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
37 #ifdef ALPHA_DEBUG_DISAS
38 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
40 # define LOG_DISAS(...) do { } while (0)
43 typedef struct DisasContext DisasContext
;
47 #if !defined (CONFIG_USER_ONLY)
54 /* global register indexes */
55 static TCGv_ptr cpu_env
;
56 static TCGv cpu_ir
[31];
57 static TCGv cpu_fir
[31];
62 static char cpu_reg_names
[10*4+21*5 + 10*5+21*6];
64 #include "gen-icount.h"
66 static void alpha_translate_init(void)
70 static int done_init
= 0;
75 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
78 for (i
= 0; i
< 31; i
++) {
79 sprintf(p
, "ir%d", i
);
80 cpu_ir
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
81 offsetof(CPUState
, ir
[i
]), p
);
82 p
+= (i
< 10) ? 4 : 5;
84 sprintf(p
, "fir%d", i
);
85 cpu_fir
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
86 offsetof(CPUState
, fir
[i
]), p
);
87 p
+= (i
< 10) ? 5 : 6;
90 cpu_pc
= tcg_global_mem_new_i64(TCG_AREG0
,
91 offsetof(CPUState
, pc
), "pc");
93 cpu_lock
= tcg_global_mem_new_i64(TCG_AREG0
,
94 offsetof(CPUState
, lock
), "lock");
96 /* register helpers */
103 static inline void gen_excp(DisasContext
*ctx
, int exception
, int error_code
)
107 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
);
108 tmp1
= tcg_const_i32(exception
);
109 tmp2
= tcg_const_i32(error_code
);
110 gen_helper_excp(tmp1
, tmp2
);
111 tcg_temp_free_i32(tmp2
);
112 tcg_temp_free_i32(tmp1
);
115 static inline void gen_invalid(DisasContext
*ctx
)
117 gen_excp(ctx
, EXCP_OPCDEC
, 0);
120 static inline void gen_qemu_ldf(TCGv t0
, TCGv t1
, int flags
)
122 TCGv tmp
= tcg_temp_new();
123 TCGv_i32 tmp32
= tcg_temp_new_i32();
124 tcg_gen_qemu_ld32u(tmp
, t1
, flags
);
125 tcg_gen_trunc_i64_i32(tmp32
, tmp
);
126 gen_helper_memory_to_f(t0
, tmp32
);
127 tcg_temp_free_i32(tmp32
);
131 static inline void gen_qemu_ldg(TCGv t0
, TCGv t1
, int flags
)
133 TCGv tmp
= tcg_temp_new();
134 tcg_gen_qemu_ld64(tmp
, t1
, flags
);
135 gen_helper_memory_to_g(t0
, tmp
);
139 static inline void gen_qemu_lds(TCGv t0
, TCGv t1
, int flags
)
141 TCGv tmp
= tcg_temp_new();
142 TCGv_i32 tmp32
= tcg_temp_new_i32();
143 tcg_gen_qemu_ld32u(tmp
, t1
, flags
);
144 tcg_gen_trunc_i64_i32(tmp32
, tmp
);
145 gen_helper_memory_to_s(t0
, tmp32
);
146 tcg_temp_free_i32(tmp32
);
150 static inline void gen_qemu_ldl_l(TCGv t0
, TCGv t1
, int flags
)
152 tcg_gen_mov_i64(cpu_lock
, t1
);
153 tcg_gen_qemu_ld32s(t0
, t1
, flags
);
156 static inline void gen_qemu_ldq_l(TCGv t0
, TCGv t1
, int flags
)
158 tcg_gen_mov_i64(cpu_lock
, t1
);
159 tcg_gen_qemu_ld64(t0
, t1
, flags
);
162 static inline void gen_load_mem(DisasContext
*ctx
,
163 void (*tcg_gen_qemu_load
)(TCGv t0
, TCGv t1
,
165 int ra
, int rb
, int32_t disp16
, int fp
,
170 if (unlikely(ra
== 31))
173 addr
= tcg_temp_new();
175 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp16
);
177 tcg_gen_andi_i64(addr
, addr
, ~0x7);
181 tcg_gen_movi_i64(addr
, disp16
);
184 tcg_gen_qemu_load(cpu_fir
[ra
], addr
, ctx
->mem_idx
);
186 tcg_gen_qemu_load(cpu_ir
[ra
], addr
, ctx
->mem_idx
);
190 static inline void gen_qemu_stf(TCGv t0
, TCGv t1
, int flags
)
192 TCGv_i32 tmp32
= tcg_temp_new_i32();
193 TCGv tmp
= tcg_temp_new();
194 gen_helper_f_to_memory(tmp32
, t0
);
195 tcg_gen_extu_i32_i64(tmp
, tmp32
);
196 tcg_gen_qemu_st32(tmp
, t1
, flags
);
198 tcg_temp_free_i32(tmp32
);
201 static inline void gen_qemu_stg(TCGv t0
, TCGv t1
, int flags
)
203 TCGv tmp
= tcg_temp_new();
204 gen_helper_g_to_memory(tmp
, t0
);
205 tcg_gen_qemu_st64(tmp
, t1
, flags
);
209 static inline void gen_qemu_sts(TCGv t0
, TCGv t1
, int flags
)
211 TCGv_i32 tmp32
= tcg_temp_new_i32();
212 TCGv tmp
= tcg_temp_new();
213 gen_helper_s_to_memory(tmp32
, t0
);
214 tcg_gen_extu_i32_i64(tmp
, tmp32
);
215 tcg_gen_qemu_st32(tmp
, t1
, flags
);
217 tcg_temp_free_i32(tmp32
);
220 static inline void gen_qemu_stl_c(TCGv t0
, TCGv t1
, int flags
)
224 l1
= gen_new_label();
225 l2
= gen_new_label();
226 tcg_gen_brcond_i64(TCG_COND_NE
, cpu_lock
, t1
, l1
);
227 tcg_gen_qemu_st32(t0
, t1
, flags
);
228 tcg_gen_movi_i64(t0
, 1);
231 tcg_gen_movi_i64(t0
, 0);
233 tcg_gen_movi_i64(cpu_lock
, -1);
236 static inline void gen_qemu_stq_c(TCGv t0
, TCGv t1
, int flags
)
240 l1
= gen_new_label();
241 l2
= gen_new_label();
242 tcg_gen_brcond_i64(TCG_COND_NE
, cpu_lock
, t1
, l1
);
243 tcg_gen_qemu_st64(t0
, t1
, flags
);
244 tcg_gen_movi_i64(t0
, 1);
247 tcg_gen_movi_i64(t0
, 0);
249 tcg_gen_movi_i64(cpu_lock
, -1);
252 static inline void gen_store_mem(DisasContext
*ctx
,
253 void (*tcg_gen_qemu_store
)(TCGv t0
, TCGv t1
,
255 int ra
, int rb
, int32_t disp16
, int fp
,
256 int clear
, int local
)
260 addr
= tcg_temp_local_new();
262 addr
= tcg_temp_new();
264 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp16
);
266 tcg_gen_andi_i64(addr
, addr
, ~0x7);
270 tcg_gen_movi_i64(addr
, disp16
);
274 tcg_gen_qemu_store(cpu_fir
[ra
], addr
, ctx
->mem_idx
);
276 tcg_gen_qemu_store(cpu_ir
[ra
], addr
, ctx
->mem_idx
);
280 zero
= tcg_const_local_i64(0);
282 zero
= tcg_const_i64(0);
283 tcg_gen_qemu_store(zero
, addr
, ctx
->mem_idx
);
289 static inline void gen_bcond(DisasContext
*ctx
, TCGCond cond
, int ra
,
290 int32_t disp
, int mask
)
294 l1
= gen_new_label();
295 l2
= gen_new_label();
296 if (likely(ra
!= 31)) {
298 TCGv tmp
= tcg_temp_new();
299 tcg_gen_andi_i64(tmp
, cpu_ir
[ra
], 1);
300 tcg_gen_brcondi_i64(cond
, tmp
, 0, l1
);
303 tcg_gen_brcondi_i64(cond
, cpu_ir
[ra
], 0, l1
);
305 /* Very uncommon case - Do not bother to optimize. */
306 TCGv tmp
= tcg_const_i64(0);
307 tcg_gen_brcondi_i64(cond
, tmp
, 0, l1
);
310 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
);
313 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp
<< 2));
317 static inline void gen_fbcond(DisasContext
*ctx
, int opc
, int ra
,
324 l1
= gen_new_label();
325 l2
= gen_new_label();
327 tmp
= tcg_temp_new();
330 tmp
= tcg_const_i64(0);
334 case 0x31: /* FBEQ */
335 gen_helper_cmpfeq(tmp
, src
);
337 case 0x32: /* FBLT */
338 gen_helper_cmpflt(tmp
, src
);
340 case 0x33: /* FBLE */
341 gen_helper_cmpfle(tmp
, src
);
343 case 0x35: /* FBNE */
344 gen_helper_cmpfne(tmp
, src
);
346 case 0x36: /* FBGE */
347 gen_helper_cmpfge(tmp
, src
);
349 case 0x37: /* FBGT */
350 gen_helper_cmpfgt(tmp
, src
);
355 tcg_gen_brcondi_i64(TCG_COND_NE
, tmp
, 0, l1
);
356 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
);
359 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp16
<< 2));
363 static inline void gen_cmov(TCGCond inv_cond
, int ra
, int rb
, int rc
,
364 int islit
, uint8_t lit
, int mask
)
368 if (unlikely(rc
== 31))
371 l1
= gen_new_label();
375 TCGv tmp
= tcg_temp_new();
376 tcg_gen_andi_i64(tmp
, cpu_ir
[ra
], 1);
377 tcg_gen_brcondi_i64(inv_cond
, tmp
, 0, l1
);
380 tcg_gen_brcondi_i64(inv_cond
, cpu_ir
[ra
], 0, l1
);
382 /* Very uncommon case - Do not bother to optimize. */
383 TCGv tmp
= tcg_const_i64(0);
384 tcg_gen_brcondi_i64(inv_cond
, tmp
, 0, l1
);
389 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
391 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
395 #define FARITH2(name) \
396 static inline void glue(gen_f, name)(int rb, int rc) \
398 if (unlikely(rc == 31)) \
402 gen_helper_ ## name (cpu_fir[rc], cpu_fir[rb]); \
404 TCGv tmp = tcg_const_i64(0); \
405 gen_helper_ ## name (cpu_fir[rc], tmp); \
406 tcg_temp_free(tmp); \
427 #define FARITH3(name) \
428 static inline void glue(gen_f, name)(int ra, int rb, int rc) \
430 if (unlikely(rc == 31)) \
435 gen_helper_ ## name (cpu_fir[rc], cpu_fir[ra], cpu_fir[rb]); \
437 TCGv tmp = tcg_const_i64(0); \
438 gen_helper_ ## name (cpu_fir[rc], cpu_fir[ra], tmp); \
439 tcg_temp_free(tmp); \
442 TCGv tmp = tcg_const_i64(0); \
444 gen_helper_ ## name (cpu_fir[rc], tmp, cpu_fir[rb]); \
446 gen_helper_ ## name (cpu_fir[rc], tmp, tmp); \
447 tcg_temp_free(tmp); \
478 #define FCMOV(name) \
479 static inline void glue(gen_f, name)(int ra, int rb, int rc) \
484 if (unlikely(rc == 31)) \
487 l1 = gen_new_label(); \
488 tmp = tcg_temp_new(); \
490 tmp = tcg_temp_new(); \
491 gen_helper_ ## name (tmp, cpu_fir[ra]); \
493 tmp = tcg_const_i64(0); \
494 gen_helper_ ## name (tmp, tmp); \
496 tcg_gen_brcondi_i64(TCG_COND_EQ, tmp, 0, l1); \
498 tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]); \
500 tcg_gen_movi_i64(cpu_fir[rc], 0); \
510 /* Implement zapnot with an immediate operand, which expands to some
511 form of immediate AND. This is a basic building block in the
512 definition of many of the other byte manipulation instructions. */
513 static inline void gen_zapnoti(int ra
, int rc
, uint8_t lit
)
520 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
523 tcg_gen_ext8u_i64(cpu_ir
[rc
], cpu_ir
[ra
]);
526 tcg_gen_ext16u_i64(cpu_ir
[rc
], cpu_ir
[ra
]);
529 tcg_gen_ext32u_i64(cpu_ir
[rc
], cpu_ir
[ra
]);
532 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[ra
]);
535 for (mask
= i
= 0; i
< 8; ++i
) {
537 mask
|= 0xffull
<< (i
* 8);
539 tcg_gen_andi_i64 (cpu_ir
[rc
], cpu_ir
[ra
], mask
);
544 static inline void gen_zapnot(int ra
, int rb
, int rc
, int islit
, uint8_t lit
)
546 if (unlikely(rc
== 31))
548 else if (unlikely(ra
== 31))
549 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
551 gen_zapnoti(ra
, rc
, lit
);
553 gen_helper_zapnot (cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
556 static inline void gen_zap(int ra
, int rb
, int rc
, int islit
, uint8_t lit
)
558 if (unlikely(rc
== 31))
560 else if (unlikely(ra
== 31))
561 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
563 gen_zapnoti(ra
, rc
, ~lit
);
565 gen_helper_zap (cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
569 /* EXTWH, EXTWH, EXTLH, EXTQH */
570 static inline void gen_ext_h(int ra
, int rb
, int rc
, int islit
,
571 uint8_t lit
, uint8_t byte_mask
)
573 if (unlikely(rc
== 31))
575 else if (unlikely(ra
== 31))
576 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
579 lit
= (64 - (lit
& 7) * 8) & 0x3f;
580 tcg_gen_shli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
582 TCGv tmp1
= tcg_temp_new();
583 tcg_gen_andi_i64(tmp1
, cpu_ir
[rb
], 7);
584 tcg_gen_shli_i64(tmp1
, tmp1
, 3);
585 tcg_gen_neg_i64(tmp1
, tmp1
);
586 tcg_gen_andi_i64(tmp1
, tmp1
, 0x3f);
587 tcg_gen_shl_i64(cpu_ir
[rc
], cpu_ir
[ra
], tmp1
);
590 gen_zapnoti(rc
, rc
, byte_mask
);
594 /* EXTBL, EXTWL, EXTWL, EXTLL, EXTQL */
595 static inline void gen_ext_l(int ra
, int rb
, int rc
, int islit
,
596 uint8_t lit
, uint8_t byte_mask
)
598 if (unlikely(rc
== 31))
600 else if (unlikely(ra
== 31))
601 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
604 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[ra
], (lit
& 7) * 8);
606 TCGv tmp
= tcg_temp_new();
607 tcg_gen_andi_i64(tmp
, cpu_ir
[rb
], 7);
608 tcg_gen_shli_i64(tmp
, tmp
, 3);
609 tcg_gen_shr_i64(cpu_ir
[rc
], cpu_ir
[ra
], tmp
);
612 gen_zapnoti(rc
, rc
, byte_mask
);
616 /* Code to call arith3 helpers */
617 #define ARITH3(name) \
618 static inline void glue(gen_, name)(int ra, int rb, int rc, int islit,\
621 if (unlikely(rc == 31)) \
626 TCGv tmp = tcg_const_i64(lit); \
627 gen_helper_ ## name(cpu_ir[rc], cpu_ir[ra], tmp); \
628 tcg_temp_free(tmp); \
630 gen_helper_ ## name (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]); \
632 TCGv tmp1 = tcg_const_i64(0); \
634 TCGv tmp2 = tcg_const_i64(lit); \
635 gen_helper_ ## name (cpu_ir[rc], tmp1, tmp2); \
636 tcg_temp_free(tmp2); \
638 gen_helper_ ## name (cpu_ir[rc], tmp1, cpu_ir[rb]); \
639 tcg_temp_free(tmp1); \
674 #define MVIOP2(name) \
675 static inline void glue(gen_, name)(int rb, int rc) \
677 if (unlikely(rc == 31)) \
679 if (unlikely(rb == 31)) \
680 tcg_gen_movi_i64(cpu_ir[rc], 0); \
682 gen_helper_ ## name (cpu_ir[rc], cpu_ir[rb]); \
689 static inline void gen_cmp(TCGCond cond
, int ra
, int rb
, int rc
, int islit
,
695 if (unlikely(rc
== 31))
698 l1
= gen_new_label();
699 l2
= gen_new_label();
702 tmp
= tcg_temp_new();
703 tcg_gen_mov_i64(tmp
, cpu_ir
[ra
]);
705 tmp
= tcg_const_i64(0);
707 tcg_gen_brcondi_i64(cond
, tmp
, lit
, l1
);
709 tcg_gen_brcond_i64(cond
, tmp
, cpu_ir
[rb
], l1
);
711 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
714 tcg_gen_movi_i64(cpu_ir
[rc
], 1);
718 static inline int translate_one(DisasContext
*ctx
, uint32_t insn
)
721 int32_t disp21
, disp16
, disp12
;
723 uint8_t opc
, ra
, rb
, rc
, sbz
, fpfn
, fn7
, fn2
, islit
, real_islit
;
727 /* Decode all instruction fields */
729 ra
= (insn
>> 21) & 0x1F;
730 rb
= (insn
>> 16) & 0x1F;
732 sbz
= (insn
>> 13) & 0x07;
733 real_islit
= islit
= (insn
>> 12) & 1;
734 if (rb
== 31 && !islit
) {
738 lit
= (insn
>> 13) & 0xFF;
739 palcode
= insn
& 0x03FFFFFF;
740 disp21
= ((int32_t)((insn
& 0x001FFFFF) << 11)) >> 11;
741 disp16
= (int16_t)(insn
& 0x0000FFFF);
742 disp12
= (int32_t)((insn
& 0x00000FFF) << 20) >> 20;
743 fn16
= insn
& 0x0000FFFF;
744 fn11
= (insn
>> 5) & 0x000007FF;
746 fn7
= (insn
>> 5) & 0x0000007F;
747 fn2
= (insn
>> 5) & 0x00000003;
749 LOG_DISAS("opc %02x ra %2d rb %2d rc %2d disp16 %6d\n",
750 opc
, ra
, rb
, rc
, disp16
);
755 if (palcode
>= 0x80 && palcode
< 0xC0) {
756 /* Unprivileged PAL call */
757 gen_excp(ctx
, EXCP_CALL_PAL
+ ((palcode
& 0x3F) << 6), 0);
758 #if !defined (CONFIG_USER_ONLY)
759 } else if (palcode
< 0x40) {
760 /* Privileged PAL code */
761 if (ctx
->mem_idx
& 1)
764 gen_excp(ctx
, EXCP_CALL_PALP
+ ((palcode
& 0x3F) << 6), 0);
767 /* Invalid PAL call */
795 if (likely(ra
!= 31)) {
797 tcg_gen_addi_i64(cpu_ir
[ra
], cpu_ir
[rb
], disp16
);
799 tcg_gen_movi_i64(cpu_ir
[ra
], disp16
);
804 if (likely(ra
!= 31)) {
806 tcg_gen_addi_i64(cpu_ir
[ra
], cpu_ir
[rb
], disp16
<< 16);
808 tcg_gen_movi_i64(cpu_ir
[ra
], disp16
<< 16);
813 if (!(ctx
->amask
& AMASK_BWX
))
815 gen_load_mem(ctx
, &tcg_gen_qemu_ld8u
, ra
, rb
, disp16
, 0, 0);
819 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 0, 1);
823 if (!(ctx
->amask
& AMASK_BWX
))
825 gen_load_mem(ctx
, &tcg_gen_qemu_ld16u
, ra
, rb
, disp16
, 0, 0);
829 gen_store_mem(ctx
, &tcg_gen_qemu_st16
, ra
, rb
, disp16
, 0, 0, 0);
833 gen_store_mem(ctx
, &tcg_gen_qemu_st8
, ra
, rb
, disp16
, 0, 0, 0);
837 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 0, 1, 0);
843 if (likely(rc
!= 31)) {
846 tcg_gen_addi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
847 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
849 tcg_gen_add_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
850 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
854 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
856 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
862 if (likely(rc
!= 31)) {
864 TCGv tmp
= tcg_temp_new();
865 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
867 tcg_gen_addi_i64(tmp
, tmp
, lit
);
869 tcg_gen_add_i64(tmp
, tmp
, cpu_ir
[rb
]);
870 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
874 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
876 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
882 if (likely(rc
!= 31)) {
885 tcg_gen_subi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
887 tcg_gen_sub_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
888 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
891 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
893 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
894 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
900 if (likely(rc
!= 31)) {
902 TCGv tmp
= tcg_temp_new();
903 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
905 tcg_gen_subi_i64(tmp
, tmp
, lit
);
907 tcg_gen_sub_i64(tmp
, tmp
, cpu_ir
[rb
]);
908 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
912 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
914 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
915 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
922 gen_cmpbge(ra
, rb
, rc
, islit
, lit
);
926 if (likely(rc
!= 31)) {
928 TCGv tmp
= tcg_temp_new();
929 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
931 tcg_gen_addi_i64(tmp
, tmp
, lit
);
933 tcg_gen_add_i64(tmp
, tmp
, cpu_ir
[rb
]);
934 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
938 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
940 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
946 if (likely(rc
!= 31)) {
948 TCGv tmp
= tcg_temp_new();
949 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
951 tcg_gen_subi_i64(tmp
, tmp
, lit
);
953 tcg_gen_sub_i64(tmp
, tmp
, cpu_ir
[rb
]);
954 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
958 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
960 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
961 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
968 gen_cmp(TCG_COND_LTU
, ra
, rb
, rc
, islit
, lit
);
972 if (likely(rc
!= 31)) {
975 tcg_gen_addi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
977 tcg_gen_add_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
980 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
982 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
988 if (likely(rc
!= 31)) {
990 TCGv tmp
= tcg_temp_new();
991 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
993 tcg_gen_addi_i64(cpu_ir
[rc
], tmp
, lit
);
995 tcg_gen_add_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
999 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1001 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1007 if (likely(rc
!= 31)) {
1010 tcg_gen_subi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1012 tcg_gen_sub_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1015 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1017 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1023 if (likely(rc
!= 31)) {
1025 TCGv tmp
= tcg_temp_new();
1026 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
1028 tcg_gen_subi_i64(cpu_ir
[rc
], tmp
, lit
);
1030 tcg_gen_sub_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1034 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1036 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1042 gen_cmp(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
);
1046 if (likely(rc
!= 31)) {
1048 TCGv tmp
= tcg_temp_new();
1049 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1051 tcg_gen_addi_i64(cpu_ir
[rc
], tmp
, lit
);
1053 tcg_gen_add_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1057 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1059 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1065 if (likely(rc
!= 31)) {
1067 TCGv tmp
= tcg_temp_new();
1068 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1070 tcg_gen_subi_i64(cpu_ir
[rc
], tmp
, lit
);
1072 tcg_gen_sub_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1076 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1078 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1084 gen_cmp(TCG_COND_LEU
, ra
, rb
, rc
, islit
, lit
);
1088 gen_addlv(ra
, rb
, rc
, islit
, lit
);
1092 gen_sublv(ra
, rb
, rc
, islit
, lit
);
1096 gen_cmp(TCG_COND_LT
, ra
, rb
, rc
, islit
, lit
);
1100 gen_addqv(ra
, rb
, rc
, islit
, lit
);
1104 gen_subqv(ra
, rb
, rc
, islit
, lit
);
1108 gen_cmp(TCG_COND_LE
, ra
, rb
, rc
, islit
, lit
);
1118 if (likely(rc
!= 31)) {
1120 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1122 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1124 tcg_gen_and_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1129 if (likely(rc
!= 31)) {
1132 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1134 tcg_gen_andc_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1136 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1141 gen_cmov(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
, 1);
1145 gen_cmov(TCG_COND_NE
, ra
, rb
, rc
, islit
, lit
, 1);
1149 if (likely(rc
!= 31)) {
1152 tcg_gen_ori_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1154 tcg_gen_or_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1157 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1159 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1165 gen_cmov(TCG_COND_NE
, ra
, rb
, rc
, islit
, lit
, 0);
1169 gen_cmov(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
, 0);
1173 if (likely(rc
!= 31)) {
1176 tcg_gen_ori_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1178 tcg_gen_orc_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1181 tcg_gen_movi_i64(cpu_ir
[rc
], ~lit
);
1183 tcg_gen_not_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1189 if (likely(rc
!= 31)) {
1192 tcg_gen_xori_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1194 tcg_gen_xor_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1197 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1199 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1205 gen_cmov(TCG_COND_GE
, ra
, rb
, rc
, islit
, lit
, 0);
1209 gen_cmov(TCG_COND_LT
, ra
, rb
, rc
, islit
, lit
, 0);
1213 if (likely(rc
!= 31)) {
1216 tcg_gen_xori_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1218 tcg_gen_eqv_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1221 tcg_gen_movi_i64(cpu_ir
[rc
], ~lit
);
1223 tcg_gen_not_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1229 if (likely(rc
!= 31)) {
1231 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1233 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1234 switch (ctx
->env
->implver
) {
1236 /* EV4, EV45, LCA, LCA45 & EV5 */
1241 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[rc
],
1242 ~(uint64_t)ctx
->amask
);
1249 gen_cmov(TCG_COND_GT
, ra
, rb
, rc
, islit
, lit
, 0);
1253 gen_cmov(TCG_COND_LE
, ra
, rb
, rc
, islit
, lit
, 0);
1258 tcg_gen_movi_i64(cpu_ir
[rc
], ctx
->env
->implver
);
1268 gen_mskbl(ra
, rb
, rc
, islit
, lit
);
1272 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x01);
1276 gen_insbl(ra
, rb
, rc
, islit
, lit
);
1280 gen_mskwl(ra
, rb
, rc
, islit
, lit
);
1284 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x03);
1288 gen_inswl(ra
, rb
, rc
, islit
, lit
);
1292 gen_mskll(ra
, rb
, rc
, islit
, lit
);
1296 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0x0f);
1300 gen_insll(ra
, rb
, rc
, islit
, lit
);
1304 gen_zap(ra
, rb
, rc
, islit
, lit
);
1308 gen_zapnot(ra
, rb
, rc
, islit
, lit
);
1312 gen_mskql(ra
, rb
, rc
, islit
, lit
);
1316 if (likely(rc
!= 31)) {
1319 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1321 TCGv shift
= tcg_temp_new();
1322 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1323 tcg_gen_shr_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1324 tcg_temp_free(shift
);
1327 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1332 gen_ext_l(ra
, rb
, rc
, islit
, lit
, 0xff);
1336 if (likely(rc
!= 31)) {
1339 tcg_gen_shli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1341 TCGv shift
= tcg_temp_new();
1342 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1343 tcg_gen_shl_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1344 tcg_temp_free(shift
);
1347 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1352 gen_insql(ra
, rb
, rc
, islit
, lit
);
1356 if (likely(rc
!= 31)) {
1359 tcg_gen_sari_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1361 TCGv shift
= tcg_temp_new();
1362 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1363 tcg_gen_sar_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1364 tcg_temp_free(shift
);
1367 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1372 gen_mskwh(ra
, rb
, rc
, islit
, lit
);
1376 gen_inswh(ra
, rb
, rc
, islit
, lit
);
1380 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0x03);
1384 gen_msklh(ra
, rb
, rc
, islit
, lit
);
1388 gen_inslh(ra
, rb
, rc
, islit
, lit
);
1392 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0x0f);
1396 gen_mskqh(ra
, rb
, rc
, islit
, lit
);
1400 gen_insqh(ra
, rb
, rc
, islit
, lit
);
1404 gen_ext_h(ra
, rb
, rc
, islit
, lit
, 0xff);
1414 if (likely(rc
!= 31)) {
1416 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1419 tcg_gen_muli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1421 tcg_gen_mul_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1422 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1428 if (likely(rc
!= 31)) {
1430 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1432 tcg_gen_muli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1434 tcg_gen_mul_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1439 gen_umulh(ra
, rb
, rc
, islit
, lit
);
1443 gen_mullv(ra
, rb
, rc
, islit
, lit
);
1447 gen_mulqv(ra
, rb
, rc
, islit
, lit
);
1454 switch (fpfn
) { /* f11 & 0x3F */
1457 if (!(ctx
->amask
& AMASK_FIX
))
1459 if (likely(rc
!= 31)) {
1461 TCGv_i32 tmp
= tcg_temp_new_i32();
1462 tcg_gen_trunc_i64_i32(tmp
, cpu_ir
[ra
]);
1463 gen_helper_memory_to_s(cpu_fir
[rc
], tmp
);
1464 tcg_temp_free_i32(tmp
);
1466 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
1471 if (!(ctx
->amask
& AMASK_FIX
))
1477 if (!(ctx
->amask
& AMASK_FIX
))
1483 if (!(ctx
->amask
& AMASK_FIX
))
1485 if (likely(rc
!= 31)) {
1487 TCGv_i32 tmp
= tcg_temp_new_i32();
1488 tcg_gen_trunc_i64_i32(tmp
, cpu_ir
[ra
]);
1489 gen_helper_memory_to_f(cpu_fir
[rc
], tmp
);
1490 tcg_temp_free_i32(tmp
);
1492 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
1497 if (!(ctx
->amask
& AMASK_FIX
))
1499 if (likely(rc
!= 31)) {
1501 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_ir
[ra
]);
1503 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
1508 if (!(ctx
->amask
& AMASK_FIX
))
1514 if (!(ctx
->amask
& AMASK_FIX
))
1523 /* VAX floating point */
1524 /* XXX: rounding mode and trap are ignored (!) */
1525 switch (fpfn
) { /* f11 & 0x3F */
1528 gen_faddf(ra
, rb
, rc
);
1532 gen_fsubf(ra
, rb
, rc
);
1536 gen_fmulf(ra
, rb
, rc
);
1540 gen_fdivf(ra
, rb
, rc
);
1552 gen_faddg(ra
, rb
, rc
);
1556 gen_fsubg(ra
, rb
, rc
);
1560 gen_fmulg(ra
, rb
, rc
);
1564 gen_fdivg(ra
, rb
, rc
);
1568 gen_fcmpgeq(ra
, rb
, rc
);
1572 gen_fcmpglt(ra
, rb
, rc
);
1576 gen_fcmpgle(ra
, rb
, rc
);
1607 /* IEEE floating-point */
1608 /* XXX: rounding mode and traps are ignored (!) */
1609 switch (fpfn
) { /* f11 & 0x3F */
1612 gen_fadds(ra
, rb
, rc
);
1616 gen_fsubs(ra
, rb
, rc
);
1620 gen_fmuls(ra
, rb
, rc
);
1624 gen_fdivs(ra
, rb
, rc
);
1628 gen_faddt(ra
, rb
, rc
);
1632 gen_fsubt(ra
, rb
, rc
);
1636 gen_fmult(ra
, rb
, rc
);
1640 gen_fdivt(ra
, rb
, rc
);
1644 gen_fcmptun(ra
, rb
, rc
);
1648 gen_fcmpteq(ra
, rb
, rc
);
1652 gen_fcmptlt(ra
, rb
, rc
);
1656 gen_fcmptle(ra
, rb
, rc
);
1659 /* XXX: incorrect */
1660 if (fn11
== 0x2AC || fn11
== 0x6AC) {
1691 if (likely(rc
!= 31)) {
1694 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_fir
[ra
]);
1697 gen_fcpys(ra
, rb
, rc
);
1702 gen_fcpysn(ra
, rb
, rc
);
1706 gen_fcpyse(ra
, rb
, rc
);
1710 if (likely(ra
!= 31))
1711 gen_helper_store_fpcr(cpu_fir
[ra
]);
1713 TCGv tmp
= tcg_const_i64(0);
1714 gen_helper_store_fpcr(tmp
);
1720 if (likely(ra
!= 31))
1721 gen_helper_load_fpcr(cpu_fir
[ra
]);
1725 gen_fcmpfeq(ra
, rb
, rc
);
1729 gen_fcmpfne(ra
, rb
, rc
);
1733 gen_fcmpflt(ra
, rb
, rc
);
1737 gen_fcmpfge(ra
, rb
, rc
);
1741 gen_fcmpfle(ra
, rb
, rc
);
1745 gen_fcmpfgt(ra
, rb
, rc
);
1753 gen_fcvtqlv(rb
, rc
);
1757 gen_fcvtqlsv(rb
, rc
);
1764 switch ((uint16_t)disp16
) {
1767 /* No-op. Just exit from the current tb */
1772 /* No-op. Just exit from the current tb */
1794 gen_helper_load_pcc(cpu_ir
[ra
]);
1799 gen_helper_rc(cpu_ir
[ra
]);
1807 gen_helper_rs(cpu_ir
[ra
]);
1818 /* HW_MFPR (PALcode) */
1819 #if defined (CONFIG_USER_ONLY)
1825 TCGv tmp
= tcg_const_i32(insn
& 0xFF);
1826 gen_helper_mfpr(cpu_ir
[ra
], tmp
, cpu_ir
[ra
]);
1833 tcg_gen_andi_i64(cpu_pc
, cpu_ir
[rb
], ~3);
1835 tcg_gen_movi_i64(cpu_pc
, 0);
1837 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
1838 /* Those four jumps only differ by the branch prediction hint */
1856 /* HW_LD (PALcode) */
1857 #if defined (CONFIG_USER_ONLY)
1863 TCGv addr
= tcg_temp_new();
1865 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp12
);
1867 tcg_gen_movi_i64(addr
, disp12
);
1868 switch ((insn
>> 12) & 0xF) {
1870 /* Longword physical access (hw_ldl/p) */
1871 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
1874 /* Quadword physical access (hw_ldq/p) */
1875 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
1878 /* Longword physical access with lock (hw_ldl_l/p) */
1879 gen_helper_ldl_l_raw(cpu_ir
[ra
], addr
);
1882 /* Quadword physical access with lock (hw_ldq_l/p) */
1883 gen_helper_ldq_l_raw(cpu_ir
[ra
], addr
);
1886 /* Longword virtual PTE fetch (hw_ldl/v) */
1887 tcg_gen_qemu_ld32s(cpu_ir
[ra
], addr
, 0);
1890 /* Quadword virtual PTE fetch (hw_ldq/v) */
1891 tcg_gen_qemu_ld64(cpu_ir
[ra
], addr
, 0);
1894 /* Incpu_ir[ra]id */
1897 /* Incpu_ir[ra]id */
1900 /* Longword virtual access (hw_ldl) */
1901 gen_helper_st_virt_to_phys(addr
, addr
);
1902 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
1905 /* Quadword virtual access (hw_ldq) */
1906 gen_helper_st_virt_to_phys(addr
, addr
);
1907 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
1910 /* Longword virtual access with protection check (hw_ldl/w) */
1911 tcg_gen_qemu_ld32s(cpu_ir
[ra
], addr
, 0);
1914 /* Quadword virtual access with protection check (hw_ldq/w) */
1915 tcg_gen_qemu_ld64(cpu_ir
[ra
], addr
, 0);
1918 /* Longword virtual access with alt access mode (hw_ldl/a)*/
1919 gen_helper_set_alt_mode();
1920 gen_helper_st_virt_to_phys(addr
, addr
);
1921 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
1922 gen_helper_restore_mode();
1925 /* Quadword virtual access with alt access mode (hw_ldq/a) */
1926 gen_helper_set_alt_mode();
1927 gen_helper_st_virt_to_phys(addr
, addr
);
1928 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
1929 gen_helper_restore_mode();
1932 /* Longword virtual access with alternate access mode and
1933 * protection checks (hw_ldl/wa)
1935 gen_helper_set_alt_mode();
1936 gen_helper_ldl_data(cpu_ir
[ra
], addr
);
1937 gen_helper_restore_mode();
1940 /* Quadword virtual access with alternate access mode and
1941 * protection checks (hw_ldq/wa)
1943 gen_helper_set_alt_mode();
1944 gen_helper_ldq_data(cpu_ir
[ra
], addr
);
1945 gen_helper_restore_mode();
1948 tcg_temp_free(addr
);
1956 if (!(ctx
->amask
& AMASK_BWX
))
1958 if (likely(rc
!= 31)) {
1960 tcg_gen_movi_i64(cpu_ir
[rc
], (int64_t)((int8_t)lit
));
1962 tcg_gen_ext8s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1967 if (!(ctx
->amask
& AMASK_BWX
))
1969 if (likely(rc
!= 31)) {
1971 tcg_gen_movi_i64(cpu_ir
[rc
], (int64_t)((int16_t)lit
));
1973 tcg_gen_ext16s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1978 if (!(ctx
->amask
& AMASK_CIX
))
1980 if (likely(rc
!= 31)) {
1982 tcg_gen_movi_i64(cpu_ir
[rc
], ctpop64(lit
));
1984 gen_helper_ctpop(cpu_ir
[rc
], cpu_ir
[rb
]);
1989 if (!(ctx
->amask
& AMASK_MVI
))
1991 gen_perr(ra
, rb
, rc
, islit
, lit
);
1995 if (!(ctx
->amask
& AMASK_CIX
))
1997 if (likely(rc
!= 31)) {
1999 tcg_gen_movi_i64(cpu_ir
[rc
], clz64(lit
));
2001 gen_helper_ctlz(cpu_ir
[rc
], cpu_ir
[rb
]);
2006 if (!(ctx
->amask
& AMASK_CIX
))
2008 if (likely(rc
!= 31)) {
2010 tcg_gen_movi_i64(cpu_ir
[rc
], ctz64(lit
));
2012 gen_helper_cttz(cpu_ir
[rc
], cpu_ir
[rb
]);
2017 if (!(ctx
->amask
& AMASK_MVI
))
2019 if (real_islit
|| ra
!= 31)
2021 gen_unpkbw (rb
, rc
);
2025 if (!(ctx
->amask
& AMASK_MVI
))
2027 if (real_islit
|| ra
!= 31)
2029 gen_unpkbl (rb
, rc
);
2033 if (!(ctx
->amask
& AMASK_MVI
))
2035 if (real_islit
|| ra
!= 31)
2041 if (!(ctx
->amask
& AMASK_MVI
))
2043 if (real_islit
|| ra
!= 31)
2049 if (!(ctx
->amask
& AMASK_MVI
))
2051 gen_minsb8 (ra
, rb
, rc
, islit
, lit
);
2055 if (!(ctx
->amask
& AMASK_MVI
))
2057 gen_minsw4 (ra
, rb
, rc
, islit
, lit
);
2061 if (!(ctx
->amask
& AMASK_MVI
))
2063 gen_minub8 (ra
, rb
, rc
, islit
, lit
);
2067 if (!(ctx
->amask
& AMASK_MVI
))
2069 gen_minuw4 (ra
, rb
, rc
, islit
, lit
);
2073 if (!(ctx
->amask
& AMASK_MVI
))
2075 gen_maxub8 (ra
, rb
, rc
, islit
, lit
);
2079 if (!(ctx
->amask
& AMASK_MVI
))
2081 gen_maxuw4 (ra
, rb
, rc
, islit
, lit
);
2085 if (!(ctx
->amask
& AMASK_MVI
))
2087 gen_maxsb8 (ra
, rb
, rc
, islit
, lit
);
2091 if (!(ctx
->amask
& AMASK_MVI
))
2093 gen_maxsw4 (ra
, rb
, rc
, islit
, lit
);
2097 if (!(ctx
->amask
& AMASK_FIX
))
2099 if (likely(rc
!= 31)) {
2101 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_fir
[ra
]);
2103 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2108 if (!(ctx
->amask
& AMASK_FIX
))
2111 TCGv_i32 tmp1
= tcg_temp_new_i32();
2113 gen_helper_s_to_memory(tmp1
, cpu_fir
[ra
]);
2115 TCGv tmp2
= tcg_const_i64(0);
2116 gen_helper_s_to_memory(tmp1
, tmp2
);
2117 tcg_temp_free(tmp2
);
2119 tcg_gen_ext_i32_i64(cpu_ir
[rc
], tmp1
);
2120 tcg_temp_free_i32(tmp1
);
2128 /* HW_MTPR (PALcode) */
2129 #if defined (CONFIG_USER_ONLY)
2135 TCGv tmp1
= tcg_const_i32(insn
& 0xFF);
2137 gen_helper_mtpr(tmp1
, cpu_ir
[ra
]);
2139 TCGv tmp2
= tcg_const_i64(0);
2140 gen_helper_mtpr(tmp1
, tmp2
);
2141 tcg_temp_free(tmp2
);
2143 tcg_temp_free(tmp1
);
2149 /* HW_REI (PALcode) */
2150 #if defined (CONFIG_USER_ONLY)
2157 gen_helper_hw_rei();
2162 tmp
= tcg_temp_new();
2163 tcg_gen_addi_i64(tmp
, cpu_ir
[rb
], (((int64_t)insn
<< 51) >> 51));
2165 tmp
= tcg_const_i64(((int64_t)insn
<< 51) >> 51);
2166 gen_helper_hw_ret(tmp
);
2173 /* HW_ST (PALcode) */
2174 #if defined (CONFIG_USER_ONLY)
2181 addr
= tcg_temp_new();
2183 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp12
);
2185 tcg_gen_movi_i64(addr
, disp12
);
2189 val
= tcg_temp_new();
2190 tcg_gen_movi_i64(val
, 0);
2192 switch ((insn
>> 12) & 0xF) {
2194 /* Longword physical access */
2195 gen_helper_stl_raw(val
, addr
);
2198 /* Quadword physical access */
2199 gen_helper_stq_raw(val
, addr
);
2202 /* Longword physical access with lock */
2203 gen_helper_stl_c_raw(val
, val
, addr
);
2206 /* Quadword physical access with lock */
2207 gen_helper_stq_c_raw(val
, val
, addr
);
2210 /* Longword virtual access */
2211 gen_helper_st_virt_to_phys(addr
, addr
);
2212 gen_helper_stl_raw(val
, addr
);
2215 /* Quadword virtual access */
2216 gen_helper_st_virt_to_phys(addr
, addr
);
2217 gen_helper_stq_raw(val
, addr
);
2238 /* Longword virtual access with alternate access mode */
2239 gen_helper_set_alt_mode();
2240 gen_helper_st_virt_to_phys(addr
, addr
);
2241 gen_helper_stl_raw(val
, addr
);
2242 gen_helper_restore_mode();
2245 /* Quadword virtual access with alternate access mode */
2246 gen_helper_set_alt_mode();
2247 gen_helper_st_virt_to_phys(addr
, addr
);
2248 gen_helper_stl_raw(val
, addr
);
2249 gen_helper_restore_mode();
2260 tcg_temp_free(addr
);
2266 gen_load_mem(ctx
, &gen_qemu_ldf
, ra
, rb
, disp16
, 1, 0);
2270 gen_load_mem(ctx
, &gen_qemu_ldg
, ra
, rb
, disp16
, 1, 0);
2274 gen_load_mem(ctx
, &gen_qemu_lds
, ra
, rb
, disp16
, 1, 0);
2278 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 1, 0);
2282 gen_store_mem(ctx
, &gen_qemu_stf
, ra
, rb
, disp16
, 1, 0, 0);
2286 gen_store_mem(ctx
, &gen_qemu_stg
, ra
, rb
, disp16
, 1, 0, 0);
2290 gen_store_mem(ctx
, &gen_qemu_sts
, ra
, rb
, disp16
, 1, 0, 0);
2294 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 1, 0, 0);
2298 gen_load_mem(ctx
, &tcg_gen_qemu_ld32s
, ra
, rb
, disp16
, 0, 0);
2302 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 0, 0);
2306 gen_load_mem(ctx
, &gen_qemu_ldl_l
, ra
, rb
, disp16
, 0, 0);
2310 gen_load_mem(ctx
, &gen_qemu_ldq_l
, ra
, rb
, disp16
, 0, 0);
2314 gen_store_mem(ctx
, &tcg_gen_qemu_st32
, ra
, rb
, disp16
, 0, 0, 0);
2318 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 0, 0, 0);
2322 gen_store_mem(ctx
, &gen_qemu_stl_c
, ra
, rb
, disp16
, 0, 0, 1);
2326 gen_store_mem(ctx
, &gen_qemu_stq_c
, ra
, rb
, disp16
, 0, 0, 1);
2331 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
2332 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp21
<< 2));
2335 case 0x31: /* FBEQ */
2336 case 0x32: /* FBLT */
2337 case 0x33: /* FBLE */
2338 gen_fbcond(ctx
, opc
, ra
, disp16
);
2344 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
2345 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp21
<< 2));
2348 case 0x35: /* FBNE */
2349 case 0x36: /* FBGE */
2350 case 0x37: /* FBGT */
2351 gen_fbcond(ctx
, opc
, ra
, disp16
);
2356 gen_bcond(ctx
, TCG_COND_EQ
, ra
, disp21
, 1);
2361 gen_bcond(ctx
, TCG_COND_EQ
, ra
, disp21
, 0);
2366 gen_bcond(ctx
, TCG_COND_LT
, ra
, disp21
, 0);
2371 gen_bcond(ctx
, TCG_COND_LE
, ra
, disp21
, 0);
2376 gen_bcond(ctx
, TCG_COND_NE
, ra
, disp21
, 1);
2381 gen_bcond(ctx
, TCG_COND_NE
, ra
, disp21
, 0);
2386 gen_bcond(ctx
, TCG_COND_GE
, ra
, disp21
, 0);
2391 gen_bcond(ctx
, TCG_COND_GT
, ra
, disp21
, 0);
2403 static inline void gen_intermediate_code_internal(CPUState
*env
,
2404 TranslationBlock
*tb
,
2407 DisasContext ctx
, *ctxp
= &ctx
;
2408 target_ulong pc_start
;
2410 uint16_t *gen_opc_end
;
2418 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2420 ctx
.amask
= env
->amask
;
2422 #if defined (CONFIG_USER_ONLY)
2425 ctx
.mem_idx
= ((env
->ps
>> 3) & 3);
2426 ctx
.pal_mode
= env
->ipr
[IPR_EXC_ADDR
] & 1;
2429 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2431 max_insns
= CF_COUNT_MASK
;
2434 for (ret
= 0; ret
== 0;) {
2435 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2436 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2437 if (bp
->pc
== ctx
.pc
) {
2438 gen_excp(&ctx
, EXCP_DEBUG
, 0);
2444 j
= gen_opc_ptr
- gen_opc_buf
;
2448 gen_opc_instr_start
[lj
++] = 0;
2450 gen_opc_pc
[lj
] = ctx
.pc
;
2451 gen_opc_instr_start
[lj
] = 1;
2452 gen_opc_icount
[lj
] = num_insns
;
2454 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
2456 insn
= ldl_code(ctx
.pc
);
2459 ret
= translate_one(ctxp
, insn
);
2462 /* if we reach a page boundary or are single stepping, stop
2465 if (env
->singlestep_enabled
) {
2466 gen_excp(&ctx
, EXCP_DEBUG
, 0);
2470 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
2473 if (gen_opc_ptr
>= gen_opc_end
)
2476 if (num_insns
>= max_insns
)
2483 if (ret
!= 1 && ret
!= 3) {
2484 tcg_gen_movi_i64(cpu_pc
, ctx
.pc
);
2486 if (tb
->cflags
& CF_LAST_IO
)
2488 /* Generate the return instruction */
2490 gen_icount_end(tb
, num_insns
);
2491 *gen_opc_ptr
= INDEX_op_end
;
2493 j
= gen_opc_ptr
- gen_opc_buf
;
2496 gen_opc_instr_start
[lj
++] = 0;
2498 tb
->size
= ctx
.pc
- pc_start
;
2499 tb
->icount
= num_insns
;
2502 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
2503 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2504 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2505 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 1);
2511 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
2513 gen_intermediate_code_internal(env
, tb
, 0);
2516 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
2518 gen_intermediate_code_internal(env
, tb
, 1);
2526 static const struct cpu_def_t cpu_defs
[] = {
2527 { "ev4", IMPLVER_2106x
, 0 },
2528 { "ev5", IMPLVER_21164
, 0 },
2529 { "ev56", IMPLVER_21164
, AMASK_BWX
},
2530 { "pca56", IMPLVER_21164
, AMASK_BWX
| AMASK_MVI
},
2531 { "ev6", IMPLVER_21264
, AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
},
2532 { "ev67", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
2533 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), },
2534 { "ev68", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
2535 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), },
2536 { "21064", IMPLVER_2106x
, 0 },
2537 { "21164", IMPLVER_21164
, 0 },
2538 { "21164a", IMPLVER_21164
, AMASK_BWX
},
2539 { "21164pc", IMPLVER_21164
, AMASK_BWX
| AMASK_MVI
},
2540 { "21264", IMPLVER_21264
, AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
},
2541 { "21264a", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
2542 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), }
2545 CPUAlphaState
* cpu_alpha_init (const char *cpu_model
)
2549 int implver
, amask
, i
, max
;
2551 env
= qemu_mallocz(sizeof(CPUAlphaState
));
2553 alpha_translate_init();
2556 /* Default to ev67; no reason not to emulate insns by default. */
2557 implver
= IMPLVER_21264
;
2558 amask
= (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
| AMASK_MVI
2559 | AMASK_TRAP
| AMASK_PREFETCH
);
2561 max
= ARRAY_SIZE(cpu_defs
);
2562 for (i
= 0; i
< max
; i
++) {
2563 if (strcmp (cpu_model
, cpu_defs
[i
].name
) == 0) {
2564 implver
= cpu_defs
[i
].implver
;
2565 amask
= cpu_defs
[i
].amask
;
2569 env
->implver
= implver
;
2573 #if defined (CONFIG_USER_ONLY)
2577 /* Initialize IPR */
2578 hwpcb
= env
->ipr
[IPR_PCBB
];
2579 env
->ipr
[IPR_ASN
] = 0;
2580 env
->ipr
[IPR_ASTEN
] = 0;
2581 env
->ipr
[IPR_ASTSR
] = 0;
2582 env
->ipr
[IPR_DATFX
] = 0;
2584 // env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
2585 // env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
2586 // env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
2587 // env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
2588 env
->ipr
[IPR_FEN
] = 0;
2589 env
->ipr
[IPR_IPL
] = 31;
2590 env
->ipr
[IPR_MCES
] = 0;
2591 env
->ipr
[IPR_PERFMON
] = 0; /* Implementation specific */
2592 // env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
2593 env
->ipr
[IPR_SISR
] = 0;
2594 env
->ipr
[IPR_VIRBND
] = -1ULL;
2596 qemu_init_vcpu(env
);
2600 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
2601 unsigned long searched_pc
, int pc_pos
, void *puc
)
2603 env
->pc
= gen_opc_pc
[pc_pos
];