diff options
author | kib <kib@FreeBSD.org> | 2010-11-26 14:50:42 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2010-11-26 14:50:42 +0000 |
commit | 60c89c994a97c0fb5628378c9b8b98b4b6f96d32 (patch) | |
tree | b2b70b68cc97d1e8a719368ec7e8475bd9afc7c0 /sys/amd64 | |
parent | b2984c404f1844039344b6aa018d21ed4ee9d388 (diff) | |
download | FreeBSD-src-60c89c994a97c0fb5628378c9b8b98b4b6f96d32.zip FreeBSD-src-60c89c994a97c0fb5628378c9b8b98b4b6f96d32.tar.gz |
Remove npxgetregs(), npxsetregs(), fpugetregs() and fpusetregs()
functions, they are unused. Remove 'user' from npxgetuserregs()
etc. names.
For {npx,fpu}{get,set}regs(), always use pcb->pcb_user_save for FPU
context storage. This eliminates the need for ugly copying with
overwrite of the newly added and reserved fields in ucontext on i386
to satisfy alignment requirements for fpusave() and fpurstor().
pc98 version was copied from i386.
Suggested and reviewed by: bde
Tested by: pho (i386 and amd64)
MFC after: 1 week
Diffstat (limited to 'sys/amd64')
-rw-r--r-- | sys/amd64/amd64/fpu.c | 69 | ||||
-rw-r--r-- | sys/amd64/amd64/machdep.c | 10 | ||||
-rw-r--r-- | sys/amd64/ia32/ia32_reg.c | 14 | ||||
-rw-r--r-- | sys/amd64/ia32/ia32_signal.c | 7 | ||||
-rw-r--r-- | sys/amd64/include/fpu.h | 5 |
5 files changed, 41 insertions, 64 deletions
diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index 4b1583a..482b5da 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -426,9 +426,7 @@ fpudna(void) fxrstor(&fpu_initialstate); if (pcb->pcb_initial_fpucw != __INITIAL_FPUCW__) fldcw(pcb->pcb_initial_fpucw); - pcb->pcb_flags |= PCB_FPUINITDONE; - if (PCB_USER_FPU(pcb)) - pcb->pcb_flags |= PCB_USERFPUINITDONE; + fpuuserinited(curthread); } else fxrstor(pcb->pcb_save); critical_exit(); @@ -448,60 +446,50 @@ fpudrop() } /* - * Get the state of the FPU without dropping ownership (if possible). - * It returns the FPU ownership status. + * Get the user state of the FPU into pcb->pcb_user_save without + * dropping ownership (if possible). It returns the FPU ownership + * status. */ int -fpugetuserregs(struct thread *td, struct savefpu *addr) +fpugetregs(struct thread *td) { struct pcb *pcb; pcb = td->td_pcb; if ((pcb->pcb_flags & PCB_USERFPUINITDONE) == 0) { - bcopy(&fpu_initialstate, addr, sizeof(fpu_initialstate)); - addr->sv_env.en_cw = pcb->pcb_initial_fpucw; - return (_MC_FPOWNED_NONE); + bcopy(&fpu_initialstate, &pcb->pcb_user_save, + sizeof(fpu_initialstate)); + pcb->pcb_user_save.sv_env.en_cw = pcb->pcb_initial_fpucw; + fpuuserinited(td); + return (_MC_FPOWNED_PCB); } critical_enter(); if (td == PCPU_GET(fpcurthread) && PCB_USER_FPU(pcb)) { - fxsave(addr); + fxsave(&pcb->pcb_user_save); critical_exit(); return (_MC_FPOWNED_FPU); } else { critical_exit(); - bcopy(&pcb->pcb_user_save, addr, sizeof(*addr)); return (_MC_FPOWNED_PCB); } } -int -fpugetregs(struct thread *td, struct savefpu *addr) +void +fpuuserinited(struct thread *td) { struct pcb *pcb; pcb = td->td_pcb; - if ((pcb->pcb_flags & PCB_FPUINITDONE) == 0) { - bcopy(&fpu_initialstate, addr, sizeof(fpu_initialstate)); - addr->sv_env.en_cw = pcb->pcb_initial_fpucw; - return (_MC_FPOWNED_NONE); - } - critical_enter(); - if (td == PCPU_GET(fpcurthread)) { - fxsave(addr); - critical_exit(); - return (_MC_FPOWNED_FPU); - } else { - critical_exit(); - bcopy(pcb->pcb_save, addr, sizeof(*addr)); - return (_MC_FPOWNED_PCB); - } + if (PCB_USER_FPU(pcb)) + pcb->pcb_flags |= PCB_FPUINITDONE; + pcb->pcb_flags |= PCB_USERFPUINITDONE; } /* * Set the state of the FPU. */ void -fpusetuserregs(struct thread *td, struct savefpu *addr) +fpusetregs(struct thread *td, struct savefpu *addr) { struct pcb *pcb; @@ -514,29 +502,8 @@ fpusetuserregs(struct thread *td, struct savefpu *addr) } else { critical_exit(); bcopy(addr, &td->td_pcb->pcb_user_save, sizeof(*addr)); - if (PCB_USER_FPU(pcb)) - pcb->pcb_flags |= PCB_FPUINITDONE; - pcb->pcb_flags |= PCB_USERFPUINITDONE; - } -} - -void -fpusetregs(struct thread *td, struct savefpu *addr) -{ - struct pcb *pcb; - - pcb = td->td_pcb; - critical_enter(); - if (td == PCPU_GET(fpcurthread)) { - fxrstor(addr); - critical_exit(); - } else { - critical_exit(); - bcopy(addr, td->td_pcb->pcb_save, sizeof(*addr)); + fpuuserinited(td); } - if (PCB_USER_FPU(pcb)) - pcb->pcb_flags |= PCB_USERFPUINITDONE; - pcb->pcb_flags |= PCB_FPUINITDONE; } /* diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 738427f..194cf71 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -1975,6 +1975,8 @@ int fill_fpregs(struct thread *td, struct fpreg *fpregs) { + KASSERT(TD_IS_SUSPENDED(td), ("not suspended thread %p", td)); + fpugetregs(td); fill_fpregs_xmm(&td->td_pcb->pcb_user_save, fpregs); return (0); } @@ -1985,6 +1987,7 @@ set_fpregs(struct thread *td, struct fpreg *fpregs) { set_fpregs_xmm(fpregs, &td->td_pcb->pcb_user_save); + fpuuserinited(td); return (0); } @@ -2099,8 +2102,9 @@ static void get_fpcontext(struct thread *td, mcontext_t *mcp) { - mcp->mc_ownedfp = fpugetuserregs(td, - (struct savefpu *)&mcp->mc_fpstate); + mcp->mc_ownedfp = fpugetregs(td); + bcopy(&td->td_pcb->pcb_user_save, &mcp->mc_fpstate, + sizeof(mcp->mc_fpstate)); mcp->mc_fpformat = fpuformat(); } @@ -2120,7 +2124,7 @@ set_fpcontext(struct thread *td, const mcontext_t *mcp) mcp->mc_ownedfp == _MC_FPOWNED_PCB) { fpstate = (struct savefpu *)&mcp->mc_fpstate; fpstate->sv_env.en_mxcsr &= cpu_mxcsr_mask; - fpusetuserregs(td, fpstate); + fpusetregs(td, fpstate); } else return (EINVAL); return (0); diff --git a/sys/amd64/ia32/ia32_reg.c b/sys/amd64/ia32/ia32_reg.c index 30fcffb..da6eb0f 100644 --- a/sys/amd64/ia32/ia32_reg.c +++ b/sys/amd64/ia32/ia32_reg.c @@ -145,13 +145,18 @@ set_regs32(struct thread *td, struct reg32 *regs) int fill_fpregs32(struct thread *td, struct fpreg32 *regs) { - struct save87 *sv_87 = (struct save87 *)regs; - struct env87 *penv_87 = &sv_87->sv_env; - struct savefpu *sv_fpu = &td->td_pcb->pcb_user_save; - struct envxmm *penv_xmm = &sv_fpu->sv_env; + struct savefpu *sv_fpu; + struct save87 *sv_87; + struct env87 *penv_87; + struct envxmm *penv_xmm; int i; bzero(regs, sizeof(*regs)); + sv_87 = (struct save87 *)regs; + penv_87 = &sv_87->sv_env; + fpugetregs(td); + sv_fpu = &td->td_pcb->pcb_user_save; + penv_xmm = &sv_fpu->sv_env; /* FPU control/status */ penv_87->en_cw = penv_xmm->en_cw; @@ -200,6 +205,7 @@ set_fpregs32(struct thread *td, struct fpreg32 *regs) sv_fpu->sv_fp[i].fp_acc = sv_87->sv_ac[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); return (0); } diff --git a/sys/amd64/ia32/ia32_signal.c b/sys/amd64/ia32/ia32_signal.c index d85a3bb..aefe9f0 100644 --- a/sys/amd64/ia32/ia32_signal.c +++ b/sys/amd64/ia32/ia32_signal.c @@ -99,8 +99,9 @@ ia32_get_fpcontext(struct thread *td, struct ia32_mcontext *mcp) * 64bit instruction and data pointers. Ignore the difference * for now, it should be irrelevant for most applications. */ - mcp->mc_ownedfp = fpugetuserregs(td, - (struct savefpu *)&mcp->mc_fpstate); + mcp->mc_ownedfp = fpugetregs(td); + bcopy(&td->td_pcb->pcb_user_save, &mcp->mc_fpstate, + sizeof(mcp->mc_fpstate)); mcp->mc_fpformat = fpuformat(); } @@ -117,7 +118,7 @@ ia32_set_fpcontext(struct thread *td, const struct ia32_mcontext *mcp) fpstate_drop(td); else if (mcp->mc_ownedfp == _MC_FPOWNED_FPU || mcp->mc_ownedfp == _MC_FPOWNED_PCB) { - fpusetuserregs(td, (struct savefpu *)&mcp->mc_fpstate); + fpusetregs(td, (struct savefpu *)&mcp->mc_fpstate); } else return (EINVAL); return (0); diff --git a/sys/amd64/include/fpu.h b/sys/amd64/include/fpu.h index ca0ac8f..50b3819 100644 --- a/sys/amd64/include/fpu.h +++ b/sys/amd64/include/fpu.h @@ -112,12 +112,11 @@ void fpudna(void); void fpudrop(void); void fpuexit(struct thread *td); int fpuformat(void); -int fpugetregs(struct thread *td, struct savefpu *addr); -int fpugetuserregs(struct thread *td, struct savefpu *addr); +int fpugetregs(struct thread *td); void fpuinit(void); void fpusetregs(struct thread *td, struct savefpu *addr); -void fpusetuserregs(struct thread *td, struct savefpu *addr); int fputrap(void); +void fpuuserinited(struct thread *td); int fpu_kern_enter(struct thread *td, struct fpu_kern_ctx *ctx, u_int flags); int fpu_kern_leave(struct thread *td, struct fpu_kern_ctx *ctx); |