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@68
|
6 #include "rbtree.h"
|
nuclear@17
|
7
|
nuclear@47
|
8 #define KMEM_START 0xc0000000
|
nuclear@68
|
9 #define KMEM_START_PAGE ADDR_TO_PAGE(KMEM_START)
|
nuclear@47
|
10
|
nuclear@17
|
11 /* page mapping flags */
|
nuclear@17
|
12 #define PG_PRESENT (1 << 0)
|
nuclear@17
|
13 #define PG_WRITABLE (1 << 1)
|
nuclear@17
|
14 #define PG_USER (1 << 2)
|
nuclear@17
|
15 #define PG_WRITE_THROUGH (1 << 3)
|
nuclear@17
|
16 #define PG_NOCACHE (1 << 4)
|
nuclear@17
|
17 #define PG_ACCESSED (1 << 5)
|
nuclear@17
|
18 #define PG_DIRTY (1 << 6)
|
nuclear@17
|
19 #define PG_TYPE (1 << 7)
|
nuclear@17
|
20 /* PG_GLOBAL mappings won't flush from TLB */
|
nuclear@17
|
21 #define PG_GLOBAL (1 << 8)
|
nuclear@17
|
22
|
nuclear@17
|
23
|
nuclear@17
|
24 #define PGSIZE 4096
|
nuclear@23
|
25 #define PAGE_COUNT (1024 * 1024)
|
nuclear@23
|
26
|
nuclear@17
|
27 #define PGOFFS_MASK 0xfff
|
nuclear@17
|
28 #define PGNUM_MASK 0xfffff000
|
nuclear@18
|
29 #define PGENT_ADDR_MASK PGNUM_MASK
|
nuclear@17
|
30
|
nuclear@23
|
31 #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12)
|
nuclear@23
|
32 #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12)
|
nuclear@17
|
33
|
nuclear@17
|
34 #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22)
|
nuclear@17
|
35 #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff)
|
nuclear@17
|
36 #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK)
|
nuclear@17
|
37
|
nuclear@17
|
38 #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10)
|
nuclear@17
|
39 #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff)
|
nuclear@17
|
40
|
nuclear@57
|
41 /* argument to clone_vm */
|
nuclear@57
|
42 #define CLONE_SHARED 0
|
nuclear@57
|
43 #define CLONE_COW 1
|
nuclear@57
|
44
|
nuclear@57
|
45 /* last argument to *_page_bit */
|
nuclear@57
|
46 #define PAGE_ONLY 0
|
nuclear@57
|
47 #define WHOLE_PATH 1
|
nuclear@17
|
48
|
nuclear@68
|
49 struct vm_page {
|
nuclear@68
|
50 int vpage, ppage;
|
nuclear@68
|
51 unsigned int flags;
|
nuclear@68
|
52
|
nuclear@68
|
53 int nref;
|
nuclear@68
|
54 };
|
nuclear@68
|
55
|
nuclear@69
|
56 struct process;
|
nuclear@69
|
57
|
nuclear@26
|
58 void init_vm(void);
|
nuclear@17
|
59
|
nuclear@23
|
60 int map_page(int vpage, int ppage, unsigned int attr);
|
nuclear@43
|
61 int unmap_page(int vpage);
|
nuclear@23
|
62 int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);
|
nuclear@43
|
63 int unmap_page_range(int vpg_start, int pgcount);
|
nuclear@23
|
64 int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr);
|
nuclear@17
|
65
|
nuclear@69
|
66 uint32_t virt_to_phys(uint32_t vaddr);
|
nuclear@43
|
67 int virt_to_phys_page(int vpg);
|
nuclear@69
|
68
|
nuclear@69
|
69 uint32_t virt_to_phys_proc(struct process *p, uint32_t vaddr);
|
nuclear@69
|
70 int virt_to_phys_page_proc(struct process *p, int vpg);
|
nuclear@18
|
71
|
nuclear@22
|
72 enum {
|
nuclear@22
|
73 MEM_KERNEL,
|
nuclear@22
|
74 MEM_USER
|
nuclear@22
|
75 };
|
nuclear@22
|
76
|
nuclear@22
|
77 int pgalloc(int num, int area);
|
nuclear@47
|
78 int pgalloc_vrange(int start, int num);
|
nuclear@23
|
79 void pgfree(int start, int num);
|
nuclear@23
|
80
|
nuclear@72
|
81 /* don't be fooled by the fact these two accept process arguments
|
nuclear@72
|
82 * they in fact work only for the "current" process (psrc and p)
|
nuclear@72
|
83 */
|
nuclear@69
|
84 void clone_vm(struct process *pdest, struct process *psrc, int cow);
|
nuclear@72
|
85 void cleanup_vm(struct process *p);
|
nuclear@57
|
86
|
nuclear@57
|
87 int get_page_bit(int pgnum, uint32_t bit, int wholepath);
|
nuclear@57
|
88 void set_page_bit(int pgnum, uint32_t bit, int wholepath);
|
nuclear@57
|
89 void clear_page_bit(int pgnum, uint32_t bit, int wholepath);
|
nuclear@43
|
90
|
nuclear@68
|
91 /* construct the vm map for the current user mappings */
|
nuclear@68
|
92 int cons_vmmap(struct rbtree *vmmap);
|
nuclear@68
|
93
|
nuclear@69
|
94 struct vm_page *get_vm_page(int vpg);
|
nuclear@69
|
95 struct vm_page *get_vm_page_proc(struct process *p, int vpg);
|
nuclear@69
|
96
|
nuclear@23
|
97 void dbg_print_vm(int area);
|
nuclear@22
|
98
|
nuclear@47
|
99 /* defined in vm-asm.S */
|
nuclear@47
|
100 void set_pgdir_addr(uint32_t addr);
|
nuclear@55
|
101 uint32_t get_pgdir_addr(void);
|
nuclear@47
|
102
|
nuclear@17
|
103 #endif /* VM_H_ */
|