Browse Source

Add a test kernel to test illegal instruction delegation (#10)

luojia65 4 years ago
parent
commit
dce019efa4
2 changed files with 21 additions and 17 deletions
  1. 2 1
      CHANGELOG.md
  2. 19 16
      test-kernel/src/main.rs

+ 2 - 1
CHANGELOG.md

@@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 ### Added
-- S-level Illegal instruction exception is now delegated into S-level software handler.
+- S-level Illegal instruction exception is now delegated into S-level software handler
+- Added a test kernel to test SBI function on RustSBI implementations
 
 ### Modified
 

+ 19 - 16
test-kernel/src/main.rs

@@ -8,12 +8,29 @@ mod console;
 mod sbi;
 
 use riscv::register::{sepc, stvec::{self, TrapMode}};
+
+pub extern "C" fn rust_main(hartid: usize, dtb_pa: usize) -> ! {
+    println!("<< Test-kernel: Hart id = {}, DTB physical address = {:#x}", hartid, dtb_pa);
+    unsafe { stvec::write(start_trap as usize, TrapMode::Direct) };
+    println!(">> Test-kernel: Trigger illegal exception");
+    unsafe { asm!("unimp") };
+    println!("<< Test-kernel: SBI test SUCCESS, shutdown");
+    sbi::shutdown()
+}
+
+pub extern "C" fn rust_trap_exception() {
+    println!("<< Test-kernel: Illegal exception delegate success");
+    sepc::write(sepc::read().wrapping_add(4));
+}
+
 use core::panic::PanicInfo;
 
 #[cfg_attr(not(test), panic_handler)]
 #[allow(unused)]
-fn panic(_info: &PanicInfo) -> ! {
-    loop {}
+fn panic(info: &PanicInfo) -> ! {
+    println!("!! Test-kernel: {}", info);
+    println!("!! Test-kernel: SBI test FAILED due to panic");
+    sbi::shutdown()
 }
 
 const BOOT_STACK_SIZE: usize = 4096 * 4 * 8;
@@ -43,15 +60,6 @@ unsafe extern "C" fn entry() -> ! {
     options(noreturn))
 }
 
-pub extern "C" fn rust_main(hartid: usize, dtb_pa: usize) -> ! {
-    println!("<< Test-kernel: Hart id = {}, DTB physical address = {:#x}", hartid, dtb_pa);
-    unsafe { stvec::write(start_trap as usize, TrapMode::Direct) };
-    println!(">> Test-kernel: Trigger illegal exception");
-    unsafe { asm!("unimp") };
-    println!("<< Test-kernel: SBI test success, shutdown");
-    sbi::shutdown()
-}
-
 #[naked]
 #[link_section = ".text"]
 unsafe extern "C" fn start_trap() {
@@ -105,8 +113,3 @@ unsafe extern "C" fn start_trap() {
     rust_trap_exception = sym rust_trap_exception,
     options(noreturn))
 }
-
-pub extern "C" fn rust_trap_exception() {
-    println!("<< Test-kernel: Illegal exception");
-    sepc::write(sepc::read().wrapping_add(4));
-}