| 1 | /* |
|---|
| 2 | * instruction fetch causes the PTE_L bit to be set |
|---|
| 3 | */ |
|---|
| 4 | #include <registers.h> |
|---|
| 5 | #include <misc.h> |
|---|
| 6 | #include <vcache.h> |
|---|
| 7 | |
|---|
| 8 | .text |
|---|
| 9 | .globl _start |
|---|
| 10 | _start: |
|---|
| 11 | .set noreorder |
|---|
| 12 | la k0, TTY_BASE |
|---|
| 13 | la k1, EXIT_BASE |
|---|
| 14 | |
|---|
| 15 | PRINT(startstr) |
|---|
| 16 | |
|---|
| 17 | /* reset cop0 status (keep BEV) */ |
|---|
| 18 | lui a0, 0x0040; |
|---|
| 19 | mtc0 a0, COP0_STATUS |
|---|
| 20 | |
|---|
| 21 | la a0, pte1_a |
|---|
| 22 | srl a0, a0, 13 |
|---|
| 23 | mtc2 a0, VC_PTPR |
|---|
| 24 | nop |
|---|
| 25 | |
|---|
| 26 | li a0, VC_TLB_EN_ITLB | VC_TLB_EN_DTLB | VC_TLB_EN_ICACHE | VC_TLB_EN_DCACHE |
|---|
| 27 | mtc2 a0, VC_TLB_EN |
|---|
| 28 | |
|---|
| 29 | PRINT(mmustr) |
|---|
| 30 | la s0, pte2_a |
|---|
| 31 | lw s1, 8(s0) |
|---|
| 32 | move a0, s1 |
|---|
| 33 | PRINTX |
|---|
| 34 | PUTCHAR(' ') |
|---|
| 35 | la a1, PTE2_L |
|---|
| 36 | and a0, s1, a1 |
|---|
| 37 | beq a0, a1, fail /* PTE2_L already set, not good */ |
|---|
| 38 | nop |
|---|
| 39 | jal doload /* cause page to be referenced */ |
|---|
| 40 | nop |
|---|
| 41 | lw s1, 8(s0) |
|---|
| 42 | move a0, s1 |
|---|
| 43 | PRINTX |
|---|
| 44 | PUTCHAR(' ') |
|---|
| 45 | la a1, PTE2_L |
|---|
| 46 | and a0, s1, a1 |
|---|
| 47 | bne a0, a1, fail /* PTE2_L not set not good */ |
|---|
| 48 | nop |
|---|
| 49 | /* check again, using ll */ |
|---|
| 50 | ll s1, 8(s0) |
|---|
| 51 | move a0, s1 |
|---|
| 52 | PRINTX |
|---|
| 53 | PUTCHAR('\n') |
|---|
| 54 | la a1, PTE2_L |
|---|
| 55 | and a0, s1, a1 |
|---|
| 56 | bne a0, a1, fail /* PTE2_L not set not good */ |
|---|
| 57 | nop |
|---|
| 58 | EXIT(0) |
|---|
| 59 | fail: |
|---|
| 60 | /* we should not get there */ |
|---|
| 61 | EXIT(1) |
|---|
| 62 | |
|---|
| 63 | .globl excep |
|---|
| 64 | excep: |
|---|
| 65 | .set noreorder |
|---|
| 66 | PRINT(statusstr) |
|---|
| 67 | mfc0 a0, COP0_STATUS |
|---|
| 68 | PRINTX |
|---|
| 69 | |
|---|
| 70 | PRINT(causestr) |
|---|
| 71 | mfc0 a0, COP0_CAUSE |
|---|
| 72 | PRINTX |
|---|
| 73 | |
|---|
| 74 | PRINT(pcstr) |
|---|
| 75 | mfc0 a0, COP0_EXPC |
|---|
| 76 | PRINTX |
|---|
| 77 | |
|---|
| 78 | PRINT(badvastr) |
|---|
| 79 | mfc0 a0, COP_0_BADVADDR |
|---|
| 80 | PRINTX |
|---|
| 81 | |
|---|
| 82 | PUTCHAR('\n') |
|---|
| 83 | /* we should get there */ |
|---|
| 84 | EXIT(0) |
|---|
| 85 | |
|---|
| 86 | .rodata: |
|---|
| 87 | statusstr: .ascii "status \0" |
|---|
| 88 | causestr: .ascii " cause \0" |
|---|
| 89 | pcstr: .ascii " pc \0" |
|---|
| 90 | badvastr: .ascii " badva \0" |
|---|
| 91 | mmustr: .ascii "mmu started \0" |
|---|
| 92 | startstr: .ascii "start\n\0" |
|---|
| 93 | |
|---|
| 94 | .org EXCEP_ADDRESS - BOOT_ADDRESS |
|---|
| 95 | .globl evect |
|---|
| 96 | evect: |
|---|
| 97 | j excep |
|---|
| 98 | nop |
|---|
| 99 | |
|---|
| 100 | /* |
|---|
| 101 | * code that will be switched by MMU switch. |
|---|
| 102 | * we use a ldscript trick here, to load this function at |
|---|
| 103 | * the appropriate address |
|---|
| 104 | */ |
|---|
| 105 | .section .text2, "ax" |
|---|
| 106 | .globl doload |
|---|
| 107 | doload: |
|---|
| 108 | jr ra |
|---|
| 109 | li a0, MAGIC1 |
|---|
| 110 | /* we should not get there */ |
|---|
| 111 | EXIT(1) |
|---|
| 112 | nop |
|---|
| 113 | |
|---|
| 114 | .data |
|---|
| 115 | .word MAGIC1 |
|---|
| 116 | testval: |
|---|
| 117 | .word MAGIC2 |
|---|
| 118 | .globl pte2_a |
|---|
| 119 | |
|---|
| 120 | /* |
|---|
| 121 | * one PD with a level 2 PTP: we invalidate an entry in the PTP and |
|---|
| 122 | * check that the VA is no longer accessible |
|---|
| 123 | */ |
|---|
| 124 | pte2_a: |
|---|
| 125 | .align 12 |
|---|
| 126 | .word PTE2_V | PTE2_C | PTE2_X |
|---|
| 127 | .word BOOT_ADDRESS >> 12 |
|---|
| 128 | .word PTE2_V | PTE2_C | PTE2_X |
|---|
| 129 | .word (BOOT_ADDRESS+0x1000) >> 12 |
|---|
| 130 | .org pte2_a + 4092 |
|---|
| 131 | .word 0 |
|---|
| 132 | .globl pte2_b |
|---|
| 133 | .globl pte1_a |
|---|
| 134 | pte1_a: |
|---|
| 135 | .align 13 |
|---|
| 136 | .word PTE1_V | PTE1_C | PTE1_W | 0x0 /* map PA 0 at VA 0 */ |
|---|
| 137 | .word 0x0 |
|---|
| 138 | .org pte1_a + (BOOT_ADDRESS >> 21) * 4 |
|---|
| 139 | .word PTE1_V | PTE1_T | (0x1000 >> 12) /* map PA 0xbfc00000 at VA 0xbfc00000 with 4k page: check real address of pte2_a !!! */ |
|---|
| 140 | .org pte1_a + (TTY_BASE >> 21) * 4 |
|---|
| 141 | .word PTE1_V | PTE1_W | (TTY_BASE >> 21) /* map PA 0xd0200000 at VA 0xd0200000 */ |
|---|
| 142 | .org pte1_a + (EXIT_BASE >> 21) * 4 |
|---|
| 143 | .word PTE1_V | PTE1_W | (EXIT_BASE >> 21) /* map PA 0xe0000000 at VA 0xe0000000 */ |
|---|
| 144 | .org pte1_a + 8192 |
|---|