The Bootloader

In the beginning, I was happily building my little kernel of 33 KB using the Gregor Brunmar tutorial. The things were simple when I was coding the Babel red, white and black screen. But as time went on, I started to manage with the logo of the HOS and later the messages. Fonts and animations are heavy and they take too much space. When I surpass, without knowing, the 1 Mbyte gap, things stopped working. I was very confused at first, but I remembered a problem that, 2 partners of me, had in university: the lack of space when they introduced strings. The optimization flags of GCC cut down the size of the kernel image but instead graphics quality decreased and sometimes the OS get stuck. Then, I started to try all pre-made bootloaders for 32 bits that I could download, including simulation with El-Torito (never ran for me). Wasted and sicked, I decided to start working with Grub. After following many How-To guides I reached my goal. Simply you need to add the "-T link.ld" option to the line where "ld.exe" is linking the object-code. The name "link.ld" refers to the following file:


ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}

Yes, it is. "link.ld" makes reference to the labels of the "boot.asm" file that developed Brandon F1 and that is available in the "OsDever" page. In "boot.asm" you will need to add the line "call __Z9principalv" after the "stublet" label as above:

stublet:
    call __Z9principalv
    jmp $

Where "__Z9principalv" is the name of the main function in your C/C++ code. It seems that the compiler teases you with this name, so just to be sure, use the command: "nm main_file.o", where "main_file" is the name of the file where the main function is located. Compile the "boot.asm" with NASM in the "elf" format and linked it with your C/C++ source. In my case the compile log is the following:

Compile the "boot.asm" with NASM in the "elf" format and linked it with your C/C++ source.

In my case the compile log is the following:

%ruta_gnu%\ld -T link.ld -o kernel.o boot.o main.o ports.o video.o hileras.o sonido.o matematica.o
%ruta_gnu%\objcopy -R .note -R .comment -S -O binary kernel.o kernel.bin

The second line is the idea of Gregor Brunmar. For finish this section, you will need to copy the "kernel.bin" to the directory "~\BOOT\" of a pre-made boot floppy disk of Grub (you can try to build it up from zero by your self too). Safe the content of the virtual floppy disk (ie. mounted by ImDisk) and restore it to a physical drive (using WinImage) or try it with Virtual Box.

Grub level, clear!

---------------------------------------------------------------------------------------------------------------------------------

1. http://www.osdever.net/bkerndev/Docs/basickernel.htm