summaryrefslogtreecommitdiff
path: root/kernel/src/lib.rs
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-08-26 20:53:46 -0500
committerNathan Ringo <nathan@remexre.com>2024-08-26 20:53:46 -0500
commitd10960f7fc664189f70fb634581958a4a1fd99fa (patch)
treefa39b8939fff7694f7e9cbcdf4bbd70e53500b6f /kernel/src/lib.rs
parent76f0764cebe313a75b9b170fa23fa940d9e5738a (diff)
Refactor DeviceTree parsing.
Diffstat (limited to 'kernel/src/lib.rs')
-rw-r--r--kernel/src/lib.rs47
1 files changed, 25 insertions, 22 deletions
diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs
index 840f397..bc5c5c0 100644
--- a/kernel/src/lib.rs
+++ b/kernel/src/lib.rs
@@ -25,44 +25,47 @@ use crate::prelude::*;
/// `device_tree::FlattenedDeviceTree::from_ptr` for the precise requirements.
/// - This must be called in supervisor mode with paging and traps disabled, but with all traps
/// delegated to supervisor mode.
+/// - Any other harts must not be running concurrently with us. TODO: Define their state.
#[no_mangle]
pub unsafe extern "C" fn hart0_boot(device_tree: *const u8) -> ! {
+ // Set up the logger.
+ //
+ // TODO: This should really be named something better than console.
console::init();
- info!("device_tree = {device_tree:?}");
+ // Parse the DeviceTree.
let flattened_device_tree = unsafe { device_tree::FlattenedDeviceTree::from_ptr(device_tree) }
.expect("invalid DeviceTree");
- for event in flattened_device_tree.struct_events() {
- let event = event.expect("invalid DeviceTree");
- dbg!(event);
- }
- // Set up the allocator and the timer subsystem.
- //
- // TODO: The timer really oughta be later...
+ // Find the available physical memory areas and initialize the physical memory
+ // free-list.
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.
+ .for_each_node(|node| {
+ if node.is_unit(&["", "cpus"]) {
+ // TODO: Do this later.
+ if let Some(timebase_frequency) = node.get_prop_u32("timebase-frequency") {
+ // SAFETY: Other harts are not concurrently running, so they can't be
+ // concurrently accessing or 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:?}");
+ } else if node.is_unit(&["", "memory"]) {
+ // Get the memory ranges.
+ let Some(reg) = node.get_reg_usize() else {
+ warn!("{}reg was not valid", node.name());
+ return Ok(());
+ };
+
+ for (addr, size) in reg {
+ info!("found memory: addr = {addr:#x}, size = {size:#x}");
+ }
}
Ok(())
})
- .map_err(|err| err.left_or_else(|void| void::unreachable(void)))
- .expect("invalid DeviceTree");
+ .unwrap_or_else(|err| void::unreachable(err));
+ // After this point, everything else is for debugging.
interrupts::example_timer();
info!("sleeping forever...");
loop {