Major refactor of codebase

This commit is contained in:
ssimnb 2026-02-14 18:11:37 +01:00
parent dbc6dc0d7c
commit f478f8d38b
125 changed files with 195 additions and 29519 deletions

View file

@ -1,16 +1,19 @@
#include <assert.h>
#include <kprint.h>
#include <stdint.h>
#include <neobbo.h>
#include "../hal/smp.h"
#include <arch/amd64/hal/smp.h>
#include <error.h>
#include <string.h>
#include "../mm/kmalloc.h"
#include "../mm/slab.h"
#include "sched.h"
#include <mm/kmalloc.h>
#include <mm/slab.h>
#include <scheduler/sched.h>
extern void switch_context(struct context **old, struct context *new);
struct ma_cache *thread_cache;
struct thread *idle;
#define QUANTUM_US 10000
@ -18,6 +21,7 @@ int next_pid = 1;
void idle_task(){
for(;;){
kprintf("idling!\n");
}
}
@ -32,11 +36,22 @@ void best_task(){
}
void thread_exit(){
struct thread *p = get_cpu_struct()->current_process;
cpu_state *cpu = get_cpu_struct();
struct thread *p = cpu->current_process;
kprintf("hi");
// Remove process from circular linked list
p->prev->next = p->next;
if(p == p->next){
cpu->current_process = idle;
}
if(p == cpu->head){
}
ma_cache_dealloc(p); // KILL the thread
sched();
@ -44,6 +59,7 @@ void thread_exit(){
/* Setup a process structure */
struct thread *alloc_thread(void){
struct cpu_state *cpu = get_cpu_struct();
struct thread *head = get_cpu_struct()->head;
struct thread *base = get_cpu_struct()->base;
@ -51,13 +67,16 @@ struct thread *alloc_thread(void){
memset(t, 0, sizeof(struct thread));
if(base == NULL){
base = t;
head = base;
}else{
head->next = t;
t->next = t;
t->prev = t;
cpu->base = t;
cpu->head = t;
} else {
t->prev = head;
t->next = base; // Circular linked list
head = t;
t->next = base;
head->next = t;
base->prev = t;
cpu->head = t;
}
t->state = READY;
@ -91,7 +110,7 @@ struct thread *add_process(uint64_t *entry){
proc->context->rip = (uint64_t)entry;
kprintf("entry: 0x{xn}", entry);
//kprintf("entry: 0x{xn}", entry);
return proc;
}
@ -114,10 +133,7 @@ struct thread *add_process(uint64_t *entry){
}
void scheduler_init(){
if(!get_cpu_struct_initialized()){
klog(__func__, "CPU struct not initialized!");
kkill();
}
assert(get_cpu_struct_initialized() && "CPU struct not initialized!");
cpu_state *cpu = get_cpu_struct();
@ -126,12 +142,10 @@ void scheduler_init(){
return;
}
struct thread *idle = add_process((uint64_t*)idle_task);
idle = add_process((uint64_t*)idle_task);
assert(idle != NULL && "Failed to allocate idle task!");
if(idle == NULL){
klog(__func__, "Failed to allocate idle task");
kkill();
}
cpu->current_process = idle;