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"
37 #define CPU_SINGLE_STEP 0x1
38 #define CPU_BRANCH_STEP 0x2
39 #define GDBSTUB_SINGLE_STEP 0x4
41 /* Include definitions for instructions classes and implementations flags */
42 //#define PPC_DEBUG_DISAS
43 //#define DO_PPC_STATISTICS
45 #ifdef PPC_DEBUG_DISAS
46 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
48 # define LOG_DISAS(...) do { } while (0)
50 /*****************************************************************************/
51 /* Code translation helpers */
53 /* global register indexes */
54 static TCGv_env cpu_env
;
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
;
75 static TCGv cpu_reserve
;
76 static TCGv cpu_fpscr
;
77 static TCGv_i32 cpu_access_type
;
79 #include "exec/gen-icount.h"
81 void ppc_translate_init(void)
85 size_t cpu_reg_names_size
;
86 static int done_init
= 0;
91 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
92 tcg_ctx
.tcg_env
= cpu_env
;
95 cpu_reg_names_size
= sizeof(cpu_reg_names
);
97 for (i
= 0; i
< 8; i
++) {
98 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
99 cpu_crf
[i
] = tcg_global_mem_new_i32(cpu_env
,
100 offsetof(CPUPPCState
, crf
[i
]), p
);
102 cpu_reg_names_size
-= 5;
105 for (i
= 0; i
< 32; i
++) {
106 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
107 cpu_gpr
[i
] = tcg_global_mem_new(cpu_env
,
108 offsetof(CPUPPCState
, gpr
[i
]), p
);
109 p
+= (i
< 10) ? 3 : 4;
110 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
111 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
112 cpu_gprh
[i
] = tcg_global_mem_new(cpu_env
,
113 offsetof(CPUPPCState
, gprh
[i
]), p
);
114 p
+= (i
< 10) ? 4 : 5;
115 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
117 snprintf(p
, cpu_reg_names_size
, "fp%d", i
);
118 cpu_fpr
[i
] = tcg_global_mem_new_i64(cpu_env
,
119 offsetof(CPUPPCState
, fpr
[i
]), p
);
120 p
+= (i
< 10) ? 4 : 5;
121 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
123 snprintf(p
, cpu_reg_names_size
, "avr%dH", i
);
124 #ifdef HOST_WORDS_BIGENDIAN
125 cpu_avrh
[i
] = tcg_global_mem_new_i64(cpu_env
,
126 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
128 cpu_avrh
[i
] = tcg_global_mem_new_i64(cpu_env
,
129 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
131 p
+= (i
< 10) ? 6 : 7;
132 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
134 snprintf(p
, cpu_reg_names_size
, "avr%dL", i
);
135 #ifdef HOST_WORDS_BIGENDIAN
136 cpu_avrl
[i
] = tcg_global_mem_new_i64(cpu_env
,
137 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
139 cpu_avrl
[i
] = tcg_global_mem_new_i64(cpu_env
,
140 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
142 p
+= (i
< 10) ? 6 : 7;
143 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
144 snprintf(p
, cpu_reg_names_size
, "vsr%d", i
);
145 cpu_vsr
[i
] = tcg_global_mem_new_i64(cpu_env
,
146 offsetof(CPUPPCState
, vsr
[i
]), p
);
147 p
+= (i
< 10) ? 5 : 6;
148 cpu_reg_names_size
-= (i
< 10) ? 5 : 6;
151 cpu_nip
= tcg_global_mem_new(cpu_env
,
152 offsetof(CPUPPCState
, nip
), "nip");
154 cpu_msr
= tcg_global_mem_new(cpu_env
,
155 offsetof(CPUPPCState
, msr
), "msr");
157 cpu_ctr
= tcg_global_mem_new(cpu_env
,
158 offsetof(CPUPPCState
, ctr
), "ctr");
160 cpu_lr
= tcg_global_mem_new(cpu_env
,
161 offsetof(CPUPPCState
, lr
), "lr");
163 #if defined(TARGET_PPC64)
164 cpu_cfar
= tcg_global_mem_new(cpu_env
,
165 offsetof(CPUPPCState
, cfar
), "cfar");
168 cpu_xer
= tcg_global_mem_new(cpu_env
,
169 offsetof(CPUPPCState
, xer
), "xer");
170 cpu_so
= tcg_global_mem_new(cpu_env
,
171 offsetof(CPUPPCState
, so
), "SO");
172 cpu_ov
= tcg_global_mem_new(cpu_env
,
173 offsetof(CPUPPCState
, ov
), "OV");
174 cpu_ca
= tcg_global_mem_new(cpu_env
,
175 offsetof(CPUPPCState
, ca
), "CA");
177 cpu_reserve
= tcg_global_mem_new(cpu_env
,
178 offsetof(CPUPPCState
, reserve_addr
),
181 cpu_fpscr
= tcg_global_mem_new(cpu_env
,
182 offsetof(CPUPPCState
, fpscr
), "fpscr");
184 cpu_access_type
= tcg_global_mem_new_i32(cpu_env
,
185 offsetof(CPUPPCState
, access_type
), "access_type");
190 /* internal defines */
191 struct DisasContext
{
192 struct TranslationBlock
*tb
;
196 /* Routine used to access memory */
197 bool pr
, hv
, dr
, le_mode
;
199 bool need_access_type
;
202 /* Translation flags */
203 TCGMemOp default_tcg_memop_mask
;
204 #if defined(TARGET_PPC64)
209 bool altivec_enabled
;
213 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
214 int singlestep_enabled
;
215 uint64_t insns_flags
;
216 uint64_t insns_flags2
;
219 /* Return true iff byteswap is needed in a scalar memop */
220 static inline bool need_byteswap(const DisasContext
*ctx
)
222 #if defined(TARGET_WORDS_BIGENDIAN)
225 return !ctx
->le_mode
;
229 /* True when active word size < size of target_long. */
231 # define NARROW_MODE(C) (!(C)->sf_mode)
233 # define NARROW_MODE(C) 0
236 struct opc_handler_t
{
237 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
239 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
241 /* instruction type */
243 /* extended instruction type */
246 void (*handler
)(DisasContext
*ctx
);
247 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
250 #if defined(DO_PPC_STATISTICS)
255 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
257 if (ctx
->need_access_type
&& ctx
->access_type
!= access_type
) {
258 tcg_gen_movi_i32(cpu_access_type
, access_type
);
259 ctx
->access_type
= access_type
;
263 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
265 if (NARROW_MODE(ctx
)) {
268 tcg_gen_movi_tl(cpu_nip
, nip
);
271 static void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
275 /* These are all synchronous exceptions, we set the PC back to
276 * the faulting instruction
278 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
279 gen_update_nip(ctx
, ctx
->nip
- 4);
281 t0
= tcg_const_i32(excp
);
282 t1
= tcg_const_i32(error
);
283 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
284 tcg_temp_free_i32(t0
);
285 tcg_temp_free_i32(t1
);
286 ctx
->exception
= (excp
);
289 static void gen_exception(DisasContext
*ctx
, uint32_t excp
)
293 /* These are all synchronous exceptions, we set the PC back to
294 * the faulting instruction
296 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
297 gen_update_nip(ctx
, ctx
->nip
- 4);
299 t0
= tcg_const_i32(excp
);
300 gen_helper_raise_exception(cpu_env
, t0
);
301 tcg_temp_free_i32(t0
);
302 ctx
->exception
= (excp
);
305 static void gen_exception_nip(DisasContext
*ctx
, uint32_t excp
,
310 gen_update_nip(ctx
, nip
);
311 t0
= tcg_const_i32(excp
);
312 gen_helper_raise_exception(cpu_env
, t0
);
313 tcg_temp_free_i32(t0
);
314 ctx
->exception
= (excp
);
317 static void gen_debug_exception(DisasContext
*ctx
)
321 /* These are all synchronous exceptions, we set the PC back to
322 * the faulting instruction
324 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
325 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
326 gen_update_nip(ctx
, ctx
->nip
);
328 t0
= tcg_const_i32(EXCP_DEBUG
);
329 gen_helper_raise_exception(cpu_env
, t0
);
330 tcg_temp_free_i32(t0
);
333 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
335 /* Will be converted to program check if needed */
336 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_INVAL
| error
);
339 static inline void gen_priv_exception(DisasContext
*ctx
, uint32_t error
)
341 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_PRIV
| error
);
344 static inline void gen_hvpriv_exception(DisasContext
*ctx
, uint32_t error
)
346 /* Will be converted to program check if needed */
347 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_PRIV
| error
);
350 /* Stop translation */
351 static inline void gen_stop_exception(DisasContext
*ctx
)
353 gen_update_nip(ctx
, ctx
->nip
);
354 ctx
->exception
= POWERPC_EXCP_STOP
;
357 #ifndef CONFIG_USER_ONLY
358 /* No need to update nip here, as execution flow will change */
359 static inline void gen_sync_exception(DisasContext
*ctx
)
361 ctx
->exception
= POWERPC_EXCP_SYNC
;
365 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
366 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
368 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
369 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
371 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
372 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
374 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
375 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
377 #define GEN_HANDLER_E_2(name, opc1, opc2, opc3, opc4, inval, type, type2) \
378 GEN_OPCODE3(name, opc1, opc2, opc3, opc4, inval, type, type2)
380 #define GEN_HANDLER2_E_2(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) \
381 GEN_OPCODE4(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2)
383 typedef struct opcode_t
{
384 unsigned char opc1
, opc2
, opc3
, opc4
;
385 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
386 unsigned char pad
[4];
388 opc_handler_t handler
;
392 /* Helpers for priv. check */
395 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \
398 #if defined(CONFIG_USER_ONLY)
399 #define CHK_HV GEN_PRIV
400 #define CHK_SV GEN_PRIV
401 #define CHK_HVRM GEN_PRIV
405 if (unlikely(ctx->pr || !ctx->hv)) { \
411 if (unlikely(ctx->pr)) { \
417 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
426 /*****************************************************************************/
427 /*** Instruction decoding ***/
428 #define EXTRACT_HELPER(name, shift, nb) \
429 static inline uint32_t name(uint32_t opcode) \
431 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
434 #define EXTRACT_SHELPER(name, shift, nb) \
435 static inline int32_t name(uint32_t opcode) \
437 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
440 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
441 static inline uint32_t name(uint32_t opcode) \
443 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
444 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
447 #define EXTRACT_HELPER_DXFORM(name, \
448 d0_bits, shift_op_d0, shift_d0, \
449 d1_bits, shift_op_d1, shift_d1, \
450 d2_bits, shift_op_d2, shift_d2) \
451 static inline int16_t name(uint32_t opcode) \
454 (((opcode >> (shift_op_d0)) & ((1 << (d0_bits)) - 1)) << (shift_d0)) | \
455 (((opcode >> (shift_op_d1)) & ((1 << (d1_bits)) - 1)) << (shift_d1)) | \
456 (((opcode >> (shift_op_d2)) & ((1 << (d2_bits)) - 1)) << (shift_d2)); \
461 EXTRACT_HELPER(opc1
, 26, 6);
463 EXTRACT_HELPER(opc2
, 1, 5);
465 EXTRACT_HELPER(opc3
, 6, 5);
467 EXTRACT_HELPER(opc4
, 16, 5);
468 /* Update Cr0 flags */
469 EXTRACT_HELPER(Rc
, 0, 1);
470 /* Update Cr6 flags (Altivec) */
471 EXTRACT_HELPER(Rc21
, 10, 1);
473 EXTRACT_HELPER(rD
, 21, 5);
475 EXTRACT_HELPER(rS
, 21, 5);
477 EXTRACT_HELPER(rA
, 16, 5);
479 EXTRACT_HELPER(rB
, 11, 5);
481 EXTRACT_HELPER(rC
, 6, 5);
483 EXTRACT_HELPER(crfD
, 23, 3);
484 EXTRACT_HELPER(crfS
, 18, 3);
485 EXTRACT_HELPER(crbD
, 21, 5);
486 EXTRACT_HELPER(crbA
, 16, 5);
487 EXTRACT_HELPER(crbB
, 11, 5);
489 EXTRACT_HELPER(_SPR
, 11, 10);
490 static inline uint32_t SPR(uint32_t opcode
)
492 uint32_t sprn
= _SPR(opcode
);
494 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
496 /*** Get constants ***/
497 /* 16 bits signed immediate value */
498 EXTRACT_SHELPER(SIMM
, 0, 16);
499 /* 16 bits unsigned immediate value */
500 EXTRACT_HELPER(UIMM
, 0, 16);
501 /* 5 bits signed immediate value */
502 EXTRACT_HELPER(SIMM5
, 16, 5);
503 /* 5 bits signed immediate value */
504 EXTRACT_HELPER(UIMM5
, 16, 5);
505 /* 4 bits unsigned immediate value */
506 EXTRACT_HELPER(UIMM4
, 16, 4);
508 EXTRACT_HELPER(NB
, 11, 5);
510 EXTRACT_HELPER(SH
, 11, 5);
511 /* Vector shift count */
512 EXTRACT_HELPER(VSH
, 6, 4);
514 EXTRACT_HELPER(MB
, 6, 5);
516 EXTRACT_HELPER(ME
, 1, 5);
518 EXTRACT_HELPER(TO
, 21, 5);
520 EXTRACT_HELPER(CRM
, 12, 8);
522 #ifndef CONFIG_USER_ONLY
523 EXTRACT_HELPER(SR
, 16, 4);
527 EXTRACT_HELPER(FPBF
, 23, 3);
528 EXTRACT_HELPER(FPIMM
, 12, 4);
529 EXTRACT_HELPER(FPL
, 25, 1);
530 EXTRACT_HELPER(FPFLM
, 17, 8);
531 EXTRACT_HELPER(FPW
, 16, 1);
534 EXTRACT_HELPER_DXFORM(DX
, 10, 6, 6, 5, 16, 1, 1, 0, 0)
535 #if defined(TARGET_PPC64)
537 EXTRACT_HELPER(L
, 16, 2);
540 /*** Jump target decoding ***/
541 /* Immediate address */
542 static inline target_ulong
LI(uint32_t opcode
)
544 return (opcode
>> 0) & 0x03FFFFFC;
547 static inline uint32_t BD(uint32_t opcode
)
549 return (opcode
>> 0) & 0xFFFC;
552 EXTRACT_HELPER(BO
, 21, 5);
553 EXTRACT_HELPER(BI
, 16, 5);
554 /* Absolute/relative address */
555 EXTRACT_HELPER(AA
, 1, 1);
557 EXTRACT_HELPER(LK
, 0, 1);
560 EXTRACT_HELPER(DCM
, 10, 6)
563 EXTRACT_HELPER(RMC
, 9, 2)
565 EXTRACT_HELPER_SPLIT(xT
, 0, 1, 21, 5);
566 EXTRACT_HELPER_SPLIT(xS
, 0, 1, 21, 5);
567 EXTRACT_HELPER_SPLIT(xA
, 2, 1, 16, 5);
568 EXTRACT_HELPER_SPLIT(xB
, 1, 1, 11, 5);
569 EXTRACT_HELPER_SPLIT(xC
, 3, 1, 6, 5);
570 EXTRACT_HELPER(DM
, 8, 2);
571 EXTRACT_HELPER(UIM
, 16, 2);
572 EXTRACT_HELPER(SHW
, 8, 2);
573 EXTRACT_HELPER(SP
, 19, 2);
574 EXTRACT_HELPER(IMM8
, 11, 8);
576 /*****************************************************************************/
577 /* PowerPC instructions table */
579 #if defined(DO_PPC_STATISTICS)
580 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
590 .handler = &gen_##name, \
591 .oname = stringify(name), \
593 .oname = stringify(name), \
595 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
606 .handler = &gen_##name, \
607 .oname = stringify(name), \
609 .oname = stringify(name), \
611 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
621 .handler = &gen_##name, \
626 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
636 .handler = &gen_##name, \
637 .oname = stringify(name), \
639 .oname = stringify(name), \
641 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
651 .handler = &gen_##name, \
657 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
667 .handler = &gen_##name, \
669 .oname = stringify(name), \
671 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
682 .handler = &gen_##name, \
684 .oname = stringify(name), \
686 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
696 .handler = &gen_##name, \
700 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
710 .handler = &gen_##name, \
712 .oname = stringify(name), \
714 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
724 .handler = &gen_##name, \
730 /* SPR load/store helpers */
731 static inline void gen_load_spr(TCGv t
, int reg
)
733 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
736 static inline void gen_store_spr(int reg
, TCGv t
)
738 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
741 /* Invalid instruction */
742 static void gen_invalid(DisasContext
*ctx
)
744 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
747 static opc_handler_t invalid_handler
= {
748 .inval1
= 0xFFFFFFFF,
749 .inval2
= 0xFFFFFFFF,
752 .handler
= gen_invalid
,
755 /*** Integer comparison ***/
757 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
759 TCGv t0
= tcg_temp_new();
760 TCGv_i32 t1
= tcg_temp_new_i32();
762 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
764 tcg_gen_setcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
);
765 tcg_gen_trunc_tl_i32(t1
, t0
);
766 tcg_gen_shli_i32(t1
, t1
, CRF_LT
);
767 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
769 tcg_gen_setcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
);
770 tcg_gen_trunc_tl_i32(t1
, t0
);
771 tcg_gen_shli_i32(t1
, t1
, CRF_GT
);
772 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
774 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, arg0
, arg1
);
775 tcg_gen_trunc_tl_i32(t1
, t0
);
776 tcg_gen_shli_i32(t1
, t1
, CRF_EQ
);
777 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
780 tcg_temp_free_i32(t1
);
783 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
785 TCGv t0
= tcg_const_tl(arg1
);
786 gen_op_cmp(arg0
, t0
, s
, crf
);
790 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
796 tcg_gen_ext32s_tl(t0
, arg0
);
797 tcg_gen_ext32s_tl(t1
, arg1
);
799 tcg_gen_ext32u_tl(t0
, arg0
);
800 tcg_gen_ext32u_tl(t1
, arg1
);
802 gen_op_cmp(t0
, t1
, s
, crf
);
807 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
809 TCGv t0
= tcg_const_tl(arg1
);
810 gen_op_cmp32(arg0
, t0
, s
, crf
);
814 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
816 if (NARROW_MODE(ctx
)) {
817 gen_op_cmpi32(reg
, 0, 1, 0);
819 gen_op_cmpi(reg
, 0, 1, 0);
824 static void gen_cmp(DisasContext
*ctx
)
826 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
827 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
828 1, crfD(ctx
->opcode
));
830 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
831 1, crfD(ctx
->opcode
));
836 static void gen_cmpi(DisasContext
*ctx
)
838 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
839 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
840 1, crfD(ctx
->opcode
));
842 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
843 1, crfD(ctx
->opcode
));
848 static void gen_cmpl(DisasContext
*ctx
)
850 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
851 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
852 0, crfD(ctx
->opcode
));
854 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
855 0, crfD(ctx
->opcode
));
860 static void gen_cmpli(DisasContext
*ctx
)
862 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
863 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
864 0, crfD(ctx
->opcode
));
866 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
867 0, crfD(ctx
->opcode
));
871 /* cmprb - range comparison: isupper, isaplha, islower*/
872 static void gen_cmprb(DisasContext
*ctx
)
874 TCGv_i32 src1
= tcg_temp_new_i32();
875 TCGv_i32 src2
= tcg_temp_new_i32();
876 TCGv_i32 src2lo
= tcg_temp_new_i32();
877 TCGv_i32 src2hi
= tcg_temp_new_i32();
878 TCGv_i32 crf
= cpu_crf
[crfD(ctx
->opcode
)];
880 tcg_gen_trunc_tl_i32(src1
, cpu_gpr
[rA(ctx
->opcode
)]);
881 tcg_gen_trunc_tl_i32(src2
, cpu_gpr
[rB(ctx
->opcode
)]);
883 tcg_gen_andi_i32(src1
, src1
, 0xFF);
884 tcg_gen_ext8u_i32(src2lo
, src2
);
885 tcg_gen_shri_i32(src2
, src2
, 8);
886 tcg_gen_ext8u_i32(src2hi
, src2
);
888 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
889 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
890 tcg_gen_and_i32(crf
, src2lo
, src2hi
);
892 if (ctx
->opcode
& 0x00200000) {
893 tcg_gen_shri_i32(src2
, src2
, 8);
894 tcg_gen_ext8u_i32(src2lo
, src2
);
895 tcg_gen_shri_i32(src2
, src2
, 8);
896 tcg_gen_ext8u_i32(src2hi
, src2
);
897 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
898 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
899 tcg_gen_and_i32(src2lo
, src2lo
, src2hi
);
900 tcg_gen_or_i32(crf
, crf
, src2lo
);
902 tcg_gen_shli_i32(crf
, crf
, CRF_GT
);
903 tcg_temp_free_i32(src1
);
904 tcg_temp_free_i32(src2
);
905 tcg_temp_free_i32(src2lo
);
906 tcg_temp_free_i32(src2hi
);
909 #if defined(TARGET_PPC64)
911 static void gen_cmpeqb(DisasContext
*ctx
)
913 gen_helper_cmpeqb(cpu_crf
[crfD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
914 cpu_gpr
[rB(ctx
->opcode
)]);
918 /* isel (PowerPC 2.03 specification) */
919 static void gen_isel(DisasContext
*ctx
)
921 uint32_t bi
= rC(ctx
->opcode
);
922 uint32_t mask
= 0x08 >> (bi
& 0x03);
923 TCGv t0
= tcg_temp_new();
926 tcg_gen_extu_i32_tl(t0
, cpu_crf
[bi
>> 2]);
927 tcg_gen_andi_tl(t0
, t0
, mask
);
929 zr
= tcg_const_tl(0);
930 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rD(ctx
->opcode
)], t0
, zr
,
931 rA(ctx
->opcode
) ? cpu_gpr
[rA(ctx
->opcode
)] : zr
,
932 cpu_gpr
[rB(ctx
->opcode
)]);
937 /* cmpb: PowerPC 2.05 specification */
938 static void gen_cmpb(DisasContext
*ctx
)
940 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
941 cpu_gpr
[rB(ctx
->opcode
)]);
944 /*** Integer arithmetic ***/
946 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
947 TCGv arg1
, TCGv arg2
, int sub
)
949 TCGv t0
= tcg_temp_new();
951 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
952 tcg_gen_xor_tl(t0
, arg1
, arg2
);
954 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
956 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
959 if (NARROW_MODE(ctx
)) {
960 tcg_gen_ext32s_tl(cpu_ov
, cpu_ov
);
962 tcg_gen_shri_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1);
963 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
966 /* Common add function */
967 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
968 TCGv arg2
, bool add_ca
, bool compute_ca
,
969 bool compute_ov
, bool compute_rc0
)
973 if (compute_ca
|| compute_ov
) {
978 if (NARROW_MODE(ctx
)) {
979 /* Caution: a non-obvious corner case of the spec is that we
980 must produce the *entire* 64-bit addition, but produce the
981 carry into bit 32. */
982 TCGv t1
= tcg_temp_new();
983 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
984 tcg_gen_add_tl(t0
, arg1
, arg2
);
986 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
988 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changed w/ carry */
990 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
991 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
993 TCGv zero
= tcg_const_tl(0);
995 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
996 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
998 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
1000 tcg_temp_free(zero
);
1003 tcg_gen_add_tl(t0
, arg1
, arg2
);
1005 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1010 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
1012 if (unlikely(compute_rc0
)) {
1013 gen_set_Rc0(ctx
, t0
);
1016 if (!TCGV_EQUAL(t0
, ret
)) {
1017 tcg_gen_mov_tl(ret
, t0
);
1021 /* Add functions with two operands */
1022 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
1023 static void glue(gen_, name)(DisasContext *ctx) \
1025 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1026 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1027 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1029 /* Add functions with one operand and one immediate */
1030 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
1031 add_ca, compute_ca, compute_ov) \
1032 static void glue(gen_, name)(DisasContext *ctx) \
1034 TCGv t0 = tcg_const_tl(const_val); \
1035 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1036 cpu_gpr[rA(ctx->opcode)], t0, \
1037 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1038 tcg_temp_free(t0); \
1041 /* add add. addo addo. */
1042 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
1043 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
1044 /* addc addc. addco addco. */
1045 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
1046 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
1047 /* adde adde. addeo addeo. */
1048 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
1049 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
1050 /* addme addme. addmeo addmeo. */
1051 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
1052 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
1053 /* addze addze. addzeo addzeo.*/
1054 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
1055 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
1057 static void gen_addi(DisasContext
*ctx
)
1059 target_long simm
= SIMM(ctx
->opcode
);
1061 if (rA(ctx
->opcode
) == 0) {
1063 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
1065 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
1066 cpu_gpr
[rA(ctx
->opcode
)], simm
);
1070 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
1072 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1073 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1074 c
, 0, 1, 0, compute_rc0
);
1078 static void gen_addic(DisasContext
*ctx
)
1080 gen_op_addic(ctx
, 0);
1083 static void gen_addic_(DisasContext
*ctx
)
1085 gen_op_addic(ctx
, 1);
1089 static void gen_addis(DisasContext
*ctx
)
1091 target_long simm
= SIMM(ctx
->opcode
);
1093 if (rA(ctx
->opcode
) == 0) {
1095 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
1097 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
1098 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
1103 static void gen_addpcis(DisasContext
*ctx
)
1105 target_long d
= DX(ctx
->opcode
);
1107 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], ctx
->nip
+ (d
<< 16));
1110 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1111 TCGv arg2
, int sign
, int compute_ov
)
1113 TCGv_i32 t0
= tcg_temp_new_i32();
1114 TCGv_i32 t1
= tcg_temp_new_i32();
1115 TCGv_i32 t2
= tcg_temp_new_i32();
1116 TCGv_i32 t3
= tcg_temp_new_i32();
1118 tcg_gen_trunc_tl_i32(t0
, arg1
);
1119 tcg_gen_trunc_tl_i32(t1
, arg2
);
1121 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1122 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1123 tcg_gen_and_i32(t2
, t2
, t3
);
1124 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1125 tcg_gen_or_i32(t2
, t2
, t3
);
1126 tcg_gen_movi_i32(t3
, 0);
1127 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1128 tcg_gen_div_i32(t3
, t0
, t1
);
1129 tcg_gen_extu_i32_tl(ret
, t3
);
1131 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t1
, 0);
1132 tcg_gen_movi_i32(t3
, 0);
1133 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1134 tcg_gen_divu_i32(t3
, t0
, t1
);
1135 tcg_gen_extu_i32_tl(ret
, t3
);
1138 tcg_gen_extu_i32_tl(cpu_ov
, t2
);
1139 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1141 tcg_temp_free_i32(t0
);
1142 tcg_temp_free_i32(t1
);
1143 tcg_temp_free_i32(t2
);
1144 tcg_temp_free_i32(t3
);
1146 if (unlikely(Rc(ctx
->opcode
) != 0))
1147 gen_set_Rc0(ctx
, ret
);
1150 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1151 static void glue(gen_, name)(DisasContext *ctx) \
1153 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1154 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1155 sign, compute_ov); \
1157 /* divwu divwu. divwuo divwuo. */
1158 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1159 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1160 /* divw divw. divwo divwo. */
1161 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1162 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1164 /* div[wd]eu[o][.] */
1165 #define GEN_DIVE(name, hlpr, compute_ov) \
1166 static void gen_##name(DisasContext *ctx) \
1168 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1169 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1170 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1171 tcg_temp_free_i32(t0); \
1172 if (unlikely(Rc(ctx->opcode) != 0)) { \
1173 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1177 GEN_DIVE(divweu
, divweu
, 0);
1178 GEN_DIVE(divweuo
, divweu
, 1);
1179 GEN_DIVE(divwe
, divwe
, 0);
1180 GEN_DIVE(divweo
, divwe
, 1);
1182 #if defined(TARGET_PPC64)
1183 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1184 TCGv arg2
, int sign
, int compute_ov
)
1186 TCGv_i64 t0
= tcg_temp_new_i64();
1187 TCGv_i64 t1
= tcg_temp_new_i64();
1188 TCGv_i64 t2
= tcg_temp_new_i64();
1189 TCGv_i64 t3
= tcg_temp_new_i64();
1191 tcg_gen_mov_i64(t0
, arg1
);
1192 tcg_gen_mov_i64(t1
, arg2
);
1194 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1195 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1196 tcg_gen_and_i64(t2
, t2
, t3
);
1197 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1198 tcg_gen_or_i64(t2
, t2
, t3
);
1199 tcg_gen_movi_i64(t3
, 0);
1200 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1201 tcg_gen_div_i64(ret
, t0
, t1
);
1203 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t1
, 0);
1204 tcg_gen_movi_i64(t3
, 0);
1205 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1206 tcg_gen_divu_i64(ret
, t0
, t1
);
1209 tcg_gen_mov_tl(cpu_ov
, t2
);
1210 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1212 tcg_temp_free_i64(t0
);
1213 tcg_temp_free_i64(t1
);
1214 tcg_temp_free_i64(t2
);
1215 tcg_temp_free_i64(t3
);
1217 if (unlikely(Rc(ctx
->opcode
) != 0))
1218 gen_set_Rc0(ctx
, ret
);
1221 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1222 static void glue(gen_, name)(DisasContext *ctx) \
1224 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1225 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1226 sign, compute_ov); \
1228 /* divwu divwu. divwuo divwuo. */
1229 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1230 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1231 /* divw divw. divwo divwo. */
1232 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1233 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1235 GEN_DIVE(divdeu
, divdeu
, 0);
1236 GEN_DIVE(divdeuo
, divdeu
, 1);
1237 GEN_DIVE(divde
, divde
, 0);
1238 GEN_DIVE(divdeo
, divde
, 1);
1241 static inline void gen_op_arith_modw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1242 TCGv arg2
, int sign
)
1244 TCGv_i32 t0
= tcg_temp_new_i32();
1245 TCGv_i32 t1
= tcg_temp_new_i32();
1247 tcg_gen_trunc_tl_i32(t0
, arg1
);
1248 tcg_gen_trunc_tl_i32(t1
, arg2
);
1250 TCGv_i32 t2
= tcg_temp_new_i32();
1251 TCGv_i32 t3
= tcg_temp_new_i32();
1252 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1253 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1254 tcg_gen_and_i32(t2
, t2
, t3
);
1255 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1256 tcg_gen_or_i32(t2
, t2
, t3
);
1257 tcg_gen_movi_i32(t3
, 0);
1258 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1259 tcg_gen_rem_i32(t3
, t0
, t1
);
1260 tcg_gen_ext_i32_tl(ret
, t3
);
1261 tcg_temp_free_i32(t2
);
1262 tcg_temp_free_i32(t3
);
1264 TCGv_i32 t2
= tcg_const_i32(1);
1265 TCGv_i32 t3
= tcg_const_i32(0);
1266 tcg_gen_movcond_i32(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1267 tcg_gen_remu_i32(t3
, t0
, t1
);
1268 tcg_gen_extu_i32_tl(ret
, t3
);
1269 tcg_temp_free_i32(t2
);
1270 tcg_temp_free_i32(t3
);
1272 tcg_temp_free_i32(t0
);
1273 tcg_temp_free_i32(t1
);
1276 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
1277 static void glue(gen_, name)(DisasContext *ctx) \
1279 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
1280 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1284 GEN_INT_ARITH_MODW(moduw
, 0x08, 0);
1285 GEN_INT_ARITH_MODW(modsw
, 0x18, 1);
1287 #if defined(TARGET_PPC64)
1288 static inline void gen_op_arith_modd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1289 TCGv arg2
, int sign
)
1291 TCGv_i64 t0
= tcg_temp_new_i64();
1292 TCGv_i64 t1
= tcg_temp_new_i64();
1294 tcg_gen_mov_i64(t0
, arg1
);
1295 tcg_gen_mov_i64(t1
, arg2
);
1297 TCGv_i64 t2
= tcg_temp_new_i64();
1298 TCGv_i64 t3
= tcg_temp_new_i64();
1299 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1300 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1301 tcg_gen_and_i64(t2
, t2
, t3
);
1302 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1303 tcg_gen_or_i64(t2
, t2
, t3
);
1304 tcg_gen_movi_i64(t3
, 0);
1305 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1306 tcg_gen_rem_i64(ret
, t0
, t1
);
1307 tcg_temp_free_i64(t2
);
1308 tcg_temp_free_i64(t3
);
1310 TCGv_i64 t2
= tcg_const_i64(1);
1311 TCGv_i64 t3
= tcg_const_i64(0);
1312 tcg_gen_movcond_i64(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1313 tcg_gen_remu_i64(ret
, t0
, t1
);
1314 tcg_temp_free_i64(t2
);
1315 tcg_temp_free_i64(t3
);
1317 tcg_temp_free_i64(t0
);
1318 tcg_temp_free_i64(t1
);
1321 #define GEN_INT_ARITH_MODD(name, opc3, sign) \
1322 static void glue(gen_, name)(DisasContext *ctx) \
1324 gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \
1325 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1329 GEN_INT_ARITH_MODD(modud
, 0x08, 0);
1330 GEN_INT_ARITH_MODD(modsd
, 0x18, 1);
1334 static void gen_mulhw(DisasContext
*ctx
)
1336 TCGv_i32 t0
= tcg_temp_new_i32();
1337 TCGv_i32 t1
= tcg_temp_new_i32();
1339 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1340 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1341 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1342 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1343 tcg_temp_free_i32(t0
);
1344 tcg_temp_free_i32(t1
);
1345 if (unlikely(Rc(ctx
->opcode
) != 0))
1346 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1349 /* mulhwu mulhwu. */
1350 static void gen_mulhwu(DisasContext
*ctx
)
1352 TCGv_i32 t0
= tcg_temp_new_i32();
1353 TCGv_i32 t1
= tcg_temp_new_i32();
1355 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1356 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1357 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1358 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1359 tcg_temp_free_i32(t0
);
1360 tcg_temp_free_i32(t1
);
1361 if (unlikely(Rc(ctx
->opcode
) != 0))
1362 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1366 static void gen_mullw(DisasContext
*ctx
)
1368 #if defined(TARGET_PPC64)
1370 t0
= tcg_temp_new_i64();
1371 t1
= tcg_temp_new_i64();
1372 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1373 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1374 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1378 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1379 cpu_gpr
[rB(ctx
->opcode
)]);
1381 if (unlikely(Rc(ctx
->opcode
) != 0))
1382 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1385 /* mullwo mullwo. */
1386 static void gen_mullwo(DisasContext
*ctx
)
1388 TCGv_i32 t0
= tcg_temp_new_i32();
1389 TCGv_i32 t1
= tcg_temp_new_i32();
1391 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1392 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1393 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1394 #if defined(TARGET_PPC64)
1395 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1397 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1400 tcg_gen_sari_i32(t0
, t0
, 31);
1401 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1402 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1403 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1405 tcg_temp_free_i32(t0
);
1406 tcg_temp_free_i32(t1
);
1407 if (unlikely(Rc(ctx
->opcode
) != 0))
1408 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1412 static void gen_mulli(DisasContext
*ctx
)
1414 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1418 #if defined(TARGET_PPC64)
1420 static void gen_mulhd(DisasContext
*ctx
)
1422 TCGv lo
= tcg_temp_new();
1423 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1424 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1426 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1427 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1431 /* mulhdu mulhdu. */
1432 static void gen_mulhdu(DisasContext
*ctx
)
1434 TCGv lo
= tcg_temp_new();
1435 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1436 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1438 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1439 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1444 static void gen_mulld(DisasContext
*ctx
)
1446 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1447 cpu_gpr
[rB(ctx
->opcode
)]);
1448 if (unlikely(Rc(ctx
->opcode
) != 0))
1449 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1452 /* mulldo mulldo. */
1453 static void gen_mulldo(DisasContext
*ctx
)
1455 TCGv_i64 t0
= tcg_temp_new_i64();
1456 TCGv_i64 t1
= tcg_temp_new_i64();
1458 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
1459 cpu_gpr
[rB(ctx
->opcode
)]);
1460 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1462 tcg_gen_sari_i64(t0
, t0
, 63);
1463 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
1464 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1466 tcg_temp_free_i64(t0
);
1467 tcg_temp_free_i64(t1
);
1469 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1470 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1475 /* Common subf function */
1476 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1477 TCGv arg2
, bool add_ca
, bool compute_ca
,
1478 bool compute_ov
, bool compute_rc0
)
1482 if (compute_ca
|| compute_ov
) {
1483 t0
= tcg_temp_new();
1487 /* dest = ~arg1 + arg2 [+ ca]. */
1488 if (NARROW_MODE(ctx
)) {
1489 /* Caution: a non-obvious corner case of the spec is that we
1490 must produce the *entire* 64-bit addition, but produce the
1491 carry into bit 32. */
1492 TCGv inv1
= tcg_temp_new();
1493 TCGv t1
= tcg_temp_new();
1494 tcg_gen_not_tl(inv1
, arg1
);
1496 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1498 tcg_gen_addi_tl(t0
, arg2
, 1);
1500 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1501 tcg_gen_add_tl(t0
, t0
, inv1
);
1502 tcg_temp_free(inv1
);
1503 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1505 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
1506 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
1507 } else if (add_ca
) {
1508 TCGv zero
, inv1
= tcg_temp_new();
1509 tcg_gen_not_tl(inv1
, arg1
);
1510 zero
= tcg_const_tl(0);
1511 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1512 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1513 tcg_temp_free(zero
);
1514 tcg_temp_free(inv1
);
1516 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1517 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1519 } else if (add_ca
) {
1520 /* Since we're ignoring carry-out, we can simplify the
1521 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1522 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1523 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1524 tcg_gen_subi_tl(t0
, t0
, 1);
1526 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1530 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1532 if (unlikely(compute_rc0
)) {
1533 gen_set_Rc0(ctx
, t0
);
1536 if (!TCGV_EQUAL(t0
, ret
)) {
1537 tcg_gen_mov_tl(ret
, t0
);
1541 /* Sub functions with Two operands functions */
1542 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1543 static void glue(gen_, name)(DisasContext *ctx) \
1545 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1546 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1547 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1549 /* Sub functions with one operand and one immediate */
1550 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1551 add_ca, compute_ca, compute_ov) \
1552 static void glue(gen_, name)(DisasContext *ctx) \
1554 TCGv t0 = tcg_const_tl(const_val); \
1555 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1556 cpu_gpr[rA(ctx->opcode)], t0, \
1557 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1558 tcg_temp_free(t0); \
1560 /* subf subf. subfo subfo. */
1561 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1562 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1563 /* subfc subfc. subfco subfco. */
1564 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1565 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1566 /* subfe subfe. subfeo subfo. */
1567 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1568 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1569 /* subfme subfme. subfmeo subfmeo. */
1570 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1571 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1572 /* subfze subfze. subfzeo subfzeo.*/
1573 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1574 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1577 static void gen_subfic(DisasContext
*ctx
)
1579 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1580 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1585 /* neg neg. nego nego. */
1586 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1588 TCGv zero
= tcg_const_tl(0);
1589 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1590 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1591 tcg_temp_free(zero
);
1594 static void gen_neg(DisasContext
*ctx
)
1596 gen_op_arith_neg(ctx
, 0);
1599 static void gen_nego(DisasContext
*ctx
)
1601 gen_op_arith_neg(ctx
, 1);
1604 /*** Integer logical ***/
1605 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1606 static void glue(gen_, name)(DisasContext *ctx) \
1608 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1609 cpu_gpr[rB(ctx->opcode)]); \
1610 if (unlikely(Rc(ctx->opcode) != 0)) \
1611 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1614 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1615 static void glue(gen_, name)(DisasContext *ctx) \
1617 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1618 if (unlikely(Rc(ctx->opcode) != 0)) \
1619 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1623 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1625 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1628 static void gen_andi_(DisasContext
*ctx
)
1630 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1631 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1635 static void gen_andis_(DisasContext
*ctx
)
1637 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1638 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1642 static void gen_cntlzw(DisasContext
*ctx
)
1644 TCGv_i32 t
= tcg_temp_new_i32();
1646 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
1647 tcg_gen_clzi_i32(t
, t
, 32);
1648 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
1649 tcg_temp_free_i32(t
);
1651 if (unlikely(Rc(ctx
->opcode
) != 0))
1652 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1656 static void gen_cnttzw(DisasContext
*ctx
)
1658 TCGv_i32 t
= tcg_temp_new_i32();
1660 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
1661 tcg_gen_ctzi_i32(t
, t
, 32);
1662 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
1663 tcg_temp_free_i32(t
);
1665 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1666 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1671 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1672 /* extsb & extsb. */
1673 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1674 /* extsh & extsh. */
1675 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1677 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1679 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1681 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
1682 static void gen_pause(DisasContext
*ctx
)
1684 TCGv_i32 t0
= tcg_const_i32(0);
1685 tcg_gen_st_i32(t0
, cpu_env
,
1686 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
1687 tcg_temp_free_i32(t0
);
1689 /* Stop translation, this gives other CPUs a chance to run */
1690 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->nip
);
1692 #endif /* defined(TARGET_PPC64) */
1695 static void gen_or(DisasContext
*ctx
)
1699 rs
= rS(ctx
->opcode
);
1700 ra
= rA(ctx
->opcode
);
1701 rb
= rB(ctx
->opcode
);
1702 /* Optimisation for mr. ri case */
1703 if (rs
!= ra
|| rs
!= rb
) {
1705 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1707 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1708 if (unlikely(Rc(ctx
->opcode
) != 0))
1709 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1710 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1711 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1712 #if defined(TARGET_PPC64)
1713 } else if (rs
!= 0) { /* 0 is nop */
1718 /* Set process priority to low */
1722 /* Set process priority to medium-low */
1726 /* Set process priority to normal */
1729 #if !defined(CONFIG_USER_ONLY)
1732 /* Set process priority to very low */
1738 /* Set process priority to medium-hight */
1744 /* Set process priority to high */
1749 if (ctx
->hv
&& !ctx
->pr
) {
1750 /* Set process priority to very high */
1759 TCGv t0
= tcg_temp_new();
1760 gen_load_spr(t0
, SPR_PPR
);
1761 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1762 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1763 gen_store_spr(SPR_PPR
, t0
);
1766 #if !defined(CONFIG_USER_ONLY)
1767 /* Pause out of TCG otherwise spin loops with smt_low eat too much
1768 * CPU and the kernel hangs. This applies to all encodings other
1769 * than no-op, e.g., miso(rs=26), yield(27), mdoio(29), mdoom(30),
1770 * and all currently undefined.
1778 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1781 static void gen_xor(DisasContext
*ctx
)
1783 /* Optimisation for "set to zero" case */
1784 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1785 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1787 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1788 if (unlikely(Rc(ctx
->opcode
) != 0))
1789 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1793 static void gen_ori(DisasContext
*ctx
)
1795 target_ulong uimm
= UIMM(ctx
->opcode
);
1797 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1800 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1804 static void gen_oris(DisasContext
*ctx
)
1806 target_ulong uimm
= UIMM(ctx
->opcode
);
1808 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1812 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1816 static void gen_xori(DisasContext
*ctx
)
1818 target_ulong uimm
= UIMM(ctx
->opcode
);
1820 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1824 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1828 static void gen_xoris(DisasContext
*ctx
)
1830 target_ulong uimm
= UIMM(ctx
->opcode
);
1832 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1836 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1839 /* popcntb : PowerPC 2.03 specification */
1840 static void gen_popcntb(DisasContext
*ctx
)
1842 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1845 static void gen_popcntw(DisasContext
*ctx
)
1847 #if defined(TARGET_PPC64)
1848 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1850 tcg_gen_ctpop_i32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1854 #if defined(TARGET_PPC64)
1855 /* popcntd: PowerPC 2.06 specification */
1856 static void gen_popcntd(DisasContext
*ctx
)
1858 tcg_gen_ctpop_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1862 /* prtyw: PowerPC 2.05 specification */
1863 static void gen_prtyw(DisasContext
*ctx
)
1865 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1866 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1867 TCGv t0
= tcg_temp_new();
1868 tcg_gen_shri_tl(t0
, rs
, 16);
1869 tcg_gen_xor_tl(ra
, rs
, t0
);
1870 tcg_gen_shri_tl(t0
, ra
, 8);
1871 tcg_gen_xor_tl(ra
, ra
, t0
);
1872 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1876 #if defined(TARGET_PPC64)
1877 /* prtyd: PowerPC 2.05 specification */
1878 static void gen_prtyd(DisasContext
*ctx
)
1880 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1881 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1882 TCGv t0
= tcg_temp_new();
1883 tcg_gen_shri_tl(t0
, rs
, 32);
1884 tcg_gen_xor_tl(ra
, rs
, t0
);
1885 tcg_gen_shri_tl(t0
, ra
, 16);
1886 tcg_gen_xor_tl(ra
, ra
, t0
);
1887 tcg_gen_shri_tl(t0
, ra
, 8);
1888 tcg_gen_xor_tl(ra
, ra
, t0
);
1889 tcg_gen_andi_tl(ra
, ra
, 1);
1894 #if defined(TARGET_PPC64)
1896 static void gen_bpermd(DisasContext
*ctx
)
1898 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
1899 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1903 #if defined(TARGET_PPC64)
1904 /* extsw & extsw. */
1905 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1908 static void gen_cntlzd(DisasContext
*ctx
)
1910 tcg_gen_clzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
1911 if (unlikely(Rc(ctx
->opcode
) != 0))
1912 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1916 static void gen_cnttzd(DisasContext
*ctx
)
1918 tcg_gen_ctzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
1919 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1920 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1925 static void gen_darn(DisasContext
*ctx
)
1927 int l
= L(ctx
->opcode
);
1930 gen_helper_darn32(cpu_gpr
[rD(ctx
->opcode
)]);
1931 } else if (l
<= 2) {
1932 /* Return 64-bit random for both CRN and RRN */
1933 gen_helper_darn64(cpu_gpr
[rD(ctx
->opcode
)]);
1935 tcg_gen_movi_i64(cpu_gpr
[rD(ctx
->opcode
)], -1);
1940 /*** Integer rotate ***/
1942 /* rlwimi & rlwimi. */
1943 static void gen_rlwimi(DisasContext
*ctx
)
1945 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1946 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1947 uint32_t sh
= SH(ctx
->opcode
);
1948 uint32_t mb
= MB(ctx
->opcode
);
1949 uint32_t me
= ME(ctx
->opcode
);
1951 if (sh
== (31-me
) && mb
<= me
) {
1952 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
1957 #if defined(TARGET_PPC64)
1961 mask
= MASK(mb
, me
);
1963 t1
= tcg_temp_new();
1964 if (mask
<= 0xffffffffu
) {
1965 TCGv_i32 t0
= tcg_temp_new_i32();
1966 tcg_gen_trunc_tl_i32(t0
, t_rs
);
1967 tcg_gen_rotli_i32(t0
, t0
, sh
);
1968 tcg_gen_extu_i32_tl(t1
, t0
);
1969 tcg_temp_free_i32(t0
);
1971 #if defined(TARGET_PPC64)
1972 tcg_gen_deposit_i64(t1
, t_rs
, t_rs
, 32, 32);
1973 tcg_gen_rotli_i64(t1
, t1
, sh
);
1975 g_assert_not_reached();
1979 tcg_gen_andi_tl(t1
, t1
, mask
);
1980 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
1981 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
1984 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1985 gen_set_Rc0(ctx
, t_ra
);
1989 /* rlwinm & rlwinm. */
1990 static void gen_rlwinm(DisasContext
*ctx
)
1992 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1993 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1994 int sh
= SH(ctx
->opcode
);
1995 int mb
= MB(ctx
->opcode
);
1996 int me
= ME(ctx
->opcode
);
1997 int len
= me
- mb
+ 1;
1998 int rsh
= (32 - sh
) & 31;
2000 if (sh
!= 0 && len
> 0 && me
== (31 - sh
)) {
2001 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2002 } else if (me
== 31 && rsh
+ len
<= 32) {
2003 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2006 #if defined(TARGET_PPC64)
2010 mask
= MASK(mb
, me
);
2012 tcg_gen_andi_tl(t_ra
, t_rs
, mask
);
2013 } else if (mask
<= 0xffffffffu
) {
2014 TCGv_i32 t0
= tcg_temp_new_i32();
2015 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2016 tcg_gen_rotli_i32(t0
, t0
, sh
);
2017 tcg_gen_andi_i32(t0
, t0
, mask
);
2018 tcg_gen_extu_i32_tl(t_ra
, t0
);
2019 tcg_temp_free_i32(t0
);
2021 #if defined(TARGET_PPC64)
2022 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2023 tcg_gen_rotli_i64(t_ra
, t_ra
, sh
);
2024 tcg_gen_andi_i64(t_ra
, t_ra
, mask
);
2026 g_assert_not_reached();
2030 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2031 gen_set_Rc0(ctx
, t_ra
);
2035 /* rlwnm & rlwnm. */
2036 static void gen_rlwnm(DisasContext
*ctx
)
2038 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2039 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2040 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2041 uint32_t mb
= MB(ctx
->opcode
);
2042 uint32_t me
= ME(ctx
->opcode
);
2045 #if defined(TARGET_PPC64)
2049 mask
= MASK(mb
, me
);
2051 if (mask
<= 0xffffffffu
) {
2052 TCGv_i32 t0
= tcg_temp_new_i32();
2053 TCGv_i32 t1
= tcg_temp_new_i32();
2054 tcg_gen_trunc_tl_i32(t0
, t_rb
);
2055 tcg_gen_trunc_tl_i32(t1
, t_rs
);
2056 tcg_gen_andi_i32(t0
, t0
, 0x1f);
2057 tcg_gen_rotl_i32(t1
, t1
, t0
);
2058 tcg_gen_extu_i32_tl(t_ra
, t1
);
2059 tcg_temp_free_i32(t0
);
2060 tcg_temp_free_i32(t1
);
2062 #if defined(TARGET_PPC64)
2063 TCGv_i64 t0
= tcg_temp_new_i64();
2064 tcg_gen_andi_i64(t0
, t_rb
, 0x1f);
2065 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2066 tcg_gen_rotl_i64(t_ra
, t_ra
, t0
);
2067 tcg_temp_free_i64(t0
);
2069 g_assert_not_reached();
2073 tcg_gen_andi_tl(t_ra
, t_ra
, mask
);
2075 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2076 gen_set_Rc0(ctx
, t_ra
);
2080 #if defined(TARGET_PPC64)
2081 #define GEN_PPC64_R2(name, opc1, opc2) \
2082 static void glue(gen_, name##0)(DisasContext *ctx) \
2084 gen_##name(ctx, 0); \
2087 static void glue(gen_, name##1)(DisasContext *ctx) \
2089 gen_##name(ctx, 1); \
2091 #define GEN_PPC64_R4(name, opc1, opc2) \
2092 static void glue(gen_, name##0)(DisasContext *ctx) \
2094 gen_##name(ctx, 0, 0); \
2097 static void glue(gen_, name##1)(DisasContext *ctx) \
2099 gen_##name(ctx, 0, 1); \
2102 static void glue(gen_, name##2)(DisasContext *ctx) \
2104 gen_##name(ctx, 1, 0); \
2107 static void glue(gen_, name##3)(DisasContext *ctx) \
2109 gen_##name(ctx, 1, 1); \
2112 static void gen_rldinm(DisasContext
*ctx
, int mb
, int me
, int sh
)
2114 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2115 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2116 int len
= me
- mb
+ 1;
2117 int rsh
= (64 - sh
) & 63;
2119 if (sh
!= 0 && len
> 0 && me
== (63 - sh
)) {
2120 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2121 } else if (me
== 63 && rsh
+ len
<= 64) {
2122 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2124 tcg_gen_rotli_tl(t_ra
, t_rs
, sh
);
2125 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2127 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2128 gen_set_Rc0(ctx
, t_ra
);
2132 /* rldicl - rldicl. */
2133 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
2137 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2138 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2139 gen_rldinm(ctx
, mb
, 63, sh
);
2141 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
2143 /* rldicr - rldicr. */
2144 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
2148 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2149 me
= MB(ctx
->opcode
) | (men
<< 5);
2150 gen_rldinm(ctx
, 0, me
, sh
);
2152 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
2154 /* rldic - rldic. */
2155 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
2159 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2160 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2161 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
2163 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
2165 static void gen_rldnm(DisasContext
*ctx
, int mb
, int me
)
2167 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2168 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2169 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2172 t0
= tcg_temp_new();
2173 tcg_gen_andi_tl(t0
, t_rb
, 0x3f);
2174 tcg_gen_rotl_tl(t_ra
, t_rs
, t0
);
2177 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2178 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2179 gen_set_Rc0(ctx
, t_ra
);
2183 /* rldcl - rldcl. */
2184 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
2188 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2189 gen_rldnm(ctx
, mb
, 63);
2191 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
2193 /* rldcr - rldcr. */
2194 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
2198 me
= MB(ctx
->opcode
) | (men
<< 5);
2199 gen_rldnm(ctx
, 0, me
);
2201 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
2203 /* rldimi - rldimi. */
2204 static void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
2206 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2207 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2208 uint32_t sh
= SH(ctx
->opcode
) | (shn
<< 5);
2209 uint32_t mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2210 uint32_t me
= 63 - sh
;
2213 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2215 target_ulong mask
= MASK(mb
, me
);
2216 TCGv t1
= tcg_temp_new();
2218 tcg_gen_rotli_tl(t1
, t_rs
, sh
);
2219 tcg_gen_andi_tl(t1
, t1
, mask
);
2220 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2221 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2224 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2225 gen_set_Rc0(ctx
, t_ra
);
2228 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
2231 /*** Integer shift ***/
2234 static void gen_slw(DisasContext
*ctx
)
2238 t0
= tcg_temp_new();
2239 /* AND rS with a mask that is 0 when rB >= 0x20 */
2240 #if defined(TARGET_PPC64)
2241 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2242 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2244 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2245 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2247 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2248 t1
= tcg_temp_new();
2249 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2250 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2253 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2254 if (unlikely(Rc(ctx
->opcode
) != 0))
2255 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2259 static void gen_sraw(DisasContext
*ctx
)
2261 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2262 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2263 if (unlikely(Rc(ctx
->opcode
) != 0))
2264 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2267 /* srawi & srawi. */
2268 static void gen_srawi(DisasContext
*ctx
)
2270 int sh
= SH(ctx
->opcode
);
2271 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2272 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2274 tcg_gen_ext32s_tl(dst
, src
);
2275 tcg_gen_movi_tl(cpu_ca
, 0);
2278 tcg_gen_ext32s_tl(dst
, src
);
2279 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
2280 t0
= tcg_temp_new();
2281 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
2282 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2284 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2285 tcg_gen_sari_tl(dst
, dst
, sh
);
2287 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2288 gen_set_Rc0(ctx
, dst
);
2293 static void gen_srw(DisasContext
*ctx
)
2297 t0
= tcg_temp_new();
2298 /* AND rS with a mask that is 0 when rB >= 0x20 */
2299 #if defined(TARGET_PPC64)
2300 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2301 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2303 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2304 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2306 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2307 tcg_gen_ext32u_tl(t0
, t0
);
2308 t1
= tcg_temp_new();
2309 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2310 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2313 if (unlikely(Rc(ctx
->opcode
) != 0))
2314 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2317 #if defined(TARGET_PPC64)
2319 static void gen_sld(DisasContext
*ctx
)
2323 t0
= tcg_temp_new();
2324 /* AND rS with a mask that is 0 when rB >= 0x40 */
2325 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2326 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2327 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2328 t1
= tcg_temp_new();
2329 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2330 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2333 if (unlikely(Rc(ctx
->opcode
) != 0))
2334 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2338 static void gen_srad(DisasContext
*ctx
)
2340 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2341 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2342 if (unlikely(Rc(ctx
->opcode
) != 0))
2343 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2345 /* sradi & sradi. */
2346 static inline void gen_sradi(DisasContext
*ctx
, int n
)
2348 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2349 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2350 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2352 tcg_gen_mov_tl(dst
, src
);
2353 tcg_gen_movi_tl(cpu_ca
, 0);
2356 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
2357 t0
= tcg_temp_new();
2358 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
2359 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2361 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2362 tcg_gen_sari_tl(dst
, src
, sh
);
2364 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2365 gen_set_Rc0(ctx
, dst
);
2369 static void gen_sradi0(DisasContext
*ctx
)
2374 static void gen_sradi1(DisasContext
*ctx
)
2379 /* extswsli & extswsli. */
2380 static inline void gen_extswsli(DisasContext
*ctx
, int n
)
2382 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2383 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2384 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2386 tcg_gen_ext32s_tl(dst
, src
);
2387 tcg_gen_shli_tl(dst
, dst
, sh
);
2388 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2389 gen_set_Rc0(ctx
, dst
);
2393 static void gen_extswsli0(DisasContext
*ctx
)
2395 gen_extswsli(ctx
, 0);
2398 static void gen_extswsli1(DisasContext
*ctx
)
2400 gen_extswsli(ctx
, 1);
2404 static void gen_srd(DisasContext
*ctx
)
2408 t0
= tcg_temp_new();
2409 /* AND rS with a mask that is 0 when rB >= 0x40 */
2410 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2411 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2412 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2413 t1
= tcg_temp_new();
2414 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2415 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2418 if (unlikely(Rc(ctx
->opcode
) != 0))
2419 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2423 /*** Addressing modes ***/
2424 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2425 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2428 target_long simm
= SIMM(ctx
->opcode
);
2431 if (rA(ctx
->opcode
) == 0) {
2432 if (NARROW_MODE(ctx
)) {
2433 simm
= (uint32_t)simm
;
2435 tcg_gen_movi_tl(EA
, simm
);
2436 } else if (likely(simm
!= 0)) {
2437 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2438 if (NARROW_MODE(ctx
)) {
2439 tcg_gen_ext32u_tl(EA
, EA
);
2442 if (NARROW_MODE(ctx
)) {
2443 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2445 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2450 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2452 if (rA(ctx
->opcode
) == 0) {
2453 if (NARROW_MODE(ctx
)) {
2454 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2456 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2459 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2460 if (NARROW_MODE(ctx
)) {
2461 tcg_gen_ext32u_tl(EA
, EA
);
2466 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2468 if (rA(ctx
->opcode
) == 0) {
2469 tcg_gen_movi_tl(EA
, 0);
2470 } else if (NARROW_MODE(ctx
)) {
2471 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2473 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2477 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2480 tcg_gen_addi_tl(ret
, arg1
, val
);
2481 if (NARROW_MODE(ctx
)) {
2482 tcg_gen_ext32u_tl(ret
, ret
);
2486 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2488 TCGLabel
*l1
= gen_new_label();
2489 TCGv t0
= tcg_temp_new();
2491 tcg_gen_andi_tl(t0
, EA
, mask
);
2492 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2493 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2494 t2
= tcg_const_i32(ctx
->opcode
& 0x03FF0000);
2495 gen_update_nip(ctx
, ctx
->nip
- 4);
2496 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2497 tcg_temp_free_i32(t1
);
2498 tcg_temp_free_i32(t2
);
2503 static inline void gen_align_no_le(DisasContext
*ctx
)
2505 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
,
2506 (ctx
->opcode
& 0x03FF0000) | POWERPC_EXCP_ALIGN_LE
);
2509 /*** Integer load ***/
2510 #define DEF_MEMOP(op) ((op) | ctx->default_tcg_memop_mask)
2511 #define BSWAP_MEMOP(op) ((op) | (ctx->default_tcg_memop_mask ^ MO_BSWAP))
2513 #define GEN_QEMU_LOAD_TL(ldop, op) \
2514 static void glue(gen_qemu_, ldop)(DisasContext *ctx, \
2518 tcg_gen_qemu_ld_tl(val, addr, ctx->mem_idx, op); \
2521 GEN_QEMU_LOAD_TL(ld8u
, DEF_MEMOP(MO_UB
))
2522 GEN_QEMU_LOAD_TL(ld16u
, DEF_MEMOP(MO_UW
))
2523 GEN_QEMU_LOAD_TL(ld16s
, DEF_MEMOP(MO_SW
))
2524 GEN_QEMU_LOAD_TL(ld32u
, DEF_MEMOP(MO_UL
))
2525 GEN_QEMU_LOAD_TL(ld32s
, DEF_MEMOP(MO_SL
))
2527 GEN_QEMU_LOAD_TL(ld16ur
, BSWAP_MEMOP(MO_UW
))
2528 GEN_QEMU_LOAD_TL(ld32ur
, BSWAP_MEMOP(MO_UL
))
2530 #define GEN_QEMU_LOAD_64(ldop, op) \
2531 static void glue(gen_qemu_, glue(ldop, _i64))(DisasContext *ctx, \
2535 tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, op); \
2538 GEN_QEMU_LOAD_64(ld8u
, DEF_MEMOP(MO_UB
))
2539 GEN_QEMU_LOAD_64(ld16u
, DEF_MEMOP(MO_UW
))
2540 GEN_QEMU_LOAD_64(ld32u
, DEF_MEMOP(MO_UL
))
2541 GEN_QEMU_LOAD_64(ld32s
, DEF_MEMOP(MO_SL
))
2542 GEN_QEMU_LOAD_64(ld64
, DEF_MEMOP(MO_Q
))
2544 #if defined(TARGET_PPC64)
2545 GEN_QEMU_LOAD_64(ld64ur
, BSWAP_MEMOP(MO_Q
))
2548 #define GEN_QEMU_STORE_TL(stop, op) \
2549 static void glue(gen_qemu_, stop)(DisasContext *ctx, \
2553 tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, op); \
2556 GEN_QEMU_STORE_TL(st8
, DEF_MEMOP(MO_UB
))
2557 GEN_QEMU_STORE_TL(st16
, DEF_MEMOP(MO_UW
))
2558 GEN_QEMU_STORE_TL(st32
, DEF_MEMOP(MO_UL
))
2560 GEN_QEMU_STORE_TL(st16r
, BSWAP_MEMOP(MO_UW
))
2561 GEN_QEMU_STORE_TL(st32r
, BSWAP_MEMOP(MO_UL
))
2563 #define GEN_QEMU_STORE_64(stop, op) \
2564 static void glue(gen_qemu_, glue(stop, _i64))(DisasContext *ctx, \
2568 tcg_gen_qemu_st_i64(val, addr, ctx->mem_idx, op); \
2571 GEN_QEMU_STORE_64(st8
, DEF_MEMOP(MO_UB
))
2572 GEN_QEMU_STORE_64(st16
, DEF_MEMOP(MO_UW
))
2573 GEN_QEMU_STORE_64(st32
, DEF_MEMOP(MO_UL
))
2574 GEN_QEMU_STORE_64(st64
, DEF_MEMOP(MO_Q
))
2576 #if defined(TARGET_PPC64)
2577 GEN_QEMU_STORE_64(st64r
, BSWAP_MEMOP(MO_Q
))
2580 #define GEN_LD(name, ldop, opc, type) \
2581 static void glue(gen_, name)(DisasContext *ctx) \
2584 gen_set_access_type(ctx, ACCESS_INT); \
2585 EA = tcg_temp_new(); \
2586 gen_addr_imm_index(ctx, EA, 0); \
2587 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2588 tcg_temp_free(EA); \
2591 #define GEN_LDU(name, ldop, opc, type) \
2592 static void glue(gen_, name##u)(DisasContext *ctx) \
2595 if (unlikely(rA(ctx->opcode) == 0 || \
2596 rA(ctx->opcode) == rD(ctx->opcode))) { \
2597 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2600 gen_set_access_type(ctx, ACCESS_INT); \
2601 EA = tcg_temp_new(); \
2602 if (type == PPC_64B) \
2603 gen_addr_imm_index(ctx, EA, 0x03); \
2605 gen_addr_imm_index(ctx, EA, 0); \
2606 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2607 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2608 tcg_temp_free(EA); \
2611 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2612 static void glue(gen_, name##ux)(DisasContext *ctx) \
2615 if (unlikely(rA(ctx->opcode) == 0 || \
2616 rA(ctx->opcode) == rD(ctx->opcode))) { \
2617 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2620 gen_set_access_type(ctx, ACCESS_INT); \
2621 EA = tcg_temp_new(); \
2622 gen_addr_reg_index(ctx, EA); \
2623 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2624 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2625 tcg_temp_free(EA); \
2628 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
2629 static void glue(gen_, name##x)(DisasContext *ctx) \
2633 gen_set_access_type(ctx, ACCESS_INT); \
2634 EA = tcg_temp_new(); \
2635 gen_addr_reg_index(ctx, EA); \
2636 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2637 tcg_temp_free(EA); \
2640 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2641 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
2643 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
2644 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
2646 #define GEN_LDS(name, ldop, op, type) \
2647 GEN_LD(name, ldop, op | 0x20, type); \
2648 GEN_LDU(name, ldop, op | 0x21, type); \
2649 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2650 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2652 /* lbz lbzu lbzux lbzx */
2653 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2654 /* lha lhau lhaux lhax */
2655 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2656 /* lhz lhzu lhzux lhzx */
2657 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2658 /* lwz lwzu lwzux lwzx */
2659 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2660 #if defined(TARGET_PPC64)
2662 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2664 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2666 GEN_LDUX(ld
, ld64_i64
, 0x15, 0x01, PPC_64B
);
2668 GEN_LDX(ld
, ld64_i64
, 0x15, 0x00, PPC_64B
);
2670 /* CI load/store variants */
2671 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
2672 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x15, PPC_CILDST
)
2673 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
2674 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
2676 static void gen_ld(DisasContext
*ctx
)
2679 if (Rc(ctx
->opcode
)) {
2680 if (unlikely(rA(ctx
->opcode
) == 0 ||
2681 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2682 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2686 gen_set_access_type(ctx
, ACCESS_INT
);
2687 EA
= tcg_temp_new();
2688 gen_addr_imm_index(ctx
, EA
, 0x03);
2689 if (ctx
->opcode
& 0x02) {
2690 /* lwa (lwau is undefined) */
2691 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2694 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2696 if (Rc(ctx
->opcode
))
2697 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2702 static void gen_lq(DisasContext
*ctx
)
2707 /* lq is a legal user mode instruction starting in ISA 2.07 */
2708 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2709 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2711 if (!legal_in_user_mode
&& ctx
->pr
) {
2712 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2716 if (!le_is_supported
&& ctx
->le_mode
) {
2717 gen_align_no_le(ctx
);
2720 ra
= rA(ctx
->opcode
);
2721 rd
= rD(ctx
->opcode
);
2722 if (unlikely((rd
& 1) || rd
== ra
)) {
2723 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2727 gen_set_access_type(ctx
, ACCESS_INT
);
2728 EA
= tcg_temp_new();
2729 gen_addr_imm_index(ctx
, EA
, 0x0F);
2731 /* We only need to swap high and low halves. gen_qemu_ld64_i64 does
2732 necessary 64-bit byteswap already. */
2733 if (unlikely(ctx
->le_mode
)) {
2734 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rd
+ 1], EA
);
2735 gen_addr_add(ctx
, EA
, EA
, 8);
2736 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rd
], EA
);
2738 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rd
], EA
);
2739 gen_addr_add(ctx
, EA
, EA
, 8);
2740 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rd
+ 1], EA
);
2746 /*** Integer store ***/
2747 #define GEN_ST(name, stop, opc, type) \
2748 static void glue(gen_, name)(DisasContext *ctx) \
2751 gen_set_access_type(ctx, ACCESS_INT); \
2752 EA = tcg_temp_new(); \
2753 gen_addr_imm_index(ctx, EA, 0); \
2754 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2755 tcg_temp_free(EA); \
2758 #define GEN_STU(name, stop, opc, type) \
2759 static void glue(gen_, stop##u)(DisasContext *ctx) \
2762 if (unlikely(rA(ctx->opcode) == 0)) { \
2763 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2766 gen_set_access_type(ctx, ACCESS_INT); \
2767 EA = tcg_temp_new(); \
2768 if (type == PPC_64B) \
2769 gen_addr_imm_index(ctx, EA, 0x03); \
2771 gen_addr_imm_index(ctx, EA, 0); \
2772 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2773 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2774 tcg_temp_free(EA); \
2777 #define GEN_STUX(name, stop, opc2, opc3, type) \
2778 static void glue(gen_, name##ux)(DisasContext *ctx) \
2781 if (unlikely(rA(ctx->opcode) == 0)) { \
2782 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2785 gen_set_access_type(ctx, ACCESS_INT); \
2786 EA = tcg_temp_new(); \
2787 gen_addr_reg_index(ctx, EA); \
2788 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2789 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2790 tcg_temp_free(EA); \
2793 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
2794 static void glue(gen_, name##x)(DisasContext *ctx) \
2798 gen_set_access_type(ctx, ACCESS_INT); \
2799 EA = tcg_temp_new(); \
2800 gen_addr_reg_index(ctx, EA); \
2801 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2802 tcg_temp_free(EA); \
2804 #define GEN_STX(name, stop, opc2, opc3, type) \
2805 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
2807 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
2808 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
2810 #define GEN_STS(name, stop, op, type) \
2811 GEN_ST(name, stop, op | 0x20, type); \
2812 GEN_STU(name, stop, op | 0x21, type); \
2813 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2814 GEN_STX(name, stop, 0x17, op | 0x00, type)
2816 /* stb stbu stbux stbx */
2817 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2818 /* sth sthu sthux sthx */
2819 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2820 /* stw stwu stwux stwx */
2821 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2822 #if defined(TARGET_PPC64)
2823 GEN_STUX(std
, st64_i64
, 0x15, 0x05, PPC_64B
);
2824 GEN_STX(std
, st64_i64
, 0x15, 0x04, PPC_64B
);
2825 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
2826 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
2827 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
2828 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
2830 static void gen_std(DisasContext
*ctx
)
2835 rs
= rS(ctx
->opcode
);
2836 if ((ctx
->opcode
& 0x3) == 0x2) { /* stq */
2837 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2838 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2840 if (!(ctx
->insns_flags
& PPC_64BX
)) {
2841 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2844 if (!legal_in_user_mode
&& ctx
->pr
) {
2845 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2849 if (!le_is_supported
&& ctx
->le_mode
) {
2850 gen_align_no_le(ctx
);
2854 if (unlikely(rs
& 1)) {
2855 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2858 gen_set_access_type(ctx
, ACCESS_INT
);
2859 EA
= tcg_temp_new();
2860 gen_addr_imm_index(ctx
, EA
, 0x03);
2862 /* We only need to swap high and low halves. gen_qemu_st64_i64 does
2863 necessary 64-bit byteswap already. */
2864 if (unlikely(ctx
->le_mode
)) {
2865 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
+ 1], EA
);
2866 gen_addr_add(ctx
, EA
, EA
, 8);
2867 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
2869 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
2870 gen_addr_add(ctx
, EA
, EA
, 8);
2871 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
+ 1], EA
);
2876 if (Rc(ctx
->opcode
)) {
2877 if (unlikely(rA(ctx
->opcode
) == 0)) {
2878 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2882 gen_set_access_type(ctx
, ACCESS_INT
);
2883 EA
= tcg_temp_new();
2884 gen_addr_imm_index(ctx
, EA
, 0x03);
2885 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
2886 if (Rc(ctx
->opcode
))
2887 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2892 /*** Integer load and store with byte reverse ***/
2895 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2898 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2900 #if defined(TARGET_PPC64)
2902 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
2904 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
2905 #endif /* TARGET_PPC64 */
2908 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2910 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2912 /*** Integer load and store multiple ***/
2915 static void gen_lmw(DisasContext
*ctx
)
2921 gen_align_no_le(ctx
);
2924 gen_set_access_type(ctx
, ACCESS_INT
);
2925 t0
= tcg_temp_new();
2926 t1
= tcg_const_i32(rD(ctx
->opcode
));
2927 gen_addr_imm_index(ctx
, t0
, 0);
2928 gen_helper_lmw(cpu_env
, t0
, t1
);
2930 tcg_temp_free_i32(t1
);
2934 static void gen_stmw(DisasContext
*ctx
)
2940 gen_align_no_le(ctx
);
2943 gen_set_access_type(ctx
, ACCESS_INT
);
2944 t0
= tcg_temp_new();
2945 t1
= tcg_const_i32(rS(ctx
->opcode
));
2946 gen_addr_imm_index(ctx
, t0
, 0);
2947 gen_helper_stmw(cpu_env
, t0
, t1
);
2949 tcg_temp_free_i32(t1
);
2952 /*** Integer load and store strings ***/
2955 /* PowerPC32 specification says we must generate an exception if
2956 * rA is in the range of registers to be loaded.
2957 * In an other hand, IBM says this is valid, but rA won't be loaded.
2958 * For now, I'll follow the spec...
2960 static void gen_lswi(DisasContext
*ctx
)
2964 int nb
= NB(ctx
->opcode
);
2965 int start
= rD(ctx
->opcode
);
2966 int ra
= rA(ctx
->opcode
);
2970 gen_align_no_le(ctx
);
2976 if (unlikely(lsw_reg_in_range(start
, nr
, ra
))) {
2977 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
2980 gen_set_access_type(ctx
, ACCESS_INT
);
2981 t0
= tcg_temp_new();
2982 gen_addr_register(ctx
, t0
);
2983 t1
= tcg_const_i32(nb
);
2984 t2
= tcg_const_i32(start
);
2985 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
2987 tcg_temp_free_i32(t1
);
2988 tcg_temp_free_i32(t2
);
2992 static void gen_lswx(DisasContext
*ctx
)
2995 TCGv_i32 t1
, t2
, t3
;
2998 gen_align_no_le(ctx
);
3001 gen_set_access_type(ctx
, ACCESS_INT
);
3002 t0
= tcg_temp_new();
3003 gen_addr_reg_index(ctx
, t0
);
3004 t1
= tcg_const_i32(rD(ctx
->opcode
));
3005 t2
= tcg_const_i32(rA(ctx
->opcode
));
3006 t3
= tcg_const_i32(rB(ctx
->opcode
));
3007 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3009 tcg_temp_free_i32(t1
);
3010 tcg_temp_free_i32(t2
);
3011 tcg_temp_free_i32(t3
);
3015 static void gen_stswi(DisasContext
*ctx
)
3019 int nb
= NB(ctx
->opcode
);
3022 gen_align_no_le(ctx
);
3025 gen_set_access_type(ctx
, ACCESS_INT
);
3026 t0
= tcg_temp_new();
3027 gen_addr_register(ctx
, t0
);
3030 t1
= tcg_const_i32(nb
);
3031 t2
= tcg_const_i32(rS(ctx
->opcode
));
3032 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3034 tcg_temp_free_i32(t1
);
3035 tcg_temp_free_i32(t2
);
3039 static void gen_stswx(DisasContext
*ctx
)
3045 gen_align_no_le(ctx
);
3048 gen_set_access_type(ctx
, ACCESS_INT
);
3049 t0
= tcg_temp_new();
3050 gen_addr_reg_index(ctx
, t0
);
3051 t1
= tcg_temp_new_i32();
3052 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3053 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3054 t2
= tcg_const_i32(rS(ctx
->opcode
));
3055 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3057 tcg_temp_free_i32(t1
);
3058 tcg_temp_free_i32(t2
);
3061 /*** Memory synchronisation ***/
3063 static void gen_eieio(DisasContext
*ctx
)
3067 #if !defined(CONFIG_USER_ONLY)
3068 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
)
3073 if (!ctx
->lazy_tlb_flush
) {
3076 l
= gen_new_label();
3077 t
= tcg_temp_new_i32();
3078 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
3079 tcg_gen_brcondi_i32(TCG_COND_EQ
, t
, 0, l
);
3081 gen_helper_check_tlb_flush_global(cpu_env
);
3083 gen_helper_check_tlb_flush_local(cpu_env
);
3086 tcg_temp_free_i32(t
);
3089 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
) { }
3093 static void gen_isync(DisasContext
*ctx
)
3096 * We need to check for a pending TLB flush. This can only happen in
3097 * kernel mode however so check MSR_PR
3100 gen_check_tlb_flush(ctx
, false);
3102 gen_stop_exception(ctx
);
3105 #define MEMOP_GET_SIZE(x) (1 << ((x) & MO_SIZE))
3107 #define LARX(name, memop) \
3108 static void gen_##name(DisasContext *ctx) \
3111 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3112 int len = MEMOP_GET_SIZE(memop); \
3113 gen_set_access_type(ctx, ACCESS_RES); \
3114 t0 = tcg_temp_local_new(); \
3115 gen_addr_reg_index(ctx, t0); \
3117 gen_check_align(ctx, t0, (len)-1); \
3119 tcg_gen_qemu_ld_tl(gpr, t0, ctx->mem_idx, memop); \
3120 tcg_gen_mov_tl(cpu_reserve, t0); \
3121 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3122 tcg_temp_free(t0); \
3126 LARX(lbarx
, DEF_MEMOP(MO_UB
))
3127 LARX(lharx
, DEF_MEMOP(MO_UW
))
3128 LARX(lwarx
, DEF_MEMOP(MO_UL
))
3130 #if defined(CONFIG_USER_ONLY)
3131 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3134 TCGv t0
= tcg_temp_new();
3136 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3137 tcg_gen_movi_tl(t0
, (MEMOP_GET_SIZE(memop
) << 5) | reg
);
3138 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3140 gen_exception_err(ctx
, POWERPC_EXCP_STCX
, 0);
3143 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3148 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3149 l1
= gen_new_label();
3150 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3151 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3152 tcg_gen_qemu_st_tl(cpu_gpr
[reg
], EA
, ctx
->mem_idx
, memop
);
3154 tcg_gen_movi_tl(cpu_reserve
, -1);
3158 #define STCX(name, memop) \
3159 static void gen_##name(DisasContext *ctx) \
3162 int len = MEMOP_GET_SIZE(memop); \
3163 gen_set_access_type(ctx, ACCESS_RES); \
3164 t0 = tcg_temp_local_new(); \
3165 gen_addr_reg_index(ctx, t0); \
3167 gen_check_align(ctx, t0, (len) - 1); \
3169 gen_conditional_store(ctx, t0, rS(ctx->opcode), memop); \
3170 tcg_temp_free(t0); \
3173 STCX(stbcx_
, DEF_MEMOP(MO_UB
))
3174 STCX(sthcx_
, DEF_MEMOP(MO_UW
))
3175 STCX(stwcx_
, DEF_MEMOP(MO_UL
))
3177 #if defined(TARGET_PPC64)
3179 LARX(ldarx
, DEF_MEMOP(MO_Q
))
3181 STCX(stdcx_
, DEF_MEMOP(MO_Q
))
3184 static void gen_lqarx(DisasContext
*ctx
)
3187 int rd
= rD(ctx
->opcode
);
3190 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
3191 (rd
== rB(ctx
->opcode
)))) {
3192 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3196 gen_set_access_type(ctx
, ACCESS_RES
);
3197 EA
= tcg_temp_local_new();
3198 gen_addr_reg_index(ctx
, EA
);
3199 gen_check_align(ctx
, EA
, 15);
3200 if (unlikely(ctx
->le_mode
)) {
3201 gpr1
= cpu_gpr
[rd
+1];
3205 gpr2
= cpu_gpr
[rd
+1];
3207 tcg_gen_qemu_ld_i64(gpr1
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_Q
));
3208 tcg_gen_mov_tl(cpu_reserve
, EA
);
3209 gen_addr_add(ctx
, EA
, EA
, 8);
3210 tcg_gen_qemu_ld_i64(gpr2
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_Q
));
3212 tcg_gen_st_tl(gpr1
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3213 tcg_gen_st_tl(gpr2
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
3218 static void gen_stqcx_(DisasContext
*ctx
)
3221 int reg
= rS(ctx
->opcode
);
3223 #if !defined(CONFIG_USER_ONLY)
3228 if (unlikely((rD(ctx
->opcode
) & 1))) {
3229 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3232 gen_set_access_type(ctx
, ACCESS_RES
);
3233 EA
= tcg_temp_local_new();
3234 gen_addr_reg_index(ctx
, EA
);
3236 gen_check_align(ctx
, EA
, (len
) - 1);
3239 #if defined(CONFIG_USER_ONLY)
3240 gen_conditional_store(ctx
, EA
, reg
, 16);
3242 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3243 l1
= gen_new_label();
3244 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3245 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3247 if (unlikely(ctx
->le_mode
)) {
3248 gpr1
= cpu_gpr
[reg
+ 1];
3249 gpr2
= cpu_gpr
[reg
];
3251 gpr1
= cpu_gpr
[reg
];
3252 gpr2
= cpu_gpr
[reg
+ 1];
3254 tcg_gen_qemu_st_tl(gpr1
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_Q
));
3255 gen_addr_add(ctx
, EA
, EA
, 8);
3256 tcg_gen_qemu_st_tl(gpr2
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_Q
));
3259 tcg_gen_movi_tl(cpu_reserve
, -1);
3264 #endif /* defined(TARGET_PPC64) */
3267 static void gen_sync(DisasContext
*ctx
)
3269 uint32_t l
= (ctx
->opcode
>> 21) & 3;
3272 * We may need to check for a pending TLB flush.
3274 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
3276 * Additionally, this can only happen in kernel mode however so
3277 * check MSR_PR as well.
3279 if (((l
== 2) || !(ctx
->insns_flags
& PPC_64B
)) && !ctx
->pr
) {
3280 gen_check_tlb_flush(ctx
, true);
3285 static void gen_wait(DisasContext
*ctx
)
3287 TCGv_i32 t0
= tcg_const_i32(1);
3288 tcg_gen_st_i32(t0
, cpu_env
,
3289 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3290 tcg_temp_free_i32(t0
);
3291 /* Stop translation, as the CPU is supposed to sleep from now */
3292 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->nip
);
3295 #if defined(TARGET_PPC64)
3296 static void gen_doze(DisasContext
*ctx
)
3298 #if defined(CONFIG_USER_ONLY)
3304 t
= tcg_const_i32(PPC_PM_DOZE
);
3305 gen_helper_pminsn(cpu_env
, t
);
3306 tcg_temp_free_i32(t
);
3307 gen_stop_exception(ctx
);
3308 #endif /* defined(CONFIG_USER_ONLY) */
3311 static void gen_nap(DisasContext
*ctx
)
3313 #if defined(CONFIG_USER_ONLY)
3319 t
= tcg_const_i32(PPC_PM_NAP
);
3320 gen_helper_pminsn(cpu_env
, t
);
3321 tcg_temp_free_i32(t
);
3322 gen_stop_exception(ctx
);
3323 #endif /* defined(CONFIG_USER_ONLY) */
3326 static void gen_sleep(DisasContext
*ctx
)
3328 #if defined(CONFIG_USER_ONLY)
3334 t
= tcg_const_i32(PPC_PM_SLEEP
);
3335 gen_helper_pminsn(cpu_env
, t
);
3336 tcg_temp_free_i32(t
);
3337 gen_stop_exception(ctx
);
3338 #endif /* defined(CONFIG_USER_ONLY) */
3341 static void gen_rvwinkle(DisasContext
*ctx
)
3343 #if defined(CONFIG_USER_ONLY)
3349 t
= tcg_const_i32(PPC_PM_RVWINKLE
);
3350 gen_helper_pminsn(cpu_env
, t
);
3351 tcg_temp_free_i32(t
);
3352 gen_stop_exception(ctx
);
3353 #endif /* defined(CONFIG_USER_ONLY) */
3355 #endif /* #if defined(TARGET_PPC64) */
3357 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3359 #if defined(TARGET_PPC64)
3361 tcg_gen_movi_tl(cpu_cfar
, nip
);
3365 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
3367 if (unlikely(ctx
->singlestep_enabled
)) {
3371 #ifndef CONFIG_USER_ONLY
3372 return (ctx
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
3379 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3381 if (NARROW_MODE(ctx
)) {
3382 dest
= (uint32_t) dest
;
3384 if (use_goto_tb(ctx
, dest
)) {
3386 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3387 tcg_gen_exit_tb((uintptr_t)ctx
->tb
+ n
);
3389 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3390 if (unlikely(ctx
->singlestep_enabled
)) {
3391 if ((ctx
->singlestep_enabled
&
3392 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3393 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3394 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3395 gen_exception_nip(ctx
, POWERPC_EXCP_TRACE
, dest
);
3397 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3398 gen_debug_exception(ctx
);
3405 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3407 if (NARROW_MODE(ctx
)) {
3408 nip
= (uint32_t)nip
;
3410 tcg_gen_movi_tl(cpu_lr
, nip
);
3414 static void gen_b(DisasContext
*ctx
)
3416 target_ulong li
, target
;
3418 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3419 /* sign extend LI */
3420 li
= LI(ctx
->opcode
);
3421 li
= (li
^ 0x02000000) - 0x02000000;
3422 if (likely(AA(ctx
->opcode
) == 0)) {
3423 target
= ctx
->nip
+ li
- 4;
3427 if (LK(ctx
->opcode
)) {
3428 gen_setlr(ctx
, ctx
->nip
);
3430 gen_update_cfar(ctx
, ctx
->nip
- 4);
3431 gen_goto_tb(ctx
, 0, target
);
3439 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3441 uint32_t bo
= BO(ctx
->opcode
);
3445 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3446 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
3447 target
= tcg_temp_local_new();
3448 if (type
== BCOND_CTR
)
3449 tcg_gen_mov_tl(target
, cpu_ctr
);
3450 else if (type
== BCOND_TAR
)
3451 gen_load_spr(target
, SPR_TAR
);
3453 tcg_gen_mov_tl(target
, cpu_lr
);
3455 TCGV_UNUSED(target
);
3457 if (LK(ctx
->opcode
))
3458 gen_setlr(ctx
, ctx
->nip
);
3459 l1
= gen_new_label();
3460 if ((bo
& 0x4) == 0) {
3461 /* Decrement and test CTR */
3462 TCGv temp
= tcg_temp_new();
3463 if (unlikely(type
== BCOND_CTR
)) {
3464 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3467 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3468 if (NARROW_MODE(ctx
)) {
3469 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3471 tcg_gen_mov_tl(temp
, cpu_ctr
);
3474 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3476 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3478 tcg_temp_free(temp
);
3480 if ((bo
& 0x10) == 0) {
3482 uint32_t bi
= BI(ctx
->opcode
);
3483 uint32_t mask
= 0x08 >> (bi
& 0x03);
3484 TCGv_i32 temp
= tcg_temp_new_i32();
3487 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3488 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3490 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3491 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3493 tcg_temp_free_i32(temp
);
3495 gen_update_cfar(ctx
, ctx
->nip
- 4);
3496 if (type
== BCOND_IM
) {
3497 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3498 if (likely(AA(ctx
->opcode
) == 0)) {
3499 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3501 gen_goto_tb(ctx
, 0, li
);
3503 if ((bo
& 0x14) != 0x14) {
3505 gen_goto_tb(ctx
, 1, ctx
->nip
);
3508 if (NARROW_MODE(ctx
)) {
3509 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3511 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3514 if ((bo
& 0x14) != 0x14) {
3516 gen_update_nip(ctx
, ctx
->nip
);
3520 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
3521 tcg_temp_free(target
);
3525 static void gen_bc(DisasContext
*ctx
)
3527 gen_bcond(ctx
, BCOND_IM
);
3530 static void gen_bcctr(DisasContext
*ctx
)
3532 gen_bcond(ctx
, BCOND_CTR
);
3535 static void gen_bclr(DisasContext
*ctx
)
3537 gen_bcond(ctx
, BCOND_LR
);
3540 static void gen_bctar(DisasContext
*ctx
)
3542 gen_bcond(ctx
, BCOND_TAR
);
3545 /*** Condition register logical ***/
3546 #define GEN_CRLOGIC(name, tcg_op, opc) \
3547 static void glue(gen_, name)(DisasContext *ctx) \
3552 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3553 t0 = tcg_temp_new_i32(); \
3555 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3557 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3559 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3560 t1 = tcg_temp_new_i32(); \
3561 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3563 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3565 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3567 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3568 tcg_op(t0, t0, t1); \
3569 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
3570 tcg_gen_andi_i32(t0, t0, bitmask); \
3571 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3572 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3573 tcg_temp_free_i32(t0); \
3574 tcg_temp_free_i32(t1); \
3578 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3580 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3582 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3584 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3586 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3588 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3590 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3592 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3595 static void gen_mcrf(DisasContext
*ctx
)
3597 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3600 /*** System linkage ***/
3602 /* rfi (supervisor only) */
3603 static void gen_rfi(DisasContext
*ctx
)
3605 #if defined(CONFIG_USER_ONLY)
3608 /* This instruction doesn't exist anymore on 64-bit server
3609 * processors compliant with arch 2.x
3611 if (ctx
->insns_flags
& PPC_SEGMENT_64B
) {
3612 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3615 /* Restore CPU state */
3617 gen_update_cfar(ctx
, ctx
->nip
- 4);
3618 gen_helper_rfi(cpu_env
);
3619 gen_sync_exception(ctx
);
3623 #if defined(TARGET_PPC64)
3624 static void gen_rfid(DisasContext
*ctx
)
3626 #if defined(CONFIG_USER_ONLY)
3629 /* Restore CPU state */
3631 gen_update_cfar(ctx
, ctx
->nip
- 4);
3632 gen_helper_rfid(cpu_env
);
3633 gen_sync_exception(ctx
);
3637 static void gen_hrfid(DisasContext
*ctx
)
3639 #if defined(CONFIG_USER_ONLY)
3642 /* Restore CPU state */
3644 gen_helper_hrfid(cpu_env
);
3645 gen_sync_exception(ctx
);
3651 #if defined(CONFIG_USER_ONLY)
3652 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3654 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3656 static void gen_sc(DisasContext
*ctx
)
3660 lev
= (ctx
->opcode
>> 5) & 0x7F;
3661 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3666 /* Check for unconditional traps (always or never) */
3667 static bool check_unconditional_trap(DisasContext
*ctx
)
3670 if (TO(ctx
->opcode
) == 0) {
3674 if (TO(ctx
->opcode
) == 31) {
3675 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
3682 static void gen_tw(DisasContext
*ctx
)
3686 if (check_unconditional_trap(ctx
)) {
3689 t0
= tcg_const_i32(TO(ctx
->opcode
));
3690 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3692 tcg_temp_free_i32(t0
);
3696 static void gen_twi(DisasContext
*ctx
)
3701 if (check_unconditional_trap(ctx
)) {
3704 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3705 t1
= tcg_const_i32(TO(ctx
->opcode
));
3706 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3708 tcg_temp_free_i32(t1
);
3711 #if defined(TARGET_PPC64)
3713 static void gen_td(DisasContext
*ctx
)
3717 if (check_unconditional_trap(ctx
)) {
3720 t0
= tcg_const_i32(TO(ctx
->opcode
));
3721 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3723 tcg_temp_free_i32(t0
);
3727 static void gen_tdi(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_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3739 tcg_temp_free_i32(t1
);
3743 /*** Processor control ***/
3745 static void gen_read_xer(TCGv dst
)
3747 TCGv t0
= tcg_temp_new();
3748 TCGv t1
= tcg_temp_new();
3749 TCGv t2
= tcg_temp_new();
3750 tcg_gen_mov_tl(dst
, cpu_xer
);
3751 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
3752 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
3753 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
3754 tcg_gen_or_tl(t0
, t0
, t1
);
3755 tcg_gen_or_tl(dst
, dst
, t2
);
3756 tcg_gen_or_tl(dst
, dst
, t0
);
3762 static void gen_write_xer(TCGv src
)
3764 tcg_gen_andi_tl(cpu_xer
, src
,
3765 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
3766 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
3767 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
3768 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
3769 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
3770 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
3771 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
3775 static void gen_mcrxr(DisasContext
*ctx
)
3777 TCGv_i32 t0
= tcg_temp_new_i32();
3778 TCGv_i32 t1
= tcg_temp_new_i32();
3779 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
3781 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
3782 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
3783 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
3784 tcg_gen_shli_i32(t0
, t0
, 3);
3785 tcg_gen_shli_i32(t1
, t1
, 2);
3786 tcg_gen_shli_i32(dst
, dst
, 1);
3787 tcg_gen_or_i32(dst
, dst
, t0
);
3788 tcg_gen_or_i32(dst
, dst
, t1
);
3789 tcg_temp_free_i32(t0
);
3790 tcg_temp_free_i32(t1
);
3792 tcg_gen_movi_tl(cpu_so
, 0);
3793 tcg_gen_movi_tl(cpu_ov
, 0);
3794 tcg_gen_movi_tl(cpu_ca
, 0);
3798 static void gen_mfcr(DisasContext
*ctx
)
3802 if (likely(ctx
->opcode
& 0x00100000)) {
3803 crm
= CRM(ctx
->opcode
);
3804 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3806 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3807 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3808 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3811 TCGv_i32 t0
= tcg_temp_new_i32();
3812 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3813 tcg_gen_shli_i32(t0
, t0
, 4);
3814 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3815 tcg_gen_shli_i32(t0
, t0
, 4);
3816 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3817 tcg_gen_shli_i32(t0
, t0
, 4);
3818 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3819 tcg_gen_shli_i32(t0
, t0
, 4);
3820 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3821 tcg_gen_shli_i32(t0
, t0
, 4);
3822 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3823 tcg_gen_shli_i32(t0
, t0
, 4);
3824 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3825 tcg_gen_shli_i32(t0
, t0
, 4);
3826 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3827 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3828 tcg_temp_free_i32(t0
);
3833 static void gen_mfmsr(DisasContext
*ctx
)
3836 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3839 static void spr_noaccess(DisasContext
*ctx
, int gprn
, int sprn
)
3842 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3843 printf("ERROR: try to access SPR %d !\n", sprn
);
3846 #define SPR_NOACCESS (&spr_noaccess)
3849 static inline void gen_op_mfspr(DisasContext
*ctx
)
3851 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
3852 uint32_t sprn
= SPR(ctx
->opcode
);
3854 #if defined(CONFIG_USER_ONLY)
3855 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3858 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3859 } else if (ctx
->hv
) {
3860 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3862 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3865 if (likely(read_cb
!= NULL
)) {
3866 if (likely(read_cb
!= SPR_NOACCESS
)) {
3867 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3869 /* Privilege exception */
3870 /* This is a hack to avoid warnings when running Linux:
3871 * this OS breaks the PowerPC virtualisation model,
3872 * allowing userland application to read the PVR
3874 if (sprn
!= SPR_PVR
) {
3875 fprintf(stderr
, "Trying to read privileged spr %d (0x%03x) at "
3876 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
3877 if (qemu_log_separate()) {
3878 qemu_log("Trying to read privileged spr %d (0x%03x) at "
3879 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
3882 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3885 /* ISA 2.07 defines these as no-ops */
3886 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
3887 (sprn
>= 808 && sprn
<= 811)) {
3892 fprintf(stderr
, "Trying to read invalid spr %d (0x%03x) at "
3893 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
3894 if (qemu_log_separate()) {
3895 qemu_log("Trying to read invalid spr %d (0x%03x) at "
3896 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
3899 /* The behaviour depends on MSR:PR and SPR# bit 0x10,
3900 * it can generate a priv, a hv emu or a no-op
3904 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3907 if (ctx
->pr
|| sprn
== 0 || sprn
== 4 || sprn
== 5 || sprn
== 6) {
3908 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3914 static void gen_mfspr(DisasContext
*ctx
)
3920 static void gen_mftb(DisasContext
*ctx
)
3926 static void gen_mtcrf(DisasContext
*ctx
)
3930 crm
= CRM(ctx
->opcode
);
3931 if (likely((ctx
->opcode
& 0x00100000))) {
3932 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
3933 TCGv_i32 temp
= tcg_temp_new_i32();
3935 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3936 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
3937 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
3938 tcg_temp_free_i32(temp
);
3941 TCGv_i32 temp
= tcg_temp_new_i32();
3942 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3943 for (crn
= 0 ; crn
< 8 ; crn
++) {
3944 if (crm
& (1 << crn
)) {
3945 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3946 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3949 tcg_temp_free_i32(temp
);
3954 #if defined(TARGET_PPC64)
3955 static void gen_mtmsrd(DisasContext
*ctx
)
3959 #if !defined(CONFIG_USER_ONLY)
3960 if (ctx
->opcode
& 0x00010000) {
3961 /* Special form that does not need any synchronisation */
3962 TCGv t0
= tcg_temp_new();
3963 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3964 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
3965 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3968 /* XXX: we need to update nip before the store
3969 * if we enter power saving mode, we will exit the loop
3970 * directly from ppc_store_msr
3972 gen_update_nip(ctx
, ctx
->nip
);
3973 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
3974 /* Must stop the translation as machine state (may have) changed */
3975 /* Note that mtmsr is not always defined as context-synchronizing */
3976 gen_stop_exception(ctx
);
3978 #endif /* !defined(CONFIG_USER_ONLY) */
3980 #endif /* defined(TARGET_PPC64) */
3982 static void gen_mtmsr(DisasContext
*ctx
)
3986 #if !defined(CONFIG_USER_ONLY)
3987 if (ctx
->opcode
& 0x00010000) {
3988 /* Special form that does not need any synchronisation */
3989 TCGv t0
= tcg_temp_new();
3990 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3991 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
3992 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3995 TCGv msr
= tcg_temp_new();
3997 /* XXX: we need to update nip before the store
3998 * if we enter power saving mode, we will exit the loop
3999 * directly from ppc_store_msr
4001 gen_update_nip(ctx
, ctx
->nip
);
4002 #if defined(TARGET_PPC64)
4003 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4005 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4007 gen_helper_store_msr(cpu_env
, msr
);
4009 /* Must stop the translation as machine state (may have) changed */
4010 /* Note that mtmsr is not always defined as context-synchronizing */
4011 gen_stop_exception(ctx
);
4017 static void gen_mtspr(DisasContext
*ctx
)
4019 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
4020 uint32_t sprn
= SPR(ctx
->opcode
);
4022 #if defined(CONFIG_USER_ONLY)
4023 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4026 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4027 } else if (ctx
->hv
) {
4028 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4030 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4033 if (likely(write_cb
!= NULL
)) {
4034 if (likely(write_cb
!= SPR_NOACCESS
)) {
4035 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4037 /* Privilege exception */
4038 fprintf(stderr
, "Trying to write privileged spr %d (0x%03x) at "
4039 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4040 if (qemu_log_separate()) {
4041 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4042 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4044 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4047 /* ISA 2.07 defines these as no-ops */
4048 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4049 (sprn
>= 808 && sprn
<= 811)) {
4055 if (qemu_log_separate()) {
4056 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4057 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4059 fprintf(stderr
, "Trying to write invalid spr %d (0x%03x) at "
4060 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4063 /* The behaviour depends on MSR:PR and SPR# bit 0x10,
4064 * it can generate a priv, a hv emu or a no-op
4068 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4071 if (ctx
->pr
|| sprn
== 0) {
4072 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4078 #if defined(TARGET_PPC64)
4080 static void gen_setb(DisasContext
*ctx
)
4082 TCGv_i32 t0
= tcg_temp_new_i32();
4083 TCGv_i32 t8
= tcg_temp_new_i32();
4084 TCGv_i32 tm1
= tcg_temp_new_i32();
4085 int crf
= crfS(ctx
->opcode
);
4087 tcg_gen_setcondi_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], 4);
4088 tcg_gen_movi_i32(t8
, 8);
4089 tcg_gen_movi_i32(tm1
, -1);
4090 tcg_gen_movcond_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], t8
, tm1
, t0
);
4091 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4093 tcg_temp_free_i32(t0
);
4094 tcg_temp_free_i32(t8
);
4095 tcg_temp_free_i32(tm1
);
4099 /*** Cache management ***/
4102 static void gen_dcbf(DisasContext
*ctx
)
4104 /* XXX: specification says this is treated as a load by the MMU */
4106 gen_set_access_type(ctx
, ACCESS_CACHE
);
4107 t0
= tcg_temp_new();
4108 gen_addr_reg_index(ctx
, t0
);
4109 gen_qemu_ld8u(ctx
, t0
, t0
);
4113 /* dcbi (Supervisor only) */
4114 static void gen_dcbi(DisasContext
*ctx
)
4116 #if defined(CONFIG_USER_ONLY)
4122 EA
= tcg_temp_new();
4123 gen_set_access_type(ctx
, ACCESS_CACHE
);
4124 gen_addr_reg_index(ctx
, EA
);
4125 val
= tcg_temp_new();
4126 /* XXX: specification says this should be treated as a store by the MMU */
4127 gen_qemu_ld8u(ctx
, val
, EA
);
4128 gen_qemu_st8(ctx
, val
, EA
);
4131 #endif /* defined(CONFIG_USER_ONLY) */
4135 static void gen_dcbst(DisasContext
*ctx
)
4137 /* XXX: specification say this is treated as a load by the MMU */
4139 gen_set_access_type(ctx
, ACCESS_CACHE
);
4140 t0
= tcg_temp_new();
4141 gen_addr_reg_index(ctx
, t0
);
4142 gen_qemu_ld8u(ctx
, t0
, t0
);
4147 static void gen_dcbt(DisasContext
*ctx
)
4149 /* interpreted as no-op */
4150 /* XXX: specification say this is treated as a load by the MMU
4151 * but does not generate any exception
4156 static void gen_dcbtst(DisasContext
*ctx
)
4158 /* interpreted as no-op */
4159 /* XXX: specification say this is treated as a load by the MMU
4160 * but does not generate any exception
4165 static void gen_dcbtls(DisasContext
*ctx
)
4167 /* Always fails locking the cache */
4168 TCGv t0
= tcg_temp_new();
4169 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
4170 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
4171 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
4176 static void gen_dcbz(DisasContext
*ctx
)
4181 gen_set_access_type(ctx
, ACCESS_CACHE
);
4182 tcgv_addr
= tcg_temp_new();
4183 tcgv_op
= tcg_const_i32(ctx
->opcode
& 0x03FF000);
4184 gen_addr_reg_index(ctx
, tcgv_addr
);
4185 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_op
);
4186 tcg_temp_free(tcgv_addr
);
4187 tcg_temp_free_i32(tcgv_op
);
4191 static void gen_dst(DisasContext
*ctx
)
4193 if (rA(ctx
->opcode
) == 0) {
4194 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4196 /* interpreted as no-op */
4201 static void gen_dstst(DisasContext
*ctx
)
4203 if (rA(ctx
->opcode
) == 0) {
4204 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4206 /* interpreted as no-op */
4212 static void gen_dss(DisasContext
*ctx
)
4214 /* interpreted as no-op */
4218 static void gen_icbi(DisasContext
*ctx
)
4221 gen_set_access_type(ctx
, ACCESS_CACHE
);
4222 t0
= tcg_temp_new();
4223 gen_addr_reg_index(ctx
, t0
);
4224 gen_helper_icbi(cpu_env
, t0
);
4230 static void gen_dcba(DisasContext
*ctx
)
4232 /* interpreted as no-op */
4233 /* XXX: specification say this is treated as a store by the MMU
4234 * but does not generate any exception
4238 /*** Segment register manipulation ***/
4239 /* Supervisor only: */
4242 static void gen_mfsr(DisasContext
*ctx
)
4244 #if defined(CONFIG_USER_ONLY)
4250 t0
= tcg_const_tl(SR(ctx
->opcode
));
4251 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4253 #endif /* defined(CONFIG_USER_ONLY) */
4257 static void gen_mfsrin(DisasContext
*ctx
)
4259 #if defined(CONFIG_USER_ONLY)
4265 t0
= tcg_temp_new();
4266 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4267 tcg_gen_andi_tl(t0
, t0
, 0xF);
4268 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4270 #endif /* defined(CONFIG_USER_ONLY) */
4274 static void gen_mtsr(DisasContext
*ctx
)
4276 #if defined(CONFIG_USER_ONLY)
4282 t0
= tcg_const_tl(SR(ctx
->opcode
));
4283 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4285 #endif /* defined(CONFIG_USER_ONLY) */
4289 static void gen_mtsrin(DisasContext
*ctx
)
4291 #if defined(CONFIG_USER_ONLY)
4297 t0
= tcg_temp_new();
4298 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4299 tcg_gen_andi_tl(t0
, t0
, 0xF);
4300 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4302 #endif /* defined(CONFIG_USER_ONLY) */
4305 #if defined(TARGET_PPC64)
4306 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4309 static void gen_mfsr_64b(DisasContext
*ctx
)
4311 #if defined(CONFIG_USER_ONLY)
4317 t0
= tcg_const_tl(SR(ctx
->opcode
));
4318 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4320 #endif /* defined(CONFIG_USER_ONLY) */
4324 static void gen_mfsrin_64b(DisasContext
*ctx
)
4326 #if defined(CONFIG_USER_ONLY)
4332 t0
= tcg_temp_new();
4333 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4334 tcg_gen_andi_tl(t0
, t0
, 0xF);
4335 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4337 #endif /* defined(CONFIG_USER_ONLY) */
4341 static void gen_mtsr_64b(DisasContext
*ctx
)
4343 #if defined(CONFIG_USER_ONLY)
4349 t0
= tcg_const_tl(SR(ctx
->opcode
));
4350 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4352 #endif /* defined(CONFIG_USER_ONLY) */
4356 static void gen_mtsrin_64b(DisasContext
*ctx
)
4358 #if defined(CONFIG_USER_ONLY)
4364 t0
= tcg_temp_new();
4365 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4366 tcg_gen_andi_tl(t0
, t0
, 0xF);
4367 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4369 #endif /* defined(CONFIG_USER_ONLY) */
4373 static void gen_slbmte(DisasContext
*ctx
)
4375 #if defined(CONFIG_USER_ONLY)
4380 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4381 cpu_gpr
[rS(ctx
->opcode
)]);
4382 #endif /* defined(CONFIG_USER_ONLY) */
4385 static void gen_slbmfee(DisasContext
*ctx
)
4387 #if defined(CONFIG_USER_ONLY)
4392 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4393 cpu_gpr
[rB(ctx
->opcode
)]);
4394 #endif /* defined(CONFIG_USER_ONLY) */
4397 static void gen_slbmfev(DisasContext
*ctx
)
4399 #if defined(CONFIG_USER_ONLY)
4404 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4405 cpu_gpr
[rB(ctx
->opcode
)]);
4406 #endif /* defined(CONFIG_USER_ONLY) */
4409 static void gen_slbfee_(DisasContext
*ctx
)
4411 #if defined(CONFIG_USER_ONLY)
4412 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4416 if (unlikely(ctx
->pr
)) {
4417 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4420 gen_helper_find_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4421 cpu_gpr
[rB(ctx
->opcode
)]);
4422 l1
= gen_new_label();
4423 l2
= gen_new_label();
4424 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4425 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rS(ctx
->opcode
)], -1, l1
);
4426 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
4429 tcg_gen_movi_tl(cpu_gpr
[rS(ctx
->opcode
)], 0);
4433 #endif /* defined(TARGET_PPC64) */
4435 /*** Lookaside buffer management ***/
4436 /* Optional & supervisor only: */
4439 static void gen_tlbia(DisasContext
*ctx
)
4441 #if defined(CONFIG_USER_ONLY)
4446 gen_helper_tlbia(cpu_env
);
4447 #endif /* defined(CONFIG_USER_ONLY) */
4451 static void gen_tlbiel(DisasContext
*ctx
)
4453 #if defined(CONFIG_USER_ONLY)
4458 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4459 #endif /* defined(CONFIG_USER_ONLY) */
4463 static void gen_tlbie(DisasContext
*ctx
)
4465 #if defined(CONFIG_USER_ONLY)
4471 if (NARROW_MODE(ctx
)) {
4472 TCGv t0
= tcg_temp_new();
4473 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4474 gen_helper_tlbie(cpu_env
, t0
);
4477 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4479 t1
= tcg_temp_new_i32();
4480 tcg_gen_ld_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
4481 tcg_gen_ori_i32(t1
, t1
, TLB_NEED_GLOBAL_FLUSH
);
4482 tcg_gen_st_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
4483 tcg_temp_free_i32(t1
);
4484 #endif /* defined(CONFIG_USER_ONLY) */
4488 static void gen_tlbsync(DisasContext
*ctx
)
4490 #if defined(CONFIG_USER_ONLY)
4495 /* BookS does both ptesync and tlbsync make tlbsync a nop for server */
4496 if (ctx
->insns_flags
& PPC_BOOKE
) {
4497 gen_check_tlb_flush(ctx
, true);
4499 #endif /* defined(CONFIG_USER_ONLY) */
4502 #if defined(TARGET_PPC64)
4504 static void gen_slbia(DisasContext
*ctx
)
4506 #if defined(CONFIG_USER_ONLY)
4511 gen_helper_slbia(cpu_env
);
4512 #endif /* defined(CONFIG_USER_ONLY) */
4516 static void gen_slbie(DisasContext
*ctx
)
4518 #if defined(CONFIG_USER_ONLY)
4523 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4524 #endif /* defined(CONFIG_USER_ONLY) */
4526 #endif /* defined(TARGET_PPC64) */
4528 /*** External control ***/
4532 static void gen_eciwx(DisasContext
*ctx
)
4535 /* Should check EAR[E] ! */
4536 gen_set_access_type(ctx
, ACCESS_EXT
);
4537 t0
= tcg_temp_new();
4538 gen_addr_reg_index(ctx
, t0
);
4539 gen_check_align(ctx
, t0
, 0x03);
4540 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4545 static void gen_ecowx(DisasContext
*ctx
)
4548 /* Should check EAR[E] ! */
4549 gen_set_access_type(ctx
, ACCESS_EXT
);
4550 t0
= tcg_temp_new();
4551 gen_addr_reg_index(ctx
, t0
);
4552 gen_check_align(ctx
, t0
, 0x03);
4553 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4557 /* PowerPC 601 specific instructions */
4560 static void gen_abs(DisasContext
*ctx
)
4562 TCGLabel
*l1
= gen_new_label();
4563 TCGLabel
*l2
= gen_new_label();
4564 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4565 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4568 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4570 if (unlikely(Rc(ctx
->opcode
) != 0))
4571 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4575 static void gen_abso(DisasContext
*ctx
)
4577 TCGLabel
*l1
= gen_new_label();
4578 TCGLabel
*l2
= gen_new_label();
4579 TCGLabel
*l3
= gen_new_label();
4580 /* Start with XER OV disabled, the most likely case */
4581 tcg_gen_movi_tl(cpu_ov
, 0);
4582 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4583 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4584 tcg_gen_movi_tl(cpu_ov
, 1);
4585 tcg_gen_movi_tl(cpu_so
, 1);
4588 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4591 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4593 if (unlikely(Rc(ctx
->opcode
) != 0))
4594 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4598 static void gen_clcs(DisasContext
*ctx
)
4600 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4601 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4602 tcg_temp_free_i32(t0
);
4603 /* Rc=1 sets CR0 to an undefined state */
4607 static void gen_div(DisasContext
*ctx
)
4609 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4610 cpu_gpr
[rB(ctx
->opcode
)]);
4611 if (unlikely(Rc(ctx
->opcode
) != 0))
4612 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4616 static void gen_divo(DisasContext
*ctx
)
4618 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4619 cpu_gpr
[rB(ctx
->opcode
)]);
4620 if (unlikely(Rc(ctx
->opcode
) != 0))
4621 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4625 static void gen_divs(DisasContext
*ctx
)
4627 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4628 cpu_gpr
[rB(ctx
->opcode
)]);
4629 if (unlikely(Rc(ctx
->opcode
) != 0))
4630 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4633 /* divso - divso. */
4634 static void gen_divso(DisasContext
*ctx
)
4636 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4637 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4638 if (unlikely(Rc(ctx
->opcode
) != 0))
4639 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4643 static void gen_doz(DisasContext
*ctx
)
4645 TCGLabel
*l1
= gen_new_label();
4646 TCGLabel
*l2
= gen_new_label();
4647 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4648 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4651 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4653 if (unlikely(Rc(ctx
->opcode
) != 0))
4654 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4658 static void gen_dozo(DisasContext
*ctx
)
4660 TCGLabel
*l1
= gen_new_label();
4661 TCGLabel
*l2
= gen_new_label();
4662 TCGv t0
= tcg_temp_new();
4663 TCGv t1
= tcg_temp_new();
4664 TCGv t2
= tcg_temp_new();
4665 /* Start with XER OV disabled, the most likely case */
4666 tcg_gen_movi_tl(cpu_ov
, 0);
4667 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4668 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4669 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4670 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4671 tcg_gen_andc_tl(t1
, t1
, t2
);
4672 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4673 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4674 tcg_gen_movi_tl(cpu_ov
, 1);
4675 tcg_gen_movi_tl(cpu_so
, 1);
4678 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4683 if (unlikely(Rc(ctx
->opcode
) != 0))
4684 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4688 static void gen_dozi(DisasContext
*ctx
)
4690 target_long simm
= SIMM(ctx
->opcode
);
4691 TCGLabel
*l1
= gen_new_label();
4692 TCGLabel
*l2
= gen_new_label();
4693 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4694 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4697 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4699 if (unlikely(Rc(ctx
->opcode
) != 0))
4700 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4703 /* lscbx - lscbx. */
4704 static void gen_lscbx(DisasContext
*ctx
)
4706 TCGv t0
= tcg_temp_new();
4707 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4708 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4709 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4711 gen_addr_reg_index(ctx
, t0
);
4712 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4713 tcg_temp_free_i32(t1
);
4714 tcg_temp_free_i32(t2
);
4715 tcg_temp_free_i32(t3
);
4716 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4717 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4718 if (unlikely(Rc(ctx
->opcode
) != 0))
4719 gen_set_Rc0(ctx
, t0
);
4723 /* maskg - maskg. */
4724 static void gen_maskg(DisasContext
*ctx
)
4726 TCGLabel
*l1
= gen_new_label();
4727 TCGv t0
= tcg_temp_new();
4728 TCGv t1
= tcg_temp_new();
4729 TCGv t2
= tcg_temp_new();
4730 TCGv t3
= tcg_temp_new();
4731 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4732 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4733 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4734 tcg_gen_addi_tl(t2
, t0
, 1);
4735 tcg_gen_shr_tl(t2
, t3
, t2
);
4736 tcg_gen_shr_tl(t3
, t3
, t1
);
4737 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4738 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4739 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4745 if (unlikely(Rc(ctx
->opcode
) != 0))
4746 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4749 /* maskir - maskir. */
4750 static void gen_maskir(DisasContext
*ctx
)
4752 TCGv t0
= tcg_temp_new();
4753 TCGv t1
= tcg_temp_new();
4754 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4755 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4756 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4759 if (unlikely(Rc(ctx
->opcode
) != 0))
4760 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4764 static void gen_mul(DisasContext
*ctx
)
4766 TCGv_i64 t0
= tcg_temp_new_i64();
4767 TCGv_i64 t1
= tcg_temp_new_i64();
4768 TCGv t2
= tcg_temp_new();
4769 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4770 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4771 tcg_gen_mul_i64(t0
, t0
, t1
);
4772 tcg_gen_trunc_i64_tl(t2
, t0
);
4773 gen_store_spr(SPR_MQ
, t2
);
4774 tcg_gen_shri_i64(t1
, t0
, 32);
4775 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4776 tcg_temp_free_i64(t0
);
4777 tcg_temp_free_i64(t1
);
4779 if (unlikely(Rc(ctx
->opcode
) != 0))
4780 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4784 static void gen_mulo(DisasContext
*ctx
)
4786 TCGLabel
*l1
= gen_new_label();
4787 TCGv_i64 t0
= tcg_temp_new_i64();
4788 TCGv_i64 t1
= tcg_temp_new_i64();
4789 TCGv t2
= tcg_temp_new();
4790 /* Start with XER OV disabled, the most likely case */
4791 tcg_gen_movi_tl(cpu_ov
, 0);
4792 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4793 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4794 tcg_gen_mul_i64(t0
, t0
, t1
);
4795 tcg_gen_trunc_i64_tl(t2
, t0
);
4796 gen_store_spr(SPR_MQ
, t2
);
4797 tcg_gen_shri_i64(t1
, t0
, 32);
4798 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4799 tcg_gen_ext32s_i64(t1
, t0
);
4800 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4801 tcg_gen_movi_tl(cpu_ov
, 1);
4802 tcg_gen_movi_tl(cpu_so
, 1);
4804 tcg_temp_free_i64(t0
);
4805 tcg_temp_free_i64(t1
);
4807 if (unlikely(Rc(ctx
->opcode
) != 0))
4808 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4812 static void gen_nabs(DisasContext
*ctx
)
4814 TCGLabel
*l1
= gen_new_label();
4815 TCGLabel
*l2
= gen_new_label();
4816 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4817 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4820 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4822 if (unlikely(Rc(ctx
->opcode
) != 0))
4823 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4826 /* nabso - nabso. */
4827 static void gen_nabso(DisasContext
*ctx
)
4829 TCGLabel
*l1
= gen_new_label();
4830 TCGLabel
*l2
= gen_new_label();
4831 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4832 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4835 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4837 /* nabs never overflows */
4838 tcg_gen_movi_tl(cpu_ov
, 0);
4839 if (unlikely(Rc(ctx
->opcode
) != 0))
4840 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4844 static void gen_rlmi(DisasContext
*ctx
)
4846 uint32_t mb
= MB(ctx
->opcode
);
4847 uint32_t me
= ME(ctx
->opcode
);
4848 TCGv t0
= tcg_temp_new();
4849 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4850 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4851 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4852 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4853 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4855 if (unlikely(Rc(ctx
->opcode
) != 0))
4856 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4860 static void gen_rrib(DisasContext
*ctx
)
4862 TCGv t0
= tcg_temp_new();
4863 TCGv t1
= tcg_temp_new();
4864 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4865 tcg_gen_movi_tl(t1
, 0x80000000);
4866 tcg_gen_shr_tl(t1
, t1
, t0
);
4867 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4868 tcg_gen_and_tl(t0
, t0
, t1
);
4869 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4870 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4873 if (unlikely(Rc(ctx
->opcode
) != 0))
4874 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4878 static void gen_sle(DisasContext
*ctx
)
4880 TCGv t0
= tcg_temp_new();
4881 TCGv t1
= tcg_temp_new();
4882 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4883 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4884 tcg_gen_subfi_tl(t1
, 32, t1
);
4885 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4886 tcg_gen_or_tl(t1
, t0
, t1
);
4887 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4888 gen_store_spr(SPR_MQ
, t1
);
4891 if (unlikely(Rc(ctx
->opcode
) != 0))
4892 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4896 static void gen_sleq(DisasContext
*ctx
)
4898 TCGv t0
= tcg_temp_new();
4899 TCGv t1
= tcg_temp_new();
4900 TCGv t2
= tcg_temp_new();
4901 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4902 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4903 tcg_gen_shl_tl(t2
, t2
, t0
);
4904 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4905 gen_load_spr(t1
, SPR_MQ
);
4906 gen_store_spr(SPR_MQ
, t0
);
4907 tcg_gen_and_tl(t0
, t0
, t2
);
4908 tcg_gen_andc_tl(t1
, t1
, t2
);
4909 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4913 if (unlikely(Rc(ctx
->opcode
) != 0))
4914 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4918 static void gen_sliq(DisasContext
*ctx
)
4920 int sh
= SH(ctx
->opcode
);
4921 TCGv t0
= tcg_temp_new();
4922 TCGv t1
= tcg_temp_new();
4923 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4924 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4925 tcg_gen_or_tl(t1
, t0
, t1
);
4926 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4927 gen_store_spr(SPR_MQ
, t1
);
4930 if (unlikely(Rc(ctx
->opcode
) != 0))
4931 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4934 /* slliq - slliq. */
4935 static void gen_slliq(DisasContext
*ctx
)
4937 int sh
= SH(ctx
->opcode
);
4938 TCGv t0
= tcg_temp_new();
4939 TCGv t1
= tcg_temp_new();
4940 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4941 gen_load_spr(t1
, SPR_MQ
);
4942 gen_store_spr(SPR_MQ
, t0
);
4943 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
4944 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
4945 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4948 if (unlikely(Rc(ctx
->opcode
) != 0))
4949 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4953 static void gen_sllq(DisasContext
*ctx
)
4955 TCGLabel
*l1
= gen_new_label();
4956 TCGLabel
*l2
= gen_new_label();
4957 TCGv t0
= tcg_temp_local_new();
4958 TCGv t1
= tcg_temp_local_new();
4959 TCGv t2
= tcg_temp_local_new();
4960 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4961 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4962 tcg_gen_shl_tl(t1
, t1
, t2
);
4963 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4964 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4965 gen_load_spr(t0
, SPR_MQ
);
4966 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4969 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4970 gen_load_spr(t2
, SPR_MQ
);
4971 tcg_gen_andc_tl(t1
, t2
, t1
);
4972 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4977 if (unlikely(Rc(ctx
->opcode
) != 0))
4978 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4982 static void gen_slq(DisasContext
*ctx
)
4984 TCGLabel
*l1
= gen_new_label();
4985 TCGv t0
= tcg_temp_new();
4986 TCGv t1
= tcg_temp_new();
4987 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4988 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4989 tcg_gen_subfi_tl(t1
, 32, t1
);
4990 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4991 tcg_gen_or_tl(t1
, t0
, t1
);
4992 gen_store_spr(SPR_MQ
, t1
);
4993 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4994 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4995 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4996 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5000 if (unlikely(Rc(ctx
->opcode
) != 0))
5001 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5004 /* sraiq - sraiq. */
5005 static void gen_sraiq(DisasContext
*ctx
)
5007 int sh
= SH(ctx
->opcode
);
5008 TCGLabel
*l1
= gen_new_label();
5009 TCGv t0
= tcg_temp_new();
5010 TCGv t1
= tcg_temp_new();
5011 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5012 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5013 tcg_gen_or_tl(t0
, t0
, t1
);
5014 gen_store_spr(SPR_MQ
, t0
);
5015 tcg_gen_movi_tl(cpu_ca
, 0);
5016 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5017 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5018 tcg_gen_movi_tl(cpu_ca
, 1);
5020 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5023 if (unlikely(Rc(ctx
->opcode
) != 0))
5024 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5028 static void gen_sraq(DisasContext
*ctx
)
5030 TCGLabel
*l1
= gen_new_label();
5031 TCGLabel
*l2
= gen_new_label();
5032 TCGv t0
= tcg_temp_new();
5033 TCGv t1
= tcg_temp_local_new();
5034 TCGv t2
= tcg_temp_local_new();
5035 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5036 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5037 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5038 tcg_gen_subfi_tl(t2
, 32, t2
);
5039 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5040 tcg_gen_or_tl(t0
, t0
, t2
);
5041 gen_store_spr(SPR_MQ
, t0
);
5042 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5043 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5044 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5045 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5048 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5049 tcg_gen_movi_tl(cpu_ca
, 0);
5050 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5051 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5052 tcg_gen_movi_tl(cpu_ca
, 1);
5056 if (unlikely(Rc(ctx
->opcode
) != 0))
5057 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5061 static void gen_sre(DisasContext
*ctx
)
5063 TCGv t0
= tcg_temp_new();
5064 TCGv t1
= tcg_temp_new();
5065 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5066 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5067 tcg_gen_subfi_tl(t1
, 32, t1
);
5068 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5069 tcg_gen_or_tl(t1
, t0
, t1
);
5070 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5071 gen_store_spr(SPR_MQ
, t1
);
5074 if (unlikely(Rc(ctx
->opcode
) != 0))
5075 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5079 static void gen_srea(DisasContext
*ctx
)
5081 TCGv t0
= tcg_temp_new();
5082 TCGv t1
= tcg_temp_new();
5083 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5084 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5085 gen_store_spr(SPR_MQ
, t0
);
5086 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5089 if (unlikely(Rc(ctx
->opcode
) != 0))
5090 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5094 static void gen_sreq(DisasContext
*ctx
)
5096 TCGv t0
= tcg_temp_new();
5097 TCGv t1
= tcg_temp_new();
5098 TCGv t2
= tcg_temp_new();
5099 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5100 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5101 tcg_gen_shr_tl(t1
, t1
, t0
);
5102 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5103 gen_load_spr(t2
, SPR_MQ
);
5104 gen_store_spr(SPR_MQ
, t0
);
5105 tcg_gen_and_tl(t0
, t0
, t1
);
5106 tcg_gen_andc_tl(t2
, t2
, t1
);
5107 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5111 if (unlikely(Rc(ctx
->opcode
) != 0))
5112 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5116 static void gen_sriq(DisasContext
*ctx
)
5118 int sh
= SH(ctx
->opcode
);
5119 TCGv t0
= tcg_temp_new();
5120 TCGv t1
= tcg_temp_new();
5121 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5122 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5123 tcg_gen_or_tl(t1
, t0
, t1
);
5124 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5125 gen_store_spr(SPR_MQ
, t1
);
5128 if (unlikely(Rc(ctx
->opcode
) != 0))
5129 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5133 static void gen_srliq(DisasContext
*ctx
)
5135 int sh
= SH(ctx
->opcode
);
5136 TCGv t0
= tcg_temp_new();
5137 TCGv t1
= tcg_temp_new();
5138 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5139 gen_load_spr(t1
, SPR_MQ
);
5140 gen_store_spr(SPR_MQ
, t0
);
5141 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5142 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5143 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5146 if (unlikely(Rc(ctx
->opcode
) != 0))
5147 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5151 static void gen_srlq(DisasContext
*ctx
)
5153 TCGLabel
*l1
= gen_new_label();
5154 TCGLabel
*l2
= gen_new_label();
5155 TCGv t0
= tcg_temp_local_new();
5156 TCGv t1
= tcg_temp_local_new();
5157 TCGv t2
= tcg_temp_local_new();
5158 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5159 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5160 tcg_gen_shr_tl(t2
, t1
, t2
);
5161 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5162 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5163 gen_load_spr(t0
, SPR_MQ
);
5164 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5167 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5168 tcg_gen_and_tl(t0
, t0
, t2
);
5169 gen_load_spr(t1
, SPR_MQ
);
5170 tcg_gen_andc_tl(t1
, t1
, t2
);
5171 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5176 if (unlikely(Rc(ctx
->opcode
) != 0))
5177 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5181 static void gen_srq(DisasContext
*ctx
)
5183 TCGLabel
*l1
= gen_new_label();
5184 TCGv t0
= tcg_temp_new();
5185 TCGv t1
= tcg_temp_new();
5186 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5187 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5188 tcg_gen_subfi_tl(t1
, 32, t1
);
5189 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5190 tcg_gen_or_tl(t1
, t0
, t1
);
5191 gen_store_spr(SPR_MQ
, t1
);
5192 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5193 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5194 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5195 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5199 if (unlikely(Rc(ctx
->opcode
) != 0))
5200 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5203 /* PowerPC 602 specific instructions */
5206 static void gen_dsa(DisasContext
*ctx
)
5209 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5213 static void gen_esa(DisasContext
*ctx
)
5216 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5220 static void gen_mfrom(DisasContext
*ctx
)
5222 #if defined(CONFIG_USER_ONLY)
5226 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5227 #endif /* defined(CONFIG_USER_ONLY) */
5230 /* 602 - 603 - G2 TLB management */
5233 static void gen_tlbld_6xx(DisasContext
*ctx
)
5235 #if defined(CONFIG_USER_ONLY)
5239 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5240 #endif /* defined(CONFIG_USER_ONLY) */
5244 static void gen_tlbli_6xx(DisasContext
*ctx
)
5246 #if defined(CONFIG_USER_ONLY)
5250 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5251 #endif /* defined(CONFIG_USER_ONLY) */
5254 /* 74xx TLB management */
5257 static void gen_tlbld_74xx(DisasContext
*ctx
)
5259 #if defined(CONFIG_USER_ONLY)
5263 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5264 #endif /* defined(CONFIG_USER_ONLY) */
5268 static void gen_tlbli_74xx(DisasContext
*ctx
)
5270 #if defined(CONFIG_USER_ONLY)
5274 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5275 #endif /* defined(CONFIG_USER_ONLY) */
5278 /* POWER instructions not in PowerPC 601 */
5281 static void gen_clf(DisasContext
*ctx
)
5283 /* Cache line flush: implemented as no-op */
5287 static void gen_cli(DisasContext
*ctx
)
5289 #if defined(CONFIG_USER_ONLY)
5292 /* Cache line invalidate: privileged and treated as no-op */
5294 #endif /* defined(CONFIG_USER_ONLY) */
5298 static void gen_dclst(DisasContext
*ctx
)
5300 /* Data cache line store: treated as no-op */
5303 static void gen_mfsri(DisasContext
*ctx
)
5305 #if defined(CONFIG_USER_ONLY)
5308 int ra
= rA(ctx
->opcode
);
5309 int rd
= rD(ctx
->opcode
);
5313 t0
= tcg_temp_new();
5314 gen_addr_reg_index(ctx
, t0
);
5315 tcg_gen_shri_tl(t0
, t0
, 28);
5316 tcg_gen_andi_tl(t0
, t0
, 0xF);
5317 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5319 if (ra
!= 0 && ra
!= rd
)
5320 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5321 #endif /* defined(CONFIG_USER_ONLY) */
5324 static void gen_rac(DisasContext
*ctx
)
5326 #if defined(CONFIG_USER_ONLY)
5332 t0
= tcg_temp_new();
5333 gen_addr_reg_index(ctx
, t0
);
5334 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5336 #endif /* defined(CONFIG_USER_ONLY) */
5339 static void gen_rfsvc(DisasContext
*ctx
)
5341 #if defined(CONFIG_USER_ONLY)
5346 gen_helper_rfsvc(cpu_env
);
5347 gen_sync_exception(ctx
);
5348 #endif /* defined(CONFIG_USER_ONLY) */
5351 /* svc is not implemented for now */
5353 /* BookE specific instructions */
5355 /* XXX: not implemented on 440 ? */
5356 static void gen_mfapidi(DisasContext
*ctx
)
5359 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5362 /* XXX: not implemented on 440 ? */
5363 static void gen_tlbiva(DisasContext
*ctx
)
5365 #if defined(CONFIG_USER_ONLY)
5371 t0
= tcg_temp_new();
5372 gen_addr_reg_index(ctx
, t0
);
5373 gen_helper_tlbiva(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5375 #endif /* defined(CONFIG_USER_ONLY) */
5378 /* All 405 MAC instructions are translated here */
5379 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5380 int ra
, int rb
, int rt
, int Rc
)
5384 t0
= tcg_temp_local_new();
5385 t1
= tcg_temp_local_new();
5387 switch (opc3
& 0x0D) {
5389 /* macchw - macchw. - macchwo - macchwo. */
5390 /* macchws - macchws. - macchwso - macchwso. */
5391 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5392 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5393 /* mulchw - mulchw. */
5394 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5395 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5396 tcg_gen_ext16s_tl(t1
, t1
);
5399 /* macchwu - macchwu. - macchwuo - macchwuo. */
5400 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5401 /* mulchwu - mulchwu. */
5402 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5403 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5404 tcg_gen_ext16u_tl(t1
, t1
);
5407 /* machhw - machhw. - machhwo - machhwo. */
5408 /* machhws - machhws. - machhwso - machhwso. */
5409 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5410 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5411 /* mulhhw - mulhhw. */
5412 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5413 tcg_gen_ext16s_tl(t0
, t0
);
5414 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5415 tcg_gen_ext16s_tl(t1
, t1
);
5418 /* machhwu - machhwu. - machhwuo - machhwuo. */
5419 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5420 /* mulhhwu - mulhhwu. */
5421 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5422 tcg_gen_ext16u_tl(t0
, t0
);
5423 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5424 tcg_gen_ext16u_tl(t1
, t1
);
5427 /* maclhw - maclhw. - maclhwo - maclhwo. */
5428 /* maclhws - maclhws. - maclhwso - maclhwso. */
5429 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5430 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5431 /* mullhw - mullhw. */
5432 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5433 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5436 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5437 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5438 /* mullhwu - mullhwu. */
5439 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5440 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5444 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5445 tcg_gen_mul_tl(t1
, t0
, t1
);
5447 /* nmultiply-and-accumulate (0x0E) */
5448 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5450 /* multiply-and-accumulate (0x0C) */
5451 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5455 /* Check overflow and/or saturate */
5456 TCGLabel
*l1
= gen_new_label();
5459 /* Start with XER OV disabled, the most likely case */
5460 tcg_gen_movi_tl(cpu_ov
, 0);
5464 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5465 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5466 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5467 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5470 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5471 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5475 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5478 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5482 /* Check overflow */
5483 tcg_gen_movi_tl(cpu_ov
, 1);
5484 tcg_gen_movi_tl(cpu_so
, 1);
5487 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5490 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5494 if (unlikely(Rc
) != 0) {
5496 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5500 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5501 static void glue(gen_, name)(DisasContext *ctx) \
5503 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5504 rD(ctx->opcode), Rc(ctx->opcode)); \
5507 /* macchw - macchw. */
5508 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5509 /* macchwo - macchwo. */
5510 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5511 /* macchws - macchws. */
5512 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5513 /* macchwso - macchwso. */
5514 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5515 /* macchwsu - macchwsu. */
5516 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5517 /* macchwsuo - macchwsuo. */
5518 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5519 /* macchwu - macchwu. */
5520 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5521 /* macchwuo - macchwuo. */
5522 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5523 /* machhw - machhw. */
5524 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5525 /* machhwo - machhwo. */
5526 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5527 /* machhws - machhws. */
5528 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5529 /* machhwso - machhwso. */
5530 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5531 /* machhwsu - machhwsu. */
5532 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5533 /* machhwsuo - machhwsuo. */
5534 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5535 /* machhwu - machhwu. */
5536 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5537 /* machhwuo - machhwuo. */
5538 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5539 /* maclhw - maclhw. */
5540 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5541 /* maclhwo - maclhwo. */
5542 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5543 /* maclhws - maclhws. */
5544 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5545 /* maclhwso - maclhwso. */
5546 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5547 /* maclhwu - maclhwu. */
5548 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5549 /* maclhwuo - maclhwuo. */
5550 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5551 /* maclhwsu - maclhwsu. */
5552 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5553 /* maclhwsuo - maclhwsuo. */
5554 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5555 /* nmacchw - nmacchw. */
5556 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5557 /* nmacchwo - nmacchwo. */
5558 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5559 /* nmacchws - nmacchws. */
5560 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5561 /* nmacchwso - nmacchwso. */
5562 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5563 /* nmachhw - nmachhw. */
5564 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5565 /* nmachhwo - nmachhwo. */
5566 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5567 /* nmachhws - nmachhws. */
5568 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5569 /* nmachhwso - nmachhwso. */
5570 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5571 /* nmaclhw - nmaclhw. */
5572 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5573 /* nmaclhwo - nmaclhwo. */
5574 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5575 /* nmaclhws - nmaclhws. */
5576 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5577 /* nmaclhwso - nmaclhwso. */
5578 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5580 /* mulchw - mulchw. */
5581 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5582 /* mulchwu - mulchwu. */
5583 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5584 /* mulhhw - mulhhw. */
5585 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5586 /* mulhhwu - mulhhwu. */
5587 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5588 /* mullhw - mullhw. */
5589 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5590 /* mullhwu - mullhwu. */
5591 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5594 static void gen_mfdcr(DisasContext
*ctx
)
5596 #if defined(CONFIG_USER_ONLY)
5602 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5603 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5604 tcg_temp_free(dcrn
);
5605 #endif /* defined(CONFIG_USER_ONLY) */
5609 static void gen_mtdcr(DisasContext
*ctx
)
5611 #if defined(CONFIG_USER_ONLY)
5617 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5618 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5619 tcg_temp_free(dcrn
);
5620 #endif /* defined(CONFIG_USER_ONLY) */
5624 /* XXX: not implemented on 440 ? */
5625 static void gen_mfdcrx(DisasContext
*ctx
)
5627 #if defined(CONFIG_USER_ONLY)
5631 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5632 cpu_gpr
[rA(ctx
->opcode
)]);
5633 /* Note: Rc update flag set leads to undefined state of Rc0 */
5634 #endif /* defined(CONFIG_USER_ONLY) */
5638 /* XXX: not implemented on 440 ? */
5639 static void gen_mtdcrx(DisasContext
*ctx
)
5641 #if defined(CONFIG_USER_ONLY)
5645 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5646 cpu_gpr
[rS(ctx
->opcode
)]);
5647 /* Note: Rc update flag set leads to undefined state of Rc0 */
5648 #endif /* defined(CONFIG_USER_ONLY) */
5651 /* mfdcrux (PPC 460) : user-mode access to DCR */
5652 static void gen_mfdcrux(DisasContext
*ctx
)
5654 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5655 cpu_gpr
[rA(ctx
->opcode
)]);
5656 /* Note: Rc update flag set leads to undefined state of Rc0 */
5659 /* mtdcrux (PPC 460) : user-mode access to DCR */
5660 static void gen_mtdcrux(DisasContext
*ctx
)
5662 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5663 cpu_gpr
[rS(ctx
->opcode
)]);
5664 /* Note: Rc update flag set leads to undefined state of Rc0 */
5668 static void gen_dccci(DisasContext
*ctx
)
5671 /* interpreted as no-op */
5675 static void gen_dcread(DisasContext
*ctx
)
5677 #if defined(CONFIG_USER_ONLY)
5683 gen_set_access_type(ctx
, ACCESS_CACHE
);
5684 EA
= tcg_temp_new();
5685 gen_addr_reg_index(ctx
, EA
);
5686 val
= tcg_temp_new();
5687 gen_qemu_ld32u(ctx
, val
, EA
);
5689 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5691 #endif /* defined(CONFIG_USER_ONLY) */
5695 static void gen_icbt_40x(DisasContext
*ctx
)
5697 /* interpreted as no-op */
5698 /* XXX: specification say this is treated as a load by the MMU
5699 * but does not generate any exception
5704 static void gen_iccci(DisasContext
*ctx
)
5707 /* interpreted as no-op */
5711 static void gen_icread(DisasContext
*ctx
)
5714 /* interpreted as no-op */
5717 /* rfci (supervisor only) */
5718 static void gen_rfci_40x(DisasContext
*ctx
)
5720 #if defined(CONFIG_USER_ONLY)
5724 /* Restore CPU state */
5725 gen_helper_40x_rfci(cpu_env
);
5726 gen_sync_exception(ctx
);
5727 #endif /* defined(CONFIG_USER_ONLY) */
5730 static void gen_rfci(DisasContext
*ctx
)
5732 #if defined(CONFIG_USER_ONLY)
5736 /* Restore CPU state */
5737 gen_helper_rfci(cpu_env
);
5738 gen_sync_exception(ctx
);
5739 #endif /* defined(CONFIG_USER_ONLY) */
5742 /* BookE specific */
5744 /* XXX: not implemented on 440 ? */
5745 static void gen_rfdi(DisasContext
*ctx
)
5747 #if defined(CONFIG_USER_ONLY)
5751 /* Restore CPU state */
5752 gen_helper_rfdi(cpu_env
);
5753 gen_sync_exception(ctx
);
5754 #endif /* defined(CONFIG_USER_ONLY) */
5757 /* XXX: not implemented on 440 ? */
5758 static void gen_rfmci(DisasContext
*ctx
)
5760 #if defined(CONFIG_USER_ONLY)
5764 /* Restore CPU state */
5765 gen_helper_rfmci(cpu_env
);
5766 gen_sync_exception(ctx
);
5767 #endif /* defined(CONFIG_USER_ONLY) */
5770 /* TLB management - PowerPC 405 implementation */
5773 static void gen_tlbre_40x(DisasContext
*ctx
)
5775 #if defined(CONFIG_USER_ONLY)
5779 switch (rB(ctx
->opcode
)) {
5781 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5782 cpu_gpr
[rA(ctx
->opcode
)]);
5785 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5786 cpu_gpr
[rA(ctx
->opcode
)]);
5789 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5792 #endif /* defined(CONFIG_USER_ONLY) */
5795 /* tlbsx - tlbsx. */
5796 static void gen_tlbsx_40x(DisasContext
*ctx
)
5798 #if defined(CONFIG_USER_ONLY)
5804 t0
= tcg_temp_new();
5805 gen_addr_reg_index(ctx
, t0
);
5806 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5808 if (Rc(ctx
->opcode
)) {
5809 TCGLabel
*l1
= gen_new_label();
5810 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5811 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5812 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5815 #endif /* defined(CONFIG_USER_ONLY) */
5819 static void gen_tlbwe_40x(DisasContext
*ctx
)
5821 #if defined(CONFIG_USER_ONLY)
5826 switch (rB(ctx
->opcode
)) {
5828 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5829 cpu_gpr
[rS(ctx
->opcode
)]);
5832 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5833 cpu_gpr
[rS(ctx
->opcode
)]);
5836 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5839 #endif /* defined(CONFIG_USER_ONLY) */
5842 /* TLB management - PowerPC 440 implementation */
5845 static void gen_tlbre_440(DisasContext
*ctx
)
5847 #if defined(CONFIG_USER_ONLY)
5852 switch (rB(ctx
->opcode
)) {
5857 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5858 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5859 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5860 tcg_temp_free_i32(t0
);
5864 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5867 #endif /* defined(CONFIG_USER_ONLY) */
5870 /* tlbsx - tlbsx. */
5871 static void gen_tlbsx_440(DisasContext
*ctx
)
5873 #if defined(CONFIG_USER_ONLY)
5879 t0
= tcg_temp_new();
5880 gen_addr_reg_index(ctx
, t0
);
5881 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5883 if (Rc(ctx
->opcode
)) {
5884 TCGLabel
*l1
= gen_new_label();
5885 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5886 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5887 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5890 #endif /* defined(CONFIG_USER_ONLY) */
5894 static void gen_tlbwe_440(DisasContext
*ctx
)
5896 #if defined(CONFIG_USER_ONLY)
5900 switch (rB(ctx
->opcode
)) {
5905 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5906 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
5907 cpu_gpr
[rS(ctx
->opcode
)]);
5908 tcg_temp_free_i32(t0
);
5912 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5915 #endif /* defined(CONFIG_USER_ONLY) */
5918 /* TLB management - PowerPC BookE 2.06 implementation */
5921 static void gen_tlbre_booke206(DisasContext
*ctx
)
5923 #if defined(CONFIG_USER_ONLY)
5927 gen_helper_booke206_tlbre(cpu_env
);
5928 #endif /* defined(CONFIG_USER_ONLY) */
5931 /* tlbsx - tlbsx. */
5932 static void gen_tlbsx_booke206(DisasContext
*ctx
)
5934 #if defined(CONFIG_USER_ONLY)
5940 if (rA(ctx
->opcode
)) {
5941 t0
= tcg_temp_new();
5942 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
5944 t0
= tcg_const_tl(0);
5947 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
5948 gen_helper_booke206_tlbsx(cpu_env
, t0
);
5950 #endif /* defined(CONFIG_USER_ONLY) */
5954 static void gen_tlbwe_booke206(DisasContext
*ctx
)
5956 #if defined(CONFIG_USER_ONLY)
5960 gen_helper_booke206_tlbwe(cpu_env
);
5961 #endif /* defined(CONFIG_USER_ONLY) */
5964 static void gen_tlbivax_booke206(DisasContext
*ctx
)
5966 #if defined(CONFIG_USER_ONLY)
5972 t0
= tcg_temp_new();
5973 gen_addr_reg_index(ctx
, t0
);
5974 gen_helper_booke206_tlbivax(cpu_env
, t0
);
5976 #endif /* defined(CONFIG_USER_ONLY) */
5979 static void gen_tlbilx_booke206(DisasContext
*ctx
)
5981 #if defined(CONFIG_USER_ONLY)
5987 t0
= tcg_temp_new();
5988 gen_addr_reg_index(ctx
, t0
);
5990 switch((ctx
->opcode
>> 21) & 0x3) {
5992 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
5995 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
5998 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6001 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6006 #endif /* defined(CONFIG_USER_ONLY) */
6011 static void gen_wrtee(DisasContext
*ctx
)
6013 #if defined(CONFIG_USER_ONLY)
6019 t0
= tcg_temp_new();
6020 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6021 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6022 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6024 /* Stop translation to have a chance to raise an exception
6025 * if we just set msr_ee to 1
6027 gen_stop_exception(ctx
);
6028 #endif /* defined(CONFIG_USER_ONLY) */
6032 static void gen_wrteei(DisasContext
*ctx
)
6034 #if defined(CONFIG_USER_ONLY)
6038 if (ctx
->opcode
& 0x00008000) {
6039 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6040 /* Stop translation to have a chance to raise an exception */
6041 gen_stop_exception(ctx
);
6043 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6045 #endif /* defined(CONFIG_USER_ONLY) */
6048 /* PowerPC 440 specific instructions */
6051 static void gen_dlmzb(DisasContext
*ctx
)
6053 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6054 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6055 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6056 tcg_temp_free_i32(t0
);
6059 /* mbar replaces eieio on 440 */
6060 static void gen_mbar(DisasContext
*ctx
)
6062 /* interpreted as no-op */
6065 /* msync replaces sync on 440 */
6066 static void gen_msync_4xx(DisasContext
*ctx
)
6068 /* interpreted as no-op */
6072 static void gen_icbt_440(DisasContext
*ctx
)
6074 /* interpreted as no-op */
6075 /* XXX: specification say this is treated as a load by the MMU
6076 * but does not generate any exception
6080 /* Embedded.Processor Control */
6082 static void gen_msgclr(DisasContext
*ctx
)
6084 #if defined(CONFIG_USER_ONLY)
6088 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6089 #endif /* defined(CONFIG_USER_ONLY) */
6092 static void gen_msgsnd(DisasContext
*ctx
)
6094 #if defined(CONFIG_USER_ONLY)
6098 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6099 #endif /* defined(CONFIG_USER_ONLY) */
6103 #if defined(TARGET_PPC64)
6104 static void gen_maddld(DisasContext
*ctx
)
6106 TCGv_i64 t1
= tcg_temp_new_i64();
6108 tcg_gen_mul_i64(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6109 tcg_gen_add_i64(cpu_gpr
[rD(ctx
->opcode
)], t1
, cpu_gpr
[rC(ctx
->opcode
)]);
6110 tcg_temp_free_i64(t1
);
6113 /* maddhd maddhdu */
6114 static void gen_maddhd_maddhdu(DisasContext
*ctx
)
6116 TCGv_i64 lo
= tcg_temp_new_i64();
6117 TCGv_i64 hi
= tcg_temp_new_i64();
6118 TCGv_i64 t1
= tcg_temp_new_i64();
6120 if (Rc(ctx
->opcode
)) {
6121 tcg_gen_mulu2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
6122 cpu_gpr
[rB(ctx
->opcode
)]);
6123 tcg_gen_movi_i64(t1
, 0);
6125 tcg_gen_muls2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
6126 cpu_gpr
[rB(ctx
->opcode
)]);
6127 tcg_gen_sari_i64(t1
, cpu_gpr
[rC(ctx
->opcode
)], 63);
6129 tcg_gen_add2_i64(t1
, cpu_gpr
[rD(ctx
->opcode
)], lo
, hi
,
6130 cpu_gpr
[rC(ctx
->opcode
)], t1
);
6131 tcg_temp_free_i64(lo
);
6132 tcg_temp_free_i64(hi
);
6133 tcg_temp_free_i64(t1
);
6135 #endif /* defined(TARGET_PPC64) */
6137 static void gen_tbegin(DisasContext
*ctx
)
6139 if (unlikely(!ctx
->tm_enabled
)) {
6140 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6143 gen_helper_tbegin(cpu_env
);
6146 #define GEN_TM_NOOP(name) \
6147 static inline void gen_##name(DisasContext *ctx) \
6149 if (unlikely(!ctx->tm_enabled)) { \
6150 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6153 /* Because tbegin always fails in QEMU, these user \
6154 * space instructions all have a simple implementation: \
6156 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6157 * = 0b0 || 0b00 || 0b0 \
6159 tcg_gen_movi_i32(cpu_crf[0], 0); \
6163 GEN_TM_NOOP(tabort
);
6164 GEN_TM_NOOP(tabortwc
);
6165 GEN_TM_NOOP(tabortwci
);
6166 GEN_TM_NOOP(tabortdc
);
6167 GEN_TM_NOOP(tabortdci
);
6170 static void gen_tcheck(DisasContext
*ctx
)
6172 if (unlikely(!ctx
->tm_enabled
)) {
6173 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6176 /* Because tbegin always fails, the tcheck implementation
6179 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
6180 * = 0b1 || 0b00 || 0b0
6182 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
6185 #if defined(CONFIG_USER_ONLY)
6186 #define GEN_TM_PRIV_NOOP(name) \
6187 static inline void gen_##name(DisasContext *ctx) \
6189 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
6194 #define GEN_TM_PRIV_NOOP(name) \
6195 static inline void gen_##name(DisasContext *ctx) \
6198 if (unlikely(!ctx->tm_enabled)) { \
6199 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6202 /* Because tbegin always fails, the implementation is \
6205 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6206 * = 0b0 || 0b00 | 0b0 \
6208 tcg_gen_movi_i32(cpu_crf[0], 0); \
6213 GEN_TM_PRIV_NOOP(treclaim
);
6214 GEN_TM_PRIV_NOOP(trechkpt
);
6216 #include "translate/fp-impl.inc.c"
6218 #include "translate/vmx-impl.inc.c"
6220 #include "translate/vsx-impl.inc.c"
6222 #include "translate/dfp-impl.inc.c"
6224 #include "translate/spe-impl.inc.c"
6226 static opcode_t opcodes
[] = {
6227 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
6228 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
6229 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
6230 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400001, PPC_INTEGER
),
6231 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
6232 #if defined(TARGET_PPC64)
6233 GEN_HANDLER_E(cmpeqb
, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE
, PPC2_ISA300
),
6235 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
6236 GEN_HANDLER_E(cmprb
, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE
, PPC2_ISA300
),
6237 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
6238 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6239 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6240 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6241 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6242 GEN_HANDLER_E(addpcis
, 0x13, 0x2, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6243 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
6244 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
6245 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
6246 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
6247 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6248 #if defined(TARGET_PPC64)
6249 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
6251 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
6252 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
6253 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6254 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6255 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6256 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
6257 GEN_HANDLER_E(cnttzw
, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6258 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
6259 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
6260 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6261 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6262 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6263 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6264 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
6265 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
6266 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6267 #if defined(TARGET_PPC64)
6268 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
6269 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
6270 GEN_HANDLER_E(cnttzd
, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6271 GEN_HANDLER_E(darn
, 0x1F, 0x13, 0x17, 0x001CF801, PPC_NONE
, PPC2_ISA300
),
6272 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6273 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
6275 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6276 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6277 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6278 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
6279 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
6280 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
6281 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
6282 #if defined(TARGET_PPC64)
6283 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
6284 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
6285 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
6286 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
6287 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
6288 GEN_HANDLER2_E(extswsli0
, "extswsli", 0x1F, 0x1A, 0x1B, 0x00000000,
6289 PPC_NONE
, PPC2_ISA300
),
6290 GEN_HANDLER2_E(extswsli1
, "extswsli", 0x1F, 0x1B, 0x1B, 0x00000000,
6291 PPC_NONE
, PPC2_ISA300
),
6293 #if defined(TARGET_PPC64)
6294 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6295 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
6296 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6298 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6299 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6300 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
6301 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
6302 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
6303 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
6304 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
6305 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
6306 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6307 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6308 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
6309 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6310 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6311 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
6312 #if defined(TARGET_PPC64)
6313 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
6314 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
6315 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
6316 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
6318 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
6319 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
6320 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6321 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6322 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
6323 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
6324 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE
, PPC2_BCTAR_ISA207
),
6325 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
6326 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
6327 #if defined(TARGET_PPC64)
6328 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
6329 GEN_HANDLER_E(doze
, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6330 GEN_HANDLER_E(nap
, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6331 GEN_HANDLER_E(sleep
, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6332 GEN_HANDLER_E(rvwinkle
, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6333 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
6335 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
6336 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
6337 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6338 #if defined(TARGET_PPC64)
6339 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
6340 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6342 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
6343 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
6344 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
6345 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
6346 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
6347 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
6348 #if defined(TARGET_PPC64)
6349 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
6350 GEN_HANDLER_E(setb
, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE
, PPC2_ISA300
),
6352 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC
),
6353 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
6354 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
6355 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
6356 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
6357 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
6358 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
6359 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
6360 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
6361 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
6362 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
6363 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
6364 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
6365 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
6366 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
6367 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
6368 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
6369 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
6370 #if defined(TARGET_PPC64)
6371 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
6372 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
6374 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
6375 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
6377 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
6378 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
6379 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
6380 GEN_HANDLER2(slbfee_
, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F0000, PPC_SEGMENT_64B
),
6382 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
6383 /* XXX Those instructions will need to be handled differently for
6384 * different ISA versions */
6385 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE
),
6386 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE
),
6387 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
6388 #if defined(TARGET_PPC64)
6389 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI
),
6390 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
6392 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
6393 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
6394 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
6395 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
6396 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
6397 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
6398 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
6399 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
6400 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
6401 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
6402 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
6403 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
6404 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
6405 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
6406 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
6407 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
6408 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
6409 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
6410 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
6411 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
6412 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
6413 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
6414 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
6415 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
6416 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
6417 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
6418 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
6419 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
6420 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
6421 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
6422 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
6423 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
6424 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
6425 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
6426 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
6427 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
6428 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
6429 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
6430 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
6431 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
6432 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
6433 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
6434 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
6435 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
6436 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
6437 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
6438 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
6439 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
6440 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
6441 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
6442 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
6443 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
6444 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
6445 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
6446 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
6447 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
6448 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
6449 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
6450 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
6451 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
6452 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
6453 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
6454 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
6455 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
6456 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
6457 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
6458 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
6459 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
6460 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
6461 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
6462 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
6463 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
6464 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
6465 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
6466 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
6467 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
6468 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
6469 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
6470 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
6471 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
6472 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
6473 PPC_NONE
, PPC2_BOOKE206
),
6474 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
6475 PPC_NONE
, PPC2_BOOKE206
),
6476 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
6477 PPC_NONE
, PPC2_BOOKE206
),
6478 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
6479 PPC_NONE
, PPC2_BOOKE206
),
6480 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
6481 PPC_NONE
, PPC2_BOOKE206
),
6482 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
6483 PPC_NONE
, PPC2_PRCNTL
),
6484 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
6485 PPC_NONE
, PPC2_PRCNTL
),
6486 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
6487 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
6488 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
6489 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
6490 PPC_BOOKE
, PPC2_BOOKE206
),
6491 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
6492 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
6493 PPC_BOOKE
, PPC2_BOOKE206
),
6494 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
6495 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
6496 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
6497 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
6498 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
6499 #if defined(TARGET_PPC64)
6500 GEN_HANDLER_E(maddhd_maddhdu
, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE
,
6502 GEN_HANDLER_E(maddld
, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6505 #undef GEN_INT_ARITH_ADD
6506 #undef GEN_INT_ARITH_ADD_CONST
6507 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
6508 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
6509 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
6510 add_ca, compute_ca, compute_ov) \
6511 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
6512 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
6513 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
6514 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
6515 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
6516 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
6517 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
6518 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
6519 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
6520 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
6521 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
6523 #undef GEN_INT_ARITH_DIVW
6524 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
6525 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
6526 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
6527 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
6528 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
6529 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
6530 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6531 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6532 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6533 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6534 GEN_HANDLER_E(modsw
, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6535 GEN_HANDLER_E(moduw
, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6537 #if defined(TARGET_PPC64)
6538 #undef GEN_INT_ARITH_DIVD
6539 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
6540 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
6541 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
6542 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
6543 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
6544 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
6546 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6547 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6548 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6549 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6550 GEN_HANDLER_E(modsd
, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6551 GEN_HANDLER_E(modud
, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6553 #undef GEN_INT_ARITH_MUL_HELPER
6554 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
6555 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
6556 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
6557 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
6558 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
6561 #undef GEN_INT_ARITH_SUBF
6562 #undef GEN_INT_ARITH_SUBF_CONST
6563 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
6564 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
6565 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
6566 add_ca, compute_ca, compute_ov) \
6567 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
6568 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
6569 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
6570 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
6571 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
6572 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
6573 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
6574 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
6575 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
6576 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
6577 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
6581 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
6582 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
6583 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
6584 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
6585 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
6586 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
6587 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
6588 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
6589 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
6590 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
6591 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
6592 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
6593 #if defined(TARGET_PPC64)
6594 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
6597 #if defined(TARGET_PPC64)
6600 #define GEN_PPC64_R2(name, opc1, opc2) \
6601 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
6602 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
6604 #define GEN_PPC64_R4(name, opc1, opc2) \
6605 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
6606 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
6608 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
6610 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
6612 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
6613 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
6614 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
6615 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
6616 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
6617 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
6625 #define GEN_LD(name, ldop, opc, type) \
6626 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
6627 #define GEN_LDU(name, ldop, opc, type) \
6628 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
6629 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
6630 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
6631 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
6632 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
6633 #define GEN_LDS(name, ldop, op, type) \
6634 GEN_LD(name, ldop, op | 0x20, type) \
6635 GEN_LDU(name, ldop, op | 0x21, type) \
6636 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
6637 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
6639 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
6640 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
6641 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
6642 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
6643 #if defined(TARGET_PPC64)
6644 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
6645 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
6646 GEN_LDUX(ld
, ld64_i64
, 0x15, 0x01, PPC_64B
)
6647 GEN_LDX(ld
, ld64_i64
, 0x15, 0x00, PPC_64B
)
6648 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
6650 /* HV/P7 and later only */
6651 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
6652 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x18, PPC_CILDST
)
6653 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
6654 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
6656 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
6657 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
6664 #define GEN_ST(name, stop, opc, type) \
6665 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
6666 #define GEN_STU(name, stop, opc, type) \
6667 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
6668 #define GEN_STUX(name, stop, opc2, opc3, type) \
6669 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
6670 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
6671 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
6672 #define GEN_STS(name, stop, op, type) \
6673 GEN_ST(name, stop, op | 0x20, type) \
6674 GEN_STU(name, stop, op | 0x21, type) \
6675 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
6676 GEN_STX(name, stop, 0x17, op | 0x00, type)
6678 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
6679 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
6680 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
6681 #if defined(TARGET_PPC64)
6682 GEN_STUX(std
, st64_i64
, 0x15, 0x05, PPC_64B
)
6683 GEN_STX(std
, st64_i64
, 0x15, 0x04, PPC_64B
)
6684 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
6685 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
6686 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
6687 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
6688 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
6690 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
6691 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
6694 #define GEN_CRLOGIC(name, tcg_op, opc) \
6695 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
6696 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
6697 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
6698 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
6699 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
6700 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
6701 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
6702 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
6703 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
6705 #undef GEN_MAC_HANDLER
6706 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6707 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
6708 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
6709 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
6710 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
6711 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
6712 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
6713 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
6714 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
6715 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
6716 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
6717 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
6718 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
6719 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
6720 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
6721 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
6722 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
6723 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
6724 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
6725 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
6726 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
6727 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
6728 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
6729 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
6730 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
6731 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
6732 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
6733 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
6734 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
6735 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
6736 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
6737 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
6738 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
6739 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
6740 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
6741 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
6742 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
6743 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
6744 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
6745 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
6746 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
6747 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
6748 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
6749 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
6751 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
6753 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
6755 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
6757 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
6759 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
6761 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
6763 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
6765 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
6767 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
6769 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
6771 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
6774 #include "translate/fp-ops.inc.c"
6776 #include "translate/vmx-ops.inc.c"
6778 #include "translate/vsx-ops.inc.c"
6780 #include "translate/dfp-ops.inc.c"
6782 #include "translate/spe-ops.inc.c"
6785 #include "helper_regs.h"
6786 #include "translate_init.c"
6788 /*****************************************************************************/
6789 /* Misc PowerPC helpers */
6790 void ppc_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
6796 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
6797 CPUPPCState
*env
= &cpu
->env
;
6800 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
6801 TARGET_FMT_lx
" XER " TARGET_FMT_lx
" CPU#%d\n",
6802 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
),
6804 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
6805 TARGET_FMT_lx
" iidx %d didx %d\n",
6806 env
->msr
, env
->spr
[SPR_HID0
],
6807 env
->hflags
, env
->immu_idx
, env
->dmmu_idx
);
6808 #if !defined(NO_TIMER_DUMP)
6809 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
6810 #if !defined(CONFIG_USER_ONLY)
6814 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
6815 #if !defined(CONFIG_USER_ONLY)
6816 , cpu_ppc_load_decr(env
)
6820 for (i
= 0; i
< 32; i
++) {
6821 if ((i
& (RGPL
- 1)) == 0)
6822 cpu_fprintf(f
, "GPR%02d", i
);
6823 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
6824 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
6825 cpu_fprintf(f
, "\n");
6827 cpu_fprintf(f
, "CR ");
6828 for (i
= 0; i
< 8; i
++)
6829 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
6830 cpu_fprintf(f
, " [");
6831 for (i
= 0; i
< 8; i
++) {
6833 if (env
->crf
[i
] & 0x08)
6835 else if (env
->crf
[i
] & 0x04)
6837 else if (env
->crf
[i
] & 0x02)
6839 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
6841 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
6843 for (i
= 0; i
< 32; i
++) {
6844 if ((i
& (RFPL
- 1)) == 0)
6845 cpu_fprintf(f
, "FPR%02d", i
);
6846 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
6847 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
6848 cpu_fprintf(f
, "\n");
6850 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
6851 #if !defined(CONFIG_USER_ONLY)
6852 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
6853 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
6854 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
6855 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
6857 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
6858 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
6859 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
6860 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
6862 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
6863 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
6864 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
6865 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
6867 #if defined(TARGET_PPC64)
6868 if (env
->excp_model
== POWERPC_EXCP_POWER7
||
6869 env
->excp_model
== POWERPC_EXCP_POWER8
) {
6870 cpu_fprintf(f
, "HSRR0 " TARGET_FMT_lx
" HSRR1 " TARGET_FMT_lx
"\n",
6871 env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
]);
6874 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
6875 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
6876 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
6877 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
6878 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
6880 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
6881 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
6882 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
6883 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
6885 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
6886 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
6887 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
6888 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
6890 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
6891 " EPR " TARGET_FMT_lx
"\n",
6892 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
6893 env
->spr
[SPR_BOOKE_EPR
]);
6896 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
6897 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
6898 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
6899 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
6902 * IVORs are left out as they are large and do not change often --
6903 * they can be read with "p $ivor0", "p $ivor1", etc.
6907 #if defined(TARGET_PPC64)
6908 if (env
->flags
& POWERPC_FLAG_CFAR
) {
6909 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
6913 switch (env
->mmu_model
) {
6914 case POWERPC_MMU_32B
:
6915 case POWERPC_MMU_601
:
6916 case POWERPC_MMU_SOFT_6xx
:
6917 case POWERPC_MMU_SOFT_74xx
:
6918 #if defined(TARGET_PPC64)
6919 case POWERPC_MMU_64B
:
6920 case POWERPC_MMU_2_03
:
6921 case POWERPC_MMU_2_06
:
6922 case POWERPC_MMU_2_06a
:
6923 case POWERPC_MMU_2_07
:
6924 case POWERPC_MMU_2_07a
:
6926 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
" DAR " TARGET_FMT_lx
6927 " DSISR " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
],
6928 env
->spr
[SPR_DAR
], env
->spr
[SPR_DSISR
]);
6930 case POWERPC_MMU_BOOKE206
:
6931 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
6932 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
6933 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
6934 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
6936 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
6937 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
6938 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
6939 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
6941 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
6942 " TLB1CFG " TARGET_FMT_lx
"\n",
6943 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
6944 env
->spr
[SPR_BOOKE_TLB1CFG
]);
6955 void ppc_cpu_dump_statistics(CPUState
*cs
, FILE*f
,
6956 fprintf_function cpu_fprintf
, int flags
)
6958 #if defined(DO_PPC_STATISTICS)
6959 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
6960 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
6963 t1
= cpu
->env
.opcodes
;
6964 for (op1
= 0; op1
< 64; op1
++) {
6966 if (is_indirect_opcode(handler
)) {
6967 t2
= ind_table(handler
);
6968 for (op2
= 0; op2
< 32; op2
++) {
6970 if (is_indirect_opcode(handler
)) {
6971 t3
= ind_table(handler
);
6972 for (op3
= 0; op3
< 32; op3
++) {
6974 if (handler
->count
== 0)
6976 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
6977 "%016" PRIx64
" %" PRId64
"\n",
6978 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
6980 handler
->count
, handler
->count
);
6983 if (handler
->count
== 0)
6985 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
6986 "%016" PRIx64
" %" PRId64
"\n",
6987 op1
, op2
, op1
, op2
, handler
->oname
,
6988 handler
->count
, handler
->count
);
6992 if (handler
->count
== 0)
6994 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
6996 op1
, op1
, handler
->oname
,
6997 handler
->count
, handler
->count
);
7003 /*****************************************************************************/
7004 void gen_intermediate_code(CPUPPCState
*env
, struct TranslationBlock
*tb
)
7006 PowerPCCPU
*cpu
= ppc_env_get_cpu(env
);
7007 CPUState
*cs
= CPU(cpu
);
7008 DisasContext ctx
, *ctxp
= &ctx
;
7009 opc_handler_t
**table
, *handler
;
7010 target_ulong pc_start
;
7017 ctx
.exception
= POWERPC_EXCP_NONE
;
7018 ctx
.spr_cb
= env
->spr_cb
;
7020 ctx
.mem_idx
= env
->dmmu_idx
;
7022 #if !defined(CONFIG_USER_ONLY)
7023 ctx
.hv
= msr_hv
|| !env
->has_hv_mode
;
7025 ctx
.insns_flags
= env
->insns_flags
;
7026 ctx
.insns_flags2
= env
->insns_flags2
;
7027 ctx
.access_type
= -1;
7028 ctx
.need_access_type
= !(env
->mmu_model
& POWERPC_MMU_64B
);
7029 ctx
.le_mode
= !!(env
->hflags
& (1 << MSR_LE
));
7030 ctx
.default_tcg_memop_mask
= ctx
.le_mode
? MO_LE
: MO_BE
;
7031 #if defined(TARGET_PPC64)
7032 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
7033 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
7035 if (env
->mmu_model
== POWERPC_MMU_32B
||
7036 env
->mmu_model
== POWERPC_MMU_601
||
7037 (env
->mmu_model
& POWERPC_MMU_64B
))
7038 ctx
.lazy_tlb_flush
= true;
7040 ctx
.fpu_enabled
= !!msr_fp
;
7041 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
7042 ctx
.spe_enabled
= !!msr_spe
;
7044 ctx
.spe_enabled
= false;
7045 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
7046 ctx
.altivec_enabled
= !!msr_vr
;
7048 ctx
.altivec_enabled
= false;
7049 if ((env
->flags
& POWERPC_FLAG_VSX
) && msr_vsx
) {
7050 ctx
.vsx_enabled
= !!msr_vsx
;
7052 ctx
.vsx_enabled
= false;
7054 #if defined(TARGET_PPC64)
7055 if ((env
->flags
& POWERPC_FLAG_TM
) && msr_tm
) {
7056 ctx
.tm_enabled
= !!msr_tm
;
7058 ctx
.tm_enabled
= false;
7061 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
7062 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
7064 ctx
.singlestep_enabled
= 0;
7065 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
7066 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
7067 if (unlikely(cs
->singlestep_enabled
)) {
7068 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
7070 #if defined (DO_SINGLE_STEP) && 0
7071 /* Single step trace mode */
7075 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7076 if (max_insns
== 0) {
7077 max_insns
= CF_COUNT_MASK
;
7079 if (max_insns
> TCG_MAX_INSNS
) {
7080 max_insns
= TCG_MAX_INSNS
;
7084 tcg_clear_temp_count();
7085 /* Set env in case of segfault during code fetch */
7086 while (ctx
.exception
== POWERPC_EXCP_NONE
&& !tcg_op_buf_full()) {
7087 tcg_gen_insn_start(ctx
.nip
);
7090 if (unlikely(cpu_breakpoint_test(cs
, ctx
.nip
, BP_ANY
))) {
7091 gen_debug_exception(ctxp
);
7092 /* The address covered by the breakpoint must be included in
7093 [tb->pc, tb->pc + tb->size) in order to for it to be
7094 properly cleared -- thus we increment the PC here so that
7095 the logic setting tb->size below does the right thing. */
7100 LOG_DISAS("----------------\n");
7101 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
7102 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
7103 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
))
7105 if (unlikely(need_byteswap(&ctx
))) {
7106 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
7108 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
7110 LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n",
7111 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7112 opc3(ctx
.opcode
), opc4(ctx
.opcode
),
7113 ctx
.le_mode
? "little" : "big");
7115 table
= env
->opcodes
;
7116 handler
= table
[opc1(ctx
.opcode
)];
7117 if (is_indirect_opcode(handler
)) {
7118 table
= ind_table(handler
);
7119 handler
= table
[opc2(ctx
.opcode
)];
7120 if (is_indirect_opcode(handler
)) {
7121 table
= ind_table(handler
);
7122 handler
= table
[opc3(ctx
.opcode
)];
7123 if (is_indirect_opcode(handler
)) {
7124 table
= ind_table(handler
);
7125 handler
= table
[opc4(ctx
.opcode
)];
7129 /* Is opcode *REALLY* valid ? */
7130 if (unlikely(handler
->handler
== &gen_invalid
)) {
7131 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
7132 "%02x - %02x - %02x - %02x (%08x) "
7133 TARGET_FMT_lx
" %d\n",
7134 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7135 opc3(ctx
.opcode
), opc4(ctx
.opcode
),
7136 ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
7140 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
7141 inval
= handler
->inval2
;
7143 inval
= handler
->inval1
;
7146 if (unlikely((ctx
.opcode
& inval
) != 0)) {
7147 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
7148 "%02x - %02x - %02x - %02x (%08x) "
7149 TARGET_FMT_lx
"\n", ctx
.opcode
& inval
,
7150 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7151 opc3(ctx
.opcode
), opc4(ctx
.opcode
),
7152 ctx
.opcode
, ctx
.nip
- 4);
7153 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
7157 (*(handler
->handler
))(&ctx
);
7158 #if defined(DO_PPC_STATISTICS)
7161 /* Check trace mode exceptions */
7162 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
7163 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
7164 ctx
.exception
!= POWERPC_SYSCALL
&&
7165 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
7166 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
7167 gen_exception_nip(ctxp
, POWERPC_EXCP_TRACE
, ctx
.nip
);
7168 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
7169 (cs
->singlestep_enabled
) ||
7171 num_insns
>= max_insns
)) {
7172 /* if we reach a page boundary or are single stepping, stop
7177 if (tcg_check_temp_count()) {
7178 fprintf(stderr
, "Opcode %02x %02x %02x %02x (%08x) leaked "
7179 "temporaries\n", opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7180 opc3(ctx
.opcode
), opc4(ctx
.opcode
), ctx
.opcode
);
7184 if (tb
->cflags
& CF_LAST_IO
)
7186 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
7187 gen_goto_tb(&ctx
, 0, ctx
.nip
);
7188 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
7189 if (unlikely(cs
->singlestep_enabled
)) {
7190 gen_debug_exception(ctxp
);
7192 /* Generate the return instruction */
7195 gen_tb_end(tb
, num_insns
);
7197 tb
->size
= ctx
.nip
- pc_start
;
7198 tb
->icount
= num_insns
;
7200 #if defined(DEBUG_DISAS)
7201 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)
7202 && qemu_log_in_addr_range(pc_start
)) {
7204 flags
= env
->bfd_mach
;
7205 flags
|= ctx
.le_mode
<< 16;
7207 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
7208 log_target_disas(cs
, pc_start
, ctx
.nip
- pc_start
, flags
);
7215 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
,