From a64fcaa3b557d3e7f611f3997a0b4c6990347d9b Mon Sep 17 00:00:00 2001 From: taitep Date: Fri, 26 Dec 2025 19:32:55 +0100 Subject: [PATCH] Make execload respect the static ram start --- src/execload.rs | 10 +++++----- src/main.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/execload.rs b/src/execload.rs index 12fe90d..70c1d65 100644 --- a/src/execload.rs +++ b/src/execload.rs @@ -14,9 +14,9 @@ use goblin::{ program_header::PT_LOAD, }, }; -use trve::consts::Addr; +use trve::{consts::Addr, mem::RAM_START}; -pub fn load>(path: P, ram: &mut [u8], ram_start: Addr) -> Result { +pub fn load>(path: P, ram: &mut [u8]) -> Result { let buf = fs::read(path)?; match Object::parse(&buf)? { @@ -36,11 +36,11 @@ pub fn load>(path: P, ram: &mut [u8], ram_start: Addr) -> Result< for ph in elf.program_headers { if ph.p_type == PT_LOAD { - let start = (ph.p_vaddr - ram_start) as usize; + let start = (ph.p_vaddr - RAM_START) as usize; let end = start + ph.p_memsz as usize; let file_end = start + ph.p_filesz as usize; - if end > ram_start as usize + ram.len() { + if end > RAM_START as usize + ram.len() { bail!("Segment at 0x{:x} does not fit in RAM", ph.p_vaddr); } @@ -60,7 +60,7 @@ pub fn load>(path: P, ram: &mut [u8], ram_start: Addr) -> Result< bail!("Program too large for RAM"); } ram[..buf.len()].copy_from_slice(&buf); - Ok(ram_start) + Ok(RAM_START) } _ => bail!("Unsupported executable format"), } diff --git a/src/main.rs b/src/main.rs index b3393d3..03072f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ fn main() -> Result<()> { bail!("Wrong number of arguments"); } - let entry_point = execload::load(&args[1], buf, 0x8000_0000)?; + let entry_point = execload::load(&args[1], buf)?; let mut mmio_root = MmioRoot::default(); mmio_root.insert(0, Arc::new(DbgOut));