annotate src/impl/vm_impl_private.cbc @ 395:17e8a4bc06a7 default tip

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