| 1 | /* |
|---|
| 2 | * itlb inval: a write to a PTE2 should invalidate the corresponding |
|---|
| 3 | * itlb and dtlb entries. |
|---|
| 4 | */ |
|---|
| 5 | #include <registers.h> |
|---|
| 6 | #include <misc.h> |
|---|
| 7 | #include <vcache.h> |
|---|
| 8 | |
|---|
| 9 | .text |
|---|
| 10 | .globl _start |
|---|
| 11 | _start: |
|---|
| 12 | .set noreorder |
|---|
| 13 | la k0, TTY_BASE |
|---|
| 14 | la k1, EXIT_BASE |
|---|
| 15 | |
|---|
| 16 | PRINT(startstr) |
|---|
| 17 | |
|---|
| 18 | /* reset cop0 status (keep BEV) */ |
|---|
| 19 | lui a0, 0x0040; |
|---|
| 20 | mtc0 a0, COP0_STATUS |
|---|
| 21 | |
|---|
| 22 | la a0, pte1_a |
|---|
| 23 | srl a0, a0, 13 |
|---|
| 24 | mtc2 a0, VC_PTPR |
|---|
| 25 | nop |
|---|
| 26 | |
|---|
| 27 | li a0, VC_TLB_EN_ITLB | VC_TLB_EN_DTLB | VC_TLB_EN_ICACHE | VC_TLB_EN_DCACHE |
|---|
| 28 | mtc2 a0, VC_TLB_EN |
|---|
| 29 | |
|---|
| 30 | PRINT(mmustr) |
|---|
| 31 | /* cause a DTLB miss */ |
|---|
| 32 | la t0, roval |
|---|
| 33 | lw a0, 0(t0) |
|---|
| 34 | PRINTX |
|---|
| 35 | PUTCHAR(' ') |
|---|
| 36 | |
|---|
| 37 | /* cause a itlb miss */ |
|---|
| 38 | jal doload |
|---|
| 39 | nop |
|---|
| 40 | PRINTX |
|---|
| 41 | PUTCHAR(' ') |
|---|
| 42 | |
|---|
| 43 | la t0, pte2_a |
|---|
| 44 | mtc2 t0, VC_DATA_L /* force dcache miss on write */ |
|---|
| 45 | mtc2 zero, VC_DATA_H |
|---|
| 46 | mtc2 zero, VC_DCACHE_INVAL_PA |
|---|
| 47 | la a0, (BOOT_ADDRESS+0x2000) >> 12 |
|---|
| 48 | sw a0, 12(t0) /* change PTE2 */ |
|---|
| 49 | sync |
|---|
| 50 | 1: |
|---|
| 51 | ll a0, 8(t0) |
|---|
| 52 | mtc2 t0, VC_DTLB_INVAL /* force tlb miss on write */ |
|---|
| 53 | la a0, PTE2_V | PTE2_C | PTE2_X |
|---|
| 54 | sc a0, 8(t0) |
|---|
| 55 | beqz a0, 1b |
|---|
| 56 | nop |
|---|
| 57 | |
|---|
| 58 | /* now we should get the second values */ |
|---|
| 59 | la t0, roval |
|---|
| 60 | lw a0, 0(t0) |
|---|
| 61 | PRINTX |
|---|
| 62 | PUTCHAR(' ') |
|---|
| 63 | |
|---|
| 64 | jal doload |
|---|
| 65 | nop |
|---|
| 66 | PRINTX |
|---|
| 67 | PUTCHAR('\n') |
|---|
| 68 | /* we should get there */ |
|---|
| 69 | EXIT(0) |
|---|
| 70 | |
|---|
| 71 | .globl excep |
|---|
| 72 | excep: |
|---|
| 73 | .set noreorder |
|---|
| 74 | PRINT(statusstr) |
|---|
| 75 | mfc0 a0, COP0_STATUS |
|---|
| 76 | PRINTX |
|---|
| 77 | |
|---|
| 78 | PRINT(causestr) |
|---|
| 79 | mfc0 a0, COP0_CAUSE |
|---|
| 80 | PRINTX |
|---|
| 81 | |
|---|
| 82 | PRINT(pcstr) |
|---|
| 83 | mfc0 a0, COP0_EXPC |
|---|
| 84 | PRINTX |
|---|
| 85 | |
|---|
| 86 | PRINT(badvastr) |
|---|
| 87 | mfc0 a0, COP_0_BADVADDR |
|---|
| 88 | PRINTX |
|---|
| 89 | |
|---|
| 90 | PUTCHAR('\n') |
|---|
| 91 | /* we should not get there */ |
|---|
| 92 | EXIT(1) |
|---|
| 93 | |
|---|
| 94 | .rodata: |
|---|
| 95 | statusstr: .ascii "status \0" |
|---|
| 96 | causestr: .ascii " cause \0" |
|---|
| 97 | pcstr: .ascii " pc \0" |
|---|
| 98 | badvastr: .ascii " badva \0" |
|---|
| 99 | mmustr: .ascii "mmu started \0" |
|---|
| 100 | startstr: .ascii "start\n\0" |
|---|
| 101 | |
|---|
| 102 | .org EXCEP_ADDRESS - BOOT_ADDRESS |
|---|
| 103 | .globl evect |
|---|
| 104 | evect: |
|---|
| 105 | j excep |
|---|
| 106 | nop |
|---|
| 107 | |
|---|
| 108 | /* |
|---|
| 109 | * code that will be switched by MMU switch. |
|---|
| 110 | * we use a ldscript trick here, to load this function at |
|---|
| 111 | * the appropriate address |
|---|
| 112 | */ |
|---|
| 113 | .section .text2, "ax" |
|---|
| 114 | .globl doload |
|---|
| 115 | doload: |
|---|
| 116 | jr ra |
|---|
| 117 | li a0, MAGIC1 |
|---|
| 118 | /* we should not get there */ |
|---|
| 119 | EXIT(1) |
|---|
| 120 | nop |
|---|
| 121 | roval: .word MAGIC2 |
|---|
| 122 | .align 12 |
|---|
| 123 | .globl doload2 |
|---|
| 124 | doload2: |
|---|
| 125 | jr ra |
|---|
| 126 | li a0, MAGIC2 |
|---|
| 127 | /* we should not get there */ |
|---|
| 128 | EXIT(1) |
|---|
| 129 | nop |
|---|
| 130 | roval2: .word MAGIC1 |
|---|
| 131 | |
|---|
| 132 | .data |
|---|
| 133 | .word MAGIC1 |
|---|
| 134 | testval: |
|---|
| 135 | .word MAGIC2 |
|---|
| 136 | .globl pte2_a |
|---|
| 137 | |
|---|
| 138 | /* |
|---|
| 139 | * one PD with a level 2 PTP: we change an entry in the PTP and |
|---|
| 140 | * check that the ITLB has been invalidated |
|---|
| 141 | */ |
|---|
| 142 | pte2_a: |
|---|
| 143 | .align 12 |
|---|
| 144 | .word PTE2_V | PTE2_C | PTE2_X |
|---|
| 145 | .word BOOT_ADDRESS >> 12 |
|---|
| 146 | .word PTE2_V | PTE2_C | PTE2_X |
|---|
| 147 | .word (BOOT_ADDRESS+0x1000) >> 12 |
|---|
| 148 | .org pte2_a + 4092 |
|---|
| 149 | .word 0 |
|---|
| 150 | .globl pte2_b |
|---|
| 151 | .globl pte1_a |
|---|
| 152 | pte1_a: |
|---|
| 153 | .align 13 |
|---|
| 154 | .word PTE1_V | PTE1_C | PTE1_W | 0x0 /* map PA 0 at VA 0 */ |
|---|
| 155 | .word 0x0 |
|---|
| 156 | .org pte1_a + (BOOT_ADDRESS >> 21) * 4 |
|---|
| 157 | .word PTE1_V | PTE1_T | (0x1000 >> 12) /* map PA 0xbfc00000 at VA 0xbfc00000 with 4k page: check real address of pte2_a !!! */ |
|---|
| 158 | .org pte1_a + (TTY_BASE >> 21) * 4 |
|---|
| 159 | .word PTE1_V | PTE1_W | (TTY_BASE >> 21) /* map PA 0xd0200000 at VA 0xd0200000 */ |
|---|
| 160 | .org pte1_a + (EXIT_BASE >> 21) * 4 |
|---|
| 161 | .word PTE1_V | PTE1_W | (EXIT_BASE >> 21) /* map PA 0xe0000000 at VA 0xe0000000 */ |
|---|
| 162 | .org pte1_a + 8192 |
|---|