I am concerned about the booting logic one can get in xv6. Specifically, I am interested in the x86_64 long mode.
https://github.com/swetland/xv6 (github happens to be not reachable at the moment of writing)
What is the root of my concern is that line, in entry64.S:
Code: Select all
lgdt (gdtr64 - mboot_header + mboot_load_addr)
Isn't it possible to do the following :
1) probe the available physical ram and not just guess it.
2) always keep the low addresses as is (they are already mapped to physical memory) and put the root of the kernel at the very top of the physical memory.
3) Create the paging, pml4, gdt...
4) jump to long mode
5) The OS knows that it cannot assign any physical memory under 1MB and over the size of the kernel (say 512MB for a small kernel) thanks to the initial memory probing.
6) Obviously no limit for virtual memory, everything is done as usual, unrelated.
That way we get :
1) gdt for cpu0 starting exactly at 0x100000
2) gdt for cpuX start exactly at (0x100000 + sizeof(gdt)) * X
3) code starting from top of kernel (MAX PHYS - 512 MB as to keep with the example) and going down to 0 (as usual). So we have that "middle memory" for the user processes.
But how to be sure that we are not erasing anything (forcing the linker not to start eventual code at 0x100000 since we will use it for our gdts and we don't initialy know how many cpus we have (hence gdts)?
Is there something I am missing, that just asks to blast me out ?