Skip to content

Commit

Permalink
Remove ISA, ISA_ISS from Makefile
Browse files Browse the repository at this point in the history
Move their calculation into the Python scripts, which means that we
don't have to make sure everything is kept in sync.
  • Loading branch information
rswarbrick authored and ctopal committed Apr 27, 2022
1 parent b63ab3b commit ecdb1e0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 24 deletions.
18 changes: 7 additions & 11 deletions dv/uvm/core_ibex/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ COV := 0
SIMULATOR := vcs
# ISS (spike, ovpsim)
ISS := spike
# ISA
ISA := rv32imcb
ISA_ISS := rv32imc_Zba_Zbb_Zbc_Zbs_Xbitmanip
# Test name (default: full regression)
TEST := all
TESTLIST := riscv_dv_extension/testlist.yaml
Expand Down Expand Up @@ -102,7 +99,6 @@ clean:

# Options used for privileged CSR test generation
CSR_OPTS=--csr_yaml=${CSR_FILE} \
--isa="${ISA}" \
--end_signature_addr=${SIGNATURE_ADDR}

# This is a list of directories that are automatically generated by some
Expand Down Expand Up @@ -198,7 +194,7 @@ ts-dirs := $(foreach ts,$(tests-and-seeds),$(RUN-DIR)/$(ts)/)
# This depends on the vendored in code in $(GEN_DIR). It also depends on the
# values of the following Makefile variables (we want to regenerate things if,
# for example, the simulator changes).
instr-gen-build-var-deps := SIMULATOR ISA CSR_OPTS \
instr-gen-build-var-deps := SIMULATOR CSR_OPTS \
SIGNATURE_ADDR PMP_REGIONS PMP_GRANULARITY
# To achieve this variable tracking, we dump each of the variables to a Makefile
# fragment and try to load it up the next time around. This done with the
Expand Down Expand Up @@ -241,9 +237,9 @@ $(BUILD-DIR)/instr-gen/.compile.stamp: \
$(verb)scripts/build-instr-gen.py \
$(verb-arg) \
--simulator $(SIMULATOR) \
--ibex-config $(IBEX_CONFIG) \
--end-signature-addr $(SIGNATURE_ADDR) \
--output $(BUILD-DIR)/instr-gen \
--isa $(ISA)
--output $(BUILD-DIR)/instr-gen
$(call dump-vars,$(ig-build-vars-path),gen,$(instr-gen-build-var-deps))
@touch $@

Expand All @@ -266,7 +262,7 @@ $(test-asms): \
--end-signature-addr $(SIGNATURE_ADDR) \
--output-dir $(@D) \
--gen-build-dir $(BUILD-DIR)/instr-gen \
--isa $(ISA) \
--ibex-config $(IBEX_CONFIG) \
--test-dot-seed $* \
--pmp-num-regions $(PMP_REGIONS) \
--pmp-granularity $(PMP_GRANULARITY)
Expand Down Expand Up @@ -294,7 +290,7 @@ $(test-bins): \
$(verb-arg) \
--input $(RUN-DIR)/$*/test.S \
--output $@ \
--isa $(ISA) \
--ibex-config $(IBEX_CONFIG) \
--test-dot-seed $*

.PHONY: instr_gen_compile
Expand All @@ -315,10 +311,10 @@ $(iss-sim-logs): \
$(RUN-DIR)/%/test.bin scripts/run-iss.py
$(verb)scripts/run-iss.py \
$(verb-arg) \
--ibex-config $(IBEX_CONFIG) \
--iss=$(ISS) \
--input=$(RUN-DIR)/$*/test.o \
--output=$@ \
--isa=$(ISA_ISS)
--output=$@

.PHONY: iss_run
iss_run: $(iss-sim-logs)
Expand Down
8 changes: 5 additions & 3 deletions dv/uvm/core_ibex/scripts/build-instr-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shutil
import sys

from scripts_lib import run_one, start_riscv_dv_run_cmd
from scripts_lib import run_one, start_riscv_dv_run_cmd, get_isas_for_config


def main() -> int:
Expand All @@ -18,7 +18,7 @@ def main() -> int:
parser.add_argument('--simulator', required=True)
parser.add_argument('--end-signature-addr', required=True)
parser.add_argument('--output', required=True)
parser.add_argument('--isa', required=True)
parser.add_argument('--ibex-config', required=True)

args = parser.parse_args()

Expand All @@ -32,11 +32,13 @@ def main() -> int:

os.makedirs(args.output, exist_ok=True)

isa, iss_isa = get_isas_for_config(args.ibex_config)

cmd = (start_riscv_dv_run_cmd(args.verbose) +
['--co', '--steps=gen',
'--simulator', args.simulator,
'--output', args.output,
'--isa', args.isa,
'--isa', isa,
'--end_signature_addr', args.end_signature_addr])

log_path = os.path.join(args.output, 'build.log')
Expand Down
8 changes: 5 additions & 3 deletions dv/uvm/core_ibex/scripts/compile-generated-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@
import sys
import tempfile

from scripts_lib import read_test_dot_seed, start_riscv_dv_run_cmd, run_one
from scripts_lib import (read_test_dot_seed, start_riscv_dv_run_cmd,
get_isas_for_config, run_one)


def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--input', required=True)
parser.add_argument('--output', required=True)
parser.add_argument('--isa', required=True)
parser.add_argument('--ibex-config', required=True)

parser.add_argument('--test-dot-seed',
type=read_test_dot_seed, required=True)

args = parser.parse_args()

isa, iss_isa = get_isas_for_config(args.ibex_config)
testname, seed = args.test_dot_seed

if not args.output.endswith('.bin'):
Expand All @@ -51,7 +53,7 @@ def main() -> int:
'--test', testname,
'--start_seed', str(seed),
'--iterations', '1',
'--isa', args.isa,
'--isa', isa,
'--debug', orig_list],
redirect_stdstreams=out_riscv_dv_path)
if dv_ret:
Expand Down
9 changes: 6 additions & 3 deletions dv/uvm/core_ibex/scripts/run-instr-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import tempfile
from typing import List

from scripts_lib import read_test_dot_seed, start_riscv_dv_run_cmd, run_one
from scripts_lib import (read_test_dot_seed, start_riscv_dv_run_cmd,
get_isas_for_config, run_one)


def main() -> int:
Expand All @@ -23,7 +24,7 @@ def main() -> int:
parser.add_argument('--end-signature-addr', required=True)
parser.add_argument('--output-dir', required=True)
parser.add_argument('--gen-build-dir', required=True)
parser.add_argument('--isa', required=True)
parser.add_argument('--ibex-config', required=True)

parser.add_argument('--test-dot-seed',
type=read_test_dot_seed, required=True)
Expand All @@ -33,6 +34,8 @@ def main() -> int:

args = parser.parse_args()

isa, iss_isa = get_isas_for_config(args.ibex_config)

testname, seed = args.test_dot_seed

inst_overrides = [
Expand Down Expand Up @@ -65,7 +68,7 @@ def main() -> int:
['--so', '--steps=gen',
'--output', placeholder,
'--simulator', args.simulator,
'--isa', args.isa,
'--isa', isa,
'--test', testname,
'--start_seed', str(seed),
'--iterations', '1',
Expand Down
8 changes: 5 additions & 3 deletions dv/uvm/core_ibex/scripts/run-iss.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import sys

from scripts_lib import run_one
from scripts_lib import get_isas_for_config, run_one


def main() -> int:
Expand All @@ -17,10 +17,12 @@ def main() -> int:
parser.add_argument('--iss', required=True)
parser.add_argument('--input', required=True)
parser.add_argument('--output', required=True)
parser.add_argument('--isa', required=True)
parser.add_argument('--ibex-config', required=True)

args = parser.parse_args()

isa, iss_isa = get_isas_for_config(args.ibex_config)

# riscv-dv knows how to run an ISS simulation (see yaml/iss.yaml in the
# vendored directory), but it has definite (and inconvenient!) opinions
# about where files should end up. Rather than fight with it, let's just
Expand All @@ -39,7 +41,7 @@ def main() -> int:
else:
spike = 'spike'

cmd = [spike, '--log-commits', '--isa', args.isa, '-l', args.input]
cmd = [spike, '--log-commits', '--isa', iss_isa, '-l', args.input]
return run_one(args.verbose,
cmd,
redirect_stdstreams=args.output)
Expand Down
34 changes: 33 additions & 1 deletion dv/uvm/core_ibex/scripts/scripts_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
from typing import Dict, List, Optional, Tuple

THIS_DIR = os.path.dirname(__file__)
IBEX_ROOT = os.path.join(THIS_DIR, 4 * '../')
IBEX_ROOT = os.path.normpath(os.path.join(THIS_DIR, 4 * '../'))
RISCV_DV_ROOT = os.path.normpath(os.path.join(IBEX_ROOT,
'vendor/google_riscv-dv'))

_OLD_SYS_PATH = sys.path
try:
sys.path = [os.path.join(IBEX_ROOT, 'util')] + sys.path
from ibex_config import parse_config
finally:
sys.path = _OLD_SYS_PATH

TestAndSeed = Tuple[str, int]


Expand Down Expand Up @@ -99,3 +106,28 @@ def read_test_dot_seed(arg: str) -> TestAndSeed:
.format(arg))

return (match.group(1), int(match.group(2), 10))


def get_isas_for_config(ibex_cfg: str) -> Tuple[str, str]:
'''Get ISA and ISS_ISA keys for the given Ibex config'''
yaml_path = os.path.join(IBEX_ROOT, "ibex_configs.yaml")
cfg = parse_config(ibex_cfg, yaml_path)

# NOTE: This logic should match the code in the get_isa_string() function
# in core_ibex/tests/core_ibex_base_test.sv: keep them in sync!
has_multiplier = cfg.rv32m != 'ibex_pkg::RV32MNone'
base_isa = 'rv32{}{}c'.format('e' if cfg.rv32e else 'i',
'm' if has_multiplier else '')

bitmanip_mapping = {
'ibex_pkg::RV32BNone': [],
'ibex_pkg::RV32BBalanced': ['Zba', 'Zbb', 'Zbs', 'Xbitmanip'],
'ibex_pkg::RV32BOTEarlGrey': ['Zba', 'Zbb', 'Zbc', 'Zbs', 'Xbitmanip'],
'ibex_pkg::RV32BFull': ['Zba', 'Zbb', 'Zbc', 'Zbs', 'Xbitmanip'],
}

bitmanip_isa = bitmanip_mapping.get(cfg.rv32b)
if bitmanip_isa is None:
raise ValueError(f'Unknown RV32B value ({cfg.rv32b}) in config YAML')

return (base_isa, '_'.join([base_isa] + bitmanip_isa))
2 changes: 2 additions & 0 deletions dv/uvm/core_ibex/tests/core_ibex_base_test.sv
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class core_ibex_base_test extends uvm_test;
irq_collected_port = new("irq_collected_port_test", this);
endfunction

// NOTE: This logic should match the code in the get_isas_for_config() function in
// core_ibex/scripts/scripts_lib.py: keep them in sync!
function string get_isa_string();
bit RV32E;
rv32m_e RV32M;
Expand Down

0 comments on commit ecdb1e0

Please sign in to comment.