diff --git a/src/target/riscv/debug_defines.h b/src/target/riscv/debug_defines.h index 2a78bdf0a..2e0c192e6 100644 --- a/src/target/riscv/debug_defines.h +++ b/src/target/riscv/debug_defines.h @@ -1,52 +1,139 @@ -#define AC_ACCESS_REGISTER None +#define DTM_IDCODE 0x01 /* -* 2: Access the lowest 32 bits of the register. +* Identifies the release version of this part. + */ +#define DTM_IDCODE_VERSION_OFFSET 28 +#define DTM_IDCODE_VERSION_LENGTH 4 +#define DTM_IDCODE_VERSION (0xf << DTM_IDCODE_VERSION_OFFSET) +/* +* Identifies the designer's part number of this part. + */ +#define DTM_IDCODE_PARTNUMBER_OFFSET 12 +#define DTM_IDCODE_PARTNUMBER_LENGTH 16 +#define DTM_IDCODE_PARTNUMBER (0xffff << DTM_IDCODE_PARTNUMBER_OFFSET) +/* +* Identifies the designer/manufacturer of this part. Bits 6:0 must be +* bits 6:0 of the designer/manufacturer's Identification Code as +* assigned by JEDEC Standard JEP106. Bits 10:7 contain the modulo-16 +* count of the number of continuation characters (0x7f) in that same +* Identification Code. + */ +#define DTM_IDCODE_MANUFID_OFFSET 1 +#define DTM_IDCODE_MANUFID_LENGTH 11 +#define DTM_IDCODE_MANUFID (0x7ff << DTM_IDCODE_MANUFID_OFFSET) +#define DTM_IDCODE_1_OFFSET 0 +#define DTM_IDCODE_1_LENGTH 1 +#define DTM_IDCODE_1 (0x1 << DTM_IDCODE_1_OFFSET) +#define DTM_DTMCONTROL 0x10 +/* +* Writing 1 to this bit resets the DMI controller, clearing any +* sticky error state. + */ +#define DTM_DTMCONTROL_DMIRESET_OFFSET 16 +#define DTM_DTMCONTROL_DMIRESET_LENGTH 1 +#define DTM_DTMCONTROL_DMIRESET (0x1 << DTM_DTMCONTROL_DMIRESET_OFFSET) +/* +* This is the minimum number of cycles a debugger should spend in +* Run-Test/Idle after every DMI scan to avoid a 'busy' +* return code (\Fdmistat of 3). A debugger must still +* check \Fdmistat when necessary. * -* 3: Access the lowest 64 bits of the register. +* 0: It is not necessary to enter Run-Test/Idle at all. * -* 4: Access the lowest 128 bits of the register. +* 1: Enter Run-Test/Idle and leave it immediately. * -* If \Fsize specifies a size larger than the register is, then the -* access must fail. If a register is accessible, then \Fsize matching -* the register's actual size must be supported. - */ -#define AC_ACCESS_REGISTER_SIZE_OFFSET 19 -#define AC_ACCESS_REGISTER_SIZE_LENGTH 3 -#define AC_ACCESS_REGISTER_SIZE (0x7 << AC_ACCESS_REGISTER_SIZE_OFFSET) -/* -* When 1, execute the program in the Program Buffer exactly once -* before performing the read/write. - */ -#define AC_ACCESS_REGISTER_PREEXEC_OFFSET 18 -#define AC_ACCESS_REGISTER_PREEXEC_LENGTH 1 -#define AC_ACCESS_REGISTER_PREEXEC (0x1 << AC_ACCESS_REGISTER_PREEXEC_OFFSET) -/* -* When 1, execute the program in the Program Buffer exactly once -* after performing the read/write. - */ -#define AC_ACCESS_REGISTER_POSTEXEC_OFFSET 17 -#define AC_ACCESS_REGISTER_POSTEXEC_LENGTH 1 -#define AC_ACCESS_REGISTER_POSTEXEC (0x1 << AC_ACCESS_REGISTER_POSTEXEC_OFFSET) -/* -* 0: Copy data from {\tt arg0} portion of {\tt data} into the -* specified register. +* 2: Enter Run-Test/Idle and stay there for 1 cycle before leaving. * -* 1: Copy data from the specified register into {\tt arg0} portion -* of {\tt data}. +* And so on. */ -#define AC_ACCESS_REGISTER_WRITE_OFFSET 16 -#define AC_ACCESS_REGISTER_WRITE_LENGTH 1 -#define AC_ACCESS_REGISTER_WRITE (0x1 << AC_ACCESS_REGISTER_WRITE_OFFSET) +#define DTM_DTMCONTROL_IDLE_OFFSET 12 +#define DTM_DTMCONTROL_IDLE_LENGTH 3 +#define DTM_DTMCONTROL_IDLE (0x7 << DTM_DTMCONTROL_IDLE_OFFSET) /* -* Number of the register to access, as described in Table~\ref{tab:regno}. +* 0: No error. +* +* 1: Reserved. Interpret the same as 2. +* +* 2: An operation failed (resulted in \Fop of 2). +* +* 3: An operation was attempted while a DMI access was still in +* progress (resulted in \Fop of 3). */ -#define AC_ACCESS_REGISTER_REGNO_OFFSET 0 -#define AC_ACCESS_REGISTER_REGNO_LENGTH 16 -#define AC_ACCESS_REGISTER_REGNO (0xffff << AC_ACCESS_REGISTER_REGNO_OFFSET) -#define AC_QUICK_ACCESS None -#define AC_QUICK_ACCESS_1_OFFSET 24 -#define AC_QUICK_ACCESS_1_LENGTH 8 -#define AC_QUICK_ACCESS_1 (0xff << AC_QUICK_ACCESS_1_OFFSET) +#define DTM_DTMCONTROL_DMISTAT_OFFSET 10 +#define DTM_DTMCONTROL_DMISTAT_LENGTH 2 +#define DTM_DTMCONTROL_DMISTAT (0x3 << DTM_DTMCONTROL_DMISTAT_OFFSET) +/* +* The size of \Faddress in \Rdmi. + */ +#define DTM_DTMCONTROL_ABITS_OFFSET 4 +#define DTM_DTMCONTROL_ABITS_LENGTH 6 +#define DTM_DTMCONTROL_ABITS (0x3f << DTM_DTMCONTROL_ABITS_OFFSET) +/* +* 0: Version described in spec version 0.11. +* +* 1: Version described in spec version 0.12 (and later?), which +* reduces the DMI data width to 32 bits. +* +* Other values are reserved for future use. + */ +#define DTM_DTMCONTROL_VERSION_OFFSET 0 +#define DTM_DTMCONTROL_VERSION_LENGTH 4 +#define DTM_DTMCONTROL_VERSION (0xf << DTM_DTMCONTROL_VERSION_OFFSET) +#define DTM_DMI 0x11 +/* +* Address used for DMI access. In Update-DR this value is used +* to access the DM over the DMI. + */ +#define DTM_DMI_ADDRESS_OFFSET 34 +#define DTM_DMI_ADDRESS_LENGTH abits +#define DTM_DMI_ADDRESS (((1L<code[i+1] << 8) | ((uint32_t) program->code[i+2] << 16) | ((uint32_t) program->code[i+3] << 24); - dmi_write(target, DMI_IBUF0 + i / 4, value); + dmi_write(target, DMI_PROGBUF0 + i / 4, value); } } @@ -1272,7 +1272,8 @@ static int halt(struct target *target) LOG_DEBUG("riscv_halt()"); select_dmi(target); - dmi_write(target, DMI_DMCONTROL, DMI_DMCONTROL_HALTREQ | DMI_DMCONTROL_DMACTIVE); + dmi_write(target, DMI_DMCONTROL, DMI_DMCONTROL_HALTREQ | + DMI_DMCONTROL_DMACTIVE); return ERROR_OK; } @@ -1679,13 +1680,14 @@ static int examine(struct target *target) LOG_DEBUG("dmcontrol: 0x%08x", dmcontrol); LOG_DEBUG(" haltreq=%d", get_field(dmcontrol, DMI_DMCONTROL_HALTREQ)); - LOG_DEBUG(" reset=%d", get_field(dmcontrol, DMI_DMCONTROL_RESET)); - LOG_DEBUG(" dmactive=%d", get_field(dmcontrol, DMI_DMCONTROL_DMACTIVE)); + LOG_DEBUG(" resumereq=%d", get_field(dmcontrol, DMI_DMCONTROL_RESUMEREQ)); LOG_DEBUG(" hartstatus=%d", get_field(dmcontrol, DMI_DMCONTROL_HARTSTATUS)); LOG_DEBUG(" hartsel=0x%x", get_field(dmcontrol, DMI_DMCONTROL_HARTSEL)); + LOG_DEBUG(" hartreset=0x%x", get_field(dmcontrol, DMI_DMCONTROL_HARTRESET)); + LOG_DEBUG(" dmactive=%d", get_field(dmcontrol, DMI_DMCONTROL_DMACTIVE)); + LOG_DEBUG(" reset=%d", get_field(dmcontrol, DMI_DMCONTROL_RESET)); LOG_DEBUG(" authenticated=%d", get_field(dmcontrol, DMI_DMCONTROL_AUTHENTICATED)); LOG_DEBUG(" authbusy=%d", get_field(dmcontrol, DMI_DMCONTROL_AUTHBUSY)); - LOG_DEBUG(" authtype=%d", get_field(dmcontrol, DMI_DMCONTROL_AUTHTYPE)); LOG_DEBUG(" version=%d", get_field(dmcontrol, DMI_DMCONTROL_VERSION)); unsigned hartstatus = DMI_DMCONTROL_HARTSTATUS; @@ -1718,8 +1720,8 @@ static int examine(struct target *target) LOG_DEBUG("abstractcs=0x%x", abstractcs); LOG_DEBUG(" datacount=%d", info->datacount); - uint32_t accesscs = dmi_read(target, DMI_ACCESSCS); - info->progsize = get_field(abstractcs, DMI_ACCESSCS_PROGSIZE); + uint32_t accesscs = dmi_read(target, DMI_PROGBUFCS); + info->progsize = get_field(abstractcs, DMI_PROGBUFCS_PROGSIZE); LOG_DEBUG("accesscs=0x%x", accesscs); LOG_DEBUG(" progsize=%d", info->progsize); @@ -1730,7 +1732,7 @@ static int examine(struct target *target) } for (unsigned i = 0; i < info->progsize; i++) { - dmi_write(target, DMI_IBUF0 + i, value); + dmi_write(target, DMI_PROGBUF0 + i, value); value += 0x52534335; } @@ -1745,17 +1747,18 @@ static int examine(struct target *target) value += 0x52534335; } for (unsigned i = 0; i < info->progsize; i++) { - uint32_t check = dmi_read(target, DMI_IBUF0 + i); + uint32_t check = dmi_read(target, DMI_PROGBUF0 + i); if (check != value) { LOG_ERROR("Wrote 0x%x to dbus address 0x%x but got back 0x%x", - value, DMI_IBUF0 + i, check); + value, DMI_PROGBUF0 + i, check); return ERROR_FAIL; } value += 0x52534335; } if (hartstatus == 1) { - dmi_write(target, DMI_DMCONTROL, DMI_DMCONTROL_HALTREQ | DMI_DMCONTROL_DMACTIVE); + dmi_write(target, DMI_DMCONTROL, DMI_DMCONTROL_HALTREQ | + DMI_DMCONTROL_DMACTIVE); for (unsigned i = 0; i < 256; i++) { dmcontrol = dmi_read(target, DMI_DMCONTROL); if (get_field(dmcontrol, DMI_DMCONTROL_HARTSTATUS) == 0)