Page 1 of 1

Floppy driver stopped working

Posted: Wed Apr 21, 2004 6:12 pm
by ohboy
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.

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");
}

I haven't changed anything of the DMA code, so it should be correct.

Re:Floppy driver stopped working

Posted: Wed Apr 21, 2004 10:10 pm
by ASHLEY4
My advice is backup your code and keep a copy until you are 100% that the updated version, works how you want it to,or you will end up :'( .

ASHLEY4.

Re:Floppy driver stopped working

Posted: Thu Apr 22, 2004 2:07 am
by Pype.Clicker
you didn't toyed with paging or segments base, did you ?

Re:Floppy driver stopped working

Posted: Thu Apr 22, 2004 11:15 am
by ohboy
Forgot to say that it's working in bochs.

Re:Floppy driver stopped working

Posted: Thu Apr 22, 2004 3:02 pm
by ohboy
Pype: don't know...
I've tried an old version of the floppy driver, but it didn't work either.

Re:Floppy driver stopped working

Posted: Thu Apr 22, 2004 4:59 pm
by ohboy
Sorry for posting this much, but, I've checked the values of st0 etc after I've tried to read:

st0: 0x40 st1: 0x4 st2: 0x10 cylinder: 0 head: 0 sector: 1 ns: 2
Drive not ready
The drive faults
Head is not active
Selected drivr is 2
Normal termination
Error in the ID address field or the data field of a sector.
No address mark found
Data can not be read
Bad cylinder
No address mark found (st2)
wrong cylinder


When I do it in bochs I get this: (when it's working)

st0: 0 st1: 0 st2: 0 c: 0 h: 0 s: 2 ns: 2
Drive is not ready
Head is active
Selected drive is 3
Successful command
normal termination
error in the ID address field or the data field of a sector
No address mark found
data can not be read
write protected
bad cylinder
crc error in data fields
no address mark found (st2)
seek fullfilled
could not find corresponding sectors when seeking on the cylinder.

When I run in bochs it works, when I run on a real comp it doesn't save anything to ram..

Re:Floppy driver stopped working

Posted: Fri Apr 23, 2004 1:40 am
by Pype.Clicker
ohboy wrote: Pype: don't know...
I've tried an old version of the floppy driver, but it didn't work either.
maybe i should get myself clearer ...
DMA transfers will only deal with *physical* addresses. If you enable paging (with some non 1:1 translation) or use a segment which base is not zero, the logical address (the one you use in your program) has not the same meaning for the DMA ...

i'm not at all a floppy-guru, so this is the best i can offer ...

Re:Floppy driver stopped working

Posted: Fri Apr 23, 2004 1:53 am
by ohboy
Ofcourse!
But that isn't my problem :\

Re:Floppy driver stopped working

Posted: Fri Apr 23, 2004 3:09 am
by Candy
ohboy wrote: Ofcourse!
But that isn't my problem :\
Physical floppy drives suffer from the spinup-problem, which bochs doesn't do. Or, as RBIL says, retry your request at least 3 times (translating to your own driver as probably 9 times).

PS: if that bochs output is success, you might have read some flags inverted.

Re:Floppy driver stopped working

Posted: Fri Apr 23, 2004 10:05 am
by ohboy
Candy: How do I detect whether my request was successful?
Like my ReadData/WriteData function?

Re:Floppy driver stopped working

Posted: Fri Apr 23, 2004 1:43 pm
by ohboy
And what do you mean by "you might have read some flags inverted"?

Re:Floppy driver stopped working

Posted: Sat Apr 24, 2004 8:09 am
by aladdin
have you made changes to your WaitFloppy() function ?
i had the same problem because of a mistake in this function...

Re:Floppy driver stopped working

Posted: Sat Apr 24, 2004 10:49 am
by ohboy
Nope, it waits until I get the interrupt.

Re:Floppy driver stopped working

Posted: Tue Apr 27, 2004 1:49 pm
by ohboy
I've done alot of debugging now, and I've made the floppy driver to read folders on a FAT12-floppy correct. But, if I try to read a sector, for example 193, I either get nothing or the first sector!
If I read sectors 0-300 in a loop it prints everything correct, but if I loop in the other way, 300-0, nothing gets read.