diff options
| -rw-r--r-- | include/fbos/sched.h | 3 | ||||
| -rw-r--r-- | kernel/head.S | 8 | ||||
| -rw-r--r-- | kernel/main.c | 18 | ||||
| -rw-r--r-- | test/test_initrd.c | 10 |
4 files changed, 25 insertions, 14 deletions
diff --git a/include/fbos/sched.h b/include/fbos/sched.h index e8edafd..67778da 100644 --- a/include/fbos/sched.h +++ b/include/fbos/sched.h @@ -30,6 +30,9 @@ struct task_struct { const void *entry_addr; }; +// Instantiated in kernel/main.c. +extern uint64_t stack[]; + // Tasks available on this kernel. extern struct task_struct tasks[4]; diff --git a/kernel/head.S b/kernel/head.S index 9a12833..4390cc9 100644 --- a/kernel/head.S +++ b/kernel/head.S @@ -94,11 +94,13 @@ _start_kernel: li t6, 0 csrw sscratch, 0 - // Point tp and sp to the init task. The 'tp' register will always point to - // the current process being executed, and it will be shown on debug when + // Point 'tp' to the init task. The 'tp' register will always point to the + // current process being executed, and it will be shown on debug when // printing out messages. la tp, tasks - la sp, tasks + THREAD_SIZE + + // Point 'sp' the our general stack. + la sp, stack + THREAD_SIZE // The `start_kernel` function requires an argument to be passed, which is // the pointer to the `fdt` blob. The bootloader puts this on the `a1` diff --git a/kernel/main.c b/kernel/main.c index 9c524c4..19220f6 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -4,16 +4,22 @@ #include <fbos/sched.h> #include <fbos/dt.h> -// Stacks to be used by our processes. -unsigned long stack[4][THREAD_SIZE / sizeof(unsigned long)]; +// 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. +uint64_t stack[THREAD_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[0], .name = "init", .entry_addr = nullptr, }, - [TASK_FIZZ] = { .stack = stack[1], .name = "fizz", .entry_addr = nullptr, }, - [TASK_BUZZ] = { .stack = stack[2], .name = "buzz", .entry_addr = nullptr, }, - [TASK_FIZZBUZZ] = { .stack = stack[3], .name = "fizzbuzz", .entry_addr = nullptr, }, + [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, }, }; // Defined in fbos/init.h. diff --git a/test/test_initrd.c b/test/test_initrd.c index 314bd25..3d07b67 100644 --- a/test/test_initrd.c +++ b/test/test_initrd.c @@ -6,13 +6,13 @@ #include <fbos/sched.h> #include <fbos/mm.h> -unsigned long stack[4][THREAD_SIZE / sizeof(unsigned long)]; +unsigned long stack[THREAD_SIZE / sizeof(unsigned long)]; struct task_struct tasks[4] = { - [TASK_INIT] = { .stack = stack[0], .entry_addr = NULL, }, - [TASK_FIZZ] = { .stack = stack[1], .entry_addr = NULL, }, - [TASK_BUZZ] = { .stack = stack[2], .entry_addr = NULL, }, - [TASK_FIZZBUZZ] = { .stack = stack[3], .entry_addr = NULL, }, + [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, }, }; int main(void) |
