1 /*-------------------------------------------------------------------------
2 setjmp.c - source file for ANSI routines setjmp & longjmp
4 Copyright (C) 1999, Sandeep Dutta . sandeep.dutta@usa.net
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this library; see the file COPYING. If not, write to the
18 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 As a special exception, if you link this library with other files,
22 some of which are compiled with SDCC, to produce an executable,
23 this library does not by itself cause the resulting executable to
24 be covered by the GNU General Public License. This exception does
25 not however invalidate any other reasons why the executable file
26 might be covered by the GNU General Public License.
27 -------------------------------------------------------------------------*/
30 #define __SDCC_HIDE_LONGJMP
33 #if defined(__SDCC_ds390)
37 int __setjmp (jmp_buf buf
)
39 unsigned char sp
, esp
;
42 /* registers would have been saved on the
43 stack anyway so we need to save SP
44 and the return address */
50 lsp
|= (unsigned int)(esp
<< 8);
54 *buf
++ = *((unsigned char __xdata
*) lsp
- 0);
55 *buf
++ = *((unsigned char __xdata
*) lsp
- 1);
56 *buf
++ = *((unsigned char __xdata
*) lsp
- 2);
60 int longjmp (jmp_buf buf
, int rv
)
65 lsp
|= (unsigned int)(*buf
++ << 8);
67 *((unsigned char __xdata
*) lsp
- 0) = *buf
++;
68 *((unsigned char __xdata
*) lsp
- 1) = *buf
++;
69 *((unsigned char __xdata
*) lsp
- 2) = *buf
++;
77 #elif defined(__SDCC_STACK_AUTO) && defined(__SDCC_USE_XSTACK)
79 static void dummy (void) __naked
83 ;------------------------------------------------------------
84 ;Allocation info
for local variables in function
'setjmp'
85 ;------------------------------------------------------------
86 ;buf Allocated to registers dptr b
87 ;------------------------------------------------------------
88 ;../../device
/lib
/_setjmp
.c
:180:int setjmp (jmp_buf buf
)
89 ; -----------------------------------------
91 ; -----------------------------------------
102 ;../../device
/lib
/_setjmp
.c
:183:*buf
++ = bpx
;
108 ;../../device
/lib
/_setjmp
.c
:184:*buf
++ = spx
;
114 ;../../device
/lib
/_setjmp
.c
:185:*buf
++ = bp
;
120 ;../../device
/lib
/_setjmp
.c
:186:*buf
++ = SP
;
126 ;../../device
/lib
/_setjmp
.c
:187:*buf
++ = *((unsigned char __data
*) SP
);
136 ;../../device
/lib
/_setjmp
.c
:188:*buf
= *((unsigned char __data
*)SP
- 1);
140 ; peephole
177.g optimized mov sequence
148 #ifdef __SDCC_MODEL_HUGE
150 ;../../device
/lib
/_setjmp
.c
:189:*buf
= *((unsigned char __data
*)SP
- 2);
154 ; peephole
177.g optimized mov sequence
163 ;../../device
/lib
/_setjmp
.c
:190:return 0;
168 ;------------------------------------------------------------
169 ;Allocation info
for local variables in function
'longjmp'
170 ;------------------------------------------------------------
171 ;rv Allocated to stack
- offset
-2
172 ;buf Allocated to registers dptr b
173 ;lsp Allocated to registers r5
174 ;------------------------------------------------------------
175 ;../../device
/lib
/_setjmp
.c
:192:int longjmp (jmp_buf buf
, int rv
)
176 ; -----------------------------------------
178 ; -----------------------------------------
189 ;../../device
/lib
/_setjmp
.c
:193:bpx
= *buf
++;
195 ;../../device
/lib
/_setjmp
.c
:194:spx
= *buf
++;
201 ;../../device
/lib
/_setjmp
.c
:195:bp
= *buf
++;
207 ;../../device
/lib
/_setjmp
.c
:196:lsp
= *buf
++;
214 ;../../device
/lib
/_setjmp
.c
:197:*((unsigned char __data
*) lsp
) = *buf
++;
224 ;../../device
/lib
/_setjmp
.c
:198:*((unsigned char __data
*) lsp
- 1) = *buf
;
234 #ifdef __SDCC_MODEL_HUGE
236 ;../../device
/lib
/_setjmp
.c
:199:*((unsigned char __data
*) lsp
- 2) = *buf
;
247 ;../../device
/lib
/_setjmp
.c
:200:SP
= lsp
;
250 ;../../device
/lib
/_setjmp
.c
:201:return rv
? rv
: 1;
265 #elif defined(__SDCC_STACK_AUTO)
267 static void dummy (void) __naked
271 ;------------------------------------------------------------
272 ;Allocation info
for local variables in function
'setjmp'
273 ;------------------------------------------------------------
274 ;buf Allocated to registers dptr b
275 ;------------------------------------------------------------
276 ;../../device
/lib
/_setjmp
.c
:122:int setjmp (unsigned char *buf
)
277 ; -----------------------------------------
279 ; -----------------------------------------
291 ;../../device
/lib
/_setjmp
.c
:125:*buf
= BP
;
297 ;../../device
/lib
/_setjmp
.c
:126:*buf
= SP
;
303 ;../../device
/lib
/_setjmp
.c
:127:*buf
++ = *((unsigned char __data
*) SP
);
313 ;../../device
/lib
/_setjmp
.c
:128:*buf
++ = *((unsigned char __data
*)SP
- 1);
324 #ifdef __SDCC_MODEL_HUGE
326 ;../../device
/lib
/_setjmp
.c
:129:*buf
++ = *((unsigned char __data
*)SP
- 2);
338 ;../../device
/lib
/_setjmp
.c
:130:return 0;
343 ;------------------------------------------------------------
344 ;Allocation info
for local variables in function
'longjmp'
345 ;------------------------------------------------------------
346 ;rv Allocated to stack
- offset
-3
347 ;buf Allocated to registers dptr b
348 ;lsp Allocated to registers r5
349 ;------------------------------------------------------------
350 ;../../device
/lib
/_setjmp
.c
:28:int longjmp (jmp_buf buf
, int rv
)
351 ; -----------------------------------------
353 ; -----------------------------------------
368 #ifdef __SDCC_MODEL_HUGE
374 ;../../device
/lib
/_setjmp
.c
:30:bp
= *buf
++;
381 ;../../device
/lib
/_setjmp
.c
:31:lsp
= *buf
++;
388 ;../../device
/lib
/_setjmp
.c
:32:*((unsigned char __data
*) lsp
) = *buf
++;
398 ;../../device
/lib
/_setjmp
.c
:33:*((unsigned char __data
*) lsp
- 1) = *buf
;
409 #ifdef __SDCC_MODEL_HUGE
411 ;../../device
/lib
/_setjmp
.c
:34:*((unsigned char __data
*) lsp
- 2) = *buf
;
423 ;../../device
/lib
/_setjmp
.c
:35:SP
= lsp
;
426 ;../../device
/lib
/_setjmp
.c
:36:return rv
? rv
: 1;
445 extern unsigned char __data spx
;
446 extern unsigned char __data bpx
;
448 int __setjmp (jmp_buf buf
)
450 /* registers would have been saved on the
451 stack anyway so we need to save SP
452 and the return address */
453 #ifdef __SDCC_USE_XSTACK
458 *buf
++ = *((unsigned char __idata
*) SP
- 0);
459 *buf
++ = *((unsigned char __idata
*) SP
- 1);
460 #ifdef __SDCC_MODEL_HUGE
461 *buf
++ = *((unsigned char __idata
*) SP
- 2);
466 int longjmp (jmp_buf buf
, int rv
)
470 #ifdef __SDCC_USE_XSTACK
475 *((unsigned char __idata
*) lsp
- 0) = *buf
++;
476 *((unsigned char __idata
*) lsp
- 1) = *buf
++;
477 #ifdef __SDCC_MODEL_HUGE
478 *((unsigned char __idata
*) lsp
- 2) = *buf
++;