Just when I thought I had my Bootloader figured out, I run into a snag when attempting to read from a hard disk.  This code used to work before on a floppy drive.  I have tried inserting code to reset the drive controller, but it miserably fails.  Good thing I have that error message.
krnlod:		;function to load the kernel into memory
jmp .rddsk ;jump over error function to read the disk

.rderr ;label to jump to if error occurs
lea si, ;load the error sting into SI
call prntstr ;print the string
cli ;clear interupts
hlt ;enter unrecoverable halt

.rddsk
mov ax, 0x8112 ;load 0x8112 into AX register (can't directly manipulate ES)
mov es, ax ;set ES to contents of AX (location of memory to read to)
xor bx, bx ;set offset to 0x0000

mov ah, 0x02 ;place 0x02 (read function) into AH
mov al, 0x12 ;read 18 sectors
mov ch, 0x00 ;read from cylinder 1
mov cl, 0x03 ;read from sector 3
mov dh, 0x00 ;read from head 0
mov dl, ;read from drive

int 0x13 ;call int 0x13 to read from disk
jc .rderr ;if carry flag is set (read unsuccessfull) go to error routine

lea si, ;load the address of the Kernel Load Message into SI
call prntstr ;print the string
ret


The variable is set from the initial DL register, so it should have the correct drive variable.  The thing is, I don't know what drive nuber it would be, as it is a USB flash drive.  I also tried it with Qemu, still the same thing when emulating a Hard Disk.  I figured that I had to read 18 sectors, as the image itself is is 21 sectors, with the first being the bootsector, and the second and third, being the program using this code.

I thank you all for your help and tolerance of my n00bishness.

EDIT:  The most strange thing I just discovered, is that it works with the floppy drive being filled with an image in Qemu, and yet even this doesn't work when I insert a hard-coded hard disk value into DL.
Posted on 2009-12-08 10:16:53 by XeonX369