Make execload respect the static ram start

This commit is contained in:
2025-12-26 19:32:55 +01:00
parent 34034dd5db
commit a64fcaa3b5
2 changed files with 6 additions and 6 deletions

View File

@@ -14,9 +14,9 @@ use goblin::{
program_header::PT_LOAD, program_header::PT_LOAD,
}, },
}; };
use trve::consts::Addr; use trve::{consts::Addr, mem::RAM_START};
pub fn load<P: AsRef<Path>>(path: P, ram: &mut [u8], ram_start: Addr) -> Result<Addr> { pub fn load<P: AsRef<Path>>(path: P, ram: &mut [u8]) -> Result<Addr> {
let buf = fs::read(path)?; let buf = fs::read(path)?;
match Object::parse(&buf)? { match Object::parse(&buf)? {
@@ -36,11 +36,11 @@ pub fn load<P: AsRef<Path>>(path: P, ram: &mut [u8], ram_start: Addr) -> Result<
for ph in elf.program_headers { for ph in elf.program_headers {
if ph.p_type == PT_LOAD { 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 end = start + ph.p_memsz as usize;
let file_end = start + ph.p_filesz 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); bail!("Segment at 0x{:x} does not fit in RAM", ph.p_vaddr);
} }
@@ -60,7 +60,7 @@ pub fn load<P: AsRef<Path>>(path: P, ram: &mut [u8], ram_start: Addr) -> Result<
bail!("Program too large for RAM"); bail!("Program too large for RAM");
} }
ram[..buf.len()].copy_from_slice(&buf); ram[..buf.len()].copy_from_slice(&buf);
Ok(ram_start) Ok(RAM_START)
} }
_ => bail!("Unsupported executable format"), _ => bail!("Unsupported executable format"),
} }

View File

@@ -30,7 +30,7 @@ fn main() -> Result<()> {
bail!("Wrong number of arguments"); 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(); let mut mmio_root = MmioRoot::default();
mmio_root.insert(0, Arc::new(DbgOut)); mmio_root.insert(0, Arc::new(DbgOut));