diff --git a/kernel.c b/kernel.c index b8cd188..99d2539 100644 --- a/kernel.c +++ b/kernel.c @@ -1,45 +1,21 @@ #include "kernel.h" #include "ecall.h" #include "sched.h" -#include "mutex.h" void thread_1(); extern ProcessControlBlock processes[PROCESS_COUNT]; +loaded_binary binary_table[NUM_BINARIES]; + +static int idx = 0; + extern void init() { - // set up processes - processes[0].pid = 1; - processes[0].pc = (int) thread_1; - processes[0].regs[2] = 128; - processes[0].status = PROC_RDY; - processes[0].requested_lock = 0; - - processes[1].pid = 2; - processes[1].pc = (int) thread_1; - processes[1].regs[2] = 256; - processes[1].status = PROC_RDY; - processes[1].requested_lock = 0; + for (int i = 0; i < 100; i++) { + idx += binary_table[i].entrypoint + 4; + } scheduler_run_next(); } -void thread_1() { - int a = 0; // a4 - int b = 0; // a5 - - while (true) { - a++; - if (a > 1000000) { - __asm__ __volatile__ ( - "ebreak" - ); - b++; - a = 0; - } - if (b > 1000000) { - b = 0; - } - } -} \ No newline at end of file diff --git a/kernel.h b/kernel.h index 0d872de..47b53e4 100644 --- a/kernel.h +++ b/kernel.h @@ -5,19 +5,29 @@ #define false 0 #define XLEN 32 // 32 bit system -#define MUTEX_COUNT 64 // must be multiple of xlen -#define PROCESS_COUNT 64 -#define MAX_INT 0x7FFFFFFF // max 32 bit signed int - -// memory layout: -#define ROM_START 0x00100 -#define IO_START 0x10000 -#define NVM_START 0x20000 -#define RAM_START 0x50000 +#define PROCESS_COUNT 32 // number of concurrent processes +#define NUM_BINARIES 16 // number of binaries loaded simultaneously // scheduler settings #define TIME_SLICE_LEN 100 // number of cpu time ticks per slice + +/* This struct holds information about binaries which are currently loaded into + * memory. Currently the kernel is not able to load binaries into memory, as + * no file system layer is implemented. When the memory image is built, the + * list of loaded binaries is populated aswell. + */ +typedef struct loaded_binary { + int binid; + int entrypoint; + int bounds[2]; +} loaded_binary; + +// create a global table holding all loaded binaries. +// this is either populated at runtime when binaries are loaded dynamically +// or when a memory image is created. +extern loaded_binary binary_table[NUM_BINARIES]; + // init function extern __attribute__((__noreturn__)) void init();