Commit 3ebf5aafe562158b59aff2ee49cbcf54332cbb23
1 parent
9c2b428e
Use slavio base as boot prom address, rearrange sun4m init code
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3747 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
3 changed files
with
105 additions
and
109 deletions
hw/sun4m.c
... | ... | @@ -60,7 +60,6 @@ |
60 | 60 | #define CMDLINE_ADDR 0x007ff000 |
61 | 61 | #define INITRD_LOAD_ADDR 0x00800000 |
62 | 62 | #define PROM_SIZE_MAX (512 * 1024) |
63 | -#define PROM_PADDR 0xff0000000ULL | |
64 | 63 | #define PROM_VADDR 0xffd00000 |
65 | 64 | #define PROM_FILENAME "openbios-sparc32" |
66 | 65 | |
... | ... | @@ -81,6 +80,8 @@ struct hwdef { |
81 | 80 | int machine_id; // For NVRAM |
82 | 81 | uint32_t iommu_version; |
83 | 82 | uint32_t intbit_to_level[32]; |
83 | + uint64_t max_mem; | |
84 | + const char * const default_cpu_model; | |
84 | 85 | }; |
85 | 86 | |
86 | 87 | /* TSC handling */ |
... | ... | @@ -273,8 +274,59 @@ static void secondary_cpu_reset(void *opaque) |
273 | 274 | env->halted = 1; |
274 | 275 | } |
275 | 276 | |
276 | -static void *sun4m_hw_init(const struct hwdef *hwdef, int RAM_size, | |
277 | - DisplayState *ds, const char *cpu_model) | |
277 | +static unsigned long sun4m_load_kernel(const char *kernel_filename, | |
278 | + const char *kernel_cmdline, | |
279 | + const char *initrd_filename) | |
280 | +{ | |
281 | + int linux_boot; | |
282 | + unsigned int i; | |
283 | + long initrd_size, kernel_size; | |
284 | + | |
285 | + linux_boot = (kernel_filename != NULL); | |
286 | + | |
287 | + kernel_size = 0; | |
288 | + if (linux_boot) { | |
289 | + kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL, | |
290 | + NULL); | |
291 | + if (kernel_size < 0) | |
292 | + kernel_size = load_aout(kernel_filename, phys_ram_base + KERNEL_LOAD_ADDR); | |
293 | + if (kernel_size < 0) | |
294 | + kernel_size = load_image(kernel_filename, phys_ram_base + KERNEL_LOAD_ADDR); | |
295 | + if (kernel_size < 0) { | |
296 | + fprintf(stderr, "qemu: could not load kernel '%s'\n", | |
297 | + kernel_filename); | |
298 | + exit(1); | |
299 | + } | |
300 | + | |
301 | + /* load initrd */ | |
302 | + initrd_size = 0; | |
303 | + if (initrd_filename) { | |
304 | + initrd_size = load_image(initrd_filename, phys_ram_base + INITRD_LOAD_ADDR); | |
305 | + if (initrd_size < 0) { | |
306 | + fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", | |
307 | + initrd_filename); | |
308 | + exit(1); | |
309 | + } | |
310 | + } | |
311 | + if (initrd_size > 0) { | |
312 | + for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { | |
313 | + if (ldl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i) | |
314 | + == 0x48647253) { // HdrS | |
315 | + stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR); | |
316 | + stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 20, initrd_size); | |
317 | + break; | |
318 | + } | |
319 | + } | |
320 | + } | |
321 | + } | |
322 | + return kernel_size; | |
323 | +} | |
324 | + | |
325 | +static void sun4m_hw_init(const struct hwdef *hwdef, int RAM_size, | |
326 | + const char *boot_device, | |
327 | + DisplayState *ds, const char *kernel_filename, | |
328 | + const char *kernel_cmdline, | |
329 | + const char *initrd_filename, const char *cpu_model) | |
278 | 330 | |
279 | 331 | { |
280 | 332 | CPUState *env, *envs[MAX_CPUS]; |
... | ... | @@ -283,8 +335,13 @@ static void *sun4m_hw_init(const struct hwdef *hwdef, int RAM_size, |
283 | 335 | qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq, |
284 | 336 | *espdma_irq, *ledma_irq; |
285 | 337 | qemu_irq *esp_reset, *le_reset; |
338 | + unsigned long prom_offset, kernel_size; | |
339 | + int ret; | |
340 | + char buf[1024]; | |
286 | 341 | |
287 | 342 | /* init CPUs */ |
343 | + if (!cpu_model) | |
344 | + cpu_model = hwdef->default_cpu_model; | |
288 | 345 | |
289 | 346 | for(i = 0; i < smp_cpus; i++) { |
290 | 347 | env = cpu_init(cpu_model); |
... | ... | @@ -302,14 +359,42 @@ static void *sun4m_hw_init(const struct hwdef *hwdef, int RAM_size, |
302 | 359 | } |
303 | 360 | register_savevm("cpu", i, 3, cpu_save, cpu_load, env); |
304 | 361 | cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS); |
362 | + env->prom_addr = hwdef->slavio_base; | |
305 | 363 | } |
306 | 364 | |
307 | 365 | for (i = smp_cpus; i < MAX_CPUS; i++) |
308 | 366 | cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS); |
309 | 367 | |
368 | + | |
310 | 369 | /* allocate RAM */ |
370 | + if ((uint64_t)RAM_size > hwdef->max_mem) { | |
371 | + fprintf(stderr, "qemu: Too much memory for this machine: %d, maximum %d\n", | |
372 | + (unsigned int)RAM_size / (1024 * 1024), | |
373 | + (unsigned int)(hwdef->max_mem / (1024 * 1024))); | |
374 | + exit(1); | |
375 | + } | |
311 | 376 | cpu_register_physical_memory(0, RAM_size, 0); |
312 | 377 | |
378 | + /* load boot prom */ | |
379 | + prom_offset = RAM_size + hwdef->vram_size; | |
380 | + cpu_register_physical_memory(hwdef->slavio_base, | |
381 | + (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) & | |
382 | + TARGET_PAGE_MASK, | |
383 | + prom_offset | IO_MEM_ROM); | |
384 | + | |
385 | + if (bios_name == NULL) | |
386 | + bios_name = PROM_FILENAME; | |
387 | + snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); | |
388 | + ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL); | |
389 | + if (ret < 0 || ret > PROM_SIZE_MAX) | |
390 | + ret = load_image(buf, phys_ram_base + prom_offset); | |
391 | + if (ret < 0 || ret > PROM_SIZE_MAX) { | |
392 | + fprintf(stderr, "qemu: could not load prom '%s'\n", | |
393 | + buf); | |
394 | + exit(1); | |
395 | + } | |
396 | + | |
397 | + /* set up devices */ | |
313 | 398 | iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version); |
314 | 399 | slavio_intctl = slavio_intctl_init(hwdef->intctl_base, |
315 | 400 | hwdef->intctl_base + 0x10000ULL, |
... | ... | @@ -372,79 +457,12 @@ static void *sun4m_hw_init(const struct hwdef *hwdef, int RAM_size, |
372 | 457 | if (hwdef->cs_base != (target_phys_addr_t)-1) |
373 | 458 | cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl); |
374 | 459 | |
375 | - return nvram; | |
376 | -} | |
460 | + kernel_size = sun4m_load_kernel(kernel_filename, kernel_cmdline, | |
461 | + initrd_filename); | |
377 | 462 | |
378 | -static void sun4m_load_kernel(long vram_size, int RAM_size, | |
379 | - const char *boot_device, | |
380 | - const char *kernel_filename, | |
381 | - const char *kernel_cmdline, | |
382 | - const char *initrd_filename, | |
383 | - int machine_id, | |
384 | - void *nvram) | |
385 | -{ | |
386 | - int ret, linux_boot; | |
387 | - char buf[1024]; | |
388 | - unsigned int i; | |
389 | - long prom_offset, initrd_size, kernel_size; | |
390 | - | |
391 | - linux_boot = (kernel_filename != NULL); | |
392 | - | |
393 | - prom_offset = RAM_size + vram_size; | |
394 | - cpu_register_physical_memory(PROM_PADDR, | |
395 | - (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK, | |
396 | - prom_offset | IO_MEM_ROM); | |
397 | - | |
398 | - if (bios_name == NULL) | |
399 | - bios_name = PROM_FILENAME; | |
400 | - snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); | |
401 | - ret = load_elf(buf, PROM_PADDR - PROM_VADDR, NULL, NULL, NULL); | |
402 | - if (ret < 0 || ret > PROM_SIZE_MAX) | |
403 | - ret = load_image(buf, phys_ram_base + prom_offset); | |
404 | - if (ret < 0 || ret > PROM_SIZE_MAX) { | |
405 | - fprintf(stderr, "qemu: could not load prom '%s'\n", | |
406 | - buf); | |
407 | - exit(1); | |
408 | - } | |
409 | - | |
410 | - kernel_size = 0; | |
411 | - if (linux_boot) { | |
412 | - kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL, | |
413 | - NULL); | |
414 | - if (kernel_size < 0) | |
415 | - kernel_size = load_aout(kernel_filename, phys_ram_base + KERNEL_LOAD_ADDR); | |
416 | - if (kernel_size < 0) | |
417 | - kernel_size = load_image(kernel_filename, phys_ram_base + KERNEL_LOAD_ADDR); | |
418 | - if (kernel_size < 0) { | |
419 | - fprintf(stderr, "qemu: could not load kernel '%s'\n", | |
420 | - kernel_filename); | |
421 | - exit(1); | |
422 | - } | |
423 | - | |
424 | - /* load initrd */ | |
425 | - initrd_size = 0; | |
426 | - if (initrd_filename) { | |
427 | - initrd_size = load_image(initrd_filename, phys_ram_base + INITRD_LOAD_ADDR); | |
428 | - if (initrd_size < 0) { | |
429 | - fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", | |
430 | - initrd_filename); | |
431 | - exit(1); | |
432 | - } | |
433 | - } | |
434 | - if (initrd_size > 0) { | |
435 | - for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { | |
436 | - if (ldl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i) | |
437 | - == 0x48647253) { // HdrS | |
438 | - stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR); | |
439 | - stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 20, initrd_size); | |
440 | - break; | |
441 | - } | |
442 | - } | |
443 | - } | |
444 | - } | |
445 | 463 | nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline, |
446 | 464 | boot_device, RAM_size, kernel_size, graphic_width, |
447 | - graphic_height, graphic_depth, machine_id); | |
465 | + graphic_height, graphic_depth, hwdef->machine_id); | |
448 | 466 | } |
449 | 467 | |
450 | 468 | static const struct hwdef hwdefs[] = { |
... | ... | @@ -481,6 +499,8 @@ static const struct hwdef hwdefs[] = { |
481 | 499 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, |
482 | 500 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, |
483 | 501 | }, |
502 | + .max_mem = 0x10000000, | |
503 | + .default_cpu_model = "Fujitsu MB86904", | |
484 | 504 | }, |
485 | 505 | /* SS-10 */ |
486 | 506 | { |
... | ... | @@ -515,6 +535,8 @@ static const struct hwdef hwdefs[] = { |
515 | 535 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, |
516 | 536 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, |
517 | 537 | }, |
538 | + .max_mem = 0xffffffff, // XXX actually first 62GB ok | |
539 | + .default_cpu_model = "TI SuperSparc II", | |
518 | 540 | }, |
519 | 541 | /* SS-600MP */ |
520 | 542 | { |
... | ... | @@ -549,40 +571,19 @@ static const struct hwdef hwdefs[] = { |
549 | 571 | 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12, |
550 | 572 | 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0, |
551 | 573 | }, |
574 | + .max_mem = 0xffffffff, // XXX actually first 62GB ok | |
575 | + .default_cpu_model = "TI SuperSparc II", | |
552 | 576 | }, |
553 | 577 | }; |
554 | 578 | |
555 | -static void sun4m_common_init(int RAM_size, const char *boot_device, DisplayState *ds, | |
556 | - const char *kernel_filename, const char *kernel_cmdline, | |
557 | - const char *initrd_filename, const char *cpu_model, | |
558 | - unsigned int machine, int max_ram) | |
559 | -{ | |
560 | - void *nvram; | |
561 | - | |
562 | - if ((unsigned int)RAM_size > (unsigned int)max_ram) { | |
563 | - fprintf(stderr, "qemu: Too much memory for this machine: %d, maximum %d\n", | |
564 | - (unsigned int)RAM_size / (1024 * 1024), | |
565 | - (unsigned int)max_ram / (1024 * 1024)); | |
566 | - exit(1); | |
567 | - } | |
568 | - nvram = sun4m_hw_init(&hwdefs[machine], RAM_size, ds, cpu_model); | |
569 | - | |
570 | - sun4m_load_kernel(hwdefs[machine].vram_size, RAM_size, boot_device, | |
571 | - kernel_filename, kernel_cmdline, initrd_filename, | |
572 | - hwdefs[machine].machine_id, nvram); | |
573 | -} | |
574 | - | |
575 | 579 | /* SPARCstation 5 hardware initialisation */ |
576 | 580 | static void ss5_init(int RAM_size, int vga_ram_size, |
577 | 581 | const char *boot_device, DisplayState *ds, |
578 | 582 | const char *kernel_filename, const char *kernel_cmdline, |
579 | 583 | const char *initrd_filename, const char *cpu_model) |
580 | 584 | { |
581 | - if (cpu_model == NULL) | |
582 | - cpu_model = "Fujitsu MB86904"; | |
583 | - sun4m_common_init(RAM_size, boot_device, ds, kernel_filename, | |
584 | - kernel_cmdline, initrd_filename, cpu_model, | |
585 | - 0, 0x10000000); | |
585 | + sun4m_hw_init(&hwdefs[0], RAM_size, boot_device, ds, kernel_filename, | |
586 | + kernel_cmdline, initrd_filename, cpu_model); | |
586 | 587 | } |
587 | 588 | |
588 | 589 | /* SPARCstation 10 hardware initialisation */ |
... | ... | @@ -591,11 +592,8 @@ static void ss10_init(int RAM_size, int vga_ram_size, |
591 | 592 | const char *kernel_filename, const char *kernel_cmdline, |
592 | 593 | const char *initrd_filename, const char *cpu_model) |
593 | 594 | { |
594 | - if (cpu_model == NULL) | |
595 | - cpu_model = "TI SuperSparc II"; | |
596 | - sun4m_common_init(RAM_size, boot_device, ds, kernel_filename, | |
597 | - kernel_cmdline, initrd_filename, cpu_model, | |
598 | - 1, 0xffffffff); // XXX actually first 62GB ok | |
595 | + sun4m_hw_init(&hwdefs[1], RAM_size, boot_device, ds, kernel_filename, | |
596 | + kernel_cmdline, initrd_filename, cpu_model); | |
599 | 597 | } |
600 | 598 | |
601 | 599 | /* SPARCserver 600MP hardware initialisation */ |
... | ... | @@ -604,11 +602,8 @@ static void ss600mp_init(int RAM_size, int vga_ram_size, |
604 | 602 | const char *kernel_filename, const char *kernel_cmdline, |
605 | 603 | const char *initrd_filename, const char *cpu_model) |
606 | 604 | { |
607 | - if (cpu_model == NULL) | |
608 | - cpu_model = "TI SuperSparc II"; | |
609 | - sun4m_common_init(RAM_size, boot_device, ds, kernel_filename, | |
610 | - kernel_cmdline, initrd_filename, cpu_model, | |
611 | - 2, 0xffffffff); // XXX actually first 62GB ok | |
605 | + sun4m_hw_init(&hwdefs[2], RAM_size, boot_device, ds, kernel_filename, | |
606 | + kernel_cmdline, initrd_filename, cpu_model); | |
612 | 607 | } |
613 | 608 | |
614 | 609 | QEMUMachine ss5_machine = { | ... | ... |
target-sparc/cpu.h
target-sparc/helper.c
... | ... | @@ -115,7 +115,7 @@ int get_physical_address (CPUState *env, target_phys_addr_t *physical, int *prot |
115 | 115 | if ((env->mmuregs[0] & MMU_E) == 0) { /* MMU disabled */ |
116 | 116 | // Boot mode: instruction fetches are taken from PROM |
117 | 117 | if (rw == 2 && (env->mmuregs[0] & env->mmu_bm)) { |
118 | - *physical = 0xff0000000ULL | (address & 0x3ffffULL); | |
118 | + *physical = env->prom_addr | (address & 0x3ffffULL); | |
119 | 119 | *prot = PAGE_READ | PAGE_EXEC; |
120 | 120 | return 0; |
121 | 121 | } | ... | ... |