Re: arm64 fpu fixes

2017-04-11 Thread Mark Kettenis
> Date: Mon, 10 Apr 2017 18:10:28 -0700
> From: Philip Guenther 
> 
> On Mon, 10 Apr 2017, Mark Kettenis wrote:
> > Diff below revises the struct fpreg definition and enables the dumping 
> > of fpu registers in core dumps.  That pointed out that we need to reset 
> > the FPU state upon exec.
> > 
> > ok?
> 
> ok guenther@
> 
> Hmm, the consequences of __uint128_t are non-trivial.  Are {,u}intmax_t 
> 128bit types on arm64?

No, they're still 64-bit:

$ clang -dM -E - < /dev/null | grep __INTMAX_TYPE
#define __INTMAX_TYPE__ long long int

Note that clang provides 128-bit integer types on more (all?)
platforms.  The situation on amd64 is exactly the same.  Newer
versions of gcc also provide a 128-bit integer type.  Perhaps the C
standard will catch up at some point.  On the other hand, changing the
intmax_t type will be an ABI break so you can count on the Linux folks
bending backwards to avoid changing it.

We should probably just go with the flow.  The 128-bit types are only
used in specific non-standard contexts right now, so there is no
immediate problem.



Re: arm64 fpu fixes

2017-04-10 Thread Philip Guenther
On Mon, 10 Apr 2017, Mark Kettenis wrote:
> Diff below revises the struct fpreg definition and enables the dumping 
> of fpu registers in core dumps.  That pointed out that we need to reset 
> the FPU state upon exec.
> 
> ok?

ok guenther@

Hmm, the consequences of __uint128_t are non-trivial.  Are {,u}intmax_t 
128bit types on arm64?



arm64 fpu fixes

2017-04-10 Thread Mark Kettenis
Diff below revises the struct fpreg definition and enables the dumping
of fpu registers in core dumps.  That pointed out that we need to
reset the FPU state upon exec.

ok?


Index: arch/arm64/arm64/machdep.c
===
RCS file: /cvs/src/sys/arch/arm64/arm64/machdep.c,v
retrieving revision 1.12
diff -u -p -r1.12 machdep.c
--- arch/arm64/arm64/machdep.c  13 Mar 2017 00:53:56 -  1.12
+++ arch/arm64/arm64/machdep.c  10 Apr 2017 11:10:43 -
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -454,6 +455,11 @@ setregs(struct proc *p, struct exec_pack
 register_t *retval)
 {
struct trapframe *tf;
+
+   /* If we were using the FPU, forget about it. */
+   if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
+   vfp_discard(p);
+   p->p_addr->u_pcb.pcb_flags &= ~PCB_FPU;
 
tf = p->p_addr->u_pcb.pcb_tf;
 
Index: arch/arm64/arm64/process_machdep.c
===
RCS file: /cvs/src/sys/arch/arm64/arm64/process_machdep.c,v
retrieving revision 1.2
diff -u -p -r1.2 process_machdep.c
--- arch/arm64/arm64/process_machdep.c  21 Mar 2017 18:43:40 -  1.2
+++ arch/arm64/arm64/process_machdep.c  10 Apr 2017 11:10:43 -
@@ -68,7 +68,11 @@ process_read_regs(struct proc *p, struct
 int
 process_read_fpregs(struct proc *p, struct fpreg *regs)
 {
-   memset(regs, 0, sizeof(*regs));
+   if (p->p_addr->u_pcb.pcb_flags & PCB_FPU)
+   memcpy(regs, >p_addr->u_pcb.pcb_fpstate, sizeof(*regs));
+   else
+   memset(regs, 0, sizeof(*regs));
+
return(0);
 }
 
Index: arch/arm64/include/reg.h
===
RCS file: /cvs/src/sys/arch/arm64/include/reg.h,v
retrieving revision 1.2
diff -u -p -r1.2 reg.h
--- arch/arm64/include/reg.h21 Mar 2017 18:43:40 -  1.2
+++ arch/arm64/include/reg.h10 Apr 2017 11:10:43 -
@@ -28,7 +28,7 @@ struct reg {
 };
 
 struct fpreg {
-   uint64_tfp_registers[64]; // really 32 128 bit registers.
+   __uint128_t fp_reg[32];
uint32_tfp_sr;
uint32_tfp_cr;
 };