Commit 43f003bb authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

powerpc: Refactor BUG/WARN macros

BUG(), WARN() and friends are using a similar inline assembly to
implement various traps with various flags.

Lets refactor via a new BUG_ENTRY() macro.
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/c19a82b37677ace0eebb0dc8c2120373c29c8dd1.1566219503.git.christophe.leroy@c-s.fr
parent 98ba8e80
...@@ -49,6 +49,15 @@ ...@@ -49,6 +49,15 @@
".previous\n" ".previous\n"
#endif #endif
#define BUG_ENTRY(insn, flags, ...) \
__asm__ __volatile__( \
"1: " insn "\n" \
_EMIT_BUG_ENTRY \
: : "i" (__FILE__), "i" (__LINE__), \
"i" (flags), \
"i" (sizeof(struct bug_entry)), \
##__VA_ARGS__)
/* /*
* BUG_ON() and WARN_ON() do their best to cooperate with compile-time * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
* optimisations. However depending on the complexity of the condition * optimisations. However depending on the complexity of the condition
...@@ -56,11 +65,7 @@ ...@@ -56,11 +65,7 @@
*/ */
#define BUG() do { \ #define BUG() do { \
__asm__ __volatile__( \ BUG_ENTRY("twi 31, 0, 0", 0); \
"1: twi 31,0,0\n" \
_EMIT_BUG_ENTRY \
: : "i" (__FILE__), "i" (__LINE__), \
"i" (0), "i" (sizeof(struct bug_entry))); \
unreachable(); \ unreachable(); \
} while (0) } while (0)
...@@ -69,23 +74,11 @@ ...@@ -69,23 +74,11 @@
if (x) \ if (x) \
BUG(); \ BUG(); \
} else { \ } else { \
__asm__ __volatile__( \ BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \
"1: "PPC_TLNEI" %4,0\n" \
_EMIT_BUG_ENTRY \
: : "i" (__FILE__), "i" (__LINE__), "i" (0), \
"i" (sizeof(struct bug_entry)), \
"r" ((__force long)(x))); \
} \ } \
} while (0) } while (0)
#define __WARN_FLAGS(flags) do { \ #define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags))
__asm__ __volatile__( \
"1: twi 31,0,0\n" \
_EMIT_BUG_ENTRY \
: : "i" (__FILE__), "i" (__LINE__), \
"i" (BUGFLAG_WARNING|(flags)), \
"i" (sizeof(struct bug_entry))); \
} while (0)
#define WARN_ON(x) ({ \ #define WARN_ON(x) ({ \
int __ret_warn_on = !!(x); \ int __ret_warn_on = !!(x); \
...@@ -93,13 +86,9 @@ ...@@ -93,13 +86,9 @@
if (__ret_warn_on) \ if (__ret_warn_on) \
__WARN(); \ __WARN(); \
} else { \ } else { \
__asm__ __volatile__( \ BUG_ENTRY(PPC_TLNEI " %4, 0", \
"1: "PPC_TLNEI" %4,0\n" \ BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \
_EMIT_BUG_ENTRY \ "r" (__ret_warn_on)); \
: : "i" (__FILE__), "i" (__LINE__), \
"i" (BUGFLAG_WARNING|BUGFLAG_TAINT(TAINT_WARN)),\
"i" (sizeof(struct bug_entry)), \
"r" (__ret_warn_on)); \
} \ } \
unlikely(__ret_warn_on); \ unlikely(__ret_warn_on); \
}) })
......
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