Scheduler fix, User RR
This commit is contained in:
@@ -9,6 +9,9 @@
|
||||
#include <kernel.h>
|
||||
#include <stddef.h>
|
||||
#include <io/term/term.h>
|
||||
#include <sched/process.h>
|
||||
|
||||
extern struct process* current_process;
|
||||
|
||||
void sys_write(unsigned int fd, const char* buf, size_t count)
|
||||
{
|
||||
@@ -20,10 +23,19 @@ void sys_write(unsigned int fd, const char* buf, size_t count)
|
||||
break;
|
||||
|
||||
case 2: //stderr
|
||||
for (size_t i=0; i<count; i++) {
|
||||
internal_putc(buf[i], NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void sys_exit(int error_code)
|
||||
{
|
||||
current_process->status = DEAD;
|
||||
DEBUG("exiting process PID=%u name=%s", current_process->pid, current_process->name);
|
||||
}
|
||||
|
||||
/*
|
||||
* syscall_handler - System call dispatcher
|
||||
* @regs: CPU state
|
||||
@@ -53,6 +65,9 @@ struct cpu_status* syscall_handler(struct cpu_status* regs)
|
||||
case 1: //sys_write
|
||||
sys_write(regs->rdi, (char*)regs->rsi, regs->rdx);
|
||||
break;
|
||||
case 60: //sys_exit
|
||||
sys_exit(regs->rdi);
|
||||
break;
|
||||
default:
|
||||
regs->rax = 0xbad515ca11;
|
||||
break;
|
||||
|
||||
+5
-2
@@ -121,11 +121,14 @@ void kmain()
|
||||
|
||||
if (!boot_ctx.module) {
|
||||
panic(NULL, "could not load 'hello' executable :(");
|
||||
}
|
||||
if (boot_ctx.module->module_count == 1) {
|
||||
}
|
||||
if (boot_ctx.module->module_count == 2) {
|
||||
file = boot_ctx.module->modules[0];
|
||||
DEBUG("file: addr=%p size=%u", file->address, file->size);
|
||||
process_create_user(file, "hello");
|
||||
|
||||
file = boot_ctx.module->modules[1];
|
||||
process_create_user(file, "pedicel");
|
||||
}
|
||||
scheduler_init();
|
||||
|
||||
|
||||
+34
-18
@@ -50,31 +50,47 @@ struct cpu_status* scheduler_schedule(struct cpu_status* context)
|
||||
panic(NULL, "current_process->context is NULL");
|
||||
}
|
||||
|
||||
if (current_process->next == NULL) {
|
||||
return current_process->context;
|
||||
}
|
||||
|
||||
current_process->context = context;
|
||||
|
||||
for (;;) {
|
||||
struct process* 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);
|
||||
current_process = NULL;
|
||||
if (current_process->status == DEAD) {
|
||||
struct process* dead_process = current_process;
|
||||
struct process* next_process = (dead_process->next != NULL) ? dead_process->next : processes_list;
|
||||
|
||||
process_delete(&processes_list, dead_process);
|
||||
|
||||
if (processes_list == NULL || next_process == dead_process) {
|
||||
current_process = idle_proc;
|
||||
return idle_proc->context;
|
||||
} else {
|
||||
current_process->status = RUNNING;
|
||||
break;
|
||||
}
|
||||
|
||||
current_process = next_process;
|
||||
} else if (current_process->next != NULL) {
|
||||
current_process = current_process->next;
|
||||
} else {
|
||||
current_process = processes_list;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (current_process->status == DEAD) {
|
||||
struct process* dead_process = current_process;
|
||||
struct process* next_process = (current_process->next != NULL) ? current_process->next : processes_list;
|
||||
|
||||
process_delete(&processes_list, dead_process);
|
||||
|
||||
if (processes_list == NULL || next_process == dead_process) {
|
||||
current_process = idle_proc;
|
||||
return idle_proc->context;
|
||||
}
|
||||
|
||||
current_process = next_process;
|
||||
continue;
|
||||
}
|
||||
|
||||
current_process->status = RUNNING;
|
||||
break;
|
||||
}
|
||||
|
||||
// Here, we chose next running process so we load its kernel stack & page tables
|
||||
tss.rsp0 = (uint64_t)current_process->kernel_stack;
|
||||
load_cr3(VIRT_TO_PHYS((uint64_t)current_process->root_page_table));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user