diff --git a/.github/workflows/end2end-smoke-test.yml b/.github/workflows/end2end-smoke-test.yml index f537917..9f3e8bf 100644 --- a/.github/workflows/end2end-smoke-test.yml +++ b/.github/workflows/end2end-smoke-test.yml @@ -15,6 +15,18 @@ jobs: - name: Fetching the generator sources uses: actions/checkout@v4 + - name: Getting the hash of the riscv sail model to fetch + id: sail-riscv-model-get-hash + run: echo "h=$(cat sail.hash.txt)" >> "$GITHUB_OUTPUT" + + - name: Fetching the riscv sail model + uses: actions/checkout@v4 + with: + repository: riscv/sail-riscv + ref: ${{ steps.sail-riscv-model-get-hash.outputs.h }} + path: ../sail-riscv/ + sparse-checkout: model + - name: Running the generator run: | source ~/.bash_profile @@ -23,7 +35,23 @@ jobs: opam install . --deps-only opam install sail=0.17.1 - ls ~/.opam/default/share/sail - ls ~/.opam/default/share/sail/lib - rm *.gen.inc - dune exec --profile release -- riscv_disasm_from_sail -f bin/sail.filepaths.txt \ No newline at end of file + + mv riscv_ast.gen.inc old_riscv_ast.gen.inc + mv riscv_decode.gen.inc old_riscv_decode.gen.inc + + dune exec --profile release -- riscv_disasm_from_sail -f sail.filepaths.txt + + echo '#include "riscv_decode.gen.inc" \n void main() {}' > test_main.c + gcc test_main.c || echo "Failure: Trying to compile the tool-generated C code failed." + + if diff -q riscv_ast.gen.inc old_riscv_ast.gen.inc > /dev/null 2>&1; then + if diff -q riscv_decode.gen.inc old_riscv_decode.gen.inc > /dev/null 2>&1; then + echo "Success: The tool generates compiling C code that is identical to the files committed." + else + echo "Failure: The tool-generated decoding logic differ from that committed in the repo." + exit 1 + fi + else + echo "Failure: The tool-generated ast definition differ from the one committed in the repo." + exit 1 + fi \ No newline at end of file diff --git a/riscv_ast.gen.inc b/riscv_ast.gen.inc index 235eb77..9490ff0 100644 --- a/riscv_ast.gen.inc +++ b/riscv_ast.gen.inc @@ -297,7 +297,9 @@ struct ast { FVFMTYPE, RIVVTYPE, RMVVTYPE, - RFVVTYPE + RFVVTYPE, + RISCV_ZICBOM, + RISCV_ZICBOZ } ast_node_type; union { @@ -2690,6 +2692,17 @@ struct ast { uint8_t vd /* bits : 5 */; } rfvvtype; + struct { + enum cbop_zicbom { + CBO_CLEAN, + CBO_FLUSH, + CBO_INVAL + } cbop; + + uint8_t rs1 /* bits : 5 */; + } riscv_zicbom; + + uint8_t riscv_zicboz /* bits : 5 */; } ast_node; } ; diff --git a/riscv_decode.gen.inc b/riscv_decode.gen.inc index dc48c2a..d76fa30 100644 --- a/riscv_decode.gen.inc +++ b/riscv_decode.gen.inc @@ -7017,6 +7017,34 @@ void decode(struct ast *tree, uint64_t binary_stream) { tree->ast_node.rfvvtype.vd = vd; return ; } + } + if ((binary_stream & 0x000000000000007F == 0x0F) && ((binary_stream & 0x0000000000000F80)>>7 == 0x00) && ((binary_stream & 0x0000000000007000)>>12 == 0x2)) { + uint64_t cbop = 0xFFFFFFFFFFFFFFFF ; + switch ((binary_stream & 0x00000000FFF00000)>>20) { + case 0x000: + cbop = CBO_INVAL ; + break; + case 0x002: + cbop = CBO_FLUSH ; + break; + case 0x001: + cbop = CBO_CLEAN ; + break; + + } + if (cbop != 0xFFFFFFFFFFFFFFFF) { + uint64_t rs1 = (binary_stream & 0x00000000000F8000)>>15 ; + tree->ast_node_type = RISCV_ZICBOM ; + tree->ast_node.riscv_zicbom.cbop = cbop; + tree->ast_node.riscv_zicbom.rs1 = rs1; + return ; + } + } + if ((binary_stream & 0x000000000000007F == 0x0F) && ((binary_stream & 0x0000000000000F80)>>7 == 0x00) && ((binary_stream & 0x0000000000007000)>>12 == 0x2) && ((binary_stream & 0x00000000FFF00000)>>20 == 0x004)) { + uint64_t rs1 = (binary_stream & 0x00000000000F8000)>>15 ; + tree->ast_node_type = RISCV_ZICBOZ ; + tree->ast_node.riscv_zicboz = rs1; + return ; } uint64_t s = binary_stream & 0x00000000FFFFFFFF ; tree->ast_node_type = ILLEGAL ; diff --git a/bin/sail.filepaths.txt b/sail.filepaths.txt similarity index 97% rename from bin/sail.filepaths.txt rename to sail.filepaths.txt index 568cca1..5a733fc 100644 --- a/bin/sail.filepaths.txt +++ b/sail.filepaths.txt @@ -76,6 +76,8 @@ ../sail-riscv/model/riscv_insts_vext_fp_vm.sail ../sail-riscv/model/riscv_insts_vext_red.sail ../sail-riscv/model/riscv_insts_vext_fp_red.sail +../sail-riscv/model/riscv_insts_zicbom.sail +../sail-riscv/model/riscv_insts_zicboz.sail ../sail-riscv/model/riscv_jalr_seq.sail ../sail-riscv/model/riscv_insts_end.sail ../sail-riscv/model/riscv_step_common.sail diff --git a/sail.hash.txt b/sail.hash.txt new file mode 100644 index 0000000..5811830 --- /dev/null +++ b/sail.hash.txt @@ -0,0 +1 @@ +e199a2e0dcdc5d2d5705b717538bb7a1b3060725 \ No newline at end of file diff --git a/tools/riscv-ls.sh b/tools/riscv-ls.sh new file mode 100755 index 0000000..f803470 --- /dev/null +++ b/tools/riscv-ls.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +if [ $# -eq 0 ]; then + echo "No sail model path given, must be given." + exit +elif [ $# -eq 1 ]; then + SAIL_RISCV_ROOT=$1 + echo "Path to sail model given as $1" +else + echo "Unrecognized arguments. Usage: riscv-ls [path to riscv sail model repo]" + echo "If no path to sail model was given, it's automatically searched for using find" + exit +fi + +MKFILE="$SAIL_RISCV_ROOT/Makefile" + +# add instrumentation to the makefile in order to be able to print any variables +echo 'print-% : ; @echo $* = $($*)' >> "$MKFILE" + +TOOL_ROOT=$PWD +( +cd $SAIL_RISCV_ROOT +make print-SAIL_SRCS | xargs -n 1 | grep ".sail" | xargs -I {} echo "$SAIL_RISCV_ROOT"{} > "$TOOL_ROOT/sail.filepaths.txt" +) + +# remove instrumentation from the makefile again to avoid version control headache +sed -i '$d' $MKFILE \ No newline at end of file