initial commit

This commit is contained in:
2025-03-11 05:17:34 +08:00
parent d1f60e7c82
commit 9238177ad6
27 changed files with 924 additions and 0 deletions

37
lib/kmalloc.c Normal file
View File

@@ -0,0 +1,37 @@
#include <kmalloc.h>
#include <stddef.h>
extern void *__heap_start;
extern void *__heap_end;
void *_heap_top = (void *)0;
// simple 8-byte aligned linear allocation
void *simple_alloc(size_t size)
{
if (!_heap_top) {
_heap_top = __heap_start;
}
if (size & 0xff)
size = (size & ~0xff) + 0x100;
if ((uint64_t)_heap_top + size >= (uint64_t)__heap_end)
return (void *)0;
void *ret = _heap_top;
_heap_top = (void *)((uint64_t)_heap_top + size);
return ret;
}
void *kmalloc(size_t size)
{
return simple_alloc(size);
}
void kfree(void *ptr)
{
// not implemented for now
return;
}