From 52a4afca71aee5c150c6c63e7c1a510501fce6f3 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 19 Nov 2024 14:55:32 +0100 Subject: Setup the stack for an init task MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bootstrap an init task which holds at least the initial stack that is to be used when setting up the registers (such as `sp` and `tp`). In order to guarantee that the stack and the rest of the registers are set up correctly, this commit also provides a raw implementation of a `printk` function. Moreover, this commit also adds an argument that must be passed to `start_kernel`, which is the pointer to the embedded `fdt` blob. This argument will be used by later work so to fetch, at least, the base address for the initial ram disk. This was also used to test that the stack was working as expected. Signed-off-by: Miquel Sabaté Solà --- include/fbos/compiler.h | 23 ++++++++++++++++++++++- include/fbos/dt.h | 8 ++++++++ include/fbos/init.h | 11 +++++++---- include/fbos/mm.h | 13 ++++++++++--- include/fbos/printk.h | 7 +++++++ include/fbos/sbi.h | 35 +++++++++++++++++++++++++++++++++++ include/fbos/sched.h | 8 ++++++++ include/fbos/string.h | 8 ++++++++ 8 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 include/fbos/dt.h create mode 100644 include/fbos/printk.h create mode 100644 include/fbos/sbi.h create mode 100644 include/fbos/sched.h create mode 100644 include/fbos/string.h (limited to 'include') diff --git a/include/fbos/compiler.h b/include/fbos/compiler.h index edf24d1..5e61ebd 100644 --- a/include/fbos/compiler.h +++ b/include/fbos/compiler.h @@ -1,9 +1,30 @@ #ifndef __FBOS_COMPILER_H #define __FBOS_COMPILER_H +/* + * Nicer looking versions of compiler attributes. + */ + #define __noreturn __attribute__((__noreturn__)) +/* + * Compiler attributes specific to linker sections. + */ + #define __section(s) __attribute__((__section__(s))) -#define __kernel __section(".text.kernel") +#define __kernel __section(".kernel.text") + +/* + * Multiple aliases for 64-bit integers which have their definition on the + * standard library. + */ + +typedef long ssize_t; +typedef unsigned long size_t; +typedef unsigned long uint64_t; +typedef unsigned long uintptr_t; + +// Helpful macro when prototyping. +#define __unused(x) (void)x #endif /* __FBOS_COMPILER_H */ diff --git a/include/fbos/dt.h b/include/fbos/dt.h new file mode 100644 index 0000000..39d8381 --- /dev/null +++ b/include/fbos/dt.h @@ -0,0 +1,8 @@ +#ifndef __FBOS_DT_H_ +#define __FBOS_DT_H_ + +#include + +void parse_dtb(uint64_t *dtb); + +#endif // __FBOS_DT_H_ diff --git a/include/fbos/init.h b/include/fbos/init.h index 1eeb33a..a919405 100644 --- a/include/fbos/init.h +++ b/include/fbos/init.h @@ -1,8 +1,11 @@ -#ifndef FBOS_INIT_H -#define FBOS_INIT_H +#ifndef __FBOS_INIT_H +#define __FBOS_INIT_H #include -extern __noreturn __kernel void start_kernel(void); +extern struct task_struct init_task; -#endif /* FBOS_INIT_H */ +// The entry point for the kernel. +__noreturn __kernel void start_kernel(uintptr_t *dtb); + +#endif /* __FBOS_INIT_H */ diff --git a/include/fbos/mm.h b/include/fbos/mm.h index 2b80076..25d18ce 100644 --- a/include/fbos/mm.h +++ b/include/fbos/mm.h @@ -1,11 +1,18 @@ -#ifndef FBOS_MM_H -#define FBOS_MM_H +#ifndef __FBOS_MM_H +#define __FBOS_MM_H /* * Page = 4KB. */ #define PAGE_SIZE 0x1000 +/* + * Initial size of the thread, which coincides with the size of the stack for a + * given thread. + */ +#define THREAD_SIZE_ORDER 2 +#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) + /* * The code will be linked to start at the first page, which will have a given * offset. @@ -13,4 +20,4 @@ #define PAGE_OFFSET 0x80200000 #define LINK_ADDR PAGE_OFFSET -#endif /* FBOS_MM_H */ +#endif /* __FBOS_MM_H */ diff --git a/include/fbos/printk.h b/include/fbos/printk.h new file mode 100644 index 0000000..2c82eda --- /dev/null +++ b/include/fbos/printk.h @@ -0,0 +1,7 @@ +#ifndef __FBOS_PRINTK_H_ +#define __FBOS_PRINTK_H_ + +extern void die(const char *const message); +extern void printk(const char *const message); + +#endif // __FBOS_PRINTK_H_ diff --git a/include/fbos/sbi.h b/include/fbos/sbi.h new file mode 100644 index 0000000..a6b893d --- /dev/null +++ b/include/fbos/sbi.h @@ -0,0 +1,35 @@ +#ifndef __FBOS_SBI_H_ +#define __FBOS_SBI_H_ + +// TODO +/* SBI_SUCCESS 0 Completed successfully */ +/* SBI_ERR_FAILED -1 Failed */ +/* SBI_ERR_NOT_SUPPORTED -2 Not supported */ +/* SBI_ERR_INVALID_PARAM -3 Invalid parameter(s) */ +/* SBI_ERR_DENIED -4 Denied or not allowed */ +/* SBI_ERR_INVALID_ADDRESS -5 Invalid address(s) */ +/* SBI_ERR_ALREADY_AVAILABLE -6 Already available */ +/* SBI_ERR_ALREADY_STARTED -7 Already started */ +/* SBI_ERR_ALREADY_STOPPED -8 Already stopped */ +/* SBI_ERR_NO_SHMEM -9 Shared memory not available */ + +enum sbi_ext { + DBCN_EXT = 0x4442434E, +}; + +enum dbcn_actions { + DBCN_WRITE = 0x00, +}; + +struct sbi_ret { + long error; + long value; +}; + +extern struct sbi_ret __sbi_ecall(unsigned long arg0, unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, unsigned long arg5, + int fid, int ext); + +#define sbi_ecall2(ext, fid, arg0, arg1) __sbi_ecall(arg0, arg1, 0, 0, 0, 0, fid, ext) + +#endif // __FBOS_SBI_H_ diff --git a/include/fbos/sched.h b/include/fbos/sched.h new file mode 100644 index 0000000..626f72f --- /dev/null +++ b/include/fbos/sched.h @@ -0,0 +1,8 @@ +#ifndef __FBOS_SCHED_H_ +#define __FBOS_SCHED_H_ + +struct task_struct { + void *stack; +}; + +#endif // __FBOS_SCHED_H_ diff --git a/include/fbos/string.h b/include/fbos/string.h new file mode 100644 index 0000000..c3da266 --- /dev/null +++ b/include/fbos/string.h @@ -0,0 +1,8 @@ +#ifndef __FBOS_STRING_H_ +#define __FBOS_STRING_H_ + +#include + +extern size_t strlen(const char *); + +#endif // __FBOS_STRING_H_ -- cgit v1.2.3