direnv allow .
Develop inside Devcontainer
or
use Dockerfile
docker build . -t riscv/mycpu
docker run -it -v $PWD/mycpu:/mycpu riscv/mycpu
or
use existing image
docker pull yutaronishiyama/riscv-chisel-book
docker run -it -v $PWD/mycpu:/mycpu yutaronishiyama/riscv-chisel-book
scalafmt
In Docker
Change file path of Memory.scala
cd /mycpu
sbt "testOnly fetch.HexTest"
sbt "testOnly decode.HexTest"
sbt "testOnly lw.HexTest"
sbt "testOnly sw.HexTest"
change the starting address in /opt/riscv/riscv-tests/env/p/link.ld
:
SECTIONS
{
. = 0x00000000; // from 0x80000000
...
}
Run the following commands:
cd /opt/riscv/riscv-tests
autoconf
./configure --prefix=/src/target
make
make install
ELF and dump files will be generated in /src/target/share/riscv-tests/isa/
. We will be using
rv32ui-p-
(for user-level instructions)rv32um-p-
(for machine-level instructions)
Convert ELF file into BIN files:
mkdir /mycpu/src/riscv
cd /mycpu/src/riscv
riscv64-unknown-elf-objcopy -O binary /src/target/share/riscv-tests/isa/rv32ui-p-add rv32ui-p-add.bin
od -An -tx1 -w1 -v rv32ui-p-add.bin >> rv32ui-p-add.hex
Run
sbt "testOnly riscvtests.RiscvTest"
Automate making hex
files
cd /mycpu/src/shell
./tohex.sh
./riscv_tests.sh
The results will be in mycpu/results
compile C code
cd /mycpu/src/c
riscv64-unknown-elf-gcc \
-march=rv32i \ # specify ISA
-mabi=ilp32 \ # specify ABI
-c \ # compile only, not link
-o ctest.o ctest.c
link it
riscv64-unknown-elf-ld -b elf32-littleriscv ctest.o -T link.ld -o ctest
riscv64-unknown-elf-objcopy -O binary ctest ctest.bin
od -An -tx1 -w1 -v ctest.bin > ../hex/ctest.hex
riscv64-unknown-elf-objdump -b elf32-littleriscv -D ctest > ../dump/ctest.elf.dmp
test it
cd /mycpu
sbt "testOnly ctest.HexTest"
compile br_hazard
cd /mycpu/src/c
make br_hazard
cd /mycpu
sbt "testOnly pipeline.HexTest"
sbt "testOnly pipeline_brhazard.HexTest"
compile hazard_wb
cd /mycpu/src/c
make hazard_wb
cd /mycpu
sbt "testOnly pipeline_datahazard.HexTest"
cd /mycpu/src/shell
./riscv_tests.sh pipeline_datahazard 09_pipeline_datahazard