wdenk | 5c952cf | 2004-10-10 21:27:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004, Psyent Corporation <www.psyent.com> |
| 3 | * Scott McNutt <smcnutt@psyent.com> |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <config.h> |
| 25 | #include <asm/opcodes.h> |
| 26 | |
| 27 | |
| 28 | .text |
| 29 | .align 4 |
| 30 | |
| 31 | .global _exception |
| 32 | |
| 33 | _exception: |
| 34 | /* SAVE ALL REGS -- this allows trap and unimplemented |
| 35 | * instruction handlers to be coded conveniently in C |
| 36 | */ |
| 37 | addi sp, sp, -(33*4) |
| 38 | stw r0, 0(sp) |
| 39 | stw r1, 4(sp) |
| 40 | stw r2, 8(sp) |
| 41 | stw r3, 12(sp) |
| 42 | stw r4, 16(sp) |
| 43 | stw r5, 20(sp) |
| 44 | stw r6, 24(sp) |
| 45 | stw r7, 28(sp) |
| 46 | stw r8, 32(sp) |
| 47 | stw r9, 36(sp) |
| 48 | stw r10, 40(sp) |
| 49 | stw r11, 44(sp) |
| 50 | stw r12, 48(sp) |
| 51 | stw r13, 52(sp) |
| 52 | stw r14, 56(sp) |
| 53 | stw r15, 60(sp) |
| 54 | stw r16, 64(sp) |
| 55 | stw r17, 68(sp) |
| 56 | stw r19, 72(sp) |
| 57 | stw r19, 76(sp) |
| 58 | stw r20, 80(sp) |
| 59 | stw r21, 84(sp) |
| 60 | stw r22, 88(sp) |
| 61 | stw r23, 92(sp) |
| 62 | stw r24, 96(sp) |
| 63 | stw r25, 100(sp) |
| 64 | stw r26, 104(sp) |
| 65 | stw r27, 108(sp) |
| 66 | stw r28, 112(sp) |
| 67 | stw r29, 116(sp) |
| 68 | stw r30, 120(sp) |
| 69 | stw r31, 124(sp) |
| 70 | rdctl et, estatus |
| 71 | stw et, 128(sp) |
| 72 | |
| 73 | /* If interrupts are disabled -- software interrupt */ |
| 74 | rdctl et, estatus |
| 75 | andi et, et, 1 |
| 76 | beq et, r0, 0f |
| 77 | |
| 78 | /* If no interrupts are pending -- software interrupt */ |
| 79 | rdctl et, ipending |
| 80 | beq et, r0, 0f |
| 81 | |
| 82 | /* HARDWARE INTERRUPT: Call interrupt handler */ |
| 83 | movhi r3, %hi(external_interrupt) |
| 84 | ori r3, r3, %lo(external_interrupt) |
| 85 | mov r4, sp /* ptr to regs */ |
| 86 | callr r3 |
| 87 | |
| 88 | /* Return address fixup: execution resumes by re-issue of |
| 89 | * interrupted instruction at ea-4 (ea == r29). Here we do |
| 90 | * simple fixup to allow common exception return. |
| 91 | */ |
| 92 | ldw r3, 116(sp) |
| 93 | addi r3, r3, -4 |
| 94 | stw r3, 116(sp) |
| 95 | br _exception_return |
| 96 | |
| 97 | 0: |
| 98 | /* TRAP EXCEPTION */ |
| 99 | movhi r3, %hi(OPC_TRAP) |
| 100 | ori r3, r3, %lo(OPC_TRAP) |
| 101 | addi r1, ea, -4 |
| 102 | ldw r1, 0(r1) |
| 103 | bne r1, r3, 1f |
| 104 | movhi r3, %hi(trap_handler) |
| 105 | ori r3, r3, %lo(trap_handler) |
| 106 | mov r4, sp /* ptr to regs */ |
| 107 | callr r3 |
| 108 | br _exception_return |
| 109 | |
| 110 | 1: |
| 111 | /* UNIMPLEMENTED INSTRUCTION EXCEPTION */ |
| 112 | movhi r3, %hi(soft_emulation) |
| 113 | ori r3, r3, %lo(soft_emulation) |
| 114 | mov r4, sp /* ptr to regs */ |
| 115 | callr r3 |
| 116 | |
| 117 | /* Restore regsisters and return from exception*/ |
| 118 | _exception_return: |
| 119 | ldw r1, 4(sp) |
| 120 | ldw r2, 8(sp) |
| 121 | ldw r3, 12(sp) |
| 122 | ldw r4, 16(sp) |
| 123 | ldw r5, 20(sp) |
| 124 | ldw r6, 24(sp) |
| 125 | ldw r7, 28(sp) |
| 126 | ldw r8, 32(sp) |
| 127 | ldw r9, 36(sp) |
| 128 | ldw r10, 40(sp) |
| 129 | ldw r11, 44(sp) |
| 130 | ldw r12, 48(sp) |
| 131 | ldw r13, 52(sp) |
| 132 | ldw r14, 56(sp) |
| 133 | ldw r15, 60(sp) |
| 134 | ldw r16, 64(sp) |
| 135 | ldw r17, 68(sp) |
| 136 | ldw r19, 72(sp) |
| 137 | ldw r19, 76(sp) |
| 138 | ldw r20, 80(sp) |
| 139 | ldw r21, 84(sp) |
| 140 | ldw r22, 88(sp) |
| 141 | ldw r23, 92(sp) |
| 142 | ldw r24, 96(sp) |
| 143 | ldw r25, 100(sp) |
| 144 | ldw r26, 104(sp) |
| 145 | ldw r27, 108(sp) |
| 146 | ldw r28, 112(sp) |
| 147 | ldw r29, 116(sp) |
| 148 | ldw r30, 120(sp) |
| 149 | ldw r31, 124(sp) |
| 150 | addi sp, sp, (33*4) |
| 151 | eret |
| 152 | /*-------------------------------------------------------------*/ |