From e582f2e63b87bf2dfa1b832c3d7342b7b6ef4a66 Mon Sep 17 00:00:00 2001 From: Alan Jian Date: Wed, 24 Jul 2024 16:52:13 +0800 Subject: [PATCH] feat: add linker script --- CMakeLists.txt | 4 ++-- linker.ld | 37 +++++++++++++++++++++++++++++++++++++ src/init.c | 7 +++---- src/main.c | 6 ------ 4 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 linker.ld delete mode 100644 src/main.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 34e4174..deb858e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.29) project(init C) -add_library(init +add_executable(init src/banner.c src/cmd.c src/cmds/banner.c @@ -14,7 +14,6 @@ add_library(init src/cmds/shutdown.c src/cmds/sleep.c src/init.c - src/main.c src/shell.c ) @@ -24,6 +23,7 @@ target_compile_options(init PRIVATE -mcmodel=medany -Wall ) +target_link_options(init PRIVATE -nostdlib -T ${PROJECT_SOURCE_DIR}/linker.ld) target_include_directories(init PRIVATE ${LIBC_INCLUDE} ${LUA_INCLUDE} diff --git a/linker.ld b/linker.ld new file mode 100644 index 0000000..23ea08f --- /dev/null +++ b/linker.ld @@ -0,0 +1,37 @@ +#include + +ENTRY(_start) +SECTIONS { + . = 0x84000000; + + .text : { + *(.text .text.*) + } + + . = ALIGN(4K); + .rodata : { + *(.rodata .rodata.*) + } + + . = ALIGN(4K); + .data : { + *(.data .data.*) + } + + .sdata : { + *(.sdata .sdata.*) + } + + . = ALIGN(8); + PROVIDE(__bss_start = .); + + .sbss : { + *(.sbss .sbss.*) + } + + .bss : { + *(.bss .bss.*) + } + + PROVIDE(_end = .); +} diff --git a/src/init.c b/src/init.c index 0a048c2..3638b57 100644 --- a/src/init.c +++ b/src/init.c @@ -2,18 +2,17 @@ #include #include #include +#include #include #include #include -void start(); - -void init(void) { +int main(void) { printf("Booting up CargOS v%d.%d.%d...\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); const char *argv[] = {"shell", nullptr}; - proc(start, argv); + proc(shell, argv); while (true) { if (wait(nullptr) < 0 && errno == ECHILD) { diff --git a/src/main.c b/src/main.c deleted file mode 100644 index f3f6c17..0000000 --- a/src/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - shell(); - return 0; -}