Commit 636aa70ade7e9b96eb9382ba3a503043e83d876b
1 parent
7b833f5b
Sparc64: refactor kernel init
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Showing
1 changed file
with
55 additions
and
42 deletions
hw/sun4u.c
... | ... | @@ -148,6 +148,56 @@ static int sun4u_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size, |
148 | 148 | |
149 | 149 | return 0; |
150 | 150 | } |
151 | +static unsigned long sun4u_load_kernel(const char *kernel_filename, | |
152 | + const char *initrd_filename, | |
153 | + ram_addr_t RAM_size, long *initrd_size) | |
154 | +{ | |
155 | + int linux_boot; | |
156 | + unsigned int i; | |
157 | + long kernel_size; | |
158 | + | |
159 | + linux_boot = (kernel_filename != NULL); | |
160 | + | |
161 | + kernel_size = 0; | |
162 | + if (linux_boot) { | |
163 | + kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL); | |
164 | + if (kernel_size < 0) | |
165 | + kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR, | |
166 | + RAM_size - KERNEL_LOAD_ADDR); | |
167 | + if (kernel_size < 0) | |
168 | + kernel_size = load_image_targphys(kernel_filename, | |
169 | + KERNEL_LOAD_ADDR, | |
170 | + RAM_size - KERNEL_LOAD_ADDR); | |
171 | + if (kernel_size < 0) { | |
172 | + fprintf(stderr, "qemu: could not load kernel '%s'\n", | |
173 | + kernel_filename); | |
174 | + exit(1); | |
175 | + } | |
176 | + | |
177 | + /* load initrd */ | |
178 | + *initrd_size = 0; | |
179 | + if (initrd_filename) { | |
180 | + *initrd_size = load_image_targphys(initrd_filename, | |
181 | + INITRD_LOAD_ADDR, | |
182 | + RAM_size - INITRD_LOAD_ADDR); | |
183 | + if (*initrd_size < 0) { | |
184 | + fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", | |
185 | + initrd_filename); | |
186 | + exit(1); | |
187 | + } | |
188 | + } | |
189 | + if (*initrd_size > 0) { | |
190 | + for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { | |
191 | + if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS | |
192 | + stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR); | |
193 | + stl_phys(KERNEL_LOAD_ADDR + i + 20, *initrd_size); | |
194 | + break; | |
195 | + } | |
196 | + } | |
197 | + } | |
198 | + } | |
199 | + return kernel_size; | |
200 | +} | |
151 | 201 | |
152 | 202 | void pic_info(Monitor *mon) |
153 | 203 | { |
... | ... | @@ -503,7 +553,6 @@ static void sun4uv_init(ram_addr_t RAM_size, |
503 | 553 | { |
504 | 554 | CPUState *env; |
505 | 555 | m48t59_t *nvram; |
506 | - int linux_boot; | |
507 | 556 | unsigned int i; |
508 | 557 | long initrd_size, kernel_size; |
509 | 558 | PCIBus *pci_bus, *pci_bus2, *pci_bus3; |
... | ... | @@ -513,8 +562,6 @@ static void sun4uv_init(ram_addr_t RAM_size, |
513 | 562 | BlockDriverState *fd[MAX_FD]; |
514 | 563 | void *fw_cfg; |
515 | 564 | |
516 | - linux_boot = (kernel_filename != NULL); | |
517 | - | |
518 | 565 | /* init CPUs */ |
519 | 566 | env = cpu_devinit(cpu_model, hwdef); |
520 | 567 | |
... | ... | @@ -523,45 +570,6 @@ static void sun4uv_init(ram_addr_t RAM_size, |
523 | 570 | |
524 | 571 | prom_init(hwdef->prom_addr, bios_name); |
525 | 572 | |
526 | - kernel_size = 0; | |
527 | - initrd_size = 0; | |
528 | - if (linux_boot) { | |
529 | - /* XXX: put correct offset */ | |
530 | - kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL); | |
531 | - if (kernel_size < 0) | |
532 | - kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR, | |
533 | - ram_size - KERNEL_LOAD_ADDR); | |
534 | - if (kernel_size < 0) | |
535 | - kernel_size = load_image_targphys(kernel_filename, | |
536 | - KERNEL_LOAD_ADDR, | |
537 | - ram_size - KERNEL_LOAD_ADDR); | |
538 | - if (kernel_size < 0) { | |
539 | - fprintf(stderr, "qemu: could not load kernel '%s'\n", | |
540 | - kernel_filename); | |
541 | - exit(1); | |
542 | - } | |
543 | - | |
544 | - /* load initrd */ | |
545 | - if (initrd_filename) { | |
546 | - initrd_size = load_image_targphys(initrd_filename, | |
547 | - INITRD_LOAD_ADDR, | |
548 | - ram_size - INITRD_LOAD_ADDR); | |
549 | - if (initrd_size < 0) { | |
550 | - fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", | |
551 | - initrd_filename); | |
552 | - exit(1); | |
553 | - } | |
554 | - } | |
555 | - if (initrd_size > 0) { | |
556 | - for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { | |
557 | - if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS | |
558 | - stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR); | |
559 | - stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size); | |
560 | - break; | |
561 | - } | |
562 | - } | |
563 | - } | |
564 | - } | |
565 | 573 | |
566 | 574 | irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS); |
567 | 575 | pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, irq, &pci_bus2, |
... | ... | @@ -621,6 +629,11 @@ static void sun4uv_init(ram_addr_t RAM_size, |
621 | 629 | } |
622 | 630 | floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd); |
623 | 631 | nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59); |
632 | + | |
633 | + initrd_size = 0; | |
634 | + kernel_size = sun4u_load_kernel(kernel_filename, initrd_filename, | |
635 | + ram_size, &initrd_size); | |
636 | + | |
624 | 637 | sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices, |
625 | 638 | KERNEL_LOAD_ADDR, kernel_size, |
626 | 639 | kernel_cmdline, | ... | ... |