Skip to contentSkip to conversation

hw/m68k: add working floppy controller for q800

PATCH In review Matt Jacobson 3 participants 12 messages Jul 2 – Jul 5 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v3 cover hw/m68k: add working floppy controller for q800

Implement the SWIM2 floppy controller and SuperDrive for the q800 machine.

Reading and writing work, and booting a system disk works. Both GCR and MFM paths work.
Tested with the Quadra 800 ROM running System 7 and A/UX 3.x. Whole-disk formatting/duplication does not yet work.

Example usage:

$ qemu-system-m68k \
   -machine q800 \
   -m 128 \
   -bios "Quadra800.ROM" \
   -nodefaults \
   -drive if=mtd,file="pram.img",format=raw \
   -drive if=floppy \
   -drive if=floppy \
   -drive if=scsi,media=disk,file="harddisk.img",format=raw \
   -drive if=scsi,media=cdrom \
   -nic user,model=dp83932 \
   -audio none \
   -display cocoa \
   -name "Macintosh Quadra 800"

(To populate the floppy drive at boot, use
-drive if=floppy,file="floppy.img",format=raw. However, note that the Macintosh ROM will eject non-bootable floppies on boot.)

The Sony drive emulator takes raw images and will generate the GCR/MFM encoding on the fly. Here are a couple sample images (HFS) to play with:

<https://mjacobson.net/files/mac-disks/floppy-800.img>
<https://mjacobson.net/files/mac-disks/floppy-1440.img>

Matt Jacobson (5):
hw/block: add Sony/Apple "SuperDrive" diskette drive
fifo32: add fifo32_peek()
hw/block: add SWIM2 floppy controller for q800 hw/m68k: add working floppy controller for q800 hw/block: remove unused SWIM1 floppy controller stub

 MAINTAINERS                        |    2 -
 hw/block/meson.build               |    2 +-
 hw/block/sony_superdrive.c         | 1032 ++++++++++++++++++++++++++++
 hw/block/swim.c                    |  577 ----------------
 hw/block/swim2.c                   |  711 +++++++++++++++++++
 hw/block/trace-events              |   25 +-
 hw/m68k/q800.c                     |    5 +-
 hw/misc/mac_via.c                  |   16 +
 include/hw/block/sony_superdrive.h |   55 ++
 include/hw/block/swim.h            |   72 --
 include/hw/block/swim2.h           |   58 ++
 include/hw/m68k/q800.h             |    4 +-
 include/hw/misc/mac_via.h          |    3 +
 include/qemu/fifo32.h              |   31 +-
 14 files changed, 1923 insertions(+), 670 deletions(-)
 create mode 100644 hw/block/sony_superdrive.c
 delete mode 100644 hw/block/swim.c
 create mode 100644 hw/block/swim2.c
 create mode 100644 include/hw/block/sony_superdrive.h
 delete mode 100644 include/hw/block/swim.h
 create mode 100644 include/hw/block/swim2.h
Signature · 1 line
2.54.0
#1 lore raw

PATCH v3 1/5 hw/block: add Sony/Apple "SuperDrive" diskette drive

The Mac Quadra 800 contains a "SuperDrive" floppy drive that supports both GCR (400 kB and 800 kB) and MFM (720 kB and 1440 kB) diskettes. Implement an emulated version, to be controlled by a forthcoming SWIM2 device.

For GCR, the emulated drive encodes the BlockBackend's data in the Apple GCR format and exposes it to the controller via sony_drive_read_byte(). The bytes are decoded not by the controller but rather in software by the Macintosh ".Sony" driver. The drive also adds the sync bytes and addressing marks that software expects.

For MFM, much less encoding is needed. The sector data passes through from the BlockBackend unmodified, and the drive only adds sync bytes and addresssing marks.

---
 hw/block/meson.build               |    2 +-
 hw/block/sony_superdrive.c         | 1032 ++++++++++++++++++++++++++++
 hw/block/trace-events              |   10 +
 include/hw/block/sony_superdrive.h |   55 ++
 4 files changed, 1098 insertions(+), 1 deletion(-)
 create mode 100644 hw/block/sony_superdrive.c
 create mode 100644 include/hw/block/sony_superdrive.h
hw/block/meson.build +1 -1
index d646323b82..c4b873a906 100644
@@ -10,7 +10,7 @@ system_ss.add(when: 'CONFIG_PFLASH_CFI01', if_true: files('pflash_cfi01.c'))
 system_ss.add(when: 'CONFIG_PFLASH_CFI02', if_true: files('pflash_cfi02.c'))
 system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80.c'))
 system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80_sfdp.c'))
-system_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c'))
+system_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c', 'sony_superdrive.c'))
 system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-block.c'))
 
 system_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c'))
hw/block/sony_superdrive.c new file +1032 -0

1,032 lines not on this page · raw message

hw/block/trace-events +10 -0
index dbaa5ca6cb..c5e021738c 100644
@@ -111,3 +111,13 @@ swim_iwmctrl_read(int reg, const char *name, unsigned size, uint64_t value) "reg
 swim_iwmctrl_write(int reg, const char *name, unsigned size, uint64_t value) "reg=%d [%s] size=%u value=0x%"PRIx64
 swim_switch_to_ism(void) "switch from IWM to ISM mode"
 swim_switch_to_iwm(void) "switch from ISM to IWM mode"
+
+# sony_superdrive.c
+sony_drive_prepare(void *drive, uint8_t track, uint8_t head, uint8_t sector, bool gcr, uint16_t payload_len) "drive=%p track=%"PRIu8" head=%"PRIu8" sector=%"PRIu8" gcr=%d length=%"PRIu16
+sony_drive_persist(void *drive, uint64_t lba, bool success) "drive=%p lba=0x%"PRIx64" success=%d"
+sony_drive_strobe(void *drive, uint8_t command, const char *name) "drive=%p cmd=0x%02"PRIx8" [%s]"
+sony_drive_read_sense(void *drive, uint8_t reg, const char *name, bool value) "drive=%p reg=0x%02"PRIx8" [%s] value=%d"
+sony_drive_set_inputs(void *drive, uint8_t phases, bool sel, bool enabled) "drive=%p phases=0x%"PRIx8" sel=%d enabled=%d"
+sony_drive_read_byte(void *drive, uint8_t value, bool is_mark, uint64_t lba, uint16_t position) "drive=%p value=0x%02"PRIx8", is_mark=%d, lba=0x%"PRIx64", position=0x%"PRIx16
+sony_drive_write_byte(void *drive, uint8_t value, uint64_t lba, uint16_t position) "drive=%p value=0x%02"PRIx8", lba=0x%"PRIx64", position=0x%"PRIx16
+sony_drive_step(void *drive, uint8_t seek_direction, uint8_t current_track) "drive=%p direction=%"PRId8", track=%"PRId8
include/hw/block/sony_superdrive.h new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
2.54.0
Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] hw/block: add Sony/Apple "SuperDrive" diskette drive

Quoted 11 lines · Matt Jacobson

The Mac Quadra 800 contains a "SuperDrive" floppy drive that supports both GCR (400 kB and 800 kB) and MFM (720 kB and 1440 kB) diskettes. Implement an emulated version, to be controlled by a forthcoming SWIM2 device.

For GCR, the emulated drive encodes the BlockBackend's data in the Apple GCR format and exposes it to the controller via sony_drive_read_byte(). The bytes are decoded not by the controller but rather in software by the Macintosh ".Sony" driver. The drive also adds the sync bytes and addressing marks that software expects.

Quoted 3 lines

For MFM, much less encoding is needed. The sector data passes through from the BlockBackend unmodified, and the drive only adds sync bytes and addresssing marks.

Maybe these last two paragraphs explaining theory of operation could go in a comment but which is easier to see than looking up a commit message but I'm OK with it either way.

Quoted 1 line

I can't tell if all of it is correct but looks reasonable to me so

#3 lore raw

Re: [PATCH v3 1/5] hw/block: add Sony/Apple "SuperDrive" diskette drive

Quoted 12 lines · BALATON Zoltan
Quoted 6 lines · Matt Jacobson

For GCR, the emulated drive encodes the BlockBackend's data in the Apple GCR format and exposes it to the controller via sony_drive_read_byte(). The bytes are decoded not by the controller but rather in software by the Macintosh ".Sony" driver. The drive also adds the sync bytes and addressing marks that software expects.

Quoted 5 lines
Quoted 3 lines

For MFM, much less encoding is needed. The sector data passes through from the BlockBackend unmodified, and the drive only adds sync bytes and addresssing marks.

Maybe these last two paragraphs explaining theory of operation could go in a comment but which is easier to see than looking up a commit message but I'm OK with it either way.

Will do in v4.

Thanks,

Matt

#4 lore raw

PATCH v3 2/5 fifo32: add fifo32_peek()

In reply to Matt Jacobson

Add fifo32_peek(), which, like the other Fifo32 functions, ultimately just delegates to the Fifo8 code.

Adjust fifo32_pop() to use ldl_le_p() too.

---
 include/qemu/fifo32.h | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
include/qemu/fifo32.h +24 -7
index 4e9fd1b5ef..4e8b739a1e 100644
@@ -15,6 +15,7 @@
 #ifndef FIFO32_H
 #define FIFO32_H
 
+#include "qemu/bswap.h"
 #include "qemu/fifo8.h"
 
 typedef struct {
@@ -117,6 +118,25 @@ static inline void fifo32_push_all(Fifo32 *fifo, const uint32_t *data,
     }
 }
 
+/**
+ * fifo32_peek:
+ * @fifo: fifo to peek from
+ *
+ * Peek the data word at the current head of the FIFO. Clients are responsible
+ * for checking for emptiness using fifo32_is_empty().
+ *
+ * Returns: The peeked 32 bits data word.
+ */
+
+static inline uint32_t fifo32_peek(Fifo32 *fifo)
+{
+    uint8_t bytes[sizeof(uint32_t)];
+    uint32_t read = fifo8_peek_buf(&fifo->fifo, bytes, sizeof(bytes));
+    assert(read == sizeof(bytes));
+
+    return ldl_le_p(bytes);
+}
+
 /**
  * fifo32_pop:
  * @fifo: fifo to pop from
@@ -130,14 +150,11 @@ static inline void fifo32_push_all(Fifo32 *fifo, const uint32_t *data,
 
 static inline uint32_t fifo32_pop(Fifo32 *fifo)
 {
-    uint32_t ret = 0;
-    int i;
-
-    for (i = 0; i < sizeof(uint32_t); i++) {
-        ret |= (fifo8_pop(&fifo->fifo) << (i * 8));
-    }
+    uint8_t bytes[sizeof(uint32_t)];
+    uint32_t popped = fifo8_pop_buf(&fifo->fifo, bytes, sizeof(bytes));
+    assert(popped == sizeof(bytes));
 
-    return ret;
+    return ldl_le_p(bytes);
 }
 
 /**
Signature · 1 line
2.54.0
#5 lore raw

PATCH v3 3/5 hw/block: add SWIM2 floppy controller for q800

In reply to Matt Jacobson

The Quadra 800 contains a SWIM2 floppy controller, which is a simplified revision of the original SWIM controller. Implement it based on publicly available specs; a future commit will connect it to q800.

---
 hw/block/meson.build     |   2 +-
 hw/block/swim2.c         | 711 +++++++++++++++++++++++++++++++++++++++
 hw/block/trace-events    |   9 +
 include/hw/block/swim2.h |  58 ++++
 4 files changed, 779 insertions(+), 1 deletion(-)
 create mode 100644 hw/block/swim2.c
 create mode 100644 include/hw/block/swim2.h
hw/block/meson.build +1 -1
index c4b873a906..733e9ffb47 100644
@@ -10,7 +10,7 @@ system_ss.add(when: 'CONFIG_PFLASH_CFI01', if_true: files('pflash_cfi01.c'))
 system_ss.add(when: 'CONFIG_PFLASH_CFI02', if_true: files('pflash_cfi02.c'))
 system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80.c'))
 system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80_sfdp.c'))
-system_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c', 'sony_superdrive.c'))
+system_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c', 'swim2.c', 'sony_superdrive.c'))
 system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-block.c'))
 
 system_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c'))
hw/block/swim2.c new file +711 -0

711 lines not on this page · raw message

hw/block/trace-events +9 -0
index c5e021738c..c5793c7da8 100644
@@ -112,6 +112,15 @@ swim_iwmctrl_write(int reg, const char *name, unsigned size, uint64_t value) "re
 swim_switch_to_ism(void) "switch from IWM to ISM mode"
 swim_switch_to_iwm(void) "switch from ISM to IWM mode"
 
+# swim2.c
+swim2_mmio_read(uint64_t addr, unsigned size, int reg, const char *name, uint64_t value, uint8_t mode, uint8_t setup, uint8_t phase, uint32_t fifo_count) "addr=0x%"PRIx64" size=%u reg=%d [%s] value=0x%"PRIx64" mode=0x%02x setup=0x%02x phase=0x%02x fifo=%u"
+swim2_mmio_write(uint64_t addr, unsigned size, int reg, const char *name, uint64_t value, uint8_t mode, uint8_t setup, uint8_t phase, uint32_t fifo_count) "addr=0x%"PRIx64" size=%u reg=%d [%s] value=0x%"PRIx64" mode=0x%02x setup=0x%02x phase=0x%02x fifo=%u"
+swim2_fifo_push(uint32_t count, uint8_t data, uint8_t flags) "fifo=%u data=0x%02x flags=0x%02x"
+swim2_fifo_pop(uint32_t count, uint8_t data, uint8_t flags, bool success) "fifo=%u data=0x%02x flags=0x%02x success=%d"
+swim2_fifo_clear(void) "clear FIFO"
+swim2_set_sel(bool sel) "set sel=%d"
+swim2_error_set(uint8_t prev, uint8_t curr, uint8_t new_err, uint8_t mode, bool write_mode, uint32_t fifo_count) "prev=0x%02x curr=0x%02x new=0x%02x mode=0x%02x write=%d fifo=%u"
+
 # sony_superdrive.c
 sony_drive_prepare(void *drive, uint8_t track, uint8_t head, uint8_t sector, bool gcr, uint16_t payload_len) "drive=%p track=%"PRIu8" head=%"PRIu8" sector=%"PRIu8" gcr=%d length=%"PRIu16
 sony_drive_persist(void *drive, uint64_t lba, bool success) "drive=%p lba=0x%"PRIx64" success=%d"
include/hw/block/swim2.h new file +58 -0

58 lines not on this page · raw message

Signature · 1 line
2.54.0
#6 lore raw

PATCH v3 4/5 hw/m68k: add working floppy controller for q800

In reply to Matt Jacobson

Switch the Quadra 800 machine to the working SWIM2 floppy controller. Hook up the HeadSel bit on the VIA to control the head selection (the IWM does not handle this part itself).

---
 hw/m68k/q800.c            |  5 +++--
 hw/misc/mac_via.c         | 16 ++++++++++++++++
 include/hw/m68k/q800.h    |  4 ++--
 include/hw/misc/mac_via.h |  3 +++
 4 files changed, 24 insertions(+), 4 deletions(-)
hw/m68k/q800.c +3 -2
index ab64250c47..a6997ef802 100644
@@ -47,7 +47,7 @@
 #include "hw/audio/asc.h"
 #include "hw/nubus/mac-nubus-bridge.h"
 #include "hw/display/macfb.h"
-#include "hw/block/swim.h"
+#include "hw/block/swim2.h"
 #include "net/net.h"
 #include "net/util.h"
 #include "qapi/error.h"
@@ -338,6 +338,7 @@ static void q800_machine_init(MachineState *machine)
     /* VIA 1 */
     object_initialize_child(OBJECT(machine), "via1", &m->via1,
                             TYPE_MOS6522_Q800_VIA1);
+    m->via1.swim = &m->swim;
     dinfo = drive_get(IF_MTD, 0, 0);
     if (dinfo) {
         qdev_prop_set_drive(DEVICE(&m->via1), "drive",
@@ -511,7 +512,7 @@ static void q800_machine_init(MachineState *machine)
     /* SWIM floppy controller */
 
     object_initialize_child(OBJECT(machine), "swim", &m->swim,
-                            TYPE_SWIM);
+                            TYPE_SWIM2);
     sysbus = SYS_BUS_DEVICE(&m->swim);
     sysbus_realize(sysbus, &error_fatal);
     memory_region_add_subregion(&m->macio, SWIM_BASE - IO_BASE,
hw/misc/mac_via.c +16 -0
index 26ee230dcc..09197fe519 100644
@@ -31,6 +31,7 @@
 #include "hw/core/qdev-properties-system.h"
 #include "system/block-backend.h"
 #include "system/rtc.h"
+#include "hw/block/swim2.h"
 #include "trace.h"
 #include "qemu/log.h"
 
@@ -1080,6 +1081,17 @@ static void mos6522_q800_via1_write(void *opaque, hwaddr addr, uint64_t val,
     mos6522_write(ms, addr, val, size);
 
     switch (addr) {
+    case VIA_REG_A:
+    case VIA_REG_ANH: {
+        const bool sel = (ms->a & VIA1A_vHeadSel) != 0;
+
+        if (v1s->swim) {
+            swim2_set_sel(v1s->swim, sel);
+        }
+
+        break;
+    }
+
     case VIA_REG_B:
         via1_rtc_update(v1s);
         via1_adb_update(v1s);
@@ -1224,6 +1236,10 @@ static void mos6522_q800_via1_reset_hold(Object *obj, ResetType type)
 
     /* Timer calibration hack */
     v1s->timer_hack_state = 0;
+
+    if (v1s->swim) {
+        swim2_set_sel(v1s->swim, false);
+    }
 }
 
 static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
include/hw/m68k/q800.h +2 -2
index 77551b9592..2a20314d57 100644
@@ -33,7 +33,7 @@
 #include "hw/char/escc.h"
 #include "hw/core/or-irq.h"
 #include "hw/scsi/esp.h"
-#include "hw/block/swim.h"
+#include "hw/block/swim2.h"
 #include "hw/nubus/mac-nubus-bridge.h"
 #include "hw/display/macfb.h"
 #include "hw/misc/djmemc.h"
@@ -59,7 +59,7 @@ struct Q800MachineState {
     ESCCState escc;
     OrIRQState escc_orgate;
     SysBusESPState esp;
-    Swim swim;
+    SWIM2State swim;
     MacNubusBridge mac_nubus_bridge;
     MacfbNubusState macfb;
     DJMEMCState djmemc;
include/hw/misc/mac_via.h +3 -0
index 114f41db4c..e23735b47c 100644
@@ -13,6 +13,7 @@
 #include "hw/core/sysbus.h"
 #include "hw/misc/mos6522.h"
 #include "hw/input/adb.h"
+#include "hw/block/swim2.h"
 #include "qom/object.h"
 
 
@@ -77,6 +78,8 @@ struct MOS6522Q800VIA1State {
 
     /* SETUPTIMEK hack */
     int timer_hack_state;
+
+    SWIM2State *swim;
 };
 
 
Signature · 1 line
2.54.0
#7 lore raw
Quoted 26 lines · Matt Jacobson

Switch the Quadra 800 machine to the working SWIM2 floppy controller. Hook up the HeadSel bit on the VIA to control the head selection (the IWM does not handle this part itself).

---
  hw/m68k/q800.c            |  5 +++--
  hw/misc/mac_via.c         | 16 ++++++++++++++++
  include/hw/m68k/q800.h    |  4 ++--
  include/hw/misc/mac_via.h |  3 +++
  4 files changed, 24 insertions(+), 4 deletions(-)
hw/m68k/q800.c +1 -1
index ab64250c47..a6997ef802 100644
@@ -47,7 +47,7 @@
  #include "hw/audio/asc.h"
  #include "hw/nubus/mac-nubus-bridge.h"
  #include "hw/display/macfb.h"
-#include "hw/block/swim.h"
+#include "hw/block/swim2.h"
  #include "net/net.h"
  #include "net/util.h"
  #include "qapi/error.h"

hw/m68k/q800.c static void q800_machine_init(MachineState *machine) · line 341

Quoted 4 lines
hw/m68k/q800.c +1 -0
@@ -338,6 +338,7 @@ static void q800_machine_init(MachineState *machine)
      /* VIA 1 */
      object_initialize_child(OBJECT(machine), "via1", &m->via1,
                              TYPE_MOS6522_Q800_VIA1);
+    m->via1.swim = &m->swim;

This doesn't look right: in general we should avoid accessing a device state struct directly unless it is absolutely unavoidable.

Quoted 28 lines
hw/m68k/q800.c +1 -1
      dinfo = drive_get(IF_MTD, 0, 0);
      if (dinfo) {
          qdev_prop_set_drive(DEVICE(&m->via1), "drive",
@@ -511,7 +512,7 @@ static void q800_machine_init(MachineState *machine)
      /* SWIM floppy controller */
 
      object_initialize_child(OBJECT(machine), "swim", &m->swim,
-                            TYPE_SWIM);
+                            TYPE_SWIM2);
      sysbus = SYS_BUS_DEVICE(&m->swim);
      sysbus_realize(sysbus, &error_fatal);
      memory_region_add_subregion(&m->macio, SWIM_BASE - IO_BASE,
hw/misc/mac_via.c +1 -0
index 26ee230dcc..09197fe519 100644
@@ -31,6 +31,7 @@
  #include "hw/core/qdev-properties-system.h"
  #include "system/block-backend.h"
  #include "system/rtc.h"
+#include "hw/block/swim2.h"
  #include "trace.h"
  #include "qemu/log.h"
 
@@ -1080,6 +1081,17 @@ static void mos6522_q800_via1_write(void *opaque, hwaddr addr, uint64_t val,
      mos6522_write(ms, addr, val, size);
 
      switch (addr) {

hw/misc/mac_via.c static void mos6522_q800_via1_write(void *opaque, hwaddr addr, uint64_t val, · line 1093

Quoted 10 lines
hw/misc/mac_via.c +10 -0
+    case VIA_REG_A:
+    case VIA_REG_ANH: {
+        const bool sel = (ms->a & VIA1A_vHeadSel) != 0;
+
+        if (v1s->swim) {
+            swim2_set_sel(v1s->swim, sel);
+        }
+
+        break;
+    }

Can you move this into a separate via1_swim_update(v1s) function as done for the rtc and adb devices as below? If possible I'd like to minimise the per-device logic in mos6522_q800_via1_write().

hw/misc/mac_via.c static void mos6522_q800_via1_reset_hold(Object *obj, ResetType type) · line 1242

Quoted 11 lines
hw/misc/mac_via.c +4 -0
      case VIA_REG_B:
          via1_rtc_update(v1s);
          via1_adb_update(v1s);
@@ -1224,6 +1236,10 @@ static void mos6522_q800_via1_reset_hold(Object *obj, ResetType type)
 
      /* Timer calibration hack */
      v1s->timer_hack_state = 0;
+
+    if (v1s->swim) {
+        swim2_set_sel(v1s->swim, false);
+    }

Given that SWIM2 is also a TYPE_DEVICE, you should be able to expose the sel signal as a GPIO on the SWIM2 device in a similar way as to how "nubus-irq" is defined in mos6522_q800_via2_init() but with just 1 signal. This allows you to connect the signal with qdev_connect_gpio_out() (see hw/m68k/q800.c) and drive it using the qemu IRQ functions, which should avoid having to reference the SWIM2 device itself directly at all.

Quoted 38 lines
hw/misc/mac_via.c +0 -0
  }
 
  static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
include/hw/m68k/q800.h +2 -2
index 77551b9592..2a20314d57 100644
@@ -33,7 +33,7 @@
  #include "hw/char/escc.h"
  #include "hw/core/or-irq.h"
  #include "hw/scsi/esp.h"
-#include "hw/block/swim.h"
+#include "hw/block/swim2.h"
  #include "hw/nubus/mac-nubus-bridge.h"
  #include "hw/display/macfb.h"
  #include "hw/misc/djmemc.h"
@@ -59,7 +59,7 @@ struct Q800MachineState {
      ESCCState escc;
      OrIRQState escc_orgate;
      SysBusESPState esp;
-    Swim swim;
+    SWIM2State swim;
      MacNubusBridge mac_nubus_bridge;
      MacfbNubusState macfb;
      DJMEMCState djmemc;
include/hw/misc/mac_via.h +1 -0
index 114f41db4c..e23735b47c 100644
@@ -13,6 +13,7 @@
  #include "hw/core/sysbus.h"
  #include "hw/misc/mos6522.h"
  #include "hw/input/adb.h"
+#include "hw/block/swim2.h"
  #include "qom/object.h"
 
 

include/hw/misc/mac_via.h struct MOS6522Q800VIA1State { · line 83

Quoted 6 lines
include/hw/misc/mac_via.h +2 -0
@@ -77,6 +78,8 @@ struct MOS6522Q800VIA1State {
 
      /* SETUPTIMEK hack */
      int timer_hack_state;
+
+    SWIM2State *swim;
  };

ATB,

Mark.

#8 lore raw

Thanks for taking a look.

Quoted 3 lines · Mark Cave-Ayland

This doesn't look right: in general we should avoid accessing a device state struct directly unless it is absolutely unavoidable.

I'll handle this as part of switching to a GPIO (below).

Quoted 1 line

Can you move this into a separate via1_swim_update(v1s) function as done for the rtc and adb devices as below? If possible I'd like to minimise the per-device logic in mos6522_q800_via1_write().

Yup, will do.

Quoted 1 line

Given that SWIM2 is also a TYPE_DEVICE, you should be able to expose the sel signal as a GPIO on the SWIM2 device in a similar way as to how "nubus-irq" is defined in mos6522_q800_via2_init() but with just 1 signal. This allows you to connect the signal with qdev_connect_gpio_out() (see hw/m68k/q800.c) and drive it using the qemu IRQ functions, which should avoid having to reference the SWIM2 device itself directly at all.

Good idea -- I'll switch over to using a GPIO to drive this for v4.

Matt

#9 lore raw

PATCH v3 5/5 hw/block: remove unused SWIM1 floppy controller stub

In reply to Matt Jacobson

This was formerly used in the q800 machine; it's been replaced by a functional SWIM2.

---
 MAINTAINERS             |   2 -
 hw/block/meson.build    |   2 +-
 hw/block/swim.c         | 577 ----------------------------------------
 hw/block/trace-events   |   8 -
 include/hw/block/swim.h |  72 -----
 5 files changed, 1 insertion(+), 660 deletions(-)
 delete mode 100644 hw/block/swim.c
 delete mode 100644 include/hw/block/swim.h
MAINTAINERS +0 -2
index 93df53d87f..55da29e0cf 100644
@@ -1394,7 +1394,6 @@ F: hw/m68k/q800-glue.c
 F: hw/misc/mac_via.c
 F: hw/nubus/*
 F: hw/display/macfb.c
-F: hw/block/swim.c
 F: hw/misc/djmemc.c
 F: hw/misc/iosb.c
 F: hw/audio/asc.c
@@ -1404,7 +1403,6 @@ F: include/standard-headers/asm-m68k/bootinfo-mac.h
 F: include/hw/misc/mac_via.h
 F: include/hw/nubus/*
 F: include/hw/display/macfb.h
-F: include/hw/block/swim.h
 F: include/hw/m68k/q800.h
 F: include/hw/m68k/q800-glue.h
 F: include/hw/misc/djmemc.h
hw/block/meson.build +1 -1
index 733e9ffb47..2a9a0b9b13 100644
@@ -10,7 +10,7 @@ system_ss.add(when: 'CONFIG_PFLASH_CFI01', if_true: files('pflash_cfi01.c'))
 system_ss.add(when: 'CONFIG_PFLASH_CFI02', if_true: files('pflash_cfi02.c'))
 system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80.c'))
 system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80_sfdp.c'))
-system_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c', 'swim2.c', 'sony_superdrive.c'))
+system_ss.add(when: 'CONFIG_SWIM', if_true: files('swim2.c', 'sony_superdrive.c'))
 system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-block.c'))
 
 system_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c'))
hw/block/swim.c deleted +0 -577

577 lines not on this page · raw message

hw/block/trace-events +0 -8
index c5793c7da8..47c4e663ef 100644
@@ -104,14 +104,6 @@ m25p80_read_sfdp(void *s, uint32_t addr, uint8_t v) "[%p] Read SFDP 0x%"PRIx32"=
 m25p80_binding(void *s) "[%p] Binding to IF_MTD drive"
 m25p80_binding_no_bdrv(void *s) "[%p] No BDRV - binding to RAM"
 
-# swim.c
-swim_ismctrl_read(int reg, const char *name, unsigned size, uint64_t value) "reg=%d [%s] size=%u value=0x%"PRIx64
-swim_ismctrl_write(int reg, const char *name, unsigned size, uint64_t value) "reg=%d [%s] size=%u value=0x%"PRIx64
-swim_iwmctrl_read(int reg, const char *name, unsigned size, uint64_t value) "reg=%d [%s] size=%u value=0x%"PRIx64
-swim_iwmctrl_write(int reg, const char *name, unsigned size, uint64_t value) "reg=%d [%s] size=%u value=0x%"PRIx64
-swim_switch_to_ism(void) "switch from IWM to ISM mode"
-swim_switch_to_iwm(void) "switch from ISM to IWM mode"
-
 # swim2.c
 swim2_mmio_read(uint64_t addr, unsigned size, int reg, const char *name, uint64_t value, uint8_t mode, uint8_t setup, uint8_t phase, uint32_t fifo_count) "addr=0x%"PRIx64" size=%u reg=%d [%s] value=0x%"PRIx64" mode=0x%02x setup=0x%02x phase=0x%02x fifo=%u"
 swim2_mmio_write(uint64_t addr, unsigned size, int reg, const char *name, uint64_t value, uint8_t mode, uint8_t setup, uint8_t phase, uint32_t fifo_count) "addr=0x%"PRIx64" size=%u reg=%d [%s] value=0x%"PRIx64" mode=0x%02x setup=0x%02x phase=0x%02x fifo=%u"
include/hw/block/swim.h deleted +0 -72

72 lines not on this page · raw message

Signature · 1 line
2.54.0
#10 lore raw
In reply to Matt Jacobson
Quoted 27 lines · Matt Jacobson

Implement the SWIM2 floppy controller and SuperDrive for the q800 machine.

Reading and writing work, and booting a system disk works. Both GCR and MFM paths work.
Tested with the Quadra 800 ROM running System 7 and A/UX 3.x. Whole-disk formatting/duplication does not yet work.

Example usage:

$ qemu-system-m68k \
  -machine q800 \
  -m 128 \
  -bios "Quadra800.ROM" \
  -nodefaults \
  -drive if=mtd,file="pram.img",format=raw \
  -drive if=floppy \
  -drive if=floppy \
  -drive if=scsi,media=disk,file="harddisk.img",format=raw \
  -drive if=scsi,media=cdrom \
  -nic user,model=dp83932 \
  -audio none \
  -display cocoa \
  -name "Macintosh Quadra 800"

(To populate the floppy drive at boot, use
-drive if=floppy,file="floppy.img",format=raw. However, note that the Macintosh ROM will eject non-bootable floppies on boot.)

Quoted 5 lines

The Sony drive emulator takes raw images and will generate the GCR/MFM encoding on the fly. Here are a couple sample images (HFS) to play with:

<https://mjacobson.net/files/mac-disks/floppy-800.img>
<https://mjacobson.net/files/mac-disks/floppy-1440.img>

Including a changelog about what's new in v3 here helps reviewers to remember what this version is about.

Regards,
BALATON Zoltan

Quoted 30 lines

Matt Jacobson (5):
hw/block: add Sony/Apple "SuperDrive" diskette drive
fifo32: add fifo32_peek()
hw/block: add SWIM2 floppy controller for q800 hw/m68k: add working floppy controller for q800 hw/block: remove unused SWIM1 floppy controller stub

MAINTAINERS                        |    2 -
hw/block/meson.build               |    2 +-
hw/block/sony_superdrive.c         | 1032 ++++++++++++++++++++++++++++
hw/block/swim.c                    |  577 ----------------
hw/block/swim2.c                   |  711 +++++++++++++++++++
hw/block/trace-events              |   25 +-
hw/m68k/q800.c                     |    5 +-
hw/misc/mac_via.c                  |   16 +
include/hw/block/sony_superdrive.h |   55 ++
include/hw/block/swim.h            |   72 --
include/hw/block/swim2.h           |   58 ++
include/hw/m68k/q800.h             |    4 +-
include/hw/misc/mac_via.h          |    3 +
include/qemu/fifo32.h              |   31 +-
14 files changed, 1923 insertions(+), 670 deletions(-)

create mode 100644 hw/block/sony_superdrive.c delete mode 100644 hw/block/swim.c
create mode 100644 hw/block/swim2.c
create mode 100644 include/hw/block/sony_superdrive.h delete mode 100644 include/hw/block/swim.h create mode 100644 include/hw/block/swim2.h

#11 lore raw
Quoted 7 lines · BALATON Zoltan

On Wed, 1 Jul 2026, Matt Jacobson wrote:

Including a changelog about what's new in v3 here helps reviewers to remember what this version is about.

Agreed; I intended to do this but forgot. Sorry! Here we go…

Changes in v2..v3:

- fix cases where the guest could reach an assert/crash with invalid MMIOs; the errors are now handled gracefully
- use DEFINE_TYPES() in swim2.c
- fix SWIM2State usage in mac_via.h (by including header instead of forward-declaring)
- allow 720k MFM disk images in sony_drive_reset()
- clarify meaning of SONY_CMD_SET_MFM / SONY_CMD_SET_GCR with comments
- in fifo32_peek(), use ldl_le_p() instead of hand-assembling the word (and adjust fifo32_pop() similarly)
- various project style conformances

Matt