Hi,
Klakap wrote:
Code:
//wait
while (!(inb(0x1F7) & 0x08)) {}
Here you are waiting for the DRQ bit to become set. What if it never becomes set? You will wait here for a long time...
Klakap wrote:
Code:
for (uint8_t idx = 0; idx < 255; idx++)
{
if(type==ATA_READ) {
buffer[idx] = inw(base + ATA_PORT_DATA);
}
else {
tmpword=(unsigned short)buffer[idx];
outw(base + ATA_PORT_DATA, tmpword);
}
}
There are a lot of errors with that block of code. Is uint8_t an 8-bit unsigned byte? If so, idx will never get to the last word you want to write (or read). If you check for below 255, the last word is ignored. The controller will always wait for that last word to be read/written unless you issue another command or a reset. Changing to:
Code:
for (uint8_t idx = 0; idx < 256; idx++)
will cause a lot more problems than you think. Hint: it is okay to use machine-sized integers within 'for' loops, i.e.: the 'int' keyword.
Also, what type (and size) is buffer? If buffer is a 16-bit word sized, then your read is okay, and your write is okay too, but why the tmpword? With the tmpword, this tells me that your buffer is probably a byte sized buffer and if so, you got all kinds of problems. First, on the read, you overwrite the high byte of every previous word written. Second, on the read (and write) you point to the next indexed byte, not word.
What size is your buffer? When I ask size, what size is an element of that buffer? Byte, Word, DWord, etc.?
-Ben
http://www.fysnet.net/osdesign_book_series.htm