diff options
author | Xiang W <wxjstz@126.com> | 2021-09-16 07:32:49 +0300 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2021-09-22 11:05:30 +0300 |
commit | 12753d22563f7d2d01f2c6644c7b66b06eb5c90f (patch) | |
tree | f1813ef20b2af5219a5481d1062262454152e2ac /include/sbi | |
parent | 3477f08b08da6bfd904218fdb76b3db592dd7ebd (diff) | |
download | opensbi-12753d22563f7d2d01f2c6644c7b66b06eb5c90f.tar.xz |
lib: sbi: add some macros to detect BUG at runtime
Three macros are added. One is called BUG, which is used to put in an
unreachable branch. One is called BUG_ON, which is used to check bugs
and assert conditions are opposite. One is called SBI_ASSERT, used for
assertion checking.
Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'include/sbi')
-rw-r--r-- | include/sbi/sbi_console.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index e24ba5f..28b4a79 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/sbi_hart.h> struct sbi_console_device { /** Name of the console device */ @@ -51,4 +52,23 @@ 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__); \ + sbi_hart_hang(); \ +} while (0) + +#define BUG_ON(cond) do { \ + if (cond) \ + BUG(); \ +} while (0) + +#define SBI_ASSERT(cond) do { \ + if (!(cond)) { \ + sbi_printf("ASSERT: %s:%d/%s(): Assertion `%s` failed.\n", \ + __FILE__,__LINE__,__func__, #cond);\ + sbi_hart_hang(); \ + } \ +} while (0) + #endif |