aboutsummaryrefslogtreecommitdiff
path: root/src/boot.s
blob: 626420c7b1f6823f6d50f736cd5139acba0cad80 (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
.syntax unified
.thumb

.section .vector_table, "a"
.word __stack_top /* Initial stack pointer */
.word _start /* Reset Handler */
.word _hang  /* Non Maskable Interrupts */
.word _hang /* Hard Fault */
.word _hang /* Memory Management Fault */
.word _hang /* Bus Fault */
.word _hang /* Usage Fault */
.skip 16 /* Reserved */
.word _hang /* SVCall */
.skip 8 /* Reserved */
.word _hang /* PendSV */
.word _hang /* SysTick */


.text
.align
.thumb_func
_start:
/* Zero init BSS */
_bss_init_start:
	/* BSS section start and end addresses are 4-bytes aligned thanks to the linker script */
	ldr r0, =__bss_start
	ldr r1, =__bss_end
	mov r2, #0
_bss_init_loop:
	cmp r0, r1
	beq _bss_init_end
	str r2, [r0], #4
	b _bss_init_loop
_bss_init_end:

/* Init data section */
_data_init_start:
	/* Data section start and end addresses are also 4-bytes aligned */
	ldr r0, =__data_lma
	ldr r1, =__data_start
	ldr r2, =__data_end
__data_init_loop:
	cmp r1, r2
	beq _data_init_end
	ldr r4, [r0], #4
	ldr r4, [r1], #4
	b __data_init_loop
_data_init_end:

	/* Reset all general purpose registers */
	mov r0, #0
	mov r1, #0
	mov r2, #0
	mov r3, #0
	mov r4, #0
	mov r5, #0
	mov r6, #0
	mov r7, #0
	mov r8, #0
	mov r9, #0
	mov r10, #0
	mov r11, #0
	mov r12, #0
	bl main

_hang:
	b .