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 irq_handle 23 .extern current_stack_pointer 24 .extern current_task 25 .globl interrupt_handler 26 .set noreorder 27 .set noat 28 29 interrupt_handler: 30 /* gp should have been set in the entrypoint. */ 31 32 jal save_state 33 nop 34 35 /* Record the stack pointer. */ 36 37 la $k0, current_stack_pointer 38 sw $sp, 0($k0) 39 40 /* Invoke the handler. */ 41 42 jal irq_handle 43 nop 44 45 /* Switch the stack pointer. */ 46 47 la $k0, current_stack_pointer 48 lw $sp, 0($k0) 49 50 /* Set the current task ASID. */ 51 52 la $k0, current_task 53 lw $k1, 0($k0) 54 mtc0 $k1, $10 /* CP0_ENTRYHI */ 55 nop 56 57 j load_and_return 58 nop 59 60 save_state: 61 sw $at, -4($sp) 62 sw $v0, -8($sp) 63 sw $v1, -12($sp) 64 sw $a0, -16($sp) 65 sw $a1, -20($sp) 66 sw $a2, -24($sp) 67 sw $a3, -28($sp) 68 sw $t0, -32($sp) 69 sw $t1, -36($sp) 70 sw $t2, -40($sp) 71 sw $t3, -44($sp) 72 sw $t4, -48($sp) 73 sw $t5, -52($sp) 74 sw $t6, -56($sp) 75 sw $t7, -60($sp) 76 sw $s0, -64($sp) 77 sw $s1, -68($sp) 78 sw $s2, -72($sp) 79 sw $s3, -76($sp) 80 sw $s4, -80($sp) 81 sw $s5, -84($sp) 82 sw $s6, -88($sp) 83 sw $s7, -92($sp) 84 sw $t8, -96($sp) 85 /* sw $t9, -100($sp) */ 86 /* sw $gp, -104($sp) */ 87 sw $fp, -108($sp) 88 /* sw $ra, -112($sp) */ 89 90 mfc0 $k0, $14 /* CP0_EPC */ 91 nop 92 sw $k0, -116($sp) 93 94 addi $sp, $sp, -120 95 j $ra 96 nop 97 98 load_and_return: 99 100 addi $sp, $sp, 120 101 102 lw $at, -4($sp) 103 lw $v0, -8($sp) 104 lw $v1, -12($sp) 105 lw $a0, -16($sp) 106 lw $a1, -20($sp) 107 lw $a2, -24($sp) 108 lw $a3, -28($sp) 109 lw $t0, -32($sp) 110 lw $t1, -36($sp) 111 lw $t2, -40($sp) 112 lw $t3, -44($sp) 113 lw $t4, -48($sp) 114 lw $t5, -52($sp) 115 lw $t6, -56($sp) 116 lw $t7, -60($sp) 117 lw $s0, -64($sp) 118 lw $s1, -68($sp) 119 lw $s2, -72($sp) 120 lw $s3, -76($sp) 121 lw $s4, -80($sp) 122 lw $s5, -84($sp) 123 lw $s6, -88($sp) 124 lw $s7, -92($sp) 125 lw $t8, -96($sp) 126 lw $t9, -100($sp) 127 lw $gp, -104($sp) 128 lw $fp, -108($sp) 129 lw $ra, -112($sp) 130 131 lw $k0, -116($sp) 132 mtc0 $k0, $14 /* CP0_EPC */ 133 nop 134 135 lw $k0, -120($sp) 136 mtc0 $k0, $12 /* CP0_STATUS */ 137 nop 138 139 eret 140 nop 141 142 .set reorder 143 .set at