Work on scheduler

This commit is contained in:
ssimnb 2026-02-26 08:22:29 +01:00
parent e72c8fe6fd
commit 184f1a60de
9 changed files with 67 additions and 41 deletions

View file

@ -19,17 +19,17 @@ extern void s_load_idt();
extern void s_load_gdt();
extern volatile struct limine_mp_request smp_request;
static cpu_state *cpus;
static cpu_state bsp_cpu;
/* Returns the CPU structure for this particular CPU */
cpu_state *get_cpu_struct(){
cpu_state *get_current_cpu_struct(){
return (cpu_state*)rdmsr(GSBASE);
}
uint64_t get_cpu_count(){
if(smp_request.response != NULL){
return smp_request.response->cpu_count;
}
return 0;
cpu_state *get_cpu_struct(int id){
return &cpus[id];
}
bool get_cpu_struct_initialized(){
@ -59,41 +59,45 @@ void ap_init(struct limine_mp_info *smp_info){
asm volatile(
"movq %%cr3, %%rax\n\
movq %%rax, %%cr3\n"
movq %%rax, %%cr3\n"
: : : "rax"
);
cpu_state *cpu_struct = (cpu_state*)kzalloc(sizeof(cpu_state));
cpu_state cpu_struct = cpus[smp_info->lapic_id];
cpu_struct->id = smp_info->lapic_id;
cpu_struct.id = smp_info->lapic_id;
wrmsr(KERNELGSBASE, (uint64_t)cpu_struct);
wrmsr(GSBASE, (uint64_t)cpu_struct);
wrmsr(KERNELGSBASE, (uint64_t)&cpu_struct);
wrmsr(GSBASE, (uint64_t)&cpu_struct);
/* Initialize APIC & APIC timer */
ap_apic_init();
free_spinlock(&ap_init_lock);
for(;;);
while(!bsp_cpu.scheduler_initialized){
__builtin_ia32_pause();
}
scheduler_init();
}
static cpu_state bsp_cpu;
void smp_init(){
struct limine_mp_response *smp_response = smp_request.response;
kprintf("smp: {d} CPUs\n", smp_response->cpu_count);
for(uint64_t i = 0; i < smp_response->cpu_count; i++){
cpus = (cpu_state *)kzalloc(sizeof(cpu_state) * smp_response->cpu_count);
for(uint64_t i = 1; i < smp_response->cpu_count; i++){
/* Pointer to smp_info is passed in RDI by Limine, so no need to pass any arguments here */
smp_response->cpus[i]->goto_address = &ap_init;
}
bsp_cpu.scheduler_context = (struct context*)kmalloc(sizeof(struct context));
bsp_cpu.scheduler_context = (struct context*)kzalloc(sizeof(struct context));
cpus[bsp_cpu.id] = bsp_cpu;
/* If one of the APs has halted, then halt the BSP */
extern bool kernel_killed;