summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-08-12 17:44:17 -0500
committerNathan Lee <me@nwlee.tech>2026-08-12 17:44:17 -0500
commit2c0efd93530c472e96ff3529aee983b53f3b78d9 (patch)
treecc36e7334e162ba67df79333e267ac93b4d984b9
parent640a81b3ee366c651286efd1b80b37992cd53282 (diff)
rework project structure
-rw-r--r--BuildConfig4
-rw-r--r--console/module_main.c4
-rw-r--r--include/common.h39
-rw-r--r--include/early/bump.h (renamed from include/bump.h)5
-rw-r--r--include/early/dtb.h (renamed from include/dtb.h)2
-rw-r--r--include/mmio.h8
-rw-r--r--include/sys/cpio.h (renamed from include/cpio.h)2
-rw-r--r--include/sys/elf.h (renamed from include/elf.h)2
-rw-r--r--include/sys/log.h (renamed from include/log.h)0
-rw-r--r--include/sys/mem.h (renamed from include/mem.h)8
-rw-r--r--include/sys/stddef.h (renamed from include/types.h)38
-rw-r--r--kernel/common/bump.c (renamed from kernel/bump.c)6
-rw-r--r--kernel/common/cpio.c (renamed from kernel/cpio.c)6
-rw-r--r--kernel/common/dtb.c (renamed from kernel/dtb.c)6
-rw-r--r--kernel/common/elf.c (renamed from kernel/elf.c)3
-rw-r--r--kernel/common/log.c (renamed from kernel/log.c)4
-rw-r--r--kernel/common/mem.c (renamed from kernel/mem.c)6
-rw-r--r--kernel/riscv/kernel.c (renamed from kernel/kernel.c)9
-rw-r--r--kernel/riscv/start.S (renamed from kernel/start.S)0
-rw-r--r--linker.ld1
20 files changed, 70 insertions, 83 deletions
diff --git a/BuildConfig b/BuildConfig
index 6f160fe..000d4ee 100644
--- a/BuildConfig
+++ b/BuildConfig
@@ -1,4 +1,4 @@
-kernel: kernel/*.c kernel/*.S
-kernel_target: kernel
+kernel: kernel/riscv/*.c kernel/riscv/*.S kernel/common/*.c
+kernel_target: kernel/riscv
modules: console
console: console/*.c
diff --git a/console/module_main.c b/console/module_main.c
index 643afc1..a3a71e8 100644
--- a/console/module_main.c
+++ b/console/module_main.c
@@ -1,5 +1,5 @@
-#include <log.h>
-#include <mmio.h>
+#include <sys/log.h>
+#include <sys/mem.h>
#ifndef __KERNEL_MODULE__
#define __KERNEL_MODULE__
diff --git a/include/common.h b/include/common.h
deleted file mode 100644
index d26b8ae..0000000
--- a/include/common.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-#include <types.h>
-
-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;
-}
-
-static inline int memcmp(const void *s1, const void *s2, size_t n) {
- const unsigned char *p1 = (const unsigned char *)s1;
- const unsigned char *p2 = (const unsigned char *)s2;
-
- for (size_t i = 0; i < n; i++) {
- if (p1[i] != p2[i]) {
- return p1[i] - p2[i];
- }
- }
-
- return 0;
-}
-
-static inline void *memcpy(void *restrict dest, const void* restrict src, size_t size) {
- unsigned char *d = (unsigned char *)dest;
- unsigned char *s = (unsigned char *)src;
- for (size_t i = 0; i < size; i++) {
- d[i] = s[i];
- }
- return d;
-}
diff --git a/include/bump.h b/include/early/bump.h
index 81cd571..bf3e6f9 100644
--- a/include/bump.h
+++ b/include/early/bump.h
@@ -1,7 +1,6 @@
#pragma once
-#include <types.h>
-#include <dtb.h>
-#include <mem.h>
+#include <sys/stddef.h>
+#include <early/dtb.h>
#define EHEAP_SIZE (512 * 1024)
diff --git a/include/dtb.h b/include/early/dtb.h
index 1f8f14f..41a7bcc 100644
--- a/include/dtb.h
+++ b/include/early/dtb.h
@@ -1,5 +1,5 @@
#pragma once
-#include <types.h>
+#include <sys/stddef.h>
#define FDT_MAGIC 0xEDFE0DD0
#define FDT_BEGIN_NODE 1
diff --git a/include/mmio.h b/include/mmio.h
deleted file mode 100644
index b6531bf..0000000
--- a/include/mmio.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#pragma once
-#include <types.h>
-
-struct mmio_device_meta {
- const char *name;
- void *start;
- size_t size;
-};
diff --git a/include/cpio.h b/include/sys/cpio.h
index 3bb40c0..c501e96 100644
--- a/include/cpio.h
+++ b/include/sys/cpio.h
@@ -1,5 +1,5 @@
#pragma once
-#include <types.h>
+#include <sys/stddef.h>
#define CPIO_HEADER_LEN 110
struct cpio_newc_hdr {
diff --git a/include/elf.h b/include/sys/elf.h
index 76c384d..95ed592 100644
--- a/include/elf.h
+++ b/include/sys/elf.h
@@ -1,5 +1,5 @@
#pragma once
-#include <types.h>
+#include <sys/stddef.h>
#define ELF_MAGIC_LE 0x464C457F
#define ELF_PAD 0
diff --git a/include/log.h b/include/sys/log.h
index da9274b..da9274b 100644
--- a/include/log.h
+++ b/include/sys/log.h
diff --git a/include/mem.h b/include/sys/mem.h
index bd6c911..769a162 100644
--- a/include/mem.h
+++ b/include/sys/mem.h
@@ -1,5 +1,5 @@
#pragma once
-#include <types.h>
+#include <sys/stddef.h>
struct mem_info {
void* start;
@@ -16,6 +16,12 @@ struct page {
enum PageStatus status;
};
+struct mmio_device_meta {
+ const char *name;
+ void *start;
+ size_t size;
+};
+
void* kmalloc(size_t size);
void* kzalloc(size_t size);
void kfree(void* ptr);
diff --git a/include/types.h b/include/sys/stddef.h
index 5be3023..27aea74 100644
--- a/include/types.h
+++ b/include/sys/stddef.h
@@ -1,5 +1,4 @@
#pragma once
-
#define NULL (void*)0
#define uintptr_t __wk_size_t
@@ -39,3 +38,40 @@ typedef __UINT16_TYPE__ __wk_uint16_t;
typedef __UINT32_TYPE__ __wk_uint32_t;
typedef __UINT64_TYPE__ __wk_uint64_t;
+
+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;
+}
+
+static inline int memcmp(const void *s1, const void *s2, size_t n) {
+ const unsigned char *p1 = (const unsigned char *)s1;
+ const unsigned char *p2 = (const unsigned char *)s2;
+
+ for (size_t i = 0; i < n; i++) {
+ if (p1[i] != p2[i]) {
+ return p1[i] - p2[i];
+ }
+ }
+
+ return 0;
+}
+
+static inline void *memcpy(void *restrict dest, const void* restrict src, size_t size) {
+ unsigned char *d = (unsigned char *)dest;
+ unsigned char *s = (unsigned char *)src;
+ for (size_t i = 0; i < size; i++) {
+ d[i] = s[i];
+ }
+ return d;
+}
diff --git a/kernel/bump.c b/kernel/common/bump.c
index 8b7bd53..1e07837 100644
--- a/kernel/bump.c
+++ b/kernel/common/bump.c
@@ -1,6 +1,6 @@
-#include <bump.h>
-#include <common.h>
-#include <log.h>
+#include <early/bump.h>
+#include <sys/log.h>
+#include <sys/mem.h>
static char eheap[EHEAP_SIZE] = {0};
static size_t eheap_off = 0;
diff --git a/kernel/cpio.c b/kernel/common/cpio.c
index 565b073..c8f7850 100644
--- a/kernel/cpio.c
+++ b/kernel/common/cpio.c
@@ -1,7 +1,5 @@
-#include <cpio.h>
-#include <types.h>
-#include <common.h>
-#include <log.h>
+#include <sys/cpio.h>
+#include <sys/log.h>
static uint32_t parse_hex(const char *p)
{
diff --git a/kernel/dtb.c b/kernel/common/dtb.c
index 7647767..b345db0 100644
--- a/kernel/dtb.c
+++ b/kernel/common/dtb.c
@@ -1,7 +1,5 @@
-
-#include <dtb.h>
-#include <bump.h>
-#include <common.h>
+#include <early/dtb.h>
+#include <early/bump.h>
struct dt_node *dt_parse(void *fdt) {
struct fdt_header *hdr = fdt;
diff --git a/kernel/elf.c b/kernel/common/elf.c
index 69c4128..871eee7 100644
--- a/kernel/elf.c
+++ b/kernel/common/elf.c
@@ -1,5 +1,4 @@
-#include <elf.h>
-#include <common.h>
+#include <sys/elf.h>
int elf_chk_header(struct elf_header *header) {
uint32_t magic_chk;
diff --git a/kernel/log.c b/kernel/common/log.c
index 84b52d3..88136f2 100644
--- a/kernel/log.c
+++ b/kernel/common/log.c
@@ -1,5 +1,5 @@
-#include <log.h>
-#include <types.h>
+#include <sys/log.h>
+
__attribute__((section(".ringbuf"), aligned(64)))
volatile char log_ring[RINGBUF_SIZE];
static int pos = 0;
diff --git a/kernel/mem.c b/kernel/common/mem.c
index 2a6bd35..fee0761 100644
--- a/kernel/mem.c
+++ b/kernel/common/mem.c
@@ -1,7 +1,5 @@
-#include <types.h>
-#include <mem.h>
-#include <dtb.h>
-#include <common.h>
+#include <sys/mem.h>
+#include <early/dtb.h>
static struct page *free_list;
diff --git a/kernel/kernel.c b/kernel/riscv/kernel.c
index de556e7..4e72e2a 100644
--- a/kernel/kernel.c
+++ b/kernel/riscv/kernel.c
@@ -1,8 +1,7 @@
-#include <types.h>
-#include <dtb.h>
-#include <bump.h>
-#include <log.h>
-#include <cpio.h>
+#include <sys/log.h>
+#include <sys/mem.h>
+#include <sys/cpio.h>
+#include <early/bump.h>
#define KERNEL_SIZE 3 * 1024 * 1024
diff --git a/kernel/start.S b/kernel/riscv/start.S
index ecec47b..ecec47b 100644
--- a/kernel/start.S
+++ b/kernel/riscv/start.S
diff --git a/linker.ld b/linker.ld
index 5bf6586..4fec2bf 100644
--- a/linker.ld
+++ b/linker.ld
@@ -71,4 +71,5 @@ SECTIONS
*(.llvm_*)
*(.rela.*)
}
+ _end = .;
}