< Operating Systems
Basic x86 boot loader
Here we are going to write a simple bootsector for an x86 machine to start with hands on experience in operating system design. The bootsector must follow a few rules. It must be written in assembly, be exactly 512 bytes long, and end with the bootloader signature of 55AA. We are also going to load it into memory at 7C00. You will need the nasm assembler.
Assembly code for infinite loop bootloader
[BITS 16]
[ORG 0x7C00]
main:
jmp $
times 510-($-$$) db 0
dw 0xAA55
- [BITS 16] Tells NASM to compile in 16 bit mode (Note to self: see about rewriting file to use 32 bits.)
- [ORG 0x7C00] The code will be loaded at address 7C00 in memory
- main: main function of program
- jmp $ jumps to start of function creating an infinite loop
- times 510-($-$$) db 0 Fills remaining 510 bytes with zeros
- dw 0xAA55 word (remaining 2 bytes) with bootloader signature, would not be recognized as bootable disk without this.
This article is issued from Wikiversity. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.