starting all available binaries as processes on kernel startup
This commit is contained in:
parent
a0c3a57921
commit
16d0c05272
35
kernel.c
35
kernel.c
@ -2,6 +2,7 @@
|
||||
#include "ecall.h"
|
||||
#include "sched.h"
|
||||
#include "io.h"
|
||||
#include "malloc.h"
|
||||
|
||||
void create_processes_from_bin_table();
|
||||
|
||||
@ -24,6 +25,40 @@ extern void init()
|
||||
|
||||
void create_processes_from_bin_table()
|
||||
{
|
||||
char msg[28] = "found bin with id 0 at pos 0";
|
||||
ProcessControlBlock* next_process = processes;
|
||||
|
||||
malloc_info info;
|
||||
info.allocate_memory_end = (void*) 0xFF0000;
|
||||
info.allocate_memory_start = (void*) 0;
|
||||
|
||||
for (int i = 0; i < NUM_BINARIES; i++) {
|
||||
if (binary_table[i].binid == 0)
|
||||
break;
|
||||
// print message
|
||||
msg[18] = (char) binary_table[i].binid + '0';
|
||||
msg[27] = (char) i + '0';
|
||||
dbgln(msg, 28);
|
||||
info.allocate_memory_start = binary_table[i].bounds[1];
|
||||
}
|
||||
|
||||
// initialize malloc
|
||||
malloc_init(&info);
|
||||
|
||||
for (int i = 0; i < NUM_BINARIES; i++) {
|
||||
if (binary_table[i].binid == 0)
|
||||
break;
|
||||
|
||||
next_process->status = PROC_RDY;
|
||||
next_process->pid = binary_table[i].binid;
|
||||
next_process->pc = binary_table[i].entrypoint;
|
||||
void* stack_top = malloc_stack(1<<12); // allocate 4Kib stack
|
||||
int stack_e = ((int) stack_top) - 32;
|
||||
next_process->regs[1] = stack_e; // set stack top, put 32 bytes of zeros there
|
||||
next_process++;
|
||||
dbgln("enabled process from table", 26);
|
||||
|
||||
memset(0, (void*) stack_e, stack_top); // write zeros to stack
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user