OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:15 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: How to use multiple disks?
PostPosted: Mon Jan 30, 2023 11:21 am 
Offline

Joined: Thu Jul 14, 2022 10:46 am
Posts: 24
Location: Canada
OK so i did some reading and there is a register at port 0x1f6 is a disk ID. BIOS sets that to the ID of the disks booted to. How can I find more IDs? Sorry if this is a dumb question lol


Top
 Profile  
 
 Post subject: Re: How to use multiple disks?
PostPosted: Mon Jan 30, 2023 11:59 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Er, I don't know what you've been reading, but port 0x1F6 isn't an ID. If your IDE controller is mapped at the legacy addresses, that port contains the drive select bit, but that only tells you which drive is selected on that IDE channel.

What kind of ID are you looking for? Why do you need an ID? There are different IDs available, and the one that works best for you will depend on what you want to do with it.


Top
 Profile  
 
 Post subject: Re: How to use multiple disks?
PostPosted: Tue Jan 31, 2023 1:39 pm 
Offline

Joined: Thu Jul 14, 2022 10:46 am
Posts: 24
Location: Canada
I must have read something wrong. I think I'm not clicking somewhere.
Attatched is a snippet of som code I wrote. Let me know if I have the correct understanding of what to do
Code:
bool ata_identify(uint16_t base_port)
{
    outb(base_port + 6, 0xA0); //master
    outb(base_port + 2, 0);
    outb(base_port + 3, 0);
    outb(base_port + 4, 0);
    outb(base_port + 5, 0);
    outb(base_port + 7, 0xEC);

    uint8_t buf[512];
    unsigned short* ptr = (unsigned short*) buf;

    // Wait for the buffer to be ready
    uint8_t c = insb(base_port + 7);
    if(!c)
        return false;

    while(c & 0x80)
        c = insb(base_port + 7);
   
    uint8_t lba_mid = insb(base_port + 4), lba_hi = insb(base_port + 5);
    if(lba_hi || lba_mid)
        return false;

    do
        c = insb(base_port + 7);
    while(!(c & 0x08) || !(c & 0x01));

    for (int i = 0; i < 256; i++)
    {
        *ptr = insw(base_port);
        ptr++;
    }
    return true;
}

int ata_count_connected_disks()
{
    int res = 0;
    for(uint16_t i = 0x400; i < 0xFFFF; i += 8)
        if(ata_identify(i))
            res++;
    return res;
}


Top
 Profile  
 
 Post subject: Re: How to use multiple disks?
PostPosted: Tue Jan 31, 2023 2:04 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
Code:
    outb(base_port + 6, 0xA0); //master

There may be two devices attached to an IDE channel; you're only checking one of them.

Code:
    uint8_t c = insb(base_port + 7);

Are you using "inb" or "insb" here? They are not the same thing.

Code:
    while(!(c & 0x08) || !(c & 0x01));

I'm pretty sure you wanted to use "&&" instead of "||" here. Also, if the error bit is set, you can't read the identify data from the disk.

Code:
        *ptr = insw(base_port);

Are you using "inw" or "insw" here? They are not the same thing.

Code:
    for(uint16_t i = 0x400; i < 0xFFFF; i += 8)
        if(ata_identify(i))

Use PCI to find the addresses of IDE controllers, don't probe for them like this. (Unless you want to use IDE on an ancient PC that doesn't support PCI - then you can assume the IDE controller uses 0x1F0.)


Top
 Profile  
 
 Post subject: Re: How to use multiple disks?
PostPosted: Tue Jan 31, 2023 2:48 pm 
Offline

Joined: Thu Jul 14, 2022 10:46 am
Posts: 24
Location: Canada
OK so PCI will tell me the port num of IDE controller. Does one IDE controller control every disks connected? or will each disk have its own controller? If each disk has its own controller, then will PCI tell me address of each controller?


Top
 Profile  
 
 Post subject: Re: How to use multiple disks?
PostPosted: Tue Jan 31, 2023 2:59 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
jaihsonk wrote:
Does one IDE controller control every disks connected? or will each disk have its own controller?

There may be any number of IDE controllers. Each IDE controller may have up to two channels. Each channel may have up to two disks.

jaihsonk wrote:
will PCI tell me address of each controller?

Yes.


Top
 Profile  
 
 Post subject: Re: How to use multiple disks?
PostPosted: Tue Jan 31, 2023 3:04 pm 
Offline

Joined: Thu Jul 14, 2022 10:46 am
Posts: 24
Location: Canada
OK thank you so much. This s a lot clearer now. Humans are a lot better the articles lol


Top
 Profile  
 
 Post subject: Re: How to use multiple disks?
PostPosted: Tue Jan 31, 2023 3:21 pm 
Offline

Joined: Thu Jul 14, 2022 10:46 am
Posts: 24
Location: Canada
For anyone else, I also found this video to explain a fw things: https://www.youtube.com/watch?v=CF_copQaORQ


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

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