2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
24 #include "disas/disas.h"
25 #include "exec/exec-all.h"
26 #include "tcg/tcg-op.h"
27 #include "tcg/tcg-op-gvec.h"
28 #include "qemu/host-utils.h"
29 #include "qemu/main-loop.h"
30 #include "exec/cpu_ldst.h"
32 #include "exec/helper-proto.h"
33 #include "exec/helper-gen.h"
35 #include "trace-tcg.h"
36 #include "exec/translator.h"
38 #include "qemu/atomic128.h"
41 #define CPU_SINGLE_STEP 0x1
42 #define CPU_BRANCH_STEP 0x2
43 #define GDBSTUB_SINGLE_STEP 0x4
45 /* Include definitions for instructions classes and implementations flags */
46 /* #define PPC_DEBUG_DISAS */
47 /* #define DO_PPC_STATISTICS */
49 #ifdef PPC_DEBUG_DISAS
50 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
52 # define LOG_DISAS(...) do { } while (0)
54 /*****************************************************************************/
55 /* Code translation helpers */
57 /* global register indexes */
58 static char cpu_reg_names
[10 * 3 + 22 * 4 /* GPR */
59 + 10 * 4 + 22 * 5 /* SPE GPRh */
61 static TCGv cpu_gpr
[32];
62 static TCGv cpu_gprh
[32];
63 static TCGv_i32 cpu_crf
[8];
68 #if defined(TARGET_PPC64)
71 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
, cpu_ov32
, cpu_ca32
;
72 static TCGv cpu_reserve
;
73 static TCGv cpu_reserve_val
;
74 static TCGv cpu_fpscr
;
75 static TCGv_i32 cpu_access_type
;
77 #include "exec/gen-icount.h"
79 void ppc_translate_init(void)
83 size_t cpu_reg_names_size
;
86 cpu_reg_names_size
= sizeof(cpu_reg_names
);
88 for (i
= 0; i
< 8; i
++) {
89 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
90 cpu_crf
[i
] = tcg_global_mem_new_i32(cpu_env
,
91 offsetof(CPUPPCState
, crf
[i
]), p
);
93 cpu_reg_names_size
-= 5;
96 for (i
= 0; i
< 32; i
++) {
97 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
98 cpu_gpr
[i
] = tcg_global_mem_new(cpu_env
,
99 offsetof(CPUPPCState
, gpr
[i
]), p
);
100 p
+= (i
< 10) ? 3 : 4;
101 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
102 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
103 cpu_gprh
[i
] = tcg_global_mem_new(cpu_env
,
104 offsetof(CPUPPCState
, gprh
[i
]), p
);
105 p
+= (i
< 10) ? 4 : 5;
106 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
109 cpu_nip
= tcg_global_mem_new(cpu_env
,
110 offsetof(CPUPPCState
, nip
), "nip");
112 cpu_msr
= tcg_global_mem_new(cpu_env
,
113 offsetof(CPUPPCState
, msr
), "msr");
115 cpu_ctr
= tcg_global_mem_new(cpu_env
,
116 offsetof(CPUPPCState
, ctr
), "ctr");
118 cpu_lr
= tcg_global_mem_new(cpu_env
,
119 offsetof(CPUPPCState
, lr
), "lr");
121 #if defined(TARGET_PPC64)
122 cpu_cfar
= tcg_global_mem_new(cpu_env
,
123 offsetof(CPUPPCState
, cfar
), "cfar");
126 cpu_xer
= tcg_global_mem_new(cpu_env
,
127 offsetof(CPUPPCState
, xer
), "xer");
128 cpu_so
= tcg_global_mem_new(cpu_env
,
129 offsetof(CPUPPCState
, so
), "SO");
130 cpu_ov
= tcg_global_mem_new(cpu_env
,
131 offsetof(CPUPPCState
, ov
), "OV");
132 cpu_ca
= tcg_global_mem_new(cpu_env
,
133 offsetof(CPUPPCState
, ca
), "CA");
134 cpu_ov32
= tcg_global_mem_new(cpu_env
,
135 offsetof(CPUPPCState
, ov32
), "OV32");
136 cpu_ca32
= tcg_global_mem_new(cpu_env
,
137 offsetof(CPUPPCState
, ca32
), "CA32");
139 cpu_reserve
= tcg_global_mem_new(cpu_env
,
140 offsetof(CPUPPCState
, reserve_addr
),
142 cpu_reserve_val
= tcg_global_mem_new(cpu_env
,
143 offsetof(CPUPPCState
, reserve_val
),
146 cpu_fpscr
= tcg_global_mem_new(cpu_env
,
147 offsetof(CPUPPCState
, fpscr
), "fpscr");
149 cpu_access_type
= tcg_global_mem_new_i32(cpu_env
,
150 offsetof(CPUPPCState
, access_type
),
154 /* internal defines */
155 struct DisasContext
{
156 DisasContextBase base
;
159 /* Routine used to access memory */
160 bool pr
, hv
, dr
, le_mode
;
162 bool need_access_type
;
165 /* Translation flags */
166 MemOp default_tcg_memop_mask
;
167 #if defined(TARGET_PPC64)
172 bool altivec_enabled
;
177 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
178 int singlestep_enabled
;
180 uint64_t insns_flags
;
181 uint64_t insns_flags2
;
184 /* Return true iff byteswap is needed in a scalar memop */
185 static inline bool need_byteswap(const DisasContext
*ctx
)
187 #if defined(TARGET_WORDS_BIGENDIAN)
190 return !ctx
->le_mode
;
194 /* True when active word size < size of target_long. */
196 # define NARROW_MODE(C) (!(C)->sf_mode)
198 # define NARROW_MODE(C) 0
201 struct opc_handler_t
{
202 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
204 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
206 /* instruction type */
208 /* extended instruction type */
211 void (*handler
)(DisasContext
*ctx
);
212 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
215 #if defined(DO_PPC_STATISTICS)
220 /* SPR load/store helpers */
221 static inline void gen_load_spr(TCGv t
, int reg
)
223 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
226 static inline void gen_store_spr(int reg
, TCGv t
)
228 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
231 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
233 if (ctx
->need_access_type
&& ctx
->access_type
!= access_type
) {
234 tcg_gen_movi_i32(cpu_access_type
, access_type
);
235 ctx
->access_type
= access_type
;
239 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
241 if (NARROW_MODE(ctx
)) {
244 tcg_gen_movi_tl(cpu_nip
, nip
);
247 static void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
252 * These are all synchronous exceptions, we set the PC back to the
253 * faulting instruction
255 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
256 gen_update_nip(ctx
, ctx
->base
.pc_next
- 4);
258 t0
= tcg_const_i32(excp
);
259 t1
= tcg_const_i32(error
);
260 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
261 tcg_temp_free_i32(t0
);
262 tcg_temp_free_i32(t1
);
263 ctx
->exception
= (excp
);
266 static void gen_exception(DisasContext
*ctx
, uint32_t excp
)
271 * These are all synchronous exceptions, we set the PC back to the
272 * faulting instruction
274 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
275 gen_update_nip(ctx
, ctx
->base
.pc_next
- 4);
277 t0
= tcg_const_i32(excp
);
278 gen_helper_raise_exception(cpu_env
, t0
);
279 tcg_temp_free_i32(t0
);
280 ctx
->exception
= (excp
);
283 static void gen_exception_nip(DisasContext
*ctx
, uint32_t excp
,
288 gen_update_nip(ctx
, nip
);
289 t0
= tcg_const_i32(excp
);
290 gen_helper_raise_exception(cpu_env
, t0
);
291 tcg_temp_free_i32(t0
);
292 ctx
->exception
= (excp
);
296 * Tells the caller what is the appropriate exception to generate and prepares
297 * SPR registers for this exception.
299 * The exception can be either POWERPC_EXCP_TRACE (on most PowerPCs) or
300 * POWERPC_EXCP_DEBUG (on BookE).
302 static uint32_t gen_prep_dbgex(DisasContext
*ctx
)
304 if (ctx
->flags
& POWERPC_FLAG_DE
) {
305 target_ulong dbsr
= 0;
306 if (ctx
->singlestep_enabled
& CPU_SINGLE_STEP
) {
309 /* Must have been branch */
312 TCGv t0
= tcg_temp_new();
313 gen_load_spr(t0
, SPR_BOOKE_DBSR
);
314 tcg_gen_ori_tl(t0
, t0
, dbsr
);
315 gen_store_spr(SPR_BOOKE_DBSR
, t0
);
317 return POWERPC_EXCP_DEBUG
;
319 return POWERPC_EXCP_TRACE
;
323 static void gen_debug_exception(DisasContext
*ctx
)
328 * These are all synchronous exceptions, we set the PC back to the
329 * faulting instruction
331 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
332 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
333 gen_update_nip(ctx
, ctx
->base
.pc_next
);
335 t0
= tcg_const_i32(EXCP_DEBUG
);
336 gen_helper_raise_exception(cpu_env
, t0
);
337 tcg_temp_free_i32(t0
);
340 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
342 /* Will be converted to program check if needed */
343 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_INVAL
| error
);
346 static inline void gen_priv_exception(DisasContext
*ctx
, uint32_t error
)
348 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_PRIV
| error
);
351 static inline void gen_hvpriv_exception(DisasContext
*ctx
, uint32_t error
)
353 /* Will be converted to program check if needed */
354 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_PRIV
| error
);
357 /* Stop translation */
358 static inline void gen_stop_exception(DisasContext
*ctx
)
360 gen_update_nip(ctx
, ctx
->base
.pc_next
);
361 ctx
->exception
= POWERPC_EXCP_STOP
;
364 #ifndef CONFIG_USER_ONLY
365 /* No need to update nip here, as execution flow will change */
366 static inline void gen_sync_exception(DisasContext
*ctx
)
368 ctx
->exception
= POWERPC_EXCP_SYNC
;
372 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
373 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
375 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
376 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
378 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
379 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
381 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
382 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
384 #define GEN_HANDLER_E_2(name, opc1, opc2, opc3, opc4, inval, type, type2) \
385 GEN_OPCODE3(name, opc1, opc2, opc3, opc4, inval, type, type2)
387 #define GEN_HANDLER2_E_2(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) \
388 GEN_OPCODE4(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2)
390 typedef struct opcode_t
{
391 unsigned char opc1
, opc2
, opc3
, opc4
;
392 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
393 unsigned char pad
[4];
395 opc_handler_t handler
;
399 /* Helpers for priv. check */
402 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \
405 #if defined(CONFIG_USER_ONLY)
406 #define CHK_HV GEN_PRIV
407 #define CHK_SV GEN_PRIV
408 #define CHK_HVRM GEN_PRIV
412 if (unlikely(ctx->pr || !ctx->hv)) { \
418 if (unlikely(ctx->pr)) { \
424 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
432 /*****************************************************************************/
433 /* PowerPC instructions table */
435 #if defined(DO_PPC_STATISTICS)
436 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
446 .handler = &gen_##name, \
447 .oname = stringify(name), \
449 .oname = stringify(name), \
451 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
462 .handler = &gen_##name, \
463 .oname = stringify(name), \
465 .oname = stringify(name), \
467 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
477 .handler = &gen_##name, \
482 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
492 .handler = &gen_##name, \
493 .oname = stringify(name), \
495 .oname = stringify(name), \
497 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
507 .handler = &gen_##name, \
513 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
523 .handler = &gen_##name, \
525 .oname = stringify(name), \
527 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
538 .handler = &gen_##name, \
540 .oname = stringify(name), \
542 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
552 .handler = &gen_##name, \
556 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
566 .handler = &gen_##name, \
568 .oname = stringify(name), \
570 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
580 .handler = &gen_##name, \
586 /* Invalid instruction */
587 static void gen_invalid(DisasContext
*ctx
)
589 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
592 static opc_handler_t invalid_handler
= {
593 .inval1
= 0xFFFFFFFF,
594 .inval2
= 0xFFFFFFFF,
597 .handler
= gen_invalid
,
600 /*** Integer comparison ***/
602 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
604 TCGv t0
= tcg_temp_new();
605 TCGv t1
= tcg_temp_new();
606 TCGv_i32 t
= tcg_temp_new_i32();
608 tcg_gen_movi_tl(t0
, CRF_EQ
);
609 tcg_gen_movi_tl(t1
, CRF_LT
);
610 tcg_gen_movcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
),
611 t0
, arg0
, arg1
, t1
, t0
);
612 tcg_gen_movi_tl(t1
, CRF_GT
);
613 tcg_gen_movcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
),
614 t0
, arg0
, arg1
, t1
, t0
);
616 tcg_gen_trunc_tl_i32(t
, t0
);
617 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
618 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t
);
622 tcg_temp_free_i32(t
);
625 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
627 TCGv t0
= tcg_const_tl(arg1
);
628 gen_op_cmp(arg0
, t0
, s
, crf
);
632 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
638 tcg_gen_ext32s_tl(t0
, arg0
);
639 tcg_gen_ext32s_tl(t1
, arg1
);
641 tcg_gen_ext32u_tl(t0
, arg0
);
642 tcg_gen_ext32u_tl(t1
, arg1
);
644 gen_op_cmp(t0
, t1
, s
, crf
);
649 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
651 TCGv t0
= tcg_const_tl(arg1
);
652 gen_op_cmp32(arg0
, t0
, s
, crf
);
656 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
658 if (NARROW_MODE(ctx
)) {
659 gen_op_cmpi32(reg
, 0, 1, 0);
661 gen_op_cmpi(reg
, 0, 1, 0);
666 static void gen_cmp(DisasContext
*ctx
)
668 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
669 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
670 1, crfD(ctx
->opcode
));
672 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
673 1, crfD(ctx
->opcode
));
678 static void gen_cmpi(DisasContext
*ctx
)
680 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
681 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
682 1, crfD(ctx
->opcode
));
684 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
685 1, crfD(ctx
->opcode
));
690 static void gen_cmpl(DisasContext
*ctx
)
692 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
693 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
694 0, crfD(ctx
->opcode
));
696 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
697 0, crfD(ctx
->opcode
));
702 static void gen_cmpli(DisasContext
*ctx
)
704 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
705 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
706 0, crfD(ctx
->opcode
));
708 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
709 0, crfD(ctx
->opcode
));
713 /* cmprb - range comparison: isupper, isaplha, islower*/
714 static void gen_cmprb(DisasContext
*ctx
)
716 TCGv_i32 src1
= tcg_temp_new_i32();
717 TCGv_i32 src2
= tcg_temp_new_i32();
718 TCGv_i32 src2lo
= tcg_temp_new_i32();
719 TCGv_i32 src2hi
= tcg_temp_new_i32();
720 TCGv_i32 crf
= cpu_crf
[crfD(ctx
->opcode
)];
722 tcg_gen_trunc_tl_i32(src1
, cpu_gpr
[rA(ctx
->opcode
)]);
723 tcg_gen_trunc_tl_i32(src2
, cpu_gpr
[rB(ctx
->opcode
)]);
725 tcg_gen_andi_i32(src1
, src1
, 0xFF);
726 tcg_gen_ext8u_i32(src2lo
, src2
);
727 tcg_gen_shri_i32(src2
, src2
, 8);
728 tcg_gen_ext8u_i32(src2hi
, src2
);
730 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
731 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
732 tcg_gen_and_i32(crf
, src2lo
, src2hi
);
734 if (ctx
->opcode
& 0x00200000) {
735 tcg_gen_shri_i32(src2
, src2
, 8);
736 tcg_gen_ext8u_i32(src2lo
, src2
);
737 tcg_gen_shri_i32(src2
, src2
, 8);
738 tcg_gen_ext8u_i32(src2hi
, src2
);
739 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
740 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
741 tcg_gen_and_i32(src2lo
, src2lo
, src2hi
);
742 tcg_gen_or_i32(crf
, crf
, src2lo
);
744 tcg_gen_shli_i32(crf
, crf
, CRF_GT_BIT
);
745 tcg_temp_free_i32(src1
);
746 tcg_temp_free_i32(src2
);
747 tcg_temp_free_i32(src2lo
);
748 tcg_temp_free_i32(src2hi
);
751 #if defined(TARGET_PPC64)
753 static void gen_cmpeqb(DisasContext
*ctx
)
755 gen_helper_cmpeqb(cpu_crf
[crfD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
756 cpu_gpr
[rB(ctx
->opcode
)]);
760 /* isel (PowerPC 2.03 specification) */
761 static void gen_isel(DisasContext
*ctx
)
763 uint32_t bi
= rC(ctx
->opcode
);
764 uint32_t mask
= 0x08 >> (bi
& 0x03);
765 TCGv t0
= tcg_temp_new();
768 tcg_gen_extu_i32_tl(t0
, cpu_crf
[bi
>> 2]);
769 tcg_gen_andi_tl(t0
, t0
, mask
);
771 zr
= tcg_const_tl(0);
772 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rD(ctx
->opcode
)], t0
, zr
,
773 rA(ctx
->opcode
) ? cpu_gpr
[rA(ctx
->opcode
)] : zr
,
774 cpu_gpr
[rB(ctx
->opcode
)]);
779 /* cmpb: PowerPC 2.05 specification */
780 static void gen_cmpb(DisasContext
*ctx
)
782 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
783 cpu_gpr
[rB(ctx
->opcode
)]);
786 /*** Integer arithmetic ***/
788 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
789 TCGv arg1
, TCGv arg2
, int sub
)
791 TCGv t0
= tcg_temp_new();
793 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
794 tcg_gen_xor_tl(t0
, arg1
, arg2
);
796 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
798 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
801 if (NARROW_MODE(ctx
)) {
802 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, 31, 1);
803 if (is_isa300(ctx
)) {
804 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
807 if (is_isa300(ctx
)) {
808 tcg_gen_extract_tl(cpu_ov32
, cpu_ov
, 31, 1);
810 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1, 1);
812 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
815 static inline void gen_op_arith_compute_ca32(DisasContext
*ctx
,
816 TCGv res
, TCGv arg0
, TCGv arg1
,
821 if (!is_isa300(ctx
)) {
827 tcg_gen_eqv_tl(t0
, arg0
, arg1
);
829 tcg_gen_xor_tl(t0
, arg0
, arg1
);
831 tcg_gen_xor_tl(t0
, t0
, res
);
832 tcg_gen_extract_tl(ca32
, t0
, 32, 1);
836 /* Common add function */
837 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
838 TCGv arg2
, TCGv ca
, TCGv ca32
,
839 bool add_ca
, bool compute_ca
,
840 bool compute_ov
, bool compute_rc0
)
844 if (compute_ca
|| compute_ov
) {
849 if (NARROW_MODE(ctx
)) {
851 * Caution: a non-obvious corner case of the spec is that
852 * we must produce the *entire* 64-bit addition, but
853 * produce the carry into bit 32.
855 TCGv t1
= tcg_temp_new();
856 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
857 tcg_gen_add_tl(t0
, arg1
, arg2
);
859 tcg_gen_add_tl(t0
, t0
, ca
);
861 tcg_gen_xor_tl(ca
, t0
, t1
); /* bits changed w/ carry */
863 tcg_gen_extract_tl(ca
, ca
, 32, 1);
864 if (is_isa300(ctx
)) {
865 tcg_gen_mov_tl(ca32
, ca
);
868 TCGv zero
= tcg_const_tl(0);
870 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, ca
, zero
);
871 tcg_gen_add2_tl(t0
, ca
, t0
, ca
, arg2
, zero
);
873 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, arg2
, zero
);
875 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, ca32
, 0);
879 tcg_gen_add_tl(t0
, arg1
, arg2
);
881 tcg_gen_add_tl(t0
, t0
, ca
);
886 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
888 if (unlikely(compute_rc0
)) {
889 gen_set_Rc0(ctx
, t0
);
893 tcg_gen_mov_tl(ret
, t0
);
897 /* Add functions with two operands */
898 #define GEN_INT_ARITH_ADD(name, opc3, ca, add_ca, compute_ca, compute_ov) \
899 static void glue(gen_, name)(DisasContext *ctx) \
901 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
902 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
904 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
906 /* Add functions with one operand and one immediate */
907 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, ca, \
908 add_ca, compute_ca, compute_ov) \
909 static void glue(gen_, name)(DisasContext *ctx) \
911 TCGv t0 = tcg_const_tl(const_val); \
912 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
913 cpu_gpr[rA(ctx->opcode)], t0, \
915 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
919 /* add add. addo addo. */
920 GEN_INT_ARITH_ADD(add
, 0x08, cpu_ca
, 0, 0, 0)
921 GEN_INT_ARITH_ADD(addo
, 0x18, cpu_ca
, 0, 0, 1)
922 /* addc addc. addco addco. */
923 GEN_INT_ARITH_ADD(addc
, 0x00, cpu_ca
, 0, 1, 0)
924 GEN_INT_ARITH_ADD(addco
, 0x10, cpu_ca
, 0, 1, 1)
925 /* adde adde. addeo addeo. */
926 GEN_INT_ARITH_ADD(adde
, 0x04, cpu_ca
, 1, 1, 0)
927 GEN_INT_ARITH_ADD(addeo
, 0x14, cpu_ca
, 1, 1, 1)
928 /* addme addme. addmeo addmeo. */
929 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, cpu_ca
, 1, 1, 0)
930 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, cpu_ca
, 1, 1, 1)
932 GEN_INT_ARITH_ADD(addex
, 0x05, cpu_ov
, 1, 1, 0);
933 /* addze addze. addzeo addzeo.*/
934 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, cpu_ca
, 1, 1, 0)
935 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, cpu_ca
, 1, 1, 1)
937 static void gen_addi(DisasContext
*ctx
)
939 target_long simm
= SIMM(ctx
->opcode
);
941 if (rA(ctx
->opcode
) == 0) {
943 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
945 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
946 cpu_gpr
[rA(ctx
->opcode
)], simm
);
950 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
952 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
953 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
954 c
, cpu_ca
, cpu_ca32
, 0, 1, 0, compute_rc0
);
958 static void gen_addic(DisasContext
*ctx
)
960 gen_op_addic(ctx
, 0);
963 static void gen_addic_(DisasContext
*ctx
)
965 gen_op_addic(ctx
, 1);
969 static void gen_addis(DisasContext
*ctx
)
971 target_long simm
= SIMM(ctx
->opcode
);
973 if (rA(ctx
->opcode
) == 0) {
975 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
977 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
978 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
983 static void gen_addpcis(DisasContext
*ctx
)
985 target_long d
= DX(ctx
->opcode
);
987 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], ctx
->base
.pc_next
+ (d
<< 16));
990 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
991 TCGv arg2
, int sign
, int compute_ov
)
993 TCGv_i32 t0
= tcg_temp_new_i32();
994 TCGv_i32 t1
= tcg_temp_new_i32();
995 TCGv_i32 t2
= tcg_temp_new_i32();
996 TCGv_i32 t3
= tcg_temp_new_i32();
998 tcg_gen_trunc_tl_i32(t0
, arg1
);
999 tcg_gen_trunc_tl_i32(t1
, arg2
);
1001 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1002 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1003 tcg_gen_and_i32(t2
, t2
, t3
);
1004 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1005 tcg_gen_or_i32(t2
, t2
, t3
);
1006 tcg_gen_movi_i32(t3
, 0);
1007 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1008 tcg_gen_div_i32(t3
, t0
, t1
);
1009 tcg_gen_extu_i32_tl(ret
, t3
);
1011 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t1
, 0);
1012 tcg_gen_movi_i32(t3
, 0);
1013 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1014 tcg_gen_divu_i32(t3
, t0
, t1
);
1015 tcg_gen_extu_i32_tl(ret
, t3
);
1018 tcg_gen_extu_i32_tl(cpu_ov
, t2
);
1019 if (is_isa300(ctx
)) {
1020 tcg_gen_extu_i32_tl(cpu_ov32
, t2
);
1022 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1024 tcg_temp_free_i32(t0
);
1025 tcg_temp_free_i32(t1
);
1026 tcg_temp_free_i32(t2
);
1027 tcg_temp_free_i32(t3
);
1029 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1030 gen_set_Rc0(ctx
, ret
);
1034 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1035 static void glue(gen_, name)(DisasContext *ctx) \
1037 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1038 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1039 sign, compute_ov); \
1041 /* divwu divwu. divwuo divwuo. */
1042 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1043 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1044 /* divw divw. divwo divwo. */
1045 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1046 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1048 /* div[wd]eu[o][.] */
1049 #define GEN_DIVE(name, hlpr, compute_ov) \
1050 static void gen_##name(DisasContext *ctx) \
1052 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1053 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1054 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1055 tcg_temp_free_i32(t0); \
1056 if (unlikely(Rc(ctx->opcode) != 0)) { \
1057 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1061 GEN_DIVE(divweu
, divweu
, 0);
1062 GEN_DIVE(divweuo
, divweu
, 1);
1063 GEN_DIVE(divwe
, divwe
, 0);
1064 GEN_DIVE(divweo
, divwe
, 1);
1066 #if defined(TARGET_PPC64)
1067 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1068 TCGv arg2
, int sign
, int compute_ov
)
1070 TCGv_i64 t0
= tcg_temp_new_i64();
1071 TCGv_i64 t1
= tcg_temp_new_i64();
1072 TCGv_i64 t2
= tcg_temp_new_i64();
1073 TCGv_i64 t3
= tcg_temp_new_i64();
1075 tcg_gen_mov_i64(t0
, arg1
);
1076 tcg_gen_mov_i64(t1
, arg2
);
1078 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1079 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1080 tcg_gen_and_i64(t2
, t2
, t3
);
1081 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1082 tcg_gen_or_i64(t2
, t2
, t3
);
1083 tcg_gen_movi_i64(t3
, 0);
1084 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1085 tcg_gen_div_i64(ret
, t0
, t1
);
1087 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t1
, 0);
1088 tcg_gen_movi_i64(t3
, 0);
1089 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1090 tcg_gen_divu_i64(ret
, t0
, t1
);
1093 tcg_gen_mov_tl(cpu_ov
, t2
);
1094 if (is_isa300(ctx
)) {
1095 tcg_gen_mov_tl(cpu_ov32
, t2
);
1097 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1099 tcg_temp_free_i64(t0
);
1100 tcg_temp_free_i64(t1
);
1101 tcg_temp_free_i64(t2
);
1102 tcg_temp_free_i64(t3
);
1104 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1105 gen_set_Rc0(ctx
, ret
);
1109 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1110 static void glue(gen_, name)(DisasContext *ctx) \
1112 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1113 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1114 sign, compute_ov); \
1116 /* divdu divdu. divduo divduo. */
1117 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1118 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1119 /* divd divd. divdo divdo. */
1120 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1121 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1123 GEN_DIVE(divdeu
, divdeu
, 0);
1124 GEN_DIVE(divdeuo
, divdeu
, 1);
1125 GEN_DIVE(divde
, divde
, 0);
1126 GEN_DIVE(divdeo
, divde
, 1);
1129 static inline void gen_op_arith_modw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1130 TCGv arg2
, int sign
)
1132 TCGv_i32 t0
= tcg_temp_new_i32();
1133 TCGv_i32 t1
= tcg_temp_new_i32();
1135 tcg_gen_trunc_tl_i32(t0
, arg1
);
1136 tcg_gen_trunc_tl_i32(t1
, arg2
);
1138 TCGv_i32 t2
= tcg_temp_new_i32();
1139 TCGv_i32 t3
= tcg_temp_new_i32();
1140 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1141 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1142 tcg_gen_and_i32(t2
, t2
, t3
);
1143 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1144 tcg_gen_or_i32(t2
, t2
, t3
);
1145 tcg_gen_movi_i32(t3
, 0);
1146 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1147 tcg_gen_rem_i32(t3
, t0
, t1
);
1148 tcg_gen_ext_i32_tl(ret
, t3
);
1149 tcg_temp_free_i32(t2
);
1150 tcg_temp_free_i32(t3
);
1152 TCGv_i32 t2
= tcg_const_i32(1);
1153 TCGv_i32 t3
= tcg_const_i32(0);
1154 tcg_gen_movcond_i32(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1155 tcg_gen_remu_i32(t3
, t0
, t1
);
1156 tcg_gen_extu_i32_tl(ret
, t3
);
1157 tcg_temp_free_i32(t2
);
1158 tcg_temp_free_i32(t3
);
1160 tcg_temp_free_i32(t0
);
1161 tcg_temp_free_i32(t1
);
1164 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
1165 static void glue(gen_, name)(DisasContext *ctx) \
1167 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
1168 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1172 GEN_INT_ARITH_MODW(moduw
, 0x08, 0);
1173 GEN_INT_ARITH_MODW(modsw
, 0x18, 1);
1175 #if defined(TARGET_PPC64)
1176 static inline void gen_op_arith_modd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1177 TCGv arg2
, int sign
)
1179 TCGv_i64 t0
= tcg_temp_new_i64();
1180 TCGv_i64 t1
= tcg_temp_new_i64();
1182 tcg_gen_mov_i64(t0
, arg1
);
1183 tcg_gen_mov_i64(t1
, arg2
);
1185 TCGv_i64 t2
= tcg_temp_new_i64();
1186 TCGv_i64 t3
= tcg_temp_new_i64();
1187 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1188 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1189 tcg_gen_and_i64(t2
, t2
, t3
);
1190 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1191 tcg_gen_or_i64(t2
, t2
, t3
);
1192 tcg_gen_movi_i64(t3
, 0);
1193 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1194 tcg_gen_rem_i64(ret
, t0
, t1
);
1195 tcg_temp_free_i64(t2
);
1196 tcg_temp_free_i64(t3
);
1198 TCGv_i64 t2
= tcg_const_i64(1);
1199 TCGv_i64 t3
= tcg_const_i64(0);
1200 tcg_gen_movcond_i64(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1201 tcg_gen_remu_i64(ret
, t0
, t1
);
1202 tcg_temp_free_i64(t2
);
1203 tcg_temp_free_i64(t3
);
1205 tcg_temp_free_i64(t0
);
1206 tcg_temp_free_i64(t1
);
1209 #define GEN_INT_ARITH_MODD(name, opc3, sign) \
1210 static void glue(gen_, name)(DisasContext *ctx) \
1212 gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \
1213 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1217 GEN_INT_ARITH_MODD(modud
, 0x08, 0);
1218 GEN_INT_ARITH_MODD(modsd
, 0x18, 1);
1222 static void gen_mulhw(DisasContext
*ctx
)
1224 TCGv_i32 t0
= tcg_temp_new_i32();
1225 TCGv_i32 t1
= tcg_temp_new_i32();
1227 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1228 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1229 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1230 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1231 tcg_temp_free_i32(t0
);
1232 tcg_temp_free_i32(t1
);
1233 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1234 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1238 /* mulhwu mulhwu. */
1239 static void gen_mulhwu(DisasContext
*ctx
)
1241 TCGv_i32 t0
= tcg_temp_new_i32();
1242 TCGv_i32 t1
= tcg_temp_new_i32();
1244 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1245 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1246 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1247 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1248 tcg_temp_free_i32(t0
);
1249 tcg_temp_free_i32(t1
);
1250 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1251 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1256 static void gen_mullw(DisasContext
*ctx
)
1258 #if defined(TARGET_PPC64)
1260 t0
= tcg_temp_new_i64();
1261 t1
= tcg_temp_new_i64();
1262 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1263 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1264 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1268 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1269 cpu_gpr
[rB(ctx
->opcode
)]);
1271 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1272 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1276 /* mullwo mullwo. */
1277 static void gen_mullwo(DisasContext
*ctx
)
1279 TCGv_i32 t0
= tcg_temp_new_i32();
1280 TCGv_i32 t1
= tcg_temp_new_i32();
1282 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1283 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1284 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1285 #if defined(TARGET_PPC64)
1286 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1288 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1291 tcg_gen_sari_i32(t0
, t0
, 31);
1292 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1293 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1294 if (is_isa300(ctx
)) {
1295 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1297 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1299 tcg_temp_free_i32(t0
);
1300 tcg_temp_free_i32(t1
);
1301 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1302 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1307 static void gen_mulli(DisasContext
*ctx
)
1309 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1313 #if defined(TARGET_PPC64)
1315 static void gen_mulhd(DisasContext
*ctx
)
1317 TCGv lo
= tcg_temp_new();
1318 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1319 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1321 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1322 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1326 /* mulhdu mulhdu. */
1327 static void gen_mulhdu(DisasContext
*ctx
)
1329 TCGv lo
= tcg_temp_new();
1330 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1331 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1333 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1334 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1339 static void gen_mulld(DisasContext
*ctx
)
1341 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1342 cpu_gpr
[rB(ctx
->opcode
)]);
1343 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1344 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1348 /* mulldo mulldo. */
1349 static void gen_mulldo(DisasContext
*ctx
)
1351 TCGv_i64 t0
= tcg_temp_new_i64();
1352 TCGv_i64 t1
= tcg_temp_new_i64();
1354 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
1355 cpu_gpr
[rB(ctx
->opcode
)]);
1356 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1358 tcg_gen_sari_i64(t0
, t0
, 63);
1359 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
1360 if (is_isa300(ctx
)) {
1361 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1363 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1365 tcg_temp_free_i64(t0
);
1366 tcg_temp_free_i64(t1
);
1368 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1369 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1374 /* Common subf function */
1375 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1376 TCGv arg2
, bool add_ca
, bool compute_ca
,
1377 bool compute_ov
, bool compute_rc0
)
1381 if (compute_ca
|| compute_ov
) {
1382 t0
= tcg_temp_new();
1386 /* dest = ~arg1 + arg2 [+ ca]. */
1387 if (NARROW_MODE(ctx
)) {
1389 * Caution: a non-obvious corner case of the spec is that
1390 * we must produce the *entire* 64-bit addition, but
1391 * produce the carry into bit 32.
1393 TCGv inv1
= tcg_temp_new();
1394 TCGv t1
= tcg_temp_new();
1395 tcg_gen_not_tl(inv1
, arg1
);
1397 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1399 tcg_gen_addi_tl(t0
, arg2
, 1);
1401 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1402 tcg_gen_add_tl(t0
, t0
, inv1
);
1403 tcg_temp_free(inv1
);
1404 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1406 tcg_gen_extract_tl(cpu_ca
, cpu_ca
, 32, 1);
1407 if (is_isa300(ctx
)) {
1408 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
1410 } else if (add_ca
) {
1411 TCGv zero
, inv1
= tcg_temp_new();
1412 tcg_gen_not_tl(inv1
, arg1
);
1413 zero
= tcg_const_tl(0);
1414 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1415 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1416 gen_op_arith_compute_ca32(ctx
, t0
, inv1
, arg2
, cpu_ca32
, 0);
1417 tcg_temp_free(zero
);
1418 tcg_temp_free(inv1
);
1420 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1421 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1422 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, cpu_ca32
, 1);
1424 } else if (add_ca
) {
1426 * Since we're ignoring carry-out, we can simplify the
1427 * standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1.
1429 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1430 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1431 tcg_gen_subi_tl(t0
, t0
, 1);
1433 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1437 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1439 if (unlikely(compute_rc0
)) {
1440 gen_set_Rc0(ctx
, t0
);
1444 tcg_gen_mov_tl(ret
, t0
);
1448 /* Sub functions with Two operands functions */
1449 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1450 static void glue(gen_, name)(DisasContext *ctx) \
1452 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1453 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1454 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1456 /* Sub functions with one operand and one immediate */
1457 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1458 add_ca, compute_ca, compute_ov) \
1459 static void glue(gen_, name)(DisasContext *ctx) \
1461 TCGv t0 = tcg_const_tl(const_val); \
1462 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1463 cpu_gpr[rA(ctx->opcode)], t0, \
1464 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1465 tcg_temp_free(t0); \
1467 /* subf subf. subfo subfo. */
1468 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1469 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1470 /* subfc subfc. subfco subfco. */
1471 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1472 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1473 /* subfe subfe. subfeo subfo. */
1474 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1475 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1476 /* subfme subfme. subfmeo subfmeo. */
1477 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1478 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1479 /* subfze subfze. subfzeo subfzeo.*/
1480 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1481 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1484 static void gen_subfic(DisasContext
*ctx
)
1486 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1487 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1492 /* neg neg. nego nego. */
1493 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1495 TCGv zero
= tcg_const_tl(0);
1496 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1497 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1498 tcg_temp_free(zero
);
1501 static void gen_neg(DisasContext
*ctx
)
1503 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1504 if (unlikely(Rc(ctx
->opcode
))) {
1505 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1509 static void gen_nego(DisasContext
*ctx
)
1511 gen_op_arith_neg(ctx
, 1);
1514 /*** Integer logical ***/
1515 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1516 static void glue(gen_, name)(DisasContext *ctx) \
1518 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1519 cpu_gpr[rB(ctx->opcode)]); \
1520 if (unlikely(Rc(ctx->opcode) != 0)) \
1521 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1524 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1525 static void glue(gen_, name)(DisasContext *ctx) \
1527 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1528 if (unlikely(Rc(ctx->opcode) != 0)) \
1529 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1533 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1535 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1538 static void gen_andi_(DisasContext
*ctx
)
1540 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1542 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1546 static void gen_andis_(DisasContext
*ctx
)
1548 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1549 UIMM(ctx
->opcode
) << 16);
1550 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1554 static void gen_cntlzw(DisasContext
*ctx
)
1556 TCGv_i32 t
= tcg_temp_new_i32();
1558 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
1559 tcg_gen_clzi_i32(t
, t
, 32);
1560 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
1561 tcg_temp_free_i32(t
);
1563 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1564 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1569 static void gen_cnttzw(DisasContext
*ctx
)
1571 TCGv_i32 t
= tcg_temp_new_i32();
1573 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
1574 tcg_gen_ctzi_i32(t
, t
, 32);
1575 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
1576 tcg_temp_free_i32(t
);
1578 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1579 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1584 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1585 /* extsb & extsb. */
1586 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1587 /* extsh & extsh. */
1588 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1590 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1592 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1594 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
1595 static void gen_pause(DisasContext
*ctx
)
1597 TCGv_i32 t0
= tcg_const_i32(0);
1598 tcg_gen_st_i32(t0
, cpu_env
,
1599 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
1600 tcg_temp_free_i32(t0
);
1602 /* Stop translation, this gives other CPUs a chance to run */
1603 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
1605 #endif /* defined(TARGET_PPC64) */
1608 static void gen_or(DisasContext
*ctx
)
1612 rs
= rS(ctx
->opcode
);
1613 ra
= rA(ctx
->opcode
);
1614 rb
= rB(ctx
->opcode
);
1615 /* Optimisation for mr. ri case */
1616 if (rs
!= ra
|| rs
!= rb
) {
1618 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1620 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1622 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1623 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1625 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1626 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1627 #if defined(TARGET_PPC64)
1628 } else if (rs
!= 0) { /* 0 is nop */
1633 /* Set process priority to low */
1637 /* Set process priority to medium-low */
1641 /* Set process priority to normal */
1644 #if !defined(CONFIG_USER_ONLY)
1647 /* Set process priority to very low */
1653 /* Set process priority to medium-hight */
1659 /* Set process priority to high */
1664 if (ctx
->hv
&& !ctx
->pr
) {
1665 /* Set process priority to very high */
1674 TCGv t0
= tcg_temp_new();
1675 gen_load_spr(t0
, SPR_PPR
);
1676 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1677 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1678 gen_store_spr(SPR_PPR
, t0
);
1681 #if !defined(CONFIG_USER_ONLY)
1683 * Pause out of TCG otherwise spin loops with smt_low eat too
1684 * much CPU and the kernel hangs. This applies to all
1685 * encodings other than no-op, e.g., miso(rs=26), yield(27),
1686 * mdoio(29), mdoom(30), and all currently undefined.
1694 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1697 static void gen_xor(DisasContext
*ctx
)
1699 /* Optimisation for "set to zero" case */
1700 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
1701 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1702 cpu_gpr
[rB(ctx
->opcode
)]);
1704 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1706 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1707 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1712 static void gen_ori(DisasContext
*ctx
)
1714 target_ulong uimm
= UIMM(ctx
->opcode
);
1716 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1719 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1723 static void gen_oris(DisasContext
*ctx
)
1725 target_ulong uimm
= UIMM(ctx
->opcode
);
1727 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1731 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1736 static void gen_xori(DisasContext
*ctx
)
1738 target_ulong uimm
= UIMM(ctx
->opcode
);
1740 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1744 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1748 static void gen_xoris(DisasContext
*ctx
)
1750 target_ulong uimm
= UIMM(ctx
->opcode
);
1752 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1756 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1760 /* popcntb : PowerPC 2.03 specification */
1761 static void gen_popcntb(DisasContext
*ctx
)
1763 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1766 static void gen_popcntw(DisasContext
*ctx
)
1768 #if defined(TARGET_PPC64)
1769 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1771 tcg_gen_ctpop_i32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1775 #if defined(TARGET_PPC64)
1776 /* popcntd: PowerPC 2.06 specification */
1777 static void gen_popcntd(DisasContext
*ctx
)
1779 tcg_gen_ctpop_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1783 /* prtyw: PowerPC 2.05 specification */
1784 static void gen_prtyw(DisasContext
*ctx
)
1786 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1787 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1788 TCGv t0
= tcg_temp_new();
1789 tcg_gen_shri_tl(t0
, rs
, 16);
1790 tcg_gen_xor_tl(ra
, rs
, t0
);
1791 tcg_gen_shri_tl(t0
, ra
, 8);
1792 tcg_gen_xor_tl(ra
, ra
, t0
);
1793 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1797 #if defined(TARGET_PPC64)
1798 /* prtyd: PowerPC 2.05 specification */
1799 static void gen_prtyd(DisasContext
*ctx
)
1801 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1802 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1803 TCGv t0
= tcg_temp_new();
1804 tcg_gen_shri_tl(t0
, rs
, 32);
1805 tcg_gen_xor_tl(ra
, rs
, t0
);
1806 tcg_gen_shri_tl(t0
, ra
, 16);
1807 tcg_gen_xor_tl(ra
, ra
, t0
);
1808 tcg_gen_shri_tl(t0
, ra
, 8);
1809 tcg_gen_xor_tl(ra
, ra
, t0
);
1810 tcg_gen_andi_tl(ra
, ra
, 1);
1815 #if defined(TARGET_PPC64)
1817 static void gen_bpermd(DisasContext
*ctx
)
1819 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
1820 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1824 #if defined(TARGET_PPC64)
1825 /* extsw & extsw. */
1826 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1829 static void gen_cntlzd(DisasContext
*ctx
)
1831 tcg_gen_clzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
1832 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1833 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1838 static void gen_cnttzd(DisasContext
*ctx
)
1840 tcg_gen_ctzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
1841 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1842 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1847 static void gen_darn(DisasContext
*ctx
)
1849 int l
= L(ctx
->opcode
);
1852 tcg_gen_movi_i64(cpu_gpr
[rD(ctx
->opcode
)], -1);
1854 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
1858 gen_helper_darn32(cpu_gpr
[rD(ctx
->opcode
)]);
1860 /* Return 64-bit random for both CRN and RRN */
1861 gen_helper_darn64(cpu_gpr
[rD(ctx
->opcode
)]);
1863 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
1864 gen_stop_exception(ctx
);
1870 /*** Integer rotate ***/
1872 /* rlwimi & rlwimi. */
1873 static void gen_rlwimi(DisasContext
*ctx
)
1875 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1876 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1877 uint32_t sh
= SH(ctx
->opcode
);
1878 uint32_t mb
= MB(ctx
->opcode
);
1879 uint32_t me
= ME(ctx
->opcode
);
1881 if (sh
== (31 - me
) && mb
<= me
) {
1882 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
1887 #if defined(TARGET_PPC64)
1891 mask
= MASK(mb
, me
);
1893 t1
= tcg_temp_new();
1894 if (mask
<= 0xffffffffu
) {
1895 TCGv_i32 t0
= tcg_temp_new_i32();
1896 tcg_gen_trunc_tl_i32(t0
, t_rs
);
1897 tcg_gen_rotli_i32(t0
, t0
, sh
);
1898 tcg_gen_extu_i32_tl(t1
, t0
);
1899 tcg_temp_free_i32(t0
);
1901 #if defined(TARGET_PPC64)
1902 tcg_gen_deposit_i64(t1
, t_rs
, t_rs
, 32, 32);
1903 tcg_gen_rotli_i64(t1
, t1
, sh
);
1905 g_assert_not_reached();
1909 tcg_gen_andi_tl(t1
, t1
, mask
);
1910 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
1911 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
1914 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1915 gen_set_Rc0(ctx
, t_ra
);
1919 /* rlwinm & rlwinm. */
1920 static void gen_rlwinm(DisasContext
*ctx
)
1922 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1923 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1924 int sh
= SH(ctx
->opcode
);
1925 int mb
= MB(ctx
->opcode
);
1926 int me
= ME(ctx
->opcode
);
1927 int len
= me
- mb
+ 1;
1928 int rsh
= (32 - sh
) & 31;
1930 if (sh
!= 0 && len
> 0 && me
== (31 - sh
)) {
1931 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
1932 } else if (me
== 31 && rsh
+ len
<= 32) {
1933 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
1936 #if defined(TARGET_PPC64)
1940 mask
= MASK(mb
, me
);
1941 if (mask
<= 0xffffffffu
) {
1943 tcg_gen_andi_tl(t_ra
, t_rs
, mask
);
1945 TCGv_i32 t0
= tcg_temp_new_i32();
1946 tcg_gen_trunc_tl_i32(t0
, t_rs
);
1947 tcg_gen_rotli_i32(t0
, t0
, sh
);
1948 tcg_gen_andi_i32(t0
, t0
, mask
);
1949 tcg_gen_extu_i32_tl(t_ra
, t0
);
1950 tcg_temp_free_i32(t0
);
1953 #if defined(TARGET_PPC64)
1954 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
1955 tcg_gen_rotli_i64(t_ra
, t_ra
, sh
);
1956 tcg_gen_andi_i64(t_ra
, t_ra
, mask
);
1958 g_assert_not_reached();
1962 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1963 gen_set_Rc0(ctx
, t_ra
);
1967 /* rlwnm & rlwnm. */
1968 static void gen_rlwnm(DisasContext
*ctx
)
1970 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1971 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1972 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
1973 uint32_t mb
= MB(ctx
->opcode
);
1974 uint32_t me
= ME(ctx
->opcode
);
1977 #if defined(TARGET_PPC64)
1981 mask
= MASK(mb
, me
);
1983 if (mask
<= 0xffffffffu
) {
1984 TCGv_i32 t0
= tcg_temp_new_i32();
1985 TCGv_i32 t1
= tcg_temp_new_i32();
1986 tcg_gen_trunc_tl_i32(t0
, t_rb
);
1987 tcg_gen_trunc_tl_i32(t1
, t_rs
);
1988 tcg_gen_andi_i32(t0
, t0
, 0x1f);
1989 tcg_gen_rotl_i32(t1
, t1
, t0
);
1990 tcg_gen_extu_i32_tl(t_ra
, t1
);
1991 tcg_temp_free_i32(t0
);
1992 tcg_temp_free_i32(t1
);
1994 #if defined(TARGET_PPC64)
1995 TCGv_i64 t0
= tcg_temp_new_i64();
1996 tcg_gen_andi_i64(t0
, t_rb
, 0x1f);
1997 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
1998 tcg_gen_rotl_i64(t_ra
, t_ra
, t0
);
1999 tcg_temp_free_i64(t0
);
2001 g_assert_not_reached();
2005 tcg_gen_andi_tl(t_ra
, t_ra
, mask
);
2007 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2008 gen_set_Rc0(ctx
, t_ra
);
2012 #if defined(TARGET_PPC64)
2013 #define GEN_PPC64_R2(name, opc1, opc2) \
2014 static void glue(gen_, name##0)(DisasContext *ctx) \
2016 gen_##name(ctx, 0); \
2019 static void glue(gen_, name##1)(DisasContext *ctx) \
2021 gen_##name(ctx, 1); \
2023 #define GEN_PPC64_R4(name, opc1, opc2) \
2024 static void glue(gen_, name##0)(DisasContext *ctx) \
2026 gen_##name(ctx, 0, 0); \
2029 static void glue(gen_, name##1)(DisasContext *ctx) \
2031 gen_##name(ctx, 0, 1); \
2034 static void glue(gen_, name##2)(DisasContext *ctx) \
2036 gen_##name(ctx, 1, 0); \
2039 static void glue(gen_, name##3)(DisasContext *ctx) \
2041 gen_##name(ctx, 1, 1); \
2044 static void gen_rldinm(DisasContext
*ctx
, int mb
, int me
, int sh
)
2046 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2047 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2048 int len
= me
- mb
+ 1;
2049 int rsh
= (64 - sh
) & 63;
2051 if (sh
!= 0 && len
> 0 && me
== (63 - sh
)) {
2052 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2053 } else if (me
== 63 && rsh
+ len
<= 64) {
2054 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2056 tcg_gen_rotli_tl(t_ra
, t_rs
, sh
);
2057 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2059 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2060 gen_set_Rc0(ctx
, t_ra
);
2064 /* rldicl - rldicl. */
2065 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
2069 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2070 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2071 gen_rldinm(ctx
, mb
, 63, sh
);
2073 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
2075 /* rldicr - rldicr. */
2076 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
2080 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2081 me
= MB(ctx
->opcode
) | (men
<< 5);
2082 gen_rldinm(ctx
, 0, me
, sh
);
2084 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
2086 /* rldic - rldic. */
2087 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
2091 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2092 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2093 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
2095 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
2097 static void gen_rldnm(DisasContext
*ctx
, int mb
, int me
)
2099 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2100 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2101 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2104 t0
= tcg_temp_new();
2105 tcg_gen_andi_tl(t0
, t_rb
, 0x3f);
2106 tcg_gen_rotl_tl(t_ra
, t_rs
, t0
);
2109 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2110 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2111 gen_set_Rc0(ctx
, t_ra
);
2115 /* rldcl - rldcl. */
2116 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
2120 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2121 gen_rldnm(ctx
, mb
, 63);
2123 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
2125 /* rldcr - rldcr. */
2126 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
2130 me
= MB(ctx
->opcode
) | (men
<< 5);
2131 gen_rldnm(ctx
, 0, me
);
2133 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
2135 /* rldimi - rldimi. */
2136 static void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
2138 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2139 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2140 uint32_t sh
= SH(ctx
->opcode
) | (shn
<< 5);
2141 uint32_t mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2142 uint32_t me
= 63 - sh
;
2145 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2147 target_ulong mask
= MASK(mb
, me
);
2148 TCGv t1
= tcg_temp_new();
2150 tcg_gen_rotli_tl(t1
, t_rs
, sh
);
2151 tcg_gen_andi_tl(t1
, t1
, mask
);
2152 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2153 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2156 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2157 gen_set_Rc0(ctx
, t_ra
);
2160 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
2163 /*** Integer shift ***/
2166 static void gen_slw(DisasContext
*ctx
)
2170 t0
= tcg_temp_new();
2171 /* AND rS with a mask that is 0 when rB >= 0x20 */
2172 #if defined(TARGET_PPC64)
2173 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2174 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2176 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2177 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2179 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2180 t1
= tcg_temp_new();
2181 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2182 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2185 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2186 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2187 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2192 static void gen_sraw(DisasContext
*ctx
)
2194 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2195 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2196 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2197 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2201 /* srawi & srawi. */
2202 static void gen_srawi(DisasContext
*ctx
)
2204 int sh
= SH(ctx
->opcode
);
2205 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2206 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2208 tcg_gen_ext32s_tl(dst
, src
);
2209 tcg_gen_movi_tl(cpu_ca
, 0);
2210 if (is_isa300(ctx
)) {
2211 tcg_gen_movi_tl(cpu_ca32
, 0);
2215 tcg_gen_ext32s_tl(dst
, src
);
2216 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
2217 t0
= tcg_temp_new();
2218 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
2219 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2221 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2222 if (is_isa300(ctx
)) {
2223 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2225 tcg_gen_sari_tl(dst
, dst
, sh
);
2227 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2228 gen_set_Rc0(ctx
, dst
);
2233 static void gen_srw(DisasContext
*ctx
)
2237 t0
= tcg_temp_new();
2238 /* AND rS with a mask that is 0 when rB >= 0x20 */
2239 #if defined(TARGET_PPC64)
2240 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2241 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2243 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2244 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2246 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2247 tcg_gen_ext32u_tl(t0
, t0
);
2248 t1
= tcg_temp_new();
2249 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2250 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2253 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2254 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2258 #if defined(TARGET_PPC64)
2260 static void gen_sld(DisasContext
*ctx
)
2264 t0
= tcg_temp_new();
2265 /* AND rS with a mask that is 0 when rB >= 0x40 */
2266 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2267 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2268 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2269 t1
= tcg_temp_new();
2270 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2271 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2274 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2275 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2280 static void gen_srad(DisasContext
*ctx
)
2282 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2283 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2284 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2285 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2288 /* sradi & sradi. */
2289 static inline void gen_sradi(DisasContext
*ctx
, int n
)
2291 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2292 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2293 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2295 tcg_gen_mov_tl(dst
, src
);
2296 tcg_gen_movi_tl(cpu_ca
, 0);
2297 if (is_isa300(ctx
)) {
2298 tcg_gen_movi_tl(cpu_ca32
, 0);
2302 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
2303 t0
= tcg_temp_new();
2304 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
2305 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2307 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2308 if (is_isa300(ctx
)) {
2309 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2311 tcg_gen_sari_tl(dst
, src
, sh
);
2313 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2314 gen_set_Rc0(ctx
, dst
);
2318 static void gen_sradi0(DisasContext
*ctx
)
2323 static void gen_sradi1(DisasContext
*ctx
)
2328 /* extswsli & extswsli. */
2329 static inline void gen_extswsli(DisasContext
*ctx
, int n
)
2331 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2332 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2333 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2335 tcg_gen_ext32s_tl(dst
, src
);
2336 tcg_gen_shli_tl(dst
, dst
, sh
);
2337 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2338 gen_set_Rc0(ctx
, dst
);
2342 static void gen_extswsli0(DisasContext
*ctx
)
2344 gen_extswsli(ctx
, 0);
2347 static void gen_extswsli1(DisasContext
*ctx
)
2349 gen_extswsli(ctx
, 1);
2353 static void gen_srd(DisasContext
*ctx
)
2357 t0
= tcg_temp_new();
2358 /* AND rS with a mask that is 0 when rB >= 0x40 */
2359 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2360 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2361 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2362 t1
= tcg_temp_new();
2363 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2364 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2367 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2368 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2373 /*** Addressing modes ***/
2374 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2375 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2378 target_long simm
= SIMM(ctx
->opcode
);
2381 if (rA(ctx
->opcode
) == 0) {
2382 if (NARROW_MODE(ctx
)) {
2383 simm
= (uint32_t)simm
;
2385 tcg_gen_movi_tl(EA
, simm
);
2386 } else if (likely(simm
!= 0)) {
2387 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2388 if (NARROW_MODE(ctx
)) {
2389 tcg_gen_ext32u_tl(EA
, EA
);
2392 if (NARROW_MODE(ctx
)) {
2393 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2395 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2400 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2402 if (rA(ctx
->opcode
) == 0) {
2403 if (NARROW_MODE(ctx
)) {
2404 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2406 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2409 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2410 if (NARROW_MODE(ctx
)) {
2411 tcg_gen_ext32u_tl(EA
, EA
);
2416 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2418 if (rA(ctx
->opcode
) == 0) {
2419 tcg_gen_movi_tl(EA
, 0);
2420 } else if (NARROW_MODE(ctx
)) {
2421 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2423 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2427 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2430 tcg_gen_addi_tl(ret
, arg1
, val
);
2431 if (NARROW_MODE(ctx
)) {
2432 tcg_gen_ext32u_tl(ret
, ret
);
2436 static inline void gen_align_no_le(DisasContext
*ctx
)
2438 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
,
2439 (ctx
->opcode
& 0x03FF0000) | POWERPC_EXCP_ALIGN_LE
);
2442 /*** Integer load ***/
2443 #define DEF_MEMOP(op) ((op) | ctx->default_tcg_memop_mask)
2444 #define BSWAP_MEMOP(op) ((op) | (ctx->default_tcg_memop_mask ^ MO_BSWAP))
2446 #define GEN_QEMU_LOAD_TL(ldop, op) \
2447 static void glue(gen_qemu_, ldop)(DisasContext *ctx, \
2451 tcg_gen_qemu_ld_tl(val, addr, ctx->mem_idx, op); \
2454 GEN_QEMU_LOAD_TL(ld8u
, DEF_MEMOP(MO_UB
))
2455 GEN_QEMU_LOAD_TL(ld16u
, DEF_MEMOP(MO_UW
))
2456 GEN_QEMU_LOAD_TL(ld16s
, DEF_MEMOP(MO_SW
))
2457 GEN_QEMU_LOAD_TL(ld32u
, DEF_MEMOP(MO_UL
))
2458 GEN_QEMU_LOAD_TL(ld32s
, DEF_MEMOP(MO_SL
))
2460 GEN_QEMU_LOAD_TL(ld16ur
, BSWAP_MEMOP(MO_UW
))
2461 GEN_QEMU_LOAD_TL(ld32ur
, BSWAP_MEMOP(MO_UL
))
2463 #define GEN_QEMU_LOAD_64(ldop, op) \
2464 static void glue(gen_qemu_, glue(ldop, _i64))(DisasContext *ctx, \
2468 tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, op); \
2471 GEN_QEMU_LOAD_64(ld8u
, DEF_MEMOP(MO_UB
))
2472 GEN_QEMU_LOAD_64(ld16u
, DEF_MEMOP(MO_UW
))
2473 GEN_QEMU_LOAD_64(ld32u
, DEF_MEMOP(MO_UL
))
2474 GEN_QEMU_LOAD_64(ld32s
, DEF_MEMOP(MO_SL
))
2475 GEN_QEMU_LOAD_64(ld64
, DEF_MEMOP(MO_Q
))
2477 #if defined(TARGET_PPC64)
2478 GEN_QEMU_LOAD_64(ld64ur
, BSWAP_MEMOP(MO_Q
))
2481 #define GEN_QEMU_STORE_TL(stop, op) \
2482 static void glue(gen_qemu_, stop)(DisasContext *ctx, \
2486 tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, op); \
2489 GEN_QEMU_STORE_TL(st8
, DEF_MEMOP(MO_UB
))
2490 GEN_QEMU_STORE_TL(st16
, DEF_MEMOP(MO_UW
))
2491 GEN_QEMU_STORE_TL(st32
, DEF_MEMOP(MO_UL
))
2493 GEN_QEMU_STORE_TL(st16r
, BSWAP_MEMOP(MO_UW
))
2494 GEN_QEMU_STORE_TL(st32r
, BSWAP_MEMOP(MO_UL
))
2496 #define GEN_QEMU_STORE_64(stop, op) \
2497 static void glue(gen_qemu_, glue(stop, _i64))(DisasContext *ctx, \
2501 tcg_gen_qemu_st_i64(val, addr, ctx->mem_idx, op); \
2504 GEN_QEMU_STORE_64(st8
, DEF_MEMOP(MO_UB
))
2505 GEN_QEMU_STORE_64(st16
, DEF_MEMOP(MO_UW
))
2506 GEN_QEMU_STORE_64(st32
, DEF_MEMOP(MO_UL
))
2507 GEN_QEMU_STORE_64(st64
, DEF_MEMOP(MO_Q
))
2509 #if defined(TARGET_PPC64)
2510 GEN_QEMU_STORE_64(st64r
, BSWAP_MEMOP(MO_Q
))
2513 #define GEN_LD(name, ldop, opc, type) \
2514 static void glue(gen_, name)(DisasContext *ctx) \
2517 gen_set_access_type(ctx, ACCESS_INT); \
2518 EA = tcg_temp_new(); \
2519 gen_addr_imm_index(ctx, EA, 0); \
2520 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2521 tcg_temp_free(EA); \
2524 #define GEN_LDU(name, ldop, opc, type) \
2525 static void glue(gen_, name##u)(DisasContext *ctx) \
2528 if (unlikely(rA(ctx->opcode) == 0 || \
2529 rA(ctx->opcode) == rD(ctx->opcode))) { \
2530 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2533 gen_set_access_type(ctx, ACCESS_INT); \
2534 EA = tcg_temp_new(); \
2535 if (type == PPC_64B) \
2536 gen_addr_imm_index(ctx, EA, 0x03); \
2538 gen_addr_imm_index(ctx, EA, 0); \
2539 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2540 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2541 tcg_temp_free(EA); \
2544 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2545 static void glue(gen_, name##ux)(DisasContext *ctx) \
2548 if (unlikely(rA(ctx->opcode) == 0 || \
2549 rA(ctx->opcode) == rD(ctx->opcode))) { \
2550 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2553 gen_set_access_type(ctx, ACCESS_INT); \
2554 EA = tcg_temp_new(); \
2555 gen_addr_reg_index(ctx, EA); \
2556 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2557 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2558 tcg_temp_free(EA); \
2561 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
2562 static void glue(gen_, name##x)(DisasContext *ctx) \
2566 gen_set_access_type(ctx, ACCESS_INT); \
2567 EA = tcg_temp_new(); \
2568 gen_addr_reg_index(ctx, EA); \
2569 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2570 tcg_temp_free(EA); \
2573 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2574 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
2576 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
2577 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
2579 #define GEN_LDS(name, ldop, op, type) \
2580 GEN_LD(name, ldop, op | 0x20, type); \
2581 GEN_LDU(name, ldop, op | 0x21, type); \
2582 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2583 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2585 /* lbz lbzu lbzux lbzx */
2586 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2587 /* lha lhau lhaux lhax */
2588 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2589 /* lhz lhzu lhzux lhzx */
2590 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2591 /* lwz lwzu lwzux lwzx */
2592 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2594 #define GEN_LDEPX(name, ldop, opc2, opc3) \
2595 static void glue(gen_, name##epx)(DisasContext *ctx) \
2599 gen_set_access_type(ctx, ACCESS_INT); \
2600 EA = tcg_temp_new(); \
2601 gen_addr_reg_index(ctx, EA); \
2602 tcg_gen_qemu_ld_tl(cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_LOAD, ldop);\
2603 tcg_temp_free(EA); \
2606 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
2607 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
2608 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
2609 #if defined(TARGET_PPC64)
2610 GEN_LDEPX(ld
, DEF_MEMOP(MO_Q
), 0x1D, 0x00)
2613 #if defined(TARGET_PPC64)
2615 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2617 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2619 GEN_LDUX(ld
, ld64_i64
, 0x15, 0x01, PPC_64B
);
2621 GEN_LDX(ld
, ld64_i64
, 0x15, 0x00, PPC_64B
);
2623 /* CI load/store variants */
2624 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
2625 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x15, PPC_CILDST
)
2626 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
2627 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
2629 static void gen_ld(DisasContext
*ctx
)
2632 if (Rc(ctx
->opcode
)) {
2633 if (unlikely(rA(ctx
->opcode
) == 0 ||
2634 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2635 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2639 gen_set_access_type(ctx
, ACCESS_INT
);
2640 EA
= tcg_temp_new();
2641 gen_addr_imm_index(ctx
, EA
, 0x03);
2642 if (ctx
->opcode
& 0x02) {
2643 /* lwa (lwau is undefined) */
2644 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2647 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2649 if (Rc(ctx
->opcode
)) {
2650 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2656 static void gen_lq(DisasContext
*ctx
)
2661 /* lq is a legal user mode instruction starting in ISA 2.07 */
2662 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2663 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2665 if (!legal_in_user_mode
&& ctx
->pr
) {
2666 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2670 if (!le_is_supported
&& ctx
->le_mode
) {
2671 gen_align_no_le(ctx
);
2674 ra
= rA(ctx
->opcode
);
2675 rd
= rD(ctx
->opcode
);
2676 if (unlikely((rd
& 1) || rd
== ra
)) {
2677 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2681 gen_set_access_type(ctx
, ACCESS_INT
);
2682 EA
= tcg_temp_new();
2683 gen_addr_imm_index(ctx
, EA
, 0x0F);
2685 /* Note that the low part is always in RD+1, even in LE mode. */
2686 lo
= cpu_gpr
[rd
+ 1];
2689 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
2690 if (HAVE_ATOMIC128
) {
2691 TCGv_i32 oi
= tcg_temp_new_i32();
2693 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
, ctx
->mem_idx
));
2694 gen_helper_lq_le_parallel(lo
, cpu_env
, EA
, oi
);
2696 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
, ctx
->mem_idx
));
2697 gen_helper_lq_be_parallel(lo
, cpu_env
, EA
, oi
);
2699 tcg_temp_free_i32(oi
);
2700 tcg_gen_ld_i64(hi
, cpu_env
, offsetof(CPUPPCState
, retxh
));
2702 /* Restart with exclusive lock. */
2703 gen_helper_exit_atomic(cpu_env
);
2704 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2706 } else if (ctx
->le_mode
) {
2707 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
);
2708 gen_addr_add(ctx
, EA
, EA
, 8);
2709 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
2711 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
);
2712 gen_addr_add(ctx
, EA
, EA
, 8);
2713 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
2719 /*** Integer store ***/
2720 #define GEN_ST(name, stop, opc, type) \
2721 static void glue(gen_, name)(DisasContext *ctx) \
2724 gen_set_access_type(ctx, ACCESS_INT); \
2725 EA = tcg_temp_new(); \
2726 gen_addr_imm_index(ctx, EA, 0); \
2727 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2728 tcg_temp_free(EA); \
2731 #define GEN_STU(name, stop, opc, type) \
2732 static void glue(gen_, stop##u)(DisasContext *ctx) \
2735 if (unlikely(rA(ctx->opcode) == 0)) { \
2736 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2739 gen_set_access_type(ctx, ACCESS_INT); \
2740 EA = tcg_temp_new(); \
2741 if (type == PPC_64B) \
2742 gen_addr_imm_index(ctx, EA, 0x03); \
2744 gen_addr_imm_index(ctx, EA, 0); \
2745 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2746 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2747 tcg_temp_free(EA); \
2750 #define GEN_STUX(name, stop, opc2, opc3, type) \
2751 static void glue(gen_, name##ux)(DisasContext *ctx) \
2754 if (unlikely(rA(ctx->opcode) == 0)) { \
2755 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2758 gen_set_access_type(ctx, ACCESS_INT); \
2759 EA = tcg_temp_new(); \
2760 gen_addr_reg_index(ctx, EA); \
2761 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2762 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2763 tcg_temp_free(EA); \
2766 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
2767 static void glue(gen_, name##x)(DisasContext *ctx) \
2771 gen_set_access_type(ctx, ACCESS_INT); \
2772 EA = tcg_temp_new(); \
2773 gen_addr_reg_index(ctx, EA); \
2774 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2775 tcg_temp_free(EA); \
2777 #define GEN_STX(name, stop, opc2, opc3, type) \
2778 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
2780 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
2781 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
2783 #define GEN_STS(name, stop, op, type) \
2784 GEN_ST(name, stop, op | 0x20, type); \
2785 GEN_STU(name, stop, op | 0x21, type); \
2786 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2787 GEN_STX(name, stop, 0x17, op | 0x00, type)
2789 /* stb stbu stbux stbx */
2790 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2791 /* sth sthu sthux sthx */
2792 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2793 /* stw stwu stwux stwx */
2794 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2796 #define GEN_STEPX(name, stop, opc2, opc3) \
2797 static void glue(gen_, name##epx)(DisasContext *ctx) \
2801 gen_set_access_type(ctx, ACCESS_INT); \
2802 EA = tcg_temp_new(); \
2803 gen_addr_reg_index(ctx, EA); \
2804 tcg_gen_qemu_st_tl( \
2805 cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_STORE, stop); \
2806 tcg_temp_free(EA); \
2809 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
2810 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
2811 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
2812 #if defined(TARGET_PPC64)
2813 GEN_STEPX(std
, DEF_MEMOP(MO_Q
), 0x1d, 0x04)
2816 #if defined(TARGET_PPC64)
2817 GEN_STUX(std
, st64_i64
, 0x15, 0x05, PPC_64B
);
2818 GEN_STX(std
, st64_i64
, 0x15, 0x04, PPC_64B
);
2819 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
2820 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
2821 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
2822 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
2824 static void gen_std(DisasContext
*ctx
)
2829 rs
= rS(ctx
->opcode
);
2830 if ((ctx
->opcode
& 0x3) == 0x2) { /* stq */
2831 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2832 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2835 if (!(ctx
->insns_flags
& PPC_64BX
)) {
2836 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2839 if (!legal_in_user_mode
&& ctx
->pr
) {
2840 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2844 if (!le_is_supported
&& ctx
->le_mode
) {
2845 gen_align_no_le(ctx
);
2849 if (unlikely(rs
& 1)) {
2850 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2853 gen_set_access_type(ctx
, ACCESS_INT
);
2854 EA
= tcg_temp_new();
2855 gen_addr_imm_index(ctx
, EA
, 0x03);
2857 /* Note that the low part is always in RS+1, even in LE mode. */
2858 lo
= cpu_gpr
[rs
+ 1];
2861 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
2862 if (HAVE_ATOMIC128
) {
2863 TCGv_i32 oi
= tcg_temp_new_i32();
2865 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
, ctx
->mem_idx
));
2866 gen_helper_stq_le_parallel(cpu_env
, EA
, lo
, hi
, oi
);
2868 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
, ctx
->mem_idx
));
2869 gen_helper_stq_be_parallel(cpu_env
, EA
, lo
, hi
, oi
);
2871 tcg_temp_free_i32(oi
);
2873 /* Restart with exclusive lock. */
2874 gen_helper_exit_atomic(cpu_env
);
2875 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2877 } else if (ctx
->le_mode
) {
2878 tcg_gen_qemu_st_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
);
2879 gen_addr_add(ctx
, EA
, EA
, 8);
2880 tcg_gen_qemu_st_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
2882 tcg_gen_qemu_st_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
);
2883 gen_addr_add(ctx
, EA
, EA
, 8);
2884 tcg_gen_qemu_st_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
2889 if (Rc(ctx
->opcode
)) {
2890 if (unlikely(rA(ctx
->opcode
) == 0)) {
2891 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2895 gen_set_access_type(ctx
, ACCESS_INT
);
2896 EA
= tcg_temp_new();
2897 gen_addr_imm_index(ctx
, EA
, 0x03);
2898 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
2899 if (Rc(ctx
->opcode
)) {
2900 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2906 /*** Integer load and store with byte reverse ***/
2909 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2912 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2914 #if defined(TARGET_PPC64)
2916 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
2918 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
2919 #endif /* TARGET_PPC64 */
2922 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2924 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2926 /*** Integer load and store multiple ***/
2929 static void gen_lmw(DisasContext
*ctx
)
2935 gen_align_no_le(ctx
);
2938 gen_set_access_type(ctx
, ACCESS_INT
);
2939 t0
= tcg_temp_new();
2940 t1
= tcg_const_i32(rD(ctx
->opcode
));
2941 gen_addr_imm_index(ctx
, t0
, 0);
2942 gen_helper_lmw(cpu_env
, t0
, t1
);
2944 tcg_temp_free_i32(t1
);
2948 static void gen_stmw(DisasContext
*ctx
)
2954 gen_align_no_le(ctx
);
2957 gen_set_access_type(ctx
, ACCESS_INT
);
2958 t0
= tcg_temp_new();
2959 t1
= tcg_const_i32(rS(ctx
->opcode
));
2960 gen_addr_imm_index(ctx
, t0
, 0);
2961 gen_helper_stmw(cpu_env
, t0
, t1
);
2963 tcg_temp_free_i32(t1
);
2966 /*** Integer load and store strings ***/
2970 * PowerPC32 specification says we must generate an exception if rA is
2971 * in the range of registers to be loaded. In an other hand, IBM says
2972 * this is valid, but rA won't be loaded. For now, I'll follow the
2975 static void gen_lswi(DisasContext
*ctx
)
2979 int nb
= NB(ctx
->opcode
);
2980 int start
= rD(ctx
->opcode
);
2981 int ra
= rA(ctx
->opcode
);
2985 gen_align_no_le(ctx
);
2991 nr
= DIV_ROUND_UP(nb
, 4);
2992 if (unlikely(lsw_reg_in_range(start
, nr
, ra
))) {
2993 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
2996 gen_set_access_type(ctx
, ACCESS_INT
);
2997 t0
= tcg_temp_new();
2998 gen_addr_register(ctx
, t0
);
2999 t1
= tcg_const_i32(nb
);
3000 t2
= tcg_const_i32(start
);
3001 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3003 tcg_temp_free_i32(t1
);
3004 tcg_temp_free_i32(t2
);
3008 static void gen_lswx(DisasContext
*ctx
)
3011 TCGv_i32 t1
, t2
, t3
;
3014 gen_align_no_le(ctx
);
3017 gen_set_access_type(ctx
, ACCESS_INT
);
3018 t0
= tcg_temp_new();
3019 gen_addr_reg_index(ctx
, t0
);
3020 t1
= tcg_const_i32(rD(ctx
->opcode
));
3021 t2
= tcg_const_i32(rA(ctx
->opcode
));
3022 t3
= tcg_const_i32(rB(ctx
->opcode
));
3023 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3025 tcg_temp_free_i32(t1
);
3026 tcg_temp_free_i32(t2
);
3027 tcg_temp_free_i32(t3
);
3031 static void gen_stswi(DisasContext
*ctx
)
3035 int nb
= NB(ctx
->opcode
);
3038 gen_align_no_le(ctx
);
3041 gen_set_access_type(ctx
, ACCESS_INT
);
3042 t0
= tcg_temp_new();
3043 gen_addr_register(ctx
, t0
);
3047 t1
= tcg_const_i32(nb
);
3048 t2
= tcg_const_i32(rS(ctx
->opcode
));
3049 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3051 tcg_temp_free_i32(t1
);
3052 tcg_temp_free_i32(t2
);
3056 static void gen_stswx(DisasContext
*ctx
)
3062 gen_align_no_le(ctx
);
3065 gen_set_access_type(ctx
, ACCESS_INT
);
3066 t0
= tcg_temp_new();
3067 gen_addr_reg_index(ctx
, t0
);
3068 t1
= tcg_temp_new_i32();
3069 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3070 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3071 t2
= tcg_const_i32(rS(ctx
->opcode
));
3072 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3074 tcg_temp_free_i32(t1
);
3075 tcg_temp_free_i32(t2
);
3078 /*** Memory synchronisation ***/
3080 static void gen_eieio(DisasContext
*ctx
)
3082 TCGBar bar
= TCG_MO_LD_ST
;
3085 * POWER9 has a eieio instruction variant using bit 6 as a hint to
3086 * tell the CPU it is a store-forwarding barrier.
3088 if (ctx
->opcode
& 0x2000000) {
3090 * ISA says that "Reserved fields in instructions are ignored
3091 * by the processor". So ignore the bit 6 on non-POWER9 CPU but
3092 * as this is not an instruction software should be using,
3093 * complain to the user.
3095 if (!(ctx
->insns_flags2
& PPC2_ISA300
)) {
3096 qemu_log_mask(LOG_GUEST_ERROR
, "invalid eieio using bit 6 at @"
3097 TARGET_FMT_lx
"\n", ctx
->base
.pc_next
- 4);
3103 tcg_gen_mb(bar
| TCG_BAR_SC
);
3106 #if !defined(CONFIG_USER_ONLY)
3107 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
)
3112 if (!ctx
->lazy_tlb_flush
) {
3115 l
= gen_new_label();
3116 t
= tcg_temp_new_i32();
3117 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
3118 tcg_gen_brcondi_i32(TCG_COND_EQ
, t
, 0, l
);
3120 gen_helper_check_tlb_flush_global(cpu_env
);
3122 gen_helper_check_tlb_flush_local(cpu_env
);
3125 tcg_temp_free_i32(t
);
3128 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
) { }
3132 static void gen_isync(DisasContext
*ctx
)
3135 * We need to check for a pending TLB flush. This can only happen in
3136 * kernel mode however so check MSR_PR
3139 gen_check_tlb_flush(ctx
, false);
3141 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
3142 gen_stop_exception(ctx
);
3145 #define MEMOP_GET_SIZE(x) (1 << ((x) & MO_SIZE))
3147 static void gen_load_locked(DisasContext
*ctx
, MemOp memop
)
3149 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3150 TCGv t0
= tcg_temp_new();
3152 gen_set_access_type(ctx
, ACCESS_RES
);
3153 gen_addr_reg_index(ctx
, t0
);
3154 tcg_gen_qemu_ld_tl(gpr
, t0
, ctx
->mem_idx
, memop
| MO_ALIGN
);
3155 tcg_gen_mov_tl(cpu_reserve
, t0
);
3156 tcg_gen_mov_tl(cpu_reserve_val
, gpr
);
3157 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3161 #define LARX(name, memop) \
3162 static void gen_##name(DisasContext *ctx) \
3164 gen_load_locked(ctx, memop); \
3168 LARX(lbarx
, DEF_MEMOP(MO_UB
))
3169 LARX(lharx
, DEF_MEMOP(MO_UW
))
3170 LARX(lwarx
, DEF_MEMOP(MO_UL
))
3172 static void gen_fetch_inc_conditional(DisasContext
*ctx
, MemOp memop
,
3173 TCGv EA
, TCGCond cond
, int addend
)
3175 TCGv t
= tcg_temp_new();
3176 TCGv t2
= tcg_temp_new();
3177 TCGv u
= tcg_temp_new();
3179 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
3180 tcg_gen_addi_tl(t2
, EA
, MEMOP_GET_SIZE(memop
));
3181 tcg_gen_qemu_ld_tl(t2
, t2
, ctx
->mem_idx
, memop
);
3182 tcg_gen_addi_tl(u
, t
, addend
);
3184 /* E.g. for fetch and increment bounded... */
3185 /* mem(EA,s) = (t != t2 ? u = t + 1 : t) */
3186 tcg_gen_movcond_tl(cond
, u
, t
, t2
, u
, t
);
3187 tcg_gen_qemu_st_tl(u
, EA
, ctx
->mem_idx
, memop
);
3189 /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */
3190 tcg_gen_movi_tl(u
, 1 << (MEMOP_GET_SIZE(memop
) * 8 - 1));
3191 tcg_gen_movcond_tl(cond
, cpu_gpr
[rD(ctx
->opcode
)], t
, t2
, t
, u
);
3198 static void gen_ld_atomic(DisasContext
*ctx
, MemOp memop
)
3200 uint32_t gpr_FC
= FC(ctx
->opcode
);
3201 TCGv EA
= tcg_temp_new();
3202 int rt
= rD(ctx
->opcode
);
3206 gen_addr_register(ctx
, EA
);
3208 src
= cpu_gpr
[(rt
+ 1) & 31];
3210 need_serial
= false;
3213 case 0: /* Fetch and add */
3214 tcg_gen_atomic_fetch_add_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3216 case 1: /* Fetch and xor */
3217 tcg_gen_atomic_fetch_xor_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3219 case 2: /* Fetch and or */
3220 tcg_gen_atomic_fetch_or_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3222 case 3: /* Fetch and 'and' */
3223 tcg_gen_atomic_fetch_and_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3225 case 4: /* Fetch and max unsigned */
3226 tcg_gen_atomic_fetch_umax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3228 case 5: /* Fetch and max signed */
3229 tcg_gen_atomic_fetch_smax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3231 case 6: /* Fetch and min unsigned */
3232 tcg_gen_atomic_fetch_umin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3234 case 7: /* Fetch and min signed */
3235 tcg_gen_atomic_fetch_smin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3238 tcg_gen_atomic_xchg_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3241 case 16: /* Compare and swap not equal */
3242 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3245 TCGv t0
= tcg_temp_new();
3246 TCGv t1
= tcg_temp_new();
3248 tcg_gen_qemu_ld_tl(t0
, EA
, ctx
->mem_idx
, memop
);
3249 if ((memop
& MO_SIZE
) == MO_64
|| TARGET_LONG_BITS
== 32) {
3250 tcg_gen_mov_tl(t1
, src
);
3252 tcg_gen_ext32u_tl(t1
, src
);
3254 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t0
, t1
,
3255 cpu_gpr
[(rt
+ 2) & 31], t0
);
3256 tcg_gen_qemu_st_tl(t1
, EA
, ctx
->mem_idx
, memop
);
3257 tcg_gen_mov_tl(dst
, t0
);
3264 case 24: /* Fetch and increment bounded */
3265 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3268 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, 1);
3271 case 25: /* Fetch and increment equal */
3272 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3275 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_EQ
, 1);
3278 case 28: /* Fetch and decrement bounded */
3279 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3282 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, -1);
3287 /* invoke data storage error handler */
3288 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
3293 /* Restart with exclusive lock. */
3294 gen_helper_exit_atomic(cpu_env
);
3295 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3299 static void gen_lwat(DisasContext
*ctx
)
3301 gen_ld_atomic(ctx
, DEF_MEMOP(MO_UL
));
3305 static void gen_ldat(DisasContext
*ctx
)
3307 gen_ld_atomic(ctx
, DEF_MEMOP(MO_Q
));
3311 static void gen_st_atomic(DisasContext
*ctx
, MemOp memop
)
3313 uint32_t gpr_FC
= FC(ctx
->opcode
);
3314 TCGv EA
= tcg_temp_new();
3317 gen_addr_register(ctx
, EA
);
3318 src
= cpu_gpr
[rD(ctx
->opcode
)];
3319 discard
= tcg_temp_new();
3323 case 0: /* add and Store */
3324 tcg_gen_atomic_add_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3326 case 1: /* xor and Store */
3327 tcg_gen_atomic_xor_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3329 case 2: /* Or and Store */
3330 tcg_gen_atomic_or_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3332 case 3: /* 'and' and Store */
3333 tcg_gen_atomic_and_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3335 case 4: /* Store max unsigned */
3336 tcg_gen_atomic_umax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3338 case 5: /* Store max signed */
3339 tcg_gen_atomic_smax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3341 case 6: /* Store min unsigned */
3342 tcg_gen_atomic_umin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3344 case 7: /* Store min signed */
3345 tcg_gen_atomic_smin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3347 case 24: /* Store twin */
3348 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3349 /* Restart with exclusive lock. */
3350 gen_helper_exit_atomic(cpu_env
);
3351 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3353 TCGv t
= tcg_temp_new();
3354 TCGv t2
= tcg_temp_new();
3355 TCGv s
= tcg_temp_new();
3356 TCGv s2
= tcg_temp_new();
3357 TCGv ea_plus_s
= tcg_temp_new();
3359 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
3360 tcg_gen_addi_tl(ea_plus_s
, EA
, MEMOP_GET_SIZE(memop
));
3361 tcg_gen_qemu_ld_tl(t2
, ea_plus_s
, ctx
->mem_idx
, memop
);
3362 tcg_gen_movcond_tl(TCG_COND_EQ
, s
, t
, t2
, src
, t
);
3363 tcg_gen_movcond_tl(TCG_COND_EQ
, s2
, t
, t2
, src
, t2
);
3364 tcg_gen_qemu_st_tl(s
, EA
, ctx
->mem_idx
, memop
);
3365 tcg_gen_qemu_st_tl(s2
, ea_plus_s
, ctx
->mem_idx
, memop
);
3367 tcg_temp_free(ea_plus_s
);
3375 /* invoke data storage error handler */
3376 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
3378 tcg_temp_free(discard
);
3382 static void gen_stwat(DisasContext
*ctx
)
3384 gen_st_atomic(ctx
, DEF_MEMOP(MO_UL
));
3388 static void gen_stdat(DisasContext
*ctx
)
3390 gen_st_atomic(ctx
, DEF_MEMOP(MO_Q
));
3394 static void gen_conditional_store(DisasContext
*ctx
, MemOp memop
)
3396 TCGLabel
*l1
= gen_new_label();
3397 TCGLabel
*l2
= gen_new_label();
3398 TCGv t0
= tcg_temp_new();
3399 int reg
= rS(ctx
->opcode
);
3401 gen_set_access_type(ctx
, ACCESS_RES
);
3402 gen_addr_reg_index(ctx
, t0
);
3403 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3406 t0
= tcg_temp_new();
3407 tcg_gen_atomic_cmpxchg_tl(t0
, cpu_reserve
, cpu_reserve_val
,
3408 cpu_gpr
[reg
], ctx
->mem_idx
,
3409 DEF_MEMOP(memop
) | MO_ALIGN
);
3410 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, t0
, cpu_reserve_val
);
3411 tcg_gen_shli_tl(t0
, t0
, CRF_EQ_BIT
);
3412 tcg_gen_or_tl(t0
, t0
, cpu_so
);
3413 tcg_gen_trunc_tl_i32(cpu_crf
[0], t0
);
3420 * Address mismatch implies failure. But we still need to provide
3421 * the memory barrier semantics of the instruction.
3423 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
3424 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3427 tcg_gen_movi_tl(cpu_reserve
, -1);
3430 #define STCX(name, memop) \
3431 static void gen_##name(DisasContext *ctx) \
3433 gen_conditional_store(ctx, memop); \
3436 STCX(stbcx_
, DEF_MEMOP(MO_UB
))
3437 STCX(sthcx_
, DEF_MEMOP(MO_UW
))
3438 STCX(stwcx_
, DEF_MEMOP(MO_UL
))
3440 #if defined(TARGET_PPC64)
3442 LARX(ldarx
, DEF_MEMOP(MO_Q
))
3444 STCX(stdcx_
, DEF_MEMOP(MO_Q
))
3447 static void gen_lqarx(DisasContext
*ctx
)
3449 int rd
= rD(ctx
->opcode
);
3452 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
3453 (rd
== rB(ctx
->opcode
)))) {
3454 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3458 gen_set_access_type(ctx
, ACCESS_RES
);
3459 EA
= tcg_temp_new();
3460 gen_addr_reg_index(ctx
, EA
);
3462 /* Note that the low part is always in RD+1, even in LE mode. */
3463 lo
= cpu_gpr
[rd
+ 1];
3466 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3467 if (HAVE_ATOMIC128
) {
3468 TCGv_i32 oi
= tcg_temp_new_i32();
3470 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
| MO_ALIGN_16
,
3472 gen_helper_lq_le_parallel(lo
, cpu_env
, EA
, oi
);
3474 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
| MO_ALIGN_16
,
3476 gen_helper_lq_be_parallel(lo
, cpu_env
, EA
, oi
);
3478 tcg_temp_free_i32(oi
);
3479 tcg_gen_ld_i64(hi
, cpu_env
, offsetof(CPUPPCState
, retxh
));
3481 /* Restart with exclusive lock. */
3482 gen_helper_exit_atomic(cpu_env
);
3483 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3487 } else if (ctx
->le_mode
) {
3488 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
| MO_ALIGN_16
);
3489 tcg_gen_mov_tl(cpu_reserve
, EA
);
3490 gen_addr_add(ctx
, EA
, EA
, 8);
3491 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
3493 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
| MO_ALIGN_16
);
3494 tcg_gen_mov_tl(cpu_reserve
, EA
);
3495 gen_addr_add(ctx
, EA
, EA
, 8);
3496 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
3500 tcg_gen_st_tl(hi
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3501 tcg_gen_st_tl(lo
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
3505 static void gen_stqcx_(DisasContext
*ctx
)
3507 int rs
= rS(ctx
->opcode
);
3510 if (unlikely(rs
& 1)) {
3511 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3515 gen_set_access_type(ctx
, ACCESS_RES
);
3516 EA
= tcg_temp_new();
3517 gen_addr_reg_index(ctx
, EA
);
3519 /* Note that the low part is always in RS+1, even in LE mode. */
3520 lo
= cpu_gpr
[rs
+ 1];
3523 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3524 if (HAVE_CMPXCHG128
) {
3525 TCGv_i32 oi
= tcg_const_i32(DEF_MEMOP(MO_Q
) | MO_ALIGN_16
);
3527 gen_helper_stqcx_le_parallel(cpu_crf
[0], cpu_env
,
3530 gen_helper_stqcx_be_parallel(cpu_crf
[0], cpu_env
,
3533 tcg_temp_free_i32(oi
);
3535 /* Restart with exclusive lock. */
3536 gen_helper_exit_atomic(cpu_env
);
3537 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3541 TCGLabel
*lab_fail
= gen_new_label();
3542 TCGLabel
*lab_over
= gen_new_label();
3543 TCGv_i64 t0
= tcg_temp_new_i64();
3544 TCGv_i64 t1
= tcg_temp_new_i64();
3546 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, lab_fail
);
3549 gen_qemu_ld64_i64(ctx
, t0
, cpu_reserve
);
3550 tcg_gen_ld_i64(t1
, cpu_env
, (ctx
->le_mode
3551 ? offsetof(CPUPPCState
, reserve_val2
)
3552 : offsetof(CPUPPCState
, reserve_val
)));
3553 tcg_gen_brcond_i64(TCG_COND_NE
, t0
, t1
, lab_fail
);
3555 tcg_gen_addi_i64(t0
, cpu_reserve
, 8);
3556 gen_qemu_ld64_i64(ctx
, t0
, t0
);
3557 tcg_gen_ld_i64(t1
, cpu_env
, (ctx
->le_mode
3558 ? offsetof(CPUPPCState
, reserve_val
)
3559 : offsetof(CPUPPCState
, reserve_val2
)));
3560 tcg_gen_brcond_i64(TCG_COND_NE
, t0
, t1
, lab_fail
);
3563 gen_qemu_st64_i64(ctx
, ctx
->le_mode
? lo
: hi
, cpu_reserve
);
3564 tcg_gen_addi_i64(t0
, cpu_reserve
, 8);
3565 gen_qemu_st64_i64(ctx
, ctx
->le_mode
? hi
: lo
, t0
);
3567 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3568 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], CRF_EQ
);
3569 tcg_gen_br(lab_over
);
3571 gen_set_label(lab_fail
);
3572 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3574 gen_set_label(lab_over
);
3575 tcg_gen_movi_tl(cpu_reserve
, -1);
3576 tcg_temp_free_i64(t0
);
3577 tcg_temp_free_i64(t1
);
3580 #endif /* defined(TARGET_PPC64) */
3583 static void gen_sync(DisasContext
*ctx
)
3585 uint32_t l
= (ctx
->opcode
>> 21) & 3;
3588 * We may need to check for a pending TLB flush.
3590 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
3592 * Additionally, this can only happen in kernel mode however so
3593 * check MSR_PR as well.
3595 if (((l
== 2) || !(ctx
->insns_flags
& PPC_64B
)) && !ctx
->pr
) {
3596 gen_check_tlb_flush(ctx
, true);
3598 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
3602 static void gen_wait(DisasContext
*ctx
)
3604 TCGv_i32 t0
= tcg_const_i32(1);
3605 tcg_gen_st_i32(t0
, cpu_env
,
3606 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3607 tcg_temp_free_i32(t0
);
3608 /* Stop translation, as the CPU is supposed to sleep from now */
3609 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3612 #if defined(TARGET_PPC64)
3613 static void gen_doze(DisasContext
*ctx
)
3615 #if defined(CONFIG_USER_ONLY)
3621 t
= tcg_const_i32(PPC_PM_DOZE
);
3622 gen_helper_pminsn(cpu_env
, t
);
3623 tcg_temp_free_i32(t
);
3624 /* Stop translation, as the CPU is supposed to sleep from now */
3625 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3626 #endif /* defined(CONFIG_USER_ONLY) */
3629 static void gen_nap(DisasContext
*ctx
)
3631 #if defined(CONFIG_USER_ONLY)
3637 t
= tcg_const_i32(PPC_PM_NAP
);
3638 gen_helper_pminsn(cpu_env
, t
);
3639 tcg_temp_free_i32(t
);
3640 /* Stop translation, as the CPU is supposed to sleep from now */
3641 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3642 #endif /* defined(CONFIG_USER_ONLY) */
3645 static void gen_stop(DisasContext
*ctx
)
3647 #if defined(CONFIG_USER_ONLY)
3653 t
= tcg_const_i32(PPC_PM_STOP
);
3654 gen_helper_pminsn(cpu_env
, t
);
3655 tcg_temp_free_i32(t
);
3656 /* Stop translation, as the CPU is supposed to sleep from now */
3657 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3658 #endif /* defined(CONFIG_USER_ONLY) */
3661 static void gen_sleep(DisasContext
*ctx
)
3663 #if defined(CONFIG_USER_ONLY)
3669 t
= tcg_const_i32(PPC_PM_SLEEP
);
3670 gen_helper_pminsn(cpu_env
, t
);
3671 tcg_temp_free_i32(t
);
3672 /* Stop translation, as the CPU is supposed to sleep from now */
3673 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3674 #endif /* defined(CONFIG_USER_ONLY) */
3677 static void gen_rvwinkle(DisasContext
*ctx
)
3679 #if defined(CONFIG_USER_ONLY)
3685 t
= tcg_const_i32(PPC_PM_RVWINKLE
);
3686 gen_helper_pminsn(cpu_env
, t
);
3687 tcg_temp_free_i32(t
);
3688 /* Stop translation, as the CPU is supposed to sleep from now */
3689 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3690 #endif /* defined(CONFIG_USER_ONLY) */
3692 #endif /* #if defined(TARGET_PPC64) */
3694 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3696 #if defined(TARGET_PPC64)
3697 if (ctx
->has_cfar
) {
3698 tcg_gen_movi_tl(cpu_cfar
, nip
);
3703 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
3705 if (unlikely(ctx
->singlestep_enabled
)) {
3709 #ifndef CONFIG_USER_ONLY
3710 return (ctx
->base
.tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
3716 static void gen_lookup_and_goto_ptr(DisasContext
*ctx
)
3718 int sse
= ctx
->singlestep_enabled
;
3719 if (unlikely(sse
)) {
3720 if (sse
& GDBSTUB_SINGLE_STEP
) {
3721 gen_debug_exception(ctx
);
3722 } else if (sse
& (CPU_SINGLE_STEP
| CPU_BRANCH_STEP
)) {
3723 uint32_t excp
= gen_prep_dbgex(ctx
);
3724 gen_exception(ctx
, excp
);
3726 tcg_gen_exit_tb(NULL
, 0);
3728 tcg_gen_lookup_and_goto_ptr();
3733 static void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3735 if (NARROW_MODE(ctx
)) {
3736 dest
= (uint32_t) dest
;
3738 if (use_goto_tb(ctx
, dest
)) {
3740 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3741 tcg_gen_exit_tb(ctx
->base
.tb
, n
);
3743 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3744 gen_lookup_and_goto_ptr(ctx
);
3748 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3750 if (NARROW_MODE(ctx
)) {
3751 nip
= (uint32_t)nip
;
3753 tcg_gen_movi_tl(cpu_lr
, nip
);
3757 static void gen_b(DisasContext
*ctx
)
3759 target_ulong li
, target
;
3761 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3762 /* sign extend LI */
3763 li
= LI(ctx
->opcode
);
3764 li
= (li
^ 0x02000000) - 0x02000000;
3765 if (likely(AA(ctx
->opcode
) == 0)) {
3766 target
= ctx
->base
.pc_next
+ li
- 4;
3770 if (LK(ctx
->opcode
)) {
3771 gen_setlr(ctx
, ctx
->base
.pc_next
);
3773 gen_update_cfar(ctx
, ctx
->base
.pc_next
- 4);
3774 gen_goto_tb(ctx
, 0, target
);
3782 static void gen_bcond(DisasContext
*ctx
, int type
)
3784 uint32_t bo
= BO(ctx
->opcode
);
3787 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3789 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
3790 target
= tcg_temp_local_new();
3791 if (type
== BCOND_CTR
) {
3792 tcg_gen_mov_tl(target
, cpu_ctr
);
3793 } else if (type
== BCOND_TAR
) {
3794 gen_load_spr(target
, SPR_TAR
);
3796 tcg_gen_mov_tl(target
, cpu_lr
);
3801 if (LK(ctx
->opcode
)) {
3802 gen_setlr(ctx
, ctx
->base
.pc_next
);
3804 l1
= gen_new_label();
3805 if ((bo
& 0x4) == 0) {
3806 /* Decrement and test CTR */
3807 TCGv temp
= tcg_temp_new();
3809 if (type
== BCOND_CTR
) {
3811 * All ISAs up to v3 describe this form of bcctr as invalid but
3812 * some processors, ie. 64-bit server processors compliant with
3813 * arch 2.x, do implement a "test and decrement" logic instead,
3814 * as described in their respective UMs. This logic involves CTR
3815 * to act as both the branch target and a counter, which makes
3816 * it basically useless and thus never used in real code.
3818 * This form was hence chosen to trigger extra micro-architectural
3819 * side-effect on real HW needed for the Spectre v2 workaround.
3820 * It is up to guests that implement such workaround, ie. linux, to
3821 * use this form in a way it just triggers the side-effect without
3822 * doing anything else harmful.
3824 if (unlikely(!is_book3s_arch2x(ctx
))) {
3825 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3826 tcg_temp_free(temp
);
3827 tcg_temp_free(target
);
3831 if (NARROW_MODE(ctx
)) {
3832 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3834 tcg_gen_mov_tl(temp
, cpu_ctr
);
3837 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3839 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3841 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3843 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3844 if (NARROW_MODE(ctx
)) {
3845 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3847 tcg_gen_mov_tl(temp
, cpu_ctr
);
3850 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3852 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3855 tcg_temp_free(temp
);
3857 if ((bo
& 0x10) == 0) {
3859 uint32_t bi
= BI(ctx
->opcode
);
3860 uint32_t mask
= 0x08 >> (bi
& 0x03);
3861 TCGv_i32 temp
= tcg_temp_new_i32();
3864 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3865 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3867 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3868 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3870 tcg_temp_free_i32(temp
);
3872 gen_update_cfar(ctx
, ctx
->base
.pc_next
- 4);
3873 if (type
== BCOND_IM
) {
3874 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3875 if (likely(AA(ctx
->opcode
) == 0)) {
3876 gen_goto_tb(ctx
, 0, ctx
->base
.pc_next
+ li
- 4);
3878 gen_goto_tb(ctx
, 0, li
);
3881 if (NARROW_MODE(ctx
)) {
3882 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3884 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3886 gen_lookup_and_goto_ptr(ctx
);
3887 tcg_temp_free(target
);
3889 if ((bo
& 0x14) != 0x14) {
3890 /* fallthrough case */
3892 gen_goto_tb(ctx
, 1, ctx
->base
.pc_next
);
3896 static void gen_bc(DisasContext
*ctx
)
3898 gen_bcond(ctx
, BCOND_IM
);
3901 static void gen_bcctr(DisasContext
*ctx
)
3903 gen_bcond(ctx
, BCOND_CTR
);
3906 static void gen_bclr(DisasContext
*ctx
)
3908 gen_bcond(ctx
, BCOND_LR
);
3911 static void gen_bctar(DisasContext
*ctx
)
3913 gen_bcond(ctx
, BCOND_TAR
);
3916 /*** Condition register logical ***/
3917 #define GEN_CRLOGIC(name, tcg_op, opc) \
3918 static void glue(gen_, name)(DisasContext *ctx) \
3923 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3924 t0 = tcg_temp_new_i32(); \
3926 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3928 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3930 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3931 t1 = tcg_temp_new_i32(); \
3932 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3934 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3936 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3938 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3939 tcg_op(t0, t0, t1); \
3940 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
3941 tcg_gen_andi_i32(t0, t0, bitmask); \
3942 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3943 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3944 tcg_temp_free_i32(t0); \
3945 tcg_temp_free_i32(t1); \
3949 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3951 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3953 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3955 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3957 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3959 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3961 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3963 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3966 static void gen_mcrf(DisasContext
*ctx
)
3968 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3971 /*** System linkage ***/
3973 /* rfi (supervisor only) */
3974 static void gen_rfi(DisasContext
*ctx
)
3976 #if defined(CONFIG_USER_ONLY)
3980 * This instruction doesn't exist anymore on 64-bit server
3981 * processors compliant with arch 2.x
3983 if (is_book3s_arch2x(ctx
)) {
3984 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3987 /* Restore CPU state */
3989 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
3992 gen_update_cfar(ctx
, ctx
->base
.pc_next
- 4);
3993 gen_helper_rfi(cpu_env
);
3994 gen_sync_exception(ctx
);
3998 #if defined(TARGET_PPC64)
3999 static void gen_rfid(DisasContext
*ctx
)
4001 #if defined(CONFIG_USER_ONLY)
4004 /* Restore CPU state */
4006 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
4009 gen_update_cfar(ctx
, ctx
->base
.pc_next
- 4);
4010 gen_helper_rfid(cpu_env
);
4011 gen_sync_exception(ctx
);
4015 static void gen_hrfid(DisasContext
*ctx
)
4017 #if defined(CONFIG_USER_ONLY)
4020 /* Restore CPU state */
4022 gen_helper_hrfid(cpu_env
);
4023 gen_sync_exception(ctx
);
4029 #if defined(CONFIG_USER_ONLY)
4030 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4032 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4034 static void gen_sc(DisasContext
*ctx
)
4038 lev
= (ctx
->opcode
>> 5) & 0x7F;
4039 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
4044 /* Check for unconditional traps (always or never) */
4045 static bool check_unconditional_trap(DisasContext
*ctx
)
4048 if (TO(ctx
->opcode
) == 0) {
4052 if (TO(ctx
->opcode
) == 31) {
4053 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
4060 static void gen_tw(DisasContext
*ctx
)
4064 if (check_unconditional_trap(ctx
)) {
4067 t0
= tcg_const_i32(TO(ctx
->opcode
));
4068 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4070 tcg_temp_free_i32(t0
);
4074 static void gen_twi(DisasContext
*ctx
)
4079 if (check_unconditional_trap(ctx
)) {
4082 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4083 t1
= tcg_const_i32(TO(ctx
->opcode
));
4084 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4086 tcg_temp_free_i32(t1
);
4089 #if defined(TARGET_PPC64)
4091 static void gen_td(DisasContext
*ctx
)
4095 if (check_unconditional_trap(ctx
)) {
4098 t0
= tcg_const_i32(TO(ctx
->opcode
));
4099 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4101 tcg_temp_free_i32(t0
);
4105 static void gen_tdi(DisasContext
*ctx
)
4110 if (check_unconditional_trap(ctx
)) {
4113 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4114 t1
= tcg_const_i32(TO(ctx
->opcode
));
4115 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4117 tcg_temp_free_i32(t1
);
4121 /*** Processor control ***/
4123 static void gen_read_xer(DisasContext
*ctx
, TCGv dst
)
4125 TCGv t0
= tcg_temp_new();
4126 TCGv t1
= tcg_temp_new();
4127 TCGv t2
= tcg_temp_new();
4128 tcg_gen_mov_tl(dst
, cpu_xer
);
4129 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
4130 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
4131 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
4132 tcg_gen_or_tl(t0
, t0
, t1
);
4133 tcg_gen_or_tl(dst
, dst
, t2
);
4134 tcg_gen_or_tl(dst
, dst
, t0
);
4135 if (is_isa300(ctx
)) {
4136 tcg_gen_shli_tl(t0
, cpu_ov32
, XER_OV32
);
4137 tcg_gen_or_tl(dst
, dst
, t0
);
4138 tcg_gen_shli_tl(t0
, cpu_ca32
, XER_CA32
);
4139 tcg_gen_or_tl(dst
, dst
, t0
);
4146 static void gen_write_xer(TCGv src
)
4148 /* Write all flags, while reading back check for isa300 */
4149 tcg_gen_andi_tl(cpu_xer
, src
,
4151 (1u << XER_OV
) | (1u << XER_OV32
) |
4152 (1u << XER_CA
) | (1u << XER_CA32
)));
4153 tcg_gen_extract_tl(cpu_ov32
, src
, XER_OV32
, 1);
4154 tcg_gen_extract_tl(cpu_ca32
, src
, XER_CA32
, 1);
4155 tcg_gen_extract_tl(cpu_so
, src
, XER_SO
, 1);
4156 tcg_gen_extract_tl(cpu_ov
, src
, XER_OV
, 1);
4157 tcg_gen_extract_tl(cpu_ca
, src
, XER_CA
, 1);
4161 static void gen_mcrxr(DisasContext
*ctx
)
4163 TCGv_i32 t0
= tcg_temp_new_i32();
4164 TCGv_i32 t1
= tcg_temp_new_i32();
4165 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4167 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4168 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4169 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4170 tcg_gen_shli_i32(t0
, t0
, 3);
4171 tcg_gen_shli_i32(t1
, t1
, 2);
4172 tcg_gen_shli_i32(dst
, dst
, 1);
4173 tcg_gen_or_i32(dst
, dst
, t0
);
4174 tcg_gen_or_i32(dst
, dst
, t1
);
4175 tcg_temp_free_i32(t0
);
4176 tcg_temp_free_i32(t1
);
4178 tcg_gen_movi_tl(cpu_so
, 0);
4179 tcg_gen_movi_tl(cpu_ov
, 0);
4180 tcg_gen_movi_tl(cpu_ca
, 0);
4185 static void gen_mcrxrx(DisasContext
*ctx
)
4187 TCGv t0
= tcg_temp_new();
4188 TCGv t1
= tcg_temp_new();
4189 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4191 /* copy OV and OV32 */
4192 tcg_gen_shli_tl(t0
, cpu_ov
, 1);
4193 tcg_gen_or_tl(t0
, t0
, cpu_ov32
);
4194 tcg_gen_shli_tl(t0
, t0
, 2);
4195 /* copy CA and CA32 */
4196 tcg_gen_shli_tl(t1
, cpu_ca
, 1);
4197 tcg_gen_or_tl(t1
, t1
, cpu_ca32
);
4198 tcg_gen_or_tl(t0
, t0
, t1
);
4199 tcg_gen_trunc_tl_i32(dst
, t0
);
4206 static void gen_mfcr(DisasContext
*ctx
)
4210 if (likely(ctx
->opcode
& 0x00100000)) {
4211 crm
= CRM(ctx
->opcode
);
4212 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4214 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4215 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4216 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4219 TCGv_i32 t0
= tcg_temp_new_i32();
4220 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4221 tcg_gen_shli_i32(t0
, t0
, 4);
4222 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4223 tcg_gen_shli_i32(t0
, t0
, 4);
4224 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4225 tcg_gen_shli_i32(t0
, t0
, 4);
4226 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4227 tcg_gen_shli_i32(t0
, t0
, 4);
4228 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4229 tcg_gen_shli_i32(t0
, t0
, 4);
4230 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4231 tcg_gen_shli_i32(t0
, t0
, 4);
4232 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4233 tcg_gen_shli_i32(t0
, t0
, 4);
4234 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4235 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4236 tcg_temp_free_i32(t0
);
4241 static void gen_mfmsr(DisasContext
*ctx
)
4244 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4247 static void spr_noaccess(DisasContext
*ctx
, int gprn
, int sprn
)
4250 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
4251 printf("ERROR: try to access SPR %d !\n", sprn
);
4254 #define SPR_NOACCESS (&spr_noaccess)
4257 static inline void gen_op_mfspr(DisasContext
*ctx
)
4259 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
4260 uint32_t sprn
= SPR(ctx
->opcode
);
4262 #if defined(CONFIG_USER_ONLY)
4263 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4266 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4267 } else if (ctx
->hv
) {
4268 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4270 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4273 if (likely(read_cb
!= NULL
)) {
4274 if (likely(read_cb
!= SPR_NOACCESS
)) {
4275 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4277 /* Privilege exception */
4279 * This is a hack to avoid warnings when running Linux:
4280 * this OS breaks the PowerPC virtualisation model,
4281 * allowing userland application to read the PVR
4283 if (sprn
!= SPR_PVR
) {
4284 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to read privileged spr "
4285 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
4286 ctx
->base
.pc_next
- 4);
4288 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4291 /* ISA 2.07 defines these as no-ops */
4292 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4293 (sprn
>= 808 && sprn
<= 811)) {
4298 qemu_log_mask(LOG_GUEST_ERROR
,
4299 "Trying to read invalid spr %d (0x%03x) at "
4300 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
4303 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
4304 * generate a priv, a hv emu or a no-op
4308 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4311 if (ctx
->pr
|| sprn
== 0 || sprn
== 4 || sprn
== 5 || sprn
== 6) {
4312 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4318 static void gen_mfspr(DisasContext
*ctx
)
4324 static void gen_mftb(DisasContext
*ctx
)
4330 static void gen_mtcrf(DisasContext
*ctx
)
4334 crm
= CRM(ctx
->opcode
);
4335 if (likely((ctx
->opcode
& 0x00100000))) {
4336 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4337 TCGv_i32 temp
= tcg_temp_new_i32();
4339 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4340 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4341 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4342 tcg_temp_free_i32(temp
);
4345 TCGv_i32 temp
= tcg_temp_new_i32();
4346 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4347 for (crn
= 0 ; crn
< 8 ; crn
++) {
4348 if (crm
& (1 << crn
)) {
4349 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4350 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4353 tcg_temp_free_i32(temp
);
4358 #if defined(TARGET_PPC64)
4359 static void gen_mtmsrd(DisasContext
*ctx
)
4363 #if !defined(CONFIG_USER_ONLY)
4364 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
4367 if (ctx
->opcode
& 0x00010000) {
4368 /* L=1 form only updates EE and RI */
4369 TCGv t0
= tcg_temp_new();
4370 TCGv t1
= tcg_temp_new();
4371 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)],
4372 (1 << MSR_RI
) | (1 << MSR_EE
));
4373 tcg_gen_andi_tl(t1
, cpu_msr
,
4374 ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
4375 tcg_gen_or_tl(t1
, t1
, t0
);
4377 gen_helper_store_msr(cpu_env
, t1
);
4383 * XXX: we need to update nip before the store if we enter
4384 * power saving mode, we will exit the loop directly from
4387 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4388 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4390 /* Must stop the translation as machine state (may have) changed */
4391 gen_stop_exception(ctx
);
4392 #endif /* !defined(CONFIG_USER_ONLY) */
4394 #endif /* defined(TARGET_PPC64) */
4396 static void gen_mtmsr(DisasContext
*ctx
)
4400 #if !defined(CONFIG_USER_ONLY)
4401 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
4404 if (ctx
->opcode
& 0x00010000) {
4405 /* L=1 form only updates EE and RI */
4406 TCGv t0
= tcg_temp_new();
4407 TCGv t1
= tcg_temp_new();
4408 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)],
4409 (1 << MSR_RI
) | (1 << MSR_EE
));
4410 tcg_gen_andi_tl(t1
, cpu_msr
,
4411 ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
4412 tcg_gen_or_tl(t1
, t1
, t0
);
4414 gen_helper_store_msr(cpu_env
, t1
);
4419 TCGv msr
= tcg_temp_new();
4422 * XXX: we need to update nip before the store if we enter
4423 * power saving mode, we will exit the loop directly from
4426 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4427 #if defined(TARGET_PPC64)
4428 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4430 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4432 gen_helper_store_msr(cpu_env
, msr
);
4435 /* Must stop the translation as machine state (may have) changed */
4436 gen_stop_exception(ctx
);
4441 static void gen_mtspr(DisasContext
*ctx
)
4443 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
4444 uint32_t sprn
= SPR(ctx
->opcode
);
4446 #if defined(CONFIG_USER_ONLY)
4447 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4450 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4451 } else if (ctx
->hv
) {
4452 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4454 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4457 if (likely(write_cb
!= NULL
)) {
4458 if (likely(write_cb
!= SPR_NOACCESS
)) {
4459 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4461 /* Privilege exception */
4462 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to write privileged spr "
4463 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
4464 ctx
->base
.pc_next
- 4);
4465 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4468 /* ISA 2.07 defines these as no-ops */
4469 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4470 (sprn
>= 808 && sprn
<= 811)) {
4476 qemu_log_mask(LOG_GUEST_ERROR
,
4477 "Trying to write invalid spr %d (0x%03x) at "
4478 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
4482 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
4483 * generate a priv, a hv emu or a no-op
4487 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4490 if (ctx
->pr
|| sprn
== 0) {
4491 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4497 #if defined(TARGET_PPC64)
4499 static void gen_setb(DisasContext
*ctx
)
4501 TCGv_i32 t0
= tcg_temp_new_i32();
4502 TCGv_i32 t8
= tcg_temp_new_i32();
4503 TCGv_i32 tm1
= tcg_temp_new_i32();
4504 int crf
= crfS(ctx
->opcode
);
4506 tcg_gen_setcondi_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], 4);
4507 tcg_gen_movi_i32(t8
, 8);
4508 tcg_gen_movi_i32(tm1
, -1);
4509 tcg_gen_movcond_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], t8
, tm1
, t0
);
4510 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4512 tcg_temp_free_i32(t0
);
4513 tcg_temp_free_i32(t8
);
4514 tcg_temp_free_i32(tm1
);
4518 /*** Cache management ***/
4521 static void gen_dcbf(DisasContext
*ctx
)
4523 /* XXX: specification says this is treated as a load by the MMU */
4525 gen_set_access_type(ctx
, ACCESS_CACHE
);
4526 t0
= tcg_temp_new();
4527 gen_addr_reg_index(ctx
, t0
);
4528 gen_qemu_ld8u(ctx
, t0
, t0
);
4532 /* dcbfep (external PID dcbf) */
4533 static void gen_dcbfep(DisasContext
*ctx
)
4535 /* XXX: specification says this is treated as a load by the MMU */
4538 gen_set_access_type(ctx
, ACCESS_CACHE
);
4539 t0
= tcg_temp_new();
4540 gen_addr_reg_index(ctx
, t0
);
4541 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
4545 /* dcbi (Supervisor only) */
4546 static void gen_dcbi(DisasContext
*ctx
)
4548 #if defined(CONFIG_USER_ONLY)
4554 EA
= tcg_temp_new();
4555 gen_set_access_type(ctx
, ACCESS_CACHE
);
4556 gen_addr_reg_index(ctx
, EA
);
4557 val
= tcg_temp_new();
4558 /* XXX: specification says this should be treated as a store by the MMU */
4559 gen_qemu_ld8u(ctx
, val
, EA
);
4560 gen_qemu_st8(ctx
, val
, EA
);
4563 #endif /* defined(CONFIG_USER_ONLY) */
4567 static void gen_dcbst(DisasContext
*ctx
)
4569 /* XXX: specification say this is treated as a load by the MMU */
4571 gen_set_access_type(ctx
, ACCESS_CACHE
);
4572 t0
= tcg_temp_new();
4573 gen_addr_reg_index(ctx
, t0
);
4574 gen_qemu_ld8u(ctx
, t0
, t0
);
4578 /* dcbstep (dcbstep External PID version) */
4579 static void gen_dcbstep(DisasContext
*ctx
)
4581 /* XXX: specification say this is treated as a load by the MMU */
4583 gen_set_access_type(ctx
, ACCESS_CACHE
);
4584 t0
= tcg_temp_new();
4585 gen_addr_reg_index(ctx
, t0
);
4586 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
4591 static void gen_dcbt(DisasContext
*ctx
)
4594 * interpreted as no-op
4595 * XXX: specification say this is treated as a load by the MMU but
4596 * does not generate any exception
4601 static void gen_dcbtep(DisasContext
*ctx
)
4604 * interpreted as no-op
4605 * XXX: specification say this is treated as a load by the MMU but
4606 * does not generate any exception
4611 static void gen_dcbtst(DisasContext
*ctx
)
4614 * interpreted as no-op
4615 * XXX: specification say this is treated as a load by the MMU but
4616 * does not generate any exception
4621 static void gen_dcbtstep(DisasContext
*ctx
)
4624 * interpreted as no-op
4625 * XXX: specification say this is treated as a load by the MMU but
4626 * does not generate any exception
4631 static void gen_dcbtls(DisasContext
*ctx
)
4633 /* Always fails locking the cache */
4634 TCGv t0
= tcg_temp_new();
4635 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
4636 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
4637 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
4642 static void gen_dcbz(DisasContext
*ctx
)
4647 gen_set_access_type(ctx
, ACCESS_CACHE
);
4648 tcgv_addr
= tcg_temp_new();
4649 tcgv_op
= tcg_const_i32(ctx
->opcode
& 0x03FF000);
4650 gen_addr_reg_index(ctx
, tcgv_addr
);
4651 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_op
);
4652 tcg_temp_free(tcgv_addr
);
4653 tcg_temp_free_i32(tcgv_op
);
4657 static void gen_dcbzep(DisasContext
*ctx
)
4662 gen_set_access_type(ctx
, ACCESS_CACHE
);
4663 tcgv_addr
= tcg_temp_new();
4664 tcgv_op
= tcg_const_i32(ctx
->opcode
& 0x03FF000);
4665 gen_addr_reg_index(ctx
, tcgv_addr
);
4666 gen_helper_dcbzep(cpu_env
, tcgv_addr
, tcgv_op
);
4667 tcg_temp_free(tcgv_addr
);
4668 tcg_temp_free_i32(tcgv_op
);
4672 static void gen_dst(DisasContext
*ctx
)
4674 if (rA(ctx
->opcode
) == 0) {
4675 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4677 /* interpreted as no-op */
4682 static void gen_dstst(DisasContext
*ctx
)
4684 if (rA(ctx
->opcode
) == 0) {
4685 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4687 /* interpreted as no-op */
4693 static void gen_dss(DisasContext
*ctx
)
4695 /* interpreted as no-op */
4699 static void gen_icbi(DisasContext
*ctx
)
4702 gen_set_access_type(ctx
, ACCESS_CACHE
);
4703 t0
= tcg_temp_new();
4704 gen_addr_reg_index(ctx
, t0
);
4705 gen_helper_icbi(cpu_env
, t0
);
4710 static void gen_icbiep(DisasContext
*ctx
)
4713 gen_set_access_type(ctx
, ACCESS_CACHE
);
4714 t0
= tcg_temp_new();
4715 gen_addr_reg_index(ctx
, t0
);
4716 gen_helper_icbiep(cpu_env
, t0
);
4722 static void gen_dcba(DisasContext
*ctx
)
4725 * interpreted as no-op
4726 * XXX: specification say this is treated as a store by the MMU
4727 * but does not generate any exception
4731 /*** Segment register manipulation ***/
4732 /* Supervisor only: */
4735 static void gen_mfsr(DisasContext
*ctx
)
4737 #if defined(CONFIG_USER_ONLY)
4743 t0
= tcg_const_tl(SR(ctx
->opcode
));
4744 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4746 #endif /* defined(CONFIG_USER_ONLY) */
4750 static void gen_mfsrin(DisasContext
*ctx
)
4752 #if defined(CONFIG_USER_ONLY)
4758 t0
= tcg_temp_new();
4759 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
4760 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4762 #endif /* defined(CONFIG_USER_ONLY) */
4766 static void gen_mtsr(DisasContext
*ctx
)
4768 #if defined(CONFIG_USER_ONLY)
4774 t0
= tcg_const_tl(SR(ctx
->opcode
));
4775 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4777 #endif /* defined(CONFIG_USER_ONLY) */
4781 static void gen_mtsrin(DisasContext
*ctx
)
4783 #if defined(CONFIG_USER_ONLY)
4789 t0
= tcg_temp_new();
4790 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
4791 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4793 #endif /* defined(CONFIG_USER_ONLY) */
4796 #if defined(TARGET_PPC64)
4797 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4800 static void gen_mfsr_64b(DisasContext
*ctx
)
4802 #if defined(CONFIG_USER_ONLY)
4808 t0
= tcg_const_tl(SR(ctx
->opcode
));
4809 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4811 #endif /* defined(CONFIG_USER_ONLY) */
4815 static void gen_mfsrin_64b(DisasContext
*ctx
)
4817 #if defined(CONFIG_USER_ONLY)
4823 t0
= tcg_temp_new();
4824 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
4825 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4827 #endif /* defined(CONFIG_USER_ONLY) */
4831 static void gen_mtsr_64b(DisasContext
*ctx
)
4833 #if defined(CONFIG_USER_ONLY)
4839 t0
= tcg_const_tl(SR(ctx
->opcode
));
4840 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4842 #endif /* defined(CONFIG_USER_ONLY) */
4846 static void gen_mtsrin_64b(DisasContext
*ctx
)
4848 #if defined(CONFIG_USER_ONLY)
4854 t0
= tcg_temp_new();
4855 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
4856 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4858 #endif /* defined(CONFIG_USER_ONLY) */
4862 static void gen_slbmte(DisasContext
*ctx
)
4864 #if defined(CONFIG_USER_ONLY)
4869 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4870 cpu_gpr
[rS(ctx
->opcode
)]);
4871 #endif /* defined(CONFIG_USER_ONLY) */
4874 static void gen_slbmfee(DisasContext
*ctx
)
4876 #if defined(CONFIG_USER_ONLY)
4881 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4882 cpu_gpr
[rB(ctx
->opcode
)]);
4883 #endif /* defined(CONFIG_USER_ONLY) */
4886 static void gen_slbmfev(DisasContext
*ctx
)
4888 #if defined(CONFIG_USER_ONLY)
4893 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4894 cpu_gpr
[rB(ctx
->opcode
)]);
4895 #endif /* defined(CONFIG_USER_ONLY) */
4898 static void gen_slbfee_(DisasContext
*ctx
)
4900 #if defined(CONFIG_USER_ONLY)
4901 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4905 if (unlikely(ctx
->pr
)) {
4906 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4909 gen_helper_find_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4910 cpu_gpr
[rB(ctx
->opcode
)]);
4911 l1
= gen_new_label();
4912 l2
= gen_new_label();
4913 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4914 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rS(ctx
->opcode
)], -1, l1
);
4915 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], CRF_EQ
);
4918 tcg_gen_movi_tl(cpu_gpr
[rS(ctx
->opcode
)], 0);
4922 #endif /* defined(TARGET_PPC64) */
4924 /*** Lookaside buffer management ***/
4925 /* Optional & supervisor only: */
4928 static void gen_tlbia(DisasContext
*ctx
)
4930 #if defined(CONFIG_USER_ONLY)
4935 gen_helper_tlbia(cpu_env
);
4936 #endif /* defined(CONFIG_USER_ONLY) */
4940 static void gen_tlbiel(DisasContext
*ctx
)
4942 #if defined(CONFIG_USER_ONLY)
4947 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4948 #endif /* defined(CONFIG_USER_ONLY) */
4952 static void gen_tlbie(DisasContext
*ctx
)
4954 #if defined(CONFIG_USER_ONLY)
4960 CHK_SV
; /* If gtse is set then tlbie is supervisor privileged */
4962 CHK_HV
; /* Else hypervisor privileged */
4965 if (NARROW_MODE(ctx
)) {
4966 TCGv t0
= tcg_temp_new();
4967 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4968 gen_helper_tlbie(cpu_env
, t0
);
4971 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4973 t1
= tcg_temp_new_i32();
4974 tcg_gen_ld_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
4975 tcg_gen_ori_i32(t1
, t1
, TLB_NEED_GLOBAL_FLUSH
);
4976 tcg_gen_st_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
4977 tcg_temp_free_i32(t1
);
4978 #endif /* defined(CONFIG_USER_ONLY) */
4982 static void gen_tlbsync(DisasContext
*ctx
)
4984 #if defined(CONFIG_USER_ONLY)
4989 CHK_SV
; /* If gtse is set then tlbsync is supervisor privileged */
4991 CHK_HV
; /* Else hypervisor privileged */
4994 /* BookS does both ptesync and tlbsync make tlbsync a nop for server */
4995 if (ctx
->insns_flags
& PPC_BOOKE
) {
4996 gen_check_tlb_flush(ctx
, true);
4998 #endif /* defined(CONFIG_USER_ONLY) */
5001 #if defined(TARGET_PPC64)
5003 static void gen_slbia(DisasContext
*ctx
)
5005 #if defined(CONFIG_USER_ONLY)
5008 uint32_t ih
= (ctx
->opcode
>> 21) & 0x7;
5009 TCGv_i32 t0
= tcg_const_i32(ih
);
5013 gen_helper_slbia(cpu_env
, t0
);
5014 tcg_temp_free_i32(t0
);
5015 #endif /* defined(CONFIG_USER_ONLY) */
5019 static void gen_slbie(DisasContext
*ctx
)
5021 #if defined(CONFIG_USER_ONLY)
5026 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5027 #endif /* defined(CONFIG_USER_ONLY) */
5031 static void gen_slbieg(DisasContext
*ctx
)
5033 #if defined(CONFIG_USER_ONLY)
5038 gen_helper_slbieg(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5039 #endif /* defined(CONFIG_USER_ONLY) */
5043 static void gen_slbsync(DisasContext
*ctx
)
5045 #if defined(CONFIG_USER_ONLY)
5049 gen_check_tlb_flush(ctx
, true);
5050 #endif /* defined(CONFIG_USER_ONLY) */
5053 #endif /* defined(TARGET_PPC64) */
5055 /*** External control ***/
5059 static void gen_eciwx(DisasContext
*ctx
)
5062 /* Should check EAR[E] ! */
5063 gen_set_access_type(ctx
, ACCESS_EXT
);
5064 t0
= tcg_temp_new();
5065 gen_addr_reg_index(ctx
, t0
);
5066 tcg_gen_qemu_ld_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5067 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5072 static void gen_ecowx(DisasContext
*ctx
)
5075 /* Should check EAR[E] ! */
5076 gen_set_access_type(ctx
, ACCESS_EXT
);
5077 t0
= tcg_temp_new();
5078 gen_addr_reg_index(ctx
, t0
);
5079 tcg_gen_qemu_st_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5080 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5084 /* PowerPC 601 specific instructions */
5087 static void gen_abs(DisasContext
*ctx
)
5089 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5090 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5092 tcg_gen_abs_tl(d
, a
);
5093 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5094 gen_set_Rc0(ctx
, d
);
5099 static void gen_abso(DisasContext
*ctx
)
5101 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5102 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5104 tcg_gen_setcondi_tl(TCG_COND_EQ
, cpu_ov
, a
, 0x80000000);
5105 tcg_gen_abs_tl(d
, a
);
5106 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
5107 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5108 gen_set_Rc0(ctx
, d
);
5113 static void gen_clcs(DisasContext
*ctx
)
5115 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
5116 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5117 tcg_temp_free_i32(t0
);
5118 /* Rc=1 sets CR0 to an undefined state */
5122 static void gen_div(DisasContext
*ctx
)
5124 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5125 cpu_gpr
[rB(ctx
->opcode
)]);
5126 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5127 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5132 static void gen_divo(DisasContext
*ctx
)
5134 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5135 cpu_gpr
[rB(ctx
->opcode
)]);
5136 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5137 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5142 static void gen_divs(DisasContext
*ctx
)
5144 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5145 cpu_gpr
[rB(ctx
->opcode
)]);
5146 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5147 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5151 /* divso - divso. */
5152 static void gen_divso(DisasContext
*ctx
)
5154 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5155 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5156 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5157 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5162 static void gen_doz(DisasContext
*ctx
)
5164 TCGLabel
*l1
= gen_new_label();
5165 TCGLabel
*l2
= gen_new_label();
5166 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)],
5167 cpu_gpr
[rA(ctx
->opcode
)], l1
);
5168 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
5169 cpu_gpr
[rA(ctx
->opcode
)]);
5172 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5174 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5175 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5180 static void gen_dozo(DisasContext
*ctx
)
5182 TCGLabel
*l1
= gen_new_label();
5183 TCGLabel
*l2
= gen_new_label();
5184 TCGv t0
= tcg_temp_new();
5185 TCGv t1
= tcg_temp_new();
5186 TCGv t2
= tcg_temp_new();
5187 /* Start with XER OV disabled, the most likely case */
5188 tcg_gen_movi_tl(cpu_ov
, 0);
5189 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)],
5190 cpu_gpr
[rA(ctx
->opcode
)], l1
);
5191 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5192 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5193 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
5194 tcg_gen_andc_tl(t1
, t1
, t2
);
5195 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5196 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5197 tcg_gen_movi_tl(cpu_ov
, 1);
5198 tcg_gen_movi_tl(cpu_so
, 1);
5201 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5206 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5207 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5212 static void gen_dozi(DisasContext
*ctx
)
5214 target_long simm
= SIMM(ctx
->opcode
);
5215 TCGLabel
*l1
= gen_new_label();
5216 TCGLabel
*l2
= gen_new_label();
5217 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
5218 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
5221 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5223 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5224 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5228 /* lscbx - lscbx. */
5229 static void gen_lscbx(DisasContext
*ctx
)
5231 TCGv t0
= tcg_temp_new();
5232 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
5233 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
5234 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
5236 gen_addr_reg_index(ctx
, t0
);
5237 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
5238 tcg_temp_free_i32(t1
);
5239 tcg_temp_free_i32(t2
);
5240 tcg_temp_free_i32(t3
);
5241 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
5242 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
5243 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5244 gen_set_Rc0(ctx
, t0
);
5249 /* maskg - maskg. */
5250 static void gen_maskg(DisasContext
*ctx
)
5252 TCGLabel
*l1
= gen_new_label();
5253 TCGv t0
= tcg_temp_new();
5254 TCGv t1
= tcg_temp_new();
5255 TCGv t2
= tcg_temp_new();
5256 TCGv t3
= tcg_temp_new();
5257 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
5258 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5259 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
5260 tcg_gen_addi_tl(t2
, t0
, 1);
5261 tcg_gen_shr_tl(t2
, t3
, t2
);
5262 tcg_gen_shr_tl(t3
, t3
, t1
);
5263 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
5264 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
5265 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5271 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5272 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5276 /* maskir - maskir. */
5277 static void gen_maskir(DisasContext
*ctx
)
5279 TCGv t0
= tcg_temp_new();
5280 TCGv t1
= tcg_temp_new();
5281 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5282 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5283 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5286 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5287 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5292 static void gen_mul(DisasContext
*ctx
)
5294 TCGv_i64 t0
= tcg_temp_new_i64();
5295 TCGv_i64 t1
= tcg_temp_new_i64();
5296 TCGv t2
= tcg_temp_new();
5297 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5298 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5299 tcg_gen_mul_i64(t0
, t0
, t1
);
5300 tcg_gen_trunc_i64_tl(t2
, t0
);
5301 gen_store_spr(SPR_MQ
, t2
);
5302 tcg_gen_shri_i64(t1
, t0
, 32);
5303 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5304 tcg_temp_free_i64(t0
);
5305 tcg_temp_free_i64(t1
);
5307 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5308 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5313 static void gen_mulo(DisasContext
*ctx
)
5315 TCGLabel
*l1
= gen_new_label();
5316 TCGv_i64 t0
= tcg_temp_new_i64();
5317 TCGv_i64 t1
= tcg_temp_new_i64();
5318 TCGv t2
= tcg_temp_new();
5319 /* Start with XER OV disabled, the most likely case */
5320 tcg_gen_movi_tl(cpu_ov
, 0);
5321 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5322 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5323 tcg_gen_mul_i64(t0
, t0
, t1
);
5324 tcg_gen_trunc_i64_tl(t2
, t0
);
5325 gen_store_spr(SPR_MQ
, t2
);
5326 tcg_gen_shri_i64(t1
, t0
, 32);
5327 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5328 tcg_gen_ext32s_i64(t1
, t0
);
5329 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
5330 tcg_gen_movi_tl(cpu_ov
, 1);
5331 tcg_gen_movi_tl(cpu_so
, 1);
5333 tcg_temp_free_i64(t0
);
5334 tcg_temp_free_i64(t1
);
5336 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5337 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5342 static void gen_nabs(DisasContext
*ctx
)
5344 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5345 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5347 tcg_gen_abs_tl(d
, a
);
5348 tcg_gen_neg_tl(d
, d
);
5349 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5350 gen_set_Rc0(ctx
, d
);
5354 /* nabso - nabso. */
5355 static void gen_nabso(DisasContext
*ctx
)
5357 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5358 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5360 tcg_gen_abs_tl(d
, a
);
5361 tcg_gen_neg_tl(d
, d
);
5362 /* nabs never overflows */
5363 tcg_gen_movi_tl(cpu_ov
, 0);
5364 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5365 gen_set_Rc0(ctx
, d
);
5370 static void gen_rlmi(DisasContext
*ctx
)
5372 uint32_t mb
= MB(ctx
->opcode
);
5373 uint32_t me
= ME(ctx
->opcode
);
5374 TCGv t0
= tcg_temp_new();
5375 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5376 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5377 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
5378 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
5380 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
5382 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5383 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5388 static void gen_rrib(DisasContext
*ctx
)
5390 TCGv t0
= tcg_temp_new();
5391 TCGv t1
= tcg_temp_new();
5392 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5393 tcg_gen_movi_tl(t1
, 0x80000000);
5394 tcg_gen_shr_tl(t1
, t1
, t0
);
5395 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5396 tcg_gen_and_tl(t0
, t0
, t1
);
5397 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
5398 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5401 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5402 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5407 static void gen_sle(DisasContext
*ctx
)
5409 TCGv t0
= tcg_temp_new();
5410 TCGv t1
= tcg_temp_new();
5411 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5412 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5413 tcg_gen_subfi_tl(t1
, 32, t1
);
5414 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5415 tcg_gen_or_tl(t1
, t0
, t1
);
5416 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5417 gen_store_spr(SPR_MQ
, t1
);
5420 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5421 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5426 static void gen_sleq(DisasContext
*ctx
)
5428 TCGv t0
= tcg_temp_new();
5429 TCGv t1
= tcg_temp_new();
5430 TCGv t2
= tcg_temp_new();
5431 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5432 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
5433 tcg_gen_shl_tl(t2
, t2
, t0
);
5434 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5435 gen_load_spr(t1
, SPR_MQ
);
5436 gen_store_spr(SPR_MQ
, t0
);
5437 tcg_gen_and_tl(t0
, t0
, t2
);
5438 tcg_gen_andc_tl(t1
, t1
, t2
);
5439 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5443 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5444 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5449 static void gen_sliq(DisasContext
*ctx
)
5451 int sh
= SH(ctx
->opcode
);
5452 TCGv t0
= tcg_temp_new();
5453 TCGv t1
= tcg_temp_new();
5454 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5455 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5456 tcg_gen_or_tl(t1
, t0
, t1
);
5457 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5458 gen_store_spr(SPR_MQ
, t1
);
5461 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5462 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5466 /* slliq - slliq. */
5467 static void gen_slliq(DisasContext
*ctx
)
5469 int sh
= SH(ctx
->opcode
);
5470 TCGv t0
= tcg_temp_new();
5471 TCGv t1
= tcg_temp_new();
5472 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5473 gen_load_spr(t1
, SPR_MQ
);
5474 gen_store_spr(SPR_MQ
, t0
);
5475 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5476 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5477 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5480 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5481 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5486 static void gen_sllq(DisasContext
*ctx
)
5488 TCGLabel
*l1
= gen_new_label();
5489 TCGLabel
*l2
= gen_new_label();
5490 TCGv t0
= tcg_temp_local_new();
5491 TCGv t1
= tcg_temp_local_new();
5492 TCGv t2
= tcg_temp_local_new();
5493 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5494 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5495 tcg_gen_shl_tl(t1
, t1
, t2
);
5496 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5497 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5498 gen_load_spr(t0
, SPR_MQ
);
5499 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5502 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5503 gen_load_spr(t2
, SPR_MQ
);
5504 tcg_gen_andc_tl(t1
, t2
, t1
);
5505 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5510 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5511 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5516 static void gen_slq(DisasContext
*ctx
)
5518 TCGLabel
*l1
= gen_new_label();
5519 TCGv t0
= tcg_temp_new();
5520 TCGv t1
= tcg_temp_new();
5521 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5522 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5523 tcg_gen_subfi_tl(t1
, 32, t1
);
5524 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5525 tcg_gen_or_tl(t1
, t0
, t1
);
5526 gen_store_spr(SPR_MQ
, t1
);
5527 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5528 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5529 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5530 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5534 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5535 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5539 /* sraiq - sraiq. */
5540 static void gen_sraiq(DisasContext
*ctx
)
5542 int sh
= SH(ctx
->opcode
);
5543 TCGLabel
*l1
= gen_new_label();
5544 TCGv t0
= tcg_temp_new();
5545 TCGv t1
= tcg_temp_new();
5546 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5547 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5548 tcg_gen_or_tl(t0
, t0
, t1
);
5549 gen_store_spr(SPR_MQ
, t0
);
5550 tcg_gen_movi_tl(cpu_ca
, 0);
5551 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5552 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5553 tcg_gen_movi_tl(cpu_ca
, 1);
5555 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5558 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5559 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5564 static void gen_sraq(DisasContext
*ctx
)
5566 TCGLabel
*l1
= gen_new_label();
5567 TCGLabel
*l2
= gen_new_label();
5568 TCGv t0
= tcg_temp_new();
5569 TCGv t1
= tcg_temp_local_new();
5570 TCGv t2
= tcg_temp_local_new();
5571 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5572 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5573 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5574 tcg_gen_subfi_tl(t2
, 32, t2
);
5575 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5576 tcg_gen_or_tl(t0
, t0
, t2
);
5577 gen_store_spr(SPR_MQ
, t0
);
5578 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5579 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5580 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5581 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5584 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5585 tcg_gen_movi_tl(cpu_ca
, 0);
5586 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5587 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5588 tcg_gen_movi_tl(cpu_ca
, 1);
5592 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5593 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5598 static void gen_sre(DisasContext
*ctx
)
5600 TCGv t0
= tcg_temp_new();
5601 TCGv t1
= tcg_temp_new();
5602 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5603 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5604 tcg_gen_subfi_tl(t1
, 32, t1
);
5605 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5606 tcg_gen_or_tl(t1
, t0
, t1
);
5607 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5608 gen_store_spr(SPR_MQ
, t1
);
5611 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5612 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5617 static void gen_srea(DisasContext
*ctx
)
5619 TCGv t0
= tcg_temp_new();
5620 TCGv t1
= tcg_temp_new();
5621 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5622 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5623 gen_store_spr(SPR_MQ
, t0
);
5624 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5627 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5628 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5633 static void gen_sreq(DisasContext
*ctx
)
5635 TCGv t0
= tcg_temp_new();
5636 TCGv t1
= tcg_temp_new();
5637 TCGv t2
= tcg_temp_new();
5638 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5639 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5640 tcg_gen_shr_tl(t1
, t1
, t0
);
5641 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5642 gen_load_spr(t2
, SPR_MQ
);
5643 gen_store_spr(SPR_MQ
, t0
);
5644 tcg_gen_and_tl(t0
, t0
, t1
);
5645 tcg_gen_andc_tl(t2
, t2
, t1
);
5646 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5650 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5651 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5656 static void gen_sriq(DisasContext
*ctx
)
5658 int sh
= SH(ctx
->opcode
);
5659 TCGv t0
= tcg_temp_new();
5660 TCGv t1
= tcg_temp_new();
5661 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5662 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5663 tcg_gen_or_tl(t1
, t0
, t1
);
5664 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5665 gen_store_spr(SPR_MQ
, t1
);
5668 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5669 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5674 static void gen_srliq(DisasContext
*ctx
)
5676 int sh
= SH(ctx
->opcode
);
5677 TCGv t0
= tcg_temp_new();
5678 TCGv t1
= tcg_temp_new();
5679 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5680 gen_load_spr(t1
, SPR_MQ
);
5681 gen_store_spr(SPR_MQ
, t0
);
5682 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5683 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5684 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5687 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5688 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5693 static void gen_srlq(DisasContext
*ctx
)
5695 TCGLabel
*l1
= gen_new_label();
5696 TCGLabel
*l2
= gen_new_label();
5697 TCGv t0
= tcg_temp_local_new();
5698 TCGv t1
= tcg_temp_local_new();
5699 TCGv t2
= tcg_temp_local_new();
5700 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5701 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5702 tcg_gen_shr_tl(t2
, t1
, t2
);
5703 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5704 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5705 gen_load_spr(t0
, SPR_MQ
);
5706 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5709 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5710 tcg_gen_and_tl(t0
, t0
, t2
);
5711 gen_load_spr(t1
, SPR_MQ
);
5712 tcg_gen_andc_tl(t1
, t1
, t2
);
5713 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5718 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5719 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5724 static void gen_srq(DisasContext
*ctx
)
5726 TCGLabel
*l1
= gen_new_label();
5727 TCGv t0
= tcg_temp_new();
5728 TCGv t1
= tcg_temp_new();
5729 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5730 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5731 tcg_gen_subfi_tl(t1
, 32, t1
);
5732 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5733 tcg_gen_or_tl(t1
, t0
, t1
);
5734 gen_store_spr(SPR_MQ
, t1
);
5735 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5736 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5737 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5738 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5742 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5743 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5747 /* PowerPC 602 specific instructions */
5750 static void gen_dsa(DisasContext
*ctx
)
5753 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5757 static void gen_esa(DisasContext
*ctx
)
5760 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5764 static void gen_mfrom(DisasContext
*ctx
)
5766 #if defined(CONFIG_USER_ONLY)
5770 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5771 #endif /* defined(CONFIG_USER_ONLY) */
5774 /* 602 - 603 - G2 TLB management */
5777 static void gen_tlbld_6xx(DisasContext
*ctx
)
5779 #if defined(CONFIG_USER_ONLY)
5783 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5784 #endif /* defined(CONFIG_USER_ONLY) */
5788 static void gen_tlbli_6xx(DisasContext
*ctx
)
5790 #if defined(CONFIG_USER_ONLY)
5794 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5795 #endif /* defined(CONFIG_USER_ONLY) */
5798 /* 74xx TLB management */
5801 static void gen_tlbld_74xx(DisasContext
*ctx
)
5803 #if defined(CONFIG_USER_ONLY)
5807 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5808 #endif /* defined(CONFIG_USER_ONLY) */
5812 static void gen_tlbli_74xx(DisasContext
*ctx
)
5814 #if defined(CONFIG_USER_ONLY)
5818 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5819 #endif /* defined(CONFIG_USER_ONLY) */
5822 /* POWER instructions not in PowerPC 601 */
5825 static void gen_clf(DisasContext
*ctx
)
5827 /* Cache line flush: implemented as no-op */
5831 static void gen_cli(DisasContext
*ctx
)
5833 #if defined(CONFIG_USER_ONLY)
5836 /* Cache line invalidate: privileged and treated as no-op */
5838 #endif /* defined(CONFIG_USER_ONLY) */
5842 static void gen_dclst(DisasContext
*ctx
)
5844 /* Data cache line store: treated as no-op */
5847 static void gen_mfsri(DisasContext
*ctx
)
5849 #if defined(CONFIG_USER_ONLY)
5852 int ra
= rA(ctx
->opcode
);
5853 int rd
= rD(ctx
->opcode
);
5857 t0
= tcg_temp_new();
5858 gen_addr_reg_index(ctx
, t0
);
5859 tcg_gen_extract_tl(t0
, t0
, 28, 4);
5860 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5862 if (ra
!= 0 && ra
!= rd
) {
5863 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5865 #endif /* defined(CONFIG_USER_ONLY) */
5868 static void gen_rac(DisasContext
*ctx
)
5870 #if defined(CONFIG_USER_ONLY)
5876 t0
= tcg_temp_new();
5877 gen_addr_reg_index(ctx
, t0
);
5878 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5880 #endif /* defined(CONFIG_USER_ONLY) */
5883 static void gen_rfsvc(DisasContext
*ctx
)
5885 #if defined(CONFIG_USER_ONLY)
5890 gen_helper_rfsvc(cpu_env
);
5891 gen_sync_exception(ctx
);
5892 #endif /* defined(CONFIG_USER_ONLY) */
5895 /* svc is not implemented for now */
5897 /* BookE specific instructions */
5899 /* XXX: not implemented on 440 ? */
5900 static void gen_mfapidi(DisasContext
*ctx
)
5903 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5906 /* XXX: not implemented on 440 ? */
5907 static void gen_tlbiva(DisasContext
*ctx
)
5909 #if defined(CONFIG_USER_ONLY)
5915 t0
= tcg_temp_new();
5916 gen_addr_reg_index(ctx
, t0
);
5917 gen_helper_tlbiva(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5919 #endif /* defined(CONFIG_USER_ONLY) */
5922 /* All 405 MAC instructions are translated here */
5923 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5924 int ra
, int rb
, int rt
, int Rc
)
5928 t0
= tcg_temp_local_new();
5929 t1
= tcg_temp_local_new();
5931 switch (opc3
& 0x0D) {
5933 /* macchw - macchw. - macchwo - macchwo. */
5934 /* macchws - macchws. - macchwso - macchwso. */
5935 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5936 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5937 /* mulchw - mulchw. */
5938 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5939 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5940 tcg_gen_ext16s_tl(t1
, t1
);
5943 /* macchwu - macchwu. - macchwuo - macchwuo. */
5944 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5945 /* mulchwu - mulchwu. */
5946 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5947 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5948 tcg_gen_ext16u_tl(t1
, t1
);
5951 /* machhw - machhw. - machhwo - machhwo. */
5952 /* machhws - machhws. - machhwso - machhwso. */
5953 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5954 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5955 /* mulhhw - mulhhw. */
5956 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5957 tcg_gen_ext16s_tl(t0
, t0
);
5958 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5959 tcg_gen_ext16s_tl(t1
, t1
);
5962 /* machhwu - machhwu. - machhwuo - machhwuo. */
5963 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5964 /* mulhhwu - mulhhwu. */
5965 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5966 tcg_gen_ext16u_tl(t0
, t0
);
5967 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5968 tcg_gen_ext16u_tl(t1
, t1
);
5971 /* maclhw - maclhw. - maclhwo - maclhwo. */
5972 /* maclhws - maclhws. - maclhwso - maclhwso. */
5973 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5974 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5975 /* mullhw - mullhw. */
5976 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5977 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5980 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5981 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5982 /* mullhwu - mullhwu. */
5983 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5984 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5988 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5989 tcg_gen_mul_tl(t1
, t0
, t1
);
5991 /* nmultiply-and-accumulate (0x0E) */
5992 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5994 /* multiply-and-accumulate (0x0C) */
5995 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5999 /* Check overflow and/or saturate */
6000 TCGLabel
*l1
= gen_new_label();
6003 /* Start with XER OV disabled, the most likely case */
6004 tcg_gen_movi_tl(cpu_ov
, 0);
6008 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
6009 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
6010 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
6011 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
6014 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
6015 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
6019 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
6022 tcg_gen_movi_tl(t0
, UINT32_MAX
);
6026 /* Check overflow */
6027 tcg_gen_movi_tl(cpu_ov
, 1);
6028 tcg_gen_movi_tl(cpu_so
, 1);
6031 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
6034 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
6038 if (unlikely(Rc
) != 0) {
6040 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
6044 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6045 static void glue(gen_, name)(DisasContext *ctx) \
6047 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6048 rD(ctx->opcode), Rc(ctx->opcode)); \
6051 /* macchw - macchw. */
6052 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
6053 /* macchwo - macchwo. */
6054 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
6055 /* macchws - macchws. */
6056 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
6057 /* macchwso - macchwso. */
6058 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
6059 /* macchwsu - macchwsu. */
6060 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
6061 /* macchwsuo - macchwsuo. */
6062 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
6063 /* macchwu - macchwu. */
6064 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
6065 /* macchwuo - macchwuo. */
6066 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
6067 /* machhw - machhw. */
6068 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
6069 /* machhwo - machhwo. */
6070 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
6071 /* machhws - machhws. */
6072 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
6073 /* machhwso - machhwso. */
6074 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
6075 /* machhwsu - machhwsu. */
6076 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
6077 /* machhwsuo - machhwsuo. */
6078 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
6079 /* machhwu - machhwu. */
6080 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
6081 /* machhwuo - machhwuo. */
6082 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
6083 /* maclhw - maclhw. */
6084 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
6085 /* maclhwo - maclhwo. */
6086 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
6087 /* maclhws - maclhws. */
6088 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
6089 /* maclhwso - maclhwso. */
6090 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
6091 /* maclhwu - maclhwu. */
6092 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
6093 /* maclhwuo - maclhwuo. */
6094 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
6095 /* maclhwsu - maclhwsu. */
6096 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
6097 /* maclhwsuo - maclhwsuo. */
6098 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
6099 /* nmacchw - nmacchw. */
6100 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
6101 /* nmacchwo - nmacchwo. */
6102 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
6103 /* nmacchws - nmacchws. */
6104 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
6105 /* nmacchwso - nmacchwso. */
6106 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
6107 /* nmachhw - nmachhw. */
6108 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
6109 /* nmachhwo - nmachhwo. */
6110 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
6111 /* nmachhws - nmachhws. */
6112 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
6113 /* nmachhwso - nmachhwso. */
6114 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
6115 /* nmaclhw - nmaclhw. */
6116 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
6117 /* nmaclhwo - nmaclhwo. */
6118 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
6119 /* nmaclhws - nmaclhws. */
6120 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
6121 /* nmaclhwso - nmaclhwso. */
6122 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
6124 /* mulchw - mulchw. */
6125 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
6126 /* mulchwu - mulchwu. */
6127 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
6128 /* mulhhw - mulhhw. */
6129 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
6130 /* mulhhwu - mulhhwu. */
6131 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
6132 /* mullhw - mullhw. */
6133 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
6134 /* mullhwu - mullhwu. */
6135 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
6138 static void gen_mfdcr(DisasContext
*ctx
)
6140 #if defined(CONFIG_USER_ONLY)
6146 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6147 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
6148 tcg_temp_free(dcrn
);
6149 #endif /* defined(CONFIG_USER_ONLY) */
6153 static void gen_mtdcr(DisasContext
*ctx
)
6155 #if defined(CONFIG_USER_ONLY)
6161 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6162 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
6163 tcg_temp_free(dcrn
);
6164 #endif /* defined(CONFIG_USER_ONLY) */
6168 /* XXX: not implemented on 440 ? */
6169 static void gen_mfdcrx(DisasContext
*ctx
)
6171 #if defined(CONFIG_USER_ONLY)
6175 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6176 cpu_gpr
[rA(ctx
->opcode
)]);
6177 /* Note: Rc update flag set leads to undefined state of Rc0 */
6178 #endif /* defined(CONFIG_USER_ONLY) */
6182 /* XXX: not implemented on 440 ? */
6183 static void gen_mtdcrx(DisasContext
*ctx
)
6185 #if defined(CONFIG_USER_ONLY)
6189 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6190 cpu_gpr
[rS(ctx
->opcode
)]);
6191 /* Note: Rc update flag set leads to undefined state of Rc0 */
6192 #endif /* defined(CONFIG_USER_ONLY) */
6195 /* mfdcrux (PPC 460) : user-mode access to DCR */
6196 static void gen_mfdcrux(DisasContext
*ctx
)
6198 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6199 cpu_gpr
[rA(ctx
->opcode
)]);
6200 /* Note: Rc update flag set leads to undefined state of Rc0 */
6203 /* mtdcrux (PPC 460) : user-mode access to DCR */
6204 static void gen_mtdcrux(DisasContext
*ctx
)
6206 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6207 cpu_gpr
[rS(ctx
->opcode
)]);
6208 /* Note: Rc update flag set leads to undefined state of Rc0 */
6212 static void gen_dccci(DisasContext
*ctx
)
6215 /* interpreted as no-op */
6219 static void gen_dcread(DisasContext
*ctx
)
6221 #if defined(CONFIG_USER_ONLY)
6227 gen_set_access_type(ctx
, ACCESS_CACHE
);
6228 EA
= tcg_temp_new();
6229 gen_addr_reg_index(ctx
, EA
);
6230 val
= tcg_temp_new();
6231 gen_qemu_ld32u(ctx
, val
, EA
);
6233 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
6235 #endif /* defined(CONFIG_USER_ONLY) */
6239 static void gen_icbt_40x(DisasContext
*ctx
)
6242 * interpreted as no-op
6243 * XXX: specification say this is treated as a load by the MMU but
6244 * does not generate any exception
6249 static void gen_iccci(DisasContext
*ctx
)
6252 /* interpreted as no-op */
6256 static void gen_icread(DisasContext
*ctx
)
6259 /* interpreted as no-op */
6262 /* rfci (supervisor only) */
6263 static void gen_rfci_40x(DisasContext
*ctx
)
6265 #if defined(CONFIG_USER_ONLY)
6269 /* Restore CPU state */
6270 gen_helper_40x_rfci(cpu_env
);
6271 gen_sync_exception(ctx
);
6272 #endif /* defined(CONFIG_USER_ONLY) */
6275 static void gen_rfci(DisasContext
*ctx
)
6277 #if defined(CONFIG_USER_ONLY)
6281 /* Restore CPU state */
6282 gen_helper_rfci(cpu_env
);
6283 gen_sync_exception(ctx
);
6284 #endif /* defined(CONFIG_USER_ONLY) */
6287 /* BookE specific */
6289 /* XXX: not implemented on 440 ? */
6290 static void gen_rfdi(DisasContext
*ctx
)
6292 #if defined(CONFIG_USER_ONLY)
6296 /* Restore CPU state */
6297 gen_helper_rfdi(cpu_env
);
6298 gen_sync_exception(ctx
);
6299 #endif /* defined(CONFIG_USER_ONLY) */
6302 /* XXX: not implemented on 440 ? */
6303 static void gen_rfmci(DisasContext
*ctx
)
6305 #if defined(CONFIG_USER_ONLY)
6309 /* Restore CPU state */
6310 gen_helper_rfmci(cpu_env
);
6311 gen_sync_exception(ctx
);
6312 #endif /* defined(CONFIG_USER_ONLY) */
6315 /* TLB management - PowerPC 405 implementation */
6318 static void gen_tlbre_40x(DisasContext
*ctx
)
6320 #if defined(CONFIG_USER_ONLY)
6324 switch (rB(ctx
->opcode
)) {
6326 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6327 cpu_gpr
[rA(ctx
->opcode
)]);
6330 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6331 cpu_gpr
[rA(ctx
->opcode
)]);
6334 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6337 #endif /* defined(CONFIG_USER_ONLY) */
6340 /* tlbsx - tlbsx. */
6341 static void gen_tlbsx_40x(DisasContext
*ctx
)
6343 #if defined(CONFIG_USER_ONLY)
6349 t0
= tcg_temp_new();
6350 gen_addr_reg_index(ctx
, t0
);
6351 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6353 if (Rc(ctx
->opcode
)) {
6354 TCGLabel
*l1
= gen_new_label();
6355 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6356 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6357 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6360 #endif /* defined(CONFIG_USER_ONLY) */
6364 static void gen_tlbwe_40x(DisasContext
*ctx
)
6366 #if defined(CONFIG_USER_ONLY)
6371 switch (rB(ctx
->opcode
)) {
6373 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6374 cpu_gpr
[rS(ctx
->opcode
)]);
6377 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6378 cpu_gpr
[rS(ctx
->opcode
)]);
6381 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6384 #endif /* defined(CONFIG_USER_ONLY) */
6387 /* TLB management - PowerPC 440 implementation */
6390 static void gen_tlbre_440(DisasContext
*ctx
)
6392 #if defined(CONFIG_USER_ONLY)
6397 switch (rB(ctx
->opcode
)) {
6402 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6403 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6404 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6405 tcg_temp_free_i32(t0
);
6409 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6412 #endif /* defined(CONFIG_USER_ONLY) */
6415 /* tlbsx - tlbsx. */
6416 static void gen_tlbsx_440(DisasContext
*ctx
)
6418 #if defined(CONFIG_USER_ONLY)
6424 t0
= tcg_temp_new();
6425 gen_addr_reg_index(ctx
, t0
);
6426 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6428 if (Rc(ctx
->opcode
)) {
6429 TCGLabel
*l1
= gen_new_label();
6430 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6431 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6432 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6435 #endif /* defined(CONFIG_USER_ONLY) */
6439 static void gen_tlbwe_440(DisasContext
*ctx
)
6441 #if defined(CONFIG_USER_ONLY)
6445 switch (rB(ctx
->opcode
)) {
6450 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6451 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6452 cpu_gpr
[rS(ctx
->opcode
)]);
6453 tcg_temp_free_i32(t0
);
6457 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6460 #endif /* defined(CONFIG_USER_ONLY) */
6463 /* TLB management - PowerPC BookE 2.06 implementation */
6466 static void gen_tlbre_booke206(DisasContext
*ctx
)
6468 #if defined(CONFIG_USER_ONLY)
6472 gen_helper_booke206_tlbre(cpu_env
);
6473 #endif /* defined(CONFIG_USER_ONLY) */
6476 /* tlbsx - tlbsx. */
6477 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6479 #if defined(CONFIG_USER_ONLY)
6485 if (rA(ctx
->opcode
)) {
6486 t0
= tcg_temp_new();
6487 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6489 t0
= tcg_const_tl(0);
6492 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6493 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6495 #endif /* defined(CONFIG_USER_ONLY) */
6499 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6501 #if defined(CONFIG_USER_ONLY)
6505 gen_helper_booke206_tlbwe(cpu_env
);
6506 #endif /* defined(CONFIG_USER_ONLY) */
6509 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6511 #if defined(CONFIG_USER_ONLY)
6517 t0
= tcg_temp_new();
6518 gen_addr_reg_index(ctx
, t0
);
6519 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6521 #endif /* defined(CONFIG_USER_ONLY) */
6524 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6526 #if defined(CONFIG_USER_ONLY)
6532 t0
= tcg_temp_new();
6533 gen_addr_reg_index(ctx
, t0
);
6535 switch ((ctx
->opcode
>> 21) & 0x3) {
6537 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6540 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6543 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6546 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6551 #endif /* defined(CONFIG_USER_ONLY) */
6556 static void gen_wrtee(DisasContext
*ctx
)
6558 #if defined(CONFIG_USER_ONLY)
6564 t0
= tcg_temp_new();
6565 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6566 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6567 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6570 * Stop translation to have a chance to raise an exception if we
6571 * just set msr_ee to 1
6573 gen_stop_exception(ctx
);
6574 #endif /* defined(CONFIG_USER_ONLY) */
6578 static void gen_wrteei(DisasContext
*ctx
)
6580 #if defined(CONFIG_USER_ONLY)
6584 if (ctx
->opcode
& 0x00008000) {
6585 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6586 /* Stop translation to have a chance to raise an exception */
6587 gen_stop_exception(ctx
);
6589 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6591 #endif /* defined(CONFIG_USER_ONLY) */
6594 /* PowerPC 440 specific instructions */
6597 static void gen_dlmzb(DisasContext
*ctx
)
6599 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6600 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6601 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6602 tcg_temp_free_i32(t0
);
6605 /* mbar replaces eieio on 440 */
6606 static void gen_mbar(DisasContext
*ctx
)
6608 /* interpreted as no-op */
6611 /* msync replaces sync on 440 */
6612 static void gen_msync_4xx(DisasContext
*ctx
)
6614 /* Only e500 seems to treat reserved bits as invalid */
6615 if ((ctx
->insns_flags2
& PPC2_BOOKE206
) &&
6616 (ctx
->opcode
& 0x03FFF801)) {
6617 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6619 /* otherwise interpreted as no-op */
6623 static void gen_icbt_440(DisasContext
*ctx
)
6626 * interpreted as no-op
6627 * XXX: specification say this is treated as a load by the MMU but
6628 * does not generate any exception
6632 /* Embedded.Processor Control */
6634 static void gen_msgclr(DisasContext
*ctx
)
6636 #if defined(CONFIG_USER_ONLY)
6640 if (is_book3s_arch2x(ctx
)) {
6641 gen_helper_book3s_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6643 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6645 #endif /* defined(CONFIG_USER_ONLY) */
6648 static void gen_msgsnd(DisasContext
*ctx
)
6650 #if defined(CONFIG_USER_ONLY)
6654 if (is_book3s_arch2x(ctx
)) {
6655 gen_helper_book3s_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6657 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6659 #endif /* defined(CONFIG_USER_ONLY) */
6662 #if defined(TARGET_PPC64)
6663 static void gen_msgclrp(DisasContext
*ctx
)
6665 #if defined(CONFIG_USER_ONLY)
6669 gen_helper_book3s_msgclrp(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6670 #endif /* defined(CONFIG_USER_ONLY) */
6673 static void gen_msgsndp(DisasContext
*ctx
)
6675 #if defined(CONFIG_USER_ONLY)
6679 gen_helper_book3s_msgsndp(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6680 #endif /* defined(CONFIG_USER_ONLY) */
6684 static void gen_msgsync(DisasContext
*ctx
)
6686 #if defined(CONFIG_USER_ONLY)
6690 #endif /* defined(CONFIG_USER_ONLY) */
6691 /* interpreted as no-op */
6694 #if defined(TARGET_PPC64)
6695 static void gen_maddld(DisasContext
*ctx
)
6697 TCGv_i64 t1
= tcg_temp_new_i64();
6699 tcg_gen_mul_i64(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6700 tcg_gen_add_i64(cpu_gpr
[rD(ctx
->opcode
)], t1
, cpu_gpr
[rC(ctx
->opcode
)]);
6701 tcg_temp_free_i64(t1
);
6704 /* maddhd maddhdu */
6705 static void gen_maddhd_maddhdu(DisasContext
*ctx
)
6707 TCGv_i64 lo
= tcg_temp_new_i64();
6708 TCGv_i64 hi
= tcg_temp_new_i64();
6709 TCGv_i64 t1
= tcg_temp_new_i64();
6711 if (Rc(ctx
->opcode
)) {
6712 tcg_gen_mulu2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
6713 cpu_gpr
[rB(ctx
->opcode
)]);
6714 tcg_gen_movi_i64(t1
, 0);
6716 tcg_gen_muls2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
6717 cpu_gpr
[rB(ctx
->opcode
)]);
6718 tcg_gen_sari_i64(t1
, cpu_gpr
[rC(ctx
->opcode
)], 63);
6720 tcg_gen_add2_i64(t1
, cpu_gpr
[rD(ctx
->opcode
)], lo
, hi
,
6721 cpu_gpr
[rC(ctx
->opcode
)], t1
);
6722 tcg_temp_free_i64(lo
);
6723 tcg_temp_free_i64(hi
);
6724 tcg_temp_free_i64(t1
);
6726 #endif /* defined(TARGET_PPC64) */
6728 static void gen_tbegin(DisasContext
*ctx
)
6730 if (unlikely(!ctx
->tm_enabled
)) {
6731 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6734 gen_helper_tbegin(cpu_env
);
6737 #define GEN_TM_NOOP(name) \
6738 static inline void gen_##name(DisasContext *ctx) \
6740 if (unlikely(!ctx->tm_enabled)) { \
6741 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6745 * Because tbegin always fails in QEMU, these user \
6746 * space instructions all have a simple implementation: \
6748 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6749 * = 0b0 || 0b00 || 0b0 \
6751 tcg_gen_movi_i32(cpu_crf[0], 0); \
6755 GEN_TM_NOOP(tabort
);
6756 GEN_TM_NOOP(tabortwc
);
6757 GEN_TM_NOOP(tabortwci
);
6758 GEN_TM_NOOP(tabortdc
);
6759 GEN_TM_NOOP(tabortdci
);
6762 static inline void gen_cp_abort(DisasContext
*ctx
)
6767 #define GEN_CP_PASTE_NOOP(name) \
6768 static inline void gen_##name(DisasContext *ctx) \
6771 * Generate invalid exception until we have an \
6772 * implementation of the copy paste facility \
6777 GEN_CP_PASTE_NOOP(copy
)
6778 GEN_CP_PASTE_NOOP(paste
)
6780 static void gen_tcheck(DisasContext
*ctx
)
6782 if (unlikely(!ctx
->tm_enabled
)) {
6783 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6787 * Because tbegin always fails, the tcheck implementation is
6790 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
6791 * = 0b1 || 0b00 || 0b0
6793 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
6796 #if defined(CONFIG_USER_ONLY)
6797 #define GEN_TM_PRIV_NOOP(name) \
6798 static inline void gen_##name(DisasContext *ctx) \
6800 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
6805 #define GEN_TM_PRIV_NOOP(name) \
6806 static inline void gen_##name(DisasContext *ctx) \
6809 if (unlikely(!ctx->tm_enabled)) { \
6810 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6814 * Because tbegin always fails, the implementation is \
6817 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6818 * = 0b0 || 0b00 | 0b0 \
6820 tcg_gen_movi_i32(cpu_crf[0], 0); \
6825 GEN_TM_PRIV_NOOP(treclaim
);
6826 GEN_TM_PRIV_NOOP(trechkpt
);
6828 static inline void get_fpr(TCGv_i64 dst
, int regno
)
6830 tcg_gen_ld_i64(dst
, cpu_env
, fpr_offset(regno
));
6833 static inline void set_fpr(int regno
, TCGv_i64 src
)
6835 tcg_gen_st_i64(src
, cpu_env
, fpr_offset(regno
));
6838 static inline void get_avr64(TCGv_i64 dst
, int regno
, bool high
)
6840 tcg_gen_ld_i64(dst
, cpu_env
, avr64_offset(regno
, high
));
6843 static inline void set_avr64(int regno
, TCGv_i64 src
, bool high
)
6845 tcg_gen_st_i64(src
, cpu_env
, avr64_offset(regno
, high
));
6848 #include "translate/fp-impl.inc.c"
6850 #include "translate/vmx-impl.inc.c"
6852 #include "translate/vsx-impl.inc.c"
6854 #include "translate/dfp-impl.inc.c"
6856 #include "translate/spe-impl.inc.c"
6858 /* Handles lfdp, lxsd, lxssp */
6859 static void gen_dform39(DisasContext
*ctx
)
6861 switch (ctx
->opcode
& 0x3) {
6863 if (ctx
->insns_flags2
& PPC2_ISA205
) {
6864 return gen_lfdp(ctx
);
6868 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6869 return gen_lxsd(ctx
);
6873 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6874 return gen_lxssp(ctx
);
6878 return gen_invalid(ctx
);
6881 /* handles stfdp, lxv, stxsd, stxssp lxvx */
6882 static void gen_dform3D(DisasContext
*ctx
)
6884 if ((ctx
->opcode
& 3) == 1) { /* DQ-FORM */
6885 switch (ctx
->opcode
& 0x7) {
6887 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6888 return gen_lxv(ctx
);
6892 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6893 return gen_stxv(ctx
);
6897 } else { /* DS-FORM */
6898 switch (ctx
->opcode
& 0x3) {
6900 if (ctx
->insns_flags2
& PPC2_ISA205
) {
6901 return gen_stfdp(ctx
);
6905 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6906 return gen_stxsd(ctx
);
6909 case 3: /* stxssp */
6910 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6911 return gen_stxssp(ctx
);
6916 return gen_invalid(ctx
);
6919 static opcode_t opcodes
[] = {
6920 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
6921 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
6922 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
6923 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400001, PPC_INTEGER
),
6924 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
6925 #if defined(TARGET_PPC64)
6926 GEN_HANDLER_E(cmpeqb
, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE
, PPC2_ISA300
),
6928 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
6929 GEN_HANDLER_E(cmprb
, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE
, PPC2_ISA300
),
6930 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
6931 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6932 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6933 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6934 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6935 GEN_HANDLER_E(addpcis
, 0x13, 0x2, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6936 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
6937 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
6938 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
6939 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
6940 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6941 #if defined(TARGET_PPC64)
6942 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
6944 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
6945 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
6946 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6947 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6948 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6949 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
6950 GEN_HANDLER_E(cnttzw
, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6951 GEN_HANDLER_E(copy
, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE
, PPC2_ISA300
),
6952 GEN_HANDLER_E(cp_abort
, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
6953 GEN_HANDLER_E(paste
, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE
, PPC2_ISA300
),
6954 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
6955 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
6956 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6957 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6958 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6959 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6960 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
6961 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
6962 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6963 #if defined(TARGET_PPC64)
6964 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
6965 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
6966 GEN_HANDLER_E(cnttzd
, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6967 GEN_HANDLER_E(darn
, 0x1F, 0x13, 0x17, 0x001CF801, PPC_NONE
, PPC2_ISA300
),
6968 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6969 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
6971 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6972 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6973 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6974 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
6975 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
6976 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
6977 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
6978 #if defined(TARGET_PPC64)
6979 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
6980 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
6981 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
6982 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
6983 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
6984 GEN_HANDLER2_E(extswsli0
, "extswsli", 0x1F, 0x1A, 0x1B, 0x00000000,
6985 PPC_NONE
, PPC2_ISA300
),
6986 GEN_HANDLER2_E(extswsli1
, "extswsli", 0x1F, 0x1B, 0x1B, 0x00000000,
6987 PPC_NONE
, PPC2_ISA300
),
6989 #if defined(TARGET_PPC64)
6990 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6991 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
6992 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6994 /* handles lfdp, lxsd, lxssp */
6995 GEN_HANDLER_E(dform39
, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
6996 /* handles stfdp, lxv, stxsd, stxssp, stxv */
6997 GEN_HANDLER_E(dform3D
, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
6998 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6999 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7000 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
7001 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
7002 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
7003 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
7004 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x01FFF801, PPC_MEM_EIEIO
),
7005 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
7006 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7007 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7008 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
7009 GEN_HANDLER_E(lwat
, 0x1F, 0x06, 0x12, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7010 GEN_HANDLER_E(stwat
, 0x1F, 0x06, 0x16, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7011 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7012 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7013 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
7014 #if defined(TARGET_PPC64)
7015 GEN_HANDLER_E(ldat
, 0x1F, 0x06, 0x13, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7016 GEN_HANDLER_E(stdat
, 0x1F, 0x06, 0x17, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7017 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
7018 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
7019 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
7020 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
7022 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
7023 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
7024 GEN_HANDLER_E(wait
, 0x1F, 0x1E, 0x00, 0x039FF801, PPC_NONE
, PPC2_ISA300
),
7025 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7026 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7027 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
7028 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
7029 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE
, PPC2_BCTAR_ISA207
),
7030 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
7031 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
7032 #if defined(TARGET_PPC64)
7033 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
7034 GEN_HANDLER_E(stop
, 0x13, 0x12, 0x0b, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
7035 GEN_HANDLER_E(doze
, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7036 GEN_HANDLER_E(nap
, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7037 GEN_HANDLER_E(sleep
, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7038 GEN_HANDLER_E(rvwinkle
, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7039 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
7041 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
7042 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
7043 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7044 #if defined(TARGET_PPC64)
7045 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
7046 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
7048 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
7049 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
7050 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
7051 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
7052 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
7053 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
7054 #if defined(TARGET_PPC64)
7055 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
7056 GEN_HANDLER_E(setb
, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE
, PPC2_ISA300
),
7057 GEN_HANDLER_E(mcrxrx
, 0x1F, 0x00, 0x12, 0x007FF801, PPC_NONE
, PPC2_ISA300
),
7059 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC
),
7060 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
7061 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
7062 GEN_HANDLER_E(dcbfep
, 0x1F, 0x1F, 0x03, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
7063 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
7064 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
7065 GEN_HANDLER_E(dcbstep
, 0x1F, 0x1F, 0x01, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
7066 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
7067 GEN_HANDLER_E(dcbtep
, 0x1F, 0x1F, 0x09, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
7068 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
7069 GEN_HANDLER_E(dcbtstep
, 0x1F, 0x1F, 0x07, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
7070 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
7071 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
7072 GEN_HANDLER_E(dcbzep
, 0x1F, 0x1F, 0x1F, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
7073 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
7074 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x01800001, PPC_ALTIVEC
),
7075 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
7076 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
7077 GEN_HANDLER_E(icbiep
, 0x1F, 0x1F, 0x1E, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
7078 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
7079 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
7080 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
7081 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
7082 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
7083 #if defined(TARGET_PPC64)
7084 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
7085 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
7087 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
7088 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
7090 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
7091 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
7092 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
7093 GEN_HANDLER2(slbfee_
, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F0000, PPC_SEGMENT_64B
),
7095 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
7097 * XXX Those instructions will need to be handled differently for
7098 * different ISA versions
7100 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE
),
7101 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE
),
7102 GEN_HANDLER_E(tlbiel
, 0x1F, 0x12, 0x08, 0x00100001, PPC_NONE
, PPC2_ISA300
),
7103 GEN_HANDLER_E(tlbie
, 0x1F, 0x12, 0x09, 0x00100001, PPC_NONE
, PPC2_ISA300
),
7104 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
7105 #if defined(TARGET_PPC64)
7106 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI
),
7107 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
7108 GEN_HANDLER_E(slbieg
, 0x1F, 0x12, 0x0E, 0x001F0001, PPC_NONE
, PPC2_ISA300
),
7109 GEN_HANDLER_E(slbsync
, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
7111 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
7112 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
7113 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
7114 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
7115 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
7116 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
7117 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
7118 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
7119 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
7120 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
7121 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
7122 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
7123 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
7124 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
7125 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
7126 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
7127 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
7128 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
7129 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
7130 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
7131 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
7132 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
7133 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
7134 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
7135 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
7136 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
7137 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
7138 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
7139 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
7140 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
7141 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
7142 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
7143 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
7144 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
7145 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
7146 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
7147 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
7148 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
7149 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
7150 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
7151 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
7152 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
7153 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
7154 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
7155 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
7156 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
7157 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
7158 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
7159 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
7160 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
7161 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
7162 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
7163 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
7164 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
7165 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
7166 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
7167 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
7168 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
7169 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
7170 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
7171 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
7172 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
7173 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
7174 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
7175 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
7176 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
7177 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
7178 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
7179 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
7180 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
7181 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
7182 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
7183 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
7184 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
7185 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
7186 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
7187 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
7188 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
7189 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
7190 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
7191 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
7192 PPC_NONE
, PPC2_BOOKE206
),
7193 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
7194 PPC_NONE
, PPC2_BOOKE206
),
7195 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
7196 PPC_NONE
, PPC2_BOOKE206
),
7197 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
7198 PPC_NONE
, PPC2_BOOKE206
),
7199 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
7200 PPC_NONE
, PPC2_BOOKE206
),
7201 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
7202 PPC_NONE
, PPC2_PRCNTL
),
7203 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
7204 PPC_NONE
, PPC2_PRCNTL
),
7205 GEN_HANDLER2_E(msgsync
, "msgsync", 0x1F, 0x16, 0x1B, 0x00000000,
7206 PPC_NONE
, PPC2_PRCNTL
),
7207 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
7208 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
7209 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
7210 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
7211 PPC_BOOKE
, PPC2_BOOKE206
),
7212 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_BOOKE
),
7213 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
7214 PPC_BOOKE
, PPC2_BOOKE206
),
7215 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001,
7217 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
7218 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
7219 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
7220 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
7221 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
7222 #if defined(TARGET_PPC64)
7223 GEN_HANDLER_E(maddhd_maddhdu
, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE
,
7225 GEN_HANDLER_E(maddld
, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7226 GEN_HANDLER2_E(msgsndp
, "msgsndp", 0x1F, 0x0E, 0x04, 0x03ff0001,
7227 PPC_NONE
, PPC2_ISA207S
),
7228 GEN_HANDLER2_E(msgclrp
, "msgclrp", 0x1F, 0x0E, 0x05, 0x03ff0001,
7229 PPC_NONE
, PPC2_ISA207S
),
7232 #undef GEN_INT_ARITH_ADD
7233 #undef GEN_INT_ARITH_ADD_CONST
7234 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
7235 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
7236 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
7237 add_ca, compute_ca, compute_ov) \
7238 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
7239 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
7240 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
7241 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
7242 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
7243 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
7244 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
7245 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
7246 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
7247 GEN_HANDLER_E(addex
, 0x1F, 0x0A, 0x05, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7248 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
7249 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
7251 #undef GEN_INT_ARITH_DIVW
7252 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
7253 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
7254 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
7255 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
7256 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
7257 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
7258 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7259 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7260 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7261 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7262 GEN_HANDLER_E(modsw
, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7263 GEN_HANDLER_E(moduw
, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7265 #if defined(TARGET_PPC64)
7266 #undef GEN_INT_ARITH_DIVD
7267 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
7268 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
7269 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
7270 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
7271 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
7272 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
7274 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7275 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7276 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7277 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7278 GEN_HANDLER_E(modsd
, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7279 GEN_HANDLER_E(modud
, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7281 #undef GEN_INT_ARITH_MUL_HELPER
7282 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
7283 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
7284 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
7285 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
7286 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
7289 #undef GEN_INT_ARITH_SUBF
7290 #undef GEN_INT_ARITH_SUBF_CONST
7291 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
7292 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
7293 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
7294 add_ca, compute_ca, compute_ov) \
7295 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
7296 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
7297 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
7298 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
7299 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
7300 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
7301 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
7302 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
7303 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
7304 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
7305 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
7309 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
7310 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
7311 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
7312 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
7313 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
7314 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
7315 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
7316 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
7317 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
7318 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
7319 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
7320 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
7321 #if defined(TARGET_PPC64)
7322 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
7325 #if defined(TARGET_PPC64)
7328 #define GEN_PPC64_R2(name, opc1, opc2) \
7329 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
7330 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
7332 #define GEN_PPC64_R4(name, opc1, opc2) \
7333 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
7334 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
7336 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
7338 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
7340 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
7341 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
7342 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
7343 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
7344 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
7345 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
7353 #define GEN_LD(name, ldop, opc, type) \
7354 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
7355 #define GEN_LDU(name, ldop, opc, type) \
7356 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
7357 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
7358 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
7359 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
7360 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
7361 #define GEN_LDS(name, ldop, op, type) \
7362 GEN_LD(name, ldop, op | 0x20, type) \
7363 GEN_LDU(name, ldop, op | 0x21, type) \
7364 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
7365 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
7367 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
7368 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
7369 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
7370 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
7371 #if defined(TARGET_PPC64)
7372 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
7373 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
7374 GEN_LDUX(ld
, ld64_i64
, 0x15, 0x01, PPC_64B
)
7375 GEN_LDX(ld
, ld64_i64
, 0x15, 0x00, PPC_64B
)
7376 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
7378 /* HV/P7 and later only */
7379 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
7380 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x18, PPC_CILDST
)
7381 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
7382 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
7384 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
7385 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
7387 /* External PID based load */
7389 #define GEN_LDEPX(name, ldop, opc2, opc3) \
7390 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
7391 0x00000001, PPC_NONE, PPC2_BOOKE206),
7393 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
7394 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
7395 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
7396 #if defined(TARGET_PPC64)
7397 GEN_LDEPX(ld
, DEF_MEMOP(MO_Q
), 0x1D, 0x00)
7405 #define GEN_ST(name, stop, opc, type) \
7406 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
7407 #define GEN_STU(name, stop, opc, type) \
7408 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
7409 #define GEN_STUX(name, stop, opc2, opc3, type) \
7410 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
7411 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
7412 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000000, type, type2),
7413 #define GEN_STS(name, stop, op, type) \
7414 GEN_ST(name, stop, op | 0x20, type) \
7415 GEN_STU(name, stop, op | 0x21, type) \
7416 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
7417 GEN_STX(name, stop, 0x17, op | 0x00, type)
7419 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
7420 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
7421 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
7422 #if defined(TARGET_PPC64)
7423 GEN_STUX(std
, st64_i64
, 0x15, 0x05, PPC_64B
)
7424 GEN_STX(std
, st64_i64
, 0x15, 0x04, PPC_64B
)
7425 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
7426 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
7427 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
7428 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
7429 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
7431 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
7432 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
7435 #define GEN_STEPX(name, ldop, opc2, opc3) \
7436 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
7437 0x00000001, PPC_NONE, PPC2_BOOKE206),
7439 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
7440 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
7441 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
7442 #if defined(TARGET_PPC64)
7443 GEN_STEPX(std
, DEF_MEMOP(MO_Q
), 0x1D, 0x04)
7447 #define GEN_CRLOGIC(name, tcg_op, opc) \
7448 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
7449 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
7450 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
7451 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
7452 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
7453 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
7454 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
7455 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
7456 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
7458 #undef GEN_MAC_HANDLER
7459 #define GEN_MAC_HANDLER(name, opc2, opc3) \
7460 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
7461 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
7462 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
7463 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
7464 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
7465 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
7466 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
7467 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
7468 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
7469 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
7470 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
7471 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
7472 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
7473 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
7474 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
7475 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
7476 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
7477 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
7478 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
7479 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
7480 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
7481 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
7482 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
7483 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
7484 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
7485 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
7486 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
7487 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
7488 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
7489 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
7490 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
7491 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
7492 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
7493 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
7494 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
7495 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
7496 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
7497 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
7498 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
7499 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
7500 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
7501 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
7502 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
7504 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
7506 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
7508 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
7510 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
7512 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
7514 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
7516 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
7518 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
7520 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
7522 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
7524 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
7527 #include "translate/fp-ops.inc.c"
7529 #include "translate/vmx-ops.inc.c"
7531 #include "translate/vsx-ops.inc.c"
7533 #include "translate/dfp-ops.inc.c"
7535 #include "translate/spe-ops.inc.c"
7538 #include "helper_regs.h"
7539 #include "translate_init.inc.c"
7541 /*****************************************************************************/
7542 /* Misc PowerPC helpers */
7543 void ppc_cpu_dump_state(CPUState
*cs
, FILE *f
, int flags
)
7548 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
7549 CPUPPCState
*env
= &cpu
->env
;
7552 qemu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
7553 TARGET_FMT_lx
" XER " TARGET_FMT_lx
" CPU#%d\n",
7554 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
),
7556 qemu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
7557 TARGET_FMT_lx
" iidx %d didx %d\n",
7558 env
->msr
, env
->spr
[SPR_HID0
],
7559 env
->hflags
, env
->immu_idx
, env
->dmmu_idx
);
7560 #if !defined(NO_TIMER_DUMP)
7561 qemu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
7562 #if !defined(CONFIG_USER_ONLY)
7563 " DECR " TARGET_FMT_lu
7566 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
7567 #if !defined(CONFIG_USER_ONLY)
7568 , cpu_ppc_load_decr(env
)
7572 for (i
= 0; i
< 32; i
++) {
7573 if ((i
& (RGPL
- 1)) == 0) {
7574 qemu_fprintf(f
, "GPR%02d", i
);
7576 qemu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
7577 if ((i
& (RGPL
- 1)) == (RGPL
- 1)) {
7578 qemu_fprintf(f
, "\n");
7581 qemu_fprintf(f
, "CR ");
7582 for (i
= 0; i
< 8; i
++)
7583 qemu_fprintf(f
, "%01x", env
->crf
[i
]);
7584 qemu_fprintf(f
, " [");
7585 for (i
= 0; i
< 8; i
++) {
7587 if (env
->crf
[i
] & 0x08) {
7589 } else if (env
->crf
[i
] & 0x04) {
7591 } else if (env
->crf
[i
] & 0x02) {
7594 qemu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
7596 qemu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
7599 if (flags
& CPU_DUMP_FPU
) {
7600 for (i
= 0; i
< 32; i
++) {
7601 if ((i
& (RFPL
- 1)) == 0) {
7602 qemu_fprintf(f
, "FPR%02d", i
);
7604 qemu_fprintf(f
, " %016" PRIx64
, *cpu_fpr_ptr(env
, i
));
7605 if ((i
& (RFPL
- 1)) == (RFPL
- 1)) {
7606 qemu_fprintf(f
, "\n");
7609 qemu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
7612 #if !defined(CONFIG_USER_ONLY)
7613 qemu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
7614 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
7615 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
7616 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
7618 qemu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
7619 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
7620 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
7621 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
7623 qemu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
7624 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
7625 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
7626 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
7628 #if defined(TARGET_PPC64)
7629 if (env
->excp_model
== POWERPC_EXCP_POWER7
||
7630 env
->excp_model
== POWERPC_EXCP_POWER8
||
7631 env
->excp_model
== POWERPC_EXCP_POWER9
) {
7632 qemu_fprintf(f
, "HSRR0 " TARGET_FMT_lx
" HSRR1 " TARGET_FMT_lx
"\n",
7633 env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
]);
7636 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
7637 qemu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
7638 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
7639 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
7640 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
7642 qemu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
7643 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
7644 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
7645 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
7647 qemu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
7648 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
7649 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
7650 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
7652 qemu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
7653 " EPR " TARGET_FMT_lx
"\n",
7654 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
7655 env
->spr
[SPR_BOOKE_EPR
]);
7658 qemu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
7659 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
7660 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
7661 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
7664 * IVORs are left out as they are large and do not change often --
7665 * they can be read with "p $ivor0", "p $ivor1", etc.
7669 #if defined(TARGET_PPC64)
7670 if (env
->flags
& POWERPC_FLAG_CFAR
) {
7671 qemu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
7675 if (env
->spr_cb
[SPR_LPCR
].name
) {
7676 qemu_fprintf(f
, " LPCR " TARGET_FMT_lx
"\n", env
->spr
[SPR_LPCR
]);
7679 switch (env
->mmu_model
) {
7680 case POWERPC_MMU_32B
:
7681 case POWERPC_MMU_601
:
7682 case POWERPC_MMU_SOFT_6xx
:
7683 case POWERPC_MMU_SOFT_74xx
:
7684 #if defined(TARGET_PPC64)
7685 case POWERPC_MMU_64B
:
7686 case POWERPC_MMU_2_03
:
7687 case POWERPC_MMU_2_06
:
7688 case POWERPC_MMU_2_07
:
7689 case POWERPC_MMU_3_00
:
7691 if (env
->spr_cb
[SPR_SDR1
].name
) { /* SDR1 Exists */
7692 qemu_fprintf(f
, " SDR1 " TARGET_FMT_lx
" ", env
->spr
[SPR_SDR1
]);
7694 if (env
->spr_cb
[SPR_PTCR
].name
) { /* PTCR Exists */
7695 qemu_fprintf(f
, " PTCR " TARGET_FMT_lx
" ", env
->spr
[SPR_PTCR
]);
7697 qemu_fprintf(f
, " DAR " TARGET_FMT_lx
" DSISR " TARGET_FMT_lx
"\n",
7698 env
->spr
[SPR_DAR
], env
->spr
[SPR_DSISR
]);
7700 case POWERPC_MMU_BOOKE206
:
7701 qemu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
7702 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
7703 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
7704 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
7706 qemu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
7707 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
7708 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
7709 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
7711 qemu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
7712 " TLB1CFG " TARGET_FMT_lx
"\n",
7713 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
7714 env
->spr
[SPR_BOOKE_TLB1CFG
]);
7725 void ppc_cpu_dump_statistics(CPUState
*cs
, int flags
)
7727 #if defined(DO_PPC_STATISTICS)
7728 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
7729 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
7732 t1
= cpu
->env
.opcodes
;
7733 for (op1
= 0; op1
< 64; op1
++) {
7735 if (is_indirect_opcode(handler
)) {
7736 t2
= ind_table(handler
);
7737 for (op2
= 0; op2
< 32; op2
++) {
7739 if (is_indirect_opcode(handler
)) {
7740 t3
= ind_table(handler
);
7741 for (op3
= 0; op3
< 32; op3
++) {
7743 if (handler
->count
== 0) {
7746 qemu_printf("%02x %02x %02x (%02x %04d) %16s: "
7747 "%016" PRIx64
" %" PRId64
"\n",
7748 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
7750 handler
->count
, handler
->count
);
7753 if (handler
->count
== 0) {
7756 qemu_printf("%02x %02x (%02x %04d) %16s: "
7757 "%016" PRIx64
" %" PRId64
"\n",
7758 op1
, op2
, op1
, op2
, handler
->oname
,
7759 handler
->count
, handler
->count
);
7763 if (handler
->count
== 0) {
7766 qemu_printf("%02x (%02x ) %16s: %016" PRIx64
7768 op1
, op1
, handler
->oname
,
7769 handler
->count
, handler
->count
);
7775 static void ppc_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
7777 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7778 CPUPPCState
*env
= cs
->env_ptr
;
7781 ctx
->exception
= POWERPC_EXCP_NONE
;
7782 ctx
->spr_cb
= env
->spr_cb
;
7784 ctx
->mem_idx
= env
->dmmu_idx
;
7786 #if !defined(CONFIG_USER_ONLY)
7787 ctx
->hv
= msr_hv
|| !env
->has_hv_mode
;
7789 ctx
->insns_flags
= env
->insns_flags
;
7790 ctx
->insns_flags2
= env
->insns_flags2
;
7791 ctx
->access_type
= -1;
7792 ctx
->need_access_type
= !(env
->mmu_model
& POWERPC_MMU_64B
);
7793 ctx
->le_mode
= !!(env
->hflags
& (1 << MSR_LE
));
7794 ctx
->default_tcg_memop_mask
= ctx
->le_mode
? MO_LE
: MO_BE
;
7795 ctx
->flags
= env
->flags
;
7796 #if defined(TARGET_PPC64)
7797 ctx
->sf_mode
= msr_is_64bit(env
, env
->msr
);
7798 ctx
->has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
7800 ctx
->lazy_tlb_flush
= env
->mmu_model
== POWERPC_MMU_32B
7801 || env
->mmu_model
== POWERPC_MMU_601
7802 || (env
->mmu_model
& POWERPC_MMU_64B
);
7804 ctx
->fpu_enabled
= !!msr_fp
;
7805 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
) {
7806 ctx
->spe_enabled
= !!msr_spe
;
7808 ctx
->spe_enabled
= false;
7810 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
) {
7811 ctx
->altivec_enabled
= !!msr_vr
;
7813 ctx
->altivec_enabled
= false;
7815 if ((env
->flags
& POWERPC_FLAG_VSX
) && msr_vsx
) {
7816 ctx
->vsx_enabled
= !!msr_vsx
;
7818 ctx
->vsx_enabled
= false;
7820 #if defined(TARGET_PPC64)
7821 if ((env
->flags
& POWERPC_FLAG_TM
) && msr_tm
) {
7822 ctx
->tm_enabled
= !!msr_tm
;
7824 ctx
->tm_enabled
= false;
7827 ctx
->gtse
= !!(env
->spr
[SPR_LPCR
] & LPCR_GTSE
);
7828 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
) {
7829 ctx
->singlestep_enabled
= CPU_SINGLE_STEP
;
7831 ctx
->singlestep_enabled
= 0;
7833 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
) {
7834 ctx
->singlestep_enabled
|= CPU_BRANCH_STEP
;
7836 if ((env
->flags
& POWERPC_FLAG_DE
) && msr_de
) {
7837 ctx
->singlestep_enabled
= 0;
7838 target_ulong dbcr0
= env
->spr
[SPR_BOOKE_DBCR0
];
7839 if (dbcr0
& DBCR0_ICMP
) {
7840 ctx
->singlestep_enabled
|= CPU_SINGLE_STEP
;
7842 if (dbcr0
& DBCR0_BRT
) {
7843 ctx
->singlestep_enabled
|= CPU_BRANCH_STEP
;
7847 if (unlikely(ctx
->base
.singlestep_enabled
)) {
7848 ctx
->singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
7850 #if defined(DO_SINGLE_STEP) && 0
7851 /* Single step trace mode */
7855 bound
= -(ctx
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
7856 ctx
->base
.max_insns
= MIN(ctx
->base
.max_insns
, bound
);
7859 static void ppc_tr_tb_start(DisasContextBase
*db
, CPUState
*cs
)
7863 static void ppc_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
7865 tcg_gen_insn_start(dcbase
->pc_next
);
7868 static bool ppc_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cs
,
7869 const CPUBreakpoint
*bp
)
7871 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7873 gen_debug_exception(ctx
);
7874 dcbase
->is_jmp
= DISAS_NORETURN
;
7876 * The address covered by the breakpoint must be included in
7877 * [tb->pc, tb->pc + tb->size) in order to for it to be properly
7878 * cleared -- thus we increment the PC here so that the logic
7879 * setting tb->size below does the right thing.
7881 ctx
->base
.pc_next
+= 4;
7885 static void ppc_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
7887 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7888 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
7889 CPUPPCState
*env
= cs
->env_ptr
;
7890 opc_handler_t
**table
, *handler
;
7892 LOG_DISAS("----------------\n");
7893 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
7894 ctx
->base
.pc_next
, ctx
->mem_idx
, (int)msr_ir
);
7896 ctx
->opcode
= translator_ldl_swap(env
, ctx
->base
.pc_next
,
7897 need_byteswap(ctx
));
7899 LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n",
7900 ctx
->opcode
, opc1(ctx
->opcode
), opc2(ctx
->opcode
),
7901 opc3(ctx
->opcode
), opc4(ctx
->opcode
),
7902 ctx
->le_mode
? "little" : "big");
7903 ctx
->base
.pc_next
+= 4;
7904 table
= cpu
->opcodes
;
7905 handler
= table
[opc1(ctx
->opcode
)];
7906 if (is_indirect_opcode(handler
)) {
7907 table
= ind_table(handler
);
7908 handler
= table
[opc2(ctx
->opcode
)];
7909 if (is_indirect_opcode(handler
)) {
7910 table
= ind_table(handler
);
7911 handler
= table
[opc3(ctx
->opcode
)];
7912 if (is_indirect_opcode(handler
)) {
7913 table
= ind_table(handler
);
7914 handler
= table
[opc4(ctx
->opcode
)];
7918 /* Is opcode *REALLY* valid ? */
7919 if (unlikely(handler
->handler
== &gen_invalid
)) {
7920 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
7921 "%02x - %02x - %02x - %02x (%08x) "
7922 TARGET_FMT_lx
" %d\n",
7923 opc1(ctx
->opcode
), opc2(ctx
->opcode
),
7924 opc3(ctx
->opcode
), opc4(ctx
->opcode
),
7925 ctx
->opcode
, ctx
->base
.pc_next
- 4, (int)msr_ir
);
7929 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
)
7930 && Rc(ctx
->opcode
))) {
7931 inval
= handler
->inval2
;
7933 inval
= handler
->inval1
;
7936 if (unlikely((ctx
->opcode
& inval
) != 0)) {
7937 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
7938 "%02x - %02x - %02x - %02x (%08x) "
7939 TARGET_FMT_lx
"\n", ctx
->opcode
& inval
,
7940 opc1(ctx
->opcode
), opc2(ctx
->opcode
),
7941 opc3(ctx
->opcode
), opc4(ctx
->opcode
),
7942 ctx
->opcode
, ctx
->base
.pc_next
- 4);
7943 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7944 ctx
->base
.is_jmp
= DISAS_NORETURN
;
7948 (*(handler
->handler
))(ctx
);
7949 #if defined(DO_PPC_STATISTICS)
7952 /* Check trace mode exceptions */
7953 if (unlikely(ctx
->singlestep_enabled
& CPU_SINGLE_STEP
&&
7954 (ctx
->base
.pc_next
<= 0x100 || ctx
->base
.pc_next
> 0xF00) &&
7955 ctx
->exception
!= POWERPC_SYSCALL
&&
7956 ctx
->exception
!= POWERPC_EXCP_TRAP
&&
7957 ctx
->exception
!= POWERPC_EXCP_BRANCH
)) {
7958 uint32_t excp
= gen_prep_dbgex(ctx
);
7959 gen_exception_nip(ctx
, excp
, ctx
->base
.pc_next
);
7962 if (tcg_check_temp_count()) {
7963 qemu_log("Opcode %02x %02x %02x %02x (%08x) leaked "
7964 "temporaries\n", opc1(ctx
->opcode
), opc2(ctx
->opcode
),
7965 opc3(ctx
->opcode
), opc4(ctx
->opcode
), ctx
->opcode
);
7968 ctx
->base
.is_jmp
= ctx
->exception
== POWERPC_EXCP_NONE
?
7969 DISAS_NEXT
: DISAS_NORETURN
;
7972 static void ppc_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
7974 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7976 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
7977 gen_goto_tb(ctx
, 0, ctx
->base
.pc_next
);
7978 } else if (ctx
->exception
!= POWERPC_EXCP_BRANCH
) {
7979 if (unlikely(ctx
->base
.singlestep_enabled
)) {
7980 gen_debug_exception(ctx
);
7982 /* Generate the return instruction */
7983 tcg_gen_exit_tb(NULL
, 0);
7987 static void ppc_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cs
)
7989 qemu_log("IN: %s\n", lookup_symbol(dcbase
->pc_first
));
7990 log_target_disas(cs
, dcbase
->pc_first
, dcbase
->tb
->size
);
7993 static const TranslatorOps ppc_tr_ops
= {
7994 .init_disas_context
= ppc_tr_init_disas_context
,
7995 .tb_start
= ppc_tr_tb_start
,
7996 .insn_start
= ppc_tr_insn_start
,
7997 .breakpoint_check
= ppc_tr_breakpoint_check
,
7998 .translate_insn
= ppc_tr_translate_insn
,
7999 .tb_stop
= ppc_tr_tb_stop
,
8000 .disas_log
= ppc_tr_disas_log
,
8003 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
8007 translator_loop(&ppc_tr_ops
, &ctx
.base
, cs
, tb
, max_insns
);
8010 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
,