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