From 065f42adc9af7fc4adc391bb6961460010c30d08 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 3 Dec 2024 07:59:01 +0100 Subject: Remove stack pointer for each process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 6132623dbf30 ("Share the same stack everywhere") the same stack is used everywhere. Hence, it's rather pointless for each task to have a pointer to a stack which is the same and that is never read. Signed-off-by: Miquel Sabaté Solà --- include/fbos/sched.h | 6 ------ kernel/main.c | 23 ++++++++++++----------- test/test_initrd.c | 10 ++++------ 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/include/fbos/sched.h b/include/fbos/sched.h index 67778da..ced620c 100644 --- a/include/fbos/sched.h +++ b/include/fbos/sched.h @@ -17,12 +17,6 @@ enum task_id { // All the information we need to grab for processes. struct task_struct { - // The stack allocated for the process. As you can see when initializing - // each process on `kernel/main.c`, we go over the top for its size. There - // is also the fact that we need to keep this as the first attribue to allow - // for simple `sp` values. - void *stack; - // Name of the task to be printed for debugging purposes. const char name[TASK_NAME_LEN]; diff --git a/kernel/main.c b/kernel/main.c index 5a11816..a2e4d13 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -5,22 +5,23 @@ #include #include -// Stack to be used by our processes. "Blasphemy!" I hear you say. "How dare you -// use the same stack for kernel and user space?" It's not like this is some -// sort of utopian system in which everyone shares everything, but since this -// stupidly simple kernel does not even bother to implement paging nor any other -// memory protection of any kind, it's not like separating stacks for each -// process and kernel space would make much of a difference. Hence, let's keep -// it simple and have the same stack everwhere. +// Stack to be used by our processes, which is initialized in head.S. +// "Blasphemy!" I hear you say. "How dare you use the same stack for kernel and +// user space?" It's not like this is some sort of utopian system in which +// everyone shares everything, but since this stupidly simple kernel does not +// even bother to implement paging nor any other memory protection of any kind, +// it's not like separating stacks for each process and kernel space would make +// much of a difference. Hence, let's keep it simple and have the same stack +// everwhere. uint64_t stack[STACK_SIZE / sizeof(uint64_t)]; // Initialize the list of structs by providing a fixed stack address and empty // values everywhere else. struct task_struct tasks[4] = { - [TASK_INIT] = { .stack = stack, .name = "init", .entry_addr = nullptr, }, - [TASK_FIZZ] = { .stack = stack, .name = "fizz", .entry_addr = nullptr, }, - [TASK_BUZZ] = { .stack = stack, .name = "buzz", .entry_addr = nullptr, }, - [TASK_FIZZBUZZ] = { .stack = stack, .name = "fizzbuzz", .entry_addr = nullptr, }, + [TASK_INIT] = { .name = "init", .entry_addr = nullptr, }, + [TASK_FIZZ] = { .name = "fizz", .entry_addr = nullptr, }, + [TASK_BUZZ] = { .name = "buzz", .entry_addr = nullptr, }, + [TASK_FIZZBUZZ] = { .name = "fizzbuzz", .entry_addr = nullptr, }, }; // Defined in fbos/init.h. diff --git a/test/test_initrd.c b/test/test_initrd.c index fb5197b..75611a7 100644 --- a/test/test_initrd.c +++ b/test/test_initrd.c @@ -6,13 +6,11 @@ #include #include -unsigned long stack[STACK_SIZE / sizeof(unsigned long)]; - struct task_struct tasks[4] = { - [TASK_INIT] = { .stack = stack, .entry_addr = NULL, }, - [TASK_FIZZ] = { .stack = stack, .entry_addr = NULL, }, - [TASK_BUZZ] = { .stack = stack, .entry_addr = NULL, }, - [TASK_FIZZBUZZ] = { .stack = stack, .entry_addr = NULL, }, + [TASK_INIT] = { .entry_addr = NULL, }, + [TASK_FIZZ] = { .entry_addr = NULL, }, + [TASK_BUZZ] = { .entry_addr = NULL, }, + [TASK_FIZZBUZZ] = { .entry_addr = NULL, }, }; int main(void) -- cgit v1.2.3