Subversion Repositories HelenOS

Rev

Rev 3788 | Rev 3913 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 jermar 1
/*
2071 jermar 2
 * Copyright (c) 2003-2004 Jakub Jermar
1 jermar 3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
1776 jermar 29
/** @addtogroup mips32mm   
1702 cejka 30
 * @{
31
 */
32
/** @file
33
 */
34
 
1 jermar 35
#include <arch/mm/tlb.h>
727 jermar 36
#include <mm/asid.h>
1 jermar 37
#include <mm/tlb.h>
391 jermar 38
#include <mm/page.h>
703 jermar 39
#include <mm/as.h>
1 jermar 40
#include <arch/cp0.h>
41
#include <panic.h>
42
#include <arch.h>
268 palkovsky 43
#include <symtab.h>
391 jermar 44
#include <synch/spinlock.h>
45
#include <print.h>
396 jermar 46
#include <debug.h>
983 palkovsky 47
#include <align.h>
1595 palkovsky 48
#include <interrupt.h>
268 palkovsky 49
 
3392 jermar 50
static void tlb_refill_fail(istate_t *);
51
static void tlb_invalid_fail(istate_t *);
52
static void tlb_modified_fail(istate_t *);
391 jermar 53
 
3392 jermar 54
static pte_t *find_mapping_and_check(uintptr_t, int, istate_t *, int *);
399 jermar 55
 
3392 jermar 56
/** Initialize TLB.
391 jermar 57
 *
58
 * Invalidate all entries and mark wired entries.
59
 */
569 jermar 60
void tlb_arch_init(void)
389 jermar 61
{
599 jermar 62
    int i;
63
 
389 jermar 64
    cp0_pagemask_write(TLB_PAGE_MASK_16K);
599 jermar 65
    cp0_entry_hi_write(0);
66
    cp0_entry_lo0_write(0);
67
    cp0_entry_lo1_write(0);
389 jermar 68
 
599 jermar 69
    /* Clear and initialize TLB. */
70
 
71
    for (i = 0; i < TLB_ENTRY_COUNT; i++) {
72
        cp0_index_write(i);
73
        tlbwi();
74
    }
598 jermar 75
 
389 jermar 76
    /*
77
     * The kernel is going to make use of some wired
391 jermar 78
     * entries (e.g. mapping kernel stacks in kseg3).
389 jermar 79
     */
80
    cp0_wired_write(TLB_WIRED);
81
}
82
 
3392 jermar 83
/** Process TLB Refill Exception.
391 jermar 84
 *
3392 jermar 85
 * @param istate    Interrupted register context.
391 jermar 86
 */
958 jermar 87
void tlb_refill(istate_t *istate)
1 jermar 88
{
396 jermar 89
    entry_lo_t lo;
1044 jermar 90
    entry_hi_t hi;
91
    asid_t asid;
1780 jermar 92
    uintptr_t badvaddr;
391 jermar 93
    pte_t *pte;
1288 jermar 94
    int pfrc;
397 jermar 95
 
391 jermar 96
    badvaddr = cp0_badvaddr_read();
397 jermar 97
 
1044 jermar 98
    spinlock_lock(&AS->lock);
99
    asid = AS->asid;
100
    spinlock_unlock(&AS->lock);
399 jermar 101
 
1044 jermar 102
    page_table_lock(AS, true);
103
 
1411 jermar 104
    pte = find_mapping_and_check(badvaddr, PF_ACCESS_READ, istate, &pfrc);
1288 jermar 105
    if (!pte) {
106
        switch (pfrc) {
107
        case AS_PF_FAULT:
108
            goto fail;
109
            break;
110
        case AS_PF_DEFER:
111
            /*
112
             * The page fault came during copy_from_uspace()
113
             * or copy_to_uspace().
114
             */
115
            page_table_unlock(AS, true);
116
            return;
117
        default:
3790 svoboda 118
            panic("Unexpected pfrc (%d).", pfrc);
1288 jermar 119
        }
120
    }
391 jermar 121
 
122
    /*
394 jermar 123
     * Record access to PTE.
391 jermar 124
     */
394 jermar 125
    pte->a = 1;
391 jermar 126
 
3228 decky 127
    tlb_prepare_entry_hi(&hi, asid, badvaddr);
3392 jermar 128
    tlb_prepare_entry_lo(&lo, pte->g, pte->p, pte->d, pte->cacheable,
129
        pte->pfn);
394 jermar 130
 
391 jermar 131
    /*
132
     * New entry is to be inserted into TLB
133
     */
399 jermar 134
    cp0_entry_hi_write(hi.value);
3392 jermar 135
    if ((badvaddr / PAGE_SIZE) % 2 == 0) {
396 jermar 136
        cp0_entry_lo0_write(lo.value);
391 jermar 137
        cp0_entry_lo1_write(0);
138
    }
139
    else {
140
        cp0_entry_lo0_write(0);
396 jermar 141
        cp0_entry_lo1_write(lo.value);
391 jermar 142
    }
612 jermar 143
    cp0_pagemask_write(TLB_PAGE_MASK_16K);
391 jermar 144
    tlbwr();
145
 
1044 jermar 146
    page_table_unlock(AS, true);
391 jermar 147
    return;
148
 
149
fail:
1044 jermar 150
    page_table_unlock(AS, true);
958 jermar 151
    tlb_refill_fail(istate);
391 jermar 152
}
153
 
3392 jermar 154
/** Process TLB Invalid Exception.
394 jermar 155
 *
3392 jermar 156
 * @param istate    Interrupted register context.
394 jermar 157
 */
958 jermar 158
void tlb_invalid(istate_t *istate)
391 jermar 159
{
396 jermar 160
    tlb_index_t index;
1780 jermar 161
    uintptr_t badvaddr;
396 jermar 162
    entry_lo_t lo;
399 jermar 163
    entry_hi_t hi;
394 jermar 164
    pte_t *pte;
1288 jermar 165
    int pfrc;
394 jermar 166
 
167
    badvaddr = cp0_badvaddr_read();
168
 
169
    /*
170
     * Locate the faulting entry in TLB.
171
     */
399 jermar 172
    hi.value = cp0_entry_hi_read();
3228 decky 173
    tlb_prepare_entry_hi(&hi, hi.asid, badvaddr);
399 jermar 174
    cp0_entry_hi_write(hi.value);
394 jermar 175
    tlbp();
396 jermar 176
    index.value = cp0_index_read();
1044 jermar 177
 
178
    page_table_lock(AS, true); 
394 jermar 179
 
180
    /*
181
     * Fail if the entry is not in TLB.
182
     */
396 jermar 183
    if (index.p) {
184
        printf("TLB entry not found.\n");
394 jermar 185
        goto fail;
396 jermar 186
    }
394 jermar 187
 
1411 jermar 188
    pte = find_mapping_and_check(badvaddr, PF_ACCESS_READ, istate, &pfrc);
1288 jermar 189
    if (!pte) {
190
        switch (pfrc) {
191
        case AS_PF_FAULT:
192
            goto fail;
193
            break;
194
        case AS_PF_DEFER:
195
            /*
196
             * The page fault came during copy_from_uspace()
197
             * or copy_to_uspace().
198
             */
199
            page_table_unlock(AS, true);             
200
            return;
201
        default:
3790 svoboda 202
            panic("Unexpected pfrc (%d).", pfrc);
1288 jermar 203
        }
204
    }
394 jermar 205
 
206
    /*
207
     * Read the faulting TLB entry.
208
     */
209
    tlbr();
210
 
211
    /*
212
     * Record access to PTE.
213
     */
214
    pte->a = 1;
215
 
3392 jermar 216
    tlb_prepare_entry_lo(&lo, pte->g, pte->p, pte->d, pte->cacheable,
217
        pte->pfn);
394 jermar 218
 
219
    /*
220
     * The entry is to be updated in TLB.
221
     */
3392 jermar 222
    if ((badvaddr / PAGE_SIZE) % 2 == 0)
396 jermar 223
        cp0_entry_lo0_write(lo.value);
394 jermar 224
    else
396 jermar 225
        cp0_entry_lo1_write(lo.value);
612 jermar 226
    cp0_pagemask_write(TLB_PAGE_MASK_16K);
394 jermar 227
    tlbwi();
228
 
1044 jermar 229
    page_table_unlock(AS, true);
394 jermar 230
    return;
231
 
232
fail:
1044 jermar 233
    page_table_unlock(AS, true);
958 jermar 234
    tlb_invalid_fail(istate);
391 jermar 235
}
236
 
3392 jermar 237
/** Process TLB Modified Exception.
394 jermar 238
 *
3392 jermar 239
 * @param istate    Interrupted register context.
394 jermar 240
 */
958 jermar 241
void tlb_modified(istate_t *istate)
391 jermar 242
{
396 jermar 243
    tlb_index_t index;
1780 jermar 244
    uintptr_t badvaddr;
396 jermar 245
    entry_lo_t lo;
399 jermar 246
    entry_hi_t hi;
394 jermar 247
    pte_t *pte;
1288 jermar 248
    int pfrc;
394 jermar 249
 
250
    badvaddr = cp0_badvaddr_read();
251
 
252
    /*
253
     * Locate the faulting entry in TLB.
254
     */
399 jermar 255
    hi.value = cp0_entry_hi_read();
3228 decky 256
    tlb_prepare_entry_hi(&hi, hi.asid, badvaddr);
399 jermar 257
    cp0_entry_hi_write(hi.value);
394 jermar 258
    tlbp();
396 jermar 259
    index.value = cp0_index_read();
1044 jermar 260
 
261
    page_table_lock(AS, true); 
394 jermar 262
 
263
    /*
264
     * Fail if the entry is not in TLB.
265
     */
396 jermar 266
    if (index.p) {
267
        printf("TLB entry not found.\n");
394 jermar 268
        goto fail;
396 jermar 269
    }
394 jermar 270
 
1411 jermar 271
    pte = find_mapping_and_check(badvaddr, PF_ACCESS_WRITE, istate, &pfrc);
1288 jermar 272
    if (!pte) {
273
        switch (pfrc) {
274
        case AS_PF_FAULT:
275
            goto fail;
276
            break;
277
        case AS_PF_DEFER:
278
            /*
279
             * The page fault came during copy_from_uspace()
280
             * or copy_to_uspace().
281
             */
282
            page_table_unlock(AS, true);             
283
            return;
284
        default:
3790 svoboda 285
            panic("Unexpected pfrc (%d).", pfrc);
1288 jermar 286
        }
287
    }
394 jermar 288
 
289
    /*
290
     * Read the faulting TLB entry.
291
     */
292
    tlbr();
293
 
294
    /*
295
     * Record access and write to PTE.
296
     */
297
    pte->a = 1;
831 jermar 298
    pte->d = 1;
394 jermar 299
 
3392 jermar 300
    tlb_prepare_entry_lo(&lo, pte->g, pte->p, pte->w, pte->cacheable,
301
        pte->pfn);
394 jermar 302
 
303
    /*
304
     * The entry is to be updated in TLB.
305
     */
3392 jermar 306
    if ((badvaddr / PAGE_SIZE) % 2 == 0)
396 jermar 307
        cp0_entry_lo0_write(lo.value);
394 jermar 308
    else
396 jermar 309
        cp0_entry_lo1_write(lo.value);
612 jermar 310
    cp0_pagemask_write(TLB_PAGE_MASK_16K);
394 jermar 311
    tlbwi();
312
 
1044 jermar 313
    page_table_unlock(AS, true);
394 jermar 314
    return;
315
 
316
fail:
1044 jermar 317
    page_table_unlock(AS, true);
958 jermar 318
    tlb_modified_fail(istate);
391 jermar 319
}
320
 
958 jermar 321
void tlb_refill_fail(istate_t *istate)
391 jermar 322
{
324 palkovsky 323
    char *symbol = "";
324
    char *sym2 = "";
325
 
958 jermar 326
    char *s = get_symtab_entry(istate->epc);
332 palkovsky 327
    if (s)
328
        symbol = s;
958 jermar 329
    s = get_symtab_entry(istate->ra);
332 palkovsky 330
    if (s)
331
        sym2 = s;
1595 palkovsky 332
 
3790 svoboda 333
    fault_if_from_uspace(istate, "TLB Refill Exception on %p.",
3392 jermar 334
        cp0_badvaddr_read());
3790 svoboda 335
    panic("%x: TLB Refill Exception at %x(%s<-%s).", cp0_badvaddr_read(),
3392 jermar 336
        istate->epc, symbol, sym2);
1 jermar 337
}
338
 
391 jermar 339
 
958 jermar 340
void tlb_invalid_fail(istate_t *istate)
1 jermar 341
{
268 palkovsky 342
    char *symbol = "";
343
 
958 jermar 344
    char *s = get_symtab_entry(istate->epc);
332 palkovsky 345
    if (s)
346
        symbol = s;
3790 svoboda 347
    fault_if_from_uspace(istate, "TLB Invalid Exception on %p.",
3392 jermar 348
        cp0_badvaddr_read());
3790 svoboda 349
    panic("%x: TLB Invalid Exception at %x(%s).", cp0_badvaddr_read(),
3392 jermar 350
        istate->epc, symbol);
1 jermar 351
}
352
 
958 jermar 353
void tlb_modified_fail(istate_t *istate)
389 jermar 354
{
355
    char *symbol = "";
356
 
958 jermar 357
    char *s = get_symtab_entry(istate->epc);
389 jermar 358
    if (s)
359
        symbol = s;
3790 svoboda 360
    fault_if_from_uspace(istate, "TLB Modified Exception on %p.",
3392 jermar 361
        cp0_badvaddr_read());
3790 svoboda 362
    panic("%x: TLB Modified Exception at %x(%s).", cp0_badvaddr_read(),
3392 jermar 363
        istate->epc, symbol);
389 jermar 364
}
365
 
3392 jermar 366
/** Try to find PTE for faulting address.
394 jermar 367
 *
703 jermar 368
 * The AS->lock must be held on entry to this function.
394 jermar 369
 *
3392 jermar 370
 * @param badvaddr  Faulting virtual address.
371
 * @param access    Access mode that caused the fault.
372
 * @param istate    Pointer to interrupted state.
373
 * @param pfrc      Pointer to variable where as_page_fault() return code
374
 *          will be stored.
394 jermar 375
 *
3392 jermar 376
 * @return      PTE on success, NULL otherwise.
394 jermar 377
 */
3392 jermar 378
pte_t *
379
find_mapping_and_check(uintptr_t badvaddr, int access, istate_t *istate,
380
    int *pfrc)
394 jermar 381
{
396 jermar 382
    entry_hi_t hi;
394 jermar 383
    pte_t *pte;
384
 
396 jermar 385
    hi.value = cp0_entry_hi_read();
394 jermar 386
 
387
    /*
388
     * Handler cannot succeed if the ASIDs don't match.
389
     */
703 jermar 390
    if (hi.asid != AS->asid) {
391
        printf("EntryHi.asid=%d, AS->asid=%d\n", hi.asid, AS->asid);
394 jermar 392
        return NULL;
396 jermar 393
    }
703 jermar 394
 
394 jermar 395
    /*
703 jermar 396
     * Check if the mapping exists in page tables.
397
     */
756 jermar 398
    pte = page_mapping_find(AS, badvaddr);
3393 jermar 399
    if (pte && pte->p && (pte->w || access != PF_ACCESS_WRITE)) {
703 jermar 400
        /*
401
         * Mapping found in page tables.
402
         * Immediately succeed.
403
         */
404
        return pte;
405
    } else {
1288 jermar 406
        int rc;
407
 
703 jermar 408
        /*
409
         * Mapping not found in page tables.
410
         * Resort to higher-level page fault handler.
411
         */
1044 jermar 412
        page_table_unlock(AS, true);
1411 jermar 413
        switch (rc = as_page_fault(badvaddr, access, istate)) {
1288 jermar 414
        case AS_PF_OK:
703 jermar 415
            /*
416
             * The higher-level page fault handler succeeded,
417
             * The mapping ought to be in place.
418
             */
1044 jermar 419
            page_table_lock(AS, true);
756 jermar 420
            pte = page_mapping_find(AS, badvaddr);
831 jermar 421
            ASSERT(pte && pte->p);
3393 jermar 422
            ASSERT(pte->w || access != PF_ACCESS_WRITE);
703 jermar 423
            return pte;
1288 jermar 424
            break;
425
        case AS_PF_DEFER:
1044 jermar 426
            page_table_lock(AS, true);
1288 jermar 427
            *pfrc = AS_PF_DEFER;
428
            return NULL;
429
            break;
430
        case AS_PF_FAULT:
431
            page_table_lock(AS, true);
432
            *pfrc = AS_PF_FAULT;
1044 jermar 433
            return NULL;
1288 jermar 434
            break;
435
        default:
3790 svoboda 436
            panic("Unexpected rc (%d).", rc);
703 jermar 437
        }
1044 jermar 438
 
703 jermar 439
    }
394 jermar 440
}
441
 
3392 jermar 442
void
443
tlb_prepare_entry_lo(entry_lo_t *lo, bool g, bool v, bool d, bool cacheable,
444
    uintptr_t pfn)
394 jermar 445
{
399 jermar 446
    lo->value = 0;
394 jermar 447
    lo->g = g;
448
    lo->v = v;
449
    lo->d = d;
831 jermar 450
    lo->c = cacheable ? PAGE_CACHEABLE_EXC_WRITE : PAGE_UNCACHED;
394 jermar 451
    lo->pfn = pfn;
452
}
399 jermar 453
 
3228 decky 454
void tlb_prepare_entry_hi(entry_hi_t *hi, asid_t asid, uintptr_t addr)
399 jermar 455
{
983 palkovsky 456
    hi->value = ALIGN_DOWN(addr, PAGE_SIZE * 2);
399 jermar 457
    hi->asid = asid;
458
}
569 jermar 459
 
594 jermar 460
/** Print contents of TLB. */
569 jermar 461
void tlb_print(void)
462
{
612 jermar 463
    page_mask_t mask;
594 jermar 464
    entry_lo_t lo0, lo1;
704 jermar 465
    entry_hi_t hi, hi_save;
2720 decky 466
    unsigned int i;
594 jermar 467
 
704 jermar 468
    hi_save.value = cp0_entry_hi_read();
2720 decky 469
 
470
    printf("#  ASID VPN2   MASK G V D C PFN\n");
471
    printf("-- ---- ------ ---- - - - - ------\n");
472
 
594 jermar 473
    for (i = 0; i < TLB_ENTRY_COUNT; i++) {
474
        cp0_index_write(i);
475
        tlbr();
476
 
612 jermar 477
        mask.value = cp0_pagemask_read();
594 jermar 478
        hi.value = cp0_entry_hi_read();
479
        lo0.value = cp0_entry_lo0_read();
480
        lo1.value = cp0_entry_lo1_read();
481
 
2720 decky 482
        printf("%-2u %-4u %#6x %#4x %1u %1u %1u %1u %#6x\n",
3392 jermar 483
            i, hi.asid, hi.vpn2, mask.mask,
484
            lo0.g, lo0.v, lo0.d, lo0.c, lo0.pfn);
2720 decky 485
        printf("                    %1u %1u %1u %1u %#6x\n",
3392 jermar 486
            lo1.g, lo1.v, lo1.d, lo1.c, lo1.pfn);
594 jermar 487
    }
704 jermar 488
 
489
    cp0_entry_hi_write(hi_save.value);
569 jermar 490
}
598 jermar 491
 
618 jermar 492
/** Invalidate all not wired TLB entries. */
598 jermar 493
void tlb_invalidate_all(void)
494
{
599 jermar 495
    ipl_t ipl;
496
    entry_lo_t lo0, lo1;
704 jermar 497
    entry_hi_t hi_save;
598 jermar 498
    int i;
499
 
704 jermar 500
    hi_save.value = cp0_entry_hi_read();
599 jermar 501
    ipl = interrupts_disable();
598 jermar 502
 
618 jermar 503
    for (i = TLB_WIRED; i < TLB_ENTRY_COUNT; i++) {
598 jermar 504
        cp0_index_write(i);
599 jermar 505
        tlbr();
506
 
507
        lo0.value = cp0_entry_lo0_read();
508
        lo1.value = cp0_entry_lo1_read();
509
 
510
        lo0.v = 0;
511
        lo1.v = 0;
512
 
513
        cp0_entry_lo0_write(lo0.value);
514
        cp0_entry_lo1_write(lo1.value);
515
 
598 jermar 516
        tlbwi();
517
    }
599 jermar 518
 
519
    interrupts_restore(ipl);
704 jermar 520
    cp0_entry_hi_write(hi_save.value);
598 jermar 521
}
522
 
523
/** Invalidate all TLB entries belonging to specified address space.
524
 *
525
 * @param asid Address space identifier.
526
 */
527
void tlb_invalidate_asid(asid_t asid)
528
{
599 jermar 529
    ipl_t ipl;
530
    entry_lo_t lo0, lo1;
704 jermar 531
    entry_hi_t hi, hi_save;
598 jermar 532
    int i;
533
 
599 jermar 534
    ASSERT(asid != ASID_INVALID);
535
 
704 jermar 536
    hi_save.value = cp0_entry_hi_read();
599 jermar 537
    ipl = interrupts_disable();
538
 
598 jermar 539
    for (i = 0; i < TLB_ENTRY_COUNT; i++) {
540
        cp0_index_write(i);
541
        tlbr();
542
 
599 jermar 543
        hi.value = cp0_entry_hi_read();
544
 
598 jermar 545
        if (hi.asid == asid) {
599 jermar 546
            lo0.value = cp0_entry_lo0_read();
547
            lo1.value = cp0_entry_lo1_read();
548
 
549
            lo0.v = 0;
550
            lo1.v = 0;
551
 
552
            cp0_entry_lo0_write(lo0.value);
553
            cp0_entry_lo1_write(lo1.value);
554
 
598 jermar 555
            tlbwi();
556
        }
557
    }
599 jermar 558
 
559
    interrupts_restore(ipl);
704 jermar 560
    cp0_entry_hi_write(hi_save.value);
598 jermar 561
}
562
 
3392 jermar 563
/** Invalidate TLB entries for specified page range belonging to specified
564
 * address space.
598 jermar 565
 *
3392 jermar 566
 * @param asid      Address space identifier.
567
 * @param page      First page whose TLB entry is to be invalidated.
568
 * @param cnt       Number of entries to invalidate.
598 jermar 569
 */
1780 jermar 570
void tlb_invalidate_pages(asid_t asid, uintptr_t page, count_t cnt)
598 jermar 571
{
2745 decky 572
    unsigned int i;
599 jermar 573
    ipl_t ipl;
574
    entry_lo_t lo0, lo1;
704 jermar 575
    entry_hi_t hi, hi_save;
598 jermar 576
    tlb_index_t index;
577
 
599 jermar 578
    ASSERT(asid != ASID_INVALID);
579
 
704 jermar 580
    hi_save.value = cp0_entry_hi_read();
599 jermar 581
    ipl = interrupts_disable();
582
 
2745 decky 583
    for (i = 0; i < cnt + 1; i += 2) {
727 jermar 584
        hi.value = 0;
3228 decky 585
        tlb_prepare_entry_hi(&hi, asid, page + i * PAGE_SIZE);
727 jermar 586
        cp0_entry_hi_write(hi.value);
599 jermar 587
 
727 jermar 588
        tlbp();
589
        index.value = cp0_index_read();
598 jermar 590
 
727 jermar 591
        if (!index.p) {
3392 jermar 592
            /*
593
             * Entry was found, index register contains valid
594
             * index.
595
             */
727 jermar 596
            tlbr();
599 jermar 597
 
727 jermar 598
            lo0.value = cp0_entry_lo0_read();
599
            lo1.value = cp0_entry_lo1_read();
599 jermar 600
 
727 jermar 601
            lo0.v = 0;
602
            lo1.v = 0;
599 jermar 603
 
727 jermar 604
            cp0_entry_lo0_write(lo0.value);
605
            cp0_entry_lo1_write(lo1.value);
599 jermar 606
 
727 jermar 607
            tlbwi();
608
        }
598 jermar 609
    }
599 jermar 610
 
611
    interrupts_restore(ipl);
704 jermar 612
    cp0_entry_hi_write(hi_save.value);
598 jermar 613
}
1702 cejka 614
 
1776 jermar 615
/** @}
1702 cejka 616
 */