Tue, 28 Dec 2010 18:59:15 +0000
DMA: remove a few debug messages and rewrite memory error handling
src/main.c | file | annotate | diff | revisions |
1.1 diff -r 8ca92162fa89 -r d6358bf2f5c2 src/main.c 1.2 --- a/src/main.c Tue Dec 28 18:58:51 2010 +0000 1.3 +++ b/src/main.c Tue Dec 28 18:59:15 2010 +0000 1.4 @@ -219,7 +219,6 @@ 1.5 // Run the DMA engine 1.6 // 1.7 if (state.dmaen) { //((state.dma_count < 0x3fff) && state.dmaen) { 1.8 - printf("DMA: copy addr=%08X count=%08X idmarw=%d dmarw=%d\n", state.dma_address, state.dma_count, state.idmarw, state.dma_reading); 1.9 // DMA ready to go -- so do it. 1.10 size_t num = 0; 1.11 while (state.dma_count < 0x4000) { 1.12 @@ -230,25 +229,60 @@ 1.13 1.14 // Evidently we have more words to copy. Copy them. 1.15 if (!wd2797_get_drq(&state.fdc_ctx)) { 1.16 - printf("\tDMABAIL: no data! dmac=%04X dmaa=%04X\n", state.dma_count, state.dma_address); 1.17 // Bail out, no data available. Try again later. 1.18 // TODO: handle HDD controller too 1.19 break; 1.20 } 1.21 1.22 + // Check memory access permissions 1.23 + // TODO: enforce these!!!! use ACCESS_CHECK_* for guidance. 1.24 + bool access_ok; 1.25 + switch (checkMemoryAccess(state.dma_address, !state.dma_reading)) { 1.26 + case MEM_PAGEFAULT: 1.27 + case MEM_PAGE_NO_WE: 1.28 + case MEM_KERNEL: 1.29 + case MEM_UIE: 1.30 + access_ok = false; 1.31 + break; 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 + // TODO: FIXME: if we get a pagefault, it NEEDS to be tagged as 'peripheral sourced'... this is a HACK! 1.39 + printf("REALLY BIG FSCKING HUGE ERROR: DMA Memory Access caused a FAULT!\n"); 1.40 + } 1.41 + 1.42 + // Map logical address to a physical RAM address 1.43 + uint32_t newAddr = mapAddr(state.dma_address, !state.dma_reading); 1.44 + 1.45 if (!state.dma_reading) { 1.46 - // Data available. Get it from the FDC. 1.47 + // Data available. Get it from the FDC. TODO: handle HDD too 1.48 d = wd2797_read_reg(&state.fdc_ctx, WD2797_REG_DATA); 1.49 d <<= 8; 1.50 d += wd2797_read_reg(&state.fdc_ctx, WD2797_REG_DATA); 1.51 1.52 - // TODO: FIXME: if we get a pagefault, it NEEDS to be tagged as 'peripheral sourced'... this is a HACK! 1.53 + if (newAddr <= 0x1FFFFF) { 1.54 + WR16(state.base_ram, newAddr, state.base_ram_size - 1, d); 1.55 + } else if (newAddr >= 0x200000) { 1.56 + WR16(state.exp_ram, newAddr - 0x200000, state.exp_ram_size - 1, d); 1.57 + } 1.58 m68k_write_memory_16(state.dma_address, d); 1.59 } else { 1.60 - // Data write to FDC 1.61 - // TODO: FIXME: if we get a pagefault, it NEEDS to be tagged as 'peripheral sourced'... this is a HACK! 1.62 - d = m68k_read_memory_16(state.dma_address); 1.63 + // Data write to FDC. TODO: handle HDD too. 1.64 1.65 + // Get the data from RAM 1.66 + if (newAddr <= 0x1fffff) { 1.67 + d = RD16(state.base_ram, newAddr, state.base_ram_size - 1); 1.68 + } else { 1.69 + if (newAddr <= (state.exp_ram_size + 0x200000 - 1)) 1.70 + d = RD16(state.exp_ram, newAddr - 0x200000, state.exp_ram_size - 1); 1.71 + else 1.72 + d = 0xffff; 1.73 + } 1.74 + 1.75 + // Send the data to the FDD 1.76 wd2797_write_reg(&state.fdc_ctx, WD2797_REG_DATA, (d >> 8)); 1.77 wd2797_write_reg(&state.fdc_ctx, WD2797_REG_DATA, (d & 0xff)); 1.78 } 1.79 @@ -261,8 +295,7 @@ 1.80 1.81 // Turn off DMA engine if we finished this cycle 1.82 if (state.dma_count >= 0x4000) { 1.83 - printf("\tDMATRAN: transfer complete! dmaa=%06X, dmac=%04X\n", state.dma_address, state.dma_count); 1.84 - // FIXME? apparently this isn't required...? 1.85 + // FIXME? apparently this isn't required... or is it? 1.86 // state.dma_count = 0; 1.87 state.dmaen = false; 1.88 }