rev |
line source |
nuclear@17
|
1 #ifndef VM_H_
|
nuclear@17
|
2 #define VM_H_
|
nuclear@17
|
3
|
nuclear@17
|
4 #include <stdlib.h>
|
nuclear@17
|
5 #include "mboot.h"
|
nuclear@17
|
6
|
nuclear@47
|
7 #define KMEM_START 0xc0000000
|
nuclear@47
|
8
|
nuclear@17
|
9 /* page mapping flags */
|
nuclear@17
|
10 #define PG_PRESENT (1 << 0)
|
nuclear@17
|
11 #define PG_WRITABLE (1 << 1)
|
nuclear@17
|
12 #define PG_USER (1 << 2)
|
nuclear@17
|
13 #define PG_WRITE_THROUGH (1 << 3)
|
nuclear@17
|
14 #define PG_NOCACHE (1 << 4)
|
nuclear@17
|
15 #define PG_ACCESSED (1 << 5)
|
nuclear@17
|
16 #define PG_DIRTY (1 << 6)
|
nuclear@17
|
17 #define PG_TYPE (1 << 7)
|
nuclear@17
|
18 /* PG_GLOBAL mappings won't flush from TLB */
|
nuclear@17
|
19 #define PG_GLOBAL (1 << 8)
|
nuclear@17
|
20
|
nuclear@17
|
21
|
nuclear@17
|
22 #define PGSIZE 4096
|
nuclear@23
|
23 #define PAGE_COUNT (1024 * 1024)
|
nuclear@23
|
24
|
nuclear@17
|
25 #define PGOFFS_MASK 0xfff
|
nuclear@17
|
26 #define PGNUM_MASK 0xfffff000
|
nuclear@18
|
27 #define PGENT_ADDR_MASK PGNUM_MASK
|
nuclear@17
|
28
|
nuclear@23
|
29 #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12)
|
nuclear@23
|
30 #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12)
|
nuclear@17
|
31
|
nuclear@17
|
32 #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22)
|
nuclear@17
|
33 #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff)
|
nuclear@17
|
34 #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK)
|
nuclear@17
|
35
|
nuclear@17
|
36 #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10)
|
nuclear@17
|
37 #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff)
|
nuclear@17
|
38
|
nuclear@57
|
39 /* argument to clone_vm */
|
nuclear@57
|
40 #define CLONE_SHARED 0
|
nuclear@57
|
41 #define CLONE_COW 1
|
nuclear@57
|
42
|
nuclear@57
|
43 /* last argument to *_page_bit */
|
nuclear@57
|
44 #define PAGE_ONLY 0
|
nuclear@57
|
45 #define WHOLE_PATH 1
|
nuclear@17
|
46
|
nuclear@26
|
47 void init_vm(void);
|
nuclear@17
|
48
|
nuclear@23
|
49 int map_page(int vpage, int ppage, unsigned int attr);
|
nuclear@43
|
50 int unmap_page(int vpage);
|
nuclear@23
|
51 int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);
|
nuclear@43
|
52 int unmap_page_range(int vpg_start, int pgcount);
|
nuclear@23
|
53 int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr);
|
nuclear@17
|
54
|
nuclear@43
|
55 int virt_to_phys_page(int vpg);
|
nuclear@18
|
56 uint32_t virt_to_phys(uint32_t vaddr);
|
nuclear@18
|
57
|
nuclear@22
|
58 enum {
|
nuclear@22
|
59 MEM_KERNEL,
|
nuclear@22
|
60 MEM_USER
|
nuclear@22
|
61 };
|
nuclear@22
|
62
|
nuclear@22
|
63 int pgalloc(int num, int area);
|
nuclear@47
|
64 int pgalloc_vrange(int start, int num);
|
nuclear@23
|
65 void pgfree(int start, int num);
|
nuclear@23
|
66
|
nuclear@57
|
67 uint32_t clone_vm(int cow);
|
nuclear@57
|
68
|
nuclear@57
|
69 int get_page_bit(int pgnum, uint32_t bit, int wholepath);
|
nuclear@57
|
70 void set_page_bit(int pgnum, uint32_t bit, int wholepath);
|
nuclear@57
|
71 void clear_page_bit(int pgnum, uint32_t bit, int wholepath);
|
nuclear@43
|
72
|
nuclear@23
|
73 void dbg_print_vm(int area);
|
nuclear@22
|
74
|
nuclear@47
|
75 /* defined in vm-asm.S */
|
nuclear@47
|
76 void set_pgdir_addr(uint32_t addr);
|
nuclear@55
|
77 uint32_t get_pgdir_addr(void);
|
nuclear@47
|
78
|
nuclear@17
|
79 #endif /* VM_H_ */
|