Added support for compiling C++ files. It isn't included for all
[AROS.git] / arch / i386-all / clib / longjmp.s
blobc7db03668e82ee4c350322108eda591bb5167b1e
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: ANSI C function longjmp()
6 Lang: english
7 */
9 /******************************************************************************
11 NAME
12 #include <setjmp.h>
14 void longjmp (jmp_buf env, int val);
16 FUNCTION
17 Save the current context so that you can return to it later.
19 INPUTS
20 env - The context/environment to restore
21 val - This value is returned by setjmp() when you return to the
22 saved context. You cannot return 0. If val is 0, then
23 setjmp() returns with 1.
25 RESULT
26 This function doesn't return.
28 NOTES
30 EXAMPLE
31 jmp_buf env;
33 ... some code ...
35 if (!setjmp (env))
37 ... this code is executed after setjmp() returns ...
39 // This is no good example on how to use this function
40 // You should not do that
41 if (error)
42 longjmp (env, 5);
44 ... some code ...
46 else
48 ... this code is executed if you call longjmp(env) ...
51 BUGS
53 SEE ALSO
54 setjmp()
56 INTERNALS
58 HISTORY
60 ******************************************************************************/
62 #include "aros/i386/asm.h"
64 .text
65 _ALIGNMENT
66 .globl AROS_CDEFNAME(longjmp)
67 _FUNCTION(AROS_CDEFNAME(longjmp))
69 .set FirstArg, 4 /* Skip Return-Adress */
70 .set env, FirstArg
71 .set val, env+4
73 AROS_CDEFNAME(longjmp):
74 /* Fetch the address of the env-structure off the stack.
75 The address is stored in %eax which is not preserved
76 because it's contents are overwritten anyway by the
77 return code */
78 movl env(%esp),%eax
80 /* Read return value into %ebx and make sure it's not 0 */
81 movl val(%esp),%ebx
82 cmpl $0,%ebx
83 jne 1f
85 movl $1,%ebx
87 /* Restore stack pointer and all registers from env */
88 movl 28(%eax),%esp /* Restore original stack */
90 movl 0(%eax),%ecx
91 movl %ecx,retaddr(%esp) /* Restore return address */
93 pushl %ebx /* Save return value on new stack */
95 /* Restore all registers */
96 movl 4(%eax),%ebx /* %ebx */
97 movl 8(%eax),%ecx /* %ecx */
98 movl 12(%eax),%edx /* %edx */
99 movl 16(%eax),%esi /* %esi */
100 movl 20(%eax),%edi /* %edi */
101 movl 24(%eax),%ebp /* %ebp */
103 popl %eax /* Fetch return value */