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(__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 /* EXTWH, EXTWH, EXTLH, EXTQH */
511 static inline void gen_ext_h(void(*tcg_gen_ext_i64
)(TCGv t0
, TCGv t1
),
512 int ra
, int rb
, int rc
, int islit
, uint8_t lit
)
514 if (unlikely(rc
== 31))
520 tcg_gen_shli_i64(cpu_ir
[rc
], cpu_ir
[ra
], 64 - ((lit
& 7) * 8));
522 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[ra
]);
525 tmp1
= tcg_temp_new();
527 tcg_gen_andi_i64(tmp1
, cpu_ir
[rb
], 7);
528 tcg_gen_shli_i64(tmp1
, tmp1
, 3);
529 tcg_gen_neg_i64(tmp1
, tmp1
);
530 tcg_gen_andi_i64(tmp1
, tmp1
, 0x3f);
531 tcg_gen_shl_i64(cpu_ir
[rc
], cpu_ir
[ra
], tmp1
);
536 tcg_gen_ext_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
538 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
541 /* EXTBL, EXTWL, EXTWL, EXTLL, EXTQL */
542 static inline void gen_ext_l(void(*tcg_gen_ext_i64
)(TCGv t0
, TCGv t1
),
543 int ra
, int rb
, int rc
, int islit
, uint8_t lit
)
545 if (unlikely(rc
== 31))
550 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[ra
], (lit
& 7) * 8);
552 TCGv tmp
= tcg_temp_new();
553 tcg_gen_andi_i64(tmp
, cpu_ir
[rb
], 7);
554 tcg_gen_shli_i64(tmp
, tmp
, 3);
555 tcg_gen_shr_i64(cpu_ir
[rc
], cpu_ir
[ra
], tmp
);
559 tcg_gen_ext_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
561 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
564 /* Code to call arith3 helpers */
565 #define ARITH3(name) \
566 static inline void glue(gen_, name)(int ra, int rb, int rc, int islit,\
569 if (unlikely(rc == 31)) \
574 TCGv tmp = tcg_const_i64(lit); \
575 gen_helper_ ## name(cpu_ir[rc], cpu_ir[ra], tmp); \
576 tcg_temp_free(tmp); \
578 gen_helper_ ## name (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]); \
580 TCGv tmp1 = tcg_const_i64(0); \
582 TCGv tmp2 = tcg_const_i64(lit); \
583 gen_helper_ ## name (cpu_ir[rc], tmp1, tmp2); \
584 tcg_temp_free(tmp2); \
586 gen_helper_ ## name (cpu_ir[rc], tmp1, cpu_ir[rb]); \
587 tcg_temp_free(tmp1); \
624 #define MVIOP2(name) \
625 static inline void glue(gen_, name)(int rb, int rc) \
627 if (unlikely(rc == 31)) \
629 if (unlikely(rb == 31)) \
630 tcg_gen_movi_i64(cpu_ir[rc], 0); \
632 gen_helper_ ## name (cpu_ir[rc], cpu_ir[rb]); \
639 static inline void gen_cmp(TCGCond cond
, int ra
, int rb
, int rc
, int islit
,
645 if (unlikely(rc
== 31))
648 l1
= gen_new_label();
649 l2
= gen_new_label();
652 tmp
= tcg_temp_new();
653 tcg_gen_mov_i64(tmp
, cpu_ir
[ra
]);
655 tmp
= tcg_const_i64(0);
657 tcg_gen_brcondi_i64(cond
, tmp
, lit
, l1
);
659 tcg_gen_brcond_i64(cond
, tmp
, cpu_ir
[rb
], l1
);
661 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
664 tcg_gen_movi_i64(cpu_ir
[rc
], 1);
668 static inline int translate_one(DisasContext
*ctx
, uint32_t insn
)
671 int32_t disp21
, disp16
, disp12
;
673 uint8_t opc
, ra
, rb
, rc
, sbz
, fpfn
, fn7
, fn2
, islit
, real_islit
;
677 /* Decode all instruction fields */
679 ra
= (insn
>> 21) & 0x1F;
680 rb
= (insn
>> 16) & 0x1F;
682 sbz
= (insn
>> 13) & 0x07;
683 real_islit
= islit
= (insn
>> 12) & 1;
684 if (rb
== 31 && !islit
) {
688 lit
= (insn
>> 13) & 0xFF;
689 palcode
= insn
& 0x03FFFFFF;
690 disp21
= ((int32_t)((insn
& 0x001FFFFF) << 11)) >> 11;
691 disp16
= (int16_t)(insn
& 0x0000FFFF);
692 disp12
= (int32_t)((insn
& 0x00000FFF) << 20) >> 20;
693 fn16
= insn
& 0x0000FFFF;
694 fn11
= (insn
>> 5) & 0x000007FF;
696 fn7
= (insn
>> 5) & 0x0000007F;
697 fn2
= (insn
>> 5) & 0x00000003;
699 LOG_DISAS("opc %02x ra %d rb %d rc %d disp16 %04x\n",
700 opc
, ra
, rb
, rc
, disp16
);
704 if (palcode
>= 0x80 && palcode
< 0xC0) {
705 /* Unprivileged PAL call */
706 gen_excp(ctx
, EXCP_CALL_PAL
+ ((palcode
& 0x3F) << 6), 0);
707 #if !defined (CONFIG_USER_ONLY)
708 } else if (palcode
< 0x40) {
709 /* Privileged PAL code */
710 if (ctx
->mem_idx
& 1)
713 gen_excp(ctx
, EXCP_CALL_PALP
+ ((palcode
& 0x3F) << 6), 0);
716 /* Invalid PAL call */
744 if (likely(ra
!= 31)) {
746 tcg_gen_addi_i64(cpu_ir
[ra
], cpu_ir
[rb
], disp16
);
748 tcg_gen_movi_i64(cpu_ir
[ra
], disp16
);
753 if (likely(ra
!= 31)) {
755 tcg_gen_addi_i64(cpu_ir
[ra
], cpu_ir
[rb
], disp16
<< 16);
757 tcg_gen_movi_i64(cpu_ir
[ra
], disp16
<< 16);
762 if (!(ctx
->amask
& AMASK_BWX
))
764 gen_load_mem(ctx
, &tcg_gen_qemu_ld8u
, ra
, rb
, disp16
, 0, 0);
768 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 0, 1);
772 if (!(ctx
->amask
& AMASK_BWX
))
774 gen_load_mem(ctx
, &tcg_gen_qemu_ld16u
, ra
, rb
, disp16
, 0, 0);
778 gen_store_mem(ctx
, &tcg_gen_qemu_st16
, ra
, rb
, disp16
, 0, 0, 0);
782 gen_store_mem(ctx
, &tcg_gen_qemu_st8
, ra
, rb
, disp16
, 0, 0, 0);
786 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 0, 1, 0);
792 if (likely(rc
!= 31)) {
795 tcg_gen_addi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
796 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
798 tcg_gen_add_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
799 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
803 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
805 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
811 if (likely(rc
!= 31)) {
813 TCGv tmp
= tcg_temp_new();
814 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
816 tcg_gen_addi_i64(tmp
, tmp
, lit
);
818 tcg_gen_add_i64(tmp
, tmp
, cpu_ir
[rb
]);
819 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
823 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
825 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
831 if (likely(rc
!= 31)) {
834 tcg_gen_subi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
836 tcg_gen_sub_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
837 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
840 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
842 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
843 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
849 if (likely(rc
!= 31)) {
851 TCGv tmp
= tcg_temp_new();
852 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
854 tcg_gen_subi_i64(tmp
, tmp
, lit
);
856 tcg_gen_sub_i64(tmp
, tmp
, cpu_ir
[rb
]);
857 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
861 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
863 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
864 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
871 gen_cmpbge(ra
, rb
, rc
, islit
, lit
);
875 if (likely(rc
!= 31)) {
877 TCGv tmp
= tcg_temp_new();
878 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
880 tcg_gen_addi_i64(tmp
, tmp
, lit
);
882 tcg_gen_add_i64(tmp
, tmp
, cpu_ir
[rb
]);
883 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
887 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
889 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
895 if (likely(rc
!= 31)) {
897 TCGv tmp
= tcg_temp_new();
898 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
900 tcg_gen_subi_i64(tmp
, tmp
, lit
);
902 tcg_gen_sub_i64(tmp
, tmp
, cpu_ir
[rb
]);
903 tcg_gen_ext32s_i64(cpu_ir
[rc
], tmp
);
907 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
909 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
910 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
917 gen_cmp(TCG_COND_LTU
, ra
, rb
, rc
, islit
, lit
);
921 if (likely(rc
!= 31)) {
924 tcg_gen_addi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
926 tcg_gen_add_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
929 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
931 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
937 if (likely(rc
!= 31)) {
939 TCGv tmp
= tcg_temp_new();
940 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
942 tcg_gen_addi_i64(cpu_ir
[rc
], tmp
, lit
);
944 tcg_gen_add_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
948 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
950 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
956 if (likely(rc
!= 31)) {
959 tcg_gen_subi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
961 tcg_gen_sub_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
964 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
966 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
972 if (likely(rc
!= 31)) {
974 TCGv tmp
= tcg_temp_new();
975 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 2);
977 tcg_gen_subi_i64(cpu_ir
[rc
], tmp
, lit
);
979 tcg_gen_sub_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
983 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
985 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
991 gen_cmp(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
);
995 if (likely(rc
!= 31)) {
997 TCGv tmp
= tcg_temp_new();
998 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1000 tcg_gen_addi_i64(cpu_ir
[rc
], tmp
, lit
);
1002 tcg_gen_add_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1006 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1008 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1014 if (likely(rc
!= 31)) {
1016 TCGv tmp
= tcg_temp_new();
1017 tcg_gen_shli_i64(tmp
, cpu_ir
[ra
], 3);
1019 tcg_gen_subi_i64(cpu_ir
[rc
], tmp
, lit
);
1021 tcg_gen_sub_i64(cpu_ir
[rc
], tmp
, cpu_ir
[rb
]);
1025 tcg_gen_movi_i64(cpu_ir
[rc
], -lit
);
1027 tcg_gen_neg_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1033 gen_cmp(TCG_COND_LEU
, ra
, rb
, rc
, islit
, lit
);
1037 gen_addlv(ra
, rb
, rc
, islit
, lit
);
1041 gen_sublv(ra
, rb
, rc
, islit
, lit
);
1045 gen_cmp(TCG_COND_LT
, ra
, rb
, rc
, islit
, lit
);
1049 gen_addqv(ra
, rb
, rc
, islit
, lit
);
1053 gen_subqv(ra
, rb
, rc
, islit
, lit
);
1057 gen_cmp(TCG_COND_LE
, ra
, rb
, rc
, islit
, lit
);
1067 if (likely(rc
!= 31)) {
1069 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1071 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1073 tcg_gen_and_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1078 if (likely(rc
!= 31)) {
1081 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1083 tcg_gen_andc_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1085 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1090 gen_cmov(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
, 1);
1094 gen_cmov(TCG_COND_NE
, ra
, rb
, rc
, islit
, lit
, 1);
1098 if (likely(rc
!= 31)) {
1101 tcg_gen_ori_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1103 tcg_gen_or_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1106 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1108 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1114 gen_cmov(TCG_COND_NE
, ra
, rb
, rc
, islit
, lit
, 0);
1118 gen_cmov(TCG_COND_EQ
, ra
, rb
, rc
, islit
, lit
, 0);
1122 if (likely(rc
!= 31)) {
1125 tcg_gen_ori_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1127 tcg_gen_orc_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1130 tcg_gen_movi_i64(cpu_ir
[rc
], ~lit
);
1132 tcg_gen_not_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1138 if (likely(rc
!= 31)) {
1141 tcg_gen_xori_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1143 tcg_gen_xor_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1146 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1148 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1154 gen_cmov(TCG_COND_GE
, ra
, rb
, rc
, islit
, lit
, 0);
1158 gen_cmov(TCG_COND_LT
, ra
, rb
, rc
, islit
, lit
, 0);
1162 if (likely(rc
!= 31)) {
1165 tcg_gen_xori_i64(cpu_ir
[rc
], cpu_ir
[ra
], ~lit
);
1167 tcg_gen_eqv_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1170 tcg_gen_movi_i64(cpu_ir
[rc
], ~lit
);
1172 tcg_gen_not_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1178 if (likely(rc
!= 31)) {
1180 tcg_gen_movi_i64(cpu_ir
[rc
], lit
);
1182 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1183 switch (ctx
->env
->implver
) {
1185 /* EV4, EV45, LCA, LCA45 & EV5 */
1190 tcg_gen_andi_i64(cpu_ir
[rc
], cpu_ir
[rc
],
1191 ~(uint64_t)ctx
->amask
);
1198 gen_cmov(TCG_COND_GT
, ra
, rb
, rc
, islit
, lit
, 0);
1202 gen_cmov(TCG_COND_LE
, ra
, rb
, rc
, islit
, lit
, 0);
1207 tcg_gen_movi_i64(cpu_ir
[rc
], ctx
->env
->implver
);
1217 gen_mskbl(ra
, rb
, rc
, islit
, lit
);
1221 gen_ext_l(&tcg_gen_ext8u_i64
, ra
, rb
, rc
, islit
, lit
);
1225 gen_insbl(ra
, rb
, rc
, islit
, lit
);
1229 gen_mskwl(ra
, rb
, rc
, islit
, lit
);
1233 gen_ext_l(&tcg_gen_ext16u_i64
, ra
, rb
, rc
, islit
, lit
);
1237 gen_inswl(ra
, rb
, rc
, islit
, lit
);
1241 gen_mskll(ra
, rb
, rc
, islit
, lit
);
1245 gen_ext_l(&tcg_gen_ext32u_i64
, ra
, rb
, rc
, islit
, lit
);
1249 gen_insll(ra
, rb
, rc
, islit
, lit
);
1253 gen_zap(ra
, rb
, rc
, islit
, lit
);
1257 gen_zapnot(ra
, rb
, rc
, islit
, lit
);
1261 gen_mskql(ra
, rb
, rc
, islit
, lit
);
1265 if (likely(rc
!= 31)) {
1268 tcg_gen_shri_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1270 TCGv shift
= tcg_temp_new();
1271 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1272 tcg_gen_shr_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1273 tcg_temp_free(shift
);
1276 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1281 gen_ext_l(NULL
, ra
, rb
, rc
, islit
, lit
);
1285 if (likely(rc
!= 31)) {
1288 tcg_gen_shli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1290 TCGv shift
= tcg_temp_new();
1291 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1292 tcg_gen_shl_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1293 tcg_temp_free(shift
);
1296 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1301 gen_insql(ra
, rb
, rc
, islit
, lit
);
1305 if (likely(rc
!= 31)) {
1308 tcg_gen_sari_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
& 0x3f);
1310 TCGv shift
= tcg_temp_new();
1311 tcg_gen_andi_i64(shift
, cpu_ir
[rb
], 0x3f);
1312 tcg_gen_sar_i64(cpu_ir
[rc
], cpu_ir
[ra
], shift
);
1313 tcg_temp_free(shift
);
1316 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1321 gen_mskwh(ra
, rb
, rc
, islit
, lit
);
1325 gen_inswh(ra
, rb
, rc
, islit
, lit
);
1329 gen_ext_h(&tcg_gen_ext16u_i64
, ra
, rb
, rc
, islit
, lit
);
1333 gen_msklh(ra
, rb
, rc
, islit
, lit
);
1337 gen_inslh(ra
, rb
, rc
, islit
, lit
);
1341 gen_ext_h(&tcg_gen_ext32u_i64
, ra
, rb
, rc
, islit
, lit
);
1345 gen_mskqh(ra
, rb
, rc
, islit
, lit
);
1349 gen_insqh(ra
, rb
, rc
, islit
, lit
);
1353 gen_ext_h(NULL
, ra
, rb
, rc
, islit
, lit
);
1363 if (likely(rc
!= 31)) {
1365 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1368 tcg_gen_muli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1370 tcg_gen_mul_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1371 tcg_gen_ext32s_i64(cpu_ir
[rc
], cpu_ir
[rc
]);
1377 if (likely(rc
!= 31)) {
1379 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
1381 tcg_gen_muli_i64(cpu_ir
[rc
], cpu_ir
[ra
], lit
);
1383 tcg_gen_mul_i64(cpu_ir
[rc
], cpu_ir
[ra
], cpu_ir
[rb
]);
1388 gen_umulh(ra
, rb
, rc
, islit
, lit
);
1392 gen_mullv(ra
, rb
, rc
, islit
, lit
);
1396 gen_mulqv(ra
, rb
, rc
, islit
, lit
);
1403 switch (fpfn
) { /* f11 & 0x3F */
1406 if (!(ctx
->amask
& AMASK_FIX
))
1408 if (likely(rc
!= 31)) {
1410 TCGv_i32 tmp
= tcg_temp_new_i32();
1411 tcg_gen_trunc_i64_i32(tmp
, cpu_ir
[ra
]);
1412 gen_helper_memory_to_s(cpu_fir
[rc
], tmp
);
1413 tcg_temp_free_i32(tmp
);
1415 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
1420 if (!(ctx
->amask
& AMASK_FIX
))
1426 if (!(ctx
->amask
& AMASK_FIX
))
1432 if (!(ctx
->amask
& AMASK_FIX
))
1434 if (likely(rc
!= 31)) {
1436 TCGv_i32 tmp
= tcg_temp_new_i32();
1437 tcg_gen_trunc_i64_i32(tmp
, cpu_ir
[ra
]);
1438 gen_helper_memory_to_f(cpu_fir
[rc
], tmp
);
1439 tcg_temp_free_i32(tmp
);
1441 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
1446 if (!(ctx
->amask
& AMASK_FIX
))
1448 if (likely(rc
!= 31)) {
1450 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_ir
[ra
]);
1452 tcg_gen_movi_i64(cpu_fir
[rc
], 0);
1457 if (!(ctx
->amask
& AMASK_FIX
))
1463 if (!(ctx
->amask
& AMASK_FIX
))
1472 /* VAX floating point */
1473 /* XXX: rounding mode and trap are ignored (!) */
1474 switch (fpfn
) { /* f11 & 0x3F */
1477 gen_faddf(ra
, rb
, rc
);
1481 gen_fsubf(ra
, rb
, rc
);
1485 gen_fmulf(ra
, rb
, rc
);
1489 gen_fdivf(ra
, rb
, rc
);
1501 gen_faddg(ra
, rb
, rc
);
1505 gen_fsubg(ra
, rb
, rc
);
1509 gen_fmulg(ra
, rb
, rc
);
1513 gen_fdivg(ra
, rb
, rc
);
1517 gen_fcmpgeq(ra
, rb
, rc
);
1521 gen_fcmpglt(ra
, rb
, rc
);
1525 gen_fcmpgle(ra
, rb
, rc
);
1556 /* IEEE floating-point */
1557 /* XXX: rounding mode and traps are ignored (!) */
1558 switch (fpfn
) { /* f11 & 0x3F */
1561 gen_fadds(ra
, rb
, rc
);
1565 gen_fsubs(ra
, rb
, rc
);
1569 gen_fmuls(ra
, rb
, rc
);
1573 gen_fdivs(ra
, rb
, rc
);
1577 gen_faddt(ra
, rb
, rc
);
1581 gen_fsubt(ra
, rb
, rc
);
1585 gen_fmult(ra
, rb
, rc
);
1589 gen_fdivt(ra
, rb
, rc
);
1593 gen_fcmptun(ra
, rb
, rc
);
1597 gen_fcmpteq(ra
, rb
, rc
);
1601 gen_fcmptlt(ra
, rb
, rc
);
1605 gen_fcmptle(ra
, rb
, rc
);
1608 /* XXX: incorrect */
1609 if (fn11
== 0x2AC || fn11
== 0x6AC) {
1640 if (likely(rc
!= 31)) {
1643 tcg_gen_mov_i64(cpu_fir
[rc
], cpu_fir
[ra
]);
1646 gen_fcpys(ra
, rb
, rc
);
1651 gen_fcpysn(ra
, rb
, rc
);
1655 gen_fcpyse(ra
, rb
, rc
);
1659 if (likely(ra
!= 31))
1660 gen_helper_store_fpcr(cpu_fir
[ra
]);
1662 TCGv tmp
= tcg_const_i64(0);
1663 gen_helper_store_fpcr(tmp
);
1669 if (likely(ra
!= 31))
1670 gen_helper_load_fpcr(cpu_fir
[ra
]);
1674 gen_fcmpfeq(ra
, rb
, rc
);
1678 gen_fcmpfne(ra
, rb
, rc
);
1682 gen_fcmpflt(ra
, rb
, rc
);
1686 gen_fcmpfge(ra
, rb
, rc
);
1690 gen_fcmpfle(ra
, rb
, rc
);
1694 gen_fcmpfgt(ra
, rb
, rc
);
1702 gen_fcvtqlv(rb
, rc
);
1706 gen_fcvtqlsv(rb
, rc
);
1713 switch ((uint16_t)disp16
) {
1716 /* No-op. Just exit from the current tb */
1721 /* No-op. Just exit from the current tb */
1743 gen_helper_load_pcc(cpu_ir
[ra
]);
1748 gen_helper_rc(cpu_ir
[ra
]);
1756 gen_helper_rs(cpu_ir
[ra
]);
1767 /* HW_MFPR (PALcode) */
1768 #if defined (CONFIG_USER_ONLY)
1774 TCGv tmp
= tcg_const_i32(insn
& 0xFF);
1775 gen_helper_mfpr(cpu_ir
[ra
], tmp
, cpu_ir
[ra
]);
1782 tcg_gen_andi_i64(cpu_pc
, cpu_ir
[rb
], ~3);
1784 tcg_gen_movi_i64(cpu_pc
, 0);
1786 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
1787 /* Those four jumps only differ by the branch prediction hint */
1805 /* HW_LD (PALcode) */
1806 #if defined (CONFIG_USER_ONLY)
1812 TCGv addr
= tcg_temp_new();
1814 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp12
);
1816 tcg_gen_movi_i64(addr
, disp12
);
1817 switch ((insn
>> 12) & 0xF) {
1819 /* Longword physical access (hw_ldl/p) */
1820 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
1823 /* Quadword physical access (hw_ldq/p) */
1824 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
1827 /* Longword physical access with lock (hw_ldl_l/p) */
1828 gen_helper_ldl_l_raw(cpu_ir
[ra
], addr
);
1831 /* Quadword physical access with lock (hw_ldq_l/p) */
1832 gen_helper_ldq_l_raw(cpu_ir
[ra
], addr
);
1835 /* Longword virtual PTE fetch (hw_ldl/v) */
1836 tcg_gen_qemu_ld32s(cpu_ir
[ra
], addr
, 0);
1839 /* Quadword virtual PTE fetch (hw_ldq/v) */
1840 tcg_gen_qemu_ld64(cpu_ir
[ra
], addr
, 0);
1843 /* Incpu_ir[ra]id */
1846 /* Incpu_ir[ra]id */
1849 /* Longword virtual access (hw_ldl) */
1850 gen_helper_st_virt_to_phys(addr
, addr
);
1851 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
1854 /* Quadword virtual access (hw_ldq) */
1855 gen_helper_st_virt_to_phys(addr
, addr
);
1856 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
1859 /* Longword virtual access with protection check (hw_ldl/w) */
1860 tcg_gen_qemu_ld32s(cpu_ir
[ra
], addr
, 0);
1863 /* Quadword virtual access with protection check (hw_ldq/w) */
1864 tcg_gen_qemu_ld64(cpu_ir
[ra
], addr
, 0);
1867 /* Longword virtual access with alt access mode (hw_ldl/a)*/
1868 gen_helper_set_alt_mode();
1869 gen_helper_st_virt_to_phys(addr
, addr
);
1870 gen_helper_ldl_raw(cpu_ir
[ra
], addr
);
1871 gen_helper_restore_mode();
1874 /* Quadword virtual access with alt access mode (hw_ldq/a) */
1875 gen_helper_set_alt_mode();
1876 gen_helper_st_virt_to_phys(addr
, addr
);
1877 gen_helper_ldq_raw(cpu_ir
[ra
], addr
);
1878 gen_helper_restore_mode();
1881 /* Longword virtual access with alternate access mode and
1882 * protection checks (hw_ldl/wa)
1884 gen_helper_set_alt_mode();
1885 gen_helper_ldl_data(cpu_ir
[ra
], addr
);
1886 gen_helper_restore_mode();
1889 /* Quadword virtual access with alternate access mode and
1890 * protection checks (hw_ldq/wa)
1892 gen_helper_set_alt_mode();
1893 gen_helper_ldq_data(cpu_ir
[ra
], addr
);
1894 gen_helper_restore_mode();
1897 tcg_temp_free(addr
);
1905 if (!(ctx
->amask
& AMASK_BWX
))
1907 if (likely(rc
!= 31)) {
1909 tcg_gen_movi_i64(cpu_ir
[rc
], (int64_t)((int8_t)lit
));
1911 tcg_gen_ext8s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1916 if (!(ctx
->amask
& AMASK_BWX
))
1918 if (likely(rc
!= 31)) {
1920 tcg_gen_movi_i64(cpu_ir
[rc
], (int64_t)((int16_t)lit
));
1922 tcg_gen_ext16s_i64(cpu_ir
[rc
], cpu_ir
[rb
]);
1927 if (!(ctx
->amask
& AMASK_CIX
))
1929 if (likely(rc
!= 31)) {
1931 tcg_gen_movi_i64(cpu_ir
[rc
], ctpop64(lit
));
1933 gen_helper_ctpop(cpu_ir
[rc
], cpu_ir
[rb
]);
1938 if (!(ctx
->amask
& AMASK_MVI
))
1940 gen_perr(ra
, rb
, rc
, islit
, lit
);
1944 if (!(ctx
->amask
& AMASK_CIX
))
1946 if (likely(rc
!= 31)) {
1948 tcg_gen_movi_i64(cpu_ir
[rc
], clz64(lit
));
1950 gen_helper_ctlz(cpu_ir
[rc
], cpu_ir
[rb
]);
1955 if (!(ctx
->amask
& AMASK_CIX
))
1957 if (likely(rc
!= 31)) {
1959 tcg_gen_movi_i64(cpu_ir
[rc
], ctz64(lit
));
1961 gen_helper_cttz(cpu_ir
[rc
], cpu_ir
[rb
]);
1966 if (!(ctx
->amask
& AMASK_MVI
))
1968 if (real_islit
|| ra
!= 31)
1970 gen_unpkbw (rb
, rc
);
1974 if (!(ctx
->amask
& AMASK_MVI
))
1976 if (real_islit
|| ra
!= 31)
1978 gen_unpkbl (rb
, rc
);
1982 if (!(ctx
->amask
& AMASK_MVI
))
1984 if (real_islit
|| ra
!= 31)
1990 if (!(ctx
->amask
& AMASK_MVI
))
1992 if (real_islit
|| ra
!= 31)
1998 if (!(ctx
->amask
& AMASK_MVI
))
2000 gen_minsb8 (ra
, rb
, rc
, islit
, lit
);
2004 if (!(ctx
->amask
& AMASK_MVI
))
2006 gen_minsw4 (ra
, rb
, rc
, islit
, lit
);
2010 if (!(ctx
->amask
& AMASK_MVI
))
2012 gen_minub8 (ra
, rb
, rc
, islit
, lit
);
2016 if (!(ctx
->amask
& AMASK_MVI
))
2018 gen_minuw4 (ra
, rb
, rc
, islit
, lit
);
2022 if (!(ctx
->amask
& AMASK_MVI
))
2024 gen_maxub8 (ra
, rb
, rc
, islit
, lit
);
2028 if (!(ctx
->amask
& AMASK_MVI
))
2030 gen_maxuw4 (ra
, rb
, rc
, islit
, lit
);
2034 if (!(ctx
->amask
& AMASK_MVI
))
2036 gen_maxsb8 (ra
, rb
, rc
, islit
, lit
);
2040 if (!(ctx
->amask
& AMASK_MVI
))
2042 gen_maxsw4 (ra
, rb
, rc
, islit
, lit
);
2046 if (!(ctx
->amask
& AMASK_FIX
))
2048 if (likely(rc
!= 31)) {
2050 tcg_gen_mov_i64(cpu_ir
[rc
], cpu_fir
[ra
]);
2052 tcg_gen_movi_i64(cpu_ir
[rc
], 0);
2057 if (!(ctx
->amask
& AMASK_FIX
))
2060 TCGv_i32 tmp1
= tcg_temp_new_i32();
2062 gen_helper_s_to_memory(tmp1
, cpu_fir
[ra
]);
2064 TCGv tmp2
= tcg_const_i64(0);
2065 gen_helper_s_to_memory(tmp1
, tmp2
);
2066 tcg_temp_free(tmp2
);
2068 tcg_gen_ext_i32_i64(cpu_ir
[rc
], tmp1
);
2069 tcg_temp_free_i32(tmp1
);
2077 /* HW_MTPR (PALcode) */
2078 #if defined (CONFIG_USER_ONLY)
2084 TCGv tmp1
= tcg_const_i32(insn
& 0xFF);
2086 gen_helper_mtpr(tmp1
, cpu_ir
[ra
]);
2088 TCGv tmp2
= tcg_const_i64(0);
2089 gen_helper_mtpr(tmp1
, tmp2
);
2090 tcg_temp_free(tmp2
);
2092 tcg_temp_free(tmp1
);
2098 /* HW_REI (PALcode) */
2099 #if defined (CONFIG_USER_ONLY)
2106 gen_helper_hw_rei();
2111 tmp
= tcg_temp_new();
2112 tcg_gen_addi_i64(tmp
, cpu_ir
[rb
], (((int64_t)insn
<< 51) >> 51));
2114 tmp
= tcg_const_i64(((int64_t)insn
<< 51) >> 51);
2115 gen_helper_hw_ret(tmp
);
2122 /* HW_ST (PALcode) */
2123 #if defined (CONFIG_USER_ONLY)
2130 addr
= tcg_temp_new();
2132 tcg_gen_addi_i64(addr
, cpu_ir
[rb
], disp12
);
2134 tcg_gen_movi_i64(addr
, disp12
);
2138 val
= tcg_temp_new();
2139 tcg_gen_movi_i64(val
, 0);
2141 switch ((insn
>> 12) & 0xF) {
2143 /* Longword physical access */
2144 gen_helper_stl_raw(val
, addr
);
2147 /* Quadword physical access */
2148 gen_helper_stq_raw(val
, addr
);
2151 /* Longword physical access with lock */
2152 gen_helper_stl_c_raw(val
, val
, addr
);
2155 /* Quadword physical access with lock */
2156 gen_helper_stq_c_raw(val
, val
, addr
);
2159 /* Longword virtual access */
2160 gen_helper_st_virt_to_phys(addr
, addr
);
2161 gen_helper_stl_raw(val
, addr
);
2164 /* Quadword virtual access */
2165 gen_helper_st_virt_to_phys(addr
, addr
);
2166 gen_helper_stq_raw(val
, addr
);
2187 /* Longword virtual access with alternate access mode */
2188 gen_helper_set_alt_mode();
2189 gen_helper_st_virt_to_phys(addr
, addr
);
2190 gen_helper_stl_raw(val
, addr
);
2191 gen_helper_restore_mode();
2194 /* Quadword virtual access with alternate access mode */
2195 gen_helper_set_alt_mode();
2196 gen_helper_st_virt_to_phys(addr
, addr
);
2197 gen_helper_stl_raw(val
, addr
);
2198 gen_helper_restore_mode();
2209 tcg_temp_free(addr
);
2215 gen_load_mem(ctx
, &gen_qemu_ldf
, ra
, rb
, disp16
, 1, 0);
2219 gen_load_mem(ctx
, &gen_qemu_ldg
, ra
, rb
, disp16
, 1, 0);
2223 gen_load_mem(ctx
, &gen_qemu_lds
, ra
, rb
, disp16
, 1, 0);
2227 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 1, 0);
2231 gen_store_mem(ctx
, &gen_qemu_stf
, ra
, rb
, disp16
, 1, 0, 0);
2235 gen_store_mem(ctx
, &gen_qemu_stg
, ra
, rb
, disp16
, 1, 0, 0);
2239 gen_store_mem(ctx
, &gen_qemu_sts
, ra
, rb
, disp16
, 1, 0, 0);
2243 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 1, 0, 0);
2247 gen_load_mem(ctx
, &tcg_gen_qemu_ld32s
, ra
, rb
, disp16
, 0, 0);
2251 gen_load_mem(ctx
, &tcg_gen_qemu_ld64
, ra
, rb
, disp16
, 0, 0);
2255 gen_load_mem(ctx
, &gen_qemu_ldl_l
, ra
, rb
, disp16
, 0, 0);
2259 gen_load_mem(ctx
, &gen_qemu_ldq_l
, ra
, rb
, disp16
, 0, 0);
2263 gen_store_mem(ctx
, &tcg_gen_qemu_st32
, ra
, rb
, disp16
, 0, 0, 0);
2267 gen_store_mem(ctx
, &tcg_gen_qemu_st64
, ra
, rb
, disp16
, 0, 0, 0);
2271 gen_store_mem(ctx
, &gen_qemu_stl_c
, ra
, rb
, disp16
, 0, 0, 1);
2275 gen_store_mem(ctx
, &gen_qemu_stq_c
, ra
, rb
, disp16
, 0, 0, 1);
2280 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
2281 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp21
<< 2));
2284 case 0x31: /* FBEQ */
2285 case 0x32: /* FBLT */
2286 case 0x33: /* FBLE */
2287 gen_fbcond(ctx
, opc
, ra
, disp16
);
2293 tcg_gen_movi_i64(cpu_ir
[ra
], ctx
->pc
);
2294 tcg_gen_movi_i64(cpu_pc
, ctx
->pc
+ (int64_t)(disp21
<< 2));
2297 case 0x35: /* FBNE */
2298 case 0x36: /* FBGE */
2299 case 0x37: /* FBGT */
2300 gen_fbcond(ctx
, opc
, ra
, disp16
);
2305 gen_bcond(ctx
, TCG_COND_EQ
, ra
, disp21
, 1);
2310 gen_bcond(ctx
, TCG_COND_EQ
, ra
, disp21
, 0);
2315 gen_bcond(ctx
, TCG_COND_LT
, ra
, disp21
, 0);
2320 gen_bcond(ctx
, TCG_COND_LE
, ra
, disp21
, 0);
2325 gen_bcond(ctx
, TCG_COND_NE
, ra
, disp21
, 1);
2330 gen_bcond(ctx
, TCG_COND_NE
, ra
, disp21
, 0);
2335 gen_bcond(ctx
, TCG_COND_GE
, ra
, disp21
, 0);
2340 gen_bcond(ctx
, TCG_COND_GT
, ra
, disp21
, 0);
2352 static inline void gen_intermediate_code_internal(CPUState
*env
,
2353 TranslationBlock
*tb
,
2356 #if defined ALPHA_DEBUG_DISAS
2357 static int insn_count
;
2359 DisasContext ctx
, *ctxp
= &ctx
;
2360 target_ulong pc_start
;
2362 uint16_t *gen_opc_end
;
2370 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2372 ctx
.amask
= env
->amask
;
2374 #if defined (CONFIG_USER_ONLY)
2377 ctx
.mem_idx
= ((env
->ps
>> 3) & 3);
2378 ctx
.pal_mode
= env
->ipr
[IPR_EXC_ADDR
] & 1;
2381 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2383 max_insns
= CF_COUNT_MASK
;
2386 for (ret
= 0; ret
== 0;) {
2387 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2388 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2389 if (bp
->pc
== ctx
.pc
) {
2390 gen_excp(&ctx
, EXCP_DEBUG
, 0);
2396 j
= gen_opc_ptr
- gen_opc_buf
;
2400 gen_opc_instr_start
[lj
++] = 0;
2402 gen_opc_pc
[lj
] = ctx
.pc
;
2403 gen_opc_instr_start
[lj
] = 1;
2404 gen_opc_icount
[lj
] = num_insns
;
2406 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
2408 #if defined ALPHA_DEBUG_DISAS
2410 LOG_DISAS("pc " TARGET_FMT_lx
" mem_idx %d\n",
2411 ctx
.pc
, ctx
.mem_idx
);
2413 insn
= ldl_code(ctx
.pc
);
2414 #if defined ALPHA_DEBUG_DISAS
2416 LOG_DISAS("opcode %08x %d\n", insn
, insn_count
);
2420 ret
= translate_one(ctxp
, insn
);
2423 /* if we reach a page boundary or are single stepping, stop
2426 if (env
->singlestep_enabled
) {
2427 gen_excp(&ctx
, EXCP_DEBUG
, 0);
2431 if ((ctx
.pc
& (TARGET_PAGE_SIZE
- 1)) == 0)
2434 if (gen_opc_ptr
>= gen_opc_end
)
2437 if (num_insns
>= max_insns
)
2444 if (ret
!= 1 && ret
!= 3) {
2445 tcg_gen_movi_i64(cpu_pc
, ctx
.pc
);
2447 if (tb
->cflags
& CF_LAST_IO
)
2449 /* Generate the return instruction */
2451 gen_icount_end(tb
, num_insns
);
2452 *gen_opc_ptr
= INDEX_op_end
;
2454 j
= gen_opc_ptr
- gen_opc_buf
;
2457 gen_opc_instr_start
[lj
++] = 0;
2459 tb
->size
= ctx
.pc
- pc_start
;
2460 tb
->icount
= num_insns
;
2462 #if defined ALPHA_DEBUG_DISAS
2463 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
2464 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
2465 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
2466 log_target_disas(pc_start
, ctx
.pc
- pc_start
, 1);
2472 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
2474 gen_intermediate_code_internal(env
, tb
, 0);
2477 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
2479 gen_intermediate_code_internal(env
, tb
, 1);
2487 static const struct cpu_def_t cpu_defs
[] = {
2488 { "ev4", IMPLVER_2106x
, 0 },
2489 { "ev5", IMPLVER_21164
, 0 },
2490 { "ev56", IMPLVER_21164
, AMASK_BWX
},
2491 { "pca56", IMPLVER_21164
, AMASK_BWX
| AMASK_MVI
},
2492 { "ev6", IMPLVER_21264
, AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
},
2493 { "ev67", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
2494 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), },
2495 { "ev68", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
2496 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), },
2497 { "21064", IMPLVER_2106x
, 0 },
2498 { "21164", IMPLVER_21164
, 0 },
2499 { "21164a", IMPLVER_21164
, AMASK_BWX
},
2500 { "21164pc", IMPLVER_21164
, AMASK_BWX
| AMASK_MVI
},
2501 { "21264", IMPLVER_21264
, AMASK_BWX
| AMASK_FIX
| AMASK_MVI
| AMASK_TRAP
},
2502 { "21264a", IMPLVER_21264
, (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
2503 | AMASK_MVI
| AMASK_TRAP
| AMASK_PREFETCH
), }
2506 CPUAlphaState
* cpu_alpha_init (const char *cpu_model
)
2510 int implver
, amask
, i
, max
;
2512 env
= qemu_mallocz(sizeof(CPUAlphaState
));
2514 alpha_translate_init();
2517 /* Default to ev67; no reason not to emulate insns by default. */
2518 implver
= IMPLVER_21264
;
2519 amask
= (AMASK_BWX
| AMASK_FIX
| AMASK_CIX
| AMASK_MVI
2520 | AMASK_TRAP
| AMASK_PREFETCH
);
2522 max
= ARRAY_SIZE(cpu_defs
);
2523 for (i
= 0; i
< max
; i
++) {
2524 if (strcmp (cpu_model
, cpu_defs
[i
].name
) == 0) {
2525 implver
= cpu_defs
[i
].implver
;
2526 amask
= cpu_defs
[i
].amask
;
2530 env
->implver
= implver
;
2534 #if defined (CONFIG_USER_ONLY)
2538 /* Initialize IPR */
2539 hwpcb
= env
->ipr
[IPR_PCBB
];
2540 env
->ipr
[IPR_ASN
] = 0;
2541 env
->ipr
[IPR_ASTEN
] = 0;
2542 env
->ipr
[IPR_ASTSR
] = 0;
2543 env
->ipr
[IPR_DATFX
] = 0;
2545 // env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
2546 // env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
2547 // env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
2548 // env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
2549 env
->ipr
[IPR_FEN
] = 0;
2550 env
->ipr
[IPR_IPL
] = 31;
2551 env
->ipr
[IPR_MCES
] = 0;
2552 env
->ipr
[IPR_PERFMON
] = 0; /* Implementation specific */
2553 // env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
2554 env
->ipr
[IPR_SISR
] = 0;
2555 env
->ipr
[IPR_VIRBND
] = -1ULL;
2557 qemu_init_vcpu(env
);
2561 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
2562 unsigned long searched_pc
, int pc_pos
, void *puc
)
2564 env
->pc
= gen_opc_pc
[pc_pos
];