Rev 822 | Rev 840 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 822 | Rev 823 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2001-2006 Jakub Jermar |
2 | * Copyright (C) 2001-2006 Jakub Jermar |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /* |
29 | /* |
30 | * This file contains address space manipulation functions. |
30 | * This file contains address space manipulation functions. |
31 | * Roughly speaking, this is a higher-level client of |
31 | * Roughly speaking, this is a higher-level client of |
32 | * Virtual Address Translation (VAT) subsystem. |
32 | * Virtual Address Translation (VAT) subsystem. |
33 | */ |
33 | */ |
34 | 34 | ||
35 | #include <mm/as.h> |
35 | #include <mm/as.h> |
36 | #include <arch/mm/as.h> |
36 | #include <arch/mm/as.h> |
37 | #include <mm/page.h> |
37 | #include <mm/page.h> |
38 | #include <mm/frame.h> |
38 | #include <mm/frame.h> |
39 | #include <mm/slab.h> |
39 | #include <mm/slab.h> |
40 | #include <mm/tlb.h> |
40 | #include <mm/tlb.h> |
41 | #include <arch/mm/page.h> |
41 | #include <arch/mm/page.h> |
42 | #include <genarch/mm/page_pt.h> |
42 | #include <genarch/mm/page_pt.h> |
43 | #include <mm/asid.h> |
43 | #include <mm/asid.h> |
44 | #include <arch/mm/asid.h> |
44 | #include <arch/mm/asid.h> |
45 | #include <arch/types.h> |
45 | #include <arch/types.h> |
46 | #include <typedefs.h> |
46 | #include <typedefs.h> |
47 | #include <synch/spinlock.h> |
47 | #include <synch/spinlock.h> |
48 | #include <config.h> |
48 | #include <config.h> |
49 | #include <adt/list.h> |
49 | #include <adt/list.h> |
50 | #include <panic.h> |
50 | #include <panic.h> |
51 | #include <arch/asm.h> |
51 | #include <arch/asm.h> |
52 | #include <debug.h> |
52 | #include <debug.h> |
53 | #include <memstr.h> |
53 | #include <memstr.h> |
54 | #include <arch.h> |
54 | #include <arch.h> |
55 | #include <print.h> |
55 | #include <print.h> |
56 | 56 | ||
57 | as_operations_t *as_operations = NULL; |
57 | as_operations_t *as_operations = NULL; |
58 | 58 | ||
- | 59 | /** Address space lock. It protects inactive_as_with_asid_head. */ |
|
- | 60 | SPINLOCK_INITIALIZE(as_lock); |
|
- | 61 | ||
- | 62 | /** |
|
- | 63 | * This list contains address spaces that are not active on any |
|
- | 64 | * processor and that have valid ASID. |
|
- | 65 | */ |
|
- | 66 | LIST_INITIALIZE(inactive_as_with_asid_head); |
|
- | 67 | ||
59 | /** Kernel address space. */ |
68 | /** Kernel address space. */ |
60 | as_t *AS_KERNEL = NULL; |
69 | as_t *AS_KERNEL = NULL; |
61 | 70 | ||
62 | static int get_area_flags(as_area_t *a); |
71 | static int get_area_flags(as_area_t *a); |
63 | 72 | ||
64 | /** Initialize address space subsystem. */ |
73 | /** Initialize address space subsystem. */ |
65 | void as_init(void) |
74 | void as_init(void) |
66 | { |
75 | { |
67 | as_arch_init(); |
76 | as_arch_init(); |
68 | AS_KERNEL = as_create(FLAG_AS_KERNEL); |
77 | AS_KERNEL = as_create(FLAG_AS_KERNEL); |
69 | if (!AS_KERNEL) |
78 | if (!AS_KERNEL) |
70 | panic("can't create kernel address space\n"); |
79 | panic("can't create kernel address space\n"); |
71 | } |
80 | } |
72 | 81 | ||
73 | /** Create address space. |
82 | /** Create address space. |
74 | * |
83 | * |
75 | * @param flags Flags that influence way in wich the address space is created. |
84 | * @param flags Flags that influence way in wich the address space is created. |
76 | */ |
85 | */ |
77 | as_t *as_create(int flags) |
86 | as_t *as_create(int flags) |
78 | { |
87 | { |
79 | as_t *as; |
88 | as_t *as; |
80 | 89 | ||
81 | as = (as_t *) malloc(sizeof(as_t), 0); |
90 | as = (as_t *) malloc(sizeof(as_t), 0); |
82 | - | ||
83 | list_initialize(&as->as_with_asid_link); |
91 | link_initialize(&as->inactive_as_with_asid_link); |
84 | spinlock_initialize(&as->lock, "as_lock"); |
92 | spinlock_initialize(&as->lock, "as_lock"); |
85 | list_initialize(&as->as_area_head); |
93 | list_initialize(&as->as_area_head); |
86 | 94 | ||
87 | if (flags & FLAG_AS_KERNEL) |
95 | if (flags & FLAG_AS_KERNEL) |
88 | as->asid = ASID_KERNEL; |
96 | as->asid = ASID_KERNEL; |
89 | else |
97 | else |
90 | as->asid = ASID_INVALID; |
98 | as->asid = ASID_INVALID; |
91 | 99 | ||
- | 100 | as->refcount = 0; |
|
92 | as->page_table = page_table_create(flags); |
101 | as->page_table = page_table_create(flags); |
93 | 102 | ||
94 | return as; |
103 | return as; |
95 | } |
104 | } |
96 | 105 | ||
97 | /** Create address space area of common attributes. |
106 | /** Create address space area of common attributes. |
98 | * |
107 | * |
99 | * The created address space area is added to the target address space. |
108 | * The created address space area is added to the target address space. |
100 | * |
109 | * |
101 | * @param as Target address space. |
110 | * @param as Target address space. |
102 | * @param type Type of area. |
111 | * @param type Type of area. |
103 | * @param size Size of area in multiples of PAGE_SIZE. |
112 | * @param size Size of area in multiples of PAGE_SIZE. |
104 | * @param base Base address of area. |
113 | * @param base Base address of area. |
105 | * |
114 | * |
106 | * @return Address space area on success or NULL on failure. |
115 | * @return Address space area on success or NULL on failure. |
107 | */ |
116 | */ |
108 | as_area_t *as_area_create(as_t *as, as_area_type_t type, size_t size, __address base) |
117 | as_area_t *as_area_create(as_t *as, as_area_type_t type, size_t size, __address base) |
109 | { |
118 | { |
110 | ipl_t ipl; |
119 | ipl_t ipl; |
111 | as_area_t *a; |
120 | as_area_t *a; |
112 | 121 | ||
113 | if (base % PAGE_SIZE) |
122 | if (base % PAGE_SIZE) |
114 | panic("addr not aligned to a page boundary"); |
123 | panic("addr not aligned to a page boundary"); |
115 | 124 | ||
116 | ipl = interrupts_disable(); |
125 | ipl = interrupts_disable(); |
117 | spinlock_lock(&as->lock); |
126 | spinlock_lock(&as->lock); |
118 | 127 | ||
119 | /* |
128 | /* |
120 | * TODO: test as_area which is to be created doesn't overlap with an existing one. |
129 | * TODO: test as_area which is to be created doesn't overlap with an existing one. |
121 | */ |
130 | */ |
122 | 131 | ||
123 | a = (as_area_t *) malloc(sizeof(as_area_t), 0); |
132 | a = (as_area_t *) malloc(sizeof(as_area_t), 0); |
124 | 133 | ||
125 | spinlock_initialize(&a->lock, "as_area_lock"); |
134 | spinlock_initialize(&a->lock, "as_area_lock"); |
126 | 135 | ||
127 | link_initialize(&a->link); |
136 | link_initialize(&a->link); |
128 | a->type = type; |
137 | a->type = type; |
129 | a->size = size; |
138 | a->size = size; |
130 | a->base = base; |
139 | a->base = base; |
131 | 140 | ||
132 | list_append(&a->link, &as->as_area_head); |
141 | list_append(&a->link, &as->as_area_head); |
133 | 142 | ||
134 | spinlock_unlock(&as->lock); |
143 | spinlock_unlock(&as->lock); |
135 | interrupts_restore(ipl); |
144 | interrupts_restore(ipl); |
136 | 145 | ||
137 | return a; |
146 | return a; |
138 | } |
147 | } |
139 | 148 | ||
140 | /** Initialize mapping for one page of address space. |
149 | /** Initialize mapping for one page of address space. |
141 | * |
150 | * |
142 | * This functions maps 'page' to 'frame' according |
151 | * This functions maps 'page' to 'frame' according |
143 | * to attributes of the address space area to |
152 | * to attributes of the address space area to |
144 | * wich 'page' belongs. |
153 | * wich 'page' belongs. |
145 | * |
154 | * |
146 | * @param a Target address space. |
155 | * @param a Target address space. |
147 | * @param page Virtual page within the area. |
156 | * @param page Virtual page within the area. |
148 | * @param frame Physical frame to which page will be mapped. |
157 | * @param frame Physical frame to which page will be mapped. |
149 | */ |
158 | */ |
150 | void as_set_mapping(as_t *as, __address page, __address frame) |
159 | void as_set_mapping(as_t *as, __address page, __address frame) |
151 | { |
160 | { |
152 | as_area_t *a, *area = NULL; |
161 | as_area_t *a, *area = NULL; |
153 | link_t *cur; |
162 | link_t *cur; |
154 | ipl_t ipl; |
163 | ipl_t ipl; |
155 | 164 | ||
156 | ipl = interrupts_disable(); |
165 | ipl = interrupts_disable(); |
157 | spinlock_lock(&as->lock); |
166 | spinlock_lock(&as->lock); |
158 | 167 | ||
159 | /* |
168 | /* |
160 | * First, try locate an area. |
169 | * First, try locate an area. |
161 | */ |
170 | */ |
162 | for (cur = as->as_area_head.next; cur != &as->as_area_head; cur = cur->next) { |
171 | for (cur = as->as_area_head.next; cur != &as->as_area_head; cur = cur->next) { |
163 | a = list_get_instance(cur, as_area_t, link); |
172 | a = list_get_instance(cur, as_area_t, link); |
164 | spinlock_lock(&a->lock); |
173 | spinlock_lock(&a->lock); |
165 | 174 | ||
166 | if ((page >= a->base) && (page < a->base + a->size * PAGE_SIZE)) { |
175 | if ((page >= a->base) && (page < a->base + a->size * PAGE_SIZE)) { |
167 | area = a; |
176 | area = a; |
168 | break; |
177 | break; |
169 | } |
178 | } |
170 | 179 | ||
171 | spinlock_unlock(&a->lock); |
180 | spinlock_unlock(&a->lock); |
172 | } |
181 | } |
173 | 182 | ||
174 | if (!area) { |
183 | if (!area) { |
175 | panic("page not part of any as_area\n"); |
184 | panic("page not part of any as_area\n"); |
176 | } |
185 | } |
177 | 186 | ||
178 | /* |
187 | /* |
179 | * Note: area->lock is held. |
188 | * Note: area->lock is held. |
180 | */ |
189 | */ |
181 | 190 | ||
182 | page_mapping_insert(as, page, frame, get_area_flags(area)); |
191 | page_mapping_insert(as, page, frame, get_area_flags(area)); |
183 | 192 | ||
184 | spinlock_unlock(&area->lock); |
193 | spinlock_unlock(&area->lock); |
185 | spinlock_unlock(&as->lock); |
194 | spinlock_unlock(&as->lock); |
186 | interrupts_restore(ipl); |
195 | interrupts_restore(ipl); |
187 | } |
196 | } |
188 | 197 | ||
189 | /** Handle page fault within the current address space. |
198 | /** Handle page fault within the current address space. |
190 | * |
199 | * |
191 | * This is the high-level page fault handler. |
200 | * This is the high-level page fault handler. |
192 | * Interrupts are assumed disabled. |
201 | * Interrupts are assumed disabled. |
193 | * |
202 | * |
194 | * @param page Faulting page. |
203 | * @param page Faulting page. |
195 | * |
204 | * |
196 | * @return 0 on page fault, 1 on success. |
205 | * @return 0 on page fault, 1 on success. |
197 | */ |
206 | */ |
198 | int as_page_fault(__address page) |
207 | int as_page_fault(__address page) |
199 | { |
208 | { |
200 | link_t *cur; |
209 | link_t *cur; |
201 | as_area_t *a, *area = NULL; |
210 | as_area_t *a, *area = NULL; |
202 | __address frame; |
211 | __address frame; |
203 | 212 | ||
204 | ASSERT(AS); |
213 | ASSERT(AS); |
205 | spinlock_lock(&AS->lock); |
214 | spinlock_lock(&AS->lock); |
206 | 215 | ||
207 | /* |
216 | /* |
208 | * Search this areas of this address space for presence of 'page'. |
217 | * Search this areas of this address space for presence of 'page'. |
209 | */ |
218 | */ |
210 | for (cur = AS->as_area_head.next; cur != &AS->as_area_head; cur = cur->next) { |
219 | for (cur = AS->as_area_head.next; cur != &AS->as_area_head; cur = cur->next) { |
211 | a = list_get_instance(cur, as_area_t, link); |
220 | a = list_get_instance(cur, as_area_t, link); |
212 | spinlock_lock(&a->lock); |
221 | spinlock_lock(&a->lock); |
213 | 222 | ||
214 | if ((page >= a->base) && (page < a->base + a->size * PAGE_SIZE)) { |
223 | if ((page >= a->base) && (page < a->base + a->size * PAGE_SIZE)) { |
215 | 224 | ||
216 | /* |
225 | /* |
217 | * We found the area containing 'page'. |
226 | * We found the area containing 'page'. |
218 | * TODO: access checking |
227 | * TODO: access checking |
219 | */ |
228 | */ |
220 | area = a; |
229 | area = a; |
221 | break; |
230 | break; |
222 | } |
231 | } |
223 | 232 | ||
224 | spinlock_unlock(&a->lock); |
233 | spinlock_unlock(&a->lock); |
225 | } |
234 | } |
226 | 235 | ||
227 | if (!area) { |
236 | if (!area) { |
228 | /* |
237 | /* |
229 | * No area contained mapping for 'page'. |
238 | * No area contained mapping for 'page'. |
230 | * Signal page fault to low-level handler. |
239 | * Signal page fault to low-level handler. |
231 | */ |
240 | */ |
232 | spinlock_unlock(&AS->lock); |
241 | spinlock_unlock(&AS->lock); |
233 | return 0; |
242 | return 0; |
234 | } |
243 | } |
235 | 244 | ||
236 | /* |
245 | /* |
237 | * Note: area->lock is held. |
246 | * Note: area->lock is held. |
238 | */ |
247 | */ |
239 | 248 | ||
240 | /* |
249 | /* |
241 | * In general, there can be several reasons that |
250 | * In general, there can be several reasons that |
242 | * can have caused this fault. |
251 | * can have caused this fault. |
243 | * |
252 | * |
244 | * - non-existent mapping: the area is a scratch |
253 | * - non-existent mapping: the area is a scratch |
245 | * area (e.g. stack) and so far has not been |
254 | * area (e.g. stack) and so far has not been |
246 | * allocated a frame for the faulting page |
255 | * allocated a frame for the faulting page |
247 | * |
256 | * |
248 | * - non-present mapping: another possibility, |
257 | * - non-present mapping: another possibility, |
249 | * currently not implemented, would be frame |
258 | * currently not implemented, would be frame |
250 | * reuse; when this becomes a possibility, |
259 | * reuse; when this becomes a possibility, |
251 | * do not forget to distinguish between |
260 | * do not forget to distinguish between |
252 | * the different causes |
261 | * the different causes |
253 | */ |
262 | */ |
254 | frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0)); |
263 | frame = PFN2ADDR(frame_alloc(ONE_FRAME, 0)); |
255 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
264 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
256 | 265 | ||
257 | /* |
266 | /* |
258 | * Map 'page' to 'frame'. |
267 | * Map 'page' to 'frame'. |
259 | * Note that TLB shootdown is not attempted as only new information is being |
268 | * Note that TLB shootdown is not attempted as only new information is being |
260 | * inserted into page tables. |
269 | * inserted into page tables. |
261 | */ |
270 | */ |
262 | page_mapping_insert(AS, page, frame, get_area_flags(area)); |
271 | page_mapping_insert(AS, page, frame, get_area_flags(area)); |
263 | 272 | ||
264 | spinlock_unlock(&area->lock); |
273 | spinlock_unlock(&area->lock); |
265 | spinlock_unlock(&AS->lock); |
274 | spinlock_unlock(&AS->lock); |
266 | 275 | ||
267 | return 1; |
276 | return 1; |
268 | } |
277 | } |
269 | 278 | ||
270 | /** Install address space on CPU. |
279 | /** Switch address spaces. |
271 | * |
280 | * |
- | 281 | * @param old Old address space or NULL. |
|
272 | * @param as Address space. |
282 | * @param new New address space. |
273 | */ |
283 | */ |
274 | void as_install(as_t *as) |
284 | void as_switch(as_t *old, as_t *new) |
275 | { |
285 | { |
276 | ipl_t ipl; |
286 | ipl_t ipl; |
277 | - | ||
278 | asid_install(as); |
287 | bool needs_asid = false; |
279 | 288 | ||
280 | ipl = interrupts_disable(); |
289 | ipl = interrupts_disable(); |
281 | spinlock_lock(&as->lock); |
290 | spinlock_lock(&as_lock); |
- | 291 | ||
- | 292 | /* |
|
- | 293 | * First, take care of the old address space. |
|
- | 294 | */ |
|
- | 295 | if (old) { |
|
- | 296 | spinlock_lock(&old->lock); |
|
- | 297 | ASSERT(old->refcount); |
|
- | 298 | if((--old->refcount == 0) && (old != AS_KERNEL)) { |
|
- | 299 | /* |
|
- | 300 | * The old address space is no longer active on |
|
- | 301 | * any processor. It can be appended to the |
|
- | 302 | * list of inactive address spaces with assigned |
|
- | 303 | * ASID. |
|
- | 304 | */ |
|
- | 305 | ASSERT(old->asid != ASID_INVALID); |
|
- | 306 | list_append(&old->inactive_as_with_asid_link, &inactive_as_with_asid_head); |
|
- | 307 | } |
|
- | 308 | spinlock_unlock(&old->lock); |
|
- | 309 | } |
|
- | 310 | ||
- | 311 | /* |
|
- | 312 | * Second, prepare the new address space. |
|
- | 313 | */ |
|
- | 314 | spinlock_lock(&new->lock); |
|
- | 315 | if ((new->refcount++ == 0) && (new != AS_KERNEL)) { |
|
- | 316 | if (new->asid != ASID_INVALID) |
|
- | 317 | list_remove(&new->inactive_as_with_asid_link); |
|
- | 318 | else |
|
- | 319 | needs_asid = true; /* defer call to asid_get() until new->lock is released */ |
|
- | 320 | } |
|
282 | SET_PTL0_ADDRESS(as->page_table); |
321 | SET_PTL0_ADDRESS(new->page_table); |
- | 322 | spinlock_unlock(&new->lock); |
|
- | 323 | ||
- | 324 | if (needs_asid) { |
|
- | 325 | /* |
|
- | 326 | * Allocation of new ASID was deferred |
|
- | 327 | * until now in order to avoid deadlock. |
|
- | 328 | */ |
|
- | 329 | asid_t asid; |
|
- | 330 | ||
- | 331 | asid = asid_get(); |
|
- | 332 | spinlock_lock(&new->lock); |
|
- | 333 | new->asid = asid; |
|
- | 334 | spinlock_unlock(&new->lock); |
|
- | 335 | } |
|
283 | spinlock_unlock(&as->lock); |
336 | spinlock_unlock(&as_lock); |
284 | interrupts_restore(ipl); |
337 | interrupts_restore(ipl); |
285 | 338 | ||
286 | /* |
339 | /* |
287 | * Perform architecture-specific steps. |
340 | * Perform architecture-specific steps. |
288 | * (e.g. write ASID to hardware register etc.) |
341 | * (e.g. write ASID to hardware register etc.) |
289 | */ |
342 | */ |
290 | as_install_arch(as); |
343 | as_install_arch(new); |
291 | 344 | ||
292 | AS = as; |
345 | AS = new; |
293 | } |
346 | } |
294 | 347 | ||
295 | /** Compute flags for virtual address translation subsytem. |
348 | /** Compute flags for virtual address translation subsytem. |
296 | * |
349 | * |
297 | * The address space area must be locked. |
350 | * The address space area must be locked. |
298 | * Interrupts must be disabled. |
351 | * Interrupts must be disabled. |
299 | * |
352 | * |
300 | * @param a Address space area. |
353 | * @param a Address space area. |
301 | * |
354 | * |
302 | * @return Flags to be used in page_mapping_insert(). |
355 | * @return Flags to be used in page_mapping_insert(). |
303 | */ |
356 | */ |
304 | int get_area_flags(as_area_t *a) |
357 | int get_area_flags(as_area_t *a) |
305 | { |
358 | { |
306 | int flags; |
359 | int flags; |
307 | 360 | ||
308 | switch (a->type) { |
361 | switch (a->type) { |
309 | case AS_AREA_TEXT: |
362 | case AS_AREA_TEXT: |
310 | flags = PAGE_EXEC | PAGE_READ | PAGE_USER | PAGE_PRESENT | PAGE_CACHEABLE; |
363 | flags = PAGE_EXEC | PAGE_READ | PAGE_USER | PAGE_PRESENT | PAGE_CACHEABLE; |
311 | break; |
364 | break; |
312 | case AS_AREA_DATA: |
365 | case AS_AREA_DATA: |
313 | case AS_AREA_STACK: |
366 | case AS_AREA_STACK: |
314 | flags = PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_PRESENT | PAGE_CACHEABLE; |
367 | flags = PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_PRESENT | PAGE_CACHEABLE; |
315 | break; |
368 | break; |
316 | default: |
369 | default: |
317 | panic("unexpected as_area_type_t %d", a->type); |
370 | panic("unexpected as_area_type_t %d", a->type); |
318 | } |
371 | } |
319 | 372 | ||
320 | return flags; |
373 | return flags; |
321 | } |
374 | } |
322 | 375 | ||
323 | /** Create page table. |
376 | /** Create page table. |
324 | * |
377 | * |
325 | * Depending on architecture, create either address space |
378 | * Depending on architecture, create either address space |
326 | * private or global page table. |
379 | * private or global page table. |
327 | * |
380 | * |
328 | * @param flags Flags saying whether the page table is for kernel address space. |
381 | * @param flags Flags saying whether the page table is for kernel address space. |
329 | * |
382 | * |
330 | * @return First entry of the page table. |
383 | * @return First entry of the page table. |
331 | */ |
384 | */ |
332 | pte_t *page_table_create(int flags) |
385 | pte_t *page_table_create(int flags) |
333 | { |
386 | { |
334 | ASSERT(as_operations); |
387 | ASSERT(as_operations); |
335 | ASSERT(as_operations->page_table_create); |
388 | ASSERT(as_operations->page_table_create); |
336 | 389 | ||
337 | return as_operations->page_table_create(flags); |
390 | return as_operations->page_table_create(flags); |
338 | } |
391 | } |
339 | 392 |