OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:15 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Cannot write using ATA PIO mode.
PostPosted: Sat Jul 27, 2019 6:02 pm 
Offline
User avatar

Joined: Sat Jul 27, 2019 5:47 pm
Posts: 10
Location: Granada, Spain
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/master/src/kernel/drivers/ATA_PIO/ATA_PIO.c#L77
And here's the code I'm running: https://github.com/jlxip/jotadOS/blob/master/src/kernel/kernel.c#L69

It might be a stupid error but I'd really appreciate some insight. Thanks!


Top
 Profile  
 
 Post subject: Re: Cannot write using ATA PIO mode.
PostPosted: Sat Jul 27, 2019 11:19 pm 
Offline
Member
Member
User avatar

Joined: Mon Jul 13, 2009 5:52 am
Posts: 99
Location: Denmark
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.


Top
 Profile  
 
 Post subject: Re: Cannot write using ATA PIO mode.
PostPosted: Sun Jul 28, 2019 3:06 am 
Offline
User avatar

Joined: Sat Jul 27, 2019 5:47 pm
Posts: 10
Location: Granada, Spain
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group