diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..706a938 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.12) +project(bsp C) +add_subdirectory(libwrap) +message(STATUS " liu here") +message(STATUS " SUPPORTED_BOARDS= ${SUPPORTED_BOARDS}") +add_library(${PROJECT_NAME} INTERFACE) +target_include_directories(${PROJECT_NAME} INTERFACE +include/ +env/${BOARD} +env/) \ No newline at end of file diff --git a/env/CMakeLists.txt b/env/CMakeLists.txt new file mode 100644 index 0000000..f5db5e1 --- /dev/null +++ b/env/CMakeLists.txt @@ -0,0 +1,39 @@ +project(bsp_env) +message(STATUS " here in bsp_env") +# Enable ASM language +enable_language(ASM) +set(LIB_SOURCES + entry.S + start.S +) + +# Set ASM compile options +set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI}") + + +add_library(asm_obj OBJECT ${LIB_SOURCES}) +add_subdirectory(${BOARD}) + + + + + + + +# Include the ISS board configuration +set(ISS_SOURCE_DIR "${CMAKE_SOURCE_DIR}/bare-metal-bsp/env/iss") +set(ISS_BINARY_DIR "${CMAKE_BINARY_DIR}/iss_build") + +add_subdirectory(${ISS_SOURCE_DIR} ${ISS_BINARY_DIR}) + + + +# Export variables for hello-world to use +set(ENV_OBJECTS + $ + $ + PARENT_SCOPE +) + +# Export board library +set(BOARD_LIB board_iss PARENT_SCOPE) diff --git a/env/common-gcc.mk b/env/common-gcc.mk index d140fca..dd10511 100644 --- a/env/common-gcc.mk +++ b/env/common-gcc.mk @@ -16,6 +16,7 @@ BOARD?=iss ASM_SRCS += $(ENV_DIR)/start.S $(ENV_DIR)/entry.S C_SRCS += $(PLATFORM_DIR)/init.c +C_SRCS += $(PLATFORM_DIR)/write.c LINKER_SCRIPT ?= $(PLATFORM_DIR)/$(LINK_TARGET).lds @@ -23,6 +24,7 @@ INCLUDES += -I$(BSP_BASE)/include INCLUDES += -I$(BSP_BASE)/drivers/ INCLUDES += -I$(ENV_DIR) INCLUDES += -I$(PLATFORM_DIR) +INCLUDES += -I$(BSP_BASE)/libwrap/sys/ LDFLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) LDFLAGS += -L$(ENV_DIR) diff --git a/env/iss/CMakeLists.txt b/env/iss/CMakeLists.txt new file mode 100644 index 0000000..994cd87 --- /dev/null +++ b/env/iss/CMakeLists.txt @@ -0,0 +1,26 @@ +# Create library for ISS board support +add_library(board_iss STATIC + init.c + write.c +) + +# Include directories +target_include_directories(board_iss PUBLIC + ${BSP_BASE}/include + ${BSP_BASE}/env + ${CMAKE_CURRENT_SOURCE_DIR} +) + +# Set compile options +target_compile_options(board_iss PRIVATE + -march=${RISCV_ARCH}_zicsr_zifencei + -mabi=${RISCV_ABI} + -mcmodel=medany + -ffunction-sections + -fdata-sections +) + +# Add compile definitions +target_compile_definitions(board_iss PRIVATE + BOARD_${BOARD} +) diff --git a/libwrap/CMakeLists.txt b/libwrap/CMakeLists.txt index dc3796a..a998307 100644 --- a/libwrap/CMakeLists.txt +++ b/libwrap/CMakeLists.txt @@ -1,55 +1,65 @@ +project(libwrap) -IF(NOT DEFINED _MK_LIBWRAP) +message(STATUS " here 2 in libwrap") -SET(_MK_LIBWRAP TRUE) +# Create object library for libwrap +set(LIB_SOURCES + sys/_exit.c + sys/close.c + sys/execve.c + sys/fork.c + sys/fstat.c + sys/getpid.c + sys/isatty.c + sys/kill.c + sys/link.c + sys/lseek.c + sys/open.c + sys/openat.c + sys/printf.c + sys/puts.c + sys/read.c + sys/sbrk.c + sys/stat.c + sys/times.c + sys/unlink.c + sys/wait.c + sys/write.c + # Standard library + stdlib/malloc.c + # Miscellaneous + misc/write_hex.c +) -SET(LIBWRAP_DIR ${CMAKE_CURRENT_LIST_DIR}) +if(SEMIHOSTING) + list(APPEND LIB_SOURCES + semihosting/semihosting.c + semihosting/trap.c ) + +endif() -SET(LIBWRAP_SRCS - ${LIBWRAP_DIR}/stdlib/malloc.c - ${LIBWRAP_DIR}/sys/open.c - ${LIBWRAP_DIR}/sys/lseek.c - ${LIBWRAP_DIR}/sys/read.c - ${LIBWRAP_DIR}/sys/write.c - ${LIBWRAP_DIR}/sys/fstat.c - ${LIBWRAP_DIR}/sys/stat.c - ${LIBWRAP_DIR}/sys/close.c - ${LIBWRAP_DIR}/sys/link.c - ${LIBWRAP_DIR}/sys/unlink.c - ${LIBWRAP_DIR}/sys/execve.c - ${LIBWRAP_DIR}/sys/fork.c - ${LIBWRAP_DIR}/sys/getpid.c - ${LIBWRAP_DIR}/sys/kill.c - ${LIBWRAP_DIR}/sys/wait.c - ${LIBWRAP_DIR}/sys/isatty.c - ${LIBWRAP_DIR}/sys/times.c - ${LIBWRAP_DIR}/sys/sbrk.c - ${LIBWRAP_DIR}/sys/_exit.c - ${LIBWRAP_DIR}/misc/write_hex.c - ${LIBWRAP_DIR}/sys/printf.c - ${LIBWRAP_DIR}/sys/puts.c -) -IF(${SEMIHOSTING}) - SET(LIBWRAP_SRCS ${LIBWRAP_SRCS} ${LIBWRAP_DIR}/semihosting/semihosting.c ${LIBWRAP_DIR}/semihosting/trap.c) -ENDIF() +add_library(${PROJECT_NAME} OBJECT ${LIB_SOURCES}) -SET(LIBWRAP_SYMS malloc free open lseek read write fstat stat close link unlink execve fork getpid jukk wait isatty times sbrk _exit printf puts) -# Includes -INCLUDE_DIRECTORIES( - ${LIBWRAP_DIR} - ${LIBWRAP_DIR}/../include - ${LIBWRAP_DIR}/../drivers - ${LIBWRAP_DIR}/../env - ${LIBWRAP_DIR}/../env/iss + +# Include directories +target_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${BSP_BASE}/include + include/ + ${BSP_BASE}/env + ${BSP_BASE}/env/${BOARD} + ${BSP_BASE}/drivers ) -ADD_LIBRARY(LIBWRAP_TGC STATIC ${LIBWRAP_SRCS}) -TARGET_COMPILE_OPTIONS(LIBWRAP_TGC PRIVATE -march=${RISCV_ARCH}_zicsr_zifencei -mabi=${RISCV_ABI} "-DBOARD_${BOARD}") +# Compile options -FOREACH(SYM ${LIBWRAP_SYMS}) - LIST(APPEND WRAP_LDFLAGS "-Wl,--wrap=${SYM}") -ENDFOREACH() +#link global_compile_options to this libraries +target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options) -SET(LIBWRAP_TGC_LDFLAGS ${WRAP_LDFLAGS} "-Wl,--start-group" "-Wl,--end-group" "-L. -lLIBWRAP_TGC") +# Compile definitions +#target_compile_definitions(libwrap_objects PRIVATE +# BOARD_${BOARD} +#) -ENDIF(NOT DEFINED _MK_LIBWRAP) +# Export objects to parent scope +set(LIBWRAP_OBJECTS $ PARENT_SCOPE) diff --git a/libwrap/libwrap.mk b/libwrap/libwrap.mk index aecf019..b4fd597 100644 --- a/libwrap/libwrap.mk +++ b/libwrap/libwrap.mk @@ -9,7 +9,6 @@ LIBWRAP_SRCS := \ sys/open.c \ sys/lseek.c \ sys/read.c \ - sys/write.c \ sys/fstat.c \ sys/stat.c \ sys/close.c \