OSDev.org

The Place to Start for Operating System Developers
It is currently Mon May 27, 2024 5:20 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Floppy Driver Discussion
PostPosted: Sat Mar 31, 2007 8:27 pm 
Offline
Member
Member
User avatar

Joined: Tue Mar 06, 2007 11:17 am
Posts: 1225
This thread is to discuss and end up building up a working floppy driver. I personally have been trying to make one, but it doesn't respond. I have interrupts enabled on the CPU and the PIC, have installed the IS (which only sets a flag when the floppy is ready for something) and I have build up a test read function.

But it doesn't work. It gets stalled in the middle near when I send and complete the floppy read command. Could it be a DMA initialization problem, or does it have something to do with the order in which it the floppy parameters get called? The problem is that I wait for the FDC interrupt but it never arrives.

Another question: is it necessary to have interrupts set up for the floppy? Wouldn't it be better to poll the results?

I will be putting code here eventually until building up a working driver, and if somebody has solutions, code snippets or exemplary code please post it. I will go and organize the skeletal driver code here to begin.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 31, 2007 10:30 pm 
Offline
Member
Member
User avatar

Joined: Thu Mar 08, 2007 11:08 am
Posts: 670
So mm.. you could set the DMA bit in DOR to 0 in order to disable interrupts and DMA, and then poll some registers.

I'd guess (too lazy to check) that you need to poll MSR, wait for MRQ bit to become 1, then read/write on FIFO, one byte at the time, to transfer data, followed by status.. but that's just speculation. Should check the manual.

The alternatives (as far as I understand) are either full PIO, PIO with interrupts, or DMA with interrupts. I don't see how (or why) it might support DMA without interrupts, since that'd be pretty insensible thing to do.

Ofcourse, you could probably just do generic ACKs for the interrupts, and poll some register (with high likelyhood MSR) on the controller to figure out when the DMA transfer is done, if you really one.

But.. like.. why not support interrupts?

_________________
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 31, 2007 10:31 pm 
Offline
Member
Member
User avatar

Joined: Thu Mar 08, 2007 11:08 am
Posts: 670
Oh and.. if you are writing in C, and you have a flag-variable which you set based on an interrupt, then make sure that variable is volatile. Just in case.

_________________
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 01, 2007 5:13 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 08, 2007 11:08 am
Posts: 670
Ok, since my floppy driver currently "works" as in the other Window there's Bochs which is currently reading track 1958/2880 quite happily, using DMA and interrupts, and what not, and since it was rather painful to find half decent documentation to figure out that stuff, with most examples being either seriously chaotic or in obfuscated assembler...

My driver currently supports the first drive in primary controller, assuming it's a 1.44MB 3.5" drive, with 1.44MB disk (80:2:18 format, 512 bytes/sector).

It is written in semimodular way, so adding support for more drives or more controllers, or whatever, shouldn't be huge amount of work. It has DMA routines basicly copypasted from the local Wiki (I found a bug there, have to remember to fix it), and is relatively heavily commented.

So before I go obfuscating it with how to recover from "fatal" error conditions, how to autodetect different types of media, how to check for media changes, and all that kind of stuff that makes source harder to read, I'm going to link the current version here.

It has not been testing on real hardware yet, and writing has not been tested at all yet, but since almost all code is shared by the read-code, I don't expect to find bugs there (there might be tons elsewhere though).

So here's a C example. It does require the ability to wait for interrupts though.

edit: attachment removed, nobody knows how the FDC works, but I know now: http://www.osdev.org/phpBB2/viewtopic.php?t=13524

_________________
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 01, 2007 7:31 pm 
Offline
Member
Member
User avatar

Joined: Tue Nov 09, 2004 12:00 am
Posts: 843
Location: United States
I have and have had a year or so ago the same exact problem. The MSR will sit with a value of 0x10 right after you issue the command, right? I just can not remember what I did to fix it exactly, but I have a good hunch.

Well. I stopped working on my floppy driver and started completing my clock multiplexer and scheduler since I do feel what is happened is the floppy controller wants to make a interrupt to let you know the command completed but like me you might be inside the interrupt handler since you might have issued a controller reset just like me and waited for the interrupt to tell you that the reset has completed. I know that with out having the 8259 PIT mask/enable the interrupt the floppy driver seems to not keep trying. It just tries once and stops. I think because the interrupt is already in service it just causes it to die.

So. I will know shortly when I get the kernel threads working, and instead of servicing the floppy controller from a interrupt I will just let it spawn a thread to handle it. I hope this fixes me problem too. *shrug*


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 07, 2007 8:39 pm 
Offline
Member
Member
User avatar

Joined: Tue Nov 09, 2004 12:00 am
Posts: 843
Location: United States
I took a look at the bochs source code for the floppy device, and through my attempts to get it working I do not feel short of being correct to say it just will not support directly reading the FIFO with the CPU. I had to use DMA go figure even though it is the best way.

The DMA needs Auto Increment, Single Mode, Write, and Channel 2 then issue the floppy command and it should go on it's own. Make sure you set the transfer length to (512-1)=511) when you configure the DMA channel. Giving it the value 512 will cause the interrupt to never occur.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 07, 2007 8:53 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
The 511 bytes is because numbering starts at 0 instead of 1 ie. 0,1,2,3....511 = 512 bytes, 1,2,3,4....,512 = 512 bytes.

_________________
Pedigree | GitHub | Twitter | LinkedIn


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 38 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