Skip to content

Commit f25c1ec

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 5ec905a commit f25c1ec

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
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: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,27 @@
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)
69-
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+
IIF(RV32_HAS(RV32E)(, _(a6) _(a7) _(s2) /* saved register */ \
54+
_(s3) _(s4) _(s5) _(s6) _(s7) _(s8) _(s9) _(s10) \
55+
_(s11) _(t3) /* temporary register */ \
56+
_(t4) _(t5) _(t6)))
7057
/* RISC-V registers (mnemonics, ABI names)
7158
*
7259
* There are 32 registers in RISC-V. The program counter is a further register
@@ -117,6 +104,7 @@ enum SV32_PTE_PERM {
117104
#define MISA_SUPER (1 << ('S' - 'A'))
118105
#define MISA_USER (1 << ('U' - 'A'))
119106
#define MISA_I (1 << ('I' - 'A'))
107+
#define MISA_E (1 << ('E' - 'A'))
120108
#define MISA_M (1 << ('M' - 'A'))
121109
#define MISA_A (1 << ('A' - 'A'))
122110
#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)