From ae94687a46091dc4c8a22f43ca57a1c2108684b7 Mon Sep 17 00:00:00 2001 From: crazii Date: Fri, 26 Apr 2024 23:43:58 +0800 Subject: [PATCH] bugfix on DMA linear memory unmap. --- sbemu/dpmi/dpmi_dj2.c | 20 +++++++++++++++----- sbemu/pic.c | 4 ---- sbemu/vdma.c | 9 +++++---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/sbemu/dpmi/dpmi_dj2.c b/sbemu/dpmi/dpmi_dj2.c index c2e05257..a8ce7cbe 100644 --- a/sbemu/dpmi/dpmi_dj2.c +++ b/sbemu/dpmi/dpmi_dj2.c @@ -31,7 +31,7 @@ typedef struct _AddressMap uint32_t Size; }AddressMap; -#define ADDRMAP_TABLE_SIZE (256 / sizeof(AddressMap)) +#define ADDRMAP_TABLE_SIZE (1024 / sizeof(AddressMap)) static AddressMap AddresMapTable[ADDRMAP_TABLE_SIZE]; @@ -39,13 +39,15 @@ static void AddAddressMap(const __dpmi_meminfo* info, uint32_t PhysicalAddr) { for(int i = 0; i < ADDRMAP_TABLE_SIZE; ++i) { - if(AddresMapTable[i].Handle == 0) + //DBG_Logi("aa %d %x %x %x %x\n", i, AddresMapTable[i].LinearAddr, AddresMapTable[i].Size, info->address, info->size); + if(AddresMapTable[i].Size == 0) { AddressMap* map = &AddresMapTable[i]; map->Handle = info->handle; map->LinearAddr = info->address; map->PhysicalAddr = PhysicalAddr; map->Size = info->size; + break; } } } @@ -54,6 +56,7 @@ static int FindAddressMap(uint32_t linearaddr) { for(int i = 0; i < ADDRMAP_TABLE_SIZE; ++i) { + //DBG_Logi("fa %d %x %x\n", i, AddresMapTable[i].LinearAddr, linearaddr); if(AddresMapTable[i].LinearAddr == linearaddr) return i; } @@ -261,7 +264,7 @@ static void DPMI_Shutdown(void) for(int i = 0; i < ADDRMAP_TABLE_SIZE; ++i) { AddressMap* map = &AddresMapTable[i]; - if(!map->Handle) + if(!map->Size) continue; if(map->Handle == ~0UL)//XMS mapped continue; @@ -279,7 +282,7 @@ uint32_t DPMI_L2P(uint32_t vaddr) for(int i = 0; i < ADDRMAP_TABLE_SIZE; ++i) { AddressMap* map = &AddresMapTable[i]; - if(!map->Handle) + if(!map->Size) continue; if(map->LinearAddr <= vaddr && vaddr <= map->LinearAddr + map->Size) { @@ -298,7 +301,7 @@ uint32_t DPMI_P2L(uint32_t paddr) for(int i = 0; i < ADDRMAP_TABLE_SIZE; ++i) { AddressMap* map = &AddresMapTable[i]; - if(!map->Handle) + if(!map->Size) continue; if(map->PhysicalAddr <= paddr && paddr <= map->PhysicalAddr + map->Size) { @@ -325,7 +328,14 @@ void* DPMI_L2PTR(uint32_t addr) uint32_t DPMI_MapMemory(uint32_t physicaladdr, uint32_t size) { + if(size == 0) + { + assert(FALSE); + return 0; + } + __dpmi_meminfo info; + info.handle = 0; info.address = physicaladdr; info.size = size; if( __dpmi_physical_address_mapping(&info) != -1) diff --git a/sbemu/pic.c b/sbemu/pic.c index 43ed80e2..932f9885 100644 --- a/sbemu/pic.c +++ b/sbemu/pic.c @@ -23,10 +23,6 @@ void PIC_SendEOIWithIRQ(uint8_t irq) { - if(PIC_GetIRQ() != irq) //not gonna happen but just incase that SMM handles a shared interrupt and we don't need send it again - return; //or it's possbile that SMM only process the interrupt without sending EOI, leaving it to IVT - //just make it safe - if(irq == 7 || irq == 15) //check spurious irq return PIC_SendEOI(); CLIS(); diff --git a/sbemu/vdma.c b/sbemu/vdma.c index 7f2a998f..134bbfd0 100644 --- a/sbemu/vdma.c +++ b/sbemu/vdma.c @@ -242,15 +242,16 @@ void VDMA_WriteData(int channel, uint8_t data) { uint32_t addr = VDMA_GetAddress(channel); int32_t index = VDMA_GetIndex(channel); - + + uint32_t laddr = addr; if(addr>1024*1024) - addr = DPMI_MapMemory(addr, 65536); + laddr = DPMI_MapMemory(addr, 65536); _LOG("dmaw: %x, %d\n", addr+index, data); - DPMI_CopyLinear(addr+index, DPMI_PTR2L(&data), 1); + DPMI_CopyLinear(laddr+index, DPMI_PTR2L(&data), 1); if(addr>1024*1024) - DPMI_UnmappMemory(addr); + DPMI_UnmappMemory(laddr); VDMA_SetIndexCounter(channel, index+1, VDMA_GetCounter(channel)-1); } }