mirror of https://gitee.com/openkylin/qemu.git
PPC: calculate kernel,initrd,cmdline locations dynamically
During testing, I was generating a vmlinux binary that easily occupied more than 20MB of RAM. Since the current -kernel code loads the initrd at a fixed address behind the kernel, we were overwriting kernel data when the kernel got too big. To finally get rid of the issue, let's calculate the initrd and cmdline addresses relative to the kernel size, so we can have kernels and initrds that are as big as they want to - as long as they fit in RAM. Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
parent
826e7b827c
commit
b9e17a3453
|
@ -35,8 +35,7 @@
|
|||
#define PROM_ADDR 0xfff00000
|
||||
|
||||
#define KERNEL_LOAD_ADDR 0x01000000
|
||||
#define CMDLINE_ADDR 0x027ff000
|
||||
#define INITRD_LOAD_ADDR 0x02800000
|
||||
#define KERNEL_GAP 0x00100000
|
||||
|
||||
#define ESCC_CLOCK 3686400
|
||||
|
||||
|
|
|
@ -120,6 +120,11 @@ static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
|
|||
return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR;
|
||||
}
|
||||
|
||||
static target_phys_addr_t round_page(target_phys_addr_t addr)
|
||||
{
|
||||
return (addr + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
|
||||
}
|
||||
|
||||
/* PowerPC Mac99 hardware initialisation */
|
||||
static void ppc_core99_init (ram_addr_t ram_size,
|
||||
const char *boot_device,
|
||||
|
@ -134,7 +139,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
|
|||
int unin_memory;
|
||||
int linux_boot, i;
|
||||
ram_addr_t ram_offset, bios_offset;
|
||||
uint32_t kernel_base, initrd_base;
|
||||
target_phys_addr_t kernel_base, initrd_base, cmdline_base = 0;
|
||||
long kernel_size, initrd_size;
|
||||
PCIBus *pci_bus;
|
||||
MacIONVRAMState *nvr;
|
||||
|
@ -220,7 +225,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
|
|||
}
|
||||
/* load initrd */
|
||||
if (initrd_filename) {
|
||||
initrd_base = INITRD_LOAD_ADDR;
|
||||
initrd_base = round_page(kernel_base + kernel_size + KERNEL_GAP);
|
||||
initrd_size = load_image_targphys(initrd_filename, initrd_base,
|
||||
ram_size - initrd_base);
|
||||
if (initrd_size < 0) {
|
||||
|
@ -228,9 +233,11 @@ static void ppc_core99_init (ram_addr_t ram_size,
|
|||
initrd_filename);
|
||||
exit(1);
|
||||
}
|
||||
cmdline_base = round_page(initrd_base + initrd_size);
|
||||
} else {
|
||||
initrd_base = 0;
|
||||
initrd_size = 0;
|
||||
cmdline_base = round_page(kernel_base + kernel_size + KERNEL_GAP);
|
||||
}
|
||||
ppc_boot_device = 'm';
|
||||
} else {
|
||||
|
@ -373,8 +380,8 @@ static void ppc_core99_init (ram_addr_t ram_size,
|
|||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
|
||||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
|
||||
if (kernel_cmdline) {
|
||||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
|
||||
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
|
||||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
|
||||
pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
|
||||
} else {
|
||||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
|
||||
}
|
||||
|
|
|
@ -59,6 +59,11 @@ static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
|
|||
return (addr & 0x0fffffff) + KERNEL_LOAD_ADDR;
|
||||
}
|
||||
|
||||
static target_phys_addr_t round_page(target_phys_addr_t addr)
|
||||
{
|
||||
return (addr + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
|
||||
}
|
||||
|
||||
static void ppc_heathrow_init (ram_addr_t ram_size,
|
||||
const char *boot_device,
|
||||
const char *kernel_filename,
|
||||
|
@ -71,7 +76,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
|
|||
qemu_irq *pic, **heathrow_irqs;
|
||||
int linux_boot, i;
|
||||
ram_addr_t ram_offset, bios_offset;
|
||||
uint32_t kernel_base, initrd_base;
|
||||
uint32_t kernel_base, initrd_base, cmdline_base = 0;
|
||||
int32_t kernel_size, initrd_size;
|
||||
PCIBus *pci_bus;
|
||||
MacIONVRAMState *nvr;
|
||||
|
@ -157,7 +162,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
|
|||
}
|
||||
/* load initrd */
|
||||
if (initrd_filename) {
|
||||
initrd_base = INITRD_LOAD_ADDR;
|
||||
initrd_base = round_page(kernel_base + kernel_size + KERNEL_GAP);
|
||||
initrd_size = load_image_targphys(initrd_filename, initrd_base,
|
||||
ram_size - initrd_base);
|
||||
if (initrd_size < 0) {
|
||||
|
@ -165,9 +170,11 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
|
|||
initrd_filename);
|
||||
exit(1);
|
||||
}
|
||||
cmdline_base = round_page(initrd_base + initrd_size);
|
||||
} else {
|
||||
initrd_base = 0;
|
||||
initrd_size = 0;
|
||||
cmdline_base = round_page(kernel_base + kernel_size + KERNEL_GAP);
|
||||
}
|
||||
ppc_boot_device = 'm';
|
||||
} else {
|
||||
|
@ -278,8 +285,8 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
|
|||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_base);
|
||||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
|
||||
if (kernel_cmdline) {
|
||||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
|
||||
pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
|
||||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, cmdline_base);
|
||||
pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE, kernel_cmdline);
|
||||
} else {
|
||||
fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue