memoryCall.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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;