I feel like this is a really dumb question, but I honestly can't figure this out. The instructions on the wiki at https://wiki.osdev.org/Creating_a_64-bit_kernel
are unclear on how you would get the VMA of the kernel, as isn't it inconsistent on where it's mapped from boot to boot, and so the linker script can't possibly know the VMA of the kernel??
I also feel like I'm doing something wrong with my approach, wherein I use UEFI to test some features, get the GOP so the kernel knows the details of the framebuffer,
load the kernel ELF file from the filesystem, get the memory map, call ExitBootServices so the kernel isn't affected by UEFI, then load the kernel, and jump to the entry point.
Github repo for implementation of the steps I described: https://github.com/ThatCodingGuy86/UnnamedOS-V2
How to load a higher half kernel in UEFI enviorment [solved]
-
- Posts: 18
- Joined: Sat Apr 30, 2022 5:57 am
How to load a higher half kernel in UEFI enviorment [solved]
Last edited by ThatCodingGuy89 on Thu Jun 02, 2022 6:16 am, edited 1 time in total.
Re: How to load a higher half kernel in a UEFI enviorment?
Why? You can use paging to abstract the physical address of the kernel away.ThatCodingGuy89 wrote:I feel like this is a really dumb question, but I honestly can't figure this out. The instructions on the wiki at https://wiki.osdev.org/Creating_a_64-bit_kernel
are unclear on how you would get the VMA of the kernel, as isn't it inconsistent on where it's mapped from boot to boot, and so the linker script can't possibly know the VMA of the kernel??
I have pretty much the same approach as you, with the bootloader UEFI executable. That executable loads the kernel to any page-aligned address it can get. Then it maps the load segments from the ELF headers as required. The main kernel is a normal ELF64 executable (ET_EXEC), linked to -2GB. As part of the parameter structure the bootloader hands to the main kernel, there is also a memory map, and the bootloader simply sets the place where the kernel image is, as well as the bootstrap page tables, as reserved.
That means the kernel can always be linked to -2GB, no matter where it is loaded. It also means the kernel can always find its ELF header at that address, and can then re-initialize the paging stuff with its own mappings. That brings the paging entirely under the kernel's control.
Carpe diem!
-
- Posts: 18
- Joined: Sat Apr 30, 2022 5:57 am
Re: How to load a higher half kernel in a UEFI enviorment?
Oh. I am an idiot, I mixed up physical memory and virtual memory somehow.nullplan wrote:Why? You can use paging to abstract the physical address of the kernel away.ThatCodingGuy89 wrote:I feel like this is a really dumb question, but I honestly can't figure this out. The instructions on the wiki at https://wiki.osdev.org/Creating_a_64-bit_kernel
are unclear on how you would get the VMA of the kernel, as isn't it inconsistent on where it's mapped from boot to boot, and so the linker script can't possibly know the VMA of the kernel??
Re: How to load a higher half kernel in UEFI enviorment [sol
These "higher-half" kernel pages / tutorials are basically just a hack and confusing people, especially people new to OS development. I would encourage anyone to ignore them and just map your kernel where you want it in virtual memory (and here with UEFI, you really have no choice).