Skip to content

Commit

Permalink
Merge pull request #1080 from Liaoshihua/spike-toolchain
Browse files Browse the repository at this point in the history
Change default simulator from qemu to spike.
  • Loading branch information
kito-cheng authored Jun 2, 2022
2 parents 1342cd7 + 5a2b88b commit 71e9e38
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 22 deletions.
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@
path = musl
url = git://git.musl-libc.org/musl
branch = master
[submodule "spike"]
path = spike
url = https://github.com/riscv-software-src/riscv-isa-sim.git
branch = master
[submodule "pk"]
path = pk
url = https://github.com/riscv-software-src/riscv-pk.git
branch = master
34 changes: 16 additions & 18 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ MUSL_SRCDIR := @with_musl_src@
LINUX_HEADERS_SRCDIR := @with_linux_headers_src@
GDB_SRCDIR := @with_gdb_src@
QEMU_SRCDIR := @with_qemu_src@
SPIKE_SRCDIR := @with_spike_src@
PK_SRCDIR := @with_pk_src@

SIM:=qemu

# Default branch for proxy kernel and spike
SPIKE_BRANCH:=master
PK_BRANCH:=master
SIM ?= @WITH_SIM@

ifeq ($(srcdir)/riscv-gcc,$(GCC_SRCDIR))
# We need a relative source dir for the gcc configure, to make msys2 mingw64
Expand Down Expand Up @@ -180,7 +178,7 @@ else
ifeq ($(SIM),spike)
# Using spike simulator.
SIM_PATH:=$(srcdir)/scripts/wrapper/spike
SIM_PREPARE:=PATH="$(SIM_PATH):$(INSTALL_DIR)/bin:$(PATH)" PK_PATH="$(INSTALL_DIR)/$(NEWLIB_TUPLE)/bin/"
SIM_PREPARE:=PATH="$(SIM_PATH):$(INSTALL_DIR)/bin:$(PATH)" PK_PATH="$(INSTALL_DIR)/$(NEWLIB_TUPLE)/bin/" ARCH_STR="$(WITH_ARCH)"
SIM_STAMP:= stamps/build-spike
ifneq (,$(findstring rv32,$(NEWLIB_MULTILIB_NAMES)))
SIM_STAMP+= stamps/build-pk32
Expand Down Expand Up @@ -259,6 +257,12 @@ else
QEMU_SRC_GIT :=
endif

ifeq ($(findstring $(srcdir),$(SPIKE_SRCDIR)),$(srcdir))
SPIKE_SRC_GIT := $(SPIKE_SRCDIR)/.git
else
SPIKE_SRC_GIT :=
endif

ifneq ("$(wildcard $(GCC_SRCDIR)/.git)","")
GCCPKGVER := g$(shell git -C $(GCC_SRCDIR) describe --always --dirty --exclude '*')
else
Expand Down Expand Up @@ -804,26 +808,20 @@ stamps/build-gcc-musl-stage2: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-musl-lin
cp -a $(INSTALL_DIR)/$(MUSL_TUPLE)/lib* $(SYSROOT)
mkdir -p $(dir $@) && touch $@

spike-src:
git clone https://github.com/riscv/riscv-isa-sim.git -b $(SPIKE_BRANCH) $@

pk-src:
git clone https://github.com/riscv/riscv-pk.git -b $(PK_BRANCH) $@

stamps/build-spike: spike-src
stamps/build-spike: $(SPIKE_SRCDIR) $(SPIKE_SRC_GIT)
rm -rf $@ $(notdir $@)
mkdir $(notdir $@)
cd $(notdir $@) && ../$</configure \
cd $(notdir $@) && $</configure \
--prefix=$(INSTALL_DIR)
$(MAKE) -C $(notdir $@)
$(MAKE) -C $(notdir $@) install
mkdir -p $(dir $@)
date > $@

stamps/build-pk32: pk-src stamps/build-gcc-newlib-stage2
stamps/build-pk32: $(PK_SRCDIR) stamps/build-gcc-newlib-stage2
rm -rf $@ $(notdir $@)
mkdir $(notdir $@)
cd $(notdir $@) && ../$</configure \
cd $(notdir $@) && $</configure \
--prefix=$(INSTALL_DIR) \
--host=$(NEWLIB_TUPLE) \
--with-arch=rv32gc
Expand All @@ -832,10 +830,10 @@ stamps/build-pk32: pk-src stamps/build-gcc-newlib-stage2
mkdir -p $(dir $@)
date > $@

stamps/build-pk64: pk-src stamps/build-gcc-newlib-stage2
stamps/build-pk64: $(PK_SRCDIR) stamps/build-gcc-newlib-stage2
rm -rf $@ $(notdir $@)
mkdir $(notdir $@)
cd $(notdir $@) && ../$</configure \
cd $(notdir $@) && $</configure \
--prefix=$(INSTALL_DIR) \
--host=$(NEWLIB_TUPLE) \
--with-arch=rv64gc
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ rv64imac with lp64 and rv64imafc with lp64 will reuse this multi-lib set.
The Dejagnu test suite has been ported to RISC-V. This can be run with a
simulator for the elf and linux toolchains. The simulator can be selected
by the SIM variable in the Makefile, e.g. SIM=qemu, SIM=gdb, or SIM=spike
(experimental). However, the testsuite allowlist is only mintained for qemu.
Other simulators might get extra failures.
(experimental).In addition, the simulator can also be selected with the
configure time option `--with-sim=`.However, the testsuite allowlist is
only mintained for qemu.Other simulators might get extra failures.
To test GCC, run the following commands:

./configure --prefix=$RISCV --disable-linux --with-arch=rv64ima # or --with-arch=rv32ima
Expand All @@ -201,6 +202,10 @@ To test GCC, run the following commands:
make linux
make report-linux SIM=qemu # Run with qemu

./configure --prefix=$RISCV --with-sim=spike
make linux
make report # Run with spike

Note:
- spike only support rv64* bare-metal/elf toolchain.
- gdb simulator only support bare-metal/elf toolchain.
Expand Down Expand Up @@ -263,3 +268,5 @@ Here is the list of configure option for specify source tree:
--with-gdb-src
--with-linux-headers-src
--with-qemu-src
--with-spike-src
--with-pk-src
59 changes: 59 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ LIBOBJS
qemu_targets
enable_libsanitizer
with_linux_headers_src
with_pk_src
with_spike_src
with_qemu_src
with_gdb_src
with_musl_src
Expand All @@ -607,6 +609,7 @@ newlib_multilib_names
glibc_multilib_names
multilib_flags
multilib_gen
WITH_SIM
WITH_ISA_SPEC
WITH_TUNE
WITH_ABI
Expand Down Expand Up @@ -676,6 +679,7 @@ with_arch
with_abi
with_tune
with_isa_spec
with_sim
enable_multilib
with_multilib_generator
enable_gcc_checking
Expand All @@ -693,6 +697,8 @@ with_glibc_src
with_musl_src
with_gdb_src
with_qemu_src
with_spike_src
with_pk_src
with_linux_headers_src
enable_libsanitizer
enable_qemu_system
Expand Down Expand Up @@ -1344,6 +1350,7 @@ Optional Packages:
--with-tune=rocket Set the base RISC-V CPU, defaults to rocket
--with-isa-spec=2.2 Set the default ISA spec version, default to 2.2,
available options: 2.2, 20190608, 20191213
--with-sim=qemu Sets the base RISC-V Simulator, defaults to qemu
--with-multilib-generator
Multi-libs configuration string, only supported for
bare-metal/elf toolchain, this option implied
Expand All @@ -1366,6 +1373,8 @@ Optional Packages:
--with-musl-src Set musl source path, use builtin source by default
--with-gdb-src Set gdb source path, use builtin source by default
--with-qemu-src Set qemu source path, use builtin source by default
--with-spike-src Set spike source path, use builtin source by default
--with-pk-src Set pk source path, use builtin source by default
--with-linux-headers-src
Set linux-headers source path, use builtin source by
default
Expand Down Expand Up @@ -3322,6 +3331,16 @@ else
fi
# Check whether --with-sim was given.
if test "${with_sim+set}" = set; then :
withval=$with_sim;
else
with_sim=qemu
fi
if test "x$with_abi" = xdefault; then :
case $with_arch in #(
*rv64g* | *rv64*d*) :
Expand Down Expand Up @@ -3352,6 +3371,8 @@ WITH_TUNE=--with-tune=$with_tune
WITH_ISA_SPEC=--with-isa-spec=$with_isa_spec
WITH_SIM=$with_sim
# Check whether --enable-multilib was given.
if test "${enable_multilib+set}" = set; then :
Expand Down Expand Up @@ -3667,6 +3688,44 @@ fi
else
with_qemu_src="\$(srcdir)/qemu"
fi
}
{
# Check whether --with-spike-src was given.
if test "${with_spike_src+set}" = set; then :
withval=$with_spike_src;
else
with_spike_src=default
fi
if test "x$with_spike_src" != xdefault; then :
with_spike_src=$with_spike_src
else
with_spike_src="\$(srcdir)/spike"
fi
}
{
# Check whether --with-pk-src was given.
if test "${with_pk_src+set}" = set; then :
withval=$with_pk_src;
else
with_pk_src=default
fi
if test "x$with_pk_src" != xdefault; then :
with_pk_src=$with_pk_src
else
with_pk_src="\$(srcdir)/pk"
fi
}
Expand Down
10 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ AC_ARG_WITH(isa-spec,
[with_isa_spec=2.2]
)

AC_ARG_WITH(sim,
[AS_HELP_STRING([--with-sim=qemu],
[Sets the base RISC-V Simulator, defaults to qemu])],
[],
[with_sim=qemu]
)

AS_IF([test "x$with_abi" = xdefault],
[AS_CASE([$with_arch],
[*rv64g* | *rv64*d*], [with_abi=lp64d],
Expand All @@ -94,6 +101,7 @@ AC_SUBST(WITH_ARCH, --with-arch=$with_arch)
AC_SUBST(WITH_ABI, --with-abi=$with_abi)
AC_SUBST(WITH_TUNE, --with-tune=$with_tune)
AC_SUBST(WITH_ISA_SPEC, --with-isa-spec=$with_isa_spec)
AC_SUBST(WITH_SIM, $with_sim)

AC_ARG_ENABLE(multilib,
[AS_HELP_STRING([--enable-multilib],
Expand Down Expand Up @@ -234,6 +242,8 @@ AX_ARG_WITH_SRC(glibc, glibc)
AX_ARG_WITH_SRC(musl, musl)
AX_ARG_WITH_SRC(gdb, riscv-gdb)
AX_ARG_WITH_SRC(qemu, qemu)
AX_ARG_WITH_SRC(spike, spike)
AX_ARG_WITH_SRC(pk, pk)

AC_ARG_WITH(linux-headers-src,
[AC_HELP_STRING([--with-linux-headers-src],
Expand Down
1 change: 1 addition & 0 deletions pk
Submodule pk added at 2efabd
4 changes: 2 additions & 2 deletions scripts/wrapper/spike/riscv64-unknown-linux-gnu-run
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

xlen="$(readelf -h $1 | grep 'Class' | cut -d: -f 2 | xargs echo | sed 's/^ELF//')"

arch="${ARCH_STR#*=}"
spike \
--isa=RV${xlen}GC \
--isa=${arch} \
${PK_PATH}/pk${xlen} "$@"
1 change: 1 addition & 0 deletions spike
Submodule spike added at a0298a

0 comments on commit 71e9e38

Please sign in to comment.