Rev 755 | Rev 757 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 755 | Rev 756 | ||
---|---|---|---|
Line 31... | Line 31... | ||
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 <mm/asid.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/tlb.h> |
39 | #include <mm/tlb.h> |
40 | #include <mm/heap.h> |
40 | #include <mm/heap.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/mm/as.h> |
- | |
46 | #include <arch/types.h> |
45 | #include <arch/types.h> |
47 | #include <typedefs.h> |
46 | #include <typedefs.h> |
48 | #include <synch/spinlock.h> |
47 | #include <synch/spinlock.h> |
49 | #include <config.h> |
48 | #include <config.h> |
50 | #include <list.h> |
49 | #include <list.h> |
Line 53... | Line 52... | ||
53 | #include <debug.h> |
52 | #include <debug.h> |
54 | #include <memstr.h> |
53 | #include <memstr.h> |
55 | #include <arch.h> |
54 | #include <arch.h> |
56 | #include <print.h> |
55 | #include <print.h> |
57 | 56 | ||
58 | #define KAS_START_INDEX PTL0_INDEX(KERNEL_ADDRESS_SPACE_START) |
- | |
59 | #define KAS_END_INDEX PTL0_INDEX(KERNEL_ADDRESS_SPACE_END) |
- | |
60 | #define KAS_INDICES (1+(KAS_END_INDEX-KAS_START_INDEX)) |
57 | as_operations_t *as_operations = NULL; |
61 | 58 | ||
62 | static int get_area_flags(as_area_t *a); |
59 | static int get_area_flags(as_area_t *a); |
63 | 60 | ||
- | 61 | /** Initialize address space subsystem. */ |
|
- | 62 | void as_init(void) |
|
- | 63 | { |
|
- | 64 | as_arch_init(); |
|
- | 65 | AS_KERNEL = as_create(FLAG_AS_KERNEL); |
|
- | 66 | if (!AS_KERNEL) |
|
- | 67 | panic("can't create kernel address space\n"); |
|
- | 68 | } |
|
- | 69 | ||
64 | /** Create address space. */ |
70 | /** Create address space. */ |
65 | /* |
- | |
66 | * FIXME: this interface must be meaningful for all possible VAT |
- | |
67 | * (Virtual Address Translation) mechanisms. |
- | |
68 | */ |
- | |
69 | as_t *as_create(pte_t *ptl0, int flags) |
71 | as_t *as_create(int flags) |
70 | { |
72 | { |
71 | as_t *as; |
73 | as_t *as; |
72 | 74 | ||
73 | as = (as_t *) malloc(sizeof(as_t)); |
75 | as = (as_t *) malloc(sizeof(as_t)); |
74 | if (as) { |
76 | if (as) { |
Line 79... | Line 81... | ||
79 | if (flags & FLAG_AS_KERNEL) |
81 | if (flags & FLAG_AS_KERNEL) |
80 | as->asid = ASID_KERNEL; |
82 | as->asid = ASID_KERNEL; |
81 | else |
83 | else |
82 | as->asid = ASID_INVALID; |
84 | as->asid = ASID_INVALID; |
83 | 85 | ||
84 | as->ptl0 = ptl0; |
- | |
85 | if (!as->ptl0) { |
- | |
86 | pte_t *src_ptl0, *dst_ptl0; |
- | |
87 | - | ||
88 | src_ptl0 = (pte_t *) PA2KA((__address) GET_PTL0_ADDRESS()); |
- | |
89 | dst_ptl0 = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL); |
- | |
90 | - | ||
91 | // memsetb((__address) dst_ptl0, PAGE_SIZE, 0); |
- | |
92 | // memcpy((void *) &dst_ptl0[KAS_START_INDEX], (void *) &src_ptl0[KAS_START_INDEX], KAS_INDICES); |
- | |
93 | - | ||
94 | memcpy((void *) dst_ptl0,(void *) src_ptl0, PAGE_SIZE); |
- | |
95 | - | ||
96 | as->ptl0 = (pte_t *) KA2PA((__address) dst_ptl0); |
86 | as->page_table = page_table_create(flags); |
97 | } |
- | |
98 | } |
87 | } |
99 | 88 | ||
100 | return as; |
89 | return as; |
101 | } |
90 | } |
102 | 91 | ||
Line 184... | Line 173... | ||
184 | 173 | ||
185 | /* |
174 | /* |
186 | * Note: area->lock is held. |
175 | * Note: area->lock is held. |
187 | */ |
176 | */ |
188 | 177 | ||
189 | page_mapping_insert(as, page, frame, get_area_flags(area), (__address) as->ptl0); |
178 | page_mapping_insert(as, page, frame, get_area_flags(area)); |
190 | 179 | ||
191 | spinlock_unlock(&area->lock); |
180 | spinlock_unlock(&area->lock); |
192 | spinlock_unlock(&as->lock); |
181 | spinlock_unlock(&as->lock); |
193 | interrupts_restore(ipl); |
182 | interrupts_restore(ipl); |
194 | } |
183 | } |
Line 264... | Line 253... | ||
264 | /* |
253 | /* |
265 | * Map 'page' to 'frame'. |
254 | * Map 'page' to 'frame'. |
266 | * Note that TLB shootdown is not attempted as only new information is being |
255 | * Note that TLB shootdown is not attempted as only new information is being |
267 | * inserted into page tables. |
256 | * inserted into page tables. |
268 | */ |
257 | */ |
269 | page_mapping_insert(AS, page, frame, get_area_flags(area), (__address) AS->ptl0); |
258 | page_mapping_insert(AS, page, frame, get_area_flags(area)); |
270 | 259 | ||
271 | spinlock_unlock(&area->lock); |
260 | spinlock_unlock(&area->lock); |
272 | spinlock_unlock(&AS->lock); |
261 | spinlock_unlock(&AS->lock); |
273 | 262 | ||
274 | return 1; |
263 | return 1; |
Line 284... | Line 273... | ||
284 | 273 | ||
285 | asid_install(as); |
274 | asid_install(as); |
286 | 275 | ||
287 | ipl = interrupts_disable(); |
276 | ipl = interrupts_disable(); |
288 | spinlock_lock(&as->lock); |
277 | spinlock_lock(&as->lock); |
289 | ASSERT(as->ptl0); |
278 | ASSERT(as->page_table); |
290 | SET_PTL0_ADDRESS(as->ptl0); |
279 | SET_PTL0_ADDRESS(as->page_table); |
291 | spinlock_unlock(&as->lock); |
280 | spinlock_unlock(&as->lock); |
292 | interrupts_restore(ipl); |
281 | interrupts_restore(ipl); |
293 | 282 | ||
294 | /* |
283 | /* |
295 | * Perform architecture-specific steps. |
284 | * Perform architecture-specific steps. |
Line 325... | Line 314... | ||
325 | panic("unexpected as_area_type_t %d", a->type); |
314 | panic("unexpected as_area_type_t %d", a->type); |
326 | } |
315 | } |
327 | 316 | ||
328 | return flags; |
317 | return flags; |
329 | } |
318 | } |
- | 319 | ||
- | 320 | /** Create page table. |
|
- | 321 | * |
|
- | 322 | * Depending on architecture, create either address space |
|
- | 323 | * private or global page table. |
|
- | 324 | * |
|
- | 325 | * @param flags Flags saying whether the page table is for kernel address space. |
|
- | 326 | * |
|
- | 327 | * @return First entry of the page table. |
|
- | 328 | */ |
|
- | 329 | pte_t *page_table_create(int flags) |
|
- | 330 | { |
|
- | 331 | ASSERT(as_operations); |
|
- | 332 | ASSERT(as_operations->page_table_create); |
|
- | 333 | ||
- | 334 | return as_operations->page_table_create(flags); |
|
- | 335 | } |