From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KsiJo-0004n3-OR for qemu-devel@nongnu.org; Wed, 22 Oct 2008 14:20:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KsiJl-0004ks-Fa for qemu-devel@nongnu.org; Wed, 22 Oct 2008 14:20:27 -0400 Received: from [199.232.76.173] (port=58897 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KsiJk-0004kh-WB for qemu-devel@nongnu.org; Wed, 22 Oct 2008 14:20:25 -0400 Received: from mail.codesourcery.com ([65.74.133.4]:58458) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KsiJj-0000xR-M6 for qemu-devel@nongnu.org; Wed, 22 Oct 2008 14:20:24 -0400 From: Paul Brook Date: Wed, 22 Oct 2008 19:20:09 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200810221920.09848.paul@codesourcery.com> Subject: [Qemu-devel] Use load addresses for ELF images Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org The patch below changes the system emulation ELF loader to use load addresses, not virtual addresses, when loading images. Typically a bare metal XIP application will have both data and code loaded into the rom area. The application startup code will then take care of copying the data segment to its virtual ram address. All the linux kernels I could find (and any image that doesn't deliberately do otherwise) have load address == virtual address. The new behavior is consistent with the gdb "load" command, grub, and pretty much every other ELF system loader I'm aware of. Signed-off-by: Paul Brook Index: loader.c =================================================================== --- loader.c (revision 5512) +++ loader.c (working copy) @@ -282,7 +282,7 @@ static void *load_at(int fd, int offset, #include "elf_ops.h" /* return < 0 if error, otherwise the number of bytes loaded in memory */ -int load_elf(const char *filename, int64_t virt_to_phys_addend, +int load_elf(const char *filename, int64_t address_offset, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr) { int fd, data_order, host_data_order, must_swab, ret; @@ -317,10 +317,10 @@ int load_elf(const char *filename, int64 lseek(fd, 0, SEEK_SET); if (e_ident[EI_CLASS] == ELFCLASS64) { - ret = load_elf64(fd, virt_to_phys_addend, must_swab, pentry, + ret = load_elf64(fd, address_offset, must_swab, pentry, lowaddr, highaddr); } else { - ret = load_elf32(fd, virt_to_phys_addend, must_swab, pentry, + ret = load_elf32(fd, address_offset, must_swab, pentry, lowaddr, highaddr); } Index: sysemu.h =================================================================== --- sysemu.h (revision 5512) +++ sysemu.h (working copy) @@ -160,7 +160,7 @@ extern CharDriverState *parallel_hds[MAX int get_image_size(const char *filename); int load_image(const char *filename, uint8_t *addr); /* deprecated */ int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz); -int load_elf(const char *filename, int64_t virt_to_phys_addend, +int load_elf(const char *filename, int64_t address_offset, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr); int load_aout(const char *filename, target_phys_addr_t addr, int max_sz); int load_uboot(const char *filename, target_ulong *ep, int *is_linux); Index: elf_ops.h =================================================================== --- elf_ops.h (revision 5512) +++ elf_ops.h (working copy) @@ -177,7 +177,7 @@ static int glue(load_symbols, SZ)(struct return -1; } -static int glue(load_elf, SZ)(int fd, int64_t virt_to_phys_addend, +static int glue(load_elf, SZ)(int fd, int64_t address_offset, int must_swab, uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr) { @@ -229,7 +229,9 @@ static int glue(load_elf, SZ)(int fd, in if (read(fd, data, ph->p_filesz) != ph->p_filesz) goto fail; } - addr = ph->p_vaddr + virt_to_phys_addend; + /* address_offset is hack for images that are + linked at the wrong physical address. */ + addr = ph->p_paddr + address_offset; cpu_physical_memory_write_rom(addr, data, mem_size);