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 "host-utils.h"
25 void helper_raise_exception(CPUState
*env
, int tt
)
27 env
->exception_index
= tt
;
31 void helper_debug(CPUState
*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(CPUState
*env
, target_ulong a
,
68 target_ulong b
, int cc
)
74 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
75 x1
= (b
& 0xffffffff);
78 helper_raise_exception(env
, TT_DIV_ZERO
);
82 if (x0
> 0xffffffff) {
89 env
->cc_src2
= overflow
;
90 env
->cc_op
= CC_OP_DIV
;
95 target_ulong
helper_udiv(CPUState
*env
, target_ulong a
, target_ulong b
)
97 return helper_udiv_common(env
, a
, b
, 0);
100 target_ulong
helper_udiv_cc(CPUState
*env
, target_ulong a
, target_ulong b
)
102 return helper_udiv_common(env
, a
, b
, 1);
105 static target_ulong
helper_sdiv_common(CPUState
*env
, target_ulong a
,
106 target_ulong b
, int cc
)
112 x0
= (a
& 0xffffffff) | ((int64_t) (env
->y
) << 32);
113 x1
= (b
& 0xffffffff);
116 helper_raise_exception(env
, TT_DIV_ZERO
);
120 if ((int32_t) x0
!= x0
) {
121 x0
= x0
< 0 ? 0x80000000 : 0x7fffffff;
127 env
->cc_src2
= overflow
;
128 env
->cc_op
= CC_OP_DIV
;
133 target_ulong
helper_sdiv(CPUState
*env
, target_ulong a
, target_ulong b
)
135 return helper_sdiv_common(env
, a
, b
, 0);
138 target_ulong
helper_sdiv_cc(CPUState
*env
, target_ulong a
, target_ulong b
)
140 return helper_sdiv_common(env
, a
, b
, 1);