| # Copyright 2025 Google LLC |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| # Makefile for Kelvin UVM Testbench (Integrates with MPACT-Sim) |
| |
| # Check if ROOTDIR is set. If not, exit with an error. |
| ifndef ROOTDIR |
| $(error ROOTDIR is not set. Please define it, e.g., export ROOTDIR=$(abspath ../../../..)) |
| endif |
| |
| # User Configuration |
| VCS = vcs |
| CXX = clang++ |
| |
| # UVM DV Directories |
| RTL_DIR = ./rtl |
| COMMON_DIR = ./common |
| TB_DIR = ./tb |
| ENV_DIR = ./env |
| TESTS_DIR = ./tests |
| BIN_DIR = ./bin |
| |
| # Simulation Work Directory |
| SIM_DIR = ./sim_work |
| LOG_DIR = $(SIM_DIR)/logs |
| WAVE_DIR = $(SIM_DIR)/waves |
| |
| # MPACT-Sim Integration Paths |
| MPACT_DIR = $(ROOTDIR)/sim/kelvin |
| MPACT_BAZEL_BIN_DIR = $(MPACT_DIR)/bazel-bin/sim/cosim |
| MPACT_COSIM_LIB_NAME = kelvin_cosim_lib_static |
| |
| # File List for VCS -f option |
| FILE_LIST = ./kelvin_dv.f |
| |
| # Simulation Settings |
| SIM_EXEC = $(SIM_DIR)/simv |
| UVM_TESTNAME ?= kelvin_base_test |
| TEST_BINARY ?= $(BIN_DIR)/program.bin |
| UVM_VERBOSITY ?= UVM_MEDIUM |
| TEST_TIMEOUT_NS ?= 20000 |
| PLUSARGS = +UVM_TESTNAME=$(UVM_TESTNAME) +TEST_BINARY=$(TEST_BINARY) \ |
| +UVM_VERBOSITY=$(UVM_VERBOSITY) +TEST_TIMEOUT=$(TEST_TIMEOUT_NS) |
| |
| # Waveform Dumping |
| DUMP_WAVES = 1 |
| WAVE_FILE = $(WAVE_DIR)/$(UVM_TESTNAME).fsdb |
| |
| # VCS Options |
| VCS_COMPILE_OPTS = \ |
| -full64 \ |
| -sverilog \ |
| +define+UVM_NO_DEPRECATED \ |
| -ntb_opts uvm-1.2 \ |
| -debug_access+all \ |
| -kdb \ |
| -timescale=1ns/1ps \ |
| -o $(SIM_EXEC) |
| |
| # Add C++ compiler/linker options for MPACT-Sim |
| VCS_COMPILE_OPTS += \ |
| -cpp $(CXX) \ |
| -cppflags "-std=c++17" \ |
| -CFLAGS "-I$(MPACT_DIR)" \ |
| -L$(MPACT_BAZEL_BIN_DIR) \ |
| -l$(MPACT_COSIM_LIB_NAME) |
| |
| VCS_RUN_OPTS = \ |
| $(PLUSARGS) |
| |
| # Add define to COMPILE options for waveform dumping |
| ifeq ($(DUMP_WAVES),1) |
| VCS_COMPILE_OPTS += +define+DUMP_WAVES |
| VCS_RUN_OPTS += +fsdb+all \ |
| +fsdbfile+$(WAVE_FILE) |
| endif |
| |
| # Targets |
| |
| .PHONY: all compile run clean dirs help build_mpact_lib |
| |
| # Default target |
| all: run |
| |
| # Create necessary directories |
| dirs: |
| @mkdir -p $(SIM_DIR) $(LOG_DIR) $(WAVE_DIR) $(BIN_DIR) |
| |
| # Build the MPACT-Sim library using Bazel with CC=clang |
| build_mpact_lib: |
| @echo "--- Building MPACT-Sim Co-sim Library via Bazel ---" |
| cd $(MPACT_DIR) && CC=clang bazel build //sim/cosim:$(MPACT_COSIM_LIB_NAME) |
| |
| # Compile the design |
| compile: dirs build_mpact_lib |
| @echo "--- Compiling with VCS ---" |
| $(VCS) $(VCS_COMPILE_OPTS) -l $(LOG_DIR)/compile.log -f $(FILE_LIST) |
| @echo "--- Compilation Finished ---" |
| |
| # Run the simulation |
| run: compile |
| @echo "--- Running Simulation ---" |
| @echo "Test: $(UVM_TESTNAME)" |
| @echo "Binary: $(TEST_BINARY)" |
| @echo "Verbosity: $(UVM_VERBOSITY)" |
| @echo "Timeout: $(TEST_TIMEOUT_NS) ns" |
| @echo "Plusargs: $(PLUSARGS)" |
| @echo "Log File: $(LOG_DIR)/$(UVM_TESTNAME).log" |
| ifeq ($(DUMP_WAVES),1) |
| @echo "Wave File: $(WAVE_FILE)" |
| endif |
| ./$(SIM_EXEC) $(VCS_RUN_OPTS) -l $(LOG_DIR)/$(UVM_TESTNAME).log |
| @echo "--- Simulation Finished ---" |
| |
| # Clean up simulation files |
| clean: |
| @echo "--- Cleaning Simulation Files ---" |
| rm -rf $(SIM_DIR) simv* csrc* *.log* *.key *.vpd *.fsdb ucli.key DVEfiles/ verdiLog/ novas.* |
| @echo "--- Cleaning MPACT-Sim Bazel cache ---" |
| cd $(MPACT_DIR) && bazel clean |
| |
| # Help |
| help: |
| @echo "Makefile Targets:" |
| @echo " make compile : Builds MPACT lib and compiles DUT/testbench" |
| @echo " make run : Builds and runs the full co-simulation" |
| @echo " : Override defaults: make run UVM_TESTNAME=<test> TEST_BINARY=<path> UVM_VERBOSITY=<level>" |
| @echo " make build_mpact_lib : Only builds the MPACT-Sim C++ library" |
| @echo " make clean : Removes generated simulation and MPACT-Sim files" |
| @echo " make dirs : Creates simulation directories" |
| @echo " make help : Shows this help message" |