diff --git a/dv/cs_registers/Makefile b/dv/cs_registers/Makefile index 3a2f2658df..eaea29570d 100644 --- a/dv/cs_registers/Makefile +++ b/dv/cs_registers/Makefile @@ -23,11 +23,46 @@ LDFLAGS = -shared CC = $(CXX) # Add svdpi include -TOOLDIR = $(subst bin/$(TOOL),,$(shell which $(TOOL))) +# Check if VERILATOR_ROOT is set, use it first if available +ifdef VERILATOR_ROOT + VERILATOR_INCLUDE = $(VERILATOR_ROOT)/include +else + # 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/share/verilator/include/vltstd \ + /usr/local/share/verilator/include \ + /usr/local/share/verilator/include/vltstd \ + /opt/verilator/share/verilator/include \ + /opt/verilator/share/verilator/include/vltstd \ + $(HOME)/verilator/include \ + $(HOME)/verilator/include/vltstd + + # 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) + VERILATOR_INCLUDE = # Leave empty or set a default fallback path if applicable + endif +endif + +# Add appropriate includes based on tool ifeq ($(TOOL),vcs) INCLUDES += -I$(TOOLDIR)include -else - INCLUDES += -I$(TOOLDIR)share/verilator/include/vltstd +else ifeq ($(TOOL),verilator) + ifdef VERILATOR_INCLUDE + INCLUDES += -I$(VERILATOR_INCLUDE) -I$(VERILATOR_INCLUDE)/vltstd + endif endif .PHONY: all clean diff --git a/dv/cs_registers/tb_cs_registers.core b/dv/cs_registers/tb_cs_registers.core index 7f109d9b6a..0468bf0c44 100644 --- a/dv/cs_registers/tb_cs_registers.core +++ b/dv/cs_registers/tb_cs_registers.core @@ -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. diff --git a/examples/simple_system/ibex_simple_system.core b/examples/simple_system/ibex_simple_system.core index 11818137a2..e919e14ee1 100644 --- a/examples/simple_system/ibex_simple_system.core +++ b/examples/simple_system/ibex_simple_system.core @@ -175,7 +175,7 @@ targets: - '--trace-structs' - '--trace-params' - '--trace-max-array 1024' - - '-CFLAGS "-std=c++14 -Wall -DVM_TRACE_FMT_FST -DTOPLEVEL_NAME=ibex_simple_system -g"' + - '-CFLAGS "-std=c++14 -Wall -fexceptions -DVM_TRACE_FMT_FST -DTOPLEVEL_NAME=ibex_simple_system -g"' - '-LDFLAGS "-pthread -lutil -lelf"' - "-Wall" # RAM primitives wider than 64bit (required for ECC) fail to build in diff --git a/vendor/lowrisc_ip/dv/verilator/memutil_dpi.core b/vendor/lowrisc_ip/dv/verilator/memutil_dpi.core index a8957e16ad..ff6d97acb2 100644 --- a/vendor/lowrisc_ip/dv/verilator/memutil_dpi.core +++ b/vendor/lowrisc_ip/dv/verilator/memutil_dpi.core @@ -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'