diff options
| author | taitep <taitep@taitep.se> | 2025-12-26 14:20:27 +0100 |
|---|---|---|
| committer | taitep <taitep@taitep.se> | 2025-12-26 14:20:27 +0100 |
| commit | 528b519ce98c21049705526442cbde1672495b49 (patch) | |
| tree | 487714ef8a58c9610da6b97d76ecd97e58b8b921 /src/main.rs | |
| parent | 6d9efb7eb85af929f3d6c22111933bb58d1ea07e (diff) | |
(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
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 83 |
1 files changed, 17 insertions, 66 deletions
diff --git a/src/main.rs b/src/main.rs index 615f3bf..b3393d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,10 +7,10 @@ use std::{env, sync::Arc, time::Duration}; use trve::{ - consts::{Byte, DWord, HWord, Word}, + consts::{Addr, Byte, DWord, HWord, Word}, core::Core, - exceptions::ExceptionType, - mem::{DeviceEntry, MemConfig, MemDeviceInterface, PageNum, Ram}, + exceptions::MemoryExceptionType, + mem::{MemConfig, MemDeviceInterface, MmioRoot, Ram}, }; use anyhow::{Result, bail}; @@ -20,7 +20,7 @@ use crate::basic_uart::BasicUart; mod execload; fn main() -> Result<()> { - let mut ram = Ram::try_new(16 * 1024 * 1024 / 4096)?; + let mut ram = Ram::try_new(16 * 1024 * 1024)?; let buf = ram.buf_mut(); let args: Vec<String> = env::args().collect(); @@ -32,24 +32,16 @@ fn main() -> Result<()> { let entry_point = execload::load(&args[1], buf, 0x8000_0000)?; + let mut mmio_root = MmioRoot::default(); + mmio_root.insert(0, Arc::new(DbgOut)); + let uart = BasicUart::new(); let uart = uart.spawn_poller(Duration::from_millis(10)); + mmio_root.insert(0x10000, uart); let mem_cfg = MemConfig { ram: Arc::new(ram), - ram_start: 0x8000_0000 / 4096, - devices: Box::new([ - DeviceEntry { - base: 0, - size: 1, - interface: Arc::new(DbgOut), - }, - DeviceEntry { - base: 1, - size: 1, - interface: uart, - }, - ]), + mmio_root, }; let mut core = Core::new(mem_cfg); @@ -64,64 +56,23 @@ mod basic_uart; struct DbgOut; impl MemDeviceInterface for DbgOut { - fn write_dword(&self, page: PageNum, offset: u16, value: DWord) -> Result<(), ExceptionType> { - eprintln!( - "Wrote DWord {value:016x} to Debug-Out page {page}, offset {offset} (byte {})", - offset * 8 - ); + fn write_dword(&self, addr: Addr, value: DWord) -> Result<(), MemoryExceptionType> { + eprintln!("Wrote DWord {value:016x} to Debug-Out address {addr:x}"); Ok(()) } - fn write_word(&self, page: PageNum, offset: u16, value: Word) -> Result<(), ExceptionType> { - eprintln!( - "Wrote Word {value:08x} to Debug-Out page {page}, offset {offset} (byte {})", - offset * 4 - ); + fn write_word(&self, addr: Addr, value: Word) -> Result<(), MemoryExceptionType> { + eprintln!("Wrote Word {value:08x} to Debug-Out address {addr:x}"); Ok(()) } - fn write_hword(&self, page: PageNum, offset: u16, value: HWord) -> Result<(), ExceptionType> { - eprintln!( - "Wrote HWord {value:04x} to Debug-Out page {page}, offset {offset} (byte {})", - offset * 2 - ); + fn write_hword(&self, addr: Addr, value: HWord) -> Result<(), MemoryExceptionType> { + eprintln!("Wrote HWord {value:04x} to Debug-Out address {addr:x}"); Ok(()) } - fn write_byte(&self, page: PageNum, offset: u16, value: Byte) -> Result<(), ExceptionType> { - eprintln!("Wrote Byte {value:02x} to Debug-Out page {page}, offset {offset}"); + fn write_byte(&self, addr: Addr, value: Byte) -> Result<(), MemoryExceptionType> { + eprintln!("Wrote Byte {value:02x} to Debug-Out address {addr:x}"); Ok(()) } - - 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> { - Err(ExceptionType::LoadAccessFault) - } - - 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) - } } |
