diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-28 11:09:43 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-28 11:09:43 -0400 |
commit | 103e9e001036dce5cd34209b62a416fd1f34abbf (patch) | |
tree | 4363f631c929f23b618c94f4d1a05ce51c4e6de8 /kernel/memory/memory.c | |
parent | add stderr (diff) | |
download | comus-103e9e001036dce5cd34209b62a416fd1f34abbf.tar.gz comus-103e9e001036dce5cd34209b62a416fd1f34abbf.tar.bz2 comus-103e9e001036dce5cd34209b62a416fd1f34abbf.zip |
move context save area to pcb not in stack
Diffstat (limited to 'kernel/memory/memory.c')
-rw-r--r-- | kernel/memory/memory.c | 21 |
1 files changed, 20 insertions, 1 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; |