From d6c177a3c02a478b6e1c29768ebfa1585b8e7518 Mon Sep 17 00:00:00 2001 From: TomW Date: Mon, 9 Feb 2015 18:26:59 +0000 Subject: [PATCH] DMA now causes page dirty mask to be updated. --- src/dma.c | 1 + src/mem.c | 15 +++++++++++++++ src/mem.h | 2 ++ src/piix.c | 3 +++ 4 files changed, 21 insertions(+) diff --git a/src/dma.c b/src/dma.c index 9de650e..7a2a99b 100644 --- a/src/dma.c +++ b/src/dma.c @@ -246,6 +246,7 @@ uint8_t _dma_read(uint32_t addr) void _dma_write(uint32_t addr, uint8_t val) { mem_writeb_phys(addr, val); + mem_invalidate_range(addr, addr); } int dma_channel_read(int channel) diff --git a/src/mem.c b/src/mem.c index 223eb98..39ec7d4 100644 --- a/src/mem.c +++ b/src/mem.c @@ -1300,6 +1300,21 @@ void mem_updatecache() } } +void mem_invalidate_range(uint32_t start_addr, uint32_t end_addr) +{ +#ifdef DYNAREC + start_addr &= ~PAGE_MASK_MASK; + end_addr = (end_addr + PAGE_MASK_MASK) & ~PAGE_MASK_MASK; + + for (; start_addr <= end_addr; start_addr += (1 << PAGE_MASK_SHIFT)) + { + uint64_t mask = (uint64_t)1 << ((start_addr >> PAGE_MASK_SHIFT) & PAGE_MASK_MASK); + + pages[start_addr >> 12].dirty_mask |= mask; + } +#endif +} + static inline int mem_mapping_read_allowed(uint32_t flags, int state) { // pclog("mem_mapping_read_allowed: flags=%x state=%x\n", flags, state); diff --git a/src/mem.h b/src/mem.h index 6ac2cc8..8398c06 100644 --- a/src/mem.h +++ b/src/mem.h @@ -134,3 +134,5 @@ static inline get_phys_noabrt(uint32_t addr) return mmutranslate_noabrt(addr, 0) & rammask; } + +void mem_invalidate_range(uint32_t start_addr, uint32_t end_addr); diff --git a/src/piix.c b/src/piix.c index 4813bbc..48de25e 100644 --- a/src/piix.c +++ b/src/piix.c @@ -8,6 +8,7 @@ #include "ibm.h" #include "ide.h" #include "io.h" +#include "mem.h" #include "pci.h" #include "piix.h" @@ -193,6 +194,8 @@ int piix_bus_master_sector_read(int channel, uint8_t *data) { if (piix_busmaster[channel].count < (512 - transferred) && piix_busmaster[channel].eot) fatal("DMA on channel %i - Read count less than 512! Addr %08X Count %04X EOT %i\n", channel, piix_busmaster[channel].addr, piix_busmaster[channel].count, piix_busmaster[channel].eot); + + mem_invalidate_range(piix_busmaster[channel].addr, piix_busmaster[channel].addr+511); if (piix_busmaster[channel].count < (512 - transferred)) {