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"
39 * Sun4m architecture was used in the following machines:
41 * SPARCserver 6xxMP/xx
42 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15), SPARCclassic X (4/10)
43 * SPARCstation LX/ZX (4/30)
44 * SPARCstation Voyager
45 * SPARCstation 10/xx, SPARCserver 10/xx
46 * SPARCstation 5, SPARCserver 5
47 * SPARCstation 20/xx, SPARCserver 20
50 * Sun4d architecture was used in the following machines:
55 * Sun4c architecture was used in the following machines:
56 * SPARCstation 1/1+, SPARCserver 1/1+
62 * See for example: http://www.sunhelp.org/faq/sunref1.html
66 #define DPRINTF(fmt, args...) \
67 do { printf("CPUIRQ: " fmt , ##args); } while (0)
69 #define DPRINTF(fmt, args...)
72 #define KERNEL_LOAD_ADDR 0x00004000
73 #define CMDLINE_ADDR 0x007ff000
74 #define INITRD_LOAD_ADDR 0x00800000
75 #define PROM_SIZE_MAX (512 * 1024)
76 #define PROM_VADDR 0xffd00000
77 #define PROM_FILENAME "openbios-sparc32"
83 target_phys_addr_t iommu_base
, slavio_base
;
84 target_phys_addr_t intctl_base
, counter_base
, nvram_base
, ms_kb_base
;
85 target_phys_addr_t serial_base
, fd_base
;
86 target_phys_addr_t idreg_base
, dma_base
, esp_base
, le_base
;
87 target_phys_addr_t tcx_base
, cs_base
, apc_base
, aux1_base
, aux2_base
;
88 target_phys_addr_t ecc_base
;
90 target_phys_addr_t sun4c_intctl_base
, sun4c_counter_base
;
91 long vram_size
, nvram_size
;
92 // IRQ numbers are not PIL ones, but master interrupt controller
93 // register bit numbers
94 int intctl_g_intr
, esp_irq
, le_irq
, clock_irq
, clock1_irq
;
95 int ser_irq
, ms_kb_irq
, fd_irq
, me_irq
, cs_irq
, ecc_irq
;
96 int machine_id
; // For NVRAM
97 uint32_t iommu_version
;
98 uint32_t intbit_to_level
[32];
100 const char * const default_cpu_model
;
103 #define MAX_IOUNITS 5
106 target_phys_addr_t iounit_bases
[MAX_IOUNITS
], slavio_base
;
107 target_phys_addr_t counter_base
, nvram_base
, ms_kb_base
;
108 target_phys_addr_t serial_base
;
109 target_phys_addr_t espdma_base
, esp_base
;
110 target_phys_addr_t ledma_base
, le_base
;
111 target_phys_addr_t tcx_base
;
112 target_phys_addr_t sbi_base
;
113 unsigned long vram_size
, nvram_size
;
114 // IRQ numbers are not PIL ones, but SBI register bit numbers
115 int esp_irq
, le_irq
, clock_irq
, clock1_irq
;
116 int ser_irq
, ms_kb_irq
, me_irq
;
117 int machine_id
; // For NVRAM
118 uint32_t iounit_version
;
120 const char * const default_cpu_model
;
125 uint64_t cpu_get_tsc()
127 return qemu_get_clock(vm_clock
);
130 int DMA_get_channel_mode (int nchan
)
134 int DMA_read_memory (int nchan
, void *buf
, int pos
, int size
)
138 int DMA_write_memory (int nchan
, void *buf
, int pos
, int size
)
142 void DMA_hold_DREQ (int nchan
) {}
143 void DMA_release_DREQ (int nchan
) {}
144 void DMA_schedule(int nchan
) {}
145 void DMA_run (void) {}
146 void DMA_init (int high_page_enable
) {}
147 void DMA_register_channel (int nchan
,
148 DMA_transfer_handler transfer_handler
,
153 extern int nographic
;
155 static void nvram_init(m48t59_t
*nvram
, uint8_t *macaddr
, const char *cmdline
,
156 const char *boot_devices
, uint32_t RAM_size
,
157 uint32_t kernel_size
,
158 int width
, int height
, int depth
,
159 int machine_id
, const char *arch
)
163 uint8_t image
[0x1ff0];
164 ohwcfg_v3_t
*header
= (ohwcfg_v3_t
*)&image
;
165 struct sparc_arch_cfg
*sparc_header
;
166 struct OpenBIOS_nvpart_v1
*part_header
;
168 memset(image
, '\0', sizeof(image
));
170 // Try to match PPC NVRAM
171 strcpy(header
->struct_ident
, "QEMU_BIOS");
172 header
->struct_version
= cpu_to_be32(3); /* structure v3 */
174 header
->nvram_size
= cpu_to_be16(0x2000);
175 header
->nvram_arch_ptr
= cpu_to_be16(sizeof(ohwcfg_v3_t
));
176 header
->nvram_arch_size
= cpu_to_be16(sizeof(struct sparc_arch_cfg
));
177 strcpy(header
->arch
, arch
);
178 header
->nb_cpus
= smp_cpus
& 0xff;
179 header
->RAM0_base
= 0;
180 header
->RAM0_size
= cpu_to_be64((uint64_t)RAM_size
);
181 strcpy(header
->boot_devices
, boot_devices
);
182 header
->nboot_devices
= strlen(boot_devices
) & 0xff;
183 header
->kernel_image
= cpu_to_be64((uint64_t)KERNEL_LOAD_ADDR
);
184 header
->kernel_size
= cpu_to_be64((uint64_t)kernel_size
);
186 strcpy(phys_ram_base
+ CMDLINE_ADDR
, cmdline
);
187 header
->cmdline
= cpu_to_be64((uint64_t)CMDLINE_ADDR
);
188 header
->cmdline_size
= cpu_to_be64((uint64_t)strlen(cmdline
));
190 // XXX add initrd_image, initrd_size
191 header
->width
= cpu_to_be16(width
);
192 header
->height
= cpu_to_be16(height
);
193 header
->depth
= cpu_to_be16(depth
);
195 header
->graphic_flags
= cpu_to_be16(OHW_GF_NOGRAPHICS
);
197 header
->crc
= cpu_to_be16(OHW_compute_crc(header
, 0x00, 0xF8));
199 // Architecture specific header
200 start
= sizeof(ohwcfg_v3_t
);
201 sparc_header
= (struct sparc_arch_cfg
*)&image
[start
];
202 sparc_header
->valid
= 0;
203 start
+= sizeof(struct sparc_arch_cfg
);
205 // OpenBIOS nvram variables
206 // Variable partition
207 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
208 part_header
->signature
= OPENBIOS_PART_SYSTEM
;
209 strcpy(part_header
->name
, "system");
211 end
= start
+ sizeof(struct OpenBIOS_nvpart_v1
);
212 for (i
= 0; i
< nb_prom_envs
; i
++)
213 end
= OpenBIOS_set_var(image
, end
, prom_envs
[i
]);
218 end
= start
+ ((end
- start
+ 15) & ~15);
219 OpenBIOS_finish_partition(part_header
, end
- start
);
223 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
224 part_header
->signature
= OPENBIOS_PART_FREE
;
225 strcpy(part_header
->name
, "free");
228 OpenBIOS_finish_partition(part_header
, end
- start
);
230 Sun_init_header((struct Sun_nvram
*)&image
[0x1fd8], macaddr
, machine_id
);
232 for (i
= 0; i
< sizeof(image
); i
++)
233 m48t59_write(nvram
, i
, image
[i
]);
236 static void *slavio_intctl
;
241 slavio_pic_info(slavio_intctl
);
247 slavio_irq_info(slavio_intctl
);
250 void cpu_check_irqs(CPUState
*env
)
252 if (env
->pil_in
&& (env
->interrupt_index
== 0 ||
253 (env
->interrupt_index
& ~15) == TT_EXTINT
)) {
256 for (i
= 15; i
> 0; i
--) {
257 if (env
->pil_in
& (1 << i
)) {
258 int old_interrupt
= env
->interrupt_index
;
260 env
->interrupt_index
= TT_EXTINT
| i
;
261 if (old_interrupt
!= env
->interrupt_index
)
262 cpu_interrupt(env
, CPU_INTERRUPT_HARD
);
266 } else if (!env
->pil_in
&& (env
->interrupt_index
& ~15) == TT_EXTINT
) {
267 env
->interrupt_index
= 0;
268 cpu_reset_interrupt(env
, CPU_INTERRUPT_HARD
);
272 static void cpu_set_irq(void *opaque
, int irq
, int level
)
274 CPUState
*env
= opaque
;
277 DPRINTF("Raise CPU IRQ %d\n", irq
);
279 env
->pil_in
|= 1 << irq
;
282 DPRINTF("Lower CPU IRQ %d\n", irq
);
283 env
->pil_in
&= ~(1 << irq
);
288 static void dummy_cpu_set_irq(void *opaque
, int irq
, int level
)
292 static void *slavio_misc
;
294 void qemu_system_powerdown(void)
296 slavio_set_power_fail(slavio_misc
, 1);
299 static void main_cpu_reset(void *opaque
)
301 CPUState
*env
= opaque
;
307 static void secondary_cpu_reset(void *opaque
)
309 CPUState
*env
= opaque
;
315 static unsigned long sun4m_load_kernel(const char *kernel_filename
,
316 const char *kernel_cmdline
,
317 const char *initrd_filename
)
321 long initrd_size
, kernel_size
;
323 linux_boot
= (kernel_filename
!= NULL
);
327 kernel_size
= load_elf(kernel_filename
, -0xf0000000ULL
, NULL
, NULL
,
330 kernel_size
= load_aout(kernel_filename
, phys_ram_base
+ KERNEL_LOAD_ADDR
);
332 kernel_size
= load_image(kernel_filename
, phys_ram_base
+ KERNEL_LOAD_ADDR
);
333 if (kernel_size
< 0) {
334 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
341 if (initrd_filename
) {
342 initrd_size
= load_image(initrd_filename
, phys_ram_base
+ INITRD_LOAD_ADDR
);
343 if (initrd_size
< 0) {
344 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
349 if (initrd_size
> 0) {
350 for (i
= 0; i
< 64 * TARGET_PAGE_SIZE
; i
+= TARGET_PAGE_SIZE
) {
351 if (ldl_raw(phys_ram_base
+ KERNEL_LOAD_ADDR
+ i
)
352 == 0x48647253) { // HdrS
353 stl_raw(phys_ram_base
+ KERNEL_LOAD_ADDR
+ i
+ 16, INITRD_LOAD_ADDR
);
354 stl_raw(phys_ram_base
+ KERNEL_LOAD_ADDR
+ i
+ 20, initrd_size
);
363 static void sun4m_hw_init(const struct hwdef
*hwdef
, int RAM_size
,
364 const char *boot_device
,
365 DisplayState
*ds
, const char *kernel_filename
,
366 const char *kernel_cmdline
,
367 const char *initrd_filename
, const char *cpu_model
)
370 CPUState
*env
, *envs
[MAX_CPUS
];
372 void *iommu
, *espdma
, *ledma
, *main_esp
, *nvram
;
373 qemu_irq
*cpu_irqs
[MAX_CPUS
], *slavio_irq
, *slavio_cpu_irq
,
374 *espdma_irq
, *ledma_irq
;
375 qemu_irq
*esp_reset
, *le_reset
;
376 unsigned long prom_offset
, kernel_size
;
379 BlockDriverState
*fd
[MAX_FD
];
384 cpu_model
= hwdef
->default_cpu_model
;
386 for(i
= 0; i
< smp_cpus
; i
++) {
387 env
= cpu_init(cpu_model
);
389 fprintf(stderr
, "qemu: Unable to find Sparc CPU definition\n");
392 cpu_sparc_set_id(env
, i
);
395 qemu_register_reset(main_cpu_reset
, env
);
397 qemu_register_reset(secondary_cpu_reset
, env
);
400 register_savevm("cpu", i
, 3, cpu_save
, cpu_load
, env
);
401 cpu_irqs
[i
] = qemu_allocate_irqs(cpu_set_irq
, envs
[i
], MAX_PILS
);
402 env
->prom_addr
= hwdef
->slavio_base
;
405 for (i
= smp_cpus
; i
< MAX_CPUS
; i
++)
406 cpu_irqs
[i
] = qemu_allocate_irqs(dummy_cpu_set_irq
, NULL
, MAX_PILS
);
410 if ((uint64_t)RAM_size
> hwdef
->max_mem
) {
411 fprintf(stderr
, "qemu: Too much memory for this machine: %d, maximum %d\n",
412 (unsigned int)RAM_size
/ (1024 * 1024),
413 (unsigned int)(hwdef
->max_mem
/ (1024 * 1024)));
416 cpu_register_physical_memory(0, RAM_size
, 0);
419 prom_offset
= RAM_size
+ hwdef
->vram_size
;
420 cpu_register_physical_memory(hwdef
->slavio_base
,
421 (PROM_SIZE_MAX
+ TARGET_PAGE_SIZE
- 1) &
423 prom_offset
| IO_MEM_ROM
);
425 if (bios_name
== NULL
)
426 bios_name
= PROM_FILENAME
;
427 snprintf(buf
, sizeof(buf
), "%s/%s", bios_dir
, bios_name
);
428 ret
= load_elf(buf
, hwdef
->slavio_base
- PROM_VADDR
, NULL
, NULL
, NULL
);
429 if (ret
< 0 || ret
> PROM_SIZE_MAX
)
430 ret
= load_image(buf
, phys_ram_base
+ prom_offset
);
431 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
432 fprintf(stderr
, "qemu: could not load prom '%s'\n",
436 prom_offset
+= (ret
+ TARGET_PAGE_SIZE
- 1) & TARGET_PAGE_MASK
;
439 slavio_intctl
= slavio_intctl_init(hwdef
->intctl_base
,
440 hwdef
->intctl_base
+ 0x10000ULL
,
441 &hwdef
->intbit_to_level
[0],
442 &slavio_irq
, &slavio_cpu_irq
,
446 if (hwdef
->idreg_base
!= (target_phys_addr_t
)-1) {
447 stl_raw(phys_ram_base
+ prom_offset
, 0xfe810103);
449 cpu_register_physical_memory(hwdef
->idreg_base
, sizeof(uint32_t),
450 prom_offset
| IO_MEM_ROM
);
453 iommu
= iommu_init(hwdef
->iommu_base
, hwdef
->iommu_version
,
454 slavio_irq
[hwdef
->me_irq
]);
456 espdma
= sparc32_dma_init(hwdef
->dma_base
, slavio_irq
[hwdef
->esp_irq
],
457 iommu
, &espdma_irq
, &esp_reset
);
459 ledma
= sparc32_dma_init(hwdef
->dma_base
+ 16ULL,
460 slavio_irq
[hwdef
->le_irq
], iommu
, &ledma_irq
,
463 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
464 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
467 tcx_init(ds
, hwdef
->tcx_base
, phys_ram_base
+ RAM_size
, RAM_size
,
468 hwdef
->vram_size
, graphic_width
, graphic_height
, graphic_depth
);
470 if (nd_table
[0].model
== NULL
471 || strcmp(nd_table
[0].model
, "lance") == 0) {
472 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, *ledma_irq
, le_reset
);
473 } else if (strcmp(nd_table
[0].model
, "?") == 0) {
474 fprintf(stderr
, "qemu: Supported NICs: lance\n");
477 fprintf(stderr
, "qemu: Unsupported NIC: %s\n", nd_table
[0].model
);
481 nvram
= m48t59_init(slavio_irq
[0], hwdef
->nvram_base
, 0,
482 hwdef
->nvram_size
, 8);
484 slavio_timer_init_all(hwdef
->counter_base
, slavio_irq
[hwdef
->clock1_irq
],
485 slavio_cpu_irq
, smp_cpus
);
487 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, slavio_irq
[hwdef
->ms_kb_irq
],
489 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
490 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
491 slavio_serial_init(hwdef
->serial_base
, slavio_irq
[hwdef
->ser_irq
],
492 serial_hds
[1], serial_hds
[0]);
494 if (hwdef
->fd_base
!= (target_phys_addr_t
)-1) {
495 /* there is zero or one floppy drive */
496 memset(fd
, 0, sizeof(fd
));
497 index
= drive_get_index(IF_FLOPPY
, 0, 0);
499 fd
[0] = drives_table
[index
].bdrv
;
501 sun4m_fdctrl_init(slavio_irq
[hwdef
->fd_irq
], hwdef
->fd_base
, fd
);
504 if (drive_get_max_bus(IF_SCSI
) > 0) {
505 fprintf(stderr
, "qemu: too many SCSI bus\n");
509 main_esp
= esp_init(hwdef
->esp_base
,
510 espdma_memory_read
, espdma_memory_write
,
511 espdma
, *espdma_irq
, esp_reset
);
513 for (i
= 0; i
< ESP_MAX_DEVS
; i
++) {
514 index
= drive_get_index(IF_SCSI
, 0, i
);
517 esp_scsi_attach(main_esp
, drives_table
[index
].bdrv
, i
);
520 slavio_misc
= slavio_misc_init(hwdef
->slavio_base
, hwdef
->apc_base
,
521 hwdef
->aux1_base
, hwdef
->aux2_base
,
522 slavio_irq
[hwdef
->me_irq
], envs
[0]);
523 if (hwdef
->cs_base
!= (target_phys_addr_t
)-1)
524 cs_init(hwdef
->cs_base
, hwdef
->cs_irq
, slavio_intctl
);
526 kernel_size
= sun4m_load_kernel(kernel_filename
, kernel_cmdline
,
529 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
530 boot_device
, RAM_size
, kernel_size
, graphic_width
,
531 graphic_height
, graphic_depth
, hwdef
->machine_id
, "Sun4m");
533 if (hwdef
->ecc_base
!= (target_phys_addr_t
)-1)
534 ecc_init(hwdef
->ecc_base
, slavio_irq
[hwdef
->ecc_irq
],
538 static void sun4c_hw_init(const struct hwdef
*hwdef
, int RAM_size
,
539 const char *boot_device
,
540 DisplayState
*ds
, const char *kernel_filename
,
541 const char *kernel_cmdline
,
542 const char *initrd_filename
, const char *cpu_model
)
546 void *iommu
, *espdma
, *ledma
, *main_esp
, *nvram
;
547 qemu_irq
*cpu_irqs
, *slavio_irq
, *espdma_irq
, *ledma_irq
;
548 qemu_irq
*esp_reset
, *le_reset
;
549 unsigned long prom_offset
, kernel_size
;
552 BlockDriverState
*fd
[MAX_FD
];
557 cpu_model
= hwdef
->default_cpu_model
;
559 env
= cpu_init(cpu_model
);
561 fprintf(stderr
, "qemu: Unable to find Sparc CPU definition\n");
565 cpu_sparc_set_id(env
, 0);
567 qemu_register_reset(main_cpu_reset
, env
);
568 register_savevm("cpu", 0, 3, cpu_save
, cpu_load
, env
);
569 cpu_irqs
= qemu_allocate_irqs(cpu_set_irq
, env
, MAX_PILS
);
570 env
->prom_addr
= hwdef
->slavio_base
;
573 if ((uint64_t)RAM_size
> hwdef
->max_mem
) {
574 fprintf(stderr
, "qemu: Too much memory for this machine: %d, maximum %d\n",
575 (unsigned int)RAM_size
/ (1024 * 1024),
576 (unsigned int)hwdef
->max_mem
/ (1024 * 1024));
579 cpu_register_physical_memory(0, RAM_size
, 0);
582 prom_offset
= RAM_size
+ hwdef
->vram_size
;
583 cpu_register_physical_memory(hwdef
->slavio_base
,
584 (PROM_SIZE_MAX
+ TARGET_PAGE_SIZE
- 1) &
586 prom_offset
| IO_MEM_ROM
);
588 if (bios_name
== NULL
)
589 bios_name
= PROM_FILENAME
;
590 snprintf(buf
, sizeof(buf
), "%s/%s", bios_dir
, bios_name
);
591 ret
= load_elf(buf
, hwdef
->slavio_base
- PROM_VADDR
, NULL
, NULL
, NULL
);
592 if (ret
< 0 || ret
> PROM_SIZE_MAX
)
593 ret
= load_image(buf
, phys_ram_base
+ prom_offset
);
594 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
595 fprintf(stderr
, "qemu: could not load prom '%s'\n",
599 prom_offset
+= (ret
+ TARGET_PAGE_SIZE
- 1) & TARGET_PAGE_MASK
;
602 slavio_intctl
= sun4c_intctl_init(hwdef
->sun4c_intctl_base
,
603 &slavio_irq
, cpu_irqs
);
605 iommu
= iommu_init(hwdef
->iommu_base
, hwdef
->iommu_version
,
606 slavio_irq
[hwdef
->me_irq
]);
608 espdma
= sparc32_dma_init(hwdef
->dma_base
, slavio_irq
[hwdef
->esp_irq
],
609 iommu
, &espdma_irq
, &esp_reset
);
611 ledma
= sparc32_dma_init(hwdef
->dma_base
+ 16ULL,
612 slavio_irq
[hwdef
->le_irq
], iommu
, &ledma_irq
,
615 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
616 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
619 tcx_init(ds
, hwdef
->tcx_base
, phys_ram_base
+ RAM_size
, RAM_size
,
620 hwdef
->vram_size
, graphic_width
, graphic_height
, graphic_depth
);
622 if (nd_table
[0].model
== NULL
623 || strcmp(nd_table
[0].model
, "lance") == 0) {
624 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, *ledma_irq
, le_reset
);
625 } else if (strcmp(nd_table
[0].model
, "?") == 0) {
626 fprintf(stderr
, "qemu: Supported NICs: lance\n");
629 fprintf(stderr
, "qemu: Unsupported NIC: %s\n", nd_table
[0].model
);
633 nvram
= m48t59_init(slavio_irq
[0], hwdef
->nvram_base
, 0,
634 hwdef
->nvram_size
, 2);
636 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, slavio_irq
[hwdef
->ms_kb_irq
],
638 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
639 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
640 slavio_serial_init(hwdef
->serial_base
, slavio_irq
[hwdef
->ser_irq
],
641 serial_hds
[1], serial_hds
[0]);
643 if (hwdef
->fd_base
!= (target_phys_addr_t
)-1) {
644 /* there is zero or one floppy drive */
645 fd
[1] = fd
[0] = NULL
;
646 index
= drive_get_index(IF_FLOPPY
, 0, 0);
648 fd
[0] = drives_table
[index
].bdrv
;
650 sun4m_fdctrl_init(slavio_irq
[hwdef
->fd_irq
], hwdef
->fd_base
, fd
);
653 if (drive_get_max_bus(IF_SCSI
) > 0) {
654 fprintf(stderr
, "qemu: too many SCSI bus\n");
658 main_esp
= esp_init(hwdef
->esp_base
,
659 espdma_memory_read
, espdma_memory_write
,
660 espdma
, *espdma_irq
, esp_reset
);
662 for (i
= 0; i
< ESP_MAX_DEVS
; i
++) {
663 index
= drive_get_index(IF_SCSI
, 0, i
);
666 esp_scsi_attach(main_esp
, drives_table
[index
].bdrv
, i
);
669 slavio_misc
= slavio_misc_init(-1, hwdef
->apc_base
,
670 hwdef
->aux1_base
, hwdef
->aux2_base
,
671 slavio_irq
[hwdef
->me_irq
], env
);
673 kernel_size
= sun4m_load_kernel(kernel_filename
, kernel_cmdline
,
676 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
677 boot_device
, RAM_size
, kernel_size
, graphic_width
,
678 graphic_height
, graphic_depth
, hwdef
->machine_id
, "Sun4c");
681 static const struct hwdef hwdefs
[] = {
684 .iommu_base
= 0x10000000,
685 .tcx_base
= 0x50000000,
686 .cs_base
= 0x6c000000,
687 .slavio_base
= 0x70000000,
688 .ms_kb_base
= 0x71000000,
689 .serial_base
= 0x71100000,
690 .nvram_base
= 0x71200000,
691 .fd_base
= 0x71400000,
692 .counter_base
= 0x71d00000,
693 .intctl_base
= 0x71e00000,
694 .idreg_base
= 0x78000000,
695 .dma_base
= 0x78400000,
696 .esp_base
= 0x78800000,
697 .le_base
= 0x78c00000,
698 .apc_base
= 0x6a000000,
699 .aux1_base
= 0x71900000,
700 .aux2_base
= 0x71910000,
702 .sun4c_intctl_base
= -1,
703 .sun4c_counter_base
= -1,
704 .vram_size
= 0x00100000,
705 .nvram_size
= 0x2000,
716 .iommu_version
= 0x05000000,
718 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
719 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
721 .max_mem
= 0x10000000,
722 .default_cpu_model
= "Fujitsu MB86904",
726 .iommu_base
= 0xfe0000000ULL
,
727 .tcx_base
= 0xe20000000ULL
,
729 .slavio_base
= 0xff0000000ULL
,
730 .ms_kb_base
= 0xff1000000ULL
,
731 .serial_base
= 0xff1100000ULL
,
732 .nvram_base
= 0xff1200000ULL
,
733 .fd_base
= 0xff1700000ULL
,
734 .counter_base
= 0xff1300000ULL
,
735 .intctl_base
= 0xff1400000ULL
,
736 .idreg_base
= 0xef0000000ULL
,
737 .dma_base
= 0xef0400000ULL
,
738 .esp_base
= 0xef0800000ULL
,
739 .le_base
= 0xef0c00000ULL
,
740 .apc_base
= 0xefa000000ULL
, // XXX should not exist
741 .aux1_base
= 0xff1800000ULL
,
742 .aux2_base
= 0xff1a01000ULL
,
743 .ecc_base
= 0xf00000000ULL
,
744 .ecc_version
= 0x10000000, // version 0, implementation 1
745 .sun4c_intctl_base
= -1,
746 .sun4c_counter_base
= -1,
747 .vram_size
= 0x00100000,
748 .nvram_size
= 0x2000,
760 .iommu_version
= 0x03000000,
762 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
763 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
765 .max_mem
= 0xffffffff, // XXX actually first 62GB ok
766 .default_cpu_model
= "TI SuperSparc II",
770 .iommu_base
= 0xfe0000000ULL
,
771 .tcx_base
= 0xe20000000ULL
,
773 .slavio_base
= 0xff0000000ULL
,
774 .ms_kb_base
= 0xff1000000ULL
,
775 .serial_base
= 0xff1100000ULL
,
776 .nvram_base
= 0xff1200000ULL
,
778 .counter_base
= 0xff1300000ULL
,
779 .intctl_base
= 0xff1400000ULL
,
781 .dma_base
= 0xef0081000ULL
,
782 .esp_base
= 0xef0080000ULL
,
783 .le_base
= 0xef0060000ULL
,
784 .apc_base
= 0xefa000000ULL
, // XXX should not exist
785 .aux1_base
= 0xff1800000ULL
,
786 .aux2_base
= 0xff1a01000ULL
, // XXX should not exist
787 .ecc_base
= 0xf00000000ULL
,
788 .ecc_version
= 0x00000000, // version 0, implementation 0
789 .sun4c_intctl_base
= -1,
790 .sun4c_counter_base
= -1,
791 .vram_size
= 0x00100000,
792 .nvram_size
= 0x2000,
804 .iommu_version
= 0x01000000,
806 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
807 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
809 .max_mem
= 0xffffffff, // XXX actually first 62GB ok
810 .default_cpu_model
= "TI SuperSparc II",
814 .iommu_base
= 0xfe0000000ULL
,
815 .tcx_base
= 0xe20000000ULL
,
817 .slavio_base
= 0xff0000000ULL
,
818 .ms_kb_base
= 0xff1000000ULL
,
819 .serial_base
= 0xff1100000ULL
,
820 .nvram_base
= 0xff1200000ULL
,
821 .fd_base
= 0xff1700000ULL
,
822 .counter_base
= 0xff1300000ULL
,
823 .intctl_base
= 0xff1400000ULL
,
824 .idreg_base
= 0xef0000000ULL
,
825 .dma_base
= 0xef0400000ULL
,
826 .esp_base
= 0xef0800000ULL
,
827 .le_base
= 0xef0c00000ULL
,
828 .apc_base
= 0xefa000000ULL
, // XXX should not exist
829 .aux1_base
= 0xff1800000ULL
,
830 .aux2_base
= 0xff1a01000ULL
,
831 .ecc_base
= 0xf00000000ULL
,
832 .ecc_version
= 0x20000000, // version 0, implementation 2
833 .sun4c_intctl_base
= -1,
834 .sun4c_counter_base
= -1,
835 .vram_size
= 0x00100000,
836 .nvram_size
= 0x2000,
848 .iommu_version
= 0x13000000,
850 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
851 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
853 .max_mem
= 0xffffffff, // XXX actually first 62GB ok
854 .default_cpu_model
= "TI SuperSparc II",
858 .iommu_base
= 0xf8000000,
859 .tcx_base
= 0xfe000000,
861 .slavio_base
= 0xf6000000,
862 .ms_kb_base
= 0xf0000000,
863 .serial_base
= 0xf1000000,
864 .nvram_base
= 0xf2000000,
865 .fd_base
= 0xf7200000,
868 .dma_base
= 0xf8400000,
869 .esp_base
= 0xf8800000,
870 .le_base
= 0xf8c00000,
872 .aux1_base
= 0xf7400003,
874 .sun4c_intctl_base
= 0xf5000000,
875 .sun4c_counter_base
= 0xf3000000,
876 .vram_size
= 0x00100000,
888 .max_mem
= 0x10000000,
889 .default_cpu_model
= "Cypress CY7C601",
893 /* SPARCstation 5 hardware initialisation */
894 static void ss5_init(int RAM_size
, int vga_ram_size
,
895 const char *boot_device
, DisplayState
*ds
,
896 const char *kernel_filename
, const char *kernel_cmdline
,
897 const char *initrd_filename
, const char *cpu_model
)
899 sun4m_hw_init(&hwdefs
[0], RAM_size
, boot_device
, ds
, kernel_filename
,
900 kernel_cmdline
, initrd_filename
, cpu_model
);
903 /* SPARCstation 10 hardware initialisation */
904 static void ss10_init(int RAM_size
, int vga_ram_size
,
905 const char *boot_device
, DisplayState
*ds
,
906 const char *kernel_filename
, const char *kernel_cmdline
,
907 const char *initrd_filename
, const char *cpu_model
)
909 sun4m_hw_init(&hwdefs
[1], RAM_size
, boot_device
, ds
, kernel_filename
,
910 kernel_cmdline
, initrd_filename
, cpu_model
);
913 /* SPARCserver 600MP hardware initialisation */
914 static void ss600mp_init(int RAM_size
, int vga_ram_size
,
915 const char *boot_device
, DisplayState
*ds
,
916 const char *kernel_filename
, const char *kernel_cmdline
,
917 const char *initrd_filename
, const char *cpu_model
)
919 sun4m_hw_init(&hwdefs
[2], RAM_size
, boot_device
, ds
, kernel_filename
,
920 kernel_cmdline
, initrd_filename
, cpu_model
);
923 /* SPARCstation 20 hardware initialisation */
924 static void ss20_init(int RAM_size
, int vga_ram_size
,
925 const char *boot_device
, DisplayState
*ds
,
926 const char *kernel_filename
, const char *kernel_cmdline
,
927 const char *initrd_filename
, const char *cpu_model
)
929 sun4m_hw_init(&hwdefs
[3], RAM_size
, boot_device
, ds
, kernel_filename
,
930 kernel_cmdline
, initrd_filename
, cpu_model
);
933 /* SPARCstation 2 hardware initialisation */
934 static void ss2_init(int RAM_size
, int vga_ram_size
,
935 const char *boot_device
, DisplayState
*ds
,
936 const char *kernel_filename
, const char *kernel_cmdline
,
937 const char *initrd_filename
, const char *cpu_model
)
939 sun4c_hw_init(&hwdefs
[4], RAM_size
, boot_device
, ds
, kernel_filename
,
940 kernel_cmdline
, initrd_filename
, cpu_model
);
943 QEMUMachine ss5_machine
= {
945 "Sun4m platform, SPARCstation 5",
949 QEMUMachine ss10_machine
= {
951 "Sun4m platform, SPARCstation 10",
955 QEMUMachine ss600mp_machine
= {
957 "Sun4m platform, SPARCserver 600MP",
961 QEMUMachine ss20_machine
= {
963 "Sun4m platform, SPARCstation 20",
967 QEMUMachine ss2_machine
= {
969 "Sun4c platform, SPARCstation 2",
973 static const struct sun4d_hwdef sun4d_hwdefs
[] = {
983 .tcx_base
= 0x820000000ULL
,
984 .slavio_base
= 0xf00000000ULL
,
985 .ms_kb_base
= 0xf00240000ULL
,
986 .serial_base
= 0xf00200000ULL
,
987 .nvram_base
= 0xf00280000ULL
,
988 .counter_base
= 0xf00300000ULL
,
989 .espdma_base
= 0x800081000ULL
,
990 .esp_base
= 0x800080000ULL
,
991 .ledma_base
= 0x800040000ULL
,
992 .le_base
= 0x800060000ULL
,
993 .sbi_base
= 0xf02800000ULL
,
994 .vram_size
= 0x00100000,
995 .nvram_size
= 0x2000,
1003 .iounit_version
= 0x03000000,
1004 .max_mem
= 0xffffffff, // XXX actually first 62GB ok
1005 .default_cpu_model
= "TI SuperSparc II",
1016 .tcx_base
= 0x820000000ULL
,
1017 .slavio_base
= 0xf00000000ULL
,
1018 .ms_kb_base
= 0xf00240000ULL
,
1019 .serial_base
= 0xf00200000ULL
,
1020 .nvram_base
= 0xf00280000ULL
,
1021 .counter_base
= 0xf00300000ULL
,
1022 .espdma_base
= 0x800081000ULL
,
1023 .esp_base
= 0x800080000ULL
,
1024 .ledma_base
= 0x800040000ULL
,
1025 .le_base
= 0x800060000ULL
,
1026 .sbi_base
= 0xf02800000ULL
,
1027 .vram_size
= 0x00100000,
1028 .nvram_size
= 0x2000,
1036 .iounit_version
= 0x03000000,
1037 .max_mem
= 0xffffffff, // XXX actually first 62GB ok
1038 .default_cpu_model
= "TI SuperSparc II",
1042 static void sun4d_hw_init(const struct sun4d_hwdef
*hwdef
, int RAM_size
,
1043 const char *boot_device
,
1044 DisplayState
*ds
, const char *kernel_filename
,
1045 const char *kernel_cmdline
,
1046 const char *initrd_filename
, const char *cpu_model
)
1048 CPUState
*env
, *envs
[MAX_CPUS
];
1050 void *iounits
[MAX_IOUNITS
], *espdma
, *ledma
, *main_esp
, *nvram
, *sbi
;
1051 qemu_irq
*cpu_irqs
[MAX_CPUS
], *sbi_irq
, *sbi_cpu_irq
,
1052 *espdma_irq
, *ledma_irq
;
1053 qemu_irq
*esp_reset
, *le_reset
;
1054 unsigned long prom_offset
, kernel_size
;
1061 cpu_model
= hwdef
->default_cpu_model
;
1063 for (i
= 0; i
< smp_cpus
; i
++) {
1064 env
= cpu_init(cpu_model
);
1066 fprintf(stderr
, "qemu: Unable to find Sparc CPU definition\n");
1069 cpu_sparc_set_id(env
, i
);
1072 qemu_register_reset(main_cpu_reset
, env
);
1074 qemu_register_reset(secondary_cpu_reset
, env
);
1077 register_savevm("cpu", i
, 3, cpu_save
, cpu_load
, env
);
1078 cpu_irqs
[i
] = qemu_allocate_irqs(cpu_set_irq
, envs
[i
], MAX_PILS
);
1079 env
->prom_addr
= hwdef
->slavio_base
;
1082 for (i
= smp_cpus
; i
< MAX_CPUS
; i
++)
1083 cpu_irqs
[i
] = qemu_allocate_irqs(dummy_cpu_set_irq
, NULL
, MAX_PILS
);
1086 if ((uint64_t)RAM_size
> hwdef
->max_mem
) {
1087 fprintf(stderr
, "qemu: Too much memory for this machine: %d, maximum %d\n",
1088 (unsigned int)RAM_size
/ (1024 * 1024),
1089 (unsigned int)(hwdef
->max_mem
/ (1024 * 1024)));
1092 cpu_register_physical_memory(0, RAM_size
, 0);
1094 /* load boot prom */
1095 prom_offset
= RAM_size
+ hwdef
->vram_size
;
1096 cpu_register_physical_memory(hwdef
->slavio_base
,
1097 (PROM_SIZE_MAX
+ TARGET_PAGE_SIZE
- 1) &
1099 prom_offset
| IO_MEM_ROM
);
1101 if (bios_name
== NULL
)
1102 bios_name
= PROM_FILENAME
;
1103 snprintf(buf
, sizeof(buf
), "%s/%s", bios_dir
, bios_name
);
1104 ret
= load_elf(buf
, hwdef
->slavio_base
- PROM_VADDR
, NULL
, NULL
, NULL
);
1105 if (ret
< 0 || ret
> PROM_SIZE_MAX
)
1106 ret
= load_image(buf
, phys_ram_base
+ prom_offset
);
1107 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
1108 fprintf(stderr
, "qemu: could not load prom '%s'\n",
1113 /* set up devices */
1114 sbi
= sbi_init(hwdef
->sbi_base
, &sbi_irq
, &sbi_cpu_irq
, cpu_irqs
);
1116 for (i
= 0; i
< MAX_IOUNITS
; i
++)
1117 if (hwdef
->iounit_bases
[i
] != (target_phys_addr_t
)-1)
1118 iounits
[i
] = iommu_init(hwdef
->iounit_bases
[i
],
1119 hwdef
->iounit_version
,
1120 sbi_irq
[hwdef
->me_irq
]);
1122 espdma
= sparc32_dma_init(hwdef
->espdma_base
, sbi_irq
[hwdef
->esp_irq
],
1123 iounits
[0], &espdma_irq
, &esp_reset
);
1125 ledma
= sparc32_dma_init(hwdef
->ledma_base
, sbi_irq
[hwdef
->le_irq
],
1126 iounits
[0], &ledma_irq
, &le_reset
);
1128 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
1129 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
1132 tcx_init(ds
, hwdef
->tcx_base
, phys_ram_base
+ RAM_size
, RAM_size
,
1133 hwdef
->vram_size
, graphic_width
, graphic_height
, graphic_depth
);
1135 if (nd_table
[0].model
== NULL
1136 || strcmp(nd_table
[0].model
, "lance") == 0) {
1137 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, *ledma_irq
, le_reset
);
1138 } else if (strcmp(nd_table
[0].model
, "?") == 0) {
1139 fprintf(stderr
, "qemu: Supported NICs: lance\n");
1142 fprintf(stderr
, "qemu: Unsupported NIC: %s\n", nd_table
[0].model
);
1146 nvram
= m48t59_init(sbi_irq
[0], hwdef
->nvram_base
, 0,
1147 hwdef
->nvram_size
, 8);
1149 slavio_timer_init_all(hwdef
->counter_base
, sbi_irq
[hwdef
->clock1_irq
],
1150 sbi_cpu_irq
, smp_cpus
);
1152 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, sbi_irq
[hwdef
->ms_kb_irq
],
1154 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1155 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1156 slavio_serial_init(hwdef
->serial_base
, sbi_irq
[hwdef
->ser_irq
],
1157 serial_hds
[1], serial_hds
[0]);
1159 if (drive_get_max_bus(IF_SCSI
) > 0) {
1160 fprintf(stderr
, "qemu: too many SCSI bus\n");
1164 main_esp
= esp_init(hwdef
->esp_base
,
1165 espdma_memory_read
, espdma_memory_write
,
1166 espdma
, *espdma_irq
, esp_reset
);
1168 for (i
= 0; i
< ESP_MAX_DEVS
; i
++) {
1169 index
= drive_get_index(IF_SCSI
, 0, i
);
1172 esp_scsi_attach(main_esp
, drives_table
[index
].bdrv
, i
);
1175 kernel_size
= sun4m_load_kernel(kernel_filename
, kernel_cmdline
,
1178 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
1179 boot_device
, RAM_size
, kernel_size
, graphic_width
,
1180 graphic_height
, graphic_depth
, hwdef
->machine_id
, "Sun4d");
1183 /* SPARCserver 1000 hardware initialisation */
1184 static void ss1000_init(int RAM_size
, int vga_ram_size
,
1185 const char *boot_device
, DisplayState
*ds
,
1186 const char *kernel_filename
, const char *kernel_cmdline
,
1187 const char *initrd_filename
, const char *cpu_model
)
1189 sun4d_hw_init(&sun4d_hwdefs
[0], RAM_size
, boot_device
, ds
, kernel_filename
,
1190 kernel_cmdline
, initrd_filename
, cpu_model
);
1193 /* SPARCcenter 2000 hardware initialisation */
1194 static void ss2000_init(int RAM_size
, int vga_ram_size
,
1195 const char *boot_device
, DisplayState
*ds
,
1196 const char *kernel_filename
, const char *kernel_cmdline
,
1197 const char *initrd_filename
, const char *cpu_model
)
1199 sun4d_hw_init(&sun4d_hwdefs
[1], RAM_size
, boot_device
, ds
, kernel_filename
,
1200 kernel_cmdline
, initrd_filename
, cpu_model
);
1203 QEMUMachine ss1000_machine
= {
1205 "Sun4d platform, SPARCserver 1000",
1209 QEMUMachine ss2000_machine
= {
1211 "Sun4d platform, SPARCcenter 2000",