mips-r2-to-r6-emul.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404
  1. /*
  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
  4. * for more details.
  5. *
  6. * Copyright (c) 2014 Imagination Technologies Ltd.
  7. * Author: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
  8. * Author: Markos Chandras <markos.chandras@imgtec.com>
  9. *
  10. * MIPS R2 user space instruction emulator for MIPS R6
  11. *
  12. */
  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/ptrace.h>
  19. #include <linux/seq_file.h>
  20. #include <asm/asm.h>
  21. #include <asm/branch.h>
  22. #include <asm/break.h>
  23. #include <asm/debug.h>
  24. #include <asm/fpu.h>
  25. #include <asm/fpu_emulator.h>
  26. #include <asm/inst.h>
  27. #include <asm/mips-r2-to-r6-emul.h>
  28. #include <asm/local.h>
  29. #include <asm/mipsregs.h>
  30. #include <asm/ptrace.h>
  31. #include <asm/uaccess.h>
  32. #ifdef CONFIG_64BIT
  33. #define ADDIU "daddiu "
  34. #define INS "dins "
  35. #define EXT "dext "
  36. #else
  37. #define ADDIU "addiu "
  38. #define INS "ins "
  39. #define EXT "ext "
  40. #endif /* CONFIG_64BIT */
  41. #define SB "sb "
  42. #define LB "lb "
  43. #define LL "ll "
  44. #define SC "sc "
  45. DEFINE_PER_CPU(struct mips_r2_emulator_stats, mipsr2emustats);
  46. DEFINE_PER_CPU(struct mips_r2_emulator_stats, mipsr2bdemustats);
  47. DEFINE_PER_CPU(struct mips_r2br_emulator_stats, mipsr2bremustats);
  48. extern const unsigned int fpucondbit[8];
  49. #define MIPS_R2_EMUL_TOTAL_PASS 10
  50. int mipsr2_emulation = 0;
  51. static int __init mipsr2emu_enable(char *s)
  52. {
  53. mipsr2_emulation = 1;
  54. pr_info("MIPS R2-to-R6 Emulator Enabled!");
  55. return 1;
  56. }
  57. __setup("mipsr2emu", mipsr2emu_enable);
  58. /**
  59. * mipsr6_emul - Emulate some frequent R2/R5/R6 instructions in delay slot
  60. * for performance instead of the traditional way of using a stack trampoline
  61. * which is rather slow.
  62. * @regs: Process register set
  63. * @ir: Instruction
  64. */
  65. static inline int mipsr6_emul(struct pt_regs *regs, u32 ir)
  66. {
  67. switch (MIPSInst_OPCODE(ir)) {
  68. case addiu_op:
  69. if (MIPSInst_RT(ir))
  70. regs->regs[MIPSInst_RT(ir)] =
  71. (s32)regs->regs[MIPSInst_RS(ir)] +
  72. (s32)MIPSInst_SIMM(ir);
  73. return 0;
  74. case daddiu_op:
  75. if (IS_ENABLED(CONFIG_32BIT))
  76. break;
  77. if (MIPSInst_RT(ir))
  78. regs->regs[MIPSInst_RT(ir)] =
  79. (s64)regs->regs[MIPSInst_RS(ir)] +
  80. (s64)MIPSInst_SIMM(ir);
  81. return 0;
  82. case lwc1_op:
  83. case swc1_op:
  84. case cop1_op:
  85. case cop1x_op:
  86. /* FPU instructions in delay slot */
  87. return -SIGFPE;
  88. case spec_op:
  89. switch (MIPSInst_FUNC(ir)) {
  90. case or_op:
  91. if (MIPSInst_RD(ir))
  92. regs->regs[MIPSInst_RD(ir)] =
  93. regs->regs[MIPSInst_RS(ir)] |
  94. regs->regs[MIPSInst_RT(ir)];
  95. return 0;
  96. case sll_op:
  97. if (MIPSInst_RS(ir))
  98. break;
  99. if (MIPSInst_RD(ir))
  100. regs->regs[MIPSInst_RD(ir)] =
  101. (s32)(((u32)regs->regs[MIPSInst_RT(ir)]) <<
  102. MIPSInst_FD(ir));
  103. return 0;
  104. case srl_op:
  105. if (MIPSInst_RS(ir))
  106. break;
  107. if (MIPSInst_RD(ir))
  108. regs->regs[MIPSInst_RD(ir)] =
  109. (s32)(((u32)regs->regs[MIPSInst_RT(ir)]) >>
  110. MIPSInst_FD(ir));
  111. return 0;
  112. case addu_op:
  113. if (MIPSInst_FD(ir))
  114. break;
  115. if (MIPSInst_RD(ir))
  116. regs->regs[MIPSInst_RD(ir)] =
  117. (s32)((u32)regs->regs[MIPSInst_RS(ir)] +
  118. (u32)regs->regs[MIPSInst_RT(ir)]);
  119. return 0;
  120. case subu_op:
  121. if (MIPSInst_FD(ir))
  122. break;
  123. if (MIPSInst_RD(ir))
  124. regs->regs[MIPSInst_RD(ir)] =
  125. (s32)((u32)regs->regs[MIPSInst_RS(ir)] -
  126. (u32)regs->regs[MIPSInst_RT(ir)]);
  127. return 0;
  128. case dsll_op:
  129. if (IS_ENABLED(CONFIG_32BIT) || MIPSInst_RS(ir))
  130. break;
  131. if (MIPSInst_RD(ir))
  132. regs->regs[MIPSInst_RD(ir)] =
  133. (s64)(((u64)regs->regs[MIPSInst_RT(ir)]) <<
  134. MIPSInst_FD(ir));
  135. return 0;
  136. case dsrl_op:
  137. if (IS_ENABLED(CONFIG_32BIT) || MIPSInst_RS(ir))
  138. break;
  139. if (MIPSInst_RD(ir))
  140. regs->regs[MIPSInst_RD(ir)] =
  141. (s64)(((u64)regs->regs[MIPSInst_RT(ir)]) >>
  142. MIPSInst_FD(ir));
  143. return 0;
  144. case daddu_op:
  145. if (IS_ENABLED(CONFIG_32BIT) || MIPSInst_FD(ir))
  146. break;
  147. if (MIPSInst_RD(ir))
  148. regs->regs[MIPSInst_RD(ir)] =
  149. (u64)regs->regs[MIPSInst_RS(ir)] +
  150. (u64)regs->regs[MIPSInst_RT(ir)];
  151. return 0;
  152. case dsubu_op:
  153. if (IS_ENABLED(CONFIG_32BIT) || MIPSInst_FD(ir))
  154. break;
  155. if (MIPSInst_RD(ir))
  156. regs->regs[MIPSInst_RD(ir)] =
  157. (s64)((u64)regs->regs[MIPSInst_RS(ir)] -
  158. (u64)regs->regs[MIPSInst_RT(ir)]);
  159. return 0;
  160. }
  161. break;
  162. default:
  163. pr_debug("No fastpath BD emulation for instruction 0x%08x (op: %02x)\n",
  164. ir, MIPSInst_OPCODE(ir));
  165. }
  166. return SIGILL;
  167. }
  168. /**
  169. * movf_func - Emulate a MOVF instruction
  170. * @regs: Process register set
  171. * @ir: Instruction
  172. *
  173. * Returns 0 since it always succeeds.
  174. */
  175. static int movf_func(struct pt_regs *regs, u32 ir)
  176. {
  177. u32 csr;
  178. u32 cond;
  179. csr = current->thread.fpu.fcr31;
  180. cond = fpucondbit[MIPSInst_RT(ir) >> 2];
  181. if (((csr & cond) == 0) && MIPSInst_RD(ir))
  182. regs->regs[MIPSInst_RD(ir)] = regs->regs[MIPSInst_RS(ir)];
  183. MIPS_R2_STATS(movs);
  184. return 0;
  185. }
  186. /**
  187. * movt_func - Emulate a MOVT instruction
  188. * @regs: Process register set
  189. * @ir: Instruction
  190. *
  191. * Returns 0 since it always succeeds.
  192. */
  193. static int movt_func(struct pt_regs *regs, u32 ir)
  194. {
  195. u32 csr;
  196. u32 cond;
  197. csr = current->thread.fpu.fcr31;
  198. cond = fpucondbit[MIPSInst_RT(ir) >> 2];
  199. if (((csr & cond) != 0) && MIPSInst_RD(ir))
  200. regs->regs[MIPSInst_RD(ir)] = regs->regs[MIPSInst_RS(ir)];
  201. MIPS_R2_STATS(movs);
  202. return 0;
  203. }
  204. /**
  205. * jr_func - Emulate a JR instruction.
  206. * @pt_regs: Process register set
  207. * @ir: Instruction
  208. *
  209. * Returns SIGILL if JR was in delay slot, SIGEMT if we
  210. * can't compute the EPC, SIGSEGV if we can't access the
  211. * userland instruction or 0 on success.
  212. */
  213. static int jr_func(struct pt_regs *regs, u32 ir)
  214. {
  215. int err;
  216. unsigned long cepc, epc, nepc;
  217. u32 nir;
  218. if (delay_slot(regs))
  219. return SIGILL;
  220. /* EPC after the RI/JR instruction */
  221. nepc = regs->cp0_epc;
  222. /* Roll back to the reserved R2 JR instruction */
  223. regs->cp0_epc -= 4;
  224. epc = regs->cp0_epc;
  225. err = __compute_return_epc(regs);
  226. if (err < 0)
  227. return SIGEMT;
  228. /* Computed EPC */
  229. cepc = regs->cp0_epc;
  230. /* Get DS instruction */
  231. err = __get_user(nir, (u32 __user *)nepc);
  232. if (err)
  233. return SIGSEGV;
  234. MIPS_R2BR_STATS(jrs);
  235. /* If nir == 0(NOP), then nothing else to do */
  236. if (nir) {
  237. /*
  238. * Negative err means FPU instruction in BD-slot,
  239. * Zero err means 'BD-slot emulation done'
  240. * For anything else we go back to trampoline emulation.
  241. */
  242. err = mipsr6_emul(regs, nir);
  243. if (err > 0) {
  244. regs->cp0_epc = nepc;
  245. err = mips_dsemul(regs, nir, epc, cepc);
  246. if (err == SIGILL)
  247. err = SIGEMT;
  248. MIPS_R2_STATS(dsemul);
  249. }
  250. }
  251. return err;
  252. }
  253. /**
  254. * movz_func - Emulate a MOVZ instruction
  255. * @regs: Process register set
  256. * @ir: Instruction
  257. *
  258. * Returns 0 since it always succeeds.
  259. */
  260. static int movz_func(struct pt_regs *regs, u32 ir)
  261. {
  262. if (((regs->regs[MIPSInst_RT(ir)]) == 0) && MIPSInst_RD(ir))
  263. regs->regs[MIPSInst_RD(ir)] = regs->regs[MIPSInst_RS(ir)];
  264. MIPS_R2_STATS(movs);
  265. return 0;
  266. }
  267. /**
  268. * movn_func - Emulate a MOVZ instruction
  269. * @regs: Process register set
  270. * @ir: Instruction
  271. *
  272. * Returns 0 since it always succeeds.
  273. */
  274. static int movn_func(struct pt_regs *regs, u32 ir)
  275. {
  276. if (((regs->regs[MIPSInst_RT(ir)]) != 0) && MIPSInst_RD(ir))
  277. regs->regs[MIPSInst_RD(ir)] = regs->regs[MIPSInst_RS(ir)];
  278. MIPS_R2_STATS(movs);
  279. return 0;
  280. }
  281. /**
  282. * mfhi_func - Emulate a MFHI instruction
  283. * @regs: Process register set
  284. * @ir: Instruction
  285. *
  286. * Returns 0 since it always succeeds.
  287. */
  288. static int mfhi_func(struct pt_regs *regs, u32 ir)
  289. {
  290. if (MIPSInst_RD(ir))
  291. regs->regs[MIPSInst_RD(ir)] = regs->hi;
  292. MIPS_R2_STATS(hilo);
  293. return 0;
  294. }
  295. /**
  296. * mthi_func - Emulate a MTHI instruction
  297. * @regs: Process register set
  298. * @ir: Instruction
  299. *
  300. * Returns 0 since it always succeeds.
  301. */
  302. static int mthi_func(struct pt_regs *regs, u32 ir)
  303. {
  304. regs->hi = regs->regs[MIPSInst_RS(ir)];
  305. MIPS_R2_STATS(hilo);
  306. return 0;
  307. }
  308. /**
  309. * mflo_func - Emulate a MFLO instruction
  310. * @regs: Process register set
  311. * @ir: Instruction
  312. *
  313. * Returns 0 since it always succeeds.
  314. */
  315. static int mflo_func(struct pt_regs *regs, u32 ir)
  316. {
  317. if (MIPSInst_RD(ir))
  318. regs->regs[MIPSInst_RD(ir)] = regs->lo;
  319. MIPS_R2_STATS(hilo);
  320. return 0;
  321. }
  322. /**
  323. * mtlo_func - Emulate a MTLO instruction
  324. * @regs: Process register set
  325. * @ir: Instruction
  326. *
  327. * Returns 0 since it always succeeds.
  328. */
  329. static int mtlo_func(struct pt_regs *regs, u32 ir)
  330. {
  331. regs->lo = regs->regs[MIPSInst_RS(ir)];
  332. MIPS_R2_STATS(hilo);
  333. return 0;
  334. }
  335. /**
  336. * mult_func - Emulate a MULT instruction
  337. * @regs: Process register set
  338. * @ir: Instruction
  339. *
  340. * Returns 0 since it always succeeds.
  341. */
  342. static int mult_func(struct pt_regs *regs, u32 ir)
  343. {
  344. s64 res;
  345. s32 rt, rs;
  346. rt = regs->regs[MIPSInst_RT(ir)];
  347. rs = regs->regs[MIPSInst_RS(ir)];
  348. res = (s64)rt * (s64)rs;
  349. rs = res;
  350. regs->lo = (s64)rs;
  351. rt = res >> 32;
  352. res = (s64)rt;
  353. regs->hi = res;
  354. MIPS_R2_STATS(muls);
  355. return 0;
  356. }
  357. /**
  358. * multu_func - Emulate a MULTU instruction
  359. * @regs: Process register set
  360. * @ir: Instruction
  361. *
  362. * Returns 0 since it always succeeds.
  363. */
  364. static int multu_func(struct pt_regs *regs, u32 ir)
  365. {
  366. u64 res;
  367. u32 rt, rs;
  368. rt = regs->regs[MIPSInst_RT(ir)];
  369. rs = regs->regs[MIPSInst_RS(ir)];
  370. res = (u64)rt * (u64)rs;
  371. rt = res;
  372. regs->lo = (s64)(s32)rt;
  373. regs->hi = (s64)(s32)(res >> 32);
  374. MIPS_R2_STATS(muls);
  375. return 0;
  376. }
  377. /**
  378. * div_func - Emulate a DIV instruction
  379. * @regs: Process register set
  380. * @ir: Instruction
  381. *
  382. * Returns 0 since it always succeeds.
  383. */
  384. static int div_func(struct pt_regs *regs, u32 ir)
  385. {
  386. s32 rt, rs;
  387. rt = regs->regs[MIPSInst_RT(ir)];
  388. rs = regs->regs[MIPSInst_RS(ir)];
  389. regs->lo = (s64)(rs / rt);
  390. regs->hi = (s64)(rs % rt);
  391. MIPS_R2_STATS(divs);
  392. return 0;
  393. }
  394. /**
  395. * divu_func - Emulate a DIVU instruction
  396. * @regs: Process register set
  397. * @ir: Instruction
  398. *
  399. * Returns 0 since it always succeeds.
  400. */
  401. static int divu_func(struct pt_regs *regs, u32 ir)
  402. {
  403. u32 rt, rs;
  404. rt = regs->regs[MIPSInst_RT(ir)];
  405. rs = regs->regs[MIPSInst_RS(ir)];
  406. regs->lo = (s64)(rs / rt);
  407. regs->hi = (s64)(rs % rt);
  408. MIPS_R2_STATS(divs);
  409. return 0;
  410. }
  411. /**
  412. * dmult_func - Emulate a DMULT instruction
  413. * @regs: Process register set
  414. * @ir: Instruction
  415. *
  416. * Returns 0 on success or SIGILL for 32-bit kernels.
  417. */
  418. static int dmult_func(struct pt_regs *regs, u32 ir)
  419. {
  420. s64 res;
  421. s64 rt, rs;
  422. if (IS_ENABLED(CONFIG_32BIT))
  423. return SIGILL;
  424. rt = regs->regs[MIPSInst_RT(ir)];
  425. rs = regs->regs[MIPSInst_RS(ir)];
  426. res = rt * rs;
  427. regs->lo = res;
  428. __asm__ __volatile__(
  429. "dmuh %0, %1, %2\t\n"
  430. : "=r"(res)
  431. : "r"(rt), "r"(rs));
  432. regs->hi = res;
  433. MIPS_R2_STATS(muls);
  434. return 0;
  435. }
  436. /**
  437. * dmultu_func - Emulate a DMULTU instruction
  438. * @regs: Process register set
  439. * @ir: Instruction
  440. *
  441. * Returns 0 on success or SIGILL for 32-bit kernels.
  442. */
  443. static int dmultu_func(struct pt_regs *regs, u32 ir)
  444. {
  445. u64 res;
  446. u64 rt, rs;
  447. if (IS_ENABLED(CONFIG_32BIT))
  448. return SIGILL;
  449. rt = regs->regs[MIPSInst_RT(ir)];
  450. rs = regs->regs[MIPSInst_RS(ir)];
  451. res = rt * rs;
  452. regs->lo = res;
  453. __asm__ __volatile__(
  454. "dmuhu %0, %1, %2\t\n"
  455. : "=r"(res)
  456. : "r"(rt), "r"(rs));
  457. regs->hi = res;
  458. MIPS_R2_STATS(muls);
  459. return 0;
  460. }
  461. /**
  462. * ddiv_func - Emulate a DDIV instruction
  463. * @regs: Process register set
  464. * @ir: Instruction
  465. *
  466. * Returns 0 on success or SIGILL for 32-bit kernels.
  467. */
  468. static int ddiv_func(struct pt_regs *regs, u32 ir)
  469. {
  470. s64 rt, rs;
  471. if (IS_ENABLED(CONFIG_32BIT))
  472. return SIGILL;
  473. rt = regs->regs[MIPSInst_RT(ir)];
  474. rs = regs->regs[MIPSInst_RS(ir)];
  475. regs->lo = rs / rt;
  476. regs->hi = rs % rt;
  477. MIPS_R2_STATS(divs);
  478. return 0;
  479. }
  480. /**
  481. * ddivu_func - Emulate a DDIVU instruction
  482. * @regs: Process register set
  483. * @ir: Instruction
  484. *
  485. * Returns 0 on success or SIGILL for 32-bit kernels.
  486. */
  487. static int ddivu_func(struct pt_regs *regs, u32 ir)
  488. {
  489. u64 rt, rs;
  490. if (IS_ENABLED(CONFIG_32BIT))
  491. return SIGILL;
  492. rt = regs->regs[MIPSInst_RT(ir)];
  493. rs = regs->regs[MIPSInst_RS(ir)];
  494. regs->lo = rs / rt;
  495. regs->hi = rs % rt;
  496. MIPS_R2_STATS(divs);
  497. return 0;
  498. }
  499. /* R6 removed instructions for the SPECIAL opcode */
  500. static struct r2_decoder_table spec_op_table[] = {
  501. { 0xfc1ff83f, 0x00000008, jr_func },
  502. { 0xfc00ffff, 0x00000018, mult_func },
  503. { 0xfc00ffff, 0x00000019, multu_func },
  504. { 0xfc00ffff, 0x0000001c, dmult_func },
  505. { 0xfc00ffff, 0x0000001d, dmultu_func },
  506. { 0xffff07ff, 0x00000010, mfhi_func },
  507. { 0xfc1fffff, 0x00000011, mthi_func },
  508. { 0xffff07ff, 0x00000012, mflo_func },
  509. { 0xfc1fffff, 0x00000013, mtlo_func },
  510. { 0xfc0307ff, 0x00000001, movf_func },
  511. { 0xfc0307ff, 0x00010001, movt_func },
  512. { 0xfc0007ff, 0x0000000a, movz_func },
  513. { 0xfc0007ff, 0x0000000b, movn_func },
  514. { 0xfc00ffff, 0x0000001a, div_func },
  515. { 0xfc00ffff, 0x0000001b, divu_func },
  516. { 0xfc00ffff, 0x0000001e, ddiv_func },
  517. { 0xfc00ffff, 0x0000001f, ddivu_func },
  518. {}
  519. };
  520. /**
  521. * madd_func - Emulate a MADD instruction
  522. * @regs: Process register set
  523. * @ir: Instruction
  524. *
  525. * Returns 0 since it always succeeds.
  526. */
  527. static int madd_func(struct pt_regs *regs, u32 ir)
  528. {
  529. s64 res;
  530. s32 rt, rs;
  531. rt = regs->regs[MIPSInst_RT(ir)];
  532. rs = regs->regs[MIPSInst_RS(ir)];
  533. res = (s64)rt * (s64)rs;
  534. rt = regs->hi;
  535. rs = regs->lo;
  536. res += ((((s64)rt) << 32) | (u32)rs);
  537. rt = res;
  538. regs->lo = (s64)rt;
  539. rs = res >> 32;
  540. regs->hi = (s64)rs;
  541. MIPS_R2_STATS(dsps);
  542. return 0;
  543. }
  544. /**
  545. * maddu_func - Emulate a MADDU instruction
  546. * @regs: Process register set
  547. * @ir: Instruction
  548. *
  549. * Returns 0 since it always succeeds.
  550. */
  551. static int maddu_func(struct pt_regs *regs, u32 ir)
  552. {
  553. u64 res;
  554. u32 rt, rs;
  555. rt = regs->regs[MIPSInst_RT(ir)];
  556. rs = regs->regs[MIPSInst_RS(ir)];
  557. res = (u64)rt * (u64)rs;
  558. rt = regs->hi;
  559. rs = regs->lo;
  560. res += ((((s64)rt) << 32) | (u32)rs);
  561. rt = res;
  562. regs->lo = (s64)(s32)rt;
  563. rs = res >> 32;
  564. regs->hi = (s64)(s32)rs;
  565. MIPS_R2_STATS(dsps);
  566. return 0;
  567. }
  568. /**
  569. * msub_func - Emulate a MSUB instruction
  570. * @regs: Process register set
  571. * @ir: Instruction
  572. *
  573. * Returns 0 since it always succeeds.
  574. */
  575. static int msub_func(struct pt_regs *regs, u32 ir)
  576. {
  577. s64 res;
  578. s32 rt, rs;
  579. rt = regs->regs[MIPSInst_RT(ir)];
  580. rs = regs->regs[MIPSInst_RS(ir)];
  581. res = (s64)rt * (s64)rs;
  582. rt = regs->hi;
  583. rs = regs->lo;
  584. res = ((((s64)rt) << 32) | (u32)rs) - res;
  585. rt = res;
  586. regs->lo = (s64)rt;
  587. rs = res >> 32;
  588. regs->hi = (s64)rs;
  589. MIPS_R2_STATS(dsps);
  590. return 0;
  591. }
  592. /**
  593. * msubu_func - Emulate a MSUBU instruction
  594. * @regs: Process register set
  595. * @ir: Instruction
  596. *
  597. * Returns 0 since it always succeeds.
  598. */
  599. static int msubu_func(struct pt_regs *regs, u32 ir)
  600. {
  601. u64 res;
  602. u32 rt, rs;
  603. rt = regs->regs[MIPSInst_RT(ir)];
  604. rs = regs->regs[MIPSInst_RS(ir)];
  605. res = (u64)rt * (u64)rs;
  606. rt = regs->hi;
  607. rs = regs->lo;
  608. res = ((((s64)rt) << 32) | (u32)rs) - res;
  609. rt = res;
  610. regs->lo = (s64)(s32)rt;
  611. rs = res >> 32;
  612. regs->hi = (s64)(s32)rs;
  613. MIPS_R2_STATS(dsps);
  614. return 0;
  615. }
  616. /**
  617. * mul_func - Emulate a MUL instruction
  618. * @regs: Process register set
  619. * @ir: Instruction
  620. *
  621. * Returns 0 since it always succeeds.
  622. */
  623. static int mul_func(struct pt_regs *regs, u32 ir)
  624. {
  625. s64 res;
  626. s32 rt, rs;
  627. if (!MIPSInst_RD(ir))
  628. return 0;
  629. rt = regs->regs[MIPSInst_RT(ir)];
  630. rs = regs->regs[MIPSInst_RS(ir)];
  631. res = (s64)rt * (s64)rs;
  632. rs = res;
  633. regs->regs[MIPSInst_RD(ir)] = (s64)rs;
  634. MIPS_R2_STATS(muls);
  635. return 0;
  636. }
  637. /**
  638. * clz_func - Emulate a CLZ instruction
  639. * @regs: Process register set
  640. * @ir: Instruction
  641. *
  642. * Returns 0 since it always succeeds.
  643. */
  644. static int clz_func(struct pt_regs *regs, u32 ir)
  645. {
  646. u32 res;
  647. u32 rs;
  648. if (!MIPSInst_RD(ir))
  649. return 0;
  650. rs = regs->regs[MIPSInst_RS(ir)];
  651. __asm__ __volatile__("clz %0, %1" : "=r"(res) : "r"(rs));
  652. regs->regs[MIPSInst_RD(ir)] = res;
  653. MIPS_R2_STATS(bops);
  654. return 0;
  655. }
  656. /**
  657. * clo_func - Emulate a CLO instruction
  658. * @regs: Process register set
  659. * @ir: Instruction
  660. *
  661. * Returns 0 since it always succeeds.
  662. */
  663. static int clo_func(struct pt_regs *regs, u32 ir)
  664. {
  665. u32 res;
  666. u32 rs;
  667. if (!MIPSInst_RD(ir))
  668. return 0;
  669. rs = regs->regs[MIPSInst_RS(ir)];
  670. __asm__ __volatile__("clo %0, %1" : "=r"(res) : "r"(rs));
  671. regs->regs[MIPSInst_RD(ir)] = res;
  672. MIPS_R2_STATS(bops);
  673. return 0;
  674. }
  675. /**
  676. * dclz_func - Emulate a DCLZ instruction
  677. * @regs: Process register set
  678. * @ir: Instruction
  679. *
  680. * Returns 0 since it always succeeds.
  681. */
  682. static int dclz_func(struct pt_regs *regs, u32 ir)
  683. {
  684. u64 res;
  685. u64 rs;
  686. if (IS_ENABLED(CONFIG_32BIT))
  687. return SIGILL;
  688. if (!MIPSInst_RD(ir))
  689. return 0;
  690. rs = regs->regs[MIPSInst_RS(ir)];
  691. __asm__ __volatile__("dclz %0, %1" : "=r"(res) : "r"(rs));
  692. regs->regs[MIPSInst_RD(ir)] = res;
  693. MIPS_R2_STATS(bops);
  694. return 0;
  695. }
  696. /**
  697. * dclo_func - Emulate a DCLO instruction
  698. * @regs: Process register set
  699. * @ir: Instruction
  700. *
  701. * Returns 0 since it always succeeds.
  702. */
  703. static int dclo_func(struct pt_regs *regs, u32 ir)
  704. {
  705. u64 res;
  706. u64 rs;
  707. if (IS_ENABLED(CONFIG_32BIT))
  708. return SIGILL;
  709. if (!MIPSInst_RD(ir))
  710. return 0;
  711. rs = regs->regs[MIPSInst_RS(ir)];
  712. __asm__ __volatile__("dclo %0, %1" : "=r"(res) : "r"(rs));
  713. regs->regs[MIPSInst_RD(ir)] = res;
  714. MIPS_R2_STATS(bops);
  715. return 0;
  716. }
  717. /* R6 removed instructions for the SPECIAL2 opcode */
  718. static struct r2_decoder_table spec2_op_table[] = {
  719. { 0xfc00ffff, 0x70000000, madd_func },
  720. { 0xfc00ffff, 0x70000001, maddu_func },
  721. { 0xfc0007ff, 0x70000002, mul_func },
  722. { 0xfc00ffff, 0x70000004, msub_func },
  723. { 0xfc00ffff, 0x70000005, msubu_func },
  724. { 0xfc0007ff, 0x70000020, clz_func },
  725. { 0xfc0007ff, 0x70000021, clo_func },
  726. { 0xfc0007ff, 0x70000024, dclz_func },
  727. { 0xfc0007ff, 0x70000025, dclo_func },
  728. { }
  729. };
  730. static inline int mipsr2_find_op_func(struct pt_regs *regs, u32 inst,
  731. struct r2_decoder_table *table)
  732. {
  733. struct r2_decoder_table *p;
  734. int err;
  735. for (p = table; p->func; p++) {
  736. if ((inst & p->mask) == p->code) {
  737. err = (p->func)(regs, inst);
  738. return err;
  739. }
  740. }
  741. return SIGILL;
  742. }
  743. /**
  744. * mipsr2_decoder: Decode and emulate a MIPS R2 instruction
  745. * @regs: Process register set
  746. * @inst: Instruction to decode and emulate
  747. * @fcr31: Floating Point Control and Status Register Cause bits returned
  748. */
  749. int mipsr2_decoder(struct pt_regs *regs, u32 inst, unsigned long *fcr31)
  750. {
  751. int err = 0;
  752. unsigned long vaddr;
  753. u32 nir;
  754. unsigned long cpc, epc, nepc, r31, res, rs, rt;
  755. void __user *fault_addr = NULL;
  756. int pass = 0;
  757. repeat:
  758. r31 = regs->regs[31];
  759. epc = regs->cp0_epc;
  760. err = compute_return_epc(regs);
  761. if (err < 0) {
  762. BUG();
  763. return SIGEMT;
  764. }
  765. pr_debug("Emulating the 0x%08x R2 instruction @ 0x%08lx (pass=%d))\n",
  766. inst, epc, pass);
  767. switch (MIPSInst_OPCODE(inst)) {
  768. case spec_op:
  769. err = mipsr2_find_op_func(regs, inst, spec_op_table);
  770. if (err < 0) {
  771. /* FPU instruction under JR */
  772. regs->cp0_cause |= CAUSEF_BD;
  773. goto fpu_emul;
  774. }
  775. break;
  776. case spec2_op:
  777. err = mipsr2_find_op_func(regs, inst, spec2_op_table);
  778. break;
  779. case bcond_op:
  780. rt = MIPSInst_RT(inst);
  781. rs = MIPSInst_RS(inst);
  782. switch (rt) {
  783. case tgei_op:
  784. if ((long)regs->regs[rs] >= MIPSInst_SIMM(inst))
  785. do_trap_or_bp(regs, 0, 0, "TGEI");
  786. MIPS_R2_STATS(traps);
  787. break;
  788. case tgeiu_op:
  789. if (regs->regs[rs] >= MIPSInst_UIMM(inst))
  790. do_trap_or_bp(regs, 0, 0, "TGEIU");
  791. MIPS_R2_STATS(traps);
  792. break;
  793. case tlti_op:
  794. if ((long)regs->regs[rs] < MIPSInst_SIMM(inst))
  795. do_trap_or_bp(regs, 0, 0, "TLTI");
  796. MIPS_R2_STATS(traps);
  797. break;
  798. case tltiu_op:
  799. if (regs->regs[rs] < MIPSInst_UIMM(inst))
  800. do_trap_or_bp(regs, 0, 0, "TLTIU");
  801. MIPS_R2_STATS(traps);
  802. break;
  803. case teqi_op:
  804. if (regs->regs[rs] == MIPSInst_SIMM(inst))
  805. do_trap_or_bp(regs, 0, 0, "TEQI");
  806. MIPS_R2_STATS(traps);
  807. break;
  808. case tnei_op:
  809. if (regs->regs[rs] != MIPSInst_SIMM(inst))
  810. do_trap_or_bp(regs, 0, 0, "TNEI");
  811. MIPS_R2_STATS(traps);
  812. break;
  813. case bltzl_op:
  814. case bgezl_op:
  815. case bltzall_op:
  816. case bgezall_op:
  817. if (delay_slot(regs)) {
  818. err = SIGILL;
  819. break;
  820. }
  821. regs->regs[31] = r31;
  822. regs->cp0_epc = epc;
  823. err = __compute_return_epc(regs);
  824. if (err < 0)
  825. return SIGEMT;
  826. if (err != BRANCH_LIKELY_TAKEN)
  827. break;
  828. cpc = regs->cp0_epc;
  829. nepc = epc + 4;
  830. err = __get_user(nir, (u32 __user *)nepc);
  831. if (err) {
  832. err = SIGSEGV;
  833. break;
  834. }
  835. /*
  836. * This will probably be optimized away when
  837. * CONFIG_DEBUG_FS is not enabled
  838. */
  839. switch (rt) {
  840. case bltzl_op:
  841. MIPS_R2BR_STATS(bltzl);
  842. break;
  843. case bgezl_op:
  844. MIPS_R2BR_STATS(bgezl);
  845. break;
  846. case bltzall_op:
  847. MIPS_R2BR_STATS(bltzall);
  848. break;
  849. case bgezall_op:
  850. MIPS_R2BR_STATS(bgezall);
  851. break;
  852. }
  853. switch (MIPSInst_OPCODE(nir)) {
  854. case cop1_op:
  855. case cop1x_op:
  856. case lwc1_op:
  857. case swc1_op:
  858. regs->cp0_cause |= CAUSEF_BD;
  859. goto fpu_emul;
  860. }
  861. if (nir) {
  862. err = mipsr6_emul(regs, nir);
  863. if (err > 0) {
  864. err = mips_dsemul(regs, nir, epc, cpc);
  865. if (err == SIGILL)
  866. err = SIGEMT;
  867. MIPS_R2_STATS(dsemul);
  868. }
  869. }
  870. break;
  871. case bltzal_op:
  872. case bgezal_op:
  873. if (delay_slot(regs)) {
  874. err = SIGILL;
  875. break;
  876. }
  877. regs->regs[31] = r31;
  878. regs->cp0_epc = epc;
  879. err = __compute_return_epc(regs);
  880. if (err < 0)
  881. return SIGEMT;
  882. cpc = regs->cp0_epc;
  883. nepc = epc + 4;
  884. err = __get_user(nir, (u32 __user *)nepc);
  885. if (err) {
  886. err = SIGSEGV;
  887. break;
  888. }
  889. /*
  890. * This will probably be optimized away when
  891. * CONFIG_DEBUG_FS is not enabled
  892. */
  893. switch (rt) {
  894. case bltzal_op:
  895. MIPS_R2BR_STATS(bltzal);
  896. break;
  897. case bgezal_op:
  898. MIPS_R2BR_STATS(bgezal);
  899. break;
  900. }
  901. switch (MIPSInst_OPCODE(nir)) {
  902. case cop1_op:
  903. case cop1x_op:
  904. case lwc1_op:
  905. case swc1_op:
  906. regs->cp0_cause |= CAUSEF_BD;
  907. goto fpu_emul;
  908. }
  909. if (nir) {
  910. err = mipsr6_emul(regs, nir);
  911. if (err > 0) {
  912. err = mips_dsemul(regs, nir, epc, cpc);
  913. if (err == SIGILL)
  914. err = SIGEMT;
  915. MIPS_R2_STATS(dsemul);
  916. }
  917. }
  918. break;
  919. default:
  920. regs->regs[31] = r31;
  921. regs->cp0_epc = epc;
  922. err = SIGILL;
  923. break;
  924. }
  925. break;
  926. case blezl_op:
  927. case bgtzl_op:
  928. /*
  929. * For BLEZL and BGTZL, rt field must be set to 0. If this
  930. * is not the case, this may be an encoding of a MIPS R6
  931. * instruction, so return to CPU execution if this occurs
  932. */
  933. if (MIPSInst_RT(inst)) {
  934. err = SIGILL;
  935. break;
  936. }
  937. /* fall through */
  938. case beql_op:
  939. case bnel_op:
  940. if (delay_slot(regs)) {
  941. err = SIGILL;
  942. break;
  943. }
  944. regs->regs[31] = r31;
  945. regs->cp0_epc = epc;
  946. err = __compute_return_epc(regs);
  947. if (err < 0)
  948. return SIGEMT;
  949. if (err != BRANCH_LIKELY_TAKEN)
  950. break;
  951. cpc = regs->cp0_epc;
  952. nepc = epc + 4;
  953. err = __get_user(nir, (u32 __user *)nepc);
  954. if (err) {
  955. err = SIGSEGV;
  956. break;
  957. }
  958. /*
  959. * This will probably be optimized away when
  960. * CONFIG_DEBUG_FS is not enabled
  961. */
  962. switch (MIPSInst_OPCODE(inst)) {
  963. case beql_op:
  964. MIPS_R2BR_STATS(beql);
  965. break;
  966. case bnel_op:
  967. MIPS_R2BR_STATS(bnel);
  968. break;
  969. case blezl_op:
  970. MIPS_R2BR_STATS(blezl);
  971. break;
  972. case bgtzl_op:
  973. MIPS_R2BR_STATS(bgtzl);
  974. break;
  975. }
  976. switch (MIPSInst_OPCODE(nir)) {
  977. case cop1_op:
  978. case cop1x_op:
  979. case lwc1_op:
  980. case swc1_op:
  981. regs->cp0_cause |= CAUSEF_BD;
  982. goto fpu_emul;
  983. }
  984. if (nir) {
  985. err = mipsr6_emul(regs, nir);
  986. if (err > 0) {
  987. err = mips_dsemul(regs, nir, epc, cpc);
  988. if (err == SIGILL)
  989. err = SIGEMT;
  990. MIPS_R2_STATS(dsemul);
  991. }
  992. }
  993. break;
  994. case lwc1_op:
  995. case swc1_op:
  996. case cop1_op:
  997. case cop1x_op:
  998. fpu_emul:
  999. regs->regs[31] = r31;
  1000. regs->cp0_epc = epc;
  1001. if (!used_math()) { /* First time FPU user. */
  1002. preempt_disable();
  1003. err = init_fpu();
  1004. preempt_enable();
  1005. set_used_math();
  1006. }
  1007. lose_fpu(1); /* Save FPU state for the emulator. */
  1008. err = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 0,
  1009. &fault_addr);
  1010. /*
  1011. * We can't allow the emulated instruction to leave any
  1012. * enabled Cause bits set in $fcr31.
  1013. */
  1014. *fcr31 = res = mask_fcr31_x(current->thread.fpu.fcr31);
  1015. current->thread.fpu.fcr31 &= ~res;
  1016. /*
  1017. * this is a tricky issue - lose_fpu() uses LL/SC atomics
  1018. * if FPU is owned and effectively cancels user level LL/SC.
  1019. * So, it could be logical to don't restore FPU ownership here.
  1020. * But the sequence of multiple FPU instructions is much much
  1021. * more often than LL-FPU-SC and I prefer loop here until
  1022. * next scheduler cycle cancels FPU ownership
  1023. */
  1024. own_fpu(1); /* Restore FPU state. */
  1025. if (err)
  1026. current->thread.cp0_baduaddr = (unsigned long)fault_addr;
  1027. MIPS_R2_STATS(fpus);
  1028. break;
  1029. case lwl_op:
  1030. rt = regs->regs[MIPSInst_RT(inst)];
  1031. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1032. if (!access_ok(VERIFY_READ, vaddr, 4)) {
  1033. current->thread.cp0_baduaddr = vaddr;
  1034. err = SIGSEGV;
  1035. break;
  1036. }
  1037. __asm__ __volatile__(
  1038. " .set push\n"
  1039. " .set reorder\n"
  1040. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1041. "1:" LB "%1, 0(%2)\n"
  1042. INS "%0, %1, 24, 8\n"
  1043. " andi %1, %2, 0x3\n"
  1044. " beq $0, %1, 9f\n"
  1045. ADDIU "%2, %2, -1\n"
  1046. "2:" LB "%1, 0(%2)\n"
  1047. INS "%0, %1, 16, 8\n"
  1048. " andi %1, %2, 0x3\n"
  1049. " beq $0, %1, 9f\n"
  1050. ADDIU "%2, %2, -1\n"
  1051. "3:" LB "%1, 0(%2)\n"
  1052. INS "%0, %1, 8, 8\n"
  1053. " andi %1, %2, 0x3\n"
  1054. " beq $0, %1, 9f\n"
  1055. ADDIU "%2, %2, -1\n"
  1056. "4:" LB "%1, 0(%2)\n"
  1057. INS "%0, %1, 0, 8\n"
  1058. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1059. "1:" LB "%1, 0(%2)\n"
  1060. INS "%0, %1, 24, 8\n"
  1061. ADDIU "%2, %2, 1\n"
  1062. " andi %1, %2, 0x3\n"
  1063. " beq $0, %1, 9f\n"
  1064. "2:" LB "%1, 0(%2)\n"
  1065. INS "%0, %1, 16, 8\n"
  1066. ADDIU "%2, %2, 1\n"
  1067. " andi %1, %2, 0x3\n"
  1068. " beq $0, %1, 9f\n"
  1069. "3:" LB "%1, 0(%2)\n"
  1070. INS "%0, %1, 8, 8\n"
  1071. ADDIU "%2, %2, 1\n"
  1072. " andi %1, %2, 0x3\n"
  1073. " beq $0, %1, 9f\n"
  1074. "4:" LB "%1, 0(%2)\n"
  1075. INS "%0, %1, 0, 8\n"
  1076. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1077. "9: sll %0, %0, 0\n"
  1078. "10:\n"
  1079. " .insn\n"
  1080. " .section .fixup,\"ax\"\n"
  1081. "8: li %3,%4\n"
  1082. " j 10b\n"
  1083. " .previous\n"
  1084. " .section __ex_table,\"a\"\n"
  1085. STR(PTR) " 1b,8b\n"
  1086. STR(PTR) " 2b,8b\n"
  1087. STR(PTR) " 3b,8b\n"
  1088. STR(PTR) " 4b,8b\n"
  1089. " .previous\n"
  1090. " .set pop\n"
  1091. : "+&r"(rt), "=&r"(rs),
  1092. "+&r"(vaddr), "+&r"(err)
  1093. : "i"(SIGSEGV));
  1094. if (MIPSInst_RT(inst) && !err)
  1095. regs->regs[MIPSInst_RT(inst)] = rt;
  1096. MIPS_R2_STATS(loads);
  1097. break;
  1098. case lwr_op:
  1099. rt = regs->regs[MIPSInst_RT(inst)];
  1100. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1101. if (!access_ok(VERIFY_READ, vaddr, 4)) {
  1102. current->thread.cp0_baduaddr = vaddr;
  1103. err = SIGSEGV;
  1104. break;
  1105. }
  1106. __asm__ __volatile__(
  1107. " .set push\n"
  1108. " .set reorder\n"
  1109. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1110. "1:" LB "%1, 0(%2)\n"
  1111. INS "%0, %1, 0, 8\n"
  1112. ADDIU "%2, %2, 1\n"
  1113. " andi %1, %2, 0x3\n"
  1114. " beq $0, %1, 9f\n"
  1115. "2:" LB "%1, 0(%2)\n"
  1116. INS "%0, %1, 8, 8\n"
  1117. ADDIU "%2, %2, 1\n"
  1118. " andi %1, %2, 0x3\n"
  1119. " beq $0, %1, 9f\n"
  1120. "3:" LB "%1, 0(%2)\n"
  1121. INS "%0, %1, 16, 8\n"
  1122. ADDIU "%2, %2, 1\n"
  1123. " andi %1, %2, 0x3\n"
  1124. " beq $0, %1, 9f\n"
  1125. "4:" LB "%1, 0(%2)\n"
  1126. INS "%0, %1, 24, 8\n"
  1127. " sll %0, %0, 0\n"
  1128. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1129. "1:" LB "%1, 0(%2)\n"
  1130. INS "%0, %1, 0, 8\n"
  1131. " andi %1, %2, 0x3\n"
  1132. " beq $0, %1, 9f\n"
  1133. ADDIU "%2, %2, -1\n"
  1134. "2:" LB "%1, 0(%2)\n"
  1135. INS "%0, %1, 8, 8\n"
  1136. " andi %1, %2, 0x3\n"
  1137. " beq $0, %1, 9f\n"
  1138. ADDIU "%2, %2, -1\n"
  1139. "3:" LB "%1, 0(%2)\n"
  1140. INS "%0, %1, 16, 8\n"
  1141. " andi %1, %2, 0x3\n"
  1142. " beq $0, %1, 9f\n"
  1143. ADDIU "%2, %2, -1\n"
  1144. "4:" LB "%1, 0(%2)\n"
  1145. INS "%0, %1, 24, 8\n"
  1146. " sll %0, %0, 0\n"
  1147. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1148. "9:\n"
  1149. "10:\n"
  1150. " .insn\n"
  1151. " .section .fixup,\"ax\"\n"
  1152. "8: li %3,%4\n"
  1153. " j 10b\n"
  1154. " .previous\n"
  1155. " .section __ex_table,\"a\"\n"
  1156. STR(PTR) " 1b,8b\n"
  1157. STR(PTR) " 2b,8b\n"
  1158. STR(PTR) " 3b,8b\n"
  1159. STR(PTR) " 4b,8b\n"
  1160. " .previous\n"
  1161. " .set pop\n"
  1162. : "+&r"(rt), "=&r"(rs),
  1163. "+&r"(vaddr), "+&r"(err)
  1164. : "i"(SIGSEGV));
  1165. if (MIPSInst_RT(inst) && !err)
  1166. regs->regs[MIPSInst_RT(inst)] = rt;
  1167. MIPS_R2_STATS(loads);
  1168. break;
  1169. case swl_op:
  1170. rt = regs->regs[MIPSInst_RT(inst)];
  1171. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1172. if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
  1173. current->thread.cp0_baduaddr = vaddr;
  1174. err = SIGSEGV;
  1175. break;
  1176. }
  1177. __asm__ __volatile__(
  1178. " .set push\n"
  1179. " .set reorder\n"
  1180. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1181. EXT "%1, %0, 24, 8\n"
  1182. "1:" SB "%1, 0(%2)\n"
  1183. " andi %1, %2, 0x3\n"
  1184. " beq $0, %1, 9f\n"
  1185. ADDIU "%2, %2, -1\n"
  1186. EXT "%1, %0, 16, 8\n"
  1187. "2:" SB "%1, 0(%2)\n"
  1188. " andi %1, %2, 0x3\n"
  1189. " beq $0, %1, 9f\n"
  1190. ADDIU "%2, %2, -1\n"
  1191. EXT "%1, %0, 8, 8\n"
  1192. "3:" SB "%1, 0(%2)\n"
  1193. " andi %1, %2, 0x3\n"
  1194. " beq $0, %1, 9f\n"
  1195. ADDIU "%2, %2, -1\n"
  1196. EXT "%1, %0, 0, 8\n"
  1197. "4:" SB "%1, 0(%2)\n"
  1198. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1199. EXT "%1, %0, 24, 8\n"
  1200. "1:" SB "%1, 0(%2)\n"
  1201. ADDIU "%2, %2, 1\n"
  1202. " andi %1, %2, 0x3\n"
  1203. " beq $0, %1, 9f\n"
  1204. EXT "%1, %0, 16, 8\n"
  1205. "2:" SB "%1, 0(%2)\n"
  1206. ADDIU "%2, %2, 1\n"
  1207. " andi %1, %2, 0x3\n"
  1208. " beq $0, %1, 9f\n"
  1209. EXT "%1, %0, 8, 8\n"
  1210. "3:" SB "%1, 0(%2)\n"
  1211. ADDIU "%2, %2, 1\n"
  1212. " andi %1, %2, 0x3\n"
  1213. " beq $0, %1, 9f\n"
  1214. EXT "%1, %0, 0, 8\n"
  1215. "4:" SB "%1, 0(%2)\n"
  1216. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1217. "9:\n"
  1218. " .insn\n"
  1219. " .section .fixup,\"ax\"\n"
  1220. "8: li %3,%4\n"
  1221. " j 9b\n"
  1222. " .previous\n"
  1223. " .section __ex_table,\"a\"\n"
  1224. STR(PTR) " 1b,8b\n"
  1225. STR(PTR) " 2b,8b\n"
  1226. STR(PTR) " 3b,8b\n"
  1227. STR(PTR) " 4b,8b\n"
  1228. " .previous\n"
  1229. " .set pop\n"
  1230. : "+&r"(rt), "=&r"(rs),
  1231. "+&r"(vaddr), "+&r"(err)
  1232. : "i"(SIGSEGV)
  1233. : "memory");
  1234. MIPS_R2_STATS(stores);
  1235. break;
  1236. case swr_op:
  1237. rt = regs->regs[MIPSInst_RT(inst)];
  1238. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1239. if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
  1240. current->thread.cp0_baduaddr = vaddr;
  1241. err = SIGSEGV;
  1242. break;
  1243. }
  1244. __asm__ __volatile__(
  1245. " .set push\n"
  1246. " .set reorder\n"
  1247. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1248. EXT "%1, %0, 0, 8\n"
  1249. "1:" SB "%1, 0(%2)\n"
  1250. ADDIU "%2, %2, 1\n"
  1251. " andi %1, %2, 0x3\n"
  1252. " beq $0, %1, 9f\n"
  1253. EXT "%1, %0, 8, 8\n"
  1254. "2:" SB "%1, 0(%2)\n"
  1255. ADDIU "%2, %2, 1\n"
  1256. " andi %1, %2, 0x3\n"
  1257. " beq $0, %1, 9f\n"
  1258. EXT "%1, %0, 16, 8\n"
  1259. "3:" SB "%1, 0(%2)\n"
  1260. ADDIU "%2, %2, 1\n"
  1261. " andi %1, %2, 0x3\n"
  1262. " beq $0, %1, 9f\n"
  1263. EXT "%1, %0, 24, 8\n"
  1264. "4:" SB "%1, 0(%2)\n"
  1265. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1266. EXT "%1, %0, 0, 8\n"
  1267. "1:" SB "%1, 0(%2)\n"
  1268. " andi %1, %2, 0x3\n"
  1269. " beq $0, %1, 9f\n"
  1270. ADDIU "%2, %2, -1\n"
  1271. EXT "%1, %0, 8, 8\n"
  1272. "2:" SB "%1, 0(%2)\n"
  1273. " andi %1, %2, 0x3\n"
  1274. " beq $0, %1, 9f\n"
  1275. ADDIU "%2, %2, -1\n"
  1276. EXT "%1, %0, 16, 8\n"
  1277. "3:" SB "%1, 0(%2)\n"
  1278. " andi %1, %2, 0x3\n"
  1279. " beq $0, %1, 9f\n"
  1280. ADDIU "%2, %2, -1\n"
  1281. EXT "%1, %0, 24, 8\n"
  1282. "4:" SB "%1, 0(%2)\n"
  1283. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1284. "9:\n"
  1285. " .insn\n"
  1286. " .section .fixup,\"ax\"\n"
  1287. "8: li %3,%4\n"
  1288. " j 9b\n"
  1289. " .previous\n"
  1290. " .section __ex_table,\"a\"\n"
  1291. STR(PTR) " 1b,8b\n"
  1292. STR(PTR) " 2b,8b\n"
  1293. STR(PTR) " 3b,8b\n"
  1294. STR(PTR) " 4b,8b\n"
  1295. " .previous\n"
  1296. " .set pop\n"
  1297. : "+&r"(rt), "=&r"(rs),
  1298. "+&r"(vaddr), "+&r"(err)
  1299. : "i"(SIGSEGV)
  1300. : "memory");
  1301. MIPS_R2_STATS(stores);
  1302. break;
  1303. case ldl_op:
  1304. if (IS_ENABLED(CONFIG_32BIT)) {
  1305. err = SIGILL;
  1306. break;
  1307. }
  1308. rt = regs->regs[MIPSInst_RT(inst)];
  1309. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1310. if (!access_ok(VERIFY_READ, vaddr, 8)) {
  1311. current->thread.cp0_baduaddr = vaddr;
  1312. err = SIGSEGV;
  1313. break;
  1314. }
  1315. __asm__ __volatile__(
  1316. " .set push\n"
  1317. " .set reorder\n"
  1318. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1319. "1: lb %1, 0(%2)\n"
  1320. " dinsu %0, %1, 56, 8\n"
  1321. " andi %1, %2, 0x7\n"
  1322. " beq $0, %1, 9f\n"
  1323. " daddiu %2, %2, -1\n"
  1324. "2: lb %1, 0(%2)\n"
  1325. " dinsu %0, %1, 48, 8\n"
  1326. " andi %1, %2, 0x7\n"
  1327. " beq $0, %1, 9f\n"
  1328. " daddiu %2, %2, -1\n"
  1329. "3: lb %1, 0(%2)\n"
  1330. " dinsu %0, %1, 40, 8\n"
  1331. " andi %1, %2, 0x7\n"
  1332. " beq $0, %1, 9f\n"
  1333. " daddiu %2, %2, -1\n"
  1334. "4: lb %1, 0(%2)\n"
  1335. " dinsu %0, %1, 32, 8\n"
  1336. " andi %1, %2, 0x7\n"
  1337. " beq $0, %1, 9f\n"
  1338. " daddiu %2, %2, -1\n"
  1339. "5: lb %1, 0(%2)\n"
  1340. " dins %0, %1, 24, 8\n"
  1341. " andi %1, %2, 0x7\n"
  1342. " beq $0, %1, 9f\n"
  1343. " daddiu %2, %2, -1\n"
  1344. "6: lb %1, 0(%2)\n"
  1345. " dins %0, %1, 16, 8\n"
  1346. " andi %1, %2, 0x7\n"
  1347. " beq $0, %1, 9f\n"
  1348. " daddiu %2, %2, -1\n"
  1349. "7: lb %1, 0(%2)\n"
  1350. " dins %0, %1, 8, 8\n"
  1351. " andi %1, %2, 0x7\n"
  1352. " beq $0, %1, 9f\n"
  1353. " daddiu %2, %2, -1\n"
  1354. "0: lb %1, 0(%2)\n"
  1355. " dins %0, %1, 0, 8\n"
  1356. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1357. "1: lb %1, 0(%2)\n"
  1358. " dinsu %0, %1, 56, 8\n"
  1359. " daddiu %2, %2, 1\n"
  1360. " andi %1, %2, 0x7\n"
  1361. " beq $0, %1, 9f\n"
  1362. "2: lb %1, 0(%2)\n"
  1363. " dinsu %0, %1, 48, 8\n"
  1364. " daddiu %2, %2, 1\n"
  1365. " andi %1, %2, 0x7\n"
  1366. " beq $0, %1, 9f\n"
  1367. "3: lb %1, 0(%2)\n"
  1368. " dinsu %0, %1, 40, 8\n"
  1369. " daddiu %2, %2, 1\n"
  1370. " andi %1, %2, 0x7\n"
  1371. " beq $0, %1, 9f\n"
  1372. "4: lb %1, 0(%2)\n"
  1373. " dinsu %0, %1, 32, 8\n"
  1374. " daddiu %2, %2, 1\n"
  1375. " andi %1, %2, 0x7\n"
  1376. " beq $0, %1, 9f\n"
  1377. "5: lb %1, 0(%2)\n"
  1378. " dins %0, %1, 24, 8\n"
  1379. " daddiu %2, %2, 1\n"
  1380. " andi %1, %2, 0x7\n"
  1381. " beq $0, %1, 9f\n"
  1382. "6: lb %1, 0(%2)\n"
  1383. " dins %0, %1, 16, 8\n"
  1384. " daddiu %2, %2, 1\n"
  1385. " andi %1, %2, 0x7\n"
  1386. " beq $0, %1, 9f\n"
  1387. "7: lb %1, 0(%2)\n"
  1388. " dins %0, %1, 8, 8\n"
  1389. " daddiu %2, %2, 1\n"
  1390. " andi %1, %2, 0x7\n"
  1391. " beq $0, %1, 9f\n"
  1392. "0: lb %1, 0(%2)\n"
  1393. " dins %0, %1, 0, 8\n"
  1394. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1395. "9:\n"
  1396. " .insn\n"
  1397. " .section .fixup,\"ax\"\n"
  1398. "8: li %3,%4\n"
  1399. " j 9b\n"
  1400. " .previous\n"
  1401. " .section __ex_table,\"a\"\n"
  1402. STR(PTR) " 1b,8b\n"
  1403. STR(PTR) " 2b,8b\n"
  1404. STR(PTR) " 3b,8b\n"
  1405. STR(PTR) " 4b,8b\n"
  1406. STR(PTR) " 5b,8b\n"
  1407. STR(PTR) " 6b,8b\n"
  1408. STR(PTR) " 7b,8b\n"
  1409. STR(PTR) " 0b,8b\n"
  1410. " .previous\n"
  1411. " .set pop\n"
  1412. : "+&r"(rt), "=&r"(rs),
  1413. "+&r"(vaddr), "+&r"(err)
  1414. : "i"(SIGSEGV));
  1415. if (MIPSInst_RT(inst) && !err)
  1416. regs->regs[MIPSInst_RT(inst)] = rt;
  1417. MIPS_R2_STATS(loads);
  1418. break;
  1419. case ldr_op:
  1420. if (IS_ENABLED(CONFIG_32BIT)) {
  1421. err = SIGILL;
  1422. break;
  1423. }
  1424. rt = regs->regs[MIPSInst_RT(inst)];
  1425. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1426. if (!access_ok(VERIFY_READ, vaddr, 8)) {
  1427. current->thread.cp0_baduaddr = vaddr;
  1428. err = SIGSEGV;
  1429. break;
  1430. }
  1431. __asm__ __volatile__(
  1432. " .set push\n"
  1433. " .set reorder\n"
  1434. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1435. "1: lb %1, 0(%2)\n"
  1436. " dins %0, %1, 0, 8\n"
  1437. " daddiu %2, %2, 1\n"
  1438. " andi %1, %2, 0x7\n"
  1439. " beq $0, %1, 9f\n"
  1440. "2: lb %1, 0(%2)\n"
  1441. " dins %0, %1, 8, 8\n"
  1442. " daddiu %2, %2, 1\n"
  1443. " andi %1, %2, 0x7\n"
  1444. " beq $0, %1, 9f\n"
  1445. "3: lb %1, 0(%2)\n"
  1446. " dins %0, %1, 16, 8\n"
  1447. " daddiu %2, %2, 1\n"
  1448. " andi %1, %2, 0x7\n"
  1449. " beq $0, %1, 9f\n"
  1450. "4: lb %1, 0(%2)\n"
  1451. " dins %0, %1, 24, 8\n"
  1452. " daddiu %2, %2, 1\n"
  1453. " andi %1, %2, 0x7\n"
  1454. " beq $0, %1, 9f\n"
  1455. "5: lb %1, 0(%2)\n"
  1456. " dinsu %0, %1, 32, 8\n"
  1457. " daddiu %2, %2, 1\n"
  1458. " andi %1, %2, 0x7\n"
  1459. " beq $0, %1, 9f\n"
  1460. "6: lb %1, 0(%2)\n"
  1461. " dinsu %0, %1, 40, 8\n"
  1462. " daddiu %2, %2, 1\n"
  1463. " andi %1, %2, 0x7\n"
  1464. " beq $0, %1, 9f\n"
  1465. "7: lb %1, 0(%2)\n"
  1466. " dinsu %0, %1, 48, 8\n"
  1467. " daddiu %2, %2, 1\n"
  1468. " andi %1, %2, 0x7\n"
  1469. " beq $0, %1, 9f\n"
  1470. "0: lb %1, 0(%2)\n"
  1471. " dinsu %0, %1, 56, 8\n"
  1472. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1473. "1: lb %1, 0(%2)\n"
  1474. " dins %0, %1, 0, 8\n"
  1475. " andi %1, %2, 0x7\n"
  1476. " beq $0, %1, 9f\n"
  1477. " daddiu %2, %2, -1\n"
  1478. "2: lb %1, 0(%2)\n"
  1479. " dins %0, %1, 8, 8\n"
  1480. " andi %1, %2, 0x7\n"
  1481. " beq $0, %1, 9f\n"
  1482. " daddiu %2, %2, -1\n"
  1483. "3: lb %1, 0(%2)\n"
  1484. " dins %0, %1, 16, 8\n"
  1485. " andi %1, %2, 0x7\n"
  1486. " beq $0, %1, 9f\n"
  1487. " daddiu %2, %2, -1\n"
  1488. "4: lb %1, 0(%2)\n"
  1489. " dins %0, %1, 24, 8\n"
  1490. " andi %1, %2, 0x7\n"
  1491. " beq $0, %1, 9f\n"
  1492. " daddiu %2, %2, -1\n"
  1493. "5: lb %1, 0(%2)\n"
  1494. " dinsu %0, %1, 32, 8\n"
  1495. " andi %1, %2, 0x7\n"
  1496. " beq $0, %1, 9f\n"
  1497. " daddiu %2, %2, -1\n"
  1498. "6: lb %1, 0(%2)\n"
  1499. " dinsu %0, %1, 40, 8\n"
  1500. " andi %1, %2, 0x7\n"
  1501. " beq $0, %1, 9f\n"
  1502. " daddiu %2, %2, -1\n"
  1503. "7: lb %1, 0(%2)\n"
  1504. " dinsu %0, %1, 48, 8\n"
  1505. " andi %1, %2, 0x7\n"
  1506. " beq $0, %1, 9f\n"
  1507. " daddiu %2, %2, -1\n"
  1508. "0: lb %1, 0(%2)\n"
  1509. " dinsu %0, %1, 56, 8\n"
  1510. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1511. "9:\n"
  1512. " .insn\n"
  1513. " .section .fixup,\"ax\"\n"
  1514. "8: li %3,%4\n"
  1515. " j 9b\n"
  1516. " .previous\n"
  1517. " .section __ex_table,\"a\"\n"
  1518. STR(PTR) " 1b,8b\n"
  1519. STR(PTR) " 2b,8b\n"
  1520. STR(PTR) " 3b,8b\n"
  1521. STR(PTR) " 4b,8b\n"
  1522. STR(PTR) " 5b,8b\n"
  1523. STR(PTR) " 6b,8b\n"
  1524. STR(PTR) " 7b,8b\n"
  1525. STR(PTR) " 0b,8b\n"
  1526. " .previous\n"
  1527. " .set pop\n"
  1528. : "+&r"(rt), "=&r"(rs),
  1529. "+&r"(vaddr), "+&r"(err)
  1530. : "i"(SIGSEGV));
  1531. if (MIPSInst_RT(inst) && !err)
  1532. regs->regs[MIPSInst_RT(inst)] = rt;
  1533. MIPS_R2_STATS(loads);
  1534. break;
  1535. case sdl_op:
  1536. if (IS_ENABLED(CONFIG_32BIT)) {
  1537. err = SIGILL;
  1538. break;
  1539. }
  1540. rt = regs->regs[MIPSInst_RT(inst)];
  1541. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1542. if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
  1543. current->thread.cp0_baduaddr = vaddr;
  1544. err = SIGSEGV;
  1545. break;
  1546. }
  1547. __asm__ __volatile__(
  1548. " .set push\n"
  1549. " .set reorder\n"
  1550. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1551. " dextu %1, %0, 56, 8\n"
  1552. "1: sb %1, 0(%2)\n"
  1553. " andi %1, %2, 0x7\n"
  1554. " beq $0, %1, 9f\n"
  1555. " daddiu %2, %2, -1\n"
  1556. " dextu %1, %0, 48, 8\n"
  1557. "2: sb %1, 0(%2)\n"
  1558. " andi %1, %2, 0x7\n"
  1559. " beq $0, %1, 9f\n"
  1560. " daddiu %2, %2, -1\n"
  1561. " dextu %1, %0, 40, 8\n"
  1562. "3: sb %1, 0(%2)\n"
  1563. " andi %1, %2, 0x7\n"
  1564. " beq $0, %1, 9f\n"
  1565. " daddiu %2, %2, -1\n"
  1566. " dextu %1, %0, 32, 8\n"
  1567. "4: sb %1, 0(%2)\n"
  1568. " andi %1, %2, 0x7\n"
  1569. " beq $0, %1, 9f\n"
  1570. " daddiu %2, %2, -1\n"
  1571. " dext %1, %0, 24, 8\n"
  1572. "5: sb %1, 0(%2)\n"
  1573. " andi %1, %2, 0x7\n"
  1574. " beq $0, %1, 9f\n"
  1575. " daddiu %2, %2, -1\n"
  1576. " dext %1, %0, 16, 8\n"
  1577. "6: sb %1, 0(%2)\n"
  1578. " andi %1, %2, 0x7\n"
  1579. " beq $0, %1, 9f\n"
  1580. " daddiu %2, %2, -1\n"
  1581. " dext %1, %0, 8, 8\n"
  1582. "7: sb %1, 0(%2)\n"
  1583. " andi %1, %2, 0x7\n"
  1584. " beq $0, %1, 9f\n"
  1585. " daddiu %2, %2, -1\n"
  1586. " dext %1, %0, 0, 8\n"
  1587. "0: sb %1, 0(%2)\n"
  1588. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1589. " dextu %1, %0, 56, 8\n"
  1590. "1: sb %1, 0(%2)\n"
  1591. " daddiu %2, %2, 1\n"
  1592. " andi %1, %2, 0x7\n"
  1593. " beq $0, %1, 9f\n"
  1594. " dextu %1, %0, 48, 8\n"
  1595. "2: sb %1, 0(%2)\n"
  1596. " daddiu %2, %2, 1\n"
  1597. " andi %1, %2, 0x7\n"
  1598. " beq $0, %1, 9f\n"
  1599. " dextu %1, %0, 40, 8\n"
  1600. "3: sb %1, 0(%2)\n"
  1601. " daddiu %2, %2, 1\n"
  1602. " andi %1, %2, 0x7\n"
  1603. " beq $0, %1, 9f\n"
  1604. " dextu %1, %0, 32, 8\n"
  1605. "4: sb %1, 0(%2)\n"
  1606. " daddiu %2, %2, 1\n"
  1607. " andi %1, %2, 0x7\n"
  1608. " beq $0, %1, 9f\n"
  1609. " dext %1, %0, 24, 8\n"
  1610. "5: sb %1, 0(%2)\n"
  1611. " daddiu %2, %2, 1\n"
  1612. " andi %1, %2, 0x7\n"
  1613. " beq $0, %1, 9f\n"
  1614. " dext %1, %0, 16, 8\n"
  1615. "6: sb %1, 0(%2)\n"
  1616. " daddiu %2, %2, 1\n"
  1617. " andi %1, %2, 0x7\n"
  1618. " beq $0, %1, 9f\n"
  1619. " dext %1, %0, 8, 8\n"
  1620. "7: sb %1, 0(%2)\n"
  1621. " daddiu %2, %2, 1\n"
  1622. " andi %1, %2, 0x7\n"
  1623. " beq $0, %1, 9f\n"
  1624. " dext %1, %0, 0, 8\n"
  1625. "0: sb %1, 0(%2)\n"
  1626. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1627. "9:\n"
  1628. " .insn\n"
  1629. " .section .fixup,\"ax\"\n"
  1630. "8: li %3,%4\n"
  1631. " j 9b\n"
  1632. " .previous\n"
  1633. " .section __ex_table,\"a\"\n"
  1634. STR(PTR) " 1b,8b\n"
  1635. STR(PTR) " 2b,8b\n"
  1636. STR(PTR) " 3b,8b\n"
  1637. STR(PTR) " 4b,8b\n"
  1638. STR(PTR) " 5b,8b\n"
  1639. STR(PTR) " 6b,8b\n"
  1640. STR(PTR) " 7b,8b\n"
  1641. STR(PTR) " 0b,8b\n"
  1642. " .previous\n"
  1643. " .set pop\n"
  1644. : "+&r"(rt), "=&r"(rs),
  1645. "+&r"(vaddr), "+&r"(err)
  1646. : "i"(SIGSEGV)
  1647. : "memory");
  1648. MIPS_R2_STATS(stores);
  1649. break;
  1650. case sdr_op:
  1651. if (IS_ENABLED(CONFIG_32BIT)) {
  1652. err = SIGILL;
  1653. break;
  1654. }
  1655. rt = regs->regs[MIPSInst_RT(inst)];
  1656. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1657. if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
  1658. current->thread.cp0_baduaddr = vaddr;
  1659. err = SIGSEGV;
  1660. break;
  1661. }
  1662. __asm__ __volatile__(
  1663. " .set push\n"
  1664. " .set reorder\n"
  1665. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1666. " dext %1, %0, 0, 8\n"
  1667. "1: sb %1, 0(%2)\n"
  1668. " daddiu %2, %2, 1\n"
  1669. " andi %1, %2, 0x7\n"
  1670. " beq $0, %1, 9f\n"
  1671. " dext %1, %0, 8, 8\n"
  1672. "2: sb %1, 0(%2)\n"
  1673. " daddiu %2, %2, 1\n"
  1674. " andi %1, %2, 0x7\n"
  1675. " beq $0, %1, 9f\n"
  1676. " dext %1, %0, 16, 8\n"
  1677. "3: sb %1, 0(%2)\n"
  1678. " daddiu %2, %2, 1\n"
  1679. " andi %1, %2, 0x7\n"
  1680. " beq $0, %1, 9f\n"
  1681. " dext %1, %0, 24, 8\n"
  1682. "4: sb %1, 0(%2)\n"
  1683. " daddiu %2, %2, 1\n"
  1684. " andi %1, %2, 0x7\n"
  1685. " beq $0, %1, 9f\n"
  1686. " dextu %1, %0, 32, 8\n"
  1687. "5: sb %1, 0(%2)\n"
  1688. " daddiu %2, %2, 1\n"
  1689. " andi %1, %2, 0x7\n"
  1690. " beq $0, %1, 9f\n"
  1691. " dextu %1, %0, 40, 8\n"
  1692. "6: sb %1, 0(%2)\n"
  1693. " daddiu %2, %2, 1\n"
  1694. " andi %1, %2, 0x7\n"
  1695. " beq $0, %1, 9f\n"
  1696. " dextu %1, %0, 48, 8\n"
  1697. "7: sb %1, 0(%2)\n"
  1698. " daddiu %2, %2, 1\n"
  1699. " andi %1, %2, 0x7\n"
  1700. " beq $0, %1, 9f\n"
  1701. " dextu %1, %0, 56, 8\n"
  1702. "0: sb %1, 0(%2)\n"
  1703. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1704. " dext %1, %0, 0, 8\n"
  1705. "1: sb %1, 0(%2)\n"
  1706. " andi %1, %2, 0x7\n"
  1707. " beq $0, %1, 9f\n"
  1708. " daddiu %2, %2, -1\n"
  1709. " dext %1, %0, 8, 8\n"
  1710. "2: sb %1, 0(%2)\n"
  1711. " andi %1, %2, 0x7\n"
  1712. " beq $0, %1, 9f\n"
  1713. " daddiu %2, %2, -1\n"
  1714. " dext %1, %0, 16, 8\n"
  1715. "3: sb %1, 0(%2)\n"
  1716. " andi %1, %2, 0x7\n"
  1717. " beq $0, %1, 9f\n"
  1718. " daddiu %2, %2, -1\n"
  1719. " dext %1, %0, 24, 8\n"
  1720. "4: sb %1, 0(%2)\n"
  1721. " andi %1, %2, 0x7\n"
  1722. " beq $0, %1, 9f\n"
  1723. " daddiu %2, %2, -1\n"
  1724. " dextu %1, %0, 32, 8\n"
  1725. "5: sb %1, 0(%2)\n"
  1726. " andi %1, %2, 0x7\n"
  1727. " beq $0, %1, 9f\n"
  1728. " daddiu %2, %2, -1\n"
  1729. " dextu %1, %0, 40, 8\n"
  1730. "6: sb %1, 0(%2)\n"
  1731. " andi %1, %2, 0x7\n"
  1732. " beq $0, %1, 9f\n"
  1733. " daddiu %2, %2, -1\n"
  1734. " dextu %1, %0, 48, 8\n"
  1735. "7: sb %1, 0(%2)\n"
  1736. " andi %1, %2, 0x7\n"
  1737. " beq $0, %1, 9f\n"
  1738. " daddiu %2, %2, -1\n"
  1739. " dextu %1, %0, 56, 8\n"
  1740. "0: sb %1, 0(%2)\n"
  1741. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1742. "9:\n"
  1743. " .insn\n"
  1744. " .section .fixup,\"ax\"\n"
  1745. "8: li %3,%4\n"
  1746. " j 9b\n"
  1747. " .previous\n"
  1748. " .section __ex_table,\"a\"\n"
  1749. STR(PTR) " 1b,8b\n"
  1750. STR(PTR) " 2b,8b\n"
  1751. STR(PTR) " 3b,8b\n"
  1752. STR(PTR) " 4b,8b\n"
  1753. STR(PTR) " 5b,8b\n"
  1754. STR(PTR) " 6b,8b\n"
  1755. STR(PTR) " 7b,8b\n"
  1756. STR(PTR) " 0b,8b\n"
  1757. " .previous\n"
  1758. " .set pop\n"
  1759. : "+&r"(rt), "=&r"(rs),
  1760. "+&r"(vaddr), "+&r"(err)
  1761. : "i"(SIGSEGV)
  1762. : "memory");
  1763. MIPS_R2_STATS(stores);
  1764. break;
  1765. case ll_op:
  1766. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1767. if (vaddr & 0x3) {
  1768. current->thread.cp0_baduaddr = vaddr;
  1769. err = SIGBUS;
  1770. break;
  1771. }
  1772. if (!access_ok(VERIFY_READ, vaddr, 4)) {
  1773. current->thread.cp0_baduaddr = vaddr;
  1774. err = SIGBUS;
  1775. break;
  1776. }
  1777. if (!cpu_has_rw_llb) {
  1778. /*
  1779. * An LL/SC block can't be safely emulated without
  1780. * a Config5/LLB availability. So it's probably time to
  1781. * kill our process before things get any worse. This is
  1782. * because Config5/LLB allows us to use ERETNC so that
  1783. * the LLAddr/LLB bit is not cleared when we return from
  1784. * an exception. MIPS R2 LL/SC instructions trap with an
  1785. * RI exception so once we emulate them here, we return
  1786. * back to userland with ERETNC. That preserves the
  1787. * LLAddr/LLB so the subsequent SC instruction will
  1788. * succeed preserving the atomic semantics of the LL/SC
  1789. * block. Without that, there is no safe way to emulate
  1790. * an LL/SC block in MIPSR2 userland.
  1791. */
  1792. pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
  1793. err = SIGKILL;
  1794. break;
  1795. }
  1796. __asm__ __volatile__(
  1797. "1:\n"
  1798. "ll %0, 0(%2)\n"
  1799. "2:\n"
  1800. ".insn\n"
  1801. ".section .fixup,\"ax\"\n"
  1802. "3:\n"
  1803. "li %1, %3\n"
  1804. "j 2b\n"
  1805. ".previous\n"
  1806. ".section __ex_table,\"a\"\n"
  1807. STR(PTR) " 1b,3b\n"
  1808. ".previous\n"
  1809. : "=&r"(res), "+&r"(err)
  1810. : "r"(vaddr), "i"(SIGSEGV)
  1811. : "memory");
  1812. if (MIPSInst_RT(inst) && !err)
  1813. regs->regs[MIPSInst_RT(inst)] = res;
  1814. MIPS_R2_STATS(llsc);
  1815. break;
  1816. case sc_op:
  1817. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1818. if (vaddr & 0x3) {
  1819. current->thread.cp0_baduaddr = vaddr;
  1820. err = SIGBUS;
  1821. break;
  1822. }
  1823. if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
  1824. current->thread.cp0_baduaddr = vaddr;
  1825. err = SIGBUS;
  1826. break;
  1827. }
  1828. if (!cpu_has_rw_llb) {
  1829. /*
  1830. * An LL/SC block can't be safely emulated without
  1831. * a Config5/LLB availability. So it's probably time to
  1832. * kill our process before things get any worse. This is
  1833. * because Config5/LLB allows us to use ERETNC so that
  1834. * the LLAddr/LLB bit is not cleared when we return from
  1835. * an exception. MIPS R2 LL/SC instructions trap with an
  1836. * RI exception so once we emulate them here, we return
  1837. * back to userland with ERETNC. That preserves the
  1838. * LLAddr/LLB so the subsequent SC instruction will
  1839. * succeed preserving the atomic semantics of the LL/SC
  1840. * block. Without that, there is no safe way to emulate
  1841. * an LL/SC block in MIPSR2 userland.
  1842. */
  1843. pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
  1844. err = SIGKILL;
  1845. break;
  1846. }
  1847. res = regs->regs[MIPSInst_RT(inst)];
  1848. __asm__ __volatile__(
  1849. "1:\n"
  1850. "sc %0, 0(%2)\n"
  1851. "2:\n"
  1852. ".insn\n"
  1853. ".section .fixup,\"ax\"\n"
  1854. "3:\n"
  1855. "li %1, %3\n"
  1856. "j 2b\n"
  1857. ".previous\n"
  1858. ".section __ex_table,\"a\"\n"
  1859. STR(PTR) " 1b,3b\n"
  1860. ".previous\n"
  1861. : "+&r"(res), "+&r"(err)
  1862. : "r"(vaddr), "i"(SIGSEGV));
  1863. if (MIPSInst_RT(inst) && !err)
  1864. regs->regs[MIPSInst_RT(inst)] = res;
  1865. MIPS_R2_STATS(llsc);
  1866. break;
  1867. case lld_op:
  1868. if (IS_ENABLED(CONFIG_32BIT)) {
  1869. err = SIGILL;
  1870. break;
  1871. }
  1872. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1873. if (vaddr & 0x7) {
  1874. current->thread.cp0_baduaddr = vaddr;
  1875. err = SIGBUS;
  1876. break;
  1877. }
  1878. if (!access_ok(VERIFY_READ, vaddr, 8)) {
  1879. current->thread.cp0_baduaddr = vaddr;
  1880. err = SIGBUS;
  1881. break;
  1882. }
  1883. if (!cpu_has_rw_llb) {
  1884. /*
  1885. * An LL/SC block can't be safely emulated without
  1886. * a Config5/LLB availability. So it's probably time to
  1887. * kill our process before things get any worse. This is
  1888. * because Config5/LLB allows us to use ERETNC so that
  1889. * the LLAddr/LLB bit is not cleared when we return from
  1890. * an exception. MIPS R2 LL/SC instructions trap with an
  1891. * RI exception so once we emulate them here, we return
  1892. * back to userland with ERETNC. That preserves the
  1893. * LLAddr/LLB so the subsequent SC instruction will
  1894. * succeed preserving the atomic semantics of the LL/SC
  1895. * block. Without that, there is no safe way to emulate
  1896. * an LL/SC block in MIPSR2 userland.
  1897. */
  1898. pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
  1899. err = SIGKILL;
  1900. break;
  1901. }
  1902. __asm__ __volatile__(
  1903. "1:\n"
  1904. "lld %0, 0(%2)\n"
  1905. "2:\n"
  1906. ".insn\n"
  1907. ".section .fixup,\"ax\"\n"
  1908. "3:\n"
  1909. "li %1, %3\n"
  1910. "j 2b\n"
  1911. ".previous\n"
  1912. ".section __ex_table,\"a\"\n"
  1913. STR(PTR) " 1b,3b\n"
  1914. ".previous\n"
  1915. : "=&r"(res), "+&r"(err)
  1916. : "r"(vaddr), "i"(SIGSEGV)
  1917. : "memory");
  1918. if (MIPSInst_RT(inst) && !err)
  1919. regs->regs[MIPSInst_RT(inst)] = res;
  1920. MIPS_R2_STATS(llsc);
  1921. break;
  1922. case scd_op:
  1923. if (IS_ENABLED(CONFIG_32BIT)) {
  1924. err = SIGILL;
  1925. break;
  1926. }
  1927. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1928. if (vaddr & 0x7) {
  1929. current->thread.cp0_baduaddr = vaddr;
  1930. err = SIGBUS;
  1931. break;
  1932. }
  1933. if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
  1934. current->thread.cp0_baduaddr = vaddr;
  1935. err = SIGBUS;
  1936. break;
  1937. }
  1938. if (!cpu_has_rw_llb) {
  1939. /*
  1940. * An LL/SC block can't be safely emulated without
  1941. * a Config5/LLB availability. So it's probably time to
  1942. * kill our process before things get any worse. This is
  1943. * because Config5/LLB allows us to use ERETNC so that
  1944. * the LLAddr/LLB bit is not cleared when we return from
  1945. * an exception. MIPS R2 LL/SC instructions trap with an
  1946. * RI exception so once we emulate them here, we return
  1947. * back to userland with ERETNC. That preserves the
  1948. * LLAddr/LLB so the subsequent SC instruction will
  1949. * succeed preserving the atomic semantics of the LL/SC
  1950. * block. Without that, there is no safe way to emulate
  1951. * an LL/SC block in MIPSR2 userland.
  1952. */
  1953. pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
  1954. err = SIGKILL;
  1955. break;
  1956. }
  1957. res = regs->regs[MIPSInst_RT(inst)];
  1958. __asm__ __volatile__(
  1959. "1:\n"
  1960. "scd %0, 0(%2)\n"
  1961. "2:\n"
  1962. ".insn\n"
  1963. ".section .fixup,\"ax\"\n"
  1964. "3:\n"
  1965. "li %1, %3\n"
  1966. "j 2b\n"
  1967. ".previous\n"
  1968. ".section __ex_table,\"a\"\n"
  1969. STR(PTR) " 1b,3b\n"
  1970. ".previous\n"
  1971. : "+&r"(res), "+&r"(err)
  1972. : "r"(vaddr), "i"(SIGSEGV));
  1973. if (MIPSInst_RT(inst) && !err)
  1974. regs->regs[MIPSInst_RT(inst)] = res;
  1975. MIPS_R2_STATS(llsc);
  1976. break;
  1977. case pref_op:
  1978. /* skip it */
  1979. break;
  1980. default:
  1981. err = SIGILL;
  1982. }
  1983. /*
  1984. * Let's not return to userland just yet. It's costly and
  1985. * it's likely we have more R2 instructions to emulate
  1986. */
  1987. if (!err && (pass++ < MIPS_R2_EMUL_TOTAL_PASS)) {
  1988. regs->cp0_cause &= ~CAUSEF_BD;
  1989. err = get_user(inst, (u32 __user *)regs->cp0_epc);
  1990. if (!err)
  1991. goto repeat;
  1992. if (err < 0)
  1993. err = SIGSEGV;
  1994. }
  1995. if (err && (err != SIGEMT)) {
  1996. regs->regs[31] = r31;
  1997. regs->cp0_epc = epc;
  1998. }
  1999. /* Likely a MIPS R6 compatible instruction */
  2000. if (pass && (err == SIGILL))
  2001. err = 0;
  2002. return err;
  2003. }
  2004. #ifdef CONFIG_DEBUG_FS
  2005. static int mipsr2_stats_show(struct seq_file *s, void *unused)
  2006. {
  2007. seq_printf(s, "Instruction\tTotal\tBDslot\n------------------------------\n");
  2008. seq_printf(s, "movs\t\t%ld\t%ld\n",
  2009. (unsigned long)__this_cpu_read(mipsr2emustats.movs),
  2010. (unsigned long)__this_cpu_read(mipsr2bdemustats.movs));
  2011. seq_printf(s, "hilo\t\t%ld\t%ld\n",
  2012. (unsigned long)__this_cpu_read(mipsr2emustats.hilo),
  2013. (unsigned long)__this_cpu_read(mipsr2bdemustats.hilo));
  2014. seq_printf(s, "muls\t\t%ld\t%ld\n",
  2015. (unsigned long)__this_cpu_read(mipsr2emustats.muls),
  2016. (unsigned long)__this_cpu_read(mipsr2bdemustats.muls));
  2017. seq_printf(s, "divs\t\t%ld\t%ld\n",
  2018. (unsigned long)__this_cpu_read(mipsr2emustats.divs),
  2019. (unsigned long)__this_cpu_read(mipsr2bdemustats.divs));
  2020. seq_printf(s, "dsps\t\t%ld\t%ld\n",
  2021. (unsigned long)__this_cpu_read(mipsr2emustats.dsps),
  2022. (unsigned long)__this_cpu_read(mipsr2bdemustats.dsps));
  2023. seq_printf(s, "bops\t\t%ld\t%ld\n",
  2024. (unsigned long)__this_cpu_read(mipsr2emustats.bops),
  2025. (unsigned long)__this_cpu_read(mipsr2bdemustats.bops));
  2026. seq_printf(s, "traps\t\t%ld\t%ld\n",
  2027. (unsigned long)__this_cpu_read(mipsr2emustats.traps),
  2028. (unsigned long)__this_cpu_read(mipsr2bdemustats.traps));
  2029. seq_printf(s, "fpus\t\t%ld\t%ld\n",
  2030. (unsigned long)__this_cpu_read(mipsr2emustats.fpus),
  2031. (unsigned long)__this_cpu_read(mipsr2bdemustats.fpus));
  2032. seq_printf(s, "loads\t\t%ld\t%ld\n",
  2033. (unsigned long)__this_cpu_read(mipsr2emustats.loads),
  2034. (unsigned long)__this_cpu_read(mipsr2bdemustats.loads));
  2035. seq_printf(s, "stores\t\t%ld\t%ld\n",
  2036. (unsigned long)__this_cpu_read(mipsr2emustats.stores),
  2037. (unsigned long)__this_cpu_read(mipsr2bdemustats.stores));
  2038. seq_printf(s, "llsc\t\t%ld\t%ld\n",
  2039. (unsigned long)__this_cpu_read(mipsr2emustats.llsc),
  2040. (unsigned long)__this_cpu_read(mipsr2bdemustats.llsc));
  2041. seq_printf(s, "dsemul\t\t%ld\t%ld\n",
  2042. (unsigned long)__this_cpu_read(mipsr2emustats.dsemul),
  2043. (unsigned long)__this_cpu_read(mipsr2bdemustats.dsemul));
  2044. seq_printf(s, "jr\t\t%ld\n",
  2045. (unsigned long)__this_cpu_read(mipsr2bremustats.jrs));
  2046. seq_printf(s, "bltzl\t\t%ld\n",
  2047. (unsigned long)__this_cpu_read(mipsr2bremustats.bltzl));
  2048. seq_printf(s, "bgezl\t\t%ld\n",
  2049. (unsigned long)__this_cpu_read(mipsr2bremustats.bgezl));
  2050. seq_printf(s, "bltzll\t\t%ld\n",
  2051. (unsigned long)__this_cpu_read(mipsr2bremustats.bltzll));
  2052. seq_printf(s, "bgezll\t\t%ld\n",
  2053. (unsigned long)__this_cpu_read(mipsr2bremustats.bgezll));
  2054. seq_printf(s, "bltzal\t\t%ld\n",
  2055. (unsigned long)__this_cpu_read(mipsr2bremustats.bltzal));
  2056. seq_printf(s, "bgezal\t\t%ld\n",
  2057. (unsigned long)__this_cpu_read(mipsr2bremustats.bgezal));
  2058. seq_printf(s, "beql\t\t%ld\n",
  2059. (unsigned long)__this_cpu_read(mipsr2bremustats.beql));
  2060. seq_printf(s, "bnel\t\t%ld\n",
  2061. (unsigned long)__this_cpu_read(mipsr2bremustats.bnel));
  2062. seq_printf(s, "blezl\t\t%ld\n",
  2063. (unsigned long)__this_cpu_read(mipsr2bremustats.blezl));
  2064. seq_printf(s, "bgtzl\t\t%ld\n",
  2065. (unsigned long)__this_cpu_read(mipsr2bremustats.bgtzl));
  2066. return 0;
  2067. }
  2068. static int mipsr2_stats_clear_show(struct seq_file *s, void *unused)
  2069. {
  2070. mipsr2_stats_show(s, unused);
  2071. __this_cpu_write((mipsr2emustats).movs, 0);
  2072. __this_cpu_write((mipsr2bdemustats).movs, 0);
  2073. __this_cpu_write((mipsr2emustats).hilo, 0);
  2074. __this_cpu_write((mipsr2bdemustats).hilo, 0);
  2075. __this_cpu_write((mipsr2emustats).muls, 0);
  2076. __this_cpu_write((mipsr2bdemustats).muls, 0);
  2077. __this_cpu_write((mipsr2emustats).divs, 0);
  2078. __this_cpu_write((mipsr2bdemustats).divs, 0);
  2079. __this_cpu_write((mipsr2emustats).dsps, 0);
  2080. __this_cpu_write((mipsr2bdemustats).dsps, 0);
  2081. __this_cpu_write((mipsr2emustats).bops, 0);
  2082. __this_cpu_write((mipsr2bdemustats).bops, 0);
  2083. __this_cpu_write((mipsr2emustats).traps, 0);
  2084. __this_cpu_write((mipsr2bdemustats).traps, 0);
  2085. __this_cpu_write((mipsr2emustats).fpus, 0);
  2086. __this_cpu_write((mipsr2bdemustats).fpus, 0);
  2087. __this_cpu_write((mipsr2emustats).loads, 0);
  2088. __this_cpu_write((mipsr2bdemustats).loads, 0);
  2089. __this_cpu_write((mipsr2emustats).stores, 0);
  2090. __this_cpu_write((mipsr2bdemustats).stores, 0);
  2091. __this_cpu_write((mipsr2emustats).llsc, 0);
  2092. __this_cpu_write((mipsr2bdemustats).llsc, 0);
  2093. __this_cpu_write((mipsr2emustats).dsemul, 0);
  2094. __this_cpu_write((mipsr2bdemustats).dsemul, 0);
  2095. __this_cpu_write((mipsr2bremustats).jrs, 0);
  2096. __this_cpu_write((mipsr2bremustats).bltzl, 0);
  2097. __this_cpu_write((mipsr2bremustats).bgezl, 0);
  2098. __this_cpu_write((mipsr2bremustats).bltzll, 0);
  2099. __this_cpu_write((mipsr2bremustats).bgezll, 0);
  2100. __this_cpu_write((mipsr2bremustats).bltzall, 0);
  2101. __this_cpu_write((mipsr2bremustats).bgezall, 0);
  2102. __this_cpu_write((mipsr2bremustats).bltzal, 0);
  2103. __this_cpu_write((mipsr2bremustats).bgezal, 0);
  2104. __this_cpu_write((mipsr2bremustats).beql, 0);
  2105. __this_cpu_write((mipsr2bremustats).bnel, 0);
  2106. __this_cpu_write((mipsr2bremustats).blezl, 0);
  2107. __this_cpu_write((mipsr2bremustats).bgtzl, 0);
  2108. return 0;
  2109. }
  2110. static int mipsr2_stats_open(struct inode *inode, struct file *file)
  2111. {
  2112. return single_open(file, mipsr2_stats_show, inode->i_private);
  2113. }
  2114. static int mipsr2_stats_clear_open(struct inode *inode, struct file *file)
  2115. {
  2116. return single_open(file, mipsr2_stats_clear_show, inode->i_private);
  2117. }
  2118. static const struct file_operations mipsr2_emul_fops = {
  2119. .open = mipsr2_stats_open,
  2120. .read = seq_read,
  2121. .llseek = seq_lseek,
  2122. .release = single_release,
  2123. };
  2124. static const struct file_operations mipsr2_clear_fops = {
  2125. .open = mipsr2_stats_clear_open,
  2126. .read = seq_read,
  2127. .llseek = seq_lseek,
  2128. .release = single_release,
  2129. };
  2130. static int __init mipsr2_init_debugfs(void)
  2131. {
  2132. struct dentry *mipsr2_emul;
  2133. if (!mips_debugfs_dir)
  2134. return -ENODEV;
  2135. mipsr2_emul = debugfs_create_file("r2_emul_stats", S_IRUGO,
  2136. mips_debugfs_dir, NULL,
  2137. &mipsr2_emul_fops);
  2138. if (!mipsr2_emul)
  2139. return -ENOMEM;
  2140. mipsr2_emul = debugfs_create_file("r2_emul_stats_clear", S_IRUGO,
  2141. mips_debugfs_dir, NULL,
  2142. &mipsr2_clear_fops);
  2143. if (!mipsr2_emul)
  2144. return -ENOMEM;
  2145. return 0;
  2146. }
  2147. device_initcall(mipsr2_init_debugfs);
  2148. #endif /* CONFIG_DEBUG_FS */