Using sbi-rt instead of asm && update rustsbi-qemu to latest
rustsbi-qemu version: a4f0bbe44d9f2f1069a9e5becd09f291e542852c
This commit is contained in:
parent
9ba3bea9db
commit
7cbefedc23
5 changed files with 23 additions and 121 deletions
|
@ -1,46 +1,27 @@
|
|||
#![allow(unused)]
|
||||
|
||||
use core::arch::asm;
|
||||
|
||||
const SBI_SET_TIMER: usize = 0;
|
||||
const SBI_CONSOLE_PUTCHAR: usize = 1;
|
||||
const SBI_CONSOLE_GETCHAR: usize = 2;
|
||||
const SBI_CLEAR_IPI: usize = 3;
|
||||
const SBI_SEND_IPI: usize = 4;
|
||||
const SBI_REMOTE_FENCE_I: usize = 5;
|
||||
const SBI_REMOTE_SFENCE_VMA: usize = 6;
|
||||
const SBI_REMOTE_SFENCE_VMA_ASID: usize = 7;
|
||||
const SBI_SHUTDOWN: usize = 8;
|
||||
|
||||
#[inline(always)]
|
||||
fn sbi_call(which: usize, arg0: usize, arg1: usize, arg2: usize) -> usize {
|
||||
let mut ret;
|
||||
unsafe {
|
||||
core::arch::asm!(
|
||||
"li x16, 0",
|
||||
"ecall",
|
||||
inlateout("x10") arg0 => ret,
|
||||
in("x11") arg1,
|
||||
in("x12") arg2,
|
||||
in("x17") which,
|
||||
);
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
pub fn set_timer(timer: usize) {
|
||||
sbi_call(SBI_SET_TIMER, timer, 0, 0);
|
||||
}
|
||||
|
||||
/// use sbi call to putchar in console (qemu uart handler)
|
||||
pub fn console_putchar(c: usize) {
|
||||
sbi_call(SBI_CONSOLE_PUTCHAR, c, 0, 0);
|
||||
#[allow(deprecated)]
|
||||
sbi_rt::legacy::console_putchar(c);
|
||||
}
|
||||
|
||||
/// use sbi call to getchar from console (qemu uart handler)
|
||||
pub fn console_getchar() -> usize {
|
||||
sbi_call(SBI_CONSOLE_GETCHAR, 0, 0, 0)
|
||||
#[allow(deprecated)]
|
||||
sbi_rt::legacy::console_getchar()
|
||||
}
|
||||
|
||||
use crate::board::QEMUExit;
|
||||
pub fn shutdown(exit_code: usize) -> ! {
|
||||
crate::board::QEMU_EXIT_HANDLE.exit_failure()
|
||||
/// use sbi call to set timer
|
||||
pub fn set_timer(timer: usize) {
|
||||
sbi_rt::set_timer(timer as _);
|
||||
}
|
||||
|
||||
/// use sbi call to shutdown the kernel
|
||||
pub fn shutdown(failure: bool) -> ! {
|
||||
use sbi_rt::{system_reset, NoReason, Shutdown, SystemFailure};
|
||||
if !failure {
|
||||
system_reset(Shutdown, NoReason);
|
||||
} else {
|
||||
system_reset(Shutdown, SystemFailure);
|
||||
}
|
||||
unreachable!()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue