openocd: fix simple cases of Yoda condition
[fw/openocd] / src / target / esirisc_trace.c
index 4e0a15529c41c8732cf16fe61966974a9eb86565..28d7536af7fdb8ba598e46fe2d1874ea2979a57e 100644 (file)
@@ -385,9 +385,9 @@ static int esirisc_trace_read_buffer(struct target *target, uint8_t *buffer)
                        buffer_cur - trace_info->buffer_start, buffer);
 }
 
-static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size)
+static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *buffer, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        const uint32_t num_bits = size * 8;
        int retval;
 
@@ -403,7 +403,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                        case ESIRISC_TRACE_ID_EXECUTE:
                        case ESIRISC_TRACE_ID_STALL:
                        case ESIRISC_TRACE_ID_BRANCH:
-                               command_print(cmd_ctx, "%s", esirisc_trace_id_strings[id]);
+                               command_print(cmd, "%s", esirisc_trace_id_strings[id]);
                                break;
 
                        case ESIRISC_TRACE_ID_EXTENDED: {
@@ -417,7 +417,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                                        case ESIRISC_TRACE_EXT_ID_STOP:
                                        case ESIRISC_TRACE_EXT_ID_WAIT:
                                        case ESIRISC_TRACE_EXT_ID_MULTICYCLE:
-                                               command_print(cmd_ctx, "%s", esirisc_trace_ext_id_strings[ext_id]);
+                                               command_print(cmd, "%s", esirisc_trace_ext_id_strings[ext_id]);
                                                break;
 
                                        case ESIRISC_TRACE_EXT_ID_ERET:
@@ -430,11 +430,11 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                                                if (retval != ERROR_OK)
                                                        goto fail;
 
-                                               command_print(cmd_ctx, "%s PC: 0x%" PRIx32,
+                                               command_print(cmd, "%s PC: 0x%" PRIx32,
                                                                esirisc_trace_ext_id_strings[ext_id], pc);
 
                                                if (ext_id == ESIRISC_TRACE_EXT_ID_END_PC) {
-                                                       command_print(cmd_ctx, "--- end of trace ---");
+                                                       command_print(cmd, "--- end of trace ---");
                                                        return ERROR_OK;
                                                }
                                                break;
@@ -450,7 +450,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                                                if (retval != ERROR_OK)
                                                        goto fail;
 
-                                               command_print(cmd_ctx, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32,
+                                               command_print(cmd, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32,
                                                                esirisc_trace_ext_id_strings[ext_id], eid, epc);
                                                break;
                                        }
@@ -461,34 +461,34 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *
                                                if (retval != ERROR_OK)
                                                        goto fail;
 
-                                               command_print(cmd_ctx, "repeats %" PRId32 " %s", count,
+                                               command_print(cmd, "repeats %" PRIu32 " %s", count,
                                                                (count == 1) ? "time" : "times");
                                                break;
                                        }
                                        case ESIRISC_TRACE_EXT_ID_END:
-                                               command_print(cmd_ctx, "--- end of trace ---");
+                                               command_print(cmd, "--- end of trace ---");
                                                return ERROR_OK;
 
                                        default:
-                                               command_print(cmd_ctx, "invalid extended trace ID: %" PRId32, ext_id);
+                                               command_print(cmd, "invalid extended trace ID: %" PRIu32, ext_id);
                                                return ERROR_FAIL;
                                }
                                break;
                        }
                        default:
-                               command_print(cmd_ctx, "invalid trace ID: %" PRId32, id);
+                               command_print(cmd, "invalid trace ID: %" PRIu32, id);
                                return ERROR_FAIL;
                }
        }
 
 fail:
-       command_print(cmd_ctx, "trace buffer too small");
+       command_print(cmd, "trace buffer too small");
        return ERROR_BUF_TOO_SMALL;
 }
 
-static int esirisc_trace_analyze_simple(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size)
+static int esirisc_trace_analyze_simple(struct command_invocation *cmd, uint8_t *buffer, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        struct esirisc_common *esirisc = target_to_esirisc(target);
        struct esirisc_trace *trace_info = &esirisc->trace_info;
        const uint32_t end_of_trace = BIT_MASK(trace_info->pc_bits) << 1;
@@ -504,45 +504,45 @@ static int esirisc_trace_analyze_simple(struct command_context *cmd_ctx, uint8_t
                        break;
 
                if (pc == end_of_trace) {
-                       command_print(cmd_ctx, "--- end of trace ---");
+                       command_print(cmd, "--- end of trace ---");
                        return ERROR_OK;
                }
 
-               command_print(cmd_ctx, "PC: 0x%" PRIx32, pc);
+               command_print(cmd, "PC: 0x%" PRIx32, pc);
        }
 
-       command_print(cmd_ctx, "trace buffer too small");
+       command_print(cmd, "trace buffer too small");
        return ERROR_BUF_TOO_SMALL;
 }
 
-static int esirisc_trace_analyze(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size)
+static int esirisc_trace_analyze(struct command_invocation *cmd, uint8_t *buffer, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        struct esirisc_common *esirisc = target_to_esirisc(target);
        struct esirisc_trace *trace_info = &esirisc->trace_info;
 
        switch (trace_info->format) {
                case ESIRISC_TRACE_FORMAT_FULL:
-                       command_print(cmd_ctx, "--- full pipeline ---");
-                       return esirisc_trace_analyze_full(cmd_ctx, buffer, size);
+                       command_print(cmd, "--- full pipeline ---");
+                       return esirisc_trace_analyze_full(cmd, buffer, size);
 
                case ESIRISC_TRACE_FORMAT_BRANCH:
-                       command_print(cmd_ctx, "--- branches taken ---");
-                       return esirisc_trace_analyze_full(cmd_ctx, buffer, size);
+                       command_print(cmd, "--- branches taken ---");
+                       return esirisc_trace_analyze_full(cmd, buffer, size);
 
                case ESIRISC_TRACE_FORMAT_ICACHE:
-                       command_print(cmd_ctx, "--- icache misses ---");
-                       return esirisc_trace_analyze_simple(cmd_ctx, buffer, size);
+                       command_print(cmd, "--- icache misses ---");
+                       return esirisc_trace_analyze_simple(cmd, buffer, size);
 
                default:
-                       command_print(cmd_ctx, "invalid trace format: %i", trace_info->format);
+                       command_print(cmd, "invalid trace format: %i", trace_info->format);
                        return ERROR_FAIL;
        }
 }
 
-static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx)
+static int esirisc_trace_analyze_buffer(struct command_invocation *cmd)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        struct esirisc_common *esirisc = target_to_esirisc(target);
        struct esirisc_trace *trace_info = &esirisc->trace_info;
        uint8_t *buffer;
@@ -552,7 +552,7 @@ static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx)
        size = esirisc_trace_buffer_size(trace_info);
        buffer = calloc(1, size);
        if (buffer == NULL) {
-               command_print(cmd_ctx, "out of memory");
+               command_print(cmd, "out of memory");
                return ERROR_FAIL;
        }
 
@@ -560,7 +560,7 @@ static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx)
        if (retval != ERROR_OK)
                goto done;
 
-       retval = esirisc_trace_analyze(cmd_ctx, buffer, size);
+       retval = esirisc_trace_analyze(cmd, buffer, size);
 
 done:
        free(buffer);
@@ -568,16 +568,16 @@ done:
        return retval;
 }
 
-static int esirisc_trace_analyze_memory(struct command_context *cmd_ctx,
+static int esirisc_trace_analyze_memory(struct command_invocation *cmd,
                target_addr_t address, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        uint8_t *buffer;
        int retval;
 
        buffer = calloc(1, size);
        if (buffer == NULL) {
-               command_print(cmd_ctx, "out of memory");
+               command_print(cmd, "out of memory");
                return ERROR_FAIL;
        }
 
@@ -585,7 +585,7 @@ static int esirisc_trace_analyze_memory(struct command_context *cmd_ctx,
        if (retval != ERROR_OK)
                goto done;
 
-       retval = esirisc_trace_analyze(cmd_ctx, buffer, size);
+       retval = esirisc_trace_analyze(cmd, buffer, size);
 
 done:
        free(buffer);
@@ -593,7 +593,7 @@ done:
        return retval;
 }
 
-static int esirisc_trace_dump(struct command_context *cmd_ctx, const char *filename,
+static int esirisc_trace_dump(struct command_invocation *cmd, const char *filename,
                uint8_t *buffer, uint32_t size)
 {
        struct fileio *fileio;
@@ -602,24 +602,24 @@ static int esirisc_trace_dump(struct command_context *cmd_ctx, const char *filen
 
        retval = fileio_open(&fileio, filename, FILEIO_WRITE, FILEIO_BINARY);
        if (retval != ERROR_OK) {
-               command_print(cmd_ctx, "could not open dump file: %s", filename);
+               command_print(cmd, "could not open dump file: %s", filename);
                return retval;
        }
 
        retval = fileio_write(fileio, size, buffer, &size_written);
        if (retval == ERROR_OK)
-               command_print(cmd_ctx, "trace data dumped to: %s", filename);
+               command_print(cmd, "trace data dumped to: %s", filename);
        else
-               command_print(cmd_ctx, "could not write dump file: %s", filename);
+               command_print(cmd, "could not write dump file: %s", filename);
 
        fileio_close(fileio);
 
        return retval;
 }
 
-static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char *filename)
+static int esirisc_trace_dump_buffer(struct command_invocation *cmd, const char *filename)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        struct esirisc_common *esirisc = target_to_esirisc(target);
        struct esirisc_trace *trace_info = &esirisc->trace_info;
        uint8_t *buffer;
@@ -629,7 +629,7 @@ static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char
        size = esirisc_trace_buffer_size(trace_info);
        buffer = calloc(1, size);
        if (buffer == NULL) {
-               command_print(cmd_ctx, "out of memory");
+               command_print(cmd, "out of memory");
                return ERROR_FAIL;
        }
 
@@ -637,7 +637,7 @@ static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char
        if (retval != ERROR_OK)
                goto done;
 
-       retval = esirisc_trace_dump(cmd_ctx, filename, buffer, size);
+       retval = esirisc_trace_dump(cmd, filename, buffer, size);
 
 done:
        free(buffer);
@@ -645,16 +645,16 @@ done:
        return retval;
 }
 
-static int esirisc_trace_dump_memory(struct command_context *cmd_ctx, const char *filename,
+static int esirisc_trace_dump_memory(struct command_invocation *cmd, const char *filename,
                target_addr_t address, uint32_t size)
 {
-       struct target *target = get_current_target(cmd_ctx);
+       struct target *target = get_current_target(cmd->ctx);
        uint8_t *buffer;
        int retval;
 
        buffer = calloc(1, size);
        if (buffer == NULL) {
-               command_print(cmd_ctx, "out of memory");
+               command_print(cmd, "out of memory");
                return ERROR_FAIL;
        }
 
@@ -662,7 +662,7 @@ static int esirisc_trace_dump_memory(struct command_context *cmd_ctx, const char
        if (retval != ERROR_OK)
                goto done;
 
-       retval = esirisc_trace_dump(cmd_ctx, filename, buffer, size);
+       retval = esirisc_trace_dump(cmd, filename, buffer, size);
 
 done:
        free(buffer);
@@ -676,13 +676,13 @@ COMMAND_HANDLER(handle_esirisc_trace_init_command)
        struct esirisc_common *esirisc = target_to_esirisc(target);
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
        int retval = esirisc_trace_init(target);
        if (retval == ERROR_OK)
-               command_print(CMD_CTX, "trace initialized");
+               command_print(CMD, "trace initialized");
 
        return retval;
 }
@@ -694,42 +694,42 @@ COMMAND_HANDLER(handle_esirisc_trace_info_command)
        struct esirisc_trace *trace_info = &esirisc->trace_info;
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
        if (esirisc_trace_is_fifo(trace_info))
-               command_print(CMD_CTX, "trace FIFO address: 0x%" TARGET_PRIxADDR,
+               command_print(CMD, "trace FIFO address: 0x%" TARGET_PRIxADDR,
                                trace_info->buffer_start);
        else {
-               command_print(CMD_CTX, "trace buffer start: 0x%" TARGET_PRIxADDR,
+               command_print(CMD, "trace buffer start: 0x%" TARGET_PRIxADDR,
                                trace_info->buffer_start);
-               command_print(CMD_CTX, "trace buffer end: 0x%" TARGET_PRIxADDR,
+               command_print(CMD, "trace buffer end: 0x%" TARGET_PRIxADDR,
                                trace_info->buffer_end);
-               command_print(CMD_CTX, "trace buffer will %swrap",
+               command_print(CMD, "trace buffer will %swrap",
                                trace_info->buffer_wrap ? "" : "not ");
        }
 
-       command_print(CMD_CTX, "flow control: %s",
+       command_print(CMD, "flow control: %s",
                        trace_info->flow_control ? "enabled" : "disabled");
 
-       command_print(CMD_CTX, "trace format: %s",
+       command_print(CMD, "trace format: %s",
                        esirisc_trace_format_strings[trace_info->format]);
-       command_print(CMD_CTX, "number of PC bits: %i", trace_info->pc_bits);
+       command_print(CMD, "number of PC bits: %i", trace_info->pc_bits);
 
-       command_print(CMD_CTX, "start trigger: %s",
+       command_print(CMD, "start trigger: %s",
                        esirisc_trace_trigger_strings[trace_info->start_trigger]);
-       command_print(CMD_CTX, "start data: 0x%" PRIx32, trace_info->start_data);
-       command_print(CMD_CTX, "start mask: 0x%" PRIx32, trace_info->start_mask);
+       command_print(CMD, "start data: 0x%" PRIx32, trace_info->start_data);
+       command_print(CMD, "start mask: 0x%" PRIx32, trace_info->start_mask);
 
-       command_print(CMD_CTX, "stop trigger: %s",
+       command_print(CMD, "stop trigger: %s",
                        esirisc_trace_trigger_strings[trace_info->stop_trigger]);
-       command_print(CMD_CTX, "stop data: 0x%" PRIx32, trace_info->stop_data);
-       command_print(CMD_CTX, "stop mask: 0x%" PRIx32, trace_info->stop_mask);
+       command_print(CMD, "stop data: 0x%" PRIx32, trace_info->stop_data);
+       command_print(CMD, "stop mask: 0x%" PRIx32, trace_info->stop_mask);
 
-       command_print(CMD_CTX, "trigger delay: %s",
+       command_print(CMD, "trigger delay: %s",
                        esirisc_trace_delay_strings[trace_info->delay]);
-       command_print(CMD_CTX, "trigger delay cycles: %i", trace_info->delay_cycles);
+       command_print(CMD, "trigger delay cycles: %" PRIu32, trace_info->delay_cycles);
 
        return ERROR_OK;
 }
@@ -741,7 +741,7 @@ COMMAND_HANDLER(handle_esirisc_trace_status_command)
        uint32_t status;
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
@@ -749,7 +749,7 @@ COMMAND_HANDLER(handle_esirisc_trace_status_command)
        if (retval != ERROR_OK)
                return retval;
 
-       command_print(CMD_CTX, "trace is %s%s%s%s",
+       command_print(CMD, "trace is %s%s%s%s",
                        (status & STATUS_T)  ? "started" : "stopped",
                        (status & STATUS_TD) ? ", disabled"   : "",
                        (status & STATUS_W)  ? ", wrapped"    : "",
@@ -764,13 +764,13 @@ COMMAND_HANDLER(handle_esirisc_trace_start_command)
        struct esirisc_common *esirisc = target_to_esirisc(target);
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
        int retval = esirisc_trace_start(target);
        if (retval == ERROR_OK)
-               command_print(CMD_CTX, "trace started");
+               command_print(CMD, "trace started");
 
        return retval;
 }
@@ -781,13 +781,13 @@ COMMAND_HANDLER(handle_esirisc_trace_stop_command)
        struct esirisc_common *esirisc = target_to_esirisc(target);
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
        int retval = esirisc_trace_stop(target);
        if (retval == ERROR_OK)
-               command_print(CMD_CTX, "trace stopped");
+               command_print(CMD, "trace stopped");
 
        return retval;
 }
@@ -801,7 +801,7 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command)
        uint32_t size;
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
@@ -817,16 +817,16 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command)
                 * as arguments as a workaround.
                 */
                if (esirisc_trace_is_fifo(trace_info)) {
-                       command_print(CMD_CTX, "analyze from FIFO not supported");
+                       command_print(CMD, "analyze from FIFO not supported");
                        return ERROR_FAIL;
                }
 
-               return esirisc_trace_analyze_buffer(CMD_CTX);
+               return esirisc_trace_analyze_buffer(CMD);
        } else {
                COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size);
 
-               return esirisc_trace_analyze_memory(CMD_CTX, address, size);
+               return esirisc_trace_analyze_memory(CMD, address, size);
        }
 }
 
@@ -839,7 +839,7 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command)
        uint32_t size;
 
        if (!esirisc->has_trace) {
-               command_print(CMD_CTX, "target does not support trace");
+               command_print(CMD, "target does not support trace");
                return ERROR_FAIL;
        }
 
@@ -849,16 +849,16 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command)
        if (CMD_ARGC == 1) {
                /* also see: handle_esirisc_trace_analyze_command() */
                if (esirisc_trace_is_fifo(trace_info)) {
-                       command_print(CMD_CTX, "dump from FIFO not supported");
+                       command_print(CMD, "dump from FIFO not supported");
                        return ERROR_FAIL;
                }
 
-               return esirisc_trace_dump_buffer(CMD_CTX, CMD_ARGV[0]);
+               return esirisc_trace_dump_buffer(CMD, CMD_ARGV[0]);
        } else {
                COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
                COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size);
 
-               return esirisc_trace_dump_memory(CMD_CTX, CMD_ARGV[2], address, size);
+               return esirisc_trace_dump_memory(CMD, CMD_ARGV[2], address, size);
        }
 }
 
@@ -946,7 +946,7 @@ COMMAND_HANDLER(handle_esirisc_trace_format_command)
        COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], pc_bits);
 
        if (pc_bits < 1 || pc_bits > 31) {
-               command_print(CMD_CTX, "invalid pc_bits: %i; must be 1..31", pc_bits);
+               command_print(CMD, "invalid pc_bits: %i; must be 1..31", pc_bits);
                return ERROR_COMMAND_SYNTAX_ERROR;
        }