Skip to content

Commit

Permalink
Fix C emulator and test script for OCaml emulator
Browse files Browse the repository at this point in the history
The generated C emulator misses z_set_Misa_C. Supply a dummy
implementation. Fix the test script to supply dtc to OCaml
emulator for non-Linux machine.
  • Loading branch information
liuzikai authored and PeterRugg committed Apr 26, 2024
1 parent a4b72e9 commit dc98a6c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ BBV_DIR?=../bbv
C_WARNINGS ?=
#-Wall -Wextra -Wno-unused-label -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-function
C_INCS = $(addprefix $(SAIL_RISCV_DIR)/c_emulator/,riscv_prelude.h riscv_platform_impl.h riscv_platform.h riscv_softfloat.h)
C_SRCS = $(addprefix $(SAIL_RISCV_DIR)/c_emulator/,riscv_prelude.c riscv_platform_impl.c riscv_platform.c riscv_softfloat.c)
C_SRCS = $(addprefix $(SAIL_RISCV_DIR)/c_emulator/,riscv_prelude.c riscv_platform_impl.c riscv_platform.c riscv_softfloat.c) handwritten_support/c_emulator_fix.c

SOFTFLOAT_DIR = $(SAIL_RISCV_DIR)/c_emulator/SoftFloat-3e
SOFTFLOAT_INCDIR = $(SOFTFLOAT_DIR)/source/include
Expand Down
18 changes: 18 additions & 0 deletions handwritten_support/c_emulator_fix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* The generated C emulator is missing this function.
Up to this point, only used by --disable-compressed/-C.
Make a dummy implementation of it.
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

struct zMisa;

typedef int unit;
typedef uint64_t mach_bits;

unit z_set_Misa_C(struct zMisa *, mach_bits) {
fprintf(stderr, "z_set_Misa_C is not supported\n");
exit(EXIT_FAILURE);
}
8 changes: 7 additions & 1 deletion test/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ cd $DIR
RISCVDIR="$DIR/.."
RISCVTESTDIR="$RISCVDIR/sail-riscv/test"

DTC_PATH=$(which dtc)
if [ -z "$DTC_PATH" ]; then
echo "dtc not found. Install it via your package manager."
exit 1
fi

RED='\033[0;91m'
GREEN='\033[0;92m'
YELLOW='\033[0;93m'
Expand Down Expand Up @@ -71,7 +77,7 @@ for test in $RISCVTESTDIR/riscv-tests/rv64*.elf; do
if [[ $(basename $test) =~ $pat ]];
then continue
fi
if $RISCVDIR/ocaml_emulator/cheri_riscv_ocaml_sim_RV64 "$test" >"${test/.elf/.out}" 2>&1 && grep -q SUCCESS "${test/.elf/.out}"
if $RISCVDIR/ocaml_emulator/cheri_riscv_ocaml_sim_RV64 -with-dtc "$DTC_PATH" "$test" >"${test/.elf/.out}" 2>&1 && grep -q SUCCESS "${test/.elf/.out}"
then
green "OCaml-64 $(basename $test)" "ok"
else
Expand Down

0 comments on commit dc98a6c

Please sign in to comment.