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 env
->exception_index
= tt
;
31 void helper_debug(CPUSPARCState
*env
)
33 env
->exception_index
= EXCP_DEBUG
;
38 target_ulong
helper_popc(target_ulong val
)
43 void helper_tick_set_count(void *opaque
, uint64_t count
)
45 #if !defined(CONFIG_USER_ONLY)
46 cpu_tick_set_count(opaque
, count
);
50 uint64_t helper_tick_get_count(void *opaque
)
52 #if !defined(CONFIG_USER_ONLY)
53 return cpu_tick_get_count(opaque
);
59 void helper_tick_set_limit(void *opaque
, uint64_t limit
)
61 #if !defined(CONFIG_USER_ONLY)
62 cpu_tick_set_limit(opaque
, limit
);
67 static target_ulong
helper_udiv_common(CPUSPARCState
*env
, target_ulong a
,
68 target_ulong b
, int cc
)
74 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
75 x1
= (b
& 0xffffffff);
78 cpu_restore_state(env
, GETPC());
79 helper_raise_exception(env
, TT_DIV_ZERO
);
83 if (x0
> 0xffffffff) {
90 env
->cc_src2
= overflow
;
91 env
->cc_op
= CC_OP_DIV
;
96 target_ulong
helper_udiv(CPUSPARCState
*env
, target_ulong a
, target_ulong b
)
98 return helper_udiv_common(env
, a
, b
, 0);
101 target_ulong
helper_udiv_cc(CPUSPARCState
*env
, target_ulong a
, target_ulong b
)
103 return helper_udiv_common(env
, a
, b
, 1);
106 static target_ulong
helper_sdiv_common(CPUSPARCState
*env
, target_ulong a
,
107 target_ulong b
, int cc
)
113 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
114 x1
= (b
& 0xffffffff);
117 cpu_restore_state(env
, GETPC());
118 helper_raise_exception(env
, TT_DIV_ZERO
);
122 if ((int32_t) x0
!= x0
) {
123 x0
= x0
< 0 ? 0x80000000 : 0x7fffffff;
129 env
->cc_src2
= overflow
;
130 env
->cc_op
= CC_OP_DIV
;
135 target_ulong
helper_sdiv(CPUSPARCState
*env
, target_ulong a
, target_ulong b
)
137 return helper_sdiv_common(env
, a
, b
, 0);
140 target_ulong
helper_sdiv_cc(CPUSPARCState
*env
, target_ulong a
, target_ulong b
)
142 return helper_sdiv_common(env
, a
, b
, 1);
145 #ifdef TARGET_SPARC64
146 int64_t helper_sdivx(CPUSPARCState
*env
, int64_t a
, int64_t b
)
149 /* Raise divide by zero trap. */
150 cpu_restore_state(env
, GETPC());
151 helper_raise_exception(env
, TT_DIV_ZERO
);
152 } else if (b
== -1) {
153 /* Avoid overflow trap with i386 divide insn. */
160 uint64_t helper_udivx(CPUSPARCState
*env
, uint64_t a
, uint64_t b
)
163 /* Raise divide by zero trap. */
164 cpu_restore_state(env
, GETPC());
165 helper_raise_exception(env
, TT_DIV_ZERO
);
171 target_ulong
helper_taddcctv(CPUSPARCState
*env
, target_ulong src1
,
176 /* Tag overflow occurs if either input has bits 0 or 1 set. */
177 if ((src1
| src2
) & 3) {
183 /* Tag overflow occurs if the addition overflows. */
184 if (~(src1
^ src2
) & (src1
^ dst
) & (1u << 31)) {
188 /* Only modify the CC after any exceptions have been generated. */
189 env
->cc_op
= CC_OP_TADDTV
;
196 cpu_restore_state(env
, GETPC());
197 helper_raise_exception(env
, TT_TOVF
);
200 target_ulong
helper_tsubcctv(CPUSPARCState
*env
, target_ulong src1
,
205 /* Tag overflow occurs if either input has bits 0 or 1 set. */
206 if ((src1
| src2
) & 3) {
212 /* Tag overflow occurs if the subtraction overflows. */
213 if ((src1
^ src2
) & (src1
^ dst
) & (1u << 31)) {
217 /* Only modify the CC after any exceptions have been generated. */
218 env
->cc_op
= CC_OP_TSUBTV
;
225 cpu_restore_state(env
, GETPC());
226 helper_raise_exception(env
, TT_TOVF
);
229 #ifndef TARGET_SPARC64
230 void helper_power_down(CPUSPARCState
*env
)
233 env
->exception_index
= EXCP_HLT
;
235 env
->npc
= env
->pc
+ 4;