Files
pepperOS/src/sched/scheduler.c

55 lines
1.5 KiB
C

/*
* @author xamidev <xamidev@riseup.net>
* @brief Round-robin scheduler
* @license GPL-3.0-only
*/
#include "kernel.h"
#include "process.h"
#include "mem/paging/paging.h"
#include <stdint.h>
#include "io/serial/serial.h"
extern struct process_t* processes_list;
extern struct process_t* current_process;
void scheduler_init()
{
// Choose first process?
current_process = processes_list;
}
struct cpu_status_t* scheduler_schedule(struct cpu_status_t* context)
{
current_process->context = context;
current_process->status = READY;
for (;;) {
struct process_t* prev_process = current_process;
if (current_process->next != NULL)
{
current_process = current_process->next;
} else
{
current_process = processes_list;
}
if (current_process != NULL && current_process->status == DEAD)
{
process_delete(&prev_process, current_process);
} else
{
current_process->status = RUNNING;
break;
}
}
// Current_process gets wrong context?? (iret_rip points to other stuff than process function; like putpixel() for example)
DEBUG("current_process={pid=%u, name='%s', root_page_table[virt]=%p}", current_process->pid, current_process->name, current_process->root_page_table);
load_cr3(VIRT_TO_PHYS((uint64_t)current_process->root_page_table));
DEBUG("loaded process pml4 into cr3");
return current_process->context;
}