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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378
  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. * movt_func - Emulate a MOVT 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. */
  747. int mipsr2_decoder(struct pt_regs *regs, u32 inst)
  748. {
  749. int err = 0;
  750. unsigned long vaddr;
  751. u32 nir;
  752. unsigned long cpc, epc, nepc, r31, res, rs, rt;
  753. void __user *fault_addr = NULL;
  754. int pass = 0;
  755. repeat:
  756. r31 = regs->regs[31];
  757. epc = regs->cp0_epc;
  758. err = compute_return_epc(regs);
  759. if (err < 0) {
  760. BUG();
  761. return SIGEMT;
  762. }
  763. pr_debug("Emulating the 0x%08x R2 instruction @ 0x%08lx (pass=%d))\n",
  764. inst, epc, pass);
  765. switch (MIPSInst_OPCODE(inst)) {
  766. case spec_op:
  767. err = mipsr2_find_op_func(regs, inst, spec_op_table);
  768. if (err < 0) {
  769. /* FPU instruction under JR */
  770. regs->cp0_cause |= CAUSEF_BD;
  771. goto fpu_emul;
  772. }
  773. break;
  774. case spec2_op:
  775. err = mipsr2_find_op_func(regs, inst, spec2_op_table);
  776. break;
  777. case bcond_op:
  778. rt = MIPSInst_RT(inst);
  779. rs = MIPSInst_RS(inst);
  780. switch (rt) {
  781. case tgei_op:
  782. if ((long)regs->regs[rs] >= MIPSInst_SIMM(inst))
  783. do_trap_or_bp(regs, 0, "TGEI");
  784. MIPS_R2_STATS(traps);
  785. break;
  786. case tgeiu_op:
  787. if (regs->regs[rs] >= MIPSInst_UIMM(inst))
  788. do_trap_or_bp(regs, 0, "TGEIU");
  789. MIPS_R2_STATS(traps);
  790. break;
  791. case tlti_op:
  792. if ((long)regs->regs[rs] < MIPSInst_SIMM(inst))
  793. do_trap_or_bp(regs, 0, "TLTI");
  794. MIPS_R2_STATS(traps);
  795. break;
  796. case tltiu_op:
  797. if (regs->regs[rs] < MIPSInst_UIMM(inst))
  798. do_trap_or_bp(regs, 0, "TLTIU");
  799. MIPS_R2_STATS(traps);
  800. break;
  801. case teqi_op:
  802. if (regs->regs[rs] == MIPSInst_SIMM(inst))
  803. do_trap_or_bp(regs, 0, "TEQI");
  804. MIPS_R2_STATS(traps);
  805. break;
  806. case tnei_op:
  807. if (regs->regs[rs] != MIPSInst_SIMM(inst))
  808. do_trap_or_bp(regs, 0, "TNEI");
  809. MIPS_R2_STATS(traps);
  810. break;
  811. case bltzl_op:
  812. case bgezl_op:
  813. case bltzall_op:
  814. case bgezall_op:
  815. if (delay_slot(regs)) {
  816. err = SIGILL;
  817. break;
  818. }
  819. regs->regs[31] = r31;
  820. regs->cp0_epc = epc;
  821. err = __compute_return_epc(regs);
  822. if (err < 0)
  823. return SIGEMT;
  824. if (err != BRANCH_LIKELY_TAKEN)
  825. break;
  826. cpc = regs->cp0_epc;
  827. nepc = epc + 4;
  828. err = __get_user(nir, (u32 __user *)nepc);
  829. if (err) {
  830. err = SIGSEGV;
  831. break;
  832. }
  833. /*
  834. * This will probably be optimized away when
  835. * CONFIG_DEBUG_FS is not enabled
  836. */
  837. switch (rt) {
  838. case bltzl_op:
  839. MIPS_R2BR_STATS(bltzl);
  840. break;
  841. case bgezl_op:
  842. MIPS_R2BR_STATS(bgezl);
  843. break;
  844. case bltzall_op:
  845. MIPS_R2BR_STATS(bltzall);
  846. break;
  847. case bgezall_op:
  848. MIPS_R2BR_STATS(bgezall);
  849. break;
  850. }
  851. switch (MIPSInst_OPCODE(nir)) {
  852. case cop1_op:
  853. case cop1x_op:
  854. case lwc1_op:
  855. case swc1_op:
  856. regs->cp0_cause |= CAUSEF_BD;
  857. goto fpu_emul;
  858. }
  859. if (nir) {
  860. err = mipsr6_emul(regs, nir);
  861. if (err > 0) {
  862. err = mips_dsemul(regs, nir, cpc);
  863. if (err == SIGILL)
  864. err = SIGEMT;
  865. MIPS_R2_STATS(dsemul);
  866. }
  867. }
  868. break;
  869. case bltzal_op:
  870. case bgezal_op:
  871. if (delay_slot(regs)) {
  872. err = SIGILL;
  873. break;
  874. }
  875. regs->regs[31] = r31;
  876. regs->cp0_epc = epc;
  877. err = __compute_return_epc(regs);
  878. if (err < 0)
  879. return SIGEMT;
  880. cpc = regs->cp0_epc;
  881. nepc = epc + 4;
  882. err = __get_user(nir, (u32 __user *)nepc);
  883. if (err) {
  884. err = SIGSEGV;
  885. break;
  886. }
  887. /*
  888. * This will probably be optimized away when
  889. * CONFIG_DEBUG_FS is not enabled
  890. */
  891. switch (rt) {
  892. case bltzal_op:
  893. MIPS_R2BR_STATS(bltzal);
  894. break;
  895. case bgezal_op:
  896. MIPS_R2BR_STATS(bgezal);
  897. break;
  898. }
  899. switch (MIPSInst_OPCODE(nir)) {
  900. case cop1_op:
  901. case cop1x_op:
  902. case lwc1_op:
  903. case swc1_op:
  904. regs->cp0_cause |= CAUSEF_BD;
  905. goto fpu_emul;
  906. }
  907. if (nir) {
  908. err = mipsr6_emul(regs, nir);
  909. if (err > 0) {
  910. err = mips_dsemul(regs, nir, cpc);
  911. if (err == SIGILL)
  912. err = SIGEMT;
  913. MIPS_R2_STATS(dsemul);
  914. }
  915. }
  916. break;
  917. default:
  918. regs->regs[31] = r31;
  919. regs->cp0_epc = epc;
  920. err = SIGILL;
  921. break;
  922. }
  923. break;
  924. case beql_op:
  925. case bnel_op:
  926. case blezl_op:
  927. case bgtzl_op:
  928. if (delay_slot(regs)) {
  929. err = SIGILL;
  930. break;
  931. }
  932. regs->regs[31] = r31;
  933. regs->cp0_epc = epc;
  934. err = __compute_return_epc(regs);
  935. if (err < 0)
  936. return SIGEMT;
  937. if (err != BRANCH_LIKELY_TAKEN)
  938. break;
  939. cpc = regs->cp0_epc;
  940. nepc = epc + 4;
  941. err = __get_user(nir, (u32 __user *)nepc);
  942. if (err) {
  943. err = SIGSEGV;
  944. break;
  945. }
  946. /*
  947. * This will probably be optimized away when
  948. * CONFIG_DEBUG_FS is not enabled
  949. */
  950. switch (MIPSInst_OPCODE(inst)) {
  951. case beql_op:
  952. MIPS_R2BR_STATS(beql);
  953. break;
  954. case bnel_op:
  955. MIPS_R2BR_STATS(bnel);
  956. break;
  957. case blezl_op:
  958. MIPS_R2BR_STATS(blezl);
  959. break;
  960. case bgtzl_op:
  961. MIPS_R2BR_STATS(bgtzl);
  962. break;
  963. }
  964. switch (MIPSInst_OPCODE(nir)) {
  965. case cop1_op:
  966. case cop1x_op:
  967. case lwc1_op:
  968. case swc1_op:
  969. regs->cp0_cause |= CAUSEF_BD;
  970. goto fpu_emul;
  971. }
  972. if (nir) {
  973. err = mipsr6_emul(regs, nir);
  974. if (err > 0) {
  975. err = mips_dsemul(regs, nir, cpc);
  976. if (err == SIGILL)
  977. err = SIGEMT;
  978. MIPS_R2_STATS(dsemul);
  979. }
  980. }
  981. break;
  982. case lwc1_op:
  983. case swc1_op:
  984. case cop1_op:
  985. case cop1x_op:
  986. fpu_emul:
  987. regs->regs[31] = r31;
  988. regs->cp0_epc = epc;
  989. if (!used_math()) { /* First time FPU user. */
  990. err = init_fpu();
  991. set_used_math();
  992. }
  993. lose_fpu(1); /* Save FPU state for the emulator. */
  994. err = fpu_emulator_cop1Handler(regs, &current->thread.fpu, 0,
  995. &fault_addr);
  996. /*
  997. * this is a tricky issue - lose_fpu() uses LL/SC atomics
  998. * if FPU is owned and effectively cancels user level LL/SC.
  999. * So, it could be logical to don't restore FPU ownership here.
  1000. * But the sequence of multiple FPU instructions is much much
  1001. * more often than LL-FPU-SC and I prefer loop here until
  1002. * next scheduler cycle cancels FPU ownership
  1003. */
  1004. own_fpu(1); /* Restore FPU state. */
  1005. if (err)
  1006. current->thread.cp0_baduaddr = (unsigned long)fault_addr;
  1007. MIPS_R2_STATS(fpus);
  1008. break;
  1009. case lwl_op:
  1010. rt = regs->regs[MIPSInst_RT(inst)];
  1011. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1012. if (!access_ok(VERIFY_READ, vaddr, 4)) {
  1013. current->thread.cp0_baduaddr = vaddr;
  1014. err = SIGSEGV;
  1015. break;
  1016. }
  1017. __asm__ __volatile__(
  1018. " .set push\n"
  1019. " .set reorder\n"
  1020. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1021. "1:" LB "%1, 0(%2)\n"
  1022. INS "%0, %1, 24, 8\n"
  1023. " andi %1, %2, 0x3\n"
  1024. " beq $0, %1, 9f\n"
  1025. ADDIU "%2, %2, -1\n"
  1026. "2:" LB "%1, 0(%2)\n"
  1027. INS "%0, %1, 16, 8\n"
  1028. " andi %1, %2, 0x3\n"
  1029. " beq $0, %1, 9f\n"
  1030. ADDIU "%2, %2, -1\n"
  1031. "3:" LB "%1, 0(%2)\n"
  1032. INS "%0, %1, 8, 8\n"
  1033. " andi %1, %2, 0x3\n"
  1034. " beq $0, %1, 9f\n"
  1035. ADDIU "%2, %2, -1\n"
  1036. "4:" LB "%1, 0(%2)\n"
  1037. INS "%0, %1, 0, 8\n"
  1038. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1039. "1:" LB "%1, 0(%2)\n"
  1040. INS "%0, %1, 24, 8\n"
  1041. ADDIU "%2, %2, 1\n"
  1042. " andi %1, %2, 0x3\n"
  1043. " beq $0, %1, 9f\n"
  1044. "2:" LB "%1, 0(%2)\n"
  1045. INS "%0, %1, 16, 8\n"
  1046. ADDIU "%2, %2, 1\n"
  1047. " andi %1, %2, 0x3\n"
  1048. " beq $0, %1, 9f\n"
  1049. "3:" LB "%1, 0(%2)\n"
  1050. INS "%0, %1, 8, 8\n"
  1051. ADDIU "%2, %2, 1\n"
  1052. " andi %1, %2, 0x3\n"
  1053. " beq $0, %1, 9f\n"
  1054. "4:" LB "%1, 0(%2)\n"
  1055. INS "%0, %1, 0, 8\n"
  1056. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1057. "9: sll %0, %0, 0\n"
  1058. "10:\n"
  1059. " .insn\n"
  1060. " .section .fixup,\"ax\"\n"
  1061. "8: li %3,%4\n"
  1062. " j 10b\n"
  1063. " .previous\n"
  1064. " .section __ex_table,\"a\"\n"
  1065. " .word 1b,8b\n"
  1066. " .word 2b,8b\n"
  1067. " .word 3b,8b\n"
  1068. " .word 4b,8b\n"
  1069. " .previous\n"
  1070. " .set pop\n"
  1071. : "+&r"(rt), "=&r"(rs),
  1072. "+&r"(vaddr), "+&r"(err)
  1073. : "i"(SIGSEGV));
  1074. if (MIPSInst_RT(inst) && !err)
  1075. regs->regs[MIPSInst_RT(inst)] = rt;
  1076. MIPS_R2_STATS(loads);
  1077. break;
  1078. case lwr_op:
  1079. rt = regs->regs[MIPSInst_RT(inst)];
  1080. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1081. if (!access_ok(VERIFY_READ, vaddr, 4)) {
  1082. current->thread.cp0_baduaddr = vaddr;
  1083. err = SIGSEGV;
  1084. break;
  1085. }
  1086. __asm__ __volatile__(
  1087. " .set push\n"
  1088. " .set reorder\n"
  1089. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1090. "1:" LB "%1, 0(%2)\n"
  1091. INS "%0, %1, 0, 8\n"
  1092. ADDIU "%2, %2, 1\n"
  1093. " andi %1, %2, 0x3\n"
  1094. " beq $0, %1, 9f\n"
  1095. "2:" LB "%1, 0(%2)\n"
  1096. INS "%0, %1, 8, 8\n"
  1097. ADDIU "%2, %2, 1\n"
  1098. " andi %1, %2, 0x3\n"
  1099. " beq $0, %1, 9f\n"
  1100. "3:" LB "%1, 0(%2)\n"
  1101. INS "%0, %1, 16, 8\n"
  1102. ADDIU "%2, %2, 1\n"
  1103. " andi %1, %2, 0x3\n"
  1104. " beq $0, %1, 9f\n"
  1105. "4:" LB "%1, 0(%2)\n"
  1106. INS "%0, %1, 24, 8\n"
  1107. " sll %0, %0, 0\n"
  1108. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1109. "1:" LB "%1, 0(%2)\n"
  1110. INS "%0, %1, 0, 8\n"
  1111. " andi %1, %2, 0x3\n"
  1112. " beq $0, %1, 9f\n"
  1113. ADDIU "%2, %2, -1\n"
  1114. "2:" LB "%1, 0(%2)\n"
  1115. INS "%0, %1, 8, 8\n"
  1116. " andi %1, %2, 0x3\n"
  1117. " beq $0, %1, 9f\n"
  1118. ADDIU "%2, %2, -1\n"
  1119. "3:" LB "%1, 0(%2)\n"
  1120. INS "%0, %1, 16, 8\n"
  1121. " andi %1, %2, 0x3\n"
  1122. " beq $0, %1, 9f\n"
  1123. ADDIU "%2, %2, -1\n"
  1124. "4:" LB "%1, 0(%2)\n"
  1125. INS "%0, %1, 24, 8\n"
  1126. " sll %0, %0, 0\n"
  1127. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1128. "9:\n"
  1129. "10:\n"
  1130. " .insn\n"
  1131. " .section .fixup,\"ax\"\n"
  1132. "8: li %3,%4\n"
  1133. " j 10b\n"
  1134. " .previous\n"
  1135. " .section __ex_table,\"a\"\n"
  1136. " .word 1b,8b\n"
  1137. " .word 2b,8b\n"
  1138. " .word 3b,8b\n"
  1139. " .word 4b,8b\n"
  1140. " .previous\n"
  1141. " .set pop\n"
  1142. : "+&r"(rt), "=&r"(rs),
  1143. "+&r"(vaddr), "+&r"(err)
  1144. : "i"(SIGSEGV));
  1145. if (MIPSInst_RT(inst) && !err)
  1146. regs->regs[MIPSInst_RT(inst)] = rt;
  1147. MIPS_R2_STATS(loads);
  1148. break;
  1149. case swl_op:
  1150. rt = regs->regs[MIPSInst_RT(inst)];
  1151. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1152. if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
  1153. current->thread.cp0_baduaddr = vaddr;
  1154. err = SIGSEGV;
  1155. break;
  1156. }
  1157. __asm__ __volatile__(
  1158. " .set push\n"
  1159. " .set reorder\n"
  1160. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1161. EXT "%1, %0, 24, 8\n"
  1162. "1:" SB "%1, 0(%2)\n"
  1163. " andi %1, %2, 0x3\n"
  1164. " beq $0, %1, 9f\n"
  1165. ADDIU "%2, %2, -1\n"
  1166. EXT "%1, %0, 16, 8\n"
  1167. "2:" SB "%1, 0(%2)\n"
  1168. " andi %1, %2, 0x3\n"
  1169. " beq $0, %1, 9f\n"
  1170. ADDIU "%2, %2, -1\n"
  1171. EXT "%1, %0, 8, 8\n"
  1172. "3:" SB "%1, 0(%2)\n"
  1173. " andi %1, %2, 0x3\n"
  1174. " beq $0, %1, 9f\n"
  1175. ADDIU "%2, %2, -1\n"
  1176. EXT "%1, %0, 0, 8\n"
  1177. "4:" SB "%1, 0(%2)\n"
  1178. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1179. EXT "%1, %0, 24, 8\n"
  1180. "1:" SB "%1, 0(%2)\n"
  1181. ADDIU "%2, %2, 1\n"
  1182. " andi %1, %2, 0x3\n"
  1183. " beq $0, %1, 9f\n"
  1184. EXT "%1, %0, 16, 8\n"
  1185. "2:" SB "%1, 0(%2)\n"
  1186. ADDIU "%2, %2, 1\n"
  1187. " andi %1, %2, 0x3\n"
  1188. " beq $0, %1, 9f\n"
  1189. EXT "%1, %0, 8, 8\n"
  1190. "3:" SB "%1, 0(%2)\n"
  1191. ADDIU "%2, %2, 1\n"
  1192. " andi %1, %2, 0x3\n"
  1193. " beq $0, %1, 9f\n"
  1194. EXT "%1, %0, 0, 8\n"
  1195. "4:" SB "%1, 0(%2)\n"
  1196. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1197. "9:\n"
  1198. " .insn\n"
  1199. " .section .fixup,\"ax\"\n"
  1200. "8: li %3,%4\n"
  1201. " j 9b\n"
  1202. " .previous\n"
  1203. " .section __ex_table,\"a\"\n"
  1204. " .word 1b,8b\n"
  1205. " .word 2b,8b\n"
  1206. " .word 3b,8b\n"
  1207. " .word 4b,8b\n"
  1208. " .previous\n"
  1209. " .set pop\n"
  1210. : "+&r"(rt), "=&r"(rs),
  1211. "+&r"(vaddr), "+&r"(err)
  1212. : "i"(SIGSEGV)
  1213. : "memory");
  1214. MIPS_R2_STATS(stores);
  1215. break;
  1216. case swr_op:
  1217. rt = regs->regs[MIPSInst_RT(inst)];
  1218. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1219. if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
  1220. current->thread.cp0_baduaddr = vaddr;
  1221. err = SIGSEGV;
  1222. break;
  1223. }
  1224. __asm__ __volatile__(
  1225. " .set push\n"
  1226. " .set reorder\n"
  1227. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1228. EXT "%1, %0, 0, 8\n"
  1229. "1:" SB "%1, 0(%2)\n"
  1230. ADDIU "%2, %2, 1\n"
  1231. " andi %1, %2, 0x3\n"
  1232. " beq $0, %1, 9f\n"
  1233. EXT "%1, %0, 8, 8\n"
  1234. "2:" SB "%1, 0(%2)\n"
  1235. ADDIU "%2, %2, 1\n"
  1236. " andi %1, %2, 0x3\n"
  1237. " beq $0, %1, 9f\n"
  1238. EXT "%1, %0, 16, 8\n"
  1239. "3:" SB "%1, 0(%2)\n"
  1240. ADDIU "%2, %2, 1\n"
  1241. " andi %1, %2, 0x3\n"
  1242. " beq $0, %1, 9f\n"
  1243. EXT "%1, %0, 24, 8\n"
  1244. "4:" SB "%1, 0(%2)\n"
  1245. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1246. EXT "%1, %0, 0, 8\n"
  1247. "1:" SB "%1, 0(%2)\n"
  1248. " andi %1, %2, 0x3\n"
  1249. " beq $0, %1, 9f\n"
  1250. ADDIU "%2, %2, -1\n"
  1251. EXT "%1, %0, 8, 8\n"
  1252. "2:" SB "%1, 0(%2)\n"
  1253. " andi %1, %2, 0x3\n"
  1254. " beq $0, %1, 9f\n"
  1255. ADDIU "%2, %2, -1\n"
  1256. EXT "%1, %0, 16, 8\n"
  1257. "3:" SB "%1, 0(%2)\n"
  1258. " andi %1, %2, 0x3\n"
  1259. " beq $0, %1, 9f\n"
  1260. ADDIU "%2, %2, -1\n"
  1261. EXT "%1, %0, 24, 8\n"
  1262. "4:" SB "%1, 0(%2)\n"
  1263. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1264. "9:\n"
  1265. " .insn\n"
  1266. " .section .fixup,\"ax\"\n"
  1267. "8: li %3,%4\n"
  1268. " j 9b\n"
  1269. " .previous\n"
  1270. " .section __ex_table,\"a\"\n"
  1271. " .word 1b,8b\n"
  1272. " .word 2b,8b\n"
  1273. " .word 3b,8b\n"
  1274. " .word 4b,8b\n"
  1275. " .previous\n"
  1276. " .set pop\n"
  1277. : "+&r"(rt), "=&r"(rs),
  1278. "+&r"(vaddr), "+&r"(err)
  1279. : "i"(SIGSEGV)
  1280. : "memory");
  1281. MIPS_R2_STATS(stores);
  1282. break;
  1283. case ldl_op:
  1284. if (config_enabled(CONFIG_32BIT)) {
  1285. err = SIGILL;
  1286. break;
  1287. }
  1288. rt = regs->regs[MIPSInst_RT(inst)];
  1289. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1290. if (!access_ok(VERIFY_READ, vaddr, 8)) {
  1291. current->thread.cp0_baduaddr = vaddr;
  1292. err = SIGSEGV;
  1293. break;
  1294. }
  1295. __asm__ __volatile__(
  1296. " .set push\n"
  1297. " .set reorder\n"
  1298. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1299. "1: lb %1, 0(%2)\n"
  1300. " dinsu %0, %1, 56, 8\n"
  1301. " andi %1, %2, 0x7\n"
  1302. " beq $0, %1, 9f\n"
  1303. " daddiu %2, %2, -1\n"
  1304. "2: lb %1, 0(%2)\n"
  1305. " dinsu %0, %1, 48, 8\n"
  1306. " andi %1, %2, 0x7\n"
  1307. " beq $0, %1, 9f\n"
  1308. " daddiu %2, %2, -1\n"
  1309. "3: lb %1, 0(%2)\n"
  1310. " dinsu %0, %1, 40, 8\n"
  1311. " andi %1, %2, 0x7\n"
  1312. " beq $0, %1, 9f\n"
  1313. " daddiu %2, %2, -1\n"
  1314. "4: lb %1, 0(%2)\n"
  1315. " dinsu %0, %1, 32, 8\n"
  1316. " andi %1, %2, 0x7\n"
  1317. " beq $0, %1, 9f\n"
  1318. " daddiu %2, %2, -1\n"
  1319. "5: lb %1, 0(%2)\n"
  1320. " dins %0, %1, 24, 8\n"
  1321. " andi %1, %2, 0x7\n"
  1322. " beq $0, %1, 9f\n"
  1323. " daddiu %2, %2, -1\n"
  1324. "6: lb %1, 0(%2)\n"
  1325. " dins %0, %1, 16, 8\n"
  1326. " andi %1, %2, 0x7\n"
  1327. " beq $0, %1, 9f\n"
  1328. " daddiu %2, %2, -1\n"
  1329. "7: lb %1, 0(%2)\n"
  1330. " dins %0, %1, 8, 8\n"
  1331. " andi %1, %2, 0x7\n"
  1332. " beq $0, %1, 9f\n"
  1333. " daddiu %2, %2, -1\n"
  1334. "0: lb %1, 0(%2)\n"
  1335. " dins %0, %1, 0, 8\n"
  1336. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1337. "1: lb %1, 0(%2)\n"
  1338. " dinsu %0, %1, 56, 8\n"
  1339. " daddiu %2, %2, 1\n"
  1340. " andi %1, %2, 0x7\n"
  1341. " beq $0, %1, 9f\n"
  1342. "2: lb %1, 0(%2)\n"
  1343. " dinsu %0, %1, 48, 8\n"
  1344. " daddiu %2, %2, 1\n"
  1345. " andi %1, %2, 0x7\n"
  1346. " beq $0, %1, 9f\n"
  1347. "3: lb %1, 0(%2)\n"
  1348. " dinsu %0, %1, 40, 8\n"
  1349. " daddiu %2, %2, 1\n"
  1350. " andi %1, %2, 0x7\n"
  1351. " beq $0, %1, 9f\n"
  1352. "4: lb %1, 0(%2)\n"
  1353. " dinsu %0, %1, 32, 8\n"
  1354. " daddiu %2, %2, 1\n"
  1355. " andi %1, %2, 0x7\n"
  1356. " beq $0, %1, 9f\n"
  1357. "5: lb %1, 0(%2)\n"
  1358. " dins %0, %1, 24, 8\n"
  1359. " daddiu %2, %2, 1\n"
  1360. " andi %1, %2, 0x7\n"
  1361. " beq $0, %1, 9f\n"
  1362. "6: lb %1, 0(%2)\n"
  1363. " dins %0, %1, 16, 8\n"
  1364. " daddiu %2, %2, 1\n"
  1365. " andi %1, %2, 0x7\n"
  1366. " beq $0, %1, 9f\n"
  1367. "7: lb %1, 0(%2)\n"
  1368. " dins %0, %1, 8, 8\n"
  1369. " daddiu %2, %2, 1\n"
  1370. " andi %1, %2, 0x7\n"
  1371. " beq $0, %1, 9f\n"
  1372. "0: lb %1, 0(%2)\n"
  1373. " dins %0, %1, 0, 8\n"
  1374. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1375. "9:\n"
  1376. " .insn\n"
  1377. " .section .fixup,\"ax\"\n"
  1378. "8: li %3,%4\n"
  1379. " j 9b\n"
  1380. " .previous\n"
  1381. " .section __ex_table,\"a\"\n"
  1382. " .word 1b,8b\n"
  1383. " .word 2b,8b\n"
  1384. " .word 3b,8b\n"
  1385. " .word 4b,8b\n"
  1386. " .word 5b,8b\n"
  1387. " .word 6b,8b\n"
  1388. " .word 7b,8b\n"
  1389. " .word 0b,8b\n"
  1390. " .previous\n"
  1391. " .set pop\n"
  1392. : "+&r"(rt), "=&r"(rs),
  1393. "+&r"(vaddr), "+&r"(err)
  1394. : "i"(SIGSEGV));
  1395. if (MIPSInst_RT(inst) && !err)
  1396. regs->regs[MIPSInst_RT(inst)] = rt;
  1397. MIPS_R2_STATS(loads);
  1398. break;
  1399. case ldr_op:
  1400. if (config_enabled(CONFIG_32BIT)) {
  1401. err = SIGILL;
  1402. break;
  1403. }
  1404. rt = regs->regs[MIPSInst_RT(inst)];
  1405. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1406. if (!access_ok(VERIFY_READ, vaddr, 8)) {
  1407. current->thread.cp0_baduaddr = vaddr;
  1408. err = SIGSEGV;
  1409. break;
  1410. }
  1411. __asm__ __volatile__(
  1412. " .set push\n"
  1413. " .set reorder\n"
  1414. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1415. "1: lb %1, 0(%2)\n"
  1416. " dins %0, %1, 0, 8\n"
  1417. " daddiu %2, %2, 1\n"
  1418. " andi %1, %2, 0x7\n"
  1419. " beq $0, %1, 9f\n"
  1420. "2: lb %1, 0(%2)\n"
  1421. " dins %0, %1, 8, 8\n"
  1422. " daddiu %2, %2, 1\n"
  1423. " andi %1, %2, 0x7\n"
  1424. " beq $0, %1, 9f\n"
  1425. "3: lb %1, 0(%2)\n"
  1426. " dins %0, %1, 16, 8\n"
  1427. " daddiu %2, %2, 1\n"
  1428. " andi %1, %2, 0x7\n"
  1429. " beq $0, %1, 9f\n"
  1430. "4: lb %1, 0(%2)\n"
  1431. " dins %0, %1, 24, 8\n"
  1432. " daddiu %2, %2, 1\n"
  1433. " andi %1, %2, 0x7\n"
  1434. " beq $0, %1, 9f\n"
  1435. "5: lb %1, 0(%2)\n"
  1436. " dinsu %0, %1, 32, 8\n"
  1437. " daddiu %2, %2, 1\n"
  1438. " andi %1, %2, 0x7\n"
  1439. " beq $0, %1, 9f\n"
  1440. "6: lb %1, 0(%2)\n"
  1441. " dinsu %0, %1, 40, 8\n"
  1442. " daddiu %2, %2, 1\n"
  1443. " andi %1, %2, 0x7\n"
  1444. " beq $0, %1, 9f\n"
  1445. "7: lb %1, 0(%2)\n"
  1446. " dinsu %0, %1, 48, 8\n"
  1447. " daddiu %2, %2, 1\n"
  1448. " andi %1, %2, 0x7\n"
  1449. " beq $0, %1, 9f\n"
  1450. "0: lb %1, 0(%2)\n"
  1451. " dinsu %0, %1, 56, 8\n"
  1452. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1453. "1: lb %1, 0(%2)\n"
  1454. " dins %0, %1, 0, 8\n"
  1455. " andi %1, %2, 0x7\n"
  1456. " beq $0, %1, 9f\n"
  1457. " daddiu %2, %2, -1\n"
  1458. "2: lb %1, 0(%2)\n"
  1459. " dins %0, %1, 8, 8\n"
  1460. " andi %1, %2, 0x7\n"
  1461. " beq $0, %1, 9f\n"
  1462. " daddiu %2, %2, -1\n"
  1463. "3: lb %1, 0(%2)\n"
  1464. " dins %0, %1, 16, 8\n"
  1465. " andi %1, %2, 0x7\n"
  1466. " beq $0, %1, 9f\n"
  1467. " daddiu %2, %2, -1\n"
  1468. "4: lb %1, 0(%2)\n"
  1469. " dins %0, %1, 24, 8\n"
  1470. " andi %1, %2, 0x7\n"
  1471. " beq $0, %1, 9f\n"
  1472. " daddiu %2, %2, -1\n"
  1473. "5: lb %1, 0(%2)\n"
  1474. " dinsu %0, %1, 32, 8\n"
  1475. " andi %1, %2, 0x7\n"
  1476. " beq $0, %1, 9f\n"
  1477. " daddiu %2, %2, -1\n"
  1478. "6: lb %1, 0(%2)\n"
  1479. " dinsu %0, %1, 40, 8\n"
  1480. " andi %1, %2, 0x7\n"
  1481. " beq $0, %1, 9f\n"
  1482. " daddiu %2, %2, -1\n"
  1483. "7: lb %1, 0(%2)\n"
  1484. " dinsu %0, %1, 48, 8\n"
  1485. " andi %1, %2, 0x7\n"
  1486. " beq $0, %1, 9f\n"
  1487. " daddiu %2, %2, -1\n"
  1488. "0: lb %1, 0(%2)\n"
  1489. " dinsu %0, %1, 56, 8\n"
  1490. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1491. "9:\n"
  1492. " .insn\n"
  1493. " .section .fixup,\"ax\"\n"
  1494. "8: li %3,%4\n"
  1495. " j 9b\n"
  1496. " .previous\n"
  1497. " .section __ex_table,\"a\"\n"
  1498. " .word 1b,8b\n"
  1499. " .word 2b,8b\n"
  1500. " .word 3b,8b\n"
  1501. " .word 4b,8b\n"
  1502. " .word 5b,8b\n"
  1503. " .word 6b,8b\n"
  1504. " .word 7b,8b\n"
  1505. " .word 0b,8b\n"
  1506. " .previous\n"
  1507. " .set pop\n"
  1508. : "+&r"(rt), "=&r"(rs),
  1509. "+&r"(vaddr), "+&r"(err)
  1510. : "i"(SIGSEGV));
  1511. if (MIPSInst_RT(inst) && !err)
  1512. regs->regs[MIPSInst_RT(inst)] = rt;
  1513. MIPS_R2_STATS(loads);
  1514. break;
  1515. case sdl_op:
  1516. if (config_enabled(CONFIG_32BIT)) {
  1517. err = SIGILL;
  1518. break;
  1519. }
  1520. rt = regs->regs[MIPSInst_RT(inst)];
  1521. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1522. if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
  1523. current->thread.cp0_baduaddr = vaddr;
  1524. err = SIGSEGV;
  1525. break;
  1526. }
  1527. __asm__ __volatile__(
  1528. " .set push\n"
  1529. " .set reorder\n"
  1530. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1531. " dextu %1, %0, 56, 8\n"
  1532. "1: sb %1, 0(%2)\n"
  1533. " andi %1, %2, 0x7\n"
  1534. " beq $0, %1, 9f\n"
  1535. " daddiu %2, %2, -1\n"
  1536. " dextu %1, %0, 48, 8\n"
  1537. "2: sb %1, 0(%2)\n"
  1538. " andi %1, %2, 0x7\n"
  1539. " beq $0, %1, 9f\n"
  1540. " daddiu %2, %2, -1\n"
  1541. " dextu %1, %0, 40, 8\n"
  1542. "3: sb %1, 0(%2)\n"
  1543. " andi %1, %2, 0x7\n"
  1544. " beq $0, %1, 9f\n"
  1545. " daddiu %2, %2, -1\n"
  1546. " dextu %1, %0, 32, 8\n"
  1547. "4: sb %1, 0(%2)\n"
  1548. " andi %1, %2, 0x7\n"
  1549. " beq $0, %1, 9f\n"
  1550. " daddiu %2, %2, -1\n"
  1551. " dext %1, %0, 24, 8\n"
  1552. "5: sb %1, 0(%2)\n"
  1553. " andi %1, %2, 0x7\n"
  1554. " beq $0, %1, 9f\n"
  1555. " daddiu %2, %2, -1\n"
  1556. " dext %1, %0, 16, 8\n"
  1557. "6: sb %1, 0(%2)\n"
  1558. " andi %1, %2, 0x7\n"
  1559. " beq $0, %1, 9f\n"
  1560. " daddiu %2, %2, -1\n"
  1561. " dext %1, %0, 8, 8\n"
  1562. "7: sb %1, 0(%2)\n"
  1563. " andi %1, %2, 0x7\n"
  1564. " beq $0, %1, 9f\n"
  1565. " daddiu %2, %2, -1\n"
  1566. " dext %1, %0, 0, 8\n"
  1567. "0: sb %1, 0(%2)\n"
  1568. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1569. " dextu %1, %0, 56, 8\n"
  1570. "1: sb %1, 0(%2)\n"
  1571. " daddiu %2, %2, 1\n"
  1572. " andi %1, %2, 0x7\n"
  1573. " beq $0, %1, 9f\n"
  1574. " dextu %1, %0, 48, 8\n"
  1575. "2: sb %1, 0(%2)\n"
  1576. " daddiu %2, %2, 1\n"
  1577. " andi %1, %2, 0x7\n"
  1578. " beq $0, %1, 9f\n"
  1579. " dextu %1, %0, 40, 8\n"
  1580. "3: sb %1, 0(%2)\n"
  1581. " daddiu %2, %2, 1\n"
  1582. " andi %1, %2, 0x7\n"
  1583. " beq $0, %1, 9f\n"
  1584. " dextu %1, %0, 32, 8\n"
  1585. "4: sb %1, 0(%2)\n"
  1586. " daddiu %2, %2, 1\n"
  1587. " andi %1, %2, 0x7\n"
  1588. " beq $0, %1, 9f\n"
  1589. " dext %1, %0, 24, 8\n"
  1590. "5: sb %1, 0(%2)\n"
  1591. " daddiu %2, %2, 1\n"
  1592. " andi %1, %2, 0x7\n"
  1593. " beq $0, %1, 9f\n"
  1594. " dext %1, %0, 16, 8\n"
  1595. "6: sb %1, 0(%2)\n"
  1596. " daddiu %2, %2, 1\n"
  1597. " andi %1, %2, 0x7\n"
  1598. " beq $0, %1, 9f\n"
  1599. " dext %1, %0, 8, 8\n"
  1600. "7: sb %1, 0(%2)\n"
  1601. " daddiu %2, %2, 1\n"
  1602. " andi %1, %2, 0x7\n"
  1603. " beq $0, %1, 9f\n"
  1604. " dext %1, %0, 0, 8\n"
  1605. "0: sb %1, 0(%2)\n"
  1606. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1607. "9:\n"
  1608. " .insn\n"
  1609. " .section .fixup,\"ax\"\n"
  1610. "8: li %3,%4\n"
  1611. " j 9b\n"
  1612. " .previous\n"
  1613. " .section __ex_table,\"a\"\n"
  1614. " .word 1b,8b\n"
  1615. " .word 2b,8b\n"
  1616. " .word 3b,8b\n"
  1617. " .word 4b,8b\n"
  1618. " .word 5b,8b\n"
  1619. " .word 6b,8b\n"
  1620. " .word 7b,8b\n"
  1621. " .word 0b,8b\n"
  1622. " .previous\n"
  1623. " .set pop\n"
  1624. : "+&r"(rt), "=&r"(rs),
  1625. "+&r"(vaddr), "+&r"(err)
  1626. : "i"(SIGSEGV)
  1627. : "memory");
  1628. MIPS_R2_STATS(stores);
  1629. break;
  1630. case sdr_op:
  1631. if (config_enabled(CONFIG_32BIT)) {
  1632. err = SIGILL;
  1633. break;
  1634. }
  1635. rt = regs->regs[MIPSInst_RT(inst)];
  1636. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1637. if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
  1638. current->thread.cp0_baduaddr = vaddr;
  1639. err = SIGSEGV;
  1640. break;
  1641. }
  1642. __asm__ __volatile__(
  1643. " .set push\n"
  1644. " .set reorder\n"
  1645. #ifdef CONFIG_CPU_LITTLE_ENDIAN
  1646. " dext %1, %0, 0, 8\n"
  1647. "1: sb %1, 0(%2)\n"
  1648. " daddiu %2, %2, 1\n"
  1649. " andi %1, %2, 0x7\n"
  1650. " beq $0, %1, 9f\n"
  1651. " dext %1, %0, 8, 8\n"
  1652. "2: sb %1, 0(%2)\n"
  1653. " daddiu %2, %2, 1\n"
  1654. " andi %1, %2, 0x7\n"
  1655. " beq $0, %1, 9f\n"
  1656. " dext %1, %0, 16, 8\n"
  1657. "3: sb %1, 0(%2)\n"
  1658. " daddiu %2, %2, 1\n"
  1659. " andi %1, %2, 0x7\n"
  1660. " beq $0, %1, 9f\n"
  1661. " dext %1, %0, 24, 8\n"
  1662. "4: sb %1, 0(%2)\n"
  1663. " daddiu %2, %2, 1\n"
  1664. " andi %1, %2, 0x7\n"
  1665. " beq $0, %1, 9f\n"
  1666. " dextu %1, %0, 32, 8\n"
  1667. "5: sb %1, 0(%2)\n"
  1668. " daddiu %2, %2, 1\n"
  1669. " andi %1, %2, 0x7\n"
  1670. " beq $0, %1, 9f\n"
  1671. " dextu %1, %0, 40, 8\n"
  1672. "6: sb %1, 0(%2)\n"
  1673. " daddiu %2, %2, 1\n"
  1674. " andi %1, %2, 0x7\n"
  1675. " beq $0, %1, 9f\n"
  1676. " dextu %1, %0, 48, 8\n"
  1677. "7: sb %1, 0(%2)\n"
  1678. " daddiu %2, %2, 1\n"
  1679. " andi %1, %2, 0x7\n"
  1680. " beq $0, %1, 9f\n"
  1681. " dextu %1, %0, 56, 8\n"
  1682. "0: sb %1, 0(%2)\n"
  1683. #else /* !CONFIG_CPU_LITTLE_ENDIAN */
  1684. " dext %1, %0, 0, 8\n"
  1685. "1: sb %1, 0(%2)\n"
  1686. " andi %1, %2, 0x7\n"
  1687. " beq $0, %1, 9f\n"
  1688. " daddiu %2, %2, -1\n"
  1689. " dext %1, %0, 8, 8\n"
  1690. "2: sb %1, 0(%2)\n"
  1691. " andi %1, %2, 0x7\n"
  1692. " beq $0, %1, 9f\n"
  1693. " daddiu %2, %2, -1\n"
  1694. " dext %1, %0, 16, 8\n"
  1695. "3: sb %1, 0(%2)\n"
  1696. " andi %1, %2, 0x7\n"
  1697. " beq $0, %1, 9f\n"
  1698. " daddiu %2, %2, -1\n"
  1699. " dext %1, %0, 24, 8\n"
  1700. "4: sb %1, 0(%2)\n"
  1701. " andi %1, %2, 0x7\n"
  1702. " beq $0, %1, 9f\n"
  1703. " daddiu %2, %2, -1\n"
  1704. " dextu %1, %0, 32, 8\n"
  1705. "5: sb %1, 0(%2)\n"
  1706. " andi %1, %2, 0x7\n"
  1707. " beq $0, %1, 9f\n"
  1708. " daddiu %2, %2, -1\n"
  1709. " dextu %1, %0, 40, 8\n"
  1710. "6: sb %1, 0(%2)\n"
  1711. " andi %1, %2, 0x7\n"
  1712. " beq $0, %1, 9f\n"
  1713. " daddiu %2, %2, -1\n"
  1714. " dextu %1, %0, 48, 8\n"
  1715. "7: sb %1, 0(%2)\n"
  1716. " andi %1, %2, 0x7\n"
  1717. " beq $0, %1, 9f\n"
  1718. " daddiu %2, %2, -1\n"
  1719. " dextu %1, %0, 56, 8\n"
  1720. "0: sb %1, 0(%2)\n"
  1721. #endif /* CONFIG_CPU_LITTLE_ENDIAN */
  1722. "9:\n"
  1723. " .insn\n"
  1724. " .section .fixup,\"ax\"\n"
  1725. "8: li %3,%4\n"
  1726. " j 9b\n"
  1727. " .previous\n"
  1728. " .section __ex_table,\"a\"\n"
  1729. " .word 1b,8b\n"
  1730. " .word 2b,8b\n"
  1731. " .word 3b,8b\n"
  1732. " .word 4b,8b\n"
  1733. " .word 5b,8b\n"
  1734. " .word 6b,8b\n"
  1735. " .word 7b,8b\n"
  1736. " .word 0b,8b\n"
  1737. " .previous\n"
  1738. " .set pop\n"
  1739. : "+&r"(rt), "=&r"(rs),
  1740. "+&r"(vaddr), "+&r"(err)
  1741. : "i"(SIGSEGV)
  1742. : "memory");
  1743. MIPS_R2_STATS(stores);
  1744. break;
  1745. case ll_op:
  1746. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1747. if (vaddr & 0x3) {
  1748. current->thread.cp0_baduaddr = vaddr;
  1749. err = SIGBUS;
  1750. break;
  1751. }
  1752. if (!access_ok(VERIFY_READ, vaddr, 4)) {
  1753. current->thread.cp0_baduaddr = vaddr;
  1754. err = SIGBUS;
  1755. break;
  1756. }
  1757. if (!cpu_has_rw_llb) {
  1758. /*
  1759. * An LL/SC block can't be safely emulated without
  1760. * a Config5/LLB availability. So it's probably time to
  1761. * kill our process before things get any worse. This is
  1762. * because Config5/LLB allows us to use ERETNC so that
  1763. * the LLAddr/LLB bit is not cleared when we return from
  1764. * an exception. MIPS R2 LL/SC instructions trap with an
  1765. * RI exception so once we emulate them here, we return
  1766. * back to userland with ERETNC. That preserves the
  1767. * LLAddr/LLB so the subsequent SC instruction will
  1768. * succeed preserving the atomic semantics of the LL/SC
  1769. * block. Without that, there is no safe way to emulate
  1770. * an LL/SC block in MIPSR2 userland.
  1771. */
  1772. pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
  1773. err = SIGKILL;
  1774. break;
  1775. }
  1776. __asm__ __volatile__(
  1777. "1:\n"
  1778. "ll %0, 0(%2)\n"
  1779. "2:\n"
  1780. ".insn\n"
  1781. ".section .fixup,\"ax\"\n"
  1782. "3:\n"
  1783. "li %1, %3\n"
  1784. "j 2b\n"
  1785. ".previous\n"
  1786. ".section __ex_table,\"a\"\n"
  1787. ".word 1b, 3b\n"
  1788. ".previous\n"
  1789. : "=&r"(res), "+&r"(err)
  1790. : "r"(vaddr), "i"(SIGSEGV)
  1791. : "memory");
  1792. if (MIPSInst_RT(inst) && !err)
  1793. regs->regs[MIPSInst_RT(inst)] = res;
  1794. MIPS_R2_STATS(llsc);
  1795. break;
  1796. case sc_op:
  1797. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1798. if (vaddr & 0x3) {
  1799. current->thread.cp0_baduaddr = vaddr;
  1800. err = SIGBUS;
  1801. break;
  1802. }
  1803. if (!access_ok(VERIFY_WRITE, vaddr, 4)) {
  1804. current->thread.cp0_baduaddr = vaddr;
  1805. err = SIGBUS;
  1806. break;
  1807. }
  1808. if (!cpu_has_rw_llb) {
  1809. /*
  1810. * An LL/SC block can't be safely emulated without
  1811. * a Config5/LLB availability. So it's probably time to
  1812. * kill our process before things get any worse. This is
  1813. * because Config5/LLB allows us to use ERETNC so that
  1814. * the LLAddr/LLB bit is not cleared when we return from
  1815. * an exception. MIPS R2 LL/SC instructions trap with an
  1816. * RI exception so once we emulate them here, we return
  1817. * back to userland with ERETNC. That preserves the
  1818. * LLAddr/LLB so the subsequent SC instruction will
  1819. * succeed preserving the atomic semantics of the LL/SC
  1820. * block. Without that, there is no safe way to emulate
  1821. * an LL/SC block in MIPSR2 userland.
  1822. */
  1823. pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
  1824. err = SIGKILL;
  1825. break;
  1826. }
  1827. res = regs->regs[MIPSInst_RT(inst)];
  1828. __asm__ __volatile__(
  1829. "1:\n"
  1830. "sc %0, 0(%2)\n"
  1831. "2:\n"
  1832. ".insn\n"
  1833. ".section .fixup,\"ax\"\n"
  1834. "3:\n"
  1835. "li %1, %3\n"
  1836. "j 2b\n"
  1837. ".previous\n"
  1838. ".section __ex_table,\"a\"\n"
  1839. ".word 1b, 3b\n"
  1840. ".previous\n"
  1841. : "+&r"(res), "+&r"(err)
  1842. : "r"(vaddr), "i"(SIGSEGV));
  1843. if (MIPSInst_RT(inst) && !err)
  1844. regs->regs[MIPSInst_RT(inst)] = res;
  1845. MIPS_R2_STATS(llsc);
  1846. break;
  1847. case lld_op:
  1848. if (config_enabled(CONFIG_32BIT)) {
  1849. err = SIGILL;
  1850. break;
  1851. }
  1852. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1853. if (vaddr & 0x7) {
  1854. current->thread.cp0_baduaddr = vaddr;
  1855. err = SIGBUS;
  1856. break;
  1857. }
  1858. if (!access_ok(VERIFY_READ, vaddr, 8)) {
  1859. current->thread.cp0_baduaddr = vaddr;
  1860. err = SIGBUS;
  1861. break;
  1862. }
  1863. if (!cpu_has_rw_llb) {
  1864. /*
  1865. * An LL/SC block can't be safely emulated without
  1866. * a Config5/LLB availability. So it's probably time to
  1867. * kill our process before things get any worse. This is
  1868. * because Config5/LLB allows us to use ERETNC so that
  1869. * the LLAddr/LLB bit is not cleared when we return from
  1870. * an exception. MIPS R2 LL/SC instructions trap with an
  1871. * RI exception so once we emulate them here, we return
  1872. * back to userland with ERETNC. That preserves the
  1873. * LLAddr/LLB so the subsequent SC instruction will
  1874. * succeed preserving the atomic semantics of the LL/SC
  1875. * block. Without that, there is no safe way to emulate
  1876. * an LL/SC block in MIPSR2 userland.
  1877. */
  1878. pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
  1879. err = SIGKILL;
  1880. break;
  1881. }
  1882. __asm__ __volatile__(
  1883. "1:\n"
  1884. "lld %0, 0(%2)\n"
  1885. "2:\n"
  1886. ".insn\n"
  1887. ".section .fixup,\"ax\"\n"
  1888. "3:\n"
  1889. "li %1, %3\n"
  1890. "j 2b\n"
  1891. ".previous\n"
  1892. ".section __ex_table,\"a\"\n"
  1893. ".word 1b, 3b\n"
  1894. ".previous\n"
  1895. : "=&r"(res), "+&r"(err)
  1896. : "r"(vaddr), "i"(SIGSEGV)
  1897. : "memory");
  1898. if (MIPSInst_RT(inst) && !err)
  1899. regs->regs[MIPSInst_RT(inst)] = res;
  1900. MIPS_R2_STATS(llsc);
  1901. break;
  1902. case scd_op:
  1903. if (config_enabled(CONFIG_32BIT)) {
  1904. err = SIGILL;
  1905. break;
  1906. }
  1907. vaddr = regs->regs[MIPSInst_RS(inst)] + MIPSInst_SIMM(inst);
  1908. if (vaddr & 0x7) {
  1909. current->thread.cp0_baduaddr = vaddr;
  1910. err = SIGBUS;
  1911. break;
  1912. }
  1913. if (!access_ok(VERIFY_WRITE, vaddr, 8)) {
  1914. current->thread.cp0_baduaddr = vaddr;
  1915. err = SIGBUS;
  1916. break;
  1917. }
  1918. if (!cpu_has_rw_llb) {
  1919. /*
  1920. * An LL/SC block can't be safely emulated without
  1921. * a Config5/LLB availability. So it's probably time to
  1922. * kill our process before things get any worse. This is
  1923. * because Config5/LLB allows us to use ERETNC so that
  1924. * the LLAddr/LLB bit is not cleared when we return from
  1925. * an exception. MIPS R2 LL/SC instructions trap with an
  1926. * RI exception so once we emulate them here, we return
  1927. * back to userland with ERETNC. That preserves the
  1928. * LLAddr/LLB so the subsequent SC instruction will
  1929. * succeed preserving the atomic semantics of the LL/SC
  1930. * block. Without that, there is no safe way to emulate
  1931. * an LL/SC block in MIPSR2 userland.
  1932. */
  1933. pr_err("Can't emulate MIPSR2 LL/SC without Config5/LLB\n");
  1934. err = SIGKILL;
  1935. break;
  1936. }
  1937. res = regs->regs[MIPSInst_RT(inst)];
  1938. __asm__ __volatile__(
  1939. "1:\n"
  1940. "scd %0, 0(%2)\n"
  1941. "2:\n"
  1942. ".insn\n"
  1943. ".section .fixup,\"ax\"\n"
  1944. "3:\n"
  1945. "li %1, %3\n"
  1946. "j 2b\n"
  1947. ".previous\n"
  1948. ".section __ex_table,\"a\"\n"
  1949. ".word 1b, 3b\n"
  1950. ".previous\n"
  1951. : "+&r"(res), "+&r"(err)
  1952. : "r"(vaddr), "i"(SIGSEGV));
  1953. if (MIPSInst_RT(inst) && !err)
  1954. regs->regs[MIPSInst_RT(inst)] = res;
  1955. MIPS_R2_STATS(llsc);
  1956. break;
  1957. case pref_op:
  1958. /* skip it */
  1959. break;
  1960. default:
  1961. err = SIGILL;
  1962. }
  1963. /*
  1964. * Lets not return to userland just yet. It's constly and
  1965. * it's likely we have more R2 instructions to emulate
  1966. */
  1967. if (!err && (pass++ < MIPS_R2_EMUL_TOTAL_PASS)) {
  1968. regs->cp0_cause &= ~CAUSEF_BD;
  1969. err = get_user(inst, (u32 __user *)regs->cp0_epc);
  1970. if (!err)
  1971. goto repeat;
  1972. if (err < 0)
  1973. err = SIGSEGV;
  1974. }
  1975. if (err && (err != SIGEMT)) {
  1976. regs->regs[31] = r31;
  1977. regs->cp0_epc = epc;
  1978. }
  1979. /* Likely a MIPS R6 compatible instruction */
  1980. if (pass && (err == SIGILL))
  1981. err = 0;
  1982. return err;
  1983. }
  1984. #ifdef CONFIG_DEBUG_FS
  1985. static int mipsr2_stats_show(struct seq_file *s, void *unused)
  1986. {
  1987. seq_printf(s, "Instruction\tTotal\tBDslot\n------------------------------\n");
  1988. seq_printf(s, "movs\t\t%ld\t%ld\n",
  1989. (unsigned long)__this_cpu_read(mipsr2emustats.movs),
  1990. (unsigned long)__this_cpu_read(mipsr2bdemustats.movs));
  1991. seq_printf(s, "hilo\t\t%ld\t%ld\n",
  1992. (unsigned long)__this_cpu_read(mipsr2emustats.hilo),
  1993. (unsigned long)__this_cpu_read(mipsr2bdemustats.hilo));
  1994. seq_printf(s, "muls\t\t%ld\t%ld\n",
  1995. (unsigned long)__this_cpu_read(mipsr2emustats.muls),
  1996. (unsigned long)__this_cpu_read(mipsr2bdemustats.muls));
  1997. seq_printf(s, "divs\t\t%ld\t%ld\n",
  1998. (unsigned long)__this_cpu_read(mipsr2emustats.divs),
  1999. (unsigned long)__this_cpu_read(mipsr2bdemustats.divs));
  2000. seq_printf(s, "dsps\t\t%ld\t%ld\n",
  2001. (unsigned long)__this_cpu_read(mipsr2emustats.dsps),
  2002. (unsigned long)__this_cpu_read(mipsr2bdemustats.dsps));
  2003. seq_printf(s, "bops\t\t%ld\t%ld\n",
  2004. (unsigned long)__this_cpu_read(mipsr2emustats.bops),
  2005. (unsigned long)__this_cpu_read(mipsr2bdemustats.bops));
  2006. seq_printf(s, "traps\t\t%ld\t%ld\n",
  2007. (unsigned long)__this_cpu_read(mipsr2emustats.traps),
  2008. (unsigned long)__this_cpu_read(mipsr2bdemustats.traps));
  2009. seq_printf(s, "fpus\t\t%ld\t%ld\n",
  2010. (unsigned long)__this_cpu_read(mipsr2emustats.fpus),
  2011. (unsigned long)__this_cpu_read(mipsr2bdemustats.fpus));
  2012. seq_printf(s, "loads\t\t%ld\t%ld\n",
  2013. (unsigned long)__this_cpu_read(mipsr2emustats.loads),
  2014. (unsigned long)__this_cpu_read(mipsr2bdemustats.loads));
  2015. seq_printf(s, "stores\t\t%ld\t%ld\n",
  2016. (unsigned long)__this_cpu_read(mipsr2emustats.stores),
  2017. (unsigned long)__this_cpu_read(mipsr2bdemustats.stores));
  2018. seq_printf(s, "llsc\t\t%ld\t%ld\n",
  2019. (unsigned long)__this_cpu_read(mipsr2emustats.llsc),
  2020. (unsigned long)__this_cpu_read(mipsr2bdemustats.llsc));
  2021. seq_printf(s, "dsemul\t\t%ld\t%ld\n",
  2022. (unsigned long)__this_cpu_read(mipsr2emustats.dsemul),
  2023. (unsigned long)__this_cpu_read(mipsr2bdemustats.dsemul));
  2024. seq_printf(s, "jr\t\t%ld\n",
  2025. (unsigned long)__this_cpu_read(mipsr2bremustats.jrs));
  2026. seq_printf(s, "bltzl\t\t%ld\n",
  2027. (unsigned long)__this_cpu_read(mipsr2bremustats.bltzl));
  2028. seq_printf(s, "bgezl\t\t%ld\n",
  2029. (unsigned long)__this_cpu_read(mipsr2bremustats.bgezl));
  2030. seq_printf(s, "bltzll\t\t%ld\n",
  2031. (unsigned long)__this_cpu_read(mipsr2bremustats.bltzll));
  2032. seq_printf(s, "bgezll\t\t%ld\n",
  2033. (unsigned long)__this_cpu_read(mipsr2bremustats.bgezll));
  2034. seq_printf(s, "bltzal\t\t%ld\n",
  2035. (unsigned long)__this_cpu_read(mipsr2bremustats.bltzal));
  2036. seq_printf(s, "bgezal\t\t%ld\n",
  2037. (unsigned long)__this_cpu_read(mipsr2bremustats.bgezal));
  2038. seq_printf(s, "beql\t\t%ld\n",
  2039. (unsigned long)__this_cpu_read(mipsr2bremustats.beql));
  2040. seq_printf(s, "bnel\t\t%ld\n",
  2041. (unsigned long)__this_cpu_read(mipsr2bremustats.bnel));
  2042. seq_printf(s, "blezl\t\t%ld\n",
  2043. (unsigned long)__this_cpu_read(mipsr2bremustats.blezl));
  2044. seq_printf(s, "bgtzl\t\t%ld\n",
  2045. (unsigned long)__this_cpu_read(mipsr2bremustats.bgtzl));
  2046. return 0;
  2047. }
  2048. static int mipsr2_stats_clear_show(struct seq_file *s, void *unused)
  2049. {
  2050. mipsr2_stats_show(s, unused);
  2051. __this_cpu_write((mipsr2emustats).movs, 0);
  2052. __this_cpu_write((mipsr2bdemustats).movs, 0);
  2053. __this_cpu_write((mipsr2emustats).hilo, 0);
  2054. __this_cpu_write((mipsr2bdemustats).hilo, 0);
  2055. __this_cpu_write((mipsr2emustats).muls, 0);
  2056. __this_cpu_write((mipsr2bdemustats).muls, 0);
  2057. __this_cpu_write((mipsr2emustats).divs, 0);
  2058. __this_cpu_write((mipsr2bdemustats).divs, 0);
  2059. __this_cpu_write((mipsr2emustats).dsps, 0);
  2060. __this_cpu_write((mipsr2bdemustats).dsps, 0);
  2061. __this_cpu_write((mipsr2emustats).bops, 0);
  2062. __this_cpu_write((mipsr2bdemustats).bops, 0);
  2063. __this_cpu_write((mipsr2emustats).traps, 0);
  2064. __this_cpu_write((mipsr2bdemustats).traps, 0);
  2065. __this_cpu_write((mipsr2emustats).fpus, 0);
  2066. __this_cpu_write((mipsr2bdemustats).fpus, 0);
  2067. __this_cpu_write((mipsr2emustats).loads, 0);
  2068. __this_cpu_write((mipsr2bdemustats).loads, 0);
  2069. __this_cpu_write((mipsr2emustats).stores, 0);
  2070. __this_cpu_write((mipsr2bdemustats).stores, 0);
  2071. __this_cpu_write((mipsr2emustats).llsc, 0);
  2072. __this_cpu_write((mipsr2bdemustats).llsc, 0);
  2073. __this_cpu_write((mipsr2emustats).dsemul, 0);
  2074. __this_cpu_write((mipsr2bdemustats).dsemul, 0);
  2075. __this_cpu_write((mipsr2bremustats).jrs, 0);
  2076. __this_cpu_write((mipsr2bremustats).bltzl, 0);
  2077. __this_cpu_write((mipsr2bremustats).bgezl, 0);
  2078. __this_cpu_write((mipsr2bremustats).bltzll, 0);
  2079. __this_cpu_write((mipsr2bremustats).bgezll, 0);
  2080. __this_cpu_write((mipsr2bremustats).bltzal, 0);
  2081. __this_cpu_write((mipsr2bremustats).bgezal, 0);
  2082. __this_cpu_write((mipsr2bremustats).beql, 0);
  2083. __this_cpu_write((mipsr2bremustats).bnel, 0);
  2084. __this_cpu_write((mipsr2bremustats).blezl, 0);
  2085. __this_cpu_write((mipsr2bremustats).bgtzl, 0);
  2086. return 0;
  2087. }
  2088. static int mipsr2_stats_open(struct inode *inode, struct file *file)
  2089. {
  2090. return single_open(file, mipsr2_stats_show, inode->i_private);
  2091. }
  2092. static int mipsr2_stats_clear_open(struct inode *inode, struct file *file)
  2093. {
  2094. return single_open(file, mipsr2_stats_clear_show, inode->i_private);
  2095. }
  2096. static const struct file_operations mipsr2_emul_fops = {
  2097. .open = mipsr2_stats_open,
  2098. .read = seq_read,
  2099. .llseek = seq_lseek,
  2100. .release = single_release,
  2101. };
  2102. static const struct file_operations mipsr2_clear_fops = {
  2103. .open = mipsr2_stats_clear_open,
  2104. .read = seq_read,
  2105. .llseek = seq_lseek,
  2106. .release = single_release,
  2107. };
  2108. static int __init mipsr2_init_debugfs(void)
  2109. {
  2110. extern struct dentry *mips_debugfs_dir;
  2111. struct dentry *mipsr2_emul;
  2112. if (!mips_debugfs_dir)
  2113. return -ENODEV;
  2114. mipsr2_emul = debugfs_create_file("r2_emul_stats", S_IRUGO,
  2115. mips_debugfs_dir, NULL,
  2116. &mipsr2_emul_fops);
  2117. if (!mipsr2_emul)
  2118. return -ENOMEM;
  2119. mipsr2_emul = debugfs_create_file("r2_emul_stats_clear", S_IRUGO,
  2120. mips_debugfs_dir, NULL,
  2121. &mipsr2_clear_fops);
  2122. if (!mipsr2_emul)
  2123. return -ENOMEM;
  2124. return 0;
  2125. }
  2126. device_initcall(mipsr2_init_debugfs);
  2127. #endif /* CONFIG_DEBUG_FS */