| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: mips_fpu.c,v 1.15 2017/05/07 05:45:07 skrll Exp $ */ | | 1 | /* $NetBSD: mips_fpu.c,v 1.16 2021/05/11 14:41:08 simonb Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2010 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2010 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Matt Thomas of 3am Software Foundry. | | 8 | * by Matt Thomas of 3am Software Foundry. |
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. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: mips_fpu.c,v 1.15 2017/05/07 05:45:07 skrll Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: mips_fpu.c,v 1.16 2021/05/11 14:41:08 simonb Exp $"); |
34 | | | 34 | |
35 | #include <sys/param.h> | | 35 | #include <sys/param.h> |
36 | #include <sys/mutex.h> | | 36 | #include <sys/mutex.h> |
37 | #include <sys/condvar.h> | | 37 | #include <sys/condvar.h> |
38 | #include <sys/cpu.h> | | 38 | #include <sys/cpu.h> |
39 | #include <sys/proc.h> | | 39 | #include <sys/proc.h> |
40 | #include <sys/lwp.h> | | 40 | #include <sys/lwp.h> |
41 | #include <sys/pcu.h> | | 41 | #include <sys/pcu.h> |
42 | | | 42 | |
43 | #include <mips/locore.h> | | 43 | #include <mips/locore.h> |
44 | #include <mips/regnum.h> | | 44 | #include <mips/regnum.h> |
45 | #include <mips/pcb.h> | | 45 | #include <mips/pcb.h> |
46 | | | 46 | |
| @@ -69,27 +69,27 @@ fpu_load(void) | | | @@ -69,27 +69,27 @@ fpu_load(void) |
69 | | | 69 | |
70 | void | | 70 | void |
71 | fpu_save(lwp_t *l) | | 71 | fpu_save(lwp_t *l) |
72 | { | | 72 | { |
73 | pcu_save(&mips_fpu_ops, l); | | 73 | pcu_save(&mips_fpu_ops, l); |
74 | } | | 74 | } |
75 | | | 75 | |
76 | bool | | 76 | bool |
77 | fpu_used_p(const lwp_t *l) | | 77 | fpu_used_p(const lwp_t *l) |
78 | { | | 78 | { |
79 | return pcu_valid_p(&mips_fpu_ops, l); | | 79 | return pcu_valid_p(&mips_fpu_ops, l); |
80 | } | | 80 | } |
81 | | | 81 | |
82 | void | | 82 | static void |
83 | mips_fpu_state_save(lwp_t *l) | | 83 | mips_fpu_state_save(lwp_t *l) |
84 | { | | 84 | { |
85 | struct trapframe * const tf = l->l_md.md_utf; | | 85 | struct trapframe * const tf = l->l_md.md_utf; |
86 | #ifndef __mips_soft_float | | 86 | #ifndef __mips_soft_float |
87 | struct pcb * const pcb = lwp_getpcb(l); | | 87 | struct pcb * const pcb = lwp_getpcb(l); |
88 | mips_fpreg_t * const fp = pcb->pcb_fpregs.r_regs; | | 88 | mips_fpreg_t * const fp = pcb->pcb_fpregs.r_regs; |
89 | #endif | | 89 | #endif |
90 | uint32_t status, fpcsr; | | 90 | uint32_t status, fpcsr; |
91 | | | 91 | |
92 | /* | | 92 | /* |
93 | * Don't do anything if the FPU is already off. | | 93 | * Don't do anything if the FPU is already off. |
94 | */ | | 94 | */ |
95 | if ((tf->tf_regs[_R_SR] & MIPS_SR_COP_1_BIT) == 0) | | 95 | if ((tf->tf_regs[_R_SR] & MIPS_SR_COP_1_BIT) == 0) |
| @@ -196,27 +196,27 @@ mips_fpu_state_save(lwp_t *l) | | | @@ -196,27 +196,27 @@ mips_fpu_state_save(lwp_t *l) |
196 | "swc1 $f28, (28*%d1)(%0) ;" | | 196 | "swc1 $f28, (28*%d1)(%0) ;" |
197 | "swc1 $f29, (29*%d1)(%0) ;" | | 197 | "swc1 $f29, (29*%d1)(%0) ;" |
198 | "swc1 $f30, (30*%d1)(%0) ;" | | 198 | "swc1 $f30, (30*%d1)(%0) ;" |
199 | "swc1 $f31, (31*%d1)(%0) ;" | | 199 | "swc1 $f31, (31*%d1)(%0) ;" |
200 | ".set reorder" :: "r"(fp), "i"(4)); | | 200 | ".set reorder" :: "r"(fp), "i"(4)); |
201 | } | | 201 | } |
202 | #endif | | 202 | #endif |
203 | /* | | 203 | /* |
204 | * stop COP1 | | 204 | * stop COP1 |
205 | */ | | 205 | */ |
206 | __asm volatile ("mtc0 %0, $%1" :: "r"(status), "n"(MIPS_COP_0_STATUS)); | | 206 | __asm volatile ("mtc0 %0, $%1" :: "r"(status), "n"(MIPS_COP_0_STATUS)); |
207 | } | | 207 | } |
208 | | | 208 | |
209 | void | | 209 | static void |
210 | mips_fpu_state_load(lwp_t *l, u_int flags) | | 210 | mips_fpu_state_load(lwp_t *l, u_int flags) |
211 | { | | 211 | { |
212 | struct trapframe * const tf = l->l_md.md_utf; | | 212 | struct trapframe * const tf = l->l_md.md_utf; |
213 | struct pcb * const pcb = lwp_getpcb(l); | | 213 | struct pcb * const pcb = lwp_getpcb(l); |
214 | #ifndef __mips_soft_float | | 214 | #ifndef __mips_soft_float |
215 | mips_fpreg_t * const fp = pcb->pcb_fpregs.r_regs; | | 215 | mips_fpreg_t * const fp = pcb->pcb_fpregs.r_regs; |
216 | #endif | | 216 | #endif |
217 | uint32_t status; | | 217 | uint32_t status; |
218 | uint32_t fpcsr; | | 218 | uint32_t fpcsr; |
219 | | | 219 | |
220 | l->l_cpu->ci_ev_fpu_loads.ev_count++; | | 220 | l->l_cpu->ci_ev_fpu_loads.ev_count++; |
221 | | | 221 | |
222 | /* | | 222 | /* |
| @@ -340,18 +340,18 @@ mips_fpu_state_load(lwp_t *l, u_int flag | | | @@ -340,18 +340,18 @@ mips_fpu_state_load(lwp_t *l, u_int flag |
340 | */ | | 340 | */ |
341 | __asm volatile( | | 341 | __asm volatile( |
342 | ".set noreorder" "\n\t" | | 342 | ".set noreorder" "\n\t" |
343 | ".set noat" "\n\t" | | 343 | ".set noat" "\n\t" |
344 | "ctc1 %0, $31" "\n\t" | | 344 | "ctc1 %0, $31" "\n\t" |
345 | "nop" "\n\t" /* XXX: Hack */ | | 345 | "nop" "\n\t" /* XXX: Hack */ |
346 | "mtc0 %1, $%2" "\n\t" | | 346 | "mtc0 %1, $%2" "\n\t" |
347 | ".set at" "\n\t" | | 347 | ".set at" "\n\t" |
348 | ".set reorder" "\n\t" | | 348 | ".set reorder" "\n\t" |
349 | :: "r"(fpcsr &~ MIPS_FPU_EXCEPTION_BITS), "r"(status), | | 349 | :: "r"(fpcsr &~ MIPS_FPU_EXCEPTION_BITS), "r"(status), |
350 | "n"(MIPS_COP_0_STATUS)); | | 350 | "n"(MIPS_COP_0_STATUS)); |
351 | } | | 351 | } |
352 | | | 352 | |
353 | void | | 353 | static void |
354 | mips_fpu_state_release(lwp_t *l) | | 354 | mips_fpu_state_release(lwp_t *l) |
355 | { | | 355 | { |
356 | l->l_md.md_utf->tf_regs[_R_SR] &= ~MIPS_SR_COP_1_BIT; | | 356 | l->l_md.md_utf->tf_regs[_R_SR] &= ~MIPS_SR_COP_1_BIT; |
357 | } | | 357 | } |