Memory mapping
Memory mapping
Hiya, I've gotten a kernel to boot and get the Multiboot info struct, but how do I use it for memory mapping for an allocator? And why are there multiple memory structs pointed to by the Multiboot struct?
Re:Memory mapping
There are multiple memory structs because you need a struct for each region of memory, and unless your computer either has zero reserved memory or zero free memory, there would necessarily have to be at least two. In practice, there's usually a lot more (9 different regions in the memory map on my laptop, for example). You need to look at the type field of each struct to determine whether that region is usable or not. Type 1 means available, type 2 means reserved, other types should be treated as reserved as well unless you're sure you know what you're doing.Crazed123 wrote: Hiya, I've gotten a kernel to boot and get the Multiboot info struct, but how do I use it for memory mapping for an allocator? And why are there multiple memory structs pointed to by the Multiboot struct?
Re:Memory mapping
So how would I turn that into something an allocator can use without already having dynamic allocation implemented?
Re:Memory mapping
Hi,
Cheers,
Brendan
This depends on how your OS will manage physical memory. If your OS manages 4 Kb pages only (and doesn't use physical addresses that are more than 32 bit) then perhaps something like:Crazed123 wrote: So how would I turn that into something an allocator can use without already having dynamic allocation implemented?
Code: Select all
for(area = 0; area++; area < totalAreas) {
if(memoryStruct.type == 1) {
startAddress = memoryStruct.startAddress;
endAddress = memoryStruct.endAddress;
if((startAddress & 0xFFF) != 0) {
startAddress = (startAddress & 0xFFFFF000) + 0x1000;
}
if(endAddress >= 4 Gb) endAddress = 4 Gb;
if(startAddress >= 4 Gb) startAddress = 4 Gb;
endAddress = endAddress & 0xFFFFF000;
while(startAddress < endAddress) {
if(startAddress isn't used by something that's de-allocated later) {
freePhysicalPage(startAddress);
}
startAddress += 0x1000;
}
}
memoryStruct = memoryStruct + memoryStruct.size;
}
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:Memory mapping
Yeah, my OS will be managing 4kb pages with bitmaps and super-bitmap. Almost got the bitmaps part down pat. Thanks!