Data Recovery
Emergencies
0800 072 3282

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 to

  1. Wait for the drive to enter 'READY' state - Status Register = 80h
  2. Set Registers P00-P06 with the correct vales
  3. Set the command register with the command code
  4. Wait for the drive to enter DRQ - This means that data is ready in the buffer
  5. Read the buffer
  6. -> step 4
  7. 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
PortSizeRead ModeWrite Mode
P0016 bitRead DataData to Write
P018 bitError RegisterFeature Register
P028 bitSector Count RegisterSector Count Register
P038 bitLBA Low registerLBA Low Register
P048 bitLBA Middle RegisterLBA Middle Register
P058 bitLBA High RegisterLBA High Register
P068 bitDrive and Head registerDrive and Head Register
P078 bitStatus RegisterCommand register
P088 bitAlt Status RegisterDevice 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

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.

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.