ft(interpreter): impl file-based minix interrupts

This commit is contained in:
2025-07-24 11:42:15 +09:00
parent 75e9df9be9
commit b3a24ade00
4 changed files with 125 additions and 3 deletions

View File

@@ -62,4 +62,27 @@ impl Memory {
log::debug!("Read raw byte {b1:#04x} and {b2:#04x}, starting at addr {addr:#04x}");
Ok(Word::from_le_bytes([b1, b2]))
}
/// Try to read C null-terminated string from memory location
/// BUG: This does not use segment registers for indexing!
pub fn read_c_string(&self, addr: usize) -> Option<String> {
let mem = &self.raw;
if addr >= mem.len() {
return None;
}
let raw = &mem[addr..];
log::debug!("Raw is {:?}", &raw[..=16]);
let nul_pos = raw.iter().position(|&b| b == 0)?;
log::debug!("Starting to read at {addr} until {nul_pos}");
let c_slice = &raw[..=nul_pos];
let c_str = std::ffi::CStr::from_bytes_with_nul(c_slice).ok()?;
c_str.to_str().ok().map(|s| s.to_owned())
}
}