Compare commits

..

4 commits

Author SHA1 Message Date
gil aaf64d0a2d Add a comment 2024-05-16 08:23:08 -05:00
gil ef07d172ff Regroup asm blocks 2024-05-16 08:21:50 -05:00
gil 8c1f860d25 Degoogle lol 2024-05-16 08:19:23 -05:00
gil 5df0472703 Loop for non-0 hartid's 2024-05-16 08:19:15 -05:00

View file

@ -14,8 +14,12 @@ mod uart;
unsafe extern "C" fn _enter() -> ! { unsafe extern "C" fn _enter() -> ! {
use core::arch::asm; use core::arch::asm;
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, // before we use the `la` pseudo-instruction for the first time,
// we need to set `gp` (google linker relaxation) // we need to set `gp` (look up linker relaxation)
".option push", // pushes the current option stack ".option push", // pushes the current option stack
".option norelax", // disable relaxation so we can properly set `gp` ".option norelax", // disable relaxation so we can properly set `gp`
// this instruction compiles to: // this instruction compiles to:
@ -38,7 +42,14 @@ unsafe extern "C" fn _enter() -> ! {
"bne t0, t1, 1b", "bne t0, t1, 1b",
"2:", "2:",
// BSS is clear! // 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-call" to {start} (call without saving a return address)
"tail {start}", "tail {start}",
start = sym start, // {start} refers to the function [start] below start = sym start, // {start} refers to the function [start] below
@ -62,8 +73,10 @@ extern "C" fn start() -> ! {
unsafe { uart::init_console(0x1000_0000) }; unsafe { uart::init_console(0x1000_0000) };
println!("Hello, world!"); println!("Hello, world!");
// print current hartid
println!("hartid: {}", riscv::register::mhartid::read()); println!("hartid: {}", riscv::register::mhartid::read());
// poll console for input and print characters back
loop { loop {
let c = uart::CONSOLE.lock().as_mut().and_then(uart::Device::get); let c = uart::CONSOLE.lock().as_mut().and_then(uart::Device::get);
if let Some(c) = c { if let Some(c) = c {
@ -74,6 +87,7 @@ extern "C" fn start() -> ! {
#[panic_handler] #[panic_handler]
fn on_panic(info: &PanicInfo) -> ! { fn on_panic(info: &PanicInfo) -> ! {
// print panic info and hang
println!("{}", info); println!("{}", info);
loop {} loop {}