Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions dv/cs_registers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,41 @@ LDFLAGS = -shared
CC = $(CXX)

# Add svdpi include
ifeq ($(TOOL),vcs)
# For VCS, add include path
TOOLDIR = $(subst bin/$(TOOL),,$(shell which $(TOOL)))
INCLUDES += -I$(TOOLDIR)include
# Check if VERILATOR_ROOT is set, use it first if available
ifdef VERILATOR_ROOT
VERILATOR_INCLUDE = $(VERILATOR_ROOT)/include
else
# For Verilator, use verilator command to find root directory
ifeq ($(shell which verilator),)
$(error "Verilator not found in PATH. Please install Verilator or add it to your PATH")
# Try to find Verilator installation directory
TOOLDIR = $(subst bin/$(TOOL),,$(shell which $(TOOL) 2>/dev/null))

# Define list of possible Verilator include paths to check
VERILATOR_INCLUDE_PATHS := \
$(TOOLDIR)share/verilator/include \
$(TOOLDIR)share/verilator/include/vltstd \
/usr/share/verilator/include \
/usr/local/share/verilator/include \
/opt/verilator/share/verilator/include \
$(HOME)/verilator/include

# Find first valid include path
VERILATOR_INCLUDE := $(firstword $(foreach dir,$(VERILATOR_INCLUDE_PATHS),$(if $(wildcard $(dir)/svdpi.h),$(dir),)))

# If include path not found, provide error messages
ifeq ($(VERILATOR_INCLUDE),)
$(warning WARNING: Could not find Verilator include directory with svdpi.h)
$(warning Searched in: $(VERILATOR_INCLUDE_PATHS))
$(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")
$(warning Or set VERILATOR_ROOT environment variable pointing to your Verilator installation)
endif
VERILATOR_ROOT = $(shell verilator --getenv VERILATOR_ROOT 2>/dev/null)
ifeq ($(VERILATOR_ROOT),)
$(error "Could not determine VERILATOR_ROOT. Please make sure Verilator is properly installed")
endif

# Add appropriate includes based on tool
ifeq ($(TOOL),vcs)
INCLUDES += -I$(TOOLDIR)include
else ifeq ($(TOOL),verilator)
ifdef VERILATOR_INCLUDE
INCLUDES += -I$(VERILATOR_INCLUDE) -I$(VERILATOR_INCLUDE)/vltstd
endif
# Add both main include directory and vltstd directory where svdpi.h is located
INCLUDES += -I$(VERILATOR_ROOT)/include -I$(VERILATOR_ROOT)/include/vltstd
endif

.PHONY: all clean
Expand Down
4 changes: 2 additions & 2 deletions dv/cs_registers/tb_cs_registers.core
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ targets:
- '--trace-structs'
- '--trace-params'
- '--trace-max-array 1024'
- '-CFLAGS "-std=c++14 -Wall -DTOPLEVEL_NAME=tb_cs_registers -DVM_TRACE_FMT_FST -g"'
- '-LDFLAGS "-pthread -lutil -lelf"'
- '-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"'
- '-LDFLAGS "-pthread -lutil -lelf -fexceptions"'
- "-Wall"
- '-Wno-fatal' # Do not fail on (style) issues, only warn about them.
2 changes: 1 addition & 1 deletion examples/sw/simple_system/common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COMMON_SRCS = $(wildcard $(COMMON_DIR)/*.c)
INCS := -I$(COMMON_DIR)

# ARCH = rv32im # to disable compressed instructions
ARCH ?= rv32imc
ARCH ?= rv32imc_zicsr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind squashing this change to remove it from the commit history?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will let you know once I'm done.


ifdef PROGRAM
PROGRAM_C := $(PROGRAM).c
Expand Down
6 changes: 6 additions & 0 deletions vendor/lowrisc_ip/dv/verilator/memutil_dpi.core
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ targets:
vcs_options:
- '-CFLAGS -I../../src/lowrisc_dv_verilator_memutil_dpi_0/cpp'
- '-lelf'
verilator:
verilator_options:
- '-CFLAGS'
- '-fexceptions'
- '-LDFLAGS'
- '-fexceptions'