summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2021-03-07 22:43:51 -0800
committerMichael Pavone <pavone@retrodev.com>2021-03-07 22:43:51 -0800
commit87c1d42cb389b91e2f41f1b5e0a11c859876101d (patch)
treee88fee1881ebac50381504528bb920e86a6b36c6
parenta452bfabb59b0d4efd6510f4cb46b877f0a2a27b (diff)
Fix bug in handling of MMAP_CODE regions smaller than 16KB
-rw-r--r--backend.c20
-rw-r--r--backend_x86.c10
2 files changed, 24 insertions, 6 deletions
diff --git a/backend.c b/backend.c
index 38cc45b..4acac8e 100644
--- a/backend.c
+++ b/backend.c
@@ -56,13 +56,23 @@ memmap_chunk const *find_map_chunk(uint32_t address, cpu_options *opts, uint16_t
if (size_sum) {
*size_sum = 0;
}
+ uint32_t minsize;
+ if (flags == MMAP_CODE) {
+ minsize = 1 << (opts->ram_flags_shift + 3);
+ } else {
+ minsize = 0;
+ }
address &= opts->address_mask;
for (memmap_chunk const *cur = opts->memmap, *end = opts->memmap + opts->memmap_chunks; cur != end; cur++)
{
if (address >= cur->start && address < cur->end) {
return cur;
} else if (size_sum && (cur->flags & flags) == flags) {
- *size_sum += chunk_size(opts, cur);
+ uint32_t size = chunk_size(opts, cur);
+ if (size < minsize) {
+ size = minsize;
+ }
+ *size_sum += size;
}
}
return NULL;
@@ -269,13 +279,15 @@ uint32_t chunk_size(cpu_options *opts, memmap_chunk const *chunk)
uint32_t ram_size(cpu_options *opts)
{
uint32_t size = 0;
+ uint32_t minsize = 1 << (opts->ram_flags_shift + 3);
for (int i = 0; i < opts->memmap_chunks; i++)
{
if (opts->memmap[i].flags & MMAP_CODE) {
- if (opts->memmap[i].mask == opts->address_mask) {
- size += opts->memmap[i].end - opts->memmap[i].start;
+ uint32_t cursize = chunk_size(opts, opts->memmap + i);
+ if (cursize < minsize) {
+ size += minsize;
} else {
- size += opts->memmap[i].mask + 1;
+ size += cursize;
}
}
}
diff --git a/backend_x86.c b/backend_x86.c
index 9458499..20cb9d3 100644
--- a/backend_x86.c
+++ b/backend_x86.c
@@ -299,10 +299,16 @@ code_ptr gen_mem_fun(cpu_options * opts, memmap_chunk const * memmap, uint32_t n
retn(code);
}
if (memmap[chunk].flags & MMAP_CODE) {
+ uint32_t added_offset;
if (memmap[chunk].mask == opts->address_mask) {
- ram_flags_off += (memmap[chunk].end - memmap[chunk].start) / (1 << opts->ram_flags_shift) / 8; ;
+ added_offset = (memmap[chunk].end - memmap[chunk].start) / (1 << opts->ram_flags_shift) / 8;
} else {
- ram_flags_off += (memmap[chunk].mask + 1) / (1 << opts->ram_flags_shift) / 8;;
+ added_offset = (memmap[chunk].mask + 1) / (1 << opts->ram_flags_shift) / 8;
+ }
+ if (added_offset) {
+ ram_flags_off += added_offset;
+ } else {
+ ram_flags_off += 1;
}
}
if (lb_jcc) {