Started implementing a boot-time memory manager
This commit is contained in:
48
sandbox/memblock/memblock.h
Normal file
48
sandbox/memblock/memblock.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef MEMBLOCK_H_
|
||||
#define MEMBLOCK_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MEMBLOCK_INIT_MEMORY_REGION_COUNT 128
|
||||
#define MEMBLOCK_INIT_RESERVED_REGION_COUNT 128
|
||||
|
||||
#define __for_each_mem_range(i, type_a, type_b, p_start, p_end) \
|
||||
|
||||
typedef uint64_t memblock_index_t;
|
||||
|
||||
typedef struct memblock_region {
|
||||
/* the address of the first byte that makes up the region */
|
||||
uintptr_t base;
|
||||
/* the address of the last byte that makes up the region */
|
||||
size_t limit;
|
||||
} memblock_region_t;
|
||||
|
||||
typedef struct memblock_type {
|
||||
struct memblock_region *regions;
|
||||
unsigned int count;
|
||||
unsigned int max;
|
||||
const char *name;
|
||||
} memblock_type_t;
|
||||
|
||||
typedef struct memblock {
|
||||
struct memblock_type memory;
|
||||
struct memblock_type reserved;
|
||||
} memblock_t;
|
||||
|
||||
typedef struct memblock_iter {
|
||||
memblock_index_t idx;
|
||||
uintptr_t base;
|
||||
size_t limit;
|
||||
} memblock_iter_t;
|
||||
|
||||
extern memblock_t memblock;
|
||||
|
||||
extern int __next_mem_range(memblock_iter_t *it);
|
||||
|
||||
extern int memblock_add(uintptr_t base, size_t size);
|
||||
extern int memblock_reserve(uintptr_t base, size_t size);
|
||||
|
||||
extern uintptr_t memblock_alloc(size_t size);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user