Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions aarch32-rt/src/arch_v4/boot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! Start-up code for CPUs that always boot into EL1

core::arch::global_asm!(
r#"
// Work around https://github.com/rust-lang/rust/issues/127269
.fpu vfp2

.pushsection .text.default_start
.arm
.global _default_start
.type _default_start, %function
_default_start:
// Init .data and .bss
bl _init_segments
// Set up stacks.
mov r0, #0
bl _stack_setup_preallocated
"#,
crate::system_init!(),
r#"
// Zero all registers before calling kmain
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
// Jump to application
bl kmain
// In case the application returns, loop forever
b .
.size _default_start, . - _default_start
.popsection
"#
);
1 change: 1 addition & 0 deletions aarch32-rt/src/arch_v4/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! ASM routines for Armv4 to Armv6

mod abort;
mod boot;
mod hvc;
mod interrupt;
mod svc;
Expand Down
42 changes: 42 additions & 0 deletions aarch32-rt/src/arch_v7/boot_from_el1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! Start-up code for CPUs that always boot into EL1

core::arch::global_asm!(
r#"
// Work around https://github.com/rust-lang/rust/issues/127269
.fpu vfp2

.pushsection .text.default_start
.arm
.global _default_start
.type _default_start, %function
_default_start:
// Init .data and .bss
bl _init_segments
// Set up stacks.
mov r0, #0
bl _stack_setup_preallocated
"#,
crate::system_init!(),
r#"
// Zero all registers before calling kmain
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
// Jump to application
bl kmain
// In case the application returns, loop forever
b .
.size _default_start, . - _default_start
.popsection
"#
);
94 changes: 94 additions & 0 deletions aarch32-rt/src/arch_v7/boot_from_el2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//! Start-up code for CPUs that *might* boot into EL2 but that we want in EL1.

use aarch32_cpu::register::{cpsr::ProcessorMode, Cpsr, Hactlr};

core::arch::global_asm!(
r#"
// Work around https://github.com/rust-lang/rust/issues/127269
.fpu vfp2
.cpu cortex-r52

.pushsection .text.default_start
.arm
.global _default_start
.type _default_start, %function
_default_start:
// Are we in EL2? If not, skip the EL2 setup portion
mrs r0, cpsr
and r0, r0, 0x1F
cmp r0, {cpsr_mode_hyp}
bne 1f
// Set stack pointer
ldr sp, =_hyp_stack_high_end
// Set the HVBAR (for EL2) to _vector_table
ldr r1, =_vector_table
mcr p15, 4, r1, c12, c0, 0
// Configure HACTLR to let us enter EL1
mrc p15, 4, r1, c1, c0, 1
mov r2, {hactlr_bits}
orr r1, r1, r2
mcr p15, 4, r1, c1, c0, 1
// Program the SPSR - enter system mode (0x1F) in Arm mode with IRQ, FIQ masked
mov r1, {sys_mode}
msr spsr_hyp, r1
adr r1, 1f
msr elr_hyp, r1
dsb
isb
eret
1:
// Set the VBAR (for EL1) to _vector_table. NB: This isn't required on
// Armv7-R because that only supports 'low' (default) or 'high'.
ldr r0, =_vector_table
mcr p15, 0, r0, c12, c0, 0
// Init .data and .bss
bl _init_segments
// Set up stacks.
mov r0, #0
bl _stack_setup_preallocated
"#,
crate::system_init!(),
r#"
// Zero all registers before calling kmain
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
// Jump to application
bl kmain
// In case the application returns, loop forever
b .
.size _default_start, . - _default_start
.popsection
"#,
cpsr_mode_hyp = const ProcessorMode::Hyp as u8,
hactlr_bits = const {
Hactlr::new_with_raw_value(0)
.with_cpuactlr(true)
.with_cdbgdci(true)
.with_flashifregionr(true)
.with_periphpregionr(true)
.with_qosr(true)
.with_bustimeoutr(true)
.with_intmonr(true)
.with_err(true)
.with_testr1(true)
.raw_value()
},
sys_mode = const {
Cpsr::new_with_raw_value(0)
.with_mode(ProcessorMode::Sys)
.with_i(true)
.with_f(true)
.raw_value()
}
);
9 changes: 9 additions & 0 deletions aarch32-rt/src/arch_v7/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ mod hvc;
mod interrupt;
mod svc;
mod undefined;

#[cfg(any(
arm_architecture = "v7-a",
all(arm_architecture = "v8-r", not(feature = "el2-mode")),
))]
mod boot_from_el2;

#[cfg(arm_architecture = "v7-r")]
mod boot_from_el1;
49 changes: 49 additions & 0 deletions aarch32-rt/src/arch_v8_hyp/boot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! Start-up code for Armv8-R to stay in EL2.
//!
//! We boot into EL2, set up a HYP stack pointer, and run `kmain` in EL2.

core::arch::global_asm!(
r#"
// Work around https://github.com/rust-lang/rust/issues/127269
.fpu vfp3

.section .text.default_start
.global _default_start
.type _default_start, %function
_default_start:
// Init .data and .bss
bl _init_segments
// Set stack pointer
ldr sp, =_hyp_stack_high_end
// Set the HVBAR (for EL2) to _vector_table
ldr r1, =_vector_table
mcr p15, 4, r1, c12, c0, 0
// Mask IRQ and FIQ
mrs r0, CPSR
orr r0, {irq_fiq}
msr CPSR, r0
"#,
crate::system_init!(),
r#"
// Zero all registers before calling kmain
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
// Jump to application
bl kmain
// In case the application returns, loop forever
b .
.size _default_start, . - _default_start
"#,
irq_fiq = const aarch32_cpu::register::Cpsr::new_with_raw_value(0).with_i(true).with_f(true).raw_value()
);
1 change: 1 addition & 0 deletions aarch32-rt/src/arch_v8_hyp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! ASM routines for Armv8-R at EL2

mod abort;
mod boot;
mod hvc;
mod interrupt;
mod svc;
Expand Down
Loading
Loading