Commit 7df526e317fe4c193589bfdf2ee06255325344cc

Authored by ths
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
hw/mips_malta.c
@@ -59,6 +59,13 @@ typedef struct { @@ -59,6 +59,13 @@ typedef struct {
59 59
60 static PITState *pit; 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 /* Malta FPGA */ 69 /* Malta FPGA */
63 static void malta_fpga_update_display(void *opaque) 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,8 +541,8 @@ static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t
534 stl_raw(p++, 0x34a50000 | (ENVP_ADDR & 0xffff)); /* ori a1, a1, low(ENVP_ADDR) */ 541 stl_raw(p++, 0x34a50000 | (ENVP_ADDR & 0xffff)); /* ori a1, a1, low(ENVP_ADDR) */
535 stl_raw(p++, 0x3c060000 | (((ENVP_ADDR + 8) >> 16) & 0xffff)); /* lui a2, high(ENVP_ADDR + 8) */ 542 stl_raw(p++, 0x3c060000 | (((ENVP_ADDR + 8) >> 16) & 0xffff)); /* lui a2, high(ENVP_ADDR + 8) */
536 stl_raw(p++, 0x34c60000 | ((ENVP_ADDR + 8) & 0xffff)); /* ori a2, a2, low(ENVP_ADDR + 8) */ 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 /* Load BAR registers as done by YAMON */ 547 /* Load BAR registers as done by YAMON */
541 stl_raw(p++, 0x3c09b400); /* lui t1, 0xb400 */ 548 stl_raw(p++, 0x3c09b400); /* lui t1, 0xb400 */
@@ -675,48 +682,48 @@ static int64_t load_kernel (CPUState *env) @@ -675,48 +682,48 @@ static int64_t load_kernel (CPUState *env)
675 long initrd_size; 682 long initrd_size;
676 ram_addr_t initrd_offset; 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 &kernel_entry, &kernel_low, &kernel_high) < 0) { 686 &kernel_entry, &kernel_low, &kernel_high) < 0) {
680 fprintf(stderr, "qemu: could not load kernel '%s'\n", 687 fprintf(stderr, "qemu: could not load kernel '%s'\n",
681 - env->kernel_filename); 688 + loaderparams.kernel_filename);
682 exit(1); 689 exit(1);
683 } 690 }
684 691
685 /* load initrd */ 692 /* load initrd */
686 initrd_size = 0; 693 initrd_size = 0;
687 initrd_offset = 0; 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 if (initrd_size > 0) { 697 if (initrd_size > 0) {
691 initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; 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 fprintf(stderr, 700 fprintf(stderr,
694 "qemu: memory too small for initial ram disk '%s'\n", 701 "qemu: memory too small for initial ram disk '%s'\n",
695 - env->initrd_filename); 702 + loaderparams.initrd_filename);
696 exit(1); 703 exit(1);
697 } 704 }
698 - initrd_size = load_image(env->initrd_filename, 705 + initrd_size = load_image(loaderparams.initrd_filename,
699 phys_ram_base + initrd_offset); 706 phys_ram_base + initrd_offset);
700 } 707 }
701 if (initrd_size == (target_ulong) -1) { 708 if (initrd_size == (target_ulong) -1) {
702 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", 709 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
703 - env->initrd_filename); 710 + loaderparams.initrd_filename);
704 exit(1); 711 exit(1);
705 } 712 }
706 } 713 }
707 714
708 /* Store command line. */ 715 /* Store command line. */
709 - prom_set(index++, env->kernel_filename); 716 + prom_set(index++, loaderparams.kernel_filename);
710 if (initrd_size > 0) 717 if (initrd_size > 0)
711 prom_set(index++, "rd_start=0x" TARGET_FMT_lx " rd_size=%li %s", 718 prom_set(index++, "rd_start=0x" TARGET_FMT_lx " rd_size=%li %s",
712 PHYS_TO_VIRT(initrd_offset), initrd_size, 719 PHYS_TO_VIRT(initrd_offset), initrd_size,
713 - env->kernel_cmdline); 720 + loaderparams.kernel_cmdline);
714 else 721 else
715 - prom_set(index++, env->kernel_cmdline); 722 + prom_set(index++, loaderparams.kernel_cmdline);
716 723
717 /* Setup minimum environment variables */ 724 /* Setup minimum environment variables */
718 prom_set(index++, "memsize"); 725 prom_set(index++, "memsize");
719 - prom_set(index++, "%i", env->ram_size); 726 + prom_set(index++, "%i", loaderparams.ram_size);
720 prom_set(index++, "modetty0"); 727 prom_set(index++, "modetty0");
721 prom_set(index++, "38400n8r"); 728 prom_set(index++, "38400n8r");
722 prom_set(index++, NULL); 729 prom_set(index++, NULL);
@@ -733,7 +740,7 @@ static void main_cpu_reset(void *opaque) @@ -733,7 +740,7 @@ static void main_cpu_reset(void *opaque)
733 /* The bootload does not need to be rewritten as it is located in a 740 /* The bootload does not need to be rewritten as it is located in a
734 read only location. The kernel location and the arguments table 741 read only location. The kernel location and the arguments table
735 location does not change. */ 742 location does not change. */
736 - if (env->kernel_filename) { 743 + if (loaderparams.kernel_filename) {
737 env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL)); 744 env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL));
738 load_kernel (env); 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,10 +825,10 @@ void mips_malta_init (int ram_size, int vga_ram_size, const char *boot_device,
818 /* If a kernel image has been specified, write a small bootloader 825 /* If a kernel image has been specified, write a small bootloader
819 to the flash location. */ 826 to the flash location. */
820 if (kernel_filename) { 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 kernel_entry = load_kernel(env); 832 kernel_entry = load_kernel(env);
826 env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL)); 833 env->CP0_Status &= ~((1 << CP0St_BEV) | (1 << CP0St_ERL));
827 write_bootloader(env, bios_offset, kernel_entry); 834 write_bootloader(env, bios_offset, kernel_entry);
hw/mips_mipssim.c
@@ -40,6 +40,13 @@ @@ -40,6 +40,13 @@
40 40
41 #define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000)) 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 static void load_kernel (CPUState *env) 50 static void load_kernel (CPUState *env)
44 { 51 {
45 int64_t entry, kernel_low, kernel_high; 52 int64_t entry, kernel_low, kernel_high;
@@ -47,7 +54,7 @@ static void load_kernel (CPUState *env) @@ -47,7 +54,7 @@ static void load_kernel (CPUState *env)
47 long initrd_size; 54 long initrd_size;
48 ram_addr_t initrd_offset; 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 &entry, &kernel_low, &kernel_high); 58 &entry, &kernel_low, &kernel_high);
52 if (kernel_size >= 0) { 59 if (kernel_size >= 0) {
53 if ((entry & ~0x7fffffffULL) == 0x80000000) 60 if ((entry & ~0x7fffffffULL) == 0x80000000)
@@ -55,29 +62,29 @@ static void load_kernel (CPUState *env) @@ -55,29 +62,29 @@ static void load_kernel (CPUState *env)
55 env->PC[env->current_tc] = entry; 62 env->PC[env->current_tc] = entry;
56 } else { 63 } else {
57 fprintf(stderr, "qemu: could not load kernel '%s'\n", 64 fprintf(stderr, "qemu: could not load kernel '%s'\n",
58 - env->kernel_filename); 65 + loaderparams.kernel_filename);
59 exit(1); 66 exit(1);
60 } 67 }
61 68
62 /* load initrd */ 69 /* load initrd */
63 initrd_size = 0; 70 initrd_size = 0;
64 initrd_offset = 0; 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 if (initrd_size > 0) { 74 if (initrd_size > 0) {
68 initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; 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 fprintf(stderr, 77 fprintf(stderr,
71 "qemu: memory too small for initial ram disk '%s'\n", 78 "qemu: memory too small for initial ram disk '%s'\n",
72 - env->initrd_filename); 79 + loaderparams.initrd_filename);
73 exit(1); 80 exit(1);
74 } 81 }
75 - initrd_size = load_image(env->initrd_filename, 82 + initrd_size = load_image(loaderparams.initrd_filename,
76 phys_ram_base + initrd_offset); 83 phys_ram_base + initrd_offset);
77 } 84 }
78 if (initrd_size == (target_ulong) -1) { 85 if (initrd_size == (target_ulong) -1) {
79 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", 86 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
80 - env->initrd_filename); 87 + loaderparams.initrd_filename);
81 exit(1); 88 exit(1);
82 } 89 }
83 } 90 }
@@ -89,7 +96,7 @@ static void main_cpu_reset(void *opaque) @@ -89,7 +96,7 @@ static void main_cpu_reset(void *opaque)
89 cpu_reset(env); 96 cpu_reset(env);
90 cpu_mips_register(env, NULL); 97 cpu_mips_register(env, NULL);
91 98
92 - if (env->kernel_filename) 99 + if (loaderparams.kernel_filename)
93 load_kernel (env); 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,10 +151,10 @@ mips_mipssim_init (int ram_size, int vga_ram_size, const char *boot_device,
144 } 151 }
145 152
146 if (kernel_filename) { 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 load_kernel(env); 158 load_kernel(env);
152 } 159 }
153 160
hw/mips_r4k.c
@@ -36,6 +36,13 @@ static PITState *pit; /* PIT i8254 */ @@ -36,6 +36,13 @@ static PITState *pit; /* PIT i8254 */
36 36
37 /*i8254 PIT is attached to the IRQ0 at PIC i8259 */ 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 static void mips_qemu_writel (void *opaque, target_phys_addr_t addr, 46 static void mips_qemu_writel (void *opaque, target_phys_addr_t addr,
40 uint32_t val) 47 uint32_t val)
41 { 48 {
@@ -64,16 +71,13 @@ static CPUReadMemoryFunc *mips_qemu_read[] = { @@ -64,16 +71,13 @@ static CPUReadMemoryFunc *mips_qemu_read[] = {
64 71
65 static int mips_qemu_iomemtype = 0; 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 int64_t entry, kernel_low, kernel_high; 76 int64_t entry, kernel_low, kernel_high;
73 long kernel_size, initrd_size; 77 long kernel_size, initrd_size;
74 ram_addr_t initrd_offset; 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 &entry, &kernel_low, &kernel_high); 81 &entry, &kernel_low, &kernel_high);
78 if (kernel_size >= 0) { 82 if (kernel_size >= 0) {
79 if ((entry & ~0x7fffffffULL) == 0x80000000) 83 if ((entry & ~0x7fffffffULL) == 0x80000000)
@@ -81,29 +85,29 @@ static void load_kernel (CPUState *env, int ram_size, @@ -81,29 +85,29 @@ static void load_kernel (CPUState *env, int ram_size,
81 env->PC[env->current_tc] = entry; 85 env->PC[env->current_tc] = entry;
82 } else { 86 } else {
83 fprintf(stderr, "qemu: could not load kernel '%s'\n", 87 fprintf(stderr, "qemu: could not load kernel '%s'\n",
84 - kernel_filename); 88 + loaderparams.kernel_filename);
85 exit(1); 89 exit(1);
86 } 90 }
87 91
88 /* load initrd */ 92 /* load initrd */
89 initrd_size = 0; 93 initrd_size = 0;
90 initrd_offset = 0; 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 if (initrd_size > 0) { 97 if (initrd_size > 0) {
94 initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK; 98 initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK;
95 if (initrd_offset + initrd_size > ram_size) { 99 if (initrd_offset + initrd_size > ram_size) {
96 fprintf(stderr, 100 fprintf(stderr,
97 "qemu: memory too small for initial ram disk '%s'\n", 101 "qemu: memory too small for initial ram disk '%s'\n",
98 - initrd_filename); 102 + loaderparams.initrd_filename);
99 exit(1); 103 exit(1);
100 } 104 }
101 - initrd_size = load_image(initrd_filename, 105 + initrd_size = load_image(loaderparams.initrd_filename,
102 phys_ram_base + initrd_offset); 106 phys_ram_base + initrd_offset);
103 } 107 }
104 if (initrd_size == (target_ulong) -1) { 108 if (initrd_size == (target_ulong) -1) {
105 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", 109 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
106 - initrd_filename); 110 + loaderparams.initrd_filename);
107 exit(1); 111 exit(1);
108 } 112 }
109 } 113 }
@@ -115,10 +119,12 @@ static void load_kernel (CPUState *env, int ram_size, @@ -115,10 +119,12 @@ static void load_kernel (CPUState *env, int ram_size,
115 "rd_start=0x" TARGET_FMT_lx " rd_size=%li ", 119 "rd_start=0x" TARGET_FMT_lx " rd_size=%li ",
116 PHYS_TO_VIRT((uint32_t)initrd_offset), 120 PHYS_TO_VIRT((uint32_t)initrd_offset),
117 initrd_size); 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 else { 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 *(int32_t *)(phys_ram_base + (16 << 20) - 260) = tswap32 (0x12345678); 130 *(int32_t *)(phys_ram_base + (16 << 20) - 260) = tswap32 (0x12345678);
@@ -131,9 +137,8 @@ static void main_cpu_reset(void *opaque) @@ -131,9 +137,8 @@ static void main_cpu_reset(void *opaque)
131 cpu_reset(env); 137 cpu_reset(env);
132 cpu_mips_register(env, NULL); 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 static 144 static
@@ -194,12 +199,11 @@ void mips_r4k_init (int ram_size, int vga_ram_size, const char *boot_device, @@ -194,12 +199,11 @@ void mips_r4k_init (int ram_size, int vga_ram_size, const char *boot_device,
194 } 199 }
195 200
196 if (kernel_filename) { 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 /* Init CPU internal devices */ 209 /* Init CPU internal devices */
target-mips/cpu.h
@@ -456,11 +456,6 @@ struct CPUMIPSState { @@ -456,11 +456,6 @@ struct CPUMIPSState {
456 456
457 CPU_COMMON 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 mips_def_t *cpu_model; 459 mips_def_t *cpu_model;
465 #ifndef CONFIG_USER_ONLY 460 #ifndef CONFIG_USER_ONLY
466 void *irq[8]; 461 void *irq[8];