1 #ifndef VM_H 2 #define VM_H 3 4 #include "processor.h" 5 6 #define PAGE_SIZE 4096ul 7 #ifdef __x86_64__ 8 #define LARGE_PAGE_SIZE (512 * PAGE_SIZE) 9 #else 10 #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) 11 #endif 12 13 #define PTE_PRESENT (1ull << 0) 14 #define PTE_PSE (1ull << 7) 15 #define PTE_WRITE (1ull << 1) 16 #define PTE_ADDR (0xffffffffff000ull) 17 18 void setup_vm(); 19 20 void *vmalloc(unsigned long size); 21 void vfree(void *mem); 22 void *vmap(unsigned long long phys, unsigned long size); 23 24 void install_pte(unsigned long *cr3, 25 int pte_level, 26 void *virt, 27 unsigned long pte, 28 unsigned long *pt_page); 29 30 void *alloc_page(); 31 32 void install_large_page(unsigned long *cr3,unsigned long phys, 33 void *virt); 34 void install_page(unsigned long *cr3, unsigned long phys, void *virt); 35 36 static inline unsigned long virt_to_phys(const void *virt) 37 { 38 return (unsigned long)virt; 39 } 40 41 static inline void *phys_to_virt(unsigned long phys) 42 { 43 return (void *)phys; 44 } 45 46 #endif 47