Potentially fix a double page fault issue under certain conditions

This commit is contained in:
Ry 2022-09-15 23:41:46 -07:00
parent 02f3d04f4f
commit d30dad4797

View File

@ -232,30 +232,34 @@ impl Memory {
pub fn write_8(&mut self, mut address: u32, byte: u8) { pub fn write_8(&mut self, mut address: u32, byte: u8) {
let mut writable = true; let mut writable = true;
let mut ok = true;
if *self.mmu_enabled() { if *self.mmu_enabled() {
(address, writable) = self.virtual_to_physical(address as u32).unwrap_or_else(|| { (address, writable) = self.virtual_to_physical(address as u32).unwrap_or_else(|| {
self.exception_sender().send(Exception::PageFaultWrite(address)).unwrap(); self.exception_sender().send(Exception::PageFaultWrite(address)).unwrap();
ok = false;
(0, false) (0, false)
}); });
} }
if writable { if ok {
let address = address as usize; if writable {
let address = address as usize;
if address >= MEMORY_ROM_START && address < MEMORY_ROM_START + MEMORY_ROM_SIZE { if address >= MEMORY_ROM_START && address < MEMORY_ROM_START + MEMORY_ROM_SIZE {
error(&format!("attempting to write to ROM address: {:#010X}", address)); error(&format!("attempting to write to ROM address: {:#010X}", address));
} }
match self.ram().get_mut(address - MEMORY_RAM_START) { match self.ram().get_mut(address - MEMORY_RAM_START) {
Some(value) => { Some(value) => {
*value = byte; *value = byte;
} }
None => { None => {
self.exception_sender().send(Exception::PageFaultWrite(address as u32)).unwrap(); self.exception_sender().send(Exception::PageFaultWrite(address as u32)).unwrap();
}
} }
} else {
self.exception_sender().send(Exception::PageFaultWrite(address)).unwrap();
} }
} else {
self.exception_sender().send(Exception::PageFaultWrite(address)).unwrap();
} }
} }
pub fn write_16(&mut self, address: u32, half: u16) { pub fn write_16(&mut self, address: u32, half: u16) {