Initial commit - slab allocator, kmalloc, other re

factors
This commit is contained in:
ssimnb 2026-01-22 08:05:47 +01:00
parent 1dd7b8b07f
commit 4e40a040dd
39 changed files with 863 additions and 412 deletions

View file

@ -4,7 +4,7 @@
#include "timer.h"
#include "ioapic.h"
#include <lock.h>
#include <stdio.h>
#include <kprint.h>
#include <SFB25.h>
#include <cpuid.h> // GCC specific
@ -55,7 +55,7 @@ void apic_sleep(uint64_t ms){
atomic_flag lapic_timer_flag = ATOMIC_FLAG_INIT;
void lapic_timer_init(int us){
acquire_lock(&lapic_timer_flag);
acquire_spinlock(&lapic_timer_flag);
/* Stop the APIC timer */
lapic_write_reg(LAPIC_TIMER_INITIAL_CNT_REG, 0);
@ -80,7 +80,7 @@ void lapic_timer_init(int us){
/* Set the inital count to the calibration */
lapic_write_reg(LAPIC_TIMER_INITIAL_CNT_REG, calibration);
free_lock(&lapic_timer_flag);
free_spinlock(&lapic_timer_flag);
}

View file

@ -1,5 +1,5 @@
#include "gdt.h"
#include <stdio.h>
#include <kprint.h>
gdt_descriptor gdt[5] = {0};

View file

@ -1,7 +1,7 @@
#include "idt.h"
#include "error.h"
#include "timer.h"
#include <stdio.h>
#include <kprint.h>
#include <lock.h>
#include <SFB25.h>
idt_descriptor idt[256] = {0};
@ -60,10 +60,10 @@ atomic_flag irq_register_lock = ATOMIC_FLAG_INIT;
/* Registers an IRQ with the specified vector. */
kstatus register_irq_vector(uint8_t vector, void *base, uint8_t flags){
acquire_lock(&irq_register_lock);
acquire_spinlock(&irq_register_lock);
if(!irq_list[vector].in_use){
free_lock(&irq_register_lock);
free_spinlock(&irq_register_lock);
return KERNEL_STATUS_ERROR;
}
@ -74,27 +74,27 @@ kstatus register_irq_vector(uint8_t vector, void *base, uint8_t flags){
s_load_idt();
free_lock(&irq_register_lock);
free_spinlock(&irq_register_lock);
return KERNEL_STATUS_SUCCESS;
}
/* Registers an IRQ and returns the vector */
int register_irq(void *base, uint8_t flags){
acquire_lock(&irq_register_lock);
acquire_spinlock(&irq_register_lock);
for(size_t i = 0; i < MAX_IRQ; i++){
if(!irq_list[i].in_use) {
set_idt_descriptor(i, base, flags);
irq_list[i].base = base;
irq_list[i].in_use = true;
free_lock(&irq_register_lock);
free_spinlock(&irq_register_lock);
s_load_idt();
return i;
}
}
free_lock(&irq_register_lock);
free_spinlock(&irq_register_lock);
return -1;
}

View file

@ -1,6 +1,6 @@
#include <stdint.h>
#include <stdio.h>
#include <kprint.h>
#include <SFB25.h>
#include "../sys/acpi.h"
#include "error.h"
@ -53,7 +53,7 @@ void ioapic_init(void){
ioapic_t *ioapic = (ioapic_t*) find_ics(0x1);
if(!ioapic){
klog(LOG_ERROR, __func__, "IOAPIC ICS not found\n");
klog(__func__, "IOAPIC ICS not found\n");
kkill();
}

View file

@ -1,7 +1,7 @@
#include <limine.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <kprint.h>
#include <SFB25.h>
#include "gdt.h"
#include "smp.h"
@ -42,7 +42,7 @@ atomic_flag ap_init_lock = ATOMIC_FLAG_INIT;
void ap_init(struct limine_smp_info *smp_info){
acquire_lock(&ap_init_lock);
acquire_spinlock(&ap_init_lock);
/* Load the GDT */
s_load_gdt();
@ -71,7 +71,7 @@ void ap_init(struct limine_smp_info *smp_info){
/* Initialize APIC & APIC timer */
ap_apic_init();
free_lock(&ap_init_lock);
free_spinlock(&ap_init_lock);
for(;;);
@ -81,7 +81,7 @@ void ap_init(struct limine_smp_info *smp_info){
void smp_init(){
if(!smp_request.response){
klog(LOG_ERROR, __func__, "Failed to get SMP request");
klog(__func__, "Failed to get SMP request");
kkill();
}

View file

@ -3,7 +3,7 @@
#include "../hal/apic.h"
#include "../drivers/pmt.h"
#include "timer.h"
#include <stdio.h>
#include <kprint.h>
#include <SFB25.h>
/* Determines which timer will be used for calibration */
@ -11,7 +11,7 @@ int calibration_timer = -1;
void timer_init(void){
if(pmt_init() == -1){
klog(LOG_INFO, __func__, "PMT Timer not found, falling back");
klog(__func__, "PMT Timer not found, falling back");
/* Fall back to PIT */
}else{
calibration_timer = PMT;

View file

@ -1,5 +1,5 @@
#include <cpuid.h>
#include <stdio.h>
#include <kprint.h>
#include <stdint.h>
#include "error.h"
#include "../drivers/pmt.h"