2 * Acess2 Kernel x86 Port
3 * - By John Hodge (thePowersGang)
13 int Multiboot_LoadMemoryMap(tMBoot_Info *MBInfo, tVAddr MapOffset, tPMemMapEnt *Map, const int MapSize, tPAddr KStart, tPAddr KEnd)
16 tMBoot_MMapEnt *ent = (void*)((tVAddr)MBInfo->MMapAddr + MapOffset);
17 tMBoot_MMapEnt *last = (void*)((tVAddr)ent + MBInfo->MMapLength);
19 ENTER("pMBInfo pMapOffset pMap iMapSize PKStart PKEnd",
20 MBInfo, MapOffset, Map, MapSize, KStart, KEnd);
22 // Check that the memory map is present
23 if( MBInfo->Flags & (1 << 6) )
25 // Build up memory map
27 while( ent < last && nPMemMapEnts < MapSize )
29 tPMemMapEnt *nent = &Map[nPMemMapEnts];
30 if( !MM_GetPhysAddr(ent) )
31 Log_KernelPanic("MBoot", "MBoot Map entry %i addres bad (%p)",
34 nent->Start = ent->Base;
35 nent->Length = ent->Length;
39 nent->Type = PMEMTYPE_FREE;
42 nent->Type = PMEMTYPE_RESERVED;
48 ent = (void*)( (tVAddr)ent + ent->Size + 4 );
51 else if( MBInfo->Flags & (1 << 0) )
53 Log_Warning("MBoot", "No memory map passed, using mem_lower and mem_upper");
56 Map[0].Length = MBInfo->LowMem * 1024;
57 Map[0].Type = PMEMTYPE_FREE;
58 Map[0].NUMADomain = 0;
60 Map[1].Start = 0x100000;
61 Map[1].Length = MBInfo->HighMem * 1024;
62 Map[1].Type = PMEMTYPE_FREE;
63 Map[1].NUMADomain = 0;
67 Log_KernelPanic("MBoot", "Multiboot didn't pass memory information");
71 nPMemMapEnts = PMemMap_ValidateMap(Map, nPMemMapEnts, MapSize);
72 // TODO: Error handling
74 // Replace kernel with PMEMTYPE_USED
75 nPMemMapEnts = PMemMap_MarkRangeUsed(
76 Map, nPMemMapEnts, MapSize,
80 PMemMap_DumpBlocks(Map, nPMemMapEnts);
82 // Check if boot modules were passed
83 if( MBInfo->Flags & (1 << 3) )
85 // Replace modules with PMEMTYPE_USED
86 nPMemMapEnts = PMemMap_MarkRangeUsed(Map, nPMemMapEnts, MapSize,
87 MBInfo->Modules, MBInfo->ModuleCount*sizeof(tMBoot_Module)
89 LOG("MBInfo->Modules = %x", MBInfo->Modules);
90 tMBoot_Module *mods = (void*)( (tVAddr)MBInfo->Modules + MapOffset);
91 for( int i = 0; i < MBInfo->ModuleCount; i ++ )
93 LOG("&mods[%i] = %p", i, &mods[i]);
94 LOG("mods[i] = {0x%x -> 0x%x}", mods[i].Start, mods[i].End);
95 nPMemMapEnts = PMemMap_MarkRangeUsed(
96 Map, nPMemMapEnts, MapSize,
97 mods[i].Start, mods[i].End - mods[i].Start
102 // Debug - Output map
103 PMemMap_DumpBlocks(Map, nPMemMapEnts);
105 LEAVE('i', nPMemMapEnts);
109 tBootModule *Multiboot_LoadModules(tMBoot_Info *MBInfo, tVAddr MapOffset, int *ModuleCount)
111 if( !(MBInfo->Flags & (1 << 3)) ) {
113 Log_Log("Arch", "No multiboot module information passed");
117 tMBoot_Module *mods = (void*)( MBInfo->Modules + MapOffset );
118 *ModuleCount = MBInfo->ModuleCount;
119 tBootModule *ret = malloc( MBInfo->ModuleCount * sizeof(*ret) );
120 for( int i = 0; i < MBInfo->ModuleCount; i ++ )
124 Log_Log("Arch", "Multiboot Module at 0x%08x, 0x%08x bytes (String at 0x%08x)",
125 mods[i].Start, mods[i].End-mods[i].Start, mods[i].String);
127 ret[i].PBase = mods[i].Start;
128 ret[i].Size = mods[i].End - mods[i].Start;
130 // Always HW map the module data
131 ofs = mods[i].Start&0xFFF;
132 ret[i].Base = (void*)( MM_MapHWPages(mods[i].Start,
133 (ret[i].Size+ofs+0xFFF) / 0x1000
136 // Only map the string if needed
137 if( !MM_GetPhysAddr( (void*)(mods[i].String + MapOffset) ) )
139 // Assumes the string is < 4096 bytes long)
140 ret[i].ArgString = (void*)(
141 MM_MapHWPages(mods[i].String, 2) + (mods[i].String&0xFFF)
145 ret[i].ArgString = (char*)(tVAddr)mods[i].String + MapOffset;