|
|
|
@ -21,7 +21,7 @@ unsigned long long int next_interrupt_scheduled_for;
|
|
|
|
|
int next_process_id = 1;
|
|
|
|
|
|
|
|
|
|
// run the next process
|
|
|
|
|
void scheduler_run_next ()
|
|
|
|
|
void scheduler_run_next()
|
|
|
|
|
{
|
|
|
|
|
current_process = scheduler_select_free();
|
|
|
|
|
// set up timer interrupt
|
|
|
|
@ -110,7 +110,7 @@ void scheduler_switch_to(ProcessControlBlock* pcb)
|
|
|
|
|
CSR_WRITE(CSR_MEPC, pcb->pc);
|
|
|
|
|
|
|
|
|
|
// set up registers
|
|
|
|
|
__asm__(
|
|
|
|
|
__asm__ (
|
|
|
|
|
"mv x31, %0\n"
|
|
|
|
|
"csrrw zero, %1, x31\n"
|
|
|
|
|
"lw x1, 0(x31)\n"
|
|
|
|
@ -180,7 +180,8 @@ void mark_ecall_entry()
|
|
|
|
|
scheduling_interrupted_start = read_time();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
optional_pcbptr find_available_pcb_slot() {
|
|
|
|
|
optional_pcbptr find_available_pcb_slot()
|
|
|
|
|
{
|
|
|
|
|
static int index = 0;
|
|
|
|
|
int start_index = index;
|
|
|
|
|
ProcessControlBlock* pcb = processes + index;
|
|
|
|
@ -200,6 +201,7 @@ optional_pcbptr create_new_process(loaded_binary* bin, int stack_size)
|
|
|
|
|
{
|
|
|
|
|
// try to get a position in the processes list
|
|
|
|
|
optional_pcbptr slot_or_err = find_available_pcb_slot();
|
|
|
|
|
|
|
|
|
|
// if that failed, we cannot creat a new process
|
|
|
|
|
if (has_error(slot_or_err)) {
|
|
|
|
|
dbgln("No more process structs!", 24);
|
|
|
|
@ -208,6 +210,7 @@ optional_pcbptr create_new_process(loaded_binary* bin, int stack_size)
|
|
|
|
|
|
|
|
|
|
// allocate stack for the new process
|
|
|
|
|
optional_voidptr stack_top_or_err = malloc_stack(stack_size); // allocate 4Kib stack
|
|
|
|
|
|
|
|
|
|
// if that failed, we also can't create a new process
|
|
|
|
|
if (has_error(stack_top_or_err)) {
|
|
|
|
|
dbgln("Error while allocating stack for process", 40);
|
|
|
|
@ -242,6 +245,7 @@ optional_pcbptr create_new_thread(ProcessControlBlock* parent, void* entrypoint,
|
|
|
|
|
{
|
|
|
|
|
// try to get a position in the processes list
|
|
|
|
|
optional_pcbptr slot_or_err = find_available_pcb_slot();
|
|
|
|
|
|
|
|
|
|
// if that failed, we cannot creat a new process
|
|
|
|
|
if (has_error(slot_or_err)) {
|
|
|
|
|
dbgln("No more process structs!", 24);
|
|
|
|
@ -250,6 +254,7 @@ optional_pcbptr create_new_thread(ProcessControlBlock* parent, void* entrypoint,
|
|
|
|
|
|
|
|
|
|
// allocate stack for the new process
|
|
|
|
|
optional_voidptr stack_top_or_err = malloc_stack(stack_size); // allocate 4Kib stack
|
|
|
|
|
|
|
|
|
|
// if that failed, we also can't create a new process
|
|
|
|
|
if (has_error(stack_top_or_err)) {
|
|
|
|
|
dbgln("Error while allocating stack for thread", 39);
|
|
|
|
|