mirror of
https://github.com/isometimes/rpi4-osdev
synced 2024-11-22 10:10:45 +00:00
Cleaned up boot.S so it's clearer where the changes are from part9
This commit is contained in:
parent
56068acbb6
commit
75beaecccf
1 changed files with 49 additions and 42 deletions
|
@ -1,52 +1,59 @@
|
||||||
#define LOCAL_CONTROL 0xff800000
|
#define LOCAL_CONTROL 0xff800000
|
||||||
#define LOCAL_PRESCALER 0xff800008
|
#define LOCAL_PRESCALER 0xff800008
|
||||||
#define OSC_FREQ 54000000
|
#define OSC_FREQ 54000000
|
||||||
#define MAIN_STACK 0x400000
|
#define MAIN_STACK 0x400000
|
||||||
|
|
||||||
.section ".text.boot"
|
.section ".text.boot" // Make sure the linker puts this at the start of the kernel image
|
||||||
|
|
||||||
|
.global _start // Execution starts here
|
||||||
|
|
||||||
.globl _start
|
|
||||||
_start:
|
_start:
|
||||||
ldr x0, =LOCAL_CONTROL // Sort out the timer
|
ldr x0, =LOCAL_CONTROL // Sort out the timer
|
||||||
str wzr, [x0]
|
str wzr, [x0]
|
||||||
mov w1, 0x80000000
|
mov w1, 0x80000000
|
||||||
str w1, [x0, #(LOCAL_PRESCALER - LOCAL_CONTROL)]
|
str w1, [x0, #(LOCAL_PRESCALER - LOCAL_CONTROL)]
|
||||||
|
|
||||||
ldr x0, =OSC_FREQ
|
ldr x0, =OSC_FREQ
|
||||||
msr cntfrq_el0, x0
|
msr cntfrq_el0, x0
|
||||||
msr cntvoff_el2, xzr
|
msr cntvoff_el2, xzr
|
||||||
|
|
||||||
mrs x6, mpidr_el1
|
// Check processor ID is zero (executing on main core), else hang
|
||||||
and x6, x6,#0xFF // Check processor id
|
mrs x1, mpidr_el1
|
||||||
cbz x6, primary_cpu // Hang for all non-primary CPU
|
and x1, x1, #3
|
||||||
|
cbz x1, 2f
|
||||||
|
|
||||||
adr x5, spin_cpu0
|
// We're not on the main core, so hang in an infinite wait loop
|
||||||
proc_hang:
|
adr x5, spin_cpu0
|
||||||
wfe
|
1: wfe
|
||||||
ldr x4, [x5, x6, lsl #3]
|
ldr x4, [x5, x1, lsl #3]
|
||||||
cbz x4, proc_hang
|
cbz x4, 1b
|
||||||
|
|
||||||
ldr x1, =__test_stack // Get ourselves a fresh stack
|
ldr x1, =__test_stack // Get ourselves a fresh stack
|
||||||
mov sp, x1
|
mov sp, x1
|
||||||
secondary_cpu:
|
|
||||||
mov x0, #0
|
mov x0, #0
|
||||||
mov x1, #0
|
mov x1, #0
|
||||||
mov x2, #0
|
mov x2, #0
|
||||||
mov x3, #0
|
mov x3, #0
|
||||||
br x4
|
br x4
|
||||||
b proc_hang
|
b 1b
|
||||||
primary_cpu:
|
2: // We're on the main core!
|
||||||
ldr x1, =__bss_start
|
|
||||||
ldr w2, =__bss_size
|
// Set stack to start somewhere safe
|
||||||
memzero:
|
mov sp, #MAIN_STACK
|
||||||
cbz w2, startup
|
|
||||||
str xzr, [x1], #8
|
// Clean the BSS section
|
||||||
sub w2, w2, #1
|
ldr x1, =__bss_start // Start address
|
||||||
cbnz w2, memzero
|
ldr w2, =__bss_size // Size of the section
|
||||||
startup:
|
3: cbz w2, 4f // Quit loop if zero
|
||||||
mov sp, #MAIN_STACK
|
str xzr, [x1], #8
|
||||||
bl main
|
sub w2, w2, #1
|
||||||
b proc_hang // should never come here
|
cbnz w2, 3b // Loop if non-zero
|
||||||
|
|
||||||
|
// Jump to our main() routine in C (make sure it doesn't return)
|
||||||
|
4: bl main
|
||||||
|
// In case it does return, halt the master core too
|
||||||
|
b 1b
|
||||||
|
|
||||||
.ltorg
|
.ltorg
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue