summaryrefslogtreecommitdiff
path: root/kernel/memory
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-28 11:09:43 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-28 11:09:43 -0400
commit103e9e001036dce5cd34209b62a416fd1f34abbf (patch)
tree4363f631c929f23b618c94f4d1a05ce51c4e6de8 /kernel/memory
parentadd stderr (diff)
downloadcomus-103e9e001036dce5cd34209b62a416fd1f34abbf.tar.gz
comus-103e9e001036dce5cd34209b62a416fd1f34abbf.tar.bz2
comus-103e9e001036dce5cd34209b62a416fd1f34abbf.zip
move context save area to pcb not in stack
Diffstat (limited to 'kernel/memory')
-rw-r--r--kernel/memory/memory.c21
-rw-r--r--kernel/memory/physalloc.c1
2 files changed, 20 insertions, 2 deletions
diff --git a/kernel/memory/memory.c b/kernel/memory/memory.c
index bd3e06b..ecfd639 100644
--- a/kernel/memory/memory.c
+++ b/kernel/memory/memory.c
@@ -71,7 +71,12 @@ mem_ctx_t mem_ctx_alloc(void)
mem_ctx_t mem_ctx_clone(const mem_ctx_t old, bool cow)
{
- mem_ctx_t new = user_mem_ctx_next;
+ mem_ctx_t new;
+
+ assert(old != NULL, "memory context is null");
+ assert(old->pml4 != NULL, "pgdir is null");
+
+ new = user_mem_ctx_next;
if (new == NULL)
return NULL;
@@ -93,6 +98,9 @@ mem_ctx_t mem_ctx_clone(const mem_ctx_t old, bool cow)
void mem_ctx_free(mem_ctx_t ctx)
{
+ assert(ctx != NULL, "memory context is null");
+ assert(ctx->pml4 != NULL, "pgdir is null");
+
pgdir_free(ctx->pml4);
virtaddr_cleanup(&ctx->virtctx);
@@ -107,9 +115,20 @@ void mem_ctx_free(mem_ctx_t ctx)
void mem_ctx_switch(mem_ctx_t ctx)
{
+ assert(ctx != NULL, "memory context is null");
+ assert(ctx->pml4 != NULL, "pgdir is null");
+
__asm__ volatile("mov %0, %%cr3" ::"r"(ctx->pml4) : "memory");
}
+volatile void *mem_ctx_pgdir(mem_ctx_t ctx)
+{
+ assert(ctx != NULL, "memory context is null");
+ assert(ctx->pml4 != NULL, "pgdir is null");
+
+ return ctx->pml4;
+}
+
void memory_init(void)
{
struct memory_map mmap;
diff --git a/kernel/memory/physalloc.c b/kernel/memory/physalloc.c
index 55ece02..c5a74b7 100644
--- a/kernel/memory/physalloc.c
+++ b/kernel/memory/physalloc.c
@@ -1,4 +1,3 @@
-#include "lib/kio.h"
#include <lib.h>
#include <comus/memory.h>
#include <comus/asm.h>