ATA Port Map
When programming directly to a hard disk, a full understanding of the interface between the hard disk and the computer is required.
ATA Port Map and Descriptions
A hard disk that complies with ATA/ATAPI standards will have 9 user accessible registers. For arguments sake we will number these P00 - P08, the function of each register is described below, note that some registers have a different name and purposes depending whether the register is being written to or when it's contents are being read by the computer. Also, the ports may contain different or Missing information when DATA and NONDATA commands are sent. For example, when sending an IDENTIFY_DEVICE (ECh) only the command register needs to be set. Note also that once the command register has been written to, the drive will execute the command immediately. So the correct procedure is;
- Wait for the drive to enter 'READY' state - Status Register = 50h
- Set Registers P00-P06 with the correct vales
- Set the command register P07 with the command code
- Wait for the drive to set DRQ state - This means that data is ready in the buffer
- Read the buffer
- -> step 4
- Process finished
If an error condition is encountered, bit 1 of the status register is set. More information about the error can be found by querying the ERROR register. set the other registers with the correct data, with the command register being set last. The drive will then run the command and return the information to it's buffer ready to be read 2 bytes at a time at P00.
Hard Disks Port Registers
Port list and description of functions.
| Function | ||||
| Port | Size | Read Mode | Write Mode | |
| P00 | 16 bit | Read Data | Data to Write | |
| P01 | 8 bit | Error Register | Feature Register | |
| P02 | 8 bit | Sector Count Register | Sector Count Register | |
| P03 | 8 bit | LBA Low register | LBA Low Register | |
| P04 | 8 bit | LBA Middle Register | LBA Middle Register | |
| P05 | 8 bit | LBA High Register | LBA High Register | |
| P06 | 8 bit | Drive and Head register | Drive and Head Register | |
| P07 | 8 bit | Status Register | Command register | |
| P08 | 8 bit | Alt Status Register | Device Control Register | |
Status register Flags
When reading the status register, it shows the current status of the drive. The status register is 8 bit and each bit is described below
- BSY (busy) - Self explanatory - The drive is 'busy' with the previous command.
- DRDY (device ready) - The drive is ready for the next command as long as DSC is set
- DF (Device Fault) - The hard disk has developed a fault that prevents it from completing the command.
- DSC (seek complete) - The last seek command has completed successfully.
- DRQ (Data Transfer Requested) - Data is in the drive's buffer memory waiting to be read.
- CORR - This bit is obsolete
- IDX - This bit is obsolete)
- ERR (error) - There was an error processing the last command (see below)
For example if the status register reads 80 (50h) this is 01010000 in binary which shows DRDY and DSC flags as set - the drive is ready for the next command.
Error register Flags
When an error occurs, it is best to read the ALT_STATUS register, if the value is not even then an Error Event has occurred. The exact code can be read from the ERROR_REGISTER. The register is 8 bit and each bit is described below. the value returned when the bit in the error register is set.
- BBK - Bad block mark - A bad block mark was detected ID field for the sector being read.
- UNC - Uncorrectable Error - An error encountered that could not be corrected
- MC - Media Changed (Not used for Fixed Hard Disk Drives)
- IDNF ID mark Not Found - The ID field for the sector could not be found.
- MCR Media Change Requested (Not used for Fixed Hard Disk Drives)
- ABRT (command aborted or not recognised) - The last command was aborted because of a drive status error or the last command was not recognised.
- TNF (Track 0 Not Found) Track 0 was not found during a Recalibrate command.
- AMNF (Address Mark Not Found) The data address mark was not found after finding the correct ID field
e.g. If error register reads 04h this is 00000100 binary indicating the ABRT flag set - the drive did not recognise the last command or an error occurred whilst processing it.
For drives that support the CFA command set, it is possible to get precise information about the error using the CFA REQUEST EXTENDED ERROR CODE.
Free diagnosis, no data recovery, no fee
All data recovery work undertaken by MjM is under a Free diagnosis and a no recovery no-fee policy. If we can't recover your data, then there is no fee for you to pay.
If you have lost data or your drive has stopped working contact us now.

