src/memory.c

changeset 104
b12651d8a0ab
parent 103
b749a3356e8d
child 105
343250338d23
     1.1 diff -r b749a3356e8d -r b12651d8a0ab src/memory.c
     1.2 --- a/src/memory.c	Fri Mar 04 00:44:36 2011 +0000
     1.3 +++ b/src/memory.c	Fri Mar 04 01:36:30 2011 +0000
     1.4 @@ -40,7 +40,7 @@
     1.5  
     1.6  			case 1:
     1.7  				// Page present -- first access
     1.8 -				state.map[page*2] &= 0x1F;	// turn off "present" bit
     1.9 +				state.map[page*2] &= 0x9F;	// turn off "present" bit (but not write enable!)
    1.10  				if (writing)
    1.11  					state.map[page*2] |= 0x60;		// Page written to (dirty)
    1.12  				else
    1.13 @@ -66,6 +66,16 @@
    1.14  
    1.15  MEM_STATUS checkMemoryAccess(uint32_t addr, bool writing)/*{{{*/
    1.16  {
    1.17 +	// Get the page bits for this page.
    1.18 +	uint16_t page = (addr >> 12) & 0x3FF;
    1.19 +	uint8_t pagebits = (MAPRAM(page) >> 13) & 0x07;
    1.20 +
    1.21 +	// Check page is present (but only for RAM zone)
    1.22 +	if ((addr < 0x400000) && ((pagebits & 0x03) == 0)) {
    1.23 +		LOG("Page not mapped in: addr %08X, page %04X, mapbits %04X", addr, page, MAPRAM(page));
    1.24 +		return MEM_PAGEFAULT;
    1.25 +	}
    1.26 +
    1.27  	// Are we in Supervisor mode?
    1.28  	if (m68k_get_reg(NULL, M68K_REG_SR) & 0x2000)
    1.29  		// Yes. We can do anything we like.
    1.30 @@ -76,14 +86,6 @@
    1.31  	if (addr >= 0x400000)
    1.32  		return MEM_UIE;
    1.33  
    1.34 -	// This leaves us with Page Fault checking. Get the page bits for this page.
    1.35 -	uint16_t page = (addr >> 12) & 0x3FF;
    1.36 -	uint8_t pagebits = (MAPRAM(page) >> 13) & 0x07;
    1.37 -
    1.38 -	// Check page is present
    1.39 -	if ((pagebits & 0x03) == 0)
    1.40 -		return MEM_PAGEFAULT;
    1.41 -
    1.42  	// User attempt to access the kernel
    1.43  	// A19, A20, A21, A22 low (kernel access): RAM addr before paging; not in Supervisor mode
    1.44  	if (((addr >> 19) & 0x0F) == 0)