Compare commits
	
		
			14 Commits
		
	
	
		
			gabi_clean
			...
			1629b165b5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 1629b165b5 | |||
| a2e932c56f | |||
| cde5ae627c | |||
| 85304d1a43 | |||
| fddf608418 | |||
| 90c45d7c3c | |||
| 48cfa8d868 | |||
| 64d6045d43 | |||
| 765f48e85a | |||
| 1ce18ee1f6 | |||
| b4a3a36b2e | |||
| 2a541997a4 | |||
| 70d94c1051 | |||
| 0df111f945 | 
							
								
								
									
										187
									
								
								CMakeLists.txt
									
									
									
									
									
								
							
							
						
						
									
										187
									
								
								CMakeLists.txt
									
									
									
									
									
								
							@@ -1,19 +1,172 @@
 | 
			
		||||
if (NOT DEFINED BOARD)
 | 
			
		||||
	set(BOARD iss)
 | 
			
		||||
cmake_minimum_required(VERSION 3.12)
 | 
			
		||||
 | 
			
		||||
# Set default RISC-V toolchain if not specified
 | 
			
		||||
if(NOT DEFINED RISCV_TOOLCHAIN_PATH)
 | 
			
		||||
    set(RISCV_TOOLCHAIN_PATH "/opt/shared/cross-toolchains/gcc13/CentOS/riscv64-unknown-elf/bin" CACHE STRING "Path to RISC-V toolchain")
 | 
			
		||||
endif()
 | 
			
		||||
if (NOT DEFINED ISA)
 | 
			
		||||
	set(ISA imc)
 | 
			
		||||
 | 
			
		||||
# Allow override of compiler executables
 | 
			
		||||
if(NOT DEFINED RISCV_GCC)
 | 
			
		||||
    set(RISCV_GCC "/opt/shared/cross-toolchains/gcc13/CentOS/riscv64-unknown-elf/bin/riscv64-unknown-elf-gcc" CACHE STRING "RISC-V GCC compiler")
 | 
			
		||||
endif()
 | 
			
		||||
message(STATUS "Building firmware using ${BOARD} board configuration")
 | 
			
		||||
add_custom_target(fw-hello-world ALL 
 | 
			
		||||
	COMMAND make -C ${riscvfw_SOURCE_DIR}/hello-world BOARD=${BOARD} ISA=${ISA}
 | 
			
		||||
	USES_TERMINAL
 | 
			
		||||
	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 | 
			
		||||
add_custom_target(fw-dhrystone ALL 
 | 
			
		||||
	COMMAND make -C ${riscvfw_SOURCE_DIR}/benchmarks/dhrystone BOARD=${BOARD} ISA=${ISA}
 | 
			
		||||
    USES_TERMINAL
 | 
			
		||||
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 | 
			
		||||
add_custom_target(fw-coremark ALL 
 | 
			
		||||
	COMMAND make -C ${riscvfw_SOURCE_DIR}/benchmarks/coremark BOARD=${BOARD} ISA=${ISA}
 | 
			
		||||
    USES_TERMINAL
 | 
			
		||||
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 | 
			
		||||
 | 
			
		||||
if(NOT DEFINED RISCV_GXX)
 | 
			
		||||
    set(RISCV_GXX "${RISCV_TOOLCHAIN_PATH}/riscv64-unknown-elf-g++" CACHE STRING "RISC-V G++ compiler")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(NOT DEFINED RISCV_OBJCOPY)
 | 
			
		||||
    set(RISCV_OBJCOPY "${RISCV_TOOLCHAIN_PATH}/riscv64-unknown-elf-objcopy" CACHE STRING "RISC-V objcopy")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(NOT DEFINED RISCV_OBJDUMP)
 | 
			
		||||
    set(RISCV_OBJDUMP "${RISCV_TOOLCHAIN_PATH}/riscv64-unknown-elf-objdump" CACHE STRING "RISC-V objdump")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# Set the compilers
 | 
			
		||||
set(CMAKE_C_COMPILER ${RISCV_GCC})
 | 
			
		||||
set(CMAKE_CXX_COMPILER ${RISCV_GXX})
 | 
			
		||||
 | 
			
		||||
project(Firmware)
 | 
			
		||||
 | 
			
		||||
# Define supported configurations
 | 
			
		||||
set(SUPPORTED_BOARDS iss)
 | 
			
		||||
set(SUPPORTED_ISAS "rv32i;rv32im;rv32imc;rv64i;rv64im;rv64imc;imc")
 | 
			
		||||
set(SUPPORTED_ABIS "ilp32;ilp32f;lp64;lp64f")
 | 
			
		||||
 | 
			
		||||
# Build target options
 | 
			
		||||
option(BUILD_HELLO_WORLD "Build hello-world example" ON)
 | 
			
		||||
option(BUILD_DHRYSTONE "Build dhrystone benchmark" OFF)
 | 
			
		||||
option(BUILD_COREMARK "Build coremark benchmark" OFF)
 | 
			
		||||
option(BUILD_ALL "Build all targets" OFF)
 | 
			
		||||
 | 
			
		||||
# If BUILD_ALL is ON, enable all targets
 | 
			
		||||
if(BUILD_ALL)
 | 
			
		||||
    set(BUILD_HELLO_WORLD ON)
 | 
			
		||||
    set(BUILD_DHRYSTONE ON)
 | 
			
		||||
    set(BUILD_COREMARK ON)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# Set default values and validate configurations
 | 
			
		||||
if(NOT DEFINED BOARD)
 | 
			
		||||
    set(BOARD iss CACHE STRING "Target board")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(NOT DEFINED ISA)
 | 
			
		||||
    set(ISA rv32imc CACHE STRING "Target ISA")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(NOT DEFINED RISCV_ABI)
 | 
			
		||||
    if(ISA MATCHES "^rv64")
 | 
			
		||||
        set(RISCV_ABI "lp64" CACHE STRING "RISC-V ABI")
 | 
			
		||||
    else()
 | 
			
		||||
        set(RISCV_ABI "ilp32" CACHE STRING "RISC-V ABI")
 | 
			
		||||
    endif()
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# Validate configurations
 | 
			
		||||
if(NOT BOARD IN_LIST SUPPORTED_BOARDS)
 | 
			
		||||
    message(FATAL_ERROR "Invalid BOARD specified. Supported boards: ${SUPPORTED_BOARDS}")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(NOT ISA IN_LIST SUPPORTED_ISAS)
 | 
			
		||||
    message(FATAL_ERROR "Invalid ISA specified(${ISA}). Supported ISAs: ${SUPPORTED_ISAS}")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(NOT RISCV_ABI IN_LIST SUPPORTED_ABIS)
 | 
			
		||||
    message(FATAL_ERROR "Invalid ABI specified. Supported ABIs: ${SUPPORTED_ABIS}")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# Set RISC-V architecture based on ISA
 | 
			
		||||
if(ISA MATCHES "^rv")
 | 
			
		||||
    set(RISCV_ARCH ${ISA})
 | 
			
		||||
else()
 | 
			
		||||
    # Default to rv32 for backward compatibility
 | 
			
		||||
    set(RISCV_ARCH "rv32${ISA}")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# Set BSP base directory
 | 
			
		||||
set(BSP_BASE "${CMAKE_CURRENT_SOURCE_DIR}/bare-metal-bsp")
 | 
			
		||||
 | 
			
		||||
# Global compile definitions
 | 
			
		||||
add_compile_definitions(BOARD_${BOARD})
 | 
			
		||||
 | 
			
		||||
# RISC-V specific compiler flags
 | 
			
		||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany")
 | 
			
		||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany")
 | 
			
		||||
#set(CMAKE_ASM_COMPILER riscv64-unknown-elf-as)
 | 
			
		||||
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -O2 -g -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} -mcmodel=medany")
 | 
			
		||||
 | 
			
		||||
# Optional: Enable semihosting support
 | 
			
		||||
option(SEMIHOSTING "Enable semihosting support" OFF)
 | 
			
		||||
if(SEMIHOSTING)
 | 
			
		||||
    add_compile_definitions(SEMIHOSTING)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
#create interface library for propagating compile options
 | 
			
		||||
#add_library(global_compile_options INTERFACE)
 | 
			
		||||
 | 
			
		||||
# Compile options
 | 
			
		||||
#target_compile_options(global_compile_options INTERFACE
 | 
			
		||||
#    -march=${RISCV_ARCH}_zicsr_zifencei
 | 
			
		||||
 #   -mabi=${RISCV_ABI}
 | 
			
		||||
 #   -mcmodel=medany
 | 
			
		||||
 #   -O2
 | 
			
		||||
 #   -g
 | 
			
		||||
  #  -ffunction-sections
 | 
			
		||||
  #  -fdata-sections
 | 
			
		||||
#)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
message(STATUS "Building firmware with configuration:")
 | 
			
		||||
message(STATUS "  Board: ${BOARD}")
 | 
			
		||||
message(STATUS "  ISA: ${ISA} (Architecture: ${RISCV_ARCH})")
 | 
			
		||||
message(STATUS "  ABI: ${RISCV_ABI}")
 | 
			
		||||
message(STATUS "  Semihosting: ${SEMIHOSTING}")
 | 
			
		||||
message(STATUS "  Toolchain:")
 | 
			
		||||
message(STATUS "    Path: ${RISCV_TOOLCHAIN_PATH}")
 | 
			
		||||
message(STATUS "    C Compiler: ${CMAKE_C_COMPILER}")
 | 
			
		||||
message(STATUS "    C++ Compiler: ${CMAKE_CXX_COMPILER}")
 | 
			
		||||
message(STATUS "Targets to build:")
 | 
			
		||||
message(STATUS "  hello-world: ${BUILD_HELLO_WORLD}")
 | 
			
		||||
message(STATUS "  dhrystone: ${BUILD_DHRYSTONE}")
 | 
			
		||||
message(STATUS "  coremark: ${BUILD_COREMARK}")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
add_subdirectory(bare-metal-bsp)
 | 
			
		||||
 | 
			
		||||
# Add subdirectories based on build options
 | 
			
		||||
if(BUILD_HELLO_WORLD)
 | 
			
		||||
    add_subdirectory(hello-world)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if(BUILD_DHRYSTONE)
 | 
			
		||||
    add_subdirectory(benchmarks/dhrystone)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if(BUILD_COREMARK)
 | 
			
		||||
    add_subdirectory(benchmarks/coremark)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# Create an all-inclusive target only if BUILD_ALL is ON
 | 
			
		||||
if(BUILD_ALL)
 | 
			
		||||
    add_custom_target(fw-common ALL
 | 
			
		||||
        DEPENDS 
 | 
			
		||||
            hello-world
 | 
			
		||||
            dhrystone
 | 
			
		||||
            coremark
 | 
			
		||||
    )
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
# Print build instructions
 | 
			
		||||
message(STATUS "")
 | 
			
		||||
message(STATUS "Build instructions:")
 | 
			
		||||
message(STATUS "  Build all targets:           cmake -DBUILD_ALL=ON ..")
 | 
			
		||||
message(STATUS "  Build specific target:       cmake -DBUILD_HELLO_WORLD=ON -DBUILD_DHRYSTONE=OFF -DBUILD_COREMARK=OFF ..")
 | 
			
		||||
message(STATUS "  Configure board:             cmake -DBOARD=iss ..")
 | 
			
		||||
message(STATUS "  Configure ISA:               cmake -DISA=rv32imc ..")
 | 
			
		||||
message(STATUS "  Configure ABI:               cmake -DRISCV_ABI=ilp32 ..")
 | 
			
		||||
message(STATUS "  Enable semihosting:          cmake -DSEMIHOSTING=ON ..")
 | 
			
		||||
message(STATUS "  Set toolchain path:          cmake -DRISCV_TOOLCHAIN_PATH=/path/to/toolchain ..")
 | 
			
		||||
message(STATUS "  Set specific compiler:       cmake -DRISCV_GCC=/path/to/riscv-gcc -DRISCV_GXX=/path/to/riscv-g++ ..")
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										26
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								README.md
									
									
									
									
									
								
							@@ -1,3 +1,25 @@
 | 
			
		||||
# Firmware
 | 
			
		||||
# MINRES Firmware Repository
 | 
			
		||||
## Structure
 | 
			
		||||
This repository comes with several executables ready to be built, such as `hello-world` or `coremark` and `dhrystone` in the `benchmark` directory.
 | 
			
		||||
Creating the executables in the easiest way possible is done by calling `make`in the corresponding directory.
 | 
			
		||||
 | 
			
		||||
Using `make clean && bear -- make ` will cause a correct compile_commands.json to be emitted. This allows using completion tools like clangd. 
 | 
			
		||||
## Prerequisite
 | 
			
		||||
This repository requires `riscv64-unknown-elf-gcc` to be located in `$PATH`.
 | 
			
		||||
 | 
			
		||||
## How to Use
 | 
			
		||||
When compiling executables, the target platform needs to be specified using the 'BOARD' variable. When compiling for the TGC5C for example, use  `make BOARD=tgc_vp`, when compiling for RTL `make BOARD=rtl`. The default value for the Board variable is 'iss'.
 | 
			
		||||
The arch can be set with the 'ISA' variable, the default value is 'imc'.
 | 
			
		||||
 | 
			
		||||
When compiling for the TGC5A VP for example, the call to create the correct binary is the following:
 | 
			
		||||
```
 | 
			
		||||
make BOARD=tgc_vp ISA=e
 | 
			
		||||
```
 | 
			
		||||
## Useful information
 | 
			
		||||
Using `bear -- <build-command>` will cause a compile_commands.json to be emitted. This allows using completion tools like clangd. 
 | 
			
		||||
 | 
			
		||||
## Current Limitations
 | 
			
		||||
Currently, this repository only supports creation of 32-bit executables (Even when setting the `RISCV_ARCH` and `RISCV_ABI` manually).
 | 
			
		||||
 | 
			
		||||
Compiling for the 'e' extension / ISA together with any other extension (`ISA=emc` for example), requires setting the `RISCV_ABI=ilp32e` explicitly. 
 | 
			
		||||
 | 
			
		||||
When switching ABI or ARCH ensure that object files in the corresponding 'env' dir in the 'bare-metal-bsp' submodule are removed, so they get created with the appropriate flags (namely the 'init.o' file).
 | 
			
		||||
 
 | 
			
		||||
 Submodule bare-metal-bsp updated: 87dc0ec230...fbe6560e79
									
								
							
							
								
								
									
										66
									
								
								benchmarks/coremark/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								benchmarks/coremark/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.12)
 | 
			
		||||
project(coremark C)
 | 
			
		||||
 | 
			
		||||
# Include BSP libwrap
 | 
			
		||||
include(${BSP_BASE}/libwrap/CMakeLists.txt)
 | 
			
		||||
 | 
			
		||||
# Source files
 | 
			
		||||
set(SOURCES
 | 
			
		||||
    core_portme.c
 | 
			
		||||
    cvt.c
 | 
			
		||||
    ee_printf.c
 | 
			
		||||
    cm/core_list_join.c
 | 
			
		||||
    cm/core_main.c
 | 
			
		||||
    cm/core_matrix.c
 | 
			
		||||
    cm/core_state.c
 | 
			
		||||
    cm/core_util.c
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Create executable
 | 
			
		||||
add_executable(coremark ${SOURCES})
 | 
			
		||||
 | 
			
		||||
# Include directories
 | 
			
		||||
target_include_directories(coremark PRIVATE
 | 
			
		||||
    ${BSP_BASE}/include
 | 
			
		||||
    ${BSP_BASE}/drivers
 | 
			
		||||
    ${BSP_BASE}/env
 | 
			
		||||
    ${CMAKE_CURRENT_SOURCE_DIR}
 | 
			
		||||
    ${CMAKE_CURRENT_SOURCE_DIR}/cm
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Link with libwrap
 | 
			
		||||
target_link_libraries(coremark PRIVATE
 | 
			
		||||
    LIBWRAP_TGC
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Add compile definitions
 | 
			
		||||
target_compile_definitions(coremark PRIVATE
 | 
			
		||||
    BOARD_${BOARD}
 | 
			
		||||
    PERFORMANCE_RUN=1
 | 
			
		||||
    ITERATIONS=1000
 | 
			
		||||
    COMPILER_FLAGS="${CMAKE_C_FLAGS}"
 | 
			
		||||
    COMPILER_VERSION="${CMAKE_C_COMPILER_VERSION}"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Set compile options
 | 
			
		||||
target_compile_options(coremark PRIVATE
 | 
			
		||||
    -march=${RISCV_ARCH}_zicsr_zifencei
 | 
			
		||||
    -mabi=${RISCV_ABI}
 | 
			
		||||
    -mcmodel=medany
 | 
			
		||||
    -ffunction-sections
 | 
			
		||||
    -fdata-sections
 | 
			
		||||
    -O2  # Optimization level for benchmarking
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Set linker options
 | 
			
		||||
target_link_options(coremark PRIVATE
 | 
			
		||||
    -T${BSP_BASE}/env/${BOARD}/link.ld
 | 
			
		||||
    -nostartfiles
 | 
			
		||||
    -Wl,--gc-sections
 | 
			
		||||
    ${LIBWRAP_TGC_LDFLAGS}
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
# Install target
 | 
			
		||||
install(TARGETS coremark
 | 
			
		||||
    RUNTIME DESTINATION bin
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										1
									
								
								benchmarks/dhrystone/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								benchmarks/dhrystone/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,2 +1,3 @@
 | 
			
		||||
dhrystone
 | 
			
		||||
/dhrystone.dis
 | 
			
		||||
build/
 | 
			
		||||
							
								
								
									
										21
									
								
								benchmarks/dhrystone/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								benchmarks/dhrystone/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.21)
 | 
			
		||||
project(dhrystone C)
 | 
			
		||||
set(TARGET dhrystone)
 | 
			
		||||
set(CMAKE_BUILD_TYPE Release)
 | 
			
		||||
set(ITERATIONS 50000) # 20000 for TGC
 | 
			
		||||
 | 
			
		||||
add_executable(${TARGET} dhry_1.c dhry_2.c dhry_stubs.c)
 | 
			
		||||
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
 | 
			
		||||
target_compile_options(${TARGET} PRIVATE -fno-inline -fno-builtin-printf -fno-common -Wno-implicit -funroll-loops -fpeel-loops -fgcse-sm -fgcse-las)
 | 
			
		||||
target_compile_definitions(${TARGET} PRIVATE ITERATIONS=${ITERATIONS} HZ=32768 TIME NO_INIT)
 | 
			
		||||
 | 
			
		||||
set(BOARD "iss" CACHE STRING "Target board")
 | 
			
		||||
add_subdirectory(../../bare-metal-bsp bsp)
 | 
			
		||||
target_link_libraries(${TARGET} PRIVATE bsp)
 | 
			
		||||
target_link_options(${TARGET} PRIVATE LINKER:--wrap=scanf)
 | 
			
		||||
include(CMakePrintHelpers)
 | 
			
		||||
cmake_print_properties(TARGETS ${TARGET} PROPERTIES COMPILE_DEFINITIONS COMPILE_OPTIONS LINK_OPTIONS INTERFACE_LINK_OPTIONS)
 | 
			
		||||
 | 
			
		||||
add_custom_command(TARGET ${TARGET} POST_BUILD
 | 
			
		||||
        COMMAND ${CMAKE_OBJDUMP} -S  ${TARGET}.elf > ${TARGET}.dis
 | 
			
		||||
        COMMENT "Creating disassembly for ${TARGET}")
 | 
			
		||||
@@ -15,9 +15,9 @@ else
 | 
			
		||||
    RISCV_ABI:=ilp32
 | 
			
		||||
endif
 | 
			
		||||
# '-lgcc -lm' are needed to add softfloat routines
 | 
			
		||||
CFLAGS  := -g -march=$(RISCV_ARCH)_zicsr_zifencei -mabi=$(RISCV_ABI) -mcmodel=medlow -O3 -DITERATIONS=$(ITERATIONS) -DHZ=32768 -DTIME -DNO_INIT -fno-inline -fno-builtin-printf -fno-common -Wno-implicit \
 | 
			
		||||
CFLAGS  := -g -O3 -DITERATIONS=$(ITERATIONS) -DHZ=32768 -DTIME -DNO_INIT -fno-inline -fno-builtin-printf -fno-common -Wno-implicit \
 | 
			
		||||
 -funroll-loops -fpeel-loops -fgcse-sm -fgcse-las
 | 
			
		||||
LDFLAGS := -g -march=$(RISCV_ARCH)_zicsr_zifencei -mabi=$(RISCV_ABI) -mcmodel=medlow -Wl,--wrap=scanf -Wl,--wrap=printf -Wl,--wrap=exit -lgcc -lm
 | 
			
		||||
LDFLAGS := -Wl,--wrap=scanf
 | 
			
		||||
 | 
			
		||||
TOOL_DIR=$(dir $(compiler))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								hello-world/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								hello-world/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,2 +1,3 @@
 | 
			
		||||
/hello
 | 
			
		||||
/hello.dis
 | 
			
		||||
build/
 | 
			
		||||
							
								
								
									
										12
									
								
								hello-world/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								hello-world/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,12 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.21)
 | 
			
		||||
project(hello-world C)
 | 
			
		||||
set(TARGET hello)
 | 
			
		||||
add_executable(${TARGET} hello.c)
 | 
			
		||||
 | 
			
		||||
set(BOARD "iss" CACHE STRING "Target board")
 | 
			
		||||
add_subdirectory(../bare-metal-bsp bsp)
 | 
			
		||||
target_link_libraries(${TARGET} PRIVATE bsp)
 | 
			
		||||
 | 
			
		||||
add_custom_command(TARGET ${TARGET} POST_BUILD
 | 
			
		||||
        COMMAND ${CMAKE_OBJDUMP} -S  ${TARGET}.elf > ${TARGET}.dis
 | 
			
		||||
        COMMENT "Creating disassembly for ${TARGET}")
 | 
			
		||||
@@ -1,91 +0,0 @@
 | 
			
		||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.13 FATAL_ERROR)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
SET(BOARD "iss" CACHE STRING "board to be compiled for")
 | 
			
		||||
OPTION(SEMIHOSTING "Enable Semihosting" ON)
 | 
			
		||||
 | 
			
		||||
SET(RISCV_ARCH "rv32imc" CACHE STRING "arch")
 | 
			
		||||
SET(RISCV_ABI "ilp32" CACHE STRING "abi")
 | 
			
		||||
 | 
			
		||||
EXECUTE_PROCESS(    
 | 
			
		||||
    COMMAND which riscv64-unknown-elf-gcc
 | 
			
		||||
    OUTPUT_VARIABLE COMPILER
 | 
			
		||||
    OUTPUT_STRIP_TRAILING_WHITESPACE)
 | 
			
		||||
 | 
			
		||||
GET_FILENAME_COMPONENT(TOOL_DIR ${COMPILER} DIRECTORY)
 | 
			
		||||
 | 
			
		||||
SET(TRIPLET "riscv64-unknown-elf")
 | 
			
		||||
 | 
			
		||||
SET(CMAKE_C_COMPILER ${TOOL_DIR}/${TRIPLET}-gcc)
 | 
			
		||||
SET(CMAKE_CXX_COMPILER ${TOOL_DIR}/${TRIPLET}-g++)
 | 
			
		||||
SET(CMAKE_ASM_COMPILER ${TOOL_DIR}/${TRIPLET}-gcc)
 | 
			
		||||
SET(CMAKE_LINKER ${TOOL_DIR}/${TRIPLET}-ld)
 | 
			
		||||
SET(CMAKE_OBJCOPY ${TOOL_DIR}/${TRIPLET}-objcopy)
 | 
			
		||||
SET(CMAKE_AR ${TOOL_DIR}/${TRIPLET}-ar)
 | 
			
		||||
 | 
			
		||||
PROJECT(semihosting_test)
 | 
			
		||||
 | 
			
		||||
SET(BSP_BASE "../bare-metal-bsp")
 | 
			
		||||
SET(ENV_DIR ${BSP_BASE}/env)
 | 
			
		||||
SET(PLATFORM_DIR ${ENV_DIR}/${BOARD})
 | 
			
		||||
 | 
			
		||||
SET(SEMIHOSTING TRUE)
 | 
			
		||||
 | 
			
		||||
INCLUDE(${BSP_BASE}/libwrap/CMakeLists.txt)
 | 
			
		||||
 | 
			
		||||
INCLUDE_DIRECTORIES(
 | 
			
		||||
    ${BSP_BASE}/include
 | 
			
		||||
    ${BSP_BASE}/drivers
 | 
			
		||||
    ${BSP_BASE}/libwrap/semihosting
 | 
			
		||||
    ${PLATFORM_DIR}
 | 
			
		||||
    ${ENV_DIR}
 | 
			
		||||
)    
 | 
			
		||||
 | 
			
		||||
# Source files
 | 
			
		||||
SET(ASM_SRCS
 | 
			
		||||
    ${ENV_DIR}/entry.S
 | 
			
		||||
    ${ENV_DIR}/start.S
 | 
			
		||||
)
 | 
			
		||||
SET(C_SRCS
 | 
			
		||||
    ${PLATFORM_DIR}/init.c
 | 
			
		||||
    test.c
 | 
			
		||||
)
 | 
			
		||||
SET_SOURCE_FILES_PROPERTIES(${ASM_SRCS} PROPERTIES LANGUAGE C)
 | 
			
		||||
 | 
			
		||||
# Compiler Flags
 | 
			
		||||
SET(COMMON_FLAGS "")
 | 
			
		||||
 | 
			
		||||
# GCC Version Check
 | 
			
		||||
EXECUTE_PROCESS(
 | 
			
		||||
    COMMAND ${CMAKE_C_COMPILER} --version
 | 
			
		||||
    OUTPUT_VARIABLE GCC_VERSION
 | 
			
		||||
)
 | 
			
		||||
IF(GCC_VERSION MATCHES "9.2")
 | 
			
		||||
    LIST(APPEND COMMON_FLAGS "-march=${RISCV_ARCH}")
 | 
			
		||||
ELSE()
 | 
			
		||||
    LIST(APPEND COMMON_FLAGS "-march=${RISCV_ARCH}_zicsr_zifencei")
 | 
			
		||||
ENDIF()
 | 
			
		||||
LIST(APPEND COMMON_FLAGS "-mabi=${RISCV_ABI}" "-mcmodel=medany" "-DBOARD_${BOARD}")
 | 
			
		||||
 | 
			
		||||
# Compiler Options
 | 
			
		||||
ADD_COMPILE_OPTIONS("${COMMON_FLAGS}")
 | 
			
		||||
IF(SEMIHOSTING)
 | 
			
		||||
ADD_DEFINITIONS(-DSEMIHOSTING=1)
 | 
			
		||||
ELSE ()
 | 
			
		||||
ADD_DEFINITIONS(-DSEMIHOSTING=0)
 | 
			
		||||
ENDIF()
 | 
			
		||||
 | 
			
		||||
ADD_EXECUTABLE(${PROJECT_NAME} ${ASM_SRCS} ${C_SRCS} ${SRC_FILES})
 | 
			
		||||
 | 
			
		||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${LIBWRAP_TGC_LDFLAGS} LIBWRAP_TGC)
 | 
			
		||||
 | 
			
		||||
# Linker Flags
 | 
			
		||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
 | 
			
		||||
    PUBLIC
 | 
			
		||||
        -march=${RISCV_ARCH} -mabi=${RISCV_ABI}
 | 
			
		||||
        -T../${PLATFORM_DIR}/link.lds #TODO Path 
 | 
			
		||||
        -Wl,-Map=${PROJECT_NAME}.map
 | 
			
		||||
        -nostartfiles
 | 
			
		||||
        -L${ENV_DIR}
 | 
			
		||||
)
 | 
			
		||||
@@ -1,21 +0,0 @@
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include "platform.h"
 | 
			
		||||
#include "encoding.h"
 | 
			
		||||
#include "semihosting.h"
 | 
			
		||||
 | 
			
		||||
int main()
 | 
			
		||||
{
 | 
			
		||||
	char new[]="/scratch/gabriel/Documents/test_file";
 | 
			
		||||
	//puts(new);
 | 
			
		||||
	//char buf[10];
 | 
			
		||||
	printf("TEST!!!");
 | 
			
		||||
	//int fh = open(new, 0, 0);
 | 
			
		||||
	//unlink(new);
 | 
			
		||||
	//read(fh, buf, 10);
 | 
			
		||||
	//printf(buf);
 | 
			
		||||
	//read(fh, buf, 10);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user