coperating-systemdiskhard-driveata

What are the PATA/IDE status codes, and what do they mean?


I'm writing an OS for fun and I'm trying to write a PATA/IDE driver to access the disk, however it is not working. I have this line unsigned char status = port_byte_in(ATAPort + COMMANDPORT); which returns the value of 88 (decimal). As this might be an indication of what I've done wrong, and as a referance for others, what are the PATA/IDE status codes?

My driver follows the 28 bit PIO PATA/IDE process.

EDIT - to clarify, here's the port_byte_in function:

unsigned char port_byte_in(unsigned short port) {
    unsigned char result;
    __asm__("in %%dx, %%al" : "=a" (result) : "d" (port));
    return result;
}

And ATAPort is 0x1F0, COMMANDPORT = 0x07


Solution

  • Before you consider writing a device driver for any kind of device you need to find/download and read all relevant specs for that device (you shouldn't rely on partial scraps of heresy from strangers).

    Most of the relevant specs are ANSI standards created by a T13 working group; and a list of them can be found here: http://www.t13.org/Standards/Default.aspx?DocumentType=3

    Unfortunately they are not free (you're supposed to pay ANSI for copies because unpaid hobbyist programmers working on stuff that is no longer commercially relevant get treated the same as companies that manufacture hardware for profit (!) ). Fortunately a web search (searching for the title of the document from the T13 list) will usually find draft versions that are almost the same as the final standards.

    There are many (eight?) version of the "AT Attachment" specs (plus other specs that you'll also need). The register you're talking about is the IDE/ATA controller's status register and is defined within these specs. Some of the definitions of the status register bits have changed (becoming "depends on command" or "obsolete") in different versions of the specs; and "depends on command" (for bit 4 of the status register) is what it sounds like - the meaning of that bit depends on what command you gave the controller last.