]> git.sur5r.net Git - openocd/blobdiff - src/target/etm.c
Cortex-M3: improved core exception handling
[openocd] / src / target / etm.c
index a506d1c4cb193e822c9bc2b9fa23878179c0ede2..3126efc2f211f597be37d5bc6b1572005f399238 100644 (file)
@@ -446,12 +446,15 @@ int etm_setup(struct target *target)
        etm_ctrl_value = (etm_ctrl_value
                        & ~ETM_PORT_WIDTH_MASK
                        & ~ETM_PORT_MODE_MASK
+                       & ~ETM_CTRL_DBGRQ
                        & ~ETM_PORT_CLOCK_MASK)
                | etm_ctx->control;
 
        buf_set_u32(etm_ctrl_reg->value, 0, 32, etm_ctrl_value);
        etm_store_reg(etm_ctrl_reg);
 
+       etm_ctx->control = etm_ctrl_value;
+
        if ((retval = jtag_execute_queue()) != ERROR_OK)
                return retval;
 
@@ -1256,12 +1259,16 @@ COMMAND_HANDLER(handle_etm_tracemode_command)
        case 0:
                break;
        case 4:
-               CALL_COMMAND_HANDLER(handle_etm_tracemode_command_update, &tracemode);
+               CALL_COMMAND_HANDLER(handle_etm_tracemode_command_update,
+                               &tracemode);
                break;
        default:
-               command_print(CMD_CTX, "usage: configure trace mode "
-                               "<none | data | address | all> "
-                               "<context id bits> <cycle accurate> <branch output>");
+               command_print(CMD_CTX, "usage: tracemode "
+                               "('none'|'data'|'address'|'all') "
+                               "context_id_bits "
+                               "('enable'|'disable') "
+                               "('enable'|'disable')"
+                               );
                return ERROR_FAIL;
        }
 
@@ -1338,8 +1345,6 @@ COMMAND_HANDLER(handle_etm_tracemode_command)
                if (!etm_ctrl_reg)
                        return ERROR_FAIL;
 
-               etm_get_reg(etm_ctrl_reg);
-
                etm->control &= ~TRACEMODE_MASK;
                etm->control |= tracemode & TRACEMODE_MASK;
 
@@ -2016,6 +2021,56 @@ COMMAND_HANDLER(handle_etm_stop_command)
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(handle_etm_trigger_debug_command)
+{
+       struct target *target;
+       struct arm *arm;
+       struct etm_context *etm;
+
+       target = get_current_target(CMD_CTX);
+       arm = target_to_arm(target);
+       if (!is_arm(arm))
+       {
+               command_print(CMD_CTX, "ETM: %s isn't an ARM",
+                               target_name(target));
+               return ERROR_FAIL;
+       }
+
+       etm = arm->etm;
+       if (!etm)
+       {
+               command_print(CMD_CTX, "ETM: no ETM configured for %s",
+                               target_name(target));
+               return ERROR_FAIL;
+       }
+
+       if (CMD_ARGC == 1) {
+               struct reg *etm_ctrl_reg;
+               bool dbgrq;
+
+               etm_ctrl_reg = etm_reg_lookup(etm, ETM_CTRL);
+               if (!etm_ctrl_reg)
+                       return ERROR_FAIL;
+
+               COMMAND_PARSE_ENABLE(CMD_ARGV[0], dbgrq);
+               if (dbgrq)
+                       etm->control |= ETM_CTRL_DBGRQ;
+               else
+                       etm->control &= ~ETM_CTRL_DBGRQ;
+
+               /* etm->control will be written to hardware
+                * the next time an "etm start" is issued.
+                */
+               buf_set_u32(etm_ctrl_reg->value, 0, 32, etm->control);
+       }
+
+       command_print(CMD_CTX, "ETM: %s debug halt",
+                       (etm->control & ETM_CTRL_DBGRQ)
+                               ? "triggers"
+                               : "does not trigger");
+       return ERROR_OK;
+}
+
 COMMAND_HANDLER(handle_etm_analyze_command)
 {
        struct target *target;
@@ -2061,11 +2116,16 @@ COMMAND_HANDLER(handle_etm_analyze_command)
 
 static const struct command_registration etm_config_command_handlers[] = {
        {
+               /* NOTE:  with ADIv5, ETMs are accessed by DAP operations,
+                * possibly over SWD, not JTAG scanchain 6 of 'target'.
+                *
+                * Also, these parameters don't match ETM v3+ modules...
+                */
                .name = "config",
-               .handler = &handle_etm_config_command,
+               .handler = handle_etm_config_command,
                .mode = COMMAND_CONFIG,
-               .usage = "<target> <port_width> <port_mode> "
-                       "<clocking> <capture_driver>",
+               .help = "Set up ETM output port.",
+               .usage = "target port_width port_mode clocking capture_driver",
        },
        COMMAND_REGISTRATION_DONE
 };
@@ -2081,57 +2141,69 @@ const struct command_registration etm_command_handlers[] = {
 
 static const struct command_registration etm_exec_command_handlers[] = {
        {
-               .name = "tracemode", handle_etm_tracemode_command,
+               .name = "tracemode",
+               .handler = handle_etm_tracemode_command,
                .mode = COMMAND_EXEC,
                .help = "configure/display trace mode",
-               .usage = "<none | data | address | all> "
-                       "<context_id_bits> <cycle_accurate> <branch_output>",
+               .usage = "('none'|'data'|'address'|'all') "
+                       "context_id_bits "
+                       "['enable'|'disable'] "
+                       "['enable'|'disable']",
        },
        {
                .name = "info",
-               .handler = &handle_etm_info_command,
+               .handler = handle_etm_info_command,
                .mode = COMMAND_EXEC,
                .help = "display info about the current target's ETM",
        },
        {
                .name = "status",
-               .handler = &handle_etm_status_command,
+               .handler = handle_etm_status_command,
                .mode = COMMAND_EXEC,
                .help = "display current target's ETM status",
        },
        {
                .name = "start",
-               .handler = &handle_etm_start_command,
+               .handler = handle_etm_start_command,
                .mode = COMMAND_EXEC,
                .help = "start ETM trace collection",
        },
        {
                .name = "stop",
-               .handler = &handle_etm_stop_command,
+               .handler = handle_etm_stop_command,
                .mode = COMMAND_EXEC,
                .help = "stop ETM trace collection",
        },
+       {
+               .name = "trigger_debug",
+               .handler = handle_etm_trigger_debug_command,
+               .mode = COMMAND_EXEC,
+               .help = "enable/disable debug entry on trigger",
+               .usage = "['enable'|'disable']",
+       },
        {
                .name = "analyze",
-               .handler = &handle_etm_analyze_command,
+               .handler = handle_etm_analyze_command,
                .mode = COMMAND_EXEC,
-               .help = "anaylze collected ETM trace",
+               .help = "analyze collected ETM trace",
        },
        {
                .name = "image",
-               .handler = &handle_etm_image_command,
+               .handler = handle_etm_image_command,
                .mode = COMMAND_EXEC,
-               .help = "load image from <file> [base address]",
+               .help = "load image from file with optional offset",
+               .usage = "filename [offset]",
        },
        {
                .name = "dump",
-               .handler = &handle_etm_dump_command,
+               .handler = handle_etm_dump_command,
                .mode = COMMAND_EXEC,
-               .help = "dump captured trace data <file>",
+               .help = "dump captured trace data to file",
+               .usage = "filename",
        },
        {
                .name = "load",
-               .handler = &handle_etm_load_command,
+               .handler = handle_etm_load_command,
                .mode = COMMAND_EXEC,
                .help = "load trace data for analysis <file>",
        },