0

i have written a super simple os and i decided to start using grub to boot it, so i started a new projected and im getting my old kernel functions to the new kernel and the ATA driver is not working stuck when i wait for DRQ

void ATA_wait_DRQ() // Wait fot drq to be 1
{
    while (!(insb(0x1F7) & STATUS_RDY))
        ;
}

and the function to read the sector

int disk_read_sector(int lba, void *buf)
{
    ATA_wait_BSY();
    print("f1");
    ATA_wait_DRQ(); // estes dois nao estavam aqui antes pus so pq no write tive de por
    print("f2");

    lba = lba + OS_SECTORS + HEADER_SECTORS;
    outb(0x1F6, (lba >> 24) | 0xE0);
    outb(0x1F2, 1);
    outb(0x1F3, (unsigned char)(lba & 0xff));
    outb(0x1F4, (unsigned char)(lba >> 8));
    outb(0x1F5, (unsigned char)(lba >> 16));
    outb(0x1F7, 0x20);

    unsigned short *ptr = (unsigned short *)buf;

    ATA_wait_BSY();
    ATA_wait_DRQ();

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

    return 0;
}

this used to work on my old bootloader so i think is something related to it the idt is also from the old bootloader and de gdt is the same as nanobyte used in this video so im really lost the interrupts are working fine, div 0 is good keyboard input also, my unique current problem

i added this function

void checkPort()
{
    char a = insb(0x1F7);
    a = a + 48;
    write_char_pos(5, 5, a, 0x00ff00);
    if (a == '0')
    {
        char b = insb(0x1F1);
        b = b + 48;
        write_char_pos(6, 6, a, 0x00ff00);
    }
}

and it wrote on pos 5,5 the 0 so i think im getting an error and on line 6,6 also a 0

Rabyt
  • 61
  • 6
  • are you running this in a virtual machine? it may have debugging abilities, or you may be able to look at the source code. [Here on page 22](https://ceunican.github.io/aos/36.IO_Devices.pdf) I found the 0x1F7 and 0x1F1 registers. What value does 0x1F7 get stuck on? – user253751 Mar 06 '23 at 19:34
  • Are you sure that it's looping forever and not crashed because it got an interrupt that wasn't handled properly? – user253751 Mar 06 '23 at 19:34
  • so... it was on the emulator... always try things on other emulators guys :D u had -cdrom on qemu startup.. it always worked for me but this time i didnt :D – Rabyt Mar 07 '23 at 21:52

0 Answers0