CAPI=2:
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
name: "lowrisc:ibex:ibex_simple_system"
description: "Generic simple system for running binaries on ibex using verilator"
filesets:
  files_simple_system:
    depend:
      - lowrisc:ibex:ibex_simple_system_core
    files:
      - tool_verilator ? (ibex_simple_system_main.cc)
    file_type: cppSource

parameters:
  RV32E:
    datatype: int
    paramtype: vlogparam
    default: 0
    description: "Enable the E ISA extension (reduced register set) [0/1]"

  RV32M:
    datatype: str
    default: ibex_pkg::RV32MFast
    paramtype: vlogdefine
    description: "RV32M implementation parameter enum. See the ibex_pkg::rv32m_e enum in ibex_pkg.sv for permitted values."

  RV32B:
    datatype: str
    default: ibex_pkg::RV32BNone
    paramtype: vlogdefine
    description: "Bitmanip implementation parameter enum. See the ibex_pkg::rv32b_e enum in ibex_pkg.sv for permitted values."

  RV32ZC:
    datatype: str
    default: ibex_pkg::RV32ZcaZcbZcmp
    paramtype: vlogdefine
    description: "Compressed instructions parameter enum. See the ibex_pkg::rv32zc_e enum in ibex_pkg.sv for permitted values."

  RegFile:
    datatype: str
    default: ibex_pkg::RegFileFF
    paramtype: vlogdefine
    description: "Register file implementation parameter enum. See the ibex_pkg::regfile_e enum in ibex_pkg.sv for permitted values."

  INSTR_CYCLE_DELAY:
    datatype: int
    default: 0
    paramtype: vlogdefine
    description: "Number of cycles to delay the instruction RAM access. This is on top of the single-cycle access that the RAM requires."

  ICache:
    datatype: int
    default: 0
    paramtype: vlogparam
    description: "Enable instruction cache"

  ICacheECC:
    datatype: int
    default: 0
    paramtype: vlogparam
    description: "Enable ECC protection in instruction cache"

  SRAMInitFile:
    datatype: str
    paramtype: vlogparam
    description: "Path to a vmem file to initialize the RAM with"

  BranchTargetALU:
    datatype: int
    paramtype: vlogparam
    default: 0
    description: "Enables separate branch target ALU (increasing branch performance EXPERIMENTAL)"

  WritebackStage:
    datatype: int
    paramtype: vlogparam
    default: 0
    description: "Enables third pipeline stage (EXPERIMENTAL)"

  SecureIbex:
    datatype: int
    default: 0
    paramtype: vlogparam
    description: "Enables security hardening features (EXPERIMENTAL) [0/1]"

  ICacheScramble:
    datatype: int
    default: 0
    paramtype: vlogparam
    description: "Enables ICache scrambling feature (EXPERIMENTAL) [0/1]"

  BranchPredictor:
    datatype: int
    paramtype: vlogparam
    default: 0
    description: "Enables static branch prediction (EXPERIMENTAL)"

  DbgTriggerEn:
    datatype: int
    default: 0
    paramtype: vlogparam
    description: "Enable support for debug triggers. "

  PMPEnable:
    datatype: int
    default: 0
    paramtype: vlogparam
    description: "Enable PMP"

  PMPGranularity:
    datatype: int
    default: 0
    paramtype: vlogparam
    description: "Granularity of NAPOT range, 0 = 4 byte, 1 = byte, 2 = 16 byte, 3 = 32 byte etc"

  PMPNumRegions:
    datatype: int
    default: 4
    paramtype: vlogparam
    description: "Number of PMP regions"

  MHPMCounterNum:
    datatype: int
    paramtype: vlogparam
    default: 0
    description: Number of performance monitor event counters [0/29]

  MHPMCounterWidth:
    datatype: int
    paramtype: vlogparam
    default: 40
    description: Bit width of performance monitor event counters [32/64]

targets:
  default: &default_target
    filesets:
      - files_simple_system
    toplevel: ibex_simple_system
    parameters:
      - RV32E
      - RV32M
      - RV32B
      - RV32ZC
      - RegFile
      - INSTR_CYCLE_DELAY
      - ICache
      - ICacheScramble
      - ICacheECC
      - BranchTargetALU
      - WritebackStage
      - SecureIbex
      - BranchPredictor
      - DbgTriggerEn
      - PMPEnable
      - PMPGranularity
      - PMPNumRegions
      - MHPMCounterNum
      - MHPMCounterWidth
      - SRAMInitFile

  lint:
    <<: *default_target
    default_tool: verilator
    tools:
      verilator:
        mode: lint-only
        verilator_options:
          - "-Wall"
          # RAM primitives wider than 64bit (required for ECC) fail to build in
          # Verilator without increasing the unroll count (see Verilator#1266)
          - "--unroll-count 72"

  sim:
    <<: *default_target
    default_tool: verilator
    tools:
      vcs:
        vcs_options:
          - '-xlrm uniq_prior_final'
          - '-debug_access+r'
      verilator:
        mode: cc
        verilator_options:
          # Disabling tracing reduces compile times but doesn't have a
          # huge influence on runtime performance.
          - '--trace'
          - '--trace-fst' # this requires -DVM_TRACE_FMT_FST in CFLAGS below!
          - '--trace-structs'
          - '--trace-params'
          - '--trace-max-array 1024'
          - '-CFLAGS "-std=c++17 -Wall -DVM_TRACE_FMT_FST -DTOPLEVEL_NAME=ibex_simple_system -g"'
          - '-LDFLAGS "-pthread -lutil -lelf"'
          - "-Wall"
          # RAM primitives wider than 64bit (required for ECC) fail to build in
          # Verilator without increasing the unroll count (see Verilator#1266)
          - "--unroll-count 72"
