18 #define ENTRY_BEEN_USED 0x01
19 #define ENTRY_IN_USE 0x02
21 static struct alloc_info {
27 static unsigned long tbl_entries;
28 static unsigned long alloc_min;
29 static unsigned long next_base;
30 static unsigned long space_left;
37 static void *simple_malloc(
unsigned long size)
40 struct alloc_info *
p = alloc_tbl;
47 for (i=0; i<tbl_entries; i++, p++)
49 if (size <= space_left) {
55 return (
void *)p->base;
60 else if (!(p->flags &
ENTRY_IN_USE) && (size <= p->size)) {
62 return (
void *)p->base;
68 static struct alloc_info *simple_find_entry(
void *
ptr)
71 struct alloc_info *p = alloc_tbl;
73 for (i=0; i<tbl_entries; i++,p++) {
77 (p->base == (
unsigned long)ptr))
83 static void simple_free(
void *ptr)
85 struct alloc_info *p = simple_find_entry(ptr);
97 static void *simple_realloc(
void *ptr,
unsigned long size)
108 return simple_malloc(size);
110 p = simple_find_entry(ptr);
116 new = simple_malloc(size);
117 memcpy(
new, ptr, p->size);
127 unsigned long granularity,
unsigned long max_allocs)
129 unsigned long heap_base, tbl_size;
131 heap_size =
_ALIGN_UP(heap_size, granularity);
133 tbl_entries = max_allocs;
135 tbl_size = tbl_entries *
sizeof(
struct alloc_info);
137 alloc_tbl = (
struct alloc_info *)
_ALIGN_UP((
unsigned long)base, 8);
138 memset(alloc_tbl, 0, tbl_size);
140 heap_base =
_ALIGN_UP((
unsigned long)alloc_tbl + tbl_size, alloc_min);
142 next_base = heap_base;
143 space_left = heap_size;
149 return (
void *)(heap_base + heap_size);