]>
git.proxmox.com Git - mirror_qemu.git/blob - target-sparc/helper.c
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/>.
21 #include "qemu/host-utils.h"
23 #include "sysemu/sysemu.h"
25 void helper_raise_exception(CPUSPARCState
*env
, int tt
)
27 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
29 cs
->exception_index
= tt
;
33 void helper_debug(CPUSPARCState
*env
)
35 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
37 cs
->exception_index
= EXCP_DEBUG
;
42 target_ulong
helper_popc(target_ulong val
)
47 void helper_tick_set_count(void *opaque
, uint64_t count
)
49 #if !defined(CONFIG_USER_ONLY)
50 cpu_tick_set_count(opaque
, count
);
54 uint64_t helper_tick_get_count(void *opaque
)
56 #if !defined(CONFIG_USER_ONLY)
57 return cpu_tick_get_count(opaque
);
63 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
65 #if !defined(CONFIG_USER_ONLY)
66 cpu_tick_set_limit(opaque
, limit
);
71 static target_ulong
helper_udiv_common(CPUSPARCState
*env
, target_ulong a
,
72 target_ulong b
, int cc
)
74 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
79 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
80 x1
= (b
& 0xffffffff);
83 cpu_restore_state(CPU(cpu
), GETPC());
84 helper_raise_exception(env
, TT_DIV_ZERO
);
88 if (x0
> 0xffffffff) {
95 env
->cc_src2
= overflow
;
96 env
->cc_op
= CC_OP_DIV
;
101 target_ulong
helper_udiv(CPUSPARCState
*env
, target_ulong a
, target_ulong b
)
103 return helper_udiv_common(env
, a
, b
, 0);
106 target_ulong
helper_udiv_cc(CPUSPARCState
*env
, target_ulong a
, target_ulong b
)
108 return helper_udiv_common(env
, a
, b
, 1);
111 static target_ulong
helper_sdiv_common(CPUSPARCState
*env
, target_ulong a
,
112 target_ulong b
, int cc
)
114 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
119 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
120 x1
= (b
& 0xffffffff);
123 cpu_restore_state(CPU(cpu
), GETPC());
124 helper_raise_exception(env
, TT_DIV_ZERO
);
128 if ((int32_t) x0
!= x0
) {
129 x0
= x0
< 0 ? 0x80000000 : 0x7fffffff;
135 env
->cc_src2
= overflow
;
136 env
->cc_op
= CC_OP_DIV
;
141 target_ulong
helper_sdiv(CPUSPARCState
*env
, target_ulong a
, target_ulong b
)
143 return helper_sdiv_common(env
, a
, b
, 0);
146 target_ulong
helper_sdiv_cc(CPUSPARCState
*env
, target_ulong a
, target_ulong b
)
148 return helper_sdiv_common(env
, a
, b
, 1);
151 #ifdef TARGET_SPARC64
152 int64_t helper_sdivx(CPUSPARCState
*env
, int64_t a
, int64_t b
)
155 /* Raise divide by zero trap. */
156 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
158 cpu_restore_state(CPU(cpu
), GETPC());
159 helper_raise_exception(env
, TT_DIV_ZERO
);
160 } else if (b
== -1) {
161 /* Avoid overflow trap with i386 divide insn. */
168 uint64_t helper_udivx(CPUSPARCState
*env
, uint64_t a
, uint64_t b
)
171 /* Raise divide by zero trap. */
172 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
174 cpu_restore_state(CPU(cpu
), GETPC());
175 helper_raise_exception(env
, TT_DIV_ZERO
);
181 target_ulong
helper_taddcctv(CPUSPARCState
*env
, target_ulong src1
,
184 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
187 /* Tag overflow occurs if either input has bits 0 or 1 set. */
188 if ((src1
| src2
) & 3) {
194 /* Tag overflow occurs if the addition overflows. */
195 if (~(src1
^ src2
) & (src1
^ dst
) & (1u << 31)) {
199 /* Only modify the CC after any exceptions have been generated. */
200 env
->cc_op
= CC_OP_TADDTV
;
207 cpu_restore_state(CPU(cpu
), GETPC());
208 helper_raise_exception(env
, TT_TOVF
);
211 target_ulong
helper_tsubcctv(CPUSPARCState
*env
, target_ulong src1
,
214 SPARCCPU
*cpu
= sparc_env_get_cpu(env
);
217 /* Tag overflow occurs if either input has bits 0 or 1 set. */
218 if ((src1
| src2
) & 3) {
224 /* Tag overflow occurs if the subtraction overflows. */
225 if ((src1
^ src2
) & (src1
^ dst
) & (1u << 31)) {
229 /* Only modify the CC after any exceptions have been generated. */
230 env
->cc_op
= CC_OP_TSUBTV
;
237 cpu_restore_state(CPU(cpu
), GETPC());
238 helper_raise_exception(env
, TT_TOVF
);
241 #ifndef TARGET_SPARC64
242 void helper_power_down(CPUSPARCState
*env
)
244 CPUState
*cs
= CPU(sparc_env_get_cpu(env
));
247 cs
->exception_index
= EXCP_HLT
;
249 env
->npc
= env
->pc
+ 4;