From: John Hodge Date: Sat, 2 Jul 2011 08:51:57 +0000 (+0800) Subject: Bugfixing a hidden bug in vm8086 (to help trace a tcp bug) X-Git-Tag: rel0.10~54 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=de86ddb7cb10ee403732f9207aba756f267ef3de;p=tpg%2Facess2.git Bugfixing a hidden bug in vm8086 (to help trace a tcp bug) --- diff --git a/Kernel/arch/x86/mm_phys.c b/Kernel/arch/x86/mm_phys.c index cc6857d1..d051adb8 100644 --- a/Kernel/arch/x86/mm_phys.c +++ b/Kernel/arch/x86/mm_phys.c @@ -451,7 +451,7 @@ void MM_DerefPhys(tPAddr PAddr) { // Get page number PAddr >>= 12; - + // We don't care about non-ram pages if(PAddr >= giPageCount) return; diff --git a/Kernel/arch/x86/mm_virt.c b/Kernel/arch/x86/mm_virt.c index 72c40c2a..8c59ea0f 100644 --- a/Kernel/arch/x86/mm_virt.c +++ b/Kernel/arch/x86/mm_virt.c @@ -55,6 +55,7 @@ #define PF_PRESENT 0x1 #define PF_WRITE 0x2 #define PF_USER 0x4 +#define PF_GLOBAL 0x80 #define PF_COW 0x200 #define PF_NOPAGE 0x400 @@ -276,7 +277,7 @@ void MM_DumpTables(tVAddr Start, tVAddr End) tPAddr expected = 0; tVAddr curPos; Uint page; - const tPAddr MASK = ~0xF98; + const tPAddr MASK = ~0xF78; Start >>= 12; End >>= 12; @@ -306,14 +307,16 @@ void MM_DumpTables(tVAddr Start, tVAddr End) || (gaPageTable[page] & MASK) != expected) { if(expected) { - Log(" 0x%08x-0x%08x => 0x%08x-0x%08x (%s%s%s%s)", - rangeStart, curPos - 1, + Log(" 0x%08x => 0x%08x - 0x%08x (%s%s%s%s%s)", + rangeStart, gaPageTable[rangeStart>>12] & ~0xFFF, - (expected & ~0xFFF) - 1, + curPos - rangeStart, (expected & PF_NOPAGE ? "P" : "-"), (expected & PF_COW ? "C" : "-"), + (expected & PF_GLOBAL ? "G" : "-"), (expected & PF_USER ? "U" : "-"), - (expected & PF_WRITE ? "W" : "-") + (expected & PF_WRITE ? "W" : "-"), + gaPageTable[page] & MASK, expected ); expected = 0; } @@ -327,10 +330,10 @@ void MM_DumpTables(tVAddr Start, tVAddr End) } if(expected) { - Log("0x%08x-0x%08x => 0x%08x-0x%08x (%s%s%s%s)", - rangeStart, curPos - 1, + Log("0x%08x => 0x%08x - 0x%08x (%s%s%s%s)", + rangeStart, gaPageTable[rangeStart>>12] & ~0xFFF, - (expected & ~0xFFF) - 1, + curPos - rangeStart, (expected & PF_NOPAGE ? "p" : "-"), (expected & PF_COW ? "C" : "-"), (expected & PF_USER ? "U" : "-"), diff --git a/Kernel/arch/x86/vm8086.c b/Kernel/arch/x86/vm8086.c index 71813510..ef449d45 100644 --- a/Kernel/arch/x86/vm8086.c +++ b/Kernel/arch/x86/vm8086.c @@ -2,6 +2,7 @@ * Acess2 VM8086 Driver * - By John Hodge (thePowersGang) */ +#define DEBUG 0 #include #include #include @@ -24,6 +25,9 @@ enum eVM8086_Opcodes }; #define VM8086_PAGES_PER_INST 4 +#define VM8086_BLOCKSIZE 128 +#define VM8086_BLOCKCOUNT ((0x9F000-0x10000)/VM8086_BLOCKSIZE) + // === IMPORTS === int Proc_Clone(Uint *Err, Uint Flags); @@ -48,6 +52,7 @@ tMutex glVM8086_Process; tPID gVM8086_WorkerPID; tTID gVM8086_CallingThread; tVM8086 volatile * volatile gpVM8086_State = (void*)-1; // Set to -1 to avoid race conditions +Uint32 gaVM8086_MemBitmap[VM8086_BLOCKCOUNT/32]; // === FUNCTIONS === int VM8086_Install(char **Arguments) @@ -79,8 +84,12 @@ int VM8086_Install(char **Arguments) //MM_SetFlags( i * 0x1000, MM_PFLAG_RO, MM_PFLAG_RO ); // Set Read Only } MM_Map( 0, 0 ); // IVT / BDA - for(i=0x10;i<0x9F;i++) { - MM_Map( i * 0x1000, i * 0x1000 ); MM_DerefPhys( i * 0x1000 ); + // Map (but allow allocation) of 0x1000 - 0x9F000 + // - So much hack, it isn't funny + for(i=1;i<0x9F;i++) { + MM_Map( i * 0x1000, i * 0x1000 ); + MM_DerefPhys( i * 0x1000 ); // Above + MM_DerefPhys( i * 0x1000 ); // Phys setup } MM_Map( 0x9F000, 0x9F000 ); // Stack / EBDA // System Stack / Stub @@ -157,8 +166,8 @@ void VM8086_GPF(tRegs *Regs) { if( gpVM8086_State == (void*)-1 ) { Log_Log("VM8086", "Worker thread ready and waiting"); - Mutex_Release( &glVM8086_Process ); // Release lock obtained in VM8086_Install gpVM8086_State = NULL; + Mutex_Release( &glVM8086_Process ); // Release lock obtained in VM8086_Install } //Log_Log("VM8086", "gpVM8086_State = %p, gVM8086_CallingThread = %i", // gpVM8086_State, gVM8086_CallingThread); @@ -359,20 +368,20 @@ void *VM8086_Allocate(tVM8086 *State, int Size, Uint16 *Segment, Uint16 *Offset) // Scan the bitmap for a free block for( j = 0; j < 32; j++ ) { if( State->Internal->AllocatedPages[i].Bitmap & (1 << j) ) { - base = j; + base = j+1; rem = nBlocks; } - else { - rem --; - if(rem == 0) // Goodie, there's a gap - { - for( j = 0; j < nBlocks; j++ ) - State->Internal->AllocatedPages[i].Bitmap |= 1 << (base + j); - *Segment = State->Internal->AllocatedPages[i].PhysAddr / 16 + base * 8; - *Offset = 0; - //Log_Debug("VM8086", "Allocated at #%i,%04x", i, base*128); - return (void*)( State->Internal->AllocatedPages[i].VirtBase + base * 128 ); - } + + rem --; + if(rem == 0) // Goodie, there's a gap + { + for( j = 0; j < nBlocks; j++ ) + State->Internal->AllocatedPages[i].Bitmap |= 1 << (base + j); + *Segment = State->Internal->AllocatedPages[i].PhysAddr / 16 + base * 8; + *Offset = 0; + LOG("Allocated at #%i,%04x", i, base*128); + LOG(" - %x:%x", *Segment, *Offset); + return (void*)( State->Internal->AllocatedPages[i].VirtBase + base * 128 ); } } } @@ -394,9 +403,10 @@ void *VM8086_Allocate(tVM8086 *State, int Size, Uint16 *Segment, Uint16 *Offset) for( j = 0; j < nBlocks; j++ ) State->Internal->AllocatedPages[i].Bitmap |= 1 << j; - //Log_Debug("VM8086", "AllocatedPages[%i].Bitmap = 0b%b", i, State->Internal->AllocatedPages[i].Bitmap); + LOG("AllocatedPages[%i].Bitmap = 0b%b", i, State->Internal->AllocatedPages[i].Bitmap); *Segment = State->Internal->AllocatedPages[i].PhysAddr / 16; *Offset = 0; + LOG(" - %x:%x", *Segment, *Offset); return (void*) State->Internal->AllocatedPages[i].VirtBase; } diff --git a/Modules/IPStack/tcp.c b/Modules/IPStack/tcp.c index fe7c299d..8ebf0aee 100644 --- a/Modules/IPStack/tcp.c +++ b/Modules/IPStack/tcp.c @@ -412,6 +412,7 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head // TODO: This should be moved out of the watcher thread, // so that a single lost packet on one connection doesn't cause // all connections on the interface to lag. + // - Meh, no real issue, as the cache shouldn't be that large TCP_INT_UpdateRecievedFromFuture(Connection); // ACK Packet @@ -601,9 +602,7 @@ void TCP_INT_AppendRecieved(tTCPConnection *Connection, tTCPStoredPacket *Pkt) RingBuffer_Write( Connection->RecievedBuffer, Pkt->Data, Pkt->Length ); - #if USE_SELECT VFS_MarkAvaliable(&Connection->Node, 1); - #endif Mutex_Release( &Connection->lRecievedPackets ); }