OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Apr 22, 2024 11:28 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Floppy driver stopped working
PostPosted: 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.

Code:
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.


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Wed Apr 21, 2004 10:10 pm 
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.


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Thu Apr 22, 2004 2:07 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
you didn't toyed with paging or segments base, did you ?

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Thu Apr 22, 2004 11:15 am 
Forgot to say that it's working in bochs.


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Thu Apr 22, 2004 3:02 pm 
Pype: don't know...
I've tried an old version of the floppy driver, but it didn't work either.


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Thu Apr 22, 2004 4:59 pm 
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..


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Fri Apr 23, 2004 1:40 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
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 ...

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Fri Apr 23, 2004 1:53 am 
Ofcourse!
But that isn't my problem :\


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Fri Apr 23, 2004 3:09 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 11:33 pm
Posts: 3882
Location: Eindhoven
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.


Top
 Profile  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Fri Apr 23, 2004 10:05 am 
Candy: How do I detect whether my request was successful?
Like my ReadData/WriteData function?


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Fri Apr 23, 2004 1:43 pm 
And what do you mean by "you might have read some flags inverted"?


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Sat Apr 24, 2004 8:09 am 
have you made changes to your WaitFloppy() function ?
i had the same problem because of a mistake in this function...


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Sat Apr 24, 2004 10:49 am 
Nope, it waits until I get the interrupt.


Top
  
 
 Post subject: Re:Floppy driver stopped working
PostPosted: Tue Apr 27, 2004 1:49 pm 
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.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 47 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group