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