Page 1 of 1
Floppy Driver Problem
Posted: Sun Jan 19, 2003 3:13 pm
by whyme_t
I'm having some big problems with my floppy driver. When tested on bochs and one of my test machines it causes an unknown exception before timing out. I have mapped exception handlers for all irq's and cpu irq's, and it is not one of those, so it must be 8, 15++.
On my other machine (with has a ls120 disk drive, can take 120mb disks) it works great.
Here is the function which causes the exception.
Code: Select all
#define FDC_MSR (0x3f4)
#define FDC_DATA (0x3f5)
int FloppyDriver::getByte()
{
volatile int msr ;
int tmo ;
for(tmo=0; tmo<128; tmo++)
{
msr = IOPorts::read(FDC_MSR) ;
if((msr & 0xd0) == 0xd0)
{
return IOPorts::read(FDC_DATA) ;
}
IOPorts::read(80) ; //delay
}
return -1 ;
}
I also noted that bochs has a problem with the code here.
00024633971e[FDD ] io_write: data rate select register unsupported
EDIT - Er, sorry I forgot to ask an actual question, doh! Can anybody see any obvious problems with the code?
Re:Floppy Driver Problem
Posted: Sun Jan 19, 2003 4:52 pm
by Curufir
This looks odd. Could be my pathetic C knowledge letting me down again, but it just does.
The bits you appear to be checking in the MSR are these:
bit 7-Main request. You check for 1 which is good, since that mean the data register is ready.
bit 6-Data I/O. You check for 1 which is right I think. The controller wanting to output data to the cpu.
bit 4-Busy bit. This is what got me curious. When this is set it means the controller is busy. So your read byte instruction only ever gets run if the controller is busy executing a command when execution reaches this "if" statement.
Data Rate Select Register is also port 0x3f4, but that shouldn't be a problem since you never write to it. Any reads from that port should (afaik) read the MSr which is what you want. You could always try using the alternative port (0x374 I think).
The other thing is this:
Can your read function handle both decimal and hex? Because you set the other 2 ports in hex, and this one in decimal. If not then port 0x50 is the parallel port I think. What you were probably trying to use was 0x80 which is the port Linux uses for delays.
**
Went and had a dig around my docs because I got curious. Apparently port 0x50 is used to control something called a "Serial Communications Chip" in some Olivetti computers (
Source: Ralf Brown's Port List). This isn't incredibly likely to be there, and reading non-existent ports is liable to cause problems.
Re:Floppy Driver Problem
Posted: Sun Jan 19, 2003 7:44 pm
by Ozguxxx
It seems to me that ANDing MSR with 0d is not what you should do whiel reading you must AND with 0c. I think I am sure about this because it is written in Intel manual. A more simple readbyte would be:
Code: Select all
void writeController(u8b data)
{
u8b status;
u8b msr;
while(1)
{
msr = inb(ADD_MSR);
if((msr & (0xc0)) == 0x80)
{
outb(ADD_DATA, data);
return;
}
}
}
Now I do not exactly know which bits are these ANDed bits but correct form should be like that. Anyway, while writing to cotroller you should and MSR with 0c and check if this value is equal to 80. (Also from intel manual.) So an appropriate and simple write is:
Code: Select all
void writeController(u8b data)
{
u8b status;
u8b msr;
while(1)
{
msr = inb(ADD_MSR);
if((msr & (0xc0)) == 0x80)
{
outb(ADD_DATA, data);
return;
}
}
}
I hope these helps you and also hope these are correct but they are worknig for mine. Anyway, also same BOCHS error was
(
00024633971e[FDD ] io_write: data rate select register unsupported
) also happening to me. I think this is about BOCHS. (Is it?) Good luck...
Re:Floppy Driver Problem
Posted: Sun Jan 19, 2003 7:46 pm
by Ozguxxx
I am sorry, I had just posted writeController instead of readController, I am really sorry: ;D
Code: Select all
u8b readController()
{
u8b msr, data;
while(1)
{
msr = inb(ADD_MSR);
if((msr & (0xc0)) == 0xc0)
{
data = inb(ADD_DATA);
return(data);
}
}
}
Re:Floppy Driver Problem
Posted: Mon Jan 20, 2003 2:12 pm
by whyme_t
Thanks for all the help so far guys, but I'm still having some problems. An exception is always called when I try and read from the FDC_MSR in my getByte function.
If I read from 0x3f4, It causes an exception, which is handled by the default handler. (but I've mapped the first 15 irqs to other handlers, remapped the pics, and only enabled clock, keyboard, and floppy).
If I read from the alternate port as suggested by Curufir, 0x374, there is no exception, but it either times out (for loop), or infinite loop (while). So I'm guessing this isn't the correct Port.
I've tried reading the various documents on the web, but I find them all a bit cryptic :-\
Can anyone help me out?
Re:Floppy Driver Problem
Posted: Mon Jan 20, 2003 2:40 pm
by Ozguxxx
Hi, are you sure that you are correctly initializing floppy controller? Also which exception is called when you read 0x3f4? Is it IRQ6? You should know in which mode controller is in because it might be waiting for a sense interrupt status command after initialization... I cannot exactly remember how it worked but my suggestion is reading intel 82077a manual, it contains all programming stuff: initialization and other operations... Good luck.