1 /* 2 * Handler routines. 3 * 4 * Copyright (C) 2015 Nicholas FitzRoy-Dale <wzdd.code@lardcave.net> 5 * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 .text 22 .extern tlb_handle 23 .extern irq_handle 24 .globl tlb_handler 25 .globl interrupt_handler 26 .set noreorder 27 .set noat 28 29 tlb_handler: 30 /* gp should have been set in the entrypoint. */ 31 32 jal save_state 33 nop 34 35 /* Invoke the handler. */ 36 37 jal tlb_handle 38 nop 39 40 j load_and_return 41 nop 42 43 interrupt_handler: 44 /* gp should have been set in the entrypoint. */ 45 46 jal save_state 47 nop 48 49 /* Invoke the handler. */ 50 51 jal irq_handle 52 nop 53 54 j load_and_return 55 nop 56 57 save_state: 58 /* Save the status, mask interrupts. */ 59 60 mfc0 $k0, $12 /* CP0_STATUS */ 61 li $k1, 0xffff03ff 62 and $k1, $k0, $k1 63 mtc0 $k1, $12 64 sw $k0, -120($sp) 65 66 sw $at, -4($sp) 67 sw $v0, -8($sp) 68 sw $v1, -12($sp) 69 sw $a0, -16($sp) 70 sw $a1, -20($sp) 71 sw $a2, -24($sp) 72 sw $a3, -28($sp) 73 sw $t0, -32($sp) 74 sw $t1, -36($sp) 75 sw $t2, -40($sp) 76 sw $t3, -44($sp) 77 sw $t4, -48($sp) 78 sw $t5, -52($sp) 79 sw $t6, -56($sp) 80 sw $t7, -60($sp) 81 sw $s0, -64($sp) 82 sw $s1, -68($sp) 83 sw $s2, -72($sp) 84 sw $s3, -76($sp) 85 sw $s4, -80($sp) 86 sw $s5, -84($sp) 87 sw $s6, -88($sp) 88 sw $s7, -92($sp) 89 sw $t8, -96($sp) 90 /* sw $t9, -100($sp) */ 91 /* sw $gp, -104($sp) */ 92 sw $fp, -108($sp) 93 /* sw $ra, -112($sp) */ 94 95 mfc0 $k0, $14 /* CP0_EPC */ 96 nop 97 sw $k0, -116($sp) 98 99 addi $sp, $sp, -120 100 j $ra 101 nop 102 103 load_and_return: 104 105 addi $sp, $sp, 120 106 107 lw $at, -4($sp) 108 lw $v0, -8($sp) 109 lw $v1, -12($sp) 110 lw $a0, -16($sp) 111 lw $a1, -20($sp) 112 lw $a2, -24($sp) 113 lw $a3, -28($sp) 114 lw $t0, -32($sp) 115 lw $t1, -36($sp) 116 lw $t2, -40($sp) 117 lw $t3, -44($sp) 118 lw $t4, -48($sp) 119 lw $t5, -52($sp) 120 lw $t6, -56($sp) 121 lw $t7, -60($sp) 122 lw $s0, -64($sp) 123 lw $s1, -68($sp) 124 lw $s2, -72($sp) 125 lw $s3, -76($sp) 126 lw $s4, -80($sp) 127 lw $s5, -84($sp) 128 lw $s6, -88($sp) 129 lw $s7, -92($sp) 130 lw $t8, -96($sp) 131 lw $t9, -100($sp) 132 lw $gp, -104($sp) 133 lw $fp, -108($sp) 134 lw $ra, -112($sp) 135 136 lw $k0, -116($sp) 137 mtc0 $k0, $14 /* CP0_EPC */ 138 nop 139 140 lw $k0, -120($sp) 141 mtc0 $k0, $12 /* CP0_STATUS */ 142 nop 143 144 eret 145 nop 146 147 .set reorder 148 .set at