ports - harddisk
Posted: Mon Sep 02, 2002 11:00 pm
I'm having some troubles reading sector 0 - head 0 - cylinder 1....
it outputs the wrong data....
but it does output the right data if I read sector 63 - head 0 - cylinder 0 before I read sector 0 - head 0 - cylinder 1...
(yes, it is on the disk in case you're wondering (I used dd for that), used the mbr for booting (windows-way))
So why doesn't it just read it inmidiatly?
reading a sector on cylinder 0, head 0, sec <63 works inmidiatly.
But reading sec 1 - cylinder 0 - head 0 doesn't..
any ideas why?
Here's the code:
code:
--------------------
bits 32
jmp s
err: mov ebx,0xb8000
mov byte[es:ebx],'E'
inc ebx
mov byte[es:ebx],0x1F
jmp hang
;===============================================
; read
;===============================================
s:
mov dx,0x1f6
mov ax,176 ; head+drive, second drive
out dx,ax
mov dx,0x1f2
mov ax,1 ; 1 sector
out dx,ax
mov dx,0x1f3
mov ax,0 ; sector 0
out dx,ax
mov dx,0x1f4
mov ax,1 ; cylinder 1
out dx,ax
mov dx,0x1f5
mov ax,0 ; high cylinder = 0
out dx,ax
mov dx,0x1f7
mov ax,0x20 ; read with retry :]
out dx,ax
f: in al,dx
or al,1 ; error?
je err
test al,8 ; are we still busy?
jz f
mov cx,0
mov ebx,0xB8000
jmp re
re: mov dx,0x1f0
in ax,dx
mov dl,al
mov dh,ah
mov byte[es:ebx],dl
inc ebx
mov byte[es:ebx],0x1F
inc ebx
mov byte[es:ebx],dh
inc ebx
mov byte[es:ebx],0x1F
inc ebx
inc cx
cmp cx,512
jne re
jmp hang
hang: jmp hang ; hang
---------------------------------
it outputs the wrong data....
but it does output the right data if I read sector 63 - head 0 - cylinder 0 before I read sector 0 - head 0 - cylinder 1...
(yes, it is on the disk in case you're wondering (I used dd for that), used the mbr for booting (windows-way))
So why doesn't it just read it inmidiatly?
reading a sector on cylinder 0, head 0, sec <63 works inmidiatly.
But reading sec 1 - cylinder 0 - head 0 doesn't..
any ideas why?
Here's the code:
code:
--------------------
bits 32
jmp s
err: mov ebx,0xb8000
mov byte[es:ebx],'E'
inc ebx
mov byte[es:ebx],0x1F
jmp hang
;===============================================
; read
;===============================================
s:
mov dx,0x1f6
mov ax,176 ; head+drive, second drive
out dx,ax
mov dx,0x1f2
mov ax,1 ; 1 sector
out dx,ax
mov dx,0x1f3
mov ax,0 ; sector 0
out dx,ax
mov dx,0x1f4
mov ax,1 ; cylinder 1
out dx,ax
mov dx,0x1f5
mov ax,0 ; high cylinder = 0
out dx,ax
mov dx,0x1f7
mov ax,0x20 ; read with retry :]
out dx,ax
f: in al,dx
or al,1 ; error?
je err
test al,8 ; are we still busy?
jz f
mov cx,0
mov ebx,0xB8000
jmp re
re: mov dx,0x1f0
in ax,dx
mov dl,al
mov dh,ah
mov byte[es:ebx],dl
inc ebx
mov byte[es:ebx],0x1F
inc ebx
mov byte[es:ebx],dh
inc ebx
mov byte[es:ebx],0x1F
inc ebx
inc cx
cmp cx,512
jne re
jmp hang
hang: jmp hang ; hang
---------------------------------