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 target_phys_addr_t sun4c_intctl_base, sun4c_counter_base;
100 long vram_size, nvram_size;
101 // IRQ numbers are not PIL ones, but master interrupt controller
102 // register bit numbers
103 int intctl_g_intr, esp_irq, le_irq, clock_irq, clock1_irq;
104 int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq, ecc_irq;
105 uint8_t nvram_machine_id;
107 uint32_t iommu_version;
108 uint32_t intbit_to_level[32];
110 const char * const default_cpu_model;
113 #define MAX_IOUNITS 5
116 target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base;
117 target_phys_addr_t counter_base, nvram_base, ms_kb_base;
118 target_phys_addr_t serial_base;
119 target_phys_addr_t espdma_base, esp_base;
120 target_phys_addr_t ledma_base, le_base;
121 target_phys_addr_t tcx_base;
122 target_phys_addr_t sbi_base;
123 unsigned long vram_size, nvram_size;
124 // IRQ numbers are not PIL ones, but SBI register bit numbers
125 int esp_irq, le_irq, clock_irq, clock1_irq;
126 int ser_irq, ms_kb_irq, me_irq;
127 uint8_t nvram_machine_id;
129 uint32_t iounit_version;
131 const char * const default_cpu_model;
134 int DMA_get_channel_mode (int nchan)
138 int DMA_read_memory (int nchan, void *buf, int pos, int size)
142 int DMA_write_memory (int nchan, void *buf, int pos, int size)
146 void DMA_hold_DREQ (int nchan) {}
147 void DMA_release_DREQ (int nchan) {}
148 void DMA_schedule(int nchan) {}
149 void DMA_run (void) {}
150 void DMA_init (int high_page_enable) {}
151 void DMA_register_channel (int nchan,
152 DMA_transfer_handler transfer_handler,
157 static int nvram_boot_set(void *opaque, const char *boot_device)
160 uint8_t image[sizeof(ohwcfg_v3_t)];
161 ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
162 m48t59_t *nvram = (m48t59_t *)opaque;
164 for (i = 0; i < sizeof(image); i++)
165 image[i] = m48t59_read(nvram, i) & 0xff;
167 pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
169 header->nboot_devices = strlen(boot_device) & 0xff;
170 header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
172 for (i = 0; i < sizeof(image); i++)
173 m48t59_write(nvram, i, image[i]);
178 extern int nographic;
180 static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
181 const char *boot_devices, ram_addr_t RAM_size,
182 uint32_t kernel_size,
183 int width, int height, int depth,
184 int nvram_machine_id, const char *arch)
188 uint8_t image[0x1ff0];
189 ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
190 struct sparc_arch_cfg *sparc_header;
191 struct OpenBIOS_nvpart_v1 *part_header;
193 memset(image, '\0', sizeof(image));
195 // Try to match PPC NVRAM
196 pstrcpy((char *)header->struct_ident, sizeof(header->struct_ident),
198 header->struct_version = cpu_to_be32(3); /* structure v3 */
200 header->nvram_size = cpu_to_be16(0x2000);
201 header->nvram_arch_ptr = cpu_to_be16(sizeof(ohwcfg_v3_t));
202 header->nvram_arch_size = cpu_to_be16(sizeof(struct sparc_arch_cfg));
203 pstrcpy((char *)header->arch, sizeof(header->arch), arch);
204 header->nb_cpus = smp_cpus & 0xff;
205 header->RAM0_base = 0;
206 header->RAM0_size = cpu_to_be64((uint64_t)RAM_size);
207 pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
209 header->nboot_devices = strlen(boot_devices) & 0xff;
210 header->kernel_image = cpu_to_be64((uint64_t)KERNEL_LOAD_ADDR);
211 header->kernel_size = cpu_to_be64((uint64_t)kernel_size);
213 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, cmdline);
214 header->cmdline = cpu_to_be64((uint64_t)CMDLINE_ADDR);
215 header->cmdline_size = cpu_to_be64((uint64_t)strlen(cmdline));
217 // XXX add initrd_image, initrd_size
218 header->width = cpu_to_be16(width);
219 header->height = cpu_to_be16(height);
220 header->depth = cpu_to_be16(depth);
222 header->graphic_flags = cpu_to_be16(OHW_GF_NOGRAPHICS);
224 header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
226 // Architecture specific header
227 start = sizeof(ohwcfg_v3_t);
228 sparc_header = (struct sparc_arch_cfg *)&image[start];
229 sparc_header->valid = 0;
230 start += sizeof(struct sparc_arch_cfg);
232 // OpenBIOS nvram variables
233 // Variable partition
234 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
235 part_header->signature = OPENBIOS_PART_SYSTEM;
236 pstrcpy(part_header->name, sizeof(part_header->name), "system");
238 end = start + sizeof(struct OpenBIOS_nvpart_v1);
239 for (i = 0; i < nb_prom_envs; i++)
240 end = OpenBIOS_set_var(image, end, prom_envs[i]);
245 end = start + ((end - start + 15) & ~15);
246 OpenBIOS_finish_partition(part_header, end - start);
250 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
251 part_header->signature = OPENBIOS_PART_FREE;
252 pstrcpy(part_header->name, sizeof(part_header->name), "free");
255 OpenBIOS_finish_partition(part_header, end - start);
257 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
260 for (i = 0; i < sizeof(image); i++)
261 m48t59_write(nvram, i, image[i]);
263 qemu_register_boot_set(nvram_boot_set, nvram);
266 static void *slavio_intctl;
271 slavio_pic_info(slavio_intctl);
277 slavio_irq_info(slavio_intctl);
280 void cpu_check_irqs(CPUState *env)
282 if (env->pil_in && (env->interrupt_index == 0 ||
283 (env->interrupt_index & ~15) == TT_EXTINT)) {
286 for (i = 15; i > 0; i--) {
287 if (env->pil_in & (1 << i)) {
288 int old_interrupt = env->interrupt_index;
290 env->interrupt_index = TT_EXTINT | i;
291 if (old_interrupt != env->interrupt_index) {
292 DPRINTF("Set CPU IRQ %d\n", i);
293 cpu_interrupt(env, CPU_INTERRUPT_HARD);
298 } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
299 DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
300 env->interrupt_index = 0;
301 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
305 static void cpu_set_irq(void *opaque, int irq, int level)
307 CPUState *env = opaque;
310 DPRINTF("Raise CPU IRQ %d\n", irq);
312 env->pil_in |= 1 << irq;
315 DPRINTF("Lower CPU IRQ %d\n", irq);
316 env->pil_in &= ~(1 << irq);
321 static void dummy_cpu_set_irq(void *opaque, int irq, int level)
325 static void *slavio_misc;
327 void qemu_system_powerdown(void)
329 slavio_set_power_fail(slavio_misc, 1);
332 static void main_cpu_reset(void *opaque)
334 CPUState *env = opaque;
340 static void secondary_cpu_reset(void *opaque)
342 CPUState *env = opaque;
348 static unsigned long sun4m_load_kernel(const char *kernel_filename,
349 const char *initrd_filename,
354 long initrd_size, kernel_size;
356 linux_boot = (kernel_filename != NULL);
360 kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL,
363 kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
364 RAM_size - KERNEL_LOAD_ADDR);
366 kernel_size = load_image_targphys(kernel_filename,
368 RAM_size - KERNEL_LOAD_ADDR);
369 if (kernel_size < 0) {
370 fprintf(stderr, "qemu: could not load kernel '%s'\n",
377 if (initrd_filename) {
378 initrd_size = load_image_targphys(initrd_filename,
380 RAM_size - INITRD_LOAD_ADDR);
381 if (initrd_size < 0) {
382 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
387 if (initrd_size > 0) {
388 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
389 if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
390 stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
391 stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
400 static void sun4m_hw_init(const struct hwdef *hwdef, ram_addr_t RAM_size,
401 const char *boot_device,
402 DisplayState *ds, const char *kernel_filename,
403 const char *kernel_cmdline,
404 const char *initrd_filename, const char *cpu_model)
407 CPUState *env, *envs[MAX_CPUS];
409 void *iommu, *espdma, *ledma, *main_esp, *nvram;
410 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
411 *espdma_irq, *ledma_irq;
412 qemu_irq *esp_reset, *le_reset;
414 unsigned long prom_offset, kernel_size;
417 BlockDriverState *fd[MAX_FD];
423 cpu_model = hwdef->default_cpu_model;
425 for(i = 0; i < smp_cpus; i++) {
426 env = cpu_init(cpu_model);
428 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
431 cpu_sparc_set_id(env, i);
434 qemu_register_reset(main_cpu_reset, env);
436 qemu_register_reset(secondary_cpu_reset, env);
439 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
440 env->prom_addr = hwdef->slavio_base;
443 for (i = smp_cpus; i < MAX_CPUS; i++)
444 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
448 if ((uint64_t)RAM_size > hwdef->max_mem) {
450 "qemu: Too much memory for this machine: %d, maximum %d\n",
451 (unsigned int)(RAM_size / (1024 * 1024)),
452 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
455 cpu_register_physical_memory(0, RAM_size, 0);
458 prom_offset = RAM_size + hwdef->vram_size;
459 cpu_register_physical_memory(hwdef->slavio_base,
460 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
462 prom_offset | IO_MEM_ROM);
464 if (bios_name == NULL)
465 bios_name = PROM_FILENAME;
466 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
467 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
468 if (ret < 0 || ret > PROM_SIZE_MAX)
469 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
470 if (ret < 0 || ret > PROM_SIZE_MAX) {
471 fprintf(stderr, "qemu: could not load prom '%s'\n",
475 prom_offset += (ret + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
478 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
479 hwdef->intctl_base + 0x10000ULL,
480 &hwdef->intbit_to_level[0],
481 &slavio_irq, &slavio_cpu_irq,
485 if (hwdef->idreg_base != (target_phys_addr_t)-1) {
486 static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
488 cpu_register_physical_memory(hwdef->idreg_base, sizeof(idreg_data),
489 prom_offset | IO_MEM_ROM);
490 cpu_physical_memory_write_rom(hwdef->idreg_base, idreg_data,
494 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
495 slavio_irq[hwdef->me_irq]);
497 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
498 iommu, &espdma_irq, &esp_reset);
500 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
501 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
504 if (graphic_depth != 8 && graphic_depth != 24) {
505 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
508 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
509 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
511 if (nd_table[0].model == NULL
512 || strcmp(nd_table[0].model, "lance") == 0) {
513 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
514 } else if (strcmp(nd_table[0].model, "?") == 0) {
515 fprintf(stderr, "qemu: Supported NICs: lance\n");
518 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
522 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
523 hwdef->nvram_size, 8);
525 slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq],
526 slavio_cpu_irq, smp_cpus);
528 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
530 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
531 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
532 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
533 serial_hds[1], serial_hds[0]);
535 slavio_misc = slavio_misc_init(hwdef->slavio_base, hwdef->apc_base,
536 hwdef->aux1_base, hwdef->aux2_base,
537 slavio_irq[hwdef->me_irq], envs[0],
540 if (hwdef->fd_base != (target_phys_addr_t)-1) {
541 /* there is zero or one floppy drive */
542 memset(fd, 0, sizeof(fd));
543 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
544 if (drive_index != -1)
545 fd[0] = drives_table[drive_index].bdrv;
547 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
551 if (drive_get_max_bus(IF_SCSI) > 0) {
552 fprintf(stderr, "qemu: too many SCSI bus\n");
556 main_esp = esp_init(hwdef->esp_base, 2,
557 espdma_memory_read, espdma_memory_write,
558 espdma, *espdma_irq, esp_reset);
560 for (i = 0; i < ESP_MAX_DEVS; i++) {
561 drive_index = drive_get_index(IF_SCSI, 0, i);
562 if (drive_index == -1)
564 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
567 if (hwdef->cs_base != (target_phys_addr_t)-1)
568 cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl);
570 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
573 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
574 boot_device, RAM_size, kernel_size, graphic_width,
575 graphic_height, graphic_depth, hwdef->nvram_machine_id,
578 if (hwdef->ecc_base != (target_phys_addr_t)-1)
579 ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
582 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
583 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
584 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
585 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
586 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
589 static void sun4c_hw_init(const struct hwdef *hwdef, ram_addr_t RAM_size,
590 const char *boot_device,
591 DisplayState *ds, const char *kernel_filename,
592 const char *kernel_cmdline,
593 const char *initrd_filename, const char *cpu_model)
597 void *iommu, *espdma, *ledma, *main_esp, *nvram;
598 qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
599 qemu_irq *esp_reset, *le_reset;
601 unsigned long prom_offset, kernel_size;
604 BlockDriverState *fd[MAX_FD];
610 cpu_model = hwdef->default_cpu_model;
612 env = cpu_init(cpu_model);
614 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
618 cpu_sparc_set_id(env, 0);
620 qemu_register_reset(main_cpu_reset, env);
621 cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
622 env->prom_addr = hwdef->slavio_base;
625 if ((uint64_t)RAM_size > hwdef->max_mem) {
627 "qemu: Too much memory for this machine: %d, maximum %d\n",
628 (unsigned int)(RAM_size / (1024 * 1024)),
629 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
632 cpu_register_physical_memory(0, RAM_size, 0);
635 prom_offset = RAM_size + hwdef->vram_size;
636 cpu_register_physical_memory(hwdef->slavio_base,
637 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
639 prom_offset | IO_MEM_ROM);
641 if (bios_name == NULL)
642 bios_name = PROM_FILENAME;
643 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
644 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
645 if (ret < 0 || ret > PROM_SIZE_MAX)
646 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
647 if (ret < 0 || ret > PROM_SIZE_MAX) {
648 fprintf(stderr, "qemu: could not load prom '%s'\n",
652 prom_offset += (ret + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
655 slavio_intctl = sun4c_intctl_init(hwdef->sun4c_intctl_base,
656 &slavio_irq, cpu_irqs);
658 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
659 slavio_irq[hwdef->me_irq]);
661 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
662 iommu, &espdma_irq, &esp_reset);
664 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
665 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
668 if (graphic_depth != 8 && graphic_depth != 24) {
669 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
672 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
673 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
675 if (nd_table[0].model == NULL
676 || strcmp(nd_table[0].model, "lance") == 0) {
677 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
678 } else if (strcmp(nd_table[0].model, "?") == 0) {
679 fprintf(stderr, "qemu: Supported NICs: lance\n");
682 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
686 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
687 hwdef->nvram_size, 2);
689 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
691 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
692 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
693 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
694 serial_hds[1], serial_hds[0]);
696 slavio_misc = slavio_misc_init(-1, hwdef->apc_base,
697 hwdef->aux1_base, hwdef->aux2_base,
698 slavio_irq[hwdef->me_irq], env, &fdc_tc);
700 if (hwdef->fd_base != (target_phys_addr_t)-1) {
701 /* there is zero or one floppy drive */
702 fd[1] = fd[0] = NULL;
703 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
704 if (drive_index != -1)
705 fd[0] = drives_table[drive_index].bdrv;
707 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
711 if (drive_get_max_bus(IF_SCSI) > 0) {
712 fprintf(stderr, "qemu: too many SCSI bus\n");
716 main_esp = esp_init(hwdef->esp_base, 2,
717 espdma_memory_read, espdma_memory_write,
718 espdma, *espdma_irq, esp_reset);
720 for (i = 0; i < ESP_MAX_DEVS; i++) {
721 drive_index = drive_get_index(IF_SCSI, 0, i);
722 if (drive_index == -1)
724 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
727 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
730 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
731 boot_device, RAM_size, kernel_size, graphic_width,
732 graphic_height, graphic_depth, hwdef->nvram_machine_id,
735 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
736 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
737 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
738 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
756 static const struct hwdef hwdefs[] = {
759 .iommu_base = 0x10000000,
760 .tcx_base = 0x50000000,
761 .cs_base = 0x6c000000,
762 .slavio_base = 0x70000000,
763 .ms_kb_base = 0x71000000,
764 .serial_base = 0x71100000,
765 .nvram_base = 0x71200000,
766 .fd_base = 0x71400000,
767 .counter_base = 0x71d00000,
768 .intctl_base = 0x71e00000,
769 .idreg_base = 0x78000000,
770 .dma_base = 0x78400000,
771 .esp_base = 0x78800000,
772 .le_base = 0x78c00000,
773 .apc_base = 0x6a000000,
774 .aux1_base = 0x71900000,
775 .aux2_base = 0x71910000,
777 .sun4c_intctl_base = -1,
778 .sun4c_counter_base = -1,
779 .vram_size = 0x00100000,
780 .nvram_size = 0x2000,
790 .nvram_machine_id = 0x80,
791 .machine_id = ss5_id,
792 .iommu_version = 0x05000000,
794 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
795 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
797 .max_mem = 0x10000000,
798 .default_cpu_model = "Fujitsu MB86904",
802 .iommu_base = 0xfe0000000ULL,
803 .tcx_base = 0xe20000000ULL,
805 .slavio_base = 0xff0000000ULL,
806 .ms_kb_base = 0xff1000000ULL,
807 .serial_base = 0xff1100000ULL,
808 .nvram_base = 0xff1200000ULL,
809 .fd_base = 0xff1700000ULL,
810 .counter_base = 0xff1300000ULL,
811 .intctl_base = 0xff1400000ULL,
812 .idreg_base = 0xef0000000ULL,
813 .dma_base = 0xef0400000ULL,
814 .esp_base = 0xef0800000ULL,
815 .le_base = 0xef0c00000ULL,
816 .apc_base = 0xefa000000ULL, // XXX should not exist
817 .aux1_base = 0xff1800000ULL,
818 .aux2_base = 0xff1a01000ULL,
819 .ecc_base = 0xf00000000ULL,
820 .ecc_version = 0x10000000, // version 0, implementation 1
821 .sun4c_intctl_base = -1,
822 .sun4c_counter_base = -1,
823 .vram_size = 0x00100000,
824 .nvram_size = 0x2000,
835 .nvram_machine_id = 0x72,
836 .machine_id = ss10_id,
837 .iommu_version = 0x03000000,
839 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
840 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
842 .max_mem = 0xf00000000ULL,
843 .default_cpu_model = "TI SuperSparc II",
847 .iommu_base = 0xfe0000000ULL,
848 .tcx_base = 0xe20000000ULL,
850 .slavio_base = 0xff0000000ULL,
851 .ms_kb_base = 0xff1000000ULL,
852 .serial_base = 0xff1100000ULL,
853 .nvram_base = 0xff1200000ULL,
855 .counter_base = 0xff1300000ULL,
856 .intctl_base = 0xff1400000ULL,
858 .dma_base = 0xef0081000ULL,
859 .esp_base = 0xef0080000ULL,
860 .le_base = 0xef0060000ULL,
861 .apc_base = 0xefa000000ULL, // XXX should not exist
862 .aux1_base = 0xff1800000ULL,
863 .aux2_base = 0xff1a01000ULL, // XXX should not exist
864 .ecc_base = 0xf00000000ULL,
865 .ecc_version = 0x00000000, // version 0, implementation 0
866 .sun4c_intctl_base = -1,
867 .sun4c_counter_base = -1,
868 .vram_size = 0x00100000,
869 .nvram_size = 0x2000,
880 .nvram_machine_id = 0x71,
881 .machine_id = ss600mp_id,
882 .iommu_version = 0x01000000,
884 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
885 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
887 .max_mem = 0xf00000000ULL,
888 .default_cpu_model = "TI SuperSparc II",
892 .iommu_base = 0xfe0000000ULL,
893 .tcx_base = 0xe20000000ULL,
895 .slavio_base = 0xff0000000ULL,
896 .ms_kb_base = 0xff1000000ULL,
897 .serial_base = 0xff1100000ULL,
898 .nvram_base = 0xff1200000ULL,
899 .fd_base = 0xff1700000ULL,
900 .counter_base = 0xff1300000ULL,
901 .intctl_base = 0xff1400000ULL,
902 .idreg_base = 0xef0000000ULL,
903 .dma_base = 0xef0400000ULL,
904 .esp_base = 0xef0800000ULL,
905 .le_base = 0xef0c00000ULL,
906 .apc_base = 0xefa000000ULL, // XXX should not exist
907 .aux1_base = 0xff1800000ULL,
908 .aux2_base = 0xff1a01000ULL,
909 .ecc_base = 0xf00000000ULL,
910 .ecc_version = 0x20000000, // version 0, implementation 2
911 .sun4c_intctl_base = -1,
912 .sun4c_counter_base = -1,
913 .vram_size = 0x00100000,
914 .nvram_size = 0x2000,
925 .nvram_machine_id = 0x72,
926 .machine_id = ss20_id,
927 .iommu_version = 0x13000000,
929 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
930 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
932 .max_mem = 0xf00000000ULL,
933 .default_cpu_model = "TI SuperSparc II",
937 .iommu_base = 0xf8000000,
938 .tcx_base = 0xfe000000,
940 .slavio_base = 0xf6000000,
941 .ms_kb_base = 0xf0000000,
942 .serial_base = 0xf1000000,
943 .nvram_base = 0xf2000000,
944 .fd_base = 0xf7200000,
947 .dma_base = 0xf8400000,
948 .esp_base = 0xf8800000,
949 .le_base = 0xf8c00000,
951 .aux1_base = 0xf7400003,
953 .sun4c_intctl_base = 0xf5000000,
954 .sun4c_counter_base = 0xf3000000,
955 .vram_size = 0x00100000,
966 .nvram_machine_id = 0x55,
967 .machine_id = ss2_id,
968 .max_mem = 0x10000000,
969 .default_cpu_model = "Cypress CY7C601",
973 .iommu_base = 0x10000000,
974 .tcx_base = 0x50000000,
976 .slavio_base = 0x70000000,
977 .ms_kb_base = 0x71000000,
978 .serial_base = 0x71100000,
979 .nvram_base = 0x71200000,
980 .fd_base = 0x71400000,
981 .counter_base = 0x71d00000,
982 .intctl_base = 0x71e00000,
983 .idreg_base = 0x78000000,
984 .dma_base = 0x78400000,
985 .esp_base = 0x78800000,
986 .le_base = 0x78c00000,
987 .apc_base = 0x71300000, // pmc
988 .aux1_base = 0x71900000,
989 .aux2_base = 0x71910000,
991 .sun4c_intctl_base = -1,
992 .sun4c_counter_base = -1,
993 .vram_size = 0x00100000,
994 .nvram_size = 0x2000,
1004 .nvram_machine_id = 0x80,
1005 .machine_id = vger_id,
1006 .iommu_version = 0x05000000,
1007 .intbit_to_level = {
1008 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
1009 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
1011 .max_mem = 0x10000000,
1012 .default_cpu_model = "Fujitsu MB86904",
1016 .iommu_base = 0x10000000,
1017 .tcx_base = 0x50000000,
1019 .slavio_base = 0x70000000,
1020 .ms_kb_base = 0x71000000,
1021 .serial_base = 0x71100000,
1022 .nvram_base = 0x71200000,
1023 .fd_base = 0x71400000,
1024 .counter_base = 0x71d00000,
1025 .intctl_base = 0x71e00000,
1026 .idreg_base = 0x78000000,
1027 .dma_base = 0x78400000,
1028 .esp_base = 0x78800000,
1029 .le_base = 0x78c00000,
1031 .aux1_base = 0x71900000,
1032 .aux2_base = 0x71910000,
1034 .sun4c_intctl_base = -1,
1035 .sun4c_counter_base = -1,
1036 .vram_size = 0x00100000,
1037 .nvram_size = 0x2000,
1047 .nvram_machine_id = 0x80,
1048 .machine_id = lx_id,
1049 .iommu_version = 0x04000000,
1050 .intbit_to_level = {
1051 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
1052 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
1054 .max_mem = 0x10000000,
1055 .default_cpu_model = "TI MicroSparc I",
1059 .iommu_base = 0x10000000,
1060 .tcx_base = 0x50000000,
1061 .cs_base = 0x6c000000,
1062 .slavio_base = 0x70000000,
1063 .ms_kb_base = 0x71000000,
1064 .serial_base = 0x71100000,
1065 .nvram_base = 0x71200000,
1066 .fd_base = 0x71400000,
1067 .counter_base = 0x71d00000,
1068 .intctl_base = 0x71e00000,
1069 .idreg_base = 0x78000000,
1070 .dma_base = 0x78400000,
1071 .esp_base = 0x78800000,
1072 .le_base = 0x78c00000,
1073 .apc_base = 0x6a000000,
1074 .aux1_base = 0x71900000,
1075 .aux2_base = 0x71910000,
1077 .sun4c_intctl_base = -1,
1078 .sun4c_counter_base = -1,
1079 .vram_size = 0x00100000,
1080 .nvram_size = 0x2000,
1090 .nvram_machine_id = 0x80,
1091 .machine_id = ss4_id,
1092 .iommu_version = 0x05000000,
1093 .intbit_to_level = {
1094 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
1095 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
1097 .max_mem = 0x10000000,
1098 .default_cpu_model = "Fujitsu MB86904",
1102 .iommu_base = 0x10000000,
1103 .tcx_base = 0x50000000,
1105 .slavio_base = 0x70000000,
1106 .ms_kb_base = 0x71000000,
1107 .serial_base = 0x71100000,
1108 .nvram_base = 0x71200000,
1109 .fd_base = 0x71400000,
1110 .counter_base = 0x71d00000,
1111 .intctl_base = 0x71e00000,
1112 .idreg_base = 0x78000000,
1113 .dma_base = 0x78400000,
1114 .esp_base = 0x78800000,
1115 .le_base = 0x78c00000,
1116 .apc_base = 0x6a000000,
1117 .aux1_base = 0x71900000,
1118 .aux2_base = 0x71910000,
1120 .sun4c_intctl_base = -1,
1121 .sun4c_counter_base = -1,
1122 .vram_size = 0x00100000,
1123 .nvram_size = 0x2000,
1133 .nvram_machine_id = 0x80,
1134 .machine_id = scls_id,
1135 .iommu_version = 0x05000000,
1136 .intbit_to_level = {
1137 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
1138 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
1140 .max_mem = 0x10000000,
1141 .default_cpu_model = "TI MicroSparc I",
1145 .iommu_base = 0x10000000,
1146 .tcx_base = 0x50000000, // XXX
1148 .slavio_base = 0x70000000,
1149 .ms_kb_base = 0x71000000,
1150 .serial_base = 0x71100000,
1151 .nvram_base = 0x71200000,
1152 .fd_base = 0x71400000,
1153 .counter_base = 0x71d00000,
1154 .intctl_base = 0x71e00000,
1155 .idreg_base = 0x78000000,
1156 .dma_base = 0x78400000,
1157 .esp_base = 0x78800000,
1158 .le_base = 0x78c00000,
1159 .apc_base = 0x6a000000,
1160 .aux1_base = 0x71900000,
1161 .aux2_base = 0x71910000,
1163 .sun4c_intctl_base = -1,
1164 .sun4c_counter_base = -1,
1165 .vram_size = 0x00100000,
1166 .nvram_size = 0x2000,
1176 .nvram_machine_id = 0x80,
1177 .machine_id = sbook_id,
1178 .iommu_version = 0x05000000,
1179 .intbit_to_level = {
1180 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
1181 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
1183 .max_mem = 0x10000000,
1184 .default_cpu_model = "TI MicroSparc I",
1188 /* SPARCstation 5 hardware initialisation */
1189 static void ss5_init(ram_addr_t RAM_size, int vga_ram_size,
1190 const char *boot_device, DisplayState *ds,
1191 const char *kernel_filename, const char *kernel_cmdline,
1192 const char *initrd_filename, const char *cpu_model)
1194 sun4m_hw_init(&hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1195 kernel_cmdline, initrd_filename, cpu_model);
1198 /* SPARCstation 10 hardware initialisation */
1199 static void ss10_init(ram_addr_t RAM_size, int vga_ram_size,
1200 const char *boot_device, DisplayState *ds,
1201 const char *kernel_filename, const char *kernel_cmdline,
1202 const char *initrd_filename, const char *cpu_model)
1204 sun4m_hw_init(&hwdefs[1], RAM_size, boot_device, ds, kernel_filename,
1205 kernel_cmdline, initrd_filename, cpu_model);
1208 /* SPARCserver 600MP hardware initialisation */
1209 static void ss600mp_init(ram_addr_t RAM_size, int vga_ram_size,
1210 const char *boot_device, DisplayState *ds,
1211 const char *kernel_filename,
1212 const char *kernel_cmdline,
1213 const char *initrd_filename, const char *cpu_model)
1215 sun4m_hw_init(&hwdefs[2], RAM_size, boot_device, ds, kernel_filename,
1216 kernel_cmdline, initrd_filename, cpu_model);
1219 /* SPARCstation 20 hardware initialisation */
1220 static void ss20_init(ram_addr_t RAM_size, int vga_ram_size,
1221 const char *boot_device, DisplayState *ds,
1222 const char *kernel_filename, const char *kernel_cmdline,
1223 const char *initrd_filename, const char *cpu_model)
1225 sun4m_hw_init(&hwdefs[3], RAM_size, boot_device, ds, kernel_filename,
1226 kernel_cmdline, initrd_filename, cpu_model);
1229 /* SPARCstation 2 hardware initialisation */
1230 static void ss2_init(ram_addr_t RAM_size, int vga_ram_size,
1231 const char *boot_device, DisplayState *ds,
1232 const char *kernel_filename, const char *kernel_cmdline,
1233 const char *initrd_filename, const char *cpu_model)
1235 sun4c_hw_init(&hwdefs[4], RAM_size, boot_device, ds, kernel_filename,
1236 kernel_cmdline, initrd_filename, cpu_model);
1239 /* SPARCstation Voyager hardware initialisation */
1240 static void vger_init(ram_addr_t RAM_size, int vga_ram_size,
1241 const char *boot_device, DisplayState *ds,
1242 const char *kernel_filename, const char *kernel_cmdline,
1243 const char *initrd_filename, const char *cpu_model)
1245 sun4m_hw_init(&hwdefs[5], RAM_size, boot_device, ds, kernel_filename,
1246 kernel_cmdline, initrd_filename, cpu_model);
1249 /* SPARCstation LX hardware initialisation */
1250 static void ss_lx_init(ram_addr_t RAM_size, int vga_ram_size,
1251 const char *boot_device, DisplayState *ds,
1252 const char *kernel_filename, const char *kernel_cmdline,
1253 const char *initrd_filename, const char *cpu_model)
1255 sun4m_hw_init(&hwdefs[6], RAM_size, boot_device, ds, kernel_filename,
1256 kernel_cmdline, initrd_filename, cpu_model);
1259 /* SPARCstation 4 hardware initialisation */
1260 static void ss4_init(ram_addr_t RAM_size, int vga_ram_size,
1261 const char *boot_device, DisplayState *ds,
1262 const char *kernel_filename, const char *kernel_cmdline,
1263 const char *initrd_filename, const char *cpu_model)
1265 sun4m_hw_init(&hwdefs[7], RAM_size, boot_device, ds, kernel_filename,
1266 kernel_cmdline, initrd_filename, cpu_model);
1269 /* SPARCClassic hardware initialisation */
1270 static void scls_init(ram_addr_t RAM_size, int vga_ram_size,
1271 const char *boot_device, DisplayState *ds,
1272 const char *kernel_filename, const char *kernel_cmdline,
1273 const char *initrd_filename, const char *cpu_model)
1275 sun4m_hw_init(&hwdefs[8], RAM_size, boot_device, ds, kernel_filename,
1276 kernel_cmdline, initrd_filename, cpu_model);
1279 /* SPARCbook hardware initialisation */
1280 static void sbook_init(ram_addr_t RAM_size, int vga_ram_size,
1281 const char *boot_device, DisplayState *ds,
1282 const char *kernel_filename, const char *kernel_cmdline,
1283 const char *initrd_filename, const char *cpu_model)
1285 sun4m_hw_init(&hwdefs[9], RAM_size, boot_device, ds, kernel_filename,
1286 kernel_cmdline, initrd_filename, cpu_model);
1289 QEMUMachine ss5_machine = {
1291 .desc = "Sun4m platform, SPARCstation 5",
1293 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1298 QEMUMachine ss10_machine = {
1300 .desc = "Sun4m platform, SPARCstation 10",
1302 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1307 QEMUMachine ss600mp_machine = {
1309 .desc = "Sun4m platform, SPARCserver 600MP",
1310 .init = ss600mp_init,
1311 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1316 QEMUMachine ss20_machine = {
1318 .desc = "Sun4m platform, SPARCstation 20",
1320 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1325 QEMUMachine ss2_machine = {
1327 .desc = "Sun4c platform, SPARCstation 2",
1329 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1334 QEMUMachine voyager_machine = {
1336 .desc = "Sun4m platform, SPARCstation Voyager",
1338 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1343 QEMUMachine ss_lx_machine = {
1345 .desc = "Sun4m platform, SPARCstation LX",
1347 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1352 QEMUMachine ss4_machine = {
1354 .desc = "Sun4m platform, SPARCstation 4",
1356 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1361 QEMUMachine scls_machine = {
1362 .name = "SPARCClassic",
1363 .desc = "Sun4m platform, SPARCClassic",
1365 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1370 QEMUMachine sbook_machine = {
1371 .name = "SPARCbook",
1372 .desc = "Sun4m platform, SPARCbook",
1374 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1379 static const struct sun4d_hwdef sun4d_hwdefs[] = {
1389 .tcx_base = 0x820000000ULL,
1390 .slavio_base = 0xf00000000ULL,
1391 .ms_kb_base = 0xf00240000ULL,
1392 .serial_base = 0xf00200000ULL,
1393 .nvram_base = 0xf00280000ULL,
1394 .counter_base = 0xf00300000ULL,
1395 .espdma_base = 0x800081000ULL,
1396 .esp_base = 0x800080000ULL,
1397 .ledma_base = 0x800040000ULL,
1398 .le_base = 0x800060000ULL,
1399 .sbi_base = 0xf02800000ULL,
1400 .vram_size = 0x00100000,
1401 .nvram_size = 0x2000,
1408 .nvram_machine_id = 0x80,
1409 .machine_id = ss1000_id,
1410 .iounit_version = 0x03000000,
1411 .max_mem = 0xf00000000ULL,
1412 .default_cpu_model = "TI SuperSparc II",
1423 .tcx_base = 0x820000000ULL,
1424 .slavio_base = 0xf00000000ULL,
1425 .ms_kb_base = 0xf00240000ULL,
1426 .serial_base = 0xf00200000ULL,
1427 .nvram_base = 0xf00280000ULL,
1428 .counter_base = 0xf00300000ULL,
1429 .espdma_base = 0x800081000ULL,
1430 .esp_base = 0x800080000ULL,
1431 .ledma_base = 0x800040000ULL,
1432 .le_base = 0x800060000ULL,
1433 .sbi_base = 0xf02800000ULL,
1434 .vram_size = 0x00100000,
1435 .nvram_size = 0x2000,
1442 .nvram_machine_id = 0x80,
1443 .machine_id = ss2000_id,
1444 .iounit_version = 0x03000000,
1445 .max_mem = 0xf00000000ULL,
1446 .default_cpu_model = "TI SuperSparc II",
1450 static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1451 const char *boot_device,
1452 DisplayState *ds, const char *kernel_filename,
1453 const char *kernel_cmdline,
1454 const char *initrd_filename, const char *cpu_model)
1456 CPUState *env, *envs[MAX_CPUS];
1458 void *iounits[MAX_IOUNITS], *espdma, *ledma, *main_esp, *nvram, *sbi;
1459 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1460 *espdma_irq, *ledma_irq;
1461 qemu_irq *esp_reset, *le_reset;
1462 unsigned long prom_offset, kernel_size;
1470 cpu_model = hwdef->default_cpu_model;
1472 for (i = 0; i < smp_cpus; i++) {
1473 env = cpu_init(cpu_model);
1475 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1478 cpu_sparc_set_id(env, i);
1481 qemu_register_reset(main_cpu_reset, env);
1483 qemu_register_reset(secondary_cpu_reset, env);
1486 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
1487 env->prom_addr = hwdef->slavio_base;
1490 for (i = smp_cpus; i < MAX_CPUS; i++)
1491 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1494 if ((uint64_t)RAM_size > hwdef->max_mem) {
1496 "qemu: Too much memory for this machine: %d, maximum %d\n",
1497 (unsigned int)(RAM_size / (1024 * 1024)),
1498 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1501 cpu_register_physical_memory(0, RAM_size, 0);
1503 /* load boot prom */
1504 prom_offset = RAM_size + hwdef->vram_size;
1505 cpu_register_physical_memory(hwdef->slavio_base,
1506 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1508 prom_offset | IO_MEM_ROM);
1510 if (bios_name == NULL)
1511 bios_name = PROM_FILENAME;
1512 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1513 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1514 if (ret < 0 || ret > PROM_SIZE_MAX)
1515 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
1516 if (ret < 0 || ret > PROM_SIZE_MAX) {
1517 fprintf(stderr, "qemu: could not load prom '%s'\n",
1522 /* set up devices */
1523 sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
1525 for (i = 0; i < MAX_IOUNITS; i++)
1526 if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
1527 iounits[i] = iommu_init(hwdef->iounit_bases[i],
1528 hwdef->iounit_version,
1529 sbi_irq[hwdef->me_irq]);
1531 espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq],
1532 iounits[0], &espdma_irq, &esp_reset);
1534 ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq],
1535 iounits[0], &ledma_irq, &le_reset);
1537 if (graphic_depth != 8 && graphic_depth != 24) {
1538 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1541 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
1542 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1544 if (nd_table[0].model == NULL
1545 || strcmp(nd_table[0].model, "lance") == 0) {
1546 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1547 } else if (strcmp(nd_table[0].model, "?") == 0) {
1548 fprintf(stderr, "qemu: Supported NICs: lance\n");
1551 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
1555 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1556 hwdef->nvram_size, 8);
1558 slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq],
1559 sbi_cpu_irq, smp_cpus);
1561 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
1563 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1564 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1565 slavio_serial_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq],
1566 serial_hds[1], serial_hds[0]);
1568 if (drive_get_max_bus(IF_SCSI) > 0) {
1569 fprintf(stderr, "qemu: too many SCSI bus\n");
1573 main_esp = esp_init(hwdef->esp_base, 2,
1574 espdma_memory_read, espdma_memory_write,
1575 espdma, *espdma_irq, esp_reset);
1577 for (i = 0; i < ESP_MAX_DEVS; i++) {
1578 drive_index = drive_get_index(IF_SCSI, 0, i);
1579 if (drive_index == -1)
1581 esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);
1584 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1587 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1588 boot_device, RAM_size, kernel_size, graphic_width,
1589 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1592 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1593 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1594 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1595 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1598 /* SPARCserver 1000 hardware initialisation */
1599 static void ss1000_init(ram_addr_t RAM_size, int vga_ram_size,
1600 const char *boot_device, DisplayState *ds,
1601 const char *kernel_filename, const char *kernel_cmdline,
1602 const char *initrd_filename, const char *cpu_model)
1604 sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1605 kernel_cmdline, initrd_filename, cpu_model);
1608 /* SPARCcenter 2000 hardware initialisation */
1609 static void ss2000_init(ram_addr_t RAM_size, int vga_ram_size,
1610 const char *boot_device, DisplayState *ds,
1611 const char *kernel_filename, const char *kernel_cmdline,
1612 const char *initrd_filename, const char *cpu_model)
1614 sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, ds, kernel_filename,
1615 kernel_cmdline, initrd_filename, cpu_model);
1618 QEMUMachine ss1000_machine = {
1620 .desc = "Sun4d platform, SPARCserver 1000",
1621 .init = ss1000_init,
1622 .ram_require = PROM_SIZE_MAX + TCX_SIZE,
1627 QEMUMachine ss2000_machine = {
1629 .desc = "Sun4d platform, SPARCcenter 2000",
1630 .init = ss2000_init,
1631 .ram_require = PROM_SIZE_MAX + TCX_SIZE,