Memory: Disable _mem_exec in phys() accesses when not using the 486+ interpreter or dynamic recompiler, and write protect support in preparation for the WD76C10 rewrite.

This commit is contained in:
OBattler
2024-02-02 05:25:40 +01:00
parent 0483b8ceec
commit 0a5d25fdde
4 changed files with 78 additions and 35 deletions

View File

@@ -182,6 +182,7 @@ int cpu_16bitbus;
int cpu_64bitbus;
int cpu_cyrix_alignment;
int cpu_cpurst_on_sr;
int cpu_use_exec = 0;
int CPUID;
int is186;
@@ -1784,16 +1785,20 @@ cpu_set(void)
x87_concurrency = x87_concurrency_486;
}
cpu_use_exec = 0;
if (is386) {
#if defined(USE_DYNAREC) && !defined(USE_GDBSTUB)
if (cpu_use_dynarec)
if (cpu_use_dynarec) {
cpu_exec = exec386_dynarec;
else
cpu_use_exec = 1;
} else
#endif
/* Use exec386 for CPU_IBM486SLC because it can reach 100 MHz. */
if ((cpu_s->cpu_type == CPU_IBM486SLC) || (cpu_s->cpu_type > CPU_486DLC))
if ((cpu_s->cpu_type == CPU_IBM486SLC) || (cpu_s->cpu_type > CPU_486DLC)) {
cpu_exec = exec386;
else
cpu_use_exec = 1;
} else
cpu_exec = exec386_2386;
} else if (cpu_s->cpu_type >= CPU_286)
cpu_exec = exec386_2386;

View File

@@ -809,6 +809,7 @@ extern int hlt_reset_pending;
extern cyrix_t cyrix;
extern int prefetch_prefixes;
extern int cpu_use_exec;
extern uint8_t use_custom_nmi_vector;
extern uint32_t custom_nmi_vector;

View File

@@ -398,6 +398,7 @@ extern void mem_mapping_disable(mem_mapping_t *);
extern void mem_mapping_enable(mem_mapping_t *);
extern void mem_mapping_recalc(uint64_t base, uint64_t size);
extern void mem_set_wp(uint64_t base, uint64_t size, uint8_t flags, uint8_t wp);
extern void mem_set_access(uint8_t bitmap, int mode, uint32_t base, uint32_t size, uint16_t access);
extern uint8_t mem_readb_phys(uint32_t addr);

View File

@@ -132,6 +132,8 @@ static mem_mapping_t *last_mapping;
static mem_mapping_t *read_mapping_bus[MEM_MAPPINGS_NO];
static mem_mapping_t *write_mapping_bus[MEM_MAPPINGS_NO];
static uint8_t *_mem_exec[MEM_MAPPINGS_NO];
static uint8_t _mem_wp[MEM_MAPPINGS_NO];
static uint8_t _mem_wp_bus[MEM_MAPPINGS_NO];
static uint8_t ff_pccache[4] = { 0xff, 0xff, 0xff, 0xff };
static mem_state_t _mem_state[MEM_MAPPINGS_NO];
static uint32_t remap_start_addr;
@@ -1631,7 +1633,7 @@ mem_readb_phys(uint32_t addr)
mem_logical_addr = 0xffffffff;
if (map) {
if (map->exec)
if (cpu_use_exec && map->exec)
ret = map->exec[(addr - map->base) & map->mask];
else if (map->read_b)
ret = map->read_b(addr, map->priv);
@@ -1649,7 +1651,7 @@ mem_readw_phys(uint32_t addr)
mem_logical_addr = 0xffffffff;
if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->exec)) {
if (cpu_use_exec && ((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->exec)) {
p = (uint16_t *) &(map->exec[(addr - map->base) & map->mask]);
ret = *p;
} else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->read_w))
@@ -1671,7 +1673,7 @@ mem_readl_phys(uint32_t addr)
mem_logical_addr = 0xffffffff;
if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->exec)) {
if (cpu_use_exec && ((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->exec)) {
p = (uint32_t *) &(map->exec[(addr - map->base) & map->mask]);
ret = *p;
} else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->read_l))
@@ -1711,7 +1713,7 @@ mem_writeb_phys(uint32_t addr, uint8_t val)
mem_logical_addr = 0xffffffff;
if (map) {
if (map->exec)
if (cpu_use_exec && map->exec)
map->exec[(addr - map->base) & map->mask] = val;
else if (map->write_b)
map->write_b(addr, val, map->priv);
@@ -1726,7 +1728,7 @@ mem_writew_phys(uint32_t addr, uint16_t val)
mem_logical_addr = 0xffffffff;
if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->exec)) {
if (cpu_use_exec && ((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->exec)) {
p = (uint16_t *) &(map->exec[(addr - map->base) & map->mask]);
*p = val;
} else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_HBOUND) && (map && map->write_w))
@@ -1745,7 +1747,7 @@ mem_writel_phys(uint32_t addr, uint32_t val)
mem_logical_addr = 0xffffffff;
if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->exec)) {
if (cpu_use_exec && ((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->exec)) {
p = (uint32_t *) &(map->exec[(addr - map->base) & map->mask]);
*p = val;
} else if (((addr & MEM_GRANULARITY_MASK) <= MEM_GRANULARITY_QBOUND) && (map && map->write_l))
@@ -1783,7 +1785,7 @@ mem_read_ram(uint32_t addr, UNUSED(void *priv))
mem_log("Read B %02X from %08X\n", ram[addr], addr);
#endif
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return ram[addr];
@@ -1797,7 +1799,7 @@ mem_read_ramw(uint32_t addr, UNUSED(void *priv))
mem_log("Read W %04X from %08X\n", *(uint16_t *) &ram[addr], addr);
#endif
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return *(uint16_t *) &ram[addr];
@@ -1811,7 +1813,7 @@ mem_read_raml(uint32_t addr, UNUSED(void *priv))
mem_log("Read L %08X from %08X\n", *(uint32_t *) &ram[addr], addr);
#endif
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return *(uint32_t *) &ram[addr];
@@ -2043,7 +2045,7 @@ mem_write_ram(uint32_t addr, uint8_t val, UNUSED(void *priv))
if ((addr >= 0xa0000) && (addr <= 0xbffff))
mem_log("Write B %02X to %08X\n", val, addr);
#endif
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_ramb_page(addr, val, &pages[addr >> 12]);
} else
@@ -2057,7 +2059,7 @@ mem_write_ramw(uint32_t addr, uint16_t val, UNUSED(void *priv))
if ((addr >= 0xa0000) && (addr <= 0xbffff))
mem_log("Write W %04X to %08X\n", val, addr);
#endif
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_ramw_page(addr, val, &pages[addr >> 12]);
} else
@@ -2071,7 +2073,7 @@ mem_write_raml(uint32_t addr, uint32_t val, UNUSED(void *priv))
if ((addr >= 0xa0000) && (addr <= 0xbffff))
mem_log("Write L %08X to %08X\n", val, addr);
#endif
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_raml_page(addr, val, &pages[addr >> 12]);
} else
@@ -2082,7 +2084,7 @@ static uint8_t
mem_read_remapped(uint32_t addr, UNUSED(void *priv))
{
addr = 0xA0000 + (addr - remap_start_addr);
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return ram[addr];
}
@@ -2091,7 +2093,7 @@ static uint16_t
mem_read_remappedw(uint32_t addr, UNUSED(void *priv))
{
addr = 0xA0000 + (addr - remap_start_addr);
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return *(uint16_t *) &ram[addr];
}
@@ -2100,7 +2102,7 @@ static uint32_t
mem_read_remappedl(uint32_t addr, UNUSED(void *priv))
{
addr = 0xA0000 + (addr - remap_start_addr);
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return *(uint32_t *) &ram[addr];
}
@@ -2109,7 +2111,7 @@ static uint8_t
mem_read_remapped2(uint32_t addr, UNUSED(void *priv))
{
addr = 0xD0000 + (addr - remap_start_addr2);
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return ram[addr];
}
@@ -2118,7 +2120,7 @@ static uint16_t
mem_read_remappedw2(uint32_t addr, UNUSED(void *priv))
{
addr = 0xD0000 + (addr - remap_start_addr2);
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return *(uint16_t *) &ram[addr];
}
@@ -2127,7 +2129,7 @@ static uint32_t
mem_read_remappedl2(uint32_t addr, UNUSED(void *priv))
{
addr = 0xD0000 + (addr - remap_start_addr2);
if (is286)
if (cpu_use_exec)
addreadlookup(mem_logical_addr, addr);
return *(uint32_t *) &ram[addr];
}
@@ -2137,7 +2139,7 @@ mem_write_remapped(uint32_t addr, uint8_t val, UNUSED(void *priv))
{
uint32_t oldaddr = addr;
addr = 0xA0000 + (addr - remap_start_addr);
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_ramb_page(addr, val, &pages[oldaddr >> 12]);
} else
@@ -2149,7 +2151,7 @@ mem_write_remappedw(uint32_t addr, uint16_t val, UNUSED(void *priv))
{
uint32_t oldaddr = addr;
addr = 0xA0000 + (addr - remap_start_addr);
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_ramw_page(addr, val, &pages[oldaddr >> 12]);
} else
@@ -2161,7 +2163,7 @@ mem_write_remappedl(uint32_t addr, uint32_t val, UNUSED(void *priv))
{
uint32_t oldaddr = addr;
addr = 0xA0000 + (addr - remap_start_addr);
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_raml_page(addr, val, &pages[oldaddr >> 12]);
} else
@@ -2173,7 +2175,7 @@ mem_write_remapped2(uint32_t addr, uint8_t val, UNUSED(void *priv))
{
uint32_t oldaddr = addr;
addr = 0xD0000 + (addr - remap_start_addr2);
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_ramb_page(addr, val, &pages[oldaddr >> 12]);
} else
@@ -2185,7 +2187,7 @@ mem_write_remappedw2(uint32_t addr, uint16_t val, UNUSED(void *priv))
{
uint32_t oldaddr = addr;
addr = 0xD0000 + (addr - remap_start_addr2);
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_ramw_page(addr, val, &pages[oldaddr >> 12]);
} else
@@ -2197,7 +2199,7 @@ mem_write_remappedl2(uint32_t addr, uint32_t val, UNUSED(void *priv))
{
uint32_t oldaddr = addr;
addr = 0xD0000 + (addr - remap_start_addr2);
if (is286) {
if (cpu_use_exec) {
addwritelookup(mem_logical_addr, addr);
mem_write_raml_page(addr, val, &pages[oldaddr >> 12]);
} else
@@ -2282,6 +2284,7 @@ mem_mapping_recalc(uint64_t base, uint64_t size)
mem_mapping_t *map;
int n;
uint64_t c;
uint8_t wp;
if (!size || (base_mapping == NULL))
return;
@@ -2300,27 +2303,42 @@ mem_mapping_recalc(uint64_t base, uint64_t size)
/* Walk mapping list. */
while (map != NULL) {
/* In range? */
if (map->enable && (uint64_t) map->base < ((uint64_t) base + (uint64_t) size) && ((uint64_t) map->base + (uint64_t) map->size) > (uint64_t) base) {
if (map->enable && (uint64_t) map->base < ((uint64_t) base + (uint64_t) size) &&
((uint64_t) map->base + (uint64_t) map->size) > (uint64_t) base) {
uint64_t start = (map->base < base) ? map->base : base;
uint64_t end = (((uint64_t) map->base + (uint64_t) map->size) < (base + size)) ? ((uint64_t) map->base + (uint64_t) map->size) : (base + size);
uint64_t end = (((uint64_t) map->base + (uint64_t) map->size) < (base + size)) ?
((uint64_t) map->base + (uint64_t) map->size) : (base + size);
if (start < map->base)
start = map->base;
for (c = start; c < end; c += MEM_GRANULARITY_SIZE) {
/* CPU */
n = !!in_smm;
if (map->exec && mem_mapping_access_allowed(map->flags, _mem_state[c >> MEM_GRANULARITY_BITS].states[n].x))
wp = _mem_wp[c >> MEM_GRANULARITY_BITS];
if (map->exec && mem_mapping_access_allowed(map->flags,
_mem_state[c >> MEM_GRANULARITY_BITS].states[n].x))
_mem_exec[c >> MEM_GRANULARITY_BITS] = map->exec + (c - map->base);
if ((map->write_b || map->write_w || map->write_l) && mem_mapping_access_allowed(map->flags, _mem_state[c >> MEM_GRANULARITY_BITS].states[n].w))
if (!wp && (map->write_b || map->write_w || map->write_l) &&
mem_mapping_access_allowed(map->flags,
_mem_state[c >> MEM_GRANULARITY_BITS].states[n].w))
write_mapping[c >> MEM_GRANULARITY_BITS] = map;
if ((map->read_b || map->read_w || map->read_l) && mem_mapping_access_allowed(map->flags, _mem_state[c >> MEM_GRANULARITY_BITS].states[n].r))
if ((map->read_b || map->read_w || map->read_l) &&
mem_mapping_access_allowed(map->flags,
_mem_state[c >> MEM_GRANULARITY_BITS].states[n].r))
read_mapping[c >> MEM_GRANULARITY_BITS] = map;
/* Bus */
n |= STATE_BUS;
if ((map->write_b || map->write_w || map->write_l) && mem_mapping_access_allowed(map->flags, _mem_state[c >> MEM_GRANULARITY_BITS].states[n].w))
wp = _mem_wp_bus[c >> MEM_GRANULARITY_BITS];
if (!wp && (map->write_b || map->write_w || map->write_l) &&
mem_mapping_access_allowed(map->flags,
_mem_state[c >> MEM_GRANULARITY_BITS].states[n].w))
write_mapping_bus[c >> MEM_GRANULARITY_BITS] = map;
if ((map->read_b || map->read_w || map->read_l) && mem_mapping_access_allowed(map->flags, _mem_state[c >> MEM_GRANULARITY_BITS].states[n].r))
if ((map->read_b || map->read_w || map->read_l) &&
mem_mapping_access_allowed(map->flags,
_mem_state[c >> MEM_GRANULARITY_BITS].states[n].r))
read_mapping_bus[c >> MEM_GRANULARITY_BITS] = map;
}
}
@@ -2380,6 +2398,22 @@ mem_mapping_recalc(uint64_t base, uint64_t size)
#endif
}
void
mem_set_wp(uint64_t base, uint64_t size, uint8_t flags, uint8_t wp)
{
uint64_t c;
uint64_t end = base + size;
for (c = base; c < end; c += MEM_GRANULARITY_SIZE) {
if (flags & ACCESS_BUS)
_mem_wp_bus[c >> MEM_GRANULARITY_BITS] = wp;
if (flags & ACCESS_CPU)
_mem_wp[c >> MEM_GRANULARITY_BITS] = wp;
}
mem_mapping_recalc(base, size);
}
void
mem_mapping_set(mem_mapping_t *map,
uint32_t base,
@@ -2790,6 +2824,8 @@ mem_reset(void)
}
memset(_mem_exec, 0x00, sizeof(_mem_exec));
memset(_mem_wp, 0x00, sizeof(_mem_wp));
memset(_mem_wp_bus, 0x00, sizeof(_mem_wp_bus));
memset(write_mapping, 0x00, sizeof(write_mapping));
memset(read_mapping, 0x00, sizeof(read_mapping));
memset(write_mapping_bus, 0x00, sizeof(write_mapping_bus));