bug.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 Regents of the University of California
  4. */
  5. #ifndef _ASM_RISCV_BUG_H
  6. #define _ASM_RISCV_BUG_H
  7. #include <linux/compiler.h>
  8. #include <linux/const.h>
  9. #include <linux/types.h>
  10. #include <asm/asm.h>
  11. #define __INSN_LENGTH_MASK _UL(0x3)
  12. #define __INSN_LENGTH_32 _UL(0x3)
  13. #define __COMPRESSED_INSN_MASK _UL(0xffff)
  14. #define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
  15. #define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */
  16. #define GET_INSN_LENGTH(insn) \
  17. ({ \
  18. unsigned long __len; \
  19. __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \
  20. 4UL : 2UL; \
  21. __len; \
  22. })
  23. typedef u32 bug_insn_t;
  24. #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
  25. #define __BUG_ENTRY_ADDR RISCV_INT " 1b - 2b"
  26. #define __BUG_ENTRY_FILE RISCV_INT " %0 - 2b"
  27. #else
  28. #define __BUG_ENTRY_ADDR RISCV_PTR " 1b"
  29. #define __BUG_ENTRY_FILE RISCV_PTR " %0"
  30. #endif
  31. #ifdef CONFIG_DEBUG_BUGVERBOSE
  32. #define __BUG_ENTRY \
  33. __BUG_ENTRY_ADDR "\n\t" \
  34. __BUG_ENTRY_FILE "\n\t" \
  35. RISCV_SHORT " %1\n\t" \
  36. RISCV_SHORT " %2"
  37. #else
  38. #define __BUG_ENTRY \
  39. __BUG_ENTRY_ADDR "\n\t" \
  40. RISCV_SHORT " %2"
  41. #endif
  42. #ifdef CONFIG_GENERIC_BUG
  43. #define __BUG_FLAGS(flags) \
  44. do { \
  45. __asm__ __volatile__ ( \
  46. "1:\n\t" \
  47. "ebreak\n" \
  48. ".pushsection __bug_table,\"aw\"\n\t" \
  49. "2:\n\t" \
  50. __BUG_ENTRY "\n\t" \
  51. ".org 2b + %3\n\t" \
  52. ".popsection" \
  53. : \
  54. : "i" (__FILE__), "i" (__LINE__), \
  55. "i" (flags), \
  56. "i" (sizeof(struct bug_entry))); \
  57. } while (0)
  58. #else /* CONFIG_GENERIC_BUG */
  59. #define __BUG_FLAGS(flags) do { \
  60. __asm__ __volatile__ ("ebreak\n"); \
  61. } while (0)
  62. #endif /* CONFIG_GENERIC_BUG */
  63. #define BUG() do { \
  64. __BUG_FLAGS(0); \
  65. unreachable(); \
  66. } while (0)
  67. #define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
  68. #define HAVE_ARCH_BUG
  69. #include <asm-generic/bug.h>
  70. struct pt_regs;
  71. struct task_struct;
  72. void die(struct pt_regs *regs, const char *str);
  73. void do_trap(struct pt_regs *regs, int signo, int code, unsigned long addr);
  74. #endif /* _ASM_RISCV_BUG_H */