ATA PIO? [solved, sort of]

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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

ATA PIO? [solved, sort of]

Post by pcmattman »

I looked at the LBA addressing/reading/writing tutorial at osedver.net and implemented it into my kernel. The only problem is, it doesn't write anything, or read. My main question is, what does it mean when I need to say what drive to read? Is that 0xA0/0xB0 or is it an actual drive indicator that I need to ask the hardware for?

Edit: never mind, I figured it out... My only question now is, why can't I write to a sparse image in Bochs and then view it in a hex-editor to test my read/write functions? I currently have to use a flat image and it's taking up 10 gig on my hard drive. Either I'll have to format my linux partition (which is almost dead anyway) or I'll have to somehow get sparse images working.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Post by ~ »

You need to know what addressing is Bochs using for reading/writing: CHS, ATA28 or ATA48. I have a 20Mb disk image or so, but it seems to be contained in some kind of file format, not in a raw binary file.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Ok... don't worry about the sparse/flat file, it's irrelevant. New question: how do I know whether or not I should use CHS or LBA on a disk?
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Post by ~ »

As far as I know, the IDENTIFY DEVICE command returns all we need to know from an ATA device, and we can see there if LBA48 is implemented. LBA28 is always implemented in the most recent versions of hard disks (I think to have seen LBA disks from 1997 that support LBA). I don't know if those LBA disks support CHS operations.

Generally, if you execute directly a command and it's not supported, it will return ABRT bit set and other related data and in that case either you can give up or try another function (for example, if LBA48 didn't work and returned ABRT, you may test LBA28 or CHS, and so on). You'll need the older ATA (1?), ATA-2, ATA-3, ATA-4, ATA-5... specifications to find out how to use CHS disks, if you are sure that your read/write routines are correct (test them on real hardware).

Maybe this Bochs documentation helps somehow to figure out the "translation mode" used to address the disk image:

http://bochs.sourceforge.net/doc/docbook/user/bios-tips.html
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Post by ces_mohab »

i use chs,lba28, using ports 01F0-01F7 or 0170-0178 for primary/secodary ide controller.
so my question is where are ports for 48bit lba?
To write an OS you need 2 minds one for coding and other for debugging.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Ok... ATM I'm using LBA28.

I got all my information over at www.osdever.net - the LBA tutorial.

Does the IDENTIFY DEVICE command let me find out how big the drive is?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

I looked into the specs and it does let me see how big it is, and more. New question relating to this: what do I need to send to the controller and what do I need to read?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Never mind, read the specs some more and found how :D.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Post by ~ »

ces_mohab wrote:i use chs,lba28, using ports 01F0-01F7 or 0170-0178 for primary/secodary ide controller.
so my question is where are ports for 48bit lba?
You just need to write the same address ports several times, I don't remember if you must start with Most Significant or Least Significant, I better find the time to make a small tutorial on IDE; it's fairly complex.

But you must note that you need a disk bigger than ~138Mb; I personally use a 200GB disk to test my LBA48 code, because virtually any smaller disk supports it, that's not necessary anyway for them.
Last edited by ~ on Sat Mar 31, 2007 11:27 pm, edited 2 times in total.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Post by ~ »

pcmattman wrote:I looked into the specs and it does let me see how big it is, and more. New question relating to this: what do I need to send to the controller and what do I need to read?
About what?
Read/Write commands?
IDENTIFY commands?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

~ wrote:
ces_mohab wrote:i use chs,lba28, using ports 01F0-01F7 or 0170-0178 for primary/secodary ide controller.
so my question is where are ports for 48bit lba?
You just need to write the same address ports several times, I don't remember if you must start with Most Significant or Least Significant, I better find the time to make a small tutorial on IDE; it's fairly complex.

But you must note that you need a disk bigger than ~138Mb; I personally use a 200GB disk to test my LBA48 code, because virtually any smaller disk supports it, that's not necessary anyway for them.
Try this tutorial, it teaches both LBA28 and LBA48 read/write via ports: LBA HDD Access via PIO
Post Reply