basic hdd read question
Posted: Tue Aug 29, 2006 3:07 am
i feel like i must be retarded :] i couldn't get my floppy driver working, so i thought i should start on hdd and just take a break from the fd. guess what? i feel worse off than i was with the fd. i can't find much material. i checked bonafide and mega-tokyo and didn't see anything. i checked osrc and one of the links i found was to this code:
(the full code is at http://www.nondot.org/sabre/os/files/Disk/HD_PORTS.asm, but i think this covers it)
so, i ported it to C just to see if it worked, and was really happy when i saw that the serial window said, "HDD read test success." turns out that was a stupid programming mistake, and it actually didn't work. what i got was 512 'FF's... if you know what i mean ;] ;]
i'm very tired right now, so if anyone could tell me why the above code does not work for a read of sector 0, i'd be very thankful.
oh, ps, i DIDN'T port over the stuff about using the bios to read and compare. i think the author was just using it to verify successful completion bla bla bla and i doubt it was important seeings how the purpose of code is to read with the ports. my success check was if the first 16 bytes on the read were 0-15 (first thing i thought of to put in the disk image :])
(the full code is at http://www.nondot.org/sabre/os/files/Disk/HD_PORTS.asm, but i think this covers it)
Code: Select all
mov dx,1f6h ;Drive and head port
mov al,0a0h ;Drive 0, head 0
out dx,al
mov dx,1f2h ;Sector count port
mov al,1 ;Read one sector
out dx,al
mov dx,1f3h ;Sector number port
mov al,1 ;Read sector one
out dx,al
mov dx,1f4h ;Cylinder low port
mov al,0 ;Cylinder 0
out dx,al
mov dx,1f5h ;Cylinder high port
mov al,0 ;The rest of the cylinder 0
out dx,al
mov dx,1f7h ;Command port
mov al,20h ;Read with retry.
out dx,al
still_going:
in al,dx
test al,8 ;This means the sector buffer requires
;servicing.
jz still_going ;Don't continue until the sector buffer
;is ready.
mov cx,512/2 ;One sector /2
mov di,offset buffer
mov dx,1f0h ;Data port - data comes in and out of here.
rep insw
; ------
mov ax,201h ;Read using int13h then compare buffers.
mov dx,80h
mov cx,1
mov bx,offset buffer2
int 13h
mov cx,512
mov si,offset buffer
mov di,offset buffer2
repe cmpsb
jne failure
mov ah,9
mov dx,offset readmsg
int 21h
jmp good_exit
failure:
mov ah,9
mov dx,offset failmsg
int 21h
good_exit:
mov ax,4c00h ;Exit the program
int 21h
readmsg db 'The buffers match. Hard disk read using ports.$'
failmsg db 'The buffers do not match.$'
i'm very tired right now, so if anyone could tell me why the above code does not work for a read of sector 0, i'd be very thankful.
oh, ps, i DIDN'T port over the stuff about using the bios to read and compare. i think the author was just using it to verify successful completion bla bla bla and i doubt it was important seeings how the purpose of code is to read with the ports. my success check was if the first 16 bytes on the read were 0-15 (first thing i thought of to put in the disk image :])