-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f089d0
commit e466fa4
Showing
4 changed files
with
255 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,168 @@ | ||
#pragma once | ||
#include "macros.h" | ||
#include "os.h" | ||
|
||
WEAK void __attribute__((noreturn)) debug_display_throw_error(int exception); | ||
#ifdef HAVE_DEBUG_THROWS | ||
WEAK void app_throw_info(unsigned int exception, unsigned int lr_val); | ||
WEAK void __attribute__((noreturn)) debug_display_exit(int exception); | ||
#endif | ||
|
||
void ledger_assert(void); | ||
|
||
#define ASSERT_ERROR_CODE 0xBAAD | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO | ||
#define LEDGER_ASSERT_CONFIG_MESSAGE_INFO 1 | ||
#define LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO 1 | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_MESSAGE_INFO | ||
#define LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO 1 | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO | ||
#endif | ||
|
||
#ifdef HAVE_LEDGER_ASSERT_DISPLAY | ||
#ifdef LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO | ||
#define LR_AND_PC_OFFSET 0 | ||
#define LR_AND_PC_SIZE 30 | ||
WEAK void assert_display_lr_and_pc(int lr, int pc); | ||
#define ASSERT_DISPLAY_LR_AND_PC(lr, pc) assert_display_lr_and_pc(lr, pc) | ||
#else | ||
#define LR_AND_PC_SIZE 0 | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_MESSAGE_INFO | ||
#define MESSAGE_OFFSET LR_AND_PC_SIZE | ||
#define MESSAGE_SIZE 20 | ||
WEAK void assert_display_message(const char *message); | ||
#define ASSERT_DISPLAY_MESSAGE(message) assert_display_message(message) | ||
#else | ||
#define MESSAGE_SIZE 0 | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO | ||
#define FILE_OFFSET MESSAGE_OFFSET + MESSAGE_SIZE | ||
#define FILE_SIZE 50 | ||
WEAK void assert_display_file_info(const char *file, unsigned int line); | ||
#define ASSERT_DISPLAY_FILE_INFO(file, line) assert_display_file_info(file, line) | ||
#else | ||
#define FILE_SIZE 0 | ||
#endif | ||
|
||
#define ASSERT_BUFFER_LEN LR_AND_PC_SIZE + MESSAGE_SIZE + FILE_SIZE | ||
#else | ||
#ifdef LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO | ||
#define ASSERT_DISPLAY_LR_AND_PC(lr, pc) \ | ||
do { \ | ||
} while (0) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_MESSAGE_INFO | ||
#define ASSERT_DISPLAY_MESSAGE(message) \ | ||
do { \ | ||
} while (0) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO | ||
#define ASSERT_DISPLAY_FILE_INFO(file, line) \ | ||
do { \ | ||
} while (0) | ||
#endif | ||
#endif | ||
|
||
#ifdef HAVE_PRINTF | ||
#ifdef LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO | ||
void print_lr_and_pc(int lr, int pc); | ||
#define ASSERT_PRINT_LR_AND_PC(lr, pc) print_lr_and_pc(lr, pc) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_MESSAGE_INFO | ||
void print_message(const char *message); | ||
#define ASSERT_PRINT_MESSAGE(message) print_message(message) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO | ||
void print_file_info(const char *file, int line); | ||
#define ASSERT_PRINT_FILE_INFO(file, line) print_file_info(file, line) | ||
#endif | ||
#else | ||
#ifdef LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO | ||
#define ASSERT_PRINT_LR_AND_PC(lr, pc) \ | ||
do { \ | ||
} while (0) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_MESSAGE_INFO | ||
#define ASSERT_PRINT_MESSAGE(message) \ | ||
do { \ | ||
} while (0) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO | ||
#define ASSERT_PRINT_FILE_INFO(file, line) \ | ||
do { \ | ||
} while (0) | ||
#endif | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO | ||
#define LEDGER_ASSERT_LR_AND_PC() \ | ||
do { \ | ||
int _lr_address = 0; \ | ||
int _pc_address = 0; \ | ||
\ | ||
__asm volatile("mov %0, lr" : "=r"(_lr_address)); \ | ||
__asm volatile("mov %0, pc" : "=r"(_pc_address)); \ | ||
_lr_address = compute_address_location(_lr_address); \ | ||
_pc_address = compute_address_location(_pc_address); \ | ||
ASSERT_PRINT_LR_AND_PC(_lr_address, _pc_address); \ | ||
ASSERT_DISPLAY_LR_AND_PC(_lr_address, _pc_address); \ | ||
} while (0) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_MESSAGE_INFO | ||
#define LEDGER_ASSERT_MESSAGE(message) \ | ||
do { \ | ||
ASSERT_PRINT_MESSAGE(message); \ | ||
ASSERT_DISPLAY_MESSAGE(message); \ | ||
} while (0) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO | ||
#define LEDGER_ASSERT_FILE_INFO() \ | ||
do { \ | ||
ASSERT_PRINT_FILE_INFO(__FILE__, __LINE__); \ | ||
ASSERT_DISPLAY_FILE_INFO(__FILE__, __LINE__); \ | ||
} while (0) | ||
#endif | ||
|
||
#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO | ||
#define LEDGER_ASSERT(test, message) \ | ||
do { \ | ||
if (!(test)) { \ | ||
LEDGER_ASSERT_LR_AND_PC(); \ | ||
LEDGER_ASSERT_MESSAGE(message); \ | ||
LEDGER_ASSERT_FILE_INFO(); \ | ||
ledger_assert(); \ | ||
} \ | ||
} while (0) | ||
#elif defined(LEDGER_ASSERT_CONFIG_MESSAGE_INFO) | ||
#define LEDGER_ASSERT(test, message) \ | ||
do { \ | ||
if (!(test)) { \ | ||
LEDGER_ASSERT_LR_AND_PC(); \ | ||
LEDGER_ASSERT_MESSAGE(message); \ | ||
ledger_assert(); \ | ||
} \ | ||
} while (0) | ||
#elif defined(LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO) | ||
#define LEDGER_ASSERT(test, message) \ | ||
do { \ | ||
if (!(test)) { \ | ||
LEDGER_ASSERT_LR_AND_PC(); \ | ||
ledger_assert(); \ | ||
} \ | ||
} while (0) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters