-
Notifications
You must be signed in to change notification settings - Fork 0
/
crt0.s
81 lines (68 loc) · 1.31 KB
/
crt0.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;; crt0.c
;; zx spectrum ram startup code
;;
;; tomaz stih sun may 20 2012
.module crt0
.globl _get_heap
.area _HEADER(ABS)
ld (#store_sp),sp ; store SP
ld sp,#stack
;; store all regs
push af
push bc
push de
push hl
push ix
push iy
ex af, af'
push af
exx
push bc
push de
push hl
call gsinit ; init static vars (sdcc style)
;; start the os
call main
;; restore all regs
pop hl
pop de
pop bc
pop af
exx
ex af,af'
pop iy
pop ix
pop hl
pop de
pop bc
pop af
ld sp,(#store_sp) ; restore original SP
ret
_get_heap:: ld hl,#heap
ret
;; (linker documentation:) where specific ordering is desired -
;; the first linker input file should have the area definitions
;; in the desired order
.area _HOME
.area _CODE
.area _GSINIT
.area _GSFINAL
.area _DATA
.area _BSS
.area _HEAP
;; this area contains data initialization code -
;; unlike gnu toolchain which generates data, sdcc generates
;; initialization code for every initialized global
;; variable. and it puts this code into _GSINIT area
.area _GSINIT
gsinit:
.area _GSFINAL
ret
.area _DATA
.area _BSS
store_sp: .word 1
;; 1024 bytes of operating system stack
.ds 1024
stack:
.area _HEAP
heap: