blob: 4c8ab2739aae4d0ecc701810e169571317812bdc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This program is free software; you can distribute it and/or modify it
3 * under the terms of the GNU General Public License (Version 2) as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope it will be useful, but WITHOUT
7 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9 * for more details.
10 *
11 * You should have received a copy of the GNU General Public License along
12 * with this program; if not, write to the Free Software Foundation, Inc.,
13 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
14 *
Atsushi Nemotoeae89072006-05-16 01:26:03 +090015 * Further private data for which no space exists in mips_fpu_struct.
16 * This should be subsumed into the mips_fpu_struct structure as
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 * defined in processor.h as soon as the absurd wired absolute assembler
18 * offsets become dynamic at compile time.
19 *
20 * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
21 * Copyright (C) 2000 MIPS Technologies, Inc. All rights reserved.
22 */
23#ifndef _ASM_FPU_EMULATOR_H
24#define _ASM_FPU_EMULATOR_H
25
Ralf Baechlee0cc3a42014-04-28 22:34:01 +020026#include <linux/sched.h>
Paul Burton432c6ba2016-07-08 11:06:19 +010027#include <asm/dsemul.h>
Ralf Baechlee0cc3a42014-04-28 22:34:01 +020028#include <asm/thread_info.h>
Ralf Baechleba3049e2008-10-28 17:38:42 +000029#include <asm/inst.h>
David Daneyb6ee75e2009-11-05 11:34:26 -080030#include <asm/local.h>
Ralf Baechlee0cc3a42014-04-28 22:34:01 +020031#include <asm/processor.h>
David Daneyb6ee75e2009-11-05 11:34:26 -080032
33#ifdef CONFIG_DEBUG_FS
Ralf Baechleba3049e2008-10-28 17:38:42 +000034
Ralf Baechle4a99d1e2005-05-11 12:02:48 +000035struct mips_fpu_emulator_stats {
Christoph Lameterd1cd39a2014-08-17 12:30:43 -050036 unsigned long emulated;
37 unsigned long loads;
38 unsigned long stores;
Aleksandar Markovicae5f3f52017-08-21 14:24:50 +020039 unsigned long branches;
Christoph Lameterd1cd39a2014-08-17 12:30:43 -050040 unsigned long cp1ops;
41 unsigned long cp1xops;
42 unsigned long errors;
43 unsigned long ieee754_inexact;
44 unsigned long ieee754_underflow;
45 unsigned long ieee754_overflow;
46 unsigned long ieee754_zerodiv;
47 unsigned long ieee754_invalidop;
David Daney2707cd22014-12-03 11:12:23 -080048 unsigned long ds_emul;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
50
David Daneyb6ee75e2009-11-05 11:34:26 -080051DECLARE_PER_CPU(struct mips_fpu_emulator_stats, fpuemustats);
52
53#define MIPS_FPU_EMU_INC_STATS(M) \
Ralf Baechlec948aca2010-03-08 19:38:13 +010054do { \
55 preempt_disable(); \
Christoph Lameterd1cd39a2014-08-17 12:30:43 -050056 __this_cpu_inc(fpuemustats.M); \
Ralf Baechlec948aca2010-03-08 19:38:13 +010057 preempt_enable(); \
58} while (0)
David Daneyb6ee75e2009-11-05 11:34:26 -080059
60#else
61#define MIPS_FPU_EMU_INC_STATS(M) do { } while (0)
62#endif /* CONFIG_DEBUG_FS */
Ralf Baechle0bd5d2e2005-02-28 17:29:15 +000063
Leonid Yegoshin102cedc2013-03-25 12:09:02 -050064extern int fpu_emulator_cop1Handler(struct pt_regs *xcp,
65 struct mips_fpu_struct *ctx, int has_fpu,
Paul Burton445a58c2017-08-23 11:17:51 -070066 void __user **fault_addr);
Maciej W. Rozycki5a1aca42016-10-28 08:21:03 +010067void force_fcr31_sig(unsigned long fcr31, void __user *fault_addr,
68 struct task_struct *tsk);
Maciej W. Rozycki304acb72015-04-03 23:27:15 +010069int process_fpemu_return(int sig, void __user *fault_addr,
70 unsigned long fcr31);
Paul Burton432c6ba2016-07-08 11:06:19 +010071int isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
72 unsigned long *contpc);
Leonid Yegoshin102cedc2013-03-25 12:09:02 -050073int mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
74 unsigned long *contpc);
Ralf Baechleba3049e2008-10-28 17:38:42 +000075
Ralf Baechlee0cc3a42014-04-28 22:34:01 +020076#define SIGNALLING_NAN 0x7ff800007ff80000LL
77
78static inline void fpu_emulator_init_fpu(void)
79{
80 struct task_struct *t = current;
81 int i;
82
Ralf Baechlee0cc3a42014-04-28 22:34:01 +020083 for (i = 0; i < 32; i++)
84 set_fpr64(&t->thread.fpu.fpr[i], 0, SIGNALLING_NAN);
85}
86
Maciej W. Rozycki5a1aca42016-10-28 08:21:03 +010087/*
88 * Mask the FCSR Cause bits according to the Enable bits, observing
89 * that Unimplemented is always enabled.
90 */
91static inline unsigned long mask_fcr31_x(unsigned long fcr31)
92{
93 return fcr31 & (FPU_CSR_UNI_X |
94 ((fcr31 & FPU_CSR_ALL_E) <<
95 (ffs(FPU_CSR_ALL_X) - ffs(FPU_CSR_ALL_E))));
96}
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#endif /* _ASM_FPU_EMULATOR_H */