From 2753bc906bf11093aadff8cbb00f6d8ffec58ade Mon Sep 17 00:00:00 2001 From: gil Date: Tue, 28 May 2024 21:17:29 -0500 Subject: [PATCH] Ordering nits, changing target --- .cargo/config.toml | 4 ++-- src/main.rs | 28 ++++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 72f0ac0..9f92d7a 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,7 +1,7 @@ # .cargo/config.toml [build] -target = "riscv64imac-unknown-none-elf" +target = "riscv64gc-unknown-none-elf" # Options for riscv32 (not currently in use) # @@ -15,7 +15,7 @@ target = "riscv64imac-unknown-none-elf" # -serial mon:stdio # -bios """ -[target.riscv64imac-unknown-none-elf] +[target.riscv64gc-unknown-none-elf] runner = """ qemu-system-riscv64 -cpu rv64 -smp 4 diff --git a/src/main.rs b/src/main.rs index 4f488fe..a1870ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ core::arch::global_asm!(include_str!("entry.s")); #[allow(unreachable_code)] unsafe extern "C" fn start() { use core::arch::asm; - use riscv::register::{mstatus, pmpaddr0, satp, sie, sstatus}; + use riscv::register::{mstatus, satp, sie, sstatus}; // Set previous privilege for all harts to M-mode, set previous interrupt // enable, and set floating-point unit to initial state @@ -26,6 +26,12 @@ unsafe extern "C" fn start() { mstatus::set_mpie(); mstatus::set_fs(sstatus::FS::Initial); + // For use with + // asm!( + // "la t1, main", + // "csrw mepc, t1", + // ); + // Disable paging satp::write(0); @@ -38,15 +44,14 @@ unsafe extern "C" fn start() { sie::set_stimer(); sie::set_ssoft(); - // hhhh - // pmpaddr0::write(0x3fffffffffffff_usize); - // TODO configure PMP + // Use PMP to give S-mode full access to memory + // pmpaddr0::write(0x3fffffffffffff); + // pmpcfg0::write(0xf); + // TODO timer init - // Trying to figure out why I can't use mret here. Might need + // Trying to figure out why I can't use mret here // asm!( - // "la t1, main", - // "csrw mepc, t1", // "mret", // options(noreturn), // ); @@ -64,7 +69,7 @@ extern "C" fn main() { // Disable machine interrupts while initializing interrupt::machine::disable(); console_init(); - // TODO Write boot message + println!("boot: console initiated, setting up paging/processes (TODO)"); // TODO Set up paging // TODO Set up processes @@ -73,6 +78,7 @@ extern "C" fn main() { // TODO Set up PLIC kinit(); + unsafe { mstatus::set_mpp(mstatus::MPP::User); mstatus::set_mpie(); @@ -80,6 +86,8 @@ extern "C" fn main() { mstatus::set_fs(sstatus::FS::Initial); } + println!("msg: Hello from hart {}!", hartid()); + riscv::asm::fence(); // Emit a fence just in case }); @@ -92,7 +100,7 @@ extern "C" fn main() { INIT_LOCK.wait(); riscv::asm::fence(); // Emit a fence just in case kinit_hart(); - println!("Hello from hart {}!", hartid()); + println!("msg: Hello from hart {}!", hartid()); } } @@ -102,7 +110,7 @@ fn console_init() { // Set up UART and print to console uart::init_console(0x1000_0000); - println!("Hello from hart {}!", hartid()); + println!("init: console"); } fn kinit() {}