Commit 7df526e317fe4c193589bfdf2ee06255325344cc
1 parent
d26bc211
Move kernel loader parameters from the cpu state to being board specific.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3557 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
4 changed files
with
72 additions
and
59 deletions
hw/mips_malta.c
... | ... | @@ -59,6 +59,13 @@ typedef struct { |
59 | 59 | |
60 | 60 | static PITState *pit; |
61 | 61 | |
62 | +static struct _loaderparams { | |
63 | + int ram_size; | |
64 | + const char *kernel_filename; | |
65 | + const char *kernel_cmdline; | |
66 | + const char *initrd_filename; | |
67 | +} loaderparams; | |
68 | + | |
62 | 69 | /* Malta FPGA */ |
63 | 70 | static void malta_fpga_update_display(void *opaque) |
64 | 71 | { |
... | ... | @@ -534,8 +541,8 @@ static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t |
534 | 541 | stl_raw(p++, 0x34a50000 | (ENVP_ADDR & 0xffff)); /* ori a1, a1, low(ENVP_ADDR) */ |
535 | 542 | stl_raw(p++, 0x3c060000 | (((ENVP_ADDR + 8) >> 16) & 0xffff)); /* lui a2, high(ENVP_ADDR + 8) */ |
536 | 543 | stl_raw(p++, 0x34c60000 | ((ENVP_ADDR + 8) & 0xffff)); /* ori a2, a2, low(ENVP_ADDR + 8) */ |
537 | - stl_raw(p++, 0x3c070000 | (env->ram_size >> 16)); /* lui a3, high(env->ram_size) */ | |
538 | - stl_raw(p++, 0x34e70000 | (env->ram_size & 0xffff)); /* ori a3, a3, low(env->ram_size) */ | |
544 | + stl_raw(p++, 0x3c070000 | (loaderparams.ram_size >> 16)); /* lui a3, high(ram_size) */ | |
545 | + stl_raw(p++, 0x34e70000 | (loaderparams.ram_size & 0xffff)); /* ori a3, a3, low(ram_size) */ | |
539 | 546 | |
540 | 547 | /* Load BAR registers as done by YAMON */ |
541 | 548 | stl_raw(p++, 0x3c09b400); /* lui t1, 0xb400 */ |
... | ... | @@ -675,48 +682,48 @@ static int64_t load_kernel (CPUState *env) |
675 | 682 | long initrd_size; |
676 | 683 | ram_addr_t initrd_offset; |
677 | 684 | |
678 | - if (load_elf(env->kernel_filename, VIRT_TO_PHYS_ADDEND, | |
685 | + if (load_elf(loaderparams.kernel_filename, VIRT_TO_PHYS_ADDEND, | |
679 | 686 | &kernel_entry, &kernel_low, &kernel_high) < 0) { |
680 | 687 | fprintf(stderr, "qemu: could not load kernel '%s'\n", |
681 | - env->kernel_filename); | |
688 | + loaderparams.kernel_filename); | |
682 | 689 | exit(1); |
683 | 690 | } |
684 | 691 | |
685 | 692 | /* load initrd */ |
686 | 693 | initrd_size = 0; |
687 | 694 | initrd_offset = 0; |
688 | - if (env->initrd_filename) { | |
689 | - initrd_size = get_image_size (env->initrd_filename); | |
695 | + if (loaderparams.initrd_filename) { | |
696 | + initrd_size = get_image_size (loaderparams.initrd_filename); | |
690 | 697 | if (initrd_size > 0) { |
691 | 698 | initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; |
692 | - if (initrd_offset + initrd_size > env->ram_size) { | |
699 | + if (initrd_offset + initrd_size > ram_size) { | |
693 | 700 | fprintf(stderr, |
694 | 701 | "qemu: memory too small for initial ram disk '%s'\n", |
695 | - env->initrd_filename); | |
702 | + loaderparams.initrd_filename); | |
696 | 703 | exit(1); |
697 | 704 | } |
698 | - initrd_size = load_image(env->initrd_filename, | |
705 | + initrd_size = load_image(loaderparams.initrd_filename, | |
699 | 706 | phys_ram_base + initrd_offset); |
700 | 707 | } |
701 | 708 | if (initrd_size == (target_ulong) -1) { |
702 | 709 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", |
703 | - env->initrd_filename); | |
710 | + loaderparams.initrd_filename); | |
704 | 711 | exit(1); |
705 | 712 | } |
706 | 713 | } |
707 | 714 | |
708 | 715 | /* Store command line. */ |
709 | - prom_set(index++, env->kernel_filename); | |
716 | + prom_set(index++, loaderparams.kernel_filename); | |
710 | 717 | if (initrd_size > 0) |
711 | 718 | prom_set(index++, "rd_start=0x" TARGET_FMT_lx " rd_size=%li %s", |
712 | 719 | PHYS_TO_VIRT(initrd_offset), initrd_size, |
713 | - env->kernel_cmdline); | |
720 | + loaderparams.kernel_cmdline); | |
714 | 721 | else |
715 | - prom_set(index++, env->kernel_cmdline); | |
722 | + prom_set(index++, loaderparams.kernel_cmdline); | |
716 | 723 | |
717 | 724 | /* Setup minimum environment variables */ |
718 | 725 | prom_set(index++, "memsize"); |
719 | - prom_set(index++, "%i", env->ram_size); | |
726 | + prom_set(index++, "%i", loaderparams.ram_size); | |
720 | 727 | prom_set(index++, "modetty0"); |
721 | 728 | prom_set(index++, "38400n8r"); |
722 | 729 | prom_set(index++, NULL); |
... | ... | @@ -733,7 +740,7 @@ static void main_cpu_reset(void *opaque) |
733 | 740 | /* The bootload does not need to be rewritten as it is located in a |
734 | 741 | read only location. The kernel location and the arguments table |
735 | 742 | location does not change. */ |
736 | - if (env->kernel_filename) { | |
743 | + if (loaderparams.kernel_filename) { | |
737 | 744 | env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL)); |
738 | 745 | load_kernel (env); |
739 | 746 | } |
... | ... | @@ -818,10 +825,10 @@ void mips_malta_init (int ram_size, int vga_ram_size, const char *boot_device, |
818 | 825 | /* If a kernel image has been specified, write a small bootloader |
819 | 826 | to the flash location. */ |
820 | 827 | if (kernel_filename) { |
821 | - env->ram_size = ram_size; | |
822 | - env->kernel_filename = kernel_filename; | |
823 | - env->kernel_cmdline = kernel_cmdline; | |
824 | - env->initrd_filename = initrd_filename; | |
828 | + loaderparams.ram_size = ram_size; | |
829 | + loaderparams.kernel_filename = kernel_filename; | |
830 | + loaderparams.kernel_cmdline = kernel_cmdline; | |
831 | + loaderparams.initrd_filename = initrd_filename; | |
825 | 832 | kernel_entry = load_kernel(env); |
826 | 833 | env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL)); |
827 | 834 | write_bootloader(env, bios_offset, kernel_entry); | ... | ... |
hw/mips_mipssim.c
... | ... | @@ -40,6 +40,13 @@ |
40 | 40 | |
41 | 41 | #define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000)) |
42 | 42 | |
43 | +static struct _loaderparams { | |
44 | + int ram_size; | |
45 | + const char *kernel_filename; | |
46 | + const char *kernel_cmdline; | |
47 | + const char *initrd_filename; | |
48 | +} loaderparams; | |
49 | + | |
43 | 50 | static void load_kernel (CPUState *env) |
44 | 51 | { |
45 | 52 | int64_t entry, kernel_low, kernel_high; |
... | ... | @@ -47,7 +54,7 @@ static void load_kernel (CPUState *env) |
47 | 54 | long initrd_size; |
48 | 55 | ram_addr_t initrd_offset; |
49 | 56 | |
50 | - kernel_size = load_elf(env->kernel_filename, VIRT_TO_PHYS_ADDEND, | |
57 | + kernel_size = load_elf(loaderparams.kernel_filename, VIRT_TO_PHYS_ADDEND, | |
51 | 58 | &entry, &kernel_low, &kernel_high); |
52 | 59 | if (kernel_size >= 0) { |
53 | 60 | if ((entry & ~0x7fffffffULL) == 0x80000000) |
... | ... | @@ -55,29 +62,29 @@ static void load_kernel (CPUState *env) |
55 | 62 | env->PC[env->current_tc] = entry; |
56 | 63 | } else { |
57 | 64 | fprintf(stderr, "qemu: could not load kernel '%s'\n", |
58 | - env->kernel_filename); | |
65 | + loaderparams.kernel_filename); | |
59 | 66 | exit(1); |
60 | 67 | } |
61 | 68 | |
62 | 69 | /* load initrd */ |
63 | 70 | initrd_size = 0; |
64 | 71 | initrd_offset = 0; |
65 | - if (env->initrd_filename) { | |
66 | - initrd_size = get_image_size (env->initrd_filename); | |
72 | + if (loaderparams.initrd_filename) { | |
73 | + initrd_size = get_image_size (loaderparams.initrd_filename); | |
67 | 74 | if (initrd_size > 0) { |
68 | 75 | initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; |
69 | - if (initrd_offset + initrd_size > env->ram_size) { | |
76 | + if (initrd_offset + initrd_size > loaderparams.ram_size) { | |
70 | 77 | fprintf(stderr, |
71 | 78 | "qemu: memory too small for initial ram disk '%s'\n", |
72 | - env->initrd_filename); | |
79 | + loaderparams.initrd_filename); | |
73 | 80 | exit(1); |
74 | 81 | } |
75 | - initrd_size = load_image(env->initrd_filename, | |
82 | + initrd_size = load_image(loaderparams.initrd_filename, | |
76 | 83 | phys_ram_base + initrd_offset); |
77 | 84 | } |
78 | 85 | if (initrd_size == (target_ulong) -1) { |
79 | 86 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", |
80 | - env->initrd_filename); | |
87 | + loaderparams.initrd_filename); | |
81 | 88 | exit(1); |
82 | 89 | } |
83 | 90 | } |
... | ... | @@ -89,7 +96,7 @@ static void main_cpu_reset(void *opaque) |
89 | 96 | cpu_reset(env); |
90 | 97 | cpu_mips_register(env, NULL); |
91 | 98 | |
92 | - if (env->kernel_filename) | |
99 | + if (loaderparams.kernel_filename) | |
93 | 100 | load_kernel (env); |
94 | 101 | } |
95 | 102 | |
... | ... | @@ -144,10 +151,10 @@ mips_mipssim_init (int ram_size, int vga_ram_size, const char *boot_device, |
144 | 151 | } |
145 | 152 | |
146 | 153 | if (kernel_filename) { |
147 | - env->ram_size = ram_size; | |
148 | - env->kernel_filename = kernel_filename; | |
149 | - env->kernel_cmdline = kernel_cmdline; | |
150 | - env->initrd_filename = initrd_filename; | |
154 | + loaderparams.ram_size = ram_size; | |
155 | + loaderparams.kernel_filename = kernel_filename; | |
156 | + loaderparams.kernel_cmdline = kernel_cmdline; | |
157 | + loaderparams.initrd_filename = initrd_filename; | |
151 | 158 | load_kernel(env); |
152 | 159 | } |
153 | 160 | ... | ... |
hw/mips_r4k.c
... | ... | @@ -36,6 +36,13 @@ static PITState *pit; /* PIT i8254 */ |
36 | 36 | |
37 | 37 | /*i8254 PIT is attached to the IRQ0 at PIC i8259 */ |
38 | 38 | |
39 | +static struct _loaderparams { | |
40 | + int ram_size; | |
41 | + const char *kernel_filename; | |
42 | + const char *kernel_cmdline; | |
43 | + const char *initrd_filename; | |
44 | +} loaderparams; | |
45 | + | |
39 | 46 | static void mips_qemu_writel (void *opaque, target_phys_addr_t addr, |
40 | 47 | uint32_t val) |
41 | 48 | { |
... | ... | @@ -64,16 +71,13 @@ static CPUReadMemoryFunc *mips_qemu_read[] = { |
64 | 71 | |
65 | 72 | static int mips_qemu_iomemtype = 0; |
66 | 73 | |
67 | -static void load_kernel (CPUState *env, int ram_size, | |
68 | - const char *kernel_filename, | |
69 | - const char *kernel_cmdline, | |
70 | - const char *initrd_filename) | |
74 | +static void load_kernel (CPUState *env) | |
71 | 75 | { |
72 | 76 | int64_t entry, kernel_low, kernel_high; |
73 | 77 | long kernel_size, initrd_size; |
74 | 78 | ram_addr_t initrd_offset; |
75 | 79 | |
76 | - kernel_size = load_elf(kernel_filename, VIRT_TO_PHYS_ADDEND, | |
80 | + kernel_size = load_elf(loaderparams.kernel_filename, VIRT_TO_PHYS_ADDEND, | |
77 | 81 | &entry, &kernel_low, &kernel_high); |
78 | 82 | if (kernel_size >= 0) { |
79 | 83 | if ((entry & ~0x7fffffffULL) == 0x80000000) |
... | ... | @@ -81,29 +85,29 @@ static void load_kernel (CPUState *env, int ram_size, |
81 | 85 | env->PC[env->current_tc] = entry; |
82 | 86 | } else { |
83 | 87 | fprintf(stderr, "qemu: could not load kernel '%s'\n", |
84 | - kernel_filename); | |
88 | + loaderparams.kernel_filename); | |
85 | 89 | exit(1); |
86 | 90 | } |
87 | 91 | |
88 | 92 | /* load initrd */ |
89 | 93 | initrd_size = 0; |
90 | 94 | initrd_offset = 0; |
91 | - if (initrd_filename) { | |
92 | - initrd_size = get_image_size (initrd_filename); | |
95 | + if (loaderparams.initrd_filename) { | |
96 | + initrd_size = get_image_size (loaderparams.initrd_filename); | |
93 | 97 | if (initrd_size > 0) { |
94 | 98 | initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; |
95 | 99 | if (initrd_offset + initrd_size > ram_size) { |
96 | 100 | fprintf(stderr, |
97 | 101 | "qemu: memory too small for initial ram disk '%s'\n", |
98 | - initrd_filename); | |
102 | + loaderparams.initrd_filename); | |
99 | 103 | exit(1); |
100 | 104 | } |
101 | - initrd_size = load_image(initrd_filename, | |
105 | + initrd_size = load_image(loaderparams.initrd_filename, | |
102 | 106 | phys_ram_base + initrd_offset); |
103 | 107 | } |
104 | 108 | if (initrd_size == (target_ulong) -1) { |
105 | 109 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", |
106 | - initrd_filename); | |
110 | + loaderparams.initrd_filename); | |
107 | 111 | exit(1); |
108 | 112 | } |
109 | 113 | } |
... | ... | @@ -115,10 +119,12 @@ static void load_kernel (CPUState *env, int ram_size, |
115 | 119 | "rd_start=0x" TARGET_FMT_lx " rd_size=%li ", |
116 | 120 | PHYS_TO_VIRT((uint32_t)initrd_offset), |
117 | 121 | initrd_size); |
118 | - strcpy (phys_ram_base + (16 << 20) - 256 + ret, kernel_cmdline); | |
122 | + strcpy (phys_ram_base + (16 << 20) - 256 + ret, | |
123 | + loaderparams.kernel_cmdline); | |
119 | 124 | } |
120 | 125 | else { |
121 | - strcpy (phys_ram_base + (16 << 20) - 256, kernel_cmdline); | |
126 | + strcpy (phys_ram_base + (16 << 20) - 256, | |
127 | + loaderparams.kernel_cmdline); | |
122 | 128 | } |
123 | 129 | |
124 | 130 | *(int32_t *)(phys_ram_base + (16 << 20) - 260) = tswap32 (0x12345678); |
... | ... | @@ -131,9 +137,8 @@ static void main_cpu_reset(void *opaque) |
131 | 137 | cpu_reset(env); |
132 | 138 | cpu_mips_register(env, NULL); |
133 | 139 | |
134 | - if (env->kernel_filename) | |
135 | - load_kernel (env, env->ram_size, env->kernel_filename, | |
136 | - env->kernel_cmdline, env->initrd_filename); | |
140 | + if (loaderparams.kernel_filename) | |
141 | + load_kernel (env); | |
137 | 142 | } |
138 | 143 | |
139 | 144 | static |
... | ... | @@ -194,12 +199,11 @@ void mips_r4k_init (int ram_size, int vga_ram_size, const char *boot_device, |
194 | 199 | } |
195 | 200 | |
196 | 201 | if (kernel_filename) { |
197 | - load_kernel (env, ram_size, kernel_filename, kernel_cmdline, | |
198 | - initrd_filename); | |
199 | - env->ram_size = ram_size; | |
200 | - env->kernel_filename = kernel_filename; | |
201 | - env->kernel_cmdline = kernel_cmdline; | |
202 | - env->initrd_filename = initrd_filename; | |
202 | + loaderparams.ram_size = ram_size; | |
203 | + loaderparams.kernel_filename = kernel_filename; | |
204 | + loaderparams.kernel_cmdline = kernel_cmdline; | |
205 | + loaderparams.initrd_filename = initrd_filename; | |
206 | + load_kernel (env); | |
203 | 207 | } |
204 | 208 | |
205 | 209 | /* Init CPU internal devices */ | ... | ... |
target-mips/cpu.h
... | ... | @@ -456,11 +456,6 @@ struct CPUMIPSState { |
456 | 456 | |
457 | 457 | CPU_COMMON |
458 | 458 | |
459 | - int ram_size; | |
460 | - const char *kernel_filename; | |
461 | - const char *kernel_cmdline; | |
462 | - const char *initrd_filename; | |
463 | - | |
464 | 459 | mips_def_t *cpu_model; |
465 | 460 | #ifndef CONFIG_USER_ONLY |
466 | 461 | void *irq[8]; | ... | ... |