bug.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * arch/v850/kernel/bug.c -- Bug reporting functions
  3. *
  4. * Copyright (C) 2001,02,03 NEC Electronics Corporation
  5. * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file COPYING in the main directory of this
  9. * archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/reboot.h>
  15. #include <linux/sched.h>
  16. #include <linux/module.h>
  17. #include <asm/errno.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/processor.h>
  20. #include <asm/current.h>
  21. /* We should use __builtin_return_address, but it doesn't work in gcc-2.90
  22. (which is currently our standard compiler on the v850). */
  23. #define ret_addr() ({ register u32 lp asm ("lp"); lp; })
  24. #define stack_addr() ({ register u32 sp asm ("sp"); sp; })
  25. void __bug ()
  26. {
  27. printk (KERN_CRIT "kernel BUG at PC 0x%x (SP ~0x%x)!\n",
  28. ret_addr() - 4, /* - 4 for `jarl' */
  29. stack_addr());
  30. machine_halt ();
  31. }
  32. int bad_trap (int trap_num, struct pt_regs *regs)
  33. {
  34. printk (KERN_CRIT
  35. "unimplemented trap %d called at 0x%08lx, pid %d!\n",
  36. trap_num, regs->pc, current->pid);
  37. return -ENOSYS;
  38. }
  39. #ifdef CONFIG_RESET_GUARD
  40. void unexpected_reset (unsigned long ret_addr, unsigned long kmode,
  41. struct task_struct *task, unsigned long sp)
  42. {
  43. printk (KERN_CRIT
  44. "unexpected reset in %s mode, pid %d"
  45. " (ret_addr = 0x%lx, sp = 0x%lx)\n",
  46. kmode ? "kernel" : "user",
  47. task ? task->pid : -1,
  48. ret_addr, sp);
  49. machine_halt ();
  50. }
  51. #endif /* CONFIG_RESET_GUARD */
  52. struct spec_reg_name {
  53. const char *name;
  54. int gpr;
  55. };
  56. struct spec_reg_name spec_reg_names[] = {
  57. { "sp", GPR_SP },
  58. { "gp", GPR_GP },
  59. { "tp", GPR_TP },
  60. { "ep", GPR_EP },
  61. { "lp", GPR_LP },
  62. { 0, 0 }
  63. };
  64. void show_regs (struct pt_regs *regs)
  65. {
  66. int gpr_base, gpr_offs;
  67. printk (" pc 0x%08lx psw 0x%08lx kernel_mode %d\n",
  68. regs->pc, regs->psw, regs->kernel_mode);
  69. printk (" ctpc 0x%08lx ctpsw 0x%08lx ctbp 0x%08lx\n",
  70. regs->ctpc, regs->ctpsw, regs->ctbp);
  71. for (gpr_base = 0; gpr_base < NUM_GPRS; gpr_base += 4) {
  72. for (gpr_offs = 0; gpr_offs < 4; gpr_offs++) {
  73. int gpr = gpr_base + gpr_offs;
  74. long val = regs->gpr[gpr];
  75. struct spec_reg_name *srn;
  76. for (srn = spec_reg_names; srn->name; srn++)
  77. if (srn->gpr == gpr)
  78. break;
  79. if (srn->name)
  80. printk ("%7s 0x%08lx", srn->name, val);
  81. else
  82. printk (" r%02d 0x%08lx", gpr, val);
  83. }
  84. printk ("\n");
  85. }
  86. }
  87. /*
  88. * TASK is a pointer to the task whose backtrace we want to see (or NULL
  89. * for current task), SP is the stack pointer of the first frame that
  90. * should be shown in the back trace (or NULL if the entire call-chain of
  91. * the task should be shown).
  92. */
  93. void show_stack (struct task_struct *task, unsigned long *sp)
  94. {
  95. unsigned long addr, end;
  96. if (sp)
  97. addr = (unsigned long)sp;
  98. else if (task)
  99. addr = task_sp (task);
  100. else
  101. addr = stack_addr ();
  102. addr = addr & ~3;
  103. end = (addr + THREAD_SIZE - 1) & THREAD_MASK;
  104. while (addr < end) {
  105. printk ("%8lX: ", addr);
  106. while (addr < end) {
  107. printk (" %8lX", *(unsigned long *)addr);
  108. addr += sizeof (unsigned long);
  109. if (! (addr & 0xF))
  110. break;
  111. }
  112. printk ("\n");
  113. }
  114. }
  115. void dump_stack ()
  116. {
  117. show_stack (0, 0);
  118. }
  119. EXPORT_SYMBOL(dump_stack);