Skip to content

Commit b8662c2

Browse files
committed
Adding changes for targes to run on verilator
1 parent 215226b commit b8662c2

File tree

4 files changed

+43
-17
lines changed

4 files changed

+43
-17
lines changed

dv/cs_registers/Makefile

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,41 @@ LDFLAGS = -shared
2323
CC = $(CXX)
2424

2525
# Add svdpi include
26-
ifeq ($(TOOL),vcs)
27-
# For VCS, add include path
28-
TOOLDIR = $(subst bin/$(TOOL),,$(shell which $(TOOL)))
29-
INCLUDES += -I$(TOOLDIR)include
26+
# Check if VERILATOR_ROOT is set, use it first if available
27+
ifdef VERILATOR_ROOT
28+
VERILATOR_INCLUDE = $(VERILATOR_ROOT)/include
3029
else
31-
# For Verilator, use verilator command to find root directory
32-
ifeq ($(shell which verilator),)
33-
$(error "Verilator not found in PATH. Please install Verilator or add it to your PATH")
30+
# Try to find Verilator installation directory
31+
TOOLDIR = $(subst bin/$(TOOL),,$(shell which $(TOOL) 2>/dev/null))
32+
33+
# Define list of possible Verilator include paths to check
34+
VERILATOR_INCLUDE_PATHS := \
35+
$(TOOLDIR)share/verilator/include \
36+
$(TOOLDIR)share/verilator/include/vltstd \
37+
/usr/share/verilator/include \
38+
/usr/local/share/verilator/include \
39+
/opt/verilator/share/verilator/include \
40+
$(HOME)/verilator/include
41+
42+
# Find first valid include path
43+
VERILATOR_INCLUDE := $(firstword $(foreach dir,$(VERILATOR_INCLUDE_PATHS),$(if $(wildcard $(dir)/svdpi.h),$(dir),)))
44+
45+
# If include path not found, provide error messages
46+
ifeq ($(VERILATOR_INCLUDE),)
47+
$(warning WARNING: Could not find Verilator include directory with svdpi.h)
48+
$(warning Searched in: $(VERILATOR_INCLUDE_PATHS))
49+
$(warning You can manually specify it using: make build-csr-test INCLUDES="-I/path/to/verilator/include -I./env -I./rst_driver -I./reg_driver -I./model")
50+
$(warning Or set VERILATOR_ROOT environment variable pointing to your Verilator installation)
3451
endif
35-
VERILATOR_ROOT = $(shell verilator --getenv VERILATOR_ROOT 2>/dev/null)
36-
ifeq ($(VERILATOR_ROOT),)
37-
$(error "Could not determine VERILATOR_ROOT. Please make sure Verilator is properly installed")
52+
endif
53+
54+
# Add appropriate includes based on tool
55+
ifeq ($(TOOL),vcs)
56+
INCLUDES += -I$(TOOLDIR)include
57+
else ifeq ($(TOOL),verilator)
58+
ifdef VERILATOR_INCLUDE
59+
INCLUDES += -I$(VERILATOR_INCLUDE) -I$(VERILATOR_INCLUDE)/vltstd
3860
endif
39-
# Add both main include directory and vltstd directory where svdpi.h is located
40-
INCLUDES += -I$(VERILATOR_ROOT)/include -I$(VERILATOR_ROOT)/include/vltstd
4161
endif
4262

4363
.PHONY: all clean

dv/cs_registers/tb_cs_registers.core

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ targets:
121121
- '--trace-structs'
122122
- '--trace-params'
123123
- '--trace-max-array 1024'
124-
- '-CFLAGS "-std=c++14 -Wall -DTOPLEVEL_NAME=tb_cs_registers -DVM_TRACE_FMT_FST -g"'
125-
- '-LDFLAGS "-pthread -lutil -lelf"'
124+
- '-CFLAGS "-std=c++14 -Wall -DTOPLEVEL_NAME=tb_cs_registers -DVM_TRACE_FMT_FST -g -fexceptions -I$(shell verilator --getenv VERILATOR_ROOT)/include -I$(shell verilator --getenv VERILATOR_ROOT)/include/vltstd"'
125+
- '-LDFLAGS "-pthread -lutil -lelf -fexceptions"'
126126
- "-Wall"
127127
- '-Wno-fatal' # Do not fail on (style) issues, only warn about them.

examples/sw/simple_system/common/common.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ COMMON_SRCS = $(wildcard $(COMMON_DIR)/*.c)
88
INCS := -I$(COMMON_DIR)
99

1010
# ARCH = rv32im # to disable compressed instructions
11-
ARCH ?= rv32imc
11+
ARCH ?= rv32imc_zicsr
1212

1313
ifdef PROGRAM
1414
PROGRAM_C := $(PROGRAM).c
@@ -19,9 +19,9 @@ SRCS = $(COMMON_SRCS) $(PROGRAM_C) $(EXTRA_SRCS)
1919
C_SRCS = $(filter %.c, $(SRCS))
2020
ASM_SRCS = $(filter %.S, $(SRCS))
2121

22-
CC = /home/wajahat/RISCV/riscv64-unknown-elf-toolchain/riscv/bin/riscv64-unknown-elf-gcc
22+
CC = riscv32-unknown-elf-gcc
2323

24-
CROSS_COMPILE = /home/wajahat/RISCV/riscv64-unknown-elf-toolchain/riscv/bin/riscv64-unknown-elf-
24+
CROSS_COMPILE = $(patsubst %-gcc,%-,$(CC))
2525
OBJCOPY ?= $(CROSS_COMPILE)objcopy
2626
OBJDUMP ?= $(CROSS_COMPILE)objdump
2727

vendor/lowrisc_ip/dv/verilator/memutil_dpi.core

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ targets:
3030
vcs_options:
3131
- '-CFLAGS -I../../src/lowrisc_dv_verilator_memutil_dpi_0/cpp'
3232
- '-lelf'
33+
verilator:
34+
verilator_options:
35+
- '-CFLAGS'
36+
- '-fexceptions'
37+
- '-LDFLAGS'
38+
- '-fexceptions'

0 commit comments

Comments
 (0)