xref: /qemu/target/sparc/int32_helper.c (revision 5650b5497e92e6136a633ec6291c81ab8fc610a0) !
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
9*5650b549SChetan 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"
21ab3b491fSBlue Swirl #include "cpu.h"
2211e66bcaSBlue Swirl #include "trace.h"
23508127e2SPaolo Bonzini #include "exec/log.h"
2454d31236SMarkus Armbruster #include "sysemu/runstate.h"
25ab3b491fSBlue Swirl 
26ab3b491fSBlue Swirl 
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_CODE_ACCESS] = "Instruction Access Error",
54ab3b491fSBlue Swirl     [TT_DATA_ACCESS] = "Data Access Error",
55ab3b491fSBlue Swirl     [TT_DIV_ZERO] = "Division By Zero",
56ab3b491fSBlue Swirl     [TT_NCP_INSN] = "Coprocessor Disabled",
57ab3b491fSBlue Swirl };
58ab3b491fSBlue Swirl 
5986e8c353SPhilippe Mathieu-Daudé static const char *excp_name_str(int32_t exception_index)
6086e8c353SPhilippe Mathieu-Daudé {
6186e8c353SPhilippe Mathieu-Daudé     if (exception_index < 0 || exception_index >= ARRAY_SIZE(excp_names)) {
6286e8c353SPhilippe Mathieu-Daudé         return "Unknown";
6386e8c353SPhilippe Mathieu-Daudé     }
6486e8c353SPhilippe Mathieu-Daudé     return excp_names[exception_index];
6586e8c353SPhilippe Mathieu-Daudé }
6686e8c353SPhilippe Mathieu-Daudé 
6797a8ea5aSAndreas Färber void sparc_cpu_do_interrupt(CPUState *cs)
68ab3b491fSBlue Swirl {
6997a8ea5aSAndreas Färber     SPARCCPU *cpu = SPARC_CPU(cs);
7097a8ea5aSAndreas Färber     CPUSPARCState *env = &cpu->env;
7127103424SAndreas Färber     int cwp, intno = cs->exception_index;
72ab3b491fSBlue Swirl 
7320132b96SRichard Henderson     /* Compute PSR before exposing state.  */
7420132b96SRichard Henderson     if (env->cc_op != CC_OP_FLAGS) {
7520132b96SRichard Henderson         cpu_get_psr(env);
7620132b96SRichard Henderson     }
7720132b96SRichard Henderson 
78ab3b491fSBlue Swirl     if (qemu_loglevel_mask(CPU_LOG_INT)) {
79ab3b491fSBlue Swirl         static int count;
80ab3b491fSBlue Swirl         const char *name;
81ab3b491fSBlue Swirl 
82ab3b491fSBlue Swirl         if (intno < 0 || intno >= 0x100) {
83ab3b491fSBlue Swirl             name = "Unknown";
84ab3b491fSBlue Swirl         } else if (intno >= 0x80) {
85ab3b491fSBlue Swirl             name = "Trap Instruction";
86ab3b491fSBlue Swirl         } else {
8786e8c353SPhilippe Mathieu-Daudé             name = excp_name_str(intno);
88ab3b491fSBlue Swirl         }
89ab3b491fSBlue Swirl 
90b884fc5eSRichard Henderson         qemu_log("%6d: %s (v=%02x)\n", count, name, intno);
91a0762859SAndreas Färber         log_cpu_state(cs, 0);
92ab3b491fSBlue Swirl #if 0
93ab3b491fSBlue Swirl         {
94ab3b491fSBlue Swirl             int i;
95ab3b491fSBlue Swirl             uint8_t *ptr;
96ab3b491fSBlue Swirl 
97ab3b491fSBlue Swirl             qemu_log("       code=");
98ab3b491fSBlue Swirl             ptr = (uint8_t *)env->pc;
99ab3b491fSBlue Swirl             for (i = 0; i < 16; i++) {
100ab3b491fSBlue Swirl                 qemu_log(" %02x", ldub(ptr + i));
101ab3b491fSBlue Swirl             }
102ab3b491fSBlue Swirl             qemu_log("\n");
103ab3b491fSBlue Swirl         }
104ab3b491fSBlue Swirl #endif
105ab3b491fSBlue Swirl         count++;
106ab3b491fSBlue Swirl     }
107ab3b491fSBlue Swirl #if !defined(CONFIG_USER_ONLY)
108ab3b491fSBlue Swirl     if (env->psret == 0) {
10927103424SAndreas Färber         if (cs->exception_index == 0x80 &&
110576e1c4cSIgor Mammedov             env->def.features & CPU_FEATURE_TA0_SHUTDOWN) {
111cf83f140SEric Blake             qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
11296d922a6SFabien Chouteau         } else {
11386e8c353SPhilippe Mathieu-Daudé             cpu_abort(cs, "Trap 0x%02x (%s) while interrupts disabled, "
11486e8c353SPhilippe Mathieu-Daudé                           "Error state",
11586e8c353SPhilippe Mathieu-Daudé                       cs->exception_index, excp_name_str(cs->exception_index));
11696d922a6SFabien Chouteau         }
117ab3b491fSBlue Swirl         return;
118ab3b491fSBlue Swirl     }
119ab3b491fSBlue Swirl #endif
120ab3b491fSBlue Swirl     env->psret = 0;
121ab3b491fSBlue Swirl     cwp = cpu_cwp_dec(env, env->cwp - 1);
122ab3b491fSBlue Swirl     cpu_set_cwp(env, cwp);
123ab3b491fSBlue Swirl     env->regwptr[9] = env->pc;
124ab3b491fSBlue Swirl     env->regwptr[10] = env->npc;
125ab3b491fSBlue Swirl     env->psrps = env->psrs;
126ab3b491fSBlue Swirl     env->psrs = 1;
127ab3b491fSBlue Swirl     env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4);
128ab3b491fSBlue Swirl     env->pc = env->tbr;
129ab3b491fSBlue Swirl     env->npc = env->pc + 4;
13027103424SAndreas Färber     cs->exception_index = -1;
131ab3b491fSBlue Swirl 
132ab3b491fSBlue Swirl #if !defined(CONFIG_USER_ONLY)
133ab3b491fSBlue Swirl     /* IRQ acknowledgment */
134ab3b491fSBlue Swirl     if ((intno & ~15) == TT_EXTINT && env->qemu_irq_ack != NULL) {
13579227036SBlue Swirl         env->qemu_irq_ack(env, env->irq_manager, intno);
136ab3b491fSBlue Swirl     }
137ab3b491fSBlue Swirl #endif
138ab3b491fSBlue Swirl }
13979227036SBlue Swirl 
14079227036SBlue Swirl #if !defined(CONFIG_USER_ONLY)
141c5f9864eSAndreas Färber static void leon3_cache_control_int(CPUSPARCState *env)
14279227036SBlue Swirl {
14379227036SBlue Swirl     uint32_t state = 0;
14479227036SBlue Swirl 
14579227036SBlue Swirl     if (env->cache_control & CACHE_CTRL_IF) {
14679227036SBlue Swirl         /* Instruction cache state */
14779227036SBlue Swirl         state = env->cache_control & CACHE_STATE_MASK;
14879227036SBlue Swirl         if (state == CACHE_ENABLED) {
14979227036SBlue Swirl             state = CACHE_FROZEN;
15011e66bcaSBlue Swirl             trace_int_helper_icache_freeze();
15179227036SBlue Swirl         }
15279227036SBlue Swirl 
15379227036SBlue Swirl         env->cache_control &= ~CACHE_STATE_MASK;
15479227036SBlue Swirl         env->cache_control |= state;
15579227036SBlue Swirl     }
15679227036SBlue Swirl 
15779227036SBlue Swirl     if (env->cache_control & CACHE_CTRL_DF) {
15879227036SBlue Swirl         /* Data cache state */
15979227036SBlue Swirl         state = (env->cache_control >> 2) & CACHE_STATE_MASK;
16079227036SBlue Swirl         if (state == CACHE_ENABLED) {
16179227036SBlue Swirl             state = CACHE_FROZEN;
16211e66bcaSBlue Swirl             trace_int_helper_dcache_freeze();
16379227036SBlue Swirl         }
16479227036SBlue Swirl 
16579227036SBlue Swirl         env->cache_control &= ~(CACHE_STATE_MASK << 2);
16679227036SBlue Swirl         env->cache_control |= (state << 2);
16779227036SBlue Swirl     }
16879227036SBlue Swirl }
16979227036SBlue Swirl 
170c5f9864eSAndreas Färber void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno)
17179227036SBlue Swirl {
17279227036SBlue Swirl     leon3_irq_ack(irq_manager, intno);
17379227036SBlue Swirl     leon3_cache_control_int(env);
17479227036SBlue Swirl }
17579227036SBlue Swirl #endif
176