summaryrefslogtreecommitdiff
path: root/kernel/memory
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-25 18:42:30 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-25 18:42:30 -0400
commit2cf6fe3f4d0811f1d62ed3ba73d15c8a187f600f (patch)
tree0c7a049c8f6293b27231a409600bc757e928925f /kernel/memory
parentadd comment (diff)
downloadcomus-2cf6fe3f4d0811f1d62ed3ba73d15c8a187f600f.tar.gz
comus-2cf6fe3f4d0811f1d62ed3ba73d15c8a187f600f.tar.bz2
comus-2cf6fe3f4d0811f1d62ed3ba73d15c8a187f600f.zip
mem_get_phys fn
Diffstat (limited to '')
-rw-r--r--kernel/memory/memory.c5
-rw-r--r--kernel/memory/paging.c23
-rw-r--r--kernel/memory/physalloc.c3
3 files changed, 24 insertions, 7 deletions
diff --git a/kernel/memory/memory.c b/kernel/memory/memory.c
index 295823e..bd3e06b 100644
--- a/kernel/memory/memory.c
+++ b/kernel/memory/memory.c
@@ -31,6 +31,11 @@ void kunmapaddr(const void *virt)
mem_unmapaddr(kernel_mem_ctx, virt);
}
+void *kget_phys(const void *virt)
+{
+ return mem_get_phys(kernel_mem_ctx, virt);
+}
+
void *kalloc_page(void)
{
return mem_alloc_page(kernel_mem_ctx, F_PRESENT | F_WRITEABLE);
diff --git a/kernel/memory/paging.c b/kernel/memory/paging.c
index 5a0b285..d54a26b 100644
--- a/kernel/memory/paging.c
+++ b/kernel/memory/paging.c
@@ -5,6 +5,7 @@
#include "physalloc.h"
#include "paging.h"
#include "memory.h"
+#include <stdint.h>
// PAGE MAP LEVEL 4 ENTRY
struct pml4e {
@@ -753,15 +754,11 @@ void *mem_mapaddr(mem_ctx_t ctx, void *phys, void *virt, size_t len,
void *kmapuseraddr(mem_ctx_t ctx, const void *vADDR, size_t len)
{
char *pADDR;
- volatile struct pte *vPTE;
- vPTE = page_locate((volatile struct pml4 *)ctx->pml4, vADDR);
- if (vPTE == NULL)
+ pADDR = mem_get_phys(ctx, vADDR);
+ if (pADDR == NULL)
return NULL;
- pADDR = (void *)((uintptr_t)vPTE->address << 12);
- pADDR += ((uint64_t)vADDR % PAGE_SIZE);
-
return kmapaddr(pADDR, NULL, len, F_PRESENT | F_WRITEABLE);
}
@@ -776,6 +773,20 @@ void mem_unmapaddr(mem_ctx_t ctx, const void *virt)
unmap_pages(&kernel_pml4, virt, pages);
}
+void *mem_get_phys(mem_ctx_t ctx, const void *vADDR)
+{
+ char *pADDR;
+ volatile struct pte *vPTE;
+
+ vPTE = page_locate((volatile struct pml4 *)ctx->pml4, vADDR);
+ if (vPTE == NULL)
+ return NULL;
+
+ pADDR = (void *)((uintptr_t)vPTE->address << 12);
+ pADDR += ((uint64_t)vADDR % PAGE_SIZE);
+ return pADDR;
+}
+
void *mem_alloc_page(mem_ctx_t ctx, unsigned int flags)
{
return mem_alloc_pages(ctx, 1, flags);
diff --git a/kernel/memory/physalloc.c b/kernel/memory/physalloc.c
index 01464ee..48d2e3f 100644
--- a/kernel/memory/physalloc.c
+++ b/kernel/memory/physalloc.c
@@ -88,7 +88,8 @@ void *alloc_phys_pages_exact(size_t pages)
if (bitmap == NULL || page_start == NULL) {
// temporary bump allocator
void *addr = (void *)memory_start;
- assert(pages == 1, "caller expects more pages, but is only getting one");
+ assert(pages == 1,
+ "caller expects more pages, but is only getting one");
memory_start += PAGE_SIZE;
return addr;
}