2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
23 #include "disas/disas.h"
24 #include "exec/exec-all.h"
26 #include "qemu/host-utils.h"
27 #include "exec/cpu_ldst.h"
29 #include "exec/helper-proto.h"
30 #include "exec/helper-gen.h"
32 #include "trace-tcg.h"
36 #define CPU_SINGLE_STEP 0x1
37 #define CPU_BRANCH_STEP 0x2
38 #define GDBSTUB_SINGLE_STEP 0x4
40 /* Include definitions for instructions classes and implementations flags */
41 //#define PPC_DEBUG_DISAS
42 //#define DO_PPC_STATISTICS
44 #ifdef PPC_DEBUG_DISAS
45 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
47 # define LOG_DISAS(...) do { } while (0)
49 /*****************************************************************************/
50 /* Code translation helpers */
52 /* global register indexes */
53 static TCGv_env cpu_env;
54 static char cpu_reg_names[10*3 + 22*4 /* GPR */
55 + 10*4 + 22*5 /* SPE GPRh */
56 + 10*4 + 22*5 /* FPR */
57 + 2*(10*6 + 22*7) /* AVRh, AVRl */
58 + 10*5 + 22*6 /* VSR */
60 static TCGv cpu_gpr[32];
61 static TCGv cpu_gprh[32];
62 static TCGv_i64 cpu_fpr[32];
63 static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
64 static TCGv_i64 cpu_vsr[32];
65 static TCGv_i32 cpu_crf[8];
70 #if defined(TARGET_PPC64)
73 static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
74 static TCGv cpu_reserve;
75 static TCGv cpu_fpscr;
76 static TCGv_i32 cpu_access_type;
78 #include "exec/gen-icount.h"
80 void ppc_translate_init(void)
84 size_t cpu_reg_names_size;
85 static int done_init = 0;
90 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
91 tcg_ctx.tcg_env = cpu_env;
94 cpu_reg_names_size = sizeof(cpu_reg_names);
96 for (i = 0; i < 8; i++) {
97 snprintf(p, cpu_reg_names_size, "crf%d", i);
98 cpu_crf[i] = tcg_global_mem_new_i32(cpu_env,
99 offsetof(CPUPPCState, crf[i]), p);
101 cpu_reg_names_size -= 5;
104 for (i = 0; i < 32; i++) {
105 snprintf(p, cpu_reg_names_size, "r%d", i);
106 cpu_gpr[i] = tcg_global_mem_new(cpu_env,
107 offsetof(CPUPPCState, gpr[i]), p);
108 p += (i < 10) ? 3 : 4;
109 cpu_reg_names_size -= (i < 10) ? 3 : 4;
110 snprintf(p, cpu_reg_names_size, "r%dH", i);
111 cpu_gprh[i] = tcg_global_mem_new(cpu_env,
112 offsetof(CPUPPCState, gprh[i]), p);
113 p += (i < 10) ? 4 : 5;
114 cpu_reg_names_size -= (i < 10) ? 4 : 5;
116 snprintf(p, cpu_reg_names_size, "fp%d", i);
117 cpu_fpr[i] = tcg_global_mem_new_i64(cpu_env,
118 offsetof(CPUPPCState, fpr[i]), p);
119 p += (i < 10) ? 4 : 5;
120 cpu_reg_names_size -= (i < 10) ? 4 : 5;
122 snprintf(p, cpu_reg_names_size, "avr%dH", i);
123 #ifdef HOST_WORDS_BIGENDIAN
124 cpu_avrh[i] = tcg_global_mem_new_i64(cpu_env,
125 offsetof(CPUPPCState, avr[i].u64[0]), p);
127 cpu_avrh[i] = tcg_global_mem_new_i64(cpu_env,
128 offsetof(CPUPPCState, avr[i].u64[1]), p);
130 p += (i < 10) ? 6 : 7;
131 cpu_reg_names_size -= (i < 10) ? 6 : 7;
133 snprintf(p, cpu_reg_names_size, "avr%dL", i);
134 #ifdef HOST_WORDS_BIGENDIAN
135 cpu_avrl[i] = tcg_global_mem_new_i64(cpu_env,
136 offsetof(CPUPPCState, avr[i].u64[1]), p);
138 cpu_avrl[i] = tcg_global_mem_new_i64(cpu_env,
139 offsetof(CPUPPCState, avr[i].u64[0]), p);
141 p += (i < 10) ? 6 : 7;
142 cpu_reg_names_size -= (i < 10) ? 6 : 7;
143 snprintf(p, cpu_reg_names_size, "vsr%d", i);
144 cpu_vsr[i] = tcg_global_mem_new_i64(cpu_env,
145 offsetof(CPUPPCState, vsr[i]), p);
146 p += (i < 10) ? 5 : 6;
147 cpu_reg_names_size -= (i < 10) ? 5 : 6;
150 cpu_nip = tcg_global_mem_new(cpu_env,
151 offsetof(CPUPPCState, nip), "nip");
153 cpu_msr = tcg_global_mem_new(cpu_env,
154 offsetof(CPUPPCState, msr), "msr");
156 cpu_ctr = tcg_global_mem_new(cpu_env,
157 offsetof(CPUPPCState, ctr), "ctr");
159 cpu_lr = tcg_global_mem_new(cpu_env,
160 offsetof(CPUPPCState, lr), "lr");
162 #if defined(TARGET_PPC64)
163 cpu_cfar = tcg_global_mem_new(cpu_env,
164 offsetof(CPUPPCState, cfar), "cfar");
167 cpu_xer = tcg_global_mem_new(cpu_env,
168 offsetof(CPUPPCState, xer), "xer");
169 cpu_so = tcg_global_mem_new(cpu_env,
170 offsetof(CPUPPCState, so), "SO");
171 cpu_ov = tcg_global_mem_new(cpu_env,
172 offsetof(CPUPPCState, ov), "OV");
173 cpu_ca = tcg_global_mem_new(cpu_env,
174 offsetof(CPUPPCState, ca), "CA");
176 cpu_reserve = tcg_global_mem_new(cpu_env,
177 offsetof(CPUPPCState, reserve_addr),
180 cpu_fpscr = tcg_global_mem_new(cpu_env,
181 offsetof(CPUPPCState, fpscr), "fpscr");
183 cpu_access_type = tcg_global_mem_new_i32(cpu_env,
184 offsetof(CPUPPCState, access_type), "access_type");
189 /* internal defines */
190 struct DisasContext {
191 struct TranslationBlock *tb;
195 /* Routine used to access memory */
196 bool pr, hv, dr, le_mode;
200 /* Translation flags */
201 TCGMemOp default_tcg_memop_mask;
202 #if defined(TARGET_PPC64)
207 bool altivec_enabled;
211 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
212 int singlestep_enabled;
213 uint64_t insns_flags;
214 uint64_t insns_flags2;
217 /* Return true iff byteswap is needed in a scalar memop */
218 static inline bool need_byteswap(const DisasContext *ctx)
220 #if defined(TARGET_WORDS_BIGENDIAN)
223 return !ctx->le_mode;
227 /* True when active word size < size of target_long. */
229 # define NARROW_MODE(C) (!(C)->sf_mode)
231 # define NARROW_MODE(C) 0
234 struct opc_handler_t {
235 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
237 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
239 /* instruction type */
241 /* extended instruction type */
244 void (*handler)(DisasContext *ctx);
245 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
248 #if defined(DO_PPC_STATISTICS)
253 static inline void gen_reset_fpstatus(void)
255 gen_helper_reset_fpstatus(cpu_env);
258 static inline void gen_compute_fprf(TCGv_i64 arg)
260 gen_helper_compute_fprf(cpu_env, arg);
261 gen_helper_float_check_status(cpu_env);
264 static inline void gen_set_access_type(DisasContext *ctx, int access_type)
266 if (ctx->access_type != access_type) {
267 tcg_gen_movi_i32(cpu_access_type, access_type);
268 ctx->access_type = access_type;
272 static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
274 if (NARROW_MODE(ctx)) {
277 tcg_gen_movi_tl(cpu_nip, nip);
280 void gen_update_current_nip(void *opaque)
282 DisasContext *ctx = opaque;
284 tcg_gen_movi_tl(cpu_nip, ctx->nip);
287 static void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
290 if (ctx->exception == POWERPC_EXCP_NONE) {
291 gen_update_nip(ctx, ctx->nip);
293 t0 = tcg_const_i32(excp);
294 t1 = tcg_const_i32(error);
295 gen_helper_raise_exception_err(cpu_env, t0, t1);
296 tcg_temp_free_i32(t0);
297 tcg_temp_free_i32(t1);
298 ctx->exception = (excp);
301 static void gen_exception(DisasContext *ctx, uint32_t excp)
304 if (ctx->exception == POWERPC_EXCP_NONE) {
305 gen_update_nip(ctx, ctx->nip);
307 t0 = tcg_const_i32(excp);
308 gen_helper_raise_exception(cpu_env, t0);
309 tcg_temp_free_i32(t0);
310 ctx->exception = (excp);
313 static void gen_debug_exception(DisasContext *ctx)
317 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
318 (ctx->exception != POWERPC_EXCP_SYNC)) {
319 gen_update_nip(ctx, ctx->nip);
321 t0 = tcg_const_i32(EXCP_DEBUG);
322 gen_helper_raise_exception(cpu_env, t0);
323 tcg_temp_free_i32(t0);
326 static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
328 /* Will be converted to program check if needed */
329 gen_exception_err(ctx, POWERPC_EXCP_HV_EMU, POWERPC_EXCP_INVAL | error);
332 static inline void gen_priv_exception(DisasContext *ctx, uint32_t error)
334 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_PRIV | error);
337 static inline void gen_hvpriv_exception(DisasContext *ctx, uint32_t error)
339 /* Will be converted to program check if needed */
340 gen_exception_err(ctx, POWERPC_EXCP_HV_EMU, POWERPC_EXCP_PRIV | error);
343 /* Stop translation */
344 static inline void gen_stop_exception(DisasContext *ctx)
346 gen_update_nip(ctx, ctx->nip);
347 ctx->exception = POWERPC_EXCP_STOP;
350 #ifndef CONFIG_USER_ONLY
351 /* No need to update nip here, as execution flow will change */
352 static inline void gen_sync_exception(DisasContext *ctx)
354 ctx->exception = POWERPC_EXCP_SYNC;
358 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
359 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
361 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
362 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
364 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
365 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
367 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
368 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
370 typedef struct opcode_t {
371 unsigned char opc1, opc2, opc3;
372 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
373 unsigned char pad[5];
375 unsigned char pad[1];
377 opc_handler_t handler;
381 /* Helpers for priv. check */
384 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \
387 #if defined(CONFIG_USER_ONLY)
388 #define CHK_HV GEN_PRIV
389 #define CHK_SV GEN_PRIV
390 #define CHK_HVRM GEN_PRIV
394 if (unlikely(ctx->pr || !ctx->hv)) { \
400 if (unlikely(ctx->pr)) { \
406 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
415 /*****************************************************************************/
416 /*** Instruction decoding ***/
417 #define EXTRACT_HELPER(name, shift, nb) \
418 static inline uint32_t name(uint32_t opcode) \
420 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
423 #define EXTRACT_SHELPER(name, shift, nb) \
424 static inline int32_t name(uint32_t opcode) \
426 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
429 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
430 static inline uint32_t name(uint32_t opcode) \
432 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
433 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
436 #define EXTRACT_HELPER_DXFORM(name, \
437 d0_bits, shift_op_d0, shift_d0, \
438 d1_bits, shift_op_d1, shift_d1, \
439 d2_bits, shift_op_d2, shift_d2) \
440 static inline int16_t name(uint32_t opcode) \
443 (((opcode >> (shift_op_d0)) & ((1 << (d0_bits)) - 1)) << (shift_d0)) | \
444 (((opcode >> (shift_op_d1)) & ((1 << (d1_bits)) - 1)) << (shift_d1)) | \
445 (((opcode >> (shift_op_d2)) & ((1 << (d2_bits)) - 1)) << (shift_d2)); \
450 EXTRACT_HELPER(opc1, 26, 6);
452 EXTRACT_HELPER(opc2, 1, 5);
454 EXTRACT_HELPER(opc3, 6, 5);
455 /* Update Cr0 flags */
456 EXTRACT_HELPER(Rc, 0, 1);
457 /* Update Cr6 flags (Altivec) */
458 EXTRACT_HELPER(Rc21, 10, 1);
460 EXTRACT_HELPER(rD, 21, 5);
462 EXTRACT_HELPER(rS, 21, 5);
464 EXTRACT_HELPER(rA, 16, 5);
466 EXTRACT_HELPER(rB, 11, 5);
468 EXTRACT_HELPER(rC, 6, 5);
470 EXTRACT_HELPER(crfD, 23, 3);
471 EXTRACT_HELPER(crfS, 18, 3);
472 EXTRACT_HELPER(crbD, 21, 5);
473 EXTRACT_HELPER(crbA, 16, 5);
474 EXTRACT_HELPER(crbB, 11, 5);
476 EXTRACT_HELPER(_SPR, 11, 10);
477 static inline uint32_t SPR(uint32_t opcode)
479 uint32_t sprn = _SPR(opcode);
481 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
483 /*** Get constants ***/
484 /* 16 bits signed immediate value */
485 EXTRACT_SHELPER(SIMM, 0, 16);
486 /* 16 bits unsigned immediate value */
487 EXTRACT_HELPER(UIMM, 0, 16);
488 /* 5 bits signed immediate value */
489 EXTRACT_HELPER(SIMM5, 16, 5);
490 /* 5 bits signed immediate value */
491 EXTRACT_HELPER(UIMM5, 16, 5);
493 EXTRACT_HELPER(NB, 11, 5);
495 EXTRACT_HELPER(SH, 11, 5);
496 /* Vector shift count */
497 EXTRACT_HELPER(VSH, 6, 4);
499 EXTRACT_HELPER(MB, 6, 5);
501 EXTRACT_HELPER(ME, 1, 5);
503 EXTRACT_HELPER(TO, 21, 5);
505 EXTRACT_HELPER(CRM, 12, 8);
507 #ifndef CONFIG_USER_ONLY
508 EXTRACT_HELPER(SR, 16, 4);
512 EXTRACT_HELPER(FPBF, 23, 3);
513 EXTRACT_HELPER(FPIMM, 12, 4);
514 EXTRACT_HELPER(FPL, 25, 1);
515 EXTRACT_HELPER(FPFLM, 17, 8);
516 EXTRACT_HELPER(FPW, 16, 1);
519 EXTRACT_HELPER_DXFORM(DX, 10, 6, 6, 5, 16, 1, 1, 0, 0)
521 /*** Jump target decoding ***/
522 /* Immediate address */
523 static inline target_ulong LI(uint32_t opcode)
525 return (opcode >> 0) & 0x03FFFFFC;
528 static inline uint32_t BD(uint32_t opcode)
530 return (opcode >> 0) & 0xFFFC;
533 EXTRACT_HELPER(BO, 21, 5);
534 EXTRACT_HELPER(BI, 16, 5);
535 /* Absolute/relative address */
536 EXTRACT_HELPER(AA, 1, 1);
538 EXTRACT_HELPER(LK, 0, 1);
541 EXTRACT_HELPER(DCM, 10, 6)
544 EXTRACT_HELPER(RMC, 9, 2)
546 /* Create a mask between <start> and <end> bits */
547 static inline target_ulong MASK(uint32_t start, uint32_t end)
551 #if defined(TARGET_PPC64)
552 if (likely(start == 0)) {
553 ret = UINT64_MAX << (63 - end);
554 } else if (likely(end == 63)) {
555 ret = UINT64_MAX >> start;
558 if (likely(start == 0)) {
559 ret = UINT32_MAX << (31 - end);
560 } else if (likely(end == 31)) {
561 ret = UINT32_MAX >> start;
565 ret = (((target_ulong)(-1ULL)) >> (start)) ^
566 (((target_ulong)(-1ULL) >> (end)) >> 1);
567 if (unlikely(start > end))
574 EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
575 EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
576 EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
577 EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
578 EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
579 EXTRACT_HELPER(DM, 8, 2);
580 EXTRACT_HELPER(UIM, 16, 2);
581 EXTRACT_HELPER(SHW, 8, 2);
582 EXTRACT_HELPER(SP, 19, 2);
583 /*****************************************************************************/
584 /* PowerPC instructions table */
586 #if defined(DO_PPC_STATISTICS)
587 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
597 .handler = &gen_##name, \
598 .oname = stringify(name), \
600 .oname = stringify(name), \
602 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
613 .handler = &gen_##name, \
614 .oname = stringify(name), \
616 .oname = stringify(name), \
618 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
628 .handler = &gen_##name, \
634 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
644 .handler = &gen_##name, \
646 .oname = stringify(name), \
648 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
659 .handler = &gen_##name, \
661 .oname = stringify(name), \
663 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
673 .handler = &gen_##name, \
679 /* SPR load/store helpers */
680 static inline void gen_load_spr(TCGv t, int reg)
682 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
685 static inline void gen_store_spr(int reg, TCGv t)
687 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
690 /* Invalid instruction */
691 static void gen_invalid(DisasContext *ctx)
693 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
696 static opc_handler_t invalid_handler = {
697 .inval1 = 0xFFFFFFFF,
698 .inval2 = 0xFFFFFFFF,
701 .handler = gen_invalid,
704 /*** Integer comparison ***/
706 static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
708 TCGv t0 = tcg_temp_new();
709 TCGv_i32 t1 = tcg_temp_new_i32();
711 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
713 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
714 tcg_gen_trunc_tl_i32(t1, t0);
715 tcg_gen_shli_i32(t1, t1, CRF_LT);
716 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
718 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
719 tcg_gen_trunc_tl_i32(t1, t0);
720 tcg_gen_shli_i32(t1, t1, CRF_GT);
721 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
723 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
724 tcg_gen_trunc_tl_i32(t1, t0);
725 tcg_gen_shli_i32(t1, t1, CRF_EQ);
726 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
729 tcg_temp_free_i32(t1);
732 static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
734 TCGv t0 = tcg_const_tl(arg1);
735 gen_op_cmp(arg0, t0, s, crf);
739 static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
745 tcg_gen_ext32s_tl(t0, arg0);
746 tcg_gen_ext32s_tl(t1, arg1);
748 tcg_gen_ext32u_tl(t0, arg0);
749 tcg_gen_ext32u_tl(t1, arg1);
751 gen_op_cmp(t0, t1, s, crf);
756 static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
758 TCGv t0 = tcg_const_tl(arg1);
759 gen_op_cmp32(arg0, t0, s, crf);
763 static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
765 if (NARROW_MODE(ctx)) {
766 gen_op_cmpi32(reg, 0, 1, 0);
768 gen_op_cmpi(reg, 0, 1, 0);
773 static void gen_cmp(DisasContext *ctx)
775 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
776 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
777 1, crfD(ctx->opcode));
779 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
780 1, crfD(ctx->opcode));
785 static void gen_cmpi(DisasContext *ctx)
787 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
788 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
789 1, crfD(ctx->opcode));
791 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
792 1, crfD(ctx->opcode));
797 static void gen_cmpl(DisasContext *ctx)
799 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
800 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
801 0, crfD(ctx->opcode));
803 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
804 0, crfD(ctx->opcode));
809 static void gen_cmpli(DisasContext *ctx)
811 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
812 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
813 0, crfD(ctx->opcode));
815 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
816 0, crfD(ctx->opcode));
820 /* cmprb - range comparison: isupper, isaplha, islower*/
821 static void gen_cmprb(DisasContext *ctx)
823 TCGv_i32 src1 = tcg_temp_new_i32();
824 TCGv_i32 src2 = tcg_temp_new_i32();
825 TCGv_i32 src2lo = tcg_temp_new_i32();
826 TCGv_i32 src2hi = tcg_temp_new_i32();
827 TCGv_i32 crf = cpu_crf[crfD(ctx->opcode)];
829 tcg_gen_trunc_tl_i32(src1, cpu_gpr[rA(ctx->opcode)]);
830 tcg_gen_trunc_tl_i32(src2, cpu_gpr[rB(ctx->opcode)]);
832 tcg_gen_andi_i32(src1, src1, 0xFF);
833 tcg_gen_ext8u_i32(src2lo, src2);
834 tcg_gen_shri_i32(src2, src2, 8);
835 tcg_gen_ext8u_i32(src2hi, src2);
837 tcg_gen_setcond_i32(TCG_COND_LEU, src2lo, src2lo, src1);
838 tcg_gen_setcond_i32(TCG_COND_LEU, src2hi, src1, src2hi);
839 tcg_gen_and_i32(crf, src2lo, src2hi);
841 if (ctx->opcode & 0x00200000) {
842 tcg_gen_shri_i32(src2, src2, 8);
843 tcg_gen_ext8u_i32(src2lo, src2);
844 tcg_gen_shri_i32(src2, src2, 8);
845 tcg_gen_ext8u_i32(src2hi, src2);
846 tcg_gen_setcond_i32(TCG_COND_LEU, src2lo, src2lo, src1);
847 tcg_gen_setcond_i32(TCG_COND_LEU, src2hi, src1, src2hi);
848 tcg_gen_and_i32(src2lo, src2lo, src2hi);
849 tcg_gen_or_i32(crf, crf, src2lo);
851 tcg_gen_shli_i32(crf, crf, CRF_GT);
852 tcg_temp_free_i32(src1);
853 tcg_temp_free_i32(src2);
854 tcg_temp_free_i32(src2lo);
855 tcg_temp_free_i32(src2hi);
858 /* isel (PowerPC 2.03 specification) */
859 static void gen_isel(DisasContext *ctx)
861 uint32_t bi = rC(ctx->opcode);
862 uint32_t mask = 0x08 >> (bi & 0x03);
863 TCGv t0 = tcg_temp_new();
866 tcg_gen_extu_i32_tl(t0, cpu_crf[bi >> 2]);
867 tcg_gen_andi_tl(t0, t0, mask);
869 zr = tcg_const_tl(0);
870 tcg_gen_movcond_tl(TCG_COND_NE, cpu_gpr[rD(ctx->opcode)], t0, zr,
871 rA(ctx->opcode) ? cpu_gpr[rA(ctx->opcode)] : zr,
872 cpu_gpr[rB(ctx->opcode)]);
877 /* cmpb: PowerPC 2.05 specification */
878 static void gen_cmpb(DisasContext *ctx)
880 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
881 cpu_gpr[rB(ctx->opcode)]);
884 /*** Integer arithmetic ***/
886 static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
887 TCGv arg1, TCGv arg2, int sub)
889 TCGv t0 = tcg_temp_new();
891 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
892 tcg_gen_xor_tl(t0, arg1, arg2);
894 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
896 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
899 if (NARROW_MODE(ctx)) {
900 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
902 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
903 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
906 /* Common add function */
907 static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
908 TCGv arg2, bool add_ca, bool compute_ca,
909 bool compute_ov, bool compute_rc0)
913 if (compute_ca || compute_ov) {
918 if (NARROW_MODE(ctx)) {
919 /* Caution: a non-obvious corner case of the spec is that we
920 must produce the *entire* 64-bit addition, but produce the
921 carry into bit 32. */
922 TCGv t1 = tcg_temp_new();
923 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
924 tcg_gen_add_tl(t0, arg1, arg2);
926 tcg_gen_add_tl(t0, t0, cpu_ca);
928 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
930 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
931 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
933 TCGv zero = tcg_const_tl(0);
935 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
936 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
938 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
943 tcg_gen_add_tl(t0, arg1, arg2);
945 tcg_gen_add_tl(t0, t0, cpu_ca);
950 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
952 if (unlikely(compute_rc0)) {
953 gen_set_Rc0(ctx, t0);
956 if (!TCGV_EQUAL(t0, ret)) {
957 tcg_gen_mov_tl(ret, t0);
961 /* Add functions with two operands */
962 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
963 static void glue(gen_, name)(DisasContext *ctx) \
965 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
966 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
967 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
969 /* Add functions with one operand and one immediate */
970 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
971 add_ca, compute_ca, compute_ov) \
972 static void glue(gen_, name)(DisasContext *ctx) \
974 TCGv t0 = tcg_const_tl(const_val); \
975 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
976 cpu_gpr[rA(ctx->opcode)], t0, \
977 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
981 /* add add. addo addo. */
982 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
983 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
984 /* addc addc. addco addco. */
985 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
986 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
987 /* adde adde. addeo addeo. */
988 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
989 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
990 /* addme addme. addmeo addmeo. */
991 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
992 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
993 /* addze addze. addzeo addzeo.*/
994 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
995 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
997 static void gen_addi(DisasContext *ctx)
999 target_long simm = SIMM(ctx->opcode);
1001 if (rA(ctx->opcode) == 0) {
1003 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
1005 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
1006 cpu_gpr[rA(ctx->opcode)], simm);
1010 static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
1012 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1013 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1014 c, 0, 1, 0, compute_rc0);
1018 static void gen_addic(DisasContext *ctx)
1020 gen_op_addic(ctx, 0);
1023 static void gen_addic_(DisasContext *ctx)
1025 gen_op_addic(ctx, 1);
1029 static void gen_addis(DisasContext *ctx)
1031 target_long simm = SIMM(ctx->opcode);
1033 if (rA(ctx->opcode) == 0) {
1035 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
1037 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
1038 cpu_gpr[rA(ctx->opcode)], simm << 16);
1043 static void gen_addpcis(DisasContext *ctx)
1045 target_long d = DX(ctx->opcode);
1047 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], ctx->nip + (d << 16));
1050 static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
1051 TCGv arg2, int sign, int compute_ov)
1053 TCGLabel *l1 = gen_new_label();
1054 TCGLabel *l2 = gen_new_label();
1055 TCGv_i32 t0 = tcg_temp_local_new_i32();
1056 TCGv_i32 t1 = tcg_temp_local_new_i32();
1058 tcg_gen_trunc_tl_i32(t0, arg1);
1059 tcg_gen_trunc_tl_i32(t1, arg2);
1060 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
1062 TCGLabel *l3 = gen_new_label();
1063 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
1064 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
1066 tcg_gen_div_i32(t0, t0, t1);
1068 tcg_gen_divu_i32(t0, t0, t1);
1071 tcg_gen_movi_tl(cpu_ov, 0);
1076 tcg_gen_sari_i32(t0, t0, 31);
1078 tcg_gen_movi_i32(t0, 0);
1081 tcg_gen_movi_tl(cpu_ov, 1);
1082 tcg_gen_movi_tl(cpu_so, 1);
1085 tcg_gen_extu_i32_tl(ret, t0);
1086 tcg_temp_free_i32(t0);
1087 tcg_temp_free_i32(t1);
1088 if (unlikely(Rc(ctx->opcode) != 0))
1089 gen_set_Rc0(ctx, ret);
1092 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1093 static void glue(gen_, name)(DisasContext *ctx) \
1095 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1096 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1097 sign, compute_ov); \
1099 /* divwu divwu. divwuo divwuo. */
1100 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
1101 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
1102 /* divw divw. divwo divwo. */
1103 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1104 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
1106 /* div[wd]eu[o][.] */
1107 #define GEN_DIVE(name, hlpr, compute_ov) \
1108 static void gen_##name(DisasContext *ctx) \
1110 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1111 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1112 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1113 tcg_temp_free_i32(t0); \
1114 if (unlikely(Rc(ctx->opcode) != 0)) { \
1115 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1119 GEN_DIVE(divweu, divweu, 0);
1120 GEN_DIVE(divweuo, divweu, 1);
1121 GEN_DIVE(divwe, divwe, 0);
1122 GEN_DIVE(divweo, divwe, 1);
1124 #if defined(TARGET_PPC64)
1125 static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1126 TCGv arg2, int sign, int compute_ov)
1128 TCGLabel *l1 = gen_new_label();
1129 TCGLabel *l2 = gen_new_label();
1131 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1133 TCGLabel *l3 = gen_new_label();
1134 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1135 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1137 tcg_gen_div_i64(ret, arg1, arg2);
1139 tcg_gen_divu_i64(ret, arg1, arg2);
1142 tcg_gen_movi_tl(cpu_ov, 0);
1147 tcg_gen_sari_i64(ret, arg1, 63);
1149 tcg_gen_movi_i64(ret, 0);
1152 tcg_gen_movi_tl(cpu_ov, 1);
1153 tcg_gen_movi_tl(cpu_so, 1);
1156 if (unlikely(Rc(ctx->opcode) != 0))
1157 gen_set_Rc0(ctx, ret);
1159 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1160 static void glue(gen_, name)(DisasContext *ctx) \
1162 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1163 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1164 sign, compute_ov); \
1166 /* divwu divwu. divwuo divwuo. */
1167 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1168 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1169 /* divw divw. divwo divwo. */
1170 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1171 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1173 GEN_DIVE(divdeu, divdeu, 0);
1174 GEN_DIVE(divdeuo, divdeu, 1);
1175 GEN_DIVE(divde, divde, 0);
1176 GEN_DIVE(divdeo, divde, 1);
1179 static inline void gen_op_arith_modw(DisasContext *ctx, TCGv ret, TCGv arg1,
1180 TCGv arg2, int sign)
1182 TCGv_i32 t0 = tcg_temp_new_i32();
1183 TCGv_i32 t1 = tcg_temp_new_i32();
1185 tcg_gen_trunc_tl_i32(t0, arg1);
1186 tcg_gen_trunc_tl_i32(t1, arg2);
1188 TCGv_i32 t2 = tcg_temp_new_i32();
1189 TCGv_i32 t3 = tcg_temp_new_i32();
1190 tcg_gen_setcondi_i32(TCG_COND_EQ, t2, t0, INT_MIN);
1191 tcg_gen_setcondi_i32(TCG_COND_EQ, t3, t1, -1);
1192 tcg_gen_and_i32(t2, t2, t3);
1193 tcg_gen_setcondi_i32(TCG_COND_EQ, t3, t1, 0);
1194 tcg_gen_or_i32(t2, t2, t3);
1195 tcg_gen_movi_i32(t3, 0);
1196 tcg_gen_movcond_i32(TCG_COND_NE, t1, t2, t3, t2, t1);
1197 tcg_gen_rem_i32(t3, t0, t1);
1198 tcg_gen_ext_i32_tl(ret, t3);
1199 tcg_temp_free_i32(t2);
1200 tcg_temp_free_i32(t3);
1202 TCGv_i32 t2 = tcg_const_i32(1);
1203 TCGv_i32 t3 = tcg_const_i32(0);
1204 tcg_gen_movcond_i32(TCG_COND_EQ, t1, t1, t3, t2, t1);
1205 tcg_gen_remu_i32(t3, t0, t1);
1206 tcg_gen_extu_i32_tl(ret, t3);
1207 tcg_temp_free_i32(t2);
1208 tcg_temp_free_i32(t3);
1210 tcg_temp_free_i32(t0);
1211 tcg_temp_free_i32(t1);
1214 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
1215 static void glue(gen_, name)(DisasContext *ctx) \
1217 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
1218 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1222 GEN_INT_ARITH_MODW(moduw, 0x08, 0);
1223 GEN_INT_ARITH_MODW(modsw, 0x18, 1);
1226 static void gen_mulhw(DisasContext *ctx)
1228 TCGv_i32 t0 = tcg_temp_new_i32();
1229 TCGv_i32 t1 = tcg_temp_new_i32();
1231 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1232 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1233 tcg_gen_muls2_i32(t0, t1, t0, t1);
1234 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1235 tcg_temp_free_i32(t0);
1236 tcg_temp_free_i32(t1);
1237 if (unlikely(Rc(ctx->opcode) != 0))
1238 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1241 /* mulhwu mulhwu. */
1242 static void gen_mulhwu(DisasContext *ctx)
1244 TCGv_i32 t0 = tcg_temp_new_i32();
1245 TCGv_i32 t1 = tcg_temp_new_i32();
1247 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1248 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1249 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1250 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1251 tcg_temp_free_i32(t0);
1252 tcg_temp_free_i32(t1);
1253 if (unlikely(Rc(ctx->opcode) != 0))
1254 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1258 static void gen_mullw(DisasContext *ctx)
1260 #if defined(TARGET_PPC64)
1262 t0 = tcg_temp_new_i64();
1263 t1 = tcg_temp_new_i64();
1264 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1265 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1266 tcg_gen_mul_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);
1270 tcg_gen_mul_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1271 cpu_gpr[rB(ctx->opcode)]);
1273 if (unlikely(Rc(ctx->opcode) != 0))
1274 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1277 /* mullwo mullwo. */
1278 static void gen_mullwo(DisasContext *ctx)
1280 TCGv_i32 t0 = tcg_temp_new_i32();
1281 TCGv_i32 t1 = tcg_temp_new_i32();
1283 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1284 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1285 tcg_gen_muls2_i32(t0, t1, t0, t1);
1286 #if defined(TARGET_PPC64)
1287 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);
1289 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], t0);
1292 tcg_gen_sari_i32(t0, t0, 31);
1293 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1294 tcg_gen_extu_i32_tl(cpu_ov, t0);
1295 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1297 tcg_temp_free_i32(t0);
1298 tcg_temp_free_i32(t1);
1299 if (unlikely(Rc(ctx->opcode) != 0))
1300 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1304 static void gen_mulli(DisasContext *ctx)
1306 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1310 #if defined(TARGET_PPC64)
1312 static void gen_mulhd(DisasContext *ctx)
1314 TCGv lo = tcg_temp_new();
1315 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1316 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1318 if (unlikely(Rc(ctx->opcode) != 0)) {
1319 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1323 /* mulhdu mulhdu. */
1324 static void gen_mulhdu(DisasContext *ctx)
1326 TCGv lo = tcg_temp_new();
1327 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1328 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1330 if (unlikely(Rc(ctx->opcode) != 0)) {
1331 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1336 static void gen_mulld(DisasContext *ctx)
1338 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1339 cpu_gpr[rB(ctx->opcode)]);
1340 if (unlikely(Rc(ctx->opcode) != 0))
1341 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1344 /* mulldo mulldo. */
1345 static void gen_mulldo(DisasContext *ctx)
1347 TCGv_i64 t0 = tcg_temp_new_i64();
1348 TCGv_i64 t1 = tcg_temp_new_i64();
1350 tcg_gen_muls2_i64(t0, t1, cpu_gpr[rA(ctx->opcode)],
1351 cpu_gpr[rB(ctx->opcode)]);
1352 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], t0);
1354 tcg_gen_sari_i64(t0, t0, 63);
1355 tcg_gen_setcond_i64(TCG_COND_NE, cpu_ov, t0, t1);
1356 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1358 tcg_temp_free_i64(t0);
1359 tcg_temp_free_i64(t1);
1361 if (unlikely(Rc(ctx->opcode) != 0)) {
1362 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1367 /* Common subf function */
1368 static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
1369 TCGv arg2, bool add_ca, bool compute_ca,
1370 bool compute_ov, bool compute_rc0)
1374 if (compute_ca || compute_ov) {
1375 t0 = tcg_temp_new();
1379 /* dest = ~arg1 + arg2 [+ ca]. */
1380 if (NARROW_MODE(ctx)) {
1381 /* Caution: a non-obvious corner case of the spec is that we
1382 must produce the *entire* 64-bit addition, but produce the
1383 carry into bit 32. */
1384 TCGv inv1 = tcg_temp_new();
1385 TCGv t1 = tcg_temp_new();
1386 tcg_gen_not_tl(inv1, arg1);
1388 tcg_gen_add_tl(t0, arg2, cpu_ca);
1390 tcg_gen_addi_tl(t0, arg2, 1);
1392 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
1393 tcg_gen_add_tl(t0, t0, inv1);
1394 tcg_temp_free(inv1);
1395 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1397 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1398 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
1399 } else if (add_ca) {
1400 TCGv zero, inv1 = tcg_temp_new();
1401 tcg_gen_not_tl(inv1, arg1);
1402 zero = tcg_const_tl(0);
1403 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
1404 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
1405 tcg_temp_free(zero);
1406 tcg_temp_free(inv1);
1408 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
1409 tcg_gen_sub_tl(t0, arg2, arg1);
1411 } else if (add_ca) {
1412 /* Since we're ignoring carry-out, we can simplify the
1413 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1414 tcg_gen_sub_tl(t0, arg2, arg1);
1415 tcg_gen_add_tl(t0, t0, cpu_ca);
1416 tcg_gen_subi_tl(t0, t0, 1);
1418 tcg_gen_sub_tl(t0, arg2, arg1);
1422 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1424 if (unlikely(compute_rc0)) {
1425 gen_set_Rc0(ctx, t0);
1428 if (!TCGV_EQUAL(t0, ret)) {
1429 tcg_gen_mov_tl(ret, t0);
1433 /* Sub functions with Two operands functions */
1434 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1435 static void glue(gen_, name)(DisasContext *ctx) \
1437 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1438 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1439 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1441 /* Sub functions with one operand and one immediate */
1442 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1443 add_ca, compute_ca, compute_ov) \
1444 static void glue(gen_, name)(DisasContext *ctx) \
1446 TCGv t0 = tcg_const_tl(const_val); \
1447 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1448 cpu_gpr[rA(ctx->opcode)], t0, \
1449 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1450 tcg_temp_free(t0); \
1452 /* subf subf. subfo subfo. */
1453 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1454 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1455 /* subfc subfc. subfco subfco. */
1456 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1457 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1458 /* subfe subfe. subfeo subfo. */
1459 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1460 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1461 /* subfme subfme. subfmeo subfmeo. */
1462 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1463 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1464 /* subfze subfze. subfzeo subfzeo.*/
1465 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1466 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
1469 static void gen_subfic(DisasContext *ctx)
1471 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1472 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1477 /* neg neg. nego nego. */
1478 static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1480 TCGv zero = tcg_const_tl(0);
1481 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1482 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1483 tcg_temp_free(zero);
1486 static void gen_neg(DisasContext *ctx)
1488 gen_op_arith_neg(ctx, 0);
1491 static void gen_nego(DisasContext *ctx)
1493 gen_op_arith_neg(ctx, 1);
1496 /*** Integer logical ***/
1497 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1498 static void glue(gen_, name)(DisasContext *ctx) \
1500 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1501 cpu_gpr[rB(ctx->opcode)]); \
1502 if (unlikely(Rc(ctx->opcode) != 0)) \
1503 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1506 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1507 static void glue(gen_, name)(DisasContext *ctx) \
1509 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1510 if (unlikely(Rc(ctx->opcode) != 0)) \
1511 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1515 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
1517 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
1520 static void gen_andi_(DisasContext *ctx)
1522 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1523 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1527 static void gen_andis_(DisasContext *ctx)
1529 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1530 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1534 static void gen_cntlzw(DisasContext *ctx)
1536 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1537 if (unlikely(Rc(ctx->opcode) != 0))
1538 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1541 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
1542 /* extsb & extsb. */
1543 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
1544 /* extsh & extsh. */
1545 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
1547 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
1549 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
1551 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
1552 static void gen_pause(DisasContext *ctx)
1554 TCGv_i32 t0 = tcg_const_i32(0);
1555 tcg_gen_st_i32(t0, cpu_env,
1556 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
1557 tcg_temp_free_i32(t0);
1559 /* Stop translation, this gives other CPUs a chance to run */
1560 gen_exception_err(ctx, EXCP_HLT, 1);
1562 #endif /* defined(TARGET_PPC64) */
1565 static void gen_or(DisasContext *ctx)
1569 rs = rS(ctx->opcode);
1570 ra = rA(ctx->opcode);
1571 rb = rB(ctx->opcode);
1572 /* Optimisation for mr. ri case */
1573 if (rs != ra || rs != rb) {
1575 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1577 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
1578 if (unlikely(Rc(ctx->opcode) != 0))
1579 gen_set_Rc0(ctx, cpu_gpr[ra]);
1580 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1581 gen_set_Rc0(ctx, cpu_gpr[rs]);
1582 #if defined(TARGET_PPC64)
1583 } else if (rs != 0) { /* 0 is nop */
1588 /* Set process priority to low */
1592 /* Set process priority to medium-low */
1596 /* Set process priority to normal */
1599 #if !defined(CONFIG_USER_ONLY)
1602 /* Set process priority to very low */
1608 /* Set process priority to medium-hight */
1614 /* Set process priority to high */
1619 if (ctx->hv && !ctx->pr) {
1620 /* Set process priority to very high */
1629 TCGv t0 = tcg_temp_new();
1630 gen_load_spr(t0, SPR_PPR);
1631 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1632 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
1633 gen_store_spr(SPR_PPR, t0);
1636 #if !defined(CONFIG_USER_ONLY)
1637 /* Pause out of TCG otherwise spin loops with smt_low eat too much
1638 * CPU and the kernel hangs. This applies to all encodings other
1639 * than no-op, e.g., miso(rs=26), yield(27), mdoio(29), mdoom(30),
1640 * and all currently undefined.
1648 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
1651 static void gen_xor(DisasContext *ctx)
1653 /* Optimisation for "set to zero" case */
1654 if (rS(ctx->opcode) != rB(ctx->opcode))
1655 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1657 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1658 if (unlikely(Rc(ctx->opcode) != 0))
1659 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1663 static void gen_ori(DisasContext *ctx)
1665 target_ulong uimm = UIMM(ctx->opcode);
1667 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1670 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1674 static void gen_oris(DisasContext *ctx)
1676 target_ulong uimm = UIMM(ctx->opcode);
1678 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1682 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1686 static void gen_xori(DisasContext *ctx)
1688 target_ulong uimm = UIMM(ctx->opcode);
1690 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1694 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1698 static void gen_xoris(DisasContext *ctx)
1700 target_ulong uimm = UIMM(ctx->opcode);
1702 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1706 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1709 /* popcntb : PowerPC 2.03 specification */
1710 static void gen_popcntb(DisasContext *ctx)
1712 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1715 static void gen_popcntw(DisasContext *ctx)
1717 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1720 #if defined(TARGET_PPC64)
1721 /* popcntd: PowerPC 2.06 specification */
1722 static void gen_popcntd(DisasContext *ctx)
1724 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1728 /* prtyw: PowerPC 2.05 specification */
1729 static void gen_prtyw(DisasContext *ctx)
1731 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1732 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1733 TCGv t0 = tcg_temp_new();
1734 tcg_gen_shri_tl(t0, rs, 16);
1735 tcg_gen_xor_tl(ra, rs, t0);
1736 tcg_gen_shri_tl(t0, ra, 8);
1737 tcg_gen_xor_tl(ra, ra, t0);
1738 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1742 #if defined(TARGET_PPC64)
1743 /* prtyd: PowerPC 2.05 specification */
1744 static void gen_prtyd(DisasContext *ctx)
1746 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1747 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1748 TCGv t0 = tcg_temp_new();
1749 tcg_gen_shri_tl(t0, rs, 32);
1750 tcg_gen_xor_tl(ra, rs, t0);
1751 tcg_gen_shri_tl(t0, ra, 16);
1752 tcg_gen_xor_tl(ra, ra, t0);
1753 tcg_gen_shri_tl(t0, ra, 8);
1754 tcg_gen_xor_tl(ra, ra, t0);
1755 tcg_gen_andi_tl(ra, ra, 1);
1760 #if defined(TARGET_PPC64)
1762 static void gen_bpermd(DisasContext *ctx)
1764 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1765 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1769 #if defined(TARGET_PPC64)
1770 /* extsw & extsw. */
1771 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
1774 static void gen_cntlzd(DisasContext *ctx)
1776 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1777 if (unlikely(Rc(ctx->opcode) != 0))
1778 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1782 /*** Integer rotate ***/
1784 /* rlwimi & rlwimi. */
1785 static void gen_rlwimi(DisasContext *ctx)
1787 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1788 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1789 uint32_t sh = SH(ctx->opcode);
1790 uint32_t mb = MB(ctx->opcode);
1791 uint32_t me = ME(ctx->opcode);
1793 if (sh == (31-me) && mb <= me) {
1794 tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1);
1799 #if defined(TARGET_PPC64)
1803 mask = MASK(mb, me);
1805 t1 = tcg_temp_new();
1806 if (mask <= 0xffffffffu) {
1807 TCGv_i32 t0 = tcg_temp_new_i32();
1808 tcg_gen_trunc_tl_i32(t0, t_rs);
1809 tcg_gen_rotli_i32(t0, t0, sh);
1810 tcg_gen_extu_i32_tl(t1, t0);
1811 tcg_temp_free_i32(t0);
1813 #if defined(TARGET_PPC64)
1814 tcg_gen_deposit_i64(t1, t_rs, t_rs, 32, 32);
1815 tcg_gen_rotli_i64(t1, t1, sh);
1817 g_assert_not_reached();
1821 tcg_gen_andi_tl(t1, t1, mask);
1822 tcg_gen_andi_tl(t_ra, t_ra, ~mask);
1823 tcg_gen_or_tl(t_ra, t_ra, t1);
1826 if (unlikely(Rc(ctx->opcode) != 0)) {
1827 gen_set_Rc0(ctx, t_ra);
1831 /* rlwinm & rlwinm. */
1832 static void gen_rlwinm(DisasContext *ctx)
1834 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1835 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1836 uint32_t sh = SH(ctx->opcode);
1837 uint32_t mb = MB(ctx->opcode);
1838 uint32_t me = ME(ctx->opcode);
1840 if (mb == 0 && me == (31 - sh)) {
1841 tcg_gen_shli_tl(t_ra, t_rs, sh);
1842 tcg_gen_ext32u_tl(t_ra, t_ra);
1843 } else if (sh != 0 && me == 31 && sh == (32 - mb)) {
1844 tcg_gen_ext32u_tl(t_ra, t_rs);
1845 tcg_gen_shri_tl(t_ra, t_ra, mb);
1848 #if defined(TARGET_PPC64)
1852 mask = MASK(mb, me);
1854 if (mask <= 0xffffffffu) {
1855 TCGv_i32 t0 = tcg_temp_new_i32();
1856 tcg_gen_trunc_tl_i32(t0, t_rs);
1857 tcg_gen_rotli_i32(t0, t0, sh);
1858 tcg_gen_andi_i32(t0, t0, mask);
1859 tcg_gen_extu_i32_tl(t_ra, t0);
1860 tcg_temp_free_i32(t0);
1862 #if defined(TARGET_PPC64)
1863 tcg_gen_deposit_i64(t_ra, t_rs, t_rs, 32, 32);
1864 tcg_gen_rotli_i64(t_ra, t_ra, sh);
1865 tcg_gen_andi_i64(t_ra, t_ra, mask);
1867 g_assert_not_reached();
1871 if (unlikely(Rc(ctx->opcode) != 0)) {
1872 gen_set_Rc0(ctx, t_ra);
1876 /* rlwnm & rlwnm. */
1877 static void gen_rlwnm(DisasContext *ctx)
1879 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1880 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1881 TCGv t_rb = cpu_gpr[rB(ctx->opcode)];
1882 uint32_t mb = MB(ctx->opcode);
1883 uint32_t me = ME(ctx->opcode);
1886 #if defined(TARGET_PPC64)
1890 mask = MASK(mb, me);
1892 if (mask <= 0xffffffffu) {
1893 TCGv_i32 t0 = tcg_temp_new_i32();
1894 TCGv_i32 t1 = tcg_temp_new_i32();
1895 tcg_gen_trunc_tl_i32(t0, t_rb);
1896 tcg_gen_trunc_tl_i32(t1, t_rs);
1897 tcg_gen_andi_i32(t0, t0, 0x1f);
1898 tcg_gen_rotl_i32(t1, t1, t0);
1899 tcg_gen_extu_i32_tl(t_ra, t1);
1900 tcg_temp_free_i32(t0);
1901 tcg_temp_free_i32(t1);
1903 #if defined(TARGET_PPC64)
1904 TCGv_i64 t0 = tcg_temp_new_i64();
1905 tcg_gen_andi_i64(t0, t_rb, 0x1f);
1906 tcg_gen_deposit_i64(t_ra, t_rs, t_rs, 32, 32);
1907 tcg_gen_rotl_i64(t_ra, t_ra, t0);
1908 tcg_temp_free_i64(t0);
1910 g_assert_not_reached();
1914 tcg_gen_andi_tl(t_ra, t_ra, mask);
1916 if (unlikely(Rc(ctx->opcode) != 0)) {
1917 gen_set_Rc0(ctx, t_ra);
1921 #if defined(TARGET_PPC64)
1922 #define GEN_PPC64_R2(name, opc1, opc2) \
1923 static void glue(gen_, name##0)(DisasContext *ctx) \
1925 gen_##name(ctx, 0); \
1928 static void glue(gen_, name##1)(DisasContext *ctx) \
1930 gen_##name(ctx, 1); \
1932 #define GEN_PPC64_R4(name, opc1, opc2) \
1933 static void glue(gen_, name##0)(DisasContext *ctx) \
1935 gen_##name(ctx, 0, 0); \
1938 static void glue(gen_, name##1)(DisasContext *ctx) \
1940 gen_##name(ctx, 0, 1); \
1943 static void glue(gen_, name##2)(DisasContext *ctx) \
1945 gen_##name(ctx, 1, 0); \
1948 static void glue(gen_, name##3)(DisasContext *ctx) \
1950 gen_##name(ctx, 1, 1); \
1953 static void gen_rldinm(DisasContext *ctx, int mb, int me, int sh)
1955 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1956 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1958 if (sh != 0 && mb == 0 && me == (63 - sh)) {
1959 tcg_gen_shli_tl(t_ra, t_rs, sh);
1960 } else if (sh != 0 && me == 63 && sh == (64 - mb)) {
1961 tcg_gen_shri_tl(t_ra, t_rs, mb);
1963 tcg_gen_rotli_tl(t_ra, t_rs, sh);
1964 tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me));
1966 if (unlikely(Rc(ctx->opcode) != 0)) {
1967 gen_set_Rc0(ctx, t_ra);
1971 /* rldicl - rldicl. */
1972 static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
1976 sh = SH(ctx->opcode) | (shn << 5);
1977 mb = MB(ctx->opcode) | (mbn << 5);
1978 gen_rldinm(ctx, mb, 63, sh);
1980 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1982 /* rldicr - rldicr. */
1983 static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
1987 sh = SH(ctx->opcode) | (shn << 5);
1988 me = MB(ctx->opcode) | (men << 5);
1989 gen_rldinm(ctx, 0, me, sh);
1991 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1993 /* rldic - rldic. */
1994 static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
1998 sh = SH(ctx->opcode) | (shn << 5);
1999 mb = MB(ctx->opcode) | (mbn << 5);
2000 gen_rldinm(ctx, mb, 63 - sh, sh);
2002 GEN_PPC64_R4(rldic, 0x1E, 0x04);
2004 static void gen_rldnm(DisasContext *ctx, int mb, int me)
2006 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
2007 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
2008 TCGv t_rb = cpu_gpr[rB(ctx->opcode)];
2011 t0 = tcg_temp_new();
2012 tcg_gen_andi_tl(t0, t_rb, 0x3f);
2013 tcg_gen_rotl_tl(t_ra, t_rs, t0);
2016 tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me));
2017 if (unlikely(Rc(ctx->opcode) != 0)) {
2018 gen_set_Rc0(ctx, t_ra);
2022 /* rldcl - rldcl. */
2023 static inline void gen_rldcl(DisasContext *ctx, int mbn)
2027 mb = MB(ctx->opcode) | (mbn << 5);
2028 gen_rldnm(ctx, mb, 63);
2030 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
2032 /* rldcr - rldcr. */
2033 static inline void gen_rldcr(DisasContext *ctx, int men)
2037 me = MB(ctx->opcode) | (men << 5);
2038 gen_rldnm(ctx, 0, me);
2040 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
2042 /* rldimi - rldimi. */
2043 static void gen_rldimi(DisasContext *ctx, int mbn, int shn)
2045 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
2046 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
2047 uint32_t sh = SH(ctx->opcode) | (shn << 5);
2048 uint32_t mb = MB(ctx->opcode) | (mbn << 5);
2049 uint32_t me = 63 - sh;
2052 tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1);
2054 target_ulong mask = MASK(mb, me);
2055 TCGv t1 = tcg_temp_new();
2057 tcg_gen_rotli_tl(t1, t_rs, sh);
2058 tcg_gen_andi_tl(t1, t1, mask);
2059 tcg_gen_andi_tl(t_ra, t_ra, ~mask);
2060 tcg_gen_or_tl(t_ra, t_ra, t1);
2063 if (unlikely(Rc(ctx->opcode) != 0)) {
2064 gen_set_Rc0(ctx, t_ra);
2067 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
2070 /*** Integer shift ***/
2073 static void gen_slw(DisasContext *ctx)
2077 t0 = tcg_temp_new();
2078 /* AND rS with a mask that is 0 when rB >= 0x20 */
2079 #if defined(TARGET_PPC64)
2080 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
2081 tcg_gen_sari_tl(t0, t0, 0x3f);
2083 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
2084 tcg_gen_sari_tl(t0, t0, 0x1f);
2086 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2087 t1 = tcg_temp_new();
2088 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
2089 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2092 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
2093 if (unlikely(Rc(ctx->opcode) != 0))
2094 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2098 static void gen_sraw(DisasContext *ctx)
2100 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
2101 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2102 if (unlikely(Rc(ctx->opcode) != 0))
2103 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2106 /* srawi & srawi. */
2107 static void gen_srawi(DisasContext *ctx)
2109 int sh = SH(ctx->opcode);
2110 TCGv dst = cpu_gpr[rA(ctx->opcode)];
2111 TCGv src = cpu_gpr[rS(ctx->opcode)];
2113 tcg_gen_ext32s_tl(dst, src);
2114 tcg_gen_movi_tl(cpu_ca, 0);
2117 tcg_gen_ext32s_tl(dst, src);
2118 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
2119 t0 = tcg_temp_new();
2120 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
2121 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
2123 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
2124 tcg_gen_sari_tl(dst, dst, sh);
2126 if (unlikely(Rc(ctx->opcode) != 0)) {
2127 gen_set_Rc0(ctx, dst);
2132 static void gen_srw(DisasContext *ctx)
2136 t0 = tcg_temp_new();
2137 /* AND rS with a mask that is 0 when rB >= 0x20 */
2138 #if defined(TARGET_PPC64)
2139 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
2140 tcg_gen_sari_tl(t0, t0, 0x3f);
2142 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
2143 tcg_gen_sari_tl(t0, t0, 0x1f);
2145 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2146 tcg_gen_ext32u_tl(t0, t0);
2147 t1 = tcg_temp_new();
2148 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
2149 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2152 if (unlikely(Rc(ctx->opcode) != 0))
2153 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2156 #if defined(TARGET_PPC64)
2158 static void gen_sld(DisasContext *ctx)
2162 t0 = tcg_temp_new();
2163 /* AND rS with a mask that is 0 when rB >= 0x40 */
2164 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2165 tcg_gen_sari_tl(t0, t0, 0x3f);
2166 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2167 t1 = tcg_temp_new();
2168 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2169 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2172 if (unlikely(Rc(ctx->opcode) != 0))
2173 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2177 static void gen_srad(DisasContext *ctx)
2179 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
2180 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2181 if (unlikely(Rc(ctx->opcode) != 0))
2182 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2184 /* sradi & sradi. */
2185 static inline void gen_sradi(DisasContext *ctx, int n)
2187 int sh = SH(ctx->opcode) + (n << 5);
2188 TCGv dst = cpu_gpr[rA(ctx->opcode)];
2189 TCGv src = cpu_gpr[rS(ctx->opcode)];
2191 tcg_gen_mov_tl(dst, src);
2192 tcg_gen_movi_tl(cpu_ca, 0);
2195 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
2196 t0 = tcg_temp_new();
2197 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
2198 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
2200 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
2201 tcg_gen_sari_tl(dst, src, sh);
2203 if (unlikely(Rc(ctx->opcode) != 0)) {
2204 gen_set_Rc0(ctx, dst);
2208 static void gen_sradi0(DisasContext *ctx)
2213 static void gen_sradi1(DisasContext *ctx)
2219 static void gen_srd(DisasContext *ctx)
2223 t0 = tcg_temp_new();
2224 /* AND rS with a mask that is 0 when rB >= 0x40 */
2225 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2226 tcg_gen_sari_tl(t0, t0, 0x3f);
2227 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2228 t1 = tcg_temp_new();
2229 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2230 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2233 if (unlikely(Rc(ctx->opcode) != 0))
2234 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2238 #if defined(TARGET_PPC64)
2239 static void gen_set_cr1_from_fpscr(DisasContext *ctx)
2241 TCGv_i32 tmp = tcg_temp_new_i32();
2242 tcg_gen_trunc_tl_i32(tmp, cpu_fpscr);
2243 tcg_gen_shri_i32(cpu_crf[1], tmp, 28);
2244 tcg_temp_free_i32(tmp);
2247 static void gen_set_cr1_from_fpscr(DisasContext *ctx)
2249 tcg_gen_shri_tl(cpu_crf[1], cpu_fpscr, 28);
2253 /*** Floating-Point arithmetic ***/
2254 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2255 static void gen_f##name(DisasContext *ctx) \
2257 if (unlikely(!ctx->fpu_enabled)) { \
2258 gen_exception(ctx, POWERPC_EXCP_FPU); \
2261 /* NIP cannot be restored if the memory exception comes from an helper */ \
2262 gen_update_nip(ctx, ctx->nip - 4); \
2263 gen_reset_fpstatus(); \
2264 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2265 cpu_fpr[rA(ctx->opcode)], \
2266 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2268 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2269 cpu_fpr[rD(ctx->opcode)]); \
2272 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2274 if (unlikely(Rc(ctx->opcode) != 0)) { \
2275 gen_set_cr1_from_fpscr(ctx); \
2279 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2280 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2281 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2283 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2284 static void gen_f##name(DisasContext *ctx) \
2286 if (unlikely(!ctx->fpu_enabled)) { \
2287 gen_exception(ctx, POWERPC_EXCP_FPU); \
2290 /* NIP cannot be restored if the memory exception comes from an helper */ \
2291 gen_update_nip(ctx, ctx->nip - 4); \
2292 gen_reset_fpstatus(); \
2293 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2294 cpu_fpr[rA(ctx->opcode)], \
2295 cpu_fpr[rB(ctx->opcode)]); \
2297 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2298 cpu_fpr[rD(ctx->opcode)]); \
2301 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2303 if (unlikely(Rc(ctx->opcode) != 0)) { \
2304 gen_set_cr1_from_fpscr(ctx); \
2307 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2308 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2309 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2311 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2312 static void gen_f##name(DisasContext *ctx) \
2314 if (unlikely(!ctx->fpu_enabled)) { \
2315 gen_exception(ctx, POWERPC_EXCP_FPU); \
2318 /* NIP cannot be restored if the memory exception comes from an helper */ \
2319 gen_update_nip(ctx, ctx->nip - 4); \
2320 gen_reset_fpstatus(); \
2321 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2322 cpu_fpr[rA(ctx->opcode)], \
2323 cpu_fpr[rC(ctx->opcode)]); \
2325 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2326 cpu_fpr[rD(ctx->opcode)]); \
2329 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2331 if (unlikely(Rc(ctx->opcode) != 0)) { \
2332 gen_set_cr1_from_fpscr(ctx); \
2335 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2336 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2337 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2339 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2340 static void gen_f##name(DisasContext *ctx) \
2342 if (unlikely(!ctx->fpu_enabled)) { \
2343 gen_exception(ctx, POWERPC_EXCP_FPU); \
2346 /* NIP cannot be restored if the memory exception comes from an helper */ \
2347 gen_update_nip(ctx, ctx->nip - 4); \
2348 gen_reset_fpstatus(); \
2349 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2350 cpu_fpr[rB(ctx->opcode)]); \
2352 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2354 if (unlikely(Rc(ctx->opcode) != 0)) { \
2355 gen_set_cr1_from_fpscr(ctx); \
2359 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2360 static void gen_f##name(DisasContext *ctx) \
2362 if (unlikely(!ctx->fpu_enabled)) { \
2363 gen_exception(ctx, POWERPC_EXCP_FPU); \
2366 /* NIP cannot be restored if the memory exception comes from an helper */ \
2367 gen_update_nip(ctx, ctx->nip - 4); \
2368 gen_reset_fpstatus(); \
2369 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2370 cpu_fpr[rB(ctx->opcode)]); \
2372 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2374 if (unlikely(Rc(ctx->opcode) != 0)) { \
2375 gen_set_cr1_from_fpscr(ctx); \
2380 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
2382 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
2384 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
2387 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
2390 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
2393 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2396 static void gen_frsqrtes(DisasContext *ctx)
2398 if (unlikely(!ctx->fpu_enabled)) {
2399 gen_exception(ctx, POWERPC_EXCP_FPU);
2402 /* NIP cannot be restored if the memory exception comes from an helper */
2403 gen_update_nip(ctx, ctx->nip - 4);
2404 gen_reset_fpstatus();
2405 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2406 cpu_fpr[rB(ctx->opcode)]);
2407 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2408 cpu_fpr[rD(ctx->opcode)]);
2409 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
2410 if (unlikely(Rc(ctx->opcode) != 0)) {
2411 gen_set_cr1_from_fpscr(ctx);
2416 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
2418 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
2422 static void gen_fsqrt(DisasContext *ctx)
2424 if (unlikely(!ctx->fpu_enabled)) {
2425 gen_exception(ctx, POWERPC_EXCP_FPU);
2428 /* NIP cannot be restored if the memory exception comes from an helper */
2429 gen_update_nip(ctx, ctx->nip - 4);
2430 gen_reset_fpstatus();
2431 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2432 cpu_fpr[rB(ctx->opcode)]);
2433 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
2434 if (unlikely(Rc(ctx->opcode) != 0)) {
2435 gen_set_cr1_from_fpscr(ctx);
2439 static void gen_fsqrts(DisasContext *ctx)
2441 if (unlikely(!ctx->fpu_enabled)) {
2442 gen_exception(ctx, POWERPC_EXCP_FPU);
2445 /* NIP cannot be restored if the memory exception comes from an helper */
2446 gen_update_nip(ctx, ctx->nip - 4);
2447 gen_reset_fpstatus();
2448 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2449 cpu_fpr[rB(ctx->opcode)]);
2450 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2451 cpu_fpr[rD(ctx->opcode)]);
2452 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
2453 if (unlikely(Rc(ctx->opcode) != 0)) {
2454 gen_set_cr1_from_fpscr(ctx);
2458 /*** Floating-Point multiply-and-add ***/
2459 /* fmadd - fmadds */
2460 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
2461 /* fmsub - fmsubs */
2462 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
2463 /* fnmadd - fnmadds */
2464 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
2465 /* fnmsub - fnmsubs */
2466 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
2468 /*** Floating-Point round & convert ***/
2470 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
2472 GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
2474 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
2476 GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
2478 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
2480 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC2_FP_CVT_S64);
2482 GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2484 GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2486 GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2488 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC2_FP_CVT_S64);
2490 GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
2492 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC2_FP_CVT_S64);
2494 GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
2497 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
2499 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
2501 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
2503 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
2505 static void gen_ftdiv(DisasContext *ctx)
2507 if (unlikely(!ctx->fpu_enabled)) {
2508 gen_exception(ctx, POWERPC_EXCP_FPU);
2511 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2512 cpu_fpr[rB(ctx->opcode)]);
2515 static void gen_ftsqrt(DisasContext *ctx)
2517 if (unlikely(!ctx->fpu_enabled)) {
2518 gen_exception(ctx, POWERPC_EXCP_FPU);
2521 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2526 /*** Floating-Point compare ***/
2529 static void gen_fcmpo(DisasContext *ctx)
2532 if (unlikely(!ctx->fpu_enabled)) {
2533 gen_exception(ctx, POWERPC_EXCP_FPU);
2536 /* NIP cannot be restored if the memory exception comes from an helper */
2537 gen_update_nip(ctx, ctx->nip - 4);
2538 gen_reset_fpstatus();
2539 crf = tcg_const_i32(crfD(ctx->opcode));
2540 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2541 cpu_fpr[rB(ctx->opcode)], crf);
2542 tcg_temp_free_i32(crf);
2543 gen_helper_float_check_status(cpu_env);
2547 static void gen_fcmpu(DisasContext *ctx)
2550 if (unlikely(!ctx->fpu_enabled)) {
2551 gen_exception(ctx, POWERPC_EXCP_FPU);
2554 /* NIP cannot be restored if the memory exception comes from an helper */
2555 gen_update_nip(ctx, ctx->nip - 4);
2556 gen_reset_fpstatus();
2557 crf = tcg_const_i32(crfD(ctx->opcode));
2558 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2559 cpu_fpr[rB(ctx->opcode)], crf);
2560 tcg_temp_free_i32(crf);
2561 gen_helper_float_check_status(cpu_env);
2564 /*** Floating-point move ***/
2566 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2567 static void gen_fabs(DisasContext *ctx)
2569 if (unlikely(!ctx->fpu_enabled)) {
2570 gen_exception(ctx, POWERPC_EXCP_FPU);
2573 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2575 if (unlikely(Rc(ctx->opcode))) {
2576 gen_set_cr1_from_fpscr(ctx);
2581 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2582 static void gen_fmr(DisasContext *ctx)
2584 if (unlikely(!ctx->fpu_enabled)) {
2585 gen_exception(ctx, POWERPC_EXCP_FPU);
2588 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2589 if (unlikely(Rc(ctx->opcode))) {
2590 gen_set_cr1_from_fpscr(ctx);
2595 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2596 static void gen_fnabs(DisasContext *ctx)
2598 if (unlikely(!ctx->fpu_enabled)) {
2599 gen_exception(ctx, POWERPC_EXCP_FPU);
2602 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2604 if (unlikely(Rc(ctx->opcode))) {
2605 gen_set_cr1_from_fpscr(ctx);
2610 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2611 static void gen_fneg(DisasContext *ctx)
2613 if (unlikely(!ctx->fpu_enabled)) {
2614 gen_exception(ctx, POWERPC_EXCP_FPU);
2617 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2619 if (unlikely(Rc(ctx->opcode))) {
2620 gen_set_cr1_from_fpscr(ctx);
2624 /* fcpsgn: PowerPC 2.05 specification */
2625 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2626 static void gen_fcpsgn(DisasContext *ctx)
2628 if (unlikely(!ctx->fpu_enabled)) {
2629 gen_exception(ctx, POWERPC_EXCP_FPU);
2632 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2633 cpu_fpr[rB(ctx->opcode)], 0, 63);
2634 if (unlikely(Rc(ctx->opcode))) {
2635 gen_set_cr1_from_fpscr(ctx);
2639 static void gen_fmrgew(DisasContext *ctx)
2642 if (unlikely(!ctx->fpu_enabled)) {
2643 gen_exception(ctx, POWERPC_EXCP_FPU);
2646 b0 = tcg_temp_new_i64();
2647 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2648 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2650 tcg_temp_free_i64(b0);
2653 static void gen_fmrgow(DisasContext *ctx)
2655 if (unlikely(!ctx->fpu_enabled)) {
2656 gen_exception(ctx, POWERPC_EXCP_FPU);
2659 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2660 cpu_fpr[rB(ctx->opcode)],
2661 cpu_fpr[rA(ctx->opcode)],
2665 /*** Floating-Point status & ctrl register ***/
2668 static void gen_mcrfs(DisasContext *ctx)
2670 TCGv tmp = tcg_temp_new();
2672 TCGv_i64 tnew_fpscr = tcg_temp_new_i64();
2677 if (unlikely(!ctx->fpu_enabled)) {
2678 gen_exception(ctx, POWERPC_EXCP_FPU);
2681 bfa = crfS(ctx->opcode);
2684 tcg_gen_shri_tl(tmp, cpu_fpscr, shift);
2685 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2686 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
2688 tcg_gen_extu_tl_i64(tnew_fpscr, cpu_fpscr);
2689 /* Only the exception bits (including FX) should be cleared if read */
2690 tcg_gen_andi_i64(tnew_fpscr, tnew_fpscr, ~((0xF << shift) & FP_EX_CLEAR_BITS));
2691 /* FEX and VX need to be updated, so don't set fpscr directly */
2692 tmask = tcg_const_i32(1 << nibble);
2693 gen_helper_store_fpscr(cpu_env, tnew_fpscr, tmask);
2694 tcg_temp_free_i32(tmask);
2695 tcg_temp_free_i64(tnew_fpscr);
2699 static void gen_mffs(DisasContext *ctx)
2701 if (unlikely(!ctx->fpu_enabled)) {
2702 gen_exception(ctx, POWERPC_EXCP_FPU);
2705 gen_reset_fpstatus();
2706 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
2707 if (unlikely(Rc(ctx->opcode))) {
2708 gen_set_cr1_from_fpscr(ctx);
2713 static void gen_mtfsb0(DisasContext *ctx)
2717 if (unlikely(!ctx->fpu_enabled)) {
2718 gen_exception(ctx, POWERPC_EXCP_FPU);
2721 crb = 31 - crbD(ctx->opcode);
2722 gen_reset_fpstatus();
2723 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
2725 /* NIP cannot be restored if the memory exception comes from an helper */
2726 gen_update_nip(ctx, ctx->nip - 4);
2727 t0 = tcg_const_i32(crb);
2728 gen_helper_fpscr_clrbit(cpu_env, t0);
2729 tcg_temp_free_i32(t0);
2731 if (unlikely(Rc(ctx->opcode) != 0)) {
2732 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2733 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2738 static void gen_mtfsb1(DisasContext *ctx)
2742 if (unlikely(!ctx->fpu_enabled)) {
2743 gen_exception(ctx, POWERPC_EXCP_FPU);
2746 crb = 31 - crbD(ctx->opcode);
2747 gen_reset_fpstatus();
2748 /* XXX: we pretend we can only do IEEE floating-point computations */
2749 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
2751 /* NIP cannot be restored if the memory exception comes from an helper */
2752 gen_update_nip(ctx, ctx->nip - 4);
2753 t0 = tcg_const_i32(crb);
2754 gen_helper_fpscr_setbit(cpu_env, t0);
2755 tcg_temp_free_i32(t0);
2757 if (unlikely(Rc(ctx->opcode) != 0)) {
2758 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2759 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2761 /* We can raise a differed exception */
2762 gen_helper_float_check_status(cpu_env);
2766 static void gen_mtfsf(DisasContext *ctx)
2771 if (unlikely(!ctx->fpu_enabled)) {
2772 gen_exception(ctx, POWERPC_EXCP_FPU);
2775 flm = FPFLM(ctx->opcode);
2776 l = FPL(ctx->opcode);
2777 w = FPW(ctx->opcode);
2778 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2779 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2782 /* NIP cannot be restored if the memory exception comes from an helper */
2783 gen_update_nip(ctx, ctx->nip - 4);
2784 gen_reset_fpstatus();
2786 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2788 t0 = tcg_const_i32(flm << (w * 8));
2790 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
2791 tcg_temp_free_i32(t0);
2792 if (unlikely(Rc(ctx->opcode) != 0)) {
2793 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2794 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2796 /* We can raise a differed exception */
2797 gen_helper_float_check_status(cpu_env);
2801 static void gen_mtfsfi(DisasContext *ctx)
2807 if (unlikely(!ctx->fpu_enabled)) {
2808 gen_exception(ctx, POWERPC_EXCP_FPU);
2811 w = FPW(ctx->opcode);
2812 bf = FPBF(ctx->opcode);
2813 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2814 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2817 sh = (8 * w) + 7 - bf;
2818 /* NIP cannot be restored if the memory exception comes from an helper */
2819 gen_update_nip(ctx, ctx->nip - 4);
2820 gen_reset_fpstatus();
2821 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
2822 t1 = tcg_const_i32(1 << sh);
2823 gen_helper_store_fpscr(cpu_env, t0, t1);
2824 tcg_temp_free_i64(t0);
2825 tcg_temp_free_i32(t1);
2826 if (unlikely(Rc(ctx->opcode) != 0)) {
2827 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2828 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2830 /* We can raise a differed exception */
2831 gen_helper_float_check_status(cpu_env);
2834 /*** Addressing modes ***/
2835 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2836 static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2839 target_long simm = SIMM(ctx->opcode);
2842 if (rA(ctx->opcode) == 0) {
2843 if (NARROW_MODE(ctx)) {
2844 simm = (uint32_t)simm;
2846 tcg_gen_movi_tl(EA, simm);
2847 } else if (likely(simm != 0)) {
2848 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2849 if (NARROW_MODE(ctx)) {
2850 tcg_gen_ext32u_tl(EA, EA);
2853 if (NARROW_MODE(ctx)) {
2854 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2856 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2861 static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
2863 if (rA(ctx->opcode) == 0) {
2864 if (NARROW_MODE(ctx)) {
2865 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2867 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2870 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2871 if (NARROW_MODE(ctx)) {
2872 tcg_gen_ext32u_tl(EA, EA);
2877 static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
2879 if (rA(ctx->opcode) == 0) {
2880 tcg_gen_movi_tl(EA, 0);
2881 } else if (NARROW_MODE(ctx)) {
2882 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2884 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2888 static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2891 tcg_gen_addi_tl(ret, arg1, val);
2892 if (NARROW_MODE(ctx)) {
2893 tcg_gen_ext32u_tl(ret, ret);
2897 static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
2899 TCGLabel *l1 = gen_new_label();
2900 TCGv t0 = tcg_temp_new();
2902 /* NIP cannot be restored if the memory exception comes from an helper */
2903 gen_update_nip(ctx, ctx->nip - 4);
2904 tcg_gen_andi_tl(t0, EA, mask);
2905 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2906 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2907 t2 = tcg_const_i32(0);
2908 gen_helper_raise_exception_err(cpu_env, t1, t2);
2909 tcg_temp_free_i32(t1);
2910 tcg_temp_free_i32(t2);
2915 /*** Integer load ***/
2916 static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2918 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2921 static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2923 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2924 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
2927 static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2929 TCGMemOp op = MO_SW | ctx->default_tcg_memop_mask;
2930 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
2933 static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2935 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2936 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
2939 static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2941 TCGv tmp = tcg_temp_new();
2942 gen_qemu_ld32u(ctx, tmp, addr);
2943 tcg_gen_extu_tl_i64(val, tmp);
2947 static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2949 TCGMemOp op = MO_SL | ctx->default_tcg_memop_mask;
2950 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
2953 static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2955 TCGv tmp = tcg_temp_new();
2956 gen_qemu_ld32s(ctx, tmp, addr);
2957 tcg_gen_ext_tl_i64(val, tmp);
2961 static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2963 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2964 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
2967 static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
2969 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
2972 static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
2974 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2975 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
2978 static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
2980 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2981 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
2984 static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2986 TCGv tmp = tcg_temp_new();
2987 tcg_gen_trunc_i64_tl(tmp, val);
2988 gen_qemu_st32(ctx, tmp, addr);
2992 static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2994 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2995 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
2998 #define GEN_LD(name, ldop, opc, type) \
2999 static void glue(gen_, name)(DisasContext *ctx) \
3002 gen_set_access_type(ctx, ACCESS_INT); \
3003 EA = tcg_temp_new(); \
3004 gen_addr_imm_index(ctx, EA, 0); \
3005 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3006 tcg_temp_free(EA); \
3009 #define GEN_LDU(name, ldop, opc, type) \
3010 static void glue(gen_, name##u)(DisasContext *ctx) \
3013 if (unlikely(rA(ctx->opcode) == 0 || \
3014 rA(ctx->opcode) == rD(ctx->opcode))) { \
3015 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3018 gen_set_access_type(ctx, ACCESS_INT); \
3019 EA = tcg_temp_new(); \
3020 if (type == PPC_64B) \
3021 gen_addr_imm_index(ctx, EA, 0x03); \
3023 gen_addr_imm_index(ctx, EA, 0); \
3024 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3025 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3026 tcg_temp_free(EA); \
3029 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
3030 static void glue(gen_, name##ux)(DisasContext *ctx) \
3033 if (unlikely(rA(ctx->opcode) == 0 || \
3034 rA(ctx->opcode) == rD(ctx->opcode))) { \
3035 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3038 gen_set_access_type(ctx, ACCESS_INT); \
3039 EA = tcg_temp_new(); \
3040 gen_addr_reg_index(ctx, EA); \
3041 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3042 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3043 tcg_temp_free(EA); \
3046 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
3047 static void glue(gen_, name##x)(DisasContext *ctx) \
3051 gen_set_access_type(ctx, ACCESS_INT); \
3052 EA = tcg_temp_new(); \
3053 gen_addr_reg_index(ctx, EA); \
3054 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3055 tcg_temp_free(EA); \
3058 #define GEN_LDX(name, ldop, opc2, opc3, type) \
3059 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3061 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
3062 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3064 #define GEN_LDS(name, ldop, op, type) \
3065 GEN_LD(name, ldop, op | 0x20, type); \
3066 GEN_LDU(name, ldop, op | 0x21, type); \
3067 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
3068 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
3070 /* lbz lbzu lbzux lbzx */
3071 GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
3072 /* lha lhau lhaux lhax */
3073 GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
3074 /* lhz lhzu lhzux lhzx */
3075 GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
3076 /* lwz lwzu lwzux lwzx */
3077 GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
3078 #if defined(TARGET_PPC64)
3080 GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
3082 GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
3084 GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
3086 GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
3088 /* CI load/store variants */
3089 GEN_LDX_HVRM(ldcix, ld64, 0x15, 0x1b, PPC_CILDST)
3090 GEN_LDX_HVRM(lwzcix, ld32u, 0x15, 0x15, PPC_CILDST)
3091 GEN_LDX_HVRM(lhzcix, ld16u, 0x15, 0x19, PPC_CILDST)
3092 GEN_LDX_HVRM(lbzcix, ld8u, 0x15, 0x1a, PPC_CILDST)
3094 static void gen_ld(DisasContext *ctx)
3097 if (Rc(ctx->opcode)) {
3098 if (unlikely(rA(ctx->opcode) == 0 ||
3099 rA(ctx->opcode) == rD(ctx->opcode))) {
3100 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3104 gen_set_access_type(ctx, ACCESS_INT);
3105 EA = tcg_temp_new();
3106 gen_addr_imm_index(ctx, EA, 0x03);
3107 if (ctx->opcode & 0x02) {
3108 /* lwa (lwau is undefined) */
3109 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
3112 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
3114 if (Rc(ctx->opcode))
3115 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3120 static void gen_lq(DisasContext *ctx)
3125 /* lq is a legal user mode instruction starting in ISA 2.07 */
3126 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3127 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3129 if (!legal_in_user_mode && ctx->pr) {
3130 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3134 if (!le_is_supported && ctx->le_mode) {
3135 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
3139 ra = rA(ctx->opcode);
3140 rd = rD(ctx->opcode);
3141 if (unlikely((rd & 1) || rd == ra)) {
3142 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3146 gen_set_access_type(ctx, ACCESS_INT);
3147 EA = tcg_temp_new();
3148 gen_addr_imm_index(ctx, EA, 0x0F);
3150 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3151 64-bit byteswap already. */
3152 if (unlikely(ctx->le_mode)) {
3153 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
3154 gen_addr_add(ctx, EA, EA, 8);
3155 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
3157 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
3158 gen_addr_add(ctx, EA, EA, 8);
3159 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
3165 /*** Integer store ***/
3166 #define GEN_ST(name, stop, opc, type) \
3167 static void glue(gen_, name)(DisasContext *ctx) \
3170 gen_set_access_type(ctx, ACCESS_INT); \
3171 EA = tcg_temp_new(); \
3172 gen_addr_imm_index(ctx, EA, 0); \
3173 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3174 tcg_temp_free(EA); \
3177 #define GEN_STU(name, stop, opc, type) \
3178 static void glue(gen_, stop##u)(DisasContext *ctx) \
3181 if (unlikely(rA(ctx->opcode) == 0)) { \
3182 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3185 gen_set_access_type(ctx, ACCESS_INT); \
3186 EA = tcg_temp_new(); \
3187 if (type == PPC_64B) \
3188 gen_addr_imm_index(ctx, EA, 0x03); \
3190 gen_addr_imm_index(ctx, EA, 0); \
3191 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3192 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3193 tcg_temp_free(EA); \
3196 #define GEN_STUX(name, stop, opc2, opc3, type) \
3197 static void glue(gen_, name##ux)(DisasContext *ctx) \
3200 if (unlikely(rA(ctx->opcode) == 0)) { \
3201 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3204 gen_set_access_type(ctx, ACCESS_INT); \
3205 EA = tcg_temp_new(); \
3206 gen_addr_reg_index(ctx, EA); \
3207 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3208 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3209 tcg_temp_free(EA); \
3212 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
3213 static void glue(gen_, name##x)(DisasContext *ctx) \
3217 gen_set_access_type(ctx, ACCESS_INT); \
3218 EA = tcg_temp_new(); \
3219 gen_addr_reg_index(ctx, EA); \
3220 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3221 tcg_temp_free(EA); \
3223 #define GEN_STX(name, stop, opc2, opc3, type) \
3224 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3226 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
3227 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3229 #define GEN_STS(name, stop, op, type) \
3230 GEN_ST(name, stop, op | 0x20, type); \
3231 GEN_STU(name, stop, op | 0x21, type); \
3232 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3233 GEN_STX(name, stop, 0x17, op | 0x00, type)
3235 /* stb stbu stbux stbx */
3236 GEN_STS(stb, st8, 0x06, PPC_INTEGER);
3237 /* sth sthu sthux sthx */
3238 GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
3239 /* stw stwu stwux stwx */
3240 GEN_STS(stw, st32, 0x04, PPC_INTEGER);
3241 #if defined(TARGET_PPC64)
3242 GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
3243 GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
3244 GEN_STX_HVRM(stdcix, st64, 0x15, 0x1f, PPC_CILDST)
3245 GEN_STX_HVRM(stwcix, st32, 0x15, 0x1c, PPC_CILDST)
3246 GEN_STX_HVRM(sthcix, st16, 0x15, 0x1d, PPC_CILDST)
3247 GEN_STX_HVRM(stbcix, st8, 0x15, 0x1e, PPC_CILDST)
3249 static void gen_std(DisasContext *ctx)
3254 rs = rS(ctx->opcode);
3255 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3256 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3257 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3259 if (!(ctx->insns_flags & PPC_64BX)) {
3260 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3263 if (!legal_in_user_mode && ctx->pr) {
3264 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3268 if (!le_is_supported && ctx->le_mode) {
3269 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
3273 if (unlikely(rs & 1)) {
3274 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3277 gen_set_access_type(ctx, ACCESS_INT);
3278 EA = tcg_temp_new();
3279 gen_addr_imm_index(ctx, EA, 0x03);
3281 /* We only need to swap high and low halves. gen_qemu_st64 does
3282 necessary 64-bit byteswap already. */
3283 if (unlikely(ctx->le_mode)) {
3284 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3285 gen_addr_add(ctx, EA, EA, 8);
3286 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3288 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3289 gen_addr_add(ctx, EA, EA, 8);
3290 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3295 if (Rc(ctx->opcode)) {
3296 if (unlikely(rA(ctx->opcode) == 0)) {
3297 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3301 gen_set_access_type(ctx, ACCESS_INT);
3302 EA = tcg_temp_new();
3303 gen_addr_imm_index(ctx, EA, 0x03);
3304 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3305 if (Rc(ctx->opcode))
3306 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3311 /*** Integer load and store with byte reverse ***/
3314 static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3316 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3317 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
3319 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
3322 static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3324 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3325 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
3327 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
3329 #if defined(TARGET_PPC64)
3331 static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3333 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3334 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
3336 GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX, CHK_NONE);
3337 #endif /* TARGET_PPC64 */
3340 static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3342 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3343 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
3345 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
3348 static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3350 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3351 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
3353 GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
3355 #if defined(TARGET_PPC64)
3357 static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3359 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3360 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
3362 GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX, CHK_NONE);
3363 #endif /* TARGET_PPC64 */
3365 /*** Integer load and store multiple ***/
3368 static void gen_lmw(DisasContext *ctx)
3372 gen_set_access_type(ctx, ACCESS_INT);
3373 /* NIP cannot be restored if the memory exception comes from an helper */
3374 gen_update_nip(ctx, ctx->nip - 4);
3375 t0 = tcg_temp_new();
3376 t1 = tcg_const_i32(rD(ctx->opcode));
3377 gen_addr_imm_index(ctx, t0, 0);
3378 gen_helper_lmw(cpu_env, t0, t1);
3380 tcg_temp_free_i32(t1);
3384 static void gen_stmw(DisasContext *ctx)
3388 gen_set_access_type(ctx, ACCESS_INT);
3389 /* NIP cannot be restored if the memory exception comes from an helper */
3390 gen_update_nip(ctx, ctx->nip - 4);
3391 t0 = tcg_temp_new();
3392 t1 = tcg_const_i32(rS(ctx->opcode));
3393 gen_addr_imm_index(ctx, t0, 0);
3394 gen_helper_stmw(cpu_env, t0, t1);
3396 tcg_temp_free_i32(t1);
3399 /*** Integer load and store strings ***/
3402 /* PowerPC32 specification says we must generate an exception if
3403 * rA is in the range of registers to be loaded.
3404 * In an other hand, IBM says this is valid, but rA won't be loaded.
3405 * For now, I'll follow the spec...
3407 static void gen_lswi(DisasContext *ctx)
3411 int nb = NB(ctx->opcode);
3412 int start = rD(ctx->opcode);
3413 int ra = rA(ctx->opcode);
3419 if (unlikely(lsw_reg_in_range(start, nr, ra))) {
3420 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
3423 gen_set_access_type(ctx, ACCESS_INT);
3424 /* NIP cannot be restored if the memory exception comes from an helper */
3425 gen_update_nip(ctx, ctx->nip - 4);
3426 t0 = tcg_temp_new();
3427 gen_addr_register(ctx, t0);
3428 t1 = tcg_const_i32(nb);
3429 t2 = tcg_const_i32(start);
3430 gen_helper_lsw(cpu_env, t0, t1, t2);
3432 tcg_temp_free_i32(t1);
3433 tcg_temp_free_i32(t2);
3437 static void gen_lswx(DisasContext *ctx)
3440 TCGv_i32 t1, t2, t3;
3441 gen_set_access_type(ctx, ACCESS_INT);
3442 /* NIP cannot be restored if the memory exception comes from an helper */
3443 gen_update_nip(ctx, ctx->nip - 4);
3444 t0 = tcg_temp_new();
3445 gen_addr_reg_index(ctx, t0);
3446 t1 = tcg_const_i32(rD(ctx->opcode));
3447 t2 = tcg_const_i32(rA(ctx->opcode));
3448 t3 = tcg_const_i32(rB(ctx->opcode));
3449 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
3451 tcg_temp_free_i32(t1);
3452 tcg_temp_free_i32(t2);
3453 tcg_temp_free_i32(t3);
3457 static void gen_stswi(DisasContext *ctx)
3461 int nb = NB(ctx->opcode);
3462 gen_set_access_type(ctx, ACCESS_INT);
3463 /* NIP cannot be restored if the memory exception comes from an helper */
3464 gen_update_nip(ctx, ctx->nip - 4);
3465 t0 = tcg_temp_new();
3466 gen_addr_register(ctx, t0);
3469 t1 = tcg_const_i32(nb);
3470 t2 = tcg_const_i32(rS(ctx->opcode));
3471 gen_helper_stsw(cpu_env, t0, t1, t2);
3473 tcg_temp_free_i32(t1);
3474 tcg_temp_free_i32(t2);
3478 static void gen_stswx(DisasContext *ctx)
3482 gen_set_access_type(ctx, ACCESS_INT);
3483 /* NIP cannot be restored if the memory exception comes from an helper */
3484 gen_update_nip(ctx, ctx->nip - 4);
3485 t0 = tcg_temp_new();
3486 gen_addr_reg_index(ctx, t0);
3487 t1 = tcg_temp_new_i32();
3488 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3489 tcg_gen_andi_i32(t1, t1, 0x7F);
3490 t2 = tcg_const_i32(rS(ctx->opcode));
3491 gen_helper_stsw(cpu_env, t0, t1, t2);
3493 tcg_temp_free_i32(t1);
3494 tcg_temp_free_i32(t2);
3497 /*** Memory synchronisation ***/
3499 static void gen_eieio(DisasContext *ctx)
3503 #if !defined(CONFIG_USER_ONLY)
3504 static inline void gen_check_tlb_flush(DisasContext *ctx)
3509 if (!ctx->lazy_tlb_flush) {
3512 l = gen_new_label();
3513 t = tcg_temp_new_i32();
3514 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, tlb_need_flush));
3515 tcg_gen_brcondi_i32(TCG_COND_EQ, t, 0, l);
3516 gen_helper_check_tlb_flush(cpu_env);
3518 tcg_temp_free_i32(t);
3521 static inline void gen_check_tlb_flush(DisasContext *ctx) { }
3525 static void gen_isync(DisasContext *ctx)
3528 * We need to check for a pending TLB flush. This can only happen in
3529 * kernel mode however so check MSR_PR
3532 gen_check_tlb_flush(ctx);
3534 gen_stop_exception(ctx);
3537 #define LARX(name, len, loadop) \
3538 static void gen_##name(DisasContext *ctx) \
3541 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3542 gen_set_access_type(ctx, ACCESS_RES); \
3543 t0 = tcg_temp_local_new(); \
3544 gen_addr_reg_index(ctx, t0); \
3546 gen_check_align(ctx, t0, (len)-1); \
3548 gen_qemu_##loadop(ctx, gpr, t0); \
3549 tcg_gen_mov_tl(cpu_reserve, t0); \
3550 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3551 tcg_temp_free(t0); \
3555 LARX(lbarx, 1, ld8u);
3556 LARX(lharx, 2, ld16u);
3557 LARX(lwarx, 4, ld32u);
3560 #if defined(CONFIG_USER_ONLY)
3561 static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3564 TCGv t0 = tcg_temp_new();
3565 uint32_t save_exception = ctx->exception;
3567 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
3568 tcg_gen_movi_tl(t0, (size << 5) | reg);
3569 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
3571 gen_update_nip(ctx, ctx->nip-4);
3572 ctx->exception = POWERPC_EXCP_BRANCH;
3573 gen_exception(ctx, POWERPC_EXCP_STCX);
3574 ctx->exception = save_exception;
3577 static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3582 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3583 l1 = gen_new_label();
3584 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3585 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3586 #if defined(TARGET_PPC64)
3588 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3592 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3593 } else if (size == 2) {
3594 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
3595 #if defined(TARGET_PPC64)
3596 } else if (size == 16) {
3597 TCGv gpr1, gpr2 , EA8;
3598 if (unlikely(ctx->le_mode)) {
3599 gpr1 = cpu_gpr[reg+1];
3600 gpr2 = cpu_gpr[reg];
3602 gpr1 = cpu_gpr[reg];
3603 gpr2 = cpu_gpr[reg+1];
3605 gen_qemu_st64(ctx, gpr1, EA);
3606 EA8 = tcg_temp_local_new();
3607 gen_addr_add(ctx, EA8, EA, 8);
3608 gen_qemu_st64(ctx, gpr2, EA8);
3612 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
3615 tcg_gen_movi_tl(cpu_reserve, -1);
3619 #define STCX(name, len) \
3620 static void gen_##name(DisasContext *ctx) \
3623 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3624 gen_inval_exception(ctx, \
3625 POWERPC_EXCP_INVAL_INVAL); \
3628 gen_set_access_type(ctx, ACCESS_RES); \
3629 t0 = tcg_temp_local_new(); \
3630 gen_addr_reg_index(ctx, t0); \
3632 gen_check_align(ctx, t0, (len)-1); \
3634 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3635 tcg_temp_free(t0); \
3642 #if defined(TARGET_PPC64)
3644 LARX(ldarx, 8, ld64);
3647 static void gen_lqarx(DisasContext *ctx)
3650 int rd = rD(ctx->opcode);
3653 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3654 (rd == rB(ctx->opcode)))) {
3655 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3659 gen_set_access_type(ctx, ACCESS_RES);
3660 EA = tcg_temp_local_new();
3661 gen_addr_reg_index(ctx, EA);
3662 gen_check_align(ctx, EA, 15);
3663 if (unlikely(ctx->le_mode)) {
3664 gpr1 = cpu_gpr[rd+1];
3668 gpr2 = cpu_gpr[rd+1];
3670 gen_qemu_ld64(ctx, gpr1, EA);
3671 tcg_gen_mov_tl(cpu_reserve, EA);
3673 gen_addr_add(ctx, EA, EA, 8);
3674 gen_qemu_ld64(ctx, gpr2, EA);
3676 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3677 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3685 #endif /* defined(TARGET_PPC64) */
3688 static void gen_sync(DisasContext *ctx)
3690 uint32_t l = (ctx->opcode >> 21) & 3;
3693 * We may need to check for a pending TLB flush.
3695 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
3697 * Additionally, this can only happen in kernel mode however so
3698 * check MSR_PR as well.
3700 if (((l == 2) || !(ctx->insns_flags & PPC_64B)) && !ctx->pr) {
3701 gen_check_tlb_flush(ctx);
3706 static void gen_wait(DisasContext *ctx)
3708 TCGv_i32 t0 = tcg_const_i32(1);
3709 tcg_gen_st_i32(t0, cpu_env,
3710 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
3711 tcg_temp_free_i32(t0);
3712 /* Stop translation, as the CPU is supposed to sleep from now */
3713 gen_exception_err(ctx, EXCP_HLT, 1);
3716 #if defined(TARGET_PPC64)
3717 static void gen_doze(DisasContext *ctx)
3719 #if defined(CONFIG_USER_ONLY)
3725 t = tcg_const_i32(PPC_PM_DOZE);
3726 gen_helper_pminsn(cpu_env, t);
3727 tcg_temp_free_i32(t);
3728 gen_stop_exception(ctx);
3729 #endif /* defined(CONFIG_USER_ONLY) */
3732 static void gen_nap(DisasContext *ctx)
3734 #if defined(CONFIG_USER_ONLY)
3740 t = tcg_const_i32(PPC_PM_NAP);
3741 gen_helper_pminsn(cpu_env, t);
3742 tcg_temp_free_i32(t);
3743 gen_stop_exception(ctx);
3744 #endif /* defined(CONFIG_USER_ONLY) */
3747 static void gen_sleep(DisasContext *ctx)
3749 #if defined(CONFIG_USER_ONLY)
3755 t = tcg_const_i32(PPC_PM_SLEEP);
3756 gen_helper_pminsn(cpu_env, t);
3757 tcg_temp_free_i32(t);
3758 gen_stop_exception(ctx);
3759 #endif /* defined(CONFIG_USER_ONLY) */
3762 static void gen_rvwinkle(DisasContext *ctx)
3764 #if defined(CONFIG_USER_ONLY)
3770 t = tcg_const_i32(PPC_PM_RVWINKLE);
3771 gen_helper_pminsn(cpu_env, t);
3772 tcg_temp_free_i32(t);
3773 gen_stop_exception(ctx);
3774 #endif /* defined(CONFIG_USER_ONLY) */
3776 #endif /* #if defined(TARGET_PPC64) */
3778 /*** Floating-point load ***/
3779 #define GEN_LDF(name, ldop, opc, type) \
3780 static void glue(gen_, name)(DisasContext *ctx) \
3783 if (unlikely(!ctx->fpu_enabled)) { \
3784 gen_exception(ctx, POWERPC_EXCP_FPU); \
3787 gen_set_access_type(ctx, ACCESS_FLOAT); \
3788 EA = tcg_temp_new(); \
3789 gen_addr_imm_index(ctx, EA, 0); \
3790 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3791 tcg_temp_free(EA); \
3794 #define GEN_LDUF(name, ldop, opc, type) \
3795 static void glue(gen_, name##u)(DisasContext *ctx) \
3798 if (unlikely(!ctx->fpu_enabled)) { \
3799 gen_exception(ctx, POWERPC_EXCP_FPU); \
3802 if (unlikely(rA(ctx->opcode) == 0)) { \
3803 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3806 gen_set_access_type(ctx, ACCESS_FLOAT); \
3807 EA = tcg_temp_new(); \
3808 gen_addr_imm_index(ctx, EA, 0); \
3809 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3810 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3811 tcg_temp_free(EA); \
3814 #define GEN_LDUXF(name, ldop, opc, type) \
3815 static void glue(gen_, name##ux)(DisasContext *ctx) \
3818 if (unlikely(!ctx->fpu_enabled)) { \
3819 gen_exception(ctx, POWERPC_EXCP_FPU); \
3822 if (unlikely(rA(ctx->opcode) == 0)) { \
3823 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3826 gen_set_access_type(ctx, ACCESS_FLOAT); \
3827 EA = tcg_temp_new(); \
3828 gen_addr_reg_index(ctx, EA); \
3829 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3830 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3831 tcg_temp_free(EA); \
3834 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3835 static void glue(gen_, name##x)(DisasContext *ctx) \
3838 if (unlikely(!ctx->fpu_enabled)) { \
3839 gen_exception(ctx, POWERPC_EXCP_FPU); \
3842 gen_set_access_type(ctx, ACCESS_FLOAT); \
3843 EA = tcg_temp_new(); \
3844 gen_addr_reg_index(ctx, EA); \
3845 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3846 tcg_temp_free(EA); \
3849 #define GEN_LDFS(name, ldop, op, type) \
3850 GEN_LDF(name, ldop, op | 0x20, type); \
3851 GEN_LDUF(name, ldop, op | 0x21, type); \
3852 GEN_LDUXF(name, ldop, op | 0x01, type); \
3853 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3855 static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3857 TCGv t0 = tcg_temp_new();
3858 TCGv_i32 t1 = tcg_temp_new_i32();
3859 gen_qemu_ld32u(ctx, t0, arg2);
3860 tcg_gen_trunc_tl_i32(t1, t0);
3862 gen_helper_float32_to_float64(arg1, cpu_env, t1);
3863 tcg_temp_free_i32(t1);
3866 /* lfd lfdu lfdux lfdx */
3867 GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3868 /* lfs lfsu lfsux lfsx */
3869 GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
3872 static void gen_lfdp(DisasContext *ctx)
3875 if (unlikely(!ctx->fpu_enabled)) {
3876 gen_exception(ctx, POWERPC_EXCP_FPU);
3879 gen_set_access_type(ctx, ACCESS_FLOAT);
3880 EA = tcg_temp_new();
3881 gen_addr_imm_index(ctx, EA, 0);
3882 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3883 64-bit byteswap already. */
3884 if (unlikely(ctx->le_mode)) {
3885 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3886 tcg_gen_addi_tl(EA, EA, 8);
3887 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3889 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3890 tcg_gen_addi_tl(EA, EA, 8);
3891 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3897 static void gen_lfdpx(DisasContext *ctx)
3900 if (unlikely(!ctx->fpu_enabled)) {
3901 gen_exception(ctx, POWERPC_EXCP_FPU);
3904 gen_set_access_type(ctx, ACCESS_FLOAT);
3905 EA = tcg_temp_new();
3906 gen_addr_reg_index(ctx, EA);
3907 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3908 64-bit byteswap already. */
3909 if (unlikely(ctx->le_mode)) {
3910 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3911 tcg_gen_addi_tl(EA, EA, 8);
3912 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3914 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3915 tcg_gen_addi_tl(EA, EA, 8);
3916 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3922 static void gen_lfiwax(DisasContext *ctx)
3926 if (unlikely(!ctx->fpu_enabled)) {
3927 gen_exception(ctx, POWERPC_EXCP_FPU);
3930 gen_set_access_type(ctx, ACCESS_FLOAT);
3931 EA = tcg_temp_new();
3932 t0 = tcg_temp_new();
3933 gen_addr_reg_index(ctx, EA);
3934 gen_qemu_ld32s(ctx, t0, EA);
3935 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
3941 static void gen_lfiwzx(DisasContext *ctx)
3944 if (unlikely(!ctx->fpu_enabled)) {
3945 gen_exception(ctx, POWERPC_EXCP_FPU);
3948 gen_set_access_type(ctx, ACCESS_FLOAT);
3949 EA = tcg_temp_new();
3950 gen_addr_reg_index(ctx, EA);
3951 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3954 /*** Floating-point store ***/
3955 #define GEN_STF(name, stop, opc, type) \
3956 static void glue(gen_, name)(DisasContext *ctx) \
3959 if (unlikely(!ctx->fpu_enabled)) { \
3960 gen_exception(ctx, POWERPC_EXCP_FPU); \
3963 gen_set_access_type(ctx, ACCESS_FLOAT); \
3964 EA = tcg_temp_new(); \
3965 gen_addr_imm_index(ctx, EA, 0); \
3966 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3967 tcg_temp_free(EA); \
3970 #define GEN_STUF(name, stop, opc, type) \
3971 static void glue(gen_, name##u)(DisasContext *ctx) \
3974 if (unlikely(!ctx->fpu_enabled)) { \
3975 gen_exception(ctx, POWERPC_EXCP_FPU); \
3978 if (unlikely(rA(ctx->opcode) == 0)) { \
3979 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3982 gen_set_access_type(ctx, ACCESS_FLOAT); \
3983 EA = tcg_temp_new(); \
3984 gen_addr_imm_index(ctx, EA, 0); \
3985 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3986 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3987 tcg_temp_free(EA); \
3990 #define GEN_STUXF(name, stop, opc, type) \
3991 static void glue(gen_, name##ux)(DisasContext *ctx) \
3994 if (unlikely(!ctx->fpu_enabled)) { \
3995 gen_exception(ctx, POWERPC_EXCP_FPU); \
3998 if (unlikely(rA(ctx->opcode) == 0)) { \
3999 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
4002 gen_set_access_type(ctx, ACCESS_FLOAT); \
4003 EA = tcg_temp_new(); \
4004 gen_addr_reg_index(ctx, EA); \
4005 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
4006 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
4007 tcg_temp_free(EA); \
4010 #define GEN_STXF(name, stop, opc2, opc3, type) \
4011 static void glue(gen_, name##x)(DisasContext *ctx) \
4014 if (unlikely(!ctx->fpu_enabled)) { \
4015 gen_exception(ctx, POWERPC_EXCP_FPU); \
4018 gen_set_access_type(ctx, ACCESS_FLOAT); \
4019 EA = tcg_temp_new(); \
4020 gen_addr_reg_index(ctx, EA); \
4021 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
4022 tcg_temp_free(EA); \
4025 #define GEN_STFS(name, stop, op, type) \
4026 GEN_STF(name, stop, op | 0x20, type); \
4027 GEN_STUF(name, stop, op | 0x21, type); \
4028 GEN_STUXF(name, stop, op | 0x01, type); \
4029 GEN_STXF(name, stop, 0x17, op | 0x00, type)
4031 static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
4033 TCGv_i32 t0 = tcg_temp_new_i32();
4034 TCGv t1 = tcg_temp_new();
4035 gen_helper_float64_to_float32(t0, cpu_env, arg1);
4036 tcg_gen_extu_i32_tl(t1, t0);
4037 tcg_temp_free_i32(t0);
4038 gen_qemu_st32(ctx, t1, arg2);
4042 /* stfd stfdu stfdux stfdx */
4043 GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
4044 /* stfs stfsu stfsux stfsx */
4045 GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
4048 static void gen_stfdp(DisasContext *ctx)
4051 if (unlikely(!ctx->fpu_enabled)) {
4052 gen_exception(ctx, POWERPC_EXCP_FPU);
4055 gen_set_access_type(ctx, ACCESS_FLOAT);
4056 EA = tcg_temp_new();
4057 gen_addr_imm_index(ctx, EA, 0);
4058 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
4059 64-bit byteswap already. */
4060 if (unlikely(ctx->le_mode)) {
4061 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
4062 tcg_gen_addi_tl(EA, EA, 8);
4063 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
4065 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
4066 tcg_gen_addi_tl(EA, EA, 8);
4067 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
4073 static void gen_stfdpx(DisasContext *ctx)
4076 if (unlikely(!ctx->fpu_enabled)) {
4077 gen_exception(ctx, POWERPC_EXCP_FPU);
4080 gen_set_access_type(ctx, ACCESS_FLOAT);
4081 EA = tcg_temp_new();
4082 gen_addr_reg_index(ctx, EA);
4083 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
4084 64-bit byteswap already. */
4085 if (unlikely(ctx->le_mode)) {
4086 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
4087 tcg_gen_addi_tl(EA, EA, 8);
4088 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
4090 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
4091 tcg_gen_addi_tl(EA, EA, 8);
4092 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
4098 static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
4100 TCGv t0 = tcg_temp_new();
4101 tcg_gen_trunc_i64_tl(t0, arg1),
4102 gen_qemu_st32(ctx, t0, arg2);
4106 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
4108 static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
4110 #if defined(TARGET_PPC64)
4112 tcg_gen_movi_tl(cpu_cfar, nip);
4116 static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest)
4118 if (unlikely(ctx->singlestep_enabled)) {
4122 #ifndef CONFIG_USER_ONLY
4123 return (ctx->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK);
4130 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
4132 if (NARROW_MODE(ctx)) {
4133 dest = (uint32_t) dest;
4135 if (use_goto_tb(ctx, dest)) {
4137 tcg_gen_movi_tl(cpu_nip, dest & ~3);
4138 tcg_gen_exit_tb((uintptr_t)ctx->tb + n);
4140 tcg_gen_movi_tl(cpu_nip, dest & ~3);
4141 if (unlikely(ctx->singlestep_enabled)) {
4142 if ((ctx->singlestep_enabled &
4143 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
4144 (ctx->exception == POWERPC_EXCP_BRANCH ||
4145 ctx->exception == POWERPC_EXCP_TRACE)) {
4146 target_ulong tmp = ctx->nip;
4148 gen_exception(ctx, POWERPC_EXCP_TRACE);
4151 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
4152 gen_debug_exception(ctx);
4159 static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
4161 if (NARROW_MODE(ctx)) {
4162 nip = (uint32_t)nip;
4164 tcg_gen_movi_tl(cpu_lr, nip);
4168 static void gen_b(DisasContext *ctx)
4170 target_ulong li, target;
4172 ctx->exception = POWERPC_EXCP_BRANCH;
4173 /* sign extend LI */
4174 li = LI(ctx->opcode);
4175 li = (li ^ 0x02000000) - 0x02000000;
4176 if (likely(AA(ctx->opcode) == 0)) {
4177 target = ctx->nip + li - 4;
4181 if (LK(ctx->opcode)) {
4182 gen_setlr(ctx, ctx->nip);
4184 gen_update_cfar(ctx, ctx->nip);
4185 gen_goto_tb(ctx, 0, target);
4193 static inline void gen_bcond(DisasContext *ctx, int type)
4195 uint32_t bo = BO(ctx->opcode);
4199 ctx->exception = POWERPC_EXCP_BRANCH;
4200 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
4201 target = tcg_temp_local_new();
4202 if (type == BCOND_CTR)
4203 tcg_gen_mov_tl(target, cpu_ctr);
4204 else if (type == BCOND_TAR)
4205 gen_load_spr(target, SPR_TAR);
4207 tcg_gen_mov_tl(target, cpu_lr);
4209 TCGV_UNUSED(target);
4211 if (LK(ctx->opcode))
4212 gen_setlr(ctx, ctx->nip);
4213 l1 = gen_new_label();
4214 if ((bo & 0x4) == 0) {
4215 /* Decrement and test CTR */
4216 TCGv temp = tcg_temp_new();
4217 if (unlikely(type == BCOND_CTR)) {
4218 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
4221 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
4222 if (NARROW_MODE(ctx)) {
4223 tcg_gen_ext32u_tl(temp, cpu_ctr);
4225 tcg_gen_mov_tl(temp, cpu_ctr);
4228 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
4230 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
4232 tcg_temp_free(temp);
4234 if ((bo & 0x10) == 0) {
4236 uint32_t bi = BI(ctx->opcode);
4237 uint32_t mask = 0x08 >> (bi & 0x03);
4238 TCGv_i32 temp = tcg_temp_new_i32();
4241 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
4242 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
4244 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
4245 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
4247 tcg_temp_free_i32(temp);
4249 gen_update_cfar(ctx, ctx->nip);
4250 if (type == BCOND_IM) {
4251 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
4252 if (likely(AA(ctx->opcode) == 0)) {
4253 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
4255 gen_goto_tb(ctx, 0, li);
4258 gen_goto_tb(ctx, 1, ctx->nip);
4260 if (NARROW_MODE(ctx)) {
4261 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
4263 tcg_gen_andi_tl(cpu_nip, target, ~3);
4267 gen_update_nip(ctx, ctx->nip);
4270 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
4271 tcg_temp_free(target);
4275 static void gen_bc(DisasContext *ctx)
4277 gen_bcond(ctx, BCOND_IM);
4280 static void gen_bcctr(DisasContext *ctx)
4282 gen_bcond(ctx, BCOND_CTR);
4285 static void gen_bclr(DisasContext *ctx)
4287 gen_bcond(ctx, BCOND_LR);
4290 static void gen_bctar(DisasContext *ctx)
4292 gen_bcond(ctx, BCOND_TAR);
4295 /*** Condition register logical ***/
4296 #define GEN_CRLOGIC(name, tcg_op, opc) \
4297 static void glue(gen_, name)(DisasContext *ctx) \
4302 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
4303 t0 = tcg_temp_new_i32(); \
4305 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
4307 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
4309 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
4310 t1 = tcg_temp_new_i32(); \
4311 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4313 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
4315 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
4317 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4318 tcg_op(t0, t0, t1); \
4319 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
4320 tcg_gen_andi_i32(t0, t0, bitmask); \
4321 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4322 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
4323 tcg_temp_free_i32(t0); \
4324 tcg_temp_free_i32(t1); \
4328 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
4330 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
4332 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
4334 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
4336 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
4338 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
4340 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
4342 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
4345 static void gen_mcrf(DisasContext *ctx)
4347 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
4350 /*** System linkage ***/
4352 /* rfi (supervisor only) */
4353 static void gen_rfi(DisasContext *ctx)
4355 #if defined(CONFIG_USER_ONLY)
4358 /* FIXME: This instruction doesn't exist anymore on 64-bit server
4359 * processors compliant with arch 2.x, we should remove it there,
4360 * but we need to fix OpenBIOS not to use it on 970 first
4362 /* Restore CPU state */
4364 gen_update_cfar(ctx, ctx->nip);
4365 gen_helper_rfi(cpu_env);
4366 gen_sync_exception(ctx);
4370 #if defined(TARGET_PPC64)
4371 static void gen_rfid(DisasContext *ctx)
4373 #if defined(CONFIG_USER_ONLY)
4376 /* Restore CPU state */
4378 gen_update_cfar(ctx, ctx->nip);
4379 gen_helper_rfid(cpu_env);
4380 gen_sync_exception(ctx);
4384 static void gen_hrfid(DisasContext *ctx)
4386 #if defined(CONFIG_USER_ONLY)
4389 /* Restore CPU state */
4391 gen_helper_hrfid(cpu_env);
4392 gen_sync_exception(ctx);
4398 #if defined(CONFIG_USER_ONLY)
4399 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4401 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4403 static void gen_sc(DisasContext *ctx)
4407 lev = (ctx->opcode >> 5) & 0x7F;
4408 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
4414 static void gen_tw(DisasContext *ctx)
4416 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
4417 /* Update the nip since this might generate a trap exception */
4418 gen_update_nip(ctx, ctx->nip);
4419 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4421 tcg_temp_free_i32(t0);
4425 static void gen_twi(DisasContext *ctx)
4427 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4428 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
4429 /* Update the nip since this might generate a trap exception */
4430 gen_update_nip(ctx, ctx->nip);
4431 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
4433 tcg_temp_free_i32(t1);
4436 #if defined(TARGET_PPC64)
4438 static void gen_td(DisasContext *ctx)
4440 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
4441 /* Update the nip since this might generate a trap exception */
4442 gen_update_nip(ctx, ctx->nip);
4443 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4445 tcg_temp_free_i32(t0);
4449 static void gen_tdi(DisasContext *ctx)
4451 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4452 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
4453 /* Update the nip since this might generate a trap exception */
4454 gen_update_nip(ctx, ctx->nip);
4455 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
4457 tcg_temp_free_i32(t1);
4461 /*** Processor control ***/
4463 static void gen_read_xer(TCGv dst)
4465 TCGv t0 = tcg_temp_new();
4466 TCGv t1 = tcg_temp_new();
4467 TCGv t2 = tcg_temp_new();
4468 tcg_gen_mov_tl(dst, cpu_xer);
4469 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4470 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4471 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4472 tcg_gen_or_tl(t0, t0, t1);
4473 tcg_gen_or_tl(dst, dst, t2);
4474 tcg_gen_or_tl(dst, dst, t0);
4480 static void gen_write_xer(TCGv src)
4482 tcg_gen_andi_tl(cpu_xer, src,
4483 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4484 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4485 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4486 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4487 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4488 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4489 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4493 static void gen_mcrxr(DisasContext *ctx)
4495 TCGv_i32 t0 = tcg_temp_new_i32();
4496 TCGv_i32 t1 = tcg_temp_new_i32();
4497 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4499 tcg_gen_trunc_tl_i32(t0, cpu_so);
4500 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4501 tcg_gen_trunc_tl_i32(dst, cpu_ca);
4502 tcg_gen_shli_i32(t0, t0, 3);
4503 tcg_gen_shli_i32(t1, t1, 2);
4504 tcg_gen_shli_i32(dst, dst, 1);
4505 tcg_gen_or_i32(dst, dst, t0);
4506 tcg_gen_or_i32(dst, dst, t1);
4507 tcg_temp_free_i32(t0);
4508 tcg_temp_free_i32(t1);
4510 tcg_gen_movi_tl(cpu_so, 0);
4511 tcg_gen_movi_tl(cpu_ov, 0);
4512 tcg_gen_movi_tl(cpu_ca, 0);
4516 static void gen_mfcr(DisasContext *ctx)
4520 if (likely(ctx->opcode & 0x00100000)) {
4521 crm = CRM(ctx->opcode);
4522 if (likely(crm && ((crm & (crm - 1)) == 0))) {
4524 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
4525 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4526 cpu_gpr[rD(ctx->opcode)], crn * 4);
4529 TCGv_i32 t0 = tcg_temp_new_i32();
4530 tcg_gen_mov_i32(t0, cpu_crf[0]);
4531 tcg_gen_shli_i32(t0, t0, 4);
4532 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4533 tcg_gen_shli_i32(t0, t0, 4);
4534 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4535 tcg_gen_shli_i32(t0, t0, 4);
4536 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4537 tcg_gen_shli_i32(t0, t0, 4);
4538 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4539 tcg_gen_shli_i32(t0, t0, 4);
4540 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4541 tcg_gen_shli_i32(t0, t0, 4);
4542 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4543 tcg_gen_shli_i32(t0, t0, 4);
4544 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4545 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4546 tcg_temp_free_i32(t0);
4551 static void gen_mfmsr(DisasContext *ctx)
4554 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
4557 static void spr_noaccess(DisasContext *ctx, int gprn, int sprn)
4560 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4561 printf("ERROR: try to access SPR %d !\n", sprn);
4564 #define SPR_NOACCESS (&spr_noaccess)
4567 static inline void gen_op_mfspr(DisasContext *ctx)
4569 void (*read_cb)(DisasContext *ctx, int gprn, int sprn);
4570 uint32_t sprn = SPR(ctx->opcode);
4572 #if defined(CONFIG_USER_ONLY)
4573 read_cb = ctx->spr_cb[sprn].uea_read;
4576 read_cb = ctx->spr_cb[sprn].uea_read;
4577 } else if (ctx->hv) {
4578 read_cb = ctx->spr_cb[sprn].hea_read;
4580 read_cb = ctx->spr_cb[sprn].oea_read;
4583 if (likely(read_cb != NULL)) {
4584 if (likely(read_cb != SPR_NOACCESS)) {
4585 (*read_cb)(ctx, rD(ctx->opcode), sprn);
4587 /* Privilege exception */
4588 /* This is a hack to avoid warnings when running Linux:
4589 * this OS breaks the PowerPC virtualisation model,
4590 * allowing userland application to read the PVR
4592 if (sprn != SPR_PVR) {
4593 fprintf(stderr, "Trying to read privileged spr %d (0x%03x) at "
4594 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4595 if (qemu_log_separate()) {
4596 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4597 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4600 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_REG);
4603 /* ISA 2.07 defines these as no-ops */
4604 if ((ctx->insns_flags2 & PPC2_ISA207S) &&
4605 (sprn >= 808 && sprn <= 811)) {
4610 fprintf(stderr, "Trying to read invalid spr %d (0x%03x) at "
4611 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4612 if (qemu_log_separate()) {
4613 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4614 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4617 /* The behaviour depends on MSR:PR and SPR# bit 0x10,
4618 * it can generate a priv, a hv emu or a no-op
4622 gen_priv_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4625 if (ctx->pr || sprn == 0 || sprn == 4 || sprn == 5 || sprn == 6) {
4626 gen_hvpriv_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4632 static void gen_mfspr(DisasContext *ctx)
4638 static void gen_mftb(DisasContext *ctx)
4644 static void gen_mtcrf(DisasContext *ctx)
4648 crm = CRM(ctx->opcode);
4649 if (likely((ctx->opcode & 0x00100000))) {
4650 if (crm && ((crm & (crm - 1)) == 0)) {
4651 TCGv_i32 temp = tcg_temp_new_i32();
4653 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4654 tcg_gen_shri_i32(temp, temp, crn * 4);
4655 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
4656 tcg_temp_free_i32(temp);
4659 TCGv_i32 temp = tcg_temp_new_i32();
4660 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4661 for (crn = 0 ; crn < 8 ; crn++) {
4662 if (crm & (1 << crn)) {
4663 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4664 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4667 tcg_temp_free_i32(temp);
4672 #if defined(TARGET_PPC64)
4673 static void gen_mtmsrd(DisasContext *ctx)
4677 #if !defined(CONFIG_USER_ONLY)
4678 if (ctx->opcode & 0x00010000) {
4679 /* Special form that does not need any synchronisation */
4680 TCGv t0 = tcg_temp_new();
4681 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4682 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(target_ulong)((1 << MSR_RI) | (1 << MSR_EE)));
4683 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4686 /* XXX: we need to update nip before the store
4687 * if we enter power saving mode, we will exit the loop
4688 * directly from ppc_store_msr
4690 gen_update_nip(ctx, ctx->nip);
4691 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
4692 /* Must stop the translation as machine state (may have) changed */
4693 /* Note that mtmsr is not always defined as context-synchronizing */
4694 gen_stop_exception(ctx);
4696 #endif /* !defined(CONFIG_USER_ONLY) */
4698 #endif /* defined(TARGET_PPC64) */
4700 static void gen_mtmsr(DisasContext *ctx)
4704 #if !defined(CONFIG_USER_ONLY)
4705 if (ctx->opcode & 0x00010000) {
4706 /* Special form that does not need any synchronisation */
4707 TCGv t0 = tcg_temp_new();
4708 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4709 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(target_ulong)((1 << MSR_RI) | (1 << MSR_EE)));
4710 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4713 TCGv msr = tcg_temp_new();
4715 /* XXX: we need to update nip before the store
4716 * if we enter power saving mode, we will exit the loop
4717 * directly from ppc_store_msr
4719 gen_update_nip(ctx, ctx->nip);
4720 #if defined(TARGET_PPC64)
4721 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4723 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
4725 gen_helper_store_msr(cpu_env, msr);
4727 /* Must stop the translation as machine state (may have) changed */
4728 /* Note that mtmsr is not always defined as context-synchronizing */
4729 gen_stop_exception(ctx);
4735 static void gen_mtspr(DisasContext *ctx)
4737 void (*write_cb)(DisasContext *ctx, int sprn, int gprn);
4738 uint32_t sprn = SPR(ctx->opcode);
4740 #if defined(CONFIG_USER_ONLY)
4741 write_cb = ctx->spr_cb[sprn].uea_write;
4744 write_cb = ctx->spr_cb[sprn].uea_write;
4745 } else if (ctx->hv) {
4746 write_cb = ctx->spr_cb[sprn].hea_write;
4748 write_cb = ctx->spr_cb[sprn].oea_write;
4751 if (likely(write_cb != NULL)) {
4752 if (likely(write_cb != SPR_NOACCESS)) {
4753 (*write_cb)(ctx, sprn, rS(ctx->opcode));
4755 /* Privilege exception */
4756 fprintf(stderr, "Trying to write privileged spr %d (0x%03x) at "
4757 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4758 if (qemu_log_separate()) {
4759 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4760 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4762 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_REG);
4765 /* ISA 2.07 defines these as no-ops */
4766 if ((ctx->insns_flags2 & PPC2_ISA207S) &&
4767 (sprn >= 808 && sprn <= 811)) {
4773 if (qemu_log_separate()) {
4774 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4775 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4777 fprintf(stderr, "Trying to write invalid spr %d (0x%03x) at "
4778 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4781 /* The behaviour depends on MSR:PR and SPR# bit 0x10,
4782 * it can generate a priv, a hv emu or a no-op
4786 gen_priv_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4789 if (ctx->pr || sprn == 0) {
4790 gen_hvpriv_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4796 /*** Cache management ***/
4799 static void gen_dcbf(DisasContext *ctx)
4801 /* XXX: specification says this is treated as a load by the MMU */
4803 gen_set_access_type(ctx, ACCESS_CACHE);
4804 t0 = tcg_temp_new();
4805 gen_addr_reg_index(ctx, t0);
4806 gen_qemu_ld8u(ctx, t0, t0);
4810 /* dcbi (Supervisor only) */
4811 static void gen_dcbi(DisasContext *ctx)
4813 #if defined(CONFIG_USER_ONLY)
4819 EA = tcg_temp_new();
4820 gen_set_access_type(ctx, ACCESS_CACHE);
4821 gen_addr_reg_index(ctx, EA);
4822 val = tcg_temp_new();
4823 /* XXX: specification says this should be treated as a store by the MMU */
4824 gen_qemu_ld8u(ctx, val, EA);
4825 gen_qemu_st8(ctx, val, EA);
4828 #endif /* defined(CONFIG_USER_ONLY) */
4832 static void gen_dcbst(DisasContext *ctx)
4834 /* XXX: specification say this is treated as a load by the MMU */
4836 gen_set_access_type(ctx, ACCESS_CACHE);
4837 t0 = tcg_temp_new();
4838 gen_addr_reg_index(ctx, t0);
4839 gen_qemu_ld8u(ctx, t0, t0);
4844 static void gen_dcbt(DisasContext *ctx)
4846 /* interpreted as no-op */
4847 /* XXX: specification say this is treated as a load by the MMU
4848 * but does not generate any exception
4853 static void gen_dcbtst(DisasContext *ctx)
4855 /* interpreted as no-op */
4856 /* XXX: specification say this is treated as a load by the MMU
4857 * but does not generate any exception
4862 static void gen_dcbtls(DisasContext *ctx)
4864 /* Always fails locking the cache */
4865 TCGv t0 = tcg_temp_new();
4866 gen_load_spr(t0, SPR_Exxx_L1CSR0);
4867 tcg_gen_ori_tl(t0, t0, L1CSR0_CUL);
4868 gen_store_spr(SPR_Exxx_L1CSR0, t0);
4873 static void gen_dcbz(DisasContext *ctx)
4876 TCGv_i32 tcgv_is_dcbzl;
4877 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
4879 gen_set_access_type(ctx, ACCESS_CACHE);
4880 /* NIP cannot be restored if the memory exception comes from an helper */
4881 gen_update_nip(ctx, ctx->nip - 4);
4882 tcgv_addr = tcg_temp_new();
4883 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4885 gen_addr_reg_index(ctx, tcgv_addr);
4886 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4888 tcg_temp_free(tcgv_addr);
4889 tcg_temp_free_i32(tcgv_is_dcbzl);
4893 static void gen_dst(DisasContext *ctx)
4895 if (rA(ctx->opcode) == 0) {
4896 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4898 /* interpreted as no-op */
4903 static void gen_dstst(DisasContext *ctx)
4905 if (rA(ctx->opcode) == 0) {
4906 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4908 /* interpreted as no-op */
4914 static void gen_dss(DisasContext *ctx)
4916 /* interpreted as no-op */
4920 static void gen_icbi(DisasContext *ctx)
4923 gen_set_access_type(ctx, ACCESS_CACHE);
4924 /* NIP cannot be restored if the memory exception comes from an helper */
4925 gen_update_nip(ctx, ctx->nip - 4);
4926 t0 = tcg_temp_new();
4927 gen_addr_reg_index(ctx, t0);
4928 gen_helper_icbi(cpu_env, t0);
4934 static void gen_dcba(DisasContext *ctx)
4936 /* interpreted as no-op */
4937 /* XXX: specification say this is treated as a store by the MMU
4938 * but does not generate any exception
4942 /*** Segment register manipulation ***/
4943 /* Supervisor only: */
4946 static void gen_mfsr(DisasContext *ctx)
4948 #if defined(CONFIG_USER_ONLY)
4954 t0 = tcg_const_tl(SR(ctx->opcode));
4955 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4957 #endif /* defined(CONFIG_USER_ONLY) */
4961 static void gen_mfsrin(DisasContext *ctx)
4963 #if defined(CONFIG_USER_ONLY)
4969 t0 = tcg_temp_new();
4970 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4971 tcg_gen_andi_tl(t0, t0, 0xF);
4972 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4974 #endif /* defined(CONFIG_USER_ONLY) */
4978 static void gen_mtsr(DisasContext *ctx)
4980 #if defined(CONFIG_USER_ONLY)
4986 t0 = tcg_const_tl(SR(ctx->opcode));
4987 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4989 #endif /* defined(CONFIG_USER_ONLY) */
4993 static void gen_mtsrin(DisasContext *ctx)
4995 #if defined(CONFIG_USER_ONLY)
5001 t0 = tcg_temp_new();
5002 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
5003 tcg_gen_andi_tl(t0, t0, 0xF);
5004 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
5006 #endif /* defined(CONFIG_USER_ONLY) */
5009 #if defined(TARGET_PPC64)
5010 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
5013 static void gen_mfsr_64b(DisasContext *ctx)
5015 #if defined(CONFIG_USER_ONLY)
5021 t0 = tcg_const_tl(SR(ctx->opcode));
5022 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
5024 #endif /* defined(CONFIG_USER_ONLY) */
5028 static void gen_mfsrin_64b(DisasContext *ctx)
5030 #if defined(CONFIG_USER_ONLY)
5036 t0 = tcg_temp_new();
5037 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
5038 tcg_gen_andi_tl(t0, t0, 0xF);
5039 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
5041 #endif /* defined(CONFIG_USER_ONLY) */
5045 static void gen_mtsr_64b(DisasContext *ctx)
5047 #if defined(CONFIG_USER_ONLY)
5053 t0 = tcg_const_tl(SR(ctx->opcode));
5054 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
5056 #endif /* defined(CONFIG_USER_ONLY) */
5060 static void gen_mtsrin_64b(DisasContext *ctx)
5062 #if defined(CONFIG_USER_ONLY)
5068 t0 = tcg_temp_new();
5069 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
5070 tcg_gen_andi_tl(t0, t0, 0xF);
5071 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
5073 #endif /* defined(CONFIG_USER_ONLY) */
5077 static void gen_slbmte(DisasContext *ctx)
5079 #if defined(CONFIG_USER_ONLY)
5084 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
5085 cpu_gpr[rS(ctx->opcode)]);
5086 #endif /* defined(CONFIG_USER_ONLY) */
5089 static void gen_slbmfee(DisasContext *ctx)
5091 #if defined(CONFIG_USER_ONLY)
5096 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
5097 cpu_gpr[rB(ctx->opcode)]);
5098 #endif /* defined(CONFIG_USER_ONLY) */
5101 static void gen_slbmfev(DisasContext *ctx)
5103 #if defined(CONFIG_USER_ONLY)
5108 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
5109 cpu_gpr[rB(ctx->opcode)]);
5110 #endif /* defined(CONFIG_USER_ONLY) */
5113 static void gen_slbfee_(DisasContext *ctx)
5115 #if defined(CONFIG_USER_ONLY)
5116 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5120 if (unlikely(ctx->pr)) {
5121 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5124 gen_helper_find_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
5125 cpu_gpr[rB(ctx->opcode)]);
5126 l1 = gen_new_label();
5127 l2 = gen_new_label();
5128 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
5129 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rS(ctx->opcode)], -1, l1);
5130 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
5133 tcg_gen_movi_tl(cpu_gpr[rS(ctx->opcode)], 0);
5137 #endif /* defined(TARGET_PPC64) */
5139 /*** Lookaside buffer management ***/
5140 /* Optional & supervisor only: */
5143 static void gen_tlbia(DisasContext *ctx)
5145 #if defined(CONFIG_USER_ONLY)
5150 gen_helper_tlbia(cpu_env);
5151 #endif /* defined(CONFIG_USER_ONLY) */
5155 static void gen_tlbiel(DisasContext *ctx)
5157 #if defined(CONFIG_USER_ONLY)
5162 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5163 #endif /* defined(CONFIG_USER_ONLY) */
5167 static void gen_tlbie(DisasContext *ctx)
5169 #if defined(CONFIG_USER_ONLY)
5174 if (NARROW_MODE(ctx)) {
5175 TCGv t0 = tcg_temp_new();
5176 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
5177 gen_helper_tlbie(cpu_env, t0);
5180 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5182 #endif /* defined(CONFIG_USER_ONLY) */
5186 static void gen_tlbsync(DisasContext *ctx)
5188 #if defined(CONFIG_USER_ONLY)
5193 /* tlbsync is a nop for server, ptesync handles delayed tlb flush,
5194 * embedded however needs to deal with tlbsync. We don't try to be
5195 * fancy and swallow the overhead of checking for both.
5197 gen_check_tlb_flush(ctx);
5198 #endif /* defined(CONFIG_USER_ONLY) */
5201 #if defined(TARGET_PPC64)
5203 static void gen_slbia(DisasContext *ctx)
5205 #if defined(CONFIG_USER_ONLY)
5210 gen_helper_slbia(cpu_env);
5211 #endif /* defined(CONFIG_USER_ONLY) */
5215 static void gen_slbie(DisasContext *ctx)
5217 #if defined(CONFIG_USER_ONLY)
5222 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5223 #endif /* defined(CONFIG_USER_ONLY) */
5225 #endif /* defined(TARGET_PPC64) */
5227 /*** External control ***/
5231 static void gen_eciwx(DisasContext *ctx)
5234 /* Should check EAR[E] ! */
5235 gen_set_access_type(ctx, ACCESS_EXT);
5236 t0 = tcg_temp_new();
5237 gen_addr_reg_index(ctx, t0);
5238 gen_check_align(ctx, t0, 0x03);
5239 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
5244 static void gen_ecowx(DisasContext *ctx)
5247 /* Should check EAR[E] ! */
5248 gen_set_access_type(ctx, ACCESS_EXT);
5249 t0 = tcg_temp_new();
5250 gen_addr_reg_index(ctx, t0);
5251 gen_check_align(ctx, t0, 0x03);
5252 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
5256 /* PowerPC 601 specific instructions */
5259 static void gen_abs(DisasContext *ctx)
5261 TCGLabel *l1 = gen_new_label();
5262 TCGLabel *l2 = gen_new_label();
5263 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
5264 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5267 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5269 if (unlikely(Rc(ctx->opcode) != 0))
5270 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5274 static void gen_abso(DisasContext *ctx)
5276 TCGLabel *l1 = gen_new_label();
5277 TCGLabel *l2 = gen_new_label();
5278 TCGLabel *l3 = gen_new_label();
5279 /* Start with XER OV disabled, the most likely case */
5280 tcg_gen_movi_tl(cpu_ov, 0);
5281 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
5282 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
5283 tcg_gen_movi_tl(cpu_ov, 1);
5284 tcg_gen_movi_tl(cpu_so, 1);
5287 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5290 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5292 if (unlikely(Rc(ctx->opcode) != 0))
5293 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5297 static void gen_clcs(DisasContext *ctx)
5299 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
5300 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
5301 tcg_temp_free_i32(t0);
5302 /* Rc=1 sets CR0 to an undefined state */
5306 static void gen_div(DisasContext *ctx)
5308 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5309 cpu_gpr[rB(ctx->opcode)]);
5310 if (unlikely(Rc(ctx->opcode) != 0))
5311 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5315 static void gen_divo(DisasContext *ctx)
5317 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5318 cpu_gpr[rB(ctx->opcode)]);
5319 if (unlikely(Rc(ctx->opcode) != 0))
5320 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5324 static void gen_divs(DisasContext *ctx)
5326 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5327 cpu_gpr[rB(ctx->opcode)]);
5328 if (unlikely(Rc(ctx->opcode) != 0))
5329 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5332 /* divso - divso. */
5333 static void gen_divso(DisasContext *ctx)
5335 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
5336 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5337 if (unlikely(Rc(ctx->opcode) != 0))
5338 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5342 static void gen_doz(DisasContext *ctx)
5344 TCGLabel *l1 = gen_new_label();
5345 TCGLabel *l2 = gen_new_label();
5346 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
5347 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5350 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5352 if (unlikely(Rc(ctx->opcode) != 0))
5353 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5357 static void gen_dozo(DisasContext *ctx)
5359 TCGLabel *l1 = gen_new_label();
5360 TCGLabel *l2 = gen_new_label();
5361 TCGv t0 = tcg_temp_new();
5362 TCGv t1 = tcg_temp_new();
5363 TCGv t2 = tcg_temp_new();
5364 /* Start with XER OV disabled, the most likely case */
5365 tcg_gen_movi_tl(cpu_ov, 0);
5366 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
5367 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5368 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5369 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
5370 tcg_gen_andc_tl(t1, t1, t2);
5371 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
5372 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5373 tcg_gen_movi_tl(cpu_ov, 1);
5374 tcg_gen_movi_tl(cpu_so, 1);
5377 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5382 if (unlikely(Rc(ctx->opcode) != 0))
5383 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5387 static void gen_dozi(DisasContext *ctx)
5389 target_long simm = SIMM(ctx->opcode);
5390 TCGLabel *l1 = gen_new_label();
5391 TCGLabel *l2 = gen_new_label();
5392 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5393 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5396 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5398 if (unlikely(Rc(ctx->opcode) != 0))
5399 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5402 /* lscbx - lscbx. */
5403 static void gen_lscbx(DisasContext *ctx)
5405 TCGv t0 = tcg_temp_new();
5406 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5407 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5408 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
5410 gen_addr_reg_index(ctx, t0);
5411 /* NIP cannot be restored if the memory exception comes from an helper */
5412 gen_update_nip(ctx, ctx->nip - 4);
5413 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
5414 tcg_temp_free_i32(t1);
5415 tcg_temp_free_i32(t2);
5416 tcg_temp_free_i32(t3);
5417 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
5418 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
5419 if (unlikely(Rc(ctx->opcode) != 0))
5420 gen_set_Rc0(ctx, t0);
5424 /* maskg - maskg. */
5425 static void gen_maskg(DisasContext *ctx)
5427 TCGLabel *l1 = gen_new_label();
5428 TCGv t0 = tcg_temp_new();
5429 TCGv t1 = tcg_temp_new();
5430 TCGv t2 = tcg_temp_new();
5431 TCGv t3 = tcg_temp_new();
5432 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5433 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5434 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5435 tcg_gen_addi_tl(t2, t0, 1);
5436 tcg_gen_shr_tl(t2, t3, t2);
5437 tcg_gen_shr_tl(t3, t3, t1);
5438 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5439 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5440 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5446 if (unlikely(Rc(ctx->opcode) != 0))
5447 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5450 /* maskir - maskir. */
5451 static void gen_maskir(DisasContext *ctx)
5453 TCGv t0 = tcg_temp_new();
5454 TCGv t1 = tcg_temp_new();
5455 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5456 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5457 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5460 if (unlikely(Rc(ctx->opcode) != 0))
5461 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5465 static void gen_mul(DisasContext *ctx)
5467 TCGv_i64 t0 = tcg_temp_new_i64();
5468 TCGv_i64 t1 = tcg_temp_new_i64();
5469 TCGv t2 = tcg_temp_new();
5470 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5471 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5472 tcg_gen_mul_i64(t0, t0, t1);
5473 tcg_gen_trunc_i64_tl(t2, t0);
5474 gen_store_spr(SPR_MQ, t2);
5475 tcg_gen_shri_i64(t1, t0, 32);
5476 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5477 tcg_temp_free_i64(t0);
5478 tcg_temp_free_i64(t1);
5480 if (unlikely(Rc(ctx->opcode) != 0))
5481 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5485 static void gen_mulo(DisasContext *ctx)
5487 TCGLabel *l1 = gen_new_label();
5488 TCGv_i64 t0 = tcg_temp_new_i64();
5489 TCGv_i64 t1 = tcg_temp_new_i64();
5490 TCGv t2 = tcg_temp_new();
5491 /* Start with XER OV disabled, the most likely case */
5492 tcg_gen_movi_tl(cpu_ov, 0);
5493 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5494 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5495 tcg_gen_mul_i64(t0, t0, t1);
5496 tcg_gen_trunc_i64_tl(t2, t0);
5497 gen_store_spr(SPR_MQ, t2);
5498 tcg_gen_shri_i64(t1, t0, 32);
5499 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5500 tcg_gen_ext32s_i64(t1, t0);
5501 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
5502 tcg_gen_movi_tl(cpu_ov, 1);
5503 tcg_gen_movi_tl(cpu_so, 1);
5505 tcg_temp_free_i64(t0);
5506 tcg_temp_free_i64(t1);
5508 if (unlikely(Rc(ctx->opcode) != 0))
5509 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5513 static void gen_nabs(DisasContext *ctx)
5515 TCGLabel *l1 = gen_new_label();
5516 TCGLabel *l2 = gen_new_label();
5517 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5518 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5521 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5523 if (unlikely(Rc(ctx->opcode) != 0))
5524 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5527 /* nabso - nabso. */
5528 static void gen_nabso(DisasContext *ctx)
5530 TCGLabel *l1 = gen_new_label();
5531 TCGLabel *l2 = gen_new_label();
5532 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5533 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5536 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5538 /* nabs never overflows */
5539 tcg_gen_movi_tl(cpu_ov, 0);
5540 if (unlikely(Rc(ctx->opcode) != 0))
5541 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5545 static void gen_rlmi(DisasContext *ctx)
5547 uint32_t mb = MB(ctx->opcode);
5548 uint32_t me = ME(ctx->opcode);
5549 TCGv t0 = tcg_temp_new();
5550 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5551 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5552 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5553 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5554 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5556 if (unlikely(Rc(ctx->opcode) != 0))
5557 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5561 static void gen_rrib(DisasContext *ctx)
5563 TCGv t0 = tcg_temp_new();
5564 TCGv t1 = tcg_temp_new();
5565 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5566 tcg_gen_movi_tl(t1, 0x80000000);
5567 tcg_gen_shr_tl(t1, t1, t0);
5568 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5569 tcg_gen_and_tl(t0, t0, t1);
5570 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5571 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5574 if (unlikely(Rc(ctx->opcode) != 0))
5575 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5579 static void gen_sle(DisasContext *ctx)
5581 TCGv t0 = tcg_temp_new();
5582 TCGv t1 = tcg_temp_new();
5583 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5584 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5585 tcg_gen_subfi_tl(t1, 32, t1);
5586 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5587 tcg_gen_or_tl(t1, t0, t1);
5588 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5589 gen_store_spr(SPR_MQ, t1);
5592 if (unlikely(Rc(ctx->opcode) != 0))
5593 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5597 static void gen_sleq(DisasContext *ctx)
5599 TCGv t0 = tcg_temp_new();
5600 TCGv t1 = tcg_temp_new();
5601 TCGv t2 = tcg_temp_new();
5602 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5603 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5604 tcg_gen_shl_tl(t2, t2, t0);
5605 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5606 gen_load_spr(t1, SPR_MQ);
5607 gen_store_spr(SPR_MQ, t0);
5608 tcg_gen_and_tl(t0, t0, t2);
5609 tcg_gen_andc_tl(t1, t1, t2);
5610 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5614 if (unlikely(Rc(ctx->opcode) != 0))
5615 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5619 static void gen_sliq(DisasContext *ctx)
5621 int sh = SH(ctx->opcode);
5622 TCGv t0 = tcg_temp_new();
5623 TCGv t1 = tcg_temp_new();
5624 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5625 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5626 tcg_gen_or_tl(t1, t0, t1);
5627 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5628 gen_store_spr(SPR_MQ, t1);
5631 if (unlikely(Rc(ctx->opcode) != 0))
5632 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5635 /* slliq - slliq. */
5636 static void gen_slliq(DisasContext *ctx)
5638 int sh = SH(ctx->opcode);
5639 TCGv t0 = tcg_temp_new();
5640 TCGv t1 = tcg_temp_new();
5641 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5642 gen_load_spr(t1, SPR_MQ);
5643 gen_store_spr(SPR_MQ, t0);
5644 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5645 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5646 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5649 if (unlikely(Rc(ctx->opcode) != 0))
5650 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5654 static void gen_sllq(DisasContext *ctx)
5656 TCGLabel *l1 = gen_new_label();
5657 TCGLabel *l2 = gen_new_label();
5658 TCGv t0 = tcg_temp_local_new();
5659 TCGv t1 = tcg_temp_local_new();
5660 TCGv t2 = tcg_temp_local_new();
5661 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5662 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5663 tcg_gen_shl_tl(t1, t1, t2);
5664 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5665 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5666 gen_load_spr(t0, SPR_MQ);
5667 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5670 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5671 gen_load_spr(t2, SPR_MQ);
5672 tcg_gen_andc_tl(t1, t2, t1);
5673 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5678 if (unlikely(Rc(ctx->opcode) != 0))
5679 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5683 static void gen_slq(DisasContext *ctx)
5685 TCGLabel *l1 = gen_new_label();
5686 TCGv t0 = tcg_temp_new();
5687 TCGv t1 = tcg_temp_new();
5688 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5689 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5690 tcg_gen_subfi_tl(t1, 32, t1);
5691 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5692 tcg_gen_or_tl(t1, t0, t1);
5693 gen_store_spr(SPR_MQ, t1);
5694 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5695 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5696 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5697 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5701 if (unlikely(Rc(ctx->opcode) != 0))
5702 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5705 /* sraiq - sraiq. */
5706 static void gen_sraiq(DisasContext *ctx)
5708 int sh = SH(ctx->opcode);
5709 TCGLabel *l1 = gen_new_label();
5710 TCGv t0 = tcg_temp_new();
5711 TCGv t1 = tcg_temp_new();
5712 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5713 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5714 tcg_gen_or_tl(t0, t0, t1);
5715 gen_store_spr(SPR_MQ, t0);
5716 tcg_gen_movi_tl(cpu_ca, 0);
5717 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5718 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
5719 tcg_gen_movi_tl(cpu_ca, 1);
5721 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5724 if (unlikely(Rc(ctx->opcode) != 0))
5725 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5729 static void gen_sraq(DisasContext *ctx)
5731 TCGLabel *l1 = gen_new_label();
5732 TCGLabel *l2 = gen_new_label();
5733 TCGv t0 = tcg_temp_new();
5734 TCGv t1 = tcg_temp_local_new();
5735 TCGv t2 = tcg_temp_local_new();
5736 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5737 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5738 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5739 tcg_gen_subfi_tl(t2, 32, t2);
5740 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5741 tcg_gen_or_tl(t0, t0, t2);
5742 gen_store_spr(SPR_MQ, t0);
5743 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5744 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5745 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5746 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5749 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
5750 tcg_gen_movi_tl(cpu_ca, 0);
5751 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5752 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
5753 tcg_gen_movi_tl(cpu_ca, 1);
5757 if (unlikely(Rc(ctx->opcode) != 0))
5758 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5762 static void gen_sre(DisasContext *ctx)
5764 TCGv t0 = tcg_temp_new();
5765 TCGv t1 = tcg_temp_new();
5766 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5767 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5768 tcg_gen_subfi_tl(t1, 32, t1);
5769 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5770 tcg_gen_or_tl(t1, t0, t1);
5771 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5772 gen_store_spr(SPR_MQ, t1);
5775 if (unlikely(Rc(ctx->opcode) != 0))
5776 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5780 static void gen_srea(DisasContext *ctx)
5782 TCGv t0 = tcg_temp_new();
5783 TCGv t1 = tcg_temp_new();
5784 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5785 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5786 gen_store_spr(SPR_MQ, t0);
5787 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5790 if (unlikely(Rc(ctx->opcode) != 0))
5791 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5795 static void gen_sreq(DisasContext *ctx)
5797 TCGv t0 = tcg_temp_new();
5798 TCGv t1 = tcg_temp_new();
5799 TCGv t2 = tcg_temp_new();
5800 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5801 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5802 tcg_gen_shr_tl(t1, t1, t0);
5803 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5804 gen_load_spr(t2, SPR_MQ);
5805 gen_store_spr(SPR_MQ, t0);
5806 tcg_gen_and_tl(t0, t0, t1);
5807 tcg_gen_andc_tl(t2, t2, t1);
5808 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5812 if (unlikely(Rc(ctx->opcode) != 0))
5813 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5817 static void gen_sriq(DisasContext *ctx)
5819 int sh = SH(ctx->opcode);
5820 TCGv t0 = tcg_temp_new();
5821 TCGv t1 = tcg_temp_new();
5822 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5823 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5824 tcg_gen_or_tl(t1, t0, t1);
5825 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5826 gen_store_spr(SPR_MQ, t1);
5829 if (unlikely(Rc(ctx->opcode) != 0))
5830 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5834 static void gen_srliq(DisasContext *ctx)
5836 int sh = SH(ctx->opcode);
5837 TCGv t0 = tcg_temp_new();
5838 TCGv t1 = tcg_temp_new();
5839 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5840 gen_load_spr(t1, SPR_MQ);
5841 gen_store_spr(SPR_MQ, t0);
5842 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5843 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5844 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5847 if (unlikely(Rc(ctx->opcode) != 0))
5848 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5852 static void gen_srlq(DisasContext *ctx)
5854 TCGLabel *l1 = gen_new_label();
5855 TCGLabel *l2 = gen_new_label();
5856 TCGv t0 = tcg_temp_local_new();
5857 TCGv t1 = tcg_temp_local_new();
5858 TCGv t2 = tcg_temp_local_new();
5859 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5860 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5861 tcg_gen_shr_tl(t2, t1, t2);
5862 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5863 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5864 gen_load_spr(t0, SPR_MQ);
5865 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5868 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5869 tcg_gen_and_tl(t0, t0, t2);
5870 gen_load_spr(t1, SPR_MQ);
5871 tcg_gen_andc_tl(t1, t1, t2);
5872 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5877 if (unlikely(Rc(ctx->opcode) != 0))
5878 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5882 static void gen_srq(DisasContext *ctx)
5884 TCGLabel *l1 = gen_new_label();
5885 TCGv t0 = tcg_temp_new();
5886 TCGv t1 = tcg_temp_new();
5887 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5888 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5889 tcg_gen_subfi_tl(t1, 32, t1);
5890 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5891 tcg_gen_or_tl(t1, t0, t1);
5892 gen_store_spr(SPR_MQ, t1);
5893 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5894 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5895 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5896 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5900 if (unlikely(Rc(ctx->opcode) != 0))
5901 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5904 /* PowerPC 602 specific instructions */
5907 static void gen_dsa(DisasContext *ctx)
5910 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5914 static void gen_esa(DisasContext *ctx)
5917 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5921 static void gen_mfrom(DisasContext *ctx)
5923 #if defined(CONFIG_USER_ONLY)
5927 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5928 #endif /* defined(CONFIG_USER_ONLY) */
5931 /* 602 - 603 - G2 TLB management */
5934 static void gen_tlbld_6xx(DisasContext *ctx)
5936 #if defined(CONFIG_USER_ONLY)
5940 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5941 #endif /* defined(CONFIG_USER_ONLY) */
5945 static void gen_tlbli_6xx(DisasContext *ctx)
5947 #if defined(CONFIG_USER_ONLY)
5951 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5952 #endif /* defined(CONFIG_USER_ONLY) */
5955 /* 74xx TLB management */
5958 static void gen_tlbld_74xx(DisasContext *ctx)
5960 #if defined(CONFIG_USER_ONLY)
5964 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5965 #endif /* defined(CONFIG_USER_ONLY) */
5969 static void gen_tlbli_74xx(DisasContext *ctx)
5971 #if defined(CONFIG_USER_ONLY)
5975 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5976 #endif /* defined(CONFIG_USER_ONLY) */
5979 /* POWER instructions not in PowerPC 601 */
5982 static void gen_clf(DisasContext *ctx)
5984 /* Cache line flush: implemented as no-op */
5988 static void gen_cli(DisasContext *ctx)
5990 #if defined(CONFIG_USER_ONLY)
5993 /* Cache line invalidate: privileged and treated as no-op */
5995 #endif /* defined(CONFIG_USER_ONLY) */
5999 static void gen_dclst(DisasContext *ctx)
6001 /* Data cache line store: treated as no-op */
6004 static void gen_mfsri(DisasContext *ctx)
6006 #if defined(CONFIG_USER_ONLY)
6009 int ra = rA(ctx->opcode);
6010 int rd = rD(ctx->opcode);
6014 t0 = tcg_temp_new();
6015 gen_addr_reg_index(ctx, t0);
6016 tcg_gen_shri_tl(t0, t0, 28);
6017 tcg_gen_andi_tl(t0, t0, 0xF);
6018 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
6020 if (ra != 0 && ra != rd)
6021 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
6022 #endif /* defined(CONFIG_USER_ONLY) */
6025 static void gen_rac(DisasContext *ctx)
6027 #if defined(CONFIG_USER_ONLY)
6033 t0 = tcg_temp_new();
6034 gen_addr_reg_index(ctx, t0);
6035 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6037 #endif /* defined(CONFIG_USER_ONLY) */
6040 static void gen_rfsvc(DisasContext *ctx)
6042 #if defined(CONFIG_USER_ONLY)
6047 gen_helper_rfsvc(cpu_env);
6048 gen_sync_exception(ctx);
6049 #endif /* defined(CONFIG_USER_ONLY) */
6052 /* svc is not implemented for now */
6054 /* POWER2 specific instructions */
6055 /* Quad manipulation (load/store two floats at a time) */
6058 static void gen_lfq(DisasContext *ctx)
6060 int rd = rD(ctx->opcode);
6062 gen_set_access_type(ctx, ACCESS_FLOAT);
6063 t0 = tcg_temp_new();
6064 gen_addr_imm_index(ctx, t0, 0);
6065 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
6066 gen_addr_add(ctx, t0, t0, 8);
6067 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
6072 static void gen_lfqu(DisasContext *ctx)
6074 int ra = rA(ctx->opcode);
6075 int rd = rD(ctx->opcode);
6077 gen_set_access_type(ctx, ACCESS_FLOAT);
6078 t0 = tcg_temp_new();
6079 t1 = tcg_temp_new();
6080 gen_addr_imm_index(ctx, t0, 0);
6081 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
6082 gen_addr_add(ctx, t1, t0, 8);
6083 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
6085 tcg_gen_mov_tl(cpu_gpr[ra], t0);
6091 static void gen_lfqux(DisasContext *ctx)
6093 int ra = rA(ctx->opcode);
6094 int rd = rD(ctx->opcode);
6095 gen_set_access_type(ctx, ACCESS_FLOAT);
6097 t0 = tcg_temp_new();
6098 gen_addr_reg_index(ctx, t0);
6099 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
6100 t1 = tcg_temp_new();
6101 gen_addr_add(ctx, t1, t0, 8);
6102 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
6105 tcg_gen_mov_tl(cpu_gpr[ra], t0);
6110 static void gen_lfqx(DisasContext *ctx)
6112 int rd = rD(ctx->opcode);
6114 gen_set_access_type(ctx, ACCESS_FLOAT);
6115 t0 = tcg_temp_new();
6116 gen_addr_reg_index(ctx, t0);
6117 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
6118 gen_addr_add(ctx, t0, t0, 8);
6119 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
6124 static void gen_stfq(DisasContext *ctx)
6126 int rd = rD(ctx->opcode);
6128 gen_set_access_type(ctx, ACCESS_FLOAT);
6129 t0 = tcg_temp_new();
6130 gen_addr_imm_index(ctx, t0, 0);
6131 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
6132 gen_addr_add(ctx, t0, t0, 8);
6133 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
6138 static void gen_stfqu(DisasContext *ctx)
6140 int ra = rA(ctx->opcode);
6141 int rd = rD(ctx->opcode);
6143 gen_set_access_type(ctx, ACCESS_FLOAT);
6144 t0 = tcg_temp_new();
6145 gen_addr_imm_index(ctx, t0, 0);
6146 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
6147 t1 = tcg_temp_new();
6148 gen_addr_add(ctx, t1, t0, 8);
6149 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
6152 tcg_gen_mov_tl(cpu_gpr[ra], t0);
6157 static void gen_stfqux(DisasContext *ctx)
6159 int ra = rA(ctx->opcode);
6160 int rd = rD(ctx->opcode);
6162 gen_set_access_type(ctx, ACCESS_FLOAT);
6163 t0 = tcg_temp_new();
6164 gen_addr_reg_index(ctx, t0);
6165 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
6166 t1 = tcg_temp_new();
6167 gen_addr_add(ctx, t1, t0, 8);
6168 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
6171 tcg_gen_mov_tl(cpu_gpr[ra], t0);
6176 static void gen_stfqx(DisasContext *ctx)
6178 int rd = rD(ctx->opcode);
6180 gen_set_access_type(ctx, ACCESS_FLOAT);
6181 t0 = tcg_temp_new();
6182 gen_addr_reg_index(ctx, t0);
6183 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
6184 gen_addr_add(ctx, t0, t0, 8);
6185 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
6189 /* BookE specific instructions */
6191 /* XXX: not implemented on 440 ? */
6192 static void gen_mfapidi(DisasContext *ctx)
6195 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6198 /* XXX: not implemented on 440 ? */
6199 static void gen_tlbiva(DisasContext *ctx)
6201 #if defined(CONFIG_USER_ONLY)
6207 t0 = tcg_temp_new();
6208 gen_addr_reg_index(ctx, t0);
6209 gen_helper_tlbiva(cpu_env, cpu_gpr[rB(ctx->opcode)]);
6211 #endif /* defined(CONFIG_USER_ONLY) */
6214 /* All 405 MAC instructions are translated here */
6215 static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
6216 int ra, int rb, int rt, int Rc)
6220 t0 = tcg_temp_local_new();
6221 t1 = tcg_temp_local_new();
6223 switch (opc3 & 0x0D) {
6225 /* macchw - macchw. - macchwo - macchwo. */
6226 /* macchws - macchws. - macchwso - macchwso. */
6227 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
6228 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
6229 /* mulchw - mulchw. */
6230 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
6231 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
6232 tcg_gen_ext16s_tl(t1, t1);
6235 /* macchwu - macchwu. - macchwuo - macchwuo. */
6236 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
6237 /* mulchwu - mulchwu. */
6238 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
6239 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
6240 tcg_gen_ext16u_tl(t1, t1);
6243 /* machhw - machhw. - machhwo - machhwo. */
6244 /* machhws - machhws. - machhwso - machhwso. */
6245 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
6246 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
6247 /* mulhhw - mulhhw. */
6248 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
6249 tcg_gen_ext16s_tl(t0, t0);
6250 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
6251 tcg_gen_ext16s_tl(t1, t1);
6254 /* machhwu - machhwu. - machhwuo - machhwuo. */
6255 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
6256 /* mulhhwu - mulhhwu. */
6257 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
6258 tcg_gen_ext16u_tl(t0, t0);
6259 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
6260 tcg_gen_ext16u_tl(t1, t1);
6263 /* maclhw - maclhw. - maclhwo - maclhwo. */
6264 /* maclhws - maclhws. - maclhwso - maclhwso. */
6265 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
6266 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
6267 /* mullhw - mullhw. */
6268 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
6269 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
6272 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
6273 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
6274 /* mullhwu - mullhwu. */
6275 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
6276 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
6280 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
6281 tcg_gen_mul_tl(t1, t0, t1);
6283 /* nmultiply-and-accumulate (0x0E) */
6284 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
6286 /* multiply-and-accumulate (0x0C) */
6287 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
6291 /* Check overflow and/or saturate */
6292 TCGLabel *l1 = gen_new_label();
6295 /* Start with XER OV disabled, the most likely case */
6296 tcg_gen_movi_tl(cpu_ov, 0);
6300 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
6301 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
6302 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
6303 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
6306 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
6307 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
6311 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
6314 tcg_gen_movi_tl(t0, UINT32_MAX);
6318 /* Check overflow */
6319 tcg_gen_movi_tl(cpu_ov, 1);
6320 tcg_gen_movi_tl(cpu_so, 1);
6323 tcg_gen_mov_tl(cpu_gpr[rt], t0);
6326 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
6330 if (unlikely(Rc) != 0) {
6332 gen_set_Rc0(ctx, cpu_gpr[rt]);
6336 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6337 static void glue(gen_, name)(DisasContext *ctx) \
6339 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6340 rD(ctx->opcode), Rc(ctx->opcode)); \
6343 /* macchw - macchw. */
6344 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
6345 /* macchwo - macchwo. */
6346 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
6347 /* macchws - macchws. */
6348 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
6349 /* macchwso - macchwso. */
6350 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
6351 /* macchwsu - macchwsu. */
6352 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
6353 /* macchwsuo - macchwsuo. */
6354 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
6355 /* macchwu - macchwu. */
6356 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
6357 /* macchwuo - macchwuo. */
6358 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
6359 /* machhw - machhw. */
6360 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
6361 /* machhwo - machhwo. */
6362 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
6363 /* machhws - machhws. */
6364 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
6365 /* machhwso - machhwso. */
6366 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
6367 /* machhwsu - machhwsu. */
6368 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
6369 /* machhwsuo - machhwsuo. */
6370 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
6371 /* machhwu - machhwu. */
6372 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
6373 /* machhwuo - machhwuo. */
6374 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
6375 /* maclhw - maclhw. */
6376 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
6377 /* maclhwo - maclhwo. */
6378 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
6379 /* maclhws - maclhws. */
6380 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
6381 /* maclhwso - maclhwso. */
6382 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
6383 /* maclhwu - maclhwu. */
6384 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
6385 /* maclhwuo - maclhwuo. */
6386 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
6387 /* maclhwsu - maclhwsu. */
6388 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
6389 /* maclhwsuo - maclhwsuo. */
6390 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
6391 /* nmacchw - nmacchw. */
6392 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
6393 /* nmacchwo - nmacchwo. */
6394 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
6395 /* nmacchws - nmacchws. */
6396 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
6397 /* nmacchwso - nmacchwso. */
6398 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
6399 /* nmachhw - nmachhw. */
6400 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
6401 /* nmachhwo - nmachhwo. */
6402 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
6403 /* nmachhws - nmachhws. */
6404 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
6405 /* nmachhwso - nmachhwso. */
6406 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
6407 /* nmaclhw - nmaclhw. */
6408 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
6409 /* nmaclhwo - nmaclhwo. */
6410 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
6411 /* nmaclhws - nmaclhws. */
6412 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
6413 /* nmaclhwso - nmaclhwso. */
6414 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
6416 /* mulchw - mulchw. */
6417 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
6418 /* mulchwu - mulchwu. */
6419 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
6420 /* mulhhw - mulhhw. */
6421 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
6422 /* mulhhwu - mulhhwu. */
6423 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
6424 /* mullhw - mullhw. */
6425 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
6426 /* mullhwu - mullhwu. */
6427 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
6430 static void gen_mfdcr(DisasContext *ctx)
6432 #if defined(CONFIG_USER_ONLY)
6438 /* NIP cannot be restored if the memory exception comes from an helper */
6439 gen_update_nip(ctx, ctx->nip - 4);
6440 dcrn = tcg_const_tl(SPR(ctx->opcode));
6441 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
6442 tcg_temp_free(dcrn);
6443 #endif /* defined(CONFIG_USER_ONLY) */
6447 static void gen_mtdcr(DisasContext *ctx)
6449 #if defined(CONFIG_USER_ONLY)
6455 /* NIP cannot be restored if the memory exception comes from an helper */
6456 gen_update_nip(ctx, ctx->nip - 4);
6457 dcrn = tcg_const_tl(SPR(ctx->opcode));
6458 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
6459 tcg_temp_free(dcrn);
6460 #endif /* defined(CONFIG_USER_ONLY) */
6464 /* XXX: not implemented on 440 ? */
6465 static void gen_mfdcrx(DisasContext *ctx)
6467 #if defined(CONFIG_USER_ONLY)
6471 /* NIP cannot be restored if the memory exception comes from an helper */
6472 gen_update_nip(ctx, ctx->nip - 4);
6473 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6474 cpu_gpr[rA(ctx->opcode)]);
6475 /* Note: Rc update flag set leads to undefined state of Rc0 */
6476 #endif /* defined(CONFIG_USER_ONLY) */
6480 /* XXX: not implemented on 440 ? */
6481 static void gen_mtdcrx(DisasContext *ctx)
6483 #if defined(CONFIG_USER_ONLY)
6487 /* NIP cannot be restored if the memory exception comes from an helper */
6488 gen_update_nip(ctx, ctx->nip - 4);
6489 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6490 cpu_gpr[rS(ctx->opcode)]);
6491 /* Note: Rc update flag set leads to undefined state of Rc0 */
6492 #endif /* defined(CONFIG_USER_ONLY) */
6495 /* mfdcrux (PPC 460) : user-mode access to DCR */
6496 static void gen_mfdcrux(DisasContext *ctx)
6498 /* NIP cannot be restored if the memory exception comes from an helper */
6499 gen_update_nip(ctx, ctx->nip - 4);
6500 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6501 cpu_gpr[rA(ctx->opcode)]);
6502 /* Note: Rc update flag set leads to undefined state of Rc0 */
6505 /* mtdcrux (PPC 460) : user-mode access to DCR */
6506 static void gen_mtdcrux(DisasContext *ctx)
6508 /* NIP cannot be restored if the memory exception comes from an helper */
6509 gen_update_nip(ctx, ctx->nip - 4);
6510 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6511 cpu_gpr[rS(ctx->opcode)]);
6512 /* Note: Rc update flag set leads to undefined state of Rc0 */
6516 static void gen_dccci(DisasContext *ctx)
6519 /* interpreted as no-op */
6523 static void gen_dcread(DisasContext *ctx)
6525 #if defined(CONFIG_USER_ONLY)
6531 gen_set_access_type(ctx, ACCESS_CACHE);
6532 EA = tcg_temp_new();
6533 gen_addr_reg_index(ctx, EA);
6534 val = tcg_temp_new();
6535 gen_qemu_ld32u(ctx, val, EA);
6537 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6539 #endif /* defined(CONFIG_USER_ONLY) */
6543 static void gen_icbt_40x(DisasContext *ctx)
6545 /* interpreted as no-op */
6546 /* XXX: specification say this is treated as a load by the MMU
6547 * but does not generate any exception
6552 static void gen_iccci(DisasContext *ctx)
6555 /* interpreted as no-op */
6559 static void gen_icread(DisasContext *ctx)
6562 /* interpreted as no-op */
6565 /* rfci (supervisor only) */
6566 static void gen_rfci_40x(DisasContext *ctx)
6568 #if defined(CONFIG_USER_ONLY)
6572 /* Restore CPU state */
6573 gen_helper_40x_rfci(cpu_env);
6574 gen_sync_exception(ctx);
6575 #endif /* defined(CONFIG_USER_ONLY) */
6578 static void gen_rfci(DisasContext *ctx)
6580 #if defined(CONFIG_USER_ONLY)
6584 /* Restore CPU state */
6585 gen_helper_rfci(cpu_env);
6586 gen_sync_exception(ctx);
6587 #endif /* defined(CONFIG_USER_ONLY) */
6590 /* BookE specific */
6592 /* XXX: not implemented on 440 ? */
6593 static void gen_rfdi(DisasContext *ctx)
6595 #if defined(CONFIG_USER_ONLY)
6599 /* Restore CPU state */
6600 gen_helper_rfdi(cpu_env);
6601 gen_sync_exception(ctx);
6602 #endif /* defined(CONFIG_USER_ONLY) */
6605 /* XXX: not implemented on 440 ? */
6606 static void gen_rfmci(DisasContext *ctx)
6608 #if defined(CONFIG_USER_ONLY)
6612 /* Restore CPU state */
6613 gen_helper_rfmci(cpu_env);
6614 gen_sync_exception(ctx);
6615 #endif /* defined(CONFIG_USER_ONLY) */
6618 /* TLB management - PowerPC 405 implementation */
6621 static void gen_tlbre_40x(DisasContext *ctx)
6623 #if defined(CONFIG_USER_ONLY)
6627 switch (rB(ctx->opcode)) {
6629 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6630 cpu_gpr[rA(ctx->opcode)]);
6633 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6634 cpu_gpr[rA(ctx->opcode)]);
6637 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6640 #endif /* defined(CONFIG_USER_ONLY) */
6643 /* tlbsx - tlbsx. */
6644 static void gen_tlbsx_40x(DisasContext *ctx)
6646 #if defined(CONFIG_USER_ONLY)
6652 t0 = tcg_temp_new();
6653 gen_addr_reg_index(ctx, t0);
6654 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6656 if (Rc(ctx->opcode)) {
6657 TCGLabel *l1 = gen_new_label();
6658 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
6659 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6660 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6663 #endif /* defined(CONFIG_USER_ONLY) */
6667 static void gen_tlbwe_40x(DisasContext *ctx)
6669 #if defined(CONFIG_USER_ONLY)
6674 switch (rB(ctx->opcode)) {
6676 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6677 cpu_gpr[rS(ctx->opcode)]);
6680 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6681 cpu_gpr[rS(ctx->opcode)]);
6684 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6687 #endif /* defined(CONFIG_USER_ONLY) */
6690 /* TLB management - PowerPC 440 implementation */
6693 static void gen_tlbre_440(DisasContext *ctx)
6695 #if defined(CONFIG_USER_ONLY)
6700 switch (rB(ctx->opcode)) {
6705 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
6706 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6707 t0, cpu_gpr[rA(ctx->opcode)]);
6708 tcg_temp_free_i32(t0);
6712 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6715 #endif /* defined(CONFIG_USER_ONLY) */
6718 /* tlbsx - tlbsx. */
6719 static void gen_tlbsx_440(DisasContext *ctx)
6721 #if defined(CONFIG_USER_ONLY)
6727 t0 = tcg_temp_new();
6728 gen_addr_reg_index(ctx, t0);
6729 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6731 if (Rc(ctx->opcode)) {
6732 TCGLabel *l1 = gen_new_label();
6733 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
6734 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6735 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6738 #endif /* defined(CONFIG_USER_ONLY) */
6742 static void gen_tlbwe_440(DisasContext *ctx)
6744 #if defined(CONFIG_USER_ONLY)
6748 switch (rB(ctx->opcode)) {
6753 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
6754 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6755 cpu_gpr[rS(ctx->opcode)]);
6756 tcg_temp_free_i32(t0);
6760 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6763 #endif /* defined(CONFIG_USER_ONLY) */
6766 /* TLB management - PowerPC BookE 2.06 implementation */
6769 static void gen_tlbre_booke206(DisasContext *ctx)
6771 #if defined(CONFIG_USER_ONLY)
6775 gen_helper_booke206_tlbre(cpu_env);
6776 #endif /* defined(CONFIG_USER_ONLY) */
6779 /* tlbsx - tlbsx. */
6780 static void gen_tlbsx_booke206(DisasContext *ctx)
6782 #if defined(CONFIG_USER_ONLY)
6788 if (rA(ctx->opcode)) {
6789 t0 = tcg_temp_new();
6790 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6792 t0 = tcg_const_tl(0);
6795 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
6796 gen_helper_booke206_tlbsx(cpu_env, t0);
6798 #endif /* defined(CONFIG_USER_ONLY) */
6802 static void gen_tlbwe_booke206(DisasContext *ctx)
6804 #if defined(CONFIG_USER_ONLY)
6808 gen_update_nip(ctx, ctx->nip - 4);
6809 gen_helper_booke206_tlbwe(cpu_env);
6810 #endif /* defined(CONFIG_USER_ONLY) */
6813 static void gen_tlbivax_booke206(DisasContext *ctx)
6815 #if defined(CONFIG_USER_ONLY)
6821 t0 = tcg_temp_new();
6822 gen_addr_reg_index(ctx, t0);
6823 gen_helper_booke206_tlbivax(cpu_env, t0);
6825 #endif /* defined(CONFIG_USER_ONLY) */
6828 static void gen_tlbilx_booke206(DisasContext *ctx)
6830 #if defined(CONFIG_USER_ONLY)
6836 t0 = tcg_temp_new();
6837 gen_addr_reg_index(ctx, t0);
6839 switch((ctx->opcode >> 21) & 0x3) {
6841 gen_helper_booke206_tlbilx0(cpu_env, t0);
6844 gen_helper_booke206_tlbilx1(cpu_env, t0);
6847 gen_helper_booke206_tlbilx3(cpu_env, t0);
6850 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6855 #endif /* defined(CONFIG_USER_ONLY) */
6860 static void gen_wrtee(DisasContext *ctx)
6862 #if defined(CONFIG_USER_ONLY)
6868 t0 = tcg_temp_new();
6869 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6870 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6871 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6873 /* Stop translation to have a chance to raise an exception
6874 * if we just set msr_ee to 1
6876 gen_stop_exception(ctx);
6877 #endif /* defined(CONFIG_USER_ONLY) */
6881 static void gen_wrteei(DisasContext *ctx)
6883 #if defined(CONFIG_USER_ONLY)
6887 if (ctx->opcode & 0x00008000) {
6888 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6889 /* Stop translation to have a chance to raise an exception */
6890 gen_stop_exception(ctx);
6892 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6894 #endif /* defined(CONFIG_USER_ONLY) */
6897 /* PowerPC 440 specific instructions */
6900 static void gen_dlmzb(DisasContext *ctx)
6902 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
6903 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6904 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
6905 tcg_temp_free_i32(t0);
6908 /* mbar replaces eieio on 440 */
6909 static void gen_mbar(DisasContext *ctx)
6911 /* interpreted as no-op */
6914 /* msync replaces sync on 440 */
6915 static void gen_msync_4xx(DisasContext *ctx)
6917 /* interpreted as no-op */
6921 static void gen_icbt_440(DisasContext *ctx)
6923 /* interpreted as no-op */
6924 /* XXX: specification say this is treated as a load by the MMU
6925 * but does not generate any exception
6929 /* Embedded.Processor Control */
6931 static void gen_msgclr(DisasContext *ctx)
6933 #if defined(CONFIG_USER_ONLY)
6937 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
6938 #endif /* defined(CONFIG_USER_ONLY) */
6941 static void gen_msgsnd(DisasContext *ctx)
6943 #if defined(CONFIG_USER_ONLY)
6947 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6948 #endif /* defined(CONFIG_USER_ONLY) */
6951 /*** Altivec vector extension ***/
6952 /* Altivec registers moves */
6954 static inline TCGv_ptr gen_avr_ptr(int reg)
6956 TCGv_ptr r = tcg_temp_new_ptr();
6957 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6961 #define GEN_VR_LDX(name, opc2, opc3) \
6962 static void glue(gen_, name)(DisasContext *ctx) \
6965 if (unlikely(!ctx->altivec_enabled)) { \
6966 gen_exception(ctx, POWERPC_EXCP_VPU); \
6969 gen_set_access_type(ctx, ACCESS_INT); \
6970 EA = tcg_temp_new(); \
6971 gen_addr_reg_index(ctx, EA); \
6972 tcg_gen_andi_tl(EA, EA, ~0xf); \
6973 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
6974 64-bit byteswap already. */ \
6975 if (ctx->le_mode) { \
6976 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6977 tcg_gen_addi_tl(EA, EA, 8); \
6978 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6980 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6981 tcg_gen_addi_tl(EA, EA, 8); \
6982 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6984 tcg_temp_free(EA); \
6987 #define GEN_VR_STX(name, opc2, opc3) \
6988 static void gen_st##name(DisasContext *ctx) \
6991 if (unlikely(!ctx->altivec_enabled)) { \
6992 gen_exception(ctx, POWERPC_EXCP_VPU); \
6995 gen_set_access_type(ctx, ACCESS_INT); \
6996 EA = tcg_temp_new(); \
6997 gen_addr_reg_index(ctx, EA); \
6998 tcg_gen_andi_tl(EA, EA, ~0xf); \
6999 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
7000 64-bit byteswap already. */ \
7001 if (ctx->le_mode) { \
7002 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
7003 tcg_gen_addi_tl(EA, EA, 8); \
7004 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
7006 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
7007 tcg_gen_addi_tl(EA, EA, 8); \
7008 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
7010 tcg_temp_free(EA); \
7013 #define GEN_VR_LVE(name, opc2, opc3, size) \
7014 static void gen_lve##name(DisasContext *ctx) \
7018 if (unlikely(!ctx->altivec_enabled)) { \
7019 gen_exception(ctx, POWERPC_EXCP_VPU); \
7022 gen_set_access_type(ctx, ACCESS_INT); \
7023 EA = tcg_temp_new(); \
7024 gen_addr_reg_index(ctx, EA); \
7026 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
7028 rs = gen_avr_ptr(rS(ctx->opcode)); \
7029 gen_helper_lve##name(cpu_env, rs, EA); \
7030 tcg_temp_free(EA); \
7031 tcg_temp_free_ptr(rs); \
7034 #define GEN_VR_STVE(name, opc2, opc3, size) \
7035 static void gen_stve##name(DisasContext *ctx) \
7039 if (unlikely(!ctx->altivec_enabled)) { \
7040 gen_exception(ctx, POWERPC_EXCP_VPU); \
7043 gen_set_access_type(ctx, ACCESS_INT); \
7044 EA = tcg_temp_new(); \
7045 gen_addr_reg_index(ctx, EA); \
7047 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
7049 rs = gen_avr_ptr(rS(ctx->opcode)); \
7050 gen_helper_stve##name(cpu_env, rs, EA); \
7051 tcg_temp_free(EA); \
7052 tcg_temp_free_ptr(rs); \
7055 GEN_VR_LDX(lvx, 0x07, 0x03);
7056 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
7057 GEN_VR_LDX(lvxl, 0x07, 0x0B);
7059 GEN_VR_LVE(bx, 0x07, 0x00, 1);
7060 GEN_VR_LVE(hx, 0x07, 0x01, 2);
7061 GEN_VR_LVE(wx, 0x07, 0x02, 4);
7063 GEN_VR_STX(svx, 0x07, 0x07);
7064 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
7065 GEN_VR_STX(svxl, 0x07, 0x0F);
7067 GEN_VR_STVE(bx, 0x07, 0x04, 1);
7068 GEN_VR_STVE(hx, 0x07, 0x05, 2);
7069 GEN_VR_STVE(wx, 0x07, 0x06, 4);
7071 static void gen_lvsl(DisasContext *ctx)
7075 if (unlikely(!ctx->altivec_enabled)) {
7076 gen_exception(ctx, POWERPC_EXCP_VPU);
7079 EA = tcg_temp_new();
7080 gen_addr_reg_index(ctx, EA);
7081 rd = gen_avr_ptr(rD(ctx->opcode));
7082 gen_helper_lvsl(rd, EA);
7084 tcg_temp_free_ptr(rd);
7087 static void gen_lvsr(DisasContext *ctx)
7091 if (unlikely(!ctx->altivec_enabled)) {
7092 gen_exception(ctx, POWERPC_EXCP_VPU);
7095 EA = tcg_temp_new();
7096 gen_addr_reg_index(ctx, EA);
7097 rd = gen_avr_ptr(rD(ctx->opcode));
7098 gen_helper_lvsr(rd, EA);
7100 tcg_temp_free_ptr(rd);
7103 static void gen_mfvscr(DisasContext *ctx)
7106 if (unlikely(!ctx->altivec_enabled)) {
7107 gen_exception(ctx, POWERPC_EXCP_VPU);
7110 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
7111 t = tcg_temp_new_i32();
7112 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
7113 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
7114 tcg_temp_free_i32(t);
7117 static void gen_mtvscr(DisasContext *ctx)
7120 if (unlikely(!ctx->altivec_enabled)) {
7121 gen_exception(ctx, POWERPC_EXCP_VPU);
7124 p = gen_avr_ptr(rB(ctx->opcode));
7125 gen_helper_mtvscr(cpu_env, p);
7126 tcg_temp_free_ptr(p);
7129 /* Logical operations */
7130 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
7131 static void glue(gen_, name)(DisasContext *ctx) \
7133 if (unlikely(!ctx->altivec_enabled)) { \
7134 gen_exception(ctx, POWERPC_EXCP_VPU); \
7137 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
7138 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
7141 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
7142 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
7143 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
7144 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
7145 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
7146 GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
7147 GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
7148 GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
7150 #define GEN_VXFORM(name, opc2, opc3) \
7151 static void glue(gen_, name)(DisasContext *ctx) \
7153 TCGv_ptr ra, rb, rd; \
7154 if (unlikely(!ctx->altivec_enabled)) { \
7155 gen_exception(ctx, POWERPC_EXCP_VPU); \
7158 ra = gen_avr_ptr(rA(ctx->opcode)); \
7159 rb = gen_avr_ptr(rB(ctx->opcode)); \
7160 rd = gen_avr_ptr(rD(ctx->opcode)); \
7161 gen_helper_##name (rd, ra, rb); \
7162 tcg_temp_free_ptr(ra); \
7163 tcg_temp_free_ptr(rb); \
7164 tcg_temp_free_ptr(rd); \
7167 #define GEN_VXFORM_ENV(name, opc2, opc3) \
7168 static void glue(gen_, name)(DisasContext *ctx) \
7170 TCGv_ptr ra, rb, rd; \
7171 if (unlikely(!ctx->altivec_enabled)) { \
7172 gen_exception(ctx, POWERPC_EXCP_VPU); \
7175 ra = gen_avr_ptr(rA(ctx->opcode)); \
7176 rb = gen_avr_ptr(rB(ctx->opcode)); \
7177 rd = gen_avr_ptr(rD(ctx->opcode)); \
7178 gen_helper_##name(cpu_env, rd, ra, rb); \
7179 tcg_temp_free_ptr(ra); \
7180 tcg_temp_free_ptr(rb); \
7181 tcg_temp_free_ptr(rd); \
7184 #define GEN_VXFORM3(name, opc2, opc3) \
7185 static void glue(gen_, name)(DisasContext *ctx) \
7187 TCGv_ptr ra, rb, rc, rd; \
7188 if (unlikely(!ctx->altivec_enabled)) { \
7189 gen_exception(ctx, POWERPC_EXCP_VPU); \
7192 ra = gen_avr_ptr(rA(ctx->opcode)); \
7193 rb = gen_avr_ptr(rB(ctx->opcode)); \
7194 rc = gen_avr_ptr(rC(ctx->opcode)); \
7195 rd = gen_avr_ptr(rD(ctx->opcode)); \
7196 gen_helper_##name(rd, ra, rb, rc); \
7197 tcg_temp_free_ptr(ra); \
7198 tcg_temp_free_ptr(rb); \
7199 tcg_temp_free_ptr(rc); \
7200 tcg_temp_free_ptr(rd); \
7204 * Support for Altivec instruction pairs that use bit 31 (Rc) as
7205 * an opcode bit. In general, these pairs come from different
7206 * versions of the ISA, so we must also support a pair of flags for
7209 #define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7210 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7212 if ((Rc(ctx->opcode) == 0) && \
7213 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7215 } else if ((Rc(ctx->opcode) == 1) && \
7216 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7219 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7223 GEN_VXFORM(vaddubm, 0, 0);
7224 GEN_VXFORM(vadduhm, 0, 1);
7225 GEN_VXFORM(vadduwm, 0, 2);
7226 GEN_VXFORM(vaddudm, 0, 3);
7227 GEN_VXFORM(vsububm, 0, 16);
7228 GEN_VXFORM(vsubuhm, 0, 17);
7229 GEN_VXFORM(vsubuwm, 0, 18);
7230 GEN_VXFORM(vsubudm, 0, 19);
7231 GEN_VXFORM(vmaxub, 1, 0);
7232 GEN_VXFORM(vmaxuh, 1, 1);
7233 GEN_VXFORM(vmaxuw, 1, 2);
7234 GEN_VXFORM(vmaxud, 1, 3);
7235 GEN_VXFORM(vmaxsb, 1, 4);
7236 GEN_VXFORM(vmaxsh, 1, 5);
7237 GEN_VXFORM(vmaxsw, 1, 6);
7238 GEN_VXFORM(vmaxsd, 1, 7);
7239 GEN_VXFORM(vminub, 1, 8);
7240 GEN_VXFORM(vminuh, 1, 9);
7241 GEN_VXFORM(vminuw, 1, 10);
7242 GEN_VXFORM(vminud, 1, 11);
7243 GEN_VXFORM(vminsb, 1, 12);
7244 GEN_VXFORM(vminsh, 1, 13);
7245 GEN_VXFORM(vminsw, 1, 14);
7246 GEN_VXFORM(vminsd, 1, 15);
7247 GEN_VXFORM(vavgub, 1, 16);
7248 GEN_VXFORM(vavguh, 1, 17);
7249 GEN_VXFORM(vavguw, 1, 18);
7250 GEN_VXFORM(vavgsb, 1, 20);
7251 GEN_VXFORM(vavgsh, 1, 21);
7252 GEN_VXFORM(vavgsw, 1, 22);
7253 GEN_VXFORM(vmrghb, 6, 0);
7254 GEN_VXFORM(vmrghh, 6, 1);
7255 GEN_VXFORM(vmrghw, 6, 2);
7256 GEN_VXFORM(vmrglb, 6, 4);
7257 GEN_VXFORM(vmrglh, 6, 5);
7258 GEN_VXFORM(vmrglw, 6, 6);
7260 static void gen_vmrgew(DisasContext *ctx)
7264 if (unlikely(!ctx->altivec_enabled)) {
7265 gen_exception(ctx, POWERPC_EXCP_VPU);
7268 VT = rD(ctx->opcode);
7269 VA = rA(ctx->opcode);
7270 VB = rB(ctx->opcode);
7271 tmp = tcg_temp_new_i64();
7272 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
7273 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
7274 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
7275 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
7276 tcg_temp_free_i64(tmp);
7279 static void gen_vmrgow(DisasContext *ctx)
7282 if (unlikely(!ctx->altivec_enabled)) {
7283 gen_exception(ctx, POWERPC_EXCP_VPU);
7286 VT = rD(ctx->opcode);
7287 VA = rA(ctx->opcode);
7288 VB = rB(ctx->opcode);
7290 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7291 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7294 GEN_VXFORM(vmuloub, 4, 0);
7295 GEN_VXFORM(vmulouh, 4, 1);
7296 GEN_VXFORM(vmulouw, 4, 2);
7297 GEN_VXFORM(vmuluwm, 4, 2);
7298 GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7299 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
7300 GEN_VXFORM(vmulosb, 4, 4);
7301 GEN_VXFORM(vmulosh, 4, 5);
7302 GEN_VXFORM(vmulosw, 4, 6);
7303 GEN_VXFORM(vmuleub, 4, 8);
7304 GEN_VXFORM(vmuleuh, 4, 9);
7305 GEN_VXFORM(vmuleuw, 4, 10);
7306 GEN_VXFORM(vmulesb, 4, 12);
7307 GEN_VXFORM(vmulesh, 4, 13);
7308 GEN_VXFORM(vmulesw, 4, 14);
7309 GEN_VXFORM(vslb, 2, 4);
7310 GEN_VXFORM(vslh, 2, 5);
7311 GEN_VXFORM(vslw, 2, 6);
7312 GEN_VXFORM(vsld, 2, 23);
7313 GEN_VXFORM(vsrb, 2, 8);
7314 GEN_VXFORM(vsrh, 2, 9);
7315 GEN_VXFORM(vsrw, 2, 10);
7316 GEN_VXFORM(vsrd, 2, 27);
7317 GEN_VXFORM(vsrab, 2, 12);
7318 GEN_VXFORM(vsrah, 2, 13);
7319 GEN_VXFORM(vsraw, 2, 14);
7320 GEN_VXFORM(vsrad, 2, 15);
7321 GEN_VXFORM(vslo, 6, 16);
7322 GEN_VXFORM(vsro, 6, 17);
7323 GEN_VXFORM(vaddcuw, 0, 6);
7324 GEN_VXFORM(vsubcuw, 0, 22);
7325 GEN_VXFORM_ENV(vaddubs, 0, 8);
7326 GEN_VXFORM_ENV(vadduhs, 0, 9);
7327 GEN_VXFORM_ENV(vadduws, 0, 10);
7328 GEN_VXFORM_ENV(vaddsbs, 0, 12);
7329 GEN_VXFORM_ENV(vaddshs, 0, 13);
7330 GEN_VXFORM_ENV(vaddsws, 0, 14);
7331 GEN_VXFORM_ENV(vsububs, 0, 24);
7332 GEN_VXFORM_ENV(vsubuhs, 0, 25);
7333 GEN_VXFORM_ENV(vsubuws, 0, 26);
7334 GEN_VXFORM_ENV(vsubsbs, 0, 28);
7335 GEN_VXFORM_ENV(vsubshs, 0, 29);
7336 GEN_VXFORM_ENV(vsubsws, 0, 30);
7337 GEN_VXFORM(vadduqm, 0, 4);
7338 GEN_VXFORM(vaddcuq, 0, 5);
7339 GEN_VXFORM3(vaddeuqm, 30, 0);
7340 GEN_VXFORM3(vaddecuq, 30, 0);
7341 GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7342 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7343 GEN_VXFORM(vsubuqm, 0, 20);
7344 GEN_VXFORM(vsubcuq, 0, 21);
7345 GEN_VXFORM3(vsubeuqm, 31, 0);
7346 GEN_VXFORM3(vsubecuq, 31, 0);
7347 GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7348 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
7349 GEN_VXFORM(vrlb, 2, 0);
7350 GEN_VXFORM(vrlh, 2, 1);
7351 GEN_VXFORM(vrlw, 2, 2);
7352 GEN_VXFORM(vrld, 2, 3);
7353 GEN_VXFORM(vsl, 2, 7);
7354 GEN_VXFORM(vsr, 2, 11);
7355 GEN_VXFORM_ENV(vpkuhum, 7, 0);
7356 GEN_VXFORM_ENV(vpkuwum, 7, 1);
7357 GEN_VXFORM_ENV(vpkudum, 7, 17);
7358 GEN_VXFORM_ENV(vpkuhus, 7, 2);
7359 GEN_VXFORM_ENV(vpkuwus, 7, 3);
7360 GEN_VXFORM_ENV(vpkudus, 7, 19);
7361 GEN_VXFORM_ENV(vpkshus, 7, 4);
7362 GEN_VXFORM_ENV(vpkswus, 7, 5);
7363 GEN_VXFORM_ENV(vpksdus, 7, 21);
7364 GEN_VXFORM_ENV(vpkshss, 7, 6);
7365 GEN_VXFORM_ENV(vpkswss, 7, 7);
7366 GEN_VXFORM_ENV(vpksdss, 7, 23);
7367 GEN_VXFORM(vpkpx, 7, 12);
7368 GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7369 GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7370 GEN_VXFORM_ENV(vsum4shs, 4, 25);
7371 GEN_VXFORM_ENV(vsum2sws, 4, 26);
7372 GEN_VXFORM_ENV(vsumsws, 4, 30);
7373 GEN_VXFORM_ENV(vaddfp, 5, 0);
7374 GEN_VXFORM_ENV(vsubfp, 5, 1);
7375 GEN_VXFORM_ENV(vmaxfp, 5, 16);
7376 GEN_VXFORM_ENV(vminfp, 5, 17);
7378 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
7379 static void glue(gen_, name)(DisasContext *ctx) \
7381 TCGv_ptr ra, rb, rd; \
7382 if (unlikely(!ctx->altivec_enabled)) { \
7383 gen_exception(ctx, POWERPC_EXCP_VPU); \
7386 ra = gen_avr_ptr(rA(ctx->opcode)); \
7387 rb = gen_avr_ptr(rB(ctx->opcode)); \
7388 rd = gen_avr_ptr(rD(ctx->opcode)); \
7389 gen_helper_##opname(cpu_env, rd, ra, rb); \
7390 tcg_temp_free_ptr(ra); \
7391 tcg_temp_free_ptr(rb); \
7392 tcg_temp_free_ptr(rd); \
7395 #define GEN_VXRFORM(name, opc2, opc3) \
7396 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7397 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7400 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7401 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7402 * come from different versions of the ISA, so we must also support a
7403 * pair of flags for each instruction.
7405 #define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7406 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7408 if ((Rc(ctx->opcode) == 0) && \
7409 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7410 if (Rc21(ctx->opcode) == 0) { \
7413 gen_##name0##_(ctx); \
7415 } else if ((Rc(ctx->opcode) == 1) && \
7416 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7417 if (Rc21(ctx->opcode) == 0) { \
7420 gen_##name1##_(ctx); \
7423 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7427 GEN_VXRFORM(vcmpequb, 3, 0)
7428 GEN_VXRFORM(vcmpequh, 3, 1)
7429 GEN_VXRFORM(vcmpequw, 3, 2)
7430 GEN_VXRFORM(vcmpequd, 3, 3)
7431 GEN_VXRFORM(vcmpgtsb, 3, 12)
7432 GEN_VXRFORM(vcmpgtsh, 3, 13)
7433 GEN_VXRFORM(vcmpgtsw, 3, 14)
7434 GEN_VXRFORM(vcmpgtsd, 3, 15)
7435 GEN_VXRFORM(vcmpgtub, 3, 8)
7436 GEN_VXRFORM(vcmpgtuh, 3, 9)
7437 GEN_VXRFORM(vcmpgtuw, 3, 10)
7438 GEN_VXRFORM(vcmpgtud, 3, 11)
7439 GEN_VXRFORM(vcmpeqfp, 3, 3)
7440 GEN_VXRFORM(vcmpgefp, 3, 7)
7441 GEN_VXRFORM(vcmpgtfp, 3, 11)
7442 GEN_VXRFORM(vcmpbfp, 3, 15)
7444 GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7445 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7446 GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7447 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7448 GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7449 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7451 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7452 static void glue(gen_, name)(DisasContext *ctx) \
7456 if (unlikely(!ctx->altivec_enabled)) { \
7457 gen_exception(ctx, POWERPC_EXCP_VPU); \
7460 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7461 rd = gen_avr_ptr(rD(ctx->opcode)); \
7462 gen_helper_##name (rd, simm); \
7463 tcg_temp_free_i32(simm); \
7464 tcg_temp_free_ptr(rd); \
7467 GEN_VXFORM_SIMM(vspltisb, 6, 12);
7468 GEN_VXFORM_SIMM(vspltish, 6, 13);
7469 GEN_VXFORM_SIMM(vspltisw, 6, 14);
7471 #define GEN_VXFORM_NOA(name, opc2, opc3) \
7472 static void glue(gen_, name)(DisasContext *ctx) \
7475 if (unlikely(!ctx->altivec_enabled)) { \
7476 gen_exception(ctx, POWERPC_EXCP_VPU); \
7479 rb = gen_avr_ptr(rB(ctx->opcode)); \
7480 rd = gen_avr_ptr(rD(ctx->opcode)); \
7481 gen_helper_##name (rd, rb); \
7482 tcg_temp_free_ptr(rb); \
7483 tcg_temp_free_ptr(rd); \
7486 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7487 static void glue(gen_, name)(DisasContext *ctx) \
7491 if (unlikely(!ctx->altivec_enabled)) { \
7492 gen_exception(ctx, POWERPC_EXCP_VPU); \
7495 rb = gen_avr_ptr(rB(ctx->opcode)); \
7496 rd = gen_avr_ptr(rD(ctx->opcode)); \
7497 gen_helper_##name(cpu_env, rd, rb); \
7498 tcg_temp_free_ptr(rb); \
7499 tcg_temp_free_ptr(rd); \
7502 GEN_VXFORM_NOA(vupkhsb, 7, 8);
7503 GEN_VXFORM_NOA(vupkhsh, 7, 9);
7504 GEN_VXFORM_NOA(vupkhsw, 7, 25);
7505 GEN_VXFORM_NOA(vupklsb, 7, 10);
7506 GEN_VXFORM_NOA(vupklsh, 7, 11);
7507 GEN_VXFORM_NOA(vupklsw, 7, 27);
7508 GEN_VXFORM_NOA(vupkhpx, 7, 13);
7509 GEN_VXFORM_NOA(vupklpx, 7, 15);
7510 GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7511 GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7512 GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7513 GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
7514 GEN_VXFORM_NOA_ENV(vrfim, 5, 11);
7515 GEN_VXFORM_NOA_ENV(vrfin, 5, 8);
7516 GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
7517 GEN_VXFORM_NOA_ENV(vrfiz, 5, 9);
7519 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7520 static void glue(gen_, name)(DisasContext *ctx) \
7524 if (unlikely(!ctx->altivec_enabled)) { \
7525 gen_exception(ctx, POWERPC_EXCP_VPU); \
7528 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7529 rd = gen_avr_ptr(rD(ctx->opcode)); \
7530 gen_helper_##name (rd, simm); \
7531 tcg_temp_free_i32(simm); \
7532 tcg_temp_free_ptr(rd); \
7535 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
7536 static void glue(gen_, name)(DisasContext *ctx) \
7540 if (unlikely(!ctx->altivec_enabled)) { \
7541 gen_exception(ctx, POWERPC_EXCP_VPU); \
7544 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7545 rb = gen_avr_ptr(rB(ctx->opcode)); \
7546 rd = gen_avr_ptr(rD(ctx->opcode)); \
7547 gen_helper_##name (rd, rb, uimm); \
7548 tcg_temp_free_i32(uimm); \
7549 tcg_temp_free_ptr(rb); \
7550 tcg_temp_free_ptr(rd); \
7553 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7554 static void glue(gen_, name)(DisasContext *ctx) \
7559 if (unlikely(!ctx->altivec_enabled)) { \
7560 gen_exception(ctx, POWERPC_EXCP_VPU); \
7563 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7564 rb = gen_avr_ptr(rB(ctx->opcode)); \
7565 rd = gen_avr_ptr(rD(ctx->opcode)); \
7566 gen_helper_##name(cpu_env, rd, rb, uimm); \
7567 tcg_temp_free_i32(uimm); \
7568 tcg_temp_free_ptr(rb); \
7569 tcg_temp_free_ptr(rd); \
7572 GEN_VXFORM_UIMM(vspltb, 6, 8);
7573 GEN_VXFORM_UIMM(vsplth, 6, 9);
7574 GEN_VXFORM_UIMM(vspltw, 6, 10);
7575 GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7576 GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7577 GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7578 GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
7580 static void gen_vsldoi(DisasContext *ctx)
7582 TCGv_ptr ra, rb, rd;
7584 if (unlikely(!ctx->altivec_enabled)) {
7585 gen_exception(ctx, POWERPC_EXCP_VPU);
7588 ra = gen_avr_ptr(rA(ctx->opcode));
7589 rb = gen_avr_ptr(rB(ctx->opcode));
7590 rd = gen_avr_ptr(rD(ctx->opcode));
7591 sh = tcg_const_i32(VSH(ctx->opcode));
7592 gen_helper_vsldoi (rd, ra, rb, sh);
7593 tcg_temp_free_ptr(ra);
7594 tcg_temp_free_ptr(rb);
7595 tcg_temp_free_ptr(rd);
7596 tcg_temp_free_i32(sh);
7599 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
7600 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7602 TCGv_ptr ra, rb, rc, rd; \
7603 if (unlikely(!ctx->altivec_enabled)) { \
7604 gen_exception(ctx, POWERPC_EXCP_VPU); \
7607 ra = gen_avr_ptr(rA(ctx->opcode)); \
7608 rb = gen_avr_ptr(rB(ctx->opcode)); \
7609 rc = gen_avr_ptr(rC(ctx->opcode)); \
7610 rd = gen_avr_ptr(rD(ctx->opcode)); \
7611 if (Rc(ctx->opcode)) { \
7612 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
7614 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
7616 tcg_temp_free_ptr(ra); \
7617 tcg_temp_free_ptr(rb); \
7618 tcg_temp_free_ptr(rc); \
7619 tcg_temp_free_ptr(rd); \
7622 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7624 static void gen_vmladduhm(DisasContext *ctx)
7626 TCGv_ptr ra, rb, rc, rd;
7627 if (unlikely(!ctx->altivec_enabled)) {
7628 gen_exception(ctx, POWERPC_EXCP_VPU);
7631 ra = gen_avr_ptr(rA(ctx->opcode));
7632 rb = gen_avr_ptr(rB(ctx->opcode));
7633 rc = gen_avr_ptr(rC(ctx->opcode));
7634 rd = gen_avr_ptr(rD(ctx->opcode));
7635 gen_helper_vmladduhm(rd, ra, rb, rc);
7636 tcg_temp_free_ptr(ra);
7637 tcg_temp_free_ptr(rb);
7638 tcg_temp_free_ptr(rc);
7639 tcg_temp_free_ptr(rd);
7642 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
7643 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
7644 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
7645 GEN_VAFORM_PAIRED(vsel, vperm, 21)
7646 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
7648 GEN_VXFORM_NOA(vclzb, 1, 28)
7649 GEN_VXFORM_NOA(vclzh, 1, 29)
7650 GEN_VXFORM_NOA(vclzw, 1, 30)
7651 GEN_VXFORM_NOA(vclzd, 1, 31)
7652 GEN_VXFORM_NOA(vpopcntb, 1, 28)
7653 GEN_VXFORM_NOA(vpopcnth, 1, 29)
7654 GEN_VXFORM_NOA(vpopcntw, 1, 30)
7655 GEN_VXFORM_NOA(vpopcntd, 1, 31)
7656 GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7657 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7658 GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7659 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7660 GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7661 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7662 GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7663 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
7664 GEN_VXFORM(vbpermq, 6, 21);
7665 GEN_VXFORM_NOA(vgbbd, 6, 20);
7666 GEN_VXFORM(vpmsumb, 4, 16)
7667 GEN_VXFORM(vpmsumh, 4, 17)
7668 GEN_VXFORM(vpmsumw, 4, 18)
7669 GEN_VXFORM(vpmsumd, 4, 19)
7671 #define GEN_BCD(op) \
7672 static void gen_##op(DisasContext *ctx) \
7674 TCGv_ptr ra, rb, rd; \
7677 if (unlikely(!ctx->altivec_enabled)) { \
7678 gen_exception(ctx, POWERPC_EXCP_VPU); \
7682 ra = gen_avr_ptr(rA(ctx->opcode)); \
7683 rb = gen_avr_ptr(rB(ctx->opcode)); \
7684 rd = gen_avr_ptr(rD(ctx->opcode)); \
7686 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7688 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7690 tcg_temp_free_ptr(ra); \
7691 tcg_temp_free_ptr(rb); \
7692 tcg_temp_free_ptr(rd); \
7693 tcg_temp_free_i32(ps); \
7699 GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7700 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7701 GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7702 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7703 GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7704 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7705 GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7706 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7708 static void gen_vsbox(DisasContext *ctx)
7711 if (unlikely(!ctx->altivec_enabled)) {
7712 gen_exception(ctx, POWERPC_EXCP_VPU);
7715 ra = gen_avr_ptr(rA(ctx->opcode));
7716 rd = gen_avr_ptr(rD(ctx->opcode));
7717 gen_helper_vsbox(rd, ra);
7718 tcg_temp_free_ptr(ra);
7719 tcg_temp_free_ptr(rd);
7722 GEN_VXFORM(vcipher, 4, 20)
7723 GEN_VXFORM(vcipherlast, 4, 20)
7724 GEN_VXFORM(vncipher, 4, 21)
7725 GEN_VXFORM(vncipherlast, 4, 21)
7727 GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7728 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7729 GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7730 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7732 #define VSHASIGMA(op) \
7733 static void gen_##op(DisasContext *ctx) \
7737 if (unlikely(!ctx->altivec_enabled)) { \
7738 gen_exception(ctx, POWERPC_EXCP_VPU); \
7741 ra = gen_avr_ptr(rA(ctx->opcode)); \
7742 rd = gen_avr_ptr(rD(ctx->opcode)); \
7743 st_six = tcg_const_i32(rB(ctx->opcode)); \
7744 gen_helper_##op(rd, ra, st_six); \
7745 tcg_temp_free_ptr(ra); \
7746 tcg_temp_free_ptr(rd); \
7747 tcg_temp_free_i32(st_six); \
7750 VSHASIGMA(vshasigmaw)
7751 VSHASIGMA(vshasigmad)
7753 GEN_VXFORM3(vpermxor, 22, 0xFF)
7754 GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7755 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7757 /*** VSX extension ***/
7759 static inline TCGv_i64 cpu_vsrh(int n)
7764 return cpu_avrh[n-32];
7768 static inline TCGv_i64 cpu_vsrl(int n)
7773 return cpu_avrl[n-32];
7777 #define VSX_LOAD_SCALAR(name, operation) \
7778 static void gen_##name(DisasContext *ctx) \
7781 if (unlikely(!ctx->vsx_enabled)) { \
7782 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7785 gen_set_access_type(ctx, ACCESS_INT); \
7786 EA = tcg_temp_new(); \
7787 gen_addr_reg_index(ctx, EA); \
7788 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7789 /* NOTE: cpu_vsrl is undefined */ \
7790 tcg_temp_free(EA); \
7793 VSX_LOAD_SCALAR(lxsdx, ld64)
7794 VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7795 VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7796 VSX_LOAD_SCALAR(lxsspx, ld32fs)
7798 static void gen_lxvd2x(DisasContext *ctx)
7801 if (unlikely(!ctx->vsx_enabled)) {
7802 gen_exception(ctx, POWERPC_EXCP_VSXU);
7805 gen_set_access_type(ctx, ACCESS_INT);
7806 EA = tcg_temp_new();
7807 gen_addr_reg_index(ctx, EA);
7808 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7809 tcg_gen_addi_tl(EA, EA, 8);
7810 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7814 static void gen_lxvdsx(DisasContext *ctx)
7817 if (unlikely(!ctx->vsx_enabled)) {
7818 gen_exception(ctx, POWERPC_EXCP_VSXU);
7821 gen_set_access_type(ctx, ACCESS_INT);
7822 EA = tcg_temp_new();
7823 gen_addr_reg_index(ctx, EA);
7824 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7825 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
7829 static void gen_lxvw4x(DisasContext *ctx)
7833 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7834 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7835 if (unlikely(!ctx->vsx_enabled)) {
7836 gen_exception(ctx, POWERPC_EXCP_VSXU);
7839 gen_set_access_type(ctx, ACCESS_INT);
7840 EA = tcg_temp_new();
7841 tmp = tcg_temp_new_i64();
7843 gen_addr_reg_index(ctx, EA);
7844 gen_qemu_ld32u_i64(ctx, tmp, EA);
7845 tcg_gen_addi_tl(EA, EA, 4);
7846 gen_qemu_ld32u_i64(ctx, xth, EA);
7847 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7849 tcg_gen_addi_tl(EA, EA, 4);
7850 gen_qemu_ld32u_i64(ctx, tmp, EA);
7851 tcg_gen_addi_tl(EA, EA, 4);
7852 gen_qemu_ld32u_i64(ctx, xtl, EA);
7853 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7856 tcg_temp_free_i64(tmp);
7859 #define VSX_STORE_SCALAR(name, operation) \
7860 static void gen_##name(DisasContext *ctx) \
7863 if (unlikely(!ctx->vsx_enabled)) { \
7864 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7867 gen_set_access_type(ctx, ACCESS_INT); \
7868 EA = tcg_temp_new(); \
7869 gen_addr_reg_index(ctx, EA); \
7870 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7871 tcg_temp_free(EA); \
7874 VSX_STORE_SCALAR(stxsdx, st64)
7875 VSX_STORE_SCALAR(stxsiwx, st32_i64)
7876 VSX_STORE_SCALAR(stxsspx, st32fs)
7878 static void gen_stxvd2x(DisasContext *ctx)
7881 if (unlikely(!ctx->vsx_enabled)) {
7882 gen_exception(ctx, POWERPC_EXCP_VSXU);
7885 gen_set_access_type(ctx, ACCESS_INT);
7886 EA = tcg_temp_new();
7887 gen_addr_reg_index(ctx, EA);
7888 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7889 tcg_gen_addi_tl(EA, EA, 8);
7890 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7894 static void gen_stxvw4x(DisasContext *ctx)
7898 if (unlikely(!ctx->vsx_enabled)) {
7899 gen_exception(ctx, POWERPC_EXCP_VSXU);
7902 gen_set_access_type(ctx, ACCESS_INT);
7903 EA = tcg_temp_new();
7904 gen_addr_reg_index(ctx, EA);
7905 tmp = tcg_temp_new_i64();
7907 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
7908 gen_qemu_st32_i64(ctx, tmp, EA);
7909 tcg_gen_addi_tl(EA, EA, 4);
7910 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7912 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7913 tcg_gen_addi_tl(EA, EA, 4);
7914 gen_qemu_st32_i64(ctx, tmp, EA);
7915 tcg_gen_addi_tl(EA, EA, 4);
7916 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7919 tcg_temp_free_i64(tmp);
7922 #define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7923 static void gen_##name(DisasContext *ctx) \
7925 if (xS(ctx->opcode) < 32) { \
7926 if (unlikely(!ctx->fpu_enabled)) { \
7927 gen_exception(ctx, POWERPC_EXCP_FPU); \
7931 if (unlikely(!ctx->altivec_enabled)) { \
7932 gen_exception(ctx, POWERPC_EXCP_VPU); \
7936 TCGv_i64 tmp = tcg_temp_new_i64(); \
7937 tcg_gen_##tcgop1(tmp, source); \
7938 tcg_gen_##tcgop2(target, tmp); \
7939 tcg_temp_free_i64(tmp); \
7943 MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7944 cpu_vsrh(xS(ctx->opcode)))
7945 MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7946 cpu_gpr[rA(ctx->opcode)])
7947 MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7948 cpu_gpr[rA(ctx->opcode)])
7950 #if defined(TARGET_PPC64)
7951 #define MV_VSRD(name, target, source) \
7952 static void gen_##name(DisasContext *ctx) \
7954 if (xS(ctx->opcode) < 32) { \
7955 if (unlikely(!ctx->fpu_enabled)) { \
7956 gen_exception(ctx, POWERPC_EXCP_FPU); \
7960 if (unlikely(!ctx->altivec_enabled)) { \
7961 gen_exception(ctx, POWERPC_EXCP_VPU); \
7965 tcg_gen_mov_i64(target, source); \
7968 MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7969 MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7973 static void gen_xxpermdi(DisasContext *ctx)
7975 if (unlikely(!ctx->vsx_enabled)) {
7976 gen_exception(ctx, POWERPC_EXCP_VSXU);
7980 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7981 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7984 xh = tcg_temp_new_i64();
7985 xl = tcg_temp_new_i64();
7987 if ((DM(ctx->opcode) & 2) == 0) {
7988 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7990 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7992 if ((DM(ctx->opcode) & 1) == 0) {
7993 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7995 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7998 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7999 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
8001 tcg_temp_free_i64(xh);
8002 tcg_temp_free_i64(xl);
8004 if ((DM(ctx->opcode) & 2) == 0) {
8005 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
8007 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
8009 if ((DM(ctx->opcode) & 1) == 0) {
8010 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
8012 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
8021 #define SGN_MASK_DP 0x8000000000000000ull
8022 #define SGN_MASK_SP 0x8000000080000000ull
8024 #define VSX_SCALAR_MOVE(name, op, sgn_mask) \
8025 static void glue(gen_, name)(DisasContext * ctx) \
8028 if (unlikely(!ctx->vsx_enabled)) { \
8029 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8032 xb = tcg_temp_new_i64(); \
8033 sgm = tcg_temp_new_i64(); \
8034 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
8035 tcg_gen_movi_i64(sgm, sgn_mask); \
8038 tcg_gen_andc_i64(xb, xb, sgm); \
8042 tcg_gen_or_i64(xb, xb, sgm); \
8046 tcg_gen_xor_i64(xb, xb, sgm); \
8050 TCGv_i64 xa = tcg_temp_new_i64(); \
8051 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
8052 tcg_gen_and_i64(xa, xa, sgm); \
8053 tcg_gen_andc_i64(xb, xb, sgm); \
8054 tcg_gen_or_i64(xb, xb, xa); \
8055 tcg_temp_free_i64(xa); \
8059 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
8060 tcg_temp_free_i64(xb); \
8061 tcg_temp_free_i64(sgm); \
8064 VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
8065 VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
8066 VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
8067 VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
8069 #define VSX_VECTOR_MOVE(name, op, sgn_mask) \
8070 static void glue(gen_, name)(DisasContext * ctx) \
8072 TCGv_i64 xbh, xbl, sgm; \
8073 if (unlikely(!ctx->vsx_enabled)) { \
8074 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8077 xbh = tcg_temp_new_i64(); \
8078 xbl = tcg_temp_new_i64(); \
8079 sgm = tcg_temp_new_i64(); \
8080 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
8081 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
8082 tcg_gen_movi_i64(sgm, sgn_mask); \
8085 tcg_gen_andc_i64(xbh, xbh, sgm); \
8086 tcg_gen_andc_i64(xbl, xbl, sgm); \
8090 tcg_gen_or_i64(xbh, xbh, sgm); \
8091 tcg_gen_or_i64(xbl, xbl, sgm); \
8095 tcg_gen_xor_i64(xbh, xbh, sgm); \
8096 tcg_gen_xor_i64(xbl, xbl, sgm); \
8100 TCGv_i64 xah = tcg_temp_new_i64(); \
8101 TCGv_i64 xal = tcg_temp_new_i64(); \
8102 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
8103 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
8104 tcg_gen_and_i64(xah, xah, sgm); \
8105 tcg_gen_and_i64(xal, xal, sgm); \
8106 tcg_gen_andc_i64(xbh, xbh, sgm); \
8107 tcg_gen_andc_i64(xbl, xbl, sgm); \
8108 tcg_gen_or_i64(xbh, xbh, xah); \
8109 tcg_gen_or_i64(xbl, xbl, xal); \
8110 tcg_temp_free_i64(xah); \
8111 tcg_temp_free_i64(xal); \
8115 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
8116 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
8117 tcg_temp_free_i64(xbh); \
8118 tcg_temp_free_i64(xbl); \
8119 tcg_temp_free_i64(sgm); \
8122 VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
8123 VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
8124 VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
8125 VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
8126 VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
8127 VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
8128 VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
8129 VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
8131 #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
8132 static void gen_##name(DisasContext * ctx) \
8135 if (unlikely(!ctx->vsx_enabled)) { \
8136 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8139 /* NIP cannot be restored if the memory exception comes from an helper */ \
8140 gen_update_nip(ctx, ctx->nip - 4); \
8141 opc = tcg_const_i32(ctx->opcode); \
8142 gen_helper_##name(cpu_env, opc); \
8143 tcg_temp_free_i32(opc); \
8146 #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
8147 static void gen_##name(DisasContext * ctx) \
8149 if (unlikely(!ctx->vsx_enabled)) { \
8150 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8153 /* NIP cannot be restored if the exception comes */ \
8154 /* from a helper. */ \
8155 gen_update_nip(ctx, ctx->nip - 4); \
8157 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
8158 cpu_vsrh(xB(ctx->opcode))); \
8161 GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
8162 GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
8163 GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
8164 GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
8165 GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
8166 GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
8167 GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
8168 GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
8169 GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
8170 GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
8171 GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
8172 GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
8173 GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
8174 GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
8175 GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
8176 GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
8177 GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
8178 GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
8179 GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
8180 GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
8181 GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
8182 GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
8183 GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
8184 GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
8185 GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
8186 GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
8187 GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
8188 GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
8189 GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
8190 GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
8191 GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
8192 GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
8193 GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
8194 GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
8195 GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
8196 GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
8197 GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
8199 GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
8200 GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
8201 GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
8202 GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
8203 GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
8204 GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
8205 GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
8206 GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
8207 GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
8208 GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
8209 GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
8210 GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
8211 GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
8212 GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
8213 GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
8214 GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
8215 GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
8217 GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
8218 GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
8219 GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
8220 GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
8221 GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
8222 GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
8223 GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
8224 GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
8225 GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
8226 GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
8227 GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
8228 GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
8229 GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
8230 GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
8231 GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
8232 GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
8233 GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
8234 GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
8235 GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
8236 GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
8237 GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
8238 GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
8239 GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
8240 GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
8241 GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
8242 GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
8243 GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
8244 GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
8245 GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
8246 GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
8247 GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
8248 GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
8249 GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
8250 GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
8251 GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
8252 GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
8254 GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
8255 GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
8256 GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
8257 GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
8258 GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
8259 GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
8260 GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
8261 GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
8262 GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
8263 GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
8264 GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
8265 GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
8266 GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
8267 GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
8268 GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
8269 GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
8270 GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
8271 GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
8272 GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
8273 GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
8274 GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
8275 GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
8276 GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
8277 GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
8278 GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
8279 GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
8280 GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
8281 GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
8282 GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
8283 GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
8284 GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
8285 GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
8286 GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
8287 GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
8288 GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
8289 GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
8291 #define VSX_LOGICAL(name, tcg_op) \
8292 static void glue(gen_, name)(DisasContext * ctx) \
8294 if (unlikely(!ctx->vsx_enabled)) { \
8295 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8298 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8299 cpu_vsrh(xB(ctx->opcode))); \
8300 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8301 cpu_vsrl(xB(ctx->opcode))); \
8304 VSX_LOGICAL(xxland, tcg_gen_and_i64)
8305 VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8306 VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8307 VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8308 VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
8309 VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8310 VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8311 VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
8313 #define VSX_XXMRG(name, high) \
8314 static void glue(gen_, name)(DisasContext * ctx) \
8316 TCGv_i64 a0, a1, b0, b1; \
8317 if (unlikely(!ctx->vsx_enabled)) { \
8318 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8321 a0 = tcg_temp_new_i64(); \
8322 a1 = tcg_temp_new_i64(); \
8323 b0 = tcg_temp_new_i64(); \
8324 b1 = tcg_temp_new_i64(); \
8326 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8327 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8328 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8329 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8331 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8332 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8333 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8334 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8336 tcg_gen_shri_i64(a0, a0, 32); \
8337 tcg_gen_shri_i64(b0, b0, 32); \
8338 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8340 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8342 tcg_temp_free_i64(a0); \
8343 tcg_temp_free_i64(a1); \
8344 tcg_temp_free_i64(b0); \
8345 tcg_temp_free_i64(b1); \
8348 VSX_XXMRG(xxmrghw, 1)
8349 VSX_XXMRG(xxmrglw, 0)
8351 static void gen_xxsel(DisasContext * ctx)
8354 if (unlikely(!ctx->vsx_enabled)) {
8355 gen_exception(ctx, POWERPC_EXCP_VSXU);
8358 a = tcg_temp_new_i64();
8359 b = tcg_temp_new_i64();
8360 c = tcg_temp_new_i64();
8362 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8363 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8364 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8366 tcg_gen_and_i64(b, b, c);
8367 tcg_gen_andc_i64(a, a, c);
8368 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8370 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8371 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8372 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8374 tcg_gen_and_i64(b, b, c);
8375 tcg_gen_andc_i64(a, a, c);
8376 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8378 tcg_temp_free_i64(a);
8379 tcg_temp_free_i64(b);
8380 tcg_temp_free_i64(c);
8383 static void gen_xxspltw(DisasContext *ctx)
8386 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8387 cpu_vsrl(xB(ctx->opcode)) :
8388 cpu_vsrh(xB(ctx->opcode));
8390 if (unlikely(!ctx->vsx_enabled)) {
8391 gen_exception(ctx, POWERPC_EXCP_VSXU);
8395 b = tcg_temp_new_i64();
8396 b2 = tcg_temp_new_i64();
8398 if (UIM(ctx->opcode) & 1) {
8399 tcg_gen_ext32u_i64(b, vsr);
8401 tcg_gen_shri_i64(b, vsr, 32);
8404 tcg_gen_shli_i64(b2, b, 32);
8405 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8406 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8408 tcg_temp_free_i64(b);
8409 tcg_temp_free_i64(b2);
8412 static void gen_xxsldwi(DisasContext *ctx)
8415 if (unlikely(!ctx->vsx_enabled)) {
8416 gen_exception(ctx, POWERPC_EXCP_VSXU);
8419 xth = tcg_temp_new_i64();
8420 xtl = tcg_temp_new_i64();
8422 switch (SHW(ctx->opcode)) {
8424 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8425 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8429 TCGv_i64 t0 = tcg_temp_new_i64();
8430 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8431 tcg_gen_shli_i64(xth, xth, 32);
8432 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8433 tcg_gen_shri_i64(t0, t0, 32);
8434 tcg_gen_or_i64(xth, xth, t0);
8435 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8436 tcg_gen_shli_i64(xtl, xtl, 32);
8437 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8438 tcg_gen_shri_i64(t0, t0, 32);
8439 tcg_gen_or_i64(xtl, xtl, t0);
8440 tcg_temp_free_i64(t0);
8444 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8445 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8449 TCGv_i64 t0 = tcg_temp_new_i64();
8450 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8451 tcg_gen_shli_i64(xth, xth, 32);
8452 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8453 tcg_gen_shri_i64(t0, t0, 32);
8454 tcg_gen_or_i64(xth, xth, t0);
8455 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8456 tcg_gen_shli_i64(xtl, xtl, 32);
8457 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8458 tcg_gen_shri_i64(t0, t0, 32);
8459 tcg_gen_or_i64(xtl, xtl, t0);
8460 tcg_temp_free_i64(t0);
8465 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8466 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8468 tcg_temp_free_i64(xth);
8469 tcg_temp_free_i64(xtl);
8472 /*** Decimal Floating Point ***/
8474 static inline TCGv_ptr gen_fprp_ptr(int reg)
8476 TCGv_ptr r = tcg_temp_new_ptr();
8477 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, fpr[reg]));
8481 #define GEN_DFP_T_A_B_Rc(name) \
8482 static void gen_##name(DisasContext *ctx) \
8484 TCGv_ptr rd, ra, rb; \
8485 if (unlikely(!ctx->fpu_enabled)) { \
8486 gen_exception(ctx, POWERPC_EXCP_FPU); \
8489 gen_update_nip(ctx, ctx->nip - 4); \
8490 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8491 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8492 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8493 gen_helper_##name(cpu_env, rd, ra, rb); \
8494 if (unlikely(Rc(ctx->opcode) != 0)) { \
8495 gen_set_cr1_from_fpscr(ctx); \
8497 tcg_temp_free_ptr(rd); \
8498 tcg_temp_free_ptr(ra); \
8499 tcg_temp_free_ptr(rb); \
8502 #define GEN_DFP_BF_A_B(name) \
8503 static void gen_##name(DisasContext *ctx) \
8506 if (unlikely(!ctx->fpu_enabled)) { \
8507 gen_exception(ctx, POWERPC_EXCP_FPU); \
8510 gen_update_nip(ctx, ctx->nip - 4); \
8511 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8512 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8513 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8515 tcg_temp_free_ptr(ra); \
8516 tcg_temp_free_ptr(rb); \
8519 #define GEN_DFP_BF_A_DCM(name) \
8520 static void gen_##name(DisasContext *ctx) \
8524 if (unlikely(!ctx->fpu_enabled)) { \
8525 gen_exception(ctx, POWERPC_EXCP_FPU); \
8528 gen_update_nip(ctx, ctx->nip - 4); \
8529 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8530 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8531 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8532 cpu_env, ra, dcm); \
8533 tcg_temp_free_ptr(ra); \
8534 tcg_temp_free_i32(dcm); \
8537 #define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8538 static void gen_##name(DisasContext *ctx) \
8541 TCGv_i32 u32_1, u32_2; \
8542 if (unlikely(!ctx->fpu_enabled)) { \
8543 gen_exception(ctx, POWERPC_EXCP_FPU); \
8546 gen_update_nip(ctx, ctx->nip - 4); \
8547 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8548 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8549 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8550 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8551 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8552 if (unlikely(Rc(ctx->opcode) != 0)) { \
8553 gen_set_cr1_from_fpscr(ctx); \
8555 tcg_temp_free_ptr(rt); \
8556 tcg_temp_free_ptr(rb); \
8557 tcg_temp_free_i32(u32_1); \
8558 tcg_temp_free_i32(u32_2); \
8561 #define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8562 static void gen_##name(DisasContext *ctx) \
8564 TCGv_ptr rt, ra, rb; \
8566 if (unlikely(!ctx->fpu_enabled)) { \
8567 gen_exception(ctx, POWERPC_EXCP_FPU); \
8570 gen_update_nip(ctx, ctx->nip - 4); \
8571 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8572 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8573 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8574 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8575 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8576 if (unlikely(Rc(ctx->opcode) != 0)) { \
8577 gen_set_cr1_from_fpscr(ctx); \
8579 tcg_temp_free_ptr(rt); \
8580 tcg_temp_free_ptr(rb); \
8581 tcg_temp_free_ptr(ra); \
8582 tcg_temp_free_i32(i32); \
8585 #define GEN_DFP_T_B_Rc(name) \
8586 static void gen_##name(DisasContext *ctx) \
8589 if (unlikely(!ctx->fpu_enabled)) { \
8590 gen_exception(ctx, POWERPC_EXCP_FPU); \
8593 gen_update_nip(ctx, ctx->nip - 4); \
8594 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8595 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8596 gen_helper_##name(cpu_env, rt, rb); \
8597 if (unlikely(Rc(ctx->opcode) != 0)) { \
8598 gen_set_cr1_from_fpscr(ctx); \
8600 tcg_temp_free_ptr(rt); \
8601 tcg_temp_free_ptr(rb); \
8604 #define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8605 static void gen_##name(DisasContext *ctx) \
8609 if (unlikely(!ctx->fpu_enabled)) { \
8610 gen_exception(ctx, POWERPC_EXCP_FPU); \
8613 gen_update_nip(ctx, ctx->nip - 4); \
8614 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8615 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8616 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8617 gen_helper_##name(cpu_env, rt, rs, i32); \
8618 if (unlikely(Rc(ctx->opcode) != 0)) { \
8619 gen_set_cr1_from_fpscr(ctx); \
8621 tcg_temp_free_ptr(rt); \
8622 tcg_temp_free_ptr(rs); \
8623 tcg_temp_free_i32(i32); \
8626 GEN_DFP_T_A_B_Rc(dadd)
8627 GEN_DFP_T_A_B_Rc(daddq)
8628 GEN_DFP_T_A_B_Rc(dsub)
8629 GEN_DFP_T_A_B_Rc(dsubq)
8630 GEN_DFP_T_A_B_Rc(dmul)
8631 GEN_DFP_T_A_B_Rc(dmulq)
8632 GEN_DFP_T_A_B_Rc(ddiv)
8633 GEN_DFP_T_A_B_Rc(ddivq)
8634 GEN_DFP_BF_A_B(dcmpu)
8635 GEN_DFP_BF_A_B(dcmpuq)
8636 GEN_DFP_BF_A_B(dcmpo)
8637 GEN_DFP_BF_A_B(dcmpoq)
8638 GEN_DFP_BF_A_DCM(dtstdc)
8639 GEN_DFP_BF_A_DCM(dtstdcq)
8640 GEN_DFP_BF_A_DCM(dtstdg)
8641 GEN_DFP_BF_A_DCM(dtstdgq)
8642 GEN_DFP_BF_A_B(dtstex)
8643 GEN_DFP_BF_A_B(dtstexq)
8644 GEN_DFP_BF_A_B(dtstsf)
8645 GEN_DFP_BF_A_B(dtstsfq)
8646 GEN_DFP_T_B_U32_U32_Rc(dquai, SIMM5, RMC)
8647 GEN_DFP_T_B_U32_U32_Rc(dquaiq, SIMM5, RMC)
8648 GEN_DFP_T_A_B_I32_Rc(dqua, RMC)
8649 GEN_DFP_T_A_B_I32_Rc(dquaq, RMC)
8650 GEN_DFP_T_A_B_I32_Rc(drrnd, RMC)
8651 GEN_DFP_T_A_B_I32_Rc(drrndq, RMC)
8652 GEN_DFP_T_B_U32_U32_Rc(drintx, FPW, RMC)
8653 GEN_DFP_T_B_U32_U32_Rc(drintxq, FPW, RMC)
8654 GEN_DFP_T_B_U32_U32_Rc(drintn, FPW, RMC)
8655 GEN_DFP_T_B_U32_U32_Rc(drintnq, FPW, RMC)
8656 GEN_DFP_T_B_Rc(dctdp)
8657 GEN_DFP_T_B_Rc(dctqpq)
8658 GEN_DFP_T_B_Rc(drsp)
8659 GEN_DFP_T_B_Rc(drdpq)
8660 GEN_DFP_T_B_Rc(dcffix)
8661 GEN_DFP_T_B_Rc(dcffixq)
8662 GEN_DFP_T_B_Rc(dctfix)
8663 GEN_DFP_T_B_Rc(dctfixq)
8664 GEN_DFP_T_FPR_I32_Rc(ddedpd, rB, SP)
8665 GEN_DFP_T_FPR_I32_Rc(ddedpdq, rB, SP)
8666 GEN_DFP_T_FPR_I32_Rc(denbcd, rB, SP)
8667 GEN_DFP_T_FPR_I32_Rc(denbcdq, rB, SP)
8668 GEN_DFP_T_B_Rc(dxex)
8669 GEN_DFP_T_B_Rc(dxexq)
8670 GEN_DFP_T_A_B_Rc(diex)
8671 GEN_DFP_T_A_B_Rc(diexq)
8672 GEN_DFP_T_FPR_I32_Rc(dscli, rA, DCM)
8673 GEN_DFP_T_FPR_I32_Rc(dscliq, rA, DCM)
8674 GEN_DFP_T_FPR_I32_Rc(dscri, rA, DCM)
8675 GEN_DFP_T_FPR_I32_Rc(dscriq, rA, DCM)
8677 /*** SPE extension ***/
8678 /* Register moves */
8680 static inline void gen_evmra(DisasContext *ctx)
8683 if (unlikely(!ctx->spe_enabled)) {
8684 gen_exception(ctx, POWERPC_EXCP_SPEU);
8688 TCGv_i64 tmp = tcg_temp_new_i64();
8690 /* tmp := rA_lo + rA_hi << 32 */
8691 tcg_gen_concat_tl_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8693 /* spe_acc := tmp */
8694 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
8695 tcg_temp_free_i64(tmp);
8698 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8699 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8702 static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8704 tcg_gen_concat_tl_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
8707 static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8709 tcg_gen_extr_i64_tl(cpu_gpr[reg], cpu_gprh[reg], t);
8712 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
8713 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
8715 if (Rc(ctx->opcode)) \
8721 /* Handler for undefined SPE opcodes */
8722 static inline void gen_speundef(DisasContext *ctx)
8724 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
8728 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
8729 static inline void gen_##name(DisasContext *ctx) \
8731 if (unlikely(!ctx->spe_enabled)) { \
8732 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8735 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8736 cpu_gpr[rB(ctx->opcode)]); \
8737 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8738 cpu_gprh[rB(ctx->opcode)]); \
8741 GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8742 GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8743 GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8744 GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8745 GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8746 GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8747 GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8748 GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
8750 /* SPE logic immediate */
8751 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
8752 static inline void gen_##name(DisasContext *ctx) \
8755 if (unlikely(!ctx->spe_enabled)) { \
8756 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8759 t0 = tcg_temp_new_i32(); \
8761 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8762 tcg_opi(t0, t0, rB(ctx->opcode)); \
8763 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8765 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8766 tcg_opi(t0, t0, rB(ctx->opcode)); \
8767 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8769 tcg_temp_free_i32(t0); \
8771 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8772 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8773 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8774 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
8776 /* SPE arithmetic */
8777 #define GEN_SPEOP_ARITH1(name, tcg_op) \
8778 static inline void gen_##name(DisasContext *ctx) \
8781 if (unlikely(!ctx->spe_enabled)) { \
8782 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8785 t0 = tcg_temp_new_i32(); \
8787 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8789 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8791 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8793 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8795 tcg_temp_free_i32(t0); \
8798 static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
8800 TCGLabel *l1 = gen_new_label();
8801 TCGLabel *l2 = gen_new_label();
8803 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8804 tcg_gen_neg_i32(ret, arg1);
8807 tcg_gen_mov_i32(ret, arg1);
8810 GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8811 GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8812 GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8813 GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
8814 static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
8816 tcg_gen_addi_i32(ret, arg1, 0x8000);
8817 tcg_gen_ext16u_i32(ret, ret);
8819 GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
8820 GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8821 GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
8823 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8824 static inline void gen_##name(DisasContext *ctx) \
8827 if (unlikely(!ctx->spe_enabled)) { \
8828 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8831 t0 = tcg_temp_new_i32(); \
8832 t1 = tcg_temp_new_i32(); \
8834 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8835 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8836 tcg_op(t0, t0, t1); \
8837 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8839 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8840 tcg_gen_trunc_tl_i32(t1, cpu_gprh[rB(ctx->opcode)]); \
8841 tcg_op(t0, t0, t1); \
8842 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8844 tcg_temp_free_i32(t0); \
8845 tcg_temp_free_i32(t1); \
8848 static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8850 TCGLabel *l1 = gen_new_label();
8851 TCGLabel *l2 = gen_new_label();
8852 TCGv_i32 t0 = tcg_temp_local_new_i32();
8854 /* No error here: 6 bits are used */
8855 tcg_gen_andi_i32(t0, arg2, 0x3F);
8856 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8857 tcg_gen_shr_i32(ret, arg1, t0);
8860 tcg_gen_movi_i32(ret, 0);
8862 tcg_temp_free_i32(t0);
8864 GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
8865 static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8867 TCGLabel *l1 = gen_new_label();
8868 TCGLabel *l2 = gen_new_label();
8869 TCGv_i32 t0 = tcg_temp_local_new_i32();
8871 /* No error here: 6 bits are used */
8872 tcg_gen_andi_i32(t0, arg2, 0x3F);
8873 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8874 tcg_gen_sar_i32(ret, arg1, t0);
8877 tcg_gen_movi_i32(ret, 0);
8879 tcg_temp_free_i32(t0);
8881 GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
8882 static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8884 TCGLabel *l1 = gen_new_label();
8885 TCGLabel *l2 = gen_new_label();
8886 TCGv_i32 t0 = tcg_temp_local_new_i32();
8888 /* No error here: 6 bits are used */
8889 tcg_gen_andi_i32(t0, arg2, 0x3F);
8890 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8891 tcg_gen_shl_i32(ret, arg1, t0);
8894 tcg_gen_movi_i32(ret, 0);
8896 tcg_temp_free_i32(t0);
8898 GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
8899 static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8901 TCGv_i32 t0 = tcg_temp_new_i32();
8902 tcg_gen_andi_i32(t0, arg2, 0x1F);
8903 tcg_gen_rotl_i32(ret, arg1, t0);
8904 tcg_temp_free_i32(t0);
8906 GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
8907 static inline void gen_evmergehi(DisasContext *ctx)
8909 if (unlikely(!ctx->spe_enabled)) {
8910 gen_exception(ctx, POWERPC_EXCP_SPEU);
8913 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8914 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8916 GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
8917 static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8919 tcg_gen_sub_i32(ret, arg2, arg1);
8921 GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
8923 /* SPE arithmetic immediate */
8924 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8925 static inline void gen_##name(DisasContext *ctx) \
8928 if (unlikely(!ctx->spe_enabled)) { \
8929 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8932 t0 = tcg_temp_new_i32(); \
8934 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8935 tcg_op(t0, t0, rA(ctx->opcode)); \
8936 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8938 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rB(ctx->opcode)]); \
8939 tcg_op(t0, t0, rA(ctx->opcode)); \
8940 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8942 tcg_temp_free_i32(t0); \
8944 GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8945 GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8947 /* SPE comparison */
8948 #define GEN_SPEOP_COMP(name, tcg_cond) \
8949 static inline void gen_##name(DisasContext *ctx) \
8951 if (unlikely(!ctx->spe_enabled)) { \
8952 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8955 TCGLabel *l1 = gen_new_label(); \
8956 TCGLabel *l2 = gen_new_label(); \
8957 TCGLabel *l3 = gen_new_label(); \
8958 TCGLabel *l4 = gen_new_label(); \
8960 tcg_gen_ext32s_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8961 tcg_gen_ext32s_tl(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8962 tcg_gen_ext32s_tl(cpu_gprh[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8963 tcg_gen_ext32s_tl(cpu_gprh[rB(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); \
8965 tcg_gen_brcond_tl(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8966 cpu_gpr[rB(ctx->opcode)], l1); \
8967 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
8969 gen_set_label(l1); \
8970 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8971 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8972 gen_set_label(l2); \
8973 tcg_gen_brcond_tl(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8974 cpu_gprh[rB(ctx->opcode)], l3); \
8975 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8976 ~(CRF_CH | CRF_CH_AND_CL)); \
8978 gen_set_label(l3); \
8979 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8980 CRF_CH | CRF_CH_OR_CL); \
8981 gen_set_label(l4); \
8983 GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8984 GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8985 GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8986 GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8987 GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8990 static inline void gen_brinc(DisasContext *ctx)
8992 /* Note: brinc is usable even if SPE is disabled */
8993 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8994 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8996 static inline void gen_evmergelo(DisasContext *ctx)
8998 if (unlikely(!ctx->spe_enabled)) {
8999 gen_exception(ctx, POWERPC_EXCP_SPEU);
9002 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9003 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
9005 static inline void gen_evmergehilo(DisasContext *ctx)
9007 if (unlikely(!ctx->spe_enabled)) {
9008 gen_exception(ctx, POWERPC_EXCP_SPEU);
9011 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
9012 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
9014 static inline void gen_evmergelohi(DisasContext *ctx)
9016 if (unlikely(!ctx->spe_enabled)) {
9017 gen_exception(ctx, POWERPC_EXCP_SPEU);
9020 if (rD(ctx->opcode) == rA(ctx->opcode)) {
9021 TCGv tmp = tcg_temp_new();
9022 tcg_gen_mov_tl(tmp, cpu_gpr[rA(ctx->opcode)]);
9023 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
9024 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], tmp);
9027 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
9028 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9031 static inline void gen_evsplati(DisasContext *ctx)
9033 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
9035 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
9036 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
9038 static inline void gen_evsplatfi(DisasContext *ctx)
9040 uint64_t imm = rA(ctx->opcode) << 27;
9042 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
9043 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
9046 static inline void gen_evsel(DisasContext *ctx)
9048 TCGLabel *l1 = gen_new_label();
9049 TCGLabel *l2 = gen_new_label();
9050 TCGLabel *l3 = gen_new_label();
9051 TCGLabel *l4 = gen_new_label();
9052 TCGv_i32 t0 = tcg_temp_local_new_i32();
9054 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
9055 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
9056 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
9059 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
9061 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
9062 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
9063 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9066 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
9068 tcg_temp_free_i32(t0);
9071 static void gen_evsel0(DisasContext *ctx)
9076 static void gen_evsel1(DisasContext *ctx)
9081 static void gen_evsel2(DisasContext *ctx)
9086 static void gen_evsel3(DisasContext *ctx)
9093 static inline void gen_evmwumi(DisasContext *ctx)
9097 if (unlikely(!ctx->spe_enabled)) {
9098 gen_exception(ctx, POWERPC_EXCP_SPEU);
9102 t0 = tcg_temp_new_i64();
9103 t1 = tcg_temp_new_i64();
9105 /* t0 := rA; t1 := rB */
9106 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
9107 tcg_gen_ext32u_i64(t0, t0);
9108 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9109 tcg_gen_ext32u_i64(t1, t1);
9111 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9113 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9115 tcg_temp_free_i64(t0);
9116 tcg_temp_free_i64(t1);
9119 static inline void gen_evmwumia(DisasContext *ctx)
9123 if (unlikely(!ctx->spe_enabled)) {
9124 gen_exception(ctx, POWERPC_EXCP_SPEU);
9128 gen_evmwumi(ctx); /* rD := rA * rB */
9130 tmp = tcg_temp_new_i64();
9133 gen_load_gpr64(tmp, rD(ctx->opcode));
9134 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
9135 tcg_temp_free_i64(tmp);
9138 static inline void gen_evmwumiaa(DisasContext *ctx)
9143 if (unlikely(!ctx->spe_enabled)) {
9144 gen_exception(ctx, POWERPC_EXCP_SPEU);
9148 gen_evmwumi(ctx); /* rD := rA * rB */
9150 acc = tcg_temp_new_i64();
9151 tmp = tcg_temp_new_i64();
9154 gen_load_gpr64(tmp, rD(ctx->opcode));
9157 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9159 /* acc := tmp + acc */
9160 tcg_gen_add_i64(acc, acc, tmp);
9163 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9166 gen_store_gpr64(rD(ctx->opcode), acc);
9168 tcg_temp_free_i64(acc);
9169 tcg_temp_free_i64(tmp);
9172 static inline void gen_evmwsmi(DisasContext *ctx)
9176 if (unlikely(!ctx->spe_enabled)) {
9177 gen_exception(ctx, POWERPC_EXCP_SPEU);
9181 t0 = tcg_temp_new_i64();
9182 t1 = tcg_temp_new_i64();
9184 /* t0 := rA; t1 := rB */
9185 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
9186 tcg_gen_ext32s_i64(t0, t0);
9187 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9188 tcg_gen_ext32s_i64(t1, t1);
9190 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9192 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9194 tcg_temp_free_i64(t0);
9195 tcg_temp_free_i64(t1);
9198 static inline void gen_evmwsmia(DisasContext *ctx)
9202 gen_evmwsmi(ctx); /* rD := rA * rB */
9204 tmp = tcg_temp_new_i64();
9207 gen_load_gpr64(tmp, rD(ctx->opcode));
9208 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
9210 tcg_temp_free_i64(tmp);
9213 static inline void gen_evmwsmiaa(DisasContext *ctx)
9215 TCGv_i64 acc = tcg_temp_new_i64();
9216 TCGv_i64 tmp = tcg_temp_new_i64();
9218 gen_evmwsmi(ctx); /* rD := rA * rB */
9220 acc = tcg_temp_new_i64();
9221 tmp = tcg_temp_new_i64();
9224 gen_load_gpr64(tmp, rD(ctx->opcode));
9227 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9229 /* acc := tmp + acc */
9230 tcg_gen_add_i64(acc, acc, tmp);
9233 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9236 gen_store_gpr64(rD(ctx->opcode), acc);
9238 tcg_temp_free_i64(acc);
9239 tcg_temp_free_i64(tmp);
9242 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9243 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9244 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9245 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9246 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9247 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9248 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9249 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
9250 GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
9251 GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9252 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9253 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9254 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9255 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9256 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9257 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9258 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9259 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9260 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9261 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
9262 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9263 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9264 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
9265 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
9266 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9267 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9268 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9269 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9270 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
9272 /* SPE load and stores */
9273 static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
9275 target_ulong uimm = rB(ctx->opcode);
9277 if (rA(ctx->opcode) == 0) {
9278 tcg_gen_movi_tl(EA, uimm << sh);
9280 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
9281 if (NARROW_MODE(ctx)) {
9282 tcg_gen_ext32u_tl(EA, EA);
9287 static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
9289 TCGv_i64 t0 = tcg_temp_new_i64();
9290 gen_qemu_ld64(ctx, t0, addr);
9291 gen_store_gpr64(rD(ctx->opcode), t0);
9292 tcg_temp_free_i64(t0);
9295 static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
9297 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9298 gen_addr_add(ctx, addr, addr, 4);
9299 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9302 static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
9304 TCGv t0 = tcg_temp_new();
9305 gen_qemu_ld16u(ctx, t0, addr);
9306 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9307 gen_addr_add(ctx, addr, addr, 2);
9308 gen_qemu_ld16u(ctx, t0, addr);
9309 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9310 gen_addr_add(ctx, addr, addr, 2);
9311 gen_qemu_ld16u(ctx, t0, addr);
9312 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9313 gen_addr_add(ctx, addr, addr, 2);
9314 gen_qemu_ld16u(ctx, t0, addr);
9315 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9319 static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
9321 TCGv t0 = tcg_temp_new();
9322 gen_qemu_ld16u(ctx, t0, addr);
9323 tcg_gen_shli_tl(t0, t0, 16);
9324 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9325 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9329 static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
9331 TCGv t0 = tcg_temp_new();
9332 gen_qemu_ld16u(ctx, t0, addr);
9333 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9334 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9338 static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
9340 TCGv t0 = tcg_temp_new();
9341 gen_qemu_ld16s(ctx, t0, addr);
9342 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9343 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9347 static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
9349 TCGv t0 = tcg_temp_new();
9350 gen_qemu_ld16u(ctx, t0, addr);
9351 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9352 gen_addr_add(ctx, addr, addr, 2);
9353 gen_qemu_ld16u(ctx, t0, addr);
9354 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9358 static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
9360 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9361 gen_addr_add(ctx, addr, addr, 2);
9362 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9365 static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
9367 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9368 gen_addr_add(ctx, addr, addr, 2);
9369 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9372 static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
9374 TCGv t0 = tcg_temp_new();
9375 gen_qemu_ld32u(ctx, t0, addr);
9376 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9377 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9381 static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
9383 TCGv t0 = tcg_temp_new();
9384 gen_qemu_ld16u(ctx, t0, addr);
9385 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9386 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9387 gen_addr_add(ctx, addr, addr, 2);
9388 gen_qemu_ld16u(ctx, t0, addr);
9389 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9390 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9394 static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
9396 TCGv_i64 t0 = tcg_temp_new_i64();
9397 gen_load_gpr64(t0, rS(ctx->opcode));
9398 gen_qemu_st64(ctx, t0, addr);
9399 tcg_temp_free_i64(t0);
9402 static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
9404 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9405 gen_addr_add(ctx, addr, addr, 4);
9406 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9409 static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
9411 TCGv t0 = tcg_temp_new();
9412 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9413 gen_qemu_st16(ctx, t0, addr);
9414 gen_addr_add(ctx, addr, addr, 2);
9415 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9416 gen_addr_add(ctx, addr, addr, 2);
9417 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
9418 gen_qemu_st16(ctx, t0, addr);
9420 gen_addr_add(ctx, addr, addr, 2);
9421 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9424 static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
9426 TCGv t0 = tcg_temp_new();
9427 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9428 gen_qemu_st16(ctx, t0, addr);
9429 gen_addr_add(ctx, addr, addr, 2);
9430 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
9431 gen_qemu_st16(ctx, t0, addr);
9435 static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
9437 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9438 gen_addr_add(ctx, addr, addr, 2);
9439 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9442 static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
9444 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9447 static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
9449 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9452 #define GEN_SPEOP_LDST(name, opc2, sh) \
9453 static void glue(gen_, name)(DisasContext *ctx) \
9456 if (unlikely(!ctx->spe_enabled)) { \
9457 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9460 gen_set_access_type(ctx, ACCESS_INT); \
9461 t0 = tcg_temp_new(); \
9462 if (Rc(ctx->opcode)) { \
9463 gen_addr_spe_imm_index(ctx, t0, sh); \
9465 gen_addr_reg_index(ctx, t0); \
9467 gen_op_##name(ctx, t0); \
9468 tcg_temp_free(t0); \
9471 GEN_SPEOP_LDST(evldd, 0x00, 3);
9472 GEN_SPEOP_LDST(evldw, 0x01, 3);
9473 GEN_SPEOP_LDST(evldh, 0x02, 3);
9474 GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9475 GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9476 GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9477 GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9478 GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9479 GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9480 GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9481 GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9483 GEN_SPEOP_LDST(evstdd, 0x10, 3);
9484 GEN_SPEOP_LDST(evstdw, 0x11, 3);
9485 GEN_SPEOP_LDST(evstdh, 0x12, 3);
9486 GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9487 GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9488 GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9489 GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
9491 /* Multiply and add - TODO */
9493 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9494 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9495 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9496 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9497 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9498 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9499 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9500 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9501 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9502 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9503 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9504 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9506 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9507 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9508 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9509 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9510 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9511 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9512 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9513 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9514 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9515 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9516 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9517 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9519 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9520 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9521 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9522 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9523 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9525 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9526 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9527 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9528 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9529 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9530 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9531 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9532 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9533 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9534 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9535 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9536 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9538 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9539 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9540 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9541 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9543 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9544 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9545 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9546 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9547 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9548 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9549 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9550 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9551 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9552 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9553 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9554 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9556 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9557 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9558 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9559 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9560 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9563 /*** SPE floating-point extension ***/
9564 #define GEN_SPEFPUOP_CONV_32_32(name) \
9565 static inline void gen_##name(DisasContext *ctx) \
9567 TCGv_i32 t0 = tcg_temp_new_i32(); \
9568 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9569 gen_helper_##name(t0, cpu_env, t0); \
9570 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9571 tcg_temp_free_i32(t0); \
9573 #define GEN_SPEFPUOP_CONV_32_64(name) \
9574 static inline void gen_##name(DisasContext *ctx) \
9576 TCGv_i64 t0 = tcg_temp_new_i64(); \
9577 TCGv_i32 t1 = tcg_temp_new_i32(); \
9578 gen_load_gpr64(t0, rB(ctx->opcode)); \
9579 gen_helper_##name(t1, cpu_env, t0); \
9580 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); \
9581 tcg_temp_free_i64(t0); \
9582 tcg_temp_free_i32(t1); \
9584 #define GEN_SPEFPUOP_CONV_64_32(name) \
9585 static inline void gen_##name(DisasContext *ctx) \
9587 TCGv_i64 t0 = tcg_temp_new_i64(); \
9588 TCGv_i32 t1 = tcg_temp_new_i32(); \
9589 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9590 gen_helper_##name(t0, cpu_env, t1); \
9591 gen_store_gpr64(rD(ctx->opcode), t0); \
9592 tcg_temp_free_i64(t0); \
9593 tcg_temp_free_i32(t1); \
9595 #define GEN_SPEFPUOP_CONV_64_64(name) \
9596 static inline void gen_##name(DisasContext *ctx) \
9598 TCGv_i64 t0 = tcg_temp_new_i64(); \
9599 gen_load_gpr64(t0, rB(ctx->opcode)); \
9600 gen_helper_##name(t0, cpu_env, t0); \
9601 gen_store_gpr64(rD(ctx->opcode), t0); \
9602 tcg_temp_free_i64(t0); \
9604 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9605 static inline void gen_##name(DisasContext *ctx) \
9608 if (unlikely(!ctx->spe_enabled)) { \
9609 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9612 t0 = tcg_temp_new_i32(); \
9613 t1 = tcg_temp_new_i32(); \
9614 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9615 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9616 gen_helper_##name(t0, cpu_env, t0, t1); \
9617 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9619 tcg_temp_free_i32(t0); \
9620 tcg_temp_free_i32(t1); \
9622 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9623 static inline void gen_##name(DisasContext *ctx) \
9626 if (unlikely(!ctx->spe_enabled)) { \
9627 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9630 t0 = tcg_temp_new_i64(); \
9631 t1 = tcg_temp_new_i64(); \
9632 gen_load_gpr64(t0, rA(ctx->opcode)); \
9633 gen_load_gpr64(t1, rB(ctx->opcode)); \
9634 gen_helper_##name(t0, cpu_env, t0, t1); \
9635 gen_store_gpr64(rD(ctx->opcode), t0); \
9636 tcg_temp_free_i64(t0); \
9637 tcg_temp_free_i64(t1); \
9639 #define GEN_SPEFPUOP_COMP_32(name) \
9640 static inline void gen_##name(DisasContext *ctx) \
9643 if (unlikely(!ctx->spe_enabled)) { \
9644 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9647 t0 = tcg_temp_new_i32(); \
9648 t1 = tcg_temp_new_i32(); \
9650 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9651 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9652 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9654 tcg_temp_free_i32(t0); \
9655 tcg_temp_free_i32(t1); \
9657 #define GEN_SPEFPUOP_COMP_64(name) \
9658 static inline void gen_##name(DisasContext *ctx) \
9661 if (unlikely(!ctx->spe_enabled)) { \
9662 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9665 t0 = tcg_temp_new_i64(); \
9666 t1 = tcg_temp_new_i64(); \
9667 gen_load_gpr64(t0, rA(ctx->opcode)); \
9668 gen_load_gpr64(t1, rB(ctx->opcode)); \
9669 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9670 tcg_temp_free_i64(t0); \
9671 tcg_temp_free_i64(t1); \
9674 /* Single precision floating-point vectors operations */
9676 GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9677 GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9678 GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9679 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
9680 static inline void gen_evfsabs(DisasContext *ctx)
9682 if (unlikely(!ctx->spe_enabled)) {
9683 gen_exception(ctx, POWERPC_EXCP_SPEU);
9686 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9688 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9691 static inline void gen_evfsnabs(DisasContext *ctx)
9693 if (unlikely(!ctx->spe_enabled)) {
9694 gen_exception(ctx, POWERPC_EXCP_SPEU);
9697 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9699 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9702 static inline void gen_evfsneg(DisasContext *ctx)
9704 if (unlikely(!ctx->spe_enabled)) {
9705 gen_exception(ctx, POWERPC_EXCP_SPEU);
9708 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9710 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9715 GEN_SPEFPUOP_CONV_64_64(evfscfui);
9716 GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9717 GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9718 GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9719 GEN_SPEFPUOP_CONV_64_64(evfsctui);
9720 GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9721 GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9722 GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9723 GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9724 GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9727 GEN_SPEFPUOP_COMP_64(evfscmpgt);
9728 GEN_SPEFPUOP_COMP_64(evfscmplt);
9729 GEN_SPEFPUOP_COMP_64(evfscmpeq);
9730 GEN_SPEFPUOP_COMP_64(evfststgt);
9731 GEN_SPEFPUOP_COMP_64(evfststlt);
9732 GEN_SPEFPUOP_COMP_64(evfststeq);
9734 /* Opcodes definitions */
9735 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9736 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9737 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9738 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9739 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9740 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9741 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9742 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9743 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9744 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9745 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9746 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9747 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9748 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9750 /* Single precision floating-point operations */
9752 GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9753 GEN_SPEFPUOP_ARITH2_32_32(efssub);
9754 GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9755 GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
9756 static inline void gen_efsabs(DisasContext *ctx)
9758 if (unlikely(!ctx->spe_enabled)) {
9759 gen_exception(ctx, POWERPC_EXCP_SPEU);
9762 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
9764 static inline void gen_efsnabs(DisasContext *ctx)
9766 if (unlikely(!ctx->spe_enabled)) {
9767 gen_exception(ctx, POWERPC_EXCP_SPEU);
9770 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9772 static inline void gen_efsneg(DisasContext *ctx)
9774 if (unlikely(!ctx->spe_enabled)) {
9775 gen_exception(ctx, POWERPC_EXCP_SPEU);
9778 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9782 GEN_SPEFPUOP_CONV_32_32(efscfui);
9783 GEN_SPEFPUOP_CONV_32_32(efscfsi);
9784 GEN_SPEFPUOP_CONV_32_32(efscfuf);
9785 GEN_SPEFPUOP_CONV_32_32(efscfsf);
9786 GEN_SPEFPUOP_CONV_32_32(efsctui);
9787 GEN_SPEFPUOP_CONV_32_32(efsctsi);
9788 GEN_SPEFPUOP_CONV_32_32(efsctuf);
9789 GEN_SPEFPUOP_CONV_32_32(efsctsf);
9790 GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9791 GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9792 GEN_SPEFPUOP_CONV_32_64(efscfd);
9795 GEN_SPEFPUOP_COMP_32(efscmpgt);
9796 GEN_SPEFPUOP_COMP_32(efscmplt);
9797 GEN_SPEFPUOP_COMP_32(efscmpeq);
9798 GEN_SPEFPUOP_COMP_32(efststgt);
9799 GEN_SPEFPUOP_COMP_32(efststlt);
9800 GEN_SPEFPUOP_COMP_32(efststeq);
9802 /* Opcodes definitions */
9803 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9804 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9805 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9806 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9807 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9808 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9809 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9810 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9811 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9812 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9813 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9814 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9815 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9816 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9818 /* Double precision floating-point operations */
9820 GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9821 GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9822 GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9823 GEN_SPEFPUOP_ARITH2_64_64(efddiv);
9824 static inline void gen_efdabs(DisasContext *ctx)
9826 if (unlikely(!ctx->spe_enabled)) {
9827 gen_exception(ctx, POWERPC_EXCP_SPEU);
9830 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9831 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9834 static inline void gen_efdnabs(DisasContext *ctx)
9836 if (unlikely(!ctx->spe_enabled)) {
9837 gen_exception(ctx, POWERPC_EXCP_SPEU);
9840 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9841 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9844 static inline void gen_efdneg(DisasContext *ctx)
9846 if (unlikely(!ctx->spe_enabled)) {
9847 gen_exception(ctx, POWERPC_EXCP_SPEU);
9850 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9851 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9856 GEN_SPEFPUOP_CONV_64_32(efdcfui);
9857 GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9858 GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9859 GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9860 GEN_SPEFPUOP_CONV_32_64(efdctui);
9861 GEN_SPEFPUOP_CONV_32_64(efdctsi);
9862 GEN_SPEFPUOP_CONV_32_64(efdctuf);
9863 GEN_SPEFPUOP_CONV_32_64(efdctsf);
9864 GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9865 GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9866 GEN_SPEFPUOP_CONV_64_32(efdcfs);
9867 GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9868 GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9869 GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9870 GEN_SPEFPUOP_CONV_64_64(efdctsidz);
9873 GEN_SPEFPUOP_COMP_64(efdcmpgt);
9874 GEN_SPEFPUOP_COMP_64(efdcmplt);
9875 GEN_SPEFPUOP_COMP_64(efdcmpeq);
9876 GEN_SPEFPUOP_COMP_64(efdtstgt);
9877 GEN_SPEFPUOP_COMP_64(efdtstlt);
9878 GEN_SPEFPUOP_COMP_64(efdtsteq);
9880 /* Opcodes definitions */
9881 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9882 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9883 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9884 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9885 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9886 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9887 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9888 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9889 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9890 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9891 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9892 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9893 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9894 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9895 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9896 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9898 static void gen_tbegin(DisasContext *ctx)
9900 if (unlikely(!ctx->tm_enabled)) {
9901 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM);
9904 gen_helper_tbegin(cpu_env);
9907 #define GEN_TM_NOOP(name) \
9908 static inline void gen_##name(DisasContext *ctx) \
9910 if (unlikely(!ctx->tm_enabled)) { \
9911 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9914 /* Because tbegin always fails in QEMU, these user \
9915 * space instructions all have a simple implementation: \
9917 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9918 * = 0b0 || 0b00 || 0b0 \
9920 tcg_gen_movi_i32(cpu_crf[0], 0); \
9924 GEN_TM_NOOP(tabort);
9925 GEN_TM_NOOP(tabortwc);
9926 GEN_TM_NOOP(tabortwci);
9927 GEN_TM_NOOP(tabortdc);
9928 GEN_TM_NOOP(tabortdci);
9931 static void gen_tcheck(DisasContext *ctx)
9933 if (unlikely(!ctx->tm_enabled)) {
9934 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM);
9937 /* Because tbegin always fails, the tcheck implementation
9940 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
9941 * = 0b1 || 0b00 || 0b0
9943 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0x8);
9946 #if defined(CONFIG_USER_ONLY)
9947 #define GEN_TM_PRIV_NOOP(name) \
9948 static inline void gen_##name(DisasContext *ctx) \
9950 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9955 #define GEN_TM_PRIV_NOOP(name) \
9956 static inline void gen_##name(DisasContext *ctx) \
9959 if (unlikely(!ctx->tm_enabled)) { \
9960 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9963 /* Because tbegin always fails, the implementation is \
9966 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9967 * = 0b0 || 0b00 | 0b0 \
9969 tcg_gen_movi_i32(cpu_crf[0], 0); \
9974 GEN_TM_PRIV_NOOP(treclaim);
9975 GEN_TM_PRIV_NOOP(trechkpt);
9977 static opcode_t opcodes[] = {
9978 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9979 GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9980 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9981 GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9982 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9983 GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
9984 GEN_HANDLER_E(cmprb, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE, PPC2_ISA300),
9985 GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9986 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9987 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9988 GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9989 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9990 GEN_HANDLER_E(addpcis, 0x13, 0x2, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA300),
9991 GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9992 GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9993 GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9994 GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9995 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9996 #if defined(TARGET_PPC64)
9997 GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9999 GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
10000 GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
10001 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10002 GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10003 GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10004 GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
10005 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
10006 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
10007 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10008 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10009 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10010 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10011 GEN_HANDLER(popcntb, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB),
10012 GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
10013 GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
10014 #if defined(TARGET_PPC64)
10015 GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
10016 GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
10017 GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
10018 GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
10020 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10021 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10022 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10023 GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
10024 GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
10025 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
10026 GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
10027 #if defined(TARGET_PPC64)
10028 GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
10029 GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
10030 GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
10031 GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
10032 GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
10034 GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
10035 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
10036 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
10037 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
10038 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
10039 GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
10040 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
10041 GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
10042 GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
10043 GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
10044 GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
10045 GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
10046 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
10047 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
10048 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
10049 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
10050 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
10051 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
10052 #if defined(TARGET_PPC64)
10053 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
10054 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
10055 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
10057 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10058 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10059 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
10060 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
10061 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
10062 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
10063 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
10064 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
10065 GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10066 GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10067 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
10068 GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10069 GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10070 GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
10071 #if defined(TARGET_PPC64)
10072 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
10073 GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
10074 GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
10075 GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
10077 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
10078 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
10079 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10080 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10081 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
10082 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
10083 GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
10084 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
10085 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
10086 #if defined(TARGET_PPC64)
10087 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
10088 GEN_HANDLER_E(doze, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE, PPC2_PM_ISA206),
10089 GEN_HANDLER_E(nap, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE, PPC2_PM_ISA206),
10090 GEN_HANDLER_E(sleep, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE, PPC2_PM_ISA206),
10091 GEN_HANDLER_E(rvwinkle, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE, PPC2_PM_ISA206),
10092 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
10094 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
10095 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
10096 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10097 #if defined(TARGET_PPC64)
10098 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
10099 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
10101 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
10102 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
10103 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
10104 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
10105 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
10106 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
10107 #if defined(TARGET_PPC64)
10108 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
10110 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC),
10111 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC),
10112 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
10113 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
10114 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
10115 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
10116 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
10117 GEN_HANDLER_E(dcbtls, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE, PPC2_BOOKE206),
10118 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
10119 GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
10120 GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
10121 GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
10122 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
10123 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
10124 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
10125 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
10126 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
10127 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
10128 #if defined(TARGET_PPC64)
10129 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
10130 GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
10132 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
10133 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
10135 GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
10136 GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
10137 GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
10138 GEN_HANDLER2(slbfee_, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F0000, PPC_SEGMENT_64B),
10140 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
10141 /* XXX Those instructions will need to be handled differently for
10142 * different ISA versions */
10143 GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE),
10144 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE),
10145 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
10146 #if defined(TARGET_PPC64)
10147 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI),
10148 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
10150 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
10151 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
10152 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
10153 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
10154 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
10155 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
10156 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
10157 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
10158 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
10159 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
10160 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
10161 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10162 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
10163 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
10164 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
10165 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
10166 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
10167 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
10168 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
10169 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10170 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
10171 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
10172 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
10173 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
10174 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
10175 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
10176 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
10177 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
10178 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
10179 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
10180 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
10181 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
10182 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
10183 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
10184 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
10185 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
10186 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
10187 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
10188 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
10189 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
10190 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
10191 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
10192 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
10193 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
10194 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
10195 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
10196 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
10197 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
10198 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
10199 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10200 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10201 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
10202 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
10203 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10204 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10205 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
10206 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
10207 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
10208 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
10209 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
10210 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
10211 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
10212 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
10213 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
10214 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
10215 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
10216 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
10217 GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
10218 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
10219 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
10220 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
10221 GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
10222 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
10223 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
10224 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
10225 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
10226 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
10227 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
10228 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
10229 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
10230 GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10231 PPC_NONE, PPC2_BOOKE206),
10232 GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10233 PPC_NONE, PPC2_BOOKE206),
10234 GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10235 PPC_NONE, PPC2_BOOKE206),
10236 GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10237 PPC_NONE, PPC2_BOOKE206),
10238 GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10239 PPC_NONE, PPC2_BOOKE206),
10240 GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10241 PPC_NONE, PPC2_PRCNTL),
10242 GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10243 PPC_NONE, PPC2_PRCNTL),
10244 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
10245 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
10246 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
10247 GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
10248 PPC_BOOKE, PPC2_BOOKE206),
10249 GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
10250 GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10251 PPC_BOOKE, PPC2_BOOKE206),
10252 GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
10253 GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
10254 GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
10255 GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
10256 GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
10257 GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
10258 GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
10259 GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
10260 GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
10262 #undef GEN_INT_ARITH_ADD
10263 #undef GEN_INT_ARITH_ADD_CONST
10264 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10265 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10266 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10267 add_ca, compute_ca, compute_ov) \
10268 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10269 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
10270 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
10271 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
10272 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
10273 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
10274 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
10275 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
10276 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
10277 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
10278 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
10280 #undef GEN_INT_ARITH_DIVW
10281 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10282 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10283 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
10284 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
10285 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
10286 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
10287 GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10288 GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10289 GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10290 GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10291 GEN_HANDLER_E(modsw, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE, PPC2_ISA300),
10292 GEN_HANDLER_E(moduw, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE, PPC2_ISA300),
10294 #if defined(TARGET_PPC64)
10295 #undef GEN_INT_ARITH_DIVD
10296 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10297 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10298 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
10299 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
10300 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
10301 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
10303 GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10304 GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10305 GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10306 GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10308 #undef GEN_INT_ARITH_MUL_HELPER
10309 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10310 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10311 GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
10312 GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
10313 GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
10316 #undef GEN_INT_ARITH_SUBF
10317 #undef GEN_INT_ARITH_SUBF_CONST
10318 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10319 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10320 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10321 add_ca, compute_ca, compute_ov) \
10322 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10323 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
10324 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
10325 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
10326 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
10327 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
10328 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
10329 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
10330 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
10331 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
10332 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
10334 #undef GEN_LOGICAL1
10335 #undef GEN_LOGICAL2
10336 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
10337 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10338 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
10339 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10340 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10341 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10342 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10343 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10344 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10345 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10346 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10347 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10348 #if defined(TARGET_PPC64)
10349 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10352 #if defined(TARGET_PPC64)
10353 #undef GEN_PPC64_R2
10354 #undef GEN_PPC64_R4
10355 #define GEN_PPC64_R2(name, opc1, opc2) \
10356 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10357 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10359 #define GEN_PPC64_R4(name, opc1, opc2) \
10360 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10361 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10363 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10365 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10367 GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10368 GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10369 GEN_PPC64_R4(rldic, 0x1E, 0x04),
10370 GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10371 GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10372 GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10375 #undef _GEN_FLOAT_ACB
10376 #undef GEN_FLOAT_ACB
10377 #undef _GEN_FLOAT_AB
10378 #undef GEN_FLOAT_AB
10379 #undef _GEN_FLOAT_AC
10380 #undef GEN_FLOAT_AC
10382 #undef GEN_FLOAT_BS
10383 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10384 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10385 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10386 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10387 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10388 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10389 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10390 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10391 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10392 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10393 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10394 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10395 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10396 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10397 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10398 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10399 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10400 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10401 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10403 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10404 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10405 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10406 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10407 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10408 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10409 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10410 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10411 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10412 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10413 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10414 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
10415 GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
10416 GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
10417 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
10418 GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10419 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
10420 GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10421 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
10422 GEN_HANDLER_E(fcfid, 0x3F, 0x0E, 0x1A, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
10423 GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10424 GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10425 GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10426 GEN_HANDLER_E(fctid, 0x3F, 0x0E, 0x19, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
10427 GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10428 GEN_HANDLER_E(fctidz, 0x3F, 0x0F, 0x19, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
10429 GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10430 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10431 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10432 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10433 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
10440 #define GEN_LD(name, ldop, opc, type) \
10441 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10442 #define GEN_LDU(name, ldop, opc, type) \
10443 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10444 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
10445 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10446 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
10447 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10448 #define GEN_LDS(name, ldop, op, type) \
10449 GEN_LD(name, ldop, op | 0x20, type) \
10450 GEN_LDU(name, ldop, op | 0x21, type) \
10451 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10452 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10454 GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10455 GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10456 GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10457 GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10458 #if defined(TARGET_PPC64)
10459 GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10460 GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10461 GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10462 GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
10463 GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX, CHK_NONE)
10465 /* HV/P7 and later only */
10466 GEN_LDX_HVRM(ldcix, ld64, 0x15, 0x1b, PPC_CILDST)
10467 GEN_LDX_HVRM(lwzcix, ld32u, 0x15, 0x18, PPC_CILDST)
10468 GEN_LDX_HVRM(lhzcix, ld16u, 0x15, 0x19, PPC_CILDST)
10469 GEN_LDX_HVRM(lbzcix, ld8u, 0x15, 0x1a, PPC_CILDST)
10471 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10472 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10479 #define GEN_ST(name, stop, opc, type) \
10480 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10481 #define GEN_STU(name, stop, opc, type) \
10482 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10483 #define GEN_STUX(name, stop, opc2, opc3, type) \
10484 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10485 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
10486 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10487 #define GEN_STS(name, stop, op, type) \
10488 GEN_ST(name, stop, op | 0x20, type) \
10489 GEN_STU(name, stop, op | 0x21, type) \
10490 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10491 GEN_STX(name, stop, 0x17, op | 0x00, type)
10493 GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10494 GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10495 GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10496 #if defined(TARGET_PPC64)
10497 GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10498 GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
10499 GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX, CHK_NONE)
10500 GEN_STX_HVRM(stdcix, st64, 0x15, 0x1f, PPC_CILDST)
10501 GEN_STX_HVRM(stwcix, st32, 0x15, 0x1c, PPC_CILDST)
10502 GEN_STX_HVRM(sthcix, st16, 0x15, 0x1d, PPC_CILDST)
10503 GEN_STX_HVRM(stbcix, st8, 0x15, 0x1e, PPC_CILDST)
10505 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10506 GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10513 #define GEN_LDF(name, ldop, opc, type) \
10514 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10515 #define GEN_LDUF(name, ldop, opc, type) \
10516 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10517 #define GEN_LDUXF(name, ldop, opc, type) \
10518 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10519 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
10520 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10521 #define GEN_LDFS(name, ldop, op, type) \
10522 GEN_LDF(name, ldop, op | 0x20, type) \
10523 GEN_LDUF(name, ldop, op | 0x21, type) \
10524 GEN_LDUXF(name, ldop, op | 0x01, type) \
10525 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10527 GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10528 GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
10529 GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
10530 GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
10531 GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10532 GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
10539 #define GEN_STF(name, stop, opc, type) \
10540 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10541 #define GEN_STUF(name, stop, opc, type) \
10542 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10543 #define GEN_STUXF(name, stop, opc, type) \
10544 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10545 #define GEN_STXF(name, stop, opc2, opc3, type) \
10546 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10547 #define GEN_STFS(name, stop, op, type) \
10548 GEN_STF(name, stop, op | 0x20, type) \
10549 GEN_STUF(name, stop, op | 0x21, type) \
10550 GEN_STUXF(name, stop, op | 0x01, type) \
10551 GEN_STXF(name, stop, 0x17, op | 0x00, type)
10553 GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10554 GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10555 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
10556 GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10557 GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
10560 #define GEN_CRLOGIC(name, tcg_op, opc) \
10561 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10562 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10563 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10564 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10565 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10566 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10567 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10568 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10569 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10571 #undef GEN_MAC_HANDLER
10572 #define GEN_MAC_HANDLER(name, opc2, opc3) \
10573 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10574 GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10575 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10576 GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10577 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10578 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10579 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10580 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10581 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10582 GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10583 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10584 GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10585 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10586 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10587 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10588 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10589 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10590 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10591 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10592 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10593 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10594 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10595 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10596 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10597 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10598 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10599 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10600 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10601 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10602 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10603 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10604 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10605 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10606 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10607 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10608 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10609 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10610 GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10611 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10612 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10613 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10614 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10615 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10621 #define GEN_VR_LDX(name, opc2, opc3) \
10622 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10623 #define GEN_VR_STX(name, opc2, opc3) \
10624 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10625 #define GEN_VR_LVE(name, opc2, opc3) \
10626 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10627 #define GEN_VR_STVE(name, opc2, opc3) \
10628 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10629 GEN_VR_LDX(lvx, 0x07, 0x03),
10630 GEN_VR_LDX(lvxl, 0x07, 0x0B),
10631 GEN_VR_LVE(bx, 0x07, 0x00),
10632 GEN_VR_LVE(hx, 0x07, 0x01),
10633 GEN_VR_LVE(wx, 0x07, 0x02),
10634 GEN_VR_STX(svx, 0x07, 0x07),
10635 GEN_VR_STX(svxl, 0x07, 0x0F),
10636 GEN_VR_STVE(bx, 0x07, 0x04),
10637 GEN_VR_STVE(hx, 0x07, 0x05),
10638 GEN_VR_STVE(wx, 0x07, 0x06),
10640 #undef GEN_VX_LOGICAL
10641 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10642 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10644 #undef GEN_VX_LOGICAL_207
10645 #define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10646 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10648 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10649 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10650 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10651 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10652 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
10653 GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10654 GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10655 GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
10658 #define GEN_VXFORM(name, opc2, opc3) \
10659 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10661 #undef GEN_VXFORM_207
10662 #define GEN_VXFORM_207(name, opc2, opc3) \
10663 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10665 #undef GEN_VXFORM_DUAL
10666 #define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10667 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10669 #undef GEN_VXRFORM_DUAL
10670 #define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10671 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10672 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10674 GEN_VXFORM(vaddubm, 0, 0),
10675 GEN_VXFORM(vadduhm, 0, 1),
10676 GEN_VXFORM(vadduwm, 0, 2),
10677 GEN_VXFORM_207(vaddudm, 0, 3),
10678 GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10679 GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
10680 GEN_VXFORM(vsubuwm, 0, 18),
10681 GEN_VXFORM_207(vsubudm, 0, 19),
10682 GEN_VXFORM(vmaxub, 1, 0),
10683 GEN_VXFORM(vmaxuh, 1, 1),
10684 GEN_VXFORM(vmaxuw, 1, 2),
10685 GEN_VXFORM_207(vmaxud, 1, 3),
10686 GEN_VXFORM(vmaxsb, 1, 4),
10687 GEN_VXFORM(vmaxsh, 1, 5),
10688 GEN_VXFORM(vmaxsw, 1, 6),
10689 GEN_VXFORM_207(vmaxsd, 1, 7),
10690 GEN_VXFORM(vminub, 1, 8),
10691 GEN_VXFORM(vminuh, 1, 9),
10692 GEN_VXFORM(vminuw, 1, 10),
10693 GEN_VXFORM_207(vminud, 1, 11),
10694 GEN_VXFORM(vminsb, 1, 12),
10695 GEN_VXFORM(vminsh, 1, 13),
10696 GEN_VXFORM(vminsw, 1, 14),
10697 GEN_VXFORM_207(vminsd, 1, 15),
10698 GEN_VXFORM(vavgub, 1, 16),
10699 GEN_VXFORM(vavguh, 1, 17),
10700 GEN_VXFORM(vavguw, 1, 18),
10701 GEN_VXFORM(vavgsb, 1, 20),
10702 GEN_VXFORM(vavgsh, 1, 21),
10703 GEN_VXFORM(vavgsw, 1, 22),
10704 GEN_VXFORM(vmrghb, 6, 0),
10705 GEN_VXFORM(vmrghh, 6, 1),
10706 GEN_VXFORM(vmrghw, 6, 2),
10707 GEN_VXFORM(vmrglb, 6, 4),
10708 GEN_VXFORM(vmrglh, 6, 5),
10709 GEN_VXFORM(vmrglw, 6, 6),
10710 GEN_VXFORM_207(vmrgew, 6, 30),
10711 GEN_VXFORM_207(vmrgow, 6, 26),
10712 GEN_VXFORM(vmuloub, 4, 0),
10713 GEN_VXFORM(vmulouh, 4, 1),
10714 GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
10715 GEN_VXFORM(vmulosb, 4, 4),
10716 GEN_VXFORM(vmulosh, 4, 5),
10717 GEN_VXFORM_207(vmulosw, 4, 6),
10718 GEN_VXFORM(vmuleub, 4, 8),
10719 GEN_VXFORM(vmuleuh, 4, 9),
10720 GEN_VXFORM_207(vmuleuw, 4, 10),
10721 GEN_VXFORM(vmulesb, 4, 12),
10722 GEN_VXFORM(vmulesh, 4, 13),
10723 GEN_VXFORM_207(vmulesw, 4, 14),
10724 GEN_VXFORM(vslb, 2, 4),
10725 GEN_VXFORM(vslh, 2, 5),
10726 GEN_VXFORM(vslw, 2, 6),
10727 GEN_VXFORM_207(vsld, 2, 23),
10728 GEN_VXFORM(vsrb, 2, 8),
10729 GEN_VXFORM(vsrh, 2, 9),
10730 GEN_VXFORM(vsrw, 2, 10),
10731 GEN_VXFORM_207(vsrd, 2, 27),
10732 GEN_VXFORM(vsrab, 2, 12),
10733 GEN_VXFORM(vsrah, 2, 13),
10734 GEN_VXFORM(vsraw, 2, 14),
10735 GEN_VXFORM_207(vsrad, 2, 15),
10736 GEN_VXFORM(vslo, 6, 16),
10737 GEN_VXFORM(vsro, 6, 17),
10738 GEN_VXFORM(vaddcuw, 0, 6),
10739 GEN_VXFORM(vsubcuw, 0, 22),
10740 GEN_VXFORM(vaddubs, 0, 8),
10741 GEN_VXFORM(vadduhs, 0, 9),
10742 GEN_VXFORM(vadduws, 0, 10),
10743 GEN_VXFORM(vaddsbs, 0, 12),
10744 GEN_VXFORM(vaddshs, 0, 13),
10745 GEN_VXFORM(vaddsws, 0, 14),
10746 GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10747 GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
10748 GEN_VXFORM(vsubuws, 0, 26),
10749 GEN_VXFORM(vsubsbs, 0, 28),
10750 GEN_VXFORM(vsubshs, 0, 29),
10751 GEN_VXFORM(vsubsws, 0, 30),
10752 GEN_VXFORM_207(vadduqm, 0, 4),
10753 GEN_VXFORM_207(vaddcuq, 0, 5),
10754 GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10755 GEN_VXFORM_207(vsubuqm, 0, 20),
10756 GEN_VXFORM_207(vsubcuq, 0, 21),
10757 GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10758 GEN_VXFORM(vrlb, 2, 0),
10759 GEN_VXFORM(vrlh, 2, 1),
10760 GEN_VXFORM(vrlw, 2, 2),
10761 GEN_VXFORM_207(vrld, 2, 3),
10762 GEN_VXFORM(vsl, 2, 7),
10763 GEN_VXFORM(vsr, 2, 11),
10764 GEN_VXFORM(vpkuhum, 7, 0),
10765 GEN_VXFORM(vpkuwum, 7, 1),
10766 GEN_VXFORM_207(vpkudum, 7, 17),
10767 GEN_VXFORM(vpkuhus, 7, 2),
10768 GEN_VXFORM(vpkuwus, 7, 3),
10769 GEN_VXFORM_207(vpkudus, 7, 19),
10770 GEN_VXFORM(vpkshus, 7, 4),
10771 GEN_VXFORM(vpkswus, 7, 5),
10772 GEN_VXFORM_207(vpksdus, 7, 21),
10773 GEN_VXFORM(vpkshss, 7, 6),
10774 GEN_VXFORM(vpkswss, 7, 7),
10775 GEN_VXFORM_207(vpksdss, 7, 23),
10776 GEN_VXFORM(vpkpx, 7, 12),
10777 GEN_VXFORM(vsum4ubs, 4, 24),
10778 GEN_VXFORM(vsum4sbs, 4, 28),
10779 GEN_VXFORM(vsum4shs, 4, 25),
10780 GEN_VXFORM(vsum2sws, 4, 26),
10781 GEN_VXFORM(vsumsws, 4, 30),
10782 GEN_VXFORM(vaddfp, 5, 0),
10783 GEN_VXFORM(vsubfp, 5, 1),
10784 GEN_VXFORM(vmaxfp, 5, 16),
10785 GEN_VXFORM(vminfp, 5, 17),
10787 #undef GEN_VXRFORM1
10789 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10790 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10791 #define GEN_VXRFORM(name, opc2, opc3) \
10792 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10793 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10794 GEN_VXRFORM(vcmpequb, 3, 0)
10795 GEN_VXRFORM(vcmpequh, 3, 1)
10796 GEN_VXRFORM(vcmpequw, 3, 2)
10797 GEN_VXRFORM(vcmpgtsb, 3, 12)
10798 GEN_VXRFORM(vcmpgtsh, 3, 13)
10799 GEN_VXRFORM(vcmpgtsw, 3, 14)
10800 GEN_VXRFORM(vcmpgtub, 3, 8)
10801 GEN_VXRFORM(vcmpgtuh, 3, 9)
10802 GEN_VXRFORM(vcmpgtuw, 3, 10)
10803 GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
10804 GEN_VXRFORM(vcmpgefp, 3, 7)
10805 GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10806 GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
10808 #undef GEN_VXFORM_SIMM
10809 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
10810 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10811 GEN_VXFORM_SIMM(vspltisb, 6, 12),
10812 GEN_VXFORM_SIMM(vspltish, 6, 13),
10813 GEN_VXFORM_SIMM(vspltisw, 6, 14),
10815 #undef GEN_VXFORM_NOA
10816 #define GEN_VXFORM_NOA(name, opc2, opc3) \
10817 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10818 GEN_VXFORM_NOA(vupkhsb, 7, 8),
10819 GEN_VXFORM_NOA(vupkhsh, 7, 9),
10820 GEN_VXFORM_207(vupkhsw, 7, 25),
10821 GEN_VXFORM_NOA(vupklsb, 7, 10),
10822 GEN_VXFORM_NOA(vupklsh, 7, 11),
10823 GEN_VXFORM_207(vupklsw, 7, 27),
10824 GEN_VXFORM_NOA(vupkhpx, 7, 13),
10825 GEN_VXFORM_NOA(vupklpx, 7, 15),
10826 GEN_VXFORM_NOA(vrefp, 5, 4),
10827 GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
10828 GEN_VXFORM_NOA(vexptefp, 5, 6),
10829 GEN_VXFORM_NOA(vlogefp, 5, 7),
10830 GEN_VXFORM_NOA(vrfim, 5, 11),
10831 GEN_VXFORM_NOA(vrfin, 5, 8),
10832 GEN_VXFORM_NOA(vrfip, 5, 10),
10833 GEN_VXFORM_NOA(vrfiz, 5, 9),
10835 #undef GEN_VXFORM_UIMM
10836 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
10837 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10838 GEN_VXFORM_UIMM(vspltb, 6, 8),
10839 GEN_VXFORM_UIMM(vsplth, 6, 9),
10840 GEN_VXFORM_UIMM(vspltw, 6, 10),
10841 GEN_VXFORM_UIMM(vcfux, 5, 12),
10842 GEN_VXFORM_UIMM(vcfsx, 5, 13),
10843 GEN_VXFORM_UIMM(vctuxs, 5, 14),
10844 GEN_VXFORM_UIMM(vctsxs, 5, 15),
10846 #undef GEN_VAFORM_PAIRED
10847 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10848 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10849 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10850 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10851 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10852 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10853 GEN_VAFORM_PAIRED(vsel, vperm, 21),
10854 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10856 GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10857 GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10858 GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10859 GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10861 GEN_VXFORM_207(vbpermq, 6, 21),
10862 GEN_VXFORM_207(vgbbd, 6, 20),
10863 GEN_VXFORM_207(vpmsumb, 4, 16),
10864 GEN_VXFORM_207(vpmsumh, 4, 17),
10865 GEN_VXFORM_207(vpmsumw, 4, 18),
10866 GEN_VXFORM_207(vpmsumd, 4, 19),
10868 GEN_VXFORM_207(vsbox, 4, 23),
10870 GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10871 GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10873 GEN_VXFORM_207(vshasigmaw, 1, 26),
10874 GEN_VXFORM_207(vshasigmad, 1, 27),
10876 GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10878 GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
10879 GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10880 GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10881 GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
10882 GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
10883 GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
10884 GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
10886 GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
10887 GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10888 GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
10889 GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
10890 GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
10892 GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10893 GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10894 GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10895 #if defined(TARGET_PPC64)
10896 GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10897 GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10901 #define GEN_XX2FORM(name, opc2, opc3, fl2) \
10902 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10903 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10906 #define GEN_XX3FORM(name, opc2, opc3, fl2) \
10907 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10908 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10909 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10910 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10912 #undef GEN_XX2IFORM
10913 #define GEN_XX2IFORM(name, opc2, opc3, fl2) \
10914 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 1, PPC_NONE, fl2), \
10915 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 1, PPC_NONE, fl2), \
10916 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 1, PPC_NONE, fl2), \
10917 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 1, PPC_NONE, fl2)
10919 #undef GEN_XX3_RC_FORM
10920 #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10921 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10922 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10923 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10924 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10925 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10926 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10927 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10928 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10930 #undef GEN_XX3FORM_DM
10931 #define GEN_XX3FORM_DM(name, opc2, opc3) \
10932 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10933 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10934 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10935 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10936 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10937 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10938 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10939 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10940 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10941 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10942 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10943 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10944 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10945 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10946 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10947 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10949 GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10950 GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10951 GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10952 GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10954 GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10955 GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10956 GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10957 GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10958 GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10959 GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10960 GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10961 GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
10963 GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10964 GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
10965 GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
10966 GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
10967 GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
10968 GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
10969 GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
10970 GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
10971 GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
10972 GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10973 GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10974 GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10975 GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10976 GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10977 GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10978 GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10979 GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
10980 GEN_XX2IFORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10981 GEN_XX2IFORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
10982 GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10983 GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
10984 GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
10985 GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
10986 GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
10987 GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
10988 GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10989 GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10990 GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10991 GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10992 GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10993 GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
10994 GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10995 GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10996 GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10997 GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10998 GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
11000 GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
11001 GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
11002 GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
11003 GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
11004 GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
11005 GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
11006 GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
11007 GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
11008 GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
11009 GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
11010 GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
11011 GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
11012 GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
11013 GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
11014 GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
11015 GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
11016 GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
11017 GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
11019 GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
11020 GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
11021 GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
11022 GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
11023 GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
11024 GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
11025 GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
11026 GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
11027 GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
11028 GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
11029 GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
11030 GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
11031 GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
11032 GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
11033 GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
11034 GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
11035 GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
11036 GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
11037 GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
11038 GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
11039 GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
11040 GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
11041 GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
11042 GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
11043 GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
11044 GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
11045 GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
11046 GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
11047 GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
11048 GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
11049 GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
11050 GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
11051 GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
11052 GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
11053 GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
11054 GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
11056 GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
11057 GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
11058 GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
11059 GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
11060 GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
11061 GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
11062 GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
11063 GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
11064 GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
11065 GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
11066 GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
11067 GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
11068 GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
11069 GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
11070 GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
11071 GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
11072 GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
11073 GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
11074 GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
11075 GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
11076 GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
11077 GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
11078 GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
11079 GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
11080 GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
11081 GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
11082 GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
11083 GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
11084 GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
11085 GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
11086 GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
11087 GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
11088 GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
11089 GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
11090 GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
11091 GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
11094 #define VSX_LOGICAL(name, opc2, opc3, fl2) \
11095 GEN_XX3FORM(name, opc2, opc3, fl2)
11097 VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
11098 VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
11099 VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
11100 VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
11101 VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
11102 VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
11103 VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
11104 VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
11105 GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
11106 GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
11107 GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
11108 GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
11110 #define GEN_XXSEL_ROW(opc3) \
11111 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
11112 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
11113 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
11114 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
11115 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
11116 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
11117 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
11118 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
11120 GEN_XXSEL_ROW(0x00)
11121 GEN_XXSEL_ROW(0x01)
11122 GEN_XXSEL_ROW(0x02)
11123 GEN_XXSEL_ROW(0x03)
11124 GEN_XXSEL_ROW(0x04)
11125 GEN_XXSEL_ROW(0x05)
11126 GEN_XXSEL_ROW(0x06)
11127 GEN_XXSEL_ROW(0x07)
11128 GEN_XXSEL_ROW(0x08)
11129 GEN_XXSEL_ROW(0x09)
11130 GEN_XXSEL_ROW(0x0A)
11131 GEN_XXSEL_ROW(0x0B)
11132 GEN_XXSEL_ROW(0x0C)
11133 GEN_XXSEL_ROW(0x0D)
11134 GEN_XXSEL_ROW(0x0E)
11135 GEN_XXSEL_ROW(0x0F)
11136 GEN_XXSEL_ROW(0x10)
11137 GEN_XXSEL_ROW(0x11)
11138 GEN_XXSEL_ROW(0x12)
11139 GEN_XXSEL_ROW(0x13)
11140 GEN_XXSEL_ROW(0x14)
11141 GEN_XXSEL_ROW(0x15)
11142 GEN_XXSEL_ROW(0x16)
11143 GEN_XXSEL_ROW(0x17)
11144 GEN_XXSEL_ROW(0x18)
11145 GEN_XXSEL_ROW(0x19)
11146 GEN_XXSEL_ROW(0x1A)
11147 GEN_XXSEL_ROW(0x1B)
11148 GEN_XXSEL_ROW(0x1C)
11149 GEN_XXSEL_ROW(0x1D)
11150 GEN_XXSEL_ROW(0x1E)
11151 GEN_XXSEL_ROW(0x1F)
11153 GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
11155 #undef GEN_DFP_T_A_B_Rc
11156 #undef GEN_DFP_BF_A_B
11157 #undef GEN_DFP_BF_A_DCM
11158 #undef GEN_DFP_T_B_U32_U32_Rc
11159 #undef GEN_DFP_T_A_B_I32_Rc
11160 #undef GEN_DFP_T_B_Rc
11161 #undef GEN_DFP_T_FPR_I32_Rc
11163 #define _GEN_DFP_LONG(name, op1, op2, mask) \
11164 GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
11166 #define _GEN_DFP_LONGx2(name, op1, op2, mask) \
11167 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11168 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
11170 #define _GEN_DFP_LONGx4(name, op1, op2, mask) \
11171 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11172 GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
11173 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
11174 GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
11176 #define _GEN_DFP_QUAD(name, op1, op2, mask) \
11177 GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
11179 #define _GEN_DFP_QUADx2(name, op1, op2, mask) \
11180 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11181 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
11183 #define _GEN_DFP_QUADx4(name, op1, op2, mask) \
11184 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11185 GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
11186 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
11187 GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
11189 #define GEN_DFP_T_A_B_Rc(name, op1, op2) \
11190 _GEN_DFP_LONG(name, op1, op2, 0x00000000)
11192 #define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
11193 _GEN_DFP_QUAD(name, op1, op2, 0x00210800)
11195 #define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
11196 _GEN_DFP_QUAD(name, op1, op2, 0x00200800)
11198 #define GEN_DFP_T_B_Rc(name, op1, op2) \
11199 _GEN_DFP_LONG(name, op1, op2, 0x001F0000)
11201 #define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
11202 _GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
11204 #define GEN_DFP_Tp_B_Rc(name, op1, op2) \
11205 _GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
11207 #define GEN_DFP_T_Bp_Rc(name, op1, op2) \
11208 _GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
11210 #define GEN_DFP_BF_A_B(name, op1, op2) \
11211 _GEN_DFP_LONG(name, op1, op2, 0x00000001)
11213 #define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
11214 _GEN_DFP_QUAD(name, op1, op2, 0x00610801)
11216 #define GEN_DFP_BF_A_Bp(name, op1, op2) \
11217 _GEN_DFP_QUAD(name, op1, op2, 0x00600801)
11219 #define GEN_DFP_BF_A_DCM(name, op1, op2) \
11220 _GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
11222 #define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
11223 _GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
11225 #define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
11226 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11228 #define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
11229 _GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
11231 #define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
11232 _GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
11234 #define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
11235 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11237 #define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
11238 _GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
11240 #define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
11241 _GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
11243 #define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
11244 _GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
11246 #define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
11247 _GEN_DFP_LONG(name, op1, op2, 0x00070000)
11249 #define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
11250 _GEN_DFP_QUAD(name, op1, op2, 0x00270800)
11252 #define GEN_DFP_S_T_B_Rc(name, op1, op2) \
11253 _GEN_DFP_LONG(name, op1, op2, 0x000F0000)
11255 #define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
11256 _GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
11258 #define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
11259 _GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
11261 #define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
11262 _GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
11264 GEN_DFP_T_A_B_Rc(dadd, 0x02, 0x00),
11265 GEN_DFP_Tp_Ap_Bp_Rc(daddq, 0x02, 0x00),
11266 GEN_DFP_T_A_B_Rc(dsub, 0x02, 0x10),
11267 GEN_DFP_Tp_Ap_Bp_Rc(dsubq, 0x02, 0x10),
11268 GEN_DFP_T_A_B_Rc(dmul, 0x02, 0x01),
11269 GEN_DFP_Tp_Ap_Bp_Rc(dmulq, 0x02, 0x01),
11270 GEN_DFP_T_A_B_Rc(ddiv, 0x02, 0x11),
11271 GEN_DFP_Tp_Ap_Bp_Rc(ddivq, 0x02, 0x11),
11272 GEN_DFP_BF_A_B(dcmpu, 0x02, 0x14),
11273 GEN_DFP_BF_Ap_Bp(dcmpuq, 0x02, 0x14),
11274 GEN_DFP_BF_A_B(dcmpo, 0x02, 0x04),
11275 GEN_DFP_BF_Ap_Bp(dcmpoq, 0x02, 0x04),
11276 GEN_DFP_BF_A_DCM(dtstdc, 0x02, 0x06),
11277 GEN_DFP_BF_Ap_DCM(dtstdcq, 0x02, 0x06),
11278 GEN_DFP_BF_A_DCM(dtstdg, 0x02, 0x07),
11279 GEN_DFP_BF_Ap_DCM(dtstdgq, 0x02, 0x07),
11280 GEN_DFP_BF_A_B(dtstex, 0x02, 0x05),
11281 GEN_DFP_BF_Ap_Bp(dtstexq, 0x02, 0x05),
11282 GEN_DFP_BF_A_B(dtstsf, 0x02, 0x15),
11283 GEN_DFP_BF_A_Bp(dtstsfq, 0x02, 0x15),
11284 GEN_DFP_TE_T_B_RMC_Rc(dquai, 0x03, 0x02),
11285 GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq, 0x03, 0x02),
11286 GEN_DFP_T_A_B_RMC_Rc(dqua, 0x03, 0x00),
11287 GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq, 0x03, 0x00),
11288 GEN_DFP_T_A_B_RMC_Rc(drrnd, 0x03, 0x01),
11289 GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq, 0x03, 0x01),
11290 GEN_DFP_R_T_B_RMC_Rc(drintx, 0x03, 0x03),
11291 GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq, 0x03, 0x03),
11292 GEN_DFP_R_T_B_RMC_Rc(drintn, 0x03, 0x07),
11293 GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq, 0x03, 0x07),
11294 GEN_DFP_T_B_Rc(dctdp, 0x02, 0x08),
11295 GEN_DFP_Tp_B_Rc(dctqpq, 0x02, 0x08),
11296 GEN_DFP_T_B_Rc(drsp, 0x02, 0x18),
11297 GEN_DFP_Tp_Bp_Rc(drdpq, 0x02, 0x18),
11298 GEN_DFP_T_B_Rc(dcffix, 0x02, 0x19),
11299 GEN_DFP_Tp_B_Rc(dcffixq, 0x02, 0x19),
11300 GEN_DFP_T_B_Rc(dctfix, 0x02, 0x09),
11301 GEN_DFP_T_Bp_Rc(dctfixq, 0x02, 0x09),
11302 GEN_DFP_SP_T_B_Rc(ddedpd, 0x02, 0x0a),
11303 GEN_DFP_SP_Tp_Bp_Rc(ddedpdq, 0x02, 0x0a),
11304 GEN_DFP_S_T_B_Rc(denbcd, 0x02, 0x1a),
11305 GEN_DFP_S_Tp_Bp_Rc(denbcdq, 0x02, 0x1a),
11306 GEN_DFP_T_B_Rc(dxex, 0x02, 0x0b),
11307 GEN_DFP_T_Bp_Rc(dxexq, 0x02, 0x0b),
11308 GEN_DFP_T_A_B_Rc(diex, 0x02, 0x1b),
11309 GEN_DFP_Tp_A_Bp_Rc(diexq, 0x02, 0x1b),
11310 GEN_DFP_T_A_SH_Rc(dscli, 0x02, 0x02),
11311 GEN_DFP_Tp_Ap_SH_Rc(dscliq, 0x02, 0x02),
11312 GEN_DFP_T_A_SH_Rc(dscri, 0x02, 0x03),
11313 GEN_DFP_Tp_Ap_SH_Rc(dscriq, 0x02, 0x03),
11316 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11317 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11318 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11319 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11320 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11321 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11322 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11323 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11324 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11325 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
11326 GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
11327 GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11328 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11329 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11330 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11331 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11332 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11333 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
11334 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11335 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11336 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11337 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11338 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11339 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11340 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11341 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11342 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11343 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11344 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11345 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11346 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
11348 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11349 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11350 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11351 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11352 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11353 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11354 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11355 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11356 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11357 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11358 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11359 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11360 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11361 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11363 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11364 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11365 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11366 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11367 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11368 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11369 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11370 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11371 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11372 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11373 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11374 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11375 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11376 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11378 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11379 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11380 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11381 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11382 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11383 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11384 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11385 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11386 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11387 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11388 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11389 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11390 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11391 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11392 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11393 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11395 #undef GEN_SPEOP_LDST
11396 #define GEN_SPEOP_LDST(name, opc2, sh) \
11397 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11398 GEN_SPEOP_LDST(evldd, 0x00, 3),
11399 GEN_SPEOP_LDST(evldw, 0x01, 3),
11400 GEN_SPEOP_LDST(evldh, 0x02, 3),
11401 GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11402 GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11403 GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11404 GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11405 GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11406 GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11407 GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11408 GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11410 GEN_SPEOP_LDST(evstdd, 0x10, 3),
11411 GEN_SPEOP_LDST(evstdw, 0x11, 3),
11412 GEN_SPEOP_LDST(evstdh, 0x12, 3),
11413 GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11414 GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11415 GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11416 GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
11418 GEN_HANDLER2_E(tbegin, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
11419 PPC_NONE, PPC2_TM),
11420 GEN_HANDLER2_E(tend, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
11421 PPC_NONE, PPC2_TM),
11422 GEN_HANDLER2_E(tabort, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
11423 PPC_NONE, PPC2_TM),
11424 GEN_HANDLER2_E(tabortwc, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
11425 PPC_NONE, PPC2_TM),
11426 GEN_HANDLER2_E(tabortwci, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
11427 PPC_NONE, PPC2_TM),
11428 GEN_HANDLER2_E(tabortdc, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
11429 PPC_NONE, PPC2_TM),
11430 GEN_HANDLER2_E(tabortdci, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
11431 PPC_NONE, PPC2_TM),
11432 GEN_HANDLER2_E(tsr, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
11433 PPC_NONE, PPC2_TM),
11434 GEN_HANDLER2_E(tcheck, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
11435 PPC_NONE, PPC2_TM),
11436 GEN_HANDLER2_E(treclaim, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
11437 PPC_NONE, PPC2_TM),
11438 GEN_HANDLER2_E(trechkpt, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
11439 PPC_NONE, PPC2_TM),
11442 #include "helper_regs.h"
11443 #include "translate_init.c"
11445 /*****************************************************************************/
11446 /* Misc PowerPC helpers */
11447 void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11453 PowerPCCPU *cpu = POWERPC_CPU(cs);
11454 CPUPPCState *env = &cpu->env;
11457 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
11458 TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
11459 env->nip, env->lr, env->ctr, cpu_read_xer(env),
11461 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
11462 TARGET_FMT_lx " iidx %d didx %d\n",
11463 env->msr, env->spr[SPR_HID0],
11464 env->hflags, env->immu_idx, env->dmmu_idx);
11465 #if !defined(NO_TIMER_DUMP)
11466 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
11467 #if !defined(CONFIG_USER_ONLY)
11471 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
11472 #if !defined(CONFIG_USER_ONLY)
11473 , cpu_ppc_load_decr(env)
11477 for (i = 0; i < 32; i++) {
11478 if ((i & (RGPL - 1)) == 0)
11479 cpu_fprintf(f, "GPR%02d", i);
11480 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
11481 if ((i & (RGPL - 1)) == (RGPL - 1))
11482 cpu_fprintf(f, "\n");
11484 cpu_fprintf(f, "CR ");
11485 for (i = 0; i < 8; i++)
11486 cpu_fprintf(f, "%01x", env->crf[i]);
11487 cpu_fprintf(f, " [");
11488 for (i = 0; i < 8; i++) {
11490 if (env->crf[i] & 0x08)
11492 else if (env->crf[i] & 0x04)
11494 else if (env->crf[i] & 0x02)
11496 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
11498 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11499 env->reserve_addr);
11500 for (i = 0; i < 32; i++) {
11501 if ((i & (RFPL - 1)) == 0)
11502 cpu_fprintf(f, "FPR%02d", i);
11503 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
11504 if ((i & (RFPL - 1)) == (RFPL - 1))
11505 cpu_fprintf(f, "\n");
11507 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
11508 #if !defined(CONFIG_USER_ONLY)
11509 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11510 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11511 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11512 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11514 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11515 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11516 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11517 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11519 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11520 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11521 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11522 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11524 #if defined(TARGET_PPC64)
11525 if (env->excp_model == POWERPC_EXCP_POWER7 ||
11526 env->excp_model == POWERPC_EXCP_POWER8) {
11527 cpu_fprintf(f, "HSRR0 " TARGET_FMT_lx " HSRR1 " TARGET_FMT_lx "\n",
11528 env->spr[SPR_HSRR0], env->spr[SPR_HSRR1]);
11531 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11532 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11533 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11534 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11535 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11537 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11538 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11539 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11540 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11542 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11543 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11544 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11545 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11547 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11548 " EPR " TARGET_FMT_lx "\n",
11549 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11550 env->spr[SPR_BOOKE_EPR]);
11553 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11554 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11555 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11556 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11559 * IVORs are left out as they are large and do not change often --
11560 * they can be read with "p $ivor0", "p $ivor1", etc.
11564 #if defined(TARGET_PPC64)
11565 if (env->flags & POWERPC_FLAG_CFAR) {
11566 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11570 switch (env->mmu_model) {
11571 case POWERPC_MMU_32B:
11572 case POWERPC_MMU_601:
11573 case POWERPC_MMU_SOFT_6xx:
11574 case POWERPC_MMU_SOFT_74xx:
11575 #if defined(TARGET_PPC64)
11576 case POWERPC_MMU_64B:
11577 case POWERPC_MMU_2_03:
11578 case POWERPC_MMU_2_06:
11579 case POWERPC_MMU_2_06a:
11580 case POWERPC_MMU_2_07:
11581 case POWERPC_MMU_2_07a:
11583 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11584 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11585 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
11587 case POWERPC_MMU_BOOKE206:
11588 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11589 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11590 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11591 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11593 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11594 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11595 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11596 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11598 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11599 " TLB1CFG " TARGET_FMT_lx "\n",
11600 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11601 env->spr[SPR_BOOKE_TLB1CFG]);
11612 void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11613 fprintf_function cpu_fprintf, int flags)
11615 #if defined(DO_PPC_STATISTICS)
11616 PowerPCCPU *cpu = POWERPC_CPU(cs);
11617 opc_handler_t **t1, **t2, **t3, *handler;
11620 t1 = cpu->env.opcodes;
11621 for (op1 = 0; op1 < 64; op1++) {
11623 if (is_indirect_opcode(handler)) {
11624 t2 = ind_table(handler);
11625 for (op2 = 0; op2 < 32; op2++) {
11627 if (is_indirect_opcode(handler)) {
11628 t3 = ind_table(handler);
11629 for (op3 = 0; op3 < 32; op3++) {
11631 if (handler->count == 0)
11633 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
11634 "%016" PRIx64 " %" PRId64 "\n",
11635 op1, op2, op3, op1, (op3 << 5) | op2,
11637 handler->count, handler->count);
11640 if (handler->count == 0)
11642 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
11643 "%016" PRIx64 " %" PRId64 "\n",
11644 op1, op2, op1, op2, handler->oname,
11645 handler->count, handler->count);
11649 if (handler->count == 0)
11651 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11653 op1, op1, handler->oname,
11654 handler->count, handler->count);
11660 /*****************************************************************************/
11661 void gen_intermediate_code(CPUPPCState *env, struct TranslationBlock *tb)
11663 PowerPCCPU *cpu = ppc_env_get_cpu(env);
11664 CPUState *cs = CPU(cpu);
11665 DisasContext ctx, *ctxp = &ctx;
11666 opc_handler_t **table, *handler;
11667 target_ulong pc_start;
11672 ctx.nip = pc_start;
11674 ctx.exception = POWERPC_EXCP_NONE;
11675 ctx.spr_cb = env->spr_cb;
11677 ctx.mem_idx = env->dmmu_idx;
11679 #if !defined(CONFIG_USER_ONLY)
11680 ctx.hv = msr_hv || !env->has_hv_mode;
11682 ctx.insns_flags = env->insns_flags;
11683 ctx.insns_flags2 = env->insns_flags2;
11684 ctx.access_type = -1;
11685 ctx.le_mode = !!(env->hflags & (1 << MSR_LE));
11686 ctx.default_tcg_memop_mask = ctx.le_mode ? MO_LE : MO_BE;
11687 #if defined(TARGET_PPC64)
11688 ctx.sf_mode = msr_is_64bit(env, env->msr);
11689 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
11691 if (env->mmu_model == POWERPC_MMU_32B ||
11692 env->mmu_model == POWERPC_MMU_601 ||
11693 (env->mmu_model & POWERPC_MMU_64B))
11694 ctx.lazy_tlb_flush = true;
11696 ctx.fpu_enabled = !!msr_fp;
11697 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
11698 ctx.spe_enabled = !!msr_spe;
11700 ctx.spe_enabled = false;
11701 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11702 ctx.altivec_enabled = !!msr_vr;
11704 ctx.altivec_enabled = false;
11705 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11706 ctx.vsx_enabled = !!msr_vsx;
11708 ctx.vsx_enabled = false;
11710 #if defined(TARGET_PPC64)
11711 if ((env->flags & POWERPC_FLAG_TM) && msr_tm) {
11712 ctx.tm_enabled = !!msr_tm;
11714 ctx.tm_enabled = false;
11717 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
11718 ctx.singlestep_enabled = CPU_SINGLE_STEP;
11720 ctx.singlestep_enabled = 0;
11721 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
11722 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
11723 if (unlikely(cs->singlestep_enabled)) {
11724 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
11726 #if defined (DO_SINGLE_STEP) && 0
11727 /* Single step trace mode */
11731 max_insns = tb->cflags & CF_COUNT_MASK;
11732 if (max_insns == 0) {
11733 max_insns = CF_COUNT_MASK;
11735 if (max_insns > TCG_MAX_INSNS) {
11736 max_insns = TCG_MAX_INSNS;
11740 tcg_clear_temp_count();
11741 /* Set env in case of segfault during code fetch */
11742 while (ctx.exception == POWERPC_EXCP_NONE && !tcg_op_buf_full()) {
11743 tcg_gen_insn_start(ctx.nip);
11746 if (unlikely(cpu_breakpoint_test(cs, ctx.nip, BP_ANY))) {
11747 gen_debug_exception(ctxp);
11748 /* The address covered by the breakpoint must be included in
11749 [tb->pc, tb->pc + tb->size) in order to for it to be
11750 properly cleared -- thus we increment the PC here so that
11751 the logic setting tb->size below does the right thing. */
11756 LOG_DISAS("----------------\n");
11757 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
11758 ctx.nip, ctx.mem_idx, (int)msr_ir);
11759 if (num_insns == max_insns && (tb->cflags & CF_LAST_IO))
11761 if (unlikely(need_byteswap(&ctx))) {
11762 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
11764 ctx.opcode = cpu_ldl_code(env, ctx.nip);
11766 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
11767 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
11768 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
11770 table = env->opcodes;
11771 handler = table[opc1(ctx.opcode)];
11772 if (is_indirect_opcode(handler)) {
11773 table = ind_table(handler);
11774 handler = table[opc2(ctx.opcode)];
11775 if (is_indirect_opcode(handler)) {
11776 table = ind_table(handler);
11777 handler = table[opc3(ctx.opcode)];
11780 /* Is opcode *REALLY* valid ? */
11781 if (unlikely(handler->handler == &gen_invalid)) {
11782 qemu_log_mask(LOG_GUEST_ERROR, "invalid/unsupported opcode: "
11783 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11784 opc1(ctx.opcode), opc2(ctx.opcode),
11785 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
11789 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11790 inval = handler->inval2;
11792 inval = handler->inval1;
11795 if (unlikely((ctx.opcode & inval) != 0)) {
11796 qemu_log_mask(LOG_GUEST_ERROR, "invalid bits: %08x for opcode: "
11797 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
11798 ctx.opcode & inval, opc1(ctx.opcode),
11799 opc2(ctx.opcode), opc3(ctx.opcode),
11800 ctx.opcode, ctx.nip - 4);
11801 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
11805 (*(handler->handler))(&ctx);
11806 #if defined(DO_PPC_STATISTICS)
11809 /* Check trace mode exceptions */
11810 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11811 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11812 ctx.exception != POWERPC_SYSCALL &&
11813 ctx.exception != POWERPC_EXCP_TRAP &&
11814 ctx.exception != POWERPC_EXCP_BRANCH)) {
11815 gen_exception(ctxp, POWERPC_EXCP_TRACE);
11816 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
11817 (cs->singlestep_enabled) ||
11819 num_insns >= max_insns)) {
11820 /* if we reach a page boundary or are single stepping, stop
11825 if (tcg_check_temp_count()) {
11826 fprintf(stderr, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11827 opc1(ctx.opcode), opc2(ctx.opcode), opc3(ctx.opcode),
11832 if (tb->cflags & CF_LAST_IO)
11834 if (ctx.exception == POWERPC_EXCP_NONE) {
11835 gen_goto_tb(&ctx, 0, ctx.nip);
11836 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
11837 if (unlikely(cs->singlestep_enabled)) {
11838 gen_debug_exception(ctxp);
11840 /* Generate the return instruction */
11841 tcg_gen_exit_tb(0);
11843 gen_tb_end(tb, num_insns);
11845 tb->size = ctx.nip - pc_start;
11846 tb->icount = num_insns;
11848 #if defined(DEBUG_DISAS)
11849 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
11850 && qemu_log_in_addr_range(pc_start)) {
11852 flags = env->bfd_mach;
11853 flags |= ctx.le_mode << 16;
11854 qemu_log("IN: %s\n", lookup_symbol(pc_start));
11855 log_target_disas(cs, pc_start, ctx.nip - pc_start, flags);
11861 void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb,
11862 target_ulong *data)
11864 env->nip = data[0];