Subversion Repositories HelenOS

Rev

Rev 3022 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3022 Rev 4055
Line 74... Line 74...
74
 
74
 
75
    ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
75
    ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
76
 
76
 
77
    if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
77
    if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
78
        newpt = (pte_t *)frame_alloc(PTL1_SIZE, FRAME_KA);
78
        newpt = (pte_t *)frame_alloc(PTL1_SIZE, FRAME_KA);
79
        memsetb((uintptr_t)newpt, FRAME_SIZE << PTL1_SIZE, 0);
79
        memsetb(newpt, FRAME_SIZE << PTL1_SIZE, 0);
80
        SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
80
        SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
81
        SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
81
        SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
82
    }
82
    }
83
 
83
 
84
    ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
84
    ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
85
 
85
 
86
    if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
86
    if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
87
        newpt = (pte_t *)frame_alloc(PTL2_SIZE, FRAME_KA);
87
        newpt = (pte_t *)frame_alloc(PTL2_SIZE, FRAME_KA);
88
        memsetb((uintptr_t)newpt, FRAME_SIZE << PTL2_SIZE, 0);
88
        memsetb(newpt, FRAME_SIZE << PTL2_SIZE, 0);
89
        SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
89
        SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
90
        SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
90
        SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
91
    }
91
    }
92
 
92
 
93
    ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
93
    ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
94
 
94
 
95
    if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
95
    if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
96
        newpt = (pte_t *)frame_alloc(PTL3_SIZE, FRAME_KA);
96
        newpt = (pte_t *)frame_alloc(PTL3_SIZE, FRAME_KA);
97
        memsetb((uintptr_t)newpt, FRAME_SIZE << PTL3_SIZE, 0);
97
        memsetb(newpt, FRAME_SIZE << PTL3_SIZE, 0);
98
        SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
98
        SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
99
        SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
99
        SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
100
    }
100
    }
101
 
101
 
102
    ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
102
    ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
Line 144... Line 144...
144
        return;
144
        return;
145
 
145
 
146
    ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
146
    ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
147
 
147
 
148
    /* Destroy the mapping. Setting to PAGE_NOT_PRESENT is not sufficient. */
148
    /* Destroy the mapping. Setting to PAGE_NOT_PRESENT is not sufficient. */
149
    memsetb((uintptr_t) &ptl3[PTL3_INDEX(page)], sizeof(pte_t), 0);
149
    memsetb(&ptl3[PTL3_INDEX(page)], sizeof(pte_t), 0);
150
 
150
 
151
    /*
151
    /*
152
     * Second, free all empty tables along the way from PTL3 down to PTL0.
152
     * Second, free all empty tables along the way from PTL3 down to PTL0.
153
     */
153
     */
154
   
154
   
Line 164... Line 164...
164
         * PTL3 is empty.
164
         * PTL3 is empty.
165
         * Release the frame and remove PTL3 pointer from preceding table.
165
         * Release the frame and remove PTL3 pointer from preceding table.
166
         */
166
         */
167
        frame_free(KA2PA((uintptr_t) ptl3));
167
        frame_free(KA2PA((uintptr_t) ptl3));
168
        if (PTL2_ENTRIES)
168
        if (PTL2_ENTRIES)
169
            memsetb((uintptr_t) &ptl2[PTL2_INDEX(page)], sizeof(pte_t), 0);
169
            memsetb(&ptl2[PTL2_INDEX(page)], sizeof(pte_t), 0);
170
        else if (PTL1_ENTRIES)
170
        else if (PTL1_ENTRIES)
171
            memsetb((uintptr_t) &ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
171
            memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
172
        else
172
        else
173
            memsetb((uintptr_t) &ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
173
            memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
174
    } else {
174
    } else {
175
        /*
175
        /*
176
         * PTL3 is not empty.
176
         * PTL3 is not empty.
177
         * Therefore, there must be a path from PTL0 to PTL3 and
177
         * Therefore, there must be a path from PTL0 to PTL3 and
178
         * thus nothing to free in higher levels.
178
         * thus nothing to free in higher levels.
Line 193... Line 193...
193
             * PTL2 is empty.
193
             * PTL2 is empty.
194
             * Release the frame and remove PTL2 pointer from preceding table.
194
             * Release the frame and remove PTL2 pointer from preceding table.
195
             */
195
             */
196
            frame_free(KA2PA((uintptr_t) ptl2));
196
            frame_free(KA2PA((uintptr_t) ptl2));
197
            if (PTL1_ENTRIES)
197
            if (PTL1_ENTRIES)
198
                memsetb((uintptr_t) &ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
198
                memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
199
            else
199
            else
200
                memsetb((uintptr_t) &ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
200
                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
201
        }
201
        }
202
        else {
202
        else {
203
            /*
203
            /*
204
             * PTL2 is not empty.
204
             * PTL2 is not empty.
205
             * Therefore, there must be a path from PTL0 to PTL2 and
205
             * Therefore, there must be a path from PTL0 to PTL2 and
Line 221... Line 221...
221
            /*
221
            /*
222
             * PTL1 is empty.
222
             * PTL1 is empty.
223
             * Release the frame and remove PTL1 pointer from preceding table.
223
             * Release the frame and remove PTL1 pointer from preceding table.
224
             */
224
             */
225
            frame_free(KA2PA((uintptr_t) ptl1));
225
            frame_free(KA2PA((uintptr_t) ptl1));
226
            memsetb((uintptr_t) &ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
226
            memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
227
        }
227
        }
228
    }
228
    }
229
 
229
 
230
}
230
}
231
 
231