splits write.c, adds iss implementation and adds CMake build system

This commit is contained in:
Eyck-Alexander Jentzsch 2025-01-06 20:19:05 +01:00
parent bace1c31c1
commit 32ff23709f
5 changed files with 80 additions and 173 deletions

View File

@ -1,11 +1,28 @@
cmake_minimum_required(VERSION 3.12) cmake_minimum_required(VERSION 3.21)
project(bsp C) project(mnrs-bsp LANGUAGES ASM C)
if(NOT DEFINED BOARD)
message(FATAL_ERROR "No Board selected")
endif()
add_compile_definitions("BOARD_${BOARD}")
# check if we are building for a testbench, adjust the Base accordingly
set(BOARD_BASE ${BOARD})
option(SEMIHOSTING "Enable semihosting support" OFF)
if(SEMIHOSTING)
add_compile_definitions(SEMIHOSTING)
endif()
add_library(startup STATIC env/start.S env/entry.S)
target_include_directories(startup PUBLIC env include)
add_subdirectory(libwrap) add_subdirectory(libwrap)
add_subdirectory(env)
message(STATUS " in bsp with ${CMAKE_CXX_FLAGS}") add_library(bsp INTERFACE)
message(STATUS " SUPPORTED_BOARDS= ${SUPPORTED_BOARDS}") target_link_libraries(bsp INTERFACE startup wrap)
add_library(${PROJECT_NAME} INTERFACE) target_include_directories(bsp INTERFACE env/${BOARD_BASE})
target_include_directories(${PROJECT_NAME} INTERFACE target_link_options(bsp INTERFACE LINKER:--no-warn-rwx-segments -nostartfiles -T ${CMAKE_CURRENT_SOURCE_DIR}/env/${BOARD_BASE}/link.lds)
include/ if(SEMIHOSTING)
env/${BOARD} target_include_directories(bsp INTERFACE /include)
env/) target_sources(bsp INTERFACE env/semihosting.c env/trap.c)
endif()

18
env/iss/bsp_write.c vendored Normal file
View File

@ -0,0 +1,18 @@
/* See LICENSE of license details. */
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
ssize_t _bsp_write(int fd, const void *ptr, size_t len) {
const uint8_t *current = (const uint8_t *)ptr;
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
*((uint32_t *)0xFFFF0000) = current[jj];
}
return len;
}
return 1;
}

38
env/iss/write.c vendored
View File

@ -1,38 +0,0 @@
/* See LICENSE of license details. */
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
#include "platform.h"
#include "stub.h"
#include "weak_under_alias.h"
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
ssize_t __wrap_write(int fd, const void *ptr, size_t len) {
const uint8_t *current = (const uint8_t *)ptr;
#if defined(SEMIHOSTING)
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
sh_writec(current[jj]);
}
return len;
} else {
sh_write(current, fd);
return len;
}
// return len;
#endif
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
*((uint32_t *)0xFFFF0000) = current[jj];
}
return len;
}
return _stub(EBADF);
}
weak_under_alias(write);

View File

@ -1,11 +1,4 @@
#cmake_minimum_required(VERSION 3.12) include(CMakePrintHelpers)
project(libwrap)
message(STATUS " here 2 in libwrap")
set(LIBRARY_NAME libwrap)
set(STATIC_LIBRARY_FLAGS "rcs")
# Create object library for libwrap
set(LIB_SOURCES set(LIB_SOURCES
sys/_exit.c sys/_exit.c
sys/close.c sys/close.c
@ -27,51 +20,21 @@ set(LIB_SOURCES
sys/times.c sys/times.c
sys/unlink.c sys/unlink.c
sys/wait.c sys/wait.c
# sys/write.c sys/write.c
# Standard library # Standard library
stdlib/malloc.c stdlib/malloc.c
# Miscellaneous # Miscellaneous
misc/write_hex.c misc/write_hex.c
) )
set(WRAP_ARGS "")
if(SEMIHOSTING) foreach(FILE ${LIB_SOURCES})
list(APPEND LIB_SOURCES get_filename_component(DIR ${FILE} DIRECTORY)
semihosting/semihosting.c if(DIR STREQUAL "sys")
semihosting/trap.c ) get_filename_component(BASE_NAME ${FILE} NAME_WE)
list(APPEND WRAP_ARGS "LINKER:--wrap=${BASE_NAME}")
endif() endif()
endforeach()
#add_library(${LIBRARY_NAME} OBJECT ${LIB_SOURCES}) add_library(wrap STATIC ${LIB_SOURCES} ../env/${BOARD_BASE}/bsp_write.c ../env/${BOARD_BASE}/bsp_read.c)
add_library(${LIBRARY_NAME} STATIC ${LIB_SOURCES}) target_link_options(wrap INTERFACE ${WRAP_ARGS})
set_target_properties(${LIBRARY_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bare-metal-bsp/${PROJECT_NAME})
message(STATUS " CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
# Retrieve the output directory for the library
get_target_property(LIBRARY_PATH ${LIBRARY_NAME} ARCHIVE_OUTPUT_DIRECTORY)
# Print the path to the console (for debugging purposes)
message(STATUS "The library output path is: ${LIBRARY_PATH}")
# Include directories
target_include_directories(${LIBRARY_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${BSP_BASE}/include
include/
${BSP_BASE}/env
${BSP_BASE}/env/${BOARD}
${BSP_BASE}/drivers
)
#link global_compile_options to this libraries
#target_link_libraries(${PROJECT_NAME} PRIVATE global_compile_options)
# Compile definitions
#target_compile_definitions(libwrap_objects PRIVATE
# BOARD_${BOARD}
#)
# Export objects to parent scope
#set(LIBWRAP_OBJECTS $<TARGET_OBJECTS:${PROJECT_NAME}> PARENT_SCOPE)

View File

@ -1,61 +1,8 @@
/* See LICENSE of license details. */ #include "weak_under_alias.h"
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "platform.h" extern ssize_t _bsp_write(int, const void *, size_t);
#include "stub.h"
#include "weak_under_alias.h"
#if defined(SEMIHOSTING)
#include "semihosting.h"
#endif
ssize_t __wrap_write(int fd, const void *ptr, size_t len) { ssize_t __wrap_write(int fd, const void *ptr, size_t len) {
const uint8_t *current = (const uint8_t *)ptr; return _bsp_write(fd, ptr, len);
#if defined(SEMIHOSTING)
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
sh_writec(current[jj]);
}
return len;
} else {
sh_write(current, fd);
return len;
}
// return len;
#endif
if (isatty(fd)) {
for (size_t jj = 0; jj < len; jj++) {
#if defined(BOARD_ehrenberg) || defined(BOARD_tgc_vp)
while (get_uart_rx_tx_reg_tx_free(uart) == 0)
;
uart_write(uart, current[jj]);
if (current[jj] == '\n') {
while (get_uart_rx_tx_reg_tx_free(uart) == 0)
;
uart_write(uart, '\r');
}
#elif defined(BOARD_iss)
*((uint32_t *)0xFFFF0000) = current[jj];
#elif defined(BOARD_TGCP)
// TODO: implement
#else
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000)
;
UART0_REG(UART_REG_TXFIFO) = current[jj];
if (current[jj] == '\n') {
while (UART0_REG(UART_REG_TXFIFO) & 0x80000000)
;
UART0_REG(UART_REG_TXFIFO) = '\r';
}
#endif
}
return len;
}
return _stub(EBADF);
} }
weak_under_alias(write); weak_under_alias(write);