kernel_linkage.c 2.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/*
 *  Kevin D. Kissell, kevink@mips and Carsten Langgaard, carstenl@mips.com
R
Ralf Baechle 已提交
3
 *  Copyright (C) 2000 MIPS Technologies, Inc.	All rights reserved.
L
Linus Torvalds 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 *  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
 */
#include <linux/sched.h>
#include <asm/processor.h>
#include <asm/signal.h>
#include <asm/uaccess.h>

27
#include <asm/fpu.h>
L
Linus Torvalds 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <asm/fpu_emulator.h>

#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\n");
	}

42
	current->thread.fpu.fcr31 = 0;
P
Paul Burton 已提交
43 44
	for (i = 0; i < 32; i++)
		set_fpr64(&current->thread.fpu.fpr[i], 0, SIGNALLING_NAN);
L
Linus Torvalds 已提交
45 46 47 48 49 50 51 52 53
}


/*
 * 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
 */

54
int fpu_emulator_save_context(struct sigcontext __user *sc)
L
Linus Torvalds 已提交
55 56 57 58 59 60
{
	int i;
	int err = 0;

	for (i = 0; i < 32; i++) {
		err |=
P
Paul Burton 已提交
61 62
		    __put_user(get_fpr64(&current->thread.fpu.fpr[i], 0),
			       &sc->sc_fpregs[i]);
L
Linus Torvalds 已提交
63
	}
64
	err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
L
Linus Torvalds 已提交
65 66 67 68

	return err;
}

69
int fpu_emulator_restore_context(struct sigcontext __user *sc)
L
Linus Torvalds 已提交
70 71 72
{
	int i;
	int err = 0;
P
Paul Burton 已提交
73
	u64 fpr_val;
L
Linus Torvalds 已提交
74 75

	for (i = 0; i < 32; i++) {
P
Paul Burton 已提交
76 77
		err |= __get_user(fpr_val, &sc->sc_fpregs[i]);
		set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val);
L
Linus Torvalds 已提交
78
	}
79
	err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
L
Linus Torvalds 已提交
80 81 82 83

	return err;
}

84
#ifdef CONFIG_64BIT
L
Linus Torvalds 已提交
85 86 87 88
/*
 * This is the o32 version
 */

89
int fpu_emulator_save_context32(struct sigcontext32 __user *sc)
L
Linus Torvalds 已提交
90 91 92
{
	int i;
	int err = 0;
93
	int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
L
Linus Torvalds 已提交
94

95
	for (i = 0; i < 32; i += inc) {
L
Linus Torvalds 已提交
96
		err |=
P
Paul Burton 已提交
97 98
		    __put_user(get_fpr64(&current->thread.fpu.fpr[i], 0),
			       &sc->sc_fpregs[i]);
L
Linus Torvalds 已提交
99
	}
100
	err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
L
Linus Torvalds 已提交
101 102 103 104

	return err;
}

105
int fpu_emulator_restore_context32(struct sigcontext32 __user *sc)
L
Linus Torvalds 已提交
106 107 108
{
	int i;
	int err = 0;
109
	int inc = test_thread_flag(TIF_32BIT_FPREGS) ? 2 : 1;
P
Paul Burton 已提交
110
	u64 fpr_val;
L
Linus Torvalds 已提交
111

112
	for (i = 0; i < 32; i += inc) {
P
Paul Burton 已提交
113 114
		err |= __get_user(fpr_val, &sc->sc_fpregs[i]);
		set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val);
L
Linus Torvalds 已提交
115
	}
116
	err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
L
Linus Torvalds 已提交
117 118 119 120

	return err;
}
#endif