1 |
69 |
zero_gravi |
<<<
|
2 |
|
|
:sectnums:
|
3 |
|
|
== Enabling RISC-V CPU Extensions
|
4 |
|
|
|
5 |
|
|
Whenever you enable/disable a RISC-V CPU extensions via the according `CPU_EXTENSION_RISCV_x` generic, you need to
|
6 |
|
|
adapt the toolchain configuration so the compiler can actually generate according code for it.
|
7 |
|
|
|
8 |
|
|
To do so, open the makefile of your project (for example `sw/example/blink_led/makefile`) and scroll to the
|
9 |
|
|
"USER CONFIGURATION" section right at the beginning of the file. You need to modify the `MARCH` variable and eventually
|
10 |
|
|
the `MABI` variable according to your CPU hardware configuration.
|
11 |
|
|
|
12 |
|
|
[source,makefile]
|
13 |
|
|
----
|
14 |
|
|
# CPU architecture and ABI
|
15 |
|
|
MARCH ?= rv32i <1>
|
16 |
|
|
MABI ?= ilp32 <2>
|
17 |
|
|
----
|
18 |
|
|
<1> MARCH = Machine architecture ("ISA string")
|
19 |
|
|
<2> MABI = Machine binary interface
|
20 |
|
|
|
21 |
|
|
For example, if you enable the RISC-V `C` extension (16-bit compressed instructions) via the `CPU_EXTENSION_RISCV_C`
|
22 |
|
|
generic (set `true`) you need to add the `c` extension also to the `MARCH` ISA string in order to make the compiler
|
23 |
|
|
emit compressed instructions.
|
24 |
|
|
|
25 |
|
|
.Privileged Architecture Extensions
|
26 |
|
|
[IMPORTANT]
|
27 |
|
|
Privileged architecture extensions like `Zicsr` or `Zifencei` are "used" _implicitly_ by the compiler. Hence, according
|
28 |
|
|
instruction will only be generated when "encoded" via inline assembly or when linking according libraries. In this case,
|
29 |
|
|
these instruction will _always_ be emitted (even if the according extension is not specified in `MARCH`). +
|
30 |
|
|
**I recommend to _not_ specify any privileged architecture extensions in `MARCH`.**
|
31 |
|
|
|
32 |
|
|
[WARNING]
|
33 |
|
|
ISA extension enabled in hardware can be a superset of the extensions enabled in software, but not the other way
|
34 |
|
|
around. For example generating compressed instructions for a CPU configuration that has the `c` extension disabled
|
35 |
|
|
will cause _illegal instruction exceptions_ at runtime.
|
36 |
|
|
|
37 |
|
|
You can also override the default `MARCH` and `MABI` configurations from the makefile when invoking the makefile:
|
38 |
|
|
|
39 |
|
|
[source,bash]
|
40 |
|
|
----
|
41 |
|
|
$ make MARCH=rv32ic clean_all all
|
42 |
|
|
----
|
43 |
|
|
|
44 |
|
|
[NOTE]
|
45 |
|
|
The RISC-V ISA string for `MARCH` follows a certain _canonical_ structure:
|
46 |
|
|
`rev32[i/e][m][a][f][d][g][q][c][b][v][n]...` For example `rv32imac` is valid while `rv32icma` is not.
|