OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [orpsocv2/] [sim/] [bin/] [Makefile] - Blame information for rev 468

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 julius
######################################################################
2
####                                                              ####
3
####  ORPSoCv2 Testbenches Makefile                               ####
4
####                                                              ####
5
####  Description                                                 ####
6
####  ORPSoCv2 Testbenches Makefile, containing rules for         ####
7
####  configuring and running different tests on the current      ####
8
####  ORPSoC(v2) design.                                          ####
9
####                                                              ####
10
####  To do:                                                      ####
11
####                                                              ####
12
####  Author(s):                                                  ####
13 360 julius
####      - Julius Baxter, julius@opencores.org                   ####
14 6 julius
####                                                              ####
15
####                                                              ####
16
######################################################################
17
####                                                              ####
18 348 julius
#### Copyright (C) 2009,2010 Authors and OPENCORES.ORG            ####
19 6 julius
####                                                              ####
20
#### This source file may be used and distributed without         ####
21
#### restriction provided that this copyright statement is not    ####
22
#### removed from the file and that any derivative work contains  ####
23
#### the original copyright notice and the associated disclaimer. ####
24
####                                                              ####
25
#### This source file is free software; you can redistribute it   ####
26
#### and/or modify it under the terms of the GNU Lesser General   ####
27
#### Public License as published by the Free Software Foundation; ####
28
#### either version 2.1 of the License, or (at your option) any   ####
29
#### later version.                                               ####
30
####                                                              ####
31
#### This source is distributed in the hope that it will be       ####
32
#### useful, but WITHOUT ANY WARRANTY; without even the implied   ####
33
#### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ####
34
#### PURPOSE.  See the GNU Lesser General Public License for more ####
35
#### details.                                                     ####
36
####                                                              ####
37
#### You should have received a copy of the GNU Lesser General    ####
38
#### Public License along with this source; if not, download it   ####
39
#### from http://www.opencores.org/lgpl.shtml                     ####
40
####                                                              ####
41
######################################################################
42
 
43 360 julius
# Name of the directory we're currently in
44
CUR_DIR=$(shell pwd)
45 6 julius
 
46 360 julius
# The root path of the whole project
47
PROJECT_ROOT ?=$(CUR_DIR)/../..
48 6 julius
 
49 362 julius
DESIGN_NAME=orpsoc
50
RTL_TESTBENCH_TOP=$(DESIGN_NAME)_testbench
51
# Top level files for DUT and testbench
52
DUT_TOP=$(RTL_VERILOG_DIR)/$(DESIGN_NAME)_top/$(DESIGN_NAME)_top.v
53
BENCH_TOP=$(BENCH_VERILOG_DIR)/$(DESIGN_NAME)_testbench.v
54
 
55 360 julius
# Need this for individual test variables to not break
56
TEST ?= or1200-simple
57 6 julius
 
58 468 julius
TESTS ?= or1200-simple \
59
        or1200-basic \
60
        or1200-cbasic \
61
        or1200-dctest \
62
        or1200-float \
63
        or1200-mmu  \
64
        or1200-except \
65
        or1200-mac \
66
        or1200-ffl1 \
67
        or1200-linkregtest \
68
        or1200-tick \
69
        or1200-ticksyscall \
70
        uart-simple
71 6 julius
 
72 360 julius
# Gets turned into verilog `define
73
SIM_TYPE=RTL
74 6 julius
 
75 360 julius
# Paths to other important parts of this test suite
76
RTL_DIR = $(PROJECT_ROOT)/rtl
77
RTL_VERILOG_DIR = $(RTL_DIR)/verilog
78
RTL_VERILOG_INCLUDE_DIR = $(RTL_VERILOG_DIR)/include
79
#RTL_VHDL_DIR = $(RTL_DIR)/vhdl
80 6 julius
 
81 360 julius
PROJECT_VERILOG_DEFINES=$(RTL_VERILOG_INCLUDE_DIR)/$(DESIGN_NAME)-defines.v
82
# Detect technology to use for the simulation
83 468 julius
DESIGN_DEFINES=$(shell cat $(PROJECT_VERILOG_DEFINES) | \
84
        sed s://.*::g | sed s:\`:\#:g | sed 's:^[ ]*::' | \
85
        awk '{print};/^\#define/{printf "_%s=%s\n",$$2,$$2}' | \
86
        grep -v PERIOD | cpp -P | sed s:^_::g | sed s:=$$::g )
87 6 julius
 
88 360 julius
# Rule to look at what defines are being extracted from main file
89
print-defines:
90
        @echo echo; echo "\t### Design defines ###"; echo
91
        @echo "\tParsing "$(PROJECT_VERILOG_DEFINES)" and exporting:"
92
        @echo $(DESIGN_DEFINES)
93 6 julius
 
94 360 julius
# Simulation directories
95
SIM_DIR ?=$(PROJECT_ROOT)/sim
96 362 julius
SIM_VLT_DIR ?=$(SIM_DIR)/vlt
97 360 julius
RTL_SIM_DIR=$(SIM_DIR)
98
RTL_SIM_RUN_DIR=$(RTL_SIM_DIR)/run
99
RTL_SIM_BIN_DIR=$(RTL_SIM_DIR)/bin
100
RTL_SIM_SRC_DIR=$(RTL_SIM_DIR)/src
101
RTL_SIM_RESULTS_DIR=$(RTL_SIM_DIR)/out
102 6 julius
 
103 360 julius
# Testbench paths
104 6 julius
BENCH_DIR=$(PROJECT_ROOT)/bench
105
BENCH_VERILOG_DIR=$(BENCH_DIR)/verilog
106 403 julius
BENCH_VERILOG_INCLUDE_DIR=$(BENCH_VERILOG_DIR)/include
107 360 julius
#BENCH_VHDL_DIR=$(BENCH_DIR)/vhdl
108 362 julius
BENCH_SYSC_DIR=$(BENCH_DIR)/sysc
109
BENCH_SYSC_SRC_DIR=$(BENCH_SYSC_DIR)/src
110
BENCH_SYSC_INCLUDE_DIR=$(BENCH_SYSC_DIR)/include
111 360 julius
 
112 362 julius
 
113 360 julius
# System software dir
114 6 julius
SW_DIR=$(PROJECT_ROOT)/sw
115 360 julius
# BootROM code, which generates a verilog array select values
116
BOOTROM_FILE=bootrom.v
117
BOOTROM_SW_DIR=$(SW_DIR)/bootrom
118
BOOTROM_SRC=$(shell ls $(BOOTROM_SW_DIR)/* | grep -v $(BOOTROM_FILE))
119
BOOTROM_VERILOG=$(BOOTROM_SW_DIR)/$(BOOTROM_FILE)
120
$(BOOTROM_VERILOG): $(BOOTROM_SRC)
121
        $(Q)echo; echo "\t### Generating bootup ROM ###"; echo
122
        $(Q)$(MAKE) -C $(BOOTROM_SW_DIR) $(BOOTROM_FILE)
123 6 julius
 
124 360 julius
# Suffix of file to check after each test for the string
125
TEST_OUT_FILE_SUFFIX=-general.log
126
TEST_OK_STRING=8000000d
127 6 julius
 
128 360 julius
# Dynamically generated verilog file defining configuration for various things
129
TEST_DEFINES_VLG=test-defines.v
130 57 julius
# Set V=1 when calling make to enable verbose output
131
# mainly for debugging purposes.
132
ifeq ($(V), 1)
133
Q=
134 360 julius
QUIET=
135 57 julius
else
136 360 julius
Q ?=@
137
QUIET=-quiet
138 57 julius
endif
139
 
140 360 julius
# Modelsim variables
141
MGC_VSIM=vsim
142
MGC_VLOG_COMP=vlog
143
MGC_VHDL_COMP=vcom
144
MODELSIM=modelsim
145 6 julius
 
146 360 julius
# Icarus variables
147
ICARUS_COMPILE=iverilog
148
ICARUS_RUN=vvp
149
ICARUS_SCRIPT=icarus.scr
150
ICARUS_SIM_EXE=vlogsim.elf
151
ICARUS=icarus
152 58 julius
 
153 360 julius
#Default simulator is Icarus Verilog
154
# Set SIMULATOR=modelsim to use Modelsim
155
# Set SIMULATOR=ncverilog to use Cadence's NC-Verilog - TODO
156
# Set SIMULATOR=icarus to use Icarus Verilog (Default)
157 68 julius
 
158 58 julius
SIMULATOR ?= $(ICARUS)
159
 
160 360 julius
# VPI debugging interface variables
161
VPI_SRC_C_DIR=$(BENCH_VERILOG_DIR)/vpi/c
162 397 julius
VPI_SRC_VERILOG_DIR=$(BENCH_VERILOG_DIR)/vpi/verilog
163 360 julius
VPI_SRCS=$(shell ls $(VPI_SRC_C_DIR)/*.[ch])
164 58 julius
 
165 360 julius
# Modelsim VPI compile variables
166
MODELTECH_VPILIB=msim_jp_vpi.sl
167
# Icarus VPI compile target
168
ICARUS_VPILIB=jp_vpi
169 58 julius
 
170 360 julius
#
171
# Modelsim-specific settings
172
#
173
VOPT_ARGS=$(QUIET) -suppress 2241
174 55 julius
# If VCD dump is desired, tell Modelsim not to optimise
175
# away everything.
176
ifeq ($(VCD), 1)
177 360 julius
#VOPT_ARGS=-voptargs="+acc=rnp"
178
VOPT_ARGS=+acc=rnpqv
179 55 julius
endif
180 360 julius
# VSIM commands
181
# Suppressed warnings - 3009: Failed to open $readmemh() file
182
# Suppressed warnings - 3009: Module 'blah' does not have a `timescale directive in effect, but previous modules do.
183
# Suppressed warnings - 8598: Non-positive replication multiplier inside concat. Replication will be ignored
184 397 julius
MGC_VSIM_ARGS=  -suppress 7 -suppress 3009 -suppress 8598 -c $(QUIET) -do "set StdArithNoWarnings 1; run -all; exit"
185
# Options required when VPI option used
186 360 julius
ifeq ($(VPI), 1)
187 397 julius
MGC_VPI_LIB=$(VPI_SRC_C_DIR)/$(MODELTECH_VPILIB)
188
MGC_VSIM_ARGS += -pli $(VPI_SRC_C_DIR)/$(MODELTECH_VPILIB)
189
 
190
ICARUS_VPI_LIB=$(VPI_SRC_C_DIR)/$(ICARUS_VPILIB)
191
ICARUS_VPI_ARGS=-M$(VPI_SRC_C_DIR) -m$(ICARUS_VPILIB)
192 58 julius
endif
193 397 julius
# Rule to make the VPI library for Modelsim
194
$(MGC_VPI_LIB): $(VPI_SRCS)
195 360 julius
        $(MAKE) -C $(VPI_SRC_C_DIR) $(MODELTECH_VPILIB)
196 58 julius
 
197 397 julius
# Rule to make VPI library for Icarus Verilog
198
$(ICARUS_VPI_LIB): $(VPI_SRCS)
199 360 julius
        $(MAKE) -C $(VPI_SRC_C_DIR) $(ICARUS_VPILIB)
200 77 rherveille
 
201 397 julius
# Manually add the VPI bench verilog path
202
BENCH_VERILOG_SRC_SUBDIRS += $(VPI_SRC_VERILOG_DIR)
203
 
204 360 julius
#
205
# Verilog DUT source variables
206
#
207
# A list of paths under rtl/verilog we wish to exclude for module searching
208
VERILOG_MODULES_EXCLUDE=  include components
209
VERILOG_MODULES_EXCLUDE_LIST_E=$(shell for exclude in $(VERILOG_MODULES_EXCLUDE); do echo "-e $$exclude"; done)
210
RTL_VERILOG_MODULES=$(shell ls $(RTL_VERILOG_DIR) | grep -v $(VERILOG_MODULES_EXCLUDE_LIST_E) )
211
# Specific files to exclude, currently none.
212
#VERILOG_EXCLUDE=
213
#VERILOG_EXCLUDE_LIST_E=$(shell for exclude in $(VERILOG_EXCLUDE); do echo "-e $$exclude"; done)
214
# List of verilog source files, minus excluded files
215
#RTL_VERILOG_SRC=$(shell for module in $(RTL_VERILOG_MODULES); do if [ -d $(RTL_VERILOG_DIR)/$$module ]; then ls $(RTL_VERILOG_DIR)/$$module/*.v | grep -v $(VERILOG_EXCLUDE_LIST_E); fi; done)
216
# List of verilog source files, ignoring excludes
217
RTL_VERILOG_SRC=$(shell for module in $(RTL_VERILOG_MODULES); do if [ -d $(RTL_VERILOG_DIR)/$$module ]; then ls $(RTL_VERILOG_DIR)/$$module/*.v; fi; done)
218 6 julius
 
219 360 julius
# List of verilog includes
220
RTL_VERILOG_INCLUDES=$(shell ls $(RTL_VERILOG_INCLUDE_DIR)/*.*)
221 6 julius
 
222 360 julius
print-verilog-src:
223
        @echo echo; echo "\t### Verilog source ###"; echo
224
        @echo $(RTL_VERILOG_SRC)
225 51 julius
 
226 360 julius
# Rules to make RTL we might need
227
# Expects modules, if they need making, to have their top verilog file to
228
# correspond to their module name, and the directory should have a make file
229
# and rule which works for this command.
230
# Add name of module to this list, currently only does verilog ones.
231
# Rule 'rtl' is called just before generating DUT modelsim compilation script
232
RTL_TO_CHECK=
233
rtl:
234
        $(Q)for module in $(RTL_TO_CHECK); do \
235
                $(MAKE) -C $(RTL_VERILOG_DIR)/$$module $$module.v; \
236
        done
237 6 julius
 
238 55 julius
#
239 360 julius
# VHDL DUT source variables
240 55 julius
#
241 360 julius
# VHDL modules
242
#RTL_VHDL_MODULES=$(shell ls $(RTL_VHDL_DIR))
243
# VHDL sources
244
#RTL_VHDL_SRC=$(shell for module in $(RTL_VHDL_MODULES); do if [ -d $(RTL_VHDL_DIR)/$$module ]; then ls $(RTL_VHDL_DIR)/$$module/*.vhd; fi; done)
245
#print-vhdl-src:
246
#       @echo echo; echo "\t### VHDL modules and source ###"; echo
247
#       @echo "modules: "; echo $(RTL_VHDL_MODULES); echo
248
#       @echo "source: "$(RTL_VHDL_SRC)
249 6 julius
 
250 40 julius
 
251 360 julius
# Testbench verilog source
252 362 julius
BENCH_VERILOG_SRC=$(shell ls $(BENCH_VERILOG_DIR)/*.v | grep -v $(DESIGN_NAME)_testbench )
253 40 julius
 
254 362 julius
print-bench-src:
255
        $(Q)echo "\tBench verilog source"; \
256
        echo $(BENCH_VERILOG_SRC)
257
 
258 360 julius
# Testbench source subdirectory detection
259 397 julius
BENCH_VERILOG_SRC_SUBDIRS +=$(shell for file in `ls $(BENCH_VERILOG_DIR)`; do if [ -d $(BENCH_VERILOG_DIR)/$$file ]; then echo $(BENCH_VERILOG_DIR)/$$file; fi; done)
260 40 julius
 
261 360 julius
# Compile script generation rules:
262 40 julius
 
263 360 julius
modelsim_dut.scr: rtl $(RTL_VERILOG_SRC) $(RTL_VERILOG_INCLUDES) $(BOOTROM_VERILOG)
264
        $(Q)echo "+incdir+"$(RTL_VERILOG_INCLUDE_DIR) > $@;
265
        $(Q)echo "+incdir+"$(RTL_SIM_SRC_DIR) >> $@;
266
        $(Q)echo "+incdir+"$(BOOTROM_SW_DIR) >> $@;
267 403 julius
        $(Q)echo "+incdir+"$(BENCH_VERILOG_INCLUDE_DIR) >> $@;
268 360 julius
        $(Q)echo "+libext+.v" >> $@;
269
        $(Q)for module in $(RTL_VERILOG_MODULES); do if [ -d $(RTL_VERILOG_DIR)/$$module ]; then echo "-y " $(RTL_VERILOG_DIR)/$$module >> $@; fi; done
270
        $(Q)echo >> $@
271 6 julius
 
272 360 julius
modelsim_bench.scr: $(BENCH_VERILOG_SRC)
273
        $(Q)echo "+incdir+"$(BENCH_VERILOG_DIR) > $@;
274
        $(Q)for path in $(BENCH_VERILOG_SRC_SUBDIRS); do echo "+incdir+"$$path >> $@; done
275
        $(Q)for path in $(BENCH_VERILOG_SRC_SUBDIRS); do echo "-y "$$path >> $@; done
276
        $(Q)echo "+incdir+"$(RTL_VERILOG_INCLUDE_DIR) >> $@;
277
        $(Q)echo "+incdir+"$(RTL_SIM_SRC_DIR) >> $@;
278
        $(Q)echo "+libext+.v" >> $@;
279
        $(Q)echo "-y" $(RTL_SIM_SRC_DIR) >> $@;
280
        $(Q)for vsrc in $(BENCH_VERILOG_SRC); do echo $$vsrc >> $@; done
281
        $(Q)echo >> $@
282 6 julius
 
283 360 julius
# Compile DUT into "work" library
284
work: modelsim_dut.scr #$(RTL_VHDL_SRC)
285
        $(Q)if [ ! -e $@ ]; then vlib $@; fi
286
#       $(Q)echo; echo "\t### Compiling VHDL design library ###"; echo
287
#       $(Q)vcom -93 $(QUIET) $(RTL_VHDL_SRC)
288
        $(Q)echo; echo "\t### Compiling Verilog design library ###"; echo
289
        $(Q)vlog $(QUIET) -f $< $(DUT_TOP)
290 6 julius
 
291 360 julius
# Single compile rule
292
.PHONY : $(MODELSIM)
293 397 julius
$(MODELSIM): modelsim_bench.scr $(TEST_DEFINES_VLG) $(MGC_VPI_LIB) work
294 360 julius
        $(Q)echo; echo "\t### Compiling testbench ###"; echo
295 362 julius
        $(Q)vlog $(QUIET) -nologo -incr $(BENCH_TOP) -f $<
296 360 julius
        $(Q)vopt $(QUIET) $(RTL_TESTBENCH_TOP) $(VOPT_ARGS) -o tb
297
        $(Q)echo; echo "\t### Launching simulation ###"; echo
298 397 julius
        $(Q)vsim $(MGC_VSIM_ARGS) tb
299 6 julius
 
300 360 julius
#
301
# Icarus Verilog simulator build and run rules
302
#
303
.PHONY: $(ICARUS_SCRIPT)
304
$(ICARUS_SCRIPT):  $(RTL_VERILOG_SRC) $(RTL_VERILOG_INCLUDES) $(BOOTROM_VERILOG) $(BENCH_VERILOG_SRC)
305
        $(Q)echo "# Icarus Verilog simulation script" > $@
306
        $(Q)echo "# Auto generated. Any alterations will be written over!" >> $@
307
        $(Q)echo "+incdir+"$(RTL_VERILOG_INCLUDE_DIR) > $@;
308
        $(Q)echo "+incdir+"$(RTL_SIM_SRC_DIR) >> $@;
309
        $(Q)echo "+incdir+"$(BENCH_VERILOG_DIR) >> $@;
310
        $(Q)echo "+incdir+"$(BOOTROM_SW_DIR) >> $@;
311
        $(Q)for path in $(BENCH_VERILOG_SRC_SUBDIRS); do echo "+incdir+"$$path >> $@; done
312
        $(Q)for path in $(BENCH_VERILOG_SRC_SUBDIRS); do echo "-y "$$path >> $@; done
313
        $(Q)for module in $(RTL_VERILOG_MODULES); do echo "-y " $(RTL_VERILOG_DIR)/$$module >> $@; done
314
        $(Q)echo "-y" $(RTL_SIM_SRC_DIR) >> $@;
315 362 julius
        $(Q)echo "-y" $(BENCH_VERILOG_DIR) >> $@;
316
        $(Q)echo $(BENCH_TOP) >> $@;
317 360 julius
        $(Q) echo >> $@
318 6 julius
 
319 360 julius
# Icarus design compilation rule
320
$(ICARUS_SIM_EXE): $(ICARUS_SCRIPT) $(TEST_DEFINES_VLG)
321
        $(Q)echo; echo "\t### Compiling ###"; echo
322
        $(Q) $(ICARUS_COMPILE) -s$(RTL_TESTBENCH_TOP) -c $< -o $@
323 49 julius
 
324 360 julius
# Icarus simulation run rule
325
$(ICARUS): $(ICARUS_SIM_EXE) $(ICARUS_VPI_LIB)
326
        $(Q)echo; echo "\t### Launching simulation ###"; echo
327
        $(Q) $(ICARUS_RUN) $(ICARUS_VPI_ARGS) -l ../out/$(ICARUS_RUN).log $<
328 63 julius
 
329 49 julius
 
330
 
331 360 julius
.PHONY: rtl-test
332 425 julius
rtl-test: clean-sim-test-sw sw-vmem clean-test-defines $(TEST_DEFINES_VLG) \
333 360 julius
        $(SIMULATOR)
334 6 julius
 
335 360 julius
# Run an RTL test followed by checking of generated results
336
rtl-test-with-check: rtl-test
337
        $(Q)$(MAKE) check-test-log; \
338
        if [ $$? -ne 0 ]; then \
339
                echo; echo "\t### "$(TEST)" test FAIL ###"; echo; \
340
        else \
341
                echo; echo "\t### "$(TEST)" test OK ###"; echo; \
342
        fi
343 6 julius
 
344 360 julius
# Do check, don't print anything out
345
rtl-test-with-check-no-print: rtl-test check-test-log
346 6 julius
 
347 360 julius
# Main RTL test loop
348
rtl-tests:
349
        $(Q)for test in $(TESTS); do \
350
                export TEST=$$test; \
351
                $(MAKE) rtl-test-with-check-no-print; \
352
                if [ $$? -ne 0 ]; then break; fi; \
353
                echo; echo "\t### $$test test OK ###"; echo; \
354 6 julius
        done
355
 
356
 
357 360 julius
.PHONY: check-test-log
358
check-test-log:
359
        $(Q)echo "#!/bin/bash" > $@
360
        $(Q)echo "function check-test-log { if [ \`grep -c -i "$(TEST_OK_STRING)" "$(RTL_SIM_RESULTS_DIR)"/"$(TEST)$(TEST_OUT_FILE_SUFFIX)"\` -gt 0 ]; then return 0; else return 1; fi; }" >> $@
361
        $(Q)echo "check-test-log" >> $@
362
        $(Q)chmod +x $@
363
        $(Q) echo; echo "\t### Checking simulation results for "$(TEST)" test ###"; echo;
364
        $(Q)./$@
365 6 julius
 
366 403 julius
# Include the test-defines.v generation rule
367
include ../bin/definesgen.inc
368 6 julius
 
369 360 julius
#       $(Q)for module in $(GATELEVEL_MODULES); do echo "\`define "$$module"_IS_GATELEVEL " >> $@; done
370
# More possible test defines go here
371 6 julius
 
372 403 julius
#
373
# Software make rules (called recursively)
374
#
375 51 julius
 
376 403 julius
# Path for the current test
377 393 julius
TEST_SW_DIR=$(SW_DIR)/tests/$(shell echo $(TEST) | cut -d "-" -f 1)/sim
378 6 julius
 
379 468 julius
# This file name corresponds to the VMEM file the RAM models will attempt to
380
# load via $readmemh().
381
SIM_VMEM_IMAGE ?=sram.vmem
382 6 julius
 
383 468 julius
ifeq ($(USER_ELF),)
384
ELF_FILE=$(TEST_SW_DIR)/$(TEST).elf
385
else
386
ELF_FILE=$(USER_ELF)
387
ELF_FILE_NOTDIR=$(notdir $(USER_ELF))
388
ELF_FILE_NOTDIR_BASENAME=$(basename $(ELF_FILE_NOTDIR))
389
endif
390 6 julius
 
391 468 julius
# Rules allowing user to specify a pre-existing VMEM file to load into the
392
# simulation, instead of compiling a test.
393
ifeq ($(USER_VMEM),)
394
VMEM_FILE=$(TEST_SW_DIR)/$(TEST).vmem
395
.PHONY: $(VMEM_FILE)
396
 
397
 
398
# If USER_ELF was specified, then we need a slightly different way of
399
# generating the VMEM file from it than a usual test
400
ifeq ($(USER_ELF),)
401
$(SIM_VMEM_IMAGE): $(VMEM_FILE)
402 360 julius
        $(Q)if [ -L $@ ]; then unlink $@; fi
403 468 julius
        $(Q)if [ -e $@ ]; then rm $@; fi
404 360 julius
        $(Q)ln -s $< $@
405 468 julius
else
406
$(SIM_VMEM_IMAGE): $(USER_ELF)
407
        $(Q)$(MAKE) -C $(SW_DIR)/lib \
408
        USER_ELF_BIN=`pwd`/$(ELF_FILE_NOTDIR_BASENAME).bin \
409
        USER_ELF_VMEM=`pwd`/$(ELF_FILE_NOTDIR_BASENAME).vmem \
410
        gen-user-elf-vmem
411
        $(Q)cp -v $(ELF_FILE_NOTDIR_BASENAME).vmem $@
412 6 julius
 
413 468 julius
TEST=$(ELF_FILE_NOTDIR_BASENAME)
414
endif
415
 
416
else
417
VMEM_FILE=$(USER_VMEM)
418
USER_VMEM_NOTDIR=$(notdir $(USER_VMEM))
419
TEST=$(basename $(USER_VMEM_NOTDIR))
420
 
421
$(SIM_VMEM_IMAGE): $(VMEM_FILE)
422
        cp -v $< $@
423
 
424
endif
425
 
426
 
427
 
428
 
429
.PHONY : sw-vmem sw-elf
430
sw-vmem: $(SIM_VMEM_IMAGE)
431
 
432 360 julius
$(TEST_SW_DIR)/$(TEST).vmem:
433
        $(Q) echo; echo "\t### Compiling software ###"; echo;
434
        $(Q)$(MAKE) -C $(TEST_SW_DIR) $(TEST).vmem
435 63 julius
 
436 425 julius
# Compile ELF and copy it here
437 468 julius
sw-elf: $(ELF_FILE)
438 425 julius
        $(Q)cp -v $< .
439
 
440
$(TEST_SW_DIR)/$(TEST).elf:
441
        $(Q) echo; echo "\t### Compiling software ###"; echo;
442
        $(Q)$(MAKE) -C $(TEST_SW_DIR) $(TEST).elf
443
 
444
 
445 397 julius
# Rule to force generation of the processed orpsoc-defines.h file
446
processed-verilog-headers-in-c-for-vlt:
447
        $(Q)$(MAKE) -C $(SW_DIR)/lib processed-verilog-headers
448
# Now copy the file into the Verilated model build path
449
        $(Q)cp $(SW_DIR)/lib/include/orpsoc-defines.h $(SIM_VLT_DIR)
450
 
451 435 julius
# Create test software disassembly
452
 
453
sw-dis: $(TEST_SW_DIR)/$(TEST).dis
454
        $(Q)cp -v $< .
455
 
456
$(TEST_SW_DIR)/$(TEST).dis:
457
        $(Q)$(MAKE) -C $(TEST_SW_DIR) $(TEST).dis
458
 
459
 
460 360 julius
#
461
# Cleaning rules
462
#
463 362 julius
clean: clean-sim clean-sim-test-sw clean-bootrom clean-vlt clean-out clean-sw
464 63 julius
 
465 360 julius
clean-sim:
466
        $(Q) echo; echo "\t### Cleaning simulation run directory ###"; echo;
467
        $(Q)rm -rf *.* lib_* work transcript check-test-log
468 468 julius
        $(Q) if [ -e $(VPI_SRC_C_DIR) ]; then \
469
                $(MAKE) -C $(VPI_SRC_C_DIR) clean; \
470
        fi
471 6 julius
 
472 360 julius
clean-bootrom:
473
        $(MAKE) -C $(BOOTROM_SW_DIR) clean
474 6 julius
 
475 360 julius
clean-out:
476
        $(Q)rm -rf $(RTL_SIM_RESULTS_DIR)/*.*
477 6 julius
 
478 363 julius
# Clean away verilator build path and objects in SystemC path
479 362 julius
clean-vlt:
480
        $(Q)rm -rf $(SIM_VLT_DIR)
481 363 julius
        $(Q)$(MAKE) -C $(BENCH_SYSC_SRC_DIR) -f $(BENCH_SYSC_SRC_DIR)/Modules.make clean
482 362 julius
 
483 360 julius
clean-test-defines:
484
        $(Q)rm -f $(TEST_DEFINES_VLG)
485 6 julius
 
486 360 julius
clean-sim-test-sw:
487 468 julius
        $(Q)if [ -L $(SIM_VMEM_IMAGE) ]; then unlink $(SIM_VMEM_IMAGE); fi
488 6 julius
 
489
clean-sw:
490 360 julius
        $(Q) echo; echo "\t### Cleaning simulation sw directories ###"; echo;
491 449 julius
        $(Q) $(MAKE) -C $(SW_DIR)/lib distclean
492 6 julius
 
493 36 julius
clean-rtl:
494 360 julius
        $(Q) echo; echo "\t### Cleaning generated verilog RTL ###"; echo;
495
        for module in $(RTL_TO_CHECK); do \
496
                $(MAKE) -C $(RTL_VERILOG_DIR)/$$module clean; \
497
        done
498 44 julius
 
499 360 julius
# Removes any checked out RTL
500
distclean: clean
501
        $(Q) echo; echo "\t### Cleaning generated verilog RTL ###"; echo;
502
        $(Q)for module in $(RTL_TO_CHECK); do \
503
                $(MAKE) -C $(RTL_VERILOG_DIR)/$$module distclean; \
504
        done
505 362 julius
 
506
################################################################################
507
# Verilator model build rules
508
################################################################################
509
 
510
VLT_EXE=Vorpsoc_top
511
VLT_SCRIPT=verilator.scr
512
 
513
# Script for Verilator
514
$(SIM_VLT_DIR)/$(VLT_SCRIPT): $(RTL_VERILOG_SRC) $(RTL_VERILOG_INCLUDES) $(BOOTROM_VERILOG)
515
        $(Q)echo "\tGenerating Verilator script"
516
        $(Q)echo "# Verilator sources script" > $@
517
        $(Q)echo "# Auto generated. Any alterations will be written over!" >> $@
518
        $(Q)echo "+incdir+"$(RTL_VERILOG_INCLUDE_DIR) > $@;
519
        $(Q)echo "+incdir+"$(BOOTROM_SW_DIR) >> $@;
520
        $(Q)echo "+incdir+"$(SIM_RUN_DIR) >> $@;
521
        $(Q)for module in $(RTL_VERILOG_MODULES); do echo "-y " $(RTL_VERILOG_DIR)/$$module >> $@; done
522
        $(Q)echo $(DUT_TOP) >> $@;
523
        $(Q) echo >> $@
524
 
525
 
526
SYSC_LIB_ARCH_DIR=$(shell ls $$SYSTEMC | grep "lib-")
527
 
528
 
529
# List of System C models - use this list to link the sources into the Verilator
530
# build directory
531
SYSC_MODELS=OrpsocAccess MemoryLoad
532
 
533 363 julius
ifdef VLT_LINT
534
VLT_FLAGS +=--lint-only
535
endif
536
 
537 362 julius
ifdef VLT_DEBUG
538
VLT_DEBUG_COMPILE_FLAGS = -g
539
# Enabling the following generates a TON of debugging
540
# when running verilator. Not so helpful.
541 363 julius
#VLT_FLAGS = --debug --dump-tree
542 362 julius
VLT_SYSC_DEBUG_DEFINE = VLT_DEBUG=1
543
endif
544
 
545 363 julius
# This will build a verilator model that will generate profiling information
546
# suitable for gprof
547
# Run it through gprof after exection with: gprof Vorpsoc_top > gprof.out
548
# then run this through the Verilator tool with:
549
# verilator_profcfunc gprof.out > vprof.out
550
ifdef VLT_EXECUTION_PROFILE_BUILD
551
VLT_CPPFLAGS +=-g -pg
552
# Maybe add these to VLT_CPPFLAGS: -ftest-coverage -fprofile-arcs
553
VLT_FLAGS +=-profile-cfuncs
554
endif
555
 
556
# If set on the command line we build the cycle accurate model which will
557
# generate verilator-specific profiling information. This is useful for
558
# checking the efficiency of the model - not really useful for checking code
559
# or the function of the model.
560
ifdef VLT_DO_PERFORMANCE_PROFILE_BUILD
561
VLT_CPPFLAGS += -fprofile-generate -fbranch-probabilities -fvpt -funroll-loops -fpeel-loops -ftracer
562 362 julius
else
563
VLT_CPPFLAGS +=-fprofile-use -Wcoverage-mismatch
564
endif
565
 
566 363 julius
# Set VLT_IN_GDB=1 when making if going to run the cycle accurate model
567
# executable in GDB.
568 362 julius
ifdef VLT_IN_GDB
569
VLT_CPPFLAGS +=-g -O0
570
else
571
# The default optimisation flag applied to all of the cycle accurate model files
572
VLT_CPPFLAGS +=-O3
573
endif
574
 
575
# VCD Enabled by default when building, enable it at runtime
576
VLT_FLAGS +=-trace
577
TRACE_FLAGS=-DVM_TRACE=1 -I${SYSTEMPERL}/src
578
 
579 363 julius
# Verilator tuning
580
# Inlining:
581
VLT_FLAGS +=--inline-mult 1
582
# Optimisation option for Verilator scripts
583
VLT_FLAGS +=-O3
584
# X-assign - at reset, all signals are set to random values, helps find rst bugs
585
VLT_FLAGS +=-x-assign unique
586
 
587 362 julius
VLT_TRACEOBJ = verilated_vcd_c
588
 
589 363 julius
 
590 362 julius
# This is the list of extra models we'll issue make commands for
591
# Included is the SystemPerl trace model
592
SYSC_MODELS_BUILD=$(SYSC_MODELS) $(VLT_TRACEOBJ)
593
 
594
# List of sources for rule sensitivity
595
SYSC_MODEL_SOURCES=$(shell ls $(BENCH_SYSC_SRC_DIR)/*.cpp)
596
SYSC_MODEL_SOURCES +=$(shell ls $(BENCH_SYSC_INCLUDE_DIR)/*.h)
597
 
598
VLT_MODULES_OBJS=$(shell for mod in $(SYSC_MODELS_BUILD); do echo $(SIM_VLT_DIR)/$$mod.o; done)
599
 
600
VLT_MODEL_LINKS=$(shell for SYSCMODEL in $(SYSC_MODELS); do echo $(SIM_VLT_DIR)/$$SYSCMODEL.cpp; done)
601
 
602
# Make Verilator build path if it doesn't exist
603
$(SIM_VLT_DIR):
604
        mkdir -p $@
605
 
606
# Dummy files the RTL requires: timescale.v
607
DUMMY_FILES_FOR_VLT=$(SIM_VLT_DIR)/timescale.v
608
$(DUMMY_FILES_FOR_VLT):
609
        $(Q)for file in $@; do if [ ! -e $$file ]; then touch $$file; fi; done
610
 
611 397 julius
build-vlt: rtl $(SIM_VLT_DIR) $(DUMMY_FILES_FOR_VLT) $(VLT_MODEL_LINKS) \
612
        processed-verilog-headers-in-c-for-vlt  $(SIM_VLT_DIR)/$(VLT_EXE)
613 362 julius
 
614
# Main Cycle-accurate build rule
615
prepare-vlt: build-vlt
616
        @echo;echo "\tCycle-accurate model compiled successfully"
617
        @echo;echo "\tRun the executable with the -h option for usage instructions:";echo
618
        $(SIM_VLT_DIR)/$(VLT_EXE) -h
619
        @echo;echo
620
 
621
$(SIM_VLT_DIR)/$(VLT_EXE): $(SIM_VLT_DIR)/lib$(VLT_EXE).a $(SIM_VLT_DIR)/OrpsocMain.o
622
# Final linking of the simulation executable. Order of libraries here is important!
623
        $(Q)echo; echo "\tGenerating simulation executable"; echo
624
        $(Q)cd $(SIM_VLT_DIR) && g++ $(VLT_DEBUG_COMPILE_FLAGS) $(VLT_CPPFLAGS) -I$(BENCH_SYSC_INCLUDE_DIR) -I$(SIM_VLT_DIR) -I$(VERILATOR_ROOT)/include -I$(SYSTEMC)/include -o $(VLT_EXE) -L. -L$(BENCH_SYSC_SRC_DIR) -L$(SYSTEMC)/$(SYSC_LIB_ARCH_DIR) OrpsocMain.o -l$(VLT_EXE) -lmodules -lsystemc
625
 
626
# Now compile the top level systemC "testbench" module from the systemC source path
627
$(SIM_VLT_DIR)/OrpsocMain.o: $(BENCH_SYSC_SRC_DIR)/OrpsocMain.cpp
628
        @echo; echo "\tCompiling top level SystemC testbench"; echo
629
        cd $(SIM_VLT_DIR) && g++ $(VLT_DEBUG_COMPILE_FLAGS) $(VLT_CPPFLAGS) $(TRACE_FLAGS) -I$(BENCH_SYSC_INCLUDE_DIR) -I$(SIM_VLT_DIR) -I$(VERILATOR_ROOT)/include -I$(SYSTEMC)/include -c $(BENCH_SYSC_SRC_DIR)/OrpsocMain.cpp
630
 
631
$(SIM_VLT_DIR)/lib$(VLT_EXE).a: $(SIM_VLT_DIR)/$(VLT_EXE)__ALL.a $(VLT_MODULES_OBJS) $(SIM_VLT_DIR)/verilated.o
632
# Now archive all of the libraries from verilator witht he other modules we might have
633
        @echo; echo "\tArchiving libraries into lib"$(VLT_EXE)".a"; echo
634
        $(Q)cd $(SIM_VLT_DIR) && \
635
        cp $(VLT_EXE)__ALL.a lib$(VLT_EXE).a && \
636
        ar rcs lib$(VLT_EXE).a verilated.o; \
637
        for SYSCMODEL in $(SYSC_MODELS_BUILD); do \
638
                ar rcs lib$(VLT_EXE).a $$SYSCMODEL.o; \
639
        done
640
 
641
$(SIM_VLT_DIR)/verilated.o: $(SYSC_MODEL_SOURCES)
642
        @echo; echo "\tCompiling verilated.o"; echo
643
        $(Q)cd $(SIM_VLT_DIR) && \
644
        export CXXFLAGS=$(VLT_DEBUG_COMPILE_FLAGS); \
645
        export USER_CPPFLAGS="$(VLT_CPPFLAGS)"; \
646
        export USER_LDDFLAGS="$(VLT_CPPFLAGS)"; \
647
        $(MAKE) -f $(VLT_EXE).mk verilated.o
648
 
649
print-sysmod-objs:
650
        $(Q)echo $(VLT_MODULES_OBJS):
651
 
652
$(VLT_MODULES_OBJS):
653
# Compile the module files
654
        @echo; echo "\tCompiling SystemC models"
655
        $(Q)cd $(SIM_VLT_DIR) && \
656
        for SYSCMODEL in $(SYSC_MODELS_BUILD); do \
657
                echo;echo "\t$$SYSCMODEL"; echo; \
658
                export CXXFLAGS=$(VLT_DEBUG_COMPILE_FLAGS); \
659
                export USER_CPPFLAGS="$(VLT_CPPFLAGS) -I$(BENCH_SYSC_INCLUDE_DIR)"; \
660
                export USER_LDDFLAGS="$(VLT_CPPFLAGS)"; \
661
                 $(MAKE) -f $(VLT_EXE).mk $$SYSCMODEL.o; \
662
        done
663
 
664
$(SIM_VLT_DIR)/$(VLT_EXE)__ALL.a: $(SIM_VLT_DIR)/$(VLT_EXE).mk $(SYSC_MODEL_SOURCES)
665
        @echo; echo "\tCompiling main design"; echo
666
        $(Q)cd $(SIM_VLT_DIR) && \
667
        export USER_CPPFLAGS="$(VLT_CPPFLAGS)"; \
668
        export USER_LDDFLAGS="$(VLT_CPPFLAGS)"; \
669
        $(MAKE) -f $(VLT_EXE).mk $(VLT_EXE)__ALL.a
670
 
671
$(SIM_VLT_DIR)/$(VLT_EXE).mk: $(SIM_VLT_DIR)/$(VLT_SCRIPT) $(BENCH_SYSC_SRC_DIR)/libmodules.a
672
# Now call verilator to generate the .mk files
673
        $(Q)echo; echo "\tGenerating makefiles with Verilator"; echo
674
        $(Q)cd $(SIM_VLT_DIR) && \
675 363 julius
        verilator -language 1364-2001 --top-module orpsoc_top -Mdir . -sc $(VLT_FLAGS) -I$(BENCH_SYSC_INCLUDE_DIR) -I$(BENCH_SYSC_SRC_DIR) -f $(SIM_VLT_DIR)/$(VLT_SCRIPT)
676 362 julius
 
677
# SystemC modules library
678
$(BENCH_SYSC_SRC_DIR)/libmodules.a:
679
        @echo; echo "\tCompiling SystemC modules"; echo
680
        $(Q)export VLT_CPPFLAGS="$(VLT_CPPFLAGS)"; \
681
        $(MAKE) -C $(BENCH_SYSC_SRC_DIR) -f $(BENCH_SYSC_SRC_DIR)/Modules.make $(VLT_SYSC_DEBUG_DEFINE)
682
 
683
print-vlt-model-link-paths:
684
        $(Q)echo $(VLT_MODEL_LINKS)
685
 
686
$(VLT_MODEL_LINKS):
687
# Link all the required system C model files into the verilator work dir
688
        for SYSCMODEL in $(SYSC_MODELS); do \
689
                if [ ! -e $(SIM_VLT_DIR)/$$SYSCMODEL.cpp ]; then \
690
                echo "\tLinking SystemC model $$SYSCMODEL  Verilator model build path"; \
691
                        ln -s $(BENCH_SYSC_SRC_DIR)/$$SYSCMODEL.cpp $(SIM_VLT_DIR)/$$SYSCMODEL.cpp; \
692
                        ln -s $(BENCH_SYSC_INCLUDE_DIR)/$$SYSCMODEL.h $(SIM_VLT_DIR)/$$SYSCMODEL.h; \
693
                fi; \
694
        done
695
 
696
 
697
################################################################################
698
# Verilator model test rules
699
################################################################################
700
 
701 425 julius
vlt-test: build-vlt clean-sim-test-sw sw-vmem
702 362 julius
        $(SIM_VLT_DIR)/$(VLT_EXE) $(TEST)
703
 
704
vlt-tests:
705
        $(Q)for test in $(TESTS); do \
706
                export TEST=$$test; \
707
                $(MAKE) vlt-test; \
708
                if [ $$? -ne 0 ]; then break; fi; \
709
                echo; echo "\t### $$test test OK ###"; echo; \
710
        done
711
 
712
 
713
 
714
###############################################################################
715
# Verilator profiled model build rules
716
###############################################################################
717
# To run this, first run a "make prepare-vlt VLT_DO_PROFILING=1" then do a
718
# "make clean" and then a "make prepare-vlt_profiled"
719
# This new make target copies athe results of the profiling back to the right
720
# paths before we create everything again
721
###############################################################################
722
.PHONY: prepare-vlt-profiled
723 363 julius
prepare-vlt-profiled: $(SIM_VLT_DIR)/OrpsocMain.gcda \
724
        clean-vlt-after-profile-run \
725
        rtl $(SIM_VLT_DIR) $(DUMMY_FILES_FOR_VLT) $(VLT_MODEL_LINKS) \
726
        $(SIM_VLT_DIR)/$(VLT_EXE)
727 362 julius
 
728
$(SIM_VLT_DIR)/OrpsocMain.gcda: $(SIM_VLT_DIR)/$(VLT_EXE)-for-profiling
729 397 julius
        $(MAKE) -C $(SW_DIR)/apps/dhry dhry.elf NUM_RUNS=5000
730 363 julius
#       $(SIM_VLT_DIR)/$(VLT_EXE) -f $(SW_DIR)/dhry/dhry.elf -v -l sim.log --crash-monitor
731 397 julius
        $(SIM_VLT_DIR)/$(VLT_EXE) -f $(SW_DIR)/apps/dhry/dhry.elf
732 362 julius
 
733 363 julius
# Clean all compiled things
734
clean-vlt-after-profile-run:
735
        $(Q)echo "\tCleaning away compiled cycle-accurate files"
736
        $(Q)rm -f $(SIM_VLT_DIR)/*.[oa] $(SIM_VLT_DIR)/$(VLT_EXE)
737
        $(Q)rm -f $(BENCH_SYSC_SRC_DIR)/*.[oa]
738
 
739
#.PHONY: $(SIM_VLT_DIR)/$(VLT_EXE)-for-profiling
740 362 julius
$(SIM_VLT_DIR)/$(VLT_EXE)-for-profiling:
741 363 julius
        $(MAKE) build-vlt VLT_DO_PERFORMANCE_PROFILE_BUILD=1
742 362 julius
 
743
.PHONY: vlt-restore-profileoutput
744
vlt-restore-profileoutput:
745
        @echo;echo "\tRestoring profiling outputs"; echo
746
        $(Q)mkdir -p ../vlt
747
        $(Q)cp /tmp/*.gc* $(SIM_VLT_DIR)
748
        $(Q)cp /tmp/*.gc* $(BENCH_SYSC_SRC_DIR)
749 363 julius
 
750
 
751
lint-vlt: $(SIM_VLT_DIR) rtl $(DUMMY_FILES_FOR_VLT) $(SIM_VLT_DIR)/$(VLT_SCRIPT)
752
        $(Q)echo; echo "\tLinting design with Verilator"; echo
753
        $(Q)cd $(SIM_VLT_DIR) && \
754 425 julius
        verilator -language 1364-2001 --top-module orpsoc_top --lint-only -Mdir . -sc $(VLT_FLAGS) -I$(BENCH_SYSC_INCLUDE_DIR) -I$(BENCH_SYSC_SRC_DIR) -f $(SIM_VLT_DIR)/$(VLT_SCRIPT)
755
 
756
################################################################################
757
# Architectural simulator test rules
758
################################################################################
759
 
760
ARCH_SIM_EXE ?=or32-elf-sim
761
ARCH_SIM_CFG ?= ../bin/or1ksim-orpsocv2.cfg
762
ARCH_SIM_OPTS ?= -q
763
 
764
.PHONY: rtl-test
765
sim-test: clean-sim-test-sw sw-elf
766 431 julius
        $(Q)echo; echo "\t### Launching simulation ###"; echo
767 425 julius
        $(Q)$(ARCH_SIM_EXE) $(ARCH_SIM_OPTS) -f $(ARCH_SIM_CFG) $(TEST).elf > \
768
        $(RTL_SIM_RESULTS_DIR)/$(TEST)$(TEST_OUT_FILE_SUFFIX)
769
 
770
# Run tests in simulation, check output
771
sim-test-with-check: sim-test check-test-log
772
 
773
# Main architectural simulations test loop
774
sim-tests:
775
        $(Q)for test in $(TESTS); do \
776
                export TEST=$$test; \
777
                $(MAKE) sim-test-with-check; \
778
                if [ $$? -ne 0 ]; then break; fi; \
779
                echo; echo "\t### $$test test OK ###"; echo; \
780
        done

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.