Thu, 03 Mar 2011 13:05:21 +0000
Fix broken pagebit update code (was failing S4TEST 19 Map Translation test)
src/memory.c | file | annotate | diff | revisions |
1.1 --- a/src/memory.c Thu Mar 03 08:18:57 2011 +0000 1.2 +++ b/src/memory.c Thu Mar 03 13:05:21 2011 +0000 1.3 @@ -5,6 +5,7 @@ 1.4 #include <assert.h> 1.5 #include "musashi/m68k.h" 1.6 #include "state.h" 1.7 +#include "utils.h" 1.8 #include "memory.h" 1.9 1.10 /****************** 1.11 @@ -25,11 +26,33 @@ 1.12 1.13 // Update the Page Status bits 1.14 uint8_t pagebits = (MAPRAM(page) >> 13) & 0x03; 1.15 - if (pagebits != 0) { 1.16 - if (writing) 1.17 - state.map[page*2] |= 0x60; // Page written to (dirty) 1.18 - else 1.19 - state.map[page*2] |= 0x40; // Page accessed but not written 1.20 + // Pagebits -- 1.21 + // 0 = not present 1.22 + // 1 = present but not accessed 1.23 + // 2 = present, accessed (read from) 1.24 + // 3 = present, dirty (written to) 1.25 + switch (pagebits) { 1.26 + case 0: 1.27 + // Page not present 1.28 + // This should cause a page fault 1.29 + LOGS("Whoa! Pagebit update, when the page is not present!"); 1.30 + break; 1.31 + 1.32 + case 1: 1.33 + // Page present -- first access 1.34 + state.map[page*2] &= 0x1F; // turn off "present" bit 1.35 + if (writing) 1.36 + state.map[page*2] |= 0x60; // Page written to (dirty) 1.37 + else 1.38 + state.map[page*2] |= 0x40; // Page accessed but not written 1.39 + break; 1.40 + 1.41 + case 2: 1.42 + case 3: 1.43 + // Page present, 2nd or later access 1.44 + if (writing) 1.45 + state.map[page*2] |= 0x60; // Page written to (dirty) 1.46 + break; 1.47 } 1.48 1.49 // Return the address with the new physical page spliced in