setjmp/longjmp: Also store *(SysBase->ThisTask->tc_SPLower) in jmpbuf
[AROS.git] / arch / i386-all / clib / setjmp.s
blob9822e0def64b38c6c3e269c07a8818f4c18c5e76
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: ANSI C function setjmp()
6 Lang: english
7 */
9 /******************************************************************************
11 NAME
12 #include <setjmp.h>
14 int setjmp (jmp_buf env);
16 FUNCTION
17 Save the current context so that you can return to it later.
19 INPUTS
20 env - The context/environment is saved here for later restoring
22 RESULT
23 0 if it returns from setjmp() and 1 when it returns from longjmp().
25 NOTES
27 EXAMPLE
28 jmp_buf env;
30 ... some code ...
32 if (!setjmp (env))
34 ... this code is executed after setjmp() returns ...
36 // This is no good example on how to use this function
37 // You should not do that
38 if (error)
39 longjmp (env, 5);
41 ... some code ...
43 else
45 ... this code is executed if you call longjmp(env) ...
48 BUGS
50 SEE ALSO
51 longjmp()
53 INTERNALS
55 HISTORY
57 ******************************************************************************/
59 #include "aros/i386/asm.h"
61 .text
62 _ALIGNMENT
63 .globl AROS_CDEFNAME(setjmp)
64 _FUNCTION(AROS_CDEFNAME(setjmp))
66 .set FirstArg, 4 /* Skip Return-Adress */
67 .set env, FirstArg
68 .set retaddr, 0
70 AROS_CDEFNAME(setjmp):
71 /* Fetch the address of the env-structure off the stack.
72 The address is stored in %eax which is not preserved
73 because it's contents are overwritten anyway by the
74 return code */
75 movl env(%esp),%eax
77 /* Save stack pointer and all registers into env */
78 movl %ebx,4(%eax) /* %ebx */
79 movl %ecx,8(%eax) /* %ecx */
80 movl %edx,12(%eax) /* %edx */
81 movl %esi,16(%eax) /* %esi */
82 movl %edi,20(%eax) /* %edi */
83 movl %ebp,24(%eax) /* %ebp */
84 movl %esp,28(%eax) /* %esp */
86 pushl %ebx /* Remember ebx */
88 /* Save *(SysBase->ThisTask->tc_SPLower) */
89 movl SysBase,%ebx
90 movl ThisTask(%ebx),%ebx
91 movl tc_SPLower(%ebx),%ebx
92 movl (%ebx),%ebx
93 movl %ebx,32(%eax)
95 movl retaddr+4(%esp), %ebx /* Save return address (%esp has changed) */
96 movl %ebx,0(%eax)
98 popl %ebx
100 xorl %eax,%eax /* Return 0 */