Problems with loading the kernel
Posted: Sat May 29, 2010 3:19 pm
First of all, I'm rather new to Assembly on x86, and my understanding of the language is somewhat limited, so please bear with me.
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:
This code is supposed to read sector 2 (512+ bytes) into memory, and then jumping to the kernel. The kernel code is this:
My intention is to simply printing each character in the string and then halting.
I'm using NASM to assemble the two files and writing them to a disk image with dd (on Windows):
After this, I have a "run.img" file of 540 bytes. When booting it with Bochs, however, it boots and seemingly loads something, saying:
... and then hanging. The last lines from the Bochs console are as follows:
I have found that when adding [ORG 0x8000] at the start of the kernel source makes it print the string correctly. This, however, does not work when booting it on a real machine. I hope someone can point out the error.
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!