added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / m68k-native / clib / setjmp.s
blobb4afa44e30e511a808b054debf9fb03bce66a93d
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: 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 "machine.i"
61 .text
62 .balign 4
63 .globl AROS_CDEFNAME(setjmp)
64 .type AROS_CDEFNAME(setjmp),@function
66 .set FirstArg, 4 /* Skip Return-Adress */
67 .set env, FirstArg
68 .set retaddr, 0
70 AROS_CDEFNAME(setjmp):
71 #if OLDJMP
72 move.l env(sp),a0 /* save area pointer */
73 move.l retaddr(sp),(a0)+ /* save old PC (return address) */
74 lea env(sp),a1 /* adjust saved SP since we won't rts */
75 move.l a1,(a0)+ /* save old SP */
76 movem.l d2-d7/a2-a6,(a0) /* save remaining non-scratch regs */
77 clr.l d0 /* return 0 */
78 rts
79 #else
80 /* New version adapted from libnix instead of ixemul.
81 * Note the slightly different register save order.
83 move.l 4(sp),a0 /* get address of jmp_buf */
84 move.l (sp),(a0)+ /* store return address */
85 movem.l d2-d7/a2-a6/sp,(a0) /* store all registers except scratch */
86 moveq.l #0,d0 /* return 0 */
87 rts
88 #endif
91 The jmp_buf is filled as follows (d0/d1/a0/a1 are not saved):
93 _jmp_buf offset contents
94 [0] 0 old pc
95 [1] 4 d2
96 [2] 8 d3
97 [3] 12 d4
98 [4] 16 d5
99 [5] 20 d6
100 [6] 24 d7
101 [7] 28 a2
102 [8] 32 a3
103 [9] 36 a4
104 [10] 40 a5
105 [11] 44 a6
106 [12] 48 old sp