hw/m68k: add working floppy controller for q800
cover hw/m68k: add working floppy controller for q800
[Please notify me of any process errors -- this is my first contribution to QEMU. Thanks.]
Implement the SWIM2 floppy controller for the q800 machine.
(For details, see: <https://archive.org/details/SWIMDesignDocs/SWIM2%20ERS/>.)
Reading and writing work, and booting from a system disk works. Tested with the Quadra 800 ROM and System 7.
Future areas of work here could include:
* Allowing for disk formatting/duplication to work
* Fleshing out the SWIM1 and hooking it up to the emulated drive
* Implementing the IWM for earlier machines (this could share code with SWIM1)
Matt Jacobson (1):
hw/m68k: add working floppy controller for q800
hw/block/meson.build | 2 +- hw/block/sony_superdrive.c | 940 +++++++++++++++++++++++++++++ hw/block/swim2.c | 657 ++++++++++++++++++++ hw/block/trace-events | 17 + hw/m68k/q800.c | 4 +- include/hw/block/sony_superdrive.h | 55 ++ include/hw/block/swim2.h | 66 ++ include/hw/m68k/q800.h | 4 +- 8 files changed, 1740 insertions(+), 5 deletions(-) create mode 100644 hw/block/sony_superdrive.c create mode 100644 hw/block/swim2.c create mode 100644 include/hw/block/sony_superdrive.h create mode 100644 include/hw/block/swim2.h
Signature · 1 line
2.37.1 (Apple Git-137.1)
PATCH 1/1 hw/m68k: add working floppy controller for q800
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, and likewise implement the floppy drives it connects to, supporting both GCR (400 kB and 800 kB) and MFM (1440 kB) diskette images.
--- hw/block/meson.build | 2 +- hw/block/sony_superdrive.c | 940 +++++++++++++++++++++++++++++ hw/block/swim2.c | 657 ++++++++++++++++++++ hw/block/trace-events | 17 + hw/m68k/q800.c | 4 +- include/hw/block/sony_superdrive.h | 55 ++ include/hw/block/swim2.h | 66 ++ include/hw/m68k/q800.h | 4 +- 8 files changed, 1740 insertions(+), 5 deletions(-) create mode 100644 hw/block/sony_superdrive.c create mode 100644 hw/block/swim2.c create mode 100644 include/hw/block/sony_superdrive.h create mode 100644 include/hw/block/swim2.h
hw/block/meson.build +1 -1
@@ -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', 'swim2.c', 'sony_superdrive.c')) system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-block.c')) specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c'))
hw/block/sony_superdrive.c new file +940 -0
940 lines not on this page · raw message
hw/block/swim2.c new file +657 -0
657 lines not on this page · raw message
hw/block/trace-events +17 -0
@@ -101,3 +101,20 @@ 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" + +# 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_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) "drive=%p lba=0x%"PRIx64 +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_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
hw/m68k/q800.c +2 -2
@@ -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"
@@ -511,7 +511,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,
include/hw/block/sony_superdrive.h new file +55 -0
55 lines not on this page · raw message
include/hw/block/swim2.h new file +66 -0
66 lines not on this page · raw message
include/hw/m68k/q800.h +2 -2
@@ -33,7 +33,7 @@#include "hw/char/escc.h" #include "hw/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;
Signature · 1 line
2.37.1 (Apple Git-137.1)
Quoted 27 lines · Matt Jacobson
[Please notify me of any process errors -- this is my first contribution to QEMU. Thanks.]
Implement the SWIM2 floppy controller for the q800 machine.
(For details, see: <https://archive.org/details/SWIMDesignDocs/SWIM2%20ERS/>.)Reading and writing work, and booting from a system disk works. Tested with the Quadra 800 ROM and System 7.
Future areas of work here could include:
* Allowing for disk formatting/duplication to work
* Fleshing out the SWIM1 and hooking it up to the emulated drive
* Implementing the IWM for earlier machines (this could share code with SWIM1)Matt Jacobson (1):
hw/m68k: add working floppy controller for q800hw/block/meson.build | 2 +- hw/block/sony_superdrive.c | 940 +++++++++++++++++++++++++++++ hw/block/swim2.c | 657 ++++++++++++++++++++ hw/block/trace-events | 17 + hw/m68k/q800.c | 4 +- include/hw/block/sony_superdrive.h | 55 ++ include/hw/block/swim2.h | 66 ++ include/hw/m68k/q800.h | 4 +- 8 files changed, 1740 insertions(+), 5 deletions(-)
Quoted 4 lines
create mode 100644
hw/block/sony_superdrive.ccreate mode 100644hw/block/swim2.c
create mode 100644include/hw/block/sony_superdrive.hcreate mode 100644include/hw/block/swim2.h
Thanks for the contribution! I've applied this patch and managed to get it to compile successfully, but I'm struggling to find a suitable disk image that works. Can you point me towards both a GCR and an MFM image I can use for testing? I think this might be because the images I use here are simply HFS(+) images.
Some initial thoughts from looking over the code:
- The basic implementation looks fairly good from what I can see, but I can see a number of places that don't match our code style guidelines. You can do a basic style check running "./scripts/checkpatch.pl HEAD~1..HEAD" from a git checkout with your patch applied which will pick up the majority of issues.
- Having everything in one patch makes it harder to review: I think it would make sense to introduce the SONY drive in one patch, the updated SWIM2 controller in another, and then a final patch to update the q800 machine to switch over the SWIM2. And maybe even an extra patch to remove the existing SWIM1 stub? The stub was added with just enough implemented to allow Linux to boot.
- Have you tested with an A/UX 3.0.1 boot floppy? A number of people are interested to run AUX 3.0.1 as per https://www.emaculation.com/doku.php/m68k-qemu-on-windows#running_qemu-system-m68k_with_a_ux_3x_guests_in_windows and it would be good to be able to use the real floppy image here.
- QEMU already has a fairly good Fifo8 implementation: is it possible to use that or Fifo32 instead of reinventing it here?
- It's worth updating the cover letter to include an example command line. I had to go digging into the patch to discover that I needed to add something like "-drive file=/tmp/Install.img,if=none,id=floppy" to attempt a floppy boot. Configuring internal devices can be fiddly: I'm wondering if there is existing precedent in the way PC floppy drives work that we can use to keep things consistent?
- When booting a test Linux image I got stuck in a boot loop, both with and without a floppy inserted in the drive:
swim2_mmio_read addr=0x1e00 size=1 reg=7 [HANDSHAKE] value=0x8 mode=0xca setup=0x28 phase=0x74 fifo=0 swim2_mmio_read addr=0x1e00 size=1 reg=7 [HANDSHAKE] value=0x8 mode=0xca setup=0x28 phase=0x74 fifo=0
...
...
Since the Linux maintainers make use of QEMU for testing, I think we need to get this working. Laurent - do you know if the 68K Mac kernel driver works on real hardware?
I appreciate the time and effort that has gone into creating this patch, and I'm really looking forward to getting it to a point where it can be merged :)
ATB,
Mark.
Le 05/12/2025 à 22:20, Mark Cave-Ayland a écrit :
Quoted 34 lines · Matt Jacobson
Quoted 27 lines
[Please notify me of any process errors -- this is my first contribution to QEMU. Thanks.]
Implement the SWIM2 floppy controller for the q800 machine.
(For details, see: <https://archive.org/details/SWIMDesignDocs/SWIM2%20ERS/>.)Reading and writing work, and booting from a system disk works. Tested with the Quadra 800 ROM and System 7.
Future areas of work here could include:
* Allowing for disk formatting/duplication to work
* Fleshing out the SWIM1 and hooking it up to the emulated drive
* Implementing the IWM for earlier machines (this could share code with SWIM1)Matt Jacobson (1):
hw/m68k: add working floppy controller for q800hw/block/meson.build | 2 +- hw/block/sony_superdrive.c | 940 +++++++++++++++++++++++++++++ hw/block/swim2.c | 657 ++++++++++++++++++++ hw/block/trace-events | 17 +
hw/m68k/q800.c | 4 +-include/hw/block/sony_superdrive.h| 55 ++ include/hw/block/swim2.h | 66 ++ include/hw/m68k/q800.h | 4 +-Quoted 5 lines
8 files changed, 1740 insertions(+), 5 deletions(-)create mode 100644
hw/block/sony_superdrive.ccreate mode 100644hw/block/swim2.c
create mode 100644include/hw/block/sony_superdrive.hcreate mode 100644include/hw/block/swim2.h
Quoted 1 line
Thanks for the contribution! I've applied this patch and managed to get it to compile successfully, but I'm struggling to find a suitable disk image that works. Can you point me towards both a GCR and an MFM image I can use for testing? I think this might be because the images I use here are simply HFS(+) images.
Perhaps you can try:
https://sourceforge.net/projects/emile/files/emile-rescue/emile-rescue-0.12/
There was a time when the kernel and a ramdisk could fit on an 1.44 MB disk...
Quoted 20 lines
Some initial thoughts from looking over the code:
- The basic implementation looks fairly good from what I can see, but I can see a number of places
that don't match our code style guidelines. You can do a basic style check running "./scripts/checkpatch.pl HEAD~1..HEAD" from a git checkout with your patch applied which will pick up the majority of issues.- Having everything in one patch makes it harder to review: I think it would make sense to introduce
the SONY drive in one patch, the updated SWIM2 controller in another, and then a final patch to update the q800 machine to switch over the SWIM2. And maybe even an extra patch to remove the existing SWIM1 stub? The stub was added with just enough implemented to allow Linux to boot.- Have you tested with an A/UX 3.0.1 boot floppy? A number of people are interested to run AUX 3.0.1
as per https://www.emaculation.com/doku.php/m68k-qemu-on-windows#running_qemu-system-m68k_with_a_ux_3x_guests_in_windowsand it would be good to be able to use the real floppy image here.- QEMU already has a fairly good Fifo8 implementation: is it possible to use that or Fifo32 instead of reinventing it here?
- It's worth updating the cover letter to include an example command line. I had to go digging into
the patch to discover that I needed to add something like "-drive file=/tmp/ Install.img,if=none,id=floppy" to attempt a floppy boot. Configuring internal devices can be fiddly: I'm wondering if there is existing precedent in the way PC floppy drives work that we can use to keep things consistent?- When booting a test Linux image I got stuck in a boot loop, both with and without a floppy inserted in the drive:
Quoted 6 lines
swim2_mmio_readaddr=0x1e00 size=1 reg=7 [HANDSHAKE] value=0x8 mode=0xca setup=0x28 phase=0x74 fifo=0swim2_mmio_readaddr=0x1e00 size=1 reg=7 [HANDSHAKE] value=0x8 mode=0xca setup=0x28 phase=0x74 fifo=0
...
...Since the Linux maintainers make use of QEMU for testing, I think we need to get this working. Laurent - do you know if the 68K Mac kernel driver works on real hardware?
Well, I wrote it, and didn't test for a while.
It only supports read access. I wrote it to be able to boot linux from a floppy and allow the kernel to read initrd from another.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/block/swim.c
Thanks,
Laurent
Hi Mark, Laurent,
Many thanks for taking the time to review. (And sorry for my delay in response. I'd still like to put in the work to get this over the finish line.)
I realize this is a large change, so I am more than happy to make changes to minimize the burden. Responses inline…
Quoted 3 lines · Mark Cave-Ayland
I've applied this patch and managed to get it to compile successfully, but I'm struggling to find a suitable disk image that works. Can you point me towards both a GCR and an MFM image I can use for testing? I think this might be because the images I use here are simply HFS(+) images.
The Sony drive emulator here takes raw HFS(+) images and will generate the GCR/MFM encoding on the fly. Here are a couple sample images to play with:
<https://mjacobson.net/files/mac-disks/floppy-800.img>
<https://mjacobson.net/files/mac-disks/floppy-1440.img>
Quoted 3 lines
Some initial thoughts from looking over the code:
- The basic implementation looks fairly good from what I can see, but I can see a number of places that don't match our code style guidelines. You can do a basic style check running "
./scripts/checkpatch.plHEAD~1..HEAD" from a git checkout with your patch applied which will pick up the majority of issues.
Thanks -- I was not aware of that script, and I'll ensure the next version passes it.
Quoted 1 line
- Having everything in one patch makes it harder to review: I think it would make sense to introduce the SONY drive in one patch, the updated SWIM2 controller in another, and then a final patch to update the q800 machine to switch over the SWIM2. And maybe even an extra patch to remove the existing SWIM1 stub? The stub was added with just enough implemented to allow Linux to boot.
That sounds reasonable. I was considering leaving the SWIM1 stub so that it could eventually be fleshed out and hooked up to the drive, but I suppose it's not worth letting it sit unused. A new version could be re-added in the future if desired.
Quoted 1 line
- Have you tested with an A/UX 3.0.1 boot floppy? A number of people are interested to run AUX 3.0.1 as per https://www.emaculation.com/doku.php/m68k-qemu-on-windows#running_qemu-system-m68k_with_a_ux_3x_guests_in_windows and it would be good to be able to use the real floppy image here.
Good question. Testing A/UX had been on my to-do list, but I hadn't yet gotten around to it.
On your prompting, I can now report that (with a handful of small bugfixes, which I will include in my next version), my A/UX 3.0.1 boot floppy boots and allows installation of A/UX, *and* both MFM and GCR floppies are mountable inside A/UX (3.0.1 and 3.1) itself.
Happily, the A/UX kernel does not have symbols stripped, and I was able to compile an old GNU binutils objdump for the m68k-unknown-coff target to analyze it!
Quoted 1 line
- QEMU already has a fairly good Fifo8 implementation: is it possible to use that or Fifo32 instead of reinventing it here?
Probably -- I just wasn't aware of it. The only downside would be that the bytes would be out-of-line, but I don't think that's worth fretting over.
Quoted 1 line
- It's worth updating the cover letter to include an example command line. I had to go digging into the patch to discover that I needed to add something like "-drive file=/tmp/Install.img,if=none,id=floppy" to attempt a floppy boot.
I'll definitely include a full example command for v2. You should be able to use just -drive if=floppy,file="some-floppy.img",format=raw. My full command is something like:
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="$1",format=raw \
-drive if=scsi,media=cdrom \
-nic user,model=dp83932 \
-audio none \
-display cocoa \
-name "Macintosh Quadra 800"
(Unless I'm trying to boot from a floppy, I tend to leave the floppy drives empty, since the ROM will auto-eject the non-bootable disks anyway.)
Quoted 1 line
Configuring internal devices can be fiddly: I'm wondering if there is existing precedent in the way PC floppy drives work that we can use to keep things consistent?
I *think* the above matches IBM PC emulation; you could even use -fda and -fdb if you wished.
Quoted 9 lines
- When booting a test Linux image I got stuck in a boot loop, both with and without a floppy inserted in the drive:
swim2_mmio_readaddr=0x1e00 size=1 reg=7 [HANDSHAKE] value=0x8 mode=0xca setup=0x28 phase=0x74 fifo=0swim2_mmio_readaddr=0x1e00 size=1 reg=7 [HANDSHAKE] value=0x8 mode=0xca setup=0x28 phase=0x74 fifo=0
...
...Since the Linux maintainers make use of QEMU for testing, I think we need to get this working. Laurent - do you know if the 68K Mac kernel driver works on real hardware?
Quoted 7 lines
On Dec 8, 2025, at 7:44 AM, Laurent Vivier <[email protected]> wrote:
Well, I wrote it, and didn't test for a while.
It only supports read access. I wrote it to be able to boot linux from a floppy and allow the kernel to read initrd from another.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/block/swim.c
I'd be glad to look into it. Would you mind sharing your Linux disk for me to try?
I'm not too familiar with Linux's support, but SWIM1 and SWIM2 are *mostly* compatible, as long as the IWM sub-mode of SWIM1 isn't used (and, from my brief read of the Linux driver there, it isn't).
Matt