Subversion Repositories HelenOS-historic

Rev

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

Rev 1702 Rev 1760
Line 69... Line 69...
69
 * @param flags Flags to be used for mapping.
69
 * @param flags Flags to be used for mapping.
70
 */
70
 */
71
void pt_mapping_insert(as_t *as, __address page, __address frame, int flags)
71
void pt_mapping_insert(as_t *as, __address page, __address frame, int flags)
72
{
72
{
73
    pte_t *ptl0, *ptl1, *ptl2, *ptl3;
73
    pte_t *ptl0, *ptl1, *ptl2, *ptl3;
74
    __address newpt;
74
    pte_t *newpt;
75
 
75
 
76
    ptl0 = (pte_t *) PA2KA((__address) as->page_table);
76
    ptl0 = (pte_t *) PA2KA((__address) as->page_table);
77
 
77
 
78
    if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
78
    if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
79
        newpt = PA2KA(PFN2ADDR(frame_alloc(ONE_FRAME, FRAME_KA)));
79
        newpt = (pte_t *)frame_alloc(ONE_FRAME, FRAME_KA);
80
        memsetb(newpt, PAGE_SIZE, 0);
80
        memsetb((__address)newpt, PAGE_SIZE, 0);
81
        SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
81
        SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
82
        SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
82
        SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
83
    }
83
    }
84
 
84
 
85
    ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
85
    ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
86
 
86
 
87
    if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
87
    if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
88
        newpt = PA2KA(PFN2ADDR(frame_alloc(ONE_FRAME, FRAME_KA)));
88
        newpt = (pte_t *)frame_alloc(ONE_FRAME, FRAME_KA);
89
        memsetb(newpt, PAGE_SIZE, 0);
89
        memsetb((__address)newpt, PAGE_SIZE, 0);
90
        SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
90
        SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
91
        SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
91
        SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
92
    }
92
    }
93
 
93
 
94
    ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
94
    ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
95
 
95
 
96
    if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
96
    if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
97
        newpt = PA2KA(PFN2ADDR(frame_alloc(ONE_FRAME, FRAME_KA)));
97
        newpt = (pte_t *)frame_alloc(ONE_FRAME, FRAME_KA);
98
        memsetb(newpt, PAGE_SIZE, 0);
98
        memsetb((__address)newpt, PAGE_SIZE, 0);
99
        SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
99
        SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
100
        SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
100
        SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
101
    }
101
    }
102
 
102
 
103
    ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
103
    ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
Line 163... Line 163...
163
    if (empty) {
163
    if (empty) {
164
        /*
164
        /*
165
         * PTL3 is empty.
165
         * PTL3 is empty.
166
         * Release the frame and remove PTL3 pointer from preceding table.
166
         * Release the frame and remove PTL3 pointer from preceding table.
167
         */
167
         */
168
        frame_free(ADDR2PFN(KA2PA((__address) ptl3)));
168
        frame_free(KA2PA((__address) ptl3));
169
        if (PTL2_ENTRIES)
169
        if (PTL2_ENTRIES)
170
            memsetb((__address) &ptl2[PTL2_INDEX(page)], sizeof(pte_t), 0);
170
            memsetb((__address) &ptl2[PTL2_INDEX(page)], sizeof(pte_t), 0);
171
        else if (PTL1_ENTRIES)
171
        else if (PTL1_ENTRIES)
172
            memsetb((__address) &ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
172
            memsetb((__address) &ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
173
        else
173
        else
Line 192... Line 192...
192
        if (empty) {
192
        if (empty) {
193
            /*
193
            /*
194
             * PTL2 is empty.
194
             * PTL2 is empty.
195
             * Release the frame and remove PTL2 pointer from preceding table.
195
             * Release the frame and remove PTL2 pointer from preceding table.
196
             */
196
             */
197
            frame_free(ADDR2PFN(KA2PA((__address) ptl2)));
197
            frame_free(KA2PA((__address) ptl2));
198
            if (PTL1_ENTRIES)
198
            if (PTL1_ENTRIES)
199
                memsetb((__address) &ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
199
                memsetb((__address) &ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
200
            else
200
            else
201
                memsetb((__address) &ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
201
                memsetb((__address) &ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
202
        }
202
        }
Line 221... Line 221...
221
        if (empty) {
221
        if (empty) {
222
            /*
222
            /*
223
             * PTL1 is empty.
223
             * PTL1 is empty.
224
             * Release the frame and remove PTL1 pointer from preceding table.
224
             * Release the frame and remove PTL1 pointer from preceding table.
225
             */
225
             */
226
            frame_free(ADDR2PFN(KA2PA((__address) ptl1)));
226
            frame_free(KA2PA((__address) ptl1));
227
            memsetb((__address) &ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
227
            memsetb((__address) &ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
228
        }
228
        }
229
    }
229
    }
230
 
230
 
231
}
231
}