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 /* #define DO_SINGLE_STEP */
36 #define ALPHA_DEBUG_DISAS
37 /* #define DO_TB_FLUSH */
40 #ifdef ALPHA_DEBUG_DISAS
41 # define LOG_DISAS(...) qemu_log(__VA_ARGS__)
43 # define LOG_DISAS(...) do { } while (0)
46 typedef struct DisasContext DisasContext;
50 #if !defined (CONFIG_USER_ONLY)
57 /* global register indexes */
58 static TCGv_ptr cpu_env;
59 static TCGv cpu_ir[31];
60 static TCGv cpu_fir[31];
65 static char cpu_reg_names[10*4+21*5 + 10*5+21*6];
67 #include "gen-icount.h"
69 static void alpha_translate_init(void)
73 static int done_init = 0;
78 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
81 for (i = 0; i < 31; i++) {
82 sprintf(p, "ir%d", i);
83 cpu_ir[i] = tcg_global_mem_new_i64(TCG_AREG0,
84 offsetof(CPUState, ir[i]), p);
85 p += (i < 10) ? 4 : 5;
87 sprintf(p, "fir%d", i);
88 cpu_fir[i] = tcg_global_mem_new_i64(TCG_AREG0,
89 offsetof(CPUState, fir[i]), p);
90 p += (i < 10) ? 5 : 6;
93 cpu_pc = tcg_global_mem_new_i64(TCG_AREG0,
94 offsetof(CPUState, pc), "pc");
96 cpu_lock = tcg_global_mem_new_i64(TCG_AREG0,
97 offsetof(CPUState, lock), "lock");
99 /* register helpers */
106 static inline void gen_excp(DisasContext *ctx, int exception, int error_code)
110 tcg_gen_movi_i64(cpu_pc, ctx->pc);
111 tmp1 = tcg_const_i32(exception);
112 tmp2 = tcg_const_i32(error_code);
113 gen_helper_excp(tmp1, tmp2);
114 tcg_temp_free_i32(tmp2);
115 tcg_temp_free_i32(tmp1);
118 static inline void gen_invalid(DisasContext *ctx)
120 gen_excp(ctx, EXCP_OPCDEC, 0);
123 static inline void gen_qemu_ldf(TCGv t0, TCGv t1, int flags)
125 TCGv tmp = tcg_temp_new();
126 TCGv_i32 tmp32 = tcg_temp_new_i32();
127 tcg_gen_qemu_ld32u(tmp, t1, flags);
128 tcg_gen_trunc_i64_i32(tmp32, tmp);
129 gen_helper_memory_to_f(t0, tmp32);
130 tcg_temp_free_i32(tmp32);
134 static inline void gen_qemu_ldg(TCGv t0, TCGv t1, int flags)
136 TCGv tmp = tcg_temp_new();
137 tcg_gen_qemu_ld64(tmp, t1, flags);
138 gen_helper_memory_to_g(t0, tmp);
142 static inline void gen_qemu_lds(TCGv t0, TCGv t1, int flags)
144 TCGv tmp = tcg_temp_new();
145 TCGv_i32 tmp32 = tcg_temp_new_i32();
146 tcg_gen_qemu_ld32u(tmp, t1, flags);
147 tcg_gen_trunc_i64_i32(tmp32, tmp);
148 gen_helper_memory_to_s(t0, tmp32);
149 tcg_temp_free_i32(tmp32);
153 static inline void gen_qemu_ldl_l(TCGv t0, TCGv t1, int flags)
155 tcg_gen_mov_i64(cpu_lock, t1);
156 tcg_gen_qemu_ld32s(t0, t1, flags);
159 static inline void gen_qemu_ldq_l(TCGv t0, TCGv t1, int flags)
161 tcg_gen_mov_i64(cpu_lock, t1);
162 tcg_gen_qemu_ld64(t0, t1, flags);
165 static inline void gen_load_mem(DisasContext *ctx,
166 void (*tcg_gen_qemu_load)(TCGv t0, TCGv t1,
168 int ra, int rb, int32_t disp16, int fp,
173 if (unlikely(ra == 31))
176 addr = tcg_temp_new();
178 tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
180 tcg_gen_andi_i64(addr, addr, ~0x7);
184 tcg_gen_movi_i64(addr, disp16);
187 tcg_gen_qemu_load(cpu_fir[ra], addr, ctx->mem_idx);
189 tcg_gen_qemu_load(cpu_ir[ra], addr, ctx->mem_idx);
193 static inline void gen_qemu_stf(TCGv t0, TCGv t1, int flags)
195 TCGv_i32 tmp32 = tcg_temp_new_i32();
196 TCGv tmp = tcg_temp_new();
197 gen_helper_f_to_memory(tmp32, t0);
198 tcg_gen_extu_i32_i64(tmp, tmp32);
199 tcg_gen_qemu_st32(tmp, t1, flags);
201 tcg_temp_free_i32(tmp32);
204 static inline void gen_qemu_stg(TCGv t0, TCGv t1, int flags)
206 TCGv tmp = tcg_temp_new();
207 gen_helper_g_to_memory(tmp, t0);
208 tcg_gen_qemu_st64(tmp, t1, flags);
212 static inline void gen_qemu_sts(TCGv t0, TCGv t1, int flags)
214 TCGv_i32 tmp32 = tcg_temp_new_i32();
215 TCGv tmp = tcg_temp_new();
216 gen_helper_s_to_memory(tmp32, t0);
217 tcg_gen_extu_i32_i64(tmp, tmp32);
218 tcg_gen_qemu_st32(tmp, t1, flags);
220 tcg_temp_free_i32(tmp32);
223 static inline void gen_qemu_stl_c(TCGv t0, TCGv t1, int flags)
227 l1 = gen_new_label();
228 l2 = gen_new_label();
229 tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1);
230 tcg_gen_qemu_st32(t0, t1, flags);
231 tcg_gen_movi_i64(t0, 1);
234 tcg_gen_movi_i64(t0, 0);
236 tcg_gen_movi_i64(cpu_lock, -1);
239 static inline void gen_qemu_stq_c(TCGv t0, TCGv t1, int flags)
243 l1 = gen_new_label();
244 l2 = gen_new_label();
245 tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1);
246 tcg_gen_qemu_st64(t0, t1, flags);
247 tcg_gen_movi_i64(t0, 1);
250 tcg_gen_movi_i64(t0, 0);
252 tcg_gen_movi_i64(cpu_lock, -1);
255 static inline void gen_store_mem(DisasContext *ctx,
256 void (*tcg_gen_qemu_store)(TCGv t0, TCGv t1,
258 int ra, int rb, int32_t disp16, int fp,
259 int clear, int local)
263 addr = tcg_temp_local_new();
265 addr = tcg_temp_new();
267 tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
269 tcg_gen_andi_i64(addr, addr, ~0x7);
273 tcg_gen_movi_i64(addr, disp16);
277 tcg_gen_qemu_store(cpu_fir[ra], addr, ctx->mem_idx);
279 tcg_gen_qemu_store(cpu_ir[ra], addr, ctx->mem_idx);
283 zero = tcg_const_local_i64(0);
285 zero = tcg_const_i64(0);
286 tcg_gen_qemu_store(zero, addr, ctx->mem_idx);
292 static inline void gen_bcond(DisasContext *ctx, TCGCond cond, int ra,
293 int32_t disp, int mask)
297 l1 = gen_new_label();
298 l2 = gen_new_label();
299 if (likely(ra != 31)) {
301 TCGv tmp = tcg_temp_new();
302 tcg_gen_andi_i64(tmp, cpu_ir[ra], 1);
303 tcg_gen_brcondi_i64(cond, tmp, 0, l1);
306 tcg_gen_brcondi_i64(cond, cpu_ir[ra], 0, l1);
308 /* Very uncommon case - Do not bother to optimize. */
309 TCGv tmp = tcg_const_i64(0);
310 tcg_gen_brcondi_i64(cond, tmp, 0, l1);
313 tcg_gen_movi_i64(cpu_pc, ctx->pc);
316 tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp << 2));
320 static inline void gen_fbcond(DisasContext *ctx, int opc, int ra,
327 l1 = gen_new_label();
328 l2 = gen_new_label();
330 tmp = tcg_temp_new();
333 tmp = tcg_const_i64(0);
337 case 0x31: /* FBEQ */
338 gen_helper_cmpfeq(tmp, src);
340 case 0x32: /* FBLT */
341 gen_helper_cmpflt(tmp, src);
343 case 0x33: /* FBLE */
344 gen_helper_cmpfle(tmp, src);
346 case 0x35: /* FBNE */
347 gen_helper_cmpfne(tmp, src);
349 case 0x36: /* FBGE */
350 gen_helper_cmpfge(tmp, src);
352 case 0x37: /* FBGT */
353 gen_helper_cmpfgt(tmp, src);
358 tcg_gen_brcondi_i64(TCG_COND_NE, tmp, 0, l1);
359 tcg_gen_movi_i64(cpu_pc, ctx->pc);
362 tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp16 << 2));
366 static inline void gen_cmov(TCGCond inv_cond, int ra, int rb, int rc,
367 int islit, uint8_t lit, int mask)
371 if (unlikely(rc == 31))
374 l1 = gen_new_label();
378 TCGv tmp = tcg_temp_new();
379 tcg_gen_andi_i64(tmp, cpu_ir[ra], 1);
380 tcg_gen_brcondi_i64(inv_cond, tmp, 0, l1);
383 tcg_gen_brcondi_i64(inv_cond, cpu_ir[ra], 0, l1);
385 /* Very uncommon case - Do not bother to optimize. */
386 TCGv tmp = tcg_const_i64(0);
387 tcg_gen_brcondi_i64(inv_cond, tmp, 0, l1);
392 tcg_gen_movi_i64(cpu_ir[rc], lit);
394 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
398 #define FARITH2(name) \
399 static inline void glue(gen_f, name)(int rb, int rc) \
401 if (unlikely(rc == 31)) \
405 gen_helper_ ## name (cpu_fir[rc], cpu_fir[rb]); \
407 TCGv tmp = tcg_const_i64(0); \
408 gen_helper_ ## name (cpu_fir[rc], tmp); \
409 tcg_temp_free(tmp); \
430 #define FARITH3(name) \
431 static inline void glue(gen_f, name)(int ra, int rb, int rc) \
433 if (unlikely(rc == 31)) \
438 gen_helper_ ## name (cpu_fir[rc], cpu_fir[ra], cpu_fir[rb]); \
440 TCGv tmp = tcg_const_i64(0); \
441 gen_helper_ ## name (cpu_fir[rc], cpu_fir[ra], tmp); \
442 tcg_temp_free(tmp); \
445 TCGv tmp = tcg_const_i64(0); \
447 gen_helper_ ## name (cpu_fir[rc], tmp, cpu_fir[rb]); \
449 gen_helper_ ## name (cpu_fir[rc], tmp, tmp); \
450 tcg_temp_free(tmp); \
481 #define FCMOV(name) \
482 static inline void glue(gen_f, name)(int ra, int rb, int rc) \
487 if (unlikely(rc == 31)) \
490 l1 = gen_new_label(); \
491 tmp = tcg_temp_new(); \
493 tmp = tcg_temp_new(); \
494 gen_helper_ ## name (tmp, cpu_fir[ra]); \
496 tmp = tcg_const_i64(0); \
497 gen_helper_ ## name (tmp, tmp); \
499 tcg_gen_brcondi_i64(TCG_COND_EQ, tmp, 0, l1); \
501 tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]); \
503 tcg_gen_movi_i64(cpu_fir[rc], 0); \
513 /* EXTWH, EXTWH, EXTLH, EXTQH */
514 static inline void gen_ext_h(void(*tcg_gen_ext_i64)(TCGv t0, TCGv t1),
515 int ra, int rb, int rc, int islit, uint8_t lit)
517 if (unlikely(rc == 31))
523 tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], 64 - ((lit & 7) * 8));
525 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[ra]);
528 tmp1 = tcg_temp_new();
529 tcg_gen_andi_i64(tmp1, cpu_ir[rb], 7);
530 tcg_gen_shli_i64(tmp1, tmp1, 3);
531 tmp2 = tcg_const_i64(64);
532 tcg_gen_sub_i64(tmp1, tmp2, tmp1);
534 tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], tmp1);
538 tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
540 tcg_gen_movi_i64(cpu_ir[rc], 0);
543 /* EXTBL, EXTWL, EXTWL, EXTLL, EXTQL */
544 static inline void gen_ext_l(void(*tcg_gen_ext_i64)(TCGv t0, TCGv t1),
545 int ra, int rb, int rc, int islit, uint8_t lit)
547 if (unlikely(rc == 31))
552 tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], (lit & 7) * 8);
554 TCGv tmp = tcg_temp_new();
555 tcg_gen_andi_i64(tmp, cpu_ir[rb], 7);
556 tcg_gen_shli_i64(tmp, tmp, 3);
557 tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], tmp);
561 tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
563 tcg_gen_movi_i64(cpu_ir[rc], 0);
566 /* Code to call arith3 helpers */
567 #define ARITH3(name) \
568 static inline void glue(gen_, name)(int ra, int rb, int rc, int islit,\
571 if (unlikely(rc == 31)) \
576 TCGv tmp = tcg_const_i64(lit); \
577 gen_helper_ ## name(cpu_ir[rc], cpu_ir[ra], tmp); \
578 tcg_temp_free(tmp); \
580 gen_helper_ ## name (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]); \
582 TCGv tmp1 = tcg_const_i64(0); \
584 TCGv tmp2 = tcg_const_i64(lit); \
585 gen_helper_ ## name (cpu_ir[rc], tmp1, tmp2); \
586 tcg_temp_free(tmp2); \
588 gen_helper_ ## name (cpu_ir[rc], tmp1, cpu_ir[rb]); \
589 tcg_temp_free(tmp1); \
617 static inline void gen_cmp(TCGCond cond, int ra, int rb, int rc, int islit,
623 if (unlikely(rc == 31))
626 l1 = gen_new_label();
627 l2 = gen_new_label();
630 tmp = tcg_temp_new();
631 tcg_gen_mov_i64(tmp, cpu_ir[ra]);
633 tmp = tcg_const_i64(0);
635 tcg_gen_brcondi_i64(cond, tmp, lit, l1);
637 tcg_gen_brcond_i64(cond, tmp, cpu_ir[rb], l1);
639 tcg_gen_movi_i64(cpu_ir[rc], 0);
642 tcg_gen_movi_i64(cpu_ir[rc], 1);
646 static inline int translate_one(DisasContext *ctx, uint32_t insn)
649 int32_t disp21, disp16, disp12;
651 uint8_t opc, ra, rb, rc, sbz, fpfn, fn7, fn2, islit;
655 /* Decode all instruction fields */
657 ra = (insn >> 21) & 0x1F;
658 rb = (insn >> 16) & 0x1F;
660 sbz = (insn >> 13) & 0x07;
661 islit = (insn >> 12) & 1;
662 if (rb == 31 && !islit) {
666 lit = (insn >> 13) & 0xFF;
667 palcode = insn & 0x03FFFFFF;
668 disp21 = ((int32_t)((insn & 0x001FFFFF) << 11)) >> 11;
669 disp16 = (int16_t)(insn & 0x0000FFFF);
670 disp12 = (int32_t)((insn & 0x00000FFF) << 20) >> 20;
671 fn16 = insn & 0x0000FFFF;
672 fn11 = (insn >> 5) & 0x000007FF;
674 fn7 = (insn >> 5) & 0x0000007F;
675 fn2 = (insn >> 5) & 0x00000003;
677 LOG_DISAS("opc %02x ra %d rb %d rc %d disp16 %04x\n",
678 opc, ra, rb, rc, disp16);
682 if (palcode >= 0x80 && palcode < 0xC0) {
683 /* Unprivileged PAL call */
684 gen_excp(ctx, EXCP_CALL_PAL + ((palcode & 0x3F) << 6), 0);
685 #if !defined (CONFIG_USER_ONLY)
686 } else if (palcode < 0x40) {
687 /* Privileged PAL code */
688 if (ctx->mem_idx & 1)
691 gen_excp(ctx, EXCP_CALL_PALP + ((palcode & 0x3F) << 6), 0);
694 /* Invalid PAL call */
722 if (likely(ra != 31)) {
724 tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16);
726 tcg_gen_movi_i64(cpu_ir[ra], disp16);
731 if (likely(ra != 31)) {
733 tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16 << 16);
735 tcg_gen_movi_i64(cpu_ir[ra], disp16 << 16);
740 if (!(ctx->amask & AMASK_BWX))
742 gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
746 gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
750 if (!(ctx->amask & AMASK_BWX))
752 gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 0);
756 gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0, 0);
760 gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0, 0);
764 gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1, 0);
770 if (likely(rc != 31)) {
773 tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
774 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
776 tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
777 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
781 tcg_gen_movi_i64(cpu_ir[rc], lit);
783 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
789 if (likely(rc != 31)) {
791 TCGv tmp = tcg_temp_new();
792 tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
794 tcg_gen_addi_i64(tmp, tmp, lit);
796 tcg_gen_add_i64(tmp, tmp, cpu_ir[rb]);
797 tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
801 tcg_gen_movi_i64(cpu_ir[rc], lit);
803 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
809 if (likely(rc != 31)) {
812 tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
814 tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
815 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
818 tcg_gen_movi_i64(cpu_ir[rc], -lit);
820 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
821 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
827 if (likely(rc != 31)) {
829 TCGv tmp = tcg_temp_new();
830 tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
832 tcg_gen_subi_i64(tmp, tmp, lit);
834 tcg_gen_sub_i64(tmp, tmp, cpu_ir[rb]);
835 tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
839 tcg_gen_movi_i64(cpu_ir[rc], -lit);
841 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
842 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
849 gen_cmpbge(ra, rb, rc, islit, lit);
853 if (likely(rc != 31)) {
855 TCGv tmp = tcg_temp_new();
856 tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
858 tcg_gen_addi_i64(tmp, tmp, lit);
860 tcg_gen_add_i64(tmp, tmp, cpu_ir[rb]);
861 tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
865 tcg_gen_movi_i64(cpu_ir[rc], lit);
867 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
873 if (likely(rc != 31)) {
875 TCGv tmp = tcg_temp_new();
876 tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
878 tcg_gen_subi_i64(tmp, tmp, lit);
880 tcg_gen_sub_i64(tmp, tmp, cpu_ir[rb]);
881 tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
885 tcg_gen_movi_i64(cpu_ir[rc], -lit);
887 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
888 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
895 gen_cmp(TCG_COND_LTU, ra, rb, rc, islit, lit);
899 if (likely(rc != 31)) {
902 tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
904 tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
907 tcg_gen_movi_i64(cpu_ir[rc], lit);
909 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
915 if (likely(rc != 31)) {
917 TCGv tmp = tcg_temp_new();
918 tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
920 tcg_gen_addi_i64(cpu_ir[rc], tmp, lit);
922 tcg_gen_add_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
926 tcg_gen_movi_i64(cpu_ir[rc], lit);
928 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
934 if (likely(rc != 31)) {
937 tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
939 tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
942 tcg_gen_movi_i64(cpu_ir[rc], -lit);
944 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
950 if (likely(rc != 31)) {
952 TCGv tmp = tcg_temp_new();
953 tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
955 tcg_gen_subi_i64(cpu_ir[rc], tmp, lit);
957 tcg_gen_sub_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
961 tcg_gen_movi_i64(cpu_ir[rc], -lit);
963 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
969 gen_cmp(TCG_COND_EQ, ra, rb, rc, islit, lit);
973 if (likely(rc != 31)) {
975 TCGv tmp = tcg_temp_new();
976 tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
978 tcg_gen_addi_i64(cpu_ir[rc], tmp, lit);
980 tcg_gen_add_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
984 tcg_gen_movi_i64(cpu_ir[rc], lit);
986 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
992 if (likely(rc != 31)) {
994 TCGv tmp = tcg_temp_new();
995 tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
997 tcg_gen_subi_i64(cpu_ir[rc], tmp, lit);
999 tcg_gen_sub_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
1003 tcg_gen_movi_i64(cpu_ir[rc], -lit);
1005 tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1011 gen_cmp(TCG_COND_LEU, ra, rb, rc, islit, lit);
1015 gen_addlv(ra, rb, rc, islit, lit);
1019 gen_sublv(ra, rb, rc, islit, lit);
1023 gen_cmp(TCG_COND_LT, ra, rb, rc, islit, lit);
1027 gen_addqv(ra, rb, rc, islit, lit);
1031 gen_subqv(ra, rb, rc, islit, lit);
1035 gen_cmp(TCG_COND_LE, ra, rb, rc, islit, lit);
1045 if (likely(rc != 31)) {
1047 tcg_gen_movi_i64(cpu_ir[rc], 0);
1049 tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], lit);
1051 tcg_gen_and_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1056 if (likely(rc != 31)) {
1059 tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1061 tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1063 tcg_gen_movi_i64(cpu_ir[rc], 0);
1068 gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 1);
1072 gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 1);
1076 if (likely(rc != 31)) {
1079 tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], lit);
1081 tcg_gen_or_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1084 tcg_gen_movi_i64(cpu_ir[rc], lit);
1086 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1092 gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 0);
1096 gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 0);
1100 if (likely(rc != 31)) {
1103 tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1105 tcg_gen_orc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1108 tcg_gen_movi_i64(cpu_ir[rc], ~lit);
1110 tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
1116 if (likely(rc != 31)) {
1119 tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], lit);
1121 tcg_gen_xor_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1124 tcg_gen_movi_i64(cpu_ir[rc], lit);
1126 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1132 gen_cmov(TCG_COND_GE, ra, rb, rc, islit, lit, 0);
1136 gen_cmov(TCG_COND_LT, ra, rb, rc, islit, lit, 0);
1140 if (likely(rc != 31)) {
1143 tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1145 tcg_gen_eqv_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1148 tcg_gen_movi_i64(cpu_ir[rc], ~lit);
1150 tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
1156 if (likely(rc != 31)) {
1158 tcg_gen_movi_i64(cpu_ir[rc], lit);
1160 tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1161 switch (ctx->env->implver) {
1163 /* EV4, EV45, LCA, LCA45 & EV5 */
1168 tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[rc],
1169 ~(uint64_t)ctx->amask);
1176 gen_cmov(TCG_COND_GT, ra, rb, rc, islit, lit, 0);
1180 gen_cmov(TCG_COND_LE, ra, rb, rc, islit, lit, 0);
1185 tcg_gen_movi_i64(cpu_ir[rc], ctx->env->implver);
1195 gen_mskbl(ra, rb, rc, islit, lit);
1199 gen_ext_l(&tcg_gen_ext8u_i64, ra, rb, rc, islit, lit);
1203 gen_insbl(ra, rb, rc, islit, lit);
1207 gen_mskwl(ra, rb, rc, islit, lit);
1211 gen_ext_l(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
1215 gen_inswl(ra, rb, rc, islit, lit);
1219 gen_mskll(ra, rb, rc, islit, lit);
1223 gen_ext_l(&tcg_gen_ext32u_i64, ra, rb, rc, islit, lit);
1227 gen_insll(ra, rb, rc, islit, lit);
1231 gen_zap(ra, rb, rc, islit, lit);
1235 gen_zapnot(ra, rb, rc, islit, lit);
1239 gen_mskql(ra, rb, rc, islit, lit);
1243 if (likely(rc != 31)) {
1246 tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1248 TCGv shift = tcg_temp_new();
1249 tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
1250 tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], shift);
1251 tcg_temp_free(shift);
1254 tcg_gen_movi_i64(cpu_ir[rc], 0);
1259 gen_ext_l(NULL, ra, rb, rc, islit, lit);
1263 if (likely(rc != 31)) {
1266 tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1268 TCGv shift = tcg_temp_new();
1269 tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
1270 tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], shift);
1271 tcg_temp_free(shift);
1274 tcg_gen_movi_i64(cpu_ir[rc], 0);
1279 gen_insql(ra, rb, rc, islit, lit);
1283 if (likely(rc != 31)) {
1286 tcg_gen_sari_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1288 TCGv shift = tcg_temp_new();
1289 tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
1290 tcg_gen_sar_i64(cpu_ir[rc], cpu_ir[ra], shift);
1291 tcg_temp_free(shift);
1294 tcg_gen_movi_i64(cpu_ir[rc], 0);
1299 gen_mskwh(ra, rb, rc, islit, lit);
1303 gen_inswh(ra, rb, rc, islit, lit);
1307 gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
1311 gen_msklh(ra, rb, rc, islit, lit);
1315 gen_inslh(ra, rb, rc, islit, lit);
1319 gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
1323 gen_mskqh(ra, rb, rc, islit, lit);
1327 gen_insqh(ra, rb, rc, islit, lit);
1331 gen_ext_h(NULL, ra, rb, rc, islit, lit);
1341 if (likely(rc != 31)) {
1343 tcg_gen_movi_i64(cpu_ir[rc], 0);
1346 tcg_gen_muli_i64(cpu_ir[rc], cpu_ir[ra], lit);
1348 tcg_gen_mul_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1349 tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1355 if (likely(rc != 31)) {
1357 tcg_gen_movi_i64(cpu_ir[rc], 0);
1359 tcg_gen_muli_i64(cpu_ir[rc], cpu_ir[ra], lit);
1361 tcg_gen_mul_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1366 gen_umulh(ra, rb, rc, islit, lit);
1370 gen_mullv(ra, rb, rc, islit, lit);
1374 gen_mulqv(ra, rb, rc, islit, lit);
1381 switch (fpfn) { /* f11 & 0x3F */
1384 if (!(ctx->amask & AMASK_FIX))
1386 if (likely(rc != 31)) {
1388 TCGv_i32 tmp = tcg_temp_new_i32();
1389 tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
1390 gen_helper_memory_to_s(cpu_fir[rc], tmp);
1391 tcg_temp_free_i32(tmp);
1393 tcg_gen_movi_i64(cpu_fir[rc], 0);
1398 if (!(ctx->amask & AMASK_FIX))
1404 if (!(ctx->amask & AMASK_FIX))
1410 if (!(ctx->amask & AMASK_FIX))
1412 if (likely(rc != 31)) {
1414 TCGv_i32 tmp = tcg_temp_new_i32();
1415 tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
1416 gen_helper_memory_to_f(cpu_fir[rc], tmp);
1417 tcg_temp_free_i32(tmp);
1419 tcg_gen_movi_i64(cpu_fir[rc], 0);
1424 if (!(ctx->amask & AMASK_FIX))
1426 if (likely(rc != 31)) {
1428 tcg_gen_mov_i64(cpu_fir[rc], cpu_ir[ra]);
1430 tcg_gen_movi_i64(cpu_fir[rc], 0);
1435 if (!(ctx->amask & AMASK_FIX))
1441 if (!(ctx->amask & AMASK_FIX))
1450 /* VAX floating point */
1451 /* XXX: rounding mode and trap are ignored (!) */
1452 switch (fpfn) { /* f11 & 0x3F */
1455 gen_faddf(ra, rb, rc);
1459 gen_fsubf(ra, rb, rc);
1463 gen_fmulf(ra, rb, rc);
1467 gen_fdivf(ra, rb, rc);
1479 gen_faddg(ra, rb, rc);
1483 gen_fsubg(ra, rb, rc);
1487 gen_fmulg(ra, rb, rc);
1491 gen_fdivg(ra, rb, rc);
1495 gen_fcmpgeq(ra, rb, rc);
1499 gen_fcmpglt(ra, rb, rc);
1503 gen_fcmpgle(ra, rb, rc);
1534 /* IEEE floating-point */
1535 /* XXX: rounding mode and traps are ignored (!) */
1536 switch (fpfn) { /* f11 & 0x3F */
1539 gen_fadds(ra, rb, rc);
1543 gen_fsubs(ra, rb, rc);
1547 gen_fmuls(ra, rb, rc);
1551 gen_fdivs(ra, rb, rc);
1555 gen_faddt(ra, rb, rc);
1559 gen_fsubt(ra, rb, rc);
1563 gen_fmult(ra, rb, rc);
1567 gen_fdivt(ra, rb, rc);
1571 gen_fcmptun(ra, rb, rc);
1575 gen_fcmpteq(ra, rb, rc);
1579 gen_fcmptlt(ra, rb, rc);
1583 gen_fcmptle(ra, rb, rc);
1586 /* XXX: incorrect */
1587 if (fn11 == 0x2AC || fn11 == 0x6AC) {
1618 if (likely(rc != 31)) {
1621 tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
1624 gen_fcpys(ra, rb, rc);
1629 gen_fcpysn(ra, rb, rc);
1633 gen_fcpyse(ra, rb, rc);
1637 if (likely(ra != 31))
1638 gen_helper_store_fpcr(cpu_fir[ra]);
1640 TCGv tmp = tcg_const_i64(0);
1641 gen_helper_store_fpcr(tmp);
1647 if (likely(ra != 31))
1648 gen_helper_load_fpcr(cpu_fir[ra]);
1652 gen_fcmpfeq(ra, rb, rc);
1656 gen_fcmpfne(ra, rb, rc);
1660 gen_fcmpflt(ra, rb, rc);
1664 gen_fcmpfge(ra, rb, rc);
1668 gen_fcmpfle(ra, rb, rc);
1672 gen_fcmpfgt(ra, rb, rc);
1680 gen_fcvtqlv(rb, rc);
1684 gen_fcvtqlsv(rb, rc);
1691 switch ((uint16_t)disp16) {
1694 /* No-op. Just exit from the current tb */
1699 /* No-op. Just exit from the current tb */
1721 gen_helper_load_pcc(cpu_ir[ra]);
1726 gen_helper_rc(cpu_ir[ra]);
1734 gen_helper_rs(cpu_ir[ra]);
1745 /* HW_MFPR (PALcode) */
1746 #if defined (CONFIG_USER_ONLY)
1752 TCGv tmp = tcg_const_i32(insn & 0xFF);
1753 gen_helper_mfpr(cpu_ir[ra], tmp, cpu_ir[ra]);
1760 tcg_gen_andi_i64(cpu_pc, cpu_ir[rb], ~3);
1762 tcg_gen_movi_i64(cpu_pc, 0);
1764 tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
1765 /* Those four jumps only differ by the branch prediction hint */
1783 /* HW_LD (PALcode) */
1784 #if defined (CONFIG_USER_ONLY)
1790 TCGv addr = tcg_temp_new();
1792 tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
1794 tcg_gen_movi_i64(addr, disp12);
1795 switch ((insn >> 12) & 0xF) {
1797 /* Longword physical access (hw_ldl/p) */
1798 gen_helper_ldl_raw(cpu_ir[ra], addr);
1801 /* Quadword physical access (hw_ldq/p) */
1802 gen_helper_ldq_raw(cpu_ir[ra], addr);
1805 /* Longword physical access with lock (hw_ldl_l/p) */
1806 gen_helper_ldl_l_raw(cpu_ir[ra], addr);
1809 /* Quadword physical access with lock (hw_ldq_l/p) */
1810 gen_helper_ldq_l_raw(cpu_ir[ra], addr);
1813 /* Longword virtual PTE fetch (hw_ldl/v) */
1814 tcg_gen_qemu_ld32s(cpu_ir[ra], addr, 0);
1817 /* Quadword virtual PTE fetch (hw_ldq/v) */
1818 tcg_gen_qemu_ld64(cpu_ir[ra], addr, 0);
1821 /* Incpu_ir[ra]id */
1824 /* Incpu_ir[ra]id */
1827 /* Longword virtual access (hw_ldl) */
1828 gen_helper_st_virt_to_phys(addr, addr);
1829 gen_helper_ldl_raw(cpu_ir[ra], addr);
1832 /* Quadword virtual access (hw_ldq) */
1833 gen_helper_st_virt_to_phys(addr, addr);
1834 gen_helper_ldq_raw(cpu_ir[ra], addr);
1837 /* Longword virtual access with protection check (hw_ldl/w) */
1838 tcg_gen_qemu_ld32s(cpu_ir[ra], addr, 0);
1841 /* Quadword virtual access with protection check (hw_ldq/w) */
1842 tcg_gen_qemu_ld64(cpu_ir[ra], addr, 0);
1845 /* Longword virtual access with alt access mode (hw_ldl/a)*/
1846 gen_helper_set_alt_mode();
1847 gen_helper_st_virt_to_phys(addr, addr);
1848 gen_helper_ldl_raw(cpu_ir[ra], addr);
1849 gen_helper_restore_mode();
1852 /* Quadword virtual access with alt access mode (hw_ldq/a) */
1853 gen_helper_set_alt_mode();
1854 gen_helper_st_virt_to_phys(addr, addr);
1855 gen_helper_ldq_raw(cpu_ir[ra], addr);
1856 gen_helper_restore_mode();
1859 /* Longword virtual access with alternate access mode and
1860 * protection checks (hw_ldl/wa)
1862 gen_helper_set_alt_mode();
1863 gen_helper_ldl_data(cpu_ir[ra], addr);
1864 gen_helper_restore_mode();
1867 /* Quadword virtual access with alternate access mode and
1868 * protection checks (hw_ldq/wa)
1870 gen_helper_set_alt_mode();
1871 gen_helper_ldq_data(cpu_ir[ra], addr);
1872 gen_helper_restore_mode();
1875 tcg_temp_free(addr);
1883 if (!(ctx->amask & AMASK_BWX))
1885 if (likely(rc != 31)) {
1887 tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int8_t)lit));
1889 tcg_gen_ext8s_i64(cpu_ir[rc], cpu_ir[rb]);
1894 if (!(ctx->amask & AMASK_BWX))
1896 if (likely(rc != 31)) {
1898 tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
1900 tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
1905 if (!(ctx->amask & AMASK_CIX))
1907 if (likely(rc != 31)) {
1909 tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
1911 gen_helper_ctpop(cpu_ir[rc], cpu_ir[rb]);
1916 if (!(ctx->amask & AMASK_MVI))
1923 if (!(ctx->amask & AMASK_CIX))
1925 if (likely(rc != 31)) {
1927 tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
1929 gen_helper_ctlz(cpu_ir[rc], cpu_ir[rb]);
1934 if (!(ctx->amask & AMASK_CIX))
1936 if (likely(rc != 31)) {
1938 tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
1940 gen_helper_cttz(cpu_ir[rc], cpu_ir[rb]);
1945 if (!(ctx->amask & AMASK_MVI))
1952 if (!(ctx->amask & AMASK_MVI))
1959 if (!(ctx->amask & AMASK_MVI))
1966 if (!(ctx->amask & AMASK_MVI))
1973 if (!(ctx->amask & AMASK_MVI))
1980 if (!(ctx->amask & AMASK_MVI))
1987 if (!(ctx->amask & AMASK_MVI))
1994 if (!(ctx->amask & AMASK_MVI))
2001 if (!(ctx->amask & AMASK_MVI))
2008 if (!(ctx->amask & AMASK_MVI))
2015 if (!(ctx->amask & AMASK_MVI))
2022 if (!(ctx->amask & AMASK_MVI))
2029 if (!(ctx->amask & AMASK_FIX))
2031 if (likely(rc != 31)) {
2033 tcg_gen_mov_i64(cpu_ir[rc], cpu_fir[ra]);
2035 tcg_gen_movi_i64(cpu_ir[rc], 0);
2040 if (!(ctx->amask & AMASK_FIX))
2043 TCGv_i32 tmp1 = tcg_temp_new_i32();
2045 gen_helper_s_to_memory(tmp1, cpu_fir[ra]);
2047 TCGv tmp2 = tcg_const_i64(0);
2048 gen_helper_s_to_memory(tmp1, tmp2);
2049 tcg_temp_free(tmp2);
2051 tcg_gen_ext_i32_i64(cpu_ir[rc], tmp1);
2052 tcg_temp_free_i32(tmp1);
2060 /* HW_MTPR (PALcode) */
2061 #if defined (CONFIG_USER_ONLY)
2067 TCGv tmp1 = tcg_const_i32(insn & 0xFF);
2069 gen_helper_mtpr(tmp1, cpu_ir[ra]);
2071 TCGv tmp2 = tcg_const_i64(0);
2072 gen_helper_mtpr(tmp1, tmp2);
2073 tcg_temp_free(tmp2);
2075 tcg_temp_free(tmp1);
2081 /* HW_REI (PALcode) */
2082 #if defined (CONFIG_USER_ONLY)
2089 gen_helper_hw_rei();
2094 tmp = tcg_temp_new();
2095 tcg_gen_addi_i64(tmp, cpu_ir[rb], (((int64_t)insn << 51) >> 51));
2097 tmp = tcg_const_i64(((int64_t)insn << 51) >> 51);
2098 gen_helper_hw_ret(tmp);
2105 /* HW_ST (PALcode) */
2106 #if defined (CONFIG_USER_ONLY)
2113 addr = tcg_temp_new();
2115 tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
2117 tcg_gen_movi_i64(addr, disp12);
2121 val = tcg_temp_new();
2122 tcg_gen_movi_i64(val, 0);
2124 switch ((insn >> 12) & 0xF) {
2126 /* Longword physical access */
2127 gen_helper_stl_raw(val, addr);
2130 /* Quadword physical access */
2131 gen_helper_stq_raw(val, addr);
2134 /* Longword physical access with lock */
2135 gen_helper_stl_c_raw(val, val, addr);
2138 /* Quadword physical access with lock */
2139 gen_helper_stq_c_raw(val, val, addr);
2142 /* Longword virtual access */
2143 gen_helper_st_virt_to_phys(addr, addr);
2144 gen_helper_stl_raw(val, addr);
2147 /* Quadword virtual access */
2148 gen_helper_st_virt_to_phys(addr, addr);
2149 gen_helper_stq_raw(val, addr);
2170 /* Longword virtual access with alternate access mode */
2171 gen_helper_set_alt_mode();
2172 gen_helper_st_virt_to_phys(addr, addr);
2173 gen_helper_stl_raw(val, addr);
2174 gen_helper_restore_mode();
2177 /* Quadword virtual access with alternate access mode */
2178 gen_helper_set_alt_mode();
2179 gen_helper_st_virt_to_phys(addr, addr);
2180 gen_helper_stl_raw(val, addr);
2181 gen_helper_restore_mode();
2192 tcg_temp_free(addr);
2198 gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
2202 gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0);
2206 gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0);
2210 gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0);
2214 gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0, 0);
2218 gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0, 0);
2222 gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0, 0);
2226 gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0, 0);
2230 gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0);
2234 gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0);
2238 gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0);
2242 gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0);
2246 gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0, 0);
2250 gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0, 0);
2254 gen_store_mem(ctx, &gen_qemu_stl_c, ra, rb, disp16, 0, 0, 1);
2258 gen_store_mem(ctx, &gen_qemu_stq_c, ra, rb, disp16, 0, 0, 1);
2263 tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
2264 tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp21 << 2));
2267 case 0x31: /* FBEQ */
2268 case 0x32: /* FBLT */
2269 case 0x33: /* FBLE */
2270 gen_fbcond(ctx, opc, ra, disp16);
2276 tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
2277 tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp21 << 2));
2280 case 0x35: /* FBNE */
2281 case 0x36: /* FBGE */
2282 case 0x37: /* FBGT */
2283 gen_fbcond(ctx, opc, ra, disp16);
2288 gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 1);
2293 gen_bcond(ctx, TCG_COND_EQ, ra, disp21, 0);
2298 gen_bcond(ctx, TCG_COND_LT, ra, disp21, 0);
2303 gen_bcond(ctx, TCG_COND_LE, ra, disp21, 0);
2308 gen_bcond(ctx, TCG_COND_NE, ra, disp21, 1);
2313 gen_bcond(ctx, TCG_COND_NE, ra, disp21, 0);
2318 gen_bcond(ctx, TCG_COND_GE, ra, disp21, 0);
2323 gen_bcond(ctx, TCG_COND_GT, ra, disp21, 0);
2335 static inline void gen_intermediate_code_internal(CPUState *env,
2336 TranslationBlock *tb,
2339 #if defined ALPHA_DEBUG_DISAS
2340 static int insn_count;
2342 DisasContext ctx, *ctxp = &ctx;
2343 target_ulong pc_start;
2345 uint16_t *gen_opc_end;
2353 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
2355 ctx.amask = env->amask;
2357 #if defined (CONFIG_USER_ONLY)
2360 ctx.mem_idx = ((env->ps >> 3) & 3);
2361 ctx.pal_mode = env->ipr[IPR_EXC_ADDR] & 1;
2364 max_insns = tb->cflags & CF_COUNT_MASK;
2366 max_insns = CF_COUNT_MASK;
2369 for (ret = 0; ret == 0;) {
2370 if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
2371 TAILQ_FOREACH(bp, &env->breakpoints, entry) {
2372 if (bp->pc == ctx.pc) {
2373 gen_excp(&ctx, EXCP_DEBUG, 0);
2379 j = gen_opc_ptr - gen_opc_buf;
2383 gen_opc_instr_start[lj++] = 0;
2385 gen_opc_pc[lj] = ctx.pc;
2386 gen_opc_instr_start[lj] = 1;
2387 gen_opc_icount[lj] = num_insns;
2389 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
2391 #if defined ALPHA_DEBUG_DISAS
2393 LOG_DISAS("pc " TARGET_FMT_lx " mem_idx %d\n",
2394 ctx.pc, ctx.mem_idx);
2396 insn = ldl_code(ctx.pc);
2397 #if defined ALPHA_DEBUG_DISAS
2399 LOG_DISAS("opcode %08x %d\n", insn, insn_count);
2403 ret = translate_one(ctxp, insn);
2406 /* if we reach a page boundary or are single stepping, stop
2409 if (env->singlestep_enabled) {
2410 gen_excp(&ctx, EXCP_DEBUG, 0);
2414 if ((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0)
2417 if (gen_opc_ptr >= gen_opc_end)
2420 if (num_insns >= max_insns)
2427 if (ret != 1 && ret != 3) {
2428 tcg_gen_movi_i64(cpu_pc, ctx.pc);
2430 #if defined (DO_TB_FLUSH)
2431 gen_helper_tb_flush();
2433 if (tb->cflags & CF_LAST_IO)
2435 /* Generate the return instruction */
2437 gen_icount_end(tb, num_insns);
2438 *gen_opc_ptr = INDEX_op_end;
2440 j = gen_opc_ptr - gen_opc_buf;
2443 gen_opc_instr_start[lj++] = 0;
2445 tb->size = ctx.pc - pc_start;
2446 tb->icount = num_insns;
2448 #if defined ALPHA_DEBUG_DISAS
2449 log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
2450 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
2451 qemu_log("IN: %s\n", lookup_symbol(pc_start));
2452 log_target_disas(pc_start, ctx.pc - pc_start, 1);
2458 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
2460 gen_intermediate_code_internal(env, tb, 0);
2463 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
2465 gen_intermediate_code_internal(env, tb, 1);
2468 CPUAlphaState * cpu_alpha_init (const char *cpu_model)
2473 env = qemu_mallocz(sizeof(CPUAlphaState));
2475 alpha_translate_init();
2477 /* XXX: should not be hardcoded */
2478 env->implver = IMPLVER_2106x;
2480 #if defined (CONFIG_USER_ONLY)
2484 /* Initialize IPR */
2485 hwpcb = env->ipr[IPR_PCBB];
2486 env->ipr[IPR_ASN] = 0;
2487 env->ipr[IPR_ASTEN] = 0;
2488 env->ipr[IPR_ASTSR] = 0;
2489 env->ipr[IPR_DATFX] = 0;
2491 // env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
2492 // env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
2493 // env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
2494 // env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
2495 env->ipr[IPR_FEN] = 0;
2496 env->ipr[IPR_IPL] = 31;
2497 env->ipr[IPR_MCES] = 0;
2498 env->ipr[IPR_PERFMON] = 0; /* Implementation specific */
2499 // env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
2500 env->ipr[IPR_SISR] = 0;
2501 env->ipr[IPR_VIRBND] = -1ULL;
2503 qemu_init_vcpu(env);
2507 void gen_pc_load(CPUState *env, TranslationBlock *tb,
2508 unsigned long searched_pc, int pc_pos, void *puc)
2510 env->pc = gen_opc_pc[pc_pos];