summaryrefslogtreecommitdiff
path: root/src/include/mm/paging.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/mm/paging.h')
-rw-r--r--src/include/mm/paging.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/include/mm/paging.h b/src/include/mm/paging.h
new file mode 100644
index 0000000..7ff9e7a
--- /dev/null
+++ b/src/include/mm/paging.h
@@ -0,0 +1,47 @@
+#ifndef PAGING_H
+#define PAGING_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+/*
+ * Virtual address bits meaning
+ *
+ * [ 31-22 | 21-12 | 11-00 ]
+ * [ Page directory Idx | Page table Idx | Offset within page ]
+ *
+ *
+ */
+#define PAGING_DIRECTORY_BITS (22)
+#define PAGING_TABLE_BITS (12)
+#define PAGING_TABLE_MASK (0x3ff)
+#define PAGING_PAGE_OFFSET_MASK (0xfff)
+
+/* Page directory control bits */
+#define PAGING_CACHE_DISABLED (1 << 4)
+#define PAGING_WRITE_THROUGH (1 << 3)
+#define PAGING_USER_ACCESS (1 << 2)
+#define PAGING_IS_WRITABLE (1 << 1)
+#define PAGING_IS_PRESENT (1 << 0)
+
+#define PAGING_ENTRIES_PER_TABLE 1024
+
+struct page_directory
+{
+ uint32_t *directory;
+};
+
+struct page_directory * paging_new_directory(uint8_t flags);
+uint32_t * paging_get_directory(struct page_directory *pd);
+void paging_switch(struct page_directory *directory);
+
+void enable_paging();
+
+bool paging_is_aligned(void *addr);
+int paging_map_vaddr(struct page_directory *directory,
+ void *vaddr,
+ void *paddr,
+ uint32_t val);
+
+#endif /* PAGING_H */