Subversion Repositories HelenOS

Rev

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

Rev 3228 Rev 3230
Line 33... Line 33...
33
 */
33
 */
34
 
34
 
35
#include <macros.h>
35
#include <macros.h>
36
#include <arch/mm/frame.h>
36
#include <arch/mm/frame.h>
37
#include <arch/mm/tlb.h>
37
#include <arch/mm/tlb.h>
-
 
38
#include <interrupt.h>
38
#include <mm/frame.h>
39
#include <mm/frame.h>
39
#include <mm/asid.h>
40
#include <mm/asid.h>
40
#include <config.h>
41
#include <config.h>
41
#include <arch/drivers/msim.h>
42
#include <arch/drivers/msim.h>
42
#include <arch/drivers/serial.h>
43
#include <arch/drivers/serial.h>
43
#include <print.h>
44
#include <print.h>
44
#include <debug.h>
-
 
45
 
-
 
46
#define TLB_PAGE_MASK_1M    (0xff << 13)
-
 
47
 
45
 
-
 
46
#define ZERO_PAGE_MASK      TLB_PAGE_MASK_1M
48
#define ZERO_FRAMES         4096
47
#define ZERO_FRAMES         4096
49
#define ZERO_PAGE_WIDTH     20  /* 1M */
48
#define ZERO_PAGE_WIDTH     20  /* 1M */
50
#define ZERO_PAGE_SIZE      (1 << ZERO_PAGE_WIDTH)
49
#define ZERO_PAGE_SIZE      (1 << ZERO_PAGE_WIDTH)
51
#define ZERO_PAGE_ASID      ASID_INVALID
50
#define ZERO_PAGE_ASID      ASID_INVALID
52
#define ZERO_PAGE_TLBI      0
51
#define ZERO_PAGE_TLBI      0
53
#define ZERO_PAGE_ADDR      0
52
#define ZERO_PAGE_ADDR      0
54
#define ZERO_PAGE_OFFSET    (ZERO_PAGE_SIZE / sizeof(uint32_t) - 1)
53
#define ZERO_PAGE_OFFSET    (ZERO_PAGE_SIZE / sizeof(uint32_t) - 1)
55
#define ZERO_PAGE_VALUE     (*((volatile uint32_t *) ZERO_PAGE_ADDR + ZERO_PAGE_OFFSET))
54
#define ZERO_PAGE_VALUE     (((volatile uint32_t *) ZERO_PAGE_ADDR)[ZERO_PAGE_OFFSET])
56
 
55
 
57
#define MAX_REGIONS         32
56
#define MAX_REGIONS         32
58
 
57
 
59
typedef struct {
58
typedef struct {
60
    pfn_t start;
59
    pfn_t start;
Line 129... Line 128...
129
static void frame_add_region(pfn_t start_frame, pfn_t end_frame)
128
static void frame_add_region(pfn_t start_frame, pfn_t end_frame)
130
{
129
{
131
    if (end_frame > start_frame) {
130
    if (end_frame > start_frame) {
132
        /* Convert 1M frames to 16K frames */
131
        /* Convert 1M frames to 16K frames */
133
        pfn_t first = ADDR2PFN(start_frame << ZERO_PAGE_WIDTH);
132
        pfn_t first = ADDR2PFN(start_frame << ZERO_PAGE_WIDTH);
134
        pfn_t count = ADDR2PFN((end_frame - start_frame - 1) << ZERO_PAGE_WIDTH);
133
        pfn_t count = ADDR2PFN((end_frame - start_frame) << ZERO_PAGE_WIDTH);
135
       
134
       
136
        /* Interrupt vector frame is blacklisted */
135
        /* Interrupt vector frame is blacklisted */
137
        pfn_t conf_frame;
136
        pfn_t conf_frame;
138
        if (start_frame == 0)
137
        if (start_frame == 0)
139
            conf_frame = 1;
138
            conf_frame = 1;
Line 154... Line 153...
154
/** Create memory zones
153
/** Create memory zones
155
 *
154
 *
156
 * Walk through available 1 MB chunks of physical
155
 * Walk through available 1 MB chunks of physical
157
 * memory and create zones.
156
 * memory and create zones.
158
 *
157
 *
-
 
158
 * Note: It is assumed that the TLB is not yet being
-
 
159
 * used in any way, thus there is no interference.
-
 
160
 *
159
 */
161
 */
160
void frame_arch_init(void)
162
void frame_arch_init(void)
161
{
163
{
162
    cp0_index_write(ZERO_PAGE_TLBI);
164
    ipl_t ipl = interrupts_disable();
163
    tlbr();
-
 
164
   
165
   
-
 
166
    /* Clear and initialize TLB */
165
    uint32_t orig_pagemask = cp0_pagemask_read();
167
    cp0_pagemask_write(ZERO_PAGE_MASK);
166
    uint32_t orig_lo0 = cp0_entry_lo0_read();
168
    cp0_entry_lo0_write(0);
167
    uint32_t orig_lo1 = cp0_entry_lo1_read();
169
    cp0_entry_lo1_write(0);
168
    uint32_t orig_hi = cp0_entry_hi_read();
170
    cp0_entry_hi_write(0);
-
 
171
 
-
 
172
    count_t i;
-
 
173
    for (i = 0; i < TLB_ENTRY_COUNT; i++) {
-
 
174
        cp0_index_write(i);
-
 
175
        tlbwi();
-
 
176
    }
169
       
177
       
170
    pfn_t start_frame = 0;
178
    pfn_t start_frame = 0;
171
    pfn_t frame;
179
    pfn_t frame;
172
    bool avail = true;
180
    bool avail = true;
173
   
181
   
Line 182... Line 190...
182
                entry_hi_t hi;
190
                entry_hi_t hi;
183
                tlb_prepare_entry_lo(&lo0, false, true, true, false, frame << (ZERO_PAGE_WIDTH - 12));
191
                tlb_prepare_entry_lo(&lo0, false, true, true, false, frame << (ZERO_PAGE_WIDTH - 12));
184
                tlb_prepare_entry_lo(&lo1, false, false, false, false, 0);
192
                tlb_prepare_entry_lo(&lo1, false, false, false, false, 0);
185
                tlb_prepare_entry_hi(&hi, ZERO_PAGE_ASID, ZERO_PAGE_ADDR);
193
                tlb_prepare_entry_hi(&hi, ZERO_PAGE_ASID, ZERO_PAGE_ADDR);
186
               
194
               
187
                cp0_index_write(ZERO_PAGE_TLBI);
-
 
188
                cp0_pagemask_write(TLB_PAGE_MASK_1M);
195
                cp0_pagemask_write(ZERO_PAGE_MASK);
189
                cp0_entry_lo0_write(lo0.value);
196
                cp0_entry_lo0_write(lo0.value);
190
                cp0_entry_lo1_write(lo1.value);
197
                cp0_entry_lo1_write(lo1.value);
191
                cp0_entry_hi_write(hi.value);
198
                cp0_entry_hi_write(hi.value);
-
 
199
                cp0_index_write(ZERO_PAGE_TLBI);
192
                tlbwi();
200
                tlbwi();
193
               
201
               
194
                ZERO_PAGE_VALUE = 0;
202
                ZERO_PAGE_VALUE = 0;
195
                if (ZERO_PAGE_VALUE != 0)
203
                if (ZERO_PAGE_VALUE != 0)
196
                    avail = false;
204
                    avail = false;
Line 209... Line 217...
209
        }
217
        }
210
    }
218
    }
211
   
219
   
212
    frame_add_region(start_frame, frame);
220
    frame_add_region(start_frame, frame);
213
   
221
   
-
 
222
    /* Blacklist interrupt vector frame */
-
 
223
    frame_mark_unavailable(0, 1);
-
 
224
   
214
    /* Cleanup TLB */
225
    /* Cleanup */
-
 
226
    cp0_pagemask_write(ZERO_PAGE_MASK);
-
 
227
    cp0_entry_lo0_write(0);
-
 
228
    cp0_entry_lo1_write(0);
-
 
229
    cp0_entry_hi_write(0);
215
    cp0_index_write(ZERO_PAGE_TLBI);
230
    cp0_index_write(ZERO_PAGE_TLBI);
216
    cp0_pagemask_write(orig_pagemask);
-
 
217
    cp0_entry_lo0_write(orig_lo0);
-
 
218
    cp0_entry_lo1_write(orig_lo1);
-
 
219
    cp0_entry_hi_write(orig_hi);
-
 
220
    tlbwi();
231
    tlbwi();
221
   
232
   
222
    /* Blacklist interrupt vector frame */
233
    interrupts_restore(ipl);
223
    frame_mark_unavailable(0, 1);
-
 
224
}
234
}
225
 
235
 
226
 
236
 
227
void physmem_print(void)
237
void physmem_print(void)
228
{
238
{