Can't read a sector from disk
Posted: Wed Apr 20, 2011 7:27 am
Hi there,
I'm implementing my own bootloader for educational use, but I got stuck at the point where I try to load another sector. I want to do this, to load the second stage of my bl. I use int 0x13 function ah = 0x2 and after that failed i tried the extension 0x42 which also failed.
Now.. some sources..
first, a verry simple loader which calls the sector read routines:
then, the sector readers which uses int 0x13 with ah = 02H (called readsector.asm)
And last, but not least the file biosextensions.asm which uses the extended read sector
Does any one see why my CF is always set and why there is always an error? Ohh before I forget, I use kvm:
Thansk in advance,
Bietje
I'm implementing my own bootloader for educational use, but I got stuck at the point where I try to load another sector. I want to do this, to load the second stage of my bl. I use int 0x13 function ah = 0x2 and after that failed i tried the extension 0x42 which also failed.
Now.. some sources..
first, a verry simple loader which calls the sector read routines:
Code: Select all
[BITS 16]
[ORG 0x7C00]
main:
; call loadimage ; with extensions
call readsector ; without extendsion
mov al, 'y'
mov ah, 0x0E
xor bh, bh ; page 0
int 0x10
jmp $
;
; Sector load routines
;
%include 'biosextensions.asm'
%include 'readsector.asm'
times 510 - ($-$$) db 0
dw 0xAA55
Code: Select all
readsector:
.start:
xor ah, ah ; function 0 = reset
mov dl, 0x80 ;pop dx ; drive 0 = floppy
int 0x13
jc .start
.loadimage:
mov bx, 0x1000
mov es, bx
xor bx, bx
mov ah, 0x2 ; function 2
mov al, 0x1 ; read 1 sector
xor ch, ch ; we are reading on cyl 0
mov cl, 0x2 ; sector to read (The second sector)
xor dh, dh ; head number
mov dl, 0x80 ; drive number.
int 0x13 ; call BIOS - Read the sector
jc .loadimage
ret
Code: Select all
loadimage:
.reset:
mov ah, 0x41
mov dl, 0x80
mov bx, 0x55AA
int 0x13
jc .reset
.read:
mov ah,0x42
mov dl,0x80
lea si,[lbaadr]
int 0x13
jc .reset
ret
;
; Disk address
;
lbaadr:
db 10h ; packet size (16 bytes)
db 0 ; reserved, must be 0
dw 0x1 ; number of sectors to transfer
dw 0x0100 ; Buffer's segment
dw 0x0000 ; Buffer's offset
dq 00002h ; 64-bit starting sector number
Code: Select all
kvm -m 200M -hda <image>
Bietje