Add more mapping helpers (nocache, summarize)
authorJack Miller <jack@codezen.org>
Sat, 19 Mar 2016 18:47:52 +0000 (13:47 -0500)
committerJack Miller <jack@codezen.org>
Sat, 19 Mar 2016 19:02:48 +0000 (14:02 -0500)
include/map.h
mm/map.c

index 2bf0ce4..50f4535 100644 (file)
@@ -4,6 +4,8 @@
 #include <types.h>
 
 int map_page(u64 virtual, u64 physical);
+int map_page_nocache(u64 virtual, u64 physical);
 void *map_page_early(u64 virtual, u64 physical, u64 *alloc_base);
+void map_page_summarize(u64 virtual);
 
 #endif
index c5b198b..4d6bca9 100644 (file)
--- a/mm/map.c
+++ b/mm/map.c
@@ -4,7 +4,7 @@
 #include <errno.h>
 #include <memmap.h>
 #include <page_alloc.h>
-
+#include <console.h>
 #include <asm/misc.h>
 
 static void __early_map_check(u64 *entry, u64 *target, u64 *alloc_base)
@@ -69,7 +69,7 @@ int __map_check(u64 *entry, u64 *target)
        return 0;
 }
 
-int map_page(u64 virtual, u64 physical)
+int __map_page_flags(u64 virtual, u64 physical, u8 flags)
 {
        u64 *pml4e,*pdpe,*pde,*pte = NULL;
        int ret, allocd = 0;
@@ -97,9 +97,10 @@ int map_page(u64 virtual, u64 physical)
        if (ret < 0)
                goto cleanup_pdpe;
 
-       *pte = physical | PF_RW | PF_P;
+       *pte = physical | PF_P | flags;
 
        reset_cr3();
+
        return 0;
 
 cleanup_pdpe:
@@ -118,3 +119,20 @@ cleanup_pml4e:
 
        return -ENOMEM;
 }
+
+int map_page(u64 virtual, u64 physical)
+{
+       return __map_page_flags(virtual, physical, PF_RW);
+}
+
+int map_page_nocache(u64 virtual, u64 physical)
+{
+       return __map_page_flags(virtual, physical, PF_RW | PF_DISABLE_CACHE);
+}
+
+void map_page_summarize(u64 virtual)
+{
+       u64 *pte = (u64 *) PTE_ADDR(virtual);
+
+       printk("M: 0x%lx -> 0x%lx\n", virtual, *pte);
+}