annotate src/impl/vm_impl.cbc @ 253:124c51584208

update vm_impl.h
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 04 Feb 2020 14:33:56 +0900
parents 58da7a1234f7
children 17ccc6e21e35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
192
tobaru
parents: 190
diff changeset
1 #include "../../context.h"
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
2 #interface "vm.h"
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
3
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
4 // ----
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
5 // typedef struct vm_impl<Impl, Isa> impl vm{
196
anatofuz
parents: 195
diff changeset
6 // union Data* vm_impl;
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
7 // uint i;
196
anatofuz
parents: 195
diff changeset
8 // pte_t* pte;
anatofuz
parents: 195
diff changeset
9 // uint sz;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
10 //
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
11 // __code loaduvm_ptesize_check(Type* vm_impl, __code next(...));
196
anatofuz
parents: 195
diff changeset
12 // __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, uint sz, __code next(...));
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
13 // __code next(...);
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
14 //
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
15 //
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
16 // } vm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
17 // ----
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
18
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
19 vm* createvm_impl(struct Context* cbc_context) {
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
20 struct vm* vm = new vm();
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
21 struct vm_impl* vm_impl = new vm_impl();
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
22 vm->vm = (union Data*)vm_impl;
196
anatofuz
parents: 195
diff changeset
23 vm_impl->vm_impl = NULL;
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
24 vm_impl->i = 0;
196
anatofuz
parents: 195
diff changeset
25 vm_impl->pte = NULL;
anatofuz
parents: 195
diff changeset
26 vm_impl->sz = 0;
anatofuz
parents: 195
diff changeset
27 vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl;
anatofuz
parents: 195
diff changeset
28 vm_impl->loaduvm_loop = C_loaduvm_loopvm_impl;
205
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 203
diff changeset
29 vm_impl->allocuvm_check_newsz = C_allocuvm_check_newszvm_impl;
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 203
diff changeset
30 vm_impl->allocuvm_loop = C_allocuvm_loopvm_impl;
208
f940ff602312 copyuvm_loop
tobaru
parents: 207
diff changeset
31 vm_impl->copyuvm_check_null = C_copyuvm_check_nullvm_impl;
f940ff602312 copyuvm_loop
tobaru
parents: 207
diff changeset
32 vm_impl->copyuvm_loop = C_copyuvm_loopvm_impl;
211
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 210
diff changeset
33 vm_impl->uva2ka_check_pe_types = C_uva2ka_check_pe_types;
213
7a4d299a35be paging_init
tobaru
parents: 211
diff changeset
34 vm_impl->paging_intvm_impl = C_paging_intvmvm_impl;
214
90b65036d9a2 paging_init
tobaru
parents: 213
diff changeset
35 vm_impl->copyout_loopvm_impl = C_copyout_loopvm_impl;
217
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 216
diff changeset
36 vm_impl->switchuvm_check_pgdirvm_impl = C_switchuvm_check_pgdirvm_impl;
218
80398e02ae72 init_inituvm
tobaru
parents: 217
diff changeset
37 vm_impl->init_inituvm_check_sz = C_init_inituvm_check_sz;
227
052669f2ef74 mv vm_void_ret to interface
anatofuz
parents: 226
diff changeset
38 vm->void_ret = C_vm_void_ret;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
39 vm->init_vmm = C_init_vmmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
40 vm->kpt_freerange = C_kpt_freerangevm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
41 vm->kpt_alloc = C_kpt_allocvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
42 vm->switchuvm = C_switchuvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
43 vm->init_inituvm = C_init_inituvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
44 vm->loaduvm = C_loaduvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
45 vm->allocuvm = C_allocuvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
46 vm->clearpteu = C_clearpteuvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
47 vm->copyuvm = C_copyuvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
48 vm->uva2ka = C_uva2kavm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
49 vm->copyout = C_copyoutvm_impl;
213
7a4d299a35be paging_init
tobaru
parents: 211
diff changeset
50 vm->paging_int = C_paging_intvm_impl;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
51 return vm;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
52 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
53
201
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
54 extern struct {
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
55 struct spinlock lock;
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
56 struct run *freelist;
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
57 } kpt_mem;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
58
227
052669f2ef74 mv vm_void_ret to interface
anatofuz
parents: 226
diff changeset
59 __code init_vmmvm_impl(struct vm_impl* vm,__code next(...)) {
201
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
60 initlock(&kpt_mem.lock, "vm");
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
61 kpt_mem.freelist = NULL;
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
62
227
052669f2ef74 mv vm_void_ret to interface
anatofuz
parents: 226
diff changeset
63 goto next(...);
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
64 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
65
202
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
66 extern struct run {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
67 struct run *next;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
68 };
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
69
202
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
70 static void _kpt_free (char *v)
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
71 {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
72 struct run *r;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
73
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
74 r = (struct run*) v;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
75 r->next = kpt_mem.freelist;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
76 kpt_mem.freelist = r;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
77 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
78
202
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
79 __code kpt_freerangevm_impl(struct vm_impl* vm, uint low, uint hi, __code next(...)) {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
80
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
81 if (low < hi) {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
82 _kpt_free((char*)low);
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
83 goto kpt_freerangevm_impl(vm, low + PT_SZ, hi, next(...));
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
84
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
85 }
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
86 goto next(...);
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
87 }
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
88 __code kpt_allocvm_impl(struct vm_impl* vm, __code next(...)) {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
89 acquire(&kpt_mem.lock);
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
90
203
6e03cee9733e can use r
tobaru
parents: 202
diff changeset
91 goto kpt_alloc_check_impl(vm_impl, next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
92 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
93
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
94 typedef struct proc proc;
205
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 203
diff changeset
95 __code switchuvmvm_impl(struct vm_impl* vm , struct proc* p, __code next(...)) { //:skip
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
96
217
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 216
diff changeset
97 goto switchuvm_check_pgdirvm_impl(...);
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
98 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
99
218
80398e02ae72 init_inituvm
tobaru
parents: 217
diff changeset
100 __code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) {
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
101
228
d1c7018537c0 write static constructor
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 227
diff changeset
102 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
d1c7018537c0 write static constructor
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 227
diff changeset
103 Gearef(cbc_context, vm_impl)->init = init;
d1c7018537c0 write static constructor
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 227
diff changeset
104 Gearef(cbc_context, vm_impl)->sz = sz;
d1c7018537c0 write static constructor
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 227
diff changeset
105 Gearef(cbc_context, vm_impl)->next = next;
218
80398e02ae72 init_inituvm
tobaru
parents: 217
diff changeset
106 goto init_inituvm_check_sz(vm, pgdir, init, sz, next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
107 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
108
197
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
109 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) {
231
58da7a1234f7 s/vm->impl=/Gearef/
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 228
diff changeset
110 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
58da7a1234f7 s/vm->impl=/Gearef/
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 228
diff changeset
111 Gearef(cbc_context, vm_impl)->addr = addr;
58da7a1234f7 s/vm->impl=/Gearef/
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 228
diff changeset
112 Gearef(cbc_context, vm_impl)->ip = ip;
58da7a1234f7 s/vm->impl=/Gearef/
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 228
diff changeset
113 Gearef(cbc_context, vm_impl)->offset = offset;
58da7a1234f7 s/vm->impl=/Gearef/
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 228
diff changeset
114 Gearef(cbc_context, vm_impl)->sz = sz;
58da7a1234f7 s/vm->impl=/Gearef/
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 228
diff changeset
115 Gearef(cbc_context, vm_impl)->next = next;
58da7a1234f7 s/vm->impl=/Gearef/
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 228
diff changeset
116
210
b8597756f701 fix loaduvm loop
tobaru
parents: 208
diff changeset
117 goto loaduvm_ptesize_checkvm_impl(vm, next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
118 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
119
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
120 __code allocuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...)) {
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
121
205
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 203
diff changeset
122 goto allocuvm_check_newszvm_impl(vm, pgdir, oldsz, newsz, next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
123 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
124
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
125 __code clearpteuvm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
126
210
b8597756f701 fix loaduvm loop
tobaru
parents: 208
diff changeset
127 goto clearpteu_check_ptevm_impl(vm, pgdir, uva, next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
128 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
129
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
130 __code copyuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint sz, __code next(...)) {
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
131
208
f940ff602312 copyuvm_loop
tobaru
parents: 207
diff changeset
132 goto copyuvm_check_nullvm_impl(vm, pgdir, sz, __code next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
133 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
134
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
135 __code uva2kavm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
136
211
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 210
diff changeset
137 goto uva2ka_check_pe_types(vm, pgdir, uva, next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
138 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
139
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
140 __code copyoutvm_impl(struct vm_impl* vm, pde_t* pgdir, uint va, void* pp, uint len, __code next(...)) {
214
90b65036d9a2 paging_init
tobaru
parents: 213
diff changeset
141
90b65036d9a2 paging_init
tobaru
parents: 213
diff changeset
142 vm->buf = (char*) pp;
90b65036d9a2 paging_init
tobaru
parents: 213
diff changeset
143
215
37900976db8e copyout
tobaru
parents: 214
diff changeset
144 goto copyout_loopvm_impl(vm, pgdir, va, pp, len, va0, pa0, next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
145 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
146
213
7a4d299a35be paging_init
tobaru
parents: 211
diff changeset
147 __code paging_intvm_impl(struct vm_impl* vm, uint phy_low, uint phy_hi, __code next(...)) {
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
148
213
7a4d299a35be paging_init
tobaru
parents: 211
diff changeset
149 goto paging_intvmvm_impl(vm, phy_low, phy_hi, next(...));
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
150 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
151
227
052669f2ef74 mv vm_void_ret to interface
anatofuz
parents: 226
diff changeset
152 __code vm_void_ret(struct vm_impl* vm) {
052669f2ef74 mv vm_void_ret to interface
anatofuz
parents: 226
diff changeset
153 return;
052669f2ef74 mv vm_void_ret to interface
anatofuz
parents: 226
diff changeset
154 }