Commit 74287114c98ecb969b7ce4b5c959da8a8a431d0f
1 parent
4f14e88c
Improved initrd support for mips.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2574 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
8 changed files
with
74 additions
and
33 deletions
elf_ops.h
... | ... | @@ -139,11 +139,13 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab) |
139 | 139 | } |
140 | 140 | |
141 | 141 | int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, |
142 | - int must_swab, uint64_t *pentry) | |
142 | + int must_swab, uint64_t *pentry, | |
143 | + uint64_t *lowaddr, uint64_t *highaddr) | |
143 | 144 | { |
144 | 145 | struct elfhdr ehdr; |
145 | 146 | struct elf_phdr *phdr = NULL, *ph; |
146 | 147 | int size, i, total_size; |
148 | + elf_word low = 0, high = 0; | |
147 | 149 | elf_word mem_size, addr; |
148 | 150 | uint8_t *data = NULL; |
149 | 151 | |
... | ... | @@ -193,12 +195,20 @@ int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, |
193 | 195 | cpu_physical_memory_write_rom(addr, data, mem_size); |
194 | 196 | |
195 | 197 | total_size += mem_size; |
198 | + if (!low || addr < low) | |
199 | + low = addr; | |
200 | + if (!high || (addr + mem_size) > high) | |
201 | + high = addr + mem_size; | |
196 | 202 | |
197 | 203 | qemu_free(data); |
198 | 204 | data = NULL; |
199 | 205 | } |
200 | 206 | } |
201 | 207 | qemu_free(phdr); |
208 | + if (lowaddr) | |
209 | + *lowaddr = (uint64_t)low; | |
210 | + if (highaddr) | |
211 | + *highaddr = (uint64_t)high; | |
202 | 212 | return total_size; |
203 | 213 | fail: |
204 | 214 | qemu_free(data); | ... | ... |
hw/arm_boot.c
... | ... | @@ -101,7 +101,7 @@ void arm_load_kernel(CPUState *env, int ram_size, const char *kernel_filename, |
101 | 101 | qemu_register_reset(main_cpu_reset, env); |
102 | 102 | } |
103 | 103 | /* Assume that raw images are linux kernels, and ELF images are not. */ |
104 | - kernel_size = load_elf(kernel_filename, 0, &elf_entry); | |
104 | + kernel_size = load_elf(kernel_filename, 0, &elf_entry, NULL, NULL); | |
105 | 105 | entry = elf_entry; |
106 | 106 | if (kernel_size < 0) { |
107 | 107 | kernel_size = load_uboot(kernel_filename, &entry, &is_linux); | ... | ... |
hw/mips_malta.c
... | ... | @@ -31,13 +31,13 @@ |
31 | 31 | #endif |
32 | 32 | |
33 | 33 | #ifdef TARGET_MIPS64 |
34 | -#define INITRD_LOAD_ADDR (int64_t)0x80800000 | |
34 | +#define PHYS_TO_VIRT(x) ((x) | ~0x7fffffffULL) | |
35 | 35 | #else |
36 | -#define INITRD_LOAD_ADDR (int32_t)0x80800000 | |
36 | +#define PHYS_TO_VIRT(x) ((x) | ~0x7fffffffU) | |
37 | 37 | #endif |
38 | 38 | |
39 | -#define ENVP_ADDR (int32_t)0x80002000 | |
40 | -#define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000)) | |
39 | +#define ENVP_ADDR (int32_t)0x80002000 | |
40 | +#define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000)) | |
41 | 41 | |
42 | 42 | #define ENVP_NB_ENTRIES 16 |
43 | 43 | #define ENVP_ENTRY_SIZE 256 |
... | ... | @@ -536,7 +536,7 @@ static void network_init (PCIBus *pci_bus) |
536 | 536 | a3 - RAM size in bytes |
537 | 537 | */ |
538 | 538 | |
539 | -static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t kernel_addr) | |
539 | +static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t kernel_entry) | |
540 | 540 | { |
541 | 541 | uint32_t *p; |
542 | 542 | |
... | ... | @@ -555,8 +555,8 @@ static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t |
555 | 555 | stl_raw(p++, 0x34c60000 | ((ENVP_ADDR + 8) & 0xffff)); /* ori a2, a2, low(ENVP_ADDR + 8) */ |
556 | 556 | stl_raw(p++, 0x3c070000 | (env->ram_size >> 16)); /* lui a3, high(env->ram_size) */ |
557 | 557 | stl_raw(p++, 0x34e70000 | (env->ram_size & 0xffff)); /* ori a3, a3, low(env->ram_size) */ |
558 | - stl_raw(p++, 0x3c1f0000 | ((kernel_addr >> 16) & 0xffff)); /* lui ra, high(kernel_addr) */; | |
559 | - stl_raw(p++, 0x37ff0000 | (kernel_addr & 0xffff)); /* ori ra, ra, low(kernel_addr) */ | |
558 | + stl_raw(p++, 0x3c1f0000 | ((kernel_entry >> 16) & 0xffff)); /* lui ra, high(kernel_entry) */ | |
559 | + stl_raw(p++, 0x37ff0000 | (kernel_entry & 0xffff)); /* ori ra, ra, low(kernel_entry) */ | |
560 | 560 | stl_raw(p++, 0x03e00008); /* jr ra */ |
561 | 561 | stl_raw(p++, 0x00000000); /* nop */ |
562 | 562 | } |
... | ... | @@ -592,11 +592,13 @@ static void prom_set(int index, const char *string, ...) |
592 | 592 | /* Kernel */ |
593 | 593 | static int64_t load_kernel (CPUState *env) |
594 | 594 | { |
595 | - int64_t kernel_addr = 0; | |
595 | + int64_t kernel_entry, kernel_low, kernel_high; | |
596 | 596 | int index = 0; |
597 | 597 | long initrd_size; |
598 | + ram_addr_t initrd_offset; | |
598 | 599 | |
599 | - if (load_elf(env->kernel_filename, VIRT_TO_PHYS_ADDEND, &kernel_addr) < 0) { | |
600 | + if (load_elf(env->kernel_filename, VIRT_TO_PHYS_ADDEND, | |
601 | + &kernel_entry, &kernel_low, &kernel_high) < 0) { | |
600 | 602 | fprintf(stderr, "qemu: could not load kernel '%s'\n", |
601 | 603 | env->kernel_filename); |
602 | 604 | exit(1); |
... | ... | @@ -604,9 +606,20 @@ static int64_t load_kernel (CPUState *env) |
604 | 606 | |
605 | 607 | /* load initrd */ |
606 | 608 | initrd_size = 0; |
609 | + initrd_offset = 0; | |
607 | 610 | if (env->initrd_filename) { |
608 | - initrd_size = load_image(env->initrd_filename, | |
609 | - phys_ram_base + INITRD_LOAD_ADDR + VIRT_TO_PHYS_ADDEND); | |
611 | + initrd_size = get_image_size (env->initrd_filename); | |
612 | + if (initrd_size > 0) { | |
613 | + initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; | |
614 | + if (initrd_offset + initrd_size > env->ram_size) { | |
615 | + fprintf(stderr, | |
616 | + "qemu: memory too small for initial ram disk '%s'\n", | |
617 | + env->initrd_filename); | |
618 | + exit(1); | |
619 | + } | |
620 | + initrd_size = load_image(env->initrd_filename, | |
621 | + phys_ram_base + initrd_offset); | |
622 | + } | |
610 | 623 | if (initrd_size == (target_ulong) -1) { |
611 | 624 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", |
612 | 625 | env->initrd_filename); |
... | ... | @@ -617,7 +630,9 @@ static int64_t load_kernel (CPUState *env) |
617 | 630 | /* Store command line. */ |
618 | 631 | prom_set(index++, env->kernel_filename); |
619 | 632 | if (initrd_size > 0) |
620 | - prom_set(index++, "rd_start=0x" TARGET_FMT_lx " rd_size=%li %s", INITRD_LOAD_ADDR, initrd_size, env->kernel_cmdline); | |
633 | + prom_set(index++, "rd_start=0x" TARGET_FMT_lx " rd_size=%li %s", | |
634 | + PHYS_TO_VIRT(initrd_offset), initrd_size, | |
635 | + env->kernel_cmdline); | |
621 | 636 | else |
622 | 637 | prom_set(index++, env->kernel_cmdline); |
623 | 638 | |
... | ... | @@ -628,7 +643,7 @@ static int64_t load_kernel (CPUState *env) |
628 | 643 | prom_set(index++, "38400n8r"); |
629 | 644 | prom_set(index++, NULL); |
630 | 645 | |
631 | - return kernel_addr; | |
646 | + return kernel_entry; | |
632 | 647 | } |
633 | 648 | |
634 | 649 | static void main_cpu_reset(void *opaque) |
... | ... | @@ -651,7 +666,7 @@ void mips_malta_init (int ram_size, int vga_ram_size, int boot_device, |
651 | 666 | { |
652 | 667 | char buf[1024]; |
653 | 668 | unsigned long bios_offset; |
654 | - int64_t kernel_addr; | |
669 | + int64_t kernel_entry; | |
655 | 670 | PCIBus *pci_bus; |
656 | 671 | CPUState *env; |
657 | 672 | RTCState *rtc_state; |
... | ... | @@ -693,8 +708,8 @@ void mips_malta_init (int ram_size, int vga_ram_size, int boot_device, |
693 | 708 | env->kernel_filename = kernel_filename; |
694 | 709 | env->kernel_cmdline = kernel_cmdline; |
695 | 710 | env->initrd_filename = initrd_filename; |
696 | - kernel_addr = load_kernel(env); | |
697 | - write_bootloader(env, bios_offset, kernel_addr); | |
711 | + kernel_entry = load_kernel(env); | |
712 | + write_bootloader(env, bios_offset, kernel_entry); | |
698 | 713 | } else { |
699 | 714 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME); |
700 | 715 | ret = load_image(buf, phys_ram_base + bios_offset); | ... | ... |
hw/mips_r4k.c
... | ... | @@ -16,9 +16,9 @@ |
16 | 16 | #endif |
17 | 17 | |
18 | 18 | #ifdef TARGET_MIPS64 |
19 | -#define INITRD_LOAD_ADDR (int64_t)(int32_t)0x80800000 | |
19 | +#define PHYS_TO_VIRT(x) ((x) | ~0x7fffffffULL) | |
20 | 20 | #else |
21 | -#define INITRD_LOAD_ADDR (int32_t)0x80800000 | |
21 | +#define PHYS_TO_VIRT(x) ((x) | ~0x7fffffffU) | |
22 | 22 | #endif |
23 | 23 | |
24 | 24 | #define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000)) |
... | ... | @@ -73,10 +73,12 @@ void load_kernel (CPUState *env, int ram_size, const char *kernel_filename, |
73 | 73 | const char *kernel_cmdline, |
74 | 74 | const char *initrd_filename) |
75 | 75 | { |
76 | - int64_t entry = 0; | |
76 | + int64_t entry, kernel_low, kernel_high; | |
77 | 77 | long kernel_size, initrd_size; |
78 | + ram_addr_t initrd_offset; | |
78 | 79 | |
79 | - kernel_size = load_elf(kernel_filename, VIRT_TO_PHYS_ADDEND, &entry); | |
80 | + kernel_size = load_elf(kernel_filename, VIRT_TO_PHYS_ADDEND, | |
81 | + &entry, &kernel_low, &kernel_high); | |
80 | 82 | if (kernel_size >= 0) { |
81 | 83 | if ((entry & ~0x7fffffffULL) == 0x80000000) |
82 | 84 | entry = (int32_t)entry; |
... | ... | @@ -89,9 +91,20 @@ void load_kernel (CPUState *env, int ram_size, const char *kernel_filename, |
89 | 91 | |
90 | 92 | /* load initrd */ |
91 | 93 | initrd_size = 0; |
94 | + initrd_offset = 0; | |
92 | 95 | if (initrd_filename) { |
93 | - initrd_size = load_image(initrd_filename, | |
94 | - phys_ram_base + INITRD_LOAD_ADDR + VIRT_TO_PHYS_ADDEND); | |
96 | + initrd_size = get_image_size (initrd_filename); | |
97 | + if (initrd_size > 0) { | |
98 | + initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; | |
99 | + if (initrd_offset + initrd_size > ram_size) { | |
100 | + fprintf(stderr, | |
101 | + "qemu: memory too small for initial ram disk '%s'\n", | |
102 | + initrd_filename); | |
103 | + exit(1); | |
104 | + } | |
105 | + initrd_size = load_image(initrd_filename, | |
106 | + phys_ram_base + initrd_offset); | |
107 | + } | |
95 | 108 | if (initrd_size == (target_ulong) -1) { |
96 | 109 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", |
97 | 110 | initrd_filename); |
... | ... | @@ -104,7 +117,7 @@ void load_kernel (CPUState *env, int ram_size, const char *kernel_filename, |
104 | 117 | int ret; |
105 | 118 | ret = sprintf(phys_ram_base + (16 << 20) - 256, |
106 | 119 | "rd_start=0x" TARGET_FMT_lx " rd_size=%li ", |
107 | - INITRD_LOAD_ADDR, | |
120 | + PHYS_TO_VIRT((uint32_t)initrd_offset), | |
108 | 121 | initrd_size); |
109 | 122 | strcpy (phys_ram_base + (16 << 20) - 256 + ret, kernel_cmdline); |
110 | 123 | } | ... | ... |
hw/sun4m.c
... | ... | @@ -295,7 +295,7 @@ static void sun4m_load_kernel(long vram_size, int ram_size, int boot_device, |
295 | 295 | prom_offset | IO_MEM_ROM); |
296 | 296 | |
297 | 297 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, PROM_FILENAME); |
298 | - ret = load_elf(buf, 0, NULL); | |
298 | + ret = load_elf(buf, 0, NULL, NULL, NULL); | |
299 | 299 | if (ret < 0) { |
300 | 300 | fprintf(stderr, "qemu: could not load prom '%s'\n", |
301 | 301 | buf); |
... | ... | @@ -304,7 +304,7 @@ static void sun4m_load_kernel(long vram_size, int ram_size, int boot_device, |
304 | 304 | |
305 | 305 | kernel_size = 0; |
306 | 306 | if (linux_boot) { |
307 | - kernel_size = load_elf(kernel_filename, -0xf0000000, NULL); | |
307 | + kernel_size = load_elf(kernel_filename, -0xf0000000, NULL, NULL, NULL); | |
308 | 308 | if (kernel_size < 0) |
309 | 309 | kernel_size = load_aout(kernel_filename, phys_ram_base + KERNEL_LOAD_ADDR); |
310 | 310 | if (kernel_size < 0) | ... | ... |
hw/sun4u.c
... | ... | @@ -292,7 +292,7 @@ static void sun4u_init(int ram_size, int vga_ram_size, int boot_device, |
292 | 292 | prom_offset | IO_MEM_ROM); |
293 | 293 | |
294 | 294 | snprintf(buf, sizeof(buf), "%s/%s", bios_dir, PROM_FILENAME); |
295 | - ret = load_elf(buf, 0, NULL); | |
295 | + ret = load_elf(buf, 0, NULL, NULL, NULL); | |
296 | 296 | if (ret < 0) { |
297 | 297 | fprintf(stderr, "qemu: could not load prom '%s'\n", |
298 | 298 | buf); |
... | ... | @@ -303,7 +303,7 @@ static void sun4u_init(int ram_size, int vga_ram_size, int boot_device, |
303 | 303 | initrd_size = 0; |
304 | 304 | if (linux_boot) { |
305 | 305 | /* XXX: put correct offset */ |
306 | - kernel_size = load_elf(kernel_filename, 0, NULL); | |
306 | + kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL); | |
307 | 307 | if (kernel_size < 0) |
308 | 308 | kernel_size = load_aout(kernel_filename, phys_ram_base + KERNEL_LOAD_ADDR); |
309 | 309 | if (kernel_size < 0) | ... | ... |
loader.c
... | ... | @@ -196,7 +196,7 @@ static void *load_at(int fd, int offset, int size) |
196 | 196 | |
197 | 197 | /* return < 0 if error, otherwise the number of bytes loaded in memory */ |
198 | 198 | int load_elf(const char *filename, int64_t virt_to_phys_addend, |
199 | - uint64_t *pentry) | |
199 | + uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr) | |
200 | 200 | { |
201 | 201 | int fd, data_order, host_data_order, must_swab, ret; |
202 | 202 | uint8_t e_ident[EI_NIDENT]; |
... | ... | @@ -230,9 +230,11 @@ int load_elf(const char *filename, int64_t virt_to_phys_addend, |
230 | 230 | |
231 | 231 | lseek(fd, 0, SEEK_SET); |
232 | 232 | if (e_ident[EI_CLASS] == ELFCLASS64) { |
233 | - ret = load_elf64(fd, virt_to_phys_addend, must_swab, pentry); | |
233 | + ret = load_elf64(fd, virt_to_phys_addend, must_swab, pentry, | |
234 | + lowaddr, highaddr); | |
234 | 235 | } else { |
235 | - ret = load_elf32(fd, virt_to_phys_addend, must_swab, pentry); | |
236 | + ret = load_elf32(fd, virt_to_phys_addend, must_swab, pentry, | |
237 | + lowaddr, highaddr); | |
236 | 238 | } |
237 | 239 | |
238 | 240 | close(fd); | ... | ... |
vl.h
... | ... | @@ -1180,7 +1180,8 @@ void slavio_pic_set_irq_cpu(void *opaque, int irq, int level, unsigned int cpu); |
1180 | 1180 | /* loader.c */ |
1181 | 1181 | int get_image_size(const char *filename); |
1182 | 1182 | int load_image(const char *filename, uint8_t *addr); |
1183 | -int load_elf(const char *filename, int64_t virt_to_phys_addend, uint64_t *pentry); | |
1183 | +int load_elf(const char *filename, int64_t virt_to_phys_addend, | |
1184 | + uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr); | |
1184 | 1185 | int load_aout(const char *filename, uint8_t *addr); |
1185 | 1186 | int load_uboot(const char *filename, target_ulong *ep, int *is_linux); |
1186 | 1187 | ... | ... |