diff options
Diffstat (limited to 'crates/kernel/src/arch')
-rw-r--r-- | crates/kernel/src/arch/riscv64/mod.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/crates/kernel/src/arch/riscv64/mod.rs b/crates/kernel/src/arch/riscv64/mod.rs index 011e244..48718c2 100644 --- a/crates/kernel/src/arch/riscv64/mod.rs +++ b/crates/kernel/src/arch/riscv64/mod.rs @@ -1,9 +1,22 @@ +use crate::cpu_locals::CPULocals; +use core::{arch::asm, ptr::NonNull}; + pub mod interrupts; pub mod paging; +/// Returns a pointer to the per-CPU locals. +pub fn get_cpu_locals() -> NonNull<CPULocals> { + // SAFETY: The entrypoint sets this up, and safe code cannot invalidate it. + unsafe { + let tp; + asm!("mv {out}, tp", out = out(reg) tp); + NonNull::new_unchecked(tp) + } +} + /// Halts the hart. pub fn sleep_forever() -> ! { loop { - unsafe { core::arch::asm!("wfi") } + unsafe { asm!("wfi") } } } |