Framework updates to provide ETM access on ARM cores other
than the current set of just ARM7 and ARM9 based cores:

 - Rename "struct armv4_5_common_s" as "struct arm".  It
   needs a bit more work to be properly generic, but it's
   the best start we have at that today.

 - In "struct arm" provide an optional ETM pointer.

 - Make ETM use "struct arm" that way not "struct arm7_9".
   Ditto ETB, which is the main way OpenOCD can support
   trace functionality (vs. giving fancy debug triggers).

The intent being:  all ARMs should eventually derive from
this newish "struct arm", so they can reuse the current ETM 
logic.  Currently the ARM cores that *don't* so derive are
only ARMv7-M (and thus Cortex-M3) and ARM11.

ARM11 should be able to support standard ETM (and ETB) access
as soon as it derives from "struct arm" ... its scanchain 6 is
used access the ETM, just like ARM7 and ARM9.

The Cortex parts (both M3 and A8) will need modified access
methods, so they can go through the DAP.  Our main A8 target
(OMAP3) needs that for both ETM and ETB.  The M3 ETM isn't
useful without trace support though, so that support won't
be worth adding for a while.
---
NOTE: the rename to "struct arm" could be split out into
a patch of its own, but that wouldn't shrink this much
since most of the work involved just uplevels the support
one level in the ARM hierarchy.  A larger patch would
stop using the old "armv4_5" type, possibly relocating
it to the arm_jtag.h header.

 src/target/arm7_9_common.h |    6 --
 src/target/arm7tdmi.c      |    9 +--
 src/target/arm9tdmi.c      |    9 +--
 src/target/armv4_5.h       |   41 +++++++++++++--
 src/target/etb.c           |   14 ++---
 src/target/etm.c           |  114 +++++++++++++++++++------------------------
 src/target/etm.h           |    3 -
 src/target/etm_dummy.c     |   14 ++---
 8 files changed, 116 insertions(+), 94 deletions(-)

--- a/src/target/arm7_9_common.h
+++ b/src/target/arm7_9_common.h
@@ -30,7 +30,7 @@
 #define ARM7_9_COMMON_H
 
 #include "breakpoints.h"
-#include "etm.h"
+#include "armv4_5.h"
 
 #define        ARM7_9_COMMON_MAGIC 0x0a790a79 /**< */
 
@@ -39,7 +39,7 @@
  */
 typedef struct arm7_9_common_s
 {
-       armv4_5_common_t armv4_5_common;
+       struct arm armv4_5_common;
        uint32_t common_magic;
 
        arm_jtag_t jtag_info; /**< JTAG information for target */
@@ -69,8 +69,6 @@ typedef struct arm7_9_common_s
        bool fast_memory_access;
        bool dcc_downloads;
 
-       etm_context_t *etm_ctx;
-
        struct working_area_s *dcc_working_area;
 
        int (*examine_debug_reason)(target_t *target); /**< Function for 
determining why debug state was entered */
--- a/src/target/arm7tdmi.c
+++ b/src/target/arm7tdmi.c
@@ -663,11 +663,12 @@ int arm7tdmi_examine(struct target_s *ta
                (*cache_p) = t;
                arm7_9->eice_cache = (*cache_p);
 
-               if (arm7_9->etm_ctx)
+               if (arm7_9->armv4_5_common.etm)
                {
                        arm_jtag_t *jtag_info = &arm7_9->jtag_info;
-                       (*cache_p)->next = etm_build_reg_cache(target, 
jtag_info, arm7_9->etm_ctx);
-                       arm7_9->etm_ctx->reg_cache = (*cache_p)->next;
+                       (*cache_p)->next = etm_build_reg_cache(target,
+                                       jtag_info, arm7_9->armv4_5_common.etm);
+                       arm7_9->armv4_5_common.etm->reg_cache = 
(*cache_p)->next;
                }
                target_set_examined(target);
        }
@@ -675,7 +676,7 @@ int arm7tdmi_examine(struct target_s *ta
                return retval;
        if ((retval = arm7_9_setup(target)) != ERROR_OK)
                return retval;
-       if (arm7_9->etm_ctx)
+       if (arm7_9->armv4_5_common.etm)
        {
                if ((retval = etm_setup(target)) != ERROR_OK)
                        return retval;
--- a/src/target/arm9tdmi.c
+++ b/src/target/arm9tdmi.c
@@ -758,11 +758,12 @@ int arm9tdmi_examine(struct target_s *ta
                (*cache_p) = t;
                arm7_9->eice_cache = (*cache_p);
 
-               if (arm7_9->etm_ctx)
+               if (arm7_9->armv4_5_common.etm)
                {
                        arm_jtag_t *jtag_info = &arm7_9->jtag_info;
-                       (*cache_p)->next = etm_build_reg_cache(target, 
jtag_info, arm7_9->etm_ctx);
-                       arm7_9->etm_ctx->reg_cache = (*cache_p)->next;
+                       (*cache_p)->next = etm_build_reg_cache(target,
+                                       jtag_info, arm7_9->armv4_5_common.etm);
+                       arm7_9->armv4_5_common.etm->reg_cache = 
(*cache_p)->next;
                }
                target_set_examined(target);
        }
@@ -770,7 +771,7 @@ int arm9tdmi_examine(struct target_s *ta
                return retval;
        if ((retval = arm7_9_setup(target)) != ERROR_OK)
                return retval;
-       if (arm7_9->etm_ctx)
+       if (arm7_9->armv4_5_common.etm)
        {
                if ((retval = etm_setup(target)) != ERROR_OK)
                        return retval;
--- a/src/target/armv4_5.h
+++ b/src/target/armv4_5.h
@@ -29,6 +29,7 @@
 #include "register.h"
 #include "target.h"
 #include "log.h"
+#include "etm.h"
 
 typedef enum armv4_5_mode
 {
@@ -73,25 +74,55 @@ enum
 
 #define ARMV4_5_COMMON_MAGIC 0x0A450A45
 
-typedef struct armv4_5_common_s
+/*
+ * NOTE:  this is going to be morphed into "struct arm", a generic toplevel
+ * holder for ARM cores.  Note that cores like the Cortex-M series do not
+ * support the same core states and do not have many shadowed registers.
+ */
+#define armv4_5_common_s arm
+
+/**
+ * Represents a generic ARM core, with standard application registers.
+ *
+ * There are sixteen application registers (including PC, SP, LR) and a PSR.
+ * Cortex-M series cores do not support as many core states or shadowed
+ * registers as traditional ARM cores, and only support Thumb2 instructions.
+ */
+typedef struct arm
 {
        int common_magic;
        reg_cache_t *core_cache;
+
        int /* armv4_5_mode */ core_mode;
        enum armv4_5_state core_state;
+
+       /** Flag reporting unavailability of the BKPT instruction. */
        bool is_armv4;
+
+       /** Handle for the Embedded Trace Module, if one is present. */
+       struct etm *etm;
+
        int (*full_context)(struct target_s *target);
-       int (*read_core_reg)(struct target_s *target, int num, enum 
armv4_5_mode mode);
-       int (*write_core_reg)(struct target_s *target, int num, enum 
armv4_5_mode mode, uint32_t value);
+       int (*read_core_reg)(struct target_s *target,
+                       int num, enum armv4_5_mode mode);
+       int (*write_core_reg)(struct target_s *target,
+                       int num, enum armv4_5_mode mode, uint32_t value);
        void *arch_info;
 } armv4_5_common_t;
 
-static inline struct armv4_5_common_s *
-target_to_armv4_5(struct target_s *target)
+#define target_to_armv4_5 target_to_arm
+
+/** Convert target handle to generic ARM target state handle. */
+static inline struct arm *target_to_arm(struct target_s *target)
 {
        return target->arch_info;
 }
 
+static inline bool is_arm(struct arm *arm)
+{
+       return arm && arm->common_magic == ARMV4_5_COMMON_MAGIC;
+}
+
 typedef struct armv4_5_algorithm_s
 {
        int common_magic;
--- a/src/target/etb.c
+++ b/src/target/etb.c
@@ -21,7 +21,7 @@
 #include "config.h"
 #endif
 
-#include "arm7_9_common.h"
+#include "armv4_5.h"
 #include "etb.h"
 
 
@@ -353,8 +353,7 @@ static int handle_etb_config_command(str
 {
        target_t *target;
        jtag_tap_t *tap;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
 
        if (argc != 2)
        {
@@ -369,9 +368,10 @@ static int handle_etb_config_command(str
                return ERROR_FAIL;
        }
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
-               command_print(cmd_ctx, "ETB: current target isn't an ARM7/ARM9 
target");
+               command_print(cmd_ctx, "ETB: '%s' isn't an ARM", args[0]);
                return ERROR_FAIL;
        }
 
@@ -382,11 +382,11 @@ static int handle_etb_config_command(str
                return ERROR_FAIL;
        }
 
-       if (arm7_9->etm_ctx)
+       if (arm->etm)
        {
                etb_t *etb = malloc(sizeof(etb_t));
 
-               arm7_9->etm_ctx->capture_driver_priv = etb;
+               arm->etm->capture_driver_priv = etb;
 
                etb->tap  = tap;
                etb->cur_scan_chain = 0xffffffff;
--- a/src/target/etm.c
+++ b/src/target/etm.c
@@ -21,10 +21,9 @@
 #include "config.h"
 #endif
 
-#include "etm.h"
+#include "armv4_5.h"
 #include "etb.h"
 #include "image.h"
-#include "arm7_9_common.h"
 #include "arm_disassembler.h"
 
 
@@ -410,8 +409,8 @@ int etm_setup(target_t *target)
 {
        int retval;
        uint32_t etm_ctrl_value;
-       struct arm7_9_common_s *arm7_9 = target_to_arm7_9(target);
-       etm_context_t *etm_ctx = arm7_9->etm_ctx;
+       struct arm *arm = target_to_arm(target);
+       etm_context_t *etm_ctx = arm->etm;
        reg_t *etm_ctrl_reg;
 
        etm_ctrl_reg = etm_reg_lookup(etm_ctx, ETM_CTRL);
@@ -1229,17 +1228,15 @@ static int handle_etm_tracemode_command(
                char *cmd, char **args, int argc)
 {
        target_t *target = get_current_target(cmd_ctx);
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm = target_to_arm(target);
        struct etm *etm;
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
-       {
+       if (!is_arm(arm)) {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       etm = arm7_9->etm_ctx;
+       etm = arm->etm;
        if (!etm) {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
                return ERROR_FAIL;
@@ -1354,8 +1351,7 @@ static int handle_etm_config_command(str
                char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_portmode_t portmode = 0x0;
        struct etm *etm_ctx;
        int i;
@@ -1370,8 +1366,8 @@ static int handle_etm_config_command(str
                return ERROR_FAIL;
        }
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
-       {
+       arm = target_to_arm(target);
+       if (!is_arm(arm)) {
                command_print(cmd_ctx, "target '%s' is '%s'; not an ARM",
                                target->cmd_name, target_get_name(target));
                return ERROR_FAIL;
@@ -1476,7 +1472,7 @@ static int handle_etm_config_command(str
        etm_ctx->ptr_ok = 0x0;
        etm_ctx->last_instruction = 0;
 
-       arm7_9->etm_ctx = etm_ctx;
+       arm->etm = etm_ctx;
 
        return etm_register_user_commands(cmd_ctx);
 }
@@ -1485,22 +1481,20 @@ static int handle_etm_info_command(struc
                char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm;
        reg_t *etm_sys_config_reg;
-
        int max_port_size;
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       etm = arm7_9->etm_ctx;
+       etm = arm->etm;
        if (!etm)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
@@ -1579,25 +1573,24 @@ static int handle_etm_status_command(str
                char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm;
        trace_status_t trace_status;
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       if (!arm7_9->etm_ctx)
+       etm = arm->etm;
+       if (!etm)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
                return ERROR_FAIL;
        }
-       etm = arm7_9->etm_ctx;
 
        /* ETM status */
        if (etm->bcd_vers >= 0x11) {
@@ -1657,8 +1650,7 @@ static int handle_etm_image_command(stru
                char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm_ctx;
 
        if (argc < 1)
@@ -1668,14 +1660,15 @@ static int handle_etm_image_command(stru
        }
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       if (!(etm_ctx = arm7_9->etm_ctx))
+       etm_ctx = arm->etm;
+       if (!etm_ctx)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
                return ERROR_FAIL;
@@ -1718,8 +1711,7 @@ static int handle_etm_dump_command(struc
 {
        fileio_t file;
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm_ctx;
        uint32_t i;
 
@@ -1730,14 +1722,15 @@ static int handle_etm_dump_command(struc
        }
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       if (!(etm_ctx = arm7_9->etm_ctx))
+       etm_ctx = arm->etm;
+       if (!etm_ctx)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
                return ERROR_FAIL;
@@ -1787,8 +1780,7 @@ static int handle_etm_load_command(struc
 {
        fileio_t file;
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm_ctx;
        uint32_t i;
 
@@ -1799,14 +1791,15 @@ static int handle_etm_load_command(struc
        }
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       if (!(etm_ctx = arm7_9->etm_ctx))
+       etm_ctx = arm->etm;
+       if (!etm_ctx)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
                return ERROR_FAIL;
@@ -1871,19 +1864,19 @@ static int handle_etm_trigger_percent_co
                char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm_ctx;
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       if (!(etm_ctx = arm7_9->etm_ctx))
+       etm_ctx = arm->etm;
+       if (!etm_ctx)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
                return ERROR_FAIL;
@@ -1913,20 +1906,19 @@ static int handle_etm_start_command(stru
                char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm_ctx;
        reg_t *etm_ctrl_reg;
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       etm_ctx = arm7_9->etm_ctx;
+       etm_ctx = arm->etm;
        if (!etm_ctx)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
@@ -1963,20 +1955,20 @@ static int handle_etm_stop_command(struc
                char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm_ctx;
        reg_t *etm_ctrl_reg;
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       if (!(etm_ctx = arm7_9->etm_ctx))
+       etm_ctx = arm->etm;
+       if (!etm_ctx)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
                return ERROR_FAIL;
@@ -2003,20 +1995,20 @@ static int handle_etm_analyze_command(st
                char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
        etm_context_t *etm_ctx;
        int retval;
 
        target = get_current_target(cmd_ctx);
-
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
                command_print(cmd_ctx, "ETM: current target isn't an ARM");
                return ERROR_FAIL;
        }
 
-       if (!(etm_ctx = arm7_9->etm_ctx))
+       etm_ctx = arm->etm;
+       if (!etm_ctx)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM 
configured");
                return ERROR_FAIL;
--- a/src/target/etm.h
+++ b/src/target/etm.h
@@ -25,7 +25,6 @@
 
 #include "trace.h"
 #include "arm_jtag.h"
-#include "armv4_5.h"
 
 struct image_s;
 
@@ -158,7 +157,7 @@ typedef struct etm
        uint32_t trace_depth;           /* number of cycles to be analyzed, 0 
if no data available */
        etm_portmode_t portmode;        /* normal, multiplexed or demultiplexed 
*/
        etmv1_tracemode_t tracemode;    /* type of info trace contains */
-       armv4_5_state_t core_state;     /* current core state */
+       int /*armv4_5_state_t*/ core_state;     /* current core state */
        struct image_s *image;          /* source for target opcodes */
        uint32_t pipe_index;            /* current trace cycle */
        uint32_t data_index;            /* cycle holding next data packet */
--- a/src/target/etm_dummy.c
+++ b/src/target/etm_dummy.c
@@ -21,15 +21,14 @@
 #include "config.h"
 #endif
 
+#include "armv4_5.h"
 #include "etm_dummy.h"
-#include "arm7_9_common.h"
 
 
 static int handle_etm_dummy_config_command(struct command_context_s *cmd_ctx, 
char *cmd, char **args, int argc)
 {
        target_t *target;
-       armv4_5_common_t *armv4_5;
-       arm7_9_common_t *arm7_9;
+       struct arm *arm;
 
        target = get_target(args[0]);
 
@@ -39,15 +38,16 @@ static int handle_etm_dummy_config_comma
                return ERROR_FAIL;
        }
 
-       if (arm7_9_get_arch_pointers(target, &armv4_5, &arm7_9) != ERROR_OK)
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
        {
-               command_print(cmd_ctx, "current target isn't an ARM7/ARM9 
target");
+               command_print(cmd_ctx, "target '%s' isn't an ARM", args[0]);
                return ERROR_FAIL;
        }
 
-       if (arm7_9->etm_ctx)
+       if (arm->etm)
        {
-               arm7_9->etm_ctx->capture_driver_priv = NULL;
+               arm->etm->capture_driver_priv = NULL;
        }
        else
        {
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to