Problem with UEFI bootloader loading PE
Posted: Fri Aug 07, 2020 8:27 am
Been working on this for a day or 2 now, but my kernel does not run. It is loaded by my efi bootloader, code is here: https://pastebin.com/BefcLQbN. My code jumps the the kernel (code here: https://pastebin.com/ZTSWA1TK) all good, but then the kernel does nothing. I have tried having it do a reset via the efi runtime services, does nothing. In the struct I pass to the entry point there is an address to the linear frame buffer for the graphics, my kernel now is meant to draw with that but nothing happens.
In terms of what I've done, firstly I tried loading the sections one by one into memory. Then from looking at the chaiOS loader I realised I had to load the header in too. Then after following this thread viewtopic.php?f=1&t=29818&start=30 I realised I could just dump the file in memory at imageBase. Then I stopped using AllocatePages to get memory for my kernel (as I had been doing previously) and now in this last iteration I have simply asked efi to read from the file and dump the contents at imageBase. All of the times, I have the same result.
In terms of jumping to the entry point, I have tried firstly some asm which I link in which changes the rsp and rbp so that the kernel can run. That did yield the same result as I have now, but at the previous blog link I have found it easier to cast the entry address to a function pointer and call that.
All of this is compiled under visual studio, all runs fine, kernel exe has the section alignment equal to the file alignment. The bootloader and kernel are tested in virtualbox.
Could anyone please explain why the kernel does not run and what I could do to get it running? I shall be very grateful, thanks in advance.
In terms of what I've done, firstly I tried loading the sections one by one into memory. Then from looking at the chaiOS loader I realised I had to load the header in too. Then after following this thread viewtopic.php?f=1&t=29818&start=30 I realised I could just dump the file in memory at imageBase. Then I stopped using AllocatePages to get memory for my kernel (as I had been doing previously) and now in this last iteration I have simply asked efi to read from the file and dump the contents at imageBase. All of the times, I have the same result.
In terms of jumping to the entry point, I have tried firstly some asm which I link in which changes the rsp and rbp so that the kernel can run. That did yield the same result as I have now, but at the previous blog link I have found it easier to cast the entry address to a function pointer and call that.
All of this is compiled under visual studio, all runs fine, kernel exe has the section alignment equal to the file alignment. The bootloader and kernel are tested in virtualbox.
Could anyone please explain why the kernel does not run and what I could do to get it running? I shall be very grateful, thanks in advance.