|
@@ -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));
|
|
|
-}
|