1 /**************************************************************************
2 *
3 * arch/mips/math_emu/kernel_linkage.c
4 *
5 * Kevin D. Kissell, kevink@mips and Carsten Langgaard, carstenl@mips.com
6 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
7 *
8 * ########################################################################
9 *
10 * This program is free software; you can distribute it and/or modify it
11 * under the terms of the GNU General Public License (Version 2) as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Routines corresponding to Linux kernel FP context
24 * manipulation primitives for the Algorithmics MIPS
25 * FPU Emulator
26 */
27 #include <linux/sched.h>
28 #include <asm/processor.h>
29 #include <asm/signal.h>
30 #include <asm/uaccess.h>
31
32 #include <asm/fpu_emulator.h>
33
34 extern struct mips_fpu_emulator_private fpuemuprivate;
35
36 #define SIGNALLING_NAN 0x7ff800007ff80000LL
37
fpu_emulator_init_fpu(void)38 void fpu_emulator_init_fpu(void)
39 {
40 static int first = 1;
41 int i;
42
43 if (first) {
44 first = 0;
45 printk("Algorithmics/MIPS FPU Emulator v1.5\n");
46 }
47
48 current->thread.fpu.soft.sr = 0;
49 for (i = 0; i < 32; i++) {
50 current->thread.fpu.soft.regs[i] = SIGNALLING_NAN;
51 }
52 }
53
54
55 /*
56 * Emulator context save/restore to/from a signal context
57 * presumed to be on the user stack, and therefore accessed
58 * with appropriate macros from uaccess.h
59 */
60
fpu_emulator_save_context(struct sigcontext * sc)61 int fpu_emulator_save_context(struct sigcontext *sc)
62 {
63 int i;
64 int err = 0;
65
66 for (i = 0; i < 32; i++) {
67 err |=
68 __put_user(current->thread.fpu.soft.regs[i],
69 &sc->sc_fpregs[i]);
70 }
71 err |= __put_user(current->thread.fpu.soft.sr, &sc->sc_fpc_csr);
72 err |= __put_user(fpuemuprivate.eir, &sc->sc_fpc_eir);
73
74 return err;
75 }
76
fpu_emulator_restore_context(struct sigcontext * sc)77 int fpu_emulator_restore_context(struct sigcontext *sc)
78 {
79 int i;
80 int err = 0;
81
82 for (i = 0; i < 32; i++) {
83 err |=
84 __get_user(current->thread.fpu.soft.regs[i],
85 &sc->sc_fpregs[i]);
86 }
87 err |= __get_user(current->thread.fpu.soft.sr, &sc->sc_fpc_csr);
88 err |= __get_user(fpuemuprivate.eir, &sc->sc_fpc_eir);
89
90 return err;
91 }
92
93 #ifdef CONFIG_MIPS64
94 /*
95 * This is the o32 version
96 */
97
fpu_emulator_save_context32(struct sigcontext32 * sc)98 int fpu_emulator_save_context32(struct sigcontext32 *sc)
99 {
100 int i;
101 int err = 0;
102
103 for (i = 0; i < 32; i+=2) {
104 err |=
105 __put_user(current->thread.fpu.soft.regs[i],
106 &sc->sc_fpregs[i]);
107 }
108 err |= __put_user(current->thread.fpu.soft.sr, &sc->sc_fpc_csr);
109 err |= __put_user(fpuemuprivate.eir, &sc->sc_fpc_eir);
110
111 return err;
112 }
113
fpu_emulator_restore_context32(struct sigcontext32 * sc)114 int fpu_emulator_restore_context32(struct sigcontext32 *sc)
115 {
116 int i;
117 int err = 0;
118
119 for (i = 0; i < 32; i+=2) {
120 err |=
121 __get_user(current->thread.fpu.soft.regs[i],
122 &sc->sc_fpregs[i]);
123 }
124 err |= __get_user(current->thread.fpu.soft.sr, &sc->sc_fpc_csr);
125 err |= __get_user(fpuemuprivate.eir, &sc->sc_fpc_eir);
126
127 return err;
128 }
129 #endif
130