ATA driver reads only zeros

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
K3achas
Posts: 22
Joined: Sat May 26, 2018 5:32 pm

ATA driver reads only zeros

Post by K3achas »

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.
Last edited by K3achas on Sat Mar 02, 2019 2:07 pm, edited 1 time in total.
The maker of Foxtrot microkernels. Currently just Greyhound, which is currently smaller than 3 KiB.
Also working on osmkVII.
User avatar
crosssans
Member
Member
Posts: 39
Joined: Fri Mar 01, 2019 3:50 pm
Location: France

Re: ATA driver reads only zeros

Post by crosssans »

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
User avatar
K3achas
Posts: 22
Joined: Sat May 26, 2018 5:32 pm

Re: ATA driver reads only zeros

Post by K3achas »

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.
User avatar
crosssans
Member
Member
Posts: 39
Joined: Fri Mar 01, 2019 3:50 pm
Location: France

Re: ATA driver reads only zeros

Post by crosssans »

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
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: ATA driver reads only zeros

Post by BenLunt »

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
User avatar
K3achas
Posts: 22
Joined: Sat May 26, 2018 5:32 pm

Re: ATA driver reads only zeros

Post by K3achas »

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.
User avatar
K3achas
Posts: 22
Joined: Sat May 26, 2018 5:32 pm

Re: ATA driver reads only zeros

Post by K3achas »

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.
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: ATA driver reads only zeros

Post by mallard »

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
User avatar
K3achas
Posts: 22
Joined: Sat May 26, 2018 5:32 pm

Re: ATA driver reads only zeros

Post by K3achas »

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.
Post Reply