ATA PIO Mode: Difference between revisions

m
Turned 2 bullets into subcategories
[unchecked revision][unchecked revision]
m (Fixed a tiny error)
m (Turned 2 bullets into subcategories)
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 [[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.
Line 87:
===Absolute/Relative LBA===
 
All the ATA commands that use LBA addressing require "absolute" LBAs (ie. the sector offset from the very beginning of the disk -- completely ignoring [[Partition Table|partition]] boundaries). At first glance, it might seem most efficient to store the LBA values in this same format in your OS. However, this is not the case. It is always necessary to validate the LBAs that are passed into your driver, as truly belonging to the partition that is being accessed. It ends up being smartest to use partition-relative LBA addressing in your code, because you then never need to test if the LBA being accessed is "off the front" of your current partition. So you only need to do half as many tests. This makes up for the fact that you need to add the absolute LBA of the beginning of the current partition to every "relative" LBA value passed to the driver. At the same time, doing this can give you access to one additional LBA address bit. (See the [[#ATA Driver|"33 bit LBA" driver]] code below.)
 
===Registers===
Line 260:
==x86 Code Examples==
 
* ===Detecting device types with a Software Reset (adapted from PypeClicker):===
(Using a Software Reset -- adapted from PypeClicker)
<pre>
/* on Primary bus: ctrl->base =0x1F0, ctrl->dev_ctl =0x3F6. REG_CYL_LO=4, REG_CYL_HI=5, REG_DEVSEL=6 */
Line 284 ⟶ 285:
 
 
===ATA Driver===
* A complete singletasking (polling) PIO mode driver for reading a hard disk
(Note: the following routines should all include some form of OS-specific timeout.)
 
<pre>
 
; do a singletasking PIO ATA read
; inputs: ebx = # of sectors to read, edi -> dest buffer, esi -> driverdata struct, ebp = 4b LBA
Anonymous user