소스 검색

Transfer to supervisor on illegal instruction; test kernel

Todo: Finish test kernel
luojia65 4 년 전
부모
커밋
6ccf232637
4개의 변경된 파일26개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 0
      Cargo.toml
  2. 10 1
      platform/qemu/src/main.rs
  3. 9 0
      test-kernel/Cargo.toml
  4. 6 0
      test-kernel/src/main.rs

+ 1 - 0
Cargo.toml

@@ -3,4 +3,5 @@
 members = [
     "rustsbi",
     "platform/*",
+    "test-kernel",
 ]

+ 10 - 1
platform/qemu/src/main.rs

@@ -453,7 +453,16 @@ extern "C" fn start_trap_rust(trap_frame: &mut TrapFrame) {
                     _ => panic!("invalid target"),
                 }
                 mepc::write(mepc::read().wrapping_add(4)); // 跳过指令
-            } else {
+            } else { // can't emulate, raise invalid instruction to supervisor
+                // 出现非法指令异常,转发到特权层
+                let cause: usize = 2; // Interrupt = 0, Exception Code = 2 (Illegal Exception)
+                let val: usize = mtval::read();
+                unsafe { asm!("
+                    csrw    scause, {cause}
+                    csrw    stval, {val}
+                ", cause = in(reg) cause, val = in(reg) val) };
+                // todo: remove these following lines
+                // 先把“test-kernel”写完,功能完整后,删除下面几行
                 #[cfg(target_pointer_width = "64")]
                 panic!("invalid instruction, mepc: {:016x?}, instruction: {:016x?}", mepc::read(), ins);
                 #[cfg(target_pointer_width = "32")]

+ 9 - 0
test-kernel/Cargo.toml

@@ -0,0 +1,9 @@
+[package]
+name = "rustsbi-test-kernel"
+version = "0.1.0"
+authors = ["luojia65 <[email protected]>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]

+ 6 - 0
test-kernel/src/main.rs

@@ -0,0 +1,6 @@
+fn main() {
+    println!("Hello, world!");
+}
+
+// A test kernel to test RustSBI function on all platforms
+// todo: make a list of functions we need to test