mirror of
https://github.com/wiiu-env/wut.git
synced 2025-01-06 13:58:18 +01:00
Split out crt from wutnewlib to wutcrt.
Can now optionally link newlib, stdc++, devoptab.
This commit is contained in:
parent
479e9ad677
commit
b4a6eb2f78
@ -4,6 +4,7 @@ project(libraries C)
|
||||
add_subdirectory(libdefaultheap)
|
||||
add_subdirectory(libgfd)
|
||||
add_subdirectory(libwhb)
|
||||
add_subdirectory(wutcrt)
|
||||
add_subdirectory(wutdevoptab)
|
||||
add_subdirectory(wutnewlib)
|
||||
add_subdirectory(wutstdc++)
|
||||
|
12
libraries/wutcrt/CMakeLists.txt
Normal file
12
libraries/wutcrt/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(wutnewlib C)
|
||||
|
||||
set_property(SOURCE crt0.s PROPERTY LANGUAGE C)
|
||||
|
||||
add_library(wutcrt
|
||||
crt0.s
|
||||
wut_crt.c)
|
||||
target_include_directories(wutcrt PRIVATE "${WUT_ROOT}/include")
|
||||
|
||||
install(TARGETS wutcrt
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
|
@ -1,15 +1,18 @@
|
||||
.extern main
|
||||
.extern exit
|
||||
.extern __init_wut
|
||||
.extern __fini_wut
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
stwu 1, -0x8(1)
|
||||
stw 3, 0(1)
|
||||
stw 4, 4(1)
|
||||
bl __init_wut_newlibc
|
||||
bl __init_wut
|
||||
lwz 3, 0(1)
|
||||
lwz 4, 4(1)
|
||||
bl main
|
||||
bl __fini_wut
|
||||
# Calling __fini is leading to crashes!
|
||||
# bl __fini
|
||||
addi 1, 1, 0x8
|
39
libraries/wutcrt/wut_crt.c
Normal file
39
libraries/wutcrt/wut_crt.c
Normal file
@ -0,0 +1,39 @@
|
||||
extern void __init_wut_newlib() __attribute__((weak));
|
||||
extern void __init_wut_devoptab() __attribute__((weak));
|
||||
extern void __init_wut_stdcpp() __attribute__((weak));
|
||||
|
||||
extern void __fini_wut_devoptab() __attribute__((weak));
|
||||
extern void __fini_wut_newlib() __attribute__((weak));
|
||||
extern void __fini_wut_stdcpp() __attribute__((weak));
|
||||
|
||||
void
|
||||
__init_wut()
|
||||
{
|
||||
if (__init_wut_newlib) {
|
||||
__init_wut_newlib();
|
||||
}
|
||||
|
||||
if (__init_wut_devoptab) {
|
||||
__init_wut_devoptab();
|
||||
}
|
||||
|
||||
if (__init_wut_stdcpp) {
|
||||
__init_wut_stdcpp();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__fini_wut()
|
||||
{
|
||||
if (__fini_wut_stdcpp) {
|
||||
__fini_wut_stdcpp();
|
||||
}
|
||||
|
||||
if (__fini_wut_devoptab) {
|
||||
__fini_wut_devoptab();
|
||||
}
|
||||
|
||||
if (__fini_wut_newlib) {
|
||||
__fini_wut_newlib();
|
||||
}
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(wutnewlib C)
|
||||
|
||||
set_property(SOURCE crt0.s PROPERTY LANGUAGE C)
|
||||
|
||||
add_library(wutnewlib
|
||||
crt0.s
|
||||
sleep.c
|
||||
syscalls.c)
|
||||
target_include_directories(wutnewlib PRIVATE "${WUT_ROOT}/include")
|
||||
|
@ -18,9 +18,6 @@ static uint8_t *sHeapBase = NULL;
|
||||
static uint32_t sHeapMaxSize = 0;
|
||||
static volatile uint32_t sHeapSize = 0;
|
||||
|
||||
void
|
||||
__init_wut_newlibc();
|
||||
|
||||
static void *
|
||||
__libwut_sbrk_r(struct _reent *r,
|
||||
ptrdiff_t incr)
|
||||
@ -172,16 +169,16 @@ __init_syscall_array()
|
||||
__syscalls.gettod_r = __libwut_gettod_r;
|
||||
}
|
||||
|
||||
extern void __init_wut_gthread() __attribute__((weak));
|
||||
|
||||
void
|
||||
__init_wut_newlibc()
|
||||
__init_wut_newlib()
|
||||
{
|
||||
__init_libc_heap();
|
||||
__init_malloc_lock();
|
||||
__init_syscall_array();
|
||||
|
||||
if (__init_wut_gthread) {
|
||||
__init_wut_gthread();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__fini_wut_newlib()
|
||||
{
|
||||
__free_libc_heap();
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ add_library(wutstdc++
|
||||
wut_gthread_mutex.cc
|
||||
wut_gthread_once.cc
|
||||
wut_gthread_recursive_mutex.cc
|
||||
wut_gthread_thread.cc)
|
||||
wut_gthread_thread.cc
|
||||
wut_stdcpp.cc)
|
||||
|
||||
target_compile_definitions(wutstdc++
|
||||
PRIVATE _GLIBCXX_HAS_GTHREADS)
|
||||
|
@ -37,9 +37,6 @@ __wut_active_p()
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void
|
||||
__init_wut_gthread()
|
||||
{
|
||||
@ -74,5 +71,3 @@ __init_wut_gthread()
|
||||
__gthread_impl.cond_wait_recursive = (__gthread_fn_cond_wait_recursive)__wut_cond_wait_recursive;
|
||||
__gthread_impl.cond_destroy = (__gthread_fn_cond_destroy)__wut_cond_destroy;
|
||||
}
|
||||
|
||||
} // extern "c"
|
||||
|
@ -20,6 +20,9 @@
|
||||
typedef volatile uint32_t __wut_once_t;
|
||||
typedef uint32_t __wut_key_t;
|
||||
|
||||
void
|
||||
__init_wut_gthread();
|
||||
|
||||
int
|
||||
__wut_active_p();
|
||||
|
||||
|
12
libraries/wutstdc++/wut_stdcpp.cc
Normal file
12
libraries/wutstdc++/wut_stdcpp.cc
Normal file
@ -0,0 +1,12 @@
|
||||
#include "wut_gthread.h"
|
||||
|
||||
extern "C" void
|
||||
__init_wut_stdcpp()
|
||||
{
|
||||
__init_wut_gthread();
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
__fini_wut_stdcpp()
|
||||
{
|
||||
}
|
@ -1,24 +1,39 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
macro(wut_enable_newlib target)
|
||||
set_property(TARGET ${target}
|
||||
APPEND_STRING PROPERTY
|
||||
LINK_FLAGS " -Wl,--whole-archive -lwutnewlib -Wl,--no-whole-archive")
|
||||
endmacro(wut_enable_newlib)
|
||||
|
||||
macro(wut_enable_devoptab target)
|
||||
set_property(TARGET ${target}
|
||||
APPEND_STRING PROPERTY
|
||||
LINK_FLAGS " -Wl,--whole-archive -lwutdevoptab -Wl,--no-whole-archive")
|
||||
endmacro(wut_enable_devoptab)
|
||||
|
||||
macro(wut_enable_stdcpp target)
|
||||
target_link_libraries(${target}
|
||||
wutnewlib
|
||||
stdc++)
|
||||
stdc++)
|
||||
|
||||
set_target_properties(${target} PROPERTIES
|
||||
COMPILE_FLAGS "-std=c++17"
|
||||
LINK_FLAGS "-Wl,--whole-archive -lwutstdc++ -Wl,--no-whole-archive")
|
||||
set_property(TARGET ${target}
|
||||
APPEND_STRING PROPERTY
|
||||
COMPILE_FLAGS "-std=c++17")
|
||||
|
||||
set_property(TARGET ${target}
|
||||
APPEND_STRING PROPERTY
|
||||
LINK_FLAGS " -Wl,--whole-archive -lwutstdc++ -Wl,--no-whole-archive")
|
||||
endmacro(wut_enable_stdcpp)
|
||||
|
||||
macro(wut_create_rpx target source)
|
||||
target_link_libraries(${source}
|
||||
wutnewlib
|
||||
coreinit)
|
||||
wutnewlib
|
||||
coreinit)
|
||||
|
||||
add_custom_target(${target} ALL
|
||||
COMMAND ${WUT_ELF2RPL} ${source} ${target}
|
||||
DEPENDS ${source}
|
||||
COMMENT "Converting to RPX ${target}")
|
||||
COMMAND ${WUT_ELF2RPL} ${source} ${target}
|
||||
DEPENDS ${source}
|
||||
COMMENT "Converting to RPX ${target}")
|
||||
|
||||
add_dependencies(${target} ${source})
|
||||
endmacro(wut_create_rpx)
|
||||
|
@ -30,7 +30,7 @@ set(WUT_C_FLAGS "-mcpu=750 -meabi -mhard-float -Wl,-q \"-I${WUT_ROOT}
|
||||
set(CMAKE_C_FLAGS "${WUT_C_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_CXX_FLAGS "${WUT_C_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_ASM_FLAGS "${WUT_C_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc -T \"${WUT_ROOT}/share/wut.ld\" \"-L${WUT_ROOT}/lib\"" CACHE STRING "")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-z,nocopyreloc -T \"${WUT_ROOT}/share/wut.ld\" \"-L${WUT_ROOT}/lib\" -lcoreinit -lwutcrt" CACHE STRING "")
|
||||
|
||||
# Setup root to exclude host system headers + libraries
|
||||
set(CMAKE_FIND_ROOT_PATH "${DEVKITPPC}" "${WUT_ROOT}/bin" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share")
|
||||
|
Loading…
Reference in New Issue
Block a user