disk Read Error with PIO method
Posted: Sun Mar 03, 2019 12:19 pm
Hi, I am currently trying to make my OS read disk sectors from the boot drive with I/O ports method. However there is something blocking me when running the Identify command.
As said, after sending the identify command to port 0x1f7, I need to check ports 0x1f4 and 0x1f5 to see if they are still 0x00, if not then the drive is not ATA.
This works fine in Qemu (I am getting 0x00 on ports 0x1f4 and 0x1f5) and I am able to read disk sectors. However when I run my OS on a real machine this is what I get:
At first:
0x1f7: 0xd0
0x1f4: 0xd0
0x1f5: 0xd0
then after a slight delay (and forever):
0x1f7: 0x51
0x1f4: 0x14
0x1f5: 0xeb
I have non-zero values on ports 0x1f4 and 0x1f5, according to the wiki page that means that the disk is not ATA and that I should stop polling the 0x1f7 port. What does it actually mean that the drive is not ATA? What should I do next if I stop polling? What should I do to read disk sectors?
Note: After sending the identify command to port 0x1f7, I get interrupt 0x2e (irq 0x14).
Thanks in advance for your help, regards
(from: https://wiki.osdev.org/ATA_PIO_Mode#Det ... ialization)To use the IDENTIFY command, select a target drive by sending 0xA0 for the master drive, or 0xB0 for the slave, to the "drive select" IO port. On the Primary bus, this would be port 0x1F6. Then set the Sectorcount, LBAlo, LBAmid, and LBAhi IO ports to 0 (port 0x1F2 to 0x1F5). Then send the IDENTIFY command (0xEC) to the Command IO port (0x1F7). Then read the Status port (0x1F7) again. If the value read is 0, the drive does not exist. For any other value: poll the Status port (0x1F7) until bit 7 (BSY, value = 0x80) clears. Because of some ATAPI drives that do not follow spec, at this point you need to check the LBAmid and LBAhi ports (0x1F4 and 0x1F5) to see if they are non-zero. If so, the drive is not ATA, and you should stop polling. Otherwise, continue polling one of the Status ports until bit 3 (DRQ, value = sets, or until bit 0 (ERR, value = 1) sets.
As said, after sending the identify command to port 0x1f7, I need to check ports 0x1f4 and 0x1f5 to see if they are still 0x00, if not then the drive is not ATA.
This works fine in Qemu (I am getting 0x00 on ports 0x1f4 and 0x1f5) and I am able to read disk sectors. However when I run my OS on a real machine this is what I get:
At first:
0x1f7: 0xd0
0x1f4: 0xd0
0x1f5: 0xd0
then after a slight delay (and forever):
0x1f7: 0x51
0x1f4: 0x14
0x1f5: 0xeb
I have non-zero values on ports 0x1f4 and 0x1f5, according to the wiki page that means that the disk is not ATA and that I should stop polling the 0x1f7 port. What does it actually mean that the drive is not ATA? What should I do next if I stop polling? What should I do to read disk sectors?
Note: After sending the identify command to port 0x1f7, I get interrupt 0x2e (irq 0x14).
Thanks in advance for your help, regards