target/etm: change prototype of etmv1_analyze_trace()
[openocd.git] / src / target / etm.c
index e99c24ffbec36f1bdf8e64f1665ae7ac8b6f0c84..4c95626f998fb8e528275c34e6598f7592ddb0d4 100644 (file)
@@ -13,9 +13,7 @@
  *   GNU General Public License for more details.                          *
  *                                                                         *
  *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -67,7 +65,7 @@ struct etm_reg_info {
        uint8_t size;                   /* low-N of 32 bits */
        uint8_t mode;                   /* RO, WO, RW */
        uint8_t bcd_vers;               /* 1.0, 2.0, etc */
-       char *name;
+       const char *name;
 };
 
 /*
@@ -144,6 +142,7 @@ static const struct etm_reg_info etm_addr_comp[] = {
        ADDR_COMPARATOR(14),
        ADDR_COMPARATOR(15),
        ADDR_COMPARATOR(16),
+       { 0, 0, 0, 0, NULL }
 #undef ADDR_COMPARATOR
 };
 
@@ -162,6 +161,7 @@ static const struct etm_reg_info etm_data_comp[] = {
        DATA_COMPARATOR(6),
        DATA_COMPARATOR(7),
        DATA_COMPARATOR(8),
+       { 0, 0, 0, 0, NULL }
 #undef DATA_COMPARATOR
 };
 
@@ -179,6 +179,7 @@ static const struct etm_reg_info etm_counters[] = {
        ETM_COUNTER(2),
        ETM_COUNTER(3),
        ETM_COUNTER(4),
+       { 0, 0, 0, 0, NULL }
 #undef ETM_COUNTER
 };
 
@@ -206,6 +207,7 @@ static const struct etm_reg_info etm_outputs[] = {
        ETM_OUTPUT(2),
        ETM_OUTPUT(3),
        ETM_OUTPUT(4),
+       { 0, 0, 0, 0, NULL }
 #undef ETM_OUTPUT
 };
 
@@ -265,6 +267,11 @@ static void etm_reg_add(unsigned bcd_vers, struct arm_jtag *jtag_info,
         * version of the ETM, to the specified cache.
         */
        for (; nreg--; r++) {
+               /* No more registers to add */
+               if (!r->size) {
+                       LOG_ERROR("etm_reg_add is requested to add non-existing registers, ETM config might be bogus");
+                       return;
+               }
 
                /* this ETM may be too old to have some registers */
                if (r->bcd_vers > bcd_vers)
@@ -309,7 +316,7 @@ struct reg_cache *etm_build_reg_cache(struct target *target,
                etm_core, 1);
 
        etm_get_reg(reg_list);
-       etm_ctx->config = buf_get_u32((void *)&arch_info->value, 0, 32);
+       etm_ctx->config = buf_get_u32(arch_info->value, 0, 32);
        config = etm_ctx->config;
 
        /* figure ETM version then add base registers */
@@ -325,7 +332,7 @@ struct reg_cache *etm_build_reg_cache(struct target *target,
                        etm_core + 1, 1);
                etm_get_reg(reg_list + 1);
                etm_ctx->id = buf_get_u32(
-                               (void *)&arch_info[1].value, 0, 32);
+                               arch_info[1].value, 0, 32);
                LOG_DEBUG("ETM ID: %08x", (unsigned) etm_ctx->id);
                bcd_vers = 0x10 + (((etm_ctx->id) >> 4) & 0xff);
 
@@ -506,7 +513,7 @@ static int etm_read_reg_w_check(struct reg *reg,
        retval = arm_jtag_scann(etm_reg->jtag_info, 0x6, TAP_IDLE);
        if (retval != ERROR_OK)
                return retval;
-       retval = arm_jtag_set_instr(etm_reg->jtag_info,
+       retval = arm_jtag_set_instr(etm_reg->jtag_info->tap,
                        etm_reg->jtag_info->intest_instr,
                        NULL,
                        TAP_IDLE);
@@ -593,7 +600,7 @@ static int etm_write_reg(struct reg *reg, uint32_t value)
        retval = arm_jtag_scann(etm_reg->jtag_info, 0x6, TAP_IDLE);
        if (retval != ERROR_OK)
                return retval;
-       retval = arm_jtag_set_instr(etm_reg->jtag_info,
+       retval = arm_jtag_set_instr(etm_reg->jtag_info->tap,
                        etm_reg->jtag_info->intest_instr,
                        NULL,
                        TAP_IDLE);
@@ -852,7 +859,7 @@ static int etmv1_data(struct etm_context *ctx, int size, uint32_t *data)
        return 0;
 }
 
-static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *cmd_ctx)
+static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocation *cmd)
 {
        int retval;
        struct arm_instruction instruction;
@@ -862,7 +869,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                ctx->capture_driver->read_trace(ctx);
 
        if (ctx->trace_depth == 0) {
-               command_print(cmd_ctx, "Trace is empty.");
+               command_print(cmd->ctx, "Trace is empty.");
                return ERROR_OK;
        }
 
@@ -886,7 +893,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                int current_pc_ok = ctx->pc_ok;
 
                if (ctx->trace_data[ctx->pipe_index].flags & ETMV1_TRIGGER_CYCLE)
-                       command_print(cmd_ctx, "--- trigger ---");
+                       command_print(cmd->ctx, "--- trigger ---");
 
                /* instructions execute in IE/D or BE/D cycles */
                if ((pipestat == STAT_IE) || (pipestat == STAT_ID))
@@ -922,7 +929,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                 * and a new branch was encountered in cycle ctx->pipe_index + retval;
                                 */
                                LOG_WARNING(
-                                       "abandoned branch encountered, correctnes of analysis uncertain");
+                                       "abandoned branch encountered, correctness of analysis uncertain");
                                ctx->pipe_index += retval;
                                continue;
                        }
@@ -935,7 +942,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                        next_pc = ctx->last_branch;
                                        break;
                                case 0x1:       /* tracing enabled */
-                                       command_print(cmd_ctx,
+                                       command_print(cmd->ctx,
                                                "--- tracing enabled at 0x%8.8" PRIx32 " ---",
                                                ctx->last_branch);
                                        ctx->current_pc = ctx->last_branch;
@@ -943,7 +950,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                        continue;
                                        break;
                                case 0x2:       /* trace restarted after FIFO overflow */
-                                       command_print(cmd_ctx,
+                                       command_print(cmd->ctx,
                                                "--- trace restarted after FIFO overflow at 0x%8.8" PRIx32 " ---",
                                                ctx->last_branch);
                                        ctx->current_pc = ctx->last_branch;
@@ -951,7 +958,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                        continue;
                                        break;
                                case 0x3:       /* exit from debug state */
-                                       command_print(cmd_ctx,
+                                       command_print(cmd->ctx,
                                                "--- exit from debug state at 0x%8.8" PRIx32 " ---",
                                                ctx->last_branch);
                                        ctx->current_pc = ctx->last_branch;
@@ -964,7 +971,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                         * we have to move on with the next trace cycle
                                         */
                                        if (!current_pc_ok) {
-                                               command_print(cmd_ctx,
+                                               command_print(cmd->ctx,
                                                        "--- periodic synchronization point at 0x%8.8" PRIx32 " ---",
                                                        next_pc);
                                                ctx->current_pc = next_pc;
@@ -981,19 +988,19 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
 
                        /* if we got here the branch was a normal PC change
                         * (or a periodic synchronization point, which means the same for that matter)
-                        * if we didn't accquire a complete PC continue with the next cycle
+                        * if we didn't acquire a complete PC continue with the next cycle
                         */
                        if (!ctx->pc_ok)
                                continue;
 
-                       /* indirect branch to the exception vector means an exception occured */
+                       /* indirect branch to the exception vector means an exception occurred */
                        if ((ctx->last_branch <= 0x20)
                                || ((ctx->last_branch >= 0xffff0000) &&
                                (ctx->last_branch <= 0xffff0020))) {
                                if ((ctx->last_branch & 0xff) == 0x10)
-                                       command_print(cmd_ctx, "data abort");
+                                       command_print(cmd->ctx, "data abort");
                                else {
-                                       command_print(cmd_ctx,
+                                       command_print(cmd->ctx,
                                                "exception vector 0x%2.2" PRIx32 "",
                                                ctx->last_branch);
                                        ctx->current_pc = ctx->last_branch;
@@ -1015,7 +1022,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                        return retval;
                                else if (retval == ERROR_TRACE_INSTRUCTION_UNAVAILABLE) {
                                        /* TODO: handle incomplete images
-                                        * for now we just quit the analsysis*/
+                                        * for now we just quit the analysis*/
                                        return retval;
                                }
                        }
@@ -1051,7 +1058,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                        ctx->ptr_ok = 1;
 
                                if (ctx->ptr_ok)
-                                       command_print(cmd_ctx,
+                                       command_print(cmd->ctx,
                                                "address: 0x%8.8" PRIx32 "",
                                                ctx->last_ptr);
                        }
@@ -1066,7 +1073,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                                        uint32_t data;
                                                        if (etmv1_data(ctx, 4, &data) != 0)
                                                                return ERROR_ETM_ANALYSIS_FAILED;
-                                                       command_print(cmd_ctx,
+                                                       command_print(cmd->ctx,
                                                                "data: 0x%8.8" PRIx32 "",
                                                                data);
                                                }
@@ -1077,7 +1084,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                        if (etmv1_data(ctx, arm_access_size(&instruction),
                                                &data) != 0)
                                                return ERROR_ETM_ANALYSIS_FAILED;
-                                       command_print(cmd_ctx, "data: 0x%8.8" PRIx32 "", data);
+                                       command_print(cmd->ctx, "data: 0x%8.8" PRIx32 "", data);
                                }
                        }
 
@@ -1112,7 +1119,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *
                                        (cycles == 1) ? "cycle" : "cycles");
                        }
 
-                       command_print(cmd_ctx, "%s%s%s",
+                       command_print(cmd->ctx, "%s%s%s",
                                instruction.text,
                                (pipestat == STAT_IN) ? " (not executed)" : "",
                                cycles_text);
@@ -1186,7 +1193,7 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update,
        /* IGNORED:
         *  - CPRT tracing (coprocessor register transfers)
         *  - debug request (causes debug entry on trigger)
-        *  - stall on FIFOFULL (preventing tracedata lossage)
+        *  - stall on FIFOFULL (preventing tracedata loss)
         */
        *mode = tracemode;
 
@@ -1338,7 +1345,7 @@ COMMAND_HANDLER(handle_etm_config_command)
         *    check whether our setting "took".
         *
         *  - The "clock" and "mode" bits are interpreted differently.
-        *    See ARM IHI 0014O table 2-17 for the old behavior, and
+        *    See ARM IHI 0014O table 2-17 for the old behaviour, and
         *    table 2-18 for the new.  With ETB it's best to specify
         *    "normal full" ...
         */
@@ -1692,7 +1699,7 @@ COMMAND_HANDLER(handle_etm_image_command)
 
 COMMAND_HANDLER(handle_etm_dump_command)
 {
-       struct fileio file;
+       struct fileio *file;
        struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
@@ -1732,24 +1739,24 @@ COMMAND_HANDLER(handle_etm_dump_command)
        if (fileio_open(&file, CMD_ARGV[0], FILEIO_WRITE, FILEIO_BINARY) != ERROR_OK)
                return ERROR_FAIL;
 
-       fileio_write_u32(&file, etm_ctx->capture_status);
-       fileio_write_u32(&file, etm_ctx->control);
-       fileio_write_u32(&file, etm_ctx->trace_depth);
+       fileio_write_u32(file, etm_ctx->capture_status);
+       fileio_write_u32(file, etm_ctx->control);
+       fileio_write_u32(file, etm_ctx->trace_depth);
 
        for (i = 0; i < etm_ctx->trace_depth; i++) {
-               fileio_write_u32(&file, etm_ctx->trace_data[i].pipestat);
-               fileio_write_u32(&file, etm_ctx->trace_data[i].packet);
-               fileio_write_u32(&file, etm_ctx->trace_data[i].flags);
+               fileio_write_u32(file, etm_ctx->trace_data[i].pipestat);
+               fileio_write_u32(file, etm_ctx->trace_data[i].packet);
+               fileio_write_u32(file, etm_ctx->trace_data[i].flags);
        }
 
-       fileio_close(&file);
+       fileio_close(file);
 
        return ERROR_OK;
 }
 
 COMMAND_HANDLER(handle_etm_load_command)
 {
-       struct fileio file;
+       struct fileio *file;
        struct target *target;
        struct arm *arm;
        struct etm_context *etm_ctx;
@@ -1779,16 +1786,16 @@ COMMAND_HANDLER(handle_etm_load_command)
        if (fileio_open(&file, CMD_ARGV[0], FILEIO_READ, FILEIO_BINARY) != ERROR_OK)
                return ERROR_FAIL;
 
-       int filesize;
-       int retval = fileio_size(&file, &filesize);
+       size_t filesize;
+       int retval = fileio_size(file, &filesize);
        if (retval != ERROR_OK) {
-               fileio_close(&file);
+               fileio_close(file);
                return retval;
        }
 
        if (filesize % 4) {
                command_print(CMD_CTX, "size isn't a multiple of 4, no valid trace data");
-               fileio_close(&file);
+               fileio_close(file);
                return ERROR_FAIL;
        }
 
@@ -1799,28 +1806,28 @@ COMMAND_HANDLER(handle_etm_load_command)
 
        {
                uint32_t tmp;
-               fileio_read_u32(&file, &tmp); etm_ctx->capture_status = tmp;
-               fileio_read_u32(&file, &tmp); etm_ctx->control = tmp;
-               fileio_read_u32(&file, &etm_ctx->trace_depth);
+               fileio_read_u32(file, &tmp); etm_ctx->capture_status = tmp;
+               fileio_read_u32(file, &tmp); etm_ctx->control = tmp;
+               fileio_read_u32(file, &etm_ctx->trace_depth);
        }
        etm_ctx->trace_data = malloc(sizeof(struct etmv1_trace_data) * etm_ctx->trace_depth);
        if (etm_ctx->trace_data == NULL) {
                command_print(CMD_CTX, "not enough memory to perform operation");
-               fileio_close(&file);
+               fileio_close(file);
                return ERROR_FAIL;
        }
 
        for (i = 0; i < etm_ctx->trace_depth; i++) {
                uint32_t pipestat, packet, flags;
-               fileio_read_u32(&file, &pipestat);
-               fileio_read_u32(&file, &packet);
-               fileio_read_u32(&file, &flags);
+               fileio_read_u32(file, &pipestat);
+               fileio_read_u32(file, &packet);
+               fileio_read_u32(file, &flags);
                etm_ctx->trace_data[i].pipestat = pipestat & 0xff;
                etm_ctx->trace_data[i].packet = packet & 0xffff;
                etm_ctx->trace_data[i].flags = flags;
        }
 
-       fileio_close(&file);
+       fileio_close(file);
 
        return ERROR_OK;
 }
@@ -1975,7 +1982,7 @@ COMMAND_HANDLER(handle_etm_analyze_command)
                return ERROR_FAIL;
        }
 
-       retval = etmv1_analyze_trace(etm_ctx, CMD_CTX);
+       retval = etmv1_analyze_trace(etm_ctx, CMD);
        if (retval != ERROR_OK) {
                /* FIX! error should be reported inside etmv1_analyze_trace() */
                switch (retval) {
@@ -2017,7 +2024,7 @@ const struct command_registration etm_command_handlers[] = {
        {
                .name = "etm",
                .mode = COMMAND_ANY,
-               .help = "Emebdded Trace Macrocell command group",
+               .help = "Embedded Trace Macrocell command group",
                .usage = "",
                .chain = etm_config_command_handlers,
        },

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)