struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / sm83 / crt0.s
blobbb66ce287b9cf5f1e7a5692b71d9ddef32cdf460
1 ;--------------------------------------------------------------------------
2 ; crt0.s -Generic crt0.s for a GBZ80.
4 ; Copyright (C) 2000, Michael Hope
5 ; Copyright (C) 2021 - 2022, Sebastian 'basxto' Riedel (sdcc@basxto.de)
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 .globl _main
32 .area _HEADER (ABS)
33 ;; Reset vector
34 .org 0x00
35 jp init
36 ;; Used by regression tests
37 .org 0x08
38 reti
39 .org 0x10
40 reti
41 .org 0x18
42 reti
43 .org 0x20
44 reti
45 .org 0x28
46 reti
47 .org 0x30
48 reti
49 ;; 0xFF (rst 0x38) is the default value of empty memory
50 .org 0x38
51 jp _exit
53 ;; Interrupt vector
54 .org 0x40
55 reti
56 .org 0x48
57 reti
58 .org 0x50
59 reti
60 .org 0x58
61 reti
62 .org 0x60
63 reti
65 .org 0x100
66 jr init
68 .org 0x150
69 init:
71 ;; Set stack pointer directly above top of Work RAM.
72 ld sp,#0xe000
74 call ___sdcc_external_startup
76 ;; Initialise global variables. Skip if __sdcc_external_startup returned
77 ;; non-zero value. Note: calling convention version 1 only.
78 or a, a
79 call Z, gsinit
81 ;; Use _main instead of main to bypass sdcc's intelligence
82 call _main
83 jp _exit
85 ;; Ordering of segments for the linker.
86 .area _HOME
87 .area _CODE
88 .area _INITIALIZER
89 .area _GSINIT
90 .area _GSFINAL
92 .area _DATA
93 .area _INITIALIZED
94 .area _BSEG
95 .area _BSS
96 .area _HEAP
98 .area _CODE
99 __clock::
100 ld a,#2
101 rst 0x08
104 _exit::
105 ;; Exit - special code to the emulator
106 ld a,#0
107 rst 0x08
109 halt
110 jr 1$
112 .area _GSINIT
113 gsinit::
114 ; Default-initialized global variables.
115 ld hl, #s__DATA
116 ld bc, #l__DATA + 0x0101
117 xor a, a
118 jr loop_implicit_compare
119 loop_implicit:
120 ld (hl+), a
121 loop_implicit_compare:
122 dec c
123 jr NZ, loop_implicit
124 dec b
125 jr NZ, loop_implicit
126 zeroed_data:
127 ; Explicitly initialized global variables.
128 ld de, #s__INITIALIZED
129 ld hl, #s__INITIALIZER
130 ld bc, #l__INITIALIZER + 0x0101
131 jr loop_explicit_compare
132 loop_explicit:
133 ld a, (hl+)
134 ld (de), a
135 inc de
136 loop_explicit_compare:
137 dec c
138 jr NZ, loop_explicit
139 dec b
140 jr NZ, loop_explicit
142 gsinit_next:
144 .area _GSFINAL