add page fault handling for DMA controller

Tue, 28 Dec 2010 19:11:46 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Tue, 28 Dec 2010 19:11:46 +0000
changeset 69
afe655559cc0
parent 68
58318104858b
child 70
5bbe76e71698

add page fault handling for DMA controller

src/main.c file | annotate | diff | revisions
     1.1 --- a/src/main.c	Tue Dec 28 19:10:36 2010 +0000
     1.2 +++ b/src/main.c	Tue Dec 28 19:11:46 2010 +0000
     1.3 @@ -239,19 +239,42 @@
     1.4  				bool access_ok;
     1.5  				switch (checkMemoryAccess(state.dma_address, !state.dma_reading)) {
     1.6  					case MEM_PAGEFAULT:
     1.7 -					case MEM_PAGE_NO_WE:
     1.8 -					case MEM_KERNEL:
     1.9 -					case MEM_UIE:
    1.10 +						// Page fault
    1.11 +						state.genstat = 0x8BFF
    1.12 +							| (state.dma_reading ? 0x4000 : 0)
    1.13 +							| (state.pie ? 0x0400 : 0);
    1.14  						access_ok = false;
    1.15  						break;
    1.16 +
    1.17 +					case MEM_UIE:
    1.18 +						// User access to memory above 4MB
    1.19 +						// FIXME? Shouldn't be possible with DMA... assert this?
    1.20 +						state.genstat = 0x9AFF
    1.21 +							| (state.dma_reading ? 0x4000 : 0)
    1.22 +							| (state.pie ? 0x0400 : 0);
    1.23 +						access_ok = false;
    1.24 +						break;
    1.25 +
    1.26 +					case MEM_KERNEL:
    1.27 +					case MEM_PAGE_NO_WE:
    1.28 +						// Kernel access or page not write enabled
    1.29 +						access_ok = false;
    1.30 +						break;
    1.31 +
    1.32  					case MEM_ALLOWED:
    1.33  						access_ok = true;
    1.34  						break;
    1.35  				}
    1.36  				if (!access_ok) {
    1.37 -					// TODO!
    1.38 +					state.bsr0 = 0x3C00;
    1.39 +					state.bsr0 |= (state.dma_address >> 16);
    1.40 +					state.bsr1 = state.dma_address & 0xffff;
    1.41 +					m68k_pulse_bus_error();
    1.42 +					printf("BUS ERROR FROM DMA: genstat=%04X, bsr0=%04X, bsr1=%04X\n", state.genstat, state.bsr0, state.bsr1);
    1.43 +
    1.44  					// TODO: FIXME: if we get a pagefault, it NEEDS to be tagged as 'peripheral sourced'... this is a HACK!
    1.45  					printf("REALLY BIG FSCKING HUGE ERROR: DMA Memory Access caused a FAULT!\n");
    1.46 +					exit(-1);
    1.47  				}
    1.48  
    1.49  				// Map logical address to a physical RAM address