diff --git a/.github/workflows/deploy-wasm.yml b/.github/workflows/deploy-wasm.yml index 682a71b92..5ee81973a 100644 --- a/.github/workflows/deploy-wasm.yml +++ b/.github/workflows/deploy-wasm.yml @@ -10,13 +10,107 @@ on: branches: - master repository_dispatch: # listening to rv32emu-prebuilt events - types: [deploy_wasm] + types: [deploy_user_wasm, deploy_system_wasm] jobs: - wasm-deploy: + wasm-system-deploy: if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' || - github.event_name == 'repository_dispatch' + github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm' + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: install-dependencies + run: | + sudo apt-get update -q=2 + sudo apt-get install -q=2 device-tree-compiler + - name: Verify if the JS or HTML files has been modified + id: changed-files + uses: tj-actions/changed-files@v46 + with: + files: | + assets/wasm/html/system.html + assets/wasm/js/system-pre.js + # Files below may have a potential performance impact (reference from benchmark.yml) + src/devices/*.c + src/system.c + src/riscv.c + src/decode.c + src/emulate.c + src/rv32_template.c + src/rv32_constopt.c + - name: install emcc + if: ${{ steps.changed-files.outputs.any_modified == 'true' || + github.event_name == 'workflow_dispatch' || + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }} + run: | + git clone https://github.com/emscripten-core/emsdk -b 3.1.51 + cd emsdk + ./emsdk install latest + ./emsdk activate latest + source ./emsdk_env.sh + echo "$PATH" >> $GITHUB_PATH + shell: bash + - name: fetch artifact + run: | + make artifact + # get from rv32emu-prebuilt + wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip" + unzip -d build/ build/shareware_doom_iwad.zip + - name: build with emcc and move application files to /tmp + if: ${{ steps.changed-files.outputs.any_modified == 'true' || + github.event_name == 'workflow_dispatch' || + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }} + run: | + make CC=emcc ENABLE_SYSTEM=1 ENABLE_SDL=1 INITRD_SIZE=32 -j + mkdir /tmp/rv32emu-system-demo + mv assets/wasm/html/system.html /tmp/rv32emu-system-demo/index.html + mv assets/wasm/js/coi-serviceworker.min.js /tmp/rv32emu-system-demo + mv build/rv32emu.js /tmp/rv32emu-system-demo + mv build/rv32emu.wasm /tmp/rv32emu-system-demo + mv build/rv32emu.worker.js /tmp/rv32emu-system-demo + ls -al /tmp/rv32emu-system-demo + - name: Check out the rv32emu-system-demo repo + if: ${{ steps.changed-files.outputs.any_modified == 'true' || + github.event_name == 'workflow_dispatch' || + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }} + uses: actions/checkout@v4 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. + repository: sysprog21/rv32emu-demo + - name: Create local changes + if: ${{ steps.changed-files.outputs.any_modified == 'true' || + github.event_name == 'workflow_dispatch' || + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }} + run: | + mkdir -p system + mv /tmp/rv32emu-system-demo/index.html ./system + mv /tmp/rv32emu-system-demo/coi-serviceworker.min.js ./system + mv /tmp/rv32emu-system-demo/rv32emu.js ./system + mv /tmp/rv32emu-system-demo/rv32emu.wasm ./system + mv /tmp/rv32emu-system-demo/rv32emu.worker.js ./system + - name: Commit files + if: ${{ steps.changed-files.outputs.any_modified == 'true' || + github.event_name == 'workflow_dispatch' || + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }} + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add system/ + git commit -m "Add changes to system emulation" + - name: Push changes + if: ${{ steps.changed-files.outputs.any_modified == 'true' || + github.event_name == 'workflow_dispatch' || + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }} + uses: ad-m/github-push-action@master + with: + repository: sysprog21/rv32emu-demo + github_token: ${{ secrets.RV32EMU_DEMO_TOKEN }} + branch: main + wasm-user-deploy: + needs: wasm-system-deploy # run jobs sequentially since two jobs operate on same reposity: rv32emu-demo + if: always() # ensures wasm-user-deploy runs regardless of the outcome or condition of wasm-system-deploy runs-on: ubuntu-latest steps: - name: Check out the repo @@ -26,8 +120,8 @@ jobs: uses: tj-actions/changed-files@v46 with: files: | - assets/wasm/html/index.html - assets/wasm/js/pre.js + assets/wasm/html/user.html + assets/wasm/js/user-pre.js build/*.elf tools/gen-elf-list-js.py # Files below may have a potential performance impact (reference from benchmark.yml) @@ -39,12 +133,10 @@ jobs: - name: install emcc if: ${{ steps.changed-files.outputs.any_modified == 'true' || github.event_name == 'workflow_dispatch' || - github.event_name == 'repository_dispatch' }} + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }} run: | - git clone https://github.com/emscripten-core/emsdk.git + git clone https://github.com/emscripten-core/emsdk -b 3.1.51 cd emsdk - git pull - git checkout 3.1.51 ./emsdk install latest ./emsdk activate latest source ./emsdk_env.sh @@ -53,21 +145,17 @@ jobs: - name: fetch artifact run: | make artifact - # Hack Cloudflare 403 Forbidden on GitHub Runner for Doom artifact download - wget --header="User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0" \ - --header="Referer: https://www.doomworld.com/" \ - --header="Accept-Language: en-US,en;q=0.9" \ - -O build/shareware_doom_iwad.zip \ - "https://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip" + # get from rv32emu-prebuilt + wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip" unzip -d build/ build/shareware_doom_iwad.zip - name: build with emcc and move application files to /tmp if: ${{ steps.changed-files.outputs.any_modified == 'true' || github.event_name == 'workflow_dispatch' || - github.event_name == 'repository_dispatch' }} + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }} run: | make CC=emcc ENABLE_SDL=1 mkdir /tmp/rv32emu-demo - mv assets/wasm/html/index.html /tmp/rv32emu-demo + mv assets/wasm/html/user.html /tmp/rv32emu-demo/index.html mv assets/wasm/js/coi-serviceworker.min.js /tmp/rv32emu-demo mv build/elf_list.js /tmp/rv32emu-demo mv build/rv32emu.js /tmp/rv32emu-demo @@ -77,7 +165,7 @@ jobs: - name: Check out the rv32emu-demo repo if: ${{ steps.changed-files.outputs.any_modified == 'true' || github.event_name == 'workflow_dispatch' || - github.event_name == 'repository_dispatch' }} + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }} uses: actions/checkout@v4 with: persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. @@ -85,7 +173,7 @@ jobs: - name: Create local changes if: ${{ steps.changed-files.outputs.any_modified == 'true' || github.event_name == 'workflow_dispatch' || - github.event_name == 'repository_dispatch' }} + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }} run: | mv /tmp/rv32emu-demo/index.html . mv /tmp/rv32emu-demo/coi-serviceworker.min.js . @@ -96,16 +184,16 @@ jobs: - name: Commit files if: ${{ steps.changed-files.outputs.any_modified == 'true' || github.event_name == 'workflow_dispatch' || - github.event_name == 'repository_dispatch' }} + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }} run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add --all - git commit -m "Add changes" + git commit -m "Add changes to user emulation" - name: Push changes if: ${{ steps.changed-files.outputs.any_modified == 'true' || github.event_name == 'workflow_dispatch' || - github.event_name == 'repository_dispatch' }} + (github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }} uses: ad-m/github-push-action@master with: repository: sysprog21/rv32emu-demo diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 899fb4705..743c1447b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,12 +80,8 @@ jobs: make artifact make ENABLE_SYSTEM=1 artifact make ENABLE_ARCH_TEST=1 artifact - # Hack Cloudflare 403 Forbidden on GitHub Runner for Doom artifact download - wget --header="User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0" \ - --header="Referer: https://www.doomworld.com/" \ - --header="Accept-Language: en-US,en;q=0.9" \ - -O build/shareware_doom_iwad.zip \ - "https://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip" + # get from rv32emu-prebuilt + wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip" unzip -d build/ build/shareware_doom_iwad.zip if: ${{ always() }} - name: default build using emcc @@ -394,12 +390,8 @@ jobs: | head -n 1 \ | sed -E 's/.*"tag_name": "([^"]+)".*/\1/') make LATEST_RELEASE=$LATEST_RELEASE ENABLE_ARCH_TEST=1 artifact - # Hack Cloudflare 403 Forbidden on GitHub Runner for Doom artifact download - wget --header="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15" \ - --header="Referer: https://www.doomworld.com/" \ - --header="Accept-Language: en-US,en;q=0.9" \ - -O build/shareware_doom_iwad.zip \ - "https://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip" + # get from rv32emu-prebuilt + wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip" unzip -d build/ build/shareware_doom_iwad.zip if: ${{ always() }} - name: default build using emcc diff --git a/Makefile b/Makefile index 41c8324bb..36e113414 100644 --- a/Makefile +++ b/Makefile @@ -286,8 +286,8 @@ $(OUT)/emulate.o: CFLAGS += -foptimize-sibling-calls -fomit-frame-pointer -fno-s include mk/external.mk include mk/artifact.mk -include mk/wasm.mk include mk/system.mk +include mk/wasm.mk all: config $(BUILD_DTB) $(BUILD_DTB2C) $(BIN) diff --git a/README.md b/README.md index 43028be79..845f70503 100644 --- a/README.md +++ b/README.md @@ -378,16 +378,25 @@ $ source ~/emsdk/emsdk_env.sh Change the Emscripten SDK environment path if necessary. At this point, you can build and start a web server service to serve WebAssembly by running: +- user space emulation: ```shell -$ make CC=emcc start-web +$ make CC=emcc start-web -j8 +``` +- system emulation: +```shell +$ make CC=emcc start-web ENABLE_SYSTEM=1 INITRD_SIZE=32 -j8 ``` 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`. -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. +You would see a dropdown menu which you can use to select the ELF executable for user space emulation, select one and +click the 'Run' button to run it. For system emulation, click the 'Run Linux' button to boot Linux. + +Alternatively, you may want to view a hosted `rv32emu` since building takes some time. +- [user space emulation demo page](https://sysprog21.github.io/rv32emu-demo/) +- [system emulation demo page](https://sysprog21.github.io/rv32emu-demo/system) -Alternatively, you may want to view a hosted `rv32emu` [demo page](https://sysprog21.github.io/rv32emu-demo/) since building takes some time. +Both pages can be easily switched using the navigation button. ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines. diff --git a/assets/wasm/html/system.html b/assets/wasm/html/system.html new file mode 100644 index 000000000..3c9710a0d --- /dev/null +++ b/assets/wasm/html/system.html @@ -0,0 +1,315 @@ + + +
+ + +Experience graphics and sounds(remember to turn on your speaker) by running doom-riscv, quake, smolnes.
+