memoryCall.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /*
  2. * arch/alpha/kernel/traps.c
  3. *
  4. * (C) Copyright 1994 Linus Torvalds
  5. */
  6. /*
  7. * This file initializes the trap entry points
  8. */
  9. #include <linux/jiffies.h>
  10. #include <linux/mm.h>
  11. #include <linux/sched.h>
  12. #include <linux/tty.h>
  13. #include <linux/delay.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/kallsyms.h>
  17. #include <linux/ratelimit.h>
  18. #include <asm/gentrap.h>
  19. #include <asm/uaccess.h>
  20. #include <asm/unaligned.h>
  21. #include <asm/sysinfo.h>
  22. #include <asm/hwrpb.h>
  23. #include <asm/mmu_context.h>
  24. #include <asm/special_insns.h>
  25. #include "proto.h"
  26. /* Work-around for some SRMs which mishandle opDEC faults. */
  27. static int opDEC_fix;
  28. static void __cpuinit
  29. opDEC_check(void)
  30. {
  31. __asm__ __volatile__ (
  32. /* Load the address of... */
  33. " br $16, 1f\n"
  34. /* A stub instruction fault handler. Just add 4 to the
  35. pc and continue. */
  36. " ldq $16, 8($sp)\n"
  37. " addq $16, 4, $16\n"
  38. " stq $16, 8($sp)\n"
  39. " call_pal %[rti]\n"
  40. /* Install the instruction fault handler. */
  41. "1: lda $17, 3\n"
  42. " call_pal %[wrent]\n"
  43. /* With that in place, the fault from the round-to-minf fp
  44. insn will arrive either at the "lda 4" insn (bad) or one
  45. past that (good). This places the correct fixup in %0. */
  46. " lda %[fix], 0\n"
  47. " cvttq/svm $f31,$f31\n"
  48. " lda %[fix], 4"
  49. : [fix] "=r" (opDEC_fix)
  50. : [rti] "n" (PAL_rti), [wrent] "n" (PAL_wrent)
  51. : "$0", "$1", "$16", "$17", "$22", "$23", "$24", "$25");
  52. if (opDEC_fix)
  53. printk("opDEC fixup enabled.\n");
  54. }
  55. void
  56. dik_show_regs(struct pt_regs *regs, unsigned long *r9_15)
  57. {
  58. printk("pc = [<%016lx>] ra = [<%016lx>] ps = %04lx %s\n",
  59. regs->pc, regs->r26, regs->ps, print_tainted());
  60. print_symbol("pc is at %s\n", regs->pc);
  61. print_symbol("ra is at %s\n", regs->r26 );
  62. printk("v0 = %016lx t0 = %016lx t1 = %016lx\n",
  63. regs->r0, regs->r1, regs->r2);
  64. printk("t2 = %016lx t3 = %016lx t4 = %016lx\n",
  65. regs->r3, regs->r4, regs->r5);
  66. printk("t5 = %016lx t6 = %016lx t7 = %016lx\n",
  67. regs->r6, regs->r7, regs->r8);
  68. if (r9_15) {
  69. printk("s0 = %016lx s1 = %016lx s2 = %016lx\n",
  70. r9_15[9], r9_15[10], r9_15[11]);
  71. printk("s3 = %016lx s4 = %016lx s5 = %016lx\n",
  72. r9_15[12], r9_15[13], r9_15[14]);
  73. printk("s6 = %016lx\n", r9_15[15]);
  74. }
  75. printk("a0 = %016lx a1 = %016lx a2 = %016lx\n",
  76. regs->r16, regs->r17, regs->r18);
  77. printk("a3 = %016lx a4 = %016lx a5 = %016lx\n",
  78. regs->r19, regs->r20, regs->r21);
  79. printk("t8 = %016lx t9 = %016lx t10= %016lx\n",
  80. regs->r22, regs->r23, regs->r24);
  81. printk("t11= %016lx pv = %016lx at = %016lx\n",
  82. regs->r25, regs->r27, regs->r28);
  83. printk("gp = %016lx sp = %p\n", regs->gp, regs+1);
  84. #if 0
  85. __halt();
  86. #endif
  87. }
  88. #if 0
  89. static char * ireg_name[] = {"v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6",
  90. "t7", "s0", "s1", "s2", "s3", "s4", "s5", "s6",
  91. "a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9",
  92. "t10", "t11", "ra", "pv", "at", "gp", "sp", "zero"};
  93. #endif
  94. static void
  95. dik_show_code(unsigned int *pc)
  96. {
  97. long i;
  98. printk("Code:");
  99. for (i = -6; i < 2; i++) {
  100. unsigned int insn;
  101. if (__get_user(insn, (unsigned int __user *)pc + i))
  102. break;
  103. printk("%c%08x%c", i ? ' ' : '<', insn, i ? ' ' : '>');
  104. }
  105. printk("\n");
  106. }
  107. static void
  108. dik_show_trace(unsigned long *sp)
  109. {
  110. long i = 0;
  111. printk("Trace:\n");
  112. while (0x1ff8 & (unsigned long) sp) {
  113. extern char _stext[], _etext[];
  114. unsigned long tmp = *sp;
  115. sp++;
  116. if (tmp < (unsigned long) &_stext)
  117. continue;
  118. if (tmp >= (unsigned long) &_etext)
  119. continue;
  120. printk("[<%lx>]", tmp);
  121. print_symbol(" %s", tmp);
  122. printk("\n");
  123. if (i > 40) {
  124. printk(" ...");
  125. break;
  126. }
  127. }
  128. printk("\n");
  129. }
  130. static int kstack_depth_to_print = 24;
  131. void show_stack(struct task_struct *task, unsigned long *sp)
  132. {
  133. unsigned long *stack;
  134. int i;
  135. /*
  136. * debugging aid: "show_stack(NULL);" prints the
  137. * back trace for this cpu.
  138. */
  139. if(sp==NULL)
  140. sp=(unsigned long*)&sp;
  141. stack = sp;
  142. for(i=0; i < kstack_depth_to_print; i++) {
  143. if (((long) stack & (THREAD_SIZE-1)) == 0)
  144. break;
  145. if (i && ((i % 4) == 0))
  146. printk("\n ");
  147. printk("%016lx ", *stack++);
  148. }
  149. printk("\n");
  150. dik_show_trace(sp);
  151. }
  152. void dump_stack(void)
  153. {
  154. show_stack(NULL, NULL);
  155. }
  156. EXPORT_SYMBOL(dump_stack);
  157. void
  158. die_if_kernel(char * str, struct pt_regs *regs, long err, unsigned long *r9_15)
  159. {
  160. if (regs->ps & 8)
  161. return;
  162. #ifdef CONFIG_SMP
  163. printk("CPU %d ", hard_smp_processor_id());
  164. #endif
  165. printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
  166. dik_show_regs(regs, r9_15);
  167. add_taint(TAINT_DIE);
  168. dik_show_trace((unsigned long *)(regs+1));
  169. dik_show_code((unsigned int *)regs->pc);
  170. if (test_and_set_thread_flag (TIF_DIE_IF_KERNEL)) {
  171. printk("die_if_kernel recursion detected.\n");
  172. local_irq_enable();
  173. while (1);
  174. }
  175. do_exit(SIGSEGV);
  176. }
  177. #ifndef CONFIG_MATHEMU
  178. static long dummy_emul(void) { return 0; }
  179. long (*alpha_fp_emul_imprecise)(struct pt_regs *regs, unsigned long writemask)
  180. = (void *)dummy_emul;
  181. long (*alpha_fp_emul) (unsigned long pc)
  182. = (void *)dummy_emul;
  183. #else
  184. long alpha_fp_emul_imprecise(struct pt_regs *regs, unsigned long writemask);
  185. long alpha_fp_emul (unsigned long pc);
  186. #endif
  187. asmlinkage void
  188. do_entArith(unsigned long summary, unsigned long write_mask,
  189. struct pt_regs *regs)
  190. {
  191. long si_code = FPE_FLTINV;
  192. siginfo_t info;
  193. if (summary & 1) {
  194. /* Software-completion summary bit is set, so try to
  195. emulate the instruction. If the processor supports
  196. precise exceptions, we don't have to search. */
  197. if (!amask(AMASK_PRECISE_TRAP))
  198. si_code = alpha_fp_emul(regs->pc - 4);
  199. else
  200. si_code = alpha_fp_emul_imprecise(regs, write_mask);
  201. if (si_code == 0)
  202. return;
  203. }
  204. die_if_kernel("Arithmetic fault", regs, 0, NULL);
  205. info.si_signo = SIGFPE;
  206. info.si_errno = 0;
  207. info.si_code = si_code;
  208. info.si_addr = (void __user *) regs->pc;
  209. send_sig_info(SIGFPE, &info, current);
  210. }
  211. asmlinkage void
  212. do_entIF(unsigned long type, struct pt_regs *regs)
  213. {
  214. siginfo_t info;
  215. int signo, code;
  216. if ((regs->ps & ~IPL_MAX) == 0) {
  217. if (type == 1) {
  218. const unsigned int *data
  219. = (const unsigned int *) regs->pc;
  220. printk("Kernel bug at %s:%d\n",
  221. (const char *)(data[1] | (long)data[2] << 32),
  222. data[0]);
  223. }
  224. die_if_kernel((type == 1 ? "Kernel Bug" : "Instruction fault"),
  225. regs, type, NULL);
  226. }
  227. switch (type) {
  228. case 0: /* breakpoint */
  229. info.si_signo = SIGTRAP;
  230. info.si_errno = 0;
  231. info.si_code = TRAP_BRKPT;
  232. info.si_trapno = 0;
  233. info.si_addr = (void __user *) regs->pc;
  234. if (ptrace_cancel_bpt(current)) {
  235. regs->pc -= 4; /* make pc point to former bpt */
  236. }
  237. send_sig_info(SIGTRAP, &info, current);
  238. return;
  239. case 1: /* bugcheck */
  240. info.si_signo = SIGTRAP;
  241. info.si_errno = 0;
  242. info.si_code = __SI_FAULT;
  243. info.si_addr = (void __user *) regs->pc;
  244. info.si_trapno = 0;
  245. send_sig_info(SIGTRAP, &info, current);
  246. return;
  247. case 2: /* gentrap */
  248. info.si_addr = (void __user *) regs->pc;
  249. info.si_trapno = regs->r16;
  250. switch ((long) regs->r16) {
  251. case GEN_INTOVF:
  252. signo = SIGFPE;
  253. code = FPE_INTOVF;
  254. break;
  255. case GEN_INTDIV:
  256. signo = SIGFPE;
  257. code = FPE_INTDIV;
  258. break;
  259. case GEN_FLTOVF:
  260. signo = SIGFPE;
  261. code = FPE_FLTOVF;
  262. break;
  263. case GEN_FLTDIV:
  264. signo = SIGFPE;
  265. code = FPE_FLTDIV;
  266. break;
  267. case GEN_FLTUND:
  268. signo = SIGFPE;
  269. code = FPE_FLTUND;
  270. break;
  271. case GEN_FLTINV:
  272. signo = SIGFPE;
  273. code = FPE_FLTINV;
  274. break;
  275. case GEN_FLTINE:
  276. signo = SIGFPE;
  277. code = FPE_FLTRES;
  278. break;
  279. case GEN_ROPRAND:
  280. signo = SIGFPE;
  281. code = __SI_FAULT;
  282. break;
  283. case GEN_DECOVF:
  284. case GEN_DECDIV:
  285. case GEN_DECINV:
  286. case GEN_ASSERTERR:
  287. case GEN_NULPTRERR:
  288. case GEN_STKOVF:
  289. case GEN_STRLENERR:
  290. case GEN_SUBSTRERR:
  291. case GEN_RANGERR:
  292. case GEN_SUBRNG:
  293. case GEN_SUBRNG1:
  294. case GEN_SUBRNG2:
  295. case GEN_SUBRNG3:
  296. case GEN_SUBRNG4:
  297. case GEN_SUBRNG5:
  298. case GEN_SUBRNG6:
  299. case GEN_SUBRNG7:
  300. default:
  301. signo = SIGTRAP;
  302. code = __SI_FAULT;
  303. break;
  304. }
  305. info.si_signo = signo;
  306. info.si_errno = 0;
  307. info.si_code = code;
  308. info.si_addr = (void __user *) regs->pc;
  309. send_sig_info(signo, &info, current);
  310. return;
  311. case 4: /* opDEC */
  312. if (implver() == IMPLVER_EV4) {
  313. long si_code;
  314. /* The some versions of SRM do not handle
  315. the opDEC properly - they return the PC of the
  316. opDEC fault, not the instruction after as the
  317. Alpha architecture requires. Here we fix it up.
  318. We do this by intentionally causing an opDEC
  319. fault during the boot sequence and testing if
  320. we get the correct PC. If not, we set a flag
  321. to correct it every time through. */
  322. regs->pc += opDEC_fix;
  323. /* EV4 does not implement anything except normal
  324. rounding. Everything else will come here as
  325. an illegal instruction. Emulate them. */
  326. si_code = alpha_fp_emul(regs->pc - 4);
  327. if (si_code == 0)
  328. return;
  329. if (si_code > 0) {
  330. info.si_signo = SIGFPE;
  331. info.si_errno = 0;
  332. info.si_code = si_code;
  333. info.si_addr = (void __user *) regs->pc;
  334. send_sig_info(SIGFPE, &info, current);
  335. return;
  336. }
  337. }
  338. break;
  339. case 3: /* FEN fault */
  340. /* Irritating users can call PAL_clrfen to disable the
  341. FPU for the process. The kernel will then trap in
  342. do_switch_stack and undo_switch_stack when we try
  343. to save and restore the FP registers.
  344. Given that GCC by default generates code that uses the
  345. FP registers, PAL_clrfen is not useful except for DoS
  346. attacks. So turn the bleeding FPU back on and be done
  347. with it. */
  348. current_thread_info()->pcb.flags |= 1;
  349. __reload_thread(&current_thread_info()->pcb);
  350. return;
  351. case 5: /* illoc */
  352. default: /* unexpected instruction-fault type */
  353. ;
  354. }
  355. info.si_signo = SIGILL;
  356. info.si_errno = 0;
  357. info.si_code = ILL_ILLOPC;
  358. info.si_addr = (void __user *) regs->pc;
  359. send_sig_info(SIGILL, &info, current);
  360. }
  361. /* There is an ifdef in the PALcode in MILO that enables a
  362. "kernel debugging entry point" as an unprivileged call_pal.
  363. We don't want to have anything to do with it, but unfortunately
  364. several versions of MILO included in distributions have it enabled,
  365. and if we don't put something on the entry point we'll oops. */
  366. asmlinkage void
  367. do_entDbg(struct pt_regs *regs)
  368. {
  369. siginfo_t info;
  370. die_if_kernel("Instruction fault", regs, 0, NULL);
  371. info.si_signo = SIGILL;
  372. info.si_errno = 0;
  373. info.si_code = ILL_ILLOPC;
  374. info.si_addr = (void __user *) regs->pc;
  375. force_sig_info(SIGILL, &info, current);
  376. }
  377. /*
  378. * entUna has a different register layout to be reasonably simple. It
  379. * needs access to all the integer registers (the kernel doesn't use
  380. * fp-regs), and it needs to have them in order for simpler access.
  381. *
  382. * Due to the non-standard register layout (and because we don't want
  383. * to handle floating-point regs), user-mode unaligned accesses are
  384. * handled separately by do_entUnaUser below.
  385. *
  386. * Oh, btw, we don't handle the "gp" register correctly, but if we fault
  387. * on a gp-register unaligned load/store, something is _very_ wrong
  388. * in the kernel anyway..
  389. */
  390. struct allregs {
  391. unsigned long regs[32];
  392. unsigned long ps, pc, gp, a0, a1, a2;
  393. };
  394. struct unaligned_stat {
  395. unsigned long count, va, pc;
  396. } unaligned[2];
  397. /* Macro for exception fixup code to access integer registers. */
  398. #define una_reg(r) (_regs[(r) >= 16 && (r) <= 18 ? (r)+19 : (r)])
  399. asmlinkage void
  400. do_entUna(void * va, unsigned long opcode, unsigned long reg,
  401. struct allregs *regs)
  402. {
  403. long error, tmp1, tmp2, tmp3, tmp4;
  404. unsigned long pc = regs->pc - 4;
  405. unsigned long *_regs = regs->regs;
  406. const struct exception_table_entry *fixup;