struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / device / lib / z180 / crt0.s
blob20bee6954a3a33ea680bd45cc958c605ba5a1a4f
1 ;--------------------------------------------------------------------------
2 ; crt0.s - Generic crt0.s for a Z80
4 ; Copyright (C) 2000, Michael Hope
6 ; This library is free software; you can redistribute it and/or modify it
7 ; under the terms of the GNU General Public License as published by the
8 ; Free Software Foundation; either version 2, or (at your option) any
9 ; later version.
11 ; This library is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ; GNU General Public License for more details.
16 ; You should have received a copy of the GNU General Public License
17 ; along with this library; see the file COPYING. If not, write to the
18 ; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19 ; MA 02110-1301, USA.
21 ; As a special exception, if you link this library with other files,
22 ; some of which are compiled with SDCC, to produce an executable,
23 ; this library does not by itself cause the resulting executable to
24 ; be covered by the GNU General Public License. This exception does
25 ; not however invalidate any other reasons why the executable file
26 ; might be covered by the GNU General Public License.
27 ;--------------------------------------------------------------------------
29 .module crt0
30 .globl _main
32 .area _HEADER (ABS)
33 ;; Reset vector
34 .org 0
35 jp init
37 .org 0x08
39 reti
40 .org 0x10
42 reti
43 .org 0x18
45 reti
46 .org 0x20
48 reti
49 .org 0x28
51 reti
52 .org 0x30
54 reti
55 .org 0x38
57 reti
59 .org 0x100
60 init:
61 ;; Set stack pointer directly above top of memory.
62 ld sp,#0x0000
64 call ___sdcc_external_startup
66 ;; Initialise global variables. Skip if __sdcc_external_startup returned
67 ;; non-zero value. Note: calling convention version 1 only.
68 or a, a
69 call Z, gsinit
71 call _main
72 jp _exit
74 ;; Ordering of segments for the linker.
75 .area _HOME
76 .area _CODE
77 .area _INITIALIZER
78 .area _GSINIT
79 .area _GSFINAL
81 .area _DATA
82 .area _INITIALIZED
83 .area _BSEG
84 .area _BSS
85 .area _HEAP
87 .area _CODE
88 __clock::
89 ld a,#2
90 rst 0x08
91 ret
93 _exit::
94 ;; Exit - special code to the emulator
95 ld a,#0
96 rst 0x08
97 1$:
98 halt
99 jr 1$
101 .area _GSINIT
102 gsinit::
104 ; Default-initialized global variables.
105 ld bc, #l__DATA
106 ld a, b
107 or a, c
108 jr Z, zeroed_data
109 ld hl, #s__DATA
110 ld (hl), #0x00
111 dec bc
112 ld a, b
113 or a, c
114 jr Z, zeroed_data
115 ld e, l
116 ld d, h
117 inc de
118 ldir
119 zeroed_data:
121 ; Explicitly initialized global variables.
122 ld bc, #l__INITIALIZER
123 ld a, b
124 or a, c
125 jr Z, gsinit_next
126 ld de, #s__INITIALIZED
127 ld hl, #s__INITIALIZER
128 ldir
130 gsinit_next:
132 .area _GSFINAL