Subversion Repositories HelenOS

Rev

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

Rev 1842 Rev 1851
Line 32... Line 32...
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/mm/tlb.h>
35
#include <arch/mm/tlb.h>
36
#include <mm/tlb.h>
36
#include <mm/tlb.h>
-
 
37
#include <mm/as.h>
-
 
38
#include <mm/asid.h>
37
#include <arch/mm/frame.h>
39
#include <arch/mm/frame.h>
38
#include <arch/mm/page.h>
40
#include <arch/mm/page.h>
39
#include <arch/mm/mmu.h>
41
#include <arch/mm/mmu.h>
-
 
42
#include <arch/interrupt.h>
40
#include <mm/asid.h>
43
#include <arch.h>
41
#include <print.h>
44
#include <print.h>
42
#include <arch/types.h>
45
#include <arch/types.h>
43
#include <typedefs.h>
46
#include <typedefs.h>
44
#include <config.h>
47
#include <config.h>
45
#include <arch/trap/trap.h>
48
#include <arch/trap/trap.h>
46
#include <panic.h>
49
#include <panic.h>
47
#include <arch/asm.h>
50
#include <arch/asm.h>
48
#include <symtab.h>
51
#include <symtab.h>
49
 
52
 
-
 
53
static void dtlb_pte_copy(pte_t *t);
-
 
54
static void do_fast_data_access_mmu_miss_fault(istate_t *istate, const char *str);
-
 
55
 
50
char *context_encoding[] = {
56
char *context_encoding[] = {
51
    "Primary",
57
    "Primary",
52
    "Secondary",
58
    "Secondary",
53
    "Nucleus",
59
    "Nucleus",
54
    "Reserved"
60
    "Reserved"
Line 97... Line 103...
97
    data.g = true;
103
    data.g = true;
98
 
104
 
99
    dtlb_data_in_write(data.value);
105
    dtlb_data_in_write(data.value);
100
}
106
}
101
 
107
 
-
 
108
void dtlb_pte_copy(pte_t *t)
-
 
109
{
-
 
110
}
-
 
111
 
102
/** ITLB miss handler. */
112
/** ITLB miss handler. */
103
void fast_instruction_access_mmu_miss(void)
113
void fast_instruction_access_mmu_miss(int n, istate_t *istate)
104
{
114
{
105
    panic("%s\n", __FUNCTION__);
115
    panic("%s\n", __FUNCTION__);
106
}
116
}
107
 
117
 
108
/** DTLB miss handler. */
118
/** DTLB miss handler.
-
 
119
 *
-
 
120
 * Note that some faults (e.g. kernel faults) were already resolved
-
 
121
 * by the low-level, assembly language part of the fast_data_access_mmu_miss
-
 
122
 * handler.
-
 
123
 */
109
void fast_data_access_mmu_miss(void)
124
void fast_data_access_mmu_miss(int n, istate_t *istate)
110
{
125
{
111
    tlb_tag_access_reg_t tag;
126
    tlb_tag_access_reg_t tag;
112
    uintptr_t tpc;
127
    uintptr_t va;
113
    char *tpc_str;
128
    pte_t *t;
114
 
129
 
115
    tag.value = dtlb_tag_access_read();
130
    tag.value = dtlb_tag_access_read();
-
 
131
    va = tag.vpn * PAGE_SIZE;
116
    if (tag.context != ASID_KERNEL || tag.vpn == 0) {
132
    if (tag.context == ASID_KERNEL) {
117
        tpc = tpc_read();
133
        if (!tag.vpn) {
118
        tpc_str = get_symtab_entry(tpc);
134
            /* NULL access in kernel */
-
 
135
            do_fast_data_access_mmu_miss_fault(istate, __FUNCTION__);
119
 
136
        }
120
        printf("Faulting page: %p, ASID=%d\n", tag.vpn * PAGE_SIZE, tag.context);
137
        do_fast_data_access_mmu_miss_fault(istate, "Unexpected kernel page fault.");
121
        printf("TPC=%p, (%s)\n", tpc, tpc_str ? tpc_str : "?");
-
 
122
        panic("%s\n", __FUNCTION__);
-
 
123
    }
138
    }
124
 
139
 
-
 
140
    page_table_lock(AS, true);
-
 
141
    t = page_mapping_find(AS, va);
-
 
142
    if (t) {
125
    /*
143
        /*
126
     * Identity map piece of faulting kernel address space.
144
         * The mapping was found in the software page hash table.
-
 
145
         * Insert it into DTLB.
127
     */
146
         */
-
 
147
        dtlb_pte_copy(t);
-
 
148
        page_table_unlock(AS, true);
-
 
149
    } else {
-
 
150
        /*
128
    dtlb_insert_mapping(tag.vpn * PAGE_SIZE, tag.vpn * FRAME_SIZE, PAGESIZE_8K, false, true);
151
         * Forward the page fault to the address space page fault handler.
-
 
152
         */    
-
 
153
        page_table_unlock(AS, true);
-
 
154
        if (as_page_fault(va, PF_ACCESS_READ, istate) == AS_PF_FAULT) {
-
 
155
            do_fast_data_access_mmu_miss_fault(istate, __FUNCTION__);
-
 
156
        }
-
 
157
    }
129
}
158
}
130
 
159
 
131
/** DTLB protection fault handler. */
160
/** DTLB protection fault handler. */
132
void fast_data_access_protection(void)
161
void fast_data_access_protection(int n, istate_t *istate)
133
{
162
{
134
    panic("%s\n", __FUNCTION__);
163
    panic("%s\n", __FUNCTION__);
135
}
164
}
136
 
165
 
137
/** Print contents of both TLBs. */
166
/** Print contents of both TLBs. */
Line 159... Line 188...
159
            i, t.vpn, t.context, d.v, d.size, d.nfo, d.ie, d.soft2, d.diag, d.pfn, d.soft, d.l, d.cp, d.cv, d.e, d.p, d.w, d.g);
188
            i, t.vpn, t.context, d.v, d.size, d.nfo, d.ie, d.soft2, d.diag, d.pfn, d.soft, d.l, d.cp, d.cv, d.e, d.p, d.w, d.g);
160
    }
189
    }
161
 
190
 
162
}
191
}
163
 
192
 
-
 
193
void do_fast_data_access_mmu_miss_fault(istate_t *istate, const char *str)
-
 
194
{
-
 
195
    tlb_tag_access_reg_t tag;
-
 
196
    uintptr_t va;
-
 
197
    char *tpc_str = get_symtab_entry(istate->tpc);
-
 
198
 
-
 
199
    tag.value = dtlb_tag_access_read();
-
 
200
    va = tag.vpn * PAGE_SIZE;
-
 
201
 
-
 
202
    printf("Faulting page: %p, ASID=%d\n", va, tag.context);
-
 
203
    printf("TPC=%p, (%s)\n", istate->tpc, tpc_str);
-
 
204
    panic("%s\n", str);
-
 
205
}
-
 
206
 
164
/** Invalidate all unlocked ITLB and DTLB entries. */
207
/** Invalidate all unlocked ITLB and DTLB entries. */
165
void tlb_invalidate_all(void)
208
void tlb_invalidate_all(void)
166
{
209
{
167
    int i;
210
    int i;
168
    tlb_data_t d;
211
    tlb_data_t d;