Skip to content

Commit

Permalink
feat: add linker script
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjian85 committed Jul 24, 2024
1 parent 35a536c commit e582f2e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,7 +14,6 @@ add_library(init
src/cmds/shutdown.c
src/cmds/sleep.c
src/init.c
src/main.c
src/shell.c
)

Expand All @@ -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}
Expand Down
37 changes: 37 additions & 0 deletions linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <config.h>

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 = .);
}
7 changes: 3 additions & 4 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
#include <errno.h>
#include <proc.h>
#include <reboot.h>
#include <shell.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>

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) {
Expand Down
6 changes: 0 additions & 6 deletions src/main.c

This file was deleted.

0 comments on commit e582f2e

Please sign in to comment.