Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc / device / lib / mos6502 / _setjmp.s
blob7a5b2e83598140e4e0fcc6836b65c5e63dcdeb18
1 ;-------------------------------------------------------------------------
2 ; setjmp.s - source file for ANSI routines setjmp & longjmp
4 ; Copyright (C) 2020, Steven Hugg. hugg@efasterlight.com
5 ; Copyright (C) 2023, Gabriele Gorla
7 ; This library is free software; you can redistribute it and/or modify it
8 ; under the terms of the GNU General Public License as published by the
9 ; Free Software Foundation; either version 2, or (at your option) any
10 ; later version.
12 ; This library is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with this library; see the file COPYING. If not, write to the
19 ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 ; MA 02110-1301, USA.
22 ; As a special exception, if you link this library with other files,
23 ; some of which are compiled with SDCC, to produce an executable,
24 ; this library does not by itself cause the resulting executable to
25 ; be covered by the GNU General Public License. This exception does
26 ; not however invalidate any other reasons why the executable file
27 ; might be covered by the GNU General Public License.
28 ;-------------------------------------------------------------------------
30 .module _setjmp
32 ;--------------------------------------------------------
33 ; exported symbols
34 ;--------------------------------------------------------
35 .globl ___setjmp ;
36 .globl _longjmp
37 .globl _longjmp_PARM_2
39 ;--------------------------------------------------------
40 ; overlayable function parameters in zero page
41 ;--------------------------------------------------------
42 .area OSEG (PAG, OVR)
43 _longjmp_PARM_2:
44 .ds 2
46 ;--------------------------------------------------------
47 ; local aliases
48 ;--------------------------------------------------------
49 .define ptr "DPTR"
50 .define rv "_longjmp_PARM_2"
52 ;--------------------------------------------------------
53 ; code
54 ;--------------------------------------------------------
55 .area CODE
57 ;------------------------------------------------------------
58 ; int __setjmp (jmp_buf buf)
59 ;------------------------------------------------------------
61 ___setjmp:
62 stx *(ptr + 1) ; msb(buf)
63 sta *(ptr + 0) ; lsb(buf)
65 ; save stack pointer
66 tsx
67 ldy #0
68 txa
69 sta [ptr],y
71 ; save return address
72 lda 0x101,x
73 iny
74 sta [ptr],y
75 lda 0x102,x
76 iny
77 sta [ptr],y
79 ; return 0
80 lda #0
81 tax
82 rts
84 ;------------------------------------------------------------
85 ; int longjmp (jmp_buf buf, int rv)
86 ;------------------------------------------------------------
88 _longjmp:
89 stx *(ptr + 1) ; msb(buf)
90 sta *(ptr + 0) ; lsb(buf)
92 ; restore stack pointer
93 ldy #0
94 lda [ptr],y
95 tax
96 txs
98 ; set return address
99 iny
100 lda [ptr],y
101 sta 0x101,x
103 lda [ptr],y
104 sta 0x102,x
106 ;_setjmp.c:224: return rv ? rv : 1;
107 ldx *(rv + 1)
109 ora *(rv + 0)
110 beq 0001$
111 lda *(rv + 0)
113 0001$:
114 lda #0x01