aboutsummaryrefslogtreecommitdiff
path: root/libgloss/xstormy16/crt0.s
blob: 28f8c8a8dca0a57a0644739ccbec182cea5eee6f (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
# XSTORMY16 startup code

# Interrupt vectors at 0x8000.
	.section .int_vec,"ax"
	.global	_start
	.align 1
_start:
	;; Reset, watchdog timer interrupt
	jmpf _int_reset
	;; base timer interrupt
	jmpf _int_basetimer
	;; timer 0
	jmpf _int_timer0
	;; timer 1
	jmpf _int_timer1
	;; SIO0 interrupt
	jmpf _int_sio0
	;; SIO1 interrupt
	jmpf _int_sio1
	;; port0 interrupt
	jmpf _int_port0
	;; port1 interrupt
	jmpf _int_port1

	.text
# Reset code, set up memory and call main.
_int_reset:
	;; Set up the stack pointer.
	mov r0,#__stack
        bz  r0,#0,0f
	mov sp,r0
0:
	;; Zero the data space
	mov r0,#_edata
	mov r1,#_end
	mov r2,#0
0:	mov.w (r0++),r2
	blt r0,r1,0b
	;; Call hardware init routine
	callf _hwinit
	;; Call initialization routines
	callf _init
	;; Set up fini routines to be called from exit
	mov r2,#@fptr(_fini)
	callf atexit
	;; Call main() with empty argc/argv/envp
	mov r2,#0
	mov r3,#0
	mov r4,#0
	callf main
	;; Exit.
	callf exit
	;; Should never reach this code.
	halt
1:	.size _int_reset,1b-_int_reset
		
# Stub interrupt routines.
	.globl _int_timer0
	.weak _int_timer0
	.globl _int_timer1
	.weak _int_timer1
	.globl _int_sio0
	.weak _int_sio0
	.globl _int_sio1
	.weak _int_sio1
	.globl _int_port0
	.weak _int_port0
	.globl _int_port1
	.weak _int_port1
	.globl _int_basetimer
	.weak _int_basetimer
_int_timer0:
_int_timer1:
_int_sio0:
_int_sio1:
_int_port0:
_int_port1:
_int_basetimer:
	iret
1:	.size _int_timer0,1b-_int_timer0

# Stub hardware init
	.globl _hwinit
	.weak _hwinit
_hwinit:
	ret
1:	.size _int_hwinit,1b-_int_hwinit

# The first word in .data has address 0, so it's not a good
# idea to use it as its address conflicts with NULL.
# Place a HALT instruction there to try to catch NULL pointer
# dereferences.
	.data
	halt