-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·73 lines (66 loc) · 2.26 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·73 lines (66 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
operation="$1"
filepath="$2"
dirpath=$(dirname -- "$filepath")
filename=$(basename -- "$filepath")
name="${filename%.*}" # Extracts the file name without extension
if [[ $# -lt 2 && "$operation" != "riscv-testsuite" ]]; then
echo "Usage: $0 {targets} <filepath>"
echo "targets:"
printf "\tbin:\tCreates a stripped elf binary from an asm file\n"
printf "\trun:\tBuilds binary and runs it, from an asm file\n"
printf "\triscv-testsuite:\tRuns official riscv testsuite, requires RISCV_TESTSUITE env var to be set to installation\n"
printf "\tobjdump:\tPrints disassembly from .bin files\n"
exit 1
fi
function build_bin() {
riscv64-unknown-elf-gcc -Wl,-Ttext=0x0 -nostdlib -o "$dirpath/$name" "$filepath" -march=rv32i -mabi=ilp32
# strips headers off of binary and just leaves code
riscv64-unknown-elf-objcopy -O binary "$dirpath/$name" "$dirpath/$name.bin"
}
case "$operation" in
bin)
build_bin
;;
run)
build_bin
cargo run --release -- "$dirpath/$name.bin"
;;
riscv-testsuite)
if [ -z "$RISCV_TESTSUITE" ]; then
echo "RISCV_TESTSUITE env var is not set"
exit 1
fi
cargo b --release
FAILED=0
FAILED_TESTS=""
for test in "$RISCV_TESTSUITE"/isa/rv32ui-p*; do
if [[ $test != *.dump ]]; then
test_base=$(basename -- "$test")
# echo to stderr
>&2 echo "Testing $test_base..."
riscv64-unknown-elf-objcopy -O binary $test "tests/$test_base.bin"
# capture the emulators stderr messages to check if program finished successfully (exit-code 0)
stderr=$(./target/release/ruscv "tests/$test_base.bin" 2>&1)
if [[ "$stderr" != *"Emulated program finished at exit syscall with exit-code: 0"* ]]; then
let "FAILED += 1"
FAILED_TESTS="${FAILED_TESTS}\n- ${test_base}"
fi
fi
done
if [ $FAILED -gt 0 ]; then
echo "Failed ${FAILED} tests:"
echo -e "${FAILED_TESTS}"
exit 1
else
echo "Passed all tests!"
fi
;;
objdump)
riscv64-unknown-elf-objdump -D "$filepath" -march=rv32i -mabi=ilp32
;;
*)
echo "Invalid operation: $operation"
exit 1
;;
esac