Bochs isnt fire interrupt for writing[solved]

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Klakap
Member
Member
Posts: 299
Joined: Sat Mar 10, 2018 10:16 am

Bochs isnt fire interrupt for writing[solved]

Post 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?
Last edited by Klakap on Sat Feb 23, 2019 12:12 pm, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: Bochs isnt fire interrupt for writing

Post 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.
Klakap
Member
Member
Posts: 299
Joined: Sat Mar 10, 2018 10:16 am

Re: Bochs isnt fire interrupt for writing

Post 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.
Post Reply