Skip to content

Commit

Permalink
Merge branch 'sysprog21:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
huaxinliao authored Oct 14, 2024
2 parents 7ab9d2b + a00c49f commit 943ae2b
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 117 deletions.
4 changes: 2 additions & 2 deletions .ci/check-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -x

for file in ${SOURCES};
do
clang-format-12 ${file} > expected-format
clang-format-18 ${file} > expected-format
diff -u -p --label="${file}" --label="expected coding style" ${file} expected-format
done
exit $(clang-format-12 --output-replacements-xml ${SOURCES} | egrep -c "</replacement>")
exit $(clang-format-18 --output-replacements-xml ${SOURCES} | egrep -c "</replacement>")
4 changes: 2 additions & 2 deletions .ci/riscv-toolchain-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ check_platform
mkdir -p toolchain

if [[ "$#" == "0" ]] || [[ "$1" != "riscv-collab" ]]; then
GCC_VER=14.2.0-1
GCC_VER=14.2.0-2
TOOLCHAIN_REPO=https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/v${GCC_VER}/xpack-riscv-none-elf-gcc-${GCC_VER}-linux-x64.tar.gz
else
UBUNTU_VER=`lsb_release -r | cut -f2`
GCC_VER=2024.04.12
GCC_VER=2024.09.03
TOOLCHAIN_REPO=https://github.com/riscv-collab/riscv-gnu-toolchain
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/${GCC_VER}/riscv32-elf-ubuntu-${UBUNTU_VER}-gcc-nightly-${GCC_VER}-nightly.tar.gz
fi
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: default build
if: ${{ steps.changed-files.outputs.any_changed == 'true' ||
github.event_name == 'workflow_dispatch'}}
run: make ENABLE_SDL=0
run: make ENABLE_SDL=0 all artifact
- name: Run benchmark
if: ${{ steps.changed-files.outputs.any_changed == 'true' ||
github.event_name == 'workflow_dispatch'}}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build-artifact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ jobs:
run: |
make artifact ENABLE_PREBUILT=0
mkdir -p /tmp/rv32emu-prebuilt
mv build/sha1sum-linux-x86-softfp /tmp
mv build/sha1sum-riscv32 /tmp
mv build/linux-x86-softfp build/riscv32 /tmp/rv32emu-prebuilt
- name: Build Sail model
run: |
Expand Down Expand Up @@ -88,4 +90,6 @@ jobs:
--title "$RELEASE_TAG""-nightly"
gh release upload $RELEASE_TAG \
rv32emu-prebuilt.tar.gz \
sha1sum-linux-x86-softfp \
sha1sum-riscv32 \
--repo sysprog21/rv32emu-prebuilt
42 changes: 0 additions & 42 deletions .github/workflows/codeql.yml

This file was deleted.

27 changes: 14 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
detect-code-related-file-changes:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
outputs:
has_code_related_changes: ${{ steps.set_has_code_related_changes.outputs.has_code_related_changes }}
steps:
Expand Down Expand Up @@ -36,20 +36,21 @@ jobs:
host-x64:
needs: [detect-code-related-file-changes]
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: install-dependencies
run: |
sudo apt-get update -q -y
sudo apt-get install -q -y libsdl2-dev libsdl2-mixer-dev
.ci/riscv-toolchain-install.sh
echo "${{ github.workspace }}/toolchain/bin" >> $GITHUB_PATH
wget https://apt.llvm.org/llvm.sh
sudo chmod +x ./llvm.sh
sudo ./llvm.sh 17
sudo ./llvm.sh 18
shell: bash
- name: default build
run: make
run: make -j$(nproc)
- name: check + tests
run: |
make check -j$(nproc)
Expand All @@ -65,7 +66,7 @@ jobs:
make distclean && make ENABLE_SDL=0 check -j$(nproc)
- name: gdbstub test
run: |
make distclean ENABLE_GDBSTUB=1 gdbstub-test
make distclean && make ENABLE_GDBSTUB=1 gdbstub-test -j$(nproc)
- name: JIT test
run: |
make ENABLE_JIT=1 clean && make ENABLE_JIT=1 check -j$(nproc)
Expand All @@ -80,14 +81,14 @@ jobs:
host-arm64:
needs: [detect-code-related-file-changes]
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: checkout code
uses: actions/checkout@v4
- name: build artifact
# The GitHub Action for non-x86 CPU
# https://github.com/uraimo/run-on-arch-action
uses: uraimo/run-on-arch-action@v2.7.1
uses: uraimo/run-on-arch-action@v2
with:
arch: aarch64
distro: ubuntu22.04
Expand All @@ -100,7 +101,7 @@ jobs:
git config --global --add safe.directory ${{ github.workspace }}/src/mini-gdbstub
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
./llvm.sh 17
./llvm.sh 18
# Append custom commands here
run: |
make -j$(nproc)
Expand All @@ -113,12 +114,12 @@ jobs:
coding-style:
needs: [detect-code-related-file-changes]
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: coding convention
run: |
sudo apt-get install -q -y clang-format-12
sudo apt-get install -q -y clang-format-18
.ci/check-newline.sh
.ci/check-format.sh
shell: bash
Expand All @@ -136,7 +137,7 @@ jobs:
sudo apt-get install -q -y clang clang-tools libsdl2-dev libsdl2-mixer-dev
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh 17
sudo ./llvm.sh 18
shell: bash
- name: run scan-build without JIT
run: make distclean && scan-build -v -o ~/scan-build --status-bugs --use-cc=clang --force-analyze-debug-code --show-description -analyzer-config stable-report-filename=true -enable-checker valist,nullability make ENABLE_EXT_F=0 ENABLE_SDL=0 ENABLE_JIT=0
Expand All @@ -163,7 +164,7 @@ jobs:
docker-hub-build-and-publish:
needs: [detect-code-related-file-changes]
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Check out the repo
uses: actions/checkout@v4
Expand All @@ -184,7 +185,7 @@ jobs:
echo "short_hash=$(git rev-parse --short "$GITHUB_SHA")" >> "$GITHUB_ENV"
- name: Build and push
if: ${{ github.event_name == 'push'}}
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
push: true
context: .
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ build/path/
build/linux-x86-softfp/
build/riscv32/
build/sail_cSim/
build/sha1sum-*
*.a
*.o
*.o.d
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ However, participation requires adherence to fundamental ground rules:
This variant should be considered the standard for all documentation efforts.
For instance, opt for "initialize" over "initialise" and "color" rather than "colour".

Software requirement: [clang-format](https://clang.llvm.org/docs/ClangFormat.html) version 12 or later.
Software requirement: [clang-format](https://clang.llvm.org/docs/ClangFormat.html) version 18 or later.

This repository consistently contains an up-to-date `.clang-format` file with rules that match the explained ones.
For maintaining a uniform coding style, execute the command `clang-format -i *.[ch]`.
For maintaining a uniform coding style, execute the command `clang-format -i *.{c,h}`.

## Coding Style for Modern C

Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ src/mini-gdbstub/Makefile:
GDBSTUB_LIB := $(GDBSTUB_OUT)/libgdbstub.a
$(GDBSTUB_LIB): src/mini-gdbstub/Makefile
$(MAKE) -C $(dir $<) O=$(dir $@)
# FIXME: track gdbstub dependency properly
$(OUT)/decode.o: $(GDBSTUB_LIB)
OBJS_EXT += gdbstub.o breakpoint.o
CFLAGS += -D'GDBSTUB_COMM="$(GDBSTUB_COMM)"'
LDFLAGS += $(GDBSTUB_LIB) -pthread
Expand Down Expand Up @@ -219,6 +217,10 @@ ifeq ($(call has, EXT_F), 1)
$(OBJS): $(SOFTFLOAT_LIB)
endif

ifeq ($(call has, GDBSTUB), 1)
$(OBJS): $(GDBSTUB_LIB)
endif

$(OUT)/%.o: src/%.c $(deps_emcc)
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) $(CFLAGS_emcc) -c -MMD -MF $@.d $<
Expand Down Expand Up @@ -256,7 +258,7 @@ EXPECTED_fcalc = Performed 12 tests, 0 failures, 100% success rate.
EXPECTED_pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086

check-hello: $(BIN)
$(Q)$(PRINTF) "Running hello.elf ..."; \
$(Q)$(PRINTF) "Running hello.elf ... "; \
if [ "$(shell $(BIN) $(OUT)/hello.elf | uniq)" = "$(strip $(EXPECTED_hello)) inferior exit code 0" ]; then \
$(call notice, [OK]); \
else \
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ The tier-2 JIT compiler in `rv32emu` leverages LLVM for powerful optimization.
Therefore, the target system must have [`LLVM`](https://llvm.org/) installed, with version 17 recommended.
If `LLVM` is not installed, only the tier-1 JIT compiler will be used for performance enhancement.

* macOS: `brew install llvm@17`
* Ubuntu Linux / Debian: `sudo apt-get install llvm-17`
* macOS: `brew install llvm@18`
* Ubuntu Linux / Debian: `sudo apt-get install llvm-18`

Build the emulator with experimental JIT compiler:
```shell
Expand Down Expand Up @@ -298,11 +298,10 @@ $ tools/rv_profiler [--start-address|--stop-address|--graph-ir] [test_program]
```

## WebAssembly Translation
### Build and run
`rv32emu` relies on [Emscripten](https://emscripten.org/docs/getting_started/downloads.html) to be compiled to WebAssembly. Thus, the target system should have
the Emscripten version 3.1.51 installed.
`rv32emu` relies on [Emscripten](https://emscripten.org/docs/getting_started/downloads.html) to be compiled to WebAssembly.
Thus, the target system should have the Emscripten version 3.1.51 installed.

Moreover, `rv32emu` leverages the tail call optimization(TCO) strategy and we have tested the WebAssembly
Moreover, `rv32emu` leverages the tail call optimization (TCO) and we have tested the WebAssembly
execution in Chrome with at least MAJOR 112 and Firefox with at least MAJOR 121 since they supports
tail call feature. Thus, please check and update your browsers if necessary or install the suitable browsers
before going further.
Expand All @@ -320,7 +319,6 @@ $ make CC=emcc start-web
You would see the server's IP:PORT in your terminal. Copy and paste it to the browsers and
you just access the index page of `rv32emu`.

### Index page
You would see a dropdown menu which you can use to select the ELF executable. Select one and
click the Run button to run it.

Expand All @@ -345,8 +343,8 @@ See [docs/prebuilt.md](docs/prebuilt.md).
* [Writing a RISC-V Emulator in Rust](https://book.rvemu.app/)
* [Bare metal C on my RISC-V toy CPU](https://florian.noeding.com/posts/risc-v-toy-cpu/cpu-from-scratch/)
* [Juraj's RISC-V note](https://jborza.com/tags/riscv/)
* [libriscv: RISC-V userspace emulator library](https://github.com/fwsGonzo/libriscv)
* [GUI-VP: RISC-V based Virtual Prototype (VP) for graphical application development](https://github.com/ics-jku/GUI-VP)
* [LupV: an education-friendly RISC-V based system emulator](https://gitlab.com/luplab/lupv)
* [mini-rv32ima](https://github.com/cnlohr/mini-rv32ima) / [video: Writing a Really Tiny RISC-V Emulator](https://youtu.be/YT5vB3UqU_E)
* [RVVM](https://github.com/LekKit/RVVM)
* [RISCVBox](https://github.com/bane9/RISCVBox)
36 changes: 32 additions & 4 deletions mk/artifact.mk
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,29 @@ else
LDFLAGS_CROSS := -lm -lsemihost
endif

.PHONY: artifact scimark2 ieeelib
.PHONY: artifact fetch-checksum scimark2 ieeelib

artifact: ieeelib scimark2
artifact: fetch-checksum ieeelib scimark2
ifeq ($(call has, PREBUILT), 1)
$(Q)$(PRINTF) "Fetching prebuilt executables from \"rv32emu-prebuilt\" ...\n"
$(Q)wget -q --show-progress https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE)/rv32emu-prebuilt.tar.gz -O- | tar -C build --strip-components=1 -xz
$(Q)$(PRINTF) "Checking SHA-1 of prebuilt binaries ... "

$(Q)$(eval PREBUILT_X86_FILENAME := $(shell cat $(BIN_DIR)/sha1sum-linux-x86-softfp | awk '{ print $$2 };'))
$(Q)$(eval PREBUILT_RV32_FILENAME := $(shell cat $(BIN_DIR)/sha1sum-riscv32 | awk '{ print $$2 };'))

$(Q)$(eval RES := 0)
$(Q)$(eval $(foreach FILE,$(PREBUILT_X86_FILENAME), \
$(call verify,$(shell grep -w $(FILE) $(BIN_DIR)/sha1sum-linux-x86-softfp | awk '{ print $$1 };'),$(BIN_DIR)/linux-x86-softfp/$(FILE),RES) \
))
$(Q)$(eval $(foreach FILE,$(PREBUILT_RV32_FILENAME), \
$(call verify,$(shell grep -w $(FILE) $(BIN_DIR)/sha1sum-riscv32 | awk '{ print $$1 };'),$(BIN_DIR)/riscv32/$(FILE),RES) \
))

$(Q)if [ "$(RES)" = "1" ]; then \
$(PRINTF) "\n$(YELLOW)SHA-1 verification fails! Re-fetching prebuilt binaries from \"rv32emu-prebuilt\" ...\n$(NO_COLOR)"; \
wget -q --show-progress https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE)/rv32emu-prebuilt.tar.gz -O- | tar -C build --strip-components=1 -xz; \
else \
$(call notice, [OK]); \
fi
else
git submodule update --init $(addprefix ./tests/,$(foreach tb,$(TEST_SUITES),$(tb)))
$(Q)for tb in $(TEST_SUITES); do \
Expand Down Expand Up @@ -82,6 +99,17 @@ else
-DCMAKE_BUILD_TYPE=RELEASE -DBOARD_NAME=rv32emu .. && \
make
$(Q)cp ./tests/quake/build/port/boards/rv32emu/quake $(BIN_DIR)/riscv32/quake

$(Q)(cd $(BIN_DIR)/linux-x86-softfp; for fd in *; do $(SHA1SUM) "$$fd"; done) >> $(BIN_DIR)/sha1sum-linux-x86-softfp
$(Q)(cd $(BIN_DIR)/riscv32; for fd in *; do $(SHA1SUM) "$$fd"; done) >> $(BIN_DIR)/sha1sum-riscv32
endif

fetch-checksum:
ifeq ($(call has, PREBUILT), 1)
$(Q)$(PRINTF) "Fetching SHA-1 of prebuilt binaries ... "
$(Q)wget -q -O $(BIN_DIR)/sha1sum-linux-x86-softfp https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE)/sha1sum-linux-x86-softfp
$(Q)wget -q -O $(BIN_DIR)/sha1sum-riscv32 https://github.com/sysprog21/rv32emu-prebuilt/releases/download/$(LATEST_RELEASE)/sha1sum-riscv32
$(Q)$(call notice, [OK])
endif

scimark2:
Expand Down
14 changes: 9 additions & 5 deletions mk/external.mk
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ endef

# $(1): correct SHA1 value
# $(2): filename or directory path
# $(3): (optional) returned result
#
# Note:
# 1. for regular file, $(SHA1SUM) command's -c option generates keyword "FAILED" for indicating an unmatch
# 2. for directory, cmp command outputs keyword "differ" for indicating an unmatch
define verify
$(eval COMPRESSED_IS_DIR := $(if $(wildcard $(2)/*),1,0))
$(eval _ := \
$(if $(filter 1,$(COMPRESSED_IS_DIR)), \
($(eval VERIFIER := \
$(if $(filter 1,$(COMPRESSED_IS_DIR)), \
($(eval VERIFIER := \
echo $(1) > $(SHA1_FILE1) \
| find $(2) -type f -print0 \
| sort -z \
Expand All @@ -58,10 +59,13 @@ define verify
| cut -f 1 -d ' ' > $(SHA1_FILE2) && cmp $(SHA1_FILE1) $(SHA1_FILE2))), \
($(eval VERIFIER := echo "$(strip $(1)) $(strip $(2))" | $(SHA1SUM) -c)) \
))
$(eval _ := $(shell $(VERIFIER)))
$(eval _ := $(shell $(VERIFIER) 2>&1))
$(eval _ := \
$(if $(filter FAILED differ:,$(_)), \
($(error $(_))), \
($(if $(3), \
$(eval $(3) := 1), \
$(error $(_)) \
)), \
(# SHA1 value match, do nothing) \
))
endef
Expand Down Expand Up @@ -92,7 +96,7 @@ $($(T)_DATA):
$(Q)$$(call prologue,$$@)
$(Q)$$(call download,$(strip $($(T)_DATA_URL)))
$(Q)$$(call extract,$(OUT),$(notdir $($(T)_DATA_URL)))
$(Q)$$(call verify,$($(T)_DATA_SHA1), $($(T)_DATA))
$(Q)$$(call verify,$($(T)_DATA_SHA1),$($(T)_DATA))
$(Q)$$(call epilogue,$(notdir $($(T)_DATA_URL)),$(SHA1_FILE1),$(SHA1_FILE2))
endef

Expand Down
Loading

0 comments on commit 943ae2b

Please sign in to comment.