lib: c: implement runtime initialisation
This commit is contained in:
@@ -26,7 +26,7 @@ bsp_add_library(
|
|||||||
NAME libc
|
NAME libc
|
||||||
LIB_DIR /usr/lib)
|
LIB_DIR /usr/lib)
|
||||||
|
|
||||||
target_link_libraries(libc PRIVATE libmango libxpc-static interface::fs)
|
target_link_libraries(libc PRIVATE libmango librosetta libxpc-static interface::fs)
|
||||||
target_compile_definitions(libc PRIVATE ENABLE_GLOBAL_HEAP=1)
|
target_compile_definitions(libc PRIVATE ENABLE_GLOBAL_HEAP=1)
|
||||||
|
|
||||||
add_subdirectory(pthread)
|
add_subdirectory(pthread)
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ foreach (dir ${source_dirs})
|
|||||||
set(headers ${headers} ${dir_headers})
|
set(headers ${headers} ${dir_headers})
|
||||||
endforeach (dir)
|
endforeach (dir)
|
||||||
|
|
||||||
set(component_sources ${sources} PARENT_SCOPE)
|
file(GLOB sys_sources
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sys/${CMAKE_SYSTEM_PROCESSOR}/*.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/sys/${CMAKE_SYSTEM_PROCESSOR}/*.S)
|
||||||
|
|
||||||
|
set(component_sources ${sources} ${sys_sources} PARENT_SCOPE)
|
||||||
set(component_headers ${headers} PARENT_SCOPE)
|
set(component_headers ${headers} PARENT_SCOPE)
|
||||||
|
|
||||||
rosetta_add_library(STATIC
|
rosetta_add_library(STATIC
|
||||||
NAME libc-core
|
NAME libc-core
|
||||||
PUBLIC_INCLUDE_DIRS ${public_include_dirs}
|
PUBLIC_INCLUDE_DIRS ${public_include_dirs}
|
||||||
SOURCES ${sources}
|
SOURCES ${sources} ${sys_sources}
|
||||||
HEADERS ${headers})
|
HEADERS ${headers})
|
||||||
|
|
||||||
sysroot_add_library(
|
sysroot_add_library(
|
||||||
|
|||||||
18
lib/libc/core/sys/x86_64/init.c
Normal file
18
lib/libc/core/sys/x86_64/init.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include <mango/log.h>
|
||||||
|
#include <rosetta/bootstrap.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern int main(int, const char **, const char **);
|
||||||
|
|
||||||
|
void *__attribute__((weak)) pthread_self(void)
|
||||||
|
{
|
||||||
|
/* Nothing */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int __libc_init(const struct rosetta_bootstrap *bsinfo)
|
||||||
|
{
|
||||||
|
(volatile void)pthread_self();
|
||||||
|
kern_logf("bsinfo = %p", bsinfo);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -3,18 +3,20 @@
|
|||||||
.global _start
|
.global _start
|
||||||
.type _start, @function
|
.type _start, @function
|
||||||
|
|
||||||
.extern main
|
.extern __libc_init
|
||||||
.type main, @function
|
.type __libc_init, @function
|
||||||
|
|
||||||
.extern task_exit
|
.extern task_exit
|
||||||
.type task_exit, @function
|
.type task_exit, @function
|
||||||
|
|
||||||
_start:
|
_start:
|
||||||
# Args (as provided by the ABI)
|
# %rdi: (struct rosetta_bootstrap *)bs_info
|
||||||
# %rdi: int argc
|
mov %rdi, %rbx
|
||||||
# %rsi: const char **argv
|
call __libc_init
|
||||||
# %rdx: kern_handle_t task
|
|
||||||
# %rcx: kern_handle_t address_space
|
mov 0(%rbx), %rdi # argc
|
||||||
|
mov 8(%rbx), %rsi # argv
|
||||||
|
mov 24(%rbx), %rdx # envp
|
||||||
call main
|
call main
|
||||||
|
|
||||||
mov %rax, %rdi
|
mov %rax, %rdi
|
||||||
|
|||||||
Reference in New Issue
Block a user