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