From: John Hodge Date: Wed, 19 Feb 2014 11:48:24 +0000 (+0800) Subject: Kernel/x86 - Multiboot module cleanup X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a02ac21b74b7030647c033ed6c6793e2d69364ac;p=tpg%2Facess2.git Kernel/x86 - Multiboot module cleanup --- diff --git a/KernelLand/Kernel/arch/x86/main.c b/KernelLand/Kernel/arch/x86/main.c index 93470a44..10cac716 100644 --- a/KernelLand/Kernel/arch/x86/main.c +++ b/KernelLand/Kernel/arch/x86/main.c @@ -134,20 +134,9 @@ void Arch_LoadBootModules(void) Log_Warning("Arch", "Unable to load module"); continue ; } - - #if 0 - // Unmap and free - int numPages = (mod->Size + ((tVAddr)mod->Base&0xFFF) + 0xFFF) >> 12; - MM_UnmapHWPages( (tVAddr)gaArch_BootModules[i].Base, numPages ); - - //for( int j = 0; j < numPages; j++ ) - // MM_DerefPhys( mod->PBase + (j << 12) ); - - if( (tVAddr) mod->ArgString > MAX_ARGSTR_POS ) - MM_UnmapHWPages( (tVAddr)mod->ArgString, 2 ); - #endif } Log_Log("Arch", "Boot modules loaded"); - if( gaArch_BootModules ) - free( gaArch_BootModules ); + Multiboot_FreeModules(giArch_NumBootModules, gaArch_BootModules); + giArch_NumBootModules = 0; + gaArch_BootModules = NULL; } diff --git a/KernelLand/Kernel/arch/x86/mboot.c b/KernelLand/Kernel/arch/x86/mboot.c index b7cebbd4..726d2d23 100644 --- a/KernelLand/Kernel/arch/x86/mboot.c +++ b/KernelLand/Kernel/arch/x86/mboot.c @@ -142,18 +142,26 @@ tBootModule *Multiboot_LoadModules(tMBoot_Info *MBInfo, tVAddr MapOffset, int *M ret[i].Base = (void*)( (tVAddr)MM_MapHWPages(mods[i].Start, (ret[i].Size+ofs+0xFFF) / 0x1000) + ofs ); - // Only map the string if needed - if( !MM_GetPhysAddr( (void*)(mods[i].String + MapOffset) ) ) - { - // Assumes the string is < 4096 bytes long) - ret[i].ArgString = (void*)( - (tVAddr)MM_MapHWPages(mods[i].String, 2) + (mods[i].String&0xFFF) - ); - } - else - ret[i].ArgString = (char*)(tVAddr)mods[i].String + MapOffset; + // Assumes the string is < 4096 bytes long) + ret[i].ArgString = (char*)MM_MapHWPages(mods[i].String, 2) + (mods[i].String&0xFFF); } return ret; } +void Multiboot_FreeModules(const int ModuleCount, tBootModule *Modules) +{ + for( int i = 0; i < ModuleCount; i ++ ) + { + Uint ofs = Modules[i].PBase % PAGE_SIZE; + Uint nPages = (Modules[i].Size+ofs+PAGE_SIZE-1) / PAGE_SIZE; + MM_UnmapHWPages(Modules[i].Base, nPages); + MM_UnmapHWPages(Modules[i].ArgString, 2); + + // TODO: handle previous freeing of this page + for( int pg = 0; pg < nPages; pg ++ ) + MM_DerefPhys( Modules[i].PBase + pg*PAGE_SIZE ); + } + free(Modules); +} + diff --git a/KernelLand/Kernel/include/mboot.h b/KernelLand/Kernel/include/mboot.h index ad936559..6ffd5c11 100644 --- a/KernelLand/Kernel/include/mboot.h +++ b/KernelLand/Kernel/include/mboot.h @@ -63,5 +63,6 @@ typedef struct { extern int Multiboot_LoadMemoryMap(tMBoot_Info *MBInfo, tVAddr MapOffset, tPMemMapEnt *Map, const int MapSize, tPAddr KStart, tPAddr KEnd); extern tBootModule *Multiboot_LoadModules(tMBoot_Info *MBInfo, tVAddr MapOffset, int *ModuleCount); +extern void Multiboot_FreeModules(const int ModuleCount, tBootModule *Modules); #endif