All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 1/2] lib: sbi: add some macros to detect BUG at runtime
@ 2021-09-15  9:03 Xiang W
  2021-09-15  9:03 ` [PATCH V2 2/2] lib: sbi: Add runtime bug detection for csr_read_num/csr_write_num/misa_string Xiang W
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Xiang W @ 2021-09-15  9:03 UTC (permalink / raw)
  To: opensbi

Two macros are mainly added. One is called BUG(), which is used to put
in unreachable branches. One named BUG_ON, used for assertion.

Signed-off-by: Xiang W <wxjstz@126.com>
---
 include/sbi/sbi_console.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h
index e24ba5f..e75a279 100644
--- a/include/sbi/sbi_console.h
+++ b/include/sbi/sbi_console.h
@@ -11,6 +11,7 @@
 #define __SBI_CONSOLE_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/riscv_asm.h>
 
 struct sbi_console_device {
 	/** Name of the console device */
@@ -51,4 +52,16 @@ struct sbi_scratch;
 
 int sbi_console_init(struct sbi_scratch *scratch);
 
+#define BUG() do { \
+	sbi_printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
+	while (1)	\
+		wfi();	\
+	__builtin_unreachable(); \
+} while (0)
+
+#define BUG_ON(cond) do { \
+	if (!(cond))	\
+		BUG(); \
+} while (0)
+
 #endif
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-09-16  4:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-15  9:03 [PATCH V2 1/2] lib: sbi: add some macros to detect BUG at runtime Xiang W
2021-09-15  9:03 ` [PATCH V2 2/2] lib: sbi: Add runtime bug detection for csr_read_num/csr_write_num/misa_string Xiang W
2021-09-15  9:27 ` [PATCH V2 1/2] lib: sbi: add some macros to detect BUG at runtime Andreas Schwab
2021-09-15 10:07   ` Xiang W
2021-09-15 12:39 ` 杜东
2021-09-15 13:56   ` Xiang W
2021-09-15 14:41     ` Mitchell Horne
2021-09-15 14:49       ` Jessica Clarke
2021-09-16  4:38         ` Xiang W

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.