ata

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

ata

Post 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?
posman
Posts: 19
Joined: Fri Sep 05, 2008 12:55 pm

Re: ata

Post 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
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: ata

Post 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
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
mobruan
Member
Member
Posts: 71
Joined: Thu Oct 09, 2008 8:25 am
Location: Rio de Janeiro - Brazil

Re: ata

Post by mobruan »

thanks!
but ata dont use LBA addressing?
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: ata

Post 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).
Post Reply