OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Problems reading harddisk in ATA PIO pooling mode.
PostPosted: Thu Mar 30, 2023 2:45 pm 
Offline

Joined: Thu Mar 30, 2023 2:19 pm
Posts: 1
Hello everybody, this is my first question in this forum. :D

I am trying to use the identify command in qemu to the hard disk (ATA PIO). My kernel is written mostly in Rust I will append the most relevant code, you can find all the OS in (https://github.com/DanielSanRocha/kecleon).
I am receiving 0xff53 from 0x1F0 (reading 16 bits) everytime I read.

My identify implementation (Rust)

Code:
pub fn initialize() {
    unsafe {
        ata_wait_bsy();
        ata_wait_drq();

        let _ = memory::inb(ATA_IO, 7);

        memory::outb(ATA_IO, 0xA0, 6);

        memory::outb(ATA_IO, 0, 2);
        memory::outb(ATA_IO, 0, 3);
        memory::outb(ATA_IO, 0, 4);
        memory::outb(ATA_IO, 0, 5);

        memory::outb(ATA_IO, 0xEC, 7);

        let status = memory::inb(ATA_IO, 7);

        if status == 0 {
            panic!("Primary ATA Driver not found!");
        }

        ata_wait_bsy();

        let x2 = memory::inb(ATA_IO, 2);
        let x3 = memory::inb(ATA_IO, 3);
        let x4 = memory::inb(ATA_IO, 4);
        let x5 = memory::inb(ATA_IO, 5);

        ata_wait_bsy();

        if x2 != 0 || x3 != 0 || x4 != 0 || x5 != 0 {
            panic!("Device at 0x1F0 is not ATA!");
        }

        ata_wait_bsy();
        ata_wait_drq();

        let name = memory::kmalloc(512);
        for i in 0..=255 {
            let cc = memory::u16_inb(ATA_DATA, 0);
            *(name as *mut u16).offset(i) = cc;
        }

        screen::print_string(name, screen::VgaColor::LightGreen);
    }
}


And ata_wait_bsy, ata_wait_drq implementation (C):

Code:
#define ATA_IO 0x1F0

void ata_wait_drq() {
    while(c_inb(ATA_IO + 7) & 0x40 == 0) {}
}

void ata_wait_bsy() {
    while(c_inb(ATA_IO + 7) & 0x80 != 0) {}
}


What I am doing wrong?


Top
 Profile  
 
 Post subject: Re: Problems reading harddisk in ATA PIO pooling mode.
PostPosted: Mon Apr 03, 2023 7:10 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
danielsan wrote:
What I am doing wrong?

You were accessing memory space instead of I/O space.

ARM doesn't have separate memory and I/O spaces like x86, so you won't have this problem now that you've switched to ARM.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 79 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