From 17bbc4af49d9bd80a62ffec478e54c48bac24258 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 7 Jun 2022 10:23:57 +0300 Subject: [PATCH] implement SuperH4 support, building with custom stdlib (libc) --- CMakeLists.txt | 22 +++++++++++++++++----- arch/SuperH4.S | 47 +++++++++++++++++++++++++++++++++++++++++++++++ va_list.h | 4 ++++ 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 arch/SuperH4.S diff --git a/CMakeLists.txt b/CMakeLists.txt index 46280ff..409656f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) \ No newline at end of file +target_link_libraries(test cutil) \ No newline at end of file diff --git a/arch/SuperH4.S b/arch/SuperH4.S new file mode 100644 index 0000000..a163710 --- /dev/null +++ b/arch/SuperH4.S @@ -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 diff --git a/va_list.h b/va_list.h index 4f37e89..9f182bc 100644 --- a/va_list.h +++ b/va_list.h @@ -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);