Monday, January 9, 2012

Reading ATA device sector

I should write to read ATA device sector.
  1. First, We will wait until the port 0x03f6 is zero using device selection protocol.
  2. Second, Next, We will set device number to port 0x01f6(device/head register).
  3. Next, We will set 0x02 to port 0x03f6(device control register) and set 0x00 to port 0x01f1(features register).
  4. Then, We will prepare for reading sector.Details below.
  5. out8(0x01f2, 1); // Set read count.
    out8(0x01f3, sector & 0xff); // Set sector number to register.
    out8(0x01f4, (sector >> 8) & 0xff); // Set cylinder low to register.
    out8(0x01f5, (sector >> 16) & 0xff); // Set cylinder High to register.
    out8(0x01f6, ((sector >> 24) & 0x0f) | 0x40); // Set Head number to register.
  6. Finally, We will read sector data by setting 0x20 to port 0x01f7.
    1. out8(0x01f7, 0x20); // read data.
for(i = 0; i < SECTOR_SIZE; i++) {
  buf[i] = inw(0x01f0);

Thank you.

No comments:

Post a Comment