Patchwork fdc: simplify media change handling

login
register
mail settings
Submitter Hervé Poussineau
Date May 5, 2012, 5:43 p.m.
Message ID <1336239809-3958-1-git-send-email-hpoussin@reactos.org>
Download mbox | patch
Permalink /patch/157045/
State New
Headers show

Comments

Hervé Poussineau - May 5, 2012, 5:43 p.m.
This also (partly) fixes IBM OS/2 Warp 4.0 floppy installation, where
not all floppies have the same format (2x80x18 for the first ones,
2x80x23 for the next ones).

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---

This patch fixes a real use case, and I didn't notice any regression.
However, as we are in bugfixes-only period, I let Kevin decide if it
is worth to include (or not) this patch in QEMU 1.1.

 hw/fdc.c |   29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)
Kevin Wolf - May 7, 2012, 8:20 a.m.
Am 05.05.2012 19:43, schrieb Hervé Poussineau:
> This also (partly) fixes IBM OS/2 Warp 4.0 floppy installation, where
> not all floppies have the same format (2x80x18 for the first ones,
> 2x80x23 for the next ones).
> 
> Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
> ---
> 
> This patch fixes a real use case, and I didn't notice any regression.
> However, as we are in bugfixes-only period, I let Kevin decide if it
> is worth to include (or not) this patch in QEMU 1.1.
> 
>  hw/fdc.c |   29 +++++++++++------------------
>  1 file changed, 11 insertions(+), 18 deletions(-)

I think this patch still doesn't get it entirely right (it would also
reset the bit if the head didn't actually move because it already was in
the right position, whereas real hardware wouldn't reset it there), but
it looks much better than what we have today and provided it passes my
testing I would like to include it in 1.1.

With which OSes did you already test it?

Kevin
Hervé Poussineau - May 7, 2012, 7:14 p.m.
Kevin Wolf a écrit :
> Am 05.05.2012 19:43, schrieb Hervé Poussineau:
>> This also (partly) fixes IBM OS/2 Warp 4.0 floppy installation, where
>> not all floppies have the same format (2x80x18 for the first ones,
>> 2x80x23 for the next ones).
>>
>> Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
>> ---
>>
>> This patch fixes a real use case, and I didn't notice any regression.
>> However, as we are in bugfixes-only period, I let Kevin decide if it
>> is worth to include (or not) this patch in QEMU 1.1.
>>
>>  hw/fdc.c |   29 +++++++++++------------------
>>  1 file changed, 11 insertions(+), 18 deletions(-)
> 
> I think this patch still doesn't get it entirely right (it would also
> reset the bit if the head didn't actually move because it already was in
> the right position, whereas real hardware wouldn't reset it there), but
> it looks much better than what we have today and provided it passes my
> testing I would like to include it in 1.1.
> 
> With which OSes did you already test it?
> 

I specifically tested floppy change on MSDOS 6.22, Windows 98 SE and 
OS/2 4.0.

Hervé

Patch

diff --git a/hw/fdc.c b/hw/fdc.c
index a0236b7..bc0c3f6 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -702,6 +702,15 @@  static void fdctrl_raise_irq(FDCtrl *fdctrl, uint8_t status0)
         qemu_set_irq(fdctrl->irq, 1);
         fdctrl->sra |= FD_SRA_INTPEND;
     }
+    if (status0 & FD_SR0_SEEK) {
+        FDrive *cur_drv;
+        /* A seek clears the disk change line (if a disk is inserted) */
+        cur_drv = get_cur_drv(fdctrl);
+        if (cur_drv->max_track) {
+            cur_drv->media_changed = 0;
+        }
+    }
+
     fdctrl->reset_sensei = 0;
     fdctrl->status0 = status0;
     FLOPPY_DPRINTF("Set interrupt status to 0x%02x\n", fdctrl->status0);
@@ -933,23 +942,7 @@  static void fdctrl_write_ccr(FDCtrl *fdctrl, uint32_t value)
 
 static int fdctrl_media_changed(FDrive *drv)
 {
-    int ret;
-
-    if (!drv->bs)
-        return 0;
-    if (drv->media_changed) {
-        drv->media_changed = 0;
-        ret = 1;
-    } else {
-        ret = bdrv_media_changed(drv->bs);
-        if (ret < 0) {
-            ret = 0;            /* we don't know, assume no */
-        }
-    }
-    if (ret) {
-        fd_revalidate(drv);
-    }
-    return ret;
+    return drv->media_changed;
 }
 
 /* Digital input register : 0x07 (read-only) */
@@ -1853,6 +1846,7 @@  static void fdctrl_change_cb(void *opaque, bool load)
     FDrive *drive = opaque;
 
     drive->media_changed = 1;
+    fd_revalidate(drive);
 }
 
 static const BlockDevOps fdctrl_block_ops = {
@@ -1883,7 +1877,6 @@  static int fdctrl_connect_drives(FDCtrl *fdctrl)
         fd_init(drive);
         fd_revalidate(drive);
         if (drive->bs) {
-            drive->media_changed = 1;
             bdrv_set_dev_ops(drive->bs, &fdctrl_block_ops, drive);
         }
     }