Lately, I’m ‘trying’ to write my own operating system. Yes, A very basic one, just a Boot Loader, a basic kernel, and if possible a Programming Environment. Its not as easy as said, I know. But, why shouldn’t I give it a shot, atleast see where I end up!
So, this is my first Boot Sector Program that actually makes the lifeless machine breath and say ‘Hello World’, or atleast stays, just hanging :-)
Would be needing to write 16 bit instructions to the x86 Processor that powers my machine.
Obviously, I’m not that hardcore monolithic computer guy who writes instructions in hexa form directly, thanks to NASM.
Now, I can write instructions in assembly and ‘NASM’ in my linux will generate the corresponding bytecode for me. That’s one cool program, the author of whom, I should be eternally grateful!
I did some googling, as any bad programmer would do, and plagiarize code that will tell the processor to keep jumping to a section, forever or otherwise hang!
; ; A simple boot sector program that loops forever. ; loop : ; Define a label , " loop ", that will allow ; us to jump back to it , forever. jmp loop ; Use a simple CPU instruction that jumps ; to a new memory address to continue execution. ; In our case , jump to the address of the current ; instruction. times 510 -( $ - $$ ) db 0 ; When compiled , our program must fit into 512 bytes , ; with the last two bytes being the magic number , ; so here , tell our assembly compiler to pad out our ; program with enough zero bytes (db 0) to bring us to the ; 510 th byte. dw 0 xaa55 ; Last two bytes ( one word ) form the magic number , ; so BIOS knows we are a boot sector.
That’s it. saving it as boot_program.asm and running
$nasm boot_program.asm -f bin -o boot_program.bin
will generate the binary file boot_program.bin.
Writing it to a USB drive appropriately, will make the drive bootable!
I haven’t tested that yet. Downlaoding VirtualBox to test my first boot program. Waiting, to see if it works!