OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:17 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to load a higher half kernel in UEFI enviorment [solved]
PostPosted: Wed Jun 01, 2022 4:47 am 
Offline

Joined: Sat Apr 30, 2022 5:57 am
Posts: 18
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


Last edited by ThatCodingGuy89 on Thu Jun 02, 2022 6:16 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How to load a higher half kernel in a UEFI enviorment?
PostPosted: Wed Jun 01, 2022 10:19 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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??
Why? You can use paging to abstract the physical address of the kernel away.

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!


Top
 Profile  
 
 Post subject: Re: How to load a higher half kernel in a UEFI enviorment?
PostPosted: Thu Jun 02, 2022 6:13 am 
Offline

Joined: Sat Apr 30, 2022 5:57 am
Posts: 18
nullplan wrote:
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??
Why? You can use paging to abstract the physical address of the kernel away.


Oh. I am an idiot, I mixed up physical memory and virtual memory somehow.


Top
 Profile  
 
 Post subject: Re: How to load a higher half kernel in UEFI enviorment [sol
PostPosted: Thu Jun 02, 2022 10:36 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
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).

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], SemrushBot [Bot] and 81 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group