By using examples on the Internet and experimenting with the language, I'm trying to write a very simple bootloader that should load a very simple kernel in real mode. However, I'm having a problem in the loading process. My intention is to have the bootloader occupy the first 512 bytes (naturally) with the kernel following right behind. From what I understand, I can do this by reading the kernel part from the drive into a memory location with interrupt 13 and then jump to that point in memory. This is my bootloader code:
Code: Select all
[ORG 0x7C00] ; The BIOS loads the boot sector into memory location 0x7C00
mov ah, 02h ;read function.
mov al, 1 ;sectors to read.
mov ch, 0 ;track.
mov cl, 2 ;sector.
mov dh, 0 ;head.
mov bx, 0800h ;kernel memory point
mov es, bx
mov bx, 0h
int 13h ;read!
jmp 0800h:0000h ;go to kernel memory point
times 510-($-$$) db 0 ;Fill the rest of the files with zeros, until we reach 510 bytes
db 0x55
db 0xAA
Code: Select all
mov si, msgwelcome
print_str:
lodsb
cmp al, 0 ;0 is end of string
je stop
mov ah, 0Eh ;teletype output
int 10h ;write!
jmp print_str ;next char!
stop:
cli
hlt
msgwelcome db 'Welcome.', 13, 10, 0
I'm using NASM to assemble the two files and writing them to a disk image with dd (on Windows):
Code: Select all
nasm -f bin -o boot.bin boot.asm
nasm -f bin -o kernel.bin kernel.asm
dd if=boot.bin of=run.img
dd if=kernel.bin of=run.img seek=1
Code: Select all
Booting from Floppy...
_
Code: Select all
00014041543i[BIOS ] Booting from 0000:7c00
00014042376i[FDD ] partial read() on floppy image returns 28/512
00014088485i[CPU0 ] WARNING: HLT instruction with IF=0!