diff --git a/.clang-format b/.clang-format index 48c14b9..a2683b8 100644 --- a/.clang-format +++ b/.clang-format @@ -38,7 +38,7 @@ BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: true BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 120 +ColumnLimit: 140 CommentPragmas: '^( IWYU pragma:| @suppress)' ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 0 diff --git a/.envrc b/.envrc index bcdccba..b0de304 100644 --- a/.envrc +++ b/.envrc @@ -5,7 +5,11 @@ if [ $distro == "CentOS" ]; then . /opt/rh/rh-python38/enable elif [ $distro == "Rocky" ]; then . /opt/rh/gcc-toolset-11/enable +elif [ $distro == "RockyLinux" ]; then + . /opt/rh/gcc-toolset-14/enable +fi +if has module; then + module load ./Modulefile fi -module load ./Modulefile layout python3 [ -f .envrc.$USER ] && . .envrc.$USER diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml new file mode 100644 index 0000000..f9bceef --- /dev/null +++ b/.github/workflows/cmake-single-platform.yml @@ -0,0 +1,46 @@ +name: Smoke Test +on: + push: + branches: [ "main", "develop" ] + pull_request: + branches: [ "main" ] + +env: + BUILD_TYPE: Release + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Sources + uses: actions/checkout@v6 + with: + submodules: true + + - name: Pull submodules + working-directory: ${{github.workspace}} + run: git submodule update --recursive --init + + - name: Cache Conan + uses: actions/cache@v4 + with: + path: ~/.conan2 + key: conan-${{ runner.os }}-unit-cpp${{ matrix.cpp_std }}-${{ hashFiles('conanfile.py') }} + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y g++ python3-pip cmake ninja-build + pip3 install -r requirements.txt + + - name: Configure + run: cmake --preset ${{env.BUILD_TYPE}} + + - name: Build + run: cmake --build ${{github.workspace}}/build/${{env.BUILD_TYPE}} --config ${{env.BUILD_TYPE}} + + - name: Smoke Test + working-directory: ${{github.workspace}} + run: ${{github.workspace}}/build/${{env.BUILD_TYPE}}/src/riscv-vp -f ${{github.workspace}}/fw/hello-world/prebuilt/hello.elf + diff --git a/.gitignore b/.gitignore index d2d7f29..14352b6 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ CMakeSettings.json /CMakeUserPresets.json /.envrc.* .clangd +/install +.gdb_history +/dbt-rise-custom diff --git a/.launch/TGC-VP interp.launch b/.launch/TGC-VP interp.launch new file mode 100644 index 0000000..11d0f2d --- /dev/null +++ b/.launch/TGC-VP interp.launch @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.launch/TGC-VP-FW-Debug dhrystone.launch b/.launch/TGC-VP-FW-Debug dhrystone.launch new file mode 100644 index 0000000..ced7812 --- /dev/null +++ b/.launch/TGC-VP-FW-Debug dhrystone.launch @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json deleted file mode 100644 index 1211532..0000000 --- a/.vscode/c_cpp_properties.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**" - ], - "defines": [], - "compilerPath": "/usr/bin/gcc", - "cStandard": "gnu17", - "cppStandard": "gnu++14", - "intelliSenseMode": "linux-gcc-x64", - "configurationProvider": "ms-vscode.cmake-tools" - } - ], - "version": 4 -} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..c15ab36 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + "recommendations": [ + "ms-vscode.cpptools-extension-pack", + "llvm-vs-code-extensions.vscode-clangd", + "eclipse-cdt.cdt-gdb-vscode", + "eclipse-cdt.memory-inspector", + "eclipse-cdt.peripheral-inspector", + + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 0cf3870..5fac938 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,22 +1,100 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "gdb", - "request": "attach", - "name": "Attach-to-gdbserver", - "executable": "./fw/hello-world/hello", - "target": ":10000", - "remote": true, + "request": "launch", + "name": "riscv-sim hello.elf", + "program": "${workspaceFolder}/build/Debug/dbt-rise-riscv/riscv-sim", + "arguments": "-f dbt-rise-riscv/contrib/fw/hello-world/hello.elf", + "cwd": "${workspaceFolder}" + }, + { + "type": "gdbtarget", + "request": "launch", + "name": "Debug hello world 32bit", + "program": "fw/hello-world/hello.elf", + "imageAndSymbols": { + "symbolFileName": "fw/hello-world/hello.elf" + }, + "target": { + "server": "${workspaceFolder}/build/RelWithDebInfo/src/riscv-vp", + "serverParameters": [ + "--isa", + "rv32gc_msu", + "-v", + "INFO", + "-f", + "fw/hello-world/hello.elf", + "-g", + "10000" + ], + "watchServerProcess": true, + "port": "10000" + }, "cwd": "${workspaceRoot}", - "valuesFormatting": "prettyPrinters", - "gdbpath": "/opt/riscv/bin/riscv32-unknown-elf-gdb", - "debugger_args": [], + "gdb": "riscv64-unknown-elf-gdb", + "openGdbConsole": false, "presentation": { - "hidden": true, + "hidden": false, + "group": "FW Debug", + "order": 2 + }, + "initCommands": [ + "b main" + ] + }, + { + "type": "gdbtarget", + "request": "launch", + "name": "Debug hello world 32bit", + "program": "fw/hello-world/hello.elf", + "imageAndSymbols": { + "symbolFileName": "fw/hello-world/hello.elf" + }, + "target": { + "server": "${workspaceFolder}/build/RelWithDebInfo/src/riscv-vp", + "serverParameters": [ + "--isa", + "rv32gc_msu", + "-v", + "INFO", + "-f", + "fw/hello-world/hello.elf", + "-g", + "10000" + ], + "watchServerProcess": true, + "port": "10000" + }, + "cwd": "${workspaceRoot}", + "gdb": "riscv64-unknown-elf-gdb", + "openGdbConsole": false, + "presentation": { + "hidden": false, + "group": "FW Debug", + "order": 2 + }, + "initCommands": [ + "b main" + ] + }, + { + "type": "gdbtarget", + "request": "attach", + "name": "Attach GDB to VP", + "program": "./fw/hello-world/hello.elf", + "imageAndSymbols": { + "symbolFileName": "./fw/hello-world/hello.elf" + }, + "target": { + "port": "10000" + }, + "cwd": "${workspaceRoot}", + "gdb": "riscv64-unknown-elf-gdb", + "openGdbConsole": false, + "presentation": { + "hidden": false, "group": "FW Debug", "order": 2 } @@ -24,30 +102,88 @@ { "type": "gdb", "request": "launch", - "name": "Launch-VP-with-gdbserver", + "name": "32bit VP with gdbserver", "cwd": "${workspaceRoot}", - "valuesFormatting": "parseText", - "target": "./build/src/tgc-vp", - "arguments": "-f fw/hello-world/hello -g 10000", - "presentation": { - "hidden": true, - "group": "FW Debug", - "order": 1 - } + "program": "${workspaceFolder}/build/Debug/src/riscv-vp", + "arguments": "--isa 'rv32gc_msu' -v INFO --disass -f fw/hello-world/hello.elf -g 10000", + "openGdbConsole": true }, { "type": "gdb", "request": "launch", - "name": "VP-Debug", + "name": "32bit VP", "cwd": "${workspaceRoot}", - "program": "${workspaceFolder}/out/build/Debug/src/riscv-vp", - "arguments": "--isa ? -f fw/hello-world/hello" + "program": "${workspaceFolder}/build/Debug/src/riscv-vp", + "arguments": "--isa 'rv32gc_msu' -v INFO -f fw/hello-world/hello.elf", + "openGdbConsole": true, + "initCommands": [ + "set breakpoint pending on", + "set breakpoint auto-hw on", + "set breakpoint always-inserted on", + "set output-radix 16" + ], + "verbose": false }, + { + "type": "gdb", + "request": "launch", + "name": "64bit VP with gdbserver", + "cwd": "${workspaceRoot}", + "program": "${workspaceFolder}/build/Debug/src/riscv-vp", + "arguments": "--isa 'rv64gc_msu' -v INFO --disass -f fw/hello-world/hello.elf -g 10000", + "openGdbConsole": true + }, + { + "type": "gdb", + "request": "launch", + "name": "TGC5 VP", + "cwd": "${workspaceRoot}", + "program": "${workspaceFolder}/build/Debug/src/riscv-vp", + "arguments": "-v DEBUG -t 3 --isa 'tgc5c_mu' -f fw/hello-world/hello.elf", + "openGdbConsole": true + }, + { + "type": "gdb", + "request": "launch", + "name": "TGC5 VP (asmjit)", + "cwd": "${workspaceRoot}", + "program": "${workspaceFolder}/build/Debug/src/riscv-vp", + "arguments": "-v DEBUG --isa 'tgc5c_mu' --backend asmjit -f fw/hello-world/hello.elf", + "openGdbConsole": true + }, + { + "type": "gdb", + "request": "launch", + "name": "RISCV-VP report ISA", + "cwd": "${workspaceRoot}", + "program": "${workspaceFolder}/build/Debug/src/riscv-vp", + "arguments": "--isa ?", + "openGdbConsole": true + }, + { + "type": "gdb", + "request": "launch", + "name": "RISCV-SIM report ISA", + "cwd": "${workspaceRoot}", + "program": "${workspaceFolder}/build/Debug/dbt-rise-riscv/riscv-sim", + "arguments": "--isa ?", + "openGdbConsole": true + } ], "compounds": [ { - "name": "FW-Debug", - "configurations": ["Launch-VP-with-gdbserver", "Attach-to-gdbserver"] + "name": "FW-Debug 32bit", + "configurations": [ + "32bit VP with gdbserver", + "Attach GDB to VP" + ] + }, + { + "name": "FW-Debug 64bit", + "configurations": [ + "64bit VP with gdbserver", + "Attach GDB to VP" + ] } ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index c0a759c..a1543ea 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,13 +5,24 @@ "debug.allowBreakpointsEverywhere": true, "editor.rulers": [ { - "column": 120, + "column": 140, "comment": "clang-format" } ], - "cmake.configureArgs": [ - "--preset", - "Debug", - "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" - ] + "editor.formatOnSave": true, + "clangd.arguments": [ + "--pretty", + "--background-index", + "--compile-commands-dir=${workspaceFolder}/build" + ], + "cmake.copyCompileCommands": "${workspaceFolder}/build/compile_commands.json", + "cmake.options.statusBarVisibility": "hidden", + "cmake.options.advanced": { + "configure": { + "projectStatusVisibility": "visible" + }, + "build": { + "statusBarVisibility": "visible" + } + } } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 18fdf26..5b079fd 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,9 +2,65 @@ "version": "2.0.0", "tasks": [ { - "label": "CMake-and-make", + "label": "Build 32bit FW", "type": "shell", - "command": "source .venv/bin/activate && cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON && cmake --build build", + "command": "make -C fw/hello-world clean all", + "problemMatcher": [], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "dedicated", + "showReuseMessage": false, + "clear": true + } + }, +{ + "label": "Build 64bit FW", + "type": "shell", + "command": "make -C fw/hello-world RISCV_ARCH=rv64imc RISCV_ABI=lp64 clean all", + "problemMatcher": [], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "dedicated", + "showReuseMessage": false, + "clear": true + } + }, + { + "label": "Run 32bit VP", + "type": "shell", + "command": "build/Debug/src/riscv-vp --isa 'rv32gc|msu_vp' -f fw/hello-world/hello.elf", + "problemMatcher": [], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "dedicated", + "showReuseMessage": false, + "clear": true + } + }, + { + "label": "Run 64bit VP", + "type": "shell", + "command": "build/Debug/src/riscv-vp --isa 'rv64gc|msu_vp' -f fw/hello-world/hello.elf", + "problemMatcher": [], + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "dedicated", + "showReuseMessage": false, + "clear": true + } + }, + { + "label": "Run 32bit VP with GDB-Server", + "type": "shell", + "command": "build/Debug/src/riscv-vp --isa 'rv32gc|msu_vp' -f fw/hello-world/hello.elf -g 10000", "problemMatcher": [], "presentation": { "echo": true, @@ -14,43 +70,11 @@ "showReuseMessage": false, "clear": true }, - "group": { - "kind": "build", - "isDefault": true - } }, { - "label": "Build-FW", + "label": "Run 64bit VP with GDB-Server", "type": "shell", - "command": "cd fw/hello-world/ && make", - "problemMatcher": [], - "presentation": { - "echo": true, - "reveal": "always", - "focus": true, - "panel": "dedicated", - "showReuseMessage": false, - "clear": true - } - }, - { - "label": "Execute-VP", - "type": "shell", - "command": "build/src/tgc-vp -f fw/hello-world/hello -p pctrace=contrib/TGC_C_cycles.json", - "problemMatcher": [], - "presentation": { - "echo": true, - "reveal": "always", - "focus": true, - "panel": "dedicated", - "showReuseMessage": false, - "clear": true - } - }, - { - "label": "VP-GDB-Server", - "type": "shell", - "command": "build/src/tgc-vp -f fw/hello-world/hello -g 10000", + "command": "build/Debug/src/riscv-vp --isa 'rv64gc|msu_vp' -v TRACEALL -f fw/hello-world/hello.elf -g 10000 |& tee run.log", "problemMatcher": [], "presentation": { "echo": true, diff --git a/CMakeLists.txt b/CMakeLists.txt index 7418014..ce8212c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ project(riscv-vp LANGUAGES C CXX VERSION 1.0.0) option(LIBS_ONLY "Just build the shared libraries needed to build the VP" OFF) option(ENABLE_COVERAGE "Enable code coverage" OFF) option(ENABLE_SANITIZER "Enable address sanitizer" OFF) +option(ENABLE_CLANGFORMAT "Enable code formatting using clang-format." OFF) option(ENABLE_CLANGTIDY "Enable static analysis with clang-tidy." OFF) option(ENABLE_FW_BUILD "Enable build of firmware of MIRES Firmware repo." OFF) option(ENABLE_GPROF "Enable gprof profiling" OFF) @@ -20,8 +21,8 @@ include(GNUInstallDirs) # add address sanitizer if(ENABLE_SANITIZER) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address,thread") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address,thread") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") endif() @@ -77,9 +78,12 @@ if(NOT LIBS_ONLY) add_subdirectory(src) endif() -find_package(ClangFormat) +if(ENABLE_CLANGFORMAT) + set(CLANG_FORMAT_EXCLUDE_PATTERNS "/scc/" "/build/" "/.direnv/") + find_package(ClangFormat) +endif() -if(FW_BUILD) +if(ENABLE_FW_BUILD) include(FetchContent) set(FETCHCONTENT_BASE_DIR ${CMAKE_CURRENT_BINARY_DIR}/..) FetchContent_Declare( diff --git a/CMakePresets.json b/CMakePresets.json index 7128e62..8b236ee 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,11 +15,14 @@ "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { "CMAKE_POLICY_DEFAULT_CMP0091": "NEW", - "CMAKE_CXX_STANDARD": "20", + "CMAKE_CXX_STANDARD": "17", "CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "scc/cmake/conan_provider.cmake", - "WITH_TCC": "OFF" + "CONAN_HOST_PROFILE": "auto-cmake", + "CONAN_BUILD_PROFILE": "conan_host_profile", + "CMAKE_EXECUTE_PROCESS_COMMAND_ECHO": "STDOUT", + "WITH_ASMJIT": "OFF" } }, { diff --git a/Linux.code-workspace b/Linux.code-workspace new file mode 100644 index 0000000..39c5ea3 --- /dev/null +++ b/Linux.code-workspace @@ -0,0 +1,13 @@ +{ + "folders": [ + { + "path": "build/Linux4TGC/buildroot" + }, + { + "path": "build/Linux4TGC/opensbi" + }, + { + "path": "build/Linux4TGC/linux" + } + ] +} \ No newline at end of file diff --git a/Modulefile b/Modulefile index c04143a..d5cc444 100644 --- a/Modulefile +++ b/Modulefile @@ -12,4 +12,4 @@ if { $distro == "CentOS" && ![info exists ::env(PROJECT)] && ![info exists ::env puts stderr "Don't forget to execute 'scl enable devtoolset-7 llvm-toolset-7 bash'" } -module load tools/gcc-riscv64-unknown-elf/13 tools/cmake/3.28 tools/utilities \ No newline at end of file +module load tools/gcc-riscv64-unknown-elf/13 tools/cmake/3.28 tools/utilities tools/vscode diff --git a/conanfile.py b/conanfile.py index 5a25656..0c6a8ea 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,6 +12,7 @@ class Pkg(ConanFile): ) default_options = { "llvm-core/*:targets": "X86", + "llvm-core/*:components": "Native", "boost/*:fPIC": "True", "boost/*:header_only": "False", "boost/*:without_contract": "True", @@ -33,7 +34,7 @@ class Pkg(ConanFile): "boost/*:without_timer": "True", "boost/*:without_type_erasure": "True", "boost/*:without_wave": "True", - "systemc/*:shared": "True" + "systemc/*:shared": "False", } def requirements(self): @@ -46,7 +47,7 @@ class Pkg(ConanFile): self.requires("lz4/1.9.3") self.requires("yaml-cpp/0.8.0") self.requires("jsoncpp/1.9.5") - self.requires("zlib/1.2.12") + self.requires("zlib/1.3.1") self.requires("asmjit/cci.20240531") if "WITH_LLVM" in os.environ: self.requires("llvm-core/19.1.7") diff --git a/dbt-rise-core b/dbt-rise-core index 2627112..97c8150 160000 --- a/dbt-rise-core +++ b/dbt-rise-core @@ -1 +1 @@ -Subproject commit 2627112886005ba7e7415972bd9e76424c219e91 +Subproject commit 97c815024fab76fe09738f7f5242259aa3ad786c diff --git a/dbt-rise-riscv b/dbt-rise-riscv index a13689b..e187284 160000 --- a/dbt-rise-riscv +++ b/dbt-rise-riscv @@ -1 +1 @@ -Subproject commit a13689b3826b4f7b27fa400208599184e3956580 +Subproject commit e18728450167372fc75a6d430ad059978d66ed75 diff --git a/fw/.gitignore b/fw/.gitignore index 0e8815f..105c692 100644 --- a/fw/.gitignore +++ b/fw/.gitignore @@ -1 +1 @@ -/fir +/bsp diff --git a/fw/hello-world/.gitignore b/fw/hello-world/.gitignore index ebea2da..3c1acc1 100644 --- a/fw/hello-world/.gitignore +++ b/fw/hello-world/.gitignore @@ -1,3 +1,3 @@ -/hello -/hello.dis -/firmware.map +/*.elf +/*.dis +/*.map diff --git a/fw/hello-world/Makefile b/fw/hello-world/Makefile index c7efb06..47ca309 100644 --- a/fw/hello-world/Makefile +++ b/fw/hello-world/Makefile @@ -2,16 +2,18 @@ TARGET = hello C_SRCS = $(wildcard *.c) HEADERS = $(wildcard *.h) -CFLAGS += -O0 -g +CFLAGS += -Og -g -BOARD=tgc_vp -LINK_TARGET=link +BOARD=riscv_vp +LINK_TARGET=rom RISCV_ARCH:=rv32imc RISCV_ABI:=ilp32 -LDFLAGS := -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) +#RISCV_ARCH:=rv64imc +#RISCV_ABI:=lp64 +LDFLAGS := -g -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -compiler := $(shell which riscv32-unknown-elf-gcc) +compiler := $(shell which riscv64-unknown-elf-gcc) TOOL_DIR=$(dir $(compiler)) -BSP_BASE = ../bsp +BSP_BASE ?= ../bsp include $(BSP_BASE)/env/common-gcc.mk diff --git a/fw/hello-world/prebuilt/hello.elf b/fw/hello-world/prebuilt/hello.elf index 5f9677b..4162422 100755 Binary files a/fw/hello-world/prebuilt/hello.elf and b/fw/hello-world/prebuilt/hello.elf differ diff --git a/pysysc/tgc-vp-toplevel.py b/pysysc/tgc-vp-toplevel.py index b1a3b9f..bf8bee0 100755 --- a/pysysc/tgc-vp-toplevel.py +++ b/pysysc/tgc-vp-toplevel.py @@ -33,17 +33,18 @@ pysysc.load_systemc() ############################################################################### scc.load_lib(project_dir) ############################################################################### -logging.debug("Loading TGC-VP Peripherals libs") +logging.debug("Loading RISCV-VP Peripherals libs") pysysc.add_include_path(os.path.join(project_dir, 'vpvper')) pysysc.add_library('sifive.h', 'libvpvper_sifive.so', project_dir) +pysysc.add_library('sifive.h', 'libvpvper_minres.so', project_dir) ############################################################################### logging.debug("Loading TGC-ISS") -pysysc.add_include_path(os.path.join(project_dir, 'tgc-iss/dbt-rise-tgc/incl/sysc')) -pysysc.add_library('core_complex.h', 'libdbt-rise-tgc_sc.so', project_dir) +pysysc.add_include_path(os.path.join(project_dir, 'iss/dbt-rise-riscv/incl/sysc')) +pysysc.add_library('core_complex.h', 'libdbt-rise-riscv.so', project_dir) ############################################################################### # Include section ############################################################################### -cppyy.include(os.path.join(project_dir, 'src/tgfs_vp/rst_gen.h')) +cppyy.include(os.path.join(project_dir, 'src/vp/rst_gen.h')) ############################################################################### # configure ############################################################################### diff --git a/scc b/scc index 3179717..4db09b1 160000 --- a/scc +++ b/scc @@ -1 +1 @@ -Subproject commit 3179717f71478bf25f11a3961808fa7920ae7932 +Subproject commit 4db09b165dc483bddad94874eb9400a1fe97b789 diff --git a/src/CLIParser.cpp b/src/CLIParser.cpp index 8109434..9861815 100644 --- a/src/CLIParser.cpp +++ b/src/CLIParser.cpp @@ -28,6 +28,7 @@ CLIParser::CLIParser(int argc, char* argv[]) // --help option if(vm_.count("help")) { std::cout << "DBT-RISE-TGC based virtual platform of TGC cores" << std::endl << desc << std::endl; + exit(0); } po::notify(vm_); // throws on error, so do after help in case there are any problems valid = true; @@ -40,15 +41,10 @@ CLIParser::CLIParser(int argc, char* argv[]) } auto log_level = vm_["verbose"].as(); auto log_level_num = static_cast(log_level); - LOGGER(DEFAULT)::reporting_level() = logging::as_log_level(log_level_num > 6 ? 6 : log_level_num); - ; - LOGGER(DEFAULT)::print_time() = false; - LOG_OUTPUT(DEFAULT)::ostream() = &std::cout; - LOGGER(connection)::reporting_level() = - logging::as_log_level(log_level_num > 4 ? log_level_num - 1 : log_level_num); - ; - LOGGER(connection)::print_time() = false; - LOG_OUTPUT(connection)::ostream() = &std::cout; + auto level = logging::as_log_level(log_level_num > 6 ? 6 : log_level_num); + LOGGER(DEFAULT)::set_reporting_level(level); + LOGGER(connection)::set_reporting_level(level); + LOGGER(dbt_rise_iss)::set_reporting_level(level); /////////////////////////////////////////////////////////////////////////// // configure logging /////////////////////////////////////////////////////////////////////////// @@ -61,8 +57,8 @@ CLIParser::CLIParser(int argc, char* argv[]) scc::stream_redirection cerr_redir(std::cerr, scc::log::ERROR); sc_core::sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", sc_core::SC_DO_NOTHING); sc_core::sc_report_handler::set_actions(sc_core::SC_ID_MORE_THAN_ONE_SIGNAL_DRIVER_, sc_core::SC_DO_NOTHING); - sc_core::sc_report_handler::set_actions(sc_core::SC_ERROR, sc_core::SC_LOG | sc_core::SC_CACHE_REPORT | - sc_core::SC_DISPLAY | sc_core::SC_STOP); + sc_core::sc_report_handler::set_actions(sc_core::SC_ERROR, + sc_core::SC_LOG | sc_core::SC_CACHE_REPORT | sc_core::SC_DISPLAY | sc_core::SC_STOP); } void CLIParser::build() { @@ -86,13 +82,13 @@ void CLIParser::build() { "enable gdb server and specify port to use") ("backend", po::value()->default_value("interp"), "the ISS backend to use, options are: interp, tcc") - ("isa", po::value()->default_value("rv32imac"), + ("isa", po::value()->default_value("rv32imac_m"), "core or isa name to use for simulation, use '?' to get list") ("dump-ir", "dump the intermediate representation") - ("dump-structure", po::value(), - "dump model structure to ELK file") - ("quantum", po::value(), + ("dump-structure", po::value(), + "dump model structure to ELK file") + ("quantum", po::value()->default_value(100), "SystemC quantum time in ns") ("reset,r", po::value(), "reset address") @@ -104,9 +100,11 @@ void CLIParser::build() { "set th ename of the trace file") ("max_time,m", po::value(), "maximum time to run") + ("parameter,p", po::value>(), + "parameter to set, value has the form of =") ("config-file,c", po::value()->default_value(""), "read configuration from file") - ("plugin,p", po::value>(), + ("plugin", po::value>(), "plugin(s) to activate") ("dump-config,dc", po::value()->default_value(""), "dump configuration to file file"); diff --git a/src/mcount.c b/src/mcount.c new file mode 100644 index 0000000..b762e07 --- /dev/null +++ b/src/mcount.c @@ -0,0 +1,9 @@ +/* The canonical name for the function is `_mcount' in both C and asm, + but some old asm code might assume it's `mcount'. */ +void _mcount (void); +weak_alias (_mcount, mcount); + +void _mcount (void) +{ + mcount_internal ((u_long) __builtin_return_address (1), (u_long) __builtin_return_address(0)); +} diff --git a/src/sc_main.cpp b/src/sc_main.cpp index 21c2276..f432a30 100644 --- a/src/sc_main.cpp +++ b/src/sc_main.cpp @@ -20,9 +20,10 @@ #include "vp/tb.h" #include +#include +#include #include #include -#include #ifdef ERROR #undef ERROR #endif @@ -31,14 +32,20 @@ const std::string core_path{"tb.top.core_complex"}; using namespace sysc; using namespace sc_core; -namespace po = boost::program_options; namespace { const size_t ERRORR_IN_COMMAND_LINE = 1; const size_t SUCCESS = 0; } // namespace +jmp_buf abrt; +void ABRThandler(int sig) { longjmp(abrt, sig); } + int sc_main(int argc, char* argv[]) { + signal(SIGINT, ABRThandler); + signal(SIGABRT, ABRThandler); + signal(SIGSEGV, ABRThandler); + signal(SIGTERM, ABRThandler); /////////////////////////////////////////////////////////////////////////// // SystemC >=2.2 got picky about multiple drivers so disable check /////////////////////////////////////////////////////////////////////////// @@ -66,33 +73,37 @@ int sc_main(int argc, char* argv[]) { /////////////////////////////////////////////////////////////////////////// scc::configurer cfg(parser.get("config-file")); /////////////////////////////////////////////////////////////////////////// + // process CLI paramter settings + /////////////////////////////////////////////////////////////////////////// + if(parser.is_set("parameter")) + for(auto& p : parser.get>("parameter")) { + auto token = util::split(p, '='); + if(token.size() == 2) + cfg.set_value_from_str(token[0], token[1]); + else + SCCERR() << "Invalid parameter specification '" << p << "', should be '='"; + } + /////////////////////////////////////////////////////////////////////////// // set up tracing & transaction recording /////////////////////////////////////////////////////////////////////////// - std::unique_ptr tracer; if(auto trace_level = parser.get("trace-level")) { auto file_name = parser.get("trace-file"); - auto enable_sig_trace = (trace_level & 0x1) != 0; // bit0 enables sig trace - auto tx_trace_type = - static_cast(trace_level >> 1); // bit3-bit1 define the kind of transaction trace auto trace_default_on = parser.is_set("trace-default-on"); - if(parser.is_set("trace-default-off")) - cfg.set_value("scc_tracer.default_trace_enable", false); + auto enable_tx_trace = static_cast(trace_level & 0x2); + cfg.set_value("scc_tracer.default_trace_enable", !parser.is_set("trace-default-off")); cfg.set_value("scc_tracer.tx_trace_type", static_cast(scc::tracer::file_type::FTR)); cfg.set_value("scc_tracer.sig_trace_type", static_cast(scc::tracer::file_type::FST)); - tracer = scc::make_unique(file_name, tx_trace_type, enable_sig_trace); + tracer = scc::make_unique(file_name, enable_tx_trace, static_cast(trace_level & 0x1)); + if(enable_tx_trace) + cfg.set_value(core_path + ".enable_instr_trace", true); } /////////////////////////////////////////////////////////////////////////// // instantiate top level /////////////////////////////////////////////////////////////////////////// auto i_system = scc::make_unique("tb"); /////////////////////////////////////////////////////////////////////////// - // add non-implemented 'enableTracing' properties - /////////////////////////////////////////////////////////////////////////// - if(tracer) - tracer->add_control(); - /////////////////////////////////////////////////////////////////////////// - // dump configuration if requested + // dump configuration if requested and/or structure /////////////////////////////////////////////////////////////////////////// if(parser.get("dump-config").size() > 0) { std::ofstream of{parser.get("dump-config")}; @@ -102,8 +113,7 @@ int sc_main(int argc, char* argv[]) { cfg.configure(); std::unique_ptr dumper; if(parser.is_set("dump-structure")) - dumper.reset( - new scc::hierarchy_dumper(parser.get("dump-structure"), scc::hierarchy_dumper::D3JSON)); + dumper.reset(new scc::hierarchy_dumper(parser.get("dump-structure"), scc::hierarchy_dumper::D3JSON)); /////////////////////////////////////////////////////////////////////////// // overwrite config with command line settings /////////////////////////////////////////////////////////////////////////// @@ -121,13 +131,11 @@ int sc_main(int argc, char* argv[]) { tlm::tlm_global_quantum::instance().set(sc_core::sc_time(parser.get("quantum"), sc_core::SC_NS)); if(parser.is_set("reset")) { auto str = parser.get("reset"); - uint64_t start_address = - str.find("0x") == 0 ? std::stoull(str.substr(2), nullptr, 16) : std::stoull(str, nullptr, 10); + uint64_t start_address = str.find("0x") == 0 ? std::stoull(str.substr(2), nullptr, 16) : std::stoull(str, nullptr, 10); cfg.set_value(core_path + ".reset_address", start_address); } if(parser.is_set("disass")) { cfg.set_value(core_path + ".enable_disass", true); - LOGGER(disass)::reporting_level() = logging::INFO; auto file_name = parser.get("disass"); if(file_name.length() > 0) { LOG_OUTPUT(disass)::stream() = fopen(file_name.c_str(), "w"); @@ -138,15 +146,19 @@ int sc_main(int argc, char* argv[]) { /////////////////////////////////////////////////////////////////////////// // run simulation /////////////////////////////////////////////////////////////////////////// - try { - if(parser.is_set("max_time")) { - sc_core::sc_start(scc::parse_from_string(parser.get("max_time"))); - } else - sc_core::sc_start(); - if(!sc_core::sc_end_of_simulation_invoked()) - sc_core::sc_stop(); - } catch(sc_core::sc_report& rep) { - sc_core::sc_report_handler::get_handler()(rep, sc_core::SC_DISPLAY | sc_core::SC_STOP); + if(auto res = setjmp(abrt)) { + SCCERR() << "Simulation aborted with signal " << res << "!"; + } else { + try { + if(parser.is_set("max_time")) { + sc_core::sc_start(scc::parse_from_string(parser.get("max_time"))); + } else + sc_core::sc_start(); + if(sc_core::sc_start_of_simulation_invoked() && !sc_core::sc_end_of_simulation_invoked()) + sc_core::sc_stop(); + } catch(sc_core::sc_report& rep) { + sc_core::sc_report_handler::get_handler()(rep, sc_core::SC_DISPLAY | sc_core::SC_STOP); + } } return 0; } diff --git a/src/vp/system.cpp b/src/vp/system.cpp index ab0069b..1ec4e78 100644 --- a/src/vp/system.cpp +++ b/src/vp/system.cpp @@ -5,7 +5,6 @@ */ #include "system.h" - #include #include #include @@ -17,18 +16,18 @@ using namespace vpvper::minres; system::system(sc_core::sc_module_name nm) : sc_core::sc_module(nm) -, NAMED(ahb_router, 3, 2) +, NAMED(ahb_router, 5, 2) , NAMED(apbBridge, PipelinedMemoryBusToApbBridge_map.size(), 1) { + mtime_clk = (1.0 / 32768) * 1_sec; + core_complex.ibus(ahb_router.target[0]); core_complex.dbus(ahb_router.target[1]); - ahb_router.initiator.at(0)(qspi.xip_sck); - ahb_router.set_target_range(0, 0xE0000000, 16_MB); - ahb_router.initiator.at(1)(mem_ram.target); - ahb_router.set_target_range(1, 0xC0000000, 128_kB); - ahb_router.initiator.at(2)(apbBridge.target[0]); - ahb_router.set_target_range(2, 0xF0000000, 256_MB); - + ahb_router.bind_target(mem_ram.target, 1, 0x00000000, 128_kB); + ahb_router.bind_target(apbBridge.target[0], 2, 0x10000000, 128_MB); + ahb_router.bind_target(eth0.socket, 3, 0x18000000, 4_KiB); + ahb_router.bind_target(eth1.socket, 4, 0x18001000, 4_KiB); + ahb_router.bind_target(qspi.xip_sck, 0, 0x20000000, 16_MB); size_t i = 0; for(const auto& e : PipelinedMemoryBusToApbBridge_map) { apbBridge.initiator.at(i)(e.target); @@ -44,6 +43,8 @@ system::system(sc_core::sc_module_name nm) qspi.clk_i(clk_i); core_complex.clk_i(clk_i); // mem_ram.clk_i(clk_i); + eth0.clk_i(clk_i); + eth1.clk_i(clk_i); gpio0.rst_i(rst_s); uart0.rst_i(rst_s); @@ -52,10 +53,14 @@ system::system(sc_core::sc_module_name nm) irq_ctrl.rst_i(rst_s); qspi.rst_i(rst_s); core_complex.rst_i(rst_s); + eth0.rst_i(rst_s); + eth1.rst_i(rst_s); - aclint.mtime_int_o(mtime_int_s); - aclint.msip_int_o(msip_int_s); - irq_ctrl.irq_o(core_int_s); + aclint.mtime_clk_i(mtime_clk); + aclint.mtime_o(mtime_s); + aclint.mtime_int_o[0](clint_int_s[sysc::riscv::TIMER_IRQ]); + aclint.msip_int_o[0](clint_int_s[sysc::riscv::SW_IRQ]); + irq_ctrl.irq_o(clint_int_s[sysc::riscv::EXT_IRQ]); irq_ctrl.pending_irq_i(irq_int_s); uart0.irq_o(irq_int_s[0]); @@ -63,10 +68,8 @@ system::system(sc_core::sc_module_name nm) timer0.interrupt_o[1](irq_int_s[2]); qspi.irq_o(irq_int_s[3]); - core_complex.timer_irq_i(mtime_int_s); - core_complex.ext_irq_i(core_int_s); - core_complex.local_irq_i(local_int_s); - core_complex.sw_irq_i(msip_int_s); + core_complex.mtime_i(mtime_s); + core_complex.clint_irq_i(clint_int_s); gpio0.pins_i(pins_i); gpio0.pins_o(pins_o); diff --git a/src/vp/system.h b/src/vp/system.h index 3ae7b54..1d03222 100644 --- a/src/vp/system.h +++ b/src/vp/system.h @@ -7,8 +7,10 @@ #ifndef SRC_VP_SYSTEM_H_ #define SRC_VP_SYSTEM_H_ +#include "tlm/scc/quantum_keeper.h" #include #include +#include #include #include #include @@ -18,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +50,7 @@ public: system(sc_core::sc_module_name nm); private: +#include "../vp/gen/PipelinedMemoryBusToApbBridge.h" // IWYU pragma: keep sysc::riscv::core_complex<> core_complex{"core_complex"}; scc::router<> ahb_router, apbBridge; vpvper::minres::gpio_tl gpio0{"gpio0"}; @@ -55,19 +59,19 @@ private: vpvper::minres::aclint_tl aclint{"aclint"}; vpvper::minres::irq_tl irq_ctrl{"irq_ctrl"}; vpvper::minres::qspi_tl qspi{"qspi"}; + vpvper::minres::ethmac eth0{"eth0"}; + vpvper::minres::ethmac eth1{"eth1"}; scc::memory<128_kB, scc::LT> mem_ram{"mem_ram"}; scc::memory<8_kB, scc::LT> boot_rom{"boot_rom"}; - sc_core::sc_signal rst_s{"rst_s"}, mtime_int_s{"mtime_int_s"}, - msip_int_s{"msip_int_s"}; - - sc_core::sc_vector> irq_int_s{"irq_int_s", 32}, - local_int_s{"local_int_s", 16}; - sc_core::sc_signal core_int_s{"core_int_s"}; + sc_core::sc_signal mtime_clk{"mtime_clk"}; + sc_core::sc_signal rst_s{"rst_s"}; + sc_core::sc_vector> irq_int_s{"irq_int_s", 32}; + sc_core::sc_vector> clint_int_s{"clint_int_s", 32}; + sc_core::sc_signal mtime_s{"mtime_s"}; void gen_reset(); -#include "../vp/gen/PipelinedMemoryBusToApbBridge.h" }; } // namespace vp diff --git a/vpvper b/vpvper index 77b5ffa..e5db899 160000 --- a/vpvper +++ b/vpvper @@ -1 +1 @@ -Subproject commit 77b5ffa40d50f63f4adac0b32076d9da590a4c51 +Subproject commit e5db89959dea03ddaa903138ba8d4810cee2d266