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

@ -1,5 +1,5 @@
#include <SFB25.h>
#include <stdio.h>
#include <kprint.h>
#include <string.h>
#include <lock.h>
#include "acpi.h"
@ -34,13 +34,13 @@ extern uint64_t *kernel_page_map;
atomic_flag pci_array_lock = ATOMIC_FLAG_INIT;
void pci_add_device(pci_structure structure){
acquire_lock(&pci_array_lock);
acquire_spinlock(&pci_array_lock);
int i = 0;
/* Find first unused space */
while(pci_array[i].func_addr[0] != 0){
if(i >= PCI_DEVICE_BUS){
klog(LOG_ERROR, __func__, "No more space in the PCI array!");
klog(__func__, "No more space in the PCI array!");
kkill();
}
i++;
@ -56,24 +56,24 @@ void pci_add_device(pci_structure structure){
}
}
free_lock(&pci_array_lock);
free_spinlock(&pci_array_lock);
return;
}
pci_structure *pci_get_device(pci_structure structure){
acquire_lock(&pci_array_lock);
acquire_spinlock(&pci_array_lock);
pci_structure ret = {0};
for(int i = 0; i < PCI_DEVICE_BUS; i++){
if( structure.segment == pci_array[i].segment &&
structure.bus == pci_array[i].bus &&
structure.device == pci_array[i].device){
free_spinlock(&pci_array_lock);
return &pci_array[i];
free_lock(&pci_array_lock);
}
}
free_lock(&pci_array_lock);
free_spinlock(&pci_array_lock);
return NULL;
}
@ -170,7 +170,7 @@ void pci_init(){
mcfg = (mcfg_t*)find_acpi_table("MCFG");
if(!mcfg){
klog(LOG_ERROR, __func__, "Failed to find MCFG table");
klog(__func__, "Failed to find MCFG table");
kprintf("pci: device: PCIe not supported! Halting");
kkill();
}
@ -180,13 +180,13 @@ void pci_init(){
parse_conf_space();
/* Map the config space */
kernel_map_pages((uint64_t*)(config_space_base_addr - hhdmoffset), (PCIE_CONF_SPACE_WIDTH * end_pci_num) / PAGE_SIZE, PTE_BIT_RW | PTE_BIT_NX);
kmap_pages((uint64_t*)(config_space_base_addr - hhdmoffset), (PCIE_CONF_SPACE_WIDTH * end_pci_num) / PAGE_SIZE, PTE_BIT_RW | PTE_BIT_NX);
/* Stores enough for an entire configuration space */
pci_array = kmalloc((256 * 32) * sizeof(pci_structure));
if(!pci_array){
klog(LOG_ERROR, __func__, "Failed to allocate memory for PCI structures!");
klog(__func__, "Failed to allocate memory for PCI structures!");
kkill();
}