brl_emu.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Emulation of the "brl" instruction for IA64 processors that
  3. * don't support it in hardware.
  4. * Author: Stephan Zeisset, Intel Corp. <Stephan.Zeisset@intel.com>
  5. *
  6. * 02/22/02 D. Mosberger Clear si_flgs, si_isr, and si_imm to avoid
  7. * leaking kernel bits.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <asm/uaccess.h>
  12. #include <asm/processor.h>
  13. extern char ia64_set_b1, ia64_set_b2, ia64_set_b3, ia64_set_b4, ia64_set_b5;
  14. struct illegal_op_return {
  15. unsigned long fkt, arg1, arg2, arg3;
  16. };
  17. /*
  18. * The unimplemented bits of a virtual address must be set
  19. * to the value of the most significant implemented bit.
  20. * unimpl_va_mask includes all unimplemented bits and
  21. * the most significant implemented bit, so the result
  22. * of an and operation with the mask must be all 0's
  23. * or all 1's for the address to be valid.
  24. */
  25. #define unimplemented_virtual_address(va) ( \
  26. ((va) & local_cpu_data->unimpl_va_mask) != 0 && \
  27. ((va) & local_cpu_data->unimpl_va_mask) != local_cpu_data->unimpl_va_mask \
  28. )
  29. /*
  30. * The unimplemented bits of a physical address must be 0.
  31. * unimpl_pa_mask includes all unimplemented bits, so the result
  32. * of an and operation with the mask must be all 0's for the
  33. * address to be valid.
  34. */
  35. #define unimplemented_physical_address(pa) ( \
  36. ((pa) & local_cpu_data->unimpl_pa_mask) != 0 \
  37. )
  38. /*
  39. * Handle an illegal operation fault that was caused by an
  40. * unimplemented "brl" instruction.
  41. * If we are not successful (e.g because the illegal operation
  42. * wasn't caused by a "brl" after all), we return -1.
  43. * If we are successful, we return either 0 or the address
  44. * of a "fixup" function for manipulating preserved register
  45. * state.
  46. */
  47. struct illegal_op_return
  48. ia64_emulate_brl (struct pt_regs *regs, unsigned long ar_ec)
  49. {
  50. unsigned long bundle[2];
  51. unsigned long opcode, btype, qp, offset, cpl;
  52. unsigned long next_ip;
  53. struct siginfo siginfo;
  54. struct illegal_op_return rv;
  55. long tmp_taken, unimplemented_address;
  56. rv.fkt = (unsigned long) -1;
  57. /*
  58. * Decode the instruction bundle.
  59. */
  60. if (copy_from_user(bundle, (void *) (regs->cr_iip), sizeof(bundle)))
  61. return rv;
  62. next_ip = (unsigned long) regs->cr_iip + 16;
  63. /* "brl" must be in slot 2. */
  64. if (ia64_psr(regs)->ri != 1) return rv;
  65. /* Must be "mlx" template */
  66. if ((bundle[0] & 0x1e) != 0x4) return rv;
  67. opcode = (bundle[1] >> 60);
  68. btype = ((bundle[1] >> 29) & 0x7);
  69. qp = ((bundle[1] >> 23) & 0x3f);
  70. offset = ((bundle[1] & 0x0800000000000000L) << 4)
  71. | ((bundle[1] & 0x00fffff000000000L) >> 32)
  72. | ((bundle[1] & 0x00000000007fffffL) << 40)
  73. | ((bundle[0] & 0xffff000000000000L) >> 24);
  74. tmp_taken = regs->pr & (1L << qp);
  75. switch(opcode) {
  76. case 0xC:
  77. /*
  78. * Long Branch.
  79. */
  80. if (btype != 0) return rv;
  81. rv.fkt = 0;
  82. if (!(tmp_taken)) {
  83. /*
  84. * Qualifying predicate is 0.
  85. * Skip instruction.
  86. */
  87. regs->cr_iip = next_ip;
  88. ia64_psr(regs)->ri = 0;
  89. return rv;
  90. }
  91. break;
  92. case 0xD:
  93. /*
  94. * Long Call.
  95. */
  96. rv.fkt = 0;
  97. if (!(tmp_taken)) {
  98. /*
  99. * Qualifying predicate is 0.
  100. * Skip instruction.
  101. */
  102. regs->cr_iip = next_ip;
  103. ia64_psr(regs)->ri = 0;
  104. return rv;
  105. }
  106. /*
  107. * BR[btype] = IP+16
  108. */
  109. switch(btype) {
  110. case 0:
  111. regs->b0 = next_ip;
  112. break;
  113. case 1:
  114. rv.fkt = (unsigned long) &ia64_set_b1;
  115. break;
  116. case 2:
  117. rv.fkt = (unsigned long) &ia64_set_b2;
  118. break;
  119. case 3:
  120. rv.fkt = (unsigned long) &ia64_set_b3;
  121. break;
  122. case 4:
  123. rv.fkt = (unsigned long) &ia64_set_b4;
  124. break;
  125. case 5:
  126. rv.fkt = (unsigned long) &ia64_set_b5;
  127. break;
  128. case 6:
  129. regs->b6 = next_ip;
  130. break;
  131. case 7:
  132. regs->b7 = next_ip;
  133. break;
  134. }
  135. rv.arg1 = next_ip;
  136. /*
  137. * AR[PFS].pfm = CFM
  138. * AR[PFS].pec = AR[EC]
  139. * AR[PFS].ppl = PSR.cpl
  140. */
  141. cpl = ia64_psr(regs)->cpl;
  142. regs->ar_pfs = ((regs->cr_ifs & 0x3fffffffff)
  143. | (ar_ec << 52) | (cpl << 62));
  144. /*
  145. * CFM.sof -= CFM.sol
  146. * CFM.sol = 0
  147. * CFM.sor = 0
  148. * CFM.rrb.gr = 0
  149. * CFM.rrb.fr = 0
  150. * CFM.rrb.pr = 0
  151. */
  152. regs->cr_ifs = ((regs->cr_ifs & 0xffffffc00000007f)
  153. - ((regs->cr_ifs >> 7) & 0x7f));
  154. break;
  155. default:
  156. /*
  157. * Unknown opcode.
  158. */
  159. return rv;
  160. }
  161. regs->cr_iip += offset;
  162. ia64_psr(regs)->ri = 0;
  163. if (ia64_psr(regs)->it == 0)
  164. unimplemented_address = unimplemented_physical_address(regs->cr_iip);
  165. else
  166. unimplemented_address = unimplemented_virtual_address(regs->cr_iip);
  167. if (unimplemented_address) {
  168. /*
  169. * The target address contains unimplemented bits.
  170. */
  171. printk(KERN_DEBUG "Woah! Unimplemented Instruction Address Trap!\n");
  172. siginfo.si_signo = SIGILL;
  173. siginfo.si_errno = 0;
  174. siginfo.si_flags = 0;
  175. siginfo.si_isr = 0;
  176. siginfo.si_imm = 0;
  177. siginfo.si_code = ILL_BADIADDR;
  178. force_sig_info(SIGILL, &siginfo, current);
  179. } else if (ia64_psr(regs)->tb) {
  180. /*
  181. * Branch Tracing is enabled.
  182. * Force a taken branch signal.
  183. */
  184. siginfo.si_signo = SIGTRAP;
  185. siginfo.si_errno = 0;
  186. siginfo.si_code = TRAP_BRANCH;
  187. siginfo.si_flags = 0;
  188. siginfo.si_isr = 0;
  189. siginfo.si_addr = 0;
  190. siginfo.si_imm = 0;
  191. force_sig_info(SIGTRAP, &siginfo, current);
  192. } else if (ia64_psr(regs)->ss) {
  193. /*
  194. * Single Step is enabled.
  195. * Force a trace signal.
  196. */
  197. siginfo.si_signo = SIGTRAP;
  198. siginfo.si_errno = 0;
  199. siginfo.si_code = TRAP_TRACE;
  200. siginfo.si_flags = 0;
  201. siginfo.si_isr = 0;
  202. siginfo.si_addr = 0;
  203. siginfo.si_imm = 0;
  204. force_sig_info(SIGTRAP, &siginfo, current);
  205. }
  206. return rv;
  207. }