+ if ((argc < 6) || (argc > 7))
+ {
+ return JIM_ERR;
+ }
+
+ int cpnum;
+ uint32_t op1;
+ uint32_t op2;
+ uint32_t CRn;
+ uint32_t CRm;
+ uint32_t value;
+
+ int e;
+ long l;
+ e = Jim_GetLong(interp, argv[1], &l);
+ if (e != JIM_OK) {
+ return e;
+ }
+ cpnum = l;
+
+ e = Jim_GetLong(interp, argv[2], &l);
+ if (e != JIM_OK) {
+ return e;
+ }
+ op1 = l;
+
+ e = Jim_GetLong(interp, argv[3], &l);
+ if (e != JIM_OK) {
+ return e;
+ }
+ CRn = l;
+
+ e = Jim_GetLong(interp, argv[4], &l);
+ if (e != JIM_OK) {
+ return e;
+ }
+ CRm = l;
+
+ e = Jim_GetLong(interp, argv[5], &l);
+ if (e != JIM_OK) {
+ return e;
+ }
+ op2 = l;
+
+ value = 0;
+
+ if (argc == 7)
+ {
+ e = Jim_GetLong(interp, argv[6], &l);
+ if (e != JIM_OK) {
+ return e;
+ }
+ value = l;
+
+ retval = target_mcr(target, cpnum, op1, op2, CRn, CRm, value);
+ if (retval != ERROR_OK)
+ return JIM_ERR;
+ } else
+ {
+ retval = target_mrc(target, cpnum, op1, op2, CRn, CRm, &value);
+ if (retval != ERROR_OK)
+ return JIM_ERR;
+
+ Jim_SetResult(interp, Jim_NewIntObj(interp, value));
+ }
+
+ return JIM_OK;
+}
+
+static const struct command_registration target_command_handlers[] = {
+ {
+ .name = "targets",
+ .handler = &handle_targets_command,
+ .mode = COMMAND_ANY,
+ .help = "change current command line target (one parameter) "
+ "or list targets (no parameters)",
+ .usage = "[<new_current_target>]",
+ },
+ {
+ .name = "target",
+ .mode = COMMAND_CONFIG,
+ .jim_handler = &jim_target,
+ .help = "configure target",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+int target_register_commands(struct command_context *cmd_ctx)
+{
+ return register_commands(cmd_ctx, NULL, target_command_handlers);
+}
+
+static const struct command_registration target_exec_command_handlers[] = {
+ {
+ .name = "fast_load_image",
+ .handler = &handle_fast_load_image_command,
+ .mode = COMMAND_ANY,
+ .help = "Load image into memory, mainly for profiling purposes",
+ .usage = "<file> <address> ['bin'|'ihex'|'elf'|'s19'] "
+ "[min_address] [max_length]",
+ },
+ {
+ .name = "fast_load",
+ .handler = &handle_fast_load_command,
+ .mode = COMMAND_ANY,
+ .help = "loads active fast load image to current target "
+ "- mainly for profiling purposes",
+ },
+ {
+ .name = "profile",
+ .handler = &handle_profile_command,
+ .mode = COMMAND_EXEC,
+ .help = "profiling samples the CPU PC",
+ },
+ /** @todo don't register virt2phys() unless target supports it */
+ {
+ .name = "virt2phys",
+ .handler = &handle_virt2phys_command,
+ .mode = COMMAND_ANY,
+ .help = "translate a virtual address into a physical address",
+ },
+
+ {
+ .name = "reg",
+ .handler = &handle_reg_command,
+ .mode = COMMAND_EXEC,
+ .help = "display or set a register",
+ },
+
+ {
+ .name = "poll",
+ .handler = &handle_poll_command,
+ .mode = COMMAND_EXEC,
+ .help = "poll target state",
+ },
+ {
+ .name = "wait_halt",
+ .handler = &handle_wait_halt_command,
+ .mode = COMMAND_EXEC,
+ .help = "wait for target halt",
+ .usage = "[time (s)]",
+ },
+ {
+ .name = "halt",
+ .handler = &handle_halt_command,
+ .mode = COMMAND_EXEC,
+ .help = "halt target",
+ },
+ {
+ .name = "resume",
+ .handler = &handle_resume_command,
+ .mode = COMMAND_EXEC,
+ .help = "resume target",
+ .usage = "[<address>]",
+ },
+ {
+ .name = "reset",
+ .handler = &handle_reset_command,
+ .mode = COMMAND_EXEC,
+ .usage = "[run|halt|init]",
+ .help = "Reset all targets into the specified mode."
+ "Default reset mode is run, if not given.",
+ },
+ {
+ .name = "soft_reset_halt",
+ .handler = &handle_soft_reset_halt_command,
+ .mode = COMMAND_EXEC,
+ .help = "halt the target and do a soft reset",
+ },
+ {
+
+ .name = "step",
+ .handler = &handle_step_command,
+ .mode = COMMAND_EXEC,
+ .help = "step one instruction from current PC or [addr]",
+ .usage = "[<address>]",
+ },
+ {
+
+ .name = "mdw",
+ .handler = &handle_md_command,
+ .mode = COMMAND_EXEC,
+ .help = "display memory words",
+ .usage = "[phys] <addr> [count]",
+ },
+ {
+ .name = "mdh",
+ .handler = &handle_md_command,
+ .mode = COMMAND_EXEC,
+ .help = "display memory half-words",
+ .usage = "[phys] <addr> [count]",
+ },
+ {
+ .name = "mdb",
+ .handler = &handle_md_command,
+ .mode = COMMAND_EXEC,
+ .help = "display memory bytes",
+ .usage = "[phys] <addr> [count]",
+ },
+ {
+
+ .name = "mww",
+ .handler = &handle_mw_command,
+ .mode = COMMAND_EXEC,
+ .help = "write memory word",
+ .usage = "[phys] <addr> <value> [count]",
+ },
+ {
+ .name = "mwh",
+ .handler = &handle_mw_command,
+ .mode = COMMAND_EXEC,
+ .help = "write memory half-word",
+ .usage = "[phys] <addr> <value> [count]",
+ },
+ {
+ .name = "mwb",
+ .handler = &handle_mw_command,
+ .mode = COMMAND_EXEC,
+ .help = "write memory byte",
+ .usage = "[phys] <addr> <value> [count]",
+ },
+ {
+
+ .name = "bp",
+ .handler = &handle_bp_command,
+ .mode = COMMAND_EXEC,
+ .help = "list or set breakpoint",
+ .usage = "[<address> <length> [hw]]",
+ },
+ {
+ .name = "rbp",
+ .handler = &handle_rbp_command,
+ .mode = COMMAND_EXEC,
+ .help = "remove breakpoint",
+ .usage = "<address>",
+ },
+ {
+
+ .name = "wp",
+ .handler = &handle_wp_command,
+ .mode = COMMAND_EXEC,
+ .help = "list or set watchpoint",
+ .usage = "[<address> <length> <r/w/a> [value] [mask]]",
+ },
+ {
+ .name = "rwp",
+ .handler = &handle_rwp_command,
+ .mode = COMMAND_EXEC,
+ .help = "remove watchpoint",
+ .usage = "<address>",
+
+ },
+ {
+ .name = "load_image",
+ .handler = &handle_load_image_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<file> <address> ['bin'|'ihex'|'elf'|'s19'] "
+ "[min_address] [max_length]",
+ },
+ {
+ .name = "dump_image",
+ .handler = &handle_dump_image_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<file> <address> <size>",
+ },
+ {
+ .name = "verify_image",
+ .handler = &handle_verify_image_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<file> [offset] [type]",
+ },
+ {
+ .name = "test_image",
+ .handler = &handle_test_image_command,
+ .mode = COMMAND_EXEC,
+ .usage = "<file> [offset] [type]",
+ },
+ {
+ .name = "ocd_mem2array",
+ .mode = COMMAND_EXEC,
+ .jim_handler = &jim_mem2array,
+ .help = "read memory and return as a TCL array "
+ "for script processing",
+ .usage = "<arrayname> <width=32|16|8> <address> <count>",
+ },
+ {
+ .name = "ocd_array2mem",
+ .mode = COMMAND_EXEC,
+ .jim_handler = &jim_array2mem,
+ .help = "convert a TCL array to memory locations "
+ "and write the values",
+ .usage = "<arrayname> <width=32|16|8> <address> <count>",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+int target_register_user_commands(struct command_context *cmd_ctx)
+{
+ int retval = ERROR_OK;
+ if ((retval = target_request_register_commands(cmd_ctx)) != ERROR_OK)
+ return retval;
+
+ if ((retval = trace_register_commands(cmd_ctx)) != ERROR_OK)
+ return retval;
+
+
+ return register_commands(cmd_ctx, NULL, target_exec_command_handlers);
+}