├── .clang-format ├── .gitattributes ├── .github ├── dependabot.yml ├── scripts │ └── build-libbpf.sh └── workflows │ ├── Build.yml │ ├── CICD.yml │ ├── codeql-analysis.yml │ ├── dependency-review.yml │ └── scorecards.yml ├── .gitignore ├── .gitmodules ├── .pre-commit-config.yaml ├── CMakeLists.txt ├── CONTRIBUTING.md ├── Docker ├── Linux │ └── Dockerfile └── Windows │ └── Dockerfile ├── Doxyfile ├── LICENSE ├── README.md ├── cmake ├── FindLibBpf.cmake ├── options.cmake └── platform.cmake ├── docs ├── DevelopmentGuide.md ├── Governance.md └── SECURITY.md ├── include └── bpf_conformance.h ├── libbpf_plugin ├── CMakeLists.txt └── libbpf_plugin.cc ├── negative ├── empty.data ├── error.data ├── incorrect_return_value_high_bits.data ├── invalid.sh ├── invalid_label.data ├── invalid_lock.data ├── invalid_lock2.data ├── invalid_mnemonic.data ├── invalid_offset.data ├── invalid_operand_count.data ├── invalid_register.data └── invalid_unknown_directive.data ├── scripts ├── .check-license.ignore ├── check-license.sh ├── commit-msg ├── format-code ├── format-code.ps1 └── pre-commit ├── src ├── CMakeLists.txt ├── boost_helper.h ├── bpf_assembler.cc ├── bpf_assembler.h ├── bpf_conformance.cc ├── bpf_test_parser.cc ├── bpf_test_parser.h ├── bpf_writer.cc ├── bpf_writer.h ├── ebpf.h ├── opcode_names.h └── runner.cc └── tests ├── add.data ├── add64.data ├── alu-arith.data ├── alu-bit.data ├── alu64-arith.data ├── alu64-bit.data ├── arsh32-imm-high.data ├── arsh32-imm-neg.data ├── arsh32-imm.data ├── arsh32-reg-high.data ├── arsh32-reg-neg.data ├── arsh32-reg.data ├── arsh64-imm-high.data ├── arsh64-imm-neg.data ├── arsh64-imm.data ├── arsh64-reg-high.data ├── arsh64-reg-neg.data ├── arsh64-reg.data ├── be16-high.data ├── be16.data ├── be32-high.data ├── be32.data ├── be64.data ├── call_local.data ├── call_unwind_fail.data ├── callx.data ├── div32-by-zero-reg-2.data ├── div32-by-zero-reg.data ├── div32-high-divisor.data ├── div32-imm.data ├── div32-reg.data ├── div64-by-zero-reg.data ├── div64-imm.data ├── div64-negative-imm.data ├── div64-negative-reg.data ├── div64-reg.data ├── exit-not-last.data ├── exit.data ├── j-signed-imm.data ├── ja32.data ├── jeq-imm.data ├── jeq-reg.data ├── jeq32-imm.data ├── jeq32-reg.data ├── jge-imm.data ├── jge-reg.data ├── jge32-imm.data ├── jge32-reg.data ├── jgt-imm.data ├── jgt-reg.data ├── jgt32-imm.data ├── jgt32-reg.data ├── jit-bounce.data ├── jle-imm.data ├── jle-reg.data ├── jle32-imm.data ├── jle32-reg.data ├── jlt-imm.data ├── jlt-reg.data ├── jlt32-imm.data ├── jlt32-reg.data ├── jne-reg.data ├── jne32-imm.data ├── jne32-reg.data ├── jset-imm.data ├── jset-reg.data ├── jset32-imm.data ├── jset32-reg.data ├── jsge-imm.data ├── jsge-reg.data ├── jsge32-imm.data ├── jsge32-reg.data ├── jsgt-imm.data ├── jsgt-reg.data ├── jsgt32-imm.data ├── jsgt32-reg.data ├── jsle-imm.data ├── jsle-reg.data ├── jsle32-imm.data ├── jsle32-reg.data ├── jslt-imm.data ├── jslt-reg.data ├── jslt32-imm.data ├── jslt32-reg.data ├── lddw.data ├── lddw2.data ├── ldxb-all.data ├── ldxb.data ├── ldxdw.data ├── ldxh-all.data ├── ldxh-all2.data ├── ldxh-same-reg.data ├── ldxh.data ├── ldxw-all.data ├── ldxw.data ├── le16-high.data ├── le16.data ├── le32-high.data ├── le32.data ├── le64.data ├── lock_add.data ├── lock_add32.data ├── lock_and.data ├── lock_and32.data ├── lock_cmpxchg.data ├── lock_cmpxchg32.data ├── lock_fetch_add.data ├── lock_fetch_add32.data ├── lock_fetch_and.data ├── lock_fetch_and32.data ├── lock_fetch_or.data ├── lock_fetch_or32.data ├── lock_fetch_xor.data ├── lock_fetch_xor32.data ├── lock_or.data ├── lock_or32.data ├── lock_xchg.data ├── lock_xchg32.data ├── lock_xor.data ├── lock_xor32.data ├── lsh32-imm-high.data ├── lsh32-imm-neg.data ├── lsh32-imm.data ├── lsh32-reg-high.data ├── lsh32-reg-neg.data ├── lsh32-reg.data ├── lsh64-imm-high.data ├── lsh64-imm-neg.data ├── lsh64-imm.data ├── lsh64-reg-high.data ├── lsh64-reg-neg.data ├── lsh64-reg.data ├── mem-len.data ├── mod-by-zero-reg.data ├── mod.data ├── mod32.data ├── mod64-by-zero-reg.data ├── mod64.data ├── mov.data ├── mov64-sign-extend.data ├── mov64.data ├── movsx1632-reg.data ├── movsx1664-reg.data ├── movsx3264-reg.data ├── movsx832-reg.data ├── movsx864-reg.data ├── mul32-imm.data ├── mul32-intmin-by-negone-imm.data ├── mul32-intmin-by-negone-reg.data ├── mul32-reg-overflow.data ├── mul32-reg.data ├── mul64-imm.data ├── mul64-intmin-by-negone-imm.data ├── mul64-intmin-by-negone-reg.data ├── mul64-reg.data ├── neg.data ├── neg32-intmin-imm.data ├── neg32-intmin-reg.data ├── neg64-intmin-imm.data ├── neg64-intmin-reg.data ├── neg64.data ├── prime.data ├── rsh32-imm-high.data ├── rsh32-imm-neg.data ├── rsh32-imm.data ├── rsh32-reg-high.data ├── rsh32-reg-neg.data ├── rsh32-reg.data ├── rsh64-imm-high.data ├── rsh64-imm-neg.data ├── rsh64-imm.data ├── rsh64-reg-high.data ├── rsh64-reg-neg.data ├── rsh64-reg.data ├── sdiv32-by-zero-imm.data ├── sdiv32-by-zero-reg.data ├── sdiv32-imm.data ├── sdiv32-intmin-by-negone-imm.data ├── sdiv32-intmin-by-negone-reg.data ├── sdiv32-reg.data ├── sdiv64-by-zero-imm.data ├── sdiv64-by-zero-reg.data ├── sdiv64-imm.data ├── sdiv64-intmin-by-negone-imm.data ├── sdiv64-intmin-by-negone-reg.data ├── sdiv64-reg.data ├── smod32-intmin-by-negone-imm.data ├── smod32-intmin-by-negone-reg.data ├── smod32-neg-by-neg-imm.data ├── smod32-neg-by-neg-reg.data ├── smod32-neg-by-pos-imm.data ├── smod32-neg-by-pos-reg.data ├── smod32-neg-by-zero-imm.data ├── smod32-neg-by-zero-reg.data ├── smod32-pos-by-neg-imm.data ├── smod32-pos-by-neg-reg.data ├── smod64-intmin-by-negone-imm.data ├── smod64-intmin-by-negone-reg.data ├── smod64-neg-by-neg-imm.data ├── smod64-neg-by-neg-reg.data ├── smod64-neg-by-pos-imm.data ├── smod64-neg-by-pos-reg.data ├── smod64-neg-by-zero-imm.data ├── smod64-neg-by-zero-reg.data ├── smod64-pos-by-neg-imm.data ├── smod64-pos-by-neg-reg.data ├── stack.data ├── stb.data ├── stdw.data ├── sth.data ├── stw.data ├── stxb-all.data ├── stxb-all2.data ├── stxb-chain.data ├── stxb.data ├── stxdw.data ├── stxh.data ├── stxw.data ├── subnet.data ├── swap16.data ├── swap32.data └── swap64.data /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | IndentWidth: 4 3 | ColumnLimit: 120 4 | AlignEscapedNewlines: Left 5 | AlignAfterOpenBracket: AlwaysBreak 6 | # 7 | # Bind * to the type rather than the name. 8 | PointerAlignment: Left 9 | # 10 | # Put function name on separate line from return type. 11 | AlwaysBreakAfterReturnType: All 12 | # 13 | # Put arguments either all on same line or on separate lines. 14 | BinPackArguments: false 15 | # 16 | # Put function parameters on separate lines. 17 | BinPackParameters: false 18 | # 19 | # Open brace goes on new line only when starting a new struct, enum, or func. 20 | BreakBeforeBraces: Mozilla 21 | # 22 | # Don't sort includes in alphabetical order because Windows headers are odd. 23 | SortIncludes: false 24 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Files identified as text should be checked in with LFs, and checked 2 | # out with the platform-specific EOL markers. 3 | # 4 | # Essentially runs `git config core.autocrlf true` for every clone. 5 | * text=auto 6 | 7 | # Bash shell scripts should always have LFs. 8 | *.sh text eol=lf 9 | /scripts/** text eol=lf 10 | 11 | # Windows build files should always have CRLFs. 12 | *.sln text eol=crlf 13 | *.vcxproj text eol=crlf 14 | *.vcxproj.filters text eol=crlf 15 | *.o -text -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (c) Microsoft Corporation 3 | # SPDX-License-Identifier: MIT 4 | # 5 | # For documentation on the format of this file, see 6 | # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 7 | 8 | version: 2 9 | updates: 10 | - package-ecosystem: "github-actions" 11 | # Workflow files stored in the 12 | # default location of `.github/workflows` 13 | directory: "/" 14 | schedule: 15 | interval: "weekly" 16 | day: "saturday" 17 | groups: 18 | actions: 19 | patterns: 20 | - "*" 21 | - package-ecosystem: "gitsubmodule" 22 | directory: "/" 23 | schedule: 24 | interval: "weekly" 25 | day: "saturday" 26 | groups: 27 | actions: 28 | patterns: 29 | - "*" 30 | - package-ecosystem: "nuget" 31 | directory: "/" 32 | schedule: 33 | interval: "weekly" 34 | day: "saturday" 35 | groups: 36 | actions: 37 | patterns: 38 | - "*" 39 | - package-ecosystem: "pip" 40 | directory: "/" 41 | schedule: 42 | interval: "weekly" 43 | day: "saturday" 44 | groups: 45 | actions: 46 | patterns: 47 | - "*" 48 | - package-ecosystem: "docker" 49 | directory: "/" 50 | schedule: 51 | interval: "weekly" 52 | day: "saturday" 53 | groups: 54 | actions: 55 | patterns: 56 | - "*" 57 | - package-ecosystem: docker 58 | directory: /Docker/Linux 59 | schedule: 60 | interval: daily 61 | groups: 62 | actions: 63 | patterns: 64 | - "*" 65 | - package-ecosystem: docker 66 | directory: /Docker/Windows 67 | schedule: 68 | interval: daily 69 | groups: 70 | actions: 71 | patterns: 72 | - "*" 73 | -------------------------------------------------------------------------------- /.github/scripts/build-libbpf.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # Copyright (c) Microsoft Corporation 3 | # SPDX-License-Identifier: MIT 4 | 5 | git clone --branch v1.3.0 https://github.com/libbpf/libbpf.git 6 | if [ $? -ne 0 ]; then 7 | echo "Could not clone the libbpf repository." 8 | exit 1 9 | fi 10 | 11 | # Jump in to the src directory to do the actual build. 12 | cd libbpf/src 13 | 14 | make 15 | if [ $? -ne 0 ]; then 16 | echo "Could not build libbpf source." 17 | exit 1 18 | fi 19 | 20 | # Now that the build was successful, install the library (shared 21 | # object and header files) in a spot where FindLibBpf.cmake can 22 | # find it when it is being built. 23 | sudo PREFIX=/usr LIBDIR=/usr/lib/x86_64-linux-gnu/ make install 24 | exit 0 25 | -------------------------------------------------------------------------------- /.github/workflows/Build.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | name: CI/CD 5 | 6 | on: 7 | workflow_call: 8 | inputs: 9 | platform: 10 | required: true 11 | type: string 12 | configuration: 13 | required: true 14 | type: string 15 | enable_sanitizers: 16 | required: false 17 | type: boolean 18 | enable_coverage: 19 | required: false 20 | type: boolean 21 | publish_docker: 22 | required: false 23 | type: boolean 24 | 25 | env: 26 | REGISTRY: ghcr.io 27 | IMAGE_NAME: alan-jowett/bpf_conformance 28 | 29 | permissions: 30 | contents: read 31 | packages: write 32 | 33 | jobs: 34 | build: 35 | 36 | runs-on: ${{inputs.platform}} 37 | env: 38 | BUILD_TYPE: ${{inputs.configuration}} 39 | 40 | steps: 41 | - name: Harden Runner 42 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 43 | with: 44 | egress-policy: audit 45 | 46 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 47 | with: 48 | submodules: 'recursive' 49 | 50 | - name: Install prerequisites - Ubuntu 51 | if: ${{ startsWith(inputs.platform, 'ubuntu-') }} 52 | run: | 53 | sudo apt-get install -y libboost-dev \ 54 | libboost-filesystem-dev \ 55 | libboost-program-options-dev \ 56 | libelf-dev \ 57 | lcov 58 | 59 | - name: Install prerequisites - macos-latest 60 | if: inputs.platform == 'macos-latest' 61 | run: | 62 | brew install \ 63 | cmake \ 64 | ninja \ 65 | ccache \ 66 | boost 67 | 68 | - name: Build/install libbpf From Source 69 | if: ${{ startsWith(inputs.platform, 'ubuntu-') }} 70 | run: ./.github/scripts/build-libbpf.sh 71 | shell: bash 72 | 73 | - name: Cache nuget packages 74 | if: ${{ startsWith(inputs.platform, 'windows-') }} 75 | uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 76 | env: 77 | cache-name: cache-nuget-modules 78 | with: 79 | path: build\packages 80 | key: ${{ runner.os }}-${{ hashFiles('**/CMakeLists.txt') }}-${{inputs.platform}} 81 | 82 | - name: Configure CMake (Windows) 83 | if: ${{ startsWith(inputs.platform, 'windows-') }} 84 | run: | 85 | cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} 86 | 87 | - name: Configure CMake (non-Windows) 88 | if: ${{ !startsWith(inputs.platform, 'windows-') }} 89 | run: | 90 | if [ "${{inputs.enable_sanitizers}}" = "true" ]; then 91 | export SANITIZER_FLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all" 92 | fi 93 | if [ "${{inputs.enable_coverage}}" = "true" ]; then 94 | export COVERAGE_FLAGS="-DCMAKE_CXX_FLAGS=\"--coverage\" -DCMAKE_C_FLAGS=\"--coverage\"" 95 | fi 96 | cmake \ 97 | -B ${{github.workspace}}/build \ 98 | -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ 99 | -DCMAKE_CXX_FLAGS="${SANITIZER_FLAGS}" \ 100 | -DCMAKE_C_FLAGS="${SANITIZER_FLAGS}" \ 101 | ${COVERAGE_FLAGS} 102 | 103 | - name: Build 104 | # Build your program with the given configuration 105 | run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} 106 | 107 | - name: Prepare for upload 108 | if: inputs.platform == 'windows-2019' && (github.event_name == 'schedule' || github.event_name == 'push') 109 | run: | 110 | md -p ${{github.workspace}}/build/upload 111 | cp ${{github.workspace}}/build/bin/${{env.BUILD_TYPE}}/bpf_conformance_runner.exe ${{github.workspace}}/build/upload/bpf_conformance_runner.exe 112 | cp ${{github.workspace}}/build/bin/${{env.BUILD_TYPE}}/bpf_conformance_runner.pdb ${{github.workspace}}/build/upload/bpf_conformance_runner.pdb 113 | cp -r ${{github.workspace}}/tests ${{github.workspace}}/build/upload 114 | 115 | - name: Upload build as artifact 116 | if: inputs.platform == 'windows-2019' && (github.event_name == 'schedule' || github.event_name == 'push') && github.ref == 'refs/heads/main' && env.BUILD_TYPE == 'RelWithDebInfo' 117 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 118 | with: 119 | name: bpf_conformance-Release 120 | path: | 121 | ${{github.workspace}}/build/upload 122 | 123 | - name: Upload build as artifact 124 | if: inputs.platform == 'windows-2019' && (github.event_name == 'schedule' || github.event_name == 'push') && github.ref == 'refs/heads/main' && env.BUILD_TYPE == 'Debug' 125 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 126 | with: 127 | name: bpf_conformance-Debug 128 | path: | 129 | ${{github.workspace}}/build/upload 130 | 131 | - name: Tests 132 | if: ${{ startsWith(inputs.platform, 'ubuntu-') }} 133 | working-directory: ${{github.workspace}} 134 | run: | 135 | cmake --build build --target test -- 136 | 137 | - name: Rerun failed tests with more verbose output 138 | if: inputs.platform == 'ubuntu-latest' && failure() 139 | working-directory: ${{github.workspace}}/build 140 | run: | 141 | ctest --rerun-failed --output-on-failure 142 | 143 | - name: Upload build folder for diagnosing issues 144 | if: always() 145 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 146 | with: 147 | name: bpf_conformance-diagnostic-${{inputs.platform}}-${{inputs.configuration}}-enable-sanitizers-${{inputs.enable_sanitizers}}-enable-coverage-${{inputs.enable_coverage}} 148 | path: ${{github.workspace}}/build 149 | 150 | - name: Generate code coverage report 151 | if: inputs.enable_coverage == true 152 | run: | 153 | mkdir -p coverage 154 | lcov --capture --directory build --include '${{github.workspace}}/*' --output-file coverage/lcov.info --exclude '${{github.workspace}}/external/*' 155 | 156 | - name: Coveralls Parallel 157 | if: inputs.enable_coverage == true 158 | uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6 159 | with: 160 | github-token: ${{ secrets.github_token }} 161 | flag-name: run-${{inputs.build_type}}-${{inputs.platform}}-${{inputs.arch}} 162 | parallel: true 163 | 164 | - name: Log in to the Container registry 165 | if: inputs.publish_docker == true 166 | uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 167 | with: 168 | registry: ${{ env.REGISTRY }} 169 | username: ${{ github.actor }} 170 | password: ${{ secrets.GITHUB_TOKEN }} 171 | 172 | - name: Extract metadata (tags, labels) for Docker 173 | if: inputs.publish_docker == true 174 | id: meta 175 | uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 176 | with: 177 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 178 | 179 | - name: Build and push Docker image 180 | if: inputs.publish_docker == true && github.event_name == 'push' 181 | uses: docker/build-push-action@1dc73863535b631f98b2378be8619f83b136f4a0 182 | with: 183 | context: build 184 | push: true 185 | tags: ${{ steps.meta.outputs.tags }} 186 | labels: ${{ steps.meta.outputs.labels }} 187 | 188 | -------------------------------------------------------------------------------- /.github/workflows/CICD.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | # Main YML file for the CICD pipeline 5 | 6 | name: CI/CD 7 | 8 | on: 9 | push: 10 | branches: [ "main" ] 11 | pull_request: 12 | branches: [ "main" ] 13 | # Run on a daily schedule to perform the full set of tests. 14 | schedule: 15 | - cron: '00 21 * * *' 16 | merge_group: 17 | 18 | permissions: 19 | contents: read 20 | packages: write 21 | 22 | concurrency: 23 | # Cancel any CI/CD workflow currently in progress for the same PR. 24 | # Allow running concurrently with any other commits. 25 | group: cicd-${{ github.event.pull_request.number || github.sha }} 26 | cancel-in-progress: true 27 | 28 | jobs: 29 | windows_release: 30 | uses: ./.github/workflows/Build.yml 31 | with: 32 | platform: windows-2019 33 | configuration: RelWithDebInfo 34 | enable_sanitizers: false 35 | enable_coverage: false 36 | 37 | windows_debug: 38 | uses: ./.github/workflows/Build.yml 39 | with: 40 | platform: windows-2019 41 | configuration: Debug 42 | enable_sanitizers: false 43 | enable_coverage: false 44 | 45 | windows_release_2022: 46 | uses: ./.github/workflows/Build.yml 47 | with: 48 | platform: windows-2022 49 | configuration: RelWithDebInfo 50 | enable_sanitizers: false 51 | enable_coverage: false 52 | 53 | windows_debug_2022: 54 | uses: ./.github/workflows/Build.yml 55 | with: 56 | platform: windows-2022 57 | configuration: Debug 58 | enable_sanitizers: false 59 | enable_coverage: false 60 | 61 | ubuntu_release: 62 | uses: ./.github/workflows/Build.yml 63 | with: 64 | platform: ubuntu-22.04 65 | configuration: Release 66 | enable_sanitizers: false 67 | enable_coverage: false 68 | publish_docker: true 69 | 70 | ubuntu_debug: 71 | uses: ./.github/workflows/Build.yml 72 | with: 73 | platform: ubuntu-latest 74 | configuration: Debug 75 | enable_sanitizers: false 76 | enable_coverage: false 77 | 78 | ubuntu_release_sanitizers: 79 | uses: ./.github/workflows/Build.yml 80 | with: 81 | platform: ubuntu-latest 82 | configuration: Release 83 | enable_sanitizers: true 84 | enable_coverage: false 85 | 86 | ubuntu_debug_sanitizers: 87 | uses: ./.github/workflows/Build.yml 88 | with: 89 | platform: ubuntu-latest 90 | configuration: Debug 91 | enable_sanitizers: true 92 | enable_coverage: false 93 | 94 | ubuntu_release_coverage: 95 | uses: ./.github/workflows/Build.yml 96 | with: 97 | platform: ubuntu-22.04 98 | configuration: Release 99 | enable_sanitizers: false 100 | enable_coverage: true 101 | 102 | ubuntu_debug_coverage: 103 | uses: ./.github/workflows/Build.yml 104 | with: 105 | platform: ubuntu-latest 106 | configuration: Debug 107 | enable_sanitizers: false 108 | enable_coverage: true 109 | 110 | macos_release: 111 | uses: ./.github/workflows/Build.yml 112 | with: 113 | platform: macos-latest 114 | configuration: Release 115 | 116 | macos_debug: 117 | uses: ./.github/workflows/Build.yml 118 | with: 119 | platform: macos-latest 120 | configuration: Debug 121 | 122 | finish: 123 | needs: 124 | - ubuntu_release_coverage 125 | - ubuntu_debug_coverage 126 | runs-on: ubuntu-latest 127 | steps: 128 | - name: Harden Runner 129 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 130 | with: 131 | egress-policy: audit 132 | 133 | - name: Coveralls Finished 134 | uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6 135 | with: 136 | github-token: ${{ secrets.github_token }} 137 | parallel-finished: true 138 | 139 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | # For most projects, this workflow file will not need changing; you simply need 5 | # to commit it to your repository. 6 | # 7 | # You may wish to alter this file to override the set of languages analyzed, 8 | # or to provide custom queries or build logic. 9 | # 10 | # ******** NOTE ******** 11 | # We have attempted to detect the languages in your repository. Please check 12 | # the `language` matrix defined below to confirm you have the correct set of 13 | # supported CodeQL languages. 14 | # 15 | name: "CodeQL" 16 | 17 | on: 18 | push: 19 | branches: [ "main" ] 20 | pull_request: 21 | # The branches below must be a subset of the branches above 22 | branches: [ "main" ] 23 | schedule: 24 | - cron: '41 12 * * 5' 25 | 26 | concurrency: 27 | # Cancel any CI/CD workflow currently in progress for the same PR. 28 | # Allow running concurrently with any other commits. 29 | group: codeql-${{ github.event.pull_request.number || github.sha }} 30 | cancel-in-progress: true 31 | 32 | permissions: 33 | contents: read 34 | 35 | jobs: 36 | analyze: 37 | name: Analyze 38 | runs-on: ubuntu-latest 39 | permissions: 40 | actions: read 41 | contents: read 42 | security-events: write 43 | 44 | strategy: 45 | fail-fast: false 46 | matrix: 47 | language: [ 'cpp' ] 48 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 49 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 50 | 51 | steps: 52 | - name: Harden Runner 53 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 54 | with: 55 | egress-policy: audit 56 | 57 | - name: Checkout repository 58 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 59 | with: 60 | submodules: 'recursive' 61 | 62 | # Initializes the CodeQL tools for scanning. 63 | - name: Initialize CodeQL 64 | uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 65 | with: 66 | languages: ${{ matrix.language }} 67 | # If you wish to specify custom queries, you can do so here or in a config file. 68 | # By default, queries listed here will override any specified in a config file. 69 | # Prefix the list here with "+" to use these queries and those in the config file. 70 | 71 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 72 | # queries: security-extended,security-and-quality 73 | 74 | - name: Install prerequisites 75 | run: | 76 | sudo apt-get install -y libboost-dev libboost-filesystem-dev libboost-program-options-dev libelf-dev 77 | 78 | - name: Build/install libbpf From Source 79 | run: ./.github/scripts/build-libbpf.sh 80 | shell: bash 81 | 82 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 83 | # If this step fails, then you should remove it and run the build manually (see below) 84 | - name: Autobuild 85 | uses: github/codeql-action/autobuild@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 86 | 87 | # ℹ️ Command-line programs to run using the OS shell. 88 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 89 | 90 | # If the Autobuild fails above, remove it and uncomment the following three lines. 91 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 92 | 93 | # - run: | 94 | # echo "Run, Build Application using script" 95 | # ./location_of_script_within_repo/buildscript.sh 96 | 97 | - name: Perform CodeQL Analysis 98 | uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 99 | with: 100 | category: "/language:${{matrix.language}}" 101 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Dependency Review Action 2 | # 3 | # This Action will scan dependency manifest files that change as part of a Pull Request, 4 | # surfacing known-vulnerable versions of the packages declared or updated in the PR. 5 | # Once installed, if the workflow run is marked as required, 6 | # PRs introducing known-vulnerable packages will be blocked from merging. 7 | # 8 | # Source repository: https://github.com/actions/dependency-review-action 9 | name: 'Dependency Review' 10 | on: [pull_request] 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | dependency-review: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Harden Runner 20 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 21 | with: 22 | egress-policy: audit 23 | 24 | - name: 'Checkout Repository' 25 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 26 | - name: 'Dependency Review' 27 | uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1 28 | -------------------------------------------------------------------------------- /.github/workflows/scorecards.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. They are provided 2 | # by a third-party and are governed by separate terms of service, privacy 3 | # policy, and support documentation. 4 | 5 | name: Scorecard supply-chain security 6 | on: 7 | # For Branch-Protection check. Only the default branch is supported. See 8 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection 9 | branch_protection_rule: 10 | # To guarantee Maintained check is occasionally updated. See 11 | # https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained 12 | schedule: 13 | - cron: '20 7 * * 2' 14 | push: 15 | branches: ["main"] 16 | 17 | # Declare default permissions as read only. 18 | permissions: read-all 19 | 20 | jobs: 21 | analysis: 22 | name: Scorecard analysis 23 | runs-on: ubuntu-latest 24 | permissions: 25 | # Needed to upload the results to code-scanning dashboard. 26 | security-events: write 27 | # Needed to publish results and get a badge (see publish_results below). 28 | id-token: write 29 | contents: read 30 | actions: read 31 | 32 | steps: 33 | - name: Harden Runner 34 | uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0 35 | with: 36 | egress-policy: audit 37 | 38 | - name: "Checkout code" 39 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 40 | with: 41 | persist-credentials: false 42 | 43 | - name: "Run analysis" 44 | uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1 45 | with: 46 | results_file: results.sarif 47 | results_format: sarif 48 | # (Optional) "write" PAT token. Uncomment the `repo_token` line below if: 49 | # - you want to enable the Branch-Protection check on a *public* repository, or 50 | # - you are installing Scorecards on a *private* repository 51 | # To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat. 52 | # repo_token: ${{ secrets.SCORECARD_TOKEN }} 53 | 54 | # Public repositories: 55 | # - Publish results to OpenSSF REST API for easy access by consumers 56 | # - Allows the repository to include the Scorecard badge. 57 | # - See https://github.com/ossf/scorecard-action#publishing-results. 58 | # For private repositories: 59 | # - `publish_results` will always be set to `false`, regardless 60 | # of the value entered here. 61 | publish_results: true 62 | 63 | # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF 64 | # format to the repository Actions tab. 65 | - name: "Upload artifact" 66 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 67 | with: 68 | name: SARIF file 69 | path: results.sarif 70 | retention-days: 5 71 | 72 | # Upload the results to GitHub's code scanning dashboard. 73 | - name: "Upload to code-scanning" 74 | uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 75 | with: 76 | sarif_file: results.sarif 77 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeLists.txt.user 2 | CMakeCache.txt 3 | CMakeFiles 4 | CMakeScripts 5 | Testing 6 | Makefile 7 | cmake_install.cmake 8 | install_manifest.txt 9 | compile_commands.json 10 | CTestTestfile.cmake 11 | _deps 12 | build/* -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/elfio"] 2 | path = external/elfio 3 | url = https://github.com/serge1/ELFIO.git 4 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/gitleaks/gitleaks 3 | rev: v8.16.3 4 | hooks: 5 | - id: gitleaks 6 | - repo: https://github.com/jumanjihouse/pre-commit-hooks 7 | rev: 3.0.0 8 | hooks: 9 | - id: shellcheck 10 | - repo: https://github.com/pocc/pre-commit-hooks 11 | rev: v1.3.5 12 | hooks: 13 | - id: cpplint 14 | - repo: https://github.com/pre-commit/pre-commit-hooks 15 | rev: v4.4.0 16 | hooks: 17 | - id: end-of-file-fixer 18 | - id: trailing-whitespace 19 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | cmake_minimum_required(VERSION 3.16) 5 | project("bpf_conformance") 6 | 7 | if (IS_DIRECTORY "${PROJECT_SOURCE_DIR}/.git") 8 | # Install Git pre-commit hook 9 | file(COPY scripts/pre-commit scripts/commit-msg 10 | DESTINATION "${PROJECT_SOURCE_DIR}/.git/hooks") 11 | endif () 12 | 13 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) 14 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) 15 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) 16 | 17 | if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") 18 | add_compile_options(/ZH:SHA_256 /guard:cf /Qspectre /sdl) 19 | add_link_options(/guard:cf /CETCOMPAT) 20 | endif() 21 | 22 | include("cmake/FindLibBpf.cmake") 23 | include(CTest) 24 | 25 | add_subdirectory("src") 26 | if (EXISTS "${PROJECT_SOURCE_DIR}/external/elfio") 27 | add_subdirectory("external/elfio") 28 | else() 29 | message(FATAL_ERROR "Missing elfio -- initialize submodules recursively, please.") 30 | endif() 31 | 32 | file(COPY tests DESTINATION .) 33 | 34 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 35 | file(COPY Docker/Windows/Dockerfile DESTINATION .) 36 | endif() 37 | 38 | if(CMAKE_SYSTEM_NAME STREQUAL "Linux") 39 | file(COPY Docker/Linux/Dockerfile DESTINATION .) 40 | endif() 41 | 42 | 43 | if (LIBBPF_FOUND) 44 | add_subdirectory("libbpf_plugin") 45 | endif() 46 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to BPF Conformance 2 | 3 | We'd love your help with BPF Conformance! Here are our contribution guidelines. 4 | 5 | - [Code of Conduct](#code-of-conduct) 6 | - [Bugs](#bugs) 7 | - [New Features](#new-features) 8 | - [Contributor License Agreement](#contributor-license-agreement) 9 | - [Contributing Code](#contributing-code) 10 | - [Tests](#tests) 11 | 12 | ## Code of Conduct 13 | 14 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 15 | For more information see the [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 16 | or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with additional questions or comments. 17 | 18 | ## Bugs 19 | 20 | ### Did you find a bug? 21 | 22 | First, **ensure the bug was not already reported** by searching on GitHub under 23 | [Issues](https://github.com/Alan-Jowett/bpf_conformance/issues). 24 | 25 | If you found a non-security related bug, you can help us by 26 | [submitting a GitHub Issue](https://github.com/Alan-Jowett/bpf_conformance/issues/new). 27 | The best bug reports provide a detailed description of the issue and step-by-step instructions 28 | for reliably reproducing the issue. 29 | 30 | We will aim to triage issues in weekly triage meetings. In case we are unable to repro the issue, we will request more information from you, the filer. 31 | There will be a waiting period of 2 weeks for the requested information and if there is no response, the issue will be closed. If this happens, please reopen the issue if you do get a repro and collect the requested information. 32 | 33 | However, in the best case, we would love it if you can submit a Pull Request with a fix. 34 | 35 | If you found a security issue, please **do not open a GitHub Issue**, and instead follow 36 | [these instructions](docs/SECURITY.md). 37 | 38 | ### Did you write a patch that fixes a bug? 39 | 40 | Fork the repo and make your changes. 41 | Then open a new GitHub pull request with the patch. 42 | 43 | * Ensure the PR description clearly describes the problem and solution. 44 | Include the relevant issue number if applicable. 45 | 46 | * Before submitting, please read the [Development Guide](docs/DevelopmentGuide.md) 47 | to know more about coding conventions. 48 | 49 | ## New Features 50 | 51 | You can request a new feature by [submitting a GitHub Issue](https://github.com/Alan-Jowett/bpf_conformance/issues/new). 52 | 53 | If you would like to implement a new feature, please first 54 | [submit a GitHub Issue](https://github.com/Alan-Jowett/bpf_conformance/issues/new) and 55 | communicate your proposal so that the community can review and provide feedback. Getting 56 | early feedback will help ensure your implementation work is accepted by the community. 57 | This will also allow us to better coordinate our efforts and minimize duplicated effort. 58 | 59 | ## Contributor License Agreement 60 | 61 | You will need to complete a Contributor License Agreement (CLA) for any code submissions. 62 | Briefly, this agreement testifies that you are granting us permission to use the submitted 63 | change according to the terms of the project's license, and that the work being submitted 64 | is under appropriate copyright. You only need to do this once. For more information see 65 | https://cla.opensource.microsoft.com/. 66 | 67 | ## Contributing Code 68 | 69 | For all but the absolute simplest changes, first 70 | [submit a GitHub Issue](https://github.com/Alan-Jowett/bpf_conformance/issues/new) so that the 71 | community can review and provide feedback. Getting early feedback will help ensure your work 72 | is accepted by the community. This will also allow us to better coordinate our efforts and 73 | minimize duplicated effort. 74 | 75 | If you would like to contribute, first identify the scale of what you would like to contribute. 76 | If it is small (grammar/spelling or a bug fix) feel free to start working on a fix. If you are 77 | submitting a feature or substantial code contribution, please discuss it with the maintainers and 78 | ensure it follows the product roadmap. You might also read these two blogs posts on contributing 79 | code: [Open Source Contribution Etiquette](http://tirania.org/blog/archive/2010/Dec-31.html) by Miguel de Icaza and 80 | [Don't "Push" Your Pull Requests](https://www.igvita.com/2011/12/19/dont-push-your-pull-requests/) by Ilya Grigorik. 81 | All code submissions will be rigorously [reviewed](docs/Governance.md) and tested by the maintainers, and only those that meet 82 | the bar for both quality and design/roadmap appropriateness will be merged into the source. 83 | 84 | For all new Pull Requests the following rules apply: 85 | - Existing tests should continue to pass. 86 | - Tests need to be provided for every bug/feature that is completed. 87 | - Documentation needs to be provided for every feature that is end-user visible. 88 | -------------------------------------------------------------------------------- /Docker/Linux/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | FROM ubuntu:24.04@sha256:6015f66923d7afbc53558d7ccffd325d43b4e249f41a6e93eef074c9505d2233 5 | 6 | # Install dependencies 7 | RUN apt-get update && apt-get install -y \ 8 | libboost-program-options-dev \ 9 | libbpf-dev 10 | 11 | # Clean up APT when done. 12 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* 13 | 14 | WORKDIR /app 15 | 16 | COPY . . 17 | 18 | LABEL org.opencontainers.image.source=https://github.com/Alan-Jowett/bpf_conformance 19 | LABEL org.opencontainers.image.description="BPF Conformance container image" 20 | LABEL org.opencontainers.image.licenses=MIT -------------------------------------------------------------------------------- /Docker/Windows/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | FROM mcr.microsoft.com/windows/nanoserver:ltsc2019@sha256:976bddfc8aa59d7b861b94467a8fb620e727874bb9f736aace6ab8b3b46aa5c8 5 | 6 | WORKDIR /app 7 | 8 | COPY . . 9 | 10 | LABEL org.opencontainers.image.source=https://github.com/Alan-Jowett/bpf_conformance 11 | LABEL org.opencontainers.image.description="BPF Conformance container image" 12 | LABEL org.opencontainers.image.licenses=MIT -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BPF Conformance 2 | [![CI/CD](https://github.com/Alan-Jowett/bpf_conformance/actions/workflows/CICD.yml/badge.svg?branch=main)](https://github.com/Alan-Jowett/bpf_conformance/actions/workflows/CICD.yml) 3 | [![Coverage Status](https://coveralls.io/repos/github/Alan-Jowett/bpf_conformance/badge.png?branch=main)](https://coveralls.io/github/Alan-Jowett/bpf_conformance?branch=main) 4 | 5 | This project measures the conformance of a BPF runtime to the ISA. To measure conformance the BPF runtime under test is built into a plugin process that does: 6 | 1) Accept both BPF byte code an initial memory. 7 | 2) Execute the byte code. 8 | 3) Return the value in %r0 at the end of the execution. 9 | 10 | ## eBPF runtime implementations that are currently measured using this project 11 | 1) [Linux Kernel via libbpf](https://github.com/Alan-Jowett/bpf_conformance/tree/main/libbpf_plugin) 12 | 2) [uBPF](https://github.com/iovisor/ubpf/tree/main/ubpf_plugin) 13 | 3) [eBPF for Windows / bpf2c](https://github.com/microsoft/ebpf-for-windows/tree/main/tests/bpf2c_plugin) 14 | 4) [rbpf](https://github.com/qmonnet/rbpf/blob/master/examples/rbpf_plugin.rs) 15 | 5) [Prevail Verifier](https://github.com/vbpf/ebpf-verifier/blob/main/src/test/test_conformance.cpp) 16 | 6) [bpftime / llvmbpf](https://github.com/eunomia-bpf/llvmbpf), The result is [here](https://eunomia-bpf.github.io/llvmbpf/bpf_conformance_results.txt) 17 | 18 | Note: 19 | Linux Kernel is treated as the authorative eBPF implementation. 20 | 21 | ## Prerequisites 22 | 23 | ### Ubuntu 24 | 25 | ``` 26 | sudo apt-get install -y libboost-dev libboost-filesystem-dev libboost-program-options-dev libelf-dev lcov libbpf-dev 27 | ``` 28 | 29 | ### MacOS 30 | 31 | ``` 32 | brew install cmake ninja ccache boost 33 | ``` 34 | 35 | ## Building 36 | 37 | Run ```cmake -S . -B build``` to configure the project, then run ```cmake --build build``` to build the project. 38 | 39 | ## Usage 40 | 41 | ``` 42 | Options: 43 | --help Print help messages 44 | --test_file_path arg Path to test file 45 | --test_file_directory arg Path to test file directory 46 | --plugin_path arg Path to plugin 47 | --plugin_options arg Options to pass to plugin 48 | --list_instructions arg List instructions used and not used in tests 49 | --list_used_instructions arg List instructions used in tests 50 | --list_unused_instructions arg List instructions not used in tests 51 | --debug (true|false) Print debug information 52 | --xdp_prolog (true|false) XDP prolog 53 | --elf (true|false) ELF format 54 | --cpu_version arg CPU version 55 | --include_regex arg Include regex 56 | --exclude_regex arg Exclude regex 57 | ``` 58 | 59 | `--xdp_prolog true` should *only* be used with the `libbpf_plugin`. 60 | 61 | ## Using a published package 62 | Select the desired version from [bpf_conformance](https://github.com/Alan-Jowett/bpf_conformance/pkgs/container/bpf_conformance) 63 | 64 | Assume the package is named: "ghcr.io/alan-jowett/bpf_conformance:main" 65 | ``` 66 | docker run --privileged -it --rm ghcr.io/alan-jowett/bpf_conformance:main src/bpf_conformance_runner --test_file_directory tests --plugin_path libbpf_plugin/libbpf_plugin --cpu_version v3 67 | ``` 68 | 69 | ## Running the test 70 | Linux (test require Linux kernel BPF support): 71 | ``` 72 | cmake --build build --target test -- 73 | ``` 74 | 75 | Note: The libbpf_plugin requires root or BPF permissions. 76 | 77 | ## Using bpf_conformance as a static lib 78 | The BPF Conformance tests can also be used as a static library as part of another tests. 79 | 1) Include include/bpf_conformance.h 80 | 2) Link against libbpf_conformance.a and boost_filesystem (depending on platform). 81 | 3) Invoke bpf_conformance, passing it a list of test files. 82 | 83 | ## Interpreting results 84 | On completion of the test the bpf_conformance tools prints the list of tests that passes/failed and a summary count. 85 | 86 | ``` 87 | sudo build/src/bpf_conformance --test_file_directory tests --plugin_path build/libbpf_plugin/libbpf_plugin 88 | Test results: 89 | PASS: "tests/add.data" 90 | PASS: "tests/add64.data" 91 | PASS: "tests/alu-arith.data" 92 | PASS: "tests/alu-bit.data" 93 | PASS: "tests/alu64-arith.data" 94 | PASS: "tests/alu64-bit.data" 95 | PASS: "tests/arsh-reg.data" 96 | PASS: "tests/arsh.data" 97 | PASS: "tests/arsh32-high-shift.data" 98 | PASS: "tests/arsh64.data" 99 | PASS: "tests/be16-high.data" 100 | PASS: "tests/be16.data" 101 | PASS: "tests/be32-high.data" 102 | PASS: "tests/be32.data" 103 | PASS: "tests/be64.data" 104 | PASS: "tests/call_unwind_fail.data" 105 | PASS: "tests/div-by-zero-reg.data" 106 | PASS: "tests/div32-high-divisor.data" 107 | PASS: "tests/div32-imm.data" 108 | PASS: "tests/div32-reg.data" 109 | PASS: "tests/div64-by-zero-reg.data" 110 | PASS: "tests/div64-imm.data" 111 | PASS: "tests/div64-reg.data" 112 | PASS: "tests/exit-not-last.data" 113 | PASS: "tests/exit.data" 114 | PASS: "tests/jeq-imm.data" 115 | PASS: "tests/jeq-reg.data" 116 | PASS: "tests/jge-imm.data" 117 | PASS: "tests/jgt-imm.data" 118 | PASS: "tests/jgt-reg.data" 119 | PASS: "tests/jit-bounce.data" 120 | PASS: "tests/jle-imm.data" 121 | PASS: "tests/jle-reg.data" 122 | PASS: "tests/jlt-imm.data" 123 | PASS: "tests/jlt-reg.data" 124 | PASS: "tests/jne-reg.data" 125 | PASS: "tests/jset-imm.data" 126 | PASS: "tests/jset-reg.data" 127 | PASS: "tests/jsge-imm.data" 128 | PASS: "tests/jsge-reg.data" 129 | PASS: "tests/jsgt-imm.data" 130 | PASS: "tests/jsgt-reg.data" 131 | PASS: "tests/jsle-imm.data" 132 | PASS: "tests/jsle-reg.data" 133 | PASS: "tests/jslt-imm.data" 134 | PASS: "tests/jslt-reg.data" 135 | PASS: "tests/lddw.data" 136 | PASS: "tests/lddw2.data" 137 | PASS: "tests/ldxb-all.data" 138 | PASS: "tests/ldxb.data" 139 | PASS: "tests/ldxdw.data" 140 | PASS: "tests/ldxh-all.data" 141 | PASS: "tests/ldxh-all2.data" 142 | PASS: "tests/ldxh-same-reg.data" 143 | PASS: "tests/ldxh.data" 144 | PASS: "tests/ldxw-all.data" 145 | PASS: "tests/ldxw.data" 146 | PASS: "tests/le16.data" 147 | PASS: "tests/le32.data" 148 | PASS: "tests/le64.data" 149 | PASS: "tests/lsh-reg.data" 150 | PASS: "tests/mem-len.data" 151 | PASS: "tests/mod-by-zero-reg.data" 152 | PASS: "tests/mod.data" 153 | PASS: "tests/mod32.data" 154 | PASS: "tests/mod64-by-zero-reg.data" 155 | PASS: "tests/mod64.data" 156 | PASS: "tests/mov.data" 157 | PASS: "tests/mul32-imm.data" 158 | PASS: "tests/mul32-reg-overflow.data" 159 | PASS: "tests/mul32-reg.data" 160 | PASS: "tests/mul64-imm.data" 161 | PASS: "tests/mul64-reg.data" 162 | PASS: "tests/neg.data" 163 | PASS: "tests/neg64.data" 164 | PASS: "tests/prime.data" 165 | PASS: "tests/rsh-reg.data" 166 | PASS: "tests/rsh32.data" 167 | PASS: "tests/stack.data" 168 | PASS: "tests/stb.data" 169 | PASS: "tests/stdw.data" 170 | PASS: "tests/sth.data" 171 | PASS: "tests/stw.data" 172 | PASS: "tests/stxb-all.data" 173 | PASS: "tests/stxb-all2.data" 174 | PASS: "tests/stxb-chain.data" 175 | PASS: "tests/stxb.data" 176 | PASS: "tests/stxdw.data" 177 | PASS: "tests/stxh.data" 178 | PASS: "tests/stxw.data" 179 | PASS: "tests/subnet.data" 180 | Passed 91 out of 91 tests. 181 | ``` 182 | 183 | ## bpf_conformance_runner plugins 184 | 185 | bpf_conformance_runner invokes plugins using command-line execution, and uses stdin, stdout, and stderr to 186 | exchange additional information as follows: 187 | 188 | ``` 189 | [] [] [--elf] 190 | ``` 191 | 192 | where: 193 | * ``: the plugin executable name 194 | * ``: if present, the contents of the `mem` section of a test data file 195 | * ``: any additional options to pass to the plugin 196 | * `--elf`: if present, indicates that the data passed to stdin will be in ELF format 197 | 198 | The program is then passed to the plugin via stdin, either as raw bytecode or (if `--elf` is specified) in ELF format. 199 | The plugin must then either: 200 | * compute a successful result and output the final contents of `r0` in hex (either with or without a leading "0x") 201 | to stdout and exit with a status of 0, OR 202 | * output an error message to stderr and exit with a non-zero status. 203 | 204 | Additional plugins can be created based on the above specification. 205 | -------------------------------------------------------------------------------- /cmake/FindLibBpf.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | # This file is derived from the following link: 5 | # https://github.com/iovisor/bpftrace/blob/master/cmake/FindLibBpf.cmake 6 | 7 | # - Try to find libbpf 8 | # Once done this will define 9 | # 10 | # LIBBPF_FOUND - system has libbpf 11 | # LIBBPF_INCLUDE_DIRS - the libbpf include directory 12 | # LIBBPF_LIBRARIES - Link these to use libbpf 13 | # LIBBPF_DEFINITIONS - Compiler switches required for using libbpf 14 | 15 | #if (LIBBPF_LIBRARIES AND LIBBPF_INCLUDE_DIRS) 16 | # set (LibBpf_FIND_QUIETLY TRUE) 17 | #endif (LIBBPF_LIBRARIES AND LIBBPF_INCLUDE_DIRS) 18 | 19 | find_path (LIBBPF_INCLUDE_DIRS 20 | NAMES 21 | bpf/bpf.h 22 | bpf/libbpf.h 23 | PATHS 24 | ENV CPATH) 25 | 26 | find_library (LIBBPF_LIBRARIES 27 | NAMES 28 | bpf 29 | PATHS 30 | ENV LIBRARY_PATH 31 | ENV LD_LIBRARY_PATH) 32 | 33 | include (FindPackageHandleStandardArgs) 34 | 35 | # handle the QUIETLY and REQUIRED arguments and set LIBBPF_FOUND to TRUE if all listed variables are TRUE 36 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibBpf "Please install the libbpf development package" 37 | LIBBPF_LIBRARIES 38 | LIBBPF_INCLUDE_DIRS) 39 | 40 | mark_as_advanced (LIBBPF_LIBRARIES LIBBPF_INCLUDE_DIRS) 41 | 42 | if (LIBBPF_FOUND) 43 | set (LIBBPF_DEFINITIONS -DHAVE_LIBBPF) 44 | elseif() 45 | message (WARNING "libbpf not found") 46 | endif() -------------------------------------------------------------------------------- /cmake/options.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | if(PLATFORM_WINDOWS) 5 | option(BOOST_VERSION "Boost version to use" "1.80.0") 6 | endif() 7 | -------------------------------------------------------------------------------- /cmake/platform.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 5 | set(PLATFORM_WINDOWS true) 6 | 7 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") 8 | set(PLATFORM_MACOS true) 9 | 10 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") 11 | set(PLATFORM_LINUX true) 12 | endif() 13 | -------------------------------------------------------------------------------- /docs/DevelopmentGuide.md: -------------------------------------------------------------------------------- 1 | Development Guide 2 | ================= 3 | 4 | Coding Conventions 5 | ------------------ 6 | 7 | * **DO** use fixed length types defined in `stdint.h` instead 8 | of language keywords determined by the compiler (e.g., `int64_t, uint8_t`, not 9 | `long, unsigned char`). 10 | 11 | * **DO** use `const` and `static` and visibility modifiers to scope exposure of 12 | variables and methods as much as possible. 13 | 14 | * **DO** use doxygen comments, with \[in,out\] 15 | [direction annotation](http://www.doxygen.nl/manual/commands.html#cmdparam) in all public API 16 | headers. This is also encouraged, but not strictly required, for internal API 17 | headers as well. 18 | 19 | * **DON'T** use global variables where possible. 20 | 21 | * **DON'T** use abbreviations unless they are already well-known terms known by 22 | users (e.g., "app", "info"), or are already required for use by developers (e.g., 23 | "min", "max", "args"). Examples of bad use would be `num_widgets` instead of 24 | `widget_count`, and `opt_widgets` instead of `option_widgets` or `optional_widgets`. 25 | 26 | * **DON'T** use hard-coded magic numbers for things that have to be consistent 27 | between different files. Instead use a `#define` or an enum or const value, as appropriate. 28 | 29 | * **DON'T** use the same C function name with two different prototypes across 30 | the project where possible. 31 | 32 | * **DON'T** use commented-out code, or code in an `#if 0` or equivalent. Make sure all code is actually 33 | built. 34 | 35 | Header Files 36 | ------------ 37 | 38 | * **DO** make sure any header file can be included directly, without requiring other 39 | headers to be included first. That is, any dependencies should be included within 40 | the header file itself. 41 | 42 | * **DO** include local headers (with `""`) before system headers (with `<>`). This 43 | helps ensure that local headers don't have dependencies on other things being 44 | included first, and is also consistent with the use of a local header for precompiled 45 | headers. 46 | 47 | * **DO** list headers in alphabetical order where possible. This helps ensure there are not duplicate includes, 48 | and also helps ensure that headers are usable directly. 49 | 50 | * **DO** use `#pragma once` in all header files, rather than using ifdefs to test for duplicate inclusion. 51 | 52 | Style Guide 53 | ----------- 54 | 55 | ### Automated Formatting with `clang-format` 56 | 57 | For all C/C++ files (`*.c`, `*.cpp` and `*.h`), we use `clang-format` (specifically 58 | version ```11.0.1```) to apply our code formatting rules. After modifying C/C++ files and 59 | before merging, be sure to run: 60 | 61 | ```sh 62 | $ ./scripts/format-code 63 | ``` 64 | 65 | ### Formatting Notes: 66 | 67 | Our coding conventions follow the [LLVM coding standards](https://llvm.org/docs/CodingStandards.html) with 68 | the following over-rides: 69 | 70 | * Source lines **MUST NOT** exceed 120 columns. 71 | * Single-line if/else/loop blocks **MUST** be enclosed in braces. 72 | 73 | Please stage the formatting changes with your commit, instead of making an extra 74 | "Format Code" commit. Your editor can likely be set up to automatically run 75 | `clang-format` across the file or region you're editing. See: 76 | 77 | - [clang-format.el](https://github.com/llvm-mirror/clang/blob/master/tools/clang-format/clang-format.el) for Emacs 78 | - [vim-clang-format](https://github.com/rhysd/vim-clang-format) for Vim 79 | - [vscode-cpptools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) 80 | for Visual Studio Code 81 | 82 | The [.clang-format](../.clang-format) file describes the style that is enforced 83 | by the script, which is based off the LLVM style with modifications closer to 84 | the default Visual Studio style. See [clang-format style options]( 85 | http://releases.llvm.org/3.6.0/tools/clang/docs/ClangFormatStyleOptions.html) 86 | for details. 87 | 88 | If you see unexpected formatting changes in the code, verify that you are running version 11 or higher of the LLVM tool-chain. 89 | 90 | ### License Header 91 | 92 | The following license header **must** be included at the top of every code file: 93 | 94 | ``` 95 | // Copyright (c) Microsoft Corporation 96 | // SPDX-License-Identifier: MIT 97 | ``` 98 | 99 | It should be prefixed with the file's comment marker. If there is a compelling 100 | reason to not include this header, the file can be added to 101 | `.check-license.ignore`. 102 | 103 | All files are checked for this header with the script: 104 | 105 | ```sh 106 | $ ./scripts/check-license 107 | ``` 108 | 109 | ### Naming Conventions 110 | 111 | Naming conventions we use that are not automated include: 112 | 113 | 1. Use `lower_snake_case` for variable, member/field, and function names. 114 | 2. Use `UPPER_SNAKE_CASE` for macro names and constants. 115 | 3. Prefer `lower_snake_case` file names for headers and sources. 116 | 4. Prefer full words for names over contractions (i.e., `memory_context`, not 117 | `mem_ctx`). 118 | 5. Prefix names with `_` to indicate internal and private fields or methods 119 | (e.g., `_internal_field, _internal_method()`). 120 | 6. The single underscore (`_` ) is reserved for local definitions (static, 121 | file-scope definitions). 122 | e.g., static ebpf_result_t _do_something(..). 123 | 7. Prefix `struct` definitions with `_` (this is an exception to point 6), and always create a `typedef` with the 124 | suffix `_t`. For example: 125 | ```c 126 | typedef struct _ebpf_widget 127 | { 128 | uint64_t count; 129 | } ebpf_widget_t; 130 | ``` 131 | 8. Prefix eBPF specific names in the global namespace with `ebpf_` (e.g., `ebpf_result_t`). 132 | 133 | Above all, if a file happens to differ in style from these guidelines (e.g., 134 | private members are named `m_member` rather than `_member`), the existing style 135 | in that file takes precedence. 136 | -------------------------------------------------------------------------------- /docs/Governance.md: -------------------------------------------------------------------------------- 1 | # Project Governance 2 | 3 | ## Reviewing Pull Requests 4 | 5 | Pull requests need at least two approvals before being eligible for merging. 6 | Besides reviewing for technical correctness, reviewers are expected to: 7 | 8 | * For any PR that adds functionality, check that the PR includes sufficient tests 9 | for that functionality. This is required in [CONTRIBUTING.md](../Contributing.md). 10 | * For any PR that adds or changes functionality in a way that is observable 11 | by administrators or by authors of eBPF programs or applications, check that 12 | documentation has been sufficiently updated. This is required in 13 | [CONTRIBUTING.md](../Contributing.md). 14 | * Check that there are no gratuitous differences in public APIs between eBPF for 15 | Windows and Linux. 16 | * Be familiar with, and call out code that does not conform to, the eBPF for Windows 17 | [coding conventions](DevelopmentGuide.md). 18 | * Check that errors are appropriately logged where first detected (not at each 19 | level of stack unwind). 20 | 21 | When multiple pull requests are approved, maintainers should prioritize merging PRs as follows: 22 | 23 | | Pri | Description | Tags | Rationale | 24 | | --- | ------------ | --------- | ---------------------- | 25 | | 1 | Bugs | bug | Affects existing users | 26 | | 2 | Test bugs | tests bug | Problem that affects CI/CD and may mask priority 1 bugs | 27 | | 3 | Additional tests | tests enhancement | Gap that once filled might surface priority 1 bugs | 28 | | 4 | Documentation | documentation | Won't affect CI/CD but may address usability issues | 29 | | 5 | Dependencies | dependencies | Often a large amount of low hanging fruit. Keeping the overall PR count low gives a better impression to newcomers and observers. | 30 | | 7 | New features | enhancement | Adds new functionality requested in a github issue. Although this typically is lower priority than dependencies, such PRs from new contributors should instead be prioritized above dependencies. | 31 | | 8 | Performance optimizations | optimization | Doesn't do anything that isn't already working, but improvements do help users | 32 | | 9 | Code cleanup | cleanup | Good to do but generally doesn't significantly affect any of the above categories | 33 | -------------------------------------------------------------------------------- /docs/SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)) of a security vulnerability, please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /include/bpf_conformance.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // SPDX-License-Identifier: MIT 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef enum class _bpf_conformance_test_result 12 | { 13 | TEST_RESULT_PASS, 14 | TEST_RESULT_FAIL, 15 | TEST_RESULT_SKIP, 16 | TEST_RESULT_ERROR, 17 | TEST_RESULT_UNKNOWN 18 | } bpf_conformance_test_result_t; 19 | 20 | typedef enum class _bpf_conformance_test_cpu_version 21 | { 22 | v1 = 1, 23 | v2 = 2, 24 | v3 = 3, 25 | v4 = 4, 26 | unknown = -1, 27 | } bpf_conformance_test_cpu_version_t; 28 | 29 | typedef enum class _bpf_conformance_groups 30 | { 31 | none = 0x00000000, 32 | base32 = 0x00000001, 33 | base64 = 0x00000002, 34 | atomic32 = 0x00000004, 35 | atomic64 = 0x00000008, 36 | divmul32 = 0x00000010, 37 | divmul64 = 0x00000020, 38 | packet = 0x00000040, 39 | callx = 0x00000080, 40 | default_groups = base32 | base64 | atomic32 | atomic64 | divmul32 | divmul64, // not callx or packet 41 | } bpf_conformance_groups_t; 42 | 43 | inline bpf_conformance_groups_t 44 | operator~(bpf_conformance_groups_t a) 45 | { 46 | return static_cast(~static_cast(a)); 47 | } 48 | 49 | inline bpf_conformance_groups_t 50 | operator|(bpf_conformance_groups_t a, bpf_conformance_groups_t b) 51 | { 52 | return static_cast(static_cast(a) | static_cast(b)); 53 | } 54 | 55 | inline bpf_conformance_groups_t& 56 | operator|=(bpf_conformance_groups_t& a, bpf_conformance_groups_t b) 57 | { 58 | return a = a | b; 59 | } 60 | 61 | inline bpf_conformance_groups_t 62 | operator&(bpf_conformance_groups_t a, bpf_conformance_groups_t b) 63 | { 64 | return static_cast(static_cast(a) & static_cast(b)); 65 | } 66 | 67 | inline bpf_conformance_groups_t& 68 | operator&=(bpf_conformance_groups_t& a, bpf_conformance_groups_t b) 69 | { 70 | return a = a & b; 71 | } 72 | 73 | // Add typedef for backwards compatibility. 74 | typedef bpf_conformance_test_cpu_version_t bpf_conformance_test_CPU_version_t; 75 | 76 | typedef enum class _bpf_conformance_list_instructions 77 | { 78 | LIST_INSTRUCTIONS_NONE, // Do not list instructions. 79 | LIST_INSTRUCTIONS_USED, // List instructions used by the test. 80 | LIST_INSTRUCTIONS_UNUSED, // List instructions not used by the test. 81 | LIST_INSTRUCTIONS_ALL, // List all instructions. 82 | } bpf_conformance_list_instructions_t; 83 | 84 | typedef struct _bpf_conformance_options 85 | { 86 | std::optional include_test_regex; 87 | std::optional exclude_test_regex; 88 | bpf_conformance_test_cpu_version_t cpu_version; 89 | bpf_conformance_groups_t groups; 90 | bpf_conformance_list_instructions_t list_instructions_option; 91 | bool debug; 92 | bool xdp_prolog; 93 | bool elf_format; 94 | } bpf_conformance_options_t; 95 | 96 | /** 97 | * @brief Run the BPF conformance tests with the given plugin. 98 | * 99 | * @param[in] test_files List of test files to run. 100 | * @param[in] plugin_path The path to the plugin to run the tests with. 101 | * @param[in] plugin_options The options to pass to the plugin. 102 | * @param[in] options Options controlling the behavior of the tests. 103 | * @return The test results for each test file. 104 | */ 105 | std::map> 106 | bpf_conformance_options( 107 | const std::vector& test_files, 108 | const std::filesystem::path& plugin_path, 109 | const std::vector& plugin_options, 110 | const bpf_conformance_options_t& options); 111 | 112 | // Backwards compatibility wrapper. 113 | /** 114 | * @brief Run the BPF conformance tests with the given plugin. 115 | * 116 | * @param[in] test_files List of test files to run. 117 | * @param[in] plugin_path The path to the plugin to run the tests with. 118 | * @param[in] plugin_options The options to pass to the plugin. 119 | * @param[in] include_test_regex A regex that matches the tests to include. 120 | * @param[in] exclude_test_regex A regex that matches the tests to exclude. 121 | * @param[in] cpu_version The CPU version to run the tests with. 122 | * @param[in] groups The conformance groups to run the tests with. 123 | * @param[in] list_instructions_option Option controlling which instructions to list. 124 | * @param[in] debug Print debug information. 125 | * @return The test results for each test file. 126 | */ 127 | inline std::map> 128 | bpf_conformance( 129 | const std::vector& test_files, 130 | const std::filesystem::path& plugin_path, 131 | const std::vector& plugin_options, 132 | std::optional include_test_regex = std::nullopt, 133 | std::optional exclude_test_regex = std::nullopt, 134 | bpf_conformance_test_cpu_version_t cpu_version = bpf_conformance_test_cpu_version_t::v3, 135 | bpf_conformance_groups_t groups = bpf_conformance_groups_t::default_groups, 136 | bpf_conformance_list_instructions_t list_instructions_option = 137 | bpf_conformance_list_instructions_t::LIST_INSTRUCTIONS_NONE, 138 | bool debug = false) 139 | { 140 | bpf_conformance_options_t options = {}; 141 | options.include_test_regex = include_test_regex; 142 | options.exclude_test_regex = exclude_test_regex; 143 | options.cpu_version = cpu_version; 144 | options.groups = groups, 145 | options.list_instructions_option = list_instructions_option; 146 | options.debug = debug; 147 | return bpf_conformance_options(test_files, plugin_path, plugin_options, options); 148 | } 149 | 150 | const std::string bpf_conformance_xdp_section_name = "xdp"; 151 | const std::string bpf_conformance_default_section_name = ".text"; 152 | const std::string bpf_conformance_default_function_name = "main"; 153 | -------------------------------------------------------------------------------- /libbpf_plugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | set(CMAKE_CXX_STANDARD 20) 5 | 6 | include_directories(${LIBBPF_INCLUDE_DIRS}) 7 | link_directories(${LIBBPF_LIBRARIES}) 8 | 9 | include(CheckSymbolExists) 10 | 11 | set(CMAKE_REQUIRED_INCLUDES ${LIBBPF_INCLUDE_DIRS}) 12 | set(CMAKE_REQUIRED_LIBRARIES ${LIBBPF_LIBRARIES}) 13 | check_symbol_exists(bpf_prog_load "bpf/bpf.h" HAS_BPF_PROG_LOAD) 14 | 15 | if(NOT HAS_BPF_PROG_LOAD) 16 | add_compile_definitions(USE_DEPRECATED_LOAD_PROGRAM) 17 | endif() 18 | 19 | add_executable( 20 | libbpf_plugin 21 | libbpf_plugin.cc 22 | ) 23 | 24 | target_link_libraries(libbpf_plugin PRIVATE ${LIBBPF_LIBRARIES}) 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /negative/empty.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -------------------------------------------------------------------------------- /negative/error.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | or %r0, %r10 5 | exit 6 | -- error 7 | Invalid -------------------------------------------------------------------------------- /negative/incorrect_return_value_high_bits.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxdw %r0, [%r1+2] 5 | exit 6 | -- mem 7 | aa bb 11 22 33 44 55 66 77 88 cc dd 8 | -- result 9 | 0x8977665544332211 10 | -------------------------------------------------------------------------------- /negative/invalid.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright (c) Microsoft Corporation 4 | # SPDX-License-Identifier: MIT 5 | 6 | echo "This is a negative test" 7 | exit $* -------------------------------------------------------------------------------- /negative/invalid_label.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ja NOT_A_LABEL 5 | exit 6 | -- result 7 | 0x11 8 | -------------------------------------------------------------------------------- /negative/invalid_lock.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lock or [%r10-8] 5 | exit 6 | -- error 7 | Invalid number of operands for lock -------------------------------------------------------------------------------- /negative/invalid_lock2.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lock 5 | exit 6 | -- error 7 | Invalid number of operands for lock -------------------------------------------------------------------------------- /negative/invalid_mnemonic.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | # Invalid mnemonic 5 | ldxq %r0, %r1 6 | exit 7 | -- result 8 | 0x11 9 | -------------------------------------------------------------------------------- /negative/invalid_offset.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxb %r0, %r1 5 | exit 6 | -- result 7 | 0x11 8 | -------------------------------------------------------------------------------- /negative/invalid_operand_count.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0 5 | exit 6 | -- result 7 | 0x11 8 | -------------------------------------------------------------------------------- /negative/invalid_register.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | or %r0, %r50 5 | exit 6 | -- error 7 | Invalid register -------------------------------------------------------------------------------- /negative/invalid_unknown_directive.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | -- Unknown directive 5 | -- error 6 | Invalid register -------------------------------------------------------------------------------- /scripts/.check-license.ignore: -------------------------------------------------------------------------------- 1 | # This file uses regular expressions, not shell globs! 2 | 3 | # File extensions that don't support embedding license info 4 | .*\.md$ 5 | .*\.o$ 6 | .*\.png$ 7 | .*\.proj$ 8 | .*\.rc$ 9 | .*\.sln$ 10 | .*\.vsdx$ 11 | 12 | # Generated files 13 | tools/netsh/resource.h 14 | 15 | # Other Files 16 | LICENSE.txt 17 | Doxyfile 18 | \.check-license\.ignore 19 | \.clang-format 20 | \.gitattributes 21 | \.github/CODEOWNERS 22 | \.github/workflows/build.yml 23 | \.gitignore 24 | \.gitmodules 25 | packages.config 26 | -------------------------------------------------------------------------------- /scripts/check-license.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (c) Microsoft Corporation 4 | # SPDX-License-Identifier: MIT 5 | 6 | # This script accepts either a list of files relative to the current 7 | # working directory, or it will check all files tracked in Git. In 8 | # both cases, it ignores files matching any regular expression listed 9 | # in '.check-license.ignore'. 10 | 11 | set -o errexit 12 | set -o pipefail 13 | 14 | license=("Copyright" "SPDX-License-Identifier") 15 | 16 | root=$(git rev-parse --show-toplevel) 17 | 18 | # If we are inside mingw* environment, then we update the path to proper format 19 | if [[ $(uname) == MINGW* ]] ; then 20 | root=$(cygpath -u "${root}") 21 | fi 22 | 23 | ignore_res=() 24 | while IFS=$'\r' read -r i; do 25 | if [[ $i =~ ^# ]] || [[ -z $i ]]; then # ignore comments 26 | continue 27 | fi 28 | ignore_res+=("$i") 29 | done < "$root/scripts/.check-license.ignore" 30 | 31 | should_ignore() { 32 | for re in "${ignore_res[@]}"; do 33 | if [[ $1 =~ $re ]]; then 34 | return 35 | fi 36 | done 37 | false 38 | } 39 | 40 | # Create array of files to check, either from the given arguments or 41 | # all files in Git, ignore any that match a regex in the ignore file. 42 | files=() 43 | if [[ $# -ne 0 ]]; then 44 | for f in "$@"; do 45 | file=$(realpath "$f") 46 | 47 | if [[ ! -f $file ]]; then # skip non-existent files 48 | continue 49 | fi 50 | 51 | file=${file#$root/} # remove the prefix 52 | 53 | if should_ignore "$file"; then 54 | continue 55 | fi 56 | 57 | files+=("$file") 58 | done 59 | else 60 | # Find all files in Git. These are guaranteed to exist, to not be 61 | # generated, and to not have the prefix. 62 | cd "$root" 63 | while IFS= read -r -d '' file; do 64 | if should_ignore "$file"; then 65 | continue 66 | fi 67 | 68 | files+=("$file") 69 | done < <(git ls-files -z) 70 | fi 71 | 72 | failures=0 73 | for file in "${files[@]}"; do 74 | for line in "${license[@]}"; do 75 | # We check only the first four lines to avoid false positives 76 | # (such as this script), but to allow for a shebang and empty 77 | # line between it and the license. 78 | if ! head -n4 "${root}/${file}" | grep --quiet --fixed-strings --max-count=1 "${line}"; then 79 | echo "${file}" 80 | failures=$((failures + 1)) 81 | break 82 | fi 83 | done 84 | done 85 | 86 | exit $failures 87 | -------------------------------------------------------------------------------- /scripts/commit-msg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (c) Microsoft Corporation 4 | # SPDX-License-Identifier: MIT 5 | 6 | set -o errexit 7 | 8 | exit_() { 9 | echo "" 10 | echo "$1" 11 | echo "" 12 | echo "This hook can be skipped if needed with 'git commit --no-verify'" 13 | echo "See '.git/hooks/commit-msg., installed from 'scripts/commit-msg'" 14 | exit 1 15 | } 16 | 17 | sign_offs="$(grep '^Signed-off-by: ' "$1" || test $? = 1 )" 18 | 19 | if [[ -z $sign_offs ]]; then 20 | exit_ "Commit failed: please sign-off on the DCO with 'git commit -s'" 21 | fi 22 | 23 | if [[ -n $(echo "$sign_offs" | sort | uniq -c | sed -e '/^[ ]*1[ ]/d') ]]; then 24 | exit_ "Commit failed: please remove duplicate Signed-off-by lines" 25 | fi 26 | -------------------------------------------------------------------------------- /scripts/format-code: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (c) Microsoft Corporation. 4 | # SPDX-License-Identifier: MIT 5 | 6 | ##============================================================================== 7 | ## 8 | ## Echo if verbose flag (ignores quiet flag) 9 | ## 10 | ##============================================================================== 11 | log_verbose() 12 | { 13 | if [[ ${verbose} -eq 1 ]]; then 14 | echo "$1" 15 | fi 16 | } 17 | 18 | ##============================================================================== 19 | ## 20 | ## Echo if whatif flag is specified but not quiet flag 21 | ## 22 | ##============================================================================== 23 | log_whatif() 24 | { 25 | if [[ ${whatif} -eq 1 && ${quiet} -ne 1 ]]; then 26 | echo "$1" 27 | fi 28 | } 29 | 30 | ##============================================================================== 31 | ## 32 | ## Process command-line options: 33 | ## 34 | ##============================================================================== 35 | 36 | for opt in "$@" 37 | do 38 | case $opt in 39 | -h | --help) 40 | usage=1 41 | ;; 42 | 43 | -v | --verbose) 44 | verbose=1 45 | ;; 46 | 47 | -q | --quiet) 48 | quiet=1 49 | ;; 50 | 51 | -w | --whatif) 52 | whatif=1 53 | ;; 54 | 55 | -s | --staged) 56 | # Split into array 57 | mapfile -t userFiles <<< "$(git diff --cached --name-only --diff-filter=ACMR)" 58 | ;; 59 | 60 | --exclude-dirs=*) 61 | userExcludeDirs="${opt#*=}" 62 | ;; 63 | 64 | --include-exts=*) 65 | userIncludeExts="${opt#*=}" 66 | ;; 67 | 68 | --files=*) 69 | read -ra userFiles <<< "${opt#*=}" 70 | ;; 71 | *) 72 | echo "$0: unknown option: $opt" 73 | exit 1 74 | ;; 75 | esac 76 | done 77 | 78 | ##============================================================================== 79 | ## 80 | ## Display help 81 | ## 82 | ##============================================================================== 83 | 84 | if [[ ${usage} -eq 1 ]]; then 85 | cat< /dev/null) 164 | 165 | if [[ -x ${cf} ]]; then 166 | cf="clang-format-7" 167 | return 168 | else 169 | cf=$(command -v clang-format 2> /dev/null) 170 | if [[ ! -x ${cf} ]]; then 171 | echo "clang-format is not installed" 172 | exit 1 173 | fi 174 | cf="clang-format" 175 | fi 176 | 177 | local required_cfver='11.0.1' 178 | # shellcheck disable=SC2155 179 | local cfver=$(${cf} --version | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+' | head -1) 180 | check_version "${required_cfver}" "${cfver}" 181 | } 182 | 183 | check_clang-format 184 | 185 | ##============================================================================== 186 | ## 187 | ## Determine parameters for finding files to format 188 | ## 189 | ##============================================================================== 190 | 191 | findargs='find .' 192 | 193 | get_find_args() 194 | { 195 | local defaultExcludeDirs='./.git ./external ./packages ./x64' 196 | local defaultIncludeExts='h hpp c cpp idl acf' 197 | 198 | if [[ -z ${userExcludeDirs} ]]; then 199 | read -r -a excludeDirs <<< "${defaultExcludeDirs}" 200 | else 201 | log_verbose "Using user directory exclusions: ${userExcludeDirs}" 202 | read -r -a excludeDirs <<< "${userExcludeDirs}" 203 | fi 204 | 205 | for exc in "${excludeDirs[@]}" 206 | do 207 | findargs="${findargs} ! \( -path '${exc}' -prune \)" 208 | done 209 | 210 | if [[ -z ${userIncludeExts} ]]; then 211 | # not local as this is used in get_file_list() too 212 | read -r -a includeExts <<< "${defaultIncludeExts}" 213 | else 214 | log_verbose "Using user extension inclusions: ${userIncludeExts}" 215 | read -r -a includeExts <<< "${userIncludeExts}" 216 | fi 217 | 218 | findargs="${findargs} \(" 219 | for ((i=0; i<${#includeExts[@]}; i++)); 220 | do 221 | findargs="${findargs} -iname '*.${includeExts[$i]}'" 222 | if [[ $((i + 1)) -lt ${#includeExts[@]} ]]; then 223 | findargs="${findargs} -o" 224 | fi 225 | done 226 | findargs="${findargs} \)" 227 | } 228 | 229 | get_find_args 230 | 231 | log_verbose "Query for files for format:" 232 | log_verbose "${findargs}" 233 | log_verbose "" 234 | 235 | ##============================================================================== 236 | ## 237 | ## Call clang-format for each file to be formatted 238 | ## 239 | ##============================================================================== 240 | 241 | filecount=0 242 | changecount=0 243 | 244 | cfargs="${cf} -style=file" 245 | if [[ ${whatif} -ne 1 ]]; then 246 | cfargs="${cfargs} -i" 247 | fi 248 | 249 | get_file_list() 250 | { 251 | if [[ -z "${userFiles[*]}" ]]; then 252 | mapfile -t file_list < <(eval "$findargs") 253 | if [[ ${#file_list[@]} -eq 0 ]]; then 254 | echo "No files were found to format!" 255 | exit 1 256 | fi 257 | else 258 | log_verbose "Using user files: ${userFiles[*]}" 259 | file_list=() 260 | for file in "${userFiles[@]}"; do 261 | for ext in "${includeExts[@]}"; do 262 | if [[ ${file##*\.} == "$ext" ]]; then 263 | file_list+=( "$file" ) 264 | log_verbose "Checking user file: ${file}" 265 | break 266 | fi 267 | done 268 | done 269 | fi 270 | } 271 | 272 | get_file_list 273 | 274 | for file in "${file_list[@]}" 275 | do 276 | ((filecount+=1)) 277 | cf="${cfargs} $file" 278 | 279 | log_whatif "Formatting $file ..." 280 | 281 | if [[ ${whatif} -eq 1 ]]; then 282 | ${cf} | diff -u "$file" - 283 | else 284 | if [[ ${verbose} -eq 1 ]]; then 285 | ${cf} 286 | else 287 | ${cf} > /dev/null 288 | fi 289 | fi 290 | 291 | #shellcheck disable=SC2181 292 | if [[ $? -ne 0 ]]; then 293 | if [[ ${whatif} -eq 1 ]]; then 294 | ((changecount+=1)) 295 | else 296 | echo "clang-format failed on file: $file." 297 | fi 298 | fi 299 | done 300 | 301 | log_whatif "${filecount} files processed, ${changecount} changed." 302 | 303 | # If files are being edited, this count is zero so we exit with success. 304 | exit "$changecount" 305 | -------------------------------------------------------------------------------- /scripts/format-code.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | $usage=$false; 5 | $quiet=$false; 6 | $verbose=$false; 7 | $whatif=$false; 8 | [System.Collections.ArrayList]$userExcludeDirs=@(); 9 | [System.Collections.ArrayList]$userIncludeExts=@(); 10 | [System.Collections.ArrayList]$excludeDirs=@(); 11 | [System.Collections.ArrayList]$includeExts=@(); 12 | [System.Collections.ArrayList]$userFiles=@(); 13 | 14 | 15 | ##============================================================================== 16 | ## 17 | ## Echo if verbose flag (ignores quiet flag) 18 | ## 19 | ##============================================================================== 20 | function log_verbose() 21 | { 22 | if ($verbose) { 23 | Write-Host "$args" 24 | } 25 | } 26 | 27 | ##============================================================================== 28 | ## 29 | ## Echo if whatif flag is specified but not quiet flag 30 | ## 31 | ##============================================================================== 32 | function log_whatif() 33 | { 34 | if ( $whatif -and -not $quiet) 35 | { 36 | Write-Host "$args" 37 | } 38 | } 39 | 40 | ##============================================================================== 41 | ## 42 | ## Process command-line options 43 | ## 44 | ## Note that in Powershell syntax, fallthrough does not work as such, 45 | ## instead one must compare against multiple values. For a discussion, see 46 | ## https://stackoverflow.com/questions/3493731/whats-the-powershell-syntax-for-multiple-values-in-a-switch-statement 47 | ## 48 | ##============================================================================== 49 | 50 | foreach ($opt in $args) 51 | { 52 | switch -regex ($opt) { 53 | 54 | { @("-h", "--help") -contains $_ } 55 | { 56 | $usage=$true; 57 | break; 58 | } 59 | 60 | { @("-q", "--quiet") -contains $_ } 61 | { 62 | $quiet=$true; 63 | break; 64 | } 65 | 66 | { @("-s", "--staged") -contains $_ } 67 | { 68 | $userFiles=@(git diff --cached --name-only --diff-filter=ACMR); 69 | break; 70 | } 71 | 72 | { @("-v", "--verbose") -contains $_ } 73 | { 74 | $verbose=$true; 75 | break; 76 | } 77 | 78 | { @("-w", "--whatif") -contains $_ } 79 | { 80 | $whatif=$true; 81 | break; 82 | } 83 | 84 | "--exclude-dirs=*" { 85 | $userExcludeDirs=($opt -split "=")[1]; 86 | break; 87 | } 88 | 89 | "--include-exts=*" { 90 | $userIncludeExts=($opt -split "=")[1]; 91 | break; 92 | } 93 | 94 | "--files=*" { 95 | $userFiles=($opt -split "=")[1]; 96 | break; 97 | } 98 | default { 99 | Write-Error "$PSCommandPath unknown option: $opt" 100 | exit 1 101 | break; 102 | } 103 | } 104 | } 105 | 106 | ##============================================================================== 107 | ## 108 | ## Display help 109 | ## 110 | ##============================================================================== 111 | 112 | if ( $usage ) { 113 | $usageMessage = @' 114 | 115 | OVERVIEW: 116 | 117 | Formats all C/C++ source files based on the .clang-format rules 118 | 119 | $ format-code [-h] [-q] [-s] [-v] [-w] [--exclude-dirs="..."] [--include-exts="..."] [--files="..."] 120 | 121 | OPTIONS: 122 | -h, --help Print this help message. 123 | -q, --quiet Display only clang-format output and errors. 124 | -s, --staged Only format files which are staged to be committed. 125 | -v, --verbose Display verbose output. 126 | -w, --whatif Run the script without actually modifying the files 127 | and display the diff of expected changes, if any. 128 | --exclude-dirs Subdirectories to exclude. If unspecified, then 129 | ./external, ./packages and ./x64 are excluded. 130 | All subdirectories are relative to the current path. 131 | --include-exts File extensions to include for formatting. If 132 | unspecified, then *.h, *.hpp, *.c, *.cpp, *idl, and 133 | *.acf are included. 134 | --files Only run the script against the specified files from 135 | the current directory. 136 | 137 | EXAMPLES: 138 | 139 | To determine what lines of each file in the default configuration would be 140 | modified by format-code, you can run from the root folder: 141 | 142 | $ ./scripts/format-code -w 143 | 144 | To update only all .c and .cpp files in src/ except for src/tools/netsh, you 145 | can run from the src folder: 146 | 147 | src$ ../scripts/format-code --exclude-dirs="tools/netsh" \ 148 | --include-exts="c cpp" 149 | 150 | To run only against a specified set of comma separated files in the current directory: 151 | 152 | $ ./scripts/format-code -w --files="file1 file2" 153 | 154 | '@ 155 | Write-Host "$usageMessage" 156 | exit 0 157 | } 158 | 159 | ##============================================================================== 160 | ## 161 | ## Determine parameters for finding files to format 162 | ## 163 | ##============================================================================== 164 | function get_find_args() 165 | { 166 | $defaultExcludeDirs=@( ".git", "external", "packages", "x64" ); 167 | $defaultIncludeExts=@( "h", "hpp", "c", "cpp", "idl", "acf" ) 168 | 169 | $findargs='get-childitem -Recurse -Name "*" -Path "." ' 170 | if ( !($userIncludeExts) ) { 171 | # not local as this is used in get_file_list() too 172 | $includeExts.AddRange($defaultIncludeExts) 173 | } 174 | else 175 | { 176 | log_verbose "Using user extension inclusions: $userIncludeExts" 177 | $includeExts.AddRange($userIncludeExts) 178 | } 179 | 180 | $findargs+=" -Include @( " 181 | foreach ($ext in $includeExts) 182 | { 183 | $findargs+=("'*."+"$ext'") 184 | if ($includeExts.IndexOf($ext) -lt $includeExts.count-1) 185 | { 186 | $findargs+=", " 187 | } 188 | } 189 | $findargs+=") " 190 | 191 | if ( !($userExcludeDirs) ) { 192 | $excludeDirs.AddRange($defaultExcludeDirs) 193 | } 194 | else { 195 | log_verbose "Using user directory exclusions: $userExcludeDirs" 196 | $excludeDirs.AddRange($userExcludeDirs) 197 | } 198 | 199 | $findargs+=" | where { " 200 | foreach ($dir in $excludeDirs) 201 | { 202 | $findargs+='$_ -notlike ' 203 | $findargs+= "'$dir"+"\*'" 204 | if ($excludeDirs.IndexOf($dir) -lt $excludeDirs.count-1) 205 | { 206 | $findargs+=" -and " 207 | } 208 | } 209 | $findargs+="} " 210 | 211 | return $findargs 212 | } 213 | 214 | function get_file_list() 215 | { 216 | if ( !($userFiles) ) { 217 | $file_list = Invoke-Expression($findargs) 218 | if ( $file_list.count -eq 0 ) { 219 | Write-Host "No files were found to format!" 220 | exit 1 221 | } 222 | } 223 | else { 224 | log_verbose "Using user files: $userfiles" 225 | $file_list=@() 226 | foreach ( $file_name in $userfiles ) { 227 | $user_file_name = get-ChildItem -Path '.' -Name $file_name 228 | $file = New-Object System.IO.FileInfo($user_file_name) 229 | foreach ( $ext in $includeExts ) { 230 | if ( $file.Extension -eq ".$ext" ) { 231 | $file_list += $file_name 232 | log_verbose "Checking user file: $file_name" 233 | break; 234 | } 235 | } 236 | } 237 | } 238 | return $file_list 239 | } 240 | 241 | $global:cf="" 242 | 243 | ##============================================================================== 244 | ## 245 | ## Check for installed clang-format tool 246 | ## 247 | ##============================================================================== 248 | function check_clang-format() 249 | { 250 | # Windows does not have a clang-format-7 executable 251 | 252 | 253 | $required_cfver='11.0.1' 254 | 255 | try { 256 | $cfver=(( Invoke-Expression "clang-format --version" 2> $null ) -split " ")[2] 257 | } 258 | catch { 259 | Write-Host "clang-format not installed" 260 | return $false 261 | } 262 | 263 | $req_ver = $required_cfver -split '.' 264 | $cf_ver = $cfver -split '.' 265 | 266 | for ($i = 0; $i -lt 3; $i++) 267 | { 268 | if ( $cf_ver[$i] -gt $req_ver[$i]) 269 | { 270 | return $true 271 | } 272 | 273 | if ( $cf_ver[$i] -lt $req_ver[$i]) 274 | { 275 | Write-Host "Required version of clang-format is $required_cfver. Current version is $cfver" 276 | return $false 277 | } 278 | # Equal just keeps going 279 | } 280 | $global:cf="clang-format" 281 | return $true 282 | } 283 | 284 | 285 | ##============================================================================== 286 | ## 287 | ## Mainline: Call clang-format for each file to be formatted 288 | ## 289 | ##============================================================================== 290 | 291 | if (!(check_clang-format)) # getting the filelist takes a few seconds. If we cant format we may as well exit now. 292 | { 293 | exit -1 294 | } 295 | 296 | $findargs = get_find_args; 297 | $filelist = get_file_list; 298 | $filecount=0 299 | $changecount=0 300 | 301 | $cfargs="$global:cf -style=file" 302 | if ( !$whatif ) { 303 | $cfargs="$cfargs -i" 304 | } 305 | 306 | foreach ( $file in $filelist ) { 307 | $filecount+=1; 308 | $cf="$cfargs $file" 309 | 310 | 311 | if ( $whatif ) { 312 | log_whatif "Formatting $file ..." 313 | ( Invoke-Expression ($cf) ) | Compare-Object (get-content $file) 314 | } 315 | else { 316 | if ( $verbose ) { 317 | log_verbose "Formatting $file ..." 318 | Invoke-Expression $cf 319 | } 320 | else { 321 | Invoke-Expression $cf > $null 322 | } 323 | } 324 | if ( $? ) { 325 | if ( $whatif ) { 326 | $changecount++ 327 | } 328 | } 329 | else { 330 | Write-Host "clang-format failed on file: $file." 331 | } 332 | } 333 | 334 | log_whatif "$filecount files processed, $changecount changed." 335 | 336 | # If files are being edited, this count is zero so we exit with success. 337 | exit $changecount 338 | -------------------------------------------------------------------------------- /scripts/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright (c) Microsoft Corporation 4 | # SPDX-License-Identifier: MIT 5 | 6 | set -o errexit 7 | 8 | exit_() { 9 | echo "" 10 | echo "$1" 11 | echo "" 12 | echo "This hook can be skipped if needed with 'git commit --no-verify'" 13 | echo "See '.git/hooks/pre-commit', installed from 'scripts/pre-commit'" 14 | exit 1 15 | } 16 | 17 | if [[ $(git config --get user.name | wc -w) -lt 2 ]]; then 18 | # This heuristic avoids bad user names such as "root" or "Ubuntu" 19 | # or a computer login name. A full name should (usually) have at 20 | # least two words. We can change this if needed later. 21 | exit_ "Commit failed: please fix your Git user name (see docs/Contributing.md)" 22 | fi 23 | 24 | if ! git diff-index --check --cached HEAD --; then 25 | exit_ "Commit failed: please fix the conflict markers or whitespace errors" 26 | fi 27 | 28 | mapfile -t files < <(git diff --cached --name-only --diff-filter=ACMR) 29 | 30 | if [[ ${#files[@]} -eq 0 ]]; then 31 | # When 'git commit --amend' is used, the files list is empty. The 32 | # scripts below interpret an empty file set as a directive to 33 | # check all the files, which is slow (but used in CI). So in this 34 | # Git hook, we just skip the following checks instead. 35 | exit 0 36 | fi 37 | 38 | scripts=$(git rev-parse --show-toplevel)/scripts 39 | 40 | if ! "$scripts/format-code" --quiet --whatif --files="${files[*]}"; then 41 | exit_ "Commit failed: to fix the formatting please run './scripts/format-code --staged' in bash or '.\\scripts\\format-code.ps1 --staged' in powershell" 42 | fi 43 | if ! "$scripts/check-license.sh" "${files[@]}"; then 44 | exit_ "Commit failed: please add license headers to the above files" 45 | fi 46 | -------------------------------------------------------------------------------- /src/boost_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // SPDX-License-Identifier: MIT 3 | 4 | #include 5 | #if BOOST_VERSION < 108800 6 | #include 7 | #else 8 | #define BOOST_PROCESS_VERSION 1 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #endif 16 | -------------------------------------------------------------------------------- /src/bpf_assembler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // SPDX-License-Identifier: MIT 3 | 4 | #pragma once 5 | #include 6 | #include 7 | #include 8 | #include "ebpf.h" 9 | 10 | /** 11 | * @brief Accept an input stream containing BPF instructions and return a vector of ebpf_inst. 12 | * 13 | * @param[in] input Input stream containing BPF instructions to assemble. 14 | * @return Vector of ebpf_inst 15 | */ 16 | std::vector 17 | bpf_assembler(std::istream& input); 18 | -------------------------------------------------------------------------------- /src/bpf_test_parser.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // SPDX-License-Identifier: MIT 3 | 4 | #include "bpf_test_parser.h" 5 | #include 6 | #include 7 | #include 8 | 9 | #include "bpf_assembler.h" 10 | 11 | std::tuple, uint64_t, std::string, std::vector> 12 | parse_test_file(const std::filesystem::path& data_file) 13 | { 14 | enum class _state 15 | { 16 | state_ignore, 17 | state_assembly, 18 | state_raw, 19 | state_result, 20 | state_memory, 21 | state_error, 22 | } state = _state::state_ignore; 23 | 24 | std::stringstream data_out; 25 | std::ifstream data_in(data_file); 26 | 27 | std::string result_string; 28 | std::string mem; 29 | std::string line; 30 | std::string expected_error; 31 | std::string raw; 32 | 33 | while (std::getline(data_in, line)) { 34 | // Strip trailing carriage return 35 | if (!line.empty() && line.back() == '\r') { 36 | line.pop_back(); 37 | } 38 | if (line.find("#") != std::string::npos) { 39 | line = line.substr(0, line.find("#")); 40 | } 41 | if (line.find("--") != std::string::npos) { 42 | if (line.find("asm") != std::string::npos) { 43 | state = _state::state_assembly; 44 | continue; 45 | } else if (line.find("result") != std::string::npos) { 46 | state = _state::state_result; 47 | continue; 48 | } else if (line.find("mem") != std::string::npos) { 49 | state = _state::state_memory; 50 | continue; 51 | } else if (line.find("raw") != std::string::npos) { 52 | state = _state::state_raw; 53 | continue; 54 | } else if (line.find("result") != std::string::npos) { 55 | state = _state::state_result; 56 | continue; 57 | } else if (line.find("no register offset") != std::string::npos) { 58 | state = _state::state_ignore; 59 | continue; 60 | } else if (line.find(" c") != std::string::npos) { 61 | state = _state::state_ignore; 62 | continue; 63 | } else if (line.find("error") != std::string::npos) { 64 | state = _state::state_error; 65 | continue; 66 | } else { 67 | std::cout << "Skipping: Unknown directive " << line << " in file " << data_file << std::endl; 68 | return {}; 69 | continue; 70 | } 71 | } 72 | if (line.empty()) { 73 | continue; 74 | } 75 | 76 | switch (state) { 77 | case _state::state_assembly: 78 | data_out << line << std::endl; 79 | break; 80 | case _state::state_result: 81 | result_string = line; 82 | break; 83 | case _state::state_memory: 84 | mem += std::string(" ") + line; 85 | break; 86 | case _state::state_error: 87 | expected_error = line; 88 | break; 89 | case _state::state_raw: 90 | raw += std::string(" ") + line; 91 | break; 92 | default: 93 | continue; 94 | } 95 | } 96 | 97 | if (expected_error.empty() && result_string.empty()) { 98 | std::cout << "Skipping: No result or error in test file " << data_file << std::endl; 99 | return {}; 100 | } 101 | 102 | uint64_t result_value; 103 | if (result_string.empty()) { 104 | result_value = 0; 105 | } else if (result_string.find("0x") != std::string::npos) { 106 | result_value = std::stoull(result_string, nullptr, 16); 107 | } else { 108 | result_value = std::stoull(result_string); 109 | } 110 | 111 | std::vector instructions; 112 | if (!raw.empty()) { 113 | std::stringstream raw_stream(raw); 114 | 115 | std::string byte; 116 | while (raw_stream >> line) { 117 | uint64_t value; 118 | ebpf_inst inst; 119 | if (line.starts_with("0x")) { 120 | value = std::stoull(line, nullptr, 16); 121 | } else { 122 | value = std::stoull(line); 123 | } 124 | *reinterpret_cast(&inst) = value; 125 | instructions.push_back(inst); 126 | } 127 | } else { 128 | data_out.seekg(0); 129 | instructions = bpf_assembler(data_out); 130 | } 131 | 132 | if (instructions.empty()) { 133 | std::cout << "Skipping: No instructions in test file " << data_file << std::endl; 134 | return {}; 135 | } 136 | 137 | std::vector input_buffer; 138 | 139 | if (!mem.empty()) { 140 | std::stringstream ss(mem); 141 | uint32_t value; 142 | while (ss >> std::hex >> value) { 143 | input_buffer.push_back(static_cast(value)); 144 | } 145 | } 146 | 147 | return {input_buffer, result_value, expected_error, instructions}; 148 | } 149 | -------------------------------------------------------------------------------- /src/bpf_test_parser.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // SPDX-License-Identifier: MIT 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "ebpf.h" 11 | 12 | /** 13 | * @brief Parse a test file and return the memory, the expected return value, the expected error string, and the BPF 14 | * byte code. 15 | * 16 | * @param[in] data_file Path to the test file. 17 | * @return Tuple of input memory, expected return value, the expected error string, and the BPF byte code sequence. 18 | */ 19 | std::tuple, uint64_t, std::string, std::vector> 20 | parse_test_file(const std::filesystem::path& data_file); 21 | -------------------------------------------------------------------------------- /src/bpf_writer.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // SPDX-License-Identifier: MIT 3 | 4 | #include 5 | 6 | #include "bpf_writer.h" 7 | 8 | const std::string symbol_section_name = ".symtab"; 9 | // https://github.com/Alan-Jowett/bpf_conformance/issues/82 10 | // Add support for the new BTF based .maps section. 11 | const std::string maps_section_name = "maps"; 12 | const std::string relocation_prefix = ".rel"; 13 | 14 | void 15 | bpf_writer_classic( 16 | std::ostream& output, 17 | const std::string& section_name, 18 | const std::string& function_name, 19 | const std::vector& instructions, 20 | const std::vector>& maps, 21 | const std::map& map_relocations) 22 | { 23 | ELFIO::elfio writer; 24 | writer.create(ELFIO::ELFCLASS64, ELFIO::ELFDATA2LSB); 25 | 26 | writer.set_type(ELFIO::ET_REL); 27 | writer.set_machine(ELFIO::EM_BPF); 28 | 29 | auto symbols_section = writer.sections.add(symbol_section_name); 30 | symbols_section->set_type(ELFIO::SHT_SYMTAB); 31 | symbols_section->set_flags(0); 32 | symbols_section->set_addr_align(4); 33 | symbols_section->set_info(1); 34 | symbols_section->set_entry_size(writer.get_default_entry_size(ELFIO::SHT_SYMTAB)); 35 | symbols_section->set_link(writer.get_section_name_str_index()); 36 | 37 | auto text_section = writer.sections.add(section_name); 38 | text_section->set_type(ELFIO::SHT_PROGBITS); 39 | text_section->set_flags(ELFIO::SHF_EXECINSTR | ELFIO::SHF_ALLOC); 40 | text_section->set_addr_align(4); 41 | text_section->append_data( 42 | reinterpret_cast(instructions.data()), 43 | static_cast(instructions.size() * sizeof(ebpf_inst_t))); 44 | 45 | auto string_accessor = ELFIO::string_section_accessor(writer.sections[writer.get_section_name_str_index()]); 46 | auto symbol_accessor = ELFIO::symbol_section_accessor(writer, symbols_section); 47 | 48 | symbol_accessor.add_symbol( 49 | string_accessor, 50 | function_name.c_str(), 51 | text_section->get_address(), 52 | text_section->get_size(), 53 | ELFIO::STB_GLOBAL, 54 | ELFIO::STT_FUNC, 55 | 0, 56 | text_section->get_index()); 57 | 58 | if (maps.size() > 0) { 59 | auto relocation_section = writer.sections.add(relocation_prefix + section_name); 60 | auto maps_section = writer.sections.add(maps_section_name); 61 | maps_section->set_type(ELFIO::SHT_PROGBITS); 62 | maps_section->set_flags(ELFIO::SHF_WRITE | ELFIO::SHF_ALLOC); 63 | maps_section->set_addr_align(4); 64 | for (const auto& map : maps) { 65 | maps_section->append_data( 66 | reinterpret_cast(&std::get<1>(map)), sizeof(ebpf_map_definition_in_file_t)); 67 | } 68 | 69 | relocation_section->set_type(ELFIO::SHT_REL); 70 | relocation_section->set_flags(0); 71 | relocation_section->set_addr_align(8); 72 | relocation_section->set_info(text_section->get_index()); 73 | relocation_section->set_link(symbols_section->get_index()); 74 | relocation_section->set_entry_size(writer.get_default_entry_size(ELFIO::SHT_REL)); 75 | 76 | auto relocation_accessor = ELFIO::relocation_section_accessor(writer, relocation_section); 77 | 78 | for (const auto& relocation : map_relocations) { 79 | auto map_entry = std::find_if( 80 | maps.begin(), maps.end(), [&](const auto& map) { return std::get<0>(map) == relocation.second; }); 81 | if (map_entry == maps.end()) { 82 | throw std::runtime_error("Map not found"); 83 | } 84 | size_t map_offset = std::distance(maps.begin(), map_entry) * sizeof(ebpf_map_definition_in_file_t); 85 | relocation_accessor.add_entry( 86 | string_accessor, 87 | relocation.second.c_str(), 88 | symbol_accessor, 89 | map_offset, 90 | sizeof(ebpf_map_definition_in_file_t), 91 | ELFIO::STB_GLOBAL << 4 | ELFIO::STT_OBJECT, 92 | 0, 93 | maps_section->get_index(), 94 | relocation.first * sizeof(ebpf_inst_t), 95 | ELFIO::R_X86_64_64); 96 | } 97 | } 98 | 99 | writer.save(output); 100 | } 101 | -------------------------------------------------------------------------------- /src/bpf_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation 2 | // SPDX-License-Identifier: MIT 3 | 4 | #pragma once 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "ebpf.h" 11 | 12 | /** 13 | * @brief Write a BPF program to an ELF file, using the classic ELF format for maps. 14 | * 15 | * @param[out] output Stream to write the ELF file to. 16 | * @param[in] instructions BPF instructions to write. 17 | * @param[in] maps BPF maps to write. 18 | * @param[in] map_relocations Map of map names to their relocations. 19 | */ 20 | void 21 | bpf_writer_classic( 22 | std::ostream& output, 23 | const std::string& section_name, 24 | const std::string& function_name, 25 | const std::vector& instructions, 26 | const std::vector>& maps, 27 | const std::map& map_relocations); 28 | -------------------------------------------------------------------------------- /src/ebpf.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Big Switch Networks, Inc 2 | // SPDX-License-Identifier: Apache-2.0 3 | 4 | /* 5 | * Copyright 2015 Big Switch Networks, Inc 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | #ifndef EBPF_H 21 | #define EBPF_H 22 | 23 | #include 24 | 25 | /* eBPF definitions */ 26 | 27 | typedef struct ebpf_inst 28 | { 29 | uint8_t opcode; 30 | uint8_t dst : 4; 31 | uint8_t src : 4; 32 | int16_t offset; 33 | int32_t imm; 34 | } ebpf_inst_t; 35 | 36 | #define EBPF_CLS_MASK 0x07 37 | #define EBPF_ALU_OP_MASK 0xf0 38 | #define EBPF_JMP_OP_MASK 0xf0 39 | 40 | #define EBPF_CLS_LD 0x00 41 | #define EBPF_CLS_LDX 0x01 42 | #define EBPF_CLS_ST 0x02 43 | #define EBPF_CLS_STX 0x03 44 | #define EBPF_CLS_ALU 0x04 45 | #define EBPF_CLS_JMP 0x05 46 | #define EBPF_CLS_JMP32 0x06 47 | #define EBPF_CLS_ALU64 0x07 48 | 49 | #define EBPF_SRC_IMM 0x00 50 | #define EBPF_SRC_REG 0x08 51 | 52 | #define EBPF_SIZE_W 0x00 53 | #define EBPF_SIZE_H 0x08 54 | #define EBPF_SIZE_B 0x10 55 | #define EBPF_SIZE_DW 0x18 56 | 57 | /** 58 | * @brief Atomic modifier for EBPF_CLS_STX operation. 59 | */ 60 | #define EBPF_MODE_ATOMIC 0xc0 61 | 62 | #define EBPF_ATOMIC_OP_FETCH 0x01 63 | #define EPBF_ATOMIC_OP_XCHG (0xe0 | EBPF_ATOMIC_OP_FETCH) 64 | #define EBPF_ATOMIC_OP_CMPXCHG (0xf0 | EBPF_ATOMIC_OP_FETCH) 65 | 66 | /* Other memory modes are not yet supported */ 67 | #define EBPF_MODE_IMM 0x00 68 | #define EBPF_MODE_MEM 0x60 69 | 70 | #define EBPF_ALU_OP_ADD 0x00 71 | #define EBPF_ALU_OP_SUB 0x10 72 | #define EBPF_ALU_OP_MUL 0x20 73 | #define EBPF_ALU_OP_DIV 0x30 74 | #define EBPF_ALU_OP_OR 0x40 75 | #define EBPF_ALU_OP_AND 0x50 76 | #define EBPF_ALU_OP_LSH 0x60 77 | #define EBPF_ALU_OP_RSH 0x70 78 | #define EBPF_ALU_OP_NEG 0x80 79 | #define EBPF_ALU_OP_MOD 0x90 80 | #define EBPF_ALU_OP_XOR 0xa0 81 | #define EBPF_ALU_OP_MOV 0xb0 82 | #define EBPF_ALU_OP_ARSH 0xc0 83 | #define EBPF_ALU_OP_END 0xd0 84 | 85 | #define EBPF_OP_ADD_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_ADD) 86 | #define EBPF_OP_ADD_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_ADD) 87 | #define EBPF_OP_SUB_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_SUB) 88 | #define EBPF_OP_SUB_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_SUB) 89 | #define EBPF_OP_MUL_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_MUL) 90 | #define EBPF_OP_MUL_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_MUL) 91 | #define EBPF_OP_DIV_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_DIV) 92 | #define EBPF_OP_DIV_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_DIV) 93 | #define EBPF_OP_OR_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_OR) 94 | #define EBPF_OP_OR_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_OR) 95 | #define EBPF_OP_AND_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_AND) 96 | #define EBPF_OP_AND_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_AND) 97 | #define EBPF_OP_LSH_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_LSH) 98 | #define EBPF_OP_LSH_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_LSH) 99 | #define EBPF_OP_RSH_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_RSH) 100 | #define EBPF_OP_RSH_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_RSH) 101 | #define EBPF_OP_NEG (EBPF_CLS_ALU | EBPF_ALU_OP_NEG) 102 | #define EBPF_OP_MOD_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_MOD) 103 | #define EBPF_OP_MOD_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_MOD) 104 | #define EBPF_OP_XOR_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_XOR) 105 | #define EBPF_OP_XOR_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_XOR) 106 | #define EBPF_OP_MOV_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_MOV) 107 | #define EBPF_OP_MOV_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_MOV) 108 | #define EBPF_OP_ARSH_IMM (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_ARSH) 109 | #define EBPF_OP_ARSH_REG (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_ARSH) 110 | #define EBPF_OP_LE (EBPF_CLS_ALU | EBPF_SRC_IMM | EBPF_ALU_OP_END) 111 | #define EBPF_OP_BE (EBPF_CLS_ALU | EBPF_SRC_REG | EBPF_ALU_OP_END) 112 | 113 | #define EBPF_OP_ADD64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_ADD) 114 | #define EBPF_OP_ADD64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_ADD) 115 | #define EBPF_OP_SUB64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_SUB) 116 | #define EBPF_OP_SUB64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_SUB) 117 | #define EBPF_OP_MUL64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_MUL) 118 | #define EBPF_OP_MUL64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_MUL) 119 | #define EBPF_OP_DIV64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_DIV) 120 | #define EBPF_OP_DIV64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_DIV) 121 | #define EBPF_OP_OR64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_OR) 122 | #define EBPF_OP_OR64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_OR) 123 | #define EBPF_OP_AND64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_AND) 124 | #define EBPF_OP_AND64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_AND) 125 | #define EBPF_OP_LSH64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_LSH) 126 | #define EBPF_OP_LSH64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_LSH) 127 | #define EBPF_OP_RSH64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_RSH) 128 | #define EBPF_OP_RSH64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_RSH) 129 | #define EBPF_OP_NEG64 (EBPF_CLS_ALU64 | EBPF_ALU_OP_NEG) 130 | #define EBPF_OP_MOD64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_MOD) 131 | #define EBPF_OP_MOD64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_MOD) 132 | #define EBPF_OP_XOR64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_XOR) 133 | #define EBPF_OP_XOR64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_XOR) 134 | #define EBPF_OP_MOV64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_MOV) 135 | #define EBPF_OP_MOV64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_MOV) 136 | #define EBPF_OP_ARSH64_IMM (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_ARSH) 137 | #define EBPF_OP_ARSH64_REG (EBPF_CLS_ALU64 | EBPF_SRC_REG | EBPF_ALU_OP_ARSH) 138 | #define EBPF_OP_SWAP (EBPF_CLS_ALU64 | EBPF_SRC_IMM | EBPF_ALU_OP_END) 139 | 140 | #define EBPF_OP_LDXW (EBPF_CLS_LDX | EBPF_MODE_MEM | EBPF_SIZE_W) 141 | #define EBPF_OP_LDXH (EBPF_CLS_LDX | EBPF_MODE_MEM | EBPF_SIZE_H) 142 | #define EBPF_OP_LDXB (EBPF_CLS_LDX | EBPF_MODE_MEM | EBPF_SIZE_B) 143 | #define EBPF_OP_LDXDW (EBPF_CLS_LDX | EBPF_MODE_MEM | EBPF_SIZE_DW) 144 | #define EBPF_OP_STW (EBPF_CLS_ST | EBPF_MODE_MEM | EBPF_SIZE_W) 145 | #define EBPF_OP_STH (EBPF_CLS_ST | EBPF_MODE_MEM | EBPF_SIZE_H) 146 | #define EBPF_OP_STB (EBPF_CLS_ST | EBPF_MODE_MEM | EBPF_SIZE_B) 147 | #define EBPF_OP_STDW (EBPF_CLS_ST | EBPF_MODE_MEM | EBPF_SIZE_DW) 148 | #define EBPF_OP_STXW (EBPF_CLS_STX | EBPF_MODE_MEM | EBPF_SIZE_W) 149 | #define EBPF_OP_STXH (EBPF_CLS_STX | EBPF_MODE_MEM | EBPF_SIZE_H) 150 | #define EBPF_OP_STXB (EBPF_CLS_STX | EBPF_MODE_MEM | EBPF_SIZE_B) 151 | #define EBPF_OP_STXDW (EBPF_CLS_STX | EBPF_MODE_MEM | EBPF_SIZE_DW) 152 | #define EBPF_OP_LDDW (EBPF_CLS_LD | EBPF_MODE_IMM | EBPF_SIZE_DW) 153 | 154 | #define EBPF_MODE_JA 0x00 155 | #define EBPF_MODE_JEQ 0x10 156 | #define EBPF_MODE_JGT 0x20 157 | #define EBPF_MODE_JGE 0x30 158 | #define EBPF_MODE_JSET 0x40 159 | #define EBPF_MODE_JNE 0x50 160 | #define EBPF_MODE_JSGT 0x60 161 | #define EBPF_MODE_JSGE 0x70 162 | #define EBPF_MODE_CALL 0x80 163 | #define EBPF_MODE_EXIT 0x90 164 | #define EBPF_MODE_JLT 0xa0 165 | #define EBPF_MODE_JLE 0xb0 166 | #define EBPF_MODE_JSLT 0xc0 167 | #define EBPF_MODE_JSLE 0xd0 168 | 169 | #define EBPF_OP_JA (EBPF_CLS_JMP | EBPF_MODE_JA) 170 | #define EBPF_OP_JA32 (EBPF_CLS_JMP32 | EBPF_MODE_JA) 171 | #define EBPF_OP_JEQ_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JEQ) 172 | #define EBPF_OP_JEQ_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JEQ) 173 | #define EBPF_OP_JGT_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JGT) 174 | #define EBPF_OP_JGT_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JGT) 175 | #define EBPF_OP_JGE_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JGE) 176 | #define EBPF_OP_JGE_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JGE) 177 | #define EBPF_OP_JSET_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JSET) 178 | #define EBPF_OP_JSET_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JSET) 179 | #define EBPF_OP_JNE_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JNE) 180 | #define EBPF_OP_JNE_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JNE) 181 | #define EBPF_OP_JSGT_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JSGT) 182 | #define EBPF_OP_JSGT_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JSGT) 183 | #define EBPF_OP_JSGE_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JSGE) 184 | #define EBPF_OP_JSGE_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JSGE) 185 | #define EBPF_OP_CALL (EBPF_CLS_JMP | EBPF_MODE_CALL) 186 | #define EBPF_OP_EXIT (EBPF_CLS_JMP | EBPF_MODE_EXIT) 187 | #define EBPF_OP_JLT_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JLT) 188 | #define EBPF_OP_JLT_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JLT) 189 | #define EBPF_OP_JLE_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JLE) 190 | #define EBPF_OP_JLE_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JLE) 191 | #define EBPF_OP_JSLT_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JSLT) 192 | #define EBPF_OP_JSLT_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JSLT) 193 | #define EBPF_OP_JSLE_IMM (EBPF_CLS_JMP | EBPF_SRC_IMM | EBPF_MODE_JSLE) 194 | #define EBPF_OP_JSLE_REG (EBPF_CLS_JMP | EBPF_SRC_REG | EBPF_MODE_JSLE) 195 | 196 | #define EBPF_OP_JEQ32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JEQ) 197 | #define EBPF_OP_JEQ32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JEQ) 198 | #define EBPF_OP_JGT32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JGT) 199 | #define EBPF_OP_JGT32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JGT) 200 | #define EBPF_OP_JGE32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JGE) 201 | #define EBPF_OP_JGE32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JGE) 202 | #define EBPF_OP_JSET32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JSET) 203 | #define EBPF_OP_JSET32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JSET) 204 | #define EBPF_OP_JNE32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JNE) 205 | #define EBPF_OP_JNE32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JNE) 206 | #define EBPF_OP_JSGT32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JSGT) 207 | #define EBPF_OP_JSGT32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JSGT) 208 | #define EBPF_OP_JSGE32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JSGE) 209 | #define EBPF_OP_JSGE32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JSGE) 210 | #define EBPF_OP_JLT32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JLT) 211 | #define EBPF_OP_JLT32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JLT) 212 | #define EBPF_OP_JLE32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JLE) 213 | #define EBPF_OP_JLE32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JLE) 214 | #define EBPF_OP_JSLT32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JSLT) 215 | #define EBPF_OP_JSLT32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JSLT) 216 | #define EBPF_OP_JSLE32_IMM (EBPF_CLS_JMP32 | EBPF_SRC_IMM | EBPF_MODE_JSLE) 217 | #define EBPF_OP_JSLE32_REG (EBPF_CLS_JMP32 | EBPF_SRC_REG | EBPF_MODE_JSLE) 218 | 219 | #define EBPF_OP_ATOMIC32_STORE (EBPF_CLS_STX | EBPF_MODE_ATOMIC | EBPF_SIZE_W) 220 | #define EBPF_OP_ATOMIC_STORE (EBPF_CLS_STX | EBPF_MODE_ATOMIC | EBPF_SIZE_DW) 221 | 222 | /** 223 | * @brief eBPF Map Definition as it appears in the maps section of an ELF file. 224 | */ 225 | typedef struct _ebpf_map_definition_in_file 226 | { 227 | uint32_t type; ///< Type of map. 228 | uint32_t key_size; ///< Size in bytes of a map key. 229 | uint32_t value_size; ///< Size in bytes of a map value. 230 | uint32_t max_entries; ///< Maximum number of entries allowed in the map. 231 | uint32_t inner_map_idx; ///< Index of inner map if this is a nested map. 232 | } ebpf_map_definition_in_file_t; 233 | 234 | #endif -------------------------------------------------------------------------------- /tests/add.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 2 6 | add32 %r0, 1 7 | add32 %r0, %r1 8 | add32 %r0, %r0 9 | add32 %r0, -3 10 | exit 11 | -- result 12 | 0x3 13 | -------------------------------------------------------------------------------- /tests/add64.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | mov %r1, 2 6 | add %r0, 1 7 | add %r0, %r1 8 | add %r0, %r0 9 | add %r0, -3 10 | exit 11 | -- result 12 | 0x3 13 | -------------------------------------------------------------------------------- /tests/alu-arith.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 10 5 | sub32 %r0, %r0 6 | mov32 %r1, 1 7 | mov32 %r2, 2 8 | mov32 %r3, 3 9 | mov32 %r4, 4 10 | mov32 %r5, 5 11 | mov32 %r6, 6 12 | mov32 %r7, 7 13 | mov32 %r8, 8 14 | mov32 %r9, 9 15 | # %r0 == 0 16 | jne %r0, 0, exit 17 | 18 | add32 %r0, 23 19 | add32 %r0, %r7 20 | # %r0 == 30 21 | jne %r0, 30, exit 22 | 23 | sub32 %r0, 13 24 | sub32 %r0, %r1 25 | # %r0 == 16 26 | jne %r0, 16, exit 27 | 28 | mul32 %r0, 7 29 | mul32 %r0, %r3 30 | # %r0 == 336 31 | jne %r0, 336, exit 32 | 33 | div32 %r0, 2 34 | div32 %r0, %r4 35 | # %r0 == 42 36 | jne %r0, 42, exit 37 | 38 | exit 39 | -- result 40 | 0x2a 41 | -------------------------------------------------------------------------------- /tests/alu-bit.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 1 6 | mov32 %r2, 2 7 | mov32 %r3, 3 8 | mov32 %r4, 4 9 | mov32 %r5, 5 10 | mov32 %r6, 6 11 | mov32 %r7, 7 12 | mov32 %r8, 8 13 | # %r0 == 0 14 | jne %r0, 0, exit 15 | 16 | or32 %r0, %r5 17 | or32 %r0, 0xa0 18 | or32 %r0, %r0 19 | # %r0 == 0xa5 20 | jne %r0, 0xa5, exit 21 | 22 | and32 %r0, 0xa3 23 | mov32 %r9, 0x91 24 | and32 %r0, %r9 25 | and32 %r0, %r0 26 | # %r0 == 0x81 27 | jne %r0, 0x81, exit 28 | 29 | lsh32 %r0, 22 30 | lsh32 %r0, %r8 31 | # %r0 == 0x40000000 32 | jne %r0, 0x40000000, exit 33 | 34 | rsh32 %r0, 19 35 | rsh32 %r0, %r7 36 | # %r0 == 0x10 37 | jne %r0, 0x10, exit 38 | 39 | xor32 %r0, 0x03 40 | xor32 %r0, %r2 41 | # %r0 == 0x11 42 | 43 | exit 44 | -- result 45 | 0x11 46 | -------------------------------------------------------------------------------- /tests/alu64-arith.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 10 5 | sub %r0, %r0 6 | mov %r1, 1 7 | mov %r2, 2 8 | mov %r3, 3 9 | mov %r4, 4 10 | mov %r5, 5 11 | mov %r6, 6 12 | mov %r7, 7 13 | mov %r8, 8 14 | mov %r9, 9 15 | # %r0 == 0 16 | jne %r0, 0, exit 17 | 18 | add %r0, 23 19 | add %r0, %r7 20 | # %r0 == 30 21 | jne %r0, 30, exit 22 | 23 | sub %r0, 13 24 | sub %r0, %r1 25 | # %r0 == 16 26 | jne %r0, 16, exit 27 | 28 | mul %r0, 7 29 | mul %r0, %r3 30 | # %r0 == 336 31 | jne %r0, 336, exit 32 | 33 | div %r0, 2 34 | div %r0, %r4 35 | # %r0 == 42 36 | 37 | exit 38 | -- result 39 | 0x2a 40 | -------------------------------------------------------------------------------- /tests/alu64-bit.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | mov %r1, 1 6 | mov %r2, 2 7 | mov %r3, 3 8 | mov %r4, 4 9 | mov %r5, 5 10 | mov %r6, 6 11 | mov %r7, 7 12 | mov %r8, 8 13 | # %r0 == 0 14 | jne %r0, 0, exit 15 | 16 | or %r0, %r5 17 | or %r0, 0xa0 18 | or %r0, %r0 19 | # %r0 == 0xa5 20 | jne %r0, 0xa5, exit 21 | 22 | and %r0, 0xa3 23 | mov %r9, 0x91 24 | and %r0, %r9 25 | and %r0, %r0 26 | # %r0 == 0x81 27 | jne %r0, 0x81, exit 28 | 29 | lsh %r0, 32 30 | lsh %r0, 22 31 | lsh %r0, %r8 32 | # %r0 == 0x4000000000000000 33 | # Too large to test against imm. 34 | 35 | rsh %r0, 32 36 | rsh %r0, 19 37 | rsh %r0, %r7 38 | # %r0 == 0x10 39 | jne %r0, 0x10, exit 40 | 41 | xor %r0, 0x03 42 | xor %r0, %r2 43 | # %r0 == 0x11 44 | 45 | exit 46 | -- result 47 | 0x11 48 | -------------------------------------------------------------------------------- /tests/arsh32-imm-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0xf8 5 | lsh32 %r0, 28 6 | # %r0 == 0x80000000 7 | arsh32 %r0, 48 8 | exit 9 | -- result 10 | 0xffff8000 11 | -------------------------------------------------------------------------------- /tests/arsh32-imm-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0xf8 5 | lsh32 %r0, 28 6 | # %r0 == 0x80000000 7 | arsh32 %r0, -16 8 | exit 9 | -- result 10 | 0xffff8000 11 | -------------------------------------------------------------------------------- /tests/arsh32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0xf8 5 | lsh32 %r0, 28 6 | # %r0 == 0x80000000 7 | arsh32 %r0, 16 8 | exit 9 | -- result 10 | 0xffff8000 11 | -------------------------------------------------------------------------------- /tests/arsh32-reg-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | -- asm 5 | mov32 %r0, 0xf8 6 | mov32 %r1, 48 7 | lsh32 %r0, 28 8 | # %r0 == 0x80000000 9 | arsh32 %r0, %r1 10 | exit 11 | -- result 12 | 0xffff8000 13 | -------------------------------------------------------------------------------- /tests/arsh32-reg-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | -- asm 5 | mov32 %r0, 0xf8 6 | mov32 %r1, -16 7 | lsh32 %r0, 28 8 | # %r0 == 0x80000000 9 | arsh32 %r0, %r1 10 | exit 11 | -- result 12 | 0xffff8000 13 | -------------------------------------------------------------------------------- /tests/arsh32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | -- asm 5 | mov32 %r0, 0xf8 6 | mov32 %r1, 16 7 | lsh32 %r0, 28 8 | # %r0 == 0x80000000 9 | arsh32 %r0, %r1 10 | exit 11 | -- result 12 | 0xffff8000 13 | -------------------------------------------------------------------------------- /tests/arsh64-imm-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | lsh %r0, 63 6 | arsh %r0, 124 7 | exit 8 | -- result 9 | 0xfffffffffffffff8 10 | -------------------------------------------------------------------------------- /tests/arsh64-imm-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | lsh %r0, 63 6 | arsh %r0, -4 7 | exit 8 | -- result 9 | 0xfffffffffffffff8 10 | -------------------------------------------------------------------------------- /tests/arsh64-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | lsh %r0, 63 6 | arsh %r0, 60 7 | exit 8 | -- result 9 | 0xfffffffffffffff8 10 | -------------------------------------------------------------------------------- /tests/arsh64-reg-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | lsh %r0, 63 6 | mov32 %r1, 124 7 | arsh %r0, %r1 8 | exit 9 | -- result 10 | 0xfffffffffffffff8 11 | -------------------------------------------------------------------------------- /tests/arsh64-reg-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | lsh %r0, 63 6 | mov32 %r1, -4 7 | arsh %r0, %r1 8 | exit 9 | -- result 10 | 0xfffffffffffffff8 11 | -------------------------------------------------------------------------------- /tests/arsh64-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | lsh %r0, 63 6 | mov32 %r1, 60 7 | arsh %r0, %r1 8 | exit 9 | -- result 10 | 0xfffffffffffffff8 11 | -------------------------------------------------------------------------------- /tests/be16-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | be16 %r0 6 | exit 7 | -- mem 8 | 11 22 33 44 55 66 77 88 9 | -- result 10 | 0x1122 11 | -------------------------------------------------------------------------------- /tests/be16.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxh %r0, [%r1] 5 | be16 %r0 6 | exit 7 | -- mem 8 | 11 22 9 | -- result 10 | 0x1122 11 | -------------------------------------------------------------------------------- /tests/be32-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | be32 %r0 6 | exit 7 | -- mem 8 | 11 22 33 44 55 66 77 88 9 | -- result 10 | 0x11223344 11 | -------------------------------------------------------------------------------- /tests/be32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxw %r0, [%r1] 5 | be32 %r0 6 | exit 7 | -- mem 8 | 11 22 33 44 9 | -- result 10 | 0x11223344 11 | -------------------------------------------------------------------------------- /tests/be64.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | be64 %r0 6 | exit 7 | -- mem 8 | 11 22 33 44 55 66 77 88 9 | -- result 10 | 0x1122334455667788 11 | -------------------------------------------------------------------------------- /tests/call_local.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | # %r1-r5 are passed to the callee 5 | mov %r0, 0 6 | mov %r1, 1 7 | mov %r2, 2 8 | mov %r3, 3 9 | mov %r4, 4 10 | mov %r5, 5 11 | # %r6-r9 are preserved 12 | mov %r6, 6 13 | mov %r7, 7 14 | mov %r8, 8 15 | mov %r9, 9 16 | call local func1 17 | # %r0 contains the return value 18 | # %r0 should contain 1 + 2 + 3 + 4 + 5 19 | jne %r0, 15, failed 20 | # %r6 through %r9 should be preserved 21 | jne %r6, 6, failed 22 | jne %r7, 7, failed 23 | jne %r8, 8, failed 24 | jne %r9, 9, failed 25 | # Success 26 | mov %r0, 1 27 | exit 28 | failed: 29 | mov %r0, -1 30 | exit 31 | # Function sets %r0 = %r1 + %r2 + %r3 + %r4 + %r5 32 | func1: 33 | mov %r0, 0 34 | add %r0, %r1 35 | add %r0, %r2 36 | add %r0, %r3 37 | add %r0, %r4 38 | add %r0, %r5 39 | mov %r6, 0 40 | mov %r7, 0 41 | mov %r8, 0 42 | mov %r9, 0 43 | exit 44 | -- result 45 | 0x1 46 | -------------------------------------------------------------------------------- /tests/call_unwind_fail.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r1, -1 5 | call 5 6 | mov %r0, 2 7 | exit 8 | -- result 9 | 0x2 10 | -- no register offset 11 | call instruction 12 | -------------------------------------------------------------------------------- /tests/callx.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r1, -1 5 | mov %r2, 5 6 | call %r2 7 | mov %r0, 2 8 | exit 9 | -- result 10 | 0x2 11 | -- no register offset 12 | call instruction 13 | -------------------------------------------------------------------------------- /tests/div32-by-zero-reg-2.data: -------------------------------------------------------------------------------- 1 | -- asm 2 | mov32 %r0, 1 3 | lddw %r1, 0x100000000 4 | div32 %r0, %r1 5 | exit 6 | -- result 7 | 0x0 8 | -------------------------------------------------------------------------------- /tests/div32-by-zero-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | mov32 %r1, 0 6 | div32 %r0, %r1 7 | exit 8 | -- result 9 | 0x0 10 | -------------------------------------------------------------------------------- /tests/div32-high-divisor.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 12 5 | lddw %r1, 0x100000004 6 | div32 %r0, %r1 7 | exit 8 | -- result 9 | 0x3 10 | -------------------------------------------------------------------------------- /tests/div32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x10000000c 5 | div32 %r0, 4 6 | exit 7 | -- result 8 | 0x3 9 | -------------------------------------------------------------------------------- /tests/div32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x10000000c 5 | mov %r1, 4 6 | div32 %r0, %r1 7 | exit 8 | -- result 9 | 0x3 10 | -------------------------------------------------------------------------------- /tests/div64-by-zero-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | mov32 %r1, 0 6 | div %r0, %r1 7 | exit 8 | -- result 9 | 0x0 10 | -------------------------------------------------------------------------------- /tests/div64-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0xc 5 | lsh %r0, 32 6 | div %r0, 4 7 | exit 8 | -- result 9 | 0x300000000 10 | -------------------------------------------------------------------------------- /tests/div64-negative-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0xFFFFFFFFFFFFFFFF 5 | div %r0, -10 6 | exit 7 | -- result 8 | 0x1 -------------------------------------------------------------------------------- /tests/div64-negative-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0xFFFFFFFFFFFFFFFF 5 | mov32 %r1, -10 6 | div %r0, %r1 7 | exit 8 | -- result 9 | 0x10000000A -------------------------------------------------------------------------------- /tests/div64-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0xc 5 | lsh %r0, 32 6 | mov %r1, 4 7 | div %r0, %r1 8 | exit 9 | -- result 10 | 0x300000000 11 | -------------------------------------------------------------------------------- /tests/exit-not-last.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r1, 0 5 | ja L2 6 | L1: 7 | mov %r2, 0 8 | exit 9 | L2: 10 | mov %r0, 0 11 | ja L1 12 | -- result 13 | 0x0 14 | -------------------------------------------------------------------------------- /tests/exit.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | exit 6 | -- result 7 | 0x0 8 | -------------------------------------------------------------------------------- /tests/j-signed-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alan Jowett 2 | # SPDX-License-Identifier: MIT 3 | # This test checks if the immediate value is sign extended when performing 4 | # unsigned jump operations. 5 | 6 | -- asm 7 | mov32 %r0, 2 8 | 9 | lddw %r1, 0xFFFFFFFF80000000 10 | jeq %r1, 0x80000000, +1 # Taken, sign extended 11 | exit 12 | 13 | lddw %r1, 0xFFFFFFFF80000000 14 | jlt %r1, 0x80000001, +1 # Taken, sign extended 15 | exit 16 | 17 | lddw %r1, 0xFFFFFFFF80000001 18 | jgt %r1, 0x80000000, +1 # Taken, sign extended 19 | exit 20 | 21 | lddw %r1, 0x80000000 22 | jne %r1, 0x80000000, +1 # Taken, sign extended 23 | exit 24 | 25 | lddw %r1, 0xFFFFFFFF00000000 26 | jset %r1, 0x80000000, +1 # Taken, sign extended 27 | exit 28 | 29 | mov32 %r0, 1 30 | exit 31 | -- result 32 | 0x1 33 | -------------------------------------------------------------------------------- /tests/ja32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r1, 0 5 | ja32 L2 6 | L1: 7 | mov %r2, 0 8 | exit 9 | L2: 10 | mov %r0, 0 11 | ja32 L1 12 | -- result 13 | 0x0 14 | -------------------------------------------------------------------------------- /tests/jeq-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 0xa 6 | jeq %r1, 0xb, exit # Not taken 7 | 8 | mov32 %r0, 1 9 | mov32 %r1, 0xb 10 | jeq %r1, 0xb, exit # Taken 11 | 12 | mov32 %r0, 2 # Skipped 13 | exit 14 | -- result 15 | 0x1 16 | -------------------------------------------------------------------------------- /tests/jeq-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 0xa 6 | mov32 %r2, 0xb 7 | jeq %r1, %r2, exit # Not taken 8 | jeq %r1, %r1, +1 # Taken 9 | exit 10 | 11 | mov32 %r0, 1 12 | mov32 %r1, 0xb 13 | jeq %r1, %r2, exit # Taken 14 | 15 | mov32 %r0, 2 # Skipped 16 | exit 17 | -- result 18 | 0x1 19 | -------------------------------------------------------------------------------- /tests/jeq32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0x0 8 | mov32 %r1, 0xa 9 | jeq32 %r1, 0xb, exit # Not taken 10 | 11 | mov32 %r0, 1 12 | # Confirm upper bits are ignored in comparison 13 | mov %r1, 0xb 14 | # set %r1 to 0x10000000b 15 | or %r1, %r9 16 | jeq32 %r1, 0xb, exit # Taken 17 | 18 | mov32 %r0, 2 # Skipped 19 | exit 20 | -- result 21 | 0x1 22 | -------------------------------------------------------------------------------- /tests/jeq32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xa 9 | mov32 %r2, 0xb 10 | jeq32 %r1, %r2, exit # Not taken 11 | jeq32 %r1, %r1, +1 # Taken 12 | exit 13 | 14 | mov32 %r0, 1 15 | mov32 %r1, 0xb 16 | # set %r1 to 0x10000000b 17 | or %r1, %r9 18 | jeq32 %r1, %r2, exit # Taken 19 | 20 | mov32 %r0, 2 # Skipped 21 | exit 22 | -- result 23 | 0x1 24 | -------------------------------------------------------------------------------- /tests/jge-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 0xa 6 | jge %r1, 0xb, exit # Not taken 7 | 8 | mov32 %r0, 1 9 | mov32 %r1, 0xc 10 | jge %r1, 0xb, exit # Taken 11 | 12 | mov32 %r0, 2 # Skipped 13 | exit 14 | -- result 15 | 0x1 16 | -------------------------------------------------------------------------------- /tests/jge-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 0xa 6 | mov32 %r2, 0x0b 7 | jge %r1, %r2, exit # Not taken 8 | jge %r1, %r1, +1 # Taken 9 | exit 10 | 11 | mov32 %r0, 1 12 | mov32 %r1, 0xc 13 | jge %r1, %r2, exit # Taken 14 | 15 | mov32 %r0, 2 # Skipped 16 | exit 17 | -- result 18 | 0x1 19 | -------------------------------------------------------------------------------- /tests/jge32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xa 9 | jge32 %r1, 0xb, exit # Not taken 10 | 11 | mov32 %r0, 1 12 | # set %r1 to 0x10000000c 13 | mov32 %r1, 0xc 14 | or %r1, %r9 15 | jge32 %r1, 0xb, exit # Taken 16 | 17 | mov32 %r0, 2 # Skipped 18 | 19 | exit 20 | -- result 21 | 0x1 22 | -------------------------------------------------------------------------------- /tests/jge32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xa 9 | mov32 %r2, 0xb 10 | jge32 %r1, %r2, exit # Not taken 11 | jge32 %r1, %r1, +1 # Taken 12 | exit 13 | 14 | mov32 %r0, 1 15 | # set %r1 to 0x10000000c 16 | mov32 %r1, 0xc 17 | or %r1, %r9 18 | jge32 %r1, %r2, exit # Taken 19 | 20 | mov32 %r0, 2 # Skipped 21 | 22 | exit 23 | -- result 24 | 0x1 25 | -------------------------------------------------------------------------------- /tests/jgt-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 5 6 | jgt %r1, 6, exit # Not taken 7 | jgt %r1, 5, exit # Not taken 8 | jgt %r1, 4, L1 # Taken 9 | exit 10 | L1: 11 | mov32 %r0, 1 12 | exit 13 | -- result 14 | 0x1 15 | -------------------------------------------------------------------------------- /tests/jgt-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | mov %r1, 5 6 | mov %r2, 6 7 | mov %r3, 4 8 | jgt %r1, %r2, exit # Not taken 9 | jgt %r1, %r1, exit # Not taken 10 | jgt %r1, %r3, taken # Taken 11 | exit 12 | taken: 13 | mov %r0, 1 14 | exit 15 | -- result 16 | 0x1 17 | -------------------------------------------------------------------------------- /tests/jgt32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | # set %r1 to 0x100000005 9 | mov32 %r1, 5 10 | or %r1, %r9 11 | jgt32 %r1, 6, exit # Not taken 12 | jgt32 %r1, 5, exit # Not taken 13 | jgt32 %r1, 4, taken # Taken 14 | exit 15 | taken: 16 | mov32 %r0, 1 17 | exit 18 | -- result 19 | 0x1 20 | -------------------------------------------------------------------------------- /tests/jgt32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov %r0, 0 8 | mov %r1, 5 9 | mov32 %r1, 5 10 | # set %r1 to 0x100000005 11 | or %r1, %r9 12 | mov %r2, 6 13 | mov %r3, 4 14 | jgt32 %r1, %r2, exit # Not taken 15 | jgt32 %r1, %r1, exit # Not taken 16 | jgt32 %r1, %r3, taken # Taken 17 | exit 18 | taken: 19 | mov %r0, 1 20 | exit 21 | -- result 22 | 0x1 23 | -------------------------------------------------------------------------------- /tests/jit-bounce.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 1 5 | mov %r6, %r0 6 | mov %r7, %r6 7 | mov %r8, %r7 8 | mov %r9, %r8 9 | # TODO %r10 10 | mov %r0, %r9 11 | exit 12 | -- result 13 | 0x1 14 | -------------------------------------------------------------------------------- /tests/jle-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 5 6 | jle %r1, 4, exit # Not taken 7 | jle %r1, 6, +1 # Taken 8 | exit 9 | taken: 10 | jle %r1, 5, +1 # Taken 11 | exit 12 | taken2: 13 | mov32 %r0, 1 14 | exit 15 | -- result 16 | 0x1 17 | -------------------------------------------------------------------------------- /tests/jle-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | mov %r1, 5 6 | mov %r2, 4 7 | mov %r3, 6 8 | jle %r1, %r2, exit # Not taken 9 | jle %r1, %r1, +1 # Taken 10 | exit 11 | jle %r1, %r3, +1 # Taken 12 | exit 13 | mov %r0, 1 14 | exit 15 | -- result 16 | 0x1 17 | -------------------------------------------------------------------------------- /tests/jle32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 5 9 | # set %r1 to 0x100000005 10 | or %r1, %r9 11 | jle32 %r1, 4, exit # Not taken 12 | jle32 %r1, 6, +1 # Taken 13 | exit 14 | jle32 %r1, 5, +1 # Taken 15 | exit 16 | mov32 %r0, 1 17 | exit 18 | -- result 19 | 0x1 20 | -------------------------------------------------------------------------------- /tests/jle32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov %r0, 0 8 | mov %r1, 5 9 | mov %r2, 4 10 | mov %r3, 6 11 | # set %r1 to 0x100000005 12 | or %r1, %r9 13 | jle32 %r1, %r2, exit # Not taken 14 | jle32 %r1, %r1, +1 # Taken 15 | exit 16 | jle32 %r1, %r3, +1 # Taken 17 | exit 18 | mov %r0, 1 19 | exit 20 | -- result 21 | 0x1 22 | -------------------------------------------------------------------------------- /tests/jlt-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 5 6 | jlt %r1, 4, exit # Not taken 7 | jlt %r1, 5, exit # Not taken 8 | jlt %r1, 6, +1 # Taken 9 | exit 10 | mov32 %r0, 1 11 | exit 12 | -- result 13 | 0x1 14 | -------------------------------------------------------------------------------- /tests/jlt-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | mov %r1, 5 6 | mov %r2, 4 7 | mov %r3, 6 8 | jlt %r1, %r2, exit # Not taken 9 | jlt %r1, %r1, exit # Not taken 10 | jlt %r1, %r3, +1 # Taken 11 | exit 12 | mov %r0, 1 13 | exit 14 | -- result 15 | 0x1 16 | -------------------------------------------------------------------------------- /tests/jlt32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 5 9 | # set %r1 to 0x100000005 10 | or %r1, %r9 11 | jlt32 %r1, 4, exit # Not taken 12 | jlt32 %r1, 5, exit # Not taken 13 | jlt32 %r1, 6, +1 # Taken 14 | exit 15 | mov32 %r0, 1 16 | exit 17 | -- result 18 | 0x1 19 | -------------------------------------------------------------------------------- /tests/jlt32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov %r0, 0 8 | mov %r1, 5 9 | mov %r2, 4 10 | mov %r3, 6 11 | # set %r1 to 0x100000005 12 | or %r1, %r9 13 | jlt32 %r1, %r2, exit # Not taken 14 | jlt32 %r1, %r1, exit # Not taken 15 | jlt32 %r1, %r3, +1 # Taken 16 | exit 17 | mov %r0, 1 18 | exit 19 | -- result 20 | 0x1 21 | -------------------------------------------------------------------------------- /tests/jne-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 0xb 6 | mov32 %r2, 0xb 7 | jne %r1, %r2, exit # Not taken 8 | jne %r1, %r1, exit # Not taken 9 | 10 | mov32 %r0, 1 11 | mov32 %r1, 0xa 12 | jne %r1, %r2, +1 # Taken 13 | 14 | mov32 %r0, 2 # Skipped 15 | exit 16 | -- result 17 | 0x1 18 | -------------------------------------------------------------------------------- /tests/jne32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xb 9 | # set %r1 to 0x10000000b 10 | or %r1, %r9 11 | jne32 %r1, 0xb, +4 # Not taken 12 | 13 | mov32 %r0, 1 14 | mov32 %r1, 0xa 15 | # set %r1 to 0x10000000a 16 | or %r1, %r9 17 | jne32 %r1, 0xb, +1 # Taken 18 | 19 | mov32 %r0, 2 # Skipped 20 | exit 21 | -- result 22 | 0x1 23 | -------------------------------------------------------------------------------- /tests/jne32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xb 9 | # set %r1 to 0x10000000b 10 | or %r1, %r9 11 | mov32 %r2, 0xb 12 | jne32 %r1, %r2, +5 # Not taken 13 | jne32 %r1, %r1, +4 # Not taken 14 | 15 | mov32 %r0, 1 16 | mov32 %r1, 0xa 17 | # set %r1 to 0x10000000a 18 | or %r1, %r9 19 | jne32 %r1, %r2, +1 # Taken 20 | 21 | mov32 %r0, 2 # Skipped 22 | exit 23 | -- result 24 | 0x1 25 | -------------------------------------------------------------------------------- /tests/jset-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 0x7 6 | jset %r1, 0x8, exit # Not taken 7 | 8 | mov32 %r0, 1 9 | mov32 %r1, 0x9 10 | jset %r1, 0x8, +1 # Taken 11 | 12 | mov32 %r0, 2 # Skipped 13 | 14 | exit 15 | -- result 16 | 0x1 17 | -------------------------------------------------------------------------------- /tests/jset-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov32 %r1, 0x7 6 | mov32 %r2, 0x8 7 | jset %r1, %r2, exit # Not taken 8 | jset %r1, %r1, +1 # Taken 9 | exit 10 | 11 | mov32 %r0, 1 12 | mov32 %r1, 0x9 13 | jset %r1, %r2, +1 # Taken 14 | 15 | mov32 %r0, 2 # Skipped 16 | 17 | exit 18 | -- result 19 | 0x1 20 | -------------------------------------------------------------------------------- /tests/jset32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0x7 9 | # set %r1 to 0x100000007 10 | or %r1, %r9 11 | jset32 %r1, 0x8, exit # Not taken 12 | 13 | mov32 %r0, 1 14 | mov32 %r1, 0x9 15 | jset32 %r1, 0x8, +1 # Taken 16 | 17 | mov32 %r0, 2 # Skipped 18 | 19 | exit 20 | -- result 21 | 0x1 22 | -------------------------------------------------------------------------------- /tests/jset32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0x7 9 | # set %r1 to 0x100000007 10 | or %r1, %r9 11 | mov32 %r2, 0x8 12 | jset32 %r1, %r2, exit # Not taken 13 | jset32 %r1, %r1, +1 # Taken 14 | exit 15 | 16 | mov32 %r0, 1 17 | mov32 %r1, 0x9 18 | jset32 %r1, %r2, +1 # Taken 19 | 20 | mov32 %r0, 2 # Skipped 21 | 22 | exit 23 | -- result 24 | 0x1 25 | -------------------------------------------------------------------------------- /tests/jsge-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov %r1, 0xfffffffe 6 | jsge %r1, 0xffffffff, exit # Not taken 7 | jsge %r1, 0, +4 # Not taken 8 | 9 | mov32 %r0, 1 10 | mov %r1, 0xffffffff 11 | jsge %r1, 0xffffffff, +1 # Taken 12 | 13 | mov32 %r0, 2 # Skipped 14 | 15 | exit 16 | -- result 17 | 0x1 18 | -------------------------------------------------------------------------------- /tests/jsge-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov %r1, 0xfffffffe 6 | mov %r2, 0xffffffff 7 | mov32 %r3, 0 8 | jsge %r1, %r2, exit # Not taken 9 | jsge %r1, %r3, exit # Not taken 10 | jsge %r1, %r1, +1 # Taken 11 | exit 12 | 13 | mov32 %r0, 1 14 | mov %r1, %r2 15 | jsge %r1, %r2, +1 # Taken 16 | 17 | mov32 %r0, 2 # Skipped 18 | 19 | exit 20 | -- result 21 | 0x1 22 | -------------------------------------------------------------------------------- /tests/jsge32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xfffffffe 9 | # set %r1 to 0x1fffffffe 10 | or %r1, %r9 11 | jsge32 %r1, 0xffffffff, exit # Not taken 12 | jsge32 %r1, 0, exit # Not taken 13 | 14 | mov32 %r0, 1 15 | mov %r1, 0xffffffff 16 | jsge32 %r1, 0xffffffff, +1 # Taken 17 | 18 | mov32 %r0, 2 # Skipped 19 | 20 | exit 21 | -- result 22 | 0x1 23 | -------------------------------------------------------------------------------- /tests/jsge32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xfffffffe 9 | # set %r1 to 0x1fffffffe 10 | or %r1, %r9 11 | mov %r2, 0xffffffff 12 | mov32 %r3, 0 13 | jsge32 %r1, %r2, exit # Not taken 14 | jsge32 %r1, %r3, exit # Not taken 15 | jsge32 %r1, %r1, +1 # Taken 16 | exit 17 | 18 | mov32 %r0, 1 19 | mov %r1, %r2 20 | jsge32 %r1, %r2, +1 # Taken 21 | 22 | mov32 %r0, 2 # Skipped 23 | 24 | exit 25 | -- result 26 | 0x1 27 | -------------------------------------------------------------------------------- /tests/jsgt-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov %r1, 0xfffffffe 6 | jsgt %r1, 0xffffffff, exit # Not taken 7 | 8 | mov32 %r0, 1 9 | mov32 %r1, 0 10 | jsgt %r1, 0xffffffff, +1 # Taken 11 | 12 | mov32 %r0, 2 # Skipped 13 | 14 | exit 15 | -- result 16 | 0x1 17 | -------------------------------------------------------------------------------- /tests/jsgt-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov %r1, 0xfffffffe 6 | mov %r2, 0xffffffff 7 | jsgt %r1, %r2, exit # Not taken 8 | jsgt %r1, %r1, exit # Not taken 9 | 10 | mov32 %r0, 1 11 | mov32 %r1, 0 12 | jsgt %r1, %r2, +1 # Taken 13 | 14 | mov32 %r0, 2 # Skipped 15 | 16 | exit 17 | -- result 18 | 0x1 19 | -------------------------------------------------------------------------------- /tests/jsgt32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xfffffffe 9 | # set %r1 to 0x1fffffffe 10 | or %r1, %r9 11 | jsgt32 %r1, 0xffffffff, exit # Not taken 12 | 13 | mov32 %r0, 1 14 | mov32 %r1, 0 15 | jsgt32 %r1, 0xffffffff, +1 # Taken 16 | 17 | mov32 %r0, 2 # Skipped 18 | 19 | exit 20 | -- result 21 | 0x1 22 | -------------------------------------------------------------------------------- /tests/jsgt32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xfffffffe 9 | # set %r1 to 0x1fffffffe 10 | or %r1, %r9 11 | mov %r2, 0xffffffff 12 | jsgt32 %r1, %r2, exit # Not taken 13 | jsgt32 %r1, %r1, exit # Not taken 14 | 15 | mov32 %r0, 1 16 | mov32 %r1, 0 17 | jsgt32 %r1, %r2, +1 # Taken 18 | 19 | mov32 %r0, 2 # Skipped 20 | 21 | exit 22 | -- result 23 | 0x1 24 | -------------------------------------------------------------------------------- /tests/jsle-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov %r1, 0xfffffffe 6 | jsle %r1, 0xfffffffd, exit # Not taken 7 | jsle %r1, 0xffffffff, +1 # Taken 8 | exit 9 | mov32 %r0, 1 10 | jsle %r1, 0xfffffffe, +1 # Taken 11 | mov32 %r0, 2 12 | exit 13 | -- result 14 | 0x1 15 | -------------------------------------------------------------------------------- /tests/jsle-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov %r1, 0xffffffff 6 | mov %r2, 0xfffffffe 7 | mov32 %r3, 0 8 | jsle %r1, %r2, exit # Not taken 9 | jsle %r1, %r3, +1 # Taken 10 | exit 11 | jsle %r1, %r1, +1 # Taken 12 | exit 13 | 14 | mov32 %r0, 1 15 | mov %r1, %r2 16 | jsle %r1, %r2, +1 # Taken 17 | mov32 %r0, 2 18 | exit 19 | -- result 20 | 0x1 21 | -------------------------------------------------------------------------------- /tests/jsle32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xfffffffe 9 | # set %r1 to 0x1fffffffe 10 | or %r1, %r9 11 | jsle32 %r1, 0xfffffffd, exit # Not taken 12 | jsle32 %r1, 0xffffffff, +1 # Taken 13 | exit 14 | mov32 %r0, 1 15 | jsle32 %r1, 0xfffffffe, +1 # Taken 16 | mov32 %r0, 2 17 | exit 18 | -- result 19 | 0x1 20 | -------------------------------------------------------------------------------- /tests/jsle32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xffffffff 9 | # set %r1 to 0x1ffffffff 10 | or %r1, %r9 11 | mov %r2, 0xfffffffe 12 | mov32 %r3, 0 13 | jsle32 %r1, %r2, exit # Not taken 14 | jsle32 %r1, %r3, +1 # Taken 15 | exit 16 | jsle32 %r1, %r1, +1 # Taken 17 | exit 18 | 19 | mov32 %r0, 1 20 | mov %r1, %r2 21 | jsle32 %r1, %r2, +1 # Taken 22 | mov32 %r0, 2 23 | exit 24 | -- result 25 | 0x1 26 | -------------------------------------------------------------------------------- /tests/jslt-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov %r1, 0xfffffffe 6 | jslt %r1, 0xfffffffd, exit # Not taken 7 | jslt %r1, 0xfffffffe, exit # Not taken 8 | jslt %r1, 0xffffffff, +1 # Taken 9 | exit 10 | mov32 %r0, 1 11 | exit 12 | -- result 13 | 0x1 14 | -------------------------------------------------------------------------------- /tests/jslt-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0 5 | mov %r1, 0xfffffffe 6 | mov %r2, 0xfffffffd 7 | mov %r3, 0xffffffff 8 | jslt %r1, %r1, exit # Not taken 9 | jslt %r1, %r2, exit # Not taken 10 | jslt %r1, %r3, +1 # Taken 11 | exit 12 | mov32 %r0, 1 13 | exit 14 | -- result 15 | 0x1 16 | -------------------------------------------------------------------------------- /tests/jslt32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xfffffffe 9 | # set %r1 to 0x1fffffffe 10 | or %r1, %r9 11 | jslt32 %r1, 0xfffffffd, exit # Not taken 12 | jslt32 %r1, 0xfffffffe, exit # Not taken 13 | jslt32 %r1, 0xffffffff, +1 # Taken 14 | exit 15 | mov32 %r0, 1 16 | exit 17 | -- result 18 | 0x1 19 | -------------------------------------------------------------------------------- /tests/jslt32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Set %r9 to 0x100000000 5 | mov %r9, 1 6 | lsh %r9, 32 7 | mov32 %r0, 0 8 | mov32 %r1, 0xfffffffe 9 | # set %r1 to 0x1fffffffe 10 | or %r1, %r9 11 | mov %r2, 0xfffffffd 12 | mov %r3, 0xffffffff 13 | jslt32 %r1, %r1, exit # Not taken 14 | jslt32 %r1, %r2, exit # Not taken 15 | jslt32 %r1, %r3, +1 # Taken 16 | exit 17 | mov32 %r0, 1 18 | exit 19 | -- result 20 | 0x1 21 | -------------------------------------------------------------------------------- /tests/lddw.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x1122334455667788 5 | exit 6 | -- raw 7 | 0x5566778800000018 8 | 0x1122334400000000 9 | 0x0000000000000095 10 | -- result 11 | 0x1122334455667788 12 | -------------------------------------------------------------------------------- /tests/lddw2.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | # Test decimal 64bit immediate value. 5 | lddw %r0, 2147483648 6 | exit 7 | -- result 8 | 0x0000000080000000 9 | -------------------------------------------------------------------------------- /tests/ldxb-all.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, %r1 5 | 6 | ldxb %r9, [%r0+0] 7 | lsh %r9, 0 8 | 9 | ldxb %r8, [%r0+0x1] 10 | lsh %r8, 4 11 | 12 | ldxb %r7, [%r0+2] 13 | lsh %r7, 8 14 | 15 | ldxb %r6, [%r0+3] 16 | lsh %r6, 12 17 | 18 | ldxb %r5, [%r0+4] 19 | lsh %r5, 16 20 | 21 | ldxb %r4, [%r0+5] 22 | lsh %r4, 20 23 | 24 | ldxb %r3, [%r0+6] 25 | lsh %r3, 24 26 | 27 | ldxb %r2, [%r0+7] 28 | lsh %r2, 28 29 | 30 | ldxb %r1, [%r0+8] 31 | lsh %r1, 32 32 | 33 | ldxb %r0, [%r0+9] 34 | lsh %r0, 36 35 | 36 | or %r0, %r1 37 | or %r0, %r2 38 | or %r0, %r3 39 | or %r0, %r4 40 | or %r0, %r5 41 | or %r0, %r6 42 | or %r0, %r7 43 | or %r0, %r8 44 | or %r0, %r9 45 | 46 | exit 47 | -- result 48 | 0x9876543210 49 | -- mem 50 | 00 01 02 03 04 05 06 07 08 09 51 | -------------------------------------------------------------------------------- /tests/ldxb.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxb %r0, [%r1+0x2] 5 | exit 6 | -- mem 7 | aa bb 11 cc dd 8 | -- result 9 | 0x11 10 | -------------------------------------------------------------------------------- /tests/ldxdw.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxdw %r0, [%r1+2] 5 | exit 6 | -- mem 7 | aa bb 11 22 33 44 55 66 77 88 cc dd 8 | -- result 9 | 0x8877665544332211 10 | -------------------------------------------------------------------------------- /tests/ldxh-all.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, %r1 5 | 6 | ldxh %r9, [%r0+0] 7 | be16 %r9 8 | lsh %r9, 0 9 | 10 | ldxh %r8, [%r0+2] 11 | be16 %r8 12 | lsh %r8, 4 13 | 14 | ldxh %r7, [%r0+4] 15 | be16 %r7 16 | lsh %r7, 8 17 | 18 | ldxh %r6, [%r0+6] 19 | be16 %r6 20 | lsh %r6, 12 21 | 22 | ldxh %r5, [%r0+8] 23 | be16 %r5 24 | lsh %r5, 16 25 | 26 | ldxh %r4, [%r0+10] 27 | be16 %r4 28 | lsh %r4, 20 29 | 30 | ldxh %r3, [%r0+12] 31 | be16 %r3 32 | lsh %r3, 24 33 | 34 | ldxh %r2, [%r0+14] 35 | be16 %r2 36 | lsh %r2, 28 37 | 38 | ldxh %r1, [%r0+16] 39 | be16 %r1 40 | lsh %r1, 32 41 | 42 | ldxh %r0, [%r0+18] 43 | be16 %r0 44 | lsh %r0, 36 45 | 46 | or %r0, %r1 47 | or %r0, %r2 48 | or %r0, %r3 49 | or %r0, %r4 50 | or %r0, %r5 51 | or %r0, %r6 52 | or %r0, %r7 53 | or %r0, %r8 54 | or %r0, %r9 55 | 56 | exit 57 | -- result 58 | 0x9876543210 59 | -- mem 60 | 00 00 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 61 | -------------------------------------------------------------------------------- /tests/ldxh-all2.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, %r1 5 | 6 | ldxh %r9, [%r0+0] 7 | be16 %r9 8 | 9 | ldxh %r8, [%r0+2] 10 | be16 %r8 11 | 12 | ldxh %r7, [%r0+4] 13 | be16 %r7 14 | 15 | ldxh %r6, [%r0+6] 16 | be16 %r6 17 | 18 | ldxh %r5, [%r0+8] 19 | be16 %r5 20 | 21 | ldxh %r4, [%r0+10] 22 | be16 %r4 23 | 24 | ldxh %r3, [%r0+12] 25 | be16 %r3 26 | 27 | ldxh %r2, [%r0+14] 28 | be16 %r2 29 | 30 | ldxh %r1, [%r0+16] 31 | be16 %r1 32 | 33 | ldxh %r0, [%r0+18] 34 | be16 %r0 35 | 36 | or %r0, %r1 37 | or %r0, %r2 38 | or %r0, %r3 39 | or %r0, %r4 40 | or %r0, %r5 41 | or %r0, %r6 42 | or %r0, %r7 43 | or %r0, %r8 44 | or %r0, %r9 45 | 46 | exit 47 | -- result 48 | 0x3ff 49 | -- mem 50 | 00 01 51 | 00 02 52 | 00 04 53 | 00 08 54 | 00 10 55 | 00 20 56 | 00 40 57 | 00 80 58 | 01 00 59 | 02 00 60 | -------------------------------------------------------------------------------- /tests/ldxh-same-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, %r1 5 | sth [%r0], 0x1234 6 | ldxh %r0, [%r0] 7 | exit 8 | -- mem 9 | ff ff 10 | -- result 11 | 0x1234 12 | -------------------------------------------------------------------------------- /tests/ldxh.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxh %r0, [%r1+2] 5 | exit 6 | -- mem 7 | aa bb 11 22 cc dd 8 | -- result 9 | 0x2211 10 | -------------------------------------------------------------------------------- /tests/ldxw-all.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, %r1 5 | 6 | ldxw %r9, [%r0+0] 7 | be32 %r9 8 | 9 | ldxw %r8, [%r0+4] 10 | be32 %r8 11 | 12 | ldxw %r7, [%r0+8] 13 | be32 %r7 14 | 15 | ldxw %r6, [%r0+12] 16 | be32 %r6 17 | 18 | ldxw %r5, [%r0+16] 19 | be32 %r5 20 | 21 | ldxw %r4, [%r0+20] 22 | be32 %r4 23 | 24 | ldxw %r3, [%r0+24] 25 | be32 %r3 26 | 27 | ldxw %r2, [%r0+28] 28 | be32 %r2 29 | 30 | ldxw %r1, [%r0+32] 31 | be32 %r1 32 | 33 | ldxw %r0, [%r0+36] 34 | be32 %r0 35 | 36 | or %r0, %r1 37 | or %r0, %r2 38 | or %r0, %r3 39 | or %r0, %r4 40 | or %r0, %r5 41 | or %r0, %r6 42 | or %r0, %r7 43 | or %r0, %r8 44 | or %r0, %r9 45 | 46 | exit 47 | -- result 48 | 0x030f0f 49 | -- mem 50 | 00 00 00 01 51 | 00 00 00 02 52 | 00 00 00 04 53 | 00 00 00 08 54 | 00 00 01 00 55 | 00 00 02 00 56 | 00 00 04 00 57 | 00 00 08 00 58 | 00 01 00 00 59 | 00 02 00 00 60 | -------------------------------------------------------------------------------- /tests/ldxw.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxw %r0, [%r1+2] 5 | exit 6 | -- mem 7 | aa bb 11 22 33 44 cc dd 8 | -- result 9 | 0x44332211 10 | -------------------------------------------------------------------------------- /tests/le16-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | le16 %r0 6 | exit 7 | -- mem 8 | 22 11 00 FF EE DD CC BB AA 9 | -- result 10 | 0x1122 11 | -------------------------------------------------------------------------------- /tests/le16.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxh %r0, [%r1] 5 | le16 %r0 6 | exit 7 | -- mem 8 | 22 11 9 | -- result 10 | 0x1122 11 | -------------------------------------------------------------------------------- /tests/le32-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | le32 %r0 6 | exit 7 | -- mem 8 | 44 33 22 11 00 FF EE DD 9 | -- result 10 | 0x11223344 11 | -------------------------------------------------------------------------------- /tests/le32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxw %r0, [%r1] 5 | le32 %r0 6 | exit 7 | -- mem 8 | 44 33 22 11 9 | -- result 10 | 0x11223344 11 | -------------------------------------------------------------------------------- /tests/le64.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | le64 %r0 6 | exit 7 | -- mem 8 | 88 77 66 55 44 33 22 11 9 | -- result 10 | 0x1122334455667788 11 | -------------------------------------------------------------------------------- /tests/lock_add.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | mov %r1, 1 7 | lock add [%r10-8], %r1 8 | ldxdw %r1, [%r10-8] 9 | lddw %r0, 0x123456789abcdef1 10 | jne %r0, %r1, exit 11 | mov %r0, 0 12 | exit 13 | -- result 14 | 0x0 15 | -------------------------------------------------------------------------------- /tests/lock_add32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | mov %r1, 1 7 | lock add32 [%r10-8], %r1 8 | ldxdw %r1, [%r10-8] 9 | lddw %r0, 0x123456789abcdef1 10 | jne %r0, %r1, exit 11 | mov %r0, 0 12 | exit 13 | -- result 14 | 0x0 15 | -------------------------------------------------------------------------------- /tests/lock_and.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | lddw %r1, 0x00ff00ff00ff00ff 7 | lock and [%r10-8], %r1 8 | ldxdw %r0, [%r10-8] 9 | lddw %r1, 0x0034007800bc00f0 10 | jne %r0, %r1, exit 11 | mov %r0, 0 12 | exit 13 | -- result 14 | 0x0 15 | -------------------------------------------------------------------------------- /tests/lock_and32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | lddw %r1, 0x00ff00ff00ff00ff 7 | lock and32 [%r10-8], %r1 8 | ldxdw %r0, [%r10-8] 9 | lddw %r1, 0x1234567800bc00f0 10 | jne %r0, %r1, exit 11 | mov %r0, 0 12 | exit 13 | -- result 14 | 0x0 15 | -------------------------------------------------------------------------------- /tests/lock_cmpxchg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | # Store 0x123456789abcdef0 in [%r10-8] 5 | lddw %r0, 0x123456789abcdef0 6 | stxdw [%r10-8], %r0 7 | lddw %r1, 0x1122334455667788 8 | lddw %r0, 0xfedcba987654321 9 | # Expected to fail as [%r10-8] != %r1 10 | lock cmpxchg [%r10-8], %r1 # Atomically compare %r0 and [%r10-8] and set [%r10-8] to %r1 if matches. 11 | # Test if %r0 contains value from [%r10-8] 12 | lddw %r1, 0x123456789abcdef0 13 | jne %r0, %r1, exit 14 | # Test if [%r10-8] is unmodified 15 | ldxdw %r0, [%r10-8] 16 | jne %r0, %r1, exit 17 | 18 | lddw %r0, 0x123456789abcdef0 19 | stxdw [%r10-8], %r0 20 | lddw %r1, 0x1122334455667788 21 | # Expected to succeed 22 | lock cmpxchg [%r10-8], %r1 # Atomically compare %r0 and [%r10-8] and set [%r10-8] to %r1 if matches. 23 | # Test if %r0 contains 0x123456789abcdef0 24 | lddw %r1, 0x123456789abcdef0 25 | jne %r0, %r1, exit 26 | # Test if %r0 contains value from [%r10-8] 27 | ldxdw %r0, [%r10-8] 28 | lddw %r1, 0x1122334455667788 29 | jne %r0, %r1, exit 30 | 31 | mov %r0, 0 32 | exit 33 | -- result 34 | 0x0 35 | -------------------------------------------------------------------------------- /tests/lock_cmpxchg32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | mov32 %r1, 0x876543210 7 | mov32 %r0, 0x12345678 8 | # Expected to fail 9 | lock cmpxchg32 [%r10-8], %r1 10 | # Test if %r0 contains 0x9abcdef0 11 | mov32 %r1, 0x9abcdef0 12 | jne %r0, %r1, exit 13 | # Test if [%r10-8] is unmodified 14 | ldxdw %r0, [%r10-8] 15 | lddw %r1, 0x123456789abcdef0 16 | jne %r0, %r1, exit 17 | 18 | lddw %r0, 0x123456789abcdef0 19 | stxdw [%r10-8], %r0 20 | mov32 %r1, 0x11223344 21 | # Expected to succeed 22 | lock cmpxchg32 [%r10-8], %r1 23 | # Test if %r0 contains 0x9abcdef0 24 | mov32 %r1, 0x9abcdef0 25 | jne %r0, %r1, exit 26 | 27 | # Test if [%r10-8] contains the expected value. 28 | ldxdw %r0, [%r10-8] 29 | lddw %r1, 0x1234567811223344 30 | jne %r0, %r1, exit 31 | 32 | mov %r0, 0 33 | exit 34 | -- result 35 | 0x0 36 | -------------------------------------------------------------------------------- /tests/lock_fetch_add.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | mov %r1, 1 7 | lock fetch add [%r10-8], %r1 8 | jne %r1, %r0, exit 9 | ldxdw %r1, [%r10-8] 10 | lddw %r0, 0x123456789abcdef1 11 | jne %r0, %r1, exit 12 | mov %r0, 0 13 | exit 14 | -- result 15 | 0x0 16 | -------------------------------------------------------------------------------- /tests/lock_fetch_add32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | mov %r1, 1 7 | lock fetch add32 [%r10-8], %r1 8 | jne32 %r1, %r0, exit 9 | ldxdw %r1, [%r10-8] 10 | lddw %r0, 0x123456789abcdef1 11 | jne %r0, %r1, exit 12 | mov %r0, 0 13 | exit 14 | -- result 15 | 0x0 16 | -------------------------------------------------------------------------------- /tests/lock_fetch_and.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | lddw %r1, 0x00ff00ff00ff00ff 7 | lock fetch and [%r10-8], %r1 8 | jne %r1, %r0, exit 9 | ldxdw %r0, [%r10-8] 10 | lddw %r1, 0x0034007800bc00f0 11 | jne %r0, %r1, exit 12 | mov %r0, 0 13 | exit 14 | -- result 15 | 0x0 16 | -------------------------------------------------------------------------------- /tests/lock_fetch_and32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x123456789abcdef0 5 | stxdw [%r10-8], %r0 6 | lddw %r1, 0x00ff00ff00ff00ff 7 | lock fetch and32 [%r10-8], %r1 8 | jne32 %r1, %r0, exit 9 | ldxdw %r0, [%r10-8] 10 | lddw %r1, 0x1234567800bc00f0 11 | jne %r0, %r1, exit 12 | mov %r0, 0 13 | exit 14 | -- result 15 | 0x0 16 | -------------------------------------------------------------------------------- /tests/lock_fetch_or.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x1100110011001100 5 | lddw %r1, 0x0011001100110011 6 | stxdw [%r10-8], %r0 7 | lock fetch or [%r10-8], %r1 8 | jne %r1, %r0, exit 9 | ldxdw %r0, [%r10-8] 10 | lddw %r1, 0x1111111111111111 11 | jne %r0, %r1, exit 12 | mov %r0, 0 13 | exit 14 | -- result 15 | 0 16 | -------------------------------------------------------------------------------- /tests/lock_fetch_or32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x1100110011001100 5 | lddw %r1, 0x0011001100110011 6 | stxdw [%r10-8], %r0 7 | lock fetch or32 [%r10-8], %r1 8 | jne32 %r1, %r0, exit 9 | ldxdw %r0, [%r10-8] 10 | # Only lower 4 bytes are modified 11 | lddw %r1, 0x1100110011111111 12 | jne %r0, %r1, exit 13 | mov %r0, 0 14 | exit 15 | -- result 16 | 0 17 | -------------------------------------------------------------------------------- /tests/lock_fetch_xor.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0xcccccccccccccccc 5 | lddw %r1, 0xffffffffffffffff 6 | stxdw [%r10-8], %r0 7 | lock fetch xor [%r10-8], %r1 8 | jne %r1, %r0, exit 9 | ldxdw %r0, [%r10-8] 10 | lddw %r1, 0x3333333333333333 11 | jne %r0, %r1, exit 12 | mov %r0, 0 13 | exit 14 | -- result 15 | 0 16 | -------------------------------------------------------------------------------- /tests/lock_fetch_xor32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0xcccccccccccccccc 5 | lddw %r1, 0xffffffffffffffff 6 | stxdw [%r10-8], %r0 7 | lock fetch xor32 [%r10-8], %r1 8 | jne32 %r1, %r0, exit 9 | ldxdw %r0, [%r10-8] 10 | lddw %r1, 0xcccccccc33333333 11 | jne %r0, %r1, exit 12 | mov %r0, 0 13 | exit 14 | -- result 15 | 0 16 | -------------------------------------------------------------------------------- /tests/lock_or.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x1100110011001100 5 | lddw %r1, 0x0011001100110011 6 | stxdw [%r10-8], %r0 7 | lock or [%r10-8], %r1 8 | ldxdw %r0, [%r10-8] 9 | lddw %r1, 0x1111111111111111 10 | jne %r0, %r1, exit 11 | mov %r0, 0 12 | exit 13 | -- result 14 | 0 15 | -------------------------------------------------------------------------------- /tests/lock_or32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x1100110011001100 5 | lddw %r1, 0x0011001100110011 6 | stxdw [%r10-8], %r0 7 | lock or32 [%r10-8], %r1 8 | ldxdw %r0, [%r10-8] 9 | # Only lower 4 bytes are modified 10 | lddw %r1, 0x1100110011111111 11 | jne %r0, %r1, exit 12 | mov %r0, 0 13 | exit 14 | -- result 15 | 0 16 | -------------------------------------------------------------------------------- /tests/lock_xchg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, 1 5 | # Write 0x1111111111111111 to [%r10-8] 6 | lddw %r1, 0x1111111111111111 7 | stxdw [%r10-8], %r1 8 | # Set the exchange value to 0x2222222222222222 9 | lddw %r1, 0x2222222222222222 10 | # After the exchange, %r1 should contain 0x1111111111111111 and 11 | # [%r10-8] should contain 0x2222222222222222 12 | lock xchg [%r10-8], %r1 13 | # Check that [%r10-8] contains 0x2222222222222222 14 | ldxdw %r2, [%r10-8] 15 | lddw %r0, 0x2222222222222222 16 | jne %r2, %r0, exit 17 | # Check that %r1 contains 0x1111111111111111 18 | lddw %r0, 0x1111111111111111 19 | jne %r1, %r0, exit 20 | mov %r0, 0 21 | exit 22 | -- result 23 | 0x0 24 | -------------------------------------------------------------------------------- /tests/lock_xchg32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, 1 5 | # Write 0x1111111111111111 to [%r10-8] 6 | lddw %r1, 0x1111111111111111 7 | stxdw [%r10-8], %r1 8 | # Set the exchange value to 0x2222222222222222 9 | lddw %r1, 0x2222222222222222 10 | # After the exchange, %r1 should contain 0x11111111 and 11 | # [%r10-8] should contain 0x1111111122222222 12 | lock xchg32 [%r10-8], %r1 13 | # Check that [%r10-8] contains 0x1111111122222222 14 | ldxdw %r2, [%r10-8] 15 | lddw %r0, 0x1111111122222222 16 | jne %r2, %r0, exit 17 | # Check that %r1 contains 0x11111111 18 | lddw %r0, 0x11111111 19 | jne %r1, %r0, exit 20 | mov %r0, 0 21 | exit 22 | -- result 23 | 0x0 24 | -------------------------------------------------------------------------------- /tests/lock_xor.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0xcccccccccccccccc 5 | lddw %r1, 0xffffffffffffffff 6 | stxdw [%r10-8], %r0 7 | lock xor [%r10-8], %r1 8 | ldxdw %r0, [%r10-8] 9 | lddw %r1, 0x3333333333333333 10 | jne %r0, %r1, exit 11 | mov %r0, 0 12 | exit 13 | -- result 14 | 0 15 | -------------------------------------------------------------------------------- /tests/lock_xor32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0xcccccccccccccccc 5 | lddw %r1, 0xffffffffffffffff 6 | stxdw [%r10-8], %r0 7 | lock xor32 [%r10-8], %r1 8 | ldxdw %r0, [%r10-8] 9 | lddw %r1, 0xcccccccc33333333 10 | jne %r0, %r1, exit 11 | mov %r0, 0 12 | exit 13 | -- result 14 | 0 15 | -------------------------------------------------------------------------------- /tests/lsh32-imm-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x11 5 | lsh32 %r0, 60 6 | exit 7 | -- result 8 | 0x10000000 9 | -------------------------------------------------------------------------------- /tests/lsh32-imm-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x11 5 | lsh32 %r0, -4 6 | exit 7 | -- result 8 | 0x10000000 9 | -------------------------------------------------------------------------------- /tests/lsh32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x11 5 | lsh32 %r0, 28 6 | exit 7 | -- result 8 | 0x10000000 9 | -------------------------------------------------------------------------------- /tests/lsh32-reg-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x11 5 | mov %r7, 60 6 | lsh32 %r0, %r7 7 | exit 8 | -- result 9 | 0x10000000 10 | -------------------------------------------------------------------------------- /tests/lsh32-reg-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x11 5 | mov %r7, -4 6 | lsh32 %r0, %r7 7 | exit 8 | -- result 9 | 0x10000000 10 | -------------------------------------------------------------------------------- /tests/lsh32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x11 5 | mov %r7, 28 6 | lsh32 %r0, %r7 7 | exit 8 | -- result 9 | 0x10000000 10 | -------------------------------------------------------------------------------- /tests/lsh64-imm-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x1 5 | lsh %r0, 68 6 | exit 7 | -- result 8 | 0x10 9 | -------------------------------------------------------------------------------- /tests/lsh64-imm-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x1 5 | lsh %r0, -60 6 | exit 7 | -- result 8 | 0x10 9 | -------------------------------------------------------------------------------- /tests/lsh64-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x1 5 | lsh %r0, 4 6 | exit 7 | -- result 8 | 0x10 9 | -------------------------------------------------------------------------------- /tests/lsh64-reg-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x1 5 | mov %r7, 68 6 | lsh %r0, %r7 7 | exit 8 | -- result 9 | 0x10 10 | -------------------------------------------------------------------------------- /tests/lsh64-reg-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x1 5 | mov %r7, -60 6 | lsh %r0, %r7 7 | exit 8 | -- result 9 | 0x10 10 | -------------------------------------------------------------------------------- /tests/lsh64-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x1 5 | mov %r7, 4 6 | lsh %r0, %r7 7 | exit 8 | -- result 9 | 0x10 10 | -------------------------------------------------------------------------------- /tests/mem-len.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, %r2 5 | exit 6 | -- mem 7 | 00 00 00 01 8 | 00 00 00 02 9 | -- no register offset 10 | -- result 11 | 0x8 12 | -------------------------------------------------------------------------------- /tests/mod-by-zero-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | mov32 %r1, 0 6 | mod32 %r0, %r1 7 | exit 8 | -- result 9 | 0x1 10 | -------------------------------------------------------------------------------- /tests/mod.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 5748 5 | mod32 %r0, 92 6 | # %r0 == 44 7 | jne %r0, 44, exit 8 | 9 | mov32 %r1, 13 10 | mod32 %r0, %r1 11 | # %r0 == 5 12 | 13 | exit 14 | -- result 15 | 0x5 16 | -------------------------------------------------------------------------------- /tests/mod32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x100000003 5 | mod32 %r0, 3 6 | exit 7 | -- result 8 | 0x0 9 | -------------------------------------------------------------------------------- /tests/mod64-by-zero-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | mov32 %r1, 0 6 | mod %r0, %r1 7 | exit 8 | -- result 9 | 0x1 10 | -------------------------------------------------------------------------------- /tests/mod64.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 0xb1858436 5 | lsh %r0, 32 6 | or %r0, 0x100dc5c8 7 | # %r0 == 0xb1858436100dc5c8 8 | 9 | mov32 %r1, 0xdde263e 10 | lsh %r1, 32 11 | or %r1, 0x3cbef7f3 12 | # %r1 == 0xdde263e3cbef7f3 13 | 14 | mod %r0, %r1 15 | # %r0 == 0xb1bb94b371a2664 16 | 17 | mod %r0, 0x658f1778 18 | # %r0 == 0x30ba5a04 19 | 20 | exit 21 | -- result 22 | 0x30ba5a04 23 | -------------------------------------------------------------------------------- /tests/mov.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Alan Jowett 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r1, 2 5 | mov32 %r0, %r1 6 | jne %r0, 2, exit 7 | lddw %r2, 0xFFFFFF00000002 8 | mov32 %r0, %r2 9 | jne %r0, 2, exit 10 | mov32 %r0, 1 11 | exit 12 | -- result 13 | 0x1 14 | -------------------------------------------------------------------------------- /tests/mov64-sign-extend.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, -10 5 | exit 6 | -- result 7 | 0xFFFFFFFFFFFFFFF6 -------------------------------------------------------------------------------- /tests/mov64.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r1, 1 5 | mov %r0, %r1 6 | mov %r0, %r0 7 | exit 8 | -- result 9 | 0x1 10 | -------------------------------------------------------------------------------- /tests/movsx1632-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r1, 0x0123456789abcdef 5 | movsx1632 %r0, %r1 6 | exit 7 | -- result 8 | 0xffffcdef 9 | -------------------------------------------------------------------------------- /tests/movsx1664-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r1, 0x0123456789abcdef 5 | movsx1664 %r0, %r1 6 | exit 7 | -- result 8 | 0xffffffffffffcdef 9 | -------------------------------------------------------------------------------- /tests/movsx3264-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r1, 0x0123456789abcdef 5 | movsx3264 %r0, %r1 6 | exit 7 | -- result 8 | 0xffffffff89abcdef 9 | -------------------------------------------------------------------------------- /tests/movsx832-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r1, 0x0123456789abcdef 5 | movsx832 %r0, %r1 6 | exit 7 | -- result 8 | 0xffffffef 9 | -------------------------------------------------------------------------------- /tests/movsx864-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r1, 0x0123456789abcdef 5 | movsx864 %r0, %r1 6 | exit 7 | -- result 8 | 0xffffffffffffffef 9 | -------------------------------------------------------------------------------- /tests/mul32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 3 5 | mul32 %r0, 4 6 | exit 7 | -- result 8 | 0xc 9 | -------------------------------------------------------------------------------- /tests/mul32-intmin-by-negone-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, 0x80000000 5 | mul32 %r0, -1 6 | exit 7 | -- result 8 | 0x80000000 9 | -------------------------------------------------------------------------------- /tests/mul32-intmin-by-negone-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, 0x80000000 5 | mov %r1, -1 6 | mul32 %r0, %r1 7 | exit 8 | -- result 9 | 0x80000000 10 | -------------------------------------------------------------------------------- /tests/mul32-reg-overflow.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x40000001 5 | mov %r1, 4 6 | mul32 %r0, %r1 7 | exit 8 | -- result 9 | 0x4 10 | -------------------------------------------------------------------------------- /tests/mul32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 3 5 | mov %r1, 4 6 | mul32 %r0, %r1 7 | exit 8 | -- result 9 | 0xc 10 | -------------------------------------------------------------------------------- /tests/mul64-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x40000001 5 | mul %r0, 4 6 | exit 7 | -- result 8 | 0x100000004 9 | -------------------------------------------------------------------------------- /tests/mul64-intmin-by-negone-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | mul %r0, -1 6 | exit 7 | -- mem 8 | 00 00 00 00 00 00 00 80 9 | -- result 10 | 0x8000000000000000 11 | -------------------------------------------------------------------------------- /tests/mul64-intmin-by-negone-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | mov %r1, -1 6 | mul %r0, %r1 7 | exit 8 | -- mem 9 | 00 00 00 00 00 00 00 80 10 | -- result 11 | 0x8000000000000000 12 | -------------------------------------------------------------------------------- /tests/mul64-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x40000001 5 | mov %r1, 4 6 | mul %r0, %r1 7 | exit 8 | -- result 9 | 0x100000004 10 | -------------------------------------------------------------------------------- /tests/neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x100000002 5 | neg32 %r0 6 | exit 7 | -- result 8 | 0xfffffffe 9 | -------------------------------------------------------------------------------- /tests/neg32-intmin-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | lddw %r0, 0x80000000 5 | neg32 %r0 6 | exit 7 | -- result 8 | 0x80000000 9 | -------------------------------------------------------------------------------- /tests/neg32-intmin-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, 0x80000000 5 | neg32 %r0 6 | exit 7 | -- result 8 | 0x80000000 9 | -------------------------------------------------------------------------------- /tests/neg64-intmin-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | neg %r0 6 | exit 7 | -- mem 8 | 00 00 00 00 00 00 00 80 9 | -- result 10 | 0x8000000000000000 11 | -------------------------------------------------------------------------------- /tests/neg64-intmin-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | mov %r1, -1 6 | neg %r0 7 | exit 8 | -- mem 9 | 00 00 00 00 00 00 00 80 10 | -- result 11 | 0x8000000000000000 12 | -------------------------------------------------------------------------------- /tests/neg64.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 2 5 | neg %r0 6 | exit 7 | -- result 8 | 0xfffffffffffffffe 9 | -------------------------------------------------------------------------------- /tests/prime.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Compiled by Clang 4 | -- c 5 | #include 6 | #include 7 | 8 | uint64_t entry(uint64_t arg) 9 | { 10 | int i = 0; 11 | for (i = 2; i < arg; i++) { 12 | if (arg % i == 0) { 13 | return false; 14 | } 15 | } 16 | return true; 17 | } 18 | -- asm 19 | mov %r1, 67 20 | mov %r0, 0x1 21 | mov %r2, 0x2 22 | jgt %r1, 0x2, L3 23 | L1: 24 | ja exit 25 | L2: 26 | add %r2, 0x1 27 | mov %r0, 0x1 28 | jge %r2, %r1, exit 29 | L3: 30 | mov %r3, %r1 31 | div %r3, %r2 32 | mul %r3, %r2 33 | mov %r4, %r1 34 | sub %r4, %r3 35 | mov %r0, 0x0 36 | jne %r4, 0x0, L2 37 | exit 38 | -- result 39 | 0x1 40 | -------------------------------------------------------------------------------- /tests/rsh32-imm-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | sub %r0, 1 6 | rsh32 %r0, 40 7 | exit 8 | -- result 9 | 0x00ffffff 10 | -------------------------------------------------------------------------------- /tests/rsh32-imm-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | sub %r0, 1 6 | rsh32 %r0, -24 7 | exit 8 | -- result 9 | 0x00ffffff 10 | -------------------------------------------------------------------------------- /tests/rsh32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | sub %r0, 1 6 | rsh32 %r0, 8 7 | exit 8 | -- result 9 | 0x00ffffff 10 | -------------------------------------------------------------------------------- /tests/rsh32-reg-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | sub %r0, 1 6 | mov %r7, 40 7 | rsh32 %r0, %r7 8 | exit 9 | -- result 10 | 0x00ffffff 11 | -------------------------------------------------------------------------------- /tests/rsh32-reg-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | sub %r0, 1 6 | mov %r7, -24 7 | rsh32 %r0, %r7 8 | exit 9 | -- result 10 | 0x00ffffff 11 | -------------------------------------------------------------------------------- /tests/rsh32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0 5 | sub %r0, 1 6 | mov %r7, 8 7 | rsh32 %r0, %r7 8 | exit 9 | -- result 10 | 0x00ffffff 11 | -------------------------------------------------------------------------------- /tests/rsh64-imm-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x10 5 | rsh %r0, 68 6 | exit 7 | -- result 8 | 0x1 9 | -------------------------------------------------------------------------------- /tests/rsh64-imm-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x10 5 | rsh %r0, -60 6 | exit 7 | -- result 8 | 0x1 9 | -------------------------------------------------------------------------------- /tests/rsh64-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x10 5 | rsh %r0, 4 6 | exit 7 | -- result 8 | 0x1 9 | -------------------------------------------------------------------------------- /tests/rsh64-reg-high.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x10 5 | mov %r7, 68 6 | rsh %r0, %r7 7 | exit 8 | -- result 9 | 0x1 10 | -------------------------------------------------------------------------------- /tests/rsh64-reg-neg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x10 5 | mov %r7, -60 6 | rsh %r0, %r7 7 | exit 8 | -- result 9 | 0x1 10 | -------------------------------------------------------------------------------- /tests/rsh64-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0x10 5 | mov %r7, 4 6 | rsh %r0, %r7 7 | exit 8 | -- result 9 | 0x1 10 | -------------------------------------------------------------------------------- /tests/sdiv32-by-zero-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, 1 5 | sdiv32 %r0, 0 6 | exit 7 | -- result 8 | 0x0 9 | -------------------------------------------------------------------------------- /tests/sdiv32-by-zero-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | mov32 %r1, 0 6 | sdiv32 %r0, %r1 7 | exit 8 | -- result 9 | 0x0 10 | -------------------------------------------------------------------------------- /tests/sdiv32-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x10000000c 5 | sdiv32 %r0, -4 6 | exit 7 | -- result 8 | 0xfffffffd 9 | -------------------------------------------------------------------------------- /tests/sdiv32-intmin-by-negone-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, 0x80000000 5 | sdiv32 %r0, -1 6 | exit 7 | -- result 8 | 0x80000000 9 | -------------------------------------------------------------------------------- /tests/sdiv32-intmin-by-negone-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, 0x80000000 5 | mov32 %r1, -1 6 | sdiv32 %r0, %r1 7 | exit 8 | -- result 9 | 0x80000000 10 | -------------------------------------------------------------------------------- /tests/sdiv32-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x10000000c 5 | mov %r1, -4 6 | sdiv32 %r0, %r1 7 | exit 8 | -- result 9 | 0xfffffffd 10 | -------------------------------------------------------------------------------- /tests/sdiv64-by-zero-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, 1 5 | sdiv %r0, 0 6 | exit 7 | -- result 8 | 0x0 9 | -------------------------------------------------------------------------------- /tests/sdiv64-by-zero-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r0, 1 5 | mov32 %r1, 0 6 | sdiv %r0, %r1 7 | exit 8 | -- result 9 | 0x0 10 | -------------------------------------------------------------------------------- /tests/sdiv64-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0xc 5 | lsh %r0, 32 6 | sdiv %r0, -4 7 | exit 8 | -- result 9 | 0xfffffffd00000000 10 | -------------------------------------------------------------------------------- /tests/sdiv64-intmin-by-negone-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | sdiv %r0, -1 6 | exit 7 | -- mem 8 | 00 00 00 00 00 00 00 80 9 | -- result 10 | 0x8000000000000000 11 | -------------------------------------------------------------------------------- /tests/sdiv64-intmin-by-negone-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | mov %r1, -1 6 | sdiv %r0, %r1 7 | exit 8 | -- mem 9 | 00 00 00 00 00 00 00 80 10 | -- result 11 | 0x8000000000000000 12 | -------------------------------------------------------------------------------- /tests/sdiv64-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0xc 5 | lsh %r0, 32 6 | mov %r1, -4 7 | sdiv %r0, %r1 8 | exit 9 | -- result 10 | 0xfffffffd00000000 11 | -------------------------------------------------------------------------------- /tests/smod32-intmin-by-negone-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, 0x80000000 5 | smod32 %r0, -1 6 | exit 7 | -- result 8 | 0x0 9 | -------------------------------------------------------------------------------- /tests/smod32-intmin-by-negone-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, 0x80000000 5 | mov32 %r1, -1 6 | smod32 %r0, %r1 7 | exit 8 | -- result 9 | 0x0 10 | -------------------------------------------------------------------------------- /tests/smod32-neg-by-neg-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, -13 5 | smod32 %r0, -3 6 | exit 7 | -- result 8 | 0xffffffff 9 | -------------------------------------------------------------------------------- /tests/smod32-neg-by-neg-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, -13 5 | mov32 %r1, -3 6 | smod32 %r0, %r1 7 | exit 8 | -- result 9 | 0xffffffff 10 | -------------------------------------------------------------------------------- /tests/smod32-neg-by-pos-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, -13 5 | smod32 %r0, 4 6 | exit 7 | -- result 8 | 0xffffffff 9 | -------------------------------------------------------------------------------- /tests/smod32-neg-by-pos-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, -13 5 | mov32 %r1, 4 6 | smod32 %r0, %r1 7 | exit 8 | -- result 9 | 0xffffffff 10 | -------------------------------------------------------------------------------- /tests/smod32-neg-by-zero-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, -10 5 | smod32 %r0, 0 6 | exit 7 | -- result 8 | 0xFFFFFFF6 9 | -------------------------------------------------------------------------------- /tests/smod32-neg-by-zero-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, -10 5 | mov32 %r1, 0 6 | smod32 %r0, %r1 7 | exit 8 | -- result 9 | 0xFFFFFFF6 10 | -------------------------------------------------------------------------------- /tests/smod32-pos-by-neg-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, 13 5 | smod32 %r0, -3 6 | exit 7 | -- result 8 | 0x1 9 | -------------------------------------------------------------------------------- /tests/smod32-pos-by-neg-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov32 %r0, 13 5 | mov32 %r1, -3 6 | smod32 %r0, %r1 7 | exit 8 | -- result 9 | 0x1 10 | -------------------------------------------------------------------------------- /tests/smod64-intmin-by-negone-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | smod %r0, -1 6 | exit 7 | -- mem 8 | 00 00 00 00 00 00 00 80 9 | -- result 10 | 0x0 11 | -------------------------------------------------------------------------------- /tests/smod64-intmin-by-negone-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | ldxdw %r0, [%r1] 5 | mov %r1, -1 6 | smod %r0, %r1 7 | exit 8 | -- mem 9 | 00 00 00 00 00 00 00 80 10 | -- result 11 | 0x0 12 | -------------------------------------------------------------------------------- /tests/smod64-neg-by-neg-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, -13 5 | smod %r0, -3 6 | exit 7 | -- result 8 | 0xffffffffffffffff 9 | -------------------------------------------------------------------------------- /tests/smod64-neg-by-neg-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, -13 5 | mov %r1, -3 6 | smod %r0, %r1 7 | exit 8 | -- result 9 | 0xffffffffffffffff 10 | -------------------------------------------------------------------------------- /tests/smod64-neg-by-pos-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, -13 5 | smod %r0, 4 6 | exit 7 | -- result 8 | 0xffffffffffffffff 9 | -------------------------------------------------------------------------------- /tests/smod64-neg-by-pos-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, -13 5 | mov %r1, 4 6 | smod %r0, %r1 7 | exit 8 | -- result 9 | 0xffffffffffffffff 10 | -------------------------------------------------------------------------------- /tests/smod64-neg-by-zero-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, -10 5 | smod %r0, 0 6 | exit 7 | -- result 8 | 0xFFFFFFFFFFFFFFF6 9 | -------------------------------------------------------------------------------- /tests/smod64-neg-by-zero-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, -10 5 | mov %r1, 0 6 | smod %r0, %r1 7 | exit 8 | -- result 9 | 0xFFFFFFFFFFFFFFF6 10 | -------------------------------------------------------------------------------- /tests/smod64-pos-by-neg-imm.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, 13 5 | smod %r0, -3 6 | exit 7 | -- result 8 | 0x1 9 | -------------------------------------------------------------------------------- /tests/smod64-pos-by-neg-reg.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Dave Thaler 2 | # SPDX-License-Identifier: MIT 3 | -- asm 4 | mov %r0, 13 5 | mov %r1, -3 6 | smod %r0, %r1 7 | exit 8 | -- result 9 | 0x1 10 | -------------------------------------------------------------------------------- /tests/stack.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r1, 51 5 | 6 | # Create lookup table 7 | stdw [%r10-16], 0xab 8 | stdw [%r10-8], 0xcd 9 | 10 | # Load lookup[%r1 % 2] 11 | and %r1, 1 12 | lsh %r1, 3 13 | mov %r2, %r10 14 | add %r2, %r1 15 | ldxdw %r0, [%r2-16] 16 | 17 | exit 18 | -- result 19 | 0xcd 20 | -------------------------------------------------------------------------------- /tests/stb.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | stb [%r1+2], 0x11 5 | ldxb %r0, [%r1+2] 6 | exit 7 | -- mem 8 | aa bb ff cc dd 9 | -- result 10 | 0x11 11 | -------------------------------------------------------------------------------- /tests/stdw.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | stdw [%r1+2], 0x44332211 5 | ldxdw %r0, [%r1+2] 6 | exit 7 | -- mem 8 | aa bb ff ff ff ff ff ff ff ff cc dd 9 | -- result 10 | 0x0000000044332211 11 | -------------------------------------------------------------------------------- /tests/sth.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | sth [%r1+2], 0x2211 5 | ldxh %r0, [%r1+2] 6 | exit 7 | -- mem 8 | aa bb ff ff cc dd 9 | -- result 10 | 0x2211 11 | -------------------------------------------------------------------------------- /tests/stw.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | stw [%r1+2], 0x44332211 5 | ldxw %r0, [%r1+2] 6 | exit 7 | -- mem 8 | aa bb ff ff ff ff cc dd 9 | -- result 10 | 0x44332211 11 | -------------------------------------------------------------------------------- /tests/stxb-all.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, 0xf0 5 | mov %r2, 0xf2 6 | mov %r3, 0xf3 7 | mov %r4, 0xf4 8 | mov %r5, 0xf5 9 | mov %r6, 0xf6 10 | mov %r7, 0xf7 11 | mov %r8, 0xf8 12 | stxb [%r1], %r0 13 | stxb [%r1+1], %r2 14 | stxb [%r1+2], %r3 15 | stxb [%r1+3], %r4 16 | stxb [%r1+4], %r5 17 | stxb [%r1+5], %r6 18 | stxb [%r1+6], %r7 19 | stxb [%r1+7], %r8 20 | ldxdw %r0, [%r1] 21 | be64 %r0 22 | exit 23 | -- mem 24 | ff ff ff ff ff ff ff ff 25 | -- result 26 | 0xf0f2f3f4f5f6f7f8 27 | -------------------------------------------------------------------------------- /tests/stxb-all2.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, %r1 5 | mov %r1, 0xf1 6 | mov %r9, 0xf9 7 | stxb [%r0], %r1 8 | stxb [%r0+1], %r9 9 | ldxh %r0, [%r0] 10 | be16 %r0 11 | exit 12 | -- mem 13 | ff ff 14 | -- result 15 | 0xf1f9 16 | -------------------------------------------------------------------------------- /tests/stxb-chain.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r0, %r1 5 | 6 | ldxb %r9, [%r0+0] 7 | stxb [%r0+1], %r9 8 | 9 | ldxb %r8, [%r0+1] 10 | stxb [%r0+2], %r8 11 | 12 | ldxb %r7, [%r0+2] 13 | stxb [%r0+3], %r7 14 | 15 | ldxb %r6, [%r0+3] 16 | stxb [%r0+4], %r6 17 | 18 | ldxb %r5, [%r0+4] 19 | stxb [%r0+5], %r5 20 | 21 | ldxb %r4, [%r0+5] 22 | stxb [%r0+6], %r4 23 | 24 | ldxb %r3, [%r0+6] 25 | stxb [%r0+7], %r3 26 | 27 | ldxb %r2, [%r0+7] 28 | stxb [%r0+8], %r2 29 | 30 | ldxb %r1, [%r0+8] 31 | stxb [%r0+9], %r1 32 | 33 | ldxb %r0, [%r0+9] 34 | exit 35 | -- mem 36 | 2a 00 00 00 00 00 00 00 00 00 37 | -- result 38 | 0x2a 39 | -------------------------------------------------------------------------------- /tests/stxb.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r2, 0x11 5 | stxb [%r1+2], %r2 6 | ldxb %r0, [%r1+2] 7 | exit 8 | -- mem 9 | aa bb ff cc dd 10 | -- result 11 | 0x11 12 | -------------------------------------------------------------------------------- /tests/stxdw.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov %r2, 0x88776655 5 | lsh %r2, 32 6 | or %r2, 0x44332211 7 | stxdw [%r1+2], %r2 8 | ldxdw %r0, [%r1+2] 9 | exit 10 | -- mem 11 | aa bb ff ff ff ff ff ff ff ff cc dd 12 | -- result 13 | 0x8877665544332211 14 | -------------------------------------------------------------------------------- /tests/stxh.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r2, 0x2211 5 | stxh [%r1+2], %r2 6 | ldxh %r0, [%r1+2] 7 | exit 8 | -- mem 9 | aa bb ff ff cc dd 10 | -- result 11 | 0x2211 12 | -------------------------------------------------------------------------------- /tests/stxw.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | mov32 %r2, 0x44332211 5 | stxw [%r1+2], %r2 6 | ldxw %r0, [%r1+2] 7 | exit 8 | -- mem 9 | aa bb ff ff ff ff cc dd 10 | -- result 11 | 0x44332211 12 | -------------------------------------------------------------------------------- /tests/subnet.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | # Compiled by Clang 4 | # Check that the ipv4_dst is in 192.168.1.0/24 5 | -- c 6 | #include 7 | 8 | #define NETMASK 0xffffff00 9 | #define SUBNET 0xc0a80100 10 | 11 | struct eth_hdr { 12 | uint8_t eth_src[6]; 13 | uint8_t eth_dst[6]; 14 | uint16_t eth_type; 15 | }; 16 | 17 | struct vlan_hdr { 18 | uint16_t vlan; 19 | uint16_t eth_type; 20 | }; 21 | 22 | struct ipv4_hdr { 23 | uint8_t ver_ihl; 24 | uint8_t tos; 25 | uint16_t total_length; 26 | uint16_t id; 27 | uint16_t frag; 28 | uint8_t ttl; 29 | uint8_t proto; 30 | uint16_t csum; 31 | uint32_t src; 32 | uint32_t dst; 33 | }; 34 | 35 | uint64_t entry(void *mem) 36 | { 37 | struct eth_hdr *eth_hdr = (void *)mem; 38 | uint16_t eth_type; 39 | void *next = eth_hdr; 40 | 41 | if (eth_hdr->eth_type == __builtin_bswap16(0x8100)) { 42 | struct vlan_hdr *vlan_hdr = (void *)(eth_hdr + 1); 43 | eth_type = vlan_hdr->eth_type; 44 | next = vlan_hdr + 1; 45 | } else { 46 | eth_type = eth_hdr->eth_type; 47 | next = eth_hdr + 1; 48 | } 49 | 50 | if (eth_type == __builtin_bswap16(0x0800)) { 51 | struct ipv4_hdr *ipv4_hdr = next; 52 | if ((ipv4_hdr->dst & __builtin_bswap32(NETMASK)) == __builtin_bswap32(SUBNET)) { 53 | return 1; 54 | } 55 | } 56 | 57 | return 0; 58 | } 59 | -- asm 60 | mov %r2, 0xe 61 | ldxh %r3, [%r1+12] 62 | jne %r3, 0x81, L1 63 | mov %r2, 0x12 64 | ldxh %r3, [%r1+16] 65 | and %r3, 0xffff 66 | L1: 67 | jne %r3, 0x8, L2 68 | add %r1, %r2 69 | mov %r0, 0x1 70 | ldxw %r1, [%r1+16] 71 | and %r1, 0xffffff 72 | jeq %r1, 0x1a8c0, exit 73 | L2: 74 | mov %r0, 0x0 75 | exit 76 | -- mem 77 | 00 00 c0 9f a0 97 00 a0 78 | cc 3b bf fa 08 00 45 10 79 | 00 3c 46 3c 40 00 40 06 80 | 73 1c c0 a8 01 02 c0 a8 81 | 01 01 06 0e 00 17 99 c5 82 | a0 ec 00 00 00 00 a0 02 83 | 7d 78 e0 a3 00 00 02 04 84 | 05 b4 04 02 08 0a 00 9c 85 | 27 24 00 00 00 00 01 03 86 | 03 00 87 | -- result 88 | 0x1 89 | -------------------------------------------------------------------------------- /tests/swap16.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x8877665544332211 5 | swap16 %r0 6 | exit 7 | -- result 8 | 0x1122 9 | -------------------------------------------------------------------------------- /tests/swap32.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x8877665544332211 5 | swap32 %r0 6 | exit 7 | -- result 8 | 0x11223344 9 | -------------------------------------------------------------------------------- /tests/swap64.data: -------------------------------------------------------------------------------- 1 | # Copyright (c) Big Switch Networks, Inc 2 | # SPDX-License-Identifier: Apache-2.0 3 | -- asm 4 | lddw %r0, 0x8877665544332211 5 | swap64 %r0 6 | exit 7 | -- result 8 | 0x1122334455667788 9 | --------------------------------------------------------------------------------