Page 1 of 1

fs lockup

Posted: Fri Mar 27, 2009 7:34 pm
by Styx
the atapi code i have locks up after a 2nd read. the first read works fine. the code is as follows:

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
}
can anyone see a problem with this?

EDIT: found problem

to anyone who may stumble upon this: you need to read the regular status register (0x1f7) in the interrupt

Re: fs lockup

Posted: Sat Mar 28, 2009 5:45 am
by pcmattman
EDIT: found problem

to anyone who may stumble upon this: you need to read the regular status register (0x1f7) in the interrupt
There are more problems than that in this code, but if you're only aiming for it to work for now and be fixed later. As long as you do change it, because if you don't you're going to get smashed with bugs :)