summaryrefslogtreecommitdiff
path: root/src/arch/amd64/paging.c
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2024-02-03 21:38:57 -0500
committerFreya Murphy <freya@freyacat.org>2024-02-03 21:39:02 -0500
commit61e7fdf1eb7d5d4a66c443fe6bd16fd2a2a92859 (patch)
tree757350208c44ac1e639dc7095d3e80eedc6cd74a /src/arch/amd64/paging.c
parentformatting (diff)
downloadcorn-61e7fdf1eb7d5d4a66c443fe6bd16fd2a2a92859.tar.gz
corn-61e7fdf1eb7d5d4a66c443fe6bd16fd2a2a92859.tar.bz2
corn-61e7fdf1eb7d5d4a66c443fe6bd16fd2a2a92859.zip
acpi table loading and shutdown works, plus mmap fix :3
Diffstat (limited to '')
-rw-r--r--src/arch/amd64/paging.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/arch/amd64/paging.c b/src/arch/amd64/paging.c
index a80737c..c857d0b 100644
--- a/src/arch/amd64/paging.c
+++ b/src/arch/amd64/paging.c
@@ -539,20 +539,20 @@ void paging_init(void) {
static inline void *page_align(void *addr) {
uintptr_t a = (uintptr_t) addr;
- a += PAGE_SIZE - 1;
a /= PAGE_SIZE;
a *= PAGE_SIZE;
return (void *) a;
}
void *mmap(void *addr, size_t len) {
- len += (long)addr % PAGE_SIZE;
- long pages = (len + PAGE_SIZE - 1) / PAGE_SIZE;
+ void *phys = page_align(addr);
+ ptrdiff_t error = (char*)addr - (char*)phys;
+ len += error;
+ long pages = len / PAGE_SIZE + 1;
void *virt = virtaddr_alloc(pages);
if (virt == NULL) {
return NULL;
}
- void *phys = page_align(addr);
if (map_pages(
kernel_pml4,
virt,
@@ -563,7 +563,7 @@ void *mmap(void *addr, size_t len) {
virtaddr_free(virt);
return NULL;
}
- return virt;
+ return (char*)virt + error;
}
void unmap(void *addr) {