Page 1 of 1

ata

Posted: Fri Oct 31, 2008 7:50 am
by mobruan
I write the following code to read two sectors from the hd:

mov dx, 0x172
mov al, 2
out dx, al

mov dx, 0x173
mov al, 0
out dx, al

mov dx, 0x174
mov al, 0
out dx, al

mov dx, 0x175
mov al, 0
out dx, al

mov dx, 0x176
mov al, 00000000b
out dx, al

mov dx, 0x177
mov al, 0x20
out dx, al

Bochs give me the folowing message:
ata1-0: read sectors issued to non-disk

is this correct, i did read the sectors or not?

Re: ata

Posted: Fri Oct 31, 2008 8:43 am
by posman
IIRC, 0x170-0x177 are for 2nd fixed disk controller, Am I right?

Why don't you use 0x1F0-0x1F7?
mobruan wrote: mov dx, 0x173
mov al, 0
out dx, al
In CHS, Shouldn't sectors start with sector 1?
mobruan wrote: mov dx, 0x176
mov al, 00000000b
out dx, al
I think bits 7 and 5 should be 1

Re: ata

Posted: Fri Oct 31, 2008 11:26 am
by kmtdk
well
have you read the wiki ? (http://wiki.osdev.org/ATA_PIO_Mode)
and by the way, you have to know the "drive" number ( i have done some reserch ( played with a real computer), and if the hdd is primary, it is 0, if there is 2 hdds, then the slave is 1. and if there is only 1, but set as slave, it is 1)
3:
here is a example code for reading the first sector ( to read the secound, just increase the "sector count" to 2, and the "mov cx,.../ 2 " to "mov cx, " as this would duble the data amout.

Code: Select all

read.harddisk:
   xor ax,ax
   mov ds,ax
   mov     dx,0x1f6         ;Drive and head port
   mov al,[drive]         ;Drive 0, head 0
   out     dx,al 

   mov     dx,0x1f2         ;Sector count port
   mov     al,1           ;Read one sector
   out     dx,al 

   mov     dx,0x1f3         ;Sector number port
   mov     al,1            ;Read sector one 
   out     dx,al 

   mov     dx,0x1f4         ;Cylinder low port
   mov     al,0            ;Cylinder 0 
   out     dx,al 

   mov     dx,0x1f5         ;Cylinder high port
   mov     al,0            ;The rest of the cylinder 0 
   out     dx,al 

   mov     dx,0x1f7         ;Command port
   mov     al,0x20          ;Read with retry.
   out     dx,al 
still_going: 
   in      al,dx 
   test    al,0x8            ;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,0x2000
   mov ax,0x0000
   mov es,ax
   mov     dx,0x1f0        ;Data port - data comes in and out of here.
   rep     insw                                                        

hope it helps ....

KMT dk

Re: ata

Posted: Fri Oct 31, 2008 12:58 pm
by mobruan
thanks!
but ata dont use LBA addressing?

Re: ata

Posted: Fri Oct 31, 2008 6:33 pm
by bewing
Yes, but you have to set the correct bits in the LBA/drive/Head IO Port (0x176 in your example -- which IS the second ATA bus, as said above).