Announce SDCC 4.5.0 RC1.
[sdcc.git] / sdcc / device / lib / z80 / setjmp.s
blobffbfc21eb95643b23e3cf925bce298bcc972fda4
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 .module setjmp
31 .optsdcc -mz80 sdcccall(1)
33 .area _CODE
35 .globl ___setjmp
37 ___setjmp:
38 ; store ret addr
39 pop de
40 push de
41 ld (hl), e
42 inc hl
43 ld (hl), d
44 inc hl
46 ; store SP
47 xor a, a
48 ld e, a
49 ld d, a
50 ex de, hl
51 add hl, sp
52 ex de, hl
53 ld (hl), e
54 inc hl
55 ld (hl), d
56 inc hl
58 ; store frame ptr
59 push ix
60 pop de
61 ld (hl), e
62 inc hl
63 ld (hl), d
65 ; ret 0
66 ld e, a
67 ld d, a
68 ret
71 .globl _longjmp
73 _longjmp:
74 ; pass retval as is, only if 0 pass 1
75 ld a, e
76 or a, d
77 jr nz, s1
78 inc e
79 s1:
80 ; save retval
81 push de
83 ; fetch stored jumpaddr
84 ld c, (hl)
85 inc hl
86 ld b, (hl)
87 inc hl
89 ; fetch spval
90 ld e, (hl)
91 inc hl
92 ld d, (hl)
93 inc hl
94 ; save spval
95 push de
97 ; fetch and set IX
98 ld e, (hl)
99 inc hl
100 ld d, (hl)
101 push de
102 pop ix
104 ; restore spval
105 pop hl
106 ; restore retval
107 pop de
108 ; adjust the stack
109 ld sp, hl
110 pop hl
112 ld l, c
113 ld h, b
114 jp (hl) ; jump to jumpaddr