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");
93 cpu_reg_names_size = sizeof(cpu_reg_names);
95 for (i = 0; i < 8; i++) {
96 snprintf(p, cpu_reg_names_size, "crf%d", i);
97 cpu_crf[i] = tcg_global_mem_new_i32(cpu_env,
98 offsetof(CPUPPCState, crf[i]), p);
100 cpu_reg_names_size -= 5;
103 for (i = 0; i < 32; i++) {
104 snprintf(p, cpu_reg_names_size, "r%d", i);
105 cpu_gpr[i] = tcg_global_mem_new(cpu_env,
106 offsetof(CPUPPCState, gpr[i]), p);
107 p += (i < 10) ? 3 : 4;
108 cpu_reg_names_size -= (i < 10) ? 3 : 4;
109 snprintf(p, cpu_reg_names_size, "r%dH", i);
110 cpu_gprh[i] = tcg_global_mem_new(cpu_env,
111 offsetof(CPUPPCState, gprh[i]), p);
112 p += (i < 10) ? 4 : 5;
113 cpu_reg_names_size -= (i < 10) ? 4 : 5;
115 snprintf(p, cpu_reg_names_size, "fp%d", i);
116 cpu_fpr[i] = tcg_global_mem_new_i64(cpu_env,
117 offsetof(CPUPPCState, fpr[i]), p);
118 p += (i < 10) ? 4 : 5;
119 cpu_reg_names_size -= (i < 10) ? 4 : 5;
121 snprintf(p, cpu_reg_names_size, "avr%dH", i);
122 #ifdef HOST_WORDS_BIGENDIAN
123 cpu_avrh[i] = tcg_global_mem_new_i64(cpu_env,
124 offsetof(CPUPPCState, avr[i].u64[0]), p);
126 cpu_avrh[i] = tcg_global_mem_new_i64(cpu_env,
127 offsetof(CPUPPCState, avr[i].u64[1]), p);
129 p += (i < 10) ? 6 : 7;
130 cpu_reg_names_size -= (i < 10) ? 6 : 7;
132 snprintf(p, cpu_reg_names_size, "avr%dL", i);
133 #ifdef HOST_WORDS_BIGENDIAN
134 cpu_avrl[i] = tcg_global_mem_new_i64(cpu_env,
135 offsetof(CPUPPCState, avr[i].u64[1]), p);
137 cpu_avrl[i] = tcg_global_mem_new_i64(cpu_env,
138 offsetof(CPUPPCState, avr[i].u64[0]), p);
140 p += (i < 10) ? 6 : 7;
141 cpu_reg_names_size -= (i < 10) ? 6 : 7;
142 snprintf(p, cpu_reg_names_size, "vsr%d", i);
143 cpu_vsr[i] = tcg_global_mem_new_i64(cpu_env,
144 offsetof(CPUPPCState, vsr[i]), p);
145 p += (i < 10) ? 5 : 6;
146 cpu_reg_names_size -= (i < 10) ? 5 : 6;
149 cpu_nip = tcg_global_mem_new(cpu_env,
150 offsetof(CPUPPCState, nip), "nip");
152 cpu_msr = tcg_global_mem_new(cpu_env,
153 offsetof(CPUPPCState, msr), "msr");
155 cpu_ctr = tcg_global_mem_new(cpu_env,
156 offsetof(CPUPPCState, ctr), "ctr");
158 cpu_lr = tcg_global_mem_new(cpu_env,
159 offsetof(CPUPPCState, lr), "lr");
161 #if defined(TARGET_PPC64)
162 cpu_cfar = tcg_global_mem_new(cpu_env,
163 offsetof(CPUPPCState, cfar), "cfar");
166 cpu_xer = tcg_global_mem_new(cpu_env,
167 offsetof(CPUPPCState, xer), "xer");
168 cpu_so = tcg_global_mem_new(cpu_env,
169 offsetof(CPUPPCState, so), "SO");
170 cpu_ov = tcg_global_mem_new(cpu_env,
171 offsetof(CPUPPCState, ov), "OV");
172 cpu_ca = tcg_global_mem_new(cpu_env,
173 offsetof(CPUPPCState, ca), "CA");
175 cpu_reserve = tcg_global_mem_new(cpu_env,
176 offsetof(CPUPPCState, reserve_addr),
179 cpu_fpscr = tcg_global_mem_new(cpu_env,
180 offsetof(CPUPPCState, fpscr), "fpscr");
182 cpu_access_type = tcg_global_mem_new_i32(cpu_env,
183 offsetof(CPUPPCState, access_type), "access_type");
188 /* internal defines */
189 struct DisasContext {
190 struct TranslationBlock *tb;
194 /* Routine used to access memory */
198 /* Translation flags */
200 TCGMemOp default_tcg_memop_mask;
201 #if defined(TARGET_PPC64)
210 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
211 int singlestep_enabled;
212 uint64_t insns_flags;
213 uint64_t insns_flags2;
216 /* Return true iff byteswap is needed in a scalar memop */
217 static inline bool need_byteswap(const DisasContext *ctx)
219 #if defined(TARGET_WORDS_BIGENDIAN)
222 return !ctx->le_mode;
226 /* True when active word size < size of target_long. */
228 # define NARROW_MODE(C) (!(C)->sf_mode)
230 # define NARROW_MODE(C) 0
233 struct opc_handler_t {
234 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
236 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
238 /* instruction type */
240 /* extended instruction type */
243 void (*handler)(DisasContext *ctx);
244 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
247 #if defined(DO_PPC_STATISTICS)
252 static inline void gen_reset_fpstatus(void)
254 gen_helper_reset_fpstatus(cpu_env);
257 static inline void gen_compute_fprf(TCGv_i64 arg)
259 gen_helper_compute_fprf(cpu_env, arg);
260 gen_helper_float_check_status(cpu_env);
263 static inline void gen_set_access_type(DisasContext *ctx, int access_type)
265 if (ctx->access_type != access_type) {
266 tcg_gen_movi_i32(cpu_access_type, access_type);
267 ctx->access_type = access_type;
271 static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
273 if (NARROW_MODE(ctx)) {
276 tcg_gen_movi_tl(cpu_nip, nip);
279 void gen_update_current_nip(void *opaque)
281 DisasContext *ctx = opaque;
283 tcg_gen_movi_tl(cpu_nip, ctx->nip);
286 static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
289 if (ctx->exception == POWERPC_EXCP_NONE) {
290 gen_update_nip(ctx, ctx->nip);
292 t0 = tcg_const_i32(excp);
293 t1 = tcg_const_i32(error);
294 gen_helper_raise_exception_err(cpu_env, t0, t1);
295 tcg_temp_free_i32(t0);
296 tcg_temp_free_i32(t1);
297 ctx->exception = (excp);
300 static inline void gen_exception(DisasContext *ctx, uint32_t excp)
303 if (ctx->exception == POWERPC_EXCP_NONE) {
304 gen_update_nip(ctx, ctx->nip);
306 t0 = tcg_const_i32(excp);
307 gen_helper_raise_exception(cpu_env, t0);
308 tcg_temp_free_i32(t0);
309 ctx->exception = (excp);
312 static inline void gen_debug_exception(DisasContext *ctx)
316 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
317 (ctx->exception != POWERPC_EXCP_SYNC)) {
318 gen_update_nip(ctx, ctx->nip);
320 t0 = tcg_const_i32(EXCP_DEBUG);
321 gen_helper_raise_exception(cpu_env, t0);
322 tcg_temp_free_i32(t0);
325 static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
327 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
330 /* Stop translation */
331 static inline void gen_stop_exception(DisasContext *ctx)
333 gen_update_nip(ctx, ctx->nip);
334 ctx->exception = POWERPC_EXCP_STOP;
337 #ifndef CONFIG_USER_ONLY
338 /* No need to update nip here, as execution flow will change */
339 static inline void gen_sync_exception(DisasContext *ctx)
341 ctx->exception = POWERPC_EXCP_SYNC;
345 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
346 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
348 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
349 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
351 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
352 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
354 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
355 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
357 typedef struct opcode_t {
358 unsigned char opc1, opc2, opc3;
359 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
360 unsigned char pad[5];
362 unsigned char pad[1];
364 opc_handler_t handler;
368 /*****************************************************************************/
369 /*** Instruction decoding ***/
370 #define EXTRACT_HELPER(name, shift, nb) \
371 static inline uint32_t name(uint32_t opcode) \
373 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
376 #define EXTRACT_SHELPER(name, shift, nb) \
377 static inline int32_t name(uint32_t opcode) \
379 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
382 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
383 static inline uint32_t name(uint32_t opcode) \
385 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
386 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
389 EXTRACT_HELPER(opc1, 26, 6);
391 EXTRACT_HELPER(opc2, 1, 5);
393 EXTRACT_HELPER(opc3, 6, 5);
394 /* Update Cr0 flags */
395 EXTRACT_HELPER(Rc, 0, 1);
396 /* Update Cr6 flags (Altivec) */
397 EXTRACT_HELPER(Rc21, 10, 1);
399 EXTRACT_HELPER(rD, 21, 5);
401 EXTRACT_HELPER(rS, 21, 5);
403 EXTRACT_HELPER(rA, 16, 5);
405 EXTRACT_HELPER(rB, 11, 5);
407 EXTRACT_HELPER(rC, 6, 5);
409 EXTRACT_HELPER(crfD, 23, 3);
410 EXTRACT_HELPER(crfS, 18, 3);
411 EXTRACT_HELPER(crbD, 21, 5);
412 EXTRACT_HELPER(crbA, 16, 5);
413 EXTRACT_HELPER(crbB, 11, 5);
415 EXTRACT_HELPER(_SPR, 11, 10);
416 static inline uint32_t SPR(uint32_t opcode)
418 uint32_t sprn = _SPR(opcode);
420 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
422 /*** Get constants ***/
423 /* 16 bits signed immediate value */
424 EXTRACT_SHELPER(SIMM, 0, 16);
425 /* 16 bits unsigned immediate value */
426 EXTRACT_HELPER(UIMM, 0, 16);
427 /* 5 bits signed immediate value */
428 EXTRACT_HELPER(SIMM5, 16, 5);
429 /* 5 bits signed immediate value */
430 EXTRACT_HELPER(UIMM5, 16, 5);
432 EXTRACT_HELPER(NB, 11, 5);
434 EXTRACT_HELPER(SH, 11, 5);
435 /* Vector shift count */
436 EXTRACT_HELPER(VSH, 6, 4);
438 EXTRACT_HELPER(MB, 6, 5);
440 EXTRACT_HELPER(ME, 1, 5);
442 EXTRACT_HELPER(TO, 21, 5);
444 EXTRACT_HELPER(CRM, 12, 8);
446 #ifndef CONFIG_USER_ONLY
447 EXTRACT_HELPER(SR, 16, 4);
451 EXTRACT_HELPER(FPBF, 23, 3);
452 EXTRACT_HELPER(FPIMM, 12, 4);
453 EXTRACT_HELPER(FPL, 25, 1);
454 EXTRACT_HELPER(FPFLM, 17, 8);
455 EXTRACT_HELPER(FPW, 16, 1);
457 /*** Jump target decoding ***/
458 /* Immediate address */
459 static inline target_ulong LI(uint32_t opcode)
461 return (opcode >> 0) & 0x03FFFFFC;
464 static inline uint32_t BD(uint32_t opcode)
466 return (opcode >> 0) & 0xFFFC;
469 EXTRACT_HELPER(BO, 21, 5);
470 EXTRACT_HELPER(BI, 16, 5);
471 /* Absolute/relative address */
472 EXTRACT_HELPER(AA, 1, 1);
474 EXTRACT_HELPER(LK, 0, 1);
477 EXTRACT_HELPER(DCM, 10, 6)
480 EXTRACT_HELPER(RMC, 9, 2)
482 /* Create a mask between <start> and <end> bits */
483 static inline target_ulong MASK(uint32_t start, uint32_t end)
487 #if defined(TARGET_PPC64)
488 if (likely(start == 0)) {
489 ret = UINT64_MAX << (63 - end);
490 } else if (likely(end == 63)) {
491 ret = UINT64_MAX >> start;
494 if (likely(start == 0)) {
495 ret = UINT32_MAX << (31 - end);
496 } else if (likely(end == 31)) {
497 ret = UINT32_MAX >> start;
501 ret = (((target_ulong)(-1ULL)) >> (start)) ^
502 (((target_ulong)(-1ULL) >> (end)) >> 1);
503 if (unlikely(start > end))
510 EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
511 EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
512 EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
513 EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
514 EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
515 EXTRACT_HELPER(DM, 8, 2);
516 EXTRACT_HELPER(UIM, 16, 2);
517 EXTRACT_HELPER(SHW, 8, 2);
518 EXTRACT_HELPER(SP, 19, 2);
519 /*****************************************************************************/
520 /* PowerPC instructions table */
522 #if defined(DO_PPC_STATISTICS)
523 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
533 .handler = &gen_##name, \
534 .oname = stringify(name), \
536 .oname = stringify(name), \
538 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
549 .handler = &gen_##name, \
550 .oname = stringify(name), \
552 .oname = stringify(name), \
554 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
564 .handler = &gen_##name, \
570 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
580 .handler = &gen_##name, \
582 .oname = stringify(name), \
584 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
595 .handler = &gen_##name, \
597 .oname = stringify(name), \
599 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
609 .handler = &gen_##name, \
615 /* SPR load/store helpers */
616 static inline void gen_load_spr(TCGv t, int reg)
618 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
621 static inline void gen_store_spr(int reg, TCGv t)
623 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
626 /* Invalid instruction */
627 static void gen_invalid(DisasContext *ctx)
629 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
632 static opc_handler_t invalid_handler = {
633 .inval1 = 0xFFFFFFFF,
634 .inval2 = 0xFFFFFFFF,
637 .handler = gen_invalid,
640 /*** Integer comparison ***/
642 static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
644 TCGv t0 = tcg_temp_new();
645 TCGv_i32 t1 = tcg_temp_new_i32();
647 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
649 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
650 tcg_gen_trunc_tl_i32(t1, t0);
651 tcg_gen_shli_i32(t1, t1, CRF_LT);
652 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
654 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
655 tcg_gen_trunc_tl_i32(t1, t0);
656 tcg_gen_shli_i32(t1, t1, CRF_GT);
657 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
659 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
660 tcg_gen_trunc_tl_i32(t1, t0);
661 tcg_gen_shli_i32(t1, t1, CRF_EQ);
662 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
665 tcg_temp_free_i32(t1);
668 static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
670 TCGv t0 = tcg_const_tl(arg1);
671 gen_op_cmp(arg0, t0, s, crf);
675 static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
681 tcg_gen_ext32s_tl(t0, arg0);
682 tcg_gen_ext32s_tl(t1, arg1);
684 tcg_gen_ext32u_tl(t0, arg0);
685 tcg_gen_ext32u_tl(t1, arg1);
687 gen_op_cmp(t0, t1, s, crf);
692 static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
694 TCGv t0 = tcg_const_tl(arg1);
695 gen_op_cmp32(arg0, t0, s, crf);
699 static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
701 if (NARROW_MODE(ctx)) {
702 gen_op_cmpi32(reg, 0, 1, 0);
704 gen_op_cmpi(reg, 0, 1, 0);
709 static void gen_cmp(DisasContext *ctx)
711 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
712 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
713 1, crfD(ctx->opcode));
715 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
716 1, crfD(ctx->opcode));
721 static void gen_cmpi(DisasContext *ctx)
723 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
724 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
725 1, crfD(ctx->opcode));
727 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
728 1, crfD(ctx->opcode));
733 static void gen_cmpl(DisasContext *ctx)
735 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
736 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
737 0, crfD(ctx->opcode));
739 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
740 0, crfD(ctx->opcode));
745 static void gen_cmpli(DisasContext *ctx)
747 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
748 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
749 0, crfD(ctx->opcode));
751 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
752 0, crfD(ctx->opcode));
756 /* isel (PowerPC 2.03 specification) */
757 static void gen_isel(DisasContext *ctx)
759 uint32_t bi = rC(ctx->opcode);
760 uint32_t mask = 0x08 >> (bi & 0x03);
761 TCGv t0 = tcg_temp_new();
764 tcg_gen_extu_i32_tl(t0, cpu_crf[bi >> 2]);
765 tcg_gen_andi_tl(t0, t0, mask);
767 zr = tcg_const_tl(0);
768 tcg_gen_movcond_tl(TCG_COND_NE, cpu_gpr[rD(ctx->opcode)], t0, zr,
769 rA(ctx->opcode) ? cpu_gpr[rA(ctx->opcode)] : zr,
770 cpu_gpr[rB(ctx->opcode)]);
775 /* cmpb: PowerPC 2.05 specification */
776 static void gen_cmpb(DisasContext *ctx)
778 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
779 cpu_gpr[rB(ctx->opcode)]);
782 /*** Integer arithmetic ***/
784 static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
785 TCGv arg1, TCGv arg2, int sub)
787 TCGv t0 = tcg_temp_new();
789 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
790 tcg_gen_xor_tl(t0, arg1, arg2);
792 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
794 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
797 if (NARROW_MODE(ctx)) {
798 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
800 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
801 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
804 /* Common add function */
805 static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
806 TCGv arg2, bool add_ca, bool compute_ca,
807 bool compute_ov, bool compute_rc0)
811 if (compute_ca || compute_ov) {
816 if (NARROW_MODE(ctx)) {
817 /* Caution: a non-obvious corner case of the spec is that we
818 must produce the *entire* 64-bit addition, but produce the
819 carry into bit 32. */
820 TCGv t1 = tcg_temp_new();
821 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
822 tcg_gen_add_tl(t0, arg1, arg2);
824 tcg_gen_add_tl(t0, t0, cpu_ca);
826 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
828 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
829 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
831 TCGv zero = tcg_const_tl(0);
833 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
834 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
836 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
841 tcg_gen_add_tl(t0, arg1, arg2);
843 tcg_gen_add_tl(t0, t0, cpu_ca);
848 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
850 if (unlikely(compute_rc0)) {
851 gen_set_Rc0(ctx, t0);
854 if (!TCGV_EQUAL(t0, ret)) {
855 tcg_gen_mov_tl(ret, t0);
859 /* Add functions with two operands */
860 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
861 static void glue(gen_, name)(DisasContext *ctx) \
863 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
864 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
865 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
867 /* Add functions with one operand and one immediate */
868 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
869 add_ca, compute_ca, compute_ov) \
870 static void glue(gen_, name)(DisasContext *ctx) \
872 TCGv t0 = tcg_const_tl(const_val); \
873 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
874 cpu_gpr[rA(ctx->opcode)], t0, \
875 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
879 /* add add. addo addo. */
880 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
881 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
882 /* addc addc. addco addco. */
883 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
884 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
885 /* adde adde. addeo addeo. */
886 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
887 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
888 /* addme addme. addmeo addmeo. */
889 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
890 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
891 /* addze addze. addzeo addzeo.*/
892 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
893 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
895 static void gen_addi(DisasContext *ctx)
897 target_long simm = SIMM(ctx->opcode);
899 if (rA(ctx->opcode) == 0) {
901 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
903 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
904 cpu_gpr[rA(ctx->opcode)], simm);
908 static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
910 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
911 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
912 c, 0, 1, 0, compute_rc0);
916 static void gen_addic(DisasContext *ctx)
918 gen_op_addic(ctx, 0);
921 static void gen_addic_(DisasContext *ctx)
923 gen_op_addic(ctx, 1);
927 static void gen_addis(DisasContext *ctx)
929 target_long simm = SIMM(ctx->opcode);
931 if (rA(ctx->opcode) == 0) {
933 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
935 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
936 cpu_gpr[rA(ctx->opcode)], simm << 16);
940 static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
941 TCGv arg2, int sign, int compute_ov)
943 TCGLabel *l1 = gen_new_label();
944 TCGLabel *l2 = gen_new_label();
945 TCGv_i32 t0 = tcg_temp_local_new_i32();
946 TCGv_i32 t1 = tcg_temp_local_new_i32();
948 tcg_gen_trunc_tl_i32(t0, arg1);
949 tcg_gen_trunc_tl_i32(t1, arg2);
950 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
952 TCGLabel *l3 = gen_new_label();
953 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
954 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
956 tcg_gen_div_i32(t0, t0, t1);
958 tcg_gen_divu_i32(t0, t0, t1);
961 tcg_gen_movi_tl(cpu_ov, 0);
966 tcg_gen_sari_i32(t0, t0, 31);
968 tcg_gen_movi_i32(t0, 0);
971 tcg_gen_movi_tl(cpu_ov, 1);
972 tcg_gen_movi_tl(cpu_so, 1);
975 tcg_gen_extu_i32_tl(ret, t0);
976 tcg_temp_free_i32(t0);
977 tcg_temp_free_i32(t1);
978 if (unlikely(Rc(ctx->opcode) != 0))
979 gen_set_Rc0(ctx, ret);
982 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
983 static void glue(gen_, name)(DisasContext *ctx) \
985 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
986 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
989 /* divwu divwu. divwuo divwuo. */
990 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
991 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
992 /* divw divw. divwo divwo. */
993 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
994 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
996 /* div[wd]eu[o][.] */
997 #define GEN_DIVE(name, hlpr, compute_ov) \
998 static void gen_##name(DisasContext *ctx) \
1000 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1001 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1002 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1003 tcg_temp_free_i32(t0); \
1004 if (unlikely(Rc(ctx->opcode) != 0)) { \
1005 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1009 GEN_DIVE(divweu, divweu, 0);
1010 GEN_DIVE(divweuo, divweu, 1);
1011 GEN_DIVE(divwe, divwe, 0);
1012 GEN_DIVE(divweo, divwe, 1);
1014 #if defined(TARGET_PPC64)
1015 static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1016 TCGv arg2, int sign, int compute_ov)
1018 TCGLabel *l1 = gen_new_label();
1019 TCGLabel *l2 = gen_new_label();
1021 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1023 TCGLabel *l3 = gen_new_label();
1024 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1025 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1027 tcg_gen_div_i64(ret, arg1, arg2);
1029 tcg_gen_divu_i64(ret, arg1, arg2);
1032 tcg_gen_movi_tl(cpu_ov, 0);
1037 tcg_gen_sari_i64(ret, arg1, 63);
1039 tcg_gen_movi_i64(ret, 0);
1042 tcg_gen_movi_tl(cpu_ov, 1);
1043 tcg_gen_movi_tl(cpu_so, 1);
1046 if (unlikely(Rc(ctx->opcode) != 0))
1047 gen_set_Rc0(ctx, ret);
1049 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1050 static void glue(gen_, name)(DisasContext *ctx) \
1052 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1053 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1054 sign, compute_ov); \
1056 /* divwu divwu. divwuo divwuo. */
1057 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1058 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1059 /* divw divw. divwo divwo. */
1060 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1061 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1063 GEN_DIVE(divdeu, divdeu, 0);
1064 GEN_DIVE(divdeuo, divdeu, 1);
1065 GEN_DIVE(divde, divde, 0);
1066 GEN_DIVE(divdeo, divde, 1);
1070 static void gen_mulhw(DisasContext *ctx)
1072 TCGv_i32 t0 = tcg_temp_new_i32();
1073 TCGv_i32 t1 = tcg_temp_new_i32();
1075 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1076 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1077 tcg_gen_muls2_i32(t0, t1, t0, t1);
1078 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1079 tcg_temp_free_i32(t0);
1080 tcg_temp_free_i32(t1);
1081 if (unlikely(Rc(ctx->opcode) != 0))
1082 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1085 /* mulhwu mulhwu. */
1086 static void gen_mulhwu(DisasContext *ctx)
1088 TCGv_i32 t0 = tcg_temp_new_i32();
1089 TCGv_i32 t1 = tcg_temp_new_i32();
1091 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1092 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1093 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1094 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1095 tcg_temp_free_i32(t0);
1096 tcg_temp_free_i32(t1);
1097 if (unlikely(Rc(ctx->opcode) != 0))
1098 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1102 static void gen_mullw(DisasContext *ctx)
1104 #if defined(TARGET_PPC64)
1106 t0 = tcg_temp_new_i64();
1107 t1 = tcg_temp_new_i64();
1108 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1109 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1110 tcg_gen_mul_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);
1114 tcg_gen_mul_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1115 cpu_gpr[rB(ctx->opcode)]);
1117 if (unlikely(Rc(ctx->opcode) != 0))
1118 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1121 /* mullwo mullwo. */
1122 static void gen_mullwo(DisasContext *ctx)
1124 TCGv_i32 t0 = tcg_temp_new_i32();
1125 TCGv_i32 t1 = tcg_temp_new_i32();
1127 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1128 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1129 tcg_gen_muls2_i32(t0, t1, t0, t1);
1130 #if defined(TARGET_PPC64)
1131 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);
1133 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], t0);
1136 tcg_gen_sari_i32(t0, t0, 31);
1137 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1138 tcg_gen_extu_i32_tl(cpu_ov, t0);
1139 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1141 tcg_temp_free_i32(t0);
1142 tcg_temp_free_i32(t1);
1143 if (unlikely(Rc(ctx->opcode) != 0))
1144 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1148 static void gen_mulli(DisasContext *ctx)
1150 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1154 #if defined(TARGET_PPC64)
1156 static void gen_mulhd(DisasContext *ctx)
1158 TCGv lo = tcg_temp_new();
1159 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1160 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1162 if (unlikely(Rc(ctx->opcode) != 0)) {
1163 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1167 /* mulhdu mulhdu. */
1168 static void gen_mulhdu(DisasContext *ctx)
1170 TCGv lo = tcg_temp_new();
1171 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1172 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1174 if (unlikely(Rc(ctx->opcode) != 0)) {
1175 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1180 static void gen_mulld(DisasContext *ctx)
1182 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1183 cpu_gpr[rB(ctx->opcode)]);
1184 if (unlikely(Rc(ctx->opcode) != 0))
1185 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1188 /* mulldo mulldo. */
1189 static void gen_mulldo(DisasContext *ctx)
1191 TCGv_i64 t0 = tcg_temp_new_i64();
1192 TCGv_i64 t1 = tcg_temp_new_i64();
1194 tcg_gen_muls2_i64(t0, t1, cpu_gpr[rA(ctx->opcode)],
1195 cpu_gpr[rB(ctx->opcode)]);
1196 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], t0);
1198 tcg_gen_sari_i64(t0, t0, 63);
1199 tcg_gen_setcond_i64(TCG_COND_NE, cpu_ov, t0, t1);
1200 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1202 tcg_temp_free_i64(t0);
1203 tcg_temp_free_i64(t1);
1205 if (unlikely(Rc(ctx->opcode) != 0)) {
1206 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1211 /* Common subf function */
1212 static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
1213 TCGv arg2, bool add_ca, bool compute_ca,
1214 bool compute_ov, bool compute_rc0)
1218 if (compute_ca || compute_ov) {
1219 t0 = tcg_temp_new();
1223 /* dest = ~arg1 + arg2 [+ ca]. */
1224 if (NARROW_MODE(ctx)) {
1225 /* Caution: a non-obvious corner case of the spec is that we
1226 must produce the *entire* 64-bit addition, but produce the
1227 carry into bit 32. */
1228 TCGv inv1 = tcg_temp_new();
1229 TCGv t1 = tcg_temp_new();
1230 tcg_gen_not_tl(inv1, arg1);
1232 tcg_gen_add_tl(t0, arg2, cpu_ca);
1234 tcg_gen_addi_tl(t0, arg2, 1);
1236 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
1237 tcg_gen_add_tl(t0, t0, inv1);
1238 tcg_temp_free(inv1);
1239 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1241 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1242 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
1243 } else if (add_ca) {
1244 TCGv zero, inv1 = tcg_temp_new();
1245 tcg_gen_not_tl(inv1, arg1);
1246 zero = tcg_const_tl(0);
1247 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
1248 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
1249 tcg_temp_free(zero);
1250 tcg_temp_free(inv1);
1252 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
1253 tcg_gen_sub_tl(t0, arg2, arg1);
1255 } else if (add_ca) {
1256 /* Since we're ignoring carry-out, we can simplify the
1257 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1258 tcg_gen_sub_tl(t0, arg2, arg1);
1259 tcg_gen_add_tl(t0, t0, cpu_ca);
1260 tcg_gen_subi_tl(t0, t0, 1);
1262 tcg_gen_sub_tl(t0, arg2, arg1);
1266 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1268 if (unlikely(compute_rc0)) {
1269 gen_set_Rc0(ctx, t0);
1272 if (!TCGV_EQUAL(t0, ret)) {
1273 tcg_gen_mov_tl(ret, t0);
1277 /* Sub functions with Two operands functions */
1278 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1279 static void glue(gen_, name)(DisasContext *ctx) \
1281 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1282 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1283 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1285 /* Sub functions with one operand and one immediate */
1286 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1287 add_ca, compute_ca, compute_ov) \
1288 static void glue(gen_, name)(DisasContext *ctx) \
1290 TCGv t0 = tcg_const_tl(const_val); \
1291 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1292 cpu_gpr[rA(ctx->opcode)], t0, \
1293 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1294 tcg_temp_free(t0); \
1296 /* subf subf. subfo subfo. */
1297 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1298 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1299 /* subfc subfc. subfco subfco. */
1300 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1301 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1302 /* subfe subfe. subfeo subfo. */
1303 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1304 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1305 /* subfme subfme. subfmeo subfmeo. */
1306 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1307 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1308 /* subfze subfze. subfzeo subfzeo.*/
1309 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1310 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
1313 static void gen_subfic(DisasContext *ctx)
1315 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1316 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1321 /* neg neg. nego nego. */
1322 static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1324 TCGv zero = tcg_const_tl(0);
1325 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1326 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1327 tcg_temp_free(zero);
1330 static void gen_neg(DisasContext *ctx)
1332 gen_op_arith_neg(ctx, 0);
1335 static void gen_nego(DisasContext *ctx)
1337 gen_op_arith_neg(ctx, 1);
1340 /*** Integer logical ***/
1341 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1342 static void glue(gen_, name)(DisasContext *ctx) \
1344 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1345 cpu_gpr[rB(ctx->opcode)]); \
1346 if (unlikely(Rc(ctx->opcode) != 0)) \
1347 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1350 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1351 static void glue(gen_, name)(DisasContext *ctx) \
1353 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1354 if (unlikely(Rc(ctx->opcode) != 0)) \
1355 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1359 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
1361 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
1364 static void gen_andi_(DisasContext *ctx)
1366 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1367 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1371 static void gen_andis_(DisasContext *ctx)
1373 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1374 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1378 static void gen_cntlzw(DisasContext *ctx)
1380 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1381 if (unlikely(Rc(ctx->opcode) != 0))
1382 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1385 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
1386 /* extsb & extsb. */
1387 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
1388 /* extsh & extsh. */
1389 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
1391 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
1393 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
1396 static void gen_or(DisasContext *ctx)
1400 rs = rS(ctx->opcode);
1401 ra = rA(ctx->opcode);
1402 rb = rB(ctx->opcode);
1403 /* Optimisation for mr. ri case */
1404 if (rs != ra || rs != rb) {
1406 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1408 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
1409 if (unlikely(Rc(ctx->opcode) != 0))
1410 gen_set_Rc0(ctx, cpu_gpr[ra]);
1411 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1412 gen_set_Rc0(ctx, cpu_gpr[rs]);
1413 #if defined(TARGET_PPC64)
1419 /* Set process priority to low */
1423 /* Set process priority to medium-low */
1427 /* Set process priority to normal */
1430 #if !defined(CONFIG_USER_ONLY)
1433 /* Set process priority to very low */
1439 /* Set process priority to medium-hight */
1445 /* Set process priority to high */
1451 /* Set process priority to very high */
1461 TCGv t0 = tcg_temp_new();
1462 gen_load_spr(t0, SPR_PPR);
1463 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1464 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
1465 gen_store_spr(SPR_PPR, t0);
1472 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
1475 static void gen_xor(DisasContext *ctx)
1477 /* Optimisation for "set to zero" case */
1478 if (rS(ctx->opcode) != rB(ctx->opcode))
1479 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1481 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1482 if (unlikely(Rc(ctx->opcode) != 0))
1483 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1487 static void gen_ori(DisasContext *ctx)
1489 target_ulong uimm = UIMM(ctx->opcode);
1491 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1493 /* XXX: should handle special NOPs for POWER series */
1496 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1500 static void gen_oris(DisasContext *ctx)
1502 target_ulong uimm = UIMM(ctx->opcode);
1504 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1508 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1512 static void gen_xori(DisasContext *ctx)
1514 target_ulong uimm = UIMM(ctx->opcode);
1516 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1520 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1524 static void gen_xoris(DisasContext *ctx)
1526 target_ulong uimm = UIMM(ctx->opcode);
1528 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1532 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1535 /* popcntb : PowerPC 2.03 specification */
1536 static void gen_popcntb(DisasContext *ctx)
1538 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1541 static void gen_popcntw(DisasContext *ctx)
1543 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1546 #if defined(TARGET_PPC64)
1547 /* popcntd: PowerPC 2.06 specification */
1548 static void gen_popcntd(DisasContext *ctx)
1550 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1554 /* prtyw: PowerPC 2.05 specification */
1555 static void gen_prtyw(DisasContext *ctx)
1557 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1558 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1559 TCGv t0 = tcg_temp_new();
1560 tcg_gen_shri_tl(t0, rs, 16);
1561 tcg_gen_xor_tl(ra, rs, t0);
1562 tcg_gen_shri_tl(t0, ra, 8);
1563 tcg_gen_xor_tl(ra, ra, t0);
1564 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1568 #if defined(TARGET_PPC64)
1569 /* prtyd: PowerPC 2.05 specification */
1570 static void gen_prtyd(DisasContext *ctx)
1572 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1573 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1574 TCGv t0 = tcg_temp_new();
1575 tcg_gen_shri_tl(t0, rs, 32);
1576 tcg_gen_xor_tl(ra, rs, t0);
1577 tcg_gen_shri_tl(t0, ra, 16);
1578 tcg_gen_xor_tl(ra, ra, t0);
1579 tcg_gen_shri_tl(t0, ra, 8);
1580 tcg_gen_xor_tl(ra, ra, t0);
1581 tcg_gen_andi_tl(ra, ra, 1);
1586 #if defined(TARGET_PPC64)
1588 static void gen_bpermd(DisasContext *ctx)
1590 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1591 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1595 #if defined(TARGET_PPC64)
1596 /* extsw & extsw. */
1597 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
1600 static void gen_cntlzd(DisasContext *ctx)
1602 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1603 if (unlikely(Rc(ctx->opcode) != 0))
1604 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1608 /*** Integer rotate ***/
1610 /* rlwimi & rlwimi. */
1611 static void gen_rlwimi(DisasContext *ctx)
1613 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1614 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1615 uint32_t sh = SH(ctx->opcode);
1616 uint32_t mb = MB(ctx->opcode);
1617 uint32_t me = ME(ctx->opcode);
1619 if (sh == (31-me) && mb <= me) {
1620 tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1);
1626 #if defined(TARGET_PPC64)
1630 mask = MASK(mb, me);
1632 t0 = tcg_temp_new_i32();
1633 t1 = tcg_temp_new();
1634 tcg_gen_trunc_tl_i32(t0, t_rs);
1635 tcg_gen_rotli_i32(t0, t0, sh);
1636 tcg_gen_extu_i32_tl(t1, t0);
1637 tcg_temp_free_i32(t0);
1639 tcg_gen_andi_tl(t1, t1, mask);
1640 tcg_gen_andi_tl(t_ra, t_ra, ~mask);
1641 tcg_gen_or_tl(t_ra, t_ra, t1);
1644 if (unlikely(Rc(ctx->opcode) != 0)) {
1645 gen_set_Rc0(ctx, t_ra);
1649 /* rlwinm & rlwinm. */
1650 static void gen_rlwinm(DisasContext *ctx)
1652 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1653 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1654 uint32_t sh = SH(ctx->opcode);
1655 uint32_t mb = MB(ctx->opcode);
1656 uint32_t me = ME(ctx->opcode);
1658 if (mb == 0 && me == (31 - sh)) {
1659 tcg_gen_shli_tl(t_ra, t_rs, sh);
1660 tcg_gen_ext32u_tl(t_ra, t_ra);
1661 } else if (sh != 0 && me == 31 && sh == (32 - mb)) {
1662 tcg_gen_ext32u_tl(t_ra, t_rs);
1663 tcg_gen_shri_tl(t_ra, t_ra, mb);
1665 #if defined(TARGET_PPC64)
1670 tcg_gen_andi_tl(t_ra, t_rs, MASK(mb, me));
1672 TCGv_i32 t0 = tcg_temp_new_i32();
1674 tcg_gen_trunc_tl_i32(t0, t_rs);
1675 tcg_gen_rotli_i32(t0, t0, sh);
1676 tcg_gen_andi_i32(t0, t0, MASK(mb, me));
1677 tcg_gen_extu_i32_tl(t_ra, t0);
1678 tcg_temp_free_i32(t0);
1681 if (unlikely(Rc(ctx->opcode) != 0)) {
1682 gen_set_Rc0(ctx, t_ra);
1686 /* rlwnm & rlwnm. */
1687 static void gen_rlwnm(DisasContext *ctx)
1689 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1690 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1691 TCGv t_rb = cpu_gpr[rB(ctx->opcode)];
1692 uint32_t mb = MB(ctx->opcode);
1693 uint32_t me = ME(ctx->opcode);
1696 #if defined(TARGET_PPC64)
1701 t0 = tcg_temp_new_i32();
1702 t1 = tcg_temp_new_i32();
1703 tcg_gen_trunc_tl_i32(t0, t_rb);
1704 tcg_gen_trunc_tl_i32(t1, t_rs);
1705 tcg_gen_andi_i32(t0, t0, 0x1f);
1706 tcg_gen_rotl_i32(t1, t1, t0);
1707 tcg_temp_free_i32(t0);
1709 tcg_gen_andi_i32(t1, t1, MASK(mb, me));
1710 tcg_gen_extu_i32_tl(t_ra, t1);
1711 tcg_temp_free_i32(t1);
1713 if (unlikely(Rc(ctx->opcode) != 0)) {
1714 gen_set_Rc0(ctx, t_ra);
1718 #if defined(TARGET_PPC64)
1719 #define GEN_PPC64_R2(name, opc1, opc2) \
1720 static void glue(gen_, name##0)(DisasContext *ctx) \
1722 gen_##name(ctx, 0); \
1725 static void glue(gen_, name##1)(DisasContext *ctx) \
1727 gen_##name(ctx, 1); \
1729 #define GEN_PPC64_R4(name, opc1, opc2) \
1730 static void glue(gen_, name##0)(DisasContext *ctx) \
1732 gen_##name(ctx, 0, 0); \
1735 static void glue(gen_, name##1)(DisasContext *ctx) \
1737 gen_##name(ctx, 0, 1); \
1740 static void glue(gen_, name##2)(DisasContext *ctx) \
1742 gen_##name(ctx, 1, 0); \
1745 static void glue(gen_, name##3)(DisasContext *ctx) \
1747 gen_##name(ctx, 1, 1); \
1750 static void gen_rldinm(DisasContext *ctx, int mb, int me, int sh)
1752 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1753 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1755 if (sh != 0 && mb == 0 && me == (63 - sh)) {
1756 tcg_gen_shli_tl(t_ra, t_rs, sh);
1757 } else if (sh != 0 && me == 63 && sh == (64 - mb)) {
1758 tcg_gen_shri_tl(t_ra, t_rs, mb);
1760 tcg_gen_rotli_tl(t_ra, t_rs, sh);
1761 tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me));
1763 if (unlikely(Rc(ctx->opcode) != 0)) {
1764 gen_set_Rc0(ctx, t_ra);
1768 /* rldicl - rldicl. */
1769 static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
1773 sh = SH(ctx->opcode) | (shn << 5);
1774 mb = MB(ctx->opcode) | (mbn << 5);
1775 gen_rldinm(ctx, mb, 63, sh);
1777 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1779 /* rldicr - rldicr. */
1780 static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
1784 sh = SH(ctx->opcode) | (shn << 5);
1785 me = MB(ctx->opcode) | (men << 5);
1786 gen_rldinm(ctx, 0, me, sh);
1788 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1790 /* rldic - rldic. */
1791 static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
1795 sh = SH(ctx->opcode) | (shn << 5);
1796 mb = MB(ctx->opcode) | (mbn << 5);
1797 gen_rldinm(ctx, mb, 63 - sh, sh);
1799 GEN_PPC64_R4(rldic, 0x1E, 0x04);
1801 static void gen_rldnm(DisasContext *ctx, int mb, int me)
1803 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1804 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1805 TCGv t_rb = cpu_gpr[rB(ctx->opcode)];
1808 t0 = tcg_temp_new();
1809 tcg_gen_andi_tl(t0, t_rb, 0x3f);
1810 tcg_gen_rotl_tl(t_ra, t_rs, t0);
1813 tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me));
1814 if (unlikely(Rc(ctx->opcode) != 0)) {
1815 gen_set_Rc0(ctx, t_ra);
1819 /* rldcl - rldcl. */
1820 static inline void gen_rldcl(DisasContext *ctx, int mbn)
1824 mb = MB(ctx->opcode) | (mbn << 5);
1825 gen_rldnm(ctx, mb, 63);
1827 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1829 /* rldcr - rldcr. */
1830 static inline void gen_rldcr(DisasContext *ctx, int men)
1834 me = MB(ctx->opcode) | (men << 5);
1835 gen_rldnm(ctx, 0, me);
1837 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1839 /* rldimi - rldimi. */
1840 static void gen_rldimi(DisasContext *ctx, int mbn, int shn)
1842 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1843 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1844 uint32_t sh = SH(ctx->opcode) | (shn << 5);
1845 uint32_t mb = MB(ctx->opcode) | (mbn << 5);
1846 uint32_t me = 63 - sh;
1849 tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1);
1851 target_ulong mask = MASK(mb, me);
1852 TCGv t1 = tcg_temp_new();
1854 tcg_gen_rotli_tl(t1, t_rs, sh);
1855 tcg_gen_andi_tl(t1, t1, mask);
1856 tcg_gen_andi_tl(t_ra, t_ra, ~mask);
1857 tcg_gen_or_tl(t_ra, t_ra, t1);
1860 if (unlikely(Rc(ctx->opcode) != 0)) {
1861 gen_set_Rc0(ctx, t_ra);
1864 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1867 /*** Integer shift ***/
1870 static void gen_slw(DisasContext *ctx)
1874 t0 = tcg_temp_new();
1875 /* AND rS with a mask that is 0 when rB >= 0x20 */
1876 #if defined(TARGET_PPC64)
1877 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1878 tcg_gen_sari_tl(t0, t0, 0x3f);
1880 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1881 tcg_gen_sari_tl(t0, t0, 0x1f);
1883 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1884 t1 = tcg_temp_new();
1885 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1886 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1889 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
1890 if (unlikely(Rc(ctx->opcode) != 0))
1891 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1895 static void gen_sraw(DisasContext *ctx)
1897 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
1898 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1899 if (unlikely(Rc(ctx->opcode) != 0))
1900 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1903 /* srawi & srawi. */
1904 static void gen_srawi(DisasContext *ctx)
1906 int sh = SH(ctx->opcode);
1907 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1908 TCGv src = cpu_gpr[rS(ctx->opcode)];
1910 tcg_gen_ext32s_tl(dst, src);
1911 tcg_gen_movi_tl(cpu_ca, 0);
1914 tcg_gen_ext32s_tl(dst, src);
1915 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1916 t0 = tcg_temp_new();
1917 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1918 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1920 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1921 tcg_gen_sari_tl(dst, dst, sh);
1923 if (unlikely(Rc(ctx->opcode) != 0)) {
1924 gen_set_Rc0(ctx, dst);
1929 static void gen_srw(DisasContext *ctx)
1933 t0 = tcg_temp_new();
1934 /* AND rS with a mask that is 0 when rB >= 0x20 */
1935 #if defined(TARGET_PPC64)
1936 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1937 tcg_gen_sari_tl(t0, t0, 0x3f);
1939 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1940 tcg_gen_sari_tl(t0, t0, 0x1f);
1942 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1943 tcg_gen_ext32u_tl(t0, t0);
1944 t1 = tcg_temp_new();
1945 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1946 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1949 if (unlikely(Rc(ctx->opcode) != 0))
1950 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1953 #if defined(TARGET_PPC64)
1955 static void gen_sld(DisasContext *ctx)
1959 t0 = tcg_temp_new();
1960 /* AND rS with a mask that is 0 when rB >= 0x40 */
1961 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1962 tcg_gen_sari_tl(t0, t0, 0x3f);
1963 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1964 t1 = tcg_temp_new();
1965 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1966 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1969 if (unlikely(Rc(ctx->opcode) != 0))
1970 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1974 static void gen_srad(DisasContext *ctx)
1976 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
1977 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1978 if (unlikely(Rc(ctx->opcode) != 0))
1979 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1981 /* sradi & sradi. */
1982 static inline void gen_sradi(DisasContext *ctx, int n)
1984 int sh = SH(ctx->opcode) + (n << 5);
1985 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1986 TCGv src = cpu_gpr[rS(ctx->opcode)];
1988 tcg_gen_mov_tl(dst, src);
1989 tcg_gen_movi_tl(cpu_ca, 0);
1992 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1993 t0 = tcg_temp_new();
1994 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1995 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1997 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1998 tcg_gen_sari_tl(dst, src, sh);
2000 if (unlikely(Rc(ctx->opcode) != 0)) {
2001 gen_set_Rc0(ctx, dst);
2005 static void gen_sradi0(DisasContext *ctx)
2010 static void gen_sradi1(DisasContext *ctx)
2016 static void gen_srd(DisasContext *ctx)
2020 t0 = tcg_temp_new();
2021 /* AND rS with a mask that is 0 when rB >= 0x40 */
2022 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2023 tcg_gen_sari_tl(t0, t0, 0x3f);
2024 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2025 t1 = tcg_temp_new();
2026 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2027 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2030 if (unlikely(Rc(ctx->opcode) != 0))
2031 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2035 #if defined(TARGET_PPC64)
2036 static void gen_set_cr1_from_fpscr(DisasContext *ctx)
2038 TCGv_i32 tmp = tcg_temp_new_i32();
2039 tcg_gen_trunc_tl_i32(tmp, cpu_fpscr);
2040 tcg_gen_shri_i32(cpu_crf[1], tmp, 28);
2041 tcg_temp_free_i32(tmp);
2044 static void gen_set_cr1_from_fpscr(DisasContext *ctx)
2046 tcg_gen_shri_tl(cpu_crf[1], cpu_fpscr, 28);
2050 /*** Floating-Point arithmetic ***/
2051 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2052 static void gen_f##name(DisasContext *ctx) \
2054 if (unlikely(!ctx->fpu_enabled)) { \
2055 gen_exception(ctx, POWERPC_EXCP_FPU); \
2058 /* NIP cannot be restored if the memory exception comes from an helper */ \
2059 gen_update_nip(ctx, ctx->nip - 4); \
2060 gen_reset_fpstatus(); \
2061 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2062 cpu_fpr[rA(ctx->opcode)], \
2063 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2065 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2066 cpu_fpr[rD(ctx->opcode)]); \
2069 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2071 if (unlikely(Rc(ctx->opcode) != 0)) { \
2072 gen_set_cr1_from_fpscr(ctx); \
2076 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2077 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2078 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2080 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2081 static void gen_f##name(DisasContext *ctx) \
2083 if (unlikely(!ctx->fpu_enabled)) { \
2084 gen_exception(ctx, POWERPC_EXCP_FPU); \
2087 /* NIP cannot be restored if the memory exception comes from an helper */ \
2088 gen_update_nip(ctx, ctx->nip - 4); \
2089 gen_reset_fpstatus(); \
2090 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2091 cpu_fpr[rA(ctx->opcode)], \
2092 cpu_fpr[rB(ctx->opcode)]); \
2094 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2095 cpu_fpr[rD(ctx->opcode)]); \
2098 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2100 if (unlikely(Rc(ctx->opcode) != 0)) { \
2101 gen_set_cr1_from_fpscr(ctx); \
2104 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2105 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2106 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2108 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2109 static void gen_f##name(DisasContext *ctx) \
2111 if (unlikely(!ctx->fpu_enabled)) { \
2112 gen_exception(ctx, POWERPC_EXCP_FPU); \
2115 /* NIP cannot be restored if the memory exception comes from an helper */ \
2116 gen_update_nip(ctx, ctx->nip - 4); \
2117 gen_reset_fpstatus(); \
2118 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2119 cpu_fpr[rA(ctx->opcode)], \
2120 cpu_fpr[rC(ctx->opcode)]); \
2122 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2123 cpu_fpr[rD(ctx->opcode)]); \
2126 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2128 if (unlikely(Rc(ctx->opcode) != 0)) { \
2129 gen_set_cr1_from_fpscr(ctx); \
2132 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2133 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2134 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2136 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2137 static void gen_f##name(DisasContext *ctx) \
2139 if (unlikely(!ctx->fpu_enabled)) { \
2140 gen_exception(ctx, POWERPC_EXCP_FPU); \
2143 /* NIP cannot be restored if the memory exception comes from an helper */ \
2144 gen_update_nip(ctx, ctx->nip - 4); \
2145 gen_reset_fpstatus(); \
2146 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2147 cpu_fpr[rB(ctx->opcode)]); \
2149 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2151 if (unlikely(Rc(ctx->opcode) != 0)) { \
2152 gen_set_cr1_from_fpscr(ctx); \
2156 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2157 static void gen_f##name(DisasContext *ctx) \
2159 if (unlikely(!ctx->fpu_enabled)) { \
2160 gen_exception(ctx, POWERPC_EXCP_FPU); \
2163 /* NIP cannot be restored if the memory exception comes from an helper */ \
2164 gen_update_nip(ctx, ctx->nip - 4); \
2165 gen_reset_fpstatus(); \
2166 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2167 cpu_fpr[rB(ctx->opcode)]); \
2169 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2171 if (unlikely(Rc(ctx->opcode) != 0)) { \
2172 gen_set_cr1_from_fpscr(ctx); \
2177 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
2179 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
2181 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
2184 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
2187 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
2190 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2193 static void gen_frsqrtes(DisasContext *ctx)
2195 if (unlikely(!ctx->fpu_enabled)) {
2196 gen_exception(ctx, POWERPC_EXCP_FPU);
2199 /* NIP cannot be restored if the memory exception comes from an helper */
2200 gen_update_nip(ctx, ctx->nip - 4);
2201 gen_reset_fpstatus();
2202 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2203 cpu_fpr[rB(ctx->opcode)]);
2204 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2205 cpu_fpr[rD(ctx->opcode)]);
2206 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
2207 if (unlikely(Rc(ctx->opcode) != 0)) {
2208 gen_set_cr1_from_fpscr(ctx);
2213 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
2215 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
2219 static void gen_fsqrt(DisasContext *ctx)
2221 if (unlikely(!ctx->fpu_enabled)) {
2222 gen_exception(ctx, POWERPC_EXCP_FPU);
2225 /* NIP cannot be restored if the memory exception comes from an helper */
2226 gen_update_nip(ctx, ctx->nip - 4);
2227 gen_reset_fpstatus();
2228 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2229 cpu_fpr[rB(ctx->opcode)]);
2230 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
2231 if (unlikely(Rc(ctx->opcode) != 0)) {
2232 gen_set_cr1_from_fpscr(ctx);
2236 static void gen_fsqrts(DisasContext *ctx)
2238 if (unlikely(!ctx->fpu_enabled)) {
2239 gen_exception(ctx, POWERPC_EXCP_FPU);
2242 /* NIP cannot be restored if the memory exception comes from an helper */
2243 gen_update_nip(ctx, ctx->nip - 4);
2244 gen_reset_fpstatus();
2245 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2246 cpu_fpr[rB(ctx->opcode)]);
2247 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2248 cpu_fpr[rD(ctx->opcode)]);
2249 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
2250 if (unlikely(Rc(ctx->opcode) != 0)) {
2251 gen_set_cr1_from_fpscr(ctx);
2255 /*** Floating-Point multiply-and-add ***/
2256 /* fmadd - fmadds */
2257 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
2258 /* fmsub - fmsubs */
2259 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
2260 /* fnmadd - fnmadds */
2261 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
2262 /* fnmsub - fnmsubs */
2263 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
2265 /*** Floating-Point round & convert ***/
2267 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
2269 GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
2271 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
2273 GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
2275 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
2277 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC2_FP_CVT_S64);
2279 GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2281 GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2283 GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2285 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC2_FP_CVT_S64);
2287 GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
2289 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC2_FP_CVT_S64);
2291 GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
2294 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
2296 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
2298 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
2300 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
2302 static void gen_ftdiv(DisasContext *ctx)
2304 if (unlikely(!ctx->fpu_enabled)) {
2305 gen_exception(ctx, POWERPC_EXCP_FPU);
2308 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2309 cpu_fpr[rB(ctx->opcode)]);
2312 static void gen_ftsqrt(DisasContext *ctx)
2314 if (unlikely(!ctx->fpu_enabled)) {
2315 gen_exception(ctx, POWERPC_EXCP_FPU);
2318 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2323 /*** Floating-Point compare ***/
2326 static void gen_fcmpo(DisasContext *ctx)
2329 if (unlikely(!ctx->fpu_enabled)) {
2330 gen_exception(ctx, POWERPC_EXCP_FPU);
2333 /* NIP cannot be restored if the memory exception comes from an helper */
2334 gen_update_nip(ctx, ctx->nip - 4);
2335 gen_reset_fpstatus();
2336 crf = tcg_const_i32(crfD(ctx->opcode));
2337 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2338 cpu_fpr[rB(ctx->opcode)], crf);
2339 tcg_temp_free_i32(crf);
2340 gen_helper_float_check_status(cpu_env);
2344 static void gen_fcmpu(DisasContext *ctx)
2347 if (unlikely(!ctx->fpu_enabled)) {
2348 gen_exception(ctx, POWERPC_EXCP_FPU);
2351 /* NIP cannot be restored if the memory exception comes from an helper */
2352 gen_update_nip(ctx, ctx->nip - 4);
2353 gen_reset_fpstatus();
2354 crf = tcg_const_i32(crfD(ctx->opcode));
2355 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2356 cpu_fpr[rB(ctx->opcode)], crf);
2357 tcg_temp_free_i32(crf);
2358 gen_helper_float_check_status(cpu_env);
2361 /*** Floating-point move ***/
2363 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2364 static void gen_fabs(DisasContext *ctx)
2366 if (unlikely(!ctx->fpu_enabled)) {
2367 gen_exception(ctx, POWERPC_EXCP_FPU);
2370 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2372 if (unlikely(Rc(ctx->opcode))) {
2373 gen_set_cr1_from_fpscr(ctx);
2378 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2379 static void gen_fmr(DisasContext *ctx)
2381 if (unlikely(!ctx->fpu_enabled)) {
2382 gen_exception(ctx, POWERPC_EXCP_FPU);
2385 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2386 if (unlikely(Rc(ctx->opcode))) {
2387 gen_set_cr1_from_fpscr(ctx);
2392 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2393 static void gen_fnabs(DisasContext *ctx)
2395 if (unlikely(!ctx->fpu_enabled)) {
2396 gen_exception(ctx, POWERPC_EXCP_FPU);
2399 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2401 if (unlikely(Rc(ctx->opcode))) {
2402 gen_set_cr1_from_fpscr(ctx);
2407 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2408 static void gen_fneg(DisasContext *ctx)
2410 if (unlikely(!ctx->fpu_enabled)) {
2411 gen_exception(ctx, POWERPC_EXCP_FPU);
2414 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2416 if (unlikely(Rc(ctx->opcode))) {
2417 gen_set_cr1_from_fpscr(ctx);
2421 /* fcpsgn: PowerPC 2.05 specification */
2422 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2423 static void gen_fcpsgn(DisasContext *ctx)
2425 if (unlikely(!ctx->fpu_enabled)) {
2426 gen_exception(ctx, POWERPC_EXCP_FPU);
2429 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2430 cpu_fpr[rB(ctx->opcode)], 0, 63);
2431 if (unlikely(Rc(ctx->opcode))) {
2432 gen_set_cr1_from_fpscr(ctx);
2436 static void gen_fmrgew(DisasContext *ctx)
2439 if (unlikely(!ctx->fpu_enabled)) {
2440 gen_exception(ctx, POWERPC_EXCP_FPU);
2443 b0 = tcg_temp_new_i64();
2444 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2445 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2447 tcg_temp_free_i64(b0);
2450 static void gen_fmrgow(DisasContext *ctx)
2452 if (unlikely(!ctx->fpu_enabled)) {
2453 gen_exception(ctx, POWERPC_EXCP_FPU);
2456 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2457 cpu_fpr[rB(ctx->opcode)],
2458 cpu_fpr[rA(ctx->opcode)],
2462 /*** Floating-Point status & ctrl register ***/
2465 static void gen_mcrfs(DisasContext *ctx)
2467 TCGv tmp = tcg_temp_new();
2469 TCGv_i64 tnew_fpscr = tcg_temp_new_i64();
2474 if (unlikely(!ctx->fpu_enabled)) {
2475 gen_exception(ctx, POWERPC_EXCP_FPU);
2478 bfa = crfS(ctx->opcode);
2481 tcg_gen_shri_tl(tmp, cpu_fpscr, shift);
2482 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2483 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
2485 tcg_gen_extu_tl_i64(tnew_fpscr, cpu_fpscr);
2486 /* Only the exception bits (including FX) should be cleared if read */
2487 tcg_gen_andi_i64(tnew_fpscr, tnew_fpscr, ~((0xF << shift) & FP_EX_CLEAR_BITS));
2488 /* FEX and VX need to be updated, so don't set fpscr directly */
2489 tmask = tcg_const_i32(1 << nibble);
2490 gen_helper_store_fpscr(cpu_env, tnew_fpscr, tmask);
2491 tcg_temp_free_i32(tmask);
2492 tcg_temp_free_i64(tnew_fpscr);
2496 static void gen_mffs(DisasContext *ctx)
2498 if (unlikely(!ctx->fpu_enabled)) {
2499 gen_exception(ctx, POWERPC_EXCP_FPU);
2502 gen_reset_fpstatus();
2503 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
2504 if (unlikely(Rc(ctx->opcode))) {
2505 gen_set_cr1_from_fpscr(ctx);
2510 static void gen_mtfsb0(DisasContext *ctx)
2514 if (unlikely(!ctx->fpu_enabled)) {
2515 gen_exception(ctx, POWERPC_EXCP_FPU);
2518 crb = 31 - crbD(ctx->opcode);
2519 gen_reset_fpstatus();
2520 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
2522 /* NIP cannot be restored if the memory exception comes from an helper */
2523 gen_update_nip(ctx, ctx->nip - 4);
2524 t0 = tcg_const_i32(crb);
2525 gen_helper_fpscr_clrbit(cpu_env, t0);
2526 tcg_temp_free_i32(t0);
2528 if (unlikely(Rc(ctx->opcode) != 0)) {
2529 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2530 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2535 static void gen_mtfsb1(DisasContext *ctx)
2539 if (unlikely(!ctx->fpu_enabled)) {
2540 gen_exception(ctx, POWERPC_EXCP_FPU);
2543 crb = 31 - crbD(ctx->opcode);
2544 gen_reset_fpstatus();
2545 /* XXX: we pretend we can only do IEEE floating-point computations */
2546 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
2548 /* NIP cannot be restored if the memory exception comes from an helper */
2549 gen_update_nip(ctx, ctx->nip - 4);
2550 t0 = tcg_const_i32(crb);
2551 gen_helper_fpscr_setbit(cpu_env, t0);
2552 tcg_temp_free_i32(t0);
2554 if (unlikely(Rc(ctx->opcode) != 0)) {
2555 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2556 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2558 /* We can raise a differed exception */
2559 gen_helper_float_check_status(cpu_env);
2563 static void gen_mtfsf(DisasContext *ctx)
2568 if (unlikely(!ctx->fpu_enabled)) {
2569 gen_exception(ctx, POWERPC_EXCP_FPU);
2572 flm = FPFLM(ctx->opcode);
2573 l = FPL(ctx->opcode);
2574 w = FPW(ctx->opcode);
2575 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2576 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2579 /* NIP cannot be restored if the memory exception comes from an helper */
2580 gen_update_nip(ctx, ctx->nip - 4);
2581 gen_reset_fpstatus();
2583 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2585 t0 = tcg_const_i32(flm << (w * 8));
2587 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
2588 tcg_temp_free_i32(t0);
2589 if (unlikely(Rc(ctx->opcode) != 0)) {
2590 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2591 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2593 /* We can raise a differed exception */
2594 gen_helper_float_check_status(cpu_env);
2598 static void gen_mtfsfi(DisasContext *ctx)
2604 if (unlikely(!ctx->fpu_enabled)) {
2605 gen_exception(ctx, POWERPC_EXCP_FPU);
2608 w = FPW(ctx->opcode);
2609 bf = FPBF(ctx->opcode);
2610 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2611 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2614 sh = (8 * w) + 7 - bf;
2615 /* NIP cannot be restored if the memory exception comes from an helper */
2616 gen_update_nip(ctx, ctx->nip - 4);
2617 gen_reset_fpstatus();
2618 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
2619 t1 = tcg_const_i32(1 << sh);
2620 gen_helper_store_fpscr(cpu_env, t0, t1);
2621 tcg_temp_free_i64(t0);
2622 tcg_temp_free_i32(t1);
2623 if (unlikely(Rc(ctx->opcode) != 0)) {
2624 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2625 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2627 /* We can raise a differed exception */
2628 gen_helper_float_check_status(cpu_env);
2631 /*** Addressing modes ***/
2632 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2633 static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2636 target_long simm = SIMM(ctx->opcode);
2639 if (rA(ctx->opcode) == 0) {
2640 if (NARROW_MODE(ctx)) {
2641 simm = (uint32_t)simm;
2643 tcg_gen_movi_tl(EA, simm);
2644 } else if (likely(simm != 0)) {
2645 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2646 if (NARROW_MODE(ctx)) {
2647 tcg_gen_ext32u_tl(EA, EA);
2650 if (NARROW_MODE(ctx)) {
2651 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2653 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2658 static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
2660 if (rA(ctx->opcode) == 0) {
2661 if (NARROW_MODE(ctx)) {
2662 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2664 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2667 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2668 if (NARROW_MODE(ctx)) {
2669 tcg_gen_ext32u_tl(EA, EA);
2674 static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
2676 if (rA(ctx->opcode) == 0) {
2677 tcg_gen_movi_tl(EA, 0);
2678 } else if (NARROW_MODE(ctx)) {
2679 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2681 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2685 static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2688 tcg_gen_addi_tl(ret, arg1, val);
2689 if (NARROW_MODE(ctx)) {
2690 tcg_gen_ext32u_tl(ret, ret);
2694 static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
2696 TCGLabel *l1 = gen_new_label();
2697 TCGv t0 = tcg_temp_new();
2699 /* NIP cannot be restored if the memory exception comes from an helper */
2700 gen_update_nip(ctx, ctx->nip - 4);
2701 tcg_gen_andi_tl(t0, EA, mask);
2702 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2703 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2704 t2 = tcg_const_i32(0);
2705 gen_helper_raise_exception_err(cpu_env, t1, t2);
2706 tcg_temp_free_i32(t1);
2707 tcg_temp_free_i32(t2);
2712 /*** Integer load ***/
2713 static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2715 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2718 static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2720 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2721 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
2724 static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2726 TCGMemOp op = MO_SW | ctx->default_tcg_memop_mask;
2727 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
2730 static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2732 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2733 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
2736 static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2738 TCGv tmp = tcg_temp_new();
2739 gen_qemu_ld32u(ctx, tmp, addr);
2740 tcg_gen_extu_tl_i64(val, tmp);
2744 static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2746 TCGMemOp op = MO_SL | ctx->default_tcg_memop_mask;
2747 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
2750 static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2752 TCGv tmp = tcg_temp_new();
2753 gen_qemu_ld32s(ctx, tmp, addr);
2754 tcg_gen_ext_tl_i64(val, tmp);
2758 static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2760 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2761 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
2764 static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
2766 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
2769 static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
2771 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2772 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
2775 static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
2777 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2778 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
2781 static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2783 TCGv tmp = tcg_temp_new();
2784 tcg_gen_trunc_i64_tl(tmp, val);
2785 gen_qemu_st32(ctx, tmp, addr);
2789 static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2791 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2792 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
2795 #define GEN_LD(name, ldop, opc, type) \
2796 static void glue(gen_, name)(DisasContext *ctx) \
2799 gen_set_access_type(ctx, ACCESS_INT); \
2800 EA = tcg_temp_new(); \
2801 gen_addr_imm_index(ctx, EA, 0); \
2802 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2803 tcg_temp_free(EA); \
2806 #define GEN_LDU(name, ldop, opc, type) \
2807 static void glue(gen_, name##u)(DisasContext *ctx) \
2810 if (unlikely(rA(ctx->opcode) == 0 || \
2811 rA(ctx->opcode) == rD(ctx->opcode))) { \
2812 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2815 gen_set_access_type(ctx, ACCESS_INT); \
2816 EA = tcg_temp_new(); \
2817 if (type == PPC_64B) \
2818 gen_addr_imm_index(ctx, EA, 0x03); \
2820 gen_addr_imm_index(ctx, EA, 0); \
2821 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2822 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2823 tcg_temp_free(EA); \
2826 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2827 static void glue(gen_, name##ux)(DisasContext *ctx) \
2830 if (unlikely(rA(ctx->opcode) == 0 || \
2831 rA(ctx->opcode) == rD(ctx->opcode))) { \
2832 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2835 gen_set_access_type(ctx, ACCESS_INT); \
2836 EA = tcg_temp_new(); \
2837 gen_addr_reg_index(ctx, EA); \
2838 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2839 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2840 tcg_temp_free(EA); \
2843 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2844 static void glue(gen_, name##x)(DisasContext *ctx) \
2847 gen_set_access_type(ctx, ACCESS_INT); \
2848 EA = tcg_temp_new(); \
2849 gen_addr_reg_index(ctx, EA); \
2850 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2851 tcg_temp_free(EA); \
2853 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2854 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2856 #define GEN_LDS(name, ldop, op, type) \
2857 GEN_LD(name, ldop, op | 0x20, type); \
2858 GEN_LDU(name, ldop, op | 0x21, type); \
2859 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2860 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2862 /* lbz lbzu lbzux lbzx */
2863 GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
2864 /* lha lhau lhaux lhax */
2865 GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
2866 /* lhz lhzu lhzux lhzx */
2867 GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
2868 /* lwz lwzu lwzux lwzx */
2869 GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
2870 #if defined(TARGET_PPC64)
2872 GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
2874 GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
2876 GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
2878 GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
2880 static void gen_ld(DisasContext *ctx)
2883 if (Rc(ctx->opcode)) {
2884 if (unlikely(rA(ctx->opcode) == 0 ||
2885 rA(ctx->opcode) == rD(ctx->opcode))) {
2886 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2890 gen_set_access_type(ctx, ACCESS_INT);
2891 EA = tcg_temp_new();
2892 gen_addr_imm_index(ctx, EA, 0x03);
2893 if (ctx->opcode & 0x02) {
2894 /* lwa (lwau is undefined) */
2895 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
2898 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
2900 if (Rc(ctx->opcode))
2901 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2906 static void gen_lq(DisasContext *ctx)
2911 /* lq is a legal user mode instruction starting in ISA 2.07 */
2912 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2913 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2915 if (!legal_in_user_mode && ctx->pr) {
2916 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2920 if (!le_is_supported && ctx->le_mode) {
2921 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2925 ra = rA(ctx->opcode);
2926 rd = rD(ctx->opcode);
2927 if (unlikely((rd & 1) || rd == ra)) {
2928 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2932 gen_set_access_type(ctx, ACCESS_INT);
2933 EA = tcg_temp_new();
2934 gen_addr_imm_index(ctx, EA, 0x0F);
2936 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
2937 64-bit byteswap already. */
2938 if (unlikely(ctx->le_mode)) {
2939 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2940 gen_addr_add(ctx, EA, EA, 8);
2941 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2943 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2944 gen_addr_add(ctx, EA, EA, 8);
2945 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2951 /*** Integer store ***/
2952 #define GEN_ST(name, stop, opc, type) \
2953 static void glue(gen_, name)(DisasContext *ctx) \
2956 gen_set_access_type(ctx, ACCESS_INT); \
2957 EA = tcg_temp_new(); \
2958 gen_addr_imm_index(ctx, EA, 0); \
2959 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2960 tcg_temp_free(EA); \
2963 #define GEN_STU(name, stop, opc, type) \
2964 static void glue(gen_, stop##u)(DisasContext *ctx) \
2967 if (unlikely(rA(ctx->opcode) == 0)) { \
2968 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2971 gen_set_access_type(ctx, ACCESS_INT); \
2972 EA = tcg_temp_new(); \
2973 if (type == PPC_64B) \
2974 gen_addr_imm_index(ctx, EA, 0x03); \
2976 gen_addr_imm_index(ctx, EA, 0); \
2977 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2978 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2979 tcg_temp_free(EA); \
2982 #define GEN_STUX(name, stop, opc2, opc3, type) \
2983 static void glue(gen_, name##ux)(DisasContext *ctx) \
2986 if (unlikely(rA(ctx->opcode) == 0)) { \
2987 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2990 gen_set_access_type(ctx, ACCESS_INT); \
2991 EA = tcg_temp_new(); \
2992 gen_addr_reg_index(ctx, EA); \
2993 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2994 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2995 tcg_temp_free(EA); \
2998 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2999 static void glue(gen_, name##x)(DisasContext *ctx) \
3002 gen_set_access_type(ctx, ACCESS_INT); \
3003 EA = tcg_temp_new(); \
3004 gen_addr_reg_index(ctx, EA); \
3005 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3006 tcg_temp_free(EA); \
3008 #define GEN_STX(name, stop, opc2, opc3, type) \
3009 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
3011 #define GEN_STS(name, stop, op, type) \
3012 GEN_ST(name, stop, op | 0x20, type); \
3013 GEN_STU(name, stop, op | 0x21, type); \
3014 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3015 GEN_STX(name, stop, 0x17, op | 0x00, type)
3017 /* stb stbu stbux stbx */
3018 GEN_STS(stb, st8, 0x06, PPC_INTEGER);
3019 /* sth sthu sthux sthx */
3020 GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
3021 /* stw stwu stwux stwx */
3022 GEN_STS(stw, st32, 0x04, PPC_INTEGER);
3023 #if defined(TARGET_PPC64)
3024 GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
3025 GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
3027 static void gen_std(DisasContext *ctx)
3032 rs = rS(ctx->opcode);
3033 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3035 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3036 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3038 if (!legal_in_user_mode && ctx->pr) {
3039 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3043 if (!le_is_supported && ctx->le_mode) {
3044 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
3048 if (unlikely(rs & 1)) {
3049 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3052 gen_set_access_type(ctx, ACCESS_INT);
3053 EA = tcg_temp_new();
3054 gen_addr_imm_index(ctx, EA, 0x03);
3056 /* We only need to swap high and low halves. gen_qemu_st64 does
3057 necessary 64-bit byteswap already. */
3058 if (unlikely(ctx->le_mode)) {
3059 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3060 gen_addr_add(ctx, EA, EA, 8);
3061 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3063 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3064 gen_addr_add(ctx, EA, EA, 8);
3065 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3070 if (Rc(ctx->opcode)) {
3071 if (unlikely(rA(ctx->opcode) == 0)) {
3072 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3076 gen_set_access_type(ctx, ACCESS_INT);
3077 EA = tcg_temp_new();
3078 gen_addr_imm_index(ctx, EA, 0x03);
3079 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3080 if (Rc(ctx->opcode))
3081 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3086 /*** Integer load and store with byte reverse ***/
3089 static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3091 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3092 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
3094 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
3097 static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3099 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3100 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
3102 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
3104 #if defined(TARGET_PPC64)
3106 static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3108 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3109 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
3111 GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3112 #endif /* TARGET_PPC64 */
3115 static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3117 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3118 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
3120 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
3123 static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3125 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3126 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
3128 GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
3130 #if defined(TARGET_PPC64)
3132 static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3134 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3135 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
3137 GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3138 #endif /* TARGET_PPC64 */
3140 /*** Integer load and store multiple ***/
3143 static void gen_lmw(DisasContext *ctx)
3147 gen_set_access_type(ctx, ACCESS_INT);
3148 /* NIP cannot be restored if the memory exception comes from an helper */
3149 gen_update_nip(ctx, ctx->nip - 4);
3150 t0 = tcg_temp_new();
3151 t1 = tcg_const_i32(rD(ctx->opcode));
3152 gen_addr_imm_index(ctx, t0, 0);
3153 gen_helper_lmw(cpu_env, t0, t1);
3155 tcg_temp_free_i32(t1);
3159 static void gen_stmw(DisasContext *ctx)
3163 gen_set_access_type(ctx, ACCESS_INT);
3164 /* NIP cannot be restored if the memory exception comes from an helper */
3165 gen_update_nip(ctx, ctx->nip - 4);
3166 t0 = tcg_temp_new();
3167 t1 = tcg_const_i32(rS(ctx->opcode));
3168 gen_addr_imm_index(ctx, t0, 0);
3169 gen_helper_stmw(cpu_env, t0, t1);
3171 tcg_temp_free_i32(t1);
3174 /*** Integer load and store strings ***/
3177 /* PowerPC32 specification says we must generate an exception if
3178 * rA is in the range of registers to be loaded.
3179 * In an other hand, IBM says this is valid, but rA won't be loaded.
3180 * For now, I'll follow the spec...
3182 static void gen_lswi(DisasContext *ctx)
3186 int nb = NB(ctx->opcode);
3187 int start = rD(ctx->opcode);
3188 int ra = rA(ctx->opcode);
3194 if (unlikely(lsw_reg_in_range(start, nr, ra))) {
3195 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
3198 gen_set_access_type(ctx, ACCESS_INT);
3199 /* NIP cannot be restored if the memory exception comes from an helper */
3200 gen_update_nip(ctx, ctx->nip - 4);
3201 t0 = tcg_temp_new();
3202 gen_addr_register(ctx, t0);
3203 t1 = tcg_const_i32(nb);
3204 t2 = tcg_const_i32(start);
3205 gen_helper_lsw(cpu_env, t0, t1, t2);
3207 tcg_temp_free_i32(t1);
3208 tcg_temp_free_i32(t2);
3212 static void gen_lswx(DisasContext *ctx)
3215 TCGv_i32 t1, t2, t3;
3216 gen_set_access_type(ctx, ACCESS_INT);
3217 /* NIP cannot be restored if the memory exception comes from an helper */
3218 gen_update_nip(ctx, ctx->nip - 4);
3219 t0 = tcg_temp_new();
3220 gen_addr_reg_index(ctx, t0);
3221 t1 = tcg_const_i32(rD(ctx->opcode));
3222 t2 = tcg_const_i32(rA(ctx->opcode));
3223 t3 = tcg_const_i32(rB(ctx->opcode));
3224 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
3226 tcg_temp_free_i32(t1);
3227 tcg_temp_free_i32(t2);
3228 tcg_temp_free_i32(t3);
3232 static void gen_stswi(DisasContext *ctx)
3236 int nb = NB(ctx->opcode);
3237 gen_set_access_type(ctx, ACCESS_INT);
3238 /* NIP cannot be restored if the memory exception comes from an helper */
3239 gen_update_nip(ctx, ctx->nip - 4);
3240 t0 = tcg_temp_new();
3241 gen_addr_register(ctx, t0);
3244 t1 = tcg_const_i32(nb);
3245 t2 = tcg_const_i32(rS(ctx->opcode));
3246 gen_helper_stsw(cpu_env, t0, t1, t2);
3248 tcg_temp_free_i32(t1);
3249 tcg_temp_free_i32(t2);
3253 static void gen_stswx(DisasContext *ctx)
3257 gen_set_access_type(ctx, ACCESS_INT);
3258 /* NIP cannot be restored if the memory exception comes from an helper */
3259 gen_update_nip(ctx, ctx->nip - 4);
3260 t0 = tcg_temp_new();
3261 gen_addr_reg_index(ctx, t0);
3262 t1 = tcg_temp_new_i32();
3263 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3264 tcg_gen_andi_i32(t1, t1, 0x7F);
3265 t2 = tcg_const_i32(rS(ctx->opcode));
3266 gen_helper_stsw(cpu_env, t0, t1, t2);
3268 tcg_temp_free_i32(t1);
3269 tcg_temp_free_i32(t2);
3272 /*** Memory synchronisation ***/
3274 static void gen_eieio(DisasContext *ctx)
3278 #if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
3279 static inline void gen_check_tlb_flush(DisasContext *ctx)
3281 TCGv_i32 t = tcg_temp_new_i32();
3282 TCGLabel *l = gen_new_label();
3284 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, tlb_need_flush));
3285 tcg_gen_brcondi_i32(TCG_COND_EQ, t, 0, l);
3286 gen_helper_check_tlb_flush(cpu_env);
3288 tcg_temp_free_i32(t);
3291 static inline void gen_check_tlb_flush(DisasContext *ctx) { }
3295 static void gen_isync(DisasContext *ctx)
3298 * We need to check for a pending TLB flush. This can only happen in
3299 * kernel mode however so check MSR_PR
3302 gen_check_tlb_flush(ctx);
3304 gen_stop_exception(ctx);
3307 #define LARX(name, len, loadop) \
3308 static void gen_##name(DisasContext *ctx) \
3311 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3312 gen_set_access_type(ctx, ACCESS_RES); \
3313 t0 = tcg_temp_local_new(); \
3314 gen_addr_reg_index(ctx, t0); \
3316 gen_check_align(ctx, t0, (len)-1); \
3318 gen_qemu_##loadop(ctx, gpr, t0); \
3319 tcg_gen_mov_tl(cpu_reserve, t0); \
3320 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3321 tcg_temp_free(t0); \
3325 LARX(lbarx, 1, ld8u);
3326 LARX(lharx, 2, ld16u);
3327 LARX(lwarx, 4, ld32u);
3330 #if defined(CONFIG_USER_ONLY)
3331 static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3334 TCGv t0 = tcg_temp_new();
3335 uint32_t save_exception = ctx->exception;
3337 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
3338 tcg_gen_movi_tl(t0, (size << 5) | reg);
3339 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
3341 gen_update_nip(ctx, ctx->nip-4);
3342 ctx->exception = POWERPC_EXCP_BRANCH;
3343 gen_exception(ctx, POWERPC_EXCP_STCX);
3344 ctx->exception = save_exception;
3347 static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3352 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3353 l1 = gen_new_label();
3354 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3355 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3356 #if defined(TARGET_PPC64)
3358 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3362 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3363 } else if (size == 2) {
3364 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
3365 #if defined(TARGET_PPC64)
3366 } else if (size == 16) {
3367 TCGv gpr1, gpr2 , EA8;
3368 if (unlikely(ctx->le_mode)) {
3369 gpr1 = cpu_gpr[reg+1];
3370 gpr2 = cpu_gpr[reg];
3372 gpr1 = cpu_gpr[reg];
3373 gpr2 = cpu_gpr[reg+1];
3375 gen_qemu_st64(ctx, gpr1, EA);
3376 EA8 = tcg_temp_local_new();
3377 gen_addr_add(ctx, EA8, EA, 8);
3378 gen_qemu_st64(ctx, gpr2, EA8);
3382 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
3385 tcg_gen_movi_tl(cpu_reserve, -1);
3389 #define STCX(name, len) \
3390 static void gen_##name(DisasContext *ctx) \
3393 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3394 gen_inval_exception(ctx, \
3395 POWERPC_EXCP_INVAL_INVAL); \
3398 gen_set_access_type(ctx, ACCESS_RES); \
3399 t0 = tcg_temp_local_new(); \
3400 gen_addr_reg_index(ctx, t0); \
3402 gen_check_align(ctx, t0, (len)-1); \
3404 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3405 tcg_temp_free(t0); \
3412 #if defined(TARGET_PPC64)
3414 LARX(ldarx, 8, ld64);
3417 static void gen_lqarx(DisasContext *ctx)
3420 int rd = rD(ctx->opcode);
3423 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3424 (rd == rB(ctx->opcode)))) {
3425 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3429 gen_set_access_type(ctx, ACCESS_RES);
3430 EA = tcg_temp_local_new();
3431 gen_addr_reg_index(ctx, EA);
3432 gen_check_align(ctx, EA, 15);
3433 if (unlikely(ctx->le_mode)) {
3434 gpr1 = cpu_gpr[rd+1];
3438 gpr2 = cpu_gpr[rd+1];
3440 gen_qemu_ld64(ctx, gpr1, EA);
3441 tcg_gen_mov_tl(cpu_reserve, EA);
3443 gen_addr_add(ctx, EA, EA, 8);
3444 gen_qemu_ld64(ctx, gpr2, EA);
3446 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3447 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3455 #endif /* defined(TARGET_PPC64) */
3458 static void gen_sync(DisasContext *ctx)
3460 uint32_t l = (ctx->opcode >> 21) & 3;
3463 * For l == 2, it's a ptesync, We need to check for a pending TLB flush.
3464 * This can only happen in kernel mode however so check MSR_PR as well.
3466 if (l == 2 && !ctx->pr) {
3467 gen_check_tlb_flush(ctx);
3472 static void gen_wait(DisasContext *ctx)
3474 TCGv_i32 t0 = tcg_temp_new_i32();
3475 tcg_gen_st_i32(t0, cpu_env,
3476 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
3477 tcg_temp_free_i32(t0);
3478 /* Stop translation, as the CPU is supposed to sleep from now */
3479 gen_exception_err(ctx, EXCP_HLT, 1);
3482 /*** Floating-point load ***/
3483 #define GEN_LDF(name, ldop, opc, type) \
3484 static void glue(gen_, name)(DisasContext *ctx) \
3487 if (unlikely(!ctx->fpu_enabled)) { \
3488 gen_exception(ctx, POWERPC_EXCP_FPU); \
3491 gen_set_access_type(ctx, ACCESS_FLOAT); \
3492 EA = tcg_temp_new(); \
3493 gen_addr_imm_index(ctx, EA, 0); \
3494 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3495 tcg_temp_free(EA); \
3498 #define GEN_LDUF(name, ldop, opc, type) \
3499 static void glue(gen_, name##u)(DisasContext *ctx) \
3502 if (unlikely(!ctx->fpu_enabled)) { \
3503 gen_exception(ctx, POWERPC_EXCP_FPU); \
3506 if (unlikely(rA(ctx->opcode) == 0)) { \
3507 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3510 gen_set_access_type(ctx, ACCESS_FLOAT); \
3511 EA = tcg_temp_new(); \
3512 gen_addr_imm_index(ctx, EA, 0); \
3513 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3514 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3515 tcg_temp_free(EA); \
3518 #define GEN_LDUXF(name, ldop, opc, type) \
3519 static void glue(gen_, name##ux)(DisasContext *ctx) \
3522 if (unlikely(!ctx->fpu_enabled)) { \
3523 gen_exception(ctx, POWERPC_EXCP_FPU); \
3526 if (unlikely(rA(ctx->opcode) == 0)) { \
3527 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3530 gen_set_access_type(ctx, ACCESS_FLOAT); \
3531 EA = tcg_temp_new(); \
3532 gen_addr_reg_index(ctx, EA); \
3533 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3534 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3535 tcg_temp_free(EA); \
3538 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3539 static void glue(gen_, name##x)(DisasContext *ctx) \
3542 if (unlikely(!ctx->fpu_enabled)) { \
3543 gen_exception(ctx, POWERPC_EXCP_FPU); \
3546 gen_set_access_type(ctx, ACCESS_FLOAT); \
3547 EA = tcg_temp_new(); \
3548 gen_addr_reg_index(ctx, EA); \
3549 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3550 tcg_temp_free(EA); \
3553 #define GEN_LDFS(name, ldop, op, type) \
3554 GEN_LDF(name, ldop, op | 0x20, type); \
3555 GEN_LDUF(name, ldop, op | 0x21, type); \
3556 GEN_LDUXF(name, ldop, op | 0x01, type); \
3557 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3559 static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3561 TCGv t0 = tcg_temp_new();
3562 TCGv_i32 t1 = tcg_temp_new_i32();
3563 gen_qemu_ld32u(ctx, t0, arg2);
3564 tcg_gen_trunc_tl_i32(t1, t0);
3566 gen_helper_float32_to_float64(arg1, cpu_env, t1);
3567 tcg_temp_free_i32(t1);
3570 /* lfd lfdu lfdux lfdx */
3571 GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3572 /* lfs lfsu lfsux lfsx */
3573 GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
3576 static void gen_lfdp(DisasContext *ctx)
3579 if (unlikely(!ctx->fpu_enabled)) {
3580 gen_exception(ctx, POWERPC_EXCP_FPU);
3583 gen_set_access_type(ctx, ACCESS_FLOAT);
3584 EA = tcg_temp_new();
3585 gen_addr_imm_index(ctx, EA, 0);
3586 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3587 64-bit byteswap already. */
3588 if (unlikely(ctx->le_mode)) {
3589 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3590 tcg_gen_addi_tl(EA, EA, 8);
3591 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3593 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3594 tcg_gen_addi_tl(EA, EA, 8);
3595 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3601 static void gen_lfdpx(DisasContext *ctx)
3604 if (unlikely(!ctx->fpu_enabled)) {
3605 gen_exception(ctx, POWERPC_EXCP_FPU);
3608 gen_set_access_type(ctx, ACCESS_FLOAT);
3609 EA = tcg_temp_new();
3610 gen_addr_reg_index(ctx, EA);
3611 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3612 64-bit byteswap already. */
3613 if (unlikely(ctx->le_mode)) {
3614 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3615 tcg_gen_addi_tl(EA, EA, 8);
3616 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3618 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3619 tcg_gen_addi_tl(EA, EA, 8);
3620 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3626 static void gen_lfiwax(DisasContext *ctx)
3630 if (unlikely(!ctx->fpu_enabled)) {
3631 gen_exception(ctx, POWERPC_EXCP_FPU);
3634 gen_set_access_type(ctx, ACCESS_FLOAT);
3635 EA = tcg_temp_new();
3636 t0 = tcg_temp_new();
3637 gen_addr_reg_index(ctx, EA);
3638 gen_qemu_ld32s(ctx, t0, EA);
3639 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
3645 static void gen_lfiwzx(DisasContext *ctx)
3648 if (unlikely(!ctx->fpu_enabled)) {
3649 gen_exception(ctx, POWERPC_EXCP_FPU);
3652 gen_set_access_type(ctx, ACCESS_FLOAT);
3653 EA = tcg_temp_new();
3654 gen_addr_reg_index(ctx, EA);
3655 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3658 /*** Floating-point store ***/
3659 #define GEN_STF(name, stop, opc, type) \
3660 static void glue(gen_, name)(DisasContext *ctx) \
3663 if (unlikely(!ctx->fpu_enabled)) { \
3664 gen_exception(ctx, POWERPC_EXCP_FPU); \
3667 gen_set_access_type(ctx, ACCESS_FLOAT); \
3668 EA = tcg_temp_new(); \
3669 gen_addr_imm_index(ctx, EA, 0); \
3670 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3671 tcg_temp_free(EA); \
3674 #define GEN_STUF(name, stop, opc, type) \
3675 static void glue(gen_, name##u)(DisasContext *ctx) \
3678 if (unlikely(!ctx->fpu_enabled)) { \
3679 gen_exception(ctx, POWERPC_EXCP_FPU); \
3682 if (unlikely(rA(ctx->opcode) == 0)) { \
3683 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3686 gen_set_access_type(ctx, ACCESS_FLOAT); \
3687 EA = tcg_temp_new(); \
3688 gen_addr_imm_index(ctx, EA, 0); \
3689 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3690 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3691 tcg_temp_free(EA); \
3694 #define GEN_STUXF(name, stop, opc, type) \
3695 static void glue(gen_, name##ux)(DisasContext *ctx) \
3698 if (unlikely(!ctx->fpu_enabled)) { \
3699 gen_exception(ctx, POWERPC_EXCP_FPU); \
3702 if (unlikely(rA(ctx->opcode) == 0)) { \
3703 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3706 gen_set_access_type(ctx, ACCESS_FLOAT); \
3707 EA = tcg_temp_new(); \
3708 gen_addr_reg_index(ctx, EA); \
3709 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3710 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3711 tcg_temp_free(EA); \
3714 #define GEN_STXF(name, stop, opc2, opc3, type) \
3715 static void glue(gen_, name##x)(DisasContext *ctx) \
3718 if (unlikely(!ctx->fpu_enabled)) { \
3719 gen_exception(ctx, POWERPC_EXCP_FPU); \
3722 gen_set_access_type(ctx, ACCESS_FLOAT); \
3723 EA = tcg_temp_new(); \
3724 gen_addr_reg_index(ctx, EA); \
3725 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3726 tcg_temp_free(EA); \
3729 #define GEN_STFS(name, stop, op, type) \
3730 GEN_STF(name, stop, op | 0x20, type); \
3731 GEN_STUF(name, stop, op | 0x21, type); \
3732 GEN_STUXF(name, stop, op | 0x01, type); \
3733 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3735 static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3737 TCGv_i32 t0 = tcg_temp_new_i32();
3738 TCGv t1 = tcg_temp_new();
3739 gen_helper_float64_to_float32(t0, cpu_env, arg1);
3740 tcg_gen_extu_i32_tl(t1, t0);
3741 tcg_temp_free_i32(t0);
3742 gen_qemu_st32(ctx, t1, arg2);
3746 /* stfd stfdu stfdux stfdx */
3747 GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
3748 /* stfs stfsu stfsux stfsx */
3749 GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
3752 static void gen_stfdp(DisasContext *ctx)
3755 if (unlikely(!ctx->fpu_enabled)) {
3756 gen_exception(ctx, POWERPC_EXCP_FPU);
3759 gen_set_access_type(ctx, ACCESS_FLOAT);
3760 EA = tcg_temp_new();
3761 gen_addr_imm_index(ctx, EA, 0);
3762 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3763 64-bit byteswap already. */
3764 if (unlikely(ctx->le_mode)) {
3765 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3766 tcg_gen_addi_tl(EA, EA, 8);
3767 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3769 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3770 tcg_gen_addi_tl(EA, EA, 8);
3771 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3777 static void gen_stfdpx(DisasContext *ctx)
3780 if (unlikely(!ctx->fpu_enabled)) {
3781 gen_exception(ctx, POWERPC_EXCP_FPU);
3784 gen_set_access_type(ctx, ACCESS_FLOAT);
3785 EA = tcg_temp_new();
3786 gen_addr_reg_index(ctx, EA);
3787 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3788 64-bit byteswap already. */
3789 if (unlikely(ctx->le_mode)) {
3790 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3791 tcg_gen_addi_tl(EA, EA, 8);
3792 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3794 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3795 tcg_gen_addi_tl(EA, EA, 8);
3796 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3802 static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3804 TCGv t0 = tcg_temp_new();
3805 tcg_gen_trunc_i64_tl(t0, arg1),
3806 gen_qemu_st32(ctx, t0, arg2);
3810 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
3812 static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3814 #if defined(TARGET_PPC64)
3816 tcg_gen_movi_tl(cpu_cfar, nip);
3820 static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest)
3822 if (unlikely(ctx->singlestep_enabled)) {
3826 #ifndef CONFIG_USER_ONLY
3827 return (ctx->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK);
3834 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
3836 if (NARROW_MODE(ctx)) {
3837 dest = (uint32_t) dest;
3839 if (use_goto_tb(ctx, dest)) {
3841 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3842 tcg_gen_exit_tb((uintptr_t)ctx->tb + n);
3844 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3845 if (unlikely(ctx->singlestep_enabled)) {
3846 if ((ctx->singlestep_enabled &
3847 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
3848 (ctx->exception == POWERPC_EXCP_BRANCH ||
3849 ctx->exception == POWERPC_EXCP_TRACE)) {
3850 target_ulong tmp = ctx->nip;
3852 gen_exception(ctx, POWERPC_EXCP_TRACE);
3855 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
3856 gen_debug_exception(ctx);
3863 static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
3865 if (NARROW_MODE(ctx)) {
3866 nip = (uint32_t)nip;
3868 tcg_gen_movi_tl(cpu_lr, nip);
3872 static void gen_b(DisasContext *ctx)
3874 target_ulong li, target;
3876 ctx->exception = POWERPC_EXCP_BRANCH;
3877 /* sign extend LI */
3878 li = LI(ctx->opcode);
3879 li = (li ^ 0x02000000) - 0x02000000;
3880 if (likely(AA(ctx->opcode) == 0)) {
3881 target = ctx->nip + li - 4;
3885 if (LK(ctx->opcode)) {
3886 gen_setlr(ctx, ctx->nip);
3888 gen_update_cfar(ctx, ctx->nip);
3889 gen_goto_tb(ctx, 0, target);
3897 static inline void gen_bcond(DisasContext *ctx, int type)
3899 uint32_t bo = BO(ctx->opcode);
3903 ctx->exception = POWERPC_EXCP_BRANCH;
3904 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
3905 target = tcg_temp_local_new();
3906 if (type == BCOND_CTR)
3907 tcg_gen_mov_tl(target, cpu_ctr);
3908 else if (type == BCOND_TAR)
3909 gen_load_spr(target, SPR_TAR);
3911 tcg_gen_mov_tl(target, cpu_lr);
3913 TCGV_UNUSED(target);
3915 if (LK(ctx->opcode))
3916 gen_setlr(ctx, ctx->nip);
3917 l1 = gen_new_label();
3918 if ((bo & 0x4) == 0) {
3919 /* Decrement and test CTR */
3920 TCGv temp = tcg_temp_new();
3921 if (unlikely(type == BCOND_CTR)) {
3922 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3925 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3926 if (NARROW_MODE(ctx)) {
3927 tcg_gen_ext32u_tl(temp, cpu_ctr);
3929 tcg_gen_mov_tl(temp, cpu_ctr);
3932 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3934 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3936 tcg_temp_free(temp);
3938 if ((bo & 0x10) == 0) {
3940 uint32_t bi = BI(ctx->opcode);
3941 uint32_t mask = 0x08 >> (bi & 0x03);
3942 TCGv_i32 temp = tcg_temp_new_i32();
3945 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3946 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3948 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3949 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
3951 tcg_temp_free_i32(temp);
3953 gen_update_cfar(ctx, ctx->nip);
3954 if (type == BCOND_IM) {
3955 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3956 if (likely(AA(ctx->opcode) == 0)) {
3957 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3959 gen_goto_tb(ctx, 0, li);
3962 gen_goto_tb(ctx, 1, ctx->nip);
3964 if (NARROW_MODE(ctx)) {
3965 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3967 tcg_gen_andi_tl(cpu_nip, target, ~3);
3971 gen_update_nip(ctx, ctx->nip);
3974 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
3975 tcg_temp_free(target);
3979 static void gen_bc(DisasContext *ctx)
3981 gen_bcond(ctx, BCOND_IM);
3984 static void gen_bcctr(DisasContext *ctx)
3986 gen_bcond(ctx, BCOND_CTR);
3989 static void gen_bclr(DisasContext *ctx)
3991 gen_bcond(ctx, BCOND_LR);
3994 static void gen_bctar(DisasContext *ctx)
3996 gen_bcond(ctx, BCOND_TAR);
3999 /*** Condition register logical ***/
4000 #define GEN_CRLOGIC(name, tcg_op, opc) \
4001 static void glue(gen_, name)(DisasContext *ctx) \
4006 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
4007 t0 = tcg_temp_new_i32(); \
4009 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
4011 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
4013 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
4014 t1 = tcg_temp_new_i32(); \
4015 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4017 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
4019 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
4021 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4022 tcg_op(t0, t0, t1); \
4023 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
4024 tcg_gen_andi_i32(t0, t0, bitmask); \
4025 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4026 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
4027 tcg_temp_free_i32(t0); \
4028 tcg_temp_free_i32(t1); \
4032 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
4034 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
4036 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
4038 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
4040 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
4042 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
4044 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
4046 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
4049 static void gen_mcrf(DisasContext *ctx)
4051 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
4054 /*** System linkage ***/
4056 /* rfi (supervisor only) */
4057 static void gen_rfi(DisasContext *ctx)
4059 #if defined(CONFIG_USER_ONLY)
4060 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4062 /* Restore CPU state */
4063 if (unlikely(ctx->pr)) {
4064 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4067 gen_update_cfar(ctx, ctx->nip);
4068 gen_helper_rfi(cpu_env);
4069 gen_sync_exception(ctx);
4073 #if defined(TARGET_PPC64)
4074 static void gen_rfid(DisasContext *ctx)
4076 #if defined(CONFIG_USER_ONLY)
4077 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4079 /* Restore CPU state */
4080 if (unlikely(ctx->pr)) {
4081 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4084 gen_update_cfar(ctx, ctx->nip);
4085 gen_helper_rfid(cpu_env);
4086 gen_sync_exception(ctx);
4090 static void gen_hrfid(DisasContext *ctx)
4092 #if defined(CONFIG_USER_ONLY)
4093 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4095 /* Restore CPU state */
4096 if (unlikely(!ctx->hv)) {
4097 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4100 gen_helper_hrfid(cpu_env);
4101 gen_sync_exception(ctx);
4107 #if defined(CONFIG_USER_ONLY)
4108 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4110 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4112 static void gen_sc(DisasContext *ctx)
4116 lev = (ctx->opcode >> 5) & 0x7F;
4117 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
4123 static void gen_tw(DisasContext *ctx)
4125 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
4126 /* Update the nip since this might generate a trap exception */
4127 gen_update_nip(ctx, ctx->nip);
4128 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4130 tcg_temp_free_i32(t0);
4134 static void gen_twi(DisasContext *ctx)
4136 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4137 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
4138 /* Update the nip since this might generate a trap exception */
4139 gen_update_nip(ctx, ctx->nip);
4140 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
4142 tcg_temp_free_i32(t1);
4145 #if defined(TARGET_PPC64)
4147 static void gen_td(DisasContext *ctx)
4149 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
4150 /* Update the nip since this might generate a trap exception */
4151 gen_update_nip(ctx, ctx->nip);
4152 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4154 tcg_temp_free_i32(t0);
4158 static void gen_tdi(DisasContext *ctx)
4160 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4161 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
4162 /* Update the nip since this might generate a trap exception */
4163 gen_update_nip(ctx, ctx->nip);
4164 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
4166 tcg_temp_free_i32(t1);
4170 /*** Processor control ***/
4172 static void gen_read_xer(TCGv dst)
4174 TCGv t0 = tcg_temp_new();
4175 TCGv t1 = tcg_temp_new();
4176 TCGv t2 = tcg_temp_new();
4177 tcg_gen_mov_tl(dst, cpu_xer);
4178 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4179 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4180 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4181 tcg_gen_or_tl(t0, t0, t1);
4182 tcg_gen_or_tl(dst, dst, t2);
4183 tcg_gen_or_tl(dst, dst, t0);
4189 static void gen_write_xer(TCGv src)
4191 tcg_gen_andi_tl(cpu_xer, src,
4192 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4193 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4194 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4195 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4196 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4197 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4198 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4202 static void gen_mcrxr(DisasContext *ctx)
4204 TCGv_i32 t0 = tcg_temp_new_i32();
4205 TCGv_i32 t1 = tcg_temp_new_i32();
4206 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4208 tcg_gen_trunc_tl_i32(t0, cpu_so);
4209 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4210 tcg_gen_trunc_tl_i32(dst, cpu_ca);
4211 tcg_gen_shli_i32(t0, t0, 3);
4212 tcg_gen_shli_i32(t1, t1, 2);
4213 tcg_gen_shli_i32(dst, dst, 1);
4214 tcg_gen_or_i32(dst, dst, t0);
4215 tcg_gen_or_i32(dst, dst, t1);
4216 tcg_temp_free_i32(t0);
4217 tcg_temp_free_i32(t1);
4219 tcg_gen_movi_tl(cpu_so, 0);
4220 tcg_gen_movi_tl(cpu_ov, 0);
4221 tcg_gen_movi_tl(cpu_ca, 0);
4225 static void gen_mfcr(DisasContext *ctx)
4229 if (likely(ctx->opcode & 0x00100000)) {
4230 crm = CRM(ctx->opcode);
4231 if (likely(crm && ((crm & (crm - 1)) == 0))) {
4233 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
4234 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4235 cpu_gpr[rD(ctx->opcode)], crn * 4);
4238 TCGv_i32 t0 = tcg_temp_new_i32();
4239 tcg_gen_mov_i32(t0, cpu_crf[0]);
4240 tcg_gen_shli_i32(t0, t0, 4);
4241 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4242 tcg_gen_shli_i32(t0, t0, 4);
4243 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4244 tcg_gen_shli_i32(t0, t0, 4);
4245 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4246 tcg_gen_shli_i32(t0, t0, 4);
4247 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4248 tcg_gen_shli_i32(t0, t0, 4);
4249 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4250 tcg_gen_shli_i32(t0, t0, 4);
4251 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4252 tcg_gen_shli_i32(t0, t0, 4);
4253 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4254 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4255 tcg_temp_free_i32(t0);
4260 static void gen_mfmsr(DisasContext *ctx)
4262 #if defined(CONFIG_USER_ONLY)
4263 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4265 if (unlikely(ctx->pr)) {
4266 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4269 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
4273 static void spr_noaccess(DisasContext *ctx, int gprn, int sprn)
4276 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4277 printf("ERROR: try to access SPR %d !\n", sprn);
4280 #define SPR_NOACCESS (&spr_noaccess)
4283 static inline void gen_op_mfspr(DisasContext *ctx)
4285 void (*read_cb)(DisasContext *ctx, int gprn, int sprn);
4286 uint32_t sprn = SPR(ctx->opcode);
4288 #if defined(CONFIG_USER_ONLY)
4289 read_cb = ctx->spr_cb[sprn].uea_read;
4292 read_cb = ctx->spr_cb[sprn].uea_read;
4293 } else if (ctx->hv) {
4294 read_cb = ctx->spr_cb[sprn].hea_read;
4296 read_cb = ctx->spr_cb[sprn].oea_read;
4299 if (likely(read_cb != NULL)) {
4300 if (likely(read_cb != SPR_NOACCESS)) {
4301 (*read_cb)(ctx, rD(ctx->opcode), sprn);
4303 /* Privilege exception */
4304 /* This is a hack to avoid warnings when running Linux:
4305 * this OS breaks the PowerPC virtualisation model,
4306 * allowing userland application to read the PVR
4308 if (sprn != SPR_PVR) {
4309 fprintf(stderr, "Trying to read privileged spr %d (0x%03x) at "
4310 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4311 if (qemu_log_separate()) {
4312 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4313 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4316 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4320 fprintf(stderr, "Trying to read invalid spr %d (0x%03x) at "
4321 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4322 if (qemu_log_separate()) {
4323 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4324 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4326 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4330 static void gen_mfspr(DisasContext *ctx)
4336 static void gen_mftb(DisasContext *ctx)
4342 static void gen_mtcrf(DisasContext *ctx)
4346 crm = CRM(ctx->opcode);
4347 if (likely((ctx->opcode & 0x00100000))) {
4348 if (crm && ((crm & (crm - 1)) == 0)) {
4349 TCGv_i32 temp = tcg_temp_new_i32();
4351 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4352 tcg_gen_shri_i32(temp, temp, crn * 4);
4353 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
4354 tcg_temp_free_i32(temp);
4357 TCGv_i32 temp = tcg_temp_new_i32();
4358 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4359 for (crn = 0 ; crn < 8 ; crn++) {
4360 if (crm & (1 << crn)) {
4361 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4362 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4365 tcg_temp_free_i32(temp);
4370 #if defined(TARGET_PPC64)
4371 static void gen_mtmsrd(DisasContext *ctx)
4373 #if defined(CONFIG_USER_ONLY)
4374 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4376 if (unlikely(ctx->pr)) {
4377 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4380 if (ctx->opcode & 0x00010000) {
4381 /* Special form that does not need any synchronisation */
4382 TCGv t0 = tcg_temp_new();
4383 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4384 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4385 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4388 /* XXX: we need to update nip before the store
4389 * if we enter power saving mode, we will exit the loop
4390 * directly from ppc_store_msr
4392 gen_update_nip(ctx, ctx->nip);
4393 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
4394 /* Must stop the translation as machine state (may have) changed */
4395 /* Note that mtmsr is not always defined as context-synchronizing */
4396 gen_stop_exception(ctx);
4402 static void gen_mtmsr(DisasContext *ctx)
4404 #if defined(CONFIG_USER_ONLY)
4405 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4407 if (unlikely(ctx->pr)) {
4408 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4411 if (ctx->opcode & 0x00010000) {
4412 /* Special form that does not need any synchronisation */
4413 TCGv t0 = tcg_temp_new();
4414 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4415 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4416 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4419 TCGv msr = tcg_temp_new();
4421 /* XXX: we need to update nip before the store
4422 * if we enter power saving mode, we will exit the loop
4423 * directly from ppc_store_msr
4425 gen_update_nip(ctx, ctx->nip);
4426 #if defined(TARGET_PPC64)
4427 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4429 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
4431 gen_helper_store_msr(cpu_env, msr);
4433 /* Must stop the translation as machine state (may have) changed */
4434 /* Note that mtmsr is not always defined as context-synchronizing */
4435 gen_stop_exception(ctx);
4441 static void gen_mtspr(DisasContext *ctx)
4443 void (*write_cb)(DisasContext *ctx, int sprn, int gprn);
4444 uint32_t sprn = SPR(ctx->opcode);
4446 #if defined(CONFIG_USER_ONLY)
4447 write_cb = ctx->spr_cb[sprn].uea_write;
4450 write_cb = ctx->spr_cb[sprn].uea_write;
4451 } else if (ctx->hv) {
4452 write_cb = ctx->spr_cb[sprn].hea_write;
4454 write_cb = ctx->spr_cb[sprn].oea_write;
4457 if (likely(write_cb != NULL)) {
4458 if (likely(write_cb != SPR_NOACCESS)) {
4459 (*write_cb)(ctx, sprn, rS(ctx->opcode));
4461 /* Privilege exception */
4462 fprintf(stderr, "Trying to write privileged spr %d (0x%03x) at "
4463 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4464 if (qemu_log_separate()) {
4465 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4466 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4468 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4472 if (qemu_log_separate()) {
4473 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4474 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4476 fprintf(stderr, "Trying to write invalid spr %d (0x%03x) at "
4477 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4478 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4482 /*** Cache management ***/
4485 static void gen_dcbf(DisasContext *ctx)
4487 /* XXX: specification says this is treated as a load by the MMU */
4489 gen_set_access_type(ctx, ACCESS_CACHE);
4490 t0 = tcg_temp_new();
4491 gen_addr_reg_index(ctx, t0);
4492 gen_qemu_ld8u(ctx, t0, t0);
4496 /* dcbi (Supervisor only) */
4497 static void gen_dcbi(DisasContext *ctx)
4499 #if defined(CONFIG_USER_ONLY)
4500 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4503 if (unlikely(ctx->pr)) {
4504 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4507 EA = tcg_temp_new();
4508 gen_set_access_type(ctx, ACCESS_CACHE);
4509 gen_addr_reg_index(ctx, EA);
4510 val = tcg_temp_new();
4511 /* XXX: specification says this should be treated as a store by the MMU */
4512 gen_qemu_ld8u(ctx, val, EA);
4513 gen_qemu_st8(ctx, val, EA);
4520 static void gen_dcbst(DisasContext *ctx)
4522 /* XXX: specification say this is treated as a load by the MMU */
4524 gen_set_access_type(ctx, ACCESS_CACHE);
4525 t0 = tcg_temp_new();
4526 gen_addr_reg_index(ctx, t0);
4527 gen_qemu_ld8u(ctx, t0, t0);
4532 static void gen_dcbt(DisasContext *ctx)
4534 /* interpreted as no-op */
4535 /* XXX: specification say this is treated as a load by the MMU
4536 * but does not generate any exception
4541 static void gen_dcbtst(DisasContext *ctx)
4543 /* interpreted as no-op */
4544 /* XXX: specification say this is treated as a load by the MMU
4545 * but does not generate any exception
4550 static void gen_dcbtls(DisasContext *ctx)
4552 /* Always fails locking the cache */
4553 TCGv t0 = tcg_temp_new();
4554 gen_load_spr(t0, SPR_Exxx_L1CSR0);
4555 tcg_gen_ori_tl(t0, t0, L1CSR0_CUL);
4556 gen_store_spr(SPR_Exxx_L1CSR0, t0);
4561 static void gen_dcbz(DisasContext *ctx)
4564 TCGv_i32 tcgv_is_dcbzl;
4565 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
4567 gen_set_access_type(ctx, ACCESS_CACHE);
4568 /* NIP cannot be restored if the memory exception comes from an helper */
4569 gen_update_nip(ctx, ctx->nip - 4);
4570 tcgv_addr = tcg_temp_new();
4571 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4573 gen_addr_reg_index(ctx, tcgv_addr);
4574 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4576 tcg_temp_free(tcgv_addr);
4577 tcg_temp_free_i32(tcgv_is_dcbzl);
4581 static void gen_dst(DisasContext *ctx)
4583 if (rA(ctx->opcode) == 0) {
4584 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4586 /* interpreted as no-op */
4591 static void gen_dstst(DisasContext *ctx)
4593 if (rA(ctx->opcode) == 0) {
4594 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4596 /* interpreted as no-op */
4602 static void gen_dss(DisasContext *ctx)
4604 /* interpreted as no-op */
4608 static void gen_icbi(DisasContext *ctx)
4611 gen_set_access_type(ctx, ACCESS_CACHE);
4612 /* NIP cannot be restored if the memory exception comes from an helper */
4613 gen_update_nip(ctx, ctx->nip - 4);
4614 t0 = tcg_temp_new();
4615 gen_addr_reg_index(ctx, t0);
4616 gen_helper_icbi(cpu_env, t0);
4622 static void gen_dcba(DisasContext *ctx)
4624 /* interpreted as no-op */
4625 /* XXX: specification say this is treated as a store by the MMU
4626 * but does not generate any exception
4630 /*** Segment register manipulation ***/
4631 /* Supervisor only: */
4634 static void gen_mfsr(DisasContext *ctx)
4636 #if defined(CONFIG_USER_ONLY)
4637 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4640 if (unlikely(ctx->pr)) {
4641 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4644 t0 = tcg_const_tl(SR(ctx->opcode));
4645 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4651 static void gen_mfsrin(DisasContext *ctx)
4653 #if defined(CONFIG_USER_ONLY)
4654 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4657 if (unlikely(ctx->pr)) {
4658 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4661 t0 = tcg_temp_new();
4662 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4663 tcg_gen_andi_tl(t0, t0, 0xF);
4664 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4670 static void gen_mtsr(DisasContext *ctx)
4672 #if defined(CONFIG_USER_ONLY)
4673 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4676 if (unlikely(ctx->pr)) {
4677 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4680 t0 = tcg_const_tl(SR(ctx->opcode));
4681 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4687 static void gen_mtsrin(DisasContext *ctx)
4689 #if defined(CONFIG_USER_ONLY)
4690 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4693 if (unlikely(ctx->pr)) {
4694 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4697 t0 = tcg_temp_new();
4698 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4699 tcg_gen_andi_tl(t0, t0, 0xF);
4700 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
4705 #if defined(TARGET_PPC64)
4706 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4709 static void gen_mfsr_64b(DisasContext *ctx)
4711 #if defined(CONFIG_USER_ONLY)
4712 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4715 if (unlikely(ctx->pr)) {
4716 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4719 t0 = tcg_const_tl(SR(ctx->opcode));
4720 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4726 static void gen_mfsrin_64b(DisasContext *ctx)
4728 #if defined(CONFIG_USER_ONLY)
4729 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4732 if (unlikely(ctx->pr)) {
4733 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4736 t0 = tcg_temp_new();
4737 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4738 tcg_gen_andi_tl(t0, t0, 0xF);
4739 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4745 static void gen_mtsr_64b(DisasContext *ctx)
4747 #if defined(CONFIG_USER_ONLY)
4748 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4751 if (unlikely(ctx->pr)) {
4752 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4755 t0 = tcg_const_tl(SR(ctx->opcode));
4756 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4762 static void gen_mtsrin_64b(DisasContext *ctx)
4764 #if defined(CONFIG_USER_ONLY)
4765 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4768 if (unlikely(ctx->pr)) {
4769 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4772 t0 = tcg_temp_new();
4773 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4774 tcg_gen_andi_tl(t0, t0, 0xF);
4775 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4781 static void gen_slbmte(DisasContext *ctx)
4783 #if defined(CONFIG_USER_ONLY)
4784 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4786 if (unlikely(ctx->pr)) {
4787 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4790 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4791 cpu_gpr[rS(ctx->opcode)]);
4795 static void gen_slbmfee(DisasContext *ctx)
4797 #if defined(CONFIG_USER_ONLY)
4798 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4800 if (unlikely(ctx->pr)) {
4801 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4804 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
4805 cpu_gpr[rB(ctx->opcode)]);
4809 static void gen_slbmfev(DisasContext *ctx)
4811 #if defined(CONFIG_USER_ONLY)
4812 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4814 if (unlikely(ctx->pr)) {
4815 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4818 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
4819 cpu_gpr[rB(ctx->opcode)]);
4822 #endif /* defined(TARGET_PPC64) */
4824 /*** Lookaside buffer management ***/
4825 /* Optional & supervisor only: */
4828 static void gen_tlbia(DisasContext *ctx)
4830 #if defined(CONFIG_USER_ONLY)
4831 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4833 if (unlikely(ctx->pr)) {
4834 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4837 gen_helper_tlbia(cpu_env);
4842 static void gen_tlbiel(DisasContext *ctx)
4844 #if defined(CONFIG_USER_ONLY)
4845 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4847 if (unlikely(ctx->pr)) {
4848 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4851 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4856 static void gen_tlbie(DisasContext *ctx)
4858 #if defined(CONFIG_USER_ONLY)
4859 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4861 if (unlikely(ctx->pr || !ctx->hv)) {
4862 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4865 if (NARROW_MODE(ctx)) {
4866 TCGv t0 = tcg_temp_new();
4867 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
4868 gen_helper_tlbie(cpu_env, t0);
4871 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4877 static void gen_tlbsync(DisasContext *ctx)
4879 #if defined(CONFIG_USER_ONLY)
4880 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4882 if (unlikely(ctx->pr || !ctx->hv)) {
4883 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4886 /* tlbsync is a nop for server, ptesync handles delayed tlb flush,
4887 * embedded however needs to deal with tlbsync. We don't try to be
4888 * fancy and swallow the overhead of checking for both.
4890 gen_check_tlb_flush(ctx);
4894 #if defined(TARGET_PPC64)
4896 static void gen_slbia(DisasContext *ctx)
4898 #if defined(CONFIG_USER_ONLY)
4899 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4901 if (unlikely(ctx->pr || !ctx->hv)) {
4902 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4905 gen_helper_slbia(cpu_env);
4910 static void gen_slbie(DisasContext *ctx)
4912 #if defined(CONFIG_USER_ONLY)
4913 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4915 if (unlikely(ctx->pr)) {
4916 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4919 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4924 /*** External control ***/
4928 static void gen_eciwx(DisasContext *ctx)
4931 /* Should check EAR[E] ! */
4932 gen_set_access_type(ctx, ACCESS_EXT);
4933 t0 = tcg_temp_new();
4934 gen_addr_reg_index(ctx, t0);
4935 gen_check_align(ctx, t0, 0x03);
4936 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
4941 static void gen_ecowx(DisasContext *ctx)
4944 /* Should check EAR[E] ! */
4945 gen_set_access_type(ctx, ACCESS_EXT);
4946 t0 = tcg_temp_new();
4947 gen_addr_reg_index(ctx, t0);
4948 gen_check_align(ctx, t0, 0x03);
4949 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
4953 /* PowerPC 601 specific instructions */
4956 static void gen_abs(DisasContext *ctx)
4958 TCGLabel *l1 = gen_new_label();
4959 TCGLabel *l2 = gen_new_label();
4960 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4961 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4964 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4966 if (unlikely(Rc(ctx->opcode) != 0))
4967 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4971 static void gen_abso(DisasContext *ctx)
4973 TCGLabel *l1 = gen_new_label();
4974 TCGLabel *l2 = gen_new_label();
4975 TCGLabel *l3 = gen_new_label();
4976 /* Start with XER OV disabled, the most likely case */
4977 tcg_gen_movi_tl(cpu_ov, 0);
4978 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4979 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
4980 tcg_gen_movi_tl(cpu_ov, 1);
4981 tcg_gen_movi_tl(cpu_so, 1);
4984 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4987 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4989 if (unlikely(Rc(ctx->opcode) != 0))
4990 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4994 static void gen_clcs(DisasContext *ctx)
4996 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
4997 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4998 tcg_temp_free_i32(t0);
4999 /* Rc=1 sets CR0 to an undefined state */
5003 static void gen_div(DisasContext *ctx)
5005 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5006 cpu_gpr[rB(ctx->opcode)]);
5007 if (unlikely(Rc(ctx->opcode) != 0))
5008 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5012 static void gen_divo(DisasContext *ctx)
5014 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5015 cpu_gpr[rB(ctx->opcode)]);
5016 if (unlikely(Rc(ctx->opcode) != 0))
5017 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5021 static void gen_divs(DisasContext *ctx)
5023 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5024 cpu_gpr[rB(ctx->opcode)]);
5025 if (unlikely(Rc(ctx->opcode) != 0))
5026 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5029 /* divso - divso. */
5030 static void gen_divso(DisasContext *ctx)
5032 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
5033 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5034 if (unlikely(Rc(ctx->opcode) != 0))
5035 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5039 static void gen_doz(DisasContext *ctx)
5041 TCGLabel *l1 = gen_new_label();
5042 TCGLabel *l2 = gen_new_label();
5043 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
5044 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5047 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5049 if (unlikely(Rc(ctx->opcode) != 0))
5050 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5054 static void gen_dozo(DisasContext *ctx)
5056 TCGLabel *l1 = gen_new_label();
5057 TCGLabel *l2 = gen_new_label();
5058 TCGv t0 = tcg_temp_new();
5059 TCGv t1 = tcg_temp_new();
5060 TCGv t2 = tcg_temp_new();
5061 /* Start with XER OV disabled, the most likely case */
5062 tcg_gen_movi_tl(cpu_ov, 0);
5063 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
5064 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5065 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5066 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
5067 tcg_gen_andc_tl(t1, t1, t2);
5068 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
5069 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5070 tcg_gen_movi_tl(cpu_ov, 1);
5071 tcg_gen_movi_tl(cpu_so, 1);
5074 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5079 if (unlikely(Rc(ctx->opcode) != 0))
5080 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5084 static void gen_dozi(DisasContext *ctx)
5086 target_long simm = SIMM(ctx->opcode);
5087 TCGLabel *l1 = gen_new_label();
5088 TCGLabel *l2 = gen_new_label();
5089 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5090 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5093 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5095 if (unlikely(Rc(ctx->opcode) != 0))
5096 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5099 /* lscbx - lscbx. */
5100 static void gen_lscbx(DisasContext *ctx)
5102 TCGv t0 = tcg_temp_new();
5103 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5104 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5105 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
5107 gen_addr_reg_index(ctx, t0);
5108 /* NIP cannot be restored if the memory exception comes from an helper */
5109 gen_update_nip(ctx, ctx->nip - 4);
5110 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
5111 tcg_temp_free_i32(t1);
5112 tcg_temp_free_i32(t2);
5113 tcg_temp_free_i32(t3);
5114 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
5115 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
5116 if (unlikely(Rc(ctx->opcode) != 0))
5117 gen_set_Rc0(ctx, t0);
5121 /* maskg - maskg. */
5122 static void gen_maskg(DisasContext *ctx)
5124 TCGLabel *l1 = gen_new_label();
5125 TCGv t0 = tcg_temp_new();
5126 TCGv t1 = tcg_temp_new();
5127 TCGv t2 = tcg_temp_new();
5128 TCGv t3 = tcg_temp_new();
5129 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5130 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5131 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5132 tcg_gen_addi_tl(t2, t0, 1);
5133 tcg_gen_shr_tl(t2, t3, t2);
5134 tcg_gen_shr_tl(t3, t3, t1);
5135 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5136 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5137 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5143 if (unlikely(Rc(ctx->opcode) != 0))
5144 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5147 /* maskir - maskir. */
5148 static void gen_maskir(DisasContext *ctx)
5150 TCGv t0 = tcg_temp_new();
5151 TCGv t1 = tcg_temp_new();
5152 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5153 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5154 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5157 if (unlikely(Rc(ctx->opcode) != 0))
5158 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5162 static void gen_mul(DisasContext *ctx)
5164 TCGv_i64 t0 = tcg_temp_new_i64();
5165 TCGv_i64 t1 = tcg_temp_new_i64();
5166 TCGv t2 = tcg_temp_new();
5167 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5168 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5169 tcg_gen_mul_i64(t0, t0, t1);
5170 tcg_gen_trunc_i64_tl(t2, t0);
5171 gen_store_spr(SPR_MQ, t2);
5172 tcg_gen_shri_i64(t1, t0, 32);
5173 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5174 tcg_temp_free_i64(t0);
5175 tcg_temp_free_i64(t1);
5177 if (unlikely(Rc(ctx->opcode) != 0))
5178 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5182 static void gen_mulo(DisasContext *ctx)
5184 TCGLabel *l1 = gen_new_label();
5185 TCGv_i64 t0 = tcg_temp_new_i64();
5186 TCGv_i64 t1 = tcg_temp_new_i64();
5187 TCGv t2 = tcg_temp_new();
5188 /* Start with XER OV disabled, the most likely case */
5189 tcg_gen_movi_tl(cpu_ov, 0);
5190 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5191 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5192 tcg_gen_mul_i64(t0, t0, t1);
5193 tcg_gen_trunc_i64_tl(t2, t0);
5194 gen_store_spr(SPR_MQ, t2);
5195 tcg_gen_shri_i64(t1, t0, 32);
5196 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5197 tcg_gen_ext32s_i64(t1, t0);
5198 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
5199 tcg_gen_movi_tl(cpu_ov, 1);
5200 tcg_gen_movi_tl(cpu_so, 1);
5202 tcg_temp_free_i64(t0);
5203 tcg_temp_free_i64(t1);
5205 if (unlikely(Rc(ctx->opcode) != 0))
5206 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5210 static void gen_nabs(DisasContext *ctx)
5212 TCGLabel *l1 = gen_new_label();
5213 TCGLabel *l2 = gen_new_label();
5214 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5215 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5218 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5220 if (unlikely(Rc(ctx->opcode) != 0))
5221 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5224 /* nabso - nabso. */
5225 static void gen_nabso(DisasContext *ctx)
5227 TCGLabel *l1 = gen_new_label();
5228 TCGLabel *l2 = gen_new_label();
5229 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5230 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5233 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5235 /* nabs never overflows */
5236 tcg_gen_movi_tl(cpu_ov, 0);
5237 if (unlikely(Rc(ctx->opcode) != 0))
5238 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
5242 static void gen_rlmi(DisasContext *ctx)
5244 uint32_t mb = MB(ctx->opcode);
5245 uint32_t me = ME(ctx->opcode);
5246 TCGv t0 = tcg_temp_new();
5247 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5248 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5249 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5250 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5251 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5253 if (unlikely(Rc(ctx->opcode) != 0))
5254 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5258 static void gen_rrib(DisasContext *ctx)
5260 TCGv t0 = tcg_temp_new();
5261 TCGv t1 = tcg_temp_new();
5262 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5263 tcg_gen_movi_tl(t1, 0x80000000);
5264 tcg_gen_shr_tl(t1, t1, t0);
5265 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5266 tcg_gen_and_tl(t0, t0, t1);
5267 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5268 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5271 if (unlikely(Rc(ctx->opcode) != 0))
5272 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5276 static void gen_sle(DisasContext *ctx)
5278 TCGv t0 = tcg_temp_new();
5279 TCGv t1 = tcg_temp_new();
5280 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5281 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5282 tcg_gen_subfi_tl(t1, 32, t1);
5283 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5284 tcg_gen_or_tl(t1, t0, t1);
5285 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5286 gen_store_spr(SPR_MQ, t1);
5289 if (unlikely(Rc(ctx->opcode) != 0))
5290 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5294 static void gen_sleq(DisasContext *ctx)
5296 TCGv t0 = tcg_temp_new();
5297 TCGv t1 = tcg_temp_new();
5298 TCGv t2 = tcg_temp_new();
5299 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5300 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5301 tcg_gen_shl_tl(t2, t2, t0);
5302 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5303 gen_load_spr(t1, SPR_MQ);
5304 gen_store_spr(SPR_MQ, t0);
5305 tcg_gen_and_tl(t0, t0, t2);
5306 tcg_gen_andc_tl(t1, t1, t2);
5307 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5311 if (unlikely(Rc(ctx->opcode) != 0))
5312 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5316 static void gen_sliq(DisasContext *ctx)
5318 int sh = SH(ctx->opcode);
5319 TCGv t0 = tcg_temp_new();
5320 TCGv t1 = tcg_temp_new();
5321 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5322 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5323 tcg_gen_or_tl(t1, t0, t1);
5324 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5325 gen_store_spr(SPR_MQ, t1);
5328 if (unlikely(Rc(ctx->opcode) != 0))
5329 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5332 /* slliq - slliq. */
5333 static void gen_slliq(DisasContext *ctx)
5335 int sh = SH(ctx->opcode);
5336 TCGv t0 = tcg_temp_new();
5337 TCGv t1 = tcg_temp_new();
5338 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5339 gen_load_spr(t1, SPR_MQ);
5340 gen_store_spr(SPR_MQ, t0);
5341 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5342 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5343 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5346 if (unlikely(Rc(ctx->opcode) != 0))
5347 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5351 static void gen_sllq(DisasContext *ctx)
5353 TCGLabel *l1 = gen_new_label();
5354 TCGLabel *l2 = gen_new_label();
5355 TCGv t0 = tcg_temp_local_new();
5356 TCGv t1 = tcg_temp_local_new();
5357 TCGv t2 = tcg_temp_local_new();
5358 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5359 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5360 tcg_gen_shl_tl(t1, t1, t2);
5361 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5362 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5363 gen_load_spr(t0, SPR_MQ);
5364 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5367 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5368 gen_load_spr(t2, SPR_MQ);
5369 tcg_gen_andc_tl(t1, t2, t1);
5370 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5375 if (unlikely(Rc(ctx->opcode) != 0))
5376 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5380 static void gen_slq(DisasContext *ctx)
5382 TCGLabel *l1 = gen_new_label();
5383 TCGv t0 = tcg_temp_new();
5384 TCGv t1 = tcg_temp_new();
5385 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5386 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5387 tcg_gen_subfi_tl(t1, 32, t1);
5388 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5389 tcg_gen_or_tl(t1, t0, t1);
5390 gen_store_spr(SPR_MQ, t1);
5391 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5392 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5393 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5394 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5398 if (unlikely(Rc(ctx->opcode) != 0))
5399 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5402 /* sraiq - sraiq. */
5403 static void gen_sraiq(DisasContext *ctx)
5405 int sh = SH(ctx->opcode);
5406 TCGLabel *l1 = gen_new_label();
5407 TCGv t0 = tcg_temp_new();
5408 TCGv t1 = tcg_temp_new();
5409 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5410 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5411 tcg_gen_or_tl(t0, t0, t1);
5412 gen_store_spr(SPR_MQ, t0);
5413 tcg_gen_movi_tl(cpu_ca, 0);
5414 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5415 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
5416 tcg_gen_movi_tl(cpu_ca, 1);
5418 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5421 if (unlikely(Rc(ctx->opcode) != 0))
5422 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5426 static void gen_sraq(DisasContext *ctx)
5428 TCGLabel *l1 = gen_new_label();
5429 TCGLabel *l2 = gen_new_label();
5430 TCGv t0 = tcg_temp_new();
5431 TCGv t1 = tcg_temp_local_new();
5432 TCGv t2 = tcg_temp_local_new();
5433 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5434 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5435 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5436 tcg_gen_subfi_tl(t2, 32, t2);
5437 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5438 tcg_gen_or_tl(t0, t0, t2);
5439 gen_store_spr(SPR_MQ, t0);
5440 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5441 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5442 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5443 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5446 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
5447 tcg_gen_movi_tl(cpu_ca, 0);
5448 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5449 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
5450 tcg_gen_movi_tl(cpu_ca, 1);
5454 if (unlikely(Rc(ctx->opcode) != 0))
5455 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5459 static void gen_sre(DisasContext *ctx)
5461 TCGv t0 = tcg_temp_new();
5462 TCGv t1 = tcg_temp_new();
5463 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5464 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5465 tcg_gen_subfi_tl(t1, 32, t1);
5466 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5467 tcg_gen_or_tl(t1, t0, t1);
5468 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5469 gen_store_spr(SPR_MQ, t1);
5472 if (unlikely(Rc(ctx->opcode) != 0))
5473 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5477 static void gen_srea(DisasContext *ctx)
5479 TCGv t0 = tcg_temp_new();
5480 TCGv t1 = tcg_temp_new();
5481 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5482 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5483 gen_store_spr(SPR_MQ, t0);
5484 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5487 if (unlikely(Rc(ctx->opcode) != 0))
5488 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5492 static void gen_sreq(DisasContext *ctx)
5494 TCGv t0 = tcg_temp_new();
5495 TCGv t1 = tcg_temp_new();
5496 TCGv t2 = tcg_temp_new();
5497 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5498 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5499 tcg_gen_shr_tl(t1, t1, t0);
5500 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5501 gen_load_spr(t2, SPR_MQ);
5502 gen_store_spr(SPR_MQ, t0);
5503 tcg_gen_and_tl(t0, t0, t1);
5504 tcg_gen_andc_tl(t2, t2, t1);
5505 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5509 if (unlikely(Rc(ctx->opcode) != 0))
5510 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5514 static void gen_sriq(DisasContext *ctx)
5516 int sh = SH(ctx->opcode);
5517 TCGv t0 = tcg_temp_new();
5518 TCGv t1 = tcg_temp_new();
5519 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5520 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5521 tcg_gen_or_tl(t1, t0, t1);
5522 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5523 gen_store_spr(SPR_MQ, t1);
5526 if (unlikely(Rc(ctx->opcode) != 0))
5527 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5531 static void gen_srliq(DisasContext *ctx)
5533 int sh = SH(ctx->opcode);
5534 TCGv t0 = tcg_temp_new();
5535 TCGv t1 = tcg_temp_new();
5536 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5537 gen_load_spr(t1, SPR_MQ);
5538 gen_store_spr(SPR_MQ, t0);
5539 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5540 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5541 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5544 if (unlikely(Rc(ctx->opcode) != 0))
5545 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5549 static void gen_srlq(DisasContext *ctx)
5551 TCGLabel *l1 = gen_new_label();
5552 TCGLabel *l2 = gen_new_label();
5553 TCGv t0 = tcg_temp_local_new();
5554 TCGv t1 = tcg_temp_local_new();
5555 TCGv t2 = tcg_temp_local_new();
5556 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5557 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5558 tcg_gen_shr_tl(t2, t1, t2);
5559 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5560 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5561 gen_load_spr(t0, SPR_MQ);
5562 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5565 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5566 tcg_gen_and_tl(t0, t0, t2);
5567 gen_load_spr(t1, SPR_MQ);
5568 tcg_gen_andc_tl(t1, t1, t2);
5569 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_srq(DisasContext *ctx)
5581 TCGLabel *l1 = gen_new_label();
5582 TCGv t0 = tcg_temp_new();
5583 TCGv t1 = tcg_temp_new();
5584 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5585 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5586 tcg_gen_subfi_tl(t1, 32, t1);
5587 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5588 tcg_gen_or_tl(t1, t0, t1);
5589 gen_store_spr(SPR_MQ, t1);
5590 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5591 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5592 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5593 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5597 if (unlikely(Rc(ctx->opcode) != 0))
5598 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5601 /* PowerPC 602 specific instructions */
5604 static void gen_dsa(DisasContext *ctx)
5607 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5611 static void gen_esa(DisasContext *ctx)
5614 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5618 static void gen_mfrom(DisasContext *ctx)
5620 #if defined(CONFIG_USER_ONLY)
5621 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5623 if (unlikely(ctx->pr)) {
5624 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5627 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5631 /* 602 - 603 - G2 TLB management */
5634 static void gen_tlbld_6xx(DisasContext *ctx)
5636 #if defined(CONFIG_USER_ONLY)
5637 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5639 if (unlikely(ctx->pr)) {
5640 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5643 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5648 static void gen_tlbli_6xx(DisasContext *ctx)
5650 #if defined(CONFIG_USER_ONLY)
5651 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5653 if (unlikely(ctx->pr)) {
5654 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5657 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5661 /* 74xx TLB management */
5664 static void gen_tlbld_74xx(DisasContext *ctx)
5666 #if defined(CONFIG_USER_ONLY)
5667 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5669 if (unlikely(ctx->pr)) {
5670 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5673 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5678 static void gen_tlbli_74xx(DisasContext *ctx)
5680 #if defined(CONFIG_USER_ONLY)
5681 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5683 if (unlikely(ctx->pr)) {
5684 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5687 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5691 /* POWER instructions not in PowerPC 601 */
5694 static void gen_clf(DisasContext *ctx)
5696 /* Cache line flush: implemented as no-op */
5700 static void gen_cli(DisasContext *ctx)
5702 /* Cache line invalidate: privileged and treated as no-op */
5703 #if defined(CONFIG_USER_ONLY)
5704 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5706 if (unlikely(ctx->pr)) {
5707 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5714 static void gen_dclst(DisasContext *ctx)
5716 /* Data cache line store: treated as no-op */
5719 static void gen_mfsri(DisasContext *ctx)
5721 #if defined(CONFIG_USER_ONLY)
5722 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5724 int ra = rA(ctx->opcode);
5725 int rd = rD(ctx->opcode);
5727 if (unlikely(ctx->pr)) {
5728 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5731 t0 = tcg_temp_new();
5732 gen_addr_reg_index(ctx, t0);
5733 tcg_gen_shri_tl(t0, t0, 28);
5734 tcg_gen_andi_tl(t0, t0, 0xF);
5735 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
5737 if (ra != 0 && ra != rd)
5738 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
5742 static void gen_rac(DisasContext *ctx)
5744 #if defined(CONFIG_USER_ONLY)
5745 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5748 if (unlikely(ctx->pr)) {
5749 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5752 t0 = tcg_temp_new();
5753 gen_addr_reg_index(ctx, t0);
5754 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
5759 static void gen_rfsvc(DisasContext *ctx)
5761 #if defined(CONFIG_USER_ONLY)
5762 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5764 if (unlikely(ctx->pr)) {
5765 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5768 gen_helper_rfsvc(cpu_env);
5769 gen_sync_exception(ctx);
5773 /* svc is not implemented for now */
5775 /* POWER2 specific instructions */
5776 /* Quad manipulation (load/store two floats at a time) */
5779 static void gen_lfq(DisasContext *ctx)
5781 int rd = rD(ctx->opcode);
5783 gen_set_access_type(ctx, ACCESS_FLOAT);
5784 t0 = tcg_temp_new();
5785 gen_addr_imm_index(ctx, t0, 0);
5786 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5787 gen_addr_add(ctx, t0, t0, 8);
5788 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5793 static void gen_lfqu(DisasContext *ctx)
5795 int ra = rA(ctx->opcode);
5796 int rd = rD(ctx->opcode);
5798 gen_set_access_type(ctx, ACCESS_FLOAT);
5799 t0 = tcg_temp_new();
5800 t1 = tcg_temp_new();
5801 gen_addr_imm_index(ctx, t0, 0);
5802 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5803 gen_addr_add(ctx, t1, t0, 8);
5804 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5806 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5812 static void gen_lfqux(DisasContext *ctx)
5814 int ra = rA(ctx->opcode);
5815 int rd = rD(ctx->opcode);
5816 gen_set_access_type(ctx, ACCESS_FLOAT);
5818 t0 = tcg_temp_new();
5819 gen_addr_reg_index(ctx, t0);
5820 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5821 t1 = tcg_temp_new();
5822 gen_addr_add(ctx, t1, t0, 8);
5823 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5826 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5831 static void gen_lfqx(DisasContext *ctx)
5833 int rd = rD(ctx->opcode);
5835 gen_set_access_type(ctx, ACCESS_FLOAT);
5836 t0 = tcg_temp_new();
5837 gen_addr_reg_index(ctx, t0);
5838 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5839 gen_addr_add(ctx, t0, t0, 8);
5840 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5845 static void gen_stfq(DisasContext *ctx)
5847 int rd = rD(ctx->opcode);
5849 gen_set_access_type(ctx, ACCESS_FLOAT);
5850 t0 = tcg_temp_new();
5851 gen_addr_imm_index(ctx, t0, 0);
5852 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5853 gen_addr_add(ctx, t0, t0, 8);
5854 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5859 static void gen_stfqu(DisasContext *ctx)
5861 int ra = rA(ctx->opcode);
5862 int rd = rD(ctx->opcode);
5864 gen_set_access_type(ctx, ACCESS_FLOAT);
5865 t0 = tcg_temp_new();
5866 gen_addr_imm_index(ctx, t0, 0);
5867 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5868 t1 = tcg_temp_new();
5869 gen_addr_add(ctx, t1, t0, 8);
5870 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5873 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5878 static void gen_stfqux(DisasContext *ctx)
5880 int ra = rA(ctx->opcode);
5881 int rd = rD(ctx->opcode);
5883 gen_set_access_type(ctx, ACCESS_FLOAT);
5884 t0 = tcg_temp_new();
5885 gen_addr_reg_index(ctx, t0);
5886 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5887 t1 = tcg_temp_new();
5888 gen_addr_add(ctx, t1, t0, 8);
5889 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5892 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5897 static void gen_stfqx(DisasContext *ctx)
5899 int rd = rD(ctx->opcode);
5901 gen_set_access_type(ctx, ACCESS_FLOAT);
5902 t0 = tcg_temp_new();
5903 gen_addr_reg_index(ctx, t0);
5904 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5905 gen_addr_add(ctx, t0, t0, 8);
5906 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5910 /* BookE specific instructions */
5912 /* XXX: not implemented on 440 ? */
5913 static void gen_mfapidi(DisasContext *ctx)
5916 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5919 /* XXX: not implemented on 440 ? */
5920 static void gen_tlbiva(DisasContext *ctx)
5922 #if defined(CONFIG_USER_ONLY)
5923 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5926 if (unlikely(ctx->pr)) {
5927 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5930 t0 = tcg_temp_new();
5931 gen_addr_reg_index(ctx, t0);
5932 gen_helper_tlbiva(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5937 /* All 405 MAC instructions are translated here */
5938 static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5939 int ra, int rb, int rt, int Rc)
5943 t0 = tcg_temp_local_new();
5944 t1 = tcg_temp_local_new();
5946 switch (opc3 & 0x0D) {
5948 /* macchw - macchw. - macchwo - macchwo. */
5949 /* macchws - macchws. - macchwso - macchwso. */
5950 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5951 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5952 /* mulchw - mulchw. */
5953 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5954 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5955 tcg_gen_ext16s_tl(t1, t1);
5958 /* macchwu - macchwu. - macchwuo - macchwuo. */
5959 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5960 /* mulchwu - mulchwu. */
5961 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5962 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5963 tcg_gen_ext16u_tl(t1, t1);
5966 /* machhw - machhw. - machhwo - machhwo. */
5967 /* machhws - machhws. - machhwso - machhwso. */
5968 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5969 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5970 /* mulhhw - mulhhw. */
5971 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5972 tcg_gen_ext16s_tl(t0, t0);
5973 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5974 tcg_gen_ext16s_tl(t1, t1);
5977 /* machhwu - machhwu. - machhwuo - machhwuo. */
5978 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5979 /* mulhhwu - mulhhwu. */
5980 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5981 tcg_gen_ext16u_tl(t0, t0);
5982 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5983 tcg_gen_ext16u_tl(t1, t1);
5986 /* maclhw - maclhw. - maclhwo - maclhwo. */
5987 /* maclhws - maclhws. - maclhwso - maclhwso. */
5988 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5989 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5990 /* mullhw - mullhw. */
5991 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5992 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
5995 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5996 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5997 /* mullhwu - mullhwu. */
5998 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5999 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
6003 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
6004 tcg_gen_mul_tl(t1, t0, t1);
6006 /* nmultiply-and-accumulate (0x0E) */
6007 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
6009 /* multiply-and-accumulate (0x0C) */
6010 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
6014 /* Check overflow and/or saturate */
6015 TCGLabel *l1 = gen_new_label();
6018 /* Start with XER OV disabled, the most likely case */
6019 tcg_gen_movi_tl(cpu_ov, 0);
6023 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
6024 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
6025 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
6026 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
6029 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
6030 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
6034 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
6037 tcg_gen_movi_tl(t0, UINT32_MAX);
6041 /* Check overflow */
6042 tcg_gen_movi_tl(cpu_ov, 1);
6043 tcg_gen_movi_tl(cpu_so, 1);
6046 tcg_gen_mov_tl(cpu_gpr[rt], t0);
6049 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
6053 if (unlikely(Rc) != 0) {
6055 gen_set_Rc0(ctx, cpu_gpr[rt]);
6059 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6060 static void glue(gen_, name)(DisasContext *ctx) \
6062 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6063 rD(ctx->opcode), Rc(ctx->opcode)); \
6066 /* macchw - macchw. */
6067 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
6068 /* macchwo - macchwo. */
6069 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
6070 /* macchws - macchws. */
6071 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
6072 /* macchwso - macchwso. */
6073 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
6074 /* macchwsu - macchwsu. */
6075 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
6076 /* macchwsuo - macchwsuo. */
6077 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
6078 /* macchwu - macchwu. */
6079 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
6080 /* macchwuo - macchwuo. */
6081 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
6082 /* machhw - machhw. */
6083 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
6084 /* machhwo - machhwo. */
6085 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
6086 /* machhws - machhws. */
6087 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
6088 /* machhwso - machhwso. */
6089 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
6090 /* machhwsu - machhwsu. */
6091 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
6092 /* machhwsuo - machhwsuo. */
6093 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
6094 /* machhwu - machhwu. */
6095 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
6096 /* machhwuo - machhwuo. */
6097 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
6098 /* maclhw - maclhw. */
6099 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
6100 /* maclhwo - maclhwo. */
6101 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
6102 /* maclhws - maclhws. */
6103 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
6104 /* maclhwso - maclhwso. */
6105 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
6106 /* maclhwu - maclhwu. */
6107 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
6108 /* maclhwuo - maclhwuo. */
6109 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
6110 /* maclhwsu - maclhwsu. */
6111 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
6112 /* maclhwsuo - maclhwsuo. */
6113 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
6114 /* nmacchw - nmacchw. */
6115 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
6116 /* nmacchwo - nmacchwo. */
6117 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
6118 /* nmacchws - nmacchws. */
6119 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
6120 /* nmacchwso - nmacchwso. */
6121 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
6122 /* nmachhw - nmachhw. */
6123 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
6124 /* nmachhwo - nmachhwo. */
6125 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
6126 /* nmachhws - nmachhws. */
6127 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
6128 /* nmachhwso - nmachhwso. */
6129 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
6130 /* nmaclhw - nmaclhw. */
6131 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
6132 /* nmaclhwo - nmaclhwo. */
6133 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
6134 /* nmaclhws - nmaclhws. */
6135 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
6136 /* nmaclhwso - nmaclhwso. */
6137 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
6139 /* mulchw - mulchw. */
6140 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
6141 /* mulchwu - mulchwu. */
6142 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
6143 /* mulhhw - mulhhw. */
6144 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
6145 /* mulhhwu - mulhhwu. */
6146 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
6147 /* mullhw - mullhw. */
6148 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
6149 /* mullhwu - mullhwu. */
6150 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
6153 static void gen_mfdcr(DisasContext *ctx)
6155 #if defined(CONFIG_USER_ONLY)
6156 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6159 if (unlikely(ctx->pr)) {
6160 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6163 /* NIP cannot be restored if the memory exception comes from an helper */
6164 gen_update_nip(ctx, ctx->nip - 4);
6165 dcrn = tcg_const_tl(SPR(ctx->opcode));
6166 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
6167 tcg_temp_free(dcrn);
6172 static void gen_mtdcr(DisasContext *ctx)
6174 #if defined(CONFIG_USER_ONLY)
6175 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6178 if (unlikely(ctx->pr)) {
6179 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6182 /* NIP cannot be restored if the memory exception comes from an helper */
6183 gen_update_nip(ctx, ctx->nip - 4);
6184 dcrn = tcg_const_tl(SPR(ctx->opcode));
6185 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
6186 tcg_temp_free(dcrn);
6191 /* XXX: not implemented on 440 ? */
6192 static void gen_mfdcrx(DisasContext *ctx)
6194 #if defined(CONFIG_USER_ONLY)
6195 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6197 if (unlikely(ctx->pr)) {
6198 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6201 /* NIP cannot be restored if the memory exception comes from an helper */
6202 gen_update_nip(ctx, ctx->nip - 4);
6203 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6204 cpu_gpr[rA(ctx->opcode)]);
6205 /* Note: Rc update flag set leads to undefined state of Rc0 */
6210 /* XXX: not implemented on 440 ? */
6211 static void gen_mtdcrx(DisasContext *ctx)
6213 #if defined(CONFIG_USER_ONLY)
6214 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6216 if (unlikely(ctx->pr)) {
6217 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
6220 /* NIP cannot be restored if the memory exception comes from an helper */
6221 gen_update_nip(ctx, ctx->nip - 4);
6222 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6223 cpu_gpr[rS(ctx->opcode)]);
6224 /* Note: Rc update flag set leads to undefined state of Rc0 */
6228 /* mfdcrux (PPC 460) : user-mode access to DCR */
6229 static void gen_mfdcrux(DisasContext *ctx)
6231 /* NIP cannot be restored if the memory exception comes from an helper */
6232 gen_update_nip(ctx, ctx->nip - 4);
6233 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6234 cpu_gpr[rA(ctx->opcode)]);
6235 /* Note: Rc update flag set leads to undefined state of Rc0 */
6238 /* mtdcrux (PPC 460) : user-mode access to DCR */
6239 static void gen_mtdcrux(DisasContext *ctx)
6241 /* NIP cannot be restored if the memory exception comes from an helper */
6242 gen_update_nip(ctx, ctx->nip - 4);
6243 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6244 cpu_gpr[rS(ctx->opcode)]);
6245 /* Note: Rc update flag set leads to undefined state of Rc0 */
6249 static void gen_dccci(DisasContext *ctx)
6251 #if defined(CONFIG_USER_ONLY)
6252 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6254 if (unlikely(ctx->pr)) {
6255 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6258 /* interpreted as no-op */
6263 static void gen_dcread(DisasContext *ctx)
6265 #if defined(CONFIG_USER_ONLY)
6266 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6269 if (unlikely(ctx->pr)) {
6270 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6273 gen_set_access_type(ctx, ACCESS_CACHE);
6274 EA = tcg_temp_new();
6275 gen_addr_reg_index(ctx, EA);
6276 val = tcg_temp_new();
6277 gen_qemu_ld32u(ctx, val, EA);
6279 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6285 static void gen_icbt_40x(DisasContext *ctx)
6287 /* interpreted as no-op */
6288 /* XXX: specification say this is treated as a load by the MMU
6289 * but does not generate any exception
6294 static void gen_iccci(DisasContext *ctx)
6296 #if defined(CONFIG_USER_ONLY)
6297 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6299 if (unlikely(ctx->pr)) {
6300 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6303 /* interpreted as no-op */
6308 static void gen_icread(DisasContext *ctx)
6310 #if defined(CONFIG_USER_ONLY)
6311 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6313 if (unlikely(ctx->pr)) {
6314 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6317 /* interpreted as no-op */
6321 /* rfci (supervisor only) */
6322 static void gen_rfci_40x(DisasContext *ctx)
6324 #if defined(CONFIG_USER_ONLY)
6325 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6327 if (unlikely(ctx->pr)) {
6328 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6331 /* Restore CPU state */
6332 gen_helper_40x_rfci(cpu_env);
6333 gen_sync_exception(ctx);
6337 static void gen_rfci(DisasContext *ctx)
6339 #if defined(CONFIG_USER_ONLY)
6340 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6342 if (unlikely(ctx->pr)) {
6343 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6346 /* Restore CPU state */
6347 gen_helper_rfci(cpu_env);
6348 gen_sync_exception(ctx);
6352 /* BookE specific */
6354 /* XXX: not implemented on 440 ? */
6355 static void gen_rfdi(DisasContext *ctx)
6357 #if defined(CONFIG_USER_ONLY)
6358 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6360 if (unlikely(ctx->pr)) {
6361 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6364 /* Restore CPU state */
6365 gen_helper_rfdi(cpu_env);
6366 gen_sync_exception(ctx);
6370 /* XXX: not implemented on 440 ? */
6371 static void gen_rfmci(DisasContext *ctx)
6373 #if defined(CONFIG_USER_ONLY)
6374 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6376 if (unlikely(ctx->pr)) {
6377 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6380 /* Restore CPU state */
6381 gen_helper_rfmci(cpu_env);
6382 gen_sync_exception(ctx);
6386 /* TLB management - PowerPC 405 implementation */
6389 static void gen_tlbre_40x(DisasContext *ctx)
6391 #if defined(CONFIG_USER_ONLY)
6392 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6394 if (unlikely(ctx->pr)) {
6395 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6398 switch (rB(ctx->opcode)) {
6400 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6401 cpu_gpr[rA(ctx->opcode)]);
6404 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6405 cpu_gpr[rA(ctx->opcode)]);
6408 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6414 /* tlbsx - tlbsx. */
6415 static void gen_tlbsx_40x(DisasContext *ctx)
6417 #if defined(CONFIG_USER_ONLY)
6418 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6421 if (unlikely(ctx->pr)) {
6422 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6425 t0 = tcg_temp_new();
6426 gen_addr_reg_index(ctx, t0);
6427 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6429 if (Rc(ctx->opcode)) {
6430 TCGLabel *l1 = gen_new_label();
6431 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
6432 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6433 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6440 static void gen_tlbwe_40x(DisasContext *ctx)
6442 #if defined(CONFIG_USER_ONLY)
6443 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6445 if (unlikely(ctx->pr)) {
6446 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6449 switch (rB(ctx->opcode)) {
6451 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6452 cpu_gpr[rS(ctx->opcode)]);
6455 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6456 cpu_gpr[rS(ctx->opcode)]);
6459 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6465 /* TLB management - PowerPC 440 implementation */
6468 static void gen_tlbre_440(DisasContext *ctx)
6470 #if defined(CONFIG_USER_ONLY)
6471 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6473 if (unlikely(ctx->pr)) {
6474 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6477 switch (rB(ctx->opcode)) {
6482 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
6483 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6484 t0, cpu_gpr[rA(ctx->opcode)]);
6485 tcg_temp_free_i32(t0);
6489 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6495 /* tlbsx - tlbsx. */
6496 static void gen_tlbsx_440(DisasContext *ctx)
6498 #if defined(CONFIG_USER_ONLY)
6499 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6502 if (unlikely(ctx->pr)) {
6503 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6506 t0 = tcg_temp_new();
6507 gen_addr_reg_index(ctx, t0);
6508 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6510 if (Rc(ctx->opcode)) {
6511 TCGLabel *l1 = gen_new_label();
6512 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
6513 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6514 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6521 static void gen_tlbwe_440(DisasContext *ctx)
6523 #if defined(CONFIG_USER_ONLY)
6524 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6526 if (unlikely(ctx->pr)) {
6527 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6530 switch (rB(ctx->opcode)) {
6535 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
6536 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6537 cpu_gpr[rS(ctx->opcode)]);
6538 tcg_temp_free_i32(t0);
6542 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6548 /* TLB management - PowerPC BookE 2.06 implementation */
6551 static void gen_tlbre_booke206(DisasContext *ctx)
6553 #if defined(CONFIG_USER_ONLY)
6554 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6556 if (unlikely(ctx->pr)) {
6557 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6561 gen_helper_booke206_tlbre(cpu_env);
6565 /* tlbsx - tlbsx. */
6566 static void gen_tlbsx_booke206(DisasContext *ctx)
6568 #if defined(CONFIG_USER_ONLY)
6569 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6572 if (unlikely(ctx->pr)) {
6573 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6577 if (rA(ctx->opcode)) {
6578 t0 = tcg_temp_new();
6579 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6581 t0 = tcg_const_tl(0);
6584 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
6585 gen_helper_booke206_tlbsx(cpu_env, t0);
6591 static void gen_tlbwe_booke206(DisasContext *ctx)
6593 #if defined(CONFIG_USER_ONLY)
6594 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6596 if (unlikely(ctx->pr)) {
6597 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6600 gen_update_nip(ctx, ctx->nip - 4);
6601 gen_helper_booke206_tlbwe(cpu_env);
6605 static void gen_tlbivax_booke206(DisasContext *ctx)
6607 #if defined(CONFIG_USER_ONLY)
6608 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6611 if (unlikely(ctx->pr)) {
6612 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6616 t0 = tcg_temp_new();
6617 gen_addr_reg_index(ctx, t0);
6619 gen_helper_booke206_tlbivax(cpu_env, t0);
6624 static void gen_tlbilx_booke206(DisasContext *ctx)
6626 #if defined(CONFIG_USER_ONLY)
6627 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6630 if (unlikely(ctx->pr)) {
6631 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6635 t0 = tcg_temp_new();
6636 gen_addr_reg_index(ctx, t0);
6638 switch((ctx->opcode >> 21) & 0x3) {
6640 gen_helper_booke206_tlbilx0(cpu_env, t0);
6643 gen_helper_booke206_tlbilx1(cpu_env, t0);
6646 gen_helper_booke206_tlbilx3(cpu_env, t0);
6649 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6659 static void gen_wrtee(DisasContext *ctx)
6661 #if defined(CONFIG_USER_ONLY)
6662 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6665 if (unlikely(ctx->pr)) {
6666 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6669 t0 = tcg_temp_new();
6670 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6671 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6672 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6674 /* Stop translation to have a chance to raise an exception
6675 * if we just set msr_ee to 1
6677 gen_stop_exception(ctx);
6682 static void gen_wrteei(DisasContext *ctx)
6684 #if defined(CONFIG_USER_ONLY)
6685 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6687 if (unlikely(ctx->pr)) {
6688 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6691 if (ctx->opcode & 0x00008000) {
6692 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6693 /* Stop translation to have a chance to raise an exception */
6694 gen_stop_exception(ctx);
6696 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6701 /* PowerPC 440 specific instructions */
6704 static void gen_dlmzb(DisasContext *ctx)
6706 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
6707 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6708 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
6709 tcg_temp_free_i32(t0);
6712 /* mbar replaces eieio on 440 */
6713 static void gen_mbar(DisasContext *ctx)
6715 /* interpreted as no-op */
6718 /* msync replaces sync on 440 */
6719 static void gen_msync_4xx(DisasContext *ctx)
6721 /* interpreted as no-op */
6725 static void gen_icbt_440(DisasContext *ctx)
6727 /* interpreted as no-op */
6728 /* XXX: specification say this is treated as a load by the MMU
6729 * but does not generate any exception
6733 /* Embedded.Processor Control */
6735 static void gen_msgclr(DisasContext *ctx)
6737 #if defined(CONFIG_USER_ONLY)
6738 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6740 if (unlikely(ctx->pr)) {
6741 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6745 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
6749 static void gen_msgsnd(DisasContext *ctx)
6751 #if defined(CONFIG_USER_ONLY)
6752 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6754 if (unlikely(ctx->pr)) {
6755 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6759 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6763 /*** Altivec vector extension ***/
6764 /* Altivec registers moves */
6766 static inline TCGv_ptr gen_avr_ptr(int reg)
6768 TCGv_ptr r = tcg_temp_new_ptr();
6769 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6773 #define GEN_VR_LDX(name, opc2, opc3) \
6774 static void glue(gen_, name)(DisasContext *ctx) \
6777 if (unlikely(!ctx->altivec_enabled)) { \
6778 gen_exception(ctx, POWERPC_EXCP_VPU); \
6781 gen_set_access_type(ctx, ACCESS_INT); \
6782 EA = tcg_temp_new(); \
6783 gen_addr_reg_index(ctx, EA); \
6784 tcg_gen_andi_tl(EA, EA, ~0xf); \
6785 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
6786 64-bit byteswap already. */ \
6787 if (ctx->le_mode) { \
6788 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6789 tcg_gen_addi_tl(EA, EA, 8); \
6790 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6792 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6793 tcg_gen_addi_tl(EA, EA, 8); \
6794 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6796 tcg_temp_free(EA); \
6799 #define GEN_VR_STX(name, opc2, opc3) \
6800 static void gen_st##name(DisasContext *ctx) \
6803 if (unlikely(!ctx->altivec_enabled)) { \
6804 gen_exception(ctx, POWERPC_EXCP_VPU); \
6807 gen_set_access_type(ctx, ACCESS_INT); \
6808 EA = tcg_temp_new(); \
6809 gen_addr_reg_index(ctx, EA); \
6810 tcg_gen_andi_tl(EA, EA, ~0xf); \
6811 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
6812 64-bit byteswap already. */ \
6813 if (ctx->le_mode) { \
6814 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6815 tcg_gen_addi_tl(EA, EA, 8); \
6816 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6818 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6819 tcg_gen_addi_tl(EA, EA, 8); \
6820 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6822 tcg_temp_free(EA); \
6825 #define GEN_VR_LVE(name, opc2, opc3, size) \
6826 static void gen_lve##name(DisasContext *ctx) \
6830 if (unlikely(!ctx->altivec_enabled)) { \
6831 gen_exception(ctx, POWERPC_EXCP_VPU); \
6834 gen_set_access_type(ctx, ACCESS_INT); \
6835 EA = tcg_temp_new(); \
6836 gen_addr_reg_index(ctx, EA); \
6838 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
6840 rs = gen_avr_ptr(rS(ctx->opcode)); \
6841 gen_helper_lve##name(cpu_env, rs, EA); \
6842 tcg_temp_free(EA); \
6843 tcg_temp_free_ptr(rs); \
6846 #define GEN_VR_STVE(name, opc2, opc3, size) \
6847 static void gen_stve##name(DisasContext *ctx) \
6851 if (unlikely(!ctx->altivec_enabled)) { \
6852 gen_exception(ctx, POWERPC_EXCP_VPU); \
6855 gen_set_access_type(ctx, ACCESS_INT); \
6856 EA = tcg_temp_new(); \
6857 gen_addr_reg_index(ctx, EA); \
6859 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
6861 rs = gen_avr_ptr(rS(ctx->opcode)); \
6862 gen_helper_stve##name(cpu_env, rs, EA); \
6863 tcg_temp_free(EA); \
6864 tcg_temp_free_ptr(rs); \
6867 GEN_VR_LDX(lvx, 0x07, 0x03);
6868 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6869 GEN_VR_LDX(lvxl, 0x07, 0x0B);
6871 GEN_VR_LVE(bx, 0x07, 0x00, 1);
6872 GEN_VR_LVE(hx, 0x07, 0x01, 2);
6873 GEN_VR_LVE(wx, 0x07, 0x02, 4);
6875 GEN_VR_STX(svx, 0x07, 0x07);
6876 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6877 GEN_VR_STX(svxl, 0x07, 0x0F);
6879 GEN_VR_STVE(bx, 0x07, 0x04, 1);
6880 GEN_VR_STVE(hx, 0x07, 0x05, 2);
6881 GEN_VR_STVE(wx, 0x07, 0x06, 4);
6883 static void gen_lvsl(DisasContext *ctx)
6887 if (unlikely(!ctx->altivec_enabled)) {
6888 gen_exception(ctx, POWERPC_EXCP_VPU);
6891 EA = tcg_temp_new();
6892 gen_addr_reg_index(ctx, EA);
6893 rd = gen_avr_ptr(rD(ctx->opcode));
6894 gen_helper_lvsl(rd, EA);
6896 tcg_temp_free_ptr(rd);
6899 static void gen_lvsr(DisasContext *ctx)
6903 if (unlikely(!ctx->altivec_enabled)) {
6904 gen_exception(ctx, POWERPC_EXCP_VPU);
6907 EA = tcg_temp_new();
6908 gen_addr_reg_index(ctx, EA);
6909 rd = gen_avr_ptr(rD(ctx->opcode));
6910 gen_helper_lvsr(rd, EA);
6912 tcg_temp_free_ptr(rd);
6915 static void gen_mfvscr(DisasContext *ctx)
6918 if (unlikely(!ctx->altivec_enabled)) {
6919 gen_exception(ctx, POWERPC_EXCP_VPU);
6922 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6923 t = tcg_temp_new_i32();
6924 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
6925 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
6926 tcg_temp_free_i32(t);
6929 static void gen_mtvscr(DisasContext *ctx)
6932 if (unlikely(!ctx->altivec_enabled)) {
6933 gen_exception(ctx, POWERPC_EXCP_VPU);
6936 p = gen_avr_ptr(rB(ctx->opcode));
6937 gen_helper_mtvscr(cpu_env, p);
6938 tcg_temp_free_ptr(p);
6941 /* Logical operations */
6942 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6943 static void glue(gen_, name)(DisasContext *ctx) \
6945 if (unlikely(!ctx->altivec_enabled)) { \
6946 gen_exception(ctx, POWERPC_EXCP_VPU); \
6949 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6950 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6953 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6954 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6955 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6956 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6957 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6958 GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
6959 GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
6960 GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
6962 #define GEN_VXFORM(name, opc2, opc3) \
6963 static void glue(gen_, name)(DisasContext *ctx) \
6965 TCGv_ptr ra, rb, rd; \
6966 if (unlikely(!ctx->altivec_enabled)) { \
6967 gen_exception(ctx, POWERPC_EXCP_VPU); \
6970 ra = gen_avr_ptr(rA(ctx->opcode)); \
6971 rb = gen_avr_ptr(rB(ctx->opcode)); \
6972 rd = gen_avr_ptr(rD(ctx->opcode)); \
6973 gen_helper_##name (rd, ra, rb); \
6974 tcg_temp_free_ptr(ra); \
6975 tcg_temp_free_ptr(rb); \
6976 tcg_temp_free_ptr(rd); \
6979 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6980 static void glue(gen_, name)(DisasContext *ctx) \
6982 TCGv_ptr ra, rb, rd; \
6983 if (unlikely(!ctx->altivec_enabled)) { \
6984 gen_exception(ctx, POWERPC_EXCP_VPU); \
6987 ra = gen_avr_ptr(rA(ctx->opcode)); \
6988 rb = gen_avr_ptr(rB(ctx->opcode)); \
6989 rd = gen_avr_ptr(rD(ctx->opcode)); \
6990 gen_helper_##name(cpu_env, rd, ra, rb); \
6991 tcg_temp_free_ptr(ra); \
6992 tcg_temp_free_ptr(rb); \
6993 tcg_temp_free_ptr(rd); \
6996 #define GEN_VXFORM3(name, opc2, opc3) \
6997 static void glue(gen_, name)(DisasContext *ctx) \
6999 TCGv_ptr ra, rb, rc, rd; \
7000 if (unlikely(!ctx->altivec_enabled)) { \
7001 gen_exception(ctx, POWERPC_EXCP_VPU); \
7004 ra = gen_avr_ptr(rA(ctx->opcode)); \
7005 rb = gen_avr_ptr(rB(ctx->opcode)); \
7006 rc = gen_avr_ptr(rC(ctx->opcode)); \
7007 rd = gen_avr_ptr(rD(ctx->opcode)); \
7008 gen_helper_##name(rd, ra, rb, rc); \
7009 tcg_temp_free_ptr(ra); \
7010 tcg_temp_free_ptr(rb); \
7011 tcg_temp_free_ptr(rc); \
7012 tcg_temp_free_ptr(rd); \
7016 * Support for Altivec instruction pairs that use bit 31 (Rc) as
7017 * an opcode bit. In general, these pairs come from different
7018 * versions of the ISA, so we must also support a pair of flags for
7021 #define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7022 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7024 if ((Rc(ctx->opcode) == 0) && \
7025 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7027 } else if ((Rc(ctx->opcode) == 1) && \
7028 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7031 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7035 GEN_VXFORM(vaddubm, 0, 0);
7036 GEN_VXFORM(vadduhm, 0, 1);
7037 GEN_VXFORM(vadduwm, 0, 2);
7038 GEN_VXFORM(vaddudm, 0, 3);
7039 GEN_VXFORM(vsububm, 0, 16);
7040 GEN_VXFORM(vsubuhm, 0, 17);
7041 GEN_VXFORM(vsubuwm, 0, 18);
7042 GEN_VXFORM(vsubudm, 0, 19);
7043 GEN_VXFORM(vmaxub, 1, 0);
7044 GEN_VXFORM(vmaxuh, 1, 1);
7045 GEN_VXFORM(vmaxuw, 1, 2);
7046 GEN_VXFORM(vmaxud, 1, 3);
7047 GEN_VXFORM(vmaxsb, 1, 4);
7048 GEN_VXFORM(vmaxsh, 1, 5);
7049 GEN_VXFORM(vmaxsw, 1, 6);
7050 GEN_VXFORM(vmaxsd, 1, 7);
7051 GEN_VXFORM(vminub, 1, 8);
7052 GEN_VXFORM(vminuh, 1, 9);
7053 GEN_VXFORM(vminuw, 1, 10);
7054 GEN_VXFORM(vminud, 1, 11);
7055 GEN_VXFORM(vminsb, 1, 12);
7056 GEN_VXFORM(vminsh, 1, 13);
7057 GEN_VXFORM(vminsw, 1, 14);
7058 GEN_VXFORM(vminsd, 1, 15);
7059 GEN_VXFORM(vavgub, 1, 16);
7060 GEN_VXFORM(vavguh, 1, 17);
7061 GEN_VXFORM(vavguw, 1, 18);
7062 GEN_VXFORM(vavgsb, 1, 20);
7063 GEN_VXFORM(vavgsh, 1, 21);
7064 GEN_VXFORM(vavgsw, 1, 22);
7065 GEN_VXFORM(vmrghb, 6, 0);
7066 GEN_VXFORM(vmrghh, 6, 1);
7067 GEN_VXFORM(vmrghw, 6, 2);
7068 GEN_VXFORM(vmrglb, 6, 4);
7069 GEN_VXFORM(vmrglh, 6, 5);
7070 GEN_VXFORM(vmrglw, 6, 6);
7072 static void gen_vmrgew(DisasContext *ctx)
7076 if (unlikely(!ctx->altivec_enabled)) {
7077 gen_exception(ctx, POWERPC_EXCP_VPU);
7080 VT = rD(ctx->opcode);
7081 VA = rA(ctx->opcode);
7082 VB = rB(ctx->opcode);
7083 tmp = tcg_temp_new_i64();
7084 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
7085 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
7086 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
7087 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
7088 tcg_temp_free_i64(tmp);
7091 static void gen_vmrgow(DisasContext *ctx)
7094 if (unlikely(!ctx->altivec_enabled)) {
7095 gen_exception(ctx, POWERPC_EXCP_VPU);
7098 VT = rD(ctx->opcode);
7099 VA = rA(ctx->opcode);
7100 VB = rB(ctx->opcode);
7102 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7103 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7106 GEN_VXFORM(vmuloub, 4, 0);
7107 GEN_VXFORM(vmulouh, 4, 1);
7108 GEN_VXFORM(vmulouw, 4, 2);
7109 GEN_VXFORM(vmuluwm, 4, 2);
7110 GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7111 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
7112 GEN_VXFORM(vmulosb, 4, 4);
7113 GEN_VXFORM(vmulosh, 4, 5);
7114 GEN_VXFORM(vmulosw, 4, 6);
7115 GEN_VXFORM(vmuleub, 4, 8);
7116 GEN_VXFORM(vmuleuh, 4, 9);
7117 GEN_VXFORM(vmuleuw, 4, 10);
7118 GEN_VXFORM(vmulesb, 4, 12);
7119 GEN_VXFORM(vmulesh, 4, 13);
7120 GEN_VXFORM(vmulesw, 4, 14);
7121 GEN_VXFORM(vslb, 2, 4);
7122 GEN_VXFORM(vslh, 2, 5);
7123 GEN_VXFORM(vslw, 2, 6);
7124 GEN_VXFORM(vsld, 2, 23);
7125 GEN_VXFORM(vsrb, 2, 8);
7126 GEN_VXFORM(vsrh, 2, 9);
7127 GEN_VXFORM(vsrw, 2, 10);
7128 GEN_VXFORM(vsrd, 2, 27);
7129 GEN_VXFORM(vsrab, 2, 12);
7130 GEN_VXFORM(vsrah, 2, 13);
7131 GEN_VXFORM(vsraw, 2, 14);
7132 GEN_VXFORM(vsrad, 2, 15);
7133 GEN_VXFORM(vslo, 6, 16);
7134 GEN_VXFORM(vsro, 6, 17);
7135 GEN_VXFORM(vaddcuw, 0, 6);
7136 GEN_VXFORM(vsubcuw, 0, 22);
7137 GEN_VXFORM_ENV(vaddubs, 0, 8);
7138 GEN_VXFORM_ENV(vadduhs, 0, 9);
7139 GEN_VXFORM_ENV(vadduws, 0, 10);
7140 GEN_VXFORM_ENV(vaddsbs, 0, 12);
7141 GEN_VXFORM_ENV(vaddshs, 0, 13);
7142 GEN_VXFORM_ENV(vaddsws, 0, 14);
7143 GEN_VXFORM_ENV(vsububs, 0, 24);
7144 GEN_VXFORM_ENV(vsubuhs, 0, 25);
7145 GEN_VXFORM_ENV(vsubuws, 0, 26);
7146 GEN_VXFORM_ENV(vsubsbs, 0, 28);
7147 GEN_VXFORM_ENV(vsubshs, 0, 29);
7148 GEN_VXFORM_ENV(vsubsws, 0, 30);
7149 GEN_VXFORM(vadduqm, 0, 4);
7150 GEN_VXFORM(vaddcuq, 0, 5);
7151 GEN_VXFORM3(vaddeuqm, 30, 0);
7152 GEN_VXFORM3(vaddecuq, 30, 0);
7153 GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7154 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7155 GEN_VXFORM(vsubuqm, 0, 20);
7156 GEN_VXFORM(vsubcuq, 0, 21);
7157 GEN_VXFORM3(vsubeuqm, 31, 0);
7158 GEN_VXFORM3(vsubecuq, 31, 0);
7159 GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7160 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
7161 GEN_VXFORM(vrlb, 2, 0);
7162 GEN_VXFORM(vrlh, 2, 1);
7163 GEN_VXFORM(vrlw, 2, 2);
7164 GEN_VXFORM(vrld, 2, 3);
7165 GEN_VXFORM(vsl, 2, 7);
7166 GEN_VXFORM(vsr, 2, 11);
7167 GEN_VXFORM_ENV(vpkuhum, 7, 0);
7168 GEN_VXFORM_ENV(vpkuwum, 7, 1);
7169 GEN_VXFORM_ENV(vpkudum, 7, 17);
7170 GEN_VXFORM_ENV(vpkuhus, 7, 2);
7171 GEN_VXFORM_ENV(vpkuwus, 7, 3);
7172 GEN_VXFORM_ENV(vpkudus, 7, 19);
7173 GEN_VXFORM_ENV(vpkshus, 7, 4);
7174 GEN_VXFORM_ENV(vpkswus, 7, 5);
7175 GEN_VXFORM_ENV(vpksdus, 7, 21);
7176 GEN_VXFORM_ENV(vpkshss, 7, 6);
7177 GEN_VXFORM_ENV(vpkswss, 7, 7);
7178 GEN_VXFORM_ENV(vpksdss, 7, 23);
7179 GEN_VXFORM(vpkpx, 7, 12);
7180 GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7181 GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7182 GEN_VXFORM_ENV(vsum4shs, 4, 25);
7183 GEN_VXFORM_ENV(vsum2sws, 4, 26);
7184 GEN_VXFORM_ENV(vsumsws, 4, 30);
7185 GEN_VXFORM_ENV(vaddfp, 5, 0);
7186 GEN_VXFORM_ENV(vsubfp, 5, 1);
7187 GEN_VXFORM_ENV(vmaxfp, 5, 16);
7188 GEN_VXFORM_ENV(vminfp, 5, 17);
7190 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
7191 static void glue(gen_, name)(DisasContext *ctx) \
7193 TCGv_ptr ra, rb, rd; \
7194 if (unlikely(!ctx->altivec_enabled)) { \
7195 gen_exception(ctx, POWERPC_EXCP_VPU); \
7198 ra = gen_avr_ptr(rA(ctx->opcode)); \
7199 rb = gen_avr_ptr(rB(ctx->opcode)); \
7200 rd = gen_avr_ptr(rD(ctx->opcode)); \
7201 gen_helper_##opname(cpu_env, rd, ra, rb); \
7202 tcg_temp_free_ptr(ra); \
7203 tcg_temp_free_ptr(rb); \
7204 tcg_temp_free_ptr(rd); \
7207 #define GEN_VXRFORM(name, opc2, opc3) \
7208 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7209 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7212 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7213 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7214 * come from different versions of the ISA, so we must also support a
7215 * pair of flags for each instruction.
7217 #define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7218 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7220 if ((Rc(ctx->opcode) == 0) && \
7221 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7222 if (Rc21(ctx->opcode) == 0) { \
7225 gen_##name0##_(ctx); \
7227 } else if ((Rc(ctx->opcode) == 1) && \
7228 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7229 if (Rc21(ctx->opcode) == 0) { \
7232 gen_##name1##_(ctx); \
7235 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7239 GEN_VXRFORM(vcmpequb, 3, 0)
7240 GEN_VXRFORM(vcmpequh, 3, 1)
7241 GEN_VXRFORM(vcmpequw, 3, 2)
7242 GEN_VXRFORM(vcmpequd, 3, 3)
7243 GEN_VXRFORM(vcmpgtsb, 3, 12)
7244 GEN_VXRFORM(vcmpgtsh, 3, 13)
7245 GEN_VXRFORM(vcmpgtsw, 3, 14)
7246 GEN_VXRFORM(vcmpgtsd, 3, 15)
7247 GEN_VXRFORM(vcmpgtub, 3, 8)
7248 GEN_VXRFORM(vcmpgtuh, 3, 9)
7249 GEN_VXRFORM(vcmpgtuw, 3, 10)
7250 GEN_VXRFORM(vcmpgtud, 3, 11)
7251 GEN_VXRFORM(vcmpeqfp, 3, 3)
7252 GEN_VXRFORM(vcmpgefp, 3, 7)
7253 GEN_VXRFORM(vcmpgtfp, 3, 11)
7254 GEN_VXRFORM(vcmpbfp, 3, 15)
7256 GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7257 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7258 GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7259 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7260 GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7261 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7263 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7264 static void glue(gen_, name)(DisasContext *ctx) \
7268 if (unlikely(!ctx->altivec_enabled)) { \
7269 gen_exception(ctx, POWERPC_EXCP_VPU); \
7272 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7273 rd = gen_avr_ptr(rD(ctx->opcode)); \
7274 gen_helper_##name (rd, simm); \
7275 tcg_temp_free_i32(simm); \
7276 tcg_temp_free_ptr(rd); \
7279 GEN_VXFORM_SIMM(vspltisb, 6, 12);
7280 GEN_VXFORM_SIMM(vspltish, 6, 13);
7281 GEN_VXFORM_SIMM(vspltisw, 6, 14);
7283 #define GEN_VXFORM_NOA(name, opc2, opc3) \
7284 static void glue(gen_, name)(DisasContext *ctx) \
7287 if (unlikely(!ctx->altivec_enabled)) { \
7288 gen_exception(ctx, POWERPC_EXCP_VPU); \
7291 rb = gen_avr_ptr(rB(ctx->opcode)); \
7292 rd = gen_avr_ptr(rD(ctx->opcode)); \
7293 gen_helper_##name (rd, rb); \
7294 tcg_temp_free_ptr(rb); \
7295 tcg_temp_free_ptr(rd); \
7298 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7299 static void glue(gen_, name)(DisasContext *ctx) \
7303 if (unlikely(!ctx->altivec_enabled)) { \
7304 gen_exception(ctx, POWERPC_EXCP_VPU); \
7307 rb = gen_avr_ptr(rB(ctx->opcode)); \
7308 rd = gen_avr_ptr(rD(ctx->opcode)); \
7309 gen_helper_##name(cpu_env, rd, rb); \
7310 tcg_temp_free_ptr(rb); \
7311 tcg_temp_free_ptr(rd); \
7314 GEN_VXFORM_NOA(vupkhsb, 7, 8);
7315 GEN_VXFORM_NOA(vupkhsh, 7, 9);
7316 GEN_VXFORM_NOA(vupkhsw, 7, 25);
7317 GEN_VXFORM_NOA(vupklsb, 7, 10);
7318 GEN_VXFORM_NOA(vupklsh, 7, 11);
7319 GEN_VXFORM_NOA(vupklsw, 7, 27);
7320 GEN_VXFORM_NOA(vupkhpx, 7, 13);
7321 GEN_VXFORM_NOA(vupklpx, 7, 15);
7322 GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7323 GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7324 GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7325 GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
7326 GEN_VXFORM_NOA_ENV(vrfim, 5, 11);
7327 GEN_VXFORM_NOA_ENV(vrfin, 5, 8);
7328 GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
7329 GEN_VXFORM_NOA_ENV(vrfiz, 5, 9);
7331 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7332 static void glue(gen_, name)(DisasContext *ctx) \
7336 if (unlikely(!ctx->altivec_enabled)) { \
7337 gen_exception(ctx, POWERPC_EXCP_VPU); \
7340 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7341 rd = gen_avr_ptr(rD(ctx->opcode)); \
7342 gen_helper_##name (rd, simm); \
7343 tcg_temp_free_i32(simm); \
7344 tcg_temp_free_ptr(rd); \
7347 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
7348 static void glue(gen_, name)(DisasContext *ctx) \
7352 if (unlikely(!ctx->altivec_enabled)) { \
7353 gen_exception(ctx, POWERPC_EXCP_VPU); \
7356 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7357 rb = gen_avr_ptr(rB(ctx->opcode)); \
7358 rd = gen_avr_ptr(rD(ctx->opcode)); \
7359 gen_helper_##name (rd, rb, uimm); \
7360 tcg_temp_free_i32(uimm); \
7361 tcg_temp_free_ptr(rb); \
7362 tcg_temp_free_ptr(rd); \
7365 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7366 static void glue(gen_, name)(DisasContext *ctx) \
7371 if (unlikely(!ctx->altivec_enabled)) { \
7372 gen_exception(ctx, POWERPC_EXCP_VPU); \
7375 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7376 rb = gen_avr_ptr(rB(ctx->opcode)); \
7377 rd = gen_avr_ptr(rD(ctx->opcode)); \
7378 gen_helper_##name(cpu_env, rd, rb, uimm); \
7379 tcg_temp_free_i32(uimm); \
7380 tcg_temp_free_ptr(rb); \
7381 tcg_temp_free_ptr(rd); \
7384 GEN_VXFORM_UIMM(vspltb, 6, 8);
7385 GEN_VXFORM_UIMM(vsplth, 6, 9);
7386 GEN_VXFORM_UIMM(vspltw, 6, 10);
7387 GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7388 GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7389 GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7390 GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
7392 static void gen_vsldoi(DisasContext *ctx)
7394 TCGv_ptr ra, rb, rd;
7396 if (unlikely(!ctx->altivec_enabled)) {
7397 gen_exception(ctx, POWERPC_EXCP_VPU);
7400 ra = gen_avr_ptr(rA(ctx->opcode));
7401 rb = gen_avr_ptr(rB(ctx->opcode));
7402 rd = gen_avr_ptr(rD(ctx->opcode));
7403 sh = tcg_const_i32(VSH(ctx->opcode));
7404 gen_helper_vsldoi (rd, ra, rb, sh);
7405 tcg_temp_free_ptr(ra);
7406 tcg_temp_free_ptr(rb);
7407 tcg_temp_free_ptr(rd);
7408 tcg_temp_free_i32(sh);
7411 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
7412 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7414 TCGv_ptr ra, rb, rc, rd; \
7415 if (unlikely(!ctx->altivec_enabled)) { \
7416 gen_exception(ctx, POWERPC_EXCP_VPU); \
7419 ra = gen_avr_ptr(rA(ctx->opcode)); \
7420 rb = gen_avr_ptr(rB(ctx->opcode)); \
7421 rc = gen_avr_ptr(rC(ctx->opcode)); \
7422 rd = gen_avr_ptr(rD(ctx->opcode)); \
7423 if (Rc(ctx->opcode)) { \
7424 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
7426 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
7428 tcg_temp_free_ptr(ra); \
7429 tcg_temp_free_ptr(rb); \
7430 tcg_temp_free_ptr(rc); \
7431 tcg_temp_free_ptr(rd); \
7434 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7436 static void gen_vmladduhm(DisasContext *ctx)
7438 TCGv_ptr ra, rb, rc, rd;
7439 if (unlikely(!ctx->altivec_enabled)) {
7440 gen_exception(ctx, POWERPC_EXCP_VPU);
7443 ra = gen_avr_ptr(rA(ctx->opcode));
7444 rb = gen_avr_ptr(rB(ctx->opcode));
7445 rc = gen_avr_ptr(rC(ctx->opcode));
7446 rd = gen_avr_ptr(rD(ctx->opcode));
7447 gen_helper_vmladduhm(rd, ra, rb, rc);
7448 tcg_temp_free_ptr(ra);
7449 tcg_temp_free_ptr(rb);
7450 tcg_temp_free_ptr(rc);
7451 tcg_temp_free_ptr(rd);
7454 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
7455 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
7456 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
7457 GEN_VAFORM_PAIRED(vsel, vperm, 21)
7458 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
7460 GEN_VXFORM_NOA(vclzb, 1, 28)
7461 GEN_VXFORM_NOA(vclzh, 1, 29)
7462 GEN_VXFORM_NOA(vclzw, 1, 30)
7463 GEN_VXFORM_NOA(vclzd, 1, 31)
7464 GEN_VXFORM_NOA(vpopcntb, 1, 28)
7465 GEN_VXFORM_NOA(vpopcnth, 1, 29)
7466 GEN_VXFORM_NOA(vpopcntw, 1, 30)
7467 GEN_VXFORM_NOA(vpopcntd, 1, 31)
7468 GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7469 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7470 GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7471 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7472 GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7473 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7474 GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7475 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
7476 GEN_VXFORM(vbpermq, 6, 21);
7477 GEN_VXFORM_NOA(vgbbd, 6, 20);
7478 GEN_VXFORM(vpmsumb, 4, 16)
7479 GEN_VXFORM(vpmsumh, 4, 17)
7480 GEN_VXFORM(vpmsumw, 4, 18)
7481 GEN_VXFORM(vpmsumd, 4, 19)
7483 #define GEN_BCD(op) \
7484 static void gen_##op(DisasContext *ctx) \
7486 TCGv_ptr ra, rb, rd; \
7489 if (unlikely(!ctx->altivec_enabled)) { \
7490 gen_exception(ctx, POWERPC_EXCP_VPU); \
7494 ra = gen_avr_ptr(rA(ctx->opcode)); \
7495 rb = gen_avr_ptr(rB(ctx->opcode)); \
7496 rd = gen_avr_ptr(rD(ctx->opcode)); \
7498 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7500 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7502 tcg_temp_free_ptr(ra); \
7503 tcg_temp_free_ptr(rb); \
7504 tcg_temp_free_ptr(rd); \
7505 tcg_temp_free_i32(ps); \
7511 GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7512 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7513 GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7514 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7515 GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7516 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7517 GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7518 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7520 static void gen_vsbox(DisasContext *ctx)
7523 if (unlikely(!ctx->altivec_enabled)) {
7524 gen_exception(ctx, POWERPC_EXCP_VPU);
7527 ra = gen_avr_ptr(rA(ctx->opcode));
7528 rd = gen_avr_ptr(rD(ctx->opcode));
7529 gen_helper_vsbox(rd, ra);
7530 tcg_temp_free_ptr(ra);
7531 tcg_temp_free_ptr(rd);
7534 GEN_VXFORM(vcipher, 4, 20)
7535 GEN_VXFORM(vcipherlast, 4, 20)
7536 GEN_VXFORM(vncipher, 4, 21)
7537 GEN_VXFORM(vncipherlast, 4, 21)
7539 GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7540 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7541 GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7542 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7544 #define VSHASIGMA(op) \
7545 static void gen_##op(DisasContext *ctx) \
7549 if (unlikely(!ctx->altivec_enabled)) { \
7550 gen_exception(ctx, POWERPC_EXCP_VPU); \
7553 ra = gen_avr_ptr(rA(ctx->opcode)); \
7554 rd = gen_avr_ptr(rD(ctx->opcode)); \
7555 st_six = tcg_const_i32(rB(ctx->opcode)); \
7556 gen_helper_##op(rd, ra, st_six); \
7557 tcg_temp_free_ptr(ra); \
7558 tcg_temp_free_ptr(rd); \
7559 tcg_temp_free_i32(st_six); \
7562 VSHASIGMA(vshasigmaw)
7563 VSHASIGMA(vshasigmad)
7565 GEN_VXFORM3(vpermxor, 22, 0xFF)
7566 GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7567 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7569 /*** VSX extension ***/
7571 static inline TCGv_i64 cpu_vsrh(int n)
7576 return cpu_avrh[n-32];
7580 static inline TCGv_i64 cpu_vsrl(int n)
7585 return cpu_avrl[n-32];
7589 #define VSX_LOAD_SCALAR(name, operation) \
7590 static void gen_##name(DisasContext *ctx) \
7593 if (unlikely(!ctx->vsx_enabled)) { \
7594 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7597 gen_set_access_type(ctx, ACCESS_INT); \
7598 EA = tcg_temp_new(); \
7599 gen_addr_reg_index(ctx, EA); \
7600 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7601 /* NOTE: cpu_vsrl is undefined */ \
7602 tcg_temp_free(EA); \
7605 VSX_LOAD_SCALAR(lxsdx, ld64)
7606 VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7607 VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7608 VSX_LOAD_SCALAR(lxsspx, ld32fs)
7610 static void gen_lxvd2x(DisasContext *ctx)
7613 if (unlikely(!ctx->vsx_enabled)) {
7614 gen_exception(ctx, POWERPC_EXCP_VSXU);
7617 gen_set_access_type(ctx, ACCESS_INT);
7618 EA = tcg_temp_new();
7619 gen_addr_reg_index(ctx, EA);
7620 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7621 tcg_gen_addi_tl(EA, EA, 8);
7622 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7626 static void gen_lxvdsx(DisasContext *ctx)
7629 if (unlikely(!ctx->vsx_enabled)) {
7630 gen_exception(ctx, POWERPC_EXCP_VSXU);
7633 gen_set_access_type(ctx, ACCESS_INT);
7634 EA = tcg_temp_new();
7635 gen_addr_reg_index(ctx, EA);
7636 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7637 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
7641 static void gen_lxvw4x(DisasContext *ctx)
7645 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7646 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7647 if (unlikely(!ctx->vsx_enabled)) {
7648 gen_exception(ctx, POWERPC_EXCP_VSXU);
7651 gen_set_access_type(ctx, ACCESS_INT);
7652 EA = tcg_temp_new();
7653 tmp = tcg_temp_new_i64();
7655 gen_addr_reg_index(ctx, EA);
7656 gen_qemu_ld32u_i64(ctx, tmp, EA);
7657 tcg_gen_addi_tl(EA, EA, 4);
7658 gen_qemu_ld32u_i64(ctx, xth, EA);
7659 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7661 tcg_gen_addi_tl(EA, EA, 4);
7662 gen_qemu_ld32u_i64(ctx, tmp, EA);
7663 tcg_gen_addi_tl(EA, EA, 4);
7664 gen_qemu_ld32u_i64(ctx, xtl, EA);
7665 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7668 tcg_temp_free_i64(tmp);
7671 #define VSX_STORE_SCALAR(name, operation) \
7672 static void gen_##name(DisasContext *ctx) \
7675 if (unlikely(!ctx->vsx_enabled)) { \
7676 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7679 gen_set_access_type(ctx, ACCESS_INT); \
7680 EA = tcg_temp_new(); \
7681 gen_addr_reg_index(ctx, EA); \
7682 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7683 tcg_temp_free(EA); \
7686 VSX_STORE_SCALAR(stxsdx, st64)
7687 VSX_STORE_SCALAR(stxsiwx, st32_i64)
7688 VSX_STORE_SCALAR(stxsspx, st32fs)
7690 static void gen_stxvd2x(DisasContext *ctx)
7693 if (unlikely(!ctx->vsx_enabled)) {
7694 gen_exception(ctx, POWERPC_EXCP_VSXU);
7697 gen_set_access_type(ctx, ACCESS_INT);
7698 EA = tcg_temp_new();
7699 gen_addr_reg_index(ctx, EA);
7700 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7701 tcg_gen_addi_tl(EA, EA, 8);
7702 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7706 static void gen_stxvw4x(DisasContext *ctx)
7710 if (unlikely(!ctx->vsx_enabled)) {
7711 gen_exception(ctx, POWERPC_EXCP_VSXU);
7714 gen_set_access_type(ctx, ACCESS_INT);
7715 EA = tcg_temp_new();
7716 gen_addr_reg_index(ctx, EA);
7717 tmp = tcg_temp_new_i64();
7719 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
7720 gen_qemu_st32_i64(ctx, tmp, EA);
7721 tcg_gen_addi_tl(EA, EA, 4);
7722 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7724 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7725 tcg_gen_addi_tl(EA, EA, 4);
7726 gen_qemu_st32_i64(ctx, tmp, EA);
7727 tcg_gen_addi_tl(EA, EA, 4);
7728 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7731 tcg_temp_free_i64(tmp);
7734 #define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7735 static void gen_##name(DisasContext *ctx) \
7737 if (xS(ctx->opcode) < 32) { \
7738 if (unlikely(!ctx->fpu_enabled)) { \
7739 gen_exception(ctx, POWERPC_EXCP_FPU); \
7743 if (unlikely(!ctx->altivec_enabled)) { \
7744 gen_exception(ctx, POWERPC_EXCP_VPU); \
7748 TCGv_i64 tmp = tcg_temp_new_i64(); \
7749 tcg_gen_##tcgop1(tmp, source); \
7750 tcg_gen_##tcgop2(target, tmp); \
7751 tcg_temp_free_i64(tmp); \
7755 MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7756 cpu_vsrh(xS(ctx->opcode)))
7757 MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7758 cpu_gpr[rA(ctx->opcode)])
7759 MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7760 cpu_gpr[rA(ctx->opcode)])
7762 #if defined(TARGET_PPC64)
7763 #define MV_VSRD(name, target, source) \
7764 static void gen_##name(DisasContext *ctx) \
7766 if (xS(ctx->opcode) < 32) { \
7767 if (unlikely(!ctx->fpu_enabled)) { \
7768 gen_exception(ctx, POWERPC_EXCP_FPU); \
7772 if (unlikely(!ctx->altivec_enabled)) { \
7773 gen_exception(ctx, POWERPC_EXCP_VPU); \
7777 tcg_gen_mov_i64(target, source); \
7780 MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7781 MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7785 static void gen_xxpermdi(DisasContext *ctx)
7787 if (unlikely(!ctx->vsx_enabled)) {
7788 gen_exception(ctx, POWERPC_EXCP_VSXU);
7792 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7793 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7796 xh = tcg_temp_new_i64();
7797 xl = tcg_temp_new_i64();
7799 if ((DM(ctx->opcode) & 2) == 0) {
7800 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7802 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7804 if ((DM(ctx->opcode) & 1) == 0) {
7805 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7807 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7810 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7811 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7813 tcg_temp_free_i64(xh);
7814 tcg_temp_free_i64(xl);
7816 if ((DM(ctx->opcode) & 2) == 0) {
7817 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7819 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7821 if ((DM(ctx->opcode) & 1) == 0) {
7822 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7824 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7833 #define SGN_MASK_DP 0x8000000000000000ull
7834 #define SGN_MASK_SP 0x8000000080000000ull
7836 #define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7837 static void glue(gen_, name)(DisasContext * ctx) \
7840 if (unlikely(!ctx->vsx_enabled)) { \
7841 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7844 xb = tcg_temp_new_i64(); \
7845 sgm = tcg_temp_new_i64(); \
7846 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7847 tcg_gen_movi_i64(sgm, sgn_mask); \
7850 tcg_gen_andc_i64(xb, xb, sgm); \
7854 tcg_gen_or_i64(xb, xb, sgm); \
7858 tcg_gen_xor_i64(xb, xb, sgm); \
7862 TCGv_i64 xa = tcg_temp_new_i64(); \
7863 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7864 tcg_gen_and_i64(xa, xa, sgm); \
7865 tcg_gen_andc_i64(xb, xb, sgm); \
7866 tcg_gen_or_i64(xb, xb, xa); \
7867 tcg_temp_free_i64(xa); \
7871 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
7872 tcg_temp_free_i64(xb); \
7873 tcg_temp_free_i64(sgm); \
7876 VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7877 VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7878 VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7879 VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7881 #define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7882 static void glue(gen_, name)(DisasContext * ctx) \
7884 TCGv_i64 xbh, xbl, sgm; \
7885 if (unlikely(!ctx->vsx_enabled)) { \
7886 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7889 xbh = tcg_temp_new_i64(); \
7890 xbl = tcg_temp_new_i64(); \
7891 sgm = tcg_temp_new_i64(); \
7892 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7893 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7894 tcg_gen_movi_i64(sgm, sgn_mask); \
7897 tcg_gen_andc_i64(xbh, xbh, sgm); \
7898 tcg_gen_andc_i64(xbl, xbl, sgm); \
7902 tcg_gen_or_i64(xbh, xbh, sgm); \
7903 tcg_gen_or_i64(xbl, xbl, sgm); \
7907 tcg_gen_xor_i64(xbh, xbh, sgm); \
7908 tcg_gen_xor_i64(xbl, xbl, sgm); \
7912 TCGv_i64 xah = tcg_temp_new_i64(); \
7913 TCGv_i64 xal = tcg_temp_new_i64(); \
7914 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7915 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7916 tcg_gen_and_i64(xah, xah, sgm); \
7917 tcg_gen_and_i64(xal, xal, sgm); \
7918 tcg_gen_andc_i64(xbh, xbh, sgm); \
7919 tcg_gen_andc_i64(xbl, xbl, sgm); \
7920 tcg_gen_or_i64(xbh, xbh, xah); \
7921 tcg_gen_or_i64(xbl, xbl, xal); \
7922 tcg_temp_free_i64(xah); \
7923 tcg_temp_free_i64(xal); \
7927 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7928 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
7929 tcg_temp_free_i64(xbh); \
7930 tcg_temp_free_i64(xbl); \
7931 tcg_temp_free_i64(sgm); \
7934 VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7935 VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7936 VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7937 VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7938 VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7939 VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7940 VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7941 VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7943 #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7944 static void gen_##name(DisasContext * ctx) \
7947 if (unlikely(!ctx->vsx_enabled)) { \
7948 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7951 /* NIP cannot be restored if the memory exception comes from an helper */ \
7952 gen_update_nip(ctx, ctx->nip - 4); \
7953 opc = tcg_const_i32(ctx->opcode); \
7954 gen_helper_##name(cpu_env, opc); \
7955 tcg_temp_free_i32(opc); \
7958 #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7959 static void gen_##name(DisasContext * ctx) \
7961 if (unlikely(!ctx->vsx_enabled)) { \
7962 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7965 /* NIP cannot be restored if the exception comes */ \
7966 /* from a helper. */ \
7967 gen_update_nip(ctx, ctx->nip - 4); \
7969 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7970 cpu_vsrh(xB(ctx->opcode))); \
7973 GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7974 GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
7975 GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
7976 GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
7977 GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
7978 GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
7979 GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
7980 GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
7981 GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
7982 GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7983 GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7984 GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7985 GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7986 GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7987 GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7988 GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7989 GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
7990 GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7991 GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
7992 GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7993 GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
7994 GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7995 GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
7996 GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7997 GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
7998 GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7999 GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
8000 GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
8001 GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
8002 GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
8003 GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
8004 GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
8005 GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
8006 GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
8007 GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
8008 GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
8009 GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
8011 GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
8012 GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
8013 GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
8014 GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
8015 GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
8016 GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
8017 GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
8018 GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
8019 GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
8020 GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
8021 GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
8022 GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
8023 GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
8024 GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
8025 GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
8026 GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
8027 GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
8029 GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
8030 GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
8031 GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
8032 GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
8033 GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
8034 GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
8035 GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
8036 GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
8037 GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
8038 GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
8039 GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
8040 GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
8041 GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
8042 GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
8043 GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
8044 GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
8045 GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
8046 GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
8047 GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
8048 GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
8049 GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
8050 GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
8051 GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
8052 GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
8053 GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
8054 GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
8055 GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
8056 GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
8057 GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
8058 GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
8059 GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
8060 GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
8061 GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
8062 GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
8063 GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
8064 GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
8066 GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
8067 GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
8068 GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
8069 GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
8070 GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
8071 GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
8072 GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
8073 GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
8074 GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
8075 GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
8076 GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
8077 GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
8078 GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
8079 GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
8080 GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
8081 GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
8082 GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
8083 GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
8084 GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
8085 GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
8086 GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
8087 GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
8088 GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
8089 GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
8090 GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
8091 GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
8092 GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
8093 GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
8094 GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
8095 GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
8096 GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
8097 GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
8098 GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
8099 GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
8100 GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
8101 GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
8103 #define VSX_LOGICAL(name, tcg_op) \
8104 static void glue(gen_, name)(DisasContext * ctx) \
8106 if (unlikely(!ctx->vsx_enabled)) { \
8107 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8110 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8111 cpu_vsrh(xB(ctx->opcode))); \
8112 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8113 cpu_vsrl(xB(ctx->opcode))); \
8116 VSX_LOGICAL(xxland, tcg_gen_and_i64)
8117 VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8118 VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8119 VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8120 VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
8121 VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8122 VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8123 VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
8125 #define VSX_XXMRG(name, high) \
8126 static void glue(gen_, name)(DisasContext * ctx) \
8128 TCGv_i64 a0, a1, b0, b1; \
8129 if (unlikely(!ctx->vsx_enabled)) { \
8130 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8133 a0 = tcg_temp_new_i64(); \
8134 a1 = tcg_temp_new_i64(); \
8135 b0 = tcg_temp_new_i64(); \
8136 b1 = tcg_temp_new_i64(); \
8138 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8139 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8140 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8141 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8143 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8144 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8145 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8146 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8148 tcg_gen_shri_i64(a0, a0, 32); \
8149 tcg_gen_shri_i64(b0, b0, 32); \
8150 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8152 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8154 tcg_temp_free_i64(a0); \
8155 tcg_temp_free_i64(a1); \
8156 tcg_temp_free_i64(b0); \
8157 tcg_temp_free_i64(b1); \
8160 VSX_XXMRG(xxmrghw, 1)
8161 VSX_XXMRG(xxmrglw, 0)
8163 static void gen_xxsel(DisasContext * ctx)
8166 if (unlikely(!ctx->vsx_enabled)) {
8167 gen_exception(ctx, POWERPC_EXCP_VSXU);
8170 a = tcg_temp_new_i64();
8171 b = tcg_temp_new_i64();
8172 c = tcg_temp_new_i64();
8174 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8175 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8176 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8178 tcg_gen_and_i64(b, b, c);
8179 tcg_gen_andc_i64(a, a, c);
8180 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8182 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8183 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8184 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8186 tcg_gen_and_i64(b, b, c);
8187 tcg_gen_andc_i64(a, a, c);
8188 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8190 tcg_temp_free_i64(a);
8191 tcg_temp_free_i64(b);
8192 tcg_temp_free_i64(c);
8195 static void gen_xxspltw(DisasContext *ctx)
8198 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8199 cpu_vsrl(xB(ctx->opcode)) :
8200 cpu_vsrh(xB(ctx->opcode));
8202 if (unlikely(!ctx->vsx_enabled)) {
8203 gen_exception(ctx, POWERPC_EXCP_VSXU);
8207 b = tcg_temp_new_i64();
8208 b2 = tcg_temp_new_i64();
8210 if (UIM(ctx->opcode) & 1) {
8211 tcg_gen_ext32u_i64(b, vsr);
8213 tcg_gen_shri_i64(b, vsr, 32);
8216 tcg_gen_shli_i64(b2, b, 32);
8217 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8218 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8220 tcg_temp_free_i64(b);
8221 tcg_temp_free_i64(b2);
8224 static void gen_xxsldwi(DisasContext *ctx)
8227 if (unlikely(!ctx->vsx_enabled)) {
8228 gen_exception(ctx, POWERPC_EXCP_VSXU);
8231 xth = tcg_temp_new_i64();
8232 xtl = tcg_temp_new_i64();
8234 switch (SHW(ctx->opcode)) {
8236 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8237 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8241 TCGv_i64 t0 = tcg_temp_new_i64();
8242 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8243 tcg_gen_shli_i64(xth, xth, 32);
8244 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8245 tcg_gen_shri_i64(t0, t0, 32);
8246 tcg_gen_or_i64(xth, xth, t0);
8247 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8248 tcg_gen_shli_i64(xtl, xtl, 32);
8249 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8250 tcg_gen_shri_i64(t0, t0, 32);
8251 tcg_gen_or_i64(xtl, xtl, t0);
8252 tcg_temp_free_i64(t0);
8256 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8257 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8261 TCGv_i64 t0 = tcg_temp_new_i64();
8262 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8263 tcg_gen_shli_i64(xth, xth, 32);
8264 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8265 tcg_gen_shri_i64(t0, t0, 32);
8266 tcg_gen_or_i64(xth, xth, t0);
8267 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8268 tcg_gen_shli_i64(xtl, xtl, 32);
8269 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8270 tcg_gen_shri_i64(t0, t0, 32);
8271 tcg_gen_or_i64(xtl, xtl, t0);
8272 tcg_temp_free_i64(t0);
8277 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8278 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8280 tcg_temp_free_i64(xth);
8281 tcg_temp_free_i64(xtl);
8284 /*** Decimal Floating Point ***/
8286 static inline TCGv_ptr gen_fprp_ptr(int reg)
8288 TCGv_ptr r = tcg_temp_new_ptr();
8289 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, fpr[reg]));
8293 #define GEN_DFP_T_A_B_Rc(name) \
8294 static void gen_##name(DisasContext *ctx) \
8296 TCGv_ptr rd, ra, rb; \
8297 if (unlikely(!ctx->fpu_enabled)) { \
8298 gen_exception(ctx, POWERPC_EXCP_FPU); \
8301 gen_update_nip(ctx, ctx->nip - 4); \
8302 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8303 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8304 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8305 gen_helper_##name(cpu_env, rd, ra, rb); \
8306 if (unlikely(Rc(ctx->opcode) != 0)) { \
8307 gen_set_cr1_from_fpscr(ctx); \
8309 tcg_temp_free_ptr(rd); \
8310 tcg_temp_free_ptr(ra); \
8311 tcg_temp_free_ptr(rb); \
8314 #define GEN_DFP_BF_A_B(name) \
8315 static void gen_##name(DisasContext *ctx) \
8318 if (unlikely(!ctx->fpu_enabled)) { \
8319 gen_exception(ctx, POWERPC_EXCP_FPU); \
8322 gen_update_nip(ctx, ctx->nip - 4); \
8323 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8324 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8325 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8327 tcg_temp_free_ptr(ra); \
8328 tcg_temp_free_ptr(rb); \
8331 #define GEN_DFP_BF_A_DCM(name) \
8332 static void gen_##name(DisasContext *ctx) \
8336 if (unlikely(!ctx->fpu_enabled)) { \
8337 gen_exception(ctx, POWERPC_EXCP_FPU); \
8340 gen_update_nip(ctx, ctx->nip - 4); \
8341 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8342 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8343 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8344 cpu_env, ra, dcm); \
8345 tcg_temp_free_ptr(ra); \
8346 tcg_temp_free_i32(dcm); \
8349 #define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8350 static void gen_##name(DisasContext *ctx) \
8353 TCGv_i32 u32_1, u32_2; \
8354 if (unlikely(!ctx->fpu_enabled)) { \
8355 gen_exception(ctx, POWERPC_EXCP_FPU); \
8358 gen_update_nip(ctx, ctx->nip - 4); \
8359 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8360 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8361 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8362 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8363 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8364 if (unlikely(Rc(ctx->opcode) != 0)) { \
8365 gen_set_cr1_from_fpscr(ctx); \
8367 tcg_temp_free_ptr(rt); \
8368 tcg_temp_free_ptr(rb); \
8369 tcg_temp_free_i32(u32_1); \
8370 tcg_temp_free_i32(u32_2); \
8373 #define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8374 static void gen_##name(DisasContext *ctx) \
8376 TCGv_ptr rt, ra, rb; \
8378 if (unlikely(!ctx->fpu_enabled)) { \
8379 gen_exception(ctx, POWERPC_EXCP_FPU); \
8382 gen_update_nip(ctx, ctx->nip - 4); \
8383 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8384 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8385 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8386 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8387 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8388 if (unlikely(Rc(ctx->opcode) != 0)) { \
8389 gen_set_cr1_from_fpscr(ctx); \
8391 tcg_temp_free_ptr(rt); \
8392 tcg_temp_free_ptr(rb); \
8393 tcg_temp_free_ptr(ra); \
8394 tcg_temp_free_i32(i32); \
8397 #define GEN_DFP_T_B_Rc(name) \
8398 static void gen_##name(DisasContext *ctx) \
8401 if (unlikely(!ctx->fpu_enabled)) { \
8402 gen_exception(ctx, POWERPC_EXCP_FPU); \
8405 gen_update_nip(ctx, ctx->nip - 4); \
8406 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8407 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8408 gen_helper_##name(cpu_env, rt, rb); \
8409 if (unlikely(Rc(ctx->opcode) != 0)) { \
8410 gen_set_cr1_from_fpscr(ctx); \
8412 tcg_temp_free_ptr(rt); \
8413 tcg_temp_free_ptr(rb); \
8416 #define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8417 static void gen_##name(DisasContext *ctx) \
8421 if (unlikely(!ctx->fpu_enabled)) { \
8422 gen_exception(ctx, POWERPC_EXCP_FPU); \
8425 gen_update_nip(ctx, ctx->nip - 4); \
8426 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8427 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8428 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8429 gen_helper_##name(cpu_env, rt, rs, i32); \
8430 if (unlikely(Rc(ctx->opcode) != 0)) { \
8431 gen_set_cr1_from_fpscr(ctx); \
8433 tcg_temp_free_ptr(rt); \
8434 tcg_temp_free_ptr(rs); \
8435 tcg_temp_free_i32(i32); \
8438 GEN_DFP_T_A_B_Rc(dadd)
8439 GEN_DFP_T_A_B_Rc(daddq)
8440 GEN_DFP_T_A_B_Rc(dsub)
8441 GEN_DFP_T_A_B_Rc(dsubq)
8442 GEN_DFP_T_A_B_Rc(dmul)
8443 GEN_DFP_T_A_B_Rc(dmulq)
8444 GEN_DFP_T_A_B_Rc(ddiv)
8445 GEN_DFP_T_A_B_Rc(ddivq)
8446 GEN_DFP_BF_A_B(dcmpu)
8447 GEN_DFP_BF_A_B(dcmpuq)
8448 GEN_DFP_BF_A_B(dcmpo)
8449 GEN_DFP_BF_A_B(dcmpoq)
8450 GEN_DFP_BF_A_DCM(dtstdc)
8451 GEN_DFP_BF_A_DCM(dtstdcq)
8452 GEN_DFP_BF_A_DCM(dtstdg)
8453 GEN_DFP_BF_A_DCM(dtstdgq)
8454 GEN_DFP_BF_A_B(dtstex)
8455 GEN_DFP_BF_A_B(dtstexq)
8456 GEN_DFP_BF_A_B(dtstsf)
8457 GEN_DFP_BF_A_B(dtstsfq)
8458 GEN_DFP_T_B_U32_U32_Rc(dquai, SIMM5, RMC)
8459 GEN_DFP_T_B_U32_U32_Rc(dquaiq, SIMM5, RMC)
8460 GEN_DFP_T_A_B_I32_Rc(dqua, RMC)
8461 GEN_DFP_T_A_B_I32_Rc(dquaq, RMC)
8462 GEN_DFP_T_A_B_I32_Rc(drrnd, RMC)
8463 GEN_DFP_T_A_B_I32_Rc(drrndq, RMC)
8464 GEN_DFP_T_B_U32_U32_Rc(drintx, FPW, RMC)
8465 GEN_DFP_T_B_U32_U32_Rc(drintxq, FPW, RMC)
8466 GEN_DFP_T_B_U32_U32_Rc(drintn, FPW, RMC)
8467 GEN_DFP_T_B_U32_U32_Rc(drintnq, FPW, RMC)
8468 GEN_DFP_T_B_Rc(dctdp)
8469 GEN_DFP_T_B_Rc(dctqpq)
8470 GEN_DFP_T_B_Rc(drsp)
8471 GEN_DFP_T_B_Rc(drdpq)
8472 GEN_DFP_T_B_Rc(dcffix)
8473 GEN_DFP_T_B_Rc(dcffixq)
8474 GEN_DFP_T_B_Rc(dctfix)
8475 GEN_DFP_T_B_Rc(dctfixq)
8476 GEN_DFP_T_FPR_I32_Rc(ddedpd, rB, SP)
8477 GEN_DFP_T_FPR_I32_Rc(ddedpdq, rB, SP)
8478 GEN_DFP_T_FPR_I32_Rc(denbcd, rB, SP)
8479 GEN_DFP_T_FPR_I32_Rc(denbcdq, rB, SP)
8480 GEN_DFP_T_B_Rc(dxex)
8481 GEN_DFP_T_B_Rc(dxexq)
8482 GEN_DFP_T_A_B_Rc(diex)
8483 GEN_DFP_T_A_B_Rc(diexq)
8484 GEN_DFP_T_FPR_I32_Rc(dscli, rA, DCM)
8485 GEN_DFP_T_FPR_I32_Rc(dscliq, rA, DCM)
8486 GEN_DFP_T_FPR_I32_Rc(dscri, rA, DCM)
8487 GEN_DFP_T_FPR_I32_Rc(dscriq, rA, DCM)
8489 /*** SPE extension ***/
8490 /* Register moves */
8492 static inline void gen_evmra(DisasContext *ctx)
8495 if (unlikely(!ctx->spe_enabled)) {
8496 gen_exception(ctx, POWERPC_EXCP_SPEU);
8500 TCGv_i64 tmp = tcg_temp_new_i64();
8502 /* tmp := rA_lo + rA_hi << 32 */
8503 tcg_gen_concat_tl_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8505 /* spe_acc := tmp */
8506 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
8507 tcg_temp_free_i64(tmp);
8510 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8511 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8514 static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8516 tcg_gen_concat_tl_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
8519 static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8521 tcg_gen_extr_i64_tl(cpu_gpr[reg], cpu_gprh[reg], t);
8524 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
8525 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
8527 if (Rc(ctx->opcode)) \
8533 /* Handler for undefined SPE opcodes */
8534 static inline void gen_speundef(DisasContext *ctx)
8536 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
8540 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
8541 static inline void gen_##name(DisasContext *ctx) \
8543 if (unlikely(!ctx->spe_enabled)) { \
8544 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8547 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8548 cpu_gpr[rB(ctx->opcode)]); \
8549 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8550 cpu_gprh[rB(ctx->opcode)]); \
8553 GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8554 GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8555 GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8556 GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8557 GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8558 GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8559 GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8560 GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
8562 /* SPE logic immediate */
8563 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
8564 static inline void gen_##name(DisasContext *ctx) \
8567 if (unlikely(!ctx->spe_enabled)) { \
8568 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8571 t0 = tcg_temp_new_i32(); \
8573 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8574 tcg_opi(t0, t0, rB(ctx->opcode)); \
8575 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8577 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8578 tcg_opi(t0, t0, rB(ctx->opcode)); \
8579 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8581 tcg_temp_free_i32(t0); \
8583 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8584 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8585 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8586 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
8588 /* SPE arithmetic */
8589 #define GEN_SPEOP_ARITH1(name, tcg_op) \
8590 static inline void gen_##name(DisasContext *ctx) \
8593 if (unlikely(!ctx->spe_enabled)) { \
8594 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8597 t0 = tcg_temp_new_i32(); \
8599 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8601 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8603 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8605 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8607 tcg_temp_free_i32(t0); \
8610 static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
8612 TCGLabel *l1 = gen_new_label();
8613 TCGLabel *l2 = gen_new_label();
8615 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8616 tcg_gen_neg_i32(ret, arg1);
8619 tcg_gen_mov_i32(ret, arg1);
8622 GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8623 GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8624 GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8625 GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
8626 static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
8628 tcg_gen_addi_i32(ret, arg1, 0x8000);
8629 tcg_gen_ext16u_i32(ret, ret);
8631 GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
8632 GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8633 GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
8635 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8636 static inline void gen_##name(DisasContext *ctx) \
8639 if (unlikely(!ctx->spe_enabled)) { \
8640 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8643 t0 = tcg_temp_new_i32(); \
8644 t1 = tcg_temp_new_i32(); \
8646 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8647 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8648 tcg_op(t0, t0, t1); \
8649 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8651 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8652 tcg_gen_trunc_tl_i32(t1, cpu_gprh[rB(ctx->opcode)]); \
8653 tcg_op(t0, t0, t1); \
8654 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8656 tcg_temp_free_i32(t0); \
8657 tcg_temp_free_i32(t1); \
8660 static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8662 TCGLabel *l1 = gen_new_label();
8663 TCGLabel *l2 = gen_new_label();
8664 TCGv_i32 t0 = tcg_temp_local_new_i32();
8666 /* No error here: 6 bits are used */
8667 tcg_gen_andi_i32(t0, arg2, 0x3F);
8668 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8669 tcg_gen_shr_i32(ret, arg1, t0);
8672 tcg_gen_movi_i32(ret, 0);
8674 tcg_temp_free_i32(t0);
8676 GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
8677 static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8679 TCGLabel *l1 = gen_new_label();
8680 TCGLabel *l2 = gen_new_label();
8681 TCGv_i32 t0 = tcg_temp_local_new_i32();
8683 /* No error here: 6 bits are used */
8684 tcg_gen_andi_i32(t0, arg2, 0x3F);
8685 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8686 tcg_gen_sar_i32(ret, arg1, t0);
8689 tcg_gen_movi_i32(ret, 0);
8691 tcg_temp_free_i32(t0);
8693 GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
8694 static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8696 TCGLabel *l1 = gen_new_label();
8697 TCGLabel *l2 = gen_new_label();
8698 TCGv_i32 t0 = tcg_temp_local_new_i32();
8700 /* No error here: 6 bits are used */
8701 tcg_gen_andi_i32(t0, arg2, 0x3F);
8702 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8703 tcg_gen_shl_i32(ret, arg1, t0);
8706 tcg_gen_movi_i32(ret, 0);
8708 tcg_temp_free_i32(t0);
8710 GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
8711 static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8713 TCGv_i32 t0 = tcg_temp_new_i32();
8714 tcg_gen_andi_i32(t0, arg2, 0x1F);
8715 tcg_gen_rotl_i32(ret, arg1, t0);
8716 tcg_temp_free_i32(t0);
8718 GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
8719 static inline void gen_evmergehi(DisasContext *ctx)
8721 if (unlikely(!ctx->spe_enabled)) {
8722 gen_exception(ctx, POWERPC_EXCP_SPEU);
8725 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8726 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8728 GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
8729 static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
8731 tcg_gen_sub_i32(ret, arg2, arg1);
8733 GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
8735 /* SPE arithmetic immediate */
8736 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8737 static inline void gen_##name(DisasContext *ctx) \
8740 if (unlikely(!ctx->spe_enabled)) { \
8741 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8744 t0 = tcg_temp_new_i32(); \
8746 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8747 tcg_op(t0, t0, rA(ctx->opcode)); \
8748 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8750 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rB(ctx->opcode)]); \
8751 tcg_op(t0, t0, rA(ctx->opcode)); \
8752 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8754 tcg_temp_free_i32(t0); \
8756 GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8757 GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8759 /* SPE comparison */
8760 #define GEN_SPEOP_COMP(name, tcg_cond) \
8761 static inline void gen_##name(DisasContext *ctx) \
8763 if (unlikely(!ctx->spe_enabled)) { \
8764 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8767 TCGLabel *l1 = gen_new_label(); \
8768 TCGLabel *l2 = gen_new_label(); \
8769 TCGLabel *l3 = gen_new_label(); \
8770 TCGLabel *l4 = gen_new_label(); \
8772 tcg_gen_ext32s_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8773 tcg_gen_ext32s_tl(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8774 tcg_gen_ext32s_tl(cpu_gprh[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8775 tcg_gen_ext32s_tl(cpu_gprh[rB(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); \
8777 tcg_gen_brcond_tl(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8778 cpu_gpr[rB(ctx->opcode)], l1); \
8779 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
8781 gen_set_label(l1); \
8782 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8783 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8784 gen_set_label(l2); \
8785 tcg_gen_brcond_tl(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8786 cpu_gprh[rB(ctx->opcode)], l3); \
8787 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8788 ~(CRF_CH | CRF_CH_AND_CL)); \
8790 gen_set_label(l3); \
8791 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8792 CRF_CH | CRF_CH_OR_CL); \
8793 gen_set_label(l4); \
8795 GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8796 GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8797 GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8798 GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8799 GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8802 static inline void gen_brinc(DisasContext *ctx)
8804 /* Note: brinc is usable even if SPE is disabled */
8805 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8806 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8808 static inline void gen_evmergelo(DisasContext *ctx)
8810 if (unlikely(!ctx->spe_enabled)) {
8811 gen_exception(ctx, POWERPC_EXCP_SPEU);
8814 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8815 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8817 static inline void gen_evmergehilo(DisasContext *ctx)
8819 if (unlikely(!ctx->spe_enabled)) {
8820 gen_exception(ctx, POWERPC_EXCP_SPEU);
8823 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8824 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8826 static inline void gen_evmergelohi(DisasContext *ctx)
8828 if (unlikely(!ctx->spe_enabled)) {
8829 gen_exception(ctx, POWERPC_EXCP_SPEU);
8832 if (rD(ctx->opcode) == rA(ctx->opcode)) {
8833 TCGv tmp = tcg_temp_new();
8834 tcg_gen_mov_tl(tmp, cpu_gpr[rA(ctx->opcode)]);
8835 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8836 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], tmp);
8839 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8840 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8843 static inline void gen_evsplati(DisasContext *ctx)
8845 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
8847 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
8848 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
8850 static inline void gen_evsplatfi(DisasContext *ctx)
8852 uint64_t imm = rA(ctx->opcode) << 27;
8854 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
8855 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
8858 static inline void gen_evsel(DisasContext *ctx)
8860 TCGLabel *l1 = gen_new_label();
8861 TCGLabel *l2 = gen_new_label();
8862 TCGLabel *l3 = gen_new_label();
8863 TCGLabel *l4 = gen_new_label();
8864 TCGv_i32 t0 = tcg_temp_local_new_i32();
8866 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8867 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
8868 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8871 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8873 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8874 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
8875 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8878 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8880 tcg_temp_free_i32(t0);
8883 static void gen_evsel0(DisasContext *ctx)
8888 static void gen_evsel1(DisasContext *ctx)
8893 static void gen_evsel2(DisasContext *ctx)
8898 static void gen_evsel3(DisasContext *ctx)
8905 static inline void gen_evmwumi(DisasContext *ctx)
8909 if (unlikely(!ctx->spe_enabled)) {
8910 gen_exception(ctx, POWERPC_EXCP_SPEU);
8914 t0 = tcg_temp_new_i64();
8915 t1 = tcg_temp_new_i64();
8917 /* t0 := rA; t1 := rB */
8918 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8919 tcg_gen_ext32u_i64(t0, t0);
8920 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8921 tcg_gen_ext32u_i64(t1, t1);
8923 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8925 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8927 tcg_temp_free_i64(t0);
8928 tcg_temp_free_i64(t1);
8931 static inline void gen_evmwumia(DisasContext *ctx)
8935 if (unlikely(!ctx->spe_enabled)) {
8936 gen_exception(ctx, POWERPC_EXCP_SPEU);
8940 gen_evmwumi(ctx); /* rD := rA * rB */
8942 tmp = tcg_temp_new_i64();
8945 gen_load_gpr64(tmp, rD(ctx->opcode));
8946 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
8947 tcg_temp_free_i64(tmp);
8950 static inline void gen_evmwumiaa(DisasContext *ctx)
8955 if (unlikely(!ctx->spe_enabled)) {
8956 gen_exception(ctx, POWERPC_EXCP_SPEU);
8960 gen_evmwumi(ctx); /* rD := rA * rB */
8962 acc = tcg_temp_new_i64();
8963 tmp = tcg_temp_new_i64();
8966 gen_load_gpr64(tmp, rD(ctx->opcode));
8969 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
8971 /* acc := tmp + acc */
8972 tcg_gen_add_i64(acc, acc, tmp);
8975 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
8978 gen_store_gpr64(rD(ctx->opcode), acc);
8980 tcg_temp_free_i64(acc);
8981 tcg_temp_free_i64(tmp);
8984 static inline void gen_evmwsmi(DisasContext *ctx)
8988 if (unlikely(!ctx->spe_enabled)) {
8989 gen_exception(ctx, POWERPC_EXCP_SPEU);
8993 t0 = tcg_temp_new_i64();
8994 t1 = tcg_temp_new_i64();
8996 /* t0 := rA; t1 := rB */
8997 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8998 tcg_gen_ext32s_i64(t0, t0);
8999 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9000 tcg_gen_ext32s_i64(t1, t1);
9002 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9004 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9006 tcg_temp_free_i64(t0);
9007 tcg_temp_free_i64(t1);
9010 static inline void gen_evmwsmia(DisasContext *ctx)
9014 gen_evmwsmi(ctx); /* rD := rA * rB */
9016 tmp = tcg_temp_new_i64();
9019 gen_load_gpr64(tmp, rD(ctx->opcode));
9020 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
9022 tcg_temp_free_i64(tmp);
9025 static inline void gen_evmwsmiaa(DisasContext *ctx)
9027 TCGv_i64 acc = tcg_temp_new_i64();
9028 TCGv_i64 tmp = tcg_temp_new_i64();
9030 gen_evmwsmi(ctx); /* rD := rA * rB */
9032 acc = tcg_temp_new_i64();
9033 tmp = tcg_temp_new_i64();
9036 gen_load_gpr64(tmp, rD(ctx->opcode));
9039 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9041 /* acc := tmp + acc */
9042 tcg_gen_add_i64(acc, acc, tmp);
9045 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
9048 gen_store_gpr64(rD(ctx->opcode), acc);
9050 tcg_temp_free_i64(acc);
9051 tcg_temp_free_i64(tmp);
9054 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9055 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9056 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9057 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9058 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9059 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9060 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9061 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
9062 GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
9063 GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9064 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9065 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9066 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9067 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9068 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9069 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9070 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9071 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9072 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9073 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
9074 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9075 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9076 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
9077 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
9078 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9079 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9080 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9081 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9082 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
9084 /* SPE load and stores */
9085 static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
9087 target_ulong uimm = rB(ctx->opcode);
9089 if (rA(ctx->opcode) == 0) {
9090 tcg_gen_movi_tl(EA, uimm << sh);
9092 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
9093 if (NARROW_MODE(ctx)) {
9094 tcg_gen_ext32u_tl(EA, EA);
9099 static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
9101 TCGv_i64 t0 = tcg_temp_new_i64();
9102 gen_qemu_ld64(ctx, t0, addr);
9103 gen_store_gpr64(rD(ctx->opcode), t0);
9104 tcg_temp_free_i64(t0);
9107 static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
9109 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9110 gen_addr_add(ctx, addr, addr, 4);
9111 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9114 static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
9116 TCGv t0 = tcg_temp_new();
9117 gen_qemu_ld16u(ctx, t0, addr);
9118 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9119 gen_addr_add(ctx, addr, addr, 2);
9120 gen_qemu_ld16u(ctx, t0, addr);
9121 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9122 gen_addr_add(ctx, addr, addr, 2);
9123 gen_qemu_ld16u(ctx, t0, addr);
9124 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9125 gen_addr_add(ctx, addr, addr, 2);
9126 gen_qemu_ld16u(ctx, t0, addr);
9127 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9131 static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
9133 TCGv t0 = tcg_temp_new();
9134 gen_qemu_ld16u(ctx, t0, addr);
9135 tcg_gen_shli_tl(t0, t0, 16);
9136 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9137 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9141 static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
9143 TCGv t0 = tcg_temp_new();
9144 gen_qemu_ld16u(ctx, t0, addr);
9145 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9146 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9150 static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
9152 TCGv t0 = tcg_temp_new();
9153 gen_qemu_ld16s(ctx, t0, addr);
9154 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9155 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9159 static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
9161 TCGv t0 = tcg_temp_new();
9162 gen_qemu_ld16u(ctx, t0, addr);
9163 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9164 gen_addr_add(ctx, addr, addr, 2);
9165 gen_qemu_ld16u(ctx, t0, addr);
9166 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9170 static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
9172 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9173 gen_addr_add(ctx, addr, addr, 2);
9174 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9177 static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
9179 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9180 gen_addr_add(ctx, addr, addr, 2);
9181 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9184 static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
9186 TCGv t0 = tcg_temp_new();
9187 gen_qemu_ld32u(ctx, t0, addr);
9188 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9189 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9193 static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
9195 TCGv t0 = tcg_temp_new();
9196 gen_qemu_ld16u(ctx, t0, addr);
9197 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9198 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9199 gen_addr_add(ctx, addr, addr, 2);
9200 gen_qemu_ld16u(ctx, t0, addr);
9201 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9202 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
9206 static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
9208 TCGv_i64 t0 = tcg_temp_new_i64();
9209 gen_load_gpr64(t0, rS(ctx->opcode));
9210 gen_qemu_st64(ctx, t0, addr);
9211 tcg_temp_free_i64(t0);
9214 static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
9216 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9217 gen_addr_add(ctx, addr, addr, 4);
9218 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9221 static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
9223 TCGv t0 = tcg_temp_new();
9224 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9225 gen_qemu_st16(ctx, t0, addr);
9226 gen_addr_add(ctx, addr, addr, 2);
9227 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9228 gen_addr_add(ctx, addr, addr, 2);
9229 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
9230 gen_qemu_st16(ctx, t0, addr);
9232 gen_addr_add(ctx, addr, addr, 2);
9233 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9236 static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
9238 TCGv t0 = tcg_temp_new();
9239 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9240 gen_qemu_st16(ctx, t0, addr);
9241 gen_addr_add(ctx, addr, addr, 2);
9242 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
9243 gen_qemu_st16(ctx, t0, addr);
9247 static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
9249 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9250 gen_addr_add(ctx, addr, addr, 2);
9251 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9254 static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
9256 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
9259 static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
9261 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
9264 #define GEN_SPEOP_LDST(name, opc2, sh) \
9265 static void glue(gen_, name)(DisasContext *ctx) \
9268 if (unlikely(!ctx->spe_enabled)) { \
9269 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9272 gen_set_access_type(ctx, ACCESS_INT); \
9273 t0 = tcg_temp_new(); \
9274 if (Rc(ctx->opcode)) { \
9275 gen_addr_spe_imm_index(ctx, t0, sh); \
9277 gen_addr_reg_index(ctx, t0); \
9279 gen_op_##name(ctx, t0); \
9280 tcg_temp_free(t0); \
9283 GEN_SPEOP_LDST(evldd, 0x00, 3);
9284 GEN_SPEOP_LDST(evldw, 0x01, 3);
9285 GEN_SPEOP_LDST(evldh, 0x02, 3);
9286 GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9287 GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9288 GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9289 GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9290 GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9291 GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9292 GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9293 GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9295 GEN_SPEOP_LDST(evstdd, 0x10, 3);
9296 GEN_SPEOP_LDST(evstdw, 0x11, 3);
9297 GEN_SPEOP_LDST(evstdh, 0x12, 3);
9298 GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9299 GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9300 GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9301 GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
9303 /* Multiply and add - TODO */
9305 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9306 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9307 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9308 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9309 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9310 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9311 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9312 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9313 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9314 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9315 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9316 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9318 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9319 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9320 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9321 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9322 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9323 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9324 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9325 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9326 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9327 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9328 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9329 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9331 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9332 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9333 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9334 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9335 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9337 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9338 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9339 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9340 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9341 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9342 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9343 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9344 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9345 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9346 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9347 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9348 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9350 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9351 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9352 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9353 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9355 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9356 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9357 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9358 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9359 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9360 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9361 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9362 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9363 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9364 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9365 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9366 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9368 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9369 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9370 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9371 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9372 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9375 /*** SPE floating-point extension ***/
9376 #define GEN_SPEFPUOP_CONV_32_32(name) \
9377 static inline void gen_##name(DisasContext *ctx) \
9379 TCGv_i32 t0 = tcg_temp_new_i32(); \
9380 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9381 gen_helper_##name(t0, cpu_env, t0); \
9382 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9383 tcg_temp_free_i32(t0); \
9385 #define GEN_SPEFPUOP_CONV_32_64(name) \
9386 static inline void gen_##name(DisasContext *ctx) \
9388 TCGv_i64 t0 = tcg_temp_new_i64(); \
9389 TCGv_i32 t1 = tcg_temp_new_i32(); \
9390 gen_load_gpr64(t0, rB(ctx->opcode)); \
9391 gen_helper_##name(t1, cpu_env, t0); \
9392 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); \
9393 tcg_temp_free_i64(t0); \
9394 tcg_temp_free_i32(t1); \
9396 #define GEN_SPEFPUOP_CONV_64_32(name) \
9397 static inline void gen_##name(DisasContext *ctx) \
9399 TCGv_i64 t0 = tcg_temp_new_i64(); \
9400 TCGv_i32 t1 = tcg_temp_new_i32(); \
9401 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9402 gen_helper_##name(t0, cpu_env, t1); \
9403 gen_store_gpr64(rD(ctx->opcode), t0); \
9404 tcg_temp_free_i64(t0); \
9405 tcg_temp_free_i32(t1); \
9407 #define GEN_SPEFPUOP_CONV_64_64(name) \
9408 static inline void gen_##name(DisasContext *ctx) \
9410 TCGv_i64 t0 = tcg_temp_new_i64(); \
9411 gen_load_gpr64(t0, rB(ctx->opcode)); \
9412 gen_helper_##name(t0, cpu_env, t0); \
9413 gen_store_gpr64(rD(ctx->opcode), t0); \
9414 tcg_temp_free_i64(t0); \
9416 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9417 static inline void gen_##name(DisasContext *ctx) \
9420 if (unlikely(!ctx->spe_enabled)) { \
9421 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9424 t0 = tcg_temp_new_i32(); \
9425 t1 = tcg_temp_new_i32(); \
9426 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9427 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9428 gen_helper_##name(t0, cpu_env, t0, t1); \
9429 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9431 tcg_temp_free_i32(t0); \
9432 tcg_temp_free_i32(t1); \
9434 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9435 static inline void gen_##name(DisasContext *ctx) \
9438 if (unlikely(!ctx->spe_enabled)) { \
9439 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9442 t0 = tcg_temp_new_i64(); \
9443 t1 = tcg_temp_new_i64(); \
9444 gen_load_gpr64(t0, rA(ctx->opcode)); \
9445 gen_load_gpr64(t1, rB(ctx->opcode)); \
9446 gen_helper_##name(t0, cpu_env, t0, t1); \
9447 gen_store_gpr64(rD(ctx->opcode), t0); \
9448 tcg_temp_free_i64(t0); \
9449 tcg_temp_free_i64(t1); \
9451 #define GEN_SPEFPUOP_COMP_32(name) \
9452 static inline void gen_##name(DisasContext *ctx) \
9455 if (unlikely(!ctx->spe_enabled)) { \
9456 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9459 t0 = tcg_temp_new_i32(); \
9460 t1 = tcg_temp_new_i32(); \
9462 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9463 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9464 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9466 tcg_temp_free_i32(t0); \
9467 tcg_temp_free_i32(t1); \
9469 #define GEN_SPEFPUOP_COMP_64(name) \
9470 static inline void gen_##name(DisasContext *ctx) \
9473 if (unlikely(!ctx->spe_enabled)) { \
9474 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9477 t0 = tcg_temp_new_i64(); \
9478 t1 = tcg_temp_new_i64(); \
9479 gen_load_gpr64(t0, rA(ctx->opcode)); \
9480 gen_load_gpr64(t1, rB(ctx->opcode)); \
9481 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9482 tcg_temp_free_i64(t0); \
9483 tcg_temp_free_i64(t1); \
9486 /* Single precision floating-point vectors operations */
9488 GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9489 GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9490 GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9491 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
9492 static inline void gen_evfsabs(DisasContext *ctx)
9494 if (unlikely(!ctx->spe_enabled)) {
9495 gen_exception(ctx, POWERPC_EXCP_SPEU);
9498 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9500 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9503 static inline void gen_evfsnabs(DisasContext *ctx)
9505 if (unlikely(!ctx->spe_enabled)) {
9506 gen_exception(ctx, POWERPC_EXCP_SPEU);
9509 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9511 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9514 static inline void gen_evfsneg(DisasContext *ctx)
9516 if (unlikely(!ctx->spe_enabled)) {
9517 gen_exception(ctx, POWERPC_EXCP_SPEU);
9520 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9522 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9527 GEN_SPEFPUOP_CONV_64_64(evfscfui);
9528 GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9529 GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9530 GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9531 GEN_SPEFPUOP_CONV_64_64(evfsctui);
9532 GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9533 GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9534 GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9535 GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9536 GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9539 GEN_SPEFPUOP_COMP_64(evfscmpgt);
9540 GEN_SPEFPUOP_COMP_64(evfscmplt);
9541 GEN_SPEFPUOP_COMP_64(evfscmpeq);
9542 GEN_SPEFPUOP_COMP_64(evfststgt);
9543 GEN_SPEFPUOP_COMP_64(evfststlt);
9544 GEN_SPEFPUOP_COMP_64(evfststeq);
9546 /* Opcodes definitions */
9547 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9548 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9549 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9550 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9551 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9552 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9553 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9554 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9555 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9556 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9557 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9558 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9559 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9560 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9562 /* Single precision floating-point operations */
9564 GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9565 GEN_SPEFPUOP_ARITH2_32_32(efssub);
9566 GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9567 GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
9568 static inline void gen_efsabs(DisasContext *ctx)
9570 if (unlikely(!ctx->spe_enabled)) {
9571 gen_exception(ctx, POWERPC_EXCP_SPEU);
9574 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
9576 static inline void gen_efsnabs(DisasContext *ctx)
9578 if (unlikely(!ctx->spe_enabled)) {
9579 gen_exception(ctx, POWERPC_EXCP_SPEU);
9582 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9584 static inline void gen_efsneg(DisasContext *ctx)
9586 if (unlikely(!ctx->spe_enabled)) {
9587 gen_exception(ctx, POWERPC_EXCP_SPEU);
9590 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9594 GEN_SPEFPUOP_CONV_32_32(efscfui);
9595 GEN_SPEFPUOP_CONV_32_32(efscfsi);
9596 GEN_SPEFPUOP_CONV_32_32(efscfuf);
9597 GEN_SPEFPUOP_CONV_32_32(efscfsf);
9598 GEN_SPEFPUOP_CONV_32_32(efsctui);
9599 GEN_SPEFPUOP_CONV_32_32(efsctsi);
9600 GEN_SPEFPUOP_CONV_32_32(efsctuf);
9601 GEN_SPEFPUOP_CONV_32_32(efsctsf);
9602 GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9603 GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9604 GEN_SPEFPUOP_CONV_32_64(efscfd);
9607 GEN_SPEFPUOP_COMP_32(efscmpgt);
9608 GEN_SPEFPUOP_COMP_32(efscmplt);
9609 GEN_SPEFPUOP_COMP_32(efscmpeq);
9610 GEN_SPEFPUOP_COMP_32(efststgt);
9611 GEN_SPEFPUOP_COMP_32(efststlt);
9612 GEN_SPEFPUOP_COMP_32(efststeq);
9614 /* Opcodes definitions */
9615 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9616 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9617 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9618 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9619 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9620 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9621 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9622 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9623 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9624 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9625 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9626 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9627 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9628 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9630 /* Double precision floating-point operations */
9632 GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9633 GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9634 GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9635 GEN_SPEFPUOP_ARITH2_64_64(efddiv);
9636 static inline void gen_efdabs(DisasContext *ctx)
9638 if (unlikely(!ctx->spe_enabled)) {
9639 gen_exception(ctx, POWERPC_EXCP_SPEU);
9642 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9643 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9646 static inline void gen_efdnabs(DisasContext *ctx)
9648 if (unlikely(!ctx->spe_enabled)) {
9649 gen_exception(ctx, POWERPC_EXCP_SPEU);
9652 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9653 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9656 static inline void gen_efdneg(DisasContext *ctx)
9658 if (unlikely(!ctx->spe_enabled)) {
9659 gen_exception(ctx, POWERPC_EXCP_SPEU);
9662 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9663 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9668 GEN_SPEFPUOP_CONV_64_32(efdcfui);
9669 GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9670 GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9671 GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9672 GEN_SPEFPUOP_CONV_32_64(efdctui);
9673 GEN_SPEFPUOP_CONV_32_64(efdctsi);
9674 GEN_SPEFPUOP_CONV_32_64(efdctuf);
9675 GEN_SPEFPUOP_CONV_32_64(efdctsf);
9676 GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9677 GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9678 GEN_SPEFPUOP_CONV_64_32(efdcfs);
9679 GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9680 GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9681 GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9682 GEN_SPEFPUOP_CONV_64_64(efdctsidz);
9685 GEN_SPEFPUOP_COMP_64(efdcmpgt);
9686 GEN_SPEFPUOP_COMP_64(efdcmplt);
9687 GEN_SPEFPUOP_COMP_64(efdcmpeq);
9688 GEN_SPEFPUOP_COMP_64(efdtstgt);
9689 GEN_SPEFPUOP_COMP_64(efdtstlt);
9690 GEN_SPEFPUOP_COMP_64(efdtsteq);
9692 /* Opcodes definitions */
9693 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9694 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9695 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9696 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9697 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9698 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9699 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9700 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9701 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9702 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9703 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9704 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9705 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9706 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9707 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9708 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9710 static void gen_tbegin(DisasContext *ctx)
9712 if (unlikely(!ctx->tm_enabled)) {
9713 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM);
9716 gen_helper_tbegin(cpu_env);
9719 #define GEN_TM_NOOP(name) \
9720 static inline void gen_##name(DisasContext *ctx) \
9722 if (unlikely(!ctx->tm_enabled)) { \
9723 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9726 /* Because tbegin always fails in QEMU, these user \
9727 * space instructions all have a simple implementation: \
9729 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9730 * = 0b0 || 0b00 || 0b0 \
9732 tcg_gen_movi_i32(cpu_crf[0], 0); \
9736 GEN_TM_NOOP(tabort);
9737 GEN_TM_NOOP(tabortwc);
9738 GEN_TM_NOOP(tabortwci);
9739 GEN_TM_NOOP(tabortdc);
9740 GEN_TM_NOOP(tabortdci);
9743 static void gen_tcheck(DisasContext *ctx)
9745 if (unlikely(!ctx->tm_enabled)) {
9746 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM);
9749 /* Because tbegin always fails, the tcheck implementation
9752 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
9753 * = 0b1 || 0b00 || 0b0
9755 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0x8);
9758 #if defined(CONFIG_USER_ONLY)
9759 #define GEN_TM_PRIV_NOOP(name) \
9760 static inline void gen_##name(DisasContext *ctx) \
9762 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9767 #define GEN_TM_PRIV_NOOP(name) \
9768 static inline void gen_##name(DisasContext *ctx) \
9770 if (unlikely(ctx->pr)) { \
9771 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9774 if (unlikely(!ctx->tm_enabled)) { \
9775 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9778 /* Because tbegin always fails, the implementation is \
9781 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9782 * = 0b0 || 0b00 | 0b0 \
9784 tcg_gen_movi_i32(cpu_crf[0], 0); \
9789 GEN_TM_PRIV_NOOP(treclaim);
9790 GEN_TM_PRIV_NOOP(trechkpt);
9792 static opcode_t opcodes[] = {
9793 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9794 GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9795 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9796 GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9797 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9798 GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
9799 GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9800 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9801 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9802 GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9803 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9804 GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9805 GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9806 GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9807 GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9808 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9809 #if defined(TARGET_PPC64)
9810 GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9812 GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9813 GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9814 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9815 GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9816 GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9817 GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9818 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9819 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9820 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9821 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9822 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9823 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9824 GEN_HANDLER(popcntb, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB),
9825 GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
9826 GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
9827 #if defined(TARGET_PPC64)
9828 GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
9829 GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
9830 GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
9831 GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
9833 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9834 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9835 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9836 GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9837 GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9838 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9839 GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9840 #if defined(TARGET_PPC64)
9841 GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9842 GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9843 GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9844 GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9845 GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9847 GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9848 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9849 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9850 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9851 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
9852 GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
9853 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
9854 GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9855 GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
9856 GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
9857 GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
9858 GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
9859 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9860 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9861 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9862 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
9863 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9864 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
9865 #if defined(TARGET_PPC64)
9866 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9867 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9868 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9870 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9871 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9872 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9873 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9874 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9875 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9876 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9877 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
9878 GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9879 GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9880 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
9881 GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9882 GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9883 GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9884 #if defined(TARGET_PPC64)
9885 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
9886 GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
9887 GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
9888 GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
9890 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9891 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9892 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9893 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9894 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9895 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
9896 GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
9897 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9898 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9899 #if defined(TARGET_PPC64)
9900 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9901 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9903 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9904 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9905 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9906 #if defined(TARGET_PPC64)
9907 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9908 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9910 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9911 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9912 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9913 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9914 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9915 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9916 #if defined(TARGET_PPC64)
9917 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9919 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
9920 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC),
9921 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9922 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9923 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
9924 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
9925 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
9926 GEN_HANDLER_E(dcbtls, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE, PPC2_BOOKE206),
9927 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
9928 GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9929 GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9930 GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9931 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9932 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9933 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9934 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9935 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9936 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9937 #if defined(TARGET_PPC64)
9938 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9939 GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9941 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
9942 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9944 GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
9945 GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
9946 GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
9948 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
9949 GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
9950 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
9951 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
9952 #if defined(TARGET_PPC64)
9953 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
9954 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
9956 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
9957 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
9958 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
9959 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
9960 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
9961 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
9962 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
9963 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
9964 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
9965 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
9966 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
9967 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9968 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
9969 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
9970 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
9971 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
9972 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
9973 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
9974 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
9975 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9976 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
9977 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
9978 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
9979 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
9980 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
9981 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
9982 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
9983 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
9984 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
9985 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
9986 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
9987 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
9988 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
9989 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
9990 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
9991 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
9992 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
9993 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
9994 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
9995 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
9996 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
9997 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
9998 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
9999 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
10000 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
10001 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
10002 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
10003 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
10004 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
10005 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10006 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10007 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
10008 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
10009 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10010 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10011 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
10012 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
10013 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
10014 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
10015 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
10016 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
10017 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
10018 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
10019 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
10020 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
10021 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
10022 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
10023 GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
10024 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
10025 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
10026 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
10027 GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
10028 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
10029 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
10030 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
10031 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
10032 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
10033 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
10034 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
10035 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
10036 GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10037 PPC_NONE, PPC2_BOOKE206),
10038 GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10039 PPC_NONE, PPC2_BOOKE206),
10040 GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10041 PPC_NONE, PPC2_BOOKE206),
10042 GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10043 PPC_NONE, PPC2_BOOKE206),
10044 GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10045 PPC_NONE, PPC2_BOOKE206),
10046 GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10047 PPC_NONE, PPC2_PRCNTL),
10048 GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10049 PPC_NONE, PPC2_PRCNTL),
10050 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
10051 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
10052 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
10053 GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
10054 PPC_BOOKE, PPC2_BOOKE206),
10055 GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
10056 GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10057 PPC_BOOKE, PPC2_BOOKE206),
10058 GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
10059 GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
10060 GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
10061 GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
10062 GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
10063 GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
10064 GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
10065 GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
10066 GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
10068 #undef GEN_INT_ARITH_ADD
10069 #undef GEN_INT_ARITH_ADD_CONST
10070 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10071 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10072 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10073 add_ca, compute_ca, compute_ov) \
10074 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10075 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
10076 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
10077 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
10078 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
10079 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
10080 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
10081 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
10082 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
10083 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
10084 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
10086 #undef GEN_INT_ARITH_DIVW
10087 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10088 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10089 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
10090 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
10091 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
10092 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
10093 GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10094 GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10095 GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10096 GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10098 #if defined(TARGET_PPC64)
10099 #undef GEN_INT_ARITH_DIVD
10100 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10101 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10102 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
10103 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
10104 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
10105 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
10107 GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10108 GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10109 GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10110 GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10112 #undef GEN_INT_ARITH_MUL_HELPER
10113 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10114 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10115 GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
10116 GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
10117 GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
10120 #undef GEN_INT_ARITH_SUBF
10121 #undef GEN_INT_ARITH_SUBF_CONST
10122 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10123 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10124 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10125 add_ca, compute_ca, compute_ov) \
10126 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10127 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
10128 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
10129 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
10130 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
10131 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
10132 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
10133 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
10134 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
10135 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
10136 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
10138 #undef GEN_LOGICAL1
10139 #undef GEN_LOGICAL2
10140 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
10141 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10142 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
10143 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10144 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10145 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10146 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10147 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10148 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10149 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10150 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10151 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10152 #if defined(TARGET_PPC64)
10153 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10156 #if defined(TARGET_PPC64)
10157 #undef GEN_PPC64_R2
10158 #undef GEN_PPC64_R4
10159 #define GEN_PPC64_R2(name, opc1, opc2) \
10160 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10161 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10163 #define GEN_PPC64_R4(name, opc1, opc2) \
10164 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10165 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10167 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10169 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10171 GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10172 GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10173 GEN_PPC64_R4(rldic, 0x1E, 0x04),
10174 GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10175 GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10176 GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10179 #undef _GEN_FLOAT_ACB
10180 #undef GEN_FLOAT_ACB
10181 #undef _GEN_FLOAT_AB
10182 #undef GEN_FLOAT_AB
10183 #undef _GEN_FLOAT_AC
10184 #undef GEN_FLOAT_AC
10186 #undef GEN_FLOAT_BS
10187 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10188 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10189 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10190 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10191 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10192 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10193 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10194 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10195 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10196 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10197 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10198 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10199 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10200 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10201 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10202 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10203 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10204 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10205 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10207 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10208 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10209 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10210 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10211 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10212 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10213 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10214 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10215 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10216 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10217 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10218 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
10219 GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
10220 GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
10221 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
10222 GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10223 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
10224 GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10225 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
10226 GEN_HANDLER_E(fcfid, 0x3F, 0x0E, 0x1A, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
10227 GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10228 GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10229 GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10230 GEN_HANDLER_E(fctid, 0x3F, 0x0E, 0x19, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
10231 GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10232 GEN_HANDLER_E(fctidz, 0x3F, 0x0F, 0x19, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
10233 GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10234 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10235 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10236 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10237 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
10244 #define GEN_LD(name, ldop, opc, type) \
10245 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10246 #define GEN_LDU(name, ldop, opc, type) \
10247 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10248 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
10249 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10250 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10251 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10252 #define GEN_LDS(name, ldop, op, type) \
10253 GEN_LD(name, ldop, op | 0x20, type) \
10254 GEN_LDU(name, ldop, op | 0x21, type) \
10255 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10256 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10258 GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10259 GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10260 GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10261 GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10262 #if defined(TARGET_PPC64)
10263 GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10264 GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10265 GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10266 GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
10267 GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
10269 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10270 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10277 #define GEN_ST(name, stop, opc, type) \
10278 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10279 #define GEN_STU(name, stop, opc, type) \
10280 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10281 #define GEN_STUX(name, stop, opc2, opc3, type) \
10282 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10283 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10284 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10285 #define GEN_STS(name, stop, op, type) \
10286 GEN_ST(name, stop, op | 0x20, type) \
10287 GEN_STU(name, stop, op | 0x21, type) \
10288 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10289 GEN_STX(name, stop, 0x17, op | 0x00, type)
10291 GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10292 GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10293 GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10294 #if defined(TARGET_PPC64)
10295 GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10296 GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
10297 GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
10299 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10300 GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10307 #define GEN_LDF(name, ldop, opc, type) \
10308 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10309 #define GEN_LDUF(name, ldop, opc, type) \
10310 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10311 #define GEN_LDUXF(name, ldop, opc, type) \
10312 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10313 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
10314 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10315 #define GEN_LDFS(name, ldop, op, type) \
10316 GEN_LDF(name, ldop, op | 0x20, type) \
10317 GEN_LDUF(name, ldop, op | 0x21, type) \
10318 GEN_LDUXF(name, ldop, op | 0x01, type) \
10319 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10321 GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10322 GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
10323 GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
10324 GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
10325 GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10326 GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
10333 #define GEN_STF(name, stop, opc, type) \
10334 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10335 #define GEN_STUF(name, stop, opc, type) \
10336 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10337 #define GEN_STUXF(name, stop, opc, type) \
10338 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10339 #define GEN_STXF(name, stop, opc2, opc3, type) \
10340 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10341 #define GEN_STFS(name, stop, op, type) \
10342 GEN_STF(name, stop, op | 0x20, type) \
10343 GEN_STUF(name, stop, op | 0x21, type) \
10344 GEN_STUXF(name, stop, op | 0x01, type) \
10345 GEN_STXF(name, stop, 0x17, op | 0x00, type)
10347 GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10348 GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10349 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
10350 GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10351 GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
10354 #define GEN_CRLOGIC(name, tcg_op, opc) \
10355 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10356 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10357 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10358 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10359 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10360 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10361 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10362 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10363 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10365 #undef GEN_MAC_HANDLER
10366 #define GEN_MAC_HANDLER(name, opc2, opc3) \
10367 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10368 GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10369 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10370 GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10371 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10372 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10373 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10374 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10375 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10376 GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10377 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10378 GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10379 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10380 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10381 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10382 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10383 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10384 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10385 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10386 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10387 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10388 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10389 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10390 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10391 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10392 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10393 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10394 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10395 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10396 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10397 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10398 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10399 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10400 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10401 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10402 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10403 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10404 GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10405 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10406 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10407 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10408 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10409 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10415 #define GEN_VR_LDX(name, opc2, opc3) \
10416 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10417 #define GEN_VR_STX(name, opc2, opc3) \
10418 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10419 #define GEN_VR_LVE(name, opc2, opc3) \
10420 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10421 #define GEN_VR_STVE(name, opc2, opc3) \
10422 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10423 GEN_VR_LDX(lvx, 0x07, 0x03),
10424 GEN_VR_LDX(lvxl, 0x07, 0x0B),
10425 GEN_VR_LVE(bx, 0x07, 0x00),
10426 GEN_VR_LVE(hx, 0x07, 0x01),
10427 GEN_VR_LVE(wx, 0x07, 0x02),
10428 GEN_VR_STX(svx, 0x07, 0x07),
10429 GEN_VR_STX(svxl, 0x07, 0x0F),
10430 GEN_VR_STVE(bx, 0x07, 0x04),
10431 GEN_VR_STVE(hx, 0x07, 0x05),
10432 GEN_VR_STVE(wx, 0x07, 0x06),
10434 #undef GEN_VX_LOGICAL
10435 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10436 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10438 #undef GEN_VX_LOGICAL_207
10439 #define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10440 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10442 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10443 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10444 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10445 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10446 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
10447 GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10448 GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10449 GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
10452 #define GEN_VXFORM(name, opc2, opc3) \
10453 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10455 #undef GEN_VXFORM_207
10456 #define GEN_VXFORM_207(name, opc2, opc3) \
10457 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10459 #undef GEN_VXFORM_DUAL
10460 #define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10461 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10463 #undef GEN_VXRFORM_DUAL
10464 #define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10465 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10466 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10468 GEN_VXFORM(vaddubm, 0, 0),
10469 GEN_VXFORM(vadduhm, 0, 1),
10470 GEN_VXFORM(vadduwm, 0, 2),
10471 GEN_VXFORM_207(vaddudm, 0, 3),
10472 GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10473 GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
10474 GEN_VXFORM(vsubuwm, 0, 18),
10475 GEN_VXFORM_207(vsubudm, 0, 19),
10476 GEN_VXFORM(vmaxub, 1, 0),
10477 GEN_VXFORM(vmaxuh, 1, 1),
10478 GEN_VXFORM(vmaxuw, 1, 2),
10479 GEN_VXFORM_207(vmaxud, 1, 3),
10480 GEN_VXFORM(vmaxsb, 1, 4),
10481 GEN_VXFORM(vmaxsh, 1, 5),
10482 GEN_VXFORM(vmaxsw, 1, 6),
10483 GEN_VXFORM_207(vmaxsd, 1, 7),
10484 GEN_VXFORM(vminub, 1, 8),
10485 GEN_VXFORM(vminuh, 1, 9),
10486 GEN_VXFORM(vminuw, 1, 10),
10487 GEN_VXFORM_207(vminud, 1, 11),
10488 GEN_VXFORM(vminsb, 1, 12),
10489 GEN_VXFORM(vminsh, 1, 13),
10490 GEN_VXFORM(vminsw, 1, 14),
10491 GEN_VXFORM_207(vminsd, 1, 15),
10492 GEN_VXFORM(vavgub, 1, 16),
10493 GEN_VXFORM(vavguh, 1, 17),
10494 GEN_VXFORM(vavguw, 1, 18),
10495 GEN_VXFORM(vavgsb, 1, 20),
10496 GEN_VXFORM(vavgsh, 1, 21),
10497 GEN_VXFORM(vavgsw, 1, 22),
10498 GEN_VXFORM(vmrghb, 6, 0),
10499 GEN_VXFORM(vmrghh, 6, 1),
10500 GEN_VXFORM(vmrghw, 6, 2),
10501 GEN_VXFORM(vmrglb, 6, 4),
10502 GEN_VXFORM(vmrglh, 6, 5),
10503 GEN_VXFORM(vmrglw, 6, 6),
10504 GEN_VXFORM_207(vmrgew, 6, 30),
10505 GEN_VXFORM_207(vmrgow, 6, 26),
10506 GEN_VXFORM(vmuloub, 4, 0),
10507 GEN_VXFORM(vmulouh, 4, 1),
10508 GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
10509 GEN_VXFORM(vmulosb, 4, 4),
10510 GEN_VXFORM(vmulosh, 4, 5),
10511 GEN_VXFORM_207(vmulosw, 4, 6),
10512 GEN_VXFORM(vmuleub, 4, 8),
10513 GEN_VXFORM(vmuleuh, 4, 9),
10514 GEN_VXFORM_207(vmuleuw, 4, 10),
10515 GEN_VXFORM(vmulesb, 4, 12),
10516 GEN_VXFORM(vmulesh, 4, 13),
10517 GEN_VXFORM_207(vmulesw, 4, 14),
10518 GEN_VXFORM(vslb, 2, 4),
10519 GEN_VXFORM(vslh, 2, 5),
10520 GEN_VXFORM(vslw, 2, 6),
10521 GEN_VXFORM_207(vsld, 2, 23),
10522 GEN_VXFORM(vsrb, 2, 8),
10523 GEN_VXFORM(vsrh, 2, 9),
10524 GEN_VXFORM(vsrw, 2, 10),
10525 GEN_VXFORM_207(vsrd, 2, 27),
10526 GEN_VXFORM(vsrab, 2, 12),
10527 GEN_VXFORM(vsrah, 2, 13),
10528 GEN_VXFORM(vsraw, 2, 14),
10529 GEN_VXFORM_207(vsrad, 2, 15),
10530 GEN_VXFORM(vslo, 6, 16),
10531 GEN_VXFORM(vsro, 6, 17),
10532 GEN_VXFORM(vaddcuw, 0, 6),
10533 GEN_VXFORM(vsubcuw, 0, 22),
10534 GEN_VXFORM(vaddubs, 0, 8),
10535 GEN_VXFORM(vadduhs, 0, 9),
10536 GEN_VXFORM(vadduws, 0, 10),
10537 GEN_VXFORM(vaddsbs, 0, 12),
10538 GEN_VXFORM(vaddshs, 0, 13),
10539 GEN_VXFORM(vaddsws, 0, 14),
10540 GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10541 GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
10542 GEN_VXFORM(vsubuws, 0, 26),
10543 GEN_VXFORM(vsubsbs, 0, 28),
10544 GEN_VXFORM(vsubshs, 0, 29),
10545 GEN_VXFORM(vsubsws, 0, 30),
10546 GEN_VXFORM_207(vadduqm, 0, 4),
10547 GEN_VXFORM_207(vaddcuq, 0, 5),
10548 GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10549 GEN_VXFORM_207(vsubuqm, 0, 20),
10550 GEN_VXFORM_207(vsubcuq, 0, 21),
10551 GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10552 GEN_VXFORM(vrlb, 2, 0),
10553 GEN_VXFORM(vrlh, 2, 1),
10554 GEN_VXFORM(vrlw, 2, 2),
10555 GEN_VXFORM_207(vrld, 2, 3),
10556 GEN_VXFORM(vsl, 2, 7),
10557 GEN_VXFORM(vsr, 2, 11),
10558 GEN_VXFORM(vpkuhum, 7, 0),
10559 GEN_VXFORM(vpkuwum, 7, 1),
10560 GEN_VXFORM_207(vpkudum, 7, 17),
10561 GEN_VXFORM(vpkuhus, 7, 2),
10562 GEN_VXFORM(vpkuwus, 7, 3),
10563 GEN_VXFORM_207(vpkudus, 7, 19),
10564 GEN_VXFORM(vpkshus, 7, 4),
10565 GEN_VXFORM(vpkswus, 7, 5),
10566 GEN_VXFORM_207(vpksdus, 7, 21),
10567 GEN_VXFORM(vpkshss, 7, 6),
10568 GEN_VXFORM(vpkswss, 7, 7),
10569 GEN_VXFORM_207(vpksdss, 7, 23),
10570 GEN_VXFORM(vpkpx, 7, 12),
10571 GEN_VXFORM(vsum4ubs, 4, 24),
10572 GEN_VXFORM(vsum4sbs, 4, 28),
10573 GEN_VXFORM(vsum4shs, 4, 25),
10574 GEN_VXFORM(vsum2sws, 4, 26),
10575 GEN_VXFORM(vsumsws, 4, 30),
10576 GEN_VXFORM(vaddfp, 5, 0),
10577 GEN_VXFORM(vsubfp, 5, 1),
10578 GEN_VXFORM(vmaxfp, 5, 16),
10579 GEN_VXFORM(vminfp, 5, 17),
10581 #undef GEN_VXRFORM1
10583 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10584 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10585 #define GEN_VXRFORM(name, opc2, opc3) \
10586 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10587 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10588 GEN_VXRFORM(vcmpequb, 3, 0)
10589 GEN_VXRFORM(vcmpequh, 3, 1)
10590 GEN_VXRFORM(vcmpequw, 3, 2)
10591 GEN_VXRFORM(vcmpgtsb, 3, 12)
10592 GEN_VXRFORM(vcmpgtsh, 3, 13)
10593 GEN_VXRFORM(vcmpgtsw, 3, 14)
10594 GEN_VXRFORM(vcmpgtub, 3, 8)
10595 GEN_VXRFORM(vcmpgtuh, 3, 9)
10596 GEN_VXRFORM(vcmpgtuw, 3, 10)
10597 GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
10598 GEN_VXRFORM(vcmpgefp, 3, 7)
10599 GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10600 GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
10602 #undef GEN_VXFORM_SIMM
10603 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
10604 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10605 GEN_VXFORM_SIMM(vspltisb, 6, 12),
10606 GEN_VXFORM_SIMM(vspltish, 6, 13),
10607 GEN_VXFORM_SIMM(vspltisw, 6, 14),
10609 #undef GEN_VXFORM_NOA
10610 #define GEN_VXFORM_NOA(name, opc2, opc3) \
10611 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10612 GEN_VXFORM_NOA(vupkhsb, 7, 8),
10613 GEN_VXFORM_NOA(vupkhsh, 7, 9),
10614 GEN_VXFORM_207(vupkhsw, 7, 25),
10615 GEN_VXFORM_NOA(vupklsb, 7, 10),
10616 GEN_VXFORM_NOA(vupklsh, 7, 11),
10617 GEN_VXFORM_207(vupklsw, 7, 27),
10618 GEN_VXFORM_NOA(vupkhpx, 7, 13),
10619 GEN_VXFORM_NOA(vupklpx, 7, 15),
10620 GEN_VXFORM_NOA(vrefp, 5, 4),
10621 GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
10622 GEN_VXFORM_NOA(vexptefp, 5, 6),
10623 GEN_VXFORM_NOA(vlogefp, 5, 7),
10624 GEN_VXFORM_NOA(vrfim, 5, 11),
10625 GEN_VXFORM_NOA(vrfin, 5, 8),
10626 GEN_VXFORM_NOA(vrfip, 5, 10),
10627 GEN_VXFORM_NOA(vrfiz, 5, 9),
10629 #undef GEN_VXFORM_UIMM
10630 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
10631 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10632 GEN_VXFORM_UIMM(vspltb, 6, 8),
10633 GEN_VXFORM_UIMM(vsplth, 6, 9),
10634 GEN_VXFORM_UIMM(vspltw, 6, 10),
10635 GEN_VXFORM_UIMM(vcfux, 5, 12),
10636 GEN_VXFORM_UIMM(vcfsx, 5, 13),
10637 GEN_VXFORM_UIMM(vctuxs, 5, 14),
10638 GEN_VXFORM_UIMM(vctsxs, 5, 15),
10640 #undef GEN_VAFORM_PAIRED
10641 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10642 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10643 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10644 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10645 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10646 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10647 GEN_VAFORM_PAIRED(vsel, vperm, 21),
10648 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10650 GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10651 GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10652 GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10653 GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10655 GEN_VXFORM_207(vbpermq, 6, 21),
10656 GEN_VXFORM_207(vgbbd, 6, 20),
10657 GEN_VXFORM_207(vpmsumb, 4, 16),
10658 GEN_VXFORM_207(vpmsumh, 4, 17),
10659 GEN_VXFORM_207(vpmsumw, 4, 18),
10660 GEN_VXFORM_207(vpmsumd, 4, 19),
10662 GEN_VXFORM_207(vsbox, 4, 23),
10664 GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10665 GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10667 GEN_VXFORM_207(vshasigmaw, 1, 26),
10668 GEN_VXFORM_207(vshasigmad, 1, 27),
10670 GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10672 GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
10673 GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10674 GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10675 GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
10676 GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
10677 GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
10678 GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
10680 GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
10681 GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10682 GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
10683 GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
10684 GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
10686 GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10687 GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10688 GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10689 #if defined(TARGET_PPC64)
10690 GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10691 GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10695 #define GEN_XX2FORM(name, opc2, opc3, fl2) \
10696 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10697 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10700 #define GEN_XX3FORM(name, opc2, opc3, fl2) \
10701 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10702 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10703 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10704 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10706 #undef GEN_XX2IFORM
10707 #define GEN_XX2IFORM(name, opc2, opc3, fl2) \
10708 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 1, PPC_NONE, fl2), \
10709 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 1, PPC_NONE, fl2), \
10710 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 1, PPC_NONE, fl2), \
10711 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 1, PPC_NONE, fl2)
10713 #undef GEN_XX3_RC_FORM
10714 #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10715 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10716 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10717 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10718 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10719 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10720 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10721 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10722 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10724 #undef GEN_XX3FORM_DM
10725 #define GEN_XX3FORM_DM(name, opc2, opc3) \
10726 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10727 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10728 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10729 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10730 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10731 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10732 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10733 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10734 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10735 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10736 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10737 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10738 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10739 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10740 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10741 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10743 GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10744 GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10745 GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10746 GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10748 GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10749 GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10750 GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10751 GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10752 GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10753 GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10754 GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10755 GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
10757 GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10758 GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
10759 GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
10760 GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
10761 GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
10762 GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
10763 GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
10764 GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
10765 GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
10766 GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10767 GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10768 GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10769 GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10770 GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10771 GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10772 GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10773 GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
10774 GEN_XX2IFORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10775 GEN_XX2IFORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
10776 GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10777 GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
10778 GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
10779 GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
10780 GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
10781 GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
10782 GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10783 GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10784 GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10785 GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10786 GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10787 GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
10788 GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10789 GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10790 GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10791 GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10792 GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
10794 GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10795 GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
10796 GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
10797 GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
10798 GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
10799 GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
10800 GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
10801 GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
10802 GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
10803 GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
10804 GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
10805 GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
10806 GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
10807 GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
10808 GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
10809 GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
10810 GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
10811 GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
10813 GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10814 GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
10815 GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
10816 GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
10817 GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
10818 GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
10819 GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
10820 GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
10821 GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
10822 GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10823 GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10824 GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10825 GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10826 GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10827 GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10828 GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10829 GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
10830 GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10831 GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
10832 GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10833 GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10834 GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
10835 GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
10836 GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10837 GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10838 GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10839 GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10840 GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10841 GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10842 GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10843 GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
10844 GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10845 GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10846 GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10847 GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10848 GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
10850 GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10851 GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
10852 GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
10853 GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
10854 GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
10855 GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
10856 GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
10857 GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
10858 GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
10859 GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10860 GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10861 GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10862 GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10863 GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10864 GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10865 GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10866 GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
10867 GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10868 GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
10869 GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10870 GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10871 GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
10872 GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
10873 GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10874 GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10875 GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10876 GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10877 GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10878 GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10879 GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10880 GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
10881 GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10882 GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10883 GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10884 GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10885 GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
10888 #define VSX_LOGICAL(name, opc2, opc3, fl2) \
10889 GEN_XX3FORM(name, opc2, opc3, fl2)
10891 VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10892 VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10893 VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10894 VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10895 VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
10896 VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
10897 VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
10898 VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
10899 GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10900 GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
10901 GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
10902 GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
10904 #define GEN_XXSEL_ROW(opc3) \
10905 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10906 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10907 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10908 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10909 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10910 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10911 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10912 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10914 GEN_XXSEL_ROW(0x00)
10915 GEN_XXSEL_ROW(0x01)
10916 GEN_XXSEL_ROW(0x02)
10917 GEN_XXSEL_ROW(0x03)
10918 GEN_XXSEL_ROW(0x04)
10919 GEN_XXSEL_ROW(0x05)
10920 GEN_XXSEL_ROW(0x06)
10921 GEN_XXSEL_ROW(0x07)
10922 GEN_XXSEL_ROW(0x08)
10923 GEN_XXSEL_ROW(0x09)
10924 GEN_XXSEL_ROW(0x0A)
10925 GEN_XXSEL_ROW(0x0B)
10926 GEN_XXSEL_ROW(0x0C)
10927 GEN_XXSEL_ROW(0x0D)
10928 GEN_XXSEL_ROW(0x0E)
10929 GEN_XXSEL_ROW(0x0F)
10930 GEN_XXSEL_ROW(0x10)
10931 GEN_XXSEL_ROW(0x11)
10932 GEN_XXSEL_ROW(0x12)
10933 GEN_XXSEL_ROW(0x13)
10934 GEN_XXSEL_ROW(0x14)
10935 GEN_XXSEL_ROW(0x15)
10936 GEN_XXSEL_ROW(0x16)
10937 GEN_XXSEL_ROW(0x17)
10938 GEN_XXSEL_ROW(0x18)
10939 GEN_XXSEL_ROW(0x19)
10940 GEN_XXSEL_ROW(0x1A)
10941 GEN_XXSEL_ROW(0x1B)
10942 GEN_XXSEL_ROW(0x1C)
10943 GEN_XXSEL_ROW(0x1D)
10944 GEN_XXSEL_ROW(0x1E)
10945 GEN_XXSEL_ROW(0x1F)
10947 GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
10949 #undef GEN_DFP_T_A_B_Rc
10950 #undef GEN_DFP_BF_A_B
10951 #undef GEN_DFP_BF_A_DCM
10952 #undef GEN_DFP_T_B_U32_U32_Rc
10953 #undef GEN_DFP_T_A_B_I32_Rc
10954 #undef GEN_DFP_T_B_Rc
10955 #undef GEN_DFP_T_FPR_I32_Rc
10957 #define _GEN_DFP_LONG(name, op1, op2, mask) \
10958 GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
10960 #define _GEN_DFP_LONGx2(name, op1, op2, mask) \
10961 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10962 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10964 #define _GEN_DFP_LONGx4(name, op1, op2, mask) \
10965 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10966 GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10967 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10968 GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10970 #define _GEN_DFP_QUAD(name, op1, op2, mask) \
10971 GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
10973 #define _GEN_DFP_QUADx2(name, op1, op2, mask) \
10974 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10975 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10977 #define _GEN_DFP_QUADx4(name, op1, op2, mask) \
10978 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10979 GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10980 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10981 GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10983 #define GEN_DFP_T_A_B_Rc(name, op1, op2) \
10984 _GEN_DFP_LONG(name, op1, op2, 0x00000000)
10986 #define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
10987 _GEN_DFP_QUAD(name, op1, op2, 0x00210800)
10989 #define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
10990 _GEN_DFP_QUAD(name, op1, op2, 0x00200800)
10992 #define GEN_DFP_T_B_Rc(name, op1, op2) \
10993 _GEN_DFP_LONG(name, op1, op2, 0x001F0000)
10995 #define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
10996 _GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
10998 #define GEN_DFP_Tp_B_Rc(name, op1, op2) \
10999 _GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
11001 #define GEN_DFP_T_Bp_Rc(name, op1, op2) \
11002 _GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
11004 #define GEN_DFP_BF_A_B(name, op1, op2) \
11005 _GEN_DFP_LONG(name, op1, op2, 0x00000001)
11007 #define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
11008 _GEN_DFP_QUAD(name, op1, op2, 0x00610801)
11010 #define GEN_DFP_BF_A_Bp(name, op1, op2) \
11011 _GEN_DFP_QUAD(name, op1, op2, 0x00600801)
11013 #define GEN_DFP_BF_A_DCM(name, op1, op2) \
11014 _GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
11016 #define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
11017 _GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
11019 #define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
11020 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11022 #define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
11023 _GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
11025 #define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
11026 _GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
11028 #define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
11029 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11031 #define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
11032 _GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
11034 #define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
11035 _GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
11037 #define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
11038 _GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
11040 #define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
11041 _GEN_DFP_LONG(name, op1, op2, 0x00070000)
11043 #define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
11044 _GEN_DFP_QUAD(name, op1, op2, 0x00270800)
11046 #define GEN_DFP_S_T_B_Rc(name, op1, op2) \
11047 _GEN_DFP_LONG(name, op1, op2, 0x000F0000)
11049 #define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
11050 _GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
11052 #define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
11053 _GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
11055 #define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
11056 _GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
11058 GEN_DFP_T_A_B_Rc(dadd, 0x02, 0x00),
11059 GEN_DFP_Tp_Ap_Bp_Rc(daddq, 0x02, 0x00),
11060 GEN_DFP_T_A_B_Rc(dsub, 0x02, 0x10),
11061 GEN_DFP_Tp_Ap_Bp_Rc(dsubq, 0x02, 0x10),
11062 GEN_DFP_T_A_B_Rc(dmul, 0x02, 0x01),
11063 GEN_DFP_Tp_Ap_Bp_Rc(dmulq, 0x02, 0x01),
11064 GEN_DFP_T_A_B_Rc(ddiv, 0x02, 0x11),
11065 GEN_DFP_Tp_Ap_Bp_Rc(ddivq, 0x02, 0x11),
11066 GEN_DFP_BF_A_B(dcmpu, 0x02, 0x14),
11067 GEN_DFP_BF_Ap_Bp(dcmpuq, 0x02, 0x14),
11068 GEN_DFP_BF_A_B(dcmpo, 0x02, 0x04),
11069 GEN_DFP_BF_Ap_Bp(dcmpoq, 0x02, 0x04),
11070 GEN_DFP_BF_A_DCM(dtstdc, 0x02, 0x06),
11071 GEN_DFP_BF_Ap_DCM(dtstdcq, 0x02, 0x06),
11072 GEN_DFP_BF_A_DCM(dtstdg, 0x02, 0x07),
11073 GEN_DFP_BF_Ap_DCM(dtstdgq, 0x02, 0x07),
11074 GEN_DFP_BF_A_B(dtstex, 0x02, 0x05),
11075 GEN_DFP_BF_Ap_Bp(dtstexq, 0x02, 0x05),
11076 GEN_DFP_BF_A_B(dtstsf, 0x02, 0x15),
11077 GEN_DFP_BF_A_Bp(dtstsfq, 0x02, 0x15),
11078 GEN_DFP_TE_T_B_RMC_Rc(dquai, 0x03, 0x02),
11079 GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq, 0x03, 0x02),
11080 GEN_DFP_T_A_B_RMC_Rc(dqua, 0x03, 0x00),
11081 GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq, 0x03, 0x00),
11082 GEN_DFP_T_A_B_RMC_Rc(drrnd, 0x03, 0x01),
11083 GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq, 0x03, 0x01),
11084 GEN_DFP_R_T_B_RMC_Rc(drintx, 0x03, 0x03),
11085 GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq, 0x03, 0x03),
11086 GEN_DFP_R_T_B_RMC_Rc(drintn, 0x03, 0x07),
11087 GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq, 0x03, 0x07),
11088 GEN_DFP_T_B_Rc(dctdp, 0x02, 0x08),
11089 GEN_DFP_Tp_B_Rc(dctqpq, 0x02, 0x08),
11090 GEN_DFP_T_B_Rc(drsp, 0x02, 0x18),
11091 GEN_DFP_Tp_Bp_Rc(drdpq, 0x02, 0x18),
11092 GEN_DFP_T_B_Rc(dcffix, 0x02, 0x19),
11093 GEN_DFP_Tp_B_Rc(dcffixq, 0x02, 0x19),
11094 GEN_DFP_T_B_Rc(dctfix, 0x02, 0x09),
11095 GEN_DFP_T_Bp_Rc(dctfixq, 0x02, 0x09),
11096 GEN_DFP_SP_T_B_Rc(ddedpd, 0x02, 0x0a),
11097 GEN_DFP_SP_Tp_Bp_Rc(ddedpdq, 0x02, 0x0a),
11098 GEN_DFP_S_T_B_Rc(denbcd, 0x02, 0x1a),
11099 GEN_DFP_S_Tp_Bp_Rc(denbcdq, 0x02, 0x1a),
11100 GEN_DFP_T_B_Rc(dxex, 0x02, 0x0b),
11101 GEN_DFP_T_Bp_Rc(dxexq, 0x02, 0x0b),
11102 GEN_DFP_T_A_B_Rc(diex, 0x02, 0x1b),
11103 GEN_DFP_Tp_A_Bp_Rc(diexq, 0x02, 0x1b),
11104 GEN_DFP_T_A_SH_Rc(dscli, 0x02, 0x02),
11105 GEN_DFP_Tp_Ap_SH_Rc(dscliq, 0x02, 0x02),
11106 GEN_DFP_T_A_SH_Rc(dscri, 0x02, 0x03),
11107 GEN_DFP_Tp_Ap_SH_Rc(dscriq, 0x02, 0x03),
11110 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11111 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11112 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11113 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11114 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11115 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11116 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11117 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11118 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11119 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
11120 GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
11121 GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11122 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11123 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11124 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11125 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11126 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11127 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
11128 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11129 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11130 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11131 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11132 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11133 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11134 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11135 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11136 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11137 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11138 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11139 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11140 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
11142 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11143 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11144 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11145 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11146 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11147 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11148 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11149 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11150 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11151 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11152 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11153 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11154 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11155 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11157 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11158 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11159 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11160 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11161 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11162 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11163 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11164 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11165 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11166 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11167 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11168 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11169 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11170 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11172 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11173 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11174 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11175 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11176 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11177 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11178 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11179 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11180 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11181 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11182 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11183 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11184 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11185 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11186 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11187 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11189 #undef GEN_SPEOP_LDST
11190 #define GEN_SPEOP_LDST(name, opc2, sh) \
11191 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11192 GEN_SPEOP_LDST(evldd, 0x00, 3),
11193 GEN_SPEOP_LDST(evldw, 0x01, 3),
11194 GEN_SPEOP_LDST(evldh, 0x02, 3),
11195 GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11196 GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11197 GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11198 GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11199 GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11200 GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11201 GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11202 GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11204 GEN_SPEOP_LDST(evstdd, 0x10, 3),
11205 GEN_SPEOP_LDST(evstdw, 0x11, 3),
11206 GEN_SPEOP_LDST(evstdh, 0x12, 3),
11207 GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11208 GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11209 GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11210 GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
11212 GEN_HANDLER2_E(tbegin, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
11213 PPC_NONE, PPC2_TM),
11214 GEN_HANDLER2_E(tend, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
11215 PPC_NONE, PPC2_TM),
11216 GEN_HANDLER2_E(tabort, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
11217 PPC_NONE, PPC2_TM),
11218 GEN_HANDLER2_E(tabortwc, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
11219 PPC_NONE, PPC2_TM),
11220 GEN_HANDLER2_E(tabortwci, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
11221 PPC_NONE, PPC2_TM),
11222 GEN_HANDLER2_E(tabortdc, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
11223 PPC_NONE, PPC2_TM),
11224 GEN_HANDLER2_E(tabortdci, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
11225 PPC_NONE, PPC2_TM),
11226 GEN_HANDLER2_E(tsr, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
11227 PPC_NONE, PPC2_TM),
11228 GEN_HANDLER2_E(tcheck, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
11229 PPC_NONE, PPC2_TM),
11230 GEN_HANDLER2_E(treclaim, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
11231 PPC_NONE, PPC2_TM),
11232 GEN_HANDLER2_E(trechkpt, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
11233 PPC_NONE, PPC2_TM),
11236 #include "helper_regs.h"
11237 #include "translate_init.c"
11239 /*****************************************************************************/
11240 /* Misc PowerPC helpers */
11241 void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11247 PowerPCCPU *cpu = POWERPC_CPU(cs);
11248 CPUPPCState *env = &cpu->env;
11251 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
11252 TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
11253 env->nip, env->lr, env->ctr, cpu_read_xer(env),
11255 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
11256 TARGET_FMT_lx " iidx %d didx %d\n",
11257 env->msr, env->spr[SPR_HID0],
11258 env->hflags, env->immu_idx, env->dmmu_idx);
11259 #if !defined(NO_TIMER_DUMP)
11260 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
11261 #if !defined(CONFIG_USER_ONLY)
11265 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
11266 #if !defined(CONFIG_USER_ONLY)
11267 , cpu_ppc_load_decr(env)
11271 for (i = 0; i < 32; i++) {
11272 if ((i & (RGPL - 1)) == 0)
11273 cpu_fprintf(f, "GPR%02d", i);
11274 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
11275 if ((i & (RGPL - 1)) == (RGPL - 1))
11276 cpu_fprintf(f, "\n");
11278 cpu_fprintf(f, "CR ");
11279 for (i = 0; i < 8; i++)
11280 cpu_fprintf(f, "%01x", env->crf[i]);
11281 cpu_fprintf(f, " [");
11282 for (i = 0; i < 8; i++) {
11284 if (env->crf[i] & 0x08)
11286 else if (env->crf[i] & 0x04)
11288 else if (env->crf[i] & 0x02)
11290 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
11292 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11293 env->reserve_addr);
11294 for (i = 0; i < 32; i++) {
11295 if ((i & (RFPL - 1)) == 0)
11296 cpu_fprintf(f, "FPR%02d", i);
11297 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
11298 if ((i & (RFPL - 1)) == (RFPL - 1))
11299 cpu_fprintf(f, "\n");
11301 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
11302 #if !defined(CONFIG_USER_ONLY)
11303 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11304 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11305 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11306 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11308 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11309 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11310 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11311 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11313 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11314 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11315 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11316 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11318 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11319 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11320 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11321 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11322 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11324 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11325 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11326 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11327 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11329 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11330 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11331 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11332 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11334 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11335 " EPR " TARGET_FMT_lx "\n",
11336 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11337 env->spr[SPR_BOOKE_EPR]);
11340 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11341 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11342 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11343 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11346 * IVORs are left out as they are large and do not change often --
11347 * they can be read with "p $ivor0", "p $ivor1", etc.
11351 #if defined(TARGET_PPC64)
11352 if (env->flags & POWERPC_FLAG_CFAR) {
11353 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11357 switch (env->mmu_model) {
11358 case POWERPC_MMU_32B:
11359 case POWERPC_MMU_601:
11360 case POWERPC_MMU_SOFT_6xx:
11361 case POWERPC_MMU_SOFT_74xx:
11362 #if defined(TARGET_PPC64)
11363 case POWERPC_MMU_64B:
11364 case POWERPC_MMU_2_03:
11365 case POWERPC_MMU_2_06:
11366 case POWERPC_MMU_2_06a:
11367 case POWERPC_MMU_2_07:
11368 case POWERPC_MMU_2_07a:
11370 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11371 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11372 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
11374 case POWERPC_MMU_BOOKE206:
11375 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11376 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11377 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11378 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11380 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11381 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11382 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11383 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11385 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11386 " TLB1CFG " TARGET_FMT_lx "\n",
11387 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11388 env->spr[SPR_BOOKE_TLB1CFG]);
11399 void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11400 fprintf_function cpu_fprintf, int flags)
11402 #if defined(DO_PPC_STATISTICS)
11403 PowerPCCPU *cpu = POWERPC_CPU(cs);
11404 opc_handler_t **t1, **t2, **t3, *handler;
11407 t1 = cpu->env.opcodes;
11408 for (op1 = 0; op1 < 64; op1++) {
11410 if (is_indirect_opcode(handler)) {
11411 t2 = ind_table(handler);
11412 for (op2 = 0; op2 < 32; op2++) {
11414 if (is_indirect_opcode(handler)) {
11415 t3 = ind_table(handler);
11416 for (op3 = 0; op3 < 32; op3++) {
11418 if (handler->count == 0)
11420 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
11421 "%016" PRIx64 " %" PRId64 "\n",
11422 op1, op2, op3, op1, (op3 << 5) | op2,
11424 handler->count, handler->count);
11427 if (handler->count == 0)
11429 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
11430 "%016" PRIx64 " %" PRId64 "\n",
11431 op1, op2, op1, op2, handler->oname,
11432 handler->count, handler->count);
11436 if (handler->count == 0)
11438 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11440 op1, op1, handler->oname,
11441 handler->count, handler->count);
11447 /*****************************************************************************/
11448 void gen_intermediate_code(CPUPPCState *env, struct TranslationBlock *tb)
11450 PowerPCCPU *cpu = ppc_env_get_cpu(env);
11451 CPUState *cs = CPU(cpu);
11452 DisasContext ctx, *ctxp = &ctx;
11453 opc_handler_t **table, *handler;
11454 target_ulong pc_start;
11459 ctx.nip = pc_start;
11461 ctx.exception = POWERPC_EXCP_NONE;
11462 ctx.spr_cb = env->spr_cb;
11464 ctx.hv = !msr_pr && msr_hv;
11465 ctx.mem_idx = env->dmmu_idx;
11466 ctx.insns_flags = env->insns_flags;
11467 ctx.insns_flags2 = env->insns_flags2;
11468 ctx.access_type = -1;
11469 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
11470 ctx.default_tcg_memop_mask = ctx.le_mode ? MO_LE : MO_BE;
11471 #if defined(TARGET_PPC64)
11472 ctx.sf_mode = msr_is_64bit(env, env->msr);
11473 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
11475 ctx.fpu_enabled = msr_fp;
11476 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
11477 ctx.spe_enabled = msr_spe;
11479 ctx.spe_enabled = 0;
11480 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11481 ctx.altivec_enabled = msr_vr;
11483 ctx.altivec_enabled = 0;
11484 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11485 ctx.vsx_enabled = msr_vsx;
11487 ctx.vsx_enabled = 0;
11489 #if defined(TARGET_PPC64)
11490 if ((env->flags & POWERPC_FLAG_TM) && msr_tm) {
11491 ctx.tm_enabled = msr_tm;
11493 ctx.tm_enabled = 0;
11496 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
11497 ctx.singlestep_enabled = CPU_SINGLE_STEP;
11499 ctx.singlestep_enabled = 0;
11500 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
11501 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
11502 if (unlikely(cs->singlestep_enabled)) {
11503 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
11505 #if defined (DO_SINGLE_STEP) && 0
11506 /* Single step trace mode */
11510 max_insns = tb->cflags & CF_COUNT_MASK;
11511 if (max_insns == 0) {
11512 max_insns = CF_COUNT_MASK;
11514 if (max_insns > TCG_MAX_INSNS) {
11515 max_insns = TCG_MAX_INSNS;
11519 tcg_clear_temp_count();
11520 /* Set env in case of segfault during code fetch */
11521 while (ctx.exception == POWERPC_EXCP_NONE && !tcg_op_buf_full()) {
11522 tcg_gen_insn_start(ctx.nip);
11525 if (unlikely(cpu_breakpoint_test(cs, ctx.nip, BP_ANY))) {
11526 gen_debug_exception(ctxp);
11527 /* The address covered by the breakpoint must be included in
11528 [tb->pc, tb->pc + tb->size) in order to for it to be
11529 properly cleared -- thus we increment the PC here so that
11530 the logic setting tb->size below does the right thing. */
11535 LOG_DISAS("----------------\n");
11536 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
11537 ctx.nip, ctx.mem_idx, (int)msr_ir);
11538 if (num_insns == max_insns && (tb->cflags & CF_LAST_IO))
11540 if (unlikely(need_byteswap(&ctx))) {
11541 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
11543 ctx.opcode = cpu_ldl_code(env, ctx.nip);
11545 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
11546 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
11547 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
11549 table = env->opcodes;
11550 handler = table[opc1(ctx.opcode)];
11551 if (is_indirect_opcode(handler)) {
11552 table = ind_table(handler);
11553 handler = table[opc2(ctx.opcode)];
11554 if (is_indirect_opcode(handler)) {
11555 table = ind_table(handler);
11556 handler = table[opc3(ctx.opcode)];
11559 /* Is opcode *REALLY* valid ? */
11560 if (unlikely(handler->handler == &gen_invalid)) {
11561 qemu_log_mask(LOG_GUEST_ERROR, "invalid/unsupported opcode: "
11562 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11563 opc1(ctx.opcode), opc2(ctx.opcode),
11564 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
11568 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11569 inval = handler->inval2;
11571 inval = handler->inval1;
11574 if (unlikely((ctx.opcode & inval) != 0)) {
11575 qemu_log_mask(LOG_GUEST_ERROR, "invalid bits: %08x for opcode: "
11576 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
11577 ctx.opcode & inval, opc1(ctx.opcode),
11578 opc2(ctx.opcode), opc3(ctx.opcode),
11579 ctx.opcode, ctx.nip - 4);
11580 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
11584 (*(handler->handler))(&ctx);
11585 #if defined(DO_PPC_STATISTICS)
11588 /* Check trace mode exceptions */
11589 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11590 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11591 ctx.exception != POWERPC_SYSCALL &&
11592 ctx.exception != POWERPC_EXCP_TRAP &&
11593 ctx.exception != POWERPC_EXCP_BRANCH)) {
11594 gen_exception(ctxp, POWERPC_EXCP_TRACE);
11595 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
11596 (cs->singlestep_enabled) ||
11598 num_insns >= max_insns)) {
11599 /* if we reach a page boundary or are single stepping, stop
11604 if (tcg_check_temp_count()) {
11605 fprintf(stderr, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11606 opc1(ctx.opcode), opc2(ctx.opcode), opc3(ctx.opcode),
11611 if (tb->cflags & CF_LAST_IO)
11613 if (ctx.exception == POWERPC_EXCP_NONE) {
11614 gen_goto_tb(&ctx, 0, ctx.nip);
11615 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
11616 if (unlikely(cs->singlestep_enabled)) {
11617 gen_debug_exception(ctxp);
11619 /* Generate the return instruction */
11620 tcg_gen_exit_tb(0);
11622 gen_tb_end(tb, num_insns);
11624 tb->size = ctx.nip - pc_start;
11625 tb->icount = num_insns;
11627 #if defined(DEBUG_DISAS)
11628 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
11630 flags = env->bfd_mach;
11631 flags |= ctx.le_mode << 16;
11632 qemu_log("IN: %s\n", lookup_symbol(pc_start));
11633 log_target_disas(cs, pc_start, ctx.nip - pc_start, flags);
11639 void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb,
11640 target_ulong *data)
11642 env->nip = data[0];