Now that the sv_xmm and sv_87 fields in the pcb are the same size as the

hardware ones, and those in the mcontext, ptrace and core files we
  can really safely cast and copy between the types.
Remove a couple of temporary buffers and add CTASSERT()s that the sizes
  do actually match.
This commit is contained in:
dsl 2014-02-04 22:48:26 +00:00
parent d39376afb9
commit 5e9aed4314
2 changed files with 28 additions and 27 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.745 2014/02/02 22:41:20 dsl Exp $ */
/* $NetBSD: machdep.c,v 1.746 2014/02/04 22:48:26 dsl Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.745 2014/02/02 22:41:20 dsl Exp $");
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.746 2014/02/04 22:48:26 dsl Exp $");
#include "opt_beep.h"
#include "opt_compat_ibcs2.h"
@ -1644,14 +1644,18 @@ cpu_getmcontext(struct lwp *l, mcontext_t *mcp, unsigned int *flags)
if (pcb->pcb_fpcpu)
fpusave_lwp(l, true);
if (i386_use_fxsave) {
memcpy(&mcp->__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm,
__CTASSERT(sizeof pcb->pcb_savefpu.sv_xmm ==
sizeof mcp->__fpregs.__fp_reg_set.__fp_xmm_state);
memcpy(&mcp->__fpregs.__fp_reg_set.__fp_xmm_state,
&pcb->pcb_savefpu.sv_xmm,
sizeof (mcp->__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm));
sizeof (mcp->__fpregs.__fp_reg_set.__fp_xmm_state));
*flags |= _UC_FXSAVE;
} else {
memcpy(&mcp->__fpregs.__fp_reg_set.__fpchip_state.__fp_state,
__CTASSERT(sizeof pcb->pcb_savefpu.sv_87 ==
sizeof mcp->__fpregs.__fp_reg_set.__fpchip_state);
memcpy(&mcp->__fpregs.__fp_reg_set.__fpchip_state,
&pcb->pcb_savefpu.sv_87,
sizeof (mcp->__fpregs.__fp_reg_set.__fpchip_state.__fp_state));
sizeof (mcp->__fpregs.__fp_reg_set.__fpchip_state));
}
#if 0
/* Apparently nothing ever touches this. */
@ -1742,26 +1746,30 @@ cpu_setmcontext(struct lwp *l, const mcontext_t *mcp, unsigned int flags)
/* Restore floating point register context, if any. */
if ((flags & _UC_FPU) != 0) {
__CTASSERT(sizeof pcb->pcb_savefpu.sv_xmm ==
sizeof mcp->__fpregs.__fp_reg_set.__fp_xmm_state);
__CTASSERT(sizeof pcb->pcb_savefpu.sv_87 ==
sizeof mcp->__fpregs.__fp_reg_set.__fpchip_state);
if (flags & _UC_FXSAVE) {
if (i386_use_fxsave) {
memcpy(
&pcb->pcb_savefpu.sv_xmm,
&mcp->__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm,
sizeof (pcb->pcb_savefpu.sv_xmm));
memcpy(&pcb->pcb_savefpu.sv_xmm,
&mcp->__fpregs.__fp_reg_set.__fp_xmm_state,
sizeof (pcb->pcb_savefpu.sv_xmm));
} else {
/* This is a weird corner case */
process_xmm_to_s87((struct fxsave *)
&mcp->__fpregs.__fp_reg_set.__fp_xmm_state.__fp_xmm,
process_xmm_to_s87((const struct fxsave *)
&mcp->__fpregs.__fp_reg_set.__fp_xmm_state,
&pcb->pcb_savefpu.sv_87);
}
} else {
if (i386_use_fxsave) {
process_s87_to_xmm((struct save87 *)
&mcp->__fpregs.__fp_reg_set.__fpchip_state.__fp_state,
process_s87_to_xmm((const struct save87 *)
&mcp->__fpregs.__fp_reg_set.__fpchip_state,
&pcb->pcb_savefpu.sv_xmm);
} else {
memcpy(&pcb->pcb_savefpu.sv_87,
&mcp->__fpregs.__fp_reg_set.__fpchip_state.__fp_state,
&mcp->__fpregs.__fp_reg_set.__fpchip_state,
sizeof (pcb->pcb_savefpu.sv_87));
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: process_machdep.c,v 1.80 2014/01/26 19:16:17 dsl Exp $ */
/* $NetBSD: process_machdep.c,v 1.81 2014/02/04 22:48:26 dsl Exp $ */
/*-
* Copyright (c) 1998, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@ -52,7 +52,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.80 2014/01/26 19:16:17 dsl Exp $");
__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.81 2014/02/04 22:48:26 dsl Exp $");
#include "opt_vm86.h"
#include "opt_ptrace.h"
@ -277,12 +277,9 @@ process_read_fpregs(struct lwp *l, struct fpreg *regs, size_t *sz)
l->l_md.md_flags |= MDL_USEDFPU;
}
__CTASSERT(sizeof *regs == sizeof (struct save87));
if (i386_use_fxsave) {
struct save87 s87;
/* XXX Yuck */
process_xmm_to_s87(&frame->sv_xmm, &s87);
memcpy(regs, &s87, sizeof(*regs));
process_xmm_to_s87(&frame->sv_xmm, (struct save87 *)regs);
} else
memcpy(regs, &frame->sv_87, sizeof(*regs));
return (0);
@ -356,11 +353,7 @@ process_write_fpregs(struct lwp *l, const struct fpreg *regs, size_t sz)
}
if (i386_use_fxsave) {
struct save87 s87;
/* XXX Yuck. */
memcpy(&s87, regs, sizeof(*regs));
process_s87_to_xmm(&s87, &frame->sv_xmm);
process_s87_to_xmm((const struct save87 *)regs, &frame->sv_xmm);
} else
memcpy(&frame->sv_87, regs, sizeof(*regs));
return (0);