Skip to content

Commit 0c38415

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 ee3bd57 commit 0c38415

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
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_EXT_E ?= 0
132+
$(call set-feature, EXT_E)
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_EXT_E
32+
#define RV32_FEATURE_EXT_E 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(EXT_E)
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
extern "C" {
3434
#endif
3535

36+
#if !RV32_HAS(EXT_E)
3637
#define RV_REGS_LIST \
3738
_(zero) /* hard-wired zero, ignoring any writes */ \
3839
_(ra) /* return address */ \
@@ -66,6 +67,25 @@ extern "C" {
6667
_(t4) \
6768
_(t5) \
6869
_(t6)
70+
#else
71+
#define RV_REGS_LIST \
72+
_(zero) /* hard-wired zero, ignoring any writes */ \
73+
_(ra) /* return address */ \
74+
_(sp) /* stack pointer */ \
75+
_(gp) /* global pointer */ \
76+
_(tp) /* thread pointer */ \
77+
_(t0) /* temporary/alternate link register */ \
78+
_(t1) /* temporaries */ \
79+
_(t2) \
80+
_(s0) /* saved register/frame pointer */ \
81+
_(s1) \
82+
_(a0) /* function arguments / return values */ \
83+
_(a1) \
84+
_(a2) /* function arguments */ \
85+
_(a3) \
86+
_(a4) \
87+
_(a5)
88+
#endif
6989

7090
/* RISC-V registers (mnemonics, ABI names)
7191
*
@@ -96,6 +116,7 @@ enum {
96116
#define MISA_A (1 << ('A' - 'A'))
97117
#define MISA_F (1 << ('F' - 'A'))
98118
#define MISA_C (1 << ('C' - 'A'))
119+
#define MISA_E (1 << ('E' - 'A'))
99120

100121
/* The mstatus register keeps track of and controls the hart’s current operating
101122
* state */

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(EXT_E)
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)