Pārlūkot izejas kodu

fix(prototyper): Nemu's device tree doesn't have `riscv,isa-extensions` field, so it is not parsed

guttatus 5 mēneši atpakaļ
vecāks
revīzija
0f815d2c71
4 mainītis faili ar 21 papildinājumiem un 14 dzēšanām
  1. 1 0
      .gitignore
  2. 1 1
      prototyper/src/main.rs
  3. 18 12
      prototyper/src/sbi/extensions.rs
  4. 1 1
      prototyper/src/sbi/ipi.rs

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 /target
+.idea/*

+ 1 - 1
prototyper/src/main.rs

@@ -161,7 +161,7 @@ extern "C" fn rust_main(_hart_id: usize, opaque: usize, nonstandard_a2: usize) {
         use riscv::register::{medeleg, mtvec};
         medeleg::clear_supervisor_env_call();
         medeleg::clear_illegal_instruction();
-        if hart_extension_probe(current_hartid(),Extension::SSTC) {
+        if hart_extension_probe(current_hartid(),Extension::Sstc) {
             menvcfg::set_bits(
                 menvcfg::STCE | menvcfg::CBIE_INVALIDATE | menvcfg::CBCFE | menvcfg::CBZE,
             );

+ 18 - 12
prototyper/src/sbi/extensions.rs

@@ -5,16 +5,16 @@ pub struct HartExtensions([bool; Extension::COUNT]);
 
 #[derive(Copy, Clone)]
 pub enum Extension {
-    SSTC = 0,
+    Sstc = 0,
 }
 
 impl Extension {
     const COUNT: usize = 1;
-    const ITER: [Self;Extension::COUNT] = [Extension::SSTC];
+    const ITER: [Self;Extension::COUNT] = [Extension::Sstc];
 
-    pub fn to_str(&self) -> &'static str {
+    pub fn as_str(&self) -> &'static str {
         match self {
-            Extension::SSTC => "sstc",
+            Extension::Sstc => "sstc",
         }
     }
 
@@ -32,6 +32,7 @@ pub fn hart_extension_probe(hart_id: usize, ext: Extension) -> bool {
     }
 }
 
+#[cfg(not(feature = "nemu"))]
 pub fn init(cpus: &NodeSeq) {
     use crate::dt::Cpu;
     for cpu_iter in cpus.iter() {
@@ -40,18 +41,22 @@ pub fn init(cpus: &NodeSeq) {
         let mut hart_exts = [false;Extension::COUNT];
         let isa = cpu.isa.unwrap();
         Extension::ITER.iter().for_each(|ext| {
-            if isa.iter().any(|e| e == ext.to_str()) {
-                hart_exts[ext.index()] = true;
-            } else {
-                hart_exts[ext.index()] = false;
-            }
+            hart_exts[ext.index()] = isa.iter().any(|e| e == ext.as_str());
         });
 
-        #[cfg(feature = "nemu")] 
-        {
-            hart_exts[Extension::SSTC.index()] = true;
+        unsafe {
+            ROOT_STACK
+                .get_mut(hart_id)
+                .map(|stack| stack.hart_context().extensions = HartExtensions(hart_exts)).unwrap()
         }
+    }
+}
 
+#[cfg(feature = "nemu")] 
+pub fn init(cpus: &NodeSeq) {
+    for hart_id in 0..cpus.len() {
+        let mut hart_exts = [false;Extension::COUNT];
+        hart_exts[Extension::Sstc.index()] = true;
         unsafe {
             ROOT_STACK
                 .get_mut(hart_id)
@@ -59,3 +64,4 @@ pub fn init(cpus: &NodeSeq) {
         }
     }
 }
+    

+ 1 - 1
prototyper/src/sbi/ipi.rs

@@ -31,7 +31,7 @@ pub struct SbiIpi<'a, T: IpiDevice> {
 impl<'a, T: IpiDevice> rustsbi::Timer for SbiIpi<'a, T> {
     #[inline]
     fn set_timer(&self, stime_value: u64) {
-        if hart_extension_probe(current_hartid(),Extension::SSTC) {
+        if hart_extension_probe(current_hartid(),Extension::Sstc) {
             stimecmp::set(stime_value);
             unsafe {
                 riscv::register::mie::set_mtimer();