From fb9627cc985912a57de8b4bedc98991e290e4075 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 20 Nov 2024 11:43:08 +0100 Subject: Fetch the initrd address from the DTB blob MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The kernel entry has a pointer to the DTB blob as a parameter. From this pointer we can parse the the DTB blob to find the properties "chosen->linux,initrd-start" and "chosen->linux,initrd-start". These properties are guaranteed to have 64-bit addresses which point where the initrd is in memory, which we need to fetch the binaries to be loaded. Signed-off-by: Miquel Sabaté Solà --- kernel/dt.c | 6 ------ kernel/main.c | 5 +++-- kernel/string.S | 46 ++++++++++++++++++++++++++++++++++++++++++++++ kernel/strlen.S | 22 ---------------------- 4 files changed, 49 insertions(+), 30 deletions(-) delete mode 100644 kernel/dt.c create mode 100644 kernel/string.S delete mode 100644 kernel/strlen.S (limited to 'kernel') diff --git a/kernel/dt.c b/kernel/dt.c deleted file mode 100644 index 55fa970..0000000 --- a/kernel/dt.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -__kernel void parse_dtb(uint64_t *dtb) -{ - __unused(dtb); -} diff --git a/kernel/main.c b/kernel/main.c index 07188b9..11f2721 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -13,13 +13,14 @@ struct task_struct init_task = { .stack = init_stack }; * function can (and will) assume that everything has been reset and that we can * start the whole thing. */ -__noreturn __kernel void start_kernel(uintptr_t *dtb) +__noreturn __kernel void start_kernel(void *dtb) { // TODO: disable irqs, etc. printk("Welcome to FizzBuzz OS!\n"); - parse_dtb(dtb); + struct initrd_addr addr = find_dt_initrd_addr(dtb); + __unused(addr); // TODO // TODO: reenable stuff diff --git a/kernel/string.S b/kernel/string.S new file mode 100644 index 0000000..d09bbac --- /dev/null +++ b/kernel/string.S @@ -0,0 +1,46 @@ +/* + * Defined in include/fbos/string.h + * + * size_t strlen(const char *str) + * + * Returns (a0): string length. + * Parameter (a0): string to measure. + * Clobbers: t0, t1. + */ +.globl strlen +.type strlen, @function +strlen: + mv t1, a0 +1: + lbu t0, 0(t1) + beqz t0, 2f + addi t1, t1, 1 + j 1b +2: + sub a0, t1, a0 + ret + +/* + * Defined in include/fbos/string.h + * + * int strcmp(const char *s1, const char *s2) + * + * Returns (a0): comparison result as in stdlib. + * Parameter (a0, a1): strings to compare. + * Clobbers: t0, t1. + */ +.globl strcmp +.type strcmp, @function +strcmp: +1: + lbu t0, 0(a0) + lbu t1, 0(a1) + bne t0, t1, 2f + addi a0, a0, 1 + addi a1, a1, 1 + bnez t0, 1b + li a0, 0 + ret +2: + sub a0, t0, t1 + ret diff --git a/kernel/strlen.S b/kernel/strlen.S deleted file mode 100644 index 6185b94..0000000 --- a/kernel/strlen.S +++ /dev/null @@ -1,22 +0,0 @@ -.globl strlen -.type strlen, @function - -/* - * Defined in include/fbos/string.h - * - * size_t strlen(const char *str) - * - * Returns (a0): string length. - * Parameter (a0): string to measure. - * Clobbers: t0, t1. - */ -strlen: - mv t1, a0 -1: - lbu t0, 0(t1) - beqz t0, 2f - addi t1, t1, 1 - j 1b -2: - sub a0, t1, a0 - ret -- cgit v1.2.3