]> rtime.felk.cvut.cz Git - zynq/linux.git/blobdiff - arch/mips/kernel/unaligned.c
Merge tag 'v4.0.8' into xlnx_4.0.8-rt6
[zynq/linux.git] / arch / mips / kernel / unaligned.c
index e11906dff8850fc277b14985eafdbbb4d2c3ece9..7659da224fcdd18fe96c87c6b3e7d1f2cc4a241c 100644 (file)
@@ -109,10 +109,11 @@ static u32 unaligned_action;
 extern void show_registers(struct pt_regs *regs);
 
 #ifdef __BIG_ENDIAN
-#define     LoadHW(addr, value, res)  \
+#define     _LoadHW(addr, value, res, type)  \
+do {                                                        \
                __asm__ __volatile__ (".set\tnoat\n"        \
-                       "1:\t"user_lb("%0", "0(%2)")"\n"    \
-                       "2:\t"user_lbu("$1", "1(%2)")"\n\t" \
+                       "1:\t"type##_lb("%0", "0(%2)")"\n"  \
+                       "2:\t"type##_lbu("$1", "1(%2)")"\n\t"\
                        "sll\t%0, 0x8\n\t"                  \
                        "or\t%0, $1\n\t"                    \
                        "li\t%1, 0\n"                       \
@@ -127,12 +128,15 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     LoadW(addr, value, res)   \
+#ifndef CONFIG_CPU_MIPSR6
+#define     _LoadW(addr, value, res, type)   \
+do {                                                        \
                __asm__ __volatile__ (                      \
-                       "1:\t"user_lwl("%0", "(%2)")"\n"    \
-                       "2:\t"user_lwr("%0", "3(%2)")"\n\t" \
+                       "1:\t"type##_lwl("%0", "(%2)")"\n"   \
+                       "2:\t"type##_lwr("%0", "3(%2)")"\n\t"\
                        "li\t%1, 0\n"                       \
                        "3:\n\t"                            \
                        ".insn\n\t"                         \
@@ -145,13 +149,52 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     LoadHWU(addr, value, res) \
+#else
+/* MIPSR6 has no lwl instruction */
+#define     _LoadW(addr, value, res, type) \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n"                      \
+                       ".set\tnoat\n\t"                    \
+                       "1:"type##_lb("%0", "0(%2)")"\n\t"  \
+                       "2:"type##_lbu("$1", "1(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "3:"type##_lbu("$1", "2(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "4:"type##_lbu("$1", "3(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "li\t%1, 0\n"                       \
+                       ".set\tpop\n"                       \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%1, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       ".previous"                         \
+                       : "=&r" (value), "=r" (res)         \
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
+
+#endif /* CONFIG_CPU_MIPSR6 */
+
+#define     _LoadHWU(addr, value, res, type) \
+do {                                                        \
                __asm__ __volatile__ (                      \
                        ".set\tnoat\n"                      \
-                       "1:\t"user_lbu("%0", "0(%2)")"\n"   \
-                       "2:\t"user_lbu("$1", "1(%2)")"\n\t" \
+                       "1:\t"type##_lbu("%0", "0(%2)")"\n" \
+                       "2:\t"type##_lbu("$1", "1(%2)")"\n\t"\
                        "sll\t%0, 0x8\n\t"                  \
                        "or\t%0, $1\n\t"                    \
                        "li\t%1, 0\n"                       \
@@ -167,12 +210,15 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     LoadWU(addr, value, res)  \
+#ifndef CONFIG_CPU_MIPSR6
+#define     _LoadWU(addr, value, res, type)  \
+do {                                                        \
                __asm__ __volatile__ (                      \
-                       "1:\t"user_lwl("%0", "(%2)")"\n"    \
-                       "2:\t"user_lwr("%0", "3(%2)")"\n\t" \
+                       "1:\t"type##_lwl("%0", "(%2)")"\n"  \
+                       "2:\t"type##_lwr("%0", "3(%2)")"\n\t"\
                        "dsll\t%0, %0, 32\n\t"              \
                        "dsrl\t%0, %0, 32\n\t"              \
                        "li\t%1, 0\n"                       \
@@ -187,9 +233,11 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     LoadDW(addr, value, res)  \
+#define     _LoadDW(addr, value, res)  \
+do {                                                        \
                __asm__ __volatile__ (                      \
                        "1:\tldl\t%0, (%2)\n"               \
                        "2:\tldr\t%0, 7(%2)\n\t"            \
@@ -205,14 +253,103 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     StoreHW(addr, value, res) \
+#else
+/* MIPSR6 has not lwl and ldl instructions */
+#define            _LoadWU(addr, value, res, type) \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n\t"                    \
+                       ".set\tnoat\n\t"                    \
+                       "1:"type##_lbu("%0", "0(%2)")"\n\t" \
+                       "2:"type##_lbu("$1", "1(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "3:"type##_lbu("$1", "2(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "4:"type##_lbu("$1", "3(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "li\t%1, 0\n"                       \
+                       ".set\tpop\n"                       \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%1, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       ".previous"                         \
+                       : "=&r" (value), "=r" (res)         \
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
+
+#define     _LoadDW(addr, value, res)  \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n\t"                    \
+                       ".set\tnoat\n\t"                    \
+                       "1:lb\t%0, 0(%2)\n\t"               \
+                       "2:lbu\t $1, 1(%2)\n\t"             \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "3:lbu\t$1, 2(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "4:lbu\t$1, 3(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "5:lbu\t$1, 4(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "6:lbu\t$1, 5(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "7:lbu\t$1, 6(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "8:lbu\t$1, 7(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "li\t%1, 0\n"                       \
+                       ".set\tpop\n\t"                     \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%1, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       STR(PTR)"\t5b, 11b\n\t"             \
+                       STR(PTR)"\t6b, 11b\n\t"             \
+                       STR(PTR)"\t7b, 11b\n\t"             \
+                       STR(PTR)"\t8b, 11b\n\t"             \
+                       ".previous"                         \
+                       : "=&r" (value), "=r" (res)         \
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
+
+#endif /* CONFIG_CPU_MIPSR6 */
+
+
+#define     _StoreHW(addr, value, res, type) \
+do {                                                        \
                __asm__ __volatile__ (                      \
                        ".set\tnoat\n"                      \
-                       "1:\t"user_sb("%1", "1(%2)")"\n"    \
+                       "1:\t"type##_sb("%1", "1(%2)")"\n"  \
                        "srl\t$1, %1, 0x8\n"                \
-                       "2:\t"user_sb("$1", "0(%2)")"\n"    \
+                       "2:\t"type##_sb("$1", "0(%2)")"\n"  \
                        ".set\tat\n\t"                      \
                        "li\t%0, 0\n"                       \
                        "3:\n\t"                            \
@@ -226,12 +363,15 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=r" (res)                        \
-                       : "r" (value), "r" (addr), "i" (-EFAULT));
+                       : "r" (value), "r" (addr), "i" (-EFAULT));\
+} while(0)
 
-#define     StoreW(addr, value, res)  \
+#ifndef CONFIG_CPU_MIPSR6
+#define     _StoreW(addr, value, res, type)  \
+do {                                                        \
                __asm__ __volatile__ (                      \
-                       "1:\t"user_swl("%1", "(%2)")"\n"    \
-                       "2:\t"user_swr("%1", "3(%2)")"\n\t" \
+                       "1:\t"type##_swl("%1", "(%2)")"\n"  \
+                       "2:\t"type##_swr("%1", "3(%2)")"\n\t"\
                        "li\t%0, 0\n"                       \
                        "3:\n\t"                            \
                        ".insn\n\t"                         \
@@ -244,9 +384,11 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                : "=r" (res)                                \
-               : "r" (value), "r" (addr), "i" (-EFAULT));
+               : "r" (value), "r" (addr), "i" (-EFAULT));  \
+} while(0)
 
-#define     StoreDW(addr, value, res) \
+#define     _StoreDW(addr, value, res) \
+do {                                                        \
                __asm__ __volatile__ (                      \
                        "1:\tsdl\t%1,(%2)\n"                \
                        "2:\tsdr\t%1, 7(%2)\n\t"            \
@@ -262,14 +404,95 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                : "=r" (res)                                \
-               : "r" (value), "r" (addr), "i" (-EFAULT));
-#endif
+               : "r" (value), "r" (addr), "i" (-EFAULT));  \
+} while(0)
+
+#else
+/* MIPSR6 has no swl and sdl instructions */
+#define     _StoreW(addr, value, res, type)  \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n\t"                    \
+                       ".set\tnoat\n\t"                    \
+                       "1:"type##_sb("%1", "3(%2)")"\n\t"  \
+                       "srl\t$1, %1, 0x8\n\t"              \
+                       "2:"type##_sb("$1", "2(%2)")"\n\t"  \
+                       "srl\t$1, $1,  0x8\n\t"             \
+                       "3:"type##_sb("$1", "1(%2)")"\n\t"  \
+                       "srl\t$1, $1, 0x8\n\t"              \
+                       "4:"type##_sb("$1", "0(%2)")"\n\t"  \
+                       ".set\tpop\n\t"                     \
+                       "li\t%0, 0\n"                       \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%0, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       ".previous"                         \
+               : "=&r" (res)                               \
+               : "r" (value), "r" (addr), "i" (-EFAULT)    \
+               : "memory");                                \
+} while(0)
 
-#ifdef __LITTLE_ENDIAN
-#define     LoadHW(addr, value, res)  \
+#define     StoreDW(addr, value, res) \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n\t"                    \
+                       ".set\tnoat\n\t"                    \
+                       "1:sb\t%1, 7(%2)\n\t"               \
+                       "dsrl\t$1, %1, 0x8\n\t"             \
+                       "2:sb\t$1, 6(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "3:sb\t$1, 5(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "4:sb\t$1, 4(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "5:sb\t$1, 3(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "6:sb\t$1, 2(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "7:sb\t$1, 1(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "8:sb\t$1, 0(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       ".set\tpop\n\t"                     \
+                       "li\t%0, 0\n"                       \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%0, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       STR(PTR)"\t5b, 11b\n\t"             \
+                       STR(PTR)"\t6b, 11b\n\t"             \
+                       STR(PTR)"\t7b, 11b\n\t"             \
+                       STR(PTR)"\t8b, 11b\n\t"             \
+                       ".previous"                         \
+               : "=&r" (res)                               \
+               : "r" (value), "r" (addr), "i" (-EFAULT)    \
+               : "memory");                                \
+} while(0)
+
+#endif /* CONFIG_CPU_MIPSR6 */
+
+#else /* __BIG_ENDIAN */
+
+#define     _LoadHW(addr, value, res, type)  \
+do {                                                        \
                __asm__ __volatile__ (".set\tnoat\n"        \
-                       "1:\t"user_lb("%0", "1(%2)")"\n"    \
-                       "2:\t"user_lbu("$1", "0(%2)")"\n\t" \
+                       "1:\t"type##_lb("%0", "1(%2)")"\n"  \
+                       "2:\t"type##_lbu("$1", "0(%2)")"\n\t"\
                        "sll\t%0, 0x8\n\t"                  \
                        "or\t%0, $1\n\t"                    \
                        "li\t%1, 0\n"                       \
@@ -284,12 +507,15 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     LoadW(addr, value, res)   \
+#ifndef CONFIG_CPU_MIPSR6
+#define     _LoadW(addr, value, res, type)   \
+do {                                                        \
                __asm__ __volatile__ (                      \
-                       "1:\t"user_lwl("%0", "3(%2)")"\n"   \
-                       "2:\t"user_lwr("%0", "(%2)")"\n\t"  \
+                       "1:\t"type##_lwl("%0", "3(%2)")"\n" \
+                       "2:\t"type##_lwr("%0", "(%2)")"\n\t"\
                        "li\t%1, 0\n"                       \
                        "3:\n\t"                            \
                        ".insn\n\t"                         \
@@ -302,13 +528,53 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     LoadHWU(addr, value, res) \
+#else
+/* MIPSR6 has no lwl instruction */
+#define     _LoadW(addr, value, res, type) \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n"                      \
+                       ".set\tnoat\n\t"                    \
+                       "1:"type##_lb("%0", "3(%2)")"\n\t"  \
+                       "2:"type##_lbu("$1", "2(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "3:"type##_lbu("$1", "1(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "4:"type##_lbu("$1", "0(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "li\t%1, 0\n"                       \
+                       ".set\tpop\n"                       \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%1, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       ".previous"                         \
+                       : "=&r" (value), "=r" (res)         \
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
+
+#endif /* CONFIG_CPU_MIPSR6 */
+
+
+#define     _LoadHWU(addr, value, res, type) \
+do {                                                        \
                __asm__ __volatile__ (                      \
                        ".set\tnoat\n"                      \
-                       "1:\t"user_lbu("%0", "1(%2)")"\n"   \
-                       "2:\t"user_lbu("$1", "0(%2)")"\n\t" \
+                       "1:\t"type##_lbu("%0", "1(%2)")"\n" \
+                       "2:\t"type##_lbu("$1", "0(%2)")"\n\t"\
                        "sll\t%0, 0x8\n\t"                  \
                        "or\t%0, $1\n\t"                    \
                        "li\t%1, 0\n"                       \
@@ -324,12 +590,15 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     LoadWU(addr, value, res)  \
+#ifndef CONFIG_CPU_MIPSR6
+#define     _LoadWU(addr, value, res, type)  \
+do {                                                        \
                __asm__ __volatile__ (                      \
-                       "1:\t"user_lwl("%0", "3(%2)")"\n"   \
-                       "2:\t"user_lwr("%0", "(%2)")"\n\t"  \
+                       "1:\t"type##_lwl("%0", "3(%2)")"\n" \
+                       "2:\t"type##_lwr("%0", "(%2)")"\n\t"\
                        "dsll\t%0, %0, 32\n\t"              \
                        "dsrl\t%0, %0, 32\n\t"              \
                        "li\t%1, 0\n"                       \
@@ -344,9 +613,11 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     LoadDW(addr, value, res)  \
+#define     _LoadDW(addr, value, res)  \
+do {                                                        \
                __asm__ __volatile__ (                      \
                        "1:\tldl\t%0, 7(%2)\n"              \
                        "2:\tldr\t%0, (%2)\n\t"             \
@@ -362,14 +633,101 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=&r" (value), "=r" (res)         \
-                       : "r" (addr), "i" (-EFAULT));
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
 
-#define     StoreHW(addr, value, res) \
+#else
+/* MIPSR6 has not lwl and ldl instructions */
+#define            _LoadWU(addr, value, res, type) \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n\t"                    \
+                       ".set\tnoat\n\t"                    \
+                       "1:"type##_lbu("%0", "3(%2)")"\n\t" \
+                       "2:"type##_lbu("$1", "2(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "3:"type##_lbu("$1", "1(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "4:"type##_lbu("$1", "0(%2)")"\n\t" \
+                       "sll\t%0, 0x8\n\t"                  \
+                       "or\t%0, $1\n\t"                    \
+                       "li\t%1, 0\n"                       \
+                       ".set\tpop\n"                       \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%1, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       ".previous"                         \
+                       : "=&r" (value), "=r" (res)         \
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
+
+#define     _LoadDW(addr, value, res)  \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n\t"                    \
+                       ".set\tnoat\n\t"                    \
+                       "1:lb\t%0, 7(%2)\n\t"               \
+                       "2:lbu\t$1, 6(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "3:lbu\t$1, 5(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "4:lbu\t$1, 4(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "5:lbu\t$1, 3(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "6:lbu\t$1, 2(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "7:lbu\t$1, 1(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "8:lbu\t$1, 0(%2)\n\t"              \
+                       "dsll\t%0, 0x8\n\t"                 \
+                       "or\t%0, $1\n\t"                    \
+                       "li\t%1, 0\n"                       \
+                       ".set\tpop\n\t"                     \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%1, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       STR(PTR)"\t5b, 11b\n\t"             \
+                       STR(PTR)"\t6b, 11b\n\t"             \
+                       STR(PTR)"\t7b, 11b\n\t"             \
+                       STR(PTR)"\t8b, 11b\n\t"             \
+                       ".previous"                         \
+                       : "=&r" (value), "=r" (res)         \
+                       : "r" (addr), "i" (-EFAULT));       \
+} while(0)
+#endif /* CONFIG_CPU_MIPSR6 */
+
+#define     _StoreHW(addr, value, res, type) \
+do {                                                        \
                __asm__ __volatile__ (                      \
                        ".set\tnoat\n"                      \
-                       "1:\t"user_sb("%1", "0(%2)")"\n"    \
+                       "1:\t"type##_sb("%1", "0(%2)")"\n"  \
                        "srl\t$1,%1, 0x8\n"                 \
-                       "2:\t"user_sb("$1", "1(%2)")"\n"    \
+                       "2:\t"type##_sb("$1", "1(%2)")"\n"  \
                        ".set\tat\n\t"                      \
                        "li\t%0, 0\n"                       \
                        "3:\n\t"                            \
@@ -383,12 +741,15 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                        : "=r" (res)                        \
-                       : "r" (value), "r" (addr), "i" (-EFAULT));
+                       : "r" (value), "r" (addr), "i" (-EFAULT));\
+} while(0)
 
-#define     StoreW(addr, value, res)  \
+#ifndef CONFIG_CPU_MIPSR6
+#define     _StoreW(addr, value, res, type)  \
+do {                                                        \
                __asm__ __volatile__ (                      \
-                       "1:\t"user_swl("%1", "3(%2)")"\n"   \
-                       "2:\t"user_swr("%1", "(%2)")"\n\t"  \
+                       "1:\t"type##_swl("%1", "3(%2)")"\n" \
+                       "2:\t"type##_swr("%1", "(%2)")"\n\t"\
                        "li\t%0, 0\n"                       \
                        "3:\n\t"                            \
                        ".insn\n\t"                         \
@@ -401,9 +762,11 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                : "=r" (res)                                \
-               : "r" (value), "r" (addr), "i" (-EFAULT));
+               : "r" (value), "r" (addr), "i" (-EFAULT));  \
+} while(0)
 
-#define     StoreDW(addr, value, res) \
+#define     _StoreDW(addr, value, res) \
+do {                                                        \
                __asm__ __volatile__ (                      \
                        "1:\tsdl\t%1, 7(%2)\n"              \
                        "2:\tsdr\t%1, (%2)\n\t"             \
@@ -419,9 +782,105 @@ extern void show_registers(struct pt_regs *regs);
                        STR(PTR)"\t2b, 4b\n\t"              \
                        ".previous"                         \
                : "=r" (res)                                \
-               : "r" (value), "r" (addr), "i" (-EFAULT));
+               : "r" (value), "r" (addr), "i" (-EFAULT));  \
+} while(0)
+
+#else
+/* MIPSR6 has no swl and sdl instructions */
+#define     _StoreW(addr, value, res, type)  \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n\t"                    \
+                       ".set\tnoat\n\t"                    \
+                       "1:"type##_sb("%1", "0(%2)")"\n\t"  \
+                       "srl\t$1, %1, 0x8\n\t"              \
+                       "2:"type##_sb("$1", "1(%2)")"\n\t"  \
+                       "srl\t$1, $1,  0x8\n\t"             \
+                       "3:"type##_sb("$1", "2(%2)")"\n\t"  \
+                       "srl\t$1, $1, 0x8\n\t"              \
+                       "4:"type##_sb("$1", "3(%2)")"\n\t"  \
+                       ".set\tpop\n\t"                     \
+                       "li\t%0, 0\n"                       \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%0, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       ".previous"                         \
+               : "=&r" (res)                               \
+               : "r" (value), "r" (addr), "i" (-EFAULT)    \
+               : "memory");                                \
+} while(0)
+
+#define     _StoreDW(addr, value, res) \
+do {                                                        \
+               __asm__ __volatile__ (                      \
+                       ".set\tpush\n\t"                    \
+                       ".set\tnoat\n\t"                    \
+                       "1:sb\t%1, 0(%2)\n\t"               \
+                       "dsrl\t$1, %1, 0x8\n\t"             \
+                       "2:sb\t$1, 1(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "3:sb\t$1, 2(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "4:sb\t$1, 3(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "5:sb\t$1, 4(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "6:sb\t$1, 5(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "7:sb\t$1, 6(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       "8:sb\t$1, 7(%2)\n\t"               \
+                       "dsrl\t$1, $1, 0x8\n\t"             \
+                       ".set\tpop\n\t"                     \
+                       "li\t%0, 0\n"                       \
+                       "10:\n\t"                           \
+                       ".insn\n\t"                         \
+                       ".section\t.fixup,\"ax\"\n\t"       \
+                       "11:\tli\t%0, %3\n\t"               \
+                       "j\t10b\n\t"                        \
+                       ".previous\n\t"                     \
+                       ".section\t__ex_table,\"a\"\n\t"    \
+                       STR(PTR)"\t1b, 11b\n\t"             \
+                       STR(PTR)"\t2b, 11b\n\t"             \
+                       STR(PTR)"\t3b, 11b\n\t"             \
+                       STR(PTR)"\t4b, 11b\n\t"             \
+                       STR(PTR)"\t5b, 11b\n\t"             \
+                       STR(PTR)"\t6b, 11b\n\t"             \
+                       STR(PTR)"\t7b, 11b\n\t"             \
+                       STR(PTR)"\t8b, 11b\n\t"             \
+                       ".previous"                         \
+               : "=&r" (res)                               \
+               : "r" (value), "r" (addr), "i" (-EFAULT)    \
+               : "memory");                                \
+} while(0)
+
+#endif /* CONFIG_CPU_MIPSR6 */
 #endif
 
+#define LoadHWU(addr, value, res)      _LoadHWU(addr, value, res, kernel)
+#define LoadHWUE(addr, value, res)     _LoadHWU(addr, value, res, user)
+#define LoadWU(addr, value, res)       _LoadWU(addr, value, res, kernel)
+#define LoadWUE(addr, value, res)      _LoadWU(addr, value, res, user)
+#define LoadHW(addr, value, res)       _LoadHW(addr, value, res, kernel)
+#define LoadHWE(addr, value, res)      _LoadHW(addr, value, res, user)
+#define LoadW(addr, value, res)                _LoadW(addr, value, res, kernel)
+#define LoadWE(addr, value, res)       _LoadW(addr, value, res, user)
+#define LoadDW(addr, value, res)       _LoadDW(addr, value, res)
+
+#define StoreHW(addr, value, res)      _StoreHW(addr, value, res, kernel)
+#define StoreHWE(addr, value, res)     _StoreHW(addr, value, res, user)
+#define StoreW(addr, value, res)       _StoreW(addr, value, res, kernel)
+#define StoreWE(addr, value, res)      _StoreW(addr, value, res, user)
+#define StoreDW(addr, value, res)      _StoreDW(addr, value, res)
+
 static void emulate_load_store_insn(struct pt_regs *regs,
        void __user *addr, unsigned int __user *pc)
 {
@@ -493,7 +952,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                                set_fs(seg);
                                goto sigbus;
                        }
-                       LoadHW(addr, value, res);
+                       LoadHWE(addr, value, res);
                        if (res) {
                                set_fs(seg);
                                goto fault;
@@ -506,7 +965,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                                set_fs(seg);
                                goto sigbus;
                        }
-                               LoadW(addr, value, res);
+                               LoadWE(addr, value, res);
                        if (res) {
                                set_fs(seg);
                                goto fault;
@@ -519,7 +978,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                                set_fs(seg);
                                goto sigbus;
                        }
-                       LoadHWU(addr, value, res);
+                       LoadHWUE(addr, value, res);
                        if (res) {
                                set_fs(seg);
                                goto fault;
@@ -534,7 +993,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                        }
                        compute_return_epc(regs);
                        value = regs->regs[insn.spec3_format.rt];
-                       StoreHW(addr, value, res);
+                       StoreHWE(addr, value, res);
                        if (res) {
                                set_fs(seg);
                                goto fault;
@@ -547,7 +1006,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                        }
                        compute_return_epc(regs);
                        value = regs->regs[insn.spec3_format.rt];
-                       StoreW(addr, value, res);
+                       StoreWE(addr, value, res);
                        if (res) {
                                set_fs(seg);
                                goto fault;
@@ -564,7 +1023,15 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                if (!access_ok(VERIFY_READ, addr, 2))
                        goto sigbus;
 
-               LoadHW(addr, value, res);
+               if (config_enabled(CONFIG_EVA)) {
+                       if (segment_eq(get_fs(), get_ds()))
+                               LoadHW(addr, value, res);
+                       else
+                               LoadHWE(addr, value, res);
+               } else {
+                       LoadHW(addr, value, res);
+               }
+
                if (res)
                        goto fault;
                compute_return_epc(regs);
@@ -575,7 +1042,15 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                if (!access_ok(VERIFY_READ, addr, 4))
                        goto sigbus;
 
-               LoadW(addr, value, res);
+               if (config_enabled(CONFIG_EVA)) {
+                       if (segment_eq(get_fs(), get_ds()))
+                               LoadW(addr, value, res);
+                       else
+                               LoadWE(addr, value, res);
+               } else {
+                       LoadW(addr, value, res);
+               }
+
                if (res)
                        goto fault;
                compute_return_epc(regs);
@@ -586,7 +1061,15 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                if (!access_ok(VERIFY_READ, addr, 2))
                        goto sigbus;
 
-               LoadHWU(addr, value, res);
+               if (config_enabled(CONFIG_EVA)) {
+                       if (segment_eq(get_fs(), get_ds()))
+                               LoadHWU(addr, value, res);
+                       else
+                               LoadHWUE(addr, value, res);
+               } else {
+                       LoadHWU(addr, value, res);
+               }
+
                if (res)
                        goto fault;
                compute_return_epc(regs);
@@ -645,7 +1128,16 @@ static void emulate_load_store_insn(struct pt_regs *regs,
 
                compute_return_epc(regs);
                value = regs->regs[insn.i_format.rt];
-               StoreHW(addr, value, res);
+
+               if (config_enabled(CONFIG_EVA)) {
+                       if (segment_eq(get_fs(), get_ds()))
+                               StoreHW(addr, value, res);
+                       else
+                               StoreHWE(addr, value, res);
+               } else {
+                       StoreHW(addr, value, res);
+               }
+
                if (res)
                        goto fault;
                break;
@@ -656,7 +1148,16 @@ static void emulate_load_store_insn(struct pt_regs *regs,
 
                compute_return_epc(regs);
                value = regs->regs[insn.i_format.rt];
-               StoreW(addr, value, res);
+
+               if (config_enabled(CONFIG_EVA)) {
+                       if (segment_eq(get_fs(), get_ds()))
+                               StoreW(addr, value, res);
+                       else
+                               StoreWE(addr, value, res);
+               } else {
+                       StoreW(addr, value, res);
+               }
+
                if (res)
                        goto fault;
                break;
@@ -703,10 +1204,13 @@ static void emulate_load_store_insn(struct pt_regs *regs,
                        break;
                return;
 
+#ifndef CONFIG_CPU_MIPSR6
        /*
         * COP2 is available to implementor for application specific use.
         * It's up to applications to register a notifier chain and do
         * whatever they have to do, including possible sending of signals.
+        *
+        * This instruction has been reallocated in Release 6
         */
        case lwc2_op:
                cu2_notifier_call_chain(CU2_LWC2_OP, regs);
@@ -723,7 +1227,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
        case sdc2_op:
                cu2_notifier_call_chain(CU2_SDC2_OP, regs);
                break;
-
+#endif
        default:
                /*
                 * Pheeee...  We encountered an yet unknown instruction or