2015-08-21 07:04:50 +00:00
|
|
|
/*
|
|
|
|
* m68k op helpers
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006-2007 CodeSourcery
|
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-02-19 06:06:03 +00:00
|
|
|
#include "qemu/osdep.h"
|
2015-08-21 07:04:50 +00:00
|
|
|
#include "cpu.h"
|
2018-02-24 07:26:26 +00:00
|
|
|
#include "exec/exec-all.h"
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
#include "exec/helper-proto.h"
|
|
|
|
|
|
|
|
#define SIGNBIT (1u << 31)
|
|
|
|
|
|
|
|
M68kCPU *cpu_m68k_init(struct uc_struct *uc, const char *cpu_model)
|
|
|
|
{
|
|
|
|
M68kCPU *cpu;
|
|
|
|
CPUM68KState *env;
|
|
|
|
ObjectClass *oc;
|
|
|
|
|
|
|
|
oc = cpu_class_by_name(uc, TYPE_M68K_CPU, cpu_model);
|
|
|
|
if (oc == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
cpu = M68K_CPU(uc, object_new(uc, object_class_get_name(oc)));
|
|
|
|
env = &cpu->env;
|
|
|
|
|
|
|
|
register_m68k_insns(env);
|
|
|
|
|
|
|
|
object_property_set_bool(uc, OBJECT(cpu), true, "realized", NULL);
|
|
|
|
|
|
|
|
return cpu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(movec)(CPUM68KState *env, uint32_t reg, uint32_t val)
|
|
|
|
{
|
|
|
|
M68kCPU *cpu = m68k_env_get_cpu(env);
|
|
|
|
|
|
|
|
switch (reg) {
|
|
|
|
case 0x02: /* CACR */
|
|
|
|
env->cacr = val;
|
|
|
|
m68k_switch_sp(env);
|
|
|
|
break;
|
|
|
|
case 0x04: case 0x05: case 0x06: case 0x07: /* ACR[0-3] */
|
|
|
|
/* TODO: Implement Access Control Registers. */
|
|
|
|
break;
|
|
|
|
case 0x801: /* VBR */
|
|
|
|
env->vbr = val;
|
|
|
|
break;
|
|
|
|
/* TODO: Implement control registers. */
|
|
|
|
default:
|
|
|
|
cpu_abort(CPU(cpu), "Unimplemented control register write 0x%x = 0x%x\n",
|
|
|
|
reg, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(set_macsr)(CPUM68KState *env, uint32_t val)
|
|
|
|
{
|
|
|
|
uint32_t acc;
|
|
|
|
int8_t exthigh;
|
|
|
|
uint8_t extlow;
|
|
|
|
uint64_t regval;
|
|
|
|
int i;
|
|
|
|
if ((env->macsr ^ val) & (MACSR_FI | MACSR_SU)) {
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
regval = env->macc[i];
|
|
|
|
exthigh = regval >> 40;
|
|
|
|
if (env->macsr & MACSR_FI) {
|
|
|
|
acc = regval >> 8;
|
|
|
|
extlow = regval;
|
|
|
|
} else {
|
|
|
|
acc = regval;
|
|
|
|
extlow = regval >> 32;
|
|
|
|
}
|
|
|
|
if (env->macsr & MACSR_FI) {
|
|
|
|
regval = (((uint64_t)acc) << 8) | extlow;
|
|
|
|
regval |= ((int64_t)exthigh) << 40;
|
|
|
|
} else if (env->macsr & MACSR_SU) {
|
|
|
|
regval = acc | (((int64_t)extlow) << 32);
|
|
|
|
regval |= ((int64_t)exthigh) << 40;
|
|
|
|
} else {
|
|
|
|
regval = acc | (((uint64_t)extlow) << 32);
|
|
|
|
regval |= ((uint64_t)(uint8_t)exthigh) << 40;
|
|
|
|
}
|
|
|
|
env->macc[i] = regval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env->macsr = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void m68k_switch_sp(CPUM68KState *env)
|
|
|
|
{
|
|
|
|
int new_sp;
|
|
|
|
|
|
|
|
env->sp[env->current_sp] = env->aregs[7];
|
|
|
|
new_sp = (env->sr & SR_S && env->cacr & M68K_CACR_EUSP)
|
|
|
|
? M68K_SSP : M68K_USP;
|
|
|
|
env->aregs[7] = env->sp[new_sp];
|
|
|
|
env->current_sp = new_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_USER_ONLY)
|
|
|
|
|
|
|
|
int m68k_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
|
|
|
|
int mmu_idx)
|
|
|
|
{
|
|
|
|
M68kCPU *cpu = M68K_CPU(cs);
|
|
|
|
|
|
|
|
cs->exception_index = EXCP_ACCESS;
|
|
|
|
cpu->env.mmu.ar = address;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* MMU */
|
|
|
|
|
|
|
|
/* TODO: This will need fixing once the MMU is implemented. */
|
|
|
|
hwaddr m68k_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
|
|
|
|
{
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int m68k_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
|
|
|
|
int mmu_idx)
|
|
|
|
{
|
|
|
|
int prot;
|
|
|
|
|
|
|
|
address &= TARGET_PAGE_MASK;
|
|
|
|
prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
|
|
|
|
tlb_set_page(cs, address, address, prot, mmu_idx, TARGET_PAGE_SIZE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify CPU of a pending interrupt. Prioritization and vectoring should
|
|
|
|
be handled by the interrupt controller. Real hardware only requests
|
|
|
|
the vector when the interrupt is acknowledged by the CPU. For
|
|
|
|
simplicitly we calculate it when the interrupt is signalled. */
|
|
|
|
void m68k_set_irq_level(M68kCPU *cpu, int level, uint8_t vector)
|
|
|
|
{
|
|
|
|
CPUState *cs = CPU(cpu);
|
|
|
|
CPUM68KState *env = &cpu->env;
|
|
|
|
|
|
|
|
env->pending_level = level;
|
|
|
|
env->pending_vector = vector;
|
|
|
|
if (level) {
|
|
|
|
cpu_interrupt(cs, CPU_INTERRUPT_HARD);
|
|
|
|
} else {
|
|
|
|
cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
uint32_t HELPER(bitrev)(uint32_t x)
|
|
|
|
{
|
|
|
|
x = ((x >> 1) & 0x55555555u) | ((x << 1) & 0xaaaaaaaau);
|
|
|
|
x = ((x >> 2) & 0x33333333u) | ((x << 2) & 0xccccccccu);
|
|
|
|
x = ((x >> 4) & 0x0f0f0f0fu) | ((x << 4) & 0xf0f0f0f0u);
|
|
|
|
return bswap32(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(ff1)(uint32_t x)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
for (n = 32; x; n--)
|
|
|
|
x >>= 1;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2018-02-27 14:27:47 +00:00
|
|
|
uint32_t HELPER(sats)(uint32_t val, uint32_t v)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
|
|
|
/* The result has the opposite sign to the original value. */
|
2018-02-27 14:27:47 +00:00
|
|
|
if ((int32_t)v < 0) {
|
2015-08-21 07:04:50 +00:00
|
|
|
val = (((int32_t)val) >> 31) ^ SIGNBIT;
|
2018-02-27 14:27:47 +00:00
|
|
|
}
|
2015-08-21 07:04:50 +00:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(subx_cc)(CPUM68KState *env, uint32_t op1, uint32_t op2)
|
|
|
|
{
|
2018-02-27 14:27:47 +00:00
|
|
|
uint32_t res, new_x;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
if (env->cc_x) {
|
2018-02-27 14:27:47 +00:00
|
|
|
new_x = (op1 <= op2);
|
2015-08-21 07:04:50 +00:00
|
|
|
res = op1 - (op2 + 1);
|
|
|
|
} else {
|
2018-02-27 14:27:47 +00:00
|
|
|
new_x = (op1 < op2);
|
2015-08-21 07:04:50 +00:00
|
|
|
res = op1 - op2;
|
|
|
|
}
|
2018-02-27 14:27:47 +00:00
|
|
|
env->cc_x = new_x;
|
|
|
|
env->cc_c = new_x;
|
|
|
|
env->cc_n = res;
|
|
|
|
env->cc_z |= res; /* !Z is sticky */
|
|
|
|
env->cc_v = (res ^ op1) & (op1 ^ op2);
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(addx_cc)(CPUM68KState *env, uint32_t op1, uint32_t op2)
|
|
|
|
{
|
2018-02-27 14:27:47 +00:00
|
|
|
uint32_t res, new_x;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
if (env->cc_x) {
|
|
|
|
res = op1 + op2 + 1;
|
2018-02-27 14:27:47 +00:00
|
|
|
new_x = (res <= op2);
|
2015-08-21 07:04:50 +00:00
|
|
|
} else {
|
|
|
|
res = op1 + op2;
|
2018-02-27 14:27:47 +00:00
|
|
|
new_x = (res < op2);
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
2018-02-27 14:27:47 +00:00
|
|
|
env->cc_x = new_x;
|
|
|
|
env->cc_c = new_x;
|
|
|
|
env->cc_n = res;
|
|
|
|
env->cc_z |= res; /* !Z is sticky. */
|
|
|
|
env->cc_v = (res ^ op1) & ~(op1 ^ op2);
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(set_sr)(CPUM68KState *env, uint32_t val)
|
|
|
|
{
|
2018-02-27 14:19:19 +00:00
|
|
|
env->sr = val & 0xffe0;
|
|
|
|
cpu_m68k_set_ccr(env, val);
|
2015-08-21 07:04:50 +00:00
|
|
|
m68k_switch_sp(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(shl_cc)(CPUM68KState *env, uint32_t val, uint32_t shift)
|
|
|
|
{
|
2018-02-27 14:27:47 +00:00
|
|
|
uint64_t result;
|
2015-08-21 07:04:50 +00:00
|
|
|
|
|
|
|
shift &= 63;
|
2018-02-27 14:27:47 +00:00
|
|
|
result = (uint64_t)val << shift;
|
|
|
|
|
|
|
|
env->cc_c = (result >> 32) & 1;
|
|
|
|
env->cc_n = result;
|
|
|
|
env->cc_z = result;
|
|
|
|
env->cc_v = 0;
|
|
|
|
env->cc_x = shift ? env->cc_c : env->cc_x;
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(shr_cc)(CPUM68KState *env, uint32_t val, uint32_t shift)
|
|
|
|
{
|
2018-02-27 14:27:47 +00:00
|
|
|
uint64_t temp;
|
2015-08-21 07:04:50 +00:00
|
|
|
uint32_t result;
|
|
|
|
|
|
|
|
shift &= 63;
|
2018-02-27 14:27:47 +00:00
|
|
|
temp = (uint64_t)val << 32 >> shift;
|
|
|
|
result = temp >> 32;
|
|
|
|
|
|
|
|
env->cc_c = (temp >> 31) & 1;
|
|
|
|
env->cc_n = result;
|
|
|
|
env->cc_z = result;
|
|
|
|
env->cc_v = 0;
|
|
|
|
env->cc_x = shift ? env->cc_c : env->cc_x;
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(sar_cc)(CPUM68KState *env, uint32_t val, uint32_t shift)
|
|
|
|
{
|
2018-02-27 14:27:47 +00:00
|
|
|
uint64_t temp;
|
2015-08-21 07:04:50 +00:00
|
|
|
uint32_t result;
|
|
|
|
|
|
|
|
shift &= 63;
|
2018-02-27 14:27:47 +00:00
|
|
|
temp = (int64_t)val << 32 >> shift;
|
|
|
|
result = temp >> 32;
|
|
|
|
|
|
|
|
env->cc_c = (temp >> 31) & 1;
|
|
|
|
env->cc_n = result;
|
|
|
|
env->cc_z = result;
|
|
|
|
env->cc_v = result ^ val;
|
|
|
|
env->cc_x = shift ? env->cc_c : env->cc_x;
|
|
|
|
|
2015-08-21 07:04:50 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FPU helpers. */
|
|
|
|
uint32_t HELPER(f64_to_i32)(CPUM68KState *env, float64 val)
|
|
|
|
{
|
|
|
|
return float64_to_int32(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float32 HELPER(f64_to_f32)(CPUM68KState *env, float64 val)
|
|
|
|
{
|
|
|
|
return float64_to_float32(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(i32_to_f64)(CPUM68KState *env, uint32_t val)
|
|
|
|
{
|
|
|
|
return int32_to_float64(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(f32_to_f64)(CPUM68KState *env, float32 val)
|
|
|
|
{
|
|
|
|
return float32_to_float64(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(iround_f64)(CPUM68KState *env, float64 val)
|
|
|
|
{
|
|
|
|
return float64_round_to_int(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(itrunc_f64)(CPUM68KState *env, float64 val)
|
|
|
|
{
|
|
|
|
return float64_trunc_to_int(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(sqrt_f64)(CPUM68KState *env, float64 val)
|
|
|
|
{
|
|
|
|
return float64_sqrt(val, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(abs_f64)(float64 val)
|
|
|
|
{
|
|
|
|
return float64_abs(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(chs_f64)(float64 val)
|
|
|
|
{
|
|
|
|
return float64_chs(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(add_f64)(CPUM68KState *env, float64 a, float64 b)
|
|
|
|
{
|
|
|
|
return float64_add(a, b, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(sub_f64)(CPUM68KState *env, float64 a, float64 b)
|
|
|
|
{
|
|
|
|
return float64_sub(a, b, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(mul_f64)(CPUM68KState *env, float64 a, float64 b)
|
|
|
|
{
|
|
|
|
return float64_mul(a, b, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(div_f64)(CPUM68KState *env, float64 a, float64 b)
|
|
|
|
{
|
|
|
|
return float64_div(a, b, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 HELPER(sub_cmp_f64)(CPUM68KState *env, float64 a, float64 b)
|
|
|
|
{
|
|
|
|
/* ??? This may incorrectly raise exceptions. */
|
|
|
|
/* ??? Should flush denormals to zero. */
|
|
|
|
float64 res;
|
|
|
|
res = float64_sub(a, b, &env->fp_status);
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Backports commit af39bc8c49224771ec0d38f1b693ea78e221d7bc from qemu
2018-02-25 00:43:05 +00:00
|
|
|
if (float64_is_quiet_nan(res, &env->fp_status)) {
|
2015-08-21 07:04:50 +00:00
|
|
|
/* +/-inf compares equal against itself, but sub returns nan. */
|
softfloat: Implement run-time-configurable meaning of signaling NaN bit
This patch modifies SoftFloat library so that it can be configured in
run-time in relation to the meaning of signaling NaN bit, while, at the
same time, strictly preserving its behavior on all existing platforms.
Background:
In floating-point calculations, there is a need for denoting undefined or
unrepresentable values. This is achieved by defining certain floating-point
numerical values to be NaNs (which stands for "not a number"). For additional
reasons, virtually all modern floating-point unit implementations use two
kinds of NaNs: quiet and signaling. The binary representations of these two
kinds of NaNs, as a rule, differ only in one bit (that bit is, traditionally,
the first bit of mantissa).
Up to 2008, standards for floating-point did not specify all details about
binary representation of NaNs. More specifically, the meaning of the bit
that is used for distinguishing between signaling and quiet NaNs was not
strictly prescribed. (IEEE 754-2008 was the first floating-point standard
that defined that meaning clearly, see [1], p. 35) As a result, different
platforms took different approaches, and that presented considerable
challenge for multi-platform emulators like QEMU.
Mips platform represents the most complex case among QEMU-supported
platforms regarding signaling NaN bit. Up to the Release 6 of Mips
architecture, "1" in signaling NaN bit denoted signaling NaN, which is
opposite to IEEE 754-2008 standard. From Release 6 on, Mips architecture
adopted IEEE standard prescription, and "0" denotes signaling NaN. On top of
that, Mips architecture for SIMD (also known as MSA, or vector instructions)
also specifies signaling bit in accordance to IEEE standard. MSA unit can be
implemented with both pre-Release 6 and Release 6 main processor units.
QEMU uses SoftFloat library to implement various floating-point-related
instructions on all platforms. The current QEMU implementation allows for
defining meaning of signaling NaN bit during build time, and is implemented
via preprocessor macro called SNAN_BIT_IS_ONE.
On the other hand, the change in this patch enables SoftFloat library to be
configured in run-time. This configuration is meant to occur during CPU
initialization, at the moment when it is definitely known what desired
behavior for particular CPU (or any additional FPUs) is.
The change is implemented so that it is consistent with existing
implementation of similar cases. This means that structure float_status is
used for passing the information about desired signaling NaN bit on each
invocation of SoftFloat functions. The additional field in float_status is
called snan_bit_is_one, which supersedes macro SNAN_BIT_IS_ONE.
IMPORTANT:
This change is not meant to create any change in emulator behavior or
functionality on any platform. It just provides the means for SoftFloat
library to be used in a more flexible way - in other words, it will just
prepare SoftFloat library for usage related to Mips platform and its
specifics regarding signaling bit meaning, which is done in some of
subsequent patches from this series.
Further break down of changes:
1) Added field snan_bit_is_one to the structure float_status, and
correspondent setter function set_snan_bit_is_one().
2) Constants <float16|float32|float64|floatx80|float128>_default_nan
(used both internally and externally) converted to functions
<float16|float32|float64|floatx80|float128>_default_nan(float_status*).
This is necessary since they are dependent on signaling bit meaning.
At the same time, for the sake of code cleanup and simplicity, constants
<floatx80|float128>_default_nan_<low|high> (used only internally within
SoftFloat library) are removed, as not needed.
3) Added a float_status* argument to SoftFloat library functions
XXX_is_quiet_nan(XXX a_), XXX_is_signaling_nan(XXX a_),
XXX_maybe_silence_nan(XXX a_). This argument must be present in
order to enable correct invocation of new version of functions
XXX_default_nan(). (XXX is <float16|float32|float64|floatx80|float128>
here)
4) Updated code for all platforms to reflect changes in SoftFloat library.
This change is twofolds: it includes modifications of SoftFloat library
functions invocations, and an addition of invocation of function
set_snan_bit_is_one() during CPU initialization, with arguments that
are appropriate for each particular platform. It was established that
all platforms zero their main CPU data structures, so snan_bit_is_one(0)
in appropriate places is not added, as it is not needed.
[1] "IEEE Standard for Floating-Point Arithmetic",
IEEE Computer Society, August 29, 2008.
Backports commit af39bc8c49224771ec0d38f1b693ea78e221d7bc from qemu
2018-02-25 00:43:05 +00:00
|
|
|
if (!float64_is_quiet_nan(a, &env->fp_status)
|
|
|
|
&& !float64_is_quiet_nan(b, &env->fp_status)) {
|
2015-08-21 07:04:50 +00:00
|
|
|
res = float64_zero;
|
|
|
|
if (float64_lt_quiet(a, res, &env->fp_status))
|
|
|
|
res = float64_chs(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(compare_f64)(CPUM68KState *env, float64 val)
|
|
|
|
{
|
|
|
|
return float64_compare_quiet(val, float64_zero, &env->fp_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MAC unit. */
|
|
|
|
/* FIXME: The MAC unit implementation is a bit of a mess. Some helpers
|
|
|
|
take values, others take register numbers and manipulate the contents
|
|
|
|
in-place. */
|
|
|
|
void HELPER(mac_move)(CPUM68KState *env, uint32_t dest, uint32_t src)
|
|
|
|
{
|
|
|
|
uint32_t mask;
|
|
|
|
env->macc[dest] = env->macc[src];
|
|
|
|
mask = MACSR_PAV0 << dest;
|
|
|
|
if (env->macsr & (MACSR_PAV0 << src))
|
|
|
|
env->macsr |= mask;
|
|
|
|
else
|
|
|
|
env->macsr &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t HELPER(macmuls)(CPUM68KState *env, uint32_t op1, uint32_t op2)
|
|
|
|
{
|
|
|
|
int64_t product;
|
|
|
|
int64_t res;
|
|
|
|
|
|
|
|
product = (uint64_t)op1 * op2;
|
|
|
|
res = (product << 24) >> 24;
|
|
|
|
if (res != product) {
|
|
|
|
env->macsr |= MACSR_V;
|
|
|
|
if (env->macsr & MACSR_OMC) {
|
|
|
|
/* Make sure the accumulate operation overflows. */
|
|
|
|
if (product < 0)
|
|
|
|
res = ~(1ll << 50);
|
|
|
|
else
|
|
|
|
res = 1ll << 50;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t HELPER(macmulu)(CPUM68KState *env, uint32_t op1, uint32_t op2)
|
|
|
|
{
|
|
|
|
uint64_t product;
|
|
|
|
|
|
|
|
product = (uint64_t)op1 * op2;
|
|
|
|
if (product & (0xffffffull << 40)) {
|
|
|
|
env->macsr |= MACSR_V;
|
|
|
|
if (env->macsr & MACSR_OMC) {
|
|
|
|
/* Make sure the accumulate operation overflows. */
|
|
|
|
product = 1ll << 50;
|
|
|
|
} else {
|
|
|
|
product &= ((1ull << 40) - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return product;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t HELPER(macmulf)(CPUM68KState *env, uint32_t op1, uint32_t op2)
|
|
|
|
{
|
|
|
|
uint64_t product;
|
|
|
|
uint32_t remainder;
|
|
|
|
|
|
|
|
product = (uint64_t)op1 * op2;
|
|
|
|
if (env->macsr & MACSR_RT) {
|
|
|
|
remainder = product & 0xffffff;
|
|
|
|
product >>= 24;
|
|
|
|
if (remainder > 0x800000)
|
|
|
|
product++;
|
|
|
|
else if (remainder == 0x800000)
|
|
|
|
product += (product & 1);
|
|
|
|
} else {
|
|
|
|
product >>= 24;
|
|
|
|
}
|
|
|
|
return product;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(macsats)(CPUM68KState *env, uint32_t acc)
|
|
|
|
{
|
|
|
|
int64_t tmp;
|
|
|
|
int64_t result;
|
|
|
|
tmp = env->macc[acc];
|
|
|
|
result = ((tmp << 16) >> 16);
|
|
|
|
if (result != tmp) {
|
|
|
|
env->macsr |= MACSR_V;
|
|
|
|
}
|
|
|
|
if (env->macsr & MACSR_V) {
|
|
|
|
env->macsr |= MACSR_PAV0 << acc;
|
|
|
|
if (env->macsr & MACSR_OMC) {
|
|
|
|
/* The result is saturated to 32 bits, despite overflow occurring
|
|
|
|
at 48 bits. Seems weird, but that's what the hardware docs
|
|
|
|
say. */
|
|
|
|
result = (result >> 63) ^ 0x7fffffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env->macc[acc] = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(macsatu)(CPUM68KState *env, uint32_t acc)
|
|
|
|
{
|
|
|
|
uint64_t val;
|
|
|
|
|
|
|
|
val = env->macc[acc];
|
|
|
|
if (val & (0xffffull << 48)) {
|
|
|
|
env->macsr |= MACSR_V;
|
|
|
|
}
|
|
|
|
if (env->macsr & MACSR_V) {
|
|
|
|
env->macsr |= MACSR_PAV0 << acc;
|
|
|
|
if (env->macsr & MACSR_OMC) {
|
|
|
|
if (val > (1ull << 53))
|
|
|
|
val = 0;
|
|
|
|
else
|
|
|
|
val = (1ull << 48) - 1;
|
|
|
|
} else {
|
|
|
|
val &= ((1ull << 48) - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env->macc[acc] = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(macsatf)(CPUM68KState *env, uint32_t acc)
|
|
|
|
{
|
|
|
|
int64_t sum;
|
|
|
|
int64_t result;
|
|
|
|
|
|
|
|
sum = env->macc[acc];
|
|
|
|
result = (sum << 16) >> 16;
|
|
|
|
if (result != sum) {
|
|
|
|
env->macsr |= MACSR_V;
|
|
|
|
}
|
|
|
|
if (env->macsr & MACSR_V) {
|
|
|
|
env->macsr |= MACSR_PAV0 << acc;
|
|
|
|
if (env->macsr & MACSR_OMC) {
|
|
|
|
result = (result >> 63) ^ 0x7fffffffffffll;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
env->macc[acc] = result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(mac_set_flags)(CPUM68KState *env, uint32_t acc)
|
|
|
|
{
|
|
|
|
uint64_t val;
|
|
|
|
val = env->macc[acc];
|
|
|
|
if (val == 0) {
|
|
|
|
env->macsr |= MACSR_Z;
|
|
|
|
} else if (val & (1ull << 47)) {
|
|
|
|
env->macsr |= MACSR_N;
|
|
|
|
}
|
|
|
|
if (env->macsr & (MACSR_PAV0 << acc)) {
|
|
|
|
env->macsr |= MACSR_V;
|
|
|
|
}
|
|
|
|
if (env->macsr & MACSR_FI) {
|
|
|
|
val = ((int64_t)val) >> 40;
|
|
|
|
if (val != 0 && val != -1)
|
|
|
|
env->macsr |= MACSR_EV;
|
|
|
|
} else if (env->macsr & MACSR_SU) {
|
|
|
|
val = ((int64_t)val) >> 32;
|
|
|
|
if (val != 0 && val != -1)
|
|
|
|
env->macsr |= MACSR_EV;
|
|
|
|
} else {
|
|
|
|
if ((val >> 32) != 0)
|
|
|
|
env->macsr |= MACSR_EV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 14:27:47 +00:00
|
|
|
#define COMPUTE_CCR(op, x, n, z, v, c) { \
|
|
|
|
switch (op) { \
|
|
|
|
case CC_OP_FLAGS: \
|
|
|
|
/* Everything in place. */ \
|
|
|
|
break; \
|
|
|
|
case CC_OP_ADD: \
|
|
|
|
res = n; \
|
|
|
|
src2 = v; \
|
|
|
|
src1 = res - src2; \
|
|
|
|
c = x; \
|
|
|
|
z = n; \
|
|
|
|
v = (res ^ src1) & ~(src1 ^ src2); \
|
|
|
|
break; \
|
|
|
|
case CC_OP_SUB: \
|
|
|
|
res = n; \
|
|
|
|
src2 = v; \
|
|
|
|
src1 = res + src2; \
|
|
|
|
c = x; \
|
|
|
|
z = n; \
|
|
|
|
v = (res ^ src1) & (src1 ^ src2); \
|
|
|
|
break; \
|
|
|
|
case CC_OP_CMP: \
|
|
|
|
src1 = n; \
|
|
|
|
src2 = v; \
|
|
|
|
res = src1 - src2; \
|
|
|
|
n = res; \
|
|
|
|
z = res; \
|
|
|
|
c = src1 < src2; \
|
|
|
|
v = (res ^ src1) & (src1 ^ src2); \
|
|
|
|
break; \
|
|
|
|
case CC_OP_LOGIC: \
|
|
|
|
c = v = 0; \
|
|
|
|
z = n; \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
cpu_abort(CPU(m68k_env_get_cpu(env)), "Bad CC_OP %d", op); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
uint32_t cpu_m68k_get_ccr(CPUM68KState *env)
|
|
|
|
{
|
|
|
|
uint32_t x, c, n, z, v;
|
|
|
|
uint32_t res, src1, src2;
|
|
|
|
|
|
|
|
x = env->cc_x;
|
|
|
|
c = env->cc_c;
|
|
|
|
n = env->cc_n;
|
|
|
|
z = env->cc_z;
|
|
|
|
v = env->cc_v;
|
|
|
|
|
|
|
|
COMPUTE_CCR(env->cc_op, x, n, z, v, c);
|
|
|
|
|
|
|
|
n = n >> 31;
|
|
|
|
v = v >> 31;
|
|
|
|
z = (z == 0);
|
|
|
|
|
|
|
|
return x * CCF_X + n * CCF_N + z * CCF_Z + v * CCF_V + c * CCF_C;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(get_ccr)(CPUM68KState *env)
|
|
|
|
{
|
|
|
|
return cpu_m68k_get_ccr(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cpu_m68k_set_ccr(CPUM68KState *env, uint32_t ccr)
|
|
|
|
{
|
|
|
|
env->cc_x = (ccr & CCF_X ? 1 : 0);
|
|
|
|
env->cc_n = (ccr & CCF_N ? -1 : 0);
|
|
|
|
env->cc_z = (ccr & CCF_Z ? 0 : 1);
|
|
|
|
env->cc_v = (ccr & CCF_V ? -1 : 0);
|
|
|
|
env->cc_c = (ccr & CCF_C ? 1 : 0);
|
|
|
|
env->cc_op = CC_OP_FLAGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(set_ccr)(CPUM68KState *env, uint32_t ccr)
|
|
|
|
{
|
|
|
|
cpu_m68k_set_ccr(env, ccr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(flush_flags)(CPUM68KState *env, uint32_t cc_op)
|
2015-08-21 07:04:50 +00:00
|
|
|
{
|
2018-02-27 14:27:47 +00:00
|
|
|
uint32_t res, src1, src2;
|
|
|
|
|
|
|
|
COMPUTE_CCR(cc_op, env->cc_x, env->cc_n, env->cc_z, env->cc_v, env->cc_c);
|
|
|
|
env->cc_op = CC_OP_FLAGS;
|
2015-08-21 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(get_macf)(CPUM68KState *env, uint64_t val)
|
|
|
|
{
|
|
|
|
int rem;
|
|
|
|
uint32_t result;
|
|
|
|
|
|
|
|
if (env->macsr & MACSR_SU) {
|
|
|
|
/* 16-bit rounding. */
|
|
|
|
rem = val & 0xffffff;
|
|
|
|
val = (val >> 24) & 0xffffu;
|
|
|
|
if (rem > 0x800000)
|
|
|
|
val++;
|
|
|
|
else if (rem == 0x800000)
|
|
|
|
val += (val & 1);
|
|
|
|
} else if (env->macsr & MACSR_RT) {
|
|
|
|
/* 32-bit rounding. */
|
|
|
|
rem = val & 0xff;
|
|
|
|
val >>= 8;
|
|
|
|
if (rem > 0x80)
|
|
|
|
val++;
|
|
|
|
else if (rem == 0x80)
|
|
|
|
val += (val & 1);
|
|
|
|
} else {
|
|
|
|
/* No rounding. */
|
|
|
|
val >>= 8;
|
|
|
|
}
|
|
|
|
if (env->macsr & MACSR_OMC) {
|
|
|
|
/* Saturate. */
|
|
|
|
if (env->macsr & MACSR_SU) {
|
|
|
|
if (val != (uint16_t) val) {
|
|
|
|
result = ((val >> 63) ^ 0x7fff) & 0xffff;
|
|
|
|
} else {
|
|
|
|
result = val & 0xffff;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (val != (uint32_t)val) {
|
|
|
|
result = ((uint32_t)(val >> 63) & 0x7fffffff);
|
|
|
|
} else {
|
|
|
|
result = (uint32_t)val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* No saturation. */
|
|
|
|
if (env->macsr & MACSR_SU) {
|
|
|
|
result = val & 0xffff;
|
|
|
|
} else {
|
|
|
|
result = (uint32_t)val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(get_macs)(uint64_t val)
|
|
|
|
{
|
|
|
|
if (val == (int32_t)val) {
|
|
|
|
return (int32_t)val;
|
|
|
|
} else {
|
|
|
|
return (val >> 61) ^ ~SIGNBIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(get_macu)(uint64_t val)
|
|
|
|
{
|
|
|
|
if ((val >> 32) == 0) {
|
|
|
|
return (uint32_t)val;
|
|
|
|
} else {
|
|
|
|
return 0xffffffffu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(get_mac_extf)(CPUM68KState *env, uint32_t acc)
|
|
|
|
{
|
|
|
|
uint32_t val;
|
|
|
|
val = env->macc[acc] & 0x00ff;
|
2018-02-26 04:20:58 +00:00
|
|
|
val |= (env->macc[acc] >> 32) & 0xff00;
|
2015-08-21 07:04:50 +00:00
|
|
|
val |= (env->macc[acc + 1] << 16) & 0x00ff0000;
|
|
|
|
val |= (env->macc[acc + 1] >> 16) & 0xff000000;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t HELPER(get_mac_exti)(CPUM68KState *env, uint32_t acc)
|
|
|
|
{
|
|
|
|
uint32_t val;
|
|
|
|
val = (env->macc[acc] >> 32) & 0xffff;
|
|
|
|
val |= (env->macc[acc + 1] >> 16) & 0xffff0000;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(set_mac_extf)(CPUM68KState *env, uint32_t val, uint32_t acc)
|
|
|
|
{
|
|
|
|
int64_t res;
|
|
|
|
int32_t tmp;
|
|
|
|
res = env->macc[acc] & 0xffffffff00ull;
|
|
|
|
tmp = (int16_t)(val & 0xff00);
|
|
|
|
res |= ((int64_t)tmp) << 32;
|
|
|
|
res |= val & 0xff;
|
|
|
|
env->macc[acc] = res;
|
|
|
|
res = env->macc[acc + 1] & 0xffffffff00ull;
|
|
|
|
tmp = (val & 0xff000000);
|
|
|
|
res |= ((int64_t)tmp) << 16;
|
|
|
|
res |= (val >> 16) & 0xff;
|
|
|
|
env->macc[acc + 1] = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(set_mac_exts)(CPUM68KState *env, uint32_t val, uint32_t acc)
|
|
|
|
{
|
|
|
|
int64_t res;
|
|
|
|
int32_t tmp;
|
|
|
|
res = (uint32_t)env->macc[acc];
|
|
|
|
tmp = (int16_t)val;
|
|
|
|
res |= ((int64_t)tmp) << 32;
|
|
|
|
env->macc[acc] = res;
|
|
|
|
res = (uint32_t)env->macc[acc + 1];
|
|
|
|
tmp = val & 0xffff0000;
|
|
|
|
res |= (int64_t)tmp << 16;
|
|
|
|
env->macc[acc + 1] = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HELPER(set_mac_extu)(CPUM68KState *env, uint32_t val, uint32_t acc)
|
|
|
|
{
|
|
|
|
uint64_t res;
|
|
|
|
res = (uint32_t)env->macc[acc];
|
|
|
|
res |= ((uint64_t)(val & 0xffff)) << 32;
|
|
|
|
env->macc[acc] = res;
|
|
|
|
res = (uint32_t)env->macc[acc + 1];
|
|
|
|
res |= (uint64_t)(val & 0xffff0000) << 16;
|
|
|
|
env->macc[acc + 1] = res;
|
|
|
|
}
|