struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / ez80_z80 / setjmp.s
blob5d975edb1495e907bd783931bef8c8686e7fb391
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 l, a
64 ld h, a
65 ret
68 .globl _longjmp
70 _longjmp:
71 pop de
72 pop de
73 ; pass retval as is, only if 0 pass 1
74 ld a, e
75 or a, d
76 jr nz, s1
77 inc e
78 s1:
79 ; save retval
80 push de
82 ; fetch stored jumpaddr
83 ld c, (hl)
84 inc hl
85 ld b, (hl)
86 inc hl
88 ; fetch spval
89 ld e, (hl)
90 inc hl
91 ld d, (hl)
92 inc hl
93 ; save spval
94 push de
96 ; fetch and set IX
97 ld e, (hl)
98 inc hl
99 ld d, (hl)
100 push de
101 pop ix
103 ; restore spval
104 pop hl
105 ; restore retval
106 pop de
107 ; adjust the stack
108 ld sp, hl
109 pop hl
111 ; retval to hl
112 ex de, hl
114 ; jump to jumpaddr
115 push bc