diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-25 18:42:30 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-25 18:42:30 -0400 |
commit | 2cf6fe3f4d0811f1d62ed3ba73d15c8a187f600f (patch) | |
tree | 0c7a049c8f6293b27231a409600bc757e928925f /kernel/memory/paging.c | |
parent | add comment (diff) | |
download | comus-2cf6fe3f4d0811f1d62ed3ba73d15c8a187f600f.tar.gz comus-2cf6fe3f4d0811f1d62ed3ba73d15c8a187f600f.tar.bz2 comus-2cf6fe3f4d0811f1d62ed3ba73d15c8a187f600f.zip |
mem_get_phys fn
Diffstat (limited to 'kernel/memory/paging.c')
-rw-r--r-- | kernel/memory/paging.c | 23 |
1 files changed, 17 insertions, 6 deletions
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); |