Floppy driver stopped working

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
ohboy

Floppy driver stopped working

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

Re:Floppy driver stopped working

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Floppy driver stopped working

Post by Pype.Clicker »

you didn't toyed with paging or segments base, did you ?
ohboy

Re:Floppy driver stopped working

Post by ohboy »

Forgot to say that it's working in bochs.
ohboy

Re:Floppy driver stopped working

Post by ohboy »

Pype: don't know...
I've tried an old version of the floppy driver, but it didn't work either.
ohboy

Re:Floppy driver stopped working

Post 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..
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Floppy driver stopped working

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

Re:Floppy driver stopped working

Post by ohboy »

Ofcourse!
But that isn't my problem :\
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Floppy driver stopped working

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

Re:Floppy driver stopped working

Post by ohboy »

Candy: How do I detect whether my request was successful?
Like my ReadData/WriteData function?
ohboy

Re:Floppy driver stopped working

Post by ohboy »

And what do you mean by "you might have read some flags inverted"?
aladdin

Re:Floppy driver stopped working

Post by aladdin »

have you made changes to your WaitFloppy() function ?
i had the same problem because of a mistake in this function...
ohboy

Re:Floppy driver stopped working

Post by ohboy »

Nope, it waits until I get the interrupt.
ohboy

Re:Floppy driver stopped working

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