Skip to content

Commit c4c12c2

Browse files
committed
Add support for the RV32E base ISA variant
The RV32E variant reduces the general-purpose registers to 16, optimizing the architecture for resource-constrained embedded microcontrollers. This addition enhances compatibility with the RISC-V specification and targets low-power, minimal-complexity systems.
1 parent 82a85ae commit c4c12c2

File tree

5 files changed

+57
-35
lines changed

5 files changed

+57
-35
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ endif
127127
ENABLE_EXT_C ?= 1
128128
$(call set-feature, EXT_C)
129129

130+
# RV32E Base Integer Instruction Set
131+
ENABLE_RV32E ?= 0
132+
$(call set-feature, RV32E)
133+
130134
# Control and Status Register (CSR)
131135
ENABLE_Zicsr ?= 1
132136
$(call set-feature, Zicsr)

src/feature.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
#define RV32_FEATURE_EXT_C 1
2828
#endif
2929

30+
/* RV32E Base Integer Instruction Set */
31+
#ifndef RV32_FEATURE_RV32E
32+
#define RV32_FEATURE_RV32E 0
33+
#endif
34+
3035
/* Control and Status Register (CSR) */
3136
#ifndef RV32_FEATURE_Zicsr
3237
#define RV32_FEATURE_Zicsr 1

src/riscv.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,15 @@ void rv_reset(riscv_t *rv, riscv_word_t pc)
769769
rv->csr_mtvec = 0;
770770
rv->csr_cycle = 0;
771771
rv->csr_mstatus = 0;
772-
rv->csr_misa |= MISA_SUPER | MISA_USER | MISA_I;
772+
rv->csr_misa |= MISA_SUPER | MISA_USER;
773773
rv->csr_mvendorid = RV_MVENDORID;
774774
rv->csr_marchid = RV_MARCHID;
775775
rv->csr_mimpid = RV_MIMPID;
776+
#if !RV32_HAS(RV32E)
777+
rv->csr_misa |= MISA_I;
778+
#else
779+
rv->csr_misa |= MISA_E;
780+
#endif
776781
#if RV32_HAS(EXT_A)
777782
rv->csr_misa |= MISA_A;
778783
#endif

src/riscv.h

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,42 @@
3333
extern "C" {
3434
#endif
3535

36-
#define RV_REGS_LIST \
37-
_(zero) /* hard-wired zero, ignoring any writes */ \
38-
_(ra) /* return address */ \
39-
_(sp) /* stack pointer */ \
40-
_(gp) /* global pointer */ \
41-
_(tp) /* thread pointer */ \
42-
_(t0) /* temporary/alternate link register */ \
43-
_(t1) /* temporaries */ \
44-
_(t2) \
45-
_(s0) /* saved register/frame pointer */ \
46-
_(s1) \
47-
_(a0) /* function arguments / return values */ \
48-
_(a1) \
49-
_(a2) /* function arguments */ \
50-
_(a3) \
51-
_(a4) \
52-
_(a5) \
53-
_(a6) \
54-
_(a7) \
55-
_(s2) /* saved register */ \
56-
_(s3) \
57-
_(s4) \
58-
_(s5) \
59-
_(s6) \
60-
_(s7) \
61-
_(s8) \
62-
_(s9) \
63-
_(s10) \
64-
_(s11) \
65-
_(t3) /* temporary register */ \
66-
_(t4) \
67-
_(t5) \
68-
_(t6)
36+
/* clang-format off */
37+
#define RV_REGS_LIST \
38+
_(zero) /* hard-wired zero, ignoring any writes */ \
39+
_(ra) /* return address */ \
40+
_(sp) /* stack pointer */ \
41+
_(gp) /* global pointer */ \
42+
_(tp) /* thread pointer */ \
43+
_(t0) /* temporary/alternate link register */ \
44+
_(t1) /* temporaries */ \
45+
_(t2) \
46+
_(s0) /* saved register/frame pointer */ \
47+
_(s1) \
48+
_(a0) /* function arguments / return values */ \
49+
_(a1) \
50+
_(a2) /* function arguments */ \
51+
_(a3) \
52+
_(a4) \
53+
_(a5) \
54+
IIF(RV32_HAS(RV32E))(, \
55+
_(a6) \
56+
_(a7) \
57+
_(s2) /* saved register */ \
58+
_(s3) \
59+
_(s4) \
60+
_(s5) \
61+
_(s6) \
62+
_(s7) \
63+
_(s8) \
64+
_(s9) \
65+
_(s10) \
66+
_(s11) \
67+
_(t3) /* temporary register */ \
68+
_(t4) \
69+
_(t5) \
70+
_(t6))
71+
/* clang-format on */
6972

7073
/* RISC-V registers (mnemonics, ABI names)
7174
*
@@ -117,6 +120,7 @@ enum SV32_PTE_PERM {
117120
#define MISA_SUPER (1 << ('S' - 'A'))
118121
#define MISA_USER (1 << ('U' - 'A'))
119122
#define MISA_I (1 << ('I' - 'A'))
123+
#define MISA_E (1 << ('E' - 'A'))
120124
#define MISA_M (1 << ('M' - 'A'))
121125
#define MISA_A (1 << ('A' - 'A'))
122126
#define MISA_F (1 << ('F' - 'A'))

src/syscall.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,12 @@ static void syscall_sbi_rst(riscv_t *rv)
466466

467467
void syscall_handler(riscv_t *rv)
468468
{
469-
/* get the syscall number */
469+
/* get the syscall number */
470+
#if !RV32_HAS(RV32E)
470471
riscv_word_t syscall = rv_get_reg(rv, rv_reg_a7);
472+
#else
473+
riscv_word_t syscall = rv_get_reg(rv, rv_reg_t0);
474+
#endif
471475

472476
switch (syscall) { /* dispatch system call */
473477
#define _(name, number) \

0 commit comments

Comments
 (0)