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

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