On Wed, 30 Jul 2025 at 01:21, Richard Henderson
<richard.hender...@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.hender...@linaro.org>
> ---
>  linux-user/arm/cpu_loop.c | 53 ++++++++++++++++++++++++++++++++-------
>  linux-user/elfload.c      | 41 +-----------------------------
>  2 files changed, 45 insertions(+), 49 deletions(-)
>
> diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
> index 1f3bb96484..8974b35e8d 100644
> --- a/linux-user/arm/cpu_loop.c
> +++ b/linux-user/arm/cpu_loop.c
> @@ -480,19 +480,54 @@ void cpu_loop(CPUARMState *env)
>      }
>  }
>
> -void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
> +void init_main_thread(CPUState *cs, struct image_info *info)
>  {
> -    cpsr_write(env, regs->uregs[16], CPSR_USER | CPSR_EXEC,
> -               CPSRWriteByInstr);
> -    for (int i = 0; i < 16; i++) {
> -        env->regs[i] = regs->uregs[i];
> +    CPUARMState *env = cpu_env(cs);
> +    abi_ptr stack = info->start_stack;
> +    abi_ptr entry = info->entry;
> +
> +    cpsr_write(env, ARM_CPU_MODE_USR | (entry & 1 ? CPSR_T : 0),
> +               CPSR_USER | CPSR_EXEC, CPSRWriteByInstr);
> +
> +    env->regs[15] = entry & 0xfffffffe;
> +    env->regs[13] = stack;
> +
> +    /* FIXME - what to for failure of get_user()? */
> +    /* FIXME - a modern kernel does not do this? */
> +    get_user_ual(env->regs[2], stack + 8); /* envp */
> +    get_user_ual(env->regs[1], stack + 4); /* envp */

This seems to have originally been in the kernel as
a half-hearted attempt to support a.out format:
kernel commit acfdd4b1f7590d0 from 2013 removed the
setting up of r1 and r2 along with the rest of that
partial a.out handling. (The commit message explains the
confused kernel handling of r0 which is the origin of our
"/* XXX: it seems that r0 is zeroed after ! */" comment.)

QEMU has never supported a.out binaries, so we should
clean this up too...

Anyway, this patch is just moving code around, so
Reviewed-by: Peter Maydell <peter.mayd...@linaro.org>

thanks
-- PMM

Reply via email to