Practical guide on making a bootloader
Two posts ago I explained why 0x55aa is the boot signature. But how do we actually create a bootloader? Well, we can do it in only 3 lines.
We are going to be using Assembly x86. Assembly is the most basic language before machine code.
First, we jump(jmp) to the current address(represented by a dollar sign):
jmp $
Then we are going to fill the rest 510 bytes with 0. We will do this using two dollar signs($$), which means the start of the section,which would be the start of the code.
As we saw in the other post, we need to fill the 510 bytes using db(define byte) and reserve the last two to fill with 0x55aa.
Our code would look like this:
jmp $
times 510-($-$$) db 0
Lastly, we fill the last two bytes with 0x55aa
jmp $
times 510-($-$$) db 0
db 0x55, 0xaa
If we compile this with the NASM and use an emulator like QEMU to run it, we will see that it loads perfectly. But that isn't very interesting, is it?
In the next post, we will print something to the screen.
Comments
Post a Comment