OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 1:36 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: EFI Loading and jumping to x64 kernel (edk2)
PostPosted: Thu Apr 27, 2017 12:08 am 
Offline

Joined: Wed Apr 26, 2017 11:43 pm
Posts: 2
Hi this is my first post here!

Right now i'm working on a bootloader in uefi and it's going quite fine. I'm able to draw a nice background gradient, load a logo and draw that as well. Right now i'm busy trying to load a kernel image (in ELF format) and handing control over to this kernel.

I have a few questions about this process:
- Paging is turned on in uefi, but do i need to alter the page tables before i load the kernel, or can the kernel take care of this?
- When loading the kernel, can i just load the full image or do i need to allocate diffrent areas for example for stack etc?
- When the kernel is loaded in memory and ExitBootServices() is called, how the heck do i jump to the kernel? Can this happen via an efi function (not likely), a pointer, inline assembly, or an assembly file linked to my EFI file?
- After i've succesfuly handed control to the kernel, just for confirmation, i need to setup the paging table again and call x64 functions via inline assembly?

Thanks in advance for your help!


Top
 Profile  
 
 Post subject: Re: EFI Loading and jumping to x64 kernel (edk2)
PostPosted: Fri Apr 28, 2017 1:23 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
joejoepie wrote:
- Paging is turned on in uefi, but do i need to alter the page tables before i load the kernel, or can the kernel take care of this?
- When loading the kernel, can i just load the full image or do i need to allocate diffrent areas for example for stack etc?

It's up to you. It's your loader, your kernel, your image format.
Quote:
- When the kernel is loaded in memory and ExitBootServices() is called, how the heck do i jump to the kernel? Can this happen via an efi function (not likely), a pointer, inline assembly, or an assembly file linked to my EFI file?

How a jump into the code could happen via some other function call? JumpIntoThereForMePlease()? There is no such a "useful" function. xD
You load your image, you find its entry point, you throw its arguments at it, accordingly to your calling convention, and you do jump into the entrypoint. You might do this in assembly, C or even XML, I heard there are even such approaches. :D
Read carefully UEFI spec on the ExitBootServices() and GetMemoryMap() services. That's the ultimate reference regarding the interaction between the FW and your loader at the control transfer phase between them.
Once ExitBootServices() completed, your code owns the memory map, you could do all you want and need.
First, it seems, you need to learn a lot.
Don't forget to not trash FW reserved memory.
Quote:
- After i've succesfuly handed control to the kernel, just for confirmation, i need to setup the paging table again and call x64 functions via inline assembly?

Thanks in advance for your help!

Having your kernel being able at least print something about its existence, generally means you are already aware of what you need to do with the memory layout/translation setup.
Just learn and think about what your memory management should look like, then you will know whether you need to rebuild page tables after your own loader or not. nobody knows this in fact. except you. in future.

_________________
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).


Top
 Profile  
 
 Post subject: Re: EFI Loading and jumping to x64 kernel (edk2)
PostPosted: Tue May 02, 2017 2:11 am 
Offline

Joined: Wed Apr 26, 2017 11:43 pm
Posts: 2
Thanks a lot for your info!

I'm indeed still learning a lot, luckily i have osdev wiki and the UEFI spec! :)
I've searched some stuff and apparently you can jump in C by using a function pointer,
but i'm not sure this will work for me since mu efi bootloader is in PE format, and the kernel
will be ELF... So an inline assembly jump will have to do i guess.

Os development certainly is an interesting topic!


Top
 Profile  
 
 Post subject: Re: EFI Loading and jumping to x64 kernel (edk2)
PostPosted: Tue May 02, 2017 6:33 am 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
joejoepie wrote:
Thanks a lot for your info!

I'm indeed still learning a lot, luckily i have osdev wiki and the UEFI spec! :)
I've searched some stuff and apparently you can jump in C by using a function pointer,
but i'm not sure this will work for me since mu efi bootloader is in PE format, and the kernel
will be ELF... So an inline assembly jump will have to do i guess.

Os development certainly is an interesting topic!

why shouldn't it work? it doesn't depend on the loader executable format, your loader just needs to be an elf loader, or whatever image format you choose for its payload. the loader and the callee should just follow the same calling convention, basically the loader should place arguments the way, the kernel entry expects them, it has nothing to do with what format your loader is, nor the kernel image format.

_________________
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).


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: SemrushBot [Bot] and 125 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