[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/6] hw/loader: Pass ELFDATA endian order argument to load_elf_ra
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 4/6] hw/loader: Pass ELFDATA endian order argument to load_elf_ram_sym() |
Date: |
Mon, 27 Jan 2025 12:38:22 +0100 |
Rather than passing a boolean 'is_big_endian' argument,
directly pass the ELFDATA, which can be unspecified using
the ELFDATANONE value.
Update the call sites:
0 -> ELFDATA2LSB
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/loader.h | 4 ++--
hw/core/loader.c | 23 ++++++++++-------------
hw/riscv/boot.c | 3 ++-
3 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 9bb34e6f062..8202c376043 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -120,7 +120,7 @@ const char *load_elf_strerror(ssize_t error);
* @lowaddr: Populated with lowest loaded address. Ignored if NULL.
* @highaddr: Populated with highest loaded address. Ignored if NULL.
* @pflags: Populated with ELF processor-specific flags. Ignore if NULL.
- * @bigendian: Expected ELF endianness. 0 for LE otherwise BE
+ * @elf_data_order: Expected ELF endianness (ELFDATA2LSB or ELFDATA2MSB).
* @elf_machine: Expected ELF machine type
* @clear_lsb: Set to mask off LSB of addresses (Some architectures use
* this for non-address data)
@@ -151,7 +151,7 @@ ssize_t load_elf_ram_sym(const char *filename,
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry,
uint64_t *lowaddr, uint64_t *highaddr,
- uint32_t *pflags, int big_endian, int elf_machine,
+ uint32_t *pflags, int elf_data_order, int elf_machine,
int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom, symbol_fn_t sym_cb);
diff --git a/hw/core/loader.c b/hw/core/loader.c
index fc2e8f91267..0cd34425e9c 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -428,7 +428,8 @@ ssize_t load_elf_as(const char *filename,
{
return load_elf_ram_sym(filename, elf_note_fn,
translate_fn, translate_opaque,
- pentry, lowaddr, highaddr, pflags, big_endian,
+ pentry, lowaddr, highaddr, pflags,
+ big_endian ? ELFDATA2MSB : ELFDATA2LSB,
elf_machine, clear_lsb, data_swab, as,
true, NULL);
}
@@ -439,11 +440,11 @@ ssize_t load_elf_ram_sym(const char *filename,
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry,
uint64_t *lowaddr, uint64_t *highaddr,
- uint32_t *pflags, int big_endian, int elf_machine,
+ uint32_t *pflags, int elf_data_order, int elf_machine,
int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom, symbol_fn_t sym_cb)
{
- int fd, host_data_order, target_data_order, must_swab;
+ int fd, host_data_order, must_swab;
ssize_t ret = ELF_LOAD_FAILED;
uint8_t e_ident[EI_NIDENT];
@@ -461,22 +462,18 @@ ssize_t load_elf_ram_sym(const char *filename,
ret = ELF_LOAD_NOT_ELF;
goto fail;
}
+
+ if (elf_data_order != ELFDATANONE && elf_data_order != e_ident[EI_DATA]) {
+ ret = ELF_LOAD_WRONG_ENDIAN;
+ goto fail;
+ }
+
#if HOST_BIG_ENDIAN
host_data_order = ELFDATA2MSB;
#else
host_data_order = ELFDATA2LSB;
#endif
must_swab = host_data_order != e_ident[EI_DATA];
- if (big_endian) {
- target_data_order = ELFDATA2MSB;
- } else {
- target_data_order = ELFDATA2LSB;
- }
-
- if (target_data_order != e_ident[EI_DATA]) {
- ret = ELF_LOAD_WRONG_ENDIAN;
- goto fail;
- }
lseek(fd, 0, SEEK_SET);
if (e_ident[EI_CLASS] == ELFCLASS64) {
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 90e75c69a04..c309441b7d8 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -246,7 +246,8 @@ void riscv_load_kernel(MachineState *machine,
*/
kernel_size = load_elf_ram_sym(kernel_filename, NULL, NULL, NULL, NULL,
&info->image_low_addr,
&info->image_high_addr,
- NULL, 0, EM_RISCV, 1, 0, NULL, true,
sym_cb);
+ NULL, ELFDATA2LSB, EM_RISCV,
+ 1, 0, NULL, true, sym_cb);
if (kernel_size > 0) {
info->kernel_size = kernel_size;
goto out;
--
2.47.1
- [PATCH 0/6] hw/loader: Pass ELFDATA endian order argument to load_elf(), Philippe Mathieu-Daudé, 2025/01/27
- [PATCH 1/6] hw/avr/boot: Replace load_elf_ram_sym() -> load_elf_as(), Philippe Mathieu-Daudé, 2025/01/27
- [PATCH 2/6] hw/loader: Remove unused load_elf_ram(), Philippe Mathieu-Daudé, 2025/01/27
- [PATCH 3/6] hw/loader: Clarify local variable name in load_elf_ram_sym(), Philippe Mathieu-Daudé, 2025/01/27
- [PATCH 4/6] hw/loader: Pass ELFDATA endian order argument to load_elf_ram_sym(),
Philippe Mathieu-Daudé <=
- [PATCH 5/6] hw/loader: Pass ELFDATA endian order argument to load_elf_as(), Philippe Mathieu-Daudé, 2025/01/27
- [PATCH 6/6] hw/loader: Pass ELFDATA endian order argument to load_elf(), Philippe Mathieu-Daudé, 2025/01/27
- Re: [PATCH 0/6] hw/loader: Pass ELFDATA endian order argument to load_elf(), Philippe Mathieu-Daudé, 2025/01/30