I've done a little OS development on x86 in Visual Studio, but I would like to move over to GCC/Cygwin (this is because I've also recently looked into the OS dev tutorials for the Raspberry Pi, and I would like to use a similar environment for each).
My bootloader is custom written and loads the kernel (which is a PE file) to 0x100000, finds the 'AddressofEntryPoint' field in the PE headers, and begins execution there.
I can compile 'kernel.c' straight into 'kernel.img' without linking (ie, using 'gcc -c'), and the kernel loads correctly. When I use any form of linking, it no longer loads.
I've used objdump and 'PE Explorer' to analyse the executable, and both report that the entry point is 0x100000, which is the same as the image base. This explains why the bootloader can't load it.
So, what has happened to the headers? I'm guessing that I've done something wrong in the linker script, or there is a special consideration with cygwin that I'm not yet aware of.
Can anyone suggest where I may have gone wrong? Or is it better to use some other file format, such as ELF, and rewrite sections of the bootloader? I think I'd prefer to stay with PE if possible, as I have more understanding of how it works than ELF (which is zero).
Any suggestions?
I have tried several linker scripts, including the one on the bare bones page. Here is one example that I've tried:
Code: Select all
ENTRY (_kmain)
BASEADDRESS = 0x100000;
SECTIONS
{
. = BASEADDRESS;
.text : AT(ADDR(.text))
{
*(.text)
}
.data : AT(ADDR(.data) - BASEADDRESS)
{
*(.data)
}
}