ft(interpreter): impl file-based minix interrupts
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user