Fixes to mem.c internal operation, non-RAM areas of the memory space should now be handled more sanely.

This commit is contained in:
OBattler
2020-05-02 05:41:38 +02:00
parent 5b87c654e1
commit d3618e6575

View File

@@ -680,7 +680,7 @@ writemembl(uint32_t addr, uint8_t val)
mem_mapping_t *map; mem_mapping_t *map;
mem_logical_addr = addr; mem_logical_addr = addr;
if (page_lookup[addr>>12]) { if (page_lookup[addr>>12] && page_lookup[addr>>12]->write_b) {
page_lookup[addr>>12]->write_b(addr, val, page_lookup[addr>>12]); page_lookup[addr>>12]->write_b(addr, val, page_lookup[addr>>12]);
return; return;
} }
@@ -772,7 +772,7 @@ writememwl(uint32_t addr, uint16_t val)
} }
} }
if (page_lookup[addr>>12]) { if (page_lookup[addr>>12] && page_lookup[addr>>12]->write_w) {
page_lookup[addr>>12]->write_w(addr, val, page_lookup[addr>>12]); page_lookup[addr>>12]->write_w(addr, val, page_lookup[addr>>12]);
return; return;
} }
@@ -874,7 +874,7 @@ writememll(uint32_t addr, uint32_t val)
return; return;
} }
} }
if (page_lookup[addr>>12]) { if (page_lookup[addr>>12] && page_lookup[addr>>12]->write_l) {
page_lookup[addr>>12]->write_l(addr, val, page_lookup[addr>>12]); page_lookup[addr>>12]->write_l(addr, val, page_lookup[addr>>12]);
return; return;
} }
@@ -970,7 +970,7 @@ writememql(uint32_t addr, uint64_t val)
return; return;
} }
} }
if (page_lookup[addr>>12]) { if (page_lookup[addr>>12] && page_lookup[addr>>12]->write_l) {
page_lookup[addr>>12]->write_l(addr, val, page_lookup[addr>>12]); page_lookup[addr>>12]->write_l(addr, val, page_lookup[addr>>12]);
page_lookup[addr>>12]->write_l(addr + 4, val >> 32, page_lookup[addr>>12]); page_lookup[addr>>12]->write_l(addr + 4, val >> 32, page_lookup[addr>>12]);
return; return;
@@ -1104,7 +1104,7 @@ writememwl(uint32_t seg, uint32_t addr, uint16_t val)
} }
} }
if (page_lookup[addr2>>12]) { if (page_lookup[addr2>>12] && page_lookup[addr2>>12]->write_w) {
page_lookup[addr2>>12]->write_w(addr2, val, page_lookup[addr2>>12]); page_lookup[addr2>>12]->write_w(addr2, val, page_lookup[addr2>>12]);
return; return;
} }
@@ -1209,7 +1209,7 @@ writememll(uint32_t seg, uint32_t addr, uint32_t val)
} }
} }
if (page_lookup[addr2>>12]) { if (page_lookup[addr2>>12] && page_lookup[addr2>>12]->write_l) {
page_lookup[addr2>>12]->write_l(addr2, val, page_lookup[addr2>>12]); page_lookup[addr2>>12]->write_l(addr2, val, page_lookup[addr2>>12]);
return; return;
} }
@@ -1307,7 +1307,7 @@ writememql(uint32_t seg, uint32_t addr, uint64_t val)
} }
} }
if (page_lookup[addr2>>12]) { if (page_lookup[addr2>>12] && page_lookup[addr2>>12]->write_l) {
page_lookup[addr2>>12]->write_l(addr2, val, page_lookup[addr2>>12]); page_lookup[addr2>>12]->write_l(addr2, val, page_lookup[addr2>>12]);
page_lookup[addr2>>12]->write_l(addr2 + 4, val >> 32, page_lookup[addr2>>12]); page_lookup[addr2>>12]->write_l(addr2 + 4, val >> 32, page_lookup[addr2>>12]);
return; return;
@@ -2303,7 +2303,7 @@ mem_a20_init(void)
void void
mem_reset(void) mem_reset(void)
{ {
uint32_t c, m; uint32_t c, m, m2;
m = 1024UL * mem_size; m = 1024UL * mem_size;
if (ram != NULL) { if (ram != NULL) {
@@ -2324,23 +2324,21 @@ mem_reset(void)
m = 4096; m = 4096;
} else { } else {
/* 80386+; maximum address space is 4GB. */ /* 80386+; maximum address space is 4GB. */
if (is486) { m = 1048576;
/* We need this since there might be BIOS execution at the end of RAM,
which could break the recompiler if there's not enough page elements. */
m = 1048576;
} else {
m = (mem_size + 384) >> 2;
if ((m << 2) < (mem_size + 384))
m++;
if (m < 4096)
m = 4096;
}
} }
} else { } else {
/* 8088/86; maximum address space is 1MB. */ /* 8088/86; maximum address space is 1MB. */
m = 256; m = 256;
} }
/* Calculate the amount of pages used by RAM, so that we can
give all the pages above this amount NULL write handlers. */
m2 = (mem_size + 384) >> 2;
if ((m2 << 2) < (mem_size + 384))
m2++;
if (m2 < 4096)
m2 = 4096;
/* /*
* Allocate and initialize the (new) page table. * Allocate and initialize the (new) page table.
* We only do this if the size of the page table has changed. * We only do this if the size of the page table has changed.
@@ -2399,9 +2397,17 @@ mem_log("MEM: reset: new pages=%08lx, pages_sz=%i\n", pages, pages_sz);
for (c = 0; c < pages_sz; c++) { for (c = 0; c < pages_sz; c++) {
pages[c].mem = &ram[c << 12]; pages[c].mem = &ram[c << 12];
pages[c].write_b = mem_write_ramb_page; if (c < m) {
pages[c].write_w = mem_write_ramw_page; pages[c].write_b = mem_write_ramb_page;
pages[c].write_l = mem_write_raml_page; pages[c].write_w = mem_write_ramw_page;
pages[c].write_l = mem_write_raml_page;
} else {
/* Make absolute sure non-RAM pages have NULL handlers so the
memory read/write handlers know to ignore them. */
pages[c].write_b = NULL;
pages[c].write_w = NULL;
pages[c].write_l = NULL;
}
#ifdef USE_NEW_DYNAREC #ifdef USE_NEW_DYNAREC
pages[c].evict_prev = EVICT_NOT_IN_LIST; pages[c].evict_prev = EVICT_NOT_IN_LIST;
pages[c].byte_dirty_mask = &byte_dirty_mask[c * 64]; pages[c].byte_dirty_mask = &byte_dirty_mask[c * 64];