From: John Hodge Date: Tue, 6 Apr 2010 15:31:32 +0000 (+0800) Subject: Fixed VM8086/Vesa memory allocation bug X-Git-Tag: rel0.06~253 X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=commitdiff_plain;h=7f07ccaa4d128305aed6f67f1f57a5c9276a895f Fixed VM8086/Vesa memory allocation bug --- diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum index 7bb7ce60..093dcc68 100644 --- a/Kernel/Makefile.BuildNum +++ b/Kernel/Makefile.BuildNum @@ -1 +1 @@ -BUILD_NUM = 1793 +BUILD_NUM = 1800 diff --git a/Kernel/arch/x86/vm8086.c b/Kernel/arch/x86/vm8086.c index c837475b..6853cbfe 100644 --- a/Kernel/arch/x86/vm8086.c +++ b/Kernel/arch/x86/vm8086.c @@ -294,23 +294,25 @@ void *VM8086_Allocate(tVM8086 *State, int Size, Uint16 *Segment, Uint16 *Offset) { int i, j, base = 0; int nBlocks, rem; - Uint32 bmp; Size = (Size + 127) & ~127; - nBlocks = Size >> 7; + nBlocks = Size / 128; if(Size > 4096) return NULL; for( i = 0; i < VM8086_PAGES_PER_INST; i++ ) { if( State->Internal->AllocatedPages[i].VirtBase == 0 ) continue; - bmp = State->Internal->AllocatedPages[i].Bitmap; + + + //Log_Debug("VM8086", "AllocatedPages[%i].Bitmap = 0b%b", i, State->Internal->AllocatedPages[i].Bitmap); + rem = nBlocks; base = 0; // Scan the bitmap for a free block - for( j = 0; j < 32-nBlocks; j++ ) { - if( bmp & (1 << j) ) { - base = 0; + for( j = 0; j < 32; j++ ) { + if( State->Internal->AllocatedPages[i].Bitmap & (1 << j) ) { + base = j; rem = nBlocks; } else { @@ -321,6 +323,7 @@ void *VM8086_Allocate(tVM8086 *State, int Size, Uint16 *Segment, Uint16 *Offset) 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 ); } } @@ -344,6 +347,7 @@ 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); *Segment = State->Internal->AllocatedPages[i].PhysAddr / 16; *Offset = 0; return (void*) State->Internal->AllocatedPages[i].VirtBase; diff --git a/Kernel/logging.c b/Kernel/logging.c index 72856db1..6eac2330 100644 --- a/Kernel/logging.c +++ b/Kernel/logging.c @@ -118,7 +118,7 @@ void Log_AddEvent(char *Ident, int Level, char *Format, va_list Args) */ void Log_Int_PrintMessage(tLogEntry *Entry) { - LogF("%018lli%s [%8s] %s\n", + LogF("%018lli%s [%+8s] %s\n", Entry->Time, csaLevelCodes[Entry->Level], Entry->Ident, diff --git a/Modules/Display/VESA/main.c b/Modules/Display/VESA/main.c index e960888f..69292933 100644 --- a/Modules/Display/VESA/main.c +++ b/Modules/Display/VESA/main.c @@ -70,10 +70,11 @@ int Vesa_Install(char **Arguments) return MODULE_ERR_NOTNEEDED; } + Log_Debug("Vesa", "info->VideoModes = %04x:%04x", info->VideoModes.seg, info->VideoModes.ofs); modes = (Uint16 *) VM8086_GetPointer(gpVesa_BiosState, info->VideoModes.seg, info->VideoModes.ofs); // Read Modes - for( giVesaModeCount = 1; modes[giVesaModeCount] != 0xFFFF; giVesaModeCount++ ); + for( giVesaModeCount = 0; modes[giVesaModeCount] != 0xFFFF; giVesaModeCount++ ); gVesa_Modes = (tVesa_Mode *)malloc( giVesaModeCount * sizeof(tVesa_Mode) ); // Insert Text Mode @@ -95,8 +96,6 @@ int Vesa_Install(char **Arguments) gpVesa_BiosState->DI = modeinfoPtr.ofs; VM8086_Int(gpVesa_BiosState, 0x10); - Log_Debug("Vesa", "gpVesa_BiosState->AX = 0x%04x", gpVesa_BiosState->AX); - // Parse Info gVesa_Modes[i].flags = 0; if ( (modeinfo->attributes & 0x90) == 0x90 )