2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (c) 2014 Imagination Technologies Ltd.
7 * Author: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
8 * Author: Markos Chandras <markos.chandras@imgtec.com>
10 * MIPS R2 user space instruction emulator for MIPS R6
13 #include <linux/bug.h>
14 #include <linux/compiler.h>
15 #include <linux/debugfs.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/ptrace.h>
20 #include <linux/seq_file.h>
23 #include <asm/branch.h>
24 #include <asm/break.h>
26 #include <asm/fpu_emulator.h>
28 #include <asm/mips-r2-to-r6-emul.h>
29 #include <asm/local.h>
30 #include <asm/ptrace.h>
31 #include <asm/uaccess.h>
34 #define ADDIU "daddiu "
38 #define ADDIU "addiu "
41 #endif /* CONFIG_64BIT */
48 DEFINE_PER_CPU(struct mips_r2_emulator_stats, mipsr2emustats);
49 DEFINE_PER_CPU(struct mips_r2_emulator_stats, mipsr2bdemustats);
50 DEFINE_PER_CPU(struct mips_r2br_emulator_stats, mipsr2bremustats);
52 extern const unsigned int fpucondbit[8];
54 #define MIPS_R2_EMUL_TOTAL_PASS 10
56 int mipsr2_emulation = 0;
58 static int __init mipsr2emu_enable(char *s)
62 pr_info("MIPS R2-to-R6 Emulator Enabled!");
66 __setup("mipsr2emu", mipsr2emu_enable);
69 * mipsr6_emul - Emulate some frequent R2/R5/R6 instructions in delay slot
70 * for performance instead of the traditional way of using a stack trampoline
71 * which is rather slow.
72 * @regs: Process register set
75 static inline int mipsr6_emul(struct pt_regs *regs, u32 ir)
77 switch (MIPSInst_OPCODE(ir)) {
80 regs->regs[MIPSInst_RT(ir)] =
81 (s32)regs->regs[MIPSInst_RS(ir)] +
82 (s32)MIPSInst_SIMM(ir);
85 if (config_enabled(CONFIG_32BIT))
89 regs->regs[MIPSInst_RT(ir)] =
90 (s64)regs->regs[MIPSInst_RS(ir)] +
91 (s64)MIPSInst_SIMM(ir);
97 /* FPU instructions in delay slot */
100 switch (MIPSInst_FUNC(ir)) {
103 regs->regs[MIPSInst_RD(ir)] =
104 regs->regs[MIPSInst_RS(ir)] |
105 regs->regs[MIPSInst_RT(ir)];
112 regs->regs[MIPSInst_RD(ir)] =
113 (s32)(((u32)regs->regs[MIPSInst_RT(ir)]) <<
121 regs->regs[MIPSInst_RD(ir)] =
122 (s32)(((u32)regs->regs[MIPSInst_RT(ir)]) >>
130 regs->regs[MIPSInst_RD(ir)] =
131 (s32)((u32)regs->regs[MIPSInst_RS(ir)] +
132 (u32)regs->regs[MIPSInst_RT(ir)]);
139 regs->regs[MIPSInst_RD(ir)] =
140 (s32)((u32)regs->regs[MIPSInst_RS(ir)] -
141 (u32)regs->regs[MIPSInst_RT(ir)]);
144 if (config_enabled(CONFIG_32BIT) || MIPSInst_RS(ir))
148 regs->regs[MIPSInst_RD(ir)] =
149 (s64)(((u64)regs->regs[MIPSInst_RT(ir)]) <<
153 if (config_enabled(CONFIG_32BIT) || MIPSInst_RS(ir))
157 regs->regs[MIPSInst_RD(ir)] =
158 (s64)(((u64)regs->regs[MIPSInst_RT(ir)]) >>
162 if (config_enabled(CONFIG_32BIT) || MIPSInst_FD(ir))
166 regs->regs[MIPSInst_RD(ir)] =
167 (u64)regs->regs[MIPSInst_RS(ir)] +
168 (u64)regs->regs[MIPSInst_RT(ir)];
171 if (config_enabled(CONFIG_32BIT) || MIPSInst_FD(ir))
175 regs->regs[MIPSInst_RD(ir)] =
176 (s64)((u64)regs->regs[MIPSInst_RS(ir)] -
177 (u64)regs->regs[MIPSInst_RT(ir)]);
182 pr_debug("No fastpath BD emulation for instruction 0x%08x (op: %02x)\n",
183 ir, MIPSInst_OPCODE(ir));
190 * movt_func - Emulate a MOVT instruction
191 * @regs: Process register set
194 * Returns 0 since it always succeeds.
196 static int movf_func(struct pt_regs *regs, u32 ir)
201 csr = current->thread.fpu.fcr31;
202 cond = fpucondbit[MIPSInst_RT(ir) >> 2];
203 if (((csr & cond) == 0) && MIPSInst_RD(ir))
204 regs->regs[MIPSInst_RD(ir)] = regs->regs[MIPSInst_RS(ir)];
210 * movt_func - Emulate a MOVT instruction
211 * @regs: Process register set
214 * Returns 0 since it always succeeds.
216 static int movt_func(struct pt_regs *regs, u32 ir)
221 csr = current->thread.fpu.fcr31;
222 cond = fpucondbit[MIPSInst_RT(ir) >> 2];
224 if (((csr & cond) != 0) && MIPSInst_RD(ir))
225 regs->regs[MIPSInst_RD(ir)] = regs->regs[MIPSInst_RS(ir)];
233 * jr_func - Emulate a JR instruction.
234 * @pt_regs: Process register set
237 * Returns SIGILL if JR was in delay slot, SIGEMT if we
238 * can't compute the EPC, SIGSEGV if we can't access the
239 * userland instruction or 0 on success.
241 static int jr_func(struct pt_regs *regs, u32 ir)
244 unsigned long cepc, epc, nepc;
247 if (delay_slot(regs))
250 /* EPC after the RI/JR instruction */
251 nepc = regs->cp0_epc;
252 /* Roll back to the reserved R2 JR instruction */
255 err = __compute_return_epc(regs);
262 cepc = regs->cp0_epc;
264 /* Get DS instruction */
265 err = __get_user(nir, (u32 __user *)nepc);
269 MIPS_R2BR_STATS(jrs);
271 /* If nir == 0(NOP), then nothing else to do */
274 * Negative err means FPU instruction in BD-slot,
275 * Zero err means 'BD-slot emulation done'
276 * For anything else we go back to trampoline emulation.
278 err = mipsr6_emul(regs, nir);
280 regs->cp0_epc = nepc;
281 err = mips_dsemul(regs, nir, cepc);
284 MIPS_R2_STATS(dsemul);
292 * movz_func - Emulate a MOVZ instruction
293 * @regs: Process register set
296 * Returns 0 since it always succeeds.
298 static int movz_func(struct pt_regs *regs, u32 ir)
300 if (((regs->regs[MIPSInst_RT(ir)]) == 0) && MIPSInst_RD(ir))
301 regs->regs[MIPSInst_RD(ir)] = regs->regs[MIPSInst_RS(ir)];
308 * movn_func - Emulate a MOVZ instruction
309 * @regs: Process register set
312 * Returns 0 since it always succeeds.
314 static int movn_func(struct pt_regs *regs, u32 ir)
316 if (((regs->regs[MIPSInst_RT(ir)]) != 0) && MIPSInst_RD(ir))
317 regs->regs[MIPSInst_RD(ir)] = regs->regs[MIPSInst_RS(ir)];
324 * mfhi_func - Emulate a MFHI instruction
325 * @regs: Process register set
328 * Returns 0 since it always succeeds.
330 static int mfhi_func(struct pt_regs *regs, u32 ir)
333 regs->regs[MIPSInst_RD(ir)] = regs->hi;
341 * mthi_func - Emulate a MTHI instruction
342 * @regs: Process register set
345 * Returns 0 since it always succeeds.
347 static int mthi_func(struct pt_regs *regs, u32 ir)
349 regs->hi = regs->regs[MIPSInst_RS(ir)];
357 * mflo_func - Emulate a MFLO instruction
358 * @regs: Process register set
361 * Returns 0 since it always succeeds.
363 static int mflo_func(struct pt_regs *regs, u32 ir)
366 regs->regs[MIPSInst_RD(ir)] = regs->lo;
374 * mtlo_func - Emulate a MTLO instruction
375 * @regs: Process register set
378 * Returns 0 since it always succeeds.
380 static int mtlo_func(struct pt_regs *regs, u32 ir)
382 regs->lo = regs->regs[MIPSInst_RS(ir)];
390 * mult_func - Emulate a MULT instruction
391 * @regs: Process register set
394 * Returns 0 since it always succeeds.
396 static int mult_func(struct pt_regs *regs, u32 ir)
401 rt = regs->regs[MIPSInst_RT(ir)];
402 rs = regs->regs[MIPSInst_RS(ir)];
403 res = (s64)rt * (s64)rs;
417 * multu_func - Emulate a MULTU instruction
418 * @regs: Process register set
421 * Returns 0 since it always succeeds.
423 static int multu_func(struct pt_regs *regs, u32 ir)
428 rt = regs->regs[MIPSInst_RT(ir)];
429 rs = regs->regs[MIPSInst_RS(ir)];
430 res = (u64)rt * (u64)rs;
433 regs->hi = (s64)(res >> 32);
441 * div_func - Emulate a DIV instruction
442 * @regs: Process register set
445 * Returns 0 since it always succeeds.
447 static int div_func(struct pt_regs *regs, u32 ir)
451 rt = regs->regs[MIPSInst_RT(ir)];
452 rs = regs->regs[MIPSInst_RS(ir)];
454 regs->lo = (s64)(rs / rt);
455 regs->hi = (s64)(rs % rt);
463 * divu_func - Emulate a DIVU instruction
464 * @regs: Process register set
467 * Returns 0 since it always succeeds.
469 static int divu_func(struct pt_regs *regs, u32 ir)
473 rt = regs->regs[MIPSInst_RT(ir)];
474 rs = regs->regs[MIPSInst_RS(ir)];
476 regs->lo = (s64)(rs / rt);
477 regs->hi = (s64)(rs % rt);
485 * dmult_func - Emulate a DMULT instruction
486 * @regs: Process register set
489 * Returns 0 on success or SIGILL for 32-bit kernels.
491 static int dmult_func(struct pt_regs *regs, u32 ir)
496 if (config_enabled(CONFIG_32BIT))
499 rt = regs->regs[MIPSInst_RT(ir)];
500 rs = regs->regs[MIPSInst_RS(ir)];
504 __asm__ __volatile__(
505 "dmuh %0, %1, %2\t\n"
517 * dmultu_func - Emulate a DMULTU instruction
518 * @regs: Process register set
521 * Returns 0 on success or SIGILL for 32-bit kernels.
523 static int dmultu_func(struct pt_regs *regs, u32 ir)
528 if (config_enabled(CONFIG_32BIT))
531 rt = regs->regs[MIPSInst_RT(ir)];
532 rs = regs->regs[MIPSInst_RS(ir)];
536 __asm__ __volatile__(
537 "dmuhu %0, %1, %2\t\n"
549 * ddiv_func - Emulate a DDIV instruction
550 * @regs: Process register set
553 * Returns 0 on success or SIGILL for 32-bit kernels.
555 static int ddiv_func(struct pt_regs *regs, u32 ir)
559 if (config_enabled(CONFIG_32BIT))
562 rt = regs->regs[MIPSInst_RT(ir)];
563 rs = regs->regs[MIPSInst_RS(ir)];
574 * ddivu_func - Emulate a DDIVU instruction
575 * @regs: Process register set
578 * Returns 0 on success or SIGILL for 32-bit kernels.
580 static int ddivu_func(struct pt_regs *regs, u32 ir)
584 if (config_enabled(CONFIG_32BIT))
587 rt = regs->regs[MIPSInst_RT(ir)];
588 rs = regs->regs[MIPSInst_RS(ir)];
598 /* R6 removed instructions for the SPECIAL opcode */
599 static struct r2_decoder_table spec_op_table[] = {
600 { 0xfc1ff83f, 0x00000008, jr_func },
601 { 0xfc00ffff, 0x00000018, mult_func },
602 { 0xfc00ffff, 0x00000019, multu_func },
603 { 0xfc00ffff, 0x0000001c, dmult_func },
604 { 0xfc00ffff, 0x0000001d, dmultu_func },
605 { 0xffff07ff, 0x00000010, mfhi_func },
606 { 0xfc1fffff, 0x00000011, mthi_func },
607 { 0xffff07ff, 0x00000012, mflo_func },
608 { 0xfc1fffff, 0x00000013, mtlo_func },
609 { 0xfc0307ff, 0x00000001, movf_func },
610 { 0xfc0307ff, 0x00010001, movt_func },
611 { 0xfc0007ff, 0x0000000a, movz_func },
612 { 0xfc0007ff, 0x0000000b, movn_func },
613 { 0xfc00ffff, 0x0000001a, div_func },
614 { 0xfc00ffff, 0x0000001b, divu_func },
615 { 0xfc00ffff, 0x0000001e, ddiv_func },
616 { 0xfc00ffff, 0x0000001f, ddivu_func },
621 * madd_func - Emulate a MADD instruction
622 * @regs: Process register set
625 * Returns 0 since it always succeeds.
627 static int madd_func(struct pt_regs *regs, u32 ir)
632 rt = regs->regs[MIPSInst_RT(ir)];
633 rs = regs->regs[MIPSInst_RS(ir)];
634 res = (s64)rt * (s64)rs;
637 res += ((((s64)rt) << 32) | (u32)rs);
650 * maddu_func - Emulate a MADDU instruction
651 * @regs: Process register set
654 * Returns 0 since it always succeeds.
656 static int maddu_func(struct pt_regs *regs, u32 ir)
661 rt = regs->regs[MIPSInst_RT(ir)];
662 rs = regs->regs[MIPSInst_RS(ir)];
663 res = (u64)rt * (u64)rs;
666 res += ((((s64)rt) << 32) | (u32)rs);
679 * msub_func - Emulate a MSUB instruction
680 * @regs: Process register set
683 * Returns 0 since it always succeeds.
685 static int msub_func(struct pt_regs *regs, u32 ir)
690 rt = regs->regs[MIPSInst_RT(ir)];
691 rs = regs->regs[MIPSInst_RS(ir)];
692 res = (s64)rt * (s64)rs;
695 res = ((((s64)rt) << 32) | (u32)rs) - res;
708 * msubu_func - Emulate a MSUBU instruction
709 * @regs: Process register set
712 * Returns 0 since it always succeeds.
714 static int msubu_func(struct pt_regs *regs, u32 ir)
719 rt = regs->regs[MIPSInst_RT(ir)];
720 rs = regs->regs[MIPSInst_RS(ir)];
721 res = (u64)rt * (u64)rs;
724 res = ((((s64)rt) << 32) | (u32)rs) - res;
737 * mul_func - Emulate a MUL instruction
738 * @regs: Process register set
741 * Returns 0 since it always succeeds.
743 static int mul_func(struct pt_regs *regs, u32 ir)
748 if (!MIPSInst_RD(ir))
750 rt = regs->regs[MIPSInst_RT(ir)];
751 rs = regs->regs[MIPSInst_RS(ir)];
752 res = (s64)rt * (s64)rs;
755 regs->regs[MIPSInst_RD(ir)] = (s64)rs;
763 * clz_func - Emulate a CLZ instruction
764 * @regs: Process register set
767 * Returns 0 since it always succeeds.
769 static int clz_func(struct pt_regs *regs, u32 ir)
774 if (!MIPSInst_RD(ir))
777 rs = regs->regs[MIPSInst_RS(ir)];
778 __asm__ __volatile__("clz %0, %1" : "=r"(res) : "r"(rs));
779 regs->regs[MIPSInst_RD(ir)] = res;
787 * clo_func - Emulate a CLO instruction
788 * @regs: Process register set
791 * Returns 0 since it always succeeds.
794 static int clo_func(struct pt_regs *regs, u32 ir)
799 if (!MIPSInst_RD(ir))
802 rs = regs->regs[MIPSInst_RS(ir)];
803 __asm__ __volatile__("clo %0, %1" : "=r"(res) : "r"(rs));
804 regs->regs[MIPSInst_RD(ir)] = res;
812 * dclz_func - Emulate a DCLZ instruction
813 * @regs: Process register set
816 * Returns 0 since it always succeeds.
818 static int dclz_func(struct pt_regs *regs, u32 ir)
823 if (config_enabled(CONFIG_32BIT))
826 if (!MIPSInst_RD(ir))
829 rs = regs->regs[MIPSInst_RS(ir)];
830 __asm__ __volatile__("dclz %0, %1" : "=r"(res) : "r"(rs));
831 regs->regs[MIPSInst_RD(ir)] = res;
839 * dclo_func - Emulate a DCLO instruction
840 * @regs: Process register set
843 * Returns 0 since it always succeeds.
845 static int dclo_func(struct pt_regs *regs, u32 ir)
850 if (config_enabled(CONFIG_32BIT))
853 if (!MIPSInst_RD(ir))
856 rs = regs->regs[MIPSInst_RS(ir)];
857 __asm__ __volatile__("dclo %0, %1" : "=r"(res) : "r"(rs));
858 regs->regs[MIPSInst_RD(ir)] = res;
865 /* R6 removed instructions for the SPECIAL2 opcode */
866 static struct r2_decoder_table spec2_op_table[] = {
867 { 0xfc00ffff, 0x70000000, madd_func },
868 { 0xfc00ffff, 0x70000001, maddu_func },
869 { 0xfc0007ff, 0x70000002, mul_func },
870 { 0xfc00ffff, 0x70000004, msub_func },
871 { 0xfc00ffff, 0x70000005, msubu_func },
872 { 0xfc0007ff, 0x70000020, clz_func },
873 { 0xfc0007ff, 0x70000021, clo_func },
874 { 0xfc0007ff, 0x70000024, dclz_func },
875 { 0xfc0007ff, 0x70000025, dclo_func },
879 static inline int mipsr2_find_op_func(struct pt_regs *regs, u32 inst,
880 struct r2_decoder_table *table)
882 struct r2_decoder_table *p;
885 for (p = table; p->func; p++) {
886 if ((inst & p->mask) == p->code) {
887 err = (p->func)(regs, inst);
895 * mipsr2_decoder: Decode and emulate a MIPS R2 instruction
896 * @regs: Process register set
897 * @inst: Instruction to decode and emulate
899 int mipsr2_decoder(struct pt_regs *regs, u32 inst)
904 unsigned long cpc, epc, nepc, r31, res, rs, rt;
906 void __user *fault_addr = NULL;
910 r31 = regs->regs[31];
912 err = compute_return_epc(regs);
917 pr_debug("Emulating the 0x%08x R2 instruction @ 0x%08lx (pass=%d))\n",
920 switch (MIPSInst_OPCODE(inst)) {
922 err = mipsr2_find_op_func(regs, inst, spec_op_table);
924 /* FPU instruction under JR */
925 regs->cp0_cause |= CAUSEF_BD;
930 err = mipsr2_find_op_func(regs, inst, spec2_op_table);
933 rt = MIPSInst_RT(inst);
934 rs = MIPSInst_RS(inst);
937 if ((long)regs->regs[rs] >= MIPSInst_SIMM(inst))
938 do_trap_or_bp(regs, 0, "TGEI");
940 MIPS_R2_STATS(traps);
944 if (regs->regs[rs] >= MIPSInst_UIMM(inst))
945 do_trap_or_bp(regs, 0, "TGEIU");
947 MIPS_R2_STATS(traps);
951 if ((long)regs->regs[rs] < MIPSInst_SIMM(inst))
952 do_trap_or_bp(regs, 0, "TLTI");
954 MIPS_R2_STATS(traps);
958 if (regs->regs[rs] < MIPSInst_UIMM(inst))
959 do_trap_or_bp(regs, 0, "TLTIU");
961 MIPS_R2_STATS(traps);
965 if (regs->regs[rs] == MIPSInst_SIMM(inst))
966 do_trap_or_bp(regs, 0, "TEQI");
968 MIPS_R2_STATS(traps);
972 if (regs->regs[rs] != MIPSInst_SIMM(inst))
973 do_trap_or_bp(regs, 0, "TNEI");
975 MIPS_R2_STATS(traps);
982 if (delay_slot(regs)) {
986 regs->regs[31] = r31;
988 err = __compute_return_epc(regs);
991 if (err != BRANCH_LIKELY_TAKEN)
995 err = __get_user(nir, (u32 __user *)nepc);
1001 * This will probably be optimized away when
1002 * CONFIG_DEBUG_FS is not enabled
1006 MIPS_R2BR_STATS(bltzl);
1009 MIPS_R2BR_STATS(bgezl);
1012 MIPS_R2BR_STATS(bltzall);
1015 MIPS_R2BR_STATS(bgezall);
1019 switch (MIPSInst_OPCODE(nir)) {
1024 regs->cp0_cause |= CAUSEF_BD;
1028 err = mipsr6_emul(regs, nir);
1030 err = mips_dsemul(regs, nir, cpc);
1033 MIPS_R2_STATS(dsemul);
1039 if (delay_slot(regs)) {
1043 regs->regs[31] = r31;
1044 regs->cp0_epc = epc;
1045 err = __compute_return_epc(regs);
1048 cpc = regs->cp0_epc;
1050 err = __get_user(nir, (u32 __user *)nepc);
1056 * This will probably be optimized away when
1057 * CONFIG_DEBUG_FS is not enabled
1061 MIPS_R2BR_STATS(bltzal);
1064 MIPS_R2BR_STATS(bgezal);
1068 switch (MIPSInst_OPCODE(nir)) {
1073 regs->cp0_cause |= CAUSEF_BD;
1077 err = mipsr6_emul(regs, nir);
1079 err = mips_dsemul(regs, nir, cpc);
1082 MIPS_R2_STATS(dsemul);
1087 regs->regs[31] = r31;
1088 regs->cp0_epc = epc;
1098 if (delay_slot(regs)) {
1102 regs->regs[31] = r31;
1103 regs->cp0_epc = epc;
1104 err = __compute_return_epc(regs);
1107 if (err != BRANCH_LIKELY_TAKEN)
1109 cpc = regs->cp0_epc;
1111 err = __get_user(nir, (u32 __user *)nepc);
1117 * This will probably be optimized away when
1118 * CONFIG_DEBUG_FS is not enabled
1120 switch (MIPSInst_OPCODE(inst)) {
1122 MIPS_R2BR_STATS(beql);
1125 MIPS_R2BR_STATS(bnel);
1128 MIPS_R2BR_STATS(blezl);
1131 MIPS_R2BR_STATS(bgtzl);
1135 switch (MIPSInst_OPCODE(nir)) {
1140 regs->cp0_cause |= CAUSEF_BD;
1144 err = mipsr6_emul(regs, nir);
1146 err = mips_dsemul(regs, nir, cpc);
1149 MIPS_R2_STATS(dsemul);
1158 regs->regs[31] = r31;
1159 regs->cp0_epc = epc;
1160 if (!used_math()) { /* First time FPU user. */
1164 lose_fpu(1); /* Save FPU state for the emulator. */
1166 err = fpu_emulator_cop1Handler(regs, ¤t->thread.fpu, 0,
1170 * this is a tricky issue - lose_fpu() uses LL/SC atomics
1171 * if FPU is owned and effectively cancels user level LL/SC.
1172 * So, it could be logical to don't restore FPU ownership here.
1173 * But the sequence of multiple FPU instructions is much much
1174 * more often than LL-FPU-SC and I prefer loop here until
1175 * next scheduler cycle cancels FPU ownership
1177 own_fpu(1); /* Restore FPU state. */
1180 current->thread.cp0_baduaddr = (unsigned long)fault_addr;
1182 MIPS_R2_STATS(fpus);
1187 rt = regs->regs[MIPSInst_RT(inst)];
1188 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1189 if (!access_ok(VERIFY_READ, vaddr, 4)) {
1190 current->thread.cp0_baduaddr = vaddr;
1194 __asm__ __volatile__(
1197 #ifdef CONFIG_CPU_LITTLE_ENDIAN
1198 "1:" LB "%1, 0(%2)\n"
1199 INS "%0, %1, 24, 8\n"
1200 " andi %1, %2, 0x3\n"
1202 ADDIU "%2, %2, -1\n"
1203 "2:" LB "%1, 0(%2)\n"
1204 INS "%0, %1, 16, 8\n"
1205 " andi %1, %2, 0x3\n"
1207 ADDIU "%2, %2, -1\n"
1208 "3:" LB "%1, 0(%2)\n"
1209 INS "%0, %1, 8, 8\n"
1210 " andi %1, %2, 0x3\n"
1212 ADDIU "%2, %2, -1\n"
1213 "4:" LB "%1, 0(%2)\n"
1214 INS "%0, %1, 0, 8\n"
1215 #else /* !CONFIG_CPU_LITTLE_ENDIAN */
1216 "1:" LB "%1, 0(%2)\n"
1217 INS "%0, %1, 24, 8\n"
1219 " andi %1, %2, 0x3\n"
1221 "2:" LB "%1, 0(%2)\n"
1222 INS "%0, %1, 16, 8\n"
1224 " andi %1, %2, 0x3\n"
1226 "3:" LB "%1, 0(%2)\n"
1227 INS "%0, %1, 8, 8\n"
1229 " andi %1, %2, 0x3\n"
1231 "4:" LB "%1, 0(%2)\n"
1232 INS "%0, %1, 0, 8\n"
1233 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
1234 "9: sll %0, %0, 0\n"
1237 " .section .fixup,\"ax\"\n"
1241 " .section __ex_table,\"a\"\n"
1248 : "+&r"(rt), "=&r"(rs),
1249 "+&r"(vaddr), "+&r"(err)
1252 if (MIPSInst_RT(inst) && !err)
1253 regs->regs[MIPSInst_RT(inst)] = rt;
1255 MIPS_R2_STATS(loads);
1260 rt = regs->regs[MIPSInst_RT(inst)];
1261 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1262 if (!access_ok(VERIFY_READ, vaddr, 4)) {
1263 current->thread.cp0_baduaddr = vaddr;
1267 __asm__ __volatile__(
1270 #ifdef CONFIG_CPU_LITTLE_ENDIAN
1271 "1:" LB "%1, 0(%2)\n"
1272 INS "%0, %1, 0, 8\n"
1274 " andi %1, %2, 0x3\n"
1276 "2:" LB "%1, 0(%2)\n"
1277 INS "%0, %1, 8, 8\n"
1279 " andi %1, %2, 0x3\n"
1281 "3:" LB "%1, 0(%2)\n"
1282 INS "%0, %1, 16, 8\n"
1284 " andi %1, %2, 0x3\n"
1286 "4:" LB "%1, 0(%2)\n"
1287 INS "%0, %1, 24, 8\n"
1289 #else /* !CONFIG_CPU_LITTLE_ENDIAN */
1290 "1:" LB "%1, 0(%2)\n"
1291 INS "%0, %1, 0, 8\n"
1292 " andi %1, %2, 0x3\n"
1294 ADDIU "%2, %2, -1\n"
1295 "2:" LB "%1, 0(%2)\n"
1296 INS "%0, %1, 8, 8\n"
1297 " andi %1, %2, 0x3\n"
1299 ADDIU "%2, %2, -1\n"
1300 "3:" LB "%1, 0(%2)\n"
1301 INS "%0, %1, 16, 8\n"
1302 " andi %1, %2, 0x3\n"
1304 ADDIU "%2, %2, -1\n"
1305 "4:" LB "%1, 0(%2)\n"
1306 INS "%0, %1, 24, 8\n"
1308 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
1312 " .section .fixup,\"ax\"\n"
1316 " .section __ex_table,\"a\"\n"
1323 : "+&r"(rt), "=&r"(rs),
1324 "+&r"(vaddr), "+&r"(err)
1326 if (MIPSInst_RT(inst) && !err)
1327 regs->regs[MIPSInst_RT(inst)] = rt;
1329 MIPS_R2_STATS(loads);
1334 rt = regs->regs[MIPSInst_RT(inst)];
1335 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1336 if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
1337 current->thread.cp0_baduaddr = vaddr;
1341 __asm__ __volatile__(
1344 #ifdef CONFIG_CPU_LITTLE_ENDIAN
1345 EXT "%1, %0, 24, 8\n"
1346 "1:" SB "%1, 0(%2)\n"
1347 " andi %1, %2, 0x3\n"
1349 ADDIU "%2, %2, -1\n"
1350 EXT "%1, %0, 16, 8\n"
1351 "2:" SB "%1, 0(%2)\n"
1352 " andi %1, %2, 0x3\n"
1354 ADDIU "%2, %2, -1\n"
1355 EXT "%1, %0, 8, 8\n"
1356 "3:" SB "%1, 0(%2)\n"
1357 " andi %1, %2, 0x3\n"
1359 ADDIU "%2, %2, -1\n"
1360 EXT "%1, %0, 0, 8\n"
1361 "4:" SB "%1, 0(%2)\n"
1362 #else /* !CONFIG_CPU_LITTLE_ENDIAN */
1363 EXT "%1, %0, 24, 8\n"
1364 "1:" SB "%1, 0(%2)\n"
1366 " andi %1, %2, 0x3\n"
1368 EXT "%1, %0, 16, 8\n"
1369 "2:" SB "%1, 0(%2)\n"
1371 " andi %1, %2, 0x3\n"
1373 EXT "%1, %0, 8, 8\n"
1374 "3:" SB "%1, 0(%2)\n"
1376 " andi %1, %2, 0x3\n"
1378 EXT "%1, %0, 0, 8\n"
1379 "4:" SB "%1, 0(%2)\n"
1380 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
1383 " .section .fixup,\"ax\"\n"
1387 " .section __ex_table,\"a\"\n"
1394 : "+&r"(rt), "=&r"(rs),
1395 "+&r"(vaddr), "+&r"(err)
1399 MIPS_R2_STATS(stores);
1404 rt = regs->regs[MIPSInst_RT(inst)];
1405 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1406 if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
1407 current->thread.cp0_baduaddr = vaddr;
1411 __asm__ __volatile__(
1414 #ifdef CONFIG_CPU_LITTLE_ENDIAN
1415 EXT "%1, %0, 0, 8\n"
1416 "1:" SB "%1, 0(%2)\n"
1418 " andi %1, %2, 0x3\n"
1420 EXT "%1, %0, 8, 8\n"
1421 "2:" SB "%1, 0(%2)\n"
1423 " andi %1, %2, 0x3\n"
1425 EXT "%1, %0, 16, 8\n"
1426 "3:" SB "%1, 0(%2)\n"
1428 " andi %1, %2, 0x3\n"
1430 EXT "%1, %0, 24, 8\n"
1431 "4:" SB "%1, 0(%2)\n"
1432 #else /* !CONFIG_CPU_LITTLE_ENDIAN */
1433 EXT "%1, %0, 0, 8\n"
1434 "1:" SB "%1, 0(%2)\n"
1435 " andi %1, %2, 0x3\n"
1437 ADDIU "%2, %2, -1\n"
1438 EXT "%1, %0, 8, 8\n"
1439 "2:" SB "%1, 0(%2)\n"
1440 " andi %1, %2, 0x3\n"
1442 ADDIU "%2, %2, -1\n"
1443 EXT "%1, %0, 16, 8\n"
1444 "3:" SB "%1, 0(%2)\n"
1445 " andi %1, %2, 0x3\n"
1447 ADDIU "%2, %2, -1\n"
1448 EXT "%1, %0, 24, 8\n"
1449 "4:" SB "%1, 0(%2)\n"
1450 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
1453 " .section .fixup,\"ax\"\n"
1457 " .section __ex_table,\"a\"\n"
1464 : "+&r"(rt), "=&r"(rs),
1465 "+&r"(vaddr), "+&r"(err)
1469 MIPS_R2_STATS(stores);
1474 if (config_enabled(CONFIG_32BIT)) {
1479 rt = regs->regs[MIPSInst_RT(inst)];
1480 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1481 if (!access_ok(VERIFY_READ, vaddr, 8)) {
1482 current->thread.cp0_baduaddr = vaddr;
1486 __asm__ __volatile__(
1489 #ifdef CONFIG_CPU_LITTLE_ENDIAN
1491 " dinsu %0, %1, 56, 8\n"
1492 " andi %1, %2, 0x7\n"
1494 " daddiu %2, %2, -1\n"
1496 " dinsu %0, %1, 48, 8\n"
1497 " andi %1, %2, 0x7\n"
1499 " daddiu %2, %2, -1\n"
1501 " dinsu %0, %1, 40, 8\n"
1502 " andi %1, %2, 0x7\n"
1504 " daddiu %2, %2, -1\n"
1506 " dinsu %0, %1, 32, 8\n"
1507 " andi %1, %2, 0x7\n"
1509 " daddiu %2, %2, -1\n"
1511 " dins %0, %1, 24, 8\n"
1512 " andi %1, %2, 0x7\n"
1514 " daddiu %2, %2, -1\n"
1516 " dins %0, %1, 16, 8\n"
1517 " andi %1, %2, 0x7\n"
1519 " daddiu %2, %2, -1\n"
1521 " dins %0, %1, 8, 8\n"
1522 " andi %1, %2, 0x7\n"
1524 " daddiu %2, %2, -1\n"
1526 " dins %0, %1, 0, 8\n"
1527 #else /* !CONFIG_CPU_LITTLE_ENDIAN */
1529 " dinsu %0, %1, 56, 8\n"
1530 " daddiu %2, %2, 1\n"
1531 " andi %1, %2, 0x7\n"
1534 " dinsu %0, %1, 48, 8\n"
1535 " daddiu %2, %2, 1\n"
1536 " andi %1, %2, 0x7\n"
1539 " dinsu %0, %1, 40, 8\n"
1540 " daddiu %2, %2, 1\n"
1541 " andi %1, %2, 0x7\n"
1544 " dinsu %0, %1, 32, 8\n"
1545 " daddiu %2, %2, 1\n"
1546 " andi %1, %2, 0x7\n"
1549 " dins %0, %1, 24, 8\n"
1550 " daddiu %2, %2, 1\n"
1551 " andi %1, %2, 0x7\n"
1554 " dins %0, %1, 16, 8\n"
1555 " daddiu %2, %2, 1\n"
1556 " andi %1, %2, 0x7\n"
1559 " dins %0, %1, 8, 8\n"
1560 " daddiu %2, %2, 1\n"
1561 " andi %1, %2, 0x7\n"
1564 " dins %0, %1, 0, 8\n"
1565 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
1568 " .section .fixup,\"ax\"\n"
1572 " .section __ex_table,\"a\"\n"
1583 : "+&r"(rt), "=&r"(rs),
1584 "+&r"(vaddr), "+&r"(err)
1586 if (MIPSInst_RT(inst) && !err)
1587 regs->regs[MIPSInst_RT(inst)] = rt;
1589 MIPS_R2_STATS(loads);
1593 if (config_enabled(CONFIG_32BIT)) {
1598 rt = regs->regs[MIPSInst_RT(inst)];
1599 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1600 if (!access_ok(VERIFY_READ, vaddr, 8)) {
1601 current->thread.cp0_baduaddr = vaddr;
1605 __asm__ __volatile__(
1608 #ifdef CONFIG_CPU_LITTLE_ENDIAN
1610 " dins %0, %1, 0, 8\n"
1611 " daddiu %2, %2, 1\n"
1612 " andi %1, %2, 0x7\n"
1615 " dins %0, %1, 8, 8\n"
1616 " daddiu %2, %2, 1\n"
1617 " andi %1, %2, 0x7\n"
1620 " dins %0, %1, 16, 8\n"
1621 " daddiu %2, %2, 1\n"
1622 " andi %1, %2, 0x7\n"
1625 " dins %0, %1, 24, 8\n"
1626 " daddiu %2, %2, 1\n"
1627 " andi %1, %2, 0x7\n"
1630 " dinsu %0, %1, 32, 8\n"
1631 " daddiu %2, %2, 1\n"
1632 " andi %1, %2, 0x7\n"
1635 " dinsu %0, %1, 40, 8\n"
1636 " daddiu %2, %2, 1\n"
1637 " andi %1, %2, 0x7\n"
1640 " dinsu %0, %1, 48, 8\n"
1641 " daddiu %2, %2, 1\n"
1642 " andi %1, %2, 0x7\n"
1645 " dinsu %0, %1, 56, 8\n"
1646 #else /* !CONFIG_CPU_LITTLE_ENDIAN */
1648 " dins %0, %1, 0, 8\n"
1649 " andi %1, %2, 0x7\n"
1651 " daddiu %2, %2, -1\n"
1653 " dins %0, %1, 8, 8\n"
1654 " andi %1, %2, 0x7\n"
1656 " daddiu %2, %2, -1\n"
1658 " dins %0, %1, 16, 8\n"
1659 " andi %1, %2, 0x7\n"
1661 " daddiu %2, %2, -1\n"
1663 " dins %0, %1, 24, 8\n"
1664 " andi %1, %2, 0x7\n"
1666 " daddiu %2, %2, -1\n"
1668 " dinsu %0, %1, 32, 8\n"
1669 " andi %1, %2, 0x7\n"
1671 " daddiu %2, %2, -1\n"
1673 " dinsu %0, %1, 40, 8\n"
1674 " andi %1, %2, 0x7\n"
1676 " daddiu %2, %2, -1\n"
1678 " dinsu %0, %1, 48, 8\n"
1679 " andi %1, %2, 0x7\n"
1681 " daddiu %2, %2, -1\n"
1683 " dinsu %0, %1, 56, 8\n"
1684 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
1687 " .section .fixup,\"ax\"\n"
1691 " .section __ex_table,\"a\"\n"
1702 : "+&r"(rt), "=&r"(rs),
1703 "+&r"(vaddr), "+&r"(err)
1705 if (MIPSInst_RT(inst) && !err)
1706 regs->regs[MIPSInst_RT(inst)] = rt;
1708 MIPS_R2_STATS(loads);
1712 if (config_enabled(CONFIG_32BIT)) {
1717 rt = regs->regs[MIPSInst_RT(inst)];
1718 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1719 if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
1720 current->thread.cp0_baduaddr = vaddr;
1724 __asm__ __volatile__(
1727 #ifdef CONFIG_CPU_LITTLE_ENDIAN
1728 " dextu %1, %0, 56, 8\n"
1730 " andi %1, %2, 0x7\n"
1732 " daddiu %2, %2, -1\n"
1733 " dextu %1, %0, 48, 8\n"
1735 " andi %1, %2, 0x7\n"
1737 " daddiu %2, %2, -1\n"
1738 " dextu %1, %0, 40, 8\n"
1740 " andi %1, %2, 0x7\n"
1742 " daddiu %2, %2, -1\n"
1743 " dextu %1, %0, 32, 8\n"
1745 " andi %1, %2, 0x7\n"
1747 " daddiu %2, %2, -1\n"
1748 " dext %1, %0, 24, 8\n"
1750 " andi %1, %2, 0x7\n"
1752 " daddiu %2, %2, -1\n"
1753 " dext %1, %0, 16, 8\n"
1755 " andi %1, %2, 0x7\n"
1757 " daddiu %2, %2, -1\n"
1758 " dext %1, %0, 8, 8\n"
1760 " andi %1, %2, 0x7\n"
1762 " daddiu %2, %2, -1\n"
1763 " dext %1, %0, 0, 8\n"
1765 #else /* !CONFIG_CPU_LITTLE_ENDIAN */
1766 " dextu %1, %0, 56, 8\n"
1768 " daddiu %2, %2, 1\n"
1769 " andi %1, %2, 0x7\n"
1771 " dextu %1, %0, 48, 8\n"
1773 " daddiu %2, %2, 1\n"
1774 " andi %1, %2, 0x7\n"
1776 " dextu %1, %0, 40, 8\n"
1778 " daddiu %2, %2, 1\n"
1779 " andi %1, %2, 0x7\n"
1781 " dextu %1, %0, 32, 8\n"
1783 " daddiu %2, %2, 1\n"
1784 " andi %1, %2, 0x7\n"
1786 " dext %1, %0, 24, 8\n"
1788 " daddiu %2, %2, 1\n"
1789 " andi %1, %2, 0x7\n"
1791 " dext %1, %0, 16, 8\n"
1793 " daddiu %2, %2, 1\n"
1794 " andi %1, %2, 0x7\n"
1796 " dext %1, %0, 8, 8\n"
1798 " daddiu %2, %2, 1\n"
1799 " andi %1, %2, 0x7\n"
1801 " dext %1, %0, 0, 8\n"
1803 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
1806 " .section .fixup,\"ax\"\n"
1810 " .section __ex_table,\"a\"\n"
1821 : "+&r"(rt), "=&r"(rs),
1822 "+&r"(vaddr), "+&r"(err)
1826 MIPS_R2_STATS(stores);
1830 if (config_enabled(CONFIG_32BIT)) {
1835 rt = regs->regs[MIPSInst_RT(inst)];
1836 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1837 if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
1838 current->thread.cp0_baduaddr = vaddr;
1842 __asm__ __volatile__(
1845 #ifdef CONFIG_CPU_LITTLE_ENDIAN
1846 " dext %1, %0, 0, 8\n"
1848 " daddiu %2, %2, 1\n"
1849 " andi %1, %2, 0x7\n"
1851 " dext %1, %0, 8, 8\n"
1853 " daddiu %2, %2, 1\n"
1854 " andi %1, %2, 0x7\n"
1856 " dext %1, %0, 16, 8\n"
1858 " daddiu %2, %2, 1\n"
1859 " andi %1, %2, 0x7\n"
1861 " dext %1, %0, 24, 8\n"
1863 " daddiu %2, %2, 1\n"
1864 " andi %1, %2, 0x7\n"
1866 " dextu %1, %0, 32, 8\n"
1868 " daddiu %2, %2, 1\n"
1869 " andi %1, %2, 0x7\n"
1871 " dextu %1, %0, 40, 8\n"
1873 " daddiu %2, %2, 1\n"
1874 " andi %1, %2, 0x7\n"
1876 " dextu %1, %0, 48, 8\n"
1878 " daddiu %2, %2, 1\n"
1879 " andi %1, %2, 0x7\n"
1881 " dextu %1, %0, 56, 8\n"
1883 #else /* !CONFIG_CPU_LITTLE_ENDIAN */
1884 " dext %1, %0, 0, 8\n"
1886 " andi %1, %2, 0x7\n"
1888 " daddiu %2, %2, -1\n"
1889 " dext %1, %0, 8, 8\n"
1891 " andi %1, %2, 0x7\n"
1893 " daddiu %2, %2, -1\n"
1894 " dext %1, %0, 16, 8\n"
1896 " andi %1, %2, 0x7\n"
1898 " daddiu %2, %2, -1\n"
1899 " dext %1, %0, 24, 8\n"
1901 " andi %1, %2, 0x7\n"
1903 " daddiu %2, %2, -1\n"
1904 " dextu %1, %0, 32, 8\n"
1906 " andi %1, %2, 0x7\n"
1908 " daddiu %2, %2, -1\n"
1909 " dextu %1, %0, 40, 8\n"
1911 " andi %1, %2, 0x7\n"
1913 " daddiu %2, %2, -1\n"
1914 " dextu %1, %0, 48, 8\n"
1916 " andi %1, %2, 0x7\n"
1918 " daddiu %2, %2, -1\n"
1919 " dextu %1, %0, 56, 8\n"
1921 #endif /* CONFIG_CPU_LITTLE_ENDIAN */
1924 " .section .fixup,\"ax\"\n"
1928 " .section __ex_table,\"a\"\n"
1939 : "+&r"(rt), "=&r"(rs),
1940 "+&r"(vaddr), "+&r"(err)
1944 MIPS_R2_STATS(stores);
1948 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
1950 current->thread.cp0_baduaddr = vaddr;
1954 if (!access_ok(VERIFY_READ, vaddr, 4)) {
1955 current->thread.cp0_baduaddr = vaddr;
1960 if (!cpu_has_rw_llb) {
1962 * An LL/SC block can't be safely emulated without
1963 * a Config5/LLB availability. So it's probably time to
1964 * kill our process before things get any worse. This is
1965 * because Config5/LLB allows us to use ERETNC so that
1966 * the LLAddr/LLB bit is not cleared when we return from
1967 * an exception. MIPS R2 LL/SC instructions trap with an
1968 * RI exception so once we emulate them here, we return
1969 * back to userland with ERETNC. That preserves the
1970 * LLAddr/LLB so the subsequent SC instruction will
1971 * succeed preserving the atomic semantics of the LL/SC
1972 * block. Without that, there is no safe way to emulate
1973 * an LL/SC block in MIPSR2 userland.
1975 pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
1980 __asm__ __volatile__(
1985 ".section .fixup,\"ax\"\n"
1990 ".section __ex_table,\"a\"\n"
1993 : "=&r"(res), "+&r"(err)
1994 : "r"(vaddr), "i"(SIGSEGV)
1997 if (MIPSInst_RT(inst) && !err)
1998 regs->regs[MIPSInst_RT(inst)] = res;
1999 MIPS_R2_STATS(llsc);
2004 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
2006 current->thread.cp0_baduaddr = vaddr;
2010 if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
2011 current->thread.cp0_baduaddr = vaddr;
2016 if (!cpu_has_rw_llb) {
2018 * An LL/SC block can't be safely emulated without
2019 * a Config5/LLB availability. So it's probably time to
2020 * kill our process before things get any worse. This is
2021 * because Config5/LLB allows us to use ERETNC so that
2022 * the LLAddr/LLB bit is not cleared when we return from
2023 * an exception. MIPS R2 LL/SC instructions trap with an
2024 * RI exception so once we emulate them here, we return
2025 * back to userland with ERETNC. That preserves the
2026 * LLAddr/LLB so the subsequent SC instruction will
2027 * succeed preserving the atomic semantics of the LL/SC
2028 * block. Without that, there is no safe way to emulate
2029 * an LL/SC block in MIPSR2 userland.
2031 pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
2036 res = regs->regs[MIPSInst_RT(inst)];
2038 __asm__ __volatile__(
2043 ".section .fixup,\"ax\"\n"
2048 ".section __ex_table,\"a\"\n"
2051 : "+&r"(res), "+&r"(err)
2052 : "r"(vaddr), "i"(SIGSEGV));
2054 if (MIPSInst_RT(inst) && !err)
2055 regs->regs[MIPSInst_RT(inst)] = res;
2057 MIPS_R2_STATS(llsc);
2062 if (config_enabled(CONFIG_32BIT)) {
2067 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
2069 current->thread.cp0_baduaddr = vaddr;
2073 if (!access_ok(VERIFY_READ, vaddr, 8)) {
2074 current->thread.cp0_baduaddr = vaddr;
2079 if (!cpu_has_rw_llb) {
2081 * An LL/SC block can't be safely emulated without
2082 * a Config5/LLB availability. So it's probably time to
2083 * kill our process before things get any worse. This is
2084 * because Config5/LLB allows us to use ERETNC so that
2085 * the LLAddr/LLB bit is not cleared when we return from
2086 * an exception. MIPS R2 LL/SC instructions trap with an
2087 * RI exception so once we emulate them here, we return
2088 * back to userland with ERETNC. That preserves the
2089 * LLAddr/LLB so the subsequent SC instruction will
2090 * succeed preserving the atomic semantics of the LL/SC
2091 * block. Without that, there is no safe way to emulate
2092 * an LL/SC block in MIPSR2 userland.
2094 pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
2099 __asm__ __volatile__(
2104 ".section .fixup,\"ax\"\n"
2109 ".section __ex_table,\"a\"\n"
2112 : "=&r"(res), "+&r"(err)
2113 : "r"(vaddr), "i"(SIGSEGV)
2115 if (MIPSInst_RT(inst) && !err)
2116 regs->regs[MIPSInst_RT(inst)] = res;
2118 MIPS_R2_STATS(llsc);
2123 if (config_enabled(CONFIG_32BIT)) {
2128 vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
2130 current->thread.cp0_baduaddr = vaddr;
2134 if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
2135 current->thread.cp0_baduaddr = vaddr;
2140 if (!cpu_has_rw_llb) {
2142 * An LL/SC block can't be safely emulated without
2143 * a Config5/LLB availability. So it's probably time to
2144 * kill our process before things get any worse. This is
2145 * because Config5/LLB allows us to use ERETNC so that
2146 * the LLAddr/LLB bit is not cleared when we return from
2147 * an exception. MIPS R2 LL/SC instructions trap with an
2148 * RI exception so once we emulate them here, we return
2149 * back to userland with ERETNC. That preserves the
2150 * LLAddr/LLB so the subsequent SC instruction will
2151 * succeed preserving the atomic semantics of the LL/SC
2152 * block. Without that, there is no safe way to emulate
2153 * an LL/SC block in MIPSR2 userland.
2155 pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
2160 res = regs->regs[MIPSInst_RT(inst)];
2162 __asm__ __volatile__(
2167 ".section .fixup,\"ax\"\n"
2172 ".section __ex_table,\"a\"\n"
2175 : "+&r"(res), "+&r"(err)
2176 : "r"(vaddr), "i"(SIGSEGV));
2178 if (MIPSInst_RT(inst) && !err)
2179 regs->regs[MIPSInst_RT(inst)] = res;
2181 MIPS_R2_STATS(llsc);
2192 * Lets not return to userland just yet. It's constly and
2193 * it's likely we have more R2 instructions to emulate
2195 if (!err && (pass++ < MIPS_R2_EMUL_TOTAL_PASS)) {
2196 regs->cp0_cause &= ~CAUSEF_BD;
2197 err = get_user(inst, (u32 __user *)regs->cp0_epc);
2205 if (err && (err != SIGEMT)) {
2206 regs->regs[31] = r31;
2207 regs->cp0_epc = epc;
2210 /* Likely a MIPS R6 compatible instruction */
2211 if (pass && (err == SIGILL))
2217 #ifdef CONFIG_DEBUG_FS
2219 static int mipsr2_stats_show(struct seq_file *s, void *unused)
2222 seq_printf(s, "Instruction\tTotal\tBDslot\n------------------------------\n");
2223 seq_printf(s, "movs\t\t%ld\t%ld\n",
2224 (unsigned long)__this_cpu_read(mipsr2emustats.movs),
2225 (unsigned long)__this_cpu_read(mipsr2bdemustats.movs));
2226 seq_printf(s, "hilo\t\t%ld\t%ld\n",
2227 (unsigned long)__this_cpu_read(mipsr2emustats.hilo),
2228 (unsigned long)__this_cpu_read(mipsr2bdemustats.hilo));
2229 seq_printf(s, "muls\t\t%ld\t%ld\n",
2230 (unsigned long)__this_cpu_read(mipsr2emustats.muls),
2231 (unsigned long)__this_cpu_read(mipsr2bdemustats.muls));
2232 seq_printf(s, "divs\t\t%ld\t%ld\n",
2233 (unsigned long)__this_cpu_read(mipsr2emustats.divs),
2234 (unsigned long)__this_cpu_read(mipsr2bdemustats.divs));
2235 seq_printf(s, "dsps\t\t%ld\t%ld\n",
2236 (unsigned long)__this_cpu_read(mipsr2emustats.dsps),
2237 (unsigned long)__this_cpu_read(mipsr2bdemustats.dsps));
2238 seq_printf(s, "bops\t\t%ld\t%ld\n",
2239 (unsigned long)__this_cpu_read(mipsr2emustats.bops),
2240 (unsigned long)__this_cpu_read(mipsr2bdemustats.bops));
2241 seq_printf(s, "traps\t\t%ld\t%ld\n",
2242 (unsigned long)__this_cpu_read(mipsr2emustats.traps),
2243 (unsigned long)__this_cpu_read(mipsr2bdemustats.traps));
2244 seq_printf(s, "fpus\t\t%ld\t%ld\n",
2245 (unsigned long)__this_cpu_read(mipsr2emustats.fpus),
2246 (unsigned long)__this_cpu_read(mipsr2bdemustats.fpus));
2247 seq_printf(s, "loads\t\t%ld\t%ld\n",
2248 (unsigned long)__this_cpu_read(mipsr2emustats.loads),
2249 (unsigned long)__this_cpu_read(mipsr2bdemustats.loads));
2250 seq_printf(s, "stores\t\t%ld\t%ld\n",
2251 (unsigned long)__this_cpu_read(mipsr2emustats.stores),
2252 (unsigned long)__this_cpu_read(mipsr2bdemustats.stores));
2253 seq_printf(s, "llsc\t\t%ld\t%ld\n",
2254 (unsigned long)__this_cpu_read(mipsr2emustats.llsc),
2255 (unsigned long)__this_cpu_read(mipsr2bdemustats.llsc));
2256 seq_printf(s, "dsemul\t\t%ld\t%ld\n",
2257 (unsigned long)__this_cpu_read(mipsr2emustats.dsemul),
2258 (unsigned long)__this_cpu_read(mipsr2bdemustats.dsemul));
2259 seq_printf(s, "jr\t\t%ld\n",
2260 (unsigned long)__this_cpu_read(mipsr2bremustats.jrs));
2261 seq_printf(s, "bltzl\t\t%ld\n",
2262 (unsigned long)__this_cpu_read(mipsr2bremustats.bltzl));
2263 seq_printf(s, "bgezl\t\t%ld\n",
2264 (unsigned long)__this_cpu_read(mipsr2bremustats.bgezl));
2265 seq_printf(s, "bltzll\t\t%ld\n",
2266 (unsigned long)__this_cpu_read(mipsr2bremustats.bltzll));
2267 seq_printf(s, "bgezll\t\t%ld\n",
2268 (unsigned long)__this_cpu_read(mipsr2bremustats.bgezll));
2269 seq_printf(s, "bltzal\t\t%ld\n",
2270 (unsigned long)__this_cpu_read(mipsr2bremustats.bltzal));
2271 seq_printf(s, "bgezal\t\t%ld\n",
2272 (unsigned long)__this_cpu_read(mipsr2bremustats.bgezal));
2273 seq_printf(s, "beql\t\t%ld\n",
2274 (unsigned long)__this_cpu_read(mipsr2bremustats.beql));
2275 seq_printf(s, "bnel\t\t%ld\n",
2276 (unsigned long)__this_cpu_read(mipsr2bremustats.bnel));
2277 seq_printf(s, "blezl\t\t%ld\n",
2278 (unsigned long)__this_cpu_read(mipsr2bremustats.blezl));
2279 seq_printf(s, "bgtzl\t\t%ld\n",
2280 (unsigned long)__this_cpu_read(mipsr2bremustats.bgtzl));
2285 static int mipsr2_stats_clear_show(struct seq_file *s, void *unused)
2287 mipsr2_stats_show(s, unused);
2289 __this_cpu_write((mipsr2emustats).movs, 0);
2290 __this_cpu_write((mipsr2bdemustats).movs, 0);
2291 __this_cpu_write((mipsr2emustats).hilo, 0);
2292 __this_cpu_write((mipsr2bdemustats).hilo, 0);
2293 __this_cpu_write((mipsr2emustats).muls, 0);
2294 __this_cpu_write((mipsr2bdemustats).muls, 0);
2295 __this_cpu_write((mipsr2emustats).divs, 0);
2296 __this_cpu_write((mipsr2bdemustats).divs, 0);
2297 __this_cpu_write((mipsr2emustats).dsps, 0);
2298 __this_cpu_write((mipsr2bdemustats).dsps, 0);
2299 __this_cpu_write((mipsr2emustats).bops, 0);
2300 __this_cpu_write((mipsr2bdemustats).bops, 0);
2301 __this_cpu_write((mipsr2emustats).traps, 0);
2302 __this_cpu_write((mipsr2bdemustats).traps, 0);
2303 __this_cpu_write((mipsr2emustats).fpus, 0);
2304 __this_cpu_write((mipsr2bdemustats).fpus, 0);
2305 __this_cpu_write((mipsr2emustats).loads, 0);
2306 __this_cpu_write((mipsr2bdemustats).loads, 0);
2307 __this_cpu_write((mipsr2emustats).stores, 0);
2308 __this_cpu_write((mipsr2bdemustats).stores, 0);
2309 __this_cpu_write((mipsr2emustats).llsc, 0);
2310 __this_cpu_write((mipsr2bdemustats).llsc, 0);
2311 __this_cpu_write((mipsr2emustats).dsemul, 0);
2312 __this_cpu_write((mipsr2bdemustats).dsemul, 0);
2313 __this_cpu_write((mipsr2bremustats).jrs, 0);
2314 __this_cpu_write((mipsr2bremustats).bltzl, 0);
2315 __this_cpu_write((mipsr2bremustats).bgezl, 0);
2316 __this_cpu_write((mipsr2bremustats).bltzll, 0);
2317 __this_cpu_write((mipsr2bremustats).bgezll, 0);
2318 __this_cpu_write((mipsr2bremustats).bltzal, 0);
2319 __this_cpu_write((mipsr2bremustats).bgezal, 0);
2320 __this_cpu_write((mipsr2bremustats).beql, 0);
2321 __this_cpu_write((mipsr2bremustats).bnel, 0);
2322 __this_cpu_write((mipsr2bremustats).blezl, 0);
2323 __this_cpu_write((mipsr2bremustats).bgtzl, 0);
2328 static int mipsr2_stats_open(struct inode *inode, struct file *file)
2330 return single_open(file, mipsr2_stats_show, inode->i_private);
2333 static int mipsr2_stats_clear_open(struct inode *inode, struct file *file)
2335 return single_open(file, mipsr2_stats_clear_show, inode->i_private);
2338 static const struct file_operations mipsr2_emul_fops = {
2339 .open = mipsr2_stats_open,
2341 .llseek = seq_lseek,
2342 .release = single_release,
2345 static const struct file_operations mipsr2_clear_fops = {
2346 .open = mipsr2_stats_clear_open,
2348 .llseek = seq_lseek,
2349 .release = single_release,
2353 static int __init mipsr2_init_debugfs(void)
2355 extern struct dentry *mips_debugfs_dir;
2356 struct dentry *mipsr2_emul;
2358 if (!mips_debugfs_dir)
2361 mipsr2_emul = debugfs_create_file("r2_emul_stats", S_IRUGO,
2362 mips_debugfs_dir, NULL,
2367 mipsr2_emul = debugfs_create_file("r2_emul_stats_clear", S_IRUGO,
2368 mips_debugfs_dir, NULL,
2369 &mipsr2_clear_fops);
2376 device_initcall(mipsr2_init_debugfs);
2378 #endif /* CONFIG_DEBUG_FS */