Changeset c7f8fc5 in mainline
- Timestamp:
- 2012-01-13T22:31:32Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d56382d
- Parents:
- c142860
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/backend_elf.c
rc142860 rc7f8fc5 44 44 #include <mm/page.h> 45 45 #include <mm/reserve.h> 46 #include <mm/km.h> 46 47 #include <genarch/mm/page_pt.h> 47 48 #include <genarch/mm/page_ht.h> … … 229 230 elf_segment_header_t *entry = area->backend_data.segment; 230 231 btree_node_t *leaf; 231 uintptr_t base, frame, page, start_anon; 232 uintptr_t base; 233 uintptr_t frame; 234 uintptr_t kpage; 235 uintptr_t upage; 236 uintptr_t start_anon; 232 237 size_t i; 233 238 bool dirty = false; … … 249 254 (((void *) elf) + ALIGN_DOWN(entry->p_offset, PAGE_SIZE)); 250 255 251 /* Virtual address of faulting page */252 page = ALIGN_DOWN(addr, PAGE_SIZE);256 /* Virtual address of faulting page */ 257 upage = ALIGN_DOWN(addr, PAGE_SIZE); 253 258 254 259 /* Virtual address of the end of initialized part of segment */ … … 264 269 mutex_lock(&area->sh_info->lock); 265 270 frame = (uintptr_t) btree_search(&area->sh_info->pagemap, 266 page - area->base, &leaf);271 upage - area->base, &leaf); 267 272 if (!frame) { 268 273 unsigned int i; … … 273 278 274 279 for (i = 0; i < leaf->keys; i++) { 275 if (leaf->key[i] == page - area->base) {280 if (leaf->key[i] == upage - area->base) { 276 281 found = true; 277 282 break; … … 281 286 if (frame || found) { 282 287 frame_reference_add(ADDR2PFN(frame)); 283 page_mapping_insert(AS, addr, frame,288 page_mapping_insert(AS, upage, frame, 284 289 as_area_get_flags(area)); 285 if (!used_space_insert(area, page, 1))290 if (!used_space_insert(area, upage, 1)) 286 291 panic("Cannot insert used space."); 287 292 mutex_unlock(&area->sh_info->lock); … … 294 299 * mapping. 295 300 */ 296 if ( page >= entry->p_vaddr &&page + PAGE_SIZE <= start_anon) {301 if (upage >= entry->p_vaddr && upage + PAGE_SIZE <= start_anon) { 297 302 /* 298 303 * Initialized portion of the segment. The memory is backed … … 304 309 */ 305 310 if (entry->p_flags & PF_W) { 306 frame = (uintptr_t)frame_alloc_noreserve(ONE_FRAME, 0); 307 memcpy((void *) PA2KA(frame), 308 (void *) (base + i * FRAME_SIZE), FRAME_SIZE); 309 if (entry->p_flags & PF_X) { 310 smc_coherence_block((void *) PA2KA(frame), 311 FRAME_SIZE); 312 } 311 kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE); 312 memcpy((void *) kpage, (void *) (base + i * FRAME_SIZE), 313 PAGE_SIZE); 314 if (entry->p_flags & PF_X) 315 smc_coherence_block((void *) kpage, FRAME_SIZE); 316 km_temporary_page_put(kpage); 313 317 dirty = true; 314 318 } else { 315 319 frame = KA2PA(base + i * FRAME_SIZE); 316 320 } 317 } else if ( page >= start_anon) {321 } else if (upage >= start_anon) { 318 322 /* 319 323 * This is the uninitialized portion of the segment. … … 322 326 * and cleared. 323 327 */ 324 frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME, 0); 325 memsetb((void *) PA2KA(frame), FRAME_SIZE, 0); 328 kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE); 329 memsetb((void *) kpage, PAGE_SIZE, 0); 330 km_temporary_page_put(kpage); 326 331 dirty = true; 327 332 } else { … … 334 339 * (The segment can be and often is shorter than 1 page). 335 340 */ 336 if ( page < entry->p_vaddr)337 pad_lo = entry->p_vaddr - page;341 if (upage < entry->p_vaddr) 342 pad_lo = entry->p_vaddr - upage; 338 343 else 339 344 pad_lo = 0; 340 345 341 if (start_anon < page + PAGE_SIZE)342 pad_hi = page + PAGE_SIZE - start_anon;346 if (start_anon < upage + PAGE_SIZE) 347 pad_hi = upage + PAGE_SIZE - start_anon; 343 348 else 344 349 pad_hi = 0; 345 350 346 frame = (uintptr_t) frame_alloc_noreserve(ONE_FRAME, 0);347 memcpy((void *) ( PA2KA(frame)+ pad_lo),348 (void *) (base + i * FRAME_SIZE + pad_lo),349 FRAME_SIZE - pad_lo - pad_hi);351 kpage = km_temporary_page_get(&frame, FRAME_NO_RESERVE); 352 memcpy((void *) (kpage + pad_lo), 353 (void *) (base + i * PAGE_SIZE + pad_lo), 354 PAGE_SIZE - pad_lo - pad_hi); 350 355 if (entry->p_flags & PF_X) { 351 smc_coherence_block((void *) ( PA2KA(frame)+ pad_lo),352 FRAME_SIZE - pad_lo - pad_hi);356 smc_coherence_block((void *) (kpage + pad_lo), 357 PAGE_SIZE - pad_lo - pad_hi); 353 358 } 354 memsetb((void *) PA2KA(frame), pad_lo, 0);355 memsetb((void *) ( PA2KA(frame) + FRAME_SIZE - pad_hi), pad_hi,356 0);359 memsetb((void *) kpage, pad_lo, 0); 360 memsetb((void *) (kpage + PAGE_SIZE - pad_hi), pad_hi, 0); 361 km_temporary_page_put(kpage); 357 362 dirty = true; 358 363 } … … 360 365 if (dirty && area->sh_info) { 361 366 frame_reference_add(ADDR2PFN(frame)); 362 btree_insert(&area->sh_info->pagemap, page - area->base,367 btree_insert(&area->sh_info->pagemap, upage - area->base, 363 368 (void *) frame, leaf); 364 369 } … … 367 372 mutex_unlock(&area->sh_info->lock); 368 373 369 page_mapping_insert(AS, addr, frame, as_area_get_flags(area));370 if (!used_space_insert(area, page, 1))374 page_mapping_insert(AS, upage, frame, as_area_get_flags(area)); 375 if (!used_space_insert(area, upage, 1)) 371 376 panic("Cannot insert used space."); 372 377
Note:
See TracChangeset
for help on using the changeset viewer.