hw/arm/boot: Set PC correctly when loading AArch64 ELF files
PATCH 1/1 hw/arm/boot: Set PC correctly when loading AArch64 ELF files
The code in do_cpu_reset() correctly handled AArch64 CPUs when running Linux kernels, but was missing code in the branch of the if() that deals with loading ELF files. Correctly jump to the ELF entry point on reset rather than leaving the reset PC at zero.
--- hw/arm/boot.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/arm/boot.c +6 -2
@@ -417,8 +417,12 @@ static void do_cpu_reset(void *opaque)if (info) {if (!info->is_linux) {/* Jump to the entry point. */ - env->regs[15 ] = info->entry &0xfffffffe ; - env->thumb = info->entry &1 ; +if (env->aarch64) { + env->pc = info->entry; + }else { + env->regs[15 ] = info->entry &0xfffffffe ; + env->thumb = info->entry &1 ; + } }else {if (CPU (cpu) == first_cpu) {if (env->aarch64) {
Signature · 1 line
1.9.1
Quoted 5 lines · Peter Maydell
The code in
do_cpu_reset()correctly handled AArch64 CPUs when running Linux kernels, but was missing code in the branch of theif()that deals with loading ELF files. Correctly jump to the ELF entry point on reset rather than leaving the reset PC at zero.
Thanks Peter! With this patch I can see the first few instructions being executed.
(The default Newlib/libgloss wants to touch EL3 registers that QEMU doesn't yet have, but I can probably make my test case work with -nostdlib.)
Thanks,
Christopher
Signature · 3 lines
Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation.
Quoted 1 line · Peter Maydell
+ env->regs[15] =
info->entry&0xfffffffe;
You'd do well to use a U suffix here, otherwise c89 makes this -2 while c99 does what you want. Which makes a tiny difference on a 64-bit host.
r~
Quoted 5 lines · Richard Henderson
Quoted 1 line · Peter Maydell
+ env->regs[15] =
info->entry&0xfffffffe;You'd do well to use a U suffix here, otherwise c89 makes this -2 while c99 does what you want. Which makes a tiny difference on a 64-bit host.
Given that env->regs[] is uint32_t, does it actually change the final result? I agree that a U suffix would be a good idea, but given that the code has been that way since 2009 it seems unlikely that we've actually got breakage from it...
thanks
-- PMM
Quoted 2 lines · Peter Maydell
Given that env->regs[] is
uint32_t, does it actually change the final result?
Ah, no. I mis-remembered regs and xregs being shared.
r~