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/>.
27 #include "host-utils.h"
29 #include "qemu-common.h"
35 #undef ALPHA_DEBUG_DISAS
36 #define CONFIG_SOFTFLOAT_INLINE
38 #ifdef ALPHA_DEBUG_DISAS
39 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
41 # define LOG_DISAS(...) do { } while (0)
44 typedef struct DisasContext DisasContext
;
46 struct TranslationBlock
*tb
;
50 #if !defined (CONFIG_USER_ONLY)
55 /* Current rounding mode for this TB. */
57 /* Current flush-to-zero setting for this TB. */
61 /* Return values from translate_one, indicating the state of the TB.
62 Note that zero indicates that we are not exiting the TB. */
67 /* We have emitted one or more goto_tb. No fixup required. */
70 /* We are not using a goto_tb (for whatever reason), but have updated
71 the PC (for whatever reason), so there's no need to do it again on
75 /* We are exiting the TB, but have neither emitted a goto_tb, nor
76 updated the PC for the next instruction to be executed. */
79 /* We are ending the TB with a noreturn function call, e.g. longjmp.
80 No following code will be executed. */
84 /* global register indexes */
85 static TCGv_ptr cpu_env
;
86 static TCGv cpu_ir
[31];
87 static TCGv cpu_fir
[31];
89 static TCGv cpu_lock_addr
;
90 static TCGv cpu_lock_st_addr
;
91 static TCGv cpu_lock_value
;
92 #ifdef CONFIG_USER_ONLY
97 static char cpu_reg_names
[10*4+21*5 + 10*5+21*6];
99 #include "gen-icount.h"
101 static void alpha_translate_init(void)
105 static int done_init
= 0;
110 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
113 for (i
= 0; i
< 31; i
++) {
114 sprintf(p
, "ir%d", i
);
115 cpu_ir
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
116 offsetof(CPUState
, ir
[i
]), p
);
117 p
+= (i
< 10) ? 4 : 5;
119 sprintf(p
, "fir%d", i
);
120 cpu_fir
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
121 offsetof(CPUState
, fir
[i
]), p
);
122 p
+= (i
< 10) ? 5 : 6;
125 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
,
126 offsetof(CPUState
, pc
), "pc");
128 cpu_lock_addr
= tcg_global_mem_new_i64(TCG_AREG0
,
129 offsetof(CPUState
, lock_addr
),
131 cpu_lock_st_addr
= tcg_global_mem_new_i64(TCG_AREG0
,
132 offsetof(CPUState
, lock_st_addr
),
134 cpu_lock_value
= tcg_global_mem_new_i64(TCG_AREG0
,
135 offsetof(CPUState
, lock_value
),
138 #ifdef CONFIG_USER_ONLY
139 cpu_uniq
= tcg_global_mem_new_i64(TCG_AREG0
,
140 offsetof(CPUState
, unique
), "uniq");
143 /* register helpers */
150 static ExitStatus
gen_excp(DisasContext
*ctx
, int exception
, int error_code
)
154 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
);
155 tmp1
= tcg_const_i32(exception
);
156 tmp2
= tcg_const_i32(error_code
);
157 gen_helper_excp(tmp1
, tmp2
);
158 tcg_temp_free_i32(tmp2
);
159 tcg_temp_free_i32(tmp1
);
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_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(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(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
, offsetof(CPUState
, fpcr_dyn_round
));
618 #if defined(CONFIG_SOFTFLOAT_INLINE)
619 /* ??? The "softfloat.h" interface is to call set_float_rounding_mode.
620 With CONFIG_SOFTFLOAT that expands to an out-of-line call that just
621 sets the one field. */
622 tcg_gen_st8_i32(tmp
, cpu_env
,
623 offsetof(CPUState
, fp_status
.float_rounding_mode
));
625 gen_helper_setroundmode(tmp
);
628 tcg_temp_free_i32(tmp
);
631 static void gen_qual_flushzero(DisasContext
*ctx
, int fn11
)
636 if (fn11
== ctx
->tb_ftz
) {
641 tmp
= tcg_temp_new_i32();
643 /* Underflow is enabled, use the FPCR setting. */
644 tcg_gen_ld8u_i32(tmp
, cpu_env
, offsetof(CPUState
, fpcr_flush_to_zero
));
646 /* Underflow is disabled, force flush-to-zero. */
647 tcg_gen_movi_i32(tmp
, 1);
650 #if defined(CONFIG_SOFTFLOAT_INLINE)
651 tcg_gen_st8_i32(tmp
, cpu_env
,
652 offsetof(CPUState
, fp_status
.flush_to_zero
));
654 gen_helper_setflushzero(tmp
);
657 tcg_temp_free_i32(tmp
);
660 static TCGv
gen_ieee_input(int reg
, int fn11
, int is_cmp
)
662 TCGv val
= tcg_temp_new();
664 tcg_gen_movi_i64(val
, 0);
665 } else if (fn11
& QUAL_S
) {
666 gen_helper_ieee_input_s(val
, cpu_fir
[reg
]);
668 gen_helper_ieee_input_cmp(val
, cpu_fir
[reg
]);
670 gen_helper_ieee_input(val
, cpu_fir
[reg
]);
675 static void gen_fp_exc_clear(void)
677 #if defined(CONFIG_SOFTFLOAT_INLINE)
678 TCGv_i32 zero
= tcg_const_i32(0);
679 tcg_gen_st8_i32(zero
, cpu_env
,
680 offsetof(CPUState
, fp_status
.float_exception_flags
));
681 tcg_temp_free_i32(zero
);
683 gen_helper_fp_exc_clear();
687 static void gen_fp_exc_raise_ignore(int rc
, int fn11
, int ignore
)
689 /* ??? We ought to be able to do something with imprecise exceptions.
690 E.g. notice we're still in the trap shadow of something within the
691 TB and do not generate the code to signal the exception; end the TB
692 when an exception is forced to arrive, either by consumption of a
693 register value or TRAPB or EXCB. */
694 TCGv_i32 exc
= tcg_temp_new_i32();
697 #if defined(CONFIG_SOFTFLOAT_INLINE)
698 tcg_gen_ld8u_i32(exc
, cpu_env
,
699 offsetof(CPUState
, fp_status
.float_exception_flags
));
701 gen_helper_fp_exc_get(exc
);
705 tcg_gen_andi_i32(exc
, exc
, ~ignore
);
708 /* ??? Pass in the regno of the destination so that the helper can
709 set EXC_MASK, which contains a bitmask of destination registers
710 that have caused arithmetic traps. A simple userspace emulation
711 does not require this. We do need it for a guest kernel's entArith,
712 or if we were to do something clever with imprecise exceptions. */
713 reg
= tcg_const_i32(rc
+ 32);
716 gen_helper_fp_exc_raise_s(exc
, reg
);
718 gen_helper_fp_exc_raise(exc
, reg
);
721 tcg_temp_free_i32(reg
);
722 tcg_temp_free_i32(exc
);
725 static inline void gen_fp_exc_raise(int rc
, int fn11
)
727 gen_fp_exc_raise_ignore(rc
, fn11
, fn11
& QUAL_I
? 0 : float_flag_inexact
);
730 static void gen_fcvtlq(int rb
, int rc
)
732 if (unlikely(rc
== 31)) {
735 if (unlikely(rb
== 31)) {
736 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
738 TCGv tmp
= tcg_temp_new();
740 /* The arithmetic right shift here, plus the sign-extended mask below
741 yields a sign-extended result without an explicit ext32s_i64. */
742 tcg_gen_sari_i64(tmp
, cpu_fir
[rb
], 32);
743 tcg_gen_shri_i64(cpu_fir
[rc
], cpu_fir
[rb
], 29);
744 tcg_gen_andi_i64(tmp
, tmp
, (int32_t)0xc0000000);
745 tcg_gen_andi_i64(cpu_fir
[rc
], cpu_fir
[rc
], 0x3fffffff);
746 tcg_gen_or_i64(cpu_fir
[rc
], cpu_fir
[rc
], tmp
);
752 static void gen_fcvtql(int rb
, int rc
)
754 if (unlikely(rc
== 31)) {
757 if (unlikely(rb
== 31)) {
758 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
760 TCGv tmp
= tcg_temp_new();
762 tcg_gen_andi_i64(tmp
, cpu_fir
[rb
], 0xC0000000);
763 tcg_gen_andi_i64(cpu_fir
[rc
], cpu_fir
[rb
], 0x3FFFFFFF);
764 tcg_gen_shli_i64(tmp
, tmp
, 32);
765 tcg_gen_shli_i64(cpu_fir
[rc
], cpu_fir
[rc
], 29);
766 tcg_gen_or_i64(cpu_fir
[rc
], cpu_fir
[rc
], tmp
);
772 static void gen_fcvtql_v(DisasContext
*ctx
, int rb
, int rc
)
775 int lab
= gen_new_label();
776 TCGv tmp
= tcg_temp_new();
778 tcg_gen_ext32s_i64(tmp
, cpu_fir
[rb
]);
779 tcg_gen_brcond_i64(TCG_COND_EQ
, tmp
, cpu_fir
[rb
], lab
);
780 gen_excp(ctx
, EXCP_ARITH
, EXC_M_IOV
);
787 #define FARITH2(name) \
788 static inline void glue(gen_f, name)(int rb, int rc) \
790 if (unlikely(rc == 31)) { \
794 gen_helper_ ## name (cpu_fir[rc], cpu_fir[rb]); \
796 TCGv tmp = tcg_const_i64(0); \
797 gen_helper_ ## name (cpu_fir[rc], tmp); \
798 tcg_temp_free(tmp); \
802 /* ??? VAX instruction qualifiers ignored. */
810 static void gen_ieee_arith2(DisasContext
*ctx
, void (*helper
)(TCGv
, TCGv
),
811 int rb
, int rc
, int fn11
)
815 /* ??? This is wrong: the instruction is not a nop, it still may
817 if (unlikely(rc
== 31)) {
821 gen_qual_roundmode(ctx
, fn11
);
822 gen_qual_flushzero(ctx
, fn11
);
825 vb
= gen_ieee_input(rb
, fn11
, 0);
826 helper(cpu_fir
[rc
], vb
);
829 gen_fp_exc_raise(rc
, fn11
);
832 #define IEEE_ARITH2(name) \
833 static inline void glue(gen_f, name)(DisasContext *ctx, \
834 int rb, int rc, int fn11) \
836 gen_ieee_arith2(ctx, gen_helper_##name, rb, rc, fn11); \
843 static void gen_fcvttq(DisasContext
*ctx
, int rb
, int rc
, int fn11
)
848 /* ??? This is wrong: the instruction is not a nop, it still may
850 if (unlikely(rc
== 31)) {
854 /* No need to set flushzero, since we have an integer output. */
856 vb
= gen_ieee_input(rb
, fn11
, 0);
858 /* Almost all integer conversions use cropped rounding, and most
859 also do not have integer overflow enabled. Special case that. */
862 gen_helper_cvttq_c(cpu_fir
[rc
], vb
);
864 case QUAL_V
| QUAL_RM_C
:
865 case QUAL_S
| QUAL_V
| QUAL_RM_C
:
866 ignore
= float_flag_inexact
;
868 case QUAL_S
| QUAL_V
| QUAL_I
| QUAL_RM_C
:
869 gen_helper_cvttq_svic(cpu_fir
[rc
], vb
);
872 gen_qual_roundmode(ctx
, fn11
);
873 gen_helper_cvttq(cpu_fir
[rc
], vb
);
874 ignore
|= (fn11
& QUAL_V
? 0 : float_flag_overflow
);
875 ignore
|= (fn11
& QUAL_I
? 0 : float_flag_inexact
);
880 gen_fp_exc_raise_ignore(rc
, fn11
, ignore
);
883 static void gen_ieee_intcvt(DisasContext
*ctx
, void (*helper
)(TCGv
, TCGv
),
884 int rb
, int rc
, int fn11
)
888 /* ??? This is wrong: the instruction is not a nop, it still may
890 if (unlikely(rc
== 31)) {
894 gen_qual_roundmode(ctx
, fn11
);
897 vb
= tcg_const_i64(0);
902 /* The only exception that can be raised by integer conversion
903 is inexact. Thus we only need to worry about exceptions when
904 inexact handling is requested. */
907 helper(cpu_fir
[rc
], vb
);
908 gen_fp_exc_raise(rc
, fn11
);
910 helper(cpu_fir
[rc
], vb
);
918 #define IEEE_INTCVT(name) \
919 static inline void glue(gen_f, name)(DisasContext *ctx, \
920 int rb, int rc, int fn11) \
922 gen_ieee_intcvt(ctx, gen_helper_##name, rb, rc, fn11); \
927 static void gen_cpys_internal(int ra
, int rb
, int rc
, int inv_a
, uint64_t mask
)
932 if (unlikely(rc
== 31)) {
936 vmask
= tcg_const_i64(mask
);
946 va
= tcg_temp_new_i64();
947 tcg_gen_mov_i64(va
, cpu_fir
[ra
]);
949 tcg_gen_andc_i64(va
, vmask
, va
);
951 tcg_gen_and_i64(va
, va
, vmask
);
959 vb
= tcg_temp_new_i64();
960 tcg_gen_andc_i64(vb
, cpu_fir
[rb
], vmask
);
963 switch (za
<< 1 | zb
) {
965 tcg_gen_or_i64(cpu_fir
[rc
], va
, vb
);
968 tcg_gen_mov_i64(cpu_fir
[rc
], va
);
971 tcg_gen_mov_i64(cpu_fir
[rc
], vb
);
974 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
978 tcg_temp_free(vmask
);
987 static inline void gen_fcpys(int ra
, int rb
, int rc
)
989 gen_cpys_internal(ra
, rb
, rc
, 0, 0x8000000000000000ULL
);
992 static inline void gen_fcpysn(int ra
, int rb
, int rc
)
994 gen_cpys_internal(ra
, rb
, rc
, 1, 0x8000000000000000ULL
);
997 static inline void gen_fcpyse(int ra
, int rb
, int rc
)
999 gen_cpys_internal(ra
, rb
, rc
, 0, 0xFFF0000000000000ULL
);
1002 #define FARITH3(name) \
1003 static inline void glue(gen_f, name)(int ra, int rb, int rc) \
1007 if (unlikely(rc == 31)) { \
1011 va = tcg_const_i64(0); \
1016 vb = tcg_const_i64(0); \
1021 gen_helper_ ## name (cpu_fir[rc], va, vb); \
1024 tcg_temp_free(va); \
1027 tcg_temp_free(vb); \
1031 /* ??? VAX instruction qualifiers ignored. */
1044 static void gen_ieee_arith3(DisasContext
*ctx
,
1045 void (*helper
)(TCGv
, TCGv
, TCGv
),
1046 int ra
, int rb
, int rc
, int fn11
)
1050 /* ??? This is wrong: the instruction is not a nop, it still may
1051 raise exceptions. */
1052 if (unlikely(rc
== 31)) {
1056 gen_qual_roundmode(ctx
, fn11
);
1057 gen_qual_flushzero(ctx
, fn11
);
1060 va
= gen_ieee_input(ra
, fn11
, 0);
1061 vb
= gen_ieee_input(rb
, fn11
, 0);
1062 helper(cpu_fir
[rc
], va
, vb
);
1066 gen_fp_exc_raise(rc
, fn11
);
1069 #define IEEE_ARITH3(name) \
1070 static inline void glue(gen_f, name)(DisasContext *ctx, \
1071 int ra, int rb, int rc, int fn11) \
1073 gen_ieee_arith3(ctx, gen_helper_##name, ra, rb, rc, fn11); \
1084 static void gen_ieee_compare(DisasContext
*ctx
,
1085 void (*helper
)(TCGv
, TCGv
, TCGv
),
1086 int ra
, int rb
, int rc
, int fn11
)
1090 /* ??? This is wrong: the instruction is not a nop, it still may
1091 raise exceptions. */
1092 if (unlikely(rc
== 31)) {
1098 va
= gen_ieee_input(ra
, fn11
, 1);
1099 vb
= gen_ieee_input(rb
, fn11
, 1);
1100 helper(cpu_fir
[rc
], va
, vb
);
1104 gen_fp_exc_raise(rc
, fn11
);
1107 #define IEEE_CMP3(name) \
1108 static inline void glue(gen_f, name)(DisasContext *ctx, \
1109 int ra, int rb, int rc, int fn11) \
1111 gen_ieee_compare(ctx, gen_helper_##name, ra, rb, rc, fn11); \
1118 static inline uint64_t zapnot_mask(uint8_t lit
)
1123 for (i
= 0; i
< 8; ++i
) {
1125 mask
|= 0xffull
<< (i
* 8);
1130 /* Implement zapnot with an immediate operand, which expands to some
1131 form of immediate AND. This is a basic building block in the
1132 definition of many of the other byte manipulation instructions. */
1133 static void gen_zapnoti(TCGv dest
, TCGv src
, uint8_t lit
)
1137 tcg_gen_movi_i64(dest
, 0);
1140 tcg_gen_ext8u_i64(dest
, src
);
1143 tcg_gen_ext16u_i64(dest
, src
);
1146 tcg_gen_ext32u_i64(dest
, src
);
1149 tcg_gen_mov_i64(dest
, src
);
1152 tcg_gen_andi_i64 (dest
, src
, zapnot_mask (lit
));
1157 static inline void gen_zapnot(int ra
, int rb
, int rc
, int islit
, uint8_t lit
)
1159 if (unlikely(rc
== 31))
1161 else if (unlikely(ra
== 31))
1162 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1164 gen_zapnoti(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1166 gen_helper_zapnot (cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1169 static inline void gen_zap(int ra
, int rb
, int rc
, int islit
, uint8_t lit
)
1171 if (unlikely(rc
== 31))
1173 else if (unlikely(ra
== 31))
1174 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1176 gen_zapnoti(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1178 gen_helper_zap (cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1182 /* EXTWH, EXTLH, EXTQH */
1183 static void gen_ext_h(int ra
, int rb
, int rc
, int islit
,
1184 uint8_t lit
, uint8_t byte_mask
)
1186 if (unlikely(rc
== 31))
1188 else if (unlikely(ra
== 31))
1189 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1192 lit
= (64 - (lit
& 7) * 8) & 0x3f;
1193 tcg_gen_shli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1195 TCGv tmp1
= tcg_temp_new();
1196 tcg_gen_andi_i64(tmp1
, cpu_ir
[rb
], 7);
1197 tcg_gen_shli_i64(tmp1
, tmp1
, 3);
1198 tcg_gen_neg_i64(tmp1
, tmp1
);
1199 tcg_gen_andi_i64(tmp1
, tmp1
, 0x3f);
1200 tcg_gen_shl_i64(cpu_ir
[rc
], cpu_ir
[ra
], tmp1
);
1201 tcg_temp_free(tmp1
);
1203 gen_zapnoti(cpu_ir
[rc
], cpu_ir
[rc
], byte_mask
);
1207 /* EXTBL, EXTWL, EXTLL, EXTQL */
1208 static void gen_ext_l(int ra
, int rb
, int rc
, int islit
,
1209 uint8_t lit
, uint8_t byte_mask
)
1211 if (unlikely(rc
== 31))
1213 else if (unlikely(ra
== 31))
1214 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1217 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[ra
], (lit
& 7) * 8);
1219 TCGv tmp
= tcg_temp_new();
1220 tcg_gen_andi_i64(tmp
, cpu_ir
[rb
], 7);
1221 tcg_gen_shli_i64(tmp
, tmp
, 3);
1222 tcg_gen_shr_i64(cpu_ir
[rc
], cpu_ir
[ra
], tmp
);
1225 gen_zapnoti(cpu_ir
[rc
], cpu_ir
[rc
], byte_mask
);
1229 /* INSWH, INSLH, INSQH */
1230 static void gen_ins_h(int ra
, int rb
, int rc
, int islit
,
1231 uint8_t lit
, uint8_t byte_mask
)
1233 if (unlikely(rc
== 31))
1235 else if (unlikely(ra
== 31) || (islit
&& (lit
& 7) == 0))
1236 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1238 TCGv tmp
= tcg_temp_new();
1240 /* The instruction description has us left-shift the byte mask
1241 and extract bits <15:8> and apply that zap at the end. This
1242 is equivalent to simply performing the zap first and shifting
1244 gen_zapnoti (tmp
, cpu_ir
[ra
], byte_mask
);
1247 /* Note that we have handled the lit==0 case above. */
1248 tcg_gen_shri_i64 (cpu_ir
[rc
], tmp
, 64 - (lit
& 7) * 8);
1250 TCGv shift
= tcg_temp_new();
1252 /* If (B & 7) == 0, we need to shift by 64 and leave a zero.
1253 Do this portably by splitting the shift into two parts:
1254 shift_count-1 and 1. Arrange for the -1 by using
1255 ones-complement instead of twos-complement in the negation:
1256 ~((B & 7) * 8) & 63. */
1258 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 7);
1259 tcg_gen_shli_i64(shift
, shift
, 3);
1260 tcg_gen_not_i64(shift
, shift
);
1261 tcg_gen_andi_i64(shift
, shift
, 0x3f);
1263 tcg_gen_shr_i64(cpu_ir
[rc
], tmp
, shift
);
1264 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[rc
], 1);
1265 tcg_temp_free(shift
);
1271 /* INSBL, INSWL, INSLL, INSQL */
1272 static void gen_ins_l(int ra
, int rb
, int rc
, int islit
,
1273 uint8_t lit
, uint8_t byte_mask
)
1275 if (unlikely(rc
== 31))
1277 else if (unlikely(ra
== 31))
1278 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1280 TCGv tmp
= tcg_temp_new();
1282 /* The instruction description has us left-shift the byte mask
1283 the same number of byte slots as the data and apply the zap
1284 at the end. This is equivalent to simply performing the zap
1285 first and shifting afterward. */
1286 gen_zapnoti (tmp
, cpu_ir
[ra
], byte_mask
);
1289 tcg_gen_shli_i64(cpu_ir
[rc
], tmp
, (lit
& 7) * 8);
1291 TCGv shift
= tcg_temp_new();
1292 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 7);
1293 tcg_gen_shli_i64(shift
, shift
, 3);
1294 tcg_gen_shl_i64(cpu_ir
[rc
], tmp
, shift
);
1295 tcg_temp_free(shift
);
1301 /* MSKWH, MSKLH, MSKQH */
1302 static void gen_msk_h(int ra
, int rb
, int rc
, int islit
,
1303 uint8_t lit
, uint8_t byte_mask
)
1305 if (unlikely(rc
== 31))
1307 else if (unlikely(ra
== 31))
1308 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1310 gen_zapnoti (cpu_ir
[rc
], cpu_ir
[ra
], ~((byte_mask
<< (lit
& 7)) >> 8));
1312 TCGv shift
= tcg_temp_new();
1313 TCGv mask
= tcg_temp_new();
1315 /* The instruction description is as above, where the byte_mask
1316 is shifted left, and then we extract bits <15:8>. This can be
1317 emulated with a right-shift on the expanded byte mask. This
1318 requires extra care because for an input <2:0> == 0 we need a
1319 shift of 64 bits in order to generate a zero. This is done by
1320 splitting the shift into two parts, the variable shift - 1
1321 followed by a constant 1 shift. The code we expand below is
1322 equivalent to ~((B & 7) * 8) & 63. */
1324 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 7);
1325 tcg_gen_shli_i64(shift
, shift
, 3);
1326 tcg_gen_not_i64(shift
, shift
);
1327 tcg_gen_andi_i64(shift
, shift
, 0x3f);
1328 tcg_gen_movi_i64(mask
, zapnot_mask (byte_mask
));
1329 tcg_gen_shr_i64(mask
, mask
, shift
);
1330 tcg_gen_shri_i64(mask
, mask
, 1);
1332 tcg_gen_andc_i64(cpu_ir
[rc
], cpu_ir
[ra
], mask
);
1334 tcg_temp_free(mask
);
1335 tcg_temp_free(shift
);
1339 /* MSKBL, MSKWL, MSKLL, MSKQL */
1340 static void gen_msk_l(int ra
, int rb
, int rc
, int islit
,
1341 uint8_t lit
, uint8_t byte_mask
)
1343 if (unlikely(rc
== 31))
1345 else if (unlikely(ra
== 31))
1346 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1348 gen_zapnoti (cpu_ir
[rc
], cpu_ir
[ra
], ~(byte_mask
<< (lit
& 7)));
1350 TCGv shift
= tcg_temp_new();
1351 TCGv mask
= tcg_temp_new();
1353 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 7);
1354 tcg_gen_shli_i64(shift
, shift
, 3);
1355 tcg_gen_movi_i64(mask
, zapnot_mask (byte_mask
));
1356 tcg_gen_shl_i64(mask
, mask
, shift
);
1358 tcg_gen_andc_i64(cpu_ir
[rc
], cpu_ir
[ra
], mask
);
1360 tcg_temp_free(mask
);
1361 tcg_temp_free(shift
);
1365 /* Code to call arith3 helpers */
1366 #define ARITH3(name) \
1367 static inline void glue(gen_, name)(int ra, int rb, int rc, int islit,\
1370 if (unlikely(rc == 31)) \
1375 TCGv tmp = tcg_const_i64(lit); \
1376 gen_helper_ ## name(cpu_ir[rc], cpu_ir[ra], tmp); \
1377 tcg_temp_free(tmp); \
1379 gen_helper_ ## name (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]); \
1381 TCGv tmp1 = tcg_const_i64(0); \
1383 TCGv tmp2 = tcg_const_i64(lit); \
1384 gen_helper_ ## name (cpu_ir[rc], tmp1, tmp2); \
1385 tcg_temp_free(tmp2); \
1387 gen_helper_ ## name (cpu_ir[rc], tmp1, cpu_ir[rb]); \
1388 tcg_temp_free(tmp1); \
1409 #define MVIOP2(name) \
1410 static inline void glue(gen_, name)(int rb, int rc) \
1412 if (unlikely(rc == 31)) \
1414 if (unlikely(rb == 31)) \
1415 tcg_gen_movi_i64(cpu_ir[rc], 0); \
1417 gen_helper_ ## name (cpu_ir[rc], cpu_ir[rb]); \
1424 static void gen_cmp(TCGCond cond
, int ra
, int rb
, int rc
,
1425 int islit
, uint8_t lit
)
1429 if (unlikely(rc
== 31)) {
1434 va
= tcg_const_i64(0);
1439 vb
= tcg_const_i64(lit
);
1444 tcg_gen_setcond_i64(cond
, cpu_ir
[rc
], va
, vb
);
1454 static void gen_rx(int ra
, int set
)
1459 tcg_gen_ld8u_i64(cpu_ir
[ra
], cpu_env
, offsetof(CPUState
, intr_flag
));
1462 tmp
= tcg_const_i32(set
);
1463 tcg_gen_st8_i32(tmp
, cpu_env
, offsetof(CPUState
, intr_flag
));
1464 tcg_temp_free_i32(tmp
);
1467 static ExitStatus
translate_one(DisasContext
*ctx
, uint32_t insn
)
1470 int32_t disp21
, disp16
, disp12
;
1472 uint8_t opc
, ra
, rb
, rc
, fpfn
, fn7
, fn2
, islit
, real_islit
;
1476 /* Decode all instruction fields */
1478 ra
= (insn
>> 21) & 0x1F;
1479 rb
= (insn
>> 16) & 0x1F;
1481 real_islit
= islit
= (insn
>> 12) & 1;
1482 if (rb
== 31 && !islit
) {
1486 lit
= (insn
>> 13) & 0xFF;
1487 palcode
= insn
& 0x03FFFFFF;
1488 disp21
= ((int32_t)((insn
& 0x001FFFFF) << 11)) >> 11;
1489 disp16
= (int16_t)(insn
& 0x0000FFFF);
1490 disp12
= (int32_t)((insn
& 0x00000FFF) << 20) >> 20;
1491 fn11
= (insn
>> 5) & 0x000007FF;
1493 fn7
= (insn
>> 5) & 0x0000007F;
1494 fn2
= (insn
>> 5) & 0x00000003;
1495 LOG_DISAS("opc %02x ra %2d rb %2d rc %2d disp16 %6d\n",
1496 opc
, ra
, rb
, rc
, disp16
);
1502 #ifdef CONFIG_USER_ONLY
1503 if (palcode
== 0x9E) {
1505 tcg_gen_mov_i64(cpu_ir
[IR_V0
], cpu_uniq
);
1507 } else if (palcode
== 0x9F) {
1509 tcg_gen_mov_i64(cpu_uniq
, cpu_ir
[IR_A0
]);
1513 if (palcode
>= 0x80 && palcode
< 0xC0) {
1514 /* Unprivileged PAL call */
1515 ret
= gen_excp(ctx
, EXCP_CALL_PAL
+ ((palcode
& 0x3F) << 6), 0);
1518 #ifndef CONFIG_USER_ONLY
1519 if (palcode
< 0x40) {
1520 /* Privileged PAL code */
1521 if (ctx
->mem_idx
& 1)
1523 ret
= gen_excp(ctx
, EXCP_CALL_PALP
+ ((palcode
& 0x3F) << 6), 0);
1526 /* Invalid PAL call */
1551 if (likely(ra
!= 31)) {
1553 tcg_gen_addi_i64(cpu_ir
[ra
], cpu_ir
[rb
], disp16
);
1555 tcg_gen_movi_i64(cpu_ir
[ra
], disp16
);
1560 if (likely(ra
!= 31)) {
1562 tcg_gen_addi_i64(cpu_ir
[ra
], cpu_ir
[rb
], disp16
<< 16);
1564 tcg_gen_movi_i64(cpu_ir
[ra
], disp16
<< 16);
1569 if (!(ctx
->amask
& AMASK_BWX
))
1571 gen_load_mem(ctx
, &tcg_gen_qemu_ld8u
, ra
, rb
, disp16
, 0, 0);
1575 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 0, 1);
1579 if (!(ctx
->amask
& AMASK_BWX
))
1581 gen_load_mem(ctx
, &tcg_gen_qemu_ld16u
, ra
, rb
, disp16
, 0, 0);
1585 gen_store_mem(ctx
, &tcg_gen_qemu_st16
, ra
, rb
, disp16
, 0, 0);
1589 gen_store_mem(ctx
, &tcg_gen_qemu_st8
, ra
, rb
, disp16
, 0, 0);
1593 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 0, 1);
1599 if (likely(rc
!= 31)) {
1602 tcg_gen_addi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1603 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1605 tcg_gen_add_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1606 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1610 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1612 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1618 if (likely(rc
!= 31)) {
1620 TCGv tmp
= tcg_temp_new();
1621 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1623 tcg_gen_addi_i64(tmp
, tmp
, lit
);
1625 tcg_gen_add_i64(tmp
, tmp
, cpu_ir
[rb
]);
1626 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
1630 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1632 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1638 if (likely(rc
!= 31)) {
1641 tcg_gen_subi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1643 tcg_gen_sub_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1644 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1647 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1649 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1650 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1656 if (likely(rc
!= 31)) {
1658 TCGv tmp
= tcg_temp_new();
1659 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1661 tcg_gen_subi_i64(tmp
, tmp
, lit
);
1663 tcg_gen_sub_i64(tmp
, tmp
, cpu_ir
[rb
]);
1664 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
1668 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1670 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1671 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1678 gen_cmpbge(ra
, rb
, rc
, islit
, lit
);
1682 if (likely(rc
!= 31)) {
1684 TCGv tmp
= tcg_temp_new();
1685 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1687 tcg_gen_addi_i64(tmp
, tmp
, lit
);
1689 tcg_gen_add_i64(tmp
, tmp
, cpu_ir
[rb
]);
1690 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
1694 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1696 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1702 if (likely(rc
!= 31)) {
1704 TCGv tmp
= tcg_temp_new();
1705 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1707 tcg_gen_subi_i64(tmp
, tmp
, lit
);
1709 tcg_gen_sub_i64(tmp
, tmp
, cpu_ir
[rb
]);
1710 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
1714 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1716 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1717 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1724 gen_cmp(TCG_COND_LTU
, ra
, rb
, rc
, islit
, lit
);
1728 if (likely(rc
!= 31)) {
1731 tcg_gen_addi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1733 tcg_gen_add_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1736 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1738 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1744 if (likely(rc
!= 31)) {
1746 TCGv tmp
= tcg_temp_new();
1747 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1749 tcg_gen_addi_i64(cpu_ir
[rc
], tmp
, lit
);
1751 tcg_gen_add_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1755 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1757 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1763 if (likely(rc
!= 31)) {
1766 tcg_gen_subi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1768 tcg_gen_sub_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1771 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1773 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1779 if (likely(rc
!= 31)) {
1781 TCGv tmp
= tcg_temp_new();
1782 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1784 tcg_gen_subi_i64(cpu_ir
[rc
], tmp
, lit
);
1786 tcg_gen_sub_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1790 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1792 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1798 gen_cmp(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
);
1802 if (likely(rc
!= 31)) {
1804 TCGv tmp
= tcg_temp_new();
1805 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1807 tcg_gen_addi_i64(cpu_ir
[rc
], tmp
, lit
);
1809 tcg_gen_add_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1813 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1815 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1821 if (likely(rc
!= 31)) {
1823 TCGv tmp
= tcg_temp_new();
1824 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1826 tcg_gen_subi_i64(cpu_ir
[rc
], tmp
, lit
);
1828 tcg_gen_sub_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1832 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1834 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1840 gen_cmp(TCG_COND_LEU
, ra
, rb
, rc
, islit
, lit
);
1844 gen_addlv(ra
, rb
, rc
, islit
, lit
);
1848 gen_sublv(ra
, rb
, rc
, islit
, lit
);
1852 gen_cmp(TCG_COND_LT
, ra
, rb
, rc
, islit
, lit
);
1856 gen_addqv(ra
, rb
, rc
, islit
, lit
);
1860 gen_subqv(ra
, rb
, rc
, islit
, lit
);
1864 gen_cmp(TCG_COND_LE
, ra
, rb
, rc
, islit
, lit
);
1874 if (likely(rc
!= 31)) {
1876 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1878 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1880 tcg_gen_and_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1885 if (likely(rc
!= 31)) {
1888 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1890 tcg_gen_andc_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1892 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1897 gen_cmov(TCG_COND_NE
, ra
, rb
, rc
, islit
, lit
, 1);
1901 gen_cmov(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
, 1);
1905 if (likely(rc
!= 31)) {
1908 tcg_gen_ori_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1910 tcg_gen_or_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1913 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1915 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1921 gen_cmov(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
, 0);
1925 gen_cmov(TCG_COND_NE
, ra
, rb
, rc
, islit
, lit
, 0);
1929 if (likely(rc
!= 31)) {
1932 tcg_gen_ori_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1934 tcg_gen_orc_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1937 tcg_gen_movi_i64(cpu_ir
[rc
], ~lit
);
1939 tcg_gen_not_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1945 if (likely(rc
!= 31)) {
1948 tcg_gen_xori_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1950 tcg_gen_xor_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1953 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1955 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1961 gen_cmov(TCG_COND_LT
, ra
, rb
, rc
, islit
, lit
, 0);
1965 gen_cmov(TCG_COND_GE
, ra
, rb
, rc
, islit
, lit
, 0);
1969 if (likely(rc
!= 31)) {
1972 tcg_gen_xori_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1974 tcg_gen_eqv_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1977 tcg_gen_movi_i64(cpu_ir
[rc
], ~lit
);
1979 tcg_gen_not_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1985 if (likely(rc
!= 31)) {
1987 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1989 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1990 switch (ctx
->env
->implver
) {
1992 /* EV4, EV45, LCA, LCA45 & EV5 */
1997 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[rc
],
1998 ~(uint64_t)ctx
->amask
);
2005 gen_cmov(TCG_COND_LE
, ra
, rb
, rc
, islit
, lit
, 0);
2009 gen_cmov(TCG_COND_GT
, ra
, rb
, rc
, islit
, lit
, 0);
2014 tcg_gen_movi_i64(cpu_ir
[rc
], ctx
->env
->implver
);
2024 gen_msk_l(ra
, rb
, rc
, islit
, lit
, 0x01);
2028 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x01);
2032 gen_ins_l(ra
, rb
, rc
, islit
, lit
, 0x01);
2036 gen_msk_l(ra
, rb
, rc
, islit
, lit
, 0x03);
2040 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x03);
2044 gen_ins_l(ra
, rb
, rc
, islit
, lit
, 0x03);
2048 gen_msk_l(ra
, rb
, rc
, islit
, lit
, 0x0f);
2052 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x0f);
2056 gen_ins_l(ra
, rb
, rc
, islit
, lit
, 0x0f);
2060 gen_zap(ra
, rb
, rc
, islit
, lit
);
2064 gen_zapnot(ra
, rb
, rc
, islit
, lit
);
2068 gen_msk_l(ra
, rb
, rc
, islit
, lit
, 0xff);
2072 if (likely(rc
!= 31)) {
2075 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
2077 TCGv shift
= tcg_temp_new();
2078 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
2079 tcg_gen_shr_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
2080 tcg_temp_free(shift
);
2083 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2088 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0xff);
2092 if (likely(rc
!= 31)) {
2095 tcg_gen_shli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
2097 TCGv shift
= tcg_temp_new();
2098 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
2099 tcg_gen_shl_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
2100 tcg_temp_free(shift
);
2103 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2108 gen_ins_l(ra
, rb
, rc
, islit
, lit
, 0xff);
2112 if (likely(rc
!= 31)) {
2115 tcg_gen_sari_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
2117 TCGv shift
= tcg_temp_new();
2118 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
2119 tcg_gen_sar_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
2120 tcg_temp_free(shift
);
2123 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2128 gen_msk_h(ra
, rb
, rc
, islit
, lit
, 0x03);
2132 gen_ins_h(ra
, rb
, rc
, islit
, lit
, 0x03);
2136 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0x03);
2140 gen_msk_h(ra
, rb
, rc
, islit
, lit
, 0x0f);
2144 gen_ins_h(ra
, rb
, rc
, islit
, lit
, 0x0f);
2148 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0x0f);
2152 gen_msk_h(ra
, rb
, rc
, islit
, lit
, 0xff);
2156 gen_ins_h(ra
, rb
, rc
, islit
, lit
, 0xff);
2160 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0xff);
2170 if (likely(rc
!= 31)) {
2172 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2175 tcg_gen_muli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
2177 tcg_gen_mul_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
2178 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
2184 if (likely(rc
!= 31)) {
2186 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2188 tcg_gen_muli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
2190 tcg_gen_mul_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
2195 gen_umulh(ra
, rb
, rc
, islit
, lit
);
2199 gen_mullv(ra
, rb
, rc
, islit
, lit
);
2203 gen_mulqv(ra
, rb
, rc
, islit
, lit
);
2210 switch (fpfn
) { /* fn11 & 0x3F */
2213 if (!(ctx
->amask
& AMASK_FIX
))
2215 if (likely(rc
!= 31)) {
2217 TCGv_i32 tmp
= tcg_temp_new_i32();
2218 tcg_gen_trunc_i64_i32(tmp
, cpu_ir
[ra
]);
2219 gen_helper_memory_to_s(cpu_fir
[rc
], tmp
);
2220 tcg_temp_free_i32(tmp
);
2222 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
2227 if (!(ctx
->amask
& AMASK_FIX
))
2233 if (!(ctx
->amask
& AMASK_FIX
))
2235 gen_fsqrts(ctx
, rb
, rc
, fn11
);
2239 if (!(ctx
->amask
& AMASK_FIX
))
2241 if (likely(rc
!= 31)) {
2243 TCGv_i32 tmp
= tcg_temp_new_i32();
2244 tcg_gen_trunc_i64_i32(tmp
, cpu_ir
[ra
]);
2245 gen_helper_memory_to_f(cpu_fir
[rc
], tmp
);
2246 tcg_temp_free_i32(tmp
);
2248 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
2253 if (!(ctx
->amask
& AMASK_FIX
))
2255 if (likely(rc
!= 31)) {
2257 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_ir
[ra
]);
2259 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
2264 if (!(ctx
->amask
& AMASK_FIX
))
2270 if (!(ctx
->amask
& AMASK_FIX
))
2272 gen_fsqrtt(ctx
, rb
, rc
, fn11
);
2279 /* VAX floating point */
2280 /* XXX: rounding mode and trap are ignored (!) */
2281 switch (fpfn
) { /* fn11 & 0x3F */
2284 gen_faddf(ra
, rb
, rc
);
2288 gen_fsubf(ra
, rb
, rc
);
2292 gen_fmulf(ra
, rb
, rc
);
2296 gen_fdivf(ra
, rb
, rc
);
2308 gen_faddg(ra
, rb
, rc
);
2312 gen_fsubg(ra
, rb
, rc
);
2316 gen_fmulg(ra
, rb
, rc
);
2320 gen_fdivg(ra
, rb
, rc
);
2324 gen_fcmpgeq(ra
, rb
, rc
);
2328 gen_fcmpglt(ra
, rb
, rc
);
2332 gen_fcmpgle(ra
, rb
, rc
);
2363 /* IEEE floating-point */
2364 switch (fpfn
) { /* fn11 & 0x3F */
2367 gen_fadds(ctx
, ra
, rb
, rc
, fn11
);
2371 gen_fsubs(ctx
, ra
, rb
, rc
, fn11
);
2375 gen_fmuls(ctx
, ra
, rb
, rc
, fn11
);
2379 gen_fdivs(ctx
, ra
, rb
, rc
, fn11
);
2383 gen_faddt(ctx
, ra
, rb
, rc
, fn11
);
2387 gen_fsubt(ctx
, ra
, rb
, rc
, fn11
);
2391 gen_fmult(ctx
, ra
, rb
, rc
, fn11
);
2395 gen_fdivt(ctx
, ra
, rb
, rc
, fn11
);
2399 gen_fcmptun(ctx
, ra
, rb
, rc
, fn11
);
2403 gen_fcmpteq(ctx
, ra
, rb
, rc
, fn11
);
2407 gen_fcmptlt(ctx
, ra
, rb
, rc
, fn11
);
2411 gen_fcmptle(ctx
, ra
, rb
, rc
, fn11
);
2414 if (fn11
== 0x2AC || fn11
== 0x6AC) {
2416 gen_fcvtst(ctx
, rb
, rc
, fn11
);
2419 gen_fcvtts(ctx
, rb
, rc
, fn11
);
2424 gen_fcvttq(ctx
, rb
, rc
, fn11
);
2428 gen_fcvtqs(ctx
, rb
, rc
, fn11
);
2432 gen_fcvtqt(ctx
, rb
, rc
, fn11
);
2445 if (likely(rc
!= 31)) {
2449 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
2451 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_fir
[ra
]);
2454 gen_fcpys(ra
, rb
, rc
);
2460 gen_fcpysn(ra
, rb
, rc
);
2464 gen_fcpyse(ra
, rb
, rc
);
2468 if (likely(ra
!= 31))
2469 gen_helper_store_fpcr(cpu_fir
[ra
]);
2471 TCGv tmp
= tcg_const_i64(0);
2472 gen_helper_store_fpcr(tmp
);
2478 if (likely(ra
!= 31))
2479 gen_helper_load_fpcr(cpu_fir
[ra
]);
2483 gen_fcmov(TCG_COND_EQ
, ra
, rb
, rc
);
2487 gen_fcmov(TCG_COND_NE
, ra
, rb
, rc
);
2491 gen_fcmov(TCG_COND_LT
, ra
, rb
, rc
);
2495 gen_fcmov(TCG_COND_GE
, ra
, rb
, rc
);
2499 gen_fcmov(TCG_COND_LE
, ra
, rb
, rc
);
2503 gen_fcmov(TCG_COND_GT
, ra
, rb
, rc
);
2513 /* ??? I'm pretty sure there's nothing that /sv needs to do that
2514 /v doesn't do. The only thing I can think is that /sv is a
2515 valid instruction merely for completeness in the ISA. */
2516 gen_fcvtql_v(ctx
, rb
, rc
);
2523 switch ((uint16_t)disp16
) {
2551 gen_helper_load_pcc(cpu_ir
[ra
]);
2573 /* HW_MFPR (PALcode) */
2574 #if defined (CONFIG_USER_ONLY)
2580 TCGv tmp
= tcg_const_i32(insn
& 0xFF);
2581 gen_helper_mfpr(cpu_ir
[ra
], tmp
, cpu_ir
[ra
]);
2587 /* JMP, JSR, RET, JSR_COROUTINE. These only differ by the branch
2588 prediction stack action, which of course we don't implement. */
2590 tcg_gen_andi_i64(cpu_pc
, cpu_ir
[rb
], ~3);
2592 tcg_gen_movi_i64(cpu_pc
, 0);
2595 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
2597 ret
= EXIT_PC_UPDATED
;
2600 /* HW_LD (PALcode) */
2601 #if defined (CONFIG_USER_ONLY)
2607 TCGv addr
= tcg_temp_new();
2609 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp12
);
2611 tcg_gen_movi_i64(addr
, disp12
);
2612 switch ((insn
>> 12) & 0xF) {
2614 /* Longword physical access (hw_ldl/p) */
2615 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
2618 /* Quadword physical access (hw_ldq/p) */
2619 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
2622 /* Longword physical access with lock (hw_ldl_l/p) */
2623 gen_helper_ldl_l_raw(cpu_ir
[ra
], addr
);
2626 /* Quadword physical access with lock (hw_ldq_l/p) */
2627 gen_helper_ldq_l_raw(cpu_ir
[ra
], addr
);
2630 /* Longword virtual PTE fetch (hw_ldl/v) */
2631 tcg_gen_qemu_ld32s(cpu_ir
[ra
], addr
, 0);
2634 /* Quadword virtual PTE fetch (hw_ldq/v) */
2635 tcg_gen_qemu_ld64(cpu_ir
[ra
], addr
, 0);
2638 /* Incpu_ir[ra]id */
2641 /* Incpu_ir[ra]id */
2644 /* Longword virtual access (hw_ldl) */
2645 gen_helper_st_virt_to_phys(addr
, addr
);
2646 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
2649 /* Quadword virtual access (hw_ldq) */
2650 gen_helper_st_virt_to_phys(addr
, addr
);
2651 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
2654 /* Longword virtual access with protection check (hw_ldl/w) */
2655 tcg_gen_qemu_ld32s(cpu_ir
[ra
], addr
, 0);
2658 /* Quadword virtual access with protection check (hw_ldq/w) */
2659 tcg_gen_qemu_ld64(cpu_ir
[ra
], addr
, 0);
2662 /* Longword virtual access with alt access mode (hw_ldl/a)*/
2663 gen_helper_set_alt_mode();
2664 gen_helper_st_virt_to_phys(addr
, addr
);
2665 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
2666 gen_helper_restore_mode();
2669 /* Quadword virtual access with alt access mode (hw_ldq/a) */
2670 gen_helper_set_alt_mode();
2671 gen_helper_st_virt_to_phys(addr
, addr
);
2672 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
2673 gen_helper_restore_mode();
2676 /* Longword virtual access with alternate access mode and
2677 * protection checks (hw_ldl/wa)
2679 gen_helper_set_alt_mode();
2680 gen_helper_ldl_data(cpu_ir
[ra
], addr
);
2681 gen_helper_restore_mode();
2684 /* Quadword virtual access with alternate access mode and
2685 * protection checks (hw_ldq/wa)
2687 gen_helper_set_alt_mode();
2688 gen_helper_ldq_data(cpu_ir
[ra
], addr
);
2689 gen_helper_restore_mode();
2692 tcg_temp_free(addr
);
2700 if (!(ctx
->amask
& AMASK_BWX
))
2702 if (likely(rc
!= 31)) {
2704 tcg_gen_movi_i64(cpu_ir
[rc
], (int64_t)((int8_t)lit
));
2706 tcg_gen_ext8s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
2711 if (!(ctx
->amask
& AMASK_BWX
))
2713 if (likely(rc
!= 31)) {
2715 tcg_gen_movi_i64(cpu_ir
[rc
], (int64_t)((int16_t)lit
));
2717 tcg_gen_ext16s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
2722 if (!(ctx
->amask
& AMASK_CIX
))
2724 if (likely(rc
!= 31)) {
2726 tcg_gen_movi_i64(cpu_ir
[rc
], ctpop64(lit
));
2728 gen_helper_ctpop(cpu_ir
[rc
], cpu_ir
[rb
]);
2733 if (!(ctx
->amask
& AMASK_MVI
))
2735 gen_perr(ra
, rb
, rc
, islit
, lit
);
2739 if (!(ctx
->amask
& AMASK_CIX
))
2741 if (likely(rc
!= 31)) {
2743 tcg_gen_movi_i64(cpu_ir
[rc
], clz64(lit
));
2745 gen_helper_ctlz(cpu_ir
[rc
], cpu_ir
[rb
]);
2750 if (!(ctx
->amask
& AMASK_CIX
))
2752 if (likely(rc
!= 31)) {
2754 tcg_gen_movi_i64(cpu_ir
[rc
], ctz64(lit
));
2756 gen_helper_cttz(cpu_ir
[rc
], cpu_ir
[rb
]);
2761 if (!(ctx
->amask
& AMASK_MVI
))
2763 if (real_islit
|| ra
!= 31)
2765 gen_unpkbw (rb
, rc
);
2769 if (!(ctx
->amask
& AMASK_MVI
))
2771 if (real_islit
|| ra
!= 31)
2773 gen_unpkbl (rb
, rc
);
2777 if (!(ctx
->amask
& AMASK_MVI
))
2779 if (real_islit
|| ra
!= 31)
2785 if (!(ctx
->amask
& AMASK_MVI
))
2787 if (real_islit
|| ra
!= 31)
2793 if (!(ctx
->amask
& AMASK_MVI
))
2795 gen_minsb8 (ra
, rb
, rc
, islit
, lit
);
2799 if (!(ctx
->amask
& AMASK_MVI
))
2801 gen_minsw4 (ra
, rb
, rc
, islit
, lit
);
2805 if (!(ctx
->amask
& AMASK_MVI
))
2807 gen_minub8 (ra
, rb
, rc
, islit
, lit
);
2811 if (!(ctx
->amask
& AMASK_MVI
))
2813 gen_minuw4 (ra
, rb
, rc
, islit
, lit
);
2817 if (!(ctx
->amask
& AMASK_MVI
))
2819 gen_maxub8 (ra
, rb
, rc
, islit
, lit
);
2823 if (!(ctx
->amask
& AMASK_MVI
))
2825 gen_maxuw4 (ra
, rb
, rc
, islit
, lit
);
2829 if (!(ctx
->amask
& AMASK_MVI
))
2831 gen_maxsb8 (ra
, rb
, rc
, islit
, lit
);
2835 if (!(ctx
->amask
& AMASK_MVI
))
2837 gen_maxsw4 (ra
, rb
, rc
, islit
, lit
);
2841 if (!(ctx
->amask
& AMASK_FIX
))
2843 if (likely(rc
!= 31)) {
2845 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_fir
[ra
]);
2847 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2852 if (!(ctx
->amask
& AMASK_FIX
))
2855 TCGv_i32 tmp1
= tcg_temp_new_i32();
2857 gen_helper_s_to_memory(tmp1
, cpu_fir
[ra
]);
2859 TCGv tmp2
= tcg_const_i64(0);
2860 gen_helper_s_to_memory(tmp1
, tmp2
);
2861 tcg_temp_free(tmp2
);
2863 tcg_gen_ext_i32_i64(cpu_ir
[rc
], tmp1
);
2864 tcg_temp_free_i32(tmp1
);
2872 /* HW_MTPR (PALcode) */
2873 #if defined (CONFIG_USER_ONLY)
2879 TCGv tmp1
= tcg_const_i32(insn
& 0xFF);
2881 gen_helper_mtpr(tmp1
, cpu_ir
[ra
]);
2883 TCGv tmp2
= tcg_const_i64(0);
2884 gen_helper_mtpr(tmp1
, tmp2
);
2885 tcg_temp_free(tmp2
);
2887 tcg_temp_free(tmp1
);
2888 ret
= EXIT_PC_STALE
;
2893 /* HW_REI (PALcode) */
2894 #if defined (CONFIG_USER_ONLY)
2901 gen_helper_hw_rei();
2906 tmp
= tcg_temp_new();
2907 tcg_gen_addi_i64(tmp
, cpu_ir
[rb
], (((int64_t)insn
<< 51) >> 51));
2909 tmp
= tcg_const_i64(((int64_t)insn
<< 51) >> 51);
2910 gen_helper_hw_ret(tmp
);
2913 ret
= EXIT_PC_UPDATED
;
2917 /* HW_ST (PALcode) */
2918 #if defined (CONFIG_USER_ONLY)
2925 addr
= tcg_temp_new();
2927 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp12
);
2929 tcg_gen_movi_i64(addr
, disp12
);
2933 val
= tcg_temp_new();
2934 tcg_gen_movi_i64(val
, 0);
2936 switch ((insn
>> 12) & 0xF) {
2938 /* Longword physical access */
2939 gen_helper_stl_raw(val
, addr
);
2942 /* Quadword physical access */
2943 gen_helper_stq_raw(val
, addr
);
2946 /* Longword physical access with lock */
2947 gen_helper_stl_c_raw(val
, val
, addr
);
2950 /* Quadword physical access with lock */
2951 gen_helper_stq_c_raw(val
, val
, addr
);
2954 /* Longword virtual access */
2955 gen_helper_st_virt_to_phys(addr
, addr
);
2956 gen_helper_stl_raw(val
, addr
);
2959 /* Quadword virtual access */
2960 gen_helper_st_virt_to_phys(addr
, addr
);
2961 gen_helper_stq_raw(val
, addr
);
2982 /* Longword virtual access with alternate access mode */
2983 gen_helper_set_alt_mode();
2984 gen_helper_st_virt_to_phys(addr
, addr
);
2985 gen_helper_stl_raw(val
, addr
);
2986 gen_helper_restore_mode();
2989 /* Quadword virtual access with alternate access mode */
2990 gen_helper_set_alt_mode();
2991 gen_helper_st_virt_to_phys(addr
, addr
);
2992 gen_helper_stl_raw(val
, addr
);
2993 gen_helper_restore_mode();
3004 tcg_temp_free(addr
);
3010 gen_load_mem(ctx
, &gen_qemu_ldf
, ra
, rb
, disp16
, 1, 0);
3014 gen_load_mem(ctx
, &gen_qemu_ldg
, ra
, rb
, disp16
, 1, 0);
3018 gen_load_mem(ctx
, &gen_qemu_lds
, ra
, rb
, disp16
, 1, 0);
3022 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 1, 0);
3026 gen_store_mem(ctx
, &gen_qemu_stf
, ra
, rb
, disp16
, 1, 0);
3030 gen_store_mem(ctx
, &gen_qemu_stg
, ra
, rb
, disp16
, 1, 0);
3034 gen_store_mem(ctx
, &gen_qemu_sts
, ra
, rb
, disp16
, 1, 0);
3038 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 1, 0);
3042 gen_load_mem(ctx
, &tcg_gen_qemu_ld32s
, ra
, rb
, disp16
, 0, 0);
3046 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 0, 0);
3050 gen_load_mem(ctx
, &gen_qemu_ldl_l
, ra
, rb
, disp16
, 0, 0);
3054 gen_load_mem(ctx
, &gen_qemu_ldq_l
, ra
, rb
, disp16
, 0, 0);
3058 gen_store_mem(ctx
, &tcg_gen_qemu_st32
, ra
, rb
, disp16
, 0, 0);
3062 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 0, 0);
3066 ret
= gen_store_conditional(ctx
, ra
, rb
, disp16
, 0);
3070 ret
= gen_store_conditional(ctx
, ra
, rb
, disp16
, 1);
3074 ret
= gen_bdirect(ctx
, ra
, disp21
);
3076 case 0x31: /* FBEQ */
3077 ret
= gen_fbcond(ctx
, TCG_COND_EQ
, ra
, disp21
);
3079 case 0x32: /* FBLT */
3080 ret
= gen_fbcond(ctx
, TCG_COND_LT
, ra
, disp21
);
3082 case 0x33: /* FBLE */
3083 ret
= gen_fbcond(ctx
, TCG_COND_LE
, ra
, disp21
);
3087 ret
= gen_bdirect(ctx
, ra
, disp21
);
3089 case 0x35: /* FBNE */
3090 ret
= gen_fbcond(ctx
, TCG_COND_NE
, ra
, disp21
);
3092 case 0x36: /* FBGE */
3093 ret
= gen_fbcond(ctx
, TCG_COND_GE
, ra
, disp21
);
3095 case 0x37: /* FBGT */
3096 ret
= gen_fbcond(ctx
, TCG_COND_GT
, ra
, disp21
);
3100 ret
= gen_bcond(ctx
, TCG_COND_EQ
, ra
, disp21
, 1);
3104 ret
= gen_bcond(ctx
, TCG_COND_EQ
, ra
, disp21
, 0);
3108 ret
= gen_bcond(ctx
, TCG_COND_LT
, ra
, disp21
, 0);
3112 ret
= gen_bcond(ctx
, TCG_COND_LE
, ra
, disp21
, 0);
3116 ret
= gen_bcond(ctx
, TCG_COND_NE
, ra
, disp21
, 1);
3120 ret
= gen_bcond(ctx
, TCG_COND_NE
, ra
, disp21
, 0);
3124 ret
= gen_bcond(ctx
, TCG_COND_GE
, ra
, disp21
, 0);
3128 ret
= gen_bcond(ctx
, TCG_COND_GT
, ra
, disp21
, 0);
3131 ret
= gen_invalid(ctx
);
3138 static inline void gen_intermediate_code_internal(CPUState
*env
,
3139 TranslationBlock
*tb
,
3142 DisasContext ctx
, *ctxp
= &ctx
;
3143 target_ulong pc_start
;
3145 uint16_t *gen_opc_end
;
3153 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
3158 ctx
.amask
= env
->amask
;
3159 #if defined (CONFIG_USER_ONLY)
3162 ctx
.mem_idx
= ((env
->ps
>> 3) & 3);
3163 ctx
.pal_mode
= env
->ipr
[IPR_EXC_ADDR
] & 1;
3166 /* ??? Every TB begins with unset rounding mode, to be initialized on
3167 the first fp insn of the TB. Alternately we could define a proper
3168 default for every TB (e.g. QUAL_RM_N or QUAL_RM_D) and make sure
3169 to reset the FP_STATUS to that default at the end of any TB that
3170 changes the default. We could even (gasp) dynamiclly figure out
3171 what default would be most efficient given the running program. */
3173 /* Similarly for flush-to-zero. */
3177 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3179 max_insns
= CF_COUNT_MASK
;
3183 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
3184 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
3185 if (bp
->pc
== ctx
.pc
) {
3186 gen_excp(&ctx
, EXCP_DEBUG
, 0);
3192 j
= gen_opc_ptr
- gen_opc_buf
;
3196 gen_opc_instr_start
[lj
++] = 0;
3198 gen_opc_pc
[lj
] = ctx
.pc
;
3199 gen_opc_instr_start
[lj
] = 1;
3200 gen_opc_icount
[lj
] = num_insns
;
3202 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
3204 insn
= ldl_code(ctx
.pc
);
3207 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
))) {
3208 tcg_gen_debug_insn_start(ctx
.pc
);
3212 ret
= translate_one(ctxp
, insn
);
3214 if (ret
== NO_EXIT
) {
3215 /* If we reach a page boundary, are single stepping,
3216 or exhaust instruction count, stop generation. */
3217 if (env
->singlestep_enabled
) {
3218 gen_excp(&ctx
, EXCP_DEBUG
, 0);
3219 ret
= EXIT_PC_UPDATED
;
3220 } else if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0
3221 || gen_opc_ptr
>= gen_opc_end
3222 || num_insns
>= max_insns
3224 ret
= EXIT_PC_STALE
;
3227 } while (ret
== NO_EXIT
);
3229 if (tb
->cflags
& CF_LAST_IO
) {
3238 tcg_gen_movi_i64(cpu_pc
, ctx
.pc
);
3240 case EXIT_PC_UPDATED
:
3247 gen_icount_end(tb
, num_insns
);
3248 *gen_opc_ptr
= INDEX_op_end
;
3250 j
= gen_opc_ptr
- gen_opc_buf
;
3253 gen_opc_instr_start
[lj
++] = 0;
3255 tb
->size
= ctx
.pc
- pc_start
;
3256 tb
->icount
= num_insns
;
3260 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3261 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3262 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 1);
3268 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
3270 gen_intermediate_code_internal(env
, tb
, 0);
3273 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
3275 gen_intermediate_code_internal(env
, tb
, 1);
3283 static const struct cpu_def_t cpu_defs
[] = {
3284 { "ev4", IMPLVER_2106x
, 0 },
3285 { "ev5", IMPLVER_21164
, 0 },
3286 { "ev56", IMPLVER_21164
, AMASK_BWX
},
3287 { "pca56", IMPLVER_21164
, AMASK_BWX
| AMASK_MVI
},
3288 { "ev6", IMPLVER_21264
, AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
},
3289 { "ev67", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
3290 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), },
3291 { "ev68", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
3292 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), },
3293 { "21064", IMPLVER_2106x
, 0 },
3294 { "21164", IMPLVER_21164
, 0 },
3295 { "21164a", IMPLVER_21164
, AMASK_BWX
},
3296 { "21164pc", IMPLVER_21164
, AMASK_BWX
| AMASK_MVI
},
3297 { "21264", IMPLVER_21264
, AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
},
3298 { "21264a", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
3299 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), }
3302 CPUAlphaState
* cpu_alpha_init (const char *cpu_model
)
3305 int implver
, amask
, i
, max
;
3307 env
= qemu_mallocz(sizeof(CPUAlphaState
));
3309 alpha_translate_init();
3312 /* Default to ev67; no reason not to emulate insns by default. */
3313 implver
= IMPLVER_21264
;
3314 amask
= (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
| AMASK_MVI
3315 | AMASK_TRAP
| AMASK_PREFETCH
);
3317 max
= ARRAY_SIZE(cpu_defs
);
3318 for (i
= 0; i
< max
; i
++) {
3319 if (strcmp (cpu_model
, cpu_defs
[i
].name
) == 0) {
3320 implver
= cpu_defs
[i
].implver
;
3321 amask
= cpu_defs
[i
].amask
;
3325 env
->implver
= implver
;
3329 #if defined (CONFIG_USER_ONLY)
3331 cpu_alpha_store_fpcr(env
, (FPCR_INVD
| FPCR_DZED
| FPCR_OVFD
3332 | FPCR_UNFD
| FPCR_INED
| FPCR_DNOD
));
3336 env
->lock_addr
= -1;
3338 /* Initialize IPR */
3339 #if defined (CONFIG_USER_ONLY)
3340 env
->ipr
[IPR_EXC_ADDR
] = 0;
3341 env
->ipr
[IPR_EXC_SUM
] = 0;
3342 env
->ipr
[IPR_EXC_MASK
] = 0;
3346 // hwpcb = env->ipr[IPR_PCBB];
3347 env
->ipr
[IPR_ASN
] = 0;
3348 env
->ipr
[IPR_ASTEN
] = 0;
3349 env
->ipr
[IPR_ASTSR
] = 0;
3350 env
->ipr
[IPR_DATFX
] = 0;
3352 // env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
3353 // env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
3354 // env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
3355 // env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
3356 env
->ipr
[IPR_FEN
] = 0;
3357 env
->ipr
[IPR_IPL
] = 31;
3358 env
->ipr
[IPR_MCES
] = 0;
3359 env
->ipr
[IPR_PERFMON
] = 0; /* Implementation specific */
3360 // env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
3361 env
->ipr
[IPR_SISR
] = 0;
3362 env
->ipr
[IPR_VIRBND
] = -1ULL;
3366 qemu_init_vcpu(env
);
3370 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
3371 unsigned long searched_pc
, int pc_pos
, void *puc
)
3373 env
->pc
= gen_opc_pc
[pc_pos
];