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"
27 #include "qemu/host-utils.h"
28 #include "exec/cpu_ldst.h"
30 #include "exec/helper-proto.h"
31 #include "exec/helper-gen.h"
33 #include "trace-tcg.h"
34 #include "exec/translator.h"
38 #define CPU_SINGLE_STEP 0x1
39 #define CPU_BRANCH_STEP 0x2
40 #define GDBSTUB_SINGLE_STEP 0x4
42 /* Include definitions for instructions classes and implementations flags */
43 //#define PPC_DEBUG_DISAS
44 //#define DO_PPC_STATISTICS
46 #ifdef PPC_DEBUG_DISAS
47 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
49 # define LOG_DISAS(...) do { } while (0)
51 /*****************************************************************************/
52 /* Code translation helpers */
54 /* global register indexes */
55 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
56 + 10*4 + 22*5 /* SPE GPRh */
57 + 10*4 + 22*5 /* FPR */
58 + 2*(10*6 + 22*7) /* AVRh, AVRl */
59 + 10*5 + 22*6 /* VSR */
61 static TCGv cpu_gpr
[32];
62 static TCGv cpu_gprh
[32];
63 static TCGv_i64 cpu_fpr
[32];
64 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
65 static TCGv_i64 cpu_vsr
[32];
66 static TCGv_i32 cpu_crf
[8];
71 #if defined(TARGET_PPC64)
74 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
, cpu_ov32
, cpu_ca32
;
75 static TCGv cpu_reserve
;
76 static TCGv cpu_reserve_val
;
77 static TCGv cpu_fpscr
;
78 static TCGv_i32 cpu_access_type
;
80 #include "exec/gen-icount.h"
82 void ppc_translate_init(void)
86 size_t cpu_reg_names_size
;
89 cpu_reg_names_size
= sizeof(cpu_reg_names
);
91 for (i
= 0; i
< 8; i
++) {
92 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
93 cpu_crf
[i
] = tcg_global_mem_new_i32(cpu_env
,
94 offsetof(CPUPPCState
, crf
[i
]), p
);
96 cpu_reg_names_size
-= 5;
99 for (i
= 0; i
< 32; i
++) {
100 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
101 cpu_gpr
[i
] = tcg_global_mem_new(cpu_env
,
102 offsetof(CPUPPCState
, gpr
[i
]), p
);
103 p
+= (i
< 10) ? 3 : 4;
104 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
105 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
106 cpu_gprh
[i
] = tcg_global_mem_new(cpu_env
,
107 offsetof(CPUPPCState
, gprh
[i
]), p
);
108 p
+= (i
< 10) ? 4 : 5;
109 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
111 snprintf(p
, cpu_reg_names_size
, "fp%d", i
);
112 cpu_fpr
[i
] = tcg_global_mem_new_i64(cpu_env
,
113 offsetof(CPUPPCState
, fpr
[i
]), p
);
114 p
+= (i
< 10) ? 4 : 5;
115 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
117 snprintf(p
, cpu_reg_names_size
, "avr%dH", i
);
118 #ifdef HOST_WORDS_BIGENDIAN
119 cpu_avrh
[i
] = tcg_global_mem_new_i64(cpu_env
,
120 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
122 cpu_avrh
[i
] = tcg_global_mem_new_i64(cpu_env
,
123 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
125 p
+= (i
< 10) ? 6 : 7;
126 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
128 snprintf(p
, cpu_reg_names_size
, "avr%dL", i
);
129 #ifdef HOST_WORDS_BIGENDIAN
130 cpu_avrl
[i
] = tcg_global_mem_new_i64(cpu_env
,
131 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
133 cpu_avrl
[i
] = tcg_global_mem_new_i64(cpu_env
,
134 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
136 p
+= (i
< 10) ? 6 : 7;
137 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
138 snprintf(p
, cpu_reg_names_size
, "vsr%d", i
);
139 cpu_vsr
[i
] = tcg_global_mem_new_i64(cpu_env
,
140 offsetof(CPUPPCState
, vsr
[i
]), p
);
141 p
+= (i
< 10) ? 5 : 6;
142 cpu_reg_names_size
-= (i
< 10) ? 5 : 6;
145 cpu_nip
= tcg_global_mem_new(cpu_env
,
146 offsetof(CPUPPCState
, nip
), "nip");
148 cpu_msr
= tcg_global_mem_new(cpu_env
,
149 offsetof(CPUPPCState
, msr
), "msr");
151 cpu_ctr
= tcg_global_mem_new(cpu_env
,
152 offsetof(CPUPPCState
, ctr
), "ctr");
154 cpu_lr
= tcg_global_mem_new(cpu_env
,
155 offsetof(CPUPPCState
, lr
), "lr");
157 #if defined(TARGET_PPC64)
158 cpu_cfar
= tcg_global_mem_new(cpu_env
,
159 offsetof(CPUPPCState
, cfar
), "cfar");
162 cpu_xer
= tcg_global_mem_new(cpu_env
,
163 offsetof(CPUPPCState
, xer
), "xer");
164 cpu_so
= tcg_global_mem_new(cpu_env
,
165 offsetof(CPUPPCState
, so
), "SO");
166 cpu_ov
= tcg_global_mem_new(cpu_env
,
167 offsetof(CPUPPCState
, ov
), "OV");
168 cpu_ca
= tcg_global_mem_new(cpu_env
,
169 offsetof(CPUPPCState
, ca
), "CA");
170 cpu_ov32
= tcg_global_mem_new(cpu_env
,
171 offsetof(CPUPPCState
, ov32
), "OV32");
172 cpu_ca32
= tcg_global_mem_new(cpu_env
,
173 offsetof(CPUPPCState
, ca32
), "CA32");
175 cpu_reserve
= tcg_global_mem_new(cpu_env
,
176 offsetof(CPUPPCState
, reserve_addr
),
178 cpu_reserve_val
= tcg_global_mem_new(cpu_env
,
179 offsetof(CPUPPCState
, reserve_val
),
182 cpu_fpscr
= tcg_global_mem_new(cpu_env
,
183 offsetof(CPUPPCState
, fpscr
), "fpscr");
185 cpu_access_type
= tcg_global_mem_new_i32(cpu_env
,
186 offsetof(CPUPPCState
, access_type
), "access_type");
189 /* internal defines */
190 struct DisasContext
{
191 DisasContextBase base
;
194 /* Routine used to access memory */
195 bool pr
, hv
, dr
, le_mode
;
197 bool need_access_type
;
200 /* Translation flags */
201 TCGMemOp default_tcg_memop_mask
;
202 #if defined(TARGET_PPC64)
207 bool altivec_enabled
;
212 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
213 int singlestep_enabled
;
214 uint64_t insns_flags
;
215 uint64_t insns_flags2
;
218 /* Return true iff byteswap is needed in a scalar memop */
219 static inline bool need_byteswap(const DisasContext
*ctx
)
221 #if defined(TARGET_WORDS_BIGENDIAN)
224 return !ctx
->le_mode
;
228 /* True when active word size < size of target_long. */
230 # define NARROW_MODE(C) (!(C)->sf_mode)
232 # define NARROW_MODE(C) 0
235 struct opc_handler_t
{
236 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
238 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
240 /* instruction type */
242 /* extended instruction type */
245 void (*handler
)(DisasContext
*ctx
);
246 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
249 #if defined(DO_PPC_STATISTICS)
254 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
256 if (ctx
->need_access_type
&& ctx
->access_type
!= access_type
) {
257 tcg_gen_movi_i32(cpu_access_type
, access_type
);
258 ctx
->access_type
= access_type
;
262 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
264 if (NARROW_MODE(ctx
)) {
267 tcg_gen_movi_tl(cpu_nip
, nip
);
270 static void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
274 /* These are all synchronous exceptions, we set the PC back to
275 * the faulting instruction
277 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
278 gen_update_nip(ctx
, ctx
->base
.pc_next
- 4);
280 t0
= tcg_const_i32(excp
);
281 t1
= tcg_const_i32(error
);
282 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
283 tcg_temp_free_i32(t0
);
284 tcg_temp_free_i32(t1
);
285 ctx
->exception
= (excp
);
288 static void gen_exception(DisasContext
*ctx
, uint32_t excp
)
292 /* These are all synchronous exceptions, we set the PC back to
293 * the faulting instruction
295 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
296 gen_update_nip(ctx
, ctx
->base
.pc_next
- 4);
298 t0
= tcg_const_i32(excp
);
299 gen_helper_raise_exception(cpu_env
, t0
);
300 tcg_temp_free_i32(t0
);
301 ctx
->exception
= (excp
);
304 static void gen_exception_nip(DisasContext
*ctx
, uint32_t excp
,
309 gen_update_nip(ctx
, nip
);
310 t0
= tcg_const_i32(excp
);
311 gen_helper_raise_exception(cpu_env
, t0
);
312 tcg_temp_free_i32(t0
);
313 ctx
->exception
= (excp
);
316 static void gen_debug_exception(DisasContext
*ctx
)
320 /* These are all synchronous exceptions, we set the PC back to
321 * the faulting instruction
323 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
324 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
325 gen_update_nip(ctx
, ctx
->base
.pc_next
);
327 t0
= tcg_const_i32(EXCP_DEBUG
);
328 gen_helper_raise_exception(cpu_env
, t0
);
329 tcg_temp_free_i32(t0
);
332 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
334 /* Will be converted to program check if needed */
335 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_INVAL
| error
);
338 static inline void gen_priv_exception(DisasContext
*ctx
, uint32_t error
)
340 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_PRIV
| error
);
343 static inline void gen_hvpriv_exception(DisasContext
*ctx
, uint32_t error
)
345 /* Will be converted to program check if needed */
346 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_PRIV
| error
);
349 /* Stop translation */
350 static inline void gen_stop_exception(DisasContext
*ctx
)
352 gen_update_nip(ctx
, ctx
->base
.pc_next
);
353 ctx
->exception
= POWERPC_EXCP_STOP
;
356 #ifndef CONFIG_USER_ONLY
357 /* No need to update nip here, as execution flow will change */
358 static inline void gen_sync_exception(DisasContext
*ctx
)
360 ctx
->exception
= POWERPC_EXCP_SYNC
;
364 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
365 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
367 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
368 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
370 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
371 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
373 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
374 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
376 #define GEN_HANDLER_E_2(name, opc1, opc2, opc3, opc4, inval, type, type2) \
377 GEN_OPCODE3(name, opc1, opc2, opc3, opc4, inval, type, type2)
379 #define GEN_HANDLER2_E_2(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) \
380 GEN_OPCODE4(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2)
382 typedef struct opcode_t
{
383 unsigned char opc1
, opc2
, opc3
, opc4
;
384 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
385 unsigned char pad
[4];
387 opc_handler_t handler
;
391 /* Helpers for priv. check */
394 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \
397 #if defined(CONFIG_USER_ONLY)
398 #define CHK_HV GEN_PRIV
399 #define CHK_SV GEN_PRIV
400 #define CHK_HVRM GEN_PRIV
404 if (unlikely(ctx->pr || !ctx->hv)) { \
410 if (unlikely(ctx->pr)) { \
416 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
424 /*****************************************************************************/
425 /* PowerPC instructions table */
427 #if defined(DO_PPC_STATISTICS)
428 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
438 .handler = &gen_##name, \
439 .oname = stringify(name), \
441 .oname = stringify(name), \
443 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
454 .handler = &gen_##name, \
455 .oname = stringify(name), \
457 .oname = stringify(name), \
459 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
469 .handler = &gen_##name, \
474 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
484 .handler = &gen_##name, \
485 .oname = stringify(name), \
487 .oname = stringify(name), \
489 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
499 .handler = &gen_##name, \
505 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
515 .handler = &gen_##name, \
517 .oname = stringify(name), \
519 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
530 .handler = &gen_##name, \
532 .oname = stringify(name), \
534 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
544 .handler = &gen_##name, \
548 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
558 .handler = &gen_##name, \
560 .oname = stringify(name), \
562 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
572 .handler = &gen_##name, \
578 /* SPR load/store helpers */
579 static inline void gen_load_spr(TCGv t
, int reg
)
581 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
584 static inline void gen_store_spr(int reg
, TCGv t
)
586 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
589 /* Invalid instruction */
590 static void gen_invalid(DisasContext
*ctx
)
592 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
595 static opc_handler_t invalid_handler
= {
596 .inval1
= 0xFFFFFFFF,
597 .inval2
= 0xFFFFFFFF,
600 .handler
= gen_invalid
,
603 /*** Integer comparison ***/
605 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
607 TCGv t0
= tcg_temp_new();
608 TCGv t1
= tcg_temp_new();
609 TCGv_i32 t
= tcg_temp_new_i32();
611 tcg_gen_movi_tl(t0
, CRF_EQ
);
612 tcg_gen_movi_tl(t1
, CRF_LT
);
613 tcg_gen_movcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
, t1
, t0
);
614 tcg_gen_movi_tl(t1
, CRF_GT
);
615 tcg_gen_movcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
, t1
, t0
);
617 tcg_gen_trunc_tl_i32(t
, t0
);
618 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
619 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t
);
623 tcg_temp_free_i32(t
);
626 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
628 TCGv t0
= tcg_const_tl(arg1
);
629 gen_op_cmp(arg0
, t0
, s
, crf
);
633 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
639 tcg_gen_ext32s_tl(t0
, arg0
);
640 tcg_gen_ext32s_tl(t1
, arg1
);
642 tcg_gen_ext32u_tl(t0
, arg0
);
643 tcg_gen_ext32u_tl(t1
, arg1
);
645 gen_op_cmp(t0
, t1
, s
, crf
);
650 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
652 TCGv t0
= tcg_const_tl(arg1
);
653 gen_op_cmp32(arg0
, t0
, s
, crf
);
657 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
659 if (NARROW_MODE(ctx
)) {
660 gen_op_cmpi32(reg
, 0, 1, 0);
662 gen_op_cmpi(reg
, 0, 1, 0);
667 static void gen_cmp(DisasContext
*ctx
)
669 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
670 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
671 1, crfD(ctx
->opcode
));
673 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
674 1, crfD(ctx
->opcode
));
679 static void gen_cmpi(DisasContext
*ctx
)
681 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
682 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
683 1, crfD(ctx
->opcode
));
685 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
686 1, crfD(ctx
->opcode
));
691 static void gen_cmpl(DisasContext
*ctx
)
693 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
694 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
695 0, crfD(ctx
->opcode
));
697 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
698 0, crfD(ctx
->opcode
));
703 static void gen_cmpli(DisasContext
*ctx
)
705 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
706 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
707 0, crfD(ctx
->opcode
));
709 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
710 0, crfD(ctx
->opcode
));
714 /* cmprb - range comparison: isupper, isaplha, islower*/
715 static void gen_cmprb(DisasContext
*ctx
)
717 TCGv_i32 src1
= tcg_temp_new_i32();
718 TCGv_i32 src2
= tcg_temp_new_i32();
719 TCGv_i32 src2lo
= tcg_temp_new_i32();
720 TCGv_i32 src2hi
= tcg_temp_new_i32();
721 TCGv_i32 crf
= cpu_crf
[crfD(ctx
->opcode
)];
723 tcg_gen_trunc_tl_i32(src1
, cpu_gpr
[rA(ctx
->opcode
)]);
724 tcg_gen_trunc_tl_i32(src2
, cpu_gpr
[rB(ctx
->opcode
)]);
726 tcg_gen_andi_i32(src1
, src1
, 0xFF);
727 tcg_gen_ext8u_i32(src2lo
, src2
);
728 tcg_gen_shri_i32(src2
, src2
, 8);
729 tcg_gen_ext8u_i32(src2hi
, src2
);
731 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
732 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
733 tcg_gen_and_i32(crf
, src2lo
, src2hi
);
735 if (ctx
->opcode
& 0x00200000) {
736 tcg_gen_shri_i32(src2
, src2
, 8);
737 tcg_gen_ext8u_i32(src2lo
, src2
);
738 tcg_gen_shri_i32(src2
, src2
, 8);
739 tcg_gen_ext8u_i32(src2hi
, src2
);
740 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
741 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
742 tcg_gen_and_i32(src2lo
, src2lo
, src2hi
);
743 tcg_gen_or_i32(crf
, crf
, src2lo
);
745 tcg_gen_shli_i32(crf
, crf
, CRF_GT_BIT
);
746 tcg_temp_free_i32(src1
);
747 tcg_temp_free_i32(src2
);
748 tcg_temp_free_i32(src2lo
);
749 tcg_temp_free_i32(src2hi
);
752 #if defined(TARGET_PPC64)
754 static void gen_cmpeqb(DisasContext
*ctx
)
756 gen_helper_cmpeqb(cpu_crf
[crfD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
757 cpu_gpr
[rB(ctx
->opcode
)]);
761 /* isel (PowerPC 2.03 specification) */
762 static void gen_isel(DisasContext
*ctx
)
764 uint32_t bi
= rC(ctx
->opcode
);
765 uint32_t mask
= 0x08 >> (bi
& 0x03);
766 TCGv t0
= tcg_temp_new();
769 tcg_gen_extu_i32_tl(t0
, cpu_crf
[bi
>> 2]);
770 tcg_gen_andi_tl(t0
, t0
, mask
);
772 zr
= tcg_const_tl(0);
773 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rD(ctx
->opcode
)], t0
, zr
,
774 rA(ctx
->opcode
) ? cpu_gpr
[rA(ctx
->opcode
)] : zr
,
775 cpu_gpr
[rB(ctx
->opcode
)]);
780 /* cmpb: PowerPC 2.05 specification */
781 static void gen_cmpb(DisasContext
*ctx
)
783 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
784 cpu_gpr
[rB(ctx
->opcode
)]);
787 /*** Integer arithmetic ***/
789 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
790 TCGv arg1
, TCGv arg2
, int sub
)
792 TCGv t0
= tcg_temp_new();
794 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
795 tcg_gen_xor_tl(t0
, arg1
, arg2
);
797 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
799 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
802 if (NARROW_MODE(ctx
)) {
803 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, 31, 1);
804 if (is_isa300(ctx
)) {
805 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
808 if (is_isa300(ctx
)) {
809 tcg_gen_extract_tl(cpu_ov32
, cpu_ov
, 31, 1);
811 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1, 1);
813 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
816 static inline void gen_op_arith_compute_ca32(DisasContext
*ctx
,
817 TCGv res
, TCGv arg0
, TCGv arg1
,
822 if (!is_isa300(ctx
)) {
828 tcg_gen_eqv_tl(t0
, arg0
, arg1
);
830 tcg_gen_xor_tl(t0
, arg0
, arg1
);
832 tcg_gen_xor_tl(t0
, t0
, res
);
833 tcg_gen_extract_tl(cpu_ca32
, t0
, 32, 1);
837 /* Common add function */
838 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
839 TCGv arg2
, bool add_ca
, bool compute_ca
,
840 bool compute_ov
, bool compute_rc0
)
844 if (compute_ca
|| compute_ov
) {
849 if (NARROW_MODE(ctx
)) {
850 /* Caution: a non-obvious corner case of the spec is that we
851 must produce the *entire* 64-bit addition, but produce the
852 carry into bit 32. */
853 TCGv t1
= tcg_temp_new();
854 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
855 tcg_gen_add_tl(t0
, arg1
, arg2
);
857 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
859 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changed w/ carry */
861 tcg_gen_extract_tl(cpu_ca
, cpu_ca
, 32, 1);
862 if (is_isa300(ctx
)) {
863 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
866 TCGv zero
= tcg_const_tl(0);
868 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
869 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
871 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
873 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, 0);
877 tcg_gen_add_tl(t0
, arg1
, arg2
);
879 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
884 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
886 if (unlikely(compute_rc0
)) {
887 gen_set_Rc0(ctx
, t0
);
891 tcg_gen_mov_tl(ret
, t0
);
895 /* Add functions with two operands */
896 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
897 static void glue(gen_, name)(DisasContext *ctx) \
899 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
900 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
901 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
903 /* Add functions with one operand and one immediate */
904 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
905 add_ca, compute_ca, compute_ov) \
906 static void glue(gen_, name)(DisasContext *ctx) \
908 TCGv t0 = tcg_const_tl(const_val); \
909 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
910 cpu_gpr[rA(ctx->opcode)], t0, \
911 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
915 /* add add. addo addo. */
916 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
917 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
918 /* addc addc. addco addco. */
919 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
920 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
921 /* adde adde. addeo addeo. */
922 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
923 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
924 /* addme addme. addmeo addmeo. */
925 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
926 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
927 /* addze addze. addzeo addzeo.*/
928 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
929 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
931 static void gen_addi(DisasContext
*ctx
)
933 target_long simm
= SIMM(ctx
->opcode
);
935 if (rA(ctx
->opcode
) == 0) {
937 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
939 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
940 cpu_gpr
[rA(ctx
->opcode
)], simm
);
944 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
946 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
947 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
948 c
, 0, 1, 0, compute_rc0
);
952 static void gen_addic(DisasContext
*ctx
)
954 gen_op_addic(ctx
, 0);
957 static void gen_addic_(DisasContext
*ctx
)
959 gen_op_addic(ctx
, 1);
963 static void gen_addis(DisasContext
*ctx
)
965 target_long simm
= SIMM(ctx
->opcode
);
967 if (rA(ctx
->opcode
) == 0) {
969 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
971 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
972 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
977 static void gen_addpcis(DisasContext
*ctx
)
979 target_long d
= DX(ctx
->opcode
);
981 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], ctx
->base
.pc_next
+ (d
<< 16));
984 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
985 TCGv arg2
, int sign
, int compute_ov
)
987 TCGv_i32 t0
= tcg_temp_new_i32();
988 TCGv_i32 t1
= tcg_temp_new_i32();
989 TCGv_i32 t2
= tcg_temp_new_i32();
990 TCGv_i32 t3
= tcg_temp_new_i32();
992 tcg_gen_trunc_tl_i32(t0
, arg1
);
993 tcg_gen_trunc_tl_i32(t1
, arg2
);
995 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
996 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
997 tcg_gen_and_i32(t2
, t2
, t3
);
998 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
999 tcg_gen_or_i32(t2
, t2
, t3
);
1000 tcg_gen_movi_i32(t3
, 0);
1001 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1002 tcg_gen_div_i32(t3
, t0
, t1
);
1003 tcg_gen_extu_i32_tl(ret
, t3
);
1005 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t1
, 0);
1006 tcg_gen_movi_i32(t3
, 0);
1007 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1008 tcg_gen_divu_i32(t3
, t0
, t1
);
1009 tcg_gen_extu_i32_tl(ret
, t3
);
1012 tcg_gen_extu_i32_tl(cpu_ov
, t2
);
1013 if (is_isa300(ctx
)) {
1014 tcg_gen_extu_i32_tl(cpu_ov32
, t2
);
1016 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1018 tcg_temp_free_i32(t0
);
1019 tcg_temp_free_i32(t1
);
1020 tcg_temp_free_i32(t2
);
1021 tcg_temp_free_i32(t3
);
1023 if (unlikely(Rc(ctx
->opcode
) != 0))
1024 gen_set_Rc0(ctx
, ret
);
1027 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1028 static void glue(gen_, name)(DisasContext *ctx) \
1030 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1031 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1032 sign, compute_ov); \
1034 /* divwu divwu. divwuo divwuo. */
1035 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1036 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1037 /* divw divw. divwo divwo. */
1038 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1039 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1041 /* div[wd]eu[o][.] */
1042 #define GEN_DIVE(name, hlpr, compute_ov) \
1043 static void gen_##name(DisasContext *ctx) \
1045 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1046 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1047 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1048 tcg_temp_free_i32(t0); \
1049 if (unlikely(Rc(ctx->opcode) != 0)) { \
1050 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1054 GEN_DIVE(divweu
, divweu
, 0);
1055 GEN_DIVE(divweuo
, divweu
, 1);
1056 GEN_DIVE(divwe
, divwe
, 0);
1057 GEN_DIVE(divweo
, divwe
, 1);
1059 #if defined(TARGET_PPC64)
1060 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1061 TCGv arg2
, int sign
, int compute_ov
)
1063 TCGv_i64 t0
= tcg_temp_new_i64();
1064 TCGv_i64 t1
= tcg_temp_new_i64();
1065 TCGv_i64 t2
= tcg_temp_new_i64();
1066 TCGv_i64 t3
= tcg_temp_new_i64();
1068 tcg_gen_mov_i64(t0
, arg1
);
1069 tcg_gen_mov_i64(t1
, arg2
);
1071 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1072 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1073 tcg_gen_and_i64(t2
, t2
, t3
);
1074 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1075 tcg_gen_or_i64(t2
, t2
, t3
);
1076 tcg_gen_movi_i64(t3
, 0);
1077 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1078 tcg_gen_div_i64(ret
, t0
, t1
);
1080 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t1
, 0);
1081 tcg_gen_movi_i64(t3
, 0);
1082 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1083 tcg_gen_divu_i64(ret
, t0
, t1
);
1086 tcg_gen_mov_tl(cpu_ov
, t2
);
1087 if (is_isa300(ctx
)) {
1088 tcg_gen_mov_tl(cpu_ov32
, t2
);
1090 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1092 tcg_temp_free_i64(t0
);
1093 tcg_temp_free_i64(t1
);
1094 tcg_temp_free_i64(t2
);
1095 tcg_temp_free_i64(t3
);
1097 if (unlikely(Rc(ctx
->opcode
) != 0))
1098 gen_set_Rc0(ctx
, ret
);
1101 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1102 static void glue(gen_, name)(DisasContext *ctx) \
1104 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1105 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1106 sign, compute_ov); \
1108 /* divdu divdu. divduo divduo. */
1109 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1110 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1111 /* divd divd. divdo divdo. */
1112 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1113 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1115 GEN_DIVE(divdeu
, divdeu
, 0);
1116 GEN_DIVE(divdeuo
, divdeu
, 1);
1117 GEN_DIVE(divde
, divde
, 0);
1118 GEN_DIVE(divdeo
, divde
, 1);
1121 static inline void gen_op_arith_modw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1122 TCGv arg2
, int sign
)
1124 TCGv_i32 t0
= tcg_temp_new_i32();
1125 TCGv_i32 t1
= tcg_temp_new_i32();
1127 tcg_gen_trunc_tl_i32(t0
, arg1
);
1128 tcg_gen_trunc_tl_i32(t1
, arg2
);
1130 TCGv_i32 t2
= tcg_temp_new_i32();
1131 TCGv_i32 t3
= tcg_temp_new_i32();
1132 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1133 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1134 tcg_gen_and_i32(t2
, t2
, t3
);
1135 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1136 tcg_gen_or_i32(t2
, t2
, t3
);
1137 tcg_gen_movi_i32(t3
, 0);
1138 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1139 tcg_gen_rem_i32(t3
, t0
, t1
);
1140 tcg_gen_ext_i32_tl(ret
, t3
);
1141 tcg_temp_free_i32(t2
);
1142 tcg_temp_free_i32(t3
);
1144 TCGv_i32 t2
= tcg_const_i32(1);
1145 TCGv_i32 t3
= tcg_const_i32(0);
1146 tcg_gen_movcond_i32(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1147 tcg_gen_remu_i32(t3
, t0
, t1
);
1148 tcg_gen_extu_i32_tl(ret
, t3
);
1149 tcg_temp_free_i32(t2
);
1150 tcg_temp_free_i32(t3
);
1152 tcg_temp_free_i32(t0
);
1153 tcg_temp_free_i32(t1
);
1156 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
1157 static void glue(gen_, name)(DisasContext *ctx) \
1159 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
1160 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1164 GEN_INT_ARITH_MODW(moduw
, 0x08, 0);
1165 GEN_INT_ARITH_MODW(modsw
, 0x18, 1);
1167 #if defined(TARGET_PPC64)
1168 static inline void gen_op_arith_modd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1169 TCGv arg2
, int sign
)
1171 TCGv_i64 t0
= tcg_temp_new_i64();
1172 TCGv_i64 t1
= tcg_temp_new_i64();
1174 tcg_gen_mov_i64(t0
, arg1
);
1175 tcg_gen_mov_i64(t1
, arg2
);
1177 TCGv_i64 t2
= tcg_temp_new_i64();
1178 TCGv_i64 t3
= tcg_temp_new_i64();
1179 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1180 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1181 tcg_gen_and_i64(t2
, t2
, t3
);
1182 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1183 tcg_gen_or_i64(t2
, t2
, t3
);
1184 tcg_gen_movi_i64(t3
, 0);
1185 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1186 tcg_gen_rem_i64(ret
, t0
, t1
);
1187 tcg_temp_free_i64(t2
);
1188 tcg_temp_free_i64(t3
);
1190 TCGv_i64 t2
= tcg_const_i64(1);
1191 TCGv_i64 t3
= tcg_const_i64(0);
1192 tcg_gen_movcond_i64(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1193 tcg_gen_remu_i64(ret
, t0
, t1
);
1194 tcg_temp_free_i64(t2
);
1195 tcg_temp_free_i64(t3
);
1197 tcg_temp_free_i64(t0
);
1198 tcg_temp_free_i64(t1
);
1201 #define GEN_INT_ARITH_MODD(name, opc3, sign) \
1202 static void glue(gen_, name)(DisasContext *ctx) \
1204 gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \
1205 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1209 GEN_INT_ARITH_MODD(modud
, 0x08, 0);
1210 GEN_INT_ARITH_MODD(modsd
, 0x18, 1);
1214 static void gen_mulhw(DisasContext
*ctx
)
1216 TCGv_i32 t0
= tcg_temp_new_i32();
1217 TCGv_i32 t1
= tcg_temp_new_i32();
1219 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1220 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1221 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1222 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1223 tcg_temp_free_i32(t0
);
1224 tcg_temp_free_i32(t1
);
1225 if (unlikely(Rc(ctx
->opcode
) != 0))
1226 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1229 /* mulhwu mulhwu. */
1230 static void gen_mulhwu(DisasContext
*ctx
)
1232 TCGv_i32 t0
= tcg_temp_new_i32();
1233 TCGv_i32 t1
= tcg_temp_new_i32();
1235 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1236 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1237 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1238 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1239 tcg_temp_free_i32(t0
);
1240 tcg_temp_free_i32(t1
);
1241 if (unlikely(Rc(ctx
->opcode
) != 0))
1242 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1246 static void gen_mullw(DisasContext
*ctx
)
1248 #if defined(TARGET_PPC64)
1250 t0
= tcg_temp_new_i64();
1251 t1
= tcg_temp_new_i64();
1252 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1253 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1254 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1258 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1259 cpu_gpr
[rB(ctx
->opcode
)]);
1261 if (unlikely(Rc(ctx
->opcode
) != 0))
1262 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1265 /* mullwo mullwo. */
1266 static void gen_mullwo(DisasContext
*ctx
)
1268 TCGv_i32 t0
= tcg_temp_new_i32();
1269 TCGv_i32 t1
= tcg_temp_new_i32();
1271 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1272 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1273 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1274 #if defined(TARGET_PPC64)
1275 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1277 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1280 tcg_gen_sari_i32(t0
, t0
, 31);
1281 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1282 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1283 if (is_isa300(ctx
)) {
1284 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1286 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1288 tcg_temp_free_i32(t0
);
1289 tcg_temp_free_i32(t1
);
1290 if (unlikely(Rc(ctx
->opcode
) != 0))
1291 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1295 static void gen_mulli(DisasContext
*ctx
)
1297 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1301 #if defined(TARGET_PPC64)
1303 static void gen_mulhd(DisasContext
*ctx
)
1305 TCGv lo
= tcg_temp_new();
1306 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1307 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1309 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1310 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1314 /* mulhdu mulhdu. */
1315 static void gen_mulhdu(DisasContext
*ctx
)
1317 TCGv lo
= tcg_temp_new();
1318 tcg_gen_mulu2_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
)]);
1327 static void gen_mulld(DisasContext
*ctx
)
1329 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1330 cpu_gpr
[rB(ctx
->opcode
)]);
1331 if (unlikely(Rc(ctx
->opcode
) != 0))
1332 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1335 /* mulldo mulldo. */
1336 static void gen_mulldo(DisasContext
*ctx
)
1338 TCGv_i64 t0
= tcg_temp_new_i64();
1339 TCGv_i64 t1
= tcg_temp_new_i64();
1341 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
1342 cpu_gpr
[rB(ctx
->opcode
)]);
1343 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1345 tcg_gen_sari_i64(t0
, t0
, 63);
1346 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
1347 if (is_isa300(ctx
)) {
1348 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1350 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1352 tcg_temp_free_i64(t0
);
1353 tcg_temp_free_i64(t1
);
1355 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1356 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1361 /* Common subf function */
1362 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1363 TCGv arg2
, bool add_ca
, bool compute_ca
,
1364 bool compute_ov
, bool compute_rc0
)
1368 if (compute_ca
|| compute_ov
) {
1369 t0
= tcg_temp_new();
1373 /* dest = ~arg1 + arg2 [+ ca]. */
1374 if (NARROW_MODE(ctx
)) {
1375 /* Caution: a non-obvious corner case of the spec is that we
1376 must produce the *entire* 64-bit addition, but produce the
1377 carry into bit 32. */
1378 TCGv inv1
= tcg_temp_new();
1379 TCGv t1
= tcg_temp_new();
1380 tcg_gen_not_tl(inv1
, arg1
);
1382 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1384 tcg_gen_addi_tl(t0
, arg2
, 1);
1386 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1387 tcg_gen_add_tl(t0
, t0
, inv1
);
1388 tcg_temp_free(inv1
);
1389 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1391 tcg_gen_extract_tl(cpu_ca
, cpu_ca
, 32, 1);
1392 if (is_isa300(ctx
)) {
1393 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
1395 } else if (add_ca
) {
1396 TCGv zero
, inv1
= tcg_temp_new();
1397 tcg_gen_not_tl(inv1
, arg1
);
1398 zero
= tcg_const_tl(0);
1399 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1400 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1401 gen_op_arith_compute_ca32(ctx
, t0
, inv1
, arg2
, 0);
1402 tcg_temp_free(zero
);
1403 tcg_temp_free(inv1
);
1405 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1406 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1407 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, 1);
1409 } else if (add_ca
) {
1410 /* Since we're ignoring carry-out, we can simplify the
1411 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1412 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1413 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1414 tcg_gen_subi_tl(t0
, t0
, 1);
1416 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1420 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1422 if (unlikely(compute_rc0
)) {
1423 gen_set_Rc0(ctx
, t0
);
1427 tcg_gen_mov_tl(ret
, t0
);
1431 /* Sub functions with Two operands functions */
1432 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1433 static void glue(gen_, name)(DisasContext *ctx) \
1435 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1436 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1437 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1439 /* Sub functions with one operand and one immediate */
1440 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1441 add_ca, compute_ca, compute_ov) \
1442 static void glue(gen_, name)(DisasContext *ctx) \
1444 TCGv t0 = tcg_const_tl(const_val); \
1445 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1446 cpu_gpr[rA(ctx->opcode)], t0, \
1447 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1448 tcg_temp_free(t0); \
1450 /* subf subf. subfo subfo. */
1451 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1452 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1453 /* subfc subfc. subfco subfco. */
1454 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1455 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1456 /* subfe subfe. subfeo subfo. */
1457 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1458 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1459 /* subfme subfme. subfmeo subfmeo. */
1460 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1461 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1462 /* subfze subfze. subfzeo subfzeo.*/
1463 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1464 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1467 static void gen_subfic(DisasContext
*ctx
)
1469 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1470 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1475 /* neg neg. nego nego. */
1476 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1478 TCGv zero
= tcg_const_tl(0);
1479 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1480 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1481 tcg_temp_free(zero
);
1484 static void gen_neg(DisasContext
*ctx
)
1486 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1487 if (unlikely(Rc(ctx
->opcode
))) {
1488 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1492 static void gen_nego(DisasContext
*ctx
)
1494 gen_op_arith_neg(ctx
, 1);
1497 /*** Integer logical ***/
1498 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1499 static void glue(gen_, name)(DisasContext *ctx) \
1501 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1502 cpu_gpr[rB(ctx->opcode)]); \
1503 if (unlikely(Rc(ctx->opcode) != 0)) \
1504 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1507 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1508 static void glue(gen_, name)(DisasContext *ctx) \
1510 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1511 if (unlikely(Rc(ctx->opcode) != 0)) \
1512 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1516 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1518 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1521 static void gen_andi_(DisasContext
*ctx
)
1523 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1524 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1528 static void gen_andis_(DisasContext
*ctx
)
1530 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1531 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1535 static void gen_cntlzw(DisasContext
*ctx
)
1537 TCGv_i32 t
= tcg_temp_new_i32();
1539 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
1540 tcg_gen_clzi_i32(t
, t
, 32);
1541 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
1542 tcg_temp_free_i32(t
);
1544 if (unlikely(Rc(ctx
->opcode
) != 0))
1545 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1549 static void gen_cnttzw(DisasContext
*ctx
)
1551 TCGv_i32 t
= tcg_temp_new_i32();
1553 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
1554 tcg_gen_ctzi_i32(t
, t
, 32);
1555 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
1556 tcg_temp_free_i32(t
);
1558 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1559 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1564 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1565 /* extsb & extsb. */
1566 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1567 /* extsh & extsh. */
1568 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1570 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1572 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1574 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
1575 static void gen_pause(DisasContext
*ctx
)
1577 TCGv_i32 t0
= tcg_const_i32(0);
1578 tcg_gen_st_i32(t0
, cpu_env
,
1579 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
1580 tcg_temp_free_i32(t0
);
1582 /* Stop translation, this gives other CPUs a chance to run */
1583 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
1585 #endif /* defined(TARGET_PPC64) */
1588 static void gen_or(DisasContext
*ctx
)
1592 rs
= rS(ctx
->opcode
);
1593 ra
= rA(ctx
->opcode
);
1594 rb
= rB(ctx
->opcode
);
1595 /* Optimisation for mr. ri case */
1596 if (rs
!= ra
|| rs
!= rb
) {
1598 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1600 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1601 if (unlikely(Rc(ctx
->opcode
) != 0))
1602 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1603 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1604 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1605 #if defined(TARGET_PPC64)
1606 } else if (rs
!= 0) { /* 0 is nop */
1611 /* Set process priority to low */
1615 /* Set process priority to medium-low */
1619 /* Set process priority to normal */
1622 #if !defined(CONFIG_USER_ONLY)
1625 /* Set process priority to very low */
1631 /* Set process priority to medium-hight */
1637 /* Set process priority to high */
1642 if (ctx
->hv
&& !ctx
->pr
) {
1643 /* Set process priority to very high */
1652 TCGv t0
= tcg_temp_new();
1653 gen_load_spr(t0
, SPR_PPR
);
1654 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1655 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1656 gen_store_spr(SPR_PPR
, t0
);
1659 #if !defined(CONFIG_USER_ONLY)
1660 /* Pause out of TCG otherwise spin loops with smt_low eat too much
1661 * CPU and the kernel hangs. This applies to all encodings other
1662 * than no-op, e.g., miso(rs=26), yield(27), mdoio(29), mdoom(30),
1663 * and all currently undefined.
1671 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1674 static void gen_xor(DisasContext
*ctx
)
1676 /* Optimisation for "set to zero" case */
1677 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1678 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1680 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1681 if (unlikely(Rc(ctx
->opcode
) != 0))
1682 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1686 static void gen_ori(DisasContext
*ctx
)
1688 target_ulong uimm
= UIMM(ctx
->opcode
);
1690 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1693 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1697 static void gen_oris(DisasContext
*ctx
)
1699 target_ulong uimm
= UIMM(ctx
->opcode
);
1701 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1705 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1709 static void gen_xori(DisasContext
*ctx
)
1711 target_ulong uimm
= UIMM(ctx
->opcode
);
1713 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1717 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1721 static void gen_xoris(DisasContext
*ctx
)
1723 target_ulong uimm
= UIMM(ctx
->opcode
);
1725 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1729 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1732 /* popcntb : PowerPC 2.03 specification */
1733 static void gen_popcntb(DisasContext
*ctx
)
1735 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1738 static void gen_popcntw(DisasContext
*ctx
)
1740 #if defined(TARGET_PPC64)
1741 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1743 tcg_gen_ctpop_i32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1747 #if defined(TARGET_PPC64)
1748 /* popcntd: PowerPC 2.06 specification */
1749 static void gen_popcntd(DisasContext
*ctx
)
1751 tcg_gen_ctpop_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1755 /* prtyw: PowerPC 2.05 specification */
1756 static void gen_prtyw(DisasContext
*ctx
)
1758 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1759 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1760 TCGv t0
= tcg_temp_new();
1761 tcg_gen_shri_tl(t0
, rs
, 16);
1762 tcg_gen_xor_tl(ra
, rs
, t0
);
1763 tcg_gen_shri_tl(t0
, ra
, 8);
1764 tcg_gen_xor_tl(ra
, ra
, t0
);
1765 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1769 #if defined(TARGET_PPC64)
1770 /* prtyd: PowerPC 2.05 specification */
1771 static void gen_prtyd(DisasContext
*ctx
)
1773 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1774 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1775 TCGv t0
= tcg_temp_new();
1776 tcg_gen_shri_tl(t0
, rs
, 32);
1777 tcg_gen_xor_tl(ra
, rs
, t0
);
1778 tcg_gen_shri_tl(t0
, ra
, 16);
1779 tcg_gen_xor_tl(ra
, ra
, t0
);
1780 tcg_gen_shri_tl(t0
, ra
, 8);
1781 tcg_gen_xor_tl(ra
, ra
, t0
);
1782 tcg_gen_andi_tl(ra
, ra
, 1);
1787 #if defined(TARGET_PPC64)
1789 static void gen_bpermd(DisasContext
*ctx
)
1791 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
1792 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1796 #if defined(TARGET_PPC64)
1797 /* extsw & extsw. */
1798 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1801 static void gen_cntlzd(DisasContext
*ctx
)
1803 tcg_gen_clzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
1804 if (unlikely(Rc(ctx
->opcode
) != 0))
1805 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1809 static void gen_cnttzd(DisasContext
*ctx
)
1811 tcg_gen_ctzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
1812 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1813 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1818 static void gen_darn(DisasContext
*ctx
)
1820 int l
= L(ctx
->opcode
);
1823 gen_helper_darn32(cpu_gpr
[rD(ctx
->opcode
)]);
1824 } else if (l
<= 2) {
1825 /* Return 64-bit random for both CRN and RRN */
1826 gen_helper_darn64(cpu_gpr
[rD(ctx
->opcode
)]);
1828 tcg_gen_movi_i64(cpu_gpr
[rD(ctx
->opcode
)], -1);
1833 /*** Integer rotate ***/
1835 /* rlwimi & rlwimi. */
1836 static void gen_rlwimi(DisasContext
*ctx
)
1838 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1839 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1840 uint32_t sh
= SH(ctx
->opcode
);
1841 uint32_t mb
= MB(ctx
->opcode
);
1842 uint32_t me
= ME(ctx
->opcode
);
1844 if (sh
== (31-me
) && mb
<= me
) {
1845 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
1850 #if defined(TARGET_PPC64)
1854 mask
= MASK(mb
, me
);
1856 t1
= tcg_temp_new();
1857 if (mask
<= 0xffffffffu
) {
1858 TCGv_i32 t0
= tcg_temp_new_i32();
1859 tcg_gen_trunc_tl_i32(t0
, t_rs
);
1860 tcg_gen_rotli_i32(t0
, t0
, sh
);
1861 tcg_gen_extu_i32_tl(t1
, t0
);
1862 tcg_temp_free_i32(t0
);
1864 #if defined(TARGET_PPC64)
1865 tcg_gen_deposit_i64(t1
, t_rs
, t_rs
, 32, 32);
1866 tcg_gen_rotli_i64(t1
, t1
, sh
);
1868 g_assert_not_reached();
1872 tcg_gen_andi_tl(t1
, t1
, mask
);
1873 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
1874 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
1877 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1878 gen_set_Rc0(ctx
, t_ra
);
1882 /* rlwinm & rlwinm. */
1883 static void gen_rlwinm(DisasContext
*ctx
)
1885 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1886 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1887 int sh
= SH(ctx
->opcode
);
1888 int mb
= MB(ctx
->opcode
);
1889 int me
= ME(ctx
->opcode
);
1890 int len
= me
- mb
+ 1;
1891 int rsh
= (32 - sh
) & 31;
1893 if (sh
!= 0 && len
> 0 && me
== (31 - sh
)) {
1894 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
1895 } else if (me
== 31 && rsh
+ len
<= 32) {
1896 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
1899 #if defined(TARGET_PPC64)
1903 mask
= MASK(mb
, me
);
1905 tcg_gen_andi_tl(t_ra
, t_rs
, mask
);
1906 } else if (mask
<= 0xffffffffu
) {
1907 TCGv_i32 t0
= tcg_temp_new_i32();
1908 tcg_gen_trunc_tl_i32(t0
, t_rs
);
1909 tcg_gen_rotli_i32(t0
, t0
, sh
);
1910 tcg_gen_andi_i32(t0
, t0
, mask
);
1911 tcg_gen_extu_i32_tl(t_ra
, t0
);
1912 tcg_temp_free_i32(t0
);
1914 #if defined(TARGET_PPC64)
1915 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
1916 tcg_gen_rotli_i64(t_ra
, t_ra
, sh
);
1917 tcg_gen_andi_i64(t_ra
, t_ra
, mask
);
1919 g_assert_not_reached();
1923 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1924 gen_set_Rc0(ctx
, t_ra
);
1928 /* rlwnm & rlwnm. */
1929 static void gen_rlwnm(DisasContext
*ctx
)
1931 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1932 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1933 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
1934 uint32_t mb
= MB(ctx
->opcode
);
1935 uint32_t me
= ME(ctx
->opcode
);
1938 #if defined(TARGET_PPC64)
1942 mask
= MASK(mb
, me
);
1944 if (mask
<= 0xffffffffu
) {
1945 TCGv_i32 t0
= tcg_temp_new_i32();
1946 TCGv_i32 t1
= tcg_temp_new_i32();
1947 tcg_gen_trunc_tl_i32(t0
, t_rb
);
1948 tcg_gen_trunc_tl_i32(t1
, t_rs
);
1949 tcg_gen_andi_i32(t0
, t0
, 0x1f);
1950 tcg_gen_rotl_i32(t1
, t1
, t0
);
1951 tcg_gen_extu_i32_tl(t_ra
, t1
);
1952 tcg_temp_free_i32(t0
);
1953 tcg_temp_free_i32(t1
);
1955 #if defined(TARGET_PPC64)
1956 TCGv_i64 t0
= tcg_temp_new_i64();
1957 tcg_gen_andi_i64(t0
, t_rb
, 0x1f);
1958 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
1959 tcg_gen_rotl_i64(t_ra
, t_ra
, t0
);
1960 tcg_temp_free_i64(t0
);
1962 g_assert_not_reached();
1966 tcg_gen_andi_tl(t_ra
, t_ra
, mask
);
1968 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1969 gen_set_Rc0(ctx
, t_ra
);
1973 #if defined(TARGET_PPC64)
1974 #define GEN_PPC64_R2(name, opc1, opc2) \
1975 static void glue(gen_, name##0)(DisasContext *ctx) \
1977 gen_##name(ctx, 0); \
1980 static void glue(gen_, name##1)(DisasContext *ctx) \
1982 gen_##name(ctx, 1); \
1984 #define GEN_PPC64_R4(name, opc1, opc2) \
1985 static void glue(gen_, name##0)(DisasContext *ctx) \
1987 gen_##name(ctx, 0, 0); \
1990 static void glue(gen_, name##1)(DisasContext *ctx) \
1992 gen_##name(ctx, 0, 1); \
1995 static void glue(gen_, name##2)(DisasContext *ctx) \
1997 gen_##name(ctx, 1, 0); \
2000 static void glue(gen_, name##3)(DisasContext *ctx) \
2002 gen_##name(ctx, 1, 1); \
2005 static void gen_rldinm(DisasContext
*ctx
, int mb
, int me
, int sh
)
2007 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2008 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2009 int len
= me
- mb
+ 1;
2010 int rsh
= (64 - sh
) & 63;
2012 if (sh
!= 0 && len
> 0 && me
== (63 - sh
)) {
2013 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2014 } else if (me
== 63 && rsh
+ len
<= 64) {
2015 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2017 tcg_gen_rotli_tl(t_ra
, t_rs
, sh
);
2018 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2020 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2021 gen_set_Rc0(ctx
, t_ra
);
2025 /* rldicl - rldicl. */
2026 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
2030 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2031 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2032 gen_rldinm(ctx
, mb
, 63, sh
);
2034 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
2036 /* rldicr - rldicr. */
2037 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
2041 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2042 me
= MB(ctx
->opcode
) | (men
<< 5);
2043 gen_rldinm(ctx
, 0, me
, sh
);
2045 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
2047 /* rldic - rldic. */
2048 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
2052 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2053 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2054 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
2056 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
2058 static void gen_rldnm(DisasContext
*ctx
, int mb
, int me
)
2060 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2061 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2062 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2065 t0
= tcg_temp_new();
2066 tcg_gen_andi_tl(t0
, t_rb
, 0x3f);
2067 tcg_gen_rotl_tl(t_ra
, t_rs
, t0
);
2070 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2071 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2072 gen_set_Rc0(ctx
, t_ra
);
2076 /* rldcl - rldcl. */
2077 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
2081 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2082 gen_rldnm(ctx
, mb
, 63);
2084 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
2086 /* rldcr - rldcr. */
2087 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
2091 me
= MB(ctx
->opcode
) | (men
<< 5);
2092 gen_rldnm(ctx
, 0, me
);
2094 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
2096 /* rldimi - rldimi. */
2097 static void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
2099 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2100 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2101 uint32_t sh
= SH(ctx
->opcode
) | (shn
<< 5);
2102 uint32_t mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2103 uint32_t me
= 63 - sh
;
2106 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2108 target_ulong mask
= MASK(mb
, me
);
2109 TCGv t1
= tcg_temp_new();
2111 tcg_gen_rotli_tl(t1
, t_rs
, sh
);
2112 tcg_gen_andi_tl(t1
, t1
, mask
);
2113 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2114 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2117 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2118 gen_set_Rc0(ctx
, t_ra
);
2121 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
2124 /*** Integer shift ***/
2127 static void gen_slw(DisasContext
*ctx
)
2131 t0
= tcg_temp_new();
2132 /* AND rS with a mask that is 0 when rB >= 0x20 */
2133 #if defined(TARGET_PPC64)
2134 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2135 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2137 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2138 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2140 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2141 t1
= tcg_temp_new();
2142 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2143 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2146 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2147 if (unlikely(Rc(ctx
->opcode
) != 0))
2148 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2152 static void gen_sraw(DisasContext
*ctx
)
2154 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2155 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2156 if (unlikely(Rc(ctx
->opcode
) != 0))
2157 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2160 /* srawi & srawi. */
2161 static void gen_srawi(DisasContext
*ctx
)
2163 int sh
= SH(ctx
->opcode
);
2164 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2165 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2167 tcg_gen_ext32s_tl(dst
, src
);
2168 tcg_gen_movi_tl(cpu_ca
, 0);
2169 if (is_isa300(ctx
)) {
2170 tcg_gen_movi_tl(cpu_ca32
, 0);
2174 tcg_gen_ext32s_tl(dst
, src
);
2175 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
2176 t0
= tcg_temp_new();
2177 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
2178 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2180 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2181 if (is_isa300(ctx
)) {
2182 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2184 tcg_gen_sari_tl(dst
, dst
, sh
);
2186 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2187 gen_set_Rc0(ctx
, dst
);
2192 static void gen_srw(DisasContext
*ctx
)
2196 t0
= tcg_temp_new();
2197 /* AND rS with a mask that is 0 when rB >= 0x20 */
2198 #if defined(TARGET_PPC64)
2199 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2200 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2202 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2203 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2205 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2206 tcg_gen_ext32u_tl(t0
, t0
);
2207 t1
= tcg_temp_new();
2208 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2209 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2212 if (unlikely(Rc(ctx
->opcode
) != 0))
2213 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2216 #if defined(TARGET_PPC64)
2218 static void gen_sld(DisasContext
*ctx
)
2222 t0
= tcg_temp_new();
2223 /* AND rS with a mask that is 0 when rB >= 0x40 */
2224 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2225 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2226 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2227 t1
= tcg_temp_new();
2228 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2229 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2232 if (unlikely(Rc(ctx
->opcode
) != 0))
2233 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2237 static void gen_srad(DisasContext
*ctx
)
2239 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2240 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2241 if (unlikely(Rc(ctx
->opcode
) != 0))
2242 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2244 /* sradi & sradi. */
2245 static inline void gen_sradi(DisasContext
*ctx
, int n
)
2247 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2248 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2249 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2251 tcg_gen_mov_tl(dst
, src
);
2252 tcg_gen_movi_tl(cpu_ca
, 0);
2253 if (is_isa300(ctx
)) {
2254 tcg_gen_movi_tl(cpu_ca32
, 0);
2258 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
2259 t0
= tcg_temp_new();
2260 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
2261 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2263 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2264 if (is_isa300(ctx
)) {
2265 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2267 tcg_gen_sari_tl(dst
, src
, sh
);
2269 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2270 gen_set_Rc0(ctx
, dst
);
2274 static void gen_sradi0(DisasContext
*ctx
)
2279 static void gen_sradi1(DisasContext
*ctx
)
2284 /* extswsli & extswsli. */
2285 static inline void gen_extswsli(DisasContext
*ctx
, int n
)
2287 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2288 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2289 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2291 tcg_gen_ext32s_tl(dst
, src
);
2292 tcg_gen_shli_tl(dst
, dst
, sh
);
2293 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2294 gen_set_Rc0(ctx
, dst
);
2298 static void gen_extswsli0(DisasContext
*ctx
)
2300 gen_extswsli(ctx
, 0);
2303 static void gen_extswsli1(DisasContext
*ctx
)
2305 gen_extswsli(ctx
, 1);
2309 static void gen_srd(DisasContext
*ctx
)
2313 t0
= tcg_temp_new();
2314 /* AND rS with a mask that is 0 when rB >= 0x40 */
2315 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2316 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2317 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2318 t1
= tcg_temp_new();
2319 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2320 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2323 if (unlikely(Rc(ctx
->opcode
) != 0))
2324 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2328 /*** Addressing modes ***/
2329 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2330 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2333 target_long simm
= SIMM(ctx
->opcode
);
2336 if (rA(ctx
->opcode
) == 0) {
2337 if (NARROW_MODE(ctx
)) {
2338 simm
= (uint32_t)simm
;
2340 tcg_gen_movi_tl(EA
, simm
);
2341 } else if (likely(simm
!= 0)) {
2342 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2343 if (NARROW_MODE(ctx
)) {
2344 tcg_gen_ext32u_tl(EA
, EA
);
2347 if (NARROW_MODE(ctx
)) {
2348 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2350 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2355 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2357 if (rA(ctx
->opcode
) == 0) {
2358 if (NARROW_MODE(ctx
)) {
2359 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2361 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2364 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2365 if (NARROW_MODE(ctx
)) {
2366 tcg_gen_ext32u_tl(EA
, EA
);
2371 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2373 if (rA(ctx
->opcode
) == 0) {
2374 tcg_gen_movi_tl(EA
, 0);
2375 } else if (NARROW_MODE(ctx
)) {
2376 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2378 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2382 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2385 tcg_gen_addi_tl(ret
, arg1
, val
);
2386 if (NARROW_MODE(ctx
)) {
2387 tcg_gen_ext32u_tl(ret
, ret
);
2391 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2393 TCGLabel
*l1
= gen_new_label();
2394 TCGv t0
= tcg_temp_new();
2396 tcg_gen_andi_tl(t0
, EA
, mask
);
2397 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2398 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2399 t2
= tcg_const_i32(ctx
->opcode
& 0x03FF0000);
2400 gen_update_nip(ctx
, ctx
->base
.pc_next
- 4);
2401 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2402 tcg_temp_free_i32(t1
);
2403 tcg_temp_free_i32(t2
);
2408 static inline void gen_align_no_le(DisasContext
*ctx
)
2410 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
,
2411 (ctx
->opcode
& 0x03FF0000) | POWERPC_EXCP_ALIGN_LE
);
2414 /*** Integer load ***/
2415 #define DEF_MEMOP(op) ((op) | ctx->default_tcg_memop_mask)
2416 #define BSWAP_MEMOP(op) ((op) | (ctx->default_tcg_memop_mask ^ MO_BSWAP))
2418 #define GEN_QEMU_LOAD_TL(ldop, op) \
2419 static void glue(gen_qemu_, ldop)(DisasContext *ctx, \
2423 tcg_gen_qemu_ld_tl(val, addr, ctx->mem_idx, op); \
2426 GEN_QEMU_LOAD_TL(ld8u
, DEF_MEMOP(MO_UB
))
2427 GEN_QEMU_LOAD_TL(ld16u
, DEF_MEMOP(MO_UW
))
2428 GEN_QEMU_LOAD_TL(ld16s
, DEF_MEMOP(MO_SW
))
2429 GEN_QEMU_LOAD_TL(ld32u
, DEF_MEMOP(MO_UL
))
2430 GEN_QEMU_LOAD_TL(ld32s
, DEF_MEMOP(MO_SL
))
2432 GEN_QEMU_LOAD_TL(ld16ur
, BSWAP_MEMOP(MO_UW
))
2433 GEN_QEMU_LOAD_TL(ld32ur
, BSWAP_MEMOP(MO_UL
))
2435 #define GEN_QEMU_LOAD_64(ldop, op) \
2436 static void glue(gen_qemu_, glue(ldop, _i64))(DisasContext *ctx, \
2440 tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, op); \
2443 GEN_QEMU_LOAD_64(ld8u
, DEF_MEMOP(MO_UB
))
2444 GEN_QEMU_LOAD_64(ld16u
, DEF_MEMOP(MO_UW
))
2445 GEN_QEMU_LOAD_64(ld32u
, DEF_MEMOP(MO_UL
))
2446 GEN_QEMU_LOAD_64(ld32s
, DEF_MEMOP(MO_SL
))
2447 GEN_QEMU_LOAD_64(ld64
, DEF_MEMOP(MO_Q
))
2449 #if defined(TARGET_PPC64)
2450 GEN_QEMU_LOAD_64(ld64ur
, BSWAP_MEMOP(MO_Q
))
2453 #define GEN_QEMU_STORE_TL(stop, op) \
2454 static void glue(gen_qemu_, stop)(DisasContext *ctx, \
2458 tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, op); \
2461 GEN_QEMU_STORE_TL(st8
, DEF_MEMOP(MO_UB
))
2462 GEN_QEMU_STORE_TL(st16
, DEF_MEMOP(MO_UW
))
2463 GEN_QEMU_STORE_TL(st32
, DEF_MEMOP(MO_UL
))
2465 GEN_QEMU_STORE_TL(st16r
, BSWAP_MEMOP(MO_UW
))
2466 GEN_QEMU_STORE_TL(st32r
, BSWAP_MEMOP(MO_UL
))
2468 #define GEN_QEMU_STORE_64(stop, op) \
2469 static void glue(gen_qemu_, glue(stop, _i64))(DisasContext *ctx, \
2473 tcg_gen_qemu_st_i64(val, addr, ctx->mem_idx, op); \
2476 GEN_QEMU_STORE_64(st8
, DEF_MEMOP(MO_UB
))
2477 GEN_QEMU_STORE_64(st16
, DEF_MEMOP(MO_UW
))
2478 GEN_QEMU_STORE_64(st32
, DEF_MEMOP(MO_UL
))
2479 GEN_QEMU_STORE_64(st64
, DEF_MEMOP(MO_Q
))
2481 #if defined(TARGET_PPC64)
2482 GEN_QEMU_STORE_64(st64r
, BSWAP_MEMOP(MO_Q
))
2485 #define GEN_LD(name, ldop, opc, type) \
2486 static void glue(gen_, name)(DisasContext *ctx) \
2489 gen_set_access_type(ctx, ACCESS_INT); \
2490 EA = tcg_temp_new(); \
2491 gen_addr_imm_index(ctx, EA, 0); \
2492 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2493 tcg_temp_free(EA); \
2496 #define GEN_LDU(name, ldop, opc, type) \
2497 static void glue(gen_, name##u)(DisasContext *ctx) \
2500 if (unlikely(rA(ctx->opcode) == 0 || \
2501 rA(ctx->opcode) == rD(ctx->opcode))) { \
2502 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2505 gen_set_access_type(ctx, ACCESS_INT); \
2506 EA = tcg_temp_new(); \
2507 if (type == PPC_64B) \
2508 gen_addr_imm_index(ctx, EA, 0x03); \
2510 gen_addr_imm_index(ctx, EA, 0); \
2511 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2512 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2513 tcg_temp_free(EA); \
2516 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2517 static void glue(gen_, name##ux)(DisasContext *ctx) \
2520 if (unlikely(rA(ctx->opcode) == 0 || \
2521 rA(ctx->opcode) == rD(ctx->opcode))) { \
2522 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2525 gen_set_access_type(ctx, ACCESS_INT); \
2526 EA = tcg_temp_new(); \
2527 gen_addr_reg_index(ctx, EA); \
2528 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2529 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2530 tcg_temp_free(EA); \
2533 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
2534 static void glue(gen_, name##x)(DisasContext *ctx) \
2538 gen_set_access_type(ctx, ACCESS_INT); \
2539 EA = tcg_temp_new(); \
2540 gen_addr_reg_index(ctx, EA); \
2541 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2542 tcg_temp_free(EA); \
2545 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2546 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
2548 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
2549 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
2551 #define GEN_LDS(name, ldop, op, type) \
2552 GEN_LD(name, ldop, op | 0x20, type); \
2553 GEN_LDU(name, ldop, op | 0x21, type); \
2554 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2555 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2557 /* lbz lbzu lbzux lbzx */
2558 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2559 /* lha lhau lhaux lhax */
2560 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2561 /* lhz lhzu lhzux lhzx */
2562 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2563 /* lwz lwzu lwzux lwzx */
2564 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2565 #if defined(TARGET_PPC64)
2567 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2569 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2571 GEN_LDUX(ld
, ld64_i64
, 0x15, 0x01, PPC_64B
);
2573 GEN_LDX(ld
, ld64_i64
, 0x15, 0x00, PPC_64B
);
2575 /* CI load/store variants */
2576 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
2577 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x15, PPC_CILDST
)
2578 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
2579 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
2581 static void gen_ld(DisasContext
*ctx
)
2584 if (Rc(ctx
->opcode
)) {
2585 if (unlikely(rA(ctx
->opcode
) == 0 ||
2586 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2587 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2591 gen_set_access_type(ctx
, ACCESS_INT
);
2592 EA
= tcg_temp_new();
2593 gen_addr_imm_index(ctx
, EA
, 0x03);
2594 if (ctx
->opcode
& 0x02) {
2595 /* lwa (lwau is undefined) */
2596 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2599 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2601 if (Rc(ctx
->opcode
))
2602 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2607 static void gen_lq(DisasContext
*ctx
)
2612 /* lq is a legal user mode instruction starting in ISA 2.07 */
2613 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2614 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2616 if (!legal_in_user_mode
&& ctx
->pr
) {
2617 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2621 if (!le_is_supported
&& ctx
->le_mode
) {
2622 gen_align_no_le(ctx
);
2625 ra
= rA(ctx
->opcode
);
2626 rd
= rD(ctx
->opcode
);
2627 if (unlikely((rd
& 1) || rd
== ra
)) {
2628 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2632 gen_set_access_type(ctx
, ACCESS_INT
);
2633 EA
= tcg_temp_new();
2634 gen_addr_imm_index(ctx
, EA
, 0x0F);
2636 /* We only need to swap high and low halves. gen_qemu_ld64_i64 does
2637 necessary 64-bit byteswap already. */
2638 if (unlikely(ctx
->le_mode
)) {
2639 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rd
+ 1], EA
);
2640 gen_addr_add(ctx
, EA
, EA
, 8);
2641 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rd
], EA
);
2643 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rd
], EA
);
2644 gen_addr_add(ctx
, EA
, EA
, 8);
2645 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rd
+ 1], EA
);
2651 /*** Integer store ***/
2652 #define GEN_ST(name, stop, opc, type) \
2653 static void glue(gen_, name)(DisasContext *ctx) \
2656 gen_set_access_type(ctx, ACCESS_INT); \
2657 EA = tcg_temp_new(); \
2658 gen_addr_imm_index(ctx, EA, 0); \
2659 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2660 tcg_temp_free(EA); \
2663 #define GEN_STU(name, stop, opc, type) \
2664 static void glue(gen_, stop##u)(DisasContext *ctx) \
2667 if (unlikely(rA(ctx->opcode) == 0)) { \
2668 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2671 gen_set_access_type(ctx, ACCESS_INT); \
2672 EA = tcg_temp_new(); \
2673 if (type == PPC_64B) \
2674 gen_addr_imm_index(ctx, EA, 0x03); \
2676 gen_addr_imm_index(ctx, EA, 0); \
2677 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2678 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2679 tcg_temp_free(EA); \
2682 #define GEN_STUX(name, stop, opc2, opc3, type) \
2683 static void glue(gen_, name##ux)(DisasContext *ctx) \
2686 if (unlikely(rA(ctx->opcode) == 0)) { \
2687 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2690 gen_set_access_type(ctx, ACCESS_INT); \
2691 EA = tcg_temp_new(); \
2692 gen_addr_reg_index(ctx, EA); \
2693 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2694 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2695 tcg_temp_free(EA); \
2698 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
2699 static void glue(gen_, name##x)(DisasContext *ctx) \
2703 gen_set_access_type(ctx, ACCESS_INT); \
2704 EA = tcg_temp_new(); \
2705 gen_addr_reg_index(ctx, EA); \
2706 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2707 tcg_temp_free(EA); \
2709 #define GEN_STX(name, stop, opc2, opc3, type) \
2710 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
2712 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
2713 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
2715 #define GEN_STS(name, stop, op, type) \
2716 GEN_ST(name, stop, op | 0x20, type); \
2717 GEN_STU(name, stop, op | 0x21, type); \
2718 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2719 GEN_STX(name, stop, 0x17, op | 0x00, type)
2721 /* stb stbu stbux stbx */
2722 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2723 /* sth sthu sthux sthx */
2724 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2725 /* stw stwu stwux stwx */
2726 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2727 #if defined(TARGET_PPC64)
2728 GEN_STUX(std
, st64_i64
, 0x15, 0x05, PPC_64B
);
2729 GEN_STX(std
, st64_i64
, 0x15, 0x04, PPC_64B
);
2730 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
2731 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
2732 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
2733 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
2735 static void gen_std(DisasContext
*ctx
)
2740 rs
= rS(ctx
->opcode
);
2741 if ((ctx
->opcode
& 0x3) == 0x2) { /* stq */
2742 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2743 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2745 if (!(ctx
->insns_flags
& PPC_64BX
)) {
2746 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2749 if (!legal_in_user_mode
&& ctx
->pr
) {
2750 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2754 if (!le_is_supported
&& ctx
->le_mode
) {
2755 gen_align_no_le(ctx
);
2759 if (unlikely(rs
& 1)) {
2760 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2763 gen_set_access_type(ctx
, ACCESS_INT
);
2764 EA
= tcg_temp_new();
2765 gen_addr_imm_index(ctx
, EA
, 0x03);
2767 /* We only need to swap high and low halves. gen_qemu_st64_i64 does
2768 necessary 64-bit byteswap already. */
2769 if (unlikely(ctx
->le_mode
)) {
2770 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
+ 1], EA
);
2771 gen_addr_add(ctx
, EA
, EA
, 8);
2772 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
2774 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
2775 gen_addr_add(ctx
, EA
, EA
, 8);
2776 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
+ 1], EA
);
2781 if (Rc(ctx
->opcode
)) {
2782 if (unlikely(rA(ctx
->opcode
) == 0)) {
2783 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2787 gen_set_access_type(ctx
, ACCESS_INT
);
2788 EA
= tcg_temp_new();
2789 gen_addr_imm_index(ctx
, EA
, 0x03);
2790 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
2791 if (Rc(ctx
->opcode
))
2792 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2797 /*** Integer load and store with byte reverse ***/
2800 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2803 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2805 #if defined(TARGET_PPC64)
2807 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
2809 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
2810 #endif /* TARGET_PPC64 */
2813 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2815 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2817 /*** Integer load and store multiple ***/
2820 static void gen_lmw(DisasContext
*ctx
)
2826 gen_align_no_le(ctx
);
2829 gen_set_access_type(ctx
, ACCESS_INT
);
2830 t0
= tcg_temp_new();
2831 t1
= tcg_const_i32(rD(ctx
->opcode
));
2832 gen_addr_imm_index(ctx
, t0
, 0);
2833 gen_helper_lmw(cpu_env
, t0
, t1
);
2835 tcg_temp_free_i32(t1
);
2839 static void gen_stmw(DisasContext
*ctx
)
2845 gen_align_no_le(ctx
);
2848 gen_set_access_type(ctx
, ACCESS_INT
);
2849 t0
= tcg_temp_new();
2850 t1
= tcg_const_i32(rS(ctx
->opcode
));
2851 gen_addr_imm_index(ctx
, t0
, 0);
2852 gen_helper_stmw(cpu_env
, t0
, t1
);
2854 tcg_temp_free_i32(t1
);
2857 /*** Integer load and store strings ***/
2860 /* PowerPC32 specification says we must generate an exception if
2861 * rA is in the range of registers to be loaded.
2862 * In an other hand, IBM says this is valid, but rA won't be loaded.
2863 * For now, I'll follow the spec...
2865 static void gen_lswi(DisasContext
*ctx
)
2869 int nb
= NB(ctx
->opcode
);
2870 int start
= rD(ctx
->opcode
);
2871 int ra
= rA(ctx
->opcode
);
2875 gen_align_no_le(ctx
);
2880 nr
= DIV_ROUND_UP(nb
, 4);
2881 if (unlikely(lsw_reg_in_range(start
, nr
, ra
))) {
2882 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
2885 gen_set_access_type(ctx
, ACCESS_INT
);
2886 t0
= tcg_temp_new();
2887 gen_addr_register(ctx
, t0
);
2888 t1
= tcg_const_i32(nb
);
2889 t2
= tcg_const_i32(start
);
2890 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
2892 tcg_temp_free_i32(t1
);
2893 tcg_temp_free_i32(t2
);
2897 static void gen_lswx(DisasContext
*ctx
)
2900 TCGv_i32 t1
, t2
, t3
;
2903 gen_align_no_le(ctx
);
2906 gen_set_access_type(ctx
, ACCESS_INT
);
2907 t0
= tcg_temp_new();
2908 gen_addr_reg_index(ctx
, t0
);
2909 t1
= tcg_const_i32(rD(ctx
->opcode
));
2910 t2
= tcg_const_i32(rA(ctx
->opcode
));
2911 t3
= tcg_const_i32(rB(ctx
->opcode
));
2912 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
2914 tcg_temp_free_i32(t1
);
2915 tcg_temp_free_i32(t2
);
2916 tcg_temp_free_i32(t3
);
2920 static void gen_stswi(DisasContext
*ctx
)
2924 int nb
= NB(ctx
->opcode
);
2927 gen_align_no_le(ctx
);
2930 gen_set_access_type(ctx
, ACCESS_INT
);
2931 t0
= tcg_temp_new();
2932 gen_addr_register(ctx
, t0
);
2935 t1
= tcg_const_i32(nb
);
2936 t2
= tcg_const_i32(rS(ctx
->opcode
));
2937 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
2939 tcg_temp_free_i32(t1
);
2940 tcg_temp_free_i32(t2
);
2944 static void gen_stswx(DisasContext
*ctx
)
2950 gen_align_no_le(ctx
);
2953 gen_set_access_type(ctx
, ACCESS_INT
);
2954 t0
= tcg_temp_new();
2955 gen_addr_reg_index(ctx
, t0
);
2956 t1
= tcg_temp_new_i32();
2957 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
2958 tcg_gen_andi_i32(t1
, t1
, 0x7F);
2959 t2
= tcg_const_i32(rS(ctx
->opcode
));
2960 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
2962 tcg_temp_free_i32(t1
);
2963 tcg_temp_free_i32(t2
);
2966 /*** Memory synchronisation ***/
2968 static void gen_eieio(DisasContext
*ctx
)
2970 tcg_gen_mb(TCG_MO_LD_ST
| TCG_BAR_SC
);
2973 #if !defined(CONFIG_USER_ONLY)
2974 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
)
2979 if (!ctx
->lazy_tlb_flush
) {
2982 l
= gen_new_label();
2983 t
= tcg_temp_new_i32();
2984 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
2985 tcg_gen_brcondi_i32(TCG_COND_EQ
, t
, 0, l
);
2987 gen_helper_check_tlb_flush_global(cpu_env
);
2989 gen_helper_check_tlb_flush_local(cpu_env
);
2992 tcg_temp_free_i32(t
);
2995 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
) { }
2999 static void gen_isync(DisasContext
*ctx
)
3002 * We need to check for a pending TLB flush. This can only happen in
3003 * kernel mode however so check MSR_PR
3006 gen_check_tlb_flush(ctx
, false);
3008 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
3009 gen_stop_exception(ctx
);
3012 #define MEMOP_GET_SIZE(x) (1 << ((x) & MO_SIZE))
3014 #define LARX(name, memop) \
3015 static void gen_##name(DisasContext *ctx) \
3018 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3019 int len = MEMOP_GET_SIZE(memop); \
3020 gen_set_access_type(ctx, ACCESS_RES); \
3021 t0 = tcg_temp_local_new(); \
3022 gen_addr_reg_index(ctx, t0); \
3024 gen_check_align(ctx, t0, (len)-1); \
3026 tcg_gen_qemu_ld_tl(gpr, t0, ctx->mem_idx, memop); \
3027 tcg_gen_mov_tl(cpu_reserve, t0); \
3028 tcg_gen_mov_tl(cpu_reserve_val, gpr); \
3029 tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); \
3030 tcg_temp_free(t0); \
3034 LARX(lbarx
, DEF_MEMOP(MO_UB
))
3035 LARX(lharx
, DEF_MEMOP(MO_UW
))
3036 LARX(lwarx
, DEF_MEMOP(MO_UL
))
3038 #define LD_ATOMIC(name, memop, tp, op, eop) \
3039 static void gen_##name(DisasContext *ctx) \
3041 int len = MEMOP_GET_SIZE(memop); \
3042 uint32_t gpr_FC = FC(ctx->opcode); \
3043 TCGv EA = tcg_temp_local_new(); \
3046 gen_addr_register(ctx, EA); \
3048 gen_check_align(ctx, EA, len - 1); \
3050 t0 = tcg_temp_new_##tp(); \
3051 t1 = tcg_temp_new_##tp(); \
3052 tcg_gen_##op(t0, cpu_gpr[rD(ctx->opcode) + 1]); \
3055 case 0: /* Fetch and add */ \
3056 tcg_gen_atomic_fetch_add_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3058 case 1: /* Fetch and xor */ \
3059 tcg_gen_atomic_fetch_xor_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3061 case 2: /* Fetch and or */ \
3062 tcg_gen_atomic_fetch_or_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3064 case 3: /* Fetch and 'and' */ \
3065 tcg_gen_atomic_fetch_and_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3067 case 8: /* Swap */ \
3068 tcg_gen_atomic_xchg_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3070 case 4: /* Fetch and max unsigned */ \
3071 case 5: /* Fetch and max signed */ \
3072 case 6: /* Fetch and min unsigned */ \
3073 case 7: /* Fetch and min signed */ \
3074 case 16: /* compare and swap not equal */ \
3075 case 24: /* Fetch and increment bounded */ \
3076 case 25: /* Fetch and increment equal */ \
3077 case 28: /* Fetch and decrement bounded */ \
3081 /* invoke data storage error handler */ \
3082 gen_exception_err(ctx, POWERPC_EXCP_DSI, POWERPC_EXCP_INVAL); \
3084 tcg_gen_##eop(cpu_gpr[rD(ctx->opcode)], t1); \
3085 tcg_temp_free_##tp(t0); \
3086 tcg_temp_free_##tp(t1); \
3087 tcg_temp_free(EA); \
3090 LD_ATOMIC(lwat
, DEF_MEMOP(MO_UL
), i32
, trunc_tl_i32
, extu_i32_tl
)
3091 #if defined(TARGET_PPC64)
3092 LD_ATOMIC(ldat
, DEF_MEMOP(MO_Q
), i64
, mov_i64
, mov_i64
)
3095 #define ST_ATOMIC(name, memop, tp, op) \
3096 static void gen_##name(DisasContext *ctx) \
3098 int len = MEMOP_GET_SIZE(memop); \
3099 uint32_t gpr_FC = FC(ctx->opcode); \
3100 TCGv EA = tcg_temp_local_new(); \
3103 gen_addr_register(ctx, EA); \
3105 gen_check_align(ctx, EA, len - 1); \
3107 t0 = tcg_temp_new_##tp(); \
3108 t1 = tcg_temp_new_##tp(); \
3109 tcg_gen_##op(t0, cpu_gpr[rD(ctx->opcode) + 1]); \
3112 case 0: /* add and Store */ \
3113 tcg_gen_atomic_add_fetch_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3115 case 1: /* xor and Store */ \
3116 tcg_gen_atomic_xor_fetch_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3118 case 2: /* Or and Store */ \
3119 tcg_gen_atomic_or_fetch_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3121 case 3: /* 'and' and Store */ \
3122 tcg_gen_atomic_and_fetch_##tp(t1, EA, t0, ctx->mem_idx, memop); \
3124 case 4: /* Store max unsigned */ \
3125 case 5: /* Store max signed */ \
3126 case 6: /* Store min unsigned */ \
3127 case 7: /* Store min signed */ \
3128 case 24: /* Store twin */ \
3132 /* invoke data storage error handler */ \
3133 gen_exception_err(ctx, POWERPC_EXCP_DSI, POWERPC_EXCP_INVAL); \
3135 tcg_temp_free_##tp(t0); \
3136 tcg_temp_free_##tp(t1); \
3137 tcg_temp_free(EA); \
3140 ST_ATOMIC(stwat
, DEF_MEMOP(MO_UL
), i32
, trunc_tl_i32
)
3141 #if defined(TARGET_PPC64)
3142 ST_ATOMIC(stdat
, DEF_MEMOP(MO_Q
), i64
, mov_i64
)
3145 #if defined(CONFIG_USER_ONLY)
3146 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3149 TCGv t0
= tcg_temp_new();
3151 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3152 tcg_gen_movi_tl(t0
, (MEMOP_GET_SIZE(memop
) << 5) | reg
);
3153 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3155 gen_exception_err(ctx
, POWERPC_EXCP_STCX
, 0);
3158 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3161 TCGLabel
*l1
= gen_new_label();
3162 TCGLabel
*l2
= gen_new_label();
3165 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3167 t0
= tcg_temp_new();
3168 tcg_gen_atomic_cmpxchg_tl(t0
, cpu_reserve
, cpu_reserve_val
,
3169 cpu_gpr
[reg
], ctx
->mem_idx
,
3170 DEF_MEMOP(memop
) | MO_ALIGN
);
3171 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, t0
, cpu_reserve_val
);
3172 tcg_gen_shli_tl(t0
, t0
, CRF_EQ_BIT
);
3173 tcg_gen_or_tl(t0
, t0
, cpu_so
);
3174 tcg_gen_trunc_tl_i32(cpu_crf
[0], t0
);
3180 /* Address mismatch implies failure. But we still need to provide the
3181 memory barrier semantics of the instruction. */
3182 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
3183 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3186 tcg_gen_movi_tl(cpu_reserve
, -1);
3190 #define STCX(name, memop) \
3191 static void gen_##name(DisasContext *ctx) \
3194 int len = MEMOP_GET_SIZE(memop); \
3195 gen_set_access_type(ctx, ACCESS_RES); \
3196 t0 = tcg_temp_local_new(); \
3197 gen_addr_reg_index(ctx, t0); \
3199 gen_check_align(ctx, t0, (len) - 1); \
3201 gen_conditional_store(ctx, t0, rS(ctx->opcode), memop); \
3202 tcg_temp_free(t0); \
3205 STCX(stbcx_
, DEF_MEMOP(MO_UB
))
3206 STCX(sthcx_
, DEF_MEMOP(MO_UW
))
3207 STCX(stwcx_
, DEF_MEMOP(MO_UL
))
3209 #if defined(TARGET_PPC64)
3211 LARX(ldarx
, DEF_MEMOP(MO_Q
))
3213 STCX(stdcx_
, DEF_MEMOP(MO_Q
))
3216 static void gen_lqarx(DisasContext
*ctx
)
3219 int rd
= rD(ctx
->opcode
);
3222 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
3223 (rd
== rB(ctx
->opcode
)))) {
3224 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3228 gen_set_access_type(ctx
, ACCESS_RES
);
3229 EA
= tcg_temp_local_new();
3230 gen_addr_reg_index(ctx
, EA
);
3231 gen_check_align(ctx
, EA
, 15);
3232 if (unlikely(ctx
->le_mode
)) {
3233 gpr1
= cpu_gpr
[rd
+1];
3237 gpr2
= cpu_gpr
[rd
+1];
3239 tcg_gen_qemu_ld_i64(gpr1
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_Q
));
3240 tcg_gen_mov_tl(cpu_reserve
, EA
);
3241 gen_addr_add(ctx
, EA
, EA
, 8);
3242 tcg_gen_qemu_ld_i64(gpr2
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_Q
));
3244 tcg_gen_st_tl(gpr1
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3245 tcg_gen_st_tl(gpr2
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
3250 static void gen_stqcx_(DisasContext
*ctx
)
3253 int reg
= rS(ctx
->opcode
);
3255 #if !defined(CONFIG_USER_ONLY)
3260 if (unlikely((rD(ctx
->opcode
) & 1))) {
3261 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3264 gen_set_access_type(ctx
, ACCESS_RES
);
3265 EA
= tcg_temp_local_new();
3266 gen_addr_reg_index(ctx
, EA
);
3268 gen_check_align(ctx
, EA
, (len
) - 1);
3271 #if defined(CONFIG_USER_ONLY)
3272 gen_conditional_store(ctx
, EA
, reg
, 16);
3274 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3275 l1
= gen_new_label();
3276 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3277 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], CRF_EQ
);
3279 if (unlikely(ctx
->le_mode
)) {
3280 gpr1
= cpu_gpr
[reg
+ 1];
3281 gpr2
= cpu_gpr
[reg
];
3283 gpr1
= cpu_gpr
[reg
];
3284 gpr2
= cpu_gpr
[reg
+ 1];
3286 tcg_gen_qemu_st_tl(gpr1
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_Q
));
3287 gen_addr_add(ctx
, EA
, EA
, 8);
3288 tcg_gen_qemu_st_tl(gpr2
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_Q
));
3291 tcg_gen_movi_tl(cpu_reserve
, -1);
3296 #endif /* defined(TARGET_PPC64) */
3299 static void gen_sync(DisasContext
*ctx
)
3301 uint32_t l
= (ctx
->opcode
>> 21) & 3;
3304 * We may need to check for a pending TLB flush.
3306 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
3308 * Additionally, this can only happen in kernel mode however so
3309 * check MSR_PR as well.
3311 if (((l
== 2) || !(ctx
->insns_flags
& PPC_64B
)) && !ctx
->pr
) {
3312 gen_check_tlb_flush(ctx
, true);
3314 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
3318 static void gen_wait(DisasContext
*ctx
)
3320 TCGv_i32 t0
= tcg_const_i32(1);
3321 tcg_gen_st_i32(t0
, cpu_env
,
3322 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3323 tcg_temp_free_i32(t0
);
3324 /* Stop translation, as the CPU is supposed to sleep from now */
3325 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3328 #if defined(TARGET_PPC64)
3329 static void gen_doze(DisasContext
*ctx
)
3331 #if defined(CONFIG_USER_ONLY)
3337 t
= tcg_const_i32(PPC_PM_DOZE
);
3338 gen_helper_pminsn(cpu_env
, t
);
3339 tcg_temp_free_i32(t
);
3340 gen_stop_exception(ctx
);
3341 #endif /* defined(CONFIG_USER_ONLY) */
3344 static void gen_nap(DisasContext
*ctx
)
3346 #if defined(CONFIG_USER_ONLY)
3352 t
= tcg_const_i32(PPC_PM_NAP
);
3353 gen_helper_pminsn(cpu_env
, t
);
3354 tcg_temp_free_i32(t
);
3355 gen_stop_exception(ctx
);
3356 #endif /* defined(CONFIG_USER_ONLY) */
3359 static void gen_stop(DisasContext
*ctx
)
3364 static void gen_sleep(DisasContext
*ctx
)
3366 #if defined(CONFIG_USER_ONLY)
3372 t
= tcg_const_i32(PPC_PM_SLEEP
);
3373 gen_helper_pminsn(cpu_env
, t
);
3374 tcg_temp_free_i32(t
);
3375 gen_stop_exception(ctx
);
3376 #endif /* defined(CONFIG_USER_ONLY) */
3379 static void gen_rvwinkle(DisasContext
*ctx
)
3381 #if defined(CONFIG_USER_ONLY)
3387 t
= tcg_const_i32(PPC_PM_RVWINKLE
);
3388 gen_helper_pminsn(cpu_env
, t
);
3389 tcg_temp_free_i32(t
);
3390 gen_stop_exception(ctx
);
3391 #endif /* defined(CONFIG_USER_ONLY) */
3393 #endif /* #if defined(TARGET_PPC64) */
3395 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3397 #if defined(TARGET_PPC64)
3399 tcg_gen_movi_tl(cpu_cfar
, nip
);
3403 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
3405 if (unlikely(ctx
->singlestep_enabled
)) {
3409 #ifndef CONFIG_USER_ONLY
3410 return (ctx
->base
.tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
3417 static void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3419 if (NARROW_MODE(ctx
)) {
3420 dest
= (uint32_t) dest
;
3422 if (use_goto_tb(ctx
, dest
)) {
3424 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3425 tcg_gen_exit_tb((uintptr_t)ctx
->base
.tb
+ n
);
3427 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3428 if (unlikely(ctx
->singlestep_enabled
)) {
3429 if ((ctx
->singlestep_enabled
&
3430 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3431 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3432 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3433 gen_exception_nip(ctx
, POWERPC_EXCP_TRACE
, dest
);
3435 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3436 gen_debug_exception(ctx
);
3439 tcg_gen_lookup_and_goto_ptr();
3443 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3445 if (NARROW_MODE(ctx
)) {
3446 nip
= (uint32_t)nip
;
3448 tcg_gen_movi_tl(cpu_lr
, nip
);
3452 static void gen_b(DisasContext
*ctx
)
3454 target_ulong li
, target
;
3456 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3457 /* sign extend LI */
3458 li
= LI(ctx
->opcode
);
3459 li
= (li
^ 0x02000000) - 0x02000000;
3460 if (likely(AA(ctx
->opcode
) == 0)) {
3461 target
= ctx
->base
.pc_next
+ li
- 4;
3465 if (LK(ctx
->opcode
)) {
3466 gen_setlr(ctx
, ctx
->base
.pc_next
);
3468 gen_update_cfar(ctx
, ctx
->base
.pc_next
- 4);
3469 gen_goto_tb(ctx
, 0, target
);
3477 static void gen_bcond(DisasContext
*ctx
, int type
)
3479 uint32_t bo
= BO(ctx
->opcode
);
3483 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3484 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
3485 target
= tcg_temp_local_new();
3486 if (type
== BCOND_CTR
)
3487 tcg_gen_mov_tl(target
, cpu_ctr
);
3488 else if (type
== BCOND_TAR
)
3489 gen_load_spr(target
, SPR_TAR
);
3491 tcg_gen_mov_tl(target
, cpu_lr
);
3495 if (LK(ctx
->opcode
))
3496 gen_setlr(ctx
, ctx
->base
.pc_next
);
3497 l1
= gen_new_label();
3498 if ((bo
& 0x4) == 0) {
3499 /* Decrement and test CTR */
3500 TCGv temp
= tcg_temp_new();
3501 if (unlikely(type
== BCOND_CTR
)) {
3502 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3505 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3506 if (NARROW_MODE(ctx
)) {
3507 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3509 tcg_gen_mov_tl(temp
, cpu_ctr
);
3512 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3514 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3516 tcg_temp_free(temp
);
3518 if ((bo
& 0x10) == 0) {
3520 uint32_t bi
= BI(ctx
->opcode
);
3521 uint32_t mask
= 0x08 >> (bi
& 0x03);
3522 TCGv_i32 temp
= tcg_temp_new_i32();
3525 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3526 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3528 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3529 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3531 tcg_temp_free_i32(temp
);
3533 gen_update_cfar(ctx
, ctx
->base
.pc_next
- 4);
3534 if (type
== BCOND_IM
) {
3535 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3536 if (likely(AA(ctx
->opcode
) == 0)) {
3537 gen_goto_tb(ctx
, 0, ctx
->base
.pc_next
+ li
- 4);
3539 gen_goto_tb(ctx
, 0, li
);
3542 if (NARROW_MODE(ctx
)) {
3543 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3545 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3547 tcg_gen_lookup_and_goto_ptr();
3548 tcg_temp_free(target
);
3550 if ((bo
& 0x14) != 0x14) {
3552 gen_goto_tb(ctx
, 1, ctx
->base
.pc_next
);
3556 static void gen_bc(DisasContext
*ctx
)
3558 gen_bcond(ctx
, BCOND_IM
);
3561 static void gen_bcctr(DisasContext
*ctx
)
3563 gen_bcond(ctx
, BCOND_CTR
);
3566 static void gen_bclr(DisasContext
*ctx
)
3568 gen_bcond(ctx
, BCOND_LR
);
3571 static void gen_bctar(DisasContext
*ctx
)
3573 gen_bcond(ctx
, BCOND_TAR
);
3576 /*** Condition register logical ***/
3577 #define GEN_CRLOGIC(name, tcg_op, opc) \
3578 static void glue(gen_, name)(DisasContext *ctx) \
3583 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3584 t0 = tcg_temp_new_i32(); \
3586 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3588 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3590 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3591 t1 = tcg_temp_new_i32(); \
3592 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3594 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3596 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3598 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3599 tcg_op(t0, t0, t1); \
3600 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
3601 tcg_gen_andi_i32(t0, t0, bitmask); \
3602 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3603 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3604 tcg_temp_free_i32(t0); \
3605 tcg_temp_free_i32(t1); \
3609 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3611 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3613 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3615 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3617 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3619 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3621 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3623 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3626 static void gen_mcrf(DisasContext
*ctx
)
3628 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3631 /*** System linkage ***/
3633 /* rfi (supervisor only) */
3634 static void gen_rfi(DisasContext
*ctx
)
3636 #if defined(CONFIG_USER_ONLY)
3639 /* This instruction doesn't exist anymore on 64-bit server
3640 * processors compliant with arch 2.x
3642 if (ctx
->insns_flags
& PPC_SEGMENT_64B
) {
3643 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3646 /* Restore CPU state */
3648 gen_update_cfar(ctx
, ctx
->base
.pc_next
- 4);
3649 gen_helper_rfi(cpu_env
);
3650 gen_sync_exception(ctx
);
3654 #if defined(TARGET_PPC64)
3655 static void gen_rfid(DisasContext
*ctx
)
3657 #if defined(CONFIG_USER_ONLY)
3660 /* Restore CPU state */
3662 gen_update_cfar(ctx
, ctx
->base
.pc_next
- 4);
3663 gen_helper_rfid(cpu_env
);
3664 gen_sync_exception(ctx
);
3668 static void gen_hrfid(DisasContext
*ctx
)
3670 #if defined(CONFIG_USER_ONLY)
3673 /* Restore CPU state */
3675 gen_helper_hrfid(cpu_env
);
3676 gen_sync_exception(ctx
);
3682 #if defined(CONFIG_USER_ONLY)
3683 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3685 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3687 static void gen_sc(DisasContext
*ctx
)
3691 lev
= (ctx
->opcode
>> 5) & 0x7F;
3692 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3697 /* Check for unconditional traps (always or never) */
3698 static bool check_unconditional_trap(DisasContext
*ctx
)
3701 if (TO(ctx
->opcode
) == 0) {
3705 if (TO(ctx
->opcode
) == 31) {
3706 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
3713 static void gen_tw(DisasContext
*ctx
)
3717 if (check_unconditional_trap(ctx
)) {
3720 t0
= tcg_const_i32(TO(ctx
->opcode
));
3721 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3723 tcg_temp_free_i32(t0
);
3727 static void gen_twi(DisasContext
*ctx
)
3732 if (check_unconditional_trap(ctx
)) {
3735 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3736 t1
= tcg_const_i32(TO(ctx
->opcode
));
3737 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3739 tcg_temp_free_i32(t1
);
3742 #if defined(TARGET_PPC64)
3744 static void gen_td(DisasContext
*ctx
)
3748 if (check_unconditional_trap(ctx
)) {
3751 t0
= tcg_const_i32(TO(ctx
->opcode
));
3752 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3754 tcg_temp_free_i32(t0
);
3758 static void gen_tdi(DisasContext
*ctx
)
3763 if (check_unconditional_trap(ctx
)) {
3766 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3767 t1
= tcg_const_i32(TO(ctx
->opcode
));
3768 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3770 tcg_temp_free_i32(t1
);
3774 /*** Processor control ***/
3776 static void gen_read_xer(DisasContext
*ctx
, TCGv dst
)
3778 TCGv t0
= tcg_temp_new();
3779 TCGv t1
= tcg_temp_new();
3780 TCGv t2
= tcg_temp_new();
3781 tcg_gen_mov_tl(dst
, cpu_xer
);
3782 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
3783 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
3784 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
3785 tcg_gen_or_tl(t0
, t0
, t1
);
3786 tcg_gen_or_tl(dst
, dst
, t2
);
3787 tcg_gen_or_tl(dst
, dst
, t0
);
3788 if (is_isa300(ctx
)) {
3789 tcg_gen_shli_tl(t0
, cpu_ov32
, XER_OV32
);
3790 tcg_gen_or_tl(dst
, dst
, t0
);
3791 tcg_gen_shli_tl(t0
, cpu_ca32
, XER_CA32
);
3792 tcg_gen_or_tl(dst
, dst
, t0
);
3799 static void gen_write_xer(TCGv src
)
3801 /* Write all flags, while reading back check for isa300 */
3802 tcg_gen_andi_tl(cpu_xer
, src
,
3804 (1u << XER_OV
) | (1u << XER_OV32
) |
3805 (1u << XER_CA
) | (1u << XER_CA32
)));
3806 tcg_gen_extract_tl(cpu_ov32
, src
, XER_OV32
, 1);
3807 tcg_gen_extract_tl(cpu_ca32
, src
, XER_CA32
, 1);
3808 tcg_gen_extract_tl(cpu_so
, src
, XER_SO
, 1);
3809 tcg_gen_extract_tl(cpu_ov
, src
, XER_OV
, 1);
3810 tcg_gen_extract_tl(cpu_ca
, src
, XER_CA
, 1);
3814 static void gen_mcrxr(DisasContext
*ctx
)
3816 TCGv_i32 t0
= tcg_temp_new_i32();
3817 TCGv_i32 t1
= tcg_temp_new_i32();
3818 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
3820 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
3821 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
3822 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
3823 tcg_gen_shli_i32(t0
, t0
, 3);
3824 tcg_gen_shli_i32(t1
, t1
, 2);
3825 tcg_gen_shli_i32(dst
, dst
, 1);
3826 tcg_gen_or_i32(dst
, dst
, t0
);
3827 tcg_gen_or_i32(dst
, dst
, t1
);
3828 tcg_temp_free_i32(t0
);
3829 tcg_temp_free_i32(t1
);
3831 tcg_gen_movi_tl(cpu_so
, 0);
3832 tcg_gen_movi_tl(cpu_ov
, 0);
3833 tcg_gen_movi_tl(cpu_ca
, 0);
3838 static void gen_mcrxrx(DisasContext
*ctx
)
3840 TCGv t0
= tcg_temp_new();
3841 TCGv t1
= tcg_temp_new();
3842 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
3844 /* copy OV and OV32 */
3845 tcg_gen_shli_tl(t0
, cpu_ov
, 1);
3846 tcg_gen_or_tl(t0
, t0
, cpu_ov32
);
3847 tcg_gen_shli_tl(t0
, t0
, 2);
3848 /* copy CA and CA32 */
3849 tcg_gen_shli_tl(t1
, cpu_ca
, 1);
3850 tcg_gen_or_tl(t1
, t1
, cpu_ca32
);
3851 tcg_gen_or_tl(t0
, t0
, t1
);
3852 tcg_gen_trunc_tl_i32(dst
, t0
);
3859 static void gen_mfcr(DisasContext
*ctx
)
3863 if (likely(ctx
->opcode
& 0x00100000)) {
3864 crm
= CRM(ctx
->opcode
);
3865 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3867 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3868 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3869 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3872 TCGv_i32 t0
= tcg_temp_new_i32();
3873 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3874 tcg_gen_shli_i32(t0
, t0
, 4);
3875 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3876 tcg_gen_shli_i32(t0
, t0
, 4);
3877 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3878 tcg_gen_shli_i32(t0
, t0
, 4);
3879 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3880 tcg_gen_shli_i32(t0
, t0
, 4);
3881 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3882 tcg_gen_shli_i32(t0
, t0
, 4);
3883 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3884 tcg_gen_shli_i32(t0
, t0
, 4);
3885 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3886 tcg_gen_shli_i32(t0
, t0
, 4);
3887 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3888 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3889 tcg_temp_free_i32(t0
);
3894 static void gen_mfmsr(DisasContext
*ctx
)
3897 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3900 static void spr_noaccess(DisasContext
*ctx
, int gprn
, int sprn
)
3903 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3904 printf("ERROR: try to access SPR %d !\n", sprn
);
3907 #define SPR_NOACCESS (&spr_noaccess)
3910 static inline void gen_op_mfspr(DisasContext
*ctx
)
3912 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
3913 uint32_t sprn
= SPR(ctx
->opcode
);
3915 #if defined(CONFIG_USER_ONLY)
3916 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3919 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3920 } else if (ctx
->hv
) {
3921 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3923 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3926 if (likely(read_cb
!= NULL
)) {
3927 if (likely(read_cb
!= SPR_NOACCESS
)) {
3928 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3930 /* Privilege exception */
3931 /* This is a hack to avoid warnings when running Linux:
3932 * this OS breaks the PowerPC virtualisation model,
3933 * allowing userland application to read the PVR
3935 if (sprn
!= SPR_PVR
) {
3936 fprintf(stderr
, "Trying to read privileged spr %d (0x%03x) at "
3937 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
3938 if (qemu_log_separate()) {
3939 qemu_log("Trying to read privileged spr %d (0x%03x) at "
3940 TARGET_FMT_lx
"\n", sprn
, sprn
,
3941 ctx
->base
.pc_next
- 4);
3944 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3947 /* ISA 2.07 defines these as no-ops */
3948 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
3949 (sprn
>= 808 && sprn
<= 811)) {
3954 fprintf(stderr
, "Trying to read invalid spr %d (0x%03x) at "
3955 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
3956 if (qemu_log_separate()) {
3957 qemu_log("Trying to read invalid spr %d (0x%03x) at "
3958 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
3961 /* The behaviour depends on MSR:PR and SPR# bit 0x10,
3962 * it can generate a priv, a hv emu or a no-op
3966 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3969 if (ctx
->pr
|| sprn
== 0 || sprn
== 4 || sprn
== 5 || sprn
== 6) {
3970 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3976 static void gen_mfspr(DisasContext
*ctx
)
3982 static void gen_mftb(DisasContext
*ctx
)
3988 static void gen_mtcrf(DisasContext
*ctx
)
3992 crm
= CRM(ctx
->opcode
);
3993 if (likely((ctx
->opcode
& 0x00100000))) {
3994 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
3995 TCGv_i32 temp
= tcg_temp_new_i32();
3997 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3998 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
3999 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4000 tcg_temp_free_i32(temp
);
4003 TCGv_i32 temp
= tcg_temp_new_i32();
4004 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4005 for (crn
= 0 ; crn
< 8 ; crn
++) {
4006 if (crm
& (1 << crn
)) {
4007 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4008 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4011 tcg_temp_free_i32(temp
);
4016 #if defined(TARGET_PPC64)
4017 static void gen_mtmsrd(DisasContext
*ctx
)
4021 #if !defined(CONFIG_USER_ONLY)
4022 if (ctx
->opcode
& 0x00010000) {
4023 /* Special form that does not need any synchronisation */
4024 TCGv t0
= tcg_temp_new();
4025 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4026 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
4027 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4030 /* XXX: we need to update nip before the store
4031 * if we enter power saving mode, we will exit the loop
4032 * directly from ppc_store_msr
4034 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4035 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4036 /* Must stop the translation as machine state (may have) changed */
4037 /* Note that mtmsr is not always defined as context-synchronizing */
4038 gen_stop_exception(ctx
);
4040 #endif /* !defined(CONFIG_USER_ONLY) */
4042 #endif /* defined(TARGET_PPC64) */
4044 static void gen_mtmsr(DisasContext
*ctx
)
4048 #if !defined(CONFIG_USER_ONLY)
4049 if (ctx
->opcode
& 0x00010000) {
4050 /* Special form that does not need any synchronisation */
4051 TCGv t0
= tcg_temp_new();
4052 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4053 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
4054 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4057 TCGv msr
= tcg_temp_new();
4059 /* XXX: we need to update nip before the store
4060 * if we enter power saving mode, we will exit the loop
4061 * directly from ppc_store_msr
4063 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4064 #if defined(TARGET_PPC64)
4065 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4067 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4069 gen_helper_store_msr(cpu_env
, msr
);
4071 /* Must stop the translation as machine state (may have) changed */
4072 /* Note that mtmsr is not always defined as context-synchronizing */
4073 gen_stop_exception(ctx
);
4079 static void gen_mtspr(DisasContext
*ctx
)
4081 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
4082 uint32_t sprn
= SPR(ctx
->opcode
);
4084 #if defined(CONFIG_USER_ONLY)
4085 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4088 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4089 } else if (ctx
->hv
) {
4090 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4092 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4095 if (likely(write_cb
!= NULL
)) {
4096 if (likely(write_cb
!= SPR_NOACCESS
)) {
4097 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4099 /* Privilege exception */
4100 fprintf(stderr
, "Trying to write privileged spr %d (0x%03x) at "
4101 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
4102 if (qemu_log_separate()) {
4103 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4104 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
4106 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4109 /* ISA 2.07 defines these as no-ops */
4110 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4111 (sprn
>= 808 && sprn
<= 811)) {
4117 if (qemu_log_separate()) {
4118 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4119 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
4121 fprintf(stderr
, "Trying to write invalid spr %d (0x%03x) at "
4122 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->base
.pc_next
- 4);
4125 /* The behaviour depends on MSR:PR and SPR# bit 0x10,
4126 * it can generate a priv, a hv emu or a no-op
4130 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4133 if (ctx
->pr
|| sprn
== 0) {
4134 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4140 #if defined(TARGET_PPC64)
4142 static void gen_setb(DisasContext
*ctx
)
4144 TCGv_i32 t0
= tcg_temp_new_i32();
4145 TCGv_i32 t8
= tcg_temp_new_i32();
4146 TCGv_i32 tm1
= tcg_temp_new_i32();
4147 int crf
= crfS(ctx
->opcode
);
4149 tcg_gen_setcondi_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], 4);
4150 tcg_gen_movi_i32(t8
, 8);
4151 tcg_gen_movi_i32(tm1
, -1);
4152 tcg_gen_movcond_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], t8
, tm1
, t0
);
4153 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4155 tcg_temp_free_i32(t0
);
4156 tcg_temp_free_i32(t8
);
4157 tcg_temp_free_i32(tm1
);
4161 /*** Cache management ***/
4164 static void gen_dcbf(DisasContext
*ctx
)
4166 /* XXX: specification says this is treated as a load by the MMU */
4168 gen_set_access_type(ctx
, ACCESS_CACHE
);
4169 t0
= tcg_temp_new();
4170 gen_addr_reg_index(ctx
, t0
);
4171 gen_qemu_ld8u(ctx
, t0
, t0
);
4175 /* dcbi (Supervisor only) */
4176 static void gen_dcbi(DisasContext
*ctx
)
4178 #if defined(CONFIG_USER_ONLY)
4184 EA
= tcg_temp_new();
4185 gen_set_access_type(ctx
, ACCESS_CACHE
);
4186 gen_addr_reg_index(ctx
, EA
);
4187 val
= tcg_temp_new();
4188 /* XXX: specification says this should be treated as a store by the MMU */
4189 gen_qemu_ld8u(ctx
, val
, EA
);
4190 gen_qemu_st8(ctx
, val
, EA
);
4193 #endif /* defined(CONFIG_USER_ONLY) */
4197 static void gen_dcbst(DisasContext
*ctx
)
4199 /* XXX: specification say this is treated as a load by the MMU */
4201 gen_set_access_type(ctx
, ACCESS_CACHE
);
4202 t0
= tcg_temp_new();
4203 gen_addr_reg_index(ctx
, t0
);
4204 gen_qemu_ld8u(ctx
, t0
, t0
);
4209 static void gen_dcbt(DisasContext
*ctx
)
4211 /* interpreted as no-op */
4212 /* XXX: specification say this is treated as a load by the MMU
4213 * but does not generate any exception
4218 static void gen_dcbtst(DisasContext
*ctx
)
4220 /* interpreted as no-op */
4221 /* XXX: specification say this is treated as a load by the MMU
4222 * but does not generate any exception
4227 static void gen_dcbtls(DisasContext
*ctx
)
4229 /* Always fails locking the cache */
4230 TCGv t0
= tcg_temp_new();
4231 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
4232 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
4233 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
4238 static void gen_dcbz(DisasContext
*ctx
)
4243 gen_set_access_type(ctx
, ACCESS_CACHE
);
4244 tcgv_addr
= tcg_temp_new();
4245 tcgv_op
= tcg_const_i32(ctx
->opcode
& 0x03FF000);
4246 gen_addr_reg_index(ctx
, tcgv_addr
);
4247 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_op
);
4248 tcg_temp_free(tcgv_addr
);
4249 tcg_temp_free_i32(tcgv_op
);
4253 static void gen_dst(DisasContext
*ctx
)
4255 if (rA(ctx
->opcode
) == 0) {
4256 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4258 /* interpreted as no-op */
4263 static void gen_dstst(DisasContext
*ctx
)
4265 if (rA(ctx
->opcode
) == 0) {
4266 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4268 /* interpreted as no-op */
4274 static void gen_dss(DisasContext
*ctx
)
4276 /* interpreted as no-op */
4280 static void gen_icbi(DisasContext
*ctx
)
4283 gen_set_access_type(ctx
, ACCESS_CACHE
);
4284 t0
= tcg_temp_new();
4285 gen_addr_reg_index(ctx
, t0
);
4286 gen_helper_icbi(cpu_env
, t0
);
4292 static void gen_dcba(DisasContext
*ctx
)
4294 /* interpreted as no-op */
4295 /* XXX: specification say this is treated as a store by the MMU
4296 * but does not generate any exception
4300 /*** Segment register manipulation ***/
4301 /* Supervisor only: */
4304 static void gen_mfsr(DisasContext
*ctx
)
4306 #if defined(CONFIG_USER_ONLY)
4312 t0
= tcg_const_tl(SR(ctx
->opcode
));
4313 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4315 #endif /* defined(CONFIG_USER_ONLY) */
4319 static void gen_mfsrin(DisasContext
*ctx
)
4321 #if defined(CONFIG_USER_ONLY)
4327 t0
= tcg_temp_new();
4328 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
4329 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4331 #endif /* defined(CONFIG_USER_ONLY) */
4335 static void gen_mtsr(DisasContext
*ctx
)
4337 #if defined(CONFIG_USER_ONLY)
4343 t0
= tcg_const_tl(SR(ctx
->opcode
));
4344 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4346 #endif /* defined(CONFIG_USER_ONLY) */
4350 static void gen_mtsrin(DisasContext
*ctx
)
4352 #if defined(CONFIG_USER_ONLY)
4358 t0
= tcg_temp_new();
4359 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
4360 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4362 #endif /* defined(CONFIG_USER_ONLY) */
4365 #if defined(TARGET_PPC64)
4366 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4369 static void gen_mfsr_64b(DisasContext
*ctx
)
4371 #if defined(CONFIG_USER_ONLY)
4377 t0
= tcg_const_tl(SR(ctx
->opcode
));
4378 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4380 #endif /* defined(CONFIG_USER_ONLY) */
4384 static void gen_mfsrin_64b(DisasContext
*ctx
)
4386 #if defined(CONFIG_USER_ONLY)
4392 t0
= tcg_temp_new();
4393 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
4394 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4396 #endif /* defined(CONFIG_USER_ONLY) */
4400 static void gen_mtsr_64b(DisasContext
*ctx
)
4402 #if defined(CONFIG_USER_ONLY)
4408 t0
= tcg_const_tl(SR(ctx
->opcode
));
4409 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4411 #endif /* defined(CONFIG_USER_ONLY) */
4415 static void gen_mtsrin_64b(DisasContext
*ctx
)
4417 #if defined(CONFIG_USER_ONLY)
4423 t0
= tcg_temp_new();
4424 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
4425 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4427 #endif /* defined(CONFIG_USER_ONLY) */
4431 static void gen_slbmte(DisasContext
*ctx
)
4433 #if defined(CONFIG_USER_ONLY)
4438 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4439 cpu_gpr
[rS(ctx
->opcode
)]);
4440 #endif /* defined(CONFIG_USER_ONLY) */
4443 static void gen_slbmfee(DisasContext
*ctx
)
4445 #if defined(CONFIG_USER_ONLY)
4450 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4451 cpu_gpr
[rB(ctx
->opcode
)]);
4452 #endif /* defined(CONFIG_USER_ONLY) */
4455 static void gen_slbmfev(DisasContext
*ctx
)
4457 #if defined(CONFIG_USER_ONLY)
4462 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4463 cpu_gpr
[rB(ctx
->opcode
)]);
4464 #endif /* defined(CONFIG_USER_ONLY) */
4467 static void gen_slbfee_(DisasContext
*ctx
)
4469 #if defined(CONFIG_USER_ONLY)
4470 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4474 if (unlikely(ctx
->pr
)) {
4475 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4478 gen_helper_find_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4479 cpu_gpr
[rB(ctx
->opcode
)]);
4480 l1
= gen_new_label();
4481 l2
= gen_new_label();
4482 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4483 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rS(ctx
->opcode
)], -1, l1
);
4484 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], CRF_EQ
);
4487 tcg_gen_movi_tl(cpu_gpr
[rS(ctx
->opcode
)], 0);
4491 #endif /* defined(TARGET_PPC64) */
4493 /*** Lookaside buffer management ***/
4494 /* Optional & supervisor only: */
4497 static void gen_tlbia(DisasContext
*ctx
)
4499 #if defined(CONFIG_USER_ONLY)
4504 gen_helper_tlbia(cpu_env
);
4505 #endif /* defined(CONFIG_USER_ONLY) */
4509 static void gen_tlbiel(DisasContext
*ctx
)
4511 #if defined(CONFIG_USER_ONLY)
4516 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4517 #endif /* defined(CONFIG_USER_ONLY) */
4521 static void gen_tlbie(DisasContext
*ctx
)
4523 #if defined(CONFIG_USER_ONLY)
4529 CHK_SV
; /* If gtse is set then tlbie is supervisor privileged */
4531 CHK_HV
; /* Else hypervisor privileged */
4534 if (NARROW_MODE(ctx
)) {
4535 TCGv t0
= tcg_temp_new();
4536 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4537 gen_helper_tlbie(cpu_env
, t0
);
4540 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4542 t1
= tcg_temp_new_i32();
4543 tcg_gen_ld_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
4544 tcg_gen_ori_i32(t1
, t1
, TLB_NEED_GLOBAL_FLUSH
);
4545 tcg_gen_st_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
4546 tcg_temp_free_i32(t1
);
4547 #endif /* defined(CONFIG_USER_ONLY) */
4551 static void gen_tlbsync(DisasContext
*ctx
)
4553 #if defined(CONFIG_USER_ONLY)
4558 CHK_SV
; /* If gtse is set then tlbsync is supervisor privileged */
4560 CHK_HV
; /* Else hypervisor privileged */
4563 /* BookS does both ptesync and tlbsync make tlbsync a nop for server */
4564 if (ctx
->insns_flags
& PPC_BOOKE
) {
4565 gen_check_tlb_flush(ctx
, true);
4567 #endif /* defined(CONFIG_USER_ONLY) */
4570 #if defined(TARGET_PPC64)
4572 static void gen_slbia(DisasContext
*ctx
)
4574 #if defined(CONFIG_USER_ONLY)
4579 gen_helper_slbia(cpu_env
);
4580 #endif /* defined(CONFIG_USER_ONLY) */
4584 static void gen_slbie(DisasContext
*ctx
)
4586 #if defined(CONFIG_USER_ONLY)
4591 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4592 #endif /* defined(CONFIG_USER_ONLY) */
4596 static void gen_slbieg(DisasContext
*ctx
)
4598 #if defined(CONFIG_USER_ONLY)
4603 gen_helper_slbieg(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4604 #endif /* defined(CONFIG_USER_ONLY) */
4608 static void gen_slbsync(DisasContext
*ctx
)
4610 #if defined(CONFIG_USER_ONLY)
4614 gen_check_tlb_flush(ctx
, true);
4615 #endif /* defined(CONFIG_USER_ONLY) */
4618 #endif /* defined(TARGET_PPC64) */
4620 /*** External control ***/
4624 static void gen_eciwx(DisasContext
*ctx
)
4627 /* Should check EAR[E] ! */
4628 gen_set_access_type(ctx
, ACCESS_EXT
);
4629 t0
= tcg_temp_new();
4630 gen_addr_reg_index(ctx
, t0
);
4631 gen_check_align(ctx
, t0
, 0x03);
4632 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4637 static void gen_ecowx(DisasContext
*ctx
)
4640 /* Should check EAR[E] ! */
4641 gen_set_access_type(ctx
, ACCESS_EXT
);
4642 t0
= tcg_temp_new();
4643 gen_addr_reg_index(ctx
, t0
);
4644 gen_check_align(ctx
, t0
, 0x03);
4645 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4649 /* PowerPC 601 specific instructions */
4652 static void gen_abs(DisasContext
*ctx
)
4654 TCGLabel
*l1
= gen_new_label();
4655 TCGLabel
*l2
= gen_new_label();
4656 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4657 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4660 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4662 if (unlikely(Rc(ctx
->opcode
) != 0))
4663 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4667 static void gen_abso(DisasContext
*ctx
)
4669 TCGLabel
*l1
= gen_new_label();
4670 TCGLabel
*l2
= gen_new_label();
4671 TCGLabel
*l3
= gen_new_label();
4672 /* Start with XER OV disabled, the most likely case */
4673 tcg_gen_movi_tl(cpu_ov
, 0);
4674 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4675 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4676 tcg_gen_movi_tl(cpu_ov
, 1);
4677 tcg_gen_movi_tl(cpu_so
, 1);
4680 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4683 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4685 if (unlikely(Rc(ctx
->opcode
) != 0))
4686 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4690 static void gen_clcs(DisasContext
*ctx
)
4692 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4693 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4694 tcg_temp_free_i32(t0
);
4695 /* Rc=1 sets CR0 to an undefined state */
4699 static void gen_div(DisasContext
*ctx
)
4701 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4702 cpu_gpr
[rB(ctx
->opcode
)]);
4703 if (unlikely(Rc(ctx
->opcode
) != 0))
4704 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4708 static void gen_divo(DisasContext
*ctx
)
4710 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4711 cpu_gpr
[rB(ctx
->opcode
)]);
4712 if (unlikely(Rc(ctx
->opcode
) != 0))
4713 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4717 static void gen_divs(DisasContext
*ctx
)
4719 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4720 cpu_gpr
[rB(ctx
->opcode
)]);
4721 if (unlikely(Rc(ctx
->opcode
) != 0))
4722 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4725 /* divso - divso. */
4726 static void gen_divso(DisasContext
*ctx
)
4728 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4729 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4730 if (unlikely(Rc(ctx
->opcode
) != 0))
4731 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4735 static void gen_doz(DisasContext
*ctx
)
4737 TCGLabel
*l1
= gen_new_label();
4738 TCGLabel
*l2
= gen_new_label();
4739 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4740 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4743 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4745 if (unlikely(Rc(ctx
->opcode
) != 0))
4746 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4750 static void gen_dozo(DisasContext
*ctx
)
4752 TCGLabel
*l1
= gen_new_label();
4753 TCGLabel
*l2
= gen_new_label();
4754 TCGv t0
= tcg_temp_new();
4755 TCGv t1
= tcg_temp_new();
4756 TCGv t2
= tcg_temp_new();
4757 /* Start with XER OV disabled, the most likely case */
4758 tcg_gen_movi_tl(cpu_ov
, 0);
4759 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4760 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4761 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4762 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4763 tcg_gen_andc_tl(t1
, t1
, t2
);
4764 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4765 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4766 tcg_gen_movi_tl(cpu_ov
, 1);
4767 tcg_gen_movi_tl(cpu_so
, 1);
4770 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4775 if (unlikely(Rc(ctx
->opcode
) != 0))
4776 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4780 static void gen_dozi(DisasContext
*ctx
)
4782 target_long simm
= SIMM(ctx
->opcode
);
4783 TCGLabel
*l1
= gen_new_label();
4784 TCGLabel
*l2
= gen_new_label();
4785 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4786 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4789 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4791 if (unlikely(Rc(ctx
->opcode
) != 0))
4792 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4795 /* lscbx - lscbx. */
4796 static void gen_lscbx(DisasContext
*ctx
)
4798 TCGv t0
= tcg_temp_new();
4799 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4800 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4801 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4803 gen_addr_reg_index(ctx
, t0
);
4804 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4805 tcg_temp_free_i32(t1
);
4806 tcg_temp_free_i32(t2
);
4807 tcg_temp_free_i32(t3
);
4808 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4809 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4810 if (unlikely(Rc(ctx
->opcode
) != 0))
4811 gen_set_Rc0(ctx
, t0
);
4815 /* maskg - maskg. */
4816 static void gen_maskg(DisasContext
*ctx
)
4818 TCGLabel
*l1
= gen_new_label();
4819 TCGv t0
= tcg_temp_new();
4820 TCGv t1
= tcg_temp_new();
4821 TCGv t2
= tcg_temp_new();
4822 TCGv t3
= tcg_temp_new();
4823 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4824 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4825 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4826 tcg_gen_addi_tl(t2
, t0
, 1);
4827 tcg_gen_shr_tl(t2
, t3
, t2
);
4828 tcg_gen_shr_tl(t3
, t3
, t1
);
4829 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4830 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4831 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4837 if (unlikely(Rc(ctx
->opcode
) != 0))
4838 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4841 /* maskir - maskir. */
4842 static void gen_maskir(DisasContext
*ctx
)
4844 TCGv t0
= tcg_temp_new();
4845 TCGv t1
= tcg_temp_new();
4846 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4847 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4848 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4851 if (unlikely(Rc(ctx
->opcode
) != 0))
4852 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4856 static void gen_mul(DisasContext
*ctx
)
4858 TCGv_i64 t0
= tcg_temp_new_i64();
4859 TCGv_i64 t1
= tcg_temp_new_i64();
4860 TCGv t2
= tcg_temp_new();
4861 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4862 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4863 tcg_gen_mul_i64(t0
, t0
, t1
);
4864 tcg_gen_trunc_i64_tl(t2
, t0
);
4865 gen_store_spr(SPR_MQ
, t2
);
4866 tcg_gen_shri_i64(t1
, t0
, 32);
4867 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4868 tcg_temp_free_i64(t0
);
4869 tcg_temp_free_i64(t1
);
4871 if (unlikely(Rc(ctx
->opcode
) != 0))
4872 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4876 static void gen_mulo(DisasContext
*ctx
)
4878 TCGLabel
*l1
= gen_new_label();
4879 TCGv_i64 t0
= tcg_temp_new_i64();
4880 TCGv_i64 t1
= tcg_temp_new_i64();
4881 TCGv t2
= tcg_temp_new();
4882 /* Start with XER OV disabled, the most likely case */
4883 tcg_gen_movi_tl(cpu_ov
, 0);
4884 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4885 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4886 tcg_gen_mul_i64(t0
, t0
, t1
);
4887 tcg_gen_trunc_i64_tl(t2
, t0
);
4888 gen_store_spr(SPR_MQ
, t2
);
4889 tcg_gen_shri_i64(t1
, t0
, 32);
4890 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4891 tcg_gen_ext32s_i64(t1
, t0
);
4892 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4893 tcg_gen_movi_tl(cpu_ov
, 1);
4894 tcg_gen_movi_tl(cpu_so
, 1);
4896 tcg_temp_free_i64(t0
);
4897 tcg_temp_free_i64(t1
);
4899 if (unlikely(Rc(ctx
->opcode
) != 0))
4900 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4904 static void gen_nabs(DisasContext
*ctx
)
4906 TCGLabel
*l1
= gen_new_label();
4907 TCGLabel
*l2
= gen_new_label();
4908 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4909 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4912 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4914 if (unlikely(Rc(ctx
->opcode
) != 0))
4915 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4918 /* nabso - nabso. */
4919 static void gen_nabso(DisasContext
*ctx
)
4921 TCGLabel
*l1
= gen_new_label();
4922 TCGLabel
*l2
= gen_new_label();
4923 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4924 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4927 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4929 /* nabs never overflows */
4930 tcg_gen_movi_tl(cpu_ov
, 0);
4931 if (unlikely(Rc(ctx
->opcode
) != 0))
4932 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4936 static void gen_rlmi(DisasContext
*ctx
)
4938 uint32_t mb
= MB(ctx
->opcode
);
4939 uint32_t me
= ME(ctx
->opcode
);
4940 TCGv t0
= tcg_temp_new();
4941 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4942 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4943 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4944 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4945 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4947 if (unlikely(Rc(ctx
->opcode
) != 0))
4948 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4952 static void gen_rrib(DisasContext
*ctx
)
4954 TCGv t0
= tcg_temp_new();
4955 TCGv t1
= tcg_temp_new();
4956 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4957 tcg_gen_movi_tl(t1
, 0x80000000);
4958 tcg_gen_shr_tl(t1
, t1
, t0
);
4959 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4960 tcg_gen_and_tl(t0
, t0
, t1
);
4961 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4962 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4965 if (unlikely(Rc(ctx
->opcode
) != 0))
4966 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4970 static void gen_sle(DisasContext
*ctx
)
4972 TCGv t0
= tcg_temp_new();
4973 TCGv t1
= tcg_temp_new();
4974 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4975 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4976 tcg_gen_subfi_tl(t1
, 32, t1
);
4977 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4978 tcg_gen_or_tl(t1
, t0
, t1
);
4979 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4980 gen_store_spr(SPR_MQ
, t1
);
4983 if (unlikely(Rc(ctx
->opcode
) != 0))
4984 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4988 static void gen_sleq(DisasContext
*ctx
)
4990 TCGv t0
= tcg_temp_new();
4991 TCGv t1
= tcg_temp_new();
4992 TCGv t2
= tcg_temp_new();
4993 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4994 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4995 tcg_gen_shl_tl(t2
, t2
, t0
);
4996 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4997 gen_load_spr(t1
, SPR_MQ
);
4998 gen_store_spr(SPR_MQ
, t0
);
4999 tcg_gen_and_tl(t0
, t0
, t2
);
5000 tcg_gen_andc_tl(t1
, t1
, t2
);
5001 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5005 if (unlikely(Rc(ctx
->opcode
) != 0))
5006 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5010 static void gen_sliq(DisasContext
*ctx
)
5012 int sh
= SH(ctx
->opcode
);
5013 TCGv t0
= tcg_temp_new();
5014 TCGv t1
= tcg_temp_new();
5015 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5016 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5017 tcg_gen_or_tl(t1
, t0
, t1
);
5018 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5019 gen_store_spr(SPR_MQ
, t1
);
5022 if (unlikely(Rc(ctx
->opcode
) != 0))
5023 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5026 /* slliq - slliq. */
5027 static void gen_slliq(DisasContext
*ctx
)
5029 int sh
= SH(ctx
->opcode
);
5030 TCGv t0
= tcg_temp_new();
5031 TCGv t1
= tcg_temp_new();
5032 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5033 gen_load_spr(t1
, SPR_MQ
);
5034 gen_store_spr(SPR_MQ
, t0
);
5035 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5036 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5037 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5040 if (unlikely(Rc(ctx
->opcode
) != 0))
5041 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5045 static void gen_sllq(DisasContext
*ctx
)
5047 TCGLabel
*l1
= gen_new_label();
5048 TCGLabel
*l2
= gen_new_label();
5049 TCGv t0
= tcg_temp_local_new();
5050 TCGv t1
= tcg_temp_local_new();
5051 TCGv t2
= tcg_temp_local_new();
5052 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5053 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5054 tcg_gen_shl_tl(t1
, t1
, t2
);
5055 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5056 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5057 gen_load_spr(t0
, SPR_MQ
);
5058 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5061 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5062 gen_load_spr(t2
, SPR_MQ
);
5063 tcg_gen_andc_tl(t1
, t2
, t1
);
5064 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5069 if (unlikely(Rc(ctx
->opcode
) != 0))
5070 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5074 static void gen_slq(DisasContext
*ctx
)
5076 TCGLabel
*l1
= gen_new_label();
5077 TCGv t0
= tcg_temp_new();
5078 TCGv t1
= tcg_temp_new();
5079 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5080 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5081 tcg_gen_subfi_tl(t1
, 32, t1
);
5082 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5083 tcg_gen_or_tl(t1
, t0
, t1
);
5084 gen_store_spr(SPR_MQ
, t1
);
5085 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5086 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5087 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5088 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5092 if (unlikely(Rc(ctx
->opcode
) != 0))
5093 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5096 /* sraiq - sraiq. */
5097 static void gen_sraiq(DisasContext
*ctx
)
5099 int sh
= SH(ctx
->opcode
);
5100 TCGLabel
*l1
= gen_new_label();
5101 TCGv t0
= tcg_temp_new();
5102 TCGv t1
= tcg_temp_new();
5103 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5104 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5105 tcg_gen_or_tl(t0
, t0
, t1
);
5106 gen_store_spr(SPR_MQ
, t0
);
5107 tcg_gen_movi_tl(cpu_ca
, 0);
5108 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5109 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5110 tcg_gen_movi_tl(cpu_ca
, 1);
5112 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5115 if (unlikely(Rc(ctx
->opcode
) != 0))
5116 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5120 static void gen_sraq(DisasContext
*ctx
)
5122 TCGLabel
*l1
= gen_new_label();
5123 TCGLabel
*l2
= gen_new_label();
5124 TCGv t0
= tcg_temp_new();
5125 TCGv t1
= tcg_temp_local_new();
5126 TCGv t2
= tcg_temp_local_new();
5127 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5128 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5129 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5130 tcg_gen_subfi_tl(t2
, 32, t2
);
5131 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5132 tcg_gen_or_tl(t0
, t0
, t2
);
5133 gen_store_spr(SPR_MQ
, t0
);
5134 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5135 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5136 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5137 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5140 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5141 tcg_gen_movi_tl(cpu_ca
, 0);
5142 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5143 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5144 tcg_gen_movi_tl(cpu_ca
, 1);
5148 if (unlikely(Rc(ctx
->opcode
) != 0))
5149 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5153 static void gen_sre(DisasContext
*ctx
)
5155 TCGv t0
= tcg_temp_new();
5156 TCGv t1
= tcg_temp_new();
5157 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5158 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5159 tcg_gen_subfi_tl(t1
, 32, t1
);
5160 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5161 tcg_gen_or_tl(t1
, t0
, t1
);
5162 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5163 gen_store_spr(SPR_MQ
, t1
);
5166 if (unlikely(Rc(ctx
->opcode
) != 0))
5167 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5171 static void gen_srea(DisasContext
*ctx
)
5173 TCGv t0
= tcg_temp_new();
5174 TCGv t1
= tcg_temp_new();
5175 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5176 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5177 gen_store_spr(SPR_MQ
, t0
);
5178 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5181 if (unlikely(Rc(ctx
->opcode
) != 0))
5182 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5186 static void gen_sreq(DisasContext
*ctx
)
5188 TCGv t0
= tcg_temp_new();
5189 TCGv t1
= tcg_temp_new();
5190 TCGv t2
= tcg_temp_new();
5191 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5192 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5193 tcg_gen_shr_tl(t1
, t1
, t0
);
5194 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5195 gen_load_spr(t2
, SPR_MQ
);
5196 gen_store_spr(SPR_MQ
, t0
);
5197 tcg_gen_and_tl(t0
, t0
, t1
);
5198 tcg_gen_andc_tl(t2
, t2
, t1
);
5199 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5203 if (unlikely(Rc(ctx
->opcode
) != 0))
5204 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5208 static void gen_sriq(DisasContext
*ctx
)
5210 int sh
= SH(ctx
->opcode
);
5211 TCGv t0
= tcg_temp_new();
5212 TCGv t1
= tcg_temp_new();
5213 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5214 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5215 tcg_gen_or_tl(t1
, t0
, t1
);
5216 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5217 gen_store_spr(SPR_MQ
, t1
);
5220 if (unlikely(Rc(ctx
->opcode
) != 0))
5221 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5225 static void gen_srliq(DisasContext
*ctx
)
5227 int sh
= SH(ctx
->opcode
);
5228 TCGv t0
= tcg_temp_new();
5229 TCGv t1
= tcg_temp_new();
5230 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5231 gen_load_spr(t1
, SPR_MQ
);
5232 gen_store_spr(SPR_MQ
, t0
);
5233 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5234 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5235 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5238 if (unlikely(Rc(ctx
->opcode
) != 0))
5239 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5243 static void gen_srlq(DisasContext
*ctx
)
5245 TCGLabel
*l1
= gen_new_label();
5246 TCGLabel
*l2
= gen_new_label();
5247 TCGv t0
= tcg_temp_local_new();
5248 TCGv t1
= tcg_temp_local_new();
5249 TCGv t2
= tcg_temp_local_new();
5250 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5251 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5252 tcg_gen_shr_tl(t2
, t1
, t2
);
5253 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5254 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5255 gen_load_spr(t0
, SPR_MQ
);
5256 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5259 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5260 tcg_gen_and_tl(t0
, t0
, t2
);
5261 gen_load_spr(t1
, SPR_MQ
);
5262 tcg_gen_andc_tl(t1
, t1
, t2
);
5263 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5268 if (unlikely(Rc(ctx
->opcode
) != 0))
5269 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5273 static void gen_srq(DisasContext
*ctx
)
5275 TCGLabel
*l1
= gen_new_label();
5276 TCGv t0
= tcg_temp_new();
5277 TCGv t1
= tcg_temp_new();
5278 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5279 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5280 tcg_gen_subfi_tl(t1
, 32, t1
);
5281 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5282 tcg_gen_or_tl(t1
, t0
, t1
);
5283 gen_store_spr(SPR_MQ
, t1
);
5284 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5285 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5286 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5287 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5291 if (unlikely(Rc(ctx
->opcode
) != 0))
5292 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5295 /* PowerPC 602 specific instructions */
5298 static void gen_dsa(DisasContext
*ctx
)
5301 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5305 static void gen_esa(DisasContext
*ctx
)
5308 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5312 static void gen_mfrom(DisasContext
*ctx
)
5314 #if defined(CONFIG_USER_ONLY)
5318 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5319 #endif /* defined(CONFIG_USER_ONLY) */
5322 /* 602 - 603 - G2 TLB management */
5325 static void gen_tlbld_6xx(DisasContext
*ctx
)
5327 #if defined(CONFIG_USER_ONLY)
5331 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5332 #endif /* defined(CONFIG_USER_ONLY) */
5336 static void gen_tlbli_6xx(DisasContext
*ctx
)
5338 #if defined(CONFIG_USER_ONLY)
5342 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5343 #endif /* defined(CONFIG_USER_ONLY) */
5346 /* 74xx TLB management */
5349 static void gen_tlbld_74xx(DisasContext
*ctx
)
5351 #if defined(CONFIG_USER_ONLY)
5355 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5356 #endif /* defined(CONFIG_USER_ONLY) */
5360 static void gen_tlbli_74xx(DisasContext
*ctx
)
5362 #if defined(CONFIG_USER_ONLY)
5366 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5367 #endif /* defined(CONFIG_USER_ONLY) */
5370 /* POWER instructions not in PowerPC 601 */
5373 static void gen_clf(DisasContext
*ctx
)
5375 /* Cache line flush: implemented as no-op */
5379 static void gen_cli(DisasContext
*ctx
)
5381 #if defined(CONFIG_USER_ONLY)
5384 /* Cache line invalidate: privileged and treated as no-op */
5386 #endif /* defined(CONFIG_USER_ONLY) */
5390 static void gen_dclst(DisasContext
*ctx
)
5392 /* Data cache line store: treated as no-op */
5395 static void gen_mfsri(DisasContext
*ctx
)
5397 #if defined(CONFIG_USER_ONLY)
5400 int ra
= rA(ctx
->opcode
);
5401 int rd
= rD(ctx
->opcode
);
5405 t0
= tcg_temp_new();
5406 gen_addr_reg_index(ctx
, t0
);
5407 tcg_gen_extract_tl(t0
, t0
, 28, 4);
5408 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5410 if (ra
!= 0 && ra
!= rd
)
5411 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5412 #endif /* defined(CONFIG_USER_ONLY) */
5415 static void gen_rac(DisasContext
*ctx
)
5417 #if defined(CONFIG_USER_ONLY)
5423 t0
= tcg_temp_new();
5424 gen_addr_reg_index(ctx
, t0
);
5425 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5427 #endif /* defined(CONFIG_USER_ONLY) */
5430 static void gen_rfsvc(DisasContext
*ctx
)
5432 #if defined(CONFIG_USER_ONLY)
5437 gen_helper_rfsvc(cpu_env
);
5438 gen_sync_exception(ctx
);
5439 #endif /* defined(CONFIG_USER_ONLY) */
5442 /* svc is not implemented for now */
5444 /* BookE specific instructions */
5446 /* XXX: not implemented on 440 ? */
5447 static void gen_mfapidi(DisasContext
*ctx
)
5450 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5453 /* XXX: not implemented on 440 ? */
5454 static void gen_tlbiva(DisasContext
*ctx
)
5456 #if defined(CONFIG_USER_ONLY)
5462 t0
= tcg_temp_new();
5463 gen_addr_reg_index(ctx
, t0
);
5464 gen_helper_tlbiva(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5466 #endif /* defined(CONFIG_USER_ONLY) */
5469 /* All 405 MAC instructions are translated here */
5470 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5471 int ra
, int rb
, int rt
, int Rc
)
5475 t0
= tcg_temp_local_new();
5476 t1
= tcg_temp_local_new();
5478 switch (opc3
& 0x0D) {
5480 /* macchw - macchw. - macchwo - macchwo. */
5481 /* macchws - macchws. - macchwso - macchwso. */
5482 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5483 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5484 /* mulchw - mulchw. */
5485 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5486 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5487 tcg_gen_ext16s_tl(t1
, t1
);
5490 /* macchwu - macchwu. - macchwuo - macchwuo. */
5491 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5492 /* mulchwu - mulchwu. */
5493 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5494 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5495 tcg_gen_ext16u_tl(t1
, t1
);
5498 /* machhw - machhw. - machhwo - machhwo. */
5499 /* machhws - machhws. - machhwso - machhwso. */
5500 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5501 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5502 /* mulhhw - mulhhw. */
5503 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5504 tcg_gen_ext16s_tl(t0
, t0
);
5505 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5506 tcg_gen_ext16s_tl(t1
, t1
);
5509 /* machhwu - machhwu. - machhwuo - machhwuo. */
5510 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5511 /* mulhhwu - mulhhwu. */
5512 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5513 tcg_gen_ext16u_tl(t0
, t0
);
5514 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5515 tcg_gen_ext16u_tl(t1
, t1
);
5518 /* maclhw - maclhw. - maclhwo - maclhwo. */
5519 /* maclhws - maclhws. - maclhwso - maclhwso. */
5520 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5521 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5522 /* mullhw - mullhw. */
5523 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5524 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5527 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5528 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5529 /* mullhwu - mullhwu. */
5530 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5531 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5535 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5536 tcg_gen_mul_tl(t1
, t0
, t1
);
5538 /* nmultiply-and-accumulate (0x0E) */
5539 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5541 /* multiply-and-accumulate (0x0C) */
5542 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5546 /* Check overflow and/or saturate */
5547 TCGLabel
*l1
= gen_new_label();
5550 /* Start with XER OV disabled, the most likely case */
5551 tcg_gen_movi_tl(cpu_ov
, 0);
5555 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5556 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5557 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5558 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5561 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5562 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5566 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5569 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5573 /* Check overflow */
5574 tcg_gen_movi_tl(cpu_ov
, 1);
5575 tcg_gen_movi_tl(cpu_so
, 1);
5578 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5581 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5585 if (unlikely(Rc
) != 0) {
5587 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5591 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5592 static void glue(gen_, name)(DisasContext *ctx) \
5594 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5595 rD(ctx->opcode), Rc(ctx->opcode)); \
5598 /* macchw - macchw. */
5599 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5600 /* macchwo - macchwo. */
5601 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5602 /* macchws - macchws. */
5603 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5604 /* macchwso - macchwso. */
5605 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5606 /* macchwsu - macchwsu. */
5607 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5608 /* macchwsuo - macchwsuo. */
5609 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5610 /* macchwu - macchwu. */
5611 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5612 /* macchwuo - macchwuo. */
5613 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5614 /* machhw - machhw. */
5615 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5616 /* machhwo - machhwo. */
5617 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5618 /* machhws - machhws. */
5619 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5620 /* machhwso - machhwso. */
5621 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5622 /* machhwsu - machhwsu. */
5623 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5624 /* machhwsuo - machhwsuo. */
5625 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5626 /* machhwu - machhwu. */
5627 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5628 /* machhwuo - machhwuo. */
5629 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5630 /* maclhw - maclhw. */
5631 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5632 /* maclhwo - maclhwo. */
5633 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5634 /* maclhws - maclhws. */
5635 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5636 /* maclhwso - maclhwso. */
5637 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5638 /* maclhwu - maclhwu. */
5639 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5640 /* maclhwuo - maclhwuo. */
5641 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5642 /* maclhwsu - maclhwsu. */
5643 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5644 /* maclhwsuo - maclhwsuo. */
5645 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5646 /* nmacchw - nmacchw. */
5647 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5648 /* nmacchwo - nmacchwo. */
5649 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5650 /* nmacchws - nmacchws. */
5651 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5652 /* nmacchwso - nmacchwso. */
5653 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5654 /* nmachhw - nmachhw. */
5655 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5656 /* nmachhwo - nmachhwo. */
5657 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5658 /* nmachhws - nmachhws. */
5659 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5660 /* nmachhwso - nmachhwso. */
5661 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5662 /* nmaclhw - nmaclhw. */
5663 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5664 /* nmaclhwo - nmaclhwo. */
5665 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5666 /* nmaclhws - nmaclhws. */
5667 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5668 /* nmaclhwso - nmaclhwso. */
5669 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5671 /* mulchw - mulchw. */
5672 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5673 /* mulchwu - mulchwu. */
5674 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5675 /* mulhhw - mulhhw. */
5676 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5677 /* mulhhwu - mulhhwu. */
5678 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5679 /* mullhw - mullhw. */
5680 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5681 /* mullhwu - mullhwu. */
5682 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5685 static void gen_mfdcr(DisasContext
*ctx
)
5687 #if defined(CONFIG_USER_ONLY)
5693 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5694 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5695 tcg_temp_free(dcrn
);
5696 #endif /* defined(CONFIG_USER_ONLY) */
5700 static void gen_mtdcr(DisasContext
*ctx
)
5702 #if defined(CONFIG_USER_ONLY)
5708 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5709 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5710 tcg_temp_free(dcrn
);
5711 #endif /* defined(CONFIG_USER_ONLY) */
5715 /* XXX: not implemented on 440 ? */
5716 static void gen_mfdcrx(DisasContext
*ctx
)
5718 #if defined(CONFIG_USER_ONLY)
5722 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5723 cpu_gpr
[rA(ctx
->opcode
)]);
5724 /* Note: Rc update flag set leads to undefined state of Rc0 */
5725 #endif /* defined(CONFIG_USER_ONLY) */
5729 /* XXX: not implemented on 440 ? */
5730 static void gen_mtdcrx(DisasContext
*ctx
)
5732 #if defined(CONFIG_USER_ONLY)
5736 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5737 cpu_gpr
[rS(ctx
->opcode
)]);
5738 /* Note: Rc update flag set leads to undefined state of Rc0 */
5739 #endif /* defined(CONFIG_USER_ONLY) */
5742 /* mfdcrux (PPC 460) : user-mode access to DCR */
5743 static void gen_mfdcrux(DisasContext
*ctx
)
5745 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5746 cpu_gpr
[rA(ctx
->opcode
)]);
5747 /* Note: Rc update flag set leads to undefined state of Rc0 */
5750 /* mtdcrux (PPC 460) : user-mode access to DCR */
5751 static void gen_mtdcrux(DisasContext
*ctx
)
5753 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5754 cpu_gpr
[rS(ctx
->opcode
)]);
5755 /* Note: Rc update flag set leads to undefined state of Rc0 */
5759 static void gen_dccci(DisasContext
*ctx
)
5762 /* interpreted as no-op */
5766 static void gen_dcread(DisasContext
*ctx
)
5768 #if defined(CONFIG_USER_ONLY)
5774 gen_set_access_type(ctx
, ACCESS_CACHE
);
5775 EA
= tcg_temp_new();
5776 gen_addr_reg_index(ctx
, EA
);
5777 val
= tcg_temp_new();
5778 gen_qemu_ld32u(ctx
, val
, EA
);
5780 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5782 #endif /* defined(CONFIG_USER_ONLY) */
5786 static void gen_icbt_40x(DisasContext
*ctx
)
5788 /* interpreted as no-op */
5789 /* XXX: specification say this is treated as a load by the MMU
5790 * but does not generate any exception
5795 static void gen_iccci(DisasContext
*ctx
)
5798 /* interpreted as no-op */
5802 static void gen_icread(DisasContext
*ctx
)
5805 /* interpreted as no-op */
5808 /* rfci (supervisor only) */
5809 static void gen_rfci_40x(DisasContext
*ctx
)
5811 #if defined(CONFIG_USER_ONLY)
5815 /* Restore CPU state */
5816 gen_helper_40x_rfci(cpu_env
);
5817 gen_sync_exception(ctx
);
5818 #endif /* defined(CONFIG_USER_ONLY) */
5821 static void gen_rfci(DisasContext
*ctx
)
5823 #if defined(CONFIG_USER_ONLY)
5827 /* Restore CPU state */
5828 gen_helper_rfci(cpu_env
);
5829 gen_sync_exception(ctx
);
5830 #endif /* defined(CONFIG_USER_ONLY) */
5833 /* BookE specific */
5835 /* XXX: not implemented on 440 ? */
5836 static void gen_rfdi(DisasContext
*ctx
)
5838 #if defined(CONFIG_USER_ONLY)
5842 /* Restore CPU state */
5843 gen_helper_rfdi(cpu_env
);
5844 gen_sync_exception(ctx
);
5845 #endif /* defined(CONFIG_USER_ONLY) */
5848 /* XXX: not implemented on 440 ? */
5849 static void gen_rfmci(DisasContext
*ctx
)
5851 #if defined(CONFIG_USER_ONLY)
5855 /* Restore CPU state */
5856 gen_helper_rfmci(cpu_env
);
5857 gen_sync_exception(ctx
);
5858 #endif /* defined(CONFIG_USER_ONLY) */
5861 /* TLB management - PowerPC 405 implementation */
5864 static void gen_tlbre_40x(DisasContext
*ctx
)
5866 #if defined(CONFIG_USER_ONLY)
5870 switch (rB(ctx
->opcode
)) {
5872 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5873 cpu_gpr
[rA(ctx
->opcode
)]);
5876 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5877 cpu_gpr
[rA(ctx
->opcode
)]);
5880 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5883 #endif /* defined(CONFIG_USER_ONLY) */
5886 /* tlbsx - tlbsx. */
5887 static void gen_tlbsx_40x(DisasContext
*ctx
)
5889 #if defined(CONFIG_USER_ONLY)
5895 t0
= tcg_temp_new();
5896 gen_addr_reg_index(ctx
, t0
);
5897 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5899 if (Rc(ctx
->opcode
)) {
5900 TCGLabel
*l1
= gen_new_label();
5901 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5902 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5903 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5906 #endif /* defined(CONFIG_USER_ONLY) */
5910 static void gen_tlbwe_40x(DisasContext
*ctx
)
5912 #if defined(CONFIG_USER_ONLY)
5917 switch (rB(ctx
->opcode
)) {
5919 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5920 cpu_gpr
[rS(ctx
->opcode
)]);
5923 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5924 cpu_gpr
[rS(ctx
->opcode
)]);
5927 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5930 #endif /* defined(CONFIG_USER_ONLY) */
5933 /* TLB management - PowerPC 440 implementation */
5936 static void gen_tlbre_440(DisasContext
*ctx
)
5938 #if defined(CONFIG_USER_ONLY)
5943 switch (rB(ctx
->opcode
)) {
5948 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5949 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5950 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5951 tcg_temp_free_i32(t0
);
5955 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5958 #endif /* defined(CONFIG_USER_ONLY) */
5961 /* tlbsx - tlbsx. */
5962 static void gen_tlbsx_440(DisasContext
*ctx
)
5964 #if defined(CONFIG_USER_ONLY)
5970 t0
= tcg_temp_new();
5971 gen_addr_reg_index(ctx
, t0
);
5972 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5974 if (Rc(ctx
->opcode
)) {
5975 TCGLabel
*l1
= gen_new_label();
5976 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5977 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5978 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5981 #endif /* defined(CONFIG_USER_ONLY) */
5985 static void gen_tlbwe_440(DisasContext
*ctx
)
5987 #if defined(CONFIG_USER_ONLY)
5991 switch (rB(ctx
->opcode
)) {
5996 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5997 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
5998 cpu_gpr
[rS(ctx
->opcode
)]);
5999 tcg_temp_free_i32(t0
);
6003 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6006 #endif /* defined(CONFIG_USER_ONLY) */
6009 /* TLB management - PowerPC BookE 2.06 implementation */
6012 static void gen_tlbre_booke206(DisasContext
*ctx
)
6014 #if defined(CONFIG_USER_ONLY)
6018 gen_helper_booke206_tlbre(cpu_env
);
6019 #endif /* defined(CONFIG_USER_ONLY) */
6022 /* tlbsx - tlbsx. */
6023 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6025 #if defined(CONFIG_USER_ONLY)
6031 if (rA(ctx
->opcode
)) {
6032 t0
= tcg_temp_new();
6033 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6035 t0
= tcg_const_tl(0);
6038 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6039 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6041 #endif /* defined(CONFIG_USER_ONLY) */
6045 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6047 #if defined(CONFIG_USER_ONLY)
6051 gen_helper_booke206_tlbwe(cpu_env
);
6052 #endif /* defined(CONFIG_USER_ONLY) */
6055 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6057 #if defined(CONFIG_USER_ONLY)
6063 t0
= tcg_temp_new();
6064 gen_addr_reg_index(ctx
, t0
);
6065 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6067 #endif /* defined(CONFIG_USER_ONLY) */
6070 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6072 #if defined(CONFIG_USER_ONLY)
6078 t0
= tcg_temp_new();
6079 gen_addr_reg_index(ctx
, t0
);
6081 switch((ctx
->opcode
>> 21) & 0x3) {
6083 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6086 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6089 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6092 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6097 #endif /* defined(CONFIG_USER_ONLY) */
6102 static void gen_wrtee(DisasContext
*ctx
)
6104 #if defined(CONFIG_USER_ONLY)
6110 t0
= tcg_temp_new();
6111 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6112 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6113 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6115 /* Stop translation to have a chance to raise an exception
6116 * if we just set msr_ee to 1
6118 gen_stop_exception(ctx
);
6119 #endif /* defined(CONFIG_USER_ONLY) */
6123 static void gen_wrteei(DisasContext
*ctx
)
6125 #if defined(CONFIG_USER_ONLY)
6129 if (ctx
->opcode
& 0x00008000) {
6130 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6131 /* Stop translation to have a chance to raise an exception */
6132 gen_stop_exception(ctx
);
6134 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6136 #endif /* defined(CONFIG_USER_ONLY) */
6139 /* PowerPC 440 specific instructions */
6142 static void gen_dlmzb(DisasContext
*ctx
)
6144 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6145 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6146 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6147 tcg_temp_free_i32(t0
);
6150 /* mbar replaces eieio on 440 */
6151 static void gen_mbar(DisasContext
*ctx
)
6153 /* interpreted as no-op */
6156 /* msync replaces sync on 440 */
6157 static void gen_msync_4xx(DisasContext
*ctx
)
6159 /* interpreted as no-op */
6163 static void gen_icbt_440(DisasContext
*ctx
)
6165 /* interpreted as no-op */
6166 /* XXX: specification say this is treated as a load by the MMU
6167 * but does not generate any exception
6171 /* Embedded.Processor Control */
6173 static void gen_msgclr(DisasContext
*ctx
)
6175 #if defined(CONFIG_USER_ONLY)
6179 /* 64-bit server processors compliant with arch 2.x */
6180 if (ctx
->insns_flags
& PPC_SEGMENT_64B
) {
6181 gen_helper_book3s_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6183 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6185 #endif /* defined(CONFIG_USER_ONLY) */
6188 static void gen_msgsnd(DisasContext
*ctx
)
6190 #if defined(CONFIG_USER_ONLY)
6194 /* 64-bit server processors compliant with arch 2.x */
6195 if (ctx
->insns_flags
& PPC_SEGMENT_64B
) {
6196 gen_helper_book3s_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6198 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6200 #endif /* defined(CONFIG_USER_ONLY) */
6203 static void gen_msgsync(DisasContext
*ctx
)
6205 #if defined(CONFIG_USER_ONLY)
6209 #endif /* defined(CONFIG_USER_ONLY) */
6210 /* interpreted as no-op */
6213 #if defined(TARGET_PPC64)
6214 static void gen_maddld(DisasContext
*ctx
)
6216 TCGv_i64 t1
= tcg_temp_new_i64();
6218 tcg_gen_mul_i64(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6219 tcg_gen_add_i64(cpu_gpr
[rD(ctx
->opcode
)], t1
, cpu_gpr
[rC(ctx
->opcode
)]);
6220 tcg_temp_free_i64(t1
);
6223 /* maddhd maddhdu */
6224 static void gen_maddhd_maddhdu(DisasContext
*ctx
)
6226 TCGv_i64 lo
= tcg_temp_new_i64();
6227 TCGv_i64 hi
= tcg_temp_new_i64();
6228 TCGv_i64 t1
= tcg_temp_new_i64();
6230 if (Rc(ctx
->opcode
)) {
6231 tcg_gen_mulu2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
6232 cpu_gpr
[rB(ctx
->opcode
)]);
6233 tcg_gen_movi_i64(t1
, 0);
6235 tcg_gen_muls2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
6236 cpu_gpr
[rB(ctx
->opcode
)]);
6237 tcg_gen_sari_i64(t1
, cpu_gpr
[rC(ctx
->opcode
)], 63);
6239 tcg_gen_add2_i64(t1
, cpu_gpr
[rD(ctx
->opcode
)], lo
, hi
,
6240 cpu_gpr
[rC(ctx
->opcode
)], t1
);
6241 tcg_temp_free_i64(lo
);
6242 tcg_temp_free_i64(hi
);
6243 tcg_temp_free_i64(t1
);
6245 #endif /* defined(TARGET_PPC64) */
6247 static void gen_tbegin(DisasContext
*ctx
)
6249 if (unlikely(!ctx
->tm_enabled
)) {
6250 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6253 gen_helper_tbegin(cpu_env
);
6256 #define GEN_TM_NOOP(name) \
6257 static inline void gen_##name(DisasContext *ctx) \
6259 if (unlikely(!ctx->tm_enabled)) { \
6260 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6263 /* Because tbegin always fails in QEMU, these user \
6264 * space instructions all have a simple implementation: \
6266 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6267 * = 0b0 || 0b00 || 0b0 \
6269 tcg_gen_movi_i32(cpu_crf[0], 0); \
6273 GEN_TM_NOOP(tabort
);
6274 GEN_TM_NOOP(tabortwc
);
6275 GEN_TM_NOOP(tabortwci
);
6276 GEN_TM_NOOP(tabortdc
);
6277 GEN_TM_NOOP(tabortdci
);
6279 static inline void gen_cp_abort(DisasContext
*ctx
)
6284 #define GEN_CP_PASTE_NOOP(name) \
6285 static inline void gen_##name(DisasContext *ctx) \
6287 /* Generate invalid exception until \
6288 * we have an implementation of the copy \
6294 GEN_CP_PASTE_NOOP(copy
)
6295 GEN_CP_PASTE_NOOP(paste
)
6297 static void gen_tcheck(DisasContext
*ctx
)
6299 if (unlikely(!ctx
->tm_enabled
)) {
6300 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6303 /* Because tbegin always fails, the tcheck implementation
6306 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
6307 * = 0b1 || 0b00 || 0b0
6309 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
6312 #if defined(CONFIG_USER_ONLY)
6313 #define GEN_TM_PRIV_NOOP(name) \
6314 static inline void gen_##name(DisasContext *ctx) \
6316 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
6321 #define GEN_TM_PRIV_NOOP(name) \
6322 static inline void gen_##name(DisasContext *ctx) \
6325 if (unlikely(!ctx->tm_enabled)) { \
6326 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6329 /* Because tbegin always fails, the implementation is \
6332 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6333 * = 0b0 || 0b00 | 0b0 \
6335 tcg_gen_movi_i32(cpu_crf[0], 0); \
6340 GEN_TM_PRIV_NOOP(treclaim
);
6341 GEN_TM_PRIV_NOOP(trechkpt
);
6343 #include "translate/fp-impl.inc.c"
6345 #include "translate/vmx-impl.inc.c"
6347 #include "translate/vsx-impl.inc.c"
6349 #include "translate/dfp-impl.inc.c"
6351 #include "translate/spe-impl.inc.c"
6353 /* Handles lfdp, lxsd, lxssp */
6354 static void gen_dform39(DisasContext
*ctx
)
6356 switch (ctx
->opcode
& 0x3) {
6358 if (ctx
->insns_flags2
& PPC2_ISA205
) {
6359 return gen_lfdp(ctx
);
6363 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6364 return gen_lxsd(ctx
);
6368 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6369 return gen_lxssp(ctx
);
6373 return gen_invalid(ctx
);
6376 /* handles stfdp, lxv, stxsd, stxssp lxvx */
6377 static void gen_dform3D(DisasContext
*ctx
)
6379 if ((ctx
->opcode
& 3) == 1) { /* DQ-FORM */
6380 switch (ctx
->opcode
& 0x7) {
6382 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6383 return gen_lxv(ctx
);
6387 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6388 return gen_stxv(ctx
);
6392 } else { /* DS-FORM */
6393 switch (ctx
->opcode
& 0x3) {
6395 if (ctx
->insns_flags2
& PPC2_ISA205
) {
6396 return gen_stfdp(ctx
);
6400 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6401 return gen_stxsd(ctx
);
6404 case 3: /* stxssp */
6405 if (ctx
->insns_flags2
& PPC2_ISA300
) {
6406 return gen_stxssp(ctx
);
6411 return gen_invalid(ctx
);
6414 static opcode_t opcodes
[] = {
6415 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
6416 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
6417 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
6418 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400001, PPC_INTEGER
),
6419 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
6420 #if defined(TARGET_PPC64)
6421 GEN_HANDLER_E(cmpeqb
, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE
, PPC2_ISA300
),
6423 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
6424 GEN_HANDLER_E(cmprb
, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE
, PPC2_ISA300
),
6425 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
6426 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6427 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6428 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6429 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6430 GEN_HANDLER_E(addpcis
, 0x13, 0x2, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6431 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
6432 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
6433 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
6434 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
6435 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6436 #if defined(TARGET_PPC64)
6437 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
6439 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
6440 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
6441 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6442 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6443 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6444 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
6445 GEN_HANDLER_E(cnttzw
, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6446 GEN_HANDLER_E(copy
, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE
, PPC2_ISA300
),
6447 GEN_HANDLER_E(cp_abort
, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
6448 GEN_HANDLER_E(paste
, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE
, PPC2_ISA300
),
6449 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
6450 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
6451 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6452 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6453 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6454 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6455 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
6456 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
6457 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6458 #if defined(TARGET_PPC64)
6459 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
6460 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
6461 GEN_HANDLER_E(cnttzd
, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6462 GEN_HANDLER_E(darn
, 0x1F, 0x13, 0x17, 0x001CF801, PPC_NONE
, PPC2_ISA300
),
6463 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6464 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
6466 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6467 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6468 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6469 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
6470 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
6471 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
6472 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
6473 #if defined(TARGET_PPC64)
6474 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
6475 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
6476 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
6477 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
6478 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
6479 GEN_HANDLER2_E(extswsli0
, "extswsli", 0x1F, 0x1A, 0x1B, 0x00000000,
6480 PPC_NONE
, PPC2_ISA300
),
6481 GEN_HANDLER2_E(extswsli1
, "extswsli", 0x1F, 0x1B, 0x1B, 0x00000000,
6482 PPC_NONE
, PPC2_ISA300
),
6484 #if defined(TARGET_PPC64)
6485 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6486 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
6487 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6489 /* handles lfdp, lxsd, lxssp */
6490 GEN_HANDLER_E(dform39
, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
6491 /* handles stfdp, lxv, stxsd, stxssp, stxv */
6492 GEN_HANDLER_E(dform3D
, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
6493 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6494 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6495 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
6496 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
6497 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
6498 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
6499 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
6500 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
6501 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6502 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6503 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
6504 GEN_HANDLER_E(lwat
, 0x1F, 0x06, 0x12, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6505 GEN_HANDLER_E(stwat
, 0x1F, 0x06, 0x16, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6506 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6507 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6508 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
6509 #if defined(TARGET_PPC64)
6510 GEN_HANDLER_E(ldat
, 0x1F, 0x06, 0x13, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6511 GEN_HANDLER_E(stdat
, 0x1F, 0x06, 0x17, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6512 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
6513 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
6514 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
6515 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
6517 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
6518 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
6519 GEN_HANDLER_E(wait
, 0x1F, 0x1E, 0x00, 0x039FF801, PPC_NONE
, PPC2_ISA300
),
6520 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6521 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6522 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
6523 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
6524 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE
, PPC2_BCTAR_ISA207
),
6525 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
6526 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
6527 #if defined(TARGET_PPC64)
6528 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
6529 GEN_HANDLER_E(stop
, 0x13, 0x12, 0x0b, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
6530 GEN_HANDLER_E(doze
, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6531 GEN_HANDLER_E(nap
, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6532 GEN_HANDLER_E(sleep
, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6533 GEN_HANDLER_E(rvwinkle
, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6534 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
6536 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
6537 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
6538 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6539 #if defined(TARGET_PPC64)
6540 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
6541 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6543 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
6544 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
6545 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
6546 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
6547 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
6548 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
6549 #if defined(TARGET_PPC64)
6550 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
6551 GEN_HANDLER_E(setb
, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE
, PPC2_ISA300
),
6552 GEN_HANDLER_E(mcrxrx
, 0x1F, 0x00, 0x12, 0x007FF801, PPC_NONE
, PPC2_ISA300
),
6554 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC
),
6555 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
6556 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
6557 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
6558 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
6559 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
6560 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
6561 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
6562 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
6563 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
6564 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x01800001, PPC_ALTIVEC
),
6565 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
6566 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
6567 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
6568 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
6569 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
6570 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
6571 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
6572 #if defined(TARGET_PPC64)
6573 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
6574 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
6576 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
6577 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
6579 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
6580 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
6581 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
6582 GEN_HANDLER2(slbfee_
, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F0000, PPC_SEGMENT_64B
),
6584 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
6585 /* XXX Those instructions will need to be handled differently for
6586 * different ISA versions */
6587 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE
),
6588 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE
),
6589 GEN_HANDLER_E(tlbiel
, 0x1F, 0x12, 0x08, 0x00100001, PPC_NONE
, PPC2_ISA300
),
6590 GEN_HANDLER_E(tlbie
, 0x1F, 0x12, 0x09, 0x00100001, PPC_NONE
, PPC2_ISA300
),
6591 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
6592 #if defined(TARGET_PPC64)
6593 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI
),
6594 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
6595 GEN_HANDLER_E(slbieg
, 0x1F, 0x12, 0x0E, 0x001F0001, PPC_NONE
, PPC2_ISA300
),
6596 GEN_HANDLER_E(slbsync
, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
6598 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
6599 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
6600 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
6601 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
6602 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
6603 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
6604 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
6605 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
6606 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
6607 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
6608 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
6609 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
6610 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
6611 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
6612 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
6613 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
6614 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
6615 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
6616 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
6617 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
6618 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
6619 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
6620 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
6621 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
6622 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
6623 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
6624 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
6625 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
6626 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
6627 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
6628 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
6629 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
6630 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
6631 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
6632 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
6633 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
6634 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
6635 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
6636 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
6637 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
6638 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
6639 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
6640 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
6641 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
6642 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
6643 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
6644 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
6645 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
6646 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
6647 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
6648 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
6649 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
6650 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
6651 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
6652 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
6653 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
6654 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
6655 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
6656 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
6657 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
6658 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
6659 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
6660 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
6661 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
6662 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
6663 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
6664 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
6665 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
6666 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
6667 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
6668 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
6669 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
6670 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
6671 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
6672 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
6673 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
6674 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
6675 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
6676 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
6677 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
6678 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
6679 PPC_NONE
, PPC2_BOOKE206
),
6680 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
6681 PPC_NONE
, PPC2_BOOKE206
),
6682 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
6683 PPC_NONE
, PPC2_BOOKE206
),
6684 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
6685 PPC_NONE
, PPC2_BOOKE206
),
6686 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
6687 PPC_NONE
, PPC2_BOOKE206
),
6688 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
6689 PPC_NONE
, PPC2_PRCNTL
),
6690 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
6691 PPC_NONE
, PPC2_PRCNTL
),
6692 GEN_HANDLER2_E(msgsync
, "msgsync", 0x1F, 0x16, 0x1B, 0x00000000,
6693 PPC_NONE
, PPC2_PRCNTL
),
6694 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
6695 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
6696 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
6697 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
6698 PPC_BOOKE
, PPC2_BOOKE206
),
6699 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
6700 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
6701 PPC_BOOKE
, PPC2_BOOKE206
),
6702 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
6703 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
6704 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
6705 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
6706 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
6707 #if defined(TARGET_PPC64)
6708 GEN_HANDLER_E(maddhd_maddhdu
, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE
,
6710 GEN_HANDLER_E(maddld
, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6713 #undef GEN_INT_ARITH_ADD
6714 #undef GEN_INT_ARITH_ADD_CONST
6715 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
6716 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
6717 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
6718 add_ca, compute_ca, compute_ov) \
6719 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
6720 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
6721 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
6722 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
6723 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
6724 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
6725 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
6726 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
6727 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
6728 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
6729 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
6731 #undef GEN_INT_ARITH_DIVW
6732 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
6733 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
6734 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
6735 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
6736 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
6737 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
6738 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6739 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6740 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6741 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6742 GEN_HANDLER_E(modsw
, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6743 GEN_HANDLER_E(moduw
, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6745 #if defined(TARGET_PPC64)
6746 #undef GEN_INT_ARITH_DIVD
6747 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
6748 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
6749 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
6750 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
6751 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
6752 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
6754 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6755 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6756 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6757 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6758 GEN_HANDLER_E(modsd
, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6759 GEN_HANDLER_E(modud
, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6761 #undef GEN_INT_ARITH_MUL_HELPER
6762 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
6763 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
6764 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
6765 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
6766 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
6769 #undef GEN_INT_ARITH_SUBF
6770 #undef GEN_INT_ARITH_SUBF_CONST
6771 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
6772 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
6773 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
6774 add_ca, compute_ca, compute_ov) \
6775 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
6776 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
6777 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
6778 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
6779 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
6780 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
6781 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
6782 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
6783 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
6784 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
6785 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
6789 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
6790 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
6791 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
6792 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
6793 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
6794 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
6795 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
6796 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
6797 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
6798 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
6799 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
6800 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
6801 #if defined(TARGET_PPC64)
6802 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
6805 #if defined(TARGET_PPC64)
6808 #define GEN_PPC64_R2(name, opc1, opc2) \
6809 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
6810 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
6812 #define GEN_PPC64_R4(name, opc1, opc2) \
6813 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
6814 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
6816 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
6818 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
6820 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
6821 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
6822 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
6823 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
6824 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
6825 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
6833 #define GEN_LD(name, ldop, opc, type) \
6834 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
6835 #define GEN_LDU(name, ldop, opc, type) \
6836 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
6837 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
6838 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
6839 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
6840 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
6841 #define GEN_LDS(name, ldop, op, type) \
6842 GEN_LD(name, ldop, op | 0x20, type) \
6843 GEN_LDU(name, ldop, op | 0x21, type) \
6844 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
6845 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
6847 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
6848 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
6849 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
6850 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
6851 #if defined(TARGET_PPC64)
6852 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
6853 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
6854 GEN_LDUX(ld
, ld64_i64
, 0x15, 0x01, PPC_64B
)
6855 GEN_LDX(ld
, ld64_i64
, 0x15, 0x00, PPC_64B
)
6856 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
6858 /* HV/P7 and later only */
6859 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
6860 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x18, PPC_CILDST
)
6861 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
6862 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
6864 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
6865 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
6872 #define GEN_ST(name, stop, opc, type) \
6873 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
6874 #define GEN_STU(name, stop, opc, type) \
6875 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
6876 #define GEN_STUX(name, stop, opc2, opc3, type) \
6877 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
6878 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
6879 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
6880 #define GEN_STS(name, stop, op, type) \
6881 GEN_ST(name, stop, op | 0x20, type) \
6882 GEN_STU(name, stop, op | 0x21, type) \
6883 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
6884 GEN_STX(name, stop, 0x17, op | 0x00, type)
6886 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
6887 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
6888 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
6889 #if defined(TARGET_PPC64)
6890 GEN_STUX(std
, st64_i64
, 0x15, 0x05, PPC_64B
)
6891 GEN_STX(std
, st64_i64
, 0x15, 0x04, PPC_64B
)
6892 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
6893 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
6894 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
6895 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
6896 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
6898 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
6899 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
6902 #define GEN_CRLOGIC(name, tcg_op, opc) \
6903 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
6904 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
6905 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
6906 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
6907 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
6908 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
6909 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
6910 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
6911 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
6913 #undef GEN_MAC_HANDLER
6914 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6915 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
6916 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
6917 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
6918 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
6919 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
6920 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
6921 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
6922 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
6923 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
6924 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
6925 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
6926 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
6927 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
6928 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
6929 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
6930 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
6931 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
6932 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
6933 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
6934 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
6935 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
6936 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
6937 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
6938 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
6939 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
6940 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
6941 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
6942 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
6943 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
6944 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
6945 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
6946 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
6947 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
6948 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
6949 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
6950 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
6951 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
6952 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
6953 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
6954 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
6955 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
6956 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
6957 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
6959 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
6961 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
6963 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
6965 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
6967 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
6969 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
6971 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
6973 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
6975 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
6977 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
6979 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
6982 #include "translate/fp-ops.inc.c"
6984 #include "translate/vmx-ops.inc.c"
6986 #include "translate/vsx-ops.inc.c"
6988 #include "translate/dfp-ops.inc.c"
6990 #include "translate/spe-ops.inc.c"
6993 #include "helper_regs.h"
6994 #include "translate_init.inc.c"
6996 /*****************************************************************************/
6997 /* Misc PowerPC helpers */
6998 void ppc_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
7004 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
7005 CPUPPCState
*env
= &cpu
->env
;
7008 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
7009 TARGET_FMT_lx
" XER " TARGET_FMT_lx
" CPU#%d\n",
7010 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
),
7012 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
7013 TARGET_FMT_lx
" iidx %d didx %d\n",
7014 env
->msr
, env
->spr
[SPR_HID0
],
7015 env
->hflags
, env
->immu_idx
, env
->dmmu_idx
);
7016 #if !defined(NO_TIMER_DUMP)
7017 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
7018 #if !defined(CONFIG_USER_ONLY)
7022 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
7023 #if !defined(CONFIG_USER_ONLY)
7024 , cpu_ppc_load_decr(env
)
7028 for (i
= 0; i
< 32; i
++) {
7029 if ((i
& (RGPL
- 1)) == 0)
7030 cpu_fprintf(f
, "GPR%02d", i
);
7031 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
7032 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
7033 cpu_fprintf(f
, "\n");
7035 cpu_fprintf(f
, "CR ");
7036 for (i
= 0; i
< 8; i
++)
7037 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
7038 cpu_fprintf(f
, " [");
7039 for (i
= 0; i
< 8; i
++) {
7041 if (env
->crf
[i
] & 0x08)
7043 else if (env
->crf
[i
] & 0x04)
7045 else if (env
->crf
[i
] & 0x02)
7047 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
7049 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
7051 for (i
= 0; i
< 32; i
++) {
7052 if ((i
& (RFPL
- 1)) == 0)
7053 cpu_fprintf(f
, "FPR%02d", i
);
7054 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
7055 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
7056 cpu_fprintf(f
, "\n");
7058 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
7059 #if !defined(CONFIG_USER_ONLY)
7060 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
7061 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
7062 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
7063 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
7065 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
7066 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
7067 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
7068 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
7070 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
7071 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
7072 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
7073 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
7075 #if defined(TARGET_PPC64)
7076 if (env
->excp_model
== POWERPC_EXCP_POWER7
||
7077 env
->excp_model
== POWERPC_EXCP_POWER8
) {
7078 cpu_fprintf(f
, "HSRR0 " TARGET_FMT_lx
" HSRR1 " TARGET_FMT_lx
"\n",
7079 env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
]);
7082 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
7083 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
7084 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
7085 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
7086 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
7088 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
7089 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
7090 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
7091 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
7093 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
7094 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
7095 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
7096 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
7098 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
7099 " EPR " TARGET_FMT_lx
"\n",
7100 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
7101 env
->spr
[SPR_BOOKE_EPR
]);
7104 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
7105 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
7106 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
7107 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
7110 * IVORs are left out as they are large and do not change often --
7111 * they can be read with "p $ivor0", "p $ivor1", etc.
7115 #if defined(TARGET_PPC64)
7116 if (env
->flags
& POWERPC_FLAG_CFAR
) {
7117 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
7121 if (env
->spr_cb
[SPR_LPCR
].name
)
7122 cpu_fprintf(f
, " LPCR " TARGET_FMT_lx
"\n", env
->spr
[SPR_LPCR
]);
7124 switch (env
->mmu_model
) {
7125 case POWERPC_MMU_32B
:
7126 case POWERPC_MMU_601
:
7127 case POWERPC_MMU_SOFT_6xx
:
7128 case POWERPC_MMU_SOFT_74xx
:
7129 #if defined(TARGET_PPC64)
7130 case POWERPC_MMU_64B
:
7131 case POWERPC_MMU_2_03
:
7132 case POWERPC_MMU_2_06
:
7133 case POWERPC_MMU_2_07
:
7134 case POWERPC_MMU_3_00
:
7136 if (env
->spr_cb
[SPR_SDR1
].name
) { /* SDR1 Exists */
7137 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
" ", env
->spr
[SPR_SDR1
]);
7139 if (env
->spr_cb
[SPR_PTCR
].name
) { /* PTCR Exists */
7140 cpu_fprintf(f
, " PTCR " TARGET_FMT_lx
" ", env
->spr
[SPR_PTCR
]);
7142 cpu_fprintf(f
, " DAR " TARGET_FMT_lx
" DSISR " TARGET_FMT_lx
"\n",
7143 env
->spr
[SPR_DAR
], env
->spr
[SPR_DSISR
]);
7145 case POWERPC_MMU_BOOKE206
:
7146 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
7147 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
7148 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
7149 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
7151 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
7152 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
7153 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
7154 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
7156 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
7157 " TLB1CFG " TARGET_FMT_lx
"\n",
7158 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
7159 env
->spr
[SPR_BOOKE_TLB1CFG
]);
7170 void ppc_cpu_dump_statistics(CPUState
*cs
, FILE*f
,
7171 fprintf_function cpu_fprintf
, int flags
)
7173 #if defined(DO_PPC_STATISTICS)
7174 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
7175 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
7178 t1
= cpu
->env
.opcodes
;
7179 for (op1
= 0; op1
< 64; op1
++) {
7181 if (is_indirect_opcode(handler
)) {
7182 t2
= ind_table(handler
);
7183 for (op2
= 0; op2
< 32; op2
++) {
7185 if (is_indirect_opcode(handler
)) {
7186 t3
= ind_table(handler
);
7187 for (op3
= 0; op3
< 32; op3
++) {
7189 if (handler
->count
== 0)
7191 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
7192 "%016" PRIx64
" %" PRId64
"\n",
7193 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
7195 handler
->count
, handler
->count
);
7198 if (handler
->count
== 0)
7200 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
7201 "%016" PRIx64
" %" PRId64
"\n",
7202 op1
, op2
, op1
, op2
, handler
->oname
,
7203 handler
->count
, handler
->count
);
7207 if (handler
->count
== 0)
7209 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
7211 op1
, op1
, handler
->oname
,
7212 handler
->count
, handler
->count
);
7218 static void ppc_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
7220 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7221 CPUPPCState
*env
= cs
->env_ptr
;
7224 ctx
->exception
= POWERPC_EXCP_NONE
;
7225 ctx
->spr_cb
= env
->spr_cb
;
7227 ctx
->mem_idx
= env
->dmmu_idx
;
7229 #if !defined(CONFIG_USER_ONLY)
7230 ctx
->hv
= msr_hv
|| !env
->has_hv_mode
;
7232 ctx
->insns_flags
= env
->insns_flags
;
7233 ctx
->insns_flags2
= env
->insns_flags2
;
7234 ctx
->access_type
= -1;
7235 ctx
->need_access_type
= !(env
->mmu_model
& POWERPC_MMU_64B
);
7236 ctx
->le_mode
= !!(env
->hflags
& (1 << MSR_LE
));
7237 ctx
->default_tcg_memop_mask
= ctx
->le_mode
? MO_LE
: MO_BE
;
7238 #if defined(TARGET_PPC64)
7239 ctx
->sf_mode
= msr_is_64bit(env
, env
->msr
);
7240 ctx
->has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
7242 ctx
->lazy_tlb_flush
= env
->mmu_model
== POWERPC_MMU_32B
7243 || env
->mmu_model
== POWERPC_MMU_601
7244 || (env
->mmu_model
& POWERPC_MMU_64B
);
7246 ctx
->fpu_enabled
= !!msr_fp
;
7247 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
7248 ctx
->spe_enabled
= !!msr_spe
;
7250 ctx
->spe_enabled
= false;
7251 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
7252 ctx
->altivec_enabled
= !!msr_vr
;
7254 ctx
->altivec_enabled
= false;
7255 if ((env
->flags
& POWERPC_FLAG_VSX
) && msr_vsx
) {
7256 ctx
->vsx_enabled
= !!msr_vsx
;
7258 ctx
->vsx_enabled
= false;
7260 #if defined(TARGET_PPC64)
7261 if ((env
->flags
& POWERPC_FLAG_TM
) && msr_tm
) {
7262 ctx
->tm_enabled
= !!msr_tm
;
7264 ctx
->tm_enabled
= false;
7267 ctx
->gtse
= !!(env
->spr
[SPR_LPCR
] & LPCR_GTSE
);
7268 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
7269 ctx
->singlestep_enabled
= CPU_SINGLE_STEP
;
7271 ctx
->singlestep_enabled
= 0;
7272 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
7273 ctx
->singlestep_enabled
|= CPU_BRANCH_STEP
;
7274 if (unlikely(ctx
->base
.singlestep_enabled
)) {
7275 ctx
->singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
7277 #if defined (DO_SINGLE_STEP) && 0
7278 /* Single step trace mode */
7282 bound
= -(ctx
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
7283 ctx
->base
.max_insns
= MIN(ctx
->base
.max_insns
, bound
);
7286 static void ppc_tr_tb_start(DisasContextBase
*db
, CPUState
*cs
)
7290 static void ppc_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
7292 tcg_gen_insn_start(dcbase
->pc_next
);
7295 static bool ppc_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cs
,
7296 const CPUBreakpoint
*bp
)
7298 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7300 gen_debug_exception(ctx
);
7301 /* The address covered by the breakpoint must be included in
7302 [tb->pc, tb->pc + tb->size) in order to for it to be
7303 properly cleared -- thus we increment the PC here so that
7304 the logic setting tb->size below does the right thing. */
7305 ctx
->base
.pc_next
+= 4;
7309 static void ppc_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
7311 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7312 CPUPPCState
*env
= cs
->env_ptr
;
7313 opc_handler_t
**table
, *handler
;
7315 LOG_DISAS("----------------\n");
7316 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
7317 ctx
->base
.pc_next
, ctx
->mem_idx
, (int)msr_ir
);
7319 if (unlikely(need_byteswap(ctx
))) {
7320 ctx
->opcode
= bswap32(cpu_ldl_code(env
, ctx
->base
.pc_next
));
7322 ctx
->opcode
= cpu_ldl_code(env
, ctx
->base
.pc_next
);
7324 LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n",
7325 ctx
->opcode
, opc1(ctx
->opcode
), opc2(ctx
->opcode
),
7326 opc3(ctx
->opcode
), opc4(ctx
->opcode
),
7327 ctx
->le_mode
? "little" : "big");
7328 ctx
->base
.pc_next
+= 4;
7329 table
= env
->opcodes
;
7330 handler
= table
[opc1(ctx
->opcode
)];
7331 if (is_indirect_opcode(handler
)) {
7332 table
= ind_table(handler
);
7333 handler
= table
[opc2(ctx
->opcode
)];
7334 if (is_indirect_opcode(handler
)) {
7335 table
= ind_table(handler
);
7336 handler
= table
[opc3(ctx
->opcode
)];
7337 if (is_indirect_opcode(handler
)) {
7338 table
= ind_table(handler
);
7339 handler
= table
[opc4(ctx
->opcode
)];
7343 /* Is opcode *REALLY* valid ? */
7344 if (unlikely(handler
->handler
== &gen_invalid
)) {
7345 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
7346 "%02x - %02x - %02x - %02x (%08x) "
7347 TARGET_FMT_lx
" %d\n",
7348 opc1(ctx
->opcode
), opc2(ctx
->opcode
),
7349 opc3(ctx
->opcode
), opc4(ctx
->opcode
),
7350 ctx
->opcode
, ctx
->base
.pc_next
- 4, (int)msr_ir
);
7354 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
)
7355 && Rc(ctx
->opcode
))) {
7356 inval
= handler
->inval2
;
7358 inval
= handler
->inval1
;
7361 if (unlikely((ctx
->opcode
& inval
) != 0)) {
7362 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
7363 "%02x - %02x - %02x - %02x (%08x) "
7364 TARGET_FMT_lx
"\n", ctx
->opcode
& inval
,
7365 opc1(ctx
->opcode
), opc2(ctx
->opcode
),
7366 opc3(ctx
->opcode
), opc4(ctx
->opcode
),
7367 ctx
->opcode
, ctx
->base
.pc_next
- 4);
7368 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7369 ctx
->base
.is_jmp
= DISAS_NORETURN
;
7373 (*(handler
->handler
))(ctx
);
7374 #if defined(DO_PPC_STATISTICS)
7377 /* Check trace mode exceptions */
7378 if (unlikely(ctx
->singlestep_enabled
& CPU_SINGLE_STEP
&&
7379 (ctx
->base
.pc_next
<= 0x100 || ctx
->base
.pc_next
> 0xF00) &&
7380 ctx
->exception
!= POWERPC_SYSCALL
&&
7381 ctx
->exception
!= POWERPC_EXCP_TRAP
&&
7382 ctx
->exception
!= POWERPC_EXCP_BRANCH
)) {
7383 gen_exception_nip(ctx
, POWERPC_EXCP_TRACE
, ctx
->base
.pc_next
);
7386 if (tcg_check_temp_count()) {
7387 qemu_log("Opcode %02x %02x %02x %02x (%08x) leaked "
7388 "temporaries\n", opc1(ctx
->opcode
), opc2(ctx
->opcode
),
7389 opc3(ctx
->opcode
), opc4(ctx
->opcode
), ctx
->opcode
);
7392 ctx
->base
.is_jmp
= ctx
->exception
== POWERPC_EXCP_NONE
?
7393 DISAS_NEXT
: DISAS_NORETURN
;
7396 static void ppc_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
7398 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7400 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
7401 gen_goto_tb(ctx
, 0, ctx
->base
.pc_next
);
7402 } else if (ctx
->exception
!= POWERPC_EXCP_BRANCH
) {
7403 if (unlikely(ctx
->base
.singlestep_enabled
)) {
7404 gen_debug_exception(ctx
);
7406 /* Generate the return instruction */
7411 static void ppc_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cs
)
7413 qemu_log("IN: %s\n", lookup_symbol(dcbase
->pc_first
));
7414 log_target_disas(cs
, dcbase
->pc_first
, dcbase
->tb
->size
);
7417 static const TranslatorOps ppc_tr_ops
= {
7418 .init_disas_context
= ppc_tr_init_disas_context
,
7419 .tb_start
= ppc_tr_tb_start
,
7420 .insn_start
= ppc_tr_insn_start
,
7421 .breakpoint_check
= ppc_tr_breakpoint_check
,
7422 .translate_insn
= ppc_tr_translate_insn
,
7423 .tb_stop
= ppc_tr_tb_stop
,
7424 .disas_log
= ppc_tr_disas_log
,
7427 void gen_intermediate_code(CPUState
*cs
, struct TranslationBlock
*tb
)
7431 translator_loop(&ppc_tr_ops
, &ctx
.base
, cs
, tb
);
7434 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
,