traps.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * Rahul Trivedi: Codito Technologies 2004
  11. */
  12. #include <linux/sched.h>
  13. #include <linux/kdebug.h>
  14. #include <linux/uaccess.h>
  15. #include <asm/ptrace.h>
  16. #include <asm/setup.h>
  17. #include <asm/kprobes.h>
  18. void __init trap_init(void)
  19. {
  20. return;
  21. }
  22. void die(const char *str, struct pt_regs *regs, unsigned long address,
  23. unsigned long cause_reg)
  24. {
  25. show_kernel_fault_diag(str, regs, address, cause_reg);
  26. /* DEAD END */
  27. __asm__("flag 1");
  28. }
  29. /*
  30. * Helper called for bulk of exceptions NOT needing specific handling
  31. * -for user faults enqueues requested signal
  32. * -for kernel, chk if due to copy_(to|from)_user, otherwise die()
  33. */
  34. static noinline int handle_exception(unsigned long cause, char *str,
  35. struct pt_regs *regs, siginfo_t *info)
  36. {
  37. if (user_mode(regs)) {
  38. struct task_struct *tsk = current;
  39. tsk->thread.fault_address = (__force unsigned int)info->si_addr;
  40. tsk->thread.cause_code = cause;
  41. force_sig_info(info->si_signo, info, tsk);
  42. } else {
  43. /* If not due to copy_(to|from)_user, we are doomed */
  44. if (fixup_exception(regs))
  45. return 0;
  46. die(str, regs, (unsigned long)info->si_addr, cause);
  47. }
  48. return 1;
  49. }
  50. #define DO_ERROR_INFO(signr, str, name, sicode) \
  51. int name(unsigned long cause, unsigned long address, struct pt_regs *regs) \
  52. { \
  53. siginfo_t info = { \
  54. .si_signo = signr, \
  55. .si_errno = 0, \
  56. .si_code = sicode, \
  57. .si_addr = (void __user *)address, \
  58. }; \
  59. return handle_exception(cause, str, regs, &info);\
  60. }
  61. /*
  62. * Entry points for exceptions NOT needing specific handling
  63. */
  64. DO_ERROR_INFO(SIGILL, "Priv Op/Disabled Extn", do_privilege_fault, ILL_PRVOPC)
  65. DO_ERROR_INFO(SIGILL, "Invalid Extn Insn", do_extension_fault, ILL_ILLOPC)
  66. DO_ERROR_INFO(SIGILL, "Illegal Insn (or Seq)", insterror_is_error, ILL_ILLOPC)
  67. DO_ERROR_INFO(SIGBUS, "Invalid Mem Access", do_memory_error, BUS_ADRERR)
  68. DO_ERROR_INFO(SIGTRAP, "Breakpoint Set", trap_is_brkpt, TRAP_BRKPT)
  69. DO_ERROR_INFO(SIGSEGV, "Misaligned Access", do_misaligned_access, SEGV_ACCERR)
  70. /*
  71. * Entry point for miscll errors such as Nested Exceptions
  72. * -Duplicate TLB entry is handled seperately though
  73. */
  74. void do_machine_check_fault(unsigned long cause, unsigned long address,
  75. struct pt_regs *regs)
  76. {
  77. die("Machine Check Exception", regs, address, cause);
  78. }
  79. /*
  80. * Entry point for traps induced by ARCompact TRAP_S <n> insn
  81. * This is same family as TRAP0/SWI insn (use the same vector).
  82. * The only difference being SWI insn take no operand, while TRAP_S does
  83. * which reflects in ECR Reg as 8 bit param.
  84. * Thus TRAP_S <n> can be used for specific purpose
  85. * -1 used for software breakpointing (gdb)
  86. * -2 used by kprobes
  87. */
  88. void do_non_swi_trap(unsigned long cause, unsigned long address,
  89. struct pt_regs *regs)
  90. {
  91. unsigned int param = cause & 0xff;
  92. switch (param) {
  93. case 1:
  94. trap_is_brkpt(cause, address, regs);
  95. break;
  96. case 2:
  97. trap_is_kprobe(param, address, regs);
  98. break;
  99. default:
  100. break;
  101. }
  102. }
  103. /*
  104. * Entry point for Instruction Error Exception
  105. * -For a corner case, ARC kprobes implementation resorts to using
  106. * this exception, hence the check
  107. */
  108. void do_insterror_or_kprobe(unsigned long cause,
  109. unsigned long address,
  110. struct pt_regs *regs)
  111. {
  112. /* Check if this exception is caused by kprobes */
  113. if (notify_die(DIE_IERR, "kprobe_ierr", regs, address,
  114. cause, SIGILL) == NOTIFY_STOP)
  115. return;
  116. insterror_is_error(cause, address, regs);
  117. }