Rev 703 | Rev 711 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 703 | Rev 704 | ||
---|---|---|---|
Line 56... | Line 56... | ||
56 | #define KAS_START_INDEX PTL0_INDEX(KERNEL_ADDRESS_SPACE_START) |
56 | #define KAS_START_INDEX PTL0_INDEX(KERNEL_ADDRESS_SPACE_START) |
57 | #define KAS_END_INDEX PTL0_INDEX(KERNEL_ADDRESS_SPACE_END) |
57 | #define KAS_END_INDEX PTL0_INDEX(KERNEL_ADDRESS_SPACE_END) |
58 | #define KAS_INDICES (1+(KAS_END_INDEX-KAS_START_INDEX)) |
58 | #define KAS_INDICES (1+(KAS_END_INDEX-KAS_START_INDEX)) |
59 | 59 | ||
60 | /* |
60 | /* |
61 | * Here we assume that PFN (Physical Frame Numbers) space |
61 | * Here we assume that PFN (Physical Frame Number) space |
62 | * is smaller than the width of index_t. UNALLOCATED_PFN |
62 | * is smaller than the width of index_t. UNALLOCATED_PFN |
63 | * can be then used to mark mappings wich were not |
63 | * can be then used to mark mappings wich were not |
64 | * allocated a physical frame. |
64 | * yet allocated a physical frame. |
65 | */ |
65 | */ |
66 | #define UNALLOCATED_PFN ((index_t) -1) |
66 | #define UNALLOCATED_PFN ((index_t) -1) |
67 | 67 | ||
68 | /** Create address space. */ |
68 | /** Create address space. */ |
69 | /* |
69 | /* |
Line 139... | Line 139... | ||
139 | } |
139 | } |
140 | 140 | ||
141 | for (i=0; i<size; i++) { |
141 | for (i=0; i<size; i++) { |
142 | /* |
142 | /* |
143 | * Frames will be allocated on-demand by |
143 | * Frames will be allocated on-demand by |
144 | * as_page_fault(). |
144 | * as_page_fault() or preloaded by |
- | 145 | * as_area_load_mapping(). |
|
145 | */ |
146 | */ |
146 | a->mapping[i] = UNALLOCATED_PFN; |
147 | a->mapping[i] = UNALLOCATED_PFN; |
147 | } |
148 | } |
148 | 149 | ||
149 | spinlock_initialize(&a->lock, "as_area_lock"); |
150 | spinlock_initialize(&a->lock, "as_area_lock"); |
Line 157... | Line 158... | ||
157 | 158 | ||
158 | } |
159 | } |
159 | 160 | ||
160 | spinlock_unlock(&as->lock); |
161 | spinlock_unlock(&as->lock); |
161 | interrupts_restore(ipl); |
162 | interrupts_restore(ipl); |
162 | 163 | ||
163 | return a; |
164 | return a; |
164 | } |
165 | } |
165 | 166 | ||
166 | /** Load mapping for address space area. |
167 | /** Load mapping for address space area. |
167 | * |
168 | * |
Line 178... | Line 179... | ||
178 | ipl = interrupts_disable(); |
179 | ipl = interrupts_disable(); |
179 | spinlock_lock(&a->lock); |
180 | spinlock_lock(&a->lock); |
180 | 181 | ||
181 | for (i = 0; i < a->size; i++) { |
182 | for (i = 0; i < a->size; i++) { |
182 | ASSERT(a->mapping[i] == UNALLOCATED_PFN); |
183 | ASSERT(a->mapping[i] == UNALLOCATED_PFN); |
- | 184 | ASSERT(pfn[i] != UNALLOCATED_PFN); |
|
183 | a->mapping[i] = pfn[i]; |
185 | a->mapping[i] = pfn[i]; |
184 | } |
186 | } |
185 | 187 | ||
186 | spinlock_unlock(&a->lock); |
188 | spinlock_unlock(&a->lock); |
187 | interrupts_restore(ipl); |
189 | interrupts_restore(ipl); |
Line 192... | Line 194... | ||
192 | * This is the high-level page fault handler. |
194 | * This is the high-level page fault handler. |
193 | * Interrupts are assumed disabled. |
195 | * Interrupts are assumed disabled. |
194 | * |
196 | * |
195 | * @param page Faulting page. |
197 | * @param page Faulting page. |
196 | * |
198 | * |
197 | * @return 0 on page fault, 1 if address space operation |
199 | * @return 0 on page fault, 1 on success. |
198 | */ |
200 | */ |
199 | int as_page_fault(__address page) |
201 | int as_page_fault(__address page) |
200 | { |
202 | { |
201 | int flags; |
203 | int flags; |
202 | link_t *cur; |
204 | link_t *cur; |
Line 248... | Line 250... | ||
248 | */ |
250 | */ |
249 | if (area->mapping[vpn] == UNALLOCATED_PFN) { |
251 | if (area->mapping[vpn] == UNALLOCATED_PFN) { |
250 | frame = frame_alloc(0, ONE_FRAME, NULL); |
252 | frame = frame_alloc(0, ONE_FRAME, NULL); |
251 | memsetb(frame, FRAME_SIZE, 0); |
253 | memsetb(frame, FRAME_SIZE, 0); |
252 | area->mapping[vpn] = frame / FRAME_SIZE; |
254 | area->mapping[vpn] = frame / FRAME_SIZE; |
- | 255 | ASSERT(area->mapping[vpn] != UNALLOCATED_PFN); |
|
253 | } else { |
256 | } else { |
254 | frame = area->mapping[vpn] * FRAME_SIZE; |
257 | frame = area->mapping[vpn] * FRAME_SIZE; |
255 | } |
258 | } |
256 | 259 | ||
257 | switch (area->type) { |
260 | switch (area->type) { |