Can't read a sector from disk

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Can't read a sector from disk

Post by Bietje »

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:

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
then, the sector readers which uses int 0x13 with ah = 02H (called readsector.asm)

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
And last, but not least the file biosextensions.asm which uses the extended read sector

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
Does any one see why my CF is always set and why there is always an error? Ohh before I forget, I use kvm:

Code: Select all

kvm -m 200M -hda <image>
Thansk in advance,
Bietje
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Can't read a sector from disk

Post by DavidCooper »

Bietje wrote: .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

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
What makes you think drive 0 is drive 80h?
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: Can't read a sector from disk

Post by Bietje »

http://en.wikipedia.org/wiki/INT_13H#Drive_Table

That :p. I found the problem.. It is quit stupid.. Since i load only one sector, is it impossible to jump to the second one.. So I have to create a virtual hard disk (image) en use a tool like dd to write the first and the second sector to it.
Post Reply