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;
|
223
|
35 vm_impl->copyout_loopvm_impl = C_copyout_loopvm_impl;
|
226
|
36 vm_impl->switchuvm_check_pgdirvm_impl = C_switchuvm_check_pgdirvm_impl;
|
227
|
37 vm_impl->init_inituvm_check_sz = C_init_inituvm_check_sz;
|
195
|
38 vm->init_vmm = C_init_vmmvm_impl;
|
|
39 vm->kpt_freerange = C_kpt_freerangevm_impl;
|
|
40 vm->kpt_alloc = C_kpt_allocvm_impl;
|
|
41 vm->switchuvm = C_switchuvmvm_impl;
|
|
42 vm->init_inituvm = C_init_inituvmvm_impl;
|
|
43 vm->loaduvm = C_loaduvmvm_impl;
|
|
44 vm->allocuvm = C_allocuvmvm_impl;
|
|
45 vm->clearpteu = C_clearpteuvm_impl;
|
|
46 vm->copyuvm = C_copyuvmvm_impl;
|
|
47 vm->uva2ka = C_uva2kavm_impl;
|
|
48 vm->copyout = C_copyoutvm_impl;
|
222
|
49 vm->paging_int = C_paging_intvm_impl;
|
195
|
50 return vm;
|
|
51 }
|
|
52
|
209
|
53 extern struct {
|
|
54 struct spinlock lock;
|
|
55 struct run *freelist;
|
|
56 } kpt_mem;
|
195
|
57
|
|
58 __code init_vmmvm_impl(struct vm_impl* vm, __code next(...)) {
|
209
|
59 initlock(&kpt_mem.lock, "vm");
|
|
60 kpt_mem.freelist = NULL;
|
|
61
|
195
|
62 goto next(...);
|
|
63 }
|
|
64
|
211
|
65 extern struct run {
|
|
66 struct run *next;
|
|
67 };
|
195
|
68
|
211
|
69 static void _kpt_free (char *v)
|
|
70 {
|
|
71 struct run *r;
|
|
72
|
|
73 r = (struct run*) v;
|
|
74 r->next = kpt_mem.freelist;
|
|
75 kpt_mem.freelist = r;
|
195
|
76 }
|
|
77
|
211
|
78 __code kpt_freerangevm_impl(struct vm_impl* vm, uint low, uint hi, __code next(...)) {
|
|
79
|
|
80 if (low < hi) {
|
|
81 _kpt_free((char*)low);
|
|
82 goto kpt_freerangevm_impl(vm, low + PT_SZ, hi, next(...));
|
|
83
|
|
84 }
|
|
85 goto next(...);
|
|
86 }
|
|
87 __code kpt_allocvm_impl(struct vm_impl* vm, __code next(...)) {
|
|
88 acquire(&kpt_mem.lock);
|
195
|
89
|
212
|
90 goto kpt_alloc_check_impl(vm_impl, next(...));
|
195
|
91 }
|
|
92
|
200
|
93 typedef struct proc proc;
|
214
|
94 __code switchuvmvm_impl(struct vm_impl* vm , struct proc* p, __code next(...)) { //:skip
|
195
|
95
|
226
|
96 goto switchuvm_check_pgdirvm_impl(...);
|
195
|
97 }
|
|
98
|
227
|
99 __code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) {
|
195
|
100
|
227
|
101 goto init_inituvm_check_sz(vm, pgdir, init, sz, next(...));
|
195
|
102 }
|
|
103
|
205
|
104 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) {
|
|
105 vm->pgdir = pgdir;
|
|
106 vm->addr = addr;
|
|
107 vm->ip = ip;
|
|
108 vm->offset = offset;
|
|
109 vm->sz = sz;
|
|
110
|
219
|
111 goto loaduvm_ptesize_checkvm_impl(vm, next(...));
|
195
|
112 }
|
|
113
|
200
|
114 __code allocuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...)) {
|
195
|
115
|
214
|
116 goto allocuvm_check_newszvm_impl(vm, pgdir, oldsz, newsz, next(...));
|
195
|
117 }
|
|
118
|
|
119 __code clearpteuvm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
|
|
120
|
219
|
121 goto clearpteu_check_ptevm_impl(vm, pgdir, uva, next(...));
|
195
|
122 }
|
|
123
|
200
|
124 __code copyuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint sz, __code next(...)) {
|
195
|
125
|
217
|
126 goto copyuvm_check_nullvm_impl(vm, pgdir, sz, __code next(...));
|
195
|
127 }
|
|
128
|
|
129 __code uva2kavm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
|
|
130
|
220
|
131 goto uva2ka_check_pe_types(vm, pgdir, uva, next(...));
|
195
|
132 }
|
|
133
|
200
|
134 __code copyoutvm_impl(struct vm_impl* vm, pde_t* pgdir, uint va, void* pp, uint len, __code next(...)) {
|
223
|
135
|
|
136 vm->buf = (char*) pp;
|
|
137
|
224
|
138 goto copyout_loopvm_impl(vm, pgdir, va, pp, len, va0, pa0, next(...));
|
195
|
139 }
|
|
140
|
222
|
141 __code paging_intvm_impl(struct vm_impl* vm, uint phy_low, uint phy_hi, __code next(...)) {
|
195
|
142
|
222
|
143 goto paging_intvmvm_impl(vm, phy_low, phy_hi, next(...));
|
195
|
144 }
|
|
145
|