summaryrefslogtreecommitdiff
path: root/kernel/kmalloc.c
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-17 18:17:21 +0200
committerMiguel <m.i@gmx.at>2018-08-17 18:17:21 +0200
commit340f513e9a41dd5815e79cffe54c3f631407f4e1 (patch)
tree08ee2757e891513467cc6fb06f94efb58adc618e /kernel/kmalloc.c
parent51d4dd040a291b62c648ff6cc0d7e0058cf4056f (diff)
cleaning up in progress
Diffstat (limited to 'kernel/kmalloc.c')
-rw-r--r--kernel/kmalloc.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c
index d235f55..e3b0863 100644
--- a/kernel/kmalloc.c
+++ b/kernel/kmalloc.c
@@ -1,36 +1,43 @@
#define FOOLOS_MODULE_NAME "kmalloc"
#include "kmalloc.h"
-#include <stddef.h>
+
#include "lib/logger/log.h"
-#define MEM_SIZE 1024*1024*8
+// 8MB for in kernel-memory
+#define MEM_SIZE 1024*1024*8
+
+static uint8_t data[MEM_SIZE]; // bytes
-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;
+static uint32_t next;
+static uint32_t first;
+static uint8_t init=0;
-void kmallocinit()
+// will be initialized on first call to kballoc() //
+static void kmallocinit()
{
next=&(data[0]);
first=next;
- if(next%4096) //align (TODO: check how to tell gcc to do that)
+ //TODO: optionally tell gcc to align this itself.
+ if(next%4096)
{
- next+=4096;
- next/=4096;
- next*=4096;
+ next+=4096;
+ next/=4096;
+ next*=4096;
}
+ //
-// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kmalloc_init: 0x%08X",next);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kmalloc_init: 0x%08X",next);
init=1;
}
-// kernel block memory allocation
+// kernel block memory allocation //
uint32_t kballoc(uint32_t size)
{
size*=4096;
+
if(!init)kmallocinit();
+
uint32_t old=next;
next+=size;
@@ -38,14 +45,14 @@ uint32_t kballoc(uint32_t 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);
-
+
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"(%d) : 0x%08X (~%dKB left)",size,old,(MEM_SIZE-next+first)/1024);
return old;
}
-//TODO!
+//TODO: allow freeing memory!!
uint32_t kbfree(uint32_t pos)
{
-
+ panic(FOOLOS_MODULE_NAME,"kbfree NOT IMPLEMENTED YET");
}