|
| 1 | +# Copyright (c) Katherine Hsu |
| 2 | +# SPDX-License-Identifier: BSD-3-Clause-Clear |
| 3 | + |
| 4 | +# yaml-language-server: $schema=../../schemas/csr_schema.json |
| 5 | + |
| 6 | +$schema: "csr_schema.json#" |
| 7 | +kind: csr |
| 8 | +name: dcsr |
| 9 | +long_name: Debug Control and Status Register |
| 10 | +address: 0x7B0 |
| 11 | +priv_mode: D |
| 12 | +length: 32 |
| 13 | +description: | |
| 14 | + Upon entry into Debug Mode, v and prv are updated with the privilege level the hart was previously in, |
| 15 | + and cause is updated with the reason for Debug Mode entry. Other than these fields and nmip, the |
| 16 | + other fields of dcsr are only writable by the external debugger. |
| 17 | +
|
| 18 | + Priority of reasons for entering Debug Mode from highest to lowest is shown below. |
| 19 | + 5:: resethaltreq |
| 20 | + 6:: halt group |
| 21 | + 3:: haltreq |
| 22 | + 2:: trigger |
| 23 | + 1:: ebreak |
| 24 | + 4:: step |
| 25 | +
|
| 26 | + For compatibility with old versions of this spec, resethaltreq and |
| 27 | + haltreq are allowed to be at different positions than shown as long as: |
| 28 | + 1. resethaltreq is higher priority than haltreq |
| 29 | + 2. the relative order of the other four causes is maintained |
| 30 | +
|
| 31 | + This CSR is read/write. |
| 32 | +
|
| 33 | +definedBy: Sdext |
| 34 | +fields: |
| 35 | + DEBUGVER: |
| 36 | + location: 31-28 |
| 37 | + type: RO |
| 38 | + description: | |
| 39 | + 0 (none):: There is no debug support. |
| 40 | + 4 (1.0):: Debug support exists as it is described in this document. |
| 41 | + 15 (custom):: There is debug support, but it does not conform to any available version of this spec. |
| 42 | + reset_value: UNDEFINED_LEGAL |
| 43 | + EXTCAUSE: |
| 44 | + location: 26-24 |
| 45 | + type: RO |
| 46 | + description: | |
| 47 | + When cause is 7, this optional field contains the value of a more specific halt reason than "other." |
| 48 | + Otherwise it contains 0. |
| 49 | +
|
| 50 | + 0 (critical error):: The hart entered a critical error state, as defined in the Smdbltrp extension. |
| 51 | +
|
| 52 | + All other values are reserved for future versions of this spec, or for use by other RISC-V extensions. |
| 53 | + reset_value: 0 |
| 54 | + CETRIG: |
| 55 | + location: 19 |
| 56 | + type: RW |
| 57 | + definedBy: Smdbltrp |
| 58 | + description: | |
| 59 | + This bit is part of Smdbltrp and only exists when that extension is implemented. |
| 60 | + 0 (disabled):: A hart in a critical error state does not enter |
| 61 | + Debug Mode but instead asserts the critical-error signal to |
| 62 | + the platform. |
| 63 | + 1 (enabled):: A hart in a critical error state enters Debug |
| 64 | + Mode instead of asserting the critical-error signal to the |
| 65 | + platform. Upon such entry into Debug Mode, the cause |
| 66 | + field is set to 7, and the extcause field is set to 0, indicating |
| 67 | + a critical error triggered the Debug Mode entry. This cause |
| 68 | + has the highest priority among all reasons for entering |
| 69 | + Debug Mode. Resuming from Debug Mode following an |
| 70 | + entry from the critical error state returns the hart to the |
| 71 | + critical error state. |
| 72 | +
|
| 73 | + When cetrig is 1, resuming from Debug Mode following an entry due to a critical |
| 74 | + error will result in an immediate re-entry into Debug Mode due to the critical error. |
| 75 | + The debugger may resume with cetrig set to 0 to allow the platform defined actions on |
| 76 | + critical-error signal to occur. Other possible actions include initiating a hart or platform |
| 77 | + reset using the Debug Module reset control. |
| 78 | + reset_value: 0 |
| 79 | + PELP: |
| 80 | + location: 18 |
| 81 | + type: RW |
| 82 | + definedBy: Zicfilp |
| 83 | + description: | |
| 84 | + This bit is part of Zicfilp and only exists when that extension is implemented. |
| 85 | + 0 (NO_LP_EXPECTED):: No landing pad instruction expected. |
| 86 | + 1 (LP_EXPECTED):: A landing pad instruction is expected. |
| 87 | + reset_value: 0 |
| 88 | + EBREAKVS: |
| 89 | + location: 17 |
| 90 | + type: RW |
| 91 | + definedBy: H |
| 92 | + description: | |
| 93 | + 0 (exception):: ebreak instructions in VS-mode behave as described in the Privileged Spec. |
| 94 | + 1 (debug mode):: ebreak instructions in VS-mode enter Debug Mode. |
| 95 | + This bit is hardwired to 0 if the hart does not support virtualization mode. |
| 96 | + reset_value: 0 |
| 97 | + EBREAKVU: |
| 98 | + location: 16 |
| 99 | + type: RW |
| 100 | + definedBy: H |
| 101 | + description: | |
| 102 | + 0 (exception):: ebreak instructions in VU-mode behave as described in the Privileged Spec. |
| 103 | + 1 (debug mode):: ebreak instructions in VU-mode enter Debug Mode. |
| 104 | + This bit is hardwired to 0 if the hart does not support virtualization mode. |
| 105 | + reset_value: 0 |
| 106 | + EBREAKM: |
| 107 | + location: 15 |
| 108 | + type: RW |
| 109 | + description: | |
| 110 | + 0 (exception):: ebreak instructions in M-mode behave as described in the Privileged Spec. |
| 111 | + 1 (debug mode):: ebreak instructions in M-mode enter Debug Mode. |
| 112 | + reset_value: 0 |
| 113 | + EBREAKS: |
| 114 | + location: 13 |
| 115 | + type: RW |
| 116 | + definedBy: S |
| 117 | + description: | |
| 118 | + 0 (exception):: ebreak instructions in S-mode behave as described in the Privileged Spec. |
| 119 | + 1 (debug mode):: ebreak instructions in S-mode enter Debug Mode. |
| 120 | + This bit is hardwired to 0 if the hart does not support S-mode. |
| 121 | + reset_value: 0 |
| 122 | + EBREAKU: |
| 123 | + location: 12 |
| 124 | + type: RW |
| 125 | + definedBy: U |
| 126 | + description: | |
| 127 | + 0 (exception):: ebreak instructions in U-mode behave as described in the Privileged Spec. |
| 128 | + 1 (debug mode):: ebreak instructions in U-mode enter Debug Mode. |
| 129 | + This bit is hardwired to 0 if the hart does not support U-mode. |
| 130 | + reset_value: 0 |
| 131 | + STEPIE: |
| 132 | + location: 11 |
| 133 | + description: | |
| 134 | + 0 (interrupts disabled):: Interrupts (including NMI) are disabled during single stepping with step set. |
| 135 | + This value should be supported. |
| 136 | + 1 (interrupts enabled):: Interrupts (including NMI) are enabled during single stepping with step set. |
| 137 | + Implementations may hard wire this bit to 0. In that case interrupt behavior can be emulated by the |
| 138 | + debugger. The debugger must not change the value of this bit while the hart is running. |
| 139 | + type(): | |
| 140 | + if (DCSR_STEPIE_TYPE == "read-only-0" || DCSR_STEPIE_TYPE == "read-only-1") { |
| 141 | + return CsrFieldType::RO; |
| 142 | + } |
| 143 | + assert(DCSR_STEPIE_TYPE == "rw", "Unhandled DCSR_STEPIE_TYPE value"); |
| 144 | + return CsrFieldType::RW; |
| 145 | + reset_value(): | |
| 146 | + if (DCSR_STEPIE_TYPE == "read-only-0") { |
| 147 | + return 0; |
| 148 | + } else if (DCSR_STEPIE_TYPE == "read-only-1") { |
| 149 | + return 1; |
| 150 | + } |
| 151 | + assert(DCSR_STEPIE_TYPE == "rw", "Unhandled DCSR_STEPIE_TYPE value"); |
| 152 | + return UNDEFINED_LEGAL; |
| 153 | + STOPCOUNT: |
| 154 | + location: 10 |
| 155 | + description: | |
| 156 | + 0 (normal):: Increment counters as usual. |
| 157 | + 1 (freeze):: Don’t increment any hart-local counters while in Debug Mode or on ebreak instructions |
| 158 | + that cause entry into Debug Mode. These counters include the instret CSR. On single-hart cores cycle |
| 159 | + should be stopped, but on multi-hart cores it must keep incrementing. |
| 160 | + An implementation may hardwire this bit to 0 or 1. |
| 161 | + type(): | |
| 162 | + if (DCSR_STOPCOUNT_TYPE == "read-only-0" || DCSR_STOPCOUNT_TYPE == "read-only-1") { |
| 163 | + return CsrFieldType::RO; |
| 164 | + } |
| 165 | + assert(DCSR_STOPCOUNT_TYPE == "rw", "Unhandled DCSR_STOPCOUNT_TYPE value"); |
| 166 | + return CsrFieldType::RW; |
| 167 | + reset_value(): | |
| 168 | + if (DCSR_STOPCOUNT_TYPE == "read-only-0") { |
| 169 | + return 0; |
| 170 | + } else if (DCSR_STOPCOUNT_TYPE == "read-only-1") { |
| 171 | + return 1; |
| 172 | + } |
| 173 | + assert(DCSR_STOPCOUNT_TYPE == "rw", "Unhandled DCSR_STOPCOUNT_TYPE value"); |
| 174 | + return UNDEFINED_LEGAL; |
| 175 | + STOPTIME: |
| 176 | + location: 9 |
| 177 | + description: | |
| 178 | + 0 (normal):: time continues to reflect mtime. |
| 179 | + 1 (freeze):: time is frozen at the time that Debug Mode was entered. When leaving Debug Mode, |
| 180 | + time will reflect the latest value of mtime again. |
| 181 | + While all harts have stoptime=1 and are in Debug Mode, mtime is allowed to stop incrementing. |
| 182 | + An implementation may hardwire this bit to 0 or 1. |
| 183 | + type(): | |
| 184 | + if (DCSR_STOPTIME_TYPE == "read-only-0" || DCSR_STOPTIME_TYPE == "read-only-1") { |
| 185 | + return CsrFieldType::RO; |
| 186 | + } |
| 187 | + assert(DCSR_STOPTIME_TYPE == "rw", "Unhandled DCSR_STOPTIME_TYPE value"); |
| 188 | + return CsrFieldType::RW; |
| 189 | + reset_value(): | |
| 190 | + if (DCSR_STOPTIME_TYPE == "read-only-0") { |
| 191 | + return 0; |
| 192 | + } else if (DCSR_STOPTIME_TYPE == "read-only-1") { |
| 193 | + return 1; |
| 194 | + } |
| 195 | + assert(DCSR_STOPTIME_TYPE == "rw", "Unhandled DCSR_STOPTIME_TYPE value"); |
| 196 | + return UNDEFINED_LEGAL; |
| 197 | + CAUSE: |
| 198 | + location: 8-6 |
| 199 | + type: RO |
| 200 | + description: | |
| 201 | + Explains why Debug Mode was entered. |
| 202 | + When there are multiple reasons to enter Debug Mode in a |
| 203 | + single cycle, hardware should set cause to the cause with |
| 204 | + the highest priority. |
| 205 | + 1 (ebreak):: An ebreak instruction was executed. |
| 206 | + 2 (trigger):: A Trigger Module trigger fired with action=1. |
| 207 | + 3 (haltreq):: The debugger requested entry to Debug Mode |
| 208 | + using haltreq. |
| 209 | + 4 (step):: The hart single stepped because step was set. |
| 210 | + 5 (resethaltreq):: The hart halted directly out of reset due to |
| 211 | + resethaltreq It is also acceptable to report 3 when this |
| 212 | + happens. |
| 213 | + 6 (group):: The hart halted because it’s part of a halt group. |
| 214 | + Harts may report 3 for this cause instead. |
| 215 | + 7 (other):: The hart halted for a reason other than the ones |
| 216 | + mentioned above. extcause may contain a more specific |
| 217 | + reason. |
| 218 | + reset_value: 0 |
| 219 | + V: |
| 220 | + location: 5 |
| 221 | + type: RW |
| 222 | + definedBy: H |
| 223 | + description: | |
| 224 | + Extends the prv field with the virtualization mode the hart was operating in |
| 225 | + when Debug Mode was entered. A debugger can change this value to change the |
| 226 | + hart’s virtualization mode when exiting Debug Mode. This bit is hardwired to 0 on harts |
| 227 | + that do not support virtualization mode. |
| 228 | + reset_value: 0 |
| 229 | + MPRVEN: |
| 230 | + location: 4 |
| 231 | + description: | |
| 232 | + 0 (disabled):: mprv in mstatus is ignored in Debug Mode. |
| 233 | + 1 (enabled):: mprv in mstatus takes effect in Debug Mode. |
| 234 | + Implementing this bit is optional. It may be tied to either 0 or 1. |
| 235 | + type(): | |
| 236 | + if (DCSR_MPRVEN_TYPE == "read-only-0" || DCSR_MPRVEN_TYPE == "read-only-1") { |
| 237 | + return CsrFieldType::RO; |
| 238 | + } |
| 239 | + assert(DCSR_MPRVEN_TYPE == "rw", "Unhandled DCSR_MPRVEN_TYPE value"); |
| 240 | + return CsrFieldType::RW; |
| 241 | + reset_value(): | |
| 242 | + if (DCSR_MPRVEN_TYPE == "read-only-0") { |
| 243 | + return 0; |
| 244 | + } else if (DCSR_MPRVEN_TYPE == "read-only-1") { |
| 245 | + return 1; |
| 246 | + } |
| 247 | + assert(DCSR_MPRVEN_TYPE == "rw", "Unhandled DCSR_MPRVEN_TYPE value"); |
| 248 | + return UNDEFINED_LEGAL; |
| 249 | + NMIP: |
| 250 | + location: 3 |
| 251 | + type: RO |
| 252 | + description: | |
| 253 | + When set, there is a Non-Maskable-Interrupt (NMI) pending for the hart. |
| 254 | + Since an NMI can indicate a hardware error condition, reliable debugging |
| 255 | + may no longer be possible once this bit becomes set. This is implementation-dependent. |
| 256 | + reset_value: 0 |
| 257 | + STEP: |
| 258 | + location: 2 |
| 259 | + type: RW |
| 260 | + description: | |
| 261 | + When set and not in Debug Mode, the hart will only execute a single instruction |
| 262 | + and then enter Debug Mode. |
| 263 | + The debugger must not change the value of this bit while the hart is running. |
| 264 | + reset_value: 0 |
| 265 | + PRV: |
| 266 | + location: 1-0 |
| 267 | + type: RW |
| 268 | + description: | |
| 269 | + Contains the privilege mode the hart was operating in when Debug Mode was entered. |
| 270 | + A debugger can change this value to change the hart’s privilege mode when exiting |
| 271 | + Debug Mode. |
| 272 | +
|
| 273 | + Not all privilege modes are supported on all harts. If the encoding written is not |
| 274 | + supported or the debugger is not allowed to change to it, the hart may change to any |
| 275 | + supported privilege mode. |
| 276 | + reset_value: 3 |
0 commit comments