I’ve been working on the Rust OS outlined in these posts:
https://os.phil-opp.com/advanced-paging/
They use a recursive page table map to map arbitrary pages to virtual memory. I’d like to use an offset mapping like the Linux kernel uses. In Linux, the kernel lives in a high memory area (above PAGE_OFFSET) and the user environments are mapped into the low memory area. Thinking about page tables makes my head spin though &em; it’s a real have to think 4th dimensionally kind of situation.
The issue is that on boot the pages are mapped in by the boot loader using its own scheme, and I’m not entirely sure what the mappings are. The kernel will have a bad time if it’s mapped away from where it is running, so if I do move to a different scheme, I’ll need to move the kernel with it. Alternatively, maybe I should modify the boot loader to map it in a way that is consistent with the final result.
Some questions I have:
1) what are the boot loader memory mappings?
2) if I move the kernel, could I just jump to the new location? are the addresses offsets or absolute?
3) could I copy the kernel pages to the equivalent offset pages? (are the equivalent pages guaranteed to be free?)
Some resources:
https://docs.rs/x86_64/0.3.5/x86_64/structures/paging/index.html
https://elinux.org/images/b/b0/Introduction_to_Memory_Management_in_Linux.pdf
https://www.kernel.org/doc/gorman/html/understand/understand006.html
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-828-operating-system-engineering-fall-2012/labs/