blob: d235f55504b53dfb4ac9cfd1d35b4805567c2c42 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#define FOOLOS_MODULE_NAME "kmalloc"
#include "kmalloc.h"
#include <stddef.h>
#include "lib/logger/log.h"
#define MEM_SIZE 1024*1024*8
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)
{
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)
{
}
|