[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 68/74] hw/rx: Handle a kernel file that is ELF
From: |
Richard Henderson |
Subject: |
[PATCH v2 68/74] hw/rx: Handle a kernel file that is ELF |
Date: |
Tue, 3 May 2022 12:48:37 -0700 |
Attempt to load the kernel with load_elf. If this fails with
ELF_LOAD_NOT_ELF, continue to treat the kernel as a raw image.
This will be handy for running semihosting programs.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
hw/rx/rx-gdbsim.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c
index be147b4bd9..64b533181d 100644
--- a/hw/rx/rx-gdbsim.c
+++ b/hw/rx/rx-gdbsim.c
@@ -26,6 +26,7 @@
#include "sysemu/device_tree.h"
#include "hw/boards.h"
#include "qom/object.h"
+#include "elf.h"
/* Same address of GDB integrated simulator */
#define SDRAM_BASE EXT_CS_BASE
@@ -57,15 +58,32 @@ static void rx_load_image(RXCPU *cpu, const char *filename,
uint32_t start, uint32_t size)
{
static uint32_t extable[32];
- long kernel_size;
+ ssize_t kernel_size;
+ uint64_t kernel_entry;
int i;
+ /* Try an ELF image first. */
+
+ kernel_size = load_elf(filename, NULL, NULL, NULL, &kernel_entry,
+ NULL, NULL, NULL, false, EM_RX, false, false);
+ if (kernel_size >= 0) {
+ cpu_set_pc(CPU(cpu), kernel_entry);
+ return;
+ }
+ if (kernel_size != ELF_LOAD_NOT_ELF) {
+ error_report("could not load kernel '%s': %s",
+ filename, load_elf_strerror(kernel_size));
+ exit(1);
+ }
+
+ /* Not ELF: load a raw image, e.g. zImage. */
+
kernel_size = load_image_targphys(filename, start, size);
if (kernel_size < 0) {
- fprintf(stderr, "qemu: could not load kernel '%s'\n", filename);
+ error_report("could not load kernel '%s'", filename);
exit(1);
}
- cpu->env.pc = start;
+ cpu_set_pc(CPU(cpu), start);
/* setup exception trap trampoline */
/* linux kernel only works little-endian mode */
--
2.34.1
- [PATCH v2 65/74] target/xtensa: Use an exception for semihosting, (continued)
- [PATCH v2 65/74] target/xtensa: Use an exception for semihosting, Richard Henderson, 2022/05/03
- [PATCH v2 61/74] target/mips: Use error_report for UHI_assert, Richard Henderson, 2022/05/03
- [PATCH v2 67/74] tests/docker: Add debian-rx-cross image, Richard Henderson, 2022/05/03
- [PATCH v2 64/74] target/mips: Remove GET_TARGET_STRING and FREE_TARGET_STRING, Richard Henderson, 2022/05/03
- [PATCH v2 69/74] target/rx: Fix the base of the fixed vector table, Richard Henderson, 2022/05/03
- [PATCH v2 73/74] target/rx: Implement libgloss semihosting, Richard Henderson, 2022/05/03
- [PATCH v2 71/74] target/rx: Consolidate exception helpers, Richard Henderson, 2022/05/03
- [PATCH v2 74/74] tests/tcg/rx: Enable semihosting multiarch tests, Richard Henderson, 2022/05/03
- [PATCH v2 62/74] semihosting: Remove qemu_semihosting_log_out, Richard Henderson, 2022/05/03
- [PATCH v2 66/74] target/xtensa: Use semihosting/syscalls.h, Richard Henderson, 2022/05/03
- [PATCH v2 68/74] hw/rx: Handle a kernel file that is ELF,
Richard Henderson <=
- [PATCH v2 72/74] target/rx: Cleanup rx_cpu_do_interrupt, Richard Henderson, 2022/05/03
- [PATCH v2 70/74] target/rx: Name the exceptions, Richard Henderson, 2022/05/03