Best way to start paging early
Posted: Sun Jan 01, 2012 5:09 pm
Hello everyone,
I want to start paging early in my OS, and it's the first thing I do in my kernel right now (using the GDT trick from the wiki). It works fine, but now I need to read the memory map grub gave me, before I can start writing a memory allocator. But I can't easily read the memory map - because it may be in a page over 4 MB (I mapped the first 4MB to the first 4MB of physical memory). So to read the memory map, I would need to add temporary pages for the kernel. But to do that, I would need to allocate memory (not really, but to do it nicely I would), which I can't, nicely, because I don't have a memory map yet!
Currently the best way seems to copy the memory map to directly after the kernel, assume it fits in the first 4 MB (can't imagine it ever wouldn't), and read it from there. Of course, I'd have to be extremely careful I don't accidentally overwrite other multi boot info like that, because it might be immediately after the kernel.
It seems like a sort of circular dependency for which there can't be a very nice solution. It wouldn't be too complex if I'd assume a maximum size for the memory map and simply pre-allocate that size in the kernel. However, all these solutions just feel like a hack.
Is there a simpler way to do this? Or is there a certain assumption that is safe to make about the multi boot info, for instance that it's in the first 4 MB of physical memory?
Thanks in advance
I want to start paging early in my OS, and it's the first thing I do in my kernel right now (using the GDT trick from the wiki). It works fine, but now I need to read the memory map grub gave me, before I can start writing a memory allocator. But I can't easily read the memory map - because it may be in a page over 4 MB (I mapped the first 4MB to the first 4MB of physical memory). So to read the memory map, I would need to add temporary pages for the kernel. But to do that, I would need to allocate memory (not really, but to do it nicely I would), which I can't, nicely, because I don't have a memory map yet!
Currently the best way seems to copy the memory map to directly after the kernel, assume it fits in the first 4 MB (can't imagine it ever wouldn't), and read it from there. Of course, I'd have to be extremely careful I don't accidentally overwrite other multi boot info like that, because it might be immediately after the kernel.
It seems like a sort of circular dependency for which there can't be a very nice solution. It wouldn't be too complex if I'd assume a maximum size for the memory map and simply pre-allocate that size in the kernel. However, all these solutions just feel like a hack.
Is there a simpler way to do this? Or is there a certain assumption that is safe to make about the multi boot info, for instance that it's in the first 4 MB of physical memory?
Thanks in advance