traps.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* $Id: traps.c,v 1.11 2005/01/24 16:03:19 orjanf Exp $
  2. *
  3. * linux/arch/cris/traps.c
  4. *
  5. * Here we handle the break vectors not used by the system call
  6. * mechanism, as well as some general stack/register dumping
  7. * things.
  8. *
  9. * Copyright (C) 2000-2002 Axis Communications AB
  10. *
  11. * Authors: Bjorn Wesen
  12. * Hans-Peter Nilsson
  13. *
  14. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <asm/pgtable.h>
  18. #include <asm/uaccess.h>
  19. static int kstack_depth_to_print = 24;
  20. extern int raw_printk(const char *fmt, ...);
  21. void show_trace(unsigned long * stack)
  22. {
  23. unsigned long addr, module_start, module_end;
  24. extern char _stext, _etext;
  25. int i;
  26. raw_printk("\nCall Trace: ");
  27. i = 1;
  28. module_start = VMALLOC_START;
  29. module_end = VMALLOC_END;
  30. while (((long) stack & (THREAD_SIZE-1)) != 0) {
  31. if (__get_user (addr, stack)) {
  32. /* This message matches "failing address" marked
  33. s390 in ksymoops, so lines containing it will
  34. not be filtered out by ksymoops. */
  35. raw_printk ("Failing address 0x%lx\n", (unsigned long)stack);
  36. break;
  37. }
  38. stack++;
  39. /*
  40. * If the address is either in the text segment of the
  41. * kernel, or in the region which contains vmalloc'ed
  42. * memory, it *may* be the address of a calling
  43. * routine; if so, print it so that someone tracing
  44. * down the cause of the crash will be able to figure
  45. * out the call path that was taken.
  46. */
  47. if (((addr >= (unsigned long) &_stext) &&
  48. (addr <= (unsigned long) &_etext)) ||
  49. ((addr >= module_start) && (addr <= module_end))) {
  50. if (i && ((i % 8) == 0))
  51. raw_printk("\n ");
  52. raw_printk("[<%08lx>] ", addr);
  53. i++;
  54. }
  55. }
  56. }
  57. /*
  58. * These constants are for searching for possible module text
  59. * segments. MODULE_RANGE is a guess of how much space is likely
  60. * to be vmalloced.
  61. */
  62. #define MODULE_RANGE (8*1024*1024)
  63. /*
  64. * The output (format, strings and order) is adjusted to be usable with
  65. * ksymoops-2.4.1 with some necessary CRIS-specific patches. Please don't
  66. * change it unless you're serious about adjusting ksymoops and syncing
  67. * with the ksymoops maintainer.
  68. */
  69. void
  70. show_stack(struct task_struct *task, unsigned long *sp)
  71. {
  72. unsigned long *stack, addr;
  73. int i;
  74. /*
  75. * debugging aid: "show_stack(NULL);" prints a
  76. * back trace.
  77. */
  78. if(sp == NULL) {
  79. if (task)
  80. sp = (unsigned long*)task->thread.ksp;
  81. else
  82. sp = (unsigned long*)rdsp();
  83. }
  84. stack = sp;
  85. raw_printk("\nStack from %08lx:\n ", (unsigned long)stack);
  86. for(i = 0; i < kstack_depth_to_print; i++) {
  87. if (((long) stack & (THREAD_SIZE-1)) == 0)
  88. break;
  89. if (i && ((i % 8) == 0))
  90. raw_printk("\n ");
  91. if (__get_user (addr, stack)) {
  92. /* This message matches "failing address" marked
  93. s390 in ksymoops, so lines containing it will
  94. not be filtered out by ksymoops. */
  95. raw_printk ("Failing address 0x%lx\n", (unsigned long)stack);
  96. break;
  97. }
  98. stack++;
  99. raw_printk("%08lx ", addr);
  100. }
  101. show_trace(sp);
  102. }
  103. static void (*nmi_handler)(struct pt_regs*);
  104. extern void arch_enable_nmi(void);
  105. void set_nmi_handler(void (*handler)(struct pt_regs*))
  106. {
  107. nmi_handler = handler;
  108. arch_enable_nmi();
  109. }
  110. void handle_nmi(struct pt_regs* regs)
  111. {
  112. if (nmi_handler)
  113. nmi_handler(regs);
  114. }
  115. #ifdef CONFIG_DEBUG_NMI_OOPS
  116. void oops_nmi_handler(struct pt_regs* regs)
  117. {
  118. stop_watchdog();
  119. raw_printk("NMI!\n");
  120. show_registers(regs);
  121. }
  122. static int
  123. __init oops_nmi_register(void)
  124. {
  125. set_nmi_handler(oops_nmi_handler);
  126. return 0;
  127. }
  128. __initcall(oops_nmi_register);
  129. #endif
  130. #if 0
  131. /* displays a short stack trace */
  132. int
  133. show_stack()
  134. {
  135. unsigned long *sp = (unsigned long *)rdusp();
  136. int i;
  137. raw_printk("Stack dump [0x%08lx]:\n", (unsigned long)sp);
  138. for(i = 0; i < 16; i++)
  139. raw_printk("sp + %d: 0x%08lx\n", i*4, sp[i]);
  140. return 0;
  141. }
  142. #endif
  143. void dump_stack(void)
  144. {
  145. show_stack(NULL, NULL);
  146. }
  147. EXPORT_SYMBOL(dump_stack);
  148. void __init
  149. trap_init(void)
  150. {
  151. /* Nothing needs to be done */
  152. }
  153. void spinning_cpu(void* addr)
  154. {
  155. raw_printk("CPU %d spinning on %X\n", smp_processor_id(), addr);
  156. dump_stack();
  157. }