Merge pull request #10 from neuschaefer/dev
Refactor physical memory address resolution code
This commit is contained in:
commit
e6af577da5
31
src/cpu.c
31
src/cpu.c
|
@ -420,9 +420,9 @@ static uint32_t *vm_findlocal(vm_t *vm, uint8_t local) {
|
||||||
vm_panic(vm, FOX32_ERR_BADREGISTER);
|
vm_panic(vm, FOX32_ERR_BADREGISTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t *vm_findmemory(vm_t *vm, uint32_t address, uint32_t size, bool write) {
|
static uint8_t *vm_findmemory_phys(vm_t *vm, uint32_t address, uint32_t size, bool write) {
|
||||||
uint32_t address_end = address + size;
|
uint32_t address_end = address + size;
|
||||||
if (!vm->mmu_enabled) {
|
|
||||||
if (address_end > address) {
|
if (address_end > address) {
|
||||||
if (address_end <= FOX32_MEMORY_RAM) {
|
if (address_end <= FOX32_MEMORY_RAM) {
|
||||||
return &vm->memory_ram[address];
|
return &vm->memory_ram[address];
|
||||||
|
@ -442,6 +442,11 @@ static uint8_t *vm_findmemory(vm_t *vm, uint32_t address, uint32_t size, bool wr
|
||||||
vm->exception_operand = address;
|
vm->exception_operand = address;
|
||||||
vm_panic(vm, FOX32_ERR_FAULT_WR);
|
vm_panic(vm, FOX32_ERR_FAULT_WR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t *vm_findmemory(vm_t *vm, uint32_t address, uint32_t size, bool write) {
|
||||||
|
if (!vm->mmu_enabled) {
|
||||||
|
return vm_findmemory_phys(vm, address, size, write);
|
||||||
} else {
|
} else {
|
||||||
mmu_page_t *virtual_page = get_present_page(address);
|
mmu_page_t *virtual_page = get_present_page(address);
|
||||||
if (virtual_page == NULL) {
|
if (virtual_page == NULL) {
|
||||||
|
@ -459,26 +464,8 @@ static uint8_t *vm_findmemory(vm_t *vm, uint32_t address, uint32_t size, bool wr
|
||||||
}
|
}
|
||||||
uint32_t offset = address & 0x00000FFF;
|
uint32_t offset = address & 0x00000FFF;
|
||||||
uint32_t physical_address = virtual_page->physical_address | offset;
|
uint32_t physical_address = virtual_page->physical_address | offset;
|
||||||
address_end = physical_address + size;
|
|
||||||
if (address_end > physical_address) {
|
return vm_findmemory_phys(vm, physical_address, size, write);
|
||||||
if (address_end <= FOX32_MEMORY_RAM) {
|
|
||||||
return &vm->memory_ram[physical_address];
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
!write &&
|
|
||||||
(physical_address >= FOX32_MEMORY_ROM_START) &&
|
|
||||||
(physical_address -= FOX32_MEMORY_ROM_START) + size <= FOX32_MEMORY_ROM
|
|
||||||
) {
|
|
||||||
return &vm->memory_rom[physical_address];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!write) {
|
|
||||||
vm->exception_operand = address;
|
|
||||||
vm_panic(vm, FOX32_ERR_FAULT_RD);
|
|
||||||
} else {
|
|
||||||
vm->exception_operand = address;
|
|
||||||
vm_panic(vm, FOX32_ERR_FAULT_WR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user