1 |
60 |
zero_gravi |
<<<
|
2 |
|
|
:sectnums:
|
3 |
|
|
=== Control and Status Registers (CSRs)
|
4 |
|
|
|
5 |
|
|
The following table shows a summary of all available CSRs. The address field defines the CSR address for
|
6 |
|
|
the CSR access instructions. The *[ASM]* name can be used for (inline) assembly code and is directly
|
7 |
|
|
understood by the assembler/compiler. The *[C]* names are defined by the NEORV32 core library and can be
|
8 |
|
|
used as immediate in plain C code. The *R/W* column shows whether the CSR can be read and/or written.
|
9 |
|
|
The NEORV32-specific CSRs are mapped to the official "custom CSRs" CSR address space.
|
10 |
|
|
|
11 |
|
|
[IMPORTANT]
|
12 |
|
|
The CSRs, the CSR-related instructions as well as the complete exception/interrupt processing
|
13 |
|
|
system are only available when the `CPU_EXTENSION_RISCV_Zicsr` generic is _true_.
|
14 |
|
|
|
15 |
|
|
[IMPORTANT]
|
16 |
|
|
When trying to write to a read-only CSR (like the `time` CSR) or when trying to access a nonexistent
|
17 |
|
|
CSR or when trying to access a machine-mode CSR from less-privileged user-mode an
|
18 |
|
|
illegal instruction exception is raised.
|
19 |
|
|
|
20 |
|
|
[NOTE]
|
21 |
|
|
CSR reset value: Please note that most of the CSRs do *NOT* provide a dedicated reset. Hence,
|
22 |
|
|
these CSRs are not initialized by a hardware reset and keep an *UNDEFINED* value until they are
|
23 |
|
|
explicitly initialized by the software (normally, this is already done by the NEORV32-specific
|
24 |
|
|
`crt0.S` start-up code). For more information see section <<_cpu_hardware_reset>>.
|
25 |
|
|
|
26 |
|
|
**CSR Listing**
|
27 |
|
|
|
28 |
|
|
The description of each single CSR provides the following summary:
|
29 |
|
|
|
30 |
|
|
.CSR description
|
31 |
|
|
[cols="4,27,>7"]
|
32 |
|
|
[frame="topbot",grid="none"]
|
33 |
72 |
zero_gravi |
|=======================
|
34 |
60 |
zero_gravi |
| _Address_ | _Description_ | _ASM alias_
|
35 |
|
|
3+| Reset value: _CSR content after hardware reset_ (also see <<_cpu_hardware_reset>>)
|
36 |
|
|
3+| _Detailed description_
|
37 |
72 |
zero_gravi |
|=======================
|
38 |
60 |
zero_gravi |
|
39 |
|
|
.Not Implemented CSRs / CSR Bits
|
40 |
|
|
[IMPORTANT]
|
41 |
|
|
All CSR bits that are unused / not implemented / not shown are _hardwired to zero_. All CSRs that are not
|
42 |
|
|
implemented at all (and are not "disabled" using certain configuration generics) will trigger an exception on
|
43 |
|
|
access. The CSR that are implemented within the NEORV32 might cause an exception if they are disabled.
|
44 |
|
|
See the according CSR description for more information.
|
45 |
|
|
|
46 |
|
|
.Debug Mode CSRs
|
47 |
|
|
[IMPORTANT]
|
48 |
|
|
The _debug mode_ CSRs are not listed here since they are only accessible in debug mode and not during normal CPU operation.
|
49 |
|
|
See section <<_cpu_debug_mode_csrs>>.
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
<<<
|
53 |
|
|
// ####################################################################################################################
|
54 |
|
|
**CSR Listing Notes**
|
55 |
|
|
|
56 |
|
|
CSRs with the following notes ...
|
57 |
|
|
|
58 |
61 |
zero_gravi |
* `X`: _custom_ - have or are a custom CPU-specific extension (that is allowed by the RISC-V specs)
|
59 |
|
|
* `R`: _read-only_ - are read-only (in contrast to the originally specified r/w capability)
|
60 |
|
|
* `C`: _constrained_ - have a constrained compatibility, not all specified bits are implemented
|
61 |
60 |
zero_gravi |
|
62 |
|
|
.NEORV32 Control and Status Registers (CSRs)
|
63 |
69 |
zero_gravi |
[cols="<6,<11,<16,^3,<25,^3"]
|
64 |
60 |
zero_gravi |
[options="header"]
|
65 |
|
|
|=======================
|
66 |
61 |
zero_gravi |
| Address | Name [ASM] | Name [C] | R/W | Function | Note
|
67 |
60 |
zero_gravi |
6+^| **<<_floating_point_csrs>>**
|
68 |
|
|
| 0x001 | <<_fflags>> | _CSR_FFLAGS_ | r/w | Floating-point accrued exceptions |
|
69 |
|
|
| 0x002 | <<_frm>> | _CSR_FRM_ | r/w | Floating-point dynamic rounding mode |
|
70 |
|
|
| 0x003 | <<_fcsr>> | _CSR_FCSR_ | r/w | Floating-point control and status (`frm` + `fflags`) |
|
71 |
66 |
zero_gravi |
6+^| **<<_machine_configuration_csrs>>**
|
72 |
64 |
zero_gravi |
| 0x30a | <<_menvcfg>> | _CSR_MENVCFG_ | r/- | Machine environment configuration register - low word | `R`
|
73 |
|
|
| 0x31a | <<_menvcfgh>> | _CSR_MENVCFGH_ | r/- | Machine environment configuration register - low word | `R`
|
74 |
66 |
zero_gravi |
6+^| **<<_machine_trap_setup_csrs>>**
|
75 |
62 |
zero_gravi |
| 0x300 | <<_mstatus>> | _CSR_MSTATUS_ | r/w | Machine status register - low word | `C`
|
76 |
60 |
zero_gravi |
| 0x301 | <<_misa>> | _CSR_MISA_ | r/- | Machine CPU ISA and extensions | `R`
|
77 |
61 |
zero_gravi |
| 0x304 | <<_mie>> | _CSR_MIE_ | r/w | Machine interrupt enable register | `X`
|
78 |
60 |
zero_gravi |
| 0x305 | <<_mtvec>> | _CSR_MTVEC_ | r/w | Machine trap-handler base address (for ALL traps) |
|
79 |
61 |
zero_gravi |
| 0x306 | <<_mcounteren>> | _CSR_MCOUNTEREN_ | r/w | Machine counter-enable register | `C`
|
80 |
62 |
zero_gravi |
| 0x310 | <<_mstatush>> | _CSR_MSTATUSH_ | r/- | Machine status register - high word | `C`
|
81 |
66 |
zero_gravi |
6+^| **<<_machine_trap_handling_csrs>>**
|
82 |
60 |
zero_gravi |
| 0x340 | <<_mscratch>> | _CSR_MSCRATCH_ | r/w | Machine scratch register |
|
83 |
|
|
| 0x341 | <<_mepc>> | _CSR_MEPC_ | r/w | Machine exception program counter |
|
84 |
61 |
zero_gravi |
| 0x342 | <<_mcause>> | _CSR_MCAUSE_ | r/w | Machine trap cause | `X`
|
85 |
69 |
zero_gravi |
| 0x343 | <<_mtval>> | _CSR_MTVAL_ | r/- | Machine bad address or instruction | `R`
|
86 |
|
|
| 0x344 | <<_mip>> | _CSR_MIP_ | r/w | Machine interrupt pending register | `X`
|
87 |
66 |
zero_gravi |
6+^| **<<_machine_physical_memory_protection_csrs>>**
|
88 |
61 |
zero_gravi |
| 0x3a0 .. 0x3af | <<_pmpcfg, `pmpcfg0`>> .. <<_pmpcfg, `pmpcfg15`>> | _CSR_PMPCFG0_ .. _CSR_PMPCFG15_ | r/w | Physical memory protection config. for region 0..63 | `C`
|
89 |
60 |
zero_gravi |
| 0x3b0 .. 0x3ef | <<_pmpaddr, `pmpaddr0`>> .. <<_pmpaddr, `pmpaddr63`>> | _CSR_PMPADDR0_ .. _CSR_PMPADDR63_ | r/w | Physical memory protection addr. register region 0..63 |
|
90 |
66 |
zero_gravi |
6+^| **<<_machine_counter_and_timer_csrs>>**
|
91 |
61 |
zero_gravi |
| 0xb00 | <<_mcycleh, `mcycle`>> | _CSR_MCYCLE_ | r/w | Machine cycle counter low word |
|
92 |
64 |
zero_gravi |
| 0xb02 | <<_minstreth, `minstret`>> | _CSR_MINSTRET_ | r/w | Machine instruction-retired counter low word |
|
93 |
61 |
zero_gravi |
| 0xb80 | <<_mcycleh>> | _CSR_MCYCLE_ | r/w | Machine cycle counter high word |
|
94 |
|
|
| 0xb82 | <<_minstreth>> | _CSR_MINSTRET_ | r/w | Machine instruction-retired counter high word |
|
95 |
|
|
| 0xc00 | <<_cycleh, `cycle`>> | _CSR_CYCLE_ | r/- | Cycle counter low word |
|
96 |
|
|
| 0xc01 | <<_timeh, `time`>> | _CSR_TIME_ | r/- | System time (from MTIME) low word |
|
97 |
60 |
zero_gravi |
| 0xc02 | <<_instreth, `instret`>> | _CSR_INSTRET_ | r/- | Instruction-retired counter low word |
|
98 |
61 |
zero_gravi |
| 0xc80 | <<_cycleh>> | _CSR_CYCLEH_ | r/- | Cycle counter high word |
|
99 |
|
|
| 0xc81 | <<_timeh>> | _CSR_TIMEH_ | r/- | System time (from MTIME) high word |
|
100 |
|
|
| 0xc82 | <<_instreth>> | _CSR_INSTRETH_ | r/- | Instruction-retired counter high word |
|
101 |
66 |
zero_gravi |
6+^| **<<_hardware_performance_monitors_hpm_csrs>>**
|
102 |
61 |
zero_gravi |
| 0x323 .. 0x33f | <<_mhpmevent, `mhpmevent3`>> .. <<_mhpmevent, `mhpmevent31`>> | _CSR_MHPMEVENT3_ .. _CSR_MHPMEVENT31_ | r/w | Machine performance-monitoring event selector 3..31 | `X`
|
103 |
60 |
zero_gravi |
| 0xb03 .. 0xb1f | <<_mhpmcounterh, `mhpmcounter3`>> .. <<_mhpmcounterh, `mhpmcounter31`>> | _CSR_MHPMCOUNTER3_ .. _CSR_MHPMCOUNTER31_ | r/w | Machine performance-monitoring counter 3..31 low word |
|
104 |
|
|
| 0xb83 .. 0xb9f | <<_mhpmcounterh, `mhpmcounter3h`>> .. <<_mhpmcounterh, `mhpmcounter31h`>> | _CSR_MHPMCOUNTER3H_ .. _CSR_MHPMCOUNTER31H_ | r/w | Machine performance-monitoring counter 3..31 high word |
|
105 |
66 |
zero_gravi |
6+^| **<<_machine_counter_setup_csrs>>**
|
106 |
60 |
zero_gravi |
| 0x320 | <<_mcountinhibit>> | _CSR_MCOUNTINHIBIT_ | r/w | Machine counter-enable register |
|
107 |
66 |
zero_gravi |
6+^| **<<_machine_information_csrs>>**
|
108 |
62 |
zero_gravi |
| 0xf11 | <<_mvendorid>> | _CSR_MVENDORID_ | r/- | Vendor ID |
|
109 |
|
|
| 0xf12 | <<_marchid>> | _CSR_MARCHID_ | r/- | Architecture ID |
|
110 |
|
|
| 0xf13 | <<_mimpid>> | _CSR_MIMPID_ | r/- | Machine implementation ID / version |
|
111 |
|
|
| 0xf14 | <<_mhartid>> | _CSR_MHARTID_ | r/- | Machine thread ID |
|
112 |
|
|
| 0xf15 | <<_mconfigptr>> | _CSR_MCONFIGPTR_ | r/- | Machine configuration pointer register |
|
113 |
72 |
zero_gravi |
6+^| **<<_neorv32_specific_csrs>>**
|
114 |
|
|
| 0xfc0 | <<_mxisa>> | _CSR_MXISA_ | r/- | NEORV32-specific "extended" machine CPU ISA and extensions |
|
115 |
60 |
zero_gravi |
|=======================
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
<<<
|
120 |
|
|
// ####################################################################################################################
|
121 |
|
|
:sectnums:
|
122 |
|
|
==== Floating-Point CSRs
|
123 |
|
|
|
124 |
|
|
These CSRs are available if the `Zfinx` extensions is enabled (`CPU_EXTENSION_RISCV_Zfinx` is _true_).
|
125 |
|
|
Otherwise any access to the floating-point CSRs will raise an illegal instruction exception.
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
:sectnums!:
|
129 |
|
|
===== **`fflags`**
|
130 |
|
|
|
131 |
|
|
[cols="4,27,>7"]
|
132 |
|
|
[frame="topbot",grid="none"]
|
133 |
72 |
zero_gravi |
|=======================
|
134 |
60 |
zero_gravi |
| 0x001 | **Floating-point accrued exceptions** | `fflags`
|
135 |
|
|
3+| Reset value: _UNDEFINED_
|
136 |
|
|
3+| The `fflags` CSR is compatible to the RISC-V specifications. It shows the accrued ("accumulated")
|
137 |
|
|
exception flags in the lowest 5 bits. This CSR is only available if a floating-point CPU extension is enabled.
|
138 |
|
|
See the RISC-V ISA spec for more information.
|
139 |
72 |
zero_gravi |
|=======================
|
140 |
60 |
zero_gravi |
|
141 |
|
|
|
142 |
|
|
:sectnums!:
|
143 |
|
|
===== **`frm`**
|
144 |
|
|
|
145 |
|
|
[cols="4,27,>7"]
|
146 |
|
|
[frame="topbot",grid="none"]
|
147 |
72 |
zero_gravi |
|=======================
|
148 |
60 |
zero_gravi |
| 0x002 | **Floating-point dynamic rounding mode** | `frm`
|
149 |
|
|
3+| Reset value: _UNDEFINED_
|
150 |
|
|
3+| The `frm` CSR is compatible to the RISC-V specifications and is used to configure the rounding modes using
|
151 |
|
|
the lowest 3 bits. This CSR is only available if a floating-point CPU extension is enabled. See the RISC-V
|
152 |
|
|
ISA spec for more information.
|
153 |
72 |
zero_gravi |
|=======================
|
154 |
60 |
zero_gravi |
|
155 |
|
|
|
156 |
|
|
:sectnums!:
|
157 |
|
|
===== **`fcsr`**
|
158 |
|
|
|
159 |
|
|
[cols="4,27,>7"]
|
160 |
|
|
[frame="topbot",grid="none"]
|
161 |
72 |
zero_gravi |
|=======================
|
162 |
60 |
zero_gravi |
| 0x003 | **Floating-point control and status register** | `fcsr`
|
163 |
|
|
3+| Reset value: _UNDEFINED_
|
164 |
|
|
3+| The `fcsr` CSR is compatible to the RISC-V specifications. It provides combined read/write access to the
|
165 |
|
|
`fflags` and `frm` CSRs. This CSR is only available if a floating-point CPU extension is enabled. See the
|
166 |
|
|
RISC-V ISA spec for more information.
|
167 |
72 |
zero_gravi |
|=======================
|
168 |
60 |
zero_gravi |
|
169 |
|
|
|
170 |
|
|
<<<
|
171 |
|
|
// ####################################################################################################################
|
172 |
|
|
:sectnums:
|
173 |
66 |
zero_gravi |
==== Machine Configuration CSRs
|
174 |
64 |
zero_gravi |
|
175 |
|
|
:sectnums!:
|
176 |
|
|
===== **`menvcfg`**
|
177 |
|
|
|
178 |
|
|
[cols="4,27,>7"]
|
179 |
|
|
[frame="topbot",grid="none"]
|
180 |
72 |
zero_gravi |
|=======================
|
181 |
64 |
zero_gravi |
| 0x30a | **Machine environment configuration register** | `menvcfg`
|
182 |
|
|
3+| Reset value: _0x00000000_
|
183 |
|
|
3+| The features of this CSR are not implemented yet. The register is read-only. NOTE: This register
|
184 |
|
|
only exists if the `U` ISA extensions is enabled.
|
185 |
72 |
zero_gravi |
|=======================
|
186 |
64 |
zero_gravi |
|
187 |
|
|
|
188 |
|
|
:sectnums!:
|
189 |
|
|
===== **`menvcfgh`**
|
190 |
|
|
|
191 |
|
|
[cols="4,27,>7"]
|
192 |
|
|
[frame="topbot",grid="none"]
|
193 |
72 |
zero_gravi |
|=======================
|
194 |
64 |
zero_gravi |
| 0x31a | **Machine environment configuration register - high word** | `menvcfgh`
|
195 |
|
|
3+| Reset value: _0x00000000_
|
196 |
|
|
3+| The features of this CSR are not implemented yet. The register is read-only. NOTE: This register
|
197 |
|
|
only exists if the `U` ISA extensions is enabled.
|
198 |
72 |
zero_gravi |
|=======================
|
199 |
64 |
zero_gravi |
|
200 |
|
|
|
201 |
|
|
<<<
|
202 |
|
|
// ####################################################################################################################
|
203 |
|
|
:sectnums:
|
204 |
66 |
zero_gravi |
==== Machine Trap Setup CSRs
|
205 |
60 |
zero_gravi |
|
206 |
|
|
:sectnums!:
|
207 |
|
|
===== **`mstatus`**
|
208 |
|
|
|
209 |
|
|
[cols="4,27,>7"]
|
210 |
|
|
[frame="topbot",grid="none"]
|
211 |
72 |
zero_gravi |
|=======================
|
212 |
61 |
zero_gravi |
| 0x300 | **Machine status register** | `mstatus`
|
213 |
|
|
3+| Reset value: _0x00000000_
|
214 |
60 |
zero_gravi |
3+| The `mstatus` CSR is compatible to the RISC-V specifications. It shows the CPU's current execution state.
|
215 |
|
|
The following bits are implemented (all remaining bits are always zero and are read-only).
|
216 |
72 |
zero_gravi |
|=======================
|
217 |
60 |
zero_gravi |
|
218 |
|
|
.Machine status register
|
219 |
|
|
[cols="^1,<3,^1,<5"]
|
220 |
|
|
[options="header",grid="rows"]
|
221 |
|
|
|=======================
|
222 |
|
|
| Bit | Name [C] | R/W | Function
|
223 |
|
|
| 12:11 | _CSR_MSTATUS_MPP_H_ : _CSR_MSTATUS_MPP_L_ | r/w | Previous machine privilege level, 11 = machine (M) level, 00 = user (U) level
|
224 |
|
|
| 7 | _CSR_MSTATUS_MPIE_ | r/w | Previous machine global interrupt enable flag state
|
225 |
61 |
zero_gravi |
| 3 | _CSR_MSTATUS_MIE_ | r/w | Machine global interrupt enable flag
|
226 |
60 |
zero_gravi |
|=======================
|
227 |
|
|
|
228 |
|
|
When entering an exception/interrupt, the `MIE` flag is copied to `MPIE` and cleared afterwards. When leaving
|
229 |
|
|
the exception/interrupt (via the `mret` instruction), `MPIE` is copied back to `MIE`.
|
230 |
|
|
|
231 |
|
|
|
232 |
|
|
:sectnums!:
|
233 |
|
|
===== **`misa`**
|
234 |
|
|
|
235 |
|
|
[cols="4,27,>7"]
|
236 |
|
|
[frame="topbot",grid="none"]
|
237 |
72 |
zero_gravi |
|=======================
|
238 |
60 |
zero_gravi |
| 0x301 | **ISA and extensions** | `misa`
|
239 |
72 |
zero_gravi |
3+| Reset value: _defined_
|
240 |
60 |
zero_gravi |
3+| The `misa` CSR gives information about the actual CPU features. The lowest 26 bits show the implemented
|
241 |
|
|
CPU extensions. The following bits are implemented (all remaining bits are always zero and are read-only).
|
242 |
72 |
zero_gravi |
|=======================
|
243 |
60 |
zero_gravi |
|
244 |
|
|
[IMPORTANT]
|
245 |
|
|
The `misa` CSR is not fully RISC-V-compatible as it is read-only. Hence, implemented CPU
|
246 |
|
|
extensions cannot be switch on/off during runtime. For compatibility reasons any write access to this
|
247 |
64 |
zero_gravi |
CSR is simply ignored and will _NOT_ cause an illegal instruction exception.
|
248 |
60 |
zero_gravi |
|
249 |
|
|
.Machine ISA and extension register
|
250 |
|
|
[cols="^1,<3,^1,<5"]
|
251 |
|
|
[options="header",grid="rows"]
|
252 |
|
|
|=======================
|
253 |
|
|
| Bit | Name [C] | R/W | Function
|
254 |
|
|
| 31:30 | _CSR_MISA_MXL_HI_EXT_ : _CSR_MISA_MXL_LO_EXT_ | r/- | 32-bit architecture indicator (always _01_)
|
255 |
|
|
| 23 | _CSR_MISA_X_EXT_ | r/- | `X` extension bit is always set to indicate custom non-standard extensions
|
256 |
|
|
| 20 | _CSR_MISA_U_EXT_ | r/- | `U` CPU extension (user mode) available, set when _CPU_EXTENSION_RISCV_U_ enabled
|
257 |
|
|
| 12 | _CSR_MISA_M_EXT_ | r/- | `M` CPU extension (mul/div) available, set when _CPU_EXTENSION_RISCV_M_ enabled
|
258 |
|
|
| 8 | _CSR_MISA_I_EXT_ | r/- | `I` CPU base ISA, cleared when _CPU_EXTENSION_RISCV_E_ enabled
|
259 |
|
|
| 4 | _CSR_MISA_E_EXT_ | r/- | `E` CPU extension (embedded) available, set when _CPU_EXTENSION_RISCV_E_ enabled
|
260 |
|
|
| 2 | _CSR_MISA_C_EXT_ | r/- | `C` CPU extension (compressed instruction) available, set when _CPU_EXTENSION_RISCV_C_ enabled
|
261 |
|
|
| 0 | _CSR_MISA_A_EXT_ | r/- | `A` CPU extension (atomic memory access) available, set when _CPU_EXTENSION_RISCV_A_ enabled
|
262 |
|
|
|=======================
|
263 |
|
|
|
264 |
|
|
[TIP]
|
265 |
72 |
zero_gravi |
Machine-mode software can discover available `Z*` _sub-extensions_ (like `Zicsr` or `Zfinx`) by checking the NEORV32-specific
|
266 |
|
|
<<_mxisa>> CSR.
|
267 |
60 |
zero_gravi |
|
268 |
|
|
|
269 |
|
|
:sectnums!:
|
270 |
|
|
===== **`mie`**
|
271 |
|
|
|
272 |
|
|
[cols="4,27,>7"]
|
273 |
|
|
[frame="topbot",grid="none"]
|
274 |
72 |
zero_gravi |
|=======================
|
275 |
60 |
zero_gravi |
| 0x304 | **Machine interrupt-enable register** | `mie`
|
276 |
|
|
3+| Reset value: _UNDEFINED_
|
277 |
|
|
3+| The `mie` CSR is compatible to the RISC-V specifications and features custom extensions for the fast
|
278 |
|
|
interrupt channels. It is used to enabled specific interrupts sources. Please note that interrupts also have to be
|
279 |
|
|
globally enabled via the `CSR_MSTATUS_MIE` flag of the `mstatus` CSR. The following bits are implemented
|
280 |
|
|
(all remaining bits are always zero and are read-only):
|
281 |
72 |
zero_gravi |
|=======================
|
282 |
60 |
zero_gravi |
|
283 |
|
|
.Machine ISA and extension register
|
284 |
|
|
[cols="^1,<3,^1,<5"]
|
285 |
|
|
[options="header",grid="rows"]
|
286 |
|
|
|=======================
|
287 |
|
|
| Bit | Name [C] | R/W | Function
|
288 |
|
|
| 31:16 | _CSR_MIE_FIRQ15E_ : _CSR_MIE_FIRQ0E_ | r/w | Fast interrupt channel 15..0 enable
|
289 |
|
|
| 11 | _CSR_MIE_MEIE_ | r/w | Machine _external_ interrupt enable
|
290 |
|
|
| 7 | _CSR_MIE_MTIE_ | r/w | Machine _timer_ interrupt enable (from _MTIME_)
|
291 |
|
|
| 3 | _CSR_MIE_MSIE_ | r/w | Machine _software_ interrupt enable
|
292 |
|
|
|=======================
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
:sectnums!:
|
296 |
|
|
===== **`mtvec`**
|
297 |
|
|
|
298 |
|
|
[cols="4,27,>7"]
|
299 |
|
|
[frame="topbot",grid="none"]
|
300 |
72 |
zero_gravi |
|=======================
|
301 |
60 |
zero_gravi |
| 0x305 | **Machine trap-handler base address** | `mtvec`
|
302 |
|
|
3+| Reset value: _UNDEFINED_
|
303 |
|
|
3+| The `mtvec` CSR is compatible to the RISC-V specifications. It stores the base address for ALL machine
|
304 |
|
|
traps. Thus, it defines the main entry point for exception/interrupt handling regardless of the actual trap
|
305 |
64 |
zero_gravi |
source. The lowest two bits of this register are always zero and cannot be modified (= address mode only).
|
306 |
72 |
zero_gravi |
|=======================
|
307 |
60 |
zero_gravi |
|
308 |
|
|
.Machine trap-handler base address
|
309 |
|
|
[cols="^1,^1,<8"]
|
310 |
|
|
[options="header",grid="rows"]
|
311 |
|
|
|=======================
|
312 |
|
|
| Bit | R/W | Function
|
313 |
|
|
| 31:2 | r/w | 4-byte aligned base address of trap base handler
|
314 |
|
|
| 1:0 | r/- | Always zero
|
315 |
|
|
|=======================
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
:sectnums!:
|
319 |
|
|
===== **`mcounteren`**
|
320 |
|
|
|
321 |
|
|
[cols="4,27,>7"]
|
322 |
|
|
[frame="topbot",grid="none"]
|
323 |
72 |
zero_gravi |
|=======================
|
324 |
60 |
zero_gravi |
| 0x306 | **Machine counter enable** | `mcounteren`
|
325 |
|
|
3+| Reset value: _UNDEFINED_
|
326 |
|
|
3+| The `mcounteren` CSR is compatible to the RISC-V specifications. The bits of this CSR define which
|
327 |
|
|
counter/timer CSR can be accessed (read) from code running in a less-privileged modes. For example,
|
328 |
61 |
zero_gravi |
if user-level code tries to read from a counter/timer CSR without enabled access, an illegal instruction
|
329 |
64 |
zero_gravi |
exception is raised. NOTE: If the `U` ISA extension is not enabled this CSR does not exist.
|
330 |
72 |
zero_gravi |
|=======================
|
331 |
60 |
zero_gravi |
|
332 |
|
|
.Machine counter enable register
|
333 |
|
|
[cols="^1,<3,^1,<5"]
|
334 |
|
|
[options="header",grid="rows"]
|
335 |
|
|
|=======================
|
336 |
|
|
| Bit | Name [C] | R/W | Function
|
337 |
64 |
zero_gravi |
| 31:3 | `0` | r/- | Always zero: user-level code is **not** allowed to read HPM counters
|
338 |
60 |
zero_gravi |
| 2 | _CSR_MCOUNTEREN_IR_ | r/w | User-level code is allowed to read `cycle[h]` CSRs when set
|
339 |
|
|
| 1 | _CSR_MCOUNTEREN_TM_ | r/w | User-level code is allowed to read `time[h]` CSRs when set
|
340 |
|
|
| 0 | _CSR_MCOUNTEREN_CY_ | r/w | User-level code is allowed to read `instret[h]` CSRs when set
|
341 |
|
|
|=======================
|
342 |
|
|
|
343 |
|
|
|
344 |
62 |
zero_gravi |
:sectnums!:
|
345 |
|
|
===== **`mstatush`**
|
346 |
|
|
|
347 |
|
|
[cols="4,27,>7"]
|
348 |
|
|
[frame="topbot",grid="none"]
|
349 |
72 |
zero_gravi |
|=======================
|
350 |
62 |
zero_gravi |
| 0x310 | **Machine status register - high word** | `mstatush`
|
351 |
|
|
3+| Reset value: _0x00000000_
|
352 |
|
|
3+| The `mstatush` CSR is compatible to the RISC-V specifications. In combination with <<_mstatus>> it shows additional
|
353 |
|
|
execution state information. The NEORV32 `mstatush` CSR is read-only and all bits are hardwired to zero.
|
354 |
72 |
zero_gravi |
|=======================
|
355 |
62 |
zero_gravi |
|
356 |
|
|
[NOTE]
|
357 |
|
|
The NEORV32 `mstatush` CSR is not a physical register. All write access are ignored and all read accesses will always
|
358 |
|
|
return zero. However, any access will not raise an illegal instruction exception. The CSR address is implemented
|
359 |
|
|
in order to comply with the RISC-V privilege architecture specs.
|
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
60 |
zero_gravi |
<<<
|
364 |
|
|
// ####################################################################################################################
|
365 |
|
|
:sectnums:
|
366 |
66 |
zero_gravi |
==== Machine Trap Handling CSRs
|
367 |
60 |
zero_gravi |
|
368 |
|
|
:sectnums!:
|
369 |
|
|
===== **`mscratch`**
|
370 |
|
|
|
371 |
|
|
[cols="4,27,>7"]
|
372 |
|
|
[frame="topbot",grid="none"]
|
373 |
72 |
zero_gravi |
|=======================
|
374 |
60 |
zero_gravi |
| 0x340 | **Scratch register for machine trap handlers** | `mscratch`
|
375 |
|
|
3+| Reset value: _UNDEFINED_
|
376 |
|
|
3+| The `mscratch` CSR is compatible to the RISC-V specifications. It is a general purpose scratch register that
|
377 |
|
|
can be used by the exception/interrupt handler. The content pf this register after reset is undefined.
|
378 |
72 |
zero_gravi |
|=======================
|
379 |
60 |
zero_gravi |
|
380 |
|
|
:sectnums!:
|
381 |
|
|
===== **`mepc`**
|
382 |
|
|
|
383 |
|
|
[cols="4,27,>7"]
|
384 |
|
|
[frame="topbot",grid="none"]
|
385 |
72 |
zero_gravi |
|=======================
|
386 |
60 |
zero_gravi |
| 0x341 | **Machine exception program counter** | `mepc`
|
387 |
|
|
3+| Reset value: _UNDEFINED_
|
388 |
|
|
3+| The `mepc` CSR is compatible to the RISC-V specifications. For exceptions (like an illegal instruction) this
|
389 |
|
|
register provides the address of the exception-causing instruction. For Interrupt (like a machine timer
|
390 |
|
|
interrupt) this register provides the address of the next not-yet-executed instruction.
|
391 |
72 |
zero_gravi |
|=======================
|
392 |
60 |
zero_gravi |
|
393 |
|
|
:sectnums!:
|
394 |
|
|
===== **`mcause`**
|
395 |
|
|
|
396 |
|
|
[cols="4,27,>7"]
|
397 |
|
|
[frame="topbot",grid="none"]
|
398 |
72 |
zero_gravi |
|=======================
|
399 |
60 |
zero_gravi |
| 0x342 | **Machine trap cause** | `mcause`
|
400 |
|
|
3+| Reset value: _UNDEFINED_
|
401 |
|
|
3+| The `mcause` CSR is compatible to the RISC-V specifications. It show the cause ID for a taken exception.
|
402 |
72 |
zero_gravi |
|=======================
|
403 |
60 |
zero_gravi |
|
404 |
|
|
.Machine trap cause register
|
405 |
|
|
[cols="^1,^1,<8"]
|
406 |
|
|
[options="header",grid="rows"]
|
407 |
|
|
|=======================
|
408 |
|
|
| Bit | R/W | Function
|
409 |
|
|
| 31 | r/w | `1` if the trap is caused by an interrupt (`0` if the trap is caused by an exception)
|
410 |
|
|
| 30:5 | r/- | _Reserved_, read as zero
|
411 |
|
|
| 4:0 | r/w | Trap ID, see <<_neorv32_trap_listing>>
|
412 |
|
|
|=======================
|
413 |
|
|
|
414 |
|
|
:sectnums!:
|
415 |
|
|
===== **`mtval`**
|
416 |
|
|
|
417 |
|
|
[cols="4,27,>7"]
|
418 |
|
|
[frame="topbot",grid="none"]
|
419 |
72 |
zero_gravi |
|=======================
|
420 |
60 |
zero_gravi |
| 0x343 | **Machine bad address or instruction** | `mtval`
|
421 |
|
|
3+| Reset value: _UNDEFINED_
|
422 |
|
|
3+| The `mtval` CSR is compatible to the RISC-V specifications. When a trap is triggered, the CSR shows either
|
423 |
|
|
the faulting address (for misaligned/faulting load/stores/fetch) or the faulting instruction itself (for illegal
|
424 |
|
|
instructions). For interrupts the CSR is set to zero.
|
425 |
72 |
zero_gravi |
|=======================
|
426 |
60 |
zero_gravi |
|
427 |
|
|
.Machine bad address or instruction register
|
428 |
|
|
[cols="^5,^5"]
|
429 |
|
|
[options="header",grid="rows"]
|
430 |
|
|
|=======================
|
431 |
|
|
| Trap cause | `mtval` content
|
432 |
|
|
| misaligned instruction fetch address or instruction fetch access fault | address of faulting instruction fetch
|
433 |
|
|
| breakpoint | program counter (= address) of faulting instruction itself
|
434 |
|
|
| misaligned load address, load access fault, misaligned store address or store access fault | program counter (= address) of faulting instruction itself
|
435 |
|
|
| illegal instruction | actual instruction word of faulting instruction
|
436 |
|
|
| anything else including interrupts | _0x00000000_ (always zero)
|
437 |
|
|
|=======================
|
438 |
|
|
|
439 |
|
|
[IMPORTAN]
|
440 |
64 |
zero_gravi |
The NEORV32 `mtval` CSR is read-only. However, a write access will _NOT_ raise an illegal instruction exception.
|
441 |
60 |
zero_gravi |
|
442 |
|
|
:sectnums!:
|
443 |
|
|
===== **`mip`**
|
444 |
|
|
|
445 |
|
|
[cols="4,27,>7"]
|
446 |
|
|
[frame="topbot",grid="none"]
|
447 |
72 |
zero_gravi |
|=======================
|
448 |
60 |
zero_gravi |
| 0x344 | **Machine interrupt Pending** | `mip`
|
449 |
|
|
3+| Reset value: _0x00000000_
|
450 |
65 |
zero_gravi |
3+| The `mip` CSR is compatible to the RISC-V specifications and also provides custom extensions. It shows currently _pending_ interrupts.
|
451 |
69 |
zero_gravi |
The bits for the standard RISC-V interrupts are read-only. Hence, these interrupts cannot be cleared using the `mip` register and must
|
452 |
|
|
be cleared/acknowledged within the according interrupt-generating device.
|
453 |
|
|
The upper 16 bits represent the status of the CPU's fast interrupt request lines (FIRQ). Once triggered, these _have to be cleared_ again by setting
|
454 |
|
|
the according `mip` bit in the interrupt handler routine to clear the current interrupt request.
|
455 |
72 |
zero_gravi |
|=======================
|
456 |
60 |
zero_gravi |
|
457 |
|
|
.Machine interrupt pending register
|
458 |
|
|
[cols="^1,<3,^1,<5"]
|
459 |
|
|
[options="header",grid="rows"]
|
460 |
|
|
|=======================
|
461 |
|
|
| Bit | Name [C] | R/W | Function
|
462 |
69 |
zero_gravi |
| 31:16 | _CSR_MIP_FIRQ15P_ : _CSR_MIP_FIRQ0P_ | r/w | fast interrupt channel 15..0 pending; cleared request by writing 1
|
463 |
|
|
| 11 | _CSR_MIP_MEIP_ | r/- | machine _external_ interrupt pending; _cleared by user-defined mechanism_
|
464 |
|
|
| 7 | _CSR_MIP_MTIP_ | r/- | machine _timer_ interrupt pending; cleared by incrementing MTIME's time compare register
|
465 |
|
|
| 3 | _CSR_MIP_MSIP_ | r/- | machine _software_ interrupt pending; _cleared by user-defined mechanism_
|
466 |
60 |
zero_gravi |
|=======================
|
467 |
|
|
|
468 |
|
|
|
469 |
|
|
<<<
|
470 |
|
|
// ####################################################################################################################
|
471 |
|
|
:sectnums:
|
472 |
66 |
zero_gravi |
==== Machine Physical Memory Protection CSRs
|
473 |
60 |
zero_gravi |
|
474 |
|
|
The available physical memory protection logic is configured via the _PMP_NUM_REGIONS_ and
|
475 |
|
|
_PMP_MIN_GRANULARITY_ top entity generics. _PMP_NUM_REGIONS_ defines the number of implemented
|
476 |
|
|
protection regions and thus, the availability of the according `pmpcfg*` and `pmpaddr*` CSRs.
|
477 |
|
|
|
478 |
70 |
zero_gravi |
[NOTE]
|
479 |
60 |
zero_gravi |
If trying to access an PMP-related CSR beyond _PMP_NUM_REGIONS_ **no illegal instruction
|
480 |
|
|
exception** is triggered. The according CSRs are read-only (writes are ignored) and always return zero.
|
481 |
|
|
|
482 |
|
|
[IMPORTANT]
|
483 |
70 |
zero_gravi |
The RISC-V-compatible NEORV32 physical memory protection only implements the **NAPOT**
|
484 |
|
|
(naturally aligned power-of-two region) mode yet with a minimal region granularity of 8 bytes.
|
485 |
60 |
zero_gravi |
|
486 |
|
|
|
487 |
|
|
:sectnums!:
|
488 |
|
|
===== **`pmpcfg`**
|
489 |
|
|
|
490 |
|
|
[cols="4,27,>7"]
|
491 |
|
|
[frame="topbot",grid="none"]
|
492 |
72 |
zero_gravi |
|=======================
|
493 |
60 |
zero_gravi |
| 0x3a0 - 0x3af| **Physical memory protection configuration registers** | `pmpcfg0` - `pmpcfg15`
|
494 |
|
|
3+| Reset value: _0x00000000_
|
495 |
|
|
3+| The `pmpcfg*` CSRs are compatible to the RISC-V specifications. They are used to configure the protected
|
496 |
|
|
regions, where each `pmpcfg*` CSR provides configuration bits for four regions. The following bits (for the
|
497 |
|
|
first PMP configuration entry) are implemented (all remaining bits are always zero and are read-only):
|
498 |
72 |
zero_gravi |
|=======================
|
499 |
60 |
zero_gravi |
|
500 |
|
|
.Physical memory protection configuration register entry
|
501 |
|
|
[cols="^1,^3,^1,<11"]
|
502 |
|
|
[options="header",grid="rows"]
|
503 |
|
|
|=======================
|
504 |
|
|
| Bit | RISC-V name | R/W | Function
|
505 |
70 |
zero_gravi |
| 7 | _L_ | r/w | lock bit, can only be cleared by CPU reset
|
506 |
60 |
zero_gravi |
| 6:5 | - | r/- | reserved, read as zero
|
507 |
|
|
| 4:3 | _A_ | r/w | mode configuration; only OFF (`00`) and NAPOT (`11`) are supported
|
508 |
|
|
| 2 | _X_ | r/w | execute permission
|
509 |
|
|
| 1 | _W_ | r/w | write permission
|
510 |
|
|
| 0 | _R_ | r/w | read permission
|
511 |
|
|
|=======================
|
512 |
|
|
|
513 |
|
|
|
514 |
|
|
:sectnums!:
|
515 |
|
|
===== **`pmpaddr`**
|
516 |
|
|
|
517 |
|
|
[cols="4,27,>7"]
|
518 |
|
|
[frame="topbot",grid="none"]
|
519 |
72 |
zero_gravi |
|=======================
|
520 |
70 |
zero_gravi |
| 0x3b0 - 0x3ef| **Physical memory protection address registers** | `pmpaddr0` - `pmpaddr63`
|
521 |
60 |
zero_gravi |
3+| Reset value: _UNDEFINED_
|
522 |
70 |
zero_gravi |
3+| The `pmpaddr*` CSRs are compatible to the RISC-V specifications. They are used to configure the PMP region's base
|
523 |
60 |
zero_gravi |
address and the region size.
|
524 |
72 |
zero_gravi |
|=======================
|
525 |
60 |
zero_gravi |
|
526 |
|
|
[NOTE]
|
527 |
|
|
When configuring PMP make sure to set `pmpaddr*` before activating the according region via
|
528 |
|
|
`pmpcfg*`. When changing the PMP configuration, deactivate the according region via `pmpcfg*`
|
529 |
|
|
before modifying `pmpaddr*`.
|
530 |
|
|
|
531 |
|
|
|
532 |
|
|
<<<
|
533 |
|
|
// ####################################################################################################################
|
534 |
|
|
:sectnums:
|
535 |
66 |
zero_gravi |
==== (Machine) Counter and Timer CSRs
|
536 |
60 |
zero_gravi |
|
537 |
66 |
zero_gravi |
The (machine) counters and timers are implemented when the `Zicntr` ISA extensions is enabled (default)
|
538 |
|
|
via the <<_cpu_extension_riscv_zicntr>> generic.
|
539 |
|
|
|
540 |
64 |
zero_gravi |
[NOTE]
|
541 |
61 |
zero_gravi |
The <<_cpu_cnt_width>> generic defines the total size of the CPU's <<_cycleh>> and <<_instreth>>
|
542 |
|
|
/ <<_mcycleh>> and <<_minstreth>>
|
543 |
64 |
zero_gravi |
counter CSRs (low and high words combined); the time CSRs are not affected by this generic. Note that any
|
544 |
61 |
zero_gravi |
configuration with <<_cpu_cnt_width>> less than 64 is not RISC-V compliant.
|
545 |
60 |
zero_gravi |
|
546 |
64 |
zero_gravi |
.Effective CPU counter width (`[m]cycle` & `[m]instret`)
|
547 |
60 |
zero_gravi |
[IMPORTANT]
|
548 |
|
|
If _CPU_CNT_WIDTH_ is less than 64 (the default value) and greater than or equal 32, the according
|
549 |
|
|
MSBs of `[m]cycleh` and `[m]instreth` are read-only and always read as zero. This configuration
|
550 |
72 |
zero_gravi |
will also set the _CSR_MXISA_ZXSCNT_ flag ("small counters") in the <<_mxisa>> CSR. +
|
551 |
61 |
zero_gravi |
+
|
552 |
64 |
zero_gravi |
If _CPU_CNT_WIDTH_ is less than 32 and greater than 0, the `[m]cycleh` and `[m]instreth` CSRs are hardwired to zero
|
553 |
|
|
and any write access to them is ignored. Furthermore, the according MSBs of `[m]cycle` and `[m]instret` are read-only
|
554 |
72 |
zero_gravi |
and always read as zero. This configuration will also set the _CSR_MXISA_ZXSCNT_ flag ("small counters") in
|
555 |
|
|
the <<_mxisa>> CSR. +
|
556 |
61 |
zero_gravi |
+
|
557 |
64 |
zero_gravi |
If _CPU_CNT_WIDTH_ is 0, the <<_cycleh>> and <<_instreth>> / <<_mcycleh>> and <<_minstreth>> CSRs are hardwired to zero
|
558 |
66 |
zero_gravi |
and any write access to them is ignored.
|
559 |
60 |
zero_gravi |
|
560 |
72 |
zero_gravi |
.Counter Increment During Debugging
|
561 |
|
|
[NOTE]
|
562 |
|
|
The `[m]cycle[h]` and `[m]instret[h]` counters do not increment when the CPU is in debug mode.
|
563 |
|
|
See section <<_cpu_debug_mode>> for more information.
|
564 |
60 |
zero_gravi |
|
565 |
72 |
zero_gravi |
|
566 |
60 |
zero_gravi |
:sectnums!:
|
567 |
|
|
===== **`cycle[h]`**
|
568 |
|
|
|
569 |
|
|
[cols="4,27,>7"]
|
570 |
|
|
[frame="topbot",grid="none"]
|
571 |
72 |
zero_gravi |
|=======================
|
572 |
60 |
zero_gravi |
| 0xc00 | **Cycle counter - low word** | `cycle`
|
573 |
|
|
| 0xc80 | **Cycle counter - high word** | `cycleh`
|
574 |
|
|
3+| Reset value: _UNDEFINED_
|
575 |
|
|
3+| The `cycle[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit cycle
|
576 |
|
|
counter. The `cycle[h]` CSR is a read-only shadowed copy of the `mcycle[h]` CSR.
|
577 |
72 |
zero_gravi |
|=======================
|
578 |
60 |
zero_gravi |
|
579 |
|
|
|
580 |
|
|
:sectnums!:
|
581 |
|
|
===== **`time[h]`**
|
582 |
|
|
|
583 |
|
|
[cols="4,27,>7"]
|
584 |
|
|
[frame="topbot",grid="none"]
|
585 |
72 |
zero_gravi |
|=======================
|
586 |
60 |
zero_gravi |
| 0xc01 | **System time - low word** | `time`
|
587 |
|
|
| 0xc81 | **System time - high word** | `timeh`
|
588 |
|
|
3+| Reset value: _UNDEFINED_
|
589 |
|
|
3+| The `time[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit system
|
590 |
|
|
time. The system time is either generated by the processor-internal _MTIME_ system timer unit (if _IO_MTIME_EN_ = _true_) or can be provided by an
|
591 |
|
|
external timer unit via the processor's `mtime_i` signal (if _IO_MTIME_EN_ = _false_).
|
592 |
|
|
CSR is read-only. Change the system time via the _MTIME_ unit.
|
593 |
72 |
zero_gravi |
|=======================
|
594 |
60 |
zero_gravi |
|
595 |
|
|
|
596 |
|
|
:sectnums!:
|
597 |
|
|
===== **`instret[h]`**
|
598 |
|
|
|
599 |
|
|
[cols="4,27,>7"]
|
600 |
|
|
[frame="topbot",grid="none"]
|
601 |
72 |
zero_gravi |
|=======================
|
602 |
60 |
zero_gravi |
| 0xc02 | **Instructions-retired counter - low word** | `instret`
|
603 |
|
|
| 0xc82 | **Instructions-retired counter - high word** | `instreth`
|
604 |
|
|
3+| Reset value: _UNDEFINED_
|
605 |
|
|
3+| The `instret[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit retired
|
606 |
|
|
instructions counter. The `instret[h]` CSR is a read-only shadowed copy of the `minstret[h]` CSR.
|
607 |
72 |
zero_gravi |
|=======================
|
608 |
60 |
zero_gravi |
|
609 |
|
|
|
610 |
|
|
:sectnums!:
|
611 |
|
|
===== **`mcycle[h]`**
|
612 |
|
|
|
613 |
|
|
[cols="4,27,>7"]
|
614 |
|
|
[frame="topbot",grid="none"]
|
615 |
72 |
zero_gravi |
|=======================
|
616 |
60 |
zero_gravi |
| 0xb00 | **Machine cycle counter - low word** | `mcycle`
|
617 |
|
|
| 0xb80 | **Machine cycle counter - high word** | `mcycleh`
|
618 |
|
|
3+| Reset value: _UNDEFINED_
|
619 |
|
|
3+| The `mcycle[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit cycle
|
620 |
70 |
zero_gravi |
counter. The `mcycle[h]` CSR can also be written when in machine mode and is mirrored to the `cycle[h]` CSR.
|
621 |
72 |
zero_gravi |
|=======================
|
622 |
60 |
zero_gravi |
|
623 |
|
|
|
624 |
|
|
:sectnums!:
|
625 |
|
|
===== **`minstret[h]`**
|
626 |
|
|
|
627 |
|
|
[cols="4,27,>7"]
|
628 |
|
|
[frame="topbot",grid="none"]
|
629 |
72 |
zero_gravi |
|=======================
|
630 |
60 |
zero_gravi |
| 0xb02 | **Machine instructions-retired counter - low word** | `minstret`
|
631 |
|
|
| 0xb82 | **Machine instructions-retired counter - high word** | `minstreth`
|
632 |
|
|
3+| Reset value: _UNDEFINED_
|
633 |
|
|
3+| The `minstret[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit retired
|
634 |
70 |
zero_gravi |
instructions counter. The `minstret[h]` CSR also be written when in machine mode and is mirrored to the `instret[h]` CSR.
|
635 |
72 |
zero_gravi |
|=======================
|
636 |
60 |
zero_gravi |
|
637 |
|
|
|
638 |
|
|
|
639 |
|
|
<<<
|
640 |
|
|
// ####################################################################################################################
|
641 |
|
|
:sectnums:
|
642 |
66 |
zero_gravi |
==== Hardware Performance Monitors (HPM) CSRs
|
643 |
60 |
zero_gravi |
|
644 |
66 |
zero_gravi |
The hardware performance monitor CSRs are implemented when the `Zihpm` ISA extension is enabled via the
|
645 |
|
|
<<_cpu_extension_riscv_zihpm>> generic.
|
646 |
60 |
zero_gravi |
|
647 |
66 |
zero_gravi |
The actually implemented hardware performance logic is configured via the <<_hpm_num_cnts>> top entity generic,
|
648 |
|
|
which defines the number of implemented performance monitors. Note that always all 28 HPM counter and configuration registers
|
649 |
|
|
(`mhpmcounter*[h]` and `mhpmevent*`) are implemented, but only the actually configured ones are real registers and
|
650 |
|
|
not hardwired to zero.
|
651 |
|
|
|
652 |
|
|
[TIP]
|
653 |
|
|
If trying to access an HPM-related CSR beyond <<_hpm_num_cnts>> **no illegal instruction exception is
|
654 |
|
|
triggered**. The according CSRs are read-only (writes are ignored) and always return zero.
|
655 |
|
|
|
656 |
61 |
zero_gravi |
[IMPORTANT]
|
657 |
66 |
zero_gravi |
The HPM system only allows machine-mode access. Hence, `hpmcounter*[h]` CSR are not implemented
|
658 |
61 |
zero_gravi |
and any access (even) from machine mode will raise an exception. Furthermore, the according bits of <<_mcounteren>>
|
659 |
|
|
used to configure user-mode access to `hpmcounter*[h]` are hard-wired to zero.
|
660 |
60 |
zero_gravi |
|
661 |
66 |
zero_gravi |
The total counter width of the HPMs can be configured before synthesis via the <<_hpm_cnt_width>> generic (0..64-bit).
|
662 |
61 |
zero_gravi |
|
663 |
60 |
zero_gravi |
[NOTE]
|
664 |
|
|
The total LSB-aligned HPM counter size (low word CSR + high word CSR) is defined via the
|
665 |
61 |
zero_gravi |
<<_hpm_num_cnts>> generic (0..64-bit). If <<_hpm_num_cnts>> is less than 64, all unused MSB-aligned
|
666 |
60 |
zero_gravi |
bits are hardwired to zero.
|
667 |
|
|
|
668 |
|
|
|
669 |
72 |
zero_gravi |
.Counter Increment During Debugging
|
670 |
|
|
[NOTE]
|
671 |
|
|
All HPM counters do not increment when the CPU is in debug mode.
|
672 |
|
|
See section <<_cpu_debug_mode>> for more information.
|
673 |
|
|
|
674 |
|
|
|
675 |
60 |
zero_gravi |
:sectnums!:
|
676 |
|
|
===== **`mhpmevent`**
|
677 |
|
|
|
678 |
|
|
[cols="4,27,>7"]
|
679 |
|
|
[frame="topbot",grid="none"]
|
680 |
72 |
zero_gravi |
|=======================
|
681 |
60 |
zero_gravi |
| 0x232 -0x33f | **Machine hardware performance monitor event selector** | `mhpmevent3` - `mhpmevent31`
|
682 |
|
|
3+| Reset value: _UNDEFINED_
|
683 |
|
|
3+| The `mhpmevent*` CSRs are compatible to the RISC-V specifications. The configuration of these CSR define
|
684 |
62 |
zero_gravi |
the architectural events that cause the according `mhpmcounter*[h]` counters to increment. All available events are
|
685 |
60 |
zero_gravi |
listed in the table below. If more than one event is selected, the according counter will increment if any of
|
686 |
|
|
the enabled events is observed (logical OR). Note that the counter will only increment by 1 step per clock
|
687 |
|
|
cycle even if more than one event is observed. If the CPU is in sleep mode, no HPM counter will increment
|
688 |
|
|
at all.
|
689 |
72 |
zero_gravi |
|=======================
|
690 |
60 |
zero_gravi |
|
691 |
|
|
The available hardware performance logic is configured via the _HPM_NUM_CNTS_ top entity generic.
|
692 |
|
|
_HPM_NUM_CNTS_ defines the number of implemented performance monitors and thus, the availability of the
|
693 |
62 |
zero_gravi |
according `mhpmcounter*[h]` and `mhpmevent*` CSRs.
|
694 |
60 |
zero_gravi |
|
695 |
|
|
.HPM event selector
|
696 |
|
|
[cols="^1,<3,^1,<5"]
|
697 |
|
|
[options="header",grid="rows"]
|
698 |
|
|
|=======================
|
699 |
61 |
zero_gravi |
| Bit | Name [C] | R/W | Event
|
700 |
|
|
| 0 | _HPMCNT_EVENT_CY_ | r/w | active clock cycle (not in sleep)
|
701 |
|
|
| 1 | - | r/- | _not implemented, always read as zero_
|
702 |
|
|
| 2 | _HPMCNT_EVENT_IR_ | r/w | retired instruction
|
703 |
|
|
| 3 | _HPMCNT_EVENT_CIR_ | r/w | retired compressed instruction
|
704 |
60 |
zero_gravi |
| 4 | _HPMCNT_EVENT_WAIT_IF_ | r/w | instruction fetch memory wait cycle (if more than 1 cycle memory latency)
|
705 |
|
|
| 5 | _HPMCNT_EVENT_WAIT_II_ | r/w | instruction issue pipeline wait cycle (if more than 1 cycle latency), caused by pipelines flushes (like taken branches)
|
706 |
|
|
| 6 | _HPMCNT_EVENT_WAIT_MC_ | r/w | multi-cycle ALU operation wait cycle
|
707 |
61 |
zero_gravi |
| 7 | _HPMCNT_EVENT_LOAD_ | r/w | load operation
|
708 |
|
|
| 8 | _HPMCNT_EVENT_STORE_ | r/w | store operation
|
709 |
60 |
zero_gravi |
| 9 | _HPMCNT_EVENT_WAIT_LS_ | r/w | load/store memory wait cycle (if more than 1 cycle memory latency)
|
710 |
61 |
zero_gravi |
| 10 | _HPMCNT_EVENT_JUMP_ | r/w | unconditional jump
|
711 |
|
|
| 11 | _HPMCNT_EVENT_BRANCH_ | r/w | conditional branch (taken or not taken)
|
712 |
60 |
zero_gravi |
| 12 | _HPMCNT_EVENT_TBRANCH_ | r/w | taken conditional branch
|
713 |
61 |
zero_gravi |
| 13 | _HPMCNT_EVENT_TRAP_ | r/w | entered trap
|
714 |
60 |
zero_gravi |
| 14 | _HPMCNT_EVENT_ILLEGAL_ | r/w | illegal instruction exception
|
715 |
|
|
|=======================
|
716 |
|
|
|
717 |
|
|
|
718 |
|
|
:sectnums!:
|
719 |
|
|
===== **`mhpmcounter[h]`**
|
720 |
|
|
|
721 |
|
|
[cols="4,27,>7"]
|
722 |
|
|
[frame="topbot",grid="none"]
|
723 |
72 |
zero_gravi |
|=======================
|
724 |
60 |
zero_gravi |
| 0xb03 - 0xb1f | **Machine hardware performance monitor - counter low** | `mhpmcounter3` - `mhpmcounter31`
|
725 |
|
|
| 0xb83 - 0xb9f | **Machine hardware performance monitor - counter high** | `mhpmcounter3h` - `mhpmcounter31h`
|
726 |
|
|
3+| Reset value: _UNDEFINED_
|
727 |
|
|
3+| The `mhpmcounter*[h]` CSRs are compatible to the RISC-V specifications. These CSRs provide the lower/upper 32-
|
728 |
61 |
zero_gravi |
bit of arbitrary event counters. The event(s) that trigger an increment of theses counters are selected via the according
|
729 |
|
|
`mhpmevent*` CSRs bits.
|
730 |
72 |
zero_gravi |
|=======================
|
731 |
60 |
zero_gravi |
|
732 |
|
|
|
733 |
|
|
<<<
|
734 |
|
|
// ####################################################################################################################
|
735 |
|
|
:sectnums:
|
736 |
66 |
zero_gravi |
==== Machine Counter Setup CSRs
|
737 |
60 |
zero_gravi |
|
738 |
|
|
:sectnums!:
|
739 |
|
|
===== **`mcountinhibit`**
|
740 |
|
|
|
741 |
|
|
[cols="4,27,>7"]
|
742 |
|
|
[frame="topbot",grid="none"]
|
743 |
72 |
zero_gravi |
|=======================
|
744 |
60 |
zero_gravi |
| 0x320 | **Machine counter-inhibit register** | `mcountinhibit`
|
745 |
|
|
3+| Reset value: _UNDEFINED_
|
746 |
|
|
3+| The `mcountinhibit` CSR is compatible to the RISC-V specifications. The bits in this register define which
|
747 |
|
|
counter/timer CSR are allowed to perform an automatic increment. Automatic update is enabled if the
|
748 |
|
|
according bit in `mcountinhibit` is cleared. The following bits are implemented (all remaining bits are
|
749 |
|
|
always zero and are read-only).
|
750 |
72 |
zero_gravi |
|=======================
|
751 |
60 |
zero_gravi |
|
752 |
|
|
.Machine counter-inhibit register
|
753 |
|
|
[cols="^1,<3,^1,<5"]
|
754 |
|
|
[options="header",grid="rows"]
|
755 |
|
|
|=======================
|
756 |
|
|
| Bit | Name [C] | R/W | Event
|
757 |
|
|
| 0 | _CSR_MCOUNTINHIBIT_IR_ | r/w | the `[m]instret[h]` CSRs will auto-increment with each committed instruction when set
|
758 |
|
|
| 2 | _CSR_MCOUNTINHIBIT_IR_ | r/w | the `[m]cycle[h]` CSRs will auto-increment with each clock cycle (if CPU is not in sleep state) when set
|
759 |
62 |
zero_gravi |
| 3:31 | _CSR_MCOUNTINHIBIT_HPM3_ _: _CSR_MCOUNTINHIBIT_HPM31_ | r/w | the `mhpmcount*[h]` CSRs will auto-increment according to the configured `mhpmevent*` selector
|
760 |
60 |
zero_gravi |
|=======================
|
761 |
|
|
|
762 |
|
|
|
763 |
|
|
<<<
|
764 |
|
|
// ####################################################################################################################
|
765 |
|
|
:sectnums:
|
766 |
66 |
zero_gravi |
==== Machine Information CSRs
|
767 |
60 |
zero_gravi |
|
768 |
62 |
zero_gravi |
[NOTE]
|
769 |
|
|
All machine information registers can only be accessed in machine mode and are read-only.
|
770 |
60 |
zero_gravi |
|
771 |
|
|
:sectnums!:
|
772 |
|
|
===== **`mvendorid`**
|
773 |
|
|
|
774 |
|
|
[cols="4,27,>7"]
|
775 |
|
|
[frame="topbot",grid="none"]
|
776 |
72 |
zero_gravi |
|=======================
|
777 |
60 |
zero_gravi |
| 0xf11 | **Machine vendor ID** | `mvendorid`
|
778 |
|
|
3+| Reset value: _0x00000000_
|
779 |
|
|
3+| The `mvendorid` CSR is compatible to the RISC-V specifications. It is read-only and always reads zero.
|
780 |
72 |
zero_gravi |
|=======================
|
781 |
60 |
zero_gravi |
|
782 |
|
|
|
783 |
|
|
:sectnums!:
|
784 |
|
|
===== **`marchid`**
|
785 |
|
|
|
786 |
|
|
[cols="4,27,>7"]
|
787 |
|
|
[frame="topbot",grid="none"]
|
788 |
72 |
zero_gravi |
|=======================
|
789 |
60 |
zero_gravi |
| 0xf12 | **Machine architecture ID** | `marchid`
|
790 |
|
|
3+| Reset value: _0x00000013_
|
791 |
|
|
3+| The `marchid` CSR is compatible to the RISC-V specifications. It is read-only and shows the NEORV32
|
792 |
|
|
official _RISC-V open-source architecture ID_ (decimal: 19, 32-bit hexadecimal: 0x00000013).
|
793 |
72 |
zero_gravi |
|=======================
|
794 |
60 |
zero_gravi |
|
795 |
|
|
|
796 |
|
|
:sectnums!:
|
797 |
|
|
===== **`mimpid`**
|
798 |
|
|
|
799 |
|
|
[cols="4,27,>7"]
|
800 |
|
|
[frame="topbot",grid="none"]
|
801 |
72 |
zero_gravi |
|=======================
|
802 |
60 |
zero_gravi |
| 0xf13 | **Machine implementation ID** | `mimpid`
|
803 |
72 |
zero_gravi |
3+| Reset value: _defined_
|
804 |
60 |
zero_gravi |
3+| The `mimpid` CSR is compatible to the RISC-V specifications. It is read-only and shows the version of the
|
805 |
|
|
NEORV32 as BCD-coded number (example: `mimpid` = _0x01020312_ → 01.02.03.12 → version 1.2.3.12).
|
806 |
72 |
zero_gravi |
|=======================
|
807 |
60 |
zero_gravi |
|
808 |
|
|
|
809 |
|
|
:sectnums!:
|
810 |
|
|
===== **`mhartid`**
|
811 |
|
|
|
812 |
|
|
[cols="4,27,>7"]
|
813 |
|
|
[frame="topbot",grid="none"]
|
814 |
72 |
zero_gravi |
|=======================
|
815 |
60 |
zero_gravi |
| 0xf14 | **Machine hardware thread ID** | `mhartid`
|
816 |
72 |
zero_gravi |
3+| Reset value: _defined_
|
817 |
60 |
zero_gravi |
3+| The `mhartid` CSR is compatible to the RISC-V specifications. It is read-only and shows the core's hart ID,
|
818 |
|
|
which is assigned via the CPU's _HW_THREAD_ID_ generic.
|
819 |
72 |
zero_gravi |
|=======================
|
820 |
60 |
zero_gravi |
|
821 |
|
|
|
822 |
62 |
zero_gravi |
:sectnums!:
|
823 |
|
|
===== **`mconfigptr`**
|
824 |
60 |
zero_gravi |
|
825 |
62 |
zero_gravi |
[cols="4,27,>7"]
|
826 |
|
|
[frame="topbot",grid="none"]
|
827 |
72 |
zero_gravi |
|=======================
|
828 |
62 |
zero_gravi |
| 0xf15 | **Machine configuration pointer register** | `mconfigptr`
|
829 |
72 |
zero_gravi |
3+| Reset value: _0x00000000_
|
830 |
62 |
zero_gravi |
3+| This register holds a physical address (if not zero) that points to the base address of an architecture configuration structure.
|
831 |
|
|
Software can traverse this data structure to discover information about the harts, the platform, and their configuration.
|
832 |
|
|
**NOTE: Not assigned yet.**
|
833 |
72 |
zero_gravi |
|=======================
|
834 |
|
|
|
835 |
|
|
|
836 |
|
|
<<<
|
837 |
|
|
// ####################################################################################################################
|
838 |
|
|
:sectnums:
|
839 |
|
|
==== NEORV32-Specific CSRs
|
840 |
|
|
|
841 |
|
|
[NOTE]
|
842 |
|
|
All NEORV32-specific CSRs are mapped to addresses that are explicitly reserved for custom **Machine-Mode, read-only** CSRs
|
843 |
|
|
(assured by the RISC-V privileged specifications). Hence, these CSRs can only be accessed when in machine-mode. Any access
|
844 |
|
|
outside of machine-mode will raise an illegal instruction exception.
|
845 |
|
|
|
846 |
|
|
:sectnums!:
|
847 |
|
|
===== **`mxisa`**
|
848 |
|
|
|
849 |
|
|
[cols="4,27,>7"]
|
850 |
|
|
[frame="topbot",grid="none"]
|
851 |
|
|
|=======================
|
852 |
|
|
| 0x7c0 | **Machine EXTENDED ISA and Extensions register** | `mxisa`
|
853 |
|
|
3+| Reset value: _defined_
|
854 |
|
|
3+| NEORV32-specific read-only CSR that helps machine-mode software to discover `Z*` sub-extensions and CPU options.
|
855 |
|
|
|=======================
|
856 |
|
|
|
857 |
|
|
|
858 |
|
|
.Machine _EXTENDED_ ISA and Extensions register bits
|
859 |
|
|
[cols="^1,<3,^1,<5"]
|
860 |
|
|
[options="header",grid="rows"]
|
861 |
|
|
|=======================
|
862 |
|
|
| Bit | Name [C] | R/W | Function
|
863 |
|
|
| 31 | _CSR_MXISA_FASTSHIFT_ | r/- | fast shifts available when set (via top's <<_fast_shift_en>> generic)
|
864 |
|
|
| 30 | _CSR_MXISA_FASTMUL_ | r/- | fast multiplication available when set (via top's <<_fast_mul_en>> generic)
|
865 |
|
|
| 31:11 | - | r/- | _reserved_, read as zero
|
866 |
|
|
| 10 | _CSR_MXISA_DEBUGMODE_ | r/- | RISC-V CPU `debug_mode` available when set (via top's <<_on_chip_debugger_en>> generic)
|
867 |
|
|
| 9 | _CSR_MXISA_ZIHPM_ | r/- | `Zihpm` (hardware performance monitors) extension available when set (via top's <<_cpu_extension_riscv_zihpm>> generic)
|
868 |
|
|
| 8 | _CSR_MXISA_PMP_ | r/- | PMP` (physical memory protection) extension available when set (via top's <<_pmp_num_regions>> generic)
|
869 |
|
|
| 7 | _CSR_MXISA_ZICNTR_ | r/- | `Zicntr` extension (`I` sub-extension) available when set - `[m]cycle`, `[m]instret` and `[m]time` CSRs available when set (via top's <<_cpu_extension_riscv_zicntr>> generic)
|
870 |
|
|
| 6 | _CSR_MXISA_ZXSCNT_ | r/- | Custom extension - _Small_ CPU counters: `[m]cycle` & `[m]instret` CSRs have less than 64-bit when set (via top's <<_cpu_cnt_width>> generic)
|
871 |
|
|
| 5 | _CSR_MXISA_ZFINX_ | r/- | `Zfinx` extension (`F` sub-/alternative-extension: FPU using `x` registers) available when set (via top's <<_cpu_extension_riscv_zfinx>> generic)
|
872 |
|
|
| 4 | - | r/- | _reserved_, read as zero
|
873 |
|
|
| 3 | _CSR_MXISA_ZXCFU_ | r/- | `Zxcfu` extension (custom functions unit for custom RISC-V instructions) available when set (via top's <<_cpu_extension_riscv_zxcfu>> generic)
|
874 |
|
|
| 2 | _CSR_MXISA_ZMMUL_ | r/- | `Zmmul` extension (`M` sub-extension) available when set (via top's <<_cpu_extension_riscv_zmmul>> generic)
|
875 |
|
|
| 1 | _CSR_MXISA_ZIFENCEI_ | r/- | `Zifencei` extension (`I` sub-extension) available when set (via top's <<_cpu_extension_riscv_zifencei>> generic)
|
876 |
|
|
| 0 | _CSR_MXISA_ZICSR_ | r/- | `Zicsr` extension (`I` sub-extension) available when set (via top's <<_cpu_extension_riscv_zicsr>> generic)
|
877 |
|
|
|=======================
|