Code-base clean-up and refactoring (#47)
[lunaix-os.git] / lunaix-os / arch / generic / bootmem.c
1 #include <sys-generic/bootmem.h>
2 #include <lunaix/sections.h>
3 #include <lunaix/spike.h>
4
5 #define BOOTMEM_SIZE   (4 * 4096)
6
7 static reclaimable char bootmem_pool[BOOTMEM_SIZE];
8 static unsigned int pos;
9
10 _default void*
11 bootmem_alloc(unsigned int size)
12 {
13     ptr_t res;
14
15     res = __ptr(bootmem_pool) + pos;
16     
17     size = ROUNDUP(size, 4);
18     pos += size;
19
20     if (pos >= BOOTMEM_SIZE) {
21         spin();
22         unreachable;
23     }
24
25     return (void*)res;
26 }
27
28 _default void
29 bootmem_free(void* ptr)
30 {
31     // not need to support, as they are all one-shot
32     return;
33 }