feat: implement MMU core functionality

* feat: Implement a basic MMU configuration

* feat: Enhance MMU by separating sections and configuring permissions

* feat: Update MMU configuration and memory allocation functions

* fix: Level 3 translation fault

* docs: add code documentation

* fix: linter

* feat: map translation tables to kernel space

* feat: move el1 stack to kernel VA space

* feat: use virtual memory for heap allocation

* docs: update Readme
This commit is contained in:
Alexander Neuhäuser
2026-03-17 19:30:45 +01:00
committed by GitHub
parent 55f410e2bb
commit f78388ee2c
23 changed files with 992 additions and 264 deletions

View File

@@ -1,2 +1,3 @@
pub mod mailbox;
pub mod power_management;
pub mod timer;

View File

@@ -3,7 +3,7 @@ use core::ptr::{read_volatile, write_volatile};
use crate::PERIPHERAL_BASE;
/// Power Management Base
static PM_BASE: u32 = PERIPHERAL_BASE + 0x10_0000;
static PM_BASE: u32 = PERIPHERAL_BASE as u32 + 0x10_0000;
static PM_RSTC: u32 = PM_BASE + 0x1c;
static PM_WDOG: u32 = PM_BASE + 0x24;
@@ -23,5 +23,6 @@ pub fn reboot_system() {
PM_PASSWORD | (pm_rstc_val & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET,
);
}
#[allow(clippy::empty_loop)]
loop {}
}

61
src/pi3/timer.rs Normal file
View File

@@ -0,0 +1,61 @@
use core::{hint::spin_loop, ptr::read_volatile};
const TIMER_CLOCK_LO: u32 = 0x3F00_3004;
const TIMER_CLOCK_HI: u32 = 0x3F00_3008;
fn read_timer_32() -> u32 {
unsafe { read_volatile(TIMER_CLOCK_LO as *const u32) }
}
fn read_timer_64() -> u64 {
loop {
let clock_hi1 = unsafe { read_volatile(TIMER_CLOCK_HI as *const u32) };
let clock_lo = unsafe { read_volatile(TIMER_CLOCK_LO as *const u32) };
let clock_hi2 = unsafe { read_volatile(TIMER_CLOCK_HI as *const u32) };
// account for roll over during read
if clock_hi1 == clock_hi2 {
return ((clock_hi1 as u64) << 32) | clock_lo as u64;
}
}
}
/// Sleep for `us` microseconds
pub fn sleep_us(us: u64) {
if us < u32::MAX as u64 {
sleep_us_u32(us as u32);
} else {
sleep_us_u64(us);
}
}
fn sleep_us_u32(us: u32) {
let start = read_timer_32();
while read_timer_32().wrapping_sub(start) < us {
spin_loop();
}
}
fn sleep_us_u64(us: u64) {
let start = read_timer_64();
while read_timer_64().wrapping_sub(start) < us {
spin_loop();
}
}
/// Sleep for `ms` milliseconds
pub fn sleep_ms(ms: u64) {
sleep_us(ms * 1_000);
}
/// Sleep for `s` seconds
pub fn sleep_s(s: u64) {
sleep_ms(s * 1_000);
}
/// Wait for `count` operations to pass
pub fn delay_nops(count: u32) {
for _ in 0..count {
spin_loop()
}
}