From 95cd78840f0891e60f5ebecc8a8eb4fbaf3c2ebf Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Sun, 12 Jan 2025 01:17:36 -0600 Subject: PROJECT RESTRUCTURING Move the entire kernel into its own directory. Create new directories for system commands, libraries and other required essentials for a complete Unix-like operating system. Signed-off-by: Danny Holman --- arch/i386/kernel/kmalloc.c | 68 ---------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 arch/i386/kernel/kmalloc.c (limited to 'arch/i386/kernel/kmalloc.c') diff --git a/arch/i386/kernel/kmalloc.c b/arch/i386/kernel/kmalloc.c deleted file mode 100644 index ea77428..0000000 --- a/arch/i386/kernel/kmalloc.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -static uintptr_t heap_start = KEND + 0xC0001000; -static uintptr_t heap_end = 0xFFBFF000; - -static void *kbrk = NULL; -static struct mem_block *first = NULL; - -void _request_page(void) { - uintptr_t paddr = pfa_alloc(1); - uintptr_t vaddr = PGROUNDDN((uintptr_t)kbrk + PAGE_SIZE); - kbrk += PAGE_SIZE; - map_page(paddr, vaddr, PD_PRES | PD_RW); -} - -void kmalloc_init(void) { - kbrk = PGROUNDDN(heap_start); - _request_page(); - first = (struct mem_block*)kbrk; - first->start = (uintptr_t)kbrk + sizeof(struct mem_block); - first->size = 0; - first->alloc = 1; - first->next = NULL; -} - -void* kmalloc(size_t sz) { - if (kbrk == NULL) - panic("Attmpted to malloc before initialization"); - if ((uintptr_t)kbrk >= heap_end) - return NULL; - - struct mem_block *temp = first; - while (temp->next != NULL) { - if (temp->next->size <= sz && temp->next->alloc == 0) { - temp->next->alloc = 1; - return (void*)temp->next->start; - } - temp = temp->next; - } - - temp->next = (struct mem_block*)((uintptr_t)temp + sizeof(struct mem_block) + temp->size); - if (temp->next > kbrk) - _request_page(); - temp->next->prev = temp; - temp->next->start = (uintptr_t)(temp->next + sizeof(struct mem_block)); - temp->next->size = sz; - temp->next->alloc = 1; - temp->next->next = NULL; - return (void*)temp->start; -} - -void kfree(void *ptr) { - struct mem_block *temp = first; - while (temp != NULL) { - if (temp->start == (uintptr_t)ptr) { - temp->alloc = 0; - return; - } - temp = temp->next; - } - panic("Attempted to free memory not alloc'd"); -} -- cgit v1.2.3