ATA PIO Mode: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
No edit summary
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(4 intermediate revisions by 2 users not shown)
Line 1:
According to the ATA specs, PIO mode must always be supported by all ATA-compliant drives as the default data transfer mechanism.
 
PIO mode uses a tremendous amount of CPU resources, because every byte of data transferred between the disk and the CPU must be sent through the CPU's [[Inline Assembly/Examples#I\O access|IO port bus]] (not the memory). On some CPUs, PIO mode can still achieve actual transfer speeds of 16MB per sec, but no other processes on the machine will get any CPU time.
 
However, when a computer is just beginning to boot, there are no other processes. So PIO mode is an excellent and simple interface to utilize during bootup, until the system goes into multitasking mode.
 
Please note that this article deals with what are now styled PATA hard disks, as opposed to SATA hard disks.
 
 
Line 18 ⟶ 20:
==Master/Slave Drives==
 
There is only one wire dedicated to selecting which drive on each bus is active. It is either electrically "high" or "low", which means that there can never be more than two devices operational on any ATA bus. They are called the master and the slave devices, for no particular reason. TheirThe terms 'master' and 'slave' have largely been abandoned as they inaccurately portray the master drive as having some kind of superiority over the slave drive, or that the latter is dependent on the master. However, these terms will be used in this document. The functionality of the master and slave drives is almost completely identical. There is a special IO port bit that allows a driver to select either drive as the target drive for each command byte.
 
 
 
==Primary/Secondary Bus==
 
Current disk controller chips almost always support two ATA buses per chip. There is a standardized set of IO ports to control the disks on the buses. The first two buses are called the Primary and Secondary ATA bus, and are almost always controlled by IO ports 0x1F0 through 0x1F7, and 0x170 through 0x177, respectively (unless you change it). The associated Device Control Registers/Alternate Status ports are IO ports 0x3F6, and 0x376, respectively. The standard IRQ for the Primary bus is IRQ14, and IRQ15 for the Secondary bus.
 
If the next two buses exist, they are normally controlled by IO ports 0x1E8 through 0x1EF, and 0x168 through 0x16F, respectively. The associated Device Control Registers/Alternate Status ports are IO ports 0x3E6, and 0x366.
Line 601:
(Using a Software Reset -- adapted from PypeClicker)
 
<sourcesyntaxhighlight lang="c">
/* on Primary bus: ctrl->base =0x1F0, ctrl->dev_ctl =0x3F6. REG_CYL_LO=4, REG_CYL_HI=5, REG_DEVSEL=6 */
int detect_devtype (int slavebit, struct DEVICE *ctrl)
Line 621:
return ATADEV_UNKNOWN;
}
</syntaxhighlight>
</source>
 
 
Line 629:
(Note: the following routines should all include some form of OS-specific timeout.)
 
<sourcesyntaxhighlight lang="asm">
; do a singletasking PIO ATA read
; inputs: ebx = # of sectors to read, edi -> dest buffer, esi -> driverdata struct, ebp = 4b LBA
Line 906:
pop eax
ret
</syntaxhighlight>
</source>
 
 
Line 931:
* http://www.ata-atapi.com -- Public Domain C driver sourcecode, including SATA, Busmatering DMA, ATAPI -- not perfect, but good.
* [http://hddguru.com/content/en/documentation/ HDD Guru] -- The actual ATA specs from the first one that was released in 1994 to the 8th one in 2006.
* An exmapleexample of [http://msdn.microsoft.com/en-us/library/windows/hardware/ff559006(v=vs.85).aspx the structure of the data returned by the IDENTIFY Command] (in case you wanted to know what most of the fields were for).
* [http://www.fysnet.net/media_storage_devices.htm A book] written by somebody on the forum about ATA and SATA.
* [https://github.com/omarrx024/xos/blob/master/kernel/blkdev/ata.asm ATA PIO driver in assembly.]