traps.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* $Id: traps.c,v 1.4 2005/04/24 18:47:55 starvik Exp $
  2. *
  3. * linux/arch/cris/arch-v10/traps.c
  4. *
  5. * Heler functions for trap handlers
  6. *
  7. * Copyright (C) 2000-2002 Axis Communications AB
  8. *
  9. * Authors: Bjorn Wesen
  10. * Hans-Peter Nilsson
  11. *
  12. */
  13. #include <linux/config.h>
  14. #include <linux/ptrace.h>
  15. #include <asm/uaccess.h>
  16. #include <asm/arch/sv_addr_ag.h>
  17. extern int raw_printk(const char *fmt, ...);
  18. void
  19. show_registers(struct pt_regs * regs)
  20. {
  21. /* We either use rdusp() - the USP register, which might not
  22. correspond to the current process for all cases we're called,
  23. or we use the current->thread.usp, which is not up to date for
  24. the current process. Experience shows we want the USP
  25. register. */
  26. unsigned long usp = rdusp();
  27. raw_printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
  28. regs->irp, regs->srp, regs->dccr, usp, regs->mof );
  29. raw_printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
  30. regs->r0, regs->r1, regs->r2, regs->r3);
  31. raw_printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
  32. regs->r4, regs->r5, regs->r6, regs->r7);
  33. raw_printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
  34. regs->r8, regs->r9, regs->r10, regs->r11);
  35. raw_printk("r12: %08lx r13: %08lx oR10: %08lx sp: %08lx\n",
  36. regs->r12, regs->r13, regs->orig_r10, regs);
  37. raw_printk("R_MMU_CAUSE: %08lx\n", (unsigned long)*R_MMU_CAUSE);
  38. raw_printk("Process %s (pid: %d, stackpage=%08lx)\n",
  39. current->comm, current->pid, (unsigned long)current);
  40. /*
  41. * When in-kernel, we also print out the stack and code at the
  42. * time of the fault..
  43. */
  44. if (! user_mode(regs)) {
  45. int i;
  46. show_stack(NULL, (unsigned long*)usp);
  47. /* Dump kernel stack if the previous dump wasn't one. */
  48. if (usp != 0)
  49. show_stack (NULL, NULL);
  50. raw_printk("\nCode: ");
  51. if(regs->irp < PAGE_OFFSET)
  52. goto bad;
  53. /* Often enough the value at regs->irp does not point to
  54. the interesting instruction, which is most often the
  55. _previous_ instruction. So we dump at an offset large
  56. enough that instruction decoding should be in sync at
  57. the interesting point, but small enough to fit on a row
  58. (sort of). We point out the regs->irp location in a
  59. ksymoops-friendly way by wrapping the byte for that
  60. address in parentheses. */
  61. for(i = -12; i < 12; i++)
  62. {
  63. unsigned char c;
  64. if(__get_user(c, &((unsigned char*)regs->irp)[i])) {
  65. bad:
  66. raw_printk(" Bad IP value.");
  67. break;
  68. }
  69. if (i == 0)
  70. raw_printk("(%02x) ", c);
  71. else
  72. raw_printk("%02x ", c);
  73. }
  74. raw_printk("\n");
  75. }
  76. }
  77. /* Called from entry.S when the watchdog has bitten
  78. * We print out something resembling an oops dump, and if
  79. * we have the nice doggy development flag set, we halt here
  80. * instead of rebooting.
  81. */
  82. extern void reset_watchdog(void);
  83. extern void stop_watchdog(void);
  84. void
  85. watchdog_bite_hook(struct pt_regs *regs)
  86. {
  87. #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
  88. local_irq_disable();
  89. stop_watchdog();
  90. show_registers(regs);
  91. while(1) /* nothing */;
  92. #else
  93. show_registers(regs);
  94. #endif
  95. }
  96. /* This is normally the 'Oops' routine */
  97. void
  98. die_if_kernel(const char * str, struct pt_regs * regs, long err)
  99. {
  100. if(user_mode(regs))
  101. return;
  102. #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
  103. /* This printout might take too long and trigger the
  104. * watchdog normally. If we're in the nice doggy
  105. * development mode, stop the watchdog during printout.
  106. */
  107. stop_watchdog();
  108. #endif
  109. raw_printk("%s: %04lx\n", str, err & 0xffff);
  110. show_registers(regs);
  111. #ifdef CONFIG_ETRAX_WATCHDOG_NICE_DOGGY
  112. reset_watchdog();
  113. #endif
  114. do_exit(SIGSEGV);
  115. }
  116. void arch_enable_nmi(void)
  117. {
  118. asm volatile("setf m");
  119. }