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