splits write.c, adds iss implementation and adds CMake build system
This commit is contained in:
parent
bace1c31c1
commit
32ff23709f
@ -1,11 +1,28 @@
|
||||
cmake_minimum_required(VERSION 3.12)
|
||||
project(bsp C)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
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(env)
|
||||
message(STATUS " in bsp with ${CMAKE_CXX_FLAGS}")
|
||||
message(STATUS " SUPPORTED_BOARDS= ${SUPPORTED_BOARDS}")
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||
include/
|
||||
env/${BOARD}
|
||||
env/)
|
||||
|
||||
add_library(bsp INTERFACE)
|
||||
target_link_libraries(bsp INTERFACE startup wrap)
|
||||
target_include_directories(bsp INTERFACE env/${BOARD_BASE})
|
||||
target_link_options(bsp INTERFACE LINKER:--no-warn-rwx-segments -nostartfiles -T ${CMAKE_CURRENT_SOURCE_DIR}/env/${BOARD_BASE}/link.lds)
|
||||
if(SEMIHOSTING)
|
||||
target_include_directories(bsp INTERFACE /include)
|
||||
target_sources(bsp INTERFACE env/semihosting.c env/trap.c)
|
||||
endif()
|
||||
|
18
env/iss/bsp_write.c
vendored
Normal file
18
env/iss/bsp_write.c
vendored
Normal 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
38
env/iss/write.c
vendored
@ -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);
|
@ -1,77 +1,40 @@
|
||||
#cmake_minimum_required(VERSION 3.12)
|
||||
project(libwrap)
|
||||
|
||||
message(STATUS " here 2 in libwrap")
|
||||
set(LIBRARY_NAME libwrap)
|
||||
set(STATIC_LIBRARY_FLAGS "rcs")
|
||||
|
||||
# Create object library for libwrap
|
||||
include(CMakePrintHelpers)
|
||||
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
|
||||
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(WRAP_ARGS "")
|
||||
foreach(FILE ${LIB_SOURCES})
|
||||
get_filename_component(DIR ${FILE} DIRECTORY)
|
||||
if(DIR STREQUAL "sys")
|
||||
get_filename_component(BASE_NAME ${FILE} NAME_WE)
|
||||
list(APPEND WRAP_ARGS "LINKER:--wrap=${BASE_NAME}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(SEMIHOSTING)
|
||||
list(APPEND LIB_SOURCES
|
||||
semihosting/semihosting.c
|
||||
semihosting/trap.c )
|
||||
|
||||
endif()
|
||||
add_library(wrap STATIC ${LIB_SOURCES} ../env/${BOARD_BASE}/bsp_write.c ../env/${BOARD_BASE}/bsp_read.c)
|
||||
target_link_options(wrap INTERFACE ${WRAP_ARGS})
|
||||
|
||||
#add_library(${LIBRARY_NAME} OBJECT ${LIB_SOURCES})
|
||||
add_library(${LIBRARY_NAME} STATIC ${LIB_SOURCES})
|
||||
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)
|
||||
|
@ -1,61 +1,8 @@
|
||||
/* See LICENSE of license details. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include "weak_under_alias.h"
|
||||
#include <unistd.h>
|
||||
|
||||
#include "platform.h"
|
||||
#include "stub.h"
|
||||
#include "weak_under_alias.h"
|
||||
#if defined(SEMIHOSTING)
|
||||
#include "semihosting.h"
|
||||
#endif
|
||||
|
||||
extern ssize_t _bsp_write(int, const void *, size_t);
|
||||
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++) {
|
||||
#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);
|
||||
return _bsp_write(fd, ptr, len);
|
||||
}
|
||||
weak_under_alias(write);
|
||||
|
Loading…
x
Reference in New Issue
Block a user