target-arm: Apply S2 MMU startlevel table size check to AArch64
[qemu/ar7.git] / target-sparc / int32_helper.c
blobd4d6a4b8a5f49447f9fb29cd729d7e67c71aedd7
1 /*
2 * Sparc32 interrupt helpers
4 * Copyright (c) 2003-2005 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "cpu.h"
22 #include "trace.h"
23 #include "sysemu/sysemu.h"
25 #define DEBUG_PCALL
27 #ifdef DEBUG_PCALL
28 static const char * const excp_names[0x80] = {
29 [TT_TFAULT] = "Instruction Access Fault",
30 [TT_ILL_INSN] = "Illegal Instruction",
31 [TT_PRIV_INSN] = "Privileged Instruction",
32 [TT_NFPU_INSN] = "FPU Disabled",
33 [TT_WIN_OVF] = "Window Overflow",
34 [TT_WIN_UNF] = "Window Underflow",
35 [TT_UNALIGNED] = "Unaligned Memory Access",
36 [TT_FP_EXCP] = "FPU Exception",
37 [TT_DFAULT] = "Data Access Fault",
38 [TT_TOVF] = "Tag Overflow",
39 [TT_EXTINT | 0x1] = "External Interrupt 1",
40 [TT_EXTINT | 0x2] = "External Interrupt 2",
41 [TT_EXTINT | 0x3] = "External Interrupt 3",
42 [TT_EXTINT | 0x4] = "External Interrupt 4",
43 [TT_EXTINT | 0x5] = "External Interrupt 5",
44 [TT_EXTINT | 0x6] = "External Interrupt 6",
45 [TT_EXTINT | 0x7] = "External Interrupt 7",
46 [TT_EXTINT | 0x8] = "External Interrupt 8",
47 [TT_EXTINT | 0x9] = "External Interrupt 9",
48 [TT_EXTINT | 0xa] = "External Interrupt 10",
49 [TT_EXTINT | 0xb] = "External Interrupt 11",
50 [TT_EXTINT | 0xc] = "External Interrupt 12",
51 [TT_EXTINT | 0xd] = "External Interrupt 13",
52 [TT_EXTINT | 0xe] = "External Interrupt 14",
53 [TT_EXTINT | 0xf] = "External Interrupt 15",
54 [TT_TOVF] = "Tag Overflow",
55 [TT_CODE_ACCESS] = "Instruction Access Error",
56 [TT_DATA_ACCESS] = "Data Access Error",
57 [TT_DIV_ZERO] = "Division By Zero",
58 [TT_NCP_INSN] = "Coprocessor Disabled",
60 #endif
62 void sparc_cpu_do_interrupt(CPUState *cs)
64 SPARCCPU *cpu = SPARC_CPU(cs);
65 CPUSPARCState *env = &cpu->env;
66 int cwp, intno = cs->exception_index;
68 /* Compute PSR before exposing state. */
69 if (env->cc_op != CC_OP_FLAGS) {
70 cpu_get_psr(env);
73 #ifdef DEBUG_PCALL
74 if (qemu_loglevel_mask(CPU_LOG_INT)) {
75 static int count;
76 const char *name;
78 if (intno < 0 || intno >= 0x100) {
79 name = "Unknown";
80 } else if (intno >= 0x80) {
81 name = "Trap Instruction";
82 } else {
83 name = excp_names[intno];
84 if (!name) {
85 name = "Unknown";
89 qemu_log("%6d: %s (v=%02x)\n", count, name, intno);
90 log_cpu_state(cs, 0);
91 #if 0
93 int i;
94 uint8_t *ptr;
96 qemu_log(" code=");
97 ptr = (uint8_t *)env->pc;
98 for (i = 0; i < 16; i++) {
99 qemu_log(" %02x", ldub(ptr + i));
101 qemu_log("\n");
103 #endif
104 count++;
106 #endif
107 #if !defined(CONFIG_USER_ONLY)
108 if (env->psret == 0) {
109 if (cs->exception_index == 0x80 &&
110 env->def->features & CPU_FEATURE_TA0_SHUTDOWN) {
111 qemu_system_shutdown_request();
112 } else {
113 cpu_abort(cs, "Trap 0x%02x while interrupts disabled, Error state",
114 cs->exception_index);
116 return;
118 #endif
119 env->psret = 0;
120 cwp = cpu_cwp_dec(env, env->cwp - 1);
121 cpu_set_cwp(env, cwp);
122 env->regwptr[9] = env->pc;
123 env->regwptr[10] = env->npc;
124 env->psrps = env->psrs;
125 env->psrs = 1;
126 env->tbr = (env->tbr & TBR_BASE_MASK) | (intno << 4);
127 env->pc = env->tbr;
128 env->npc = env->pc + 4;
129 cs->exception_index = -1;
131 #if !defined(CONFIG_USER_ONLY)
132 /* IRQ acknowledgment */
133 if ((intno & ~15) == TT_EXTINT && env->qemu_irq_ack != NULL) {
134 env->qemu_irq_ack(env, env->irq_manager, intno);
136 #endif
139 #if !defined(CONFIG_USER_ONLY)
140 static void leon3_cache_control_int(CPUSPARCState *env)
142 uint32_t state = 0;
144 if (env->cache_control & CACHE_CTRL_IF) {
145 /* Instruction cache state */
146 state = env->cache_control & CACHE_STATE_MASK;
147 if (state == CACHE_ENABLED) {
148 state = CACHE_FROZEN;
149 trace_int_helper_icache_freeze();
152 env->cache_control &= ~CACHE_STATE_MASK;
153 env->cache_control |= state;
156 if (env->cache_control & CACHE_CTRL_DF) {
157 /* Data cache state */
158 state = (env->cache_control >> 2) & CACHE_STATE_MASK;
159 if (state == CACHE_ENABLED) {
160 state = CACHE_FROZEN;
161 trace_int_helper_dcache_freeze();
164 env->cache_control &= ~(CACHE_STATE_MASK << 2);
165 env->cache_control |= (state << 2);
169 void leon3_irq_manager(CPUSPARCState *env, void *irq_manager, int intno)
171 leon3_irq_ack(irq_manager, intno);
172 leon3_cache_control_int(env);
174 #endif