INT13 makes me dizzy!
Posted: Tue Jul 09, 2002 8:45 am
Here's a part of my bootloader code (complete code can be found on clicker CVS. It works pretty fine on Intel motherboards (ranging from P1 to P3), but it only loads one sector every minute on AMD hardware ... If i remember well, each call to that function only ask for one single sector...
Does anyone have a clue about this ??
Thanks in advance ...
; Read a sector from the floppy drive.
;
; Parameters:
; - "logical" sector number [bp+8]
; - destination segment [bp+6]
; - destination offset [bp+4]
ReadSector:
push bp ; set up stack frame
mov bp, sp ; "
pusha ; save all registers
; Sector = log_sec % SECTORS_PER_TRACK
; Head = (log_sec / SECTORS_PER_TRACK) % HEADS
mov ax, [bp+8] ; get logical sector number from stack
xor dx, dx ; dx is high part of dividend (== 0)
mov bx, SECTORS_PER_TRACK ; divisor
div bx ; do the division
mov [cs:sec], dx ; sector is the remainder
and ax, 1 ; same as mod by HEADS==2 (slight hack)
mov [cs:head], ax
; Track = log_sec / (SECTORS_PER_TRACK*HEADS)
mov ax, [bp+8] ; get logical sector number again
xor dx, dx ; dx is high part of dividend
mov bx, SECTORS_PER_TRACK*2 ; divisor
div bx ; do the division
mov [cs:track], ax ; track is quotient
; Now, try to actually read the sector from the floppy,
; retrying up to 3 times.
mov [cs:num_retries], byte 0
.again:
mov ax, [bp+6] ; dest segment...
mov es, ax ; goes in es
mov ax, (0x02 << 8) | 1 ; function = 02h in ah,
; # secs = 1 in al
mov bx, [cs:track] ; track number...
mov ch, bl ; goes in ch
mov bx, [cs:sec] ; sector number...
mov cl, bl ; goes in cl...
inc cl ; but it must be 1-based, not 0-based
mov bx, [cs:head] ; head number...
mov dh, bl ; goes in dh
xor dl, dl ; hard code drive=0
mov bx, [bp+4] ; offset goes in bx
; (es:bx points to buffer)
; Call the BIOS Read Diskette Sectors service
int 0x13
; If the carry flag is NOT set, then there was no error
; and we're done.
jnc .done
; Error - code stored in ah
mov dx, ax
call PrintHex
inc byte [cs:num_retries]
cmp byte [cs:num_retries], 3
jne .again
; If we got here, we failed thrice, so we give up
mov dx, 0xdead
call PrintHex
.here: jmp .here
.done:
popa ; restore all regisiters
pop bp ; leave stack frame
ret
Does anyone have a clue about this ??
Thanks in advance ...
; Read a sector from the floppy drive.
;
; Parameters:
; - "logical" sector number [bp+8]
; - destination segment [bp+6]
; - destination offset [bp+4]
ReadSector:
push bp ; set up stack frame
mov bp, sp ; "
pusha ; save all registers
; Sector = log_sec % SECTORS_PER_TRACK
; Head = (log_sec / SECTORS_PER_TRACK) % HEADS
mov ax, [bp+8] ; get logical sector number from stack
xor dx, dx ; dx is high part of dividend (== 0)
mov bx, SECTORS_PER_TRACK ; divisor
div bx ; do the division
mov [cs:sec], dx ; sector is the remainder
and ax, 1 ; same as mod by HEADS==2 (slight hack)
mov [cs:head], ax
; Track = log_sec / (SECTORS_PER_TRACK*HEADS)
mov ax, [bp+8] ; get logical sector number again
xor dx, dx ; dx is high part of dividend
mov bx, SECTORS_PER_TRACK*2 ; divisor
div bx ; do the division
mov [cs:track], ax ; track is quotient
; Now, try to actually read the sector from the floppy,
; retrying up to 3 times.
mov [cs:num_retries], byte 0
.again:
mov ax, [bp+6] ; dest segment...
mov es, ax ; goes in es
mov ax, (0x02 << 8) | 1 ; function = 02h in ah,
; # secs = 1 in al
mov bx, [cs:track] ; track number...
mov ch, bl ; goes in ch
mov bx, [cs:sec] ; sector number...
mov cl, bl ; goes in cl...
inc cl ; but it must be 1-based, not 0-based
mov bx, [cs:head] ; head number...
mov dh, bl ; goes in dh
xor dl, dl ; hard code drive=0
mov bx, [bp+4] ; offset goes in bx
; (es:bx points to buffer)
; Call the BIOS Read Diskette Sectors service
int 0x13
; If the carry flag is NOT set, then there was no error
; and we're done.
jnc .done
; Error - code stored in ah
mov dx, ax
call PrintHex
inc byte [cs:num_retries]
cmp byte [cs:num_retries], 3
jne .again
; If we got here, we failed thrice, so we give up
mov dx, 0xdead
call PrintHex
.here: jmp .here
.done:
popa ; restore all regisiters
pop bp ; leave stack frame
ret