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"
43 * Sun4m architecture was used in the following machines:
45 * SPARCserver 6xxMP/xx
46 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
47 * SPARCclassic X (4/10)
48 * SPARCstation LX/ZX (4/30)
49 * SPARCstation Voyager
50 * SPARCstation 10/xx, SPARCserver 10/xx
51 * SPARCstation 5, SPARCserver 5
52 * SPARCstation 20/xx, SPARCserver 20
55 * Sun4d architecture was used in the following machines:
60 * Sun4c architecture was used in the following machines:
61 * SPARCstation 1/1+, SPARCserver 1/1+
67 * See for example: http://www.sunhelp.org/faq/sunref1.html
71 #define DPRINTF(fmt, args...) \
72 do { printf("CPUIRQ: " fmt , ##args); } while (0)
74 #define DPRINTF(fmt, args...)
77 #define KERNEL_LOAD_ADDR 0x00004000
78 #define CMDLINE_ADDR 0x007ff000
79 #define INITRD_LOAD_ADDR 0x00800000
80 #define PROM_SIZE_MAX (1024 * 1024)
81 #define PROM_VADDR 0xffd00000
82 #define PROM_FILENAME "openbios-sparc32"
83 #define CFG_ADDR 0xd00000510ULL
84 #define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
86 // Control plane, 8-bit and 24-bit planes
87 #define TCX_SIZE (9 * 1024 * 1024)
92 #define ESCC_CLOCK 4915200
95 target_phys_addr_t iommu_base
, slavio_base
;
96 target_phys_addr_t intctl_base
, counter_base
, nvram_base
, ms_kb_base
;
97 target_phys_addr_t serial_base
, fd_base
;
98 target_phys_addr_t idreg_base
, dma_base
, esp_base
, le_base
;
99 target_phys_addr_t tcx_base
, cs_base
, apc_base
, aux1_base
, aux2_base
;
100 target_phys_addr_t ecc_base
;
101 uint32_t ecc_version
;
102 long vram_size
, nvram_size
;
103 // IRQ numbers are not PIL ones, but master interrupt controller
104 // register bit numbers
105 int esp_irq
, le_irq
, clock_irq
, clock1_irq
;
106 int ser_irq
, ms_kb_irq
, fd_irq
, me_irq
, cs_irq
, ecc_irq
;
107 uint8_t nvram_machine_id
;
109 uint32_t iommu_version
;
110 uint32_t intbit_to_level
[32];
112 const char * const default_cpu_model
;
115 #define MAX_IOUNITS 5
118 target_phys_addr_t iounit_bases
[MAX_IOUNITS
], slavio_base
;
119 target_phys_addr_t counter_base
, nvram_base
, ms_kb_base
;
120 target_phys_addr_t serial_base
;
121 target_phys_addr_t espdma_base
, esp_base
;
122 target_phys_addr_t ledma_base
, le_base
;
123 target_phys_addr_t tcx_base
;
124 target_phys_addr_t sbi_base
;
125 unsigned long vram_size
, nvram_size
;
126 // IRQ numbers are not PIL ones, but SBI register bit numbers
127 int esp_irq
, le_irq
, clock_irq
, clock1_irq
;
128 int ser_irq
, ms_kb_irq
, me_irq
;
129 uint8_t nvram_machine_id
;
131 uint32_t iounit_version
;
133 const char * const default_cpu_model
;
137 target_phys_addr_t iommu_base
, slavio_base
;
138 target_phys_addr_t intctl_base
, counter_base
, nvram_base
, ms_kb_base
;
139 target_phys_addr_t serial_base
, fd_base
;
140 target_phys_addr_t idreg_base
, dma_base
, esp_base
, le_base
;
141 target_phys_addr_t tcx_base
, aux1_base
;
142 long vram_size
, nvram_size
;
143 // IRQ numbers are not PIL ones, but master interrupt controller
144 // register bit numbers
145 int esp_irq
, le_irq
, clock_irq
, clock1_irq
;
146 int ser_irq
, ms_kb_irq
, fd_irq
, me_irq
;
147 uint8_t nvram_machine_id
;
149 uint32_t iommu_version
;
150 uint32_t intbit_to_level
[32];
152 const char * const default_cpu_model
;
155 int DMA_get_channel_mode (int nchan
)
159 int DMA_read_memory (int nchan
, void *buf
, int pos
, int size
)
163 int DMA_write_memory (int nchan
, void *buf
, int pos
, int size
)
167 void DMA_hold_DREQ (int nchan
) {}
168 void DMA_release_DREQ (int nchan
) {}
169 void DMA_schedule(int nchan
) {}
170 void DMA_init (int high_page_enable
) {}
171 void DMA_register_channel (int nchan
,
172 DMA_transfer_handler transfer_handler
,
177 static int fw_cfg_boot_set(void *opaque
, const char *boot_device
)
179 fw_cfg_add_i16(opaque
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
183 static void nvram_init(m48t59_t
*nvram
, uint8_t *macaddr
, const char *cmdline
,
184 const char *boot_devices
, ram_addr_t RAM_size
,
185 uint32_t kernel_size
,
186 int width
, int height
, int depth
,
187 int nvram_machine_id
, const char *arch
)
191 uint8_t image
[0x1ff0];
192 struct OpenBIOS_nvpart_v1
*part_header
;
194 memset(image
, '\0', sizeof(image
));
198 // OpenBIOS nvram variables
199 // Variable partition
200 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
201 part_header
->signature
= OPENBIOS_PART_SYSTEM
;
202 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "system");
204 end
= start
+ sizeof(struct OpenBIOS_nvpart_v1
);
205 for (i
= 0; i
< nb_prom_envs
; i
++)
206 end
= OpenBIOS_set_var(image
, end
, prom_envs
[i
]);
211 end
= start
+ ((end
- start
+ 15) & ~15);
212 OpenBIOS_finish_partition(part_header
, end
- start
);
216 part_header
= (struct OpenBIOS_nvpart_v1
*)&image
[start
];
217 part_header
->signature
= OPENBIOS_PART_FREE
;
218 pstrcpy(part_header
->name
, sizeof(part_header
->name
), "free");
221 OpenBIOS_finish_partition(part_header
, end
- start
);
223 Sun_init_header((struct Sun_nvram
*)&image
[0x1fd8], macaddr
,
226 for (i
= 0; i
< sizeof(image
); i
++)
227 m48t59_write(nvram
, i
, image
[i
]);
230 static void *slavio_intctl
;
232 void pic_info(Monitor
*mon
)
235 slavio_pic_info(mon
, slavio_intctl
);
238 void irq_info(Monitor
*mon
)
241 slavio_irq_info(mon
, slavio_intctl
);
244 void cpu_check_irqs(CPUState
*env
)
246 if (env
->pil_in
&& (env
->interrupt_index
== 0 ||
247 (env
->interrupt_index
& ~15) == TT_EXTINT
)) {
250 for (i
= 15; i
> 0; i
--) {
251 if (env
->pil_in
& (1 << i
)) {
252 int old_interrupt
= env
->interrupt_index
;
254 env
->interrupt_index
= TT_EXTINT
| i
;
255 if (old_interrupt
!= env
->interrupt_index
) {
256 DPRINTF("Set CPU IRQ %d\n", i
);
257 cpu_interrupt(env
, CPU_INTERRUPT_HARD
);
262 } else if (!env
->pil_in
&& (env
->interrupt_index
& ~15) == TT_EXTINT
) {
263 DPRINTF("Reset CPU IRQ %d\n", env
->interrupt_index
& 15);
264 env
->interrupt_index
= 0;
265 cpu_reset_interrupt(env
, CPU_INTERRUPT_HARD
);
269 static void cpu_set_irq(void *opaque
, int irq
, int level
)
271 CPUState
*env
= opaque
;
274 DPRINTF("Raise CPU IRQ %d\n", irq
);
276 env
->pil_in
|= 1 << irq
;
279 DPRINTF("Lower CPU IRQ %d\n", irq
);
280 env
->pil_in
&= ~(1 << irq
);
285 static void dummy_cpu_set_irq(void *opaque
, int irq
, int level
)
289 static void *slavio_misc
;
291 void qemu_system_powerdown(void)
293 slavio_set_power_fail(slavio_misc
, 1);
296 static void main_cpu_reset(void *opaque
)
298 CPUState
*env
= opaque
;
304 static void secondary_cpu_reset(void *opaque
)
306 CPUState
*env
= opaque
;
312 static void cpu_halt_signal(void *opaque
, int irq
, int level
)
314 if (level
&& cpu_single_env
)
315 cpu_interrupt(cpu_single_env
, CPU_INTERRUPT_HALT
);
318 static unsigned long sun4m_load_kernel(const char *kernel_filename
,
319 const char *initrd_filename
,
324 long initrd_size
, kernel_size
;
326 linux_boot
= (kernel_filename
!= NULL
);
330 kernel_size
= load_elf(kernel_filename
, -0xf0000000ULL
, NULL
, NULL
,
333 kernel_size
= load_aout(kernel_filename
, KERNEL_LOAD_ADDR
,
334 RAM_size
- KERNEL_LOAD_ADDR
);
336 kernel_size
= load_image_targphys(kernel_filename
,
338 RAM_size
- KERNEL_LOAD_ADDR
);
339 if (kernel_size
< 0) {
340 fprintf(stderr
, "qemu: could not load kernel '%s'\n",
347 if (initrd_filename
) {
348 initrd_size
= load_image_targphys(initrd_filename
,
350 RAM_size
- INITRD_LOAD_ADDR
);
351 if (initrd_size
< 0) {
352 fprintf(stderr
, "qemu: could not load initial ram disk '%s'\n",
357 if (initrd_size
> 0) {
358 for (i
= 0; i
< 64 * TARGET_PAGE_SIZE
; i
+= TARGET_PAGE_SIZE
) {
359 if (ldl_phys(KERNEL_LOAD_ADDR
+ i
) == 0x48647253) { // HdrS
360 stl_phys(KERNEL_LOAD_ADDR
+ i
+ 16, INITRD_LOAD_ADDR
);
361 stl_phys(KERNEL_LOAD_ADDR
+ i
+ 20, initrd_size
);
370 static void sun4m_hw_init(const struct sun4m_hwdef
*hwdef
, ram_addr_t RAM_size
,
371 const char *boot_device
,
372 const char *kernel_filename
,
373 const char *kernel_cmdline
,
374 const char *initrd_filename
, const char *cpu_model
)
377 CPUState
*env
, *envs
[MAX_CPUS
];
379 void *iommu
, *espdma
, *ledma
, *main_esp
, *nvram
;
380 qemu_irq
*cpu_irqs
[MAX_CPUS
], *slavio_irq
, *slavio_cpu_irq
,
381 *espdma_irq
, *ledma_irq
;
382 qemu_irq
*esp_reset
, *le_reset
;
385 ram_addr_t ram_offset
, prom_offset
, tcx_offset
, idreg_offset
;
386 unsigned long kernel_size
;
389 BlockDriverState
*fd
[MAX_FD
];
395 cpu_model
= hwdef
->default_cpu_model
;
397 for(i
= 0; i
< smp_cpus
; i
++) {
398 env
= cpu_init(cpu_model
);
400 fprintf(stderr
, "qemu: Unable to find Sparc CPU definition\n");
403 cpu_sparc_set_id(env
, i
);
406 qemu_register_reset(main_cpu_reset
, env
);
408 qemu_register_reset(secondary_cpu_reset
, env
);
411 cpu_irqs
[i
] = qemu_allocate_irqs(cpu_set_irq
, envs
[i
], MAX_PILS
);
412 env
->prom_addr
= hwdef
->slavio_base
;
415 for (i
= smp_cpus
; i
< MAX_CPUS
; i
++)
416 cpu_irqs
[i
] = qemu_allocate_irqs(dummy_cpu_set_irq
, NULL
, MAX_PILS
);
420 if ((uint64_t)RAM_size
> hwdef
->max_mem
) {
422 "qemu: Too much memory for this machine: %d, maximum %d\n",
423 (unsigned int)(RAM_size
/ (1024 * 1024)),
424 (unsigned int)(hwdef
->max_mem
/ (1024 * 1024)));
427 ram_offset
= qemu_ram_alloc(RAM_size
);
428 cpu_register_physical_memory(0, RAM_size
, ram_offset
);
431 prom_offset
= qemu_ram_alloc(PROM_SIZE_MAX
);
432 cpu_register_physical_memory(hwdef
->slavio_base
,
433 (PROM_SIZE_MAX
+ TARGET_PAGE_SIZE
- 1) &
435 prom_offset
| IO_MEM_ROM
);
437 if (bios_name
== NULL
)
438 bios_name
= PROM_FILENAME
;
439 snprintf(buf
, sizeof(buf
), "%s/%s", bios_dir
, bios_name
);
440 ret
= load_elf(buf
, hwdef
->slavio_base
- PROM_VADDR
, NULL
, NULL
, NULL
);
441 if (ret
< 0 || ret
> PROM_SIZE_MAX
)
442 ret
= load_image_targphys(buf
, hwdef
->slavio_base
, PROM_SIZE_MAX
);
443 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
444 fprintf(stderr
, "qemu: could not load prom '%s'\n",
450 slavio_intctl
= slavio_intctl_init(hwdef
->intctl_base
,
451 hwdef
->intctl_base
+ 0x10000ULL
,
452 &hwdef
->intbit_to_level
[0],
453 &slavio_irq
, &slavio_cpu_irq
,
457 if (hwdef
->idreg_base
) {
458 static const uint8_t idreg_data
[] = { 0xfe, 0x81, 0x01, 0x03 };
460 idreg_offset
= qemu_ram_alloc(sizeof(idreg_data
));
461 cpu_register_physical_memory(hwdef
->idreg_base
, sizeof(idreg_data
),
462 idreg_offset
| IO_MEM_ROM
);
463 cpu_physical_memory_write_rom(hwdef
->idreg_base
, idreg_data
,
467 iommu
= iommu_init(hwdef
->iommu_base
, hwdef
->iommu_version
,
468 slavio_irq
[hwdef
->me_irq
]);
470 espdma
= sparc32_dma_init(hwdef
->dma_base
, slavio_irq
[hwdef
->esp_irq
],
471 iommu
, &espdma_irq
, &esp_reset
);
473 ledma
= sparc32_dma_init(hwdef
->dma_base
+ 16ULL,
474 slavio_irq
[hwdef
->le_irq
], iommu
, &ledma_irq
,
477 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
478 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
481 tcx_offset
= qemu_ram_alloc(hwdef
->vram_size
);
482 tcx_init(hwdef
->tcx_base
, phys_ram_base
+ tcx_offset
, tcx_offset
,
483 hwdef
->vram_size
, graphic_width
, graphic_height
, graphic_depth
);
485 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, *ledma_irq
, le_reset
);
487 nvram
= m48t59_init(slavio_irq
[0], hwdef
->nvram_base
, 0,
488 hwdef
->nvram_size
, 8);
490 slavio_timer_init_all(hwdef
->counter_base
, slavio_irq
[hwdef
->clock1_irq
],
491 slavio_cpu_irq
, smp_cpus
);
493 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, slavio_irq
[hwdef
->ms_kb_irq
],
494 nographic
, ESCC_CLOCK
, 1);
495 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
496 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
497 escc_init(hwdef
->serial_base
, slavio_irq
[hwdef
->ser_irq
], slavio_irq
[hwdef
->ser_irq
],
498 serial_hds
[0], serial_hds
[1], ESCC_CLOCK
, 1);
500 cpu_halt
= qemu_allocate_irqs(cpu_halt_signal
, NULL
, 1);
501 slavio_misc
= slavio_misc_init(hwdef
->slavio_base
, hwdef
->apc_base
,
502 hwdef
->aux1_base
, hwdef
->aux2_base
,
503 slavio_irq
[hwdef
->me_irq
], cpu_halt
[0],
506 if (hwdef
->fd_base
) {
507 /* there is zero or one floppy drive */
508 memset(fd
, 0, sizeof(fd
));
509 drive_index
= drive_get_index(IF_FLOPPY
, 0, 0);
510 if (drive_index
!= -1)
511 fd
[0] = drives_table
[drive_index
].bdrv
;
513 sun4m_fdctrl_init(slavio_irq
[hwdef
->fd_irq
], hwdef
->fd_base
, fd
,
517 if (drive_get_max_bus(IF_SCSI
) > 0) {
518 fprintf(stderr
, "qemu: too many SCSI bus\n");
522 main_esp
= esp_init(hwdef
->esp_base
, 2,
523 espdma_memory_read
, espdma_memory_write
,
524 espdma
, *espdma_irq
, esp_reset
);
526 for (i
= 0; i
< ESP_MAX_DEVS
; i
++) {
527 drive_index
= drive_get_index(IF_SCSI
, 0, i
);
528 if (drive_index
== -1)
530 esp_scsi_attach(main_esp
, drives_table
[drive_index
].bdrv
, i
);
534 cs_init(hwdef
->cs_base
, hwdef
->cs_irq
, slavio_intctl
);
536 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
539 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
540 boot_device
, RAM_size
, kernel_size
, graphic_width
,
541 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
545 ecc_init(hwdef
->ecc_base
, slavio_irq
[hwdef
->ecc_irq
],
548 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
549 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
550 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
551 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
552 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
553 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
554 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
555 if (kernel_cmdline
) {
556 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
557 pstrcpy_targphys(CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
559 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
561 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
562 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
563 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
564 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
582 static const struct sun4m_hwdef sun4m_hwdefs
[] = {
585 .iommu_base
= 0x10000000,
586 .tcx_base
= 0x50000000,
587 .cs_base
= 0x6c000000,
588 .slavio_base
= 0x70000000,
589 .ms_kb_base
= 0x71000000,
590 .serial_base
= 0x71100000,
591 .nvram_base
= 0x71200000,
592 .fd_base
= 0x71400000,
593 .counter_base
= 0x71d00000,
594 .intctl_base
= 0x71e00000,
595 .idreg_base
= 0x78000000,
596 .dma_base
= 0x78400000,
597 .esp_base
= 0x78800000,
598 .le_base
= 0x78c00000,
599 .apc_base
= 0x6a000000,
600 .aux1_base
= 0x71900000,
601 .aux2_base
= 0x71910000,
602 .vram_size
= 0x00100000,
603 .nvram_size
= 0x2000,
613 .nvram_machine_id
= 0x80,
614 .machine_id
= ss5_id
,
615 .iommu_version
= 0x05000000,
617 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
618 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
620 .max_mem
= 0x10000000,
621 .default_cpu_model
= "Fujitsu MB86904",
625 .iommu_base
= 0xfe0000000ULL
,
626 .tcx_base
= 0xe20000000ULL
,
627 .slavio_base
= 0xff0000000ULL
,
628 .ms_kb_base
= 0xff1000000ULL
,
629 .serial_base
= 0xff1100000ULL
,
630 .nvram_base
= 0xff1200000ULL
,
631 .fd_base
= 0xff1700000ULL
,
632 .counter_base
= 0xff1300000ULL
,
633 .intctl_base
= 0xff1400000ULL
,
634 .idreg_base
= 0xef0000000ULL
,
635 .dma_base
= 0xef0400000ULL
,
636 .esp_base
= 0xef0800000ULL
,
637 .le_base
= 0xef0c00000ULL
,
638 .apc_base
= 0xefa000000ULL
, // XXX should not exist
639 .aux1_base
= 0xff1800000ULL
,
640 .aux2_base
= 0xff1a01000ULL
,
641 .ecc_base
= 0xf00000000ULL
,
642 .ecc_version
= 0x10000000, // version 0, implementation 1
643 .vram_size
= 0x00100000,
644 .nvram_size
= 0x2000,
654 .nvram_machine_id
= 0x72,
655 .machine_id
= ss10_id
,
656 .iommu_version
= 0x03000000,
658 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
659 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
661 .max_mem
= 0xf00000000ULL
,
662 .default_cpu_model
= "TI SuperSparc II",
666 .iommu_base
= 0xfe0000000ULL
,
667 .tcx_base
= 0xe20000000ULL
,
668 .slavio_base
= 0xff0000000ULL
,
669 .ms_kb_base
= 0xff1000000ULL
,
670 .serial_base
= 0xff1100000ULL
,
671 .nvram_base
= 0xff1200000ULL
,
672 .counter_base
= 0xff1300000ULL
,
673 .intctl_base
= 0xff1400000ULL
,
674 .dma_base
= 0xef0081000ULL
,
675 .esp_base
= 0xef0080000ULL
,
676 .le_base
= 0xef0060000ULL
,
677 .apc_base
= 0xefa000000ULL
, // XXX should not exist
678 .aux1_base
= 0xff1800000ULL
,
679 .aux2_base
= 0xff1a01000ULL
, // XXX should not exist
680 .ecc_base
= 0xf00000000ULL
,
681 .ecc_version
= 0x00000000, // version 0, implementation 0
682 .vram_size
= 0x00100000,
683 .nvram_size
= 0x2000,
693 .nvram_machine_id
= 0x71,
694 .machine_id
= ss600mp_id
,
695 .iommu_version
= 0x01000000,
697 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
698 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
700 .max_mem
= 0xf00000000ULL
,
701 .default_cpu_model
= "TI SuperSparc II",
705 .iommu_base
= 0xfe0000000ULL
,
706 .tcx_base
= 0xe20000000ULL
,
707 .slavio_base
= 0xff0000000ULL
,
708 .ms_kb_base
= 0xff1000000ULL
,
709 .serial_base
= 0xff1100000ULL
,
710 .nvram_base
= 0xff1200000ULL
,
711 .fd_base
= 0xff1700000ULL
,
712 .counter_base
= 0xff1300000ULL
,
713 .intctl_base
= 0xff1400000ULL
,
714 .idreg_base
= 0xef0000000ULL
,
715 .dma_base
= 0xef0400000ULL
,
716 .esp_base
= 0xef0800000ULL
,
717 .le_base
= 0xef0c00000ULL
,
718 .apc_base
= 0xefa000000ULL
, // XXX should not exist
719 .aux1_base
= 0xff1800000ULL
,
720 .aux2_base
= 0xff1a01000ULL
,
721 .ecc_base
= 0xf00000000ULL
,
722 .ecc_version
= 0x20000000, // version 0, implementation 2
723 .vram_size
= 0x00100000,
724 .nvram_size
= 0x2000,
734 .nvram_machine_id
= 0x72,
735 .machine_id
= ss20_id
,
736 .iommu_version
= 0x13000000,
738 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
739 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
741 .max_mem
= 0xf00000000ULL
,
742 .default_cpu_model
= "TI SuperSparc II",
746 .iommu_base
= 0x10000000,
747 .tcx_base
= 0x50000000,
748 .slavio_base
= 0x70000000,
749 .ms_kb_base
= 0x71000000,
750 .serial_base
= 0x71100000,
751 .nvram_base
= 0x71200000,
752 .fd_base
= 0x71400000,
753 .counter_base
= 0x71d00000,
754 .intctl_base
= 0x71e00000,
755 .idreg_base
= 0x78000000,
756 .dma_base
= 0x78400000,
757 .esp_base
= 0x78800000,
758 .le_base
= 0x78c00000,
759 .apc_base
= 0x71300000, // pmc
760 .aux1_base
= 0x71900000,
761 .aux2_base
= 0x71910000,
762 .vram_size
= 0x00100000,
763 .nvram_size
= 0x2000,
772 .nvram_machine_id
= 0x80,
773 .machine_id
= vger_id
,
774 .iommu_version
= 0x05000000,
776 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
777 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
779 .max_mem
= 0x10000000,
780 .default_cpu_model
= "Fujitsu MB86904",
784 .iommu_base
= 0x10000000,
785 .tcx_base
= 0x50000000,
786 .slavio_base
= 0x70000000,
787 .ms_kb_base
= 0x71000000,
788 .serial_base
= 0x71100000,
789 .nvram_base
= 0x71200000,
790 .fd_base
= 0x71400000,
791 .counter_base
= 0x71d00000,
792 .intctl_base
= 0x71e00000,
793 .idreg_base
= 0x78000000,
794 .dma_base
= 0x78400000,
795 .esp_base
= 0x78800000,
796 .le_base
= 0x78c00000,
797 .aux1_base
= 0x71900000,
798 .aux2_base
= 0x71910000,
799 .vram_size
= 0x00100000,
800 .nvram_size
= 0x2000,
809 .nvram_machine_id
= 0x80,
811 .iommu_version
= 0x04000000,
813 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
814 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
816 .max_mem
= 0x10000000,
817 .default_cpu_model
= "TI MicroSparc I",
821 .iommu_base
= 0x10000000,
822 .tcx_base
= 0x50000000,
823 .cs_base
= 0x6c000000,
824 .slavio_base
= 0x70000000,
825 .ms_kb_base
= 0x71000000,
826 .serial_base
= 0x71100000,
827 .nvram_base
= 0x71200000,
828 .fd_base
= 0x71400000,
829 .counter_base
= 0x71d00000,
830 .intctl_base
= 0x71e00000,
831 .idreg_base
= 0x78000000,
832 .dma_base
= 0x78400000,
833 .esp_base
= 0x78800000,
834 .le_base
= 0x78c00000,
835 .apc_base
= 0x6a000000,
836 .aux1_base
= 0x71900000,
837 .aux2_base
= 0x71910000,
838 .vram_size
= 0x00100000,
839 .nvram_size
= 0x2000,
849 .nvram_machine_id
= 0x80,
850 .machine_id
= ss4_id
,
851 .iommu_version
= 0x05000000,
853 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
854 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
856 .max_mem
= 0x10000000,
857 .default_cpu_model
= "Fujitsu MB86904",
861 .iommu_base
= 0x10000000,
862 .tcx_base
= 0x50000000,
863 .slavio_base
= 0x70000000,
864 .ms_kb_base
= 0x71000000,
865 .serial_base
= 0x71100000,
866 .nvram_base
= 0x71200000,
867 .fd_base
= 0x71400000,
868 .counter_base
= 0x71d00000,
869 .intctl_base
= 0x71e00000,
870 .idreg_base
= 0x78000000,
871 .dma_base
= 0x78400000,
872 .esp_base
= 0x78800000,
873 .le_base
= 0x78c00000,
874 .apc_base
= 0x6a000000,
875 .aux1_base
= 0x71900000,
876 .aux2_base
= 0x71910000,
877 .vram_size
= 0x00100000,
878 .nvram_size
= 0x2000,
887 .nvram_machine_id
= 0x80,
888 .machine_id
= scls_id
,
889 .iommu_version
= 0x05000000,
891 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
892 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
894 .max_mem
= 0x10000000,
895 .default_cpu_model
= "TI MicroSparc I",
899 .iommu_base
= 0x10000000,
900 .tcx_base
= 0x50000000, // XXX
901 .slavio_base
= 0x70000000,
902 .ms_kb_base
= 0x71000000,
903 .serial_base
= 0x71100000,
904 .nvram_base
= 0x71200000,
905 .fd_base
= 0x71400000,
906 .counter_base
= 0x71d00000,
907 .intctl_base
= 0x71e00000,
908 .idreg_base
= 0x78000000,
909 .dma_base
= 0x78400000,
910 .esp_base
= 0x78800000,
911 .le_base
= 0x78c00000,
912 .apc_base
= 0x6a000000,
913 .aux1_base
= 0x71900000,
914 .aux2_base
= 0x71910000,
915 .vram_size
= 0x00100000,
916 .nvram_size
= 0x2000,
925 .nvram_machine_id
= 0x80,
926 .machine_id
= sbook_id
,
927 .iommu_version
= 0x05000000,
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
= 0x10000000,
933 .default_cpu_model
= "TI MicroSparc I",
937 /* SPARCstation 5 hardware initialisation */
938 static void ss5_init(ram_addr_t RAM_size
, int vga_ram_size
,
939 const char *boot_device
,
940 const char *kernel_filename
, const char *kernel_cmdline
,
941 const char *initrd_filename
, const char *cpu_model
)
943 sun4m_hw_init(&sun4m_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
944 kernel_cmdline
, initrd_filename
, cpu_model
);
947 /* SPARCstation 10 hardware initialisation */
948 static void ss10_init(ram_addr_t RAM_size
, int vga_ram_size
,
949 const char *boot_device
,
950 const char *kernel_filename
, const char *kernel_cmdline
,
951 const char *initrd_filename
, const char *cpu_model
)
953 sun4m_hw_init(&sun4m_hwdefs
[1], RAM_size
, boot_device
, kernel_filename
,
954 kernel_cmdline
, initrd_filename
, cpu_model
);
957 /* SPARCserver 600MP hardware initialisation */
958 static void ss600mp_init(ram_addr_t RAM_size
, int vga_ram_size
,
959 const char *boot_device
,
960 const char *kernel_filename
,
961 const char *kernel_cmdline
,
962 const char *initrd_filename
, const char *cpu_model
)
964 sun4m_hw_init(&sun4m_hwdefs
[2], RAM_size
, boot_device
, kernel_filename
,
965 kernel_cmdline
, initrd_filename
, cpu_model
);
968 /* SPARCstation 20 hardware initialisation */
969 static void ss20_init(ram_addr_t RAM_size
, int vga_ram_size
,
970 const char *boot_device
,
971 const char *kernel_filename
, const char *kernel_cmdline
,
972 const char *initrd_filename
, const char *cpu_model
)
974 sun4m_hw_init(&sun4m_hwdefs
[3], RAM_size
, boot_device
, kernel_filename
,
975 kernel_cmdline
, initrd_filename
, cpu_model
);
978 /* SPARCstation Voyager hardware initialisation */
979 static void vger_init(ram_addr_t RAM_size
, int vga_ram_size
,
980 const char *boot_device
,
981 const char *kernel_filename
, const char *kernel_cmdline
,
982 const char *initrd_filename
, const char *cpu_model
)
984 sun4m_hw_init(&sun4m_hwdefs
[4], RAM_size
, boot_device
, kernel_filename
,
985 kernel_cmdline
, initrd_filename
, cpu_model
);
988 /* SPARCstation LX hardware initialisation */
989 static void ss_lx_init(ram_addr_t RAM_size
, int vga_ram_size
,
990 const char *boot_device
,
991 const char *kernel_filename
, const char *kernel_cmdline
,
992 const char *initrd_filename
, const char *cpu_model
)
994 sun4m_hw_init(&sun4m_hwdefs
[5], RAM_size
, boot_device
, kernel_filename
,
995 kernel_cmdline
, initrd_filename
, cpu_model
);
998 /* SPARCstation 4 hardware initialisation */
999 static void ss4_init(ram_addr_t RAM_size
, int vga_ram_size
,
1000 const char *boot_device
,
1001 const char *kernel_filename
, const char *kernel_cmdline
,
1002 const char *initrd_filename
, const char *cpu_model
)
1004 sun4m_hw_init(&sun4m_hwdefs
[6], RAM_size
, boot_device
, kernel_filename
,
1005 kernel_cmdline
, initrd_filename
, cpu_model
);
1008 /* SPARCClassic hardware initialisation */
1009 static void scls_init(ram_addr_t RAM_size
, int vga_ram_size
,
1010 const char *boot_device
,
1011 const char *kernel_filename
, const char *kernel_cmdline
,
1012 const char *initrd_filename
, const char *cpu_model
)
1014 sun4m_hw_init(&sun4m_hwdefs
[7], RAM_size
, boot_device
, kernel_filename
,
1015 kernel_cmdline
, initrd_filename
, cpu_model
);
1018 /* SPARCbook hardware initialisation */
1019 static void sbook_init(ram_addr_t RAM_size
, int vga_ram_size
,
1020 const char *boot_device
,
1021 const char *kernel_filename
, const char *kernel_cmdline
,
1022 const char *initrd_filename
, const char *cpu_model
)
1024 sun4m_hw_init(&sun4m_hwdefs
[8], RAM_size
, boot_device
, kernel_filename
,
1025 kernel_cmdline
, initrd_filename
, cpu_model
);
1028 QEMUMachine ss5_machine
= {
1030 .desc
= "Sun4m platform, SPARCstation 5",
1032 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1037 QEMUMachine ss10_machine
= {
1039 .desc
= "Sun4m platform, SPARCstation 10",
1041 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1047 QEMUMachine ss600mp_machine
= {
1049 .desc
= "Sun4m platform, SPARCserver 600MP",
1050 .init
= ss600mp_init
,
1051 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1057 QEMUMachine ss20_machine
= {
1059 .desc
= "Sun4m platform, SPARCstation 20",
1061 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1067 QEMUMachine voyager_machine
= {
1069 .desc
= "Sun4m platform, SPARCstation Voyager",
1071 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1076 QEMUMachine ss_lx_machine
= {
1078 .desc
= "Sun4m platform, SPARCstation LX",
1080 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1085 QEMUMachine ss4_machine
= {
1087 .desc
= "Sun4m platform, SPARCstation 4",
1089 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1094 QEMUMachine scls_machine
= {
1095 .name
= "SPARCClassic",
1096 .desc
= "Sun4m platform, SPARCClassic",
1098 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1103 QEMUMachine sbook_machine
= {
1104 .name
= "SPARCbook",
1105 .desc
= "Sun4m platform, SPARCbook",
1107 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1112 static const struct sun4d_hwdef sun4d_hwdefs
[] = {
1122 .tcx_base
= 0x820000000ULL
,
1123 .slavio_base
= 0xf00000000ULL
,
1124 .ms_kb_base
= 0xf00240000ULL
,
1125 .serial_base
= 0xf00200000ULL
,
1126 .nvram_base
= 0xf00280000ULL
,
1127 .counter_base
= 0xf00300000ULL
,
1128 .espdma_base
= 0x800081000ULL
,
1129 .esp_base
= 0x800080000ULL
,
1130 .ledma_base
= 0x800040000ULL
,
1131 .le_base
= 0x800060000ULL
,
1132 .sbi_base
= 0xf02800000ULL
,
1133 .vram_size
= 0x00100000,
1134 .nvram_size
= 0x2000,
1141 .nvram_machine_id
= 0x80,
1142 .machine_id
= ss1000_id
,
1143 .iounit_version
= 0x03000000,
1144 .max_mem
= 0xf00000000ULL
,
1145 .default_cpu_model
= "TI SuperSparc II",
1156 .tcx_base
= 0x820000000ULL
,
1157 .slavio_base
= 0xf00000000ULL
,
1158 .ms_kb_base
= 0xf00240000ULL
,
1159 .serial_base
= 0xf00200000ULL
,
1160 .nvram_base
= 0xf00280000ULL
,
1161 .counter_base
= 0xf00300000ULL
,
1162 .espdma_base
= 0x800081000ULL
,
1163 .esp_base
= 0x800080000ULL
,
1164 .ledma_base
= 0x800040000ULL
,
1165 .le_base
= 0x800060000ULL
,
1166 .sbi_base
= 0xf02800000ULL
,
1167 .vram_size
= 0x00100000,
1168 .nvram_size
= 0x2000,
1175 .nvram_machine_id
= 0x80,
1176 .machine_id
= ss2000_id
,
1177 .iounit_version
= 0x03000000,
1178 .max_mem
= 0xf00000000ULL
,
1179 .default_cpu_model
= "TI SuperSparc II",
1183 static void sun4d_hw_init(const struct sun4d_hwdef
*hwdef
, ram_addr_t RAM_size
,
1184 const char *boot_device
,
1185 const char *kernel_filename
,
1186 const char *kernel_cmdline
,
1187 const char *initrd_filename
, const char *cpu_model
)
1189 CPUState
*env
, *envs
[MAX_CPUS
];
1191 void *iounits
[MAX_IOUNITS
], *espdma
, *ledma
, *main_esp
, *nvram
, *sbi
;
1192 qemu_irq
*cpu_irqs
[MAX_CPUS
], *sbi_irq
, *sbi_cpu_irq
,
1193 *espdma_irq
, *ledma_irq
;
1194 qemu_irq
*esp_reset
, *le_reset
;
1195 ram_addr_t ram_offset
, prom_offset
, tcx_offset
;
1196 unsigned long kernel_size
;
1204 cpu_model
= hwdef
->default_cpu_model
;
1206 for (i
= 0; i
< smp_cpus
; i
++) {
1207 env
= cpu_init(cpu_model
);
1209 fprintf(stderr
, "qemu: Unable to find Sparc CPU definition\n");
1212 cpu_sparc_set_id(env
, i
);
1215 qemu_register_reset(main_cpu_reset
, env
);
1217 qemu_register_reset(secondary_cpu_reset
, env
);
1220 cpu_irqs
[i
] = qemu_allocate_irqs(cpu_set_irq
, envs
[i
], MAX_PILS
);
1221 env
->prom_addr
= hwdef
->slavio_base
;
1224 for (i
= smp_cpus
; i
< MAX_CPUS
; i
++)
1225 cpu_irqs
[i
] = qemu_allocate_irqs(dummy_cpu_set_irq
, NULL
, MAX_PILS
);
1228 if ((uint64_t)RAM_size
> hwdef
->max_mem
) {
1230 "qemu: Too much memory for this machine: %d, maximum %d\n",
1231 (unsigned int)(RAM_size
/ (1024 * 1024)),
1232 (unsigned int)(hwdef
->max_mem
/ (1024 * 1024)));
1235 ram_offset
= qemu_ram_alloc(RAM_size
);
1236 cpu_register_physical_memory(0, RAM_size
, ram_offset
);
1238 /* load boot prom */
1239 prom_offset
= qemu_ram_alloc(PROM_SIZE_MAX
);
1240 cpu_register_physical_memory(hwdef
->slavio_base
,
1241 (PROM_SIZE_MAX
+ TARGET_PAGE_SIZE
- 1) &
1243 prom_offset
| IO_MEM_ROM
);
1245 if (bios_name
== NULL
)
1246 bios_name
= PROM_FILENAME
;
1247 snprintf(buf
, sizeof(buf
), "%s/%s", bios_dir
, bios_name
);
1248 ret
= load_elf(buf
, hwdef
->slavio_base
- PROM_VADDR
, NULL
, NULL
, NULL
);
1249 if (ret
< 0 || ret
> PROM_SIZE_MAX
)
1250 ret
= load_image_targphys(buf
, hwdef
->slavio_base
, PROM_SIZE_MAX
);
1251 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
1252 fprintf(stderr
, "qemu: could not load prom '%s'\n",
1257 /* set up devices */
1258 sbi
= sbi_init(hwdef
->sbi_base
, &sbi_irq
, &sbi_cpu_irq
, cpu_irqs
);
1260 for (i
= 0; i
< MAX_IOUNITS
; i
++)
1261 if (hwdef
->iounit_bases
[i
] != (target_phys_addr_t
)-1)
1262 iounits
[i
] = iommu_init(hwdef
->iounit_bases
[i
],
1263 hwdef
->iounit_version
,
1264 sbi_irq
[hwdef
->me_irq
]);
1266 espdma
= sparc32_dma_init(hwdef
->espdma_base
, sbi_irq
[hwdef
->esp_irq
],
1267 iounits
[0], &espdma_irq
, &esp_reset
);
1269 ledma
= sparc32_dma_init(hwdef
->ledma_base
, sbi_irq
[hwdef
->le_irq
],
1270 iounits
[0], &ledma_irq
, &le_reset
);
1272 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
1273 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
1276 tcx_offset
= qemu_ram_alloc(hwdef
->vram_size
);
1277 tcx_init(hwdef
->tcx_base
, phys_ram_base
+ tcx_offset
, tcx_offset
,
1278 hwdef
->vram_size
, graphic_width
, graphic_height
, graphic_depth
);
1280 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, *ledma_irq
, le_reset
);
1282 nvram
= m48t59_init(sbi_irq
[0], hwdef
->nvram_base
, 0,
1283 hwdef
->nvram_size
, 8);
1285 slavio_timer_init_all(hwdef
->counter_base
, sbi_irq
[hwdef
->clock1_irq
],
1286 sbi_cpu_irq
, smp_cpus
);
1288 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, sbi_irq
[hwdef
->ms_kb_irq
],
1289 nographic
, ESCC_CLOCK
, 1);
1290 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1291 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1292 escc_init(hwdef
->serial_base
, sbi_irq
[hwdef
->ser_irq
], sbi_irq
[hwdef
->ser_irq
],
1293 serial_hds
[0], serial_hds
[1], ESCC_CLOCK
, 1);
1295 if (drive_get_max_bus(IF_SCSI
) > 0) {
1296 fprintf(stderr
, "qemu: too many SCSI bus\n");
1300 main_esp
= esp_init(hwdef
->esp_base
, 2,
1301 espdma_memory_read
, espdma_memory_write
,
1302 espdma
, *espdma_irq
, esp_reset
);
1304 for (i
= 0; i
< ESP_MAX_DEVS
; i
++) {
1305 drive_index
= drive_get_index(IF_SCSI
, 0, i
);
1306 if (drive_index
== -1)
1308 esp_scsi_attach(main_esp
, drives_table
[drive_index
].bdrv
, i
);
1311 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
1314 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
1315 boot_device
, RAM_size
, kernel_size
, graphic_width
,
1316 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
1319 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
1320 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
1321 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
1322 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
1323 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
1324 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
1325 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
1326 if (kernel_cmdline
) {
1327 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
1328 pstrcpy_targphys(CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
1330 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
1332 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
1333 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
1334 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
1335 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
1338 /* SPARCserver 1000 hardware initialisation */
1339 static void ss1000_init(ram_addr_t RAM_size
, int vga_ram_size
,
1340 const char *boot_device
,
1341 const char *kernel_filename
, const char *kernel_cmdline
,
1342 const char *initrd_filename
, const char *cpu_model
)
1344 sun4d_hw_init(&sun4d_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
1345 kernel_cmdline
, initrd_filename
, cpu_model
);
1348 /* SPARCcenter 2000 hardware initialisation */
1349 static void ss2000_init(ram_addr_t RAM_size
, int vga_ram_size
,
1350 const char *boot_device
,
1351 const char *kernel_filename
, const char *kernel_cmdline
,
1352 const char *initrd_filename
, const char *cpu_model
)
1354 sun4d_hw_init(&sun4d_hwdefs
[1], RAM_size
, boot_device
, kernel_filename
,
1355 kernel_cmdline
, initrd_filename
, cpu_model
);
1358 QEMUMachine ss1000_machine
= {
1360 .desc
= "Sun4d platform, SPARCserver 1000",
1361 .init
= ss1000_init
,
1362 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1368 QEMUMachine ss2000_machine
= {
1370 .desc
= "Sun4d platform, SPARCcenter 2000",
1371 .init
= ss2000_init
,
1372 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,
1378 static const struct sun4c_hwdef sun4c_hwdefs
[] = {
1381 .iommu_base
= 0xf8000000,
1382 .tcx_base
= 0xfe000000,
1383 .slavio_base
= 0xf6000000,
1384 .intctl_base
= 0xf5000000,
1385 .counter_base
= 0xf3000000,
1386 .ms_kb_base
= 0xf0000000,
1387 .serial_base
= 0xf1000000,
1388 .nvram_base
= 0xf2000000,
1389 .fd_base
= 0xf7200000,
1390 .dma_base
= 0xf8400000,
1391 .esp_base
= 0xf8800000,
1392 .le_base
= 0xf8c00000,
1393 .aux1_base
= 0xf7400003,
1394 .vram_size
= 0x00100000,
1395 .nvram_size
= 0x800,
1404 .nvram_machine_id
= 0x55,
1405 .machine_id
= ss2_id
,
1406 .max_mem
= 0x10000000,
1407 .default_cpu_model
= "Cypress CY7C601",
1411 static void sun4c_hw_init(const struct sun4c_hwdef
*hwdef
, ram_addr_t RAM_size
,
1412 const char *boot_device
,
1413 const char *kernel_filename
,
1414 const char *kernel_cmdline
,
1415 const char *initrd_filename
, const char *cpu_model
)
1419 void *iommu
, *espdma
, *ledma
, *main_esp
, *nvram
;
1420 qemu_irq
*cpu_irqs
, *slavio_irq
, *espdma_irq
, *ledma_irq
;
1421 qemu_irq
*esp_reset
, *le_reset
;
1423 ram_addr_t ram_offset
, prom_offset
, tcx_offset
;
1424 unsigned long kernel_size
;
1427 BlockDriverState
*fd
[MAX_FD
];
1433 cpu_model
= hwdef
->default_cpu_model
;
1435 env
= cpu_init(cpu_model
);
1437 fprintf(stderr
, "qemu: Unable to find Sparc CPU definition\n");
1441 cpu_sparc_set_id(env
, 0);
1443 qemu_register_reset(main_cpu_reset
, env
);
1444 cpu_irqs
= qemu_allocate_irqs(cpu_set_irq
, env
, MAX_PILS
);
1445 env
->prom_addr
= hwdef
->slavio_base
;
1448 if ((uint64_t)RAM_size
> hwdef
->max_mem
) {
1450 "qemu: Too much memory for this machine: %d, maximum %d\n",
1451 (unsigned int)(RAM_size
/ (1024 * 1024)),
1452 (unsigned int)(hwdef
->max_mem
/ (1024 * 1024)));
1455 ram_offset
= qemu_ram_alloc(RAM_size
);
1456 cpu_register_physical_memory(0, RAM_size
, ram_offset
);
1458 /* load boot prom */
1459 prom_offset
= qemu_ram_alloc(PROM_SIZE_MAX
);
1460 cpu_register_physical_memory(hwdef
->slavio_base
,
1461 (PROM_SIZE_MAX
+ TARGET_PAGE_SIZE
- 1) &
1463 prom_offset
| IO_MEM_ROM
);
1465 if (bios_name
== NULL
)
1466 bios_name
= PROM_FILENAME
;
1467 snprintf(buf
, sizeof(buf
), "%s/%s", bios_dir
, bios_name
);
1468 ret
= load_elf(buf
, hwdef
->slavio_base
- PROM_VADDR
, NULL
, NULL
, NULL
);
1469 if (ret
< 0 || ret
> PROM_SIZE_MAX
)
1470 ret
= load_image_targphys(buf
, hwdef
->slavio_base
, PROM_SIZE_MAX
);
1471 if (ret
< 0 || ret
> PROM_SIZE_MAX
) {
1472 fprintf(stderr
, "qemu: could not load prom '%s'\n",
1477 /* set up devices */
1478 slavio_intctl
= sun4c_intctl_init(hwdef
->intctl_base
,
1479 &slavio_irq
, cpu_irqs
);
1481 iommu
= iommu_init(hwdef
->iommu_base
, hwdef
->iommu_version
,
1482 slavio_irq
[hwdef
->me_irq
]);
1484 espdma
= sparc32_dma_init(hwdef
->dma_base
, slavio_irq
[hwdef
->esp_irq
],
1485 iommu
, &espdma_irq
, &esp_reset
);
1487 ledma
= sparc32_dma_init(hwdef
->dma_base
+ 16ULL,
1488 slavio_irq
[hwdef
->le_irq
], iommu
, &ledma_irq
,
1491 if (graphic_depth
!= 8 && graphic_depth
!= 24) {
1492 fprintf(stderr
, "qemu: Unsupported depth: %d\n", graphic_depth
);
1495 tcx_offset
= qemu_ram_alloc(hwdef
->vram_size
);
1496 tcx_init(hwdef
->tcx_base
, phys_ram_base
+ tcx_offset
, tcx_offset
,
1497 hwdef
->vram_size
, graphic_width
, graphic_height
, graphic_depth
);
1499 lance_init(&nd_table
[0], hwdef
->le_base
, ledma
, *ledma_irq
, le_reset
);
1501 nvram
= m48t59_init(slavio_irq
[0], hwdef
->nvram_base
, 0,
1502 hwdef
->nvram_size
, 2);
1504 slavio_serial_ms_kbd_init(hwdef
->ms_kb_base
, slavio_irq
[hwdef
->ms_kb_irq
],
1505 nographic
, ESCC_CLOCK
, 1);
1506 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1507 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1508 escc_init(hwdef
->serial_base
, slavio_irq
[hwdef
->ser_irq
],
1509 slavio_irq
[hwdef
->ser_irq
], serial_hds
[0], serial_hds
[1],
1512 slavio_misc
= slavio_misc_init(0, 0, hwdef
->aux1_base
, 0,
1513 slavio_irq
[hwdef
->me_irq
], NULL
, &fdc_tc
);
1515 if (hwdef
->fd_base
!= (target_phys_addr_t
)-1) {
1516 /* there is zero or one floppy drive */
1517 memset(fd
, 0, sizeof(fd
));
1518 drive_index
= drive_get_index(IF_FLOPPY
, 0, 0);
1519 if (drive_index
!= -1)
1520 fd
[0] = drives_table
[drive_index
].bdrv
;
1522 sun4m_fdctrl_init(slavio_irq
[hwdef
->fd_irq
], hwdef
->fd_base
, fd
,
1526 if (drive_get_max_bus(IF_SCSI
) > 0) {
1527 fprintf(stderr
, "qemu: too many SCSI bus\n");
1531 main_esp
= esp_init(hwdef
->esp_base
, 2,
1532 espdma_memory_read
, espdma_memory_write
,
1533 espdma
, *espdma_irq
, esp_reset
);
1535 for (i
= 0; i
< ESP_MAX_DEVS
; i
++) {
1536 drive_index
= drive_get_index(IF_SCSI
, 0, i
);
1537 if (drive_index
== -1)
1539 esp_scsi_attach(main_esp
, drives_table
[drive_index
].bdrv
, i
);
1542 kernel_size
= sun4m_load_kernel(kernel_filename
, initrd_filename
,
1545 nvram_init(nvram
, (uint8_t *)&nd_table
[0].macaddr
, kernel_cmdline
,
1546 boot_device
, RAM_size
, kernel_size
, graphic_width
,
1547 graphic_height
, graphic_depth
, hwdef
->nvram_machine_id
,
1550 fw_cfg
= fw_cfg_init(0, 0, CFG_ADDR
, CFG_ADDR
+ 2);
1551 fw_cfg_add_i32(fw_cfg
, FW_CFG_ID
, 1);
1552 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)ram_size
);
1553 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, hwdef
->machine_id
);
1554 fw_cfg_add_i16(fw_cfg
, FW_CFG_SUN4M_DEPTH
, graphic_depth
);
1555 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, KERNEL_LOAD_ADDR
);
1556 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
1557 if (kernel_cmdline
) {
1558 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
1559 pstrcpy_targphys(CMDLINE_ADDR
, TARGET_PAGE_SIZE
, kernel_cmdline
);
1561 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, 0);
1563 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, INITRD_LOAD_ADDR
);
1564 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, 0); // not used
1565 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
1566 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
1569 /* SPARCstation 2 hardware initialisation */
1570 static void ss2_init(ram_addr_t RAM_size
, int vga_ram_size
,
1571 const char *boot_device
,
1572 const char *kernel_filename
, const char *kernel_cmdline
,
1573 const char *initrd_filename
, const char *cpu_model
)
1575 sun4c_hw_init(&sun4c_hwdefs
[0], RAM_size
, boot_device
, kernel_filename
,
1576 kernel_cmdline
, initrd_filename
, cpu_model
);
1579 QEMUMachine ss2_machine
= {
1581 .desc
= "Sun4c platform, SPARCstation 2",
1583 .ram_require
= PROM_SIZE_MAX
+ TCX_SIZE
,