Skip to content

Commit

Permalink
Translate between abridged and full x87 tags for compat32
Browse files Browse the repository at this point in the history
ptrace(PT_GETFPREGS).

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
  • Loading branch information
kostikbel committed Jun 24, 2017
1 parent f7df80f commit c377ff6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions sys/amd64/ia32/ia32_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fill_fpregs32(struct thread *td, struct fpreg32 *regs)
/* FPU control/status */
penv_87->en_cw = penv_xmm->en_cw;
penv_87->en_sw = penv_xmm->en_sw;
penv_87->en_tw = penv_xmm->en_tw;

/*
* XXX for en_fip/fcs/foo/fos, check if the fxsave format
* uses the old-style layout for 32 bit user apps. If so,
Expand All @@ -170,9 +170,13 @@ fill_fpregs32(struct thread *td, struct fpreg32 *regs)
/* Entry into the kernel always sets TF_HASSEGS */
penv_87->en_fos = td->td_frame->tf_ds;

/* FPU registers */
for (i = 0; i < 8; ++i)
/* FPU registers and tags */
penv_87->en_tw = 0xffff;
for (i = 0; i < 8; ++i) {
sv_87->sv_ac[i] = sv_fpu->sv_fp[i].fp_acc;
if ((penv_xmm->en_tw & (1 << i)) != 0)
penv_87->en_tw &= ~(3 << i * 2);
}

return (0);
}
Expand All @@ -189,15 +193,19 @@ set_fpregs32(struct thread *td, struct fpreg32 *regs)
/* FPU control/status */
penv_xmm->en_cw = penv_87->en_cw;
penv_xmm->en_sw = penv_87->en_sw;
penv_xmm->en_tw = penv_87->en_tw;
penv_xmm->en_rip = penv_87->en_fip;
/* penv_87->en_fcs and en_fos ignored, see above */
penv_xmm->en_opcode = penv_87->en_opcode;
penv_xmm->en_rdp = penv_87->en_foo;

/* FPU registers */
for (i = 0; i < 8; ++i)
/* FPU registers and tags */
penv_xmm->en_tw = 0;
for (i = 0; i < 8; ++i) {
sv_fpu->sv_fp[i].fp_acc = sv_87->sv_ac[i];
if ((penv_87->en_tw & (3 << i * 2)) != (3 << i * 2))
penv_xmm->en_tw |= 1 << i;
}

for (i = 8; i < 16; ++i)
bzero(&sv_fpu->sv_fp[i].fp_acc, sizeof(sv_fpu->sv_fp[i].fp_acc));
fpuuserinited(td);
Expand Down

0 comments on commit c377ff6

Please sign in to comment.