]> git.proxmox.com Git - qemu.git/blame - hw/sun4m.c
Introduce is_default field for QEMUMachine
[qemu.git] / hw / sun4m.c
CommitLineData
420557e8 1/*
ee76f82e 2 * QEMU Sun4m & Sun4d & Sun4c System Emulator
5fafdf24 3 *
b81b3b10 4 * Copyright (c) 2003-2005 Fabrice Bellard
5fafdf24 5 *
420557e8
FB
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
9d07d757 24#include "sysbus.h"
87ecb68b
PB
25#include "qemu-timer.h"
26#include "sun4m.h"
27#include "nvram.h"
28#include "sparc32_dma.h"
29#include "fdc.h"
30#include "sysemu.h"
31#include "net.h"
32#include "boards.h"
d2c63fc1 33#include "firmware_abi.h"
8b17de88 34#include "scsi.h"
22548760
BS
35#include "pc.h"
36#include "isa.h"
3cce6243 37#include "fw_cfg.h"
b4ed08e0 38#include "escc.h"
d2c63fc1 39
b3a23197 40//#define DEBUG_IRQ
420557e8 41
36cd9210
BS
42/*
43 * Sun4m architecture was used in the following machines:
44 *
45 * SPARCserver 6xxMP/xx
77f193da
BS
46 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
47 * SPARCclassic X (4/10)
36cd9210
BS
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
53 * SPARCstation 4
54 *
7d85892b
BS
55 * Sun4d architecture was used in the following machines:
56 *
57 * SPARCcenter 2000
58 * SPARCserver 1000
59 *
ee76f82e
BS
60 * Sun4c architecture was used in the following machines:
61 * SPARCstation 1/1+, SPARCserver 1/1+
62 * SPARCstation SLC
63 * SPARCstation IPC
64 * SPARCstation ELC
65 * SPARCstation IPX
66 *
36cd9210
BS
67 * See for example: http://www.sunhelp.org/faq/sunref1.html
68 */
69
b3a23197 70#ifdef DEBUG_IRQ
001faf32
BS
71#define DPRINTF(fmt, ...) \
72 do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0)
b3a23197 73#else
001faf32 74#define DPRINTF(fmt, ...)
b3a23197
BS
75#endif
76
420557e8 77#define KERNEL_LOAD_ADDR 0x00004000
b6f479d3 78#define CMDLINE_ADDR 0x007ff000
713c45fa 79#define INITRD_LOAD_ADDR 0x00800000
a7227727 80#define PROM_SIZE_MAX (1024 * 1024)
40ce0a9a 81#define PROM_VADDR 0xffd00000
f930d07e 82#define PROM_FILENAME "openbios-sparc32"
3cce6243 83#define CFG_ADDR 0xd00000510ULL
fbfcf955 84#define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
b8174937 85
ba3c64fb 86#define MAX_CPUS 16
b3a23197 87#define MAX_PILS 16
420557e8 88
b4ed08e0
BS
89#define ESCC_CLOCK 4915200
90
8137cde8 91struct sun4m_hwdef {
5dcb6b91
BS
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;
4c2485de 95 target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
0019ad53 96 target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base;
7eb0c8e8
BS
97 target_phys_addr_t ecc_base;
98 uint32_t ecc_version;
36cd9210 99 long vram_size, nvram_size;
6341fdcb 100 // IRQ numbers are not PIL ones, but master interrupt controller
e3a79bca 101 // register bit numbers
1572a18c 102 int esp_irq, le_irq, clock_irq, clock1_irq;
e42c20b4 103 int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq, ecc_irq;
905fdcb5
BS
104 uint8_t nvram_machine_id;
105 uint16_t machine_id;
7fbfb139 106 uint32_t iommu_version;
e0353fe2 107 uint32_t intbit_to_level[32];
3ebf5aaf
BS
108 uint64_t max_mem;
109 const char * const default_cpu_model;
36cd9210
BS
110};
111
7d85892b
BS
112#define MAX_IOUNITS 5
113
114struct sun4d_hwdef {
115 target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base;
116 target_phys_addr_t counter_base, nvram_base, ms_kb_base;
117 target_phys_addr_t serial_base;
118 target_phys_addr_t espdma_base, esp_base;
119 target_phys_addr_t ledma_base, le_base;
120 target_phys_addr_t tcx_base;
121 target_phys_addr_t sbi_base;
122 unsigned long vram_size, nvram_size;
123 // IRQ numbers are not PIL ones, but SBI register bit numbers
124 int esp_irq, le_irq, clock_irq, clock1_irq;
125 int ser_irq, ms_kb_irq, me_irq;
905fdcb5
BS
126 uint8_t nvram_machine_id;
127 uint16_t machine_id;
7d85892b
BS
128 uint32_t iounit_version;
129 uint64_t max_mem;
130 const char * const default_cpu_model;
131};
132
8137cde8
BS
133struct sun4c_hwdef {
134 target_phys_addr_t iommu_base, slavio_base;
135 target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
136 target_phys_addr_t serial_base, fd_base;
137 target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
1572a18c 138 target_phys_addr_t tcx_base, aux1_base;
8137cde8
BS
139 long vram_size, nvram_size;
140 // IRQ numbers are not PIL ones, but master interrupt controller
141 // register bit numbers
1572a18c
BS
142 int esp_irq, le_irq, clock_irq, clock1_irq;
143 int ser_irq, ms_kb_irq, fd_irq, me_irq;
8137cde8
BS
144 uint8_t nvram_machine_id;
145 uint16_t machine_id;
146 uint32_t iommu_version;
147 uint32_t intbit_to_level[32];
148 uint64_t max_mem;
149 const char * const default_cpu_model;
150};
151
6f7e9aec
FB
152int DMA_get_channel_mode (int nchan)
153{
154 return 0;
155}
156int DMA_read_memory (int nchan, void *buf, int pos, int size)
157{
158 return 0;
159}
160int DMA_write_memory (int nchan, void *buf, int pos, int size)
161{
162 return 0;
163}
164void DMA_hold_DREQ (int nchan) {}
165void DMA_release_DREQ (int nchan) {}
166void DMA_schedule(int nchan) {}
6f7e9aec
FB
167void DMA_init (int high_page_enable) {}
168void DMA_register_channel (int nchan,
169 DMA_transfer_handler transfer_handler,
170 void *opaque)
171{
172}
173
513f789f 174static int fw_cfg_boot_set(void *opaque, const char *boot_device)
81864572 175{
513f789f 176 fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
81864572
BS
177 return 0;
178}
179
819385c5 180static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
6ef05b95 181 const char *boot_devices, ram_addr_t RAM_size,
f930d07e
BS
182 uint32_t kernel_size,
183 int width, int height, int depth,
905fdcb5 184 int nvram_machine_id, const char *arch)
e80cfcfc 185{
d2c63fc1 186 unsigned int i;
66508601 187 uint32_t start, end;
d2c63fc1 188 uint8_t image[0x1ff0];
d2c63fc1
BS
189 struct OpenBIOS_nvpart_v1 *part_header;
190
191 memset(image, '\0', sizeof(image));
e80cfcfc 192
513f789f 193 start = 0;
b6f479d3 194
66508601
BS
195 // OpenBIOS nvram variables
196 // Variable partition
d2c63fc1
BS
197 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
198 part_header->signature = OPENBIOS_PART_SYSTEM;
363a37d5 199 pstrcpy(part_header->name, sizeof(part_header->name), "system");
66508601 200
d2c63fc1 201 end = start + sizeof(struct OpenBIOS_nvpart_v1);
66508601 202 for (i = 0; i < nb_prom_envs; i++)
d2c63fc1
BS
203 end = OpenBIOS_set_var(image, end, prom_envs[i]);
204
205 // End marker
206 image[end++] = '\0';
66508601 207
66508601 208 end = start + ((end - start + 15) & ~15);
d2c63fc1 209 OpenBIOS_finish_partition(part_header, end - start);
66508601
BS
210
211 // free partition
212 start = end;
d2c63fc1
BS
213 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
214 part_header->signature = OPENBIOS_PART_FREE;
363a37d5 215 pstrcpy(part_header->name, sizeof(part_header->name), "free");
66508601
BS
216
217 end = 0x1fd0;
d2c63fc1
BS
218 OpenBIOS_finish_partition(part_header, end - start);
219
905fdcb5
BS
220 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
221 nvram_machine_id);
d2c63fc1
BS
222
223 for (i = 0; i < sizeof(image); i++)
224 m48t59_write(nvram, i, image[i]);
e80cfcfc
FB
225}
226
227static void *slavio_intctl;
228
376253ec 229void pic_info(Monitor *mon)
e80cfcfc 230{
7d85892b 231 if (slavio_intctl)
376253ec 232 slavio_pic_info(mon, slavio_intctl);
e80cfcfc
FB
233}
234
376253ec 235void irq_info(Monitor *mon)
e80cfcfc 236{
7d85892b 237 if (slavio_intctl)
376253ec 238 slavio_irq_info(mon, slavio_intctl);
e80cfcfc
FB
239}
240
327ac2e7
BS
241void cpu_check_irqs(CPUState *env)
242{
243 if (env->pil_in && (env->interrupt_index == 0 ||
244 (env->interrupt_index & ~15) == TT_EXTINT)) {
245 unsigned int i;
246
247 for (i = 15; i > 0; i--) {
248 if (env->pil_in & (1 << i)) {
249 int old_interrupt = env->interrupt_index;
250
251 env->interrupt_index = TT_EXTINT | i;
f32d7ec5
BS
252 if (old_interrupt != env->interrupt_index) {
253 DPRINTF("Set CPU IRQ %d\n", i);
327ac2e7 254 cpu_interrupt(env, CPU_INTERRUPT_HARD);
f32d7ec5 255 }
327ac2e7
BS
256 break;
257 }
258 }
259 } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
f32d7ec5 260 DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
327ac2e7
BS
261 env->interrupt_index = 0;
262 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
263 }
264}
265
b3a23197
BS
266static void cpu_set_irq(void *opaque, int irq, int level)
267{
268 CPUState *env = opaque;
269
270 if (level) {
271 DPRINTF("Raise CPU IRQ %d\n", irq);
b3a23197 272 env->halted = 0;
327ac2e7
BS
273 env->pil_in |= 1 << irq;
274 cpu_check_irqs(env);
b3a23197
BS
275 } else {
276 DPRINTF("Lower CPU IRQ %d\n", irq);
327ac2e7
BS
277 env->pil_in &= ~(1 << irq);
278 cpu_check_irqs(env);
b3a23197
BS
279 }
280}
281
282static void dummy_cpu_set_irq(void *opaque, int irq, int level)
283{
284}
285
3475187d
FB
286static void *slavio_misc;
287
288void qemu_system_powerdown(void)
289{
290 slavio_set_power_fail(slavio_misc, 1);
291}
292
c68ea704
FB
293static void main_cpu_reset(void *opaque)
294{
295 CPUState *env = opaque;
3d29fbef
BS
296
297 cpu_reset(env);
298 env->halted = 0;
299}
300
301static void secondary_cpu_reset(void *opaque)
302{
303 CPUState *env = opaque;
304
c68ea704 305 cpu_reset(env);
3d29fbef 306 env->halted = 1;
c68ea704
FB
307}
308
6d0c293d
BS
309static void cpu_halt_signal(void *opaque, int irq, int level)
310{
311 if (level && cpu_single_env)
312 cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT);
313}
314
3ebf5aaf 315static unsigned long sun4m_load_kernel(const char *kernel_filename,
293f78bc
BS
316 const char *initrd_filename,
317 ram_addr_t RAM_size)
3ebf5aaf
BS
318{
319 int linux_boot;
320 unsigned int i;
321 long initrd_size, kernel_size;
322
323 linux_boot = (kernel_filename != NULL);
324
325 kernel_size = 0;
326 if (linux_boot) {
327 kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL,
328 NULL);
329 if (kernel_size < 0)
293f78bc
BS
330 kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
331 RAM_size - KERNEL_LOAD_ADDR);
3ebf5aaf 332 if (kernel_size < 0)
293f78bc
BS
333 kernel_size = load_image_targphys(kernel_filename,
334 KERNEL_LOAD_ADDR,
335 RAM_size - KERNEL_LOAD_ADDR);
3ebf5aaf
BS
336 if (kernel_size < 0) {
337 fprintf(stderr, "qemu: could not load kernel '%s'\n",
338 kernel_filename);
339 exit(1);
340 }
341
342 /* load initrd */
343 initrd_size = 0;
344 if (initrd_filename) {
293f78bc
BS
345 initrd_size = load_image_targphys(initrd_filename,
346 INITRD_LOAD_ADDR,
347 RAM_size - INITRD_LOAD_ADDR);
3ebf5aaf
BS
348 if (initrd_size < 0) {
349 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
350 initrd_filename);
351 exit(1);
352 }
353 }
354 if (initrd_size > 0) {
355 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
293f78bc
BS
356 if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
357 stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
358 stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
3ebf5aaf
BS
359 break;
360 }
361 }
362 }
363 }
364 return kernel_size;
365}
366
9d07d757
PB
367static void lance_init(NICInfo *nd, target_phys_addr_t leaddr,
368 void *dma_opaque, qemu_irq irq, qemu_irq *reset)
369{
370 DeviceState *dev;
371 SysBusDevice *s;
372
373 qemu_check_nic_model(&nd_table[0], "lance");
374
375 dev = qdev_create(NULL, "lance");
376 qdev_set_netdev(dev, nd);
377 qdev_set_prop_ptr(dev, "dma", dma_opaque);
378 qdev_init(dev);
379 s = sysbus_from_qdev(dev);
380 sysbus_mmio_map(s, 0, leaddr);
381 sysbus_connect_irq(s, 0, irq);
382 *reset = qdev_get_irq_sink(dev, 0);
383}
384
8137cde8 385static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
3ebf5aaf 386 const char *boot_device,
3023f332 387 const char *kernel_filename,
3ebf5aaf
BS
388 const char *kernel_cmdline,
389 const char *initrd_filename, const char *cpu_model)
36cd9210 390
420557e8 391{
ba3c64fb 392 CPUState *env, *envs[MAX_CPUS];
713c45fa 393 unsigned int i;
cfb9de9c 394 void *iommu, *espdma, *ledma, *nvram;
b3a23197 395 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
d7edfd27 396 *espdma_irq, *ledma_irq;
2d069bab 397 qemu_irq *esp_reset, *le_reset;
2be17ebd 398 qemu_irq *fdc_tc;
6d0c293d 399 qemu_irq *cpu_halt;
dc828ca1 400 ram_addr_t ram_offset, prom_offset, idreg_offset;
5c6602c5 401 unsigned long kernel_size;
3ebf5aaf
BS
402 int ret;
403 char buf[1024];
e4bcb14c 404 BlockDriverState *fd[MAX_FD];
22548760 405 int drive_index;
3cce6243 406 void *fw_cfg;
420557e8 407
ba3c64fb 408 /* init CPUs */
3ebf5aaf
BS
409 if (!cpu_model)
410 cpu_model = hwdef->default_cpu_model;
b3a23197 411
ba3c64fb 412 for(i = 0; i < smp_cpus; i++) {
aaed909a
FB
413 env = cpu_init(cpu_model);
414 if (!env) {
8e82c6a8 415 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
aaed909a
FB
416 exit(1);
417 }
418 cpu_sparc_set_id(env, i);
ba3c64fb 419 envs[i] = env;
3d29fbef
BS
420 if (i == 0) {
421 qemu_register_reset(main_cpu_reset, env);
422 } else {
423 qemu_register_reset(secondary_cpu_reset, env);
ba3c64fb 424 env->halted = 1;
3d29fbef 425 }
b3a23197 426 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
3ebf5aaf 427 env->prom_addr = hwdef->slavio_base;
ba3c64fb 428 }
b3a23197
BS
429
430 for (i = smp_cpus; i < MAX_CPUS; i++)
431 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
432
3ebf5aaf 433
420557e8 434 /* allocate RAM */
3ebf5aaf 435 if ((uint64_t)RAM_size > hwdef->max_mem) {
77f193da
BS
436 fprintf(stderr,
437 "qemu: Too much memory for this machine: %d, maximum %d\n",
6ef05b95 438 (unsigned int)(RAM_size / (1024 * 1024)),
3ebf5aaf
BS
439 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
440 exit(1);
441 }
5c6602c5
BS
442 ram_offset = qemu_ram_alloc(RAM_size);
443 cpu_register_physical_memory(0, RAM_size, ram_offset);
420557e8 444
3ebf5aaf 445 /* load boot prom */
5c6602c5 446 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
3ebf5aaf
BS
447 cpu_register_physical_memory(hwdef->slavio_base,
448 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
449 TARGET_PAGE_MASK,
450 prom_offset | IO_MEM_ROM);
451
452 if (bios_name == NULL)
453 bios_name = PROM_FILENAME;
454 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
455 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
456 if (ret < 0 || ret > PROM_SIZE_MAX)
e01f4a1c 457 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
3ebf5aaf
BS
458 if (ret < 0 || ret > PROM_SIZE_MAX) {
459 fprintf(stderr, "qemu: could not load prom '%s'\n",
460 buf);
461 exit(1);
462 }
463
464 /* set up devices */
36cd9210 465 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
5dcb6b91 466 hwdef->intctl_base + 0x10000ULL,
d537cf6c 467 &hwdef->intbit_to_level[0],
d7edfd27 468 &slavio_irq, &slavio_cpu_irq,
b3a23197 469 cpu_irqs,
d7edfd27 470 hwdef->clock_irq);
b3a23197 471
fe096129 472 if (hwdef->idreg_base) {
293f78bc 473 static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
4c2485de 474
5c6602c5 475 idreg_offset = qemu_ram_alloc(sizeof(idreg_data));
293f78bc 476 cpu_register_physical_memory(hwdef->idreg_base, sizeof(idreg_data),
5c6602c5 477 idreg_offset | IO_MEM_ROM);
293f78bc
BS
478 cpu_physical_memory_write_rom(hwdef->idreg_base, idreg_data,
479 sizeof(idreg_data));
4c2485de
BS
480 }
481
ff403da6
BS
482 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
483 slavio_irq[hwdef->me_irq]);
484
5aca8c3b 485 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
2d069bab
BS
486 iommu, &espdma_irq, &esp_reset);
487
5aca8c3b 488 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
2d069bab
BS
489 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
490 &le_reset);
ba3c64fb 491
eee0b836
BS
492 if (graphic_depth != 8 && graphic_depth != 24) {
493 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
494 exit (1);
495 }
dc828ca1
PB
496 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
497 graphic_depth);
dbe06e18 498
0ae18cee 499 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
dbe06e18 500
d537cf6c
PB
501 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
502 hwdef->nvram_size, 8);
81732d19
BS
503
504 slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq],
19f8e5dd 505 slavio_cpu_irq, smp_cpus);
81732d19 506
577390ff 507 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
993fbfdb 508 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
b81b3b10
FB
509 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
510 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
aeeb69c7
AJ
511 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], slavio_irq[hwdef->ser_irq],
512 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
741402f9 513
6d0c293d 514 cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
2be17ebd
BS
515 slavio_misc = slavio_misc_init(hwdef->slavio_base, hwdef->apc_base,
516 hwdef->aux1_base, hwdef->aux2_base,
6d0c293d 517 slavio_irq[hwdef->me_irq], cpu_halt[0],
2be17ebd
BS
518 &fdc_tc);
519
fe096129 520 if (hwdef->fd_base) {
e4bcb14c 521 /* there is zero or one floppy drive */
309e60bd 522 memset(fd, 0, sizeof(fd));
22548760
BS
523 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
524 if (drive_index != -1)
525 fd[0] = drives_table[drive_index].bdrv;
2d069bab 526
2be17ebd
BS
527 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
528 fdc_tc);
e4bcb14c
TS
529 }
530
531 if (drive_get_max_bus(IF_SCSI) > 0) {
532 fprintf(stderr, "qemu: too many SCSI bus\n");
533 exit(1);
534 }
535
cfb9de9c
PB
536 esp_init(hwdef->esp_base, 2,
537 espdma_memory_read, espdma_memory_write,
538 espdma, *espdma_irq, esp_reset);
f1587550 539
fe096129 540 if (hwdef->cs_base)
803b3c7b 541 cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl);
b3ceef24 542
293f78bc
BS
543 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
544 RAM_size);
36cd9210 545
36cd9210 546 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
b3ceef24 547 boot_device, RAM_size, kernel_size, graphic_width,
905fdcb5
BS
548 graphic_height, graphic_depth, hwdef->nvram_machine_id,
549 "Sun4m");
7eb0c8e8 550
fe096129 551 if (hwdef->ecc_base)
e42c20b4
BS
552 ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
553 hwdef->ecc_version);
3cce6243
BS
554
555 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
556 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
905fdcb5
BS
557 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
558 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
fbfcf955 559 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
513f789f
BS
560 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
561 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
562 if (kernel_cmdline) {
563 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
564 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
565 } else {
566 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
567 }
568 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
569 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
570 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
571 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
36cd9210
BS
572}
573
905fdcb5
BS
574enum {
575 ss2_id = 0,
576 ss5_id = 32,
577 vger_id,
578 lx_id,
579 ss4_id,
580 scls_id,
581 sbook_id,
582 ss10_id = 64,
583 ss20_id,
584 ss600mp_id,
585 ss1000_id = 96,
586 ss2000_id,
587};
588
8137cde8 589static const struct sun4m_hwdef sun4m_hwdefs[] = {
36cd9210
BS
590 /* SS-5 */
591 {
592 .iommu_base = 0x10000000,
593 .tcx_base = 0x50000000,
594 .cs_base = 0x6c000000,
384ccb5d 595 .slavio_base = 0x70000000,
36cd9210
BS
596 .ms_kb_base = 0x71000000,
597 .serial_base = 0x71100000,
598 .nvram_base = 0x71200000,
599 .fd_base = 0x71400000,
600 .counter_base = 0x71d00000,
601 .intctl_base = 0x71e00000,
4c2485de 602 .idreg_base = 0x78000000,
36cd9210
BS
603 .dma_base = 0x78400000,
604 .esp_base = 0x78800000,
605 .le_base = 0x78c00000,
127fc407 606 .apc_base = 0x6a000000,
0019ad53
BS
607 .aux1_base = 0x71900000,
608 .aux2_base = 0x71910000,
36cd9210
BS
609 .vram_size = 0x00100000,
610 .nvram_size = 0x2000,
611 .esp_irq = 18,
612 .le_irq = 16,
e3a79bca 613 .clock_irq = 7,
36cd9210
BS
614 .clock1_irq = 19,
615 .ms_kb_irq = 14,
616 .ser_irq = 15,
617 .fd_irq = 22,
618 .me_irq = 30,
619 .cs_irq = 5,
905fdcb5
BS
620 .nvram_machine_id = 0x80,
621 .machine_id = ss5_id,
cf3102ac 622 .iommu_version = 0x05000000,
e0353fe2 623 .intbit_to_level = {
f930d07e
BS
624 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
625 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
e0353fe2 626 },
3ebf5aaf
BS
627 .max_mem = 0x10000000,
628 .default_cpu_model = "Fujitsu MB86904",
e0353fe2
BS
629 },
630 /* SS-10 */
e0353fe2 631 {
5dcb6b91
BS
632 .iommu_base = 0xfe0000000ULL,
633 .tcx_base = 0xe20000000ULL,
5dcb6b91
BS
634 .slavio_base = 0xff0000000ULL,
635 .ms_kb_base = 0xff1000000ULL,
636 .serial_base = 0xff1100000ULL,
637 .nvram_base = 0xff1200000ULL,
638 .fd_base = 0xff1700000ULL,
639 .counter_base = 0xff1300000ULL,
640 .intctl_base = 0xff1400000ULL,
4c2485de 641 .idreg_base = 0xef0000000ULL,
5dcb6b91
BS
642 .dma_base = 0xef0400000ULL,
643 .esp_base = 0xef0800000ULL,
644 .le_base = 0xef0c00000ULL,
0019ad53 645 .apc_base = 0xefa000000ULL, // XXX should not exist
127fc407
BS
646 .aux1_base = 0xff1800000ULL,
647 .aux2_base = 0xff1a01000ULL,
7eb0c8e8
BS
648 .ecc_base = 0xf00000000ULL,
649 .ecc_version = 0x10000000, // version 0, implementation 1
e0353fe2
BS
650 .vram_size = 0x00100000,
651 .nvram_size = 0x2000,
652 .esp_irq = 18,
653 .le_irq = 16,
e3a79bca 654 .clock_irq = 7,
e0353fe2
BS
655 .clock1_irq = 19,
656 .ms_kb_irq = 14,
657 .ser_irq = 15,
658 .fd_irq = 22,
659 .me_irq = 30,
e42c20b4 660 .ecc_irq = 28,
905fdcb5
BS
661 .nvram_machine_id = 0x72,
662 .machine_id = ss10_id,
7fbfb139 663 .iommu_version = 0x03000000,
e0353fe2 664 .intbit_to_level = {
f930d07e
BS
665 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
666 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
e0353fe2 667 },
6ef05b95 668 .max_mem = 0xf00000000ULL,
3ebf5aaf 669 .default_cpu_model = "TI SuperSparc II",
36cd9210 670 },
6a3b9cc9
BS
671 /* SS-600MP */
672 {
673 .iommu_base = 0xfe0000000ULL,
674 .tcx_base = 0xe20000000ULL,
6a3b9cc9
BS
675 .slavio_base = 0xff0000000ULL,
676 .ms_kb_base = 0xff1000000ULL,
677 .serial_base = 0xff1100000ULL,
678 .nvram_base = 0xff1200000ULL,
6a3b9cc9
BS
679 .counter_base = 0xff1300000ULL,
680 .intctl_base = 0xff1400000ULL,
681 .dma_base = 0xef0081000ULL,
682 .esp_base = 0xef0080000ULL,
683 .le_base = 0xef0060000ULL,
0019ad53 684 .apc_base = 0xefa000000ULL, // XXX should not exist
127fc407
BS
685 .aux1_base = 0xff1800000ULL,
686 .aux2_base = 0xff1a01000ULL, // XXX should not exist
7eb0c8e8
BS
687 .ecc_base = 0xf00000000ULL,
688 .ecc_version = 0x00000000, // version 0, implementation 0
6a3b9cc9
BS
689 .vram_size = 0x00100000,
690 .nvram_size = 0x2000,
691 .esp_irq = 18,
692 .le_irq = 16,
e3a79bca 693 .clock_irq = 7,
6a3b9cc9
BS
694 .clock1_irq = 19,
695 .ms_kb_irq = 14,
696 .ser_irq = 15,
697 .fd_irq = 22,
698 .me_irq = 30,
e42c20b4 699 .ecc_irq = 28,
905fdcb5
BS
700 .nvram_machine_id = 0x71,
701 .machine_id = ss600mp_id,
7fbfb139 702 .iommu_version = 0x01000000,
6a3b9cc9
BS
703 .intbit_to_level = {
704 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
705 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
706 },
6ef05b95 707 .max_mem = 0xf00000000ULL,
3ebf5aaf 708 .default_cpu_model = "TI SuperSparc II",
6a3b9cc9 709 },
ae40972f
BS
710 /* SS-20 */
711 {
712 .iommu_base = 0xfe0000000ULL,
713 .tcx_base = 0xe20000000ULL,
ae40972f
BS
714 .slavio_base = 0xff0000000ULL,
715 .ms_kb_base = 0xff1000000ULL,
716 .serial_base = 0xff1100000ULL,
717 .nvram_base = 0xff1200000ULL,
718 .fd_base = 0xff1700000ULL,
719 .counter_base = 0xff1300000ULL,
720 .intctl_base = 0xff1400000ULL,
4c2485de 721 .idreg_base = 0xef0000000ULL,
ae40972f
BS
722 .dma_base = 0xef0400000ULL,
723 .esp_base = 0xef0800000ULL,
724 .le_base = 0xef0c00000ULL,
0019ad53 725 .apc_base = 0xefa000000ULL, // XXX should not exist
577d8dd4
BS
726 .aux1_base = 0xff1800000ULL,
727 .aux2_base = 0xff1a01000ULL,
ae40972f
BS
728 .ecc_base = 0xf00000000ULL,
729 .ecc_version = 0x20000000, // version 0, implementation 2
730 .vram_size = 0x00100000,
731 .nvram_size = 0x2000,
732 .esp_irq = 18,
733 .le_irq = 16,
e3a79bca 734 .clock_irq = 7,
ae40972f
BS
735 .clock1_irq = 19,
736 .ms_kb_irq = 14,
737 .ser_irq = 15,
738 .fd_irq = 22,
739 .me_irq = 30,
e42c20b4 740 .ecc_irq = 28,
905fdcb5
BS
741 .nvram_machine_id = 0x72,
742 .machine_id = ss20_id,
ae40972f
BS
743 .iommu_version = 0x13000000,
744 .intbit_to_level = {
745 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
746 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
747 },
6ef05b95 748 .max_mem = 0xf00000000ULL,
ae40972f
BS
749 .default_cpu_model = "TI SuperSparc II",
750 },
a526a31c
BS
751 /* Voyager */
752 {
753 .iommu_base = 0x10000000,
754 .tcx_base = 0x50000000,
a526a31c
BS
755 .slavio_base = 0x70000000,
756 .ms_kb_base = 0x71000000,
757 .serial_base = 0x71100000,
758 .nvram_base = 0x71200000,
759 .fd_base = 0x71400000,
760 .counter_base = 0x71d00000,
761 .intctl_base = 0x71e00000,
762 .idreg_base = 0x78000000,
763 .dma_base = 0x78400000,
764 .esp_base = 0x78800000,
765 .le_base = 0x78c00000,
766 .apc_base = 0x71300000, // pmc
767 .aux1_base = 0x71900000,
768 .aux2_base = 0x71910000,
a526a31c
BS
769 .vram_size = 0x00100000,
770 .nvram_size = 0x2000,
771 .esp_irq = 18,
772 .le_irq = 16,
773 .clock_irq = 7,
774 .clock1_irq = 19,
775 .ms_kb_irq = 14,
776 .ser_irq = 15,
777 .fd_irq = 22,
778 .me_irq = 30,
905fdcb5
BS
779 .nvram_machine_id = 0x80,
780 .machine_id = vger_id,
a526a31c
BS
781 .iommu_version = 0x05000000,
782 .intbit_to_level = {
783 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
784 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
785 },
786 .max_mem = 0x10000000,
787 .default_cpu_model = "Fujitsu MB86904",
788 },
789 /* LX */
790 {
791 .iommu_base = 0x10000000,
792 .tcx_base = 0x50000000,
a526a31c
BS
793 .slavio_base = 0x70000000,
794 .ms_kb_base = 0x71000000,
795 .serial_base = 0x71100000,
796 .nvram_base = 0x71200000,
797 .fd_base = 0x71400000,
798 .counter_base = 0x71d00000,
799 .intctl_base = 0x71e00000,
800 .idreg_base = 0x78000000,
801 .dma_base = 0x78400000,
802 .esp_base = 0x78800000,
803 .le_base = 0x78c00000,
a526a31c
BS
804 .aux1_base = 0x71900000,
805 .aux2_base = 0x71910000,
a526a31c
BS
806 .vram_size = 0x00100000,
807 .nvram_size = 0x2000,
808 .esp_irq = 18,
809 .le_irq = 16,
810 .clock_irq = 7,
811 .clock1_irq = 19,
812 .ms_kb_irq = 14,
813 .ser_irq = 15,
814 .fd_irq = 22,
815 .me_irq = 30,
905fdcb5
BS
816 .nvram_machine_id = 0x80,
817 .machine_id = lx_id,
a526a31c
BS
818 .iommu_version = 0x04000000,
819 .intbit_to_level = {
820 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
821 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
822 },
823 .max_mem = 0x10000000,
824 .default_cpu_model = "TI MicroSparc I",
825 },
826 /* SS-4 */
827 {
828 .iommu_base = 0x10000000,
829 .tcx_base = 0x50000000,
830 .cs_base = 0x6c000000,
831 .slavio_base = 0x70000000,
832 .ms_kb_base = 0x71000000,
833 .serial_base = 0x71100000,
834 .nvram_base = 0x71200000,
835 .fd_base = 0x71400000,
836 .counter_base = 0x71d00000,
837 .intctl_base = 0x71e00000,
838 .idreg_base = 0x78000000,
839 .dma_base = 0x78400000,
840 .esp_base = 0x78800000,
841 .le_base = 0x78c00000,
842 .apc_base = 0x6a000000,
843 .aux1_base = 0x71900000,
844 .aux2_base = 0x71910000,
a526a31c
BS
845 .vram_size = 0x00100000,
846 .nvram_size = 0x2000,
847 .esp_irq = 18,
848 .le_irq = 16,
849 .clock_irq = 7,
850 .clock1_irq = 19,
851 .ms_kb_irq = 14,
852 .ser_irq = 15,
853 .fd_irq = 22,
854 .me_irq = 30,
855 .cs_irq = 5,
905fdcb5
BS
856 .nvram_machine_id = 0x80,
857 .machine_id = ss4_id,
a526a31c
BS
858 .iommu_version = 0x05000000,
859 .intbit_to_level = {
860 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
861 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
862 },
863 .max_mem = 0x10000000,
864 .default_cpu_model = "Fujitsu MB86904",
865 },
866 /* SPARCClassic */
867 {
868 .iommu_base = 0x10000000,
869 .tcx_base = 0x50000000,
a526a31c
BS
870 .slavio_base = 0x70000000,
871 .ms_kb_base = 0x71000000,
872 .serial_base = 0x71100000,
873 .nvram_base = 0x71200000,
874 .fd_base = 0x71400000,
875 .counter_base = 0x71d00000,
876 .intctl_base = 0x71e00000,
877 .idreg_base = 0x78000000,
878 .dma_base = 0x78400000,
879 .esp_base = 0x78800000,
880 .le_base = 0x78c00000,
881 .apc_base = 0x6a000000,
882 .aux1_base = 0x71900000,
883 .aux2_base = 0x71910000,
a526a31c
BS
884 .vram_size = 0x00100000,
885 .nvram_size = 0x2000,
886 .esp_irq = 18,
887 .le_irq = 16,
888 .clock_irq = 7,
889 .clock1_irq = 19,
890 .ms_kb_irq = 14,
891 .ser_irq = 15,
892 .fd_irq = 22,
893 .me_irq = 30,
905fdcb5
BS
894 .nvram_machine_id = 0x80,
895 .machine_id = scls_id,
a526a31c
BS
896 .iommu_version = 0x05000000,
897 .intbit_to_level = {
898 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
899 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
900 },
901 .max_mem = 0x10000000,
902 .default_cpu_model = "TI MicroSparc I",
903 },
904 /* SPARCbook */
905 {
906 .iommu_base = 0x10000000,
907 .tcx_base = 0x50000000, // XXX
a526a31c
BS
908 .slavio_base = 0x70000000,
909 .ms_kb_base = 0x71000000,
910 .serial_base = 0x71100000,
911 .nvram_base = 0x71200000,
912 .fd_base = 0x71400000,
913 .counter_base = 0x71d00000,
914 .intctl_base = 0x71e00000,
915 .idreg_base = 0x78000000,
916 .dma_base = 0x78400000,
917 .esp_base = 0x78800000,
918 .le_base = 0x78c00000,
919 .apc_base = 0x6a000000,
920 .aux1_base = 0x71900000,
921 .aux2_base = 0x71910000,
a526a31c
BS
922 .vram_size = 0x00100000,
923 .nvram_size = 0x2000,
924 .esp_irq = 18,
925 .le_irq = 16,
926 .clock_irq = 7,
927 .clock1_irq = 19,
928 .ms_kb_irq = 14,
929 .ser_irq = 15,
930 .fd_irq = 22,
931 .me_irq = 30,
905fdcb5
BS
932 .nvram_machine_id = 0x80,
933 .machine_id = sbook_id,
a526a31c
BS
934 .iommu_version = 0x05000000,
935 .intbit_to_level = {
936 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
937 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
938 },
939 .max_mem = 0x10000000,
940 .default_cpu_model = "TI MicroSparc I",
941 },
36cd9210
BS
942};
943
36cd9210 944/* SPARCstation 5 hardware initialisation */
fbe1b595 945static void ss5_init(ram_addr_t RAM_size,
3023f332 946 const char *boot_device,
b881c2c6
BS
947 const char *kernel_filename, const char *kernel_cmdline,
948 const char *initrd_filename, const char *cpu_model)
36cd9210 949{
3023f332 950 sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
3ebf5aaf 951 kernel_cmdline, initrd_filename, cpu_model);
420557e8 952}
c0e564d5 953
e0353fe2 954/* SPARCstation 10 hardware initialisation */
fbe1b595 955static void ss10_init(ram_addr_t RAM_size,
3023f332 956 const char *boot_device,
b881c2c6
BS
957 const char *kernel_filename, const char *kernel_cmdline,
958 const char *initrd_filename, const char *cpu_model)
e0353fe2 959{
3023f332 960 sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
3ebf5aaf 961 kernel_cmdline, initrd_filename, cpu_model);
e0353fe2
BS
962}
963
6a3b9cc9 964/* SPARCserver 600MP hardware initialisation */
fbe1b595 965static void ss600mp_init(ram_addr_t RAM_size,
3023f332 966 const char *boot_device,
77f193da
BS
967 const char *kernel_filename,
968 const char *kernel_cmdline,
6a3b9cc9
BS
969 const char *initrd_filename, const char *cpu_model)
970{
3023f332 971 sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
3ebf5aaf 972 kernel_cmdline, initrd_filename, cpu_model);
6a3b9cc9
BS
973}
974
ae40972f 975/* SPARCstation 20 hardware initialisation */
fbe1b595 976static void ss20_init(ram_addr_t RAM_size,
3023f332 977 const char *boot_device,
ae40972f
BS
978 const char *kernel_filename, const char *kernel_cmdline,
979 const char *initrd_filename, const char *cpu_model)
980{
3023f332 981 sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
ee76f82e
BS
982 kernel_cmdline, initrd_filename, cpu_model);
983}
984
a526a31c 985/* SPARCstation Voyager hardware initialisation */
fbe1b595 986static void vger_init(ram_addr_t RAM_size,
3023f332 987 const char *boot_device,
a526a31c
BS
988 const char *kernel_filename, const char *kernel_cmdline,
989 const char *initrd_filename, const char *cpu_model)
990{
3023f332 991 sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
a526a31c
BS
992 kernel_cmdline, initrd_filename, cpu_model);
993}
994
995/* SPARCstation LX hardware initialisation */
fbe1b595 996static void ss_lx_init(ram_addr_t RAM_size,
3023f332 997 const char *boot_device,
a526a31c
BS
998 const char *kernel_filename, const char *kernel_cmdline,
999 const char *initrd_filename, const char *cpu_model)
1000{
3023f332 1001 sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1002 kernel_cmdline, initrd_filename, cpu_model);
1003}
1004
1005/* SPARCstation 4 hardware initialisation */
fbe1b595 1006static void ss4_init(ram_addr_t RAM_size,
3023f332 1007 const char *boot_device,
a526a31c
BS
1008 const char *kernel_filename, const char *kernel_cmdline,
1009 const char *initrd_filename, const char *cpu_model)
1010{
3023f332 1011 sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1012 kernel_cmdline, initrd_filename, cpu_model);
1013}
1014
1015/* SPARCClassic hardware initialisation */
fbe1b595 1016static void scls_init(ram_addr_t RAM_size,
3023f332 1017 const char *boot_device,
a526a31c
BS
1018 const char *kernel_filename, const char *kernel_cmdline,
1019 const char *initrd_filename, const char *cpu_model)
1020{
3023f332 1021 sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1022 kernel_cmdline, initrd_filename, cpu_model);
1023}
1024
1025/* SPARCbook hardware initialisation */
fbe1b595 1026static void sbook_init(ram_addr_t RAM_size,
3023f332 1027 const char *boot_device,
a526a31c
BS
1028 const char *kernel_filename, const char *kernel_cmdline,
1029 const char *initrd_filename, const char *cpu_model)
1030{
3023f332 1031 sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1032 kernel_cmdline, initrd_filename, cpu_model);
1033}
1034
f80f9ec9 1035static QEMUMachine ss5_machine = {
66de733b
BS
1036 .name = "SS-5",
1037 .desc = "Sun4m platform, SPARCstation 5",
1038 .init = ss5_init,
c9b1ae2c 1039 .use_scsi = 1,
0c257437 1040 .is_default = 1,
c0e564d5 1041};
e0353fe2 1042
f80f9ec9 1043static QEMUMachine ss10_machine = {
66de733b
BS
1044 .name = "SS-10",
1045 .desc = "Sun4m platform, SPARCstation 10",
1046 .init = ss10_init,
c9b1ae2c 1047 .use_scsi = 1,
1bcee014 1048 .max_cpus = 4,
e0353fe2 1049};
6a3b9cc9 1050
f80f9ec9 1051static QEMUMachine ss600mp_machine = {
66de733b
BS
1052 .name = "SS-600MP",
1053 .desc = "Sun4m platform, SPARCserver 600MP",
1054 .init = ss600mp_init,
c9b1ae2c 1055 .use_scsi = 1,
1bcee014 1056 .max_cpus = 4,
6a3b9cc9 1057};
ae40972f 1058
f80f9ec9 1059static QEMUMachine ss20_machine = {
66de733b
BS
1060 .name = "SS-20",
1061 .desc = "Sun4m platform, SPARCstation 20",
1062 .init = ss20_init,
c9b1ae2c 1063 .use_scsi = 1,
1bcee014 1064 .max_cpus = 4,
ae40972f
BS
1065};
1066
f80f9ec9 1067static QEMUMachine voyager_machine = {
66de733b
BS
1068 .name = "Voyager",
1069 .desc = "Sun4m platform, SPARCstation Voyager",
1070 .init = vger_init,
c9b1ae2c 1071 .use_scsi = 1,
a526a31c
BS
1072};
1073
f80f9ec9 1074static QEMUMachine ss_lx_machine = {
66de733b
BS
1075 .name = "LX",
1076 .desc = "Sun4m platform, SPARCstation LX",
1077 .init = ss_lx_init,
c9b1ae2c 1078 .use_scsi = 1,
a526a31c
BS
1079};
1080
f80f9ec9 1081static QEMUMachine ss4_machine = {
66de733b
BS
1082 .name = "SS-4",
1083 .desc = "Sun4m platform, SPARCstation 4",
1084 .init = ss4_init,
c9b1ae2c 1085 .use_scsi = 1,
a526a31c
BS
1086};
1087
f80f9ec9 1088static QEMUMachine scls_machine = {
66de733b
BS
1089 .name = "SPARCClassic",
1090 .desc = "Sun4m platform, SPARCClassic",
1091 .init = scls_init,
c9b1ae2c 1092 .use_scsi = 1,
a526a31c
BS
1093};
1094
f80f9ec9 1095static QEMUMachine sbook_machine = {
66de733b
BS
1096 .name = "SPARCbook",
1097 .desc = "Sun4m platform, SPARCbook",
1098 .init = sbook_init,
c9b1ae2c 1099 .use_scsi = 1,
a526a31c
BS
1100};
1101
7d85892b
BS
1102static const struct sun4d_hwdef sun4d_hwdefs[] = {
1103 /* SS-1000 */
1104 {
1105 .iounit_bases = {
1106 0xfe0200000ULL,
1107 0xfe1200000ULL,
1108 0xfe2200000ULL,
1109 0xfe3200000ULL,
1110 -1,
1111 },
1112 .tcx_base = 0x820000000ULL,
1113 .slavio_base = 0xf00000000ULL,
1114 .ms_kb_base = 0xf00240000ULL,
1115 .serial_base = 0xf00200000ULL,
1116 .nvram_base = 0xf00280000ULL,
1117 .counter_base = 0xf00300000ULL,
1118 .espdma_base = 0x800081000ULL,
1119 .esp_base = 0x800080000ULL,
1120 .ledma_base = 0x800040000ULL,
1121 .le_base = 0x800060000ULL,
1122 .sbi_base = 0xf02800000ULL,
c1d00dc0 1123 .vram_size = 0x00100000,
7d85892b
BS
1124 .nvram_size = 0x2000,
1125 .esp_irq = 3,
1126 .le_irq = 4,
1127 .clock_irq = 14,
1128 .clock1_irq = 10,
1129 .ms_kb_irq = 12,
1130 .ser_irq = 12,
905fdcb5
BS
1131 .nvram_machine_id = 0x80,
1132 .machine_id = ss1000_id,
7d85892b 1133 .iounit_version = 0x03000000,
6ef05b95 1134 .max_mem = 0xf00000000ULL,
7d85892b
BS
1135 .default_cpu_model = "TI SuperSparc II",
1136 },
1137 /* SS-2000 */
1138 {
1139 .iounit_bases = {
1140 0xfe0200000ULL,
1141 0xfe1200000ULL,
1142 0xfe2200000ULL,
1143 0xfe3200000ULL,
1144 0xfe4200000ULL,
1145 },
1146 .tcx_base = 0x820000000ULL,
1147 .slavio_base = 0xf00000000ULL,
1148 .ms_kb_base = 0xf00240000ULL,
1149 .serial_base = 0xf00200000ULL,
1150 .nvram_base = 0xf00280000ULL,
1151 .counter_base = 0xf00300000ULL,
1152 .espdma_base = 0x800081000ULL,
1153 .esp_base = 0x800080000ULL,
1154 .ledma_base = 0x800040000ULL,
1155 .le_base = 0x800060000ULL,
1156 .sbi_base = 0xf02800000ULL,
c1d00dc0 1157 .vram_size = 0x00100000,
7d85892b
BS
1158 .nvram_size = 0x2000,
1159 .esp_irq = 3,
1160 .le_irq = 4,
1161 .clock_irq = 14,
1162 .clock1_irq = 10,
1163 .ms_kb_irq = 12,
1164 .ser_irq = 12,
905fdcb5
BS
1165 .nvram_machine_id = 0x80,
1166 .machine_id = ss2000_id,
7d85892b 1167 .iounit_version = 0x03000000,
6ef05b95 1168 .max_mem = 0xf00000000ULL,
7d85892b
BS
1169 .default_cpu_model = "TI SuperSparc II",
1170 },
1171};
1172
6ef05b95 1173static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
7d85892b 1174 const char *boot_device,
3023f332 1175 const char *kernel_filename,
7d85892b
BS
1176 const char *kernel_cmdline,
1177 const char *initrd_filename, const char *cpu_model)
1178{
1179 CPUState *env, *envs[MAX_CPUS];
1180 unsigned int i;
cfb9de9c 1181 void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram, *sbi;
7d85892b
BS
1182 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1183 *espdma_irq, *ledma_irq;
1184 qemu_irq *esp_reset, *le_reset;
dc828ca1 1185 ram_addr_t ram_offset, prom_offset;
5c6602c5 1186 unsigned long kernel_size;
7d85892b
BS
1187 int ret;
1188 char buf[1024];
3cce6243 1189 void *fw_cfg;
7d85892b
BS
1190
1191 /* init CPUs */
1192 if (!cpu_model)
1193 cpu_model = hwdef->default_cpu_model;
1194
1195 for (i = 0; i < smp_cpus; i++) {
1196 env = cpu_init(cpu_model);
1197 if (!env) {
8e82c6a8 1198 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
7d85892b
BS
1199 exit(1);
1200 }
1201 cpu_sparc_set_id(env, i);
1202 envs[i] = env;
1203 if (i == 0) {
1204 qemu_register_reset(main_cpu_reset, env);
1205 } else {
1206 qemu_register_reset(secondary_cpu_reset, env);
1207 env->halted = 1;
1208 }
7d85892b
BS
1209 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
1210 env->prom_addr = hwdef->slavio_base;
1211 }
1212
1213 for (i = smp_cpus; i < MAX_CPUS; i++)
1214 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1215
1216 /* allocate RAM */
1217 if ((uint64_t)RAM_size > hwdef->max_mem) {
77f193da
BS
1218 fprintf(stderr,
1219 "qemu: Too much memory for this machine: %d, maximum %d\n",
6ef05b95 1220 (unsigned int)(RAM_size / (1024 * 1024)),
7d85892b
BS
1221 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1222 exit(1);
1223 }
5c6602c5
BS
1224 ram_offset = qemu_ram_alloc(RAM_size);
1225 cpu_register_physical_memory(0, RAM_size, ram_offset);
7d85892b
BS
1226
1227 /* load boot prom */
5c6602c5 1228 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
7d85892b
BS
1229 cpu_register_physical_memory(hwdef->slavio_base,
1230 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1231 TARGET_PAGE_MASK,
1232 prom_offset | IO_MEM_ROM);
1233
1234 if (bios_name == NULL)
1235 bios_name = PROM_FILENAME;
1236 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1237 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1238 if (ret < 0 || ret > PROM_SIZE_MAX)
e01f4a1c 1239 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
7d85892b
BS
1240 if (ret < 0 || ret > PROM_SIZE_MAX) {
1241 fprintf(stderr, "qemu: could not load prom '%s'\n",
1242 buf);
1243 exit(1);
1244 }
1245
1246 /* set up devices */
1247 sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
1248
1249 for (i = 0; i < MAX_IOUNITS; i++)
1250 if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
ff403da6
BS
1251 iounits[i] = iommu_init(hwdef->iounit_bases[i],
1252 hwdef->iounit_version,
1253 sbi_irq[hwdef->me_irq]);
7d85892b
BS
1254
1255 espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq],
1256 iounits[0], &espdma_irq, &esp_reset);
1257
1258 ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq],
1259 iounits[0], &ledma_irq, &le_reset);
1260
1261 if (graphic_depth != 8 && graphic_depth != 24) {
1262 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1263 exit (1);
1264 }
dc828ca1
PB
1265 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
1266 graphic_depth);
7d85892b 1267
0ae18cee 1268 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
7d85892b
BS
1269
1270 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1271 hwdef->nvram_size, 8);
1272
1273 slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq],
1274 sbi_cpu_irq, smp_cpus);
1275
1276 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
993fbfdb 1277 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
7d85892b
BS
1278 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1279 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
aeeb69c7
AJ
1280 escc_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq], sbi_irq[hwdef->ser_irq],
1281 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
7d85892b
BS
1282
1283 if (drive_get_max_bus(IF_SCSI) > 0) {
1284 fprintf(stderr, "qemu: too many SCSI bus\n");
1285 exit(1);
1286 }
1287
cfb9de9c
PB
1288 esp_init(hwdef->esp_base, 2,
1289 espdma_memory_read, espdma_memory_write,
1290 espdma, *espdma_irq, esp_reset);
7d85892b 1291
293f78bc
BS
1292 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1293 RAM_size);
7d85892b
BS
1294
1295 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1296 boot_device, RAM_size, kernel_size, graphic_width,
905fdcb5
BS
1297 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1298 "Sun4d");
3cce6243
BS
1299
1300 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1301 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
905fdcb5
BS
1302 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1303 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
513f789f
BS
1304 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1305 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1306 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1307 if (kernel_cmdline) {
1308 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1309 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
1310 } else {
1311 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1312 }
1313 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1314 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1315 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1316 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
7d85892b
BS
1317}
1318
1319/* SPARCserver 1000 hardware initialisation */
fbe1b595 1320static void ss1000_init(ram_addr_t RAM_size,
3023f332 1321 const char *boot_device,
7d85892b
BS
1322 const char *kernel_filename, const char *kernel_cmdline,
1323 const char *initrd_filename, const char *cpu_model)
1324{
3023f332 1325 sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
7d85892b
BS
1326 kernel_cmdline, initrd_filename, cpu_model);
1327}
1328
1329/* SPARCcenter 2000 hardware initialisation */
fbe1b595 1330static void ss2000_init(ram_addr_t RAM_size,
3023f332 1331 const char *boot_device,
7d85892b
BS
1332 const char *kernel_filename, const char *kernel_cmdline,
1333 const char *initrd_filename, const char *cpu_model)
1334{
3023f332 1335 sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
7d85892b
BS
1336 kernel_cmdline, initrd_filename, cpu_model);
1337}
1338
f80f9ec9 1339static QEMUMachine ss1000_machine = {
66de733b
BS
1340 .name = "SS-1000",
1341 .desc = "Sun4d platform, SPARCserver 1000",
1342 .init = ss1000_init,
c9b1ae2c 1343 .use_scsi = 1,
1bcee014 1344 .max_cpus = 8,
7d85892b
BS
1345};
1346
f80f9ec9 1347static QEMUMachine ss2000_machine = {
66de733b
BS
1348 .name = "SS-2000",
1349 .desc = "Sun4d platform, SPARCcenter 2000",
1350 .init = ss2000_init,
c9b1ae2c 1351 .use_scsi = 1,
1bcee014 1352 .max_cpus = 20,
7d85892b 1353};
8137cde8
BS
1354
1355static const struct sun4c_hwdef sun4c_hwdefs[] = {
1356 /* SS-2 */
1357 {
1358 .iommu_base = 0xf8000000,
1359 .tcx_base = 0xfe000000,
8137cde8
BS
1360 .slavio_base = 0xf6000000,
1361 .intctl_base = 0xf5000000,
1362 .counter_base = 0xf3000000,
1363 .ms_kb_base = 0xf0000000,
1364 .serial_base = 0xf1000000,
1365 .nvram_base = 0xf2000000,
1366 .fd_base = 0xf7200000,
1367 .dma_base = 0xf8400000,
1368 .esp_base = 0xf8800000,
1369 .le_base = 0xf8c00000,
8137cde8 1370 .aux1_base = 0xf7400003,
8137cde8
BS
1371 .vram_size = 0x00100000,
1372 .nvram_size = 0x800,
1373 .esp_irq = 2,
1374 .le_irq = 3,
1375 .clock_irq = 5,
1376 .clock1_irq = 7,
1377 .ms_kb_irq = 1,
1378 .ser_irq = 1,
1379 .fd_irq = 1,
1380 .me_irq = 1,
8137cde8
BS
1381 .nvram_machine_id = 0x55,
1382 .machine_id = ss2_id,
1383 .max_mem = 0x10000000,
1384 .default_cpu_model = "Cypress CY7C601",
1385 },
1386};
1387
1388static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1389 const char *boot_device,
3023f332 1390 const char *kernel_filename,
8137cde8
BS
1391 const char *kernel_cmdline,
1392 const char *initrd_filename, const char *cpu_model)
1393{
1394 CPUState *env;
cfb9de9c 1395 void *iommu, *espdma, *ledma, *nvram;
8137cde8
BS
1396 qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
1397 qemu_irq *esp_reset, *le_reset;
1398 qemu_irq *fdc_tc;
dc828ca1 1399 ram_addr_t ram_offset, prom_offset;
5c6602c5 1400 unsigned long kernel_size;
8137cde8
BS
1401 int ret;
1402 char buf[1024];
1403 BlockDriverState *fd[MAX_FD];
1404 int drive_index;
1405 void *fw_cfg;
1406
1407 /* init CPU */
1408 if (!cpu_model)
1409 cpu_model = hwdef->default_cpu_model;
1410
1411 env = cpu_init(cpu_model);
1412 if (!env) {
1413 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1414 exit(1);
1415 }
1416
1417 cpu_sparc_set_id(env, 0);
1418
1419 qemu_register_reset(main_cpu_reset, env);
1420 cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
1421 env->prom_addr = hwdef->slavio_base;
1422
1423 /* allocate RAM */
1424 if ((uint64_t)RAM_size > hwdef->max_mem) {
1425 fprintf(stderr,
1426 "qemu: Too much memory for this machine: %d, maximum %d\n",
1427 (unsigned int)(RAM_size / (1024 * 1024)),
1428 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1429 exit(1);
1430 }
5c6602c5
BS
1431 ram_offset = qemu_ram_alloc(RAM_size);
1432 cpu_register_physical_memory(0, RAM_size, ram_offset);
8137cde8
BS
1433
1434 /* load boot prom */
5c6602c5 1435 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
8137cde8
BS
1436 cpu_register_physical_memory(hwdef->slavio_base,
1437 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1438 TARGET_PAGE_MASK,
1439 prom_offset | IO_MEM_ROM);
1440
1441 if (bios_name == NULL)
1442 bios_name = PROM_FILENAME;
1443 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1444 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1445 if (ret < 0 || ret > PROM_SIZE_MAX)
1446 ret = load_image_targphys(buf, hwdef->slavio_base, PROM_SIZE_MAX);
1447 if (ret < 0 || ret > PROM_SIZE_MAX) {
1448 fprintf(stderr, "qemu: could not load prom '%s'\n",
1449 buf);
1450 exit(1);
1451 }
8137cde8
BS
1452
1453 /* set up devices */
1454 slavio_intctl = sun4c_intctl_init(hwdef->intctl_base,
1455 &slavio_irq, cpu_irqs);
1456
1457 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
1458 slavio_irq[hwdef->me_irq]);
1459
1460 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
1461 iommu, &espdma_irq, &esp_reset);
1462
1463 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
1464 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
1465 &le_reset);
1466
1467 if (graphic_depth != 8 && graphic_depth != 24) {
1468 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1469 exit (1);
1470 }
dc828ca1
PB
1471 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
1472 graphic_depth);
8137cde8 1473
0ae18cee 1474 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
8137cde8
BS
1475
1476 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
1477 hwdef->nvram_size, 2);
1478
1479 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
993fbfdb 1480 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
8137cde8
BS
1481 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1482 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
aeeb69c7
AJ
1483 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
1484 slavio_irq[hwdef->ser_irq], serial_hds[0], serial_hds[1],
1485 ESCC_CLOCK, 1);
8137cde8 1486
fe096129 1487 slavio_misc = slavio_misc_init(0, 0, hwdef->aux1_base, 0,
6d0c293d 1488 slavio_irq[hwdef->me_irq], NULL, &fdc_tc);
8137cde8
BS
1489
1490 if (hwdef->fd_base != (target_phys_addr_t)-1) {
1491 /* there is zero or one floppy drive */
ce802585 1492 memset(fd, 0, sizeof(fd));
8137cde8
BS
1493 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
1494 if (drive_index != -1)
1495 fd[0] = drives_table[drive_index].bdrv;
1496
1497 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
1498 fdc_tc);
1499 }
1500
1501 if (drive_get_max_bus(IF_SCSI) > 0) {
1502 fprintf(stderr, "qemu: too many SCSI bus\n");
1503 exit(1);
1504 }
1505
cfb9de9c
PB
1506 esp_init(hwdef->esp_base, 2,
1507 espdma_memory_read, espdma_memory_write,
1508 espdma, *espdma_irq, esp_reset);
8137cde8
BS
1509
1510 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1511 RAM_size);
1512
1513 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1514 boot_device, RAM_size, kernel_size, graphic_width,
1515 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1516 "Sun4c");
1517
1518 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1519 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1520 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1521 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
513f789f
BS
1522 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1523 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1524 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1525 if (kernel_cmdline) {
1526 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1527 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
1528 } else {
1529 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1530 }
1531 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1532 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1533 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1534 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
8137cde8
BS
1535}
1536
1537/* SPARCstation 2 hardware initialisation */
fbe1b595 1538static void ss2_init(ram_addr_t RAM_size,
3023f332 1539 const char *boot_device,
8137cde8
BS
1540 const char *kernel_filename, const char *kernel_cmdline,
1541 const char *initrd_filename, const char *cpu_model)
1542{
3023f332 1543 sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
8137cde8
BS
1544 kernel_cmdline, initrd_filename, cpu_model);
1545}
1546
f80f9ec9 1547static QEMUMachine ss2_machine = {
8137cde8
BS
1548 .name = "SS-2",
1549 .desc = "Sun4c platform, SPARCstation 2",
1550 .init = ss2_init,
8137cde8 1551 .use_scsi = 1,
8137cde8 1552};
f80f9ec9
AL
1553
1554static void ss2_machine_init(void)
1555{
1556 qemu_register_machine(&ss5_machine);
1557 qemu_register_machine(&ss10_machine);
1558 qemu_register_machine(&ss600mp_machine);
1559 qemu_register_machine(&ss20_machine);
1560 qemu_register_machine(&voyager_machine);
1561 qemu_register_machine(&ss_lx_machine);
1562 qemu_register_machine(&ss4_machine);
1563 qemu_register_machine(&scls_machine);
1564 qemu_register_machine(&sbook_machine);
1565 qemu_register_machine(&ss1000_machine);
1566 qemu_register_machine(&ss2000_machine);
1567 qemu_register_machine(&ss2_machine);
1568}
1569
1570machine_init(ss2_machine_init);