name: 'Processor Check'

on:
  push:
    branches:
      - main
    paths:
      - 'rtl/**'
      - 'sw/**'
      - 'sim/**'
      - '.github/workflows/Processor.yml'
  pull_request:
    paths:
      - 'rtl/**'
      - 'sw/**'
      - 'sim/**'
      - '.github/workflows/Processor.yml'
  workflow_dispatch:

jobs:

  sim_default_tb:
    runs-on: ubuntu-latest
    name: 'processor simulation'
    strategy:
      fail-fast: false
      matrix:
        example:
          - processor_check
          - hello_world

    steps:

    - name: '🧰 Repository Checkout'
      uses: actions/checkout@v6

    - name: '📦 Install xPack RISC-V GCC'
      run: |
        wget -q https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v15.2.0-1/xpack-riscv-none-elf-gcc-15.2.0-1-linux-x64.tar.gz
        mkdir $GITHUB_WORKSPACE/riscv-gcc
        tar -xzf xpack-riscv-none-elf-gcc-15.2.0-1-linux-x64.tar.gz -C $GITHUB_WORKSPACE/riscv-gcc
        echo $GITHUB_WORKSPACE/riscv-gcc/xpack-riscv-none-elf-gcc-15.2.0-1/bin >> $GITHUB_PATH

    - name: '📦 Install GHDL'
      uses: ghdl/setup-ghdl@v1
      with:
        version: nightly
        backend: mcode

    - name: '🔍 Check tools'
      run: |
        riscv-none-elf-gcc -v
        ghdl -v

    - name: '⚙️ Build software framework tests'
      run: |
        make RISCV_PREFIX=riscv-none-elf- -C sw/example/processor_check check
        make RISCV_PREFIX=riscv-none-elf- -C sw/example clean_all exe
        make RISCV_PREFIX=riscv-none-elf- -C sw/bootloader clean_all info bootloader

    - name: '🚧 Compile executable and run simulation'
      run: |
        make -C sw/example/${{ matrix.example }} \
        RISCV_PREFIX=riscv-none-elf- \
        USER_FLAGS+="-DUART0_SIM_MODE -DUART1_SIM_MODE" \
        clean_all \
        info \
        all \
        sim-check
