qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 14/30] bsd-user/arm/target_arch_thread.h: Routines to crea


From: Warner Losh
Subject: Re: [PATCH v2 14/30] bsd-user/arm/target_arch_thread.h: Routines to create and switch to a thread
Date: Wed, 3 Nov 2021 12:27:38 -0600


[[ Adding Olivier Houchard to confirm my reading of the ARM init twisty maze of code ]]
On Tue, Nov 2, 2021 at 9:31 PM Richard Henderson <richard.henderson@linaro.org> wrote:
On 11/2/21 6:52 PM, Warner Losh wrote:
> +    /*
> +     * Thumb mode is encoded by the low bit in the entry point (since ARM can't
> +     * execute at odd addresses). When it's set, set the Thumb bit (T) in the
> +     * CPSR.
> +     */
> +    if (entry & 0x1) {
> +        cpsr_write(env, cpsr_read(env) | CPSR_T, CPSR_T, CPSRWriteByInstr);
> +    }

This should be

   cpsr_write(env, (entry & 1) * CPSR_T, CPSR_T, CPSRWriteByInstr);

because you need to clear T for arm mode as well.

Ah. Right. I'd intended to fix this, but it slipped my mind (along with the other T bit thing you told me about).
 
> +    /* FIXME - what to for failure of get_user()? */
> +    get_user_ual(regs->ARM_r2, stack + 8); /* envp */
> +    get_user_ual(regs->ARM_r1, stack + 4); /* envp */

Surely these values are present in image_info anyway?

The host versions are in image_info, but the target versions are not.  Linux-user does a similar
thing without the #define sugar form ARM_rX. I didn't see where the current bsd-user squirrels
this information away (it's computed and stored in local variables), nor did my much more
brief look at linux-user. 

Looking at the FreeBSD kernel, though, we don't set r1 or r2. r0 and r1 are set to 0 explicitly,
and r2 is set to 0 because the first user registers are all cleared. In the static case, they
are ignored (since r0 = ps_strings, r1 = obj_main (unused) and r2 = cleanup (also
unused in the static case). If we're entering via the dynamic loader, it saves r0 and generates
r1 (though it's ultimately unused) and r2 (which rtld sets to its cleanup routine). r0 is the ps
strings that ps displays, so isn't relevant to emulation.

tl;dr: I'll add a comment to that effect and make it simpler (assuming my analysis survives)

Warner

reply via email to

[Prev in Thread] Current Thread [Next in Thread]