Stop GDB when polling fails, srst assert or powerdropout is detected
[openocd.git] / src / target / etm.c
index cc80b68590e56dd6a0addfaaffd23807a50cbdd3..5a774f4d24c364beef75b9acbfcd94431afdbef1 100644 (file)
@@ -68,13 +68,18 @@ struct etm_reg_info {
 
 /*
  * Registers 0..0x7f are JTAG-addressable using scanchain 6.
+ * (Or on some processors, through coprocessor operations.)
  * Newer versions of ETM make some W/O registers R/W, and
  * provide definitions for some previously-unused bits.
  */
-static const struct etm_reg_info reg[] = {
+
+/* basic registers that are always there given the right ETM version */
+static const struct etm_reg_info etm_core[] = {
+       /* NOTE: we "know" ETM_CONFIG is listed first */
+       { ETM_CONFIG, 32, RO, 0x10, "ETM_CONFIG", },
+
        /* ETM Trace Registers */
        { ETM_CTRL, 32, RW, 0x10, "ETM_CTRL", },
-       { ETM_CONFIG, 32, RO, 0x10, "ETM_CONFIG", },
        { ETM_TRIG_EVENT, 17, WO, 0x10, "ETM_TRIG_EVENT", },
        { ETM_ASIC_CTRL,  8, WO, 0x10, "ETM_ASIC_CTRL", },
        { ETM_STATUS,  3, RO, 0x11, "ETM_STATUS", },
@@ -86,16 +91,25 @@ static const struct etm_reg_info reg[] = {
        { ETM_TRACE_EN_EVENT, 17, WO, 0x10, "ETM_TRACE_EN_EVENT", },
        { ETM_TRACE_EN_CTRL1, 26, WO, 0x10, "ETM_TRACE_EN_CTRL1", },
 
-       /* FIFOFULL configuration */
-       { ETM_FIFOFULL_REGION, 25, WO, 0x10, "ETM_FIFOFULL_REGION", },
-       { ETM_FIFOFULL_LEVEL,  8, WO, 0x10, "ETM_FIFOFULL_LEVEL", },
-
        /* ViewData configuration (data trace) */
        { ETM_VIEWDATA_EVENT, 17, WO, 0x10, "ETM_VIEWDATA_EVENT", },
        { ETM_VIEWDATA_CTRL1, 32, WO, 0x10, "ETM_VIEWDATA_CTRL1", },
        { ETM_VIEWDATA_CTRL2, 32, WO, 0x10, "ETM_VIEWDATA_CTRL2", },
        { ETM_VIEWDATA_CTRL3, 17, WO, 0x10, "ETM_VIEWDATA_CTRL3", },
 
+       /* REVISIT exclude VIEWDATA_CTRL2 when it's not there */
+
+       { 0x78, 12, WO, 0x20, "ETM_SYNC_FREQ", },
+       { 0x79, 32, RO, 0x20, "ETM_ID", },
+};
+
+static const struct etm_reg_info etm_fifofull[] = {
+       /* FIFOFULL configuration */
+       { ETM_FIFOFULL_REGION, 25, WO, 0x10, "ETM_FIFOFULL_REGION", },
+       { ETM_FIFOFULL_LEVEL,  8, WO, 0x10, "ETM_FIFOFULL_LEVEL", },
+};
+
+static const struct etm_reg_info etm_addr_comp[] = {
        /* Address comparator register pairs */
 #define ADDR_COMPARATOR(i) \
                { ETM_ADDR_COMPARATOR_VALUE + (i), 32, WO, 0x10, \
@@ -120,7 +134,9 @@ static const struct etm_reg_info reg[] = {
        ADDR_COMPARATOR(14),
        ADDR_COMPARATOR(15),
 #undef ADDR_COMPARATOR
+};
 
+static const struct etm_reg_info etm_data_comp[] = {
        /* Data Value Comparators (NOTE: odd addresses are reserved) */
 #define DATA_COMPARATOR(i) \
                { ETM_DATA_COMPARATOR_VALUE + 2*(i), 32, WO, 0x10, \
@@ -136,9 +152,10 @@ static const struct etm_reg_info reg[] = {
        DATA_COMPARATOR(6),
        DATA_COMPARATOR(7),
 #undef DATA_COMPARATOR
+};
 
-       /* Counters */
-#define COUNTER(i) \
+static const struct etm_reg_info etm_counters[] = {
+#define ETM_COUNTER(i) \
                { ETM_COUNTER_RELOAD_VALUE + (i), 16, WO, 0x10, \
                                "ETM_COUNTER_RELOAD_VALUE" #i, }, \
                { ETM_COUNTER_ENABLE + (i), 18, WO, 0x10, \
@@ -147,35 +164,39 @@ static const struct etm_reg_info reg[] = {
                                "ETM_COUNTER_RELOAD_EVENT" #i, }, \
                { ETM_COUNTER_VALUE + (i), 16, RO, 0x10, \
                                "ETM_COUNTER_VALUE" #i, }
-       COUNTER(0),
-       COUNTER(1),
-       COUNTER(2),
-       COUNTER(3),
-#undef COUNTER
-
-       /* Sequencers */
-#define SEQ(i) \
+       ETM_COUNTER(0),
+       ETM_COUNTER(1),
+       ETM_COUNTER(2),
+       ETM_COUNTER(3),
+#undef ETM_COUNTER
+};
+
+static const struct etm_reg_info etm_sequencer[] = {
+#define ETM_SEQ(i) \
                { ETM_SEQUENCER_EVENT + (i), 17, WO, 0x10, \
                                "ETM_SEQUENCER_EVENT" #i, }
-       SEQ(0),                         /* 1->2 */
-       SEQ(1),                         /* 2->1 */
-       SEQ(2),                         /* 2->3 */
-       SEQ(3),                         /* 3->1 */
-       SEQ(4),                         /* 3->2 */
-       SEQ(5),                         /* 1->3 */
-#undef SEQ
+       ETM_SEQ(0),                             /* 1->2 */
+       ETM_SEQ(1),                             /* 2->1 */
+       ETM_SEQ(2),                             /* 2->3 */
+       ETM_SEQ(3),                             /* 3->1 */
+       ETM_SEQ(4),                             /* 3->2 */
+       ETM_SEQ(5),                             /* 1->3 */
+#undef ETM_SEQ
        /* 0x66 reserved */
        { ETM_SEQUENCER_STATE,  2, RO, 0x10, "ETM_SEQUENCER_STATE", },
+};
 
-#define OUT(i) \
+static const struct etm_reg_info etm_outputs[] = {
+#define ETM_OUTPUT(i) \
                { ETM_EXTERNAL_OUTPUT + (i), 17, WO, 0x10, \
                                "ETM_EXTERNAL_OUTPUT" #i, }
 
-       OUT(0),
-       OUT(1),
-       OUT(2),
-       OUT(3),
-#undef OUT
+       ETM_OUTPUT(0),
+       ETM_OUTPUT(1),
+       ETM_OUTPUT(2),
+       ETM_OUTPUT(3),
+#undef ETM_OUTPUT
+};
 
 #if 0
        /* registers from 0x6c..0x7f were added after ETMv1.3 */
@@ -185,11 +206,7 @@ static const struct etm_reg_info reg[] = {
        { 0x6d, 32, RO, 0x20, "ETM_CONTEXTID_COMPARATOR_VALUE1", }
        { 0x6e, 32, RO, 0x20, "ETM_CONTEXTID_COMPARATOR_VALUE1", }
        { 0x6f, 32, RO, 0x20, "ETM_CONTEXTID_COMPARATOR_MASK", }
-
-       { 0x78, 12, WO, 0x20, "ETM_SYNC_FREQ", },
-       { 0x79, 32, RO, 0x20, "ETM_ID", },
 #endif
-};
 
 static int etm_reg_arch_type = -1;
 
@@ -224,43 +241,137 @@ static reg_t *etm_reg_lookup(etm_context_t *etm_ctx, unsigned id)
        return NULL;
 }
 
+static void etm_reg_add(unsigned bcd_vers, arm_jtag_t *jtag_info,
+               reg_cache_t *cache, etm_reg_t *ereg,
+               const struct etm_reg_info *r, unsigned nreg)
+{
+       reg_t *reg = cache->reg_list;
+
+       reg += cache->num_regs;
+       ereg += cache->num_regs;
+
+       /* add up to "nreg" registers from "r", if supported by this
+        * version of the ETM, to the specified cache.
+        */
+       for (; nreg--; r++) {
+
+               /* this ETM may be too old to have some registers */
+               if (r->bcd_vers > bcd_vers)
+                       continue;
+
+               reg->name = r->name;
+               reg->size = r->size;
+               reg->value = &ereg->value;
+               reg->arch_info = ereg;
+               reg->arch_type = etm_reg_arch_type;
+               reg++;
+               cache->num_regs++;
+
+               ereg->reg_info = r;
+               ereg->jtag_info = jtag_info;
+               ereg++;
+       }
+}
+
 reg_cache_t *etm_build_reg_cache(target_t *target,
                arm_jtag_t *jtag_info, etm_context_t *etm_ctx)
 {
        reg_cache_t *reg_cache = malloc(sizeof(reg_cache_t));
        reg_t *reg_list = NULL;
        etm_reg_t *arch_info = NULL;
-       int num_regs = ARRAY_SIZE(reg);
-       int i;
+       unsigned bcd_vers, config;
 
        /* register a register arch-type for etm registers only once */
        if (etm_reg_arch_type == -1)
-               etm_reg_arch_type = register_reg_arch_type(etm_get_reg, etm_set_reg_w_exec);
+               etm_reg_arch_type = register_reg_arch_type(etm_get_reg,
+                               etm_set_reg_w_exec);
 
        /* the actual registers are kept in two arrays */
-       reg_list = calloc(num_regs, sizeof(reg_t));
-       arch_info = calloc(num_regs, sizeof(etm_reg_t));
+       reg_list = calloc(128, sizeof(reg_t));
+       arch_info = calloc(128, sizeof(etm_reg_t));
 
        /* fill in values for the reg cache */
        reg_cache->name = "etm registers";
        reg_cache->next = NULL;
        reg_cache->reg_list = reg_list;
-       reg_cache->num_regs = num_regs;
-
-       /* set up registers */
-       for (i = 0; i < num_regs; i++)
-       {
-               const struct etm_reg_info *r = reg + i;
-
-               reg_list[i].name = r->name;
-               reg_list[i].size = r->size;
-               reg_list[i].value = &arch_info[i].value;
-               reg_list[i].arch_info = &arch_info[i];
-               reg_list[i].arch_type = etm_reg_arch_type;
-
-               arch_info[i].reg_info = r;
-               arch_info[i].jtag_info = jtag_info;
+       reg_cache->num_regs = 0;
+
+       /* add ETM_CONFIG, then parse its values to see
+        * which other registers exist in this ETM
+        */
+       etm_reg_add(0x10, jtag_info, reg_cache, arch_info,
+                       etm_core, 1);
+
+       etm_get_reg(reg_list);
+       etm_ctx->config = buf_get_u32((void *)&arch_info->value, 0, 32);
+       config = etm_ctx->config;
+
+       /* figure ETM version then add base registers */
+       if (config & (1 << 31)) {
+               bcd_vers = 0x20;
+               LOG_WARNING("ETMv2+ support is incomplete");
+
+               /* REVISIT read ID register, distinguish ETMv3.3 etc;
+                * don't presume trace start/stop support is present;
+                * and include any context ID comparator registers.
+                */
+       } else {
+               switch (config >> 28) {
+               case 7:
+               case 5:
+               case 3:
+                       bcd_vers = 0x13;
+                       break;
+               case 4:
+               case 2:
+                       bcd_vers = 0x12;
+                       break;
+               case 1:
+                       bcd_vers = 0x11;
+                       break;
+               case 0:
+                       bcd_vers = 0x10;
+                       break;
+               default:
+                       LOG_WARNING("Bad ETMv1 protocol %d", config >> 28);
+                       free(reg_cache);
+                       free(reg_list);
+                       free(arch_info);
+                       return ERROR_OK;
+               }
        }
+       etm_ctx->bcd_vers = bcd_vers;
+       LOG_INFO("ETM v%d.%d", bcd_vers >> 4, bcd_vers & 0xf);
+
+       etm_reg_add(bcd_vers, jtag_info, reg_cache, arch_info,
+                       etm_core + 1, ARRAY_SIZE(etm_core) - 1);
+
+       /* address and data comparators; counters; outputs */
+       etm_reg_add(bcd_vers, jtag_info, reg_cache, arch_info,
+                       etm_addr_comp, 4 * (0x0f & (config >> 0)));
+       etm_reg_add(bcd_vers, jtag_info, reg_cache, arch_info,
+                       etm_data_comp, 2 * (0x0f & (config >> 4)));
+       etm_reg_add(bcd_vers, jtag_info, reg_cache, arch_info,
+                       etm_counters, 4 * (0x07 & (config >> 13)));
+       etm_reg_add(bcd_vers, jtag_info, reg_cache, arch_info,
+                       etm_outputs, (0x07 & (config >> 20)));
+
+       /* FIFOFULL presence is optional
+        * REVISIT for ETMv1.2 and later, don't bother adding this
+        * unless ETM_SYS_CONFIG says it's also *supported* ...
+        */
+       if (config & (1 << 23))
+               etm_reg_add(bcd_vers, jtag_info, reg_cache, arch_info,
+                               etm_fifofull, ARRAY_SIZE(etm_fifofull));
+
+       /* sequencer is optional (for state-dependant triggering) */
+       if (config & (1 << 16))
+               etm_reg_add(bcd_vers, jtag_info, reg_cache, arch_info,
+                               etm_sequencer, ARRAY_SIZE(etm_sequencer));
+
+       /* REVISIT could realloc and likely save half the memory
+        * in the two chunks we allocated...
+        */
 
        /* the ETM might have an ETB connected */
        if (strcmp(etm_ctx->capture_driver->name, "etb") == 0)
@@ -271,6 +382,7 @@ reg_cache_t *etm_build_reg_cache(target_t *target,
                {
                        LOG_ERROR("etb selected as etm capture driver, but no ETB configured");
                        free(reg_cache);
+                       free(reg_list);
                        free(arch_info);
                        return ERROR_OK;
                }
@@ -1362,7 +1474,7 @@ static int handle_etm_info_command(struct command_context_s *cmd_ctx,
        target_t *target;
        armv4_5_common_t *armv4_5;
        arm7_9_common_t *arm7_9;
-       reg_t *etm_config_reg;
+       etm_context_t *etm;
        reg_t *etm_sys_config_reg;
 
        int max_port_size;
@@ -1375,31 +1487,45 @@ static int handle_etm_info_command(struct command_context_s *cmd_ctx,
                return ERROR_OK;
        }
 
-       if (!arm7_9->etm_ctx)
+       etm = arm7_9->etm_ctx;
+       if (!etm)
        {
                command_print(cmd_ctx, "current target doesn't have an ETM configured");
                return ERROR_OK;
        }
 
-       etm_config_reg = etm_reg_lookup(arm7_9->etm_ctx, ETM_CONFIG);
-       if (!etm_config_reg)
-               return ERROR_OK;
-       etm_sys_config_reg = etm_reg_lookup(arm7_9->etm_ctx, ETM_SYS_CONFIG);
-       if (!etm_sys_config_reg)
-               return ERROR_OK;
-
-       etm_get_reg(etm_config_reg);
-       command_print(cmd_ctx, "pairs of address comparators: %i", (int)buf_get_u32(etm_config_reg->value, 0, 4));
-       command_print(cmd_ctx, "pairs of data comparators: %i", (int)buf_get_u32(etm_config_reg->value, 4, 4));
-       command_print(cmd_ctx, "memory map decoders: %i", (int)buf_get_u32(etm_config_reg->value, 8, 5));
-       command_print(cmd_ctx, "number of counters: %i", (int)buf_get_u32(etm_config_reg->value, 13, 3));
+       command_print(cmd_ctx, "ETM v%d.%d",
+                       etm->bcd_vers >> 4, etm->bcd_vers & 0xf);
+       command_print(cmd_ctx, "pairs of address comparators: %i",
+                       (etm->config >> 0) & 0x0f);
+       command_print(cmd_ctx, "data comparators: %i",
+                       (etm->config >> 4) & 0x0f);
+       command_print(cmd_ctx, "memory map decoders: %i",
+                       (etm->config >> 8) & 0x1f);
+       command_print(cmd_ctx, "number of counters: %i",
+                       (etm->config >> 13) & 0x07);
        command_print(cmd_ctx, "sequencer %spresent",
-                       (buf_get_u32(etm_config_reg->value, 16, 1) == 1) ? "" : "not ");
-       command_print(cmd_ctx, "number of ext. inputs: %i", (int)buf_get_u32(etm_config_reg->value, 17, 3));
-       command_print(cmd_ctx, "number of ext. outputs: %i",(int) buf_get_u32(etm_config_reg->value, 20, 3));
+                       (etm->config & (1 << 16)) ? "" : "not ");
+       command_print(cmd_ctx, "number of ext. inputs: %i",
+                       (etm->config >> 17) & 0x07);
+       command_print(cmd_ctx, "number of ext. outputs: %i",
+                       (etm->config >> 20) & 0x07);
        command_print(cmd_ctx, "FIFO full %spresent",
-                       (buf_get_u32(etm_config_reg->value, 23, 1) == 1) ? "" : "not ");
-       command_print(cmd_ctx, "protocol version: %i", (int)buf_get_u32(etm_config_reg->value, 28, 3));
+                       (etm->config & (1 << 23)) ? "" : "not ");
+       if (etm->bcd_vers < 0x20)
+               command_print(cmd_ctx, "protocol version: %i",
+                               (etm->config >> 28) & 0x07);
+       else {
+               command_print(cmd_ctx, "trace start/stop %spresent",
+                               (etm->config & (1 << 26)) ? "" : "not ");
+               command_print(cmd_ctx, "number of context comparators: %i",
+                               (etm->config >> 24) & 0x03);
+       }
+
+       /* SYS_CONFIG isn't present before ETMv1.2 */
+       etm_sys_config_reg = etm_reg_lookup(etm, ETM_SYS_CONFIG);
+       if (!etm_sys_config_reg)
+               return ERROR_OK;
 
        etm_get_reg(etm_sys_config_reg);
 
@@ -1441,6 +1567,7 @@ static int handle_etm_status_command(struct command_context_s *cmd_ctx, char *cm
        target_t *target;
        armv4_5_common_t *armv4_5;
        arm7_9_common_t *arm7_9;
+       etm_context_t *etm;
        trace_status_t trace_status;
 
        target = get_current_target(cmd_ctx);
@@ -1456,28 +1583,56 @@ static int handle_etm_status_command(struct command_context_s *cmd_ctx, char *cm
                command_print(cmd_ctx, "current target doesn't have an ETM configured");
                return ERROR_OK;
        }
+       etm = arm7_9->etm_ctx;
 
-       trace_status = arm7_9->etm_ctx->capture_driver->status(arm7_9->etm_ctx);
+       /* ETM status */
+       if (etm->bcd_vers >= 0x11) {
+               reg_t *reg;
 
+               reg = etm_reg_lookup(etm, ETM_STATUS);
+               if (!reg)
+                       return ERROR_OK;
+               if (etm_get_reg(reg) == ERROR_OK) {
+                       unsigned s = buf_get_u32(reg->value, 0, reg->size);
+
+                       command_print(cmd_ctx, "etm: %s%s%s%s",
+                               /* bit(1) == progbit */
+                               (etm->bcd_vers >= 0x12)
+                                       ? ((s & (1 << 1))
+                                               ? "disabled" : "enabled")
+                                       : "?",
+                               ((s & (1 << 3)) && etm->bcd_vers >= 0x31)
+                                       ? " triggered" : "",
+                               ((s & (1 << 2)) && etm->bcd_vers >= 0x12)
+                                       ? " start/stop" : "",
+                               ((s & (1 << 0)) && etm->bcd_vers >= 0x11)
+                                       ? " untraced-overflow" : "");
+               } /* else ignore and try showing trace port status */
+       }
+
+       /* Trace Port Driver status */
+       trace_status = etm->capture_driver->status(etm);
        if (trace_status == TRACE_IDLE)
        {
-               command_print(cmd_ctx, "tracing is idle");
+               command_print(cmd_ctx, "%s: idle", etm->capture_driver->name);
        }
        else
        {
                static char *completed = " completed";
                static char *running = " is running";
-               static char *overflowed = ", trace overflowed";
-               static char *triggered = ", trace triggered";
+               static char *overflowed = ", overflowed";
+               static char *triggered = ", triggered";
 
-               command_print(cmd_ctx, "trace collection%s%s%s",
+               command_print(cmd_ctx, "%s: trace collection%s%s%s",
+                       etm->capture_driver->name,
                        (trace_status & TRACE_RUNNING) ? running : completed,
                        (trace_status & TRACE_OVERFLOWED) ? overflowed : "",
                        (trace_status & TRACE_TRIGGERED) ? triggered : "");
 
-               if (arm7_9->etm_ctx->trace_depth > 0)
+               if (etm->trace_depth > 0)
                {
-                       command_print(cmd_ctx, "%i frames of trace data read", (int)(arm7_9->etm_ctx->trace_depth));
+                       command_print(cmd_ctx, "%i frames of trace data read",
+                                       (int)(etm->trace_depth));
                }
        }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)