You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.4 KiB
C

3 years ago
#include "kernel.h"
#include "ktypes.h"
3 years ago
#include "ecall.h"
#include "sched.h"
#include "io.h"
#include "malloc.h"
3 years ago
void read_binary_table();
3 years ago
extern ProcessControlBlock processes[PROCESS_COUNT];
// this array is populated when the memory image is built, therefore it should
// resign in a section which is not overwritten with zeros on startup
loaded_binary binary_table[NUM_BINARIES] __attribute__ ((section (".data")));
extern void memset(unsigned int, void*, void*);
3 years ago
extern void init()
{
init_ecall_table();
dbgln("Kernel started!", 15);
read_binary_table();
3 years ago
scheduler_run_next();
}
void read_binary_table()
{
char msg[28] = "found bin with id 0 at pos 0";
malloc_info info;
info.allocate_memory_end = (void*) 0xFF0000;
info.allocate_memory_start = (void*) 0;
// calculate the end of loaded binaries
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;
// create a new process for each binary found
// it should have around 4kb stack
create_new_process(binary_table+i, 1<<12);
}
}