2012-04-29 17:12:26 +04:00
|
|
|
/*
|
|
|
|
* x86 integer helpers
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 15:28:01 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-04-29 17:12:26 +04:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:03 +03:00
|
|
|
#include "qemu/osdep.h"
|
2012-04-29 17:12:26 +04:00
|
|
|
#include "cpu.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/host-utils.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-proto.h"
|
2019-03-15 06:01:42 +03:00
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "qemu/guest-random.h"
|
2020-12-12 18:55:14 +03:00
|
|
|
#include "helper-tcg.h"
|
2012-04-29 17:12:26 +04:00
|
|
|
|
|
|
|
//#define DEBUG_MULDIV
|
|
|
|
|
|
|
|
/* modulo 9 table */
|
|
|
|
static const uint8_t rclb_table[32] = {
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7,
|
|
|
|
8, 0, 1, 2, 3, 4, 5, 6,
|
|
|
|
7, 8, 0, 1, 2, 3, 4, 5,
|
|
|
|
6, 7, 8, 0, 1, 2, 3, 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* modulo 17 table */
|
|
|
|
static const uint8_t rclw_table[32] = {
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7,
|
|
|
|
8, 9, 10, 11, 12, 13, 14, 15,
|
|
|
|
16, 0, 1, 2, 3, 4, 5, 6,
|
|
|
|
7, 8, 9, 10, 11, 12, 13, 14,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* division, flags are undefined */
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_divb_AL(CPUX86State *env, target_ulong t0)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
unsigned int num, den, q, r;
|
|
|
|
|
2013-05-28 12:20:59 +04:00
|
|
|
num = (env->regs[R_EAX] & 0xffff);
|
2012-04-29 17:12:26 +04:00
|
|
|
den = (t0 & 0xff);
|
|
|
|
if (den == 0) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q = (num / den);
|
|
|
|
if (q > 0xff) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q &= 0xff;
|
|
|
|
r = (num % den) & 0xff;
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xffff) | (r << 8) | q;
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_idivb_AL(CPUX86State *env, target_ulong t0)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int num, den, q, r;
|
|
|
|
|
2013-05-28 12:20:59 +04:00
|
|
|
num = (int16_t)env->regs[R_EAX];
|
2012-04-29 17:12:26 +04:00
|
|
|
den = (int8_t)t0;
|
|
|
|
if (den == 0) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q = (num / den);
|
|
|
|
if (q != (int8_t)q) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q &= 0xff;
|
|
|
|
r = (num % den) & 0xff;
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xffff) | (r << 8) | q;
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_divw_AX(CPUX86State *env, target_ulong t0)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
unsigned int num, den, q, r;
|
|
|
|
|
2013-05-28 12:21:02 +04:00
|
|
|
num = (env->regs[R_EAX] & 0xffff) | ((env->regs[R_EDX] & 0xffff) << 16);
|
2012-04-29 17:12:26 +04:00
|
|
|
den = (t0 & 0xffff);
|
|
|
|
if (den == 0) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q = (num / den);
|
|
|
|
if (q > 0xffff) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q &= 0xffff;
|
|
|
|
r = (num % den) & 0xffff;
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xffff) | q;
|
2013-05-28 12:21:02 +04:00
|
|
|
env->regs[R_EDX] = (env->regs[R_EDX] & ~0xffff) | r;
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_idivw_AX(CPUX86State *env, target_ulong t0)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int num, den, q, r;
|
|
|
|
|
2013-05-28 12:21:02 +04:00
|
|
|
num = (env->regs[R_EAX] & 0xffff) | ((env->regs[R_EDX] & 0xffff) << 16);
|
2012-04-29 17:12:26 +04:00
|
|
|
den = (int16_t)t0;
|
|
|
|
if (den == 0) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q = (num / den);
|
|
|
|
if (q != (int16_t)q) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q &= 0xffff;
|
|
|
|
r = (num % den) & 0xffff;
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xffff) | q;
|
2013-05-28 12:21:02 +04:00
|
|
|
env->regs[R_EDX] = (env->regs[R_EDX] & ~0xffff) | r;
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_divl_EAX(CPUX86State *env, target_ulong t0)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
unsigned int den, r;
|
|
|
|
uint64_t num, q;
|
|
|
|
|
2013-05-28 12:21:02 +04:00
|
|
|
num = ((uint32_t)env->regs[R_EAX]) | ((uint64_t)((uint32_t)env->regs[R_EDX]) << 32);
|
2012-04-29 17:12:26 +04:00
|
|
|
den = t0;
|
|
|
|
if (den == 0) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q = (num / den);
|
|
|
|
r = (num % den);
|
|
|
|
if (q > 0xffffffff) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (uint32_t)q;
|
2013-05-28 12:21:02 +04:00
|
|
|
env->regs[R_EDX] = (uint32_t)r;
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_idivl_EAX(CPUX86State *env, target_ulong t0)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int den, r;
|
|
|
|
int64_t num, q;
|
|
|
|
|
2013-05-28 12:21:02 +04:00
|
|
|
num = ((uint32_t)env->regs[R_EAX]) | ((uint64_t)((uint32_t)env->regs[R_EDX]) << 32);
|
2012-04-29 17:12:26 +04:00
|
|
|
den = t0;
|
|
|
|
if (den == 0) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
q = (num / den);
|
|
|
|
r = (num % den);
|
|
|
|
if (q != (int32_t)q) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (uint32_t)q;
|
2013-05-28 12:21:02 +04:00
|
|
|
env->regs[R_EDX] = (uint32_t)r;
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* bcd */
|
|
|
|
|
|
|
|
/* XXX: exception */
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_aam(CPUX86State *env, int base)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int al, ah;
|
|
|
|
|
2013-05-28 12:20:59 +04:00
|
|
|
al = env->regs[R_EAX] & 0xff;
|
2012-04-29 17:12:26 +04:00
|
|
|
ah = al / base;
|
|
|
|
al = al % base;
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xffff) | al | (ah << 8);
|
2012-04-29 17:12:26 +04:00
|
|
|
CC_DST = al;
|
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_aad(CPUX86State *env, int base)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int al, ah;
|
|
|
|
|
2013-05-28 12:20:59 +04:00
|
|
|
al = env->regs[R_EAX] & 0xff;
|
|
|
|
ah = (env->regs[R_EAX] >> 8) & 0xff;
|
2012-04-29 17:12:26 +04:00
|
|
|
al = ((ah * base) + al) & 0xff;
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xffff) | al;
|
2012-04-29 17:12:26 +04:00
|
|
|
CC_DST = al;
|
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_aaa(CPUX86State *env)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int icarry;
|
|
|
|
int al, ah, af;
|
|
|
|
int eflags;
|
|
|
|
|
2012-04-29 16:45:34 +04:00
|
|
|
eflags = cpu_cc_compute_all(env, CC_OP);
|
2012-04-29 17:12:26 +04:00
|
|
|
af = eflags & CC_A;
|
2013-05-28 12:20:59 +04:00
|
|
|
al = env->regs[R_EAX] & 0xff;
|
|
|
|
ah = (env->regs[R_EAX] >> 8) & 0xff;
|
2012-04-29 17:12:26 +04:00
|
|
|
|
|
|
|
icarry = (al > 0xf9);
|
|
|
|
if (((al & 0x0f) > 9) || af) {
|
|
|
|
al = (al + 6) & 0x0f;
|
|
|
|
ah = (ah + 1 + icarry) & 0xff;
|
|
|
|
eflags |= CC_C | CC_A;
|
|
|
|
} else {
|
|
|
|
eflags &= ~(CC_C | CC_A);
|
|
|
|
al &= 0x0f;
|
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xffff) | al | (ah << 8);
|
2012-04-29 17:12:26 +04:00
|
|
|
CC_SRC = eflags;
|
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_aas(CPUX86State *env)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int icarry;
|
|
|
|
int al, ah, af;
|
|
|
|
int eflags;
|
|
|
|
|
2012-04-29 16:45:34 +04:00
|
|
|
eflags = cpu_cc_compute_all(env, CC_OP);
|
2012-04-29 17:12:26 +04:00
|
|
|
af = eflags & CC_A;
|
2013-05-28 12:20:59 +04:00
|
|
|
al = env->regs[R_EAX] & 0xff;
|
|
|
|
ah = (env->regs[R_EAX] >> 8) & 0xff;
|
2012-04-29 17:12:26 +04:00
|
|
|
|
|
|
|
icarry = (al < 6);
|
|
|
|
if (((al & 0x0f) > 9) || af) {
|
|
|
|
al = (al - 6) & 0x0f;
|
|
|
|
ah = (ah - 1 - icarry) & 0xff;
|
|
|
|
eflags |= CC_C | CC_A;
|
|
|
|
} else {
|
|
|
|
eflags &= ~(CC_C | CC_A);
|
|
|
|
al &= 0x0f;
|
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xffff) | al | (ah << 8);
|
2012-04-29 17:12:26 +04:00
|
|
|
CC_SRC = eflags;
|
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_daa(CPUX86State *env)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int old_al, al, af, cf;
|
|
|
|
int eflags;
|
|
|
|
|
2012-04-29 16:45:34 +04:00
|
|
|
eflags = cpu_cc_compute_all(env, CC_OP);
|
2012-04-29 17:12:26 +04:00
|
|
|
cf = eflags & CC_C;
|
|
|
|
af = eflags & CC_A;
|
2013-05-28 12:20:59 +04:00
|
|
|
old_al = al = env->regs[R_EAX] & 0xff;
|
2012-04-29 17:12:26 +04:00
|
|
|
|
|
|
|
eflags = 0;
|
|
|
|
if (((al & 0x0f) > 9) || af) {
|
|
|
|
al = (al + 6) & 0xff;
|
|
|
|
eflags |= CC_A;
|
|
|
|
}
|
|
|
|
if ((old_al > 0x99) || cf) {
|
|
|
|
al = (al + 0x60) & 0xff;
|
|
|
|
eflags |= CC_C;
|
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xff) | al;
|
2012-04-29 17:12:26 +04:00
|
|
|
/* well, speed is not an issue here, so we compute the flags by hand */
|
|
|
|
eflags |= (al == 0) << 6; /* zf */
|
|
|
|
eflags |= parity_table[al]; /* pf */
|
|
|
|
eflags |= (al & 0x80); /* sf */
|
|
|
|
CC_SRC = eflags;
|
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_das(CPUX86State *env)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
int al, al1, af, cf;
|
|
|
|
int eflags;
|
|
|
|
|
2012-04-29 16:45:34 +04:00
|
|
|
eflags = cpu_cc_compute_all(env, CC_OP);
|
2012-04-29 17:12:26 +04:00
|
|
|
cf = eflags & CC_C;
|
|
|
|
af = eflags & CC_A;
|
2013-05-28 12:20:59 +04:00
|
|
|
al = env->regs[R_EAX] & 0xff;
|
2012-04-29 17:12:26 +04:00
|
|
|
|
|
|
|
eflags = 0;
|
|
|
|
al1 = al;
|
|
|
|
if (((al & 0x0f) > 9) || af) {
|
|
|
|
eflags |= CC_A;
|
|
|
|
if (al < 6 || cf) {
|
|
|
|
eflags |= CC_C;
|
|
|
|
}
|
|
|
|
al = (al - 6) & 0xff;
|
|
|
|
}
|
|
|
|
if ((al1 > 0x99) || cf) {
|
|
|
|
al = (al - 0x60) & 0xff;
|
|
|
|
eflags |= CC_C;
|
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = (env->regs[R_EAX] & ~0xff) | al;
|
2012-04-29 17:12:26 +04:00
|
|
|
/* well, speed is not an issue here, so we compute the flags by hand */
|
|
|
|
eflags |= (al == 0) << 6; /* zf */
|
|
|
|
eflags |= parity_table[al]; /* pf */
|
|
|
|
eflags |= (al & 0x80); /* sf */
|
|
|
|
CC_SRC = eflags;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
static void add128(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b)
|
|
|
|
{
|
|
|
|
*plow += a;
|
|
|
|
/* carry test */
|
|
|
|
if (*plow < a) {
|
|
|
|
(*phigh)++;
|
|
|
|
}
|
|
|
|
*phigh += b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void neg128(uint64_t *plow, uint64_t *phigh)
|
|
|
|
{
|
|
|
|
*plow = ~*plow;
|
|
|
|
*phigh = ~*phigh;
|
|
|
|
add128(plow, phigh, 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return TRUE if overflow */
|
|
|
|
static int div64(uint64_t *plow, uint64_t *phigh, uint64_t b)
|
|
|
|
{
|
|
|
|
uint64_t q, r, a1, a0;
|
|
|
|
int i, qb, ab;
|
|
|
|
|
|
|
|
a0 = *plow;
|
|
|
|
a1 = *phigh;
|
|
|
|
if (a1 == 0) {
|
|
|
|
q = a0 / b;
|
|
|
|
r = a0 % b;
|
|
|
|
*plow = q;
|
|
|
|
*phigh = r;
|
|
|
|
} else {
|
|
|
|
if (a1 >= b) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* XXX: use a better algorithm */
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
ab = a1 >> 63;
|
|
|
|
a1 = (a1 << 1) | (a0 >> 63);
|
|
|
|
if (ab || a1 >= b) {
|
|
|
|
a1 -= b;
|
|
|
|
qb = 1;
|
|
|
|
} else {
|
|
|
|
qb = 0;
|
|
|
|
}
|
|
|
|
a0 = (a0 << 1) | qb;
|
|
|
|
}
|
|
|
|
#if defined(DEBUG_MULDIV)
|
|
|
|
printf("div: 0x%016" PRIx64 "%016" PRIx64 " / 0x%016" PRIx64
|
|
|
|
": q=0x%016" PRIx64 " r=0x%016" PRIx64 "\n",
|
|
|
|
*phigh, *plow, b, a0, a1);
|
|
|
|
#endif
|
|
|
|
*plow = a0;
|
|
|
|
*phigh = a1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return TRUE if overflow */
|
|
|
|
static int idiv64(uint64_t *plow, uint64_t *phigh, int64_t b)
|
|
|
|
{
|
|
|
|
int sa, sb;
|
|
|
|
|
|
|
|
sa = ((int64_t)*phigh < 0);
|
|
|
|
if (sa) {
|
|
|
|
neg128(plow, phigh);
|
|
|
|
}
|
|
|
|
sb = (b < 0);
|
|
|
|
if (sb) {
|
|
|
|
b = -b;
|
|
|
|
}
|
|
|
|
if (div64(plow, phigh, b) != 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (sa ^ sb) {
|
|
|
|
if (*plow > (1ULL << 63)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
*plow = -*plow;
|
|
|
|
} else {
|
|
|
|
if (*plow >= (1ULL << 63)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sa) {
|
|
|
|
*phigh = -*phigh;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_divq_EAX(CPUX86State *env, target_ulong t0)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
uint64_t r0, r1;
|
|
|
|
|
|
|
|
if (t0 == 0) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
r0 = env->regs[R_EAX];
|
2013-05-28 12:21:02 +04:00
|
|
|
r1 = env->regs[R_EDX];
|
2012-04-29 17:12:26 +04:00
|
|
|
if (div64(&r0, &r1, t0)) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = r0;
|
2013-05-28 12:21:02 +04:00
|
|
|
env->regs[R_EDX] = r1;
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
|
2012-04-29 18:11:56 +04:00
|
|
|
void helper_idivq_EAX(CPUX86State *env, target_ulong t0)
|
2012-04-29 17:12:26 +04:00
|
|
|
{
|
|
|
|
uint64_t r0, r1;
|
|
|
|
|
|
|
|
if (t0 == 0) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
r0 = env->regs[R_EAX];
|
2013-05-28 12:21:02 +04:00
|
|
|
r1 = env->regs[R_EDX];
|
2012-04-29 17:12:26 +04:00
|
|
|
if (idiv64(&r0, &r1, t0)) {
|
2015-07-10 12:57:25 +03:00
|
|
|
raise_exception_ra(env, EXCP00_DIVZ, GETPC());
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
2013-05-28 12:20:59 +04:00
|
|
|
env->regs[R_EAX] = r0;
|
2013-05-28 12:21:02 +04:00
|
|
|
env->regs[R_EDX] = r1;
|
2012-04-29 17:12:26 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-21 23:52:26 +04:00
|
|
|
#if TARGET_LONG_BITS == 32
|
|
|
|
# define ctztl ctz32
|
|
|
|
# define clztl clz32
|
|
|
|
#else
|
|
|
|
# define ctztl ctz64
|
|
|
|
# define clztl clz64
|
|
|
|
#endif
|
|
|
|
|
2013-01-24 06:09:43 +04:00
|
|
|
target_ulong helper_pdep(target_ulong src, target_ulong mask)
|
|
|
|
{
|
|
|
|
target_ulong dest = 0;
|
|
|
|
int i, o;
|
|
|
|
|
|
|
|
for (i = 0; mask != 0; i++) {
|
|
|
|
o = ctztl(mask);
|
|
|
|
mask &= mask - 1;
|
|
|
|
dest |= ((src >> i) & 1) << o;
|
|
|
|
}
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
target_ulong helper_pext(target_ulong src, target_ulong mask)
|
|
|
|
{
|
|
|
|
target_ulong dest = 0;
|
|
|
|
int i, o;
|
|
|
|
|
|
|
|
for (o = 0; mask != 0; o++) {
|
|
|
|
i = ctztl(mask);
|
|
|
|
mask &= mask - 1;
|
|
|
|
dest |= ((src >> i) & 1) << o;
|
|
|
|
}
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2012-04-29 17:12:26 +04:00
|
|
|
#define SHIFT 0
|
|
|
|
#include "shift_helper_template.h"
|
|
|
|
#undef SHIFT
|
|
|
|
|
|
|
|
#define SHIFT 1
|
|
|
|
#include "shift_helper_template.h"
|
|
|
|
#undef SHIFT
|
|
|
|
|
|
|
|
#define SHIFT 2
|
|
|
|
#include "shift_helper_template.h"
|
|
|
|
#undef SHIFT
|
|
|
|
|
|
|
|
#ifdef TARGET_X86_64
|
|
|
|
#define SHIFT 3
|
|
|
|
#include "shift_helper_template.h"
|
|
|
|
#undef SHIFT
|
|
|
|
#endif
|
2015-11-18 14:55:47 +03:00
|
|
|
|
|
|
|
/* Test that BIT is enabled in CR4. If not, raise an illegal opcode
|
|
|
|
exception. This reduces the requirements for rare CR4 bits being
|
|
|
|
mapped into HFLAGS. */
|
|
|
|
void helper_cr4_testbit(CPUX86State *env, uint32_t bit)
|
|
|
|
{
|
|
|
|
if (unlikely((env->cr[4] & bit) == 0)) {
|
|
|
|
raise_exception_ra(env, EXCP06_ILLOP, GETPC());
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 06:01:42 +03:00
|
|
|
|
|
|
|
target_ulong HELPER(rdrand)(CPUX86State *env)
|
|
|
|
{
|
|
|
|
Error *err = NULL;
|
|
|
|
target_ulong ret;
|
|
|
|
|
|
|
|
if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) {
|
|
|
|
qemu_log_mask(LOG_UNIMP, "rdrand: Crypto failure: %s",
|
|
|
|
error_get_pretty(err));
|
|
|
|
error_free(err);
|
|
|
|
/* Failure clears CF and all other flags, and returns 0. */
|
|
|
|
env->cc_src = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Success sets CF and clears all others. */
|
|
|
|
env->cc_src = CC_C;
|
|
|
|
return ret;
|
|
|
|
}
|