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_USER (1ull << 2) 17 #define PTE_ADDR (0xffffffffff000ull) 18 19 void setup_vm(); 20 21 void *vmalloc(unsigned long size); 22 void vfree(void *mem); 23 void *vmap(unsigned long long phys, unsigned long size); 24 void *alloc_vpage(void); 25 void *alloc_vpages(ulong nr); 26 uint64_t virt_to_phys_cr3(void *mem); 27 28 unsigned long *get_pte(unsigned long *cr3, void *virt); 29 unsigned long *install_pte(unsigned long *cr3, 30 int pte_level, 31 void *virt, 32 unsigned long pte, 33 unsigned long *pt_page); 34 35 void *alloc_page(); 36 37 unsigned long *install_large_page(unsigned long *cr3,unsigned long phys, 38 void *virt); 39 unsigned long *install_page(unsigned long *cr3, unsigned long phys, void *virt); 40 41 static inline unsigned long virt_to_phys(const void *virt) 42 { 43 return (unsigned long)virt; 44 } 45 46 static inline void *phys_to_virt(unsigned long phys) 47 { 48 return (void *)phys; 49 } 50 51 #endif 52