Page 1 of 1

LBA28 Disk Driver

Posted: Wed May 16, 2007 4:53 am
by XCHG
Maybe it's just me or is someone else in here really wondering where these magic values for LBA28 hard disk driver coming from? I read the so-called tutorial in http://osdever.net/ and it is not helpful for me. I was wondering if anybody had the specification for LBA28 and could hook me up with it because I've been searching in Google and I haven't yet been able to find any good documentation(s).

I'd appreciate your help.

Posted: Wed May 16, 2007 5:08 am
by Brynet-Inc
I'm only guessing, but wouldn't it be documented in the ATA specification?

According to the Wikipedia article:
Wikpedia wrote:The original ATA specification used a 28-bit addressing mode. This allowed for the addressing of 228 (268,435,456) sectors (with blocks of 512 bytes each), resulting in a maximum capacity of 137 gigabytes (128 GiB)
So if this is referring to LBA28, Isn't it safe to assume it's documented in the original standard.. (Or at least ATA-2?..)
Wikipedia wrote:ATA-6 introduced 48 bit addressing, increasing the limit to 128 PiB (or 144 petabytes).
This in my opinion would mean that LBA48 was first documented in the ATA-6 specification..

If I'm not mistaken, The below provides links to past and present ATA standards :)
http://en.wikipedia.org/wiki/Advanced_T ... d_features

I hope this helped some..

Re: LBA28 Disk Driver

Posted: Wed May 16, 2007 3:25 pm
by mathematician
XCHG wrote:Maybe it's just me or is someone else in here really wondering where these magic values for LBA28 hard disk driver coming from? I read the so-called tutorial in http://osdever.net/ and it is not helpful for me. I was wondering if anybody had the specification for LBA28 and could hook me up with it because I've been searching in Google and I haven't yet been able to find any good documentation(s).

I'd appreciate your help.
Bit assignments for the device register (0x1F6)

Bit 7 Obsolete in LBA mode, should be set to 1 in CHS mode
Bit 6 Sets LBA/CHS mode. 1=LBA, 0=CHS
Bit 5 As bit 7
Bit 4 1=Slave drive, 0=Master drive
Bit 3-0 In LBA mode, bits 27-24 of address. In CHS mode, head number

You may be sorry that you asked, but you can find all the documentation your heart could possibly wish for at www.t13.org

Posted: Fri May 18, 2007 12:36 am
by XCHG
10/4. I appreciate your help. Thank you. Over and out.

Posted: Fri May 18, 2007 5:16 am
by XCHG
Alright. I download the specifications for ATA-1. I read them and actually worked some of the commands out. The problem is that these specifications/manuals are not having programmers as their audience specifically so I am having trouble understanding some of the points. I was wondering if anybody knew of place that has a nice tutorial for HDD access.

Thank you guys.

Posted: Fri May 18, 2007 4:37 pm
by pcmattman
You're not going to believe this, but ATA is possibly one of the easiest things to code! If you're happy using ports, it works pretty much out of the box. Of course, once you need some speed ports become a bottleneck, and you can use DMA.

Head on over to osdever.net and find the LBA HDD tutorial. It outlines how to read/write hard drives using LBA (28 and 48). You could also look at my code in my CVS (ata_pio.cc) which is heavily commented... but only supports LBA28. I'm going to change that soon.

If you know how to use DMA (which I don't, always confuses me :shock: ) then I'd recommend using it.

Hint: if you read the ATA docs as a reference it's much easier. For instance, if you want to know the code for IDENTIFY DEVICE and what it returns you just look up IDENTIFY DEVICE and interpret that information.

Posted: Sun May 20, 2007 3:22 am
by XCHG
pcmattman,

Unfortunately, I don't like copying people's codes. I have coded my entire kernel myself and if I am given time, I can rebuild and recode it without any need for anybody else's code. I have looked at the tutorial on OSDev and after the first look I had at it, I realized that it was more like "do this and do that" kind of article than "why you should do this and why you should do that". I don't like magic words as the tutorial calls them and when I turned to the specifications they somehow confused me a little.

It could be nice to have a tutorial that walks you through different steps of working with HDDs. I would be thankful beyond words to have a look at such tutorial if you know about one. Thank again for your reply.

Posted: Sun May 20, 2007 3:35 am
by pcmattman
There are two tutorials I want to write: one is for hard drive access. The other is for multitasking, but I don't want to do that one until I get virtual mode tasks working.

At some point in time, you're going to have to look at code and copy parts of it. We all do it, if you don't you're just reinventing the wheel. I'd recommend going over the tutorial again with the ATA specs at hand, and then figuring out the commands.

For instance, the tutorial uses the command 0x20, "Read Sector(s)". Look that up in the ATA specs, and then match up what the tutorial outputs to each port and match that with the specs. It's really not that hard, and if you write some #defines at the top you can address register offsets by name (ATA_FEATURES, ATA_COMMAND etc).

By the way, the 'magic bits' he references are part of this register:

Code: Select all

Device/Head: obs | LBA | obs | DEV | Head number or LBA
The reasons he does all that shifting:
Sector Number -
starting sector number or LBA address bits (7:0).

Cylinder Low -
starting cylinder number bits (7:0) or LBA address bits (15:8).

Cylinder High -
starting cylinder number bits (15:8) or LBA address bits (23:16).

Device/Head -
bit 6 set to one if LBA address, cleared to zero if CHS address.
DEV shall indicate the selected device.
bits (3:0) starting head number or LBA address bits (27:24).
You're using LBA28, so your address (ie. sector number) must be put in there somewhere.

You've got to read the specs - all the above comes from nowhere but the specs. I wrote my ATA driver off the specs, and that tutorial.

Good luck!