qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Better floppy disk support
@ 2004-05-11 14:21 Mark Jonckheere
  2004-05-12 20:33 ` Fabrice Bellard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Jonckheere @ 2004-05-11 14:21 UTC (permalink / raw)
  To: qemu-devel

I propose some patches for better floppy disk support:

1. To make "tomsrtbt-2.0.103.ElTorito.288.img" bootable.

The first one is in fdc.c. It removes the test in fd_init(), since it
always forces the disk type to 1.44 MB, It is better to give the first
call to fd_revalidate() a chance to decide if it is a 1.44 or 2.88 drive.

2. To make my standalone chntpw-disk bootable (google for bd000607.zip).

Booting from bd000607.img gives a segmentation error. It seems that the
bootcode on this floppy (syslinux-ldlinux) does a word-length (16-bit)
INW at address 0x80 which was translated by function default_ioport_readw()
in a call to default_ioport_readb(NULL, 0x80) and read_page(NULL, 0x81).
The second function (in dma.c) needs a (dma_cont *) pointer as its first
parameter and segfaults when it tries to dereference the NULL-pointer.

To avoid this problem with word-length io-reads to two adjacent io-ports
from different or undefined devices it is best to translate it into two
readb calls each with its own opaque value. The function default_ioport_readw()
is not the most logical place for doing this, it is better to do this
upstream in the function cpu_inw().

I modified cpu_inw() and cpu_outw(), but the same problem could also
happen with cpu_inl() and cpu_outl().

3. To accept "--nics 0" as a legal argument.

Sometimes it can be usefull to install software without ethernet support.
I made a minor modification to accept 0 as a legal value for the argument
--nics. Since the default value remains 1, nothing changes for current usage.

greetings,
Mark.


diffs from cvs sources downloaded at 2004-05-10 11:41 (UTC) start here
---8<-------------------------------------------------------->8---
diff -wurb qemu/hw/fdc.c qemu-patched/hw/fdc.c
--- qemu/hw/fdc.c       Sat May  8 23:01:23 2004
+++ qemu-patched/hw/fdc.c       Mon May 10 18:18:35 2004
@@ -94,9 +94,9 @@
  {
      /* Drive */
      drv->bs = bs;
-    if (bs)
-        drv->drive = FDRIVE_DRV_144;
-    else
+//    if (bs)
+//        drv->drive = FDRIVE_DRV_144;
+//    else
          drv->drive = FDRIVE_DRV_NONE;
      drv->drflags = 0;
      drv->perpendicular = 0;
diff -wurb qemu/vl.c qemu-patched/vl.c
--- qemu/vl.c   Thu Apr 29 00:26:05 2004
+++ qemu-patched/vl.c   Tue May 11 14:49:07 2004
@@ -133,19 +133,19 @@
  #endif
  }

-/* default is to make two byte accesses */
  uint32_t default_ioport_readw(void *opaque, uint32_t address)
  {
-    uint32_t data;
-    data = ioport_read_table[0][address & (MAX_IOPORTS - 1)](opaque, address);
-    data |= ioport_read_table[0][(address + 1) & (MAX_IOPORTS - 1)](opaque, address + 1) << 8;
-    return data;
+#ifdef DEBUG_UNUSED_IOPORT
+    fprintf(stderr, "inw: port=0x%04x\n", address);
+#endif
+    return 0xffff;
  }

  void default_ioport_writew(void *opaque, uint32_t address, uint32_t data)
  {
-    ioport_write_table[0][address & (MAX_IOPORTS - 1)](opaque, address, data & 0xff);
-    ioport_write_table[0][(address + 1) & (MAX_IOPORTS - 1)](opaque, address + 1, (data >> 8) & 0xff);
+#ifdef DEBUG_UNUSED_IOPORT
+    fprintf(stderr, "outw: port=0x%04x data=0x%04x\n", address, data);
+#endif
  }

  uint32_t default_ioport_readl(void *opaque, uint32_t address)
@@ -159,7 +159,7 @@
  void default_ioport_writel(void *opaque, uint32_t address, uint32_t data)
  {
  #ifdef DEBUG_UNUSED_IOPORT
-    fprintf(stderr, "outl: port=0x%04x data=0x%02x\n", address, data);
+    fprintf(stderr, "outl: port=0x%04x data=0x%08x\n", address, data);
  #endif
  }

@@ -279,8 +279,18 @@

  void cpu_outw(CPUState *env, int addr, int val)
  {
+    IOPortWriteFunc *writefunc;
+
      addr &= (MAX_IOPORTS - 1);
-    ioport_write_table[1][addr](ioport_opaque[addr], addr, val);
+    writefunc = ioport_write_table[1][addr];
+    if ( writefunc != default_ioport_writew &&
+            (ioport_write_table[0][addr] == ioport_write_table[0][addr + 1]))
+        writefunc(ioport_opaque[addr], addr, val);
+    else {
+        ioport_write_table[0][addr](ioport_opaque[addr], addr, val & 0xff);
+        ioport_write_table[0][addr + 1](ioport_opaque[addr + 1],
+                addr + 1, (val >> 8 ) & 0xff);
+    }
  }

  void cpu_outl(CPUState *env, int addr, int val)
@@ -297,8 +307,16 @@

  int cpu_inw(CPUState *env, int addr)
  {
+    IOPortReadFunc *readfunc;
+
      addr &= (MAX_IOPORTS - 1);
-    return ioport_read_table[1][addr](ioport_opaque[addr], addr);
+    readfunc = ioport_read_table[1][addr];
+    if ( readfunc != default_ioport_readw &&
+            (ioport_read_table[0][addr] == ioport_read_table[0][addr + 1]))
+        return readfunc(ioport_opaque[addr], addr);
+    else
+        return ioport_read_table[0][addr](ioport_opaque[addr], addr) |
+            (ioport_read_table[0][addr+1](ioport_opaque[addr+1], addr+1) << 8);
  }

  int cpu_inl(CPUState *env, int addr)
@@ -2008,7 +2026,7 @@
                  break;
              case 16:
                  nb_nics = atoi(optarg);
-                if (nb_nics < 1 || nb_nics > MAX_NICS) {
+                if (nb_nics < 0 || nb_nics > MAX_NICS) {
                      fprintf(stderr, "qemu: invalid number of network interfaces\n");
                      exit(1);
                  }
---8<-------------------------------------------------------->8---

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] Better floppy disk support
  2004-05-11 14:21 [Qemu-devel] Better floppy disk support Mark Jonckheere
@ 2004-05-12 20:33 ` Fabrice Bellard
  0 siblings, 0 replies; 2+ messages in thread
From: Fabrice Bellard @ 2004-05-12 20:33 UTC (permalink / raw)
  To: qemu-devel

Mark Jonckheere wrote:
> I propose some patches for better floppy disk support:
> 
> 1. To make "tomsrtbt-2.0.103.ElTorito.288.img" bootable.
> 
> The first one is in fdc.c. It removes the test in fd_init(), since it
> always forces the disk type to 1.44 MB, It is better to give the first
> call to fd_revalidate() a chance to decide if it is a 1.44 or 2.88 drive.

This is incorrect as the BIOS configuration will be invalid. I think it 
is better to probe the disk image size in fd_init (just to select 
between 1.44 and 2.88 drives).

> 2. To make my standalone chntpw-disk bootable (google for bd000607.zip).
> 
> Booting from bd000607.img gives a segmentation error. It seems that the
> bootcode on this floppy (syslinux-ldlinux) does a word-length (16-bit)
> INW at address 0x80 which was translated by function default_ioport_readw()
> in a call to default_ioport_readb(NULL, 0x80) and read_page(NULL, 0x81).
> The second function (in dma.c) needs a (dma_cont *) pointer as its first
> parameter and segfaults when it tries to dereference the NULL-pointer.
> 
> To avoid this problem with word-length io-reads to two adjacent io-ports
> from different or undefined devices it is best to translate it into two
> readb calls each with its own opaque value. The function 
> default_ioport_readw()
> is not the most logical place for doing this, it is better to do this
> upstream in the function cpu_inw().
> 
> I modified cpu_inw() and cpu_outw(), but the same problem could also
> happen with cpu_inl() and cpu_outl().

I have commited a slightly different patch (your patch breaks 16 bit 
I/Os and is too slow).

> 3. To accept "--nics 0" as a legal argument.
> 
> Sometimes it can be usefull to install software without ethernet support.
> I made a minor modification to accept 0 as a legal value for the argument
> --nics. Since the default value remains 1, nothing changes for current 
> usage.

OK.

Fabrice.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-05-12 20:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-11 14:21 [Qemu-devel] Better floppy disk support Mark Jonckheere
2004-05-12 20:33 ` Fabrice Bellard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).