Subversion Repositories HelenOS

Rev

Rev 3104 | Rev 3142 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3104 Rev 3141
Line 46... Line 46...
46
#include <genarch/mm/page_ht.h>
46
#include <genarch/mm/page_ht.h>
47
#include <align.h>
47
#include <align.h>
48
#include <memstr.h>
48
#include <memstr.h>
49
#include <macros.h>
49
#include <macros.h>
50
#include <arch.h>
50
#include <arch.h>
-
 
51
#include <arch/barrier.h>
51
 
52
 
52
#ifdef CONFIG_VIRT_IDX_DCACHE
53
#ifdef CONFIG_VIRT_IDX_DCACHE
53
#include <arch/mm/cache.h>
54
#include <arch/mm/cache.h>
54
#endif
55
#endif
55
 
56
 
Line 65... Line 66...
65
 
66
 
66
/** Service a page fault in the ELF backend address space area.
67
/** Service a page fault in the ELF backend address space area.
67
 *
68
 *
68
 * The address space area and page tables must be already locked.
69
 * The address space area and page tables must be already locked.
69
 *
70
 *
70
 * @param area Pointer to the address space area.
71
 * @param area      Pointer to the address space area.
71
 * @param addr Faulting virtual address.
72
 * @param addr      Faulting virtual address.
72
 * @param access Access mode that caused the fault (i.e. read/write/exec).
73
 * @param access    Access mode that caused the fault (i.e.
-
 
74
 *          read/write/exec).
73
 *
75
 *
74
 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e.
76
 * @return      AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK
75
 *     serviced).
77
 *          on success (i.e. serviced).
76
 */
78
 */
77
int elf_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
79
int elf_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access)
78
{
80
{
79
    elf_header_t *elf = area->backend_data.elf;
81
    elf_header_t *elf = area->backend_data.elf;
80
    elf_segment_header_t *entry = area->backend_data.segment;
82
    elf_segment_header_t *entry = area->backend_data.segment;
Line 148... Line 150...
148
         */
150
         */
149
        if (entry->p_flags & PF_W) {
151
        if (entry->p_flags & PF_W) {
150
            frame = (uintptr_t)frame_alloc(ONE_FRAME, 0);
152
            frame = (uintptr_t)frame_alloc(ONE_FRAME, 0);
151
            memcpy((void *) PA2KA(frame),
153
            memcpy((void *) PA2KA(frame),
152
                (void *) (base + i * FRAME_SIZE), FRAME_SIZE);
154
                (void *) (base + i * FRAME_SIZE), FRAME_SIZE);
-
 
155
            if (entry->p_flags & PF_X)
-
 
156
                smc_coherence_block(PA2KA(frame), FRAME_SIZE);
153
            dirty = true;
157
            dirty = true;
154
        } else {
158
        } else {
155
            frame = KA2PA(base + i * FRAME_SIZE);
159
            frame = KA2PA(base + i * FRAME_SIZE);
156
        }  
160
        }  
157
    } else if (page >= start_anon) {
161
    } else if (page >= start_anon) {
Line 185... Line 189...
185
 
189
 
186
        frame = (uintptr_t)frame_alloc(ONE_FRAME, 0);
190
        frame = (uintptr_t)frame_alloc(ONE_FRAME, 0);
187
        memcpy((void *) (PA2KA(frame) + pad_lo),
191
        memcpy((void *) (PA2KA(frame) + pad_lo),
188
            (void *) (base + i * FRAME_SIZE + pad_lo),
192
            (void *) (base + i * FRAME_SIZE + pad_lo),
189
            FRAME_SIZE - pad_lo - pad_hi);
193
            FRAME_SIZE - pad_lo - pad_hi);
-
 
194
        if (entry->p_flags & PF_X)
-
 
195
            smc_coherence_block(PA2KA(frame) + pad_lo, FRAME_SIZE -
-
 
196
                pad_lo - pad_hi);
190
        memsetb((void *) PA2KA(frame), pad_lo, 0);
197
        memsetb((void *) PA2KA(frame), pad_lo, 0);
191
        memsetb((void *) (PA2KA(frame) + FRAME_SIZE - pad_hi), pad_hi, 0);
198
        memsetb((void *) (PA2KA(frame) + FRAME_SIZE - pad_hi), pad_hi,
-
 
199
            0);
192
        dirty = true;
200
        dirty = true;
193
    }
201
    }
194
 
202
 
195
    if (dirty && area->sh_info) {
203
    if (dirty && area->sh_info) {
196
        frame_reference_add(ADDR2PFN(frame));
204
        frame_reference_add(ADDR2PFN(frame));
Line 210... Line 218...
210
 
218
 
211
/** Free a frame that is backed by the ELF backend.
219
/** Free a frame that is backed by the ELF backend.
212
 *
220
 *
213
 * The address space area and page tables must be already locked.
221
 * The address space area and page tables must be already locked.
214
 *
222
 *
215
 * @param area Pointer to the address space area.
223
 * @param area      Pointer to the address space area.
216
 * @param page Page that is mapped to frame. Must be aligned to PAGE_SIZE.
224
 * @param page      Page that is mapped to frame. Must be aligned to
-
 
225
 *          PAGE_SIZE.
217
 * @param frame Frame to be released.
226
 * @param frame     Frame to be released.
218
 *
227
 *
219
 */
228
 */
220
void elf_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
229
void elf_frame_free(as_area_t *area, uintptr_t page, uintptr_t frame)
221
{
230
{
222
    elf_header_t *elf = area->backend_data.elf;
231
    elf_header_t *elf = area->backend_data.elf;
Line 255... Line 264...
255
 * Otherwise only portions of the area that are not backed by the ELF image
264
 * Otherwise only portions of the area that are not backed by the ELF image
256
 * are put into the pagemap.
265
 * are put into the pagemap.
257
 *
266
 *
258
 * The address space and address space area must be locked prior to the call.
267
 * The address space and address space area must be locked prior to the call.
259
 *
268
 *
260
 * @param area Address space area.
269
 * @param area      Address space area.
261
 */
270
 */
262
void elf_share(as_area_t *area)
271
void elf_share(as_area_t *area)
263
{
272
{
264
    elf_segment_header_t *entry = area->backend_data.segment;
273
    elf_segment_header_t *entry = area->backend_data.segment;
265
    link_t *cur;
274
    link_t *cur;