diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-08-26 15:25:55 -0500 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-08-26 15:25:55 -0500 |
commit | 76f0764cebe313a75b9b170fa23fa940d9e5738a (patch) | |
tree | b56641c41748594582aa56f9a539f04152cfc108 /kernel/src/lib.rs | |
parent | f1897c47a8f03955b76d521d1843a25123bd65a2 (diff) |
The start of interrupt and timer support, with some DeviceTree parsing.
Diffstat (limited to 'kernel/src/lib.rs')
-rw-r--r-- | kernel/src/lib.rs | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 0a724c6..840f397 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -1,12 +1,21 @@ #![no_std] +#[macro_use] +pub mod util; + +pub mod allocators; +pub mod collections; pub mod console; pub mod device_tree; -pub mod util; +pub mod drivers; +pub mod interrupts; +pub mod prelude; #[cfg(not(test))] mod panic; +use crate::prelude::*; + /// The entrypoint to the kernel. This should be executed by hart0 alone. It performs some early /// boot tasks, then wakes up any other harts. /// @@ -20,7 +29,7 @@ mod panic; pub unsafe extern "C" fn hart0_boot(device_tree: *const u8) -> ! { console::init(); - log::info!("device_tree = {device_tree:?}"); + info!("device_tree = {device_tree:?}"); let flattened_device_tree = unsafe { device_tree::FlattenedDeviceTree::from_ptr(device_tree) } .expect("invalid DeviceTree"); for event in flattened_device_tree.struct_events() { @@ -28,5 +37,35 @@ pub unsafe extern "C" fn hart0_boot(device_tree: *const u8) -> ! { dbg!(event); } - todo!() + // Set up the allocator and the timer subsystem. + // + // TODO: The timer really oughta be later... + flattened_device_tree + .for_each_property(|node, prop, value| { + if node == ["", "cpus"] && prop == "timebase-frequency" { + if value.len() == 4 { + let value = [value[0], value[1], value[2], value[3]]; + let timebase_frequency = u32::from_be_bytes(value); + // SAFETY: Nobody is concurrently running, so they can't be concurrently + // modifying this. + unsafe { + drivers::riscv_timer::TIMEBASE_FREQUENCY = timebase_frequency; + } + dbg!(timebase_frequency); + } else { + warn!("/cpus/timebase-frequency was not a 4-byte quantity"); + } + } else { + info!("{node}{prop} = {value:?}"); + } + Ok(()) + }) + .map_err(|err| err.left_or_else(|void| void::unreachable(void))) + .expect("invalid DeviceTree"); + + interrupts::example_timer(); + info!("sleeping forever..."); + loop { + unsafe { core::arch::asm!("wfi") } + } } |