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à --- include/fbos/compiler.h | 12 +++++++++++- include/fbos/dt.h | 9 ++++++++- include/fbos/init.h | 2 +- include/fbos/printk.h | 17 +++++++++++++++++ include/fbos/string.h | 1 + 5 files changed, 38 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/fbos/compiler.h b/include/fbos/compiler.h index 35091c0..b88bb0b 100644 --- a/include/fbos/compiler.h +++ b/include/fbos/compiler.h @@ -11,16 +11,24 @@ * Compiler attributes specific to linker sections. */ +#ifdef __KERNEL__ #define __section(s) __attribute__((__section__(s))) #define __kernel __section(".kernel.text") +#else +#define __kernel +#endif /* __KERNEL__ */ /* - * Multiple aliases for 64-bit integers which have their definition on the + * Multiple aliases for 32/64-bit integers which have their definition on the * standard library. */ +typedef int int32_t; typedef long ssize_t; +typedef long int64_t; + typedef unsigned long size_t; +typedef unsigned int uint32_t; typedef unsigned long uint64_t; typedef unsigned long uintptr_t; @@ -28,8 +36,10 @@ typedef unsigned long uintptr_t; * NULL */ +#ifdef __KERNEL__ #define NULL (void *)0 #define nullptr NULL +#endif /* __KERNEL__ */ // Helpful macro when prototyping. #define __unused(x) (void)x diff --git a/include/fbos/dt.h b/include/fbos/dt.h index 39d8381..fd77c35 100644 --- a/include/fbos/dt.h +++ b/include/fbos/dt.h @@ -3,6 +3,13 @@ #include -void parse_dtb(uint64_t *dtb); +// Pair of addresses where the initrd is located in memory. +struct initrd_addr { + uintptr_t start; + uintptr_t end; +}; + +// Returns the `initrd` addresses as parsed from the given DTB blob. +struct initrd_addr find_dt_initrd_addr(uint32_t *dtb); #endif // __FBOS_DT_H_ diff --git a/include/fbos/init.h b/include/fbos/init.h index a919405..eb72508 100644 --- a/include/fbos/init.h +++ b/include/fbos/init.h @@ -6,6 +6,6 @@ extern struct task_struct init_task; // The entry point for the kernel. -__noreturn __kernel void start_kernel(uintptr_t *dtb); +__noreturn __kernel void start_kernel(void *dtb); #endif /* __FBOS_INIT_H */ diff --git a/include/fbos/printk.h b/include/fbos/printk.h index 2c82eda..6b32555 100644 --- a/include/fbos/printk.h +++ b/include/fbos/printk.h @@ -1,7 +1,24 @@ #ifndef __FBOS_PRINTK_H_ #define __FBOS_PRINTK_H_ +/* + * This file might be pulled from user space tests. Hence, define alternatives + * for this functions from glibc. + */ + +#ifdef __KERNEL__ extern void die(const char *const message); extern void printk(const char *const message); +#else +#include +#include + +#define die(x) \ + do { \ + printf(x); \ + exit(1); \ + } while (0) +#define printk(x) printf(x) +#endif /* __KERNEL */ #endif // __FBOS_PRINTK_H_ diff --git a/include/fbos/string.h b/include/fbos/string.h index c3da266..af7e2ef 100644 --- a/include/fbos/string.h +++ b/include/fbos/string.h @@ -4,5 +4,6 @@ #include extern size_t strlen(const char *); +extern int strcmp(const char *, const char *); #endif // __FBOS_STRING_H_ -- cgit v1.2.3