paul@68 | 1 | /* |
paul@114 | 2 | * Interrupt and TLB miss handling support. |
paul@68 | 3 | * |
paul@114 | 4 | * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> |
paul@68 | 5 | * |
paul@68 | 6 | * This program is free software: you can redistribute it and/or modify |
paul@68 | 7 | * it under the terms of the GNU General Public License as published by |
paul@68 | 8 | * the Free Software Foundation, either version 3 of the License, or |
paul@68 | 9 | * (at your option) any later version. |
paul@68 | 10 | * |
paul@68 | 11 | * This program is distributed in the hope that it will be useful, |
paul@68 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@68 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@68 | 14 | * GNU General Public License for more details. |
paul@68 | 15 | * |
paul@68 | 16 | * You should have received a copy of the GNU General Public License |
paul@68 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
paul@68 | 18 | */ |
paul@68 | 19 | |
paul@68 | 20 | .text |
paul@86 | 21 | .extern interrupt_handler |
paul@145 | 22 | .extern current_registers |
paul@145 | 23 | .extern current_stack_pointer |
paul@114 | 24 | .globl _tlb_entry |
paul@141 | 25 | .globl _exc_entry |
paul@68 | 26 | .globl _irq_entry |
paul@68 | 27 | .globl _end_entries |
paul@68 | 28 | .set noreorder |
paul@68 | 29 | |
paul@151 | 30 | #include "paging.h" |
paul@136 | 31 | |
paul@114 | 32 | _tlb_entry: |
paul@136 | 33 | /* Get the bad address. */ |
paul@136 | 34 | |
paul@136 | 35 | mfc0 $k0, $10 /* CP0_ENTRYHI */ |
paul@136 | 36 | nop |
paul@136 | 37 | andi $k1, $k0, 0xff /* ASID */ |
paul@136 | 38 | |
paul@136 | 39 | /* For ASID == 0... */ |
paul@136 | 40 | |
paul@136 | 41 | beqz $k1, _tlb_entry_direct |
paul@136 | 42 | nop |
paul@136 | 43 | |
paul@136 | 44 | /* Otherwise, load the page table entries. */ |
paul@136 | 45 | |
paul@136 | 46 | andi $k1, $k0, 0xff /* ASID */ |
paul@146 | 47 | li $k0, page_table_task_size |
paul@146 | 48 | mul $k0, $k0, $k1 /* [ASID] (ASID * page_table_task_size) */ |
paul@146 | 49 | li $k1, page_table_start /* page_table */ |
paul@146 | 50 | addu $k1, $k0, $k1 /* page_table[ASID] */ |
paul@136 | 51 | |
paul@146 | 52 | mfc0 $k0, $4 /* CP0_CONTEXT */ |
paul@136 | 53 | nop |
paul@146 | 54 | srl $k0, $k0, 1 /* use 8 byte - not 16 byte - entries */ |
paul@146 | 55 | addu $k0, $k0, $k1 /* page_table[ASID][entry] */ |
paul@136 | 56 | |
paul@136 | 57 | lw $k1, 0($k0) /* page_table[ASID][entry][0] */ |
paul@136 | 58 | mtc0 $k1, $2 /* CP0_ENTRYLO0 */ |
paul@146 | 59 | |
paul@136 | 60 | lw $k1, 4($k0) /* page_table[ASID][entry][1] */ |
paul@136 | 61 | mtc0 $k1, $3 /* CP0_ENTRYLO1 */ |
paul@136 | 62 | /* page size is 4KB */ |
paul@136 | 63 | mtc0 $zero, $5 /* CP0_PAGEMASK */ |
paul@136 | 64 | nop |
paul@136 | 65 | |
paul@136 | 66 | tlbwr |
paul@136 | 67 | nop |
paul@167 | 68 | |
paul@181 | 69 | eret |
paul@136 | 70 | nop |
paul@136 | 71 | |
paul@136 | 72 | _tlb_entry_direct: |
paul@136 | 73 | /* Otherwise, just translate the address directly. */ |
paul@136 | 74 | |
paul@136 | 75 | li $k1, 0xffffe000 |
paul@136 | 76 | and $k0, $k0, $k1 /* VPN2 (8KB resolution) */ |
paul@136 | 77 | srl $k0, $k0, 6 /* PFN (maintain 8KB resolution, bit 6 remaining zero) */ |
paul@136 | 78 | ori $k0, $k0, 0x1e /* flags */ |
paul@136 | 79 | |
paul@136 | 80 | mtc0 $k0, $2 /* CP0_ENTRYLO0 */ |
paul@136 | 81 | ori $k0, $k0, 0x40 /* page size is 4KB (bit 6 set) */ |
paul@136 | 82 | mtc0 $k0, $3 /* CP0_ENTRYLO1 */ |
paul@136 | 83 | nop /* page size is 4KB */ |
paul@136 | 84 | mtc0 $zero, $5 /* CP0_PAGEMASK */ |
paul@136 | 85 | nop |
paul@136 | 86 | |
paul@136 | 87 | tlbwr |
paul@136 | 88 | nop |
paul@170 | 89 | |
paul@172 | 90 | eret |
paul@172 | 91 | nop |
paul@172 | 92 | |
paul@141 | 93 | _exc_entry: |
paul@141 | 94 | /* Handle TLB refill exceptions. */ |
paul@141 | 95 | |
paul@141 | 96 | mfc0 $k0, $13 /* CP0_CAUSE */ |
paul@141 | 97 | li $k1, 0x0000007c |
paul@141 | 98 | and $k0, $k0, $k1 /* ExcCode << 2 */ |
paul@141 | 99 | srl $k0, $k0, 2 /* ExcCode */ |
paul@141 | 100 | addi $k1, $k0, -2 /* ExcCode == 2 */ |
paul@141 | 101 | beqz $k1, _tlb_entry |
paul@141 | 102 | addi $k1, $k0, -3 /* ExcCode == 3 */ |
paul@141 | 103 | beqz $k1, _tlb_entry |
paul@141 | 104 | nop |
paul@141 | 105 | _fail: |
paul@141 | 106 | b _fail |
paul@141 | 107 | nop |
paul@141 | 108 | |
paul@136 | 109 | _irq_entry: |
paul@145 | 110 | /* Set the ASID. */ |
paul@145 | 111 | |
paul@145 | 112 | mtc0 $zero, $10 /* CP0_ENTRYHI */ |
paul@145 | 113 | nop |
paul@145 | 114 | |
paul@145 | 115 | /* Obtain the kernel global offset table. */ |
paul@145 | 116 | |
paul@145 | 117 | move $k0, $gp |
paul@145 | 118 | lui $gp, %hi(_GLOBAL_OFFSET_TABLE_) |
paul@145 | 119 | ori $gp, $gp, %lo(_GLOBAL_OFFSET_TABLE_) |
paul@145 | 120 | |
paul@145 | 121 | /* Obtain a store of registers for the current task. */ |
paul@145 | 122 | |
paul@145 | 123 | la $k1, current_registers |
paul@145 | 124 | lw $k1, 0($k1) |
paul@145 | 125 | |
paul@127 | 126 | /* Save registers that the assembler wants to trash. */ |
paul@127 | 127 | |
paul@145 | 128 | sw $t9, 100($k1) |
paul@145 | 129 | sw $k0, 104($k1) /* old gp */ |
paul@145 | 130 | sw $ra, 112($k1) |
paul@145 | 131 | |
paul@145 | 132 | /* Record the stack pointer. */ |
paul@127 | 133 | |
paul@145 | 134 | la $k1, current_stack_pointer |
paul@145 | 135 | lw $k1, 0($k1) /* &stack_pointers[current_task] */ |
paul@145 | 136 | sw $sp, 0($k1) |
paul@145 | 137 | |
paul@145 | 138 | /* Switch to the kernel stack. */ |
paul@145 | 139 | |
paul@145 | 140 | li $sp, 0x80070000 |
paul@145 | 141 | |
paul@145 | 142 | /* Invoke the rest of the interrupt handling process. */ |
paul@145 | 143 | |
paul@122 | 144 | la $k0, interrupt_handler |
paul@68 | 145 | jr $k0 |
paul@68 | 146 | nop |
paul@68 | 147 | |
paul@68 | 148 | _end_entries: |
paul@68 | 149 | |
paul@68 | 150 | .set reorder |