struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / z80n / setjmp.s
blob89c19dddedd484de06a266eb7e24bcdfd4367647
1 ;--------------------------------------------------------------------------
2 ; setjmp.s
4 ; Copyright (C) 2011-2024, Philipp Klaus Krause
5 ; Copyright (C) 2024 Janko Stamenović
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 .area _CODE
32 .globl ___setjmp
34 ___setjmp:
35 ; store ret addr
36 pop de
37 push de
38 ld (hl), e
39 inc hl
40 ld (hl), d
41 inc hl
43 ; store SP
44 xor a, a
45 ld e, a
46 ld d, a
47 ex de, hl
48 add hl, sp
49 ex de, hl
50 ld (hl), e
51 inc hl
52 ld (hl), d
53 inc hl
55 ; store frame ptr
56 push ix
57 pop de
58 ld (hl), e
59 inc hl
60 ld (hl), d
62 ; ret 0
63 ld e, a
64 ld d, a
65 ret
68 .globl _longjmp
70 _longjmp:
71 ; pass retval as is, only if 0 pass 1
72 ld a, e
73 or a, d
74 jr nz, s1
75 inc e
76 s1:
77 ; save retval
78 push de
80 ; fetch stored jumpaddr
81 ld c, (hl)
82 inc hl
83 ld b, (hl)
84 inc hl
86 ; fetch spval
87 ld e, (hl)
88 inc hl
89 ld d, (hl)
90 inc hl
91 ; save spval
92 push de
94 ; fetch and set IX
95 ld e, (hl)
96 inc hl
97 ld d, (hl)
98 push de
99 pop ix
101 ; restore spval
102 pop hl
103 ; restore retval
104 pop de
105 ; adjust the stack
106 ld sp, hl
107 pop hl
109 ld l, c
110 ld h, b
111 jp (hl) ; jump to jumpaddr