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 |
73 |
zero_gravi |
| 0x3a0 .. 0x3af | <<_pmpcfg, `pmpcfg0`>> .. <<_pmpcfg, `pmpcfg3`>> | _CSR_PMPCFG0_ .. _CSR_PMPCFG3_ | r/w | Physical memory protection config. for region 0..15 | `C`
|
89 |
|
|
| 0x3b0 .. 0x3ef | <<_pmpaddr, `pmpaddr0`>> .. <<_pmpaddr, `pmpaddr15`>> | _CSR_PMPADDR0_ .. _CSR_PMPADDR15_ | r/w | Physical memory protection addr. register region 0..15 |
|
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 |
73 |
zero_gravi |
| 21 | _CSR_MSTATUS_TW_ | r/w | **TW**: Disallows execution of `wfi` instruction in user mode when set; hardwired to zero if user-mode not implemented
|
224 |
|
|
| 12:11 | _CSR_MSTATUS_MPP_H_ : _CSR_MSTATUS_MPP_L_ | r/w | **MPP*: Previous machine privilege level, 11 = machine (M) level, 00 = user (U) level
|
225 |
|
|
| 7 | _CSR_MSTATUS_MPIE_ | r/w | **MPIE**: Previous machine global interrupt enable flag state
|
226 |
|
|
| 3 | _CSR_MSTATUS_MIE_ | r/w | **MIE**: Machine global interrupt enable flag
|
227 |
60 |
zero_gravi |
|=======================
|
228 |
|
|
|
229 |
|
|
When entering an exception/interrupt, the `MIE` flag is copied to `MPIE` and cleared afterwards. When leaving
|
230 |
|
|
the exception/interrupt (via the `mret` instruction), `MPIE` is copied back to `MIE`.
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
:sectnums!:
|
234 |
|
|
===== **`misa`**
|
235 |
|
|
|
236 |
|
|
[cols="4,27,>7"]
|
237 |
|
|
[frame="topbot",grid="none"]
|
238 |
72 |
zero_gravi |
|=======================
|
239 |
60 |
zero_gravi |
| 0x301 | **ISA and extensions** | `misa`
|
240 |
72 |
zero_gravi |
3+| Reset value: _defined_
|
241 |
60 |
zero_gravi |
3+| The `misa` CSR gives information about the actual CPU features. The lowest 26 bits show the implemented
|
242 |
|
|
CPU extensions. The following bits are implemented (all remaining bits are always zero and are read-only).
|
243 |
72 |
zero_gravi |
|=======================
|
244 |
60 |
zero_gravi |
|
245 |
|
|
[IMPORTANT]
|
246 |
|
|
The `misa` CSR is not fully RISC-V-compatible as it is read-only. Hence, implemented CPU
|
247 |
|
|
extensions cannot be switch on/off during runtime. For compatibility reasons any write access to this
|
248 |
64 |
zero_gravi |
CSR is simply ignored and will _NOT_ cause an illegal instruction exception.
|
249 |
60 |
zero_gravi |
|
250 |
|
|
.Machine ISA and extension register
|
251 |
|
|
[cols="^1,<3,^1,<5"]
|
252 |
|
|
[options="header",grid="rows"]
|
253 |
|
|
|=======================
|
254 |
|
|
| Bit | Name [C] | R/W | Function
|
255 |
73 |
zero_gravi |
| 31:30 | _CSR_MISA_MXL_HI_EXT_ : _CSR_MISA_MXL_LO_EXT_ | r/- | **MXL**: 32-bit architecture indicator (always _01_)
|
256 |
|
|
| 23 | _CSR_MISA_X_EXT_ | r/- | **X**: extension bit is always set to indicate custom non-standard extensions
|
257 |
|
|
| 20 | _CSR_MISA_U_EXT_ | r/- | **U**: CPU extension (user mode) available, set when _CPU_EXTENSION_RISCV_U_ enabled
|
258 |
|
|
| 12 | _CSR_MISA_M_EXT_ | r/- | **M**: CPU extension (mul/div) available, set when _CPU_EXTENSION_RISCV_M_ enabled
|
259 |
|
|
| 8 | _CSR_MISA_I_EXT_ | r/- | **I**: CPU base ISA, cleared when _CPU_EXTENSION_RISCV_E_ enabled
|
260 |
|
|
| 4 | _CSR_MISA_E_EXT_ | r/- | **E**: CPU extension (embedded) available, set when _CPU_EXTENSION_RISCV_E_ enabled
|
261 |
|
|
| 2 | _CSR_MISA_C_EXT_ | r/- | **C**: CPU extension (compressed instruction) available, set when _CPU_EXTENSION_RISCV_C_ enabled
|
262 |
|
|
| 0 | _CSR_MISA_A_EXT_ | r/- | **A**: CPU extension (atomic memory access) available, set when _CPU_EXTENSION_RISCV_A_ enabled
|
263 |
60 |
zero_gravi |
|=======================
|
264 |
|
|
|
265 |
|
|
[TIP]
|
266 |
72 |
zero_gravi |
Machine-mode software can discover available `Z*` _sub-extensions_ (like `Zicsr` or `Zfinx`) by checking the NEORV32-specific
|
267 |
|
|
<<_mxisa>> CSR.
|
268 |
60 |
zero_gravi |
|
269 |
|
|
|
270 |
|
|
:sectnums!:
|
271 |
|
|
===== **`mie`**
|
272 |
|
|
|
273 |
|
|
[cols="4,27,>7"]
|
274 |
|
|
[frame="topbot",grid="none"]
|
275 |
72 |
zero_gravi |
|=======================
|
276 |
60 |
zero_gravi |
| 0x304 | **Machine interrupt-enable register** | `mie`
|
277 |
|
|
3+| Reset value: _UNDEFINED_
|
278 |
|
|
3+| The `mie` CSR is compatible to the RISC-V specifications and features custom extensions for the fast
|
279 |
|
|
interrupt channels. It is used to enabled specific interrupts sources. Please note that interrupts also have to be
|
280 |
|
|
globally enabled via the `CSR_MSTATUS_MIE` flag of the `mstatus` CSR. The following bits are implemented
|
281 |
|
|
(all remaining bits are always zero and are read-only):
|
282 |
72 |
zero_gravi |
|=======================
|
283 |
60 |
zero_gravi |
|
284 |
|
|
.Machine ISA and extension register
|
285 |
|
|
[cols="^1,<3,^1,<5"]
|
286 |
|
|
[options="header",grid="rows"]
|
287 |
|
|
|=======================
|
288 |
|
|
| Bit | Name [C] | R/W | Function
|
289 |
|
|
| 31:16 | _CSR_MIE_FIRQ15E_ : _CSR_MIE_FIRQ0E_ | r/w | Fast interrupt channel 15..0 enable
|
290 |
73 |
zero_gravi |
| 11 | _CSR_MIE_MEIE_ | r/w | **MEIE**: Machine _external_ interrupt enable
|
291 |
|
|
| 7 | _CSR_MIE_MTIE_ | r/w | **MTIE**: Machine _timer_ interrupt enable (from _MTIME_)
|
292 |
|
|
| 3 | _CSR_MIE_MSIE_ | r/w | **MSIE**: Machine _software_ interrupt enable
|
293 |
60 |
zero_gravi |
|=======================
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
:sectnums!:
|
297 |
|
|
===== **`mtvec`**
|
298 |
|
|
|
299 |
|
|
[cols="4,27,>7"]
|
300 |
|
|
[frame="topbot",grid="none"]
|
301 |
72 |
zero_gravi |
|=======================
|
302 |
60 |
zero_gravi |
| 0x305 | **Machine trap-handler base address** | `mtvec`
|
303 |
|
|
3+| Reset value: _UNDEFINED_
|
304 |
|
|
3+| The `mtvec` CSR is compatible to the RISC-V specifications. It stores the base address for ALL machine
|
305 |
|
|
traps. Thus, it defines the main entry point for exception/interrupt handling regardless of the actual trap
|
306 |
64 |
zero_gravi |
source. The lowest two bits of this register are always zero and cannot be modified (= address mode only).
|
307 |
72 |
zero_gravi |
|=======================
|
308 |
60 |
zero_gravi |
|
309 |
|
|
.Machine trap-handler base address
|
310 |
|
|
[cols="^1,^1,<8"]
|
311 |
|
|
[options="header",grid="rows"]
|
312 |
|
|
|=======================
|
313 |
|
|
| Bit | R/W | Function
|
314 |
73 |
zero_gravi |
| 31:2 | r/w | **BASE**: 4-byte aligned base address of trap base handler
|
315 |
|
|
| 1:0 | r/- | **MODE**: Always zero; BASE defined entry for _all_ traps
|
316 |
60 |
zero_gravi |
|=======================
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
:sectnums!:
|
320 |
|
|
===== **`mcounteren`**
|
321 |
|
|
|
322 |
|
|
[cols="4,27,>7"]
|
323 |
|
|
[frame="topbot",grid="none"]
|
324 |
72 |
zero_gravi |
|=======================
|
325 |
60 |
zero_gravi |
| 0x306 | **Machine counter enable** | `mcounteren`
|
326 |
|
|
3+| Reset value: _UNDEFINED_
|
327 |
|
|
3+| The `mcounteren` CSR is compatible to the RISC-V specifications. The bits of this CSR define which
|
328 |
|
|
counter/timer CSR can be accessed (read) from code running in a less-privileged modes. For example,
|
329 |
61 |
zero_gravi |
if user-level code tries to read from a counter/timer CSR without enabled access, an illegal instruction
|
330 |
64 |
zero_gravi |
exception is raised. NOTE: If the `U` ISA extension is not enabled this CSR does not exist.
|
331 |
72 |
zero_gravi |
|=======================
|
332 |
60 |
zero_gravi |
|
333 |
|
|
.Machine counter enable register
|
334 |
|
|
[cols="^1,<3,^1,<5"]
|
335 |
|
|
[options="header",grid="rows"]
|
336 |
|
|
|=======================
|
337 |
|
|
| Bit | Name [C] | R/W | Function
|
338 |
64 |
zero_gravi |
| 31:3 | `0` | r/- | Always zero: user-level code is **not** allowed to read HPM counters
|
339 |
73 |
zero_gravi |
| 2 | _CSR_MCOUNTEREN_IR_ | r/w | **IR**: User-level code is allowed to read `cycle[h]` CSRs when set
|
340 |
|
|
| 1 | _CSR_MCOUNTEREN_TM_ | r/w | **TM**: User-level code is allowed to read `time[h]` CSRs when set
|
341 |
|
|
| 0 | _CSR_MCOUNTEREN_CY_ | r/w | **CY**: User-level code is allowed to read `instret[h]` CSRs when set
|
342 |
60 |
zero_gravi |
|=======================
|
343 |
|
|
|
344 |
73 |
zero_gravi |
.HPM Access
|
345 |
|
|
[NOTE]
|
346 |
|
|
Bits 3 to 31 are used to control user-level access to the <<_hardware_performance_monitors_hpm_csrs>>. In the NEORV32
|
347 |
|
|
CPU these bits are hardwired to zero. Hence, user-level software cannot access the HPMs. Accordingly, the
|
348 |
|
|
`pmcounter*[h]` CSRs are **not** implemented and any access will raise an illegal instruction exception.
|
349 |
60 |
zero_gravi |
|
350 |
73 |
zero_gravi |
|
351 |
62 |
zero_gravi |
:sectnums!:
|
352 |
|
|
===== **`mstatush`**
|
353 |
|
|
|
354 |
|
|
[cols="4,27,>7"]
|
355 |
|
|
[frame="topbot",grid="none"]
|
356 |
72 |
zero_gravi |
|=======================
|
357 |
62 |
zero_gravi |
| 0x310 | **Machine status register - high word** | `mstatush`
|
358 |
|
|
3+| Reset value: _0x00000000_
|
359 |
|
|
3+| The `mstatush` CSR is compatible to the RISC-V specifications. In combination with <<_mstatus>> it shows additional
|
360 |
|
|
execution state information. The NEORV32 `mstatush` CSR is read-only and all bits are hardwired to zero.
|
361 |
72 |
zero_gravi |
|=======================
|
362 |
62 |
zero_gravi |
|
363 |
|
|
|
364 |
|
|
|
365 |
60 |
zero_gravi |
<<<
|
366 |
|
|
// ####################################################################################################################
|
367 |
|
|
:sectnums:
|
368 |
66 |
zero_gravi |
==== Machine Trap Handling CSRs
|
369 |
60 |
zero_gravi |
|
370 |
|
|
:sectnums!:
|
371 |
|
|
===== **`mscratch`**
|
372 |
|
|
|
373 |
|
|
[cols="4,27,>7"]
|
374 |
|
|
[frame="topbot",grid="none"]
|
375 |
72 |
zero_gravi |
|=======================
|
376 |
60 |
zero_gravi |
| 0x340 | **Scratch register for machine trap handlers** | `mscratch`
|
377 |
|
|
3+| Reset value: _UNDEFINED_
|
378 |
|
|
3+| The `mscratch` CSR is compatible to the RISC-V specifications. It is a general purpose scratch register that
|
379 |
|
|
can be used by the exception/interrupt handler. The content pf this register after reset is undefined.
|
380 |
72 |
zero_gravi |
|=======================
|
381 |
60 |
zero_gravi |
|
382 |
|
|
:sectnums!:
|
383 |
|
|
===== **`mepc`**
|
384 |
|
|
|
385 |
|
|
[cols="4,27,>7"]
|
386 |
|
|
[frame="topbot",grid="none"]
|
387 |
72 |
zero_gravi |
|=======================
|
388 |
60 |
zero_gravi |
| 0x341 | **Machine exception program counter** | `mepc`
|
389 |
|
|
3+| Reset value: _UNDEFINED_
|
390 |
|
|
3+| The `mepc` CSR is compatible to the RISC-V specifications. For exceptions (like an illegal instruction) this
|
391 |
|
|
register provides the address of the exception-causing instruction. For Interrupt (like a machine timer
|
392 |
|
|
interrupt) this register provides the address of the next not-yet-executed instruction.
|
393 |
72 |
zero_gravi |
|=======================
|
394 |
60 |
zero_gravi |
|
395 |
|
|
:sectnums!:
|
396 |
|
|
===== **`mcause`**
|
397 |
|
|
|
398 |
|
|
[cols="4,27,>7"]
|
399 |
|
|
[frame="topbot",grid="none"]
|
400 |
72 |
zero_gravi |
|=======================
|
401 |
60 |
zero_gravi |
| 0x342 | **Machine trap cause** | `mcause`
|
402 |
|
|
3+| Reset value: _UNDEFINED_
|
403 |
|
|
3+| The `mcause` CSR is compatible to the RISC-V specifications. It show the cause ID for a taken exception.
|
404 |
72 |
zero_gravi |
|=======================
|
405 |
60 |
zero_gravi |
|
406 |
|
|
.Machine trap cause register
|
407 |
|
|
[cols="^1,^1,<8"]
|
408 |
|
|
[options="header",grid="rows"]
|
409 |
|
|
|=======================
|
410 |
|
|
| Bit | R/W | Function
|
411 |
73 |
zero_gravi |
| 31 | r/w | **Interrupt**: `1` if the trap is caused by an interrupt (`0` if the trap is caused by an exception)
|
412 |
60 |
zero_gravi |
| 30:5 | r/- | _Reserved_, read as zero
|
413 |
73 |
zero_gravi |
| 4:0 | r/w | **Trap ID**: see <<_neorv32_trap_listing>>
|
414 |
60 |
zero_gravi |
|=======================
|
415 |
|
|
|
416 |
|
|
:sectnums!:
|
417 |
|
|
===== **`mtval`**
|
418 |
|
|
|
419 |
|
|
[cols="4,27,>7"]
|
420 |
|
|
[frame="topbot",grid="none"]
|
421 |
72 |
zero_gravi |
|=======================
|
422 |
60 |
zero_gravi |
| 0x343 | **Machine bad address or instruction** | `mtval`
|
423 |
|
|
3+| Reset value: _UNDEFINED_
|
424 |
|
|
3+| The `mtval` CSR is compatible to the RISC-V specifications. When a trap is triggered, the CSR shows either
|
425 |
|
|
the faulting address (for misaligned/faulting load/stores/fetch) or the faulting instruction itself (for illegal
|
426 |
|
|
instructions). For interrupts the CSR is set to zero.
|
427 |
72 |
zero_gravi |
|=======================
|
428 |
60 |
zero_gravi |
|
429 |
|
|
.Machine bad address or instruction register
|
430 |
|
|
[cols="^5,^5"]
|
431 |
|
|
[options="header",grid="rows"]
|
432 |
|
|
|=======================
|
433 |
|
|
| Trap cause | `mtval` content
|
434 |
|
|
| misaligned instruction fetch address or instruction fetch access fault | address of faulting instruction fetch
|
435 |
|
|
| breakpoint | program counter (= address) of faulting instruction itself
|
436 |
|
|
| misaligned load address, load access fault, misaligned store address or store access fault | program counter (= address) of faulting instruction itself
|
437 |
|
|
| illegal instruction | actual instruction word of faulting instruction
|
438 |
|
|
| anything else including interrupts | _0x00000000_ (always zero)
|
439 |
|
|
|=======================
|
440 |
|
|
|
441 |
|
|
[IMPORTAN]
|
442 |
64 |
zero_gravi |
The NEORV32 `mtval` CSR is read-only. However, a write access will _NOT_ raise an illegal instruction exception.
|
443 |
60 |
zero_gravi |
|
444 |
|
|
:sectnums!:
|
445 |
|
|
===== **`mip`**
|
446 |
|
|
|
447 |
|
|
[cols="4,27,>7"]
|
448 |
|
|
[frame="topbot",grid="none"]
|
449 |
72 |
zero_gravi |
|=======================
|
450 |
60 |
zero_gravi |
| 0x344 | **Machine interrupt Pending** | `mip`
|
451 |
|
|
3+| Reset value: _0x00000000_
|
452 |
65 |
zero_gravi |
3+| The `mip` CSR is compatible to the RISC-V specifications and also provides custom extensions. It shows currently _pending_ interrupts.
|
453 |
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
|
454 |
|
|
be cleared/acknowledged within the according interrupt-generating device.
|
455 |
73 |
zero_gravi |
The upper 16 bits represent the status of the CPU's fast interrupt request lines (FIRQ). Once triggered, these bit have to be cleared manually by
|
456 |
|
|
writing zero to the according `mip` bits (in the interrupt handler routine) to clear the current interrupt request.
|
457 |
72 |
zero_gravi |
|=======================
|
458 |
60 |
zero_gravi |
|
459 |
|
|
.Machine interrupt pending register
|
460 |
|
|
[cols="^1,<3,^1,<5"]
|
461 |
|
|
[options="header",grid="rows"]
|
462 |
|
|
|=======================
|
463 |
|
|
| Bit | Name [C] | R/W | Function
|
464 |
73 |
zero_gravi |
| 31:16 | _CSR_MIP_FIRQ15P_ : _CSR_MIP_FIRQ0P_ | r/c | **FIRQxP**: Fast interrupt channel 15..0 pending; cleared request by writing 1
|
465 |
|
|
| 11 | _CSR_MIP_MEIP_ | r/- | **MEIP**: Machine _external_ interrupt pending; _cleared by user-defined mechanism_
|
466 |
|
|
| 7 | _CSR_MIP_MTIP_ | r/- | **MTIP**: Machine _timer_ interrupt pending; cleared by incrementing MTIME's time compare register
|
467 |
|
|
| 3 | _CSR_MIP_MSIP_ | r/- | **MSIP**: Machine _software_ interrupt pending; _cleared by user-defined mechanism_
|
468 |
60 |
zero_gravi |
|=======================
|
469 |
|
|
|
470 |
73 |
zero_gravi |
.FIRQ Channel Mapping
|
471 |
|
|
[TIP]
|
472 |
|
|
See section <<_neorv32_specific_fast_interrupt_requests>> for the mapping of the FIRQ channels and the according
|
473 |
|
|
interrupt-triggering processor module.
|
474 |
60 |
zero_gravi |
|
475 |
73 |
zero_gravi |
|
476 |
60 |
zero_gravi |
<<<
|
477 |
|
|
// ####################################################################################################################
|
478 |
|
|
:sectnums:
|
479 |
66 |
zero_gravi |
==== Machine Physical Memory Protection CSRs
|
480 |
60 |
zero_gravi |
|
481 |
73 |
zero_gravi |
The available physical memory protection logic is configured via the <<_pmp_num_regions>> and
|
482 |
|
|
<<_pmp_min_granularity>> top entity generics. <<_pmp_num_regions>> defines the number of implemented
|
483 |
|
|
protection regions and thus, the implementation of the available _PMP entries_. Each PMP entry consists of an
|
484 |
|
|
8-bit `pmpcfg` CSR entry and a complete `pmpaddr*` CSR.
|
485 |
|
|
See section <<_pmp_physical_memory_protection>> for more information.
|
486 |
60 |
zero_gravi |
|
487 |
70 |
zero_gravi |
[NOTE]
|
488 |
73 |
zero_gravi |
If trying to access an PMP-related CSR beyond <<_pmp_num_regions>> **no illegal instruction
|
489 |
60 |
zero_gravi |
exception** is triggered. The according CSRs are read-only (writes are ignored) and always return zero.
|
490 |
73 |
zero_gravi |
However, any access beyond `pmpcfg3` or `pmpaddr15`, which are the last physically implemented registers if
|
491 |
|
|
<<_pmp_num_regions>> == 16, will raise an illegal instruction exception as these CSRs are not implemented at all.
|
492 |
60 |
zero_gravi |
|
493 |
|
|
|
494 |
|
|
:sectnums!:
|
495 |
|
|
===== **`pmpcfg`**
|
496 |
|
|
|
497 |
|
|
[cols="4,27,>7"]
|
498 |
|
|
[frame="topbot",grid="none"]
|
499 |
72 |
zero_gravi |
|=======================
|
500 |
73 |
zero_gravi |
| 0x3a0 - 0x3a3| **Physical memory protection configuration registers** | `pmpcfg0` - `pmpcfg3`
|
501 |
60 |
zero_gravi |
3+| Reset value: _0x00000000_
|
502 |
|
|
3+| The `pmpcfg*` CSRs are compatible to the RISC-V specifications. They are used to configure the protected
|
503 |
73 |
zero_gravi |
regions, where each `pmpcfg*` CSR provides configuration bits for four regions (8-bit per region).
|
504 |
|
|
The actual number of available `pmpcfg` CSRs and CSR entries is defined by the <<_pmp_num_regions>> generic.
|
505 |
72 |
zero_gravi |
|=======================
|
506 |
60 |
zero_gravi |
|
507 |
73 |
zero_gravi |
.Physical memory protection configuration register layout (1 entry out of 4)
|
508 |
60 |
zero_gravi |
[cols="^1,^3,^1,<11"]
|
509 |
|
|
[options="header",grid="rows"]
|
510 |
|
|
|=======================
|
511 |
73 |
zero_gravi |
| Bit | Name [C] | R/W | Function
|
512 |
|
|
| 7 | _PMPCFG_L_ | r/w | **L**: Lock bit, prevents further write accesses, also enforces access rights in machine-mode, can only be cleared by CPU reset
|
513 |
|
|
| 6:5 | - | r/- | _reserved_, read as zero
|
514 |
|
|
| 4 | _PMPCFG_A_MSB_ | r/- .2+<| **A**: Mode configuration; only **OFF** (`00`) and **TOR** (`01`) modes are supported, any other value will map back to OFF/TOR
|
515 |
|
|
as the MSB is hardwired to zero
|
516 |
|
|
| 3 | _PMPCFG_A_LSB_ | r/w
|
517 |
|
|
| 2 | _PMPCFG_X_ | r/w | **X**: Execute permission
|
518 |
|
|
| 1 | _PMPCFG_W_ | r/w | **W**: Write permission
|
519 |
|
|
| 0 | _PMPCFG_R_ | r/w | **R**: Read permission
|
520 |
60 |
zero_gravi |
|=======================
|
521 |
|
|
|
522 |
73 |
zero_gravi |
[WARNING]
|
523 |
|
|
Setting the lock bit `L` **only locks the according PMP entry** and not the PMP entries below!
|
524 |
60 |
zero_gravi |
|
525 |
73 |
zero_gravi |
|
526 |
60 |
zero_gravi |
:sectnums!:
|
527 |
|
|
===== **`pmpaddr`**
|
528 |
|
|
|
529 |
|
|
[cols="4,27,>7"]
|
530 |
|
|
[frame="topbot",grid="none"]
|
531 |
72 |
zero_gravi |
|=======================
|
532 |
73 |
zero_gravi |
| 0x3b0 - 0x3bf| **Physical memory protection address registers** | `pmpaddr0` - `pmpaddr15`
|
533 |
60 |
zero_gravi |
3+| Reset value: _UNDEFINED_
|
534 |
73 |
zero_gravi |
3+| The `pmpaddr*` CSRs are compatible to the RISC-V specifications. They are used to configure bits 33:2 of the PMP region's
|
535 |
|
|
physical memory address. The actual number of available `pmpaddr` CSRs is defined by the <<_pmp_num_regions>> generic.
|
536 |
72 |
zero_gravi |
|=======================
|
537 |
60 |
zero_gravi |
|
538 |
73 |
zero_gravi |
.Physical memory protection address register layout
|
539 |
|
|
[cols="^6,^3,<7"]
|
540 |
|
|
[options="header",grid="rows"]
|
541 |
|
|
|=======================
|
542 |
|
|
| Bit | R/W | Function
|
543 |
|
|
| 31:30 | r/- | Hardwired to zero
|
544 |
|
|
| 29 : _log2(PMP_MIN_GRANULARITY)-2_ | r/w | Bits 31 downto _log2(PMP_MIN_GRANULARITY)_ of the region's address
|
545 |
|
|
| _log2(PMP_MIN_GRANULARITY)-2_ : 0 | r/- | Hardwired to zero
|
546 |
|
|
|=======================
|
547 |
|
|
|
548 |
60 |
zero_gravi |
[NOTE]
|
549 |
73 |
zero_gravi |
When configuring the PMP make sure to set `pmpaddr*` before activating the according region via
|
550 |
60 |
zero_gravi |
`pmpcfg*`. When changing the PMP configuration, deactivate the according region via `pmpcfg*`
|
551 |
|
|
before modifying `pmpaddr*`.
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
<<<
|
555 |
|
|
// ####################################################################################################################
|
556 |
|
|
:sectnums:
|
557 |
66 |
zero_gravi |
==== (Machine) Counter and Timer CSRs
|
558 |
60 |
zero_gravi |
|
559 |
66 |
zero_gravi |
The (machine) counters and timers are implemented when the `Zicntr` ISA extensions is enabled (default)
|
560 |
|
|
via the <<_cpu_extension_riscv_zicntr>> generic.
|
561 |
|
|
|
562 |
64 |
zero_gravi |
[NOTE]
|
563 |
61 |
zero_gravi |
The <<_cpu_cnt_width>> generic defines the total size of the CPU's <<_cycleh>> and <<_instreth>>
|
564 |
|
|
/ <<_mcycleh>> and <<_minstreth>>
|
565 |
64 |
zero_gravi |
counter CSRs (low and high words combined); the time CSRs are not affected by this generic. Note that any
|
566 |
61 |
zero_gravi |
configuration with <<_cpu_cnt_width>> less than 64 is not RISC-V compliant.
|
567 |
60 |
zero_gravi |
|
568 |
64 |
zero_gravi |
.Effective CPU counter width (`[m]cycle` & `[m]instret`)
|
569 |
60 |
zero_gravi |
[IMPORTANT]
|
570 |
|
|
If _CPU_CNT_WIDTH_ is less than 64 (the default value) and greater than or equal 32, the according
|
571 |
|
|
MSBs of `[m]cycleh` and `[m]instreth` are read-only and always read as zero. This configuration
|
572 |
72 |
zero_gravi |
will also set the _CSR_MXISA_ZXSCNT_ flag ("small counters") in the <<_mxisa>> CSR. +
|
573 |
61 |
zero_gravi |
+
|
574 |
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
|
575 |
|
|
and any write access to them is ignored. Furthermore, the according MSBs of `[m]cycle` and `[m]instret` are read-only
|
576 |
72 |
zero_gravi |
and always read as zero. This configuration will also set the _CSR_MXISA_ZXSCNT_ flag ("small counters") in
|
577 |
|
|
the <<_mxisa>> CSR. +
|
578 |
61 |
zero_gravi |
+
|
579 |
64 |
zero_gravi |
If _CPU_CNT_WIDTH_ is 0, the <<_cycleh>> and <<_instreth>> / <<_mcycleh>> and <<_minstreth>> CSRs are hardwired to zero
|
580 |
66 |
zero_gravi |
and any write access to them is ignored.
|
581 |
60 |
zero_gravi |
|
582 |
72 |
zero_gravi |
.Counter Increment During Debugging
|
583 |
|
|
[NOTE]
|
584 |
|
|
The `[m]cycle[h]` and `[m]instret[h]` counters do not increment when the CPU is in debug mode.
|
585 |
|
|
See section <<_cpu_debug_mode>> for more information.
|
586 |
60 |
zero_gravi |
|
587 |
72 |
zero_gravi |
|
588 |
60 |
zero_gravi |
:sectnums!:
|
589 |
|
|
===== **`cycle[h]`**
|
590 |
|
|
|
591 |
|
|
[cols="4,27,>7"]
|
592 |
|
|
[frame="topbot",grid="none"]
|
593 |
72 |
zero_gravi |
|=======================
|
594 |
60 |
zero_gravi |
| 0xc00 | **Cycle counter - low word** | `cycle`
|
595 |
|
|
| 0xc80 | **Cycle counter - high word** | `cycleh`
|
596 |
|
|
3+| Reset value: _UNDEFINED_
|
597 |
|
|
3+| The `cycle[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit cycle
|
598 |
|
|
counter. The `cycle[h]` CSR is a read-only shadowed copy of the `mcycle[h]` CSR.
|
599 |
72 |
zero_gravi |
|=======================
|
600 |
60 |
zero_gravi |
|
601 |
|
|
|
602 |
|
|
:sectnums!:
|
603 |
|
|
===== **`time[h]`**
|
604 |
|
|
|
605 |
|
|
[cols="4,27,>7"]
|
606 |
|
|
[frame="topbot",grid="none"]
|
607 |
72 |
zero_gravi |
|=======================
|
608 |
60 |
zero_gravi |
| 0xc01 | **System time - low word** | `time`
|
609 |
|
|
| 0xc81 | **System time - high word** | `timeh`
|
610 |
|
|
3+| Reset value: _UNDEFINED_
|
611 |
|
|
3+| The `time[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit system
|
612 |
|
|
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
|
613 |
|
|
external timer unit via the processor's `mtime_i` signal (if _IO_MTIME_EN_ = _false_).
|
614 |
|
|
CSR is read-only. Change the system time via the _MTIME_ unit.
|
615 |
72 |
zero_gravi |
|=======================
|
616 |
60 |
zero_gravi |
|
617 |
|
|
|
618 |
|
|
:sectnums!:
|
619 |
|
|
===== **`instret[h]`**
|
620 |
|
|
|
621 |
|
|
[cols="4,27,>7"]
|
622 |
|
|
[frame="topbot",grid="none"]
|
623 |
72 |
zero_gravi |
|=======================
|
624 |
60 |
zero_gravi |
| 0xc02 | **Instructions-retired counter - low word** | `instret`
|
625 |
|
|
| 0xc82 | **Instructions-retired counter - high word** | `instreth`
|
626 |
|
|
3+| Reset value: _UNDEFINED_
|
627 |
|
|
3+| The `instret[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit retired
|
628 |
|
|
instructions counter. The `instret[h]` CSR is a read-only shadowed copy of the `minstret[h]` CSR.
|
629 |
72 |
zero_gravi |
|=======================
|
630 |
60 |
zero_gravi |
|
631 |
|
|
|
632 |
|
|
:sectnums!:
|
633 |
|
|
===== **`mcycle[h]`**
|
634 |
|
|
|
635 |
|
|
[cols="4,27,>7"]
|
636 |
|
|
[frame="topbot",grid="none"]
|
637 |
72 |
zero_gravi |
|=======================
|
638 |
60 |
zero_gravi |
| 0xb00 | **Machine cycle counter - low word** | `mcycle`
|
639 |
|
|
| 0xb80 | **Machine cycle counter - high word** | `mcycleh`
|
640 |
|
|
3+| Reset value: _UNDEFINED_
|
641 |
|
|
3+| The `mcycle[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit cycle
|
642 |
70 |
zero_gravi |
counter. The `mcycle[h]` CSR can also be written when in machine mode and is mirrored to the `cycle[h]` CSR.
|
643 |
72 |
zero_gravi |
|=======================
|
644 |
60 |
zero_gravi |
|
645 |
|
|
|
646 |
|
|
:sectnums!:
|
647 |
|
|
===== **`minstret[h]`**
|
648 |
|
|
|
649 |
|
|
[cols="4,27,>7"]
|
650 |
|
|
[frame="topbot",grid="none"]
|
651 |
72 |
zero_gravi |
|=======================
|
652 |
60 |
zero_gravi |
| 0xb02 | **Machine instructions-retired counter - low word** | `minstret`
|
653 |
|
|
| 0xb82 | **Machine instructions-retired counter - high word** | `minstreth`
|
654 |
|
|
3+| Reset value: _UNDEFINED_
|
655 |
|
|
3+| The `minstret[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit retired
|
656 |
70 |
zero_gravi |
instructions counter. The `minstret[h]` CSR also be written when in machine mode and is mirrored to the `instret[h]` CSR.
|
657 |
72 |
zero_gravi |
|=======================
|
658 |
60 |
zero_gravi |
|
659 |
|
|
|
660 |
|
|
|
661 |
|
|
<<<
|
662 |
|
|
// ####################################################################################################################
|
663 |
|
|
:sectnums:
|
664 |
66 |
zero_gravi |
==== Hardware Performance Monitors (HPM) CSRs
|
665 |
60 |
zero_gravi |
|
666 |
66 |
zero_gravi |
The hardware performance monitor CSRs are implemented when the `Zihpm` ISA extension is enabled via the
|
667 |
|
|
<<_cpu_extension_riscv_zihpm>> generic.
|
668 |
60 |
zero_gravi |
|
669 |
66 |
zero_gravi |
The actually implemented hardware performance logic is configured via the <<_hpm_num_cnts>> top entity generic,
|
670 |
|
|
which defines the number of implemented performance monitors. Note that always all 28 HPM counter and configuration registers
|
671 |
|
|
(`mhpmcounter*[h]` and `mhpmevent*`) are implemented, but only the actually configured ones are real registers and
|
672 |
|
|
not hardwired to zero.
|
673 |
|
|
|
674 |
|
|
[TIP]
|
675 |
|
|
If trying to access an HPM-related CSR beyond <<_hpm_num_cnts>> **no illegal instruction exception is
|
676 |
|
|
triggered**. The according CSRs are read-only (writes are ignored) and always return zero.
|
677 |
|
|
|
678 |
73 |
zero_gravi |
[NOTE]
|
679 |
66 |
zero_gravi |
The HPM system only allows machine-mode access. Hence, `hpmcounter*[h]` CSR are not implemented
|
680 |
61 |
zero_gravi |
and any access (even) from machine mode will raise an exception. Furthermore, the according bits of <<_mcounteren>>
|
681 |
|
|
used to configure user-mode access to `hpmcounter*[h]` are hard-wired to zero.
|
682 |
60 |
zero_gravi |
|
683 |
66 |
zero_gravi |
The total counter width of the HPMs can be configured before synthesis via the <<_hpm_cnt_width>> generic (0..64-bit).
|
684 |
61 |
zero_gravi |
|
685 |
60 |
zero_gravi |
[NOTE]
|
686 |
|
|
The total LSB-aligned HPM counter size (low word CSR + high word CSR) is defined via the
|
687 |
61 |
zero_gravi |
<<_hpm_num_cnts>> generic (0..64-bit). If <<_hpm_num_cnts>> is less than 64, all unused MSB-aligned
|
688 |
60 |
zero_gravi |
bits are hardwired to zero.
|
689 |
|
|
|
690 |
|
|
|
691 |
72 |
zero_gravi |
.Counter Increment During Debugging
|
692 |
|
|
[NOTE]
|
693 |
|
|
All HPM counters do not increment when the CPU is in debug mode.
|
694 |
|
|
See section <<_cpu_debug_mode>> for more information.
|
695 |
|
|
|
696 |
|
|
|
697 |
60 |
zero_gravi |
:sectnums!:
|
698 |
|
|
===== **`mhpmevent`**
|
699 |
|
|
|
700 |
|
|
[cols="4,27,>7"]
|
701 |
|
|
[frame="topbot",grid="none"]
|
702 |
72 |
zero_gravi |
|=======================
|
703 |
60 |
zero_gravi |
| 0x232 -0x33f | **Machine hardware performance monitor event selector** | `mhpmevent3` - `mhpmevent31`
|
704 |
|
|
3+| Reset value: _UNDEFINED_
|
705 |
|
|
3+| The `mhpmevent*` CSRs are compatible to the RISC-V specifications. The configuration of these CSR define
|
706 |
62 |
zero_gravi |
the architectural events that cause the according `mhpmcounter*[h]` counters to increment. All available events are
|
707 |
60 |
zero_gravi |
listed in the table below. If more than one event is selected, the according counter will increment if any of
|
708 |
|
|
the enabled events is observed (logical OR). Note that the counter will only increment by 1 step per clock
|
709 |
73 |
zero_gravi |
cycle even if more than one event is observed. If the CPU is in sleep or debug mode, no HPM counter will increment
|
710 |
60 |
zero_gravi |
at all.
|
711 |
72 |
zero_gravi |
|=======================
|
712 |
60 |
zero_gravi |
|
713 |
|
|
.HPM event selector
|
714 |
|
|
[cols="^1,<3,^1,<5"]
|
715 |
|
|
[options="header",grid="rows"]
|
716 |
|
|
|=======================
|
717 |
61 |
zero_gravi |
| Bit | Name [C] | R/W | Event
|
718 |
|
|
| 0 | _HPMCNT_EVENT_CY_ | r/w | active clock cycle (not in sleep)
|
719 |
|
|
| 1 | - | r/- | _not implemented, always read as zero_
|
720 |
73 |
zero_gravi |
| 2 | _HPMCNT_EVENT_IR_ | r/w | retired instruction (compressed or uncompressed)
|
721 |
61 |
zero_gravi |
| 3 | _HPMCNT_EVENT_CIR_ | r/w | retired compressed instruction
|
722 |
60 |
zero_gravi |
| 4 | _HPMCNT_EVENT_WAIT_IF_ | r/w | instruction fetch memory wait cycle (if more than 1 cycle memory latency)
|
723 |
|
|
| 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)
|
724 |
|
|
| 6 | _HPMCNT_EVENT_WAIT_MC_ | r/w | multi-cycle ALU operation wait cycle
|
725 |
73 |
zero_gravi |
| 7 | _HPMCNT_EVENT_LOAD_ | r/w | memory data load operation
|
726 |
|
|
| 8 | _HPMCNT_EVENT_STORE_ | r/w | memory data store operation
|
727 |
60 |
zero_gravi |
| 9 | _HPMCNT_EVENT_WAIT_LS_ | r/w | load/store memory wait cycle (if more than 1 cycle memory latency)
|
728 |
61 |
zero_gravi |
| 10 | _HPMCNT_EVENT_JUMP_ | r/w | unconditional jump
|
729 |
|
|
| 11 | _HPMCNT_EVENT_BRANCH_ | r/w | conditional branch (taken or not taken)
|
730 |
60 |
zero_gravi |
| 12 | _HPMCNT_EVENT_TBRANCH_ | r/w | taken conditional branch
|
731 |
73 |
zero_gravi |
| 13 | _HPMCNT_EVENT_TRAP_ | r/w | entered trap (synchronous exception or interrupt)
|
732 |
60 |
zero_gravi |
| 14 | _HPMCNT_EVENT_ILLEGAL_ | r/w | illegal instruction exception
|
733 |
|
|
|=======================
|
734 |
|
|
|
735 |
|
|
|
736 |
|
|
:sectnums!:
|
737 |
|
|
===== **`mhpmcounter[h]`**
|
738 |
|
|
|
739 |
|
|
[cols="4,27,>7"]
|
740 |
|
|
[frame="topbot",grid="none"]
|
741 |
72 |
zero_gravi |
|=======================
|
742 |
60 |
zero_gravi |
| 0xb03 - 0xb1f | **Machine hardware performance monitor - counter low** | `mhpmcounter3` - `mhpmcounter31`
|
743 |
|
|
| 0xb83 - 0xb9f | **Machine hardware performance monitor - counter high** | `mhpmcounter3h` - `mhpmcounter31h`
|
744 |
|
|
3+| Reset value: _UNDEFINED_
|
745 |
|
|
3+| The `mhpmcounter*[h]` CSRs are compatible to the RISC-V specifications. These CSRs provide the lower/upper 32-
|
746 |
61 |
zero_gravi |
bit of arbitrary event counters. The event(s) that trigger an increment of theses counters are selected via the according
|
747 |
|
|
`mhpmevent*` CSRs bits.
|
748 |
72 |
zero_gravi |
|=======================
|
749 |
60 |
zero_gravi |
|
750 |
|
|
|
751 |
|
|
<<<
|
752 |
|
|
// ####################################################################################################################
|
753 |
|
|
:sectnums:
|
754 |
66 |
zero_gravi |
==== Machine Counter Setup CSRs
|
755 |
60 |
zero_gravi |
|
756 |
|
|
:sectnums!:
|
757 |
|
|
===== **`mcountinhibit`**
|
758 |
|
|
|
759 |
|
|
[cols="4,27,>7"]
|
760 |
|
|
[frame="topbot",grid="none"]
|
761 |
72 |
zero_gravi |
|=======================
|
762 |
60 |
zero_gravi |
| 0x320 | **Machine counter-inhibit register** | `mcountinhibit`
|
763 |
|
|
3+| Reset value: _UNDEFINED_
|
764 |
|
|
3+| The `mcountinhibit` CSR is compatible to the RISC-V specifications. The bits in this register define which
|
765 |
|
|
counter/timer CSR are allowed to perform an automatic increment. Automatic update is enabled if the
|
766 |
|
|
according bit in `mcountinhibit` is cleared. The following bits are implemented (all remaining bits are
|
767 |
|
|
always zero and are read-only).
|
768 |
72 |
zero_gravi |
|=======================
|
769 |
60 |
zero_gravi |
|
770 |
|
|
.Machine counter-inhibit register
|
771 |
|
|
[cols="^1,<3,^1,<5"]
|
772 |
|
|
[options="header",grid="rows"]
|
773 |
|
|
|=======================
|
774 |
|
|
| Bit | Name [C] | R/W | Event
|
775 |
73 |
zero_gravi |
| 0 | _CSR_MCOUNTINHIBIT_IR_ | r/w | **IR**: The `[m]instret[h]` CSRs will auto-increment with each committed instruction when set
|
776 |
|
|
| 2 | _CSR_MCOUNTINHIBIT_CY_ | r/w | **CY**: The `[m]cycle[h]` CSRs will auto-increment with each clock cycle (if CPU is not in sleep state) when set
|
777 |
|
|
| 3:31 | _CSR_MCOUNTINHIBIT_HPM3_ : _CSR_MCOUNTINHIBIT_HPM31_ | r/w | **HPMx**: The `mhpmcount*[h]` CSRs will auto-increment according to the configured `mhpmevent*` selector
|
778 |
60 |
zero_gravi |
|=======================
|
779 |
|
|
|
780 |
|
|
|
781 |
|
|
<<<
|
782 |
|
|
// ####################################################################################################################
|
783 |
|
|
:sectnums:
|
784 |
66 |
zero_gravi |
==== Machine Information CSRs
|
785 |
60 |
zero_gravi |
|
786 |
62 |
zero_gravi |
[NOTE]
|
787 |
|
|
All machine information registers can only be accessed in machine mode and are read-only.
|
788 |
60 |
zero_gravi |
|
789 |
|
|
:sectnums!:
|
790 |
|
|
===== **`mvendorid`**
|
791 |
|
|
|
792 |
|
|
[cols="4,27,>7"]
|
793 |
|
|
[frame="topbot",grid="none"]
|
794 |
72 |
zero_gravi |
|=======================
|
795 |
60 |
zero_gravi |
| 0xf11 | **Machine vendor ID** | `mvendorid`
|
796 |
|
|
3+| Reset value: _0x00000000_
|
797 |
|
|
3+| The `mvendorid` CSR is compatible to the RISC-V specifications. It is read-only and always reads zero.
|
798 |
72 |
zero_gravi |
|=======================
|
799 |
60 |
zero_gravi |
|
800 |
|
|
|
801 |
|
|
:sectnums!:
|
802 |
|
|
===== **`marchid`**
|
803 |
|
|
|
804 |
|
|
[cols="4,27,>7"]
|
805 |
|
|
[frame="topbot",grid="none"]
|
806 |
72 |
zero_gravi |
|=======================
|
807 |
60 |
zero_gravi |
| 0xf12 | **Machine architecture ID** | `marchid`
|
808 |
|
|
3+| Reset value: _0x00000013_
|
809 |
|
|
3+| The `marchid` CSR is compatible to the RISC-V specifications. It is read-only and shows the NEORV32
|
810 |
|
|
official _RISC-V open-source architecture ID_ (decimal: 19, 32-bit hexadecimal: 0x00000013).
|
811 |
72 |
zero_gravi |
|=======================
|
812 |
60 |
zero_gravi |
|
813 |
|
|
|
814 |
|
|
:sectnums!:
|
815 |
|
|
===== **`mimpid`**
|
816 |
|
|
|
817 |
|
|
[cols="4,27,>7"]
|
818 |
|
|
[frame="topbot",grid="none"]
|
819 |
72 |
zero_gravi |
|=======================
|
820 |
60 |
zero_gravi |
| 0xf13 | **Machine implementation ID** | `mimpid`
|
821 |
72 |
zero_gravi |
3+| Reset value: _defined_
|
822 |
60 |
zero_gravi |
3+| The `mimpid` CSR is compatible to the RISC-V specifications. It is read-only and shows the version of the
|
823 |
|
|
NEORV32 as BCD-coded number (example: `mimpid` = _0x01020312_ → 01.02.03.12 → version 1.2.3.12).
|
824 |
72 |
zero_gravi |
|=======================
|
825 |
60 |
zero_gravi |
|
826 |
|
|
|
827 |
|
|
:sectnums!:
|
828 |
|
|
===== **`mhartid`**
|
829 |
|
|
|
830 |
|
|
[cols="4,27,>7"]
|
831 |
|
|
[frame="topbot",grid="none"]
|
832 |
72 |
zero_gravi |
|=======================
|
833 |
60 |
zero_gravi |
| 0xf14 | **Machine hardware thread ID** | `mhartid`
|
834 |
72 |
zero_gravi |
3+| Reset value: _defined_
|
835 |
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,
|
836 |
|
|
which is assigned via the CPU's _HW_THREAD_ID_ generic.
|
837 |
72 |
zero_gravi |
|=======================
|
838 |
60 |
zero_gravi |
|
839 |
|
|
|
840 |
62 |
zero_gravi |
:sectnums!:
|
841 |
|
|
===== **`mconfigptr`**
|
842 |
60 |
zero_gravi |
|
843 |
62 |
zero_gravi |
[cols="4,27,>7"]
|
844 |
|
|
[frame="topbot",grid="none"]
|
845 |
72 |
zero_gravi |
|=======================
|
846 |
62 |
zero_gravi |
| 0xf15 | **Machine configuration pointer register** | `mconfigptr`
|
847 |
72 |
zero_gravi |
3+| Reset value: _0x00000000_
|
848 |
62 |
zero_gravi |
3+| This register holds a physical address (if not zero) that points to the base address of an architecture configuration structure.
|
849 |
|
|
Software can traverse this data structure to discover information about the harts, the platform, and their configuration.
|
850 |
|
|
**NOTE: Not assigned yet.**
|
851 |
72 |
zero_gravi |
|=======================
|
852 |
|
|
|
853 |
|
|
|
854 |
|
|
<<<
|
855 |
|
|
// ####################################################################################################################
|
856 |
|
|
:sectnums:
|
857 |
|
|
==== NEORV32-Specific CSRs
|
858 |
|
|
|
859 |
|
|
[NOTE]
|
860 |
|
|
All NEORV32-specific CSRs are mapped to addresses that are explicitly reserved for custom **Machine-Mode, read-only** CSRs
|
861 |
|
|
(assured by the RISC-V privileged specifications). Hence, these CSRs can only be accessed when in machine-mode. Any access
|
862 |
|
|
outside of machine-mode will raise an illegal instruction exception.
|
863 |
|
|
|
864 |
|
|
:sectnums!:
|
865 |
|
|
===== **`mxisa`**
|
866 |
|
|
|
867 |
|
|
[cols="4,27,>7"]
|
868 |
|
|
[frame="topbot",grid="none"]
|
869 |
|
|
|=======================
|
870 |
|
|
| 0x7c0 | **Machine EXTENDED ISA and Extensions register** | `mxisa`
|
871 |
|
|
3+| Reset value: _defined_
|
872 |
|
|
3+| NEORV32-specific read-only CSR that helps machine-mode software to discover `Z*` sub-extensions and CPU options.
|
873 |
|
|
|=======================
|
874 |
|
|
|
875 |
|
|
|
876 |
|
|
.Machine _EXTENDED_ ISA and Extensions register bits
|
877 |
|
|
[cols="^1,<3,^1,<5"]
|
878 |
|
|
[options="header",grid="rows"]
|
879 |
|
|
|=======================
|
880 |
|
|
| Bit | Name [C] | R/W | Function
|
881 |
|
|
| 31 | _CSR_MXISA_FASTSHIFT_ | r/- | fast shifts available when set (via top's <<_fast_shift_en>> generic)
|
882 |
|
|
| 30 | _CSR_MXISA_FASTMUL_ | r/- | fast multiplication available when set (via top's <<_fast_mul_en>> generic)
|
883 |
|
|
| 31:11 | - | r/- | _reserved_, read as zero
|
884 |
|
|
| 10 | _CSR_MXISA_DEBUGMODE_ | r/- | RISC-V CPU `debug_mode` available when set (via top's <<_on_chip_debugger_en>> generic)
|
885 |
|
|
| 9 | _CSR_MXISA_ZIHPM_ | r/- | `Zihpm` (hardware performance monitors) extension available when set (via top's <<_cpu_extension_riscv_zihpm>> generic)
|
886 |
|
|
| 8 | _CSR_MXISA_PMP_ | r/- | PMP` (physical memory protection) extension available when set (via top's <<_pmp_num_regions>> generic)
|
887 |
|
|
| 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)
|
888 |
|
|
| 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)
|
889 |
|
|
| 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)
|
890 |
|
|
| 4 | - | r/- | _reserved_, read as zero
|
891 |
|
|
| 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)
|
892 |
|
|
| 2 | _CSR_MXISA_ZMMUL_ | r/- | `Zmmul` extension (`M` sub-extension) available when set (via top's <<_cpu_extension_riscv_zmmul>> generic)
|
893 |
|
|
| 1 | _CSR_MXISA_ZIFENCEI_ | r/- | `Zifencei` extension (`I` sub-extension) available when set (via top's <<_cpu_extension_riscv_zifencei>> generic)
|
894 |
|
|
| 0 | _CSR_MXISA_ZICSR_ | r/- | `Zicsr` extension (`I` sub-extension) available when set (via top's <<_cpu_extension_riscv_zicsr>> generic)
|
895 |
|
|
|=======================
|