kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 1 | ;; 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 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 10 | .area _HEADER (ABS) |
| 11 | ;; Ordering of segments for the linker. |
| 12 | .area _CODE |
| 13 | init: |
PulkoMandy | 32c249b | 2014-06-29 13:15:09 +0200 | [diff] [blame] | 14 | ; This is the program entry point. Execution starts here |
| 15 | ;; Initialise global variables, clear BSS areas, initialize AMSDOS and setup heap. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 16 | call gsinit |
PulkoMandy | 32c249b | 2014-06-29 13:15:09 +0200 | [diff] [blame] | 17 | ; Enter the C main. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 18 | call _main |
| 19 | |
| 20 | _exit:: |
| 21 | ret |
PulkoMandy | d4445ca | 2014-06-28 11:43:26 +0200 | [diff] [blame] | 22 | |
| 23 | .area _HOME |
| 24 | .area _CODE |
PulkoMandy | 32c249b | 2014-06-29 13:15:09 +0200 | [diff] [blame] | 25 | .area _INITIALIZED |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 26 | |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 27 | .area _DATA |
PulkoMandy | d4445ca | 2014-06-28 11:43:26 +0200 | [diff] [blame] | 28 | .area _BSEG |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 29 | .area _BSS (REL) |
| 30 | .area _HEAP (REL) |
| 31 | _progend:: |
PulkoMandy | 32c249b | 2014-06-29 13:15:09 +0200 | [diff] [blame] | 32 | ; 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 |
PulkoMandy | 9d35dfb | 2014-06-29 20:26:47 +0200 | [diff] [blame^] | 40 | .area _GSINIT (REL) |
| 41 | .area _GSFINAL (REL) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 42 | |
PulkoMandy | 32c249b | 2014-06-29 13:15:09 +0200 | [diff] [blame] | 43 | ; ----------------------------------------------------------------------------- |
| 44 | |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 45 | .area _GSINIT (REL) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 46 | gsinit:: |
PulkoMandy | d4445ca | 2014-06-28 11:43:26 +0200 | [diff] [blame] | 47 | 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 |
| 54 | gsinit_next: |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 55 | ; Clear BSS sections |
| 56 | ld hl,#s__DATA |
| 57 | ld (hl),#0 |
PulkoMandy | 9d35dfb | 2014-06-29 20:26:47 +0200 | [diff] [blame^] | 58 | ld de,#s__DATA + #1 |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 59 | 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 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 67 | |
PulkoMandy | d4445ca | 2014-06-28 11:43:26 +0200 | [diff] [blame] | 68 | .area _GSFINAL |
PulkoMandy | 2bb86d9 | 2014-06-28 17:09:59 +0200 | [diff] [blame] | 69 | ; After the ROMs are initialized, initialize the heap. |
| 70 | jp __sdcc_heap_init |