Floppy driver stopped working
Posted: Wed Apr 21, 2004 6:12 pm
My floppy driver was working correctly, until some days ago when I changed something which I can't recall.
Anyway, the floppy responds with an interrupt when it has read data, but the DMA doesn't put correct data, instead alot of garbage.
If I try to read from the floppy 3 times after eachother it will start working again.
I haven't changed anything of the DMA code, so it should be correct.
Anyway, the floppy responds with an interrupt when it has read data, but the DMA doesn't put correct data, instead alot of garbage.
If I try to read from the floppy 3 times after eachother it will start working again.
Code: Select all
void SendByte(uint8 _data) {
volatile int msr;
int tmo;
for (tmo = 0; tmo < 9999999; tmo++) {
msr = inb(FDC_MSR);
if ((msr & 0xc0) == 0x80) {
outb(FDC_DATA, _data);
return;
}
inb(0x80);
}
kprintf("SEND BYTE TIMEOUT\n");
}
int ReadByte() {
volatile int msr;
int tmo;
for (tmo = 0; tmo < 9999999; tmo++) {
msr = inb(FDC_MSR);
if ((msr & 0xd0) == 0xd0)
return inb(FDC_DATA);
inb(0x80);
}
kprintf("READ BYTE TIMEOUT\n");
return -1;
}
void SeekCylinder(uint32 cylinder) {
uint32 st0 = 0, cyl = 0;
uint32 iTO;
g_FloppyStatus = FDD_SEEKING;
SendByte(CMD_SEEK);
SendByte(0x0);
SendByte(cylinder);
WaitFloppy();
SendByte(CMD_SIS);
st0 = ReadByte();
cyl = ReadByte();
}
void ReadFDDSector(int _block, char* _buffer) {
uint32 cyl, sect, head, i, st0, st1, st2, c,h,s,ns;
LBA2CHS(_block, &cyl, &head, ?);
if (_buffer >= 0xA0000)
StartDMA(DMA_FLOPPY, DMA_READ, 0x90000, 511);
else
StartDMA(DMA_FLOPPY, DMA_READ, _buffer, 511);
kprintf("SEEKING!\n");
SeekCylinder(cyl);
g_FloppyStatus = FDD_READING;
SendByte(CMD_READ);
SendByte(head << 2);
SendByte(cyl);
SendByte(head);
SendByte(sect);
SendByte(2);
SendByte(1);
SendByte(FD_GAP3RW);
SendByte(0xFF);
kprintf("WAITING!\n");
WaitFloppy();
st0 = ReadByte();
st1 = ReadByte();
st2 = ReadByte();
c = ReadByte();
h = ReadByte();
s = ReadByte();
ns = ReadByte();
if (_buffer >= 0xA0000)^M
memcpy(_buffer, 0x90000, 512);
int a = 0;
for (a = 0; a < 512; a++)
kprintf("%c", _buffer[a]);
kprintf("\n");
}