blob: f5608ce903471fb16327f924eeae5020afd48550 [file] [log] [blame]
kthacker62e146c2006-04-17 15:11:35 +00001;; File: crt0.s
2;; Generic crt0.s for a Z80
3;; From SDCC..
4;; Modified to suit execution on the Amstrad CPC!
5;; by H. Hansen 2003
6
7 .module crt0
8 .globl _main
9 .globl _progend
kthacker62e146c2006-04-17 15:11:35 +000010 .area _HEADER (ABS)
11 ;; Ordering of segments for the linker.
12 .area _CODE
13init:
PulkoMandy32c249b2014-06-29 13:15:09 +020014; This is the program entry point. Execution starts here
15;; Initialise global variables, clear BSS areas, initialize AMSDOS and setup heap.
kthacker62e146c2006-04-17 15:11:35 +000016 call gsinit
PulkoMandy32c249b2014-06-29 13:15:09 +020017; Enter the C main.
kthacker62e146c2006-04-17 15:11:35 +000018 call _main
19
20_exit::
21 ret
PulkoMandyd4445ca2014-06-28 11:43:26 +020022
23 .area _HOME
24 .area _CODE
PulkoMandy32c249b2014-06-29 13:15:09 +020025 .area _INITIALIZED
kthacker62e146c2006-04-17 15:11:35 +000026
PulkoMandy2bb86d92014-06-28 17:09:59 +020027 .area _DATA
PulkoMandyd4445ca2014-06-28 11:43:26 +020028 .area _BSEG
PulkoMandy2bb86d92014-06-28 17:09:59 +020029 .area _BSS (REL)
30 .area _HEAP (REL)
31_progend::
PulkoMandy32c249b2014-06-29 13:15:09 +020032 ; NOTE - THE IS NOT ROM-FRIENDLY!
33 ; We put the initializers for initialized data in the memory that will later
34 ; be used for the heap. The gsinit copies it back to the CODE area above.
35 ; Then, we can overwrite the now unused initializers with the heap.
36 ; In the case of software actually running from ROM, the initializer section
37 ; would be in ROM, and GSINIT would copy it to RAM. Of course in that case,
38 ; The initializer space can't be reclaimed for the heap...
39 .area _INITIALIZER
PulkoMandy9d35dfb2014-06-29 20:26:47 +020040 .area _GSINIT (REL)
41 .area _GSFINAL (REL)
kthacker62e146c2006-04-17 15:11:35 +000042
PulkoMandy32c249b2014-06-29 13:15:09 +020043; -----------------------------------------------------------------------------
44
PulkoMandy2bb86d92014-06-28 17:09:59 +020045 .area _GSINIT (REL)
kthacker62e146c2006-04-17 15:11:35 +000046gsinit::
PulkoMandyd4445ca2014-06-28 11:43:26 +020047 ld bc, #l__INITIALIZER
48 ld a, b
49 or a, c
50 jr Z, gsinit_next
51 ld de, #s__INITIALIZED
52 ld hl, #s__INITIALIZER
53 ldir
54gsinit_next:
PulkoMandy2bb86d92014-06-28 17:09:59 +020055; Clear BSS sections
56 ld hl,#s__DATA
57 ld (hl),#0
PulkoMandy9d35dfb2014-06-29 20:26:47 +020058 ld de,#s__DATA + #1
PulkoMandy2bb86d92014-06-28 17:09:59 +020059 ld bc,#l__DATA
60 ldir
61
62; Initialize disk ROM
63 ld hl,#0xabff
64 ld de,#0x40
65 ld c,#7
66 call 0xbcce
kthacker62e146c2006-04-17 15:11:35 +000067
PulkoMandyd4445ca2014-06-28 11:43:26 +020068 .area _GSFINAL
PulkoMandy2bb86d92014-06-28 17:09:59 +020069 ; After the ROMs are initialized, initialize the heap.
70 jp __sdcc_heap_init