after doing some research and testing, I think I have clear what are the next steps I have to take to continue with my project, however, given the amount of uncertainly I am leaving at the side of the road on different subjects, because some knowledge gaps, I would really appreciate if you think I am taking the right way.
Current Goal: Concatenate a compiled Kernel in c to the bootloader, load the whole ELF in memory from disk, parse it and allocate the relevant content in memory, and jump to it to continue execution.
This is the scenario:
- - Rolling my own bootloader, which at this moment is able to:
- - Check and enable A20 while in real mode (Bochs comes it with it enabled anyway)
- Reading sectors from floppy, form a binary blob, no filesystem.
- Print stuff for debugging, including converting decimal values to ASCII strings
- Checking memory (Only Int 0x12, no E820 yet, because Bochs is a predictable platform, so it is fair enough so far)
- Preparing some basic segmentation, one segment for code, one for data, covering the whole memory, overlapping.
- Switching to Protected Mode
- Printing stuff in Protected Mode via VGA Text mode, with return carriage and stuff...
- - Check and enable A20 while in real mode (Bochs comes it with it enabled anyway)
- In the kernel side:
- - I have prepared my cross-compiler, targeting i686-elf , 32 bits.
- I am compiling using the following optins: (no linking yet)- - -m32: To make sure it is 32bits
- -c: To compile but do not link yet
- -o: output file...
- -std=gnu99: to use C99 standard and not earlier versions
- -ffreestanding: Let GCC know we do not use any standard library (aside from libgcc).
- -O0: No optimizations, to avoid running into problems at this stage, reduce complexity and make the learning curve not that step.
- -Wall and -Wextra: To make sure the compiler is extremely picky with our code ,and clear it from any warning that could be a potential error later on.
- -masm=intel: Just personal preference to examine the code generated
- - -m32: To make sure it is 32bits
- - I have prepared my cross-compiler, targeting i686-elf , 32 bits.
The conceptual questions I have at this moment are:
- @ Shall I use std=gnu99 or a more recent version of the C standard? Is there any showstopper to use c11 or c17?
- * For linking, I will use:
- - -ffreestanding (it is not clear in the gcc doc if this is a CC or LD parameter)
- -nostdlib: Because we cannot use any standard library
- -lgcc: To include the libgcc library
- I will use also the linker to concatenate my asm bootloader (already in machine code via the NASM assembler) with the compiled code from the Kernel in c, resulting in the final ELF32 file.
- For the aforementioned process, I will use a linker script.
- - -ffreestanding (it is not clear in the gcc doc if this is a CC or LD parameter)
- - Read the sectors where the raw ELF file is
- Parse the ELF file using asm code to extract the code and data, and handle the relocation offsets
- Carefully structure the fetched code and data in memory
- Jump to the kernel.
@ Am I planning this right or there is any pitfall or limitation on this approach?
- * For linking, I will use:
Thanks in advance.