| 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 | */ | 
|  | 22 | #include <linux/config.h> | 
|  | 23 | #include <linux/sched.h> | 
|  | 24 | #include <asm/processor.h> | 
|  | 25 | #include <asm/signal.h> | 
|  | 26 | #include <asm/uaccess.h> | 
|  | 27 |  | 
|  | 28 | #include <asm/fpu_emulator.h> | 
|  | 29 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #define SIGNALLING_NAN 0x7ff800007ff80000LL | 
|  | 31 |  | 
|  | 32 | void 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 |  | 
|  | 42 | current->thread.fpu.soft.fcr31 = 0; | 
|  | 43 | for (i = 0; i < 32; i++) { | 
|  | 44 | current->thread.fpu.soft.fpr[i] = SIGNALLING_NAN; | 
|  | 45 | } | 
|  | 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 |  | 
|  | 55 | int fpu_emulator_save_context(struct sigcontext *sc) | 
|  | 56 | { | 
|  | 57 | int i; | 
|  | 58 | int err = 0; | 
|  | 59 |  | 
|  | 60 | for (i = 0; i < 32; i++) { | 
|  | 61 | err |= | 
|  | 62 | __put_user(current->thread.fpu.soft.fpr[i], | 
|  | 63 | &sc->sc_fpregs[i]); | 
|  | 64 | } | 
|  | 65 | err |= __put_user(current->thread.fpu.soft.fcr31, &sc->sc_fpc_csr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  | 
|  | 67 | return err; | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | int fpu_emulator_restore_context(struct sigcontext *sc) | 
|  | 71 | { | 
|  | 72 | int i; | 
|  | 73 | int err = 0; | 
|  | 74 |  | 
|  | 75 | for (i = 0; i < 32; i++) { | 
|  | 76 | err |= | 
|  | 77 | __get_user(current->thread.fpu.soft.fpr[i], | 
|  | 78 | &sc->sc_fpregs[i]); | 
|  | 79 | } | 
|  | 80 | err |= __get_user(current->thread.fpu.soft.fcr31, &sc->sc_fpc_csr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 |  | 
|  | 82 | return err; | 
|  | 83 | } | 
|  | 84 |  | 
| Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 85 | #ifdef CONFIG_64BIT | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | /* | 
|  | 87 | * This is the o32 version | 
|  | 88 | */ | 
|  | 89 |  | 
|  | 90 | int fpu_emulator_save_context32(struct sigcontext32 *sc) | 
|  | 91 | { | 
|  | 92 | int i; | 
|  | 93 | int err = 0; | 
|  | 94 |  | 
|  | 95 | for (i = 0; i < 32; i+=2) { | 
|  | 96 | err |= | 
|  | 97 | __put_user(current->thread.fpu.soft.fpr[i], | 
|  | 98 | &sc->sc_fpregs[i]); | 
|  | 99 | } | 
|  | 100 | err |= __put_user(current->thread.fpu.soft.fcr31, &sc->sc_fpc_csr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 |  | 
|  | 102 | return err; | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | int fpu_emulator_restore_context32(struct sigcontext32 *sc) | 
|  | 106 | { | 
|  | 107 | int i; | 
|  | 108 | int err = 0; | 
|  | 109 |  | 
|  | 110 | for (i = 0; i < 32; i+=2) { | 
|  | 111 | err |= | 
|  | 112 | __get_user(current->thread.fpu.soft.fpr[i], | 
|  | 113 | &sc->sc_fpregs[i]); | 
|  | 114 | } | 
|  | 115 | err |= __get_user(current->thread.fpu.soft.fcr31, &sc->sc_fpc_csr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 |  | 
|  | 117 | return err; | 
|  | 118 | } | 
|  | 119 | #endif |