Page 1 of 1

Problems reading Floppy with int 13h

Posted: Thu Jun 12, 2003 11:00 pm
by hefe
With this (my) code i try to load the whole flopppy to 0x9000:0x0 (TEMP_SEG)
But it always fails at the same position.

Here is the the relevant code:

;Format   Size   Cyls(Tracks)   Heads  Sec/Trk
;1.44M    3 1/2     80            2      18
FLOPPY_TRACKS              equ  80
FLOPPY_SECTORS_PER_TRACK   equ  18
TEMP_SEG                   equ  0x9000

; reset FDC
xor  ah,ah
xor  dl,dl
int  0x13


start_sector     dw        2    
sectors_to_read  dw       17
track            dw        0
head             dw        0

mov ax,TEMP_SEG
mov es,ax


read_loop:
xor bx,bx

; Print a dot
mov  si,dot
call message

call read_track

; increment es
xor ax, ax
xor bx, bx
xor cx, cx
mov ax, [sectors_to_read]
mov cx, 0x20  ; sector size (512) / 10h (segment)
mul cx
mov bx, ax
mov ax, es
add ax, bx
mov es, ax

xor word [head], 0x0001
mov word [start_sector], 1
mov word [sectors_to_read], FLOPPY_SECTORS_PER_TRACK

cmp word [head], 0x0000
jne do_not_change_track
inc word [track]

do_not_change_track:

cmp word [track], 30  ; stop after 30 tracks...

jne read_loop


I debuggen the code with bochs's internal debugger.
this are the values of the registers just before the int 13h call that fails:

<bochs:98> info registers
eax            0x212            530
ecx            0x160701         1443585
edx            0x100            256
ebx            0x7              7
esp            0xfffc           0xfffc
ebp            0x0              0x0
esi            0x7c3e           31806
edi            0xffe4           65508
eip            0x7d2e           0x7d2e
eflags         0x246            582
cs             0x0              0
ss             0x9000           36864
ds             0x0              0
es             0xb1a0           45472
fs             0x0              0
gs             0x0              0

if i read the doku, everythink seems allright:

AH = 02h
AL = number of sectors to read (must be nonzero) => 0x12 == 18
CH = low eight bits of cylinder number => 0x7  ==  7
CL = sector number 1-63 (bits 0-5) => 0x1 ==  1
high two bits of cylinder (bits 6-7, hard disk only)
DH = head number => 0x1  ==  1
DL = drive number (bit 7 set for hard disk)         => 0x0  ==  0
ES:BX -> data buffer => 0xb1a0:0x7



And this is the errors bochs prints in the log:

00001012124i[FDD  ] read() on floppy image returns 0
00001012636i[FDD  ] read() on floppy image returns 0
00001030501i[CPU  ] BxError: instruction with op1=0xff
00001030501i[CPU  ] nnn was 7
00001030501i[CPU  ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001030502i[CPU  ] BxError: instruction with op1=0xff
00001030502i[CPU  ] nnn was 7
00001030502i[CPU  ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001030503i[CPU  ] BxError: instruction with op1=0xff
00001030503i[CPU  ] nnn was 7
00001030503i[CPU  ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001030504i[CPU  ] BxError: instruction with op1=0xff
00001030504i[CPU  ] nnn was 7
00001030504i[CPU  ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001030505i[CPU  ] BxError: instruction with op1=0xff
00001030505i[CPU  ] nnn was 7
00001030505i[CPU  ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001030506i[CPU  ] BxError: instruction with op1=0xff
00001030506i[CPU  ] nnn was 7
00001030506i[CPU  ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001030507i[CPU  ] BxError: instruction with op1=0xff
00001030507i[CPU  ] nnn was 7
00001030507i[CPU  ] WARNING: Encountered an unknown instruction (signalling illegal instruction):
00001030508i[CPU  ] BxError: instruction with op1=0xff
00001030508i[CPU  ] nnn was 7


I hope someone can help me, I have stopped os developement 2 years ago because i didn't get this problem solved.

sorry for my bad english & kind regards
hefe

ops..

Posted: Thu Jun 12, 2003 11:00 pm
by hefe
here is the read_track function i forgot to post:

read_track:     mov cl, [start_sector]
                mov ch, [track]
                mov dl, 0x00
                mov dh, [head]
                mov ah, 0x02
                mov al, [sectors_to_read]
                int 0x13
                ret


im running in real mode, and its a bootsector, thats wy i start on sector 2 on the first read

RE:ops..

Posted: Fri Jun 13, 2003 11:00 pm
by hefe
i just solved the problem

thanks anyway

RE:ops..

Posted: Fri Jun 20, 2003 11:00 pm
by Astor
I have just a doubt. How did you do to load an entire floppy (1.44 MB) en real mode if you are not be able to write over 1 Mb ?

RE:ops..

Posted: Sat Jun 21, 2003 11:00 pm
by hefe
well, it are 500KB now :)

RE:ops..

Posted: Thu Jun 26, 2003 11:00 pm
by Khumba
You have to enable flat/unreal mode.  You enable the A20 line, switch to protected mode, make a 4GB segment, then switch back to real mode. (The segment stays)