1ab3b491fSBlue Swirl /* 2ab3b491fSBlue Swirl * Sparc32 interrupt helpers 3ab3b491fSBlue Swirl * 4ab3b491fSBlue Swirl * Copyright (c) 2003-2005 Fabrice Bellard 5ab3b491fSBlue Swirl * 6ab3b491fSBlue Swirl * This library is free software; you can redistribute it and/or 7ab3b491fSBlue Swirl * modify it under the terms of the GNU Lesser General Public 8ab3b491fSBlue Swirl * License as published by the Free Software Foundation; either 95650b549SChetan Pant * version 2.1 of the License, or (at your option) any later version. 10ab3b491fSBlue Swirl * 11ab3b491fSBlue Swirl * This library is distributed in the hope that it will be useful, 12ab3b491fSBlue Swirl * but WITHOUT ANY WARRANTY; without even the implied warranty of 13ab3b491fSBlue Swirl * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14ab3b491fSBlue Swirl * Lesser General Public License for more details. 15ab3b491fSBlue Swirl * 16ab3b491fSBlue Swirl * You should have received a copy of the GNU Lesser General Public 17ab3b491fSBlue Swirl * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18ab3b491fSBlue Swirl */ 19ab3b491fSBlue Swirl 20db5ebe5fSPeter Maydell #include "qemu/osdep.h" 21*10fb1340SPhilippe Mathieu-Daudé #include "qemu/main-loop.h" 22ab3b491fSBlue Swirl #include "cpu.h" 2311e66bcaSBlue Swirl #include "trace.h" 24508127e2SPaolo Bonzini #include "exec/log.h" 2554d31236SMarkus Armbruster #include "sysemu/runstate.h" 26ab3b491fSBlue Swirl 27ab3b491fSBlue Swirl 28ab3b491fSBlue Swirl static const char * const excp_names[0x80] = { 29ab3b491fSBlue Swirl [TT_TFAULT] = "Instruction Access Fault", 30ab3b491fSBlue Swirl [TT_ILL_INSN] = "Illegal Instruction", 31ab3b491fSBlue Swirl [TT_PRIV_INSN] = "Privileged Instruction", 32ab3b491fSBlue Swirl [TT_NFPU_INSN] = "FPU Disabled", 33ab3b491fSBlue Swirl [TT_WIN_OVF] = "Window Overflow", 34ab3b491fSBlue Swirl [TT_WIN_UNF] = "Window Underflow", 35ab3b491fSBlue Swirl [TT_UNALIGNED] = "Unaligned Memory Access", 36ab3b491fSBlue Swirl [TT_FP_EXCP] = "FPU Exception", 37ab3b491fSBlue Swirl [TT_DFAULT] = "Data Access Fault", 38ab3b491fSBlue Swirl [TT_TOVF] = "Tag Overflow", 39ab3b491fSBlue Swirl [TT_EXTINT | 0x1] = "External Interrupt 1", 40ab3b491fSBlue Swirl [TT_EXTINT | 0x2] = "External Interrupt 2", 41ab3b491fSBlue Swirl [TT_EXTINT | 0x3] = "External Interrupt 3", 42ab3b491fSBlue Swirl [TT_EXTINT | 0x4] = "External Interrupt 4", 43ab3b491fSBlue Swirl [TT_EXTINT | 0x5] = "External Interrupt 5", 44ab3b491fSBlue Swirl [TT_EXTINT | 0x6] = "External Interrupt 6", 45ab3b491fSBlue Swirl [TT_EXTINT | 0x7] = "External Interrupt 7", 46ab3b491fSBlue Swirl [TT_EXTINT | 0x8] = "External Interrupt 8", 47ab3b491fSBlue Swirl [TT_EXTINT | 0x9] = "External Interrupt 9", 48ab3b491fSBlue Swirl [TT_EXTINT | 0xa] = "External Interrupt 10", 49ab3b491fSBlue Swirl [TT_EXTINT | 0xb] = "External Interrupt 11", 50ab3b491fSBlue Swirl [TT_EXTINT | 0xc] = "External Interrupt 12", 51ab3b491fSBlue Swirl [TT_EXTINT | 0xd] = "External Interrupt 13", 52ab3b491fSBlue Swirl [TT_EXTINT | 0xe] = "External Interrupt 14", 53ab3b491fSBlue Swirl [TT_EXTINT | 0xf] = "External Interrupt 15", 54ab3b491fSBlue Swirl [TT_CODE_ACCESS] = "Instruction Access Error", 55ab3b491fSBlue Swirl [TT_DATA_ACCESS] = "Data Access Error", 56ab3b491fSBlue Swirl [TT_DIV_ZERO] = "Division By Zero", 57ab3b491fSBlue Swirl [TT_NCP_INSN] = "Coprocessor Disabled", 58ab3b491fSBlue Swirl }; 59ab3b491fSBlue Swirl 6086e8c353SPhilippe Mathieu-Daudé static const char *excp_name_str(int32_t exception_index) 6186e8c353SPhilippe Mathieu-Daudé { 6286e8c353SPhilippe Mathieu-Daudé if (exception_index < 0 || exception_index >= ARRAY_SIZE(excp_names)) { 6386e8c353SPhilippe Mathieu-Daudé return "Unknown"; 6486e8c353SPhilippe Mathieu-Daudé } 6586e8c353SPhilippe Mathieu-Daudé return excp_names[exception_index]; 6686e8c353SPhilippe Mathieu-Daudé } 6786e8c353SPhilippe Mathieu-Daudé 68*10fb1340SPhilippe Mathieu-Daudé void cpu_check_irqs(CPUSPARCState *env) 69*10fb1340SPhilippe Mathieu-Daudé { 70*10fb1340SPhilippe Mathieu-Daudé CPUState *cs; 71*10fb1340SPhilippe Mathieu-Daudé 72*10fb1340SPhilippe Mathieu-Daudé /* We should be holding the BQL before we mess with IRQs */ 73*10fb1340SPhilippe Mathieu-Daudé g_assert(qemu_mutex_iothread_locked()); 74*10fb1340SPhilippe Mathieu-Daudé 75*10fb1340SPhilippe Mathieu-Daudé if (env->pil_in && (env->interrupt_index == 0 || 76*10fb1340SPhilippe Mathieu-Daudé (env->interrupt_index & ~15) == TT_EXTINT)) { 77*10fb1340SPhilippe Mathieu-Daudé unsigned int i; 78*10fb1340SPhilippe Mathieu-Daudé 79*10fb1340SPhilippe Mathieu-Daudé for (i = 15; i > 0; i--) { 80*10fb1340SPhilippe Mathieu-Daudé if (env->pil_in & (1 << i)) { 81*10fb1340SPhilippe Mathieu-Daudé int old_interrupt = env->interrupt_index; 82*10fb1340SPhilippe Mathieu-Daudé 83*10fb1340SPhilippe Mathieu-Daudé env->interrupt_index = TT_EXTINT | i; 84*10fb1340SPhilippe Mathieu-Daudé if (old_interrupt != env->interrupt_index) { 85*10fb1340SPhilippe Mathieu-Daudé cs = env_cpu(env); 86*10fb1340SPhilippe Mathieu-Daudé trace_sun4m_cpu_interrupt(i); 87*10fb1340SPhilippe Mathieu-Daudé cpu_interrupt(cs, CPU_INTERRUPT_HARD); 88*10fb1340SPhilippe Mathieu-Daudé } 89*10fb1340SPhilippe Mathieu-Daudé break; 90*10fb1340SPhilippe Mathieu-Daudé } 91*10fb1340SPhilippe Mathieu-Daudé } 92*10fb1340SPhilippe Mathieu-Daudé } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) { 93*10fb1340SPhilippe Mathieu-Daudé cs = env_cpu(env); 94*10fb1340SPhilippe Mathieu-Daudé trace_sun4m_cpu_reset_interrupt(env->interrupt_index & 15); 95*10fb1340SPhilippe Mathieu-Daudé env->interrupt_index = 0; 96*10fb1340SPhilippe Mathieu-Daudé cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); 97*10fb1340SPhilippe Mathieu-Daudé } 98*10fb1340SPhilippe Mathieu-Daudé } 99*10fb1340SPhilippe Mathieu-Daudé 10097a8ea5aSAndreas Färber void sparc_cpu_do_interrupt(CPUState *cs) 101ab3b491fSBlue Swirl { 10297a8ea5aSAndreas Färber SPARCCPU *cpu = SPARC_CPU(cs); 10397a8ea5aSAndreas Färber CPUSPARCState *env = &cpu->env; 10427103424SAndreas Färber int cwp, intno = cs->exception_index; 105ab3b491fSBlue Swirl 10620132b96SRichard Henderson /* Compute PSR before exposing state. */ 10720132b96SRichard Henderson if (env->cc_op != CC_OP_FLAGS) { 10820132b96SRichard Henderson cpu_get_psr(env); 10920132b96SRichard Henderson } 11020132b96SRichard Henderson 111ab3b491fSBlue Swirl if (qemu_loglevel_mask(CPU_LOG_INT)) { 112ab3b491fSBlue Swirl static int count; 113ab3b491fSBlue Swirl const char *name; 114ab3b491fSBlue Swirl 115ab3b491fSBlue Swirl if (intno < 0 || intno >= 0x100) { 116ab3b491fSBlue Swirl name = "Unknown"; 117ab3b491fSBlue Swirl } else if (intno >= 0x80) { 118ab3b491fSBlue Swirl name = "Trap Instruction"; 119ab3b491fSBlue Swirl } else { 12086e8c353SPhilippe Mathieu-Daudé name = excp_name_str(intno); 121ab3b491fSBlue Swirl } 122ab3b491fSBlue Swirl 123b884fc5eSRichard Henderson qemu_log("%6d: %s (v=%02x)\n", count, name, intno); 124a0762859SAndreas Färber log_cpu_state(cs, 0); 125ab3b491fSBlue Swirl #if 0 126ab3b491fSBlue Swirl { 127ab3b491fSBlue Swirl int i; 128ab3b491fSBlue Swirl uint8_t *ptr; 129ab3b491fSBlue Swirl 130ab3b491fSBlue Swirl qemu_log(" code="); 131ab3b491fSBlue Swirl ptr = (uint8_t *)env->pc; 132ab3b491fSBlue Swirl for (i = 0; i < 16; i++) { 133ab3b491fSBlue Swirl qemu_log(" %02x", ldub(ptr + i)); 134ab3b491fSBlue Swirl } 135ab3b491fSBlue Swirl qemu_log("\n"); 136ab3b491fSBlue Swirl } 137ab3b491fSBlue Swirl #endif 138ab3b491fSBlue Swirl count++; 139ab3b491fSBlue Swirl } 140ab3b491fSBlue Swirl #if !defined(CONFIG_USER_ONLY) 141ab3b491fSBlue Swirl if (env->psret == 0) { 14227103424SAndreas Färber if (cs->exception_index == 0x80 && 143576e1c4cSIgor Mammedov env->def.features & CPU_FEATURE_TA0_SHUTDOWN) { 144cf83f140SEric Blake qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); 14596d922a6SFabien Chouteau } else { 14686e8c353SPhilippe Mathieu-Daudé cpu_abort(cs, "Trap 0x%02x (%s) while interrupts disabled, " 14786e8c353SPhilippe Mathieu-Daudé "Error state", 14886e8c353SPhilippe Mathieu-Daudé cs->exception_index, excp_name_str(cs->exception_index)); 14996d922a6SFabien Chouteau } 150ab3b491fSBlue Swirl return; 151ab3b491fSBlue Swirl } 152ab3b491fSBlue Swirl #endif 153ab3b491fSBlue Swirl env->psret = 0; 154ab3b491fSBlue Swirl cwp = cpu_cwp_dec(env, env->cwp - 1); 155ab3b491fSBlue Swirl cpu_set_cwp(env, cwp); 156ab3b491fSBlue Swirl env->regwptr[9] = env->pc; 157ab3b491fSBlue Swirl env->regwptr[10] = env->npc; 158ab3b491fSBlue Swirl env->psrps = env->psrs; 159ab3b491fSBlue Swirl env->psrs = 1; 160ab3b491fSBlue Swirl env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4); 161ab3b491fSBlue Swirl env->pc = env->tbr; 162ab3b491fSBlue Swirl env->npc = env->pc + 4; 16327103424SAndreas Färber cs->exception_index = -1; 164ab3b491fSBlue Swirl 165ab3b491fSBlue Swirl #if !defined(CONFIG_USER_ONLY) 166ab3b491fSBlue Swirl /* IRQ acknowledgment */ 167ab3b491fSBlue Swirl if ((intno & ~15) == TT_EXTINT && env->qemu_irq_ack != NULL) { 16879227036SBlue Swirl env->qemu_irq_ack(env, env->irq_manager, intno); 169ab3b491fSBlue Swirl } 170ab3b491fSBlue Swirl #endif 171ab3b491fSBlue Swirl } 172