From 5c34da1415719ac62108fec1bcec5f61e7d6059e Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Wed, 25 May 2022 10:08:43 -0700 Subject: [PATCH] Use new debug_defines.h (#703) * Update debug_defines from the spec. Now it includes constants for field values, so use them instead of duplicating that here. Change-Id: I2fca6e89f25123c39d4bf483b8244e47aefb0f88 * Remove unused #defines Change-Id: Id20351851c9ed2c3aa82ccf8c04b604bef11692a * Use debug spec constants in a few more places Change-Id: Ic4578729c89e3c6a26a72772e1635c5345bd6a52 Signed-off-by: Tim Newsome * Use macros for trigger action types. Which were added with the very latest debug_defines.h. Change-Id: I47f73e11d2ec529c720f2e1df05f7b0d3026e43a Signed-off-by: Tim Newsome --- src/target/riscv/debug_defines.h | 2414 ++++++++++++++++++------------ src/target/riscv/riscv-013.c | 17 +- src/target/riscv/riscv.c | 116 +- 3 files changed, 1487 insertions(+), 1060 deletions(-) diff --git a/src/target/riscv/debug_defines.h b/src/target/riscv/debug_defines.h index 5c9eef4ea..1c7459261 100644 --- a/src/target/riscv/debug_defines.h +++ b/src/target/riscv/debug_defines.h @@ -1,6 +1,6 @@ /* * This file is auto-generated by running 'make debug_defines.h' in - * https://github.com/riscv/riscv-debug-spec/ (3dfe4f7) + * https://github.com/riscv/riscv-debug-spec/ (182b9c4) * License: Creative Commons Attribution 4.0 International Public License (CC BY 4.0) */ @@ -8,15 +8,15 @@ /* * Identifies the release version of this part. */ -#define DTM_IDCODE_VERSION_OFFSET 28 +#define DTM_IDCODE_VERSION_OFFSET 0x1c #define DTM_IDCODE_VERSION_LENGTH 4 -#define DTM_IDCODE_VERSION (0xfU << DTM_IDCODE_VERSION_OFFSET) +#define DTM_IDCODE_VERSION 0xf0000000U /* * 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 (0xffffU << DTM_IDCODE_PARTNUMBER_OFFSET) +#define DTM_IDCODE_PARTNUMBER_OFFSET 0xc +#define DTM_IDCODE_PARTNUMBER_LENGTH 0x10 +#define DTM_IDCODE_PARTNUMBER 0xffff000 /* * Identifies the designer/manufacturer of this part. Bits 6:0 must be * bits 6:0 of the designer/manufacturer's Identification Code as @@ -25,11 +25,11 @@ * Identification Code. */ #define DTM_IDCODE_MANUFID_OFFSET 1 -#define DTM_IDCODE_MANUFID_LENGTH 11 -#define DTM_IDCODE_MANUFID (0x7ffU << DTM_IDCODE_MANUFID_OFFSET) +#define DTM_IDCODE_MANUFID_LENGTH 0xb +#define DTM_IDCODE_MANUFID 0xffe #define DTM_IDCODE_1_OFFSET 0 #define DTM_IDCODE_1_LENGTH 1 -#define DTM_IDCODE_1 (0x1U << DTM_IDCODE_1_OFFSET) +#define DTM_IDCODE_1 1 #define DTM_DTMCS 0x10 /* * Writing 1 to this bit does a hard reset of the DTM, @@ -40,16 +40,16 @@ * complete (e.g. a reset condition caused an inflight DMI transaction to * be cancelled). */ -#define DTM_DTMCS_DMIHARDRESET_OFFSET 17 +#define DTM_DTMCS_DMIHARDRESET_OFFSET 0x11 #define DTM_DTMCS_DMIHARDRESET_LENGTH 1 -#define DTM_DTMCS_DMIHARDRESET (0x1U << DTM_DTMCS_DMIHARDRESET_OFFSET) +#define DTM_DTMCS_DMIHARDRESET 0x20000 /* * Writing 1 to this bit clears the sticky error state, but does * not affect outstanding DMI transactions. */ -#define DTM_DTMCS_DMIRESET_OFFSET 16 +#define DTM_DTMCS_DMIRESET_OFFSET 0x10 #define DTM_DTMCS_DMIRESET_LENGTH 1 -#define DTM_DTMCS_DMIRESET (0x1U << DTM_DTMCS_DMIRESET_OFFSET) +#define DTM_DTMCS_DMIRESET 0x10000 /* * This is a hint to the debugger of the minimum number of * cycles a debugger should spend in @@ -65,76 +65,89 @@ * * And so on. */ -#define DTM_DTMCS_IDLE_OFFSET 12 +#define DTM_DTMCS_IDLE_OFFSET 0xc #define DTM_DTMCS_IDLE_LENGTH 3 -#define DTM_DTMCS_IDLE (0x7U << DTM_DTMCS_IDLE_OFFSET) +#define DTM_DTMCS_IDLE 0x7000 /* - * 0: No error. - * - * 1: Reserved. Interpret the same as 2. - * - * 2: An operation failed (resulted in \FdtmDmiOp of 2). - * - * 3: An operation was attempted while a DMI access was still in - * progress (resulted in \FdtmDmiOp of 3). + * Read-only alias of \FdtmDmiOp. */ -#define DTM_DTMCS_DMISTAT_OFFSET 10 +#define DTM_DTMCS_DMISTAT_OFFSET 0xa #define DTM_DTMCS_DMISTAT_LENGTH 2 -#define DTM_DTMCS_DMISTAT (0x3U << DTM_DTMCS_DMISTAT_OFFSET) +#define DTM_DTMCS_DMISTAT 0xc00 /* * The size of \FdmSbaddressZeroAddress in \RdtmDmi. */ #define DTM_DTMCS_ABITS_OFFSET 4 #define DTM_DTMCS_ABITS_LENGTH 6 -#define DTM_DTMCS_ABITS (0x3fU << DTM_DTMCS_ABITS_OFFSET) -/* - * 0: Version described in spec version 0.11. - * - * 1: Version described in spec versions 0.13 and 1.0. - * - * 15: Version not described in any available version of this spec. - */ +#define DTM_DTMCS_ABITS 0x3f0 #define DTM_DTMCS_VERSION_OFFSET 0 #define DTM_DTMCS_VERSION_LENGTH 4 -#define DTM_DTMCS_VERSION (0xfU << DTM_DTMCS_VERSION_OFFSET) +#define DTM_DTMCS_VERSION 0xf +/* + * 0.11: Version described in spec version 0.11. + */ +#define DTM_DTMCS_VERSION_0_11 0 +/* + * 1.0: Version described in spec versions 0.13 and 1.0. + */ +#define DTM_DTMCS_VERSION_1_0 1 +/* + * custom: Version not described in any available version of this spec. + */ +#define DTM_DTMCS_VERSION_CUSTOM 15 #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 << abits) - 1) << DTM_DMI_ADDRESS_OFFSET) +#define DTM_DMI_ADDRESS_OFFSET 0x22 +#define DTM_DMI_ADDRESS_LENGTH(abits) abits +#define DTM_DMI_ADDRESS(abits) ((0x400000000ULL * (1ULL<misa & (1 << ('S' - 'A'))) - tdata1 |= MCONTROL_S; + tdata1 |= CSR_MCONTROL_S; if (r->misa & (1 << ('U' - 'A'))) - tdata1 |= MCONTROL_U; + tdata1 |= CSR_MCONTROL_U; if (trigger->execute) - tdata1 |= MCONTROL_EXECUTE; + tdata1 |= CSR_MCONTROL_EXECUTE; if (trigger->read) - tdata1 |= MCONTROL_LOAD; + tdata1 |= CSR_MCONTROL_LOAD; if (trigger->write) - tdata1 |= MCONTROL_STORE; + tdata1 |= CSR_MCONTROL_STORE; riscv_set_register(target, GDB_REGNO_TDATA1, tdata1); @@ -653,10 +577,10 @@ static int maybe_add_trigger_t6(struct target *target, } /* address/data match trigger */ - tdata1 |= MCONTROL_DMODE(riscv_xlen(target)); + tdata1 |= CSR_MCONTROL6_DMODE(riscv_xlen(target)); tdata1 = set_field(tdata1, CSR_MCONTROL6_ACTION, - MCONTROL_ACTION_DEBUG_MODE); - tdata1 = set_field(tdata1, CSR_MCONTROL6_MATCH, MCONTROL_MATCH_EQUAL); + CSR_MCONTROL6_ACTION_DEBUG_MODE); + tdata1 = set_field(tdata1, CSR_MCONTROL6_MATCH, CSR_MCONTROL6_MATCH_EQUAL); tdata1 |= CSR_MCONTROL6_M; if (r->misa & (1 << ('H' - 'A'))) tdata1 |= CSR_MCONTROL6_VS | CSR_MCONTROL6_VU; @@ -715,7 +639,7 @@ static int add_trigger(struct target *target, struct trigger *trigger) int result = riscv_get_register(target, &tdata1, GDB_REGNO_TDATA1); if (result != ERROR_OK) return result; - int type = get_field(tdata1, MCONTROL_TYPE(riscv_xlen(target))); + int type = get_field(tdata1, CSR_TDATA1_TYPE(riscv_xlen(target))); result = ERROR_OK; switch (type) { @@ -1046,7 +970,7 @@ static int riscv_hit_trigger_hit_bit(struct target *target, uint32_t *unique_id) uint64_t tdata1; if (riscv_get_register(target, &tdata1, GDB_REGNO_TDATA1) != ERROR_OK) return ERROR_FAIL; - int type = get_field(tdata1, MCONTROL_TYPE(riscv_xlen(target))); + int type = get_field(tdata1, CSR_TDATA1_TYPE(riscv_xlen(target))); uint64_t hit_mask = 0; switch (type) { @@ -1447,7 +1371,7 @@ static int disable_triggers(struct target *target, riscv_reg_t *state) riscv_reg_t tdata1; if (riscv_get_register(target, &tdata1, GDB_REGNO_TDATA1) != ERROR_OK) return ERROR_FAIL; - if (tdata1 & MCONTROL_DMODE(riscv_xlen(target))) { + if (tdata1 & CSR_TDATA1_DMODE(riscv_xlen(target))) { state[t] = tdata1; if (riscv_set_register(target, GDB_REGNO_TDATA1, 0) != ERROR_OK) return ERROR_FAIL; @@ -4036,7 +3960,7 @@ int riscv_enumerate_triggers(struct target *target) if (result != ERROR_OK) return result; - int type = get_field(tdata1, MCONTROL_TYPE(riscv_xlen(target))); + int type = get_field(tdata1, CSR_TDATA1_TYPE(riscv_xlen(target))); if (type == 0) break; switch (type) { @@ -4046,11 +3970,11 @@ int riscv_enumerate_triggers(struct target *target) riscv_set_register(target, GDB_REGNO_TDATA1, 0); break; case 2: - if (tdata1 & MCONTROL_DMODE(riscv_xlen(target))) + if (tdata1 & CSR_MCONTROL_DMODE(riscv_xlen(target))) riscv_set_register(target, GDB_REGNO_TDATA1, 0); break; case 6: - if (tdata1 & MCONTROL_DMODE(riscv_xlen(target))) + if (tdata1 & CSR_MCONTROL6_DMODE(riscv_xlen(target))) riscv_set_register(target, GDB_REGNO_TDATA1, 0); break; }