BarryServer : Git

All the code for all my projects
// BarryServer : Git / Orion / commit / d41a53cbc7d055b1c00cf0a339dbed6925f4f02c / mem / paging.h

// Related

Orion

Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)
diff --git a/mem/paging.h b/mem/paging.h
new file mode 100644
index 0000000..a3acaf2
--- /dev/null
+++ b/mem/paging.h
@@ -0,0 +1,58 @@
+#ifndef KERNEL_MEM_PAGING_H
+#define KERNEL_MEM_PAGING_H
+
+#include <stdint.h>
+#include "../proc/proc.h"
+#include "../spinlock.h"
+
+#define PG_ADDR(pg) (pg & 0xFFFFF000)
+#define PG_ATTR(pg) (pg & 0x00000FFF)
+
+#define QUICK_PAGE ((void *) 0x7FF000)
+
+typedef uint32_t page_t;
+typedef uint32_t page_table_t;
+typedef uint32_t page_dir_t;
+
+/* Page flags */
+enum PageFlag {
+	PTE_PRESENT = (1 << 0),
+	PTE_WRITE   = (1 << 1),
+	PTE_USER    = (1 << 2),
+	PTE_THROUGH = (1 << 3),
+	PTE_NOCACHE = (1 << 4),
+	PTE_ACCESS  = (1 << 5),
+	PTE_DIRTY   = (1 << 6),
+	PTE_GLOBAL  = (1 << 8),
+};
+/* Page Table flags */
+enum PageTableFlag {
+	PDE_PRESENT = (1 << 0),
+	PDE_WRITE   = (1 << 1),
+	PDE_USER    = (1 << 2),
+	PDE_THROUGH = (1 << 3),
+	PDE_NOCACHE = (1 << 4),
+	PDE_ACCESS  = (1 << 5),
+};
+
+/* Flush Translation Lookaside Buffer */
+static inline void
+flush_tlb(uintptr_t addr)
+{
+	asm volatile("invlpg (%0)" :: "r" (addr) : "memory");
+}
+
+extern Spinlock quickPageLock;
+extern page_t zeroFrame;
+
+void init_paging(void);
+void early_page_fault_handler(InterruptFrame *frame);
+void page_fault_handler(InterruptFrame *frame);
+void alloc_page(page_t *page, uint16_t flags, page_t frame);
+void free_page(page_t *page);
+page_t *get_page(void *addr);
+page_dir_t clone_dir(void);
+void clean_dir(void);
+page_t quick_page(page_t frame);
+
+#endif