xref: /XiangShan/Makefile (revision 735e00f7de54bd3593eac9ad97afc062cb0dc949)
1TOP = TopMain
2FPGATOP = FPGANOOP
3BUILD_DIR = ./build
4TOP_V = $(BUILD_DIR)/$(TOP).v
5SCALA_FILE = $(shell find ./src/main/scala -name '*.scala')
6TEST_FILE = $(shell find ./src/test/scala -name '*.scala')
7MEM_GEN = ./scripts/vlsi_mem_gen
8
9SIMTOP = top.TestMain
10IMAGE ?= temp
11
12# remote machine with more cores to speedup c++ build
13REMOTE ?= localhost
14
15.DEFAULT_GOAL = verilog
16
17help:
18	mill XiangShan.test.runMain top.$(TOP) --help
19
20$(TOP_V): $(SCALA_FILE)
21	mkdir -p $(@D)
22	mill XiangShan.runMain top.$(TOP) -X verilog -td $(@D) --output-file $(@F) --infer-rw $(FPGATOP) --repl-seq-mem -c:$(FPGATOP):-o:$(@D)/$(@F).conf
23	$(MEM_GEN) $(@D)/$(@F).conf >> $@
24	sed -i -e 's/_\(aw\|ar\|w\|r\|b\)_\(\|bits_\)/_\1/g' $@
25	@git log -n 1 >> .__head__
26	@git diff >> .__diff__
27	@sed -i 's/^/\/\// ' .__head__
28	@sed -i 's/^/\/\//' .__diff__
29	@cat .__head__ .__diff__ $@ > .__out__
30	@mv .__out__ $@
31	@rm .__head__ .__diff__
32
33deploy: build/top.zip
34
35
36build/top.zip: $(TOP_V)
37	@zip -r $@ $< $<.conf build/*.anno.json
38
39.PHONY: deploy build/top.zip
40
41verilog: $(TOP_V)
42
43SIM_TOP = XSSimTop
44SIM_TOP_V = $(BUILD_DIR)/$(SIM_TOP).v
45SIM_ARGS =
46$(SIM_TOP_V): $(SCALA_FILE) $(TEST_FILE)
47	mkdir -p $(@D)
48	mill XiangShan.test.runMain $(SIMTOP) -X verilog -td $(@D) --full-stacktrace --output-file $(@F) $(SIM_ARGS)
49
50EMU_CSRC_DIR = $(abspath ./src/test/csrc)
51EMU_VSRC_DIR = $(abspath ./src/test/vsrc)
52EMU_CXXFILES = $(shell find $(EMU_CSRC_DIR) -name "*.cpp")
53EMU_VFILES = $(shell find $(EMU_VSRC_DIR) -name "*.v" -or -name "*.sv")
54
55EMU_CXXFLAGS  = -std=c++11 -static -Wall -I$(EMU_CSRC_DIR)
56EMU_CXXFLAGS += -DVERILATOR -Wno-maybe-uninitialized
57EMU_LDFLAGS   = -lpthread -lSDL2 -ldl
58EMU_THREADS   = 1
59ifeq ($(EMU_THREADS), 1)
60	VTHREAD_FLAGS = --threads 1
61else
62	VTHREAD_FLAGS = --threads $(EMU_THREADS) --threads-dpi none
63endif
64
65# --trace
66VERILATOR_FLAGS = --top-module $(SIM_TOP) \
67  +define+VERILATOR=1 \
68  +define+PRINTF_COND=1 \
69  +define+RANDOMIZE_REG_INIT \
70  +define+RANDOMIZE_MEM_INIT \
71  $(VTHREAD_FLAGS) \
72  --trace \
73  --assert \
74  --savable \
75  --stats-vars \
76  --output-split 5000 \
77  --output-split-cfuncs 5000 \
78  -I$(abspath $(BUILD_DIR)) \
79  --x-assign unique -O3 -CFLAGS "$(EMU_CXXFLAGS)" \
80  -LDFLAGS "$(EMU_LDFLAGS)"
81
82EMU_MK := $(BUILD_DIR)/emu-compile/V$(SIM_TOP).mk
83EMU_DEPS := $(EMU_VFILES) $(EMU_CXXFILES)
84EMU_HEADERS := $(shell find $(EMU_CSRC_DIR) -name "*.h")
85EMU := $(BUILD_DIR)/emu
86
87$(EMU_MK): $(SIM_TOP_V) | $(EMU_DEPS)
88	@mkdir -p $(@D)
89	verilator --cc --exe $(VERILATOR_FLAGS) \
90		-o $(abspath $(EMU)) -Mdir $(@D) $^ $(EMU_DEPS)
91
92REF_SO := $(NEMU_HOME)/build/riscv64-nemu-interpreter-so
93$(REF_SO):
94	$(MAKE) -C $(NEMU_HOME) ISA=riscv64 SHARE=1
95
96$(EMU): $(EMU_MK) $(EMU_DEPS) $(EMU_HEADERS) $(REF_SO)
97ifeq ($(REMOTE),localhost)
98	CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) VM_PARALLEL_BUILDS=1 OPT_FAST="-O3" -C $(abspath $(dir $(EMU_MK))) -f $(abspath $(EMU_MK))
99else
100	ssh -tt $(REMOTE) 'CPPFLAGS=-DREF_SO=\\\"$(REF_SO)\\\" $(MAKE) -j80 VM_PARALLEL_BUILDS=1 OPT_FAST="-O3" -C $(abspath $(dir $(EMU_MK))) -f $(abspath $(EMU_MK))'
101endif
102
103SEED ?= $(shell shuf -i 1-10000 -n 1)
104
105
106# log will only be printed when (B<=GTimer<=E) && (L < loglevel)
107# use 'emu -h' to see more details
108B ?= 0
109E ?= -1
110SNAPSHOT ?=
111ENABLESNAPSHOT ?= 0
112
113# enable this runtime option if you want to generate a vcd file
114# use 'emu -h' to see more details
115#WAVEFORM = --dump-wave
116
117ifeq ($(SNAPSHOT),)
118SNAPSHOT_OPTION =
119else
120SNAPSHOT_OPTION = --load-snapshot=$(SNAPSHOT)
121endif
122
123
124ifeq ($(ENABLESNAPSHOT),1)
125EMU_CXXFLAGS += -D__ENABLESNAPSHOT__
126endif
127
128EMU_FLAGS = -s $(SEED) -b $(B) -e $(E) $(SNAPSHOT_OPTION) $(WAVEFORM)
129
130emu: $(EMU)
131	ls build
132	$(EMU) -i $(IMAGE) $(EMU_FLAGS)
133
134cache:
135	$(MAKE) emu IMAGE=Makefile
136
137clean:
138	git submodule foreach git clean -fdx
139	git clean -fd
140
141init:
142	git submodule update --init
143
144bump:
145	git submodule foreach "git fetch origin&&git checkout master&&git reset --hard origin/master"
146
147bsp:
148	mill -i mill.contrib.BSP/install
149.PHONY: verilog emu clean help init bump bsp $(REF_SO)
150