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
;
48 #if !defined (CONFIG_USER_ONLY)
54 /* Current rounding mode for this TB. */
56 /* Current flush-to-zero setting for this TB. */
60 /* global register indexes */
61 static TCGv_ptr cpu_env
;
62 static TCGv cpu_ir
[31];
63 static TCGv cpu_fir
[31];
66 #ifdef CONFIG_USER_ONLY
71 static char cpu_reg_names
[10*4+21*5 + 10*5+21*6];
73 #include "gen-icount.h"
75 static void alpha_translate_init(void)
79 static int done_init
= 0;
84 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
87 for (i
= 0; i
< 31; i
++) {
88 sprintf(p
, "ir%d", i
);
89 cpu_ir
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
90 offsetof(CPUState
, ir
[i
]), p
);
91 p
+= (i
< 10) ? 4 : 5;
93 sprintf(p
, "fir%d", i
);
94 cpu_fir
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
95 offsetof(CPUState
, fir
[i
]), p
);
96 p
+= (i
< 10) ? 5 : 6;
99 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
,
100 offsetof(CPUState
, pc
), "pc");
102 cpu_lock
= tcg_global_mem_new_i64(TCG_AREG0
,
103 offsetof(CPUState
, lock
), "lock");
105 #ifdef CONFIG_USER_ONLY
106 cpu_uniq
= tcg_global_mem_new_i64(TCG_AREG0
,
107 offsetof(CPUState
, unique
), "uniq");
110 /* register helpers */
117 static inline void gen_excp(DisasContext
*ctx
, int exception
, int error_code
)
121 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
);
122 tmp1
= tcg_const_i32(exception
);
123 tmp2
= tcg_const_i32(error_code
);
124 gen_helper_excp(tmp1
, tmp2
);
125 tcg_temp_free_i32(tmp2
);
126 tcg_temp_free_i32(tmp1
);
129 static inline void gen_invalid(DisasContext
*ctx
)
131 gen_excp(ctx
, EXCP_OPCDEC
, 0);
134 static inline void gen_qemu_ldf(TCGv t0
, TCGv t1
, int flags
)
136 TCGv tmp
= tcg_temp_new();
137 TCGv_i32 tmp32
= tcg_temp_new_i32();
138 tcg_gen_qemu_ld32u(tmp
, t1
, flags
);
139 tcg_gen_trunc_i64_i32(tmp32
, tmp
);
140 gen_helper_memory_to_f(t0
, tmp32
);
141 tcg_temp_free_i32(tmp32
);
145 static inline void gen_qemu_ldg(TCGv t0
, TCGv t1
, int flags
)
147 TCGv tmp
= tcg_temp_new();
148 tcg_gen_qemu_ld64(tmp
, t1
, flags
);
149 gen_helper_memory_to_g(t0
, tmp
);
153 static inline void gen_qemu_lds(TCGv t0
, TCGv t1
, int flags
)
155 TCGv tmp
= tcg_temp_new();
156 TCGv_i32 tmp32
= tcg_temp_new_i32();
157 tcg_gen_qemu_ld32u(tmp
, t1
, flags
);
158 tcg_gen_trunc_i64_i32(tmp32
, tmp
);
159 gen_helper_memory_to_s(t0
, tmp32
);
160 tcg_temp_free_i32(tmp32
);
164 static inline void gen_qemu_ldl_l(TCGv t0
, TCGv t1
, int flags
)
166 tcg_gen_mov_i64(cpu_lock
, t1
);
167 tcg_gen_qemu_ld32s(t0
, t1
, flags
);
170 static inline void gen_qemu_ldq_l(TCGv t0
, TCGv t1
, int flags
)
172 tcg_gen_mov_i64(cpu_lock
, t1
);
173 tcg_gen_qemu_ld64(t0
, t1
, flags
);
176 static inline void gen_load_mem(DisasContext
*ctx
,
177 void (*tcg_gen_qemu_load
)(TCGv t0
, TCGv t1
,
179 int ra
, int rb
, int32_t disp16
, int fp
,
184 if (unlikely(ra
== 31))
187 addr
= tcg_temp_new();
189 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp16
);
191 tcg_gen_andi_i64(addr
, addr
, ~0x7);
195 tcg_gen_movi_i64(addr
, disp16
);
198 tcg_gen_qemu_load(cpu_fir
[ra
], addr
, ctx
->mem_idx
);
200 tcg_gen_qemu_load(cpu_ir
[ra
], addr
, ctx
->mem_idx
);
204 static inline void gen_qemu_stf(TCGv t0
, TCGv t1
, int flags
)
206 TCGv_i32 tmp32
= tcg_temp_new_i32();
207 TCGv tmp
= tcg_temp_new();
208 gen_helper_f_to_memory(tmp32
, t0
);
209 tcg_gen_extu_i32_i64(tmp
, tmp32
);
210 tcg_gen_qemu_st32(tmp
, t1
, flags
);
212 tcg_temp_free_i32(tmp32
);
215 static inline void gen_qemu_stg(TCGv t0
, TCGv t1
, int flags
)
217 TCGv tmp
= tcg_temp_new();
218 gen_helper_g_to_memory(tmp
, t0
);
219 tcg_gen_qemu_st64(tmp
, t1
, flags
);
223 static inline void gen_qemu_sts(TCGv t0
, TCGv t1
, int flags
)
225 TCGv_i32 tmp32
= tcg_temp_new_i32();
226 TCGv tmp
= tcg_temp_new();
227 gen_helper_s_to_memory(tmp32
, t0
);
228 tcg_gen_extu_i32_i64(tmp
, tmp32
);
229 tcg_gen_qemu_st32(tmp
, t1
, flags
);
231 tcg_temp_free_i32(tmp32
);
234 static inline void gen_qemu_stl_c(TCGv t0
, TCGv t1
, int flags
)
238 l1
= gen_new_label();
239 l2
= gen_new_label();
240 tcg_gen_brcond_i64(TCG_COND_NE
, cpu_lock
, t1
, l1
);
241 tcg_gen_qemu_st32(t0
, t1
, flags
);
242 tcg_gen_movi_i64(t0
, 1);
245 tcg_gen_movi_i64(t0
, 0);
247 tcg_gen_movi_i64(cpu_lock
, -1);
250 static inline void gen_qemu_stq_c(TCGv t0
, TCGv t1
, int flags
)
254 l1
= gen_new_label();
255 l2
= gen_new_label();
256 tcg_gen_brcond_i64(TCG_COND_NE
, cpu_lock
, t1
, l1
);
257 tcg_gen_qemu_st64(t0
, t1
, flags
);
258 tcg_gen_movi_i64(t0
, 1);
261 tcg_gen_movi_i64(t0
, 0);
263 tcg_gen_movi_i64(cpu_lock
, -1);
266 static inline void gen_store_mem(DisasContext
*ctx
,
267 void (*tcg_gen_qemu_store
)(TCGv t0
, TCGv t1
,
269 int ra
, int rb
, int32_t disp16
, int fp
,
270 int clear
, int local
)
274 addr
= tcg_temp_local_new();
276 addr
= tcg_temp_new();
278 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp16
);
280 tcg_gen_andi_i64(addr
, addr
, ~0x7);
284 tcg_gen_movi_i64(addr
, disp16
);
288 tcg_gen_qemu_store(cpu_fir
[ra
], addr
, ctx
->mem_idx
);
290 tcg_gen_qemu_store(cpu_ir
[ra
], addr
, ctx
->mem_idx
);
294 zero
= tcg_const_local_i64(0);
296 zero
= tcg_const_i64(0);
297 tcg_gen_qemu_store(zero
, addr
, ctx
->mem_idx
);
303 static void gen_bcond_pcload(DisasContext
*ctx
, int32_t disp
, int lab_true
)
305 int lab_over
= gen_new_label();
307 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
);
308 tcg_gen_br(lab_over
);
309 gen_set_label(lab_true
);
310 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp
<< 2));
311 gen_set_label(lab_over
);
314 static void gen_bcond(DisasContext
*ctx
, TCGCond cond
, int ra
,
315 int32_t disp
, int mask
)
317 int lab_true
= gen_new_label();
319 if (likely(ra
!= 31)) {
321 TCGv tmp
= tcg_temp_new();
322 tcg_gen_andi_i64(tmp
, cpu_ir
[ra
], 1);
323 tcg_gen_brcondi_i64(cond
, tmp
, 0, lab_true
);
326 tcg_gen_brcondi_i64(cond
, cpu_ir
[ra
], 0, lab_true
);
329 /* Very uncommon case - Do not bother to optimize. */
330 TCGv tmp
= tcg_const_i64(0);
331 tcg_gen_brcondi_i64(cond
, tmp
, 0, lab_true
);
334 gen_bcond_pcload(ctx
, disp
, lab_true
);
337 /* Generate a forward TCG branch to LAB_TRUE if RA cmp 0.0.
338 This is complicated by the fact that -0.0 compares the same as +0.0. */
340 static void gen_fbcond_internal(TCGCond cond
, TCGv src
, int lab_true
)
343 uint64_t mzero
= 1ull << 63;
349 /* For <= or >, the -0.0 value directly compares the way we want. */
350 tcg_gen_brcondi_i64(cond
, src
, 0, lab_true
);
355 /* For == or !=, we can simply mask off the sign bit and compare. */
356 /* ??? Assume that the temporary is reclaimed at the branch. */
357 tmp
= tcg_temp_new();
358 tcg_gen_andi_i64(tmp
, src
, mzero
- 1);
359 tcg_gen_brcondi_i64(cond
, tmp
, 0, lab_true
);
363 /* For >=, emit two branches to the destination. */
364 tcg_gen_brcondi_i64(cond
, src
, 0, lab_true
);
365 tcg_gen_brcondi_i64(TCG_COND_EQ
, src
, mzero
, lab_true
);
369 /* For <, first filter out -0.0 to what will be the fallthru. */
370 lab_false
= gen_new_label();
371 tcg_gen_brcondi_i64(TCG_COND_EQ
, src
, mzero
, lab_false
);
372 tcg_gen_brcondi_i64(cond
, src
, 0, lab_true
);
373 gen_set_label(lab_false
);
381 static void gen_fbcond(DisasContext
*ctx
, TCGCond cond
, int ra
, int32_t disp
)
385 if (unlikely(ra
== 31)) {
386 /* Very uncommon case, but easier to optimize it to an integer
387 comparison than continuing with the floating point comparison. */
388 gen_bcond(ctx
, cond
, ra
, disp
, 0);
392 lab_true
= gen_new_label();
393 gen_fbcond_internal(cond
, cpu_fir
[ra
], lab_true
);
394 gen_bcond_pcload(ctx
, disp
, lab_true
);
397 static inline void gen_cmov(TCGCond inv_cond
, int ra
, int rb
, int rc
,
398 int islit
, uint8_t lit
, int mask
)
402 if (unlikely(rc
== 31))
405 l1
= gen_new_label();
409 TCGv tmp
= tcg_temp_new();
410 tcg_gen_andi_i64(tmp
, cpu_ir
[ra
], 1);
411 tcg_gen_brcondi_i64(inv_cond
, tmp
, 0, l1
);
414 tcg_gen_brcondi_i64(inv_cond
, cpu_ir
[ra
], 0, l1
);
416 /* Very uncommon case - Do not bother to optimize. */
417 TCGv tmp
= tcg_const_i64(0);
418 tcg_gen_brcondi_i64(inv_cond
, tmp
, 0, l1
);
423 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
425 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
429 static void gen_fcmov(TCGCond inv_cond
, int ra
, int rb
, int rc
)
431 TCGv va
= cpu_fir
[ra
];
434 if (unlikely(rc
== 31))
436 if (unlikely(ra
== 31)) {
437 /* ??? Assume that the temporary is reclaimed at the branch. */
438 va
= tcg_const_i64(0);
441 l1
= gen_new_label();
442 gen_fbcond_internal(inv_cond
, va
, l1
);
445 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_fir
[rb
]);
447 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
451 #define QUAL_RM_N 0x080 /* Round mode nearest even */
452 #define QUAL_RM_C 0x000 /* Round mode chopped */
453 #define QUAL_RM_M 0x040 /* Round mode minus infinity */
454 #define QUAL_RM_D 0x0c0 /* Round mode dynamic */
455 #define QUAL_RM_MASK 0x0c0
457 #define QUAL_U 0x100 /* Underflow enable (fp output) */
458 #define QUAL_V 0x100 /* Overflow enable (int output) */
459 #define QUAL_S 0x400 /* Software completion enable */
460 #define QUAL_I 0x200 /* Inexact detection enable */
462 static void gen_qual_roundmode(DisasContext
*ctx
, int fn11
)
466 fn11
&= QUAL_RM_MASK
;
467 if (fn11
== ctx
->tb_rm
) {
472 tmp
= tcg_temp_new_i32();
475 tcg_gen_movi_i32(tmp
, float_round_nearest_even
);
478 tcg_gen_movi_i32(tmp
, float_round_to_zero
);
481 tcg_gen_movi_i32(tmp
, float_round_down
);
484 tcg_gen_ld8u_i32(tmp
, cpu_env
, offsetof(CPUState
, fpcr_dyn_round
));
488 #if defined(CONFIG_SOFTFLOAT_INLINE)
489 /* ??? The "softfloat.h" interface is to call set_float_rounding_mode.
490 With CONFIG_SOFTFLOAT that expands to an out-of-line call that just
491 sets the one field. */
492 tcg_gen_st8_i32(tmp
, cpu_env
,
493 offsetof(CPUState
, fp_status
.float_rounding_mode
));
495 gen_helper_setroundmode(tmp
);
498 tcg_temp_free_i32(tmp
);
501 static void gen_qual_flushzero(DisasContext
*ctx
, int fn11
)
506 if (fn11
== ctx
->tb_ftz
) {
511 tmp
= tcg_temp_new_i32();
513 /* Underflow is enabled, use the FPCR setting. */
514 tcg_gen_ld8u_i32(tmp
, cpu_env
, offsetof(CPUState
, fpcr_flush_to_zero
));
516 /* Underflow is disabled, force flush-to-zero. */
517 tcg_gen_movi_i32(tmp
, 1);
520 #if defined(CONFIG_SOFTFLOAT_INLINE)
521 tcg_gen_st8_i32(tmp
, cpu_env
,
522 offsetof(CPUState
, fp_status
.flush_to_zero
));
524 gen_helper_setflushzero(tmp
);
527 tcg_temp_free_i32(tmp
);
530 static TCGv
gen_ieee_input(int reg
, int fn11
, int is_cmp
)
532 TCGv val
= tcg_temp_new();
534 tcg_gen_movi_i64(val
, 0);
535 } else if (fn11
& QUAL_S
) {
536 gen_helper_ieee_input_s(val
, cpu_fir
[reg
]);
538 gen_helper_ieee_input_cmp(val
, cpu_fir
[reg
]);
540 gen_helper_ieee_input(val
, cpu_fir
[reg
]);
545 static void gen_fp_exc_clear(void)
547 #if defined(CONFIG_SOFTFLOAT_INLINE)
548 TCGv_i32 zero
= tcg_const_i32(0);
549 tcg_gen_st8_i32(zero
, cpu_env
,
550 offsetof(CPUState
, fp_status
.float_exception_flags
));
551 tcg_temp_free_i32(zero
);
553 gen_helper_fp_exc_clear();
557 static void gen_fp_exc_raise_ignore(int rc
, int fn11
, int ignore
)
559 /* ??? We ought to be able to do something with imprecise exceptions.
560 E.g. notice we're still in the trap shadow of something within the
561 TB and do not generate the code to signal the exception; end the TB
562 when an exception is forced to arrive, either by consumption of a
563 register value or TRAPB or EXCB. */
564 TCGv_i32 exc
= tcg_temp_new_i32();
567 #if defined(CONFIG_SOFTFLOAT_INLINE)
568 tcg_gen_ld8u_i32(exc
, cpu_env
,
569 offsetof(CPUState
, fp_status
.float_exception_flags
));
571 gen_helper_fp_exc_get(exc
);
575 tcg_gen_andi_i32(exc
, exc
, ~ignore
);
578 /* ??? Pass in the regno of the destination so that the helper can
579 set EXC_MASK, which contains a bitmask of destination registers
580 that have caused arithmetic traps. A simple userspace emulation
581 does not require this. We do need it for a guest kernel's entArith,
582 or if we were to do something clever with imprecise exceptions. */
583 reg
= tcg_const_i32(rc
+ 32);
586 gen_helper_fp_exc_raise_s(exc
, reg
);
588 gen_helper_fp_exc_raise(exc
, reg
);
591 tcg_temp_free_i32(reg
);
592 tcg_temp_free_i32(exc
);
595 static inline void gen_fp_exc_raise(int rc
, int fn11
)
597 gen_fp_exc_raise_ignore(rc
, fn11
, fn11
& QUAL_I
? 0 : float_flag_inexact
);
600 static void gen_fcvtql(int rb
, int rc
)
602 if (unlikely(rc
== 31)) {
605 if (unlikely(rb
== 31)) {
606 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
608 TCGv tmp
= tcg_temp_new();
610 tcg_gen_andi_i64(tmp
, cpu_fir
[rb
], 0xC0000000);
611 tcg_gen_andi_i64(cpu_fir
[rc
], cpu_fir
[rb
], 0x3FFFFFFF);
612 tcg_gen_shli_i64(tmp
, tmp
, 32);
613 tcg_gen_shli_i64(cpu_fir
[rc
], cpu_fir
[rc
], 29);
614 tcg_gen_or_i64(cpu_fir
[rc
], cpu_fir
[rc
], tmp
);
620 static void gen_fcvtql_v(DisasContext
*ctx
, int rb
, int rc
)
623 int lab
= gen_new_label();
624 TCGv tmp
= tcg_temp_new();
626 tcg_gen_ext32s_i64(tmp
, cpu_fir
[rb
]);
627 tcg_gen_brcond_i64(TCG_COND_EQ
, tmp
, cpu_fir
[rb
], lab
);
628 gen_excp(ctx
, EXCP_ARITH
, EXC_M_IOV
);
635 #define FARITH2(name) \
636 static inline void glue(gen_f, name)(int rb, int rc) \
638 if (unlikely(rc == 31)) { \
642 gen_helper_ ## name (cpu_fir[rc], cpu_fir[rb]); \
644 TCGv tmp = tcg_const_i64(0); \
645 gen_helper_ ## name (cpu_fir[rc], tmp); \
646 tcg_temp_free(tmp); \
651 /* ??? VAX instruction qualifiers ignored. */
659 static void gen_ieee_arith2(DisasContext
*ctx
, void (*helper
)(TCGv
, TCGv
),
660 int rb
, int rc
, int fn11
)
664 /* ??? This is wrong: the instruction is not a nop, it still may
666 if (unlikely(rc
== 31)) {
670 gen_qual_roundmode(ctx
, fn11
);
671 gen_qual_flushzero(ctx
, fn11
);
674 vb
= gen_ieee_input(rb
, fn11
, 0);
675 helper(cpu_fir
[rc
], vb
);
678 gen_fp_exc_raise(rc
, fn11
);
681 #define IEEE_ARITH2(name) \
682 static inline void glue(gen_f, name)(DisasContext *ctx, \
683 int rb, int rc, int fn11) \
685 gen_ieee_arith2(ctx, gen_helper_##name, rb, rc, fn11); \
692 static void gen_fcvttq(DisasContext
*ctx
, int rb
, int rc
, int fn11
)
697 /* ??? This is wrong: the instruction is not a nop, it still may
699 if (unlikely(rc
== 31)) {
703 /* No need to set flushzero, since we have an integer output. */
705 vb
= gen_ieee_input(rb
, fn11
, 0);
707 /* Almost all integer conversions use cropped rounding, and most
708 also do not have integer overflow enabled. Special case that. */
711 gen_helper_cvttq_c(cpu_fir
[rc
], vb
);
713 case QUAL_V
| QUAL_RM_C
:
714 case QUAL_S
| QUAL_V
| QUAL_RM_C
:
715 ignore
= float_flag_inexact
;
717 case QUAL_S
| QUAL_V
| QUAL_I
| QUAL_RM_C
:
718 gen_helper_cvttq_svic(cpu_fir
[rc
], vb
);
721 gen_qual_roundmode(ctx
, fn11
);
722 gen_helper_cvttq(cpu_fir
[rc
], vb
);
723 ignore
|= (fn11
& QUAL_V
? 0 : float_flag_overflow
);
724 ignore
|= (fn11
& QUAL_I
? 0 : float_flag_inexact
);
729 gen_fp_exc_raise_ignore(rc
, fn11
, ignore
);
732 static void gen_ieee_intcvt(DisasContext
*ctx
, void (*helper
)(TCGv
, TCGv
),
733 int rb
, int rc
, int fn11
)
737 /* ??? This is wrong: the instruction is not a nop, it still may
739 if (unlikely(rc
== 31)) {
743 gen_qual_roundmode(ctx
, fn11
);
746 vb
= tcg_const_i64(0);
751 /* The only exception that can be raised by integer conversion
752 is inexact. Thus we only need to worry about exceptions when
753 inexact handling is requested. */
756 helper(cpu_fir
[rc
], vb
);
757 gen_fp_exc_raise(rc
, fn11
);
759 helper(cpu_fir
[rc
], vb
);
767 #define IEEE_INTCVT(name) \
768 static inline void glue(gen_f, name)(DisasContext *ctx, \
769 int rb, int rc, int fn11) \
771 gen_ieee_intcvt(ctx, gen_helper_##name, rb, rc, fn11); \
776 #define FARITH3(name) \
777 static inline void glue(gen_f, name)(int ra, int rb, int rc) \
781 if (unlikely(rc == 31)) { \
785 va = tcg_const_i64(0); \
790 vb = tcg_const_i64(0); \
795 gen_helper_ ## name (cpu_fir[rc], va, vb); \
804 /* ??? Ought to expand these inline; simple masking operations. */
809 /* ??? VAX instruction qualifiers ignored. */
822 static void gen_ieee_arith3(DisasContext
*ctx
,
823 void (*helper
)(TCGv
, TCGv
, TCGv
),
824 int ra
, int rb
, int rc
, int fn11
)
828 /* ??? This is wrong: the instruction is not a nop, it still may
830 if (unlikely(rc
== 31)) {
834 gen_qual_roundmode(ctx
, fn11
);
835 gen_qual_flushzero(ctx
, fn11
);
838 va
= gen_ieee_input(ra
, fn11
, 0);
839 vb
= gen_ieee_input(rb
, fn11
, 0);
840 helper(cpu_fir
[rc
], va
, vb
);
844 gen_fp_exc_raise(rc
, fn11
);
847 #define IEEE_ARITH3(name) \
848 static inline void glue(gen_f, name)(DisasContext *ctx, \
849 int ra, int rb, int rc, int fn11) \
851 gen_ieee_arith3(ctx, gen_helper_##name, ra, rb, rc, fn11); \
862 static void gen_ieee_compare(DisasContext
*ctx
,
863 void (*helper
)(TCGv
, TCGv
, TCGv
),
864 int ra
, int rb
, int rc
, int fn11
)
868 /* ??? This is wrong: the instruction is not a nop, it still may
870 if (unlikely(rc
== 31)) {
876 va
= gen_ieee_input(ra
, fn11
, 1);
877 vb
= gen_ieee_input(rb
, fn11
, 1);
878 helper(cpu_fir
[rc
], va
, vb
);
882 gen_fp_exc_raise(rc
, fn11
);
885 #define IEEE_CMP3(name) \
886 static inline void glue(gen_f, name)(DisasContext *ctx, \
887 int ra, int rb, int rc, int fn11) \
889 gen_ieee_compare(ctx, gen_helper_##name, ra, rb, rc, fn11); \
896 static inline uint64_t zapnot_mask(uint8_t lit
)
901 for (i
= 0; i
< 8; ++i
) {
903 mask
|= 0xffull
<< (i
* 8);
908 /* Implement zapnot with an immediate operand, which expands to some
909 form of immediate AND. This is a basic building block in the
910 definition of many of the other byte manipulation instructions. */
911 static void gen_zapnoti(TCGv dest
, TCGv src
, uint8_t lit
)
915 tcg_gen_movi_i64(dest
, 0);
918 tcg_gen_ext8u_i64(dest
, src
);
921 tcg_gen_ext16u_i64(dest
, src
);
924 tcg_gen_ext32u_i64(dest
, src
);
927 tcg_gen_mov_i64(dest
, src
);
930 tcg_gen_andi_i64 (dest
, src
, zapnot_mask (lit
));
935 static inline void gen_zapnot(int ra
, int rb
, int rc
, int islit
, uint8_t lit
)
937 if (unlikely(rc
== 31))
939 else if (unlikely(ra
== 31))
940 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
942 gen_zapnoti(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
944 gen_helper_zapnot (cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
947 static inline void gen_zap(int ra
, int rb
, int rc
, int islit
, uint8_t lit
)
949 if (unlikely(rc
== 31))
951 else if (unlikely(ra
== 31))
952 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
954 gen_zapnoti(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
956 gen_helper_zap (cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
960 /* EXTWH, EXTLH, EXTQH */
961 static void gen_ext_h(int ra
, int rb
, int rc
, int islit
,
962 uint8_t lit
, uint8_t byte_mask
)
964 if (unlikely(rc
== 31))
966 else if (unlikely(ra
== 31))
967 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
970 lit
= (64 - (lit
& 7) * 8) & 0x3f;
971 tcg_gen_shli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
973 TCGv tmp1
= tcg_temp_new();
974 tcg_gen_andi_i64(tmp1
, cpu_ir
[rb
], 7);
975 tcg_gen_shli_i64(tmp1
, tmp1
, 3);
976 tcg_gen_neg_i64(tmp1
, tmp1
);
977 tcg_gen_andi_i64(tmp1
, tmp1
, 0x3f);
978 tcg_gen_shl_i64(cpu_ir
[rc
], cpu_ir
[ra
], tmp1
);
981 gen_zapnoti(cpu_ir
[rc
], cpu_ir
[rc
], byte_mask
);
985 /* EXTBL, EXTWL, EXTLL, EXTQL */
986 static void gen_ext_l(int ra
, int rb
, int rc
, int islit
,
987 uint8_t lit
, uint8_t byte_mask
)
989 if (unlikely(rc
== 31))
991 else if (unlikely(ra
== 31))
992 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
995 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[ra
], (lit
& 7) * 8);
997 TCGv tmp
= tcg_temp_new();
998 tcg_gen_andi_i64(tmp
, cpu_ir
[rb
], 7);
999 tcg_gen_shli_i64(tmp
, tmp
, 3);
1000 tcg_gen_shr_i64(cpu_ir
[rc
], cpu_ir
[ra
], tmp
);
1003 gen_zapnoti(cpu_ir
[rc
], cpu_ir
[rc
], byte_mask
);
1007 /* INSWH, INSLH, INSQH */
1008 static void gen_ins_h(int ra
, int rb
, int rc
, int islit
,
1009 uint8_t lit
, uint8_t byte_mask
)
1011 if (unlikely(rc
== 31))
1013 else if (unlikely(ra
== 31) || (islit
&& (lit
& 7) == 0))
1014 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1016 TCGv tmp
= tcg_temp_new();
1018 /* The instruction description has us left-shift the byte mask
1019 and extract bits <15:8> and apply that zap at the end. This
1020 is equivalent to simply performing the zap first and shifting
1022 gen_zapnoti (tmp
, cpu_ir
[ra
], byte_mask
);
1025 /* Note that we have handled the lit==0 case above. */
1026 tcg_gen_shri_i64 (cpu_ir
[rc
], tmp
, 64 - (lit
& 7) * 8);
1028 TCGv shift
= tcg_temp_new();
1030 /* If (B & 7) == 0, we need to shift by 64 and leave a zero.
1031 Do this portably by splitting the shift into two parts:
1032 shift_count-1 and 1. Arrange for the -1 by using
1033 ones-complement instead of twos-complement in the negation:
1034 ~((B & 7) * 8) & 63. */
1036 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 7);
1037 tcg_gen_shli_i64(shift
, shift
, 3);
1038 tcg_gen_not_i64(shift
, shift
);
1039 tcg_gen_andi_i64(shift
, shift
, 0x3f);
1041 tcg_gen_shr_i64(cpu_ir
[rc
], tmp
, shift
);
1042 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[rc
], 1);
1043 tcg_temp_free(shift
);
1049 /* INSBL, INSWL, INSLL, INSQL */
1050 static void gen_ins_l(int ra
, int rb
, int rc
, int islit
,
1051 uint8_t lit
, uint8_t byte_mask
)
1053 if (unlikely(rc
== 31))
1055 else if (unlikely(ra
== 31))
1056 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1058 TCGv tmp
= tcg_temp_new();
1060 /* The instruction description has us left-shift the byte mask
1061 the same number of byte slots as the data and apply the zap
1062 at the end. This is equivalent to simply performing the zap
1063 first and shifting afterward. */
1064 gen_zapnoti (tmp
, cpu_ir
[ra
], byte_mask
);
1067 tcg_gen_shli_i64(cpu_ir
[rc
], tmp
, (lit
& 7) * 8);
1069 TCGv shift
= tcg_temp_new();
1070 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 7);
1071 tcg_gen_shli_i64(shift
, shift
, 3);
1072 tcg_gen_shl_i64(cpu_ir
[rc
], tmp
, shift
);
1073 tcg_temp_free(shift
);
1079 /* MSKWH, MSKLH, MSKQH */
1080 static void gen_msk_h(int ra
, int rb
, int rc
, int islit
,
1081 uint8_t lit
, uint8_t byte_mask
)
1083 if (unlikely(rc
== 31))
1085 else if (unlikely(ra
== 31))
1086 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1088 gen_zapnoti (cpu_ir
[rc
], cpu_ir
[ra
], ~((byte_mask
<< (lit
& 7)) >> 8));
1090 TCGv shift
= tcg_temp_new();
1091 TCGv mask
= tcg_temp_new();
1093 /* The instruction description is as above, where the byte_mask
1094 is shifted left, and then we extract bits <15:8>. This can be
1095 emulated with a right-shift on the expanded byte mask. This
1096 requires extra care because for an input <2:0> == 0 we need a
1097 shift of 64 bits in order to generate a zero. This is done by
1098 splitting the shift into two parts, the variable shift - 1
1099 followed by a constant 1 shift. The code we expand below is
1100 equivalent to ~((B & 7) * 8) & 63. */
1102 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 7);
1103 tcg_gen_shli_i64(shift
, shift
, 3);
1104 tcg_gen_not_i64(shift
, shift
);
1105 tcg_gen_andi_i64(shift
, shift
, 0x3f);
1106 tcg_gen_movi_i64(mask
, zapnot_mask (byte_mask
));
1107 tcg_gen_shr_i64(mask
, mask
, shift
);
1108 tcg_gen_shri_i64(mask
, mask
, 1);
1110 tcg_gen_andc_i64(cpu_ir
[rc
], cpu_ir
[ra
], mask
);
1112 tcg_temp_free(mask
);
1113 tcg_temp_free(shift
);
1117 /* MSKBL, MSKWL, MSKLL, MSKQL */
1118 static void gen_msk_l(int ra
, int rb
, int rc
, int islit
,
1119 uint8_t lit
, uint8_t byte_mask
)
1121 if (unlikely(rc
== 31))
1123 else if (unlikely(ra
== 31))
1124 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1126 gen_zapnoti (cpu_ir
[rc
], cpu_ir
[ra
], ~(byte_mask
<< (lit
& 7)));
1128 TCGv shift
= tcg_temp_new();
1129 TCGv mask
= tcg_temp_new();
1131 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 7);
1132 tcg_gen_shli_i64(shift
, shift
, 3);
1133 tcg_gen_movi_i64(mask
, zapnot_mask (byte_mask
));
1134 tcg_gen_shl_i64(mask
, mask
, shift
);
1136 tcg_gen_andc_i64(cpu_ir
[rc
], cpu_ir
[ra
], mask
);
1138 tcg_temp_free(mask
);
1139 tcg_temp_free(shift
);
1143 /* Code to call arith3 helpers */
1144 #define ARITH3(name) \
1145 static inline void glue(gen_, name)(int ra, int rb, int rc, int islit,\
1148 if (unlikely(rc == 31)) \
1153 TCGv tmp = tcg_const_i64(lit); \
1154 gen_helper_ ## name(cpu_ir[rc], cpu_ir[ra], tmp); \
1155 tcg_temp_free(tmp); \
1157 gen_helper_ ## name (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]); \
1159 TCGv tmp1 = tcg_const_i64(0); \
1161 TCGv tmp2 = tcg_const_i64(lit); \
1162 gen_helper_ ## name (cpu_ir[rc], tmp1, tmp2); \
1163 tcg_temp_free(tmp2); \
1165 gen_helper_ ## name (cpu_ir[rc], tmp1, cpu_ir[rb]); \
1166 tcg_temp_free(tmp1); \
1187 #define MVIOP2(name) \
1188 static inline void glue(gen_, name)(int rb, int rc) \
1190 if (unlikely(rc == 31)) \
1192 if (unlikely(rb == 31)) \
1193 tcg_gen_movi_i64(cpu_ir[rc], 0); \
1195 gen_helper_ ## name (cpu_ir[rc], cpu_ir[rb]); \
1202 static void gen_cmp(TCGCond cond
, int ra
, int rb
, int rc
,
1203 int islit
, uint8_t lit
)
1207 if (unlikely(rc
== 31)) {
1212 va
= tcg_const_i64(0);
1217 vb
= tcg_const_i64(lit
);
1222 tcg_gen_setcond_i64(cond
, cpu_ir
[rc
], va
, vb
);
1232 static inline int translate_one(DisasContext
*ctx
, uint32_t insn
)
1235 int32_t disp21
, disp16
, disp12
;
1236 uint16_t fn11
, fn16
;
1237 uint8_t opc
, ra
, rb
, rc
, sbz
, fpfn
, fn7
, fn2
, islit
, real_islit
;
1241 /* Decode all instruction fields */
1243 ra
= (insn
>> 21) & 0x1F;
1244 rb
= (insn
>> 16) & 0x1F;
1246 sbz
= (insn
>> 13) & 0x07;
1247 real_islit
= islit
= (insn
>> 12) & 1;
1248 if (rb
== 31 && !islit
) {
1252 lit
= (insn
>> 13) & 0xFF;
1253 palcode
= insn
& 0x03FFFFFF;
1254 disp21
= ((int32_t)((insn
& 0x001FFFFF) << 11)) >> 11;
1255 disp16
= (int16_t)(insn
& 0x0000FFFF);
1256 disp12
= (int32_t)((insn
& 0x00000FFF) << 20) >> 20;
1257 fn16
= insn
& 0x0000FFFF;
1258 fn11
= (insn
>> 5) & 0x000007FF;
1260 fn7
= (insn
>> 5) & 0x0000007F;
1261 fn2
= (insn
>> 5) & 0x00000003;
1263 LOG_DISAS("opc %02x ra %2d rb %2d rc %2d disp16 %6d\n",
1264 opc
, ra
, rb
, rc
, disp16
);
1269 #ifdef CONFIG_USER_ONLY
1270 if (palcode
== 0x9E) {
1272 tcg_gen_mov_i64(cpu_ir
[IR_V0
], cpu_uniq
);
1274 } else if (palcode
== 0x9F) {
1276 tcg_gen_mov_i64(cpu_uniq
, cpu_ir
[IR_A0
]);
1280 if (palcode
>= 0x80 && palcode
< 0xC0) {
1281 /* Unprivileged PAL call */
1282 gen_excp(ctx
, EXCP_CALL_PAL
+ ((palcode
& 0x3F) << 6), 0);
1286 #ifndef CONFIG_USER_ONLY
1287 if (palcode
< 0x40) {
1288 /* Privileged PAL code */
1289 if (ctx
->mem_idx
& 1)
1291 gen_excp(ctx
, EXCP_CALL_PALP
+ ((palcode
& 0x3F) << 6), 0);
1295 /* Invalid PAL call */
1320 if (likely(ra
!= 31)) {
1322 tcg_gen_addi_i64(cpu_ir
[ra
], cpu_ir
[rb
], disp16
);
1324 tcg_gen_movi_i64(cpu_ir
[ra
], disp16
);
1329 if (likely(ra
!= 31)) {
1331 tcg_gen_addi_i64(cpu_ir
[ra
], cpu_ir
[rb
], disp16
<< 16);
1333 tcg_gen_movi_i64(cpu_ir
[ra
], disp16
<< 16);
1338 if (!(ctx
->amask
& AMASK_BWX
))
1340 gen_load_mem(ctx
, &tcg_gen_qemu_ld8u
, ra
, rb
, disp16
, 0, 0);
1344 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 0, 1);
1348 if (!(ctx
->amask
& AMASK_BWX
))
1350 gen_load_mem(ctx
, &tcg_gen_qemu_ld16u
, ra
, rb
, disp16
, 0, 0);
1354 gen_store_mem(ctx
, &tcg_gen_qemu_st16
, ra
, rb
, disp16
, 0, 0, 0);
1358 gen_store_mem(ctx
, &tcg_gen_qemu_st8
, ra
, rb
, disp16
, 0, 0, 0);
1362 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 0, 1, 0);
1368 if (likely(rc
!= 31)) {
1371 tcg_gen_addi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1372 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1374 tcg_gen_add_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1375 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1379 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1381 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1387 if (likely(rc
!= 31)) {
1389 TCGv tmp
= tcg_temp_new();
1390 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1392 tcg_gen_addi_i64(tmp
, tmp
, lit
);
1394 tcg_gen_add_i64(tmp
, tmp
, cpu_ir
[rb
]);
1395 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
1399 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1401 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1407 if (likely(rc
!= 31)) {
1410 tcg_gen_subi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1412 tcg_gen_sub_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1413 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1416 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1418 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1419 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1425 if (likely(rc
!= 31)) {
1427 TCGv tmp
= tcg_temp_new();
1428 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1430 tcg_gen_subi_i64(tmp
, tmp
, lit
);
1432 tcg_gen_sub_i64(tmp
, tmp
, cpu_ir
[rb
]);
1433 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
1437 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1439 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1440 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1447 gen_cmpbge(ra
, rb
, rc
, islit
, lit
);
1451 if (likely(rc
!= 31)) {
1453 TCGv tmp
= tcg_temp_new();
1454 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1456 tcg_gen_addi_i64(tmp
, tmp
, lit
);
1458 tcg_gen_add_i64(tmp
, tmp
, cpu_ir
[rb
]);
1459 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
1463 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1465 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1471 if (likely(rc
!= 31)) {
1473 TCGv tmp
= tcg_temp_new();
1474 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1476 tcg_gen_subi_i64(tmp
, tmp
, lit
);
1478 tcg_gen_sub_i64(tmp
, tmp
, cpu_ir
[rb
]);
1479 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
1483 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1485 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1486 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1493 gen_cmp(TCG_COND_LTU
, ra
, rb
, rc
, islit
, lit
);
1497 if (likely(rc
!= 31)) {
1500 tcg_gen_addi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1502 tcg_gen_add_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1505 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1507 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1513 if (likely(rc
!= 31)) {
1515 TCGv tmp
= tcg_temp_new();
1516 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1518 tcg_gen_addi_i64(cpu_ir
[rc
], tmp
, lit
);
1520 tcg_gen_add_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1524 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1526 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1532 if (likely(rc
!= 31)) {
1535 tcg_gen_subi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1537 tcg_gen_sub_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1540 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1542 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1548 if (likely(rc
!= 31)) {
1550 TCGv tmp
= tcg_temp_new();
1551 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1553 tcg_gen_subi_i64(cpu_ir
[rc
], tmp
, lit
);
1555 tcg_gen_sub_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1559 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1561 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1567 gen_cmp(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
);
1571 if (likely(rc
!= 31)) {
1573 TCGv tmp
= tcg_temp_new();
1574 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1576 tcg_gen_addi_i64(cpu_ir
[rc
], tmp
, lit
);
1578 tcg_gen_add_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1582 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1584 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1590 if (likely(rc
!= 31)) {
1592 TCGv tmp
= tcg_temp_new();
1593 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1595 tcg_gen_subi_i64(cpu_ir
[rc
], tmp
, lit
);
1597 tcg_gen_sub_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1601 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1603 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1609 gen_cmp(TCG_COND_LEU
, ra
, rb
, rc
, islit
, lit
);
1613 gen_addlv(ra
, rb
, rc
, islit
, lit
);
1617 gen_sublv(ra
, rb
, rc
, islit
, lit
);
1621 gen_cmp(TCG_COND_LT
, ra
, rb
, rc
, islit
, lit
);
1625 gen_addqv(ra
, rb
, rc
, islit
, lit
);
1629 gen_subqv(ra
, rb
, rc
, islit
, lit
);
1633 gen_cmp(TCG_COND_LE
, ra
, rb
, rc
, islit
, lit
);
1643 if (likely(rc
!= 31)) {
1645 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1647 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1649 tcg_gen_and_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1654 if (likely(rc
!= 31)) {
1657 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1659 tcg_gen_andc_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1661 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1666 gen_cmov(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
, 1);
1670 gen_cmov(TCG_COND_NE
, ra
, rb
, rc
, islit
, lit
, 1);
1674 if (likely(rc
!= 31)) {
1677 tcg_gen_ori_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1679 tcg_gen_or_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1682 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1684 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1690 gen_cmov(TCG_COND_NE
, ra
, rb
, rc
, islit
, lit
, 0);
1694 gen_cmov(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
, 0);
1698 if (likely(rc
!= 31)) {
1701 tcg_gen_ori_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1703 tcg_gen_orc_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1706 tcg_gen_movi_i64(cpu_ir
[rc
], ~lit
);
1708 tcg_gen_not_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1714 if (likely(rc
!= 31)) {
1717 tcg_gen_xori_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1719 tcg_gen_xor_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1722 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1724 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1730 gen_cmov(TCG_COND_GE
, ra
, rb
, rc
, islit
, lit
, 0);
1734 gen_cmov(TCG_COND_LT
, ra
, rb
, rc
, islit
, lit
, 0);
1738 if (likely(rc
!= 31)) {
1741 tcg_gen_xori_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1743 tcg_gen_eqv_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1746 tcg_gen_movi_i64(cpu_ir
[rc
], ~lit
);
1748 tcg_gen_not_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1754 if (likely(rc
!= 31)) {
1756 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1758 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1759 switch (ctx
->env
->implver
) {
1761 /* EV4, EV45, LCA, LCA45 & EV5 */
1766 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[rc
],
1767 ~(uint64_t)ctx
->amask
);
1774 gen_cmov(TCG_COND_GT
, ra
, rb
, rc
, islit
, lit
, 0);
1778 gen_cmov(TCG_COND_LE
, ra
, rb
, rc
, islit
, lit
, 0);
1783 tcg_gen_movi_i64(cpu_ir
[rc
], ctx
->env
->implver
);
1793 gen_msk_l(ra
, rb
, rc
, islit
, lit
, 0x01);
1797 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x01);
1801 gen_ins_l(ra
, rb
, rc
, islit
, lit
, 0x01);
1805 gen_msk_l(ra
, rb
, rc
, islit
, lit
, 0x03);
1809 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x03);
1813 gen_ins_l(ra
, rb
, rc
, islit
, lit
, 0x03);
1817 gen_msk_l(ra
, rb
, rc
, islit
, lit
, 0x0f);
1821 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x0f);
1825 gen_ins_l(ra
, rb
, rc
, islit
, lit
, 0x0f);
1829 gen_zap(ra
, rb
, rc
, islit
, lit
);
1833 gen_zapnot(ra
, rb
, rc
, islit
, lit
);
1837 gen_msk_l(ra
, rb
, rc
, islit
, lit
, 0xff);
1841 if (likely(rc
!= 31)) {
1844 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1846 TCGv shift
= tcg_temp_new();
1847 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1848 tcg_gen_shr_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1849 tcg_temp_free(shift
);
1852 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1857 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0xff);
1861 if (likely(rc
!= 31)) {
1864 tcg_gen_shli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1866 TCGv shift
= tcg_temp_new();
1867 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1868 tcg_gen_shl_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1869 tcg_temp_free(shift
);
1872 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1877 gen_ins_l(ra
, rb
, rc
, islit
, lit
, 0xff);
1881 if (likely(rc
!= 31)) {
1884 tcg_gen_sari_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1886 TCGv shift
= tcg_temp_new();
1887 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1888 tcg_gen_sar_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1889 tcg_temp_free(shift
);
1892 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1897 gen_msk_h(ra
, rb
, rc
, islit
, lit
, 0x03);
1901 gen_ins_h(ra
, rb
, rc
, islit
, lit
, 0x03);
1905 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0x03);
1909 gen_msk_h(ra
, rb
, rc
, islit
, lit
, 0x0f);
1913 gen_ins_h(ra
, rb
, rc
, islit
, lit
, 0x0f);
1917 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0x0f);
1921 gen_msk_h(ra
, rb
, rc
, islit
, lit
, 0xff);
1925 gen_ins_h(ra
, rb
, rc
, islit
, lit
, 0xff);
1929 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0xff);
1939 if (likely(rc
!= 31)) {
1941 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1944 tcg_gen_muli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1946 tcg_gen_mul_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1947 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1953 if (likely(rc
!= 31)) {
1955 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1957 tcg_gen_muli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1959 tcg_gen_mul_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1964 gen_umulh(ra
, rb
, rc
, islit
, lit
);
1968 gen_mullv(ra
, rb
, rc
, islit
, lit
);
1972 gen_mulqv(ra
, rb
, rc
, islit
, lit
);
1979 switch (fpfn
) { /* fn11 & 0x3F */
1982 if (!(ctx
->amask
& AMASK_FIX
))
1984 if (likely(rc
!= 31)) {
1986 TCGv_i32 tmp
= tcg_temp_new_i32();
1987 tcg_gen_trunc_i64_i32(tmp
, cpu_ir
[ra
]);
1988 gen_helper_memory_to_s(cpu_fir
[rc
], tmp
);
1989 tcg_temp_free_i32(tmp
);
1991 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
1996 if (!(ctx
->amask
& AMASK_FIX
))
2002 if (!(ctx
->amask
& AMASK_FIX
))
2004 gen_fsqrts(ctx
, rb
, rc
, fn11
);
2008 if (!(ctx
->amask
& AMASK_FIX
))
2010 if (likely(rc
!= 31)) {
2012 TCGv_i32 tmp
= tcg_temp_new_i32();
2013 tcg_gen_trunc_i64_i32(tmp
, cpu_ir
[ra
]);
2014 gen_helper_memory_to_f(cpu_fir
[rc
], tmp
);
2015 tcg_temp_free_i32(tmp
);
2017 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
2022 if (!(ctx
->amask
& AMASK_FIX
))
2024 if (likely(rc
!= 31)) {
2026 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_ir
[ra
]);
2028 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
2033 if (!(ctx
->amask
& AMASK_FIX
))
2039 if (!(ctx
->amask
& AMASK_FIX
))
2041 gen_fsqrtt(ctx
, rb
, rc
, fn11
);
2048 /* VAX floating point */
2049 /* XXX: rounding mode and trap are ignored (!) */
2050 switch (fpfn
) { /* fn11 & 0x3F */
2053 gen_faddf(ra
, rb
, rc
);
2057 gen_fsubf(ra
, rb
, rc
);
2061 gen_fmulf(ra
, rb
, rc
);
2065 gen_fdivf(ra
, rb
, rc
);
2077 gen_faddg(ra
, rb
, rc
);
2081 gen_fsubg(ra
, rb
, rc
);
2085 gen_fmulg(ra
, rb
, rc
);
2089 gen_fdivg(ra
, rb
, rc
);
2093 gen_fcmpgeq(ra
, rb
, rc
);
2097 gen_fcmpglt(ra
, rb
, rc
);
2101 gen_fcmpgle(ra
, rb
, rc
);
2132 /* IEEE floating-point */
2133 switch (fpfn
) { /* fn11 & 0x3F */
2136 gen_fadds(ctx
, ra
, rb
, rc
, fn11
);
2140 gen_fsubs(ctx
, ra
, rb
, rc
, fn11
);
2144 gen_fmuls(ctx
, ra
, rb
, rc
, fn11
);
2148 gen_fdivs(ctx
, ra
, rb
, rc
, fn11
);
2152 gen_faddt(ctx
, ra
, rb
, rc
, fn11
);
2156 gen_fsubt(ctx
, ra
, rb
, rc
, fn11
);
2160 gen_fmult(ctx
, ra
, rb
, rc
, fn11
);
2164 gen_fdivt(ctx
, ra
, rb
, rc
, fn11
);
2168 gen_fcmptun(ctx
, ra
, rb
, rc
, fn11
);
2172 gen_fcmpteq(ctx
, ra
, rb
, rc
, fn11
);
2176 gen_fcmptlt(ctx
, ra
, rb
, rc
, fn11
);
2180 gen_fcmptle(ctx
, ra
, rb
, rc
, fn11
);
2183 if (fn11
== 0x2AC || fn11
== 0x6AC) {
2185 gen_fcvtst(ctx
, rb
, rc
, fn11
);
2188 gen_fcvtts(ctx
, rb
, rc
, fn11
);
2193 gen_fcvttq(ctx
, rb
, rc
, fn11
);
2197 gen_fcvtqs(ctx
, rb
, rc
, fn11
);
2201 gen_fcvtqt(ctx
, rb
, rc
, fn11
);
2214 if (likely(rc
!= 31)) {
2218 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
2220 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_fir
[ra
]);
2223 gen_fcpys(ra
, rb
, rc
);
2229 gen_fcpysn(ra
, rb
, rc
);
2233 gen_fcpyse(ra
, rb
, rc
);
2237 if (likely(ra
!= 31))
2238 gen_helper_store_fpcr(cpu_fir
[ra
]);
2240 TCGv tmp
= tcg_const_i64(0);
2241 gen_helper_store_fpcr(tmp
);
2247 if (likely(ra
!= 31))
2248 gen_helper_load_fpcr(cpu_fir
[ra
]);
2252 gen_fcmov(TCG_COND_NE
, ra
, rb
, rc
);
2256 gen_fcmov(TCG_COND_EQ
, ra
, rb
, rc
);
2260 gen_fcmov(TCG_COND_GE
, ra
, rb
, rc
);
2264 gen_fcmov(TCG_COND_LT
, ra
, rb
, rc
);
2268 gen_fcmov(TCG_COND_GT
, ra
, rb
, rc
);
2272 gen_fcmov(TCG_COND_LE
, ra
, rb
, rc
);
2282 /* ??? I'm pretty sure there's nothing that /sv needs to do that
2283 /v doesn't do. The only thing I can think is that /sv is a
2284 valid instruction merely for completeness in the ISA. */
2285 gen_fcvtql_v(ctx
, rb
, rc
);
2292 switch ((uint16_t)disp16
) {
2295 /* No-op. Just exit from the current tb */
2300 /* No-op. Just exit from the current tb */
2322 gen_helper_load_pcc(cpu_ir
[ra
]);
2327 gen_helper_rc(cpu_ir
[ra
]);
2335 gen_helper_rs(cpu_ir
[ra
]);
2346 /* HW_MFPR (PALcode) */
2347 #if defined (CONFIG_USER_ONLY)
2353 TCGv tmp
= tcg_const_i32(insn
& 0xFF);
2354 gen_helper_mfpr(cpu_ir
[ra
], tmp
, cpu_ir
[ra
]);
2361 tcg_gen_andi_i64(cpu_pc
, cpu_ir
[rb
], ~3);
2363 tcg_gen_movi_i64(cpu_pc
, 0);
2365 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
2366 /* Those four jumps only differ by the branch prediction hint */
2384 /* HW_LD (PALcode) */
2385 #if defined (CONFIG_USER_ONLY)
2391 TCGv addr
= tcg_temp_new();
2393 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp12
);
2395 tcg_gen_movi_i64(addr
, disp12
);
2396 switch ((insn
>> 12) & 0xF) {
2398 /* Longword physical access (hw_ldl/p) */
2399 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
2402 /* Quadword physical access (hw_ldq/p) */
2403 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
2406 /* Longword physical access with lock (hw_ldl_l/p) */
2407 gen_helper_ldl_l_raw(cpu_ir
[ra
], addr
);
2410 /* Quadword physical access with lock (hw_ldq_l/p) */
2411 gen_helper_ldq_l_raw(cpu_ir
[ra
], addr
);
2414 /* Longword virtual PTE fetch (hw_ldl/v) */
2415 tcg_gen_qemu_ld32s(cpu_ir
[ra
], addr
, 0);
2418 /* Quadword virtual PTE fetch (hw_ldq/v) */
2419 tcg_gen_qemu_ld64(cpu_ir
[ra
], addr
, 0);
2422 /* Incpu_ir[ra]id */
2425 /* Incpu_ir[ra]id */
2428 /* Longword virtual access (hw_ldl) */
2429 gen_helper_st_virt_to_phys(addr
, addr
);
2430 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
2433 /* Quadword virtual access (hw_ldq) */
2434 gen_helper_st_virt_to_phys(addr
, addr
);
2435 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
2438 /* Longword virtual access with protection check (hw_ldl/w) */
2439 tcg_gen_qemu_ld32s(cpu_ir
[ra
], addr
, 0);
2442 /* Quadword virtual access with protection check (hw_ldq/w) */
2443 tcg_gen_qemu_ld64(cpu_ir
[ra
], addr
, 0);
2446 /* Longword virtual access with alt access mode (hw_ldl/a)*/
2447 gen_helper_set_alt_mode();
2448 gen_helper_st_virt_to_phys(addr
, addr
);
2449 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
2450 gen_helper_restore_mode();
2453 /* Quadword virtual access with alt access mode (hw_ldq/a) */
2454 gen_helper_set_alt_mode();
2455 gen_helper_st_virt_to_phys(addr
, addr
);
2456 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
2457 gen_helper_restore_mode();
2460 /* Longword virtual access with alternate access mode and
2461 * protection checks (hw_ldl/wa)
2463 gen_helper_set_alt_mode();
2464 gen_helper_ldl_data(cpu_ir
[ra
], addr
);
2465 gen_helper_restore_mode();
2468 /* Quadword virtual access with alternate access mode and
2469 * protection checks (hw_ldq/wa)
2471 gen_helper_set_alt_mode();
2472 gen_helper_ldq_data(cpu_ir
[ra
], addr
);
2473 gen_helper_restore_mode();
2476 tcg_temp_free(addr
);
2484 if (!(ctx
->amask
& AMASK_BWX
))
2486 if (likely(rc
!= 31)) {
2488 tcg_gen_movi_i64(cpu_ir
[rc
], (int64_t)((int8_t)lit
));
2490 tcg_gen_ext8s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
2495 if (!(ctx
->amask
& AMASK_BWX
))
2497 if (likely(rc
!= 31)) {
2499 tcg_gen_movi_i64(cpu_ir
[rc
], (int64_t)((int16_t)lit
));
2501 tcg_gen_ext16s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
2506 if (!(ctx
->amask
& AMASK_CIX
))
2508 if (likely(rc
!= 31)) {
2510 tcg_gen_movi_i64(cpu_ir
[rc
], ctpop64(lit
));
2512 gen_helper_ctpop(cpu_ir
[rc
], cpu_ir
[rb
]);
2517 if (!(ctx
->amask
& AMASK_MVI
))
2519 gen_perr(ra
, rb
, rc
, islit
, lit
);
2523 if (!(ctx
->amask
& AMASK_CIX
))
2525 if (likely(rc
!= 31)) {
2527 tcg_gen_movi_i64(cpu_ir
[rc
], clz64(lit
));
2529 gen_helper_ctlz(cpu_ir
[rc
], cpu_ir
[rb
]);
2534 if (!(ctx
->amask
& AMASK_CIX
))
2536 if (likely(rc
!= 31)) {
2538 tcg_gen_movi_i64(cpu_ir
[rc
], ctz64(lit
));
2540 gen_helper_cttz(cpu_ir
[rc
], cpu_ir
[rb
]);
2545 if (!(ctx
->amask
& AMASK_MVI
))
2547 if (real_islit
|| ra
!= 31)
2549 gen_unpkbw (rb
, rc
);
2553 if (!(ctx
->amask
& AMASK_MVI
))
2555 if (real_islit
|| ra
!= 31)
2557 gen_unpkbl (rb
, rc
);
2561 if (!(ctx
->amask
& AMASK_MVI
))
2563 if (real_islit
|| ra
!= 31)
2569 if (!(ctx
->amask
& AMASK_MVI
))
2571 if (real_islit
|| ra
!= 31)
2577 if (!(ctx
->amask
& AMASK_MVI
))
2579 gen_minsb8 (ra
, rb
, rc
, islit
, lit
);
2583 if (!(ctx
->amask
& AMASK_MVI
))
2585 gen_minsw4 (ra
, rb
, rc
, islit
, lit
);
2589 if (!(ctx
->amask
& AMASK_MVI
))
2591 gen_minub8 (ra
, rb
, rc
, islit
, lit
);
2595 if (!(ctx
->amask
& AMASK_MVI
))
2597 gen_minuw4 (ra
, rb
, rc
, islit
, lit
);
2601 if (!(ctx
->amask
& AMASK_MVI
))
2603 gen_maxub8 (ra
, rb
, rc
, islit
, lit
);
2607 if (!(ctx
->amask
& AMASK_MVI
))
2609 gen_maxuw4 (ra
, rb
, rc
, islit
, lit
);
2613 if (!(ctx
->amask
& AMASK_MVI
))
2615 gen_maxsb8 (ra
, rb
, rc
, islit
, lit
);
2619 if (!(ctx
->amask
& AMASK_MVI
))
2621 gen_maxsw4 (ra
, rb
, rc
, islit
, lit
);
2625 if (!(ctx
->amask
& AMASK_FIX
))
2627 if (likely(rc
!= 31)) {
2629 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_fir
[ra
]);
2631 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2636 if (!(ctx
->amask
& AMASK_FIX
))
2639 TCGv_i32 tmp1
= tcg_temp_new_i32();
2641 gen_helper_s_to_memory(tmp1
, cpu_fir
[ra
]);
2643 TCGv tmp2
= tcg_const_i64(0);
2644 gen_helper_s_to_memory(tmp1
, tmp2
);
2645 tcg_temp_free(tmp2
);
2647 tcg_gen_ext_i32_i64(cpu_ir
[rc
], tmp1
);
2648 tcg_temp_free_i32(tmp1
);
2656 /* HW_MTPR (PALcode) */
2657 #if defined (CONFIG_USER_ONLY)
2663 TCGv tmp1
= tcg_const_i32(insn
& 0xFF);
2665 gen_helper_mtpr(tmp1
, cpu_ir
[ra
]);
2667 TCGv tmp2
= tcg_const_i64(0);
2668 gen_helper_mtpr(tmp1
, tmp2
);
2669 tcg_temp_free(tmp2
);
2671 tcg_temp_free(tmp1
);
2677 /* HW_REI (PALcode) */
2678 #if defined (CONFIG_USER_ONLY)
2685 gen_helper_hw_rei();
2690 tmp
= tcg_temp_new();
2691 tcg_gen_addi_i64(tmp
, cpu_ir
[rb
], (((int64_t)insn
<< 51) >> 51));
2693 tmp
= tcg_const_i64(((int64_t)insn
<< 51) >> 51);
2694 gen_helper_hw_ret(tmp
);
2701 /* HW_ST (PALcode) */
2702 #if defined (CONFIG_USER_ONLY)
2709 addr
= tcg_temp_new();
2711 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp12
);
2713 tcg_gen_movi_i64(addr
, disp12
);
2717 val
= tcg_temp_new();
2718 tcg_gen_movi_i64(val
, 0);
2720 switch ((insn
>> 12) & 0xF) {
2722 /* Longword physical access */
2723 gen_helper_stl_raw(val
, addr
);
2726 /* Quadword physical access */
2727 gen_helper_stq_raw(val
, addr
);
2730 /* Longword physical access with lock */
2731 gen_helper_stl_c_raw(val
, val
, addr
);
2734 /* Quadword physical access with lock */
2735 gen_helper_stq_c_raw(val
, val
, addr
);
2738 /* Longword virtual access */
2739 gen_helper_st_virt_to_phys(addr
, addr
);
2740 gen_helper_stl_raw(val
, addr
);
2743 /* Quadword virtual access */
2744 gen_helper_st_virt_to_phys(addr
, addr
);
2745 gen_helper_stq_raw(val
, addr
);
2766 /* Longword virtual access with alternate access mode */
2767 gen_helper_set_alt_mode();
2768 gen_helper_st_virt_to_phys(addr
, addr
);
2769 gen_helper_stl_raw(val
, addr
);
2770 gen_helper_restore_mode();
2773 /* Quadword virtual access with alternate access mode */
2774 gen_helper_set_alt_mode();
2775 gen_helper_st_virt_to_phys(addr
, addr
);
2776 gen_helper_stl_raw(val
, addr
);
2777 gen_helper_restore_mode();
2788 tcg_temp_free(addr
);
2794 gen_load_mem(ctx
, &gen_qemu_ldf
, ra
, rb
, disp16
, 1, 0);
2798 gen_load_mem(ctx
, &gen_qemu_ldg
, ra
, rb
, disp16
, 1, 0);
2802 gen_load_mem(ctx
, &gen_qemu_lds
, ra
, rb
, disp16
, 1, 0);
2806 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 1, 0);
2810 gen_store_mem(ctx
, &gen_qemu_stf
, ra
, rb
, disp16
, 1, 0, 0);
2814 gen_store_mem(ctx
, &gen_qemu_stg
, ra
, rb
, disp16
, 1, 0, 0);
2818 gen_store_mem(ctx
, &gen_qemu_sts
, ra
, rb
, disp16
, 1, 0, 0);
2822 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 1, 0, 0);
2826 gen_load_mem(ctx
, &tcg_gen_qemu_ld32s
, ra
, rb
, disp16
, 0, 0);
2830 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 0, 0);
2834 gen_load_mem(ctx
, &gen_qemu_ldl_l
, ra
, rb
, disp16
, 0, 0);
2838 gen_load_mem(ctx
, &gen_qemu_ldq_l
, ra
, rb
, disp16
, 0, 0);
2842 gen_store_mem(ctx
, &tcg_gen_qemu_st32
, ra
, rb
, disp16
, 0, 0, 0);
2846 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 0, 0, 0);
2850 gen_store_mem(ctx
, &gen_qemu_stl_c
, ra
, rb
, disp16
, 0, 0, 1);
2854 gen_store_mem(ctx
, &gen_qemu_stq_c
, ra
, rb
, disp16
, 0, 0, 1);
2859 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
2860 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp21
<< 2));
2863 case 0x31: /* FBEQ */
2864 gen_fbcond(ctx
, TCG_COND_EQ
, ra
, disp21
);
2867 case 0x32: /* FBLT */
2868 gen_fbcond(ctx
, TCG_COND_LT
, ra
, disp21
);
2871 case 0x33: /* FBLE */
2872 gen_fbcond(ctx
, TCG_COND_LE
, ra
, disp21
);
2878 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
2879 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp21
<< 2));
2882 case 0x35: /* FBNE */
2883 gen_fbcond(ctx
, TCG_COND_NE
, ra
, disp21
);
2886 case 0x36: /* FBGE */
2887 gen_fbcond(ctx
, TCG_COND_GE
, ra
, disp21
);
2890 case 0x37: /* FBGT */
2891 gen_fbcond(ctx
, TCG_COND_GT
, ra
, disp21
);
2896 gen_bcond(ctx
, TCG_COND_EQ
, ra
, disp21
, 1);
2901 gen_bcond(ctx
, TCG_COND_EQ
, ra
, disp21
, 0);
2906 gen_bcond(ctx
, TCG_COND_LT
, ra
, disp21
, 0);
2911 gen_bcond(ctx
, TCG_COND_LE
, ra
, disp21
, 0);
2916 gen_bcond(ctx
, TCG_COND_NE
, ra
, disp21
, 1);
2921 gen_bcond(ctx
, TCG_COND_NE
, ra
, disp21
, 0);
2926 gen_bcond(ctx
, TCG_COND_GE
, ra
, disp21
, 0);
2931 gen_bcond(ctx
, TCG_COND_GT
, ra
, disp21
, 0);
2943 static inline void gen_intermediate_code_internal(CPUState
*env
,
2944 TranslationBlock
*tb
,
2947 DisasContext ctx
, *ctxp
= &ctx
;
2948 target_ulong pc_start
;
2950 uint16_t *gen_opc_end
;
2958 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2960 ctx
.amask
= env
->amask
;
2962 #if defined (CONFIG_USER_ONLY)
2965 ctx
.mem_idx
= ((env
->ps
>> 3) & 3);
2966 ctx
.pal_mode
= env
->ipr
[IPR_EXC_ADDR
] & 1;
2969 /* ??? Every TB begins with unset rounding mode, to be initialized on
2970 the first fp insn of the TB. Alternately we could define a proper
2971 default for every TB (e.g. QUAL_RM_N or QUAL_RM_D) and make sure
2972 to reset the FP_STATUS to that default at the end of any TB that
2973 changes the default. We could even (gasp) dynamiclly figure out
2974 what default would be most efficient given the running program. */
2976 /* Similarly for flush-to-zero. */
2980 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2982 max_insns
= CF_COUNT_MASK
;
2985 for (ret
= 0; ret
== 0;) {
2986 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2987 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2988 if (bp
->pc
== ctx
.pc
) {
2989 gen_excp(&ctx
, EXCP_DEBUG
, 0);
2995 j
= gen_opc_ptr
- gen_opc_buf
;
2999 gen_opc_instr_start
[lj
++] = 0;
3001 gen_opc_pc
[lj
] = ctx
.pc
;
3002 gen_opc_instr_start
[lj
] = 1;
3003 gen_opc_icount
[lj
] = num_insns
;
3005 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
3007 insn
= ldl_code(ctx
.pc
);
3010 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
))) {
3011 tcg_gen_debug_insn_start(ctx
.pc
);
3015 ret
= translate_one(ctxp
, insn
);
3018 /* if we reach a page boundary or are single stepping, stop
3021 if (env
->singlestep_enabled
) {
3022 gen_excp(&ctx
, EXCP_DEBUG
, 0);
3026 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
3029 if (gen_opc_ptr
>= gen_opc_end
)
3032 if (num_insns
>= max_insns
)
3039 if (ret
!= 1 && ret
!= 3) {
3040 tcg_gen_movi_i64(cpu_pc
, ctx
.pc
);
3042 if (tb
->cflags
& CF_LAST_IO
)
3044 /* Generate the return instruction */
3046 gen_icount_end(tb
, num_insns
);
3047 *gen_opc_ptr
= INDEX_op_end
;
3049 j
= gen_opc_ptr
- gen_opc_buf
;
3052 gen_opc_instr_start
[lj
++] = 0;
3054 tb
->size
= ctx
.pc
- pc_start
;
3055 tb
->icount
= num_insns
;
3058 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3059 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3060 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 1);
3066 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
3068 gen_intermediate_code_internal(env
, tb
, 0);
3071 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
3073 gen_intermediate_code_internal(env
, tb
, 1);
3081 static const struct cpu_def_t cpu_defs
[] = {
3082 { "ev4", IMPLVER_2106x
, 0 },
3083 { "ev5", IMPLVER_21164
, 0 },
3084 { "ev56", IMPLVER_21164
, AMASK_BWX
},
3085 { "pca56", IMPLVER_21164
, AMASK_BWX
| AMASK_MVI
},
3086 { "ev6", IMPLVER_21264
, AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
},
3087 { "ev67", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
3088 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), },
3089 { "ev68", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
3090 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), },
3091 { "21064", IMPLVER_2106x
, 0 },
3092 { "21164", IMPLVER_21164
, 0 },
3093 { "21164a", IMPLVER_21164
, AMASK_BWX
},
3094 { "21164pc", IMPLVER_21164
, AMASK_BWX
| AMASK_MVI
},
3095 { "21264", IMPLVER_21264
, AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
},
3096 { "21264a", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
3097 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), }
3100 CPUAlphaState
* cpu_alpha_init (const char *cpu_model
)
3103 int implver
, amask
, i
, max
;
3105 env
= qemu_mallocz(sizeof(CPUAlphaState
));
3107 alpha_translate_init();
3110 /* Default to ev67; no reason not to emulate insns by default. */
3111 implver
= IMPLVER_21264
;
3112 amask
= (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
| AMASK_MVI
3113 | AMASK_TRAP
| AMASK_PREFETCH
);
3115 max
= ARRAY_SIZE(cpu_defs
);
3116 for (i
= 0; i
< max
; i
++) {
3117 if (strcmp (cpu_model
, cpu_defs
[i
].name
) == 0) {
3118 implver
= cpu_defs
[i
].implver
;
3119 amask
= cpu_defs
[i
].amask
;
3123 env
->implver
= implver
;
3127 #if defined (CONFIG_USER_ONLY)
3129 cpu_alpha_store_fpcr(env
, (FPCR_INVD
| FPCR_DZED
| FPCR_OVFD
3130 | FPCR_UNFD
| FPCR_INED
| FPCR_DNOD
));
3135 /* Initialize IPR */
3136 #if defined (CONFIG_USER_ONLY)
3137 env
->ipr
[IPR_EXC_ADDR
] = 0;
3138 env
->ipr
[IPR_EXC_SUM
] = 0;
3139 env
->ipr
[IPR_EXC_MASK
] = 0;
3143 hwpcb
= env
->ipr
[IPR_PCBB
];
3144 env
->ipr
[IPR_ASN
] = 0;
3145 env
->ipr
[IPR_ASTEN
] = 0;
3146 env
->ipr
[IPR_ASTSR
] = 0;
3147 env
->ipr
[IPR_DATFX
] = 0;
3149 // env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
3150 // env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
3151 // env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
3152 // env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
3153 env
->ipr
[IPR_FEN
] = 0;
3154 env
->ipr
[IPR_IPL
] = 31;
3155 env
->ipr
[IPR_MCES
] = 0;
3156 env
->ipr
[IPR_PERFMON
] = 0; /* Implementation specific */
3157 // env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
3158 env
->ipr
[IPR_SISR
] = 0;
3159 env
->ipr
[IPR_VIRBND
] = -1ULL;
3163 qemu_init_vcpu(env
);
3167 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
3168 unsigned long searched_pc
, int pc_pos
, void *puc
)
3170 env
->pc
= gen_opc_pc
[pc_pos
];