[PATCH 22/23] Add set_mcontext function for ARM AArch64 in bsd-user

Ajeet Singh posted 23 patches 5 months, 1 week ago
Only 22 patches received!
There is a newer version of this series
[PATCH 22/23] Add set_mcontext function for ARM AArch64 in bsd-user
Posted by Ajeet Singh 5 months, 1 week ago
From: Stacey Son <sson@FreeBSD.org>

The function copies register values from the provided target_mcontext_t
structure to the CPUARMState registers

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Ajeet Singh <itachis@FreeBSD.org>
---
 bsd-user/aarch64/signal.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c
index 43c886e603..13faac8ce6 100644
--- a/bsd-user/aarch64/signal.c
+++ b/bsd-user/aarch64/signal.c
@@ -95,3 +95,25 @@ abi_long setup_sigframe_arch(CPUARMState *env, abi_ulong frame_addr,
     return 0;
 }
 
+/*
+ * Compare to set_mcontext() in arm64/arm64/machdep.c
+ * Assumes that the memory is locked if frame points to user memory.
+ */
+abi_long set_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int srflag)
+{
+    int err = 0, i;
+    const uint64_t *gr = mcp->mc_gpregs.gp_x;
+
+    for (i = 0; i < 30; i++) {
+        regs->xregs[i] = tswap64(gr[i]);
+    }
+
+    regs->xregs[TARGET_REG_SP] = tswap64(mcp->mc_gpregs.gp_sp);
+    regs->xregs[TARGET_REG_LR] = tswap64(mcp->mc_gpregs.gp_lr);
+    regs->pc = mcp->mc_gpregs.gp_elr;
+    pstate_write(regs, mcp->mc_gpregs.gp_spsr);
+
+    /* XXX FP? */
+
+    return err;
+}
-- 
2.34.1
Re: [PATCH 22/23] Add set_mcontext function for ARM AArch64 in bsd-user
Posted by Richard Henderson 5 months, 1 week ago
On 6/17/24 11:58, Ajeet Singh wrote:
> From: Stacey Son <sson@FreeBSD.org>
> 
> The function copies register values from the provided target_mcontext_t
> structure to the CPUARMState registers
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Ajeet Singh <itachis@FreeBSD.org>
> ---
>   bsd-user/aarch64/signal.c | 22 ++++++++++++++++++++++
>   1 file changed, 22 insertions(+)
> 
> diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c
> index 43c886e603..13faac8ce6 100644
> --- a/bsd-user/aarch64/signal.c
> +++ b/bsd-user/aarch64/signal.c
> @@ -95,3 +95,25 @@ abi_long setup_sigframe_arch(CPUARMState *env, abi_ulong frame_addr,
>       return 0;
>   }
>   
> +/*
> + * Compare to set_mcontext() in arm64/arm64/machdep.c
> + * Assumes that the memory is locked if frame points to user memory.
> + */
> +abi_long set_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int srflag)
> +{
> +    int err = 0, i;
> +    const uint64_t *gr = mcp->mc_gpregs.gp_x;
> +
> +    for (i = 0; i < 30; i++) {
> +        regs->xregs[i] = tswap64(gr[i]);
> +    }
> +
> +    regs->xregs[TARGET_REG_SP] = tswap64(mcp->mc_gpregs.gp_sp);
> +    regs->xregs[TARGET_REG_LR] = tswap64(mcp->mc_gpregs.gp_lr);
> +    regs->pc = mcp->mc_gpregs.gp_elr;

tswap.

> +    pstate_write(regs, mcp->mc_gpregs.gp_spsr);
> +
> +    /* XXX FP? */

Similarly, see target_restore_fpsimd_record.


r~
Re: [PATCH 22/23] Add set_mcontext function for ARM AArch64 in bsd-user
Posted by Warner Losh 5 months ago
On Tue, Jun 18, 2024 at 4:51 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 6/17/24 11:58, Ajeet Singh wrote:
> > From: Stacey Son <sson@FreeBSD.org>
> >
> > The function copies register values from the provided target_mcontext_t
> > structure to the CPUARMState registers
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Ajeet Singh <itachis@FreeBSD.org>
> > ---
> >   bsd-user/aarch64/signal.c | 22 ++++++++++++++++++++++
> >   1 file changed, 22 insertions(+)
> >
> > diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c
> > index 43c886e603..13faac8ce6 100644
> > --- a/bsd-user/aarch64/signal.c
> > +++ b/bsd-user/aarch64/signal.c
> > @@ -95,3 +95,25 @@ abi_long setup_sigframe_arch(CPUARMState *env,
> abi_ulong frame_addr,
> >       return 0;
> >   }
> >
> > +/*
> > + * Compare to set_mcontext() in arm64/arm64/machdep.c
> > + * Assumes that the memory is locked if frame points to user memory.
> > + */
> > +abi_long set_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int
> srflag)
> > +{
> > +    int err = 0, i;
> > +    const uint64_t *gr = mcp->mc_gpregs.gp_x;
> > +
> > +    for (i = 0; i < 30; i++) {
> > +        regs->xregs[i] = tswap64(gr[i]);
> > +    }
> > +
> > +    regs->xregs[TARGET_REG_SP] = tswap64(mcp->mc_gpregs.gp_sp);
> > +    regs->xregs[TARGET_REG_LR] = tswap64(mcp->mc_gpregs.gp_lr);
> > +    regs->pc = mcp->mc_gpregs.gp_elr;
>
> tswap.
>

So "regs->pc = tswap64(mcp->mc_gpregs.gp_elr)"  then?


> > +    pstate_write(regs, mcp->mc_gpregs.gp_spsr);
> > +
> > +    /* XXX FP? */
>
> Similarly, see target_restore_fpsimd_record.
>

Since neither this, nor the get_mcontext is written for FP on upstream yet,
can we do those as a followup commit?

Warner


>
> r~
>
Re: [PATCH 22/23] Add set_mcontext function for ARM AArch64 in bsd-user
Posted by Richard Henderson 5 months ago
On 6/23/24 08:54, Warner Losh wrote:
> 
> 
> On Tue, Jun 18, 2024 at 4:51 PM Richard Henderson <richard.henderson@linaro.org 
> <mailto:richard.henderson@linaro.org>> wrote:
> 
>     On 6/17/24 11:58, Ajeet Singh wrote:
>      > From: Stacey Son <sson@FreeBSD.org>
>      >
>      > The function copies register values from the provided target_mcontext_t
>      > structure to the CPUARMState registers
>      >
>      > Signed-off-by: Stacey Son <sson@FreeBSD.org>
>      > Signed-off-by: Ajeet Singh <itachis@FreeBSD.org>
>      > ---
>      >   bsd-user/aarch64/signal.c | 22 ++++++++++++++++++++++
>      >   1 file changed, 22 insertions(+)
>      >
>      > diff --git a/bsd-user/aarch64/signal.c b/bsd-user/aarch64/signal.c
>      > index 43c886e603..13faac8ce6 100644
>      > --- a/bsd-user/aarch64/signal.c
>      > +++ b/bsd-user/aarch64/signal.c
>      > @@ -95,3 +95,25 @@ abi_long setup_sigframe_arch(CPUARMState *env, abi_ulong frame_addr,
>      >       return 0;
>      >   }
>      >
>      > +/*
>      > + * Compare to set_mcontext() in arm64/arm64/machdep.c
>      > + * Assumes that the memory is locked if frame points to user memory.
>      > + */
>      > +abi_long set_mcontext(CPUARMState *regs, target_mcontext_t *mcp, int srflag)
>      > +{
>      > +    int err = 0, i;
>      > +    const uint64_t *gr = mcp->mc_gpregs.gp_x;
>      > +
>      > +    for (i = 0; i < 30; i++) {
>      > +        regs->xregs[i] = tswap64(gr[i]);
>      > +    }
>      > +
>      > +    regs->xregs[TARGET_REG_SP] = tswap64(mcp->mc_gpregs.gp_sp);
>      > +    regs->xregs[TARGET_REG_LR] = tswap64(mcp->mc_gpregs.gp_lr);
>      > +    regs->pc = mcp->mc_gpregs.gp_elr;
> 
>     tswap.
> 
> 
> So "regs->pc = tswap64(mcp->mc_gpregs.gp_elr)"  then?

Yes.

> 
>      > +    pstate_write(regs, mcp->mc_gpregs.gp_spsr);
>      > +
>      > +    /* XXX FP? */
> 
>     Similarly, see target_restore_fpsimd_record.
> 
> 
> Since neither this, nor the get_mcontext is written for FP on upstream yet, can we do 
> those as a followup commit?

Yes.


r~