Browse Source

feat: cpu_enable should consider privilege check

Signed-off-by: yzs <320016@qq.com>
yzs 6 days ago
parent
commit
cd0e6bf5fc
2 changed files with 14 additions and 1 deletions
  1. 11 0
      prototyper/prototyper/src/main.rs
  2. 3 1
      prototyper/prototyper/src/platform/mod.rs

+ 11 - 0
prototyper/prototyper/src/main.rs

@@ -37,6 +37,9 @@ use crate::sbi::trap_stack;
 
 pub const R_RISCV_RELATIVE: usize = 3;
 
+use crate::cfg::NUM_HART_MAX;
+static mut ENABLED: [bool; NUM_HART_MAX] = [false; NUM_HART_MAX];
+
 #[unsafe(no_mangle)]
 extern "C" fn rust_main(_hart_id: usize, opaque: usize, nonstandard_a2: usize) {
     // Track whether SBI is initialized and ready.
@@ -53,11 +56,19 @@ extern "C" fn rust_main(_hart_id: usize, opaque: usize, nonstandard_a2: usize) {
         MPP::Supervisor => {
             if !misa::read().unwrap().has_extension('S') {
                 fail::stop();
+            } else {
+                unsafe {
+                    ENABLED[current_hartid()] = true;
+                }
             }
         }
         MPP::User => {
             if !misa::read().unwrap().has_extension('U') {
                 fail::stop();
+            } else {
+                unsafe {
+                    ENABLED[current_hartid()] = true;
+                }
             }
         }
         _ => {}

+ 3 - 1
prototyper/prototyper/src/platform/mod.rs

@@ -264,7 +264,9 @@ impl Platform {
             let cpu = cpu_iter.deserialize::<Cpu>();
             let hart_id = cpu.reg.iter().next().unwrap().0.start;
             if let Some(x) = cpu_list.get_mut(hart_id) {
-                *x = true;
+                unsafe {
+                    *x = crate::ENABLED[hart_id];
+                }
             } else {
                 error!(
                     "The maximum supported hart id is {}, but the hart id {} was obtained. Please check the config!",