blob: eb65e85fc479060eb2f588b9c316ca4f55d0dc0d [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
PulkoMandyd4445ca2014-06-28 11:43:26 +020026 .area _GSINIT (REL)
27 .area _GSFINAL (REL)
kthacker62e146c2006-04-17 15:11:35 +000028
PulkoMandy2bb86d92014-06-28 17:09:59 +020029 .area _DATA
PulkoMandyd4445ca2014-06-28 11:43:26 +020030 .area _BSEG
PulkoMandy2bb86d92014-06-28 17:09:59 +020031 .area _BSS (REL)
32 .area _HEAP (REL)
33_progend::
PulkoMandy32c249b2014-06-29 13:15:09 +020034 ; NOTE - THE IS NOT ROM-FRIENDLY!
35 ; We put the initializers for initialized data in the memory that will later
36 ; be used for the heap. The gsinit copies it back to the CODE area above.
37 ; Then, we can overwrite the now unused initializers with the heap.
38 ; In the case of software actually running from ROM, the initializer section
39 ; would be in ROM, and GSINIT would copy it to RAM. Of course in that case,
40 ; The initializer space can't be reclaimed for the heap...
41 .area _INITIALIZER
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
58 ld de,#s__DATA
59 inc de
60 ld bc,#l__DATA
61 ldir
62
63; Initialize disk ROM
64 ld hl,#0xabff
65 ld de,#0x40
66 ld c,#7
67 call 0xbcce
kthacker62e146c2006-04-17 15:11:35 +000068
PulkoMandyd4445ca2014-06-28 11:43:26 +020069 .area _GSFINAL
PulkoMandy2bb86d92014-06-28 17:09:59 +020070 ; After the ROMs are initialized, initialize the heap.
71 jp __sdcc_heap_init