Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
774 views
in Technique[技术] by (71.8m points)

x86 - Cannot read disk sectors in assembly language

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...