2016-05-04 07:21:39 +08:00
|
|
|
RISCV_TOOLS_DIR = /opt/riscv32imc
|
|
|
|
RISCV_TOOLS_PREFIX = $(RISCV_TOOLS_DIR)/bin/riscv32-unknown-elf-
|
2016-05-03 22:53:22 +08:00
|
|
|
CSMITH_INCDIR = $(shell ls -d /usr/local/include/csmith-* | head -n1)
|
|
|
|
CC = $(RISCV_TOOLS_PREFIX)gcc
|
2016-05-04 19:34:32 +08:00
|
|
|
SHELL = /bin/bash
|
2016-05-03 22:53:22 +08:00
|
|
|
|
2016-05-04 19:34:32 +08:00
|
|
|
help:
|
|
|
|
@echo "Usage: make { loop | verilator | iverilog | spike }"
|
|
|
|
|
|
|
|
loop:
|
|
|
|
+set -e; x() { echo "$$*" >&2; "$$@"; }; while true; do \
|
|
|
|
echo; echo; rm -f output_ref.txt output_sim.txt; \
|
|
|
|
echo "-----------------------------------------"; \
|
|
|
|
x rm -f test.hex test.elf test.c test_ref test.ld; \
|
|
|
|
x $(MAKE) test_ref test.hex obj_dir/Vtestbench; \
|
|
|
|
x timeout 1 ./test_ref > >( tee output_ref.txt; ) || { echo TIMEOUT; continue; }; \
|
|
|
|
x obj_dir/Vtestbench > >( tee /dev/stderr | grep -v '$$finish' > output_sim.txt; ); \
|
|
|
|
sleep 1; x diff -u output_ref.txt output_sim.txt; echo "OK."; \
|
|
|
|
done
|
|
|
|
|
|
|
|
verilator: test_ref test.hex obj_dir/Vtestbench
|
|
|
|
./test_ref | tee output_ref.txt
|
|
|
|
obj_dir/Vtestbench | grep -v '$$finish' | tee output_sim.txt
|
|
|
|
diff -u output_ref.txt output_sim.txt
|
|
|
|
|
|
|
|
iverilog: test_ref test.hex testbench.vvp
|
2016-05-04 14:57:16 +08:00
|
|
|
./test_ref | tee output_ref.txt
|
|
|
|
vvp -N testbench.vvp | tee output_sim.txt
|
2016-05-03 22:53:22 +08:00
|
|
|
diff -u output_ref.txt output_sim.txt
|
|
|
|
|
2016-05-04 16:34:51 +08:00
|
|
|
spike: riscv-fesvr/build.ok riscv-isa-sim/build.ok test_ref test.elf
|
|
|
|
./test_ref | tee output_ref.txt
|
2016-05-04 19:34:32 +08:00
|
|
|
LD_LIBRARY_PATH="./riscv-isa-sim:./riscv-fesvr" ./riscv-isa-sim/spike test.elf | tee output_sim.txt
|
|
|
|
diff -u output_ref.txt output_sim.txt
|
2016-05-04 07:21:39 +08:00
|
|
|
|
|
|
|
riscv-fesvr/build.ok:
|
|
|
|
rm -rf riscv-fesvr
|
|
|
|
git clone https://github.com/riscv/riscv-fesvr.git riscv-fesvr
|
|
|
|
+cd riscv-fesvr && git checkout 1c02bd6 && ./configure && make && touch build.ok
|
|
|
|
|
|
|
|
riscv-isa-sim/build.ok: riscv-fesvr/build.ok
|
|
|
|
rm -rf riscv-isa-sim
|
|
|
|
git clone https://github.com/riscv/riscv-isa-sim.git riscv-isa-sim
|
|
|
|
cd riscv-isa-sim && git checkout 10ae74e
|
|
|
|
cd riscv-isa-sim && patch -p1 < ../riscv-isa-sim-exit.diff
|
2016-05-04 15:10:58 +08:00
|
|
|
cd riscv-isa-sim && patch -p1 < ../riscv-isa-sim-console.diff
|
2016-05-04 07:21:39 +08:00
|
|
|
cd riscv-isa-sim && LDFLAGS="-L../riscv-fesvr" ./configure --with-isa=RV32IMC
|
|
|
|
+cd riscv-isa-sim && ln -s ../riscv-fesvr/fesvr . && make && touch build.ok
|
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
testbench.vvp: testbench.v ../../picorv32.v
|
|
|
|
iverilog -o testbench.vvp testbench.v ../../picorv32.v
|
|
|
|
chmod -x testbench.vvp
|
2016-05-03 22:53:22 +08:00
|
|
|
|
2016-05-04 19:34:32 +08:00
|
|
|
obj_dir/Vtestbench: testbench.v testbench.cc ../../picorv32.v
|
|
|
|
verilator --exe -Wno-fatal --cc --top-module testbench testbench.v ../../picorv32.v testbench.cc
|
|
|
|
$(MAKE) -C obj_dir -f Vtestbench.mk
|
|
|
|
|
2016-05-04 07:21:39 +08:00
|
|
|
test.hex: test.elf
|
|
|
|
$(RISCV_TOOLS_PREFIX)objcopy -O verilog test.elf test.hex
|
2016-05-03 22:53:22 +08:00
|
|
|
|
|
|
|
start.elf: start.S start.ld
|
|
|
|
$(CC) -nostdlib -o start.elf start.S -T start.ld
|
|
|
|
chmod -x start.elf
|
|
|
|
|
2016-05-04 14:57:16 +08:00
|
|
|
test_ref: test.c
|
|
|
|
gcc -m32 -o test_ref -w -Os -I $(CSMITH_INCDIR) test.c
|
2016-05-03 22:53:22 +08:00
|
|
|
|
2016-05-04 07:21:39 +08:00
|
|
|
test.elf: test.c syscalls.c start.S
|
|
|
|
sed -e '/SECTIONS/,+1 s/{/{ . = 0x00000000; .start : { *(.text.start) } application_entry_point = 0x00010000;/;' \
|
|
|
|
$(RISCV_TOOLS_DIR)/riscv32-unknown-elf/lib/riscv.ld > test.ld
|
|
|
|
$(CC) -o test.elf -w -Os -I $(CSMITH_INCDIR) -T test.ld test.c syscalls.c start.S
|
2016-05-03 22:53:22 +08:00
|
|
|
chmod -x test.elf
|
|
|
|
|
|
|
|
test.c:
|
|
|
|
echo "integer size = 4" > platform.info
|
|
|
|
echo "pointer size = 4" >> platform.info
|
2016-05-04 16:34:51 +08:00
|
|
|
csmith --no-packed-struct -o test.c
|
2016-05-03 22:53:22 +08:00
|
|
|
|
|
|
|
clean:
|
2016-05-04 19:34:32 +08:00
|
|
|
rm -rf platform.info test.c test.ld test.elf test.hex test_ref obj_dir
|
|
|
|
rm -rf testbench.vvp testbench.vcd output_ref.txt output_sim.txt
|
2016-05-03 22:53:22 +08:00
|
|
|
|
2016-05-04 07:21:39 +08:00
|
|
|
mrproper: clean
|
|
|
|
rm -rf riscv-fesvr riscv-isa-sim
|
|
|
|
|
2016-05-04 19:34:32 +08:00
|
|
|
.PHONY: help loop verilator iverilog spike clean mrproper
|
2016-05-04 07:21:39 +08:00
|
|
|
|