Efi bootloader, PE Loading Image = really stuck.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Efi bootloader, PE Loading Image = really stuck.

Post by MollenOS »

Haha great catch, the code is untested, it's newly written. But never the less you just saved me from some debugging ;)
albus95
Member
Member
Posts: 42
Joined: Tue Nov 17, 2015 3:12 am
Libera.chat IRC: albus95

Re: Efi bootloader, PE Loading Image = really stuck.

Post by albus95 »

MollenOS wrote:Haha great catch, the code is untested, it's newly written. But never the less you just saved me from some debugging ;)
Also just because we I'm reading your code I'm wondering why you are not using the default PE specification structure of windows?
I'm mean all the PE structures and value are in WinNT.h of the standard windows SDK?
There is some difference between your structures and microsoft ones
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Efi bootloader, PE Loading Image = really stuck.

Post by MollenOS »

Mine should be pretty correct, every structure in my header is defined from the PE specification. I'm confident they are correct, if they differ in the NT file I don't know why
albus95
Member
Member
Posts: 42
Joined: Tue Nov 17, 2015 3:12 am
Libera.chat IRC: albus95

Re: Efi bootloader, PE Loading Image = really stuck.

Post by albus95 »

MollenOS wrote:Ok, to get how many pages you will need to allocate, you'll need to parse the sections.

For help, you can see my PeLoader implementation:
https://github.com/Fadekraft/MollenOS/b ... PeLoader.c

The relevant code for you is in the function "Addr_t PeRelocateSections(MCorePeFile_t *PeFile, uint8_t *Data, Addr_t SectionAddr, uint16_t NumSections)"

If you want to skip the whole parsing sections and relocating them, and you just want to call the entry point directly, you need to compile your PE executable with a section alignment set to the file alignment. Normally the section alignment is page-aligned, and file-alignment is set to 0x400. If you set section-alignment to 0x400, the code layout will be the same and you don't need to relocate sections.
By the way you can't set the code alignement to 0x400, in vs you can set it to a power of two, in the wiki I see it set to 512, is ok?
I mean I'm using the /ALIGN directive.
Any way now you say that I can load it in memory instead of do the relocation.
Than what I will have to do? access like

Code: Select all

(Buffer + OptHeader->AddressOfEntryPoint)
and cast it to the function pointer like:

Code: Select all

typedef VOID(__stdcall *KernelEntryPoint)(PLOADER_EFI_BLOCK LoadedBlock);
KernelEntryPoint EntryPoint = (KernelEntryPoint)(Buffer + OptHeader->AddressOfEntryPoint);
EntryPoint(NULL);
Or I have to do also other stuff?
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Efi bootloader, PE Loading Image = really stuck.

Post by MollenOS »

albus95 wrote:
MollenOS wrote:Ok, to get how many pages you will need to allocate, you'll need to parse the sections.

For help, you can see my PeLoader implementation:
https://github.com/Fadekraft/MollenOS/b ... PeLoader.c

The relevant code for you is in the function "Addr_t PeRelocateSections(MCorePeFile_t *PeFile, uint8_t *Data, Addr_t SectionAddr, uint16_t NumSections)"

If you want to skip the whole parsing sections and relocating them, and you just want to call the entry point directly, you need to compile your PE executable with a section alignment set to the file alignment. Normally the section alignment is page-aligned, and file-alignment is set to 0x400. If you set section-alignment to 0x400, the code layout will be the same and you don't need to relocate sections.
By the way you can't set the code alignement to 0x400, in vs you can set it to a power of two, in the wiki I see it set to 512, is ok?
I mean I'm using the /ALIGN directive.
Any way now you say that I can load it in memory instead of do the relocation.
Than what I will have to do? access like

Code: Select all

(Buffer + OptHeader->AddressOfEntryPoint)
and cast it to the function pointer like:

Code: Select all

typedef VOID(__stdcall *KernelEntryPoint)(PLOADER_EFI_BLOCK LoadedBlock);
KernelEntryPoint EntryPoint = (KernelEntryPoint)(Buffer + OptHeader->AddressOfEntryPoint);
EntryPoint(NULL);
Or I have to do also other stuff?
That is correct, and yes, just set the alignment to 512 (which btw is 0x200), it will work as well.
albus95
Member
Member
Posts: 42
Joined: Tue Nov 17, 2015 3:12 am
Libera.chat IRC: albus95

Re: Efi bootloader, PE Loading Image = really stuck.

Post by albus95 »

Ya now it work!!!
But right now I have a bigger problem, how the hell I can write to the screen after I jump into my kernel and call

Code: Select all

 BS->ExitBootServices?
I try the always work

Code: Select all

UCHAR* vidMem = (UCHAR*)0b80000;
think but it no work.
Anyway
I image that the interrupt table is arleady set up and of course also the gpd/ipt stuff.
So what the are initialization that the kernel have to do?
I almost bet that I need to support for ACPI.
Any one have ideas?
There basicly zero information on the net about developing kernel with uefi booting!
Last edited by albus95 on Fri Nov 20, 2015 3:54 pm, edited 1 time in total.
kzinti
Member
Member
Posts: 898
Joined: Mon Feb 02, 2015 7:11 pm

Re: Efi bootloader, PE Loading Image = really stuck.

Post by kzinti »

With UEFI as your firmware, you can't assume the VGA adapter is available / initialized / configured. This is why you can't just write text to the VGA memory buffer and expect it to work.
albus95
Member
Member
Posts: 42
Joined: Tue Nov 17, 2015 3:12 am
Libera.chat IRC: albus95

Re: Efi bootloader, PE Loading Image = really stuck.

Post by albus95 »

kiznit wrote:With UEFI as your firmware, you can't assume the VGA adapter is available / initialized / configured. This is why you can't just write text to the VGA memory buffer and expect it to work.
Ah as I imagine, so I think you can configure it in UEFI somehow!
So how you configure it? Any ideas?
intx13
Member
Member
Posts: 112
Joined: Wed Sep 07, 2011 3:34 pm

Re: Efi bootloader, PE Loading Image = really stuck.

Post by intx13 »

I'm glad to hear you got PE loading working!

There are UEFI protocols available for working with the framebuffer, but I don't know if they're commonly implemented on real hardware. Most operating systems will just load a VGA driver or similar at that point. If you're looking for input on that, you'll probably want to start a new thread though.
albus95
Member
Member
Posts: 42
Joined: Tue Nov 17, 2015 3:12 am
Libera.chat IRC: albus95

Re: Efi bootloader, PE Loading Image = really stuck.

Post by albus95 »

intx13 wrote:I'm glad to hear you got PE loading working!

There are UEFI protocols available for working with the framebuffer, but I don't know if they're commonly implemented on real hardware. Most operating systems will just load a VGA driver or similar at that point. If you're looking for input on that, you'll probably want to start a new thread though.
I probably will do that!
Any way I imagine that it would be a lot of work to implement a vga driver!
albus95
Member
Member
Posts: 42
Joined: Tue Nov 17, 2015 3:12 am
Libera.chat IRC: albus95

Re: Efi bootloader, PE Loading Image = really stuck.

Post by albus95 »

Now we have th next step blog....
Thanks for the help of anybody!
http://forum.osdev.org/viewtopic.php?f=1&t=29835
Post Reply