[Patch] Floppy emulation on old Linux kernels

Post Reply
micronix
Posts: 3
Joined: Mon 22 Jan, 2018 11:55 am

[Patch] Floppy emulation on old Linux kernels

Post by micronix » Wed 24 Jan, 2018 8:29 am

Hi guys,

I noticed some time ago, that some old versions of the Linux kernel freeze in floppy drive detection.
I know that these kernels run fine on older versions of PCem, so I tried to locate the exact change in the PCem code which causes this bug.

These old Linux kernels started to freeze after this change in fdc.c:
https://bitbucket.org/pcem_emulator/pce ... at=default

To know whats going on, I enabled some of the pclog lines in fdc.c and I got this:

Code: Select all

Write FDC 03F2 04 C000000: 24864983 00 24864983 rate=0  0
Write FDC 03F2 0C C000000: 24865044 00 24865044 rate=0  0
Write FDC 03F2 0C C000000: 24865233 00 24865233 rate=0  0
Write FDC 03F2 08 C000000: 24865996 00 24865996 rate=0  0
Write FDC 03F2 0C C000000: 24866016 00 24866016 rate=0  0
Reset FDC
fdc_callback -1 0
Write FDC 03F5 08 C000000: 24866231 00 24866231 rate=0  0
Starting FDC command 08
fdc_callback 8 0
Sense interrupt status 4
Read param 9 C0
Read param 10 1B
Write FDC 03F5 08 C000000: 24866392 00 24866392 rate=0  0
Starting FDC command 08
fdc_callback 8 0
Sense interrupt status 3
Read param 9 C1
Read param 10 1B
Write FDC 03F5 08 C000000: 24866459 00 24866459 rate=0  0
Starting FDC command 08
fdc_callback 8 0
Sense interrupt status 2
Read param 9 C2
Read param 10 1B                                                                                                                                                                              
Write FDC 03F5 08 C000000: 24866488 00 24866488 rate=0  0                                                                                                                                     
Starting FDC command 08                                                                                                                                                                       
fdc_callback 8 0                                                                                                                                                                              
Sense interrupt status 1                                                                                                                                                                      
Read param 9 C3                                                                                                                                                                               
Read param 10 1B                                                                                                                                                                              
Write FDC 03F5 08 C000000: 24866503 80 24866503 rate=0  0                                                                                                                                     
Starting FDC command 08                                                                                                                                                                       
fdc_callback 8 0
Sense interrupt status 0
Read param 9 80
Read param 10 1B
Write FDC 03F5 08 C000000: 24866503 80 24866503 rate=0  0
Starting FDC command 08
fdc_callback 8 0
Sense interrupt status 0
Read param 9 80
Read param 10 1B
Write FDC 03F5 08 C000000: 24866503 80 24866503 rate=0  0
Starting FDC command 08
fdc_callback 8 0
Sense interrupt status 0
Read param 9 80
Read param 10 1B
The last 6 lines are repeating over and over, so it seems like the kernel is stuck in an endless loop.

After reverting the change in fdc.c, the kernel boots again. I don't know why this change causes this behavior since the code seems to be equal.

Anyways, I attached a patch. After this patch, these old kernels are no longer stuck in the floppy drive detection and boot successfully again.

Edit:
The code is not equal, if fdc_reset_stat is 1.
Attachments
floppypatch.diff.txt
(562 Bytes) Downloaded 64 times

User avatar
SarahWalker
Site Admin
Posts: 1580
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Patch] Floppy emulation on old Linux kernels

Post by SarahWalker » Thu 25 Jan, 2018 8:17 pm

This breaks the MR 386DX clone, which is why the change was originally made. Doing some digging to find out what's going on...

micronix
Posts: 3
Joined: Mon 22 Jan, 2018 11:55 am

Re: [Patch] Floppy emulation on old Linux kernels

Post by micronix » Thu 25 Jan, 2018 9:12 pm

I don't know if this helps, but I compared the floppy driver source code (drivers/block/floppy.c) of the affected kernel version 2.0.27 and the unaffected version 2.0.40.
In 2.0.40 there is a variable in the floppy interrupt handler which limits the maximum number of loops.
I attached the relevant code.

OT: I can't put this code in the post (in code tags) because I get a HTTP 403 and after trying two times it looks like my IP gets temporary banned.
Attachments
floppy.txt
(643 Bytes) Downloaded 33 times

User avatar
SarahWalker
Site Admin
Posts: 1580
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Patch] Floppy emulation on old Linux kernels

Post by SarahWalker » Thu 25 Jan, 2018 10:17 pm

Done some testing now. MR BIOS and Linux 2.0.27 differ in what they expect to read as FDC Status 0 following an FDC reset. MR BIOS expects to read 0x80 within 5 Sense Interrupt Status commands. Linux expects to read 0x00 in an undetermined number of SIS commands. I've done some testing on a real machine, and following a reset the FDC returns 0xCx 4 times (due to drive ready polling), then just returns 0x80 - which is what PCem currently does. Linux 2.0.27 does boot on this machine though, so there's clearly something else going on here.

User avatar
SarahWalker
Site Admin
Posts: 1580
Joined: Thu 24 Apr, 2014 4:18 pm

Re: [Patch] Floppy emulation on old Linux kernels

Post by SarahWalker » Fri 26 Jan, 2018 9:32 pm

Fixed in rev 1008.

teppic
Posts: 42
Joined: Tue 20 Jun, 2017 12:31 pm

Re: [Patch] Floppy emulation on old Linux kernels

Post by teppic » Sat 27 Jan, 2018 8:24 am

Yay, great work.

Post Reply