diff --git a/.project b/.project new file mode 100644 index 00000000..5ad20221 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + ZeroPilot-SW-3 + + + + + + + + diff --git a/Common/Inc/zp_assert.h b/Common/Inc/zp_assert.h new file mode 100644 index 00000000..e465c857 --- /dev/null +++ b/Common/Inc/zp_assert.h @@ -0,0 +1,29 @@ +#pragma once + +#ifndef ZP_ASSERT_H +#define ZP_ASSERT_H + +#include + +typedef struct sAssertInfo { + uint64_t pc; + uint64_t lr; +} sAssertInfo; + +void store_assert(const uint64_t *pc, const uint64_t *lr); + +#define GET_LR() __builtin_return_address(0) +//#define GET_PC(_a) __asm volatile ("mov %0, pc" : "=r" (_a)) // Comment out this for ARM +#define GET_PC(_a) __asm volatile("1: lea 1b(%%rip), %0;": "=a"(pc)); // Comment this for x86 + +#define MY_ASSERT_RECORD() \ + do { \ + void *pc = NULL; \ + GET_PC(pc); \ + const void *lr = GET_LR(); \ + store_assert(pc, lr); \ + } while (0) + +void zp_assert(bool expr); + +#endif diff --git a/Common/Src/zp_assert.c b/Common/Src/zp_assert.c new file mode 100644 index 00000000..235724b9 --- /dev/null +++ b/Common/Src/zp_assert.c @@ -0,0 +1,17 @@ +#include "zp_assert.h" + +static sAssertInfo g_assert_info; + +void store_assert(const uint64_t *pc, const uint64_t *lr) { + g_assert_info.pc = pc; + g_assert_info.lr = lr; +} + +void zp_assert(bool expr) { + if (!expr) { +//#warning This should call the los hardfault handler, or something more appropriate + while (1) { + MY_ASSERT_RECORD(); + } + } +}