Skip to contentSkip to conversation

hw/m68k: add Apple Machintosh Quadra 800 machine

PATCH Superseded Laurent Vivier 3 participants 15 messages Jun 27, 2018 – Jul 8, 2018

v2 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v2 cover hw/m68k: add Apple Machintosh Quadra 800 machine

I'm rebasing some of these patches for seven years now, too many years...

if you want to test the machine, I'm sorry, it doesn't boot a MacROM, but you can boot a linux kernel from the command line.

You can install your own disk using debian-installer, with:

    ...
    -M q800 \
    -serial none -serial mon:stdio \
    -m 1000M -drive file=m68k.qcow2,format=qcow2 \
    -net nic,model=dp83932,addr=09:00:07:12:34:57 \
    -append "console=ttyS0 vga=off" \
    -kernel vmlinux-4.15.0-2-m68k \
    -initrd initrd.gz \
    -drive file=debian-9.0-m68k-NETINST-1.iso \
    -drive file=m68k.qcow2,format=qcow2 \
    -nographic

If you use a graphic adapter instead of "-nographic", you can use "-g" to set the size of the display (I use "-g 1600x800x24").

You can get the ISO from:

https://cdimage.debian.org/mirror/cdimage/ports/9.0/m68k/iso-cd/debian-9.0-m68k-NETINST-1.iso

and extract the kernel and initrd.gz:

guestfish --add debian-9.0-m68k-NETINST-1.iso --ro \
          --mount /dev/sda:/ <<_EOF_

copy-out /install/cdrom/initrd.gz .
copy-out /install/kernels/vmlinux-4.15.0-2-m68k .
_EOF_

The mirror to use is: http://ftp.ports.debian.org/debian-ports/
when it fails, continue without boot loader.

In the same way, you can extract the kernel and the initramfs from the qcow2 image to use it with "-kernel" and "-initrd":

guestfish --add m68k.qcow2 --mount /dev/sda2:/ <<_EOF_ copy-out /boot/vmlinux-4.15.0-2-m68k . copy-out /boot/initrd.img-4.15.0-2-m68k . _EOF_

and boot with:

   ...
   -append "root=/dev/sda2 rw console=ttyS0 console=tty \
   -kernel vmlinux-4.15.0-2-m68k \
   -initrd initrd.img-4.15.0-2-m68k

v2: remove the dp8393x fixes, because one of the patch breaks something
Update "dp8393x: manage big endian bus" with idea from Thomas Mark has reworked most of the patches:
- use mos6522
- some code move, renamings and cleanup

Laurent Vivier (10):
hw/m68k: add via support
ADB: VIA probes ADB bus when it is idle
escc: introduce a selector for the register bit
hw/m68k: add video card
hw/m68k: Apple Sound Chip (ASC) emulation
ESP: add pseudo-DMA as used by Macintosh
hw/m68k: add Nubus support
hw/m68k: add a dummy SWIM floppy controller
dp8393x: manage big endian bus
hw/m68k: define Macintosh Quadra 800

 MAINTAINERS                         |  19 +
 arch_init.c                         |   4 +
 default-configs/m68k-softmmu.mak    |  14 +
 hw/Makefile.objs                    |   1 +
 hw/audio/Makefile.objs              |   1 +
 hw/audio/asc.c                      | 463 +++++++++++++++++++++++
 hw/block/Makefile.objs              |   1 +
 hw/block/swim.c                     | 284 ++++++++++++++
 hw/char/escc.c                      |  30 +-
 hw/display/Makefile.objs            |   1 +
 hw/display/macfb-template.h         | 158 ++++++++
 hw/display/macfb.c                  | 308 +++++++++++++++
 hw/input/adb-kbd.c                  |   4 +
 hw/input/adb-mouse.c                |   4 +
 hw/input/adb.c                      | 115 ++++++
 hw/intc/Makefile.objs               |   1 +
 hw/intc/q800_irq.c                  |  73 ++++
 hw/m68k/Makefile.objs               |   6 +-
 hw/m68k/bootinfo.h                  | 100 +++++
 hw/m68k/q800.c                      | 385 +++++++++++++++++++
 hw/mips/mips_jazz.c                 |   2 +-
 hw/misc/Makefile.objs               |   1 +
 hw/misc/mac_via.c                   | 731 ++++++++++++++++++++++++++++++++++++
 hw/net/dp8393x.c                    |  88 +++--
 hw/nubus/Makefile.objs              |   4 +
 hw/nubus/mac-nubus-bridge.c         |  45 +++
 hw/nubus/nubus-bridge.c             |  34 ++
 hw/nubus/nubus-bus.c                | 111 ++++++
 hw/nubus/nubus-device.c             | 210 +++++++++++
 hw/scsi/esp.c                       | 297 +++++++++++++--
 include/hw/audio/asc.h              |  48 +++
 include/hw/block/swim.h             |  53 +++
 include/hw/char/escc.h              |   1 +
 include/hw/display/macfb.h          |  63 ++++
 include/hw/input/adb.h              |  10 +
 include/hw/intc/q800_irq.h          |  39 ++
 include/hw/misc/mac_via.h           | 107 ++++++
 include/hw/nubus/mac-nubus-bridge.h |  24 ++
 include/hw/nubus/nubus.h            |  69 ++++
 include/hw/scsi/esp.h               |  11 +-
 qemu-options.hx                     |   2 +-
 tests/qom-test.c                    |   5 +
 tests/test-hmp.c                    |   3 +-
 vl.c                                |   3 +-
 44 files changed, 3857 insertions(+), 76 deletions(-)
 create mode 100644 hw/audio/asc.c
 create mode 100644 hw/block/swim.c
 create mode 100644 hw/display/macfb-template.h
 create mode 100644 hw/display/macfb.c
 create mode 100644 hw/intc/q800_irq.c
 create mode 100644 hw/m68k/bootinfo.h
 create mode 100644 hw/m68k/q800.c
 create mode 100644 hw/misc/mac_via.c
 create mode 100644 hw/nubus/Makefile.objs
 create mode 100644 hw/nubus/mac-nubus-bridge.c
 create mode 100644 hw/nubus/nubus-bridge.c
 create mode 100644 hw/nubus/nubus-bus.c
 create mode 100644 hw/nubus/nubus-device.c
 create mode 100644 include/hw/audio/asc.h
 create mode 100644 include/hw/block/swim.h
 create mode 100644 include/hw/display/macfb.h
 create mode 100644 include/hw/intc/q800_irq.h
 create mode 100644 include/hw/misc/mac_via.h
 create mode 100644 include/hw/nubus/mac-nubus-bridge.h
 create mode 100644 include/hw/nubus/nubus.h
Signature · 1 line
2.14.4
#1 lore raw

PATCH v2 1/10 hw/m68k: add via support

---
 hw/misc/Makefile.objs     |   1 +
 hw/misc/mac_via.c         | 675 ++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/misc/mac_via.h | 106 ++++++++
 3 files changed, 782 insertions(+)
 create mode 100644 hw/misc/mac_via.c
 create mode 100644 include/hw/misc/mac_via.h
hw/misc/Makefile.objs +1 -0
index 9350900845..24eb8011f1 100644
@@ -70,5 +70,6 @@ obj-$(CONFIG_PVPANIC) += pvpanic.o
 obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
 obj-$(CONFIG_AUX) += auxbus.o
 obj-$(CONFIG_ASPEED_SOC) += aspeed_scu.o aspeed_sdmc.o
+obj-$(CONFIG_MAC_VIA) += mac_via.o
 obj-y += mmio_interface.o
 obj-$(CONFIG_MSF2) += msf2-sysreg.o
hw/misc/mac_via.c new file +675 -0

675 lines not on this page · raw message

include/hw/misc/mac_via.h new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.14.4
#2 lore raw

PATCH v2 2/10 ADB: VIA probes ADB bus when it is idle

In reply to Laurent Vivier
---
 hw/input/adb-kbd.c        |   4 ++
 hw/input/adb-mouse.c      |   4 ++
 hw/input/adb.c            | 115 ++++++++++++++++++++++++++++++++++++++++++++++
 hw/misc/mac_via.c         |  56 ++++++++++++++++++++++
 include/hw/input/adb.h    |  10 ++++
 include/hw/misc/mac_via.h |   1 +
 6 files changed, 190 insertions(+)
hw/input/adb-kbd.c +4 -0
index b026e9d49f..f439e106bb 100644
@@ -195,6 +195,10 @@ static int adb_kbd_poll(ADBDevice *d, uint8_t *obuf)
     int keycode;
     int olen;
 
+    if (obuf == NULL) {
+        return s->count;
+    }
+
     olen = 0;
     if (s->count == 0) {
         return 0;
hw/input/adb-mouse.c +4 -0
index 83833b0035..7615c252d5 100644
@@ -73,6 +73,10 @@ static int adb_mouse_poll(ADBDevice *d, uint8_t *obuf)
         return 0;
     }
 
+    if (obuf == NULL) {
+        return 2;
+    }
+
     dx = s->dx;
     if (dx < -63) {
         dx = -63;
hw/input/adb.c +115 -0

127 lines not on this page · raw message

hw/misc/mac_via.c +56 -0

86 lines not on this page · raw message

include/hw/input/adb.h +10 -0
index f99d478252..1888c5aab7 100644
@@ -76,6 +76,12 @@ struct ADBBusState {
     ADBDevice *devices[MAX_ADB_DEVICES];
     int nb_devices;
     int poll_index;
+    qemu_irq data_ready;
+    int data_in_size;
+    int data_in_index;
+    int data_out_index;
+    uint8_t data_in[128];
+    uint8_t data_out[16];
 };
 
 int adb_request(ADBBusState *s, uint8_t *buf_out,
@@ -85,4 +91,8 @@ int adb_poll(ADBBusState *s, uint8_t *buf_out, uint16_t poll_mask);
 #define TYPE_ADB_KEYBOARD "adb-keyboard"
 #define TYPE_ADB_MOUSE "adb-mouse"
 
+int adb_via_poll(ADBBusState *s, int state, uint8_t *data);
+int adb_send(ADBBusState *adb, int state, uint8_t data);
+int adb_receive(ADBBusState *adb, int state, uint8_t *data);
+
 #endif /* ADB_H */
include/hw/misc/mac_via.h +1 -0
index a3a972ccc5..85d8715b12 100644
@@ -96,6 +96,7 @@ typedef struct MacVIAState {
 
     /* ADB */
     ADBBusState adb_bus;
+    QEMUTimer *adb_poll_timer;
 
     /* external timers */
     QEMUTimer *one_second_timer;
Signature · 1 line
2.14.4
#3 lore raw

PATCH v2 3/10 escc: introduce a selector for the register bit

In reply to Laurent Vivier

On Sparc and PowerMac, the bit 0 of the address selects the register type (control or data) and bit 1 selects the channel (B or A).

On m68k Macintosh, the bit 0 selects the channel and bit 1 the register type.

This patch introduces a new parameter (bit_swap) to the device interface to indicate bits usage must be swapped between registers and channels.

For the moment all the machines use the bit 0, but this change will be needed to emulate Quadra 800.

---
 hw/char/escc.c         | 30 ++++++++++++++++++++++++------
 include/hw/char/escc.h |  1 +
 2 files changed, 25 insertions(+), 6 deletions(-)
hw/char/escc.c +24 -6
index 628f5f81f7..cec75b06f9 100644
@@ -42,14 +42,21 @@
  * mouse and keyboard ports don't implement all functions and they are
  * only asynchronous. There is no DMA.
  *
- * Z85C30 is also used on PowerMacs. There are some small differences
- * between Sparc version (sunzilog) and PowerMac (pmac):
+ * Z85C30 is also used on PowerMacs and m68k Macs.
+ *
+ * There are some small differences between Sparc version (sunzilog)
+ * and PowerMac (pmac):
  *  Offset between control and data registers
  *  There is some kind of lockup bug, but we can ignore it
  *  CTS is inverted
  *  DMA on pmac using DBDMA chip
  *  pmac can do IRDA and faster rates, sunzilog can only do 38400
  *  pmac baud rate generator clock is 3.6864 MHz, sunzilog 4.9152 MHz
+ *
+ * Linux driver for m68k Macs is the same as for PowerMac (pmac_zilog),
+ * but registers are grouped by type and not by channel:
+ * channel is selected by bit 0 of the address (instead of bit 1)
+ * and register is selected by bit 1 of the address (instead of bit 0).
  */
 
 /*
@@ -169,6 +176,16 @@ static void handle_kbd_command(ESCCChannelState *s, int val);
 static int serial_can_receive(void *opaque);
 static void serial_receive_byte(ESCCChannelState *s, int ch);
 
+static int reg_shift(ESCCState *s)
+{
+    return s->bit_swap ? s->it_shift + 1 : s->it_shift;
+}
+
+static int chn_shift(ESCCState *s)
+{
+    return s->bit_swap ? s->it_shift : s->it_shift + 1;
+}
+
 static void clear_queue(void *opaque)
 {
     ESCCChannelState *s = opaque;
@@ -433,8 +450,8 @@ static void escc_mem_write(void *opaque, hwaddr addr,
     int newreg, channel;
 
     val &= 0xff;
-    saddr = (addr >> serial->it_shift) & 1;
-    channel = (addr >> (serial->it_shift + 1)) & 1;
+    saddr = (addr >> reg_shift(serial)) & 1;
+    channel = (addr >> chn_shift(serial)) & 1;
     s = &serial->chn[channel];
     switch (saddr) {
     case SERIAL_CTRL:
@@ -537,8 +554,8 @@ static uint64_t escc_mem_read(void *opaque, hwaddr addr,
     uint32_t ret;
     int channel;
 
-    saddr = (addr >> serial->it_shift) & 1;
-    channel = (addr >> (serial->it_shift + 1)) & 1;
+    saddr = (addr >> reg_shift(serial)) & 1;
+    channel = (addr >> chn_shift(serial)) & 1;
     s = &serial->chn[channel];
     switch (saddr) {
     case SERIAL_CTRL:
@@ -822,6 +839,7 @@ static void escc_realize(DeviceState *dev, Error **errp)
 static Property escc_properties[] = {
     DEFINE_PROP_UINT32("frequency", ESCCState, frequency,   0),
     DEFINE_PROP_UINT32("it_shift",  ESCCState, it_shift,    0),
+    DEFINE_PROP_BOOL("bit_swap",    ESCCState, bit_swap,    false),
     DEFINE_PROP_UINT32("disabled",  ESCCState, disabled,    0),
     DEFINE_PROP_UINT32("chnBtype",  ESCCState, chn[0].type, 0),
     DEFINE_PROP_UINT32("chnAtype",  ESCCState, chn[1].type, 0),
include/hw/char/escc.h +1 -0
index 42aca83611..8762f61c14 100644
@@ -50,6 +50,7 @@ typedef struct ESCCState {
 
     struct ESCCChannelState chn[2];
     uint32_t it_shift;
+    bool bit_swap;
     MemoryRegion mmio;
     uint32_t disabled;
     uint32_t frequency;
Signature · 1 line
2.14.4
#4 lore raw

PATCH v2 4/10 hw/m68k: add video card

In reply to Laurent Vivier
---
 arch_init.c                 |   4 +
 hw/display/Makefile.objs    |   1 +
 hw/display/macfb-template.h | 158 +++++++++++++++++++++++++++
 hw/display/macfb.c          | 252 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/display/macfb.h  |  42 ++++++++
 qemu-options.hx             |   2 +-
 vl.c                        |   3 +-
 7 files changed, 460 insertions(+), 2 deletions(-)
 create mode 100644 hw/display/macfb-template.h
 create mode 100644 hw/display/macfb.c
 create mode 100644 include/hw/display/macfb.h
arch_init.c +4 -0
index f4f3f610c8..5a71b48dc5 100644
@@ -39,6 +39,10 @@
 int graphic_width = 1024;
 int graphic_height = 768;
 int graphic_depth = 8;
+#elif defined(TARGET_M68K)
+int graphic_width = 800;
+int graphic_height = 600;
+int graphic_depth = 8;
 #else
 int graphic_width = 800;
 int graphic_height = 600;
hw/display/Makefile.objs +1 -0
index fb8408c6d0..bb9f509e4f 100644
@@ -22,6 +22,7 @@ common-obj-$(CONFIG_EXYNOS4) += exynos4210_fimd.o
 common-obj-$(CONFIG_FRAMEBUFFER) += framebuffer.o
 common-obj-$(CONFIG_MILKYMIST) += milkymist-vgafb.o
 common-obj-$(CONFIG_ZAURUS) += tc6393xb.o
+common-obj-$(CONFIG_MACFB) += macfb.o
 
 common-obj-$(CONFIG_MILKYMIST_TMU2) += milkymist-tmu2.o
 milkymist-tmu2.o-cflags := $(X11_CFLAGS)
hw/display/macfb-template.h new file +158 -0

158 lines not on this page · raw message

hw/display/macfb.c new file +252 -0

252 lines not on this page · raw message

include/hw/display/macfb.h new file +42 -0

42 lines not on this page · raw message

qemu-options.hx +1 -1
index d5b0c26e8e..b48f925128 100644
@@ -1539,7 +1539,7 @@ ETEXI
 
 DEF("g", 1, QEMU_OPTION_g ,
     "-g WxH[xDEPTH]  Set the initial graphical resolution and depth\n",
-    QEMU_ARCH_PPC | QEMU_ARCH_SPARC)
+    QEMU_ARCH_PPC | QEMU_ARCH_SPARC | QEMU_ARCH_M68K)
 STEXI
 @item -g @var{width}x@var{height}[x@var{depth}]
 @findex -g
vl.c +2 -1
index d26f19b06d..87ba3859eb 100644
@@ -3310,7 +3310,8 @@ int main(int argc, char **argv, char **envp)
                     if (*p == 'x') {
                         p++;
                         depth = strtol(p, (char **)&p, 10);
-                        if (depth != 8 && depth != 15 && depth != 16 &&
+                        if (depth != 1 && depth != 2 && depth != 4 &&
+                            depth != 8 && depth != 15 && depth != 16 &&
                             depth != 24 && depth != 32)
                             goto graphic_error;
                     } else if (*p == '\0') {
Signature · 1 line
2.14.4
#5 lore raw

PATCH v2 5/10 hw/m68k: Apple Sound Chip (ASC) emulation

In reply to Laurent Vivier

This is broken as the linux driver seems broken too...

---
 hw/audio/Makefile.objs |   1 +
 hw/audio/asc.c         | 463 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/audio/asc.h |  48 +++++
 3 files changed, 512 insertions(+)
 create mode 100644 hw/audio/asc.c
 create mode 100644 include/hw/audio/asc.h
hw/audio/Makefile.objs +1 -0
index 63db383709..44d1ada7b0 100644
@@ -16,3 +16,4 @@ common-obj-$(CONFIG_MARVELL_88W8618) += marvell_88w8618.o
 common-obj-$(CONFIG_MILKYMIST) += milkymist-ac97.o
 
 common-obj-y += soundhw.o
+common-obj-$(CONFIG_ASC) += asc.o
hw/audio/asc.c new file +463 -0

463 lines not on this page · raw message

include/hw/audio/asc.h new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.14.4
#6 lore raw

PATCH v2 6/10 ESP: add pseudo-DMA as used by Macintosh

In reply to Laurent Vivier
---
 hw/mips/mips_jazz.c   |   2 +-
 hw/scsi/esp.c         | 297 ++++++++++++++++++++++++++++++++++++++++++++------
 include/hw/scsi/esp.h |  11 +-
 3 files changed, 276 insertions(+), 34 deletions(-)
hw/mips/mips_jazz.c +1 -1
index 90cb306f53..87118f2d03 100644
@@ -282,7 +282,7 @@ static void mips_jazz_init(MachineState *machine,
 
     /* SCSI adapter */
     esp = esp_init(0x80002000, 0, rc4030_dma_read, rc4030_dma_write, dmas[0],
-                   qdev_get_gpio_in(rc4030, 5), &esp_reset, &dma_enable);
+                   qdev_get_gpio_in(rc4030, 5), NULL, &esp_reset, &dma_enable);
     scsi_bus_legacy_handle_cmdline(&esp->bus);
 
     /* Floppy */
hw/scsi/esp.c +266 -31

440 lines not on this page · raw message

include/hw/scsi/esp.h +9 -2
index 93fdaced67..43312e4bc8 100644
@@ -18,6 +18,7 @@ struct ESPState {
     uint8_t rregs[ESP_REGS];
     uint8_t wregs[ESP_REGS];
     qemu_irq irq;
+    qemu_irq irq_data;
     uint8_t chip_id;
     bool tchi_written;
     int32_t ti_size;
@@ -46,6 +47,11 @@ struct ESPState {
     ESPDMAMemoryReadWriteFunc dma_memory_write;
     void *dma_opaque;
     void (*dma_cb)(ESPState *s);
+    uint8_t pdma_buf[32];
+    uint32_t pdma_len;
+    uint8_t *pdma_start;
+    uint8_t *pdma_cur;
+    void (*pdma_cb)(ESPState *s);
 };
 
 #define TYPE_ESP "esp"
@@ -57,6 +63,7 @@ typedef struct {
     /*< public >*/
 
     MemoryRegion iomem;
+    MemoryRegion pdma;
     uint32_t it_shift;
     ESPState esp;
 } SysBusESPState;
@@ -134,8 +141,8 @@ typedef struct {
 ESPState *esp_init(hwaddr espaddr, int it_shift,
                    ESPDMAMemoryReadWriteFunc dma_memory_read,
                    ESPDMAMemoryReadWriteFunc dma_memory_write,
-                   void *dma_opaque, qemu_irq irq, qemu_irq *reset,
-                   qemu_irq *dma_enable);
+                   void *dma_opaque, qemu_irq irq, qemu_irq irq_data,
+                   qemu_irq *reset, qemu_irq *dma_enable);
 void esp_dma_enable(ESPState *s, int irq, int level);
 void esp_request_cancelled(SCSIRequest *req);
 void esp_command_complete(SCSIRequest *req, uint32_t status, size_t resid);
Signature · 1 line
2.14.4
#7 lore raw

PATCH v2 7/10 hw/m68k: add Nubus support

In reply to Laurent Vivier
---
 hw/Makefile.objs                    |   1 +
 hw/display/macfb.c                  |  56 ++++++++++
 hw/nubus/Makefile.objs              |   4 +
 hw/nubus/mac-nubus-bridge.c         |  45 ++++++++
 hw/nubus/nubus-bridge.c             |  34 ++++++
 hw/nubus/nubus-bus.c                | 111 +++++++++++++++++++
 hw/nubus/nubus-device.c             | 210 ++++++++++++++++++++++++++++++++++++
 include/hw/display/macfb.h          |  21 ++++
 include/hw/nubus/mac-nubus-bridge.h |  24 +++++
 include/hw/nubus/nubus.h            |  69 ++++++++++++
 10 files changed, 575 insertions(+)
 create mode 100644 hw/nubus/Makefile.objs
 create mode 100644 hw/nubus/mac-nubus-bridge.c
 create mode 100644 hw/nubus/nubus-bridge.c
 create mode 100644 hw/nubus/nubus-bus.c
 create mode 100644 hw/nubus/nubus-device.c
 create mode 100644 include/hw/nubus/mac-nubus-bridge.h
 create mode 100644 include/hw/nubus/nubus.h
hw/Makefile.objs +1 -0
index a19c1417ed..8c97b4b97b 100644
@@ -35,6 +35,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/
 devices-dirs-$(CONFIG_SOFTMMU) += xen/
 devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/
 devices-dirs-$(CONFIG_SOFTMMU) += smbios/
+devices-dirs-$(CONFIG_NUBUS) += nubus/
 devices-dirs-y += core/
 common-obj-y += $(devices-dirs-y)
 obj-y += $(devices-dirs-y)
hw/display/macfb.c +56 -0

95 lines not on this page · raw message

hw/nubus/Makefile.objs new file +4 -0
new file mode 100644
index 0000000000..ebb050a4ad
@@ -0,0 +1,4 @@
+common-obj-y += nubus-device.o
+common-obj-y += nubus-bus.o
+common-obj-y += nubus-bridge.o
+common-obj-$(CONFIG_MAC) += mac-nubus-bridge.o
hw/nubus/mac-nubus-bridge.c new file +45 -0

45 lines not on this page · raw message

hw/nubus/nubus-bridge.c new file +34 -0
new file mode 100644
index 0000000000..cd8c6a91eb
@@ -0,0 +1,34 @@
+/*
+ * QEMU Macintosh Nubus
+ *
+ * Copyright (c) 2013-2018 Laurent Vivier <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "hw/sysbus.h"
+#include "hw/nubus/nubus.h"
+
+static void nubus_bridge_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->fw_name = "nubus";
+}
+
+static const TypeInfo nubus_bridge_info = {
+    .name          = TYPE_NUBUS_BRIDGE,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(SysBusDevice),
+    .class_init    = nubus_bridge_class_init,
+};
+
+static void nubus_register_types(void)
+{
+    type_register_static(&nubus_bridge_info);
+}
+
+type_init(nubus_register_types)
hw/nubus/nubus-bus.c new file +111 -0

111 lines not on this page · raw message

hw/nubus/nubus-device.c new file +210 -0

210 lines not on this page · raw message

include/hw/display/macfb.h +21 -0
index 70ea5480fe..3059f2f36a 100644
@@ -39,4 +39,25 @@ typedef struct {
     MacfbState macfb;
 } MacfbSysBusState;
 
+#define MACFB_NUBUS_DEVICE_CLASS(class) \
+    OBJECT_CLASS_CHECK(MacfbNubusDeviceClass, (class), TYPE_NUBUS_MACFB)
+#define MACFB_NUBUS_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(MacfbNubusDeviceClass, (obj), TYPE_NUBUS_MACFB)
+
+typedef struct MacfbNubusDeviceClass {
+    DeviceClass parent_class;
+
+    DeviceRealize parent_realize;
+} MacfbNubusDeviceClass;
+
+#define TYPE_NUBUS_MACFB "nubus-macfb"
+#define NUBUS_MACFB(obj) \
+    OBJECT_CHECK(MacfbNubusState, (obj), TYPE_NUBUS_MACFB)
+
+typedef struct {
+    NubusDevice busdev;
+
+    MacfbState macfb;
+} MacfbNubusState;
+
 #endif
include/hw/nubus/mac-nubus-bridge.h new file +24 -0
new file mode 100644
index 0000000000..ce9c789d99
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2013-2018 Laurent Vivier <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef HW_NUBUS_MAC_H
+#define HW_NUBUS_MAC_H
+
+#include "hw/nubus/nubus.h"
+
+#define TYPE_MAC_NUBUS_BRIDGE "mac-nubus-bridge"
+#define MAC_NUBUS_BRIDGE(obj) OBJECT_CHECK(MacNubusState, (obj), \
+                                           TYPE_MAC_NUBUS_BRIDGE)
+
+typedef struct MacNubusState {
+    SysBusDevice sysbus_dev;
+
+    NubusBus *bus;
+} MacNubusState;
+
+#endif
include/hw/nubus/nubus.h new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.14.4
#8 lore raw

PATCH v2 8/10 hw/m68k: add a dummy SWIM floppy controller

In reply to Laurent Vivier
---
 hw/block/Makefile.objs  |   1 +
 hw/block/swim.c         | 284 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/block/swim.h |  53 +++++++++
 3 files changed, 338 insertions(+)
 create mode 100644 hw/block/swim.c
 create mode 100644 include/hw/block/swim.h
hw/block/Makefile.objs +1 -0
index 53ce5751ae..068de3f0c9 100644
@@ -8,6 +8,7 @@ common-obj-$(CONFIG_XEN) += xen_disk.o
 common-obj-$(CONFIG_ECC) += ecc.o
 common-obj-$(CONFIG_ONENAND) += onenand.o
 common-obj-$(CONFIG_NVME_PCI) += nvme.o
+common-obj-$(CONFIG_SWIM) += swim.o
 
 obj-$(CONFIG_SH4) += tc58128.o
 
hw/block/swim.c new file +284 -0

284 lines not on this page · raw message

include/hw/block/swim.h new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.14.4
#9 lore raw

Re: [Qemu-devel] [C v2 08/10] hw/m68k: add a dummy SWIM floppy controller

Am 28.06.2018 um 01:23 hat Laurent Vivier geschrieben:

hw/block/swim.c line 261

Quoted 9 lines
hw/block/swim.c new file +5 -0
+static Property swim_properties[] = {
+    DEFINE_PROP_DRIVE("driveA", SWIMCtrl, drives[0].blk),
+    DEFINE_PROP_DRIVE("driveB", SWIMCtrl, drives[1].blk),
+    DEFINE_PROP_END_OF_LIST(),
+};

This is not the right way to model things. The floppy controller needs to expose a bus and floppy drives need to be created with a separate -device option.

isa-fdc still has these options, but that's only for compatibility and their implementation is basically a wrapper around the modern qdev way.

Kevin

#10 lore raw

Re: [Qemu-devel] [C v2 08/10] hw/m68k: add a dummy SWIM floppy controller

Le 28/06/2018 à 10:44, Kevin Wolf a écrit :

Quoted 15 lines

Am 28.06.2018 um 01:23 hat Laurent Vivier geschrieben:

hw/block/swim.c line 261

Quoted 9 lines
hw/block/swim.c new file +5 -0
+static Property swim_properties[] = {
+    DEFINE_PROP_DRIVE("driveA", SWIMCtrl, drives[0].blk),
+    DEFINE_PROP_DRIVE("driveB", SWIMCtrl, drives[1].blk),
+    DEFINE_PROP_END_OF_LIST(),
+};

This is not the right way to model things. The floppy controller needs to expose a bus and floppy drives need to be created with a separate -device option.

Quoted 2 lines

isa-fdc still has these options, but that's only for compatibility and their implementation is basically a wrapper around the modern qdev way.

Thank you Kevin, I will update this part.

Laurent

#11 lore raw

PATCH v2 9/10 dp8393x: manage big endian bus

In reply to Laurent Vivier

This is needed by Quadra 800, this card can run on little-endian or big-endian bus.

---
 hw/net/dp8393x.c | 88 ++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 57 insertions(+), 31 deletions(-)
hw/net/dp8393x.c +57 -31
index f2d2ce344c..62adff9ba3 100644
@@ -150,6 +150,7 @@ typedef struct dp8393xState {
 
     /* Hardware */
     uint8_t it_shift;
+    bool big_endian;
     qemu_irq irq;
 #ifdef DEBUG_SONIC
     int irq_level;
@@ -220,6 +221,29 @@ static uint32_t dp8393x_wt(dp8393xState *s)
     return s->regs[SONIC_WT1] << 16 | s->regs[SONIC_WT0];
 }
 
+static uint16_t dp8393x_get(dp8393xState *s, int width, uint16_t *base,
+                            int offset)
+{
+    uint16_t val;
+
+    if (s->big_endian) {
+        val = be16_to_cpu(base[offset * width + width - 1]);
+    } else {
+        val = le16_to_cpu(base[offset * width]);
+    }
+    return val;
+}
+
+static void dp8393x_put(dp8393xState *s, int width, uint16_t *base, int offset,
+                        uint16_t val)
+{
+    if (s->big_endian) {
+        base[offset * width + width - 1] = cpu_to_be16(val);
+    } else {
+        base[offset * width] = cpu_to_le16(val);
+    }
+}
+
 static void dp8393x_update_irq(dp8393xState *s)
 {
     int level = (s->regs[SONIC_IMR] & s->regs[SONIC_ISR]) ? 1 : 0;
@@ -251,12 +275,12 @@ static void dp8393x_do_load_cam(dp8393xState *s)
         /* Fill current entry */
         address_space_rw(&s->as, dp8393x_cdp(s),
             MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);
-        s->cam[index][0] = data[1 * width] & 0xff;
-        s->cam[index][1] = data[1 * width] >> 8;
-        s->cam[index][2] = data[2 * width] & 0xff;
-        s->cam[index][3] = data[2 * width] >> 8;
-        s->cam[index][4] = data[3 * width] & 0xff;
-        s->cam[index][5] = data[3 * width] >> 8;
+        s->cam[index][0] = dp8393x_get(s, width, data, 1) & 0xff;
+        s->cam[index][1] = dp8393x_get(s, width, data, 1) >> 8;
+        s->cam[index][2] = dp8393x_get(s, width, data, 2) & 0xff;
+        s->cam[index][3] = dp8393x_get(s, width, data, 2) >> 8;
+        s->cam[index][4] = dp8393x_get(s, width, data, 3) & 0xff;
+        s->cam[index][5] = dp8393x_get(s, width, data, 3) >> 8;
         DPRINTF("load cam[%d] with %02x%02x%02x%02x%02x%02x\n", index,
             s->cam[index][0], s->cam[index][1], s->cam[index][2],
             s->cam[index][3], s->cam[index][4], s->cam[index][5]);
@@ -269,7 +293,7 @@ static void dp8393x_do_load_cam(dp8393xState *s)
     /* Read CAM enable */
     address_space_rw(&s->as, dp8393x_cdp(s),
         MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);
-    s->regs[SONIC_CE] = data[0 * width];
+    s->regs[SONIC_CE] = dp8393x_get(s, width, data, 0);
     DPRINTF("load cam done. cam enable mask 0x%04x\n", s->regs[SONIC_CE]);
 
     /* Done */
@@ -290,10 +314,10 @@ static void dp8393x_do_read_rra(dp8393xState *s)
         MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);
 
     /* Update SONIC registers */
-    s->regs[SONIC_CRBA0] = data[0 * width];
-    s->regs[SONIC_CRBA1] = data[1 * width];
-    s->regs[SONIC_RBWC0] = data[2 * width];
-    s->regs[SONIC_RBWC1] = data[3 * width];
+    s->regs[SONIC_CRBA0] = dp8393x_get(s, width, data, 0);
+    s->regs[SONIC_CRBA1] = dp8393x_get(s, width, data, 1);
+    s->regs[SONIC_RBWC0] = dp8393x_get(s, width, data, 2);
+    s->regs[SONIC_RBWC1] = dp8393x_get(s, width, data, 3);
     DPRINTF("CRBA0/1: 0x%04x/0x%04x, RBWC0/1: 0x%04x/0x%04x\n",
         s->regs[SONIC_CRBA0], s->regs[SONIC_CRBA1],
         s->regs[SONIC_RBWC0], s->regs[SONIC_RBWC1]);
@@ -408,12 +432,12 @@ static void dp8393x_do_transmit_packets(dp8393xState *s)
         tx_len = 0;
 
         /* Update registers */
-        s->regs[SONIC_TCR] = data[0 * width] & 0xf000;
-        s->regs[SONIC_TPS] = data[1 * width];
-        s->regs[SONIC_TFC] = data[2 * width];
-        s->regs[SONIC_TSA0] = data[3 * width];
-        s->regs[SONIC_TSA1] = data[4 * width];
-        s->regs[SONIC_TFS] = data[5 * width];
+        s->regs[SONIC_TCR] = dp8393x_get(s, width, data, 0) & 0xf000;
+        s->regs[SONIC_TPS] = dp8393x_get(s, width, data, 1);
+        s->regs[SONIC_TFC] = dp8393x_get(s, width, data, 2);
+        s->regs[SONIC_TSA0] = dp8393x_get(s, width, data, 3);
+        s->regs[SONIC_TSA1] = dp8393x_get(s, width, data, 4);
+        s->regs[SONIC_TFS] = dp8393x_get(s, width, data, 5);
 
         /* Handle programmable interrupt */
         if (s->regs[SONIC_TCR] & SONIC_TCR_PINT) {
@@ -439,9 +463,9 @@ static void dp8393x_do_transmit_packets(dp8393xState *s)
                 address_space_rw(&s->as,
                     dp8393x_ttda(s) + sizeof(uint16_t) * (4 + 3 * i) * width,
                     MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);
-                s->regs[SONIC_TSA0] = data[0 * width];
-                s->regs[SONIC_TSA1] = data[1 * width];
-                s->regs[SONIC_TFS] = data[2 * width];
+                s->regs[SONIC_TSA0] = dp8393x_get(s, width, data, 0);
+                s->regs[SONIC_TSA1] = dp8393x_get(s, width, data, 1);
+                s->regs[SONIC_TFS] = dp8393x_get(s, width, data, 2);
             }
         }
 
@@ -468,7 +492,8 @@ static void dp8393x_do_transmit_packets(dp8393xState *s)
         s->regs[SONIC_TCR] |= SONIC_TCR_PTX;
 
         /* Write status */
-        data[0 * width] = s->regs[SONIC_TCR] & 0x0fff; /* status */
+        dp8393x_put(s, width, data, 0,
+                    s->regs[SONIC_TCR] & 0x0fff); /* status */
         size = sizeof(uint16_t) * width;
         address_space_rw(&s->as,
             dp8393x_ttda(s),
@@ -482,8 +507,8 @@ static void dp8393x_do_transmit_packets(dp8393xState *s)
                              sizeof(uint16_t) *
                              (4 + 3 * s->regs[SONIC_TFC]) * width,
                 MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);
-            s->regs[SONIC_CTDA] = data[0 * width] & ~0x1;
-            if (data[0 * width] & 0x1) {
+            s->regs[SONIC_CTDA] = dp8393x_get(s, width, data, 0) & ~0x1;
+            if (dp8393x_get(s, width, data, 0) & 0x1) {
                 /* EOL detected */
                 break;
             }
@@ -746,7 +771,7 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf,
         address = dp8393x_crda(s) + sizeof(uint16_t) * 5 * width;
         address_space_rw(&s->as, address, MEMTXATTRS_UNSPECIFIED,
                          (uint8_t *)data, size, 0);
-        if (data[0 * width] & 0x1) {
+        if (dp8393x_get(s, width, data, 0) & 0x1) {
             /* Still EOL ; stop reception */
             return -1;
         } else {
@@ -790,11 +815,11 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf,
 
     /* Write status to memory */
     DPRINTF("Write status at %08x\n", dp8393x_crda(s));
-    data[0 * width] = s->regs[SONIC_RCR]; /* status */
-    data[1 * width] = rx_len; /* byte count */
-    data[2 * width] = s->regs[SONIC_TRBA0]; /* pkt_ptr0 */
-    data[3 * width] = s->regs[SONIC_TRBA1]; /* pkt_ptr1 */
-    data[4 * width] = s->regs[SONIC_RSC]; /* seq_no */
+    dp8393x_put(s, width, data, 0, s->regs[SONIC_RCR]); /* status */
+    dp8393x_put(s, width, data, 1, rx_len); /* byte count */
+    dp8393x_put(s, width, data, 2, s->regs[SONIC_TRBA0]); /* pkt_ptr0 */
+    dp8393x_put(s, width, data, 3, s->regs[SONIC_TRBA1]); /* pkt_ptr1 */
+    dp8393x_put(s, width, data, 4, s->regs[SONIC_RSC]); /* seq_no */
     size = sizeof(uint16_t) * 5 * width;
     address_space_rw(&s->as, dp8393x_crda(s),
         MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 1);
@@ -803,12 +828,12 @@ static ssize_t dp8393x_receive(NetClientState *nc, const uint8_t * buf,
     size = sizeof(uint16_t) * width;
     address_space_rw(&s->as, dp8393x_crda(s) + sizeof(uint16_t) * 5 * width,
         MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);
-    s->regs[SONIC_LLFA] = data[0 * width];
+    s->regs[SONIC_LLFA] = dp8393x_get(s, width, data, 0);
     if (s->regs[SONIC_LLFA] & 0x1) {
         /* EOL detected */
         s->regs[SONIC_ISR] |= SONIC_ISR_RDE;
     } else {
-        data[0 * width] = 0; /* in_use */
+        dp8393x_put(s, width, data, 0, 0); /* in_use */
         address_space_rw(&s->as, dp8393x_crda(s) + sizeof(uint16_t) * 6 * width,
             MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, sizeof(uint16_t), 1);
         s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA];
@@ -921,6 +946,7 @@ static Property dp8393x_properties[] = {
     DEFINE_NIC_PROPERTIES(dp8393xState, conf),
     DEFINE_PROP_PTR("dma_mr", dp8393xState, dma_mr),
     DEFINE_PROP_UINT8("it_shift", dp8393xState, it_shift, 0),
+    DEFINE_PROP_BOOL("big_endian", dp8393xState, big_endian, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
Signature · 1 line
2.14.4
#12 lore raw

Re: [Qemu-devel] [C v2 09/10] dp8393x: manage big endian bus

Quoted 57 lines · Laurent Vivier

This is needed by Quadra 800, this card can run on little-endian or big-endian bus.

---
 hw/net/dp8393x.c | 88 ++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 57 insertions(+), 31 deletions(-)
hw/net/dp8393x.c +24 -2
index f2d2ce344c..62adff9ba3 100644
@@ -150,6 +150,7 @@ typedef struct dp8393xState {
 
     /* Hardware */
     uint8_t it_shift;
+    bool big_endian;
     qemu_irq irq;
 #ifdef DEBUG_SONIC
     int irq_level;
@@ -220,6 +221,29 @@ static uint32_t dp8393x_wt(dp8393xState *s)
     return s->regs[SONIC_WT1] << 16 | s->regs[SONIC_WT0];
 }
 
+static uint16_t dp8393x_get(dp8393xState *s, int width, uint16_t *base,
+                            int offset)
+{
+    uint16_t val;
+
+    if (s->big_endian) {
+        val = be16_to_cpu(base[offset * width + width - 1]);
+    } else {
+        val = le16_to_cpu(base[offset * width]);
+    }
+    return val;
+}
+
+static void dp8393x_put(dp8393xState *s, int width, uint16_t *base, int offset,
+                        uint16_t val)
+{
+    if (s->big_endian) {
+        base[offset * width + width - 1] = cpu_to_be16(val);
+    } else {
+        base[offset * width] = cpu_to_le16(val);
+    }
+}
+
 static void dp8393x_update_irq(dp8393xState *s)
 {
     int level = (s->regs[SONIC_IMR] & s->regs[SONIC_ISR]) ? 1 : 0;
@@ -251,12 +275,12 @@ static void dp8393x_do_load_cam(dp8393xState *s)
         /* Fill current entry */
         address_space_rw(&s->as, dp8393x_cdp(s),
             MEMTXATTRS_UNSPECIFIED, (uint8_t *)data, size, 0);
-        s->cam[index][0] = data[1 * width] & 0xff;
-        s->cam[index][1] = data[1 * width] >> 8;

hw/net/dp8393x.c static void dp8393x_do_load_cam(dp8393xState *s) · line 283

Quoted 10 lines
hw/net/dp8393x.c +6 -4
-        s->cam[index][2] = data[2 * width] & 0xff;
-        s->cam[index][3] = data[2 * width] >> 8;
-        s->cam[index][4] = data[3 * width] & 0xff;
-        s->cam[index][5] = data[3 * width] >> 8;
+        s->cam[index][0] = dp8393x_get(s, width, data, 1) & 0xff;
+        s->cam[index][1] = dp8393x_get(s, width, data, 1) >> 8;
+        s->cam[index][2] = dp8393x_get(s, width, data, 2) & 0xff;
+        s->cam[index][3] = dp8393x_get(s, width, data, 2) >> 8;
+        s->cam[index][4] = dp8393x_get(s, width, data, 3) & 0xff;
+        s->cam[index][5] = dp8393x_get(s, width, data, 3) >> 8;

So if the device is used with a little endian bus, but on a big endian host, there is now an additional byte swap operation for all the values now, right? Was this a bug in the previous implementation? If so, it might be worth to mention that in the patch description?

Thomas

#13 lore raw

PATCH v2 10/10 hw/m68k: define Macintosh Quadra 800

In reply to Laurent Vivier

From: Laurent Vivier <[email protected]>

---
 MAINTAINERS                      |  19 ++
 default-configs/m68k-softmmu.mak |  14 ++
 hw/intc/Makefile.objs            |   1 +
 hw/intc/q800_irq.c               |  73 ++++++++
 hw/m68k/Makefile.objs            |   6 +-
 hw/m68k/bootinfo.h               | 100 ++++++++++
 hw/m68k/q800.c                   | 385 +++++++++++++++++++++++++++++++++++++++
 include/hw/intc/q800_irq.h       |  39 ++++
 tests/qom-test.c                 |   5 +
 tests/test-hmp.c                 |   3 +-
 10 files changed, 642 insertions(+), 3 deletions(-)
 create mode 100644 hw/intc/q800_irq.c
 create mode 100644 hw/m68k/bootinfo.h
 create mode 100644 hw/m68k/q800.c
 create mode 100644 include/hw/intc/q800_irq.h
MAINTAINERS +19 -0
index 8c626f6a07..3c7c8d891e 100644
@@ -693,6 +693,25 @@ F: hw/char/mcf_uart.c
 F: hw/net/mcf_fec.c
 F: include/hw/m68k/mcf*.h
 
+q800
+M: Laurent Vivier <[email protected]>
+S: Maintained
+F: hw/audio/asc.c
+F: hw/block/swim.c
+F: hw/m68k/bootinfo.h
+F: hw/display/macfb-template.h
+F: hw/display/macfb.c
+F: hw/intc/q800_irq.c
+F: hw/m68k/q800.c
+F: hw/misc/mac_via.c
+F: hw/nubus/*
+F: include/hw/audio/asc.h
+F: include/hw/block/swim.h
+F: include/hw/display/macfb.h
+F: include/hw/intc/q800_irq.h
+F: include/hw/misc/mac_via.h
+F: include/hw/nubus/*
+
 MicroBlaze Machines
 -------------------
 petalogix_s3adsp1800
default-configs/m68k-softmmu.mak +14 -0
index 60f7cdfbf2..993644aa42 100644
@@ -2,3 +2,17 @@
 
 CONFIG_COLDFIRE=y
 CONFIG_PTIMER=y
+CONFIG_ESCC=y
+CONFIG_FRAMEBUFFER=y
+CONFIG_ADB=y
+CONFIG_MOS6522=y
+CONFIG_MAC_VIA=y
+CONFIG_Q800_IRQ=y
+CONFIG_MAC=y
+CONFIG_SCSI=y
+CONFIG_ESP=y
+CONFIG_ASC=y
+CONFIG_MACFB=y
+CONFIG_NUBUS=y
+CONFIG_DP8393X=y
+CONFIG_SWIM=y
hw/intc/Makefile.objs +1 -0
index 0e9963f5ee..030967a0b3 100644
@@ -46,3 +46,4 @@ obj-$(CONFIG_ARM_GIC) += arm_gicv3_cpuif.o
 obj-$(CONFIG_MIPS_CPS) += mips_gic.o
 obj-$(CONFIG_NIOS2) += nios2_iic.o
 obj-$(CONFIG_OMPIC) += ompic.o
+obj-$(CONFIG_Q800_IRQ) += q800_irq.o
hw/intc/q800_irq.c new file +73 -0

73 lines not on this page · raw message

hw/m68k/Makefile.objs +4 -2
index d1f089c08a..18ebf1937a 100644
@@ -1,2 +1,4 @@
-obj-y += an5206.o mcf5208.o
-obj-y += mcf5206.o mcf_intc.o
+obj-$(CONFIG_COLDFIRE) += an5206.o mcf5208.o
+obj-$(CONFIG_MAC) += q800.o
+
+obj-$(CONFIG_COLDFIRE) += mcf5206.o mcf_intc.o
hw/m68k/bootinfo.h new file +100 -0

100 lines not on this page · raw message

hw/m68k/q800.c new file +385 -0

385 lines not on this page · raw message

include/hw/intc/q800_irq.h new file +39 -0
new file mode 100644
index 0000000000..91c2de1cc5
@@ -0,0 +1,39 @@
+/*
+ * QEMU Motorla 680x0 Macintosh hardware System Emulator
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef Q800_IRQ_H
+#define Q800_IRQ_H
+
+#include "hw/sysbus.h"
+
+#define TYPE_Q800_IRQC "q800-irq-controller"
+#define Q800_IRQC(obj) OBJECT_CHECK(Q800IRQControllerState, (obj), \
+                                    TYPE_Q800_IRQC)
+
+typedef struct Q800IRQControllerState {
+    SysBusDevice parent_obj;
+
+    M68kCPU *cpu;
+    uint8_t ipr;
+} Q800IRQControllerState;
+
+#endif
tests/qom-test.c +5 -0
index e6f712cbd3..373699fda4 100644
@@ -19,12 +19,17 @@ static const char *blacklist_x86[] = {
     "xenfv", "xenpv", NULL
 };
 
+static const char *blacklist_m68k[] = {
+    "q800", NULL
+};
+
 static const struct {
     const char *arch;
     const char **machine;
 } blacklists[] = {
     { "i386", blacklist_x86 },
     { "x86_64", blacklist_x86 },
+    { "m68k", blacklist_m68k },
 };
 
 static bool is_blacklisted(const char *arch, const char *mach)
tests/test-hmp.c +2 -1
index 5352c9c088..f3b79d5bdf 100644
@@ -139,7 +139,8 @@ static void add_machine_test_case(const char *mname)
     char *path;
 
     /* Ignore blacklisted machines that have known problems */
-    if (!strcmp("xenfv", mname) || !strcmp("xenpv", mname)) {
+    if (!strcmp("xenfv", mname) || !strcmp("xenpv", mname) ||
+        !strcmp("q800", mname)) {
         return;
     }
 
Signature · 1 line
2.14.4
#14 lore raw

Re: [Qemu-devel] [C v2 10/10] hw/m68k: define Macintosh Quadra 800

Quoted 21 lines · Laurent Vivier

From: Laurent Vivier <[email protected]>

---
 MAINTAINERS                      |  19 ++
 default-configs/m68k-softmmu.mak |  14 ++
 hw/intc/Makefile.objs            |   1 +
 hw/intc/q800_irq.c               |  73 ++++++++
 hw/m68k/Makefile.objs            |   6 +-
 hw/m68k/bootinfo.h               | 100 ++++++++++
 hw/m68k/q800.c                   | 385 +++++++++++++++++++++++++++++++++++++++
 include/hw/intc/q800_irq.h       |  39 ++++
 tests/qom-test.c                 |   5 +
 tests/test-hmp.c                 |   3 +-
 10 files changed, 642 insertions(+), 3 deletions(-)
 create mode 100644 hw/intc/q800_irq.c
 create mode 100644 hw/m68k/bootinfo.h
 create mode 100644 hw/m68k/q800.c
 create mode 100644 include/hw/intc/q800_irq.h

[...]

hw/m68k/bootinfo.h

Quoted 6 lines
hw/m68k/bootinfo.h new file +0 -0
new file mode 100644
index 0000000000..6584775f6d
@@ -0,0 +1,100 @@

Please add a comment with copyright information, and maybe also some proper header guards.

Maybe it would also be better to rename this file to "mac-bootinfo.h" or so, to make it clear that it is not related to coldfire or other 68k boards?

Quoted 106 lines
hw/m68k/bootinfo.h new file +100 -0
+struct bi_record {
+    uint16_t tag;        /* tag ID */
+    uint16_t size;       /* size of record */
+    uint32_t data[0];    /* data */
+};
+
+/* machine independent tags */
+
+#define BI_LAST         0x0000 /* last record */
+#define BI_MACHTYPE     0x0001 /* machine type (u_long) */
+#define BI_CPUTYPE      0x0002 /* cpu type (u_long) */
+#define BI_FPUTYPE      0x0003 /* fpu type (u_long) */
+#define BI_MMUTYPE      0x0004 /* mmu type (u_long) */
+#define BI_MEMCHUNK     0x0005 /* memory chunk address and size */
+                               /* (struct mem_info) */
+#define BI_RAMDISK      0x0006 /* ramdisk address and size */
+                               /* (struct mem_info) */
+#define BI_COMMAND_LINE 0x0007 /* kernel command line parameters */
+                               /* (string) */
+
+/*  Macintosh-specific tags (all u_long) */
+
+#define BI_MAC_MODEL    0x8000  /* Mac Gestalt ID (model type) */
+#define BI_MAC_VADDR    0x8001  /* Mac video base address */
+#define BI_MAC_VDEPTH   0x8002  /* Mac video depth */
+#define BI_MAC_VROW     0x8003  /* Mac video rowbytes */
+#define BI_MAC_VDIM     0x8004  /* Mac video dimensions */
+#define BI_MAC_VLOGICAL 0x8005  /* Mac video logical base */
+#define BI_MAC_SCCBASE  0x8006  /* Mac SCC base address */
+#define BI_MAC_BTIME    0x8007  /* Mac boot time */
+#define BI_MAC_GMTBIAS  0x8008  /* Mac GMT timezone offset */
+#define BI_MAC_MEMSIZE  0x8009  /* Mac RAM size (sanity check) */
+#define BI_MAC_CPUID    0x800a  /* Mac CPU type (sanity check) */
+#define BI_MAC_ROMBASE  0x800b  /* Mac system ROM base address */
+
+/*  Macintosh hardware profile data */
+
+#define BI_MAC_VIA1BASE 0x8010  /* Mac VIA1 base address (always present) */
+#define BI_MAC_VIA2BASE 0x8011  /* Mac VIA2 base address (type varies) */
+#define BI_MAC_VIA2TYPE 0x8012  /* Mac VIA2 type (VIA, RBV, OSS) */
+#define BI_MAC_ADBTYPE  0x8013  /* Mac ADB interface type */
+#define BI_MAC_ASCBASE  0x8014  /* Mac Apple Sound Chip base address */
+#define BI_MAC_SCSI5380 0x8015  /* Mac NCR 5380 SCSI (base address, multi) */
+#define BI_MAC_SCSIDMA  0x8016  /* Mac SCSI DMA (base address) */
+#define BI_MAC_SCSI5396 0x8017  /* Mac NCR 53C96 SCSI (base address, multi) */
+#define BI_MAC_IDETYPE  0x8018  /* Mac IDE interface type */
+#define BI_MAC_IDEBASE  0x8019  /* Mac IDE interface base address */
+#define BI_MAC_NUBUS    0x801a  /* Mac Nubus type (none, regular, pseudo) */
+#define BI_MAC_SLOTMASK 0x801b  /* Mac Nubus slots present */
+#define BI_MAC_SCCTYPE  0x801c  /* Mac SCC serial type (normal, IOP) */
+#define BI_MAC_ETHTYPE  0x801d  /* Mac builtin ethernet type (Sonic, MACE */
+#define BI_MAC_ETHBASE  0x801e  /* Mac builtin ethernet base address */
+#define BI_MAC_PMU      0x801f  /* Mac power management / poweroff hardware */
+#define BI_MAC_IOP_SWIM 0x8020  /* Mac SWIM floppy IOP */
+#define BI_MAC_IOP_ADB  0x8021  /* Mac ADB IOP */
+
+#define BOOTINFO0(as, base, id) \
+    do { \
+        stw_phys(as, base, id); \
+        base += 2; \
+        stw_phys(as, base, sizeof(struct bi_record)); \
+        base += 2; \
+    } while (0)
+
+#define BOOTINFO1(as, base, id, value) \
+    do { \
+        stw_phys(as, base, id); \
+        base += 2; \
+        stw_phys(as, base, sizeof(struct bi_record) + 4); \
+        base += 2; \
+        stl_phys(as, base, value); \
+        base += 4; \
+    } while (0)
+
+#define BOOTINFO2(as, base, id, value1, value2) \
+    do { \
+        stw_phys(as, base, id); \
+        base += 2; \
+        stw_phys(as, base, sizeof(struct bi_record) + 8); \
+        base += 2; \
+        stl_phys(as, base, value1); \
+        base += 4; \
+        stl_phys(as, base, value2); \
+        base += 4; \
+    } while (0)
+
+#define BOOTINFOSTR(as, base, id, string) \
+    do { \
+        int i; \
+        stw_phys(as, base, id); \
+        base += 2; \
+        stw_phys(as, base, \
+                 (sizeof(struct bi_record) + strlen(string) + 2) & ~1); \
+        base += 2; \
+        for (i = 0; string[i]; i++) { \
+            stb_phys(as, base++, string[i]); \
+        } \
+        stb_phys(as, base++, 0); \
+        base = (parameters_base + 1) & ~1; \
+    } while (0)
hw/m68k/q800.c new file +0 -0
new file mode 100644
index 0000000000..51ad3c6c76
@@ -0,0 +1,385 @@

[...]

Quoted 25 lines
hw/m68k/q800.c new file +25 -0
+static void q800_init(MachineState *machine)
+{
+    M68kCPU *cpu = NULL;
+    int linux_boot;
+    int32_t kernel_size;
+    uint64_t elf_entry;
+    char *filename;
+    int bios_size;
+    ram_addr_t initrd_base;
+    int32_t initrd_size;
+    MemoryRegion *rom;
+    MemoryRegion *ram;
+    ram_addr_t ram_size = machine->ram_size;
+    const char *kernel_filename = machine->kernel_filename;
+    const char *initrd_filename = machine->initrd_filename;
+    const char *kernel_cmdline = machine->kernel_cmdline;
+    hwaddr parameters_base;
+    CPUState *cs;
+    DeviceState *dev;
+    DeviceState *via_dev, *pic_dev;
+    SysBusESPState *sysbus_esp;
+    ESPState *esp;
+    SysBusDevice *sysbus;
+    BusState *adb_bus;
+    NubusBus *nubus;

hw/m68k/q800.c line 134

Quoted 10 lines
hw/m68k/q800.c new file +10 -0
+    DriveInfo *fds[2];
+
+    linux_boot = (kernel_filename != NULL);
+
+    /* init CPUs */
+    cpu = M68K_CPU(cpu_create(machine->cpu_type));
+    if (!cpu) {
+            hw_error("qemu: unable to find m68k CPU definition\n");
+            exit(1);
+    }

I think the check for !cpu is not necessary anymore since 4482e05cbbb7e50e476f6a9500cf0b38913bd939 ... anyway, please don't use hw_error() for error reporting here, but rather use error_report() instead.

Quoted 24 lines
hw/m68k/q800.c new file +24 -0
+    qemu_register_reset(main_cpu_reset, cpu);
+
+    ram = g_malloc(sizeof(*ram));
+    memory_region_init_ram(ram, NULL, "m68k_mac.ram", ram_size, &error_abort);
+    memory_region_add_subregion(get_system_memory(), 0, ram);
+
+    /* IRQ controller */
+
+    pic_dev = qdev_create(NULL, TYPE_Q800_IRQC);
+    object_property_set_link(OBJECT(pic_dev), OBJECT(cpu), "cpu",
+                             &error_abort);
+    qdev_init_nofail(pic_dev);
+
+    /* VIA */
+
+    via_dev = qdev_create(NULL, TYPE_MAC_VIA);
+    qdev_init_nofail(via_dev);
+    sysbus = SYS_BUS_DEVICE(via_dev);
+    sysbus_mmio_map(sysbus, 0, VIA_BASE);
+    qdev_connect_gpio_out_named(DEVICE(sysbus), "irq", 0,
+                                qdev_get_gpio_in(pic_dev, 0));
+    qdev_connect_gpio_out_named(DEVICE(sysbus), "irq", 1,
+                                qdev_get_gpio_in(pic_dev, 1));
+

hw/m68k/q800.c line 168

Quoted 10 lines
hw/m68k/q800.c new file +10 -0
+    adb_bus = qdev_get_child_bus(via_dev, "adb.0");
+    dev = qdev_create(adb_bus, TYPE_ADB_KEYBOARD);
+    qdev_init_nofail(dev);
+    dev = qdev_create(adb_bus, TYPE_ADB_MOUSE);
+    qdev_init_nofail(dev);
+
+    /* MACSONIC */
+
+    if (nb_nics != 1) {
+        hw_error("Q800 needs a dp83932 ethernet interfaces");

That error message is certainly wrong, and please don't use hw_error() for non-cpu related errors. Maybe rather:

if (nb_nics > 1) {
error_report("Q800 can only have one ethernet interface"); exit(1);
}

?

Also please make sure that your code can run with --nodefaults, too. (The NIC can be created but simply not be connected in that case)

hw/m68k/q800.c line 174

Quoted 6 lines
hw/m68k/q800.c new file +6 -0
+    }
+    if (!nd_table[0].model) {
+        nd_table[0].model = g_strdup("dp83932");
+    }
+    if (strcmp(nd_table[0].model, "dp83932") != 0) {
+        hw_error("Q800 needs a dp83932 ethernet interfaces");

Simply rely on the qemu_check_nic_model() below instead?

Quoted 16 lines
hw/m68k/q800.c new file +16 -0
+    } else {
+        /* MacSonic driver needs an Apple MAC address
+         * Valid prefix are:
+         * 00:05:02 Apple
+         * 00:80:19 Dayna Communications, Inc.
+         * 00:A0:40 Apple
+         * 08:00:07 Apple
+         * (Q800 use the last one)
+         */
+        nd_table[0].macaddr.a[0] = 0x08;
+        nd_table[0].macaddr.a[1] = 0x00;
+        nd_table[0].macaddr.a[2] = 0x07;
+    }
+    qemu_check_nic_model(&nd_table[0], "dp83932");
+    dev = qdev_create(NULL, "dp8393x");
+    qdev_set_nic_properties(dev, &nd_table[0]);

[...]

hw/m68k/q800.c line 254

Quoted 4 lines
hw/m68k/q800.c new file +4 -0
+    /* SWIM floppy controller */
+
+    if (drive_get_max_bus(IF_FLOPPY) >= 2) {
+        fprintf(stderr, "qemu: too many floppy drives\n");

error_report() please.

Quoted 4 lines
hw/m68k/q800.c new file +4 -0
+        exit(1);
+    }
+    fds[0] = drive_get(IF_FLOPPY, 0, 0);
+    fds[1] = drive_get(IF_FLOPPY, 0, 1);

[...]

hw/m68k/q800.c line 330

Quoted 6 lines
hw/m68k/q800.c new file +6 -0
+        /* load initrd */
+        if (initrd_filename) {
+            initrd_size = get_image_size(initrd_filename);
+            if (initrd_size < 0) {
+                hw_error("qemu: could not load initial ram disk '%s'\n",
+                         initrd_filename);

error_report() please.

Quoted 25 lines
hw/m68k/q800.c new file +25 -0
+                exit(1);
+            }
+
+            initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK;
+            load_image_targphys(initrd_filename, initrd_base,
+                                ram_size - initrd_base);
+            BOOTINFO2(cs->as, parameters_base, BI_RAMDISK, initrd_base,
+                      initrd_size);
+        } else {
+            initrd_base = 0;
+            initrd_size = 0;
+        }
+        BOOTINFO0(cs->as, parameters_base, BI_LAST);
+    } else {
+        uint8_t *ptr;
+        /* allocate and load BIOS */
+        rom = g_malloc(sizeof(*rom));
+        memory_region_init_ram(rom, NULL, "m68k_mac.rom", MACROM_SIZE,
+                               &error_abort);
+        if (bios_name == NULL) {
+            bios_name = MACROM_FILENAME;
+        }
+        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+        memory_region_set_readonly(rom, true);
+        memory_region_add_subregion(get_system_memory(), MACROM_ADDR, rom);

hw/m68k/q800.c line 365

Quoted 10 lines
hw/m68k/q800.c new file +10 -0
+
+        /* Load MacROM binary */
+        if (filename) {
+            bios_size = load_image_targphys(filename, MACROM_ADDR, MACROM_SIZE);
+            g_free(filename);
+        } else {
+            bios_size = -1;
+        }
+        if (bios_size < 0 || bios_size > MACROM_SIZE) {
+            hw_error("qemu: could not load MacROM '%s'\n", bios_name);

error_report() please.

Quoted 8 lines
hw/m68k/q800.c new file +8 -0
+            exit(1);
+        }
+        ptr = rom_ptr(MACROM_ADDR);
+        stl_phys(cs->as, 0, ldl_p(ptr));    /* reset initial SP */
+        stl_phys(cs->as, 4,
+                 MACROM_ADDR + ldl_p(ptr + 4)); /* reset initial PC */
+    }
+}

[...]

Quoted 27 lines
tests/qom-test.c +5 -0
index e6f712cbd3..373699fda4 100644
@@ -19,12 +19,17 @@ static const char *blacklist_x86[] = {
     "xenfv", "xenpv", NULL
 };
 
+static const char *blacklist_m68k[] = {
+    "q800", NULL
+};
+
 static const struct {
     const char *arch;
     const char **machine;
 } blacklists[] = {
     { "i386", blacklist_x86 },
     { "x86_64", blacklist_x86 },
+    { "m68k", blacklist_m68k },
 };
 
 static bool is_blacklisted(const char *arch, const char *mach)
tests/test-hmp.c +0 -0
index 5352c9c088..f3b79d5bdf 100644

tests/test-hmp.c static void add_machine_test_case(const char *mname) · line 145

Quoted 8 lines
tests/test-hmp.c +2 -1
@@ -139,7 +139,8 @@ static void add_machine_test_case(const char *mname)
     char *path;
 
     /* Ignore blacklisted machines that have known problems */
-    if (!strcmp("xenfv", mname) || !strcmp("xenpv", mname)) {
+    if (!strcmp("xenfv", mname) || !strcmp("xenpv", mname) ||
+        !strcmp("q800", mname)) {
         return;
     }

Introducing a new machine and immediately black-listing it in the tests is super ugly. What's the problem here, and why can't you fix them? You need at least to elaborate on that topic in the patch description.

Thomas