ATA PIO Mode: Difference between revisions

Jump to navigation Jump to search
1,461 bytes added ,  16 years ago
Added 2 more sections
[unchecked revision][unchecked revision]
m (Turned 2 bullets into subcategories)
(Added 2 more sections)
Line 36:
 
There is a similar problem after writing the Command Register, with the ERR/DF bits. They are two slightly different kinds of errors, that can terminate a command. BSY and DRQ will be cleared, but ERR or DF remain set <i>until just after you write a new command to the Command Register</i>. If you are using polling (see below), you should account for the fact that your first four reads of the Status Register, after sending your command byte, may have the ERR or DF bits still set accidentally. (If you are using IRQs, the Status will always be correct by the time the IRQ is serviced.)
 
==Cache Flush==
 
On some drives it is necessary to "manually" flush the hardware write cache after every write command. This is done by sending the 0xE7 command to the Command Register (then waiting for BSY to clear). If a driver does not do this, then subsequent write commands can fail invisibly, or "temporary bad sectors" can be created on your disk.
 
==Bad Sectors==
 
For practical purposes, there are three different types of bad sectors on an ATA disk.
* Sectors that can't be written (permanent)
* Sectors that can't be read (permanent)
* Sectors that can't be read (temporary)
 
Some disk manufacturers have a feature that allows a small supply of "spare" sectors on the disk to be remapped onto permanent bad sectors. However, that feature is non-standard and completely manufacturer-specific. In general, an OS/filesystem will need to keep a "bad sector list" for each partition of each drive, and work around the bad sectors.
 
As said above, there are also "temporary bad sectors". When you read them you will get a hardware error, just like for a permanently bad sector. If you write to that sector, however, the write will work perfectly and the sector will turn back into a good sector. Temporary bad sectors can happen as a result of unflushed write caches, power spikes, or power failures.
 
==Detection and Initialization==
Line 204 ⟶ 219:
 
===Writing 28 bit LBA===
To write sectors in 28 bit PIO mode, send command "WRITE SECTORS" (0x30) to the Command port. Do <b>not</b> use <b>REP</b> OUTSW to transfer data. There must be a tiny delay between each OUTSW output word. A jmp $+2 size of delay. Make sure to do a Cache Flush (ATA command 0xE7) after each write command completes.
 
===48 bit PIO===
Line 226 ⟶ 241:
# Send the "READ SECTORS EXT" command (0x24) to port 0x1F7: outb(0x1F7, 0x24)
 
To write sectors in 48 bit PIO mode, send command "WRITE SECTORS EXT" (0x34), instead. (As before, do not use REP OUTSW when writing.) And remember to do a Cache Flush after each write command completes.
 
After the command byte is sent, transfer each sector of data in exactly the same way as for a 28 bit PIO Read/Write command.
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu