nuclear@17: #ifndef VM_H_ nuclear@17: #define VM_H_ nuclear@17: nuclear@17: #include nuclear@17: #include "mboot.h" nuclear@17: nuclear@47: #define KMEM_START 0xc0000000 nuclear@47: nuclear@17: /* page mapping flags */ nuclear@17: #define PG_PRESENT (1 << 0) nuclear@17: #define PG_WRITABLE (1 << 1) nuclear@17: #define PG_USER (1 << 2) nuclear@17: #define PG_WRITE_THROUGH (1 << 3) nuclear@17: #define PG_NOCACHE (1 << 4) nuclear@17: #define PG_ACCESSED (1 << 5) nuclear@17: #define PG_DIRTY (1 << 6) nuclear@17: #define PG_TYPE (1 << 7) nuclear@17: /* PG_GLOBAL mappings won't flush from TLB */ nuclear@17: #define PG_GLOBAL (1 << 8) nuclear@17: nuclear@17: nuclear@17: #define PGSIZE 4096 nuclear@23: #define PAGE_COUNT (1024 * 1024) nuclear@23: nuclear@17: #define PGOFFS_MASK 0xfff nuclear@17: #define PGNUM_MASK 0xfffff000 nuclear@18: #define PGENT_ADDR_MASK PGNUM_MASK nuclear@17: nuclear@23: #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12) nuclear@23: #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12) nuclear@17: nuclear@17: #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22) nuclear@17: #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff) nuclear@17: #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK) nuclear@17: nuclear@17: #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10) nuclear@17: #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff) nuclear@17: nuclear@17: nuclear@26: void init_vm(void); nuclear@17: nuclear@23: int map_page(int vpage, int ppage, unsigned int attr); nuclear@43: int unmap_page(int vpage); nuclear@23: int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr); nuclear@43: int unmap_page_range(int vpg_start, int pgcount); nuclear@23: int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr); nuclear@17: nuclear@43: int virt_to_phys_page(int vpg); nuclear@18: uint32_t virt_to_phys(uint32_t vaddr); nuclear@18: nuclear@22: enum { nuclear@22: MEM_KERNEL, nuclear@22: MEM_USER nuclear@22: }; nuclear@22: nuclear@22: int pgalloc(int num, int area); nuclear@47: int pgalloc_vrange(int start, int num); nuclear@23: void pgfree(int start, int num); nuclear@23: nuclear@47: uint32_t clone_vm(void); nuclear@43: nuclear@23: void dbg_print_vm(int area); nuclear@22: nuclear@47: /* defined in vm-asm.S */ nuclear@47: void set_pgdir_addr(uint32_t addr); nuclear@47: nuclear@17: #endif /* VM_H_ */