Skip to content

Commit

Permalink
Factor out recipes for building SW RTL simulators into Makefrags
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbiancolin committed Sep 25, 2018
1 parent 29e70e5 commit a1abbc1
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 54 deletions.
65 changes: 11 additions & 54 deletions src/main/cc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,73 +76,30 @@ $(OUT_DIR)/$(DESIGN)-$(PLATFORM): $(GEN_DIR)/$(DESIGN)-const.h $(lib) $(DRIVER)

$(PLATFORM): $(OUT_DIR)/$(DESIGN)-$(PLATFORM) $(OUT_DIR)/$(DESIGN).chain

# Sources for building MIDAS-level simulators. Must be defined before sources VCS/Verilator Makefrags
emul_files := simif simif_emul emul/mmio_$(PLATFORM) sample/sample
emul_h := $(addprefix $(midas_dir)/, $(addsuffix .h, $(emul_files) emul/mmio))
emul_cc := $(addprefix $(midas_dir)/, $(addsuffix .cc, $(emul_files) sample/simif_sample))
emul_v := $(v_dir)/emul_$(PLATFORM).v

# Compile verilator emulation binary
VERILATOR ?= verilator --cc --exe
override VERILATOR_FLAGS := --assert -Wno-STMTDLY -O3 \
-CFLAGS "$(CXXFLAGS)" -LDFLAGS "$(LDFLAGS) -lmidas" \
$(VERILATOR_FLAGS)
emul_h := $(driver_h) $(endpoint_h) $( $(addprefix $(midas_dir)/, $(addsuffix .h, $(emul_files) emul/mmio))
# This includes c sources and static libraries
emul_cc := $(DRIVER) $(endpoint_cc) $(addprefix $(midas_dir)/, $(addsuffix .cc, $(emul_files) sample/simif_sample)) $(lib)
emul_v := $(design_v)
emul_h_inc := $(GEN_DIR)/$(DESIGN)-const.h
# The lop level module must be called out for verilator
ifeq ($(PLATFORM),zynq)
top_module = ZynqShim
endif
ifeq ($(PLATFORM),f1)
top_module = F1Shim
endif

$(OUT_DIR)/V$(DESIGN): $(GEN_DIR)/$(DESIGN)-const.h $(design_v) $(lib) $(DRIVER) $(driver_h) $(emul_cc) $(emul_h) $(endpoint_cc) $(endpoint_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/V$(DESIGN).csrc
$(VERILATOR) $(VERILATOR_FLAGS) --top-module $(top_module) -Mdir $(GEN_DIR)/V$(DESIGN).csrc \
-CFLAGS "-include $< -include $(GEN_DIR)/V$(DESIGN).csrc/V$(top_module).h" \
-o $@ $(design_v) $(DRIVER) $(emul_cc) $(endpoint_cc)
$(MAKE) -C $(GEN_DIR)/V$(DESIGN).csrc -f V$(top_module).mk

$(OUT_DIR)/V$(DESIGN)-debug: $(GEN_DIR)/$(DESIGN)-const.h $(design_v) $(lib) $(DRIVER) $(driver_h) $(emul_cc) $(emul_h) $(endpoint_cc) $(endpoint_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/V$(DESIGN)-debug.csrc
$(VERILATOR) $(VERILATOR_FLAGS) --trace --top-module $(top_module) -Mdir $(GEN_DIR)/V$(DESIGN)-debug.csrc \
-CFLAGS "-include $< -include $(GEN_DIR)/V$(DESIGN)-debug.csrc/V$(top_module).h" \
-o $@ $(design_v) $(DRIVER) $(emul_cc) $(endpoint_cc)
$(MAKE) -C $(GEN_DIR)/V$(DESIGN)-debug.csrc -f V$(top_module).mk
include Makefrag-verilator

verilator: $(OUT_DIR)/V$(DESIGN) $(OUT_DIR)/$(DESIGN).chain $(OUT_DIR)/dramsim2_ini
verilator-debug: $(OUT_DIR)/V$(DESIGN)-debug $(OUT_DIR)/$(DESIGN).chain $(OUT_DIR)/dramsim2_ini

# Compile VCS emulation binary
VCS ?= vcs -full64
override VCS_FLAGS := -quiet -timescale=1ns/1ps +v2k +rad +vcs+initreg+random +vcs+lic+wait \
-notice -line +lint=all,noVCDE,noONGS,noUI -quiet -debug_pp +no_notifier -e vcs_main -cpp $(CXX) \
-CFLAGS "$(CXXFLAGS) -DVCS -I$(VCS_HOME)/include" \
-LDFLAGS "$(LDFLAGS) -lmidas" \
+define+CLOCK_PERIOD=$(CLOCK_PERIOD) \
+define+RANDOMIZE_MEM_INIT \
+define+RANDOMIZE_REG_INIT \
+define+RANDOMIZE_GARBAGE_ASSIGN \
+define+RANDOMIZE_INVALID_ASSIGN \
$(VCS_FLAGS)

$(OUT_DIR)/$(DESIGN): $(GEN_DIR)/$(DESIGN)-const.h $(design_v) $(emul_v) $(lib) $(DRIVER) $(driver_h) $(emul_cc) $(emul_h) $(endpoint_cc) $(endpoint_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/$(DESIGN).csrc
rm -rf $(OUT_DIR)/$(DESIGN).daidir
$(VCS) $(VCS_FLAGS) -Mdir=$(GEN_DIR)/$(DESIGN).csrc +vc+list \
+define+STOP_COND=!emul.reset +define+PRINTF_COND=!emul.reset \
-CFLAGS "-include $<" \
-o $@ $(GEN_DIR)/$(DESIGN)-const.vh $(design_v) $(emul_v) $(lib) $(DRIVER) $(emul_cc) $(endpoint_cc)

$(OUT_DIR)/$(DESIGN)-debug: $(GEN_DIR)/$(DESIGN)-const.h $(design_v) $(emul_v) $(lib) $(DRIVER) $(driver_h) $(emul_cc) $(emul_h) $(endpoint_cc) $(endpoint_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/$(DESIGN)-debug.csrc
rm -rf $(OUT_DIR)/$(DESIGN)-debug.daidir
$(VCS) $(VCS_FLAGS) -Mdir=$(GEN_DIR)/$(DESIGN)-debug.csrc +vc+list \
+define+STOP_COND=!emul.reset +define+PRINTF_COND=!emul.reset +define+DEBUG \
-CFLAGS "-include $<" \
-o $@ $(GEN_DIR)/$(DESIGN)-const.vh $(design_v) $(emul_v) $(lib) $(DRIVER) $(emul_cc) $(endpoint_cc)
# Add an extra wrapper source for VCS simulators
vcs_wrapper_v := $(v_dir)/emul_$(PLATFORM).v
include Makefrag-vcs

vcs: $(OUT_DIR)/$(DESIGN) $(OUT_DIR)/$(DESIGN).chain $(OUT_DIR)/dramsim2_ini
vcs-debug: $(OUT_DIR)/$(DESIGN)-debug $(OUT_DIR)/$(DESIGN).chain $(OUT_DIR)/dramsim2_ini
Expand Down
40 changes: 40 additions & 0 deletions src/main/cc/Makefrag-vcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# VCS RTL Simulation Makefrag
#
# This makefrag stores common recipes for building RTL simulators with VCS
#
# Compulsory variables:
# All those described Makefrag-verilator
# vcs_wrapper_v: An additional verilog wrapper around the DUT not used in verilator
# CLOCK_PERIOD: Self explanatory

VCS ?= vcs -full64
override VCS_FLAGS := -quiet -timescale=1ns/1ps +v2k +rad +vcs+initreg+random +vcs+lic+wait \
-notice -line +lint=all,noVCDE,noONGS,noUI -quiet -debug_pp +no_notifier -e vcs_main -cpp $(CXX) \
-CFLAGS "$(CXXFLAGS) -DVCS -I$(VCS_HOME)/include" \
-LDFLAGS "$(LDFLAGS) -lmidas" \
+define+CLOCK_PERIOD=$(CLOCK_PERIOD) \
+define+RANDOMIZE_MEM_INIT \
+define+RANDOMIZE_REG_INIT \
+define+RANDOMIZE_GARBAGE_ASSIGN \
+define+RANDOMIZE_INVALID_ASSIGN \
$(VCS_FLAGS)

vcs_v := $(vcs_wrapper_v) $(emul_v)

$(OUT_DIR)/$(DESIGN): $(emul_h_inc) $(vcs_v) $(emul_cc) $(emul_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/$(DESIGN).csrc
rm -rf $(OUT_DIR)/$(DESIGN).daidir
$(VCS) $(VCS_FLAGS) -Mdir=$(GEN_DIR)/$(DESIGN).csrc +vc+list \
+define+STOP_COND=!emul.reset +define+PRINTF_COND=!emul.reset \
-CFLAGS "-include $<" \
-o $@ $(GEN_DIR)/$(DESIGN)-const.vh $(vcs_v) $(emul_cc)

$(OUT_DIR)/$(DESIGN)-debug: $(emul_h_inc) $(vcs_v) $(emul_cc) $(emul_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/$(DESIGN)-debug.csrc
rm -rf $(OUT_DIR)/$(DESIGN)-debug.daidir
$(VCS) $(VCS_FLAGS) -Mdir=$(GEN_DIR)/$(DESIGN)-debug.csrc +vc+list \
+define+STOP_COND=!emul.reset +define+PRINTF_COND=!emul.reset +define+DEBUG \
-CFLAGS "-include $<" \
-o $@ $(GEN_DIR)/$(DESIGN)-const.vh $(vcs_v) $(emul_cc)
36 changes: 36 additions & 0 deletions src/main/cc/Makefrag-verilator
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Verilator RTL Simulation Makefrag
#
# This makefrag stores common recipes for building RTL simulators with Verilator
#
# Compulsory variables:
# OUT_DIR: See Makefile
# GEN_DIR: See Makefile
# DESIGN: See Makefile
# emul_h_inc: A c header with macro definitions to be included in all compilation units
# emul_cc: C++ sources
# emul_h: C++ headers
# emul_v: verilog sources
#
# Verilator Only:
# top_module: The top of the DUT

VERILATOR ?= verilator --cc --exe
override VERILATOR_FLAGS := --assert -Wno-STMTDLY -O3 \
-CFLAGS "$(CXXFLAGS)" -LDFLAGS "$(LDFLAGS) -lmidas" \
$(VERILATOR_FLAGS)

$(OUT_DIR)/V$(DESIGN): $(emul_h_inc) $(emul_v) $(emul_cc) $(emul_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/V$(DESIGN).csrc
$(VERILATOR) $(VERILATOR_FLAGS) --top-module $(top_module) -Mdir $(GEN_DIR)/V$(DESIGN).csrc \
-CFLAGS "-include $< -include $(GEN_DIR)/V$(DESIGN).csrc/V$(top_module).h" \
-o $@ $(emul_v) $(DRIVER) $(emul_cc) $(endpoint_cc)
$(MAKE) -C $(GEN_DIR)/V$(DESIGN).csrc -f V$(top_module).mk

$(OUT_DIR)/V$(DESIGN)-debug: $(emul_h_inc) $(emul_v) $(emul_cc) $(emul_h)
mkdir -p $(OUT_DIR)
rm -rf $(GEN_DIR)/V$(DESIGN)-debug.csrc
$(VERILATOR) $(VERILATOR_FLAGS) --trace --top-module $(top_module) -Mdir $(GEN_DIR)/V$(DESIGN)-debug.csrc \
-CFLAGS "-include $< -include $(GEN_DIR)/V$(DESIGN)-debug.csrc/V$(top_module).h" \
-o $@ $(emul_v) $(emul_cc)
$(MAKE) -C $(GEN_DIR)/V$(DESIGN)-debug.csrc -f V$(top_module).mk

0 comments on commit a1abbc1

Please sign in to comment.