diff --git a/Makefile b/Makefile index 486c919..dbaa534 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SOURCES = src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c +SOURCES = src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c build: rm -f *.o diff --git a/src/idt/idt.c b/src/idt/idt.c index c5094ce..434fb63 100644 --- a/src/idt/idt.c +++ b/src/idt/idt.c @@ -5,6 +5,7 @@ #include "io/kbd/ps2.h" #include #include +#include "sched/scheduler.h" struct interrupt_descriptor idt[256]; struct idtr idt_reg; @@ -187,6 +188,7 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context) case 32: //DEBUG("Timer Interrupt"); ticks++; + scheduler_schedule(); // Send an EOI so that we can continue having interrupts outb(0x20, 0x20); break; diff --git a/src/kmain.c b/src/kmain.c index a2b0812..a30cbfe 100644 --- a/src/kmain.c +++ b/src/kmain.c @@ -14,6 +14,7 @@ #include "mem/paging/paging.h" #include "mem/paging/vmm.h" #include "mem/heap/kheap.h" +#include "sched/process.h" // Limine version used __attribute__((used, section(".limine_requests"))) @@ -76,6 +77,9 @@ const char* splash = "pepperOS version "PEPPEROS_VERSION_MAJOR"."PEPPEROS_VERSIO struct boot_context boot_ctx; +extern struct process_t* processes_list; +extern struct process_t* current_process; + // This is our entry point void kmain() { @@ -122,7 +126,11 @@ void kmain() { printf("testing, attention please %d\n", i); } - // term_scroll(); + + struct process_t* pedicel = process_create(); + + process_add(&processes_list, pedicel); + process_display_list(processes_list); hcf(); } diff --git a/src/sched/process.c b/src/sched/process.c new file mode 100644 index 0000000..3ce3654 --- /dev/null +++ b/src/sched/process.c @@ -0,0 +1,99 @@ +#include +#include "process.h" +#include "mem/heap/kheap.h" +#include "kernel.h" + +struct process_t* processes_list; +struct process_t* current_process; + +void process_init() +{ + processes_list = NULL; + current_process = NULL; +} + +// Only for debug +void process_display_list(struct process_t* processes_list) +{ + int process_view_id = 0; + struct process_t* tmp = processes_list; + while (tmp != NULL) + { + DEBUG("{%d: } -> ", process_view_id); + tmp = tmp->next; + process_view_id++; + } + DEBUG("NULL"); +} + +struct process_t* process_create() +{ + struct process_t* proc = (struct process_t*)kmalloc(sizeof(struct process_t)); + + if (!proc) return NULL; + + proc->context = NULL; + proc->status = READY; + proc->next = NULL; + + return proc; +} + +void process_add(struct process_t** processes_list, struct process_t* process) +{ + if (!process) return; + process->next = NULL; + + if (*processes_list == NULL) + { + // List is empty + *processes_list = process; + return; + } + + struct process_t* tmp = *processes_list; + while (tmp->next != NULL) + { + tmp = tmp->next; + } + // We're at last process before NULL + tmp->next = process; + // process->next = NULL; +} + +void process_delete(struct process_t** processes_list, struct process_t* process) +{ + if (!processes_list || !*processes_list || !process) return; + + if (*processes_list == process) + { + // process to delete is at head + *processes_list = process->next; + process->next = NULL; + kfree(process); + return; + } + + struct process_t* tmp = *processes_list; + while (tmp->next && tmp->next != process) + { + tmp = tmp->next; + } + + if (tmp->next == NULL) + { + // Didn't find the process + return; + } + + // We're at process before the one we want to delete + tmp->next = process->next; + process->next = NULL; + kfree(process); +} + +struct process_t* process_get_next(struct process_t* process) +{ + if (!process) return NULL; + return process->next; +} \ No newline at end of file diff --git a/src/sched/process.h b/src/sched/process.h new file mode 100644 index 0000000..b23249b --- /dev/null +++ b/src/sched/process.h @@ -0,0 +1,26 @@ +#ifndef PROCESS_H +#define PROCESS_H + +typedef enum +{ + READY, + RUNNING, + DEAD +} status_t; + +struct process_t +{ + status_t status; + struct cpu_status_t* context; + struct process_t* next; +}; + +void process_init(); +struct process_t* process_create(); +void process_add(struct process_t** processes_list, struct process_t* process); +void process_delete(struct process_t** processes_list, struct process_t* process); +struct process_t* process_get_next(struct process_t* process); + +void process_display_list(struct process_t* processes_list); + +#endif \ No newline at end of file diff --git a/src/sched/scheduler.c b/src/sched/scheduler.c new file mode 100644 index 0000000..1ac1ed5 --- /dev/null +++ b/src/sched/scheduler.c @@ -0,0 +1,9 @@ +#include "kernel.h" + +extern struct process_t* processes_list; +extern struct process_t* current_process; + +void scheduler_schedule() +{ + DEBUG("Scheduler called!"); +} \ No newline at end of file diff --git a/src/sched/scheduler.h b/src/sched/scheduler.h new file mode 100644 index 0000000..daf425e --- /dev/null +++ b/src/sched/scheduler.h @@ -0,0 +1,6 @@ +#ifndef SCHEDULER_H +#define SCHEDULER_H + +void scheduler_schedule(); + +#endif \ No newline at end of file diff --git a/test.bin b/test.bin new file mode 100644 index 0000000..60f94fd --- /dev/null +++ b/test.bin @@ -0,0 +1 @@ +ΈοΎ­ήλώ \ No newline at end of file