Skip to content

Commit 98255ec

Browse files
committed
cm: cm_panic & cm_assert macros
Also includes: * Minor reordering of code.
1 parent a62e886 commit 98255ec

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

include/cm/cm.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,27 @@
1818
#include <syscall.h>
1919
#endif
2020

21-
#define INVALID_HANDLE (-1)
22-
#define HALT() for (;;)
23-
24-
INT cm_snprintf (CHAR* dest, size_t size, const CHAR* fmt, ...);
25-
INT cm_vsnprintf (CHAR* dest, size_t size, const CHAR* fmt, va_list l);
21+
#define INVALID_HANDLE (-1)
22+
#define CM_ABORT_EXIT_CODE (127U)
2623

2724
/***************************************************************************************************
2825
* Misc functions
2926
***************************************************************************************************/
27+
#define HALT() for (;;)
28+
29+
#define cm_panic() \
30+
do { \
31+
CM_DBG_ERROR ("Panic at %s: %u", __FILE__, __LINE__); \
32+
cm_process_abort (CM_ABORT_EXIT_CODE); \
33+
} while (0)
34+
35+
#define cm_assert(t) \
36+
do { \
37+
if (!(t)) { \
38+
cm_panic(); \
39+
} \
40+
} while (0)
41+
3042
void cm_delay (UINT ms);
3143

3244
static inline void cm_get_bootloaded_file (const char* const filename,
@@ -85,3 +97,5 @@ void* cm_memcpy (void* dest, const void* src, size_t n);
8597
UINT cm_strlen (const char* s);
8698
char* cm_strncpy (char* d, const char* s, SIZE n);
8799
void* cm_memset (void* const s, U8 c, size_t n);
100+
INT cm_snprintf (CHAR* dest, size_t size, const CHAR* fmt, ...);
101+
INT cm_vsnprintf (CHAR* dest, size_t size, const CHAR* fmt, va_list l);

0 commit comments

Comments
 (0)