diff --git a/CMakeLists.txt b/CMakeLists.txt index d4b8ff2..df75248 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,8 @@ set(EHS_SOURCES src/io/hid/Input.cpp include/ehs/io/hid/Input.h include/ehs/io/Console.h include/ehs/system/Lock.h + src/crt/ffi.cpp + include/ehs/crt/CRT_LNX.h ) if (IS_OS_WINDOWS) @@ -231,7 +233,7 @@ target_include_directories(EHS PUBLIC ${PROJECT_SOURCE_DIR}/include) if (IS_OS_LINUX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions") - target_link_options(EHS PUBLIC -nostdlib -nostartfiles -e start -T ${PROJECT_SOURCE_DIR}/custom.ld) + target_link_options(EHS PUBLIC -T ${PROJECT_SOURCE_DIR}/custom.ld) set(CMAKE_INSTALL_PREFIX "${USER_HOME_DIRECTORY}/.local") elseif (IS_OS_WINDOWS) set(CMAKE_INSTALL_PREFIX "${USER_HOME_DIRECTORY}/EHS") diff --git a/include/ehs/crt/CRT_LNX.h b/include/ehs/crt/CRT_LNX.h new file mode 100644 index 0000000..221d894 --- /dev/null +++ b/include/ehs/crt/CRT_LNX.h @@ -0,0 +1,8 @@ +#pragma once + +extern "C" +{ + void construct() __attribute__((constructor)); + + void destruct() __attribute__((destructor)); +} \ No newline at end of file diff --git a/src/CRT_LNX.cpp b/src/CRT_LNX.cpp index 1f6f209..dcaaa51 100644 --- a/src/CRT_LNX.cpp +++ b/src/CRT_LNX.cpp @@ -1,3 +1,4 @@ +#include "ehs/crt/CRT_LNX.h" #include "ehs/Log.h" #include "ehs/HRNG.h" @@ -74,16 +75,12 @@ extern "C" return 0; } - void construct() __attribute__((constructor)); - void construct() { for (void (**p)() = __start_init_array; p < __stop_init_array; ++p) (*p)(); } - void destruct() __attribute__((destructor)); - void destruct() { for (void (**p)() = __start_fini_array; p < __stop_fini_array; ++p) diff --git a/src/EHS.cpp b/src/EHS.cpp index 6a86b5f..1bb7c6d 100644 --- a/src/EHS.cpp +++ b/src/EHS.cpp @@ -7,6 +7,7 @@ #include "ehs/io/img/Img.h" #include "ehs/io/img/PNG.h" #include "ehs/io/RIFF.h" +#include "ehs/crt/CRT_LNX.h" #include @@ -635,7 +636,7 @@ void LogRaised(const ehs::Log& log) ehs::BaseConsole::Write_8(result); } -void start() +int main() { ehs::Console::Attach(); @@ -682,4 +683,6 @@ void start() ehs::GarbageCollector::Stop(); ehs::Console::Free(); + + return code; } \ No newline at end of file diff --git a/src/crt/ffi.cpp b/src/crt/ffi.cpp new file mode 100644 index 0000000..e2d345c --- /dev/null +++ b/src/crt/ffi.cpp @@ -0,0 +1,46 @@ +#include "ehs/Types.h" + +extern "C" +{ + // Mock ffi_type structure + struct ffi_type + { + ehs::UInt_64 size; + unsigned short alignment; + unsigned short type; + struct ffi_type** elements; + }; + + // Mock ffi_status enum + typedef enum + { + FFI_OK, + FFI_BAD_TYPEDEF, + FFI_BAD_ABI + } ffi_status; + + // Declare the ffi_type variables as extern if they are defined elsewhere or just define them if they are used locally + struct ffi_type ffi_type_void = {0, 0, 0, nullptr}; + struct ffi_type ffi_type_pointer = {sizeof(void*), __alignof__(void*), 0, nullptr}; + struct ffi_type ffi_type_uint32 = {sizeof(unsigned int), __alignof__(unsigned int), 0, nullptr}; + struct ffi_type ffi_type_sint32 = {sizeof(int), __alignof__(int), 0, nullptr}; + + // Mock ffi_prep_cif function + ffi_status ffi_prep_cif(void* cif, int abi, unsigned int nargs, struct ffi_type* rtype, struct ffi_type** atypes) + { + return FFI_OK; // Pretend success + } + + // Mock ffi_call function + void ffi_call(void* cif, void (* fn)(), void* rvalue, void** avalues) + { + // Do nothing + } + + __asm__(".symver ffi_type_void,ffi_type_void@LIBFFI_BASE_8.0"); + __asm__(".symver ffi_type_pointer,ffi_type_pointer@LIBFFI_BASE_8.0"); + __asm__(".symver ffi_type_uint32,ffi_type_uint32@LIBFFI_BASE_8.0"); + __asm__(".symver ffi_type_sint32,ffi_type_sint32@LIBFFI_BASE_8.0"); + __asm__(".symver ffi_prep_cif,ffi_prep_cif@LIBFFI_BASE_8.0"); + __asm__(".symver ffi_call,ffi_call@LIBFFI_BASE_8.0"); +} \ No newline at end of file