Re: Efi bootloader, PE Loading Image = really stuck.
Posted: Fri Nov 20, 2015 9:25 am
Haha great catch, the code is untested, it's newly written. But never the less you just saved me from some debugging
The Place to Start for Operating System Developers
http://f.osdev.org/
Also just because we I'm reading your code I'm wondering why you are not using the default PE specification structure of windows?MollenOS wrote:Haha great catch, the code is untested, it's newly written. But never the less you just saved me from some debugging
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?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.
Code: Select all
(Buffer + OptHeader->AddressOfEntryPoint)
Code: Select all
typedef VOID(__stdcall *KernelEntryPoint)(PLOADER_EFI_BLOCK LoadedBlock);
KernelEntryPoint EntryPoint = (KernelEntryPoint)(Buffer + OptHeader->AddressOfEntryPoint);
EntryPoint(NULL);
That is correct, and yes, just set the alignment to 512 (which btw is 0x200), it will work as well.albus95 wrote: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?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.
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 likeand cast it to the function pointer like:Code: Select all
(Buffer + OptHeader->AddressOfEntryPoint)
Or I have to do also other stuff?Code: Select all
typedef VOID(__stdcall *KernelEntryPoint)(PLOADER_EFI_BLOCK LoadedBlock); KernelEntryPoint EntryPoint = (KernelEntryPoint)(Buffer + OptHeader->AddressOfEntryPoint); EntryPoint(NULL);
Code: Select all
BS->ExitBootServices?
Code: Select all
UCHAR* vidMem = (UCHAR*)0b80000;
Ah as I imagine, so I think you can configure it in UEFI somehow!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.
I probably will do that!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.