aboutsummaryrefslogtreecommitdiff
path: root/hw/mips_malta.c
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-04-01 17:56:37 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-04-01 17:56:37 +0000
commit74287114c98ecb969b7ce4b5c959da8a8a431d0f (patch)
treed82c33d09efeb9dff7a5b9b20324ee507f0458d1 /hw/mips_malta.c
parent4f14e88c5991877085b1090508ee222d6f3ef088 (diff)
Improved initrd support for mips.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2574 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/mips_malta.c')
-rw-r--r--hw/mips_malta.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index e4b43bea99..0ba3359ef4 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -31,13 +31,13 @@
#endif
#ifdef TARGET_MIPS64
-#define INITRD_LOAD_ADDR (int64_t)0x80800000
+#define PHYS_TO_VIRT(x) ((x) | ~0x7fffffffULL)
#else
-#define INITRD_LOAD_ADDR (int32_t)0x80800000
+#define PHYS_TO_VIRT(x) ((x) | ~0x7fffffffU)
#endif
-#define ENVP_ADDR (int32_t)0x80002000
-#define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000))
+#define ENVP_ADDR (int32_t)0x80002000
+#define VIRT_TO_PHYS_ADDEND (-((int64_t)(int32_t)0x80000000))
#define ENVP_NB_ENTRIES 16
#define ENVP_ENTRY_SIZE 256
@@ -536,7 +536,7 @@ static void network_init (PCIBus *pci_bus)
a3 - RAM size in bytes
*/
-static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t kernel_addr)
+static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t kernel_entry)
{
uint32_t *p;
@@ -555,8 +555,8 @@ static void write_bootloader (CPUState *env, unsigned long bios_offset, int64_t
stl_raw(p++, 0x34c60000 | ((ENVP_ADDR + 8) & 0xffff)); /* ori a2, a2, low(ENVP_ADDR + 8) */
stl_raw(p++, 0x3c070000 | (env->ram_size >> 16)); /* lui a3, high(env->ram_size) */
stl_raw(p++, 0x34e70000 | (env->ram_size & 0xffff)); /* ori a3, a3, low(env->ram_size) */
- stl_raw(p++, 0x3c1f0000 | ((kernel_addr >> 16) & 0xffff)); /* lui ra, high(kernel_addr) */;
- stl_raw(p++, 0x37ff0000 | (kernel_addr & 0xffff)); /* ori ra, ra, low(kernel_addr) */
+ stl_raw(p++, 0x3c1f0000 | ((kernel_entry >> 16) & 0xffff)); /* lui ra, high(kernel_entry) */
+ stl_raw(p++, 0x37ff0000 | (kernel_entry & 0xffff)); /* ori ra, ra, low(kernel_entry) */
stl_raw(p++, 0x03e00008); /* jr ra */
stl_raw(p++, 0x00000000); /* nop */
}
@@ -592,11 +592,13 @@ static void prom_set(int index, const char *string, ...)
/* Kernel */
static int64_t load_kernel (CPUState *env)
{
- int64_t kernel_addr = 0;
+ int64_t kernel_entry, kernel_low, kernel_high;
int index = 0;
long initrd_size;
+ ram_addr_t initrd_offset;
- if (load_elf(env->kernel_filename, VIRT_TO_PHYS_ADDEND, &kernel_addr) < 0) {
+ if (load_elf(env->kernel_filename, VIRT_TO_PHYS_ADDEND,
+ &kernel_entry, &kernel_low, &kernel_high) < 0) {
fprintf(stderr, "qemu: could not load kernel '%s'\n",
env->kernel_filename);
exit(1);
@@ -604,9 +606,20 @@ static int64_t load_kernel (CPUState *env)
/* load initrd */
initrd_size = 0;
+ initrd_offset = 0;
if (env->initrd_filename) {
- initrd_size = load_image(env->initrd_filename,
- phys_ram_base + INITRD_LOAD_ADDR + VIRT_TO_PHYS_ADDEND);
+ initrd_size = get_image_size (env->initrd_filename);
+ if (initrd_size > 0) {
+ initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) & TARGET_PAGE_MASK;
+ if (initrd_offset + initrd_size > env->ram_size) {
+ fprintf(stderr,
+ "qemu: memory too small for initial ram disk '%s'\n",
+ env->initrd_filename);
+ exit(1);
+ }
+ initrd_size = load_image(env->initrd_filename,
+ phys_ram_base + initrd_offset);
+ }
if (initrd_size == (target_ulong) -1) {
fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
env->initrd_filename);
@@ -617,7 +630,9 @@ static int64_t load_kernel (CPUState *env)
/* Store command line. */
prom_set(index++, env->kernel_filename);
if (initrd_size > 0)
- prom_set(index++, "rd_start=0x" TARGET_FMT_lx " rd_size=%li %s", INITRD_LOAD_ADDR, initrd_size, env->kernel_cmdline);
+ prom_set(index++, "rd_start=0x" TARGET_FMT_lx " rd_size=%li %s",
+ PHYS_TO_VIRT(initrd_offset), initrd_size,
+ env->kernel_cmdline);
else
prom_set(index++, env->kernel_cmdline);
@@ -628,7 +643,7 @@ static int64_t load_kernel (CPUState *env)
prom_set(index++, "38400n8r");
prom_set(index++, NULL);
- return kernel_addr;
+ return kernel_entry;
}
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,
{
char buf[1024];
unsigned long bios_offset;
- int64_t kernel_addr;
+ int64_t kernel_entry;
PCIBus *pci_bus;
CPUState *env;
RTCState *rtc_state;
@@ -693,8 +708,8 @@ void mips_malta_init (int ram_size, int vga_ram_size, int boot_device,
env->kernel_filename = kernel_filename;
env->kernel_cmdline = kernel_cmdline;
env->initrd_filename = initrd_filename;
- kernel_addr = load_kernel(env);
- write_bootloader(env, bios_offset, kernel_addr);
+ kernel_entry = load_kernel(env);
+ write_bootloader(env, bios_offset, kernel_entry);
} else {
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
ret = load_image(buf, phys_ram_base + bios_offset);