blob: 52e6c58c8de1d88b12d80b6bac2872cc54bb72f6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Kevin D. Kissell, kevink@mips and Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
17 *
18 * Routines corresponding to Linux kernel FP context
19 * manipulation primitives for the Algorithmics MIPS
20 * FPU Emulator
21 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/sched.h>
23#include <asm/processor.h>
24#include <asm/signal.h>
25#include <asm/uaccess.h>
26
Dmitri Vorobievf028b862008-07-15 19:57:31 +030027#include <asm/fpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/fpu_emulator.h>
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#define SIGNALLING_NAN 0x7ff800007ff80000LL
31
32void fpu_emulator_init_fpu(void)
33{
34 static int first = 1;
35 int i;
36
37 if (first) {
38 first = 0;
39 printk("Algorithmics/MIPS FPU Emulator v1.5\n");
40 }
41
Atsushi Nemotoeae89072006-05-16 01:26:03 +090042 current->thread.fpu.fcr31 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 for (i = 0; i < 32; i++) {
Atsushi Nemotoeae89072006-05-16 01:26:03 +090044 current->thread.fpu.fpr[i] = SIGNALLING_NAN;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 }
46}
47
48
49/*
50 * Emulator context save/restore to/from a signal context
51 * presumed to be on the user stack, and therefore accessed
52 * with appropriate macros from uaccess.h
53 */
54
Atsushi Nemoto53dc8022007-03-10 01:07:45 +090055int fpu_emulator_save_context(struct sigcontext __user *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 int i;
58 int err = 0;
59
60 for (i = 0; i < 32; i++) {
61 err |=
Atsushi Nemotoeae89072006-05-16 01:26:03 +090062 __put_user(current->thread.fpu.fpr[i], &sc->sc_fpregs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 }
Atsushi Nemotoeae89072006-05-16 01:26:03 +090064 err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 return err;
67}
68
Atsushi Nemoto53dc8022007-03-10 01:07:45 +090069int fpu_emulator_restore_context(struct sigcontext __user *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
71 int i;
72 int err = 0;
73
74 for (i = 0; i < 32; i++) {
75 err |=
Atsushi Nemotoeae89072006-05-16 01:26:03 +090076 __get_user(current->thread.fpu.fpr[i], &sc->sc_fpregs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 }
Atsushi Nemotoeae89072006-05-16 01:26:03 +090078 err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 return err;
81}
82
Ralf Baechle875d43e2005-09-03 15:56:16 -070083#ifdef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
85 * This is the o32 version
86 */
87
Atsushi Nemoto53dc8022007-03-10 01:07:45 +090088int fpu_emulator_save_context32(struct sigcontext32 __user *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 int i;
91 int err = 0;
92
93 for (i = 0; i < 32; i+=2) {
94 err |=
Atsushi Nemotoeae89072006-05-16 01:26:03 +090095 __put_user(current->thread.fpu.fpr[i], &sc->sc_fpregs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
Atsushi Nemotoeae89072006-05-16 01:26:03 +090097 err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 return err;
100}
101
Atsushi Nemoto53dc8022007-03-10 01:07:45 +0900102int fpu_emulator_restore_context32(struct sigcontext32 __user *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 int i;
105 int err = 0;
106
107 for (i = 0; i < 32; i+=2) {
108 err |=
Atsushi Nemotoeae89072006-05-16 01:26:03 +0900109 __get_user(current->thread.fpu.fpr[i], &sc->sc_fpregs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
Atsushi Nemotoeae89072006-05-16 01:26:03 +0900111 err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 return err;
114}
115#endif