197
|
1 #include "../../context.h"
|
195
|
2 #interface "vm.h"
|
|
3
|
|
4 // ----
|
|
5 // typedef struct vm_impl<Impl, Isa> impl vm{
|
204
|
6 // union Data* vm_impl;
|
200
|
7 // uint i;
|
204
|
8 // pte_t* pte;
|
|
9 // uint sz;
|
195
|
10 //
|
200
|
11 // __code loaduvm_ptesize_check(Type* vm_impl, __code next(...));
|
204
|
12 // __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, uint sz, __code next(...));
|
200
|
13 // __code next(...);
|
195
|
14 //
|
|
15 //
|
|
16 // } vm_impl;
|
|
17 // ----
|
|
18
|
|
19 vm* createvm_impl(struct Context* cbc_context) {
|
|
20 struct vm* vm = new vm();
|
|
21 struct vm_impl* vm_impl = new vm_impl();
|
|
22 vm->vm = (union Data*)vm_impl;
|
204
|
23 vm_impl->vm_impl = NULL;
|
200
|
24 vm_impl->i = 0;
|
204
|
25 vm_impl->pte = NULL;
|
|
26 vm_impl->sz = 0;
|
|
27 vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl;
|
|
28 vm_impl->loaduvm_loop = C_loaduvm_loopvm_impl;
|
214
|
29 vm_impl->allocuvm_check_newsz = C_allocuvm_check_newszvm_impl;
|
|
30 vm_impl->allocuvm_loop = C_allocuvm_loopvm_impl;
|
217
|
31 vm_impl->copyuvm_check_null = C_copyuvm_check_nullvm_impl;
|
|
32 vm_impl->copyuvm_loop = C_copyuvm_loopvm_impl;
|
220
|
33 vm_impl->uva2ka_check_pe_types = C_uva2ka_check_pe_types;
|
222
|
34 vm_impl->paging_intvm_impl = C_paging_intvmvm_impl;
|
195
|
35 vm->init_vmm = C_init_vmmvm_impl;
|
|
36 vm->kpt_freerange = C_kpt_freerangevm_impl;
|
|
37 vm->kpt_alloc = C_kpt_allocvm_impl;
|
|
38 vm->switchuvm = C_switchuvmvm_impl;
|
|
39 vm->init_inituvm = C_init_inituvmvm_impl;
|
|
40 vm->loaduvm = C_loaduvmvm_impl;
|
|
41 vm->allocuvm = C_allocuvmvm_impl;
|
|
42 vm->clearpteu = C_clearpteuvm_impl;
|
|
43 vm->copyuvm = C_copyuvmvm_impl;
|
|
44 vm->uva2ka = C_uva2kavm_impl;
|
|
45 vm->copyout = C_copyoutvm_impl;
|
222
|
46 vm->paging_int = C_paging_intvm_impl;
|
195
|
47 return vm;
|
|
48 }
|
|
49
|
209
|
50 extern struct {
|
|
51 struct spinlock lock;
|
|
52 struct run *freelist;
|
|
53 } kpt_mem;
|
195
|
54
|
|
55 __code init_vmmvm_impl(struct vm_impl* vm, __code next(...)) {
|
209
|
56 initlock(&kpt_mem.lock, "vm");
|
|
57 kpt_mem.freelist = NULL;
|
|
58
|
195
|
59 goto next(...);
|
|
60 }
|
|
61
|
211
|
62 extern struct run {
|
|
63 struct run *next;
|
|
64 };
|
195
|
65
|
211
|
66 static void _kpt_free (char *v)
|
|
67 {
|
|
68 struct run *r;
|
|
69
|
|
70 r = (struct run*) v;
|
|
71 r->next = kpt_mem.freelist;
|
|
72 kpt_mem.freelist = r;
|
195
|
73 }
|
|
74
|
211
|
75 __code kpt_freerangevm_impl(struct vm_impl* vm, uint low, uint hi, __code next(...)) {
|
|
76
|
|
77 if (low < hi) {
|
|
78 _kpt_free((char*)low);
|
|
79 goto kpt_freerangevm_impl(vm, low + PT_SZ, hi, next(...));
|
|
80
|
|
81 }
|
|
82 goto next(...);
|
|
83 }
|
|
84 __code kpt_allocvm_impl(struct vm_impl* vm, __code next(...)) {
|
|
85 acquire(&kpt_mem.lock);
|
195
|
86
|
212
|
87 goto kpt_alloc_check_impl(vm_impl, next(...));
|
211
|
88
|
|
89 goto next(...);
|
195
|
90 }
|
|
91
|
200
|
92 typedef struct proc proc;
|
214
|
93 __code switchuvmvm_impl(struct vm_impl* vm , struct proc* p, __code next(...)) { //:skip
|
195
|
94
|
|
95 goto next(...);
|
|
96 }
|
|
97
|
200
|
98 __code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) { //:skip
|
195
|
99
|
|
100 goto next(...);
|
|
101 }
|
|
102
|
205
|
103 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) {
|
|
104 vm->pgdir = pgdir;
|
|
105 vm->addr = addr;
|
|
106 vm->ip = ip;
|
|
107 vm->offset = offset;
|
|
108 vm->sz = sz;
|
|
109
|
219
|
110 goto loaduvm_ptesize_checkvm_impl(vm, next(...));
|
195
|
111 }
|
|
112
|
200
|
113 __code allocuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...)) {
|
195
|
114
|
214
|
115 goto allocuvm_check_newszvm_impl(vm, pgdir, oldsz, newsz, next(...));
|
195
|
116 }
|
|
117
|
|
118 __code clearpteuvm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
|
|
119
|
219
|
120 goto clearpteu_check_ptevm_impl(vm, pgdir, uva, next(...));
|
195
|
121 }
|
|
122
|
200
|
123 __code copyuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint sz, __code next(...)) {
|
195
|
124
|
217
|
125 goto copyuvm_check_nullvm_impl(vm, pgdir, sz, __code next(...));
|
195
|
126 }
|
|
127
|
|
128 __code uva2kavm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
|
|
129
|
220
|
130 goto uva2ka_check_pe_types(vm, pgdir, uva, next(...));
|
195
|
131 }
|
|
132
|
200
|
133 __code copyoutvm_impl(struct vm_impl* vm, pde_t* pgdir, uint va, void* pp, uint len, __code next(...)) {
|
222
|
134
|
195
|
135 goto next(...);
|
|
136 }
|
|
137
|
222
|
138 __code paging_intvm_impl(struct vm_impl* vm, uint phy_low, uint phy_hi, __code next(...)) {
|
195
|
139
|
222
|
140 goto paging_intvmvm_impl(vm, phy_low, phy_hi, next(...));
|
195
|
141 }
|
|
142
|