fox32: Add 3 extra bytes at the end of fast and shared memory

Because Operand::ImmediatePtr always reads 4 bytes (even if the
instruction size is smaller), attempting to read the last byte of
memory through a pointer would cause fox32 to warn about reading
unmapped memory. Adding 3 extra bytes to the end of memory prevents
this.
This commit is contained in:
ry755 2022-02-01 23:07:51 -08:00 committed by Ry
parent 29d6690d97
commit fe476414b7
2 changed files with 11 additions and 6 deletions

View File

@ -66,21 +66,25 @@ fn main() {
let mouse = Arc::new(Mutex::new(Mouse::new()));
// 32 MiB of shared memory
let shared_memory = Arc::new(Mutex::new(vec![0u8; 0x02000000]));
// plus 3 bytes at the end to allow for reading the last byte of memory as an immediate pointer
// Operand::ImmediatePtr always reads 4 bytes
let shared_memory = Arc::new(Mutex::new(vec![0u8; 0x02000003]));
let mut cpu = {
// 32 MiB of fast memory
let cpu_fast_memory = vec![0; 0x02000000];
// plus 3 extra bytes at the end to allow for reading the last byte of memory as an immediate pointer
// Operand::ImmediatePtr always reads 4 bytes
let cpu_fast_memory = vec![0; 0x02000003];
let cpu_shared_memory = Arc::clone(&shared_memory);
let cpu_overlays = Arc::clone(&display.overlays);
let cpu_read_only_memory = read_rom();
let fast_size = cpu_fast_memory.len();
let fast_size = cpu_fast_memory.len() - 3;
let fast_bottom_address = 0x00000000;
let fast_top_address = fast_bottom_address + fast_size - 1;
println!("Fast: {:.2}MB mapped at {:#010X}-{:#010X}", fast_size / 1048576, fast_bottom_address, fast_top_address);
let shared_size = { cpu_shared_memory.lock().unwrap().len() };
let shared_size = { cpu_shared_memory.lock().unwrap().len() - 3 };
let shared_bottom_address = 0x80000000;
let shared_top_address = shared_bottom_address + shared_size - 1;
println!("Shared: {:.2}MB mapped at {:#010X}-{:#010X}", shared_size / 1048576, shared_bottom_address, shared_top_address);

View File

@ -18,9 +18,10 @@ pub struct Memory {
impl Memory {
pub fn new(fast_memory: Vec<u8>, shared_memory: Arc<Mutex<Vec<u8>>>, overlays: Arc<Mutex<Vec<Overlay>>>, rom: Vec<u8>) -> Self {
let shared_memory_size = { shared_memory.lock().unwrap().len() };
// 3 extra bytes at the end to allow for reading the last byte of memory as an immediate pointer
let shared_memory_size = { shared_memory.lock().unwrap().len() - 3 };
Memory {
fast_memory_size: fast_memory.len(),
fast_memory_size: fast_memory.len() - 3,
fast_memory,
shared_memory_size,
shared_memory,