Tuesday, July 13, 2010

Making your own simple bootloader



In computing, booting (also known as "booting up") is a bootstrapping process that starts operating systems when the user turns on acomputer system. A boot sequence is the initial set of operations that the computer performs when power is switched on. The bootloader typically loads the main operating system for the computer.

The CPU starts in real mode and the BIOS loads this code at address 0000:7c00. The boot loader size have to 512 KB and the last two bytes must be aa and 55. That code is the boot signature.

This is a very very simple bootloader ;p (write in NASM)
org 7c00h ;put the boot loader into memory at address 0000:7c00h
hang:
jmp hang

times 510-($-$$) db <---- this code is to fill zero and now 2 bytes less now

db 0x55
db 0xAA

And this is how to write a message at your bootloader.

org 7c00h

xor ax, ax ; make it zero
mov ds, ax
mov si, msg
ch_loop:lodsb ; this is for write character to your monitor   read interrupt reference for more information
or al, al  ; zero=end of string
jz hang    ; get out
mov ah, 0x0E
int 0x10
jmp ch_loop
hang:
jmp hang
msg db 'your message here', 13, 10, 0
times 510-($-$$) db 0
db 0x55
db 0xAA

This is very simple bootloader. To run this program you must compile this program to binary file and write it to your floppy disk. The code is assembled in NASM and copied to floppy.

nasmw boot.asm -f bin -o boot.bin

Then write the bin file to your floppy disk with debug in command prompt.

debug boot.bin
-W 100 0 0 1 ; 100 debug will start at CS:0100. 0 is the floppy A. 0 is start sector. 1 is sector size to write.
-Q
This is how to write bootloader on floppy disk. I'm searching to booting from USB flash disk but i need more knowledge base. Contact me if someone know how to make bootloader form flash disk

No comments:

Post a Comment

Footer

Your Ad Here