Fix endianness issues particulary with strings
This commit is contained in:
parent
5f8965b94d
commit
5000c28b97
@ -154,13 +154,17 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
|
|||||||
let f = machine.read_int_register(12);
|
let f = machine.read_int_register(12);
|
||||||
|
|
||||||
// load buffer
|
// load buffer
|
||||||
let mut buffer = "".to_string();
|
let mut buffer = String::new();
|
||||||
|
let mut val: [u8; 4] = [0; 4];
|
||||||
|
for (j, elem) in val.iter_mut().enumerate() {
|
||||||
|
*elem = machine.read_memory(1, address as usize + j) as u8;
|
||||||
|
}
|
||||||
for i in 0..size {
|
for i in 0..size {
|
||||||
buffer.push((machine.read_memory(1, (address + i) as usize)) as u8 as char);
|
buffer.push((machine.read_memory(1, (address + i) as usize)) as u8 as char);
|
||||||
}
|
}
|
||||||
|
|
||||||
if f as u8 == CONSOLE_OUTPUT {
|
if f as u8 == CONSOLE_OUTPUT {
|
||||||
println!("{}", buffer); // todo replace with console driver in the future
|
print!("{}", buffer); // todo replace with console driver in the future
|
||||||
Ok(MachineOk::Ok)
|
Ok(MachineOk::Ok)
|
||||||
} else {
|
} else {
|
||||||
Err("SC_WRITE to file is not yet implemented")?
|
Err("SC_WRITE to file is not yet implemented")?
|
||||||
|
@ -463,7 +463,12 @@ impl Loader {
|
|||||||
buf[k] = self.bytes.get(section.image_offset as usize + j + k).copied().ok_or(LoaderError::ParsingError(format!("index 0x{:x} is out of bound because list have a size of 0x{:x} (image offset 0x{:x}, j 0x{:x}, k 0x{:x})", section.image_offset as usize + j + k, self.bytes.len(), section.image_offset, j, k)))?;
|
buf[k] = self.bytes.get(section.image_offset as usize + j + k).copied().ok_or(LoaderError::ParsingError(format!("index 0x{:x} is out of bound because list have a size of 0x{:x} (image offset 0x{:x}, j 0x{:x}, k 0x{:x})", section.image_offset as usize + j + k, self.bytes.len(), section.image_offset, j, k)))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
machine.write_memory(4, start_index + section.virt_addr as usize + j, u32::from_le_bytes(buf) as u64);
|
|
||||||
|
machine.write_memory(1, start_index + section.virt_addr as usize + j, buf[0] as u64);
|
||||||
|
machine.write_memory(1, start_index + section.virt_addr as usize + j + 1, buf[1] as u64);
|
||||||
|
machine.write_memory(1, start_index + section.virt_addr as usize + j + 2, buf[2] as u64);
|
||||||
|
machine.write_memory(1, start_index + section.virt_addr as usize + j + 3, buf[3] as u64);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ impl Machine {
|
|||||||
*elem = self.main_memory[self.pc as usize + i];
|
*elem = self.main_memory[self.pc as usize + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
let val = u32::from_be_bytes(val) as u64;
|
let val = u32::from_le_bytes(val) as u64;
|
||||||
let inst : Instruction = Instruction::new(val);
|
let inst : Instruction = Instruction::new(val);
|
||||||
if self.debug {
|
if self.debug {
|
||||||
self.print_status();
|
self.print_status();
|
||||||
|
Loading…
Reference in New Issue
Block a user