8000 arch/rv32i: separate kernel and app trap handlers by lschuermann · Pull Request #4009 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

arch/rv32i: separate kernel and app trap handlers #4009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
304 changes: 125 additions & 179 deletions arch/rv32i/src/lib.rs

Large diffs are not rendered by default.

421 changes: 313 additions & 108 deletions arch/rv32i/src/syscall.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion boards/esp32-c3-devkitM-1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ unsafe fn setup() -> (
use esp32_c3::sysreg::{CpuFrequency, PllFrequency};

// only machine mode
rv32i::configure_trap_handler(rv32i::PermissionMode::Machine);
rv32i::configure_trap_handler();

let peripherals = static_init!(Esp32C3DefaultPeripherals, Esp32C3DefaultPeripherals::new());

Expand Down
2 changes: 1 addition & 1 deletion boards/hifive1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ unsafe fn start() -> (
&'static e310_g002::chip::E310x<'static, E310G002DefaultPeripherals<'static>>,
) {
// only machine mode
rv32i::configure_trap_handler(rv32i::PermissionMode::Machine);
rv32i::configure_trap_handler();

let peripherals = static_init!(
E310G002DefaultPeripherals,
Expand Down
2 changes: 1 addition & 1 deletion boards/hifive_inventor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ unsafe fn start() -> (
&'static e310_g003::chip::E310x<'static, E310G003DefaultPeripherals<'static>>,
) {
// only machine mode
rv32i::configure_trap_handler(rv32i::PermissionMode::Machine);
rv32i::configure_trap_handler();

let peripherals = static_init!(
E310G003DefaultPeripherals,
Expand Down
2 changes: 1 addition & 1 deletion boards/litex/arty/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub unsafe fn main() {
// ---------- BASIC INITIALIZATION ----------

// Basic setup of the riscv platform.
rv32i::configure_trap_handler(rv32i::PermissionMode::Machine);
rv32i::configure_trap_handler();

// Set up memory protection immediately after setting the trap handler, to
// ensure that much of the board initialization routine runs with PMP kernel
Expand Down
2 changes: 1 addition & 1 deletion boards/litex/sim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub unsafe fn main() {
// ---------- BASIC INITIALIZATION ----------

// Basic setup of the riscv platform.
rv32i::configure_trap_handler(rv32i::PermissionMode::Machine);
rv32i::configure_trap_handler();

// Set up memory protection immediately after setting the trap handler, to
// ensure that much of the board initialization routine runs with PMP kernel
Expand Down
2 changes: 1 addition & 1 deletion boards/qemu_rv32_virt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ pub unsafe fn main() {
// ---------- BASIC INITIALIZATION -----------

// Basic setup of the RISC-V IMAC platform
rv32i::configure_trap_handler(rv32i::PermissionMode::Machine);
rv32i::configure_trap_handler();

// Set up memory protection immediately after setting the trap handler, to
// ensure that much of the board initialization routine runs with ePMP
Expand Down
2 changes: 1 addition & 1 deletion boards/redboard_redv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl KernelResources<e310_g002::chip::E310x<'static, E310G002DefaultPeripherals<
#[no_mangle]
pub unsafe fn main() {
// only machine mode
rv32i::configure_trap_handler(rv32i::PermissionMode::Machine);
rv32i::configure_trap_handler();

let peripherals = static_init!(
E310G002DefaultPeripherals,
Expand Down
2 changes: 1 addition & 1 deletion boards/swervolf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl KernelResources<swervolf_eh1::chip::SweRVolf<'static, SweRVolfDefaultPeriph
#[no_mangle]
pub unsafe fn main() {
// only machine mode
rv32i::configure_trap_handler(rv32i::PermissionMode::Machine);
rv32i::configure_trap_handler();

let peripherals = static_init!(
SweRVolfDefaultPeripherals,
Expand Down
85 changes: 46 additions & 39 deletions chips/earlgrey/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,22 @@ pub unsafe extern "C" fn disable_interrupt_trap_handler(mcause_val: u32) {
}

pub unsafe fn configure_trap_handler() {
// The common _start_trap handler uses mscratch to determine
// whether we are executing kernel or process code. Set to `0` to
// indicate we're in the kernel right now.
CSR.mscratch.set(0);

// The Ibex CPU does not support non-vectored trap entries.
CSR.mtvec
.write(mtvec::trap_addr.val(_start_trap_vectored as usize >> 2) + mtvec::mode::Vectored)
CSR.mtvec.write(
mtvec::trap_addr.val(_earlgrey_start_trap_vectored as usize >> 2) + mtvec::mode::Vectored,
);
}

// Mock implementation for crate tests that does not include the section
// specifier, as the test will not use our linker script, and the host
// compilation environment may not allow the section name.
#[cfg(not(all(target_arch = "riscv32", target_os = "none")))]
pub extern "C" fn _start_trap_vectored() {
pub extern "C" fn _earlgrey_start_trap_vectored() {
use core::hint::unreachable_unchecked;
unsafe {
unreachable_unchecked();
Expand All @@ -446,7 +452,7 @@ pub extern "C" fn _start_trap_vectored() {

#[cfg(all(target_arch = "riscv32", target_os = "none"))]
extern "C" {
pub fn _start_trap_vectored();
pub fn _earlgrey_start_trap_vectored();
}

#[cfg(all(target_arch = "riscv32", target_os = "none"))]
Expand All @@ -461,39 +467,40 @@ core::arch::global_asm!(
"
.section .riscv.trap_vectored, \"ax\"
.globl _start_trap_vectored
_start_trap_vectored:

j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
j _start_trap
"
_earlgrey_start_trap_vectored:

j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
j {start_trap}
",
start_trap = sym rv32i::_start_trap,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are tangential, but we should avoid referencing symbol names directly across crates. Instead, we should use proper Rust function exports and re-introduce them as locally-scoped symbols in Rust's asm! blocks.

5109

);
Loading
0