From 4038ec5662a5b1ebe652e9170069e3f2f79c7e71 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Sat, 24 Aug 2024 00:05:47 +0200 Subject: Bootstrap the project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For now the base layout has been defined and we have a binary that is properly reached through openSBI. Signed-off-by: Miquel Sabaté Solà --- kernel/fbos.ld.S | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/head.S | 6 ++++++ kernel/main.c | 12 ++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 kernel/fbos.ld.S create mode 100644 kernel/head.S create mode 100644 kernel/main.c (limited to 'kernel') diff --git a/kernel/fbos.ld.S b/kernel/fbos.ld.S new file mode 100644 index 0000000..f288161 --- /dev/null +++ b/kernel/fbos.ld.S @@ -0,0 +1,52 @@ +#include + +SECTIONS { + // Ensure that the image starts at the very exact address SBI expects it to. + . = LINK_ADDR; + + // You would usually want to separate the head section into its own thing + // instead of clumping it into the main `.text` one. Well, I'm no expert on + // linker configuration, so patches are welcome :) + .text : { + // The very first thing has to be the `_start` function, which is where + // SBI will jump into. Afterwards comes the rest of `.text.head`. + _start = .; + *(.text.head) + + // Aligning it to a full page is maybe a bit too much considering how + // small `.text.head` really is. I just saw this same thing on the Linux + // Kernel and it felt clean. + . = ALIGN(PAGE_SIZE); + + // From now on the rest of the `.text` could just be a continuation, but + // I further split it into `.text.kernel` so the jump from head isn't + // that large. That is, we put first the very core of the kernel, and + // the rest can go wherever. + __kernel_text_start = .; + *(.text.kernel) + __kernel_text_end = .; + + // And the rest. + *(.text) + } + + // In total we would reserve two full blown pages for the kernel code, which + // is definitely too much, but whatever, memory is cheap. + . = ALIGN(PAGE_SIZE); + + .data : { + *(.data) + } + + . = ALIGN(8); + + .rodata : { + *(.rodata) + } + + . = ALIGN(8); + + .bss : { + *(.bss) + } +} diff --git a/kernel/head.S b/kernel/head.S new file mode 100644 index 0000000..ba155cb --- /dev/null +++ b/kernel/head.S @@ -0,0 +1,6 @@ +.global _start +.section .text.head + +_start: + // TODO + call start_kernel diff --git a/kernel/main.c b/kernel/main.c new file mode 100644 index 0000000..325f858 --- /dev/null +++ b/kernel/main.c @@ -0,0 +1,12 @@ +#include + +/* + * This is the main entry point of the kernel after head.S is done. This + * function can (and will) assume that everything has been reset and that we can + * start the whole thing. + */ +__noreturn __kernel void start_kernel(void) +{ + for (;;) + ; +} -- cgit v1.2.3