implement SuperH4 support, building with custom stdlib (libc)

This commit is contained in:
mykola2312 2022-06-07 10:23:57 +03:00
parent 011ead1a1c
commit 17bbc4af49
3 changed files with 68 additions and 5 deletions

View file

@ -24,11 +24,15 @@ set(SOURCES
heap.c
)
set(ARCHITECTURE "ARMv7" CACHE STRING "cutil target architecture")
set(ARCHITECTURE "SuperH4" CACHE STRING "cutil target architecture")
set(ARM_PROCESSOR "cortex-m4" CACHE STRING "cutil ARM processor")
set(ARM_PROFILE "a" CACHE STRING "cutil ARM architecture profile")
if ("${ARCHITECTURE}" MATCHES "ARM*")
set(CUSTOM_STDLIB "" CACHE STRING "custom stdlib path")
add_compile_definitions(ARM_PROCESSOR="${ARM_PROCESSOR}")
add_compile_definitions(ARM_PROFILE="${ARM_PROFILE}")
if ("${ARM_PROFILE}" STREQUAL "m")
add_compile_options("-mcpu=${ARM_PROCESSOR}")
add_compile_options("-mthumb")
@ -38,20 +42,28 @@ if ("${ARCHITECTURE}" MATCHES "ARM*")
add_compile_options("-march=${COMPILE_ARCHITECTURE}-${ARM_PROFILE}")
add_compile_options("-marm")
endif()
elseif("${ARCHITECTURE}" MATCHES "SuperH4")
set(CUSTOM_STDLIB "/opt/sh4-platform/lib" CACHE STRING "custom stdlib path")
add_compile_options("-m4")
endif()
add_compile_definitions(ARM_PROCESSOR="${ARM_PROCESSOR}")
add_compile_definitions(ARM_PROFILE="${ARM_PROFILE}")
add_library(cutil STATIC ${SOURCES} ${HEADERS}
"arch/${ARCHITECTURE}.S"
)
option(NOSTDLIB "compile cutil without stdlib" ON)
option(STATIC "compile test static" OFF)
if (NOSTDLIB)
target_compile_definitions(cutil PRIVATE CUTIL_NOSTDLIB)
target_compile_options(cutil PRIVATE "-nostdlib")
endif()
if(NOT "${CUSTOM_STDLIB}" STREQUAL "")
add_compile_options("-nostdlib")
set(CMAKE_EXE_LINKER_FLAGS "-L${CUSTOM_STDLIB} -l:libc.so.6")
elseif (STATIC)
add_link_options(-static)
endif()
add_executable(test test.c)
target_link_libraries(test -static cutil)
target_link_libraries(test cutil)

47
arch/SuperH4.S Normal file
View file

@ -0,0 +1,47 @@
.globl hw_bswap16
.globl hw_bswap32
.globl hw_bswap64
.globl _cu_memcpy
.globl _cu_memmove
.globl _cu_memcmp
.globl _cu_memset
.globl cu_memzero
.globl cu_memtest
.globl cu_va_start
.globl cu_va_arg
.text
.align 16
hw_bswap16:
rts
hw_bswap32:
rts
hw_bswap64:
rts
_cu_memcpy:
rts
_cu_memmove:
rts
_cu_memcmp:
rts
_cu_memset:
rts
cu_memzero:
rts
cu_memtest:
rts
cu_va_start:
rts
cu_va_arg:
rts

View file

@ -21,6 +21,10 @@ typedef struct {
typedef struct {
uword fp;
} cu_va_list;
#elif (defined(CU_ARCH_SUPERH))
typedef struct {
uword fp;
} cu_va_list;
#endif
extern void cu_va_start(cu_va_list* va);