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 9ab3b491fSBlue Swirl * version 2 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 20ab3b491fSBlue Swirl #include "cpu.h" 2111e66bcaSBlue Swirl #include "trace.h" 229c17d615SPaolo Bonzini #include "sysemu/sysemu.h" 23ab3b491fSBlue Swirl 24b884fc5eSRichard Henderson #define DEBUG_PCALL 25ab3b491fSBlue Swirl 26ab3b491fSBlue Swirl #ifdef DEBUG_PCALL 27ab3b491fSBlue Swirl static const char * const excp_names[0x80] = { 28ab3b491fSBlue Swirl [TT_TFAULT] = "Instruction Access Fault", 29ab3b491fSBlue Swirl [TT_ILL_INSN] = "Illegal Instruction", 30ab3b491fSBlue Swirl [TT_PRIV_INSN] = "Privileged Instruction", 31ab3b491fSBlue Swirl [TT_NFPU_INSN] = "FPU Disabled", 32ab3b491fSBlue Swirl [TT_WIN_OVF] = "Window Overflow", 33ab3b491fSBlue Swirl [TT_WIN_UNF] = "Window Underflow", 34ab3b491fSBlue Swirl [TT_UNALIGNED] = "Unaligned Memory Access", 35ab3b491fSBlue Swirl [TT_FP_EXCP] = "FPU Exception", 36ab3b491fSBlue Swirl [TT_DFAULT] = "Data Access Fault", 37ab3b491fSBlue Swirl [TT_TOVF] = "Tag Overflow", 38ab3b491fSBlue Swirl [TT_EXTINT | 0x1] = "External Interrupt 1", 39ab3b491fSBlue Swirl [TT_EXTINT | 0x2] = "External Interrupt 2", 40ab3b491fSBlue Swirl [TT_EXTINT | 0x3] = "External Interrupt 3", 41ab3b491fSBlue Swirl [TT_EXTINT | 0x4] = "External Interrupt 4", 42ab3b491fSBlue Swirl [TT_EXTINT | 0x5] = "External Interrupt 5", 43ab3b491fSBlue Swirl [TT_EXTINT | 0x6] = "External Interrupt 6", 44ab3b491fSBlue Swirl [TT_EXTINT | 0x7] = "External Interrupt 7", 45ab3b491fSBlue Swirl [TT_EXTINT | 0x8] = "External Interrupt 8", 46ab3b491fSBlue Swirl [TT_EXTINT | 0x9] = "External Interrupt 9", 47ab3b491fSBlue Swirl [TT_EXTINT | 0xa] = "External Interrupt 10", 48ab3b491fSBlue Swirl [TT_EXTINT | 0xb] = "External Interrupt 11", 49ab3b491fSBlue Swirl [TT_EXTINT | 0xc] = "External Interrupt 12", 50ab3b491fSBlue Swirl [TT_EXTINT | 0xd] = "External Interrupt 13", 51ab3b491fSBlue Swirl [TT_EXTINT | 0xe] = "External Interrupt 14", 52ab3b491fSBlue Swirl [TT_EXTINT | 0xf] = "External Interrupt 15", 53ab3b491fSBlue Swirl [TT_TOVF] = "Tag Overflow", 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 #endif 60ab3b491fSBlue Swirl 6197a8ea5aSAndreas Färber void sparc_cpu_do_interrupt(CPUState *cs) 62ab3b491fSBlue Swirl { 6397a8ea5aSAndreas Färber SPARCCPU *cpu = SPARC_CPU(cs); 6497a8ea5aSAndreas Färber CPUSPARCState *env = &cpu->env; 65ab3b491fSBlue Swirl int cwp, intno = env->exception_index; 66ab3b491fSBlue Swirl 6720132b96SRichard Henderson /* Compute PSR before exposing state. */ 6820132b96SRichard Henderson if (env->cc_op != CC_OP_FLAGS) { 6920132b96SRichard Henderson cpu_get_psr(env); 7020132b96SRichard Henderson } 7120132b96SRichard Henderson 72ab3b491fSBlue Swirl #ifdef DEBUG_PCALL 73ab3b491fSBlue Swirl if (qemu_loglevel_mask(CPU_LOG_INT)) { 74ab3b491fSBlue Swirl static int count; 75ab3b491fSBlue Swirl const char *name; 76ab3b491fSBlue Swirl 77ab3b491fSBlue Swirl if (intno < 0 || intno >= 0x100) { 78ab3b491fSBlue Swirl name = "Unknown"; 79ab3b491fSBlue Swirl } else if (intno >= 0x80) { 80ab3b491fSBlue Swirl name = "Trap Instruction"; 81ab3b491fSBlue Swirl } else { 82ab3b491fSBlue Swirl name = excp_names[intno]; 83ab3b491fSBlue Swirl if (!name) { 84ab3b491fSBlue Swirl name = "Unknown"; 85ab3b491fSBlue Swirl } 86ab3b491fSBlue Swirl } 87ab3b491fSBlue Swirl 88b884fc5eSRichard Henderson qemu_log("%6d: %s (v=%02x)\n", count, name, intno); 89ab3b491fSBlue Swirl log_cpu_state(env, 0); 90ab3b491fSBlue Swirl #if 0 91ab3b491fSBlue Swirl { 92ab3b491fSBlue Swirl int i; 93ab3b491fSBlue Swirl uint8_t *ptr; 94ab3b491fSBlue Swirl 95ab3b491fSBlue Swirl qemu_log(" code="); 96ab3b491fSBlue Swirl ptr = (uint8_t *)env->pc; 97ab3b491fSBlue Swirl for (i = 0; i < 16; i++) { 98ab3b491fSBlue Swirl qemu_log(" %02x", ldub(ptr + i)); 99ab3b491fSBlue Swirl } 100ab3b491fSBlue Swirl qemu_log("\n"); 101ab3b491fSBlue Swirl } 102ab3b491fSBlue Swirl #endif 103ab3b491fSBlue Swirl count++; 104ab3b491fSBlue Swirl } 105ab3b491fSBlue Swirl #endif 106ab3b491fSBlue Swirl #if !defined(CONFIG_USER_ONLY) 107ab3b491fSBlue Swirl if (env->psret == 0) { 10896d922a6SFabien Chouteau if (env->exception_index == 0x80 && 10996d922a6SFabien Chouteau env->def->features & CPU_FEATURE_TA0_SHUTDOWN) { 11096d922a6SFabien Chouteau qemu_system_shutdown_request(); 11196d922a6SFabien Chouteau } else { 112ab3b491fSBlue Swirl cpu_abort(env, "Trap 0x%02x while interrupts disabled, Error state", 113ab3b491fSBlue Swirl env->exception_index); 11496d922a6SFabien Chouteau } 115ab3b491fSBlue Swirl return; 116ab3b491fSBlue Swirl } 117ab3b491fSBlue Swirl #endif 118ab3b491fSBlue Swirl env->psret = 0; 119ab3b491fSBlue Swirl cwp = cpu_cwp_dec(env, env->cwp - 1); 120ab3b491fSBlue Swirl cpu_set_cwp(env, cwp); 121ab3b491fSBlue Swirl env->regwptr[9] = env->pc; 122ab3b491fSBlue Swirl env->regwptr[10] = env->npc; 123ab3b491fSBlue Swirl env->psrps = env->psrs; 124ab3b491fSBlue Swirl env->psrs = 1; 125ab3b491fSBlue Swirl env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4); 126ab3b491fSBlue Swirl env->pc = env->tbr; 127ab3b491fSBlue Swirl env->npc = env->pc + 4; 128ab3b491fSBlue Swirl env->exception_index = -1; 129ab3b491fSBlue Swirl 130ab3b491fSBlue Swirl #if !defined(CONFIG_USER_ONLY) 131ab3b491fSBlue Swirl /* IRQ acknowledgment */ 132ab3b491fSBlue Swirl if ((intno & ~15) == TT_EXTINT && env->qemu_irq_ack != NULL) { 13379227036SBlue Swirl env->qemu_irq_ack(env, env->irq_manager, intno); 134ab3b491fSBlue Swirl } 135ab3b491fSBlue Swirl #endif 136ab3b491fSBlue Swirl } 13779227036SBlue Swirl 13879227036SBlue Swirl #if !defined(CONFIG_USER_ONLY) 139c5f9864eSAndreas Färber static void leon3_cache_control_int(CPUSPARCState *env) 14079227036SBlue Swirl { 14179227036SBlue Swirl uint32_t state = 0; 14279227036SBlue Swirl 14379227036SBlue Swirl if (env->cache_control & CACHE_CTRL_IF) { 14479227036SBlue Swirl /* Instruction cache state */ 14579227036SBlue Swirl state = env->cache_control & CACHE_STATE_MASK; 14679227036SBlue Swirl if (state == CACHE_ENABLED) { 14779227036SBlue Swirl state = CACHE_FROZEN; 14811e66bcaSBlue Swirl trace_int_helper_icache_freeze(); 14979227036SBlue Swirl } 15079227036SBlue Swirl 15179227036SBlue Swirl env->cache_control &= ~CACHE_STATE_MASK; 15279227036SBlue Swirl env->cache_control |= state; 15379227036SBlue Swirl } 15479227036SBlue Swirl 15579227036SBlue Swirl if (env->cache_control & CACHE_CTRL_DF) { 15679227036SBlue Swirl /* Data cache state */ 15779227036SBlue Swirl state = (env->cache_control >> 2) & CACHE_STATE_MASK; 15879227036SBlue Swirl if (state == CACHE_ENABLED) { 15979227036SBlue Swirl state = CACHE_FROZEN; 16011e66bcaSBlue Swirl trace_int_helper_dcache_freeze(); 16179227036SBlue Swirl } 16279227036SBlue Swirl 16379227036SBlue Swirl env->cache_control &= ~(CACHE_STATE_MASK << 2); 16479227036SBlue Swirl env->cache_control |= (state << 2); 16579227036SBlue Swirl } 16679227036SBlue Swirl } 16779227036SBlue Swirl 168c5f9864eSAndreas Färber void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno) 16979227036SBlue Swirl { 17079227036SBlue Swirl leon3_irq_ack(irq_manager, intno); 17179227036SBlue Swirl leon3_cache_control_int(env); 17279227036SBlue Swirl } 17379227036SBlue Swirl #endif 174