added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / arch / .unmaintained / m68k-native / clib / longjmp.s
blob7242eaf6250ad4f0d35060855be6a2fb6a6acbc8
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: 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 "machine.i"
64 .text
65 .balign 4
66 .globl AROS_CDEFNAME(longjmp)
67 .type AROS_CDEFNAME(longjmp),@function
69 .set FirstArg, 4 /* Skip Return-Adress */
70 .set env, FirstArg
71 .set val, env+4
72 .set retaddr, 0
73 AROS_CDEFNAME(longjmp):
74 #ifdef OLDJMP
75 move.l env(sp),a0 /* save area pointer */
76 move.l val(sp),d0
77 jne okret
78 moveq.l #1,d0 /* make sure it isn't 0 */
79 okret:
80 move.l 4(a0),sp /* restore SP */
81 move.l 0(a0),(sp) /* restore PC */
82 movem.l 8(a0),d2-d7/a2-a6 /* restore remaining non-scratch regs */
83 rts
84 #else
85 /* New version adapted from libnix instead of ixemul.
86 * Note the slightly different register save order.
88 addq.w #4,sp /* returns to other address */
89 move.l (sp)+,a0 /* get address of jmp_buf */
90 move.l (sp)+,d0 /* get return code */
91 jne .okret
92 moveq.l #1,d0 /* make sure it isn't 0 */
93 .okret:
94 move.l 48(a0),sp /* restore sp */
95 move.l (a0)+,(sp) /* set return address */
96 movem.l (a0),d2-d7/a2-a6 /* restore all registers except scratch and sp */
97 rts
98 #endif
101 The jmp_buf is filled as follows (d0/d1/a0/a1 are not saved):
103 _jmp_buf offset contents
104 [0] 0 old pc
105 [1] 4 d2
106 [2] 8 d3
107 [3] 12 d4
108 [4] 16 d5
109 [5] 20 d6
110 [6] 24 d7
111 [7] 28 a2
112 [8] 32 a3
113 [9] 36 a4
114 [10] 40 a5
115 [11] 44 a6
116 [12] 48 old sp