xous-core/loader/src/debug.rs
bunnie 483e8f3508 the great loader culling
The loader grew a lot of hair over the past few months as it
was abused as a baremetal environment for chip bring-up.

A baremetal environment was explicitly created to help with that,
so we don't have to pollute the loader with lots of unused features
and ancilliary code.

Furthermore, a decision was made to eliminate updates from the
loader code base - the loader is just for setting up Xous. This
allows the loader to be more platform-agnostic.

Boot1 instead contains all the platform-specific code for doing updates.

For completeness, we note that boot0 is a minimal piece of code that is the
first step in the chain of trust and is intended to be a read-only
segment of code that has public keys baked into it that are used
to bootstrap the rest of the ecosystem.

At this point, the loader is now slimmed down and runs. Still needs
testing to make sure the culling wasn't too aggressive, but I am
much happier with where this is landing as the loader is once again
just focused on getting Xous up and running.
2025-10-01 14:57:40 +08:00

122 lines
3.2 KiB
Rust

use utralib::generated::*;
#[allow(dead_code)]
pub struct Uart {
// pub base: *mut u32,
}
impl Uart {
#[cfg(any(feature = "precursor", feature = "renode"))]
#[allow(dead_code)]
pub fn putc(&self, c: u8) {
let base = utra::uart::HW_UART_BASE as *mut u32;
let mut uart = CSR::new(base);
// Wait until TXFULL is `0`
while uart.r(utra::uart::TXFULL) != 0 {}
uart.wo(utra::uart::RXTX, c as u32)
}
#[cfg(any(feature = "bao1x"))]
pub fn putc(&self, c: u8) {
use bao1x_hal::udma;
let buf: [u8; 1] = [c];
let uart_buf_addr = bao1x_hal::board::UART_DMA_TX_BUF_PHYS;
let mut udma_uart = unsafe {
// safety: this is safe to call, because boot1 setup the console for us
udma::Uart::get_handle(utra::udma_uart_2::HW_UDMA_UART_2_BASE, uart_buf_addr, uart_buf_addr)
};
udma_uart.write(&buf);
}
}
use core::fmt::{Error, Write};
impl Write for Uart {
fn write_str(&mut self, s: &str) -> Result<(), Error> {
for c in s.bytes() {
self.putc(c);
}
Ok(())
}
}
#[macro_use]
#[cfg(all(not(test), feature = "debug-print"))]
pub mod debug_print_hardware {
#[macro_export]
macro_rules! print
{
($($args:tt)+) => ({
use core::fmt::Write;
let _ = write!(crate::debug::Uart {}, $($args)+);
});
}
}
#[macro_use]
#[cfg(all(not(test), not(feature = "debug-print")))]
mod debug_print_hardware {
#[macro_export]
#[allow(unused_variables)]
macro_rules! print {
($($args:tt)+) => {{}};
}
}
#[macro_use]
#[cfg(test)]
mod debug_print_hardware {
#[macro_export]
#[allow(unused_variables)]
macro_rules! print {
($($args:tt)+) => ({
std::print!($($args)+)
});
}
}
#[macro_export]
macro_rules! println
{
() => ({
$crate::print!("\r\n")
});
($fmt:expr) => ({
$crate::print!(concat!($fmt, "\r\n"))
});
($fmt:expr, $($args:tt)+) => ({
$crate::print!(concat!($fmt, "\r\n"), $($args)+)
});
}
pub fn print_pagetable(root: usize) {
use crate::PageTable;
println!("Memory Maps (SATP: {:08x} Root: {:08x}):", root, root << 12);
let l1_pt = unsafe { &mut (*((root << 12) as *mut PageTable)) };
for (i, l1_entry) in l1_pt.entries.iter().enumerate() {
if *l1_entry == 0 {
continue;
}
let _superpage_addr = i as u32 * (1 << 22);
println!(
" {:4} Superpage for {:08x} @ {:08x} (flags: {:03x})",
i,
_superpage_addr,
(*l1_entry >> 10) << 12,
l1_entry & 0x3ff
);
// let l0_pt_addr = ((l1_entry >> 10) << 12) as *const u32;
let l0_pt = unsafe { &mut (*(((*l1_entry >> 10) << 12) as *mut PageTable)) };
for (j, l0_entry) in l0_pt.entries.iter().enumerate() {
if *l0_entry == 0 {
continue;
}
let _page_addr = j as u32 * (1 << 12);
println!(
" {:4} {:08x} -> {:08x} (flags: {:03x})",
j,
_superpage_addr + _page_addr,
(*l0_entry >> 10) << 12,
l0_entry & 0x3ff
);
}
}
}