From 5c15e93fa87800b1f8fae7ef688a9d41221526f1 Mon Sep 17 00:00:00 2001 From: Nathan Lee Date: Fri, 19 Jun 2026 19:05:01 -0500 Subject: 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 --- include/bump.h | 10 ++++++++++ include/common.h | 19 +++++++++++++++++++ include/dtb.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/mem.h | 7 +++++-- include/wdt.h | 18 ------------------ 5 files changed, 80 insertions(+), 20 deletions(-) create mode 100644 include/bump.h create mode 100644 include/common.h create mode 100644 include/dtb.h delete mode 100644 include/wdt.h (limited to 'include') diff --git a/include/bump.h b/include/bump.h new file mode 100644 index 0000000..81cd571 --- /dev/null +++ b/include/bump.h @@ -0,0 +1,10 @@ +#pragma once +#include +#include +#include +#define EHEAP_SIZE (512 * 1024) + + +void* kemalloc(size_t size); +struct mem_info *km_find_memory(struct dt_node *head); + diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..86f1f9c --- /dev/null +++ b/include/common.h @@ -0,0 +1,19 @@ +#pragma once +#include + +static inline size_t strlen(const char *s) { + size_t len = 0; + while (*s++) { + ++len; + } + return len; +} +static inline int strcmp(const char *str1, const char* str2) { + while (*str1 && (*str1 == *str2)) { + ++str1; + ++str2; + } + return *(const unsigned char *)str1 - *(const unsigned char *)str2; +} + + diff --git a/include/dtb.h b/include/dtb.h new file mode 100644 index 0000000..1f8f14f --- /dev/null +++ b/include/dtb.h @@ -0,0 +1,46 @@ +#pragma once +#include + +#define FDT_MAGIC 0xEDFE0DD0 +#define FDT_BEGIN_NODE 1 +#define FDT_END_NODE 2 +#define FDT_PROP 3 +#define FDT_NOP 4 +#define FDT_END 9 + +#define DTB_MAX_NODES 16 + +struct dt_node { + char *name; + struct dt_prop *props; + struct dt_node *children; + struct dt_node *next; +}; + +struct dt_prop { + char *name; + char *value; + size_t len; + struct dt_prop *next; +}; + +struct fdt_header { + uint32_t magic; + uint32_t totalsize; + uint32_t off_dt_struct; + uint32_t off_dt_strings; + uint32_t off_mem_rsvmap; + uint32_t version; + uint32_t last_comp_version; + uint32_t boot_cpuid_phys; + uint32_t size_dt_strings; + uint32_t size_dt_struct; +}; + +struct dt_node *dt_parse(void *fdt); +void *dt_get_prop(struct dt_node *node, char *name, size_t *len); +uint32_t dt_read_u32(struct dt_node *node, char *name, uint32_t *out); + + +struct dt_node *dt_node_alloc(char *name); +struct dt_prop *dt_prop_alloc(char *name, void *value, size_t len); diff --git a/include/mem.h b/include/mem.h index 12976df..6135786 100644 --- a/include/mem.h +++ b/include/mem.h @@ -1,8 +1,6 @@ #pragma once #include -#define EHEAP_SIZE (512 * 1024) - typedef enum { PAGE_FREE, PAGE_ALLOCATED @@ -14,6 +12,11 @@ struct page { struct page* next; }; +struct mem_info { + void* start; + size_t size; +}; + void* kmalloc(size_t size); void* memcpy(void* to, const void* from,size_t size); diff --git a/include/wdt.h b/include/wdt.h deleted file mode 100644 index 31739ab..0000000 --- a/include/wdt.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include - -#define WDT_MAGIC 0x67674141 - -struct wdt_device { - uint32_t type; - uint32_t driver_id; - uint32_t start; - uint32_t size; -}; - -struct wdt_root { - uint32_t magic; - uint32_t count; - struct wdt_device devices[]; -}; - -- cgit v1.2.3