Commit d18ebc27 authored by Vincent Chen's avatar Vincent Chen Committed by Palmer Dabbelt

riscv: support trap-based WARN()

The WARN() related function will trigger a debug exception. This can help
developers to analyze the cause of WARN() because if the debugger is
connected, the control flow will be transferred to debugging
environment.
Signed-off-by: default avatarVincent Chen <vincentc@andestech.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarPalmer Dabbelt <palmer@sifive.com>
parent a21344df
...@@ -38,38 +38,46 @@ typedef u32 bug_insn_t; ...@@ -38,38 +38,46 @@ typedef u32 bug_insn_t;
#define __BUG_ENTRY \ #define __BUG_ENTRY \
__BUG_ENTRY_ADDR "\n\t" \ __BUG_ENTRY_ADDR "\n\t" \
__BUG_ENTRY_FILE "\n\t" \ __BUG_ENTRY_FILE "\n\t" \
RISCV_SHORT " %1" RISCV_SHORT " %1\n\t" \
RISCV_SHORT " %2"
#else #else
#define __BUG_ENTRY \ #define __BUG_ENTRY \
__BUG_ENTRY_ADDR __BUG_ENTRY_ADDR "\n\t" \
RISCV_SHORT " %2"
#endif #endif
#define BUG() \ #define __BUG_FLAGS(flags) \
do { \ do { \
__asm__ __volatile__ ( \ __asm__ __volatile__ ( \
"1:\n\t" \ "1:\n\t" \
"ebreak\n" \ "ebreak\n" \
".pushsection __bug_table,\"a\"\n\t" \ ".pushsection __bug_table,\"aw\"\n\t" \
"2:\n\t" \ "2:\n\t" \
__BUG_ENTRY "\n\t" \ __BUG_ENTRY "\n\t" \
".org 2b + %2\n\t" \ ".org 2b + %3\n\t" \
".popsection" \ ".popsection" \
: \ : \
: "i" (__FILE__), "i" (__LINE__), \ : "i" (__FILE__), "i" (__LINE__), \
"i" (sizeof(struct bug_entry))); \ "i" (flags), \
unreachable(); \ "i" (sizeof(struct bug_entry))); \
} while (0) } while (0)
#endif /* !__ASSEMBLY__ */ #endif /* !__ASSEMBLY__ */
#else /* CONFIG_GENERIC_BUG */ #else /* CONFIG_GENERIC_BUG */
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#define BUG() \ #define __BUG_FLAGS(flags) do { \
do { \
__asm__ __volatile__ ("ebreak\n"); \ __asm__ __volatile__ ("ebreak\n"); \
unreachable(); \
} while (0) } while (0)
#endif /* !__ASSEMBLY__ */ #endif /* !__ASSEMBLY__ */
#endif /* CONFIG_GENERIC_BUG */ #endif /* CONFIG_GENERIC_BUG */
#define BUG() do { \
__BUG_FLAGS(0); \
unreachable(); \
} while (0)
#define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
#define HAVE_ARCH_BUG #define HAVE_ARCH_BUG
#include <asm-generic/bug.h> #include <asm-generic/bug.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment