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

Subversion Repositories openrisc

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

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 475 julius
# Suppressed warnings - 3009: Module 'blah' does not have a `timescale
183
#                       directive in effect, but previous modules do.
184
# Suppressed warnings - 8598: Non-positive replication multiplier inside
185
#                       concat. Replication will be ignored
186
MGC_VSIM_ARGS=  -suppress 7 -suppress 3009 -suppress 8598 -c $(QUIET) \
187
                -do "set StdArithNoWarnings 1; run -all; exit"
188 397 julius
# Options required when VPI option used
189 360 julius
ifeq ($(VPI), 1)
190 397 julius
MGC_VPI_LIB=$(VPI_SRC_C_DIR)/$(MODELTECH_VPILIB)
191
MGC_VSIM_ARGS += -pli $(VPI_SRC_C_DIR)/$(MODELTECH_VPILIB)
192
 
193
ICARUS_VPI_LIB=$(VPI_SRC_C_DIR)/$(ICARUS_VPILIB)
194
ICARUS_VPI_ARGS=-M$(VPI_SRC_C_DIR) -m$(ICARUS_VPILIB)
195 58 julius
endif
196 397 julius
# Rule to make the VPI library for Modelsim
197
$(MGC_VPI_LIB): $(VPI_SRCS)
198 360 julius
        $(MAKE) -C $(VPI_SRC_C_DIR) $(MODELTECH_VPILIB)
199 58 julius
 
200 397 julius
# Rule to make VPI library for Icarus Verilog
201
$(ICARUS_VPI_LIB): $(VPI_SRCS)
202 360 julius
        $(MAKE) -C $(VPI_SRC_C_DIR) $(ICARUS_VPILIB)
203 77 rherveille
 
204 397 julius
# Manually add the VPI bench verilog path
205
BENCH_VERILOG_SRC_SUBDIRS += $(VPI_SRC_VERILOG_DIR)
206
 
207 360 julius
#
208
# Verilog DUT source variables
209
#
210
# A list of paths under rtl/verilog we wish to exclude for module searching
211
VERILOG_MODULES_EXCLUDE=  include components
212 475 julius
VERILOG_MODULES_EXCLUDE_LIST_E=$(shell for exclude in \
213
                $(VERILOG_MODULES_EXCLUDE); do echo "-e $$exclude"; done)
214
RTL_VERILOG_MODULES=$(shell ls $(RTL_VERILOG_DIR) | grep -v \
215
                        $(VERILOG_MODULES_EXCLUDE_LIST_E) )
216 360 julius
# Specific files to exclude, currently none.
217
#VERILOG_EXCLUDE=
218 475 julius
#VERILOG_EXCLUDE_LIST_E=$(shell for exclude in $(VERILOG_EXCLUDE); \
219
                do echo "-e $$exclude"; done)
220 360 julius
# List of verilog source files, minus excluded files
221 475 julius
#RTL_VERILOG_SRC=$(shell for module in $(RTL_VERILOG_MODULES); do \
222
        if [ -d $(RTL_VERILOG_DIR)/$$module ]; then \
223
                ls $(RTL_VERILOG_DIR)/$$module/*.v | grep -v \
224
                        $(VERILOG_EXCLUDE_LIST_E); \
225
        fi; done)
226 360 julius
# List of verilog source files, ignoring excludes
227 475 julius
RTL_VERILOG_SRC=$(shell for module in $(RTL_VERILOG_MODULES); do \
228
        if [ -d $(RTL_VERILOG_DIR)/$$module ]; then \
229
                ls $(RTL_VERILOG_DIR)/$$module/*.v; \
230
        fi; done)
231 6 julius
 
232 360 julius
# List of verilog includes
233
RTL_VERILOG_INCLUDES=$(shell ls $(RTL_VERILOG_INCLUDE_DIR)/*.*)
234 6 julius
 
235 360 julius
print-verilog-src:
236
        @echo echo; echo "\t### Verilog source ###"; echo
237
        @echo $(RTL_VERILOG_SRC)
238 51 julius
 
239 360 julius
# Rules to make RTL we might need
240
# Expects modules, if they need making, to have their top verilog file to
241
# correspond to their module name, and the directory should have a make file
242
# and rule which works for this command.
243
# Add name of module to this list, currently only does verilog ones.
244
# Rule 'rtl' is called just before generating DUT modelsim compilation script
245
RTL_TO_CHECK=
246
rtl:
247
        $(Q)for module in $(RTL_TO_CHECK); do \
248
                $(MAKE) -C $(RTL_VERILOG_DIR)/$$module $$module.v; \
249
        done
250 6 julius
 
251 55 julius
#
252 360 julius
# VHDL DUT source variables
253 55 julius
#
254 360 julius
# VHDL modules
255
#RTL_VHDL_MODULES=$(shell ls $(RTL_VHDL_DIR))
256
# VHDL sources
257 475 julius
#RTL_VHDL_SRC=$(shell for module in $(RTL_VHDL_MODULES); do \
258
        if [ -d $(RTL_VHDL_DIR)/$$module ]; then \
259
                ls $(RTL_VHDL_DIR)/$$module/*.vhd; \
260
        fi; done)
261 360 julius
#print-vhdl-src:
262
#       @echo echo; echo "\t### VHDL modules and source ###"; echo
263
#       @echo "modules: "; echo $(RTL_VHDL_MODULES); echo
264
#       @echo "source: "$(RTL_VHDL_SRC)
265 6 julius
 
266 40 julius
 
267 360 julius
# Testbench verilog source
268 475 julius
BENCH_VERILOG_SRC=$(shell ls $(BENCH_VERILOG_DIR)/*.v | grep -v \
269
        $(DESIGN_NAME)_testbench )
270 40 julius
 
271 362 julius
print-bench-src:
272
        $(Q)echo "\tBench verilog source"; \
273
        echo $(BENCH_VERILOG_SRC)
274
 
275 360 julius
# Testbench source subdirectory detection
276 475 julius
BENCH_VERILOG_SRC_SUBDIRS +=$(shell for file in `ls $(BENCH_VERILOG_DIR)`; do \
277
        if [ -d $(BENCH_VERILOG_DIR)/$$file ]; then \
278
                echo $(BENCH_VERILOG_DIR)/$$file; \
279
        fi; done)
280 40 julius
 
281 360 julius
# Compile script generation rules:
282 40 julius
 
283 475 julius
modelsim_dut.scr: rtl $(RTL_VERILOG_SRC) $(RTL_VERILOG_INCLUDES) \
284
                        $(BOOTROM_VERILOG)
285 360 julius
        $(Q)echo "+incdir+"$(RTL_VERILOG_INCLUDE_DIR) > $@;
286
        $(Q)echo "+incdir+"$(RTL_SIM_SRC_DIR) >> $@;
287
        $(Q)echo "+incdir+"$(BOOTROM_SW_DIR) >> $@;
288 403 julius
        $(Q)echo "+incdir+"$(BENCH_VERILOG_INCLUDE_DIR) >> $@;
289 360 julius
        $(Q)echo "+libext+.v" >> $@;
290 475 julius
        $(Q)for module in $(RTL_VERILOG_MODULES); do \
291
                if [ -d $(RTL_VERILOG_DIR)/$$module ]; then \
292
                        echo "-y " $(RTL_VERILOG_DIR)/$$module >> $@; \
293
                fi; done
294 360 julius
        $(Q)echo >> $@
295 6 julius
 
296 360 julius
modelsim_bench.scr: $(BENCH_VERILOG_SRC)
297
        $(Q)echo "+incdir+"$(BENCH_VERILOG_DIR) > $@;
298 475 julius
        $(Q)for path in $(BENCH_VERILOG_SRC_SUBDIRS); do \
299
                echo "+incdir+"$$path >> $@; \
300
        done
301
        $(Q)for path in $(BENCH_VERILOG_SRC_SUBDIRS); do \
302
                echo "-y "$$path >> $@; \
303
        done
304 360 julius
        $(Q)echo "+incdir+"$(RTL_VERILOG_INCLUDE_DIR) >> $@;
305
        $(Q)echo "+incdir+"$(RTL_SIM_SRC_DIR) >> $@;
306
        $(Q)echo "+libext+.v" >> $@;
307
        $(Q)echo "-y" $(RTL_SIM_SRC_DIR) >> $@;
308
        $(Q)for vsrc in $(BENCH_VERILOG_SRC); do echo $$vsrc >> $@; done
309
        $(Q)echo >> $@
310 6 julius
 
311 360 julius
# Compile DUT into "work" library
312
work: modelsim_dut.scr #$(RTL_VHDL_SRC)
313
        $(Q)if [ ! -e $@ ]; then vlib $@; fi
314
#       $(Q)echo; echo "\t### Compiling VHDL design library ###"; echo
315
#       $(Q)vcom -93 $(QUIET) $(RTL_VHDL_SRC)
316
        $(Q)echo; echo "\t### Compiling Verilog design library ###"; echo
317
        $(Q)vlog $(QUIET) -f $< $(DUT_TOP)
318 6 julius
 
319 360 julius
# Single compile rule
320
.PHONY : $(MODELSIM)
321 397 julius
$(MODELSIM): modelsim_bench.scr $(TEST_DEFINES_VLG) $(MGC_VPI_LIB) work
322 360 julius
        $(Q)echo; echo "\t### Compiling testbench ###"; echo
323 362 julius
        $(Q)vlog $(QUIET) -nologo -incr $(BENCH_TOP) -f $<
324 360 julius
        $(Q)vopt $(QUIET) $(RTL_TESTBENCH_TOP) $(VOPT_ARGS) -o tb
325
        $(Q)echo; echo "\t### Launching simulation ###"; echo
326 397 julius
        $(Q)vsim $(MGC_VSIM_ARGS) tb
327 6 julius
 
328 360 julius
#
329
# Icarus Verilog simulator build and run rules
330
#
331
.PHONY: $(ICARUS_SCRIPT)
332 475 julius
$(ICARUS_SCRIPT):  $(RTL_VERILOG_SRC) $(RTL_VERILOG_INCLUDES) \
333
                $(BOOTROM_VERILOG) $(BENCH_VERILOG_SRC)
334 360 julius
        $(Q)echo "# Icarus Verilog simulation script" > $@
335
        $(Q)echo "# Auto generated. Any alterations will be written over!" >> $@
336
        $(Q)echo "+incdir+"$(RTL_VERILOG_INCLUDE_DIR) > $@;
337
        $(Q)echo "+incdir+"$(RTL_SIM_SRC_DIR) >> $@;
338
        $(Q)echo "+incdir+"$(BENCH_VERILOG_DIR) >> $@;
339
        $(Q)echo "+incdir+"$(BOOTROM_SW_DIR) >> $@;
340 475 julius
        $(Q)for path in $(BENCH_VERILOG_SRC_SUBDIRS); do \
341
                echo "+incdir+"$$path >> $@; \
342
        done
343
        $(Q)for path in $(BENCH_VERILOG_SRC_SUBDIRS); do \
344
                echo "-y "$$path >> $@; \
345
        done
346
        $(Q)for module in $(RTL_VERILOG_MODULES); do \
347
                echo "-y " $(RTL_VERILOG_DIR)/$$module >> $@; \
348
        done
349 360 julius
        $(Q)echo "-y" $(RTL_SIM_SRC_DIR) >> $@;
350 362 julius
        $(Q)echo "-y" $(BENCH_VERILOG_DIR) >> $@;
351
        $(Q)echo $(BENCH_TOP) >> $@;
352 360 julius
        $(Q) echo >> $@
353 6 julius
 
354 360 julius
# Icarus design compilation rule
355
$(ICARUS_SIM_EXE): $(ICARUS_SCRIPT) $(TEST_DEFINES_VLG)
356
        $(Q)echo; echo "\t### Compiling ###"; echo
357
        $(Q) $(ICARUS_COMPILE) -s$(RTL_TESTBENCH_TOP) -c $< -o $@
358 49 julius
 
359 360 julius
# Icarus simulation run rule
360
$(ICARUS): $(ICARUS_SIM_EXE) $(ICARUS_VPI_LIB)
361
        $(Q)echo; echo "\t### Launching simulation ###"; echo
362
        $(Q) $(ICARUS_RUN) $(ICARUS_VPI_ARGS) -l ../out/$(ICARUS_RUN).log $<
363 63 julius
 
364 49 julius
 
365
 
366 360 julius
.PHONY: rtl-test
367 425 julius
rtl-test: clean-sim-test-sw sw-vmem clean-test-defines $(TEST_DEFINES_VLG) \
368 360 julius
        $(SIMULATOR)
369 6 julius
 
370 360 julius
# Run an RTL test followed by checking of generated results
371
rtl-test-with-check: rtl-test
372
        $(Q)$(MAKE) check-test-log; \
373
        if [ $$? -ne 0 ]; then \
374
                echo; echo "\t### "$(TEST)" test FAIL ###"; echo; \
375
        else \
376
                echo; echo "\t### "$(TEST)" test OK ###"; echo; \
377
        fi
378 6 julius
 
379 360 julius
# Do check, don't print anything out
380
rtl-test-with-check-no-print: rtl-test check-test-log
381 6 julius
 
382 360 julius
# Main RTL test loop
383
rtl-tests:
384
        $(Q)for test in $(TESTS); do \
385
                export TEST=$$test; \
386
                $(MAKE) rtl-test-with-check-no-print; \
387
                if [ $$? -ne 0 ]; then break; fi; \
388
                echo; echo "\t### $$test test OK ###"; echo; \
389 6 julius
        done
390
 
391
 
392 360 julius
.PHONY: check-test-log
393
check-test-log:
394
        $(Q)echo "#!/bin/bash" > $@
395
        $(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; }" >> $@
396
        $(Q)echo "check-test-log" >> $@
397
        $(Q)chmod +x $@
398
        $(Q) echo; echo "\t### Checking simulation results for "$(TEST)" test ###"; echo;
399
        $(Q)./$@
400 6 julius
 
401 403 julius
# Include the test-defines.v generation rule
402
include ../bin/definesgen.inc
403 6 julius
 
404 403 julius
#
405
# Software make rules (called recursively)
406
#
407 51 julius
 
408 403 julius
# Path for the current test
409 393 julius
TEST_SW_DIR=$(SW_DIR)/tests/$(shell echo $(TEST) | cut -d "-" -f 1)/sim
410 6 julius
 
411 468 julius
# This file name corresponds to the VMEM file the RAM models will attempt to
412
# load via $readmemh().
413
SIM_VMEM_IMAGE ?=sram.vmem
414 6 julius
 
415 468 julius
ifeq ($(USER_ELF),)
416
ELF_FILE=$(TEST_SW_DIR)/$(TEST).elf
417
else
418
ELF_FILE=$(USER_ELF)
419
ELF_FILE_NOTDIR=$(notdir $(USER_ELF))
420
ELF_FILE_NOTDIR_BASENAME=$(basename $(ELF_FILE_NOTDIR))
421
endif
422 6 julius
 
423 468 julius
# Rules allowing user to specify a pre-existing VMEM file to load into the
424
# simulation, instead of compiling a test.
425
ifeq ($(USER_VMEM),)
426
VMEM_FILE=$(TEST_SW_DIR)/$(TEST).vmem
427
.PHONY: $(VMEM_FILE)
428
 
429
 
430
# If USER_ELF was specified, then we need a slightly different way of
431
# generating the VMEM file from it than a usual test
432
ifeq ($(USER_ELF),)
433
$(SIM_VMEM_IMAGE): $(VMEM_FILE)
434 360 julius
        $(Q)if [ -L $@ ]; then unlink $@; fi
435 468 julius
        $(Q)if [ -e $@ ]; then rm $@; fi
436 360 julius
        $(Q)ln -s $< $@
437 468 julius
else
438
$(SIM_VMEM_IMAGE): $(USER_ELF)
439
        $(Q)$(MAKE) -C $(SW_DIR)/lib \
440
        USER_ELF_BIN=`pwd`/$(ELF_FILE_NOTDIR_BASENAME).bin \
441
        USER_ELF_VMEM=`pwd`/$(ELF_FILE_NOTDIR_BASENAME).vmem \
442
        gen-user-elf-vmem
443
        $(Q)cp -v $(ELF_FILE_NOTDIR_BASENAME).vmem $@
444 6 julius
 
445 468 julius
TEST=$(ELF_FILE_NOTDIR_BASENAME)
446
endif
447
 
448
else
449
VMEM_FILE=$(USER_VMEM)
450
USER_VMEM_NOTDIR=$(notdir $(USER_VMEM))
451
TEST=$(basename $(USER_VMEM_NOTDIR))
452
 
453
$(SIM_VMEM_IMAGE): $(VMEM_FILE)
454
        cp -v $< $@
455
 
456
endif
457
 
458
 
459
 
460
 
461
.PHONY : sw-vmem sw-elf
462
sw-vmem: $(SIM_VMEM_IMAGE)
463
 
464 360 julius
$(TEST_SW_DIR)/$(TEST).vmem:
465
        $(Q) echo; echo "\t### Compiling software ###"; echo;
466
        $(Q)$(MAKE) -C $(TEST_SW_DIR) $(TEST).vmem
467 63 julius
 
468 425 julius
# Compile ELF and copy it here
469 468 julius
sw-elf: $(ELF_FILE)
470 425 julius
        $(Q)cp -v $< .
471
 
472
$(TEST_SW_DIR)/$(TEST).elf:
473
        $(Q) echo; echo "\t### Compiling software ###"; echo;
474
        $(Q)$(MAKE) -C $(TEST_SW_DIR) $(TEST).elf
475
 
476
 
477 397 julius
# Rule to force generation of the processed orpsoc-defines.h file
478
processed-verilog-headers-in-c-for-vlt:
479
        $(Q)$(MAKE) -C $(SW_DIR)/lib processed-verilog-headers
480
# Now copy the file into the Verilated model build path
481
        $(Q)cp $(SW_DIR)/lib/include/orpsoc-defines.h $(SIM_VLT_DIR)
482
 
483 435 julius
# Create test software disassembly
484
 
485
sw-dis: $(TEST_SW_DIR)/$(TEST).dis
486
        $(Q)cp -v $< .
487
 
488
$(TEST_SW_DIR)/$(TEST).dis:
489
        $(Q)$(MAKE) -C $(TEST_SW_DIR) $(TEST).dis
490
 
491
 
492 360 julius
#
493
# Cleaning rules
494
#
495 362 julius
clean: clean-sim clean-sim-test-sw clean-bootrom clean-vlt clean-out clean-sw
496 63 julius
 
497 360 julius
clean-sim:
498
        $(Q) echo; echo "\t### Cleaning simulation run directory ###"; echo;
499
        $(Q)rm -rf *.* lib_* work transcript check-test-log
500 468 julius
        $(Q) if [ -e $(VPI_SRC_C_DIR) ]; then \
501
                $(MAKE) -C $(VPI_SRC_C_DIR) clean; \
502
        fi
503 6 julius
 
504 360 julius
clean-bootrom:
505
        $(MAKE) -C $(BOOTROM_SW_DIR) clean
506 6 julius
 
507 360 julius
clean-out:
508
        $(Q)rm -rf $(RTL_SIM_RESULTS_DIR)/*.*
509 6 julius
 
510 363 julius
# Clean away verilator build path and objects in SystemC path
511 362 julius
clean-vlt:
512
        $(Q)rm -rf $(SIM_VLT_DIR)
513 475 julius
        $(Q)$(MAKE) -C $(BENCH_SYSC_SRC_DIR) -f \
514
                $(BENCH_SYSC_SRC_DIR)/Modules.make clean
515 362 julius
 
516 360 julius
clean-test-defines:
517
        $(Q)rm -f $(TEST_DEFINES_VLG)
518 6 julius
 
519 360 julius
clean-sim-test-sw:
520 468 julius
        $(Q)if [ -L $(SIM_VMEM_IMAGE) ]; then unlink $(SIM_VMEM_IMAGE); fi
521 6 julius
 
522
clean-sw:
523 360 julius
        $(Q) echo; echo "\t### Cleaning simulation sw directories ###"; echo;
524 449 julius
        $(Q) $(MAKE) -C $(SW_DIR)/lib distclean
525 6 julius
 
526 36 julius
clean-rtl:
527 360 julius
        $(Q) echo; echo "\t### Cleaning generated verilog RTL ###"; echo;
528
        for module in $(RTL_TO_CHECK); do \
529
                $(MAKE) -C $(RTL_VERILOG_DIR)/$$module clean; \
530
        done
531 44 julius
 
532 360 julius
# Removes any checked out RTL
533
distclean: clean
534
        $(Q) echo; echo "\t### Cleaning generated verilog RTL ###"; echo;
535
        $(Q)for module in $(RTL_TO_CHECK); do \
536
                $(MAKE) -C $(RTL_VERILOG_DIR)/$$module distclean; \
537
        done
538 362 julius
 
539
################################################################################
540
# Verilator model build rules
541
################################################################################
542
 
543
VLT_EXE=Vorpsoc_top
544
VLT_SCRIPT=verilator.scr
545
 
546
# Script for Verilator
547 475 julius
$(SIM_VLT_DIR)/$(VLT_SCRIPT): $(RTL_VERILOG_SRC) $(RTL_VERILOG_INCLUDES) \
548
                                $(BOOTROM_VERILOG)
549 362 julius
        $(Q)echo "\tGenerating Verilator script"
550
        $(Q)echo "# Verilator sources script" > $@
551
        $(Q)echo "# Auto generated. Any alterations will be written over!" >> $@
552
        $(Q)echo "+incdir+"$(RTL_VERILOG_INCLUDE_DIR) > $@;
553
        $(Q)echo "+incdir+"$(BOOTROM_SW_DIR) >> $@;
554
        $(Q)echo "+incdir+"$(SIM_RUN_DIR) >> $@;
555 475 julius
        $(Q)for module in $(RTL_VERILOG_MODULES); do \
556
                echo "-y " $(RTL_VERILOG_DIR)/$$module >> $@; \
557
        done
558 362 julius
        $(Q)echo $(DUT_TOP) >> $@;
559
        $(Q) echo >> $@
560
 
561
 
562
SYSC_LIB_ARCH_DIR=$(shell ls $$SYSTEMC | grep "lib-")
563
 
564
 
565
# List of System C models - use this list to link the sources into the Verilator
566
# build directory
567
SYSC_MODELS=OrpsocAccess MemoryLoad
568
 
569 363 julius
ifdef VLT_LINT
570
VLT_FLAGS +=--lint-only
571
endif
572
 
573 362 julius
ifdef VLT_DEBUG
574
VLT_DEBUG_COMPILE_FLAGS = -g
575
# Enabling the following generates a TON of debugging
576
# when running verilator. Not so helpful.
577 363 julius
#VLT_FLAGS = --debug --dump-tree
578 362 julius
VLT_SYSC_DEBUG_DEFINE = VLT_DEBUG=1
579
endif
580
 
581 363 julius
# This will build a verilator model that will generate profiling information
582
# suitable for gprof
583
# Run it through gprof after exection with: gprof Vorpsoc_top > gprof.out
584
# then run this through the Verilator tool with:
585
# verilator_profcfunc gprof.out > vprof.out
586
ifdef VLT_EXECUTION_PROFILE_BUILD
587
VLT_CPPFLAGS +=-g -pg
588
# Maybe add these to VLT_CPPFLAGS: -ftest-coverage -fprofile-arcs
589
VLT_FLAGS +=-profile-cfuncs
590
endif
591
 
592
# If set on the command line we build the cycle accurate model which will
593
# generate verilator-specific profiling information. This is useful for
594
# checking the efficiency of the model - not really useful for checking code
595
# or the function of the model.
596
ifdef VLT_DO_PERFORMANCE_PROFILE_BUILD
597 475 julius
VLT_CPPFLAGS += -fprofile-generate -fbranch-probabilities -fvpt \
598
                -funroll-loops -fpeel-loops -ftracer
599 362 julius
else
600
VLT_CPPFLAGS +=-fprofile-use -Wcoverage-mismatch
601
endif
602
 
603 363 julius
# Set VLT_IN_GDB=1 when making if going to run the cycle accurate model
604
# executable in GDB.
605 362 julius
ifdef VLT_IN_GDB
606
VLT_CPPFLAGS +=-g -O0
607
else
608
# The default optimisation flag applied to all of the cycle accurate model files
609
VLT_CPPFLAGS +=-O3
610
endif
611
 
612
# VCD Enabled by default when building, enable it at runtime
613
VLT_FLAGS +=-trace
614
TRACE_FLAGS=-DVM_TRACE=1 -I${SYSTEMPERL}/src
615
 
616 363 julius
# Verilator tuning
617
# Inlining:
618
VLT_FLAGS +=--inline-mult 1
619
# Optimisation option for Verilator scripts
620
VLT_FLAGS +=-O3
621 475 julius
# X-assign - at reset, all signals are set to random values, helps find
622
# reset bugs
623 363 julius
VLT_FLAGS +=-x-assign unique
624
 
625 362 julius
VLT_TRACEOBJ = verilated_vcd_c
626
 
627 363 julius
 
628 362 julius
# This is the list of extra models we'll issue make commands for
629
# Included is the SystemPerl trace model
630
SYSC_MODELS_BUILD=$(SYSC_MODELS) $(VLT_TRACEOBJ)
631
 
632
# List of sources for rule sensitivity
633
SYSC_MODEL_SOURCES=$(shell ls $(BENCH_SYSC_SRC_DIR)/*.cpp)
634
SYSC_MODEL_SOURCES +=$(shell ls $(BENCH_SYSC_INCLUDE_DIR)/*.h)
635
 
636 475 julius
VLT_MODULES_OBJS=$(shell for mod in $(SYSC_MODELS_BUILD); do \
637
                echo $(SIM_VLT_DIR)/$$mod.o; \
638
        done)
639 362 julius
 
640 475 julius
VLT_MODEL_LINKS=$(shell for SYSCMODEL in $(SYSC_MODELS); do \
641
                echo $(SIM_VLT_DIR)/$$SYSCMODEL.cpp; \
642
        done)
643 362 julius
 
644
# Make Verilator build path if it doesn't exist
645
$(SIM_VLT_DIR):
646
        mkdir -p $@
647
 
648
# Dummy files the RTL requires: timescale.v
649
DUMMY_FILES_FOR_VLT=$(SIM_VLT_DIR)/timescale.v
650
$(DUMMY_FILES_FOR_VLT):
651
        $(Q)for file in $@; do if [ ! -e $$file ]; then touch $$file; fi; done
652
 
653 397 julius
build-vlt: rtl $(SIM_VLT_DIR) $(DUMMY_FILES_FOR_VLT) $(VLT_MODEL_LINKS) \
654
        processed-verilog-headers-in-c-for-vlt  $(SIM_VLT_DIR)/$(VLT_EXE)
655 362 julius
 
656
# Main Cycle-accurate build rule
657
prepare-vlt: build-vlt
658
        @echo;echo "\tCycle-accurate model compiled successfully"
659
        @echo;echo "\tRun the executable with the -h option for usage instructions:";echo
660
        $(SIM_VLT_DIR)/$(VLT_EXE) -h
661
        @echo;echo
662
 
663 475 julius
$(SIM_VLT_DIR)/$(VLT_EXE): $(SIM_VLT_DIR)/lib$(VLT_EXE).a \
664
                                $(SIM_VLT_DIR)/OrpsocMain.o
665
# Final linking of the simulation executable. Order of libraries here is
666
# important!
667 362 julius
        $(Q)echo; echo "\tGenerating simulation executable"; echo
668 475 julius
        $(Q)cd $(SIM_VLT_DIR) && \
669
                g++ $(VLT_DEBUG_COMPILE_FLAGS) \
670
                $(VLT_CPPFLAGS) -I$(BENCH_SYSC_INCLUDE_DIR) -I$(SIM_VLT_DIR) \
671
                -I$(VERILATOR_ROOT)/include -I$(SYSTEMC)/include -o $(VLT_EXE) \
672
                -L. -L$(BENCH_SYSC_SRC_DIR) -L$(SYSTEMC)/$(SYSC_LIB_ARCH_DIR) \
673
                OrpsocMain.o -l$(VLT_EXE) -lmodules -lsystemc
674 362 julius
 
675 475 julius
# Now compile the top level systemC "testbench" module from the systemC source
676
# path
677 362 julius
$(SIM_VLT_DIR)/OrpsocMain.o: $(BENCH_SYSC_SRC_DIR)/OrpsocMain.cpp
678
        @echo; echo "\tCompiling top level SystemC testbench"; echo
679 475 julius
        cd $(SIM_VLT_DIR) && \
680
        g++ $(VLT_DEBUG_COMPILE_FLAGS) $(VLT_CPPFLAGS) $(TRACE_FLAGS) \
681
        -I$(BENCH_SYSC_INCLUDE_DIR) -I$(SIM_VLT_DIR) \
682
        -I$(VERILATOR_ROOT)/include -I$(SYSTEMC)/include -c \
683
        $(BENCH_SYSC_SRC_DIR)/OrpsocMain.cpp
684 362 julius
 
685 475 julius
$(SIM_VLT_DIR)/lib$(VLT_EXE).a: $(SIM_VLT_DIR)/$(VLT_EXE)__ALL.a \
686
                $(VLT_MODULES_OBJS) $(SIM_VLT_DIR)/verilated.o
687
# Now archive all of the libraries from verilator witht he other modules we
688
# might have
689 362 julius
        @echo; echo "\tArchiving libraries into lib"$(VLT_EXE)".a"; echo
690
        $(Q)cd $(SIM_VLT_DIR) && \
691
        cp $(VLT_EXE)__ALL.a lib$(VLT_EXE).a && \
692
        ar rcs lib$(VLT_EXE).a verilated.o; \
693
        for SYSCMODEL in $(SYSC_MODELS_BUILD); do \
694
                ar rcs lib$(VLT_EXE).a $$SYSCMODEL.o; \
695
        done
696
 
697
$(SIM_VLT_DIR)/verilated.o: $(SYSC_MODEL_SOURCES)
698
        @echo; echo "\tCompiling verilated.o"; echo
699
        $(Q)cd $(SIM_VLT_DIR) && \
700
        export CXXFLAGS=$(VLT_DEBUG_COMPILE_FLAGS); \
701
        export USER_CPPFLAGS="$(VLT_CPPFLAGS)"; \
702
        export USER_LDDFLAGS="$(VLT_CPPFLAGS)"; \
703
        $(MAKE) -f $(VLT_EXE).mk verilated.o
704
 
705
print-sysmod-objs:
706
        $(Q)echo $(VLT_MODULES_OBJS):
707
 
708
$(VLT_MODULES_OBJS):
709
# Compile the module files
710
        @echo; echo "\tCompiling SystemC models"
711
        $(Q)cd $(SIM_VLT_DIR) && \
712
        for SYSCMODEL in $(SYSC_MODELS_BUILD); do \
713
                echo;echo "\t$$SYSCMODEL"; echo; \
714
                export CXXFLAGS=$(VLT_DEBUG_COMPILE_FLAGS); \
715
                export USER_CPPFLAGS="$(VLT_CPPFLAGS) -I$(BENCH_SYSC_INCLUDE_DIR)"; \
716
                export USER_LDDFLAGS="$(VLT_CPPFLAGS)"; \
717
                 $(MAKE) -f $(VLT_EXE).mk $$SYSCMODEL.o; \
718
        done
719
 
720 475 julius
$(SIM_VLT_DIR)/$(VLT_EXE)__ALL.a: $(SIM_VLT_DIR)/$(VLT_EXE).mk \
721
                $(SYSC_MODEL_SOURCES)
722 362 julius
        @echo; echo "\tCompiling main design"; echo
723
        $(Q)cd $(SIM_VLT_DIR) && \
724
        export USER_CPPFLAGS="$(VLT_CPPFLAGS)"; \
725
        export USER_LDDFLAGS="$(VLT_CPPFLAGS)"; \
726
        $(MAKE) -f $(VLT_EXE).mk $(VLT_EXE)__ALL.a
727
 
728 475 julius
$(SIM_VLT_DIR)/$(VLT_EXE).mk: $(SIM_VLT_DIR)/$(VLT_SCRIPT) \
729
                $(BENCH_SYSC_SRC_DIR)/libmodules.a
730 362 julius
# Now call verilator to generate the .mk files
731
        $(Q)echo; echo "\tGenerating makefiles with Verilator"; echo
732
        $(Q)cd $(SIM_VLT_DIR) && \
733 475 julius
        verilator -language 1364-2001 --top-module orpsoc_top -Mdir . -sc \
734
        $(VLT_FLAGS) -I$(BENCH_SYSC_INCLUDE_DIR) -I$(BENCH_SYSC_SRC_DIR) \
735
        -f $(SIM_VLT_DIR)/$(VLT_SCRIPT)
736 362 julius
 
737
# SystemC modules library
738
$(BENCH_SYSC_SRC_DIR)/libmodules.a:
739
        @echo; echo "\tCompiling SystemC modules"; echo
740
        $(Q)export VLT_CPPFLAGS="$(VLT_CPPFLAGS)"; \
741 475 julius
        $(MAKE) -C $(BENCH_SYSC_SRC_DIR) \
742
        -f $(BENCH_SYSC_SRC_DIR)/Modules.make $(VLT_SYSC_DEBUG_DEFINE)
743 362 julius
 
744
print-vlt-model-link-paths:
745
        $(Q)echo $(VLT_MODEL_LINKS)
746
 
747
$(VLT_MODEL_LINKS):
748
# Link all the required system C model files into the verilator work dir
749 476 julius
        $(Q)for SYSCMODEL in $(SYSC_MODELS); do \
750 362 julius
                if [ ! -e $(SIM_VLT_DIR)/$$SYSCMODEL.cpp ]; then \
751 476 julius
                echo \
752
        "\tLinking SystemC model $$SYSCMODEL  Verilator model build path"; \
753 475 julius
                        ln -s $(BENCH_SYSC_SRC_DIR)/$$SYSCMODEL.cpp \
754
                                $(SIM_VLT_DIR)/$$SYSCMODEL.cpp; \
755
                        ln -s $(BENCH_SYSC_INCLUDE_DIR)/$$SYSCMODEL.h \
756
                                $(SIM_VLT_DIR)/$$SYSCMODEL.h; \
757 362 julius
                fi; \
758
        done
759
 
760
 
761
################################################################################
762
# Verilator model test rules
763
################################################################################
764
 
765 425 julius
vlt-test: build-vlt clean-sim-test-sw sw-vmem
766 362 julius
        $(SIM_VLT_DIR)/$(VLT_EXE) $(TEST)
767
 
768
vlt-tests:
769
        $(Q)for test in $(TESTS); do \
770
                export TEST=$$test; \
771
                $(MAKE) vlt-test; \
772
                if [ $$? -ne 0 ]; then break; fi; \
773
                echo; echo "\t### $$test test OK ###"; echo; \
774
        done
775
 
776
 
777
 
778
###############################################################################
779
# Verilator profiled model build rules
780
###############################################################################
781 476 julius
# To run this, first run a "make prepare-vlt-profiled"
782 362 julius
# This new make target copies athe results of the profiling back to the right
783
# paths before we create everything again
784
###############################################################################
785
.PHONY: prepare-vlt-profiled
786 363 julius
prepare-vlt-profiled: $(SIM_VLT_DIR)/OrpsocMain.gcda \
787
        clean-vlt-after-profile-run \
788
        rtl $(SIM_VLT_DIR) $(DUMMY_FILES_FOR_VLT) $(VLT_MODEL_LINKS) \
789
        $(SIM_VLT_DIR)/$(VLT_EXE)
790 362 julius
 
791
$(SIM_VLT_DIR)/OrpsocMain.gcda: $(SIM_VLT_DIR)/$(VLT_EXE)-for-profiling
792 397 julius
        $(MAKE) -C $(SW_DIR)/apps/dhry dhry.elf NUM_RUNS=5000
793
        $(SIM_VLT_DIR)/$(VLT_EXE) -f $(SW_DIR)/apps/dhry/dhry.elf
794 362 julius
 
795 363 julius
# Clean all compiled things
796
clean-vlt-after-profile-run:
797
        $(Q)echo "\tCleaning away compiled cycle-accurate files"
798
        $(Q)rm -f $(SIM_VLT_DIR)/*.[oa] $(SIM_VLT_DIR)/$(VLT_EXE)
799
        $(Q)rm -f $(BENCH_SYSC_SRC_DIR)/*.[oa]
800
 
801
#.PHONY: $(SIM_VLT_DIR)/$(VLT_EXE)-for-profiling
802 362 julius
$(SIM_VLT_DIR)/$(VLT_EXE)-for-profiling:
803 363 julius
        $(MAKE) build-vlt VLT_DO_PERFORMANCE_PROFILE_BUILD=1
804 362 julius
 
805
.PHONY: vlt-restore-profileoutput
806
vlt-restore-profileoutput:
807
        @echo;echo "\tRestoring profiling outputs"; echo
808
        $(Q)mkdir -p ../vlt
809
        $(Q)cp /tmp/*.gc* $(SIM_VLT_DIR)
810
        $(Q)cp /tmp/*.gc* $(BENCH_SYSC_SRC_DIR)
811 363 julius
 
812
 
813
lint-vlt: $(SIM_VLT_DIR) rtl $(DUMMY_FILES_FOR_VLT) $(SIM_VLT_DIR)/$(VLT_SCRIPT)
814
        $(Q)echo; echo "\tLinting design with Verilator"; echo
815
        $(Q)cd $(SIM_VLT_DIR) && \
816 475 julius
        verilator -language 1364-2001 --top-module orpsoc_top --lint-only \
817
        -Mdir . -sc $(VLT_FLAGS) -I$(BENCH_SYSC_INCLUDE_DIR) \
818
        -I$(BENCH_SYSC_SRC_DIR) -f $(SIM_VLT_DIR)/$(VLT_SCRIPT)
819 425 julius
 
820
################################################################################
821
# Architectural simulator test rules
822
################################################################################
823
 
824
ARCH_SIM_EXE ?=or32-elf-sim
825 475 julius
ARCH_SIM_CFG ?= ../bin/refdesign-or1ksim.cfg
826 425 julius
ARCH_SIM_OPTS ?= -q
827
 
828
.PHONY: rtl-test
829
sim-test: clean-sim-test-sw sw-elf
830 431 julius
        $(Q)echo; echo "\t### Launching simulation ###"; echo
831 425 julius
        $(Q)$(ARCH_SIM_EXE) $(ARCH_SIM_OPTS) -f $(ARCH_SIM_CFG) $(TEST).elf > \
832
        $(RTL_SIM_RESULTS_DIR)/$(TEST)$(TEST_OUT_FILE_SUFFIX)
833
 
834
# Run tests in simulation, check output
835
sim-test-with-check: sim-test check-test-log
836
 
837
# Main architectural simulations test loop
838
sim-tests:
839
        $(Q)for test in $(TESTS); do \
840
                export TEST=$$test; \
841
                $(MAKE) sim-test-with-check; \
842
                if [ $$? -ne 0 ]; then break; fi; \
843
                echo; echo "\t### $$test test OK ###"; echo; \
844
        done

powered by: WebSVN 2.1.0

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