aboutsummaryrefslogtreecommitdiff
path: root/kernel/include/mm/virtual_mm.h
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/include/mm/virtual_mm.h')
-rw-r--r--kernel/include/mm/virtual_mm.h45
1 files changed, 34 insertions, 11 deletions
diff --git a/kernel/include/mm/virtual_mm.h b/kernel/include/mm/virtual_mm.h
index 3f938d2..ad2b961 100644
--- a/kernel/include/mm/virtual_mm.h
+++ b/kernel/include/mm/virtual_mm.h
@@ -29,20 +29,22 @@
#define PAGE_DIRECTORY_INDEX(virtual_address) ((virtual_address >> 22) & 0x3ff)
#define PAGE_TABLE_INDEX(virtual_address) ((virtual_address >> 12) & 0x3ff)
-#define PDE_PRESENT 1
-#define PDE_WRITABLE (1 << 1)
-#define PDE_USER (1 << 2)
-#define PDE_WRITETHROUGH (1 << 3)
-#define PDE_CACHE_DISABLE (1 << 4)
-#define PDE_ACCESSED (1 << 5)
+#define SET_PDE_PRESENT(x) x
+#define SET_PDE_WRITABLE(x) (x << 1)
+#define SET_PDE_USER(x) (x << 2)
+#define SET_PDE_WRITETHROUGH(x) (x << 3)
+#define SET_PDE_CACHE_DISABLE(x) (x << 4)
+#define SET_PDE_ACCESSED(x) (x << 5)
/* Never set (reserved by Intel) */
-#define PDE_RESERVED (0 << 6)
-#define PDE_PAGE_SIZE (1 << 7)
-#define PDE_GLOBAL (1 << 8)
+#define SET_PDE_RESERVED(x) (x << 6)
+#define SET_PDE_PAGE_SIZE(x) (x << 7)
+#define SET_PDE_GLOBAL(x) (x << 8)
/* NOTE: Unused by the CPU, free to be used by us! */
-#define PDE_UNUSED(x) (x << 9)
+#define SET_PDE_UNUSED(x) (x << 9)
/* Page table address */
-#define PDE_FRAME(x) (x << 11)
+#define SET_PDE_FRAME(x) (x << 11)
+
+#define GET_PDE_FRAME(x) (*x >> 11)
#define SET_PTE_PRESENT(x) x
#define SET_PTE_WRITABLE(x) (x << 1)
@@ -58,6 +60,7 @@
/* MAX: 0xFFFFF000 */
#define SET_PTE_FRAME(x) (x << 11)
+#define PTE_IS_PRESENT(x) (x & 1)
#define GET_PTE_FRAME(x) (*x >> 11)
#define ADD_ATTRIB(entry, attribute) (*entry |= (attribute))
@@ -92,4 +95,24 @@ uint32_t *virtual_mm_lookup_directory(uint32_t *page_directory,
*/
void virtual_mm_load_page_directory(uint32_t *page_directory);
+/*
+ * Switches the current page directory to a given page directory
+ */
+bool virtual_mm_switch_page_directory(uint32_t *page_directory);
+
+/*
+ * Flushes the given TLB entry
+ */
+void virtual_mm_flush_tlb_entry(uint32_t *virtual_addr);
+
+/*
+ * Map a given physical address to a virtual address
+ */
+bool virtual_mm_map_page(uint32_t *physical_addr, uint32_t *virtual_addr);
+
+/*
+ * Initialize the virtual memory manager
+ */
+void virtual_mm_initialize(void);
+
#endif