| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: fpu.c,v 1.43 2018/06/23 10:06:02 maxv Exp $ */ | | 1 | /* $NetBSD: fpu.c,v 1.44 2018/06/29 19:34:35 maxv Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. All | | 4 | * Copyright (c) 2008 The NetBSD Foundation, Inc. All |
5 | * rights reserved. | | 5 | * rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software developed for The NetBSD Foundation | | 7 | * This code is derived from software developed for The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -86,27 +86,27 @@ | | | @@ -86,27 +86,27 @@ |
86 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 86 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
87 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 87 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
88 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 88 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
89 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 89 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
90 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 90 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
91 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 91 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
92 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 92 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
93 | * SUCH DAMAGE. | | 93 | * SUCH DAMAGE. |
94 | * | | 94 | * |
95 | * @(#)npx.c 7.2 (Berkeley) 5/12/91 | | 95 | * @(#)npx.c 7.2 (Berkeley) 5/12/91 |
96 | */ | | 96 | */ |
97 | | | 97 | |
98 | #include <sys/cdefs.h> | | 98 | #include <sys/cdefs.h> |
99 | __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.43 2018/06/23 10:06:02 maxv Exp $"); | | 99 | __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.44 2018/06/29 19:34:35 maxv Exp $"); |
100 | | | 100 | |
101 | #include "opt_multiprocessor.h" | | 101 | #include "opt_multiprocessor.h" |
102 | | | 102 | |
103 | #include <sys/param.h> | | 103 | #include <sys/param.h> |
104 | #include <sys/systm.h> | | 104 | #include <sys/systm.h> |
105 | #include <sys/conf.h> | | 105 | #include <sys/conf.h> |
106 | #include <sys/cpu.h> | | 106 | #include <sys/cpu.h> |
107 | #include <sys/file.h> | | 107 | #include <sys/file.h> |
108 | #include <sys/proc.h> | | 108 | #include <sys/proc.h> |
109 | #include <sys/kernel.h> | | 109 | #include <sys/kernel.h> |
110 | #include <sys/sysctl.h> | | 110 | #include <sys/sysctl.h> |
111 | #include <sys/xcall.h> | | 111 | #include <sys/xcall.h> |
112 | | | 112 | |
| @@ -349,26 +349,40 @@ fpu_eagerrestore(struct lwp *l) | | | @@ -349,26 +349,40 @@ fpu_eagerrestore(struct lwp *l) |
349 | KASSERT(ci->ci_fpcurlwp == NULL); | | 349 | KASSERT(ci->ci_fpcurlwp == NULL); |
350 | KASSERT(pcb->pcb_fpcpu == NULL); | | 350 | KASSERT(pcb->pcb_fpcpu == NULL); |
351 | ci->ci_fpcurlwp = l; | | 351 | ci->ci_fpcurlwp = l; |
352 | pcb->pcb_fpcpu = ci; | | 352 | pcb->pcb_fpcpu = ci; |
353 | fpu_restore(l); | | 353 | fpu_restore(l); |
354 | } | | 354 | } |
355 | | | 355 | |
356 | void | | 356 | void |
357 | fpu_eagerswitch(struct lwp *oldlwp, struct lwp *newlwp) | | 357 | fpu_eagerswitch(struct lwp *oldlwp, struct lwp *newlwp) |
358 | { | | 358 | { |
359 | int s; | | 359 | int s; |
360 | | | 360 | |
361 | s = splhigh(); | | 361 | s = splhigh(); |
| | | 362 | #ifdef DIAGNOSTIC |
| | | 363 | if (oldlwp != NULL) { |
| | | 364 | struct pcb *pcb = lwp_getpcb(oldlwp); |
| | | 365 | struct cpu_info *ci = curcpu(); |
| | | 366 | if (pcb->pcb_fpcpu == NULL) { |
| | | 367 | KASSERT(ci->ci_fpcurlwp != oldlwp); |
| | | 368 | } else if (pcb->pcb_fpcpu == ci) { |
| | | 369 | KASSERT(ci->ci_fpcurlwp == oldlwp); |
| | | 370 | } else { |
| | | 371 | panic("%s: oldlwp's state installed elsewhere", |
| | | 372 | __func__); |
| | | 373 | } |
| | | 374 | } |
| | | 375 | #endif |
362 | fpusave_cpu(true); | | 376 | fpusave_cpu(true); |
363 | if (!(newlwp->l_flag & LW_SYSTEM)) | | 377 | if (!(newlwp->l_flag & LW_SYSTEM)) |
364 | fpu_eagerrestore(newlwp); | | 378 | fpu_eagerrestore(newlwp); |
365 | splx(s); | | 379 | splx(s); |
366 | } | | 380 | } |
367 | | | 381 | |
368 | /* -------------------------------------------------------------------------- */ | | 382 | /* -------------------------------------------------------------------------- */ |
369 | | | 383 | |
370 | /* | | 384 | /* |
371 | * This is a synchronous trap on either an x87 instruction (due to an | | 385 | * This is a synchronous trap on either an x87 instruction (due to an |
372 | * unmasked error on the previous x87 instruction) or on an SSE/SSE2 etc | | 386 | * unmasked error on the previous x87 instruction) or on an SSE/SSE2 etc |
373 | * instruction due to an error on the instruction itself. | | 387 | * instruction due to an error on the instruction itself. |
374 | * | | 388 | * |