Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Missing Cortex-A/R memory IO diagnostics #1698

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/target/cortexar.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,14 @@ static uint32_t cortexar_coproc_read(target_s *const target, const uint8_t copro
cortexar_run_insn(target,
ARM_MRC_INSN |
ENCODE_CP_ACCESS(coproc & 0xfU, (op >> 8U) & 0x7U, 0U, (op >> 4U) & 0xfU, op & 0xfU, (op >> 12U) & 0x7U));
return cortexar_core_reg_read(target, 0U);
const uint32_t result = cortexar_core_reg_read(target, 0U);
DEBUG_PROTO("%s: coproc %u (%04x): %08" PRIx32 "\n", __func__, coproc, op, result);
return result;
}

static void cortexar_coproc_write(target_s *const target, const uint8_t coproc, const uint16_t op, const uint32_t value)
{
DEBUG_PROTO("%s: coproc %u (%04x): %08" PRIx32 "\n", __func__, coproc, op, value);
/*
* Perform a write of a coprocessor - which one (between 0 and 15) is given by the coproc parameter
* and which register of the coprocessor to write and the operands required is given by op.
Expand Down Expand Up @@ -1000,6 +1003,19 @@ static void cortexar_mem_read(target_s *const target, void *const dest, const ta
cortexr_mem_read_slow(target, (uint8_t *)dest, src, len);
/* Deal with any data faults that occured */
cortexr_mem_handle_fault(target, __func__, fault_status, fault_addr);

DEBUG_PROTO("%s: Reading %zu bytes @0x%" PRIx32 ":", __func__, len, src);
#ifndef DEBUG_PROTO_IS_NOOP
const uint8_t *const data = (const uint8_t *)dest;
#endif
for (size_t offset = 0; offset < len; ++offset) {
if (offset == 16U)
break;
DEBUG_PROTO(" %02x", data[offset]);
}
if (len > 16U)
DEBUG_PROTO(" ...");
DEBUG_PROTO("\n");
}

/* Fast path for cortexar_mem_write(). Assumes the address to read data from is already loaded in r0. */
Expand Down Expand Up @@ -1061,7 +1077,19 @@ static void cortexar_mem_write(
target_s *const target, const target_addr_t dest, const void *const src, const size_t len)
{
cortexar_priv_s *const priv = (cortexar_priv_s *)target->priv;
DEBUG_TARGET("%s: Writing %zu bytes @0x%" PRIx32 "\n", __func__, len, dest);
DEBUG_PROTO("%s: Writing %zu bytes @0x%" PRIx32 ":", __func__, len, dest);
#ifndef DEBUG_PROTO_IS_NOOP
const uint8_t *const data = (const uint8_t *)src;
#endif
for (size_t offset = 0; offset < len; ++offset) {
if (offset == 16U)
break;
DEBUG_PROTO(" %02x", data[offset]);
}
if (len > 16U)
DEBUG_PROTO(" ...");
DEBUG_PROTO("\n");

/* Cache DFSR and DFAR in case we wind up triggering a data fault */
const uint32_t fault_status = cortexar_coproc_read(target, CORTEXAR_DFSR);
const uint32_t fault_addr = cortexar_coproc_read(target, CORTEXAR_DFAR);
Expand Down