-
Notifications
You must be signed in to change notification settings - Fork 42
/
main.rs
47 lines (42 loc) · 1.09 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![no_std]
#![no_main]
#![feature(naked_functions, asm_const)]
#![deny(warnings)]
/// Supervisor 汇编入口。
///
/// 设置栈并跳转到 Rust。
#[naked]
#[no_mangle]
#[link_section = ".text.entry"]
unsafe extern "C" fn _start() -> ! {
const STACK_SIZE: usize = 4096;
#[link_section = ".bss.uninit"]
static mut STACK: [u8; STACK_SIZE] = [0u8; STACK_SIZE];
core::arch::asm!(
"la sp, {stack} + {stack_size}",
"j {main}",
stack_size = const STACK_SIZE,
stack = sym STACK,
main = sym rust_main,
options(noreturn),
)
}
/// 非常简单的 Supervisor 裸机程序。
///
/// 打印 `Hello, World!`,然后关机。
extern "C" fn rust_main() -> ! {
use sbi_rt::*;
for c in b"Hello, world!" {
#[allow(deprecated)]
legacy::console_putchar(*c as _);
}
system_reset(Shutdown, NoReason);
unreachable!()
}
/// Rust 异常处理函数,以异常方式关机。
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
use sbi_rt::*;
system_reset(Shutdown, SystemFailure);
loop {}
}