diff mbox series

[06/23] Add Aarch64 register handling

Message ID 20240617185804.25075-7-itachis@FreeBSD.org (mailing list archive)
State New, archived
Headers show
Series ARM AArch64 Support for BSD | expand

Commit Message

Ajeet Singh June 17, 2024, 6:57 p.m. UTC
From: Stacey Son <sson@FreeBSD.org>

Header file for managing CPU register states in
FreeBSD user mode

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Ajeet Singh <itachis@FreeBSD.org>
---
 bsd-user/aarch64/target_arch_reg.h | 56 ++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 bsd-user/aarch64/target_arch_reg.h

Comments

Richard Henderson June 18, 2024, 4:35 a.m. UTC | #1
On 6/17/24 11:57, Ajeet Singh wrote:
> From: Stacey Son <sson@FreeBSD.org>
> 
> Header file for managing CPU register states in
> FreeBSD user mode
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Ajeet Singh <itachis@FreeBSD.org>
> ---
>   bsd-user/aarch64/target_arch_reg.h | 56 ++++++++++++++++++++++++++++++
>   1 file changed, 56 insertions(+)
>   create mode 100644 bsd-user/aarch64/target_arch_reg.h
> 
> diff --git a/bsd-user/aarch64/target_arch_reg.h b/bsd-user/aarch64/target_arch_reg.h
> new file mode 100644
> index 0000000000..5c7154f0c1
> --- /dev/null
> +++ b/bsd-user/aarch64/target_arch_reg.h
> @@ -0,0 +1,56 @@
> +/*
> + *  FreeBSD arm64 register structures
> + *
> + *  Copyright (c) 2015 Stacey Son
> + *  All rights reserved.
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + *
> + *  This program is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with this program; if not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef TARGET_ARCH_REG_H
> +#define TARGET_ARCH_REG_H
> +
> +/* See sys/arm64/include/reg.h */
> +typedef struct target_reg {
> +    uint64_t        x[30];
> +    uint64_t        lr;
> +    uint64_t        sp;
> +    uint64_t        elr;
> +    uint64_t        spsr;
> +} target_reg_t;
> +
> +typedef struct target_fpreg {
> +    __uint128_t     fp_q[32];

I'm not keen on this, though possibly it doesn't matter for hosts that bsd-user is 
intended to support.  Better as either Int128 or uint64_t fp_q[32][2].

What is this structure used for within qemu?
Does freebsd support SVE yet?

It's certainly not used with this patch, so it's hard to tell, but can we omit it entirely 
for now?


r~
Warner Losh June 23, 2024, 8:37 p.m. UTC | #2
On Mon, Jun 17, 2024 at 10:35 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 6/17/24 11:57, Ajeet Singh wrote:
> > From: Stacey Son <sson@FreeBSD.org>
> >
> > Header file for managing CPU register states in
> > FreeBSD user mode
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Ajeet Singh <itachis@FreeBSD.org>
> > ---
> >   bsd-user/aarch64/target_arch_reg.h | 56 ++++++++++++++++++++++++++++++
> >   1 file changed, 56 insertions(+)
> >   create mode 100644 bsd-user/aarch64/target_arch_reg.h
> >
> > diff --git a/bsd-user/aarch64/target_arch_reg.h
> b/bsd-user/aarch64/target_arch_reg.h
> > new file mode 100644
> > index 0000000000..5c7154f0c1
> > --- /dev/null
> > +++ b/bsd-user/aarch64/target_arch_reg.h
> > @@ -0,0 +1,56 @@
> > +/*
> > + *  FreeBSD arm64 register structures
> > + *
> > + *  Copyright (c) 2015 Stacey Son
> > + *  All rights reserved.
> > + *
> > + *  This program is free software; you can redistribute it and/or modify
> > + *  it under the terms of the GNU General Public License as published by
> > + *  the Free Software Foundation; either version 2 of the License, or
> > + *  (at your option) any later version.
> > + *
> > + *  This program is distributed in the hope that it will be useful,
> > + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + *  GNU General Public License for more details.
> > + *
> > + *  You should have received a copy of the GNU General Public License
> > + *  along with this program; if not, see <http://www.gnu.org/licenses/
> >.
> > + */
> > +
> > +#ifndef TARGET_ARCH_REG_H
> > +#define TARGET_ARCH_REG_H
> > +
> > +/* See sys/arm64/include/reg.h */
> > +typedef struct target_reg {
> > +    uint64_t        x[30];
> > +    uint64_t        lr;
> > +    uint64_t        sp;
> > +    uint64_t        elr;
> > +    uint64_t        spsr;
> > +} target_reg_t;
> > +
> > +typedef struct target_fpreg {
> > +    __uint128_t     fp_q[32];
>
> I'm not keen on this, though possibly it doesn't matter for hosts that
> bsd-user is
> intended to support.  Better as either Int128 or uint64_t fp_q[32][2].
>

OK. We don't use In128 anywhere today, but it's an easy change.


> What is this structure used for within qemu?
>

Yes. target_fpreg_t is used by the generic core dump code. This reserves
the proper amount of space for it. IIRC, gdb gets cranky if you don't, but
that memory is "dim" in my head, so maybe that problem was corrected ages
ago.


> Does freebsd support SVE yet?
>

Yes. But as later patches show bsd-user does not. I need to add that
support. None of our target applications seem to care, but that might just
be because the wrong answers are produced w/o a crash and there's enough
other crashes that it hasn't percolated up to the top of anybody's queue...


> It's certainly not used with this patch, so it's hard to tell, but can we
> omit it entirely
> for now?
>

It will be necessary for the core dump stuff, though I suppose it's all 0's
right now.  And core dumps are a low-priority item, but it just has to be
SOMETHING, so I propose we just change it here (and in
target_arch_signal.h) to be Int128 and then the future set of changes that
will add FP support for signals, etc will make whatever tweaks / fixes are
needed then.

Warner
diff mbox series

Patch

diff --git a/bsd-user/aarch64/target_arch_reg.h b/bsd-user/aarch64/target_arch_reg.h
new file mode 100644
index 0000000000..5c7154f0c1
--- /dev/null
+++ b/bsd-user/aarch64/target_arch_reg.h
@@ -0,0 +1,56 @@ 
+/*
+ *  FreeBSD arm64 register structures
+ *
+ *  Copyright (c) 2015 Stacey Son
+ *  All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TARGET_ARCH_REG_H
+#define TARGET_ARCH_REG_H
+
+/* See sys/arm64/include/reg.h */
+typedef struct target_reg {
+    uint64_t        x[30];
+    uint64_t        lr;
+    uint64_t        sp;
+    uint64_t        elr;
+    uint64_t        spsr;
+} target_reg_t;
+
+typedef struct target_fpreg {
+    __uint128_t     fp_q[32];
+    uint32_t        fp_sr;
+    uint32_t        fp_cr;
+} target_fpreg_t;
+
+#define tswapreg(ptr)   tswapal(ptr)
+
+static inline void target_copy_regs(target_reg_t *regs, CPUARMState *env)
+{
+    int i;
+
+    for (i = 0; i < 30; i++) {
+        regs->x[i] = tswapreg(env->xregs[i]);
+    }
+    regs->lr = tswapreg(env->xregs[30]);
+    regs->sp = tswapreg(env->xregs[31]);
+    regs->elr = tswapreg(env->pc);
+    regs->spsr = tswapreg(pstate_read(env));
+}
+
+#undef tswapreg
+
+#endif /* TARGET_ARCH_REG_H */