mirror of
https://github.com/armink/CmBacktrace.git
synced 2025-01-08 20:16:17 +08:00
1、【完善】获取 PSP 、MSP 及 SP 寄存器函数,增强兼容性。
Signed-off-by: armink <armink.ztl@gmail.com>
This commit is contained in:
parent
8aae96fc28
commit
390541a413
@ -31,33 +31,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/* include or export for supported __get_MSP, __get_PSP function */
|
|
||||||
#if defined(__CC_ARM)
|
|
||||||
static __inline __asm uint32_t __get_MSP(void) {
|
|
||||||
mrs r0, msp
|
|
||||||
bx lr
|
|
||||||
}
|
|
||||||
static __inline __asm uint32_t __get_PSP(void) {
|
|
||||||
mrs r0, psp
|
|
||||||
bx lr
|
|
||||||
}
|
|
||||||
#elif defined(__ICCARM__)
|
|
||||||
#include <intrinsics.h>
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
__attribute__( ( always_inline ) ) static inline uint32_t __get_MSP(void) {
|
|
||||||
register uint32_t result;
|
|
||||||
__asm volatile ("MRS %0, msp\n" : "=r" (result) );
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
__attribute__( ( always_inline ) ) static inline uint32_t __get_PSP(void) {
|
|
||||||
register uint32_t result;
|
|
||||||
__asm volatile ("MRS %0, psp\n" : "=r" (result) );
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#error "not supported compiler"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__CC_ARM)
|
#if defined(__CC_ARM)
|
||||||
#define SECTION_START(_name_) _name_##$$Base
|
#define SECTION_START(_name_) _name_##$$Base
|
||||||
#define SECTION_END(_name_) _name_##$$Limit
|
#define SECTION_END(_name_) _name_##$$Limit
|
||||||
@ -369,7 +342,7 @@ size_t cm_backtrace_call_stack(uint32_t *buffer, size_t size, uint32_t sp) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* OS environment */
|
/* OS environment */
|
||||||
if (__get_SP() == __get_PSP()) {
|
if (cmb_get_sp() == cmb_get_psp()) {
|
||||||
get_cur_thread_stack_info(sp, &stack_start_addr, &stack_size);
|
get_cur_thread_stack_info(sp, &stack_start_addr, &stack_size);
|
||||||
}
|
}
|
||||||
#endif /* CMB_USING_OS_PLATFORM */
|
#endif /* CMB_USING_OS_PLATFORM */
|
||||||
@ -426,7 +399,7 @@ void cm_backtrace_assert(uint32_t sp) {
|
|||||||
CMB_ASSERT(init_ok);
|
CMB_ASSERT(init_ok);
|
||||||
|
|
||||||
#ifdef CMB_USING_OS_PLATFORM
|
#ifdef CMB_USING_OS_PLATFORM
|
||||||
uint32_t cur_stack_pointer = __get_SP();
|
uint32_t cur_stack_pointer = cmb_get_sp();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cmb_println("");
|
cmb_println("");
|
||||||
@ -434,14 +407,14 @@ void cm_backtrace_assert(uint32_t sp) {
|
|||||||
|
|
||||||
#ifdef CMB_USING_OS_PLATFORM
|
#ifdef CMB_USING_OS_PLATFORM
|
||||||
/* OS environment */
|
/* OS environment */
|
||||||
if (cur_stack_pointer == __get_MSP()) {
|
if (cur_stack_pointer == cmb_get_msp()) {
|
||||||
cmb_println(print_info[PRINT_ASSERT_ON_HANDLER]);
|
cmb_println(print_info[PRINT_ASSERT_ON_HANDLER]);
|
||||||
|
|
||||||
#ifdef CMB_USING_DUMP_STACK_INFO
|
#ifdef CMB_USING_DUMP_STACK_INFO
|
||||||
dump_main_stack(main_stack_start_addr, main_stack_size, (uint32_t *) sp);
|
dump_main_stack(main_stack_start_addr, main_stack_size, (uint32_t *) sp);
|
||||||
#endif /* CMB_USING_DUMP_STACK_INFO */
|
#endif /* CMB_USING_DUMP_STACK_INFO */
|
||||||
|
|
||||||
} else if (cur_stack_pointer == __get_PSP()) {
|
} else if (cur_stack_pointer == cmb_get_psp()) {
|
||||||
cmb_println(print_info[PRINT_ASSERT_ON_THREAD], get_cur_thread_name());
|
cmb_println(print_info[PRINT_ASSERT_ON_THREAD], get_cur_thread_name());
|
||||||
|
|
||||||
#ifdef CMB_USING_DUMP_STACK_INFO
|
#ifdef CMB_USING_DUMP_STACK_INFO
|
||||||
@ -616,7 +589,7 @@ void cm_backtrace_fault(uint32_t fault_handler_lr, uint32_t fault_handler_sp) {
|
|||||||
/* check which stack was used before (MSP or PSP) */
|
/* check which stack was used before (MSP or PSP) */
|
||||||
if (on_thread_before_fault) {
|
if (on_thread_before_fault) {
|
||||||
cmb_println(print_info[PRINT_FAULT_ON_THREAD], get_cur_thread_name() != NULL ? get_cur_thread_name() : "NO_NAME");
|
cmb_println(print_info[PRINT_FAULT_ON_THREAD], get_cur_thread_name() != NULL ? get_cur_thread_name() : "NO_NAME");
|
||||||
saved_regs_addr = stack_pointer = __get_PSP();
|
saved_regs_addr = stack_pointer = cmb_get_psp();
|
||||||
|
|
||||||
#ifdef CMB_USING_DUMP_STACK_INFO
|
#ifdef CMB_USING_DUMP_STACK_INFO
|
||||||
get_cur_thread_stack_info(stack_pointer, &stack_start_addr, &stack_size);
|
get_cur_thread_stack_info(stack_pointer, &stack_start_addr, &stack_size);
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* library software version number */
|
/* library software version number */
|
||||||
#define CMB_SW_VERSION "0.2.0"
|
#define CMB_SW_VERSION "0.2.1"
|
||||||
|
|
||||||
#define CMB_CPU_ARM_CORTEX_M0 0
|
#define CMB_CPU_ARM_CORTEX_M0 0
|
||||||
#define CMB_CPU_ARM_CORTEX_M3 1
|
#define CMB_CPU_ARM_CORTEX_M3 1
|
||||||
@ -314,16 +314,51 @@ if (!(EXPR)) \
|
|||||||
#endif /* (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTT) */
|
#endif /* (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTT) */
|
||||||
#endif /* (defined(CMB_USING_BARE_METAL_PLATFORM) && defined(CMB_USING_OS_PLATFORM)) */
|
#endif /* (defined(CMB_USING_BARE_METAL_PLATFORM) && defined(CMB_USING_OS_PLATFORM)) */
|
||||||
|
|
||||||
/* include or export for supported, __get_SP function */
|
/* include or export for supported cmb_get_msp, cmb_get_psp and cmb_get_sp function */
|
||||||
#if defined(__CC_ARM)
|
#if defined(__CC_ARM)
|
||||||
static __inline __asm uint32_t __get_SP(void) {
|
static __inline __asm uint32_t cmb_get_msp(void) {
|
||||||
|
mrs r0, msp
|
||||||
|
bx lr
|
||||||
|
}
|
||||||
|
static __inline __asm uint32_t cmb_get_psp(void) {
|
||||||
|
mrs r0, psp
|
||||||
|
bx lr
|
||||||
|
}
|
||||||
|
static __inline __asm uint32_t cmb_get_sp(void) {
|
||||||
mov r0, sp
|
mov r0, sp
|
||||||
bx lr
|
bx lr
|
||||||
}
|
}
|
||||||
#elif defined(__ICCARM__)
|
#elif defined(__ICCARM__)
|
||||||
#include <intrinsics.h>
|
static uint32_t cmb_get_msp(void)
|
||||||
|
{
|
||||||
|
register uint32_t result;
|
||||||
|
__asm("MRS %0, msp" : "=r" (result));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
static uint32_t cmb_get_psp(void)
|
||||||
|
{
|
||||||
|
register uint32_t result;
|
||||||
|
__asm("MRS %0, psp" : "=r" (result));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
static uint32_t cmb_get_sp(void)
|
||||||
|
{
|
||||||
|
register uint32_t result;
|
||||||
|
__asm("MOV %0, sp" : "=r" (result));
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
__attribute__( ( always_inline ) ) static inline uint32_t __get_SP(void) {
|
__attribute__( ( always_inline ) ) static inline uint32_t cmb_get_msp(void) {
|
||||||
|
register uint32_t result;
|
||||||
|
__asm volatile ("MRS %0, msp\n" : "=r" (result) );
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
__attribute__( ( always_inline ) ) static inline uint32_t cmb_get_psp(void) {
|
||||||
|
register uint32_t result;
|
||||||
|
__asm volatile ("MRS %0, psp\n" : "=r" (result) );
|
||||||
|
return(result);
|
||||||
|
}
|
||||||
|
__attribute__( ( always_inline ) ) static inline uint32_t cmb_get_sp(void) {
|
||||||
register uint32_t result;
|
register uint32_t result;
|
||||||
__asm volatile ("MOV %0, sp\n" : "=r" (result) );
|
__asm volatile ("MOV %0, sp\n" : "=r" (result) );
|
||||||
return(result);
|
return(result);
|
||||||
|
@ -155,7 +155,7 @@ void assert_failed(u8* file, u32 line)
|
|||||||
/* User can add his own implementation to report the file name and line number,
|
/* User can add his own implementation to report the file name and line number,
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
cm_backtrace_assert(__get_SP());
|
cm_backtrace_assert(cmb_get_sp());
|
||||||
printf("assert failed at %s:%d \n", file, line);
|
printf("assert failed at %s:%d \n", file, line);
|
||||||
while (1) {
|
while (1) {
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ void assert_failed(u8* file, u32 line)
|
|||||||
/* User can add his own implementation to report the file name and line number,
|
/* User can add his own implementation to report the file name and line number,
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
cm_backtrace_assert(__get_SP());
|
cm_backtrace_assert(cmb_get_sp());
|
||||||
printf("assert failed at %s:%d \n", file, line);
|
printf("assert failed at %s:%d \n", file, line);
|
||||||
while (1) {
|
while (1) {
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user