Hanz wrote:Even now I have so fun that I can't event imagine how fun it will be. (Or, maybe "the fun kernel parts" is sarcasm.)
Ah, it's not sarcasm. The kernel and user-space is the goal, it's where you can do useful things and be a real operating system. The bootloader itself is irrelevant directly, it's only task is loading the kernel. There are technical details and challenges all over the place, but in the kernel you become a real operating system and do real things.
I don't do bootloaders myself for the above reasons (and when I do, I won't use a naive approach), but the basic approach is that produce two binaries separately: The bootloader itself and the kernel. The bootloader you just do with your assembler and make a raw image that can be written to your boot media. The kernel should be linked like shown in Bare Bones (except that you might decide another load address, if you don't do multiboot). You then get a linked ELF kernel. If you implement multiboot, you load that kernel as is in the multiboot manner. Otherwise, you can use a tool like objcopy to convert the ELF kernel into whatever format you prefer. You now have the bootloader and the kernel in your favorite format. Somehow you mix that into a basic bootable image with your bootloader installed, which can then locate the kernel on the boot media (perhaps using a little filesystem), load it appropriately into memory and switch to it.
It's best to link to an ELF kernel first. This is a versatile format and contains a lot of useful meta information that makes them convenient, existing tools understand then natively, they can be dumped, studied, converted, all that good stuff you can't do with naive formats. You then convert the ELF binary into whatever format you prefer.
A naive way to do this: You link the kernel to 0x7E00 (512 bytes after the bootloader). You objcopy the kernel to a flat binary loadable at 0x7E00. Your 512 byte bootloader loaded at at 0x7C00, loaded from byte offset 0 of the harddisk, loads some sectors from byte offset 512 (where your kernel will be) to 0x7E00 and onwards. The bootloader switches to protected mode and all the other bootloader stuff and starts executing at 0x7E00. To make a harddisk image, you merely cat bootloader.bin kernel.bin and pad some zeroes.
A better way to do this: The harddisk contains an ext2 filesystem containing the kernel at /boot/myos.kernel as a 32-bit ELF multiboot kernel. The bootloader loads its part two and then parses the filesystem with its read-only ext2 driver, locates the kernel, loads it to the addresses written in the ELF program, switches to protected mode and starts executing the kernel as detailed in the multiboot standard.
I certainly think it can good experience to write a bootloader. I wouldn't recommend it as the way to start osdev. My recommendation is to use GRUB and multiboot to get started, write a good operating system, when GRUB isn't good enough, you write your own awesome bootloader with all your experience.