Page 1 of 1

Trouble detecting drive for ATA_PIO.

Posted: Mon Apr 04, 2022 1:26 pm
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?

Re: Trouble detecting drive for ATA_PIO.

Posted: Mon Apr 04, 2022 2:08 pm
by iansjack
What do you mean by “sending the interrupt command”? Do you have an online repository of your code?

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 7:44 am
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.

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 8:56 am
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.

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 11:14 am
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.

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 11:22 am
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?

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 12:15 pm
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.

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 1:08 pm
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.

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 1:36 pm
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.

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 2:29 pm
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).

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 2:42 pm
by iansjack
That’s correct. A CD drive is not ATA. Try attaching a hard disk.

Re: Trouble detecting drive for ATA_PIO.

Posted: Tue Apr 05, 2022 2:51 pm
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!