Question

I am trying to read disk sectors by the following code:

disk_load :
push dx 

mov ah , 0x02 ; BIOS read sector function
mov al , dh ; Read DH sectors(dh is initialized before calling the routine)
mov ch , 0x01 ;
mov dh , 0x00 ; Select head 0
mov cl , 0x02 ; Start reading from second sector ( i.e.
; after the boot sector )

mov dl,0x80 (tried with 0x00 as well)

int 0x13 ; BIOS interrupt

pop dx ; Restore DX from the stack
jc cset

cmp dh,al ; if AL ( sectors read ) != DH ( sectors expected )
jne disk_error ; 

Problem is ,Carry flag is set every time denoting an error. Initially I tried boot disk 0x00 which when I checked AL register afterwards found out that no sectors are being read. Then I changed to 0x80 ,now AL register would have the exact number of sectors requested but still Carry flag is being set!

So what could be the problem here? Carry seems to be set always after int 0x13! I am running an iso file in Virtual Box if that matters.

Was it helpful?

Solution

Some hints:

  1. You should load CH with zero, not one, beause cylinders are numbered from zero.
  2. Upon failure an error code is returned in AH, have you looked at that?
  3. Booting from cd (iso as you say) complicates things, in particular check if you have floppy emulation enabled. Or just use a virtual floppy until you get things right.
  4. The BIOS usually passes the boot drive for you in DL so there should be no need to overwrite that.

Using floppy image and fixing point #1, it works for me with bochs and qemu (don't have virtualbox).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top