diff options
-rw-r--r-- | src/target/arm720t.h | 7 | ||||
-rw-r--r-- | src/target/arm7_9_common.h | 7 | ||||
-rw-r--r-- | src/target/arm920t.h | 7 | ||||
-rw-r--r-- | src/target/arm926ejs.h | 8 | ||||
-rw-r--r-- | src/target/arm966e.h | 7 | ||||
-rw-r--r-- | src/target/armv4_5.h | 6 | ||||
-rw-r--r-- | src/target/armv7a.h | 7 | ||||
-rw-r--r-- | src/target/armv7m.h | 6 | ||||
-rw-r--r-- | src/target/cortex_a8.h | 7 | ||||
-rw-r--r-- | src/target/cortex_m3.h | 7 | ||||
-rw-r--r-- | src/target/target.h | 15 | ||||
-rw-r--r-- | src/target/xscale.h | 7 |
12 files changed, 91 insertions, 0 deletions
diff --git a/src/target/arm720t.h b/src/target/arm720t.h index c769626..0689e44 100644 --- a/src/target/arm720t.h +++ b/src/target/arm720t.h @@ -35,4 +35,11 @@ typedef struct arm720t_common_s uint32_t far_reg; } arm720t_common_t; +static inline struct arm720t_common_s * +target_to_arm720(struct target_s *target) +{ + return container_of(target->arch_info, struct arm720t_common_s, + arm7tdmi_common.arm7_9_common.armv4_5_common); +} + #endif /* ARM720T_H */ diff --git a/src/target/arm7_9_common.h b/src/target/arm7_9_common.h index 80f8fc7..d86ac24 100644 --- a/src/target/arm7_9_common.h +++ b/src/target/arm7_9_common.h @@ -112,6 +112,13 @@ typedef struct arm7_9_common_s } arm7_9_common_t; +static inline struct arm7_9_common_s * +target_to_arm7_9(struct target_s *target) +{ + return container_of(target->arch_info, struct arm7_9_common_s, + armv4_5_common); +} + int arm7_9_register_commands(struct command_context_s *cmd_ctx); int arm7_9_poll(target_t *target); diff --git a/src/target/arm920t.h b/src/target/arm920t.h index ed851a9..eb66eaa 100644 --- a/src/target/arm920t.h +++ b/src/target/arm920t.h @@ -38,6 +38,13 @@ typedef struct arm920t_common_s int preserve_cache; } arm920t_common_t; +static inline struct arm920t_common_s * +target_to_arm920(struct target_s *target) +{ + return container_of(target->arch_info, struct arm920t_common_s, + arm9tdmi_common.arm7_9_common.armv4_5_common); +} + typedef struct arm920t_cache_line_s { uint32_t cam; diff --git a/src/target/arm926ejs.h b/src/target/arm926ejs.h index 7adbf1f..ff811e3 100644 --- a/src/target/arm926ejs.h +++ b/src/target/arm926ejs.h @@ -38,6 +38,14 @@ typedef struct arm926ejs_common_s uint32_t d_far; } arm926ejs_common_t; +static inline struct arm926ejs_common_s * +target_to_arm926(struct target_s *target) +{ + return container_of(target->arch_info, struct arm926ejs_common_s, + arm9tdmi_common.arm7_9_common.armv4_5_common); +} + + extern int arm926ejs_init_arch_info(target_t *target, arm926ejs_common_t *arm926ejs, jtag_tap_t *tap); extern int arm926ejs_register_commands(struct command_context_s *cmd_ctx); extern int arm926ejs_arch_state(struct target_s *target); diff --git a/src/target/arm966e.h b/src/target/arm966e.h index 21dee1e..710f207 100644 --- a/src/target/arm966e.h +++ b/src/target/arm966e.h @@ -34,6 +34,13 @@ typedef struct arm966e_common_s uint32_t cp15_control_reg; } arm966e_common_t; +static inline struct arm966e_common_s * +target_to_arm966(struct target_s *target) +{ + return container_of(target->arch_info, struct arm966e_common_s, + arm9tdmi_common.arm7_9_common.armv4_5_common); +} + extern int arm966e_init_arch_info(target_t *target, arm966e_common_t *arm966e, jtag_tap_t *tap); extern int arm966e_register_commands(struct command_context_s *cmd_ctx); extern int arm966e_write_cp15(target_t *target, int reg_addr, uint32_t value); diff --git a/src/target/armv4_5.h b/src/target/armv4_5.h index 80f28db..fb7926b 100644 --- a/src/target/armv4_5.h +++ b/src/target/armv4_5.h @@ -86,6 +86,12 @@ typedef struct armv4_5_common_s void *arch_info; } armv4_5_common_t; +static inline struct armv4_5_common_s * +target_to_armv4_5(struct target_s *target) +{ + return target->arch_info; +} + typedef struct armv4_5_algorithm_s { int common_magic; diff --git a/src/target/armv7a.h b/src/target/armv7a.h index c5e3257..3fc97f1 100644 --- a/src/target/armv7a.h +++ b/src/target/armv7a.h @@ -127,6 +127,13 @@ typedef struct armv7a_common_s } armv7a_common_t; +static inline struct armv7a_common_s * +target_to_armv7a(struct target_s *target) +{ + return container_of(target->arch_info, struct armv7a_common_s, + armv4_5_common); +} + typedef struct armv7a_algorithm_s { int common_magic; diff --git a/src/target/armv7m.h b/src/target/armv7m.h index d9c62a8..487d6fd 100644 --- a/src/target/armv7m.h +++ b/src/target/armv7m.h @@ -116,6 +116,12 @@ typedef struct armv7m_common_s void *arch_info; } armv7m_common_t; +static inline struct armv7m_common_s * +target_to_armv7m(struct target_s *target) +{ + return target->arch_info; +} + typedef struct armv7m_algorithm_s { int common_magic; diff --git a/src/target/cortex_a8.h b/src/target/cortex_a8.h index 3695696..b98a7de 100644 --- a/src/target/cortex_a8.h +++ b/src/target/cortex_a8.h @@ -137,6 +137,13 @@ typedef struct cortex_a8_common_s void *arch_info; } cortex_a8_common_t; +static inline struct cortex_a8_common_s * +target_to_cortex_a8(struct target_s *target) +{ + return container_of(target->arch_info, struct cortex_a8_common_s, + armv7a_common.armv4_5_common); +} + extern int cortex_a8_init_arch_info(target_t *target, cortex_a8_common_t *cortex_a8, jtag_tap_t *tap); int cortex_a8_read_memory(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); int cortex_a8_write_memory(struct target_s *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer); diff --git a/src/target/cortex_m3.h b/src/target/cortex_m3.h index 1dd724c..629db8e 100644 --- a/src/target/cortex_m3.h +++ b/src/target/cortex_m3.h @@ -164,4 +164,11 @@ typedef struct cortex_m3_common_s void *arch_info; } cortex_m3_common_t; +static inline struct cortex_m3_common_s * +target_to_cm3(struct target_s *target) +{ + return container_of(target->arch_info, + struct cortex_m3_common_s, armv7m); +} + #endif /* CORTEX_M3_H */ diff --git a/src/target/target.h b/src/target/target.h index c971f18..1bbf40f 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -26,6 +26,8 @@ #ifndef TARGET_H #define TARGET_H +#include <stddef.h> + #include "breakpoints.h" #include "algorithm.h" #include "command.h" @@ -34,6 +36,19 @@ struct reg_s; struct trace_s; struct command_context_s; + +/** + * Cast a member of a structure out to the containing structure. + * @param ptr The pointer to the member. + * @param type The type of the container struct this is embedded in. + * @param member The name of the member within the struct. + * + * This is a mechanism which is used throughout the Linux kernel. + */ +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + /* * TARGET_UNKNOWN = 0: we don't know anything about the target yet * TARGET_RUNNING = 1: the target is executing user code diff --git a/src/target/xscale.h b/src/target/xscale.h index 4b34cf8..a1f3d46 100644 --- a/src/target/xscale.h +++ b/src/target/xscale.h @@ -134,6 +134,13 @@ typedef struct xscale_common_s int fast_memory_access; } xscale_common_t; +static inline struct xscale_common_s * +target_to_xscale(struct target_s *target) +{ + return container_of(target->arch_info, struct xscale_common_s, + armv4_5_common); +} + typedef struct xscale_reg_s { int dbg_handler_number; |