branch.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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) 1996, 97, 2000, 2001 by Ralf Baechle
  7. * Copyright (C) 2001 MIPS Technologies, Inc.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/signal.h>
  12. #include <linux/module.h>
  13. #include <asm/branch.h>
  14. #include <asm/cpu.h>
  15. #include <asm/cpu-features.h>
  16. #include <asm/fpu.h>
  17. #include <asm/fpu_emulator.h>
  18. #include <asm/inst.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/uaccess.h>
  21. /*
  22. * Calculate and return exception PC in case of branch delay slot
  23. * for microMIPS and MIPS16e. It does not clear the ISA mode bit.
  24. */
  25. int __isa_exception_epc(struct pt_regs *regs)
  26. {
  27. unsigned short inst;
  28. long epc = regs->cp0_epc;
  29. /* Calculate exception PC in branch delay slot. */
  30. if (__get_user(inst, (u16 __user *) msk_isa16_mode(epc))) {
  31. /* This should never happen because delay slot was checked. */
  32. force_sig(SIGSEGV, current);
  33. return epc;
  34. }
  35. if (cpu_has_mips16) {
  36. if (((union mips16e_instruction)inst).ri.opcode
  37. == MIPS16e_jal_op)
  38. epc += 4;
  39. else
  40. epc += 2;
  41. } else if (mm_insn_16bit(inst))
  42. epc += 2;
  43. else
  44. epc += 4;
  45. return epc;
  46. }
  47. /* (microMIPS) Convert 16-bit register encoding to 32-bit register encoding. */
  48. static const unsigned int reg16to32map[8] = {16, 17, 2, 3, 4, 5, 6, 7};
  49. int __mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
  50. unsigned long *contpc)
  51. {
  52. union mips_instruction insn = (union mips_instruction)dec_insn.insn;
  53. int bc_false = 0;
  54. unsigned int fcr31;
  55. unsigned int bit;
  56. if (!cpu_has_mmips)
  57. return 0;
  58. switch (insn.mm_i_format.opcode) {
  59. case mm_pool32a_op:
  60. if ((insn.mm_i_format.simmediate & MM_POOL32A_MINOR_MASK) ==
  61. mm_pool32axf_op) {
  62. switch (insn.mm_i_format.simmediate >>
  63. MM_POOL32A_MINOR_SHIFT) {
  64. case mm_jalr_op:
  65. case mm_jalrhb_op:
  66. case mm_jalrs_op:
  67. case mm_jalrshb_op:
  68. if (insn.mm_i_format.rt != 0) /* Not mm_jr */
  69. regs->regs[insn.mm_i_format.rt] =
  70. regs->cp0_epc +
  71. dec_insn.pc_inc +
  72. dec_insn.next_pc_inc;
  73. *contpc = regs->regs[insn.mm_i_format.rs];
  74. return 1;
  75. }
  76. }
  77. break;
  78. case mm_pool32i_op:
  79. switch (insn.mm_i_format.rt) {
  80. case mm_bltzals_op:
  81. case mm_bltzal_op:
  82. regs->regs[31] = regs->cp0_epc +
  83. dec_insn.pc_inc +
  84. dec_insn.next_pc_inc;
  85. /* Fall through */
  86. case mm_bltz_op:
  87. if ((long)regs->regs[insn.mm_i_format.rs] < 0)
  88. *contpc = regs->cp0_epc +
  89. dec_insn.pc_inc +
  90. (insn.mm_i_format.simmediate << 1);
  91. else
  92. *contpc = regs->cp0_epc +
  93. dec_insn.pc_inc +
  94. dec_insn.next_pc_inc;
  95. return 1;
  96. case mm_bgezals_op:
  97. case mm_bgezal_op:
  98. regs->regs[31] = regs->cp0_epc +
  99. dec_insn.pc_inc +
  100. dec_insn.next_pc_inc;
  101. /* Fall through */
  102. case mm_bgez_op:
  103. if ((long)regs->regs[insn.mm_i_format.rs] >= 0)
  104. *contpc = regs->cp0_epc +
  105. dec_insn.pc_inc +
  106. (insn.mm_i_format.simmediate << 1);
  107. else
  108. *contpc = regs->cp0_epc +
  109. dec_insn.pc_inc +
  110. dec_insn.next_pc_inc;
  111. return 1;
  112. case mm_blez_op:
  113. if ((long)regs->regs[insn.mm_i_format.rs] <= 0)
  114. *contpc = regs->cp0_epc +
  115. dec_insn.pc_inc +
  116. (insn.mm_i_format.simmediate << 1);
  117. else
  118. *contpc = regs->cp0_epc +
  119. dec_insn.pc_inc +
  120. dec_insn.next_pc_inc;
  121. return 1;
  122. case mm_bgtz_op:
  123. if ((long)regs->regs[insn.mm_i_format.rs] <= 0)
  124. *contpc = regs->cp0_epc +
  125. dec_insn.pc_inc +
  126. (insn.mm_i_format.simmediate << 1);
  127. else
  128. *contpc = regs->cp0_epc +
  129. dec_insn.pc_inc +
  130. dec_insn.next_pc_inc;
  131. return 1;
  132. case mm_bc2f_op:
  133. case mm_bc1f_op:
  134. bc_false = 1;
  135. /* Fall through */
  136. case mm_bc2t_op:
  137. case mm_bc1t_op:
  138. preempt_disable();
  139. if (is_fpu_owner())
  140. asm volatile("cfc1\t%0,$31" : "=r" (fcr31));
  141. else
  142. fcr31 = current->thread.fpu.fcr31;
  143. preempt_enable();
  144. if (bc_false)
  145. fcr31 = ~fcr31;
  146. bit = (insn.mm_i_format.rs >> 2);
  147. bit += (bit != 0);
  148. bit += 23;
  149. if (fcr31 & (1 << bit))
  150. *contpc = regs->cp0_epc +
  151. dec_insn.pc_inc +
  152. (insn.mm_i_format.simmediate << 1);
  153. else
  154. *contpc = regs->cp0_epc +
  155. dec_insn.pc_inc + dec_insn.next_pc_inc;
  156. return 1;
  157. }
  158. break;
  159. case mm_pool16c_op:
  160. switch (insn.mm_i_format.rt) {
  161. case mm_jalr16_op:
  162. case mm_jalrs16_op:
  163. regs->regs[31] = regs->cp0_epc +
  164. dec_insn.pc_inc + dec_insn.next_pc_inc;
  165. /* Fall through */
  166. case mm_jr16_op:
  167. *contpc = regs->regs[insn.mm_i_format.rs];
  168. return 1;
  169. }
  170. break;
  171. case mm_beqz16_op:
  172. if ((long)regs->regs[reg16to32map[insn.mm_b1_format.rs]] == 0)
  173. *contpc = regs->cp0_epc +
  174. dec_insn.pc_inc +
  175. (insn.mm_b1_format.simmediate << 1);
  176. else
  177. *contpc = regs->cp0_epc +
  178. dec_insn.pc_inc + dec_insn.next_pc_inc;
  179. return 1;
  180. case mm_bnez16_op:
  181. if ((long)regs->regs[reg16to32map[insn.mm_b1_format.rs]] != 0)
  182. *contpc = regs->cp0_epc +
  183. dec_insn.pc_inc +
  184. (insn.mm_b1_format.simmediate << 1);
  185. else
  186. *contpc = regs->cp0_epc +
  187. dec_insn.pc_inc + dec_insn.next_pc_inc;
  188. return 1;
  189. case mm_b16_op:
  190. *contpc = regs->cp0_epc + dec_insn.pc_inc +
  191. (insn.mm_b0_format.simmediate << 1);
  192. return 1;
  193. case mm_beq32_op:
  194. if (regs->regs[insn.mm_i_format.rs] ==
  195. regs->regs[insn.mm_i_format.rt])
  196. *contpc = regs->cp0_epc +
  197. dec_insn.pc_inc +
  198. (insn.mm_i_format.simmediate << 1);
  199. else
  200. *contpc = regs->cp0_epc +
  201. dec_insn.pc_inc +
  202. dec_insn.next_pc_inc;
  203. return 1;
  204. case mm_bne32_op:
  205. if (regs->regs[insn.mm_i_format.rs] !=
  206. regs->regs[insn.mm_i_format.rt])
  207. *contpc = regs->cp0_epc +
  208. dec_insn.pc_inc +
  209. (insn.mm_i_format.simmediate << 1);
  210. else
  211. *contpc = regs->cp0_epc +
  212. dec_insn.pc_inc + dec_insn.next_pc_inc;
  213. return 1;
  214. case mm_jalx32_op:
  215. regs->regs[31] = regs->cp0_epc +
  216. dec_insn.pc_inc + dec_insn.next_pc_inc;
  217. *contpc = regs->cp0_epc + dec_insn.pc_inc;
  218. *contpc >>= 28;
  219. *contpc <<= 28;
  220. *contpc |= (insn.j_format.target << 2);
  221. return 1;
  222. case mm_jals32_op:
  223. case mm_jal32_op:
  224. regs->regs[31] = regs->cp0_epc +
  225. dec_insn.pc_inc + dec_insn.next_pc_inc;
  226. /* Fall through */
  227. case mm_j32_op:
  228. *contpc = regs->cp0_epc + dec_insn.pc_inc;
  229. *contpc >>= 27;
  230. *contpc <<= 27;
  231. *contpc |= (insn.j_format.target << 1);
  232. set_isa16_mode(*contpc);
  233. return 1;
  234. }
  235. return 0;
  236. }
  237. /*
  238. * Compute return address and emulate branch in microMIPS mode after an
  239. * exception only. It does not handle compact branches/jumps and cannot
  240. * be used in interrupt context. (Compact branches/jumps do not cause
  241. * exceptions.)
  242. */
  243. int __microMIPS_compute_return_epc(struct pt_regs *regs)
  244. {
  245. u16 __user *pc16;
  246. u16 halfword;
  247. unsigned int word;
  248. unsigned long contpc;
  249. struct mm_decoded_insn mminsn = { 0 };
  250. mminsn.micro_mips_mode = 1;
  251. /* This load never faults. */
  252. pc16 = (unsigned short __user *)msk_isa16_mode(regs->cp0_epc);
  253. __get_user(halfword, pc16);
  254. pc16++;
  255. contpc = regs->cp0_epc + 2;
  256. word = ((unsigned int)halfword << 16);
  257. mminsn.pc_inc = 2;
  258. if (!mm_insn_16bit(halfword)) {
  259. __get_user(halfword, pc16);
  260. pc16++;
  261. contpc = regs->cp0_epc + 4;
  262. mminsn.pc_inc = 4;
  263. word |= halfword;
  264. }
  265. mminsn.insn = word;
  266. if (get_user(halfword, pc16))
  267. goto sigsegv;
  268. mminsn.next_pc_inc = 2;
  269. word = ((unsigned int)halfword << 16);
  270. if (!mm_insn_16bit(halfword)) {
  271. pc16++;
  272. if (get_user(halfword, pc16))
  273. goto sigsegv;
  274. mminsn.next_pc_inc = 4;
  275. word |= halfword;
  276. }
  277. mminsn.next_insn = word;
  278. mm_isBranchInstr(regs, mminsn, &contpc);
  279. regs->cp0_epc = contpc;
  280. return 0;
  281. sigsegv:
  282. force_sig(SIGSEGV, current);
  283. return -EFAULT;
  284. }
  285. /*
  286. * Compute return address and emulate branch in MIPS16e mode after an
  287. * exception only. It does not handle compact branches/jumps and cannot
  288. * be used in interrupt context. (Compact branches/jumps do not cause
  289. * exceptions.)
  290. */
  291. int __MIPS16e_compute_return_epc(struct pt_regs *regs)
  292. {
  293. u16 __user *addr;
  294. union mips16e_instruction inst;
  295. u16 inst2;
  296. u32 fullinst;
  297. long epc;
  298. epc = regs->cp0_epc;
  299. /* Read the instruction. */
  300. addr = (u16 __user *)msk_isa16_mode(epc);
  301. if (__get_user(inst.full, addr)) {
  302. force_sig(SIGSEGV, current);
  303. return -EFAULT;
  304. }
  305. switch (inst.ri.opcode) {
  306. case MIPS16e_extend_op:
  307. regs->cp0_epc += 4;
  308. return 0;
  309. /*
  310. * JAL and JALX in MIPS16e mode
  311. */
  312. case MIPS16e_jal_op:
  313. addr += 1;
  314. if (__get_user(inst2, addr)) {
  315. force_sig(SIGSEGV, current);
  316. return -EFAULT;
  317. }
  318. fullinst = ((unsigned)inst.full << 16) | inst2;
  319. regs->regs[31] = epc + 6;
  320. epc += 4;
  321. epc >>= 28;
  322. epc <<= 28;
  323. /*
  324. * JAL:5 X:1 TARGET[20-16]:5 TARGET[25:21]:5 TARGET[15:0]:16
  325. *
  326. * ......TARGET[15:0].................TARGET[20:16]...........
  327. * ......TARGET[25:21]
  328. */
  329. epc |=
  330. ((fullinst & 0xffff) << 2) | ((fullinst & 0x3e00000) >> 3) |
  331. ((fullinst & 0x1f0000) << 7);
  332. if (!inst.jal.x)
  333. set_isa16_mode(epc); /* Set ISA mode bit. */
  334. regs->cp0_epc = epc;
  335. return 0;
  336. /*
  337. * J(AL)R(C)
  338. */
  339. case MIPS16e_rr_op:
  340. if (inst.rr.func == MIPS16e_jr_func) {
  341. if (inst.rr.ra)
  342. regs->cp0_epc = regs->regs[31];
  343. else
  344. regs->cp0_epc =
  345. regs->regs[reg16to32[inst.rr.rx]];
  346. if (inst.rr.l) {
  347. if (inst.rr.nd)
  348. regs->regs[31] = epc + 2;
  349. else
  350. regs->regs[31] = epc + 4;
  351. }
  352. return 0;
  353. }
  354. break;
  355. }
  356. /*
  357. * All other cases have no branch delay slot and are 16-bits.
  358. * Branches do not cause an exception.
  359. */
  360. regs->cp0_epc += 2;
  361. return 0;
  362. }
  363. /**
  364. * __compute_return_epc_for_insn - Computes the return address and do emulate
  365. * branch simulation, if required.
  366. *
  367. * @regs: Pointer to pt_regs
  368. * @insn: branch instruction to decode
  369. * @returns: -EFAULT on error and forces SIGBUS, and on success
  370. * returns 0 or BRANCH_LIKELY_TAKEN as appropriate after
  371. * evaluating the branch.
  372. */
  373. int __compute_return_epc_for_insn(struct pt_regs *regs,
  374. union mips_instruction insn)
  375. {
  376. unsigned int bit, fcr31, dspcontrol;
  377. long epc = regs->cp0_epc;
  378. int ret = 0;
  379. switch (insn.i_format.opcode) {
  380. /*
  381. * jr and jalr are in r_format format.
  382. */
  383. case spec_op:
  384. switch (insn.r_format.func) {
  385. case jalr_op:
  386. regs->regs[insn.r_format.rd] = epc + 8;
  387. /* Fall through */
  388. case jr_op:
  389. regs->cp0_epc = regs->regs[insn.r_format.rs];
  390. break;
  391. }
  392. break;
  393. /*
  394. * This group contains:
  395. * bltz_op, bgez_op, bltzl_op, bgezl_op,
  396. * bltzal_op, bgezal_op, bltzall_op, bgezall_op.
  397. */
  398. case bcond_op:
  399. switch (insn.i_format.rt) {
  400. case bltz_op:
  401. case bltzl_op:
  402. if ((long)regs->regs[insn.i_format.rs] < 0) {
  403. epc = epc + 4 + (insn.i_format.simmediate << 2);
  404. if (insn.i_format.rt == bltzl_op)
  405. ret = BRANCH_LIKELY_TAKEN;
  406. } else
  407. epc += 8;
  408. regs->cp0_epc = epc;
  409. break;
  410. case bgez_op:
  411. case bgezl_op:
  412. if ((long)regs->regs[insn.i_format.rs] >= 0) {
  413. epc = epc + 4 + (insn.i_format.simmediate << 2);
  414. if (insn.i_format.rt == bgezl_op)
  415. ret = BRANCH_LIKELY_TAKEN;
  416. } else
  417. epc += 8;
  418. regs->cp0_epc = epc;
  419. break;
  420. case bltzal_op:
  421. case bltzall_op:
  422. regs->regs[31] = epc + 8;
  423. if ((long)regs->regs[insn.i_format.rs] < 0) {
  424. epc = epc + 4 + (insn.i_format.simmediate << 2);
  425. if (insn.i_format.rt == bltzall_op)
  426. ret = BRANCH_LIKELY_TAKEN;
  427. } else
  428. epc += 8;
  429. regs->cp0_epc = epc;
  430. break;
  431. case bgezal_op:
  432. case bgezall_op:
  433. regs->regs[31] = epc + 8;
  434. if ((long)regs->regs[insn.i_format.rs] >= 0) {
  435. epc = epc + 4 + (insn.i_format.simmediate << 2);
  436. if (insn.i_format.rt == bgezall_op)
  437. ret = BRANCH_LIKELY_TAKEN;
  438. } else
  439. epc += 8;
  440. regs->cp0_epc = epc;
  441. break;
  442. case bposge32_op:
  443. if (!cpu_has_dsp)
  444. goto sigill;
  445. dspcontrol = rddsp(0x01);
  446. if (dspcontrol >= 32) {
  447. epc = epc + 4 + (insn.i_format.simmediate << 2);
  448. } else
  449. epc += 8;
  450. regs->cp0_epc = epc;
  451. break;
  452. }
  453. break;
  454. /*
  455. * These are unconditional and in j_format.
  456. */
  457. case jal_op:
  458. regs->regs[31] = regs->cp0_epc + 8;
  459. case j_op:
  460. epc += 4;
  461. epc >>= 28;
  462. epc <<= 28;
  463. epc |= (insn.j_format.target << 2);
  464. regs->cp0_epc = epc;
  465. if (insn.i_format.opcode == jalx_op)
  466. set_isa16_mode(regs->cp0_epc);
  467. break;
  468. /*
  469. * These are conditional and in i_format.
  470. */
  471. case beq_op:
  472. case beql_op:
  473. if (regs->regs[insn.i_format.rs] ==
  474. regs->regs[insn.i_format.rt]) {
  475. epc = epc + 4 + (insn.i_format.simmediate << 2);
  476. if (insn.i_format.opcode == beql_op)
  477. ret = BRANCH_LIKELY_TAKEN;
  478. } else
  479. epc += 8;
  480. regs->cp0_epc = epc;
  481. break;
  482. case bne_op:
  483. case bnel_op:
  484. if (regs->regs[insn.i_format.rs] !=
  485. regs->regs[insn.i_format.rt]) {
  486. epc = epc + 4 + (insn.i_format.simmediate << 2);
  487. if (insn.i_format.opcode == bnel_op)
  488. ret = BRANCH_LIKELY_TAKEN;
  489. } else
  490. epc += 8;
  491. regs->cp0_epc = epc;
  492. break;
  493. case blez_op: /* not really i_format */
  494. case blezl_op:
  495. /* rt field assumed to be zero */
  496. if ((long)regs->regs[insn.i_format.rs] <= 0) {
  497. epc = epc + 4 + (insn.i_format.simmediate << 2);
  498. if (insn.i_format.opcode == blezl_op)
  499. ret = BRANCH_LIKELY_TAKEN;
  500. } else
  501. epc += 8;
  502. regs->cp0_epc = epc;
  503. break;
  504. case bgtz_op:
  505. case bgtzl_op:
  506. /* rt field assumed to be zero */
  507. if ((long)regs->regs[insn.i_format.rs] > 0) {
  508. epc = epc + 4 + (insn.i_format.simmediate << 2);
  509. if (insn.i_format.opcode == bgtzl_op)
  510. ret = BRANCH_LIKELY_TAKEN;
  511. } else
  512. epc += 8;
  513. regs->cp0_epc = epc;
  514. break;
  515. /*
  516. * And now the FPA/cp1 branch instructions.
  517. */
  518. case cop1_op:
  519. preempt_disable();
  520. if (is_fpu_owner())
  521. asm volatile(
  522. ".set push\n"
  523. "\t.set mips1\n"
  524. "\tcfc1\t%0,$31\n"
  525. "\t.set pop" : "=r" (fcr31));
  526. else
  527. fcr31 = current->thread.fpu.fcr31;
  528. preempt_enable();
  529. bit = (insn.i_format.rt >> 2);
  530. bit += (bit != 0);
  531. bit += 23;
  532. switch (insn.i_format.rt & 3) {
  533. case 0: /* bc1f */
  534. case 2: /* bc1fl */
  535. if (~fcr31 & (1 << bit)) {
  536. epc = epc + 4 + (insn.i_format.simmediate << 2);
  537. if (insn.i_format.rt == 2)
  538. ret = BRANCH_LIKELY_TAKEN;
  539. } else
  540. epc += 8;
  541. regs->cp0_epc = epc;
  542. break;
  543. case 1: /* bc1t */
  544. case 3: /* bc1tl */
  545. if (fcr31 & (1 << bit)) {
  546. epc = epc + 4 + (insn.i_format.simmediate << 2);
  547. if (insn.i_format.rt == 3)
  548. ret = BRANCH_LIKELY_TAKEN;
  549. } else
  550. epc += 8;
  551. regs->cp0_epc = epc;
  552. break;
  553. }
  554. break;
  555. #ifdef CONFIG_CPU_CAVIUM_OCTEON
  556. case lwc2_op: /* This is bbit0 on Octeon */
  557. if ((regs->regs[insn.i_format.rs] & (1ull<<insn.i_format.rt))
  558. == 0)
  559. epc = epc + 4 + (insn.i_format.simmediate << 2);
  560. else
  561. epc += 8;
  562. regs->cp0_epc = epc;
  563. break;
  564. case ldc2_op: /* This is bbit032 on Octeon */
  565. if ((regs->regs[insn.i_format.rs] &
  566. (1ull<<(insn.i_format.rt+32))) == 0)
  567. epc = epc + 4 + (insn.i_format.simmediate << 2);
  568. else
  569. epc += 8;
  570. regs->cp0_epc = epc;
  571. break;
  572. case swc2_op: /* This is bbit1 on Octeon */
  573. if (regs->regs[insn.i_format.rs] & (1ull<<insn.i_format.rt))
  574. epc = epc + 4 + (insn.i_format.simmediate << 2);
  575. else
  576. epc += 8;
  577. regs->cp0_epc = epc;
  578. break;
  579. case sdc2_op: /* This is bbit132 on Octeon */
  580. if (regs->regs[insn.i_format.rs] &
  581. (1ull<<(insn.i_format.rt+32)))
  582. epc = epc + 4 + (insn.i_format.simmediate << 2);
  583. else
  584. epc += 8;
  585. regs->cp0_epc = epc;
  586. break;
  587. #endif
  588. }
  589. return ret;
  590. sigill:
  591. printk("%s: DSP branch but not DSP ASE - sending SIGBUS.\n", current->comm);
  592. force_sig(SIGBUS, current);
  593. return -EFAULT;
  594. }
  595. EXPORT_SYMBOL_GPL(__compute_return_epc_for_insn);
  596. int __compute_return_epc(struct pt_regs *regs)
  597. {
  598. unsigned int __user *addr;
  599. long epc;
  600. union mips_instruction insn;
  601. epc = regs->cp0_epc;
  602. if (epc & 3)
  603. goto unaligned;
  604. /*
  605. * Read the instruction
  606. */
  607. addr = (unsigned int __user *) epc;
  608. if (__get_user(insn.word, addr)) {
  609. force_sig(SIGSEGV, current);
  610. return -EFAULT;
  611. }
  612. return __compute_return_epc_for_insn(regs, insn);
  613. unaligned:
  614. printk("%s: unaligned epc - sending SIGBUS.\n", current->comm);
  615. force_sig(SIGBUS, current);
  616. return -EFAULT;
  617. }