Furi: smaller crash routine (#1912)
* Furi: smaller crash routine * Furi: small fixes * Furi: cleanup check routines, more assembly code, force inline of __furi_halt_mcu * SubGhz: cleanup residual line mess * Documentation * Dap-link: fix help * Furi: replace __furi_halt_mcu with HALT_MCU macros * Furi: disable IRQ earlier in crash handler * Furi: properly handle masked mode when detecting ISR * Ble: allow 0 length feed in rpc_session_feed * Format sources * Furi: better crash logic explanation. * Furi: some grammar in check.h Co-authored-by: SG <who.just.the.doctor@gmail.com>
This commit is contained in:
+36
-24
@@ -1,3 +1,16 @@
|
||||
/**
|
||||
* @file check.h
|
||||
*
|
||||
* Furi crash and assert functions.
|
||||
*
|
||||
* The main problem with crashing is that you can't do anything without disturbing registers,
|
||||
* and if you disturb registers, you won't be able to see the correct register values in the debugger.
|
||||
*
|
||||
* Current solution works around it by passing the message through r12 and doing some magic with registers in crash function.
|
||||
* r0-r10 are stored in the ram2 on crash routine start and restored at the end.
|
||||
* The only register that is going to be lost is r11.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -8,9 +21,6 @@ extern "C" {
|
||||
#define FURI_NORETURN noreturn
|
||||
#endif
|
||||
|
||||
/** Pointer to pass message to __furi_crash and __furi_halt */
|
||||
extern const char* __furi_check_message;
|
||||
|
||||
/** Crash system */
|
||||
FURI_NORETURN void __furi_crash();
|
||||
|
||||
@@ -18,39 +28,41 @@ FURI_NORETURN void __furi_crash();
|
||||
FURI_NORETURN void __furi_halt();
|
||||
|
||||
/** Crash system with message. Show message after reboot. */
|
||||
#define furi_crash(message) \
|
||||
do { \
|
||||
__furi_check_message = message; \
|
||||
__furi_crash(); \
|
||||
#define furi_crash(message) \
|
||||
do { \
|
||||
register const void* r12 asm("r12") = (void*)message; \
|
||||
asm volatile("sukima%=:" : : "r"(r12)); \
|
||||
__furi_crash(); \
|
||||
} while(0)
|
||||
|
||||
/** Halt system with message. */
|
||||
#define furi_halt(message) \
|
||||
do { \
|
||||
__furi_check_message = message; \
|
||||
__furi_halt(); \
|
||||
#define furi_halt(message) \
|
||||
do { \
|
||||
register const void* r12 asm("r12") = (void*)message; \
|
||||
asm volatile("sukima%=:" : : "r"(r12)); \
|
||||
__furi_halt(); \
|
||||
} while(0)
|
||||
|
||||
/** Check condition and crash if check failed */
|
||||
#define furi_check(__e) \
|
||||
do { \
|
||||
if ((__e) == 0) { \
|
||||
furi_crash("furi_check failed\r\n"); \
|
||||
} \
|
||||
#define furi_check(__e) \
|
||||
do { \
|
||||
if((__e) == 0) { \
|
||||
furi_crash("furi_check failed\r\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/** Only in debug build: Assert condition and crash if assert failed */
|
||||
#ifdef FURI_DEBUG
|
||||
#define furi_assert(__e) \
|
||||
do { \
|
||||
if ((__e) == 0) { \
|
||||
furi_crash("furi_assert failed\r\n"); \
|
||||
} \
|
||||
#define furi_assert(__e) \
|
||||
do { \
|
||||
if((__e) == 0) { \
|
||||
furi_crash("furi_assert failed\r\n"); \
|
||||
} \
|
||||
} while(0)
|
||||
#else
|
||||
#define furi_assert(__e) \
|
||||
do { \
|
||||
((void)(__e)); \
|
||||
#define furi_assert(__e) \
|
||||
do { \
|
||||
((void)(__e)); \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user