xref: /qemu/target/sparc/int64_helper.c (revision ab3b491f2131e12503d165a8ffaef5f3a488eafe)
1ab3b491fSBlue Swirl /*
2ab3b491fSBlue Swirl  * Sparc64 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"
21ab3b491fSBlue Swirl 
22ab3b491fSBlue Swirl //#define DEBUG_PCALL
23ab3b491fSBlue Swirl 
24ab3b491fSBlue Swirl #ifdef DEBUG_PCALL
25ab3b491fSBlue Swirl static const char * const excp_names[0x80] = {
26ab3b491fSBlue Swirl     [TT_TFAULT] = "Instruction Access Fault",
27ab3b491fSBlue Swirl     [TT_TMISS] = "Instruction Access MMU Miss",
28ab3b491fSBlue Swirl     [TT_CODE_ACCESS] = "Instruction Access Error",
29ab3b491fSBlue Swirl     [TT_ILL_INSN] = "Illegal Instruction",
30ab3b491fSBlue Swirl     [TT_PRIV_INSN] = "Privileged Instruction",
31ab3b491fSBlue Swirl     [TT_NFPU_INSN] = "FPU Disabled",
32ab3b491fSBlue Swirl     [TT_FP_EXCP] = "FPU Exception",
33ab3b491fSBlue Swirl     [TT_TOVF] = "Tag Overflow",
34ab3b491fSBlue Swirl     [TT_CLRWIN] = "Clean Windows",
35ab3b491fSBlue Swirl     [TT_DIV_ZERO] = "Division By Zero",
36ab3b491fSBlue Swirl     [TT_DFAULT] = "Data Access Fault",
37ab3b491fSBlue Swirl     [TT_DMISS] = "Data Access MMU Miss",
38ab3b491fSBlue Swirl     [TT_DATA_ACCESS] = "Data Access Error",
39ab3b491fSBlue Swirl     [TT_DPROT] = "Data Protection Error",
40ab3b491fSBlue Swirl     [TT_UNALIGNED] = "Unaligned Memory Access",
41ab3b491fSBlue Swirl     [TT_PRIV_ACT] = "Privileged Action",
42ab3b491fSBlue Swirl     [TT_EXTINT | 0x1] = "External Interrupt 1",
43ab3b491fSBlue Swirl     [TT_EXTINT | 0x2] = "External Interrupt 2",
44ab3b491fSBlue Swirl     [TT_EXTINT | 0x3] = "External Interrupt 3",
45ab3b491fSBlue Swirl     [TT_EXTINT | 0x4] = "External Interrupt 4",
46ab3b491fSBlue Swirl     [TT_EXTINT | 0x5] = "External Interrupt 5",
47ab3b491fSBlue Swirl     [TT_EXTINT | 0x6] = "External Interrupt 6",
48ab3b491fSBlue Swirl     [TT_EXTINT | 0x7] = "External Interrupt 7",
49ab3b491fSBlue Swirl     [TT_EXTINT | 0x8] = "External Interrupt 8",
50ab3b491fSBlue Swirl     [TT_EXTINT | 0x9] = "External Interrupt 9",
51ab3b491fSBlue Swirl     [TT_EXTINT | 0xa] = "External Interrupt 10",
52ab3b491fSBlue Swirl     [TT_EXTINT | 0xb] = "External Interrupt 11",
53ab3b491fSBlue Swirl     [TT_EXTINT | 0xc] = "External Interrupt 12",
54ab3b491fSBlue Swirl     [TT_EXTINT | 0xd] = "External Interrupt 13",
55ab3b491fSBlue Swirl     [TT_EXTINT | 0xe] = "External Interrupt 14",
56ab3b491fSBlue Swirl     [TT_EXTINT | 0xf] = "External Interrupt 15",
57ab3b491fSBlue Swirl };
58ab3b491fSBlue Swirl #endif
59ab3b491fSBlue Swirl 
60ab3b491fSBlue Swirl void do_interrupt(CPUState *env)
61ab3b491fSBlue Swirl {
62ab3b491fSBlue Swirl     int intno = env->exception_index;
63ab3b491fSBlue Swirl     trap_state *tsptr;
64ab3b491fSBlue Swirl 
65ab3b491fSBlue Swirl #ifdef DEBUG_PCALL
66ab3b491fSBlue Swirl     if (qemu_loglevel_mask(CPU_LOG_INT)) {
67ab3b491fSBlue Swirl         static int count;
68ab3b491fSBlue Swirl         const char *name;
69ab3b491fSBlue Swirl 
70ab3b491fSBlue Swirl         if (intno < 0 || intno >= 0x180) {
71ab3b491fSBlue Swirl             name = "Unknown";
72ab3b491fSBlue Swirl         } else if (intno >= 0x100) {
73ab3b491fSBlue Swirl             name = "Trap Instruction";
74ab3b491fSBlue Swirl         } else if (intno >= 0xc0) {
75ab3b491fSBlue Swirl             name = "Window Fill";
76ab3b491fSBlue Swirl         } else if (intno >= 0x80) {
77ab3b491fSBlue Swirl             name = "Window Spill";
78ab3b491fSBlue Swirl         } else {
79ab3b491fSBlue Swirl             name = excp_names[intno];
80ab3b491fSBlue Swirl             if (!name) {
81ab3b491fSBlue Swirl                 name = "Unknown";
82ab3b491fSBlue Swirl             }
83ab3b491fSBlue Swirl         }
84ab3b491fSBlue Swirl 
85ab3b491fSBlue Swirl         qemu_log("%6d: %s (v=%04x) pc=%016" PRIx64 " npc=%016" PRIx64
86ab3b491fSBlue Swirl                 " SP=%016" PRIx64 "\n",
87ab3b491fSBlue Swirl                 count, name, intno,
88ab3b491fSBlue Swirl                 env->pc,
89ab3b491fSBlue Swirl                 env->npc, env->regwptr[6]);
90ab3b491fSBlue Swirl         log_cpu_state(env, 0);
91ab3b491fSBlue Swirl #if 0
92ab3b491fSBlue Swirl         {
93ab3b491fSBlue Swirl             int i;
94ab3b491fSBlue Swirl             uint8_t *ptr;
95ab3b491fSBlue Swirl 
96ab3b491fSBlue Swirl             qemu_log("       code=");
97ab3b491fSBlue Swirl             ptr = (uint8_t *)env->pc;
98ab3b491fSBlue Swirl             for (i = 0; i < 16; i++) {
99ab3b491fSBlue Swirl                 qemu_log(" %02x", ldub(ptr + i));
100ab3b491fSBlue Swirl             }
101ab3b491fSBlue Swirl             qemu_log("\n");
102ab3b491fSBlue Swirl         }
103ab3b491fSBlue Swirl #endif
104ab3b491fSBlue Swirl         count++;
105ab3b491fSBlue Swirl     }
106ab3b491fSBlue Swirl #endif
107ab3b491fSBlue Swirl #if !defined(CONFIG_USER_ONLY)
108ab3b491fSBlue Swirl     if (env->tl >= env->maxtl) {
109ab3b491fSBlue Swirl         cpu_abort(env, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
110ab3b491fSBlue Swirl                   " Error state", env->exception_index, env->tl, env->maxtl);
111ab3b491fSBlue Swirl         return;
112ab3b491fSBlue Swirl     }
113ab3b491fSBlue Swirl #endif
114ab3b491fSBlue Swirl     if (env->tl < env->maxtl - 1) {
115ab3b491fSBlue Swirl         env->tl++;
116ab3b491fSBlue Swirl     } else {
117ab3b491fSBlue Swirl         env->pstate |= PS_RED;
118ab3b491fSBlue Swirl         if (env->tl < env->maxtl) {
119ab3b491fSBlue Swirl             env->tl++;
120ab3b491fSBlue Swirl         }
121ab3b491fSBlue Swirl     }
122ab3b491fSBlue Swirl     tsptr = cpu_tsptr(env);
123ab3b491fSBlue Swirl 
124ab3b491fSBlue Swirl     tsptr->tstate = (cpu_get_ccr(env) << 32) |
125ab3b491fSBlue Swirl         ((env->asi & 0xff) << 24) | ((env->pstate & 0xf3f) << 8) |
126ab3b491fSBlue Swirl         cpu_get_cwp64(env);
127ab3b491fSBlue Swirl     tsptr->tpc = env->pc;
128ab3b491fSBlue Swirl     tsptr->tnpc = env->npc;
129ab3b491fSBlue Swirl     tsptr->tt = intno;
130ab3b491fSBlue Swirl 
131ab3b491fSBlue Swirl     switch (intno) {
132ab3b491fSBlue Swirl     case TT_IVEC:
133ab3b491fSBlue Swirl         cpu_change_pstate(env, PS_PEF | PS_PRIV | PS_IG);
134ab3b491fSBlue Swirl         break;
135ab3b491fSBlue Swirl     case TT_TFAULT:
136ab3b491fSBlue Swirl     case TT_DFAULT:
137ab3b491fSBlue Swirl     case TT_TMISS ... TT_TMISS + 3:
138ab3b491fSBlue Swirl     case TT_DMISS ... TT_DMISS + 3:
139ab3b491fSBlue Swirl     case TT_DPROT ... TT_DPROT + 3:
140ab3b491fSBlue Swirl         cpu_change_pstate(env, PS_PEF | PS_PRIV | PS_MG);
141ab3b491fSBlue Swirl         break;
142ab3b491fSBlue Swirl     default:
143ab3b491fSBlue Swirl         cpu_change_pstate(env, PS_PEF | PS_PRIV | PS_AG);
144ab3b491fSBlue Swirl         break;
145ab3b491fSBlue Swirl     }
146ab3b491fSBlue Swirl 
147ab3b491fSBlue Swirl     if (intno == TT_CLRWIN) {
148ab3b491fSBlue Swirl         cpu_set_cwp(env, cpu_cwp_dec(env, env->cwp - 1));
149ab3b491fSBlue Swirl     } else if ((intno & 0x1c0) == TT_SPILL) {
150ab3b491fSBlue Swirl         cpu_set_cwp(env, cpu_cwp_dec(env, env->cwp - env->cansave - 2));
151ab3b491fSBlue Swirl     } else if ((intno & 0x1c0) == TT_FILL) {
152ab3b491fSBlue Swirl         cpu_set_cwp(env, cpu_cwp_inc(env, env->cwp + 1));
153ab3b491fSBlue Swirl     }
154ab3b491fSBlue Swirl     env->tbr &= ~0x7fffULL;
155ab3b491fSBlue Swirl     env->tbr |= ((env->tl > 1) ? 1 << 14 : 0) | (intno << 5);
156ab3b491fSBlue Swirl     env->pc = env->tbr;
157ab3b491fSBlue Swirl     env->npc = env->pc + 4;
158ab3b491fSBlue Swirl     env->exception_index = -1;
159ab3b491fSBlue Swirl }
160