cp1emu.c 28 KB

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