代码拉取完成,页面将自动刷新
//! SBI call wrappers
#![allow(unused)]
use core::arch::asm;
const SBI_CONSOLE_PUTCHAR: usize = 1;
const SRST_EXTENSION: usize = 0x53525354;
const SYSTEM_RESET_FUNCTION: usize = 0;
enum SystemResetType {
Shutdown = 0,
ColdReboot = 1,
WarmReboot = 2
}
enum SystemResetReason {
NoReason = 0,
SystemFailure = 1
}
/// general sbi call
#[inline(always)]
fn sbi_call(eid: usize, fid: usize, arg0: usize, arg1: usize, arg2: usize) -> usize {
let mut ret;
unsafe {
asm!(
"ecall",
inlateout("x10") arg0 => ret,
in("x11") arg1,
in("x12") arg2,
in("x16") fid,
in("x17") eid,
);
}
ret
}
/// use sbi call to putchar in console (qemu uart handler)
pub fn console_putchar(c: usize) {
sbi_call(SBI_CONSOLE_PUTCHAR, 0, c, 0, 0);
}
/// use sbi call to shutdown the kernel
pub fn shutdown() -> ! {
sbi_call(SRST_EXTENSION, SYSTEM_RESET_FUNCTION,
SystemResetType::Shutdown as usize,
SystemResetReason::NoReason as usize,
0);
panic!("It should shutdown!")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。