Page 3 of 3

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

Posted: Fri Nov 20, 2015 9:25 am
by MollenOS
Haha great catch, the code is untested, it's newly written. But never the less you just saved me from some debugging ;)

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

Posted: Fri Nov 20, 2015 11:33 am
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

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

Posted: Fri Nov 20, 2015 11:41 am
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

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

Posted: Fri Nov 20, 2015 11:49 am
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?

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

Posted: Fri Nov 20, 2015 11:58 am
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.

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

Posted: Fri Nov 20, 2015 3:42 pm
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!

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

Posted: Fri Nov 20, 2015 3:54 pm
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.

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

Posted: Fri Nov 20, 2015 3:55 pm
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?

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

Posted: Fri Nov 20, 2015 4:11 pm
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.

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

Posted: Fri Nov 20, 2015 4:13 pm
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!

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

Posted: Fri Nov 20, 2015 5:09 pm
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