diff --git a/sys/CMakeLists.txt b/sys/CMakeLists.txt index e69de29..8c9f81b 100644 --- a/sys/CMakeLists.txt +++ b/sys/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(ld) diff --git a/sys/ld/CMakeLists.txt b/sys/ld/CMakeLists.txt new file mode 100644 index 0000000..a51a7ce --- /dev/null +++ b/sys/ld/CMakeLists.txt @@ -0,0 +1,24 @@ +file(GLOB c_sources *.c *.h) +file(GLOB arch_sources arch/${CMAKE_SYSTEM_PROCESSOR}/*.S) + +set_property(SOURCE ${arch_sources} PROPERTY LANGUAGE C) + +add_executable(ld ${c_sources} ${arch_sources}) +set_target_properties(ld PROPERTIES + POSITION_INDEPENDENT_CODE ON + OUTPUT_NAME "ld64" + SUFFIX ".so") + +target_link_libraries(ld ulibc libmango) + +target_compile_options(ld PRIVATE + -fPIC -fno-stack-protector -nostdlib -ffreestanding) +target_link_options(ld PRIVATE + -fPIC -nostdlib -ffreestanding -Wl,-shared) + +sysroot_add_program( + NAME ld + BIN_DIR /lib) +bsp_add_program( + NAME ld + BIN_DIR /lib) diff --git a/sys/ld/arch/x86_64/layout.ld b/sys/ld/arch/x86_64/layout.ld new file mode 100644 index 0000000..96a7da4 --- /dev/null +++ b/sys/ld/arch/x86_64/layout.ld @@ -0,0 +1,30 @@ +ENTRY(_start) + +SECTIONS { + .text ALIGN(4K) : { + *(.text) + *(.rodata) + } + + .rodata ALIGN(4K) : { + + } + + .data ALIGN(4K) : { + *(.data) + *(.bss) + *(.dynamic) + } + + .dynamic ALIGN(8) : { + *(.dynamic) + } + + .got.plt ALIGN(4K) : { + *(.got.plt) + } + + /DISCARD/ : { + *(.interp) + } +} diff --git a/sys/ld/arch/x86_64/start.S b/sys/ld/arch/x86_64/start.S new file mode 100644 index 0000000..45ef52b --- /dev/null +++ b/sys/ld/arch/x86_64/start.S @@ -0,0 +1,15 @@ +.code64 + +.global _start +.type _start, @function + +.extern main +.type main, @function + +.extern exit +.type exit, @function + +_start: + call main +1: pause + jmp 1b diff --git a/sys/ld/main.c b/sys/ld/main.c new file mode 100644 index 0000000..31fc8e2 --- /dev/null +++ b/sys/ld/main.c @@ -0,0 +1,13 @@ +#include +#include + +int main( + int argc, + const char **argv, + kern_handle_t task, + kern_handle_t address_space, + uintptr_t bsp_base) +{ + kern_log("ld!"); + return 0; +}