From 29dca8b846250a015e84b36e40f4bd1b57bf55fa Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 7 Mar 2022 16:14:33 -0800 Subject: [PATCH] Update debug_defines.h (#942) I'll need it for some trigger work. --- riscv/debug_defines.h | 3235 +++++++++++++++++++++++++---------------- riscv/debug_module.cc | 232 +-- 2 files changed, 2084 insertions(+), 1383 deletions(-) diff --git a/riscv/debug_defines.h b/riscv/debug_defines.h index 1f7e0b72..9ce54b72 100644 --- a/riscv/debug_defines.h +++ b/riscv/debug_defines.h @@ -1,22 +1,28 @@ +/* + * This file is auto-generated by running 'make debug_defines.h' in + * https://github.com/riscv/riscv-debug-spec/ (4ce69ad) + * License: Creative Commons Attribution 4.0 International Public License (CC BY 4.0) + */ + #define DTM_IDCODE 0x01 /* -* Identifies the release version of this part. + * Identifies the release version of this part. */ #define DTM_IDCODE_VERSION_OFFSET 28 #define DTM_IDCODE_VERSION_LENGTH 4 #define DTM_IDCODE_VERSION (0xfU << DTM_IDCODE_VERSION_OFFSET) /* -* Identifies the designer's part number of this part. + * 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) /* -* 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. + * 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 @@ -26,274 +32,311 @@ #define DTM_IDCODE_1 (0x1U << DTM_IDCODE_1_OFFSET) #define DTM_DTMCS 0x10 /* -* Writing 1 to this bit does a hard reset of the DTM, -* causing the DTM to forget about any outstanding DMI transactions. -* In general this should only be used when the Debugger has -* reason to expect that the outstanding DMI transaction will never -* complete (e.g. a reset condition caused an inflight DMI transaction to -* be cancelled). + * Writing 1 to this bit does a hard reset of the DTM, + * causing the DTM to forget about any outstanding DMI transactions, and + * returning all registers and internal state to their reset value. + * In general this should only be used when the Debugger has + * reason to expect that the outstanding DMI transaction will never + * complete (e.g. a reset condition caused an inflight DMI transaction to + * be cancelled). */ #define DTM_DTMCS_DMIHARDRESET_OFFSET 17 #define DTM_DTMCS_DMIHARDRESET_LENGTH 1 #define DTM_DTMCS_DMIHARDRESET (0x1U << DTM_DTMCS_DMIHARDRESET_OFFSET) /* -* Writing 1 to this bit clears the sticky error state -* and allows the DTM to retry or complete the previous -* transaction. + * 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_LENGTH 1 #define DTM_DTMCS_DMIRESET (0x1U << DTM_DTMCS_DMIRESET_OFFSET) /* -* This is a hint to the debugger of 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. -* -* 0: It is not necessary to enter Run-Test/Idle at all. -* -* 1: Enter Run-Test/Idle and leave it immediately. -* -* 2: Enter Run-Test/Idle and stay there for 1 cycle before leaving. -* -* And so on. + * This is a hint to the debugger of the minimum number of + * cycles a debugger should spend in + * Run-Test/Idle after every DMI scan to avoid a `busy' + * return code (\FdtmDtmcsDmistat of 3). A debugger must still + * check \FdtmDtmcsDmistat when necessary. + * + * 0: It is not necessary to enter Run-Test/Idle at all. + * + * 1: Enter Run-Test/Idle and leave it immediately. + * + * 2: Enter Run-Test/Idle and stay there for 1 cycle before leaving. + * + * And so on. */ #define DTM_DTMCS_IDLE_OFFSET 12 #define DTM_DTMCS_IDLE_LENGTH 3 #define DTM_DTMCS_IDLE (0x7U << DTM_DTMCS_IDLE_OFFSET) /* -* 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). + * 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). */ #define DTM_DTMCS_DMISTAT_OFFSET 10 #define DTM_DTMCS_DMISTAT_LENGTH 2 #define DTM_DTMCS_DMISTAT (0x3U << DTM_DTMCS_DMISTAT_OFFSET) /* -* The size of \Faddress in \Rdmi. + * 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 version 0.13. -* -* 15: Version not described in any available version of this spec. + * 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_VERSION_OFFSET 0 #define DTM_DTMCS_VERSION_LENGTH 4 #define DTM_DTMCS_VERSION (0xfU << DTM_DTMCS_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. + * 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< ", address)); - if (address >= DMI_DATA0 && address < DMI_DATA0 + abstractcs.datacount) { - unsigned i = address - DMI_DATA0; + if (address >= DM_DATA0 && address < DM_DATA0 + abstractcs.datacount) { + unsigned i = address - DM_DATA0; result = read32(dmdata, i); if (abstractcs.busy) { result = -1; @@ -372,8 +372,8 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) if (!abstractcs.busy && ((abstractauto.autoexecdata >> i) & 1)) { perform_abstract_command(); } - } else if (address >= DMI_PROGBUF0 && address < DMI_PROGBUF0 + config.progbufsize) { - unsigned i = address - DMI_PROGBUF0; + } else if (address >= DM_PROGBUF0 && address < DM_PROGBUF0 + config.progbufsize) { + unsigned i = address - DM_PROGBUF0; result = read32(program_buffer, i); if (abstractcs.busy) { result = -1; @@ -385,20 +385,20 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) } else { switch (address) { - case DMI_DMCONTROL: + case DM_DMCONTROL: { - result = set_field(result, DMI_DMCONTROL_HALTREQ, dmcontrol.haltreq); - result = set_field(result, DMI_DMCONTROL_RESUMEREQ, dmcontrol.resumereq); - result = set_field(result, DMI_DMCONTROL_HARTSELHI, - dmcontrol.hartsel >> DMI_DMCONTROL_HARTSELLO_LENGTH); - result = set_field(result, DMI_DMCONTROL_HASEL, dmcontrol.hasel); - result = set_field(result, DMI_DMCONTROL_HARTSELLO, dmcontrol.hartsel); - result = set_field(result, DMI_DMCONTROL_HARTRESET, dmcontrol.hartreset); - result = set_field(result, DMI_DMCONTROL_NDMRESET, dmcontrol.ndmreset); - result = set_field(result, DMI_DMCONTROL_DMACTIVE, dmcontrol.dmactive); + result = set_field(result, DM_DMCONTROL_HALTREQ, dmcontrol.haltreq); + result = set_field(result, DM_DMCONTROL_RESUMEREQ, dmcontrol.resumereq); + result = set_field(result, DM_DMCONTROL_HARTSELHI, + dmcontrol.hartsel >> DM_DMCONTROL_HARTSELLO_LENGTH); + result = set_field(result, DM_DMCONTROL_HASEL, dmcontrol.hasel); + result = set_field(result, DM_DMCONTROL_HARTSELLO, dmcontrol.hartsel); + result = set_field(result, DM_DMCONTROL_HARTRESET, dmcontrol.hartreset); + result = set_field(result, DM_DMCONTROL_NDMRESET, dmcontrol.ndmreset); + result = set_field(result, DM_DMCONTROL_DMACTIVE, dmcontrol.dmactive); } break; - case DMI_DMSTATUS: + case DM_DMSTATUS: { dmstatus.allhalted = true; dmstatus.anyhalted = false; @@ -433,51 +433,51 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) dmstatus.allunavail = false; dmstatus.anyunavail = false; - result = set_field(result, DMI_DMSTATUS_IMPEBREAK, + result = set_field(result, DM_DMSTATUS_IMPEBREAK, dmstatus.impebreak); - result = set_field(result, DMI_DMSTATUS_ALLHAVERESET, + result = set_field(result, DM_DMSTATUS_ALLHAVERESET, hart_state[dmcontrol.hartsel].havereset); - result = set_field(result, DMI_DMSTATUS_ANYHAVERESET, + result = set_field(result, DM_DMSTATUS_ANYHAVERESET, hart_state[dmcontrol.hartsel].havereset); - result = set_field(result, DMI_DMSTATUS_ALLNONEXISTENT, dmstatus.allnonexistant); - result = set_field(result, DMI_DMSTATUS_ALLUNAVAIL, dmstatus.allunavail); - result = set_field(result, DMI_DMSTATUS_ALLRUNNING, dmstatus.allrunning); - result = set_field(result, DMI_DMSTATUS_ALLHALTED, dmstatus.allhalted); - result = set_field(result, DMI_DMSTATUS_ALLRESUMEACK, dmstatus.allresumeack); - result = set_field(result, DMI_DMSTATUS_ANYNONEXISTENT, dmstatus.anynonexistant); - result = set_field(result, DMI_DMSTATUS_ANYUNAVAIL, dmstatus.anyunavail); - result = set_field(result, DMI_DMSTATUS_ANYRUNNING, dmstatus.anyrunning); - result = set_field(result, DMI_DMSTATUS_ANYHALTED, dmstatus.anyhalted); - result = set_field(result, DMI_DMSTATUS_ANYRESUMEACK, dmstatus.anyresumeack); - result = set_field(result, DMI_DMSTATUS_AUTHENTICATED, dmstatus.authenticated); - result = set_field(result, DMI_DMSTATUS_AUTHBUSY, dmstatus.authbusy); - result = set_field(result, DMI_DMSTATUS_VERSION, dmstatus.version); + result = set_field(result, DM_DMSTATUS_ALLNONEXISTENT, dmstatus.allnonexistant); + result = set_field(result, DM_DMSTATUS_ALLUNAVAIL, dmstatus.allunavail); + result = set_field(result, DM_DMSTATUS_ALLRUNNING, dmstatus.allrunning); + result = set_field(result, DM_DMSTATUS_ALLHALTED, dmstatus.allhalted); + result = set_field(result, DM_DMSTATUS_ALLRESUMEACK, dmstatus.allresumeack); + result = set_field(result, DM_DMSTATUS_ANYNONEXISTENT, dmstatus.anynonexistant); + result = set_field(result, DM_DMSTATUS_ANYUNAVAIL, dmstatus.anyunavail); + result = set_field(result, DM_DMSTATUS_ANYRUNNING, dmstatus.anyrunning); + result = set_field(result, DM_DMSTATUS_ANYHALTED, dmstatus.anyhalted); + result = set_field(result, DM_DMSTATUS_ANYRESUMEACK, dmstatus.anyresumeack); + result = set_field(result, DM_DMSTATUS_AUTHENTICATED, dmstatus.authenticated); + result = set_field(result, DM_DMSTATUS_AUTHBUSY, dmstatus.authbusy); + result = set_field(result, DM_DMSTATUS_VERSION, dmstatus.version); } break; - case DMI_ABSTRACTCS: - result = set_field(result, DMI_ABSTRACTCS_CMDERR, abstractcs.cmderr); - result = set_field(result, DMI_ABSTRACTCS_BUSY, abstractcs.busy); - result = set_field(result, DMI_ABSTRACTCS_DATACOUNT, abstractcs.datacount); - result = set_field(result, DMI_ABSTRACTCS_PROGBUFSIZE, + case DM_ABSTRACTCS: + result = set_field(result, DM_ABSTRACTCS_CMDERR, abstractcs.cmderr); + result = set_field(result, DM_ABSTRACTCS_BUSY, abstractcs.busy); + result = set_field(result, DM_ABSTRACTCS_DATACOUNT, abstractcs.datacount); + result = set_field(result, DM_ABSTRACTCS_PROGBUFSIZE, abstractcs.progbufsize); break; - case DMI_ABSTRACTAUTO: - result = set_field(result, DMI_ABSTRACTAUTO_AUTOEXECPROGBUF, abstractauto.autoexecprogbuf); - result = set_field(result, DMI_ABSTRACTAUTO_AUTOEXECDATA, abstractauto.autoexecdata); + case DM_ABSTRACTAUTO: + result = set_field(result, DM_ABSTRACTAUTO_AUTOEXECPROGBUF, abstractauto.autoexecprogbuf); + result = set_field(result, DM_ABSTRACTAUTO_AUTOEXECDATA, abstractauto.autoexecdata); break; - case DMI_COMMAND: + case DM_COMMAND: result = 0; break; - case DMI_HARTINFO: - result = set_field(result, DMI_HARTINFO_NSCRATCH, 1); - result = set_field(result, DMI_HARTINFO_DATAACCESS, 1); - result = set_field(result, DMI_HARTINFO_DATASIZE, abstractcs.datacount); - result = set_field(result, DMI_HARTINFO_DATAADDR, debug_data_start); + case DM_HARTINFO: + result = set_field(result, DM_HARTINFO_NSCRATCH, 1); + result = set_field(result, DM_HARTINFO_DATAACCESS, 1); + result = set_field(result, DM_HARTINFO_DATASIZE, abstractcs.datacount); + result = set_field(result, DM_HARTINFO_DATAADDR, debug_data_start); break; - case DMI_HAWINDOWSEL: + case DM_HAWINDOWSEL: result = hawindowsel; break; - case DMI_HAWINDOW: + case DM_HAWINDOW: { unsigned base = hawindowsel * 32; for (unsigned i = 0; i < 32; i++) { @@ -488,33 +488,33 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) } } break; - case DMI_SBCS: - result = set_field(result, DMI_SBCS_SBVERSION, sbcs.version); - result = set_field(result, DMI_SBCS_SBREADONADDR, sbcs.readonaddr); - result = set_field(result, DMI_SBCS_SBACCESS, sbcs.sbaccess); - result = set_field(result, DMI_SBCS_SBAUTOINCREMENT, sbcs.autoincrement); - result = set_field(result, DMI_SBCS_SBREADONDATA, sbcs.readondata); - result = set_field(result, DMI_SBCS_SBERROR, sbcs.error); - result = set_field(result, DMI_SBCS_SBASIZE, sbcs.asize); - result = set_field(result, DMI_SBCS_SBACCESS128, sbcs.access128); - result = set_field(result, DMI_SBCS_SBACCESS64, sbcs.access64); - result = set_field(result, DMI_SBCS_SBACCESS32, sbcs.access32); - result = set_field(result, DMI_SBCS_SBACCESS16, sbcs.access16); - result = set_field(result, DMI_SBCS_SBACCESS8, sbcs.access8); + case DM_SBCS: + result = set_field(result, DM_SBCS_SBVERSION, sbcs.version); + result = set_field(result, DM_SBCS_SBREADONADDR, sbcs.readonaddr); + result = set_field(result, DM_SBCS_SBACCESS, sbcs.sbaccess); + result = set_field(result, DM_SBCS_SBAUTOINCREMENT, sbcs.autoincrement); + result = set_field(result, DM_SBCS_SBREADONDATA, sbcs.readondata); + result = set_field(result, DM_SBCS_SBERROR, sbcs.error); + result = set_field(result, DM_SBCS_SBASIZE, sbcs.asize); + result = set_field(result, DM_SBCS_SBACCESS128, sbcs.access128); + result = set_field(result, DM_SBCS_SBACCESS64, sbcs.access64); + result = set_field(result, DM_SBCS_SBACCESS32, sbcs.access32); + result = set_field(result, DM_SBCS_SBACCESS16, sbcs.access16); + result = set_field(result, DM_SBCS_SBACCESS8, sbcs.access8); break; - case DMI_SBADDRESS0: + case DM_SBADDRESS0: result = sbaddress[0]; break; - case DMI_SBADDRESS1: + case DM_SBADDRESS1: result = sbaddress[1]; break; - case DMI_SBADDRESS2: + case DM_SBADDRESS2: result = sbaddress[2]; break; - case DMI_SBADDRESS3: + case DM_SBADDRESS3: result = sbaddress[3]; break; - case DMI_SBDATA0: + case DM_SBDATA0: result = sbdata[0]; if (sbcs.error == 0) { if (sbcs.readondata) { @@ -525,20 +525,20 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) } } break; - case DMI_SBDATA1: + case DM_SBDATA1: result = sbdata[1]; break; - case DMI_SBDATA2: + case DM_SBDATA2: result = sbdata[2]; break; - case DMI_SBDATA3: + case DM_SBDATA3: result = sbdata[3]; break; - case DMI_AUTHDATA: + case DM_AUTHDATA: result = challenge; break; - case DMI_DMCS2: - result = set_field(result, DMI_DMCS2_HALTGROUP, + case DM_DMCS2: + result = set_field(result, DM_DMCS2_GROUP, hart_state[dmcontrol.hartsel].haltgroup); break; default: @@ -753,14 +753,14 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) { D(fprintf(stderr, "dmi_write(0x%x, 0x%x)\n", address, value)); - if (!dmstatus.authenticated && address != DMI_AUTHDATA && - address != DMI_DMCONTROL) + if (!dmstatus.authenticated && address != DM_AUTHDATA && + address != DM_DMCONTROL) return false; - if (address >= DMI_DATA0 && address < DMI_DATA0 + abstractcs.datacount) { - unsigned i = address - DMI_DATA0; + if (address >= DM_DATA0 && address < DM_DATA0 + abstractcs.datacount) { + unsigned i = address - DM_DATA0; if (!abstractcs.busy) - write32(dmdata, address - DMI_DATA0, value); + write32(dmdata, address - DM_DATA0, value); if (abstractcs.busy && abstractcs.cmderr == CMDERR_NONE) { abstractcs.cmderr = CMDERR_BUSY; @@ -771,8 +771,8 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) } return true; - } else if (address >= DMI_PROGBUF0 && address < DMI_PROGBUF0 + config.progbufsize) { - unsigned i = address - DMI_PROGBUF0; + } else if (address >= DM_PROGBUF0 && address < DM_PROGBUF0 + config.progbufsize) { + unsigned i = address - DM_PROGBUF0; if (!abstractcs.busy) write32(program_buffer, i, value); @@ -784,29 +784,29 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) } else { switch (address) { - case DMI_DMCONTROL: + case DM_DMCONTROL: { - if (!dmcontrol.dmactive && get_field(value, DMI_DMCONTROL_DMACTIVE)) + if (!dmcontrol.dmactive && get_field(value, DM_DMCONTROL_DMACTIVE)) reset(); - dmcontrol.dmactive = get_field(value, DMI_DMCONTROL_DMACTIVE); + dmcontrol.dmactive = get_field(value, DM_DMCONTROL_DMACTIVE); if (!dmstatus.authenticated || !dmcontrol.dmactive) return true; - dmcontrol.haltreq = get_field(value, DMI_DMCONTROL_HALTREQ); - dmcontrol.resumereq = get_field(value, DMI_DMCONTROL_RESUMEREQ); - dmcontrol.hartreset = get_field(value, DMI_DMCONTROL_HARTRESET); - dmcontrol.ndmreset = get_field(value, DMI_DMCONTROL_NDMRESET); + dmcontrol.haltreq = get_field(value, DM_DMCONTROL_HALTREQ); + dmcontrol.resumereq = get_field(value, DM_DMCONTROL_RESUMEREQ); + dmcontrol.hartreset = get_field(value, DM_DMCONTROL_HARTRESET); + dmcontrol.ndmreset = get_field(value, DM_DMCONTROL_NDMRESET); if (config.support_hasel) - dmcontrol.hasel = get_field(value, DMI_DMCONTROL_HASEL); + dmcontrol.hasel = get_field(value, DM_DMCONTROL_HASEL); else dmcontrol.hasel = 0; - dmcontrol.hartsel = get_field(value, DMI_DMCONTROL_HARTSELHI) << - DMI_DMCONTROL_HARTSELLO_LENGTH; - dmcontrol.hartsel |= get_field(value, DMI_DMCONTROL_HARTSELLO); + dmcontrol.hartsel = get_field(value, DM_DMCONTROL_HARTSELHI) << + DM_DMCONTROL_HARTSELLO_LENGTH; + dmcontrol.hartsel |= get_field(value, DM_DMCONTROL_HARTSELLO); dmcontrol.hartsel &= (1L<