From c265a35cc63127141894d147db811153ce00851b Mon Sep 17 00:00:00 2001 From: Matte23 Date: Sun, 3 Nov 2024 11:51:19 +0100 Subject: [PATCH] Add base code for custom stack length --- Makefile | 4 ++-- os/process.c | 8 ++++++++ os/process.h | 10 +++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 36b9686..c5e0352 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CPU = -mcpu=cortex-m4 THUMB = -mthumb LDFLAGS = -T linker.ld -CFLAGS = $(CPU) $(THUMB) +CFLAGS = $(CPU) $(THUMB) -I libc/ QEMU = qemu-system-arm BOARD = netduino2 @@ -13,7 +13,7 @@ BOARD = netduino2 # Output file TARGET = main.elf # Source files -SRCS = os/main.c os/process.c os/scheduler.c os/alloc.c tasks/library.c tasks/tasks.c +SRCS = os/main.c os/process.c os/scheduler.c os/alloc.c libc/library.c tasks/tasks.c # Object files OBJS = $(SRCS:.c=.o) diff --git a/os/process.c b/os/process.c index 3a429e9..7f32b32 100644 --- a/os/process.c +++ b/os/process.c @@ -1,15 +1,23 @@ #include "process.h" #include "alloc.h" +#include void create_process_table(ProcessTable **table) { *table = malloc(sizeof(ProcessTable)); (*table)->entries = 0; } +ProcessStack* create_stack(size_t size) { + ProcessStack* stack = malloc(sizeof(ProcessStack) + size*sizeof(uint32_t)); + stack->stack_size = size; + return stack; +} + int create_process(ProcessTable *table, void *entrypoint) { if (table->entries>=MAX_PROCESS) return 1; Process *pentry = &table->process_list[table->entries++]; pentry->entrypoint = entrypoint; + pentry->stack = create_stack(STACK_SIZE); return 0; } diff --git a/os/process.h b/os/process.h index 33bb187..6eb1f5e 100644 --- a/os/process.h +++ b/os/process.h @@ -1,3 +1,4 @@ +#include #ifndef PROCESS_H #include @@ -7,9 +8,14 @@ #define STACK_SIZE 32 #define STACK_START(stack) (&stack[STACK_SIZE-1]) +typedef struct { + uint32_t stack_size; + uint32_t stack[]; +} ProcessStack; + typedef struct { int (*entrypoint)(); - uint32_t stack[STACK_SIZE]; + ProcessStack* stack; } Process; typedef struct { @@ -19,5 +25,7 @@ typedef struct { void create_process_table(ProcessTable **table); +ProcessStack* create_stack(size_t size); + int create_process(ProcessTable *table, void *entrypoint); #endif