arch cpu_id

This commit is contained in:
Garen Tyler 2023-11-09 19:02:16 -07:00
parent 1e12ccddb3
commit 934dc13f96
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
5 changed files with 12 additions and 2 deletions

View File

@ -0,0 +1,4 @@
//! Architecture-agnostic CPU functions.
#[cfg(target_arch = "riscv64")]
pub use super::riscv::cpu::cpu_id;

View File

@ -1,5 +1,6 @@
#[cfg(target_arch = "riscv64")]
pub mod riscv;
pub mod cpu;
pub mod interrupt;
pub mod power;

View File

@ -0,0 +1,5 @@
use super::asm::r_tp;
pub fn cpu_id() -> usize {
unsafe { r_tp() as usize }
}

View File

@ -1,5 +1,6 @@
pub mod asm;
pub mod clint;
pub mod cpu;
pub mod memlayout;
pub mod plic;
pub mod power;

View File

@ -1,5 +1,4 @@
use super::{context::Context, process::Process};
use crate::arch::riscv::asm::r_tp;
use core::ptr::{addr_of_mut, null_mut};
pub static mut CPUS: [Cpu; crate::NCPU] = [Cpu::new(); crate::NCPU];
@ -29,7 +28,7 @@ impl Cpu {
/// to prevent race with process being moved
/// to a different CPU.
pub fn current_id() -> usize {
unsafe { r_tp() as usize }
crate::arch::cpu::cpu_id()
}
/// Return this CPU's cpu struct.
/// Interrupts must be disabled.