feat: implement privileged mode support

This commit is contained in:
abnerhexu
2026-06-29 07:00:55 +00:00
parent a32db39c80
commit b6afa61e66
89 changed files with 49571 additions and 43647 deletions

28
sim/scripts/run_opensbi.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
set -u
TESTBENCH="../verilator/obj_dir/VCore"
OPENSBI_BIN="${OPENSBI_BIN:-../../opensbi/build/platform/generic/firmware/fw_payload.elf}"
TIMEOUT_SECONDS="${TIMEOUT_SECONDS:-10}"
if [ ! -x "$TESTBENCH" ]; then
echo "Error: Testbench not found. Run 'make -C sim/verilator compile' first."
exit 1
fi
if [ ! -f "$OPENSBI_BIN" ]; then
echo "Error: OpenSBI payload not found: $OPENSBI_BIN"
echo "Set OPENSBI_BIN to a firmware ELF path."
exit 2
fi
echo "Running OpenSBI payload: $OPENSBI_BIN"
timeout "${TIMEOUT_SECONDS}s" "$TESTBENCH" "$OPENSBI_BIN"
exitcode=$?
if [ "$exitcode" -eq 124 ]; then
echo "OpenSBI run timed out"
exit 124
fi
exit "$exitcode"

View File

@@ -0,0 +1,75 @@
#!/bin/bash
set -u
TESTBENCH="../verilator/obj_dir/VCore"
TESTS_DIR="../../riscv-tests/isa"
RESULTS_DIR="../results"
RESULTS_FILE="$RESULTS_DIR/privileged_test_results.txt"
TIMEOUT_SECONDS="${TIMEOUT_SECONDS:-5}"
mkdir -p "$RESULTS_DIR"
if [ ! -x "$TESTBENCH" ]; then
echo "Error: Testbench not found. Run 'make -C sim/verilator compile' first."
exit 1
fi
echo "Running privileged RISC-V tests..." > "$RESULTS_FILE"
echo "=================================" >> "$RESULTS_FILE"
PASS=0
FAIL=0
TIMEOUT=0
shopt -s nullglob
tests=(
"$TESTS_DIR"/rv64mi-p-*
"$TESTS_DIR"/rv64si-p-*
"$TESTS_DIR"/rv64ui-p-fence_i
)
for test in "${tests[@]}"; do
[[ "$test" == *.dump ]] && continue
[ ! -f "$test" ] && continue
testname=$(basename "$test")
printf "Running %s... " "$testname"
output=$(timeout "${TIMEOUT_SECONDS}s" "$TESTBENCH" "$test" 2>&1)
exitcode=$?
if [ "$exitcode" -eq 0 ]; then
echo "PASS"
echo "$testname: exit=0 PASS" >> "$RESULTS_FILE"
PASS=$((PASS + 1))
elif [ "$exitcode" -eq 124 ]; then
echo "TIMEOUT"
echo "$testname: exit=124 TIMEOUT" >> "$RESULTS_FILE"
TIMEOUT=$((TIMEOUT + 1))
else
echo "FAIL (exit code $exitcode)"
echo "$testname: exit=$exitcode FAIL" >> "$RESULTS_FILE"
printf '%s\n' "$output" >> "$RESULTS_FILE"
FAIL=$((FAIL + 1))
fi
done
TOTAL=$((PASS + FAIL + TIMEOUT))
{
echo ""
echo "================================="
echo "Summary:"
echo " PASS: $PASS"
echo " FAIL: $FAIL"
echo " TIMEOUT: $TIMEOUT"
echo " TOTAL: $TOTAL"
} >> "$RESULTS_FILE"
echo ""
echo "Summary:"
echo " PASS: $PASS"
echo " FAIL: $FAIL"
echo " TIMEOUT: $TIMEOUT"
echo " TOTAL: $TOTAL"
echo ""
echo "Results saved to $RESULTS_FILE"

View File

@@ -2,7 +2,7 @@
TESTBENCH="../verilator/obj_dir/VCore"
TESTS_DIR="../../riscv-tests/isa"
RESULTS_FILE="test_results.txt"
RESULTS_FILE="../results/test_results.txt"
if [ ! -x "$TESTBENCH" ]; then
echo "Error: Testbench not found. Run 'make compile' first."