Skip to content

Commit

Permalink
bugfix on DMA linear memory unmap.
Browse files Browse the repository at this point in the history
  • Loading branch information
crazii committed Apr 26, 2024
1 parent 75a88d6 commit ae94687
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
20 changes: 15 additions & 5 deletions sbemu/dpmi/dpmi_dj2.c
Expand Up @@ -31,21 +31,23 @@ 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];

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;
}
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions sbemu/pic.c
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions sbemu/vdma.c
Expand Up @@ -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);
}
}

0 comments on commit ae94687

Please sign in to comment.