OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 10:29 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: ATA driver reads only zeros
PostPosted: Sat Mar 02, 2019 10:05 am 
Offline
User avatar

Joined: Sat May 26, 2018 5:32 pm
Posts: 22
Hello. I've got back to work on my ATA driver, and after rewriting the initialization, I've finally got it working. Unfortunately, all the reads I preform using the driver return zeros (I've only tried them in qemu).

Link to the code. Relevant function is ata_read which starts on line 45.

_________________
The maker of Foxtrot microkernels. Currently just Greyhound, which is currently smaller than 3 KiB.
Also working on osmkVII.


Last edited by K3achas on Sat Mar 02, 2019 2:07 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: ATA driver reads only zeros
PostPosted: Sat Mar 02, 2019 12:56 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 01, 2019 3:50 pm
Posts: 39
Location: France
The first thing that I can recommend you to do is spacing your code: most of the time, you'll catch the part where you did wrong and rectify it.

The second thing to do is to print each ATA command sent to the disk with all the important values to a console, a logger, serial port, etc. This will allow you to see if the command arguments are properly set and sent. Don't forget to also print the status of the ATA disk that you're accessing, that could be useful for your problem.

If you still didn't notice any error in your code, check if the problem comes from your code or the emulator/virtualization tool itself. If you're booting off real hardware, check UEFI's settings if the parameters are correct. By the way, it would be very helpful to send the configuration that you're using to test your operating system! :)

Anyways, feel free to correct me if I said something wrong, as I started my journey in operating system development a month ago now. :D


Top
 Profile  
 
 Post subject: Re: ATA driver reads only zeros
PostPosted: Sat Mar 02, 2019 2:06 pm 
Offline
User avatar

Joined: Sat May 26, 2018 5:32 pm
Posts: 22
Thanks. After printing the registers of the ATA controller, I found out that I hadn't actually output one of the registers. Good luck on your osdev journey.

It now reads on sector just fine, but with the second sector I try to read, it aborts the command. Updated code.

_________________
The maker of Foxtrot microkernels. Currently just Greyhound, which is currently smaller than 3 KiB.
Also working on osmkVII.


Top
 Profile  
 
 Post subject: Re: ATA driver reads only zeros
PostPosted: Sat Mar 02, 2019 3:13 pm 
Offline
Member
Member
User avatar

Joined: Fri Mar 01, 2019 3:50 pm
Posts: 39
Location: France
K3achas wrote:
It now reads on sector just fine, but with the second sector I try to read, it aborts the command

Did you compare what you currently have with the example code found on the OSDev Wiki? Maybe this could help :wink:
Thanks, by the way :D


Top
 Profile  
 
 Post subject: Re: ATA driver reads only zeros
PostPosted: Sat Mar 02, 2019 5:02 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
K3achas wrote:
Thanks. After printing the registers of the ATA controller, I found out that I hadn't actually output one of the registers. Good luck on your osdev journey.

It now reads on[e] sector just fine, but with the second sector I try to read, it aborts the command.

Abort usually means that there is an error in the parameters, which could mean it is in the middle of the last command. Did you read all of the sector or sectors requested? For example, if you think you are reading only one sector (256 words) but actually requested more, it may abort. (may, depending on the current status and command)

Also, note that the interrupt is fired for each sector read, not at the beginning of all sectors requested. For example, if you request two sectors, you will read 256 words and expect an interrupt before the next sector is to be read, reading the STATUS register to clear the interrupt. If you do not acknowledge the interrupt, an abort might take place.

Without looking at your code in more detail, I just threw this out there. However, I must ask why you are writing in assembly instead of C or another high level language. In my opinion, coding in assembly makes it much more error prone.

Ben
-http://www.fysnet.net/osdesign_book_series.htm


Top
 Profile  
 
 Post subject: Re: ATA driver reads only zeros
PostPosted: Sat Mar 02, 2019 6:32 pm 
Offline
User avatar

Joined: Sat May 26, 2018 5:32 pm
Posts: 22
I now see I had ambiguous wording. I meant the second time I tried to read a sector. Each read so far has only been one sector. After making an edit to the code, I've found out that DRQ has been unset before I return.

EDIT: Also, I'm writing it in assembly because I like the challenge.

_________________
The maker of Foxtrot microkernels. Currently just Greyhound, which is currently smaller than 3 KiB.
Also working on osmkVII.


Top
 Profile  
 
 Post subject: Re: ATA driver reads only zeros
PostPosted: Sun Mar 03, 2019 10:52 am 
Offline
User avatar

Joined: Sat May 26, 2018 5:32 pm
Posts: 22
Error was a garbage in garbage out error. I put a push where I needed to put a pop in the function calling ata_read the second time. I've added some code to note what the registers are permanently in there for debugging.

_________________
The maker of Foxtrot microkernels. Currently just Greyhound, which is currently smaller than 3 KiB.
Also working on osmkVII.


Top
 Profile  
 
 Post subject: Re: ATA driver reads only zeros
PostPosted: Mon Mar 04, 2019 7:31 am 
Offline
Member
Member

Joined: Tue May 13, 2014 3:02 am
Posts: 280
Location: Private, UK
This may be a silly question, but have you confirmed that the disk image being used by QEMU actually contains something other than zeros? A freshly created image would likely contain just that...

_________________
Image


Top
 Profile  
 
 Post subject: Re: ATA driver reads only zeros
PostPosted: Mon Mar 04, 2019 12:27 pm 
Offline
User avatar

Joined: Sat May 26, 2018 5:32 pm
Posts: 22
I am certain that it contains stuff others than zeros -- I've successfully fixed the code and read from it.

_________________
The maker of Foxtrot microkernels. Currently just Greyhound, which is currently smaller than 3 KiB.
Also working on osmkVII.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 96 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