diff options
Diffstat (limited to 'src/target/arm946e.c')
-rw-r--r-- | src/target/arm946e.c | 74 |
1 files changed, 29 insertions, 45 deletions
diff --git a/src/target/arm946e.c b/src/target/arm946e.c index 5e25d71..112631a 100644 --- a/src/target/arm946e.c +++ b/src/target/arm946e.c @@ -99,11 +99,11 @@ static int arm946e_target_create(struct target *target, Jim_Interp *interp) return ERROR_OK; } -static int arm946e_verify_pointer(struct command_context *cmd_ctx, +static int arm946e_verify_pointer(struct command_invocation *cmd, struct arm946e_common *arm946e) { if (arm946e->common_magic != ARM946E_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an ARM946"); + command_print(cmd, "target is not an ARM946"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -549,70 +549,54 @@ int arm946e_read_memory(struct target *target, target_addr_t address, return ERROR_OK; } -static int jim_arm946e_cp15(Jim_Interp *interp, int argc, Jim_Obj * const *argv) +COMMAND_HANDLER(arm946e_handle_cp15) { /* one or two arguments, access a single register (write if second argument is given) */ - if (argc < 2 || argc > 3) { - Jim_WrongNumArgs(interp, 1, argv, "addr [value]"); - return JIM_ERR; - } - - struct command_context *cmd_ctx = current_command_context(interp); - assert(cmd_ctx != NULL); + if (CMD_ARGC < 1 || CMD_ARGC > 2) + return ERROR_COMMAND_SYNTAX_ERROR; - struct target *target = get_current_target(cmd_ctx); - if (target == NULL) { - LOG_ERROR("arm946e: no current target"); - return JIM_ERR; - } + struct target *target = get_current_target(CMD_CTX); struct arm946e_common *arm946e = target_to_arm946(target); - int retval = arm946e_verify_pointer(cmd_ctx, arm946e); + int retval = arm946e_verify_pointer(CMD, arm946e); if (retval != ERROR_OK) - return JIM_ERR; + return retval; if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target %s must be stopped for \"cp15\" command", target_name(target)); - return JIM_ERR; + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); + return ERROR_TARGET_NOT_HALTED; } - long l; uint32_t address; - retval = Jim_GetLong(interp, argv[1], &l); - address = l; - if (JIM_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); - if (argc == 2) { + if (CMD_ARGC == 1) { uint32_t value; retval = arm946e_read_cp15(target, address, &value); if (retval != ERROR_OK) { - command_print(cmd_ctx, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); - return JIM_ERR; + command_print(CMD, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); + return retval; } retval = jtag_execute_queue(); if (retval != ERROR_OK) - return JIM_ERR; - char buf[20]; - sprintf(buf, "0x%08" PRIx32, value); + return retval; + /* Return value in hex format */ - Jim_SetResultString(interp, buf, -1); - } else if (argc == 3) { + command_print(CMD, "0x%08" PRIx32, value); + } else if (CMD_ARGC == 2) { uint32_t value; - retval = Jim_GetLong(interp, argv[2], &l); - value = l; - if (JIM_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); + retval = arm946e_write_cp15(target, address, value); if (retval != ERROR_OK) { - command_print(cmd_ctx, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); - return JIM_ERR; + command_print(CMD, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); + return retval; } if (address == CP15_CTL) arm946e_update_cp15_caches(target, value); } - return JIM_OK; + return ERROR_OK; } COMMAND_HANDLER(arm946e_handle_idcache) @@ -624,12 +608,12 @@ COMMAND_HANDLER(arm946e_handle_idcache) struct target *target = get_current_target(CMD_CTX); struct arm946e_common *arm946e = target_to_arm946(target); - retval = arm946e_verify_pointer(CMD_CTX, arm946e); + retval = arm946e_verify_pointer(CMD, arm946e); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_TARGET_NOT_HALTED; } @@ -639,9 +623,9 @@ COMMAND_HANDLER(arm946e_handle_idcache) bool bena = ((arm946e->cp15_control_reg & (icache ? CP15_CTL_ICACHE : CP15_CTL_DCACHE)) != 0) && (arm946e->cp15_control_reg & 0x1); if (csize == 0) - command_print(CMD_CTX, "%s-cache absent", icache ? "I" : "D"); + command_print(CMD, "%s-cache absent", icache ? "I" : "D"); else - command_print(CMD_CTX, "%s-cache size: %" PRIu32 "K, %s", + command_print(CMD, "%s-cache size: %" PRIu32 "K, %s", icache ? "I" : "D", csize, bena ? "enabled" : "disabled"); return ERROR_OK; } @@ -659,7 +643,7 @@ COMMAND_HANDLER(arm946e_handle_idcache) /* Do not invalidate or change state, if cache is absent */ if (csize == 0) { - command_print(CMD_CTX, "%s-cache absent, '%s' operation undefined", icache ? "I" : "D", CMD_ARGV[0]); + command_print(CMD, "%s-cache absent, '%s' operation undefined", icache ? "I" : "D", CMD_ARGV[0]); return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } @@ -703,7 +687,7 @@ COMMAND_HANDLER(arm946e_handle_idcache) static const struct command_registration arm946e_exec_command_handlers[] = { { .name = "cp15", - .jim_handler = jim_arm946e_cp15, + .handler = arm946e_handle_cp15, .mode = COMMAND_EXEC, .usage = "regnum [value]", .help = "read/modify cp15 register", |