cp1emu.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /*
  2. * cp1emu.c: a MIPS coprocessor 1 (fpu) instruction emulator
  3. *
  4. * MIPS floating point support
  5. * Copyright (C) 1994-2000 Algorithmics Ltd.
  6. * http://www.algor.co.uk
  7. *
  8. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  9. * Copyright (C) 2000 MIPS Technologies, Inc.
  10. *
  11. * This program is free software; you can distribute it and/or modify it
  12. * under the terms of the GNU General Public License (Version 2) as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  18. * for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  23. *
  24. * A complete emulator for MIPS coprocessor 1 instructions. This is
  25. * required for #float(switch) or #float(trap), where it catches all
  26. * COP1 instructions via the "CoProcessor Unusable" exception.
  27. *
  28. * More surprisingly it is also required for #float(ieee), to help out
  29. * the hardware fpu at the boundaries of the IEEE-754 representation
  30. * (denormalised values, infinities, underflow, etc). It is made
  31. * quite nasty because emulation of some non-COP1 instructions is
  32. * required, e.g. in branch delay slots.
  33. *
  34. * Note if you know that you won't have an fpu, then you'll get much
  35. * better performance by compiling with -msoft-float!
  36. */
  37. #include <linux/sched.h>
  38. #include <linux/debugfs.h>
  39. #include <asm/inst.h>
  40. #include <asm/bootinfo.h>
  41. #include <asm/processor.h>
  42. #include <asm/ptrace.h>
  43. #include <asm/signal.h>
  44. #include <asm/mipsregs.h>
  45. #include <asm/fpu_emulator.h>
  46. #include <asm/uaccess.h>
  47. #include <asm/branch.h>
  48. #include "ieee754.h"
  49. /* Strap kernel emulator for full MIPS IV emulation */
  50. #ifdef __mips
  51. #undef __mips
  52. #endif
  53. #define __mips 4
  54. /* Function which emulates a floating point instruction. */
  55. static int fpu_emu(struct pt_regs *, struct mips_fpu_struct *,
  56. mips_instruction);
  57. #if __mips >= 4 && __mips != 32
  58. static int fpux_emu(struct pt_regs *,
  59. struct mips_fpu_struct *, mips_instruction);
  60. #endif
  61. /* Further private data for which no space exists in mips_fpu_struct */
  62. struct mips_fpu_emulator_stats fpuemustats;
  63. /* Control registers */
  64. #define FPCREG_RID 0 /* $0 = revision id */
  65. #define FPCREG_CSR 31 /* $31 = csr */
  66. /* Convert Mips rounding mode (0..3) to IEEE library modes. */
  67. static const unsigned char ieee_rm[4] = {
  68. [FPU_CSR_RN] = IEEE754_RN,
  69. [FPU_CSR_RZ] = IEEE754_RZ,
  70. [FPU_CSR_RU] = IEEE754_RU,
  71. [FPU_CSR_RD] = IEEE754_RD,
  72. };
  73. /* Convert IEEE library modes to Mips rounding mode (0..3). */
  74. static const unsigned char mips_rm[4] = {
  75. [IEEE754_RN] = FPU_CSR_RN,
  76. [IEEE754_RZ] = FPU_CSR_RZ,
  77. [IEEE754_RD] = FPU_CSR_RD,
  78. [IEEE754_RU] = FPU_CSR_RU,
  79. };
  80. #if __mips >= 4
  81. /* convert condition code register number to csr bit */
  82. static const unsigned int fpucondbit[8] = {
  83. FPU_CSR_COND0,
  84. FPU_CSR_COND1,
  85. FPU_CSR_COND2,
  86. FPU_CSR_COND3,
  87. FPU_CSR_COND4,
  88. FPU_CSR_COND5,
  89. FPU_CSR_COND6,
  90. FPU_CSR_COND7
  91. };
  92. #endif
  93. /*
  94. * Redundant with logic already in kernel/branch.c,
  95. * embedded in compute_return_epc. At some point,
  96. * a single subroutine should be used across both
  97. * modules.
  98. */
  99. static int isBranchInstr(mips_instruction * i)
  100. {
  101. switch (MIPSInst_OPCODE(*i)) {
  102. case spec_op:
  103. switch (MIPSInst_FUNC(*i)) {
  104. case jalr_op:
  105. case jr_op:
  106. return 1;
  107. }
  108. break;
  109. case bcond_op:
  110. switch (MIPSInst_RT(*i)) {
  111. case bltz_op:
  112. case bgez_op:
  113. case bltzl_op:
  114. case bgezl_op:
  115. case bltzal_op:
  116. case bgezal_op:
  117. case bltzall_op:
  118. case bgezall_op:
  119. return 1;
  120. }
  121. break;
  122. case j_op:
  123. case jal_op:
  124. case jalx_op:
  125. case beq_op:
  126. case bne_op:
  127. case blez_op:
  128. case bgtz_op:
  129. case beql_op:
  130. case bnel_op:
  131. case blezl_op:
  132. case bgtzl_op:
  133. return 1;
  134. case cop0_op:
  135. case cop1_op:
  136. case cop2_op:
  137. case cop1x_op:
  138. if (MIPSInst_RS(*i) == bc_op)
  139. return 1;
  140. break;
  141. }
  142. return 0;
  143. }
  144. /*
  145. * In the Linux kernel, we support selection of FPR format on the
  146. * basis of the Status.FR bit. If an FPU is not present, the FR bit
  147. * is hardwired to zero, which would imply a 32-bit FPU even for
  148. * 64-bit CPUs. For 64-bit kernels with no FPU we use TIF_32BIT_REGS
  149. * as a proxy for the FR bit so that a 64-bit FPU is emulated. In any
  150. * case, for a 32-bit kernel which uses the O32 MIPS ABI, only the
  151. * even FPRs are used (Status.FR = 0).
  152. */
  153. static inline int cop1_64bit(struct pt_regs *xcp)
  154. {
  155. if (cpu_has_fpu)
  156. return xcp->cp0_status & ST0_FR;
  157. #ifdef CONFIG_64BIT
  158. return !test_thread_flag(TIF_32BIT_REGS);
  159. #else
  160. return 0;
  161. #endif
  162. }
  163. #define SIFROMREG(si, x) ((si) = cop1_64bit(xcp) || !(x & 1) ? \
  164. (int)ctx->fpr[x] : (int)(ctx->fpr[x & ~1] >> 32))
  165. #define SITOREG(si, x) (ctx->fpr[x & ~(cop1_64bit(xcp) == 0)] = \
  166. cop1_64bit(xcp) || !(x & 1) ? \
  167. ctx->fpr[x & ~1] >> 32 << 32 | (u32)(si) : \
  168. ctx->fpr[x & ~1] << 32 >> 32 | (u64)(si) << 32)
  169. #define DIFROMREG(di, x) ((di) = ctx->fpr[x & ~(cop1_64bit(xcp) == 0)])
  170. #define DITOREG(di, x) (ctx->fpr[x & ~(cop1_64bit(xcp) == 0)] = (di))
  171. #define SPFROMREG(sp, x) SIFROMREG((sp).bits, x)
  172. #define SPTOREG(sp, x) SITOREG((sp).bits, x)
  173. #define DPFROMREG(dp, x) DIFROMREG((dp).bits, x)
  174. #define DPTOREG(dp, x) DITOREG((dp).bits, x)
  175. /*
  176. * Emulate the single floating point instruction pointed at by EPC.
  177. * Two instructions if the instruction is in a branch delay slot.
  178. */
  179. static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx)
  180. {
  181. mips_instruction ir;
  182. unsigned long emulpc, contpc;
  183. unsigned int cond;
  184. if (get_user(ir, (mips_instruction __user *) xcp->cp0_epc)) {
  185. fpuemustats.errors++;
  186. return SIGBUS;
  187. }
  188. /* XXX NEC Vr54xx bug workaround */
  189. if ((xcp->cp0_cause & CAUSEF_BD) && !isBranchInstr(&ir))
  190. xcp->cp0_cause &= ~CAUSEF_BD;
  191. if (xcp->cp0_cause & CAUSEF_BD) {
  192. /*
  193. * The instruction to be emulated is in a branch delay slot
  194. * which means that we have to emulate the branch instruction
  195. * BEFORE we do the cop1 instruction.
  196. *
  197. * This branch could be a COP1 branch, but in that case we
  198. * would have had a trap for that instruction, and would not
  199. * come through this route.
  200. *
  201. * Linux MIPS branch emulator operates on context, updating the
  202. * cp0_epc.
  203. */
  204. emulpc = xcp->cp0_epc + 4; /* Snapshot emulation target */
  205. if (__compute_return_epc(xcp)) {
  206. #ifdef CP1DBG
  207. printk("failed to emulate branch at %p\n",
  208. (void *) (xcp->cp0_epc));
  209. #endif
  210. return SIGILL;
  211. }
  212. if (get_user(ir, (mips_instruction __user *) emulpc)) {
  213. fpuemustats.errors++;
  214. return SIGBUS;
  215. }
  216. /* __compute_return_epc() will have updated cp0_epc */
  217. contpc = xcp->cp0_epc;
  218. /* In order not to confuse ptrace() et al, tweak context */
  219. xcp->cp0_epc = emulpc - 4;
  220. } else {
  221. emulpc = xcp->cp0_epc;
  222. contpc = xcp->cp0_epc + 4;
  223. }
  224. emul:
  225. fpuemustats.emulated++;
  226. switch (MIPSInst_OPCODE(ir)) {
  227. case ldc1_op:{
  228. u64 __user *va = (u64 __user *) (xcp->regs[MIPSInst_RS(ir)] +
  229. MIPSInst_SIMM(ir));
  230. u64 val;
  231. fpuemustats.loads++;
  232. if (get_user(val, va)) {
  233. fpuemustats.errors++;
  234. return SIGBUS;
  235. }
  236. DITOREG(val, MIPSInst_RT(ir));
  237. break;
  238. }
  239. case sdc1_op:{
  240. u64 __user *va = (u64 __user *) (xcp->regs[MIPSInst_RS(ir)] +
  241. MIPSInst_SIMM(ir));
  242. u64 val;
  243. fpuemustats.stores++;
  244. DIFROMREG(val, MIPSInst_RT(ir));
  245. if (put_user(val, va)) {
  246. fpuemustats.errors++;
  247. return SIGBUS;
  248. }
  249. break;
  250. }
  251. case lwc1_op:{
  252. u32 __user *va = (u32 __user *) (xcp->regs[MIPSInst_RS(ir)] +
  253. MIPSInst_SIMM(ir));
  254. u32 val;
  255. fpuemustats.loads++;
  256. if (get_user(val, va)) {
  257. fpuemustats.errors++;
  258. return SIGBUS;
  259. }
  260. SITOREG(val, MIPSInst_RT(ir));
  261. break;
  262. }
  263. case swc1_op:{
  264. u32 __user *va = (u32 __user *) (xcp->regs[MIPSInst_RS(ir)] +
  265. MIPSInst_SIMM(ir));
  266. u32 val;
  267. fpuemustats.stores++;
  268. SIFROMREG(val, MIPSInst_RT(ir));
  269. if (put_user(val, va)) {
  270. fpuemustats.errors++;
  271. return SIGBUS;
  272. }
  273. break;
  274. }
  275. case cop1_op:
  276. switch (MIPSInst_RS(ir)) {
  277. #if defined(__mips64)
  278. case dmfc_op:
  279. /* copregister fs -> gpr[rt] */
  280. if (MIPSInst_RT(ir) != 0) {
  281. DIFROMREG(xcp->regs[MIPSInst_RT(ir)],
  282. MIPSInst_RD(ir));
  283. }
  284. break;
  285. case dmtc_op:
  286. /* copregister fs <- rt */
  287. DITOREG(xcp->regs[MIPSInst_RT(ir)], MIPSInst_RD(ir));
  288. break;
  289. #endif
  290. case mfc_op:
  291. /* copregister rd -> gpr[rt] */
  292. if (MIPSInst_RT(ir) != 0) {
  293. SIFROMREG(xcp->regs[MIPSInst_RT(ir)],
  294. MIPSInst_RD(ir));
  295. }
  296. break;
  297. case mtc_op:
  298. /* copregister rd <- rt */
  299. SITOREG(xcp->regs[MIPSInst_RT(ir)], MIPSInst_RD(ir));
  300. break;
  301. case cfc_op:{
  302. /* cop control register rd -> gpr[rt] */
  303. u32 value;
  304. if (MIPSInst_RD(ir) == FPCREG_CSR) {
  305. value = ctx->fcr31;
  306. value = (value & ~0x3) | mips_rm[value & 0x3];
  307. #ifdef CSRTRACE
  308. printk("%p gpr[%d]<-csr=%08x\n",
  309. (void *) (xcp->cp0_epc),
  310. MIPSInst_RT(ir), value);
  311. #endif
  312. }
  313. else if (MIPSInst_RD(ir) == FPCREG_RID)
  314. value = 0;
  315. else
  316. value = 0;
  317. if (MIPSInst_RT(ir))
  318. xcp->regs[MIPSInst_RT(ir)] = value;
  319. break;
  320. }
  321. case ctc_op:{
  322. /* copregister rd <- rt */
  323. u32 value;
  324. if (MIPSInst_RT(ir) == 0)
  325. value = 0;
  326. else
  327. value = xcp->regs[MIPSInst_RT(ir)];
  328. /* we only have one writable control reg
  329. */
  330. if (MIPSInst_RD(ir) == FPCREG_CSR) {
  331. #ifdef CSRTRACE
  332. printk("%p gpr[%d]->csr=%08x\n",
  333. (void *) (xcp->cp0_epc),
  334. MIPSInst_RT(ir), value);
  335. #endif
  336. value &= (FPU_CSR_FLUSH | FPU_CSR_ALL_E | FPU_CSR_ALL_S | 0x03);
  337. ctx->fcr31 &= ~(FPU_CSR_FLUSH | FPU_CSR_ALL_E | FPU_CSR_ALL_S | 0x03);
  338. /* convert to ieee library modes */
  339. ctx->fcr31 |= (value & ~0x3) | ieee_rm[value & 0x3];
  340. }
  341. if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) {
  342. return SIGFPE;
  343. }
  344. break;
  345. }
  346. case bc_op:{
  347. int likely = 0;
  348. if (xcp->cp0_cause & CAUSEF_BD)
  349. return SIGILL;
  350. #if __mips >= 4
  351. cond = ctx->fcr31 & fpucondbit[MIPSInst_RT(ir) >> 2];
  352. #else
  353. cond = ctx->fcr31 & FPU_CSR_COND;
  354. #endif
  355. switch (MIPSInst_RT(ir) & 3) {
  356. case bcfl_op:
  357. likely = 1;
  358. case bcf_op:
  359. cond = !cond;
  360. break;
  361. case bctl_op:
  362. likely = 1;
  363. case bct_op:
  364. break;
  365. default:
  366. /* thats an illegal instruction */
  367. return SIGILL;
  368. }
  369. xcp->cp0_cause |= CAUSEF_BD;
  370. if (cond) {
  371. /* branch taken: emulate dslot
  372. * instruction
  373. */
  374. xcp->cp0_epc += 4;
  375. contpc = (xcp->cp0_epc +
  376. (MIPSInst_SIMM(ir) << 2));
  377. if (get_user(ir,
  378. (mips_instruction __user *) xcp->cp0_epc)) {
  379. fpuemustats.errors++;
  380. return SIGBUS;
  381. }
  382. switch (MIPSInst_OPCODE(ir)) {
  383. case lwc1_op:
  384. case swc1_op:
  385. #if (__mips >= 2 || defined(__mips64))
  386. case ldc1_op:
  387. case sdc1_op:
  388. #endif
  389. case cop1_op:
  390. #if __mips >= 4 && __mips != 32
  391. case cop1x_op:
  392. #endif
  393. /* its one of ours */
  394. goto emul;
  395. #if __mips >= 4
  396. case spec_op:
  397. if (MIPSInst_FUNC(ir) == movc_op)
  398. goto emul;
  399. break;
  400. #endif
  401. }
  402. /*
  403. * Single step the non-cp1
  404. * instruction in the dslot
  405. */
  406. return mips_dsemul(xcp, ir, contpc);
  407. }
  408. else {
  409. /* branch not taken */
  410. if (likely) {
  411. /*
  412. * branch likely nullifies
  413. * dslot if not taken
  414. */
  415. xcp->cp0_epc += 4;
  416. contpc += 4;
  417. /*
  418. * else continue & execute
  419. * dslot as normal insn
  420. */
  421. }
  422. }
  423. break;
  424. }
  425. default:
  426. if (!(MIPSInst_RS(ir) & 0x10))
  427. return SIGILL;
  428. {
  429. int sig;
  430. /* a real fpu computation instruction */
  431. if ((sig = fpu_emu(xcp, ctx, ir)))
  432. return sig;
  433. }
  434. }
  435. break;
  436. #if __mips >= 4 && __mips != 32
  437. case cop1x_op:{
  438. int sig;
  439. if ((sig = fpux_emu(xcp, ctx, ir)))
  440. return sig;
  441. break;
  442. }
  443. #endif
  444. #if __mips >= 4
  445. case spec_op:
  446. if (MIPSInst_FUNC(ir) != movc_op)
  447. return SIGILL;
  448. cond = fpucondbit[MIPSInst_RT(ir) >> 2];
  449. if (((ctx->fcr31 & cond) != 0) == ((MIPSInst_RT(ir) & 1) != 0))
  450. xcp->regs[MIPSInst_RD(ir)] =
  451. xcp->regs[MIPSInst_RS(ir)];
  452. break;
  453. #endif
  454. default:
  455. return SIGILL;
  456. }
  457. /* we did it !! */
  458. xcp->cp0_epc = contpc;
  459. xcp->cp0_cause &= ~CAUSEF_BD;
  460. return 0;
  461. }
  462. /*
  463. * Conversion table from MIPS compare ops 48-63
  464. * cond = ieee754dp_cmp(x,y,IEEE754_UN,sig);
  465. */
  466. static const unsigned char cmptab[8] = {
  467. 0, /* cmp_0 (sig) cmp_sf */
  468. IEEE754_CUN, /* cmp_un (sig) cmp_ngle */
  469. IEEE754_CEQ, /* cmp_eq (sig) cmp_seq */
  470. IEEE754_CEQ | IEEE754_CUN, /* cmp_ueq (sig) cmp_ngl */
  471. IEEE754_CLT, /* cmp_olt (sig) cmp_lt */
  472. IEEE754_CLT | IEEE754_CUN, /* cmp_ult (sig) cmp_nge */
  473. IEEE754_CLT | IEEE754_CEQ, /* cmp_ole (sig) cmp_le */
  474. IEEE754_CLT | IEEE754_CEQ | IEEE754_CUN, /* cmp_ule (sig) cmp_ngt */
  475. };
  476. #if __mips >= 4 && __mips != 32
  477. /*
  478. * Additional MIPS4 instructions
  479. */
  480. #define DEF3OP(name, p, f1, f2, f3) \
  481. static ieee754##p fpemu_##p##_##name(ieee754##p r, ieee754##p s, \
  482. ieee754##p t) \
  483. { \
  484. struct _ieee754_csr ieee754_csr_save; \
  485. s = f1(s, t); \
  486. ieee754_csr_save = ieee754_csr; \
  487. s = f2(s, r); \
  488. ieee754_csr_save.cx |= ieee754_csr.cx; \
  489. ieee754_csr_save.sx |= ieee754_csr.sx; \
  490. s = f3(s); \
  491. ieee754_csr.cx |= ieee754_csr_save.cx; \
  492. ieee754_csr.sx |= ieee754_csr_save.sx; \
  493. return s; \
  494. }
  495. static ieee754dp fpemu_dp_recip(ieee754dp d)
  496. {
  497. return ieee754dp_div(ieee754dp_one(0), d);
  498. }
  499. static ieee754dp fpemu_dp_rsqrt(ieee754dp d)
  500. {
  501. return ieee754dp_div(ieee754dp_one(0), ieee754dp_sqrt(d));
  502. }
  503. static ieee754sp fpemu_sp_recip(ieee754sp s)
  504. {
  505. return ieee754sp_div(ieee754sp_one(0), s);
  506. }
  507. static ieee754sp fpemu_sp_rsqrt(ieee754sp s)
  508. {
  509. return ieee754sp_div(ieee754sp_one(0), ieee754sp_sqrt(s));
  510. }
  511. DEF3OP(madd, sp, ieee754sp_mul, ieee754sp_add, );
  512. DEF3OP(msub, sp, ieee754sp_mul, ieee754sp_sub, );
  513. DEF3OP(nmadd, sp, ieee754sp_mul, ieee754sp_add, ieee754sp_neg);
  514. DEF3OP(nmsub, sp, ieee754sp_mul, ieee754sp_sub, ieee754sp_neg);
  515. DEF3OP(madd, dp, ieee754dp_mul, ieee754dp_add, );
  516. DEF3OP(msub, dp, ieee754dp_mul, ieee754dp_sub, );
  517. DEF3OP(nmadd, dp, ieee754dp_mul, ieee754dp_add, ieee754dp_neg);
  518. DEF3OP(nmsub, dp, ieee754dp_mul, ieee754dp_sub, ieee754dp_neg);
  519. static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
  520. mips_instruction ir)
  521. {
  522. unsigned rcsr = 0; /* resulting csr */
  523. fpuemustats.cp1xops++;
  524. switch (MIPSInst_FMA_FFMT(ir)) {
  525. case s_fmt:{ /* 0 */
  526. ieee754sp(*handler) (ieee754sp, ieee754sp, ieee754sp);
  527. ieee754sp fd, fr, fs, ft;
  528. u32 __user *va;
  529. u32 val;
  530. switch (MIPSInst_FUNC(ir)) {
  531. case lwxc1_op:
  532. va = (void __user *) (xcp->regs[MIPSInst_FR(ir)] +
  533. xcp->regs[MIPSInst_FT(ir)]);
  534. fpuemustats.loads++;
  535. if (get_user(val, va)) {
  536. fpuemustats.errors++;
  537. return SIGBUS;
  538. }
  539. SITOREG(val, MIPSInst_FD(ir));
  540. break;
  541. case swxc1_op:
  542. va = (void __user *) (xcp->regs[MIPSInst_FR(ir)] +
  543. xcp->regs[MIPSInst_FT(ir)]);
  544. fpuemustats.stores++;
  545. SIFROMREG(val, MIPSInst_FS(ir));
  546. if (put_user(val, va)) {
  547. fpuemustats.errors++;
  548. return SIGBUS;
  549. }
  550. break;
  551. case madd_s_op:
  552. handler = fpemu_sp_madd;
  553. goto scoptop;
  554. case msub_s_op:
  555. handler = fpemu_sp_msub;
  556. goto scoptop;
  557. case nmadd_s_op:
  558. handler = fpemu_sp_nmadd;
  559. goto scoptop;
  560. case nmsub_s_op:
  561. handler = fpemu_sp_nmsub;
  562. goto scoptop;
  563. scoptop:
  564. SPFROMREG(fr, MIPSInst_FR(ir));
  565. SPFROMREG(fs, MIPSInst_FS(ir));
  566. SPFROMREG(ft, MIPSInst_FT(ir));
  567. fd = (*handler) (fr, fs, ft);
  568. SPTOREG(fd, MIPSInst_FD(ir));
  569. copcsr:
  570. if (ieee754_cxtest(IEEE754_INEXACT))
  571. rcsr |= FPU_CSR_INE_X | FPU_CSR_INE_S;
  572. if (ieee754_cxtest(IEEE754_UNDERFLOW))
  573. rcsr |= FPU_CSR_UDF_X | FPU_CSR_UDF_S;
  574. if (ieee754_cxtest(IEEE754_OVERFLOW))
  575. rcsr |= FPU_CSR_OVF_X | FPU_CSR_OVF_S;
  576. if (ieee754_cxtest(IEEE754_INVALID_OPERATION))
  577. rcsr |= FPU_CSR_INV_X | FPU_CSR_INV_S;
  578. ctx->fcr31 = (ctx->fcr31 & ~FPU_CSR_ALL_X) | rcsr;
  579. if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) {
  580. /*printk ("SIGFPE: fpu csr = %08x\n",
  581. ctx->fcr31); */
  582. return SIGFPE;
  583. }
  584. break;
  585. default:
  586. return SIGILL;
  587. }
  588. break;
  589. }
  590. case d_fmt:{ /* 1 */
  591. ieee754dp(*handler) (ieee754dp, ieee754dp, ieee754dp);
  592. ieee754dp fd, fr, fs, ft;
  593. u64 __user *va;
  594. u64 val;
  595. switch (MIPSInst_FUNC(ir)) {
  596. case ldxc1_op:
  597. va = (void __user *) (xcp->regs[MIPSInst_FR(ir)] +
  598. xcp->regs[MIPSInst_FT(ir)]);
  599. fpuemustats.loads++;
  600. if (get_user(val, va)) {
  601. fpuemustats.errors++;
  602. return SIGBUS;
  603. }
  604. DITOREG(val, MIPSInst_FD(ir));
  605. break;
  606. case sdxc1_op:
  607. va = (void __user *) (xcp->regs[MIPSInst_FR(ir)] +
  608. xcp->regs[MIPSInst_FT(ir)]);
  609. fpuemustats.stores++;
  610. DIFROMREG(val, MIPSInst_FS(ir));
  611. if (put_user(val, va)) {
  612. fpuemustats.errors++;
  613. return SIGBUS;
  614. }
  615. break;
  616. case madd_d_op:
  617. handler = fpemu_dp_madd;
  618. goto dcoptop;
  619. case msub_d_op:
  620. handler = fpemu_dp_msub;
  621. goto dcoptop;
  622. case nmadd_d_op:
  623. handler = fpemu_dp_nmadd;
  624. goto dcoptop;
  625. case nmsub_d_op:
  626. handler = fpemu_dp_nmsub;
  627. goto dcoptop;
  628. dcoptop:
  629. DPFROMREG(fr, MIPSInst_FR(ir));
  630. DPFROMREG(fs, MIPSInst_FS(ir));
  631. DPFROMREG(ft, MIPSInst_FT(ir));
  632. fd = (*handler) (fr, fs, ft);
  633. DPTOREG(fd, MIPSInst_FD(ir));
  634. goto copcsr;
  635. default:
  636. return SIGILL;
  637. }
  638. break;
  639. }
  640. case 0x7: /* 7 */
  641. if (MIPSInst_FUNC(ir) != pfetch_op) {
  642. return SIGILL;
  643. }
  644. /* ignore prefx operation */
  645. break;
  646. default:
  647. return SIGILL;
  648. }
  649. return 0;
  650. }
  651. #endif
  652. /*
  653. * Emulate a single COP1 arithmetic instruction.
  654. */
  655. static int fpu_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
  656. mips_instruction ir)
  657. {
  658. int rfmt; /* resulting format */
  659. unsigned rcsr = 0; /* resulting csr */
  660. unsigned cond;
  661. union {
  662. ieee754dp d;
  663. ieee754sp s;
  664. int w;
  665. #ifdef __mips64
  666. s64 l;
  667. #endif
  668. } rv; /* resulting value */
  669. fpuemustats.cp1ops++;
  670. switch (rfmt = (MIPSInst_FFMT(ir) & 0xf)) {
  671. case s_fmt:{ /* 0 */
  672. union {
  673. ieee754sp(*b) (ieee754sp, ieee754sp);
  674. ieee754sp(*u) (ieee754sp);
  675. } handler;
  676. switch (MIPSInst_FUNC(ir)) {
  677. /* binary ops */
  678. case fadd_op:
  679. handler.b = ieee754sp_add;
  680. goto scopbop;
  681. case fsub_op:
  682. handler.b = ieee754sp_sub;
  683. goto scopbop;
  684. case fmul_op:
  685. handler.b = ieee754sp_mul;
  686. goto scopbop;
  687. case fdiv_op:
  688. handler.b = ieee754sp_div;
  689. goto scopbop;
  690. /* unary ops */
  691. #if __mips >= 2 || defined(__mips64)
  692. case fsqrt_op:
  693. handler.u = ieee754sp_sqrt;
  694. goto scopuop;
  695. #endif
  696. #if __mips >= 4 && __mips != 32
  697. case frsqrt_op:
  698. handler.u = fpemu_sp_rsqrt;
  699. goto scopuop;
  700. case frecip_op:
  701. handler.u = fpemu_sp_recip;
  702. goto scopuop;
  703. #endif
  704. #if __mips >= 4
  705. case fmovc_op:
  706. cond = fpucondbit[MIPSInst_FT(ir) >> 2];
  707. if (((ctx->fcr31 & cond) != 0) !=
  708. ((MIPSInst_FT(ir) & 1) != 0))
  709. return 0;
  710. SPFROMREG(rv.s, MIPSInst_FS(ir));
  711. break;
  712. case fmovz_op:
  713. if (xcp->regs[MIPSInst_FT(ir)] != 0)
  714. return 0;
  715. SPFROMREG(rv.s, MIPSInst_FS(ir));
  716. break;
  717. case fmovn_op:
  718. if (xcp->regs[MIPSInst_FT(ir)] == 0)
  719. return 0;
  720. SPFROMREG(rv.s, MIPSInst_FS(ir));
  721. break;
  722. #endif
  723. case fabs_op:
  724. handler.u = ieee754sp_abs;
  725. goto scopuop;
  726. case fneg_op:
  727. handler.u = ieee754sp_neg;
  728. goto scopuop;
  729. case fmov_op:
  730. /* an easy one */
  731. SPFROMREG(rv.s, MIPSInst_FS(ir));
  732. goto copcsr;
  733. /* binary op on handler */
  734. scopbop:
  735. {
  736. ieee754sp fs, ft;
  737. SPFROMREG(fs, MIPSInst_FS(ir));
  738. SPFROMREG(ft, MIPSInst_FT(ir));
  739. rv.s = (*handler.b) (fs, ft);
  740. goto copcsr;
  741. }
  742. scopuop:
  743. {
  744. ieee754sp fs;
  745. SPFROMREG(fs, MIPSInst_FS(ir));
  746. rv.s = (*handler.u) (fs);
  747. goto copcsr;
  748. }
  749. copcsr:
  750. if (ieee754_cxtest(IEEE754_INEXACT))
  751. rcsr |= FPU_CSR_INE_X | FPU_CSR_INE_S;
  752. if (ieee754_cxtest(IEEE754_UNDERFLOW))
  753. rcsr |= FPU_CSR_UDF_X | FPU_CSR_UDF_S;
  754. if (ieee754_cxtest(IEEE754_OVERFLOW))
  755. rcsr |= FPU_CSR_OVF_X | FPU_CSR_OVF_S;
  756. if (ieee754_cxtest(IEEE754_ZERO_DIVIDE))
  757. rcsr |= FPU_CSR_DIV_X | FPU_CSR_DIV_S;
  758. if (ieee754_cxtest(IEEE754_INVALID_OPERATION))
  759. rcsr |= FPU_CSR_INV_X | FPU_CSR_INV_S;
  760. break;
  761. /* unary conv ops */
  762. case fcvts_op:
  763. return SIGILL; /* not defined */
  764. case fcvtd_op:{
  765. ieee754sp fs;
  766. SPFROMREG(fs, MIPSInst_FS(ir));
  767. rv.d = ieee754dp_fsp(fs);
  768. rfmt = d_fmt;
  769. goto copcsr;
  770. }
  771. case fcvtw_op:{
  772. ieee754sp fs;
  773. SPFROMREG(fs, MIPSInst_FS(ir));
  774. rv.w = ieee754sp_tint(fs);
  775. rfmt = w_fmt;
  776. goto copcsr;
  777. }
  778. #if __mips >= 2 || defined(__mips64)
  779. case fround_op:
  780. case ftrunc_op:
  781. case fceil_op:
  782. case ffloor_op:{
  783. unsigned int oldrm = ieee754_csr.rm;
  784. ieee754sp fs;
  785. SPFROMREG(fs, MIPSInst_FS(ir));
  786. ieee754_csr.rm = ieee_rm[MIPSInst_FUNC(ir) & 0x3];
  787. rv.w = ieee754sp_tint(fs);
  788. ieee754_csr.rm = oldrm;
  789. rfmt = w_fmt;
  790. goto copcsr;
  791. }
  792. #endif /* __mips >= 2 */
  793. #if defined(__mips64)
  794. case fcvtl_op:{
  795. ieee754sp fs;
  796. SPFROMREG(fs, MIPSInst_FS(ir));
  797. rv.l = ieee754sp_tlong(fs);
  798. rfmt = l_fmt;
  799. goto copcsr;
  800. }
  801. case froundl_op:
  802. case ftruncl_op:
  803. case fceill_op:
  804. case ffloorl_op:{
  805. unsigned int oldrm = ieee754_csr.rm;
  806. ieee754sp fs;
  807. SPFROMREG(fs, MIPSInst_FS(ir));
  808. ieee754_csr.rm = ieee_rm[MIPSInst_FUNC(ir) & 0x3];
  809. rv.l = ieee754sp_tlong(fs);
  810. ieee754_csr.rm = oldrm;
  811. rfmt = l_fmt;
  812. goto copcsr;
  813. }
  814. #endif /* defined(__mips64) */
  815. default:
  816. if (MIPSInst_FUNC(ir) >= fcmp_op) {
  817. unsigned cmpop = MIPSInst_FUNC(ir) - fcmp_op;
  818. ieee754sp fs, ft;
  819. SPFROMREG(fs, MIPSInst_FS(ir));
  820. SPFROMREG(ft, MIPSInst_FT(ir));
  821. rv.w = ieee754sp_cmp(fs, ft,
  822. cmptab[cmpop & 0x7], cmpop & 0x8);
  823. rfmt = -1;
  824. if ((cmpop & 0x8) && ieee754_cxtest
  825. (IEEE754_INVALID_OPERATION))
  826. rcsr = FPU_CSR_INV_X | FPU_CSR_INV_S;
  827. else
  828. goto copcsr;
  829. }
  830. else {
  831. return SIGILL;
  832. }
  833. break;
  834. }
  835. break;
  836. }
  837. case d_fmt:{
  838. union {
  839. ieee754dp(*b) (ieee754dp, ieee754dp);
  840. ieee754dp(*u) (ieee754dp);
  841. } handler;
  842. switch (MIPSInst_FUNC(ir)) {
  843. /* binary ops */
  844. case fadd_op:
  845. handler.b = ieee754dp_add;
  846. goto dcopbop;
  847. case fsub_op:
  848. handler.b = ieee754dp_sub;
  849. goto dcopbop;
  850. case fmul_op:
  851. handler.b = ieee754dp_mul;
  852. goto dcopbop;
  853. case fdiv_op:
  854. handler.b = ieee754dp_div;
  855. goto dcopbop;
  856. /* unary ops */
  857. #if __mips >= 2 || defined(__mips64)
  858. case fsqrt_op:
  859. handler.u = ieee754dp_sqrt;
  860. goto dcopuop;
  861. #endif
  862. #if __mips >= 4 && __mips != 32
  863. case frsqrt_op:
  864. handler.u = fpemu_dp_rsqrt;
  865. goto dcopuop;
  866. case frecip_op:
  867. handler.u = fpemu_dp_recip;
  868. goto dcopuop;
  869. #endif
  870. #if __mips >= 4
  871. case fmovc_op:
  872. cond = fpucondbit[MIPSInst_FT(ir) >> 2];
  873. if (((ctx->fcr31 & cond) != 0) !=
  874. ((MIPSInst_FT(ir) & 1) != 0))
  875. return 0;
  876. DPFROMREG(rv.d, MIPSInst_FS(ir));
  877. break;
  878. case fmovz_op:
  879. if (xcp->regs[MIPSInst_FT(ir)] != 0)
  880. return 0;
  881. DPFROMREG(rv.d, MIPSInst_FS(ir));
  882. break;
  883. case fmovn_op:
  884. if (xcp->regs[MIPSInst_FT(ir)] == 0)
  885. return 0;
  886. DPFROMREG(rv.d, MIPSInst_FS(ir));
  887. break;
  888. #endif
  889. case fabs_op:
  890. handler.u = ieee754dp_abs;
  891. goto dcopuop;
  892. case fneg_op:
  893. handler.u = ieee754dp_neg;
  894. goto dcopuop;
  895. case fmov_op:
  896. /* an easy one */
  897. DPFROMREG(rv.d, MIPSInst_FS(ir));
  898. goto copcsr;
  899. /* binary op on handler */
  900. dcopbop:{
  901. ieee754dp fs, ft;
  902. DPFROMREG(fs, MIPSInst_FS(ir));
  903. DPFROMREG(ft, MIPSInst_FT(ir));
  904. rv.d = (*handler.b) (fs, ft);
  905. goto copcsr;
  906. }
  907. dcopuop:{
  908. ieee754dp fs;
  909. DPFROMREG(fs, MIPSInst_FS(ir));
  910. rv.d = (*handler.u) (fs);
  911. goto copcsr;
  912. }
  913. /* unary conv ops */
  914. case fcvts_op:{
  915. ieee754dp fs;
  916. DPFROMREG(fs, MIPSInst_FS(ir));
  917. rv.s = ieee754sp_fdp(fs);
  918. rfmt = s_fmt;
  919. goto copcsr;
  920. }
  921. case fcvtd_op:
  922. return SIGILL; /* not defined */
  923. case fcvtw_op:{
  924. ieee754dp fs;
  925. DPFROMREG(fs, MIPSInst_FS(ir));
  926. rv.w = ieee754dp_tint(fs); /* wrong */
  927. rfmt = w_fmt;
  928. goto copcsr;
  929. }
  930. #if __mips >= 2 || defined(__mips64)
  931. case fround_op:
  932. case ftrunc_op:
  933. case fceil_op:
  934. case ffloor_op:{
  935. unsigned int oldrm = ieee754_csr.rm;
  936. ieee754dp fs;
  937. DPFROMREG(fs, MIPSInst_FS(ir));
  938. ieee754_csr.rm = ieee_rm[MIPSInst_FUNC(ir) & 0x3];
  939. rv.w = ieee754dp_tint(fs);
  940. ieee754_csr.rm = oldrm;
  941. rfmt = w_fmt;
  942. goto copcsr;
  943. }
  944. #endif
  945. #if defined(__mips64)
  946. case fcvtl_op:{
  947. ieee754dp fs;
  948. DPFROMREG(fs, MIPSInst_FS(ir));
  949. rv.l = ieee754dp_tlong(fs);
  950. rfmt = l_fmt;
  951. goto copcsr;
  952. }
  953. case froundl_op:
  954. case ftruncl_op:
  955. case fceill_op:
  956. case ffloorl_op:{
  957. unsigned int oldrm = ieee754_csr.rm;
  958. ieee754dp fs;
  959. DPFROMREG(fs, MIPSInst_FS(ir));
  960. ieee754_csr.rm = ieee_rm[MIPSInst_FUNC(ir) & 0x3];
  961. rv.l = ieee754dp_tlong(fs);
  962. ieee754_csr.rm = oldrm;
  963. rfmt = l_fmt;
  964. goto copcsr;
  965. }
  966. #endif /* __mips >= 3 */
  967. default:
  968. if (MIPSInst_FUNC(ir) >= fcmp_op) {
  969. unsigned cmpop = MIPSInst_FUNC(ir) - fcmp_op;
  970. ieee754dp fs, ft;
  971. DPFROMREG(fs, MIPSInst_FS(ir));
  972. DPFROMREG(ft, MIPSInst_FT(ir));
  973. rv.w = ieee754dp_cmp(fs, ft,
  974. cmptab[cmpop & 0x7], cmpop & 0x8);
  975. rfmt = -1;
  976. if ((cmpop & 0x8)
  977. &&
  978. ieee754_cxtest
  979. (IEEE754_INVALID_OPERATION))
  980. rcsr = FPU_CSR_INV_X | FPU_CSR_INV_S;
  981. else
  982. goto copcsr;
  983. }
  984. else {
  985. return SIGILL;
  986. }
  987. break;
  988. }
  989. break;
  990. }
  991. case w_fmt:{
  992. ieee754sp fs;
  993. switch (MIPSInst_FUNC(ir)) {
  994. case fcvts_op:
  995. /* convert word to single precision real */
  996. SPFROMREG(fs, MIPSInst_FS(ir));
  997. rv.s = ieee754sp_fint(fs.bits);
  998. rfmt = s_fmt;
  999. goto copcsr;
  1000. case fcvtd_op:
  1001. /* convert word to double precision real */
  1002. SPFROMREG(fs, MIPSInst_FS(ir));
  1003. rv.d = ieee754dp_fint(fs.bits);
  1004. rfmt = d_fmt;
  1005. goto copcsr;
  1006. default:
  1007. return SIGILL;
  1008. }
  1009. break;
  1010. }
  1011. #if defined(__mips64)
  1012. case l_fmt:{
  1013. switch (MIPSInst_FUNC(ir)) {
  1014. case fcvts_op:
  1015. /* convert long to single precision real */
  1016. rv.s = ieee754sp_flong(ctx->fpr[MIPSInst_FS(ir)]);
  1017. rfmt = s_fmt;
  1018. goto copcsr;
  1019. case fcvtd_op:
  1020. /* convert long to double precision real */
  1021. rv.d = ieee754dp_flong(ctx->fpr[MIPSInst_FS(ir)]);
  1022. rfmt = d_fmt;
  1023. goto copcsr;
  1024. default:
  1025. return SIGILL;
  1026. }
  1027. break;
  1028. }
  1029. #endif
  1030. default:
  1031. return SIGILL;
  1032. }
  1033. /*
  1034. * Update the fpu CSR register for this operation.
  1035. * If an exception is required, generate a tidy SIGFPE exception,
  1036. * without updating the result register.
  1037. * Note: cause exception bits do not accumulate, they are rewritten
  1038. * for each op; only the flag/sticky bits accumulate.
  1039. */
  1040. ctx->fcr31 = (ctx->fcr31 & ~FPU_CSR_ALL_X) | rcsr;
  1041. if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) {
  1042. /*printk ("SIGFPE: fpu csr = %08x\n",ctx->fcr31); */
  1043. return SIGFPE;
  1044. }
  1045. /*
  1046. * Now we can safely write the result back to the register file.
  1047. */
  1048. switch (rfmt) {
  1049. case -1:{
  1050. #if __mips >= 4
  1051. cond = fpucondbit[MIPSInst_FD(ir) >> 2];
  1052. #else
  1053. cond = FPU_CSR_COND;
  1054. #endif
  1055. if (rv.w)
  1056. ctx->fcr31 |= cond;
  1057. else
  1058. ctx->fcr31 &= ~cond;
  1059. break;
  1060. }
  1061. case d_fmt:
  1062. DPTOREG(rv.d, MIPSInst_FD(ir));
  1063. break;
  1064. case s_fmt:
  1065. SPTOREG(rv.s, MIPSInst_FD(ir));
  1066. break;
  1067. case w_fmt:
  1068. SITOREG(rv.w, MIPSInst_FD(ir));
  1069. break;
  1070. #if defined(__mips64)
  1071. case l_fmt:
  1072. DITOREG(rv.l, MIPSInst_FD(ir));
  1073. break;
  1074. #endif
  1075. default:
  1076. return SIGILL;
  1077. }
  1078. return 0;
  1079. }
  1080. int fpu_emulator_cop1Handler(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
  1081. int has_fpu)
  1082. {
  1083. unsigned long oldepc, prevepc;
  1084. mips_instruction insn;
  1085. int sig = 0;
  1086. oldepc = xcp->cp0_epc;
  1087. do {
  1088. prevepc = xcp->cp0_epc;
  1089. if (get_user(insn, (mips_instruction __user *) xcp->cp0_epc)) {
  1090. fpuemustats.errors++;
  1091. return SIGBUS;
  1092. }
  1093. if (insn == 0)
  1094. xcp->cp0_epc += 4; /* skip nops */
  1095. else {
  1096. /*
  1097. * The 'ieee754_csr' is an alias of
  1098. * ctx->fcr31. No need to copy ctx->fcr31 to
  1099. * ieee754_csr. But ieee754_csr.rm is ieee
  1100. * library modes. (not mips rounding mode)
  1101. */
  1102. /* convert to ieee library modes */
  1103. ieee754_csr.rm = ieee_rm[ieee754_csr.rm];
  1104. sig = cop1Emulate(xcp, ctx);
  1105. /* revert to mips rounding mode */
  1106. ieee754_csr.rm = mips_rm[ieee754_csr.rm];
  1107. }
  1108. if (has_fpu)
  1109. break;
  1110. if (sig)
  1111. break;
  1112. cond_resched();
  1113. } while (xcp->cp0_epc > prevepc);
  1114. /* SIGILL indicates a non-fpu instruction */
  1115. if (sig == SIGILL && xcp->cp0_epc != oldepc)
  1116. /* but if epc has advanced, then ignore it */
  1117. sig = 0;
  1118. return sig;
  1119. }
  1120. #ifdef CONFIG_DEBUG_FS
  1121. extern struct dentry *mips_debugfs_dir;
  1122. static int __init debugfs_fpuemu(void)
  1123. {
  1124. struct dentry *d, *dir;
  1125. int i;
  1126. static struct {
  1127. const char *name;
  1128. unsigned int *v;
  1129. } vars[] __initdata = {
  1130. { "emulated", &fpuemustats.emulated },
  1131. { "loads", &fpuemustats.loads },
  1132. { "stores", &fpuemustats.stores },
  1133. { "cp1ops", &fpuemustats.cp1ops },
  1134. { "cp1xops", &fpuemustats.cp1xops },
  1135. { "errors", &fpuemustats.errors },
  1136. };
  1137. if (!mips_debugfs_dir)
  1138. return -ENODEV;
  1139. dir = debugfs_create_dir("fpuemustats", mips_debugfs_dir);
  1140. if (!dir)
  1141. return -ENOMEM;
  1142. for (i = 0; i < ARRAY_SIZE(vars); i++) {
  1143. d = debugfs_create_u32(vars[i].name, S_IRUGO, dir, vars[i].v);
  1144. if (!d)
  1145. return -ENOMEM;
  1146. }
  1147. return 0;
  1148. }
  1149. __initcall(debugfs_fpuemu);
  1150. #endif