diff --git a/CMakeLists.txt b/CMakeLists.txt index fae7253..1c8404e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,62 +44,18 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utils.cmake) -################################################################################ -# Host Runtime Library # -################################################################################ -add_library(runtime_host STATIC) - -target_compile_options(runtime_host - PRIVATE - -O2 -) - -target_compile_options(runtime_host - PUBLIC - -march=${ISA_HOST} - -mabi=${ABI} -) - -# WIESEP: Expose common link option -target_link_options(runtime_host - PUBLIC - -march=${ISA_HOST} - -mabi=${ABI} - -nostartfiles - -ffreestanding -) - -################################################################################ -# Snitch Cluster Runtime Library # -################################################################################ -add_library(runtime_cluster_snitch STATIC) - -# WIESEP: Do not export optimization flags -target_compile_options(runtime_cluster_snitch - PRIVATE - -O2 -) - -target_compile_options(runtime_cluster_snitch - PUBLIC - -march=${ISA_CLUSTER_SNITCH} - -mabi=${ABI} -) - -# WIESEP: Expose common link option -target_link_options(runtime_cluster_snitch - PUBLIC - -march=${ISA_CLUSTER_SNITCH} - -mabi=${ABI} - -nostartfiles - -ffreestanding -) - ################################################################################ # Add subdirectories # ################################################################################ -add_subdirectory(hal) +# WIESEP: Targets have to be included before the other folders to make them available +# Depending on the target, the following static libraries have to added by the targets: +# - runtime_host +# - runtime_cluster_snitch add_subdirectory(targets) + +# Include other subdirectories +add_subdirectory(hal) +add_subdirectory(devices) add_subdirectory(drivers) ################################################################################ diff --git a/cmake/Utils.cmake b/cmake/Utils.cmake index 27e48a3..44b6eac 100644 --- a/cmake/Utils.cmake +++ b/cmake/Utils.cmake @@ -29,3 +29,52 @@ macro(add_target_source name) message(WARNING "Path ${CMAKE_CURRENT_LIST_DIR}/${name} does not exist") endif() endmacro() + +# Define a reusable macro for handling folder mappings +macro(add_chimera_subdirectories target_platform category mappings) + # Initialize included folders + set(included_folders "") + + # Process mappings + foreach(mapping IN LISTS ${mappings}) + string(FIND "${mapping}" ":" delim_pos) + if(delim_pos EQUAL -1) + message(WARNING "[CHIMERA-SDK] Invalid mapping entry: '${mapping}'. Skipping.") + continue() + endif() + + + # Extract key and value + string(SUBSTRING "${mapping}" 0 ${delim_pos} key) + math(EXPR value_start "${delim_pos} + 1") + string(SUBSTRING "${mapping}" ${value_start} -1 value) + + if(key STREQUAL "${target_platform}") + list(APPEND included_folders ${value}) + break() + endif() + endforeach() + + string(REPLACE "," ";" included_folders "${included_folders}") + + # Align output with padding + string(LENGTH "[CHIMERA-SDK] Enabled ${category}s" category_prefix_length) + math(EXPR padding_length "36 - ${category_prefix_length}") + if(padding_length GREATER 0) + string(REPEAT " " ${padding_length} padding) + else() + set(padding "") + endif() + + # Debug: Print the folders being included + message(STATUS "[CHIMERA-SDK] Enabled ${category}s${padding}: ${included_folders}") + + # Add subdirectories, checking for a valid CMakeLists.txt + foreach(folder IN LISTS included_folders) + if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${folder}/CMakeLists.txt) + add_subdirectory(${folder}) + else() + message(WARNING "[CHIMERA-SDK] ${category} folder '${folder}' does not contain a valid CMakeLists.txt. Skipping.") + endif() + endforeach() +endmacro() diff --git a/devices/CMakeLists.txt b/devices/CMakeLists.txt new file mode 100644 index 0000000..7882405 --- /dev/null +++ b/devices/CMakeLists.txt @@ -0,0 +1,41 @@ +# Copyright 2024 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +# Philip Wiese + +# Define mappings directly using lists for each target +# set(CHIMERA_DEVICE_CONVOLVE_FOLDERS snitch_cluster) +# set(CHIMERA_DEVICE_OPEN_FOLDERS snitch_cluster) +# set(CHIMERA_DEVICE_HOST_FOLDERS) + +# # Determine which folders to include based on TARGET_PLATFORM +# if(TARGET_PLATFORM STREQUAL "chimera-convolve") +# set(INCLUDED_FOLDERS ${CHIMERA_DEVICE_CONVOLVE_FOLDERS}) +# elseif(TARGET_PLATFORM STREQUAL "chimera-open") +# set(INCLUDED_FOLDERS ${CHIMERA_DEVICE_OPEN_FOLDERS}) +# elseif(TARGET_PLATFORM STREQUAL "chimera-host") +# set(INCLUDED_FOLDERS ${CHIMERA_DEVICE_HOST_FOLDERS}) +# endif() + +# # WIESEP: Print the folders being included +# message(STATUS "[CHIMERA-SDK] Enabled Devices : ${INCLUDED_FOLDERS}") + +# # Add subdirectories, checking for a valid CMakeLists.txt in each folder +# foreach(folder IN LISTS INCLUDED_FOLDERS) +# if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${folder}/CMakeLists.txt) +# add_subdirectory(${folder}) +# else() +# message(WARNING "[CHIMERA-SDK] Device folder '${folder}' does not contain a valid CMakeLists.txt. Skipping.") +# endif() +# endforeach() + +# Define mappings for devices +set(DEVICE_MAPPINGS + chimera-convolve:snitch_cluster + chimera-open:snitch_cluster + chimera-host: +) + +# Call the macro +add_chimera_subdirectories(${TARGET_PLATFORM} "Device" DEVICE_MAPPINGS) diff --git a/devices/snitch_cluster/CMakeLists.txt b/devices/snitch_cluster/CMakeLists.txt new file mode 100644 index 0000000..79aae8f --- /dev/null +++ b/devices/snitch_cluster/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright 2024 ETH Zurich and University of Bologna. +# Licensed under the Apache License, Version 2.0, see LICENSE for details. +# SPDX-License-Identifier: Apache-2.0 +# +# Philip Wiese + + +################################################################################ +# Snitch Cluster Runtime Library # +################################################################################ +file(GLOB_RECURSE C_SOURCES_SNITCH + "trampoline_snitchCluster.c" +) + +target_sources(runtime_cluster_snitch PRIVATE ${C_SOURCES_SNITCH}) diff --git a/drivers/cluster/trampoline_snitchCluster.c b/devices/snitch_cluster/trampoline_snitchCluster.c similarity index 100% rename from drivers/cluster/trampoline_snitchCluster.c rename to devices/snitch_cluster/trampoline_snitchCluster.c diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 3779272..d2b9407 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -4,9 +4,16 @@ # # Philip Wiese +# Define mappings for drivers +set(DRIVER_MAPPINGS + chimera-convolve:cluster + chimera-open:cluster + chimera-host: +) + +# Call the macro +add_chimera_subdirectories(${TARGET_PLATFORM} "Driver" DRIVER_MAPPINGS) -# WIESEP: Add all runtime drivers -add_subdirectory(cluster) # WIESEP: Export this directory as root include directory for the drivers target_include_directories(runtime_host PUBLIC ${CMAKE_CURRENT_LIST_DIR}) diff --git a/drivers/cluster/CMakeLists.txt b/drivers/cluster/CMakeLists.txt index 172adee..6c70ec9 100644 --- a/drivers/cluster/CMakeLists.txt +++ b/drivers/cluster/CMakeLists.txt @@ -13,15 +13,3 @@ file(GLOB_RECURSE C_SOURCES ) target_sources(runtime_host PRIVATE ${C_SOURCES}) - -################################################################################ -# Snitch Cluster Runtime Library # -################################################################################ -file(GLOB_RECURSE C_SOURCES_SNITCH - "trampoline_snitchCluster.c" -) - -target_sources(runtime_cluster_snitch PRIVATE ${C_SOURCES_SNITCH}) - - - diff --git a/targets/chimera-convolve/CMakeLists.txt b/targets/chimera-convolve/CMakeLists.txt index 54f6e22..57d4cad 100644 --- a/targets/chimera-convolve/CMakeLists.txt +++ b/targets/chimera-convolve/CMakeLists.txt @@ -6,6 +6,11 @@ # Viviane Potocnik # Philip Wiese +################################################################################ +# Host Runtime Library # +################################################################################ +add_library(runtime_host STATIC) + file(GLOB_RECURSE ASM_SOURCES "src/crt0.S" ) @@ -22,21 +27,62 @@ target_sources(runtime_host ${C_SOURCES} ) +# WIESEP: Export the target specific include directory +target_include_directories(runtime_host + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/include +) + +target_compile_options(runtime_host + PRIVATE + -O2 +) + +target_compile_options(runtime_host + PUBLIC + -march=${ISA_HOST} + -mabi=${ABI} +) + # WIESEP: Export the target specific linkerscript target_link_options(runtime_host PUBLIC -L${CMAKE_CURRENT_LIST_DIR} -Tlink.ld + -march=${ISA_HOST} + -mabi=${ABI} + -nostartfiles + -ffreestanding ) -# WIESEP: Export the target specific include directory -target_include_directories(runtime_host - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/include -) +################################################################################ +# Snitch Cluster Runtime Library # +################################################################################ +add_library(runtime_cluster_snitch STATIC) # WIESEP: Export the headers also to the cluster runtime target_include_directories(runtime_cluster_snitch PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ) + +# WIESEP: Do not export optimization flags +target_compile_options(runtime_cluster_snitch + PRIVATE + -O2 +) + +target_compile_options(runtime_cluster_snitch + PUBLIC + -march=${ISA_CLUSTER_SNITCH} + -mabi=${ABI} +) + +# WIESEP: Expose common link option +target_link_options(runtime_cluster_snitch + PUBLIC + -march=${ISA_CLUSTER_SNITCH} + -mabi=${ABI} + -nostartfiles + -ffreestanding +) \ No newline at end of file diff --git a/targets/chimera-host/CMakeLists.txt b/targets/chimera-host/CMakeLists.txt index 54f6e22..1a7cb65 100644 --- a/targets/chimera-host/CMakeLists.txt +++ b/targets/chimera-host/CMakeLists.txt @@ -6,6 +6,11 @@ # Viviane Potocnik # Philip Wiese +################################################################################ +# Host Runtime Library # +################################################################################ +add_library(runtime_host STATIC) + file(GLOB_RECURSE ASM_SOURCES "src/crt0.S" ) @@ -22,21 +27,35 @@ target_sources(runtime_host ${C_SOURCES} ) -# WIESEP: Export the target specific linkerscript -target_link_options(runtime_host - PUBLIC - -L${CMAKE_CURRENT_LIST_DIR} - -Tlink.ld -) - # WIESEP: Export the target specific include directory target_include_directories(runtime_host PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ) -# WIESEP: Export the headers also to the cluster runtime -target_include_directories(runtime_cluster_snitch +target_compile_options(runtime_host + PRIVATE + -O2 +) + +target_compile_options(runtime_host PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/include + -march=${ISA_HOST} + -mabi=${ABI} +) + +# WIESEP: Export the target specific linkerscript +target_link_options(runtime_host + PUBLIC + -L${CMAKE_CURRENT_LIST_DIR} + -Tlink.ld + -march=${ISA_HOST} + -mabi=${ABI} + -nostartfiles + -ffreestanding ) + +################################################################################ +# Snitch Cluster Runtime Library # +################################################################################ +# WIESEP: There is no Snitch cluster present in this target \ No newline at end of file diff --git a/targets/chimera-host/include/addr_maps/soc_addr_map.h b/targets/chimera-host/include/addr_maps/soc_addr_map.h new file mode 100644 index 0000000..dbd9cea --- /dev/null +++ b/targets/chimera-host/include/addr_maps/soc_addr_map.h @@ -0,0 +1,25 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Moritz Scherer + +#ifndef _SOC_ADDR_MAP_INCLUDE_GUARD_ +#define _SOC_ADDR_MAP_INCLUDE_GUARD_ + +#include + +#define CLINT_CTRL_BASE 0x02040000 + +#define SOC_CTRL_BASE 0x30001000 + +#define NUM_CLUSTER_CORES 0 + +static uint8_t _chimera_numCores[] = {0}; + +#define _chimera_numClusters 0 + +#define CHIMERA_PADFRAME_BASE_ADDRESS 0x30002000 +#define FLL_BASE_ADDR 0x30003000 + +#endif diff --git a/targets/chimera-host/include/regs/soc_ctrl.h b/targets/chimera-host/include/regs/soc_ctrl.h new file mode 100644 index 0000000..3ae00e7 --- /dev/null +++ b/targets/chimera-host/include/regs/soc_ctrl.h @@ -0,0 +1,23 @@ +// Generated register defines for chimera + +// Copyright information found in source file: +// Copyright 2024 ETH Zurich and University of Bologna. + +// Licensing information found in source file: +// +// SPDX-License-Identifier: SHL-0.51 + +#ifndef _CHIMERA_REG_DEFS_ +#define _CHIMERA_REG_DEFS_ + +#ifdef __cplusplus +extern "C" { +#endif +// Register width +#define CHIMERA_PARAM_REG_WIDTH 32 + +#ifdef __cplusplus +} // extern "C" +#endif +#endif // _CHIMERA_REG_DEFS_ +// End generated register defines for chimera diff --git a/targets/chimera-host/include/soc.h b/targets/chimera-host/include/soc.h new file mode 100644 index 0000000..4362aa7 --- /dev/null +++ b/targets/chimera-host/include/soc.h @@ -0,0 +1,13 @@ +// Copyright 2024 ETH Zurich and University of Bologna. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 +// +// Philip Wiese + +#ifndef _SOC_INCLUDE_GUARD_ +#define _SOC_INCLUDE_GUARD_ + +#include "regs/soc_ctrl.h" +#include "addr_maps/soc_addr_map.h" + +#endif //_SOC_INCLUDE_GUARD_ diff --git a/targets/chimera-open/CMakeLists.txt b/targets/chimera-open/CMakeLists.txt index 54f6e22..57d4cad 100644 --- a/targets/chimera-open/CMakeLists.txt +++ b/targets/chimera-open/CMakeLists.txt @@ -6,6 +6,11 @@ # Viviane Potocnik # Philip Wiese +################################################################################ +# Host Runtime Library # +################################################################################ +add_library(runtime_host STATIC) + file(GLOB_RECURSE ASM_SOURCES "src/crt0.S" ) @@ -22,21 +27,62 @@ target_sources(runtime_host ${C_SOURCES} ) +# WIESEP: Export the target specific include directory +target_include_directories(runtime_host + PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/include +) + +target_compile_options(runtime_host + PRIVATE + -O2 +) + +target_compile_options(runtime_host + PUBLIC + -march=${ISA_HOST} + -mabi=${ABI} +) + # WIESEP: Export the target specific linkerscript target_link_options(runtime_host PUBLIC -L${CMAKE_CURRENT_LIST_DIR} -Tlink.ld + -march=${ISA_HOST} + -mabi=${ABI} + -nostartfiles + -ffreestanding ) -# WIESEP: Export the target specific include directory -target_include_directories(runtime_host - PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/include -) +################################################################################ +# Snitch Cluster Runtime Library # +################################################################################ +add_library(runtime_cluster_snitch STATIC) # WIESEP: Export the headers also to the cluster runtime target_include_directories(runtime_cluster_snitch PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ) + +# WIESEP: Do not export optimization flags +target_compile_options(runtime_cluster_snitch + PRIVATE + -O2 +) + +target_compile_options(runtime_cluster_snitch + PUBLIC + -march=${ISA_CLUSTER_SNITCH} + -mabi=${ABI} +) + +# WIESEP: Expose common link option +target_link_options(runtime_cluster_snitch + PUBLIC + -march=${ISA_CLUSTER_SNITCH} + -mabi=${ABI} + -nostartfiles + -ffreestanding +) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 814b4ef..d731ade 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,30 +5,12 @@ # Moritz Scherer # Philip Wiese -# Define mappings directly using lists for each target -set(CHIMERA_CONVOLVE_FOLDERS chimera-convolve chimera-open chimera-host) -set(CHIMERA_OPEN_FOLDERS chimera-open chimera-host) -set(CHIMERA_HOST_FOLDERS chimera-host) +# Define mappings for tests +set(TEST_MAPPINGS + chimera-convolve:chimera-convolve,chimera-open,chimera-host + chimera-open:chimera-open,chimera-host + chimera-host:chimera-host +) -# Determine which folders to include based on TARGET_PLATFORM -if(TARGET_PLATFORM STREQUAL "chimera-convolve") - set(INCLUDED_FOLDERS ${CHIMERA_CONVOLVE_FOLDERS}) -elseif(TARGET_PLATFORM STREQUAL "chimera-open") - set(INCLUDED_FOLDERS ${CHIMERA_OPEN_FOLDERS}) -elseif(TARGET_PLATFORM STREQUAL "chimera-host") - set(INCLUDED_FOLDERS ${CHIMERA_HOST_FOLDERS}) -else() - message(FATAL_ERROR "[CHIMERA-SDK] Unknown TARGET_PLATFORM: '${TARGET_PLATFORM}'. Valid options are chimera-convolve, chimera-open, or chimera-host.") -endif() - -# WIESEP: Print the folders being included -message(STATUS "[CHIMERA-SDK] Including test folders: ${INCLUDED_FOLDERS}") - -# Add subdirectories, checking for a valid CMakeLists.txt in each folder -foreach(folder IN LISTS INCLUDED_FOLDERS) - if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${folder}/CMakeLists.txt) - add_subdirectory(${folder}) - else() - message(WARNING "[CHIMERA-SDK] Folder '${folder}' does not contain a valid CMakeLists.txt. Skipping.") - endif() -endforeach() +# Call the macro +add_chimera_subdirectories(${TARGET_PLATFORM} "Test" TEST_MAPPINGS)