Skip to content

Commit

Permalink
cpu: inline function to print instruction register
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegHahm committed Sep 11, 2015
1 parent 888e146 commit d7161b6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cpu/atmega_common/include/cpu.h
Expand Up @@ -25,9 +25,11 @@
#ifndef __ATMEGA_COMMON_H
#define __ATMEGA_COMMON_H

#include "cpu_conf.h"
#include <stdio.h>
#include <avr/interrupt.h>

#include "cpu_conf.h"

/**
* For downwards compatibility with old RIOT code.
* TODO: remove once core was adjusted
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions cpu/cortexm_common/include/cpu.h
Expand Up @@ -30,6 +30,8 @@
#ifndef CPU_H_
#define CPU_H_

#include <stdio.h>

#include "cpu_conf.h"
#include "irq.h"

Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions cpu/lpc2387/include/cpu.h
Expand Up @@ -16,7 +16,9 @@
* @{
*/

#include <stdio.h>
#include <stdbool.h>

#include "lpc2387.h"
#include "arm_cpu.h"

Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cpu/msp430-common/include/cpu.h
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions cpu/native/include/cpu.h
Expand Up @@ -20,6 +20,8 @@
#ifndef _CPU_H
#define _CPU_H

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cpu/x86/include/cpu.h
Expand Up @@ -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
Expand Down

0 comments on commit d7161b6

Please sign in to comment.