flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > From bootloader to kernel |
Author |
|
cod3b453 22 Jan 2012, 13:38
As the name suggests, the boot loader will also need to load the kernel from disk into memory (temporary buffer); in the case of a C kernel, there are a few possibilities. Depending on your compiler/setup, the normal output is PE or ELF binaries which include a header that tells you the section offsets and sizes; you'll want to unpack the binary (to another location) according to these values and then jump to the entrypoint address (also in the header).
If your kernel is 32bit, the final image address must be what is specified in the header but in 64bit you can compile with position independent code (PIC) enabled and put the image anywhere. A few gotchas if you're aiming for a 64bit kernel are that VS does not allow 64bit inline assembly, so you'll need to create and link an external COFF file in FASM, and the fastcall convention is different between windows and unix compilers, so any calls into supporting FASM code will need to be (re)assembled accordingly. For the actual jump from the loader to kernel, you have the choice of the jump that switches to protected/long mode going directly to the kernel entrypoint, and having to set up the correct register state in C (ASM still required here), or you can do this in the loader and jump again to the entry point. Hope that helps. |
|||
22 Jan 2012, 13:38 |
|
Andy 22 Jan 2012, 14:57
Ok, what compiler you suggest me to use to get one of this output formats? Can you point me to some good resources or some simple examples?
|
|||
22 Jan 2012, 14:57 |
|
cod3b453 22 Jan 2012, 16:36
Without more information, I'd say probably GCC, which is multi platform and well supported by IDEs, if you want one. On unix the default output is ELF, on the windows MinGW port it is PE exe.
I don't have example code for loading the binary because I use FASM macros to merge it into my ASM module at compile time but you can lookup the PE/ELF header definitions and do this at run time. For a 64bit target, I use: Quote: gcc -nostdinc -O2 -Wall -Werror -c -fPIC -omain.o ../main.c -m64 |
|||
22 Jan 2012, 16:36 |
|
egos 23 Jan 2012, 09:14
Usually stage 1 boot loader runs raw binary. So you should have kernel in raw binary format if it's run directly by stage 1. Or you should have stage 2 boot loader in raw binary format that is run by stage 1 and then runs kernel in ELF/PE format.
|
|||
23 Jan 2012, 09:14 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.