kern

view src/vm.h @ 51:b1e8c8251884

lalalala
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 01 Aug 2011 06:45:29 +0300
parents 5f6c5751ae05
children 88a6c4e192f9
line source
1 #ifndef VM_H_
2 #define VM_H_
4 #include <stdlib.h>
5 #include "mboot.h"
7 #define KMEM_START 0xc0000000
9 /* page mapping flags */
10 #define PG_PRESENT (1 << 0)
11 #define PG_WRITABLE (1 << 1)
12 #define PG_USER (1 << 2)
13 #define PG_WRITE_THROUGH (1 << 3)
14 #define PG_NOCACHE (1 << 4)
15 #define PG_ACCESSED (1 << 5)
16 #define PG_DIRTY (1 << 6)
17 #define PG_TYPE (1 << 7)
18 /* PG_GLOBAL mappings won't flush from TLB */
19 #define PG_GLOBAL (1 << 8)
22 #define PGSIZE 4096
23 #define PAGE_COUNT (1024 * 1024)
25 #define PGOFFS_MASK 0xfff
26 #define PGNUM_MASK 0xfffff000
27 #define PGENT_ADDR_MASK PGNUM_MASK
29 #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12)
30 #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12)
32 #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22)
33 #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff)
34 #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK)
36 #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10)
37 #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff)
40 void init_vm(void);
42 int map_page(int vpage, int ppage, unsigned int attr);
43 int unmap_page(int vpage);
44 int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);
45 int unmap_page_range(int vpg_start, int pgcount);
46 int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr);
48 int virt_to_phys_page(int vpg);
49 uint32_t virt_to_phys(uint32_t vaddr);
51 enum {
52 MEM_KERNEL,
53 MEM_USER
54 };
56 int pgalloc(int num, int area);
57 int pgalloc_vrange(int start, int num);
58 void pgfree(int start, int num);
60 uint32_t clone_vm(void);
62 void dbg_print_vm(int area);
64 /* defined in vm-asm.S */
65 void set_pgdir_addr(uint32_t addr);
67 #endif /* VM_H_ */