build: fix kernel build on different architectures

Userspace still fails to compile on non-x86!!!
This commit is contained in:
2025-04-13 13:47:59 +00:00
parent 33eee9c628
commit 0735743f44
19 changed files with 618 additions and 43 deletions

View File

@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.10)
project(FennixRuntime_${TARGET_OS}_${TARGET_ARCH})
find_program(COMPILER_PATH NAMES $ENV{CC} gcc REQUIRED)
set(LIB_OUTPUT_DIR "${CMAKE_INSTALL_PREFIX}/lib")
file(MAKE_DIRECTORY ${LIB_OUTPUT_DIR})
add_custom_target(copy_crt_files ALL
COMMAND ${COMPILER_PATH} -print-file-name=libgcc.a | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtbegin.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtend.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crti.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtn.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMENT "Copying CRT files"
)
file(GLOB CRT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
set(OBJECT_FILES "")
foreach(source ${CRT_SOURCES})
get_filename_component(name ${source} NAME_WE)
set(obj "${CMAKE_BINARY_DIR}/${name}.o")
add_custom_command(
OUTPUT ${obj}
COMMAND ${COMPILER_PATH} -c ${source} -o ${obj}
DEPENDS ${source}
)
list(APPEND OBJECT_FILES ${obj})
endforeach()
if(OBJECT_FILES)
add_custom_target(crt_objects ALL DEPENDS ${OBJECT_FILES})
install(FILES ${OBJECT_FILES} DESTINATION lib)
endif()

View File

@ -0,0 +1 @@
#include "crt1.c"

View File

@ -0,0 +1,53 @@
/*
This file is part of Fennix C Library.
Fennix C Library is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
__attribute__((naked, used, no_stack_protector, section(".text"))) void _start()
{
#warning "crt1.c: _start() is not implemented yet"
}
/* These are declared in GNU ld */
enum
{
NT_FNX_ABI_TAG = 1,
NT_FNX_VERSION = 2,
NT_FNX_BUILD_ID = 3,
NT_FNX_ARCH = 4
};
typedef struct Elf_Nhdr
{
__UINT32_TYPE__ n_namesz;
__UINT32_TYPE__ n_descsz;
__UINT32_TYPE__ n_type;
char n_name[];
} __attribute__((packed)) Elf_Nhdr;
const struct
{
Elf_Nhdr header;
char name[4];
__UINT32_TYPE__ desc[4];
} __abi_tag __attribute__((used, aligned(4), section(".note.ABI-tag"))) = {
.header = {
.n_namesz = 4, /* "FNX" + '\0' */
.n_descsz = sizeof(__UINT32_TYPE__) * 4, /* Description Size */
.n_type = NT_FNX_ABI_TAG, /* Type */
},
.name = "FNX",
.desc = {0, 0, 0, 0},
};

View File

@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.10)
project(FennixRuntime_${TARGET_OS}_${TARGET_ARCH})
find_program(COMPILER_PATH NAMES $ENV{CC} gcc REQUIRED)
set(LIB_OUTPUT_DIR "${CMAKE_INSTALL_PREFIX}/lib")
file(MAKE_DIRECTORY ${LIB_OUTPUT_DIR})
add_custom_target(copy_crt_files ALL
COMMAND ${COMPILER_PATH} -print-file-name=libgcc.a | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtbegin.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtend.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crti.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtn.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMENT "Copying CRT files"
)
file(GLOB CRT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
set(OBJECT_FILES "")
foreach(source ${CRT_SOURCES})
get_filename_component(name ${source} NAME_WE)
set(obj "${CMAKE_BINARY_DIR}/${name}.o")
add_custom_command(
OUTPUT ${obj}
COMMAND ${COMPILER_PATH} -c ${source} -o ${obj}
DEPENDS ${source}
)
list(APPEND OBJECT_FILES ${obj})
endforeach()
if(OBJECT_FILES)
add_custom_target(crt_objects ALL DEPENDS ${OBJECT_FILES})
install(FILES ${OBJECT_FILES} DESTINATION lib)
endif()

View File

@ -0,0 +1 @@
#include "crt1.c"

View File

@ -0,0 +1,53 @@
/*
This file is part of Fennix C Library.
Fennix C Library is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
__attribute__((naked, used, no_stack_protector, section(".text"))) void _start()
{
#warning "crt1.c: _start() is not implemented yet"
}
/* These are declared in GNU ld */
enum
{
NT_FNX_ABI_TAG = 1,
NT_FNX_VERSION = 2,
NT_FNX_BUILD_ID = 3,
NT_FNX_ARCH = 4
};
typedef struct Elf_Nhdr
{
__UINT32_TYPE__ n_namesz;
__UINT32_TYPE__ n_descsz;
__UINT32_TYPE__ n_type;
char n_name[];
} __attribute__((packed)) Elf_Nhdr;
const struct
{
Elf_Nhdr header;
char name[4];
__UINT32_TYPE__ desc[4];
} __abi_tag __attribute__((used, aligned(4), section(".note.ABI-tag"))) = {
.header = {
.n_namesz = 4, /* "FNX" + '\0' */
.n_descsz = sizeof(__UINT32_TYPE__) * 4, /* Description Size */
.n_type = NT_FNX_ABI_TAG, /* Type */
},
.name = "FNX",
.desc = {0, 0, 0, 0},
};

View File

@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.10)
project(FennixRuntime_${TARGET_OS}_${TARGET_ARCH})
find_program(COMPILER_PATH NAMES $ENV{CC} gcc REQUIRED)
set(LIB_OUTPUT_DIR "${CMAKE_INSTALL_PREFIX}/lib")
file(MAKE_DIRECTORY ${LIB_OUTPUT_DIR})
add_custom_target(copy_crt_files ALL
COMMAND ${COMPILER_PATH} -print-file-name=libgcc.a | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtbegin.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtend.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crti.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMAND ${COMPILER_PATH} -print-file-name=crtn.o | xargs cp -t ${LIB_OUTPUT_DIR}
COMMENT "Copying CRT files"
)
file(GLOB CRT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
set(OBJECT_FILES "")
foreach(source ${CRT_SOURCES})
get_filename_component(name ${source} NAME_WE)
set(obj "${CMAKE_BINARY_DIR}/${name}.o")
add_custom_command(
OUTPUT ${obj}
COMMAND ${COMPILER_PATH} -c ${source} -o ${obj}
DEPENDS ${source}
)
list(APPEND OBJECT_FILES ${obj})
endforeach()
if(OBJECT_FILES)
add_custom_target(crt_objects ALL DEPENDS ${OBJECT_FILES})
install(FILES ${OBJECT_FILES} DESTINATION lib)
endif()

View File

@ -0,0 +1 @@
#include "crt1.c"

View File

@ -0,0 +1,53 @@
/*
This file is part of Fennix C Library.
Fennix C Library is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
Fennix C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fennix C Library. If not, see <https://www.gnu.org/licenses/>.
*/
__attribute__((naked, used, no_stack_protector, section(".text"))) void _start()
{
#warning "crt1.c: _start() is not implemented yet"
}
/* These are declared in GNU ld */
enum
{
NT_FNX_ABI_TAG = 1,
NT_FNX_VERSION = 2,
NT_FNX_BUILD_ID = 3,
NT_FNX_ARCH = 4
};
typedef struct Elf_Nhdr
{
__UINT32_TYPE__ n_namesz;
__UINT32_TYPE__ n_descsz;
__UINT32_TYPE__ n_type;
char n_name[];
} __attribute__((packed)) Elf_Nhdr;
const struct
{
Elf_Nhdr header;
char name[4];
__UINT32_TYPE__ desc[4];
} __abi_tag __attribute__((used, aligned(4), section(".note.ABI-tag"))) = {
.header = {
.n_namesz = 4, /* "FNX" + '\0' */
.n_descsz = sizeof(__UINT32_TYPE__) * 4, /* Description Size */
.n_type = NT_FNX_ABI_TAG, /* Type */
},
.name = "FNX",
.desc = {0, 0, 0, 0},
};