[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH rc2 18/25] hw/core/loader: Let load_elf populate the processor-sp
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH rc2 18/25] hw/core/loader: Let load_elf populate the processor-specific flags |
Date: |
Fri, 24 Jan 2020 01:51:24 +0100 |
One some architectures (like AVR) we can determine
the cpu type by reading the ELF flags.
Signed-off-by: Michael Rolnik <address@hidden>
Reviewed-by: Aleksandar Markovic <address@hidden>
Message-Id: <<address@hidden>
[PMD: Extracted from bigger patch,
Replaced 'uint32_t *pe_flags' by 'int proc_flags']
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
include/hw/elf_ops.h | 6 +++++-
include/hw/loader.h | 6 ++++--
hw/core/loader.c | 15 ++++++++-------
hw/riscv/boot.c | 2 +-
4 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index e07d276df7..5d0f9587d3 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -316,7 +316,8 @@ static int glue(load_elf, SZ)(const char *name, int fd,
void *translate_opaque,
int must_swab, uint64_t *pentry,
uint64_t *lowaddr, uint64_t *highaddr,
- int elf_machine, int clear_lsb, int data_swab,
+ int *proc_flags, int elf_machine,
+ int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom,
symbol_fn_t sym_cb)
{
@@ -389,6 +390,9 @@ static int glue(load_elf, SZ)(const char *name, int fd,
}
}
+ if (proc_flags) {
+ *proc_flags = (elf_sword)ehdr.e_flags;
+ }
if (pentry)
*pentry = (uint64_t)(elf_sword)ehdr.e_entry;
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 48a96cd559..cc5ede7b90 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -101,6 +101,7 @@ const char *load_elf_strerror(int error);
* @pentry: Populated with program entry point. Ignored if NULL.
* @lowaddr: Populated with lowest loaded address. Ignored if NULL.
* @highaddr: Populated with highest loaded address. Ignored if NULL.
+ * @proc_flags: Populated with ELF processor-specific flags. Ignore if NULL.
* @bigendian: Expected ELF endianness. 0 for LE otherwise BE
* @elf_machine: Expected ELF machine type
* @clear_lsb: Set to mask off LSB of addresses (Some architectures use
@@ -131,8 +132,9 @@ int load_elf_ram_sym(const char *filename,
uint64_t (*elf_note_fn)(void *, void *, bool),
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry,
- uint64_t *lowaddr, uint64_t *highaddr, int big_endian,
- int elf_machine, int clear_lsb, int data_swab,
+ uint64_t *lowaddr, uint64_t *highaddr, int *proc_flags,
+ int big_endian, int elf_machine,
+ int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom, symbol_fn_t sym_cb);
/** load_elf_ram:
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 5099f27dc8..3bee2f8ae0 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -438,7 +438,7 @@ int load_elf_ram(const char *filename,
{
return load_elf_ram_sym(filename, elf_note_fn,
translate_fn, translate_opaque,
- pentry, lowaddr, highaddr, big_endian,
+ pentry, lowaddr, highaddr, NULL, big_endian,
elf_machine, clear_lsb, data_swab, as,
load_rom, NULL);
}
@@ -448,8 +448,9 @@ int load_elf_ram_sym(const char *filename,
uint64_t (*elf_note_fn)(void *, void *, bool),
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry,
- uint64_t *lowaddr, uint64_t *highaddr, int big_endian,
- int elf_machine, int clear_lsb, int data_swab,
+ uint64_t *lowaddr, uint64_t *highaddr, int *proc_flags,
+ int big_endian, int elf_machine,
+ int clear_lsb, int data_swab,
AddressSpace *as, bool load_rom, symbol_fn_t sym_cb)
{
int fd, data_order, target_data_order, must_swab, ret = ELF_LOAD_FAILED;
@@ -490,13 +491,13 @@ int load_elf_ram_sym(const char *filename,
if (e_ident[EI_CLASS] == ELFCLASS64) {
ret = load_elf64(filename, fd, elf_note_fn,
translate_fn, translate_opaque, must_swab,
- pentry, lowaddr, highaddr, elf_machine, clear_lsb,
- data_swab, as, load_rom, sym_cb);
+ pentry, lowaddr, highaddr, proc_flags, elf_machine,
+ clear_lsb, data_swab, as, load_rom, sym_cb);
} else {
ret = load_elf32(filename, fd, elf_note_fn,
translate_fn, translate_opaque, must_swab,
- pentry, lowaddr, highaddr, elf_machine, clear_lsb,
- data_swab, as, load_rom, sym_cb);
+ pentry, lowaddr, highaddr, proc_flags, elf_machine,
+ clear_lsb, data_swab, as, load_rom, sym_cb);
}
fail:
diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
index 027303d2a3..746ca1f795 100644
--- a/hw/riscv/boot.c
+++ b/hw/riscv/boot.c
@@ -119,7 +119,7 @@ target_ulong riscv_load_kernel(const char *kernel_filename,
symbol_fn_t sym_cb)
uint64_t kernel_entry, kernel_high;
if (load_elf_ram_sym(kernel_filename, NULL, NULL, NULL,
- &kernel_entry, NULL, &kernel_high, 0,
+ &kernel_entry, NULL, &kernel_high, NULL, 0,
EM_RISCV, 1, 0, NULL, true, sym_cb) > 0) {
return kernel_entry;
}
--
2.21.1
- [PATCH rc2 12/25] hw/timer: Add limited support for Atmel 16 bit timer peripheral, (continued)
- [PATCH rc2 15/25] target/avr: Register AVR support with the rest of QEMU, Philippe Mathieu-Daudé, 2020/01/23
- [PATCH rc2 16/25] target/avr: Add machine none test, Philippe Mathieu-Daudé, 2020/01/23
- [PATCH rc2 17/25] target/avr: Update MAINTAINERS file, Philippe Mathieu-Daudé, 2020/01/23
- [PATCH rc2 18/25] hw/core/loader: Let load_elf populate the processor-specific flags,
Philippe Mathieu-Daudé <=
- [PATCH rc2 19/25] hw/avr: Add helper to load raw/ELF firmware binaries, Philippe Mathieu-Daudé, 2020/01/23
- [PATCH rc2 21/25] hw/avr: Add some Arduino boards, Philippe Mathieu-Daudé, 2020/01/23
- [PATCH rc2 20/25] hw/avr: Add some ATmega microcontrollers, Philippe Mathieu-Daudé, 2020/01/23
[PATCH rc2 22/25] target/avr: Update build system, Philippe Mathieu-Daudé, 2020/01/23
[PATCH rc2 23/25] tests/boot-serial-test: Test some Arduino boards (AVR based), Philippe Mathieu-Daudé, 2020/01/23