bug.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (C) 2012 Regents of the University of California
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _ASM_RISCV_BUG_H
  14. #define _ASM_RISCV_BUG_H
  15. #include <linux/compiler.h>
  16. #include <linux/const.h>
  17. #include <linux/types.h>
  18. #include <asm/asm.h>
  19. #ifdef CONFIG_GENERIC_BUG
  20. #define __BUG_INSN _AC(0x00100073, UL) /* ebreak */
  21. #ifndef __ASSEMBLY__
  22. typedef u32 bug_insn_t;
  23. #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
  24. #define __BUG_ENTRY_ADDR RISCV_INT " 1b - 2b"
  25. #define __BUG_ENTRY_FILE RISCV_INT " %0 - 2b"
  26. #else
  27. #define __BUG_ENTRY_ADDR RISCV_PTR " 1b"
  28. #define __BUG_ENTRY_FILE RISCV_PTR " %0"
  29. #endif
  30. #ifdef CONFIG_DEBUG_BUGVERBOSE
  31. #define __BUG_ENTRY \
  32. __BUG_ENTRY_ADDR "\n\t" \
  33. __BUG_ENTRY_FILE "\n\t" \
  34. RISCV_SHORT " %1"
  35. #else
  36. #define __BUG_ENTRY \
  37. __BUG_ENTRY_ADDR
  38. #endif
  39. #define BUG() \
  40. do { \
  41. __asm__ __volatile__ ( \
  42. "1:\n\t" \
  43. "ebreak\n" \
  44. ".pushsection __bug_table,\"a\"\n\t" \
  45. "2:\n\t" \
  46. __BUG_ENTRY "\n\t" \
  47. ".org 2b + %2\n\t" \
  48. ".popsection" \
  49. : \
  50. : "i" (__FILE__), "i" (__LINE__), \
  51. "i" (sizeof(struct bug_entry))); \
  52. unreachable(); \
  53. } while (0)
  54. #endif /* !__ASSEMBLY__ */
  55. #else /* CONFIG_GENERIC_BUG */
  56. #ifndef __ASSEMBLY__
  57. #define BUG() \
  58. do { \
  59. __asm__ __volatile__ ("ebreak\n"); \
  60. unreachable(); \
  61. } while (0)
  62. #endif /* !__ASSEMBLY__ */
  63. #endif /* CONFIG_GENERIC_BUG */
  64. #define HAVE_ARCH_BUG
  65. #include <asm-generic/bug.h>
  66. #ifndef __ASSEMBLY__
  67. struct pt_regs;
  68. struct task_struct;
  69. extern void die(struct pt_regs *regs, const char *str);
  70. extern void do_trap(struct pt_regs *regs, int signo, int code,
  71. unsigned long addr, struct task_struct *tsk);
  72. #endif /* !__ASSEMBLY__ */
  73. #endif /* _ASM_RISCV_BUG_H */