[C] ATA PIO Problem

Programming, for all ages and all languages.
Post Reply
User avatar
flerovium
Posts: 8
Joined: Tue May 15, 2012 10:11 am

[C] ATA PIO Problem

Post by flerovium »

Hello, new here, 15 years old , coding a kernel and from germany :) (enough information about myself)

I have a Problem with my ATA PIO Kernel Driver. I can read e.g. the MBR Sector etc, but when I try to read Sector 0x11CE (RootDir in my case), the
only output I get are some zeros. So it seems that the driver is not able to read Sector < 512, but I can't understand why, because I am already writing the Sector number with my outsw function instead of outb. Please help me. This is the code:

Code: Select all

unsigned char *hdReadSector(short Sector)
{
    unsigned char output[512];
    outb(0x1f6, 0x0); // Drive 0, Head 0
    outb(0x1f2, 0x1); // Read 1 Sector
    outsw(0x1f3, &Sector, 0x1); //outb(0x1f3, Sector); // Sector to read
    outb(0x1f4, 0); // Cylinder Low Port
    outb(0x1f5, 0); // Cylinder High Port
    outb(0x1f7, 0x20); // Read with retry
    
    int x = 0;
    while (x != 30000)
        x++;
    //while (!(inb(0x1f7) & 0x8 )) {};
    
    int i = 0;
    for (i; i < 256; i++)
    {
        short in = 0;
        insw(0x1f0, &in, 0x1);
        output[i*2] = in & 0xFF;
        output[(i*2)+1] = in >> 8;
    }
    return output;
}
Any advice accepted.

Thank you very much :)
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: [C] ATA PIO Problem

Post by Nable »

You are misundertstanding what IO port is. I mean that you can write only a fixed size value to one port, so if port is for 8bit IO, then you should learn what ports to use for upper bits.
Just go to http://wiki.osdev.org/ATA_PIO_Mode and Ctrl+F "1f3", you'll find what you need.
User avatar
flerovium
Posts: 8
Joined: Tue May 15, 2012 10:11 am

Re: [C] ATA PIO Problem

Post by flerovium »

Oh thank you very much ;)
So did I understand right, that I have to split the value and send it to the different ports?

Thank you very much.

EDIT: Oh f*ck (bad word) :DDD Thank you it works, I can keep on writing my FAT32 Driver!!
Post Reply