Announce SDCC 4.5.0 RC1.
[sdcc.git] / sdcc / device / lib / z80 / crt0.s
blobbd3981264a966eceff4265560d23c1b59f896899
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 .optsdcc -mz80 sdcccall(1)
31 .globl _main
33 .area _HEADER (ABS)
34 ;; Reset vector
35 .org 0
36 jp init
38 .org 0x08
40 reti
41 .org 0x10
43 reti
44 .org 0x18
46 reti
47 .org 0x20
49 reti
50 .org 0x28
52 reti
53 .org 0x30
55 reti
56 .org 0x38
58 reti
60 .org 0x100
61 init:
62 ;; Set stack pointer directly above top of memory.
63 ld sp,#0x0000
65 call ___sdcc_external_startup
67 ;; Initialise global variables. Skip if __sdcc_external_startup returned
68 ;; non-zero value. Note: calling convention version 1 only.
69 or a, a
70 call Z, gsinit
72 call _main
73 jp _exit
75 ;; Ordering of segments for the linker.
76 .area _HOME
77 .area _CODE
78 .area _INITIALIZER
79 .area _GSINIT
80 .area _GSFINAL
82 .area _DATA
83 .area _INITIALIZED
84 .area _BSEG
85 .area _BSS
86 .area _HEAP
88 .area _CODE
89 __clock::
90 ld a,#2
91 rst 0x08
92 ret
94 _exit::
95 ;; Exit - special code to the emulator
96 ld a,#0
97 rst 0x08
98 1$:
99 halt
100 jr 1$
102 .area _GSINIT
103 gsinit::
105 ; Default-initialized global variables.
106 ld bc, #l__DATA
107 ld a, b
108 or a, c
109 jr Z, zeroed_data
110 ld hl, #s__DATA
111 ld (hl), #0x00
112 dec bc
113 ld a, b
114 or a, c
115 jr Z, zeroed_data
116 ld e, l
117 ld d, h
118 inc de
119 ldir
120 zeroed_data:
122 ; Explicitly initialized global variables.
123 ld bc, #l__INITIALIZER
124 ld a, b
125 or a, c
126 jr Z, gsinit_next
127 ld de, #s__INITIALIZED
128 ld hl, #s__INITIALIZER
129 ldir
131 gsinit_next:
133 .area _GSFINAL