diff options
author | Keith Short <keithshort@chromium.org> | 2021-07-29 12:14:37 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-07-30 16:41:04 +0000 |
commit | ae82a45be1a02e394904599c1b13c0b18c5c39a7 (patch) | |
tree | c72ffc87a52f591dd7a27e622ae163fe823055e8 /builtin | |
parent | 70fa081aad48db8319a3b7a3a793ee351fd1f763 (diff) | |
download | chrome-ec-ae82a45be1a02e394904599c1b13c0b18c5c39a7.tar.gz |
assert: Fix ASSERT() when !CONFIG_DEBUG_ASSERT_REBOOTS
The option CONFIG_DEBUG_ASSERT_REBOOTS can be undefined to save code
size and generate a software breakpoint to recovery.
Fix this code path to support the RISC-V and NDS32 architectures.
This also fixes an incorrect usage of __builtin_unreachable() which
caused all ASSERT() calls to generate an unconditional return.
BUG=none
BRANCH=none
TEST=Disable CONFIG_DEBUG_ASSERT_REBOOTS, run "crash assert" on hayato
(RISC-V architecture) and lazor (ARM architecture).
TEST=Disable CONFIG_DEBUG_ASSERT_REBOOTS on boten (NDS32 architecture)
and verfiy code compiles
Signed-off-by: Keith Short <keithshort@chromium.org>
Change-Id: Iff2455fd209355d4276488b48f7b1dfe52cc35b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3061077
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/assert.h | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/builtin/assert.h b/builtin/assert.h index f51ea7b57a..fb87f844ce 100644 --- a/builtin/assert.h +++ b/builtin/assert.h @@ -31,7 +31,7 @@ extern noreturn void panic_assert_fail(const char *fname, int linenum); #else /* !CONFIG_DEBUG_ASSERT_BRIEF */ extern noreturn void panic_assert_fail(const char *msg, const char *func, - const char *fname, int linenum); + const char *fname, int linenum); #define ASSERT(cond) \ do { \ if (!(cond)) \ @@ -42,11 +42,25 @@ extern noreturn void panic_assert_fail(const char *msg, const char *func, #else /* !CONFIG_DEBUG_ASSERT_REBOOTS */ -#define ASSERT(cond) \ - do { \ - if (!(cond)) \ - __asm("bkpt"); \ - __builtin_unreachable(); \ +#if defined(__arm__) +#define ARCH_SOFTWARE_BREAKPOINT __asm("bkpt") +#elif defined(__nds32__) +#define ARCH_SOFTWARE_BREAKPOINT __asm("break 0") +#elif defined(__riscv) +#define ARCH_SOFTWARE_BREAKPOINT __asm("ebreak") +#elif defined(VIF_BUILD) +/* The genvif utility compiles usb_pd_policy.c and needs an empty definition. */ +#define ARCH_SOFTWARE_BREAKPOINT +#else +#error "CONFIG_DEBUG_ASSERT_REBOOTS must be defined on this architecture" +#endif + +#define ASSERT(cond) \ + do { \ + if (!(cond)) { \ + ARCH_SOFTWARE_BREAKPOINT; \ + __builtin_unreachable(); \ + } \ } while (0) #endif /* CONFIG_DEBUG_ASSERT_REBOOTS */ |