+// SPDX-License-Identifier: GPL-2.0-or-later
+
/***************************************************************************
* Copyright (C) 2018 by Square, Inc. *
* Steven Stallion <stallion@squareup.com> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * 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, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
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;
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: {
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:
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;
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;
}
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;
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;
size = esirisc_trace_buffer_size(trace_info);
buffer = calloc(1, size);
- if (buffer == NULL) {
- command_print(cmd_ctx, "out of memory");
+ if (!buffer) {
+ command_print(cmd, "out of memory");
return ERROR_FAIL;
}
if (retval != ERROR_OK)
goto done;
- retval = esirisc_trace_analyze(cmd_ctx, buffer, size);
+ retval = esirisc_trace_analyze(cmd, buffer, size);
done:
free(buffer);
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");
+ if (!buffer) {
+ command_print(cmd, "out of memory");
return ERROR_FAIL;
}
if (retval != ERROR_OK)
goto done;
- retval = esirisc_trace_analyze(cmd_ctx, buffer, size);
+ retval = esirisc_trace_analyze(cmd, buffer, size);
done:
free(buffer);
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;
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;
size = esirisc_trace_buffer_size(trace_info);
buffer = calloc(1, size);
- if (buffer == NULL) {
- command_print(cmd_ctx, "out of memory");
+ if (!buffer) {
+ command_print(cmd, "out of memory");
return ERROR_FAIL;
}
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);
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");
+ if (!buffer) {
+ command_print(cmd, "out of memory");
return ERROR_FAIL;
}
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);
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;
}
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;
}
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;
}
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" : "",
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;
}
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;
}
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;
}
* 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);
}
}
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;
}
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);
}
}
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;
}