Add base code for custom stack length
This commit is contained in:
4
Makefile
4
Makefile
@@ -5,7 +5,7 @@ CPU = -mcpu=cortex-m4
|
|||||||
THUMB = -mthumb
|
THUMB = -mthumb
|
||||||
|
|
||||||
LDFLAGS = -T linker.ld
|
LDFLAGS = -T linker.ld
|
||||||
CFLAGS = $(CPU) $(THUMB)
|
CFLAGS = $(CPU) $(THUMB) -I libc/
|
||||||
|
|
||||||
QEMU = qemu-system-arm
|
QEMU = qemu-system-arm
|
||||||
BOARD = netduino2
|
BOARD = netduino2
|
||||||
@@ -13,7 +13,7 @@ BOARD = netduino2
|
|||||||
# Output file
|
# Output file
|
||||||
TARGET = main.elf
|
TARGET = main.elf
|
||||||
# Source files
|
# 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
|
# Object files
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,23 @@
|
|||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "alloc.h"
|
#include "alloc.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void create_process_table(ProcessTable **table) {
|
void create_process_table(ProcessTable **table) {
|
||||||
*table = malloc(sizeof(ProcessTable));
|
*table = malloc(sizeof(ProcessTable));
|
||||||
(*table)->entries = 0;
|
(*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) {
|
int create_process(ProcessTable *table, void *entrypoint) {
|
||||||
if (table->entries>=MAX_PROCESS) return 1;
|
if (table->entries>=MAX_PROCESS) return 1;
|
||||||
|
|
||||||
Process *pentry = &table->process_list[table->entries++];
|
Process *pentry = &table->process_list[table->entries++];
|
||||||
pentry->entrypoint = entrypoint;
|
pentry->entrypoint = entrypoint;
|
||||||
|
pentry->stack = create_stack(STACK_SIZE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
10
os/process.h
10
os/process.h
@@ -1,3 +1,4 @@
|
|||||||
|
#include <stddef.h>
|
||||||
#ifndef PROCESS_H
|
#ifndef PROCESS_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -7,9 +8,14 @@
|
|||||||
#define STACK_SIZE 32
|
#define STACK_SIZE 32
|
||||||
#define STACK_START(stack) (&stack[STACK_SIZE-1])
|
#define STACK_START(stack) (&stack[STACK_SIZE-1])
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t stack_size;
|
||||||
|
uint32_t stack[];
|
||||||
|
} ProcessStack;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int (*entrypoint)();
|
int (*entrypoint)();
|
||||||
uint32_t stack[STACK_SIZE];
|
ProcessStack* stack;
|
||||||
} Process;
|
} Process;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -19,5 +25,7 @@ typedef struct {
|
|||||||
|
|
||||||
void create_process_table(ProcessTable **table);
|
void create_process_table(ProcessTable **table);
|
||||||
|
|
||||||
|
ProcessStack* create_stack(size_t size);
|
||||||
|
|
||||||
int create_process(ProcessTable *table, void *entrypoint);
|
int create_process(ProcessTable *table, void *entrypoint);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user