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/>.
22 #include "disas/disas.h"
24 #include "qemu/host-utils.h"
30 #define CPU_SINGLE_STEP 0x1
31 #define CPU_BRANCH_STEP 0x2
32 #define GDBSTUB_SINGLE_STEP 0x4
34 /* Include definitions for instructions classes and implementations flags */
35 //#define PPC_DEBUG_DISAS
36 //#define DO_PPC_STATISTICS
38 #ifdef PPC_DEBUG_DISAS
39 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
41 # define LOG_DISAS(...) do { } while (0)
43 /*****************************************************************************/
44 /* Code translation helpers */
46 /* global register indexes */
47 static TCGv_ptr cpu_env
;
48 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
49 #if !defined(TARGET_PPC64)
50 + 10*4 + 22*5 /* SPE GPRh */
52 + 10*4 + 22*5 /* FPR */
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
55 static TCGv cpu_gpr
[32];
56 #if !defined(TARGET_PPC64)
57 static TCGv cpu_gprh
[32];
59 static TCGv_i64 cpu_fpr
[32];
60 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
61 static TCGv_i32 cpu_crf
[8];
66 #if defined(TARGET_PPC64)
70 static TCGv cpu_reserve
;
71 static TCGv cpu_fpscr
;
72 static TCGv_i32 cpu_access_type
;
74 #include "exec/gen-icount.h"
76 void ppc_translate_init(void)
80 size_t cpu_reg_names_size
;
81 static int done_init
= 0;
86 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
89 cpu_reg_names_size
= sizeof(cpu_reg_names
);
91 for (i
= 0; i
< 8; i
++) {
92 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
93 cpu_crf
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
94 offsetof(CPUPPCState
, crf
[i
]), p
);
96 cpu_reg_names_size
-= 5;
99 for (i
= 0; i
< 32; i
++) {
100 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
101 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
102 offsetof(CPUPPCState
, gpr
[i
]), p
);
103 p
+= (i
< 10) ? 3 : 4;
104 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
105 #if !defined(TARGET_PPC64)
106 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
107 cpu_gprh
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
108 offsetof(CPUPPCState
, gprh
[i
]), p
);
109 p
+= (i
< 10) ? 4 : 5;
110 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
113 snprintf(p
, cpu_reg_names_size
, "fp%d", i
);
114 cpu_fpr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
115 offsetof(CPUPPCState
, fpr
[i
]), p
);
116 p
+= (i
< 10) ? 4 : 5;
117 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
119 snprintf(p
, cpu_reg_names_size
, "avr%dH", i
);
120 #ifdef HOST_WORDS_BIGENDIAN
121 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
122 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
124 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
125 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
127 p
+= (i
< 10) ? 6 : 7;
128 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
130 snprintf(p
, cpu_reg_names_size
, "avr%dL", i
);
131 #ifdef HOST_WORDS_BIGENDIAN
132 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
133 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
135 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
136 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
138 p
+= (i
< 10) ? 6 : 7;
139 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
142 cpu_nip
= tcg_global_mem_new(TCG_AREG0
,
143 offsetof(CPUPPCState
, nip
), "nip");
145 cpu_msr
= tcg_global_mem_new(TCG_AREG0
,
146 offsetof(CPUPPCState
, msr
), "msr");
148 cpu_ctr
= tcg_global_mem_new(TCG_AREG0
,
149 offsetof(CPUPPCState
, ctr
), "ctr");
151 cpu_lr
= tcg_global_mem_new(TCG_AREG0
,
152 offsetof(CPUPPCState
, lr
), "lr");
154 #if defined(TARGET_PPC64)
155 cpu_cfar
= tcg_global_mem_new(TCG_AREG0
,
156 offsetof(CPUPPCState
, cfar
), "cfar");
159 cpu_xer
= tcg_global_mem_new(TCG_AREG0
,
160 offsetof(CPUPPCState
, xer
), "xer");
162 cpu_reserve
= tcg_global_mem_new(TCG_AREG0
,
163 offsetof(CPUPPCState
, reserve_addr
),
166 cpu_fpscr
= tcg_global_mem_new(TCG_AREG0
,
167 offsetof(CPUPPCState
, fpscr
), "fpscr");
169 cpu_access_type
= tcg_global_mem_new_i32(TCG_AREG0
,
170 offsetof(CPUPPCState
, access_type
), "access_type");
172 /* register helpers */
179 /* internal defines */
180 typedef struct DisasContext
{
181 struct TranslationBlock
*tb
;
185 /* Routine used to access memory */
188 /* Translation flags */
190 #if defined(TARGET_PPC64)
197 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
198 int singlestep_enabled
;
201 struct opc_handler_t
{
202 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
204 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
206 /* instruction type */
208 /* extended instruction type */
211 void (*handler
)(DisasContext
*ctx
);
212 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
215 #if defined(DO_PPC_STATISTICS)
220 static inline void gen_reset_fpstatus(void)
222 gen_helper_reset_fpstatus(cpu_env
);
225 static inline void gen_compute_fprf(TCGv_i64 arg
, int set_fprf
, int set_rc
)
227 TCGv_i32 t0
= tcg_temp_new_i32();
230 /* This case might be optimized later */
231 tcg_gen_movi_i32(t0
, 1);
232 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
233 if (unlikely(set_rc
)) {
234 tcg_gen_mov_i32(cpu_crf
[1], t0
);
236 gen_helper_float_check_status(cpu_env
);
237 } else if (unlikely(set_rc
)) {
238 /* We always need to compute fpcc */
239 tcg_gen_movi_i32(t0
, 0);
240 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
241 tcg_gen_mov_i32(cpu_crf
[1], t0
);
244 tcg_temp_free_i32(t0
);
247 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
249 if (ctx
->access_type
!= access_type
) {
250 tcg_gen_movi_i32(cpu_access_type
, access_type
);
251 ctx
->access_type
= access_type
;
255 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
257 #if defined(TARGET_PPC64)
259 tcg_gen_movi_tl(cpu_nip
, nip
);
262 tcg_gen_movi_tl(cpu_nip
, (uint32_t)nip
);
265 static inline void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
268 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
269 gen_update_nip(ctx
, ctx
->nip
);
271 t0
= tcg_const_i32(excp
);
272 t1
= tcg_const_i32(error
);
273 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
274 tcg_temp_free_i32(t0
);
275 tcg_temp_free_i32(t1
);
276 ctx
->exception
= (excp
);
279 static inline void gen_exception(DisasContext
*ctx
, uint32_t excp
)
282 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
283 gen_update_nip(ctx
, ctx
->nip
);
285 t0
= tcg_const_i32(excp
);
286 gen_helper_raise_exception(cpu_env
, t0
);
287 tcg_temp_free_i32(t0
);
288 ctx
->exception
= (excp
);
291 static inline void gen_debug_exception(DisasContext
*ctx
)
295 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
296 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
297 gen_update_nip(ctx
, ctx
->nip
);
299 t0
= tcg_const_i32(EXCP_DEBUG
);
300 gen_helper_raise_exception(cpu_env
, t0
);
301 tcg_temp_free_i32(t0
);
304 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
306 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
309 /* Stop translation */
310 static inline void gen_stop_exception(DisasContext
*ctx
)
312 gen_update_nip(ctx
, ctx
->nip
);
313 ctx
->exception
= POWERPC_EXCP_STOP
;
316 /* No need to update nip here, as execution flow will change */
317 static inline void gen_sync_exception(DisasContext
*ctx
)
319 ctx
->exception
= POWERPC_EXCP_SYNC
;
322 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
323 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
325 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
326 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
328 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
329 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
331 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
332 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
334 typedef struct opcode_t
{
335 unsigned char opc1
, opc2
, opc3
;
336 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
337 unsigned char pad
[5];
339 unsigned char pad
[1];
341 opc_handler_t handler
;
345 /*****************************************************************************/
346 /*** Instruction decoding ***/
347 #define EXTRACT_HELPER(name, shift, nb) \
348 static inline uint32_t name(uint32_t opcode) \
350 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
353 #define EXTRACT_SHELPER(name, shift, nb) \
354 static inline int32_t name(uint32_t opcode) \
356 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
360 EXTRACT_HELPER(opc1
, 26, 6);
362 EXTRACT_HELPER(opc2
, 1, 5);
364 EXTRACT_HELPER(opc3
, 6, 5);
365 /* Update Cr0 flags */
366 EXTRACT_HELPER(Rc
, 0, 1);
368 EXTRACT_HELPER(rD
, 21, 5);
370 EXTRACT_HELPER(rS
, 21, 5);
372 EXTRACT_HELPER(rA
, 16, 5);
374 EXTRACT_HELPER(rB
, 11, 5);
376 EXTRACT_HELPER(rC
, 6, 5);
378 EXTRACT_HELPER(crfD
, 23, 3);
379 EXTRACT_HELPER(crfS
, 18, 3);
380 EXTRACT_HELPER(crbD
, 21, 5);
381 EXTRACT_HELPER(crbA
, 16, 5);
382 EXTRACT_HELPER(crbB
, 11, 5);
384 EXTRACT_HELPER(_SPR
, 11, 10);
385 static inline uint32_t SPR(uint32_t opcode
)
387 uint32_t sprn
= _SPR(opcode
);
389 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
391 /*** Get constants ***/
392 EXTRACT_HELPER(IMM
, 12, 8);
393 /* 16 bits signed immediate value */
394 EXTRACT_SHELPER(SIMM
, 0, 16);
395 /* 16 bits unsigned immediate value */
396 EXTRACT_HELPER(UIMM
, 0, 16);
397 /* 5 bits signed immediate value */
398 EXTRACT_HELPER(SIMM5
, 16, 5);
399 /* 5 bits signed immediate value */
400 EXTRACT_HELPER(UIMM5
, 16, 5);
402 EXTRACT_HELPER(NB
, 11, 5);
404 EXTRACT_HELPER(SH
, 11, 5);
405 /* Vector shift count */
406 EXTRACT_HELPER(VSH
, 6, 4);
408 EXTRACT_HELPER(MB
, 6, 5);
410 EXTRACT_HELPER(ME
, 1, 5);
412 EXTRACT_HELPER(TO
, 21, 5);
414 EXTRACT_HELPER(CRM
, 12, 8);
415 EXTRACT_HELPER(FM
, 17, 8);
416 EXTRACT_HELPER(SR
, 16, 4);
417 EXTRACT_HELPER(FPIMM
, 12, 4);
419 /*** Jump target decoding ***/
421 EXTRACT_SHELPER(d
, 0, 16);
422 /* Immediate address */
423 static inline target_ulong
LI(uint32_t opcode
)
425 return (opcode
>> 0) & 0x03FFFFFC;
428 static inline uint32_t BD(uint32_t opcode
)
430 return (opcode
>> 0) & 0xFFFC;
433 EXTRACT_HELPER(BO
, 21, 5);
434 EXTRACT_HELPER(BI
, 16, 5);
435 /* Absolute/relative address */
436 EXTRACT_HELPER(AA
, 1, 1);
438 EXTRACT_HELPER(LK
, 0, 1);
440 /* Create a mask between <start> and <end> bits */
441 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
445 #if defined(TARGET_PPC64)
446 if (likely(start
== 0)) {
447 ret
= UINT64_MAX
<< (63 - end
);
448 } else if (likely(end
== 63)) {
449 ret
= UINT64_MAX
>> start
;
452 if (likely(start
== 0)) {
453 ret
= UINT32_MAX
<< (31 - end
);
454 } else if (likely(end
== 31)) {
455 ret
= UINT32_MAX
>> start
;
459 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
460 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
461 if (unlikely(start
> end
))
468 /*****************************************************************************/
469 /* PowerPC instructions table */
471 #if defined(DO_PPC_STATISTICS)
472 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
482 .handler = &gen_##name, \
483 .oname = stringify(name), \
485 .oname = stringify(name), \
487 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
498 .handler = &gen_##name, \
499 .oname = stringify(name), \
501 .oname = stringify(name), \
503 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
513 .handler = &gen_##name, \
519 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
529 .handler = &gen_##name, \
531 .oname = stringify(name), \
533 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
544 .handler = &gen_##name, \
546 .oname = stringify(name), \
548 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
558 .handler = &gen_##name, \
564 /* SPR load/store helpers */
565 static inline void gen_load_spr(TCGv t
, int reg
)
567 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
570 static inline void gen_store_spr(int reg
, TCGv t
)
572 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
575 /* Invalid instruction */
576 static void gen_invalid(DisasContext
*ctx
)
578 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
581 static opc_handler_t invalid_handler
= {
582 .inval1
= 0xFFFFFFFF,
583 .inval2
= 0xFFFFFFFF,
586 .handler
= gen_invalid
,
589 /*** Integer comparison ***/
591 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
595 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_xer
);
596 tcg_gen_shri_i32(cpu_crf
[crf
], cpu_crf
[crf
], XER_SO
);
597 tcg_gen_andi_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1);
599 l1
= gen_new_label();
600 l2
= gen_new_label();
601 l3
= gen_new_label();
603 tcg_gen_brcond_tl(TCG_COND_LT
, arg0
, arg1
, l1
);
604 tcg_gen_brcond_tl(TCG_COND_GT
, arg0
, arg1
, l2
);
606 tcg_gen_brcond_tl(TCG_COND_LTU
, arg0
, arg1
, l1
);
607 tcg_gen_brcond_tl(TCG_COND_GTU
, arg0
, arg1
, l2
);
609 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_EQ
);
612 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_LT
);
615 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_GT
);
619 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
621 TCGv t0
= tcg_const_local_tl(arg1
);
622 gen_op_cmp(arg0
, t0
, s
, crf
);
626 #if defined(TARGET_PPC64)
627 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
630 t0
= tcg_temp_local_new();
631 t1
= tcg_temp_local_new();
633 tcg_gen_ext32s_tl(t0
, arg0
);
634 tcg_gen_ext32s_tl(t1
, arg1
);
636 tcg_gen_ext32u_tl(t0
, arg0
);
637 tcg_gen_ext32u_tl(t1
, arg1
);
639 gen_op_cmp(t0
, t1
, s
, crf
);
644 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
646 TCGv t0
= tcg_const_local_tl(arg1
);
647 gen_op_cmp32(arg0
, t0
, s
, crf
);
652 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
654 #if defined(TARGET_PPC64)
656 gen_op_cmpi32(reg
, 0, 1, 0);
659 gen_op_cmpi(reg
, 0, 1, 0);
663 static void gen_cmp(DisasContext
*ctx
)
665 #if defined(TARGET_PPC64)
666 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
667 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
668 1, crfD(ctx
->opcode
));
671 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
672 1, crfD(ctx
->opcode
));
676 static void gen_cmpi(DisasContext
*ctx
)
678 #if defined(TARGET_PPC64)
679 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
680 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
681 1, crfD(ctx
->opcode
));
684 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
685 1, crfD(ctx
->opcode
));
689 static void gen_cmpl(DisasContext
*ctx
)
691 #if defined(TARGET_PPC64)
692 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
693 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
694 0, crfD(ctx
->opcode
));
697 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
698 0, crfD(ctx
->opcode
));
702 static void gen_cmpli(DisasContext
*ctx
)
704 #if defined(TARGET_PPC64)
705 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
706 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
707 0, crfD(ctx
->opcode
));
710 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
711 0, crfD(ctx
->opcode
));
714 /* isel (PowerPC 2.03 specification) */
715 static void gen_isel(DisasContext
*ctx
)
718 uint32_t bi
= rC(ctx
->opcode
);
722 l1
= gen_new_label();
723 l2
= gen_new_label();
725 mask
= 1 << (3 - (bi
& 0x03));
726 t0
= tcg_temp_new_i32();
727 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
728 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
729 if (rA(ctx
->opcode
) == 0)
730 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
732 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
735 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
737 tcg_temp_free_i32(t0
);
740 /*** Integer arithmetic ***/
742 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
743 TCGv arg1
, TCGv arg2
, int sub
)
748 l1
= gen_new_label();
749 /* Start with XER OV disabled, the most likely case */
750 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
751 t0
= tcg_temp_local_new();
752 tcg_gen_xor_tl(t0
, arg0
, arg1
);
753 #if defined(TARGET_PPC64)
755 tcg_gen_ext32s_tl(t0
, t0
);
758 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
760 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
761 tcg_gen_xor_tl(t0
, arg1
, arg2
);
762 #if defined(TARGET_PPC64)
764 tcg_gen_ext32s_tl(t0
, t0
);
767 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
769 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
770 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
775 static inline void gen_op_arith_compute_ca(DisasContext
*ctx
, TCGv arg1
,
778 int l1
= gen_new_label();
780 #if defined(TARGET_PPC64)
781 if (!(ctx
->sf_mode
)) {
786 tcg_gen_ext32u_tl(t0
, arg1
);
787 tcg_gen_ext32u_tl(t1
, arg2
);
789 tcg_gen_brcond_tl(TCG_COND_GTU
, t0
, t1
, l1
);
791 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
793 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
801 tcg_gen_brcond_tl(TCG_COND_GTU
, arg1
, arg2
, l1
);
803 tcg_gen_brcond_tl(TCG_COND_GEU
, arg1
, arg2
, l1
);
805 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
810 /* Common add function */
811 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
812 TCGv arg2
, int add_ca
, int compute_ca
,
817 if ((!compute_ca
&& !compute_ov
) ||
818 (!TCGV_EQUAL(ret
,arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
821 t0
= tcg_temp_local_new();
825 t1
= tcg_temp_local_new();
826 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
827 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
832 if (compute_ca
&& compute_ov
) {
833 /* Start with XER CA and OV disabled, the most likely case */
834 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
835 } else if (compute_ca
) {
836 /* Start with XER CA disabled, the most likely case */
837 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
838 } else if (compute_ov
) {
839 /* Start with XER OV disabled, the most likely case */
840 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
843 tcg_gen_add_tl(t0
, arg1
, arg2
);
846 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
849 tcg_gen_add_tl(t0
, t0
, t1
);
850 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
854 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
857 if (unlikely(Rc(ctx
->opcode
) != 0))
858 gen_set_Rc0(ctx
, t0
);
860 if (!TCGV_EQUAL(t0
, ret
)) {
861 tcg_gen_mov_tl(ret
, t0
);
865 /* Add functions with two operands */
866 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
867 static void glue(gen_, name)(DisasContext *ctx) \
869 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
870 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
871 add_ca, compute_ca, compute_ov); \
873 /* Add functions with one operand and one immediate */
874 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
875 add_ca, compute_ca, compute_ov) \
876 static void glue(gen_, name)(DisasContext *ctx) \
878 TCGv t0 = tcg_const_local_tl(const_val); \
879 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
880 cpu_gpr[rA(ctx->opcode)], t0, \
881 add_ca, compute_ca, compute_ov); \
885 /* add add. addo addo. */
886 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
887 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
888 /* addc addc. addco addco. */
889 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
890 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
891 /* adde adde. addeo addeo. */
892 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
893 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
894 /* addme addme. addmeo addmeo. */
895 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
896 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
897 /* addze addze. addzeo addzeo.*/
898 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
899 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
901 static void gen_addi(DisasContext
*ctx
)
903 target_long simm
= SIMM(ctx
->opcode
);
905 if (rA(ctx
->opcode
) == 0) {
907 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
909 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
);
913 static inline void gen_op_addic(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
916 target_long simm
= SIMM(ctx
->opcode
);
918 /* Start with XER CA and OV disabled, the most likely case */
919 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
921 if (likely(simm
!= 0)) {
922 TCGv t0
= tcg_temp_local_new();
923 tcg_gen_addi_tl(t0
, arg1
, simm
);
924 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
925 tcg_gen_mov_tl(ret
, t0
);
928 tcg_gen_mov_tl(ret
, arg1
);
931 gen_set_Rc0(ctx
, ret
);
935 static void gen_addic(DisasContext
*ctx
)
937 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
940 static void gen_addic_(DisasContext
*ctx
)
942 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
946 static void gen_addis(DisasContext
*ctx
)
948 target_long simm
= SIMM(ctx
->opcode
);
950 if (rA(ctx
->opcode
) == 0) {
952 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
954 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
958 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
959 TCGv arg2
, int sign
, int compute_ov
)
961 int l1
= gen_new_label();
962 int l2
= gen_new_label();
963 TCGv_i32 t0
= tcg_temp_local_new_i32();
964 TCGv_i32 t1
= tcg_temp_local_new_i32();
966 tcg_gen_trunc_tl_i32(t0
, arg1
);
967 tcg_gen_trunc_tl_i32(t1
, arg2
);
968 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
970 int l3
= gen_new_label();
971 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
972 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
974 tcg_gen_div_i32(t0
, t0
, t1
);
976 tcg_gen_divu_i32(t0
, t0
, t1
);
979 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
984 tcg_gen_sari_i32(t0
, t0
, 31);
986 tcg_gen_movi_i32(t0
, 0);
989 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
992 tcg_gen_extu_i32_tl(ret
, t0
);
993 tcg_temp_free_i32(t0
);
994 tcg_temp_free_i32(t1
);
995 if (unlikely(Rc(ctx
->opcode
) != 0))
996 gen_set_Rc0(ctx
, ret
);
999 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1000 static void glue(gen_, name)(DisasContext *ctx) \
1002 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1003 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1004 sign, compute_ov); \
1006 /* divwu divwu. divwuo divwuo. */
1007 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1008 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1009 /* divw divw. divwo divwo. */
1010 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1011 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1012 #if defined(TARGET_PPC64)
1013 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1014 TCGv arg2
, int sign
, int compute_ov
)
1016 int l1
= gen_new_label();
1017 int l2
= gen_new_label();
1019 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1021 int l3
= gen_new_label();
1022 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1023 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1025 tcg_gen_div_i64(ret
, arg1
, arg2
);
1027 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1030 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1035 tcg_gen_sari_i64(ret
, arg1
, 63);
1037 tcg_gen_movi_i64(ret
, 0);
1040 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1043 if (unlikely(Rc(ctx
->opcode
) != 0))
1044 gen_set_Rc0(ctx
, ret
);
1046 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1047 static void glue(gen_, name)(DisasContext *ctx) \
1049 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1050 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1051 sign, compute_ov); \
1053 /* divwu divwu. divwuo divwuo. */
1054 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1055 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1056 /* divw divw. divwo divwo. */
1057 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1058 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1062 static void gen_mulhw(DisasContext
*ctx
)
1064 TCGv_i32 t0
= tcg_temp_new_i32();
1065 TCGv_i32 t1
= tcg_temp_new_i32();
1067 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1068 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1069 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1070 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1071 tcg_temp_free_i32(t0
);
1072 tcg_temp_free_i32(t1
);
1073 if (unlikely(Rc(ctx
->opcode
) != 0))
1074 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1077 /* mulhwu mulhwu. */
1078 static void gen_mulhwu(DisasContext
*ctx
)
1080 TCGv_i32 t0
= tcg_temp_new_i32();
1081 TCGv_i32 t1
= tcg_temp_new_i32();
1083 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1084 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1085 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1086 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1087 tcg_temp_free_i32(t0
);
1088 tcg_temp_free_i32(t1
);
1089 if (unlikely(Rc(ctx
->opcode
) != 0))
1090 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1094 static void gen_mullw(DisasContext
*ctx
)
1096 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1097 cpu_gpr
[rB(ctx
->opcode
)]);
1098 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1099 if (unlikely(Rc(ctx
->opcode
) != 0))
1100 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1103 /* mullwo mullwo. */
1104 static void gen_mullwo(DisasContext
*ctx
)
1109 t0
= tcg_temp_new_i64();
1110 t1
= tcg_temp_new_i64();
1111 l1
= gen_new_label();
1112 /* Start with XER OV disabled, the most likely case */
1113 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1114 #if defined(TARGET_PPC64)
1115 tcg_gen_ext32s_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1116 tcg_gen_ext32s_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1118 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1119 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1121 tcg_gen_mul_i64(t0
, t0
, t1
);
1122 #if defined(TARGET_PPC64)
1123 tcg_gen_ext32s_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1124 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, cpu_gpr
[rD(ctx
->opcode
)], l1
);
1126 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1127 tcg_gen_ext32s_i64(t1
, t0
);
1128 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
1130 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1132 tcg_temp_free_i64(t0
);
1133 tcg_temp_free_i64(t1
);
1134 if (unlikely(Rc(ctx
->opcode
) != 0))
1135 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1139 static void gen_mulli(DisasContext
*ctx
)
1141 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1145 #if defined(TARGET_PPC64)
1147 static void gen_mulhd(DisasContext
*ctx
)
1149 TCGv lo
= tcg_temp_new();
1150 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1151 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1153 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1154 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1158 /* mulhdu mulhdu. */
1159 static void gen_mulhdu(DisasContext
*ctx
)
1161 TCGv lo
= tcg_temp_new();
1162 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1163 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1165 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1166 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1171 static void gen_mulld(DisasContext
*ctx
)
1173 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1174 cpu_gpr
[rB(ctx
->opcode
)]);
1175 if (unlikely(Rc(ctx
->opcode
) != 0))
1176 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1179 /* mulldo mulldo. */
1180 static void gen_mulldo(DisasContext
*ctx
)
1182 gen_helper_mulldo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
1183 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1184 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1185 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1190 /* neg neg. nego nego. */
1191 static inline void gen_op_arith_neg(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1194 int l1
= gen_new_label();
1195 int l2
= gen_new_label();
1196 TCGv t0
= tcg_temp_local_new();
1197 #if defined(TARGET_PPC64)
1199 tcg_gen_mov_tl(t0
, arg1
);
1200 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT64_MIN
, l1
);
1204 tcg_gen_ext32s_tl(t0
, arg1
);
1205 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1207 tcg_gen_neg_tl(ret
, arg1
);
1209 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1213 tcg_gen_mov_tl(ret
, t0
);
1215 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1219 if (unlikely(Rc(ctx
->opcode
) != 0))
1220 gen_set_Rc0(ctx
, ret
);
1223 static void gen_neg(DisasContext
*ctx
)
1225 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1228 static void gen_nego(DisasContext
*ctx
)
1230 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1233 /* Common subf function */
1234 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1235 TCGv arg2
, int add_ca
, int compute_ca
,
1240 if ((!compute_ca
&& !compute_ov
) ||
1241 (!TCGV_EQUAL(ret
, arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
1244 t0
= tcg_temp_local_new();
1248 t1
= tcg_temp_local_new();
1249 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
1250 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
1255 if (compute_ca
&& compute_ov
) {
1256 /* Start with XER CA and OV disabled, the most likely case */
1257 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
1258 } else if (compute_ca
) {
1259 /* Start with XER CA disabled, the most likely case */
1260 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1261 } else if (compute_ov
) {
1262 /* Start with XER OV disabled, the most likely case */
1263 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1267 tcg_gen_not_tl(t0
, arg1
);
1268 tcg_gen_add_tl(t0
, t0
, arg2
);
1269 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 0);
1270 tcg_gen_add_tl(t0
, t0
, t1
);
1271 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
1274 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1276 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 1);
1280 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1283 if (unlikely(Rc(ctx
->opcode
) != 0))
1284 gen_set_Rc0(ctx
, t0
);
1286 if (!TCGV_EQUAL(t0
, ret
)) {
1287 tcg_gen_mov_tl(ret
, t0
);
1291 /* Sub functions with Two operands functions */
1292 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1293 static void glue(gen_, name)(DisasContext *ctx) \
1295 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1296 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1297 add_ca, compute_ca, compute_ov); \
1299 /* Sub functions with one operand and one immediate */
1300 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1301 add_ca, compute_ca, compute_ov) \
1302 static void glue(gen_, name)(DisasContext *ctx) \
1304 TCGv t0 = tcg_const_local_tl(const_val); \
1305 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1306 cpu_gpr[rA(ctx->opcode)], t0, \
1307 add_ca, compute_ca, compute_ov); \
1308 tcg_temp_free(t0); \
1310 /* subf subf. subfo subfo. */
1311 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1312 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1313 /* subfc subfc. subfco subfco. */
1314 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1315 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1316 /* subfe subfe. subfeo subfo. */
1317 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1318 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1319 /* subfme subfme. subfmeo subfmeo. */
1320 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1321 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1322 /* subfze subfze. subfzeo subfzeo.*/
1323 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1324 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1327 static void gen_subfic(DisasContext
*ctx
)
1329 /* Start with XER CA and OV disabled, the most likely case */
1330 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1331 TCGv t0
= tcg_temp_local_new();
1332 TCGv t1
= tcg_const_local_tl(SIMM(ctx
->opcode
));
1333 tcg_gen_sub_tl(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)]);
1334 gen_op_arith_compute_ca(ctx
, t0
, t1
, 1);
1336 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1340 /*** Integer logical ***/
1341 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1342 static void glue(gen_, name)(DisasContext *ctx) \
1344 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1345 cpu_gpr[rB(ctx->opcode)]); \
1346 if (unlikely(Rc(ctx->opcode) != 0)) \
1347 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1350 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1351 static void glue(gen_, name)(DisasContext *ctx) \
1353 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1354 if (unlikely(Rc(ctx->opcode) != 0)) \
1355 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1359 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1361 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1364 static void gen_andi_(DisasContext
*ctx
)
1366 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1367 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1371 static void gen_andis_(DisasContext
*ctx
)
1373 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1374 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1378 static void gen_cntlzw(DisasContext
*ctx
)
1380 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1381 if (unlikely(Rc(ctx
->opcode
) != 0))
1382 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1385 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1386 /* extsb & extsb. */
1387 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1388 /* extsh & extsh. */
1389 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1391 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1393 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1396 static void gen_or(DisasContext
*ctx
)
1400 rs
= rS(ctx
->opcode
);
1401 ra
= rA(ctx
->opcode
);
1402 rb
= rB(ctx
->opcode
);
1403 /* Optimisation for mr. ri case */
1404 if (rs
!= ra
|| rs
!= rb
) {
1406 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1408 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1409 if (unlikely(Rc(ctx
->opcode
) != 0))
1410 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1411 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1412 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1413 #if defined(TARGET_PPC64)
1419 /* Set process priority to low */
1423 /* Set process priority to medium-low */
1427 /* Set process priority to normal */
1430 #if !defined(CONFIG_USER_ONLY)
1432 if (ctx
->mem_idx
> 0) {
1433 /* Set process priority to very low */
1438 if (ctx
->mem_idx
> 0) {
1439 /* Set process priority to medium-hight */
1444 if (ctx
->mem_idx
> 0) {
1445 /* Set process priority to high */
1450 if (ctx
->mem_idx
> 1) {
1451 /* Set process priority to very high */
1461 TCGv t0
= tcg_temp_new();
1462 gen_load_spr(t0
, SPR_PPR
);
1463 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1464 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1465 gen_store_spr(SPR_PPR
, t0
);
1472 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1475 static void gen_xor(DisasContext
*ctx
)
1477 /* Optimisation for "set to zero" case */
1478 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1479 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1481 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1482 if (unlikely(Rc(ctx
->opcode
) != 0))
1483 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1487 static void gen_ori(DisasContext
*ctx
)
1489 target_ulong uimm
= UIMM(ctx
->opcode
);
1491 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1493 /* XXX: should handle special NOPs for POWER series */
1496 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1500 static void gen_oris(DisasContext
*ctx
)
1502 target_ulong uimm
= UIMM(ctx
->opcode
);
1504 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1508 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1512 static void gen_xori(DisasContext
*ctx
)
1514 target_ulong uimm
= UIMM(ctx
->opcode
);
1516 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1520 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1524 static void gen_xoris(DisasContext
*ctx
)
1526 target_ulong uimm
= UIMM(ctx
->opcode
);
1528 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1532 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1535 /* popcntb : PowerPC 2.03 specification */
1536 static void gen_popcntb(DisasContext
*ctx
)
1538 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1541 static void gen_popcntw(DisasContext
*ctx
)
1543 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1546 #if defined(TARGET_PPC64)
1547 /* popcntd: PowerPC 2.06 specification */
1548 static void gen_popcntd(DisasContext
*ctx
)
1550 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1554 #if defined(TARGET_PPC64)
1555 /* extsw & extsw. */
1556 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1559 static void gen_cntlzd(DisasContext
*ctx
)
1561 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1562 if (unlikely(Rc(ctx
->opcode
) != 0))
1563 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1567 /*** Integer rotate ***/
1569 /* rlwimi & rlwimi. */
1570 static void gen_rlwimi(DisasContext
*ctx
)
1572 uint32_t mb
, me
, sh
;
1574 mb
= MB(ctx
->opcode
);
1575 me
= ME(ctx
->opcode
);
1576 sh
= SH(ctx
->opcode
);
1577 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1578 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1582 TCGv t0
= tcg_temp_new();
1583 #if defined(TARGET_PPC64)
1584 TCGv_i32 t2
= tcg_temp_new_i32();
1585 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1586 tcg_gen_rotli_i32(t2
, t2
, sh
);
1587 tcg_gen_extu_i32_i64(t0
, t2
);
1588 tcg_temp_free_i32(t2
);
1590 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1592 #if defined(TARGET_PPC64)
1596 mask
= MASK(mb
, me
);
1597 t1
= tcg_temp_new();
1598 tcg_gen_andi_tl(t0
, t0
, mask
);
1599 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1600 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1604 if (unlikely(Rc(ctx
->opcode
) != 0))
1605 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1608 /* rlwinm & rlwinm. */
1609 static void gen_rlwinm(DisasContext
*ctx
)
1611 uint32_t mb
, me
, sh
;
1613 sh
= SH(ctx
->opcode
);
1614 mb
= MB(ctx
->opcode
);
1615 me
= ME(ctx
->opcode
);
1617 if (likely(mb
== 0 && me
== (31 - sh
))) {
1618 if (likely(sh
== 0)) {
1619 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1621 TCGv t0
= tcg_temp_new();
1622 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1623 tcg_gen_shli_tl(t0
, t0
, sh
);
1624 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1627 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1628 TCGv t0
= tcg_temp_new();
1629 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1630 tcg_gen_shri_tl(t0
, t0
, mb
);
1631 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1634 TCGv t0
= tcg_temp_new();
1635 #if defined(TARGET_PPC64)
1636 TCGv_i32 t1
= tcg_temp_new_i32();
1637 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1638 tcg_gen_rotli_i32(t1
, t1
, sh
);
1639 tcg_gen_extu_i32_i64(t0
, t1
);
1640 tcg_temp_free_i32(t1
);
1642 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1644 #if defined(TARGET_PPC64)
1648 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1651 if (unlikely(Rc(ctx
->opcode
) != 0))
1652 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1655 /* rlwnm & rlwnm. */
1656 static void gen_rlwnm(DisasContext
*ctx
)
1660 #if defined(TARGET_PPC64)
1664 mb
= MB(ctx
->opcode
);
1665 me
= ME(ctx
->opcode
);
1666 t0
= tcg_temp_new();
1667 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1668 #if defined(TARGET_PPC64)
1669 t1
= tcg_temp_new_i32();
1670 t2
= tcg_temp_new_i32();
1671 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1672 tcg_gen_trunc_i64_i32(t2
, t0
);
1673 tcg_gen_rotl_i32(t1
, t1
, t2
);
1674 tcg_gen_extu_i32_i64(t0
, t1
);
1675 tcg_temp_free_i32(t1
);
1676 tcg_temp_free_i32(t2
);
1678 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1680 if (unlikely(mb
!= 0 || me
!= 31)) {
1681 #if defined(TARGET_PPC64)
1685 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1687 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1690 if (unlikely(Rc(ctx
->opcode
) != 0))
1691 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1694 #if defined(TARGET_PPC64)
1695 #define GEN_PPC64_R2(name, opc1, opc2) \
1696 static void glue(gen_, name##0)(DisasContext *ctx) \
1698 gen_##name(ctx, 0); \
1701 static void glue(gen_, name##1)(DisasContext *ctx) \
1703 gen_##name(ctx, 1); \
1705 #define GEN_PPC64_R4(name, opc1, opc2) \
1706 static void glue(gen_, name##0)(DisasContext *ctx) \
1708 gen_##name(ctx, 0, 0); \
1711 static void glue(gen_, name##1)(DisasContext *ctx) \
1713 gen_##name(ctx, 0, 1); \
1716 static void glue(gen_, name##2)(DisasContext *ctx) \
1718 gen_##name(ctx, 1, 0); \
1721 static void glue(gen_, name##3)(DisasContext *ctx) \
1723 gen_##name(ctx, 1, 1); \
1726 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1729 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1730 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1731 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1732 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1734 TCGv t0
= tcg_temp_new();
1735 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1736 if (likely(mb
== 0 && me
== 63)) {
1737 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1739 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1743 if (unlikely(Rc(ctx
->opcode
) != 0))
1744 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1746 /* rldicl - rldicl. */
1747 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1751 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1752 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1753 gen_rldinm(ctx
, mb
, 63, sh
);
1755 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1756 /* rldicr - rldicr. */
1757 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1761 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1762 me
= MB(ctx
->opcode
) | (men
<< 5);
1763 gen_rldinm(ctx
, 0, me
, sh
);
1765 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1766 /* rldic - rldic. */
1767 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1771 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1772 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1773 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1775 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1777 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1781 mb
= MB(ctx
->opcode
);
1782 me
= ME(ctx
->opcode
);
1783 t0
= tcg_temp_new();
1784 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1785 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1786 if (unlikely(mb
!= 0 || me
!= 63)) {
1787 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1789 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1792 if (unlikely(Rc(ctx
->opcode
) != 0))
1793 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1796 /* rldcl - rldcl. */
1797 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1801 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1802 gen_rldnm(ctx
, mb
, 63);
1804 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1805 /* rldcr - rldcr. */
1806 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1810 me
= MB(ctx
->opcode
) | (men
<< 5);
1811 gen_rldnm(ctx
, 0, me
);
1813 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1814 /* rldimi - rldimi. */
1815 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1817 uint32_t sh
, mb
, me
;
1819 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1820 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1822 if (unlikely(sh
== 0 && mb
== 0)) {
1823 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1828 t0
= tcg_temp_new();
1829 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1830 t1
= tcg_temp_new();
1831 mask
= MASK(mb
, me
);
1832 tcg_gen_andi_tl(t0
, t0
, mask
);
1833 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1834 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1838 if (unlikely(Rc(ctx
->opcode
) != 0))
1839 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1841 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1844 /*** Integer shift ***/
1847 static void gen_slw(DisasContext
*ctx
)
1851 t0
= tcg_temp_new();
1852 /* AND rS with a mask that is 0 when rB >= 0x20 */
1853 #if defined(TARGET_PPC64)
1854 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1855 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1857 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1858 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1860 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1861 t1
= tcg_temp_new();
1862 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1863 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1866 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1867 if (unlikely(Rc(ctx
->opcode
) != 0))
1868 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1872 static void gen_sraw(DisasContext
*ctx
)
1874 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1875 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1876 if (unlikely(Rc(ctx
->opcode
) != 0))
1877 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1880 /* srawi & srawi. */
1881 static void gen_srawi(DisasContext
*ctx
)
1883 int sh
= SH(ctx
->opcode
);
1887 l1
= gen_new_label();
1888 l2
= gen_new_label();
1889 t0
= tcg_temp_local_new();
1890 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1891 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
1892 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1893 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1894 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1897 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1899 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1900 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, sh
);
1903 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1904 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1906 if (unlikely(Rc(ctx
->opcode
) != 0))
1907 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1911 static void gen_srw(DisasContext
*ctx
)
1915 t0
= tcg_temp_new();
1916 /* AND rS with a mask that is 0 when rB >= 0x20 */
1917 #if defined(TARGET_PPC64)
1918 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1919 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1921 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1922 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1924 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1925 tcg_gen_ext32u_tl(t0
, t0
);
1926 t1
= tcg_temp_new();
1927 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1928 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1931 if (unlikely(Rc(ctx
->opcode
) != 0))
1932 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1935 #if defined(TARGET_PPC64)
1937 static void gen_sld(DisasContext
*ctx
)
1941 t0
= tcg_temp_new();
1942 /* AND rS with a mask that is 0 when rB >= 0x40 */
1943 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1944 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1945 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1946 t1
= tcg_temp_new();
1947 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1948 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1951 if (unlikely(Rc(ctx
->opcode
) != 0))
1952 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1956 static void gen_srad(DisasContext
*ctx
)
1958 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1959 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1960 if (unlikely(Rc(ctx
->opcode
) != 0))
1961 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1963 /* sradi & sradi. */
1964 static inline void gen_sradi(DisasContext
*ctx
, int n
)
1966 int sh
= SH(ctx
->opcode
) + (n
<< 5);
1970 l1
= gen_new_label();
1971 l2
= gen_new_label();
1972 t0
= tcg_temp_local_new();
1973 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
1974 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1975 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1976 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1979 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1982 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1984 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1985 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1987 if (unlikely(Rc(ctx
->opcode
) != 0))
1988 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1991 static void gen_sradi0(DisasContext
*ctx
)
1996 static void gen_sradi1(DisasContext
*ctx
)
2002 static void gen_srd(DisasContext
*ctx
)
2006 t0
= tcg_temp_new();
2007 /* AND rS with a mask that is 0 when rB >= 0x40 */
2008 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2009 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2010 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2011 t1
= tcg_temp_new();
2012 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2013 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2016 if (unlikely(Rc(ctx
->opcode
) != 0))
2017 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2021 /*** Floating-Point arithmetic ***/
2022 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2023 static void gen_f##name(DisasContext *ctx) \
2025 if (unlikely(!ctx->fpu_enabled)) { \
2026 gen_exception(ctx, POWERPC_EXCP_FPU); \
2029 /* NIP cannot be restored if the memory exception comes from an helper */ \
2030 gen_update_nip(ctx, ctx->nip - 4); \
2031 gen_reset_fpstatus(); \
2032 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2033 cpu_fpr[rA(ctx->opcode)], \
2034 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2036 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2037 cpu_fpr[rD(ctx->opcode)]); \
2039 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2040 Rc(ctx->opcode) != 0); \
2043 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2044 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2045 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2047 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2048 static void gen_f##name(DisasContext *ctx) \
2050 if (unlikely(!ctx->fpu_enabled)) { \
2051 gen_exception(ctx, POWERPC_EXCP_FPU); \
2054 /* NIP cannot be restored if the memory exception comes from an helper */ \
2055 gen_update_nip(ctx, ctx->nip - 4); \
2056 gen_reset_fpstatus(); \
2057 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2058 cpu_fpr[rA(ctx->opcode)], \
2059 cpu_fpr[rB(ctx->opcode)]); \
2061 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2062 cpu_fpr[rD(ctx->opcode)]); \
2064 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2065 set_fprf, Rc(ctx->opcode) != 0); \
2067 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2068 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2069 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2071 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2072 static void gen_f##name(DisasContext *ctx) \
2074 if (unlikely(!ctx->fpu_enabled)) { \
2075 gen_exception(ctx, POWERPC_EXCP_FPU); \
2078 /* NIP cannot be restored if the memory exception comes from an helper */ \
2079 gen_update_nip(ctx, ctx->nip - 4); \
2080 gen_reset_fpstatus(); \
2081 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2082 cpu_fpr[rA(ctx->opcode)], \
2083 cpu_fpr[rC(ctx->opcode)]); \
2085 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2086 cpu_fpr[rD(ctx->opcode)]); \
2088 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2089 set_fprf, Rc(ctx->opcode) != 0); \
2091 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2092 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2093 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2095 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2096 static void gen_f##name(DisasContext *ctx) \
2098 if (unlikely(!ctx->fpu_enabled)) { \
2099 gen_exception(ctx, POWERPC_EXCP_FPU); \
2102 /* NIP cannot be restored if the memory exception comes from an helper */ \
2103 gen_update_nip(ctx, ctx->nip - 4); \
2104 gen_reset_fpstatus(); \
2105 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2106 cpu_fpr[rB(ctx->opcode)]); \
2107 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2108 set_fprf, Rc(ctx->opcode) != 0); \
2111 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2112 static void gen_f##name(DisasContext *ctx) \
2114 if (unlikely(!ctx->fpu_enabled)) { \
2115 gen_exception(ctx, POWERPC_EXCP_FPU); \
2118 /* NIP cannot be restored if the memory exception comes from an helper */ \
2119 gen_update_nip(ctx, ctx->nip - 4); \
2120 gen_reset_fpstatus(); \
2121 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2122 cpu_fpr[rB(ctx->opcode)]); \
2123 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2124 set_fprf, Rc(ctx->opcode) != 0); \
2128 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2130 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2132 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2135 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2138 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2141 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2144 static void gen_frsqrtes(DisasContext
*ctx
)
2146 if (unlikely(!ctx
->fpu_enabled
)) {
2147 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2150 /* NIP cannot be restored if the memory exception comes from an helper */
2151 gen_update_nip(ctx
, ctx
->nip
- 4);
2152 gen_reset_fpstatus();
2153 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2154 cpu_fpr
[rB(ctx
->opcode
)]);
2155 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2156 cpu_fpr
[rD(ctx
->opcode
)]);
2157 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2161 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2163 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2167 static void gen_fsqrt(DisasContext
*ctx
)
2169 if (unlikely(!ctx
->fpu_enabled
)) {
2170 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2173 /* NIP cannot be restored if the memory exception comes from an helper */
2174 gen_update_nip(ctx
, ctx
->nip
- 4);
2175 gen_reset_fpstatus();
2176 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2177 cpu_fpr
[rB(ctx
->opcode
)]);
2178 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2181 static void gen_fsqrts(DisasContext
*ctx
)
2183 if (unlikely(!ctx
->fpu_enabled
)) {
2184 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2187 /* NIP cannot be restored if the memory exception comes from an helper */
2188 gen_update_nip(ctx
, ctx
->nip
- 4);
2189 gen_reset_fpstatus();
2190 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2191 cpu_fpr
[rB(ctx
->opcode
)]);
2192 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2193 cpu_fpr
[rD(ctx
->opcode
)]);
2194 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2197 /*** Floating-Point multiply-and-add ***/
2198 /* fmadd - fmadds */
2199 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2200 /* fmsub - fmsubs */
2201 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2202 /* fnmadd - fnmadds */
2203 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2204 /* fnmsub - fnmsubs */
2205 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2207 /*** Floating-Point round & convert ***/
2209 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2211 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2213 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2214 #if defined(TARGET_PPC64)
2216 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2218 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2220 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2224 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2226 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2228 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2230 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2232 /*** Floating-Point compare ***/
2235 static void gen_fcmpo(DisasContext
*ctx
)
2238 if (unlikely(!ctx
->fpu_enabled
)) {
2239 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2242 /* NIP cannot be restored if the memory exception comes from an helper */
2243 gen_update_nip(ctx
, ctx
->nip
- 4);
2244 gen_reset_fpstatus();
2245 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2246 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2247 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2248 tcg_temp_free_i32(crf
);
2249 gen_helper_float_check_status(cpu_env
);
2253 static void gen_fcmpu(DisasContext
*ctx
)
2256 if (unlikely(!ctx
->fpu_enabled
)) {
2257 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2260 /* NIP cannot be restored if the memory exception comes from an helper */
2261 gen_update_nip(ctx
, ctx
->nip
- 4);
2262 gen_reset_fpstatus();
2263 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2264 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2265 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2266 tcg_temp_free_i32(crf
);
2267 gen_helper_float_check_status(cpu_env
);
2270 /*** Floating-point move ***/
2272 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2273 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2276 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2277 static void gen_fmr(DisasContext
*ctx
)
2279 if (unlikely(!ctx
->fpu_enabled
)) {
2280 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2283 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2284 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2288 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2289 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2291 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2292 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2294 /*** Floating-Point status & ctrl register ***/
2297 static void gen_mcrfs(DisasContext
*ctx
)
2299 TCGv tmp
= tcg_temp_new();
2302 if (unlikely(!ctx
->fpu_enabled
)) {
2303 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2306 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2307 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2308 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2310 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2311 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2315 static void gen_mffs(DisasContext
*ctx
)
2317 if (unlikely(!ctx
->fpu_enabled
)) {
2318 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2321 gen_reset_fpstatus();
2322 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2323 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2327 static void gen_mtfsb0(DisasContext
*ctx
)
2331 if (unlikely(!ctx
->fpu_enabled
)) {
2332 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2335 crb
= 31 - crbD(ctx
->opcode
);
2336 gen_reset_fpstatus();
2337 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2339 /* NIP cannot be restored if the memory exception comes from an helper */
2340 gen_update_nip(ctx
, ctx
->nip
- 4);
2341 t0
= tcg_const_i32(crb
);
2342 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2343 tcg_temp_free_i32(t0
);
2345 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2346 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2347 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2352 static void gen_mtfsb1(DisasContext
*ctx
)
2356 if (unlikely(!ctx
->fpu_enabled
)) {
2357 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2360 crb
= 31 - crbD(ctx
->opcode
);
2361 gen_reset_fpstatus();
2362 /* XXX: we pretend we can only do IEEE floating-point computations */
2363 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2365 /* NIP cannot be restored if the memory exception comes from an helper */
2366 gen_update_nip(ctx
, ctx
->nip
- 4);
2367 t0
= tcg_const_i32(crb
);
2368 gen_helper_fpscr_setbit(cpu_env
, t0
);
2369 tcg_temp_free_i32(t0
);
2371 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2372 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2373 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2375 /* We can raise a differed exception */
2376 gen_helper_float_check_status(cpu_env
);
2380 static void gen_mtfsf(DisasContext
*ctx
)
2383 int L
= ctx
->opcode
& 0x02000000;
2385 if (unlikely(!ctx
->fpu_enabled
)) {
2386 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2389 /* NIP cannot be restored if the memory exception comes from an helper */
2390 gen_update_nip(ctx
, ctx
->nip
- 4);
2391 gen_reset_fpstatus();
2393 t0
= tcg_const_i32(0xff);
2395 t0
= tcg_const_i32(FM(ctx
->opcode
));
2396 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2397 tcg_temp_free_i32(t0
);
2398 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2399 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2400 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2402 /* We can raise a differed exception */
2403 gen_helper_float_check_status(cpu_env
);
2407 static void gen_mtfsfi(DisasContext
*ctx
)
2413 if (unlikely(!ctx
->fpu_enabled
)) {
2414 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2417 bf
= crbD(ctx
->opcode
) >> 2;
2419 /* NIP cannot be restored if the memory exception comes from an helper */
2420 gen_update_nip(ctx
, ctx
->nip
- 4);
2421 gen_reset_fpstatus();
2422 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2423 t1
= tcg_const_i32(1 << sh
);
2424 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2425 tcg_temp_free_i64(t0
);
2426 tcg_temp_free_i32(t1
);
2427 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2428 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2429 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2431 /* We can raise a differed exception */
2432 gen_helper_float_check_status(cpu_env
);
2435 /*** Addressing modes ***/
2436 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2437 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2440 target_long simm
= SIMM(ctx
->opcode
);
2443 if (rA(ctx
->opcode
) == 0) {
2444 #if defined(TARGET_PPC64)
2445 if (!ctx
->sf_mode
) {
2446 tcg_gen_movi_tl(EA
, (uint32_t)simm
);
2449 tcg_gen_movi_tl(EA
, simm
);
2450 } else if (likely(simm
!= 0)) {
2451 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2452 #if defined(TARGET_PPC64)
2453 if (!ctx
->sf_mode
) {
2454 tcg_gen_ext32u_tl(EA
, EA
);
2458 #if defined(TARGET_PPC64)
2459 if (!ctx
->sf_mode
) {
2460 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2463 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2467 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2469 if (rA(ctx
->opcode
) == 0) {
2470 #if defined(TARGET_PPC64)
2471 if (!ctx
->sf_mode
) {
2472 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2475 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2477 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2478 #if defined(TARGET_PPC64)
2479 if (!ctx
->sf_mode
) {
2480 tcg_gen_ext32u_tl(EA
, EA
);
2486 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2488 if (rA(ctx
->opcode
) == 0) {
2489 tcg_gen_movi_tl(EA
, 0);
2491 #if defined(TARGET_PPC64)
2492 if (!ctx
->sf_mode
) {
2493 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2496 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2500 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2503 tcg_gen_addi_tl(ret
, arg1
, val
);
2504 #if defined(TARGET_PPC64)
2505 if (!ctx
->sf_mode
) {
2506 tcg_gen_ext32u_tl(ret
, ret
);
2511 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2513 int l1
= gen_new_label();
2514 TCGv t0
= tcg_temp_new();
2516 /* NIP cannot be restored if the memory exception comes from an helper */
2517 gen_update_nip(ctx
, ctx
->nip
- 4);
2518 tcg_gen_andi_tl(t0
, EA
, mask
);
2519 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2520 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2521 t2
= tcg_const_i32(0);
2522 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2523 tcg_temp_free_i32(t1
);
2524 tcg_temp_free_i32(t2
);
2529 /*** Integer load ***/
2530 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2532 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2535 static inline void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2537 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2540 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2542 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2543 if (unlikely(ctx
->le_mode
)) {
2544 tcg_gen_bswap16_tl(arg1
, arg1
);
2548 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2550 if (unlikely(ctx
->le_mode
)) {
2551 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2552 tcg_gen_bswap16_tl(arg1
, arg1
);
2553 tcg_gen_ext16s_tl(arg1
, arg1
);
2555 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2559 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2561 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2562 if (unlikely(ctx
->le_mode
)) {
2563 tcg_gen_bswap32_tl(arg1
, arg1
);
2567 #if defined(TARGET_PPC64)
2568 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2570 if (unlikely(ctx
->le_mode
)) {
2571 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2572 tcg_gen_bswap32_tl(arg1
, arg1
);
2573 tcg_gen_ext32s_tl(arg1
, arg1
);
2575 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2579 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2581 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2582 if (unlikely(ctx
->le_mode
)) {
2583 tcg_gen_bswap64_i64(arg1
, arg1
);
2587 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2589 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2592 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2594 if (unlikely(ctx
->le_mode
)) {
2595 TCGv t0
= tcg_temp_new();
2596 tcg_gen_ext16u_tl(t0
, arg1
);
2597 tcg_gen_bswap16_tl(t0
, t0
);
2598 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2601 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2605 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2607 if (unlikely(ctx
->le_mode
)) {
2608 TCGv t0
= tcg_temp_new();
2609 tcg_gen_ext32u_tl(t0
, arg1
);
2610 tcg_gen_bswap32_tl(t0
, t0
);
2611 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2614 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2618 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2620 if (unlikely(ctx
->le_mode
)) {
2621 TCGv_i64 t0
= tcg_temp_new_i64();
2622 tcg_gen_bswap64_i64(t0
, arg1
);
2623 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2624 tcg_temp_free_i64(t0
);
2626 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2629 #define GEN_LD(name, ldop, opc, type) \
2630 static void glue(gen_, name)(DisasContext *ctx) \
2633 gen_set_access_type(ctx, ACCESS_INT); \
2634 EA = tcg_temp_new(); \
2635 gen_addr_imm_index(ctx, EA, 0); \
2636 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2637 tcg_temp_free(EA); \
2640 #define GEN_LDU(name, ldop, opc, type) \
2641 static void glue(gen_, name##u)(DisasContext *ctx) \
2644 if (unlikely(rA(ctx->opcode) == 0 || \
2645 rA(ctx->opcode) == rD(ctx->opcode))) { \
2646 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2649 gen_set_access_type(ctx, ACCESS_INT); \
2650 EA = tcg_temp_new(); \
2651 if (type == PPC_64B) \
2652 gen_addr_imm_index(ctx, EA, 0x03); \
2654 gen_addr_imm_index(ctx, EA, 0); \
2655 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2656 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2657 tcg_temp_free(EA); \
2660 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2661 static void glue(gen_, name##ux)(DisasContext *ctx) \
2664 if (unlikely(rA(ctx->opcode) == 0 || \
2665 rA(ctx->opcode) == rD(ctx->opcode))) { \
2666 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2669 gen_set_access_type(ctx, ACCESS_INT); \
2670 EA = tcg_temp_new(); \
2671 gen_addr_reg_index(ctx, EA); \
2672 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2673 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2674 tcg_temp_free(EA); \
2677 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2678 static void glue(gen_, name##x)(DisasContext *ctx) \
2681 gen_set_access_type(ctx, ACCESS_INT); \
2682 EA = tcg_temp_new(); \
2683 gen_addr_reg_index(ctx, EA); \
2684 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2685 tcg_temp_free(EA); \
2687 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2688 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2690 #define GEN_LDS(name, ldop, op, type) \
2691 GEN_LD(name, ldop, op | 0x20, type); \
2692 GEN_LDU(name, ldop, op | 0x21, type); \
2693 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2694 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2696 /* lbz lbzu lbzux lbzx */
2697 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2698 /* lha lhau lhaux lhax */
2699 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2700 /* lhz lhzu lhzux lhzx */
2701 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2702 /* lwz lwzu lwzux lwzx */
2703 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2704 #if defined(TARGET_PPC64)
2706 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2708 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2710 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2712 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2714 static void gen_ld(DisasContext
*ctx
)
2717 if (Rc(ctx
->opcode
)) {
2718 if (unlikely(rA(ctx
->opcode
) == 0 ||
2719 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2720 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2724 gen_set_access_type(ctx
, ACCESS_INT
);
2725 EA
= tcg_temp_new();
2726 gen_addr_imm_index(ctx
, EA
, 0x03);
2727 if (ctx
->opcode
& 0x02) {
2728 /* lwa (lwau is undefined) */
2729 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2732 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2734 if (Rc(ctx
->opcode
))
2735 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2740 static void gen_lq(DisasContext
*ctx
)
2742 #if defined(CONFIG_USER_ONLY)
2743 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2748 /* Restore CPU state */
2749 if (unlikely(ctx
->mem_idx
== 0)) {
2750 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2753 ra
= rA(ctx
->opcode
);
2754 rd
= rD(ctx
->opcode
);
2755 if (unlikely((rd
& 1) || rd
== ra
)) {
2756 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2759 if (unlikely(ctx
->le_mode
)) {
2760 /* Little-endian mode is not handled */
2761 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2764 gen_set_access_type(ctx
, ACCESS_INT
);
2765 EA
= tcg_temp_new();
2766 gen_addr_imm_index(ctx
, EA
, 0x0F);
2767 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2768 gen_addr_add(ctx
, EA
, EA
, 8);
2769 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2775 /*** Integer store ***/
2776 #define GEN_ST(name, stop, opc, type) \
2777 static void glue(gen_, name)(DisasContext *ctx) \
2780 gen_set_access_type(ctx, ACCESS_INT); \
2781 EA = tcg_temp_new(); \
2782 gen_addr_imm_index(ctx, EA, 0); \
2783 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2784 tcg_temp_free(EA); \
2787 #define GEN_STU(name, stop, opc, type) \
2788 static void glue(gen_, stop##u)(DisasContext *ctx) \
2791 if (unlikely(rA(ctx->opcode) == 0)) { \
2792 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2795 gen_set_access_type(ctx, ACCESS_INT); \
2796 EA = tcg_temp_new(); \
2797 if (type == PPC_64B) \
2798 gen_addr_imm_index(ctx, EA, 0x03); \
2800 gen_addr_imm_index(ctx, EA, 0); \
2801 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2802 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2803 tcg_temp_free(EA); \
2806 #define GEN_STUX(name, stop, opc2, opc3, type) \
2807 static void glue(gen_, name##ux)(DisasContext *ctx) \
2810 if (unlikely(rA(ctx->opcode) == 0)) { \
2811 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2814 gen_set_access_type(ctx, ACCESS_INT); \
2815 EA = tcg_temp_new(); \
2816 gen_addr_reg_index(ctx, EA); \
2817 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2818 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2819 tcg_temp_free(EA); \
2822 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2823 static void glue(gen_, name##x)(DisasContext *ctx) \
2826 gen_set_access_type(ctx, ACCESS_INT); \
2827 EA = tcg_temp_new(); \
2828 gen_addr_reg_index(ctx, EA); \
2829 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2830 tcg_temp_free(EA); \
2832 #define GEN_STX(name, stop, opc2, opc3, type) \
2833 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2835 #define GEN_STS(name, stop, op, type) \
2836 GEN_ST(name, stop, op | 0x20, type); \
2837 GEN_STU(name, stop, op | 0x21, type); \
2838 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2839 GEN_STX(name, stop, 0x17, op | 0x00, type)
2841 /* stb stbu stbux stbx */
2842 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2843 /* sth sthu sthux sthx */
2844 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2845 /* stw stwu stwux stwx */
2846 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2847 #if defined(TARGET_PPC64)
2848 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2849 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2851 static void gen_std(DisasContext
*ctx
)
2856 rs
= rS(ctx
->opcode
);
2857 if ((ctx
->opcode
& 0x3) == 0x2) {
2858 #if defined(CONFIG_USER_ONLY)
2859 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2862 if (unlikely(ctx
->mem_idx
== 0)) {
2863 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2866 if (unlikely(rs
& 1)) {
2867 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2870 if (unlikely(ctx
->le_mode
)) {
2871 /* Little-endian mode is not handled */
2872 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2875 gen_set_access_type(ctx
, ACCESS_INT
);
2876 EA
= tcg_temp_new();
2877 gen_addr_imm_index(ctx
, EA
, 0x03);
2878 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2879 gen_addr_add(ctx
, EA
, EA
, 8);
2880 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2885 if (Rc(ctx
->opcode
)) {
2886 if (unlikely(rA(ctx
->opcode
) == 0)) {
2887 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2891 gen_set_access_type(ctx
, ACCESS_INT
);
2892 EA
= tcg_temp_new();
2893 gen_addr_imm_index(ctx
, EA
, 0x03);
2894 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2895 if (Rc(ctx
->opcode
))
2896 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2901 /*** Integer load and store with byte reverse ***/
2903 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2905 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2906 if (likely(!ctx
->le_mode
)) {
2907 tcg_gen_bswap16_tl(arg1
, arg1
);
2910 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2913 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2915 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2916 if (likely(!ctx
->le_mode
)) {
2917 tcg_gen_bswap32_tl(arg1
, arg1
);
2920 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2922 #if defined(TARGET_PPC64)
2924 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2926 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2927 if (likely(!ctx
->le_mode
)) {
2928 tcg_gen_bswap64_tl(arg1
, arg1
);
2931 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
2932 #endif /* TARGET_PPC64 */
2935 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2937 if (likely(!ctx
->le_mode
)) {
2938 TCGv t0
= tcg_temp_new();
2939 tcg_gen_ext16u_tl(t0
, arg1
);
2940 tcg_gen_bswap16_tl(t0
, t0
);
2941 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2944 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2947 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2950 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2952 if (likely(!ctx
->le_mode
)) {
2953 TCGv t0
= tcg_temp_new();
2954 tcg_gen_ext32u_tl(t0
, arg1
);
2955 tcg_gen_bswap32_tl(t0
, t0
);
2956 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2959 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2962 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2964 #if defined(TARGET_PPC64)
2966 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2968 if (likely(!ctx
->le_mode
)) {
2969 TCGv t0
= tcg_temp_new();
2970 tcg_gen_bswap64_tl(t0
, arg1
);
2971 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2974 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2977 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
2978 #endif /* TARGET_PPC64 */
2980 /*** Integer load and store multiple ***/
2983 static void gen_lmw(DisasContext
*ctx
)
2987 gen_set_access_type(ctx
, ACCESS_INT
);
2988 /* NIP cannot be restored if the memory exception comes from an helper */
2989 gen_update_nip(ctx
, ctx
->nip
- 4);
2990 t0
= tcg_temp_new();
2991 t1
= tcg_const_i32(rD(ctx
->opcode
));
2992 gen_addr_imm_index(ctx
, t0
, 0);
2993 gen_helper_lmw(cpu_env
, t0
, t1
);
2995 tcg_temp_free_i32(t1
);
2999 static void gen_stmw(DisasContext
*ctx
)
3003 gen_set_access_type(ctx
, ACCESS_INT
);
3004 /* NIP cannot be restored if the memory exception comes from an helper */
3005 gen_update_nip(ctx
, ctx
->nip
- 4);
3006 t0
= tcg_temp_new();
3007 t1
= tcg_const_i32(rS(ctx
->opcode
));
3008 gen_addr_imm_index(ctx
, t0
, 0);
3009 gen_helper_stmw(cpu_env
, t0
, t1
);
3011 tcg_temp_free_i32(t1
);
3014 /*** Integer load and store strings ***/
3017 /* PowerPC32 specification says we must generate an exception if
3018 * rA is in the range of registers to be loaded.
3019 * In an other hand, IBM says this is valid, but rA won't be loaded.
3020 * For now, I'll follow the spec...
3022 static void gen_lswi(DisasContext
*ctx
)
3026 int nb
= NB(ctx
->opcode
);
3027 int start
= rD(ctx
->opcode
);
3028 int ra
= rA(ctx
->opcode
);
3034 if (unlikely(((start
+ nr
) > 32 &&
3035 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3036 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3037 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3040 gen_set_access_type(ctx
, ACCESS_INT
);
3041 /* NIP cannot be restored if the memory exception comes from an helper */
3042 gen_update_nip(ctx
, ctx
->nip
- 4);
3043 t0
= tcg_temp_new();
3044 gen_addr_register(ctx
, t0
);
3045 t1
= tcg_const_i32(nb
);
3046 t2
= tcg_const_i32(start
);
3047 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3049 tcg_temp_free_i32(t1
);
3050 tcg_temp_free_i32(t2
);
3054 static void gen_lswx(DisasContext
*ctx
)
3057 TCGv_i32 t1
, t2
, t3
;
3058 gen_set_access_type(ctx
, ACCESS_INT
);
3059 /* NIP cannot be restored if the memory exception comes from an helper */
3060 gen_update_nip(ctx
, ctx
->nip
- 4);
3061 t0
= tcg_temp_new();
3062 gen_addr_reg_index(ctx
, t0
);
3063 t1
= tcg_const_i32(rD(ctx
->opcode
));
3064 t2
= tcg_const_i32(rA(ctx
->opcode
));
3065 t3
= tcg_const_i32(rB(ctx
->opcode
));
3066 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3068 tcg_temp_free_i32(t1
);
3069 tcg_temp_free_i32(t2
);
3070 tcg_temp_free_i32(t3
);
3074 static void gen_stswi(DisasContext
*ctx
)
3078 int nb
= NB(ctx
->opcode
);
3079 gen_set_access_type(ctx
, ACCESS_INT
);
3080 /* NIP cannot be restored if the memory exception comes from an helper */
3081 gen_update_nip(ctx
, ctx
->nip
- 4);
3082 t0
= tcg_temp_new();
3083 gen_addr_register(ctx
, t0
);
3086 t1
= tcg_const_i32(nb
);
3087 t2
= tcg_const_i32(rS(ctx
->opcode
));
3088 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3090 tcg_temp_free_i32(t1
);
3091 tcg_temp_free_i32(t2
);
3095 static void gen_stswx(DisasContext
*ctx
)
3099 gen_set_access_type(ctx
, ACCESS_INT
);
3100 /* NIP cannot be restored if the memory exception comes from an helper */
3101 gen_update_nip(ctx
, ctx
->nip
- 4);
3102 t0
= tcg_temp_new();
3103 gen_addr_reg_index(ctx
, t0
);
3104 t1
= tcg_temp_new_i32();
3105 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3106 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3107 t2
= tcg_const_i32(rS(ctx
->opcode
));
3108 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3110 tcg_temp_free_i32(t1
);
3111 tcg_temp_free_i32(t2
);
3114 /*** Memory synchronisation ***/
3116 static void gen_eieio(DisasContext
*ctx
)
3121 static void gen_isync(DisasContext
*ctx
)
3123 gen_stop_exception(ctx
);
3127 static void gen_lwarx(DisasContext
*ctx
)
3130 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3131 gen_set_access_type(ctx
, ACCESS_RES
);
3132 t0
= tcg_temp_local_new();
3133 gen_addr_reg_index(ctx
, t0
);
3134 gen_check_align(ctx
, t0
, 0x03);
3135 gen_qemu_ld32u(ctx
, gpr
, t0
);
3136 tcg_gen_mov_tl(cpu_reserve
, t0
);
3137 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3141 #if defined(CONFIG_USER_ONLY)
3142 static void gen_conditional_store (DisasContext
*ctx
, TCGv EA
,
3145 TCGv t0
= tcg_temp_new();
3146 uint32_t save_exception
= ctx
->exception
;
3148 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3149 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3150 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3152 gen_update_nip(ctx
, ctx
->nip
-4);
3153 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3154 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3155 ctx
->exception
= save_exception
;
3160 static void gen_stwcx_(DisasContext
*ctx
)
3163 gen_set_access_type(ctx
, ACCESS_RES
);
3164 t0
= tcg_temp_local_new();
3165 gen_addr_reg_index(ctx
, t0
);
3166 gen_check_align(ctx
, t0
, 0x03);
3167 #if defined(CONFIG_USER_ONLY)
3168 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 4);
3173 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3174 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3175 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3176 l1
= gen_new_label();
3177 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3178 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3179 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3181 tcg_gen_movi_tl(cpu_reserve
, -1);
3187 #if defined(TARGET_PPC64)
3189 static void gen_ldarx(DisasContext
*ctx
)
3192 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3193 gen_set_access_type(ctx
, ACCESS_RES
);
3194 t0
= tcg_temp_local_new();
3195 gen_addr_reg_index(ctx
, t0
);
3196 gen_check_align(ctx
, t0
, 0x07);
3197 gen_qemu_ld64(ctx
, gpr
, t0
);
3198 tcg_gen_mov_tl(cpu_reserve
, t0
);
3199 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3204 static void gen_stdcx_(DisasContext
*ctx
)
3207 gen_set_access_type(ctx
, ACCESS_RES
);
3208 t0
= tcg_temp_local_new();
3209 gen_addr_reg_index(ctx
, t0
);
3210 gen_check_align(ctx
, t0
, 0x07);
3211 #if defined(CONFIG_USER_ONLY)
3212 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 8);
3216 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3217 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3218 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3219 l1
= gen_new_label();
3220 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3221 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3222 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3224 tcg_gen_movi_tl(cpu_reserve
, -1);
3229 #endif /* defined(TARGET_PPC64) */
3232 static void gen_sync(DisasContext
*ctx
)
3237 static void gen_wait(DisasContext
*ctx
)
3239 TCGv_i32 t0
= tcg_temp_new_i32();
3240 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUPPCState
, halted
));
3241 tcg_temp_free_i32(t0
);
3242 /* Stop translation, as the CPU is supposed to sleep from now */
3243 gen_exception_err(ctx
, EXCP_HLT
, 1);
3246 /*** Floating-point load ***/
3247 #define GEN_LDF(name, ldop, opc, type) \
3248 static void glue(gen_, name)(DisasContext *ctx) \
3251 if (unlikely(!ctx->fpu_enabled)) { \
3252 gen_exception(ctx, POWERPC_EXCP_FPU); \
3255 gen_set_access_type(ctx, ACCESS_FLOAT); \
3256 EA = tcg_temp_new(); \
3257 gen_addr_imm_index(ctx, EA, 0); \
3258 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3259 tcg_temp_free(EA); \
3262 #define GEN_LDUF(name, ldop, opc, type) \
3263 static void glue(gen_, name##u)(DisasContext *ctx) \
3266 if (unlikely(!ctx->fpu_enabled)) { \
3267 gen_exception(ctx, POWERPC_EXCP_FPU); \
3270 if (unlikely(rA(ctx->opcode) == 0)) { \
3271 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3274 gen_set_access_type(ctx, ACCESS_FLOAT); \
3275 EA = tcg_temp_new(); \
3276 gen_addr_imm_index(ctx, EA, 0); \
3277 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3278 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3279 tcg_temp_free(EA); \
3282 #define GEN_LDUXF(name, ldop, opc, type) \
3283 static void glue(gen_, name##ux)(DisasContext *ctx) \
3286 if (unlikely(!ctx->fpu_enabled)) { \
3287 gen_exception(ctx, POWERPC_EXCP_FPU); \
3290 if (unlikely(rA(ctx->opcode) == 0)) { \
3291 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3294 gen_set_access_type(ctx, ACCESS_FLOAT); \
3295 EA = tcg_temp_new(); \
3296 gen_addr_reg_index(ctx, EA); \
3297 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3298 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3299 tcg_temp_free(EA); \
3302 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3303 static void glue(gen_, name##x)(DisasContext *ctx) \
3306 if (unlikely(!ctx->fpu_enabled)) { \
3307 gen_exception(ctx, POWERPC_EXCP_FPU); \
3310 gen_set_access_type(ctx, ACCESS_FLOAT); \
3311 EA = tcg_temp_new(); \
3312 gen_addr_reg_index(ctx, EA); \
3313 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3314 tcg_temp_free(EA); \
3317 #define GEN_LDFS(name, ldop, op, type) \
3318 GEN_LDF(name, ldop, op | 0x20, type); \
3319 GEN_LDUF(name, ldop, op | 0x21, type); \
3320 GEN_LDUXF(name, ldop, op | 0x01, type); \
3321 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3323 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3325 TCGv t0
= tcg_temp_new();
3326 TCGv_i32 t1
= tcg_temp_new_i32();
3327 gen_qemu_ld32u(ctx
, t0
, arg2
);
3328 tcg_gen_trunc_tl_i32(t1
, t0
);
3330 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3331 tcg_temp_free_i32(t1
);
3334 /* lfd lfdu lfdux lfdx */
3335 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3336 /* lfs lfsu lfsux lfsx */
3337 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3339 /*** Floating-point store ***/
3340 #define GEN_STF(name, stop, opc, type) \
3341 static void glue(gen_, name)(DisasContext *ctx) \
3344 if (unlikely(!ctx->fpu_enabled)) { \
3345 gen_exception(ctx, POWERPC_EXCP_FPU); \
3348 gen_set_access_type(ctx, ACCESS_FLOAT); \
3349 EA = tcg_temp_new(); \
3350 gen_addr_imm_index(ctx, EA, 0); \
3351 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3352 tcg_temp_free(EA); \
3355 #define GEN_STUF(name, stop, opc, type) \
3356 static void glue(gen_, name##u)(DisasContext *ctx) \
3359 if (unlikely(!ctx->fpu_enabled)) { \
3360 gen_exception(ctx, POWERPC_EXCP_FPU); \
3363 if (unlikely(rA(ctx->opcode) == 0)) { \
3364 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3367 gen_set_access_type(ctx, ACCESS_FLOAT); \
3368 EA = tcg_temp_new(); \
3369 gen_addr_imm_index(ctx, EA, 0); \
3370 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3371 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3372 tcg_temp_free(EA); \
3375 #define GEN_STUXF(name, stop, opc, type) \
3376 static void glue(gen_, name##ux)(DisasContext *ctx) \
3379 if (unlikely(!ctx->fpu_enabled)) { \
3380 gen_exception(ctx, POWERPC_EXCP_FPU); \
3383 if (unlikely(rA(ctx->opcode) == 0)) { \
3384 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3387 gen_set_access_type(ctx, ACCESS_FLOAT); \
3388 EA = tcg_temp_new(); \
3389 gen_addr_reg_index(ctx, EA); \
3390 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3391 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3392 tcg_temp_free(EA); \
3395 #define GEN_STXF(name, stop, opc2, opc3, type) \
3396 static void glue(gen_, name##x)(DisasContext *ctx) \
3399 if (unlikely(!ctx->fpu_enabled)) { \
3400 gen_exception(ctx, POWERPC_EXCP_FPU); \
3403 gen_set_access_type(ctx, ACCESS_FLOAT); \
3404 EA = tcg_temp_new(); \
3405 gen_addr_reg_index(ctx, EA); \
3406 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3407 tcg_temp_free(EA); \
3410 #define GEN_STFS(name, stop, op, type) \
3411 GEN_STF(name, stop, op | 0x20, type); \
3412 GEN_STUF(name, stop, op | 0x21, type); \
3413 GEN_STUXF(name, stop, op | 0x01, type); \
3414 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3416 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3418 TCGv_i32 t0
= tcg_temp_new_i32();
3419 TCGv t1
= tcg_temp_new();
3420 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3421 tcg_gen_extu_i32_tl(t1
, t0
);
3422 tcg_temp_free_i32(t0
);
3423 gen_qemu_st32(ctx
, t1
, arg2
);
3427 /* stfd stfdu stfdux stfdx */
3428 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3429 /* stfs stfsu stfsux stfsx */
3430 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3433 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3435 TCGv t0
= tcg_temp_new();
3436 tcg_gen_trunc_i64_tl(t0
, arg1
),
3437 gen_qemu_st32(ctx
, t0
, arg2
);
3441 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3443 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3445 #if defined(TARGET_PPC64)
3447 tcg_gen_movi_tl(cpu_cfar
, nip
);
3452 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3454 TranslationBlock
*tb
;
3456 #if defined(TARGET_PPC64)
3458 dest
= (uint32_t) dest
;
3460 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3461 likely(!ctx
->singlestep_enabled
)) {
3463 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3464 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
3466 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3467 if (unlikely(ctx
->singlestep_enabled
)) {
3468 if ((ctx
->singlestep_enabled
&
3469 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3470 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3471 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3472 target_ulong tmp
= ctx
->nip
;
3474 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3477 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3478 gen_debug_exception(ctx
);
3485 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3487 #if defined(TARGET_PPC64)
3488 if (ctx
->sf_mode
== 0)
3489 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3492 tcg_gen_movi_tl(cpu_lr
, nip
);
3496 static void gen_b(DisasContext
*ctx
)
3498 target_ulong li
, target
;
3500 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3501 /* sign extend LI */
3502 #if defined(TARGET_PPC64)
3504 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3507 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3508 if (likely(AA(ctx
->opcode
) == 0))
3509 target
= ctx
->nip
+ li
- 4;
3512 if (LK(ctx
->opcode
))
3513 gen_setlr(ctx
, ctx
->nip
);
3514 gen_update_cfar(ctx
, ctx
->nip
);
3515 gen_goto_tb(ctx
, 0, target
);
3522 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3524 uint32_t bo
= BO(ctx
->opcode
);
3528 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3529 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3530 target
= tcg_temp_local_new();
3531 if (type
== BCOND_CTR
)
3532 tcg_gen_mov_tl(target
, cpu_ctr
);
3534 tcg_gen_mov_tl(target
, cpu_lr
);
3536 TCGV_UNUSED(target
);
3538 if (LK(ctx
->opcode
))
3539 gen_setlr(ctx
, ctx
->nip
);
3540 l1
= gen_new_label();
3541 if ((bo
& 0x4) == 0) {
3542 /* Decrement and test CTR */
3543 TCGv temp
= tcg_temp_new();
3544 if (unlikely(type
== BCOND_CTR
)) {
3545 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3548 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3549 #if defined(TARGET_PPC64)
3551 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3554 tcg_gen_mov_tl(temp
, cpu_ctr
);
3556 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3558 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3560 tcg_temp_free(temp
);
3562 if ((bo
& 0x10) == 0) {
3564 uint32_t bi
= BI(ctx
->opcode
);
3565 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3566 TCGv_i32 temp
= tcg_temp_new_i32();
3569 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3570 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3572 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3573 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3575 tcg_temp_free_i32(temp
);
3577 gen_update_cfar(ctx
, ctx
->nip
);
3578 if (type
== BCOND_IM
) {
3579 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3580 if (likely(AA(ctx
->opcode
) == 0)) {
3581 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3583 gen_goto_tb(ctx
, 0, li
);
3586 gen_goto_tb(ctx
, 1, ctx
->nip
);
3588 #if defined(TARGET_PPC64)
3589 if (!(ctx
->sf_mode
))
3590 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3593 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3596 #if defined(TARGET_PPC64)
3597 if (!(ctx
->sf_mode
))
3598 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3601 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3606 static void gen_bc(DisasContext
*ctx
)
3608 gen_bcond(ctx
, BCOND_IM
);
3611 static void gen_bcctr(DisasContext
*ctx
)
3613 gen_bcond(ctx
, BCOND_CTR
);
3616 static void gen_bclr(DisasContext
*ctx
)
3618 gen_bcond(ctx
, BCOND_LR
);
3621 /*** Condition register logical ***/
3622 #define GEN_CRLOGIC(name, tcg_op, opc) \
3623 static void glue(gen_, name)(DisasContext *ctx) \
3628 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3629 t0 = tcg_temp_new_i32(); \
3631 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3633 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3635 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3636 t1 = tcg_temp_new_i32(); \
3637 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3639 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3641 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3643 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3644 tcg_op(t0, t0, t1); \
3645 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3646 tcg_gen_andi_i32(t0, t0, bitmask); \
3647 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3648 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3649 tcg_temp_free_i32(t0); \
3650 tcg_temp_free_i32(t1); \
3654 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3656 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3658 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3660 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3662 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3664 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3666 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3668 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3671 static void gen_mcrf(DisasContext
*ctx
)
3673 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3676 /*** System linkage ***/
3678 /* rfi (mem_idx only) */
3679 static void gen_rfi(DisasContext
*ctx
)
3681 #if defined(CONFIG_USER_ONLY)
3682 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3684 /* Restore CPU state */
3685 if (unlikely(!ctx
->mem_idx
)) {
3686 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3689 gen_update_cfar(ctx
, ctx
->nip
);
3690 gen_helper_rfi(cpu_env
);
3691 gen_sync_exception(ctx
);
3695 #if defined(TARGET_PPC64)
3696 static void gen_rfid(DisasContext
*ctx
)
3698 #if defined(CONFIG_USER_ONLY)
3699 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3701 /* Restore CPU state */
3702 if (unlikely(!ctx
->mem_idx
)) {
3703 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3706 gen_update_cfar(ctx
, ctx
->nip
);
3707 gen_helper_rfid(cpu_env
);
3708 gen_sync_exception(ctx
);
3712 static void gen_hrfid(DisasContext
*ctx
)
3714 #if defined(CONFIG_USER_ONLY)
3715 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3717 /* Restore CPU state */
3718 if (unlikely(ctx
->mem_idx
<= 1)) {
3719 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3722 gen_helper_hrfid(cpu_env
);
3723 gen_sync_exception(ctx
);
3729 #if defined(CONFIG_USER_ONLY)
3730 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3732 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3734 static void gen_sc(DisasContext
*ctx
)
3738 lev
= (ctx
->opcode
>> 5) & 0x7F;
3739 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3745 static void gen_tw(DisasContext
*ctx
)
3747 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3748 /* Update the nip since this might generate a trap exception */
3749 gen_update_nip(ctx
, ctx
->nip
);
3750 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3752 tcg_temp_free_i32(t0
);
3756 static void gen_twi(DisasContext
*ctx
)
3758 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3759 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3760 /* Update the nip since this might generate a trap exception */
3761 gen_update_nip(ctx
, ctx
->nip
);
3762 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3764 tcg_temp_free_i32(t1
);
3767 #if defined(TARGET_PPC64)
3769 static void gen_td(DisasContext
*ctx
)
3771 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3772 /* Update the nip since this might generate a trap exception */
3773 gen_update_nip(ctx
, ctx
->nip
);
3774 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3776 tcg_temp_free_i32(t0
);
3780 static void gen_tdi(DisasContext
*ctx
)
3782 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3783 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3784 /* Update the nip since this might generate a trap exception */
3785 gen_update_nip(ctx
, ctx
->nip
);
3786 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3788 tcg_temp_free_i32(t1
);
3792 /*** Processor control ***/
3795 static void gen_mcrxr(DisasContext
*ctx
)
3797 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_xer
);
3798 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], XER_CA
);
3799 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_SO
| 1 << XER_OV
| 1 << XER_CA
));
3803 static void gen_mfcr(DisasContext
*ctx
)
3807 if (likely(ctx
->opcode
& 0x00100000)) {
3808 crm
= CRM(ctx
->opcode
);
3809 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3811 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3812 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3813 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3816 TCGv_i32 t0
= tcg_temp_new_i32();
3817 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3818 tcg_gen_shli_i32(t0
, t0
, 4);
3819 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3820 tcg_gen_shli_i32(t0
, t0
, 4);
3821 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3822 tcg_gen_shli_i32(t0
, t0
, 4);
3823 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3824 tcg_gen_shli_i32(t0
, t0
, 4);
3825 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3826 tcg_gen_shli_i32(t0
, t0
, 4);
3827 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3828 tcg_gen_shli_i32(t0
, t0
, 4);
3829 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3830 tcg_gen_shli_i32(t0
, t0
, 4);
3831 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3832 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3833 tcg_temp_free_i32(t0
);
3838 static void gen_mfmsr(DisasContext
*ctx
)
3840 #if defined(CONFIG_USER_ONLY)
3841 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3843 if (unlikely(!ctx
->mem_idx
)) {
3844 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3847 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3851 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
3854 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3855 printf("ERROR: try to access SPR %d !\n", sprn
);
3858 #define SPR_NOACCESS (&spr_noaccess)
3861 static inline void gen_op_mfspr(DisasContext
*ctx
)
3863 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3864 uint32_t sprn
= SPR(ctx
->opcode
);
3866 #if !defined(CONFIG_USER_ONLY)
3867 if (ctx
->mem_idx
== 2)
3868 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3869 else if (ctx
->mem_idx
)
3870 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3873 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3874 if (likely(read_cb
!= NULL
)) {
3875 if (likely(read_cb
!= SPR_NOACCESS
)) {
3876 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3878 /* Privilege exception */
3879 /* This is a hack to avoid warnings when running Linux:
3880 * this OS breaks the PowerPC virtualisation model,
3881 * allowing userland application to read the PVR
3883 if (sprn
!= SPR_PVR
) {
3884 qemu_log("Trying to read privileged spr %d %03x at "
3885 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3886 printf("Trying to read privileged spr %d %03x at "
3887 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3889 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3893 qemu_log("Trying to read invalid spr %d %03x at "
3894 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3895 printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx
"\n",
3896 sprn
, sprn
, ctx
->nip
);
3897 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3901 static void gen_mfspr(DisasContext
*ctx
)
3907 static void gen_mftb(DisasContext
*ctx
)
3913 static void gen_mtcrf(DisasContext
*ctx
)
3917 crm
= CRM(ctx
->opcode
);
3918 if (likely((ctx
->opcode
& 0x00100000))) {
3919 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
3920 TCGv_i32 temp
= tcg_temp_new_i32();
3922 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3923 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
3924 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
3925 tcg_temp_free_i32(temp
);
3928 TCGv_i32 temp
= tcg_temp_new_i32();
3929 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3930 for (crn
= 0 ; crn
< 8 ; crn
++) {
3931 if (crm
& (1 << crn
)) {
3932 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3933 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3936 tcg_temp_free_i32(temp
);
3941 #if defined(TARGET_PPC64)
3942 static void gen_mtmsrd(DisasContext
*ctx
)
3944 #if defined(CONFIG_USER_ONLY)
3945 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3947 if (unlikely(!ctx
->mem_idx
)) {
3948 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3951 if (ctx
->opcode
& 0x00010000) {
3952 /* Special form that does not need any synchronisation */
3953 TCGv t0
= tcg_temp_new();
3954 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3955 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3956 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3959 /* XXX: we need to update nip before the store
3960 * if we enter power saving mode, we will exit the loop
3961 * directly from ppc_store_msr
3963 gen_update_nip(ctx
, ctx
->nip
);
3964 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
3965 /* Must stop the translation as machine state (may have) changed */
3966 /* Note that mtmsr is not always defined as context-synchronizing */
3967 gen_stop_exception(ctx
);
3973 static void gen_mtmsr(DisasContext
*ctx
)
3975 #if defined(CONFIG_USER_ONLY)
3976 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3978 if (unlikely(!ctx
->mem_idx
)) {
3979 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3982 if (ctx
->opcode
& 0x00010000) {
3983 /* Special form that does not need any synchronisation */
3984 TCGv t0
= tcg_temp_new();
3985 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3986 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3987 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3990 TCGv msr
= tcg_temp_new();
3992 /* XXX: we need to update nip before the store
3993 * if we enter power saving mode, we will exit the loop
3994 * directly from ppc_store_msr
3996 gen_update_nip(ctx
, ctx
->nip
);
3997 #if defined(TARGET_PPC64)
3998 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4000 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4002 gen_helper_store_msr(cpu_env
, msr
);
4003 /* Must stop the translation as machine state (may have) changed */
4004 /* Note that mtmsr is not always defined as context-synchronizing */
4005 gen_stop_exception(ctx
);
4011 static void gen_mtspr(DisasContext
*ctx
)
4013 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
4014 uint32_t sprn
= SPR(ctx
->opcode
);
4016 #if !defined(CONFIG_USER_ONLY)
4017 if (ctx
->mem_idx
== 2)
4018 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4019 else if (ctx
->mem_idx
)
4020 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4023 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4024 if (likely(write_cb
!= NULL
)) {
4025 if (likely(write_cb
!= SPR_NOACCESS
)) {
4026 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4028 /* Privilege exception */
4029 qemu_log("Trying to write privileged spr %d %03x at "
4030 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
4031 printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx
4032 "\n", sprn
, sprn
, ctx
->nip
);
4033 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4037 qemu_log("Trying to write invalid spr %d %03x at "
4038 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
4039 printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx
"\n",
4040 sprn
, sprn
, ctx
->nip
);
4041 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4045 /*** Cache management ***/
4048 static void gen_dcbf(DisasContext
*ctx
)
4050 /* XXX: specification says this is treated as a load by the MMU */
4052 gen_set_access_type(ctx
, ACCESS_CACHE
);
4053 t0
= tcg_temp_new();
4054 gen_addr_reg_index(ctx
, t0
);
4055 gen_qemu_ld8u(ctx
, t0
, t0
);
4059 /* dcbi (Supervisor only) */
4060 static void gen_dcbi(DisasContext
*ctx
)
4062 #if defined(CONFIG_USER_ONLY)
4063 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4066 if (unlikely(!ctx
->mem_idx
)) {
4067 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4070 EA
= tcg_temp_new();
4071 gen_set_access_type(ctx
, ACCESS_CACHE
);
4072 gen_addr_reg_index(ctx
, EA
);
4073 val
= tcg_temp_new();
4074 /* XXX: specification says this should be treated as a store by the MMU */
4075 gen_qemu_ld8u(ctx
, val
, EA
);
4076 gen_qemu_st8(ctx
, val
, EA
);
4083 static void gen_dcbst(DisasContext
*ctx
)
4085 /* XXX: specification say this is treated as a load by the MMU */
4087 gen_set_access_type(ctx
, ACCESS_CACHE
);
4088 t0
= tcg_temp_new();
4089 gen_addr_reg_index(ctx
, t0
);
4090 gen_qemu_ld8u(ctx
, t0
, t0
);
4095 static void gen_dcbt(DisasContext
*ctx
)
4097 /* interpreted as no-op */
4098 /* XXX: specification say this is treated as a load by the MMU
4099 * but does not generate any exception
4104 static void gen_dcbtst(DisasContext
*ctx
)
4106 /* interpreted as no-op */
4107 /* XXX: specification say this is treated as a load by the MMU
4108 * but does not generate any exception
4113 static void gen_dcbz(DisasContext
*ctx
)
4116 TCGv_i32 tcgv_is_dcbzl
;
4117 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4119 gen_set_access_type(ctx
, ACCESS_CACHE
);
4120 /* NIP cannot be restored if the memory exception comes from an helper */
4121 gen_update_nip(ctx
, ctx
->nip
- 4);
4122 tcgv_addr
= tcg_temp_new();
4123 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4125 gen_addr_reg_index(ctx
, tcgv_addr
);
4126 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4128 tcg_temp_free(tcgv_addr
);
4129 tcg_temp_free_i32(tcgv_is_dcbzl
);
4133 static void gen_dst(DisasContext
*ctx
)
4135 if (rA(ctx
->opcode
) == 0) {
4136 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4138 /* interpreted as no-op */
4143 static void gen_dstst(DisasContext
*ctx
)
4145 if (rA(ctx
->opcode
) == 0) {
4146 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4148 /* interpreted as no-op */
4154 static void gen_dss(DisasContext
*ctx
)
4156 /* interpreted as no-op */
4160 static void gen_icbi(DisasContext
*ctx
)
4163 gen_set_access_type(ctx
, ACCESS_CACHE
);
4164 /* NIP cannot be restored if the memory exception comes from an helper */
4165 gen_update_nip(ctx
, ctx
->nip
- 4);
4166 t0
= tcg_temp_new();
4167 gen_addr_reg_index(ctx
, t0
);
4168 gen_helper_icbi(cpu_env
, t0
);
4174 static void gen_dcba(DisasContext
*ctx
)
4176 /* interpreted as no-op */
4177 /* XXX: specification say this is treated as a store by the MMU
4178 * but does not generate any exception
4182 /*** Segment register manipulation ***/
4183 /* Supervisor only: */
4186 static void gen_mfsr(DisasContext
*ctx
)
4188 #if defined(CONFIG_USER_ONLY)
4189 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4192 if (unlikely(!ctx
->mem_idx
)) {
4193 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4196 t0
= tcg_const_tl(SR(ctx
->opcode
));
4197 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4203 static void gen_mfsrin(DisasContext
*ctx
)
4205 #if defined(CONFIG_USER_ONLY)
4206 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4209 if (unlikely(!ctx
->mem_idx
)) {
4210 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4213 t0
= tcg_temp_new();
4214 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4215 tcg_gen_andi_tl(t0
, t0
, 0xF);
4216 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4222 static void gen_mtsr(DisasContext
*ctx
)
4224 #if defined(CONFIG_USER_ONLY)
4225 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4228 if (unlikely(!ctx
->mem_idx
)) {
4229 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4232 t0
= tcg_const_tl(SR(ctx
->opcode
));
4233 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4239 static void gen_mtsrin(DisasContext
*ctx
)
4241 #if defined(CONFIG_USER_ONLY)
4242 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4245 if (unlikely(!ctx
->mem_idx
)) {
4246 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4249 t0
= tcg_temp_new();
4250 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4251 tcg_gen_andi_tl(t0
, t0
, 0xF);
4252 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4257 #if defined(TARGET_PPC64)
4258 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4261 static void gen_mfsr_64b(DisasContext
*ctx
)
4263 #if defined(CONFIG_USER_ONLY)
4264 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4267 if (unlikely(!ctx
->mem_idx
)) {
4268 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4271 t0
= tcg_const_tl(SR(ctx
->opcode
));
4272 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4278 static void gen_mfsrin_64b(DisasContext
*ctx
)
4280 #if defined(CONFIG_USER_ONLY)
4281 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4284 if (unlikely(!ctx
->mem_idx
)) {
4285 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4288 t0
= tcg_temp_new();
4289 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4290 tcg_gen_andi_tl(t0
, t0
, 0xF);
4291 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4297 static void gen_mtsr_64b(DisasContext
*ctx
)
4299 #if defined(CONFIG_USER_ONLY)
4300 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4303 if (unlikely(!ctx
->mem_idx
)) {
4304 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4307 t0
= tcg_const_tl(SR(ctx
->opcode
));
4308 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4314 static void gen_mtsrin_64b(DisasContext
*ctx
)
4316 #if defined(CONFIG_USER_ONLY)
4317 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4320 if (unlikely(!ctx
->mem_idx
)) {
4321 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4324 t0
= tcg_temp_new();
4325 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4326 tcg_gen_andi_tl(t0
, t0
, 0xF);
4327 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4333 static void gen_slbmte(DisasContext
*ctx
)
4335 #if defined(CONFIG_USER_ONLY)
4336 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4338 if (unlikely(!ctx
->mem_idx
)) {
4339 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4342 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4343 cpu_gpr
[rS(ctx
->opcode
)]);
4347 static void gen_slbmfee(DisasContext
*ctx
)
4349 #if defined(CONFIG_USER_ONLY)
4350 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4352 if (unlikely(!ctx
->mem_idx
)) {
4353 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4356 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4357 cpu_gpr
[rB(ctx
->opcode
)]);
4361 static void gen_slbmfev(DisasContext
*ctx
)
4363 #if defined(CONFIG_USER_ONLY)
4364 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4366 if (unlikely(!ctx
->mem_idx
)) {
4367 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4370 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4371 cpu_gpr
[rB(ctx
->opcode
)]);
4374 #endif /* defined(TARGET_PPC64) */
4376 /*** Lookaside buffer management ***/
4377 /* Optional & mem_idx only: */
4380 static void gen_tlbia(DisasContext
*ctx
)
4382 #if defined(CONFIG_USER_ONLY)
4383 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4385 if (unlikely(!ctx
->mem_idx
)) {
4386 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4389 gen_helper_tlbia(cpu_env
);
4394 static void gen_tlbiel(DisasContext
*ctx
)
4396 #if defined(CONFIG_USER_ONLY)
4397 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4399 if (unlikely(!ctx
->mem_idx
)) {
4400 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4403 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4408 static void gen_tlbie(DisasContext
*ctx
)
4410 #if defined(CONFIG_USER_ONLY)
4411 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4413 if (unlikely(!ctx
->mem_idx
)) {
4414 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4417 #if defined(TARGET_PPC64)
4418 if (!ctx
->sf_mode
) {
4419 TCGv t0
= tcg_temp_new();
4420 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4421 gen_helper_tlbie(cpu_env
, t0
);
4425 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4430 static void gen_tlbsync(DisasContext
*ctx
)
4432 #if defined(CONFIG_USER_ONLY)
4433 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4435 if (unlikely(!ctx
->mem_idx
)) {
4436 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4439 /* This has no effect: it should ensure that all previous
4440 * tlbie have completed
4442 gen_stop_exception(ctx
);
4446 #if defined(TARGET_PPC64)
4448 static void gen_slbia(DisasContext
*ctx
)
4450 #if defined(CONFIG_USER_ONLY)
4451 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4453 if (unlikely(!ctx
->mem_idx
)) {
4454 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4457 gen_helper_slbia(cpu_env
);
4462 static void gen_slbie(DisasContext
*ctx
)
4464 #if defined(CONFIG_USER_ONLY)
4465 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4467 if (unlikely(!ctx
->mem_idx
)) {
4468 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4471 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4476 /*** External control ***/
4480 static void gen_eciwx(DisasContext
*ctx
)
4483 /* Should check EAR[E] ! */
4484 gen_set_access_type(ctx
, ACCESS_EXT
);
4485 t0
= tcg_temp_new();
4486 gen_addr_reg_index(ctx
, t0
);
4487 gen_check_align(ctx
, t0
, 0x03);
4488 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4493 static void gen_ecowx(DisasContext
*ctx
)
4496 /* Should check EAR[E] ! */
4497 gen_set_access_type(ctx
, ACCESS_EXT
);
4498 t0
= tcg_temp_new();
4499 gen_addr_reg_index(ctx
, t0
);
4500 gen_check_align(ctx
, t0
, 0x03);
4501 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4505 /* PowerPC 601 specific instructions */
4508 static void gen_abs(DisasContext
*ctx
)
4510 int l1
= gen_new_label();
4511 int l2
= gen_new_label();
4512 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4513 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4516 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4518 if (unlikely(Rc(ctx
->opcode
) != 0))
4519 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4523 static void gen_abso(DisasContext
*ctx
)
4525 int l1
= gen_new_label();
4526 int l2
= gen_new_label();
4527 int l3
= gen_new_label();
4528 /* Start with XER OV disabled, the most likely case */
4529 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4530 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4531 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4532 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4535 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4538 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4540 if (unlikely(Rc(ctx
->opcode
) != 0))
4541 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4545 static void gen_clcs(DisasContext
*ctx
)
4547 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4548 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4549 tcg_temp_free_i32(t0
);
4550 /* Rc=1 sets CR0 to an undefined state */
4554 static void gen_div(DisasContext
*ctx
)
4556 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4557 cpu_gpr
[rB(ctx
->opcode
)]);
4558 if (unlikely(Rc(ctx
->opcode
) != 0))
4559 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4563 static void gen_divo(DisasContext
*ctx
)
4565 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4566 cpu_gpr
[rB(ctx
->opcode
)]);
4567 if (unlikely(Rc(ctx
->opcode
) != 0))
4568 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4572 static void gen_divs(DisasContext
*ctx
)
4574 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4575 cpu_gpr
[rB(ctx
->opcode
)]);
4576 if (unlikely(Rc(ctx
->opcode
) != 0))
4577 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4580 /* divso - divso. */
4581 static void gen_divso(DisasContext
*ctx
)
4583 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4584 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4585 if (unlikely(Rc(ctx
->opcode
) != 0))
4586 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4590 static void gen_doz(DisasContext
*ctx
)
4592 int l1
= gen_new_label();
4593 int l2
= gen_new_label();
4594 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4595 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4598 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4600 if (unlikely(Rc(ctx
->opcode
) != 0))
4601 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4605 static void gen_dozo(DisasContext
*ctx
)
4607 int l1
= gen_new_label();
4608 int l2
= gen_new_label();
4609 TCGv t0
= tcg_temp_new();
4610 TCGv t1
= tcg_temp_new();
4611 TCGv t2
= tcg_temp_new();
4612 /* Start with XER OV disabled, the most likely case */
4613 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4614 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4615 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4616 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4617 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4618 tcg_gen_andc_tl(t1
, t1
, t2
);
4619 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4620 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4621 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4624 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4629 if (unlikely(Rc(ctx
->opcode
) != 0))
4630 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4634 static void gen_dozi(DisasContext
*ctx
)
4636 target_long simm
= SIMM(ctx
->opcode
);
4637 int l1
= gen_new_label();
4638 int l2
= gen_new_label();
4639 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4640 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4643 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4645 if (unlikely(Rc(ctx
->opcode
) != 0))
4646 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4649 /* lscbx - lscbx. */
4650 static void gen_lscbx(DisasContext
*ctx
)
4652 TCGv t0
= tcg_temp_new();
4653 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4654 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4655 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4657 gen_addr_reg_index(ctx
, t0
);
4658 /* NIP cannot be restored if the memory exception comes from an helper */
4659 gen_update_nip(ctx
, ctx
->nip
- 4);
4660 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4661 tcg_temp_free_i32(t1
);
4662 tcg_temp_free_i32(t2
);
4663 tcg_temp_free_i32(t3
);
4664 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4665 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4666 if (unlikely(Rc(ctx
->opcode
) != 0))
4667 gen_set_Rc0(ctx
, t0
);
4671 /* maskg - maskg. */
4672 static void gen_maskg(DisasContext
*ctx
)
4674 int l1
= gen_new_label();
4675 TCGv t0
= tcg_temp_new();
4676 TCGv t1
= tcg_temp_new();
4677 TCGv t2
= tcg_temp_new();
4678 TCGv t3
= tcg_temp_new();
4679 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4680 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4681 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4682 tcg_gen_addi_tl(t2
, t0
, 1);
4683 tcg_gen_shr_tl(t2
, t3
, t2
);
4684 tcg_gen_shr_tl(t3
, t3
, t1
);
4685 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4686 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4687 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4693 if (unlikely(Rc(ctx
->opcode
) != 0))
4694 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4697 /* maskir - maskir. */
4698 static void gen_maskir(DisasContext
*ctx
)
4700 TCGv t0
= tcg_temp_new();
4701 TCGv t1
= tcg_temp_new();
4702 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4703 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4704 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4707 if (unlikely(Rc(ctx
->opcode
) != 0))
4708 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4712 static void gen_mul(DisasContext
*ctx
)
4714 TCGv_i64 t0
= tcg_temp_new_i64();
4715 TCGv_i64 t1
= tcg_temp_new_i64();
4716 TCGv t2
= tcg_temp_new();
4717 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4718 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4719 tcg_gen_mul_i64(t0
, t0
, t1
);
4720 tcg_gen_trunc_i64_tl(t2
, t0
);
4721 gen_store_spr(SPR_MQ
, t2
);
4722 tcg_gen_shri_i64(t1
, t0
, 32);
4723 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4724 tcg_temp_free_i64(t0
);
4725 tcg_temp_free_i64(t1
);
4727 if (unlikely(Rc(ctx
->opcode
) != 0))
4728 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4732 static void gen_mulo(DisasContext
*ctx
)
4734 int l1
= gen_new_label();
4735 TCGv_i64 t0
= tcg_temp_new_i64();
4736 TCGv_i64 t1
= tcg_temp_new_i64();
4737 TCGv t2
= tcg_temp_new();
4738 /* Start with XER OV disabled, the most likely case */
4739 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4740 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4741 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4742 tcg_gen_mul_i64(t0
, t0
, t1
);
4743 tcg_gen_trunc_i64_tl(t2
, t0
);
4744 gen_store_spr(SPR_MQ
, t2
);
4745 tcg_gen_shri_i64(t1
, t0
, 32);
4746 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4747 tcg_gen_ext32s_i64(t1
, t0
);
4748 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4749 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4751 tcg_temp_free_i64(t0
);
4752 tcg_temp_free_i64(t1
);
4754 if (unlikely(Rc(ctx
->opcode
) != 0))
4755 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4759 static void gen_nabs(DisasContext
*ctx
)
4761 int l1
= gen_new_label();
4762 int l2
= gen_new_label();
4763 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4764 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4767 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4769 if (unlikely(Rc(ctx
->opcode
) != 0))
4770 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4773 /* nabso - nabso. */
4774 static void gen_nabso(DisasContext
*ctx
)
4776 int l1
= gen_new_label();
4777 int l2
= gen_new_label();
4778 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4779 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4782 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4784 /* nabs never overflows */
4785 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4786 if (unlikely(Rc(ctx
->opcode
) != 0))
4787 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4791 static void gen_rlmi(DisasContext
*ctx
)
4793 uint32_t mb
= MB(ctx
->opcode
);
4794 uint32_t me
= ME(ctx
->opcode
);
4795 TCGv t0
= tcg_temp_new();
4796 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4797 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4798 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4799 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4800 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4802 if (unlikely(Rc(ctx
->opcode
) != 0))
4803 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4807 static void gen_rrib(DisasContext
*ctx
)
4809 TCGv t0
= tcg_temp_new();
4810 TCGv t1
= tcg_temp_new();
4811 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4812 tcg_gen_movi_tl(t1
, 0x80000000);
4813 tcg_gen_shr_tl(t1
, t1
, t0
);
4814 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4815 tcg_gen_and_tl(t0
, t0
, t1
);
4816 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4817 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4820 if (unlikely(Rc(ctx
->opcode
) != 0))
4821 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4825 static void gen_sle(DisasContext
*ctx
)
4827 TCGv t0
= tcg_temp_new();
4828 TCGv t1
= tcg_temp_new();
4829 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4830 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4831 tcg_gen_subfi_tl(t1
, 32, t1
);
4832 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4833 tcg_gen_or_tl(t1
, t0
, t1
);
4834 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4835 gen_store_spr(SPR_MQ
, t1
);
4838 if (unlikely(Rc(ctx
->opcode
) != 0))
4839 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4843 static void gen_sleq(DisasContext
*ctx
)
4845 TCGv t0
= tcg_temp_new();
4846 TCGv t1
= tcg_temp_new();
4847 TCGv t2
= tcg_temp_new();
4848 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4849 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4850 tcg_gen_shl_tl(t2
, t2
, t0
);
4851 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4852 gen_load_spr(t1
, SPR_MQ
);
4853 gen_store_spr(SPR_MQ
, t0
);
4854 tcg_gen_and_tl(t0
, t0
, t2
);
4855 tcg_gen_andc_tl(t1
, t1
, t2
);
4856 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4860 if (unlikely(Rc(ctx
->opcode
) != 0))
4861 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4865 static void gen_sliq(DisasContext
*ctx
)
4867 int sh
= SH(ctx
->opcode
);
4868 TCGv t0
= tcg_temp_new();
4869 TCGv t1
= tcg_temp_new();
4870 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4871 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4872 tcg_gen_or_tl(t1
, t0
, t1
);
4873 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4874 gen_store_spr(SPR_MQ
, t1
);
4877 if (unlikely(Rc(ctx
->opcode
) != 0))
4878 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4881 /* slliq - slliq. */
4882 static void gen_slliq(DisasContext
*ctx
)
4884 int sh
= SH(ctx
->opcode
);
4885 TCGv t0
= tcg_temp_new();
4886 TCGv t1
= tcg_temp_new();
4887 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4888 gen_load_spr(t1
, SPR_MQ
);
4889 gen_store_spr(SPR_MQ
, t0
);
4890 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
4891 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
4892 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4895 if (unlikely(Rc(ctx
->opcode
) != 0))
4896 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4900 static void gen_sllq(DisasContext
*ctx
)
4902 int l1
= gen_new_label();
4903 int l2
= gen_new_label();
4904 TCGv t0
= tcg_temp_local_new();
4905 TCGv t1
= tcg_temp_local_new();
4906 TCGv t2
= tcg_temp_local_new();
4907 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4908 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4909 tcg_gen_shl_tl(t1
, t1
, t2
);
4910 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4911 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4912 gen_load_spr(t0
, SPR_MQ
);
4913 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4916 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4917 gen_load_spr(t2
, SPR_MQ
);
4918 tcg_gen_andc_tl(t1
, t2
, t1
);
4919 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4924 if (unlikely(Rc(ctx
->opcode
) != 0))
4925 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4929 static void gen_slq(DisasContext
*ctx
)
4931 int l1
= gen_new_label();
4932 TCGv t0
= tcg_temp_new();
4933 TCGv t1
= tcg_temp_new();
4934 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4935 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4936 tcg_gen_subfi_tl(t1
, 32, t1
);
4937 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4938 tcg_gen_or_tl(t1
, t0
, t1
);
4939 gen_store_spr(SPR_MQ
, t1
);
4940 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4941 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4942 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4943 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
4947 if (unlikely(Rc(ctx
->opcode
) != 0))
4948 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4951 /* sraiq - sraiq. */
4952 static void gen_sraiq(DisasContext
*ctx
)
4954 int sh
= SH(ctx
->opcode
);
4955 int l1
= gen_new_label();
4956 TCGv t0
= tcg_temp_new();
4957 TCGv t1
= tcg_temp_new();
4958 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4959 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4960 tcg_gen_or_tl(t0
, t0
, t1
);
4961 gen_store_spr(SPR_MQ
, t0
);
4962 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4963 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4964 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
4965 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4967 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
4970 if (unlikely(Rc(ctx
->opcode
) != 0))
4971 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4975 static void gen_sraq(DisasContext
*ctx
)
4977 int l1
= gen_new_label();
4978 int l2
= gen_new_label();
4979 TCGv t0
= tcg_temp_new();
4980 TCGv t1
= tcg_temp_local_new();
4981 TCGv t2
= tcg_temp_local_new();
4982 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4983 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4984 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4985 tcg_gen_subfi_tl(t2
, 32, t2
);
4986 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4987 tcg_gen_or_tl(t0
, t0
, t2
);
4988 gen_store_spr(SPR_MQ
, t0
);
4989 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4990 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
4991 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
4992 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
4995 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
4996 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4997 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4998 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
4999 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
5003 if (unlikely(Rc(ctx
->opcode
) != 0))
5004 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5008 static void gen_sre(DisasContext
*ctx
)
5010 TCGv t0
= tcg_temp_new();
5011 TCGv t1
= tcg_temp_new();
5012 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5013 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5014 tcg_gen_subfi_tl(t1
, 32, t1
);
5015 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5016 tcg_gen_or_tl(t1
, t0
, t1
);
5017 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5018 gen_store_spr(SPR_MQ
, t1
);
5021 if (unlikely(Rc(ctx
->opcode
) != 0))
5022 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5026 static void gen_srea(DisasContext
*ctx
)
5028 TCGv t0
= tcg_temp_new();
5029 TCGv t1
= tcg_temp_new();
5030 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5031 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5032 gen_store_spr(SPR_MQ
, t0
);
5033 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5036 if (unlikely(Rc(ctx
->opcode
) != 0))
5037 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5041 static void gen_sreq(DisasContext
*ctx
)
5043 TCGv t0
= tcg_temp_new();
5044 TCGv t1
= tcg_temp_new();
5045 TCGv t2
= tcg_temp_new();
5046 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5047 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5048 tcg_gen_shr_tl(t1
, t1
, t0
);
5049 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5050 gen_load_spr(t2
, SPR_MQ
);
5051 gen_store_spr(SPR_MQ
, t0
);
5052 tcg_gen_and_tl(t0
, t0
, t1
);
5053 tcg_gen_andc_tl(t2
, t2
, t1
);
5054 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5058 if (unlikely(Rc(ctx
->opcode
) != 0))
5059 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5063 static void gen_sriq(DisasContext
*ctx
)
5065 int sh
= SH(ctx
->opcode
);
5066 TCGv t0
= tcg_temp_new();
5067 TCGv t1
= tcg_temp_new();
5068 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5069 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5070 tcg_gen_or_tl(t1
, t0
, t1
);
5071 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5072 gen_store_spr(SPR_MQ
, t1
);
5075 if (unlikely(Rc(ctx
->opcode
) != 0))
5076 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5080 static void gen_srliq(DisasContext
*ctx
)
5082 int sh
= SH(ctx
->opcode
);
5083 TCGv t0
= tcg_temp_new();
5084 TCGv t1
= tcg_temp_new();
5085 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5086 gen_load_spr(t1
, SPR_MQ
);
5087 gen_store_spr(SPR_MQ
, t0
);
5088 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5089 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5090 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5093 if (unlikely(Rc(ctx
->opcode
) != 0))
5094 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5098 static void gen_srlq(DisasContext
*ctx
)
5100 int l1
= gen_new_label();
5101 int l2
= gen_new_label();
5102 TCGv t0
= tcg_temp_local_new();
5103 TCGv t1
= tcg_temp_local_new();
5104 TCGv t2
= tcg_temp_local_new();
5105 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5106 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5107 tcg_gen_shr_tl(t2
, t1
, t2
);
5108 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5109 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5110 gen_load_spr(t0
, SPR_MQ
);
5111 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5114 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5115 tcg_gen_and_tl(t0
, t0
, t2
);
5116 gen_load_spr(t1
, SPR_MQ
);
5117 tcg_gen_andc_tl(t1
, t1
, t2
);
5118 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5123 if (unlikely(Rc(ctx
->opcode
) != 0))
5124 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5128 static void gen_srq(DisasContext
*ctx
)
5130 int l1
= gen_new_label();
5131 TCGv t0
= tcg_temp_new();
5132 TCGv t1
= tcg_temp_new();
5133 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5134 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5135 tcg_gen_subfi_tl(t1
, 32, t1
);
5136 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5137 tcg_gen_or_tl(t1
, t0
, t1
);
5138 gen_store_spr(SPR_MQ
, t1
);
5139 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5140 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5141 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5142 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5146 if (unlikely(Rc(ctx
->opcode
) != 0))
5147 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5150 /* PowerPC 602 specific instructions */
5153 static void gen_dsa(DisasContext
*ctx
)
5156 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5160 static void gen_esa(DisasContext
*ctx
)
5163 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5167 static void gen_mfrom(DisasContext
*ctx
)
5169 #if defined(CONFIG_USER_ONLY)
5170 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5172 if (unlikely(!ctx
->mem_idx
)) {
5173 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5176 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5180 /* 602 - 603 - G2 TLB management */
5183 static void gen_tlbld_6xx(DisasContext
*ctx
)
5185 #if defined(CONFIG_USER_ONLY)
5186 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5188 if (unlikely(!ctx
->mem_idx
)) {
5189 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5192 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5197 static void gen_tlbli_6xx(DisasContext
*ctx
)
5199 #if defined(CONFIG_USER_ONLY)
5200 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5202 if (unlikely(!ctx
->mem_idx
)) {
5203 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5206 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5210 /* 74xx TLB management */
5213 static void gen_tlbld_74xx(DisasContext
*ctx
)
5215 #if defined(CONFIG_USER_ONLY)
5216 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5218 if (unlikely(!ctx
->mem_idx
)) {
5219 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5222 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5227 static void gen_tlbli_74xx(DisasContext
*ctx
)
5229 #if defined(CONFIG_USER_ONLY)
5230 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5232 if (unlikely(!ctx
->mem_idx
)) {
5233 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5236 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5240 /* POWER instructions not in PowerPC 601 */
5243 static void gen_clf(DisasContext
*ctx
)
5245 /* Cache line flush: implemented as no-op */
5249 static void gen_cli(DisasContext
*ctx
)
5251 /* Cache line invalidate: privileged and treated as no-op */
5252 #if defined(CONFIG_USER_ONLY)
5253 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5255 if (unlikely(!ctx
->mem_idx
)) {
5256 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5263 static void gen_dclst(DisasContext
*ctx
)
5265 /* Data cache line store: treated as no-op */
5268 static void gen_mfsri(DisasContext
*ctx
)
5270 #if defined(CONFIG_USER_ONLY)
5271 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5273 int ra
= rA(ctx
->opcode
);
5274 int rd
= rD(ctx
->opcode
);
5276 if (unlikely(!ctx
->mem_idx
)) {
5277 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5280 t0
= tcg_temp_new();
5281 gen_addr_reg_index(ctx
, t0
);
5282 tcg_gen_shri_tl(t0
, t0
, 28);
5283 tcg_gen_andi_tl(t0
, t0
, 0xF);
5284 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5286 if (ra
!= 0 && ra
!= rd
)
5287 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5291 static void gen_rac(DisasContext
*ctx
)
5293 #if defined(CONFIG_USER_ONLY)
5294 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5297 if (unlikely(!ctx
->mem_idx
)) {
5298 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5301 t0
= tcg_temp_new();
5302 gen_addr_reg_index(ctx
, t0
);
5303 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5308 static void gen_rfsvc(DisasContext
*ctx
)
5310 #if defined(CONFIG_USER_ONLY)
5311 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5313 if (unlikely(!ctx
->mem_idx
)) {
5314 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5317 gen_helper_rfsvc(cpu_env
);
5318 gen_sync_exception(ctx
);
5322 /* svc is not implemented for now */
5324 /* POWER2 specific instructions */
5325 /* Quad manipulation (load/store two floats at a time) */
5328 static void gen_lfq(DisasContext
*ctx
)
5330 int rd
= rD(ctx
->opcode
);
5332 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5333 t0
= tcg_temp_new();
5334 gen_addr_imm_index(ctx
, t0
, 0);
5335 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5336 gen_addr_add(ctx
, t0
, t0
, 8);
5337 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5342 static void gen_lfqu(DisasContext
*ctx
)
5344 int ra
= rA(ctx
->opcode
);
5345 int rd
= rD(ctx
->opcode
);
5347 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5348 t0
= tcg_temp_new();
5349 t1
= tcg_temp_new();
5350 gen_addr_imm_index(ctx
, t0
, 0);
5351 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5352 gen_addr_add(ctx
, t1
, t0
, 8);
5353 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5355 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5361 static void gen_lfqux(DisasContext
*ctx
)
5363 int ra
= rA(ctx
->opcode
);
5364 int rd
= rD(ctx
->opcode
);
5365 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5367 t0
= tcg_temp_new();
5368 gen_addr_reg_index(ctx
, t0
);
5369 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5370 t1
= tcg_temp_new();
5371 gen_addr_add(ctx
, t1
, t0
, 8);
5372 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5375 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5380 static void gen_lfqx(DisasContext
*ctx
)
5382 int rd
= rD(ctx
->opcode
);
5384 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5385 t0
= tcg_temp_new();
5386 gen_addr_reg_index(ctx
, t0
);
5387 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5388 gen_addr_add(ctx
, t0
, t0
, 8);
5389 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5394 static void gen_stfq(DisasContext
*ctx
)
5396 int rd
= rD(ctx
->opcode
);
5398 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5399 t0
= tcg_temp_new();
5400 gen_addr_imm_index(ctx
, t0
, 0);
5401 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5402 gen_addr_add(ctx
, t0
, t0
, 8);
5403 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5408 static void gen_stfqu(DisasContext
*ctx
)
5410 int ra
= rA(ctx
->opcode
);
5411 int rd
= rD(ctx
->opcode
);
5413 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5414 t0
= tcg_temp_new();
5415 gen_addr_imm_index(ctx
, t0
, 0);
5416 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5417 t1
= tcg_temp_new();
5418 gen_addr_add(ctx
, t1
, t0
, 8);
5419 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5422 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5427 static void gen_stfqux(DisasContext
*ctx
)
5429 int ra
= rA(ctx
->opcode
);
5430 int rd
= rD(ctx
->opcode
);
5432 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5433 t0
= tcg_temp_new();
5434 gen_addr_reg_index(ctx
, t0
);
5435 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5436 t1
= tcg_temp_new();
5437 gen_addr_add(ctx
, t1
, t0
, 8);
5438 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5441 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5446 static void gen_stfqx(DisasContext
*ctx
)
5448 int rd
= rD(ctx
->opcode
);
5450 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5451 t0
= tcg_temp_new();
5452 gen_addr_reg_index(ctx
, t0
);
5453 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5454 gen_addr_add(ctx
, t0
, t0
, 8);
5455 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5459 /* BookE specific instructions */
5461 /* XXX: not implemented on 440 ? */
5462 static void gen_mfapidi(DisasContext
*ctx
)
5465 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5468 /* XXX: not implemented on 440 ? */
5469 static void gen_tlbiva(DisasContext
*ctx
)
5471 #if defined(CONFIG_USER_ONLY)
5472 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5475 if (unlikely(!ctx
->mem_idx
)) {
5476 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5479 t0
= tcg_temp_new();
5480 gen_addr_reg_index(ctx
, t0
);
5481 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5486 /* All 405 MAC instructions are translated here */
5487 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5488 int ra
, int rb
, int rt
, int Rc
)
5492 t0
= tcg_temp_local_new();
5493 t1
= tcg_temp_local_new();
5495 switch (opc3
& 0x0D) {
5497 /* macchw - macchw. - macchwo - macchwo. */
5498 /* macchws - macchws. - macchwso - macchwso. */
5499 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5500 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5501 /* mulchw - mulchw. */
5502 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5503 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5504 tcg_gen_ext16s_tl(t1
, t1
);
5507 /* macchwu - macchwu. - macchwuo - macchwuo. */
5508 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5509 /* mulchwu - mulchwu. */
5510 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5511 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5512 tcg_gen_ext16u_tl(t1
, t1
);
5515 /* machhw - machhw. - machhwo - machhwo. */
5516 /* machhws - machhws. - machhwso - machhwso. */
5517 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5518 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5519 /* mulhhw - mulhhw. */
5520 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5521 tcg_gen_ext16s_tl(t0
, t0
);
5522 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5523 tcg_gen_ext16s_tl(t1
, t1
);
5526 /* machhwu - machhwu. - machhwuo - machhwuo. */
5527 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5528 /* mulhhwu - mulhhwu. */
5529 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5530 tcg_gen_ext16u_tl(t0
, t0
);
5531 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5532 tcg_gen_ext16u_tl(t1
, t1
);
5535 /* maclhw - maclhw. - maclhwo - maclhwo. */
5536 /* maclhws - maclhws. - maclhwso - maclhwso. */
5537 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5538 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5539 /* mullhw - mullhw. */
5540 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5541 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5544 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5545 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5546 /* mullhwu - mullhwu. */
5547 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5548 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5552 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5553 tcg_gen_mul_tl(t1
, t0
, t1
);
5555 /* nmultiply-and-accumulate (0x0E) */
5556 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5558 /* multiply-and-accumulate (0x0C) */
5559 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5563 /* Check overflow and/or saturate */
5564 int l1
= gen_new_label();
5567 /* Start with XER OV disabled, the most likely case */
5568 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
5572 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5573 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5574 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5575 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5578 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5579 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5583 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5586 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5590 /* Check overflow */
5591 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
5594 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5597 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5601 if (unlikely(Rc
) != 0) {
5603 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5607 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5608 static void glue(gen_, name)(DisasContext *ctx) \
5610 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5611 rD(ctx->opcode), Rc(ctx->opcode)); \
5614 /* macchw - macchw. */
5615 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5616 /* macchwo - macchwo. */
5617 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5618 /* macchws - macchws. */
5619 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5620 /* macchwso - macchwso. */
5621 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5622 /* macchwsu - macchwsu. */
5623 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5624 /* macchwsuo - macchwsuo. */
5625 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5626 /* macchwu - macchwu. */
5627 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5628 /* macchwuo - macchwuo. */
5629 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5630 /* machhw - machhw. */
5631 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5632 /* machhwo - machhwo. */
5633 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5634 /* machhws - machhws. */
5635 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5636 /* machhwso - machhwso. */
5637 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5638 /* machhwsu - machhwsu. */
5639 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5640 /* machhwsuo - machhwsuo. */
5641 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5642 /* machhwu - machhwu. */
5643 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5644 /* machhwuo - machhwuo. */
5645 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5646 /* maclhw - maclhw. */
5647 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5648 /* maclhwo - maclhwo. */
5649 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5650 /* maclhws - maclhws. */
5651 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5652 /* maclhwso - maclhwso. */
5653 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5654 /* maclhwu - maclhwu. */
5655 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5656 /* maclhwuo - maclhwuo. */
5657 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5658 /* maclhwsu - maclhwsu. */
5659 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5660 /* maclhwsuo - maclhwsuo. */
5661 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5662 /* nmacchw - nmacchw. */
5663 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5664 /* nmacchwo - nmacchwo. */
5665 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5666 /* nmacchws - nmacchws. */
5667 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5668 /* nmacchwso - nmacchwso. */
5669 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5670 /* nmachhw - nmachhw. */
5671 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5672 /* nmachhwo - nmachhwo. */
5673 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5674 /* nmachhws - nmachhws. */
5675 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5676 /* nmachhwso - nmachhwso. */
5677 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5678 /* nmaclhw - nmaclhw. */
5679 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5680 /* nmaclhwo - nmaclhwo. */
5681 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5682 /* nmaclhws - nmaclhws. */
5683 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5684 /* nmaclhwso - nmaclhwso. */
5685 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5687 /* mulchw - mulchw. */
5688 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5689 /* mulchwu - mulchwu. */
5690 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5691 /* mulhhw - mulhhw. */
5692 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5693 /* mulhhwu - mulhhwu. */
5694 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5695 /* mullhw - mullhw. */
5696 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5697 /* mullhwu - mullhwu. */
5698 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5701 static void gen_mfdcr(DisasContext
*ctx
)
5703 #if defined(CONFIG_USER_ONLY)
5704 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5707 if (unlikely(!ctx
->mem_idx
)) {
5708 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5711 /* NIP cannot be restored if the memory exception comes from an helper */
5712 gen_update_nip(ctx
, ctx
->nip
- 4);
5713 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5714 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5715 tcg_temp_free(dcrn
);
5720 static void gen_mtdcr(DisasContext
*ctx
)
5722 #if defined(CONFIG_USER_ONLY)
5723 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5726 if (unlikely(!ctx
->mem_idx
)) {
5727 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5730 /* NIP cannot be restored if the memory exception comes from an helper */
5731 gen_update_nip(ctx
, ctx
->nip
- 4);
5732 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5733 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5734 tcg_temp_free(dcrn
);
5739 /* XXX: not implemented on 440 ? */
5740 static void gen_mfdcrx(DisasContext
*ctx
)
5742 #if defined(CONFIG_USER_ONLY)
5743 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5745 if (unlikely(!ctx
->mem_idx
)) {
5746 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5749 /* NIP cannot be restored if the memory exception comes from an helper */
5750 gen_update_nip(ctx
, ctx
->nip
- 4);
5751 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5752 cpu_gpr
[rA(ctx
->opcode
)]);
5753 /* Note: Rc update flag set leads to undefined state of Rc0 */
5758 /* XXX: not implemented on 440 ? */
5759 static void gen_mtdcrx(DisasContext
*ctx
)
5761 #if defined(CONFIG_USER_ONLY)
5762 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5764 if (unlikely(!ctx
->mem_idx
)) {
5765 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5768 /* NIP cannot be restored if the memory exception comes from an helper */
5769 gen_update_nip(ctx
, ctx
->nip
- 4);
5770 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5771 cpu_gpr
[rS(ctx
->opcode
)]);
5772 /* Note: Rc update flag set leads to undefined state of Rc0 */
5776 /* mfdcrux (PPC 460) : user-mode access to DCR */
5777 static void gen_mfdcrux(DisasContext
*ctx
)
5779 /* NIP cannot be restored if the memory exception comes from an helper */
5780 gen_update_nip(ctx
, ctx
->nip
- 4);
5781 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5782 cpu_gpr
[rA(ctx
->opcode
)]);
5783 /* Note: Rc update flag set leads to undefined state of Rc0 */
5786 /* mtdcrux (PPC 460) : user-mode access to DCR */
5787 static void gen_mtdcrux(DisasContext
*ctx
)
5789 /* NIP cannot be restored if the memory exception comes from an helper */
5790 gen_update_nip(ctx
, ctx
->nip
- 4);
5791 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5792 cpu_gpr
[rS(ctx
->opcode
)]);
5793 /* Note: Rc update flag set leads to undefined state of Rc0 */
5797 static void gen_dccci(DisasContext
*ctx
)
5799 #if defined(CONFIG_USER_ONLY)
5800 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5802 if (unlikely(!ctx
->mem_idx
)) {
5803 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5806 /* interpreted as no-op */
5811 static void gen_dcread(DisasContext
*ctx
)
5813 #if defined(CONFIG_USER_ONLY)
5814 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5817 if (unlikely(!ctx
->mem_idx
)) {
5818 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5821 gen_set_access_type(ctx
, ACCESS_CACHE
);
5822 EA
= tcg_temp_new();
5823 gen_addr_reg_index(ctx
, EA
);
5824 val
= tcg_temp_new();
5825 gen_qemu_ld32u(ctx
, val
, EA
);
5827 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5833 static void gen_icbt_40x(DisasContext
*ctx
)
5835 /* interpreted as no-op */
5836 /* XXX: specification say this is treated as a load by the MMU
5837 * but does not generate any exception
5842 static void gen_iccci(DisasContext
*ctx
)
5844 #if defined(CONFIG_USER_ONLY)
5845 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5847 if (unlikely(!ctx
->mem_idx
)) {
5848 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5851 /* interpreted as no-op */
5856 static void gen_icread(DisasContext
*ctx
)
5858 #if defined(CONFIG_USER_ONLY)
5859 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5861 if (unlikely(!ctx
->mem_idx
)) {
5862 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5865 /* interpreted as no-op */
5869 /* rfci (mem_idx only) */
5870 static void gen_rfci_40x(DisasContext
*ctx
)
5872 #if defined(CONFIG_USER_ONLY)
5873 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5875 if (unlikely(!ctx
->mem_idx
)) {
5876 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5879 /* Restore CPU state */
5880 gen_helper_40x_rfci(cpu_env
);
5881 gen_sync_exception(ctx
);
5885 static void gen_rfci(DisasContext
*ctx
)
5887 #if defined(CONFIG_USER_ONLY)
5888 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5890 if (unlikely(!ctx
->mem_idx
)) {
5891 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5894 /* Restore CPU state */
5895 gen_helper_rfci(cpu_env
);
5896 gen_sync_exception(ctx
);
5900 /* BookE specific */
5902 /* XXX: not implemented on 440 ? */
5903 static void gen_rfdi(DisasContext
*ctx
)
5905 #if defined(CONFIG_USER_ONLY)
5906 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5908 if (unlikely(!ctx
->mem_idx
)) {
5909 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5912 /* Restore CPU state */
5913 gen_helper_rfdi(cpu_env
);
5914 gen_sync_exception(ctx
);
5918 /* XXX: not implemented on 440 ? */
5919 static void gen_rfmci(DisasContext
*ctx
)
5921 #if defined(CONFIG_USER_ONLY)
5922 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5924 if (unlikely(!ctx
->mem_idx
)) {
5925 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5928 /* Restore CPU state */
5929 gen_helper_rfmci(cpu_env
);
5930 gen_sync_exception(ctx
);
5934 /* TLB management - PowerPC 405 implementation */
5937 static void gen_tlbre_40x(DisasContext
*ctx
)
5939 #if defined(CONFIG_USER_ONLY)
5940 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5942 if (unlikely(!ctx
->mem_idx
)) {
5943 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5946 switch (rB(ctx
->opcode
)) {
5948 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5949 cpu_gpr
[rA(ctx
->opcode
)]);
5952 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5953 cpu_gpr
[rA(ctx
->opcode
)]);
5956 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5962 /* tlbsx - tlbsx. */
5963 static void gen_tlbsx_40x(DisasContext
*ctx
)
5965 #if defined(CONFIG_USER_ONLY)
5966 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5969 if (unlikely(!ctx
->mem_idx
)) {
5970 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5973 t0
= tcg_temp_new();
5974 gen_addr_reg_index(ctx
, t0
);
5975 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5977 if (Rc(ctx
->opcode
)) {
5978 int l1
= gen_new_label();
5979 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
5980 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
5981 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
5982 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5983 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5990 static void gen_tlbwe_40x(DisasContext
*ctx
)
5992 #if defined(CONFIG_USER_ONLY)
5993 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5995 if (unlikely(!ctx
->mem_idx
)) {
5996 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5999 switch (rB(ctx
->opcode
)) {
6001 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6002 cpu_gpr
[rS(ctx
->opcode
)]);
6005 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6006 cpu_gpr
[rS(ctx
->opcode
)]);
6009 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6015 /* TLB management - PowerPC 440 implementation */
6018 static void gen_tlbre_440(DisasContext
*ctx
)
6020 #if defined(CONFIG_USER_ONLY)
6021 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6023 if (unlikely(!ctx
->mem_idx
)) {
6024 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6027 switch (rB(ctx
->opcode
)) {
6032 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6033 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6034 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6035 tcg_temp_free_i32(t0
);
6039 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6045 /* tlbsx - tlbsx. */
6046 static void gen_tlbsx_440(DisasContext
*ctx
)
6048 #if defined(CONFIG_USER_ONLY)
6049 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6052 if (unlikely(!ctx
->mem_idx
)) {
6053 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6056 t0
= tcg_temp_new();
6057 gen_addr_reg_index(ctx
, t0
);
6058 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6060 if (Rc(ctx
->opcode
)) {
6061 int l1
= gen_new_label();
6062 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
6063 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
6064 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
6065 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6066 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6073 static void gen_tlbwe_440(DisasContext
*ctx
)
6075 #if defined(CONFIG_USER_ONLY)
6076 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6078 if (unlikely(!ctx
->mem_idx
)) {
6079 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6082 switch (rB(ctx
->opcode
)) {
6087 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6088 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6089 cpu_gpr
[rS(ctx
->opcode
)]);
6090 tcg_temp_free_i32(t0
);
6094 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6100 /* TLB management - PowerPC BookE 2.06 implementation */
6103 static void gen_tlbre_booke206(DisasContext
*ctx
)
6105 #if defined(CONFIG_USER_ONLY)
6106 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6108 if (unlikely(!ctx
->mem_idx
)) {
6109 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6113 gen_helper_booke206_tlbre(cpu_env
);
6117 /* tlbsx - tlbsx. */
6118 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6120 #if defined(CONFIG_USER_ONLY)
6121 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6124 if (unlikely(!ctx
->mem_idx
)) {
6125 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6129 if (rA(ctx
->opcode
)) {
6130 t0
= tcg_temp_new();
6131 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6133 t0
= tcg_const_tl(0);
6136 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6137 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6142 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6144 #if defined(CONFIG_USER_ONLY)
6145 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6147 if (unlikely(!ctx
->mem_idx
)) {
6148 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6151 gen_update_nip(ctx
, ctx
->nip
- 4);
6152 gen_helper_booke206_tlbwe(cpu_env
);
6156 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6158 #if defined(CONFIG_USER_ONLY)
6159 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6162 if (unlikely(!ctx
->mem_idx
)) {
6163 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6167 t0
= tcg_temp_new();
6168 gen_addr_reg_index(ctx
, t0
);
6170 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6174 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6176 #if defined(CONFIG_USER_ONLY)
6177 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6180 if (unlikely(!ctx
->mem_idx
)) {
6181 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6185 t0
= tcg_temp_new();
6186 gen_addr_reg_index(ctx
, t0
);
6188 switch((ctx
->opcode
>> 21) & 0x3) {
6190 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6193 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6196 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6199 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6209 static void gen_wrtee(DisasContext
*ctx
)
6211 #if defined(CONFIG_USER_ONLY)
6212 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6215 if (unlikely(!ctx
->mem_idx
)) {
6216 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6219 t0
= tcg_temp_new();
6220 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6221 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6222 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6224 /* Stop translation to have a chance to raise an exception
6225 * if we just set msr_ee to 1
6227 gen_stop_exception(ctx
);
6232 static void gen_wrteei(DisasContext
*ctx
)
6234 #if defined(CONFIG_USER_ONLY)
6235 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6237 if (unlikely(!ctx
->mem_idx
)) {
6238 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6241 if (ctx
->opcode
& 0x00008000) {
6242 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6243 /* Stop translation to have a chance to raise an exception */
6244 gen_stop_exception(ctx
);
6246 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6251 /* PowerPC 440 specific instructions */
6254 static void gen_dlmzb(DisasContext
*ctx
)
6256 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6257 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6258 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6259 tcg_temp_free_i32(t0
);
6262 /* mbar replaces eieio on 440 */
6263 static void gen_mbar(DisasContext
*ctx
)
6265 /* interpreted as no-op */
6268 /* msync replaces sync on 440 */
6269 static void gen_msync_4xx(DisasContext
*ctx
)
6271 /* interpreted as no-op */
6275 static void gen_icbt_440(DisasContext
*ctx
)
6277 /* interpreted as no-op */
6278 /* XXX: specification say this is treated as a load by the MMU
6279 * but does not generate any exception
6283 /* Embedded.Processor Control */
6285 static void gen_msgclr(DisasContext
*ctx
)
6287 #if defined(CONFIG_USER_ONLY)
6288 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6290 if (unlikely(ctx
->mem_idx
== 0)) {
6291 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6295 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6299 static void gen_msgsnd(DisasContext
*ctx
)
6301 #if defined(CONFIG_USER_ONLY)
6302 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6304 if (unlikely(ctx
->mem_idx
== 0)) {
6305 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6309 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6313 /*** Altivec vector extension ***/
6314 /* Altivec registers moves */
6316 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6318 TCGv_ptr r
= tcg_temp_new_ptr();
6319 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6323 #define GEN_VR_LDX(name, opc2, opc3) \
6324 static void glue(gen_, name)(DisasContext *ctx) \
6327 if (unlikely(!ctx->altivec_enabled)) { \
6328 gen_exception(ctx, POWERPC_EXCP_VPU); \
6331 gen_set_access_type(ctx, ACCESS_INT); \
6332 EA = tcg_temp_new(); \
6333 gen_addr_reg_index(ctx, EA); \
6334 tcg_gen_andi_tl(EA, EA, ~0xf); \
6335 if (ctx->le_mode) { \
6336 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6337 tcg_gen_addi_tl(EA, EA, 8); \
6338 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6340 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6341 tcg_gen_addi_tl(EA, EA, 8); \
6342 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6344 tcg_temp_free(EA); \
6347 #define GEN_VR_STX(name, opc2, opc3) \
6348 static void gen_st##name(DisasContext *ctx) \
6351 if (unlikely(!ctx->altivec_enabled)) { \
6352 gen_exception(ctx, POWERPC_EXCP_VPU); \
6355 gen_set_access_type(ctx, ACCESS_INT); \
6356 EA = tcg_temp_new(); \
6357 gen_addr_reg_index(ctx, EA); \
6358 tcg_gen_andi_tl(EA, EA, ~0xf); \
6359 if (ctx->le_mode) { \
6360 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6361 tcg_gen_addi_tl(EA, EA, 8); \
6362 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6364 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6365 tcg_gen_addi_tl(EA, EA, 8); \
6366 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6368 tcg_temp_free(EA); \
6371 #define GEN_VR_LVE(name, opc2, opc3) \
6372 static void gen_lve##name(DisasContext *ctx) \
6376 if (unlikely(!ctx->altivec_enabled)) { \
6377 gen_exception(ctx, POWERPC_EXCP_VPU); \
6380 gen_set_access_type(ctx, ACCESS_INT); \
6381 EA = tcg_temp_new(); \
6382 gen_addr_reg_index(ctx, EA); \
6383 rs = gen_avr_ptr(rS(ctx->opcode)); \
6384 gen_helper_lve##name(cpu_env, rs, EA); \
6385 tcg_temp_free(EA); \
6386 tcg_temp_free_ptr(rs); \
6389 #define GEN_VR_STVE(name, opc2, opc3) \
6390 static void gen_stve##name(DisasContext *ctx) \
6394 if (unlikely(!ctx->altivec_enabled)) { \
6395 gen_exception(ctx, POWERPC_EXCP_VPU); \
6398 gen_set_access_type(ctx, ACCESS_INT); \
6399 EA = tcg_temp_new(); \
6400 gen_addr_reg_index(ctx, EA); \
6401 rs = gen_avr_ptr(rS(ctx->opcode)); \
6402 gen_helper_stve##name(cpu_env, rs, EA); \
6403 tcg_temp_free(EA); \
6404 tcg_temp_free_ptr(rs); \
6407 GEN_VR_LDX(lvx
, 0x07, 0x03);
6408 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6409 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6411 GEN_VR_LVE(bx
, 0x07, 0x00);
6412 GEN_VR_LVE(hx
, 0x07, 0x01);
6413 GEN_VR_LVE(wx
, 0x07, 0x02);
6415 GEN_VR_STX(svx
, 0x07, 0x07);
6416 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6417 GEN_VR_STX(svxl
, 0x07, 0x0F);
6419 GEN_VR_STVE(bx
, 0x07, 0x04);
6420 GEN_VR_STVE(hx
, 0x07, 0x05);
6421 GEN_VR_STVE(wx
, 0x07, 0x06);
6423 static void gen_lvsl(DisasContext
*ctx
)
6427 if (unlikely(!ctx
->altivec_enabled
)) {
6428 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6431 EA
= tcg_temp_new();
6432 gen_addr_reg_index(ctx
, EA
);
6433 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6434 gen_helper_lvsl(rd
, EA
);
6436 tcg_temp_free_ptr(rd
);
6439 static void gen_lvsr(DisasContext
*ctx
)
6443 if (unlikely(!ctx
->altivec_enabled
)) {
6444 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6447 EA
= tcg_temp_new();
6448 gen_addr_reg_index(ctx
, EA
);
6449 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6450 gen_helper_lvsr(rd
, EA
);
6452 tcg_temp_free_ptr(rd
);
6455 static void gen_mfvscr(DisasContext
*ctx
)
6458 if (unlikely(!ctx
->altivec_enabled
)) {
6459 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6462 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6463 t
= tcg_temp_new_i32();
6464 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6465 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6466 tcg_temp_free_i32(t
);
6469 static void gen_mtvscr(DisasContext
*ctx
)
6472 if (unlikely(!ctx
->altivec_enabled
)) {
6473 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6476 p
= gen_avr_ptr(rD(ctx
->opcode
));
6477 gen_helper_mtvscr(cpu_env
, p
);
6478 tcg_temp_free_ptr(p
);
6481 /* Logical operations */
6482 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6483 static void glue(gen_, name)(DisasContext *ctx) \
6485 if (unlikely(!ctx->altivec_enabled)) { \
6486 gen_exception(ctx, POWERPC_EXCP_VPU); \
6489 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6490 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6493 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6494 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6495 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6496 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6497 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6499 #define GEN_VXFORM(name, opc2, opc3) \
6500 static void glue(gen_, name)(DisasContext *ctx) \
6502 TCGv_ptr ra, rb, rd; \
6503 if (unlikely(!ctx->altivec_enabled)) { \
6504 gen_exception(ctx, POWERPC_EXCP_VPU); \
6507 ra = gen_avr_ptr(rA(ctx->opcode)); \
6508 rb = gen_avr_ptr(rB(ctx->opcode)); \
6509 rd = gen_avr_ptr(rD(ctx->opcode)); \
6510 gen_helper_##name (rd, ra, rb); \
6511 tcg_temp_free_ptr(ra); \
6512 tcg_temp_free_ptr(rb); \
6513 tcg_temp_free_ptr(rd); \
6516 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6517 static void glue(gen_, name)(DisasContext *ctx) \
6519 TCGv_ptr ra, rb, rd; \
6520 if (unlikely(!ctx->altivec_enabled)) { \
6521 gen_exception(ctx, POWERPC_EXCP_VPU); \
6524 ra = gen_avr_ptr(rA(ctx->opcode)); \
6525 rb = gen_avr_ptr(rB(ctx->opcode)); \
6526 rd = gen_avr_ptr(rD(ctx->opcode)); \
6527 gen_helper_##name(cpu_env, rd, ra, rb); \
6528 tcg_temp_free_ptr(ra); \
6529 tcg_temp_free_ptr(rb); \
6530 tcg_temp_free_ptr(rd); \
6533 GEN_VXFORM(vaddubm
, 0, 0);
6534 GEN_VXFORM(vadduhm
, 0, 1);
6535 GEN_VXFORM(vadduwm
, 0, 2);
6536 GEN_VXFORM(vsububm
, 0, 16);
6537 GEN_VXFORM(vsubuhm
, 0, 17);
6538 GEN_VXFORM(vsubuwm
, 0, 18);
6539 GEN_VXFORM(vmaxub
, 1, 0);
6540 GEN_VXFORM(vmaxuh
, 1, 1);
6541 GEN_VXFORM(vmaxuw
, 1, 2);
6542 GEN_VXFORM(vmaxsb
, 1, 4);
6543 GEN_VXFORM(vmaxsh
, 1, 5);
6544 GEN_VXFORM(vmaxsw
, 1, 6);
6545 GEN_VXFORM(vminub
, 1, 8);
6546 GEN_VXFORM(vminuh
, 1, 9);
6547 GEN_VXFORM(vminuw
, 1, 10);
6548 GEN_VXFORM(vminsb
, 1, 12);
6549 GEN_VXFORM(vminsh
, 1, 13);
6550 GEN_VXFORM(vminsw
, 1, 14);
6551 GEN_VXFORM(vavgub
, 1, 16);
6552 GEN_VXFORM(vavguh
, 1, 17);
6553 GEN_VXFORM(vavguw
, 1, 18);
6554 GEN_VXFORM(vavgsb
, 1, 20);
6555 GEN_VXFORM(vavgsh
, 1, 21);
6556 GEN_VXFORM(vavgsw
, 1, 22);
6557 GEN_VXFORM(vmrghb
, 6, 0);
6558 GEN_VXFORM(vmrghh
, 6, 1);
6559 GEN_VXFORM(vmrghw
, 6, 2);
6560 GEN_VXFORM(vmrglb
, 6, 4);
6561 GEN_VXFORM(vmrglh
, 6, 5);
6562 GEN_VXFORM(vmrglw
, 6, 6);
6563 GEN_VXFORM(vmuloub
, 4, 0);
6564 GEN_VXFORM(vmulouh
, 4, 1);
6565 GEN_VXFORM(vmulosb
, 4, 4);
6566 GEN_VXFORM(vmulosh
, 4, 5);
6567 GEN_VXFORM(vmuleub
, 4, 8);
6568 GEN_VXFORM(vmuleuh
, 4, 9);
6569 GEN_VXFORM(vmulesb
, 4, 12);
6570 GEN_VXFORM(vmulesh
, 4, 13);
6571 GEN_VXFORM(vslb
, 2, 4);
6572 GEN_VXFORM(vslh
, 2, 5);
6573 GEN_VXFORM(vslw
, 2, 6);
6574 GEN_VXFORM(vsrb
, 2, 8);
6575 GEN_VXFORM(vsrh
, 2, 9);
6576 GEN_VXFORM(vsrw
, 2, 10);
6577 GEN_VXFORM(vsrab
, 2, 12);
6578 GEN_VXFORM(vsrah
, 2, 13);
6579 GEN_VXFORM(vsraw
, 2, 14);
6580 GEN_VXFORM(vslo
, 6, 16);
6581 GEN_VXFORM(vsro
, 6, 17);
6582 GEN_VXFORM(vaddcuw
, 0, 6);
6583 GEN_VXFORM(vsubcuw
, 0, 22);
6584 GEN_VXFORM_ENV(vaddubs
, 0, 8);
6585 GEN_VXFORM_ENV(vadduhs
, 0, 9);
6586 GEN_VXFORM_ENV(vadduws
, 0, 10);
6587 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
6588 GEN_VXFORM_ENV(vaddshs
, 0, 13);
6589 GEN_VXFORM_ENV(vaddsws
, 0, 14);
6590 GEN_VXFORM_ENV(vsububs
, 0, 24);
6591 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
6592 GEN_VXFORM_ENV(vsubuws
, 0, 26);
6593 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
6594 GEN_VXFORM_ENV(vsubshs
, 0, 29);
6595 GEN_VXFORM_ENV(vsubsws
, 0, 30);
6596 GEN_VXFORM(vrlb
, 2, 0);
6597 GEN_VXFORM(vrlh
, 2, 1);
6598 GEN_VXFORM(vrlw
, 2, 2);
6599 GEN_VXFORM(vsl
, 2, 7);
6600 GEN_VXFORM(vsr
, 2, 11);
6601 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
6602 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
6603 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
6604 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
6605 GEN_VXFORM_ENV(vpkshus
, 7, 4);
6606 GEN_VXFORM_ENV(vpkswus
, 7, 5);
6607 GEN_VXFORM_ENV(vpkshss
, 7, 6);
6608 GEN_VXFORM_ENV(vpkswss
, 7, 7);
6609 GEN_VXFORM(vpkpx
, 7, 12);
6610 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
6611 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
6612 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
6613 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
6614 GEN_VXFORM_ENV(vsumsws
, 4, 30);
6615 GEN_VXFORM_ENV(vaddfp
, 5, 0);
6616 GEN_VXFORM_ENV(vsubfp
, 5, 1);
6617 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
6618 GEN_VXFORM_ENV(vminfp
, 5, 17);
6620 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6621 static void glue(gen_, name)(DisasContext *ctx) \
6623 TCGv_ptr ra, rb, rd; \
6624 if (unlikely(!ctx->altivec_enabled)) { \
6625 gen_exception(ctx, POWERPC_EXCP_VPU); \
6628 ra = gen_avr_ptr(rA(ctx->opcode)); \
6629 rb = gen_avr_ptr(rB(ctx->opcode)); \
6630 rd = gen_avr_ptr(rD(ctx->opcode)); \
6631 gen_helper_##opname(cpu_env, rd, ra, rb); \
6632 tcg_temp_free_ptr(ra); \
6633 tcg_temp_free_ptr(rb); \
6634 tcg_temp_free_ptr(rd); \
6637 #define GEN_VXRFORM(name, opc2, opc3) \
6638 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6639 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6641 GEN_VXRFORM(vcmpequb
, 3, 0)
6642 GEN_VXRFORM(vcmpequh
, 3, 1)
6643 GEN_VXRFORM(vcmpequw
, 3, 2)
6644 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6645 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6646 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6647 GEN_VXRFORM(vcmpgtub
, 3, 8)
6648 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6649 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6650 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6651 GEN_VXRFORM(vcmpgefp
, 3, 7)
6652 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6653 GEN_VXRFORM(vcmpbfp
, 3, 15)
6655 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6656 static void glue(gen_, name)(DisasContext *ctx) \
6660 if (unlikely(!ctx->altivec_enabled)) { \
6661 gen_exception(ctx, POWERPC_EXCP_VPU); \
6664 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6665 rd = gen_avr_ptr(rD(ctx->opcode)); \
6666 gen_helper_##name (rd, simm); \
6667 tcg_temp_free_i32(simm); \
6668 tcg_temp_free_ptr(rd); \
6671 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6672 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6673 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6675 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6676 static void glue(gen_, name)(DisasContext *ctx) \
6679 if (unlikely(!ctx->altivec_enabled)) { \
6680 gen_exception(ctx, POWERPC_EXCP_VPU); \
6683 rb = gen_avr_ptr(rB(ctx->opcode)); \
6684 rd = gen_avr_ptr(rD(ctx->opcode)); \
6685 gen_helper_##name (rd, rb); \
6686 tcg_temp_free_ptr(rb); \
6687 tcg_temp_free_ptr(rd); \
6690 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6691 static void glue(gen_, name)(DisasContext *ctx) \
6695 if (unlikely(!ctx->altivec_enabled)) { \
6696 gen_exception(ctx, POWERPC_EXCP_VPU); \
6699 rb = gen_avr_ptr(rB(ctx->opcode)); \
6700 rd = gen_avr_ptr(rD(ctx->opcode)); \
6701 gen_helper_##name(cpu_env, rd, rb); \
6702 tcg_temp_free_ptr(rb); \
6703 tcg_temp_free_ptr(rd); \
6706 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6707 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6708 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6709 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6710 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6711 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6712 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
6713 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
6714 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
6715 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
6716 GEN_VXFORM_NOA_ENV(vrfim
, 5, 8);
6717 GEN_VXFORM_NOA_ENV(vrfin
, 5, 9);
6718 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
6719 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 11);
6721 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6722 static void glue(gen_, name)(DisasContext *ctx) \
6726 if (unlikely(!ctx->altivec_enabled)) { \
6727 gen_exception(ctx, POWERPC_EXCP_VPU); \
6730 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6731 rd = gen_avr_ptr(rD(ctx->opcode)); \
6732 gen_helper_##name (rd, simm); \
6733 tcg_temp_free_i32(simm); \
6734 tcg_temp_free_ptr(rd); \
6737 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6738 static void glue(gen_, name)(DisasContext *ctx) \
6742 if (unlikely(!ctx->altivec_enabled)) { \
6743 gen_exception(ctx, POWERPC_EXCP_VPU); \
6746 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6747 rb = gen_avr_ptr(rB(ctx->opcode)); \
6748 rd = gen_avr_ptr(rD(ctx->opcode)); \
6749 gen_helper_##name (rd, rb, uimm); \
6750 tcg_temp_free_i32(uimm); \
6751 tcg_temp_free_ptr(rb); \
6752 tcg_temp_free_ptr(rd); \
6755 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6756 static void glue(gen_, name)(DisasContext *ctx) \
6761 if (unlikely(!ctx->altivec_enabled)) { \
6762 gen_exception(ctx, POWERPC_EXCP_VPU); \
6765 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6766 rb = gen_avr_ptr(rB(ctx->opcode)); \
6767 rd = gen_avr_ptr(rD(ctx->opcode)); \
6768 gen_helper_##name(cpu_env, rd, rb, uimm); \
6769 tcg_temp_free_i32(uimm); \
6770 tcg_temp_free_ptr(rb); \
6771 tcg_temp_free_ptr(rd); \
6774 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6775 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6776 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6777 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
6778 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
6779 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
6780 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
6782 static void gen_vsldoi(DisasContext
*ctx
)
6784 TCGv_ptr ra
, rb
, rd
;
6786 if (unlikely(!ctx
->altivec_enabled
)) {
6787 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6790 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6791 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6792 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6793 sh
= tcg_const_i32(VSH(ctx
->opcode
));
6794 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
6795 tcg_temp_free_ptr(ra
);
6796 tcg_temp_free_ptr(rb
);
6797 tcg_temp_free_ptr(rd
);
6798 tcg_temp_free_i32(sh
);
6801 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6802 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6804 TCGv_ptr ra, rb, rc, rd; \
6805 if (unlikely(!ctx->altivec_enabled)) { \
6806 gen_exception(ctx, POWERPC_EXCP_VPU); \
6809 ra = gen_avr_ptr(rA(ctx->opcode)); \
6810 rb = gen_avr_ptr(rB(ctx->opcode)); \
6811 rc = gen_avr_ptr(rC(ctx->opcode)); \
6812 rd = gen_avr_ptr(rD(ctx->opcode)); \
6813 if (Rc(ctx->opcode)) { \
6814 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
6816 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
6818 tcg_temp_free_ptr(ra); \
6819 tcg_temp_free_ptr(rb); \
6820 tcg_temp_free_ptr(rc); \
6821 tcg_temp_free_ptr(rd); \
6824 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
6826 static void gen_vmladduhm(DisasContext
*ctx
)
6828 TCGv_ptr ra
, rb
, rc
, rd
;
6829 if (unlikely(!ctx
->altivec_enabled
)) {
6830 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6833 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6834 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6835 rc
= gen_avr_ptr(rC(ctx
->opcode
));
6836 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6837 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
6838 tcg_temp_free_ptr(ra
);
6839 tcg_temp_free_ptr(rb
);
6840 tcg_temp_free_ptr(rc
);
6841 tcg_temp_free_ptr(rd
);
6844 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
6845 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
6846 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
6847 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
6848 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
6850 /*** SPE extension ***/
6851 /* Register moves */
6854 static inline void gen_evmra(DisasContext
*ctx
)
6857 if (unlikely(!ctx
->spe_enabled
)) {
6858 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
6862 #if defined(TARGET_PPC64)
6864 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6867 tcg_gen_st_i64(cpu_gpr
[rA(ctx
->opcode
)],
6869 offsetof(CPUPPCState
, spe_acc
));
6871 TCGv_i64 tmp
= tcg_temp_new_i64();
6873 /* tmp := rA_lo + rA_hi << 32 */
6874 tcg_gen_concat_i32_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6876 /* spe_acc := tmp */
6877 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
6878 tcg_temp_free_i64(tmp
);
6881 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6882 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6886 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
6888 #if defined(TARGET_PPC64)
6889 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
6891 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
6895 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
6897 #if defined(TARGET_PPC64)
6898 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
6900 TCGv_i64 tmp
= tcg_temp_new_i64();
6901 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
6902 tcg_gen_shri_i64(tmp
, t
, 32);
6903 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
6904 tcg_temp_free_i64(tmp
);
6908 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
6909 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6911 if (Rc(ctx->opcode)) \
6917 /* Handler for undefined SPE opcodes */
6918 static inline void gen_speundef(DisasContext
*ctx
)
6920 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6924 #if defined(TARGET_PPC64)
6925 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6926 static inline void gen_##name(DisasContext *ctx) \
6928 if (unlikely(!ctx->spe_enabled)) { \
6929 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6932 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6933 cpu_gpr[rB(ctx->opcode)]); \
6936 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6937 static inline void gen_##name(DisasContext *ctx) \
6939 if (unlikely(!ctx->spe_enabled)) { \
6940 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6943 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6944 cpu_gpr[rB(ctx->opcode)]); \
6945 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6946 cpu_gprh[rB(ctx->opcode)]); \
6950 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
6951 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
6952 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
6953 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
6954 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
6955 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
6956 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
6957 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
6959 /* SPE logic immediate */
6960 #if defined(TARGET_PPC64)
6961 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6962 static inline void gen_##name(DisasContext *ctx) \
6964 if (unlikely(!ctx->spe_enabled)) { \
6965 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6968 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6969 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6970 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6971 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6972 tcg_opi(t0, t0, rB(ctx->opcode)); \
6973 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6974 tcg_gen_trunc_i64_i32(t1, t2); \
6975 tcg_temp_free_i64(t2); \
6976 tcg_opi(t1, t1, rB(ctx->opcode)); \
6977 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6978 tcg_temp_free_i32(t0); \
6979 tcg_temp_free_i32(t1); \
6982 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6983 static inline void gen_##name(DisasContext *ctx) \
6985 if (unlikely(!ctx->spe_enabled)) { \
6986 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6989 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6991 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6995 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
6996 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
6997 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
6998 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
7000 /* SPE arithmetic */
7001 #if defined(TARGET_PPC64)
7002 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7003 static inline void gen_##name(DisasContext *ctx) \
7005 if (unlikely(!ctx->spe_enabled)) { \
7006 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7009 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7010 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7011 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7012 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7014 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7015 tcg_gen_trunc_i64_i32(t1, t2); \
7016 tcg_temp_free_i64(t2); \
7018 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7019 tcg_temp_free_i32(t0); \
7020 tcg_temp_free_i32(t1); \
7023 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7024 static inline void gen_##name(DisasContext *ctx) \
7026 if (unlikely(!ctx->spe_enabled)) { \
7027 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7030 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
7031 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
7035 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
7037 int l1
= gen_new_label();
7038 int l2
= gen_new_label();
7040 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
7041 tcg_gen_neg_i32(ret
, arg1
);
7044 tcg_gen_mov_i32(ret
, arg1
);
7047 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
7048 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
7049 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
7050 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
7051 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
7053 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
7054 tcg_gen_ext16u_i32(ret
, ret
);
7056 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
7057 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
7058 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
7060 #if defined(TARGET_PPC64)
7061 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7062 static inline void gen_##name(DisasContext *ctx) \
7064 if (unlikely(!ctx->spe_enabled)) { \
7065 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7068 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7069 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7070 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
7071 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
7072 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7073 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
7074 tcg_op(t0, t0, t2); \
7075 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
7076 tcg_gen_trunc_i64_i32(t1, t3); \
7077 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
7078 tcg_gen_trunc_i64_i32(t2, t3); \
7079 tcg_temp_free_i64(t3); \
7080 tcg_op(t1, t1, t2); \
7081 tcg_temp_free_i32(t2); \
7082 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7083 tcg_temp_free_i32(t0); \
7084 tcg_temp_free_i32(t1); \
7087 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7088 static inline void gen_##name(DisasContext *ctx) \
7090 if (unlikely(!ctx->spe_enabled)) { \
7091 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7094 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7095 cpu_gpr[rB(ctx->opcode)]); \
7096 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7097 cpu_gprh[rB(ctx->opcode)]); \
7101 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7106 l1
= gen_new_label();
7107 l2
= gen_new_label();
7108 t0
= tcg_temp_local_new_i32();
7109 /* No error here: 6 bits are used */
7110 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7111 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7112 tcg_gen_shr_i32(ret
, arg1
, t0
);
7115 tcg_gen_movi_i32(ret
, 0);
7117 tcg_temp_free_i32(t0
);
7119 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
7120 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7125 l1
= gen_new_label();
7126 l2
= gen_new_label();
7127 t0
= tcg_temp_local_new_i32();
7128 /* No error here: 6 bits are used */
7129 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7130 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7131 tcg_gen_sar_i32(ret
, arg1
, t0
);
7134 tcg_gen_movi_i32(ret
, 0);
7136 tcg_temp_free_i32(t0
);
7138 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
7139 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7144 l1
= gen_new_label();
7145 l2
= gen_new_label();
7146 t0
= tcg_temp_local_new_i32();
7147 /* No error here: 6 bits are used */
7148 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7149 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7150 tcg_gen_shl_i32(ret
, arg1
, t0
);
7153 tcg_gen_movi_i32(ret
, 0);
7155 tcg_temp_free_i32(t0
);
7157 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
7158 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7160 TCGv_i32 t0
= tcg_temp_new_i32();
7161 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
7162 tcg_gen_rotl_i32(ret
, arg1
, t0
);
7163 tcg_temp_free_i32(t0
);
7165 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
7166 static inline void gen_evmergehi(DisasContext
*ctx
)
7168 if (unlikely(!ctx
->spe_enabled
)) {
7169 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7172 #if defined(TARGET_PPC64)
7173 TCGv t0
= tcg_temp_new();
7174 TCGv t1
= tcg_temp_new();
7175 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7176 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7177 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7181 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7182 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7185 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
7186 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7188 tcg_gen_sub_i32(ret
, arg2
, arg1
);
7190 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
7192 /* SPE arithmetic immediate */
7193 #if defined(TARGET_PPC64)
7194 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7195 static inline void gen_##name(DisasContext *ctx) \
7197 if (unlikely(!ctx->spe_enabled)) { \
7198 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7201 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7202 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7203 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7204 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7205 tcg_op(t0, t0, rA(ctx->opcode)); \
7206 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7207 tcg_gen_trunc_i64_i32(t1, t2); \
7208 tcg_temp_free_i64(t2); \
7209 tcg_op(t1, t1, rA(ctx->opcode)); \
7210 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7211 tcg_temp_free_i32(t0); \
7212 tcg_temp_free_i32(t1); \
7215 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7216 static inline void gen_##name(DisasContext *ctx) \
7218 if (unlikely(!ctx->spe_enabled)) { \
7219 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7222 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7224 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7228 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
7229 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
7231 /* SPE comparison */
7232 #if defined(TARGET_PPC64)
7233 #define GEN_SPEOP_COMP(name, tcg_cond) \
7234 static inline void gen_##name(DisasContext *ctx) \
7236 if (unlikely(!ctx->spe_enabled)) { \
7237 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7240 int l1 = gen_new_label(); \
7241 int l2 = gen_new_label(); \
7242 int l3 = gen_new_label(); \
7243 int l4 = gen_new_label(); \
7244 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7245 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7246 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7247 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7248 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7249 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
7250 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
7252 gen_set_label(l1); \
7253 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7254 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7255 gen_set_label(l2); \
7256 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7257 tcg_gen_trunc_i64_i32(t0, t2); \
7258 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7259 tcg_gen_trunc_i64_i32(t1, t2); \
7260 tcg_temp_free_i64(t2); \
7261 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7262 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7263 ~(CRF_CH | CRF_CH_AND_CL)); \
7265 gen_set_label(l3); \
7266 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7267 CRF_CH | CRF_CH_OR_CL); \
7268 gen_set_label(l4); \
7269 tcg_temp_free_i32(t0); \
7270 tcg_temp_free_i32(t1); \
7273 #define GEN_SPEOP_COMP(name, tcg_cond) \
7274 static inline void gen_##name(DisasContext *ctx) \
7276 if (unlikely(!ctx->spe_enabled)) { \
7277 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7280 int l1 = gen_new_label(); \
7281 int l2 = gen_new_label(); \
7282 int l3 = gen_new_label(); \
7283 int l4 = gen_new_label(); \
7285 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7286 cpu_gpr[rB(ctx->opcode)], l1); \
7287 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7289 gen_set_label(l1); \
7290 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7291 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7292 gen_set_label(l2); \
7293 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7294 cpu_gprh[rB(ctx->opcode)], l3); \
7295 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7296 ~(CRF_CH | CRF_CH_AND_CL)); \
7298 gen_set_label(l3); \
7299 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7300 CRF_CH | CRF_CH_OR_CL); \
7301 gen_set_label(l4); \
7304 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
7305 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
7306 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
7307 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
7308 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
7311 static inline void gen_brinc(DisasContext
*ctx
)
7313 /* Note: brinc is usable even if SPE is disabled */
7314 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
7315 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7317 static inline void gen_evmergelo(DisasContext
*ctx
)
7319 if (unlikely(!ctx
->spe_enabled
)) {
7320 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7323 #if defined(TARGET_PPC64)
7324 TCGv t0
= tcg_temp_new();
7325 TCGv t1
= tcg_temp_new();
7326 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7327 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7328 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7332 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7333 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7336 static inline void gen_evmergehilo(DisasContext
*ctx
)
7338 if (unlikely(!ctx
->spe_enabled
)) {
7339 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7342 #if defined(TARGET_PPC64)
7343 TCGv t0
= tcg_temp_new();
7344 TCGv t1
= tcg_temp_new();
7345 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7346 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7347 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7351 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7352 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7355 static inline void gen_evmergelohi(DisasContext
*ctx
)
7357 if (unlikely(!ctx
->spe_enabled
)) {
7358 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7361 #if defined(TARGET_PPC64)
7362 TCGv t0
= tcg_temp_new();
7363 TCGv t1
= tcg_temp_new();
7364 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7365 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7366 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7370 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
7371 TCGv_i32 tmp
= tcg_temp_new_i32();
7372 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
7373 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7374 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
7375 tcg_temp_free_i32(tmp
);
7377 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7378 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7382 static inline void gen_evsplati(DisasContext
*ctx
)
7384 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
7386 #if defined(TARGET_PPC64)
7387 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7389 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7390 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7393 static inline void gen_evsplatfi(DisasContext
*ctx
)
7395 uint64_t imm
= rA(ctx
->opcode
) << 27;
7397 #if defined(TARGET_PPC64)
7398 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7400 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7401 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7405 static inline void gen_evsel(DisasContext
*ctx
)
7407 int l1
= gen_new_label();
7408 int l2
= gen_new_label();
7409 int l3
= gen_new_label();
7410 int l4
= gen_new_label();
7411 TCGv_i32 t0
= tcg_temp_local_new_i32();
7412 #if defined(TARGET_PPC64)
7413 TCGv t1
= tcg_temp_local_new();
7414 TCGv t2
= tcg_temp_local_new();
7416 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
7417 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
7418 #if defined(TARGET_PPC64)
7419 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7421 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7425 #if defined(TARGET_PPC64)
7426 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7428 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7431 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
7432 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
7433 #if defined(TARGET_PPC64)
7434 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)]);
7436 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7440 #if defined(TARGET_PPC64)
7441 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)]);
7443 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7446 tcg_temp_free_i32(t0
);
7447 #if defined(TARGET_PPC64)
7448 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
7454 static void gen_evsel0(DisasContext
*ctx
)
7459 static void gen_evsel1(DisasContext
*ctx
)
7464 static void gen_evsel2(DisasContext
*ctx
)
7469 static void gen_evsel3(DisasContext
*ctx
)
7476 static inline void gen_evmwumi(DisasContext
*ctx
)
7480 if (unlikely(!ctx
->spe_enabled
)) {
7481 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7485 t0
= tcg_temp_new_i64();
7486 t1
= tcg_temp_new_i64();
7488 /* t0 := rA; t1 := rB */
7489 #if defined(TARGET_PPC64)
7490 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7491 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7493 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7494 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7497 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7499 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7501 tcg_temp_free_i64(t0
);
7502 tcg_temp_free_i64(t1
);
7505 static inline void gen_evmwumia(DisasContext
*ctx
)
7509 if (unlikely(!ctx
->spe_enabled
)) {
7510 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7514 gen_evmwumi(ctx
); /* rD := rA * rB */
7516 tmp
= tcg_temp_new_i64();
7519 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7520 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7521 tcg_temp_free_i64(tmp
);
7524 static inline void gen_evmwumiaa(DisasContext
*ctx
)
7529 if (unlikely(!ctx
->spe_enabled
)) {
7530 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7534 gen_evmwumi(ctx
); /* rD := rA * rB */
7536 acc
= tcg_temp_new_i64();
7537 tmp
= tcg_temp_new_i64();
7540 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7543 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7545 /* acc := tmp + acc */
7546 tcg_gen_add_i64(acc
, acc
, tmp
);
7549 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7552 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7554 tcg_temp_free_i64(acc
);
7555 tcg_temp_free_i64(tmp
);
7558 static inline void gen_evmwsmi(DisasContext
*ctx
)
7562 if (unlikely(!ctx
->spe_enabled
)) {
7563 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7567 t0
= tcg_temp_new_i64();
7568 t1
= tcg_temp_new_i64();
7570 /* t0 := rA; t1 := rB */
7571 #if defined(TARGET_PPC64)
7572 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7573 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7575 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7576 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7579 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7581 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7583 tcg_temp_free_i64(t0
);
7584 tcg_temp_free_i64(t1
);
7587 static inline void gen_evmwsmia(DisasContext
*ctx
)
7591 gen_evmwsmi(ctx
); /* rD := rA * rB */
7593 tmp
= tcg_temp_new_i64();
7596 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7597 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7599 tcg_temp_free_i64(tmp
);
7602 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
7604 TCGv_i64 acc
= tcg_temp_new_i64();
7605 TCGv_i64 tmp
= tcg_temp_new_i64();
7607 gen_evmwsmi(ctx
); /* rD := rA * rB */
7609 acc
= tcg_temp_new_i64();
7610 tmp
= tcg_temp_new_i64();
7613 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7616 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7618 /* acc := tmp + acc */
7619 tcg_gen_add_i64(acc
, acc
, tmp
);
7622 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7625 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7627 tcg_temp_free_i64(acc
);
7628 tcg_temp_free_i64(tmp
);
7631 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7632 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7633 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7634 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7635 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7636 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7637 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7638 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
7639 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
7640 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7641 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7642 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7643 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7644 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7645 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7646 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7647 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7648 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7649 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7650 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
7651 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7652 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7653 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
7654 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
7655 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7656 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7657 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7658 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7659 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
7661 /* SPE load and stores */
7662 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
7664 target_ulong uimm
= rB(ctx
->opcode
);
7666 if (rA(ctx
->opcode
) == 0) {
7667 tcg_gen_movi_tl(EA
, uimm
<< sh
);
7669 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
7670 #if defined(TARGET_PPC64)
7671 if (!ctx
->sf_mode
) {
7672 tcg_gen_ext32u_tl(EA
, EA
);
7678 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
7680 #if defined(TARGET_PPC64)
7681 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7683 TCGv_i64 t0
= tcg_temp_new_i64();
7684 gen_qemu_ld64(ctx
, t0
, addr
);
7685 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7686 tcg_gen_shri_i64(t0
, t0
, 32);
7687 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7688 tcg_temp_free_i64(t0
);
7692 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
7694 #if defined(TARGET_PPC64)
7695 TCGv t0
= tcg_temp_new();
7696 gen_qemu_ld32u(ctx
, t0
, addr
);
7697 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7698 gen_addr_add(ctx
, addr
, addr
, 4);
7699 gen_qemu_ld32u(ctx
, t0
, addr
);
7700 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7703 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7704 gen_addr_add(ctx
, addr
, addr
, 4);
7705 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7709 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
7711 TCGv t0
= tcg_temp_new();
7712 #if defined(TARGET_PPC64)
7713 gen_qemu_ld16u(ctx
, t0
, addr
);
7714 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7715 gen_addr_add(ctx
, addr
, addr
, 2);
7716 gen_qemu_ld16u(ctx
, t0
, addr
);
7717 tcg_gen_shli_tl(t0
, t0
, 32);
7718 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7719 gen_addr_add(ctx
, addr
, addr
, 2);
7720 gen_qemu_ld16u(ctx
, t0
, addr
);
7721 tcg_gen_shli_tl(t0
, t0
, 16);
7722 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7723 gen_addr_add(ctx
, addr
, addr
, 2);
7724 gen_qemu_ld16u(ctx
, t0
, addr
);
7725 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7727 gen_qemu_ld16u(ctx
, t0
, addr
);
7728 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7729 gen_addr_add(ctx
, addr
, addr
, 2);
7730 gen_qemu_ld16u(ctx
, t0
, addr
);
7731 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7732 gen_addr_add(ctx
, addr
, addr
, 2);
7733 gen_qemu_ld16u(ctx
, t0
, addr
);
7734 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7735 gen_addr_add(ctx
, addr
, addr
, 2);
7736 gen_qemu_ld16u(ctx
, t0
, addr
);
7737 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7742 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
7744 TCGv t0
= tcg_temp_new();
7745 gen_qemu_ld16u(ctx
, t0
, addr
);
7746 #if defined(TARGET_PPC64)
7747 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7748 tcg_gen_shli_tl(t0
, t0
, 16);
7749 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7751 tcg_gen_shli_tl(t0
, t0
, 16);
7752 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7753 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7758 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
7760 TCGv t0
= tcg_temp_new();
7761 gen_qemu_ld16u(ctx
, t0
, addr
);
7762 #if defined(TARGET_PPC64)
7763 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7764 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7766 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7767 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7772 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
7774 TCGv t0
= tcg_temp_new();
7775 gen_qemu_ld16s(ctx
, t0
, addr
);
7776 #if defined(TARGET_PPC64)
7777 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7778 tcg_gen_ext32u_tl(t0
, t0
);
7779 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7781 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7782 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7787 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
7789 TCGv t0
= tcg_temp_new();
7790 #if defined(TARGET_PPC64)
7791 gen_qemu_ld16u(ctx
, t0
, addr
);
7792 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7793 gen_addr_add(ctx
, addr
, addr
, 2);
7794 gen_qemu_ld16u(ctx
, t0
, addr
);
7795 tcg_gen_shli_tl(t0
, t0
, 16);
7796 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7798 gen_qemu_ld16u(ctx
, t0
, addr
);
7799 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7800 gen_addr_add(ctx
, addr
, addr
, 2);
7801 gen_qemu_ld16u(ctx
, t0
, addr
);
7802 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7807 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
7809 #if defined(TARGET_PPC64)
7810 TCGv t0
= tcg_temp_new();
7811 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7812 gen_addr_add(ctx
, addr
, addr
, 2);
7813 gen_qemu_ld16u(ctx
, t0
, addr
);
7814 tcg_gen_shli_tl(t0
, t0
, 32);
7815 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7818 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7819 gen_addr_add(ctx
, addr
, addr
, 2);
7820 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7824 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
7826 #if defined(TARGET_PPC64)
7827 TCGv t0
= tcg_temp_new();
7828 gen_qemu_ld16s(ctx
, t0
, addr
);
7829 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7830 gen_addr_add(ctx
, addr
, addr
, 2);
7831 gen_qemu_ld16s(ctx
, t0
, addr
);
7832 tcg_gen_shli_tl(t0
, t0
, 32);
7833 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7836 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7837 gen_addr_add(ctx
, addr
, addr
, 2);
7838 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7842 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
7844 TCGv t0
= tcg_temp_new();
7845 gen_qemu_ld32u(ctx
, t0
, addr
);
7846 #if defined(TARGET_PPC64)
7847 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7848 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7850 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7851 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7856 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
7858 TCGv t0
= tcg_temp_new();
7859 #if defined(TARGET_PPC64)
7860 gen_qemu_ld16u(ctx
, t0
, addr
);
7861 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7862 tcg_gen_shli_tl(t0
, t0
, 32);
7863 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7864 gen_addr_add(ctx
, addr
, addr
, 2);
7865 gen_qemu_ld16u(ctx
, t0
, addr
);
7866 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7867 tcg_gen_shli_tl(t0
, t0
, 16);
7868 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7870 gen_qemu_ld16u(ctx
, t0
, addr
);
7871 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7872 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7873 gen_addr_add(ctx
, addr
, addr
, 2);
7874 gen_qemu_ld16u(ctx
, t0
, addr
);
7875 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7876 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7881 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
7883 #if defined(TARGET_PPC64)
7884 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7886 TCGv_i64 t0
= tcg_temp_new_i64();
7887 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
7888 gen_qemu_st64(ctx
, t0
, addr
);
7889 tcg_temp_free_i64(t0
);
7893 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
7895 #if defined(TARGET_PPC64)
7896 TCGv t0
= tcg_temp_new();
7897 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7898 gen_qemu_st32(ctx
, t0
, addr
);
7901 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7903 gen_addr_add(ctx
, addr
, addr
, 4);
7904 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7907 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
7909 TCGv t0
= tcg_temp_new();
7910 #if defined(TARGET_PPC64)
7911 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7913 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7915 gen_qemu_st16(ctx
, t0
, addr
);
7916 gen_addr_add(ctx
, addr
, addr
, 2);
7917 #if defined(TARGET_PPC64)
7918 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7919 gen_qemu_st16(ctx
, t0
, addr
);
7921 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7923 gen_addr_add(ctx
, addr
, addr
, 2);
7924 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7925 gen_qemu_st16(ctx
, t0
, addr
);
7927 gen_addr_add(ctx
, addr
, addr
, 2);
7928 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7931 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
7933 TCGv t0
= tcg_temp_new();
7934 #if defined(TARGET_PPC64)
7935 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7937 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7939 gen_qemu_st16(ctx
, t0
, addr
);
7940 gen_addr_add(ctx
, addr
, addr
, 2);
7941 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7942 gen_qemu_st16(ctx
, t0
, addr
);
7946 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
7948 #if defined(TARGET_PPC64)
7949 TCGv t0
= tcg_temp_new();
7950 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7951 gen_qemu_st16(ctx
, t0
, addr
);
7954 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7956 gen_addr_add(ctx
, addr
, addr
, 2);
7957 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7960 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
7962 #if defined(TARGET_PPC64)
7963 TCGv t0
= tcg_temp_new();
7964 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7965 gen_qemu_st32(ctx
, t0
, addr
);
7968 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7972 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
7974 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7977 #define GEN_SPEOP_LDST(name, opc2, sh) \
7978 static void glue(gen_, name)(DisasContext *ctx) \
7981 if (unlikely(!ctx->spe_enabled)) { \
7982 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7985 gen_set_access_type(ctx, ACCESS_INT); \
7986 t0 = tcg_temp_new(); \
7987 if (Rc(ctx->opcode)) { \
7988 gen_addr_spe_imm_index(ctx, t0, sh); \
7990 gen_addr_reg_index(ctx, t0); \
7992 gen_op_##name(ctx, t0); \
7993 tcg_temp_free(t0); \
7996 GEN_SPEOP_LDST(evldd
, 0x00, 3);
7997 GEN_SPEOP_LDST(evldw
, 0x01, 3);
7998 GEN_SPEOP_LDST(evldh
, 0x02, 3);
7999 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
8000 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
8001 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
8002 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
8003 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
8004 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
8005 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
8006 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
8008 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
8009 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
8010 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
8011 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
8012 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
8013 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
8014 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
8016 /* Multiply and add - TODO */
8018 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
8019 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8020 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8021 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8022 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8023 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8024 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8025 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8026 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8027 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8028 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8029 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8031 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8032 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8033 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8034 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8035 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8036 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8037 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8038 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8039 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8040 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8041 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8042 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8044 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8045 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8046 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8047 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8048 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
8050 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8051 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8052 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8053 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8054 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8055 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8056 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8057 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8058 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8059 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8060 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8061 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8063 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8064 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8065 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8066 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8068 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8069 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8070 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8071 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8072 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8073 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8074 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8075 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8076 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8077 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8078 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8079 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8081 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8082 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8083 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8084 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8085 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8088 /*** SPE floating-point extension ***/
8089 #if defined(TARGET_PPC64)
8090 #define GEN_SPEFPUOP_CONV_32_32(name) \
8091 static inline void gen_##name(DisasContext *ctx) \
8095 t0 = tcg_temp_new_i32(); \
8096 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8097 gen_helper_##name(t0, cpu_env, t0); \
8098 t1 = tcg_temp_new(); \
8099 tcg_gen_extu_i32_tl(t1, t0); \
8100 tcg_temp_free_i32(t0); \
8101 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8102 0xFFFFFFFF00000000ULL); \
8103 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8104 tcg_temp_free(t1); \
8106 #define GEN_SPEFPUOP_CONV_32_64(name) \
8107 static inline void gen_##name(DisasContext *ctx) \
8111 t0 = tcg_temp_new_i32(); \
8112 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8113 t1 = tcg_temp_new(); \
8114 tcg_gen_extu_i32_tl(t1, t0); \
8115 tcg_temp_free_i32(t0); \
8116 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8117 0xFFFFFFFF00000000ULL); \
8118 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8119 tcg_temp_free(t1); \
8121 #define GEN_SPEFPUOP_CONV_64_32(name) \
8122 static inline void gen_##name(DisasContext *ctx) \
8124 TCGv_i32 t0 = tcg_temp_new_i32(); \
8125 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8126 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8127 tcg_temp_free_i32(t0); \
8129 #define GEN_SPEFPUOP_CONV_64_64(name) \
8130 static inline void gen_##name(DisasContext *ctx) \
8132 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8133 cpu_gpr[rB(ctx->opcode)]); \
8135 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8136 static inline void gen_##name(DisasContext *ctx) \
8140 if (unlikely(!ctx->spe_enabled)) { \
8141 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8144 t0 = tcg_temp_new_i32(); \
8145 t1 = tcg_temp_new_i32(); \
8146 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8147 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8148 gen_helper_##name(t0, cpu_env, t0, t1); \
8149 tcg_temp_free_i32(t1); \
8150 t2 = tcg_temp_new(); \
8151 tcg_gen_extu_i32_tl(t2, t0); \
8152 tcg_temp_free_i32(t0); \
8153 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8154 0xFFFFFFFF00000000ULL); \
8155 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8156 tcg_temp_free(t2); \
8158 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8159 static inline void gen_##name(DisasContext *ctx) \
8161 if (unlikely(!ctx->spe_enabled)) { \
8162 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8165 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8166 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8168 #define GEN_SPEFPUOP_COMP_32(name) \
8169 static inline void gen_##name(DisasContext *ctx) \
8172 if (unlikely(!ctx->spe_enabled)) { \
8173 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8176 t0 = tcg_temp_new_i32(); \
8177 t1 = tcg_temp_new_i32(); \
8178 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8179 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8180 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8181 tcg_temp_free_i32(t0); \
8182 tcg_temp_free_i32(t1); \
8184 #define GEN_SPEFPUOP_COMP_64(name) \
8185 static inline void gen_##name(DisasContext *ctx) \
8187 if (unlikely(!ctx->spe_enabled)) { \
8188 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8191 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8192 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8195 #define GEN_SPEFPUOP_CONV_32_32(name) \
8196 static inline void gen_##name(DisasContext *ctx) \
8198 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8199 cpu_gpr[rB(ctx->opcode)]); \
8201 #define GEN_SPEFPUOP_CONV_32_64(name) \
8202 static inline void gen_##name(DisasContext *ctx) \
8204 TCGv_i64 t0 = tcg_temp_new_i64(); \
8205 gen_load_gpr64(t0, rB(ctx->opcode)); \
8206 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8207 tcg_temp_free_i64(t0); \
8209 #define GEN_SPEFPUOP_CONV_64_32(name) \
8210 static inline void gen_##name(DisasContext *ctx) \
8212 TCGv_i64 t0 = tcg_temp_new_i64(); \
8213 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8214 gen_store_gpr64(rD(ctx->opcode), t0); \
8215 tcg_temp_free_i64(t0); \
8217 #define GEN_SPEFPUOP_CONV_64_64(name) \
8218 static inline void gen_##name(DisasContext *ctx) \
8220 TCGv_i64 t0 = tcg_temp_new_i64(); \
8221 gen_load_gpr64(t0, rB(ctx->opcode)); \
8222 gen_helper_##name(t0, cpu_env, t0); \
8223 gen_store_gpr64(rD(ctx->opcode), t0); \
8224 tcg_temp_free_i64(t0); \
8226 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8227 static inline void gen_##name(DisasContext *ctx) \
8229 if (unlikely(!ctx->spe_enabled)) { \
8230 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8233 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8234 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8236 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8237 static inline void gen_##name(DisasContext *ctx) \
8240 if (unlikely(!ctx->spe_enabled)) { \
8241 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8244 t0 = tcg_temp_new_i64(); \
8245 t1 = tcg_temp_new_i64(); \
8246 gen_load_gpr64(t0, rA(ctx->opcode)); \
8247 gen_load_gpr64(t1, rB(ctx->opcode)); \
8248 gen_helper_##name(t0, cpu_env, t0, t1); \
8249 gen_store_gpr64(rD(ctx->opcode), t0); \
8250 tcg_temp_free_i64(t0); \
8251 tcg_temp_free_i64(t1); \
8253 #define GEN_SPEFPUOP_COMP_32(name) \
8254 static inline void gen_##name(DisasContext *ctx) \
8256 if (unlikely(!ctx->spe_enabled)) { \
8257 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8260 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8261 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8263 #define GEN_SPEFPUOP_COMP_64(name) \
8264 static inline void gen_##name(DisasContext *ctx) \
8267 if (unlikely(!ctx->spe_enabled)) { \
8268 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8271 t0 = tcg_temp_new_i64(); \
8272 t1 = tcg_temp_new_i64(); \
8273 gen_load_gpr64(t0, rA(ctx->opcode)); \
8274 gen_load_gpr64(t1, rB(ctx->opcode)); \
8275 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8276 tcg_temp_free_i64(t0); \
8277 tcg_temp_free_i64(t1); \
8281 /* Single precision floating-point vectors operations */
8283 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
8284 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
8285 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
8286 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
8287 static inline void gen_evfsabs(DisasContext
*ctx
)
8289 if (unlikely(!ctx
->spe_enabled
)) {
8290 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8293 #if defined(TARGET_PPC64)
8294 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
8296 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
8297 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8300 static inline void gen_evfsnabs(DisasContext
*ctx
)
8302 if (unlikely(!ctx
->spe_enabled
)) {
8303 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8306 #if defined(TARGET_PPC64)
8307 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8309 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8310 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8313 static inline void gen_evfsneg(DisasContext
*ctx
)
8315 if (unlikely(!ctx
->spe_enabled
)) {
8316 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8319 #if defined(TARGET_PPC64)
8320 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8322 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8323 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8328 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
8329 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
8330 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
8331 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
8332 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
8333 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
8334 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
8335 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
8336 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
8337 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
8340 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
8341 GEN_SPEFPUOP_COMP_64(evfscmplt
);
8342 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
8343 GEN_SPEFPUOP_COMP_64(evfststgt
);
8344 GEN_SPEFPUOP_COMP_64(evfststlt
);
8345 GEN_SPEFPUOP_COMP_64(evfststeq
);
8347 /* Opcodes definitions */
8348 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8349 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8350 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8351 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8352 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8353 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8354 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8355 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8356 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8357 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8358 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8359 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8360 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8361 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8363 /* Single precision floating-point operations */
8365 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
8366 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
8367 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
8368 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
8369 static inline void gen_efsabs(DisasContext
*ctx
)
8371 if (unlikely(!ctx
->spe_enabled
)) {
8372 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8375 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
8377 static inline void gen_efsnabs(DisasContext
*ctx
)
8379 if (unlikely(!ctx
->spe_enabled
)) {
8380 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8383 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8385 static inline void gen_efsneg(DisasContext
*ctx
)
8387 if (unlikely(!ctx
->spe_enabled
)) {
8388 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8391 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8395 GEN_SPEFPUOP_CONV_32_32(efscfui
);
8396 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
8397 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
8398 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
8399 GEN_SPEFPUOP_CONV_32_32(efsctui
);
8400 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
8401 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
8402 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
8403 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
8404 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
8405 GEN_SPEFPUOP_CONV_32_64(efscfd
);
8408 GEN_SPEFPUOP_COMP_32(efscmpgt
);
8409 GEN_SPEFPUOP_COMP_32(efscmplt
);
8410 GEN_SPEFPUOP_COMP_32(efscmpeq
);
8411 GEN_SPEFPUOP_COMP_32(efststgt
);
8412 GEN_SPEFPUOP_COMP_32(efststlt
);
8413 GEN_SPEFPUOP_COMP_32(efststeq
);
8415 /* Opcodes definitions */
8416 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8417 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8418 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8419 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8420 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8421 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
8422 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8423 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8424 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8425 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8426 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8427 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8428 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8429 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8431 /* Double precision floating-point operations */
8433 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
8434 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
8435 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
8436 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
8437 static inline void gen_efdabs(DisasContext
*ctx
)
8439 if (unlikely(!ctx
->spe_enabled
)) {
8440 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8443 #if defined(TARGET_PPC64)
8444 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
8446 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8447 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8450 static inline void gen_efdnabs(DisasContext
*ctx
)
8452 if (unlikely(!ctx
->spe_enabled
)) {
8453 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8456 #if defined(TARGET_PPC64)
8457 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8459 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8460 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8463 static inline void gen_efdneg(DisasContext
*ctx
)
8465 if (unlikely(!ctx
->spe_enabled
)) {
8466 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8469 #if defined(TARGET_PPC64)
8470 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8472 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8473 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8478 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
8479 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
8480 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
8481 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
8482 GEN_SPEFPUOP_CONV_32_64(efdctui
);
8483 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
8484 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
8485 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
8486 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
8487 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
8488 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
8489 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
8490 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
8491 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
8492 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
8495 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
8496 GEN_SPEFPUOP_COMP_64(efdcmplt
);
8497 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
8498 GEN_SPEFPUOP_COMP_64(efdtstgt
);
8499 GEN_SPEFPUOP_COMP_64(efdtstlt
);
8500 GEN_SPEFPUOP_COMP_64(efdtsteq
);
8502 /* Opcodes definitions */
8503 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8504 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8505 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
8506 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8507 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8508 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8509 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8510 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
8511 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8512 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8513 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8514 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8515 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8516 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8517 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8518 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8520 static opcode_t opcodes
[] = {
8521 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
8522 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
8523 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8524 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
8525 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8526 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
8527 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8528 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8529 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8530 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8531 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
8532 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
8533 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
8534 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
8535 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8536 #if defined(TARGET_PPC64)
8537 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
8539 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
8540 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
8541 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8542 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8543 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8544 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
8545 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
8546 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
8547 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8548 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8549 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8550 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8551 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
8552 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
8553 #if defined(TARGET_PPC64)
8554 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
8555 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
8557 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8558 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8559 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8560 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
8561 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
8562 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
8563 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
8564 #if defined(TARGET_PPC64)
8565 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
8566 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
8567 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
8568 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
8569 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
8571 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
8572 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8573 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8574 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
8575 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
8576 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
8577 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
8578 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
8579 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
8580 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
8581 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT
),
8582 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
),
8583 #if defined(TARGET_PPC64)
8584 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8585 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
8586 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8588 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8589 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8590 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
8591 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
8592 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
8593 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
8594 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
8595 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
8596 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
8597 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
8598 #if defined(TARGET_PPC64)
8599 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
8600 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
8602 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
8603 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
8604 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8605 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8606 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
8607 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
8608 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
8609 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
8610 #if defined(TARGET_PPC64)
8611 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
8612 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
8614 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
8615 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
8616 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8617 #if defined(TARGET_PPC64)
8618 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
8619 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8621 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
8622 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
8623 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
8624 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
8625 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
8626 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
8627 #if defined(TARGET_PPC64)
8628 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
8630 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
8631 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
8632 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
8633 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
8634 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
8635 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
),
8636 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
),
8637 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
8638 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
8639 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
8640 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
8641 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
8642 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
8643 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
8644 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
8645 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
8646 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
8647 #if defined(TARGET_PPC64)
8648 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
8649 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8651 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
8652 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8654 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
8655 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
8656 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
8658 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
8659 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
8660 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
8661 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
8662 #if defined(TARGET_PPC64)
8663 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
8664 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
8666 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
8667 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
8668 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
8669 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
8670 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
8671 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
8672 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
8673 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
8674 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
8675 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
8676 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
8677 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8678 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
8679 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
8680 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
8681 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
8682 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
8683 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
8684 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
8685 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8686 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
8687 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
8688 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
8689 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
8690 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
8691 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
8692 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
8693 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
8694 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
8695 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
8696 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
8697 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
8698 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
8699 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
8700 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
8701 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
8702 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
8703 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
8704 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
8705 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
8706 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
8707 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
8708 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
8709 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
8710 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
8711 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
8712 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
8713 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
8714 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
8715 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8716 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8717 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
8718 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
8719 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8720 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8721 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
8722 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
8723 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
8724 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
8725 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
8726 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
8727 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
8728 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
8729 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
8730 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
8731 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
8732 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
8733 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
8734 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
8735 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
8736 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
8737 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
8738 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
8739 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
8740 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
8741 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
8742 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
8743 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
8744 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
8745 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
8746 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8747 PPC_NONE
, PPC2_BOOKE206
),
8748 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8749 PPC_NONE
, PPC2_BOOKE206
),
8750 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8751 PPC_NONE
, PPC2_BOOKE206
),
8752 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8753 PPC_NONE
, PPC2_BOOKE206
),
8754 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8755 PPC_NONE
, PPC2_BOOKE206
),
8756 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8757 PPC_NONE
, PPC2_PRCNTL
),
8758 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8759 PPC_NONE
, PPC2_PRCNTL
),
8760 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
8761 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
8762 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
8763 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
8764 PPC_BOOKE
, PPC2_BOOKE206
),
8765 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
8766 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8767 PPC_BOOKE
, PPC2_BOOKE206
),
8768 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
8769 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
8770 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
8771 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
8772 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
8773 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
8774 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
8775 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
8776 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
8777 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
8779 #undef GEN_INT_ARITH_ADD
8780 #undef GEN_INT_ARITH_ADD_CONST
8781 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8782 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8783 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8784 add_ca, compute_ca, compute_ov) \
8785 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8786 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
8787 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
8788 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
8789 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
8790 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
8791 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
8792 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
8793 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
8794 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
8795 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
8797 #undef GEN_INT_ARITH_DIVW
8798 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8799 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8800 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
8801 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
8802 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
8803 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
8805 #if defined(TARGET_PPC64)
8806 #undef GEN_INT_ARITH_DIVD
8807 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8808 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8809 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
8810 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
8811 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
8812 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
8814 #undef GEN_INT_ARITH_MUL_HELPER
8815 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8816 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8817 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
8818 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
8819 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
8822 #undef GEN_INT_ARITH_SUBF
8823 #undef GEN_INT_ARITH_SUBF_CONST
8824 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8825 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8826 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8827 add_ca, compute_ca, compute_ov) \
8828 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8829 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
8830 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
8831 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
8832 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
8833 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
8834 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
8835 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
8836 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
8837 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
8838 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
8842 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8843 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8844 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8845 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8846 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
8847 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8848 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8849 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8850 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8851 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8852 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8853 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8854 #if defined(TARGET_PPC64)
8855 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8858 #if defined(TARGET_PPC64)
8861 #define GEN_PPC64_R2(name, opc1, opc2) \
8862 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8863 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8865 #define GEN_PPC64_R4(name, opc1, opc2) \
8866 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8867 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8869 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8871 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8873 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
8874 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
8875 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
8876 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
8877 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
8878 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
8881 #undef _GEN_FLOAT_ACB
8882 #undef GEN_FLOAT_ACB
8883 #undef _GEN_FLOAT_AB
8885 #undef _GEN_FLOAT_AC
8889 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
8890 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
8891 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
8892 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
8893 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
8894 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8895 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8896 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
8897 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8898 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8899 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8900 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8901 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
8902 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8903 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8904 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
8905 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
8906 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
8907 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
8909 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
8910 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
8911 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
8912 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
8913 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
8914 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
8915 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
8916 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
8917 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
8918 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
8919 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
8920 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
8921 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
8922 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
8923 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
8924 #if defined(TARGET_PPC64)
8925 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
8926 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
8927 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
8929 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
8930 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
8931 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
8932 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
8933 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
),
8934 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
),
8935 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
),
8942 #define GEN_LD(name, ldop, opc, type) \
8943 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8944 #define GEN_LDU(name, ldop, opc, type) \
8945 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8946 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
8947 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8948 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
8949 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8950 #define GEN_LDS(name, ldop, op, type) \
8951 GEN_LD(name, ldop, op | 0x20, type) \
8952 GEN_LDU(name, ldop, op | 0x21, type) \
8953 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
8954 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8956 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
8957 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
8958 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
8959 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
8960 #if defined(TARGET_PPC64)
8961 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
8962 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
8963 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
8964 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
8965 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
8967 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
8968 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
8975 #define GEN_ST(name, stop, opc, type) \
8976 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8977 #define GEN_STU(name, stop, opc, type) \
8978 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8979 #define GEN_STUX(name, stop, opc2, opc3, type) \
8980 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8981 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
8982 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8983 #define GEN_STS(name, stop, op, type) \
8984 GEN_ST(name, stop, op | 0x20, type) \
8985 GEN_STU(name, stop, op | 0x21, type) \
8986 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
8987 GEN_STX(name, stop, 0x17, op | 0x00, type)
8989 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
8990 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
8991 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
8992 #if defined(TARGET_PPC64)
8993 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
8994 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
8995 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
8997 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
8998 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
9005 #define GEN_LDF(name, ldop, opc, type) \
9006 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9007 #define GEN_LDUF(name, ldop, opc, type) \
9008 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9009 #define GEN_LDUXF(name, ldop, opc, type) \
9010 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9011 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
9012 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9013 #define GEN_LDFS(name, ldop, op, type) \
9014 GEN_LDF(name, ldop, op | 0x20, type) \
9015 GEN_LDUF(name, ldop, op | 0x21, type) \
9016 GEN_LDUXF(name, ldop, op | 0x01, type) \
9017 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
9019 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
9020 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
9027 #define GEN_STF(name, stop, opc, type) \
9028 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9029 #define GEN_STUF(name, stop, opc, type) \
9030 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9031 #define GEN_STUXF(name, stop, opc, type) \
9032 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9033 #define GEN_STXF(name, stop, opc2, opc3, type) \
9034 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9035 #define GEN_STFS(name, stop, op, type) \
9036 GEN_STF(name, stop, op | 0x20, type) \
9037 GEN_STUF(name, stop, op | 0x21, type) \
9038 GEN_STUXF(name, stop, op | 0x01, type) \
9039 GEN_STXF(name, stop, 0x17, op | 0x00, type)
9041 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
9042 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
9043 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
9046 #define GEN_CRLOGIC(name, tcg_op, opc) \
9047 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
9048 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
9049 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
9050 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
9051 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
9052 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
9053 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
9054 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
9055 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
9057 #undef GEN_MAC_HANDLER
9058 #define GEN_MAC_HANDLER(name, opc2, opc3) \
9059 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
9060 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
9061 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
9062 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
9063 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
9064 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
9065 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
9066 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
9067 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
9068 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
9069 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
9070 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
9071 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
9072 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
9073 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
9074 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
9075 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
9076 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
9077 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
9078 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
9079 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
9080 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
9081 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
9082 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
9083 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
9084 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
9085 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
9086 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
9087 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
9088 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
9089 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
9090 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
9091 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
9092 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
9093 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
9094 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
9095 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
9096 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
9097 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
9098 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
9099 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
9100 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
9101 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
9107 #define GEN_VR_LDX(name, opc2, opc3) \
9108 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9109 #define GEN_VR_STX(name, opc2, opc3) \
9110 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9111 #define GEN_VR_LVE(name, opc2, opc3) \
9112 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9113 #define GEN_VR_STVE(name, opc2, opc3) \
9114 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9115 GEN_VR_LDX(lvx
, 0x07, 0x03),
9116 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
9117 GEN_VR_LVE(bx
, 0x07, 0x00),
9118 GEN_VR_LVE(hx
, 0x07, 0x01),
9119 GEN_VR_LVE(wx
, 0x07, 0x02),
9120 GEN_VR_STX(svx
, 0x07, 0x07),
9121 GEN_VR_STX(svxl
, 0x07, 0x0F),
9122 GEN_VR_STVE(bx
, 0x07, 0x04),
9123 GEN_VR_STVE(hx
, 0x07, 0x05),
9124 GEN_VR_STVE(wx
, 0x07, 0x06),
9126 #undef GEN_VX_LOGICAL
9127 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9128 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9129 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
9130 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
9131 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
9132 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
9133 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
9136 #define GEN_VXFORM(name, opc2, opc3) \
9137 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9138 GEN_VXFORM(vaddubm
, 0, 0),
9139 GEN_VXFORM(vadduhm
, 0, 1),
9140 GEN_VXFORM(vadduwm
, 0, 2),
9141 GEN_VXFORM(vsububm
, 0, 16),
9142 GEN_VXFORM(vsubuhm
, 0, 17),
9143 GEN_VXFORM(vsubuwm
, 0, 18),
9144 GEN_VXFORM(vmaxub
, 1, 0),
9145 GEN_VXFORM(vmaxuh
, 1, 1),
9146 GEN_VXFORM(vmaxuw
, 1, 2),
9147 GEN_VXFORM(vmaxsb
, 1, 4),
9148 GEN_VXFORM(vmaxsh
, 1, 5),
9149 GEN_VXFORM(vmaxsw
, 1, 6),
9150 GEN_VXFORM(vminub
, 1, 8),
9151 GEN_VXFORM(vminuh
, 1, 9),
9152 GEN_VXFORM(vminuw
, 1, 10),
9153 GEN_VXFORM(vminsb
, 1, 12),
9154 GEN_VXFORM(vminsh
, 1, 13),
9155 GEN_VXFORM(vminsw
, 1, 14),
9156 GEN_VXFORM(vavgub
, 1, 16),
9157 GEN_VXFORM(vavguh
, 1, 17),
9158 GEN_VXFORM(vavguw
, 1, 18),
9159 GEN_VXFORM(vavgsb
, 1, 20),
9160 GEN_VXFORM(vavgsh
, 1, 21),
9161 GEN_VXFORM(vavgsw
, 1, 22),
9162 GEN_VXFORM(vmrghb
, 6, 0),
9163 GEN_VXFORM(vmrghh
, 6, 1),
9164 GEN_VXFORM(vmrghw
, 6, 2),
9165 GEN_VXFORM(vmrglb
, 6, 4),
9166 GEN_VXFORM(vmrglh
, 6, 5),
9167 GEN_VXFORM(vmrglw
, 6, 6),
9168 GEN_VXFORM(vmuloub
, 4, 0),
9169 GEN_VXFORM(vmulouh
, 4, 1),
9170 GEN_VXFORM(vmulosb
, 4, 4),
9171 GEN_VXFORM(vmulosh
, 4, 5),
9172 GEN_VXFORM(vmuleub
, 4, 8),
9173 GEN_VXFORM(vmuleuh
, 4, 9),
9174 GEN_VXFORM(vmulesb
, 4, 12),
9175 GEN_VXFORM(vmulesh
, 4, 13),
9176 GEN_VXFORM(vslb
, 2, 4),
9177 GEN_VXFORM(vslh
, 2, 5),
9178 GEN_VXFORM(vslw
, 2, 6),
9179 GEN_VXFORM(vsrb
, 2, 8),
9180 GEN_VXFORM(vsrh
, 2, 9),
9181 GEN_VXFORM(vsrw
, 2, 10),
9182 GEN_VXFORM(vsrab
, 2, 12),
9183 GEN_VXFORM(vsrah
, 2, 13),
9184 GEN_VXFORM(vsraw
, 2, 14),
9185 GEN_VXFORM(vslo
, 6, 16),
9186 GEN_VXFORM(vsro
, 6, 17),
9187 GEN_VXFORM(vaddcuw
, 0, 6),
9188 GEN_VXFORM(vsubcuw
, 0, 22),
9189 GEN_VXFORM(vaddubs
, 0, 8),
9190 GEN_VXFORM(vadduhs
, 0, 9),
9191 GEN_VXFORM(vadduws
, 0, 10),
9192 GEN_VXFORM(vaddsbs
, 0, 12),
9193 GEN_VXFORM(vaddshs
, 0, 13),
9194 GEN_VXFORM(vaddsws
, 0, 14),
9195 GEN_VXFORM(vsububs
, 0, 24),
9196 GEN_VXFORM(vsubuhs
, 0, 25),
9197 GEN_VXFORM(vsubuws
, 0, 26),
9198 GEN_VXFORM(vsubsbs
, 0, 28),
9199 GEN_VXFORM(vsubshs
, 0, 29),
9200 GEN_VXFORM(vsubsws
, 0, 30),
9201 GEN_VXFORM(vrlb
, 2, 0),
9202 GEN_VXFORM(vrlh
, 2, 1),
9203 GEN_VXFORM(vrlw
, 2, 2),
9204 GEN_VXFORM(vsl
, 2, 7),
9205 GEN_VXFORM(vsr
, 2, 11),
9206 GEN_VXFORM(vpkuhum
, 7, 0),
9207 GEN_VXFORM(vpkuwum
, 7, 1),
9208 GEN_VXFORM(vpkuhus
, 7, 2),
9209 GEN_VXFORM(vpkuwus
, 7, 3),
9210 GEN_VXFORM(vpkshus
, 7, 4),
9211 GEN_VXFORM(vpkswus
, 7, 5),
9212 GEN_VXFORM(vpkshss
, 7, 6),
9213 GEN_VXFORM(vpkswss
, 7, 7),
9214 GEN_VXFORM(vpkpx
, 7, 12),
9215 GEN_VXFORM(vsum4ubs
, 4, 24),
9216 GEN_VXFORM(vsum4sbs
, 4, 28),
9217 GEN_VXFORM(vsum4shs
, 4, 25),
9218 GEN_VXFORM(vsum2sws
, 4, 26),
9219 GEN_VXFORM(vsumsws
, 4, 30),
9220 GEN_VXFORM(vaddfp
, 5, 0),
9221 GEN_VXFORM(vsubfp
, 5, 1),
9222 GEN_VXFORM(vmaxfp
, 5, 16),
9223 GEN_VXFORM(vminfp
, 5, 17),
9227 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
9228 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
9229 #define GEN_VXRFORM(name, opc2, opc3) \
9230 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
9231 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
9232 GEN_VXRFORM(vcmpequb
, 3, 0)
9233 GEN_VXRFORM(vcmpequh
, 3, 1)
9234 GEN_VXRFORM(vcmpequw
, 3, 2)
9235 GEN_VXRFORM(vcmpgtsb
, 3, 12)
9236 GEN_VXRFORM(vcmpgtsh
, 3, 13)
9237 GEN_VXRFORM(vcmpgtsw
, 3, 14)
9238 GEN_VXRFORM(vcmpgtub
, 3, 8)
9239 GEN_VXRFORM(vcmpgtuh
, 3, 9)
9240 GEN_VXRFORM(vcmpgtuw
, 3, 10)
9241 GEN_VXRFORM(vcmpeqfp
, 3, 3)
9242 GEN_VXRFORM(vcmpgefp
, 3, 7)
9243 GEN_VXRFORM(vcmpgtfp
, 3, 11)
9244 GEN_VXRFORM(vcmpbfp
, 3, 15)
9246 #undef GEN_VXFORM_SIMM
9247 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
9248 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9249 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
9250 GEN_VXFORM_SIMM(vspltish
, 6, 13),
9251 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
9253 #undef GEN_VXFORM_NOA
9254 #define GEN_VXFORM_NOA(name, opc2, opc3) \
9255 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9256 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
9257 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
9258 GEN_VXFORM_NOA(vupklsb
, 7, 10),
9259 GEN_VXFORM_NOA(vupklsh
, 7, 11),
9260 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
9261 GEN_VXFORM_NOA(vupklpx
, 7, 15),
9262 GEN_VXFORM_NOA(vrefp
, 5, 4),
9263 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
9264 GEN_VXFORM_NOA(vexptefp
, 5, 6),
9265 GEN_VXFORM_NOA(vlogefp
, 5, 7),
9266 GEN_VXFORM_NOA(vrfim
, 5, 8),
9267 GEN_VXFORM_NOA(vrfin
, 5, 9),
9268 GEN_VXFORM_NOA(vrfip
, 5, 10),
9269 GEN_VXFORM_NOA(vrfiz
, 5, 11),
9271 #undef GEN_VXFORM_UIMM
9272 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
9273 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9274 GEN_VXFORM_UIMM(vspltb
, 6, 8),
9275 GEN_VXFORM_UIMM(vsplth
, 6, 9),
9276 GEN_VXFORM_UIMM(vspltw
, 6, 10),
9277 GEN_VXFORM_UIMM(vcfux
, 5, 12),
9278 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
9279 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
9280 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
9282 #undef GEN_VAFORM_PAIRED
9283 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9284 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9285 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
9286 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
9287 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
9288 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
9289 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
9290 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
9293 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
9294 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
9295 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9296 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9297 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9298 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9299 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9300 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9301 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9302 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
9303 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
9304 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9305 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9306 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9307 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9308 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9309 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9310 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
9311 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9312 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9313 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9314 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9315 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9316 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9317 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9318 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9319 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9320 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9321 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9322 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9323 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
9325 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9326 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9327 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9328 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9329 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9330 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9331 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9332 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9333 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9334 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9335 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9336 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9337 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9338 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9340 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9341 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9342 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9343 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9344 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9345 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
9346 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9347 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9348 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9349 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9350 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9351 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9352 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9353 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9355 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9356 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9357 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
9358 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9359 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9360 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9361 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9362 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
9363 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9364 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9365 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9366 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9367 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9368 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9369 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9370 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9372 #undef GEN_SPEOP_LDST
9373 #define GEN_SPEOP_LDST(name, opc2, sh) \
9374 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9375 GEN_SPEOP_LDST(evldd
, 0x00, 3),
9376 GEN_SPEOP_LDST(evldw
, 0x01, 3),
9377 GEN_SPEOP_LDST(evldh
, 0x02, 3),
9378 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
9379 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
9380 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
9381 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
9382 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
9383 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
9384 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
9385 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
9387 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
9388 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
9389 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
9390 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
9391 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
9392 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
9393 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
9396 #include "helper_regs.h"
9397 #include "translate_init.c"
9399 /*****************************************************************************/
9400 /* Misc PowerPC helpers */
9401 void cpu_dump_state (CPUPPCState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
9409 cpu_synchronize_state(env
);
9411 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
9412 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
9413 env
->nip
, env
->lr
, env
->ctr
, env
->xer
);
9414 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
9415 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
9416 env
->hflags
, env
->mmu_idx
);
9417 #if !defined(NO_TIMER_DUMP)
9418 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
9419 #if !defined(CONFIG_USER_ONLY)
9423 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
9424 #if !defined(CONFIG_USER_ONLY)
9425 , cpu_ppc_load_decr(env
)
9429 for (i
= 0; i
< 32; i
++) {
9430 if ((i
& (RGPL
- 1)) == 0)
9431 cpu_fprintf(f
, "GPR%02d", i
);
9432 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
9433 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
9434 cpu_fprintf(f
, "\n");
9436 cpu_fprintf(f
, "CR ");
9437 for (i
= 0; i
< 8; i
++)
9438 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
9439 cpu_fprintf(f
, " [");
9440 for (i
= 0; i
< 8; i
++) {
9442 if (env
->crf
[i
] & 0x08)
9444 else if (env
->crf
[i
] & 0x04)
9446 else if (env
->crf
[i
] & 0x02)
9448 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
9450 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
9452 for (i
= 0; i
< 32; i
++) {
9453 if ((i
& (RFPL
- 1)) == 0)
9454 cpu_fprintf(f
, "FPR%02d", i
);
9455 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
9456 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
9457 cpu_fprintf(f
, "\n");
9459 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
9460 #if !defined(CONFIG_USER_ONLY)
9461 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
9462 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
9463 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
9464 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
9466 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
9467 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
9468 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
9469 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
9471 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
9472 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
9473 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
9474 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
9476 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
9477 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
9478 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
9479 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
9480 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
9482 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
9483 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
9484 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
9485 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
9487 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
9488 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
9489 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
9490 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
9492 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
9493 " EPR " TARGET_FMT_lx
"\n",
9494 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
9495 env
->spr
[SPR_BOOKE_EPR
]);
9498 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
9499 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
9500 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
9501 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
9504 * IVORs are left out as they are large and do not change often --
9505 * they can be read with "p $ivor0", "p $ivor1", etc.
9509 #if defined(TARGET_PPC64)
9510 if (env
->flags
& POWERPC_FLAG_CFAR
) {
9511 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
9515 switch (env
->mmu_model
) {
9516 case POWERPC_MMU_32B
:
9517 case POWERPC_MMU_601
:
9518 case POWERPC_MMU_SOFT_6xx
:
9519 case POWERPC_MMU_SOFT_74xx
:
9520 #if defined(TARGET_PPC64)
9521 case POWERPC_MMU_620
:
9522 case POWERPC_MMU_64B
:
9524 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
]);
9526 case POWERPC_MMU_BOOKE206
:
9527 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
9528 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
9529 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
9530 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
9532 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
9533 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
9534 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
9535 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
9537 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
9538 " TLB1CFG " TARGET_FMT_lx
"\n",
9539 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
9540 env
->spr
[SPR_BOOKE_TLB1CFG
]);
9551 void cpu_dump_statistics (CPUPPCState
*env
, FILE*f
, fprintf_function cpu_fprintf
,
9554 #if defined(DO_PPC_STATISTICS)
9555 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
9559 for (op1
= 0; op1
< 64; op1
++) {
9561 if (is_indirect_opcode(handler
)) {
9562 t2
= ind_table(handler
);
9563 for (op2
= 0; op2
< 32; op2
++) {
9565 if (is_indirect_opcode(handler
)) {
9566 t3
= ind_table(handler
);
9567 for (op3
= 0; op3
< 32; op3
++) {
9569 if (handler
->count
== 0)
9571 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
9572 "%016" PRIx64
" %" PRId64
"\n",
9573 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
9575 handler
->count
, handler
->count
);
9578 if (handler
->count
== 0)
9580 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
9581 "%016" PRIx64
" %" PRId64
"\n",
9582 op1
, op2
, op1
, op2
, handler
->oname
,
9583 handler
->count
, handler
->count
);
9587 if (handler
->count
== 0)
9589 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
9591 op1
, op1
, handler
->oname
,
9592 handler
->count
, handler
->count
);
9598 /*****************************************************************************/
9599 static inline void gen_intermediate_code_internal(CPUPPCState
*env
,
9600 TranslationBlock
*tb
,
9603 DisasContext ctx
, *ctxp
= &ctx
;
9604 opc_handler_t
**table
, *handler
;
9605 target_ulong pc_start
;
9606 uint16_t *gen_opc_end
;
9613 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
9616 ctx
.exception
= POWERPC_EXCP_NONE
;
9617 ctx
.spr_cb
= env
->spr_cb
;
9618 ctx
.mem_idx
= env
->mmu_idx
;
9619 ctx
.access_type
= -1;
9620 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
9621 #if defined(TARGET_PPC64)
9622 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
9623 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
9625 ctx
.fpu_enabled
= msr_fp
;
9626 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
9627 ctx
.spe_enabled
= msr_spe
;
9629 ctx
.spe_enabled
= 0;
9630 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
9631 ctx
.altivec_enabled
= msr_vr
;
9633 ctx
.altivec_enabled
= 0;
9634 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
9635 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
9637 ctx
.singlestep_enabled
= 0;
9638 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
9639 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
9640 if (unlikely(env
->singlestep_enabled
))
9641 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
9642 #if defined (DO_SINGLE_STEP) && 0
9643 /* Single step trace mode */
9647 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9649 max_insns
= CF_COUNT_MASK
;
9652 /* Set env in case of segfault during code fetch */
9653 while (ctx
.exception
== POWERPC_EXCP_NONE
9654 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
) {
9655 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9656 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9657 if (bp
->pc
== ctx
.nip
) {
9658 gen_debug_exception(ctxp
);
9663 if (unlikely(search_pc
)) {
9664 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9668 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9670 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.nip
;
9671 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
9672 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
9674 LOG_DISAS("----------------\n");
9675 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
9676 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
9677 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9679 if (unlikely(ctx
.le_mode
)) {
9680 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
9682 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
9684 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9685 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9686 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
9687 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
9688 tcg_gen_debug_insn_start(ctx
.nip
);
9691 table
= env
->opcodes
;
9693 handler
= table
[opc1(ctx
.opcode
)];
9694 if (is_indirect_opcode(handler
)) {
9695 table
= ind_table(handler
);
9696 handler
= table
[opc2(ctx
.opcode
)];
9697 if (is_indirect_opcode(handler
)) {
9698 table
= ind_table(handler
);
9699 handler
= table
[opc3(ctx
.opcode
)];
9702 /* Is opcode *REALLY* valid ? */
9703 if (unlikely(handler
->handler
== &gen_invalid
)) {
9704 if (qemu_log_enabled()) {
9705 qemu_log("invalid/unsupported opcode: "
9706 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
9707 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9708 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
9713 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
9714 inval
= handler
->inval2
;
9716 inval
= handler
->inval1
;
9719 if (unlikely((ctx
.opcode
& inval
) != 0)) {
9720 if (qemu_log_enabled()) {
9721 qemu_log("invalid bits: %08x for opcode: "
9722 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
9723 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
9724 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
9725 ctx
.opcode
, ctx
.nip
- 4);
9727 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
9731 (*(handler
->handler
))(&ctx
);
9732 #if defined(DO_PPC_STATISTICS)
9735 /* Check trace mode exceptions */
9736 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
9737 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
9738 ctx
.exception
!= POWERPC_SYSCALL
&&
9739 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
9740 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
9741 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
9742 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
9743 (env
->singlestep_enabled
) ||
9745 num_insns
>= max_insns
)) {
9746 /* if we reach a page boundary or are single stepping, stop
9752 if (tb
->cflags
& CF_LAST_IO
)
9754 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
9755 gen_goto_tb(&ctx
, 0, ctx
.nip
);
9756 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
9757 if (unlikely(env
->singlestep_enabled
)) {
9758 gen_debug_exception(ctxp
);
9760 /* Generate the return instruction */
9763 gen_icount_end(tb
, num_insns
);
9764 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
9765 if (unlikely(search_pc
)) {
9766 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9769 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9771 tb
->size
= ctx
.nip
- pc_start
;
9772 tb
->icount
= num_insns
;
9774 #if defined(DEBUG_DISAS)
9775 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9777 flags
= env
->bfd_mach
;
9778 flags
|= ctx
.le_mode
<< 16;
9779 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9780 log_target_disas(env
, pc_start
, ctx
.nip
- pc_start
, flags
);
9786 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9788 gen_intermediate_code_internal(env
, tb
, 0);
9791 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9793 gen_intermediate_code_internal(env
, tb
, 1);
9796 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
9798 env
->nip
= tcg_ctx
.gen_opc_pc
[pc_pos
];