Floppy driver trouble: works on Virtual PC, but not Bochs

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
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Floppy driver trouble: works on Virtual PC, but not Bochs

Post by chibicitiberiu »

Hello, I have some trouble with my floppy driver. It works perfectly in Microsoft Virtual PC 2007, but in Bochs, it fails. Says (when reading) that motor is off, and a command is issued before another one is completed, so two panics. When writing, only get 'motor is not on'. But the motors are on, and I have irq set properly (i think). What could be wrong with it?

Could the inline-implemented-sleep function(s) fail for some reason? Could this be a time-out related issue?
Can anyone test this on real hardware, and report other bugs/issues?
(have some LCD trouble with my desktop PC, had to replace it with the testbed's CRT, and it's really hard to switch them back. And my laptop which is my working machine unfortunately doesn't have floppy.)

Theoretically, the driver should work with these types of 3.5" floppies: 720K, 1.44M and 2.88M, any other format/size unsupported.


I'm uploading the OS floppy image, and the floppy code, if you need any additional code, or information feel free to ask.
floppy.c
(11.8 KiB) Downloaded 50 times
ctaos.zip
OS image. Type "help" in the prompt for a a list of available commands. The floppy "read" command reads all the sectors in the floppy, so you should call "read 0" so it doesn't try to read off the disk. Initially wasn't like this, but I changed it for debugging & testing. And "write" writes two sectors, one with a value, one with another... this was to test if it can write properly multiple sectors.
(42.28 KiB) Downloaded 34 times
Thank you very much for your help and your time in advance.

UPDATE: these are the panics that I get from bochs when reading:
00287403665p[FDD ] >>PANIC<< floppy_command(): read/write: motor not on
00299368482p[FDD ] >>PANIC<< write 0x03f5: receiving new command 0x08, old one (0xc6) pending
So it's trying to read before finishing with the Sense command.
Tibi,
Currently working on the Lux Operating System
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: Floppy driver trouble: works on Virtual PC, but not Boch

Post by chibicitiberiu »

Updates: I found a bug in the floppy write function, it was setting up DMA for read and not write.
But that didn't solve the issues :cry: and I can't figure out why is this thing not working properly in bochs. I tried increasing the motor spinup time to half a second, setting many other delays, etc... but just won't work. I'm out of ideas...
Please help.......
Tibi,
Currently working on the Lux Operating System
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: Floppy driver trouble: works on Virtual PC, but not Boch

Post by chibicitiberiu »

Update: I finally found the bug that was giving the "motor not on" error.

It was in the floppy select function

Code: Select all

      if (drive >= FloppyDrivesInstalled) return;

      unsigned char dor = inportb(FloppyRegDOR) & 0xf0   // !!! THIS

      // Send mechanical drive data
      FloppyDriveData(drive, 1);

      // Select drive in DOR register
      outportb (FloppyRegDOR, dor | 4 | 8 | drive); // !!! AND THIS
The old code would outport only 4|8|drive, so the motor bits were lost.

But the second panic message still appears:
00299368482p[FDD ] >>PANIC<< write 0x03f5: receiving new command 0x08, old one (0xc6) pending

Why could it be appearing? Can anyone explain? So basically it's saying while it's reading (0x06), I'm sending command 0x08 (sense). But IRQ6 isn't triggered when it is time? Could Bochs' weird really fast clock be a problem here, because in theory it should wait up to 3 seconds before timeout? (in bochs 3 seconds pass in like .5)
Tibi,
Currently working on the Lux Operating System
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Floppy driver trouble: works on Virtual PC, but not Boch

Post by Combuster »

If you (mis)configured bochs so that time goes slower, then so does the time for the FDD and all timers within the system.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: Floppy driver trouble: works on Virtual PC, but not Boch

Post by chibicitiberiu »

Found yet another bug, I wasn't reading all the result bytes with the condition I put there, but still... that didn't solve the problem. Also I eliminated sense command after every read/write operation, but still doesn't work.

My head is starting to hurt... just can't find that error that is causing all this trouble. #-o
I'm uploading the latest bugfixed version, hope it helps.

The error I get is becoming really weird. It says that I issue command 0x03 before it finishes read operation, but I don't even have that in the updated code. I issue command 0x03 before reading the sectors, and then I start reading. It's really weird.


I struck another problem as well... I can't build it any more, windows 98 doesn't recognize correctly any more the file structure of the shared folder, it's a really weird problem. I don't have floppy on my laptop, and I've been using a virtual pc to build directly to .img floppies. I will find a solution eventually, but will take some time.
Attachments
floppy.c
(12.71 KiB) Downloaded 45 times
Tibi,
Currently working on the Lux Operating System
Post Reply