Fix broken pagebit update code (was failing S4TEST 19 Map Translation test)

Thu, 03 Mar 2011 13:05:21 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Thu, 03 Mar 2011 13:05:21 +0000
changeset 100
d6f699f89303
parent 99
2d06b823a015
child 101
e20f02519835

Fix broken pagebit update code (was failing S4TEST 19 Map Translation test)

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