Skip to content

Commit

Permalink
reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Nov 29, 2023
1 parent e466fa4 commit a54437c
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 163 deletions.
12 changes: 4 additions & 8 deletions Makefile.standard_app
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,14 @@ ifneq ($(DEBUG), 0)
else
DEFINES += PRINTF=mcu_usb_printf
endif
ifneq ($(DISABLE_LEDGER_ASSERT), 1)
DEFINES += HAVE_LEDGER_ASSERT_DISPLAY
DEFINES += LEDGER_ASSERT_CONFIG_FILE_INFO
endif
else
DEFINES += PRINTF\(...\)=
endif

#####################################################################
# LEDGER_ASSERT #
#####################################################################
ifneq ($(DISABLE_LEDGER_ASSERT), 1)
DEFINES += HAVE_LEDGER_ASSERT_DISPLAY
DEFINES += LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO
endif

#####################################################################
# IO SEPROXY BUFFER SIZE #
#####################################################################
Expand Down
123 changes: 57 additions & 66 deletions lib_standard_app/debug.h → include/ledger_assert.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#pragma once
#include "macros.h"
#include "os.h"

#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
#include "appflags.h"
#include "bolos_target.h"
#include "decorators.h"
#include "errors.h"

void ledger_assert(void);
void __attribute__((noreturn)) assert_display_exit(void);

#define ASSERT_ERROR_CODE 0xBAAD

Expand All @@ -20,105 +18,86 @@ void ledger_assert(void);
#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
#if defined(LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO) && defined(HAVE_LEDGER_ASSERT_DISPLAY)
#define LR_AND_PC_OFFSET 0
#define LR_AND_PC_SIZE 30
WEAK void assert_display_lr_and_pc(int lr, int pc);
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
#define ASSERT_DISPLAY_LR_AND_PC(lr, pc) \
do { \
} while (0)
#endif

#ifdef LEDGER_ASSERT_CONFIG_MESSAGE_INFO
#if defined(LEDGER_ASSERT_CONFIG_MESSAGE_INFO) && defined(HAVE_LEDGER_ASSERT_DISPLAY)
#define MESSAGE_OFFSET LR_AND_PC_SIZE
#define MESSAGE_SIZE 20
WEAK void assert_display_message(const char *message);
void assert_display_message(const char *message);
#define ASSERT_DISPLAY_MESSAGE(message) assert_display_message(message)
#else
#define MESSAGE_SIZE 0
#define ASSERT_DISPLAY_MESSAGE(message) \
do { \
} while (0)
#endif

#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO
#if defined(LEDGER_ASSERT_CONFIG_FILE_INFO) && defined(HAVE_LEDGER_ASSERT_DISPLAY)
#define FILE_OFFSET MESSAGE_OFFSET + MESSAGE_SIZE
#define FILE_SIZE 50
WEAK void assert_display_file_info(const char *file, unsigned int line);
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)
#ifdef HAVE_LEDGER_ASSERT_DISPLAY
#define ASSERT_BUFFER_LEN LR_AND_PC_SIZE + MESSAGE_SIZE + FILE_SIZE
#define LEDGER_ASSERT_EXIT() assert_display_exit()
#else
#define LEDGER_ASSERT_EXIT() exit_app(true)
#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
#if defined(LEDGER_ASSERT_CONFIG_LR_AND_PC_INFO) && defined(HAVE_PRINTF)
void assert_print_lr_and_pc(int lr, int pc);
#define ASSERT_PRINT_LR_AND_PC(lr, pc) assert_print_lr_and_pc(lr, pc)
#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
#if defined(LEDGER_ASSERT_CONFIG_MESSAGE_INFO) && defined(HAVE_PRINTF)
void assert_print_message(const char *message);
#define ASSERT_PRINT_MESSAGE(message) assert_print_message(message)
#else
#define ASSERT_PRINT_MESSAGE(message) \
do { \
} while (0)
#endif

#ifdef LEDGER_ASSERT_CONFIG_FILE_INFO
#if defined(LEDGER_ASSERT_CONFIG_FILE_INFO) && defined(HAVE_PRINTF)
void assert_print_file_info(const char *file, int line);
#define ASSERT_PRINT_FILE_INFO(file, line) assert_print_file_info(file, line)
#else
#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); \
#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)); \
ASSERT_PRINT_LR_AND_PC(_lr_address, _pc_address); \
ASSERT_DISPLAY_LR_AND_PC(_lr_address, _pc_address); \
} while (0)
#endif

Expand All @@ -145,7 +124,7 @@ void print_file_info(const char *file, int line);
LEDGER_ASSERT_LR_AND_PC(); \
LEDGER_ASSERT_MESSAGE(message); \
LEDGER_ASSERT_FILE_INFO(); \
ledger_assert(); \
LEDGER_ASSERT_EXIT(); \
} \
} while (0)
#elif defined(LEDGER_ASSERT_CONFIG_MESSAGE_INFO)
Expand All @@ -154,15 +133,27 @@ void print_file_info(const char *file, int line);
if (!(test)) { \
LEDGER_ASSERT_LR_AND_PC(); \
LEDGER_ASSERT_MESSAGE(message); \
ledger_assert(); \
LEDGER_ASSERT_EXIT(); \
} \
} 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(); \
LEDGER_ASSERT_EXIT(); \
} \
} while (0)
#endif

#if defined(HAVE_DEBUG_THROWS)
void throw_display_lr(int e, int lr);
void throw_print_lr(int lr);
#define DEBUG_THROW(e) \
do { \
unsigned int lr_val; \
__asm volatile("mov %0, lr" : "=r"(lr_val)); \
throw_display_lr(e, lr_val); \
throw_print_lr(lr_val); \
} while (0)
#endif
2 changes: 0 additions & 2 deletions include/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ int snprintf(char *str, size_t str_size, const char *format, ...);
#endif // HAVE_SPRINTF

#ifndef HAVE_BOLOS
#if defined(HAVE_PRINTF) || defined(HAVE_DEBUG_THROWS)
int compute_address_location(int address);
#endif
#endif

// syscall test
// SYSCALL void dummy_1(unsigned int* p PLENGTH(2+len+15+ len + 16 + sizeof(io_send_t) + 1 ),
Expand Down
4 changes: 2 additions & 2 deletions lib_standard_app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "os.h"
#include "io.h"
#include "debug.h"
#include "ledger_assert.h"

#ifdef HAVE_SWAP
#include "swap.h"
Expand Down Expand Up @@ -90,7 +90,7 @@ static void standalone_app_main(void)
BLE_power(0, NULL);
#endif
// Display crash info on screen for debug purpose
debug_display_exit(e);
assert_display_exit();
#endif
}
FINALLY {}
Expand Down
Loading

0 comments on commit a54437c

Please sign in to comment.