diff options
Diffstat (limited to 'kernel/kmalloc.c')
| -rw-r--r-- | kernel/kmalloc.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c index 4939e05..a3b4ab6 100644 --- a/kernel/kmalloc.c +++ b/kernel/kmalloc.c @@ -1,9 +1,51 @@ +#define FOOLOS_MODULE_NAME "kmalloc" #include "kmalloc.h" #include <stddef.h> +#include "lib/logger/log.h" -static uint8_t data[1024*1024*8]; //8MB kernel memory managed by kmalloc +#define MEM_SIZE 1024*1024*8 -uint32_t kmalloc(uint32_t size) +static uint8_t data[MEM_SIZE]; //8MB kernel memory managed by kmalloc +static uint32_t next; +static uint32_t first; +static uint8_t init=0; + +void kmallocinit() +{ + next=&(data[0]); + first=next; + + if(next%4096) //align (TODO: check how to tell gcc to do that) + { + next+=4096; + next/=4096; + next*=4096; + } + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kmalloc_init: 0x%08X",next); + init=1; +} + +// kernel block memory allocation +uint32_t kballoc(uint32_t size) { - return NULL; + size*=4096; + if(!init)kmallocinit(); + uint32_t old=next; + next+=size; + + if(next>=first+MEM_SIZE) + { + panic(FOOLOS_MODULE_NAME,"kballoc ran out of memory! maybe increase MEM_SIZE in kmalloc.c?"); + } + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"(%d) : 0x%08X (~%dKB left)",size,old,(MEM_SIZE-next+first)/1024); + + return old; +} + +//TODO! +uint32_t kbfree(uint32_t pos) +{ + } + |
