(BIG CHANGE) memory handling has changed, MMIO is now a 2 level page table, misaligned access supported, addresses not internally split to page and offset immediately, all load/store instructions implemented. Might still have bugs

This commit is contained in:
2025-12-26 14:20:27 +01:00
parent 6d9efb7eb8
commit 528b519ce9
9 changed files with 478 additions and 456 deletions

View File

@@ -13,9 +13,9 @@ use std::time::Duration;
use nix::fcntl::fcntl;
use nix::fcntl::{FcntlArg, OFlag};
use trve::consts::{Byte, DWord, HWord, Word};
use trve::exceptions::ExceptionType;
use trve::mem::{MemDeviceInterface, PageNum};
use trve::consts::{Addr, Byte};
use trve::exceptions::MemoryExceptionType;
use trve::mem::MemDeviceInterface;
/// byte 0: rx/tx
/// byte 1: status (------rt, r=rxready, t=txready)/none
@@ -78,79 +78,20 @@ impl BasicUart {
}
impl MemDeviceInterface for BasicUart {
fn write_dword(
&self,
_page: PageNum,
_offset: u16,
_value: DWord,
) -> Result<(), ExceptionType> {
Err(ExceptionType::StoreAmoAccessFault)
}
fn write_word(&self, _page: PageNum, _offset: u16, _value: Word) -> Result<(), ExceptionType> {
Err(ExceptionType::StoreAmoAccessFault)
}
fn write_hword(
&self,
_page: PageNum,
_offset: u16,
_value: HWord,
) -> Result<(), ExceptionType> {
Err(ExceptionType::StoreAmoAccessFault)
}
fn write_byte(&self, page: PageNum, offset: u16, value: Byte) -> Result<(), ExceptionType> {
if page > 0 {
return Err(ExceptionType::StoreAmoAccessFault);
}
match offset {
fn write_byte(&self, addr: Addr, value: Byte) -> Result<(), MemoryExceptionType> {
match addr {
0 => {
self.write(value);
Ok(())
}
_ => Err(ExceptionType::StoreAmoAccessFault),
_ => Err(MemoryExceptionType::AccessFault),
}
}
fn read_dword(&self, _page: PageNum, _offset: u16) -> Result<DWord, ExceptionType> {
Err(ExceptionType::LoadAccessFault)
}
fn read_word(&self, _page: PageNum, _offset: u16) -> Result<Word, ExceptionType> {
Err(ExceptionType::LoadAccessFault)
}
fn read_hword(&self, _page: PageNum, _offset: u16) -> Result<HWord, ExceptionType> {
Err(ExceptionType::LoadAccessFault)
}
fn read_byte(&self, page: PageNum, offset: u16) -> Result<Byte, ExceptionType> {
if page > 0 {
return Err(ExceptionType::LoadAccessFault);
}
match offset {
fn read_byte(&self, addr: Addr) -> Result<Byte, MemoryExceptionType> {
match addr {
0 => Ok(self.read()),
1 => Ok(1 | (self.can_read() as u8) << 1),
_ => Err(ExceptionType::LoadAccessFault),
_ => Err(MemoryExceptionType::AccessFault),
}
}
fn get_atomic_word(
&self,
_page: PageNum,
_offset: u16,
) -> Result<&std::sync::atomic::AtomicU32, ExceptionType> {
Err(ExceptionType::StoreAmoAccessFault)
}
fn get_atomic_dword(
&self,
_page: PageNum,
_offset: u16,
) -> Result<&std::sync::atomic::AtomicU64, ExceptionType> {
Err(ExceptionType::StoreAmoAccessFault)
}
}