summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordzwdz2021-09-05 18:32:08 +0200
committerdzwdz2021-09-05 18:32:08 +0200
commit838b142b7374150df63ec02b02377c114a14b314 (patch)
treeb5b22e5517da7a4ac96a47f0cfe6a4755d00da44 /src
parentd6c1dceba2511fa2edf839942b237d3a27bb9535 (diff)
move most of the memory stuff to kernel/mem/
Diffstat (limited to 'src')
-rw-r--r--src/kernel/arch/i386/pagedir.c2
-rw-r--r--src/kernel/main.c2
-rw-r--r--src/kernel/mem/alloc.c38
-rw-r--r--src/kernel/mem/alloc.h15
-rw-r--r--src/kernel/mem/virt.c (renamed from src/kernel/mem.c)39
-rw-r--r--src/kernel/mem/virt.h (renamed from src/kernel/mem.h)17
-rw-r--r--src/kernel/proc.c2
-rw-r--r--src/kernel/syscalls.c3
-rw-r--r--src/kernel/tests/vfs.c2
-rw-r--r--src/kernel/vfs/mount.c2
-rw-r--r--src/kernel/vfs/root.c2
11 files changed, 64 insertions, 60 deletions
diff --git a/src/kernel/arch/i386/pagedir.c b/src/kernel/arch/i386/pagedir.c
index 8f62a45..2fc96f4 100644
--- a/src/kernel/arch/i386/pagedir.c
+++ b/src/kernel/arch/i386/pagedir.c
@@ -1,5 +1,5 @@
#include <kernel/arch/generic.h>
-#include <kernel/mem.h>
+#include <kernel/mem/alloc.h>
#include <kernel/util.h>
#include <stdint.h>
diff --git a/src/kernel/main.c b/src/kernel/main.c
index cc8e10d..97fd6f1 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -1,6 +1,6 @@
#include <kernel/arch/generic.h>
#include <kernel/main.h>
-#include <kernel/mem.h>
+#include <kernel/mem/alloc.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/tests/tests.h>
diff --git a/src/kernel/mem/alloc.c b/src/kernel/mem/alloc.c
new file mode 100644
index 0000000..42a2f3b
--- /dev/null
+++ b/src/kernel/mem/alloc.c
@@ -0,0 +1,38 @@
+#include <kernel/arch/generic.h>
+#include <kernel/mem/alloc.h>
+#include <kernel/util.h>
+#include <stdint.h>
+
+static void *highest_page;
+
+void mem_init(struct kmain_info *info) {
+ // finds the highest used page, and starts allocating pages above it
+ void *highest = &_bss_end;
+
+ if (highest < info->init.at + info->init.size)
+ highest = info->init.at + info->init.size;
+
+ // align up to PAGE_SIZE
+ highest_page = (void*)(((uintptr_t)highest + PAGE_MASK) & ~PAGE_MASK);
+}
+
+void *page_alloc(size_t pages) {
+ void *bottom = highest_page;
+ highest_page += pages * PAGE_SIZE;
+ return bottom;
+}
+
+// frees `pages` consecutive pages starting from *first
+void page_free(void *first, size_t pages) {
+ // not implemented
+}
+
+
+void *kmalloc(size_t len) {
+ // extremely inefficient, but this is only temporary anyways
+ return page_alloc(len / PAGE_SIZE + 1);
+}
+
+void kfree(void *ptr) {
+ // unimplemented
+}
diff --git a/src/kernel/mem/alloc.h b/src/kernel/mem/alloc.h
new file mode 100644
index 0000000..571b289
--- /dev/null
+++ b/src/kernel/mem/alloc.h
@@ -0,0 +1,15 @@
+#pragma once
+#include <kernel/arch/generic.h>
+#include <kernel/main.h>
+#include <stddef.h>
+
+void mem_init(struct kmain_info *);
+
+// allocates `pages` consecutive pages
+void *page_alloc(size_t pages);
+
+// frees `pages` consecutive pages starting from *first
+void page_free(void *first, size_t pages);
+
+void *kmalloc(size_t len);
+void kfree(void *ptr);
diff --git a/src/kernel/mem.c b/src/kernel/mem/virt.c
index 55b0361..2990668 100644
--- a/src/kernel/mem.c
+++ b/src/kernel/mem/virt.c
@@ -1,44 +1,7 @@
#include <kernel/arch/generic.h>
-#include <kernel/mem.h>
+#include <kernel/mem/virt.h>
#include <kernel/util.h>
-#include <stdint.h>
-static void *highest_page;
-
-void mem_init(struct kmain_info *info) {
- // finds the highest used page, and starts allocating pages above it
- void *highest = &_bss_end;
-
- if (highest < info->init.at + info->init.size)
- highest = info->init.at + info->init.size;
-
- // align up to PAGE_SIZE
- highest_page = (void*)(((uintptr_t)highest + PAGE_MASK) & ~PAGE_MASK);
-}
-
-void *page_alloc(size_t pages) {
- void *bottom = highest_page;
- highest_page += pages * PAGE_SIZE;
- return bottom;
-}
-
-// frees `pages` consecutive pages starting from *first
-void page_free(void *first, size_t pages) {
- // not implemented
-}
-
-
-void *kmalloc(size_t len) {
- // extremely inefficient, but this is only temporary anyways
- return page_alloc(len / PAGE_SIZE + 1);
-}
-
-void kfree(void *ptr) {
- // unimplemented
-}
-
-
-// TODO move to some shared file in kernel/arch/
void virt_iter_new(
struct virt_iter *iter, user_ptr virt, size_t length,
struct pagedir *pages, bool user, bool writeable)
diff --git a/src/kernel/mem.h b/src/kernel/mem/virt.h
index 5184ec5..98a7a16 100644
--- a/src/kernel/mem.h
+++ b/src/kernel/mem/virt.h
@@ -1,22 +1,9 @@
+/* contains utilities for interacting with virtual memory */
#pragma once
-#include <kernel/arch/generic.h>
-#include <kernel/main.h>
#include <kernel/types.h>
+#include <stdbool.h>
#include <stddef.h>
-void mem_init(struct kmain_info *);
-
-// allocates `pages` consecutive pages
-void *page_alloc(size_t pages);
-
-// frees `pages` consecutive pages starting from *first
-void page_free(void *first, size_t pages);
-
-void *kmalloc(size_t len);
-void kfree(void *ptr);
-
-
-// used for iterating through some part of a process' memory
struct virt_iter {
void *frag;
size_t frag_len;
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index e504a5d..445536a 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -1,5 +1,5 @@
#include <kernel/arch/generic.h>
-#include <kernel/mem.h>
+#include <kernel/mem/alloc.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/util.h>
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 0a53a00..416c815 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -1,5 +1,6 @@
#include <kernel/arch/generic.h>
-#include <kernel/mem.h>
+#include <kernel/mem/alloc.h>
+#include <kernel/mem/virt.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/types.h>
diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c
index 0871f92..69e40af 100644
--- a/src/kernel/tests/vfs.c
+++ b/src/kernel/tests/vfs.c
@@ -1,4 +1,4 @@
-#include <kernel/mem.h>
+#include <kernel/mem/alloc.h>
#include <kernel/tests/base.h>
#include <kernel/util.h>
#include <kernel/vfs/mount.h>
diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c
index 07eed0d..37bfe63 100644
--- a/src/kernel/vfs/mount.c
+++ b/src/kernel/vfs/mount.c
@@ -1,4 +1,4 @@
-#include <kernel/mem.h>
+#include <kernel/mem/alloc.h>
#include <kernel/util.h>
#include <kernel/vfs/mount.h>
diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c
index 0f11a5b..5b23555 100644
--- a/src/kernel/vfs/root.c
+++ b/src/kernel/vfs/root.c
@@ -1,4 +1,4 @@
-#include <kernel/mem.h>
+#include <kernel/mem/virt.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
#include <kernel/types.h>