2 * Alpha emulation cpu translation for qemu.
4 * Copyright (c) 2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "host-utils.h"
29 #undef ALPHA_DEBUG_DISAS
30 #define CONFIG_SOFTFLOAT_INLINE
32 #ifdef ALPHA_DEBUG_DISAS
33 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
35 # define LOG_DISAS(...) do { } while (0)
38 typedef struct DisasContext DisasContext;
40 struct TranslationBlock *tb;
45 /* Current rounding mode for this TB. */
47 /* Current flush-to-zero setting for this TB. */
51 /* Return values from translate_one, indicating the state of the TB.
52 Note that zero indicates that we are not exiting the TB. */
57 /* We have emitted one or more goto_tb. No fixup required. */
60 /* We are not using a goto_tb (for whatever reason), but have updated
61 the PC (for whatever reason), so there's no need to do it again on
65 /* We are exiting the TB, but have neither emitted a goto_tb, nor
66 updated the PC for the next instruction to be executed. */
69 /* We are ending the TB with a noreturn function call, e.g. longjmp.
70 No following code will be executed. */
74 /* global register indexes */
75 static TCGv_ptr cpu_env;
76 static TCGv cpu_ir[31];
77 static TCGv cpu_fir[31];
79 static TCGv cpu_lock_addr;
80 static TCGv cpu_lock_st_addr;
81 static TCGv cpu_lock_value;
82 static TCGv cpu_unique;
83 #ifndef CONFIG_USER_ONLY
84 static TCGv cpu_sysval;
89 static char cpu_reg_names[10*4+21*5 + 10*5+21*6];
91 #include "gen-icount.h"
93 static void alpha_translate_init(void)
97 static int done_init = 0;
102 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
105 for (i = 0; i < 31; i++) {
106 sprintf(p, "ir%d", i);
107 cpu_ir[i] = tcg_global_mem_new_i64(TCG_AREG0,
108 offsetof(CPUAlphaState, ir[i]), p);
109 p += (i < 10) ? 4 : 5;
111 sprintf(p, "fir%d", i);
112 cpu_fir[i] = tcg_global_mem_new_i64(TCG_AREG0,
113 offsetof(CPUAlphaState, fir[i]), p);
114 p += (i < 10) ? 5 : 6;
117 cpu_pc = tcg_global_mem_new_i64(TCG_AREG0,
118 offsetof(CPUAlphaState, pc), "pc");
120 cpu_lock_addr = tcg_global_mem_new_i64(TCG_AREG0,
121 offsetof(CPUAlphaState, lock_addr),
123 cpu_lock_st_addr = tcg_global_mem_new_i64(TCG_AREG0,
124 offsetof(CPUAlphaState, lock_st_addr),
126 cpu_lock_value = tcg_global_mem_new_i64(TCG_AREG0,
127 offsetof(CPUAlphaState, lock_value),
130 cpu_unique = tcg_global_mem_new_i64(TCG_AREG0,
131 offsetof(CPUAlphaState, unique), "unique");
132 #ifndef CONFIG_USER_ONLY
133 cpu_sysval = tcg_global_mem_new_i64(TCG_AREG0,
134 offsetof(CPUAlphaState, sysval), "sysval");
135 cpu_usp = tcg_global_mem_new_i64(TCG_AREG0,
136 offsetof(CPUAlphaState, usp), "usp");
139 /* register helpers */
146 static void gen_excp_1(int exception, int error_code)
150 tmp1 = tcg_const_i32(exception);
151 tmp2 = tcg_const_i32(error_code);
152 gen_helper_excp(cpu_env, tmp1, tmp2);
153 tcg_temp_free_i32(tmp2);
154 tcg_temp_free_i32(tmp1);
157 static ExitStatus gen_excp(DisasContext *ctx, int exception, int error_code)
159 tcg_gen_movi_i64(cpu_pc, ctx->pc);
160 gen_excp_1(exception, error_code);
161 return EXIT_NORETURN;
164 static inline ExitStatus gen_invalid(DisasContext *ctx)
166 return gen_excp(ctx, EXCP_OPCDEC, 0);
169 static inline void gen_qemu_ldf(TCGv t0, TCGv t1, int flags)
171 TCGv tmp = tcg_temp_new();
172 TCGv_i32 tmp32 = tcg_temp_new_i32();
173 tcg_gen_qemu_ld32u(tmp, t1, flags);
174 tcg_gen_trunc_i64_i32(tmp32, tmp);
175 gen_helper_memory_to_f(t0, tmp32);
176 tcg_temp_free_i32(tmp32);
180 static inline void gen_qemu_ldg(TCGv t0, TCGv t1, int flags)
182 TCGv tmp = tcg_temp_new();
183 tcg_gen_qemu_ld64(tmp, t1, flags);
184 gen_helper_memory_to_g(t0, tmp);
188 static inline void gen_qemu_lds(TCGv t0, TCGv t1, int flags)
190 TCGv tmp = tcg_temp_new();
191 TCGv_i32 tmp32 = tcg_temp_new_i32();
192 tcg_gen_qemu_ld32u(tmp, t1, flags);
193 tcg_gen_trunc_i64_i32(tmp32, tmp);
194 gen_helper_memory_to_s(t0, tmp32);
195 tcg_temp_free_i32(tmp32);
199 static inline void gen_qemu_ldl_l(TCGv t0, TCGv t1, int flags)
201 tcg_gen_qemu_ld32s(t0, t1, flags);
202 tcg_gen_mov_i64(cpu_lock_addr, t1);
203 tcg_gen_mov_i64(cpu_lock_value, t0);
206 static inline void gen_qemu_ldq_l(TCGv t0, TCGv t1, int flags)
208 tcg_gen_qemu_ld64(t0, t1, flags);
209 tcg_gen_mov_i64(cpu_lock_addr, t1);
210 tcg_gen_mov_i64(cpu_lock_value, t0);
213 static inline void gen_load_mem(DisasContext *ctx,
214 void (*tcg_gen_qemu_load)(TCGv t0, TCGv t1,
216 int ra, int rb, int32_t disp16, int fp,
221 /* LDQ_U with ra $31 is UNOP. Other various loads are forms of
222 prefetches, which we can treat as nops. No worries about
223 missed exceptions here. */
224 if (unlikely(ra == 31)) {
228 addr = tcg_temp_new();
230 tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
232 tcg_gen_andi_i64(addr, addr, ~0x7);
238 tcg_gen_movi_i64(addr, disp16);
241 va = (fp ? cpu_fir[ra] : cpu_ir[ra]);
242 tcg_gen_qemu_load(va, addr, ctx->mem_idx);
247 static inline void gen_qemu_stf(TCGv t0, TCGv t1, int flags)
249 TCGv_i32 tmp32 = tcg_temp_new_i32();
250 TCGv tmp = tcg_temp_new();
251 gen_helper_f_to_memory(tmp32, t0);
252 tcg_gen_extu_i32_i64(tmp, tmp32);
253 tcg_gen_qemu_st32(tmp, t1, flags);
255 tcg_temp_free_i32(tmp32);
258 static inline void gen_qemu_stg(TCGv t0, TCGv t1, int flags)
260 TCGv tmp = tcg_temp_new();
261 gen_helper_g_to_memory(tmp, t0);
262 tcg_gen_qemu_st64(tmp, t1, flags);
266 static inline void gen_qemu_sts(TCGv t0, TCGv t1, int flags)
268 TCGv_i32 tmp32 = tcg_temp_new_i32();
269 TCGv tmp = tcg_temp_new();
270 gen_helper_s_to_memory(tmp32, t0);
271 tcg_gen_extu_i32_i64(tmp, tmp32);
272 tcg_gen_qemu_st32(tmp, t1, flags);
274 tcg_temp_free_i32(tmp32);
277 static inline void gen_store_mem(DisasContext *ctx,
278 void (*tcg_gen_qemu_store)(TCGv t0, TCGv t1,
280 int ra, int rb, int32_t disp16, int fp,
285 addr = tcg_temp_new();
287 tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
289 tcg_gen_andi_i64(addr, addr, ~0x7);
295 tcg_gen_movi_i64(addr, disp16);
299 va = tcg_const_i64(0);
301 va = (fp ? cpu_fir[ra] : cpu_ir[ra]);
303 tcg_gen_qemu_store(va, addr, ctx->mem_idx);
311 static ExitStatus gen_store_conditional(DisasContext *ctx, int ra, int rb,
312 int32_t disp16, int quad)
317 /* ??? Don't bother storing anything. The user can't tell
318 the difference, since the zero register always reads zero. */
322 #if defined(CONFIG_USER_ONLY)
323 addr = cpu_lock_st_addr;
325 addr = tcg_temp_local_new();
329 tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
331 tcg_gen_movi_i64(addr, disp16);
334 #if defined(CONFIG_USER_ONLY)
335 /* ??? This is handled via a complicated version of compare-and-swap
336 in the cpu_loop. Hopefully one day we'll have a real CAS opcode
337 in TCG so that this isn't necessary. */
338 return gen_excp(ctx, quad ? EXCP_STQ_C : EXCP_STL_C, ra);
340 /* ??? In system mode we are never multi-threaded, so CAS can be
341 implemented via a non-atomic load-compare-store sequence. */
343 int lab_fail, lab_done;
346 lab_fail = gen_new_label();
347 lab_done = gen_new_label();
348 tcg_gen_brcond_i64(TCG_COND_NE, addr, cpu_lock_addr, lab_fail);
350 val = tcg_temp_new();
352 tcg_gen_qemu_ld64(val, addr, ctx->mem_idx);
354 tcg_gen_qemu_ld32s(val, addr, ctx->mem_idx);
356 tcg_gen_brcond_i64(TCG_COND_NE, val, cpu_lock_value, lab_fail);
359 tcg_gen_qemu_st64(cpu_ir[ra], addr, ctx->mem_idx);
361 tcg_gen_qemu_st32(cpu_ir[ra], addr, ctx->mem_idx);
363 tcg_gen_movi_i64(cpu_ir[ra], 1);
364 tcg_gen_br(lab_done);
366 gen_set_label(lab_fail);
367 tcg_gen_movi_i64(cpu_ir[ra], 0);
369 gen_set_label(lab_done);
370 tcg_gen_movi_i64(cpu_lock_addr, -1);
378 static int use_goto_tb(DisasContext *ctx, uint64_t dest)
380 /* Check for the dest on the same page as the start of the TB. We
381 also want to suppress goto_tb in the case of single-steping and IO. */
382 return (((ctx->tb->pc ^ dest) & TARGET_PAGE_MASK) == 0
383 && !ctx->env->singlestep_enabled
384 && !(ctx->tb->cflags & CF_LAST_IO));
387 static ExitStatus gen_bdirect(DisasContext *ctx, int ra, int32_t disp)
389 uint64_t dest = ctx->pc + (disp << 2);
392 tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
395 /* Notice branch-to-next; used to initialize RA with the PC. */
398 } else if (use_goto_tb(ctx, dest)) {
400 tcg_gen_movi_i64(cpu_pc, dest);
401 tcg_gen_exit_tb((tcg_target_long)ctx->tb);
404 tcg_gen_movi_i64(cpu_pc, dest);
405 return EXIT_PC_UPDATED;
409 static ExitStatus gen_bcond_internal(DisasContext *ctx, TCGCond cond,
410 TCGv cmp, int32_t disp)
412 uint64_t dest = ctx->pc + (disp << 2);
413 int lab_true = gen_new_label();
415 if (use_goto_tb(ctx, dest)) {
416 tcg_gen_brcondi_i64(cond, cmp, 0, lab_true);
419 tcg_gen_movi_i64(cpu_pc, ctx->pc);
420 tcg_gen_exit_tb((tcg_target_long)ctx->tb);
422 gen_set_label(lab_true);
424 tcg_gen_movi_i64(cpu_pc, dest);
425 tcg_gen_exit_tb((tcg_target_long)ctx->tb + 1);
429 int lab_over = gen_new_label();
431 /* ??? Consider using either
434 movcond pc, cond, 0, tmp, pc
441 The current diamond subgraph surely isn't efficient. */
443 tcg_gen_brcondi_i64(cond, cmp, 0, lab_true);
444 tcg_gen_movi_i64(cpu_pc, ctx->pc);
445 tcg_gen_br(lab_over);
446 gen_set_label(lab_true);
447 tcg_gen_movi_i64(cpu_pc, dest);
448 gen_set_label(lab_over);
450 return EXIT_PC_UPDATED;
454 static ExitStatus gen_bcond(DisasContext *ctx, TCGCond cond, int ra,
455 int32_t disp, int mask)
459 if (unlikely(ra == 31)) {
460 cmp_tmp = tcg_const_i64(0);
462 cmp_tmp = tcg_temp_new();
464 tcg_gen_andi_i64(cmp_tmp, cpu_ir[ra], 1);
466 tcg_gen_mov_i64(cmp_tmp, cpu_ir[ra]);
470 return gen_bcond_internal(ctx, cond, cmp_tmp, disp);
473 /* Fold -0.0 for comparison with COND. */
475 static void gen_fold_mzero(TCGCond cond, TCGv dest, TCGv src)
477 uint64_t mzero = 1ull << 63;
482 /* For <= or >, the -0.0 value directly compares the way we want. */
483 tcg_gen_mov_i64(dest, src);
488 /* For == or !=, we can simply mask off the sign bit and compare. */
489 tcg_gen_andi_i64(dest, src, mzero - 1);
494 /* For >= or <, map -0.0 to +0.0 via comparison and mask. */
495 tcg_gen_setcondi_i64(TCG_COND_NE, dest, src, mzero);
496 tcg_gen_neg_i64(dest, dest);
497 tcg_gen_and_i64(dest, dest, src);
505 static ExitStatus gen_fbcond(DisasContext *ctx, TCGCond cond, int ra,
510 if (unlikely(ra == 31)) {
511 /* Very uncommon case, but easier to optimize it to an integer
512 comparison than continuing with the floating point comparison. */
513 return gen_bcond(ctx, cond, ra, disp, 0);
516 cmp_tmp = tcg_temp_new();
517 gen_fold_mzero(cond, cmp_tmp, cpu_fir[ra]);
518 return gen_bcond_internal(ctx, cond, cmp_tmp, disp);
521 static void gen_cmov(TCGCond cond, int ra, int rb, int rc,
522 int islit, uint8_t lit, int mask)
524 TCGCond inv_cond = tcg_invert_cond(cond);
527 if (unlikely(rc == 31))
530 l1 = gen_new_label();
534 TCGv tmp = tcg_temp_new();
535 tcg_gen_andi_i64(tmp, cpu_ir[ra], 1);
536 tcg_gen_brcondi_i64(inv_cond, tmp, 0, l1);
539 tcg_gen_brcondi_i64(inv_cond, cpu_ir[ra], 0, l1);
541 /* Very uncommon case - Do not bother to optimize. */
542 TCGv tmp = tcg_const_i64(0);
543 tcg_gen_brcondi_i64(inv_cond, tmp, 0, l1);
548 tcg_gen_movi_i64(cpu_ir[rc], lit);
550 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
554 static void gen_fcmov(TCGCond cond, int ra, int rb, int rc)
559 if (unlikely(rc == 31)) {
563 cmp_tmp = tcg_temp_new();
564 if (unlikely(ra == 31)) {
565 tcg_gen_movi_i64(cmp_tmp, 0);
567 gen_fold_mzero(cond, cmp_tmp, cpu_fir[ra]);
570 l1 = gen_new_label();
571 tcg_gen_brcondi_i64(tcg_invert_cond(cond), cmp_tmp, 0, l1);
572 tcg_temp_free(cmp_tmp);
575 tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[rb]);
577 tcg_gen_movi_i64(cpu_fir[rc], 0);
581 #define QUAL_RM_N 0x080 /* Round mode nearest even */
582 #define QUAL_RM_C 0x000 /* Round mode chopped */
583 #define QUAL_RM_M 0x040 /* Round mode minus infinity */
584 #define QUAL_RM_D 0x0c0 /* Round mode dynamic */
585 #define QUAL_RM_MASK 0x0c0
587 #define QUAL_U 0x100 /* Underflow enable (fp output) */
588 #define QUAL_V 0x100 /* Overflow enable (int output) */
589 #define QUAL_S 0x400 /* Software completion enable */
590 #define QUAL_I 0x200 /* Inexact detection enable */
592 static void gen_qual_roundmode(DisasContext *ctx, int fn11)
596 fn11 &= QUAL_RM_MASK;
597 if (fn11 == ctx->tb_rm) {
602 tmp = tcg_temp_new_i32();
605 tcg_gen_movi_i32(tmp, float_round_nearest_even);
608 tcg_gen_movi_i32(tmp, float_round_to_zero);
611 tcg_gen_movi_i32(tmp, float_round_down);
614 tcg_gen_ld8u_i32(tmp, cpu_env,
615 offsetof(CPUAlphaState, fpcr_dyn_round));
619 #if defined(CONFIG_SOFTFLOAT_INLINE)
620 /* ??? The "softfloat.h" interface is to call set_float_rounding_mode.
621 With CONFIG_SOFTFLOAT that expands to an out-of-line call that just
622 sets the one field. */
623 tcg_gen_st8_i32(tmp, cpu_env,
624 offsetof(CPUAlphaState, fp_status.float_rounding_mode));
626 gen_helper_setroundmode(tmp);
629 tcg_temp_free_i32(tmp);
632 static void gen_qual_flushzero(DisasContext *ctx, int fn11)
637 if (fn11 == ctx->tb_ftz) {
642 tmp = tcg_temp_new_i32();
644 /* Underflow is enabled, use the FPCR setting. */
645 tcg_gen_ld8u_i32(tmp, cpu_env,
646 offsetof(CPUAlphaState, fpcr_flush_to_zero));
648 /* Underflow is disabled, force flush-to-zero. */
649 tcg_gen_movi_i32(tmp, 1);
652 #if defined(CONFIG_SOFTFLOAT_INLINE)
653 tcg_gen_st8_i32(tmp, cpu_env,
654 offsetof(CPUAlphaState, fp_status.flush_to_zero));
656 gen_helper_setflushzero(tmp);
659 tcg_temp_free_i32(tmp);
662 static TCGv gen_ieee_input(int reg, int fn11, int is_cmp)
664 TCGv val = tcg_temp_new();
666 tcg_gen_movi_i64(val, 0);
667 } else if (fn11 & QUAL_S) {
668 gen_helper_ieee_input_s(val, cpu_env, cpu_fir[reg]);
670 gen_helper_ieee_input_cmp(val, cpu_env, cpu_fir[reg]);
672 gen_helper_ieee_input(val, cpu_env, cpu_fir[reg]);
677 static void gen_fp_exc_clear(void)
679 #if defined(CONFIG_SOFTFLOAT_INLINE)
680 TCGv_i32 zero = tcg_const_i32(0);
681 tcg_gen_st8_i32(zero, cpu_env,
682 offsetof(CPUAlphaState, fp_status.float_exception_flags));
683 tcg_temp_free_i32(zero);
685 gen_helper_fp_exc_clear(cpu_env);
689 static void gen_fp_exc_raise_ignore(int rc, int fn11, int ignore)
691 /* ??? We ought to be able to do something with imprecise exceptions.
692 E.g. notice we're still in the trap shadow of something within the
693 TB and do not generate the code to signal the exception; end the TB
694 when an exception is forced to arrive, either by consumption of a
695 register value or TRAPB or EXCB. */
696 TCGv_i32 exc = tcg_temp_new_i32();
699 #if defined(CONFIG_SOFTFLOAT_INLINE)
700 tcg_gen_ld8u_i32(exc, cpu_env,
701 offsetof(CPUAlphaState, fp_status.float_exception_flags));
703 gen_helper_fp_exc_get(exc, cpu_env);
707 tcg_gen_andi_i32(exc, exc, ~ignore);
710 /* ??? Pass in the regno of the destination so that the helper can
711 set EXC_MASK, which contains a bitmask of destination registers
712 that have caused arithmetic traps. A simple userspace emulation
713 does not require this. We do need it for a guest kernel's entArith,
714 or if we were to do something clever with imprecise exceptions. */
715 reg = tcg_const_i32(rc + 32);
718 gen_helper_fp_exc_raise_s(cpu_env, exc, reg);
720 gen_helper_fp_exc_raise(cpu_env, exc, reg);
723 tcg_temp_free_i32(reg);
724 tcg_temp_free_i32(exc);
727 static inline void gen_fp_exc_raise(int rc, int fn11)
729 gen_fp_exc_raise_ignore(rc, fn11, fn11 & QUAL_I ? 0 : float_flag_inexact);
732 static void gen_fcvtlq(int rb, int rc)
734 if (unlikely(rc == 31)) {
737 if (unlikely(rb == 31)) {
738 tcg_gen_movi_i64(cpu_fir[rc], 0);
740 TCGv tmp = tcg_temp_new();
742 /* The arithmetic right shift here, plus the sign-extended mask below
743 yields a sign-extended result without an explicit ext32s_i64. */
744 tcg_gen_sari_i64(tmp, cpu_fir[rb], 32);
745 tcg_gen_shri_i64(cpu_fir[rc], cpu_fir[rb], 29);
746 tcg_gen_andi_i64(tmp, tmp, (int32_t)0xc0000000);
747 tcg_gen_andi_i64(cpu_fir[rc], cpu_fir[rc], 0x3fffffff);
748 tcg_gen_or_i64(cpu_fir[rc], cpu_fir[rc], tmp);
754 static void gen_fcvtql(int rb, int rc)
756 if (unlikely(rc == 31)) {
759 if (unlikely(rb == 31)) {
760 tcg_gen_movi_i64(cpu_fir[rc], 0);
762 TCGv tmp = tcg_temp_new();
764 tcg_gen_andi_i64(tmp, cpu_fir[rb], 0xC0000000);
765 tcg_gen_andi_i64(cpu_fir[rc], cpu_fir[rb], 0x3FFFFFFF);
766 tcg_gen_shli_i64(tmp, tmp, 32);
767 tcg_gen_shli_i64(cpu_fir[rc], cpu_fir[rc], 29);
768 tcg_gen_or_i64(cpu_fir[rc], cpu_fir[rc], tmp);
774 static void gen_fcvtql_v(DisasContext *ctx, int rb, int rc)
777 int lab = gen_new_label();
778 TCGv tmp = tcg_temp_new();
780 tcg_gen_ext32s_i64(tmp, cpu_fir[rb]);
781 tcg_gen_brcond_i64(TCG_COND_EQ, tmp, cpu_fir[rb], lab);
782 gen_excp(ctx, EXCP_ARITH, EXC_M_IOV);
789 #define FARITH2(name) \
790 static inline void glue(gen_f, name)(int rb, int rc) \
792 if (unlikely(rc == 31)) { \
796 gen_helper_ ## name(cpu_fir[rc], cpu_env, cpu_fir[rb]); \
798 TCGv tmp = tcg_const_i64(0); \
799 gen_helper_ ## name(cpu_fir[rc], cpu_env, tmp); \
800 tcg_temp_free(tmp); \
804 /* ??? VAX instruction qualifiers ignored. */
812 static void gen_ieee_arith2(DisasContext *ctx,
813 void (*helper)(TCGv, TCGv_ptr, TCGv),
814 int rb, int rc, int fn11)
818 /* ??? This is wrong: the instruction is not a nop, it still may
820 if (unlikely(rc == 31)) {
824 gen_qual_roundmode(ctx, fn11);
825 gen_qual_flushzero(ctx, fn11);
828 vb = gen_ieee_input(rb, fn11, 0);
829 helper(cpu_fir[rc], cpu_env, vb);
832 gen_fp_exc_raise(rc, fn11);
835 #define IEEE_ARITH2(name) \
836 static inline void glue(gen_f, name)(DisasContext *ctx, \
837 int rb, int rc, int fn11) \
839 gen_ieee_arith2(ctx, gen_helper_##name, rb, rc, fn11); \
846 static void gen_fcvttq(DisasContext *ctx, int rb, int rc, int fn11)
851 /* ??? This is wrong: the instruction is not a nop, it still may
853 if (unlikely(rc == 31)) {
857 /* No need to set flushzero, since we have an integer output. */
859 vb = gen_ieee_input(rb, fn11, 0);
861 /* Almost all integer conversions use cropped rounding, and most
862 also do not have integer overflow enabled. Special case that. */
865 gen_helper_cvttq_c(cpu_fir[rc], cpu_env, vb);
867 case QUAL_V | QUAL_RM_C:
868 case QUAL_S | QUAL_V | QUAL_RM_C:
869 ignore = float_flag_inexact;
871 case QUAL_S | QUAL_V | QUAL_I | QUAL_RM_C:
872 gen_helper_cvttq_svic(cpu_fir[rc], cpu_env, vb);
875 gen_qual_roundmode(ctx, fn11);
876 gen_helper_cvttq(cpu_fir[rc], cpu_env, vb);
877 ignore |= (fn11 & QUAL_V ? 0 : float_flag_overflow);
878 ignore |= (fn11 & QUAL_I ? 0 : float_flag_inexact);
883 gen_fp_exc_raise_ignore(rc, fn11, ignore);
886 static void gen_ieee_intcvt(DisasContext *ctx,
887 void (*helper)(TCGv, TCGv_ptr, TCGv),
888 int rb, int rc, int fn11)
892 /* ??? This is wrong: the instruction is not a nop, it still may
894 if (unlikely(rc == 31)) {
898 gen_qual_roundmode(ctx, fn11);
901 vb = tcg_const_i64(0);
906 /* The only exception that can be raised by integer conversion
907 is inexact. Thus we only need to worry about exceptions when
908 inexact handling is requested. */
911 helper(cpu_fir[rc], cpu_env, vb);
912 gen_fp_exc_raise(rc, fn11);
914 helper(cpu_fir[rc], cpu_env, vb);
922 #define IEEE_INTCVT(name) \
923 static inline void glue(gen_f, name)(DisasContext *ctx, \
924 int rb, int rc, int fn11) \
926 gen_ieee_intcvt(ctx, gen_helper_##name, rb, rc, fn11); \
931 static void gen_cpys_internal(int ra, int rb, int rc, int inv_a, uint64_t mask)
936 if (unlikely(rc == 31)) {
940 vmask = tcg_const_i64(mask);
950 va = tcg_temp_new_i64();
951 tcg_gen_mov_i64(va, cpu_fir[ra]);
953 tcg_gen_andc_i64(va, vmask, va);
955 tcg_gen_and_i64(va, va, vmask);
963 vb = tcg_temp_new_i64();
964 tcg_gen_andc_i64(vb, cpu_fir[rb], vmask);
967 switch (za << 1 | zb) {
969 tcg_gen_or_i64(cpu_fir[rc], va, vb);
972 tcg_gen_mov_i64(cpu_fir[rc], va);
975 tcg_gen_mov_i64(cpu_fir[rc], vb);
978 tcg_gen_movi_i64(cpu_fir[rc], 0);
982 tcg_temp_free(vmask);
991 static inline void gen_fcpys(int ra, int rb, int rc)
993 gen_cpys_internal(ra, rb, rc, 0, 0x8000000000000000ULL);
996 static inline void gen_fcpysn(int ra, int rb, int rc)
998 gen_cpys_internal(ra, rb, rc, 1, 0x8000000000000000ULL);
1001 static inline void gen_fcpyse(int ra, int rb, int rc)
1003 gen_cpys_internal(ra, rb, rc, 0, 0xFFF0000000000000ULL);
1006 #define FARITH3(name) \
1007 static inline void glue(gen_f, name)(int ra, int rb, int rc) \
1011 if (unlikely(rc == 31)) { \
1015 va = tcg_const_i64(0); \
1020 vb = tcg_const_i64(0); \
1025 gen_helper_ ## name(cpu_fir[rc], cpu_env, va, vb); \
1028 tcg_temp_free(va); \
1031 tcg_temp_free(vb); \
1035 /* ??? VAX instruction qualifiers ignored. */
1048 static void gen_ieee_arith3(DisasContext *ctx,
1049 void (*helper)(TCGv, TCGv_ptr, TCGv, TCGv),
1050 int ra, int rb, int rc, int fn11)
1054 /* ??? This is wrong: the instruction is not a nop, it still may
1055 raise exceptions. */
1056 if (unlikely(rc == 31)) {
1060 gen_qual_roundmode(ctx, fn11);
1061 gen_qual_flushzero(ctx, fn11);
1064 va = gen_ieee_input(ra, fn11, 0);
1065 vb = gen_ieee_input(rb, fn11, 0);
1066 helper(cpu_fir[rc], cpu_env, va, vb);
1070 gen_fp_exc_raise(rc, fn11);
1073 #define IEEE_ARITH3(name) \
1074 static inline void glue(gen_f, name)(DisasContext *ctx, \
1075 int ra, int rb, int rc, int fn11) \
1077 gen_ieee_arith3(ctx, gen_helper_##name, ra, rb, rc, fn11); \
1088 static void gen_ieee_compare(DisasContext *ctx,
1089 void (*helper)(TCGv, TCGv_ptr, TCGv, TCGv),
1090 int ra, int rb, int rc, int fn11)
1094 /* ??? This is wrong: the instruction is not a nop, it still may
1095 raise exceptions. */
1096 if (unlikely(rc == 31)) {
1102 va = gen_ieee_input(ra, fn11, 1);
1103 vb = gen_ieee_input(rb, fn11, 1);
1104 helper(cpu_fir[rc], cpu_env, va, vb);
1108 gen_fp_exc_raise(rc, fn11);
1111 #define IEEE_CMP3(name) \
1112 static inline void glue(gen_f, name)(DisasContext *ctx, \
1113 int ra, int rb, int rc, int fn11) \
1115 gen_ieee_compare(ctx, gen_helper_##name, ra, rb, rc, fn11); \
1122 static inline uint64_t zapnot_mask(uint8_t lit)
1127 for (i = 0; i < 8; ++i) {
1129 mask |= 0xffull << (i * 8);
1134 /* Implement zapnot with an immediate operand, which expands to some
1135 form of immediate AND. This is a basic building block in the
1136 definition of many of the other byte manipulation instructions. */
1137 static void gen_zapnoti(TCGv dest, TCGv src, uint8_t lit)
1141 tcg_gen_movi_i64(dest, 0);
1144 tcg_gen_ext8u_i64(dest, src);
1147 tcg_gen_ext16u_i64(dest, src);
1150 tcg_gen_ext32u_i64(dest, src);
1153 tcg_gen_mov_i64(dest, src);
1156 tcg_gen_andi_i64 (dest, src, zapnot_mask (lit));
1161 static inline void gen_zapnot(int ra, int rb, int rc, int islit, uint8_t lit)
1163 if (unlikely(rc == 31))
1165 else if (unlikely(ra == 31))
1166 tcg_gen_movi_i64(cpu_ir[rc], 0);
1168 gen_zapnoti(cpu_ir[rc], cpu_ir[ra], lit);
1170 gen_helper_zapnot (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1173 static inline void gen_zap(int ra, int rb, int rc, int islit, uint8_t lit)
1175 if (unlikely(rc == 31))
1177 else if (unlikely(ra == 31))
1178 tcg_gen_movi_i64(cpu_ir[rc], 0);
1180 gen_zapnoti(cpu_ir[rc], cpu_ir[ra], ~lit);
1182 gen_helper_zap (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1186 /* EXTWH, EXTLH, EXTQH */
1187 static void gen_ext_h(int ra, int rb, int rc, int islit,
1188 uint8_t lit, uint8_t byte_mask)
1190 if (unlikely(rc == 31))
1192 else if (unlikely(ra == 31))
1193 tcg_gen_movi_i64(cpu_ir[rc], 0);
1196 lit = (64 - (lit & 7) * 8) & 0x3f;
1197 tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit);
1199 TCGv tmp1 = tcg_temp_new();
1200 tcg_gen_andi_i64(tmp1, cpu_ir[rb], 7);
1201 tcg_gen_shli_i64(tmp1, tmp1, 3);
1202 tcg_gen_neg_i64(tmp1, tmp1);
1203 tcg_gen_andi_i64(tmp1, tmp1, 0x3f);
1204 tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], tmp1);
1205 tcg_temp_free(tmp1);
1207 gen_zapnoti(cpu_ir[rc], cpu_ir[rc], byte_mask);
1211 /* EXTBL, EXTWL, EXTLL, EXTQL */
1212 static void gen_ext_l(int ra, int rb, int rc, int islit,
1213 uint8_t lit, uint8_t byte_mask)
1215 if (unlikely(rc == 31))
1217 else if (unlikely(ra == 31))
1218 tcg_gen_movi_i64(cpu_ir[rc], 0);
1221 tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], (lit & 7) * 8);
1223 TCGv tmp = tcg_temp_new();
1224 tcg_gen_andi_i64(tmp, cpu_ir[rb], 7);
1225 tcg_gen_shli_i64(tmp, tmp, 3);
1226 tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], tmp);
1229 gen_zapnoti(cpu_ir[rc], cpu_ir[rc], byte_mask);
1233 /* INSWH, INSLH, INSQH */
1234 static void gen_ins_h(int ra, int rb, int rc, int islit,
1235 uint8_t lit, uint8_t byte_mask)
1237 if (unlikely(rc == 31))
1239 else if (unlikely(ra == 31) || (islit && (lit & 7) == 0))
1240 tcg_gen_movi_i64(cpu_ir[rc], 0);
1242 TCGv tmp = tcg_temp_new();
1244 /* The instruction description has us left-shift the byte mask
1245 and extract bits <15:8> and apply that zap at the end. This
1246 is equivalent to simply performing the zap first and shifting
1248 gen_zapnoti (tmp, cpu_ir[ra], byte_mask);
1251 /* Note that we have handled the lit==0 case above. */
1252 tcg_gen_shri_i64 (cpu_ir[rc], tmp, 64 - (lit & 7) * 8);
1254 TCGv shift = tcg_temp_new();
1256 /* If (B & 7) == 0, we need to shift by 64 and leave a zero.
1257 Do this portably by splitting the shift into two parts:
1258 shift_count-1 and 1. Arrange for the -1 by using
1259 ones-complement instead of twos-complement in the negation:
1260 ~((B & 7) * 8) & 63. */
1262 tcg_gen_andi_i64(shift, cpu_ir[rb], 7);
1263 tcg_gen_shli_i64(shift, shift, 3);
1264 tcg_gen_not_i64(shift, shift);
1265 tcg_gen_andi_i64(shift, shift, 0x3f);
1267 tcg_gen_shr_i64(cpu_ir[rc], tmp, shift);
1268 tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[rc], 1);
1269 tcg_temp_free(shift);
1275 /* INSBL, INSWL, INSLL, INSQL */
1276 static void gen_ins_l(int ra, int rb, int rc, int islit,
1277 uint8_t lit, uint8_t byte_mask)
1279 if (unlikely(rc == 31))
1281 else if (unlikely(ra == 31))
1282 tcg_gen_movi_i64(cpu_ir[rc], 0);
1284 TCGv tmp = tcg_temp_new();
1286 /* The instruction description has us left-shift the byte mask
1287 the same number of byte slots as the data and apply the zap
1288 at the end. This is equivalent to simply performing the zap
1289 first and shifting afterward. */
1290 gen_zapnoti (tmp, cpu_ir[ra], byte_mask);
1293 tcg_gen_shli_i64(cpu_ir[rc], tmp, (lit & 7) * 8);
1295 TCGv shift = tcg_temp_new();
1296 tcg_gen_andi_i64(shift, cpu_ir[rb], 7);
1297 tcg_gen_shli_i64(shift, shift, 3);
1298 tcg_gen_shl_i64(cpu_ir[rc], tmp, shift);
1299 tcg_temp_free(shift);
1305 /* MSKWH, MSKLH, MSKQH */
1306 static void gen_msk_h(int ra, int rb, int rc, int islit,
1307 uint8_t lit, uint8_t byte_mask)
1309 if (unlikely(rc == 31))
1311 else if (unlikely(ra == 31))
1312 tcg_gen_movi_i64(cpu_ir[rc], 0);
1314 gen_zapnoti (cpu_ir[rc], cpu_ir[ra], ~((byte_mask << (lit & 7)) >> 8));
1316 TCGv shift = tcg_temp_new();
1317 TCGv mask = tcg_temp_new();
1319 /* The instruction description is as above, where the byte_mask
1320 is shifted left, and then we extract bits <15:8>. This can be
1321 emulated with a right-shift on the expanded byte mask. This
1322 requires extra care because for an input <2:0> == 0 we need a
1323 shift of 64 bits in order to generate a zero. This is done by
1324 splitting the shift into two parts, the variable shift - 1
1325 followed by a constant 1 shift. The code we expand below is
1326 equivalent to ~((B & 7) * 8) & 63. */
1328 tcg_gen_andi_i64(shift, cpu_ir[rb], 7);
1329 tcg_gen_shli_i64(shift, shift, 3);
1330 tcg_gen_not_i64(shift, shift);
1331 tcg_gen_andi_i64(shift, shift, 0x3f);
1332 tcg_gen_movi_i64(mask, zapnot_mask (byte_mask));
1333 tcg_gen_shr_i64(mask, mask, shift);
1334 tcg_gen_shri_i64(mask, mask, 1);
1336 tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], mask);
1338 tcg_temp_free(mask);
1339 tcg_temp_free(shift);
1343 /* MSKBL, MSKWL, MSKLL, MSKQL */
1344 static void gen_msk_l(int ra, int rb, int rc, int islit,
1345 uint8_t lit, uint8_t byte_mask)
1347 if (unlikely(rc == 31))
1349 else if (unlikely(ra == 31))
1350 tcg_gen_movi_i64(cpu_ir[rc], 0);
1352 gen_zapnoti (cpu_ir[rc], cpu_ir[ra], ~(byte_mask << (lit & 7)));
1354 TCGv shift = tcg_temp_new();
1355 TCGv mask = tcg_temp_new();
1357 tcg_gen_andi_i64(shift, cpu_ir[rb], 7);
1358 tcg_gen_shli_i64(shift, shift, 3);
1359 tcg_gen_movi_i64(mask, zapnot_mask (byte_mask));
1360 tcg_gen_shl_i64(mask, mask, shift);
1362 tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], mask);
1364 tcg_temp_free(mask);
1365 tcg_temp_free(shift);
1369 /* Code to call arith3 helpers */
1370 #define ARITH3(name) \
1371 static inline void glue(gen_, name)(int ra, int rb, int rc, int islit,\
1374 if (unlikely(rc == 31)) \
1379 TCGv tmp = tcg_const_i64(lit); \
1380 gen_helper_ ## name(cpu_ir[rc], cpu_ir[ra], tmp); \
1381 tcg_temp_free(tmp); \
1383 gen_helper_ ## name (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]); \
1385 TCGv tmp1 = tcg_const_i64(0); \
1387 TCGv tmp2 = tcg_const_i64(lit); \
1388 gen_helper_ ## name (cpu_ir[rc], tmp1, tmp2); \
1389 tcg_temp_free(tmp2); \
1391 gen_helper_ ## name (cpu_ir[rc], tmp1, cpu_ir[rb]); \
1392 tcg_temp_free(tmp1); \
1413 #define MVIOP2(name) \
1414 static inline void glue(gen_, name)(int rb, int rc) \
1416 if (unlikely(rc == 31)) \
1418 if (unlikely(rb == 31)) \
1419 tcg_gen_movi_i64(cpu_ir[rc], 0); \
1421 gen_helper_ ## name (cpu_ir[rc], cpu_ir[rb]); \
1428 static void gen_cmp(TCGCond cond, int ra, int rb, int rc,
1429 int islit, uint8_t lit)
1433 if (unlikely(rc == 31)) {
1438 va = tcg_const_i64(0);
1443 vb = tcg_const_i64(lit);
1448 tcg_gen_setcond_i64(cond, cpu_ir[rc], va, vb);
1458 static void gen_rx(int ra, int set)
1463 tcg_gen_ld8u_i64(cpu_ir[ra], cpu_env, offsetof(CPUAlphaState, intr_flag));
1466 tmp = tcg_const_i32(set);
1467 tcg_gen_st8_i32(tmp, cpu_env, offsetof(CPUAlphaState, intr_flag));
1468 tcg_temp_free_i32(tmp);
1471 static ExitStatus gen_call_pal(DisasContext *ctx, int palcode)
1473 /* We're emulating OSF/1 PALcode. Many of these are trivial access
1474 to internal cpu registers. */
1476 /* Unprivileged PAL call */
1477 if (palcode >= 0x80 && palcode < 0xC0) {
1481 /* No-op inside QEMU. */
1485 tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_unique);
1489 tcg_gen_mov_i64(cpu_unique, cpu_ir[IR_A0]);
1492 return gen_excp(ctx, EXCP_CALL_PAL, palcode & 0xbf);
1497 #ifndef CONFIG_USER_ONLY
1498 /* Privileged PAL code */
1499 if (palcode < 0x40 && (ctx->tb->flags & TB_FLAGS_USER_MODE) == 0) {
1503 /* No-op inside QEMU. */
1507 /* No-op inside QEMU. */
1511 tcg_gen_st_i64(cpu_ir[IR_A0], cpu_env, offsetof(CPUAlphaState, vptptr));
1515 tcg_gen_mov_i64(cpu_sysval, cpu_ir[IR_A0]);
1519 tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_sysval);
1526 /* Note that we already know we're in kernel mode, so we know
1527 that PS only contains the 3 IPL bits. */
1528 tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUAlphaState, ps));
1530 /* But make sure and store only the 3 IPL bits from the user. */
1531 tmp = tcg_temp_new();
1532 tcg_gen_andi_i64(tmp, cpu_ir[IR_A0], PS_INT_MASK);
1533 tcg_gen_st8_i64(tmp, cpu_env, offsetof(CPUAlphaState, ps));
1540 tcg_gen_ld8u_i64(cpu_ir[IR_V0], cpu_env, offsetof(CPUAlphaState, ps));
1544 tcg_gen_mov_i64(cpu_usp, cpu_ir[IR_A0]);
1548 tcg_gen_mov_i64(cpu_ir[IR_V0], cpu_usp);
1552 tcg_gen_ld32s_i64(cpu_ir[IR_V0], cpu_env,
1553 offsetof(CPUAlphaState, cpu_index));
1557 return gen_excp(ctx, EXCP_CALL_PAL, palcode & 0x3f);
1563 return gen_invalid(ctx);
1566 #ifndef CONFIG_USER_ONLY
1568 #define PR_BYTE 0x100000
1569 #define PR_LONG 0x200000
1571 static int cpu_pr_data(int pr)
1574 case 0: return offsetof(CPUAlphaState, ps) | PR_BYTE;
1575 case 1: return offsetof(CPUAlphaState, fen) | PR_BYTE;
1576 case 2: return offsetof(CPUAlphaState, pcc_ofs) | PR_LONG;
1577 case 3: return offsetof(CPUAlphaState, trap_arg0);
1578 case 4: return offsetof(CPUAlphaState, trap_arg1);
1579 case 5: return offsetof(CPUAlphaState, trap_arg2);
1580 case 6: return offsetof(CPUAlphaState, exc_addr);
1581 case 7: return offsetof(CPUAlphaState, palbr);
1582 case 8: return offsetof(CPUAlphaState, ptbr);
1583 case 9: return offsetof(CPUAlphaState, vptptr);
1584 case 10: return offsetof(CPUAlphaState, unique);
1585 case 11: return offsetof(CPUAlphaState, sysval);
1586 case 12: return offsetof(CPUAlphaState, usp);
1589 return offsetof(CPUAlphaState, shadow[pr - 32]);
1591 return offsetof(CPUAlphaState, scratch[pr - 40]);
1594 return offsetof(CPUAlphaState, alarm_expire);
1599 static ExitStatus gen_mfpr(int ra, int regno)
1601 int data = cpu_pr_data(regno);
1603 /* In our emulated PALcode, these processor registers have no
1604 side effects from reading. */
1613 gen_helper_get_time(cpu_ir[ra]);
1615 return EXIT_PC_STALE;
1617 gen_helper_get_time(cpu_ir[ra]);
1622 /* The basic registers are data only, and unknown registers
1623 are read-zero, write-ignore. */
1625 tcg_gen_movi_i64(cpu_ir[ra], 0);
1626 } else if (data & PR_BYTE) {
1627 tcg_gen_ld8u_i64(cpu_ir[ra], cpu_env, data & ~PR_BYTE);
1628 } else if (data & PR_LONG) {
1629 tcg_gen_ld32s_i64(cpu_ir[ra], cpu_env, data & ~PR_LONG);
1631 tcg_gen_ld_i64(cpu_ir[ra], cpu_env, data);
1636 static ExitStatus gen_mtpr(DisasContext *ctx, int rb, int regno)
1642 tmp = tcg_const_i64(0);
1655 gen_helper_tbis(tmp);
1660 tmp = tcg_const_i64(1);
1661 tcg_gen_st32_i64(tmp, cpu_env, offsetof(CPUAlphaState, halted));
1662 return gen_excp(ctx, EXCP_HLT, 0);
1666 gen_helper_halt(tmp);
1667 return EXIT_PC_STALE;
1671 gen_helper_set_alarm(tmp);
1675 /* The basic registers are data only, and unknown registers
1676 are read-zero, write-ignore. */
1677 data = cpu_pr_data(regno);
1679 if (data & PR_BYTE) {
1680 tcg_gen_st8_i64(tmp, cpu_env, data & ~PR_BYTE);
1681 } else if (data & PR_LONG) {
1682 tcg_gen_st32_i64(tmp, cpu_env, data & ~PR_LONG);
1684 tcg_gen_st_i64(tmp, cpu_env, data);
1696 #endif /* !USER_ONLY*/
1698 static ExitStatus translate_one(DisasContext *ctx, uint32_t insn)
1701 int32_t disp21, disp16;
1702 #ifndef CONFIG_USER_ONLY
1706 uint8_t opc, ra, rb, rc, fpfn, fn7, islit, real_islit;
1710 /* Decode all instruction fields */
1712 ra = (insn >> 21) & 0x1F;
1713 rb = (insn >> 16) & 0x1F;
1715 real_islit = islit = (insn >> 12) & 1;
1716 if (rb == 31 && !islit) {
1720 lit = (insn >> 13) & 0xFF;
1721 palcode = insn & 0x03FFFFFF;
1722 disp21 = ((int32_t)((insn & 0x001FFFFF) << 11)) >> 11;
1723 disp16 = (int16_t)(insn & 0x0000FFFF);
1724 #ifndef CONFIG_USER_ONLY
1725 disp12 = (int32_t)((insn & 0x00000FFF) << 20) >> 20;
1727 fn11 = (insn >> 5) & 0x000007FF;
1729 fn7 = (insn >> 5) & 0x0000007F;
1730 LOG_DISAS("opc %02x ra %2d rb %2d rc %2d disp16 %6d\n",
1731 opc, ra, rb, rc, disp16);
1737 ret = gen_call_pal(ctx, palcode);
1762 if (likely(ra != 31)) {
1764 tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16);
1766 tcg_gen_movi_i64(cpu_ir[ra], disp16);
1771 if (likely(ra != 31)) {
1773 tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16 << 16);
1775 tcg_gen_movi_i64(cpu_ir[ra], disp16 << 16);
1780 if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
1781 gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
1787 gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
1791 if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
1792 gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 0);
1798 gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0);
1802 gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0);
1806 gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1);
1812 if (likely(rc != 31)) {
1815 tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
1816 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1818 tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1819 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1823 tcg_gen_movi_i64(cpu_ir[rc], lit);
1825 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
1831 if (likely(rc != 31)) {
1833 TCGv tmp = tcg_temp_new();
1834 tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
1836 tcg_gen_addi_i64(tmp, tmp, lit);
1838 tcg_gen_add_i64(tmp, tmp, cpu_ir[rb]);
1839 tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
1843 tcg_gen_movi_i64(cpu_ir[rc], lit);
1845 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
1851 if (likely(rc != 31)) {
1854 tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
1856 tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1857 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1860 tcg_gen_movi_i64(cpu_ir[rc], -lit);
1862 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1863 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1869 if (likely(rc != 31)) {
1871 TCGv tmp = tcg_temp_new();
1872 tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
1874 tcg_gen_subi_i64(tmp, tmp, lit);
1876 tcg_gen_sub_i64(tmp, tmp, cpu_ir[rb]);
1877 tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
1881 tcg_gen_movi_i64(cpu_ir[rc], -lit);
1883 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1884 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1891 gen_cmpbge(ra, rb, rc, islit, lit);
1895 if (likely(rc != 31)) {
1897 TCGv tmp = tcg_temp_new();
1898 tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
1900 tcg_gen_addi_i64(tmp, tmp, lit);
1902 tcg_gen_add_i64(tmp, tmp, cpu_ir[rb]);
1903 tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
1907 tcg_gen_movi_i64(cpu_ir[rc], lit);
1909 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
1915 if (likely(rc != 31)) {
1917 TCGv tmp = tcg_temp_new();
1918 tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
1920 tcg_gen_subi_i64(tmp, tmp, lit);
1922 tcg_gen_sub_i64(tmp, tmp, cpu_ir[rb]);
1923 tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
1927 tcg_gen_movi_i64(cpu_ir[rc], -lit);
1929 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1930 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1937 gen_cmp(TCG_COND_LTU, ra, rb, rc, islit, lit);
1941 if (likely(rc != 31)) {
1944 tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
1946 tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1949 tcg_gen_movi_i64(cpu_ir[rc], lit);
1951 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1957 if (likely(rc != 31)) {
1959 TCGv tmp = tcg_temp_new();
1960 tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
1962 tcg_gen_addi_i64(cpu_ir[rc], tmp, lit);
1964 tcg_gen_add_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
1968 tcg_gen_movi_i64(cpu_ir[rc], lit);
1970 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1976 if (likely(rc != 31)) {
1979 tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
1981 tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1984 tcg_gen_movi_i64(cpu_ir[rc], -lit);
1986 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1992 if (likely(rc != 31)) {
1994 TCGv tmp = tcg_temp_new();
1995 tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
1997 tcg_gen_subi_i64(cpu_ir[rc], tmp, lit);
1999 tcg_gen_sub_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
2003 tcg_gen_movi_i64(cpu_ir[rc], -lit);
2005 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
2011 gen_cmp(TCG_COND_EQ, ra, rb, rc, islit, lit);
2015 if (likely(rc != 31)) {
2017 TCGv tmp = tcg_temp_new();
2018 tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
2020 tcg_gen_addi_i64(cpu_ir[rc], tmp, lit);
2022 tcg_gen_add_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
2026 tcg_gen_movi_i64(cpu_ir[rc], lit);
2028 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
2034 if (likely(rc != 31)) {
2036 TCGv tmp = tcg_temp_new();
2037 tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
2039 tcg_gen_subi_i64(cpu_ir[rc], tmp, lit);
2041 tcg_gen_sub_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
2045 tcg_gen_movi_i64(cpu_ir[rc], -lit);
2047 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
2053 gen_cmp(TCG_COND_LEU, ra, rb, rc, islit, lit);
2057 gen_addlv(ra, rb, rc, islit, lit);
2061 gen_sublv(ra, rb, rc, islit, lit);
2065 gen_cmp(TCG_COND_LT, ra, rb, rc, islit, lit);
2069 gen_addqv(ra, rb, rc, islit, lit);
2073 gen_subqv(ra, rb, rc, islit, lit);
2077 gen_cmp(TCG_COND_LE, ra, rb, rc, islit, lit);
2087 if (likely(rc != 31)) {
2089 tcg_gen_movi_i64(cpu_ir[rc], 0);
2091 tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], lit);
2093 tcg_gen_and_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2098 if (likely(rc != 31)) {
2101 tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
2103 tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2105 tcg_gen_movi_i64(cpu_ir[rc], 0);
2110 gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 1);
2114 gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 1);
2118 if (likely(rc != 31)) {
2121 tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], lit);
2123 tcg_gen_or_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2126 tcg_gen_movi_i64(cpu_ir[rc], lit);
2128 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
2134 gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 0);
2138 gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 0);
2142 if (likely(rc != 31)) {
2145 tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
2147 tcg_gen_orc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2150 tcg_gen_movi_i64(cpu_ir[rc], ~lit);
2152 tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
2158 if (likely(rc != 31)) {
2161 tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], lit);
2163 tcg_gen_xor_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2166 tcg_gen_movi_i64(cpu_ir[rc], lit);
2168 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
2174 gen_cmov(TCG_COND_LT, ra, rb, rc, islit, lit, 0);
2178 gen_cmov(TCG_COND_GE, ra, rb, rc, islit, lit, 0);
2182 if (likely(rc != 31)) {
2185 tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
2187 tcg_gen_eqv_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2190 tcg_gen_movi_i64(cpu_ir[rc], ~lit);
2192 tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
2198 if (likely(rc != 31)) {
2199 uint64_t amask = ctx->tb->flags >> TB_FLAGS_AMASK_SHIFT;
2202 tcg_gen_movi_i64(cpu_ir[rc], lit & ~amask);
2204 tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[rb], ~amask);
2210 gen_cmov(TCG_COND_LE, ra, rb, rc, islit, lit, 0);
2214 gen_cmov(TCG_COND_GT, ra, rb, rc, islit, lit, 0);
2219 tcg_gen_movi_i64(cpu_ir[rc], ctx->env->implver);
2229 gen_msk_l(ra, rb, rc, islit, lit, 0x01);
2233 gen_ext_l(ra, rb, rc, islit, lit, 0x01);
2237 gen_ins_l(ra, rb, rc, islit, lit, 0x01);
2241 gen_msk_l(ra, rb, rc, islit, lit, 0x03);
2245 gen_ext_l(ra, rb, rc, islit, lit, 0x03);
2249 gen_ins_l(ra, rb, rc, islit, lit, 0x03);
2253 gen_msk_l(ra, rb, rc, islit, lit, 0x0f);
2257 gen_ext_l(ra, rb, rc, islit, lit, 0x0f);
2261 gen_ins_l(ra, rb, rc, islit, lit, 0x0f);
2265 gen_zap(ra, rb, rc, islit, lit);
2269 gen_zapnot(ra, rb, rc, islit, lit);
2273 gen_msk_l(ra, rb, rc, islit, lit, 0xff);
2277 if (likely(rc != 31)) {
2280 tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
2282 TCGv shift = tcg_temp_new();
2283 tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
2284 tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], shift);
2285 tcg_temp_free(shift);
2288 tcg_gen_movi_i64(cpu_ir[rc], 0);
2293 gen_ext_l(ra, rb, rc, islit, lit, 0xff);
2297 if (likely(rc != 31)) {
2300 tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
2302 TCGv shift = tcg_temp_new();
2303 tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
2304 tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], shift);
2305 tcg_temp_free(shift);
2308 tcg_gen_movi_i64(cpu_ir[rc], 0);
2313 gen_ins_l(ra, rb, rc, islit, lit, 0xff);
2317 if (likely(rc != 31)) {
2320 tcg_gen_sari_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
2322 TCGv shift = tcg_temp_new();
2323 tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
2324 tcg_gen_sar_i64(cpu_ir[rc], cpu_ir[ra], shift);
2325 tcg_temp_free(shift);
2328 tcg_gen_movi_i64(cpu_ir[rc], 0);
2333 gen_msk_h(ra, rb, rc, islit, lit, 0x03);
2337 gen_ins_h(ra, rb, rc, islit, lit, 0x03);
2341 gen_ext_h(ra, rb, rc, islit, lit, 0x03);
2345 gen_msk_h(ra, rb, rc, islit, lit, 0x0f);
2349 gen_ins_h(ra, rb, rc, islit, lit, 0x0f);
2353 gen_ext_h(ra, rb, rc, islit, lit, 0x0f);
2357 gen_msk_h(ra, rb, rc, islit, lit, 0xff);
2361 gen_ins_h(ra, rb, rc, islit, lit, 0xff);
2365 gen_ext_h(ra, rb, rc, islit, lit, 0xff);
2375 if (likely(rc != 31)) {
2377 tcg_gen_movi_i64(cpu_ir[rc], 0);
2380 tcg_gen_muli_i64(cpu_ir[rc], cpu_ir[ra], lit);
2382 tcg_gen_mul_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2383 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
2389 if (likely(rc != 31)) {
2391 tcg_gen_movi_i64(cpu_ir[rc], 0);
2393 tcg_gen_muli_i64(cpu_ir[rc], cpu_ir[ra], lit);
2395 tcg_gen_mul_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
2400 gen_umulh(ra, rb, rc, islit, lit);
2404 gen_mullv(ra, rb, rc, islit, lit);
2408 gen_mulqv(ra, rb, rc, islit, lit);
2415 switch (fpfn) { /* fn11 & 0x3F */
2418 if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
2421 if (likely(rc != 31)) {
2423 TCGv_i32 tmp = tcg_temp_new_i32();
2424 tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
2425 gen_helper_memory_to_s(cpu_fir[rc], tmp);
2426 tcg_temp_free_i32(tmp);
2428 tcg_gen_movi_i64(cpu_fir[rc], 0);
2433 if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
2440 if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
2441 gen_fsqrts(ctx, rb, rc, fn11);
2447 if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
2450 if (likely(rc != 31)) {
2452 TCGv_i32 tmp = tcg_temp_new_i32();
2453 tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
2454 gen_helper_memory_to_f(cpu_fir[rc], tmp);
2455 tcg_temp_free_i32(tmp);
2457 tcg_gen_movi_i64(cpu_fir[rc], 0);
2462 if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
2465 if (likely(rc != 31)) {
2467 tcg_gen_mov_i64(cpu_fir[rc], cpu_ir[ra]);
2469 tcg_gen_movi_i64(cpu_fir[rc], 0);
2474 if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
2481 if (ctx->tb->flags & TB_FLAGS_AMASK_FIX) {
2482 gen_fsqrtt(ctx, rb, rc, fn11);
2491 /* VAX floating point */
2492 /* XXX: rounding mode and trap are ignored (!) */
2493 switch (fpfn) { /* fn11 & 0x3F */
2496 gen_faddf(ra, rb, rc);
2500 gen_fsubf(ra, rb, rc);
2504 gen_fmulf(ra, rb, rc);
2508 gen_fdivf(ra, rb, rc);
2520 gen_faddg(ra, rb, rc);
2524 gen_fsubg(ra, rb, rc);
2528 gen_fmulg(ra, rb, rc);
2532 gen_fdivg(ra, rb, rc);
2536 gen_fcmpgeq(ra, rb, rc);
2540 gen_fcmpglt(ra, rb, rc);
2544 gen_fcmpgle(ra, rb, rc);
2575 /* IEEE floating-point */
2576 switch (fpfn) { /* fn11 & 0x3F */
2579 gen_fadds(ctx, ra, rb, rc, fn11);
2583 gen_fsubs(ctx, ra, rb, rc, fn11);
2587 gen_fmuls(ctx, ra, rb, rc, fn11);
2591 gen_fdivs(ctx, ra, rb, rc, fn11);
2595 gen_faddt(ctx, ra, rb, rc, fn11);
2599 gen_fsubt(ctx, ra, rb, rc, fn11);
2603 gen_fmult(ctx, ra, rb, rc, fn11);
2607 gen_fdivt(ctx, ra, rb, rc, fn11);
2611 gen_fcmptun(ctx, ra, rb, rc, fn11);
2615 gen_fcmpteq(ctx, ra, rb, rc, fn11);
2619 gen_fcmptlt(ctx, ra, rb, rc, fn11);
2623 gen_fcmptle(ctx, ra, rb, rc, fn11);
2626 if (fn11 == 0x2AC || fn11 == 0x6AC) {
2628 gen_fcvtst(ctx, rb, rc, fn11);
2631 gen_fcvtts(ctx, rb, rc, fn11);
2636 gen_fcvttq(ctx, rb, rc, fn11);
2640 gen_fcvtqs(ctx, rb, rc, fn11);
2644 gen_fcvtqt(ctx, rb, rc, fn11);
2657 if (likely(rc != 31)) {
2661 tcg_gen_movi_i64(cpu_fir[rc], 0);
2663 tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
2666 gen_fcpys(ra, rb, rc);
2672 gen_fcpysn(ra, rb, rc);
2676 gen_fcpyse(ra, rb, rc);
2680 if (likely(ra != 31))
2681 gen_helper_store_fpcr(cpu_env, cpu_fir[ra]);
2683 TCGv tmp = tcg_const_i64(0);
2684 gen_helper_store_fpcr(cpu_env, tmp);
2690 if (likely(ra != 31))
2691 gen_helper_load_fpcr(cpu_fir[ra], cpu_env);
2695 gen_fcmov(TCG_COND_EQ, ra, rb, rc);
2699 gen_fcmov(TCG_COND_NE, ra, rb, rc);
2703 gen_fcmov(TCG_COND_LT, ra, rb, rc);
2707 gen_fcmov(TCG_COND_GE, ra, rb, rc);
2711 gen_fcmov(TCG_COND_LE, ra, rb, rc);
2715 gen_fcmov(TCG_COND_GT, ra, rb, rc);
2725 /* ??? I'm pretty sure there's nothing that /sv needs to do that
2726 /v doesn't do. The only thing I can think is that /sv is a
2727 valid instruction merely for completeness in the ISA. */
2728 gen_fcvtql_v(ctx, rb, rc);
2735 switch ((uint16_t)disp16) {
2765 gen_helper_load_pcc(cpu_ir[ra]);
2767 ret = EXIT_PC_STALE;
2769 gen_helper_load_pcc(cpu_ir[ra]);
2793 /* HW_MFPR (PALcode) */
2794 #ifndef CONFIG_USER_ONLY
2795 if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
2796 return gen_mfpr(ra, insn & 0xffff);
2801 /* JMP, JSR, RET, JSR_COROUTINE. These only differ by the branch
2802 prediction stack action, which of course we don't implement. */
2804 tcg_gen_andi_i64(cpu_pc, cpu_ir[rb], ~3);
2806 tcg_gen_movi_i64(cpu_pc, 0);
2809 tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
2811 ret = EXIT_PC_UPDATED;
2814 /* HW_LD (PALcode) */
2815 #ifndef CONFIG_USER_ONLY
2816 if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
2823 addr = tcg_temp_new();
2825 tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
2827 tcg_gen_movi_i64(addr, disp12);
2828 switch ((insn >> 12) & 0xF) {
2830 /* Longword physical access (hw_ldl/p) */
2831 gen_helper_ldl_phys(cpu_ir[ra], addr);
2834 /* Quadword physical access (hw_ldq/p) */
2835 gen_helper_ldq_phys(cpu_ir[ra], addr);
2838 /* Longword physical access with lock (hw_ldl_l/p) */
2839 gen_helper_ldl_l_phys(cpu_ir[ra], addr);
2842 /* Quadword physical access with lock (hw_ldq_l/p) */
2843 gen_helper_ldq_l_phys(cpu_ir[ra], addr);
2846 /* Longword virtual PTE fetch (hw_ldl/v) */
2849 /* Quadword virtual PTE fetch (hw_ldq/v) */
2853 /* Incpu_ir[ra]id */
2856 /* Incpu_ir[ra]id */
2859 /* Longword virtual access (hw_ldl) */
2862 /* Quadword virtual access (hw_ldq) */
2865 /* Longword virtual access with protection check (hw_ldl/w) */
2866 tcg_gen_qemu_ld32s(cpu_ir[ra], addr, MMU_KERNEL_IDX);
2869 /* Quadword virtual access with protection check (hw_ldq/w) */
2870 tcg_gen_qemu_ld64(cpu_ir[ra], addr, MMU_KERNEL_IDX);
2873 /* Longword virtual access with alt access mode (hw_ldl/a)*/
2876 /* Quadword virtual access with alt access mode (hw_ldq/a) */
2879 /* Longword virtual access with alternate access mode and
2880 protection checks (hw_ldl/wa) */
2881 tcg_gen_qemu_ld32s(cpu_ir[ra], addr, MMU_USER_IDX);
2884 /* Quadword virtual access with alternate access mode and
2885 protection checks (hw_ldq/wa) */
2886 tcg_gen_qemu_ld64(cpu_ir[ra], addr, MMU_USER_IDX);
2889 tcg_temp_free(addr);
2898 if ((ctx->tb->flags & TB_FLAGS_AMASK_BWX) == 0) {
2901 if (likely(rc != 31)) {
2903 tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int8_t)lit));
2905 tcg_gen_ext8s_i64(cpu_ir[rc], cpu_ir[rb]);
2910 if (ctx->tb->flags & TB_FLAGS_AMASK_BWX) {
2911 if (likely(rc != 31)) {
2913 tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
2915 tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
2923 if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
2924 if (likely(rc != 31)) {
2926 tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
2928 gen_helper_ctpop(cpu_ir[rc], cpu_ir[rb]);
2936 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
2937 gen_perr(ra, rb, rc, islit, lit);
2943 if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
2944 if (likely(rc != 31)) {
2946 tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
2948 gen_helper_ctlz(cpu_ir[rc], cpu_ir[rb]);
2956 if (ctx->tb->flags & TB_FLAGS_AMASK_CIX) {
2957 if (likely(rc != 31)) {
2959 tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
2961 gen_helper_cttz(cpu_ir[rc], cpu_ir[rb]);
2969 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
2970 if (real_islit || ra != 31) {
2979 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
2980 if (real_islit || ra != 31) {
2989 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
2990 if (real_islit || ra != 31) {
2999 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3000 if (real_islit || ra != 31) {
3009 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3010 gen_minsb8(ra, rb, rc, islit, lit);
3016 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3017 gen_minsw4(ra, rb, rc, islit, lit);
3023 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3024 gen_minub8(ra, rb, rc, islit, lit);
3030 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3031 gen_minuw4(ra, rb, rc, islit, lit);
3037 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3038 gen_maxub8(ra, rb, rc, islit, lit);
3044 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3045 gen_maxuw4(ra, rb, rc, islit, lit);
3051 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3052 gen_maxsb8(ra, rb, rc, islit, lit);
3058 if (ctx->tb->flags & TB_FLAGS_AMASK_MVI) {
3059 gen_maxsw4(ra, rb, rc, islit, lit);
3065 if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
3068 if (likely(rc != 31)) {
3070 tcg_gen_mov_i64(cpu_ir[rc], cpu_fir[ra]);
3072 tcg_gen_movi_i64(cpu_ir[rc], 0);
3077 if ((ctx->tb->flags & TB_FLAGS_AMASK_FIX) == 0) {
3081 TCGv_i32 tmp1 = tcg_temp_new_i32();
3083 gen_helper_s_to_memory(tmp1, cpu_fir[ra]);
3085 TCGv tmp2 = tcg_const_i64(0);
3086 gen_helper_s_to_memory(tmp1, tmp2);
3087 tcg_temp_free(tmp2);
3089 tcg_gen_ext_i32_i64(cpu_ir[rc], tmp1);
3090 tcg_temp_free_i32(tmp1);
3098 /* HW_MTPR (PALcode) */
3099 #ifndef CONFIG_USER_ONLY
3100 if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
3101 return gen_mtpr(ctx, rb, insn & 0xffff);
3106 /* HW_RET (PALcode) */
3107 #ifndef CONFIG_USER_ONLY
3108 if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
3110 /* Pre-EV6 CPUs interpreted this as HW_REI, loading the return
3111 address from EXC_ADDR. This turns out to be useful for our
3112 emulation PALcode, so continue to accept it. */
3113 TCGv tmp = tcg_temp_new();
3114 tcg_gen_ld_i64(tmp, cpu_env, offsetof(CPUAlphaState, exc_addr));
3115 gen_helper_hw_ret(tmp);
3118 gen_helper_hw_ret(cpu_ir[rb]);
3120 ret = EXIT_PC_UPDATED;
3126 /* HW_ST (PALcode) */
3127 #ifndef CONFIG_USER_ONLY
3128 if (ctx->tb->flags & TB_FLAGS_PAL_MODE) {
3130 addr = tcg_temp_new();
3132 tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
3134 tcg_gen_movi_i64(addr, disp12);
3138 val = tcg_temp_new();
3139 tcg_gen_movi_i64(val, 0);
3141 switch ((insn >> 12) & 0xF) {
3143 /* Longword physical access */
3144 gen_helper_stl_phys(addr, val);
3147 /* Quadword physical access */
3148 gen_helper_stq_phys(addr, val);
3151 /* Longword physical access with lock */
3152 gen_helper_stl_c_phys(val, addr, val);
3155 /* Quadword physical access with lock */
3156 gen_helper_stq_c_phys(val, addr, val);
3159 /* Longword virtual access */
3162 /* Quadword virtual access */
3183 /* Longword virtual access with alternate access mode */
3186 /* Quadword virtual access with alternate access mode */
3197 tcg_temp_free(addr);
3204 gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
3208 gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0);
3212 gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0);
3216 gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0);
3220 gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0);
3224 gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0);
3228 gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0);
3232 gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0);
3236 gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0);
3240 gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0);
3244 gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0);
3248 gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0);
3252 gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0);
3256 gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0);
3260 ret = gen_store_conditional(ctx, ra, rb, disp16, 0);
3264 ret = gen_store_conditional(ctx, ra, rb, disp16, 1);
3268 ret = gen_bdirect(ctx, ra, disp21);
3270 case 0x31: /* FBEQ */
3271 ret = gen_fbcond(ctx, TCG_COND_EQ, ra, disp21);
3273 case 0x32: /* FBLT */
3274 ret = gen_fbcond(ctx, TCG_COND_LT, ra, disp21);
3276 case 0x33: /* FBLE */
3277 ret = gen_fbcond(ctx, TCG_COND_LE, ra, disp21);
3281 ret = gen_bdirect(ctx, ra, disp21);
3283 case 0x35: /* FBNE */
3284 ret = gen_fbcond(ctx, TCG_COND_NE, ra, disp21);
3286 case 0x36: /* FBGE */
3287 ret = gen_fbcond(ctx, TCG_COND_GE, ra, disp21);
3289 case 0x37: /* FBGT */
3290 ret = gen_fbcond(ctx, TCG_COND_GT, ra, disp21);
3294 ret = gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 1);
3298 ret = gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 0);
3302 ret = gen_bcond(ctx, TCG_COND_LT, ra, disp21, 0);
3306 ret = gen_bcond(ctx, TCG_COND_LE, ra, disp21, 0);
3310 ret = gen_bcond(ctx, TCG_COND_NE, ra, disp21, 1);
3314 ret = gen_bcond(ctx, TCG_COND_NE, ra, disp21, 0);
3318 ret = gen_bcond(ctx, TCG_COND_GE, ra, disp21, 0);
3322 ret = gen_bcond(ctx, TCG_COND_GT, ra, disp21, 0);
3325 ret = gen_invalid(ctx);
3332 static inline void gen_intermediate_code_internal(CPUAlphaState *env,
3333 TranslationBlock *tb,
3336 DisasContext ctx, *ctxp = &ctx;
3337 target_ulong pc_start;
3339 uint16_t *gen_opc_end;
3347 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
3352 ctx.mem_idx = cpu_mmu_index(env);
3354 /* ??? Every TB begins with unset rounding mode, to be initialized on
3355 the first fp insn of the TB. Alternately we could define a proper
3356 default for every TB (e.g. QUAL_RM_N or QUAL_RM_D) and make sure
3357 to reset the FP_STATUS to that default at the end of any TB that
3358 changes the default. We could even (gasp) dynamiclly figure out
3359 what default would be most efficient given the running program. */
3361 /* Similarly for flush-to-zero. */
3365 max_insns = tb->cflags & CF_COUNT_MASK;
3367 max_insns = CF_COUNT_MASK;
3371 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
3372 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
3373 if (bp->pc == ctx.pc) {
3374 gen_excp(&ctx, EXCP_DEBUG, 0);
3380 j = gen_opc_ptr - gen_opc_buf;
3384 gen_opc_instr_start[lj++] = 0;
3386 gen_opc_pc[lj] = ctx.pc;
3387 gen_opc_instr_start[lj] = 1;
3388 gen_opc_icount[lj] = num_insns;
3390 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
3392 insn = ldl_code(ctx.pc);
3395 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
3396 tcg_gen_debug_insn_start(ctx.pc);
3400 ret = translate_one(ctxp, insn);
3402 /* If we reach a page boundary, are single stepping,
3403 or exhaust instruction count, stop generation. */
3405 && ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0
3406 || gen_opc_ptr >= gen_opc_end
3407 || num_insns >= max_insns
3409 || env->singlestep_enabled)) {
3410 ret = EXIT_PC_STALE;
3412 } while (ret == NO_EXIT);
3414 if (tb->cflags & CF_LAST_IO) {
3423 tcg_gen_movi_i64(cpu_pc, ctx.pc);
3425 case EXIT_PC_UPDATED:
3426 if (env->singlestep_enabled) {
3427 gen_excp_1(EXCP_DEBUG, 0);
3436 gen_icount_end(tb, num_insns);
3437 *gen_opc_ptr = INDEX_op_end;
3439 j = gen_opc_ptr - gen_opc_buf;
3442 gen_opc_instr_start[lj++] = 0;
3444 tb->size = ctx.pc - pc_start;
3445 tb->icount = num_insns;
3449 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
3450 qemu_log("IN: %s\n", lookup_symbol(pc_start));
3451 log_target_disas(pc_start, ctx.pc - pc_start, 1);
3457 void gen_intermediate_code (CPUAlphaState *env, struct TranslationBlock *tb)
3459 gen_intermediate_code_internal(env, tb, 0);
3462 void gen_intermediate_code_pc (CPUAlphaState *env, struct TranslationBlock *tb)
3464 gen_intermediate_code_internal(env, tb, 1);
3472 static const struct cpu_def_t cpu_defs[] = {
3473 { "ev4", IMPLVER_2106x, 0 },
3474 { "ev5", IMPLVER_21164, 0 },
3475 { "ev56", IMPLVER_21164, AMASK_BWX },
3476 { "pca56", IMPLVER_21164, AMASK_BWX | AMASK_MVI },
3477 { "ev6", IMPLVER_21264, AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP },
3478 { "ev67", IMPLVER_21264, (AMASK_BWX | AMASK_FIX | AMASK_CIX
3479 | AMASK_MVI | AMASK_TRAP | AMASK_PREFETCH), },
3480 { "ev68", IMPLVER_21264, (AMASK_BWX | AMASK_FIX | AMASK_CIX
3481 | AMASK_MVI | AMASK_TRAP | AMASK_PREFETCH), },
3482 { "21064", IMPLVER_2106x, 0 },
3483 { "21164", IMPLVER_21164, 0 },
3484 { "21164a", IMPLVER_21164, AMASK_BWX },
3485 { "21164pc", IMPLVER_21164, AMASK_BWX | AMASK_MVI },
3486 { "21264", IMPLVER_21264, AMASK_BWX | AMASK_FIX | AMASK_MVI | AMASK_TRAP },
3487 { "21264a", IMPLVER_21264, (AMASK_BWX | AMASK_FIX | AMASK_CIX
3488 | AMASK_MVI | AMASK_TRAP | AMASK_PREFETCH), }
3491 CPUAlphaState * cpu_alpha_init (const char *cpu_model)
3494 int implver, amask, i, max;
3496 env = g_malloc0(sizeof(CPUAlphaState));
3498 alpha_translate_init();
3501 /* Default to ev67; no reason not to emulate insns by default. */
3502 implver = IMPLVER_21264;
3503 amask = (AMASK_BWX | AMASK_FIX | AMASK_CIX | AMASK_MVI
3504 | AMASK_TRAP | AMASK_PREFETCH);
3506 max = ARRAY_SIZE(cpu_defs);
3507 for (i = 0; i < max; i++) {
3508 if (strcmp (cpu_model, cpu_defs[i].name) == 0) {
3509 implver = cpu_defs[i].implver;
3510 amask = cpu_defs[i].amask;
3514 env->implver = implver;
3517 #if defined (CONFIG_USER_ONLY)
3518 env->ps = PS_USER_MODE;
3519 cpu_alpha_store_fpcr(env, (FPCR_INVD | FPCR_DZED | FPCR_OVFD
3520 | FPCR_UNFD | FPCR_INED | FPCR_DNOD
3521 | FPCR_DYN_NORMAL));
3523 env->lock_addr = -1;
3526 qemu_init_vcpu(env);
3530 void restore_state_to_opc(CPUAlphaState *env, TranslationBlock *tb, int pc_pos)
3532 env->pc = gen_opc_pc[pc_pos];