Rev 711 | Rev 727 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 711 | Rev 718 | ||
---|---|---|---|
Line 140... | Line 140... | ||
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() or preloaded by |
144 | * as_page_fault() or preloaded by |
145 | * as_area_load_mapping(). |
145 | * as_area_set_mapping(). |
146 | */ |
146 | */ |
147 | a->mapping[i] = UNALLOCATED_PFN; |
147 | a->mapping[i] = UNALLOCATED_PFN; |
148 | } |
148 | } |
149 | 149 | ||
150 | spinlock_initialize(&a->lock, "as_area_lock"); |
150 | spinlock_initialize(&a->lock, "as_area_lock"); |
Line 166... | Line 166... | ||
166 | 166 | ||
167 | /** Load mapping for address space area. |
167 | /** Load mapping for address space area. |
168 | * |
168 | * |
169 | * Initialize a->mapping. |
169 | * Initialize a->mapping. |
170 | * |
170 | * |
171 | * @param a Target address space area. |
171 | * @param a Target address space area. |
172 | * @param pfn Array of frame numbers. Number of elements must match with a->mapping. |
172 | * @param vpn Page number relative to area start. |
- | 173 | * @param pfn Frame number to map. |
|
173 | */ |
174 | */ |
174 | void as_area_load_mapping(as_area_t *a, index_t *pfn) |
175 | void as_area_set_mapping(as_area_t *a, index_t vpn, index_t pfn) |
175 | { |
176 | { |
- | 177 | ASSERT(vpn < a->size); |
|
- | 178 | ASSERT(a->mapping[vpn] == UNALLOCATED_PFN); |
|
- | 179 | ASSERT(pfn != UNALLOCATED_PFN); |
|
- | 180 | ||
176 | ipl_t ipl; |
181 | ipl_t ipl; |
177 | int i; |
- | |
178 | 182 | ||
179 | ipl = interrupts_disable(); |
183 | ipl = interrupts_disable(); |
180 | spinlock_lock(&a->lock); |
184 | spinlock_lock(&a->lock); |
181 | 185 | ||
182 | for (i = 0; i < a->size; i++) { |
- | |
183 | ASSERT(a->mapping[i] == UNALLOCATED_PFN); |
- | |
184 | ASSERT(pfn[i] != UNALLOCATED_PFN); |
- | |
185 | a->mapping[i] = pfn[i]; |
186 | a->mapping[vpn] = pfn; |
186 | } |
- | |
187 | 187 | ||
188 | spinlock_unlock(&a->lock); |
188 | spinlock_unlock(&a->lock); |
189 | interrupts_restore(ipl); |
189 | interrupts_restore(ipl); |
190 | } |
190 | } |
191 | 191 | ||
Line 251... | Line 251... | ||
251 | if (area->mapping[vpn] == UNALLOCATED_PFN) { |
251 | if (area->mapping[vpn] == UNALLOCATED_PFN) { |
252 | frame = frame_alloc(0, ONE_FRAME, NULL); |
252 | frame = frame_alloc(0, ONE_FRAME, NULL); |
253 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
253 | memsetb(PA2KA(frame), FRAME_SIZE, 0); |
254 | area->mapping[vpn] = frame / FRAME_SIZE; |
254 | area->mapping[vpn] = frame / FRAME_SIZE; |
255 | ASSERT(area->mapping[vpn] != UNALLOCATED_PFN); |
255 | ASSERT(area->mapping[vpn] != UNALLOCATED_PFN); |
256 | } else { |
256 | } else |
257 | frame = area->mapping[vpn] * FRAME_SIZE; |
257 | frame = area->mapping[vpn] * FRAME_SIZE; |
258 | } |
- | |
259 | 258 | ||
260 | switch (area->type) { |
259 | switch (area->type) { |
261 | case AS_AREA_TEXT: |
260 | case AS_AREA_TEXT: |
262 | flags = PAGE_EXEC | PAGE_READ | PAGE_USER | PAGE_PRESENT | PAGE_CACHEABLE; |
261 | flags = PAGE_EXEC | PAGE_READ | PAGE_USER | PAGE_PRESENT | PAGE_CACHEABLE; |
263 | break; |
262 | break; |