diff --git a/cpu/atmega_common/include/cpu.h b/cpu/atmega_common/include/cpu.h index fb7ab005de..5b170d0c82 100644 --- a/cpu/atmega_common/include/cpu.h +++ b/cpu/atmega_common/include/cpu.h @@ -25,9 +25,11 @@ #ifndef __ATMEGA_COMMON_H #define __ATMEGA_COMMON_H -#include "cpu_conf.h" +#include #include +#include "cpu_conf.h" + /** * For downwards compatibility with old RIOT code. * TODO: remove once core was adjusted @@ -46,6 +48,16 @@ extern "C" { */ void cpu_init(void); +/** + * @brief Print the last instruction's address + * + * @todo: Not supported + */ +static inline void cpu_print_last_instruction(void) +{ + printf("n/a"); +} + #ifdef __cplusplus } #endif diff --git a/cpu/cortexm_common/include/cpu.h b/cpu/cortexm_common/include/cpu.h index dbe1157397..5578398d0f 100644 --- a/cpu/cortexm_common/include/cpu.h +++ b/cpu/cortexm_common/include/cpu.h @@ -30,6 +30,8 @@ #ifndef CPU_H_ #define CPU_H_ +#include + #include "cpu_conf.h" #include "irq.h" @@ -100,6 +102,16 @@ void cpu_init(void); */ void cortexm_init(void); +/** + * @brief Prints the current content of the link register (lr) + */ +static inline void cpu_print_last_instruction(void) +{ + register uint32_t *lr_ptr; + __asm__ __volatile__("mov %0, lr" : "=r"(lr_ptr)); + printf("%p", lr_ptr); +} + #ifdef __cplusplus } #endif diff --git a/cpu/lpc2387/include/cpu.h b/cpu/lpc2387/include/cpu.h index 6fbc336f9b..d361e5fbe2 100644 --- a/cpu/lpc2387/include/cpu.h +++ b/cpu/lpc2387/include/cpu.h @@ -16,7 +16,9 @@ * @{ */ +#include #include + #include "lpc2387.h" #include "arm_cpu.h" @@ -41,6 +43,16 @@ bool install_irq(int IntNumber, void (*HandlerAddr)(void), int Priority); void gpio_init_ports(void); #endif +/** + * @brief Prints the current content of the link register (lr) + */ +static inline void cpu_print_last_instruction(void) +{ + register uint32_t *lr_ptr; + __asm__ __volatile__("mov %0, lr" : "=r"(lr_ptr)); + printf("%p", lr_ptr); +} + #ifdef __cplusplus } #endif diff --git a/cpu/msp430-common/include/cpu.h b/cpu/msp430-common/include/cpu.h index f92c2c80b9..5a78e10d81 100644 --- a/cpu/msp430-common/include/cpu.h +++ b/cpu/msp430-common/include/cpu.h @@ -167,6 +167,16 @@ inline void __restore_context(unsigned int irqen) */ void msp430_cpu_init(void); +/** + * @brief Print the last instruction's address + * + * @todo: Not supported + */ +static inline void cpu_print_last_instruction(void) +{ + printf("n/a"); +} + #ifdef __cplusplus } #endif diff --git a/cpu/native/include/cpu.h b/cpu/native/include/cpu.h index 734a09e8d2..af252f3720 100644 --- a/cpu/native/include/cpu.h +++ b/cpu/native/include/cpu.h @@ -20,6 +20,8 @@ #ifndef _CPU_H #define _CPU_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -28,6 +30,16 @@ extern "C" { void dINT(void); void eINT(void); +/** + * @brief Prints the last instruction's address + */ +static inline void cpu_print_last_instruction(void) +{ + void *p; + __asm__("1: mov 1b, %0" : "=r" (p)); + printf("%p", p); +} + #ifdef __cplusplus } #endif diff --git a/cpu/x86/include/cpu.h b/cpu/x86/include/cpu.h index 4099e16e2e..633ff8448e 100644 --- a/cpu/x86/include/cpu.h +++ b/cpu/x86/include/cpu.h @@ -133,6 +133,16 @@ void x86_init_board(void); */ bool x86_get_memory_region(uint64_t *start, uint64_t *len, unsigned long *cnt); +/** + * @brief Prints the last instruction's address + * + * @todo: Not supported + */ +static inline void cpu_print_last_instruction(void) +{ + printf("n/a"); +} + #ifdef __cplusplus } #endif