-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.S
102 lines (84 loc) · 1.62 KB
/
boot.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
.section ".text.boot"
.global Start
Start:
// r0 = 0
// r1 = model ID (0xC42)
// r2 = ATAGs (0x100)
// Setup the stack
mov sp, #0x8000
// clear out BSS section
ldr r4, =_bss_start
ldr r9, =_bss_end
mov r5, #0
mov r6, #0
mov r7, #0
mov r8, #0
b 2f // catch the case of BSS being 0 byte
// store multiple at r4
1: stmia r4!, {r5-r8}
// If we're still below bss_end, loop again
2: cmp r4, r9
blo 1b
// Call kernel_main
ldr r3, =kernel_main
blx r3
// halt
halt:
wfe
b halt
/*
1: // compute offset of .init_array (same as offset of '1')
adr r0, 1b
ldr r1, =1b
sub r0, r1
bl put_uint32
tmp1: ldr r0, [pc, #tmp2 - tmp1 - 8]
ldr r0, [pc, r0]
tmp2: .word delay - tmp1
*/
// store constants
text.boot.constants:
.ltorg
.section ".text"
// sleep a bit
// r0 - number of loops to delay (#0x100000 = ~1s)
.global delay
delay:
subs r0, #1
bne delay
bx lr
// core wakes up here, set stack and call core_main
.global core_wakeup
core_wakeup:
// get core ID
mrc p15,0,r0,c0,c0,5
and r0, #3
// get stack
ldr r1, =stacks
ldr sp, [r1, r0, lsl #2]
// Call kernel_main
ldr r3, =core_main
blx r3
// busy loop
1: b 1b
.section ".data"
.align 2
.global stacks
stacks: .word stack0
.word stack1
.word stack2
.word stack3
.section ".bss"
.align 12
.fill 16384, 1, 0
.global stack0
stack0:
.fill 16384, 1, 0
.global stack1
stack1:
.fill 16384, 1, 0
.global stack2
stack2:
.fill 16384, 1, 0
.global stack3
stack3: