xref: /linux/arch/mips/kernel/unaligned.c (revision e4aa1f153add29343eeb8b3bf0f64e7c6fc7e697)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Handle unaligned accesses by emulation.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * This file is subject to the terms and conditions of the GNU General Public
51da177e4SLinus Torvalds  * License.  See the file "COPYING" in the main directory of this archive
61da177e4SLinus Torvalds  * for more details.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Copyright (C) 1996, 1998, 1999, 2002 by Ralf Baechle
91da177e4SLinus Torvalds  * Copyright (C) 1999 Silicon Graphics, Inc.
109d8e5736SMarkos Chandras  * Copyright (C) 2014 Imagination Technologies Ltd.
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  * This file contains exception handler for address error exception with the
131da177e4SLinus Torvalds  * special capability to execute faulting instructions in software.  The
141da177e4SLinus Torvalds  * handler does not try to handle the case when the program counter points
151da177e4SLinus Torvalds  * to an address not aligned to a word boundary.
161da177e4SLinus Torvalds  *
171da177e4SLinus Torvalds  * Putting data to unaligned addresses is a bad practice even on Intel where
181da177e4SLinus Torvalds  * only the performance is affected.  Much worse is that such code is non-
191da177e4SLinus Torvalds  * portable.  Due to several programs that die on MIPS due to alignment
201da177e4SLinus Torvalds  * problems I decided to implement this handler anyway though I originally
211da177e4SLinus Torvalds  * didn't intend to do this at all for user code.
221da177e4SLinus Torvalds  *
231da177e4SLinus Torvalds  * For now I enable fixing of address errors by default to make life easier.
241da177e4SLinus Torvalds  * I however intend to disable this somewhen in the future when the alignment
251da177e4SLinus Torvalds  * problems with user programs have been fixed.	 For programmers this is the
261da177e4SLinus Torvalds  * right way to go.
271da177e4SLinus Torvalds  *
281da177e4SLinus Torvalds  * Fixing address errors is a per process option.  The option is inherited
291da177e4SLinus Torvalds  * across fork(2) and execve(2) calls.	If you really want to use the
301da177e4SLinus Torvalds  * option in your user programs - I discourage the use of the software
311da177e4SLinus Torvalds  * emulation strongly - use the following code in your userland stuff:
321da177e4SLinus Torvalds  *
331da177e4SLinus Torvalds  * #include <sys/sysmips.h>
341da177e4SLinus Torvalds  *
351da177e4SLinus Torvalds  * ...
361da177e4SLinus Torvalds  * sysmips(MIPS_FIXADE, x);
371da177e4SLinus Torvalds  * ...
381da177e4SLinus Torvalds  *
391da177e4SLinus Torvalds  * The argument x is 0 for disabling software emulation, enabled otherwise.
401da177e4SLinus Torvalds  *
411da177e4SLinus Torvalds  * Below a little program to play around with this feature.
421da177e4SLinus Torvalds  *
431da177e4SLinus Torvalds  * #include <stdio.h>
441da177e4SLinus Torvalds  * #include <sys/sysmips.h>
451da177e4SLinus Torvalds  *
461da177e4SLinus Torvalds  * struct foo {
471da177e4SLinus Torvalds  *	   unsigned char bar[8];
481da177e4SLinus Torvalds  * };
491da177e4SLinus Torvalds  *
501da177e4SLinus Torvalds  * main(int argc, char *argv[])
511da177e4SLinus Torvalds  * {
521da177e4SLinus Torvalds  *	   struct foo x = {0, 1, 2, 3, 4, 5, 6, 7};
531da177e4SLinus Torvalds  *	   unsigned int *p = (unsigned int *) (x.bar + 3);
541da177e4SLinus Torvalds  *	   int i;
551da177e4SLinus Torvalds  *
561da177e4SLinus Torvalds  *	   if (argc > 1)
571da177e4SLinus Torvalds  *		   sysmips(MIPS_FIXADE, atoi(argv[1]));
581da177e4SLinus Torvalds  *
591da177e4SLinus Torvalds  *	   printf("*p = %08lx\n", *p);
601da177e4SLinus Torvalds  *
611da177e4SLinus Torvalds  *	   *p = 0xdeadface;
621da177e4SLinus Torvalds  *
631da177e4SLinus Torvalds  *	   for(i = 0; i <= 7; i++)
641da177e4SLinus Torvalds  *	   printf("%02x ", x.bar[i]);
651da177e4SLinus Torvalds  *	   printf("\n");
661da177e4SLinus Torvalds  * }
671da177e4SLinus Torvalds  *
681da177e4SLinus Torvalds  * Coprocessor loads are not supported; I think this case is unimportant
691da177e4SLinus Torvalds  * in the practice.
701da177e4SLinus Torvalds  *
711da177e4SLinus Torvalds  * TODO: Handle ndc (attempted store to doubleword in uncached memory)
721da177e4SLinus Torvalds  *	 exception for the R6000.
731da177e4SLinus Torvalds  *	 A store crossing a page boundary might be executed only partially.
741da177e4SLinus Torvalds  *	 Undo the partial store in this case.
751da177e4SLinus Torvalds  */
76c3fc5cd5SRalf Baechle #include <linux/context_tracking.h>
771da177e4SLinus Torvalds #include <linux/mm.h>
781da177e4SLinus Torvalds #include <linux/signal.h>
791da177e4SLinus Torvalds #include <linux/smp.h>
80e8edc6e0SAlexey Dobriyan #include <linux/sched.h>
816312e0eeSAtsushi Nemoto #include <linux/debugfs.h>
827f788d2dSDeng-Cheng Zhu #include <linux/perf_event.h>
837f788d2dSDeng-Cheng Zhu 
841da177e4SLinus Torvalds #include <asm/asm.h>
851da177e4SLinus Torvalds #include <asm/branch.h>
861da177e4SLinus Torvalds #include <asm/byteorder.h>
8769f3a7deSRalf Baechle #include <asm/cop2.h>
88102cedc3SLeonid Yegoshin #include <asm/fpu.h>
89102cedc3SLeonid Yegoshin #include <asm/fpu_emulator.h>
901da177e4SLinus Torvalds #include <asm/inst.h>
911da177e4SLinus Torvalds #include <asm/uaccess.h>
921da177e4SLinus Torvalds 
931da177e4SLinus Torvalds #define STR(x)	__STR(x)
941da177e4SLinus Torvalds #define __STR(x)  #x
951da177e4SLinus Torvalds 
966312e0eeSAtsushi Nemoto enum {
976312e0eeSAtsushi Nemoto 	UNALIGNED_ACTION_QUIET,
986312e0eeSAtsushi Nemoto 	UNALIGNED_ACTION_SIGNAL,
996312e0eeSAtsushi Nemoto 	UNALIGNED_ACTION_SHOW,
1006312e0eeSAtsushi Nemoto };
1016312e0eeSAtsushi Nemoto #ifdef CONFIG_DEBUG_FS
1026312e0eeSAtsushi Nemoto static u32 unaligned_instructions;
1036312e0eeSAtsushi Nemoto static u32 unaligned_action;
1046312e0eeSAtsushi Nemoto #else
1056312e0eeSAtsushi Nemoto #define unaligned_action UNALIGNED_ACTION_QUIET
1061da177e4SLinus Torvalds #endif
1076312e0eeSAtsushi Nemoto extern void show_registers(struct pt_regs *regs);
1081da177e4SLinus Torvalds 
10934c2f668SLeonid Yegoshin #ifdef __BIG_ENDIAN
110eeb53895SMarkos Chandras #define     _LoadHW(addr, value, res, type)  \
1113563c32dSMarkos Chandras do {                                                        \
11234c2f668SLeonid Yegoshin 		__asm__ __volatile__ (".set\tnoat\n"        \
113eeb53895SMarkos Chandras 			"1:\t"type##_lb("%0", "0(%2)")"\n"  \
114eeb53895SMarkos Chandras 			"2:\t"type##_lbu("$1", "1(%2)")"\n\t"\
11534c2f668SLeonid Yegoshin 			"sll\t%0, 0x8\n\t"                  \
11634c2f668SLeonid Yegoshin 			"or\t%0, $1\n\t"                    \
11734c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
11834c2f668SLeonid Yegoshin 			"3:\t.set\tat\n\t"                  \
11934c2f668SLeonid Yegoshin 			".insn\n\t"                         \
12034c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
12134c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
12234c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
12334c2f668SLeonid Yegoshin 			".previous\n\t"                     \
12434c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
12534c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
12634c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
12734c2f668SLeonid Yegoshin 			".previous"                         \
12834c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
1293563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
1303563c32dSMarkos Chandras } while(0)
13134c2f668SLeonid Yegoshin 
1320593a44cSLeonid Yegoshin #ifndef CONFIG_CPU_MIPSR6
133eeb53895SMarkos Chandras #define     _LoadW(addr, value, res, type)   \
1343563c32dSMarkos Chandras do {                                                        \
13534c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
136eeb53895SMarkos Chandras 			"1:\t"type##_lwl("%0", "(%2)")"\n"   \
137eeb53895SMarkos Chandras 			"2:\t"type##_lwr("%0", "3(%2)")"\n\t"\
13834c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
13934c2f668SLeonid Yegoshin 			"3:\n\t"                            \
14034c2f668SLeonid Yegoshin 			".insn\n\t"                         \
14134c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
14234c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
14334c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
14434c2f668SLeonid Yegoshin 			".previous\n\t"                     \
14534c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
14634c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
14734c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
14834c2f668SLeonid Yegoshin 			".previous"                         \
14934c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
1503563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
1513563c32dSMarkos Chandras } while(0)
1523563c32dSMarkos Chandras 
1530593a44cSLeonid Yegoshin #else
1540593a44cSLeonid Yegoshin /* MIPSR6 has no lwl instruction */
155eeb53895SMarkos Chandras #define     _LoadW(addr, value, res, type) \
1563563c32dSMarkos Chandras do {                                                        \
1570593a44cSLeonid Yegoshin 		__asm__ __volatile__ (			    \
1580593a44cSLeonid Yegoshin 			".set\tpush\n"			    \
1590593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
160eeb53895SMarkos Chandras 			"1:"type##_lb("%0", "0(%2)")"\n\t"  \
161eeb53895SMarkos Chandras 			"2:"type##_lbu("$1", "1(%2)")"\n\t" \
1620593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
1630593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
164eeb53895SMarkos Chandras 			"3:"type##_lbu("$1", "2(%2)")"\n\t" \
1650593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
1660593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
167eeb53895SMarkos Chandras 			"4:"type##_lbu("$1", "3(%2)")"\n\t" \
1680593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
1690593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
1700593a44cSLeonid Yegoshin 			"li\t%1, 0\n"			    \
1710593a44cSLeonid Yegoshin 			".set\tpop\n"			    \
1720593a44cSLeonid Yegoshin 			"10:\n\t"			    \
1730593a44cSLeonid Yegoshin 			".insn\n\t"			    \
1740593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
1750593a44cSLeonid Yegoshin 			"11:\tli\t%1, %3\n\t"		    \
1760593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
1770593a44cSLeonid Yegoshin 			".previous\n\t"			    \
1780593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
1790593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
1800593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
1810593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
1820593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
1830593a44cSLeonid Yegoshin 			".previous"			    \
1840593a44cSLeonid Yegoshin 			: "=&r" (value), "=r" (res)	    \
1853563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
1863563c32dSMarkos Chandras } while(0)
1873563c32dSMarkos Chandras 
1880593a44cSLeonid Yegoshin #endif /* CONFIG_CPU_MIPSR6 */
18934c2f668SLeonid Yegoshin 
190eeb53895SMarkos Chandras #define     _LoadHWU(addr, value, res, type) \
1913563c32dSMarkos Chandras do {                                                        \
19234c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
19334c2f668SLeonid Yegoshin 			".set\tnoat\n"                      \
194eeb53895SMarkos Chandras 			"1:\t"type##_lbu("%0", "0(%2)")"\n" \
195eeb53895SMarkos Chandras 			"2:\t"type##_lbu("$1", "1(%2)")"\n\t"\
19634c2f668SLeonid Yegoshin 			"sll\t%0, 0x8\n\t"                  \
19734c2f668SLeonid Yegoshin 			"or\t%0, $1\n\t"                    \
19834c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
19934c2f668SLeonid Yegoshin 			"3:\n\t"                            \
20034c2f668SLeonid Yegoshin 			".insn\n\t"                         \
20134c2f668SLeonid Yegoshin 			".set\tat\n\t"                      \
20234c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
20334c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
20434c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
20534c2f668SLeonid Yegoshin 			".previous\n\t"                     \
20634c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
20734c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
20834c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
20934c2f668SLeonid Yegoshin 			".previous"                         \
21034c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
2113563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
2123563c32dSMarkos Chandras } while(0)
21334c2f668SLeonid Yegoshin 
2140593a44cSLeonid Yegoshin #ifndef CONFIG_CPU_MIPSR6
215eeb53895SMarkos Chandras #define     _LoadWU(addr, value, res, type)  \
2163563c32dSMarkos Chandras do {                                                        \
21734c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
218eeb53895SMarkos Chandras 			"1:\t"type##_lwl("%0", "(%2)")"\n"  \
219eeb53895SMarkos Chandras 			"2:\t"type##_lwr("%0", "3(%2)")"\n\t"\
22034c2f668SLeonid Yegoshin 			"dsll\t%0, %0, 32\n\t"              \
22134c2f668SLeonid Yegoshin 			"dsrl\t%0, %0, 32\n\t"              \
22234c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
22334c2f668SLeonid Yegoshin 			"3:\n\t"                            \
22434c2f668SLeonid Yegoshin 			".insn\n\t"                         \
22534c2f668SLeonid Yegoshin 			"\t.section\t.fixup,\"ax\"\n\t"     \
22634c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
22734c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
22834c2f668SLeonid Yegoshin 			".previous\n\t"                     \
22934c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
23034c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
23134c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
23234c2f668SLeonid Yegoshin 			".previous"                         \
23334c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
2343563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
2353563c32dSMarkos Chandras } while(0)
23634c2f668SLeonid Yegoshin 
237eeb53895SMarkos Chandras #define     _LoadDW(addr, value, res)  \
2383563c32dSMarkos Chandras do {                                                        \
23934c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
24034c2f668SLeonid Yegoshin 			"1:\tldl\t%0, (%2)\n"               \
24134c2f668SLeonid Yegoshin 			"2:\tldr\t%0, 7(%2)\n\t"            \
24234c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
24334c2f668SLeonid Yegoshin 			"3:\n\t"                            \
24434c2f668SLeonid Yegoshin 			".insn\n\t"                         \
24534c2f668SLeonid Yegoshin 			"\t.section\t.fixup,\"ax\"\n\t"     \
24634c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
24734c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
24834c2f668SLeonid Yegoshin 			".previous\n\t"                     \
24934c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
25034c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
25134c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
25234c2f668SLeonid Yegoshin 			".previous"                         \
25334c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
2543563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
2553563c32dSMarkos Chandras } while(0)
2563563c32dSMarkos Chandras 
2570593a44cSLeonid Yegoshin #else
2580593a44cSLeonid Yegoshin /* MIPSR6 has not lwl and ldl instructions */
259eeb53895SMarkos Chandras #define	    _LoadWU(addr, value, res, type) \
2603563c32dSMarkos Chandras do {                                                        \
2610593a44cSLeonid Yegoshin 		__asm__ __volatile__ (			    \
2620593a44cSLeonid Yegoshin 			".set\tpush\n\t"		    \
2630593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
264eeb53895SMarkos Chandras 			"1:"type##_lbu("%0", "0(%2)")"\n\t" \
265eeb53895SMarkos Chandras 			"2:"type##_lbu("$1", "1(%2)")"\n\t" \
2660593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
2670593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
268eeb53895SMarkos Chandras 			"3:"type##_lbu("$1", "2(%2)")"\n\t" \
2690593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
2700593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
271eeb53895SMarkos Chandras 			"4:"type##_lbu("$1", "3(%2)")"\n\t" \
2720593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
2730593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
2740593a44cSLeonid Yegoshin 			"li\t%1, 0\n"			    \
2750593a44cSLeonid Yegoshin 			".set\tpop\n"			    \
2760593a44cSLeonid Yegoshin 			"10:\n\t"			    \
2770593a44cSLeonid Yegoshin 			".insn\n\t"			    \
2780593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
2790593a44cSLeonid Yegoshin 			"11:\tli\t%1, %3\n\t"		    \
2800593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
2810593a44cSLeonid Yegoshin 			".previous\n\t"			    \
2820593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
2830593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
2840593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
2850593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
2860593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
2870593a44cSLeonid Yegoshin 			".previous"			    \
2880593a44cSLeonid Yegoshin 			: "=&r" (value), "=r" (res)	    \
2893563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
2903563c32dSMarkos Chandras } while(0)
2910593a44cSLeonid Yegoshin 
292eeb53895SMarkos Chandras #define     _LoadDW(addr, value, res)  \
2933563c32dSMarkos Chandras do {                                                        \
2940593a44cSLeonid Yegoshin 		__asm__ __volatile__ (			    \
2950593a44cSLeonid Yegoshin 			".set\tpush\n\t"		    \
2960593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
2970593a44cSLeonid Yegoshin 			"1:lb\t%0, 0(%2)\n\t"    	    \
2980593a44cSLeonid Yegoshin 			"2:lbu\t $1, 1(%2)\n\t"   	    \
2990593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
3000593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
3010593a44cSLeonid Yegoshin 			"3:lbu\t$1, 2(%2)\n\t"   	    \
3020593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
3030593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
3040593a44cSLeonid Yegoshin 			"4:lbu\t$1, 3(%2)\n\t"   	    \
3050593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
3060593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
3070593a44cSLeonid Yegoshin 			"5:lbu\t$1, 4(%2)\n\t"   	    \
3080593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
3090593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
3100593a44cSLeonid Yegoshin 			"6:lbu\t$1, 5(%2)\n\t"   	    \
3110593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
3120593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
3130593a44cSLeonid Yegoshin 			"7:lbu\t$1, 6(%2)\n\t"   	    \
3140593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
3150593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
3160593a44cSLeonid Yegoshin 			"8:lbu\t$1, 7(%2)\n\t"   	    \
3170593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
3180593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
3190593a44cSLeonid Yegoshin 			"li\t%1, 0\n"			    \
3200593a44cSLeonid Yegoshin 			".set\tpop\n\t"			    \
3210593a44cSLeonid Yegoshin 			"10:\n\t"			    \
3220593a44cSLeonid Yegoshin 			".insn\n\t"			    \
3230593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
3240593a44cSLeonid Yegoshin 			"11:\tli\t%1, %3\n\t"		    \
3250593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
3260593a44cSLeonid Yegoshin 			".previous\n\t"			    \
3270593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
3280593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
3290593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
3300593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
3310593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
3320593a44cSLeonid Yegoshin 			STR(PTR)"\t5b, 11b\n\t"		    \
3330593a44cSLeonid Yegoshin 			STR(PTR)"\t6b, 11b\n\t"		    \
3340593a44cSLeonid Yegoshin 			STR(PTR)"\t7b, 11b\n\t"		    \
3350593a44cSLeonid Yegoshin 			STR(PTR)"\t8b, 11b\n\t"		    \
3360593a44cSLeonid Yegoshin 			".previous"			    \
3370593a44cSLeonid Yegoshin 			: "=&r" (value), "=r" (res)	    \
3383563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
3393563c32dSMarkos Chandras } while(0)
3403563c32dSMarkos Chandras 
3410593a44cSLeonid Yegoshin #endif /* CONFIG_CPU_MIPSR6 */
3420593a44cSLeonid Yegoshin 
34334c2f668SLeonid Yegoshin 
344eeb53895SMarkos Chandras #define     _StoreHW(addr, value, res, type) \
3453563c32dSMarkos Chandras do {                                                        \
34634c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
34734c2f668SLeonid Yegoshin 			".set\tnoat\n"                      \
348eeb53895SMarkos Chandras 			"1:\t"type##_sb("%1", "1(%2)")"\n"  \
34934c2f668SLeonid Yegoshin 			"srl\t$1, %1, 0x8\n"                \
350eeb53895SMarkos Chandras 			"2:\t"type##_sb("$1", "0(%2)")"\n"  \
35134c2f668SLeonid Yegoshin 			".set\tat\n\t"                      \
35234c2f668SLeonid Yegoshin 			"li\t%0, 0\n"                       \
35334c2f668SLeonid Yegoshin 			"3:\n\t"                            \
35434c2f668SLeonid Yegoshin 			".insn\n\t"                         \
35534c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
35634c2f668SLeonid Yegoshin 			"4:\tli\t%0, %3\n\t"                \
35734c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
35834c2f668SLeonid Yegoshin 			".previous\n\t"                     \
35934c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
36034c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
36134c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
36234c2f668SLeonid Yegoshin 			".previous"                         \
36334c2f668SLeonid Yegoshin 			: "=r" (res)                        \
3643563c32dSMarkos Chandras 			: "r" (value), "r" (addr), "i" (-EFAULT));\
3653563c32dSMarkos Chandras } while(0)
36634c2f668SLeonid Yegoshin 
3670593a44cSLeonid Yegoshin #ifndef CONFIG_CPU_MIPSR6
368eeb53895SMarkos Chandras #define     _StoreW(addr, value, res, type)  \
3693563c32dSMarkos Chandras do {                                                        \
37034c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
371eeb53895SMarkos Chandras 			"1:\t"type##_swl("%1", "(%2)")"\n"  \
372eeb53895SMarkos Chandras 			"2:\t"type##_swr("%1", "3(%2)")"\n\t"\
37334c2f668SLeonid Yegoshin 			"li\t%0, 0\n"                       \
37434c2f668SLeonid Yegoshin 			"3:\n\t"                            \
37534c2f668SLeonid Yegoshin 			".insn\n\t"                         \
37634c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
37734c2f668SLeonid Yegoshin 			"4:\tli\t%0, %3\n\t"                \
37834c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
37934c2f668SLeonid Yegoshin 			".previous\n\t"                     \
38034c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
38134c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
38234c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
38334c2f668SLeonid Yegoshin 			".previous"                         \
38434c2f668SLeonid Yegoshin 		: "=r" (res)                                \
3853563c32dSMarkos Chandras 		: "r" (value), "r" (addr), "i" (-EFAULT));  \
3863563c32dSMarkos Chandras } while(0)
38734c2f668SLeonid Yegoshin 
388eeb53895SMarkos Chandras #define     _StoreDW(addr, value, res) \
3893563c32dSMarkos Chandras do {                                                        \
39034c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
39134c2f668SLeonid Yegoshin 			"1:\tsdl\t%1,(%2)\n"                \
39234c2f668SLeonid Yegoshin 			"2:\tsdr\t%1, 7(%2)\n\t"            \
39334c2f668SLeonid Yegoshin 			"li\t%0, 0\n"                       \
39434c2f668SLeonid Yegoshin 			"3:\n\t"                            \
39534c2f668SLeonid Yegoshin 			".insn\n\t"                         \
39634c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
39734c2f668SLeonid Yegoshin 			"4:\tli\t%0, %3\n\t"                \
39834c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
39934c2f668SLeonid Yegoshin 			".previous\n\t"                     \
40034c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
40134c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
40234c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
40334c2f668SLeonid Yegoshin 			".previous"                         \
40434c2f668SLeonid Yegoshin 		: "=r" (res)                                \
4053563c32dSMarkos Chandras 		: "r" (value), "r" (addr), "i" (-EFAULT));  \
4063563c32dSMarkos Chandras } while(0)
4073563c32dSMarkos Chandras 
4080593a44cSLeonid Yegoshin #else
4090593a44cSLeonid Yegoshin /* MIPSR6 has no swl and sdl instructions */
410eeb53895SMarkos Chandras #define     _StoreW(addr, value, res, type)  \
4113563c32dSMarkos Chandras do {                                                        \
4120593a44cSLeonid Yegoshin 		__asm__ __volatile__ (                      \
4130593a44cSLeonid Yegoshin 			".set\tpush\n\t"		    \
4140593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
415eeb53895SMarkos Chandras 			"1:"type##_sb("%1", "3(%2)")"\n\t"  \
4160593a44cSLeonid Yegoshin 			"srl\t$1, %1, 0x8\n\t"		    \
417eeb53895SMarkos Chandras 			"2:"type##_sb("$1", "2(%2)")"\n\t"  \
4180593a44cSLeonid Yegoshin 			"srl\t$1, $1,  0x8\n\t"		    \
419eeb53895SMarkos Chandras 			"3:"type##_sb("$1", "1(%2)")"\n\t"  \
4200593a44cSLeonid Yegoshin 			"srl\t$1, $1, 0x8\n\t"		    \
421eeb53895SMarkos Chandras 			"4:"type##_sb("$1", "0(%2)")"\n\t"  \
4220593a44cSLeonid Yegoshin 			".set\tpop\n\t"			    \
4230593a44cSLeonid Yegoshin 			"li\t%0, 0\n"			    \
4240593a44cSLeonid Yegoshin 			"10:\n\t"			    \
4250593a44cSLeonid Yegoshin 			".insn\n\t"			    \
4260593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
4270593a44cSLeonid Yegoshin 			"11:\tli\t%0, %3\n\t"		    \
4280593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
4290593a44cSLeonid Yegoshin 			".previous\n\t"			    \
4300593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
4310593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
4320593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
4330593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
4340593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
4350593a44cSLeonid Yegoshin 			".previous"			    \
4360593a44cSLeonid Yegoshin 		: "=&r" (res)			    	    \
4370593a44cSLeonid Yegoshin 		: "r" (value), "r" (addr), "i" (-EFAULT)    \
4383563c32dSMarkos Chandras 		: "memory");                                \
4393563c32dSMarkos Chandras } while(0)
44034c2f668SLeonid Yegoshin 
441531a6d59SJames Cowgill #define     _StoreDW(addr, value, res) \
4423563c32dSMarkos Chandras do {                                                        \
4430593a44cSLeonid Yegoshin 		__asm__ __volatile__ (                      \
4440593a44cSLeonid Yegoshin 			".set\tpush\n\t"		    \
4450593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
4460593a44cSLeonid Yegoshin 			"1:sb\t%1, 7(%2)\n\t"    	    \
4470593a44cSLeonid Yegoshin 			"dsrl\t$1, %1, 0x8\n\t"		    \
4480593a44cSLeonid Yegoshin 			"2:sb\t$1, 6(%2)\n\t"    	    \
4490593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
4500593a44cSLeonid Yegoshin 			"3:sb\t$1, 5(%2)\n\t"    	    \
4510593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
4520593a44cSLeonid Yegoshin 			"4:sb\t$1, 4(%2)\n\t"    	    \
4530593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
4540593a44cSLeonid Yegoshin 			"5:sb\t$1, 3(%2)\n\t"    	    \
4550593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
4560593a44cSLeonid Yegoshin 			"6:sb\t$1, 2(%2)\n\t"    	    \
4570593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
4580593a44cSLeonid Yegoshin 			"7:sb\t$1, 1(%2)\n\t"    	    \
4590593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
4600593a44cSLeonid Yegoshin 			"8:sb\t$1, 0(%2)\n\t"    	    \
4610593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
4620593a44cSLeonid Yegoshin 			".set\tpop\n\t"			    \
4630593a44cSLeonid Yegoshin 			"li\t%0, 0\n"			    \
4640593a44cSLeonid Yegoshin 			"10:\n\t"			    \
4650593a44cSLeonid Yegoshin 			".insn\n\t"			    \
4660593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
4670593a44cSLeonid Yegoshin 			"11:\tli\t%0, %3\n\t"		    \
4680593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
4690593a44cSLeonid Yegoshin 			".previous\n\t"			    \
4700593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
4710593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
4720593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
4730593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
4740593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
4750593a44cSLeonid Yegoshin 			STR(PTR)"\t5b, 11b\n\t"		    \
4760593a44cSLeonid Yegoshin 			STR(PTR)"\t6b, 11b\n\t"		    \
4770593a44cSLeonid Yegoshin 			STR(PTR)"\t7b, 11b\n\t"		    \
4780593a44cSLeonid Yegoshin 			STR(PTR)"\t8b, 11b\n\t"		    \
4790593a44cSLeonid Yegoshin 			".previous"			    \
4800593a44cSLeonid Yegoshin 		: "=&r" (res)			    	    \
4810593a44cSLeonid Yegoshin 		: "r" (value), "r" (addr), "i" (-EFAULT)    \
4823563c32dSMarkos Chandras 		: "memory");                                \
4833563c32dSMarkos Chandras } while(0)
4843563c32dSMarkos Chandras 
4850593a44cSLeonid Yegoshin #endif /* CONFIG_CPU_MIPSR6 */
4860593a44cSLeonid Yegoshin 
4870593a44cSLeonid Yegoshin #else /* __BIG_ENDIAN */
4880593a44cSLeonid Yegoshin 
489eeb53895SMarkos Chandras #define     _LoadHW(addr, value, res, type)  \
4903563c32dSMarkos Chandras do {                                                        \
49134c2f668SLeonid Yegoshin 		__asm__ __volatile__ (".set\tnoat\n"        \
492eeb53895SMarkos Chandras 			"1:\t"type##_lb("%0", "1(%2)")"\n"  \
493eeb53895SMarkos Chandras 			"2:\t"type##_lbu("$1", "0(%2)")"\n\t"\
49434c2f668SLeonid Yegoshin 			"sll\t%0, 0x8\n\t"                  \
49534c2f668SLeonid Yegoshin 			"or\t%0, $1\n\t"                    \
49634c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
49734c2f668SLeonid Yegoshin 			"3:\t.set\tat\n\t"                  \
49834c2f668SLeonid Yegoshin 			".insn\n\t"                         \
49934c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
50034c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
50134c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
50234c2f668SLeonid Yegoshin 			".previous\n\t"                     \
50334c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
50434c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
50534c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
50634c2f668SLeonid Yegoshin 			".previous"                         \
50734c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
5083563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
5093563c32dSMarkos Chandras } while(0)
51034c2f668SLeonid Yegoshin 
5110593a44cSLeonid Yegoshin #ifndef CONFIG_CPU_MIPSR6
512eeb53895SMarkos Chandras #define     _LoadW(addr, value, res, type)   \
5133563c32dSMarkos Chandras do {                                                        \
51434c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
515eeb53895SMarkos Chandras 			"1:\t"type##_lwl("%0", "3(%2)")"\n" \
516eeb53895SMarkos Chandras 			"2:\t"type##_lwr("%0", "(%2)")"\n\t"\
51734c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
51834c2f668SLeonid Yegoshin 			"3:\n\t"                            \
51934c2f668SLeonid Yegoshin 			".insn\n\t"                         \
52034c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
52134c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
52234c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
52334c2f668SLeonid Yegoshin 			".previous\n\t"                     \
52434c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
52534c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
52634c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
52734c2f668SLeonid Yegoshin 			".previous"                         \
52834c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
5293563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
5303563c32dSMarkos Chandras } while(0)
5313563c32dSMarkos Chandras 
5320593a44cSLeonid Yegoshin #else
5330593a44cSLeonid Yegoshin /* MIPSR6 has no lwl instruction */
534eeb53895SMarkos Chandras #define     _LoadW(addr, value, res, type) \
5353563c32dSMarkos Chandras do {                                                        \
5360593a44cSLeonid Yegoshin 		__asm__ __volatile__ (			    \
5370593a44cSLeonid Yegoshin 			".set\tpush\n"			    \
5380593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
539eeb53895SMarkos Chandras 			"1:"type##_lb("%0", "3(%2)")"\n\t"  \
540eeb53895SMarkos Chandras 			"2:"type##_lbu("$1", "2(%2)")"\n\t" \
5410593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
5420593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
543eeb53895SMarkos Chandras 			"3:"type##_lbu("$1", "1(%2)")"\n\t" \
5440593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
5450593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
546eeb53895SMarkos Chandras 			"4:"type##_lbu("$1", "0(%2)")"\n\t" \
5470593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
5480593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
5490593a44cSLeonid Yegoshin 			"li\t%1, 0\n"			    \
5500593a44cSLeonid Yegoshin 			".set\tpop\n"			    \
5510593a44cSLeonid Yegoshin 			"10:\n\t"			    \
5520593a44cSLeonid Yegoshin 			".insn\n\t"			    \
5530593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
5540593a44cSLeonid Yegoshin 			"11:\tli\t%1, %3\n\t"		    \
5550593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
5560593a44cSLeonid Yegoshin 			".previous\n\t"			    \
5570593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
5580593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
5590593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
5600593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
5610593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
5620593a44cSLeonid Yegoshin 			".previous"			    \
5630593a44cSLeonid Yegoshin 			: "=&r" (value), "=r" (res)	    \
5643563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
5653563c32dSMarkos Chandras } while(0)
5663563c32dSMarkos Chandras 
5670593a44cSLeonid Yegoshin #endif /* CONFIG_CPU_MIPSR6 */
5680593a44cSLeonid Yegoshin 
56934c2f668SLeonid Yegoshin 
570eeb53895SMarkos Chandras #define     _LoadHWU(addr, value, res, type) \
5713563c32dSMarkos Chandras do {                                                        \
57234c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
57334c2f668SLeonid Yegoshin 			".set\tnoat\n"                      \
574eeb53895SMarkos Chandras 			"1:\t"type##_lbu("%0", "1(%2)")"\n" \
575eeb53895SMarkos Chandras 			"2:\t"type##_lbu("$1", "0(%2)")"\n\t"\
57634c2f668SLeonid Yegoshin 			"sll\t%0, 0x8\n\t"                  \
57734c2f668SLeonid Yegoshin 			"or\t%0, $1\n\t"                    \
57834c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
57934c2f668SLeonid Yegoshin 			"3:\n\t"                            \
58034c2f668SLeonid Yegoshin 			".insn\n\t"                         \
58134c2f668SLeonid Yegoshin 			".set\tat\n\t"                      \
58234c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
58334c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
58434c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
58534c2f668SLeonid Yegoshin 			".previous\n\t"                     \
58634c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
58734c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
58834c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
58934c2f668SLeonid Yegoshin 			".previous"                         \
59034c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
5913563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
5923563c32dSMarkos Chandras } while(0)
59334c2f668SLeonid Yegoshin 
5940593a44cSLeonid Yegoshin #ifndef CONFIG_CPU_MIPSR6
595eeb53895SMarkos Chandras #define     _LoadWU(addr, value, res, type)  \
5963563c32dSMarkos Chandras do {                                                        \
59734c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
598eeb53895SMarkos Chandras 			"1:\t"type##_lwl("%0", "3(%2)")"\n" \
599eeb53895SMarkos Chandras 			"2:\t"type##_lwr("%0", "(%2)")"\n\t"\
60034c2f668SLeonid Yegoshin 			"dsll\t%0, %0, 32\n\t"              \
60134c2f668SLeonid Yegoshin 			"dsrl\t%0, %0, 32\n\t"              \
60234c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
60334c2f668SLeonid Yegoshin 			"3:\n\t"                            \
60434c2f668SLeonid Yegoshin 			".insn\n\t"                         \
60534c2f668SLeonid Yegoshin 			"\t.section\t.fixup,\"ax\"\n\t"     \
60634c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
60734c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
60834c2f668SLeonid Yegoshin 			".previous\n\t"                     \
60934c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
61034c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
61134c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
61234c2f668SLeonid Yegoshin 			".previous"                         \
61334c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
6143563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
6153563c32dSMarkos Chandras } while(0)
61634c2f668SLeonid Yegoshin 
617eeb53895SMarkos Chandras #define     _LoadDW(addr, value, res)  \
6183563c32dSMarkos Chandras do {                                                        \
61934c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
62034c2f668SLeonid Yegoshin 			"1:\tldl\t%0, 7(%2)\n"              \
62134c2f668SLeonid Yegoshin 			"2:\tldr\t%0, (%2)\n\t"             \
62234c2f668SLeonid Yegoshin 			"li\t%1, 0\n"                       \
62334c2f668SLeonid Yegoshin 			"3:\n\t"                            \
62434c2f668SLeonid Yegoshin 			".insn\n\t"                         \
62534c2f668SLeonid Yegoshin 			"\t.section\t.fixup,\"ax\"\n\t"     \
62634c2f668SLeonid Yegoshin 			"4:\tli\t%1, %3\n\t"                \
62734c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
62834c2f668SLeonid Yegoshin 			".previous\n\t"                     \
62934c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
63034c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
63134c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
63234c2f668SLeonid Yegoshin 			".previous"                         \
63334c2f668SLeonid Yegoshin 			: "=&r" (value), "=r" (res)         \
6343563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
6353563c32dSMarkos Chandras } while(0)
6363563c32dSMarkos Chandras 
6370593a44cSLeonid Yegoshin #else
6380593a44cSLeonid Yegoshin /* MIPSR6 has not lwl and ldl instructions */
639eeb53895SMarkos Chandras #define	    _LoadWU(addr, value, res, type) \
6403563c32dSMarkos Chandras do {                                                        \
6410593a44cSLeonid Yegoshin 		__asm__ __volatile__ (			    \
6420593a44cSLeonid Yegoshin 			".set\tpush\n\t"		    \
6430593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
644eeb53895SMarkos Chandras 			"1:"type##_lbu("%0", "3(%2)")"\n\t" \
645eeb53895SMarkos Chandras 			"2:"type##_lbu("$1", "2(%2)")"\n\t" \
6460593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
6470593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
648eeb53895SMarkos Chandras 			"3:"type##_lbu("$1", "1(%2)")"\n\t" \
6490593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
6500593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
651eeb53895SMarkos Chandras 			"4:"type##_lbu("$1", "0(%2)")"\n\t" \
6520593a44cSLeonid Yegoshin 			"sll\t%0, 0x8\n\t"		    \
6530593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
6540593a44cSLeonid Yegoshin 			"li\t%1, 0\n"			    \
6550593a44cSLeonid Yegoshin 			".set\tpop\n"			    \
6560593a44cSLeonid Yegoshin 			"10:\n\t"			    \
6570593a44cSLeonid Yegoshin 			".insn\n\t"			    \
6580593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
6590593a44cSLeonid Yegoshin 			"11:\tli\t%1, %3\n\t"		    \
6600593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
6610593a44cSLeonid Yegoshin 			".previous\n\t"			    \
6620593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
6630593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
6640593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
6650593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
6660593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
6670593a44cSLeonid Yegoshin 			".previous"			    \
6680593a44cSLeonid Yegoshin 			: "=&r" (value), "=r" (res)	    \
6693563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
6703563c32dSMarkos Chandras } while(0)
6710593a44cSLeonid Yegoshin 
672eeb53895SMarkos Chandras #define     _LoadDW(addr, value, res)  \
6733563c32dSMarkos Chandras do {                                                        \
6740593a44cSLeonid Yegoshin 		__asm__ __volatile__ (			    \
6750593a44cSLeonid Yegoshin 			".set\tpush\n\t"		    \
6760593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
6770593a44cSLeonid Yegoshin 			"1:lb\t%0, 7(%2)\n\t"    	    \
6780593a44cSLeonid Yegoshin 			"2:lbu\t$1, 6(%2)\n\t"   	    \
6790593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
6800593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
6810593a44cSLeonid Yegoshin 			"3:lbu\t$1, 5(%2)\n\t"   	    \
6820593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
6830593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
6840593a44cSLeonid Yegoshin 			"4:lbu\t$1, 4(%2)\n\t"   	    \
6850593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
6860593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
6870593a44cSLeonid Yegoshin 			"5:lbu\t$1, 3(%2)\n\t"   	    \
6880593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
6890593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
6900593a44cSLeonid Yegoshin 			"6:lbu\t$1, 2(%2)\n\t"   	    \
6910593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
6920593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
6930593a44cSLeonid Yegoshin 			"7:lbu\t$1, 1(%2)\n\t"   	    \
6940593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
6950593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
6960593a44cSLeonid Yegoshin 			"8:lbu\t$1, 0(%2)\n\t"   	    \
6970593a44cSLeonid Yegoshin 			"dsll\t%0, 0x8\n\t"		    \
6980593a44cSLeonid Yegoshin 			"or\t%0, $1\n\t"		    \
6990593a44cSLeonid Yegoshin 			"li\t%1, 0\n"			    \
7000593a44cSLeonid Yegoshin 			".set\tpop\n\t"			    \
7010593a44cSLeonid Yegoshin 			"10:\n\t"			    \
7020593a44cSLeonid Yegoshin 			".insn\n\t"			    \
7030593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
7040593a44cSLeonid Yegoshin 			"11:\tli\t%1, %3\n\t"		    \
7050593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
7060593a44cSLeonid Yegoshin 			".previous\n\t"			    \
7070593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
7080593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
7090593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
7100593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
7110593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
7120593a44cSLeonid Yegoshin 			STR(PTR)"\t5b, 11b\n\t"		    \
7130593a44cSLeonid Yegoshin 			STR(PTR)"\t6b, 11b\n\t"		    \
7140593a44cSLeonid Yegoshin 			STR(PTR)"\t7b, 11b\n\t"		    \
7150593a44cSLeonid Yegoshin 			STR(PTR)"\t8b, 11b\n\t"		    \
7160593a44cSLeonid Yegoshin 			".previous"			    \
7170593a44cSLeonid Yegoshin 			: "=&r" (value), "=r" (res)	    \
7183563c32dSMarkos Chandras 			: "r" (addr), "i" (-EFAULT));       \
7193563c32dSMarkos Chandras } while(0)
7200593a44cSLeonid Yegoshin #endif /* CONFIG_CPU_MIPSR6 */
72134c2f668SLeonid Yegoshin 
722eeb53895SMarkos Chandras #define     _StoreHW(addr, value, res, type) \
7233563c32dSMarkos Chandras do {                                                        \
72434c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
72534c2f668SLeonid Yegoshin 			".set\tnoat\n"                      \
726eeb53895SMarkos Chandras 			"1:\t"type##_sb("%1", "0(%2)")"\n"  \
72734c2f668SLeonid Yegoshin 			"srl\t$1,%1, 0x8\n"                 \
728eeb53895SMarkos Chandras 			"2:\t"type##_sb("$1", "1(%2)")"\n"  \
72934c2f668SLeonid Yegoshin 			".set\tat\n\t"                      \
73034c2f668SLeonid Yegoshin 			"li\t%0, 0\n"                       \
73134c2f668SLeonid Yegoshin 			"3:\n\t"                            \
73234c2f668SLeonid Yegoshin 			".insn\n\t"                         \
73334c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
73434c2f668SLeonid Yegoshin 			"4:\tli\t%0, %3\n\t"                \
73534c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
73634c2f668SLeonid Yegoshin 			".previous\n\t"                     \
73734c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
73834c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
73934c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
74034c2f668SLeonid Yegoshin 			".previous"                         \
74134c2f668SLeonid Yegoshin 			: "=r" (res)                        \
7423563c32dSMarkos Chandras 			: "r" (value), "r" (addr), "i" (-EFAULT));\
7433563c32dSMarkos Chandras } while(0)
7443563c32dSMarkos Chandras 
7450593a44cSLeonid Yegoshin #ifndef CONFIG_CPU_MIPSR6
746eeb53895SMarkos Chandras #define     _StoreW(addr, value, res, type)  \
7473563c32dSMarkos Chandras do {                                                        \
74834c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
749eeb53895SMarkos Chandras 			"1:\t"type##_swl("%1", "3(%2)")"\n" \
750eeb53895SMarkos Chandras 			"2:\t"type##_swr("%1", "(%2)")"\n\t"\
75134c2f668SLeonid Yegoshin 			"li\t%0, 0\n"                       \
75234c2f668SLeonid Yegoshin 			"3:\n\t"                            \
75334c2f668SLeonid Yegoshin 			".insn\n\t"                         \
75434c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
75534c2f668SLeonid Yegoshin 			"4:\tli\t%0, %3\n\t"                \
75634c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
75734c2f668SLeonid Yegoshin 			".previous\n\t"                     \
75834c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
75934c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
76034c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
76134c2f668SLeonid Yegoshin 			".previous"                         \
76234c2f668SLeonid Yegoshin 		: "=r" (res)                                \
7633563c32dSMarkos Chandras 		: "r" (value), "r" (addr), "i" (-EFAULT));  \
7643563c32dSMarkos Chandras } while(0)
76534c2f668SLeonid Yegoshin 
766eeb53895SMarkos Chandras #define     _StoreDW(addr, value, res) \
7673563c32dSMarkos Chandras do {                                                        \
76834c2f668SLeonid Yegoshin 		__asm__ __volatile__ (                      \
76934c2f668SLeonid Yegoshin 			"1:\tsdl\t%1, 7(%2)\n"              \
77034c2f668SLeonid Yegoshin 			"2:\tsdr\t%1, (%2)\n\t"             \
77134c2f668SLeonid Yegoshin 			"li\t%0, 0\n"                       \
77234c2f668SLeonid Yegoshin 			"3:\n\t"                            \
77334c2f668SLeonid Yegoshin 			".insn\n\t"                         \
77434c2f668SLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"       \
77534c2f668SLeonid Yegoshin 			"4:\tli\t%0, %3\n\t"                \
77634c2f668SLeonid Yegoshin 			"j\t3b\n\t"                         \
77734c2f668SLeonid Yegoshin 			".previous\n\t"                     \
77834c2f668SLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
77934c2f668SLeonid Yegoshin 			STR(PTR)"\t1b, 4b\n\t"              \
78034c2f668SLeonid Yegoshin 			STR(PTR)"\t2b, 4b\n\t"              \
78134c2f668SLeonid Yegoshin 			".previous"                         \
78234c2f668SLeonid Yegoshin 		: "=r" (res)                                \
7833563c32dSMarkos Chandras 		: "r" (value), "r" (addr), "i" (-EFAULT));  \
7843563c32dSMarkos Chandras } while(0)
7853563c32dSMarkos Chandras 
7860593a44cSLeonid Yegoshin #else
7870593a44cSLeonid Yegoshin /* MIPSR6 has no swl and sdl instructions */
788eeb53895SMarkos Chandras #define     _StoreW(addr, value, res, type)  \
7893563c32dSMarkos Chandras do {                                                        \
7900593a44cSLeonid Yegoshin 		__asm__ __volatile__ (                      \
7910593a44cSLeonid Yegoshin 			".set\tpush\n\t"		    \
7920593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
793eeb53895SMarkos Chandras 			"1:"type##_sb("%1", "0(%2)")"\n\t"  \
7940593a44cSLeonid Yegoshin 			"srl\t$1, %1, 0x8\n\t"		    \
795eeb53895SMarkos Chandras 			"2:"type##_sb("$1", "1(%2)")"\n\t"  \
7960593a44cSLeonid Yegoshin 			"srl\t$1, $1,  0x8\n\t"		    \
797eeb53895SMarkos Chandras 			"3:"type##_sb("$1", "2(%2)")"\n\t"  \
7980593a44cSLeonid Yegoshin 			"srl\t$1, $1, 0x8\n\t"		    \
799eeb53895SMarkos Chandras 			"4:"type##_sb("$1", "3(%2)")"\n\t"  \
8000593a44cSLeonid Yegoshin 			".set\tpop\n\t"			    \
8010593a44cSLeonid Yegoshin 			"li\t%0, 0\n"			    \
8020593a44cSLeonid Yegoshin 			"10:\n\t"			    \
8030593a44cSLeonid Yegoshin 			".insn\n\t"			    \
8040593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
8050593a44cSLeonid Yegoshin 			"11:\tli\t%0, %3\n\t"		    \
8060593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
8070593a44cSLeonid Yegoshin 			".previous\n\t"			    \
8080593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
8090593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
8100593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
8110593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
8120593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
8130593a44cSLeonid Yegoshin 			".previous"			    \
8140593a44cSLeonid Yegoshin 		: "=&r" (res)			    	    \
8150593a44cSLeonid Yegoshin 		: "r" (value), "r" (addr), "i" (-EFAULT)    \
8163563c32dSMarkos Chandras 		: "memory");                                \
8173563c32dSMarkos Chandras } while(0)
8180593a44cSLeonid Yegoshin 
819eeb53895SMarkos Chandras #define     _StoreDW(addr, value, res) \
8203563c32dSMarkos Chandras do {                                                        \
8210593a44cSLeonid Yegoshin 		__asm__ __volatile__ (                      \
8220593a44cSLeonid Yegoshin 			".set\tpush\n\t"		    \
8230593a44cSLeonid Yegoshin 			".set\tnoat\n\t"		    \
8240593a44cSLeonid Yegoshin 			"1:sb\t%1, 0(%2)\n\t"    	    \
8250593a44cSLeonid Yegoshin 			"dsrl\t$1, %1, 0x8\n\t"		    \
8260593a44cSLeonid Yegoshin 			"2:sb\t$1, 1(%2)\n\t"    	    \
8270593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
8280593a44cSLeonid Yegoshin 			"3:sb\t$1, 2(%2)\n\t"    	    \
8290593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
8300593a44cSLeonid Yegoshin 			"4:sb\t$1, 3(%2)\n\t"    	    \
8310593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
8320593a44cSLeonid Yegoshin 			"5:sb\t$1, 4(%2)\n\t"    	    \
8330593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
8340593a44cSLeonid Yegoshin 			"6:sb\t$1, 5(%2)\n\t"    	    \
8350593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
8360593a44cSLeonid Yegoshin 			"7:sb\t$1, 6(%2)\n\t"    	    \
8370593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
8380593a44cSLeonid Yegoshin 			"8:sb\t$1, 7(%2)\n\t"    	    \
8390593a44cSLeonid Yegoshin 			"dsrl\t$1, $1, 0x8\n\t"		    \
8400593a44cSLeonid Yegoshin 			".set\tpop\n\t"			    \
8410593a44cSLeonid Yegoshin 			"li\t%0, 0\n"			    \
8420593a44cSLeonid Yegoshin 			"10:\n\t"			    \
8430593a44cSLeonid Yegoshin 			".insn\n\t"			    \
8440593a44cSLeonid Yegoshin 			".section\t.fixup,\"ax\"\n\t"	    \
8450593a44cSLeonid Yegoshin 			"11:\tli\t%0, %3\n\t"		    \
8460593a44cSLeonid Yegoshin 			"j\t10b\n\t"			    \
8470593a44cSLeonid Yegoshin 			".previous\n\t"			    \
8480593a44cSLeonid Yegoshin 			".section\t__ex_table,\"a\"\n\t"    \
8490593a44cSLeonid Yegoshin 			STR(PTR)"\t1b, 11b\n\t"		    \
8500593a44cSLeonid Yegoshin 			STR(PTR)"\t2b, 11b\n\t"		    \
8510593a44cSLeonid Yegoshin 			STR(PTR)"\t3b, 11b\n\t"		    \
8520593a44cSLeonid Yegoshin 			STR(PTR)"\t4b, 11b\n\t"		    \
8530593a44cSLeonid Yegoshin 			STR(PTR)"\t5b, 11b\n\t"		    \
8540593a44cSLeonid Yegoshin 			STR(PTR)"\t6b, 11b\n\t"		    \
8550593a44cSLeonid Yegoshin 			STR(PTR)"\t7b, 11b\n\t"		    \
8560593a44cSLeonid Yegoshin 			STR(PTR)"\t8b, 11b\n\t"		    \
8570593a44cSLeonid Yegoshin 			".previous"			    \
8580593a44cSLeonid Yegoshin 		: "=&r" (res)			    	    \
8590593a44cSLeonid Yegoshin 		: "r" (value), "r" (addr), "i" (-EFAULT)    \
8603563c32dSMarkos Chandras 		: "memory");                                \
8613563c32dSMarkos Chandras } while(0)
8623563c32dSMarkos Chandras 
8630593a44cSLeonid Yegoshin #endif /* CONFIG_CPU_MIPSR6 */
86434c2f668SLeonid Yegoshin #endif
86534c2f668SLeonid Yegoshin 
866eeb53895SMarkos Chandras #define LoadHWU(addr, value, res)	_LoadHWU(addr, value, res, kernel)
867eeb53895SMarkos Chandras #define LoadHWUE(addr, value, res)	_LoadHWU(addr, value, res, user)
868eeb53895SMarkos Chandras #define LoadWU(addr, value, res)	_LoadWU(addr, value, res, kernel)
869eeb53895SMarkos Chandras #define LoadWUE(addr, value, res)	_LoadWU(addr, value, res, user)
870eeb53895SMarkos Chandras #define LoadHW(addr, value, res)	_LoadHW(addr, value, res, kernel)
871eeb53895SMarkos Chandras #define LoadHWE(addr, value, res)	_LoadHW(addr, value, res, user)
872eeb53895SMarkos Chandras #define LoadW(addr, value, res)		_LoadW(addr, value, res, kernel)
873eeb53895SMarkos Chandras #define LoadWE(addr, value, res)	_LoadW(addr, value, res, user)
874eeb53895SMarkos Chandras #define LoadDW(addr, value, res)	_LoadDW(addr, value, res)
875eeb53895SMarkos Chandras 
876eeb53895SMarkos Chandras #define StoreHW(addr, value, res)	_StoreHW(addr, value, res, kernel)
877eeb53895SMarkos Chandras #define StoreHWE(addr, value, res)	_StoreHW(addr, value, res, user)
878eeb53895SMarkos Chandras #define StoreW(addr, value, res)	_StoreW(addr, value, res, kernel)
879eeb53895SMarkos Chandras #define StoreWE(addr, value, res)	_StoreW(addr, value, res, user)
880eeb53895SMarkos Chandras #define StoreDW(addr, value, res)	_StoreDW(addr, value, res)
881eeb53895SMarkos Chandras 
8827f18f151SRalf Baechle static void emulate_load_store_insn(struct pt_regs *regs,
8837f18f151SRalf Baechle 	void __user *addr, unsigned int __user *pc)
8841da177e4SLinus Torvalds {
8851da177e4SLinus Torvalds 	union mips_instruction insn;
8861da177e4SLinus Torvalds 	unsigned long value;
8871da177e4SLinus Torvalds 	unsigned int res;
88834c2f668SLeonid Yegoshin 	unsigned long origpc;
88934c2f668SLeonid Yegoshin 	unsigned long orig31;
890102cedc3SLeonid Yegoshin 	void __user *fault_addr = NULL;
891c1771216SLeonid Yegoshin #ifdef	CONFIG_EVA
892c1771216SLeonid Yegoshin 	mm_segment_t seg;
893c1771216SLeonid Yegoshin #endif
894*e4aa1f15SLeonid Yegoshin 	union fpureg *fpr;
895*e4aa1f15SLeonid Yegoshin 	enum msa_2b_fmt df;
896*e4aa1f15SLeonid Yegoshin 	unsigned int wd;
89734c2f668SLeonid Yegoshin 	origpc = (unsigned long)pc;
89834c2f668SLeonid Yegoshin 	orig31 = regs->regs[31];
89934c2f668SLeonid Yegoshin 
900a8b0ca17SPeter Zijlstra 	perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);
9017f788d2dSDeng-Cheng Zhu 
9021da177e4SLinus Torvalds 	/*
9031da177e4SLinus Torvalds 	 * This load never faults.
9041da177e4SLinus Torvalds 	 */
905fe00f943SRalf Baechle 	__get_user(insn.word, pc);
9061da177e4SLinus Torvalds 
9071da177e4SLinus Torvalds 	switch (insn.i_format.opcode) {
9081da177e4SLinus Torvalds 		/*
9091da177e4SLinus Torvalds 		 * These are instructions that a compiler doesn't generate.  We
9101da177e4SLinus Torvalds 		 * can assume therefore that the code is MIPS-aware and
9111da177e4SLinus Torvalds 		 * really buggy.  Emulating these instructions would break the
9121da177e4SLinus Torvalds 		 * semantics anyway.
9131da177e4SLinus Torvalds 		 */
9141da177e4SLinus Torvalds 	case ll_op:
9151da177e4SLinus Torvalds 	case lld_op:
9161da177e4SLinus Torvalds 	case sc_op:
9171da177e4SLinus Torvalds 	case scd_op:
9181da177e4SLinus Torvalds 
9191da177e4SLinus Torvalds 		/*
9201da177e4SLinus Torvalds 		 * For these instructions the only way to create an address
9211da177e4SLinus Torvalds 		 * error is an attempted access to kernel/supervisor address
9221da177e4SLinus Torvalds 		 * space.
9231da177e4SLinus Torvalds 		 */
9241da177e4SLinus Torvalds 	case ldl_op:
9251da177e4SLinus Torvalds 	case ldr_op:
9261da177e4SLinus Torvalds 	case lwl_op:
9271da177e4SLinus Torvalds 	case lwr_op:
9281da177e4SLinus Torvalds 	case sdl_op:
9291da177e4SLinus Torvalds 	case sdr_op:
9301da177e4SLinus Torvalds 	case swl_op:
9311da177e4SLinus Torvalds 	case swr_op:
9321da177e4SLinus Torvalds 	case lb_op:
9331da177e4SLinus Torvalds 	case lbu_op:
9341da177e4SLinus Torvalds 	case sb_op:
9351da177e4SLinus Torvalds 		goto sigbus;
9361da177e4SLinus Torvalds 
9371da177e4SLinus Torvalds 		/*
93834c2f668SLeonid Yegoshin 		 * The remaining opcodes are the ones that are really of
93934c2f668SLeonid Yegoshin 		 * interest.
9401da177e4SLinus Torvalds 		 */
941c1771216SLeonid Yegoshin #ifdef CONFIG_EVA
942c1771216SLeonid Yegoshin 	case spec3_op:
943c1771216SLeonid Yegoshin 		/*
944c1771216SLeonid Yegoshin 		 * we can land here only from kernel accessing user memory,
945c1771216SLeonid Yegoshin 		 * so we need to "switch" the address limit to user space, so
946c1771216SLeonid Yegoshin 		 * address check can work properly.
947c1771216SLeonid Yegoshin 		 */
948c1771216SLeonid Yegoshin 		seg = get_fs();
949c1771216SLeonid Yegoshin 		set_fs(USER_DS);
950c1771216SLeonid Yegoshin 		switch (insn.spec3_format.func) {
951c1771216SLeonid Yegoshin 		case lhe_op:
952c1771216SLeonid Yegoshin 			if (!access_ok(VERIFY_READ, addr, 2)) {
953c1771216SLeonid Yegoshin 				set_fs(seg);
954c1771216SLeonid Yegoshin 				goto sigbus;
955c1771216SLeonid Yegoshin 			}
956eeb53895SMarkos Chandras 			LoadHWE(addr, value, res);
957c1771216SLeonid Yegoshin 			if (res) {
958c1771216SLeonid Yegoshin 				set_fs(seg);
959c1771216SLeonid Yegoshin 				goto fault;
960c1771216SLeonid Yegoshin 			}
961c1771216SLeonid Yegoshin 			compute_return_epc(regs);
962c1771216SLeonid Yegoshin 			regs->regs[insn.spec3_format.rt] = value;
963c1771216SLeonid Yegoshin 			break;
964c1771216SLeonid Yegoshin 		case lwe_op:
965c1771216SLeonid Yegoshin 			if (!access_ok(VERIFY_READ, addr, 4)) {
966c1771216SLeonid Yegoshin 				set_fs(seg);
967c1771216SLeonid Yegoshin 				goto sigbus;
968c1771216SLeonid Yegoshin 			}
969eeb53895SMarkos Chandras 				LoadWE(addr, value, res);
970c1771216SLeonid Yegoshin 			if (res) {
971c1771216SLeonid Yegoshin 				set_fs(seg);
972c1771216SLeonid Yegoshin 				goto fault;
973c1771216SLeonid Yegoshin 			}
974c1771216SLeonid Yegoshin 			compute_return_epc(regs);
975c1771216SLeonid Yegoshin 			regs->regs[insn.spec3_format.rt] = value;
976c1771216SLeonid Yegoshin 			break;
977c1771216SLeonid Yegoshin 		case lhue_op:
978c1771216SLeonid Yegoshin 			if (!access_ok(VERIFY_READ, addr, 2)) {
979c1771216SLeonid Yegoshin 				set_fs(seg);
980c1771216SLeonid Yegoshin 				goto sigbus;
981c1771216SLeonid Yegoshin 			}
982eeb53895SMarkos Chandras 			LoadHWUE(addr, value, res);
983c1771216SLeonid Yegoshin 			if (res) {
984c1771216SLeonid Yegoshin 				set_fs(seg);
985c1771216SLeonid Yegoshin 				goto fault;
986c1771216SLeonid Yegoshin 			}
987c1771216SLeonid Yegoshin 			compute_return_epc(regs);
988c1771216SLeonid Yegoshin 			regs->regs[insn.spec3_format.rt] = value;
989c1771216SLeonid Yegoshin 			break;
990c1771216SLeonid Yegoshin 		case she_op:
991c1771216SLeonid Yegoshin 			if (!access_ok(VERIFY_WRITE, addr, 2)) {
992c1771216SLeonid Yegoshin 				set_fs(seg);
993c1771216SLeonid Yegoshin 				goto sigbus;
994c1771216SLeonid Yegoshin 			}
995c1771216SLeonid Yegoshin 			compute_return_epc(regs);
996c1771216SLeonid Yegoshin 			value = regs->regs[insn.spec3_format.rt];
997eeb53895SMarkos Chandras 			StoreHWE(addr, value, res);
998c1771216SLeonid Yegoshin 			if (res) {
999c1771216SLeonid Yegoshin 				set_fs(seg);
1000c1771216SLeonid Yegoshin 				goto fault;
1001c1771216SLeonid Yegoshin 			}
1002c1771216SLeonid Yegoshin 			break;
1003c1771216SLeonid Yegoshin 		case swe_op:
1004c1771216SLeonid Yegoshin 			if (!access_ok(VERIFY_WRITE, addr, 4)) {
1005c1771216SLeonid Yegoshin 				set_fs(seg);
1006c1771216SLeonid Yegoshin 				goto sigbus;
1007c1771216SLeonid Yegoshin 			}
1008c1771216SLeonid Yegoshin 			compute_return_epc(regs);
1009c1771216SLeonid Yegoshin 			value = regs->regs[insn.spec3_format.rt];
1010eeb53895SMarkos Chandras 			StoreWE(addr, value, res);
1011c1771216SLeonid Yegoshin 			if (res) {
1012c1771216SLeonid Yegoshin 				set_fs(seg);
1013c1771216SLeonid Yegoshin 				goto fault;
1014c1771216SLeonid Yegoshin 			}
1015c1771216SLeonid Yegoshin 			break;
1016c1771216SLeonid Yegoshin 		default:
1017c1771216SLeonid Yegoshin 			set_fs(seg);
1018c1771216SLeonid Yegoshin 			goto sigill;
1019c1771216SLeonid Yegoshin 		}
1020c1771216SLeonid Yegoshin 		set_fs(seg);
1021c1771216SLeonid Yegoshin 		break;
1022c1771216SLeonid Yegoshin #endif
10231da177e4SLinus Torvalds 	case lh_op:
10241da177e4SLinus Torvalds 		if (!access_ok(VERIFY_READ, addr, 2))
10251da177e4SLinus Torvalds 			goto sigbus;
10261da177e4SLinus Torvalds 
10276eae3548SMarkos Chandras 		if (config_enabled(CONFIG_EVA)) {
10286eae3548SMarkos Chandras 			if (segment_eq(get_fs(), get_ds()))
102934c2f668SLeonid Yegoshin 				LoadHW(addr, value, res);
10306eae3548SMarkos Chandras 			else
10316eae3548SMarkos Chandras 				LoadHWE(addr, value, res);
10326eae3548SMarkos Chandras 		} else {
10336eae3548SMarkos Chandras 			LoadHW(addr, value, res);
10346eae3548SMarkos Chandras 		}
10356eae3548SMarkos Chandras 
10361da177e4SLinus Torvalds 		if (res)
10371da177e4SLinus Torvalds 			goto fault;
10387f18f151SRalf Baechle 		compute_return_epc(regs);
10397f18f151SRalf Baechle 		regs->regs[insn.i_format.rt] = value;
10401da177e4SLinus Torvalds 		break;
10411da177e4SLinus Torvalds 
10421da177e4SLinus Torvalds 	case lw_op:
10431da177e4SLinus Torvalds 		if (!access_ok(VERIFY_READ, addr, 4))
10441da177e4SLinus Torvalds 			goto sigbus;
10451da177e4SLinus Torvalds 
10466eae3548SMarkos Chandras 		if (config_enabled(CONFIG_EVA)) {
10476eae3548SMarkos Chandras 			if (segment_eq(get_fs(), get_ds()))
104834c2f668SLeonid Yegoshin 				LoadW(addr, value, res);
10496eae3548SMarkos Chandras 			else
10506eae3548SMarkos Chandras 				LoadWE(addr, value, res);
10516eae3548SMarkos Chandras 		} else {
10526eae3548SMarkos Chandras 			LoadW(addr, value, res);
10536eae3548SMarkos Chandras 		}
10546eae3548SMarkos Chandras 
10551da177e4SLinus Torvalds 		if (res)
10561da177e4SLinus Torvalds 			goto fault;
10577f18f151SRalf Baechle 		compute_return_epc(regs);
10587f18f151SRalf Baechle 		regs->regs[insn.i_format.rt] = value;
10591da177e4SLinus Torvalds 		break;
10601da177e4SLinus Torvalds 
10611da177e4SLinus Torvalds 	case lhu_op:
10621da177e4SLinus Torvalds 		if (!access_ok(VERIFY_READ, addr, 2))
10631da177e4SLinus Torvalds 			goto sigbus;
10641da177e4SLinus Torvalds 
10656eae3548SMarkos Chandras 		if (config_enabled(CONFIG_EVA)) {
10666eae3548SMarkos Chandras 			if (segment_eq(get_fs(), get_ds()))
106734c2f668SLeonid Yegoshin 				LoadHWU(addr, value, res);
10686eae3548SMarkos Chandras 			else
10696eae3548SMarkos Chandras 				LoadHWUE(addr, value, res);
10706eae3548SMarkos Chandras 		} else {
10716eae3548SMarkos Chandras 			LoadHWU(addr, value, res);
10726eae3548SMarkos Chandras 		}
10736eae3548SMarkos Chandras 
10741da177e4SLinus Torvalds 		if (res)
10751da177e4SLinus Torvalds 			goto fault;
10767f18f151SRalf Baechle 		compute_return_epc(regs);
10777f18f151SRalf Baechle 		regs->regs[insn.i_format.rt] = value;
10781da177e4SLinus Torvalds 		break;
10791da177e4SLinus Torvalds 
10801da177e4SLinus Torvalds 	case lwu_op:
1081875d43e7SRalf Baechle #ifdef CONFIG_64BIT
10821da177e4SLinus Torvalds 		/*
10831da177e4SLinus Torvalds 		 * A 32-bit kernel might be running on a 64-bit processor.  But
10841da177e4SLinus Torvalds 		 * if we're on a 32-bit processor and an i-cache incoherency
10851da177e4SLinus Torvalds 		 * or race makes us see a 64-bit instruction here the sdl/sdr
10861da177e4SLinus Torvalds 		 * would blow up, so for now we don't handle unaligned 64-bit
10871da177e4SLinus Torvalds 		 * instructions on 32-bit kernels.
10881da177e4SLinus Torvalds 		 */
10891da177e4SLinus Torvalds 		if (!access_ok(VERIFY_READ, addr, 4))
10901da177e4SLinus Torvalds 			goto sigbus;
10911da177e4SLinus Torvalds 
109234c2f668SLeonid Yegoshin 		LoadWU(addr, value, res);
10931da177e4SLinus Torvalds 		if (res)
10941da177e4SLinus Torvalds 			goto fault;
10957f18f151SRalf Baechle 		compute_return_epc(regs);
10967f18f151SRalf Baechle 		regs->regs[insn.i_format.rt] = value;
10971da177e4SLinus Torvalds 		break;
1098875d43e7SRalf Baechle #endif /* CONFIG_64BIT */
10991da177e4SLinus Torvalds 
11001da177e4SLinus Torvalds 		/* Cannot handle 64-bit instructions in 32-bit kernel */
11011da177e4SLinus Torvalds 		goto sigill;
11021da177e4SLinus Torvalds 
11031da177e4SLinus Torvalds 	case ld_op:
1104875d43e7SRalf Baechle #ifdef CONFIG_64BIT
11051da177e4SLinus Torvalds 		/*
11061da177e4SLinus Torvalds 		 * A 32-bit kernel might be running on a 64-bit processor.  But
11071da177e4SLinus Torvalds 		 * if we're on a 32-bit processor and an i-cache incoherency
11081da177e4SLinus Torvalds 		 * or race makes us see a 64-bit instruction here the sdl/sdr
11091da177e4SLinus Torvalds 		 * would blow up, so for now we don't handle unaligned 64-bit
11101da177e4SLinus Torvalds 		 * instructions on 32-bit kernels.
11111da177e4SLinus Torvalds 		 */
11121da177e4SLinus Torvalds 		if (!access_ok(VERIFY_READ, addr, 8))
11131da177e4SLinus Torvalds 			goto sigbus;
11141da177e4SLinus Torvalds 
111534c2f668SLeonid Yegoshin 		LoadDW(addr, value, res);
11161da177e4SLinus Torvalds 		if (res)
11171da177e4SLinus Torvalds 			goto fault;
11187f18f151SRalf Baechle 		compute_return_epc(regs);
11197f18f151SRalf Baechle 		regs->regs[insn.i_format.rt] = value;
11201da177e4SLinus Torvalds 		break;
1121875d43e7SRalf Baechle #endif /* CONFIG_64BIT */
11221da177e4SLinus Torvalds 
11231da177e4SLinus Torvalds 		/* Cannot handle 64-bit instructions in 32-bit kernel */
11241da177e4SLinus Torvalds 		goto sigill;
11251da177e4SLinus Torvalds 
11261da177e4SLinus Torvalds 	case sh_op:
11271da177e4SLinus Torvalds 		if (!access_ok(VERIFY_WRITE, addr, 2))
11281da177e4SLinus Torvalds 			goto sigbus;
11291da177e4SLinus Torvalds 
113034c2f668SLeonid Yegoshin 		compute_return_epc(regs);
11311da177e4SLinus Torvalds 		value = regs->regs[insn.i_format.rt];
11326eae3548SMarkos Chandras 
11336eae3548SMarkos Chandras 		if (config_enabled(CONFIG_EVA)) {
11346eae3548SMarkos Chandras 			if (segment_eq(get_fs(), get_ds()))
113534c2f668SLeonid Yegoshin 				StoreHW(addr, value, res);
11366eae3548SMarkos Chandras 			else
11376eae3548SMarkos Chandras 				StoreHWE(addr, value, res);
11386eae3548SMarkos Chandras 		} else {
11396eae3548SMarkos Chandras 			StoreHW(addr, value, res);
11406eae3548SMarkos Chandras 		}
11416eae3548SMarkos Chandras 
11421da177e4SLinus Torvalds 		if (res)
11431da177e4SLinus Torvalds 			goto fault;
11441da177e4SLinus Torvalds 		break;
11451da177e4SLinus Torvalds 
11461da177e4SLinus Torvalds 	case sw_op:
11471da177e4SLinus Torvalds 		if (!access_ok(VERIFY_WRITE, addr, 4))
11481da177e4SLinus Torvalds 			goto sigbus;
11491da177e4SLinus Torvalds 
115034c2f668SLeonid Yegoshin 		compute_return_epc(regs);
11511da177e4SLinus Torvalds 		value = regs->regs[insn.i_format.rt];
11526eae3548SMarkos Chandras 
11536eae3548SMarkos Chandras 		if (config_enabled(CONFIG_EVA)) {
11546eae3548SMarkos Chandras 			if (segment_eq(get_fs(), get_ds()))
115534c2f668SLeonid Yegoshin 				StoreW(addr, value, res);
11566eae3548SMarkos Chandras 			else
11576eae3548SMarkos Chandras 				StoreWE(addr, value, res);
11586eae3548SMarkos Chandras 		} else {
11596eae3548SMarkos Chandras 			StoreW(addr, value, res);
11606eae3548SMarkos Chandras 		}
11616eae3548SMarkos Chandras 
11621da177e4SLinus Torvalds 		if (res)
11631da177e4SLinus Torvalds 			goto fault;
11641da177e4SLinus Torvalds 		break;
11651da177e4SLinus Torvalds 
11661da177e4SLinus Torvalds 	case sd_op:
1167875d43e7SRalf Baechle #ifdef CONFIG_64BIT
11681da177e4SLinus Torvalds 		/*
11691da177e4SLinus Torvalds 		 * A 32-bit kernel might be running on a 64-bit processor.  But
11701da177e4SLinus Torvalds 		 * if we're on a 32-bit processor and an i-cache incoherency
11711da177e4SLinus Torvalds 		 * or race makes us see a 64-bit instruction here the sdl/sdr
11721da177e4SLinus Torvalds 		 * would blow up, so for now we don't handle unaligned 64-bit
11731da177e4SLinus Torvalds 		 * instructions on 32-bit kernels.
11741da177e4SLinus Torvalds 		 */
11751da177e4SLinus Torvalds 		if (!access_ok(VERIFY_WRITE, addr, 8))
11761da177e4SLinus Torvalds 			goto sigbus;
11771da177e4SLinus Torvalds 
117834c2f668SLeonid Yegoshin 		compute_return_epc(regs);
11791da177e4SLinus Torvalds 		value = regs->regs[insn.i_format.rt];
118034c2f668SLeonid Yegoshin 		StoreDW(addr, value, res);
11811da177e4SLinus Torvalds 		if (res)
11821da177e4SLinus Torvalds 			goto fault;
11831da177e4SLinus Torvalds 		break;
1184875d43e7SRalf Baechle #endif /* CONFIG_64BIT */
11851da177e4SLinus Torvalds 
11861da177e4SLinus Torvalds 		/* Cannot handle 64-bit instructions in 32-bit kernel */
11871da177e4SLinus Torvalds 		goto sigill;
11881da177e4SLinus Torvalds 
11891da177e4SLinus Torvalds 	case lwc1_op:
11901da177e4SLinus Torvalds 	case ldc1_op:
11911da177e4SLinus Torvalds 	case swc1_op:
11921da177e4SLinus Torvalds 	case sdc1_op:
1193102cedc3SLeonid Yegoshin 		die_if_kernel("Unaligned FP access in kernel code", regs);
1194102cedc3SLeonid Yegoshin 		BUG_ON(!used_math());
1195102cedc3SLeonid Yegoshin 
1196102cedc3SLeonid Yegoshin 		lose_fpu(1);	/* Save FPU state for the emulator. */
1197102cedc3SLeonid Yegoshin 		res = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
1198102cedc3SLeonid Yegoshin 					       &fault_addr);
1199102cedc3SLeonid Yegoshin 		own_fpu(1);	/* Restore FPU state. */
1200102cedc3SLeonid Yegoshin 
1201102cedc3SLeonid Yegoshin 		/* Signal if something went wrong. */
1202304acb71SMaciej W. Rozycki 		process_fpemu_return(res, fault_addr, 0);
1203102cedc3SLeonid Yegoshin 
1204102cedc3SLeonid Yegoshin 		if (res == 0)
1205102cedc3SLeonid Yegoshin 			break;
1206102cedc3SLeonid Yegoshin 		return;
12071da177e4SLinus Torvalds 
1208*e4aa1f15SLeonid Yegoshin 	case msa_op:
1209*e4aa1f15SLeonid Yegoshin 		if (!cpu_has_msa)
1210*e4aa1f15SLeonid Yegoshin 			goto sigill;
1211*e4aa1f15SLeonid Yegoshin 
1212*e4aa1f15SLeonid Yegoshin 		/*
1213*e4aa1f15SLeonid Yegoshin 		 * If we've reached this point then userland should have taken
1214*e4aa1f15SLeonid Yegoshin 		 * the MSA disabled exception & initialised vector context at
1215*e4aa1f15SLeonid Yegoshin 		 * some point in the past.
1216*e4aa1f15SLeonid Yegoshin 		 */
1217*e4aa1f15SLeonid Yegoshin 		BUG_ON(!thread_msa_context_live());
1218*e4aa1f15SLeonid Yegoshin 
1219*e4aa1f15SLeonid Yegoshin 		df = insn.msa_mi10_format.df;
1220*e4aa1f15SLeonid Yegoshin 		wd = insn.msa_mi10_format.wd;
1221*e4aa1f15SLeonid Yegoshin 		fpr = &current->thread.fpu.fpr[wd];
1222*e4aa1f15SLeonid Yegoshin 
1223*e4aa1f15SLeonid Yegoshin 		switch (insn.msa_mi10_format.func) {
1224*e4aa1f15SLeonid Yegoshin 		case msa_ld_op:
1225*e4aa1f15SLeonid Yegoshin 			if (!access_ok(VERIFY_READ, addr, sizeof(*fpr)))
1226*e4aa1f15SLeonid Yegoshin 				goto sigbus;
1227*e4aa1f15SLeonid Yegoshin 
1228*e4aa1f15SLeonid Yegoshin 			/*
1229*e4aa1f15SLeonid Yegoshin 			 * Disable preemption to avoid a race between copying
1230*e4aa1f15SLeonid Yegoshin 			 * state from userland, migrating to another CPU and
1231*e4aa1f15SLeonid Yegoshin 			 * updating the hardware vector register below.
1232*e4aa1f15SLeonid Yegoshin 			 */
1233*e4aa1f15SLeonid Yegoshin 			preempt_disable();
1234*e4aa1f15SLeonid Yegoshin 
1235*e4aa1f15SLeonid Yegoshin 			res = __copy_from_user_inatomic(fpr, addr,
1236*e4aa1f15SLeonid Yegoshin 							sizeof(*fpr));
1237*e4aa1f15SLeonid Yegoshin 			if (res)
1238*e4aa1f15SLeonid Yegoshin 				goto fault;
1239*e4aa1f15SLeonid Yegoshin 
1240*e4aa1f15SLeonid Yegoshin 			/*
1241*e4aa1f15SLeonid Yegoshin 			 * Update the hardware register if it is in use by the
1242*e4aa1f15SLeonid Yegoshin 			 * task in this quantum, in order to avoid having to
1243*e4aa1f15SLeonid Yegoshin 			 * save & restore the whole vector context.
1244*e4aa1f15SLeonid Yegoshin 			 */
1245*e4aa1f15SLeonid Yegoshin 			if (test_thread_flag(TIF_USEDMSA))
1246*e4aa1f15SLeonid Yegoshin 				write_msa_wr(wd, fpr, df);
1247*e4aa1f15SLeonid Yegoshin 
1248*e4aa1f15SLeonid Yegoshin 			preempt_enable();
1249*e4aa1f15SLeonid Yegoshin 			break;
1250*e4aa1f15SLeonid Yegoshin 
1251*e4aa1f15SLeonid Yegoshin 		case msa_st_op:
1252*e4aa1f15SLeonid Yegoshin 			if (!access_ok(VERIFY_WRITE, addr, sizeof(*fpr)))
1253*e4aa1f15SLeonid Yegoshin 				goto sigbus;
1254*e4aa1f15SLeonid Yegoshin 
1255*e4aa1f15SLeonid Yegoshin 			/*
1256*e4aa1f15SLeonid Yegoshin 			 * Update from the hardware register if it is in use by
1257*e4aa1f15SLeonid Yegoshin 			 * the task in this quantum, in order to avoid having to
1258*e4aa1f15SLeonid Yegoshin 			 * save & restore the whole vector context.
1259*e4aa1f15SLeonid Yegoshin 			 */
1260*e4aa1f15SLeonid Yegoshin 			preempt_disable();
1261*e4aa1f15SLeonid Yegoshin 			if (test_thread_flag(TIF_USEDMSA))
1262*e4aa1f15SLeonid Yegoshin 				read_msa_wr(wd, fpr, df);
1263*e4aa1f15SLeonid Yegoshin 			preempt_enable();
1264*e4aa1f15SLeonid Yegoshin 
1265*e4aa1f15SLeonid Yegoshin 			res = __copy_to_user_inatomic(addr, fpr, sizeof(*fpr));
1266*e4aa1f15SLeonid Yegoshin 			if (res)
1267*e4aa1f15SLeonid Yegoshin 				goto fault;
1268*e4aa1f15SLeonid Yegoshin 			break;
1269*e4aa1f15SLeonid Yegoshin 
1270*e4aa1f15SLeonid Yegoshin 		default:
1271*e4aa1f15SLeonid Yegoshin 			goto sigbus;
1272*e4aa1f15SLeonid Yegoshin 		}
1273*e4aa1f15SLeonid Yegoshin 
1274*e4aa1f15SLeonid Yegoshin 		compute_return_epc(regs);
1275*e4aa1f15SLeonid Yegoshin 		break;
1276*e4aa1f15SLeonid Yegoshin 
12770593a44cSLeonid Yegoshin #ifndef CONFIG_CPU_MIPSR6
12781da177e4SLinus Torvalds 	/*
127969f3a7deSRalf Baechle 	 * COP2 is available to implementor for application specific use.
128069f3a7deSRalf Baechle 	 * It's up to applications to register a notifier chain and do
128169f3a7deSRalf Baechle 	 * whatever they have to do, including possible sending of signals.
12820593a44cSLeonid Yegoshin 	 *
12830593a44cSLeonid Yegoshin 	 * This instruction has been reallocated in Release 6
12841da177e4SLinus Torvalds 	 */
128569f3a7deSRalf Baechle 	case lwc2_op:
128669f3a7deSRalf Baechle 		cu2_notifier_call_chain(CU2_LWC2_OP, regs);
128769f3a7deSRalf Baechle 		break;
128869f3a7deSRalf Baechle 
128969f3a7deSRalf Baechle 	case ldc2_op:
129069f3a7deSRalf Baechle 		cu2_notifier_call_chain(CU2_LDC2_OP, regs);
129169f3a7deSRalf Baechle 		break;
129269f3a7deSRalf Baechle 
129369f3a7deSRalf Baechle 	case swc2_op:
129469f3a7deSRalf Baechle 		cu2_notifier_call_chain(CU2_SWC2_OP, regs);
129569f3a7deSRalf Baechle 		break;
129669f3a7deSRalf Baechle 
129769f3a7deSRalf Baechle 	case sdc2_op:
129869f3a7deSRalf Baechle 		cu2_notifier_call_chain(CU2_SDC2_OP, regs);
129969f3a7deSRalf Baechle 		break;
13000593a44cSLeonid Yegoshin #endif
13011da177e4SLinus Torvalds 	default:
13021da177e4SLinus Torvalds 		/*
13031da177e4SLinus Torvalds 		 * Pheeee...  We encountered an yet unknown instruction or
13041da177e4SLinus Torvalds 		 * cache coherence problem.  Die sucker, die ...
13051da177e4SLinus Torvalds 		 */
13061da177e4SLinus Torvalds 		goto sigill;
13071da177e4SLinus Torvalds 	}
13081da177e4SLinus Torvalds 
13096312e0eeSAtsushi Nemoto #ifdef CONFIG_DEBUG_FS
13101da177e4SLinus Torvalds 	unaligned_instructions++;
13111da177e4SLinus Torvalds #endif
13121da177e4SLinus Torvalds 
13137f18f151SRalf Baechle 	return;
13141da177e4SLinus Torvalds 
13151da177e4SLinus Torvalds fault:
131634c2f668SLeonid Yegoshin 	/* roll back jump/branch */
131734c2f668SLeonid Yegoshin 	regs->cp0_epc = origpc;
131834c2f668SLeonid Yegoshin 	regs->regs[31] = orig31;
13191da177e4SLinus Torvalds 	/* Did we have an exception handler installed? */
13201da177e4SLinus Torvalds 	if (fixup_exception(regs))
13217f18f151SRalf Baechle 		return;
13221da177e4SLinus Torvalds 
13231da177e4SLinus Torvalds 	die_if_kernel("Unhandled kernel unaligned access", regs);
1324a6d5ff04SDavid Daney 	force_sig(SIGSEGV, current);
13251da177e4SLinus Torvalds 
13267f18f151SRalf Baechle 	return;
13271da177e4SLinus Torvalds 
13281da177e4SLinus Torvalds sigbus:
13291da177e4SLinus Torvalds 	die_if_kernel("Unhandled kernel unaligned access", regs);
1330a6d5ff04SDavid Daney 	force_sig(SIGBUS, current);
13311da177e4SLinus Torvalds 
13327f18f151SRalf Baechle 	return;
13331da177e4SLinus Torvalds 
13341da177e4SLinus Torvalds sigill:
133534c2f668SLeonid Yegoshin 	die_if_kernel
133634c2f668SLeonid Yegoshin 	    ("Unhandled kernel unaligned access or invalid instruction", regs);
133734c2f668SLeonid Yegoshin 	force_sig(SIGILL, current);
133834c2f668SLeonid Yegoshin }
133934c2f668SLeonid Yegoshin 
134034c2f668SLeonid Yegoshin /* Recode table from 16-bit register notation to 32-bit GPR. */
134134c2f668SLeonid Yegoshin const int reg16to32[] = { 16, 17, 2, 3, 4, 5, 6, 7 };
134234c2f668SLeonid Yegoshin 
134334c2f668SLeonid Yegoshin /* Recode table from 16-bit STORE register notation to 32-bit GPR. */
134434c2f668SLeonid Yegoshin const int reg16to32st[] = { 0, 17, 2, 3, 4, 5, 6, 7 };
134534c2f668SLeonid Yegoshin 
134674338805SDavid Daney static void emulate_load_store_microMIPS(struct pt_regs *regs,
134774338805SDavid Daney 					 void __user *addr)
134834c2f668SLeonid Yegoshin {
134934c2f668SLeonid Yegoshin 	unsigned long value;
135034c2f668SLeonid Yegoshin 	unsigned int res;
135134c2f668SLeonid Yegoshin 	int i;
135234c2f668SLeonid Yegoshin 	unsigned int reg = 0, rvar;
135334c2f668SLeonid Yegoshin 	unsigned long orig31;
135434c2f668SLeonid Yegoshin 	u16 __user *pc16;
135534c2f668SLeonid Yegoshin 	u16 halfword;
135634c2f668SLeonid Yegoshin 	unsigned int word;
135734c2f668SLeonid Yegoshin 	unsigned long origpc, contpc;
135834c2f668SLeonid Yegoshin 	union mips_instruction insn;
135934c2f668SLeonid Yegoshin 	struct mm_decoded_insn mminsn;
136034c2f668SLeonid Yegoshin 	void __user *fault_addr = NULL;
136134c2f668SLeonid Yegoshin 
136234c2f668SLeonid Yegoshin 	origpc = regs->cp0_epc;
136334c2f668SLeonid Yegoshin 	orig31 = regs->regs[31];
136434c2f668SLeonid Yegoshin 
136534c2f668SLeonid Yegoshin 	mminsn.micro_mips_mode = 1;
136634c2f668SLeonid Yegoshin 
136734c2f668SLeonid Yegoshin 	/*
136834c2f668SLeonid Yegoshin 	 * This load never faults.
136934c2f668SLeonid Yegoshin 	 */
137034c2f668SLeonid Yegoshin 	pc16 = (unsigned short __user *)msk_isa16_mode(regs->cp0_epc);
137134c2f668SLeonid Yegoshin 	__get_user(halfword, pc16);
137234c2f668SLeonid Yegoshin 	pc16++;
137334c2f668SLeonid Yegoshin 	contpc = regs->cp0_epc + 2;
137434c2f668SLeonid Yegoshin 	word = ((unsigned int)halfword << 16);
137534c2f668SLeonid Yegoshin 	mminsn.pc_inc = 2;
137634c2f668SLeonid Yegoshin 
137734c2f668SLeonid Yegoshin 	if (!mm_insn_16bit(halfword)) {
137834c2f668SLeonid Yegoshin 		__get_user(halfword, pc16);
137934c2f668SLeonid Yegoshin 		pc16++;
138034c2f668SLeonid Yegoshin 		contpc = regs->cp0_epc + 4;
138134c2f668SLeonid Yegoshin 		mminsn.pc_inc = 4;
138234c2f668SLeonid Yegoshin 		word |= halfword;
138334c2f668SLeonid Yegoshin 	}
138434c2f668SLeonid Yegoshin 	mminsn.insn = word;
138534c2f668SLeonid Yegoshin 
138634c2f668SLeonid Yegoshin 	if (get_user(halfword, pc16))
138734c2f668SLeonid Yegoshin 		goto fault;
138834c2f668SLeonid Yegoshin 	mminsn.next_pc_inc = 2;
138934c2f668SLeonid Yegoshin 	word = ((unsigned int)halfword << 16);
139034c2f668SLeonid Yegoshin 
139134c2f668SLeonid Yegoshin 	if (!mm_insn_16bit(halfword)) {
139234c2f668SLeonid Yegoshin 		pc16++;
139334c2f668SLeonid Yegoshin 		if (get_user(halfword, pc16))
139434c2f668SLeonid Yegoshin 			goto fault;
139534c2f668SLeonid Yegoshin 		mminsn.next_pc_inc = 4;
139634c2f668SLeonid Yegoshin 		word |= halfword;
139734c2f668SLeonid Yegoshin 	}
139834c2f668SLeonid Yegoshin 	mminsn.next_insn = word;
139934c2f668SLeonid Yegoshin 
140034c2f668SLeonid Yegoshin 	insn = (union mips_instruction)(mminsn.insn);
140134c2f668SLeonid Yegoshin 	if (mm_isBranchInstr(regs, mminsn, &contpc))
140234c2f668SLeonid Yegoshin 		insn = (union mips_instruction)(mminsn.next_insn);
140334c2f668SLeonid Yegoshin 
140434c2f668SLeonid Yegoshin 	/*  Parse instruction to find what to do */
140534c2f668SLeonid Yegoshin 
140634c2f668SLeonid Yegoshin 	switch (insn.mm_i_format.opcode) {
140734c2f668SLeonid Yegoshin 
140834c2f668SLeonid Yegoshin 	case mm_pool32a_op:
140934c2f668SLeonid Yegoshin 		switch (insn.mm_x_format.func) {
141034c2f668SLeonid Yegoshin 		case mm_lwxs_op:
141134c2f668SLeonid Yegoshin 			reg = insn.mm_x_format.rd;
141234c2f668SLeonid Yegoshin 			goto loadW;
141334c2f668SLeonid Yegoshin 		}
141434c2f668SLeonid Yegoshin 
141534c2f668SLeonid Yegoshin 		goto sigbus;
141634c2f668SLeonid Yegoshin 
141734c2f668SLeonid Yegoshin 	case mm_pool32b_op:
141834c2f668SLeonid Yegoshin 		switch (insn.mm_m_format.func) {
141934c2f668SLeonid Yegoshin 		case mm_lwp_func:
142034c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
142134c2f668SLeonid Yegoshin 			if (reg == 31)
142234c2f668SLeonid Yegoshin 				goto sigbus;
142334c2f668SLeonid Yegoshin 
142434c2f668SLeonid Yegoshin 			if (!access_ok(VERIFY_READ, addr, 8))
142534c2f668SLeonid Yegoshin 				goto sigbus;
142634c2f668SLeonid Yegoshin 
142734c2f668SLeonid Yegoshin 			LoadW(addr, value, res);
142834c2f668SLeonid Yegoshin 			if (res)
142934c2f668SLeonid Yegoshin 				goto fault;
143034c2f668SLeonid Yegoshin 			regs->regs[reg] = value;
143134c2f668SLeonid Yegoshin 			addr += 4;
143234c2f668SLeonid Yegoshin 			LoadW(addr, value, res);
143334c2f668SLeonid Yegoshin 			if (res)
143434c2f668SLeonid Yegoshin 				goto fault;
143534c2f668SLeonid Yegoshin 			regs->regs[reg + 1] = value;
143634c2f668SLeonid Yegoshin 			goto success;
143734c2f668SLeonid Yegoshin 
143834c2f668SLeonid Yegoshin 		case mm_swp_func:
143934c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
144034c2f668SLeonid Yegoshin 			if (reg == 31)
144134c2f668SLeonid Yegoshin 				goto sigbus;
144234c2f668SLeonid Yegoshin 
144334c2f668SLeonid Yegoshin 			if (!access_ok(VERIFY_WRITE, addr, 8))
144434c2f668SLeonid Yegoshin 				goto sigbus;
144534c2f668SLeonid Yegoshin 
144634c2f668SLeonid Yegoshin 			value = regs->regs[reg];
144734c2f668SLeonid Yegoshin 			StoreW(addr, value, res);
144834c2f668SLeonid Yegoshin 			if (res)
144934c2f668SLeonid Yegoshin 				goto fault;
145034c2f668SLeonid Yegoshin 			addr += 4;
145134c2f668SLeonid Yegoshin 			value = regs->regs[reg + 1];
145234c2f668SLeonid Yegoshin 			StoreW(addr, value, res);
145334c2f668SLeonid Yegoshin 			if (res)
145434c2f668SLeonid Yegoshin 				goto fault;
145534c2f668SLeonid Yegoshin 			goto success;
145634c2f668SLeonid Yegoshin 
145734c2f668SLeonid Yegoshin 		case mm_ldp_func:
145834c2f668SLeonid Yegoshin #ifdef CONFIG_64BIT
145934c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
146034c2f668SLeonid Yegoshin 			if (reg == 31)
146134c2f668SLeonid Yegoshin 				goto sigbus;
146234c2f668SLeonid Yegoshin 
146334c2f668SLeonid Yegoshin 			if (!access_ok(VERIFY_READ, addr, 16))
146434c2f668SLeonid Yegoshin 				goto sigbus;
146534c2f668SLeonid Yegoshin 
146634c2f668SLeonid Yegoshin 			LoadDW(addr, value, res);
146734c2f668SLeonid Yegoshin 			if (res)
146834c2f668SLeonid Yegoshin 				goto fault;
146934c2f668SLeonid Yegoshin 			regs->regs[reg] = value;
147034c2f668SLeonid Yegoshin 			addr += 8;
147134c2f668SLeonid Yegoshin 			LoadDW(addr, value, res);
147234c2f668SLeonid Yegoshin 			if (res)
147334c2f668SLeonid Yegoshin 				goto fault;
147434c2f668SLeonid Yegoshin 			regs->regs[reg + 1] = value;
147534c2f668SLeonid Yegoshin 			goto success;
147634c2f668SLeonid Yegoshin #endif /* CONFIG_64BIT */
147734c2f668SLeonid Yegoshin 
147834c2f668SLeonid Yegoshin 			goto sigill;
147934c2f668SLeonid Yegoshin 
148034c2f668SLeonid Yegoshin 		case mm_sdp_func:
148134c2f668SLeonid Yegoshin #ifdef CONFIG_64BIT
148234c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
148334c2f668SLeonid Yegoshin 			if (reg == 31)
148434c2f668SLeonid Yegoshin 				goto sigbus;
148534c2f668SLeonid Yegoshin 
148634c2f668SLeonid Yegoshin 			if (!access_ok(VERIFY_WRITE, addr, 16))
148734c2f668SLeonid Yegoshin 				goto sigbus;
148834c2f668SLeonid Yegoshin 
148934c2f668SLeonid Yegoshin 			value = regs->regs[reg];
149034c2f668SLeonid Yegoshin 			StoreDW(addr, value, res);
149134c2f668SLeonid Yegoshin 			if (res)
149234c2f668SLeonid Yegoshin 				goto fault;
149334c2f668SLeonid Yegoshin 			addr += 8;
149434c2f668SLeonid Yegoshin 			value = regs->regs[reg + 1];
149534c2f668SLeonid Yegoshin 			StoreDW(addr, value, res);
149634c2f668SLeonid Yegoshin 			if (res)
149734c2f668SLeonid Yegoshin 				goto fault;
149834c2f668SLeonid Yegoshin 			goto success;
149934c2f668SLeonid Yegoshin #endif /* CONFIG_64BIT */
150034c2f668SLeonid Yegoshin 
150134c2f668SLeonid Yegoshin 			goto sigill;
150234c2f668SLeonid Yegoshin 
150334c2f668SLeonid Yegoshin 		case mm_lwm32_func:
150434c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
150534c2f668SLeonid Yegoshin 			rvar = reg & 0xf;
150634c2f668SLeonid Yegoshin 			if ((rvar > 9) || !reg)
150734c2f668SLeonid Yegoshin 				goto sigill;
150834c2f668SLeonid Yegoshin 			if (reg & 0x10) {
150934c2f668SLeonid Yegoshin 				if (!access_ok
151034c2f668SLeonid Yegoshin 				    (VERIFY_READ, addr, 4 * (rvar + 1)))
151134c2f668SLeonid Yegoshin 					goto sigbus;
151234c2f668SLeonid Yegoshin 			} else {
151334c2f668SLeonid Yegoshin 				if (!access_ok(VERIFY_READ, addr, 4 * rvar))
151434c2f668SLeonid Yegoshin 					goto sigbus;
151534c2f668SLeonid Yegoshin 			}
151634c2f668SLeonid Yegoshin 			if (rvar == 9)
151734c2f668SLeonid Yegoshin 				rvar = 8;
151834c2f668SLeonid Yegoshin 			for (i = 16; rvar; rvar--, i++) {
151934c2f668SLeonid Yegoshin 				LoadW(addr, value, res);
152034c2f668SLeonid Yegoshin 				if (res)
152134c2f668SLeonid Yegoshin 					goto fault;
152234c2f668SLeonid Yegoshin 				addr += 4;
152334c2f668SLeonid Yegoshin 				regs->regs[i] = value;
152434c2f668SLeonid Yegoshin 			}
152534c2f668SLeonid Yegoshin 			if ((reg & 0xf) == 9) {
152634c2f668SLeonid Yegoshin 				LoadW(addr, value, res);
152734c2f668SLeonid Yegoshin 				if (res)
152834c2f668SLeonid Yegoshin 					goto fault;
152934c2f668SLeonid Yegoshin 				addr += 4;
153034c2f668SLeonid Yegoshin 				regs->regs[30] = value;
153134c2f668SLeonid Yegoshin 			}
153234c2f668SLeonid Yegoshin 			if (reg & 0x10) {
153334c2f668SLeonid Yegoshin 				LoadW(addr, value, res);
153434c2f668SLeonid Yegoshin 				if (res)
153534c2f668SLeonid Yegoshin 					goto fault;
153634c2f668SLeonid Yegoshin 				regs->regs[31] = value;
153734c2f668SLeonid Yegoshin 			}
153834c2f668SLeonid Yegoshin 			goto success;
153934c2f668SLeonid Yegoshin 
154034c2f668SLeonid Yegoshin 		case mm_swm32_func:
154134c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
154234c2f668SLeonid Yegoshin 			rvar = reg & 0xf;
154334c2f668SLeonid Yegoshin 			if ((rvar > 9) || !reg)
154434c2f668SLeonid Yegoshin 				goto sigill;
154534c2f668SLeonid Yegoshin 			if (reg & 0x10) {
154634c2f668SLeonid Yegoshin 				if (!access_ok
154734c2f668SLeonid Yegoshin 				    (VERIFY_WRITE, addr, 4 * (rvar + 1)))
154834c2f668SLeonid Yegoshin 					goto sigbus;
154934c2f668SLeonid Yegoshin 			} else {
155034c2f668SLeonid Yegoshin 				if (!access_ok(VERIFY_WRITE, addr, 4 * rvar))
155134c2f668SLeonid Yegoshin 					goto sigbus;
155234c2f668SLeonid Yegoshin 			}
155334c2f668SLeonid Yegoshin 			if (rvar == 9)
155434c2f668SLeonid Yegoshin 				rvar = 8;
155534c2f668SLeonid Yegoshin 			for (i = 16; rvar; rvar--, i++) {
155634c2f668SLeonid Yegoshin 				value = regs->regs[i];
155734c2f668SLeonid Yegoshin 				StoreW(addr, value, res);
155834c2f668SLeonid Yegoshin 				if (res)
155934c2f668SLeonid Yegoshin 					goto fault;
156034c2f668SLeonid Yegoshin 				addr += 4;
156134c2f668SLeonid Yegoshin 			}
156234c2f668SLeonid Yegoshin 			if ((reg & 0xf) == 9) {
156334c2f668SLeonid Yegoshin 				value = regs->regs[30];
156434c2f668SLeonid Yegoshin 				StoreW(addr, value, res);
156534c2f668SLeonid Yegoshin 				if (res)
156634c2f668SLeonid Yegoshin 					goto fault;
156734c2f668SLeonid Yegoshin 				addr += 4;
156834c2f668SLeonid Yegoshin 			}
156934c2f668SLeonid Yegoshin 			if (reg & 0x10) {
157034c2f668SLeonid Yegoshin 				value = regs->regs[31];
157134c2f668SLeonid Yegoshin 				StoreW(addr, value, res);
157234c2f668SLeonid Yegoshin 				if (res)
157334c2f668SLeonid Yegoshin 					goto fault;
157434c2f668SLeonid Yegoshin 			}
157534c2f668SLeonid Yegoshin 			goto success;
157634c2f668SLeonid Yegoshin 
157734c2f668SLeonid Yegoshin 		case mm_ldm_func:
157834c2f668SLeonid Yegoshin #ifdef CONFIG_64BIT
157934c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
158034c2f668SLeonid Yegoshin 			rvar = reg & 0xf;
158134c2f668SLeonid Yegoshin 			if ((rvar > 9) || !reg)
158234c2f668SLeonid Yegoshin 				goto sigill;
158334c2f668SLeonid Yegoshin 			if (reg & 0x10) {
158434c2f668SLeonid Yegoshin 				if (!access_ok
158534c2f668SLeonid Yegoshin 				    (VERIFY_READ, addr, 8 * (rvar + 1)))
158634c2f668SLeonid Yegoshin 					goto sigbus;
158734c2f668SLeonid Yegoshin 			} else {
158834c2f668SLeonid Yegoshin 				if (!access_ok(VERIFY_READ, addr, 8 * rvar))
158934c2f668SLeonid Yegoshin 					goto sigbus;
159034c2f668SLeonid Yegoshin 			}
159134c2f668SLeonid Yegoshin 			if (rvar == 9)
159234c2f668SLeonid Yegoshin 				rvar = 8;
159334c2f668SLeonid Yegoshin 
159434c2f668SLeonid Yegoshin 			for (i = 16; rvar; rvar--, i++) {
159534c2f668SLeonid Yegoshin 				LoadDW(addr, value, res);
159634c2f668SLeonid Yegoshin 				if (res)
159734c2f668SLeonid Yegoshin 					goto fault;
159834c2f668SLeonid Yegoshin 				addr += 4;
159934c2f668SLeonid Yegoshin 				regs->regs[i] = value;
160034c2f668SLeonid Yegoshin 			}
160134c2f668SLeonid Yegoshin 			if ((reg & 0xf) == 9) {
160234c2f668SLeonid Yegoshin 				LoadDW(addr, value, res);
160334c2f668SLeonid Yegoshin 				if (res)
160434c2f668SLeonid Yegoshin 					goto fault;
160534c2f668SLeonid Yegoshin 				addr += 8;
160634c2f668SLeonid Yegoshin 				regs->regs[30] = value;
160734c2f668SLeonid Yegoshin 			}
160834c2f668SLeonid Yegoshin 			if (reg & 0x10) {
160934c2f668SLeonid Yegoshin 				LoadDW(addr, value, res);
161034c2f668SLeonid Yegoshin 				if (res)
161134c2f668SLeonid Yegoshin 					goto fault;
161234c2f668SLeonid Yegoshin 				regs->regs[31] = value;
161334c2f668SLeonid Yegoshin 			}
161434c2f668SLeonid Yegoshin 			goto success;
161534c2f668SLeonid Yegoshin #endif /* CONFIG_64BIT */
161634c2f668SLeonid Yegoshin 
161734c2f668SLeonid Yegoshin 			goto sigill;
161834c2f668SLeonid Yegoshin 
161934c2f668SLeonid Yegoshin 		case mm_sdm_func:
162034c2f668SLeonid Yegoshin #ifdef CONFIG_64BIT
162134c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
162234c2f668SLeonid Yegoshin 			rvar = reg & 0xf;
162334c2f668SLeonid Yegoshin 			if ((rvar > 9) || !reg)
162434c2f668SLeonid Yegoshin 				goto sigill;
162534c2f668SLeonid Yegoshin 			if (reg & 0x10) {
162634c2f668SLeonid Yegoshin 				if (!access_ok
162734c2f668SLeonid Yegoshin 				    (VERIFY_WRITE, addr, 8 * (rvar + 1)))
162834c2f668SLeonid Yegoshin 					goto sigbus;
162934c2f668SLeonid Yegoshin 			} else {
163034c2f668SLeonid Yegoshin 				if (!access_ok(VERIFY_WRITE, addr, 8 * rvar))
163134c2f668SLeonid Yegoshin 					goto sigbus;
163234c2f668SLeonid Yegoshin 			}
163334c2f668SLeonid Yegoshin 			if (rvar == 9)
163434c2f668SLeonid Yegoshin 				rvar = 8;
163534c2f668SLeonid Yegoshin 
163634c2f668SLeonid Yegoshin 			for (i = 16; rvar; rvar--, i++) {
163734c2f668SLeonid Yegoshin 				value = regs->regs[i];
163834c2f668SLeonid Yegoshin 				StoreDW(addr, value, res);
163934c2f668SLeonid Yegoshin 				if (res)
164034c2f668SLeonid Yegoshin 					goto fault;
164134c2f668SLeonid Yegoshin 				addr += 8;
164234c2f668SLeonid Yegoshin 			}
164334c2f668SLeonid Yegoshin 			if ((reg & 0xf) == 9) {
164434c2f668SLeonid Yegoshin 				value = regs->regs[30];
164534c2f668SLeonid Yegoshin 				StoreDW(addr, value, res);
164634c2f668SLeonid Yegoshin 				if (res)
164734c2f668SLeonid Yegoshin 					goto fault;
164834c2f668SLeonid Yegoshin 				addr += 8;
164934c2f668SLeonid Yegoshin 			}
165034c2f668SLeonid Yegoshin 			if (reg & 0x10) {
165134c2f668SLeonid Yegoshin 				value = regs->regs[31];
165234c2f668SLeonid Yegoshin 				StoreDW(addr, value, res);
165334c2f668SLeonid Yegoshin 				if (res)
165434c2f668SLeonid Yegoshin 					goto fault;
165534c2f668SLeonid Yegoshin 			}
165634c2f668SLeonid Yegoshin 			goto success;
165734c2f668SLeonid Yegoshin #endif /* CONFIG_64BIT */
165834c2f668SLeonid Yegoshin 
165934c2f668SLeonid Yegoshin 			goto sigill;
166034c2f668SLeonid Yegoshin 
166134c2f668SLeonid Yegoshin 			/*  LWC2, SWC2, LDC2, SDC2 are not serviced */
166234c2f668SLeonid Yegoshin 		}
166334c2f668SLeonid Yegoshin 
166434c2f668SLeonid Yegoshin 		goto sigbus;
166534c2f668SLeonid Yegoshin 
166634c2f668SLeonid Yegoshin 	case mm_pool32c_op:
166734c2f668SLeonid Yegoshin 		switch (insn.mm_m_format.func) {
166834c2f668SLeonid Yegoshin 		case mm_lwu_func:
166934c2f668SLeonid Yegoshin 			reg = insn.mm_m_format.rd;
167034c2f668SLeonid Yegoshin 			goto loadWU;
167134c2f668SLeonid Yegoshin 		}
167234c2f668SLeonid Yegoshin 
167334c2f668SLeonid Yegoshin 		/*  LL,SC,LLD,SCD are not serviced */
167434c2f668SLeonid Yegoshin 		goto sigbus;
167534c2f668SLeonid Yegoshin 
167634c2f668SLeonid Yegoshin 	case mm_pool32f_op:
167734c2f668SLeonid Yegoshin 		switch (insn.mm_x_format.func) {
167834c2f668SLeonid Yegoshin 		case mm_lwxc1_func:
167934c2f668SLeonid Yegoshin 		case mm_swxc1_func:
168034c2f668SLeonid Yegoshin 		case mm_ldxc1_func:
168134c2f668SLeonid Yegoshin 		case mm_sdxc1_func:
168234c2f668SLeonid Yegoshin 			goto fpu_emul;
168334c2f668SLeonid Yegoshin 		}
168434c2f668SLeonid Yegoshin 
168534c2f668SLeonid Yegoshin 		goto sigbus;
168634c2f668SLeonid Yegoshin 
168734c2f668SLeonid Yegoshin 	case mm_ldc132_op:
168834c2f668SLeonid Yegoshin 	case mm_sdc132_op:
168934c2f668SLeonid Yegoshin 	case mm_lwc132_op:
169034c2f668SLeonid Yegoshin 	case mm_swc132_op:
169134c2f668SLeonid Yegoshin fpu_emul:
169234c2f668SLeonid Yegoshin 		/* roll back jump/branch */
169334c2f668SLeonid Yegoshin 		regs->cp0_epc = origpc;
169434c2f668SLeonid Yegoshin 		regs->regs[31] = orig31;
169534c2f668SLeonid Yegoshin 
169634c2f668SLeonid Yegoshin 		die_if_kernel("Unaligned FP access in kernel code", regs);
169734c2f668SLeonid Yegoshin 		BUG_ON(!used_math());
169834c2f668SLeonid Yegoshin 		BUG_ON(!is_fpu_owner());
169934c2f668SLeonid Yegoshin 
170034c2f668SLeonid Yegoshin 		lose_fpu(1);	/* save the FPU state for the emulator */
170134c2f668SLeonid Yegoshin 		res = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 1,
170234c2f668SLeonid Yegoshin 					       &fault_addr);
170334c2f668SLeonid Yegoshin 		own_fpu(1);	/* restore FPU state */
170434c2f668SLeonid Yegoshin 
170534c2f668SLeonid Yegoshin 		/* If something went wrong, signal */
1706304acb71SMaciej W. Rozycki 		process_fpemu_return(res, fault_addr, 0);
170734c2f668SLeonid Yegoshin 
170834c2f668SLeonid Yegoshin 		if (res == 0)
170934c2f668SLeonid Yegoshin 			goto success;
171034c2f668SLeonid Yegoshin 		return;
171134c2f668SLeonid Yegoshin 
171234c2f668SLeonid Yegoshin 	case mm_lh32_op:
171334c2f668SLeonid Yegoshin 		reg = insn.mm_i_format.rt;
171434c2f668SLeonid Yegoshin 		goto loadHW;
171534c2f668SLeonid Yegoshin 
171634c2f668SLeonid Yegoshin 	case mm_lhu32_op:
171734c2f668SLeonid Yegoshin 		reg = insn.mm_i_format.rt;
171834c2f668SLeonid Yegoshin 		goto loadHWU;
171934c2f668SLeonid Yegoshin 
172034c2f668SLeonid Yegoshin 	case mm_lw32_op:
172134c2f668SLeonid Yegoshin 		reg = insn.mm_i_format.rt;
172234c2f668SLeonid Yegoshin 		goto loadW;
172334c2f668SLeonid Yegoshin 
172434c2f668SLeonid Yegoshin 	case mm_sh32_op:
172534c2f668SLeonid Yegoshin 		reg = insn.mm_i_format.rt;
172634c2f668SLeonid Yegoshin 		goto storeHW;
172734c2f668SLeonid Yegoshin 
172834c2f668SLeonid Yegoshin 	case mm_sw32_op:
172934c2f668SLeonid Yegoshin 		reg = insn.mm_i_format.rt;
173034c2f668SLeonid Yegoshin 		goto storeW;
173134c2f668SLeonid Yegoshin 
173234c2f668SLeonid Yegoshin 	case mm_ld32_op:
173334c2f668SLeonid Yegoshin 		reg = insn.mm_i_format.rt;
173434c2f668SLeonid Yegoshin 		goto loadDW;
173534c2f668SLeonid Yegoshin 
173634c2f668SLeonid Yegoshin 	case mm_sd32_op:
173734c2f668SLeonid Yegoshin 		reg = insn.mm_i_format.rt;
173834c2f668SLeonid Yegoshin 		goto storeDW;
173934c2f668SLeonid Yegoshin 
174034c2f668SLeonid Yegoshin 	case mm_pool16c_op:
174134c2f668SLeonid Yegoshin 		switch (insn.mm16_m_format.func) {
174234c2f668SLeonid Yegoshin 		case mm_lwm16_op:
174334c2f668SLeonid Yegoshin 			reg = insn.mm16_m_format.rlist;
174434c2f668SLeonid Yegoshin 			rvar = reg + 1;
174534c2f668SLeonid Yegoshin 			if (!access_ok(VERIFY_READ, addr, 4 * rvar))
174634c2f668SLeonid Yegoshin 				goto sigbus;
174734c2f668SLeonid Yegoshin 
174834c2f668SLeonid Yegoshin 			for (i = 16; rvar; rvar--, i++) {
174934c2f668SLeonid Yegoshin 				LoadW(addr, value, res);
175034c2f668SLeonid Yegoshin 				if (res)
175134c2f668SLeonid Yegoshin 					goto fault;
175234c2f668SLeonid Yegoshin 				addr += 4;
175334c2f668SLeonid Yegoshin 				regs->regs[i] = value;
175434c2f668SLeonid Yegoshin 			}
175534c2f668SLeonid Yegoshin 			LoadW(addr, value, res);
175634c2f668SLeonid Yegoshin 			if (res)
175734c2f668SLeonid Yegoshin 				goto fault;
175834c2f668SLeonid Yegoshin 			regs->regs[31] = value;
175934c2f668SLeonid Yegoshin 
176034c2f668SLeonid Yegoshin 			goto success;
176134c2f668SLeonid Yegoshin 
176234c2f668SLeonid Yegoshin 		case mm_swm16_op:
176334c2f668SLeonid Yegoshin 			reg = insn.mm16_m_format.rlist;
176434c2f668SLeonid Yegoshin 			rvar = reg + 1;
176534c2f668SLeonid Yegoshin 			if (!access_ok(VERIFY_WRITE, addr, 4 * rvar))
176634c2f668SLeonid Yegoshin 				goto sigbus;
176734c2f668SLeonid Yegoshin 
176834c2f668SLeonid Yegoshin 			for (i = 16; rvar; rvar--, i++) {
176934c2f668SLeonid Yegoshin 				value = regs->regs[i];
177034c2f668SLeonid Yegoshin 				StoreW(addr, value, res);
177134c2f668SLeonid Yegoshin 				if (res)
177234c2f668SLeonid Yegoshin 					goto fault;
177334c2f668SLeonid Yegoshin 				addr += 4;
177434c2f668SLeonid Yegoshin 			}
177534c2f668SLeonid Yegoshin 			value = regs->regs[31];
177634c2f668SLeonid Yegoshin 			StoreW(addr, value, res);
177734c2f668SLeonid Yegoshin 			if (res)
177834c2f668SLeonid Yegoshin 				goto fault;
177934c2f668SLeonid Yegoshin 
178034c2f668SLeonid Yegoshin 			goto success;
178134c2f668SLeonid Yegoshin 
178234c2f668SLeonid Yegoshin 		}
178334c2f668SLeonid Yegoshin 
178434c2f668SLeonid Yegoshin 		goto sigbus;
178534c2f668SLeonid Yegoshin 
178634c2f668SLeonid Yegoshin 	case mm_lhu16_op:
178734c2f668SLeonid Yegoshin 		reg = reg16to32[insn.mm16_rb_format.rt];
178834c2f668SLeonid Yegoshin 		goto loadHWU;
178934c2f668SLeonid Yegoshin 
179034c2f668SLeonid Yegoshin 	case mm_lw16_op:
179134c2f668SLeonid Yegoshin 		reg = reg16to32[insn.mm16_rb_format.rt];
179234c2f668SLeonid Yegoshin 		goto loadW;
179334c2f668SLeonid Yegoshin 
179434c2f668SLeonid Yegoshin 	case mm_sh16_op:
179534c2f668SLeonid Yegoshin 		reg = reg16to32st[insn.mm16_rb_format.rt];
179634c2f668SLeonid Yegoshin 		goto storeHW;
179734c2f668SLeonid Yegoshin 
179834c2f668SLeonid Yegoshin 	case mm_sw16_op:
179934c2f668SLeonid Yegoshin 		reg = reg16to32st[insn.mm16_rb_format.rt];
180034c2f668SLeonid Yegoshin 		goto storeW;
180134c2f668SLeonid Yegoshin 
180234c2f668SLeonid Yegoshin 	case mm_lwsp16_op:
180334c2f668SLeonid Yegoshin 		reg = insn.mm16_r5_format.rt;
180434c2f668SLeonid Yegoshin 		goto loadW;
180534c2f668SLeonid Yegoshin 
180634c2f668SLeonid Yegoshin 	case mm_swsp16_op:
180734c2f668SLeonid Yegoshin 		reg = insn.mm16_r5_format.rt;
180834c2f668SLeonid Yegoshin 		goto storeW;
180934c2f668SLeonid Yegoshin 
181034c2f668SLeonid Yegoshin 	case mm_lwgp16_op:
181134c2f668SLeonid Yegoshin 		reg = reg16to32[insn.mm16_r3_format.rt];
181234c2f668SLeonid Yegoshin 		goto loadW;
181334c2f668SLeonid Yegoshin 
181434c2f668SLeonid Yegoshin 	default:
181534c2f668SLeonid Yegoshin 		goto sigill;
181634c2f668SLeonid Yegoshin 	}
181734c2f668SLeonid Yegoshin 
181834c2f668SLeonid Yegoshin loadHW:
181934c2f668SLeonid Yegoshin 	if (!access_ok(VERIFY_READ, addr, 2))
182034c2f668SLeonid Yegoshin 		goto sigbus;
182134c2f668SLeonid Yegoshin 
182234c2f668SLeonid Yegoshin 	LoadHW(addr, value, res);
182334c2f668SLeonid Yegoshin 	if (res)
182434c2f668SLeonid Yegoshin 		goto fault;
182534c2f668SLeonid Yegoshin 	regs->regs[reg] = value;
182634c2f668SLeonid Yegoshin 	goto success;
182734c2f668SLeonid Yegoshin 
182834c2f668SLeonid Yegoshin loadHWU:
182934c2f668SLeonid Yegoshin 	if (!access_ok(VERIFY_READ, addr, 2))
183034c2f668SLeonid Yegoshin 		goto sigbus;
183134c2f668SLeonid Yegoshin 
183234c2f668SLeonid Yegoshin 	LoadHWU(addr, value, res);
183334c2f668SLeonid Yegoshin 	if (res)
183434c2f668SLeonid Yegoshin 		goto fault;
183534c2f668SLeonid Yegoshin 	regs->regs[reg] = value;
183634c2f668SLeonid Yegoshin 	goto success;
183734c2f668SLeonid Yegoshin 
183834c2f668SLeonid Yegoshin loadW:
183934c2f668SLeonid Yegoshin 	if (!access_ok(VERIFY_READ, addr, 4))
184034c2f668SLeonid Yegoshin 		goto sigbus;
184134c2f668SLeonid Yegoshin 
184234c2f668SLeonid Yegoshin 	LoadW(addr, value, res);
184334c2f668SLeonid Yegoshin 	if (res)
184434c2f668SLeonid Yegoshin 		goto fault;
184534c2f668SLeonid Yegoshin 	regs->regs[reg] = value;
184634c2f668SLeonid Yegoshin 	goto success;
184734c2f668SLeonid Yegoshin 
184834c2f668SLeonid Yegoshin loadWU:
184934c2f668SLeonid Yegoshin #ifdef CONFIG_64BIT
185034c2f668SLeonid Yegoshin 	/*
185134c2f668SLeonid Yegoshin 	 * A 32-bit kernel might be running on a 64-bit processor.  But
185234c2f668SLeonid Yegoshin 	 * if we're on a 32-bit processor and an i-cache incoherency
185334c2f668SLeonid Yegoshin 	 * or race makes us see a 64-bit instruction here the sdl/sdr
185434c2f668SLeonid Yegoshin 	 * would blow up, so for now we don't handle unaligned 64-bit
185534c2f668SLeonid Yegoshin 	 * instructions on 32-bit kernels.
185634c2f668SLeonid Yegoshin 	 */
185734c2f668SLeonid Yegoshin 	if (!access_ok(VERIFY_READ, addr, 4))
185834c2f668SLeonid Yegoshin 		goto sigbus;
185934c2f668SLeonid Yegoshin 
186034c2f668SLeonid Yegoshin 	LoadWU(addr, value, res);
186134c2f668SLeonid Yegoshin 	if (res)
186234c2f668SLeonid Yegoshin 		goto fault;
186334c2f668SLeonid Yegoshin 	regs->regs[reg] = value;
186434c2f668SLeonid Yegoshin 	goto success;
186534c2f668SLeonid Yegoshin #endif /* CONFIG_64BIT */
186634c2f668SLeonid Yegoshin 
186734c2f668SLeonid Yegoshin 	/* Cannot handle 64-bit instructions in 32-bit kernel */
186834c2f668SLeonid Yegoshin 	goto sigill;
186934c2f668SLeonid Yegoshin 
187034c2f668SLeonid Yegoshin loadDW:
187134c2f668SLeonid Yegoshin #ifdef CONFIG_64BIT
187234c2f668SLeonid Yegoshin 	/*
187334c2f668SLeonid Yegoshin 	 * A 32-bit kernel might be running on a 64-bit processor.  But
187434c2f668SLeonid Yegoshin 	 * if we're on a 32-bit processor and an i-cache incoherency
187534c2f668SLeonid Yegoshin 	 * or race makes us see a 64-bit instruction here the sdl/sdr
187634c2f668SLeonid Yegoshin 	 * would blow up, so for now we don't handle unaligned 64-bit
187734c2f668SLeonid Yegoshin 	 * instructions on 32-bit kernels.
187834c2f668SLeonid Yegoshin 	 */
187934c2f668SLeonid Yegoshin 	if (!access_ok(VERIFY_READ, addr, 8))
188034c2f668SLeonid Yegoshin 		goto sigbus;
188134c2f668SLeonid Yegoshin 
188234c2f668SLeonid Yegoshin 	LoadDW(addr, value, res);
188334c2f668SLeonid Yegoshin 	if (res)
188434c2f668SLeonid Yegoshin 		goto fault;
188534c2f668SLeonid Yegoshin 	regs->regs[reg] = value;
188634c2f668SLeonid Yegoshin 	goto success;
188734c2f668SLeonid Yegoshin #endif /* CONFIG_64BIT */
188834c2f668SLeonid Yegoshin 
188934c2f668SLeonid Yegoshin 	/* Cannot handle 64-bit instructions in 32-bit kernel */
189034c2f668SLeonid Yegoshin 	goto sigill;
189134c2f668SLeonid Yegoshin 
189234c2f668SLeonid Yegoshin storeHW:
189334c2f668SLeonid Yegoshin 	if (!access_ok(VERIFY_WRITE, addr, 2))
189434c2f668SLeonid Yegoshin 		goto sigbus;
189534c2f668SLeonid Yegoshin 
189634c2f668SLeonid Yegoshin 	value = regs->regs[reg];
189734c2f668SLeonid Yegoshin 	StoreHW(addr, value, res);
189834c2f668SLeonid Yegoshin 	if (res)
189934c2f668SLeonid Yegoshin 		goto fault;
190034c2f668SLeonid Yegoshin 	goto success;
190134c2f668SLeonid Yegoshin 
190234c2f668SLeonid Yegoshin storeW:
190334c2f668SLeonid Yegoshin 	if (!access_ok(VERIFY_WRITE, addr, 4))
190434c2f668SLeonid Yegoshin 		goto sigbus;
190534c2f668SLeonid Yegoshin 
190634c2f668SLeonid Yegoshin 	value = regs->regs[reg];
190734c2f668SLeonid Yegoshin 	StoreW(addr, value, res);
190834c2f668SLeonid Yegoshin 	if (res)
190934c2f668SLeonid Yegoshin 		goto fault;
191034c2f668SLeonid Yegoshin 	goto success;
191134c2f668SLeonid Yegoshin 
191234c2f668SLeonid Yegoshin storeDW:
191334c2f668SLeonid Yegoshin #ifdef CONFIG_64BIT
191434c2f668SLeonid Yegoshin 	/*
191534c2f668SLeonid Yegoshin 	 * A 32-bit kernel might be running on a 64-bit processor.  But
191634c2f668SLeonid Yegoshin 	 * if we're on a 32-bit processor and an i-cache incoherency
191734c2f668SLeonid Yegoshin 	 * or race makes us see a 64-bit instruction here the sdl/sdr
191834c2f668SLeonid Yegoshin 	 * would blow up, so for now we don't handle unaligned 64-bit
191934c2f668SLeonid Yegoshin 	 * instructions on 32-bit kernels.
192034c2f668SLeonid Yegoshin 	 */
192134c2f668SLeonid Yegoshin 	if (!access_ok(VERIFY_WRITE, addr, 8))
192234c2f668SLeonid Yegoshin 		goto sigbus;
192334c2f668SLeonid Yegoshin 
192434c2f668SLeonid Yegoshin 	value = regs->regs[reg];
192534c2f668SLeonid Yegoshin 	StoreDW(addr, value, res);
192634c2f668SLeonid Yegoshin 	if (res)
192734c2f668SLeonid Yegoshin 		goto fault;
192834c2f668SLeonid Yegoshin 	goto success;
192934c2f668SLeonid Yegoshin #endif /* CONFIG_64BIT */
193034c2f668SLeonid Yegoshin 
193134c2f668SLeonid Yegoshin 	/* Cannot handle 64-bit instructions in 32-bit kernel */
193234c2f668SLeonid Yegoshin 	goto sigill;
193334c2f668SLeonid Yegoshin 
193434c2f668SLeonid Yegoshin success:
193534c2f668SLeonid Yegoshin 	regs->cp0_epc = contpc;	/* advance or branch */
193634c2f668SLeonid Yegoshin 
193734c2f668SLeonid Yegoshin #ifdef CONFIG_DEBUG_FS
193834c2f668SLeonid Yegoshin 	unaligned_instructions++;
193934c2f668SLeonid Yegoshin #endif
194034c2f668SLeonid Yegoshin 	return;
194134c2f668SLeonid Yegoshin 
194234c2f668SLeonid Yegoshin fault:
194334c2f668SLeonid Yegoshin 	/* roll back jump/branch */
194434c2f668SLeonid Yegoshin 	regs->cp0_epc = origpc;
194534c2f668SLeonid Yegoshin 	regs->regs[31] = orig31;
194634c2f668SLeonid Yegoshin 	/* Did we have an exception handler installed? */
194734c2f668SLeonid Yegoshin 	if (fixup_exception(regs))
194834c2f668SLeonid Yegoshin 		return;
194934c2f668SLeonid Yegoshin 
195034c2f668SLeonid Yegoshin 	die_if_kernel("Unhandled kernel unaligned access", regs);
195134c2f668SLeonid Yegoshin 	force_sig(SIGSEGV, current);
195234c2f668SLeonid Yegoshin 
195334c2f668SLeonid Yegoshin 	return;
195434c2f668SLeonid Yegoshin 
195534c2f668SLeonid Yegoshin sigbus:
195634c2f668SLeonid Yegoshin 	die_if_kernel("Unhandled kernel unaligned access", regs);
195734c2f668SLeonid Yegoshin 	force_sig(SIGBUS, current);
195834c2f668SLeonid Yegoshin 
195934c2f668SLeonid Yegoshin 	return;
196034c2f668SLeonid Yegoshin 
196134c2f668SLeonid Yegoshin sigill:
196234c2f668SLeonid Yegoshin 	die_if_kernel
196334c2f668SLeonid Yegoshin 	    ("Unhandled kernel unaligned access or invalid instruction", regs);
1964a6d5ff04SDavid Daney 	force_sig(SIGILL, current);
19651da177e4SLinus Torvalds }
19661da177e4SLinus Torvalds 
1967451b001bSSteven J. Hill static void emulate_load_store_MIPS16e(struct pt_regs *regs, void __user * addr)
1968451b001bSSteven J. Hill {
1969451b001bSSteven J. Hill 	unsigned long value;
1970451b001bSSteven J. Hill 	unsigned int res;
1971451b001bSSteven J. Hill 	int reg;
1972451b001bSSteven J. Hill 	unsigned long orig31;
1973451b001bSSteven J. Hill 	u16 __user *pc16;
1974451b001bSSteven J. Hill 	unsigned long origpc;
1975451b001bSSteven J. Hill 	union mips16e_instruction mips16inst, oldinst;
1976451b001bSSteven J. Hill 
1977451b001bSSteven J. Hill 	origpc = regs->cp0_epc;
1978451b001bSSteven J. Hill 	orig31 = regs->regs[31];
1979451b001bSSteven J. Hill 	pc16 = (unsigned short __user *)msk_isa16_mode(origpc);
1980451b001bSSteven J. Hill 	/*
1981451b001bSSteven J. Hill 	 * This load never faults.
1982451b001bSSteven J. Hill 	 */
1983451b001bSSteven J. Hill 	__get_user(mips16inst.full, pc16);
1984451b001bSSteven J. Hill 	oldinst = mips16inst;
1985451b001bSSteven J. Hill 
1986451b001bSSteven J. Hill 	/* skip EXTEND instruction */
1987451b001bSSteven J. Hill 	if (mips16inst.ri.opcode == MIPS16e_extend_op) {
1988451b001bSSteven J. Hill 		pc16++;
1989451b001bSSteven J. Hill 		__get_user(mips16inst.full, pc16);
1990451b001bSSteven J. Hill 	} else if (delay_slot(regs)) {
1991451b001bSSteven J. Hill 		/*  skip jump instructions */
1992451b001bSSteven J. Hill 		/*  JAL/JALX are 32 bits but have OPCODE in first short int */
1993451b001bSSteven J. Hill 		if (mips16inst.ri.opcode == MIPS16e_jal_op)
1994451b001bSSteven J. Hill 			pc16++;
1995451b001bSSteven J. Hill 		pc16++;
1996451b001bSSteven J. Hill 		if (get_user(mips16inst.full, pc16))
1997451b001bSSteven J. Hill 			goto sigbus;
1998451b001bSSteven J. Hill 	}
1999451b001bSSteven J. Hill 
2000451b001bSSteven J. Hill 	switch (mips16inst.ri.opcode) {
2001451b001bSSteven J. Hill 	case MIPS16e_i64_op:	/* I64 or RI64 instruction */
2002451b001bSSteven J. Hill 		switch (mips16inst.i64.func) {	/* I64/RI64 func field check */
2003451b001bSSteven J. Hill 		case MIPS16e_ldpc_func:
2004451b001bSSteven J. Hill 		case MIPS16e_ldsp_func:
2005451b001bSSteven J. Hill 			reg = reg16to32[mips16inst.ri64.ry];
2006451b001bSSteven J. Hill 			goto loadDW;
2007451b001bSSteven J. Hill 
2008451b001bSSteven J. Hill 		case MIPS16e_sdsp_func:
2009451b001bSSteven J. Hill 			reg = reg16to32[mips16inst.ri64.ry];
2010451b001bSSteven J. Hill 			goto writeDW;
2011451b001bSSteven J. Hill 
2012451b001bSSteven J. Hill 		case MIPS16e_sdrasp_func:
2013451b001bSSteven J. Hill 			reg = 29;	/* GPRSP */
2014451b001bSSteven J. Hill 			goto writeDW;
2015451b001bSSteven J. Hill 		}
2016451b001bSSteven J. Hill 
2017451b001bSSteven J. Hill 		goto sigbus;
2018451b001bSSteven J. Hill 
2019451b001bSSteven J. Hill 	case MIPS16e_swsp_op:
2020451b001bSSteven J. Hill 	case MIPS16e_lwpc_op:
2021451b001bSSteven J. Hill 	case MIPS16e_lwsp_op:
2022451b001bSSteven J. Hill 		reg = reg16to32[mips16inst.ri.rx];
2023451b001bSSteven J. Hill 		break;
2024451b001bSSteven J. Hill 
2025451b001bSSteven J. Hill 	case MIPS16e_i8_op:
2026451b001bSSteven J. Hill 		if (mips16inst.i8.func != MIPS16e_swrasp_func)
2027451b001bSSteven J. Hill 			goto sigbus;
2028451b001bSSteven J. Hill 		reg = 29;	/* GPRSP */
2029451b001bSSteven J. Hill 		break;
2030451b001bSSteven J. Hill 
2031451b001bSSteven J. Hill 	default:
2032451b001bSSteven J. Hill 		reg = reg16to32[mips16inst.rri.ry];
2033451b001bSSteven J. Hill 		break;
2034451b001bSSteven J. Hill 	}
2035451b001bSSteven J. Hill 
2036451b001bSSteven J. Hill 	switch (mips16inst.ri.opcode) {
2037451b001bSSteven J. Hill 
2038451b001bSSteven J. Hill 	case MIPS16e_lb_op:
2039451b001bSSteven J. Hill 	case MIPS16e_lbu_op:
2040451b001bSSteven J. Hill 	case MIPS16e_sb_op:
2041451b001bSSteven J. Hill 		goto sigbus;
2042451b001bSSteven J. Hill 
2043451b001bSSteven J. Hill 	case MIPS16e_lh_op:
2044451b001bSSteven J. Hill 		if (!access_ok(VERIFY_READ, addr, 2))
2045451b001bSSteven J. Hill 			goto sigbus;
2046451b001bSSteven J. Hill 
2047451b001bSSteven J. Hill 		LoadHW(addr, value, res);
2048451b001bSSteven J. Hill 		if (res)
2049451b001bSSteven J. Hill 			goto fault;
2050451b001bSSteven J. Hill 		MIPS16e_compute_return_epc(regs, &oldinst);
2051451b001bSSteven J. Hill 		regs->regs[reg] = value;
2052451b001bSSteven J. Hill 		break;
2053451b001bSSteven J. Hill 
2054451b001bSSteven J. Hill 	case MIPS16e_lhu_op:
2055451b001bSSteven J. Hill 		if (!access_ok(VERIFY_READ, addr, 2))
2056451b001bSSteven J. Hill 			goto sigbus;
2057451b001bSSteven J. Hill 
2058451b001bSSteven J. Hill 		LoadHWU(addr, value, res);
2059451b001bSSteven J. Hill 		if (res)
2060451b001bSSteven J. Hill 			goto fault;
2061451b001bSSteven J. Hill 		MIPS16e_compute_return_epc(regs, &oldinst);
2062451b001bSSteven J. Hill 		regs->regs[reg] = value;
2063451b001bSSteven J. Hill 		break;
2064451b001bSSteven J. Hill 
2065451b001bSSteven J. Hill 	case MIPS16e_lw_op:
2066451b001bSSteven J. Hill 	case MIPS16e_lwpc_op:
2067451b001bSSteven J. Hill 	case MIPS16e_lwsp_op:
2068451b001bSSteven J. Hill 		if (!access_ok(VERIFY_READ, addr, 4))
2069451b001bSSteven J. Hill 			goto sigbus;
2070451b001bSSteven J. Hill 
2071451b001bSSteven J. Hill 		LoadW(addr, value, res);
2072451b001bSSteven J. Hill 		if (res)
2073451b001bSSteven J. Hill 			goto fault;
2074451b001bSSteven J. Hill 		MIPS16e_compute_return_epc(regs, &oldinst);
2075451b001bSSteven J. Hill 		regs->regs[reg] = value;
2076451b001bSSteven J. Hill 		break;
2077451b001bSSteven J. Hill 
2078451b001bSSteven J. Hill 	case MIPS16e_lwu_op:
2079451b001bSSteven J. Hill #ifdef CONFIG_64BIT
2080451b001bSSteven J. Hill 		/*
2081451b001bSSteven J. Hill 		 * A 32-bit kernel might be running on a 64-bit processor.  But
2082451b001bSSteven J. Hill 		 * if we're on a 32-bit processor and an i-cache incoherency
2083451b001bSSteven J. Hill 		 * or race makes us see a 64-bit instruction here the sdl/sdr
2084451b001bSSteven J. Hill 		 * would blow up, so for now we don't handle unaligned 64-bit
2085451b001bSSteven J. Hill 		 * instructions on 32-bit kernels.
2086451b001bSSteven J. Hill 		 */
2087451b001bSSteven J. Hill 		if (!access_ok(VERIFY_READ, addr, 4))
2088451b001bSSteven J. Hill 			goto sigbus;
2089451b001bSSteven J. Hill 
2090451b001bSSteven J. Hill 		LoadWU(addr, value, res);
2091451b001bSSteven J. Hill 		if (res)
2092451b001bSSteven J. Hill 			goto fault;
2093451b001bSSteven J. Hill 		MIPS16e_compute_return_epc(regs, &oldinst);
2094451b001bSSteven J. Hill 		regs->regs[reg] = value;
2095451b001bSSteven J. Hill 		break;
2096451b001bSSteven J. Hill #endif /* CONFIG_64BIT */
2097451b001bSSteven J. Hill 
2098451b001bSSteven J. Hill 		/* Cannot handle 64-bit instructions in 32-bit kernel */
2099451b001bSSteven J. Hill 		goto sigill;
2100451b001bSSteven J. Hill 
2101451b001bSSteven J. Hill 	case MIPS16e_ld_op:
2102451b001bSSteven J. Hill loadDW:
2103451b001bSSteven J. Hill #ifdef CONFIG_64BIT
2104451b001bSSteven J. Hill 		/*
2105451b001bSSteven J. Hill 		 * A 32-bit kernel might be running on a 64-bit processor.  But
2106451b001bSSteven J. Hill 		 * if we're on a 32-bit processor and an i-cache incoherency
2107451b001bSSteven J. Hill 		 * or race makes us see a 64-bit instruction here the sdl/sdr
2108451b001bSSteven J. Hill 		 * would blow up, so for now we don't handle unaligned 64-bit
2109451b001bSSteven J. Hill 		 * instructions on 32-bit kernels.
2110451b001bSSteven J. Hill 		 */
2111451b001bSSteven J. Hill 		if (!access_ok(VERIFY_READ, addr, 8))
2112451b001bSSteven J. Hill 			goto sigbus;
2113451b001bSSteven J. Hill 
2114451b001bSSteven J. Hill 		LoadDW(addr, value, res);
2115451b001bSSteven J. Hill 		if (res)
2116451b001bSSteven J. Hill 			goto fault;
2117451b001bSSteven J. Hill 		MIPS16e_compute_return_epc(regs, &oldinst);
2118451b001bSSteven J. Hill 		regs->regs[reg] = value;
2119451b001bSSteven J. Hill 		break;
2120451b001bSSteven J. Hill #endif /* CONFIG_64BIT */
2121451b001bSSteven J. Hill 
2122451b001bSSteven J. Hill 		/* Cannot handle 64-bit instructions in 32-bit kernel */
2123451b001bSSteven J. Hill 		goto sigill;
2124451b001bSSteven J. Hill 
2125451b001bSSteven J. Hill 	case MIPS16e_sh_op:
2126451b001bSSteven J. Hill 		if (!access_ok(VERIFY_WRITE, addr, 2))
2127451b001bSSteven J. Hill 			goto sigbus;
2128451b001bSSteven J. Hill 
2129451b001bSSteven J. Hill 		MIPS16e_compute_return_epc(regs, &oldinst);
2130451b001bSSteven J. Hill 		value = regs->regs[reg];
2131451b001bSSteven J. Hill 		StoreHW(addr, value, res);
2132451b001bSSteven J. Hill 		if (res)
2133451b001bSSteven J. Hill 			goto fault;
2134451b001bSSteven J. Hill 		break;
2135451b001bSSteven J. Hill 
2136451b001bSSteven J. Hill 	case MIPS16e_sw_op:
2137451b001bSSteven J. Hill 	case MIPS16e_swsp_op:
2138451b001bSSteven J. Hill 	case MIPS16e_i8_op:	/* actually - MIPS16e_swrasp_func */
2139451b001bSSteven J. Hill 		if (!access_ok(VERIFY_WRITE, addr, 4))
2140451b001bSSteven J. Hill 			goto sigbus;
2141451b001bSSteven J. Hill 
2142451b001bSSteven J. Hill 		MIPS16e_compute_return_epc(regs, &oldinst);
2143451b001bSSteven J. Hill 		value = regs->regs[reg];
2144451b001bSSteven J. Hill 		StoreW(addr, value, res);
2145451b001bSSteven J. Hill 		if (res)
2146451b001bSSteven J. Hill 			goto fault;
2147451b001bSSteven J. Hill 		break;
2148451b001bSSteven J. Hill 
2149451b001bSSteven J. Hill 	case MIPS16e_sd_op:
2150451b001bSSteven J. Hill writeDW:
2151451b001bSSteven J. Hill #ifdef CONFIG_64BIT
2152451b001bSSteven J. Hill 		/*
2153451b001bSSteven J. Hill 		 * A 32-bit kernel might be running on a 64-bit processor.  But
2154451b001bSSteven J. Hill 		 * if we're on a 32-bit processor and an i-cache incoherency
2155451b001bSSteven J. Hill 		 * or race makes us see a 64-bit instruction here the sdl/sdr
2156451b001bSSteven J. Hill 		 * would blow up, so for now we don't handle unaligned 64-bit
2157451b001bSSteven J. Hill 		 * instructions on 32-bit kernels.
2158451b001bSSteven J. Hill 		 */
2159451b001bSSteven J. Hill 		if (!access_ok(VERIFY_WRITE, addr, 8))
2160451b001bSSteven J. Hill 			goto sigbus;
2161451b001bSSteven J. Hill 
2162451b001bSSteven J. Hill 		MIPS16e_compute_return_epc(regs, &oldinst);
2163451b001bSSteven J. Hill 		value = regs->regs[reg];
2164451b001bSSteven J. Hill 		StoreDW(addr, value, res);
2165451b001bSSteven J. Hill 		if (res)
2166451b001bSSteven J. Hill 			goto fault;
2167451b001bSSteven J. Hill 		break;
2168451b001bSSteven J. Hill #endif /* CONFIG_64BIT */
2169451b001bSSteven J. Hill 
2170451b001bSSteven J. Hill 		/* Cannot handle 64-bit instructions in 32-bit kernel */
2171451b001bSSteven J. Hill 		goto sigill;
2172451b001bSSteven J. Hill 
2173451b001bSSteven J. Hill 	default:
2174451b001bSSteven J. Hill 		/*
2175451b001bSSteven J. Hill 		 * Pheeee...  We encountered an yet unknown instruction or
2176451b001bSSteven J. Hill 		 * cache coherence problem.  Die sucker, die ...
2177451b001bSSteven J. Hill 		 */
2178451b001bSSteven J. Hill 		goto sigill;
2179451b001bSSteven J. Hill 	}
2180451b001bSSteven J. Hill 
2181451b001bSSteven J. Hill #ifdef CONFIG_DEBUG_FS
2182451b001bSSteven J. Hill 	unaligned_instructions++;
2183451b001bSSteven J. Hill #endif
2184451b001bSSteven J. Hill 
2185451b001bSSteven J. Hill 	return;
2186451b001bSSteven J. Hill 
2187451b001bSSteven J. Hill fault:
2188451b001bSSteven J. Hill 	/* roll back jump/branch */
2189451b001bSSteven J. Hill 	regs->cp0_epc = origpc;
2190451b001bSSteven J. Hill 	regs->regs[31] = orig31;
2191451b001bSSteven J. Hill 	/* Did we have an exception handler installed? */
2192451b001bSSteven J. Hill 	if (fixup_exception(regs))
2193451b001bSSteven J. Hill 		return;
2194451b001bSSteven J. Hill 
2195451b001bSSteven J. Hill 	die_if_kernel("Unhandled kernel unaligned access", regs);
2196451b001bSSteven J. Hill 	force_sig(SIGSEGV, current);
2197451b001bSSteven J. Hill 
2198451b001bSSteven J. Hill 	return;
2199451b001bSSteven J. Hill 
2200451b001bSSteven J. Hill sigbus:
2201451b001bSSteven J. Hill 	die_if_kernel("Unhandled kernel unaligned access", regs);
2202451b001bSSteven J. Hill 	force_sig(SIGBUS, current);
2203451b001bSSteven J. Hill 
2204451b001bSSteven J. Hill 	return;
2205451b001bSSteven J. Hill 
2206451b001bSSteven J. Hill sigill:
2207451b001bSSteven J. Hill 	die_if_kernel
2208451b001bSSteven J. Hill 	    ("Unhandled kernel unaligned access or invalid instruction", regs);
2209451b001bSSteven J. Hill 	force_sig(SIGILL, current);
2210451b001bSSteven J. Hill }
2211fc192e50STony Wu 
22121da177e4SLinus Torvalds asmlinkage void do_ade(struct pt_regs *regs)
22131da177e4SLinus Torvalds {
2214c3fc5cd5SRalf Baechle 	enum ctx_state prev_state;
2215fe00f943SRalf Baechle 	unsigned int __user *pc;
22161da177e4SLinus Torvalds 	mm_segment_t seg;
22171da177e4SLinus Torvalds 
2218c3fc5cd5SRalf Baechle 	prev_state = exception_enter();
22197f788d2dSDeng-Cheng Zhu 	perf_sw_event(PERF_COUNT_SW_ALIGNMENT_FAULTS,
2220a8b0ca17SPeter Zijlstra 			1, regs, regs->cp0_badvaddr);
22211da177e4SLinus Torvalds 	/*
22221da177e4SLinus Torvalds 	 * Did we catch a fault trying to load an instruction?
22231da177e4SLinus Torvalds 	 */
222434c2f668SLeonid Yegoshin 	if (regs->cp0_badvaddr == regs->cp0_epc)
22251da177e4SLinus Torvalds 		goto sigbus;
22261da177e4SLinus Torvalds 
2227293c5bd1SRalf Baechle 	if (user_mode(regs) && !test_thread_flag(TIF_FIXADE))
22281da177e4SLinus Torvalds 		goto sigbus;
22296312e0eeSAtsushi Nemoto 	if (unaligned_action == UNALIGNED_ACTION_SIGNAL)
22306312e0eeSAtsushi Nemoto 		goto sigbus;
22311da177e4SLinus Torvalds 
22321da177e4SLinus Torvalds 	/*
22331da177e4SLinus Torvalds 	 * Do branch emulation only if we didn't forward the exception.
22341da177e4SLinus Torvalds 	 * This is all so but ugly ...
22351da177e4SLinus Torvalds 	 */
223634c2f668SLeonid Yegoshin 
223734c2f668SLeonid Yegoshin 	/*
223834c2f668SLeonid Yegoshin 	 * Are we running in microMIPS mode?
223934c2f668SLeonid Yegoshin 	 */
224034c2f668SLeonid Yegoshin 	if (get_isa16_mode(regs->cp0_epc)) {
224134c2f668SLeonid Yegoshin 		/*
224234c2f668SLeonid Yegoshin 		 * Did we catch a fault trying to load an instruction in
224334c2f668SLeonid Yegoshin 		 * 16-bit mode?
224434c2f668SLeonid Yegoshin 		 */
224534c2f668SLeonid Yegoshin 		if (regs->cp0_badvaddr == msk_isa16_mode(regs->cp0_epc))
224634c2f668SLeonid Yegoshin 			goto sigbus;
224734c2f668SLeonid Yegoshin 		if (unaligned_action == UNALIGNED_ACTION_SHOW)
224834c2f668SLeonid Yegoshin 			show_registers(regs);
224934c2f668SLeonid Yegoshin 
225034c2f668SLeonid Yegoshin 		if (cpu_has_mmips) {
225134c2f668SLeonid Yegoshin 			seg = get_fs();
225234c2f668SLeonid Yegoshin 			if (!user_mode(regs))
225334c2f668SLeonid Yegoshin 				set_fs(KERNEL_DS);
225434c2f668SLeonid Yegoshin 			emulate_load_store_microMIPS(regs,
225534c2f668SLeonid Yegoshin 				(void __user *)regs->cp0_badvaddr);
225634c2f668SLeonid Yegoshin 			set_fs(seg);
225734c2f668SLeonid Yegoshin 
225834c2f668SLeonid Yegoshin 			return;
225934c2f668SLeonid Yegoshin 		}
226034c2f668SLeonid Yegoshin 
2261451b001bSSteven J. Hill 		if (cpu_has_mips16) {
2262451b001bSSteven J. Hill 			seg = get_fs();
2263451b001bSSteven J. Hill 			if (!user_mode(regs))
2264451b001bSSteven J. Hill 				set_fs(KERNEL_DS);
2265451b001bSSteven J. Hill 			emulate_load_store_MIPS16e(regs,
2266451b001bSSteven J. Hill 				(void __user *)regs->cp0_badvaddr);
2267451b001bSSteven J. Hill 			set_fs(seg);
2268451b001bSSteven J. Hill 
2269451b001bSSteven J. Hill 			return;
2270451b001bSSteven J. Hill 	}
2271451b001bSSteven J. Hill 
227234c2f668SLeonid Yegoshin 		goto sigbus;
227334c2f668SLeonid Yegoshin 	}
227434c2f668SLeonid Yegoshin 
227534c2f668SLeonid Yegoshin 	if (unaligned_action == UNALIGNED_ACTION_SHOW)
227634c2f668SLeonid Yegoshin 		show_registers(regs);
227734c2f668SLeonid Yegoshin 	pc = (unsigned int __user *)exception_epc(regs);
227834c2f668SLeonid Yegoshin 
22791da177e4SLinus Torvalds 	seg = get_fs();
22801da177e4SLinus Torvalds 	if (!user_mode(regs))
22811da177e4SLinus Torvalds 		set_fs(KERNEL_DS);
22827f18f151SRalf Baechle 	emulate_load_store_insn(regs, (void __user *)regs->cp0_badvaddr, pc);
22831da177e4SLinus Torvalds 	set_fs(seg);
22841da177e4SLinus Torvalds 
22851da177e4SLinus Torvalds 	return;
22861da177e4SLinus Torvalds 
22871da177e4SLinus Torvalds sigbus:
22881da177e4SLinus Torvalds 	die_if_kernel("Kernel unaligned instruction access", regs);
22891da177e4SLinus Torvalds 	force_sig(SIGBUS, current);
22901da177e4SLinus Torvalds 
22911da177e4SLinus Torvalds 	/*
22921da177e4SLinus Torvalds 	 * XXX On return from the signal handler we should advance the epc
22931da177e4SLinus Torvalds 	 */
2294c3fc5cd5SRalf Baechle 	exception_exit(prev_state);
22951da177e4SLinus Torvalds }
22966312e0eeSAtsushi Nemoto 
22976312e0eeSAtsushi Nemoto #ifdef CONFIG_DEBUG_FS
22986312e0eeSAtsushi Nemoto extern struct dentry *mips_debugfs_dir;
22996312e0eeSAtsushi Nemoto static int __init debugfs_unaligned(void)
23006312e0eeSAtsushi Nemoto {
23016312e0eeSAtsushi Nemoto 	struct dentry *d;
23026312e0eeSAtsushi Nemoto 
23036312e0eeSAtsushi Nemoto 	if (!mips_debugfs_dir)
23046312e0eeSAtsushi Nemoto 		return -ENODEV;
23056312e0eeSAtsushi Nemoto 	d = debugfs_create_u32("unaligned_instructions", S_IRUGO,
23066312e0eeSAtsushi Nemoto 			       mips_debugfs_dir, &unaligned_instructions);
2307b517531cSZhaolei 	if (!d)
2308b517531cSZhaolei 		return -ENOMEM;
23096312e0eeSAtsushi Nemoto 	d = debugfs_create_u32("unaligned_action", S_IRUGO | S_IWUSR,
23106312e0eeSAtsushi Nemoto 			       mips_debugfs_dir, &unaligned_action);
2311b517531cSZhaolei 	if (!d)
2312b517531cSZhaolei 		return -ENOMEM;
23136312e0eeSAtsushi Nemoto 	return 0;
23146312e0eeSAtsushi Nemoto }
23156312e0eeSAtsushi Nemoto __initcall(debugfs_unaligned);
23166312e0eeSAtsushi Nemoto #endif
2317