traps.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Traps/Non-MMU Exception handling for ARC
  3. *
  4. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * vineetg: May 2011
  11. * -user-space unaligned access emulation
  12. *
  13. * Rahul Trivedi: Codito Technologies 2004
  14. */
  15. #include <linux/sched.h>
  16. #include <linux/kdebug.h>
  17. #include <linux/uaccess.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/kprobes.h>
  20. #include <linux/kgdb.h>
  21. #include <asm/setup.h>
  22. #include <asm/unaligned.h>
  23. #include <asm/kprobes.h>
  24. void __init trap_init(void)
  25. {
  26. return;
  27. }
  28. void die(const char *str, struct pt_regs *regs, unsigned long address,
  29. unsigned long cause_reg)
  30. {
  31. show_kernel_fault_diag(str, regs, address, cause_reg);
  32. /* DEAD END */
  33. __asm__("flag 1");
  34. }
  35. /*
  36. * Helper called for bulk of exceptions NOT needing specific handling
  37. * -for user faults enqueues requested signal
  38. * -for kernel, chk if due to copy_(to|from)_user, otherwise die()
  39. */
  40. static noinline int handle_exception(unsigned long cause, char *str,
  41. struct pt_regs *regs, siginfo_t *info)
  42. {
  43. if (user_mode(regs)) {
  44. struct task_struct *tsk = current;
  45. tsk->thread.fault_address = (__force unsigned int)info->si_addr;
  46. tsk->thread.cause_code = cause;
  47. force_sig_info(info->si_signo, info, tsk);
  48. } else {
  49. /* If not due to copy_(to|from)_user, we are doomed */
  50. if (fixup_exception(regs))
  51. return 0;
  52. die(str, regs, (unsigned long)info->si_addr, cause);
  53. }
  54. return 1;
  55. }
  56. #define DO_ERROR_INFO(signr, str, name, sicode) \
  57. int name(unsigned long cause, unsigned long address, struct pt_regs *regs) \
  58. { \
  59. siginfo_t info = { \
  60. .si_signo = signr, \
  61. .si_errno = 0, \
  62. .si_code = sicode, \
  63. .si_addr = (void __user *)address, \
  64. }; \
  65. return handle_exception(cause, str, regs, &info);\
  66. }
  67. /*
  68. * Entry points for exceptions NOT needing specific handling
  69. */
  70. DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
  71. DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
  72. DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
  73. DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", do_memory_error, BUS_ADRERR)
  74. DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
  75. DO_ERROR_INFO(SIGBUS, "Misaligned Access", do_misaligned_error, BUS_ADRALN)
  76. #ifdef CONFIG_ARC_MISALIGN_ACCESS
  77. /*
  78. * Entry Point for Misaligned Data access Exception, for emulating in software
  79. */
  80. int do_misaligned_access(unsigned long cause, unsigned long address,
  81. struct pt_regs *regs, struct callee_regs *cregs)
  82. {
  83. if (misaligned_fixup(address, regs, cause, cregs) != 0)
  84. return do_misaligned_error(cause, address, regs);
  85. return 0;
  86. }
  87. #endif
  88. /*
  89. * Entry point for miscll errors such as Nested Exceptions
  90. * -Duplicate TLB entry is handled seperately though
  91. */
  92. void do_machine_check_fault(unsigned long cause, unsigned long address,
  93. struct pt_regs *regs)
  94. {
  95. die("Machine Check Exception", regs, address, cause);
  96. }
  97. /*
  98. * Entry point for traps induced by ARCompact TRAP_S <n> insn
  99. * This is same family as TRAP0/SWI insn (use the same vector).
  100. * The only difference being SWI insn take no operand, while TRAP_S does
  101. * which reflects in ECR Reg as 8 bit param.
  102. * Thus TRAP_S <n> can be used for specific purpose
  103. * -1 used for software breakpointing (gdb)
  104. * -2 used by kprobes
  105. */
  106. void do_non_swi_trap(unsigned long cause, unsigned long address,
  107. struct pt_regs *regs)
  108. {
  109. unsigned int param = cause & 0xff;
  110. switch (param) {
  111. case 1:
  112. trap_is_brkpt(cause, address, regs);
  113. break;
  114. case 2:
  115. trap_is_kprobe(param, address, regs);
  116. break;
  117. case 3:
  118. case 4:
  119. kgdb_trap(regs, param);
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. /*
  126. * Entry point for Instruction Error Exception
  127. * -For a corner case, ARC kprobes implementation resorts to using
  128. * this exception, hence the check
  129. */
  130. void do_insterror_or_kprobe(unsigned long cause,
  131. unsigned long address,
  132. struct pt_regs *regs)
  133. {
  134. /* Check if this exception is caused by kprobes */
  135. if (notify_die(DIE_IERR, "kprobe_ierr", regs, address,
  136. cause, SIGILL) == NOTIFY_STOP)
  137. return;
  138. insterror_is_error(cause, address, regs);
  139. }