/* Define if subproject MCPPBS_SPROJ_NORM is enabled */
#undef RISCV_ENABLED
-/* Define if 64-bit mode is supported */
-#undef RISCV_ENABLE_64BIT
-
/* Enable commit log generation */
#undef RISCV_ENABLE_COMMITLOG
-/* Define if floating-point instructions are supported */
-#undef RISCV_ENABLE_FPU
-
/* Enable PC histogram generation */
#undef RISCV_ENABLE_HISTOGRAM
-/* Define if RISC-V Compressed is supported */
-#undef RISCV_ENABLE_RVC
-
/* Define if subproject MCPPBS_SPROJ_NORM is enabled */
#undef SOFTFLOAT_ENABLED
enable_stow
enable_optional_subprojects
with_fesvr
-enable_fpu
-enable_rvc
-enable_64bit
enable_commitlog
enable_histogram
'
--enable-stow Enable stow-based install
--enable-optional-subprojects
Enable all optional subprojects
- --disable-fpu Disable floating-point
- --disable-rvc Disable RISC-V Compressed
- --disable-64bit Disable 64-bit mode
--enable-commitlog Enable commit log generation
--enable-histogram Enable PC histogram generation
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
+$as_echo_n "checking for library containing dlopen... " >&6; }
+if ${ac_cv_search_dlopen+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+/* Override any GCC internal prototype to avoid an error.
+ Use char because int might match the return type of a GCC
+ builtin and then its argument prototype would still apply. */
+#ifdef __cplusplus
+extern "C"
+#endif
+char dlopen ();
+int
+main ()
+{
+return dlopen ();
+ ;
+ return 0;
+}
+_ACEOF
+for ac_lib in '' dl dld; do
+ if test -z "$ac_lib"; then
+ ac_res="none required"
+ else
+ ac_res=-l$ac_lib
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ fi
+ if ac_fn_cxx_try_link "$LINENO"; then :
+ ac_cv_search_dlopen=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext
+ if ${ac_cv_search_dlopen+:} false; then :
+ break
+fi
+done
+if ${ac_cv_search_dlopen+:} false; then :
+
+else
+ ac_cv_search_dlopen=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5
+$as_echo "$ac_cv_search_dlopen" >&6; }
+ac_res=$ac_cv_search_dlopen
+if test "$ac_res" != no; then :
+ test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+else
+
+ as_fn_error $? "unable to find the dlopen() function" "$LINENO" 5
+
+fi
+
+
# Check whether --with-fesvr was given.
if test "${with_fesvr+set}" = set; then :
fi
-# Check whether --enable-fpu was given.
-if test "${enable_fpu+set}" = set; then :
- enableval=$enable_fpu;
-fi
-
-if test "x$enable_fpu" != "xno"; then :
-
-
-$as_echo "#define RISCV_ENABLE_FPU /**/" >>confdefs.h
-
-
-fi
-
-# Check whether --enable-rvc was given.
-if test "${enable_rvc+set}" = set; then :
- enableval=$enable_rvc;
-fi
-
-if test "x$enable_rvc" != "xno"; then :
-
-
-$as_echo "#define RISCV_ENABLE_RVC /**/" >>confdefs.h
-
-
-fi
-
-# Check whether --enable-64bit was given.
-if test "${enable_64bit+set}" = set; then :
- enableval=$enable_64bit;
-fi
-
-if test "x$enable_64bit" != "xno"; then :
-
-
-$as_echo "#define RISCV_ENABLE_64BIT /**/" >>confdefs.h
-
-
-fi
-
# Check whether --enable-commitlog was given.
if test "${enable_commitlog+set}" = set; then :
enableval=$enable_commitlog;
$as_echo "#define SPIKE_MAIN_ENABLED /**/" >>confdefs.h
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing dlopen" >&5
-$as_echo_n "checking for library containing dlopen... " >&6; }
-if ${ac_cv_search_dlopen+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- ac_func_search_save_LIBS=$LIBS
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-/* Override any GCC internal prototype to avoid an error.
- Use char because int might match the return type of a GCC
- builtin and then its argument prototype would still apply. */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dlopen ();
-int
-main ()
-{
-return dlopen ();
- ;
- return 0;
-}
-_ACEOF
-for ac_lib in '' dl dld; do
- if test -z "$ac_lib"; then
- ac_res="none required"
- else
- ac_res=-l$ac_lib
- LIBS="-l$ac_lib $ac_func_search_save_LIBS"
- fi
- if ac_fn_cxx_try_link "$LINENO"; then :
- ac_cv_search_dlopen=$ac_res
-fi
-rm -f core conftest.err conftest.$ac_objext \
- conftest$ac_exeext
- if ${ac_cv_search_dlopen+:} false; then :
- break
-fi
-done
-if ${ac_cv_search_dlopen+:} false; then :
-
-else
- ac_cv_search_dlopen=no
-fi
-rm conftest.$ac_ext
-LIBS=$ac_func_search_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_dlopen" >&5
-$as_echo "$ac_cv_search_dlopen" >&6; }
-ac_res=$ac_cv_search_dlopen
-if test "$ac_res" != no; then :
- test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
-
-else
-
- as_fn_error $? "unable to find the dlopen() function" "$LINENO" 5
-
-fi
-
#define FSR_NXA (FPEXC_NX << FSR_AEXC_SHIFT)
#define FSR_AEXC (FSR_NVA | FSR_OFA | FSR_UFA | FSR_DZA | FSR_NXA)
-#ifdef RISCV_ENABLE_RVC
-# define INSN_ALIGNMENT 2
-# define require_rvc
-#else
-# define INSN_ALIGNMENT 4
-# define require_rvc throw trap_illegal_instruction()
-#endif
-
#define insn_length(x) \
(((x) & 0x03) < 0x03 ? 2 : \
((x) & 0x1f) < 0x1f ? 4 : \
#define require_privilege(p) if (get_field(STATE.mstatus, MSTATUS_PRV) < (p)) throw trap_illegal_instruction()
#define require_rv64 if(unlikely(xlen != 64)) throw trap_illegal_instruction()
#define require_rv32 if(unlikely(xlen != 32)) throw trap_illegal_instruction()
-#ifdef RISCV_ENABLE_FPU
-# define require_fp if (unlikely((STATE.mstatus & MSTATUS_FS) == 0)) throw trap_illegal_instruction()
-#else
-# define require_fp throw trap_illegal_instruction()
-#endif
+#define require_extension(s) if (!p->supports_extension(s)) throw trap_illegal_instruction()
+#define require_fp if (unlikely((STATE.mstatus & MSTATUS_FS) == 0)) throw trap_illegal_instruction()
#define require_accelerator if (unlikely((STATE.mstatus & MSTATUS_XS) == 0)) throw trap_illegal_instruction()
#define set_fp_exceptions ({ STATE.fflags |= softfloat_exceptionFlags; \
#define zext_xlen(x) (((reg_t)(x) << (64-xlen)) >> (64-xlen))
#define set_pc(x) \
- do { if ((x) & (INSN_ALIGNMENT-1)) \
+ do { if (unlikely(((x) & 2)) && !p->supports_extension('C')) \
throw trap_instruction_address_misaligned(x); \
npc = sext_xlen(x); \
} while(0)
#define VM_MBB 1
#define VM_MBBID 2
#define VM_SV32 4
-#define VM_SV43 5
+#define VM_SV39 5
+#define VM_SV48 6
#define UA_RV32 0
#define UA_RV64 4
#define PTE_R 0x040 // Referenced
#define PTE_D 0x080 // Dirty
#define PTE_SOFT 0x300 // Reserved for Software
-#define PTE_PPN_SHIFT 10
+#define RV64_PTE_PPN_SHIFT 26
+#define RV32_PTE_PPN_SHIFT 10
#define PTE_TYPE_INVALID 0
#define PTE_TYPE_TABLE 1
#define PTE_TYPE_U 2
# define MSTATUS_HA MSTATUS64_HA
# define MSTATUS_SD MSTATUS64_SD
# define SSTATUS_SD SSTATUS64_SD
-# define RISCV_PGLEVELS 3 /* Sv39 */
# define RISCV_PGLEVEL_BITS 9
+# define PTE_PPN_SHIFT RV64_PTE_PPN_SHIFT
#else
# define MSTATUS_SD MSTATUS32_SD
# define SSTATUS_SD SSTATUS32_SD
-# define RISCV_PGLEVELS 2 /* Sv32 */
# define RISCV_PGLEVEL_BITS 10
+# define PTE_PPN_SHIFT RV32_PTE_PPN_SHIFT
#endif
#define RISCV_PGSHIFT 12
#define RISCV_PGSIZE (1 << RISCV_PGSHIFT)
--- /dev/null
+#include "extension.h"
+#include <string>
+#include <map>
+#include <dlfcn.h>
+
+static std::map<std::string, std::function<extension_t*()>>& extensions()
+{
+ static std::map<std::string, std::function<extension_t*()>> v;
+ return v;
+}
+
+void register_extension(const char* name, std::function<extension_t*()> f)
+{
+ extensions()[name] = f;
+}
+
+std::function<extension_t*()> find_extension(const char* name)
+{
+ if (!extensions().count(name)) {
+ // try to find extension xyz by loading libxyz.so
+ std::string libname = std::string("lib") + name + ".so";
+ if (!dlopen(libname.c_str(), RTLD_LAZY)) {
+ fprintf(stderr, "couldn't find extension '%s' (or library '%s')\n",
+ name, libname.c_str());
+ exit(-1);
+ }
+ if (!extensions().count(name)) {
+ fprintf(stderr, "couldn't find extension '%s' in shared library '%s'\n",
+ name, libname.c_str());
+ exit(-1);
+ }
+ }
+
+ return extensions()[name];
+}
+require_extension('A');
require_rv64;
reg_t v = MMU.load_uint64(RS1);
MMU.store_uint64(RS1, RS2 + v);
+require_extension('A');
reg_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, RS2 + v);
WRITE_RD(v);
+require_extension('A');
require_rv64;
reg_t v = MMU.load_uint64(RS1);
MMU.store_uint64(RS1, RS2 & v);
+require_extension('A');
reg_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, RS2 & v);
WRITE_RD(v);
+require_extension('A');
require_rv64;
sreg_t v = MMU.load_int64(RS1);
MMU.store_uint64(RS1, std::max(sreg_t(RS2),v));
+require_extension('A');
int32_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, std::max(int32_t(RS2),v));
WRITE_RD(v);
+require_extension('A');
require_rv64;
reg_t v = MMU.load_uint64(RS1);
MMU.store_uint64(RS1, std::max(RS2,v));
+require_extension('A');
uint32_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, std::max(uint32_t(RS2),v));
WRITE_RD((int32_t)v);
+require_extension('A');
require_rv64;
sreg_t v = MMU.load_int64(RS1);
MMU.store_uint64(RS1, std::min(sreg_t(RS2),v));
+require_extension('A');
int32_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, std::min(int32_t(RS2),v));
WRITE_RD(v);
+require_extension('A');
require_rv64;
reg_t v = MMU.load_uint64(RS1);
MMU.store_uint64(RS1, std::min(RS2,v));
+require_extension('A');
uint32_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, std::min(uint32_t(RS2),v));
WRITE_RD((int32_t)v);
+require_extension('A');
require_rv64;
reg_t v = MMU.load_uint64(RS1);
MMU.store_uint64(RS1, RS2 | v);
+require_extension('A');
reg_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, RS2 | v);
WRITE_RD(v);
+require_extension('A');
require_rv64;
reg_t v = MMU.load_uint64(RS1);
MMU.store_uint64(RS1, RS2);
+require_extension('A');
reg_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, RS2);
WRITE_RD(v);
+require_extension('A');
require_rv64;
reg_t v = MMU.load_uint64(RS1);
MMU.store_uint64(RS1, RS2 ^ v);
+require_extension('A');
reg_t v = MMU.load_int32(RS1);
MMU.store_uint32(RS1, RS2 ^ v);
WRITE_RD(v);
-require_rvc;
+require_extension('C');
WRITE_RD(sext_xlen(RVC_RS1 + RVC_RS2));
-require_rvc;
+require_extension('C');
WRITE_RD(sext_xlen(RVC_RS2 + insn.rvc_imm()));
-require_rvc;
+require_extension('C');
WRITE_RD(sext_xlen(RVC_RS2 + insn.rvc_lwsp_imm()));
-require_rvc;
+require_extension('C');
require_rv64;
WRITE_RD(sext32(RVC_RS2 + insn.rvc_imm()));
-require_rvc;
+require_extension('C');
require_rv64;
WRITE_RD(sext32(RVC_RS1 + RVC_RS2));
-require_rvc;
+require_extension('C');
if (RVC_RS1S == 0)
set_pc(pc + insn.rvc_b_imm());
-require_rvc;
+require_extension('C');
if (RVC_RS1S != 0)
set_pc(pc + insn.rvc_b_imm());
-require_rvc;
+require_extension('C');
set_pc(pc + insn.rvc_j_imm());
-require_rvc;
+require_extension('C');
reg_t tmp = npc;
set_pc(RVC_RS1 & ~reg_t(1));
WRITE_RD(tmp);
-require_rvc;
+require_extension('C');
require_rv64;
WRITE_RVC_RDS(MMU.load_int64(RVC_RS1S + insn.rvc_ld_imm()));
-require_rvc;
+require_extension('C');
require_rv64;
WRITE_RD(MMU.load_int64(RVC_SP + insn.rvc_ldsp_imm()));
-require_rvc;
+require_extension('C');
if (insn.rvc_rd() == 0) {
if (insn.rvc_imm() == -32) // c.sbreak
throw trap_breakpoint();
-require_rvc;
+require_extension('C');
WRITE_RD(insn.rvc_imm() << 12);
-require_rvc;
+require_extension('C');
WRITE_RVC_RDS(MMU.load_int32(RVC_RS1S + insn.rvc_lw_imm()));
-require_rvc;
+require_extension('C');
WRITE_RD(MMU.load_int32(RVC_SP + insn.rvc_lwsp_imm()));
-require_rvc;
+require_extension('C');
WRITE_RD(RVC_RS1);
-require_rvc;
+require_extension('C');
require_rv64;
MMU.store_uint64(RVC_RS1S + insn.rvc_ld_imm(), RVC_RS2S);
-require_rvc;
+require_extension('C');
require_rv64;
MMU.store_uint64(RVC_SP + insn.rvc_ldsp_imm(), RVC_RS2);
-require_rvc;
+require_extension('C');
if (insn.rvc_imm() >= xlen)
throw trap_illegal_instruction();
WRITE_RD(sext_xlen(RVC_RS2 << insn.rvc_imm()));
-require_rvc;
+require_extension('C');
MMU.store_uint32(RVC_RS1S + insn.rvc_lw_imm(), RVC_RS2S);
-require_rvc;
+require_extension('C');
MMU.store_uint32(RVC_SP + insn.rvc_lwsp_imm(), RVC_RS2);
+require_extension('M');
sreg_t lhs = sext_xlen(RS1);
sreg_t rhs = sext_xlen(RS2);
if(rhs == 0)
+require_extension('M');
reg_t lhs = zext_xlen(RS1);
reg_t rhs = zext_xlen(RS2);
if(rhs == 0)
+require_extension('M');
require_rv64;
reg_t lhs = zext32(RS1);
reg_t rhs = zext32(RS2);
+require_extension('M');
require_rv64;
sreg_t lhs = sext32(RS1);
sreg_t rhs = sext32(RS2);
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_mulAdd(FRS1, 0x3ff0000000000000ULL, FRS2));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_mulAdd(FRS1, 0x3f800000, FRS2));
+require_extension('D');
require_fp;
WRITE_RD(f64_classify(FRS1));
+require_extension('F');
require_fp;
WRITE_RD(f32_classify(FRS1));
+require_extension('D');
require_rv64;
require_fp;
softfloat_roundingMode = RM;
+require_extension('D');
require_rv64;
require_fp;
softfloat_roundingMode = RM;
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_to_f64(FRS1));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(i32_to_f64((int32_t)RS1));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(ui32_to_f64((uint32_t)RS1));
+require_extension('D');
require_rv64;
require_fp;
softfloat_roundingMode = RM;
+require_extension('F');
require_rv64;
require_fp;
softfloat_roundingMode = RM;
+require_extension('D');
require_rv64;
require_fp;
softfloat_roundingMode = RM;
+require_extension('F');
require_rv64;
require_fp;
softfloat_roundingMode = RM;
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_to_f32(FRS1));
+require_extension('F');
require_rv64;
require_fp;
softfloat_roundingMode = RM;
+require_extension('F');
require_rv64;
require_fp;
softfloat_roundingMode = RM;
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(i32_to_f32((int32_t)RS1));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(ui32_to_f32((uint32_t)RS1));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_RD(sext32(f64_to_i32(FRS1, RM, true)));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_RD(sext32(f32_to_i32(FRS1, RM, true)));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_RD(sext32(f64_to_ui32(FRS1, RM, true)));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_RD(sext32(f32_to_ui32(FRS1, RM, true)));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_div(FRS1, FRS2));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_div(FRS1, FRS2));
+require_extension('D');
require_fp;
WRITE_RD(f64_eq(FRS1, FRS2));
set_fp_exceptions;
+require_extension('F');
require_fp;
WRITE_RD(f32_eq(FRS1, FRS2));
set_fp_exceptions;
+require_extension('D');
require_fp;
WRITE_FRD(MMU.load_int64(RS1 + insn.i_imm()));
+require_extension('D');
require_fp;
WRITE_RD(f64_le(FRS1, FRS2));
set_fp_exceptions;
+require_extension('F');
require_fp;
WRITE_RD(f32_le(FRS1, FRS2));
set_fp_exceptions;
+require_extension('D');
require_fp;
WRITE_RD(f64_lt(FRS1, FRS2));
set_fp_exceptions;
+require_extension('F');
require_fp;
WRITE_RD(f32_lt(FRS1, FRS2));
set_fp_exceptions;
+require_extension('F');
require_fp;
WRITE_FRD(MMU.load_int32(RS1 + insn.i_imm()));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_mulAdd(FRS1, FRS2, FRS3));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_mulAdd(FRS1, FRS2, FRS3));
+require_extension('D');
require_fp;
WRITE_FRD(isNaNF64UI(FRS2) || f64_le_quiet(FRS2,FRS1) /* && FRS1 not NaN */
? FRS1 : FRS2);
+require_extension('F');
require_fp;
WRITE_FRD(isNaNF32UI(FRS2) || f32_le_quiet(FRS2,FRS1) /* && FRS1 not NaN */
? FRS1 : FRS2);
+require_extension('D');
require_fp;
WRITE_FRD(isNaNF64UI(FRS2) || f64_lt_quiet(FRS1,FRS2) /* && FRS1 not NaN */
? FRS1 : FRS2);
+require_extension('F');
require_fp;
WRITE_FRD(isNaNF32UI(FRS2) || f32_lt_quiet(FRS1,FRS2) /* && FRS1 not NaN */
? FRS1 : FRS2);
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_mulAdd(FRS1, FRS2, FRS3 ^ (uint64_t)INT64_MIN));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_mulAdd(FRS1, FRS2, FRS3 ^ (uint32_t)INT32_MIN));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_mulAdd(FRS1, FRS2, (FRS1 ^ FRS2) & (uint64_t)INT64_MIN));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_mulAdd(FRS1, FRS2, (FRS1 ^ FRS2) & (uint32_t)INT32_MIN));
+require_extension('D');
require_rv64;
require_fp;
WRITE_FRD(RS1);
+require_extension('F');
require_fp;
WRITE_FRD(RS1);
+require_extension('D');
require_rv64;
require_fp;
WRITE_RD(FRS1);
+require_extension('F');
require_fp;
WRITE_RD(sext32(FRS1));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_mulAdd(FRS1 ^ (uint64_t)INT64_MIN, FRS2, FRS3 ^ (uint64_t)INT64_MIN));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_mulAdd(FRS1 ^ (uint32_t)INT32_MIN, FRS2, FRS3 ^ (uint32_t)INT32_MIN));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_mulAdd(FRS1 ^ (uint64_t)INT64_MIN, FRS2, FRS3));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_mulAdd(FRS1 ^ (uint32_t)INT32_MIN, FRS2, FRS3));
+require_extension('D');
require_fp;
MMU.store_uint64(RS1 + insn.s_imm(), FRS2);
+require_extension('D');
require_fp;
WRITE_FRD((FRS1 &~ INT64_MIN) | (FRS2 & INT64_MIN));
+require_extension('F');
require_fp;
WRITE_FRD((FRS1 &~ (uint32_t)INT32_MIN) | (FRS2 & (uint32_t)INT32_MIN));
+require_extension('D');
require_fp;
WRITE_FRD((FRS1 &~ INT64_MIN) | ((~FRS2) & INT64_MIN));
+require_extension('F');
require_fp;
WRITE_FRD((FRS1 &~ (uint32_t)INT32_MIN) | ((~FRS2) & (uint32_t)INT32_MIN));
+require_extension('D');
require_fp;
WRITE_FRD(FRS1 ^ (FRS2 & INT64_MIN));
+require_extension('F');
require_fp;
WRITE_FRD(FRS1 ^ (FRS2 & (uint32_t)INT32_MIN));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_sqrt(FRS1));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_sqrt(FRS1));
+require_extension('D');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f64_mulAdd(FRS1, 0x3ff0000000000000ULL, FRS2 ^ (uint64_t)INT64_MIN));
+require_extension('F');
require_fp;
softfloat_roundingMode = RM;
WRITE_FRD(f32_mulAdd(FRS1, 0x3f800000, FRS2 ^ (uint32_t)INT32_MIN));
+require_extension('F');
require_fp;
MMU.store_uint32(RS1 + insn.s_imm(), FRS2);
+require_extension('A');
require_rv64;
p->get_state()->load_reservation = RS1;
WRITE_RD(MMU.load_int64(RS1));
+require_extension('A');
p->get_state()->load_reservation = RS1;
WRITE_RD(MMU.load_int32(RS1));
+require_extension('M');
WRITE_RD(sext_xlen(RS1 * RS2));
+require_extension('M');
if (xlen == 64)
WRITE_RD(mulh(RS1, RS2));
else
+require_extension('M');
if (xlen == 64)
WRITE_RD(mulhsu(RS1, RS2));
else
+require_extension('M');
if (xlen == 64)
WRITE_RD(mulhu(RS1, RS2));
else
+require_extension('M');
require_rv64;
WRITE_RD(sext32(RS1 * RS2));
+require_extension('M');
sreg_t lhs = sext_xlen(RS1);
sreg_t rhs = sext_xlen(RS2);
if(rhs == 0)
+require_extension('M');
reg_t lhs = zext_xlen(RS1);
reg_t rhs = zext_xlen(RS2);
if(rhs == 0)
+require_extension('M');
require_rv64;
reg_t lhs = zext32(RS1);
reg_t rhs = zext32(RS2);
+require_extension('M');
require_rv64;
sreg_t lhs = sext32(RS1);
sreg_t rhs = sext32(RS2);
+require_extension('A');
require_rv64;
if (RS1 == p->get_state()->load_reservation)
{
+require_extension('A');
if (RS1 == p->get_state()->load_reservation)
{
MMU.store_uint32(RS1, RS2);
-WRITE_RD(RS1 < insn.i_imm());
+WRITE_RD(RS1 < reg_t(insn.i_imm()));
#include "sim.h"
#include "processor.h"
+#define LEVELS(xlen) ((xlen) == 32 ? 2 : 3)
+#define PPN_SHIFT(xlen) ((xlen) == 32 ? 10 : 26)
+#define PTIDXBITS(xlen) ((xlen) == 32 ? 10 : 9)
+#define VPN_BITS(xlen) (PTIDXBITS(xlen) * LEVELS(xlen))
+#define VA_BITS(xlen) (VPN_BITS(xlen) + PGSHIFT)
+
mmu_t::mmu_t(char* _mem, size_t _memsz)
: mem(_mem), memsz(_memsz), proc(NULL)
{
return mem + paddr;
}
-pte_t mmu_t::walk(reg_t addr, bool supervisor, bool store, bool fetch)
+reg_t mmu_t::walk(reg_t addr, bool supervisor, bool store, bool fetch)
{
- reg_t msb_mask = -(reg_t(1) << (VA_BITS-1));
+ reg_t msb_mask = -(reg_t(1) << (VA_BITS(proc->xlen) - 1));
if ((addr & msb_mask) != 0 && (addr & msb_mask) != msb_mask)
return -1; // address isn't properly sign-extended
reg_t base = proc->get_state()->sptbr;
- int ptshift = (LEVELS-1)*PTIDXBITS;
- for (reg_t i = 0; i < LEVELS; i++, ptshift -= PTIDXBITS) {
- reg_t idx = (addr >> (PGSHIFT+ptshift)) & ((1<<PTIDXBITS)-1);
+ int xlen = proc->max_xlen;
+ int ptshift = (LEVELS(xlen) - 1) * PTIDXBITS(xlen);
+ for (reg_t i = 0; i < LEVELS(xlen); i++, ptshift -= PTIDXBITS(xlen)) {
+ reg_t idx = (addr >> (PGSHIFT+ptshift)) & ((1<<PTIDXBITS(xlen))-1);
// check that physical address of PTE is legal
- reg_t pte_addr = base + idx*sizeof(pte_t);
+ reg_t pte_addr = base + idx*sizeof(reg_t);
if (pte_addr >= memsz)
return -1;
- pte_t* ppte = (pte_t*)(mem+pte_addr);
- reg_t ppn = *ppte >> PTE_PPN_SHIFT;
+ reg_t* ppte = (reg_t*)(mem+pte_addr);
+ reg_t ppn = *ppte >> PPN_SHIFT(xlen);
if ((*ppte & PTE_TYPE) == PTE_TYPE_TABLE) { // next level of page table
base = ppn << PGSHIFT;
#include <vector>
// virtual memory configuration
-typedef reg_t pte_t;
-const reg_t LEVELS = sizeof(pte_t) == 8 ? 3 : 2;
-const reg_t PGSHIFT = 12;
-const reg_t PTIDXBITS = PGSHIFT - (sizeof(pte_t) == 8 ? 3 : 2);
+#define PGSHIFT 12
const reg_t PGSIZE = 1 << PGSHIFT;
-const reg_t VPN_BITS = PTIDXBITS * LEVELS;
-const reg_t VA_BITS = VPN_BITS + PGSHIFT;
struct insn_fetch_t
{
void* refill_tlb(reg_t addr, reg_t bytes, bool store, bool fetch);
// perform a page table walk for a given VA; set referenced/dirty bits
- pte_t walk(reg_t addr, bool supervisor, bool store, bool fetch);
+ reg_t walk(reg_t addr, bool supervisor, bool store, bool fetch);
// translate a virtual address to a physical address
void* translate(reg_t addr, reg_t bytes, bool store, bool fetch)
#undef STATE
#define STATE state
-processor_t::processor_t(sim_t* _sim, mmu_t* _mmu, uint32_t _id)
- : sim(_sim), mmu(_mmu), ext(NULL), disassembler(new disassembler_t),
- id(_id), run(false), debug(false)
+processor_t::processor_t(const char* isa, sim_t* sim, uint32_t id)
+ : sim(sim), ext(NULL), disassembler(new disassembler_t),
+ id(id), run(false), debug(false)
{
- reset(true);
+ parse_isa_string(isa);
+
+ mmu = new mmu_t(sim->mem, sim->memsz);
mmu->set_processor(this);
+ reset(true);
+
#define DECLARE_INSN(name, match, mask) REGISTER_INSN(this, name, match, mask)
#include "encoding.h"
#undef DECLARE_INSN
}
#endif
+ delete mmu;
delete disassembler;
}
+static void bad_isa_string(const char* isa)
+{
+ fprintf(stderr, "error: bad --isa option %s\n", isa);
+ abort();
+}
+
+void processor_t::parse_isa_string(const char* isa)
+{
+ const char* p = isa;
+ const char* all_subsets = "IMAFDC";
+
+ max_xlen = 64;
+ if (strncmp(p, "RV32", 4) == 0)
+ max_xlen = 32, p += 4;
+ else if (strncmp(p, "RV64", 4) == 0)
+ p += 4;
+ else if (strncmp(p, "RV", 2) == 0)
+ p += 2;
+
+ if (!*p)
+ p = all_subsets;
+ else if (*p != 'I')
+ bad_isa_string(isa);
+
+ memset(subsets, 0, sizeof(subsets));
+
+ while (*p) {
+ if (auto next = strchr(all_subsets, *p)) {
+ subsets[(int)*p] = true;
+ all_subsets = next + 1;
+ p++;
+ } else if (*p == 'X') {
+ const char* ext = p+1, *end = ext;
+ while (islower(*end))
+ end++;
+ register_extension(find_extension(std::string(ext, end - ext).c_str())());
+ p = end;
+ } else {
+ bad_isa_string(isa);
+ }
+ }
+
+ if (supports_extension('D') && !supports_extension('F'))
+ bad_isa_string(isa);
+}
+
void state_t::reset()
{
memset(this, 0, sizeof(*this));
mstatus = set_field(mstatus, MSTATUS_PRV, PRV_M);
mstatus = set_field(mstatus, MSTATUS_PRV1, PRV_S);
mstatus = set_field(mstatus, MSTATUS_PRV2, PRV_S);
-#ifdef RISCV_ENABLE_64BIT
- mstatus = set_field(mstatus, MSTATUS64_UA, UA_RV64);
- mstatus = set_field(mstatus, MSTATUS64_SA, UA_RV64);
-#endif
pc = 0x100;
load_reservation = -1;
}
return;
run = !value;
- state.reset(); // reset the core
+ state.reset();
set_csr(CSR_MSTATUS, state.mstatus);
if (ext)
void processor_t::raise_interrupt(reg_t which)
{
- throw trap_t(((reg_t)1 << 63) | which);
+ throw trap_t(((reg_t)1 << (max_xlen-1)) | which);
}
void processor_t::take_interrupt()
return priv == PRV_U || priv == PRV_S || priv == PRV_M;
}
-static bool validate_arch(reg_t arch)
+static bool validate_arch(int max_xlen, reg_t arch)
{
-#ifdef RISCV_ENABLE_64BIT
- if (arch == UA_RV64) return true;
-#endif
+ if (max_xlen == 64 && arch == UA_RV64)
+ return true;
return arch == UA_RV32;
}
-static bool validate_vm(reg_t vm)
+static bool validate_vm(int max_xlen, reg_t vm)
{
- // TODO: VM_SV32 support
-#ifdef RISCV_ENABLE_64BIT
- if (vm == VM_SV43) return true;
-#endif
+ if (max_xlen == 64 && vm == VM_SV39)
+ return true;
+ if (max_xlen == 32 && vm == VM_SV32)
+ return true;
return vm == VM_MBARE;
}
mask |= MSTATUS_XS;
state.mstatus = (state.mstatus & ~mask) | (val & mask);
- if (validate_vm(get_field(val, MSTATUS_VM)))
+ if (validate_vm(max_xlen, get_field(val, MSTATUS_VM)))
state.mstatus = (state.mstatus & ~MSTATUS_VM) | (val & MSTATUS_VM);
if (validate_priv(get_field(val, MSTATUS_MPRV)))
state.mstatus = (state.mstatus & ~MSTATUS_MPRV) | (val & MSTATUS_MPRV);
state.mstatus = (state.mstatus & ~MSTATUS_PRV2) | (val & MSTATUS_PRV2);
if (validate_priv(get_field(val, MSTATUS_PRV3)))
state.mstatus = (state.mstatus & ~MSTATUS_PRV3) | (val & MSTATUS_PRV3);
- xlen = 32;
bool dirty = (state.mstatus & MSTATUS_FS) == MSTATUS_FS;
dirty |= (state.mstatus & MSTATUS_XS) == MSTATUS_XS;
-#ifndef RISCV_ENABLE_64BIT
- state.mstatus = set_field(state.mstatus, MSTATUS32_SD, dirty);
-#else
- state.mstatus = set_field(state.mstatus, MSTATUS64_SD, dirty);
-
- if (validate_arch(get_field(val, MSTATUS64_UA)))
- state.mstatus = (state.mstatus & ~MSTATUS64_UA) | (val & MSTATUS64_UA);
- if (validate_arch(get_field(val, MSTATUS64_SA)))
- state.mstatus = (state.mstatus & ~MSTATUS64_SA) | (val & MSTATUS64_SA);
- switch (get_field(state.mstatus, MSTATUS_PRV)) {
- case PRV_U: if (get_field(state.mstatus, MSTATUS64_UA)) xlen = 64; break;
- case PRV_S: if (get_field(state.mstatus, MSTATUS64_SA)) xlen = 64; break;
- case PRV_M: xlen = 64; break;
- default: abort();
+ xlen = 32;
+ if (max_xlen == 32) {
+ state.mstatus = set_field(state.mstatus, MSTATUS32_SD, dirty);
+ } else {
+ state.mstatus = set_field(state.mstatus, MSTATUS64_SD, dirty);
+
+ if (validate_arch(max_xlen, get_field(val, MSTATUS64_UA)))
+ state.mstatus = (state.mstatus & ~MSTATUS64_UA) | (val & MSTATUS64_UA);
+ if (validate_arch(max_xlen, get_field(val, MSTATUS64_SA)))
+ state.mstatus = (state.mstatus & ~MSTATUS64_SA) | (val & MSTATUS64_SA);
+ switch (get_field(state.mstatus, MSTATUS_PRV)) {
+ case PRV_U: if (get_field(state.mstatus, MSTATUS64_UA)) xlen = 64; break;
+ case PRV_S: if (get_field(state.mstatus, MSTATUS64_SA)) xlen = 64; break;
+ case PRV_M: xlen = 64; break;
+ default: abort();
+ }
}
-#endif
break;
}
case CSR_SSTATUS:
case CSR_STVEC: return state.stvec;
case CSR_STIMECMP: return state.stimecmp;
case CSR_SCAUSE:
- if (xlen == 32 && (state.scause >> 63) != 0)
- return state.scause | ((reg_t)1 << 31);
+ if (max_xlen > xlen)
+ return state.scause | ((state.scause >> (max_xlen-1)) << (xlen-1));
return state.scause;
case CSR_SPTBR: return state.sptbr;
case CSR_SASID: return 0;
class processor_t
{
public:
- processor_t(sim_t* _sim, mmu_t* _mmu, uint32_t _id);
+ processor_t(const char* isa, sim_t* sim, uint32_t id);
~processor_t();
void set_debug(bool value);
mmu_t* get_mmu() { return mmu; }
state_t* get_state() { return &state; }
extension_t* get_extension() { return ext; }
+ bool supports_extension(unsigned char ext) { return subsets[ext]; }
void push_privilege_stack();
void pop_privilege_stack();
void yield_load_reservation() { state.load_reservation = (reg_t)-1; }
extension_t* ext;
disassembler_t* disassembler;
state_t state;
+ bool subsets[256];
uint32_t id;
+ int max_xlen;
int xlen;
bool run; // !reset
bool debug;
friend class mmu_t;
friend class extension_t;
+ void parse_isa_string(const char* isa);
void build_opcode_map();
insn_func_t decode_insn(insn_t insn);
};
AC_LANG_CPLUSPLUS
+AC_SEARCH_LIBS([dlopen], [dl dld], [], [
+ AC_MSG_ERROR([unable to find the dlopen() function])
+])
+
AC_ARG_WITH([fesvr],
[AS_HELP_STRING([--with-fesvr],
[path to your fesvr installation if not in a standard location])],
AC_CHECK_LIB(pthread, pthread_create, [], [AC_MSG_ERROR([libpthread is required])])
-AC_ARG_ENABLE([fpu], AS_HELP_STRING([--disable-fpu], [Disable floating-point]))
-AS_IF([test "x$enable_fpu" != "xno"], [
- AC_DEFINE([RISCV_ENABLE_FPU],,[Define if floating-point instructions are supported])
-])
-
-AC_ARG_ENABLE([rvc], AS_HELP_STRING([--disable-rvc], [Disable RISC-V Compressed]))
-AS_IF([test "x$enable_rvc" != "xno"], [
- AC_DEFINE([RISCV_ENABLE_RVC],,[Define if RISC-V Compressed is supported])
-])
-
-AC_ARG_ENABLE([64bit], AS_HELP_STRING([--disable-64bit], [Disable 64-bit mode]))
-AS_IF([test "x$enable_64bit" != "xno"], [
- AC_DEFINE([RISCV_ENABLE_64BIT],,[Define if 64-bit mode is supported])
-])
-
AC_ARG_ENABLE([commitlog], AS_HELP_STRING([--enable-commitlog], [Enable commit log generation]))
AS_IF([test "x$enable_commitlog" = "xyes"], [
AC_DEFINE([RISCV_ENABLE_COMMITLOG],,[Enable commit log generation])
mmu.cc \
disasm.cc \
extension.cc \
+ extensions.cc \
rocc.cc \
regnames.cc \
$(riscv_gen_srcs) \
riscv_test_srcs =
riscv_gen_hdrs = \
- icache.h \
+ icache.h \
riscv_gen_srcs = \
$(addsuffix .cc, $(call get_insn_list,$(src_dir)/riscv/encoding.h))
signal(sig, &handle_signal);
}
-sim_t::sim_t(size_t nprocs, size_t mem_mb, const std::vector<std::string>& args)
+sim_t::sim_t(const char* isa, size_t nprocs, size_t mem_mb,
+ const std::vector<std::string>& args)
: htif(new htif_isasim_t(this, args)), procs(std::max(nprocs, size_t(1))),
current_step(0), current_proc(0), debug(false)
{
debug_mmu = new mmu_t(mem, memsz);
- for (size_t i = 0; i < procs.size(); i++) {
- procs[i] = new processor_t(this, new mmu_t(mem, memsz), i);
- }
-
+ for (size_t i = 0; i < procs.size(); i++)
+ procs[i] = new processor_t(isa, this, i);
}
sim_t::~sim_t()
{
for (size_t i = 0; i < procs.size(); i++)
- {
- mmu_t* pmmu = procs[i]->get_mmu();
delete procs[i];
- delete pmmu;
- }
delete debug_mmu;
free(mem);
}
class sim_t
{
public:
- sim_t(size_t _nprocs, size_t mem_mb, const std::vector<std::string>& htif_args);
+ sim_t(const char* isa, size_t _nprocs, size_t mem_mb,
+ const std::vector<std::string>& htif_args);
~sim_t();
// run the simulation to completion
reg_t get_tohost(const std::vector<std::string>& args);
friend class htif_isasim_t;
+ friend class processor_t;
};
extern volatile bool ctrlc_pressed;
+++ /dev/null
-#include "extension.h"
-#include <string>
-#include <map>
-#include <dlfcn.h>
-
-static std::map<std::string, std::function<extension_t*()>>& extensions()
-{
- static std::map<std::string, std::function<extension_t*()>> v;
- return v;
-}
-
-void register_extension(const char* name, std::function<extension_t*()> f)
-{
- extensions()[name] = f;
-}
-
-std::function<extension_t*()> find_extension(const char* name)
-{
- if (!extensions().count(name)) {
- // try to find extension xyz by loading libxyz.so
- std::string libname = std::string("lib") + name + ".so";
- if (!dlopen(libname.c_str(), RTLD_LAZY)) {
- fprintf(stderr, "couldn't find extension '%s' (or library '%s')\n",
- name, libname.c_str());
- exit(-1);
- }
- if (!extensions().count(name)) {
- fprintf(stderr, "couldn't find extension '%s' in shared library '%s'\n",
- name, libname.c_str());
- exit(-1);
- }
- }
-
- return extensions()[name];
-}
{
fprintf(stderr, "usage: spike [host options] <target program> [target options]\n");
fprintf(stderr, "Host Options:\n");
- fprintf(stderr, " -p <n> Simulate <n> processors\n");
- fprintf(stderr, " -m <n> Provide <n> MB of target memory\n");
+ fprintf(stderr, " -p <n> Simulate <n> processors [default 1]\n");
+ fprintf(stderr, " -m <n> Provide <n> MiB of target memory [default 4096]\n");
fprintf(stderr, " -d Interactive debug mode\n");
fprintf(stderr, " -g Track histogram of PCs\n");
fprintf(stderr, " -h Print this help message\n");
+ fprintf(stderr, " --isa=<name> RISC-V ISA string [default RV64IMAFDC]\n");
fprintf(stderr, " --ic=<S>:<W>:<B> Instantiate a cache model with S sets,\n");
fprintf(stderr, " --dc=<S>:<W>:<B> W ways, and B-byte blocks (with S and\n");
fprintf(stderr, " --l2=<S>:<W>:<B> B both powers of 2).\n");
std::unique_ptr<dcache_sim_t> dc;
std::unique_ptr<cache_sim_t> l2;
std::function<extension_t*()> extension;
+ const char* isa = "RV64";
option_parser_t parser;
parser.help(&help);
parser.option(0, "ic", 1, [&](const char* s){ic.reset(new icache_sim_t(s));});
parser.option(0, "dc", 1, [&](const char* s){dc.reset(new dcache_sim_t(s));});
parser.option(0, "l2", 1, [&](const char* s){l2.reset(cache_sim_t::construct(s, "L2$"));});
+ parser.option(0, "isa", 1, [&](const char* s){isa = s;});
parser.option(0, "extension", 1, [&](const char* s){extension = find_extension(s);});
parser.option(0, "extlib", 1, [&](const char *s){
void *lib = dlopen(s, RTLD_NOW | RTLD_GLOBAL);
if (!*argv1)
help();
std::vector<std::string> htif_args(argv1, (const char*const*)argv + argc);
- sim_t s(nprocs, mem_mb, htif_args);
+ sim_t s(isa, nprocs, mem_mb, htif_args);
if (ic && l2) ic->set_miss_handler(&*l2);
if (dc && l2) dc->set_miss_handler(&*l2);
-AC_SEARCH_LIBS([dlopen], [dl dld], [], [
- AC_MSG_ERROR([unable to find the dlopen() function])
-])
spike_main_hdrs = \
spike_main_srcs = \
- extensions.cc \