Code: Select all
volatile char irqhd = 0;
void irq_hdd(struct regs* r)
{
irqhd = 1;
}
/* buffer = place to stuff data, lba = location on disk, count = num sectors */
void read(unsigned short *buffer, unsigned int lba, unsigned char count)
{
register int i;
irqhd = 0;
// read
outb(0x03f6, BIT(2)); // set srst (software reset)
inb(0x03f6); inb(0x03f6); // wait
inb(0x03f6); inb(0x03f6);
outb(0x01f6, 0xe0); // first master
outb(0x01f2, count); // set the count
outb(0x01f3, (unsigned char) lba); // and the lba
outb(0x01f4, (unsigned char) (lba >> 8));
outb(0x01f5, (unsigned char) (lba >> 16));
outb(0x01f7, 0x20); // read with retry
while(!irqhd); // wait for irq to fire
for(i = 0; i < count*256; i++)
buffer[i] = inw(0x01f0); // read in count sectors, word by word
}
EDIT: found problem
to anyone who may stumble upon this: you need to read the regular status register (0x1f7) in the interrupt