Trouble detecting drive for ATA_PIO.

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
Caffeine
Member
Member
Posts: 79
Joined: Mon Nov 15, 2021 9:48 pm

Trouble detecting drive for ATA_PIO.

Post by Caffeine »

Hi, I am having trouble detecting the hard disk for my ATA_PIO driver. After sending the interrupt command, the status port comes back as 0? Does this mean I should write a PIC driver to find out where the ATA_PIO ports are? Or is their another soulution?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Trouble detecting drive for ATA_PIO.

Post by iansjack »

What do you mean by “sending the interrupt command”? Do you have an online repository of your code?
Caffeine
Member
Member
Posts: 79
Joined: Mon Nov 15, 2021 9:48 pm

Re: Trouble detecting drive for ATA_PIO.

Post by Caffeine »

iansjack wrote:What do you mean by “sending the interrupt command”? Do you have an online repository of your code?
That was i typo, my bad. I meant the IDENTIFY command.
Klakap
Member
Member
Posts: 297
Joined: Sat Mar 10, 2018 10:16 am

Re: Trouble detecting drive for ATA_PIO.

Post by Klakap »

Without code, it is almost impossible to guess where problem is.
Caffeine wrote:Does this mean I should write a PIC driver to find out where the ATA_PIO ports are?
I assume you mean PCI. If you want serious driver, answer is yes. Hard disk is not everywhere connected to same ports.
Caffeine
Member
Member
Posts: 79
Joined: Mon Nov 15, 2021 9:48 pm

Re: Trouble detecting drive for ATA_PIO.

Post by Caffeine »

Klakap wrote:Without code, it is almost impossible to guess where problem is.
Caffeine wrote:Does this mean I should write a PIC driver to find out where the ATA_PIO ports are?
I assume you mean PCI. If you want serious driver, answer is yes. Hard disk is not everywhere connected to same ports.
I did mean PCI, again, sorry for the typos. Thanks for the help! I'll make a PCI driver.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Trouble detecting drive for ATA_PIO.

Post by Octocontrabass »

It sounds an awful lot like you do have an IDE controller at the legacy I/O addresses, but there's no hard drive attached.

Are you testing this in a virtual machine? If so, how did you configure said virtual machine?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Trouble detecting drive for ATA_PIO.

Post by iansjack »

You must know whether there is an IDE drive in your computer (real or virtual). So, is there? If so then there is something wrong in your code (which we can’t see, so can’t guess at your error).

Forget PCI; if you have an IDE drive it will show up at the standard ports.
Caffeine
Member
Member
Posts: 79
Joined: Mon Nov 15, 2021 9:48 pm

Re: Trouble detecting drive for ATA_PIO.

Post by Caffeine »

Octocontrabass wrote:It sounds an awful lot like you do have an IDE controller at the legacy I/O addresses, but there's no hard drive attached.

Are you testing this in a virtual machine? If so, how did you configure said virtual machine?
Yeah, I'm using qemu. Here is the command I am using:

Code: Select all

qemu-system-i386 -cdrom Binaries/OS.iso -s
.

But other than that I am using the default settings.

EDIT:
I just replaced the line with:

Code: Select all

qemu-system-i386 -drive file=Binaries/caffieneOS.iso,media=cdrom
and now it is detecting something! But it does not look like it supports ATA.
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Trouble detecting drive for ATA_PIO.

Post by Octocontrabass »

Caffeine wrote:

Code: Select all

qemu-system-i386 -cdrom Binaries/OS.iso -s
This attaches a CD drive to the secondary IDE channel. You're probably looking at the primary IDE channel, but this command doesn't attach anything to the primary IDE channel.
Caffeine wrote:I just replaced the line with:

Code: Select all

qemu-system-i386 -drive file=Binaries/caffieneOS.iso,media=cdrom
, and now it is detecting something!
This attaches a CD drive to the primary IDE channel.
Caffeine
Member
Member
Posts: 79
Joined: Mon Nov 15, 2021 9:48 pm

Re: Trouble detecting drive for ATA_PIO.

Post by Caffeine »

So now the drive does not seem to be ATA. My code to check if it is ATA is:

Code: Select all

    while (status & STAT_BSY) { status = inportb(ATA_PRIMARY_COMM_REGSTAT); }  // Wait for status bit to clear

    unsigned char mid = inportb(ATA_PRIMARY_LBA_MID);
    unsigned char hi = inportb(ATA_PRIMARY_LBA_HI);
    if (mid != 0 || hi != 0) { print("The drive is not ATA."); return 0; }
And i've defined ATA_PRIMARY_LBA_MID as 0x1F4 and ATA_PRIMARY_LBA_HI 0x1F5. I'm pretty sure this is right but if not please let me know. And if I did do it correctly, how do I make the drive ATA. Also, STAT_BSY is defined as (1 << 7).
Last edited by Caffeine on Tue Apr 05, 2022 2:46 pm, edited 1 time in total.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Trouble detecting drive for ATA_PIO.

Post by iansjack »

That’s correct. A CD drive is not ATA. Try attaching a hard disk.
Caffeine
Member
Member
Posts: 79
Joined: Mon Nov 15, 2021 9:48 pm

Re: Trouble detecting drive for ATA_PIO.

Post by Caffeine »

iansjack wrote:That’s correct. A CD drive is not ATA. Try attaching a hard disk.
I got it working by running the VM with this command:

Code: Select all

qemu-system-i386 -drive file=Binaries/caffieneOS.iso,media=disk,format=raw
Thanks for all of your help!
Post Reply