This commit is contained in:
karutoh 2024-02-13 22:56:53 -08:00
parent 18ab086b3d
commit cfa7d5c75d
5 changed files with 62 additions and 6 deletions

View File

@ -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")

View File

@ -0,0 +1,8 @@
#pragma once
extern "C"
{
void construct() __attribute__((constructor));
void destruct() __attribute__((destructor));
}

View File

@ -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)

View File

@ -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 <zlib.h>
@ -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;
}

46
src/crt/ffi.cpp Normal file
View File

@ -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");
}