Add a basic UART (very much temporary, its performance is most likely horrible

This commit is contained in:
2025-12-21 15:27:39 +01:00
parent eec40b069a
commit 0457530e0c
2 changed files with 174 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ use std::{
fs::File,
io::{self, Read},
sync::Arc,
time::Duration,
};
use trve::{
@@ -17,6 +18,8 @@ use trve::{
mem::{DeviceEntry, MemAccessFault, MemConfig, MemDeviceInterface, PageNum, Ram},
};
use crate::basic_uart::BasicUart;
fn read_file_to_buffer(path: &str, buffer: &mut [u8]) -> io::Result<usize> {
let mut file = File::open(path)?;
let mut total_read = 0;
@@ -42,14 +45,24 @@ fn main() -> Result<(), Box<dyn Error>> {
let buf = ram.buf_mut();
read_file_to_buffer("./img", buf)?;
let uart = BasicUart::new();
let uart = uart.spawn_poller(Duration::from_millis(10));
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),
}]),
devices: Box::new([
DeviceEntry {
base: 0,
size: 1,
interface: Arc::new(DbgOut),
},
DeviceEntry {
base: 1,
size: 1,
interface: uart,
},
]),
};
let mut core = Core::new(mem_cfg);
@@ -59,6 +72,8 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}
mod basic_uart;
struct DbgOut;
impl MemDeviceInterface for DbgOut {