-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.s
74 lines (64 loc) · 1.53 KB
/
core.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
.syntax unified
.cpu cortex-m3
.fpu softvfp
.thumb
//Global values
.global reset_handler
/*
* Reset handler
* Called on reset and power on
*/
.type reset_handler, %function
reset_handler:
//Set the stack pointer to the end of the stack
LDR r0, =_estack
MOV sp, r0
/*
* Copy data from flash to RAM data init section.
* R2 will store our progress along the sidata section.
*/
MOVS r0, #0
/*
* Load the start/end addresses of the data section,
* and the start of the data init sections.
*/
LDR r1, =_sdata
LDR r2, =_edata
LDR r3, =_sidata
B copy_sidata_loop
copy_sidata:
//Offset the data init section by our copy progress
LDR r4, [r3, r0]
//Copy the current word into data and increment
STR r4, [r1, r0]
ADDS r0, r0, #4
copy_sidata_loop:
/*
* Unless we've copied the whole data section, copy the
* next word from sidata->data
*/
ADDS r4, r0, r1
CMP r4, r2
BCC copy_sidata
/*
* Once we are done copying the data section into RAM,
* move on to filling the BSS section with 0s
*/
MOVS r0, #0
LDR r1, =_sbss
LDR r2, =_ebss
B reset_bss_loop
//Fill the BSS segment with 0s
reset_bss:
//Store a 0 and increment by a word
STR r0, [r1]
ADDS r1, r1, #4
reset_bss_loop:
/*
* We'll user R1 to count progress here; if we aren't
* done, reset the next word and increment
*/
CMP r1, r2
BCC reset_bss
B init
.size reset_handler, .-reset_handler