* 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "exec.h"
+#include "host-utils.h"
#include "softfloat.h"
-
-#include "op_helper.h"
-
-#define MEMSUFFIX _raw
-#include "op_helper_mem.h"
-
-#if !defined(CONFIG_USER_ONLY)
-#define MEMSUFFIX _kernel
-#include "op_helper_mem.h"
-
-#define MEMSUFFIX _executive
-#include "op_helper_mem.h"
-
-#define MEMSUFFIX _supervisor
-#include "op_helper_mem.h"
-
-#define MEMSUFFIX _user
-#include "op_helper_mem.h"
-
-/* This is used for pal modes */
-#define MEMSUFFIX _data
-#include "op_helper_mem.h"
-#endif
-
-void helper_tb_flush (void)
-{
- tlb_flush(env, 1);
-}
-
-void cpu_dump_EA (target_ulong EA);
-void helper_print_mem_EA (target_ulong EA)
-{
- cpu_dump_EA(EA);
-}
+#include "helper.h"
+#include "qemu-timer.h"
/*****************************************************************************/
/* Exceptions processing helpers */
-void helper_excp (uint32_t excp, uint32_t error)
+
+/* This should only be called from translate, via gen_excp.
+ We expect that ENV->PC has already been updated. */
+void QEMU_NORETURN helper_excp(int excp, int error)
{
env->exception_index = excp;
env->error_code = error;
- cpu_loop_exit();
+ cpu_loop_exit(env);
}
-void helper_amask (void)
+static void do_restore_state(void *retaddr)
{
- switch (env->implver) {
- case IMPLVER_2106x:
- /* EV4, EV45, LCA, LCA45 & EV5 */
- break;
- case IMPLVER_21164:
- case IMPLVER_21264:
- case IMPLVER_21364:
- T0 &= ~env->amask;
- break;
- }
-}
+ unsigned long pc = (unsigned long)retaddr;
-void helper_load_pcc (void)
-{
- /* XXX: TODO */
- T0 = 0;
+ if (pc) {
+ TranslationBlock *tb = tb_find_pc(pc);
+ if (tb) {
+ cpu_restore_state(tb, env, pc);
+ }
+ }
}
-void helper_load_implver (void)
+/* This may be called from any of the helpers to set up EXCEPTION_INDEX. */
+static void QEMU_NORETURN dynamic_excp(int excp, int error)
{
- T0 = env->implver;
+ env->exception_index = excp;
+ env->error_code = error;
+ do_restore_state(GETPC());
+ cpu_loop_exit(env);
}
-void helper_load_fpcr (void)
+static void QEMU_NORETURN arith_excp(int exc, uint64_t mask)
{
- T0 = 0;
-#ifdef CONFIG_SOFTFLOAT
- T0 |= env->fp_status.float_exception_flags << 52;
- if (env->fp_status.float_exception_flags)
- T0 |= 1ULL << 63;
- env->ipr[IPR_EXC_SUM] &= ~0x3E:
- env->ipr[IPR_EXC_SUM] |= env->fp_status.float_exception_flags << 1;
-#endif
- switch (env->fp_status.float_rounding_mode) {
- case float_round_nearest_even:
- T0 |= 2ULL << 58;
- break;
- case float_round_down:
- T0 |= 1ULL << 58;
- break;
- case float_round_up:
- T0 |= 3ULL << 58;
- break;
- case float_round_to_zero:
- break;
- }
+ env->trap_arg0 = exc;
+ env->trap_arg1 = mask;
+ dynamic_excp(EXCP_ARITH, 0);
}
-void helper_store_fpcr (void)
+uint64_t helper_load_pcc (void)
{
-#ifdef CONFIG_SOFTFLOAT
- set_float_exception_flags((T0 >> 52) & 0x3F, &FP_STATUS);
+#ifndef CONFIG_USER_ONLY
+ /* In system mode we have access to a decent high-resolution clock.
+ In order to make OS-level time accounting work with the RPCC,
+ present it with a well-timed clock fixed at 250MHz. */
+ return (((uint64_t)env->pcc_ofs << 32)
+ | (uint32_t)(qemu_get_clock_ns(vm_clock) >> 2));
+#else
+ /* In user-mode, vm_clock doesn't exist. Just pass through the host cpu
+ clock ticks. Also, don't bother taking PCC_OFS into account. */
+ return (uint32_t)cpu_get_real_ticks();
#endif
- switch ((T0 >> 58) & 3) {
- case 0:
- set_float_rounding_mode(float_round_to_zero, &FP_STATUS);
- break;
- case 1:
- set_float_rounding_mode(float_round_down, &FP_STATUS);
- break;
- case 2:
- set_float_rounding_mode(float_round_nearest_even, &FP_STATUS);
- break;
- case 3:
- set_float_rounding_mode(float_round_up, &FP_STATUS);
- break;
- }
}
-void helper_load_irf (void)
+uint64_t helper_load_fpcr (void)
{
- /* XXX: TODO */
- T0 = 0;
+ return cpu_alpha_load_fpcr (env);
}
-void helper_set_irf (void)
+void helper_store_fpcr (uint64_t val)
{
- /* XXX: TODO */
+ cpu_alpha_store_fpcr (env, val);
}
-void helper_clear_irf (void)
+uint64_t helper_addqv (uint64_t op1, uint64_t op2)
{
- /* XXX: TODO */
-}
-
-void helper_addqv (void)
-{
- T2 = T0;
- T0 += T1;
- if (unlikely((T2 ^ T1 ^ (-1ULL)) & (T2 ^ T0) & (1ULL << 63))) {
- helper_excp(EXCP_ARITH, EXCP_ARITH_OVERFLOW);
+ uint64_t tmp = op1;
+ op1 += op2;
+ if (unlikely((tmp ^ op2 ^ (-1ULL)) & (tmp ^ op1) & (1ULL << 63))) {
+ arith_excp(EXC_M_IOV, 0);
}
+ return op1;
}
-void helper_addlv (void)
+uint64_t helper_addlv (uint64_t op1, uint64_t op2)
{
- T2 = T0;
- T0 = (uint32_t)(T0 + T1);
- if (unlikely((T2 ^ T1 ^ (-1UL)) & (T2 ^ T0) & (1UL << 31))) {
- helper_excp(EXCP_ARITH, EXCP_ARITH_OVERFLOW);
+ uint64_t tmp = op1;
+ op1 = (uint32_t)(op1 + op2);
+ if (unlikely((tmp ^ op2 ^ (-1UL)) & (tmp ^ op1) & (1UL << 31))) {
+ arith_excp(EXC_M_IOV, 0);
}
+ return op1;
}
-void helper_subqv (void)
+uint64_t helper_subqv (uint64_t op1, uint64_t op2)
{
- T2 = T0;
- T0 -= T1;
- if (unlikely(((~T2) ^ T0 ^ (-1ULL)) & ((~T2) ^ T1) & (1ULL << 63))) {
- helper_excp(EXCP_ARITH, EXCP_ARITH_OVERFLOW);
+ uint64_t res;
+ res = op1 - op2;
+ if (unlikely((op1 ^ op2) & (res ^ op1) & (1ULL << 63))) {
+ arith_excp(EXC_M_IOV, 0);
}
+ return res;
}
-void helper_sublv (void)
+uint64_t helper_sublv (uint64_t op1, uint64_t op2)
{
- T2 = T0;
- T0 = (uint32_t)(T0 - T1);
- if (unlikely(((~T2) ^ T0 ^ (-1UL)) & ((~T2) ^ T1) & (1UL << 31))) {
- helper_excp(EXCP_ARITH, EXCP_ARITH_OVERFLOW);
+ uint32_t res;
+ res = op1 - op2;
+ if (unlikely((op1 ^ op2) & (res ^ op1) & (1UL << 31))) {
+ arith_excp(EXC_M_IOV, 0);
}
+ return res;
}
-void helper_mullv (void)
+uint64_t helper_mullv (uint64_t op1, uint64_t op2)
{
- int64_t res = (int64_t)T0 * (int64_t)T1;
+ int64_t res = (int64_t)op1 * (int64_t)op2;
if (unlikely((int32_t)res != res)) {
- helper_excp(EXCP_ARITH, EXCP_ARITH_OVERFLOW);
+ arith_excp(EXC_M_IOV, 0);
}
- T0 = (int64_t)((int32_t)res);
+ return (int64_t)((int32_t)res);
}
-void helper_mulqv ()
+uint64_t helper_mulqv (uint64_t op1, uint64_t op2)
{
uint64_t tl, th;
- muls64(&tl, &th, T0, T1);
+ muls64(&tl, &th, op1, op2);
/* If th != 0 && th != -1, then we had an overflow */
if (unlikely((th + 1) > 1)) {
- helper_excp(EXCP_ARITH, EXCP_ARITH_OVERFLOW);
+ arith_excp(EXC_M_IOV, 0);
}
- T0 = tl;
+ return tl;
}
-void helper_ctpop (void)
+uint64_t helper_umulh (uint64_t op1, uint64_t op2)
{
- int n;
+ uint64_t tl, th;
- for (n = 0; T0 != 0; n++)
- T0 = T0 ^ (T0 - 1);
- T0 = n;
+ mulu64(&tl, &th, op1, op2);
+ return th;
}
-void helper_ctlz (void)
+uint64_t helper_ctpop (uint64_t arg)
{
- uint32_t op32;
- int n;
-
- n = 0;
- if (!(T0 & 0xFFFFFFFF00000000ULL)) {
- n += 32;
- T0 <<= 32;
- }
- /* Make it easier for 32 bits hosts */
- op32 = T0 >> 32;
- if (!(op32 & 0xFFFF0000UL)) {
- n += 16;
- op32 <<= 16;
- }
- if (!(op32 & 0xFF000000UL)) {
- n += 8;
- op32 <<= 8;
- }
- if (!(op32 & 0xF0000000UL)) {
- n += 4;
- op32 <<= 4;
- }
- if (!(op32 & 0xC0000000UL)) {
- n += 2;
- op32 <<= 2;
- }
- if (!(op32 & 0x80000000UL)) {
- n++;
- op32 <<= 1;
- }
- if (!(op32 & 0x80000000UL)) {
- n++;
- }
- T0 = n;
+ return ctpop64(arg);
}
-void helper_cttz (void)
+uint64_t helper_ctlz (uint64_t arg)
{
- uint32_t op32;
- int n;
+ return clz64(arg);
+}
- n = 0;
- if (!(T0 & 0x00000000FFFFFFFFULL)) {
- n += 32;
- T0 >>= 32;
- }
- /* Make it easier for 32 bits hosts */
- op32 = T0;
- if (!(op32 & 0x0000FFFFUL)) {
- n += 16;
- op32 >>= 16;
- }
- if (!(op32 & 0x000000FFUL)) {
- n += 8;
- op32 >>= 8;
- }
- if (!(op32 & 0x0000000FUL)) {
- n += 4;
- op32 >>= 4;
- }
- if (!(op32 & 0x00000003UL)) {
- n += 2;
- op32 >>= 2;
- }
- if (!(op32 & 0x00000001UL)) {
- n++;
- op32 >>= 1;
- }
- if (!(op32 & 0x00000001UL)) {
- n++;
- }
- T0 = n;
+uint64_t helper_cttz (uint64_t arg)
+{
+ return ctz64(arg);
}
-static inline uint64_t byte_zap (uint64_t op, uint8_t mskb)
+static inline uint64_t byte_zap(uint64_t op, uint8_t mskb)
{
uint64_t mask;
return op & ~mask;
}
-void helper_mskbl (void)
+uint64_t helper_zap(uint64_t val, uint64_t mask)
{
- T0 = byte_zap(T0, 0x01 << (T1 & 7));
+ return byte_zap(val, mask);
}
-void helper_extbl (void)
+uint64_t helper_zapnot(uint64_t val, uint64_t mask)
{
- T0 >>= (T1 & 7) * 8;
- T0 = byte_zap(T0, 0xFE);
+ return byte_zap(val, ~mask);
}
-void helper_insbl (void)
+uint64_t helper_cmpbge (uint64_t op1, uint64_t op2)
{
- T0 <<= (T1 & 7) * 8;
- T0 = byte_zap(T0, ~(0x01 << (T1 & 7)));
-}
+ uint8_t opa, opb, res;
+ int i;
-void helper_mskwl (void)
-{
- T0 = byte_zap(T0, 0x03 << (T1 & 7));
+ res = 0;
+ for (i = 0; i < 8; i++) {
+ opa = op1 >> (i * 8);
+ opb = op2 >> (i * 8);
+ if (opa >= opb)
+ res |= 1 << i;
+ }
+ return res;
}
-void helper_extwl (void)
+uint64_t helper_minub8 (uint64_t op1, uint64_t op2)
{
- T0 >>= (T1 & 7) * 8;
- T0 = byte_zap(T0, 0xFC);
-}
+ uint64_t res = 0;
+ uint8_t opa, opb, opr;
+ int i;
-void helper_inswl (void)
-{
- T0 <<= (T1 & 7) * 8;
- T0 = byte_zap(T0, ~(0x03 << (T1 & 7)));
+ for (i = 0; i < 8; ++i) {
+ opa = op1 >> (i * 8);
+ opb = op2 >> (i * 8);
+ opr = opa < opb ? opa : opb;
+ res |= (uint64_t)opr << (i * 8);
+ }
+ return res;
}
-void helper_mskll (void)
+uint64_t helper_minsb8 (uint64_t op1, uint64_t op2)
{
- T0 = byte_zap(T0, 0x0F << (T1 & 7));
-}
+ uint64_t res = 0;
+ int8_t opa, opb;
+ uint8_t opr;
+ int i;
-void helper_extll (void)
-{
- T0 >>= (T1 & 7) * 8;
- T0 = byte_zap(T0, 0xF0);
+ for (i = 0; i < 8; ++i) {
+ opa = op1 >> (i * 8);
+ opb = op2 >> (i * 8);
+ opr = opa < opb ? opa : opb;
+ res |= (uint64_t)opr << (i * 8);
+ }
+ return res;
}
-void helper_insll (void)
+uint64_t helper_minuw4 (uint64_t op1, uint64_t op2)
{
- T0 <<= (T1 & 7) * 8;
- T0 = byte_zap(T0, ~(0x0F << (T1 & 7)));
+ uint64_t res = 0;
+ uint16_t opa, opb, opr;
+ int i;
+
+ for (i = 0; i < 4; ++i) {
+ opa = op1 >> (i * 16);
+ opb = op2 >> (i * 16);
+ opr = opa < opb ? opa : opb;
+ res |= (uint64_t)opr << (i * 16);
+ }
+ return res;
}
-void helper_zap (void)
+uint64_t helper_minsw4 (uint64_t op1, uint64_t op2)
{
- T0 = byte_zap(T0, T1);
+ uint64_t res = 0;
+ int16_t opa, opb;
+ uint16_t opr;
+ int i;
+
+ for (i = 0; i < 4; ++i) {
+ opa = op1 >> (i * 16);
+ opb = op2 >> (i * 16);
+ opr = opa < opb ? opa : opb;
+ res |= (uint64_t)opr << (i * 16);
+ }
+ return res;
}
-void helper_zapnot (void)
+uint64_t helper_maxub8 (uint64_t op1, uint64_t op2)
{
- T0 = byte_zap(T0, ~T1);
+ uint64_t res = 0;
+ uint8_t opa, opb, opr;
+ int i;
+
+ for (i = 0; i < 8; ++i) {
+ opa = op1 >> (i * 8);
+ opb = op2 >> (i * 8);
+ opr = opa > opb ? opa : opb;
+ res |= (uint64_t)opr << (i * 8);
+ }
+ return res;
}
-void helper_mskql (void)
+uint64_t helper_maxsb8 (uint64_t op1, uint64_t op2)
{
- T0 = byte_zap(T0, 0xFF << (T1 & 7));
+ uint64_t res = 0;
+ int8_t opa, opb;
+ uint8_t opr;
+ int i;
+
+ for (i = 0; i < 8; ++i) {
+ opa = op1 >> (i * 8);
+ opb = op2 >> (i * 8);
+ opr = opa > opb ? opa : opb;
+ res |= (uint64_t)opr << (i * 8);
+ }
+ return res;
}
-void helper_extql (void)
+uint64_t helper_maxuw4 (uint64_t op1, uint64_t op2)
{
- T0 >>= (T1 & 7) * 8;
- T0 = byte_zap(T0, 0x00);
+ uint64_t res = 0;
+ uint16_t opa, opb, opr;
+ int i;
+
+ for (i = 0; i < 4; ++i) {
+ opa = op1 >> (i * 16);
+ opb = op2 >> (i * 16);
+ opr = opa > opb ? opa : opb;
+ res |= (uint64_t)opr << (i * 16);
+ }
+ return res;
}
-void helper_insql (void)
+uint64_t helper_maxsw4 (uint64_t op1, uint64_t op2)
{
- T0 <<= (T1 & 7) * 8;
- T0 = byte_zap(T0, ~(0xFF << (T1 & 7)));
+ uint64_t res = 0;
+ int16_t opa, opb;
+ uint16_t opr;
+ int i;
+
+ for (i = 0; i < 4; ++i) {
+ opa = op1 >> (i * 16);
+ opb = op2 >> (i * 16);
+ opr = opa > opb ? opa : opb;
+ res |= (uint64_t)opr << (i * 16);
+ }
+ return res;
}
-void helper_mskwh (void)
+uint64_t helper_perr (uint64_t op1, uint64_t op2)
{
- T0 = byte_zap(T0, (0x03 << (T1 & 7)) >> 8);
+ uint64_t res = 0;
+ uint8_t opa, opb, opr;
+ int i;
+
+ for (i = 0; i < 8; ++i) {
+ opa = op1 >> (i * 8);
+ opb = op2 >> (i * 8);
+ if (opa >= opb)
+ opr = opa - opb;
+ else
+ opr = opb - opa;
+ res += opr;
+ }
+ return res;
}
-void helper_inswh (void)
+uint64_t helper_pklb (uint64_t op1)
{
- T0 >>= 64 - ((T1 & 7) * 8);
- T0 = byte_zap(T0, ~((0x03 << (T1 & 7)) >> 8));
+ return (op1 & 0xff) | ((op1 >> 24) & 0xff00);
}
-void helper_extwh (void)
+uint64_t helper_pkwb (uint64_t op1)
{
- T0 <<= 64 - ((T1 & 7) * 8);
- T0 = byte_zap(T0, ~0x07);
+ return ((op1 & 0xff)
+ | ((op1 >> 8) & 0xff00)
+ | ((op1 >> 16) & 0xff0000)
+ | ((op1 >> 24) & 0xff000000));
}
-void helper_msklh (void)
+uint64_t helper_unpkbl (uint64_t op1)
{
- T0 = byte_zap(T0, (0x0F << (T1 & 7)) >> 8);
+ return (op1 & 0xff) | ((op1 & 0xff00) << 24);
}
-void helper_inslh (void)
+uint64_t helper_unpkbw (uint64_t op1)
{
- T0 >>= 64 - ((T1 & 7) * 8);
- T0 = byte_zap(T0, ~((0x0F << (T1 & 7)) >> 8));
+ return ((op1 & 0xff)
+ | ((op1 & 0xff00) << 8)
+ | ((op1 & 0xff0000) << 16)
+ | ((op1 & 0xff000000) << 24));
}
-void helper_extlh (void)
+/* Floating point helpers */
+
+void helper_setroundmode (uint32_t val)
{
- T0 <<= 64 - ((T1 & 7) * 8);
- T0 = byte_zap(T0, ~0x0F);
+ set_float_rounding_mode(val, &FP_STATUS);
}
-void helper_mskqh (void)
+void helper_setflushzero (uint32_t val)
{
- T0 = byte_zap(T0, (0xFF << (T1 & 7)) >> 8);
+ set_flush_to_zero(val, &FP_STATUS);
}
-void helper_insqh (void)
+void helper_fp_exc_clear (void)
{
- T0 >>= 64 - ((T1 & 7) * 8);
- T0 = byte_zap(T0, ~((0xFF << (T1 & 7)) >> 8));
+ set_float_exception_flags(0, &FP_STATUS);
}
-void helper_extqh (void)
+uint32_t helper_fp_exc_get (void)
{
- T0 <<= 64 - ((T1 & 7) * 8);
- T0 = byte_zap(T0, 0x00);
+ return get_float_exception_flags(&FP_STATUS);
}
-void helper_cmpbge (void)
+/* Raise exceptions for ieee fp insns without software completion.
+ In that case there are no exceptions that don't trap; the mask
+ doesn't apply. */
+void helper_fp_exc_raise(uint32_t exc, uint32_t regno)
{
- uint8_t opa, opb, res;
- int i;
+ if (exc) {
+ uint32_t hw_exc = 0;
- res = 0;
- for (i = 0; i < 7; i++) {
- opa = T0 >> (i * 8);
- opb = T1 >> (i * 8);
- if (opa >= opb)
- res |= 1 << i;
+ if (exc & float_flag_invalid) {
+ hw_exc |= EXC_M_INV;
+ }
+ if (exc & float_flag_divbyzero) {
+ hw_exc |= EXC_M_DZE;
+ }
+ if (exc & float_flag_overflow) {
+ hw_exc |= EXC_M_FOV;
+ }
+ if (exc & float_flag_underflow) {
+ hw_exc |= EXC_M_UNF;
+ }
+ if (exc & float_flag_inexact) {
+ hw_exc |= EXC_M_INE;
+ }
+
+ arith_excp(hw_exc, 1ull << regno);
}
- T0 = res;
}
-void helper_cmov_fir (int freg)
+/* Raise exceptions for ieee fp insns with software completion. */
+void helper_fp_exc_raise_s(uint32_t exc, uint32_t regno)
{
- if (FT0 != 0)
- env->fir[freg] = FT1;
-}
+ if (exc) {
+ env->fpcr_exc_status |= exc;
-void helper_sqrts (void)
-{
- FT0 = float32_sqrt(FT0, &FP_STATUS);
+ exc &= ~env->fpcr_exc_mask;
+ if (exc) {
+ helper_fp_exc_raise(exc, regno);
+ }
+ }
}
-void helper_cpys (void)
+/* Input remapping without software completion. Handle denormal-map-to-zero
+ and trap for all other non-finite numbers. */
+uint64_t helper_ieee_input(uint64_t val)
{
- union {
- double d;
- uint64_t i;
- } p, q, r;
+ uint32_t exp = (uint32_t)(val >> 52) & 0x7ff;
+ uint64_t frac = val & 0xfffffffffffffull;
- p.d = FT0;
- q.d = FT1;
- r.i = p.i & 0x8000000000000000ULL;
- r.i |= q.i & ~0x8000000000000000ULL;
- FT0 = r.d;
+ if (exp == 0) {
+ if (frac != 0) {
+ /* If DNZ is set flush denormals to zero on input. */
+ if (env->fpcr_dnz) {
+ val &= 1ull << 63;
+ } else {
+ arith_excp(EXC_M_UNF, 0);
+ }
+ }
+ } else if (exp == 0x7ff) {
+ /* Infinity or NaN. */
+ /* ??? I'm not sure these exception bit flags are correct. I do
+ know that the Linux kernel, at least, doesn't rely on them and
+ just emulates the insn to figure out what exception to use. */
+ arith_excp(frac ? EXC_M_INV : EXC_M_FOV, 0);
+ }
+ return val;
}
-void helper_cpysn (void)
+/* Similar, but does not trap for infinities. Used for comparisons. */
+uint64_t helper_ieee_input_cmp(uint64_t val)
{
- union {
- double d;
- uint64_t i;
- } p, q, r;
+ uint32_t exp = (uint32_t)(val >> 52) & 0x7ff;
+ uint64_t frac = val & 0xfffffffffffffull;
- p.d = FT0;
- q.d = FT1;
- r.i = (~p.i) & 0x8000000000000000ULL;
- r.i |= q.i & ~0x8000000000000000ULL;
- FT0 = r.d;
+ if (exp == 0) {
+ if (frac != 0) {
+ /* If DNZ is set flush denormals to zero on input. */
+ if (env->fpcr_dnz) {
+ val &= 1ull << 63;
+ } else {
+ arith_excp(EXC_M_UNF, 0);
+ }
+ }
+ } else if (exp == 0x7ff && frac) {
+ /* NaN. */
+ arith_excp(EXC_M_INV, 0);
+ }
+ return val;
}
-void helper_cpyse (void)
+/* Input remapping with software completion enabled. All we have to do
+ is handle denormal-map-to-zero; all other inputs get exceptions as
+ needed from the actual operation. */
+uint64_t helper_ieee_input_s(uint64_t val)
{
- union {
- double d;
- uint64_t i;
- } p, q, r;
-
- p.d = FT0;
- q.d = FT1;
- r.i = p.i & 0xFFF0000000000000ULL;
- r.i |= q.i & ~0xFFF0000000000000ULL;
- FT0 = r.d;
+ if (env->fpcr_dnz) {
+ uint32_t exp = (uint32_t)(val >> 52) & 0x7ff;
+ if (exp == 0) {
+ val &= 1ull << 63;
+ }
+ }
+ return val;
}
-void helper_itofs (void)
+/* F floating (VAX) */
+static inline uint64_t float32_to_f(float32 fa)
{
- union {
- double d;
- uint64_t i;
- } p;
+ uint64_t r, exp, mant, sig;
+ CPU_FloatU a;
- p.d = FT0;
- FT0 = int64_to_float32(p.i, &FP_STATUS);
-}
+ a.f = fa;
+ sig = ((uint64_t)a.l & 0x80000000) << 32;
+ exp = (a.l >> 23) & 0xff;
+ mant = ((uint64_t)a.l & 0x007fffff) << 29;
-void helper_ftois (void)
-{
- union {
- double d;
- uint64_t i;
- } p;
+ if (exp == 255) {
+ /* NaN or infinity */
+ r = 1; /* VAX dirty zero */
+ } else if (exp == 0) {
+ if (mant == 0) {
+ /* Zero */
+ r = 0;
+ } else {
+ /* Denormalized */
+ r = sig | ((exp + 1) << 52) | mant;
+ }
+ } else {
+ if (exp >= 253) {
+ /* Overflow */
+ r = 1; /* VAX dirty zero */
+ } else {
+ r = sig | ((exp + 2) << 52);
+ }
+ }
- p.i = float32_to_int64(FT0, &FP_STATUS);
- FT0 = p.d;
+ return r;
}
-void helper_sqrtt (void)
+static inline float32 f_to_float32(uint64_t a)
{
- FT0 = float64_sqrt(FT0, &FP_STATUS);
-}
+ uint32_t exp, mant_sig;
+ CPU_FloatU r;
-void helper_cmptun (void)
-{
- union {
- double d;
- uint64_t i;
- } p;
+ exp = ((a >> 55) & 0x80) | ((a >> 52) & 0x7f);
+ mant_sig = ((a >> 32) & 0x80000000) | ((a >> 29) & 0x007fffff);
- p.i = 0;
- if (float64_is_nan(FT0) || float64_is_nan(FT1))
- p.i = 0x4000000000000000ULL;
- FT0 = p.d;
-}
+ if (unlikely(!exp && mant_sig)) {
+ /* Reserved operands / Dirty zero */
+ dynamic_excp(EXCP_OPCDEC, 0);
+ }
-void helper_cmpteq (void)
-{
- union {
- double d;
- uint64_t i;
- } p;
+ if (exp < 3) {
+ /* Underflow */
+ r.l = 0;
+ } else {
+ r.l = ((exp - 2) << 23) | mant_sig;
+ }
- p.i = 0;
- if (float64_eq(FT0, FT1, &FP_STATUS))
- p.i = 0x4000000000000000ULL;
- FT0 = p.d;
+ return r.f;
}
-void helper_cmptle (void)
+uint32_t helper_f_to_memory (uint64_t a)
{
- union {
- double d;
- uint64_t i;
- } p;
+ uint32_t r;
+ r = (a & 0x00001fffe0000000ull) >> 13;
+ r |= (a & 0x07ffe00000000000ull) >> 45;
+ r |= (a & 0xc000000000000000ull) >> 48;
+ return r;
+}
- p.i = 0;
- if (float64_le(FT0, FT1, &FP_STATUS))
- p.i = 0x4000000000000000ULL;
- FT0 = p.d;
+uint64_t helper_memory_to_f (uint32_t a)
+{
+ uint64_t r;
+ r = ((uint64_t)(a & 0x0000c000)) << 48;
+ r |= ((uint64_t)(a & 0x003fffff)) << 45;
+ r |= ((uint64_t)(a & 0xffff0000)) << 13;
+ if (!(a & 0x00004000))
+ r |= 0x7ll << 59;
+ return r;
}
-void helper_cmptlt (void)
+/* ??? Emulating VAX arithmetic with IEEE arithmetic is wrong. We should
+ either implement VAX arithmetic properly or just signal invalid opcode. */
+
+uint64_t helper_addf (uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t i;
- } p;
+ float32 fa, fb, fr;
- p.i = 0;
- if (float64_lt(FT0, FT1, &FP_STATUS))
- p.i = 0x4000000000000000ULL;
- FT0 = p.d;
+ fa = f_to_float32(a);
+ fb = f_to_float32(b);
+ fr = float32_add(fa, fb, &FP_STATUS);
+ return float32_to_f(fr);
}
-void helper_itoft (void)
+uint64_t helper_subf (uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t i;
- } p;
+ float32 fa, fb, fr;
- p.d = FT0;
- FT0 = int64_to_float64(p.i, &FP_STATUS);
+ fa = f_to_float32(a);
+ fb = f_to_float32(b);
+ fr = float32_sub(fa, fb, &FP_STATUS);
+ return float32_to_f(fr);
}
-void helper_ftoit (void)
+uint64_t helper_mulf (uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t i;
- } p;
+ float32 fa, fb, fr;
- p.i = float64_to_int64(FT0, &FP_STATUS);
- FT0 = p.d;
+ fa = f_to_float32(a);
+ fb = f_to_float32(b);
+ fr = float32_mul(fa, fb, &FP_STATUS);
+ return float32_to_f(fr);
}
-static int vaxf_is_valid (float ff)
+uint64_t helper_divf (uint64_t a, uint64_t b)
{
- union {
- float f;
- uint32_t i;
- } p;
- uint32_t exp, mant;
-
- p.f = ff;
- exp = (p.i >> 23) & 0xFF;
- mant = p.i & 0x007FFFFF;
- if (exp == 0 && ((p.i & 0x80000000) || mant != 0)) {
- /* Reserved operands / Dirty zero */
- return 0;
- }
+ float32 fa, fb, fr;
- return 1;
+ fa = f_to_float32(a);
+ fb = f_to_float32(b);
+ fr = float32_div(fa, fb, &FP_STATUS);
+ return float32_to_f(fr);
}
-static float vaxf_to_ieee32 (float ff)
+uint64_t helper_sqrtf (uint64_t t)
{
- union {
- float f;
- uint32_t i;
- } p;
- uint32_t exp;
+ float32 ft, fr;
- p.f = ff;
- exp = (p.i >> 23) & 0xFF;
- if (exp < 3) {
- /* Underflow */
- p.f = 0.0;
- } else {
- p.f *= 0.25;
- }
-
- return p.f;
+ ft = f_to_float32(t);
+ fr = float32_sqrt(ft, &FP_STATUS);
+ return float32_to_f(fr);
}
-static float ieee32_to_vaxf (float fi)
+
+/* G floating (VAX) */
+static inline uint64_t float64_to_g(float64 fa)
{
- union {
- float f;
- uint32_t i;
- } p;
- uint32_t exp, mant;
+ uint64_t r, exp, mant, sig;
+ CPU_DoubleU a;
- p.f = fi;
- exp = (p.i >> 23) & 0xFF;
- mant = p.i & 0x007FFFFF;
- if (exp == 255) {
+ a.d = fa;
+ sig = a.ll & 0x8000000000000000ull;
+ exp = (a.ll >> 52) & 0x7ff;
+ mant = a.ll & 0x000fffffffffffffull;
+
+ if (exp == 2047) {
/* NaN or infinity */
- p.i = 1;
+ r = 1; /* VAX dirty zero */
} else if (exp == 0) {
if (mant == 0) {
/* Zero */
- p.i = 0;
+ r = 0;
} else {
/* Denormalized */
- p.f *= 2.0;
+ r = sig | ((exp + 1) << 52) | mant;
}
} else {
- if (exp >= 253) {
+ if (exp >= 2045) {
/* Overflow */
- p.i = 1;
+ r = 1; /* VAX dirty zero */
} else {
- p.f *= 4.0;
+ r = sig | ((exp + 2) << 52);
}
}
- return p.f;
+ return r;
}
-void helper_addf (void)
+static inline float64 g_to_float64(uint64_t a)
{
- float ft0, ft1, ft2;
+ uint64_t exp, mant_sig;
+ CPU_DoubleU r;
- if (!vaxf_is_valid(FT0) || !vaxf_is_valid(FT1)) {
- /* XXX: TODO */
+ exp = (a >> 52) & 0x7ff;
+ mant_sig = a & 0x800fffffffffffffull;
+
+ if (!exp && mant_sig) {
+ /* Reserved operands / Dirty zero */
+ dynamic_excp(EXCP_OPCDEC, 0);
}
- ft0 = vaxf_to_ieee32(FT0);
- ft1 = vaxf_to_ieee32(FT1);
- ft2 = float32_add(ft0, ft1, &FP_STATUS);
- FT0 = ieee32_to_vaxf(ft2);
+
+ if (exp < 3) {
+ /* Underflow */
+ r.ll = 0;
+ } else {
+ r.ll = ((exp - 2) << 52) | mant_sig;
+ }
+
+ return r.d;
}
-void helper_subf (void)
+uint64_t helper_g_to_memory (uint64_t a)
{
- float ft0, ft1, ft2;
+ uint64_t r;
+ r = (a & 0x000000000000ffffull) << 48;
+ r |= (a & 0x00000000ffff0000ull) << 16;
+ r |= (a & 0x0000ffff00000000ull) >> 16;
+ r |= (a & 0xffff000000000000ull) >> 48;
+ return r;
+}
- if (!vaxf_is_valid(FT0) || !vaxf_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxf_to_ieee32(FT0);
- ft1 = vaxf_to_ieee32(FT1);
- ft2 = float32_sub(ft0, ft1, &FP_STATUS);
- FT0 = ieee32_to_vaxf(ft2);
+uint64_t helper_memory_to_g (uint64_t a)
+{
+ uint64_t r;
+ r = (a & 0x000000000000ffffull) << 48;
+ r |= (a & 0x00000000ffff0000ull) << 16;
+ r |= (a & 0x0000ffff00000000ull) >> 16;
+ r |= (a & 0xffff000000000000ull) >> 48;
+ return r;
}
-void helper_mulf (void)
+uint64_t helper_addg (uint64_t a, uint64_t b)
{
- float ft0, ft1, ft2;
+ float64 fa, fb, fr;
- if (!vaxf_is_valid(FT0) || !vaxf_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxf_to_ieee32(FT0);
- ft1 = vaxf_to_ieee32(FT1);
- ft2 = float32_mul(ft0, ft1, &FP_STATUS);
- FT0 = ieee32_to_vaxf(ft2);
+ fa = g_to_float64(a);
+ fb = g_to_float64(b);
+ fr = float64_add(fa, fb, &FP_STATUS);
+ return float64_to_g(fr);
}
-void helper_divf (void)
+uint64_t helper_subg (uint64_t a, uint64_t b)
{
- float ft0, ft1, ft2;
+ float64 fa, fb, fr;
- if (!vaxf_is_valid(FT0) || !vaxf_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxf_to_ieee32(FT0);
- ft1 = vaxf_to_ieee32(FT1);
- ft2 = float32_div(ft0, ft1, &FP_STATUS);
- FT0 = ieee32_to_vaxf(ft2);
+ fa = g_to_float64(a);
+ fb = g_to_float64(b);
+ fr = float64_sub(fa, fb, &FP_STATUS);
+ return float64_to_g(fr);
}
-void helper_sqrtf (void)
+uint64_t helper_mulg (uint64_t a, uint64_t b)
{
- float ft0, ft1;
+ float64 fa, fb, fr;
- if (!vaxf_is_valid(FT0) || !vaxf_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxf_to_ieee32(FT0);
- ft1 = float32_sqrt(ft0, &FP_STATUS);
- FT0 = ieee32_to_vaxf(ft1);
+ fa = g_to_float64(a);
+ fb = g_to_float64(b);
+ fr = float64_mul(fa, fb, &FP_STATUS);
+ return float64_to_g(fr);
}
-void helper_itoff (void)
+uint64_t helper_divg (uint64_t a, uint64_t b)
{
- /* XXX: TODO */
+ float64 fa, fb, fr;
+
+ fa = g_to_float64(a);
+ fb = g_to_float64(b);
+ fr = float64_div(fa, fb, &FP_STATUS);
+ return float64_to_g(fr);
}
-static int vaxg_is_valid (double ff)
+uint64_t helper_sqrtg (uint64_t a)
{
- union {
- double f;
- uint64_t i;
- } p;
- uint64_t exp, mant;
-
- p.f = ff;
- exp = (p.i >> 52) & 0x7FF;
- mant = p.i & 0x000FFFFFFFFFFFFFULL;
- if (exp == 0 && ((p.i & 0x8000000000000000ULL) || mant != 0)) {
- /* Reserved operands / Dirty zero */
- return 0;
- }
+ float64 fa, fr;
- return 1;
+ fa = g_to_float64(a);
+ fr = float64_sqrt(fa, &FP_STATUS);
+ return float64_to_g(fr);
}
-static double vaxg_to_ieee64 (double fg)
+
+/* S floating (single) */
+
+/* Taken from linux/arch/alpha/kernel/traps.c, s_mem_to_reg. */
+static inline uint64_t float32_to_s_int(uint32_t fi)
{
- union {
- double f;
- uint64_t i;
- } p;
+ uint32_t frac = fi & 0x7fffff;
+ uint32_t sign = fi >> 31;
+ uint32_t exp_msb = (fi >> 30) & 1;
+ uint32_t exp_low = (fi >> 23) & 0x7f;
uint32_t exp;
- p.f = fg;
- exp = (p.i >> 52) & 0x7FF;
- if (exp < 3) {
- /* Underflow */
- p.f = 0.0;
+ exp = (exp_msb << 10) | exp_low;
+ if (exp_msb) {
+ if (exp_low == 0x7f)
+ exp = 0x7ff;
} else {
- p.f *= 0.25;
+ if (exp_low != 0x00)
+ exp |= 0x380;
}
- return p.f;
+ return (((uint64_t)sign << 63)
+ | ((uint64_t)exp << 52)
+ | ((uint64_t)frac << 29));
}
-static double ieee64_to_vaxg (double fi)
+static inline uint64_t float32_to_s(float32 fa)
{
- union {
- double f;
- uint64_t i;
- } p;
- uint64_t mant;
- uint32_t exp;
+ CPU_FloatU a;
+ a.f = fa;
+ return float32_to_s_int(a.l);
+}
- p.f = fi;
- exp = (p.i >> 52) & 0x7FF;
- mant = p.i & 0x000FFFFFFFFFFFFFULL;
- if (exp == 255) {
- /* NaN or infinity */
- p.i = 1; /* VAX dirty zero */
- } else if (exp == 0) {
- if (mant == 0) {
- /* Zero */
- p.i = 0;
- } else {
- /* Denormalized */
- p.f *= 2.0;
- }
- } else {
- if (exp >= 2045) {
- /* Overflow */
- p.i = 1; /* VAX dirty zero */
- } else {
- p.f *= 4.0;
- }
- }
+static inline uint32_t s_to_float32_int(uint64_t a)
+{
+ return ((a >> 32) & 0xc0000000) | ((a >> 29) & 0x3fffffff);
+}
- return p.f;
+static inline float32 s_to_float32(uint64_t a)
+{
+ CPU_FloatU r;
+ r.l = s_to_float32_int(a);
+ return r.f;
}
-void helper_addg (void)
+uint32_t helper_s_to_memory (uint64_t a)
{
- double ft0, ft1, ft2;
+ return s_to_float32_int(a);
+}
- if (!vaxg_is_valid(FT0) || !vaxg_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxg_to_ieee64(FT0);
- ft1 = vaxg_to_ieee64(FT1);
- ft2 = float64_add(ft0, ft1, &FP_STATUS);
- FT0 = ieee64_to_vaxg(ft2);
+uint64_t helper_memory_to_s (uint32_t a)
+{
+ return float32_to_s_int(a);
}
-void helper_subg (void)
+uint64_t helper_adds (uint64_t a, uint64_t b)
{
- double ft0, ft1, ft2;
+ float32 fa, fb, fr;
- if (!vaxg_is_valid(FT0) || !vaxg_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxg_to_ieee64(FT0);
- ft1 = vaxg_to_ieee64(FT1);
- ft2 = float64_sub(ft0, ft1, &FP_STATUS);
- FT0 = ieee64_to_vaxg(ft2);
+ fa = s_to_float32(a);
+ fb = s_to_float32(b);
+ fr = float32_add(fa, fb, &FP_STATUS);
+ return float32_to_s(fr);
}
-void helper_mulg (void)
+uint64_t helper_subs (uint64_t a, uint64_t b)
{
- double ft0, ft1, ft2;
+ float32 fa, fb, fr;
- if (!vaxg_is_valid(FT0) || !vaxg_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxg_to_ieee64(FT0);
- ft1 = vaxg_to_ieee64(FT1);
- ft2 = float64_mul(ft0, ft1, &FP_STATUS);
- FT0 = ieee64_to_vaxg(ft2);
+ fa = s_to_float32(a);
+ fb = s_to_float32(b);
+ fr = float32_sub(fa, fb, &FP_STATUS);
+ return float32_to_s(fr);
}
-void helper_divg (void)
+uint64_t helper_muls (uint64_t a, uint64_t b)
{
- double ft0, ft1, ft2;
+ float32 fa, fb, fr;
- if (!vaxg_is_valid(FT0) || !vaxg_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxg_to_ieee64(FT0);
- ft1 = vaxg_to_ieee64(FT1);
- ft2 = float64_div(ft0, ft1, &FP_STATUS);
- FT0 = ieee64_to_vaxg(ft2);
+ fa = s_to_float32(a);
+ fb = s_to_float32(b);
+ fr = float32_mul(fa, fb, &FP_STATUS);
+ return float32_to_s(fr);
}
-void helper_sqrtg (void)
+uint64_t helper_divs (uint64_t a, uint64_t b)
{
- double ft0, ft1;
+ float32 fa, fb, fr;
- if (!vaxg_is_valid(FT0) || !vaxg_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxg_to_ieee64(FT0);
- ft1 = float64_sqrt(ft0, &FP_STATUS);
- FT0 = ieee64_to_vaxg(ft1);
+ fa = s_to_float32(a);
+ fb = s_to_float32(b);
+ fr = float32_div(fa, fb, &FP_STATUS);
+ return float32_to_s(fr);
}
-void helper_cmpgeq (void)
+uint64_t helper_sqrts (uint64_t a)
{
- union {
- double d;
- uint64_t u;
- } p;
- double ft0, ft1;
+ float32 fa, fr;
- if (!vaxg_is_valid(FT0) || !vaxg_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxg_to_ieee64(FT0);
- ft1 = vaxg_to_ieee64(FT1);
- p.u = 0;
- if (float64_eq(ft0, ft1, &FP_STATUS))
- p.u = 0x4000000000000000ULL;
- FT0 = p.d;
+ fa = s_to_float32(a);
+ fr = float32_sqrt(fa, &FP_STATUS);
+ return float32_to_s(fr);
}
-void helper_cmpglt (void)
+
+/* T floating (double) */
+static inline float64 t_to_float64(uint64_t a)
{
- union {
- double d;
- uint64_t u;
- } p;
- double ft0, ft1;
+ /* Memory format is the same as float64 */
+ CPU_DoubleU r;
+ r.ll = a;
+ return r.d;
+}
- if (!vaxg_is_valid(FT0) || !vaxg_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxg_to_ieee64(FT0);
- ft1 = vaxg_to_ieee64(FT1);
- p.u = 0;
- if (float64_lt(ft0, ft1, &FP_STATUS))
- p.u = 0x4000000000000000ULL;
- FT0 = p.d;
+static inline uint64_t float64_to_t(float64 fa)
+{
+ /* Memory format is the same as float64 */
+ CPU_DoubleU r;
+ r.d = fa;
+ return r.ll;
}
-void helper_cmpgle (void)
+uint64_t helper_addt (uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t u;
- } p;
- double ft0, ft1;
+ float64 fa, fb, fr;
- if (!vaxg_is_valid(FT0) || !vaxg_is_valid(FT1)) {
- /* XXX: TODO */
- }
- ft0 = vaxg_to_ieee64(FT0);
- ft1 = vaxg_to_ieee64(FT1);
- p.u = 0;
- if (float64_le(ft0, ft1, &FP_STATUS))
- p.u = 0x4000000000000000ULL;
- FT0 = p.d;
+ fa = t_to_float64(a);
+ fb = t_to_float64(b);
+ fr = float64_add(fa, fb, &FP_STATUS);
+ return float64_to_t(fr);
}
-void helper_cvtqs (void)
+uint64_t helper_subt (uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t u;
- } p;
+ float64 fa, fb, fr;
- p.d = FT0;
- FT0 = (float)p.u;
+ fa = t_to_float64(a);
+ fb = t_to_float64(b);
+ fr = float64_sub(fa, fb, &FP_STATUS);
+ return float64_to_t(fr);
}
-void helper_cvttq (void)
+uint64_t helper_mult (uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t u;
- } p;
+ float64 fa, fb, fr;
- p.u = FT0;
- FT0 = p.d;
+ fa = t_to_float64(a);
+ fb = t_to_float64(b);
+ fr = float64_mul(fa, fb, &FP_STATUS);
+ return float64_to_t(fr);
}
-void helper_cvtqt (void)
+uint64_t helper_divt (uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t u;
- } p;
+ float64 fa, fb, fr;
- p.d = FT0;
- FT0 = p.u;
+ fa = t_to_float64(a);
+ fb = t_to_float64(b);
+ fr = float64_div(fa, fb, &FP_STATUS);
+ return float64_to_t(fr);
}
-void helper_cvtqf (void)
+uint64_t helper_sqrtt (uint64_t a)
{
- union {
- double d;
- uint64_t u;
- } p;
+ float64 fa, fr;
- p.d = FT0;
- FT0 = ieee32_to_vaxf(p.u);
+ fa = t_to_float64(a);
+ fr = float64_sqrt(fa, &FP_STATUS);
+ return float64_to_t(fr);
}
-void helper_cvtgf (void)
+/* Comparisons */
+uint64_t helper_cmptun (uint64_t a, uint64_t b)
{
- double ft0;
+ float64 fa, fb;
+
+ fa = t_to_float64(a);
+ fb = t_to_float64(b);
- ft0 = vaxg_to_ieee64(FT0);
- FT0 = ieee32_to_vaxf(ft0);
+ if (float64_unordered_quiet(fa, fb, &FP_STATUS)) {
+ return 0x4000000000000000ULL;
+ } else {
+ return 0;
+ }
}
-void helper_cvtgd (void)
+uint64_t helper_cmpteq(uint64_t a, uint64_t b)
{
- /* XXX: TODO */
+ float64 fa, fb;
+
+ fa = t_to_float64(a);
+ fb = t_to_float64(b);
+
+ if (float64_eq_quiet(fa, fb, &FP_STATUS))
+ return 0x4000000000000000ULL;
+ else
+ return 0;
}
-void helper_cvtgq (void)
+uint64_t helper_cmptle(uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t u;
- } p;
+ float64 fa, fb;
+
+ fa = t_to_float64(a);
+ fb = t_to_float64(b);
- p.u = vaxg_to_ieee64(FT0);
- FT0 = p.d;
+ if (float64_le(fa, fb, &FP_STATUS))
+ return 0x4000000000000000ULL;
+ else
+ return 0;
}
-void helper_cvtqg (void)
+uint64_t helper_cmptlt(uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t u;
- } p;
+ float64 fa, fb;
- p.d = FT0;
- FT0 = ieee64_to_vaxg(p.u);
+ fa = t_to_float64(a);
+ fb = t_to_float64(b);
+
+ if (float64_lt(fa, fb, &FP_STATUS))
+ return 0x4000000000000000ULL;
+ else
+ return 0;
}
-void helper_cvtdg (void)
+uint64_t helper_cmpgeq(uint64_t a, uint64_t b)
{
- /* XXX: TODO */
+ float64 fa, fb;
+
+ fa = g_to_float64(a);
+ fb = g_to_float64(b);
+
+ if (float64_eq_quiet(fa, fb, &FP_STATUS))
+ return 0x4000000000000000ULL;
+ else
+ return 0;
}
-void helper_cvtlq (void)
+uint64_t helper_cmpgle(uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t u;
- } p, q;
+ float64 fa, fb;
+
+ fa = g_to_float64(a);
+ fb = g_to_float64(b);
- p.d = FT0;
- q.u = (p.u >> 29) & 0x3FFFFFFF;
- q.u |= (p.u >> 32);
- q.u = (int64_t)((int32_t)q.u);
- FT0 = q.d;
+ if (float64_le(fa, fb, &FP_STATUS))
+ return 0x4000000000000000ULL;
+ else
+ return 0;
}
-static inline void __helper_cvtql (int s, int v)
+uint64_t helper_cmpglt(uint64_t a, uint64_t b)
{
- union {
- double d;
- uint64_t u;
- } p, q;
+ float64 fa, fb;
- p.d = FT0;
- q.u = ((uint64_t)(p.u & 0xC0000000)) << 32;
- q.u |= ((uint64_t)(p.u & 0x7FFFFFFF)) << 29;
- FT0 = q.d;
- if (v && (int64_t)((int32_t)p.u) != (int64_t)p.u) {
- helper_excp(EXCP_ARITH, EXCP_ARITH_OVERFLOW);
- }
- if (s) {
- /* TODO */
- }
+ fa = g_to_float64(a);
+ fb = g_to_float64(b);
+
+ if (float64_lt(fa, fb, &FP_STATUS))
+ return 0x4000000000000000ULL;
+ else
+ return 0;
}
-void helper_cvtql (void)
+/* Floating point format conversion */
+uint64_t helper_cvtts (uint64_t a)
{
- __helper_cvtql(0, 0);
+ float64 fa;
+ float32 fr;
+
+ fa = t_to_float64(a);
+ fr = float64_to_float32(fa, &FP_STATUS);
+ return float32_to_s(fr);
}
-void helper_cvtqlv (void)
+uint64_t helper_cvtst (uint64_t a)
{
- __helper_cvtql(0, 1);
+ float32 fa;
+ float64 fr;
+
+ fa = s_to_float32(a);
+ fr = float32_to_float64(fa, &FP_STATUS);
+ return float64_to_t(fr);
}
-void helper_cvtqlsv (void)
+uint64_t helper_cvtqs (uint64_t a)
{
- __helper_cvtql(1, 1);
+ float32 fr = int64_to_float32(a, &FP_STATUS);
+ return float32_to_s(fr);
}
-void helper_cmpfeq (void)
+/* Implement float64 to uint64 conversion without saturation -- we must
+ supply the truncated result. This behaviour is used by the compiler
+ to get unsigned conversion for free with the same instruction.
+
+ The VI flag is set when overflow or inexact exceptions should be raised. */
+
+static inline uint64_t helper_cvttq_internal(uint64_t a, int roundmode, int VI)
{
- if (float64_eq(FT0, FT1, &FP_STATUS))
- T0 = 1;
- else
- T0 = 0;
+ uint64_t frac, ret = 0;
+ uint32_t exp, sign, exc = 0;
+ int shift;
+
+ sign = (a >> 63);
+ exp = (uint32_t)(a >> 52) & 0x7ff;
+ frac = a & 0xfffffffffffffull;
+
+ if (exp == 0) {
+ if (unlikely(frac != 0)) {
+ goto do_underflow;
+ }
+ } else if (exp == 0x7ff) {
+ exc = (frac ? float_flag_invalid : VI ? float_flag_overflow : 0);
+ } else {
+ /* Restore implicit bit. */
+ frac |= 0x10000000000000ull;
+
+ shift = exp - 1023 - 52;
+ if (shift >= 0) {
+ /* In this case the number is so large that we must shift
+ the fraction left. There is no rounding to do. */
+ if (shift < 63) {
+ ret = frac << shift;
+ if (VI && (ret >> shift) != frac) {
+ exc = float_flag_overflow;
+ }
+ }
+ } else {
+ uint64_t round;
+
+ /* In this case the number is smaller than the fraction as
+ represented by the 52 bit number. Here we must think
+ about rounding the result. Handle this by shifting the
+ fractional part of the number into the high bits of ROUND.
+ This will let us efficiently handle round-to-nearest. */
+ shift = -shift;
+ if (shift < 63) {
+ ret = frac >> shift;
+ round = frac << (64 - shift);
+ } else {
+ /* The exponent is so small we shift out everything.
+ Leave a sticky bit for proper rounding below. */
+ do_underflow:
+ round = 1;
+ }
+
+ if (round) {
+ exc = (VI ? float_flag_inexact : 0);
+ switch (roundmode) {
+ case float_round_nearest_even:
+ if (round == (1ull << 63)) {
+ /* Fraction is exactly 0.5; round to even. */
+ ret += (ret & 1);
+ } else if (round > (1ull << 63)) {
+ ret += 1;
+ }
+ break;
+ case float_round_to_zero:
+ break;
+ case float_round_up:
+ ret += 1 - sign;
+ break;
+ case float_round_down:
+ ret += sign;
+ break;
+ }
+ }
+ }
+ if (sign) {
+ ret = -ret;
+ }
+ }
+ if (unlikely(exc)) {
+ float_raise(exc, &FP_STATUS);
+ }
+
+ return ret;
}
-void helper_cmpfne (void)
+uint64_t helper_cvttq(uint64_t a)
{
- if (float64_eq(FT0, FT1, &FP_STATUS))
- T0 = 0;
- else
- T0 = 1;
+ return helper_cvttq_internal(a, FP_STATUS.float_rounding_mode, 1);
}
-void helper_cmpflt (void)
+uint64_t helper_cvttq_c(uint64_t a)
{
- if (float64_lt(FT0, FT1, &FP_STATUS))
- T0 = 1;
- else
- T0 = 0;
+ return helper_cvttq_internal(a, float_round_to_zero, 0);
}
-void helper_cmpfle (void)
+uint64_t helper_cvttq_svic(uint64_t a)
{
- if (float64_lt(FT0, FT1, &FP_STATUS))
- T0 = 1;
- else
- T0 = 0;
+ return helper_cvttq_internal(a, float_round_to_zero, 1);
}
-void helper_cmpfgt (void)
+uint64_t helper_cvtqt (uint64_t a)
{
- if (float64_le(FT0, FT1, &FP_STATUS))
- T0 = 0;
- else
- T0 = 1;
+ float64 fr = int64_to_float64(a, &FP_STATUS);
+ return float64_to_t(fr);
}
-void helper_cmpfge (void)
+uint64_t helper_cvtqf (uint64_t a)
{
- if (float64_lt(FT0, FT1, &FP_STATUS))
- T0 = 0;
- else
- T0 = 1;
+ float32 fr = int64_to_float32(a, &FP_STATUS);
+ return float32_to_f(fr);
}
-#if !defined (CONFIG_USER_ONLY)
-void helper_mfpr (int iprn)
+uint64_t helper_cvtgf (uint64_t a)
{
- uint64_t val;
+ float64 fa;
+ float32 fr;
- if (cpu_alpha_mfpr(env, iprn, &val) == 0)
- T0 = val;
+ fa = g_to_float64(a);
+ fr = float64_to_float32(fa, &FP_STATUS);
+ return float32_to_f(fr);
}
-void helper_mtpr (int iprn)
+uint64_t helper_cvtgq (uint64_t a)
{
- cpu_alpha_mtpr(env, iprn, T0, NULL);
+ float64 fa = g_to_float64(a);
+ return float64_to_int64_round_to_zero(fa, &FP_STATUS);
+}
+
+uint64_t helper_cvtqg (uint64_t a)
+{
+ float64 fr;
+ fr = int64_to_float64(a, &FP_STATUS);
+ return float64_to_g(fr);
+}
+
+/* PALcode support special instructions */
+#if !defined (CONFIG_USER_ONLY)
+void helper_hw_ret (uint64_t a)
+{
+ env->pc = a & ~3;
+ env->intr_flag = 0;
+ env->lock_addr = -1;
+ if ((a & 1) == 0) {
+ env->pal_mode = 0;
+ swap_shadow_regs(env);
+ }
+}
+
+void helper_tbia(void)
+{
+ tlb_flush(env, 1);
+}
+
+void helper_tbis(uint64_t p)
+{
+ tlb_flush_page(env, p);
}
#endif
/*****************************************************************************/
/* Softmmu support */
#if !defined (CONFIG_USER_ONLY)
+uint64_t helper_ldl_phys(uint64_t p)
+{
+ return (int32_t)ldl_phys(p);
+}
+
+uint64_t helper_ldq_phys(uint64_t p)
+{
+ return ldq_phys(p);
+}
-#define GETPC() (__builtin_return_address(0))
+uint64_t helper_ldl_l_phys(uint64_t p)
+{
+ env->lock_addr = p;
+ return env->lock_value = (int32_t)ldl_phys(p);
+}
-/* XXX: the two following helpers are pure hacks.
- * Hopefully, we emulate the PALcode, then we should never see
- * HW_LD / HW_ST instructions.
- */
-void helper_ld_phys_to_virt (void)
-{
- uint64_t tlb_addr, physaddr;
- int index, mmu_idx;
- void *retaddr;
-
- mmu_idx = cpu_mmu_index(env);
- index = (T0 >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
- redo:
- tlb_addr = env->tlb_table[mmu_idx][index].addr_read;
- if ((T0 & TARGET_PAGE_MASK) ==
- (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
- physaddr = T0 + env->tlb_table[mmu_idx][index].addend;
- } else {
- /* the page is not in the TLB : fill it */
- retaddr = GETPC();
- tlb_fill(T0, 0, mmu_idx, retaddr);
- goto redo;
+uint64_t helper_ldq_l_phys(uint64_t p)
+{
+ env->lock_addr = p;
+ return env->lock_value = ldl_phys(p);
+}
+
+void helper_stl_phys(uint64_t p, uint64_t v)
+{
+ stl_phys(p, v);
+}
+
+void helper_stq_phys(uint64_t p, uint64_t v)
+{
+ stq_phys(p, v);
+}
+
+uint64_t helper_stl_c_phys(uint64_t p, uint64_t v)
+{
+ uint64_t ret = 0;
+
+ if (p == env->lock_addr) {
+ int32_t old = ldl_phys(p);
+ if (old == (int32_t)env->lock_value) {
+ stl_phys(p, v);
+ ret = 1;
+ }
}
- T0 = physaddr;
+ env->lock_addr = -1;
+
+ return ret;
}
-void helper_st_phys_to_virt (void)
+uint64_t helper_stq_c_phys(uint64_t p, uint64_t v)
{
- uint64_t tlb_addr, physaddr;
- int index, mmu_idx;
- void *retaddr;
+ uint64_t ret = 0;
- mmu_idx = cpu_mmu_index(env);
- index = (T0 >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
- redo:
- tlb_addr = env->tlb_table[mmu_idx][index].addr_write;
- if ((T0 & TARGET_PAGE_MASK) ==
- (tlb_addr & (TARGET_PAGE_MASK | TLB_INVALID_MASK))) {
- physaddr = T0 + env->tlb_table[mmu_idx][index].addend;
- } else {
- /* the page is not in the TLB : fill it */
- retaddr = GETPC();
- tlb_fill(T0, 1, mmu_idx, retaddr);
- goto redo;
+ if (p == env->lock_addr) {
+ uint64_t old = ldq_phys(p);
+ if (old == env->lock_value) {
+ stq_phys(p, v);
+ ret = 1;
+ }
}
- T0 = physaddr;
+ env->lock_addr = -1;
+
+ return ret;
+}
+
+static void QEMU_NORETURN do_unaligned_access(target_ulong addr, int is_write,
+ int is_user, void *retaddr)
+{
+ uint64_t pc;
+ uint32_t insn;
+
+ do_restore_state(retaddr);
+
+ pc = env->pc;
+ insn = ldl_code(pc);
+
+ env->trap_arg0 = addr;
+ env->trap_arg1 = insn >> 26; /* opcode */
+ env->trap_arg2 = (insn >> 21) & 31; /* dest regno */
+ helper_excp(EXCP_UNALIGN, 0);
+}
+
+void QEMU_NORETURN cpu_unassigned_access(CPUState *env1,
+ target_phys_addr_t addr, int is_write,
+ int is_exec, int unused, int size)
+{
+ env = env1;
+ env->trap_arg0 = addr;
+ env->trap_arg1 = is_write;
+ dynamic_excp(EXCP_MCHK, 0);
}
#define MMUSUFFIX _mmu
+#define ALIGNED_ONLY
#define SHIFT 0
#include "softmmu_template.h"
/* XXX: fix it to restore all registers */
void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
{
- TranslationBlock *tb;
CPUState *saved_env;
- target_phys_addr_t pc;
int ret;
/* XXX: hack to restore env in all cases, even if not called from
saved_env = env;
env = cpu_single_env;
ret = cpu_alpha_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
- if (!likely(ret == 0)) {
- if (likely(retaddr)) {
- /* now we have a real cpu fault */
- pc = (target_phys_addr_t)retaddr;
- tb = tb_find_pc(pc);
- if (likely(tb)) {
- /* the PC is inside the translated code. It means that we have
- a virtual CPU fault */
- cpu_restore_state(tb, env, pc, NULL);
- }
- }
+ if (unlikely(ret != 0)) {
+ do_restore_state(retaddr);
/* Exception index and error code are already set */
- cpu_loop_exit();
+ cpu_loop_exit(env);
}
env = saved_env;
}
-
#endif