Compare commits
No commits in common. "aaf64d0a2d5b1c20845fb322f4a1548b86336b8a" and "9aa84608251a8db4e0ecbe44651247f5b9e5afd9" have entirely different histories.
aaf64d0a2d
...
9aa8460825
18
src/main.rs
18
src/main.rs
|
@ -14,12 +14,8 @@ mod uart;
|
|||
unsafe extern "C" fn _enter() -> ! {
|
||||
use core::arch::asm;
|
||||
asm!(
|
||||
// load hartid into t0; if t0 =/= 0, then jump to busy loop
|
||||
"csrr t0, mhartid",
|
||||
"bnez t0, 3f",
|
||||
|
||||
// before we use the `la` pseudo-instruction for the first time,
|
||||
// we need to set `gp` (look up linker relaxation)
|
||||
// we need to set `gp` (google linker relaxation)
|
||||
".option push", // pushes the current option stack
|
||||
".option norelax", // disable relaxation so we can properly set `gp`
|
||||
// this instruction compiles to:
|
||||
|
@ -42,14 +38,7 @@ unsafe extern "C" fn _enter() -> ! {
|
|||
"bne t0, t1, 1b",
|
||||
"2:",
|
||||
// BSS is clear!
|
||||
"j 4f",
|
||||
|
||||
// busy loop if hartid =/= 0
|
||||
"3:",
|
||||
"wfi", // wait for interrupt (or nop)
|
||||
"j 3b",
|
||||
|
||||
"4:",
|
||||
|
||||
// "tail-call" to {start} (call without saving a return address)
|
||||
"tail {start}",
|
||||
start = sym start, // {start} refers to the function [start] below
|
||||
|
@ -73,10 +62,8 @@ extern "C" fn start() -> ! {
|
|||
unsafe { uart::init_console(0x1000_0000) };
|
||||
println!("Hello, world!");
|
||||
|
||||
// print current hartid
|
||||
println!("hartid: {}", riscv::register::mhartid::read());
|
||||
|
||||
// poll console for input and print characters back
|
||||
loop {
|
||||
let c = uart::CONSOLE.lock().as_mut().and_then(uart::Device::get);
|
||||
if let Some(c) = c {
|
||||
|
@ -87,7 +74,6 @@ extern "C" fn start() -> ! {
|
|||
|
||||
#[panic_handler]
|
||||
fn on_panic(info: &PanicInfo) -> ! {
|
||||
// print panic info and hang
|
||||
println!("{}", info);
|
||||
|
||||
loop {}
|
||||
|
|
Loading…
Reference in a new issue