Makefile 6.6 KB
Newer Older
Z
Zihao Yu 已提交
1
TOP = TopMain
2
FPGATOP = FPGANOOP
L
Lingrui98 已提交
3
BUILD_DIR = ./build
Z
Zihao Yu 已提交
4 5
TOP_V = $(BUILD_DIR)/$(TOP).v
SCALA_FILE = $(shell find ./src/main/scala -name '*.scala')
6
TEST_FILE = $(shell find ./src/test/scala -name '*.scala')
Z
Zihao Yu 已提交
7
MEM_GEN = ./scripts/vlsi_mem_gen
Z
Zihao Yu 已提交
8

Z
Zihao Yu 已提交
9
SIMTOP = top.TestMain
Z
Zihao Yu 已提交
10
IMAGE ?= temp
Z
Zihao Yu 已提交
11

12 13 14 15 16 17 18 19
# co-simulation with DRAMsim3
ifeq ($(WITH_DRAMSIM3),1)
ifndef DRAMSIM3_HOME
$(error DRAMSIM3_HOME is not set)
endif
override SIM_ARGS += --with-dramsim3
endif

Y
Yinan Xu 已提交
20
# remote machine with more cores to speedup c++ build
21 22
REMOTE ?= localhost

Z
Zihao Yu 已提交
23 24
.DEFAULT_GOAL = verilog

Z
Zihao Yu 已提交
25
help:
L
linjiawei 已提交
26
	mill XiangShan.test.runMain top.$(TOP) --help
Z
Zihao Yu 已提交
27

Z
Zihao Yu 已提交
28 29
$(TOP_V): $(SCALA_FILE)
	mkdir -p $(@D)
30
	mill XiangShan.test.runMain $(SIMTOP) -td $(@D) --full-stacktrace --output-file $(@F) --disable-all --fpga-platform --remove-assert --infer-rw --repl-seq-mem -c:$(SIMTOP):-o:$(@D)/$(@F).conf $(SIM_ARGS)
31
	$(MEM_GEN) $(@D)/$(@F).conf >> $@
Y
Yinan Xu 已提交
32
	# sed -i -e 's/_\(aw\|ar\|w\|r\|b\)_\(\|bits_\)/_\1/g' $@
33 34 35 36 37 38 39
	@git log -n 1 >> .__head__
	@git diff >> .__diff__
	@sed -i 's/^/\/\// ' .__head__
	@sed -i 's/^/\/\//' .__diff__
	@cat .__head__ .__diff__ $@ > .__out__
	@mv .__out__ $@
	@rm .__head__ .__diff__
40 41 42 43 44

deploy: build/top.zip


build/top.zip: $(TOP_V)
45 46 47 48
	@zip -r $@ $< $<.conf build/*.anno.json

.PHONY: deploy build/top.zip

Z
Zihao Yu 已提交
49 50
verilog: $(TOP_V)

51
SIM_TOP   = XSSimTop
Z
Zihao Yu 已提交
52
SIM_TOP_V = $(BUILD_DIR)/$(SIM_TOP).v
53
$(SIM_TOP_V): $(SCALA_FILE) $(TEST_FILE)
Z
Zihao Yu 已提交
54
	mkdir -p $(@D)
55
	date -R
L
linjiawei 已提交
56
	mill XiangShan.test.runMain $(SIMTOP) -X verilog -td $(@D) --full-stacktrace --output-file $(@F) $(SIM_ARGS)
57
	sed -i '/module XSSimTop/,/endmodule/d' $(SIM_TOP_V)
58
	sed -i -e 's/$$fatal/xs_assert(`__LINE__)/g' $(SIM_TOP_V)
59
	date -R
Z
Zihao Yu 已提交
60

61
EMU_TOP      = XSSimSoC
Z
Zihao Yu 已提交
62 63 64
EMU_CSRC_DIR = $(abspath ./src/test/csrc)
EMU_VSRC_DIR = $(abspath ./src/test/vsrc)
EMU_CXXFILES = $(shell find $(EMU_CSRC_DIR) -name "*.cpp")
65
EMU_VFILES   = $(shell find $(EMU_VSRC_DIR) -name "*.v" -or -name "*.sv")
Z
Zihao Yu 已提交
66

67
EMU_CXXFLAGS += -std=c++11 -static -Wall -I$(EMU_CSRC_DIR)
Z
Zihao Yu 已提交
68
EMU_CXXFLAGS += -DVERILATOR -Wno-maybe-uninitialized
Z
zoujr 已提交
69
EMU_LDFLAGS  += -lpthread -lSDL2 -ldl -lz
70

A
Allen 已提交
71
VEXTRA_FLAGS  = -I$(abspath $(BUILD_DIR)) --x-assign unique -O3 -CFLAGS "$(EMU_CXXFLAGS)" -LDFLAGS "$(EMU_LDFLAGS)"
Y
Yinan Xu 已提交
72

73
# Verilator trace support
L
LinJiawei 已提交
74
EMU_TRACE ?=
Y
Yinan Xu 已提交
75 76 77
ifeq ($(EMU_TRACE),1)
VEXTRA_FLAGS += --trace
endif
78 79 80

# Verilator multi-thread support
EMU_THREADS  ?= 1
Y
Yinan Xu 已提交
81
ifneq ($(EMU_THREADS),1)
82
VEXTRA_FLAGS += --threads $(EMU_THREADS) --threads-dpi all
Y
Yinan Xu 已提交
83
endif
84 85

# Verilator savable
L
LinJiawei 已提交
86
EMU_SNAPSHOT ?=
87 88 89
ifeq ($(EMU_SNAPSHOT),1)
VEXTRA_FLAGS += --savable
EMU_CXXFLAGS += -DVM_SAVABLE
90 91
endif

A
Allen 已提交
92 93 94 95 96 97
# Verilator coverage
EMU_COVERAGE ?=
ifeq ($(EMU_COVERAGE),1)
VEXTRA_FLAGS += --coverage-line --coverage-toggle
endif

98 99 100 101 102 103 104
# co-simulation with DRAMsim3
ifeq ($(WITH_DRAMSIM3),1)
EMU_CXXFLAGS += -I$(DRAMSIM3_HOME)/src
EMU_CXXFLAGS += -DWITH_DRAMSIM3 -DDRAMSIM3_CONFIG=\\\"$(DRAMSIM3_HOME)/configs/XiangShan.ini\\\" -DDRAMSIM3_OUTDIR=\\\"$(BUILD_DIR)\\\"
EMU_LDFLAGS  += $(DRAMSIM3_HOME)/build/libdramsim3.a
endif

105
# --trace
106
VERILATOR_FLAGS = --top-module $(EMU_TOP) \
Z
Zihao Yu 已提交
107
  +define+VERILATOR=1 \
Z
Zihao Yu 已提交
108
  +define+PRINTF_COND=1 \
Z
Zihao Yu 已提交
109
  +define+RANDOMIZE_REG_INIT \
110
  +define+RANDOMIZE_MEM_INIT \
111
  $(VEXTRA_FLAGS) \
Z
Zihao Yu 已提交
112
  --assert \
113
  --stats-vars \
Z
Zihao Yu 已提交
114
  --output-split 5000 \
Y
Yinan Xu 已提交
115
  --output-split-cfuncs 5000
Z
Zihao Yu 已提交
116

L
LinJiawei 已提交
117
EMU_MK := $(BUILD_DIR)/emu-compile/V$(EMU_TOP).mk
Z
Zihao Yu 已提交
118 119 120 121 122 123
EMU_DEPS := $(EMU_VFILES) $(EMU_CXXFILES)
EMU_HEADERS := $(shell find $(EMU_CSRC_DIR) -name "*.h")
EMU := $(BUILD_DIR)/emu

$(EMU_MK): $(SIM_TOP_V) | $(EMU_DEPS)
	@mkdir -p $(@D)
124
	date -R
Z
Zihao Yu 已提交
125
	verilator --cc --exe $(VERILATOR_FLAGS) \
Z
Zihao Yu 已提交
126
		-o $(abspath $(EMU)) -Mdir $(@D) $^ $(EMU_DEPS)
127
	date -R
Z
Zihao Yu 已提交
128

Y
Yinan Xu 已提交
129 130 131
ifndef NEMU_HOME
$(error NEMU_HOME is not set)
endif
L
LinJiawei 已提交
132
REF_SO := $(NEMU_HOME)/build/riscv64-nemu-interpreter-so
Z
Zihao Yu 已提交
133
$(REF_SO):
134
	$(MAKE) -C $(NEMU_HOME) ISA=riscv64 SHARE=1
Z
Zihao Yu 已提交
135

L
LinJiawei 已提交
136 137 138 139 140 141 142
LOCK = /var/emu/emu.lock
LOCK_BIN = $(abspath $(BUILD_DIR)/lock-emu)

$(LOCK_BIN): ./scripts/utils/lock-emu.c
	gcc $^ -o $@

$(EMU): $(EMU_MK) $(EMU_DEPS) $(EMU_HEADERS) $(REF_SO) $(LOCK_BIN)
143
	date -R
144
ifeq ($(REMOTE),localhost)
L
LinJiawei 已提交
145
	CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) VM_PARALLEL_BUILDS=1 OPT_FAST="-O3" -C $(abspath $(dir $(EMU_MK))) -f $(abspath $(EMU_MK))
146
else
L
LinJiawei 已提交
147 148 149
	@echo "try to get emu.lock ..."
	ssh -tt $(REMOTE) '$(LOCK_BIN) $(LOCK)'
	@echo "get lock"
L
LinJiawei 已提交
150
	ssh -tt $(REMOTE) 'CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) -j230 VM_PARALLEL_BUILDS=1 OPT_FAST="-O3" -C $(abspath $(dir $(EMU_MK))) -f $(abspath $(EMU_MK))'
L
LinJiawei 已提交
151 152
	@echo "release lock ..."
	ssh -tt $(REMOTE) 'rm -f $(LOCK)'
153
endif
154
	date -R
Z
Zihao Yu 已提交
155

156
SEED ?= $(shell shuf -i 1-10000 -n 1)
157

L
Lingrui98 已提交
158 159
VME_SOURCE ?= $(shell pwd)/build/$(TOP).v
VME_MODULES ?= 
160

161 162
# log will only be printed when (B<=GTimer<=E) && (L < loglevel)
# use 'emu -h' to see more details
163 164
B ?= 0
E ?= -1
165 166
SNAPSHOT ?=

L
LinJiawei 已提交
167 168 169 170
# enable this runtime option if you want to generate a vcd file
# use 'emu -h' to see more details
#WAVEFORM = --dump-wave

171 172 173
ifeq ($(SNAPSHOT),)
SNAPSHOT_OPTION = 
else
Y
Yinan Xu 已提交
174
SNAPSHOT_OPTION = --load-snapshot=$(SNAPSHOT)
175 176
endif

Y
Yinan Xu 已提交
177 178 179
ifndef NOOP_HOME
$(error NOOP_HOME is not set)
endif
L
LinJiawei 已提交
180
EMU_FLAGS = -s $(SEED) -b $(B) -e $(E) $(SNAPSHOT_OPTION) $(WAVEFORM)
181

Z
Zihao Yu 已提交
182
emu: $(EMU)
Y
Yinan Xu 已提交
183
	ls build
Y
Yinan Xu 已提交
184
	$(EMU) -i $(IMAGE) $(EMU_FLAGS)
Z
Zihao Yu 已提交
185

186 187 188 189 190
coverage:
	verilator_coverage --annotate build/logs/annotated --annotate-min 1 build/logs/coverage.dat
	python3 scripts/coverage/coverage.py build/logs/annotated/XSSimTop.v build/XSSimTop_annotated.v
	python3 scripts/coverage/statistics.py build/XSSimTop_annotated.v >build/coverage.log

L
Lingrui98 已提交
191 192 193
#-----------------------timing scripts-------------------------
# run "make vme/tap help=1" to get help info

194 195 196 197
# extract verilog module from TopMain.v
# usage: make vme VME_MODULES=Roq
TIMING_SCRIPT_PATH = ./timingScripts
vme: $(TOP_V)
L
Lingrui98 已提交
198
	make -C $(TIMING_SCRIPT_PATH) vme
199 200 201 202 203

# get and sort timing analysis with total delay(start+end) and max delay(start or end)
# and print it out
tap:
	make -C $(TIMING_SCRIPT_PATH) tap
204 205 206 207 208

# usage: make phy_evaluate VME_MODULE=Roq REMOTE=100
phy_evaluate: vme
	scp -r ./build/extracted/* $(REMOTE):~/phy_evaluation/remote_run/rtl
	ssh -tt $(REMOTE) 'cd ~/phy_evaluation/remote_run && $(MAKE) evaluate DESIGN_NAME=$(VME_MODULE)'
209
	scp -r  $(REMOTE):~/phy_evaluation/remote_run/rpts ./build
210 211 212 213 214

# usage: make phy_evaluate_atc VME_MODULE=Roq REMOTE=100
phy_evaluate_atc: vme
	scp -r ./build/extracted/* $(REMOTE):~/phy_evaluation/remote_run/rtl
	ssh -tt $(REMOTE) 'cd ~/phy_evaluation/remote_run && $(MAKE) evaluate_atc DESIGN_NAME=$(VME_MODULE)'
215
	scp -r  $(REMOTE):~/phy_evaluation/remote_run/rpts ./build
216

Z
Zihao Yu 已提交
217
cache:
Z
Zihao Yu 已提交
218
	$(MAKE) emu IMAGE=Makefile
Z
Zihao Yu 已提交
219

L
LinJiawei 已提交
220 221 222
release-lock:
	ssh -tt $(REMOTE) 'rm -f $(LOCK)'

Z
Zihao Yu 已提交
223
clean:
224 225
	git submodule foreach git clean -fdx
	git clean -fd
Y
Yinan Xu 已提交
226
	rm -rf ./build
Z
Zihao Yu 已提交
227

L
linjiawei 已提交
228 229 230
init:
	git submodule update --init

231 232 233 234 235 236
bump:
	git submodule foreach "git fetch origin&&git checkout master&&git reset --hard origin/master"

bsp:
	mill -i mill.contrib.BSP/install
.PHONY: verilog emu clean help init bump bsp $(REF_SO)