📄 gt64xxx.c
字号:
/* ECC */ case GT_ECC_ERRDATALO: case GT_ECC_ERRDATAHI: case GT_ECC_MEM: case GT_ECC_CALC: case GT_ECC_ERRADDR: /* Read-only registers, do nothing */ break; /* PCI Internal */ case GT_PCI0_CMD: case GT_PCI1_CMD: s->regs[saddr] = val & 0x0401fc0f; break; case GT_PCI0_CFGADDR: s->pci->config_reg = val & 0x80fffffc; break; case GT_PCI0_CFGDATA: pci_host_data_writel(s->pci, 0, val); break; /* SDRAM Parameters */ case GT_SDRAM_B0: case GT_SDRAM_B1: case GT_SDRAM_B2: case GT_SDRAM_B3: /* We don't simulate electrical parameters of the SDRAM. Accept, but ignore the values. */ s->regs[saddr] = val; break; default:#if 0 printf ("gt64120_writel: Bad register offset 0x%x\n", (int)addr);#endif break; }}static uint32_t gt64120_readl (void *opaque, target_phys_addr_t addr){ GT64120State *s = opaque; uint32_t val; uint32_t saddr; val = 0; saddr = (addr & 0xfff) >> 2; switch (saddr) { /* CPU Configuration */ case GT_MULTI: /* Only one GT64xxx is present on the CPU bus, return the initial value */ val = s->regs[saddr]; break; /* CPU Error Report */ case GT_CPUERR_ADDRLO: case GT_CPUERR_ADDRHI: case GT_CPUERR_DATALO: case GT_CPUERR_DATAHI: case GT_CPUERR_PARITY: /* Emulated memory has no error, always return the initial values */ val = s->regs[saddr]; break; /* CPU Sync Barrier */ case GT_PCI0SYNC: case GT_PCI1SYNC: /* Reading those register should empty all FIFO on the PCI bus, which are not emulated. The return value should be a random value that should be ignored. */ val = 0xc000ffee; break; /* ECC */ case GT_ECC_ERRDATALO: case GT_ECC_ERRDATAHI: case GT_ECC_MEM: case GT_ECC_CALC: case GT_ECC_ERRADDR: /* Emulated memory has no error, always return the initial values */ val = s->regs[saddr]; break; case GT_CPU: case GT_PCI0IOLD: case GT_PCI0M0LD: case GT_PCI0M1LD: case GT_PCI1IOLD: case GT_PCI1M0LD: case GT_PCI1M1LD: case GT_PCI0IOHD: case GT_PCI0M0HD: case GT_PCI0M1HD: case GT_PCI1IOHD: case GT_PCI1M0HD: case GT_PCI1M1HD: case GT_PCI0_CMD: case GT_PCI1_CMD: case GT_PCI0IOREMAP: case GT_PCI0M0REMAP: case GT_PCI0M1REMAP: case GT_PCI1IOREMAP: case GT_PCI1M0REMAP: case GT_PCI1M1REMAP: val = s->regs[saddr]; break; case GT_PCI0_IACK: /* Read the IRQ number */ val = pic_read_irq(isa_pic); break; /* SDRAM Parameters */ case GT_SDRAM_B0: case GT_SDRAM_B1: case GT_SDRAM_B2: case GT_SDRAM_B3: /* We don't simulate electrical parameters of the SDRAM. Just return the last written value. */ val = s->regs[saddr]; break; /* PCI Internal */ case GT_PCI0_CFGADDR: val = s->pci->config_reg; break; case GT_PCI0_CFGDATA: val = pci_host_data_readl(s->pci, 0); break; default: val = s->regs[saddr];#if 0 printf ("gt64120_readl: Bad register offset 0x%x\n", (int)addr);#endif break; }#ifdef TARGET_WORDS_BIGENDIAN return bswap32(val);#else return val;#endif}static CPUWriteMemoryFunc *gt64120_write[] = { >64120_writel, >64120_writel, >64120_writel,};static CPUReadMemoryFunc *gt64120_read[] = { >64120_readl, >64120_readl, >64120_readl,};static int pci_gt64120_map_irq(PCIDevice *pci_dev, int irq_num){ int slot; slot = (pci_dev->devfn >> 3); switch (slot) { /* PIIX4 USB */ case 10: return 3; /* AMD 79C973 Ethernet */ case 11: return 0; /* Crystal 4281 Sound */ case 12: return 0; /* PCI slot 1 to 4 */ case 18 ... 21: return ((slot - 18) + irq_num) & 0x03; /* Unknown device, don't do any translation */ default: return irq_num; }}extern PCIDevice *piix4_dev;static int pci_irq_levels[4];static void pci_gt64120_set_irq(void *pic, int irq_num, int level){ int i, pic_irq, pic_level; pci_irq_levels[irq_num] = level; /* now we change the pic irq level according to the piix irq mappings */ /* XXX: optimize */ pic_irq = piix4_dev->config[0x60 + irq_num]; if (pic_irq < 16) { /* The pic level is the logical OR of all the PCI irqs mapped to it */ pic_level = 0; for (i = 0; i < 4; i++) { if (pic_irq == piix4_dev->config[0x60 + i]) pic_level |= pci_irq_levels[i]; } pic_set_irq(pic_irq, pic_level); }}void gt64120_reset(void *opaque){ GT64120State *s = opaque; /* CPU Configuration */#ifdef TARGET_WORDS_BIGENDIAN s->regs[GT_CPU] = 0x00000000;#else s->regs[GT_CPU] = 0x00000800;#endif s->regs[GT_MULTI] = 0x00000000; /* CPU Address decode FIXME: not complete*/ s->regs[GT_PCI0IOLD] = 0x00000080; s->regs[GT_PCI0IOHD] = 0x0000000f; s->regs[GT_PCI0M0LD] = 0x00000090; s->regs[GT_PCI0M0HD] = 0x0000001f; s->regs[GT_PCI0M1LD] = 0x00000790; s->regs[GT_PCI0M1HD] = 0x0000001f; s->regs[GT_PCI1IOLD] = 0x00000100; s->regs[GT_PCI1IOHD] = 0x0000000f; s->regs[GT_PCI1M0LD] = 0x00000110; s->regs[GT_PCI1M0HD] = 0x0000001f; s->regs[GT_PCI1M1LD] = 0x00000120; s->regs[GT_PCI1M1HD] = 0x0000002f; s->regs[GT_PCI0IOREMAP] = 0x00000080; s->regs[GT_PCI0M0REMAP] = 0x00000090; s->regs[GT_PCI0M1REMAP] = 0x00000790; s->regs[GT_PCI1IOREMAP] = 0x00000100; s->regs[GT_PCI1M0REMAP] = 0x00000110; s->regs[GT_PCI1M1REMAP] = 0x00000120; /* CPU Error Report */ s->regs[GT_CPUERR_ADDRLO] = 0x00000000; s->regs[GT_CPUERR_ADDRHI] = 0x00000000; s->regs[GT_CPUERR_DATALO] = 0xffffffff; s->regs[GT_CPUERR_DATAHI] = 0xffffffff; s->regs[GT_CPUERR_PARITY] = 0x000000ff; /* ECC */ s->regs[GT_ECC_ERRDATALO] = 0x00000000; s->regs[GT_ECC_ERRDATAHI] = 0x00000000; s->regs[GT_ECC_MEM] = 0x00000000; s->regs[GT_ECC_CALC] = 0x00000000; s->regs[GT_ECC_ERRADDR] = 0x00000000; /* SDRAM Parameters */ s->regs[GT_SDRAM_B0] = 0x00000005; s->regs[GT_SDRAM_B1] = 0x00000005; s->regs[GT_SDRAM_B2] = 0x00000005; s->regs[GT_SDRAM_B3] = 0x00000005; /* PCI Internal FIXME: not complete*/#ifdef TARGET_WORDS_BIGENDIAN s->regs[GT_PCI0_CMD] = 0x00000000; s->regs[GT_PCI1_CMD] = 0x00000000;#else s->regs[GT_PCI0_CMD] = 0x00010001; s->regs[GT_PCI1_CMD] = 0x00010001;#endif s->regs[GT_PCI0_IACK] = 0x00000000; s->regs[GT_PCI1_IACK] = 0x00000000; gt64120_pci_mapping(s);}PCIBus *pci_gt64120_init(void *pic){ GT64120State *s; PCIDevice *d; int gt64120; s = qemu_mallocz(sizeof(GT64120State)); s->pci = qemu_mallocz(sizeof(GT64120PCIState)); gt64120_reset(s); s->pci->bus = pci_register_bus(pci_gt64120_set_irq, pci_gt64120_map_irq, pic, 144, 4); gt64120 = cpu_register_io_memory(0, gt64120_read, gt64120_write, s); cpu_register_physical_memory(0x1be00000LL, 0x1000, gt64120); d = pci_register_device(s->pci->bus, "GT64120 PCI Bus", sizeof(PCIDevice), 0, NULL, NULL); d->config[0x00] = 0xab; // vendor_id d->config[0x01] = 0x11; d->config[0x02] = 0x46; // device_id d->config[0x03] = 0x20; d->config[0x04] = 0x06; d->config[0x05] = 0x00; d->config[0x06] = 0x80; d->config[0x07] = 0xa2; d->config[0x08] = 0x10; d->config[0x09] = 0x00; d->config[0x0A] = 0x80; d->config[0x0B] = 0x05; d->config[0x0C] = 0x08; d->config[0x0D] = 0x40; d->config[0x0E] = 0x00; d->config[0x0F] = 0x00; d->config[0x17] = 0x08; d->config[0x1B] = 0x1c; d->config[0x1F] = 0x1f; d->config[0x23] = 0x14; d->config[0x27] = 0x14; d->config[0x3D] = 0x01; return s->pci->bus;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -