static void ppc_prep_init(QEMUMachineInitArgs *args)

{

    ram_addr_t ram_size = args->ram_size;

    const char *cpu_model = args->cpu_model;

    const char *kernel_filename = args->kernel_filename;

    const char *kernel_cmdline = args->kernel_cmdline;

    const char *initrd_filename = args->initrd_filename;

    const char *boot_device = args->boot_device;

    MemoryRegion *sysmem = get_system_memory();

    PowerPCCPU *cpu = NULL;

    CPUPPCState *env = NULL;

    char *filename;

    nvram_t nvram;

    M48t59State *m48t59;

    MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1);

    PortioList *port_list = g_new(PortioList, 1);

#if 0

    MemoryRegion *xcsr = g_new(MemoryRegion, 1);

#endif

    int linux_boot, i, nb_nics1, bios_size;

    MemoryRegion *ram = g_new(MemoryRegion, 1);

    MemoryRegion *bios = g_new(MemoryRegion, 1);

    uint32_t kernel_base, initrd_base;

    long kernel_size, initrd_size;

    DeviceState *dev;

    PCIHostState *pcihost;

    PCIBus *pci_bus;

    PCIDevice *pci;

    ISABus *isa_bus;

    ISADevice *isa;

    qemu_irq *cpu_exit_irq;

    int ppc_boot_device;

    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];



    sysctrl = g_malloc0(sizeof(sysctrl_t));



    linux_boot = (kernel_filename != NULL);



    /* init CPUs */

    if (cpu_model == NULL)

        cpu_model = "602";

    for (i = 0; i < smp_cpus; i++) {

        cpu = cpu_ppc_init(cpu_model);

        if (cpu == NULL) {

            fprintf(stderr, "Unable to find PowerPC CPU definition\n");

            exit(1);

        }

        env = &cpu->env;



        if (env->flags & POWERPC_FLAG_RTC_CLK) {

            /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */

            cpu_ppc_tb_init(env, 7812500UL);

        } else {

            /* Set time-base frequency to 100 Mhz */

            cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);

        }

        qemu_register_reset(ppc_prep_reset, cpu);

    }



    /* allocate RAM */

    memory_region_init_ram(ram, NULL, "ppc_prep.ram", ram_size);

    vmstate_register_ram_global(ram);

    memory_region_add_subregion(sysmem, 0, ram);



    /* allocate and load BIOS */

    memory_region_init_ram(bios, NULL, "ppc_prep.bios", BIOS_SIZE);

    memory_region_set_readonly(bios, true);

    memory_region_add_subregion(sysmem, (uint32_t)(-BIOS_SIZE), bios);

    vmstate_register_ram_global(bios);

    if (bios_name == NULL)

        bios_name = BIOS_FILENAME;

    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);

    if (filename) {

        bios_size = load_elf(filename, NULL, NULL, NULL,

                             NULL, NULL, 1, ELF_MACHINE, 0);

        if (bios_size < 0) {

            bios_size = get_image_size(filename);

            if (bios_size > 0 && bios_size <= BIOS_SIZE) {

                hwaddr bios_addr;

                bios_size = (bios_size + 0xfff) & ~0xfff;

                bios_addr = (uint32_t)(-bios_size);

                bios_size = load_image_targphys(filename, bios_addr, bios_size);

            }

            if (bios_size > BIOS_SIZE) {

                fprintf(stderr, "qemu: PReP bios '%s' is too large (0x%x)\n",

                        bios_name, bios_size);

                exit(1);

            }

        }

    } else {

        bios_size = -1;

    }

    if (bios_size < 0 && !qtest_enabled()) {

        fprintf(stderr, "qemu: could not load PPC PReP bios '%s'\n",

                bios_name);

        exit(1);

    }

    if (filename) {

        g_free(filename);

    }



    if (linux_boot) {

        kernel_base = KERNEL_LOAD_ADDR;

        /* now we can load the kernel */

        kernel_size = load_image_targphys(kernel_filename, kernel_base,

                                          ram_size - kernel_base);

        if (kernel_size < 0) {

            hw_error("qemu: could not load kernel '%s'\n", kernel_filename);

            exit(1);

        }

        /* load initrd */

        if (initrd_filename) {

            initrd_base = INITRD_LOAD_ADDR;

            initrd_size = load_image_targphys(initrd_filename, initrd_base,

                                              ram_size - initrd_base);

            if (initrd_size < 0) {

                hw_error("qemu: could not load initial ram disk '%s'\n",

                          initrd_filename);

            }

        } else {

            initrd_base = 0;

            initrd_size = 0;

        }

        ppc_boot_device = 'm';

    } else {

        kernel_base = 0;

        kernel_size = 0;

        initrd_base = 0;

        initrd_size = 0;

        ppc_boot_device = '\0';

        /* For now, OHW cannot boot from the network. */

        for (i = 0; boot_device[i] != '\0'; i++) {

            if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {

                ppc_boot_device = boot_device[i];

                break;

            }

        }

        if (ppc_boot_device == '\0') {

            fprintf(stderr, "No valid boot device for Mac99 machine\n");

            exit(1);

        }

    }



    if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {

        hw_error("Only 6xx bus is supported on PREP machine\n");

    }



    dev = qdev_create(NULL, "raven-pcihost");

    pcihost = PCI_HOST_BRIDGE(dev);

    object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL);

    qdev_init_nofail(dev);

    pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");

    if (pci_bus == NULL) {

        fprintf(stderr, "Couldn't create PCI host controller.\n");

        exit(1);

    }



    /* PCI -> ISA bridge */

    pci = pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "i82378");

    cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);

    cpu = POWERPC_CPU(first_cpu);

    qdev_connect_gpio_out(&pci->qdev, 0,

                          cpu->env.irq_inputs[PPC6xx_INPUT_INT]);

    qdev_connect_gpio_out(&pci->qdev, 1, *cpu_exit_irq);

    sysbus_connect_irq(&pcihost->busdev, 0, qdev_get_gpio_in(&pci->qdev, 9));

    sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11));

    sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9));

    sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11));

    isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci), "isa.0"));



    /* Super I/O (parallel + serial ports) */

    isa = isa_create(isa_bus, TYPE_PC87312);

    dev = DEVICE(isa);

    qdev_prop_set_uint8(dev, "config", 13); /* fdc, ser0, ser1, par0 */

    qdev_init_nofail(dev);



    /* Register 8 MB of ISA IO space (needed for non-contiguous map) */

    memory_region_init_io(PPC_io_memory, NULL, &PPC_prep_io_ops, sysctrl,

                          "ppc-io", 0x00800000);

    memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory);



    /* init basic PC hardware */

    pci_vga_init(pci_bus);



    nb_nics1 = nb_nics;

    if (nb_nics1 > NE2000_NB_MAX)

        nb_nics1 = NE2000_NB_MAX;

    for(i = 0; i < nb_nics1; i++) {

        if (nd_table[i].model == NULL) {

	    nd_table[i].model = g_strdup("ne2k_isa");

        }

        if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {

            isa_ne2000_init(isa_bus, ne2000_io[i], ne2000_irq[i],

                            &nd_table[i]);

        } else {

            pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL);

        }

    }



    ide_drive_get(hd, MAX_IDE_BUS);

    for(i = 0; i < MAX_IDE_BUS; i++) {

        isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i],

                     hd[2 * i],

		     hd[2 * i + 1]);

    }

    isa_create_simple(isa_bus, "i8042");



    cpu = POWERPC_CPU(first_cpu);

    sysctrl->reset_irq = cpu->env.irq_inputs[PPC6xx_INPUT_HRESET];



    portio_list_init(port_list, NULL, prep_portio_list, sysctrl, "prep");

    portio_list_add(port_list, get_system_io(), 0x0);



    /* PowerPC control and status register group */

#if 0

    memory_region_init_io(xcsr, NULL, &PPC_XCSR_ops, NULL, "ppc-xcsr", 0x1000);

    memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr);

#endif



    if (usb_enabled(false)) {

        pci_create_simple(pci_bus, -1, "pci-ohci");

    }



    m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59);

    if (m48t59 == NULL)

        return;

    sysctrl->nvram = m48t59;



    /* Initialise NVRAM */

    nvram.opaque = m48t59;

    nvram.read_fn = &m48t59_read;

    nvram.write_fn = &m48t59_write;

    PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,

                         kernel_base, kernel_size,

                         kernel_cmdline,

                         initrd_base, initrd_size,

                         /* XXX: need an option to load a NVRAM image */

                         0,

                         graphic_width, graphic_height, graphic_depth);

}

static void ppc_prep_init(QEMUMachineInitArgs *args)

{

    ram_addr_t ram_size = args->ram_size;

    const char *cpu_model = args->cpu_model;

    const char *kernel_filename = args->kernel_filename;

    const char *kernel_cmdline = args->kernel_cmdline;

    const char *initrd_filename = args->initrd_filename;

    const char *boot_device = args->boot_device;

    MemoryRegion *sysmem = get_system_memory();

    PowerPCCPU *cpu = NULL;

    CPUPPCState *env = NULL;

    char *filename;

    nvram_t nvram;

    M48t59State *m48t59;

    MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1);

    PortioList *port_list = g_new(PortioList, 1);

#if 0

    MemoryRegion *xcsr = g_new(MemoryRegion, 1);

#endif

    int linux_boot, i, nb_nics1, bios_size;

    MemoryRegion *ram = g_new(MemoryRegion, 1);

    MemoryRegion *bios = g_new(MemoryRegion, 1);

    uint32_t kernel_base, initrd_base;

    long kernel_size, initrd_size;

    DeviceState *dev;

    PCIHostState *pcihost;

    PCIBus *pci_bus;

    PCIDevice *pci;

    ISABus *isa_bus;

    ISADevice *isa;

    qemu_irq *cpu_exit_irq;

    int ppc_boot_device;

    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];



    sysctrl = g_malloc0(sizeof(sysctrl_t));



    linux_boot = (kernel_filename != NULL);



    

    if (cpu_model == NULL)

        cpu_model = "602";

    for (i = 0; i < smp_cpus; i++) {

        cpu = cpu_ppc_init(cpu_model);

        if (cpu == NULL) {

            fprintf(stderr, "Unable to find PowerPC CPU definition\n");

            exit(1);

        }

        env = &cpu->env;



        if (env->flags & POWERPC_FLAG_RTC_CLK) {

            

            cpu_ppc_tb_init(env, 7812500UL);

        } else {

            

            cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);

        }

        qemu_register_reset(ppc_prep_reset, cpu);

    }



    

    memory_region_init_ram(ram, NULL, "ppc_prep.ram", ram_size);

    vmstate_register_ram_global(ram);

    memory_region_add_subregion(sysmem, 0, ram);



    

    memory_region_init_ram(bios, NULL, "ppc_prep.bios", BIOS_SIZE);

    memory_region_set_readonly(bios, true);

    memory_region_add_subregion(sysmem, (uint32_t)(-BIOS_SIZE), bios);

    vmstate_register_ram_global(bios);

    if (bios_name == NULL)

        bios_name = BIOS_FILENAME;

    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);

    if (filename) {

        bios_size = load_elf(filename, NULL, NULL, NULL,

                             NULL, NULL, 1, ELF_MACHINE, 0);

        if (bios_size < 0) {

            bios_size = get_image_size(filename);

            if (bios_size > 0 && bios_size <= BIOS_SIZE) {

                hwaddr bios_addr;

                bios_size = (bios_size + 0xfff) & ~0xfff;

                bios_addr = (uint32_t)(-bios_size);

                bios_size = load_image_targphys(filename, bios_addr, bios_size);

            }

            if (bios_size > BIOS_SIZE) {

                fprintf(stderr, "qemu: PReP bios '%s' is too large (0x%x)\n",

                        bios_name, bios_size);

                exit(1);

            }

        }

    } else {

        bios_size = -1;

    }

    if (bios_size < 0 && !qtest_enabled()) {

        fprintf(stderr, "qemu: could not load PPC PReP bios '%s'\n",

                bios_name);

        exit(1);

    }

    if (filename) {

        g_free(filename);

    }



    if (linux_boot) {

        kernel_base = KERNEL_LOAD_ADDR;

        

        kernel_size = load_image_targphys(kernel_filename, kernel_base,

                                          ram_size - kernel_base);

        if (kernel_size < 0) {

            hw_error("qemu: could not load kernel '%s'\n", kernel_filename);

            exit(1);

        }

        

        if (initrd_filename) {

            initrd_base = INITRD_LOAD_ADDR;

            initrd_size = load_image_targphys(initrd_filename, initrd_base,

                                              ram_size - initrd_base);

            if (initrd_size < 0) {

                hw_error("qemu: could not load initial ram disk '%s'\n",

                          initrd_filename);

            }

        } else {

            initrd_base = 0;

            initrd_size = 0;

        }

        ppc_boot_device = 'm';

    } else {

        kernel_base = 0;

        kernel_size = 0;

        initrd_base = 0;

        initrd_size = 0;

        ppc_boot_device = '\0';

        

        for (i = 0; boot_device[i] != '\0'; i++) {

            if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {

                ppc_boot_device = boot_device[i];

                break;

            }

        }

        if (ppc_boot_device == '\0') {

            fprintf(stderr, "No valid boot device for Mac99 machine\n");

            exit(1);

        }

    }



    if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {

        hw_error("Only 6xx bus is supported on PREP machine\n");

    }



    dev = qdev_create(NULL, "raven-pcihost");

    pcihost = PCI_HOST_BRIDGE(dev);

    object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL);

    qdev_init_nofail(dev);

    pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");

    if (pci_bus == NULL) {

        fprintf(stderr, "Couldn't create PCI host controller.\n");

        exit(1);

    }



    

    pci = pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "i82378");

    cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);

    cpu = POWERPC_CPU(first_cpu);

    qdev_connect_gpio_out(&pci->qdev, 0,

                          cpu->env.irq_inputs[PPC6xx_INPUT_INT]);

    qdev_connect_gpio_out(&pci->qdev, 1, *cpu_exit_irq);

    sysbus_connect_irq(&pcihost->busdev, 0, qdev_get_gpio_in(&pci->qdev, 9));

    sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11));

    sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9));

    sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11));

    isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci), "isa.0"));



    

    isa = isa_create(isa_bus, TYPE_PC87312);

    dev = DEVICE(isa);

    qdev_prop_set_uint8(dev, "config", 13); 

    qdev_init_nofail(dev);



    

    memory_region_init_io(PPC_io_memory, NULL, &PPC_prep_io_ops, sysctrl,

                          "ppc-io", 0x00800000);

    memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory);



    

    pci_vga_init(pci_bus);



    nb_nics1 = nb_nics;

    if (nb_nics1 > NE2000_NB_MAX)

        nb_nics1 = NE2000_NB_MAX;

    for(i = 0; i < nb_nics1; i++) {

        if (nd_table[i].model == NULL) {

	    nd_table[i].model = g_strdup("ne2k_isa");

        }

        if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {

            isa_ne2000_init(isa_bus, ne2000_io[i], ne2000_irq[i],

                            &nd_table[i]);

        } else {

            pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL);

        }

    }



    ide_drive_get(hd, MAX_IDE_BUS);

    for(i = 0; i < MAX_IDE_BUS; i++) {

        isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i],

                     hd[2 * i],

		     hd[2 * i + 1]);

    }

    isa_create_simple(isa_bus, "i8042");



    cpu = POWERPC_CPU(first_cpu);

    sysctrl->reset_irq = cpu->env.irq_inputs[PPC6xx_INPUT_HRESET];



    portio_list_init(port_list, NULL, prep_portio_list, sysctrl, "prep");

    portio_list_add(port_list, get_system_io(), 0x0);



    

#if 0

    memory_region_init_io(xcsr, NULL, &PPC_XCSR_ops, NULL, "ppc-xcsr", 0x1000);

    memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr);

#endif



    if (usb_enabled(false)) {

        pci_create_simple(pci_bus, -1, "pci-ohci");

    }



    m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59);

    if (m48t59 == NULL)

        return;

    sysctrl->nvram = m48t59;



    

    nvram.opaque = m48t59;

    nvram.read_fn = &m48t59_read;

    nvram.write_fn = &m48t59_write;

    PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,

                         kernel_base, kernel_size,

                         kernel_cmdline,

                         initrd_base, initrd_size,

                         

                         0,

                         graphic_width, graphic_height, graphic_depth);

}

static void FUNC_0(QEMUMachineInitArgs *VAR_0)

{

    ram_addr_t ram_size = VAR_0->ram_size;

    const char *VAR_1 = VAR_0->VAR_1;

    const char *VAR_2 = VAR_0->VAR_2;

    const char *VAR_3 = VAR_0->VAR_3;

    const char *VAR_4 = VAR_0->VAR_4;

    const char *VAR_5 = VAR_0->VAR_5;

    MemoryRegion *sysmem = get_system_memory();

    PowerPCCPU *cpu = NULL;

    CPUPPCState *env = NULL;

    char *VAR_6;

    nvram_t nvram;

    M48t59State *m48t59;

    MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1);

    PortioList *port_list = g_new(PortioList, 1);

#if 0

    MemoryRegion *xcsr = g_new(MemoryRegion, 1);

#endif

    int VAR_7, VAR_8, VAR_9, VAR_10;

    MemoryRegion *ram = g_new(MemoryRegion, 1);

    MemoryRegion *bios = g_new(MemoryRegion, 1);

    uint32_t kernel_base, initrd_base;

    long VAR_11, VAR_12;

    DeviceState *dev;

    PCIHostState *pcihost;

    PCIBus *pci_bus;

    PCIDevice *pci;

    ISABus *isa_bus;

    ISADevice *isa;

    qemu_irq *cpu_exit_irq;

    int VAR_13;

    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];



    sysctrl = g_malloc0(sizeof(sysctrl_t));



    VAR_7 = (VAR_2 != NULL);



    

    if (VAR_1 == NULL)

        VAR_1 = "602";

    for (VAR_8 = 0; VAR_8 < smp_cpus; VAR_8++) {

        cpu = cpu_ppc_init(VAR_1);

        if (cpu == NULL) {

            fprintf(stderr, "Unable to find PowerPC CPU definition\n");

            exit(1);

        }

        env = &cpu->env;



        if (env->flags & POWERPC_FLAG_RTC_CLK) {

            

            cpu_ppc_tb_init(env, 7812500UL);

        } else {

            

            cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);

        }

        qemu_register_reset(ppc_prep_reset, cpu);

    }



    

    memory_region_init_ram(ram, NULL, "ppc_prep.ram", ram_size);

    vmstate_register_ram_global(ram);

    memory_region_add_subregion(sysmem, 0, ram);



    

    memory_region_init_ram(bios, NULL, "ppc_prep.bios", BIOS_SIZE);

    memory_region_set_readonly(bios, true);

    memory_region_add_subregion(sysmem, (uint32_t)(-BIOS_SIZE), bios);

    vmstate_register_ram_global(bios);

    if (bios_name == NULL)

        bios_name = BIOS_FILENAME;

    VAR_6 = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);

    if (VAR_6) {

        VAR_10 = load_elf(VAR_6, NULL, NULL, NULL,

                             NULL, NULL, 1, ELF_MACHINE, 0);

        if (VAR_10 < 0) {

            VAR_10 = get_image_size(VAR_6);

            if (VAR_10 > 0 && VAR_10 <= BIOS_SIZE) {

                hwaddr bios_addr;

                VAR_10 = (VAR_10 + 0xfff) & ~0xfff;

                bios_addr = (uint32_t)(-VAR_10);

                VAR_10 = load_image_targphys(VAR_6, bios_addr, VAR_10);

            }

            if (VAR_10 > BIOS_SIZE) {

                fprintf(stderr, "qemu: PReP bios '%s' is too large (0x%x)\n",

                        bios_name, VAR_10);

                exit(1);

            }

        }

    } else {

        VAR_10 = -1;

    }

    if (VAR_10 < 0 && !qtest_enabled()) {

        fprintf(stderr, "qemu: could not load PPC PReP bios '%s'\n",

                bios_name);

        exit(1);

    }

    if (VAR_6) {

        g_free(VAR_6);

    }



    if (VAR_7) {

        kernel_base = KERNEL_LOAD_ADDR;

        

        VAR_11 = load_image_targphys(VAR_2, kernel_base,

                                          ram_size - kernel_base);

        if (VAR_11 < 0) {

            hw_error("qemu: could not load kernel '%s'\n", VAR_2);

            exit(1);

        }

        

        if (VAR_4) {

            initrd_base = INITRD_LOAD_ADDR;

            VAR_12 = load_image_targphys(VAR_4, initrd_base,

                                              ram_size - initrd_base);

            if (VAR_12 < 0) {

                hw_error("qemu: could not load initial ram disk '%s'\n",

                          VAR_4);

            }

        } else {

            initrd_base = 0;

            VAR_12 = 0;

        }

        VAR_13 = 'm';

    } else {

        kernel_base = 0;

        VAR_11 = 0;

        initrd_base = 0;

        VAR_12 = 0;

        VAR_13 = '\0';

        

        for (VAR_8 = 0; VAR_5[VAR_8] != '\0'; VAR_8++) {

            if (VAR_5[VAR_8] >= 'a' && VAR_5[VAR_8] <= 'f') {

                VAR_13 = VAR_5[VAR_8];

                break;

            }

        }

        if (VAR_13 == '\0') {

            fprintf(stderr, "No valid boot device for Mac99 machine\n");

            exit(1);

        }

    }



    if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {

        hw_error("Only 6xx bus is supported on PREP machine\n");

    }



    dev = qdev_create(NULL, "raven-pcihost");

    pcihost = PCI_HOST_BRIDGE(dev);

    object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL);

    qdev_init_nofail(dev);

    pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");

    if (pci_bus == NULL) {

        fprintf(stderr, "Couldn't create PCI host controller.\n");

        exit(1);

    }



    

    pci = pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "i82378");

    cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);

    cpu = POWERPC_CPU(first_cpu);

    qdev_connect_gpio_out(&pci->qdev, 0,

                          cpu->env.irq_inputs[PPC6xx_INPUT_INT]);

    qdev_connect_gpio_out(&pci->qdev, 1, *cpu_exit_irq);

    sysbus_connect_irq(&pcihost->busdev, 0, qdev_get_gpio_in(&pci->qdev, 9));

    sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11));

    sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9));

    sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11));

    isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci), "isa.0"));



    

    isa = isa_create(isa_bus, TYPE_PC87312);

    dev = DEVICE(isa);

    qdev_prop_set_uint8(dev, "config", 13); 

    qdev_init_nofail(dev);



    

    memory_region_init_io(PPC_io_memory, NULL, &PPC_prep_io_ops, sysctrl,

                          "ppc-io", 0x00800000);

    memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory);



    

    pci_vga_init(pci_bus);



    VAR_9 = nb_nics;

    if (VAR_9 > NE2000_NB_MAX)

        VAR_9 = NE2000_NB_MAX;

    for(VAR_8 = 0; VAR_8 < VAR_9; VAR_8++) {

        if (nd_table[VAR_8].model == NULL) {

	    nd_table[VAR_8].model = g_strdup("ne2k_isa");

        }

        if (strcmp(nd_table[VAR_8].model, "ne2k_isa") == 0) {

            isa_ne2000_init(isa_bus, ne2000_io[VAR_8], ne2000_irq[VAR_8],

                            &nd_table[VAR_8]);

        } else {

            pci_nic_init_nofail(&nd_table[VAR_8], pci_bus, "ne2k_pci", NULL);

        }

    }



    ide_drive_get(hd, MAX_IDE_BUS);

    for(VAR_8 = 0; VAR_8 < MAX_IDE_BUS; VAR_8++) {

        isa_ide_init(isa_bus, ide_iobase[VAR_8], ide_iobase2[VAR_8], ide_irq[VAR_8],

                     hd[2 * VAR_8],

		     hd[2 * VAR_8 + 1]);

    }

    isa_create_simple(isa_bus, "i8042");



    cpu = POWERPC_CPU(first_cpu);

    sysctrl->reset_irq = cpu->env.irq_inputs[PPC6xx_INPUT_HRESET];



    portio_list_init(port_list, NULL, prep_portio_list, sysctrl, "prep");

    portio_list_add(port_list, get_system_io(), 0x0);



    

#if 0

    memory_region_init_io(xcsr, NULL, &PPC_XCSR_ops, NULL, "ppc-xcsr", 0x1000);

    memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr);

#endif



    if (usb_enabled(false)) {

        pci_create_simple(pci_bus, -1, "pci-ohci");

    }



    m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59);

    if (m48t59 == NULL)

        return;

    sysctrl->nvram = m48t59;



    

    nvram.opaque = m48t59;

    nvram.read_fn = &m48t59_read;

    nvram.write_fn = &m48t59_write;

    PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, VAR_13,

                         kernel_base, VAR_11,

                         VAR_3,

                         initrd_base, VAR_12,

                         

                         0,

                         graphic_width, graphic_height, graphic_depth);

}

static void FUNC_0(QEMUMachineInitArgs *VAR_0)
{ ram_addr_t ram_size = VAR_0->ram_size; const char *VAR_1 = VAR_0->VAR_1; const char *VAR_2 = VAR_0->VAR_2; const char *VAR_3 = VAR_0->VAR_3; const char *VAR_4 = VAR_0->VAR_4; const char *VAR_5 = VAR_0->VAR_5; MemoryRegion *sysmem = get_system_memory(); PowerPCCPU *cpu = NULL; CPUPPCState *env = NULL; char *VAR_6; nvram_t nvram; M48t59State *m48t59; MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1); PortioList *port_list = g_new(PortioList, 1); #if 0
MemoryRegion *xcsr = g_new(MemoryRegion, 1); #endif
int VAR_7, VAR_8, VAR_9, VAR_10; MemoryRegion *ram = g_new(MemoryRegion, 1); MemoryRegion *bios = g_new(MemoryRegion, 1); uint32_t kernel_base, initrd_base; long VAR_11, VAR_12; DeviceState *dev; PCIHostState *pcihost; PCIBus *pci_bus; PCIDevice *pci; ISABus *isa_bus; ISADevice *isa; qemu_irq *cpu_exit_irq; int VAR_13; DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; sysctrl = g_malloc0(sizeof(sysctrl_t)); VAR_7 = (VAR_2 != NULL); if (VAR_1 == NULL)
VAR_1 = "602"; for (VAR_8 = 0; VAR_8 < smp_cpus; VAR_8++) { cpu = cpu_ppc_init(VAR_1); if (cpu == NULL) { fprintf(stderr, "Unable to find PowerPC CPU definition\n"); exit(1); } env = &cpu->env; if (env->flags & POWERPC_FLAG_RTC_CLK) { cpu_ppc_tb_init(env, 7812500UL); } else { cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL); } qemu_register_reset(ppc_prep_reset, cpu); } memory_region_init_ram(ram, NULL, "ppc_prep.ram", ram_size); vmstate_register_ram_global(ram); memory_region_add_subregion(sysmem, 0, ram); memory_region_init_ram(bios, NULL, "ppc_prep.bios", BIOS_SIZE); memory_region_set_readonly(bios, true); memory_region_add_subregion(sysmem, (uint32_t)(-BIOS_SIZE), bios); vmstate_register_ram_global(bios); if (bios_name == NULL)
bios_name = BIOS_FILENAME; VAR_6 = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); if (VAR_6) { VAR_10 = load_elf(VAR_6, NULL, NULL, NULL,
NULL, NULL, 1, ELF_MACHINE, 0); if (VAR_10 < 0) { VAR_10 = get_image_size(VAR_6); if (VAR_10 > 0 && VAR_10 <= BIOS_SIZE) { hwaddr bios_addr; VAR_10 = (VAR_10 + 0xfff) & ~0xfff; bios_addr = (uint32_t)(-VAR_10); VAR_10 = load_image_targphys(VAR_6, bios_addr, VAR_10); } if (VAR_10 > BIOS_SIZE) { fprintf(stderr, "qemu: PReP bios '%s' is too large (0x%x)\n",
bios_name, VAR_10); exit(1); } } } else { VAR_10 = -1; } if (VAR_10 < 0 && !qtest_enabled()) { fprintf(stderr, "qemu: could not load PPC PReP bios '%s'\n",
bios_name); exit(1); } if (VAR_6) { g_free(VAR_6); } if (VAR_7) { kernel_base = KERNEL_LOAD_ADDR; VAR_11 = load_image_targphys(VAR_2, kernel_base,
ram_size - kernel_base); if (VAR_11 < 0) { hw_error("qemu: could not load kernel '%s'\n", VAR_2); exit(1); } if (VAR_4) { initrd_base = INITRD_LOAD_ADDR; VAR_12 = load_image_targphys(VAR_4, initrd_base,
ram_size - initrd_base); if (VAR_12 < 0) { hw_error("qemu: could not load initial ram disk '%s'\n",
VAR_4); } } else { initrd_base = 0; VAR_12 = 0; } VAR_13 = 'm'; } else { kernel_base = 0; VAR_11 = 0; initrd_base = 0; VAR_12 = 0; VAR_13 = '\0'; for (VAR_8 = 0; VAR_5[VAR_8] != '\0'; VAR_8++) { if (VAR_5[VAR_8] >= 'a' && VAR_5[VAR_8] <= 'f') { VAR_13 = VAR_5[VAR_8]; break; } } if (VAR_13 == '\0') { fprintf(stderr, "No valid boot device for Mac99 machine\n"); exit(1); } } if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) { hw_error("Only 6xx bus is supported on PREP machine\n"); } dev = qdev_create(NULL, "raven-pcihost"); pcihost = PCI_HOST_BRIDGE(dev); object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL); qdev_init_nofail(dev); pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0"); if (pci_bus == NULL) { fprintf(stderr, "Couldn't create PCI host controller.\n"); exit(1); } pci = pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "i82378"); cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1); cpu = POWERPC_CPU(first_cpu); qdev_connect_gpio_out(&pci->qdev, 0,
cpu->env.irq_inputs[PPC6xx_INPUT_INT]); qdev_connect_gpio_out(&pci->qdev, 1, *cpu_exit_irq); sysbus_connect_irq(&pcihost->busdev, 0, qdev_get_gpio_in(&pci->qdev, 9)); sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11)); sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9)); sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11)); isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci), "isa.0")); isa = isa_create(isa_bus, TYPE_PC87312); dev = DEVICE(isa); qdev_prop_set_uint8(dev, "config", 13); qdev_init_nofail(dev); memory_region_init_io(PPC_io_memory, NULL, &PPC_prep_io_ops, sysctrl,
"ppc-io", 0x00800000); memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory); pci_vga_init(pci_bus); VAR_9 = nb_nics; if (VAR_9 > NE2000_NB_MAX)
VAR_9 = NE2000_NB_MAX; for(VAR_8 = 0; VAR_8 < VAR_9; VAR_8++) { if (nd_table[VAR_8].model == NULL) { nd_table[VAR_8].model = g_strdup("ne2k_isa"); } if (strcmp(nd_table[VAR_8].model, "ne2k_isa") == 0) { isa_ne2000_init(isa_bus, ne2000_io[VAR_8], ne2000_irq[VAR_8],
&nd_table[VAR_8]); } else { pci_nic_init_nofail(&nd_table[VAR_8], pci_bus, "ne2k_pci", NULL); } } ide_drive_get(hd, MAX_IDE_BUS); for(VAR_8 = 0; VAR_8 < MAX_IDE_BUS; VAR_8++) { isa_ide_init(isa_bus, ide_iobase[VAR_8], ide_iobase2[VAR_8], ide_irq[VAR_8],
hd[2 * VAR_8],
hd[2 * VAR_8 + 1]); } isa_create_simple(isa_bus, "i8042"); cpu = POWERPC_CPU(first_cpu); sysctrl->reset_irq = cpu->env.irq_inputs[PPC6xx_INPUT_HRESET]; portio_list_init(port_list, NULL, prep_portio_list, sysctrl, "prep"); portio_list_add(port_list, get_system_io(), 0x0); #if 0
memory_region_init_io(xcsr, NULL, &PPC_XCSR_ops, NULL, "ppc-xcsr", 0x1000); memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr); #endif
if (usb_enabled(false)) { pci_create_simple(pci_bus, -1, "pci-ohci"); } m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59); if (m48t59 == NULL)
return; sysctrl->nvram = m48t59; nvram.opaque = m48t59; nvram.read_fn = &m48t59_read; nvram.write_fn = &m48t59_write; PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, VAR_13,
kernel_base, VAR_11,
VAR_3,
initrd_base, VAR_12,
0,
graphic_width, graphic_height, graphic_depth); }