Cannot write using ATA PIO mode.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
jlxip
Posts: 10
Joined: Sat Jul 27, 2019 5:47 pm
Location: Granada, Spain
Contact:

Cannot write using ATA PIO mode.

Post by jlxip »

I've been struggling for more than a week with this issue: I cannot get ATA PIO writing working properly. Most of the time it doesn't work, but sometimes it does, so I thought that it might be a timing issue, but setting more and more delay didn't really help. The only thing that sort of patches this is to write several times before doing the flush, but even this doesn't always work.

I've modified my code according to a lot of different places, from GitHub repositories to YouTube tutorials, but I can't seem to get it working.
I'm using both VirtualBox and Qemu to test it.

The thing is that I know reading works: when a successful write occurs, if I turn off the machine, comment the writing code, and run only the reading, I always get the same output.

Here's my driver: https://github.com/jlxip/jotadOS/blob/m ... _PIO.c#L77
And here's the code I'm running: https://github.com/jlxip/jotadOS/blob/m ... rnel.c#L69

It might be a stupid error but I'd really appreciate some insight. Thanks!
User avatar
zity
Member
Member
Posts: 99
Joined: Mon Jul 13, 2009 5:52 am
Location: Denmark

Re: Cannot write using ATA PIO mode.

Post by zity »

A couple of things come to mind when looking at your code.

- When doing the drive select, you should really check that it actually succeeds
- After sending the write command (0x30) you need to poll the status register and wait until BSY is cleared and DRQ is set (you should also check that ERR and DF is not set). If you don't do this, you might start writing the data before the drive is actually ready.
- I would send the flush command (0xE7) directly after you are done writing the data in the for loop.

The wiki article ATA_PIO_Mode is quite good. Ignore the code, and just read the text.
User avatar
jlxip
Posts: 10
Joined: Sat Jul 27, 2019 5:47 pm
Location: Granada, Spain
Contact:

Re: Cannot write using ATA PIO mode.

Post by jlxip »

zity wrote:After sending the write command (0x30) you need to poll the status register and wait until BSY is cleared and DRQ is set (you should also check that ERR and DF is not set). If you don't do this, you might start writing the data before the drive is actually ready.
I've implemented the rest of your points as well, but THIS made the difference. Thank you very much!!! =D>
Post Reply