diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-09-15 03:25:30 -0500 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-09-15 03:25:30 -0500 |
commit | 49bf92a7aaf10a4777ea512303e442588f4ce2e5 (patch) | |
tree | 2ad6e4baf4ea0c2e728a5c103139da520e32f378 /crates/kernel/src/arch | |
parent | fc918ea68d536fa9f219e7b4decdae1f561c9886 (diff) |
Start of serious allocator work.
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") } } } |