⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppc_chrp.c

📁 xen虚拟机源代码安装包
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * QEMU PPC CHRP/PMAC hardware System Emulator *  * Copyright (c) 2004 Fabrice Bellard *  * 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"#define BIOS_FILENAME "ppc_rom.bin"#define VGABIOS_FILENAME "video.x"#define NVRAM_SIZE        0x2000#define KERNEL_LOAD_ADDR 0x01000000#define INITRD_LOAD_ADDR 0x01800000/* MacIO devices (mapped inside the MacIO address space): CUDA, DBDMA,   NVRAM */static int dbdma_mem_index;static int cuda_mem_index;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;static int macio_nvram_mem_index = -1;/* DBDMA: currently no op - should suffice right now */static void dbdma_writeb (void *opaque, target_phys_addr_t addr, uint32_t value){    printf("%s: 0x%08x <= 0x%08x\n", __func__, addr, value);}static void dbdma_writew (void *opaque, target_phys_addr_t addr, uint32_t value){}static void dbdma_writel (void *opaque, target_phys_addr_t addr, uint32_t value){}static uint32_t dbdma_readb (void *opaque, target_phys_addr_t addr){    printf("%s: 0x%08x => 0x00000000\n", __func__, addr);    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,};/* macio style NVRAM device */typedef struct MacIONVRAMState {    uint8_t data[0x2000];} MacIONVRAMState;static void macio_nvram_writeb (void *opaque, target_phys_addr_t addr, uint32_t value){    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);    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,};static MacIONVRAMState *macio_nvram_init(void){    MacIONVRAMState *s;    s = qemu_mallocz(sizeof(MacIONVRAMState));    if (!s)        return NULL;    macio_nvram_mem_index = cpu_register_io_memory(0, macio_nvram_read,                                                    macio_nvram_write, s);    return s;}static void macio_map(PCIDevice *pci_dev, int region_num,                       uint32_t addr, uint32_t size, int type){    if (heathrow_pic_mem_index >= 0) {        cpu_register_physical_memory(addr + 0x00000, 0x1000,                                      heathrow_pic_mem_index);    }    cpu_register_physical_memory(addr + 0x08000, 0x1000, dbdma_mem_index);    cpu_register_physical_memory(addr + 0x16000, 0x2000, cuda_mem_index);    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) {        cpu_register_physical_memory(addr + 0x40000, 0x40000,                                      openpic_mem_index);    }    if (macio_nvram_mem_index >= 0)        cpu_register_physical_memory(addr + 0x60000, 0x20000, macio_nvram_mem_index);}static void macio_init(PCIBus *bus, int device_id){    PCIDevice *d;    d = pci_register_device(bus, "macio", sizeof(PCIDevice),                            -1, NULL, NULL);    /* Note: this code is strongly inspirated from the corresponding code       in PearPC */    d->config[0x00] = 0x6b; // vendor_id    d->config[0x01] = 0x10;    d->config[0x02] = device_id;    d->config[0x03] = device_id >> 8;    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        dbdma_mem_index = cpu_register_io_memory(0, dbdma_read, dbdma_write, NULL);    pci_register_io_region(d, 0, 0x80000,                            PCI_ADDRESS_SPACE_MEM, macio_map);}/* 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 */static int vga_osi_call(CPUState *env){    static int vga_vbl_enabled;    int linesize;        //    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;            }        }        env->gpr[3] = 0;         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 */        env->gpr[3] = 0;         break;    case 116: /* set hwcursor */        /* R6 = x, R7 = y, R8 = visible, R9 = data */        break;    default:        fprintf(stderr, "unsupported OSI call R5=%08x\n", env->gpr[5]);        break;    }    return 1; /* osi_call handled */}/* XXX: suppress that */static void pic_irq_request(void *opaque, int level){}static uint8_t nvram_chksum(const uint8_t *buf, int n){    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 */void pmac_format_nvram_partition(uint8_t *buf, int len){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -