diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | include/mem.h | 22 | ||||
| -rw-r--r-- | include/types.h | 17 | ||||
| -rw-r--r-- | include/wdt.h | 18 | ||||
| -rw-r--r-- | kernel/kernel.c | 21 | ||||
| -rw-r--r-- | kernel/mem.c | 32 |
7 files changed, 108 insertions, 6 deletions
@@ -1 +1,3 @@ /out +/.cache +compile_commands.json @@ -109,7 +109,7 @@ $(KERNEL_ELF): $(KERNEL_OBJS) linker.ld | $(BIN_DIR) $(KERNEL_BIN): $(KERNEL_ELF) | $(BIN_DIR) @echo " OBJCOPY $@" - $(OBJCOPY) $(OBJCOPY_FLAG) $(KERNEL_ELF) $(KERNEL_BIN) + $(OBJCOPY) $(KERNEL_OBJCOPY_FLAG) $(KERNEL_ELF) $(KERNEL_BIN) $(OBJ_DIR)/%.o: %.c# | $(OBJ_DIR)/% @mkdir -p $(dir $@) diff --git a/include/mem.h b/include/mem.h new file mode 100644 index 0000000..12976df --- /dev/null +++ b/include/mem.h @@ -0,0 +1,22 @@ +#pragma once +#include <types.h> + +#define EHEAP_SIZE (512 * 1024) + +typedef enum { + PAGE_FREE, + PAGE_ALLOCATED +} MemoryPageAvailability; + +struct page { + void* locator; + MemoryPageAvailability availability; + struct page* next; +}; + +void* kmalloc(size_t size); +void* memcpy(void* to, const void* from,size_t size); + +void* kemalloc(size_t size); + +extern struct page root; diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..4c7965c --- /dev/null +++ b/include/types.h @@ -0,0 +1,17 @@ +#pragma once + +#define NULL (void*)0 + +#define size_t __wk_size_t +#define uint8_t __wk_uint8_t +#define uint16_t __wk_uint16_t +#define uint32_t __wk_uint32_t +#define uint64_t __wk_uint64_t +#define be32_to_cpu(x) __builtin_bswap32(x) + +typedef __UINTPTR_TYPE__ __wk_size_t; +typedef __UINT8_TYPE__ __wk_uint8_t; +typedef __UINT16_TYPE__ __wk_uint16_t; +typedef __UINT32_TYPE__ __wk_uint32_t; +typedef __UINT64_TYPE__ __wk_uint64_t; + diff --git a/include/wdt.h b/include/wdt.h new file mode 100644 index 0000000..31739ab --- /dev/null +++ b/include/wdt.h @@ -0,0 +1,18 @@ +#pragma once +#include <types.h> + +#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[]; +}; + diff --git a/kernel/kernel.c b/kernel/kernel.c index 753f4a5..3dbf0d1 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,3 +1,5 @@ +#include <types.h> +#include <wdt.h> #define UART_BASE 0x10000000 // Example UART address static inline void putchar(char c) { @@ -11,10 +13,19 @@ static void print_string(const char *str) { } } -void kernel_main(void) { - print_string("Hello from RISC-V kernel!\n"); - - while (1) { - // Wait +void kernel_main(void *wdt) { + struct wdt_root *root = wdt; + print_string("deserialized all!\n"); + uint32_t count = root->count; + for (uint32_t i = 0; i < count; i++) { + print_string("deserializing wdt node!\n"); + print_string("device type: "); + if (root->devices[i].type == 0) { + print_string("mem"); + } else { + print_string("unknown"); + } + print_string("\n"); } + while(1); } diff --git a/kernel/mem.c b/kernel/mem.c new file mode 100644 index 0000000..531dd81 --- /dev/null +++ b/kernel/mem.c @@ -0,0 +1,32 @@ +#include <types.h> +#include <mem.h> + +static char eheap[EHEAP_SIZE] = {0}; +static size_t eheap_off = 0; + +void* kmalloc(size_t size) { + return (void*)size; +} + +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; +} + +void* memcpy(void *to, const void *from, size_t size) { + char *dest = (char *)to; + const char *src = (const char *)from; + + while (size--) { + *dest++ = *src++; + } + + return dest; +} |
