2 * Sparc64 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"
22 #include "exec/helper-proto.h"
28 static const char * const excp_names
[0x80] = {
29 [TT_TFAULT
] = "Instruction Access Fault",
30 [TT_TMISS
] = "Instruction Access MMU Miss",
31 [TT_CODE_ACCESS
] = "Instruction Access Error",
32 [TT_ILL_INSN
] = "Illegal Instruction",
33 [TT_PRIV_INSN
] = "Privileged Instruction",
34 [TT_NFPU_INSN
] = "FPU Disabled",
35 [TT_FP_EXCP
] = "FPU Exception",
36 [TT_TOVF
] = "Tag Overflow",
37 [TT_CLRWIN
] = "Clean Windows",
38 [TT_DIV_ZERO
] = "Division By Zero",
39 [TT_DFAULT
] = "Data Access Fault",
40 [TT_DMISS
] = "Data Access MMU Miss",
41 [TT_DATA_ACCESS
] = "Data Access Error",
42 [TT_DPROT
] = "Data Protection Error",
43 [TT_UNALIGNED
] = "Unaligned Memory Access",
44 [TT_PRIV_ACT
] = "Privileged Action",
45 [TT_EXTINT
| 0x1] = "External Interrupt 1",
46 [TT_EXTINT
| 0x2] = "External Interrupt 2",
47 [TT_EXTINT
| 0x3] = "External Interrupt 3",
48 [TT_EXTINT
| 0x4] = "External Interrupt 4",
49 [TT_EXTINT
| 0x5] = "External Interrupt 5",
50 [TT_EXTINT
| 0x6] = "External Interrupt 6",
51 [TT_EXTINT
| 0x7] = "External Interrupt 7",
52 [TT_EXTINT
| 0x8] = "External Interrupt 8",
53 [TT_EXTINT
| 0x9] = "External Interrupt 9",
54 [TT_EXTINT
| 0xa] = "External Interrupt 10",
55 [TT_EXTINT
| 0xb] = "External Interrupt 11",
56 [TT_EXTINT
| 0xc] = "External Interrupt 12",
57 [TT_EXTINT
| 0xd] = "External Interrupt 13",
58 [TT_EXTINT
| 0xe] = "External Interrupt 14",
59 [TT_EXTINT
| 0xf] = "External Interrupt 15",
63 void sparc_cpu_do_interrupt(CPUState
*cs
)
65 SPARCCPU
*cpu
= SPARC_CPU(cs
);
66 CPUSPARCState
*env
= &cpu
->env
;
67 int intno
= cs
->exception_index
;
70 /* Compute PSR before exposing state. */
71 if (env
->cc_op
!= CC_OP_FLAGS
) {
76 if (qemu_loglevel_mask(CPU_LOG_INT
)) {
80 if (intno
< 0 || intno
>= 0x180) {
82 } else if (intno
>= 0x100) {
83 name
= "Trap Instruction";
84 } else if (intno
>= 0xc0) {
86 } else if (intno
>= 0x80) {
87 name
= "Window Spill";
89 name
= excp_names
[intno
];
95 qemu_log("%6d: %s (v=%04x)\n", count
, name
, intno
);
103 ptr
= (uint8_t *)env
->pc
;
104 for (i
= 0; i
< 16; i
++) {
105 qemu_log(" %02x", ldub(ptr
+ i
));
113 #if !defined(CONFIG_USER_ONLY)
114 if (env
->tl
>= env
->maxtl
) {
115 cpu_abort(cs
, "Trap 0x%04x while trap level (%d) >= MAXTL (%d),"
116 " Error state", cs
->exception_index
, env
->tl
, env
->maxtl
);
120 if (env
->tl
< env
->maxtl
- 1) {
123 env
->pstate
|= PS_RED
;
124 if (env
->tl
< env
->maxtl
) {
128 tsptr
= cpu_tsptr(env
);
130 tsptr
->tstate
= (cpu_get_ccr(env
) << 32) |
131 ((env
->asi
& 0xff) << 24) | ((env
->pstate
& 0xf3f) << 8) |
133 tsptr
->tpc
= env
->pc
;
134 tsptr
->tnpc
= env
->npc
;
139 cpu_change_pstate(env
, PS_PEF
| PS_PRIV
| PS_IG
);
143 case TT_TMISS
... TT_TMISS
+ 3:
144 case TT_DMISS
... TT_DMISS
+ 3:
145 case TT_DPROT
... TT_DPROT
+ 3:
146 cpu_change_pstate(env
, PS_PEF
| PS_PRIV
| PS_MG
);
149 cpu_change_pstate(env
, PS_PEF
| PS_PRIV
| PS_AG
);
153 if (intno
== TT_CLRWIN
) {
154 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- 1));
155 } else if ((intno
& 0x1c0) == TT_SPILL
) {
156 cpu_set_cwp(env
, cpu_cwp_dec(env
, env
->cwp
- env
->cansave
- 2));
157 } else if ((intno
& 0x1c0) == TT_FILL
) {
158 cpu_set_cwp(env
, cpu_cwp_inc(env
, env
->cwp
+ 1));
160 env
->tbr
&= ~0x7fffULL
;
161 env
->tbr
|= ((env
->tl
> 1) ? 1 << 14 : 0) | (intno
<< 5);
163 env
->npc
= env
->pc
+ 4;
164 cs
->exception_index
= -1;
167 trap_state
*cpu_tsptr(CPUSPARCState
* env
)
169 return &env
->ts
[env
->tl
& MAXTL_MASK
];
172 static bool do_modify_softint(CPUSPARCState
*env
, uint32_t value
)
174 if (env
->softint
!= value
) {
175 env
->softint
= value
;
176 #if !defined(CONFIG_USER_ONLY)
177 if (cpu_interrupts_enabled(env
)) {
186 void helper_set_softint(CPUSPARCState
*env
, uint64_t value
)
188 if (do_modify_softint(env
, env
->softint
| (uint32_t)value
)) {
189 trace_int_helper_set_softint(env
->softint
);
193 void helper_clear_softint(CPUSPARCState
*env
, uint64_t value
)
195 if (do_modify_softint(env
, env
->softint
& (uint32_t)~value
)) {
196 trace_int_helper_clear_softint(env
->softint
);
200 void helper_write_softint(CPUSPARCState
*env
, uint64_t value
)
202 if (do_modify_softint(env
, (uint32_t)value
)) {
203 trace_int_helper_write_softint(env
->softint
);