2 * QEMU Sun4m & Sun4d & Sun4c System Emulator
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu-timer.h"
28 #include "sparc32_dma.h"
33 #include "firmware_abi.h"
42 * Sun4m architecture was used in the following machines:
44 * SPARCserver 6xxMP/xx
45 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
46 * SPARCclassic X (4/10)
47 * SPARCstation LX/ZX (4/30)
48 * SPARCstation Voyager
49 * SPARCstation 10/xx, SPARCserver 10/xx
50 * SPARCstation 5, SPARCserver 5
51 * SPARCstation 20/xx, SPARCserver 20
54 * Sun4d architecture was used in the following machines:
59 * Sun4c architecture was used in the following machines:
60 * SPARCstation 1/1+, SPARCserver 1/1+
66 * See for example: http://www.sunhelp.org/faq/sunref1.html
70 #define DPRINTF(fmt, args...) \
71 do { printf("CPUIRQ: " fmt , ##args); } while (0)
73 #define DPRINTF(fmt, args...)
76 #define KERNEL_LOAD_ADDR 0x00004000
77 #define CMDLINE_ADDR 0x007ff000
78 #define INITRD_LOAD_ADDR 0x00800000
79 #define PROM_SIZE_MAX (512 * 1024)
80 #define PROM_VADDR 0xffd00000
81 #define PROM_FILENAME "openbios-sparc32"
82 #define CFG_ADDR 0xd00000510ULL
83 #define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
85 // Control plane, 8-bit and 24-bit planes
86 #define TCX_SIZE (9 * 1024 * 1024)
92 target_phys_addr_t iommu_base, slavio_base;
93 target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
94 target_phys_addr_t serial_base, fd_base;
95 target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
96 target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base;
97 target_phys_addr_t ecc_base;
99 long vram_size, nvram_size;
100 // IRQ numbers are not PIL ones, but master interrupt controller
101 // register bit numbers
102 int intctl_g_intr, esp_irq, le_irq, clock_irq, clock1_irq;
103 int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq, ecc_irq;
104 uint8_t nvram_machine_id;
106 uint32_t iommu_version;
107 uint32_t intbit_to_level[32];
109 const char * const default_cpu_model;
112 #define MAX_IOUNITS 5
115 target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base;
116 target_phys_addr_t counter_base, nvram_base, ms_kb_base;
117 target_phys_addr_t serial_base;
118 target_phys_addr_t espdma_base, esp_base;
119 target_phys_addr_t ledma_base, le_base;
120 target_phys_addr_t tcx_base;
121 target_phys_addr_t sbi_base;
122 unsigned long vram_size, nvram_size;
123 // IRQ numbers are not PIL ones, but SBI register bit numbers
124 int esp_irq, le_irq, clock_irq, clock1_irq;
125 int ser_irq, ms_kb_irq, me_irq;
126 uint8_t nvram_machine_id;
128 uint32_t iounit_version;
130 const char * const default_cpu_model;
134 target_phys_addr_t iommu_base, slavio_base;
135 target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
136 target_phys_addr_t serial_base, fd_base;
137 target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
138 target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base;
139 long vram_size, nvram_size;
140 // IRQ numbers are not PIL ones, but master interrupt controller
141 // register bit numbers
142 int intctl_g_intr, esp_irq, le_irq, clock_irq, clock1_irq;
143 int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq;
144 uint8_t nvram_machine_id;
146 uint32_t iommu_version;
147 uint32_t intbit_to_level[32];
149 const char * const default_cpu_model;
152 int DMA_get_channel_mode (int nchan)
156 int DMA_read_memory (int nchan, void *buf, int pos, int size)
160 int DMA_write_memory (int nchan, void *buf, int pos, int size)
164 void DMA_hold_DREQ (int nchan) {}
165 void DMA_release_DREQ (int nchan) {}
166 void DMA_schedule(int nchan) {}
167 void DMA_run (void) {}
168 void DMA_init (int high_page_enable) {}
169 void DMA_register_channel (int nchan,
170 DMA_transfer_handler transfer_handler,
175 static int nvram_boot_set(void *opaque, const char *boot_device)
178 uint8_t image[sizeof(ohwcfg_v3_t)];
179 ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
180 m48t59_t *nvram = (m48t59_t *)opaque;
182 for (i = 0; i < sizeof(image); i++)
183 image[i] = m48t59_read(nvram, i) & 0xff;
185 pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
187 header->nboot_devices = strlen(boot_device) & 0xff;
188 header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
190 for (i = 0; i < sizeof(image); i++)
191 m48t59_write(nvram, i, image[i]);
196 static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
197 const char *boot_devices, ram_addr_t RAM_size,
198 uint32_t kernel_size,
199 int width, int height, int depth,
200 int nvram_machine_id, const char *arch)
204 uint8_t image[0x1ff0];
205 ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
206 struct sparc_arch_cfg *sparc_header;
207 struct OpenBIOS_nvpart_v1 *part_header;
209 memset(image, '\0', sizeof(image));
211 // Try to match PPC NVRAM
212 pstrcpy((char *)header->struct_ident, sizeof(header->struct_ident),
214 header->struct_version = cpu_to_be32(3); /* structure v3 */
216 header->nvram_size = cpu_to_be16(0x2000);
217 header->nvram_arch_ptr = cpu_to_be16(sizeof(ohwcfg_v3_t));
218 header->nvram_arch_size = cpu_to_be16(sizeof(struct sparc_arch_cfg));
219 pstrcpy((char *)header->arch, sizeof(header->arch), arch);
220 header->nb_cpus = smp_cpus & 0xff;
221 header->RAM0_base = 0;
222 header->RAM0_size = cpu_to_be64((uint64_t)RAM_size);
223 pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
225 header->nboot_devices = strlen(boot_devices) & 0xff;
226 header->kernel_image = cpu_to_be64((uint64_t)KERNEL_LOAD_ADDR);
227 header->kernel_size = cpu_to_be64((uint64_t)kernel_size);
229 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, cmdline);
230 header->cmdline = cpu_to_be64((uint64_t)CMDLINE_ADDR);
231 header->cmdline_size = cpu_to_be64((uint64_t)strlen(cmdline));
233 // XXX add initrd_image, initrd_size
234 header->width = cpu_to_be16(width);
235 header->height = cpu_to_be16(height);
236 header->depth = cpu_to_be16(depth);
238 header->graphic_flags = cpu_to_be16(OHW_GF_NOGRAPHICS);
240 header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
242 // Architecture specific header
243 start = sizeof(ohwcfg_v3_t);
244 sparc_header = (struct sparc_arch_cfg *)&image[start];
245 sparc_header->valid = 0;
246 start += sizeof(struct sparc_arch_cfg);
248 // OpenBIOS nvram variables
249 // Variable partition
250 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
251 part_header->signature = OPENBIOS_PART_SYSTEM;
252 pstrcpy(part_header->name, sizeof(part_header->name), "system");
254 end = start + sizeof(struct OpenBIOS_nvpart_v1);
255 for (i = 0; i < nb_prom_envs; i++)
256 end = OpenBIOS_set_var(image, end, prom_envs[i]);
261 end = start + ((end - start + 15) & ~15);
262 OpenBIOS_finish_partition(part_header, end - start);
266 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
267 part_header->signature = OPENBIOS_PART_FREE;
268 pstrcpy(part_header->name, sizeof(part_header->name), "free");
271 OpenBIOS_finish_partition(part_header, end - start);
273 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
276 for (i = 0; i < sizeof(image); i++)
277 m48t59_write(nvram, i, image[i]);
279 qemu_register_boot_set(nvram_boot_set, nvram);
282 static void *slavio_intctl;
287 slavio_pic_info(slavio_intctl);
293 slavio_irq_info(slavio_intctl);
296 void cpu_check_irqs(CPUState *env)
298 if (env->pil_in && (env->interrupt_index == 0 ||
299 (env->interrupt_index & ~15) == TT_EXTINT)) {
302 for (i = 15; i > 0; i--) {
303 if (env->pil_in & (1 << i)) {
304 int old_interrupt = env->interrupt_index;
306 env->interrupt_index = TT_EXTINT | i;
307 if (old_interrupt != env->interrupt_index) {
308 DPRINTF("Set CPU IRQ %d\n", i);
309 cpu_interrupt(env, CPU_INTERRUPT_HARD);
314 } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
315 DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
316 env->interrupt_index = 0;
317 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
321 static void cpu_set_irq(void *opaque, int irq, int level)
323 CPUState *env = opaque;
326 DPRINTF("Raise CPU IRQ %d\n", irq);
328 env->pil_in |= 1 << irq;
331 DPRINTF("Lower CPU IRQ %d\n", irq);
332 env->pil_in &= ~(1 << irq);
337 static void dummy_cpu_set_irq(void *opaque, int irq, int level)
341 static void *slavio_misc;
343 void qemu_system_powerdown(void)
345 slavio_set_power_fail(slavio_misc, 1);
348 static void main_cpu_reset(void *opaque)
350 CPUState *env = opaque;
356 static void secondary_cpu_reset(void *opaque)
358 CPUState *env = opaque;
364 static unsigned long sun4m_load_kernel(const char *kernel_filename,
365 const char *initrd_filename,
370 long initrd_size, kernel_size;
372 linux_boot = (kernel_filename != NULL);
376 kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL,
379 kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
380 RAM_size - KERNEL_LOAD_ADDR);
382 kernel_size = load_image_targphys(kernel_filename,
384 RAM_size - KERNEL_LOAD_ADDR);
385 if (kernel_size < 0) {
386 fprintf(stderr, "qemu: could not load kernel '%s'\n",
393 if (initrd_filename) {
394 initrd_size = load_image_targphys(initrd_filename,
396 RAM_size - INITRD_LOAD_ADDR);
397 if (initrd_size < 0) {
398 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
403 if (initrd_size > 0) {
404 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
405 if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
406 stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
407 stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
416 static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
417 const char *boot_device,
418 DisplayState *ds, const char *kernel_filename,
419 const char *kernel_cmdline,
420 const char *initrd_filename, const char *cpu_model)
423 CPUState *env, *envs[MAX_CPUS];
425 void *iommu, *espdma, *ledma, *main_esp, *nvram;
426 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
427 *espdma_irq, *ledma_irq;
428 qemu_irq *esp_reset, *le_reset;
430 unsigned long prom_offset, kernel_size;
433 BlockDriverState *fd[MAX_FD];
439 cpu_model = hwdef->default_cpu_model;
441 for(i = 0; i < smp_cpus; i++) {
442 env = cpu_init(cpu_model);
444 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
447 cpu_sparc_set_id(env, i);
450 qemu_register_reset(main_cpu_reset, env);
452 qemu_register_reset(secondary_cpu_reset, env);
455 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
456 env->prom_addr = hwdef->slavio_base;
459 for (i = smp_cpus; i < MAX_CPUS; i++)
460 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
464 if ((uint64_t)RAM_size > hwdef->max_mem) {
466 "qemu: Too much memory for this machine: %d, maximum %d\n",
467 (unsigned int)(RAM_size / (1024 * 1024)),
468 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
471 cpu_register_physical_memory(0, RAM_size, 0);
474 prom_offset = RAM_size + hwdef->vram_size;
475 cpu_register_physical_memory(hwdef->slavio_base,
476 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
478 prom_offset | IO_MEM_ROM);
480 if (bios_name == NULL)
481 bios_name = PROM_FILENAME;
482 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
483 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
484 if (ret < 0 || ret > PROM_SIZE_MAX)
485 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
486 if (ret < 0 || ret > PROM_SIZE_MAX) {
487 fprintf(stderr, "qemu: could not load prom '%s'\n",
491 prom_offset += (ret + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
494 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
495 hwdef->intctl_base + 0x10000ULL,
496 &hwdef->intbit_to_level[0],
497 &slavio_irq, &slavio_cpu_irq,
501 if (hwdef->idreg_base != (target_phys_addr_t)-1) {
502 static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
504 cpu_register_physical_memory(hwdef->idreg_base, sizeof(idreg_data),
505 prom_offset | IO_MEM_ROM);
506 cpu_physical_memory_write_rom(hwdef->idreg_base, idreg_data,
510 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
511 slavio_irq[hwdef->me_irq]);
513 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
514 iommu, &espdma_irq, &esp_reset);
516 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
517 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
520 if (graphic_depth != 8 && graphic_depth != 24) {
521 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
524 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
525 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
527 if (nd_table[0].model == NULL
528 || strcmp(nd_table[0].model, "lance") == 0) {
529 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
530 } else if (strcmp(nd_table[0].model, "?") == 0) {
531 fprintf(stderr, "qemu: Supported NICs: lance\n");
534 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
538 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
539 hwdef->nvram_size, 8);
541 slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq],
542 slavio_cpu_irq, smp_cpus);
544 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
546 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
547 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
548 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
549 serial_hds[1], serial_hds[0]);
551 slavio_misc = slavio_misc_init(hwdef->slavio_base, hwdef->apc_base,
552 hwdef->aux1_base, hwdef->aux2_base,
553 slavio_irq[hwdef->me_irq], envs[0],
556 if (hwdef->fd_base != (target_phys_addr_t)-1) {
557 /* there is zero or one floppy drive */
558 memset(fd, 0, sizeof(fd));
559 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
560 if (drive_index != -1)
561 fd[0] = drives_table[drive_index].bdrv;
563 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
567 if (drive_get_max_bus(IF_SCSI) > 0) {
568 fprintf(stderr, "qemu: too many SCSI bus\n");
572 main_esp = esp_init(hwdef->esp_base, 2,
573 espdma_memory_read, espdma_memory_write,
574 espdma, *espdma_irq, esp_reset);
576 for (i = 0; i < ESP_MAX_DEVS; i++) {
577 drive_index = drive_get_index(IF_SCSI, 0, i);
578 if (drive_index == -1)
580 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
583 if (hwdef->cs_base != (target_phys_addr_t)-1)
584 cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl);
586 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
589 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
590 boot_device, RAM_size, kernel_size, graphic_width,
591 graphic_height, graphic_depth, hwdef->nvram_machine_id,
594 if (hwdef->ecc_base != (target_phys_addr_t)-1)
595 ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
598 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
599 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
600 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
601 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
602 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
620 static const struct sun4m_hwdef sun4m_hwdefs[] = {
623 .iommu_base = 0x10000000,
624 .tcx_base = 0x50000000,
625 .cs_base = 0x6c000000,
626 .slavio_base = 0x70000000,
627 .ms_kb_base = 0x71000000,
628 .serial_base = 0x71100000,
629 .nvram_base = 0x71200000,
630 .fd_base = 0x71400000,
631 .counter_base = 0x71d00000,
632 .intctl_base = 0x71e00000,
633 .idreg_base = 0x78000000,
634 .dma_base = 0x78400000,
635 .esp_base = 0x78800000,
636 .le_base = 0x78c00000,
637 .apc_base = 0x6a000000,
638 .aux1_base = 0x71900000,
639 .aux2_base = 0x71910000,
641 .vram_size = 0x00100000,
642 .nvram_size = 0x2000,
652 .nvram_machine_id = 0x80,
653 .machine_id = ss5_id,
654 .iommu_version = 0x05000000,
656 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
657 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
659 .max_mem = 0x10000000,
660 .default_cpu_model = "Fujitsu MB86904",
664 .iommu_base = 0xfe0000000ULL,
665 .tcx_base = 0xe20000000ULL,
667 .slavio_base = 0xff0000000ULL,
668 .ms_kb_base = 0xff1000000ULL,
669 .serial_base = 0xff1100000ULL,
670 .nvram_base = 0xff1200000ULL,
671 .fd_base = 0xff1700000ULL,
672 .counter_base = 0xff1300000ULL,
673 .intctl_base = 0xff1400000ULL,
674 .idreg_base = 0xef0000000ULL,
675 .dma_base = 0xef0400000ULL,
676 .esp_base = 0xef0800000ULL,
677 .le_base = 0xef0c00000ULL,
678 .apc_base = 0xefa000000ULL, // XXX should not exist
679 .aux1_base = 0xff1800000ULL,
680 .aux2_base = 0xff1a01000ULL,
681 .ecc_base = 0xf00000000ULL,
682 .ecc_version = 0x10000000, // version 0, implementation 1
683 .vram_size = 0x00100000,
684 .nvram_size = 0x2000,
695 .nvram_machine_id = 0x72,
696 .machine_id = ss10_id,
697 .iommu_version = 0x03000000,
699 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
700 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
702 .max_mem = 0xf00000000ULL,
703 .default_cpu_model = "TI SuperSparc II",
707 .iommu_base = 0xfe0000000ULL,
708 .tcx_base = 0xe20000000ULL,
710 .slavio_base = 0xff0000000ULL,
711 .ms_kb_base = 0xff1000000ULL,
712 .serial_base = 0xff1100000ULL,
713 .nvram_base = 0xff1200000ULL,
715 .counter_base = 0xff1300000ULL,
716 .intctl_base = 0xff1400000ULL,
718 .dma_base = 0xef0081000ULL,
719 .esp_base = 0xef0080000ULL,
720 .le_base = 0xef0060000ULL,
721 .apc_base = 0xefa000000ULL, // XXX should not exist
722 .aux1_base = 0xff1800000ULL,
723 .aux2_base = 0xff1a01000ULL, // XXX should not exist
724 .ecc_base = 0xf00000000ULL,
725 .ecc_version = 0x00000000, // version 0, implementation 0
726 .vram_size = 0x00100000,
727 .nvram_size = 0x2000,
738 .nvram_machine_id = 0x71,
739 .machine_id = ss600mp_id,
740 .iommu_version = 0x01000000,
742 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
743 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
745 .max_mem = 0xf00000000ULL,
746 .default_cpu_model = "TI SuperSparc II",
750 .iommu_base = 0xfe0000000ULL,
751 .tcx_base = 0xe20000000ULL,
753 .slavio_base = 0xff0000000ULL,
754 .ms_kb_base = 0xff1000000ULL,
755 .serial_base = 0xff1100000ULL,
756 .nvram_base = 0xff1200000ULL,
757 .fd_base = 0xff1700000ULL,
758 .counter_base = 0xff1300000ULL,
759 .intctl_base = 0xff1400000ULL,
760 .idreg_base = 0xef0000000ULL,
761 .dma_base = 0xef0400000ULL,
762 .esp_base = 0xef0800000ULL,
763 .le_base = 0xef0c00000ULL,
764 .apc_base = 0xefa000000ULL, // XXX should not exist
765 .aux1_base = 0xff1800000ULL,
766 .aux2_base = 0xff1a01000ULL,
767 .ecc_base = 0xf00000000ULL,
768 .ecc_version = 0x20000000, // version 0, implementation 2
769 .vram_size = 0x00100000,
770 .nvram_size = 0x2000,
781 .nvram_machine_id = 0x72,
782 .machine_id = ss20_id,
783 .iommu_version = 0x13000000,
785 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
786 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
788 .max_mem = 0xf00000000ULL,
789 .default_cpu_model = "TI SuperSparc II",
793 .iommu_base = 0x10000000,
794 .tcx_base = 0x50000000,
796 .slavio_base = 0x70000000,
797 .ms_kb_base = 0x71000000,
798 .serial_base = 0x71100000,
799 .nvram_base = 0x71200000,
800 .fd_base = 0x71400000,
801 .counter_base = 0x71d00000,
802 .intctl_base = 0x71e00000,
803 .idreg_base = 0x78000000,
804 .dma_base = 0x78400000,
805 .esp_base = 0x78800000,
806 .le_base = 0x78c00000,
807 .apc_base = 0x71300000, // pmc
808 .aux1_base = 0x71900000,
809 .aux2_base = 0x71910000,
811 .vram_size = 0x00100000,
812 .nvram_size = 0x2000,
822 .nvram_machine_id = 0x80,
823 .machine_id = vger_id,
824 .iommu_version = 0x05000000,
826 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
827 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
829 .max_mem = 0x10000000,
830 .default_cpu_model = "Fujitsu MB86904",
834 .iommu_base = 0x10000000,
835 .tcx_base = 0x50000000,
837 .slavio_base = 0x70000000,
838 .ms_kb_base = 0x71000000,
839 .serial_base = 0x71100000,
840 .nvram_base = 0x71200000,
841 .fd_base = 0x71400000,
842 .counter_base = 0x71d00000,
843 .intctl_base = 0x71e00000,
844 .idreg_base = 0x78000000,
845 .dma_base = 0x78400000,
846 .esp_base = 0x78800000,
847 .le_base = 0x78c00000,
849 .aux1_base = 0x71900000,
850 .aux2_base = 0x71910000,
852 .vram_size = 0x00100000,
853 .nvram_size = 0x2000,
863 .nvram_machine_id = 0x80,
865 .iommu_version = 0x04000000,
867 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
868 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
870 .max_mem = 0x10000000,
871 .default_cpu_model = "TI MicroSparc I",
875 .iommu_base = 0x10000000,
876 .tcx_base = 0x50000000,
877 .cs_base = 0x6c000000,
878 .slavio_base = 0x70000000,
879 .ms_kb_base = 0x71000000,
880 .serial_base = 0x71100000,
881 .nvram_base = 0x71200000,
882 .fd_base = 0x71400000,
883 .counter_base = 0x71d00000,
884 .intctl_base = 0x71e00000,
885 .idreg_base = 0x78000000,
886 .dma_base = 0x78400000,
887 .esp_base = 0x78800000,
888 .le_base = 0x78c00000,
889 .apc_base = 0x6a000000,
890 .aux1_base = 0x71900000,
891 .aux2_base = 0x71910000,
893 .vram_size = 0x00100000,
894 .nvram_size = 0x2000,
904 .nvram_machine_id = 0x80,
905 .machine_id = ss4_id,
906 .iommu_version = 0x05000000,
908 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
909 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
911 .max_mem = 0x10000000,
912 .default_cpu_model = "Fujitsu MB86904",
916 .iommu_base = 0x10000000,
917 .tcx_base = 0x50000000,
919 .slavio_base = 0x70000000,
920 .ms_kb_base = 0x71000000,
921 .serial_base = 0x71100000,
922 .nvram_base = 0x71200000,
923 .fd_base = 0x71400000,
924 .counter_base = 0x71d00000,
925 .intctl_base = 0x71e00000,
926 .idreg_base = 0x78000000,
927 .dma_base = 0x78400000,
928 .esp_base = 0x78800000,
929 .le_base = 0x78c00000,
930 .apc_base = 0x6a000000,
931 .aux1_base = 0x71900000,
932 .aux2_base = 0x71910000,
934 .vram_size = 0x00100000,
935 .nvram_size = 0x2000,
945 .nvram_machine_id = 0x80,
946 .machine_id = scls_id,
947 .iommu_version = 0x05000000,
949 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
950 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
952 .max_mem = 0x10000000,
953 .default_cpu_model = "TI MicroSparc I",
957 .iommu_base = 0x10000000,
958 .tcx_base = 0x50000000, // XXX
960 .slavio_base = 0x70000000,
961 .ms_kb_base = 0x71000000,
962 .serial_base = 0x71100000,
963 .nvram_base = 0x71200000,
964 .fd_base = 0x71400000,
965 .counter_base = 0x71d00000,
966 .intctl_base = 0x71e00000,
967 .idreg_base = 0x78000000,
968 .dma_base = 0x78400000,
969 .esp_base = 0x78800000,
970 .le_base = 0x78c00000,
971 .apc_base = 0x6a000000,
972 .aux1_base = 0x71900000,
973 .aux2_base = 0x71910000,
975 .vram_size = 0x00100000,
976 .nvram_size = 0x2000,
986 .nvram_machine_id = 0x80,
987 .machine_id = sbook_id,
988 .iommu_version = 0x05000000,
990 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
991 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
993 .max_mem = 0x10000000,
994 .default_cpu_model = "TI MicroSparc I",
998 /* SPARCstation 5 hardware initialisation */
999 static void ss5_init(ram_addr_t RAM_size, int vga_ram_size,
1000 const char *boot_device, DisplayState *ds,
1001 const char *kernel_filename, const char *kernel_cmdline,
1002 const char *initrd_filename, const char *cpu_model)
1004 sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1005 kernel_cmdline, initrd_filename, cpu_model);
1008 /* SPARCstation 10 hardware initialisation */
1009 static void ss10_init(ram_addr_t RAM_size, int vga_ram_size,
1010 const char *boot_device, DisplayState *ds,
1011 const char *kernel_filename, const char *kernel_cmdline,
1012 const char *initrd_filename, const char *cpu_model)
1014 sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, ds, kernel_filename,
1015 kernel_cmdline, initrd_filename, cpu_model);
1018 /* SPARCserver 600MP hardware initialisation */
1019 static void ss600mp_init(ram_addr_t RAM_size, int vga_ram_size,
1020 const char *boot_device, DisplayState *ds,
1021 const char *kernel_filename,
1022 const char *kernel_cmdline,
1023 const char *initrd_filename, const char *cpu_model)
1025 sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, ds, kernel_filename,
1026 kernel_cmdline, initrd_filename, cpu_model);
1029 /* SPARCstation 20 hardware initialisation */
1030 static void ss20_init(ram_addr_t RAM_size, int vga_ram_size,
1031 const char *boot_device, DisplayState *ds,
1032 const char *kernel_filename, const char *kernel_cmdline,
1033 const char *initrd_filename, const char *cpu_model)
1035 sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, ds, kernel_filename,
1036 kernel_cmdline, initrd_filename, cpu_model);
1039 /* SPARCstation Voyager hardware initialisation */
1040 static void vger_init(ram_addr_t RAM_size, int vga_ram_size,
1041 const char *boot_device, DisplayState *ds,
1042 const char *kernel_filename, const char *kernel_cmdline,
1043 const char *initrd_filename, const char *cpu_model)
1045 sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, ds, kernel_filename,
1046 kernel_cmdline, initrd_filename, cpu_model);
1049 /* SPARCstation LX hardware initialisation */
1050 static void ss_lx_init(ram_addr_t RAM_size, int vga_ram_size,
1051 const char *boot_device, DisplayState *ds,
1052 const char *kernel_filename, const char *kernel_cmdline,
1053 const char *initrd_filename, const char *cpu_model)
1055 sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, ds, kernel_filename,
1056 kernel_cmdline, initrd_filename, cpu_model);
1059 /* SPARCstation 4 hardware initialisation */
1060 static void ss4_init(ram_addr_t RAM_size, int vga_ram_size,
1061 const char *boot_device, DisplayState *ds,
1062 const char *kernel_filename, const char *kernel_cmdline,
1063 const char *initrd_filename, const char *cpu_model)
1065 sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, ds, kernel_filename,
1066 kernel_cmdline, initrd_filename, cpu_model);
1069 /* SPARCClassic hardware initialisation */
1070 static void scls_init(ram_addr_t RAM_size, int vga_ram_size,
1071 const char *boot_device, DisplayState *ds,
1072 const char *kernel_filename, const char *kernel_cmdline,
1073 const char *initrd_filename, const char *cpu_model)
1075 sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, ds, kernel_filename,
1076 kernel_cmdline, initrd_filename, cpu_model);
1079 /* SPARCbook hardware initialisation */
1080 static void sbook_init(ram_addr_t RAM_size, int vga_ram_size,
1081 const char *boot_device, DisplayState *ds,
1082 const char *kernel_filename, const char *kernel_cmdline,
1083 const char *initrd_filename, const char *cpu_model)
1085 sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, ds, kernel_filename,
1086 kernel_cmdline, initrd_filename, cpu_model);
1089 QEMUMachine ss5_machine = {
1091 .desc = "Sun4m platform, SPARCstation 5",
1093 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1099 QEMUMachine ss10_machine = {
1101 .desc = "Sun4m platform, SPARCstation 10",
1103 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1109 QEMUMachine ss600mp_machine = {
1111 .desc = "Sun4m platform, SPARCserver 600MP",
1112 .init = ss600mp_init,
1113 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1119 QEMUMachine ss20_machine = {
1121 .desc = "Sun4m platform, SPARCstation 20",
1123 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1129 QEMUMachine voyager_machine = {
1131 .desc = "Sun4m platform, SPARCstation Voyager",
1133 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1139 QEMUMachine ss_lx_machine = {
1141 .desc = "Sun4m platform, SPARCstation LX",
1143 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1149 QEMUMachine ss4_machine = {
1151 .desc = "Sun4m platform, SPARCstation 4",
1153 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1159 QEMUMachine scls_machine = {
1160 .name = "SPARCClassic",
1161 .desc = "Sun4m platform, SPARCClassic",
1163 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1169 QEMUMachine sbook_machine = {
1170 .name = "SPARCbook",
1171 .desc = "Sun4m platform, SPARCbook",
1173 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1179 static const struct sun4d_hwdef sun4d_hwdefs[] = {
1189 .tcx_base = 0x820000000ULL,
1190 .slavio_base = 0xf00000000ULL,
1191 .ms_kb_base = 0xf00240000ULL,
1192 .serial_base = 0xf00200000ULL,
1193 .nvram_base = 0xf00280000ULL,
1194 .counter_base = 0xf00300000ULL,
1195 .espdma_base = 0x800081000ULL,
1196 .esp_base = 0x800080000ULL,
1197 .ledma_base = 0x800040000ULL,
1198 .le_base = 0x800060000ULL,
1199 .sbi_base = 0xf02800000ULL,
1200 .vram_size = 0x00100000,
1201 .nvram_size = 0x2000,
1208 .nvram_machine_id = 0x80,
1209 .machine_id = ss1000_id,
1210 .iounit_version = 0x03000000,
1211 .max_mem = 0xf00000000ULL,
1212 .default_cpu_model = "TI SuperSparc II",
1223 .tcx_base = 0x820000000ULL,
1224 .slavio_base = 0xf00000000ULL,
1225 .ms_kb_base = 0xf00240000ULL,
1226 .serial_base = 0xf00200000ULL,
1227 .nvram_base = 0xf00280000ULL,
1228 .counter_base = 0xf00300000ULL,
1229 .espdma_base = 0x800081000ULL,
1230 .esp_base = 0x800080000ULL,
1231 .ledma_base = 0x800040000ULL,
1232 .le_base = 0x800060000ULL,
1233 .sbi_base = 0xf02800000ULL,
1234 .vram_size = 0x00100000,
1235 .nvram_size = 0x2000,
1242 .nvram_machine_id = 0x80,
1243 .machine_id = ss2000_id,
1244 .iounit_version = 0x03000000,
1245 .max_mem = 0xf00000000ULL,
1246 .default_cpu_model = "TI SuperSparc II",
1250 static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1251 const char *boot_device,
1252 DisplayState *ds, const char *kernel_filename,
1253 const char *kernel_cmdline,
1254 const char *initrd_filename, const char *cpu_model)
1256 CPUState *env, *envs[MAX_CPUS];
1258 void *iounits[MAX_IOUNITS], *espdma, *ledma, *main_esp, *nvram, *sbi;
1259 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1260 *espdma_irq, *ledma_irq;
1261 qemu_irq *esp_reset, *le_reset;
1262 unsigned long prom_offset, kernel_size;
1270 cpu_model = hwdef->default_cpu_model;
1272 for (i = 0; i < smp_cpus; i++) {
1273 env = cpu_init(cpu_model);
1275 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1278 cpu_sparc_set_id(env, i);
1281 qemu_register_reset(main_cpu_reset, env);
1283 qemu_register_reset(secondary_cpu_reset, env);
1286 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
1287 env->prom_addr = hwdef->slavio_base;
1290 for (i = smp_cpus; i < MAX_CPUS; i++)
1291 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1294 if ((uint64_t)RAM_size > hwdef->max_mem) {
1296 "qemu: Too much memory for this machine: %d, maximum %d\n",
1297 (unsigned int)(RAM_size / (1024 * 1024)),
1298 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1301 cpu_register_physical_memory(0, RAM_size, 0);
1303 /* load boot prom */
1304 prom_offset = RAM_size + hwdef->vram_size;
1305 cpu_register_physical_memory(hwdef->slavio_base,
1306 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1308 prom_offset | IO_MEM_ROM);
1310 if (bios_name == NULL)
1311 bios_name = PROM_FILENAME;
1312 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1313 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1314 if (ret < 0 || ret > PROM_SIZE_MAX)
1315 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
1316 if (ret < 0 || ret > PROM_SIZE_MAX) {
1317 fprintf(stderr, "qemu: could not load prom '%s'\n",
1322 /* set up devices */
1323 sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
1325 for (i = 0; i < MAX_IOUNITS; i++)
1326 if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
1327 iounits[i] = iommu_init(hwdef->iounit_bases[i],
1328 hwdef->iounit_version,
1329 sbi_irq[hwdef->me_irq]);
1331 espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq],
1332 iounits[0], &espdma_irq, &esp_reset);
1334 ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq],
1335 iounits[0], &ledma_irq, &le_reset);
1337 if (graphic_depth != 8 && graphic_depth != 24) {
1338 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1341 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
1342 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1344 if (nd_table[0].model == NULL
1345 || strcmp(nd_table[0].model, "lance") == 0) {
1346 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1347 } else if (strcmp(nd_table[0].model, "?") == 0) {
1348 fprintf(stderr, "qemu: Supported NICs: lance\n");
1351 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
1355 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1356 hwdef->nvram_size, 8);
1358 slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq],
1359 sbi_cpu_irq, smp_cpus);
1361 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
1363 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1364 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1365 slavio_serial_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq],
1366 serial_hds[1], serial_hds[0]);
1368 if (drive_get_max_bus(IF_SCSI) > 0) {
1369 fprintf(stderr, "qemu: too many SCSI bus\n");
1373 main_esp = esp_init(hwdef->esp_base, 2,
1374 espdma_memory_read, espdma_memory_write,
1375 espdma, *espdma_irq, esp_reset);
1377 for (i = 0; i < ESP_MAX_DEVS; i++) {
1378 drive_index = drive_get_index(IF_SCSI, 0, i);
1379 if (drive_index == -1)
1381 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
1384 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1387 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1388 boot_device, RAM_size, kernel_size, graphic_width,
1389 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1392 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1393 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1394 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1395 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1398 /* SPARCserver 1000 hardware initialisation */
1399 static void ss1000_init(ram_addr_t RAM_size, int vga_ram_size,
1400 const char *boot_device, DisplayState *ds,
1401 const char *kernel_filename, const char *kernel_cmdline,
1402 const char *initrd_filename, const char *cpu_model)
1404 sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1405 kernel_cmdline, initrd_filename, cpu_model);
1408 /* SPARCcenter 2000 hardware initialisation */
1409 static void ss2000_init(ram_addr_t RAM_size, int vga_ram_size,
1410 const char *boot_device, DisplayState *ds,
1411 const char *kernel_filename, const char *kernel_cmdline,
1412 const char *initrd_filename, const char *cpu_model)
1414 sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, ds, kernel_filename,
1415 kernel_cmdline, initrd_filename, cpu_model);
1418 QEMUMachine ss1000_machine = {
1420 .desc = "Sun4d platform, SPARCserver 1000",
1421 .init = ss1000_init,
1422 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1428 QEMUMachine ss2000_machine = {
1430 .desc = "Sun4d platform, SPARCcenter 2000",
1431 .init = ss2000_init,
1432 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1438 static const struct sun4c_hwdef sun4c_hwdefs[] = {
1441 .iommu_base = 0xf8000000,
1442 .tcx_base = 0xfe000000,
1444 .slavio_base = 0xf6000000,
1445 .intctl_base = 0xf5000000,
1446 .counter_base = 0xf3000000,
1447 .ms_kb_base = 0xf0000000,
1448 .serial_base = 0xf1000000,
1449 .nvram_base = 0xf2000000,
1450 .fd_base = 0xf7200000,
1451 .dma_base = 0xf8400000,
1452 .esp_base = 0xf8800000,
1453 .le_base = 0xf8c00000,
1455 .aux1_base = 0xf7400003,
1457 .vram_size = 0x00100000,
1458 .nvram_size = 0x800,
1468 .nvram_machine_id = 0x55,
1469 .machine_id = ss2_id,
1470 .max_mem = 0x10000000,
1471 .default_cpu_model = "Cypress CY7C601",
1475 static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1476 const char *boot_device,
1477 DisplayState *ds, const char *kernel_filename,
1478 const char *kernel_cmdline,
1479 const char *initrd_filename, const char *cpu_model)
1483 void *iommu, *espdma, *ledma, *main_esp, *nvram;
1484 qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
1485 qemu_irq *esp_reset, *le_reset;
1487 unsigned long prom_offset, kernel_size;
1490 BlockDriverState *fd[MAX_FD];
1496 cpu_model = hwdef->default_cpu_model;
1498 env = cpu_init(cpu_model);
1500 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1504 cpu_sparc_set_id(env, 0);
1506 qemu_register_reset(main_cpu_reset, env);
1507 cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
1508 env->prom_addr = hwdef->slavio_base;
1511 if ((uint64_t)RAM_size > hwdef->max_mem) {
1513 "qemu: Too much memory for this machine: %d, maximum %d\n",
1514 (unsigned int)(RAM_size / (1024 * 1024)),
1515 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1518 cpu_register_physical_memory(0, RAM_size, 0);
1520 /* load boot prom */
1521 prom_offset = RAM_size + hwdef->vram_size;
1522 cpu_register_physical_memory(hwdef->slavio_base,
1523 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1525 prom_offset | IO_MEM_ROM);
1527 if (bios_name == NULL)
1528 bios_name = PROM_FILENAME;
1529 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1530 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1531 if (ret < 0 || ret > PROM_SIZE_MAX)
1532 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
1533 if (ret < 0 || ret > PROM_SIZE_MAX) {
1534 fprintf(stderr, "qemu: could not load prom '%s'\n",
1538 prom_offset += (ret + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
1540 /* set up devices */
1541 slavio_intctl = sun4c_intctl_init(hwdef->intctl_base,
1542 &slavio_irq, cpu_irqs);
1544 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
1545 slavio_irq[hwdef->me_irq]);
1547 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
1548 iommu, &espdma_irq, &esp_reset);
1550 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
1551 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
1554 if (graphic_depth != 8 && graphic_depth != 24) {
1555 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1558 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
1559 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1561 if (nd_table[0].model == NULL
1562 || strcmp(nd_table[0].model, "lance") == 0) {
1563 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1564 } else if (strcmp(nd_table[0].model, "?") == 0) {
1565 fprintf(stderr, "qemu: Supported NICs: lance\n");
1568 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
1572 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
1573 hwdef->nvram_size, 2);
1575 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
1577 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1578 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1579 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
1580 serial_hds[1], serial_hds[0]);
1582 slavio_misc = slavio_misc_init(0, hwdef->apc_base,
1583 hwdef->aux1_base, hwdef->aux2_base,
1584 slavio_irq[hwdef->me_irq], env, &fdc_tc);
1586 if (hwdef->fd_base != (target_phys_addr_t)-1) {
1587 /* there is zero or one floppy drive */
1588 fd[1] = fd[0] = NULL;
1589 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
1590 if (drive_index != -1)
1591 fd[0] = drives_table[drive_index].bdrv;
1593 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
1597 if (drive_get_max_bus(IF_SCSI) > 0) {
1598 fprintf(stderr, "qemu: too many SCSI bus\n");
1602 main_esp = esp_init(hwdef->esp_base, 2,
1603 espdma_memory_read, espdma_memory_write,
1604 espdma, *espdma_irq, esp_reset);
1606 for (i = 0; i < ESP_MAX_DEVS; i++) {
1607 drive_index = drive_get_index(IF_SCSI, 0, i);
1608 if (drive_index == -1)
1610 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
1613 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1616 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1617 boot_device, RAM_size, kernel_size, graphic_width,
1618 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1621 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1622 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1623 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1624 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1627 /* SPARCstation 2 hardware initialisation */
1628 static void ss2_init(ram_addr_t RAM_size, int vga_ram_size,
1629 const char *boot_device, DisplayState *ds,
1630 const char *kernel_filename, const char *kernel_cmdline,
1631 const char *initrd_filename, const char *cpu_model)
1633 sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1634 kernel_cmdline, initrd_filename, cpu_model);
1637 QEMUMachine ss2_machine = {
1639 .desc = "Sun4c platform, SPARCstation 2",
1641 .ram_require = PROM_SIZE_MAX + TCX_SIZE,