OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Issue with ATA IDENTIFY command on QEMU
PostPosted: Sat Sep 02, 2017 8:08 pm 
Offline
User avatar

Joined: Thu Apr 24, 2014 1:35 pm
Posts: 13
Hello all,

I've been working on a basic ATA driver, but I'm running into a strange problem when I try to issue the command IDENTIFY (ECh) to a drive:

Code:
cli

mov dx, 0x3f6 ;clear both control registers
xor al, al
out dx, al
mov dx, 0x376
out dx, al

mov dx, 0x177 ;now we need to check if there even are any drives
in al, dx
cmp al, 0xff ;if status is all ones, there is no drive at all
je ata_err

;now we need to check that we at least /have/ a responsive drive
mov dx, 0x172
mov al, 0x72
out dx, al
inc dx
mov al, 0x73
out dx, al
inc dx
mov al, 0xfa ;just a random value
out dx, al
mov dx, 0x172
in al, dx
cmp al, 0x72
jne stop_it ;this means we have no responsive drives

mov dx, 0x176 ;drive select register
mov al, 0xa0 ;master drive
out dx, al

mov dx, 0x177 ;now send IDENTIFY (0xec) to command reg
mov al, 0xec
out dx, al
in al, dx ;immediately read status after command
call fnc_print_hex ;print human-readable contents of al
cmp al, 0x00 ;if status is zero after IDENTIFY command, drive doesn't exist
je ata_err


On the primary bus (IO ports xFx), there is no master or slave drive, as status returns 00h after IDENTIFY command on both. On the secondary bus (IO x7x), the slave drive has the same behavior, but the master returns 41h (10000001b).

If I'm not mistaken, this means the busy and error bits are both set after issuing the command. Is this a problem with QEMU (v 0.9.0 under Windows (I know)), or am I doing something wrong with my code?

I'm booting off of an CD-ROM ISO, and I'm zero-ing both bus's control registers before attempting anything. I also check that the secondary returns old CHS values written to its registers.

My Sources

ATA PIO Mode
http://lateblt.tripod.com/atapi.htm
http://forum.osdev.org/viewtopic.php?t=15087

_________________
SAUCE CD IV - The most schwaaay OS.


Top
 Profile  
 
 Post subject: Re: Issue with ATA IDENTIFY command on QEMU
PostPosted: Sat Sep 02, 2017 8:23 pm 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
The BSY bit is bit 7 (0x80) not bit 6 (0x40). Your returned status (0x41) seems normal to me, because you're using a CD-ROM, which really is ATAPI and not ATA. Basically, ATAPI allows you send SCSI commands over the ATA bus. Most CD-ROMs are ATAPI devices.

After sending the ATA IDENTIFY command and receiving an error, read the ID of the device to check whether the error was caused by the device itself, or there is no device, or the device is a CD-ROM. If it is a CD-ROM, you perform the exact same IDENTIFY sequence but with the ATAPI IDENTIFY command byte instead of ATA IDENTIFY. I don't recall the exact values for each register/command I mentioned, but you can find them somewhere on our Wiki. ;)

If I were to guess from old memory however, the ATAPI IDENTIFY command is either 0xA1 or 0xA2. Again, just a guess.

_________________
You know your OS is advanced when you stop using the Intel programming guide as a reference.


Top
 Profile  
 
 Post subject: Re: Issue with ATA IDENTIFY command on QEMU
PostPosted: Sun Sep 03, 2017 5:59 am 
Offline
User avatar

Joined: Thu Apr 24, 2014 1:35 pm
Posts: 13
omarrx024 wrote:
The BSY bit is bit 7 (0x80) not bit 6 (0x40). Your returned status (0x41) seems normal to me, because you're using a CD-ROM, which really is ATAPI and not ATA. Basically, ATAPI allows you send SCSI commands over the ATA bus. Most CD-ROMs are ATAPI devices.


This is what I was missing, thank you! I was thinking that it was a normal ATA PIO device. #-o Now it works just fine with command 0xA1.

_________________
SAUCE CD IV - The most schwaaay OS.


Top
 Profile  
 
 Post subject: Re: Issue with ATA IDENTIFY command on QEMU
PostPosted: Sun Sep 03, 2017 4:45 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
FelixBoop wrote:
omarrx024 wrote:
...because you're using a CD-ROM, which really is ATAPI and not ATA. Basically, ATAPI allows you send SCSI commands over the ATA bus. Most CD-ROMs are ATAPI devices.

This is what I was missing, thank you! I was thinking that it was a normal ATA PIO device. #-o Now it works just fine with command 0xA1.

Just to add that this is the technique you are suppose to use to detect whether the device is ATA or ATAPI. Granted, you can and should check the two register values after a reset, but you should also then send the ATA IDENTIFY command.

An ATAPI will purposely fail an ATA IDENTIFY, therefore if you send the ATA IDENTIFY and it is successful, you know you have an ATA only device. If it fails, you either have a faulty ATA device or an ATAPI device, so try the ATAPI IDENTIFY. If it is successful, you have an ATAPI device.

Also, an ATA IDENTIFY command must wait for the drive to be ready, and ATAPI IDENTIFY, you do not have to wait for it to be ready. (via the ATA_STATUS_RDY bit)

Ben


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

All times are UTC - 6 hours


Who is online

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