1 /* 2 * Handler routines. 3 * 4 * Copyright (C) 2008 by Maurus Cuelenaere 5 * Copyright (C) 2015 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 irq_handle 23 .globl real_exception_handler 24 .set noreorder 25 .set noat 26 27 #define C0_STATUS $12 28 #define C0_CAUSE $13 29 #define C0_EPC $14 30 #define C0_CONFIG $16 31 #define S_CauseExcCode 2 32 #define M_CauseExcCode (0x1f << S_CauseExcCode) 33 34 real_exception_handler: 35 addiu $sp, -0x80 36 sw $ra, 0($sp) 37 sw $fp, 4($sp) 38 sw $gp, 8($sp) 39 sw $t9, 0xC($sp) 40 sw $t8, 0x10($sp) 41 sw $s7, 0x14($sp) 42 sw $s6, 0x18($sp) 43 sw $s5, 0x1C($sp) 44 sw $s4, 0x20($sp) 45 sw $s3, 0x24($sp) 46 sw $s2, 0x28($sp) 47 sw $s1, 0x2C($sp) 48 sw $s0, 0x30($sp) 49 sw $t7, 0x34($sp) 50 sw $t6, 0x38($sp) 51 sw $t5, 0x3C($sp) 52 sw $t4, 0x40($sp) 53 sw $t3, 0x44($sp) 54 sw $t2, 0x48($sp) 55 sw $t1, 0x4C($sp) 56 sw $t0, 0x50($sp) 57 sw $a3, 0x54($sp) 58 sw $a2, 0x58($sp) 59 sw $a1, 0x5C($sp) 60 sw $a0, 0x60($sp) 61 sw $v1, 0x64($sp) 62 sw $v0, 0x68($sp) 63 sw $1, 0x6C($sp) 64 mflo $k0 65 nop 66 sw $k0, 0x70($sp) 67 mfhi $k0 68 nop 69 sw $k0, 0x74($sp) 70 mfc0 $k0, C0_STATUS 71 sll $zero, 1 72 sll $zero, 1 73 sll $zero, 1 74 sll $zero, 1 75 sw $k0, 0x78($sp) 76 mfc0 $k0, C0_EPC 77 sll $zero, 1 78 sll $zero, 1 79 sll $zero, 1 80 sll $zero, 1 81 sw $k0, 0x7C($sp) 82 83 li $k1, M_CauseExcCode 84 mfc0 $k0, C0_CAUSE 85 and $k0, $k1 86 beq $zero, $k0, _int 87 nop 88 j _exception 89 nop 90 91 _int: 92 /* Invoke the handler. */ 93 94 jal irq_handle 95 nop 96 j _exception_return 97 98 _exception: 99 move $a0, $sp 100 mfc0 $a1, C0_CAUSE 101 sll $zero, 1 102 sll $zero, 1 103 sll $zero, 1 104 sll $zero, 1 105 mfc0 $a2, C0_EPC 106 sll $zero, 1 107 sll $zero, 1 108 sll $zero, 1 109 sll $zero, 1 110 /* jal exception_handler */ 111 j _exception_return 112 nop 113 114 _exception_return: 115 lw $ra, 0($sp) 116 lw $fp, 4($sp) 117 lw $gp, 8($sp) 118 lw $t9, 0xC($sp) 119 lw $t8, 0x10($sp) 120 lw $s7, 0x14($sp) 121 lw $s6, 0x18($sp) 122 lw $s5, 0x1C($sp) 123 lw $s4, 0x20($sp) 124 lw $s3, 0x24($sp) 125 lw $s2, 0x28($sp) 126 lw $s1, 0x2C($sp) 127 lw $s0, 0x30($sp) 128 lw $t7, 0x34($sp) 129 lw $t6, 0x38($sp) 130 lw $t5, 0x3C($sp) 131 lw $t4, 0x40($sp) 132 lw $t3, 0x44($sp) 133 lw $t2, 0x48($sp) 134 lw $t1, 0x4C($sp) 135 lw $t0, 0x50($sp) 136 lw $a3, 0x54($sp) 137 lw $a2, 0x58($sp) 138 lw $a1, 0x5C($sp) 139 lw $a0, 0x60($sp) 140 lw $v1, 0x64($sp) 141 lw $v0, 0x68($sp) 142 lw $1, 0x6C($sp) 143 lw $k0, 0x70($sp) 144 mtlo $k0 145 nop 146 lw $k0, 0x74($sp) 147 mthi $k0 148 nop 149 lw $k0, 0x78($sp) 150 mtc0 $k0, C0_STATUS 151 nop 152 sll $zero, 1 153 sll $zero, 1 154 sll $zero, 1 155 sll $zero, 1 156 lw $k0, 0x7C($sp) 157 mtc0 $k0, C0_EPC 158 nop 159 sll $zero, 1 160 sll $zero, 1 161 sll $zero, 1 162 sll $zero, 1 163 addiu $sp, 0x80 164 eret 165 nop 166 167 .set reorder 168 .set at