OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [docs/] [datasheet/] [cpu_csr.adoc] - Blame information for rev 60

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
|======
34
| _Address_ | _Description_ | _ASM alias_
35
3+| Reset value: _CSR content after hardware reset_ (also see <<_cpu_hardware_reset>>)
36
3+| _Detailed description_
37
|======
38
 
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
* `C` - have or are a custom CPU extension (that is allowed by the RISC-V specs)
59
* `R` - are read-only (in contrast to the originally specified r/w capability)
60
* `S` - have a constrained compatibility; for example not all specified bits are available
61
 
62
.NEORV32 Control and Status Registers (CSRs)
63
[cols="<4,<6,<11,^3,<11,^3"]
64
[options="header"]
65
|=======================
66
| Address | Name [ASM]   | Name [C]         | R/W | Function | Note
67
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
6+^| **<<_machine_trap_setup>>**
72
| 0x300   | <<_mstatus>>    | _CSR_MSTATUS_    | r/w | Machine status register | `S`
73
| 0x301   | <<_misa>>       | _CSR_MISA_       | r/- | Machine CPU ISA and extensions | `R`
74
| 0x304   | <<_mie>>        | _CSR_MIE_        | r/w | Machine interrupt enable register | `C`
75
| 0x305   | <<_mtvec>>      | _CSR_MTVEC_      | r/w | Machine trap-handler base address (for ALL traps) |
76
| 0x306   | <<_mcounteren>> | _CSR_MCOUNTEREN_ | r/w | Machine counter-enable register | `S`
77
6+^| **<<_machine_trap_handling>>**
78
| 0x340   | <<_mscratch>>   | _CSR_MSCRATCH_   | r/w | Machine scratch register |
79
| 0x341   | <<_mepc>>       | _CSR_MEPC_       | r/w | Machine exception program counter |
80
| 0x342   | <<_mcause>>     | _CSR_MCAUSE_     | r/w | Machine trap cause | `C`
81
| 0x343   | <<_mtval>>      | _CSR_MTVAL_      | r/- | Machine bad address or instruction | `R`
82
| 0x344   | <<_mip>>        | _CSR_MIP_        | r/- | Machine interrupt pending register | `CR`
83
6+^| **<<_machine_physical_memory_protection>>**
84
| 0x3a0 .. 0x3af | <<_pmpcfg, `pmpcfg0`>> .. <<_pmpcfg, , `pmpcfg15`>>   | _CSR_PMPCFG0_ .. _CSR_PMPCFG15_ | r/w | Physical memory protection config. for region 0..63 | `S`
85
| 0x3b0 .. 0x3ef | <<_pmpaddr, `pmpaddr0`>> .. <<_pmpaddr, `pmpaddr63`>> | _CSR_PMPADDR0_ .. _CSR_PMPADDR63_ | r/w | Physical memory protection addr. register region 0..63 |
86
6+^| **<<_machine_counters_and_timers>>**
87
| 0xb00   | <<_mcycleh, `mcycle`>>     | _CSR_MCYCLE_     | r/w | Machine cycle counter low word |
88
| 0xb02   | <<_minstreth, `_minstret`>>   | _CSR_MINSTRET_   | r/w | Machine instruction-retired counter low word |
89
| 0xb80   | <<_mcycleh>>    | _CSR_MCYCLE_     | r/w | Machine cycle counter high word |
90
| 0xb82   | <<_minstreth>>  | _CSR_MINSTRET_   | r/w | Machine instruction-retired counter high word |
91
| 0xc00   | <<_cycleh, `cycle`>>      | _CSR_CYCLE_      | r/- | Cycle counter low word |
92
| 0xc01   | <<_timeh, `time`>>       | _CSR_TIME_       | r/- | System time (from MTIME) low word |
93
| 0xc02   | <<_instreth, `instret`>>    | _CSR_INSTRET_    | r/- | Instruction-retired counter low word |
94
| 0xc80   | <<_cycleh>>     | _CSR_CYCLEH_     | r/- | Cycle counter high word |
95
| 0xc81   | <<_timeh>>      | _CSR_TIMEH_      | r/- | System time (from MTIME) high word |
96
| 0xc82   | <<_instreth>>   | _CSR_INSTRETH_   | r/- | Instruction-retired counter high word |
97
6+^| **<<_hardware_performance_monitors_hpm>>**
98
| 0x323 .. 0x33f | <<_mhpmevent, `mhpmevent3`>> .. <<_mhpmevent, `mhpmevent31`>>       | _CSR_MHPMEVENT3_ .. _CSR_MHPMEVENT31_       | r/w | Machine performance-monitoring event selector 3..31 | `C`
99
| 0xb03 .. 0xb1f | <<_mhpmcounterh, `mhpmcounter3`>> .. <<_mhpmcounterh, `mhpmcounter31`>>   | _CSR_MHPMCOUNTER3_ .. _CSR_MHPMCOUNTER31_   | r/w | Machine performance-monitoring counter 3..31 low word |
100
| 0xb83 .. 0xb9f | <<_mhpmcounterh, `mhpmcounter3h`>> .. <<_mhpmcounterh, `mhpmcounter31h`>> | _CSR_MHPMCOUNTER3H_ .. _CSR_MHPMCOUNTER31H_ | r/w | Machine performance-monitoring counter 3..31 high word |
101
| 0xc03 .. 0xc1f | <<_hpmcounterh, `hpmcounter3`>> .. <<_hpmcounterh, `hpmcounter31`>>     | _CSR_HPMCOUNTER3_ .. _CSR_HPMCOUNTER31_     | r/- | Performance-monitoring counter 3..31 low word |
102
| 0xc83 .. 0xc9f | <<_hpmcounterh, `hpmcounter3h`>> .. <<_hpmcounter31h, `hpmcounter31h`>>   | _CSR_HPMCOUNTER3H_ .. _CSR_HPMCOUNTER31H_   | r/- | Performance-monitoring counter 3..31 high word |
103
6+^| **<<_machine_counter_setup>>**
104
| 0x320   | <<_mcountinhibit>> | _CSR_MCOUNTINHIBIT_ | r/w | Machine counter-enable register |
105
6+^| **<<_machine_information_registers>>**
106
| 0xf11   | <<_mvendorid>> | _CSR_MVENDORID_ | r/- | Vendor ID |
107
| 0xf12   | <<_marchid>>   | _CSR_MARCHID_   | r/- | Architecture ID |
108
| 0xf13   | <<_mimpid>>    | _CSR_MIMPID_    | r/- | Machine implementation ID / version |
109
| 0xf14   | <<_mhartid>>   | _CSR_MHARTID_   | r/- | Machine thread ID |
110
6+^| **<<_neorv32_specific_custom_csrs>>**
111
| 0xfc0   | <<_mzext>> | _CSR_MZEXT_ | r/- | Available `Z*` CPU extensions |
112
|=======================
113
 
114
 
115
 
116
<<<
117
// ####################################################################################################################
118
:sectnums:
119
==== Floating-Point CSRs
120
 
121
These CSRs are available if the `Zfinx` extensions is enabled (`CPU_EXTENSION_RISCV_Zfinx` is _true_).
122
Otherwise any access to the floating-point CSRs will raise an illegal instruction exception.
123
 
124
 
125
:sectnums!:
126
===== **`fflags`**
127
 
128
[cols="4,27,>7"]
129
[frame="topbot",grid="none"]
130
|======
131
| 0x001 | **Floating-point accrued exceptions** | `fflags`
132
3+| Reset value: _UNDEFINED_
133
3+| The `fflags` CSR is compatible to the RISC-V specifications. It shows the accrued ("accumulated")
134
exception flags in the lowest 5 bits. This CSR is only available if a floating-point CPU extension is enabled.
135
See the RISC-V ISA spec for more information.
136
|======
137
 
138
 
139
:sectnums!:
140
===== **`frm`**
141
 
142
[cols="4,27,>7"]
143
[frame="topbot",grid="none"]
144
|======
145
| 0x002 | **Floating-point dynamic rounding mode** | `frm`
146
3+| Reset value: _UNDEFINED_
147
3+| The `frm` CSR is compatible to the RISC-V specifications and is used to configure the rounding modes using
148
the lowest 3 bits. This CSR is only available if a floating-point CPU extension is enabled. See the RISC-V
149
ISA spec for more information.
150
|======
151
 
152
 
153
:sectnums!:
154
===== **`fcsr`**
155
 
156
[cols="4,27,>7"]
157
[frame="topbot",grid="none"]
158
|======
159
| 0x003 | **Floating-point control and status register** | `fcsr`
160
3+| Reset value: _UNDEFINED_
161
3+| The `fcsr` CSR is compatible to the RISC-V specifications. It provides combined read/write access to the
162
`fflags` and `frm` CSRs. This CSR is only available if a floating-point CPU extension is enabled. See the
163
RISC-V ISA spec for more information.
164
|======
165
 
166
 
167
<<<
168
// ####################################################################################################################
169
:sectnums:
170
==== Machine Trap Setup
171
 
172
:sectnums!:
173
===== **`mstatus`**
174
 
175
[cols="4,27,>7"]
176
[frame="topbot",grid="none"]
177
|======
178
| 0x300 | **Machine status register - low word** | `mstatus`
179
3+| Reset value: _0x00000020.00000000_
180
3+| The `mstatus` CSR is compatible to the RISC-V specifications. It shows the CPU's current execution state.
181
The following bits are implemented (all remaining bits are always zero and are read-only).
182
|======
183
 
184
.Machine status register
185
[cols="^1,<3,^1,<5"]
186
[options="header",grid="rows"]
187
|=======================
188
| Bit   | Name [C] | R/W | Function
189
| 12:11 | _CSR_MSTATUS_MPP_H_ : _CSR_MSTATUS_MPP_L_ | r/w | Previous machine privilege level, 11 = machine (M) level, 00 = user (U) level
190
| 7     | _CSR_MSTATUS_MPIE_ | r/w | Previous machine global interrupt enable flag state
191
| 3     | _CSR_MSTATUS_MIE_ | r/w | Machine global interrupt enable flag
192
|=======================
193
 
194
When entering an exception/interrupt, the `MIE` flag is copied to `MPIE` and cleared afterwards. When leaving
195
the exception/interrupt (via the `mret` instruction), `MPIE` is copied back to `MIE`.
196
 
197
 
198
:sectnums!:
199
===== **`misa`**
200
 
201
[cols="4,27,>7"]
202
[frame="topbot",grid="none"]
203
|======
204
| 0x301 | **ISA and extensions** | `misa`
205
3+| Reset value: _configuration dependant_
206
3+| The `misa` CSR gives information about the actual CPU features. The lowest 26 bits show the implemented
207
CPU extensions. The following bits are implemented (all remaining bits are always zero and are read-only).
208
|======
209
 
210
[IMPORTANT]
211
The `misa` CSR is not fully RISC-V-compatible as it is read-only. Hence, implemented CPU
212
extensions cannot be switch on/off during runtime. For compatibility reasons any write access to this
213
CSR is simply ignored and will NOT cause an illegal instruction exception.
214
 
215
.Machine ISA and extension register
216
[cols="^1,<3,^1,<5"]
217
[options="header",grid="rows"]
218
|=======================
219
| Bit   | Name [C] | R/W | Function
220
| 31:30 | _CSR_MISA_MXL_HI_EXT_ : _CSR_MISA_MXL_LO_EXT_ | r/- | 32-bit architecture indicator (always _01_)
221
| 23    | _CSR_MISA_X_EXT_ | r/- | `X` extension bit is always set to indicate custom non-standard extensions
222
| 20    | _CSR_MISA_U_EXT_ | r/- | `U` CPU extension (user mode) available, set when _CPU_EXTENSION_RISCV_U_ enabled
223
| 12    | _CSR_MISA_M_EXT_ | r/- | `M` CPU extension (mul/div) available, set when _CPU_EXTENSION_RISCV_M_ enabled
224
| 8     | _CSR_MISA_I_EXT_ | r/- | `I` CPU base ISA, cleared when _CPU_EXTENSION_RISCV_E_ enabled
225
| 4     | _CSR_MISA_E_EXT_ | r/- | `E` CPU extension (embedded) available, set when _CPU_EXTENSION_RISCV_E_ enabled
226
| 2     | _CSR_MISA_C_EXT_ | r/- | `C` CPU extension (compressed instruction) available, set when _CPU_EXTENSION_RISCV_C_ enabled
227
| 0     | _CSR_MISA_A_EXT_ | r/- | `A` CPU extension (atomic memory access) available, set when _CPU_EXTENSION_RISCV_A_ enabled
228
|=======================
229
 
230
[TIP]
231
Information regarding the available RISC-V Z* _sub-extensions_ (like `Zicsr` or `Zfinx`) can be found in the <<_mzext>> CSR.
232
 
233
 
234
:sectnums!:
235
===== **`mie`**
236
 
237
[cols="4,27,>7"]
238
[frame="topbot",grid="none"]
239
|======
240
| 0x304 | **Machine interrupt-enable register** | `mie`
241
3+| Reset value: _UNDEFINED_
242
3+| The `mie` CSR is compatible to the RISC-V specifications and features custom extensions for the fast
243
interrupt channels. It is used to enabled specific interrupts sources. Please note that interrupts also have to be
244
globally enabled via the `CSR_MSTATUS_MIE` flag of the `mstatus` CSR. The following bits are implemented
245
(all remaining bits are always zero and are read-only):
246
|======
247
 
248
.Machine ISA and extension register
249
[cols="^1,<3,^1,<5"]
250
[options="header",grid="rows"]
251
|=======================
252
| Bit   | Name [C] | R/W | Function
253
| 31:16 | _CSR_MIE_FIRQ15E_ : _CSR_MIE_FIRQ0E_ | r/w | Fast interrupt channel 15..0 enable
254
| 11    | _CSR_MIE_MEIE_ | r/w | Machine _external_ interrupt enable
255
| 7     | _CSR_MIE_MTIE_ | r/w | Machine _timer_ interrupt enable (from _MTIME_)
256
| 3     | _CSR_MIE_MSIE_ | r/w | Machine _software_ interrupt enable
257
|=======================
258
 
259
 
260
:sectnums!:
261
===== **`mtvec`**
262
 
263
[cols="4,27,>7"]
264
[frame="topbot",grid="none"]
265
|======
266
| 0x305 | **Machine trap-handler base address** | `mtvec`
267
3+| Reset value: _UNDEFINED_
268
3+| The `mtvec` CSR is compatible to the RISC-V specifications. It stores the base address for ALL machine
269
traps. Thus, it defines the main entry point for exception/interrupt handling regardless of the actual trap
270
source. The lowest two bits of this register are always zero and cannot be modified (= fixed address mode).
271
|======
272
 
273
.Machine trap-handler base address
274
[cols="^1,^1,<8"]
275
[options="header",grid="rows"]
276
|=======================
277
| Bit  | R/W | Function
278
| 31:2 | r/w | 4-byte aligned base address of trap base handler
279
| 1:0  | r/- | Always zero
280
|=======================
281
 
282
 
283
:sectnums!:
284
===== **`mcounteren`**
285
 
286
[cols="4,27,>7"]
287
[frame="topbot",grid="none"]
288
|======
289
| 0x306 | **Machine counter enable** | `mcounteren`
290
3+| Reset value: _UNDEFINED_
291
3+| The `mcounteren` CSR is compatible to the RISC-V specifications. The bits of this CSR define which
292
counter/timer CSR can be accessed (read) from code running in a less-privileged modes. For example,
293
if user-level code tries to read from a counter/timer CSR without having access, the illegal instruction
294
exception is raised. The following table shows all implemented bits (all remaining bits are always zero and
295
are read-only). If user mode in not implemented (_CPU_EXTENSION_RISCV_U_ = _false_) all bits of the
296
`mcounteren` CSR are tied to zero.
297
|======
298
 
299
.Machine counter enable register
300
[cols="^1,<3,^1,<5"]
301
[options="header",grid="rows"]
302
|=======================
303
| Bit   | Name [C] | R/W | Function
304
| 31:16 | _CSR_MCOUNTEREN_HPM31_ : _CSR_MCOUNTEREN_HPM3_ | r/w | User-level code is allowed to read `hpmcounter*[h]` CSRs when set
305
| 2     | _CSR_MCOUNTEREN_IR_ | r/w | User-level code is allowed to read `cycle[h]` CSRs when set
306
| 1     | _CSR_MCOUNTEREN_TM_ | r/w | User-level code is allowed to read `time[h]` CSRs when set
307
| 0     | _CSR_MCOUNTEREN_CY_ | r/w | User-level code is allowed to read `instret[h]` CSRs when set
308
|=======================
309
 
310
 
311
<<<
312
// ####################################################################################################################
313
:sectnums:
314
==== Machine Trap Handling
315
 
316
:sectnums!:
317
===== **`mscratch`**
318
 
319
[cols="4,27,>7"]
320
[frame="topbot",grid="none"]
321
|======
322
| 0x340 | **Scratch register for machine trap handlers** | `mscratch`
323
3+| Reset value: _UNDEFINED_
324
3+| The `mscratch` CSR is compatible to the RISC-V specifications. It is a general purpose scratch register that
325
can be used by the exception/interrupt handler. The content pf this register after reset is undefined.
326
|======
327
 
328
:sectnums!:
329
===== **`mepc`**
330
 
331
[cols="4,27,>7"]
332
[frame="topbot",grid="none"]
333
|======
334
| 0x341 | **Machine exception program counter** | `mepc`
335
3+| Reset value: _UNDEFINED_
336
3+| The `mepc` CSR is compatible to the RISC-V specifications. For exceptions (like an illegal instruction) this
337
register provides the address of the exception-causing instruction. For Interrupt (like a machine timer
338
interrupt) this register provides the address of the next not-yet-executed instruction.
339
|======
340
 
341
:sectnums!:
342
===== **`mcause`**
343
 
344
[cols="4,27,>7"]
345
[frame="topbot",grid="none"]
346
|======
347
| 0x342 | **Machine trap cause** | `mcause`
348
3+| Reset value: _UNDEFINED_
349
3+| The `mcause` CSR is compatible to the RISC-V specifications. It show the cause ID for a taken exception.
350
|======
351
 
352
.Machine trap cause register
353
[cols="^1,^1,<8"]
354
[options="header",grid="rows"]
355
|=======================
356
| Bit  | R/W | Function
357
| 31   | r/w | `1` if the trap is caused by an interrupt (`0` if the trap is caused by an exception)
358
| 30:5 | r/- | _Reserved_, read as zero
359
| 4:0  | r/w | Trap ID, see <<_neorv32_trap_listing>>
360
|=======================
361
 
362
:sectnums!:
363
===== **`mtval`**
364
 
365
[cols="4,27,>7"]
366
[frame="topbot",grid="none"]
367
|======
368
| 0x343 | **Machine bad address or instruction** | `mtval`
369
3+| Reset value: _UNDEFINED_
370
3+| The `mtval` CSR is compatible to the RISC-V specifications. When a trap is triggered, the CSR shows either
371
the faulting address (for misaligned/faulting load/stores/fetch) or the faulting instruction itself (for illegal
372
instructions). For interrupts the CSR is set to zero.
373
|======
374
 
375
.Machine bad address or instruction register
376
[cols="^5,^5"]
377
[options="header",grid="rows"]
378
|=======================
379
| Trap cause | `mtval` content
380
| misaligned instruction fetch address or instruction fetch access fault | address of faulting instruction fetch
381
| breakpoint | program counter (= address) of faulting instruction itself
382
| misaligned load address, load access fault, misaligned store address or store access fault | program counter (= address) of faulting instruction itself
383
| illegal instruction | actual instruction word of faulting instruction
384
| anything else including interrupts | _0x00000000_ (always zero)
385
|=======================
386
 
387
[IMPORTAN]
388
The NEORV32 `mtval` CSR is read-only. A write access will raise an illegal instruction exception.
389
 
390
:sectnums!:
391
===== **`mip`**
392
 
393
[cols="4,27,>7"]
394
[frame="topbot",grid="none"]
395
|======
396
| 0x344 | **Machine interrupt Pending** | `mip`
397
3+| Reset value: _0x00000000_
398
3+| The `mip` CSR is _partly_ compatible to the RISC-V specifications and also provides custom extensions. It shows currently pending interrupts. Since this register is
399
read-only, pending interrupt can only be cleared by disabling and re-enabling the according `mie` CSr bit. Writing to this CSR will
400
raise an illegal instruction exception. The following CSR bits are implemented (all remaining bits are always zero and are read-only).
401
|======
402
 
403
.Machine interrupt pending register
404
[cols="^1,<3,^1,<5"]
405
[options="header",grid="rows"]
406
|=======================
407
| Bit | Name [C] | R/W | Function
408
| 31:16 | _CSR_MIP_FIRQ15P_ : _CSR_MIP_FIRQ0P_ | r/- | fast interrupt channel 15..0 pending
409
| 11    | _CSR_MIP_MEIP_ | r/- | machine _external_ interrupt pending
410
| 7     | _CSR_MIP_MTIP_ | r/- | machine _timer_ interrupt pending
411
| 3     | _CSR_MIP_MSIP_ | r/- | machine _software_ interrupt pending
412
|=======================
413
 
414
 
415
<<<
416
// ####################################################################################################################
417
:sectnums:
418
==== Machine Physical Memory Protection
419
 
420
The available physical memory protection logic is configured via the _PMP_NUM_REGIONS_ and
421
_PMP_MIN_GRANULARITY_ top entity generics. _PMP_NUM_REGIONS_ defines the number of implemented
422
protection regions and thus, the availability of the according `pmpcfg*` and `pmpaddr*` CSRs.
423
 
424
[TIP]
425
If trying to access an PMP-related CSR beyond _PMP_NUM_REGIONS_ **no illegal instruction
426
exception** is triggered. The according CSRs are read-only (writes are ignored) and always return zero.
427
 
428
[IMPORTANT]
429
The RISC-V-compatible NEORV32 physical memory protection only implements the _NAPOT_
430
(naturally aligned power-of-two region) mode with a minimal region granularity of 8 bytes.
431
 
432
 
433
:sectnums!:
434
===== **`pmpcfg`**
435
 
436
[cols="4,27,>7"]
437
[frame="topbot",grid="none"]
438
|======
439
| 0x3a0 - 0x3af| **Physical memory protection configuration registers** | `pmpcfg0` - `pmpcfg15`
440
3+| Reset value: _0x00000000_
441
3+| The `pmpcfg*` CSRs are compatible to the RISC-V specifications. They are used to configure the protected
442
regions, where each `pmpcfg*` CSR provides configuration bits for four regions. The following bits (for the
443
first PMP configuration entry) are implemented (all remaining bits are always zero and are read-only):
444
|======
445
 
446
.Physical memory protection configuration register entry
447
[cols="^1,^3,^1,<11"]
448
[options="header",grid="rows"]
449
|=======================
450
| Bit | RISC-V name | R/W | Function
451
| 7   | _L_ | r/w | lock bit, can be set – but not be cleared again (only via CPU reset)
452
| 6:5 | -   | r/- | reserved, read as zero
453
| 4:3 | _A_ | r/w | mode configuration; only OFF (`00`) and NAPOT (`11`) are supported
454
| 2   | _X_ | r/w | execute permission
455
| 1   | _W_ | r/w | write permission
456
| 0   | _R_ | r/w | read permission
457
|=======================
458
 
459
 
460
:sectnums!:
461
===== **`pmpaddr`**
462
 
463
[cols="4,27,>7"]
464
[frame="topbot",grid="none"]
465
|======
466
| 0x3b0 - 0x3ef| **Physical memory protection configuration registers** | `pmpaddr0` - `pmpaddr63`
467
3+| Reset value: _UNDEFINED_
468
3+| The `pmpaddr*` CSRs are compatible to the RISC-V specifications. They are used to configure the base
469
address and the region size.
470
|======
471
 
472
[NOTE]
473
When configuring PMP make sure to set `pmpaddr*` before activating the according region via
474
`pmpcfg*`. When changing the PMP configuration, deactivate the according region via `pmpcfg*`
475
before modifying `pmpaddr*`.
476
 
477
 
478
<<<
479
// ####################################################################################################################
480
:sectnums:
481
==== (Machine) Counters and Timers
482
 
483
[IMPORTANT]
484
The _CPU_CNT_WIDTH_ generic defines the total size of the CPU's `[m]cycle` and `[m]instret`
485
counter CSRs (low and high words combined); the time CSRs are not affected by this generic. Any
486
configuration with _CPU_CNT_WIDTH_ less than 64 is not RISC-V compliant.
487
 
488
[IMPORTANT]
489
If _CPU_CNT_WIDTH_ is less than 64 (the default value) and greater than or equal 32, the according
490
MSBs of `[m]cycleh` and `[m]instreth` are read-only and always read as zero. This configuration
491
will also set the _ZXSCNT_ flag in the `mzext` CSR.
492
 
493
[IMPORTANT]
494
If _CPU_CNT_WIDTH_ is less than 32 and greater than 0, the `[m]cycleh` and `[m]instreth` do not
495
exist and any access will raise an illegal instruction exception. Furthermore, the according MSBs of
496
`[m]cycle` and `[m]instret` are read-only and always read as zero. This configuration will also
497
set the _ZXSCNT_ flag in the `mzext` CSR.
498
 
499
[IMPORTANT]
500
If _CPU_CNT_WIDTH_ is 0, the `[m]cycleh`, `[m]cycle`, `[m]instreth` and `[m]instret` do not
501
exist and any access will raise an illegal instruction exception. This configuration will also set the
502
_ZXNOCNT_ flag in the `mzext` CSR.
503
 
504
 
505
:sectnums!:
506
===== **`cycle[h]`**
507
 
508
[cols="4,27,>7"]
509
[frame="topbot",grid="none"]
510
|======
511
| 0xc00 | **Cycle counter - low word** | `cycle`
512
| 0xc80 | **Cycle counter - high word** | `cycleh`
513
3+| Reset value: _UNDEFINED_
514
3+| The `cycle[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit cycle
515
counter. The `cycle[h]` CSR is a read-only shadowed copy of the `mcycle[h]` CSR.
516
|======
517
 
518
 
519
:sectnums!:
520
===== **`time[h]`**
521
 
522
[cols="4,27,>7"]
523
[frame="topbot",grid="none"]
524
|======
525
| 0xc01 | **System time - low word** | `time`
526
| 0xc81 | **System time - high word** | `timeh`
527
3+| Reset value: _UNDEFINED_
528
3+| The `time[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit system
529
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
530
external timer unit via the processor's `mtime_i` signal (if _IO_MTIME_EN_ = _false_).
531
CSR is read-only. Change the system time via the _MTIME_ unit.
532
|======
533
 
534
 
535
:sectnums!:
536
===== **`instret[h]`**
537
 
538
[cols="4,27,>7"]
539
[frame="topbot",grid="none"]
540
|======
541
| 0xc02 | **Instructions-retired counter - low word** | `instret`
542
| 0xc82 | **Instructions-retired counter - high word** | `instreth`
543
3+| Reset value: _UNDEFINED_
544
3+| The `instret[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit retired
545
instructions counter. The `instret[h]` CSR is a read-only shadowed copy of the `minstret[h]` CSR.
546
|======
547
 
548
 
549
:sectnums!:
550
===== **`mcycle[h]`**
551
 
552
[cols="4,27,>7"]
553
[frame="topbot",grid="none"]
554
|======
555
| 0xb00 | **Machine cycle counter - low word** | `mcycle`
556
| 0xb80 | **Machine cycle counter - high word** | `mcycleh`
557
3+| Reset value: _UNDEFINED_
558
3+| The `mcycle[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit cycle
559
counter. The `mcycle[h]` CSR can also be written when in machine mode and is copied to the `cycle[h]` CSR.
560
|======
561
 
562
 
563
:sectnums!:
564
===== **`minstret[h]`**
565
 
566
[cols="4,27,>7"]
567
[frame="topbot",grid="none"]
568
|======
569
| 0xb02 | **Machine instructions-retired counter - low word** | `minstret`
570
| 0xb82 | **Machine instructions-retired counter - high word** | `minstreth`
571
3+| Reset value: _UNDEFINED_
572
3+| The `minstret[h]` CSR is compatible to the RISC-V specifications. It shows the lower/upper 32-bit of the 64-bit retired
573
instructions counter. The `minstret[h]` CSR also be written when in machine mode and is copied to the `instret[h]` CSR.
574
|======
575
 
576
 
577
 
578
<<<
579
// ####################################################################################################################
580
:sectnums:
581
==== Hardware Performance Monitors (HPM)
582
 
583
The available hardware performance logic is configured via the _HPM_NUM_CNTS_ top entity generic.
584
_HPM_NUM_CNTS_ defines the number of implemented performance monitors and thus, the availability of the
585
according `[m]hpmcounter*[h]` and `mhpmevent*` CSRs.
586
 
587
The total size of the HPMs can be configured before synthesis via the _HPM_CNT_WIDTH_ generic (0..64-bit).
588
 
589
[TIP]
590
If trying to access an HPM-related CSR beyond _HPM_NUM_CNTS_ **no illegal instruction exception is
591
triggered**. The according CSRs are read-only (writes are ignored) and always return zero.
592
 
593
[NOTE]
594
The total LSB-aligned HPM counter size (low word CSR + high word CSR) is defined via the
595
_HPM_CNT_WIDTH_ generic (0..64-bit). If _HPM_CNT_WIDTH_ is less than 64, all unused MSB-aligned
596
bits are hardwired to zero.
597
 
598
 
599
:sectnums!:
600
===== **`mhpmevent`**
601
 
602
[cols="4,27,>7"]
603
[frame="topbot",grid="none"]
604
|======
605
| 0x232 -0x33f | **Machine hardware performance monitor event selector** | `mhpmevent3` - `mhpmevent31`
606
3+| Reset value: _UNDEFINED_
607
3+| The `mhpmevent*` CSRs are compatible to the RISC-V specifications. The configuration of these CSR define
608
the architectural events that cause the according `[m]hpmcounter*[h]` counters to increment. All available events are
609
listed in the table below. If more than one event is selected, the according counter will increment if any of
610
the enabled events is observed (logical OR). Note that the counter will only increment by 1 step per clock
611
cycle even if more than one event is observed. If the CPU is in sleep mode, no HPM counter will increment
612
at all.
613
|======
614
 
615
The available hardware performance logic is configured via the _HPM_NUM_CNTS_ top entity generic.
616
_HPM_NUM_CNTS_ defines the number of implemented performance monitors and thus, the availability of the
617
according `[m]hpmcounter*[h]` and `mhpmevent*` CSRs.
618
 
619
.HPM event selector
620
[cols="^1,<3,^1,<5"]
621
[options="header",grid="rows"]
622
|=======================
623
| Bit | Name [C] | R/W | Event
624
| 0   | _HPMCNT_EVENT_CY_ | r/w | active clock cycle (not in sleep)
625
| 1   | -                 | r/- | _not implemented, always read as zero_
626
| 2   | _HPMCNT_EVENT_IR_ | r/w | retired instruction
627
| 3   | _HPMCNT_EVENT_CIR_ | r/w | retired cmpressed instruction
628
| 4   | _HPMCNT_EVENT_WAIT_IF_ | r/w | instruction fetch memory wait cycle (if more than 1 cycle memory latency)
629
| 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)
630
| 6   | _HPMCNT_EVENT_WAIT_MC_ | r/w | multi-cycle ALU operation wait cycle
631
| 7   | _HPMCNT_EVENT_LOAD_ | r/w | load operation
632
| 8   | _HPMCNT_EVENT_STORE_ | r/w | store operation
633
| 9   | _HPMCNT_EVENT_WAIT_LS_ | r/w | load/store memory wait cycle (if more than 1 cycle memory latency)
634
| 10  | _HPMCNT_EVENT_JUMP_ | r/w | unconditional jump
635
| 11  | _HPMCNT_EVENT_BRANCH_ | r/w | conditional branch (taken or not taken)
636
| 12  | _HPMCNT_EVENT_TBRANCH_ | r/w | taken conditional branch
637
| 13  | _HPMCNT_EVENT_TRAP_ | r/w | entered trap
638
| 14  | _HPMCNT_EVENT_ILLEGAL_ | r/w | illegal instruction exception
639
|=======================
640
 
641
 
642
:sectnums!:
643
===== **`hpmcounter[h]`**
644
 
645
[cols="4,27,>7"]
646
[frame="topbot",grid="none"]
647
|======
648
| 0xc03 - 0xc1f | **Hardware performance monitor - counter low** | `hpmcounter3` - `hpmcounter31`
649
| 0xc83 - 0xc9f | **Hardware performance monitor - counter high** | `hpmcounter3h` - `hpmcounter31h`
650
3+| Reset value: _UNDEFINED_
651
3+| The `hpmcounter*[h]` CSRs are compatible to the RISC-V specifications. These CSRs provide the lower/upper 32-bit
652
of arbitrary event counters (64-bit). These CSRs are read-only and provide a showed copy of the according
653
`mhpmcounter*[h]` CSRs. The event(s) that trigger an increment of theses counters are selected via the according
654
`mhpmevent*` CSRs.
655
|======
656
 
657
 
658
:sectnums!:
659
===== **`mhpmcounter[h]`**
660
 
661
[cols="4,27,>7"]
662
[frame="topbot",grid="none"]
663
|======
664
| 0xb03 - 0xb1f | **Machine hardware performance monitor - counter low** | `mhpmcounter3` - `mhpmcounter31`
665
| 0xb83 - 0xb9f | **Machine hardware performance monitor - counter high** | `mhpmcounter3h` - `mhpmcounter31h`
666
3+| Reset value: _UNDEFINED_
667
3+| The `mhpmcounter*[h]` CSRs are compatible to the RISC-V specifications. These CSRs provide the lower/upper 32-
668
bit of arbitrary event counters (64-bit). The `mhpmcounter*[h]` CSRs can also be written and are copied to the
669
`hpmcounter*[h]` CSRs. The event(s) that trigger an increment of theses counters are selected via the according
670
`mhpmevent*` CSRs.
671
|======
672
 
673
 
674
<<<
675
// ####################################################################################################################
676
:sectnums:
677
==== Machine Counter Setup
678
 
679
:sectnums!:
680
===== **`mcountinhibit`**
681
 
682
[cols="4,27,>7"]
683
[frame="topbot",grid="none"]
684
|======
685
| 0x320 | **Machine counter-inhibit register** | `mcountinhibit`
686
3+| Reset value: _UNDEFINED_
687
3+| The `mcountinhibit` CSR is compatible to the RISC-V specifications. The bits in this register define which
688
counter/timer CSR are allowed to perform an automatic increment. Automatic update is enabled if the
689
according bit in `mcountinhibit` is cleared. The following bits are implemented (all remaining bits are
690
always zero and are read-only).
691
|======
692
 
693
.Machine counter-inhibit register
694
[cols="^1,<3,^1,<5"]
695
[options="header",grid="rows"]
696
|=======================
697
| Bit  | Name [C] | R/W | Event
698
| 0    | _CSR_MCOUNTINHIBIT_IR_ | r/w | the `[m]instret[h]` CSRs will auto-increment with each committed instruction when set
699
| 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
700
| 3:31 | _CSR_MCOUNTINHIBIT_HPM3_ _: _CSR_MCOUNTINHIBIT_HPM31_ | r/w | the `[m]hpmcount*[h]` CSRs will auto-increment according to the configured `mhpmevent*` selector
701
|=======================
702
 
703
 
704
<<<
705
// ####################################################################################################################
706
:sectnums:
707
==== Machine Information Registers
708
 
709
 
710
:sectnums!:
711
===== **`mvendorid`**
712
 
713
[cols="4,27,>7"]
714
[frame="topbot",grid="none"]
715
|======
716
| 0xf11 | **Machine vendor ID** | `mvendorid`
717
3+| Reset value: _0x00000000_
718
3+| The `mvendorid` CSR is compatible to the RISC-V specifications. It is read-only and always reads zero.
719
|======
720
 
721
 
722
:sectnums!:
723
===== **`marchid`**
724
 
725
[cols="4,27,>7"]
726
[frame="topbot",grid="none"]
727
|======
728
| 0xf12 | **Machine architecture ID** | `marchid`
729
3+| Reset value: _0x00000013_
730
3+| The `marchid` CSR is compatible to the RISC-V specifications. It is read-only and shows the NEORV32
731
official _RISC-V open-source architecture ID_ (decimal: 19, 32-bit hexadecimal: 0x00000013).
732
|======
733
 
734
 
735
:sectnums!:
736
===== **`mimpid`**
737
 
738
[cols="4,27,>7"]
739
[frame="topbot",grid="none"]
740
|======
741
| 0xf13 | **Machine implementation ID** | `mimpid`
742
3+| Reset value: _HW version number_
743
3+| The `mimpid` CSR is compatible to the RISC-V specifications. It is read-only and shows the version of the
744
NEORV32 as BCD-coded number (example: `mimpid` = _0x01020312_ → 01.02.03.12 → version 1.2.3.12).
745
|======
746
 
747
 
748
:sectnums!:
749
===== **`mhartid`**
750
 
751
[cols="4,27,>7"]
752
[frame="topbot",grid="none"]
753
|======
754
| 0xf14 | **Machine hardware thread ID** | `mhartid`
755
3+| Reset value: _HW_THREAD_ID_ generic
756
3+| The `mhartid` CSR is compatible to the RISC-V specifications. It is read-only and shows the core's hart ID,
757
which is assigned via the CPU's _HW_THREAD_ID_ generic.
758
|======
759
 
760
 
761
 
762
<<<
763
// ####################################################################################################################
764
:sectnums:
765
==== NEORV32-Specific Custom CSRs
766
 
767
 
768
:sectnums!:
769
===== **`mzext`**
770
 
771
[cols="4,27,>7"]
772
[frame="topbot",grid="none"]
773
|======
774
| 0xfc0 | **Available Z* extensions** | `mzext`
775
3+| Reset value: _0x00000000_
776
3+| The `mzext` CSR is a custom read-only CSR that shows the implemented Z* extensions. The following bits
777
are implemented (all remaining bits are always zero). The entire CSR is read-only.
778
|======
779
 
780
.Machine counter-inhibit register
781
[cols="^1,<3,^1,<5"]
782
[options="header",grid="rows"]
783
|=======================
784
| Bit | Name [C] | R/W | Event
785
| 0   | _CPU_MZEXT_ZICSR_ | r/- | `Zicsr` extensions available (enabled via _CPU_EXTENSION_RISCV_Zicsr_ generic)
786
| 1   | _CPU_MZEXT_ZIFENCEI_ | r/- | `Zifencei` extensions available (enabled via _CPU_EXTENSION_RISCV_Zifencei_ generic)
787
| 5   | _CPU_MZEXT_ZFINX_ | r/- | `Zfinx` extensions available (enabled via _CPU_EXTENSION_RISCV_Zfinx_ generic)
788
| 6   | _CPU_MZEXT_ZXSCNT_ | r/- | custom extension: "Small CPU counters": `cycle[h]` & `instret[h]` CSRs have less than 64-bit when set (when _CPU_CNT_WIDTH_ generic is less than 64)
789
| 7   | _CPU_MZEXT_ZXNOCNT_ | r/- | custom extension: "NO CPU counters": `cycle[h]` & `instret[h]` CSRs are not available at all when set (when _CPU_CNT_WIDTH_ generic is 0)
790
| 8   | _CSR_MZEXT_PMP_ | r/- | PMP (physical memory protection) extension available (_PMP_NUM_REGIONS_ generic > 0)
791
| 9   | _CSR_MZEXT_HPM_ | r/- | HPM (hardware performance monitors) extension available (_HPM_NUM_CNTS_ generic > 0)
792
| 10  | _CSR_MZEXT_DEBUGMODE_ | r/- | RISC-V "CPU debug mode" extension available (enabled via _CPU_EXTENSION_RISCV_DEBUG_ generic)
793
|=======================

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.