diff options
| author | Nathan Lee <me@nwlee.tech> | 2026-06-19 19:05:01 -0500 |
|---|---|---|
| committer | Nathan Lee <me@nwlee.tech> | 2026-06-19 19:05:01 -0500 |
| commit | 5c15e93fa87800b1f8fae7ef688a9d41221526f1 (patch) | |
| tree | 2b8ed7b696edc9889b588dd79db14c564ea9a77e /kernel/bump.c | |
| parent | b106df2447d23d6b3fcffa7cc87edde218d054f3 (diff) | |
create dtb allocator
the parent commit (b106df2447d23d6b3fcffa7cc87edde218d054f3) discussed
the possibility of creating dtb device discovery. for that, we have
replaced wdt device discovery with dtb device discovery. in the future,
we will use the pci kernel module to use device discovery via a PCI
controller
Diffstat (limited to 'kernel/bump.c')
| -rw-r--r-- | kernel/bump.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/kernel/bump.c b/kernel/bump.c new file mode 100644 index 0000000..369f92f --- /dev/null +++ b/kernel/bump.c @@ -0,0 +1,49 @@ +#include <bump.h> +#include <common.h> + +static char eheap[EHEAP_SIZE] = {0}; +static size_t eheap_off = 0; + +struct mem_info *km_find_memory(struct dt_node *head) { + struct dt_node *child = head->children; + while (child) { + return km_find_memory(child); + child = child->next; + } + + if (strlen(head->name) != 0) { + struct dt_prop *prop_head = head->props; + while (prop_head) { + if (strcmp(prop_head->name, "device_type") == 0 + && strcmp(prop_head->value, "memory") == 0) { + size_t len = 0; + uint32_t *reg = (uint32_t *)dt_get_prop(head, "reg", &len); + if (reg && len >= 8) { + uint32_t base = be32_to_cpu(reg[0]); + uint32_t size = be32_to_cpu(reg[1]); + struct mem_info *ret = kemalloc(sizeof(struct mem_info)); + ret->start = (void*)base; + ret->size = (size_t)size; + + return ret; + } + } + prop_head = prop_head->next; + } + } + return NULL; +} + + +void* kemalloc(size_t size) { + size = (size + 7) & ~7; + + if (eheap_off + size > EHEAP_SIZE) { + return NULL; + } + + void *ptr = &eheap[eheap_off]; + eheap_off += size; + return ptr; +} + |
