annotate src/impl/vm_impl_private.cbc @ 323:f0b337cb6024 default tip

use goto err->panic
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sat, 08 Feb 2020 20:37:42 +0900
parents 173753022721
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
226
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
1 #include "param.h"
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
2 #include "proc.h"
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
3 #include "mmu.h"
222
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
4 #include "defs.h"
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
5 #include "memlayout.h"
200
1301727600cc success build
anatofuz
parents:
diff changeset
6 #interface "vm_impl.h"
316
b58517e62ebf use goto panic at vm_impl
anatofuz
parents: 308
diff changeset
7 #interface "Err.h"
200
1301727600cc success build
anatofuz
parents:
diff changeset
8
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
9 /*
281
4d76280758db move context.pm to util.pm ...
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 270
diff changeset
10 vm_impl* createvm_impl2(); //:skip
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
11 */
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
12
304
9fa2e66bc9ed comment at vm_impl private field
anatofuz
parents: 281
diff changeset
13 __code loaduvm_ptesize_checkvm_impl(struct vm_impl* vm_impl,char* addr, __code next(int ret, ...)) {
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
14 if ((uint) addr %PTE_SZ != 0) {
317
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
15 char* msg = "addr % PTE_SZ != 0";
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
16 struct Err* err = createKernelError(&proc->cbc_context);
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
17 Gearef(cbc_context, Err)->msg = msg;
318
173753022721 s/goto err->panic/goto meta/
anatofuz
parents: 317
diff changeset
18 goto meta(cbc_context, err->panic);
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
19 }
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
20
219
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
21 goto loaduvm_loopvm_impl(vm_impl, next(ret, ...));
200
1301727600cc success build
anatofuz
parents:
diff changeset
22 }
1301727600cc success build
anatofuz
parents:
diff changeset
23
304
9fa2e66bc9ed comment at vm_impl private field
anatofuz
parents: 281
diff changeset
24 __code loaduvm_loopvm_impl(struct vm_impl* vm_impl, uint i, uint sz,__code next(int ret, ...)) {
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
25 if (i < sz) {
219
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
26 goto loaduvm_check_pgdir(vm_impl, next(ret, ...));
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
27 }
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
28
219
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
29 goto loaduvm_exit(vm_impl, next(ret, ...));
200
1301727600cc success build
anatofuz
parents:
diff changeset
30 }
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
31
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
32
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
33 static pte_t* walkpgdir (pde_t *pgdir, const void *va, int alloc)
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
34 {
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
35 pde_t *pde;
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
36 pte_t *pgtab;
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
37
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
38 // pgdir points to the page directory, get the page direcotry entry (pde)
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
39 pde = &pgdir[PDE_IDX(va)];
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
40
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
41 if (*pde & PE_TYPES) {
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
42 pgtab = (pte_t*) p2v(PT_ADDR(*pde));
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
43
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
44 } else {
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
45 if (!alloc || (pgtab = (pte_t*) kpt_alloc()) == 0) {
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
46 return 0;
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
47 }
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
48
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
49 // Make sure all those PTE_P bits are zero.
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
50 memset(pgtab, 0, PT_SZ);
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
51
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
52 // The permissions here are overly generous, but they can
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
53 // be further restricted by the permissions in the page table
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
54 // entries, if necessary.
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
55 *pde = v2p(pgtab) | UPDE_TYPE;
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
56 }
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
57
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
58 return &pgtab[PTE_IDX(va)];
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
59 }
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
60
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
61
304
9fa2e66bc9ed comment at vm_impl private field
anatofuz
parents: 281
diff changeset
62 __code loaduvm_check_pgdir(struct vm_impl* vm_impl, pte_t* pte, pde_t* pgdir, uint i, char* addr, uint pa, __code next(int ret, ...)) {
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
63 if ((pte = walkpgdir(pgdir, addr + i, 0)) == 0) {
317
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
64 char* msg = "pte != walkpgdir...";
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
65 struct Err* err = createKernelError(&proc->cbc_context);
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
66 Gearef(cbc_context, Err)->msg = msg;
318
173753022721 s/goto err->panic/goto meta/
anatofuz
parents: 317
diff changeset
67 goto meta(cbc_context, err->panic);
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
68 }
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
69 pa = PTE_ADDR(*pte);
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
70
308
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
71 Gearef(cbc_context, vm_impl)->pte = pte;
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
72 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
73 Gearef(cbc_context, vm_impl)->addr = addr;
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
74 Gearef(cbc_context, vm_impl)->pa = pa;
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
75
219
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
76 goto loaduvm_check_PTE_SZ(vm_impl, next(ret, ...));
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
77 }
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
78
304
9fa2e66bc9ed comment at vm_impl private field
anatofuz
parents: 281
diff changeset
79 __code loaduvm_check_PTE_SZ(struct vm_impl* vm_impl, uint sz, uint i, uint n, struct inode* ip, uint pa, uint offset, __code next(int ret, ...)) {
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
80
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
81 if (sz - i < PTE_SZ) {
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
82 n = sz - i;
207
8a55878f6a25 loaduvm
tobaru
parents: 206
diff changeset
83 } else {
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
84 n = PTE_SZ;
207
8a55878f6a25 loaduvm
tobaru
parents: 206
diff changeset
85 }
8a55878f6a25 loaduvm
tobaru
parents: 206
diff changeset
86
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
87 if (readi(ip, p2v(pa), offset + i, n) != n) {
219
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
88 ret = -1;
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
89 goto next(ret, ...);
207
8a55878f6a25 loaduvm
tobaru
parents: 206
diff changeset
90 }
8a55878f6a25 loaduvm
tobaru
parents: 206
diff changeset
91
308
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
92 Gearef(cbc_context, vm_impl)->n = n;
208
a0620ca23f19 be functional loaduvm
tobaru
parents: 207
diff changeset
93
219
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
94 goto loaduvm_loopvm_impl(vm_impl, next(ret, ...));
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
95 }
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
96
219
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
97 __code loaduvm_exit(struct vm_impl* vm_impl, __code next(int ret, ...)) {
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
98 ret = 0;
b8597756f701 fix loaduvm loop
tobaru
parents: 218
diff changeset
99 goto next(ret, ...);
206
247aa9ee931c loaduvm_loopvm_impl
tobaru
parents: 205
diff changeset
100 }
211
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 208
diff changeset
101
212
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
102 struct run {
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
103 struct run *next;
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
104 };
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
105
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
106 struct {
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
107 struct spinlock lock;
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
108 struct run* freelist;
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
109 } kpt_mem;
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
110
215
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
111
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
112 static int mappages (pde_t *pgdir, void *va, uint size, uint pa, int ap)
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
113 {
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
114 char *a, *last;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
115 pte_t *pte;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
116
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
117 a = (char*) align_dn(va, PTE_SZ);
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
118 last = (char*) align_dn((uint)va + size - 1, PTE_SZ);
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
119
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
120 for (;;) {
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
121 if ((pte = walkpgdir(pgdir, a, 1)) == 0) {
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
122 return -1;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
123 }
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
124
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
125 if (*pte & PE_TYPES) {
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
126 panic("remap");
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
127 }
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
128
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
129 *pte = pa | ((ap & 0x3) << 4) | PE_CACHE | PE_BUF | PTE_TYPE;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
130
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
131 if (a == last) {
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
132 break;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
133 }
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
134
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
135 a += PTE_SZ;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
136 pa += PTE_SZ;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
137 }
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
138
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
139 return 0;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
140 }
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
141
211
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 208
diff changeset
142 __code kpt_alloc_check_impl(struct vm_impl* vm_impl, __code next(...)) {
212
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
143 struct run* r;
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
144 if ((r = kpt_mem.freelist) != NULL ) {
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
145 kpt_mem.freelist = r->next;
6e03cee9733e can use r
tobaru
parents: 211
diff changeset
146 }
213
f4effd36aefc kpt_alloc
tobaru
parents: 212
diff changeset
147 release(&kpt_mem.lock);
211
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 208
diff changeset
148
213
f4effd36aefc kpt_alloc
tobaru
parents: 212
diff changeset
149 if ((r == NULL) && ((r = kmalloc (PT_ORDER)) == NULL)) {
316
b58517e62ebf use goto panic at vm_impl
anatofuz
parents: 308
diff changeset
150 char* msg = "oom: kpt_alloc";
b58517e62ebf use goto panic at vm_impl
anatofuz
parents: 308
diff changeset
151 struct Err* err = createKernelError(&proc->cbc_context);
b58517e62ebf use goto panic at vm_impl
anatofuz
parents: 308
diff changeset
152 Gearef(cbc_context, Err)->msg = msg;
318
173753022721 s/goto err->panic/goto meta/
anatofuz
parents: 317
diff changeset
153 goto meta(cbc_context, err->panic);
213
f4effd36aefc kpt_alloc
tobaru
parents: 212
diff changeset
154 }
f4effd36aefc kpt_alloc
tobaru
parents: 212
diff changeset
155
f4effd36aefc kpt_alloc
tobaru
parents: 212
diff changeset
156 memset(r, 0, PT_SZ);
211
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 208
diff changeset
157 goto next((char*)r);
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 208
diff changeset
158 }
214
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
159
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
160 __code allocuvm_check_newszvm_impl(struct vm_impl* vm_impl, pde_t* pgdir, uint oldsz, uint newsz, __code next(int ret, ...)){
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
161 if (newsz >= UADDR_SZ) {
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
162 goto next(0, ...);
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
163 }
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
164
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
165 if (newsz < oldsz) {
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
166 ret = newsz;
215
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
167 goto next(ret, ...);
214
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
168 }
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
169
215
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
170 char* mem;
214
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
171 uint a = align_up(oldsz, PTE_SZ);
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
172
215
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
173 goto allocuvm_loopvm_impl(vm_impl, pgdir, oldsz, newsz, mem, a, next(ret, ...));
214
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
174 }
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
175
215
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
176 __code allocuvm_loopvm_impl(struct vm_impl* vm_impl, pde_t* pgdir, uint oldsz, uint newsz, char* mem, uint a, __code next(int ret, ...)){
214
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
177
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
178 if (a < newsz) {
215
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
179 mem = alloc_page();
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
180
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
181 if (mem == 0) {
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
182 cprintf("allocuvm out of memory\n");
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
183 deallocuvm(pgdir, newsz, oldsz);
216
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
184 goto next(0, ...);
215
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
185 }
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
186
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
187 memset(mem, 0, PTE_SZ);
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
188 mappages(pgdir, (char*) a, PTE_SZ, v2p(mem), AP_KU);
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
189
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
190 goto allocuvm_loopvm_impl(vm_impl, pgdir, oldsz, newsz, a + PTE_SZ, next(ret, ...));
214
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
191 }
215
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
192 ret = newsz;
291d4e9304a1 allocuvm_loopvm_imp
tobaru
parents: 214
diff changeset
193 goto next(ret, ...);
214
2ecf1e09e981 allocuvm_loop and return
tobaru
parents: 213
diff changeset
194 }
216
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
195
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
196 __code clearpteu_check_ptevm_impl(struct vm_impl* vm_impl, pde_t* pgdir, char* uva, __code next(int ret, ...)) {
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
197 pte_t *pte;
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
198
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
199 pte = walkpgdir(pgdir, uva, 0);
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
200 if (pte == 0) {
317
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
201 char* msg = "clearpteu";
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
202 struct Err* err = createKernelError(&proc->cbc_context);
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
203 Gearef(cbc_context, Err)->msg = msg;
318
173753022721 s/goto err->panic/goto meta/
anatofuz
parents: 317
diff changeset
204 goto meta(cbc_context, err->panic);
216
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
205 }
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
206
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
207 // in ARM, we change the AP field (ap & 0x3) << 4)
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
208 *pte = (*pte & ~(0x03 << 4)) | AP_KO << 4;
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
209
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
210 goto next(ret, ...);
0f1700bd5cff cleapteu
tobaru
parents: 215
diff changeset
211 }
217
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
212
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
213 __code copyuvm_check_nullvm_impl(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, __code next(int ret, ...)) {
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
214 pde_t *d;
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
215 pte_t *pte;
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
216 uint pa, i, ap;
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
217 char *mem;
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
218
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
219 // allocate a new first level page directory
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
220 d = kpt_alloc();
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
221 if (d == NULL ) {
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
222 ret = NULL;
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
223 goto next(ret, ...);
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
224 }
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
225 i = 0;
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
226
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
227 goto copyuvm_loopvm_impl(vm_impl, pgdir, sz, *d, *pte, pa, i, ap, *mem, next(ret, ...));
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
228 }
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
229
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
230 __code copyuvm_loopvm_impl(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
231
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
232 if (i < sz) {
218
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
233 goto copyuvm_loop_check_walkpgdir(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
217
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
234
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
235 }
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
236 ret = d;
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
237 goto next(ret, ...);
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
238 }
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
239
218
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
240 __code copyuvm_loop_check_walkpgdir(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
241 if ((pte = walkpgdir(pgdir, (void *) i, 0)) == 0) {
317
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
242 char* msg = "copyuvm: pte should exist";
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
243 struct Err* err = createKernelError(&proc->cbc_context);
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
244 Gearef(cbc_context, Err)->msg = msg;
318
173753022721 s/goto err->panic/goto meta/
anatofuz
parents: 317
diff changeset
245 goto meta(cbc_context, err->panic);
218
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
246 }
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
247 goto copyuvm_loop_check_pte(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
248 }
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
249
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
250 __code copyuvm_loop_check_pte(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
251
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
252 if (!(*pte & PE_TYPES)) {
317
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
253 char* msg = "copyuvm: page not present";
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
254 struct Err* err = createKernelError(&proc->cbc_context);
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
255 Gearef(cbc_context, Err)->msg = msg;
318
173753022721 s/goto err->panic/goto meta/
anatofuz
parents: 317
diff changeset
256 goto meta(cbc_context, err->panic);
218
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
257 }
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
258
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
259 goto copyuvm_loop_check_mem(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
260 }
217
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
261
218
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
262 __code copyuvm_loop_check_mem(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
263 pa = PTE_ADDR (*pte);
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
264 ap = PTE_AP (*pte);
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
265
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
266 if ((mem = alloc_page()) == 0) {
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
267 goto copyuvm_loop_bad(vm_impl, d, next(...));
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
268 }
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
269 goto copyuvm_loop_check_mappages(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
270
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
271 }
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
272
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
273 __code copyuvm_loop_check_mappages(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
274
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
275 memmove(mem, (char*) p2v(pa), PTE_SZ);
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
276
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
277 if (mappages(d, (void*) i, PTE_SZ, v2p(mem), ap) < 0) {
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
278 goto copyuvm_loop_bad(vm_impl, d, next(...));
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
279 }
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
280 goto copyuvm_loopvm_impl(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
1c923ae14607 copyuvm
tobaru
parents: 217
diff changeset
281
217
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
282 }
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
283
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
284 __code copyuvm_loop_bad(struct vm_impl* vm_impl, pde_t* d, __code next(int ret, ...)) {
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
285 freevm(d);
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
286 ret = 0;
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
287 goto next(ret, ...);
f940ff602312 copyuvm_loop
tobaru
parents: 216
diff changeset
288 }
220
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
289
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
290
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
291 __code uva2ka_check_pe_types(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(int ret, ...)) {
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
292 pte_t* pte;
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
293
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
294 pte = walkpgdir(pgdir, uva, 0);
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
295
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
296 // make sure it exists
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
297 if ((*pte & PE_TYPES) == 0) {
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
298 ret = 0;
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
299 goto next(ret, ...);
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
300 }
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
301 goto uva2ka_check_pte_ap(vm, pgdir, uva, pte, next(...));
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
302 }
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
303
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
304 __code uva2ka_check_pte_ap(struct vm_impl* vm, pde_t* pgdir, char* uva, pte_t* pte, __code next(int ret, ...)) {
221
098942ff5f44 uva2ka_check_pte_ap
tobaru
parents: 220
diff changeset
305 // make sure it is a user page
098942ff5f44 uva2ka_check_pte_ap
tobaru
parents: 220
diff changeset
306 if (PTE_AP(*pte) != AP_KU) {
098942ff5f44 uva2ka_check_pte_ap
tobaru
parents: 220
diff changeset
307 ret = 0;
098942ff5f44 uva2ka_check_pte_ap
tobaru
parents: 220
diff changeset
308 goto next(ret, ...);
098942ff5f44 uva2ka_check_pte_ap
tobaru
parents: 220
diff changeset
309 }
098942ff5f44 uva2ka_check_pte_ap
tobaru
parents: 220
diff changeset
310 ret = (char*) p2v(PTE_ADDR(*pte));
220
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
311 goto next(ret, ...);
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
312 }
c1d1721fd907 uva2ka_check_pe_types
tobaru
parents: 219
diff changeset
313
222
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
314 // flush all TLB
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
315 static void flush_tlb (void)
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
316 {
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
317 uint val = 0;
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
318 asm("MCR p15, 0, %[r], c8, c7, 0" : :[r]"r" (val):);
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
319
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
320 // invalid entire data and instruction cache
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
321 asm ("MCR p15,0,%[r],c7,c10,0": :[r]"r" (val):);
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
322 asm ("MCR p15,0,%[r],c7,c11,0": :[r]"r" (val):);
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
323 }
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
324
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
325 __code paging_intvmvm_impl(struct vm_impl* vm_impl, uint phy_low, uint phy_hi, __code next(...)) {
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
326 mappages (P2V(&_kernel_pgtbl), P2V(phy_low), phy_hi - phy_low, phy_low, AP_KU);
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
327 flush_tlb ();
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
328
223
90b65036d9a2 paging_init
tobaru
parents: 222
diff changeset
329 goto next(...);
222
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
330 }
7a4d299a35be paging_init
tobaru
parents: 221
diff changeset
331
224
37900976db8e copyout
tobaru
parents: 223
diff changeset
332 __code copyout_loopvm_impl(struct vm_impl* vm_impl, pde_t* pgdir, uint va, void* pp, uint len, uint va0, char* pa0, __code next(int ret, ...)) {
37900976db8e copyout
tobaru
parents: 223
diff changeset
333 if (len > 0) {
37900976db8e copyout
tobaru
parents: 223
diff changeset
334 va0 = align_dn(va, PTE_SZ);
37900976db8e copyout
tobaru
parents: 223
diff changeset
335 pa0 = uva2ka(pgdir, (char*) va0);
37900976db8e copyout
tobaru
parents: 223
diff changeset
336 goto copyout_loop_check_pa0(vm_impl, pgdir, va, pp, len, va0, pa0, n, next(...));
37900976db8e copyout
tobaru
parents: 223
diff changeset
337 }
37900976db8e copyout
tobaru
parents: 223
diff changeset
338 ret = 0;
37900976db8e copyout
tobaru
parents: 223
diff changeset
339 goto next(ret, ...);
223
90b65036d9a2 paging_init
tobaru
parents: 222
diff changeset
340
90b65036d9a2 paging_init
tobaru
parents: 222
diff changeset
341 }
90b65036d9a2 paging_init
tobaru
parents: 222
diff changeset
342
224
37900976db8e copyout
tobaru
parents: 223
diff changeset
343 __code copyout_loop_check_pa0(struct vm_impl* vm_impl, pde_t* pgdir, uint va, void* pp, uint len, uint va0, char* pa0, uint n, __code next(int ret, ...)) {
37900976db8e copyout
tobaru
parents: 223
diff changeset
344 if (pa0 == 0) {
37900976db8e copyout
tobaru
parents: 223
diff changeset
345 ret = -1;
37900976db8e copyout
tobaru
parents: 223
diff changeset
346 goto next(ret, ...);
37900976db8e copyout
tobaru
parents: 223
diff changeset
347 }
37900976db8e copyout
tobaru
parents: 223
diff changeset
348 goto copyout_loop_check_n(vm_impl, pgdir, va, pp, len, va0, pa0, n, buf, next(...));
37900976db8e copyout
tobaru
parents: 223
diff changeset
349 }
37900976db8e copyout
tobaru
parents: 223
diff changeset
350 __code copyout_loop_check_n(struct vm_impl* vm_impl, pde_t* pgdir, uint va, void* pp, uint len, uint va0, char* pa0, uint n, char* buf, __code next(...)) {
37900976db8e copyout
tobaru
parents: 223
diff changeset
351 n = PTE_SZ - (va - va0);
223
90b65036d9a2 paging_init
tobaru
parents: 222
diff changeset
352
224
37900976db8e copyout
tobaru
parents: 223
diff changeset
353 if (n > len) {
37900976db8e copyout
tobaru
parents: 223
diff changeset
354 n = len;
37900976db8e copyout
tobaru
parents: 223
diff changeset
355 }
37900976db8e copyout
tobaru
parents: 223
diff changeset
356
37900976db8e copyout
tobaru
parents: 223
diff changeset
357 len -= n;
37900976db8e copyout
tobaru
parents: 223
diff changeset
358 buf += n;
37900976db8e copyout
tobaru
parents: 223
diff changeset
359 va = va0 + PTE_SZ;
308
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
360 Gearef(cbc_context, vm_impl)->n = n;
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
361 Gearef(cbc_context, vm_impl)->len = len;
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
362 Gearef(cbc_context, vm_impl)->buf = buf;
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
363 Gearef(cbc_context, vm_impl)->va = va;
50fd5d414066 add write back context at vm_impl_private
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 306
diff changeset
364
224
37900976db8e copyout
tobaru
parents: 223
diff changeset
365 goto copyout_loopvm_impl(vm_impl, pgdir, va, pp, len, va0, pa0, next(...));
37900976db8e copyout
tobaru
parents: 223
diff changeset
366 }
37900976db8e copyout
tobaru
parents: 223
diff changeset
367
226
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
368 typedef struct proc proc_struct;
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
369 __code switchuvm_check_pgdirvm_impl(struct vm_impl* vm_impl, proc_struct* p, __code next(...)) { //:skip
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
370 uint val;
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
371
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
372 pushcli();
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
373
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
374 if (p->pgdir == 0) {
317
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
375 char* msg = "switchuvm: no pgdir";
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
376 struct Err* err = createKernelError(&proc->cbc_context);
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
377 Gearef(cbc_context, Err)->msg = msg;
318
173753022721 s/goto err->panic/goto meta/
anatofuz
parents: 317
diff changeset
378 goto meta(cbc_context, err->panic);
226
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
379 }
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
380
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
381 val = (uint) V2P(p->pgdir) | 0x00;
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
382
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
383 asm("MCR p15, 0, %[v], c2, c0, 0": :[v]"r" (val):);
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
384 flush_tlb();
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
385
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
386 popcli();
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
387
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
388 goto next(...);
415081e357ec switchuvm_check_pgdirvm_impl
tobaru
parents: 224
diff changeset
389 }
227
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
390
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
391 __code init_inituvm_check_sz(struct vm_impl* vm_impl, pde_t* pgdir, char* init, uint sz, __code next(...)) {
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
392 char* mem;
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
393
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
394 if (sz >= PTE_SZ) {
317
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
395 char* msg = "inituvm: more than a page";
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
396 struct Err* err = createKernelError(&proc->cbc_context);
d1dfc4af40d7 use goto panic
anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
parents: 316
diff changeset
397 Gearef(cbc_context, Err)->msg = msg;
318
173753022721 s/goto err->panic/goto meta/
anatofuz
parents: 317
diff changeset
398 goto meta(cbc_context, err->panic);
227
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
399 }
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
400
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
401 mem = alloc_page();
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
402 memset(mem, 0, PTE_SZ);
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
403 mappages(pgdir, 0, PTE_SZ, v2p(mem), AP_KU);
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
404 memmove(mem, init, sz);
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
405
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
406 goto next(...);
80398e02ae72 init_inituvm
tobaru
parents: 226
diff changeset
407 }
269
bd948528b2d6 impl_vm_void_ret
anatofuz
parents: 227
diff changeset
408