diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-11-24 23:27:13 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-11-24 23:27:13 +0100 |
| commit | f4986dab75fa612f4f3d525187cd04c029d9bc6b (patch) | |
| tree | c70dd8bd8bd420578bf0a2af01e23ecec89bea0c | |
| parent | 1e81d5c0e4503c86f60ee21da76694ac0693a2e3 (diff) | |
| download | fbos-f4986dab75fa.tar.gz fbos-f4986dab75fa.zip | |
Accept tasks as a parameter on initrd extraction
This allows this functionality to be properly extracted for unit tests.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
| -rw-r--r-- | include/fbos/init.h | 4 | ||||
| -rw-r--r-- | kernel/initrd.c | 13 | ||||
| -rw-r--r-- | kernel/main.c | 15 | ||||
| -rw-r--r-- | test/test_initrd.c | 2 |
4 files changed, 21 insertions, 13 deletions
diff --git a/include/fbos/init.h b/include/fbos/init.h index 711d2cf..f0f1dce 100644 --- a/include/fbos/init.h +++ b/include/fbos/init.h @@ -2,6 +2,7 @@ #define __FBOS_INIT_H #include <fbos/compiler.h> +#include <fbos/sched.h> // Tracks the amount of seconds that have elapsed since activating timer // interrupts. @@ -11,7 +12,8 @@ extern uint64_t seconds_elapsed; // Extract the executables from the initrd that is located at `base_addr` and // has the given `size`. -void extract_initrd(const unsigned char *const base_addr, uint64_t size); +void extract_initrd(const unsigned char *const base_addr, uint64_t size, + struct task_struct tasks[4]); // Setup the interrupt vectors and the SBI timer. void setup_interrupts(void); diff --git a/kernel/initrd.c b/kernel/initrd.c index 3fc2a52..d503dd8 100644 --- a/kernel/initrd.c +++ b/kernel/initrd.c @@ -69,7 +69,7 @@ __kernel int get_task_id_from_path(const char *const path) // Fetch the 'entry_addr' for the ELF binary pointed by 'addr'. If everything // goes right, the task identified by 'task_id' will finally be initialized with // said address. -__kernel void get_task_entry_addr(int task_id, const unsigned char *const addr) +__kernel const void *get_task_entry_addr(const unsigned char *const addr) { uint64_t offset; @@ -84,10 +84,11 @@ __kernel void get_task_entry_addr(int task_id, const unsigned char *const addr) } offset = (uint64_t)addr[0x18]; - tasks[task_id].entry_addr = (const void *)(addr + offset); + return (const void *)(addr + offset); } -__kernel void extract_initrd(const unsigned char *const initrd_addr, uint64_t size) +__kernel void extract_initrd(const unsigned char *const initrd_addr, uint64_t size, + struct task_struct g_tasks[4]) { char buffer[BUFFER_SIZE]; uint64_t name_size, file_size, padding, base = 0; @@ -140,8 +141,10 @@ __kernel void extract_initrd(const unsigned char *const initrd_addr, uint64_t si // there might be some padding in between the header and the file. padding = 4 - ((CPIO_HEADER_SIZE + name_size) & 3); - // And extract everything from the ELF file for the given task. - get_task_entry_addr(task_id, &initrd_addr[base + name_size + CPIO_HEADER_SIZE + padding]); + // And extract the entry address for the current task from the ELF + // binary. + g_tasks[task_id].entry_addr = + get_task_entry_addr(&initrd_addr[base + name_size + CPIO_HEADER_SIZE + padding]); // Advance the base to the next file. base += CPIO_HEADER_SIZE + name_size + padding + file_size; diff --git a/kernel/main.c b/kernel/main.c index 58d67f5..fdcef1f 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -4,13 +4,16 @@ #include <fbos/sched.h> #include <fbos/dt.h> -unsigned long init_stack[4][THREAD_SIZE / sizeof(unsigned long)]; +// Stacks to be used by our processes. +unsigned long stack[4][THREAD_SIZE / sizeof(unsigned long)]; +// Initialize the list of structs by providing a fixed stack address and empty +// values everywhere else. struct task_struct tasks[4] = { - [TASK_INIT] = { .stack = init_stack[0], .entry_addr = nullptr, }, - [TASK_FIZZ] = { .stack = init_stack[1], .entry_addr = nullptr, }, - [TASK_BUZZ] = { .stack = init_stack[2], .entry_addr = nullptr, }, - [TASK_FIZZBUZZ] = { .stack = init_stack[3], .entry_addr = nullptr, }, + [TASK_INIT] = { .stack = stack[0], .entry_addr = nullptr, }, + [TASK_FIZZ] = { .stack = stack[1], .entry_addr = nullptr, }, + [TASK_BUZZ] = { .stack = stack[2], .entry_addr = nullptr, }, + [TASK_FIZZBUZZ] = { .stack = stack[3], .entry_addr = nullptr, }, }; /* @@ -24,7 +27,7 @@ __noreturn __kernel void start_kernel(void *dtb) // Extract information from the DTB blob. struct initrd_addr addr = find_dt_initrd_addr(dtb); - extract_initrd((unsigned char *)addr.start, addr.end - addr.start); + extract_initrd((unsigned char *)addr.start, addr.end - addr.start, tasks); // At this point everything has already been handled: setup the interrupt // vector and enable the timer to start ticking and scheduling the three diff --git a/test/test_initrd.c b/test/test_initrd.c index 73429b8..2d0d045 100644 --- a/test/test_initrd.c +++ b/test/test_initrd.c @@ -30,7 +30,7 @@ int main(void) contents[fsize] = 0; - extract_initrd(contents, (uint64_t)fsize); + extract_initrd(contents, (uint64_t)fsize, tasks); free(contents); // TODO |
