ppc_chrp.c 20.0 KB
Newer Older
B
bellard 已提交
1 2
/*
 * QEMU PPC CHRP/PMAC hardware System Emulator
3
 *
4
 * Copyright (c) 2004-2007 Fabrice Bellard
5
 *
B
bellard 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * 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.
 */
#include "vl.h"

26 27 28
/* SMP is not enabled, for now */
#define MAX_CPUS 1

B
bellard 已提交
29
#define BIOS_FILENAME "ppc_rom.bin"
B
bellard 已提交
30
#define VGABIOS_FILENAME "video.x"
B
bellard 已提交
31 32
#define NVRAM_SIZE        0x2000

B
bellard 已提交
33 34 35
#define KERNEL_LOAD_ADDR 0x01000000
#define INITRD_LOAD_ADDR 0x01800000

B
bellard 已提交
36
/* MacIO devices (mapped inside the MacIO address space): CUDA, DBDMA,
37
   NVRAM */
B
bellard 已提交
38 39 40

static int dbdma_mem_index;
static int cuda_mem_index;
41 42 43 44
static int ide0_mem_index = -1;
static int ide1_mem_index = -1;
static int openpic_mem_index = -1;
static int heathrow_pic_mem_index = -1;
45
static int macio_nvram_mem_index = -1;
B
bellard 已提交
46 47 48

/* DBDMA: currently no op - should suffice right now */

49 50
static void dbdma_writeb (void *opaque,
                          target_phys_addr_t addr, uint32_t value)
B
bellard 已提交
51
{
52
    printf("%s: 0x" PADDRX " <= 0x%08x\n", __func__, addr, value);
B
bellard 已提交
53 54
}

55 56
static void dbdma_writew (void *opaque,
                          target_phys_addr_t addr, uint32_t value)
B
bellard 已提交
57 58 59
{
}

60 61
static void dbdma_writel (void *opaque,
                          target_phys_addr_t addr, uint32_t value)
B
bellard 已提交
62 63 64 65 66
{
}

static uint32_t dbdma_readb (void *opaque, target_phys_addr_t addr)
{
67
    printf("%s: 0x" PADDRX " => 0x00000000\n", __func__, addr);
68

B
bellard 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    return 0;
}

static uint32_t dbdma_readw (void *opaque, target_phys_addr_t addr)
{
    return 0;
}

static uint32_t dbdma_readl (void *opaque, target_phys_addr_t addr)
{
    return 0;
}

static CPUWriteMemoryFunc *dbdma_write[] = {
    &dbdma_writeb,
    &dbdma_writew,
    &dbdma_writel,
};

static CPUReadMemoryFunc *dbdma_read[] = {
    &dbdma_readb,
    &dbdma_readw,
    &dbdma_readl,
};

94 95 96 97 98
/* macio style NVRAM device */
typedef struct MacIONVRAMState {
    uint8_t data[0x2000];
} MacIONVRAMState;

99 100
static void macio_nvram_writeb (void *opaque,
                                target_phys_addr_t addr, uint32_t value)
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
{
    MacIONVRAMState *s = opaque;
    addr = (addr >> 4) & 0x1fff;
    s->data[addr] = value;
    //    printf("macio_nvram_writeb %04x = %02x\n", addr, value);
}

static uint32_t macio_nvram_readb (void *opaque, target_phys_addr_t addr)
{
    MacIONVRAMState *s = opaque;
    uint32_t value;

    addr = (addr >> 4) & 0x1fff;
    value = s->data[addr];
    //    printf("macio_nvram_readb %04x = %02x\n", addr, value);
116

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    return value;
}

static CPUWriteMemoryFunc *macio_nvram_write[] = {
    &macio_nvram_writeb,
    &macio_nvram_writeb,
    &macio_nvram_writeb,
};

static CPUReadMemoryFunc *macio_nvram_read[] = {
    &macio_nvram_readb,
    &macio_nvram_readb,
    &macio_nvram_readb,
};

132
static MacIONVRAMState *macio_nvram_init (void)
133 134 135 136 137
{
    MacIONVRAMState *s;
    s = qemu_mallocz(sizeof(MacIONVRAMState));
    if (!s)
        return NULL;
138
    macio_nvram_mem_index = cpu_register_io_memory(0, macio_nvram_read,
139
                                                   macio_nvram_write, s);
140

141 142 143
    return s;
}

144 145
static void macio_map (PCIDevice *pci_dev, int region_num,
                       uint32_t addr, uint32_t size, int type)
B
bellard 已提交
146
{
147
    if (heathrow_pic_mem_index >= 0) {
148
        cpu_register_physical_memory(addr + 0x00000, 0x1000,
149 150
                                     heathrow_pic_mem_index);
    }
B
bellard 已提交
151 152
    cpu_register_physical_memory(addr + 0x08000, 0x1000, dbdma_mem_index);
    cpu_register_physical_memory(addr + 0x16000, 0x2000, cuda_mem_index);
153 154 155 156 157
    if (ide0_mem_index >= 0)
        cpu_register_physical_memory(addr + 0x1f000, 0x1000, ide0_mem_index);
    if (ide1_mem_index >= 0)
        cpu_register_physical_memory(addr + 0x20000, 0x1000, ide1_mem_index);
    if (openpic_mem_index >= 0) {
158
        cpu_register_physical_memory(addr + 0x40000, 0x40000,
159 160
                                     openpic_mem_index);
    }
161
    if (macio_nvram_mem_index >= 0)
162 163
        cpu_register_physical_memory(addr + 0x60000, 0x20000,
                                     macio_nvram_mem_index);
B
bellard 已提交
164 165
}

166
static void macio_init (PCIBus *bus, int device_id)
B
bellard 已提交
167 168 169
{
    PCIDevice *d;

B
bellard 已提交
170 171
    d = pci_register_device(bus, "macio", sizeof(PCIDevice),
                            -1, NULL, NULL);
B
bellard 已提交
172 173 174 175
    /* Note: this code is strongly inspirated from the corresponding code
       in PearPC */
    d->config[0x00] = 0x6b; // vendor_id
    d->config[0x01] = 0x10;
176 177
    d->config[0x02] = device_id;
    d->config[0x03] = device_id >> 8;
B
bellard 已提交
178 179 180 181 182 183

    d->config[0x0a] = 0x00; // class_sub = pci2pci
    d->config[0x0b] = 0xff; // class_base = bridge
    d->config[0x0e] = 0x00; // header_type

    d->config[0x3d] = 0x01; // interrupt on pin 1
184

B
bellard 已提交
185 186
    dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, NULL);

187
    pci_register_io_region(d, 0, 0x80000,
B
bellard 已提交
188 189 190
                           PCI_ADDRESS_SPACE_MEM, macio_map);
}

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
/* UniN device */
static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
{
}

static uint32_t unin_readl (void *opaque, target_phys_addr_t addr)
{
    return 0;
}

static CPUWriteMemoryFunc *unin_write[] = {
    &unin_writel,
    &unin_writel,
    &unin_writel,
};

static CPUReadMemoryFunc *unin_read[] = {
    &unin_readl,
    &unin_readl,
    &unin_readl,
};

/* temporary frame buffer OSI calls for the video.x driver. The right
   solution is to modify the driver to use VGA PCI I/Os */
215 216
/* XXX: to be removed. This is no way related to emulation */
static int vga_osi_call (CPUState *env)
217 218 219
{
    static int vga_vbl_enabled;
    int linesize;
220

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    //    printf("osi_call R5=%d\n", env->gpr[5]);

    /* same handler as PearPC, coming from the original MOL video
       driver. */
    switch(env->gpr[5]) {
    case 4:
        break;
    case 28: /* set_vmode */
        if (env->gpr[6] != 1 || env->gpr[7] != 0)
            env->gpr[3] = 1;
        else
            env->gpr[3] = 0;
        break;
    case 29: /* get_vmode_info */
        if (env->gpr[6] != 0) {
            if (env->gpr[6] != 1 || env->gpr[7] != 0) {
                env->gpr[3] = 1;
                break;
            }
        }
241
        env->gpr[3] = 0;
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
        env->gpr[4] = (1 << 16) | 1; /* num_vmodes, cur_vmode */
        env->gpr[5] = (1 << 16) | 0; /* num_depths, cur_depth_mode */
        env->gpr[6] = (graphic_width << 16) | graphic_height; /* w, h */
        env->gpr[7] = 85 << 16; /* refresh rate */
        env->gpr[8] = (graphic_depth + 7) & ~7; /* depth (round to byte) */
        linesize = ((graphic_depth + 7) >> 3) * graphic_width;
        linesize = (linesize + 3) & ~3;
        env->gpr[9] = (linesize << 16) | 0; /* row_bytes, offset */
        break;
    case 31: /* set_video power */
        env->gpr[3] = 0;
        break;
    case 39: /* video_ctrl */
        if (env->gpr[6] == 0 || env->gpr[6] == 1)
            vga_vbl_enabled = env->gpr[6];
        env->gpr[3] = 0;
        break;
    case 47:
        break;
    case 59: /* set_color */
        /* R6 = index, R7 = RGB */
        env->gpr[3] = 0;
        break;
    case 64: /* get color */
        /* R6 = index */
267
        env->gpr[3] = 0;
268 269 270 271 272
        break;
    case 116: /* set hwcursor */
        /* R6 = x, R7 = y, R8 = visible, R9 = data */
        break;
    default:
273
        fprintf(stderr, "unsupported OSI call R5=" REGX "\n", env->gpr[5]);
274 275
        break;
    }
276

277 278 279
    return 1; /* osi_call handled */
}

280
static uint8_t nvram_chksum (const uint8_t *buf, int n)
281 282 283 284 285 286 287 288 289
{
    int sum, i;
    sum = 0;
    for(i = 0; i < n; i++)
        sum += buf[i];
    return (sum & 0xff) + (sum >> 8);
}

/* set a free Mac OS NVRAM partition */
290
void pmac_format_nvram_partition (uint8_t *buf, int len)
291 292
{
    char partition_name[12] = "wwwwwwwwwwww";
293

294 295 296 297 298 299
    buf[0] = 0x7f; /* free partition magic */
    buf[1] = 0; /* checksum */
    buf[2] = len >> 8;
    buf[3] = len;
    memcpy(buf + 4, partition_name, 12);
    buf[1] = nvram_chksum(buf, 16);
300
}
301

302
/* PowerPC CHRP hardware initialisation */
303 304 305 306 307 308 309 310
static void ppc_chrp_init (int ram_size, int vga_ram_size, int boot_device,
                           DisplayState *ds, const char **fd_filename,
                           int snapshot,
                           const char *kernel_filename,
                           const char *kernel_cmdline,
                           const char *initrd_filename,
                           const char *cpu_model,
                           int is_heathrow)
B
bellard 已提交
311
{
312
    CPUState *env, *envs[MAX_CPUS];
B
bellard 已提交
313
    char buf[1024];
314
    qemu_irq *pic, **openpic_irqs;
B
bellard 已提交
315
    m48t59_t *nvram;
P
pbrook 已提交
316
    int unin_memory;
B
bellard 已提交
317 318
    int linux_boot, i;
    unsigned long bios_offset, vga_bios_offset;
B
bellard 已提交
319
    uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
320
    ppc_def_t *def;
B
bellard 已提交
321
    PCIBus *pci_bus;
322
    const char *arch_name;
B
bellard 已提交
323
    int vga_bios_size, bios_size;
P
pbrook 已提交
324
    qemu_irq *dummy_irq;
B
bellard 已提交
325

B
bellard 已提交
326 327
    linux_boot = (kernel_filename != NULL);

B
bellard 已提交
328 329
    /* init CPUs */
    env = cpu_init();
J
j_mayer 已提交
330
    qemu_register_reset(&cpu_ppc_reset, env);
B
bellard 已提交
331 332
    register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);

333 334 335
    /* Default CPU is a generic 74x/75x */
    if (cpu_model == NULL)
        cpu_model = "750";
B
bellard 已提交
336 337 338 339 340 341
    /* XXX: CPU model (or PVR) should be provided on command line */
    //    ppc_find_by_name("750gx", &def); // Linux boot OK
    //    ppc_find_by_name("750fx", &def); // Linux boot OK
    /* Linux does not boot on 750cxe (and probably other 750cx based)
     * because it assumes it has 8 IBAT & DBAT pairs as it only have 4.
     */
342
    ppc_find_by_name(cpu_model, &def);
B
bellard 已提交
343 344 345
    if (def == NULL) {
        cpu_abort(env, "Unable to find PowerPC CPU definition\n");
    }
346 347 348 349 350 351 352
    for (i = 0; i < smp_cpus; i++) {
        cpu_ppc_register(env, def);
        /* Set time-base frequency to 100 Mhz */
        cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
        env->osi_call = vga_osi_call;
        envs[i] = env;
    }
B
bellard 已提交
353

B
bellard 已提交
354 355 356 357 358 359
    /* allocate RAM */
    cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);

    /* allocate and load BIOS */
    bios_offset = ram_size + vga_ram_size;
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
B
bellard 已提交
360 361
    bios_size = load_image(buf, phys_ram_base + bios_offset);
    if (bios_size < 0 || bios_size > BIOS_SIZE) {
J
j_mayer 已提交
362
        cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf);
B
bellard 已提交
363 364
        exit(1);
    }
B
bellard 已提交
365
    bios_size = (bios_size + 0xfff) & ~0xfff;
J
j_mayer 已提交
366
    cpu_register_physical_memory((uint32_t)(-bios_size),
B
bellard 已提交
367
                                 bios_size, bios_offset | IO_MEM_ROM);
368

B
bellard 已提交
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
    /* allocate and load VGA BIOS */
    vga_bios_offset = bios_offset + bios_size;
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
    vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8);
    if (vga_bios_size < 0) {
        /* if no bios is present, we can still work */
        fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf);
        vga_bios_size = 0;
    } else {
        /* set a specific header (XXX: find real Apple format for NDRV
           drivers) */
        phys_ram_base[vga_bios_offset] = 'N';
        phys_ram_base[vga_bios_offset + 1] = 'D';
        phys_ram_base[vga_bios_offset + 2] = 'R';
        phys_ram_base[vga_bios_offset + 3] = 'V';
384
        cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4),
B
bellard 已提交
385 386 387 388
                     vga_bios_size);
        vga_bios_size += 8;
    }
    vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff;
389

B
bellard 已提交
390 391 392 393 394
    if (linux_boot) {
        kernel_base = KERNEL_LOAD_ADDR;
        /* now we can load the kernel */
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
        if (kernel_size < 0) {
J
j_mayer 已提交
395 396
            cpu_abort(env, "qemu: could not load kernel '%s'\n",
                      kernel_filename);
B
bellard 已提交
397 398 399 400 401 402 403 404
            exit(1);
        }
        /* load initrd */
        if (initrd_filename) {
            initrd_base = INITRD_LOAD_ADDR;
            initrd_size = load_image(initrd_filename,
                                     phys_ram_base + initrd_base);
            if (initrd_size < 0) {
J
j_mayer 已提交
405 406
                cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
                          initrd_filename);
B
bellard 已提交
407 408 409 410 411 412 413 414 415 416 417 418 419
                exit(1);
            }
        } else {
            initrd_base = 0;
            initrd_size = 0;
        }
        boot_device = 'm';
    } else {
        kernel_base = 0;
        kernel_size = 0;
        initrd_base = 0;
        initrd_size = 0;
    }
420 421 422

    if (is_heathrow) {
        isa_mem_base = 0x80000000;
423

424
        /* Register 2 MB of ISA IO space */
P
pbrook 已提交
425 426
        isa_mmio_init(0xfe000000, 0x00200000);

427
        /* init basic PC hardware */
428 429 430 431
        if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
            cpu_abort(env, "Only 6xx bus is supported on heathrow machine\n");
            exit(1);
        }
P
pbrook 已提交
432 433
        pic = heathrow_pic_init(&heathrow_pic_mem_index);
        pci_bus = pci_grackle_init(0xfec00000, pic);
434
        pci_vga_init(pci_bus, ds, phys_ram_base + ram_size,
B
bellard 已提交
435 436
                     ram_size, vga_ram_size,
                     vga_bios_offset, vga_bios_size);
437 438

        /* XXX: suppress that */
P
pbrook 已提交
439
        dummy_irq = i8259_init(NULL);
440

441
        /* XXX: use Mac Serial port */
P
pbrook 已提交
442
        serial_init(0x3f8, dummy_irq[4], serial_hds[0]);
443

444
        for(i = 0; i < nb_nics; i++) {
445 446
            if (!nd_table[i].model)
                nd_table[i].model = "ne2k_pci";
447
            pci_nic_init(pci_bus, &nd_table[i], -1);
448
        }
449

450 451 452
        pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);

        /* cuda also initialize ADB */
P
pbrook 已提交
453
        cuda_mem_index = cuda_init(pic[0x12]);
454

455 456
        adb_kbd_init(&adb_bus);
        adb_mouse_init(&adb_bus);
457

458 459 460 461 462 463 464
        {
            MacIONVRAMState *nvr;
            nvr = macio_nvram_init();
            pmac_format_nvram_partition(nvr->data, 0x2000);
        }

        macio_init(pci_bus, 0x0017);
465

P
pbrook 已提交
466
        nvram = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
467

468 469 470
        arch_name = "HEATHROW";
    } else {
        isa_mem_base = 0x80000000;
471

472
        /* Register 8 MB of ISA IO space */
P
pbrook 已提交
473
        isa_mmio_init(0xf2000000, 0x00800000);
474

475 476 477 478
        /* UniN init */
        unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL);
        cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory);

479 480 481 482 483 484 485
        openpic_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *));
        openpic_irqs[0] =
            qemu_mallocz(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
        for (i = 0; i < smp_cpus; i++) {
            /* Mac99 IRQ connection between OpenPIC outputs pins
             * and PowerPC input pins
             */
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
            switch (PPC_INPUT(env)) {
            case PPC_FLAGS_INPUT_6xx:
                openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
                openpic_irqs[i][OPENPIC_OUTPUT_INT] =
                    ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
                openpic_irqs[i][OPENPIC_OUTPUT_CINT] =
                    ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
                openpic_irqs[i][OPENPIC_OUTPUT_MCK] =
                    ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_MCP];
                /* Not connected ? */
                openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL;
                /* Check this */
                openpic_irqs[i][OPENPIC_OUTPUT_RESET] =
                    ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_HRESET];
                break;
            case PPC_FLAGS_INPUT_970:
                openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
                openpic_irqs[i][OPENPIC_OUTPUT_INT] =
                    ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT];
                openpic_irqs[i][OPENPIC_OUTPUT_CINT] =
                    ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT];
                openpic_irqs[i][OPENPIC_OUTPUT_MCK] =
                    ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_MCP];
                /* Not connected ? */
                openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL;
                /* Check this */
                openpic_irqs[i][OPENPIC_OUTPUT_RESET] =
                    ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_HRESET];
                break;
            default:
516
                cpu_abort(env, "Bus model not supported on mac99 machine\n");
517 518
                exit(1);
            }
519 520 521
        }
        pic = openpic_init(NULL, &openpic_mem_index, smp_cpus,
                           openpic_irqs, NULL);
P
pbrook 已提交
522
        pci_bus = pci_pmac_init(pic);
523
        /* init basic PC hardware */
B
bellard 已提交
524 525 526
        pci_vga_init(pci_bus, ds, phys_ram_base + ram_size,
                     ram_size, vga_ram_size,
                     vga_bios_offset, vga_bios_size);
527 528

        /* XXX: suppress that */
P
pbrook 已提交
529
        dummy_irq = i8259_init(NULL);
530

531
        /* XXX: use Mac Serial port */
P
pbrook 已提交
532
        serial_init(0x3f8, dummy_irq[4], serial_hds[0]);
533
        for(i = 0; i < nb_nics; i++) {
534 535 536
            if (!nd_table[i].model)
                nd_table[i].model = "ne2k_pci";
            pci_nic_init(pci_bus, &nd_table[i], -1);
537 538
        }
#if 1
P
pbrook 已提交
539 540
        ide0_mem_index = pmac_ide_init(&bs_table[0], pic[0x13]);
        ide1_mem_index = pmac_ide_init(&bs_table[2], pic[0x14]);
541 542 543 544
#else
        pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);
#endif
        /* cuda also initialize ADB */
P
pbrook 已提交
545
        cuda_mem_index = cuda_init(pic[0x19]);
546

547 548
        adb_kbd_init(&adb_bus);
        adb_mouse_init(&adb_bus);
549

550
        macio_init(pci_bus, 0x0022);
551

P
pbrook 已提交
552
        nvram = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
553

554
        arch_name = "MAC99";
B
bellard 已提交
555
    }
P
pbrook 已提交
556 557

    if (usb_enabled) {
558
        usb_ohci_init_pci(pci_bus, 3, -1);
P
pbrook 已提交
559 560
    }

B
bellard 已提交
561 562
    if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
        graphic_depth = 15;
B
bellard 已提交
563

564
    PPC_NVRAM_set_params(nvram, NVRAM_SIZE, arch_name, ram_size, boot_device,
B
bellard 已提交
565 566 567
                         kernel_base, kernel_size,
                         kernel_cmdline,
                         initrd_base, initrd_size,
B
bellard 已提交
568
                         /* XXX: need an option to load a NVRAM image */
B
bellard 已提交
569 570 571
                         0,
                         graphic_width, graphic_height, graphic_depth);
    /* No PCI init: the BIOS will do it */
572 573 574 575 576

    /* Special port to get debug messages from Open-Firmware */
    register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
}

577 578 579 580 581 582 583
static void ppc_core99_init (int ram_size, int vga_ram_size, int boot_device,
                             DisplayState *ds, const char **fd_filename,
                             int snapshot,
                             const char *kernel_filename,
                             const char *kernel_cmdline,
                             const char *initrd_filename,
                             const char *cpu_model)
584 585 586 587
{
    ppc_chrp_init(ram_size, vga_ram_size, boot_device,
                  ds, fd_filename, snapshot,
                  kernel_filename, kernel_cmdline,
588
                  initrd_filename, cpu_model, 0);
B
bellard 已提交
589
}
590

591 592 593 594 595 596 597
static void ppc_heathrow_init (int ram_size, int vga_ram_size, int boot_device,
                               DisplayState *ds, const char **fd_filename,
                               int snapshot,
                               const char *kernel_filename,
                               const char *kernel_cmdline,
                               const char *initrd_filename,
                               const char *cpu_model)
598 599 600 601
{
    ppc_chrp_init(ram_size, vga_ram_size, boot_device,
                  ds, fd_filename, snapshot,
                  kernel_filename, kernel_cmdline,
602
                  initrd_filename, cpu_model, 1);
603 604 605
}

QEMUMachine core99_machine = {
B
bellard 已提交
606 607
    "mac99",
    "Mac99 based PowerMAC",
608 609 610 611
    ppc_core99_init,
};

QEMUMachine heathrow_machine = {
B
bellard 已提交
612
    "g3bw",
613 614 615
    "Heathrow based PowerMAC",
    ppc_heathrow_init,
};