Subversion Repositories HelenOS

Rev

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

Rev 2131 Rev 2422
Line 32... Line 32...
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <arch/mm/tsb.h>
35
#include <arch/mm/tsb.h>
36
#include <arch/mm/tlb.h>
36
#include <arch/mm/tlb.h>
-
 
37
#include <arch/mm/page.h>
37
#include <arch/barrier.h>
38
#include <arch/barrier.h>
38
#include <mm/as.h>
39
#include <mm/as.h>
39
#include <arch/types.h>
40
#include <arch/types.h>
40
#include <macros.h>
41
#include <macros.h>
41
#include <debug.h>
42
#include <debug.h>
42
 
43
 
43
#define TSB_INDEX_MASK      ((1 << (21 + 1 + TSB_SIZE - PAGE_WIDTH)) - 1)
44
#define TSB_INDEX_MASK  ((1 << (21 + 1 + TSB_SIZE - MMU_PAGE_WIDTH)) - 1)
44
 
45
 
45
/** Invalidate portion of TSB.
46
/** Invalidate portion of TSB.
46
 *
47
 *
47
 * We assume that the address space is already locked. Note that respective
48
 * We assume that the address space is already locked. Note that respective
48
 * portions of both TSBs are invalidated at a time.
49
 * portions of both TSBs are invalidated at a time.
Line 57... Line 58...
57
    index_t i0, i;
58
    index_t i0, i;
58
    count_t cnt;
59
    count_t cnt;
59
   
60
   
60
    ASSERT(as->arch.itsb && as->arch.dtsb);
61
    ASSERT(as->arch.itsb && as->arch.dtsb);
61
   
62
   
62
    i0 = (page >> PAGE_WIDTH) & TSB_INDEX_MASK;
63
    i0 = (page >> MMU_PAGE_WIDTH) & TSB_INDEX_MASK;
-
 
64
    ASSERT(i0 < ITSB_ENTRY_COUNT && i0 < DTSB_ENTRY_COUNT);
-
 
65
 
-
 
66
    if (pages == (count_t) -1 || (pages * 2) > ITSB_ENTRY_COUNT)
63
    cnt = min(pages, ITSB_ENTRY_COUNT);
67
        cnt = ITSB_ENTRY_COUNT;
-
 
68
    else
-
 
69
        cnt = pages * 2;
64
   
70
   
65
    for (i = 0; i < cnt; i++) {
71
    for (i = 0; i < cnt; i++) {
66
        as->arch.itsb[(i0 + i) & (ITSB_ENTRY_COUNT - 1)].tag.invalid =
72
        as->arch.itsb[(i0 + i) & (ITSB_ENTRY_COUNT - 1)].tag.invalid =
67
            true;
73
            true;
68
        as->arch.dtsb[(i0 + i) & (DTSB_ENTRY_COUNT - 1)].tag.invalid =
74
        as->arch.dtsb[(i0 + i) & (DTSB_ENTRY_COUNT - 1)].tag.invalid =
69
            true;
75
            true;
70
    }
76
    }
71
}
77
}
72
 
78
 
73
/** Copy software PTE to ITSB.
79
/** Copy software PTE to ITSB.
74
 *
80
 *
75
 * @param t Software PTE.
81
 * @param t     Software PTE.
-
 
82
 * @param index Zero if lower 8K-subpage, one if higher 8K subpage.
76
 */
83
 */
77
void itsb_pte_copy(pte_t *t)
84
void itsb_pte_copy(pte_t *t, index_t index)
78
{
85
{
79
    as_t *as;
86
    as_t *as;
80
    tsb_entry_t *tsb;
87
    tsb_entry_t *tsb;
-
 
88
    index_t entry;
-
 
89
 
-
 
90
    ASSERT(index <= 1);
81
   
91
   
82
    as = t->as;
92
    as = t->as;
83
    tsb = &as->arch.itsb[(t->page >> PAGE_WIDTH) & TSB_INDEX_MASK];
93
    entry = ((t->page >> MMU_PAGE_WIDTH) + index) & TSB_INDEX_MASK;
-
 
94
    ASSERT(entry < ITSB_ENTRY_COUNT);
-
 
95
    tsb = &as->arch.itsb[entry];
84
 
96
 
85
    /*
97
    /*
86
     * We use write barriers to make sure that the TSB load
98
     * We use write barriers to make sure that the TSB load
87
     * won't use inconsistent data or that the fault will
99
     * won't use inconsistent data or that the fault will
88
     * be repeated.
100
     * be repeated.
Line 93... Line 105...
93
                     * set to 0) */
105
                     * set to 0) */
94
 
106
 
95
    write_barrier();
107
    write_barrier();
96
 
108
 
97
    tsb->tag.context = as->asid;
109
    tsb->tag.context = as->asid;
-
 
110
    /* the shift is bigger than PAGE_WIDTH, do not bother with index  */
98
    tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
111
    tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
99
    tsb->data.value = 0;
112
    tsb->data.value = 0;
100
    tsb->data.size = PAGESIZE_8K;
113
    tsb->data.size = PAGESIZE_8K;
101
    tsb->data.pfn = t->frame >> FRAME_WIDTH;
114
    tsb->data.pfn = (t->frame >> MMU_FRAME_WIDTH) + index;
102
    tsb->data.cp = t->c;
115
    tsb->data.cp = t->c;
103
    tsb->data.p = t->k;     /* p as privileged */
116
    tsb->data.p = t->k;     /* p as privileged */
104
    tsb->data.v = t->p;
117
    tsb->data.v = t->p;
105
   
118
   
106
    write_barrier();
119
    write_barrier();
Line 108... Line 121...
108
    tsb->tag.invalid = false;   /* mark the entry as valid */
121
    tsb->tag.invalid = false;   /* mark the entry as valid */
109
}
122
}
110
 
123
 
111
/** Copy software PTE to DTSB.
124
/** Copy software PTE to DTSB.
112
 *
125
 *
113
 * @param t Software PTE.
126
 * @param t Software PTE.
-
 
127
 * @param index Zero if lower 8K-subpage, one if higher 8K-subpage.
114
 * @param ro If true, the mapping is copied read-only.
128
 * @param ro    If true, the mapping is copied read-only.
115
 */
129
 */
116
void dtsb_pte_copy(pte_t *t, bool ro)
130
void dtsb_pte_copy(pte_t *t, index_t index, bool ro)
117
{
131
{
118
    as_t *as;
132
    as_t *as;
119
    tsb_entry_t *tsb;
133
    tsb_entry_t *tsb;
-
 
134
    index_t entry;
120
   
135
   
-
 
136
    ASSERT(index <= 1);
-
 
137
 
121
    as = t->as;
138
    as = t->as;
122
    tsb = &as->arch.dtsb[(t->page >> PAGE_WIDTH) & TSB_INDEX_MASK];
139
    entry = ((t->page >> MMU_PAGE_WIDTH) + index) & TSB_INDEX_MASK;
-
 
140
    ASSERT(entry < DTSB_ENTRY_COUNT);
-
 
141
    tsb = &as->arch.dtsb[entry];
123
 
142
 
124
    /*
143
    /*
125
     * We use write barriers to make sure that the TSB load
144
     * We use write barriers to make sure that the TSB load
126
     * won't use inconsistent data or that the fault will
145
     * won't use inconsistent data or that the fault will
127
     * be repeated.
146
     * be repeated.
Line 132... Line 151...
132
                     * set to 0) */
151
                     * set to 0) */
133
 
152
 
134
    write_barrier();
153
    write_barrier();
135
 
154
 
136
    tsb->tag.context = as->asid;
155
    tsb->tag.context = as->asid;
-
 
156
    /* the shift is bigger than PAGE_WIDTH, do not bother with index */
137
    tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
157
    tsb->tag.va_tag = t->page >> VA_TAG_PAGE_SHIFT;
138
    tsb->data.value = 0;
158
    tsb->data.value = 0;
139
    tsb->data.size = PAGESIZE_8K;
159
    tsb->data.size = PAGESIZE_8K;
140
    tsb->data.pfn = t->frame >> FRAME_WIDTH;
160
    tsb->data.pfn = (t->frame >> MMU_FRAME_WIDTH) + index;
141
    tsb->data.cp = t->c;
161
    tsb->data.cp = t->c;
142
#ifdef CONFIG_VIRT_IDX_DCACHE
162
#ifdef CONFIG_VIRT_IDX_DCACHE
143
    tsb->data.cv = t->c;
163
    tsb->data.cv = t->c;
144
#endif /* CONFIG_VIRT_IDX_DCACHE */
164
#endif /* CONFIG_VIRT_IDX_DCACHE */
145
    tsb->data.p = t->k;     /* p as privileged */
165
    tsb->data.p = t->k;     /* p as privileged */
146
    tsb->data.w = ro ? false : t->w;
166
    tsb->data.w = ro ? false : t->w;
147
    tsb->data.v = t->p;
167
    tsb->data.v = t->p;
148
   
168
   
149
    write_barrier();
169
    write_barrier();
150
   
170
   
151
    tsb->tag.invalid = true;    /* mark the entry as valid */
171
    tsb->tag.invalid = false;   /* mark the entry as valid */
152
}
172
}
153
 
173
 
154
/** @}
174
/** @}
155
 */
175
 */