Page 1 of 1

Bochs isnt fire interrupt for writing[solved]

Posted: Thu Feb 21, 2019 1:14 pm
by Klakap
Good day!

I found problem with my ata pio driver. If I in Bochs write, interrupt isnt fire. This is my code:

Code: Select all

int ata_pio28(uint16_t base, uint8_t type, uint64_t addr, uint8_t drive) {
    int cycle=0;

    if(drive==IDE_MASTER) {
    outb(base+ATA_PORT_DRV, 0xE0);
    }
    else { // IDE_SLAVE
    outb(base+ATA_PORT_DRV, 0xF0);
    }

    if ((inb(base+ATA_PORT_STATUS) & 0x01)) { 
        system_ata_pio_error();
        return 0;
    }

    ide_primary_interrupt=0;    //prepare value for next interrupt

    //PIO28
    outb(base+ATA_PORT_FEATURES, 0x00);
    outb(base+ATA_PORT_SCT_COUNT, 0x01);
    outb(base+ATA_PORT_SCT_NUMBER, (unsigned char)addr);
    outb(base+ATA_PORT_CYL_LOW, (unsigned char)(addr >> 8));
    outb(base+ATA_PORT_CYL_HIGH, (unsigned char)(addr >> 16));
    //type
    if(type==ATA_READ) {
    outb(base+ATA_PORT_COMMAND, 0x20);  // Send command
    }
    else {
    outb(base+ATA_PORT_COMMAND, 0x30);
    }

    //wait for irq
    cycle=0;
    for(int i=0; i<10000; i++) {
        inb(base+7);  //wait
        if( ide_primary_interrupt==1 ) {  //irq is fire
            cycle=1;
            break;    
        }    
    }
    if(cycle==0) {  //Something is wrong
        return 0;
    }

    for (int idx = 0; idx < 256; idx++)
    {
        if(type==ATA_READ) {
            ata_buffer[idx] = inw(base + ATA_PORT_DATA);
        }
        else {
            outw(base + ATA_PORT_DATA, ata_buffer[idx]);
        }
    }

    return 1;
}
Please where is bug?

Re: Bochs isnt fire interrupt for writing

Posted: Fri Feb 22, 2019 4:43 am
by Octocontrabass
I don't know if this is related to the issues you're having in Bochs, but I see you're reading the status register outside of your interrupt handler. Reading the status register acknowledges the interrupt. You should use the alternate status register instead.

Re: Bochs isnt fire interrupt for writing

Posted: Sat Feb 23, 2019 12:12 pm
by Klakap
Thank you! With reading from alternate status register and pooling is all good. I think than my waiting cycle was little time for irq.