| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/sched.h> | 
 | 23 | #include <asm/processor.h> | 
 | 24 | #include <asm/signal.h> | 
 | 25 | #include <asm/uaccess.h> | 
 | 26 |  | 
 | 27 | #include <asm/fpu_emulator.h> | 
 | 28 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #define SIGNALLING_NAN 0x7ff800007ff80000LL | 
 | 30 |  | 
 | 31 | void fpu_emulator_init_fpu(void) | 
 | 32 | { | 
 | 33 | 	static int first = 1; | 
 | 34 | 	int i; | 
 | 35 |  | 
 | 36 | 	if (first) { | 
 | 37 | 		first = 0; | 
 | 38 | 		printk("Algorithmics/MIPS FPU Emulator v1.5\n"); | 
 | 39 | 	} | 
 | 40 |  | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 41 | 	current->thread.fpu.fcr31 = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | 	for (i = 0; i < 32; i++) { | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 43 | 		current->thread.fpu.fpr[i] = SIGNALLING_NAN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | 	} | 
 | 45 | } | 
 | 46 |  | 
 | 47 |  | 
 | 48 | /* | 
 | 49 |  * Emulator context save/restore to/from a signal context | 
 | 50 |  * presumed to be on the user stack, and therefore accessed | 
 | 51 |  * with appropriate macros from uaccess.h | 
 | 52 |  */ | 
 | 53 |  | 
 | 54 | int fpu_emulator_save_context(struct sigcontext *sc) | 
 | 55 | { | 
 | 56 | 	int i; | 
 | 57 | 	int err = 0; | 
 | 58 |  | 
 | 59 | 	for (i = 0; i < 32; i++) { | 
 | 60 | 		err |= | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 61 | 		    __put_user(current->thread.fpu.fpr[i], &sc->sc_fpregs[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | 	} | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 63 | 	err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 |  | 
 | 65 | 	return err; | 
 | 66 | } | 
 | 67 |  | 
 | 68 | int fpu_emulator_restore_context(struct sigcontext *sc) | 
 | 69 | { | 
 | 70 | 	int i; | 
 | 71 | 	int err = 0; | 
 | 72 |  | 
 | 73 | 	for (i = 0; i < 32; i++) { | 
 | 74 | 		err |= | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 75 | 		    __get_user(current->thread.fpu.fpr[i], &sc->sc_fpregs[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | 	} | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 77 | 	err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 |  | 
 | 79 | 	return err; | 
 | 80 | } | 
 | 81 |  | 
| Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 82 | #ifdef CONFIG_64BIT | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* | 
 | 84 |  * This is the o32 version | 
 | 85 |  */ | 
 | 86 |  | 
 | 87 | int fpu_emulator_save_context32(struct sigcontext32 *sc) | 
 | 88 | { | 
 | 89 | 	int i; | 
 | 90 | 	int err = 0; | 
 | 91 |  | 
 | 92 | 	for (i = 0; i < 32; i+=2) { | 
 | 93 | 		err |= | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 94 | 		    __put_user(current->thread.fpu.fpr[i], &sc->sc_fpregs[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | 	} | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 96 | 	err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 |  | 
 | 98 | 	return err; | 
 | 99 | } | 
 | 100 |  | 
 | 101 | int fpu_emulator_restore_context32(struct sigcontext32 *sc) | 
 | 102 | { | 
 | 103 | 	int i; | 
 | 104 | 	int err = 0; | 
 | 105 |  | 
 | 106 | 	for (i = 0; i < 32; i+=2) { | 
 | 107 | 		err |= | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 108 | 		    __get_user(current->thread.fpu.fpr[i], &sc->sc_fpregs[i]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | 	} | 
| Atsushi Nemoto | eae8907 | 2006-05-16 01:26:03 +0900 | [diff] [blame] | 110 | 	err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 |  | 
 | 112 | 	return err; | 
 | 113 | } | 
 | 114 | #endif |