-static int arm11_handle_mrc_mcr(struct command_context_s *cmd_ctx,
- char *cmd, char **args, int argc, bool read)
-{
- int retval;
-
- if (argc != (read ? 6 : 7))
- {
- LOG_ERROR("Invalid number of arguments.");
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
- arm11_common_t * arm11 = arm11_find_target(args[0]);
-
- if (!arm11)
- {
- LOG_ERROR("Parameter 1 is not a the JTAG chain position of an ARM11 device.");
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
-
- if (arm11->target->state != TARGET_HALTED)
- {
- LOG_WARNING("target was not halted");
- return ERROR_TARGET_NOT_HALTED;
- }
-
- uint32_t values[6];
-
- for (size_t i = 0; i < (read ? 5 : 6); i++)
- {
- COMMAND_PARSE_NUMBER(u32, args[i + 1], values[i]);
-
- if (values[i] > arm11_coproc_instruction_limits[i])
- {
- LOG_ERROR("Parameter %ld out of bounds (%" PRId32 " max).",
- (long)(i + 2),
- arm11_coproc_instruction_limits[i]);
- return ERROR_COMMAND_SYNTAX_ERROR;
- }
- }
-
- uint32_t instr = 0xEE000010 |
- (values[0] << 8) |
- (values[1] << 21) |
- (values[2] << 16) |
- (values[3] << 0) |
- (values[4] << 5);
-
- if (read)
- instr |= 0x00100000;
-
- retval = arm11_run_instr_data_prepare(arm11);
- if (retval != ERROR_OK)
- return retval;
-
- if (read)
- {
- uint32_t result;
- retval = arm11_run_instr_data_from_core_via_r0(arm11, instr, &result);
- if (retval != ERROR_OK)
- return retval;
-
- LOG_INFO("MRC p%d, %d, R0, c%d, c%d, %d = 0x%08" PRIx32 " (%" PRId32 ")",
- (int)(values[0]),
- (int)(values[1]),
- (int)(values[2]),
- (int)(values[3]),
- (int)(values[4]), result, result);
- }
- else
- {
- retval = arm11_run_instr_data_to_core_via_r0(arm11, instr, values[5]);
- if (retval != ERROR_OK)
- return retval;
-
- LOG_INFO("MRC p%d, %d, R0 (#0x%08" PRIx32 "), c%d, c%d, %d",
- (int)(values[0]), (int)(values[1]),
- values[5],
- (int)(values[2]), (int)(values[3]), (int)(values[4]));
- }
-
- return arm11_run_instr_data_finish(arm11);
-}
-
-static int arm11_handle_mrc(struct command_context_s *cmd_ctx,
- char *cmd, char **args, int argc)
-{
- return arm11_handle_mrc_mcr(cmd_ctx, cmd, args, argc, true);
-}
-
-static int arm11_handle_mcr(struct command_context_s *cmd_ctx,
- char *cmd, char **args, int argc)
-{
- return arm11_handle_mrc_mcr(cmd_ctx, cmd, args, argc, false);
-}
-