Rename & scheduler stuff

This commit is contained in:
ssimnb 2026-01-24 08:15:08 +01:00
parent 4e40a040dd
commit 0066af13e8
25 changed files with 63 additions and 88 deletions

View file

@ -1,21 +1,24 @@
#include <kprint.h>
#include <stdint.h>
#include <string.h>
#include <SFB25.h>
#include <neobbo.h>
#include "../hal/smp.h"
#include <error.h>
#include "../mm/kmalloc.h"
#include "sched.h"
extern context *save_context();
extern void get_context(struct context *ctx);
extern void switch_context(context *old, context *new);
extern void restore_stack(uint64_t rsp, uint64_t rbp);
#define QUANTUM_US 10000
int next_pid = 1;
void idle_task(){
kprintf("Hello world from bruhd task!\n");
kprintf("Hello world from idle task!\n");
}
void test_task(){
@ -32,32 +35,22 @@ proc *alloc_process(void){
proc *p = &proc_list[i];
p->state = READY;
kprintf("pstate = 0x{x}\n", READY);
kprintf("actual: 0x{x}\n", p->state);
p->kstack = kmalloc(INITIAL_STACK_SIZE);
kprintf("actua1l: 0x{x}\n", p->state);
p->pid = next_pid++;
kprintf("actua2l: 0x{x}\n", p->state);
memset(&p->context, 0, sizeof(context));
kprintf("actua3l: 0x{x}\n", p->state);
p->context.rbp = (uint64_t)p->kstack;
p->context.rsp = (uint64_t)p->context.rbp + INITIAL_STACK_SIZE;
kprintf("actua4l: 0x{x}\n", p->state);
return p;
}
}
kprintf("Couldn't find free process!");
klog(__func__, "Couldnt find free process!!!!!!\n");
}
kstatus add_task(uint64_t *entry){
proc *add_task(uint64_t *entry){
proc *proc = alloc_process();
if (proc == NULL) {
@ -67,7 +60,7 @@ kstatus add_task(uint64_t *entry){
proc->context.rip = (uint64_t)entry;
return KERNEL_STATUS_SUCCESS;
return proc;
}
void scheduler_init(){
@ -83,27 +76,32 @@ void scheduler_init(){
kkill();
}
kprintf("hi1\n");
proc *proc_list = state->process_list;
memset(proc_list, 0, sizeof(proc) * 512);
int pid = add_task((uint64_t*)idle_task);
proc *idle = add_task((uint64_t*)idle_task);
if(idle == NULL){
klog(__func__, "Failed to allocate idle task");
kkill();
}
state->current_process = idle;
add_task((uint64_t*)test_task);
for(;;){
for(int i = 0; i < PROC_MAX; i++){
if(proc_list[i].state == READY){
kprintf("Hell yeah");
context old_state = state->current_process->context;
state->current_process = &proc_list[i];
state->current_process->state = RUNNING;
get_context(&state->scheduler_context);
switch_context(&old_state, &state->current_process->context);
}
}
}
@ -112,8 +110,6 @@ void scheduler_init(){
void scheduler_tick(){
cpu_state *state = get_cpu_struct();
proc *proc_list = state->process_list;
switch_context(&state->current_process->context, &state->scheduler_context);
}