1 /* 2 * QEMU Motorla 680x0 Macintosh hardware System Emulator 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 * THE SOFTWARE. 21 */ 22 23 #include "qemu/osdep.h" 24 #include "qemu/units.h" 25 #include "qemu/datadir.h" 26 #include "qemu/guest-random.h" 27 #include "sysemu/sysemu.h" 28 #include "cpu.h" 29 #include "hw/boards.h" 30 #include "hw/or-irq.h" 31 #include "elf.h" 32 #include "hw/loader.h" 33 #include "ui/console.h" 34 #include "hw/char/escc.h" 35 #include "hw/sysbus.h" 36 #include "hw/scsi/esp.h" 37 #include "standard-headers/asm-m68k/bootinfo.h" 38 #include "standard-headers/asm-m68k/bootinfo-mac.h" 39 #include "bootinfo.h" 40 #include "hw/m68k/q800.h" 41 #include "hw/m68k/q800-glue.h" 42 #include "hw/misc/mac_via.h" 43 #include "hw/misc/djmemc.h" 44 #include "hw/misc/iosb.h" 45 #include "hw/input/adb.h" 46 #include "hw/audio/asc.h" 47 #include "hw/nubus/mac-nubus-bridge.h" 48 #include "hw/display/macfb.h" 49 #include "hw/block/swim.h" 50 #include "net/net.h" 51 #include "qapi/error.h" 52 #include "qemu/error-report.h" 53 #include "sysemu/qtest.h" 54 #include "sysemu/runstate.h" 55 #include "sysemu/reset.h" 56 #include "migration/vmstate.h" 57 58 #define MACROM_ADDR 0x40800000 59 #define MACROM_SIZE 0x00100000 60 61 #define MACROM_FILENAME "MacROM.bin" 62 63 #define IO_BASE 0x50000000 64 #define IO_SLICE 0x00040000 65 #define IO_SLICE_MASK (IO_SLICE - 1) 66 #define IO_SIZE 0x04000000 67 68 #define VIA_BASE (IO_BASE + 0x00000) 69 #define SONIC_PROM_BASE (IO_BASE + 0x08000) 70 #define SONIC_BASE (IO_BASE + 0x0a000) 71 #define SCC_BASE (IO_BASE + 0x0c020) 72 #define DJMEMC_BASE (IO_BASE + 0x0e000) 73 #define ESP_BASE (IO_BASE + 0x10000) 74 #define ESP_PDMA (IO_BASE + 0x10100) 75 #define ASC_BASE (IO_BASE + 0x14000) 76 #define IOSB_BASE (IO_BASE + 0x18000) 77 #define SWIM_BASE (IO_BASE + 0x1E000) 78 79 #define SONIC_PROM_SIZE 0x1000 80 81 /* 82 * the video base, whereas it a Nubus address, 83 * is needed by the kernel to have early display and 84 * thus provided by the bootloader 85 */ 86 #define VIDEO_BASE 0xf9000000 87 88 #define MAC_CLOCK 3686418 89 90 /* Size of whole RAM area */ 91 #define RAM_SIZE 0x40000000 92 93 /* 94 * Slot 0x9 is reserved for use by the in-built framebuffer whilst only 95 * slots 0xc, 0xd and 0xe physically exist on the Quadra 800 96 */ 97 #define Q800_NUBUS_SLOTS_AVAILABLE (BIT(0x9) | BIT(0xc) | BIT(0xd) | \ 98 BIT(0xe)) 99 100 /* Quadra 800 machine ID */ 101 #define Q800_MACHINE_ID 0xa55a2bad 102 103 104 static void main_cpu_reset(void *opaque) 105 { 106 M68kCPU *cpu = opaque; 107 CPUState *cs = CPU(cpu); 108 109 cpu_reset(cs); 110 cpu->env.aregs[7] = ldl_phys(cs->as, 0); 111 cpu->env.pc = ldl_phys(cs->as, 4); 112 } 113 114 static void rerandomize_rng_seed(void *opaque) 115 { 116 struct bi_record *rng_seed = opaque; 117 qemu_guest_getrandom_nofail((void *)rng_seed->data + 2, 118 be16_to_cpu(*(uint16_t *)rng_seed->data)); 119 } 120 121 static uint8_t fake_mac_rom[] = { 122 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123 124 /* offset: 0xa - mac_reset */ 125 126 /* via2[vDirB] |= VIA2B_vPower */ 127 0x20, 0x7C, 0x50, 0xF0, 0x24, 0x00, /* moveal VIA2_BASE+vDirB,%a0 */ 128 0x10, 0x10, /* moveb %a0@,%d0 */ 129 0x00, 0x00, 0x00, 0x04, /* orib #4,%d0 */ 130 0x10, 0x80, /* moveb %d0,%a0@ */ 131 132 /* via2[vBufB] &= ~VIA2B_vPower */ 133 0x20, 0x7C, 0x50, 0xF0, 0x20, 0x00, /* moveal VIA2_BASE+vBufB,%a0 */ 134 0x10, 0x10, /* moveb %a0@,%d0 */ 135 0x02, 0x00, 0xFF, 0xFB, /* andib #-5,%d0 */ 136 0x10, 0x80, /* moveb %d0,%a0@ */ 137 138 /* while (true) ; */ 139 0x60, 0xFE /* bras [self] */ 140 }; 141 142 static MemTxResult macio_alias_read(void *opaque, hwaddr addr, uint64_t *data, 143 unsigned size, MemTxAttrs attrs) 144 { 145 MemTxResult r; 146 uint32_t val; 147 148 addr &= IO_SLICE_MASK; 149 addr |= IO_BASE; 150 151 switch (size) { 152 case 4: 153 val = address_space_ldl_be(&address_space_memory, addr, attrs, &r); 154 break; 155 case 2: 156 val = address_space_lduw_be(&address_space_memory, addr, attrs, &r); 157 break; 158 case 1: 159 val = address_space_ldub(&address_space_memory, addr, attrs, &r); 160 break; 161 default: 162 g_assert_not_reached(); 163 } 164 165 *data = val; 166 return r; 167 } 168 169 static MemTxResult macio_alias_write(void *opaque, hwaddr addr, uint64_t value, 170 unsigned size, MemTxAttrs attrs) 171 { 172 MemTxResult r; 173 174 addr &= IO_SLICE_MASK; 175 addr |= IO_BASE; 176 177 switch (size) { 178 case 4: 179 address_space_stl_be(&address_space_memory, addr, value, attrs, &r); 180 break; 181 case 2: 182 address_space_stw_be(&address_space_memory, addr, value, attrs, &r); 183 break; 184 case 1: 185 address_space_stb(&address_space_memory, addr, value, attrs, &r); 186 break; 187 default: 188 g_assert_not_reached(); 189 } 190 191 return r; 192 } 193 194 static const MemoryRegionOps macio_alias_ops = { 195 .read_with_attrs = macio_alias_read, 196 .write_with_attrs = macio_alias_write, 197 .endianness = DEVICE_BIG_ENDIAN, 198 .valid = { 199 .min_access_size = 1, 200 .max_access_size = 4, 201 }, 202 }; 203 204 static uint64_t machine_id_read(void *opaque, hwaddr addr, unsigned size) 205 { 206 return Q800_MACHINE_ID; 207 } 208 209 static void machine_id_write(void *opaque, hwaddr addr, uint64_t val, 210 unsigned size) 211 { 212 return; 213 } 214 215 static const MemoryRegionOps machine_id_ops = { 216 .read = machine_id_read, 217 .write = machine_id_write, 218 .endianness = DEVICE_BIG_ENDIAN, 219 .valid = { 220 .min_access_size = 4, 221 .max_access_size = 4, 222 }, 223 }; 224 225 static uint64_t ramio_read(void *opaque, hwaddr addr, unsigned size) 226 { 227 return 0x0; 228 } 229 230 static void ramio_write(void *opaque, hwaddr addr, uint64_t val, 231 unsigned size) 232 { 233 return; 234 } 235 236 static const MemoryRegionOps ramio_ops = { 237 .read = ramio_read, 238 .write = ramio_write, 239 .endianness = DEVICE_BIG_ENDIAN, 240 .valid = { 241 .min_access_size = 1, 242 .max_access_size = 4, 243 }, 244 }; 245 246 static void q800_machine_init(MachineState *machine) 247 { 248 Q800MachineState *m = Q800_MACHINE(machine); 249 int linux_boot; 250 int32_t kernel_size; 251 uint64_t elf_entry; 252 char *filename; 253 int bios_size; 254 ram_addr_t initrd_base; 255 int32_t initrd_size; 256 uint8_t *prom; 257 int i, checksum; 258 MacFbMode *macfb_mode; 259 ram_addr_t ram_size = machine->ram_size; 260 const char *kernel_filename = machine->kernel_filename; 261 const char *initrd_filename = machine->initrd_filename; 262 const char *kernel_cmdline = machine->kernel_cmdline; 263 const char *bios_name = machine->firmware ?: MACROM_FILENAME; 264 hwaddr parameters_base; 265 CPUState *cs; 266 DeviceState *dev; 267 SysBusESPState *sysbus_esp; 268 ESPState *esp; 269 SysBusDevice *sysbus; 270 BusState *adb_bus; 271 NubusBus *nubus; 272 DriveInfo *dinfo; 273 uint8_t rng_seed[32]; 274 275 linux_boot = (kernel_filename != NULL); 276 277 if (ram_size > 1 * GiB) { 278 error_report("Too much memory for this machine: %" PRId64 " MiB, " 279 "maximum 1024 MiB", ram_size / MiB); 280 exit(1); 281 } 282 283 /* init CPUs */ 284 object_initialize_child(OBJECT(machine), "cpu", &m->cpu, machine->cpu_type); 285 qdev_realize(DEVICE(&m->cpu), NULL, &error_fatal); 286 qemu_register_reset(main_cpu_reset, &m->cpu); 287 288 /* RAM */ 289 memory_region_init_io(&m->ramio, OBJECT(machine), &ramio_ops, &m->ramio, 290 "ram", RAM_SIZE); 291 memory_region_add_subregion(get_system_memory(), 0x0, &m->ramio); 292 293 memory_region_add_subregion(&m->ramio, 0, machine->ram); 294 295 /* 296 * Create container for all IO devices 297 */ 298 memory_region_init(&m->macio, OBJECT(machine), "mac-io", IO_SLICE); 299 memory_region_add_subregion(get_system_memory(), IO_BASE, &m->macio); 300 301 /* 302 * Memory from IO_BASE to IO_BASE + IO_SLICE is repeated 303 * from IO_BASE + IO_SLICE to IO_BASE + IO_SIZE 304 */ 305 memory_region_init_io(&m->macio_alias, OBJECT(machine), &macio_alias_ops, 306 &m->macio, "mac-io.alias", IO_SIZE - IO_SLICE); 307 memory_region_add_subregion(get_system_memory(), IO_BASE + IO_SLICE, 308 &m->macio_alias); 309 310 memory_region_init_io(&m->machine_id, NULL, &machine_id_ops, NULL, 311 "Machine ID", 4); 312 memory_region_add_subregion(get_system_memory(), 0x5ffffffc, 313 &m->machine_id); 314 315 /* IRQ Glue */ 316 object_initialize_child(OBJECT(machine), "glue", &m->glue, TYPE_GLUE); 317 object_property_set_link(OBJECT(&m->glue), "cpu", OBJECT(&m->cpu), 318 &error_abort); 319 sysbus_realize(SYS_BUS_DEVICE(&m->glue), &error_fatal); 320 321 /* djMEMC memory controller */ 322 object_initialize_child(OBJECT(machine), "djmemc", &m->djmemc, 323 TYPE_DJMEMC); 324 sysbus = SYS_BUS_DEVICE(&m->djmemc); 325 sysbus_realize_and_unref(sysbus, &error_fatal); 326 memory_region_add_subregion(&m->macio, DJMEMC_BASE - IO_BASE, 327 sysbus_mmio_get_region(sysbus, 0)); 328 329 /* IOSB subsystem */ 330 object_initialize_child(OBJECT(machine), "iosb", &m->iosb, TYPE_IOSB); 331 sysbus = SYS_BUS_DEVICE(&m->iosb); 332 sysbus_realize_and_unref(sysbus, &error_fatal); 333 memory_region_add_subregion(&m->macio, IOSB_BASE - IO_BASE, 334 sysbus_mmio_get_region(sysbus, 0)); 335 336 /* VIA 1 */ 337 object_initialize_child(OBJECT(machine), "via1", &m->via1, 338 TYPE_MOS6522_Q800_VIA1); 339 dinfo = drive_get(IF_MTD, 0, 0); 340 if (dinfo) { 341 qdev_prop_set_drive(DEVICE(&m->via1), "drive", 342 blk_by_legacy_dinfo(dinfo)); 343 } 344 sysbus = SYS_BUS_DEVICE(&m->via1); 345 sysbus_realize(sysbus, &error_fatal); 346 memory_region_add_subregion(&m->macio, VIA_BASE - IO_BASE, 347 sysbus_mmio_get_region(sysbus, 1)); 348 sysbus_connect_irq(sysbus, 0, 349 qdev_get_gpio_in(DEVICE(&m->glue), GLUE_IRQ_IN_VIA1)); 350 /* A/UX mode */ 351 qdev_connect_gpio_out(DEVICE(&m->via1), 0, 352 qdev_get_gpio_in_named(DEVICE(&m->glue), 353 "auxmode", 0)); 354 355 adb_bus = qdev_get_child_bus(DEVICE(&m->via1), "adb.0"); 356 dev = qdev_new(TYPE_ADB_KEYBOARD); 357 qdev_realize_and_unref(dev, adb_bus, &error_fatal); 358 dev = qdev_new(TYPE_ADB_MOUSE); 359 qdev_realize_and_unref(dev, adb_bus, &error_fatal); 360 361 /* VIA 2 */ 362 object_initialize_child(OBJECT(machine), "via2", &m->via2, 363 TYPE_MOS6522_Q800_VIA2); 364 sysbus = SYS_BUS_DEVICE(&m->via2); 365 sysbus_realize(sysbus, &error_fatal); 366 memory_region_add_subregion(&m->macio, VIA_BASE - IO_BASE + VIA_SIZE, 367 sysbus_mmio_get_region(sysbus, 1)); 368 sysbus_connect_irq(sysbus, 0, 369 qdev_get_gpio_in(DEVICE(&m->glue), GLUE_IRQ_IN_VIA2)); 370 371 /* MACSONIC */ 372 373 if (nb_nics > 1) { 374 error_report("q800 can only have one ethernet interface"); 375 exit(1); 376 } 377 378 qemu_check_nic_model(&nd_table[0], "dp83932"); 379 380 /* 381 * MacSonic driver needs an Apple MAC address 382 * Valid prefix are: 383 * 00:05:02 Apple 384 * 00:80:19 Dayna Communications, Inc. 385 * 00:A0:40 Apple 386 * 08:00:07 Apple 387 * (Q800 use the last one) 388 */ 389 nd_table[0].macaddr.a[0] = 0x08; 390 nd_table[0].macaddr.a[1] = 0x00; 391 nd_table[0].macaddr.a[2] = 0x07; 392 393 object_initialize_child(OBJECT(machine), "dp8393x", &m->dp8393x, 394 TYPE_DP8393X); 395 dev = DEVICE(&m->dp8393x); 396 qdev_set_nic_properties(dev, &nd_table[0]); 397 qdev_prop_set_uint8(dev, "it_shift", 2); 398 qdev_prop_set_bit(dev, "big_endian", true); 399 object_property_set_link(OBJECT(dev), "dma_mr", 400 OBJECT(get_system_memory()), &error_abort); 401 sysbus = SYS_BUS_DEVICE(dev); 402 sysbus_realize(sysbus, &error_fatal); 403 memory_region_add_subregion(&m->macio, SONIC_BASE - IO_BASE, 404 sysbus_mmio_get_region(sysbus, 0)); 405 sysbus_connect_irq(sysbus, 0, 406 qdev_get_gpio_in(DEVICE(&m->glue), GLUE_IRQ_IN_SONIC)); 407 408 memory_region_init_rom(&m->dp8393x_prom, NULL, "dp8393x-q800.prom", 409 SONIC_PROM_SIZE, &error_fatal); 410 memory_region_add_subregion(get_system_memory(), SONIC_PROM_BASE, 411 &m->dp8393x_prom); 412 413 /* Add MAC address with valid checksum to PROM */ 414 prom = memory_region_get_ram_ptr(&m->dp8393x_prom); 415 checksum = 0; 416 for (i = 0; i < 6; i++) { 417 prom[i] = revbit8(nd_table[0].macaddr.a[i]); 418 checksum ^= prom[i]; 419 } 420 prom[7] = 0xff - checksum; 421 422 /* SCC */ 423 424 object_initialize_child(OBJECT(machine), "escc", &m->escc, 425 TYPE_ESCC); 426 dev = DEVICE(&m->escc); 427 qdev_prop_set_uint32(dev, "disabled", 0); 428 qdev_prop_set_uint32(dev, "frequency", MAC_CLOCK); 429 qdev_prop_set_uint32(dev, "it_shift", 1); 430 qdev_prop_set_bit(dev, "bit_swap", true); 431 qdev_prop_set_chr(dev, "chrA", serial_hd(0)); 432 qdev_prop_set_chr(dev, "chrB", serial_hd(1)); 433 qdev_prop_set_uint32(dev, "chnBtype", 0); 434 qdev_prop_set_uint32(dev, "chnAtype", 0); 435 sysbus = SYS_BUS_DEVICE(dev); 436 sysbus_realize(sysbus, &error_fatal); 437 438 /* Logically OR both its IRQs together */ 439 object_initialize_child(OBJECT(machine), "escc_orgate", &m->escc_orgate, 440 TYPE_OR_IRQ); 441 object_property_set_int(OBJECT(&m->escc_orgate), "num-lines", 2, 442 &error_fatal); 443 dev = DEVICE(&m->escc_orgate); 444 qdev_realize(dev, NULL, &error_fatal); 445 sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(dev, 0)); 446 sysbus_connect_irq(sysbus, 1, qdev_get_gpio_in(dev, 1)); 447 qdev_connect_gpio_out(dev, 0, 448 qdev_get_gpio_in(DEVICE(&m->glue), 449 GLUE_IRQ_IN_ESCC)); 450 memory_region_add_subregion(&m->macio, SCC_BASE - IO_BASE, 451 sysbus_mmio_get_region(sysbus, 0)); 452 453 /* Create alias for NetBSD */ 454 memory_region_init_alias(&m->escc_alias, OBJECT(machine), "escc-alias", 455 sysbus_mmio_get_region(sysbus, 0), 0, 0x8); 456 memory_region_add_subregion(&m->macio, SCC_BASE - IO_BASE - 0x20, 457 &m->escc_alias); 458 459 /* SCSI */ 460 461 object_initialize_child(OBJECT(machine), "esp", &m->esp, 462 TYPE_SYSBUS_ESP); 463 sysbus_esp = SYSBUS_ESP(&m->esp); 464 esp = &sysbus_esp->esp; 465 esp->dma_memory_read = NULL; 466 esp->dma_memory_write = NULL; 467 esp->dma_opaque = NULL; 468 sysbus_esp->it_shift = 4; 469 esp->dma_enabled = 1; 470 471 sysbus = SYS_BUS_DEVICE(&m->esp); 472 sysbus_realize(sysbus, &error_fatal); 473 /* SCSI and SCSI data IRQs are negative edge triggered */ 474 sysbus_connect_irq(sysbus, 0, 475 qemu_irq_invert( 476 qdev_get_gpio_in(DEVICE(&m->via2), 477 VIA2_IRQ_SCSI_BIT))); 478 sysbus_connect_irq(sysbus, 1, 479 qemu_irq_invert( 480 qdev_get_gpio_in(DEVICE(&m->via2), 481 VIA2_IRQ_SCSI_DATA_BIT))); 482 memory_region_add_subregion(&m->macio, ESP_BASE - IO_BASE, 483 sysbus_mmio_get_region(sysbus, 0)); 484 memory_region_add_subregion(&m->macio, ESP_PDMA - IO_BASE, 485 sysbus_mmio_get_region(sysbus, 1)); 486 487 scsi_bus_legacy_handle_cmdline(&esp->bus); 488 489 /* Apple Sound Chip */ 490 491 object_initialize_child(OBJECT(machine), "asc", &m->asc, TYPE_ASC); 492 qdev_prop_set_uint8(DEVICE(&m->asc), "asctype", m->easc ? ASC_TYPE_EASC 493 : ASC_TYPE_ASC); 494 if (machine->audiodev) { 495 qdev_prop_set_string(DEVICE(&m->asc), "audiodev", machine->audiodev); 496 } 497 sysbus = SYS_BUS_DEVICE(&m->asc); 498 sysbus_realize_and_unref(sysbus, &error_fatal); 499 memory_region_add_subregion(&m->macio, ASC_BASE - IO_BASE, 500 sysbus_mmio_get_region(sysbus, 0)); 501 sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(DEVICE(&m->glue), 502 GLUE_IRQ_IN_ASC)); 503 504 /* Wire ASC IRQ via GLUE for use in classic mode */ 505 qdev_connect_gpio_out(DEVICE(&m->glue), GLUE_IRQ_ASC, 506 qdev_get_gpio_in(DEVICE(&m->via2), 507 VIA2_IRQ_ASC_BIT)); 508 509 /* SWIM floppy controller */ 510 511 object_initialize_child(OBJECT(machine), "swim", &m->swim, 512 TYPE_SWIM); 513 sysbus = SYS_BUS_DEVICE(&m->swim); 514 sysbus_realize(sysbus, &error_fatal); 515 memory_region_add_subregion(&m->macio, SWIM_BASE - IO_BASE, 516 sysbus_mmio_get_region(sysbus, 0)); 517 518 /* NuBus */ 519 520 object_initialize_child(OBJECT(machine), "mac-nubus-bridge", 521 &m->mac_nubus_bridge, 522 TYPE_MAC_NUBUS_BRIDGE); 523 sysbus = SYS_BUS_DEVICE(&m->mac_nubus_bridge); 524 dev = DEVICE(&m->mac_nubus_bridge); 525 qdev_prop_set_uint32(DEVICE(&m->mac_nubus_bridge), "slot-available-mask", 526 Q800_NUBUS_SLOTS_AVAILABLE); 527 sysbus_realize(sysbus, &error_fatal); 528 memory_region_add_subregion(get_system_memory(), 529 MAC_NUBUS_FIRST_SLOT * NUBUS_SUPER_SLOT_SIZE, 530 sysbus_mmio_get_region(sysbus, 0)); 531 memory_region_add_subregion(get_system_memory(), 532 NUBUS_SLOT_BASE + 533 MAC_NUBUS_FIRST_SLOT * NUBUS_SLOT_SIZE, 534 sysbus_mmio_get_region(sysbus, 1)); 535 qdev_connect_gpio_out(dev, 9, 536 qdev_get_gpio_in_named(DEVICE(&m->via2), "nubus-irq", 537 VIA2_NUBUS_IRQ_INTVIDEO)); 538 for (i = 1; i < VIA2_NUBUS_IRQ_NB; i++) { 539 qdev_connect_gpio_out(dev, 9 + i, 540 qdev_get_gpio_in_named(DEVICE(&m->via2), 541 "nubus-irq", 542 VIA2_NUBUS_IRQ_9 + i)); 543 } 544 545 /* 546 * Since the framebuffer in slot 0x9 uses a separate IRQ, wire the unused 547 * IRQ via GLUE for use by SONIC Ethernet in classic mode 548 */ 549 qdev_connect_gpio_out(DEVICE(&m->glue), GLUE_IRQ_NUBUS_9, 550 qdev_get_gpio_in_named(DEVICE(&m->via2), "nubus-irq", 551 VIA2_NUBUS_IRQ_9)); 552 553 nubus = NUBUS_BUS(qdev_get_child_bus(dev, "nubus-bus.0")); 554 555 /* framebuffer in nubus slot #9 */ 556 557 object_initialize_child(OBJECT(machine), "macfb", &m->macfb, 558 TYPE_NUBUS_MACFB); 559 dev = DEVICE(&m->macfb); 560 qdev_prop_set_uint32(dev, "slot", 9); 561 qdev_prop_set_uint32(dev, "width", graphic_width); 562 qdev_prop_set_uint32(dev, "height", graphic_height); 563 qdev_prop_set_uint8(dev, "depth", graphic_depth); 564 if (graphic_width == 1152 && graphic_height == 870) { 565 qdev_prop_set_uint8(dev, "display", MACFB_DISPLAY_APPLE_21_COLOR); 566 } else { 567 qdev_prop_set_uint8(dev, "display", MACFB_DISPLAY_VGA); 568 } 569 qdev_realize(dev, BUS(nubus), &error_fatal); 570 571 macfb_mode = (NUBUS_MACFB(dev)->macfb).mode; 572 573 cs = CPU(&m->cpu); 574 if (linux_boot) { 575 uint64_t high; 576 void *param_blob, *param_ptr, *param_rng_seed; 577 578 if (kernel_cmdline) { 579 param_blob = g_malloc(strlen(kernel_cmdline) + 1024); 580 } else { 581 param_blob = g_malloc(1024); 582 } 583 584 kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, 585 &elf_entry, NULL, &high, NULL, 1, 586 EM_68K, 0, 0); 587 if (kernel_size < 0) { 588 error_report("could not load kernel '%s'", kernel_filename); 589 exit(1); 590 } 591 stl_phys(cs->as, 4, elf_entry); /* reset initial PC */ 592 parameters_base = (high + 1) & ~1; 593 param_ptr = param_blob; 594 595 BOOTINFO1(param_ptr, BI_MACHTYPE, MACH_MAC); 596 BOOTINFO1(param_ptr, BI_FPUTYPE, FPU_68040); 597 BOOTINFO1(param_ptr, BI_MMUTYPE, MMU_68040); 598 BOOTINFO1(param_ptr, BI_CPUTYPE, CPU_68040); 599 BOOTINFO1(param_ptr, BI_MAC_CPUID, CPUB_68040); 600 BOOTINFO1(param_ptr, BI_MAC_MODEL, MAC_MODEL_Q800); 601 BOOTINFO1(param_ptr, 602 BI_MAC_MEMSIZE, ram_size >> 20); /* in MB */ 603 BOOTINFO2(param_ptr, BI_MEMCHUNK, 0, ram_size); 604 BOOTINFO1(param_ptr, BI_MAC_VADDR, 605 VIDEO_BASE + macfb_mode->offset); 606 BOOTINFO1(param_ptr, BI_MAC_VDEPTH, graphic_depth); 607 BOOTINFO1(param_ptr, BI_MAC_VDIM, 608 (graphic_height << 16) | graphic_width); 609 BOOTINFO1(param_ptr, BI_MAC_VROW, macfb_mode->stride); 610 BOOTINFO1(param_ptr, BI_MAC_SCCBASE, SCC_BASE); 611 612 memory_region_init_ram_ptr(&m->rom, NULL, "m68k_fake_mac.rom", 613 sizeof(fake_mac_rom), fake_mac_rom); 614 memory_region_set_readonly(&m->rom, true); 615 memory_region_add_subregion(get_system_memory(), MACROM_ADDR, &m->rom); 616 617 if (kernel_cmdline) { 618 BOOTINFOSTR(param_ptr, BI_COMMAND_LINE, 619 kernel_cmdline); 620 } 621 622 /* Pass seed to RNG. */ 623 param_rng_seed = param_ptr; 624 qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); 625 BOOTINFODATA(param_ptr, BI_RNG_SEED, 626 rng_seed, sizeof(rng_seed)); 627 628 /* load initrd */ 629 if (initrd_filename) { 630 initrd_size = get_image_size(initrd_filename); 631 if (initrd_size < 0) { 632 error_report("could not load initial ram disk '%s'", 633 initrd_filename); 634 exit(1); 635 } 636 637 initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK; 638 load_image_targphys(initrd_filename, initrd_base, 639 ram_size - initrd_base); 640 BOOTINFO2(param_ptr, BI_RAMDISK, initrd_base, 641 initrd_size); 642 } else { 643 initrd_base = 0; 644 initrd_size = 0; 645 } 646 BOOTINFO0(param_ptr, BI_LAST); 647 rom_add_blob_fixed_as("bootinfo", param_blob, param_ptr - param_blob, 648 parameters_base, cs->as); 649 qemu_register_reset_nosnapshotload(rerandomize_rng_seed, 650 rom_ptr_for_as(cs->as, parameters_base, 651 param_ptr - param_blob) + 652 (param_rng_seed - param_blob)); 653 g_free(param_blob); 654 } else { 655 uint8_t *ptr; 656 /* allocate and load BIOS */ 657 memory_region_init_rom(&m->rom, NULL, "m68k_mac.rom", MACROM_SIZE, 658 &error_abort); 659 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); 660 memory_region_add_subregion(get_system_memory(), MACROM_ADDR, &m->rom); 661 662 memory_region_init_alias(&m->rom_alias, NULL, "m68k_mac.rom-alias", 663 &m->rom, 0, MACROM_SIZE); 664 memory_region_add_subregion(get_system_memory(), 0x40000000, 665 &m->rom_alias); 666 667 /* Load MacROM binary */ 668 if (filename) { 669 bios_size = load_image_targphys(filename, MACROM_ADDR, MACROM_SIZE); 670 g_free(filename); 671 } else { 672 bios_size = -1; 673 } 674 675 /* Remove qtest_enabled() check once firmware files are in the tree */ 676 if (!qtest_enabled()) { 677 if (bios_size <= 0 || bios_size > MACROM_SIZE) { 678 error_report("could not load MacROM '%s'", bios_name); 679 exit(1); 680 } 681 682 ptr = rom_ptr(MACROM_ADDR, bios_size); 683 assert(ptr != NULL); 684 stl_phys(cs->as, 0, ldl_p(ptr)); /* reset initial SP */ 685 stl_phys(cs->as, 4, 686 MACROM_ADDR + ldl_p(ptr + 4)); /* reset initial PC */ 687 } 688 } 689 } 690 691 static bool q800_get_easc(Object *obj, Error **errp) 692 { 693 Q800MachineState *ms = Q800_MACHINE(obj); 694 695 return ms->easc; 696 } 697 698 static void q800_set_easc(Object *obj, bool value, Error **errp) 699 { 700 Q800MachineState *ms = Q800_MACHINE(obj); 701 702 ms->easc = value; 703 } 704 705 static void q800_init(Object *obj) 706 { 707 Q800MachineState *ms = Q800_MACHINE(obj); 708 709 /* Default to EASC */ 710 ms->easc = true; 711 } 712 713 static GlobalProperty hw_compat_q800[] = { 714 { "scsi-hd", "quirk_mode_page_vendor_specific_apple", "on" }, 715 { "scsi-hd", "vendor", " SEAGATE" }, 716 { "scsi-hd", "product", " ST225N" }, 717 { "scsi-hd", "ver", "1.0 " }, 718 { "scsi-cd", "quirk_mode_page_apple_vendor", "on" }, 719 { "scsi-cd", "quirk_mode_sense_rom_use_dbd", "on" }, 720 { "scsi-cd", "quirk_mode_page_vendor_specific_apple", "on" }, 721 { "scsi-cd", "quirk_mode_page_truncated", "on" }, 722 { "scsi-cd", "vendor", "MATSHITA" }, 723 { "scsi-cd", "product", "CD-ROM CR-8005" }, 724 { "scsi-cd", "ver", "1.0k" }, 725 }; 726 static const size_t hw_compat_q800_len = G_N_ELEMENTS(hw_compat_q800); 727 728 static void q800_machine_class_init(ObjectClass *oc, void *data) 729 { 730 static const char * const valid_cpu_types[] = { 731 M68K_CPU_TYPE_NAME("m68040"), 732 NULL 733 }; 734 MachineClass *mc = MACHINE_CLASS(oc); 735 736 mc->desc = "Macintosh Quadra 800"; 737 mc->init = q800_machine_init; 738 mc->default_cpu_type = M68K_CPU_TYPE_NAME("m68040"); 739 mc->valid_cpu_types = valid_cpu_types; 740 mc->max_cpus = 1; 741 mc->block_default_type = IF_SCSI; 742 mc->default_ram_id = "m68k_mac.ram"; 743 machine_add_audiodev_property(mc); 744 compat_props_add(mc->compat_props, hw_compat_q800, hw_compat_q800_len); 745 746 object_class_property_add_bool(oc, "easc", q800_get_easc, q800_set_easc); 747 object_class_property_set_description(oc, "easc", 748 "Set to off to use ASC rather than EASC"); 749 } 750 751 static const TypeInfo q800_machine_typeinfo = { 752 .name = MACHINE_TYPE_NAME("q800"), 753 .parent = TYPE_MACHINE, 754 .instance_init = q800_init, 755 .instance_size = sizeof(Q800MachineState), 756 .class_init = q800_machine_class_init, 757 }; 758 759 static void q800_machine_register_types(void) 760 { 761 type_register_static(&q800_machine_typeinfo); 762 } 763 764 type_init(q800_machine_register_types) 765