Blame view

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