Add missing files

This commit is contained in:
2024-11-03 11:41:22 +01:00
parent 6587c8498f
commit 137ec0fd74
6 changed files with 96 additions and 0 deletions

15
os/process.c Normal file
View File

@@ -0,0 +1,15 @@
#include "process.h"
#include "alloc.h"
void create_process_table(ProcessTable **table) {
*table = malloc(sizeof(ProcessTable));
(*table)->entries = 0;
}
int create_process(ProcessTable *table, void *entrypoint) {
if (table->entries>=MAX_PROCESS) return 1;
Process *pentry = &table->process_list[table->entries++];
pentry->entrypoint = entrypoint;
return 0;
}

23
os/process.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef PROCESS_H
#include <stdint.h>
#define PROCESS_H
#define MAX_PROCESS 16
#define STACK_SIZE 32
#define STACK_START(stack) (&stack[STACK_SIZE-1])
typedef struct {
int (*entrypoint)();
uint32_t stack[STACK_SIZE];
} Process;
typedef struct {
Process process_list[MAX_PROCESS];
int entries;
} ProcessTable;
void create_process_table(ProcessTable **table);
int create_process(ProcessTable *table, void *entrypoint);
#endif

31
os/scheduler.c Normal file
View File

@@ -0,0 +1,31 @@
#include "process.h"
uint32_t **current_sp;
extern void puts(const char *s);
void start_task(Process *pentry) {
__asm volatile(
"mov %0, sp"
: "=r" (*current_sp)
);
__asm volatile(
"mov sp, %0\n"
:: "r" (STACK_START(pentry->stack))
);
pentry->entrypoint();
__asm volatile(
"mov sp, %0\n"
:: "r" (*current_sp)
);
}
void run(ProcessTable *ptable) {
while(1) {
for (int i = 0; i<ptable->entries; i++) {
Process *pentry = &ptable->process_list[i];
start_task(pentry);
}
}
}

1
os/scheduler.h Normal file
View File

@@ -0,0 +1 @@
void run();