2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "disas/disas.h"
24 #include "qemu/host-utils.h"
30 #define CPU_SINGLE_STEP 0x1
31 #define CPU_BRANCH_STEP 0x2
32 #define GDBSTUB_SINGLE_STEP 0x4
34 /* Include definitions for instructions classes and implementations flags */
35 //#define PPC_DEBUG_DISAS
36 //#define DO_PPC_STATISTICS
38 #ifdef PPC_DEBUG_DISAS
39 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
41 # define LOG_DISAS(...) do { } while (0)
43 /*****************************************************************************/
44 /* Code translation helpers */
46 /* global register indexes */
47 static TCGv_ptr cpu_env;
48 static char cpu_reg_names[10*3 + 22*4 /* GPR */
49 #if !defined(TARGET_PPC64)
50 + 10*4 + 22*5 /* SPE GPRh */
52 + 10*4 + 22*5 /* FPR */
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
55 static TCGv cpu_gpr[32];
56 #if !defined(TARGET_PPC64)
57 static TCGv cpu_gprh[32];
59 static TCGv_i64 cpu_fpr[32];
60 static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
61 static TCGv_i32 cpu_crf[8];
66 #if defined(TARGET_PPC64)
69 static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
70 static TCGv cpu_reserve;
71 static TCGv cpu_fpscr;
72 static TCGv_i32 cpu_access_type;
74 #include "exec/gen-icount.h"
76 void ppc_translate_init(void)
80 size_t cpu_reg_names_size;
81 static int done_init = 0;
86 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
89 cpu_reg_names_size = sizeof(cpu_reg_names);
91 for (i = 0; i < 8; i++) {
92 snprintf(p, cpu_reg_names_size, "crf%d", i);
93 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
94 offsetof(CPUPPCState, crf[i]), p);
96 cpu_reg_names_size -= 5;
99 for (i = 0; i < 32; i++) {
100 snprintf(p, cpu_reg_names_size, "r%d", i);
101 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
102 offsetof(CPUPPCState, gpr[i]), p);
103 p += (i < 10) ? 3 : 4;
104 cpu_reg_names_size -= (i < 10) ? 3 : 4;
105 #if !defined(TARGET_PPC64)
106 snprintf(p, cpu_reg_names_size, "r%dH", i);
107 cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
108 offsetof(CPUPPCState, gprh[i]), p);
109 p += (i < 10) ? 4 : 5;
110 cpu_reg_names_size -= (i < 10) ? 4 : 5;
113 snprintf(p, cpu_reg_names_size, "fp%d", i);
114 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
115 offsetof(CPUPPCState, fpr[i]), p);
116 p += (i < 10) ? 4 : 5;
117 cpu_reg_names_size -= (i < 10) ? 4 : 5;
119 snprintf(p, cpu_reg_names_size, "avr%dH", i);
120 #ifdef HOST_WORDS_BIGENDIAN
121 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
122 offsetof(CPUPPCState, avr[i].u64[0]), p);
124 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
125 offsetof(CPUPPCState, avr[i].u64[1]), p);
127 p += (i < 10) ? 6 : 7;
128 cpu_reg_names_size -= (i < 10) ? 6 : 7;
130 snprintf(p, cpu_reg_names_size, "avr%dL", i);
131 #ifdef HOST_WORDS_BIGENDIAN
132 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
133 offsetof(CPUPPCState, avr[i].u64[1]), p);
135 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
136 offsetof(CPUPPCState, avr[i].u64[0]), p);
138 p += (i < 10) ? 6 : 7;
139 cpu_reg_names_size -= (i < 10) ? 6 : 7;
142 cpu_nip = tcg_global_mem_new(TCG_AREG0,
143 offsetof(CPUPPCState, nip), "nip");
145 cpu_msr = tcg_global_mem_new(TCG_AREG0,
146 offsetof(CPUPPCState, msr), "msr");
148 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
149 offsetof(CPUPPCState, ctr), "ctr");
151 cpu_lr = tcg_global_mem_new(TCG_AREG0,
152 offsetof(CPUPPCState, lr), "lr");
154 #if defined(TARGET_PPC64)
155 cpu_cfar = tcg_global_mem_new(TCG_AREG0,
156 offsetof(CPUPPCState, cfar), "cfar");
159 cpu_xer = tcg_global_mem_new(TCG_AREG0,
160 offsetof(CPUPPCState, xer), "xer");
161 cpu_so = tcg_global_mem_new(TCG_AREG0,
162 offsetof(CPUPPCState, so), "SO");
163 cpu_ov = tcg_global_mem_new(TCG_AREG0,
164 offsetof(CPUPPCState, ov), "OV");
165 cpu_ca = tcg_global_mem_new(TCG_AREG0,
166 offsetof(CPUPPCState, ca), "CA");
168 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
169 offsetof(CPUPPCState, reserve_addr),
172 cpu_fpscr = tcg_global_mem_new(TCG_AREG0,
173 offsetof(CPUPPCState, fpscr), "fpscr");
175 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
176 offsetof(CPUPPCState, access_type), "access_type");
181 /* internal defines */
182 typedef struct DisasContext {
183 struct TranslationBlock *tb;
187 /* Routine used to access memory */
190 /* Translation flags */
192 #if defined(TARGET_PPC64)
200 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
201 int singlestep_enabled;
202 uint64_t insns_flags;
203 uint64_t insns_flags2;
206 /* True when active word size < size of target_long. */
208 # define NARROW_MODE(C) (!(C)->sf_mode)
210 # define NARROW_MODE(C) 0
213 struct opc_handler_t {
214 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
216 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
218 /* instruction type */
220 /* extended instruction type */
223 void (*handler)(DisasContext *ctx);
224 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
227 #if defined(DO_PPC_STATISTICS)
232 static inline void gen_reset_fpstatus(void)
234 gen_helper_reset_fpstatus(cpu_env);
237 static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
239 TCGv_i32 t0 = tcg_temp_new_i32();
242 /* This case might be optimized later */
243 tcg_gen_movi_i32(t0, 1);
244 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
245 if (unlikely(set_rc)) {
246 tcg_gen_mov_i32(cpu_crf[1], t0);
248 gen_helper_float_check_status(cpu_env);
249 } else if (unlikely(set_rc)) {
250 /* We always need to compute fpcc */
251 tcg_gen_movi_i32(t0, 0);
252 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
253 tcg_gen_mov_i32(cpu_crf[1], t0);
256 tcg_temp_free_i32(t0);
259 static inline void gen_set_access_type(DisasContext *ctx, int access_type)
261 if (ctx->access_type != access_type) {
262 tcg_gen_movi_i32(cpu_access_type, access_type);
263 ctx->access_type = access_type;
267 static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
269 if (NARROW_MODE(ctx)) {
272 tcg_gen_movi_tl(cpu_nip, nip);
275 static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
278 if (ctx->exception == POWERPC_EXCP_NONE) {
279 gen_update_nip(ctx, ctx->nip);
281 t0 = tcg_const_i32(excp);
282 t1 = tcg_const_i32(error);
283 gen_helper_raise_exception_err(cpu_env, t0, t1);
284 tcg_temp_free_i32(t0);
285 tcg_temp_free_i32(t1);
286 ctx->exception = (excp);
289 static inline void gen_exception(DisasContext *ctx, uint32_t excp)
292 if (ctx->exception == POWERPC_EXCP_NONE) {
293 gen_update_nip(ctx, ctx->nip);
295 t0 = tcg_const_i32(excp);
296 gen_helper_raise_exception(cpu_env, t0);
297 tcg_temp_free_i32(t0);
298 ctx->exception = (excp);
301 static inline void gen_debug_exception(DisasContext *ctx)
305 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
306 (ctx->exception != POWERPC_EXCP_SYNC)) {
307 gen_update_nip(ctx, ctx->nip);
309 t0 = tcg_const_i32(EXCP_DEBUG);
310 gen_helper_raise_exception(cpu_env, t0);
311 tcg_temp_free_i32(t0);
314 static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
316 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
319 /* Stop translation */
320 static inline void gen_stop_exception(DisasContext *ctx)
322 gen_update_nip(ctx, ctx->nip);
323 ctx->exception = POWERPC_EXCP_STOP;
326 /* No need to update nip here, as execution flow will change */
327 static inline void gen_sync_exception(DisasContext *ctx)
329 ctx->exception = POWERPC_EXCP_SYNC;
332 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
333 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
335 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
336 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
338 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
339 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
341 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
342 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
344 typedef struct opcode_t {
345 unsigned char opc1, opc2, opc3;
346 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
347 unsigned char pad[5];
349 unsigned char pad[1];
351 opc_handler_t handler;
355 /*****************************************************************************/
356 /*** Instruction decoding ***/
357 #define EXTRACT_HELPER(name, shift, nb) \
358 static inline uint32_t name(uint32_t opcode) \
360 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
363 #define EXTRACT_SHELPER(name, shift, nb) \
364 static inline int32_t name(uint32_t opcode) \
366 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
369 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
370 static inline uint32_t name(uint32_t opcode) \
372 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
373 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
376 EXTRACT_HELPER(opc1, 26, 6);
378 EXTRACT_HELPER(opc2, 1, 5);
380 EXTRACT_HELPER(opc3, 6, 5);
381 /* Update Cr0 flags */
382 EXTRACT_HELPER(Rc, 0, 1);
384 EXTRACT_HELPER(rD, 21, 5);
386 EXTRACT_HELPER(rS, 21, 5);
388 EXTRACT_HELPER(rA, 16, 5);
390 EXTRACT_HELPER(rB, 11, 5);
392 EXTRACT_HELPER(rC, 6, 5);
394 EXTRACT_HELPER(crfD, 23, 3);
395 EXTRACT_HELPER(crfS, 18, 3);
396 EXTRACT_HELPER(crbD, 21, 5);
397 EXTRACT_HELPER(crbA, 16, 5);
398 EXTRACT_HELPER(crbB, 11, 5);
400 EXTRACT_HELPER(_SPR, 11, 10);
401 static inline uint32_t SPR(uint32_t opcode)
403 uint32_t sprn = _SPR(opcode);
405 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
407 /*** Get constants ***/
408 EXTRACT_HELPER(IMM, 12, 8);
409 /* 16 bits signed immediate value */
410 EXTRACT_SHELPER(SIMM, 0, 16);
411 /* 16 bits unsigned immediate value */
412 EXTRACT_HELPER(UIMM, 0, 16);
413 /* 5 bits signed immediate value */
414 EXTRACT_HELPER(SIMM5, 16, 5);
415 /* 5 bits signed immediate value */
416 EXTRACT_HELPER(UIMM5, 16, 5);
418 EXTRACT_HELPER(NB, 11, 5);
420 EXTRACT_HELPER(SH, 11, 5);
421 /* Vector shift count */
422 EXTRACT_HELPER(VSH, 6, 4);
424 EXTRACT_HELPER(MB, 6, 5);
426 EXTRACT_HELPER(ME, 1, 5);
428 EXTRACT_HELPER(TO, 21, 5);
430 EXTRACT_HELPER(CRM, 12, 8);
431 EXTRACT_HELPER(SR, 16, 4);
434 EXTRACT_HELPER(FPBF, 23, 3);
435 EXTRACT_HELPER(FPIMM, 12, 4);
436 EXTRACT_HELPER(FPL, 25, 1);
437 EXTRACT_HELPER(FPFLM, 17, 8);
438 EXTRACT_HELPER(FPW, 16, 1);
440 /*** Jump target decoding ***/
442 EXTRACT_SHELPER(d, 0, 16);
443 /* Immediate address */
444 static inline target_ulong LI(uint32_t opcode)
446 return (opcode >> 0) & 0x03FFFFFC;
449 static inline uint32_t BD(uint32_t opcode)
451 return (opcode >> 0) & 0xFFFC;
454 EXTRACT_HELPER(BO, 21, 5);
455 EXTRACT_HELPER(BI, 16, 5);
456 /* Absolute/relative address */
457 EXTRACT_HELPER(AA, 1, 1);
459 EXTRACT_HELPER(LK, 0, 1);
461 /* Create a mask between <start> and <end> bits */
462 static inline target_ulong MASK(uint32_t start, uint32_t end)
466 #if defined(TARGET_PPC64)
467 if (likely(start == 0)) {
468 ret = UINT64_MAX << (63 - end);
469 } else if (likely(end == 63)) {
470 ret = UINT64_MAX >> start;
473 if (likely(start == 0)) {
474 ret = UINT32_MAX << (31 - end);
475 } else if (likely(end == 31)) {
476 ret = UINT32_MAX >> start;
480 ret = (((target_ulong)(-1ULL)) >> (start)) ^
481 (((target_ulong)(-1ULL) >> (end)) >> 1);
482 if (unlikely(start > end))
489 EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
490 EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
491 EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
492 EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
493 EXTRACT_HELPER(DM, 8, 2);
494 /*****************************************************************************/
495 /* PowerPC instructions table */
497 #if defined(DO_PPC_STATISTICS)
498 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
508 .handler = &gen_##name, \
509 .oname = stringify(name), \
511 .oname = stringify(name), \
513 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
524 .handler = &gen_##name, \
525 .oname = stringify(name), \
527 .oname = stringify(name), \
529 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
539 .handler = &gen_##name, \
545 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
555 .handler = &gen_##name, \
557 .oname = stringify(name), \
559 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
570 .handler = &gen_##name, \
572 .oname = stringify(name), \
574 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
584 .handler = &gen_##name, \
590 /* SPR load/store helpers */
591 static inline void gen_load_spr(TCGv t, int reg)
593 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
596 static inline void gen_store_spr(int reg, TCGv t)
598 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
601 /* Invalid instruction */
602 static void gen_invalid(DisasContext *ctx)
604 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
607 static opc_handler_t invalid_handler = {
608 .inval1 = 0xFFFFFFFF,
609 .inval2 = 0xFFFFFFFF,
612 .handler = gen_invalid,
615 /*** Integer comparison ***/
617 static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
619 TCGv t0 = tcg_temp_new();
620 TCGv_i32 t1 = tcg_temp_new_i32();
622 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
624 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
625 tcg_gen_trunc_tl_i32(t1, t0);
626 tcg_gen_shli_i32(t1, t1, CRF_LT);
627 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
629 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
630 tcg_gen_trunc_tl_i32(t1, t0);
631 tcg_gen_shli_i32(t1, t1, CRF_GT);
632 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
634 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
635 tcg_gen_trunc_tl_i32(t1, t0);
636 tcg_gen_shli_i32(t1, t1, CRF_EQ);
637 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
640 tcg_temp_free_i32(t1);
643 static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
645 TCGv t0 = tcg_const_tl(arg1);
646 gen_op_cmp(arg0, t0, s, crf);
650 static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
656 tcg_gen_ext32s_tl(t0, arg0);
657 tcg_gen_ext32s_tl(t1, arg1);
659 tcg_gen_ext32u_tl(t0, arg0);
660 tcg_gen_ext32u_tl(t1, arg1);
662 gen_op_cmp(t0, t1, s, crf);
667 static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
669 TCGv t0 = tcg_const_tl(arg1);
670 gen_op_cmp32(arg0, t0, s, crf);
674 static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
676 if (NARROW_MODE(ctx)) {
677 gen_op_cmpi32(reg, 0, 1, 0);
679 gen_op_cmpi(reg, 0, 1, 0);
684 static void gen_cmp(DisasContext *ctx)
686 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
687 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
688 1, crfD(ctx->opcode));
690 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
691 1, crfD(ctx->opcode));
696 static void gen_cmpi(DisasContext *ctx)
698 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
699 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
700 1, crfD(ctx->opcode));
702 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
703 1, crfD(ctx->opcode));
708 static void gen_cmpl(DisasContext *ctx)
710 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
711 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
712 0, crfD(ctx->opcode));
714 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
715 0, crfD(ctx->opcode));
720 static void gen_cmpli(DisasContext *ctx)
722 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
723 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
724 0, crfD(ctx->opcode));
726 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
727 0, crfD(ctx->opcode));
731 /* isel (PowerPC 2.03 specification) */
732 static void gen_isel(DisasContext *ctx)
735 uint32_t bi = rC(ctx->opcode);
739 l1 = gen_new_label();
740 l2 = gen_new_label();
742 mask = 1 << (3 - (bi & 0x03));
743 t0 = tcg_temp_new_i32();
744 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
745 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
746 if (rA(ctx->opcode) == 0)
747 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
749 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
752 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
754 tcg_temp_free_i32(t0);
757 /* cmpb: PowerPC 2.05 specification */
758 static void gen_cmpb(DisasContext *ctx)
760 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
761 cpu_gpr[rB(ctx->opcode)]);
764 /*** Integer arithmetic ***/
766 static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
767 TCGv arg1, TCGv arg2, int sub)
769 TCGv t0 = tcg_temp_new();
771 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
772 tcg_gen_xor_tl(t0, arg1, arg2);
774 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
776 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
779 if (NARROW_MODE(ctx)) {
780 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
782 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
783 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
786 /* Common add function */
787 static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
788 TCGv arg2, bool add_ca, bool compute_ca,
789 bool compute_ov, bool compute_rc0)
793 if (compute_ca || compute_ov) {
798 if (NARROW_MODE(ctx)) {
799 /* Caution: a non-obvious corner case of the spec is that we
800 must produce the *entire* 64-bit addition, but produce the
801 carry into bit 32. */
802 TCGv t1 = tcg_temp_new();
803 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
804 tcg_gen_add_tl(t0, arg1, arg2);
806 tcg_gen_add_tl(t0, t0, cpu_ca);
808 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
810 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
811 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
813 TCGv zero = tcg_const_tl(0);
815 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
816 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
818 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
823 tcg_gen_add_tl(t0, arg1, arg2);
825 tcg_gen_add_tl(t0, t0, cpu_ca);
830 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
832 if (unlikely(compute_rc0)) {
833 gen_set_Rc0(ctx, t0);
836 if (!TCGV_EQUAL(t0, ret)) {
837 tcg_gen_mov_tl(ret, t0);
841 /* Add functions with two operands */
842 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
843 static void glue(gen_, name)(DisasContext *ctx) \
845 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
846 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
847 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
849 /* Add functions with one operand and one immediate */
850 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
851 add_ca, compute_ca, compute_ov) \
852 static void glue(gen_, name)(DisasContext *ctx) \
854 TCGv t0 = tcg_const_tl(const_val); \
855 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
856 cpu_gpr[rA(ctx->opcode)], t0, \
857 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
861 /* add add. addo addo. */
862 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
863 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
864 /* addc addc. addco addco. */
865 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
866 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
867 /* adde adde. addeo addeo. */
868 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
869 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
870 /* addme addme. addmeo addmeo. */
871 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
872 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
873 /* addze addze. addzeo addzeo.*/
874 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
875 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
877 static void gen_addi(DisasContext *ctx)
879 target_long simm = SIMM(ctx->opcode);
881 if (rA(ctx->opcode) == 0) {
883 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
885 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
886 cpu_gpr[rA(ctx->opcode)], simm);
890 static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
892 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
893 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
894 c, 0, 1, 0, compute_rc0);
898 static void gen_addic(DisasContext *ctx)
900 gen_op_addic(ctx, 0);
903 static void gen_addic_(DisasContext *ctx)
905 gen_op_addic(ctx, 1);
909 static void gen_addis(DisasContext *ctx)
911 target_long simm = SIMM(ctx->opcode);
913 if (rA(ctx->opcode) == 0) {
915 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
917 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
918 cpu_gpr[rA(ctx->opcode)], simm << 16);
922 static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
923 TCGv arg2, int sign, int compute_ov)
925 int l1 = gen_new_label();
926 int l2 = gen_new_label();
927 TCGv_i32 t0 = tcg_temp_local_new_i32();
928 TCGv_i32 t1 = tcg_temp_local_new_i32();
930 tcg_gen_trunc_tl_i32(t0, arg1);
931 tcg_gen_trunc_tl_i32(t1, arg2);
932 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
934 int l3 = gen_new_label();
935 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
936 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
938 tcg_gen_div_i32(t0, t0, t1);
940 tcg_gen_divu_i32(t0, t0, t1);
943 tcg_gen_movi_tl(cpu_ov, 0);
948 tcg_gen_sari_i32(t0, t0, 31);
950 tcg_gen_movi_i32(t0, 0);
953 tcg_gen_movi_tl(cpu_ov, 1);
954 tcg_gen_movi_tl(cpu_so, 1);
957 tcg_gen_extu_i32_tl(ret, t0);
958 tcg_temp_free_i32(t0);
959 tcg_temp_free_i32(t1);
960 if (unlikely(Rc(ctx->opcode) != 0))
961 gen_set_Rc0(ctx, ret);
964 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
965 static void glue(gen_, name)(DisasContext *ctx) \
967 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
968 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
971 /* divwu divwu. divwuo divwuo. */
972 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
973 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
974 /* divw divw. divwo divwo. */
975 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
976 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
977 #if defined(TARGET_PPC64)
978 static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
979 TCGv arg2, int sign, int compute_ov)
981 int l1 = gen_new_label();
982 int l2 = gen_new_label();
984 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
986 int l3 = gen_new_label();
987 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
988 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
990 tcg_gen_div_i64(ret, arg1, arg2);
992 tcg_gen_divu_i64(ret, arg1, arg2);
995 tcg_gen_movi_tl(cpu_ov, 0);
1000 tcg_gen_sari_i64(ret, arg1, 63);
1002 tcg_gen_movi_i64(ret, 0);
1005 tcg_gen_movi_tl(cpu_ov, 1);
1006 tcg_gen_movi_tl(cpu_so, 1);
1009 if (unlikely(Rc(ctx->opcode) != 0))
1010 gen_set_Rc0(ctx, ret);
1012 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1013 static void glue(gen_, name)(DisasContext *ctx) \
1015 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1016 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1017 sign, compute_ov); \
1019 /* divwu divwu. divwuo divwuo. */
1020 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1021 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1022 /* divw divw. divwo divwo. */
1023 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1024 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1028 static void gen_mulhw(DisasContext *ctx)
1030 TCGv_i32 t0 = tcg_temp_new_i32();
1031 TCGv_i32 t1 = tcg_temp_new_i32();
1033 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1034 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1035 tcg_gen_muls2_i32(t0, t1, t0, t1);
1036 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1037 tcg_temp_free_i32(t0);
1038 tcg_temp_free_i32(t1);
1039 if (unlikely(Rc(ctx->opcode) != 0))
1040 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1043 /* mulhwu mulhwu. */
1044 static void gen_mulhwu(DisasContext *ctx)
1046 TCGv_i32 t0 = tcg_temp_new_i32();
1047 TCGv_i32 t1 = tcg_temp_new_i32();
1049 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1050 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1051 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1052 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1053 tcg_temp_free_i32(t0);
1054 tcg_temp_free_i32(t1);
1055 if (unlikely(Rc(ctx->opcode) != 0))
1056 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1060 static void gen_mullw(DisasContext *ctx)
1062 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1063 cpu_gpr[rB(ctx->opcode)]);
1064 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
1065 if (unlikely(Rc(ctx->opcode) != 0))
1066 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1069 /* mullwo mullwo. */
1070 static void gen_mullwo(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_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1080 tcg_gen_sari_i32(t0, t0, 31);
1081 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1082 tcg_gen_extu_i32_tl(cpu_ov, t0);
1083 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1085 tcg_temp_free_i32(t0);
1086 tcg_temp_free_i32(t1);
1087 if (unlikely(Rc(ctx->opcode) != 0))
1088 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1092 static void gen_mulli(DisasContext *ctx)
1094 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1098 #if defined(TARGET_PPC64)
1100 static void gen_mulhd(DisasContext *ctx)
1102 TCGv lo = tcg_temp_new();
1103 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1104 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1106 if (unlikely(Rc(ctx->opcode) != 0)) {
1107 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1111 /* mulhdu mulhdu. */
1112 static void gen_mulhdu(DisasContext *ctx)
1114 TCGv lo = tcg_temp_new();
1115 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1116 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1118 if (unlikely(Rc(ctx->opcode) != 0)) {
1119 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1124 static void gen_mulld(DisasContext *ctx)
1126 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1127 cpu_gpr[rB(ctx->opcode)]);
1128 if (unlikely(Rc(ctx->opcode) != 0))
1129 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1132 /* mulldo mulldo. */
1133 static void gen_mulldo(DisasContext *ctx)
1135 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1136 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1137 if (unlikely(Rc(ctx->opcode) != 0)) {
1138 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1143 /* Common subf function */
1144 static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
1145 TCGv arg2, bool add_ca, bool compute_ca,
1146 bool compute_ov, bool compute_rc0)
1150 if (compute_ca || compute_ov) {
1151 t0 = tcg_temp_new();
1155 /* dest = ~arg1 + arg2 [+ ca]. */
1156 if (NARROW_MODE(ctx)) {
1157 /* Caution: a non-obvious corner case of the spec is that we
1158 must produce the *entire* 64-bit addition, but produce the
1159 carry into bit 32. */
1160 TCGv inv1 = tcg_temp_new();
1161 TCGv t1 = tcg_temp_new();
1162 tcg_gen_not_tl(inv1, arg1);
1164 tcg_gen_add_tl(t0, arg2, cpu_ca);
1166 tcg_gen_addi_tl(t0, arg2, 1);
1168 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
1169 tcg_gen_add_tl(t0, t0, inv1);
1170 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1172 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1173 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
1174 } else if (add_ca) {
1175 TCGv zero, inv1 = tcg_temp_new();
1176 tcg_gen_not_tl(inv1, arg1);
1177 zero = tcg_const_tl(0);
1178 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
1179 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
1180 tcg_temp_free(zero);
1181 tcg_temp_free(inv1);
1183 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
1184 tcg_gen_sub_tl(t0, arg2, arg1);
1186 } else if (add_ca) {
1187 /* Since we're ignoring carry-out, we can simplify the
1188 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1189 tcg_gen_sub_tl(t0, arg2, arg1);
1190 tcg_gen_add_tl(t0, t0, cpu_ca);
1191 tcg_gen_subi_tl(t0, t0, 1);
1193 tcg_gen_sub_tl(t0, arg2, arg1);
1197 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1199 if (unlikely(compute_rc0)) {
1200 gen_set_Rc0(ctx, t0);
1203 if (!TCGV_EQUAL(t0, ret)) {
1204 tcg_gen_mov_tl(ret, t0);
1208 /* Sub functions with Two operands functions */
1209 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1210 static void glue(gen_, name)(DisasContext *ctx) \
1212 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1213 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1214 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1216 /* Sub functions with one operand and one immediate */
1217 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1218 add_ca, compute_ca, compute_ov) \
1219 static void glue(gen_, name)(DisasContext *ctx) \
1221 TCGv t0 = tcg_const_tl(const_val); \
1222 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1223 cpu_gpr[rA(ctx->opcode)], t0, \
1224 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1225 tcg_temp_free(t0); \
1227 /* subf subf. subfo subfo. */
1228 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1229 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1230 /* subfc subfc. subfco subfco. */
1231 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1232 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1233 /* subfe subfe. subfeo subfo. */
1234 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1235 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1236 /* subfme subfme. subfmeo subfmeo. */
1237 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1238 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1239 /* subfze subfze. subfzeo subfzeo.*/
1240 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1241 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
1244 static void gen_subfic(DisasContext *ctx)
1246 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1247 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1252 /* neg neg. nego nego. */
1253 static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1255 TCGv zero = tcg_const_tl(0);
1256 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1257 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1258 tcg_temp_free(zero);
1261 static void gen_neg(DisasContext *ctx)
1263 gen_op_arith_neg(ctx, 0);
1266 static void gen_nego(DisasContext *ctx)
1268 gen_op_arith_neg(ctx, 1);
1271 /*** Integer logical ***/
1272 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1273 static void glue(gen_, name)(DisasContext *ctx) \
1275 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1276 cpu_gpr[rB(ctx->opcode)]); \
1277 if (unlikely(Rc(ctx->opcode) != 0)) \
1278 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1281 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1282 static void glue(gen_, name)(DisasContext *ctx) \
1284 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1285 if (unlikely(Rc(ctx->opcode) != 0)) \
1286 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1290 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
1292 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
1295 static void gen_andi_(DisasContext *ctx)
1297 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1298 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1302 static void gen_andis_(DisasContext *ctx)
1304 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1305 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1309 static void gen_cntlzw(DisasContext *ctx)
1311 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1312 if (unlikely(Rc(ctx->opcode) != 0))
1313 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1316 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
1317 /* extsb & extsb. */
1318 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
1319 /* extsh & extsh. */
1320 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
1322 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
1324 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
1327 static void gen_or(DisasContext *ctx)
1331 rs = rS(ctx->opcode);
1332 ra = rA(ctx->opcode);
1333 rb = rB(ctx->opcode);
1334 /* Optimisation for mr. ri case */
1335 if (rs != ra || rs != rb) {
1337 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1339 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
1340 if (unlikely(Rc(ctx->opcode) != 0))
1341 gen_set_Rc0(ctx, cpu_gpr[ra]);
1342 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1343 gen_set_Rc0(ctx, cpu_gpr[rs]);
1344 #if defined(TARGET_PPC64)
1350 /* Set process priority to low */
1354 /* Set process priority to medium-low */
1358 /* Set process priority to normal */
1361 #if !defined(CONFIG_USER_ONLY)
1363 if (ctx->mem_idx > 0) {
1364 /* Set process priority to very low */
1369 if (ctx->mem_idx > 0) {
1370 /* Set process priority to medium-hight */
1375 if (ctx->mem_idx > 0) {
1376 /* Set process priority to high */
1381 if (ctx->mem_idx > 1) {
1382 /* Set process priority to very high */
1392 TCGv t0 = tcg_temp_new();
1393 gen_load_spr(t0, SPR_PPR);
1394 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1395 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
1396 gen_store_spr(SPR_PPR, t0);
1403 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
1406 static void gen_xor(DisasContext *ctx)
1408 /* Optimisation for "set to zero" case */
1409 if (rS(ctx->opcode) != rB(ctx->opcode))
1410 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1412 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1413 if (unlikely(Rc(ctx->opcode) != 0))
1414 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1418 static void gen_ori(DisasContext *ctx)
1420 target_ulong uimm = UIMM(ctx->opcode);
1422 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1424 /* XXX: should handle special NOPs for POWER series */
1427 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1431 static void gen_oris(DisasContext *ctx)
1433 target_ulong uimm = UIMM(ctx->opcode);
1435 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1439 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1443 static void gen_xori(DisasContext *ctx)
1445 target_ulong uimm = UIMM(ctx->opcode);
1447 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1451 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1455 static void gen_xoris(DisasContext *ctx)
1457 target_ulong uimm = UIMM(ctx->opcode);
1459 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1463 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1466 /* popcntb : PowerPC 2.03 specification */
1467 static void gen_popcntb(DisasContext *ctx)
1469 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1472 static void gen_popcntw(DisasContext *ctx)
1474 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1477 #if defined(TARGET_PPC64)
1478 /* popcntd: PowerPC 2.06 specification */
1479 static void gen_popcntd(DisasContext *ctx)
1481 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1485 /* prtyw: PowerPC 2.05 specification */
1486 static void gen_prtyw(DisasContext *ctx)
1488 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1489 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1490 TCGv t0 = tcg_temp_new();
1491 tcg_gen_shri_tl(t0, rs, 16);
1492 tcg_gen_xor_tl(ra, rs, t0);
1493 tcg_gen_shri_tl(t0, ra, 8);
1494 tcg_gen_xor_tl(ra, ra, t0);
1495 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1499 #if defined(TARGET_PPC64)
1500 /* prtyd: PowerPC 2.05 specification */
1501 static void gen_prtyd(DisasContext *ctx)
1503 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1504 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1505 TCGv t0 = tcg_temp_new();
1506 tcg_gen_shri_tl(t0, rs, 32);
1507 tcg_gen_xor_tl(ra, rs, t0);
1508 tcg_gen_shri_tl(t0, ra, 16);
1509 tcg_gen_xor_tl(ra, ra, t0);
1510 tcg_gen_shri_tl(t0, ra, 8);
1511 tcg_gen_xor_tl(ra, ra, t0);
1512 tcg_gen_andi_tl(ra, ra, 1);
1517 #if defined(TARGET_PPC64)
1518 /* extsw & extsw. */
1519 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
1522 static void gen_cntlzd(DisasContext *ctx)
1524 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1525 if (unlikely(Rc(ctx->opcode) != 0))
1526 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1530 /*** Integer rotate ***/
1532 /* rlwimi & rlwimi. */
1533 static void gen_rlwimi(DisasContext *ctx)
1535 uint32_t mb, me, sh;
1537 mb = MB(ctx->opcode);
1538 me = ME(ctx->opcode);
1539 sh = SH(ctx->opcode);
1540 if (likely(sh == 0 && mb == 0 && me == 31)) {
1541 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1545 TCGv t0 = tcg_temp_new();
1546 #if defined(TARGET_PPC64)
1547 TCGv_i32 t2 = tcg_temp_new_i32();
1548 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1549 tcg_gen_rotli_i32(t2, t2, sh);
1550 tcg_gen_extu_i32_i64(t0, t2);
1551 tcg_temp_free_i32(t2);
1553 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1555 #if defined(TARGET_PPC64)
1559 mask = MASK(mb, me);
1560 t1 = tcg_temp_new();
1561 tcg_gen_andi_tl(t0, t0, mask);
1562 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1563 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1567 if (unlikely(Rc(ctx->opcode) != 0))
1568 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1571 /* rlwinm & rlwinm. */
1572 static void gen_rlwinm(DisasContext *ctx)
1574 uint32_t mb, me, sh;
1576 sh = SH(ctx->opcode);
1577 mb = MB(ctx->opcode);
1578 me = ME(ctx->opcode);
1580 if (likely(mb == 0 && me == (31 - sh))) {
1581 if (likely(sh == 0)) {
1582 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1584 TCGv t0 = tcg_temp_new();
1585 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1586 tcg_gen_shli_tl(t0, t0, sh);
1587 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1590 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
1591 TCGv t0 = tcg_temp_new();
1592 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1593 tcg_gen_shri_tl(t0, t0, mb);
1594 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1597 TCGv t0 = tcg_temp_new();
1598 #if defined(TARGET_PPC64)
1599 TCGv_i32 t1 = tcg_temp_new_i32();
1600 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1601 tcg_gen_rotli_i32(t1, t1, sh);
1602 tcg_gen_extu_i32_i64(t0, t1);
1603 tcg_temp_free_i32(t1);
1605 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1607 #if defined(TARGET_PPC64)
1611 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1614 if (unlikely(Rc(ctx->opcode) != 0))
1615 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1618 /* rlwnm & rlwnm. */
1619 static void gen_rlwnm(DisasContext *ctx)
1623 #if defined(TARGET_PPC64)
1627 mb = MB(ctx->opcode);
1628 me = ME(ctx->opcode);
1629 t0 = tcg_temp_new();
1630 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
1631 #if defined(TARGET_PPC64)
1632 t1 = tcg_temp_new_i32();
1633 t2 = tcg_temp_new_i32();
1634 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1635 tcg_gen_trunc_i64_i32(t2, t0);
1636 tcg_gen_rotl_i32(t1, t1, t2);
1637 tcg_gen_extu_i32_i64(t0, t1);
1638 tcg_temp_free_i32(t1);
1639 tcg_temp_free_i32(t2);
1641 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1643 if (unlikely(mb != 0 || me != 31)) {
1644 #if defined(TARGET_PPC64)
1648 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1650 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1653 if (unlikely(Rc(ctx->opcode) != 0))
1654 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1657 #if defined(TARGET_PPC64)
1658 #define GEN_PPC64_R2(name, opc1, opc2) \
1659 static void glue(gen_, name##0)(DisasContext *ctx) \
1661 gen_##name(ctx, 0); \
1664 static void glue(gen_, name##1)(DisasContext *ctx) \
1666 gen_##name(ctx, 1); \
1668 #define GEN_PPC64_R4(name, opc1, opc2) \
1669 static void glue(gen_, name##0)(DisasContext *ctx) \
1671 gen_##name(ctx, 0, 0); \
1674 static void glue(gen_, name##1)(DisasContext *ctx) \
1676 gen_##name(ctx, 0, 1); \
1679 static void glue(gen_, name##2)(DisasContext *ctx) \
1681 gen_##name(ctx, 1, 0); \
1684 static void glue(gen_, name##3)(DisasContext *ctx) \
1686 gen_##name(ctx, 1, 1); \
1689 static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1692 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1693 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1694 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1695 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1697 TCGv t0 = tcg_temp_new();
1698 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1699 if (likely(mb == 0 && me == 63)) {
1700 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1702 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1706 if (unlikely(Rc(ctx->opcode) != 0))
1707 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1709 /* rldicl - rldicl. */
1710 static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
1714 sh = SH(ctx->opcode) | (shn << 5);
1715 mb = MB(ctx->opcode) | (mbn << 5);
1716 gen_rldinm(ctx, mb, 63, sh);
1718 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1719 /* rldicr - rldicr. */
1720 static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
1724 sh = SH(ctx->opcode) | (shn << 5);
1725 me = MB(ctx->opcode) | (men << 5);
1726 gen_rldinm(ctx, 0, me, sh);
1728 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1729 /* rldic - rldic. */
1730 static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
1734 sh = SH(ctx->opcode) | (shn << 5);
1735 mb = MB(ctx->opcode) | (mbn << 5);
1736 gen_rldinm(ctx, mb, 63 - sh, sh);
1738 GEN_PPC64_R4(rldic, 0x1E, 0x04);
1740 static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
1744 t0 = tcg_temp_new();
1745 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1746 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1747 if (unlikely(mb != 0 || me != 63)) {
1748 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1750 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1753 if (unlikely(Rc(ctx->opcode) != 0))
1754 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1757 /* rldcl - rldcl. */
1758 static inline void gen_rldcl(DisasContext *ctx, int mbn)
1762 mb = MB(ctx->opcode) | (mbn << 5);
1763 gen_rldnm(ctx, mb, 63);
1765 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1766 /* rldcr - rldcr. */
1767 static inline void gen_rldcr(DisasContext *ctx, int men)
1771 me = MB(ctx->opcode) | (men << 5);
1772 gen_rldnm(ctx, 0, me);
1774 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1775 /* rldimi - rldimi. */
1776 static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
1778 uint32_t sh, mb, me;
1780 sh = SH(ctx->opcode) | (shn << 5);
1781 mb = MB(ctx->opcode) | (mbn << 5);
1783 if (unlikely(sh == 0 && mb == 0)) {
1784 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1789 t0 = tcg_temp_new();
1790 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1791 t1 = tcg_temp_new();
1792 mask = MASK(mb, me);
1793 tcg_gen_andi_tl(t0, t0, mask);
1794 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1795 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1799 if (unlikely(Rc(ctx->opcode) != 0))
1800 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1802 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1805 /*** Integer shift ***/
1808 static void gen_slw(DisasContext *ctx)
1812 t0 = tcg_temp_new();
1813 /* AND rS with a mask that is 0 when rB >= 0x20 */
1814 #if defined(TARGET_PPC64)
1815 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1816 tcg_gen_sari_tl(t0, t0, 0x3f);
1818 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1819 tcg_gen_sari_tl(t0, t0, 0x1f);
1821 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1822 t1 = tcg_temp_new();
1823 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1824 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1827 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
1828 if (unlikely(Rc(ctx->opcode) != 0))
1829 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1833 static void gen_sraw(DisasContext *ctx)
1835 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
1836 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1837 if (unlikely(Rc(ctx->opcode) != 0))
1838 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1841 /* srawi & srawi. */
1842 static void gen_srawi(DisasContext *ctx)
1844 int sh = SH(ctx->opcode);
1845 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1846 TCGv src = cpu_gpr[rS(ctx->opcode)];
1848 tcg_gen_mov_tl(dst, src);
1849 tcg_gen_movi_tl(cpu_ca, 0);
1852 tcg_gen_ext32s_tl(dst, src);
1853 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1854 t0 = tcg_temp_new();
1855 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1856 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1858 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1859 tcg_gen_sari_tl(dst, dst, sh);
1861 if (unlikely(Rc(ctx->opcode) != 0)) {
1862 gen_set_Rc0(ctx, dst);
1867 static void gen_srw(DisasContext *ctx)
1871 t0 = tcg_temp_new();
1872 /* AND rS with a mask that is 0 when rB >= 0x20 */
1873 #if defined(TARGET_PPC64)
1874 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1875 tcg_gen_sari_tl(t0, t0, 0x3f);
1877 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1878 tcg_gen_sari_tl(t0, t0, 0x1f);
1880 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1881 tcg_gen_ext32u_tl(t0, t0);
1882 t1 = tcg_temp_new();
1883 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1884 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1887 if (unlikely(Rc(ctx->opcode) != 0))
1888 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1891 #if defined(TARGET_PPC64)
1893 static void gen_sld(DisasContext *ctx)
1897 t0 = tcg_temp_new();
1898 /* AND rS with a mask that is 0 when rB >= 0x40 */
1899 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1900 tcg_gen_sari_tl(t0, t0, 0x3f);
1901 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1902 t1 = tcg_temp_new();
1903 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1904 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1907 if (unlikely(Rc(ctx->opcode) != 0))
1908 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1912 static void gen_srad(DisasContext *ctx)
1914 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
1915 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1916 if (unlikely(Rc(ctx->opcode) != 0))
1917 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1919 /* sradi & sradi. */
1920 static inline void gen_sradi(DisasContext *ctx, int n)
1922 int sh = SH(ctx->opcode) + (n << 5);
1923 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1924 TCGv src = cpu_gpr[rS(ctx->opcode)];
1926 tcg_gen_mov_tl(dst, src);
1927 tcg_gen_movi_tl(cpu_ca, 0);
1930 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1931 t0 = tcg_temp_new();
1932 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1933 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1935 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1936 tcg_gen_sari_tl(dst, src, sh);
1938 if (unlikely(Rc(ctx->opcode) != 0)) {
1939 gen_set_Rc0(ctx, dst);
1943 static void gen_sradi0(DisasContext *ctx)
1948 static void gen_sradi1(DisasContext *ctx)
1954 static void gen_srd(DisasContext *ctx)
1958 t0 = tcg_temp_new();
1959 /* AND rS with a mask that is 0 when rB >= 0x40 */
1960 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1961 tcg_gen_sari_tl(t0, t0, 0x3f);
1962 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1963 t1 = tcg_temp_new();
1964 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1965 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1968 if (unlikely(Rc(ctx->opcode) != 0))
1969 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1973 /*** Floating-Point arithmetic ***/
1974 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1975 static void gen_f##name(DisasContext *ctx) \
1977 if (unlikely(!ctx->fpu_enabled)) { \
1978 gen_exception(ctx, POWERPC_EXCP_FPU); \
1981 /* NIP cannot be restored if the memory exception comes from an helper */ \
1982 gen_update_nip(ctx, ctx->nip - 4); \
1983 gen_reset_fpstatus(); \
1984 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1985 cpu_fpr[rA(ctx->opcode)], \
1986 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
1988 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1989 cpu_fpr[rD(ctx->opcode)]); \
1991 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
1992 Rc(ctx->opcode) != 0); \
1995 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1996 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1997 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1999 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2000 static void gen_f##name(DisasContext *ctx) \
2002 if (unlikely(!ctx->fpu_enabled)) { \
2003 gen_exception(ctx, POWERPC_EXCP_FPU); \
2006 /* NIP cannot be restored if the memory exception comes from an helper */ \
2007 gen_update_nip(ctx, ctx->nip - 4); \
2008 gen_reset_fpstatus(); \
2009 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2010 cpu_fpr[rA(ctx->opcode)], \
2011 cpu_fpr[rB(ctx->opcode)]); \
2013 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2014 cpu_fpr[rD(ctx->opcode)]); \
2016 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2017 set_fprf, Rc(ctx->opcode) != 0); \
2019 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2020 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2021 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2023 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2024 static void gen_f##name(DisasContext *ctx) \
2026 if (unlikely(!ctx->fpu_enabled)) { \
2027 gen_exception(ctx, POWERPC_EXCP_FPU); \
2030 /* NIP cannot be restored if the memory exception comes from an helper */ \
2031 gen_update_nip(ctx, ctx->nip - 4); \
2032 gen_reset_fpstatus(); \
2033 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2034 cpu_fpr[rA(ctx->opcode)], \
2035 cpu_fpr[rC(ctx->opcode)]); \
2037 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2038 cpu_fpr[rD(ctx->opcode)]); \
2040 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2041 set_fprf, Rc(ctx->opcode) != 0); \
2043 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2044 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2045 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2047 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2048 static void gen_f##name(DisasContext *ctx) \
2050 if (unlikely(!ctx->fpu_enabled)) { \
2051 gen_exception(ctx, POWERPC_EXCP_FPU); \
2054 /* NIP cannot be restored if the memory exception comes from an helper */ \
2055 gen_update_nip(ctx, ctx->nip - 4); \
2056 gen_reset_fpstatus(); \
2057 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2058 cpu_fpr[rB(ctx->opcode)]); \
2059 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2060 set_fprf, Rc(ctx->opcode) != 0); \
2063 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2064 static void gen_f##name(DisasContext *ctx) \
2066 if (unlikely(!ctx->fpu_enabled)) { \
2067 gen_exception(ctx, POWERPC_EXCP_FPU); \
2070 /* NIP cannot be restored if the memory exception comes from an helper */ \
2071 gen_update_nip(ctx, ctx->nip - 4); \
2072 gen_reset_fpstatus(); \
2073 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2074 cpu_fpr[rB(ctx->opcode)]); \
2075 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2076 set_fprf, Rc(ctx->opcode) != 0); \
2080 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
2082 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
2084 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
2087 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
2090 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
2093 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2096 static void gen_frsqrtes(DisasContext *ctx)
2098 if (unlikely(!ctx->fpu_enabled)) {
2099 gen_exception(ctx, POWERPC_EXCP_FPU);
2102 /* NIP cannot be restored if the memory exception comes from an helper */
2103 gen_update_nip(ctx, ctx->nip - 4);
2104 gen_reset_fpstatus();
2105 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2106 cpu_fpr[rB(ctx->opcode)]);
2107 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2108 cpu_fpr[rD(ctx->opcode)]);
2109 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2113 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
2115 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
2119 static void gen_fsqrt(DisasContext *ctx)
2121 if (unlikely(!ctx->fpu_enabled)) {
2122 gen_exception(ctx, POWERPC_EXCP_FPU);
2125 /* NIP cannot be restored if the memory exception comes from an helper */
2126 gen_update_nip(ctx, ctx->nip - 4);
2127 gen_reset_fpstatus();
2128 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2129 cpu_fpr[rB(ctx->opcode)]);
2130 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2133 static void gen_fsqrts(DisasContext *ctx)
2135 if (unlikely(!ctx->fpu_enabled)) {
2136 gen_exception(ctx, POWERPC_EXCP_FPU);
2139 /* NIP cannot be restored if the memory exception comes from an helper */
2140 gen_update_nip(ctx, ctx->nip - 4);
2141 gen_reset_fpstatus();
2142 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2143 cpu_fpr[rB(ctx->opcode)]);
2144 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2145 cpu_fpr[rD(ctx->opcode)]);
2146 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2149 /*** Floating-Point multiply-and-add ***/
2150 /* fmadd - fmadds */
2151 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
2152 /* fmsub - fmsubs */
2153 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
2154 /* fnmadd - fnmadds */
2155 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
2156 /* fnmsub - fnmsubs */
2157 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
2159 /*** Floating-Point round & convert ***/
2161 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
2163 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
2165 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
2166 #if defined(TARGET_PPC64)
2168 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
2170 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
2172 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
2176 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
2178 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
2180 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
2182 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
2184 /*** Floating-Point compare ***/
2187 static void gen_fcmpo(DisasContext *ctx)
2190 if (unlikely(!ctx->fpu_enabled)) {
2191 gen_exception(ctx, POWERPC_EXCP_FPU);
2194 /* NIP cannot be restored if the memory exception comes from an helper */
2195 gen_update_nip(ctx, ctx->nip - 4);
2196 gen_reset_fpstatus();
2197 crf = tcg_const_i32(crfD(ctx->opcode));
2198 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2199 cpu_fpr[rB(ctx->opcode)], crf);
2200 tcg_temp_free_i32(crf);
2201 gen_helper_float_check_status(cpu_env);
2205 static void gen_fcmpu(DisasContext *ctx)
2208 if (unlikely(!ctx->fpu_enabled)) {
2209 gen_exception(ctx, POWERPC_EXCP_FPU);
2212 /* NIP cannot be restored if the memory exception comes from an helper */
2213 gen_update_nip(ctx, ctx->nip - 4);
2214 gen_reset_fpstatus();
2215 crf = tcg_const_i32(crfD(ctx->opcode));
2216 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2217 cpu_fpr[rB(ctx->opcode)], crf);
2218 tcg_temp_free_i32(crf);
2219 gen_helper_float_check_status(cpu_env);
2222 /*** Floating-point move ***/
2224 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2225 static void gen_fabs(DisasContext *ctx)
2227 if (unlikely(!ctx->fpu_enabled)) {
2228 gen_exception(ctx, POWERPC_EXCP_FPU);
2231 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2233 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2237 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2238 static void gen_fmr(DisasContext *ctx)
2240 if (unlikely(!ctx->fpu_enabled)) {
2241 gen_exception(ctx, POWERPC_EXCP_FPU);
2244 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2245 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2249 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2250 static void gen_fnabs(DisasContext *ctx)
2252 if (unlikely(!ctx->fpu_enabled)) {
2253 gen_exception(ctx, POWERPC_EXCP_FPU);
2256 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2258 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2262 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2263 static void gen_fneg(DisasContext *ctx)
2265 if (unlikely(!ctx->fpu_enabled)) {
2266 gen_exception(ctx, POWERPC_EXCP_FPU);
2269 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2271 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2274 /* fcpsgn: PowerPC 2.05 specification */
2275 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2276 static void gen_fcpsgn(DisasContext *ctx)
2278 if (unlikely(!ctx->fpu_enabled)) {
2279 gen_exception(ctx, POWERPC_EXCP_FPU);
2282 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2283 cpu_fpr[rB(ctx->opcode)], 0, 63);
2284 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2287 /*** Floating-Point status & ctrl register ***/
2290 static void gen_mcrfs(DisasContext *ctx)
2292 TCGv tmp = tcg_temp_new();
2295 if (unlikely(!ctx->fpu_enabled)) {
2296 gen_exception(ctx, POWERPC_EXCP_FPU);
2299 bfa = 4 * (7 - crfS(ctx->opcode));
2300 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2301 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2303 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
2304 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
2308 static void gen_mffs(DisasContext *ctx)
2310 if (unlikely(!ctx->fpu_enabled)) {
2311 gen_exception(ctx, POWERPC_EXCP_FPU);
2314 gen_reset_fpstatus();
2315 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
2316 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2320 static void gen_mtfsb0(DisasContext *ctx)
2324 if (unlikely(!ctx->fpu_enabled)) {
2325 gen_exception(ctx, POWERPC_EXCP_FPU);
2328 crb = 31 - crbD(ctx->opcode);
2329 gen_reset_fpstatus();
2330 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
2332 /* NIP cannot be restored if the memory exception comes from an helper */
2333 gen_update_nip(ctx, ctx->nip - 4);
2334 t0 = tcg_const_i32(crb);
2335 gen_helper_fpscr_clrbit(cpu_env, t0);
2336 tcg_temp_free_i32(t0);
2338 if (unlikely(Rc(ctx->opcode) != 0)) {
2339 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2340 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2345 static void gen_mtfsb1(DisasContext *ctx)
2349 if (unlikely(!ctx->fpu_enabled)) {
2350 gen_exception(ctx, POWERPC_EXCP_FPU);
2353 crb = 31 - crbD(ctx->opcode);
2354 gen_reset_fpstatus();
2355 /* XXX: we pretend we can only do IEEE floating-point computations */
2356 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
2358 /* NIP cannot be restored if the memory exception comes from an helper */
2359 gen_update_nip(ctx, ctx->nip - 4);
2360 t0 = tcg_const_i32(crb);
2361 gen_helper_fpscr_setbit(cpu_env, t0);
2362 tcg_temp_free_i32(t0);
2364 if (unlikely(Rc(ctx->opcode) != 0)) {
2365 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2366 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2368 /* We can raise a differed exception */
2369 gen_helper_float_check_status(cpu_env);
2373 static void gen_mtfsf(DisasContext *ctx)
2378 if (unlikely(!ctx->fpu_enabled)) {
2379 gen_exception(ctx, POWERPC_EXCP_FPU);
2382 flm = FPFLM(ctx->opcode);
2383 l = FPL(ctx->opcode);
2384 w = FPW(ctx->opcode);
2385 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2386 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2389 /* NIP cannot be restored if the memory exception comes from an helper */
2390 gen_update_nip(ctx, ctx->nip - 4);
2391 gen_reset_fpstatus();
2393 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2395 t0 = tcg_const_i32(flm << (w * 8));
2397 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
2398 tcg_temp_free_i32(t0);
2399 if (unlikely(Rc(ctx->opcode) != 0)) {
2400 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2401 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2403 /* We can raise a differed exception */
2404 gen_helper_float_check_status(cpu_env);
2408 static void gen_mtfsfi(DisasContext *ctx)
2414 if (unlikely(!ctx->fpu_enabled)) {
2415 gen_exception(ctx, POWERPC_EXCP_FPU);
2418 w = FPW(ctx->opcode);
2419 bf = FPBF(ctx->opcode);
2420 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2421 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2424 sh = (8 * w) + 7 - bf;
2425 /* NIP cannot be restored if the memory exception comes from an helper */
2426 gen_update_nip(ctx, ctx->nip - 4);
2427 gen_reset_fpstatus();
2428 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
2429 t1 = tcg_const_i32(1 << sh);
2430 gen_helper_store_fpscr(cpu_env, t0, t1);
2431 tcg_temp_free_i64(t0);
2432 tcg_temp_free_i32(t1);
2433 if (unlikely(Rc(ctx->opcode) != 0)) {
2434 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2435 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
2437 /* We can raise a differed exception */
2438 gen_helper_float_check_status(cpu_env);
2441 /*** Addressing modes ***/
2442 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2443 static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2446 target_long simm = SIMM(ctx->opcode);
2449 if (rA(ctx->opcode) == 0) {
2450 if (NARROW_MODE(ctx)) {
2451 simm = (uint32_t)simm;
2453 tcg_gen_movi_tl(EA, simm);
2454 } else if (likely(simm != 0)) {
2455 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2456 if (NARROW_MODE(ctx)) {
2457 tcg_gen_ext32u_tl(EA, EA);
2460 if (NARROW_MODE(ctx)) {
2461 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2463 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2468 static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
2470 if (rA(ctx->opcode) == 0) {
2471 if (NARROW_MODE(ctx)) {
2472 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2474 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2477 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2478 if (NARROW_MODE(ctx)) {
2479 tcg_gen_ext32u_tl(EA, EA);
2484 static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
2486 if (rA(ctx->opcode) == 0) {
2487 tcg_gen_movi_tl(EA, 0);
2488 } else if (NARROW_MODE(ctx)) {
2489 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2491 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2495 static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2498 tcg_gen_addi_tl(ret, arg1, val);
2499 if (NARROW_MODE(ctx)) {
2500 tcg_gen_ext32u_tl(ret, ret);
2504 static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
2506 int l1 = gen_new_label();
2507 TCGv t0 = tcg_temp_new();
2509 /* NIP cannot be restored if the memory exception comes from an helper */
2510 gen_update_nip(ctx, ctx->nip - 4);
2511 tcg_gen_andi_tl(t0, EA, mask);
2512 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2513 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2514 t2 = tcg_const_i32(0);
2515 gen_helper_raise_exception_err(cpu_env, t1, t2);
2516 tcg_temp_free_i32(t1);
2517 tcg_temp_free_i32(t2);
2522 /*** Integer load ***/
2523 static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2525 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2528 static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2530 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2533 static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2535 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2536 if (unlikely(ctx->le_mode)) {
2537 tcg_gen_bswap16_tl(arg1, arg1);
2541 static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2543 if (unlikely(ctx->le_mode)) {
2544 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2545 tcg_gen_bswap16_tl(arg1, arg1);
2546 tcg_gen_ext16s_tl(arg1, arg1);
2548 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2552 static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2554 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2555 if (unlikely(ctx->le_mode)) {
2556 tcg_gen_bswap32_tl(arg1, arg1);
2560 static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2562 if (unlikely(ctx->le_mode)) {
2563 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2564 tcg_gen_bswap32_tl(arg1, arg1);
2565 tcg_gen_ext32s_tl(arg1, arg1);
2567 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
2570 static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2572 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2573 if (unlikely(ctx->le_mode)) {
2574 tcg_gen_bswap64_i64(arg1, arg1);
2578 static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
2580 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
2583 static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
2585 if (unlikely(ctx->le_mode)) {
2586 TCGv t0 = tcg_temp_new();
2587 tcg_gen_ext16u_tl(t0, arg1);
2588 tcg_gen_bswap16_tl(t0, t0);
2589 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2592 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2596 static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
2598 if (unlikely(ctx->le_mode)) {
2599 TCGv t0 = tcg_temp_new();
2600 tcg_gen_ext32u_tl(t0, arg1);
2601 tcg_gen_bswap32_tl(t0, t0);
2602 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2605 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2609 static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2611 if (unlikely(ctx->le_mode)) {
2612 TCGv_i64 t0 = tcg_temp_new_i64();
2613 tcg_gen_bswap64_i64(t0, arg1);
2614 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
2615 tcg_temp_free_i64(t0);
2617 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
2620 #define GEN_LD(name, ldop, opc, type) \
2621 static void glue(gen_, name)(DisasContext *ctx) \
2624 gen_set_access_type(ctx, ACCESS_INT); \
2625 EA = tcg_temp_new(); \
2626 gen_addr_imm_index(ctx, EA, 0); \
2627 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2628 tcg_temp_free(EA); \
2631 #define GEN_LDU(name, ldop, opc, type) \
2632 static void glue(gen_, name##u)(DisasContext *ctx) \
2635 if (unlikely(rA(ctx->opcode) == 0 || \
2636 rA(ctx->opcode) == rD(ctx->opcode))) { \
2637 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2640 gen_set_access_type(ctx, ACCESS_INT); \
2641 EA = tcg_temp_new(); \
2642 if (type == PPC_64B) \
2643 gen_addr_imm_index(ctx, EA, 0x03); \
2645 gen_addr_imm_index(ctx, EA, 0); \
2646 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2647 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2648 tcg_temp_free(EA); \
2651 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2652 static void glue(gen_, name##ux)(DisasContext *ctx) \
2655 if (unlikely(rA(ctx->opcode) == 0 || \
2656 rA(ctx->opcode) == rD(ctx->opcode))) { \
2657 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2660 gen_set_access_type(ctx, ACCESS_INT); \
2661 EA = tcg_temp_new(); \
2662 gen_addr_reg_index(ctx, EA); \
2663 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2664 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2665 tcg_temp_free(EA); \
2668 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2669 static void glue(gen_, name##x)(DisasContext *ctx) \
2672 gen_set_access_type(ctx, ACCESS_INT); \
2673 EA = tcg_temp_new(); \
2674 gen_addr_reg_index(ctx, EA); \
2675 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2676 tcg_temp_free(EA); \
2678 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2679 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2681 #define GEN_LDS(name, ldop, op, type) \
2682 GEN_LD(name, ldop, op | 0x20, type); \
2683 GEN_LDU(name, ldop, op | 0x21, type); \
2684 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2685 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2687 /* lbz lbzu lbzux lbzx */
2688 GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
2689 /* lha lhau lhaux lhax */
2690 GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
2691 /* lhz lhzu lhzux lhzx */
2692 GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
2693 /* lwz lwzu lwzux lwzx */
2694 GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
2695 #if defined(TARGET_PPC64)
2697 GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
2699 GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
2701 GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
2703 GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
2705 static void gen_ld(DisasContext *ctx)
2708 if (Rc(ctx->opcode)) {
2709 if (unlikely(rA(ctx->opcode) == 0 ||
2710 rA(ctx->opcode) == rD(ctx->opcode))) {
2711 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2715 gen_set_access_type(ctx, ACCESS_INT);
2716 EA = tcg_temp_new();
2717 gen_addr_imm_index(ctx, EA, 0x03);
2718 if (ctx->opcode & 0x02) {
2719 /* lwa (lwau is undefined) */
2720 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
2723 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
2725 if (Rc(ctx->opcode))
2726 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2731 static void gen_lq(DisasContext *ctx)
2733 #if defined(CONFIG_USER_ONLY)
2734 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2739 /* Restore CPU state */
2740 if (unlikely(ctx->mem_idx == 0)) {
2741 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2744 ra = rA(ctx->opcode);
2745 rd = rD(ctx->opcode);
2746 if (unlikely((rd & 1) || rd == ra)) {
2747 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2750 if (unlikely(ctx->le_mode)) {
2751 /* Little-endian mode is not handled */
2752 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2755 gen_set_access_type(ctx, ACCESS_INT);
2756 EA = tcg_temp_new();
2757 gen_addr_imm_index(ctx, EA, 0x0F);
2758 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2759 gen_addr_add(ctx, EA, EA, 8);
2760 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2766 /*** Integer store ***/
2767 #define GEN_ST(name, stop, opc, type) \
2768 static void glue(gen_, name)(DisasContext *ctx) \
2771 gen_set_access_type(ctx, ACCESS_INT); \
2772 EA = tcg_temp_new(); \
2773 gen_addr_imm_index(ctx, EA, 0); \
2774 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2775 tcg_temp_free(EA); \
2778 #define GEN_STU(name, stop, opc, type) \
2779 static void glue(gen_, stop##u)(DisasContext *ctx) \
2782 if (unlikely(rA(ctx->opcode) == 0)) { \
2783 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2786 gen_set_access_type(ctx, ACCESS_INT); \
2787 EA = tcg_temp_new(); \
2788 if (type == PPC_64B) \
2789 gen_addr_imm_index(ctx, EA, 0x03); \
2791 gen_addr_imm_index(ctx, EA, 0); \
2792 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2793 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2794 tcg_temp_free(EA); \
2797 #define GEN_STUX(name, stop, opc2, opc3, type) \
2798 static void glue(gen_, name##ux)(DisasContext *ctx) \
2801 if (unlikely(rA(ctx->opcode) == 0)) { \
2802 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2805 gen_set_access_type(ctx, ACCESS_INT); \
2806 EA = tcg_temp_new(); \
2807 gen_addr_reg_index(ctx, EA); \
2808 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2809 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2810 tcg_temp_free(EA); \
2813 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2814 static void glue(gen_, name##x)(DisasContext *ctx) \
2817 gen_set_access_type(ctx, ACCESS_INT); \
2818 EA = tcg_temp_new(); \
2819 gen_addr_reg_index(ctx, EA); \
2820 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2821 tcg_temp_free(EA); \
2823 #define GEN_STX(name, stop, opc2, opc3, type) \
2824 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2826 #define GEN_STS(name, stop, op, type) \
2827 GEN_ST(name, stop, op | 0x20, type); \
2828 GEN_STU(name, stop, op | 0x21, type); \
2829 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2830 GEN_STX(name, stop, 0x17, op | 0x00, type)
2832 /* stb stbu stbux stbx */
2833 GEN_STS(stb, st8, 0x06, PPC_INTEGER);
2834 /* sth sthu sthux sthx */
2835 GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
2836 /* stw stwu stwux stwx */
2837 GEN_STS(stw, st32, 0x04, PPC_INTEGER);
2838 #if defined(TARGET_PPC64)
2839 GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2840 GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
2842 static void gen_std(DisasContext *ctx)
2847 rs = rS(ctx->opcode);
2848 if ((ctx->opcode & 0x3) == 0x2) {
2849 #if defined(CONFIG_USER_ONLY)
2850 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2853 if (unlikely(ctx->mem_idx == 0)) {
2854 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2857 if (unlikely(rs & 1)) {
2858 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2861 if (unlikely(ctx->le_mode)) {
2862 /* Little-endian mode is not handled */
2863 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2866 gen_set_access_type(ctx, ACCESS_INT);
2867 EA = tcg_temp_new();
2868 gen_addr_imm_index(ctx, EA, 0x03);
2869 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
2870 gen_addr_add(ctx, EA, EA, 8);
2871 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
2876 if (Rc(ctx->opcode)) {
2877 if (unlikely(rA(ctx->opcode) == 0)) {
2878 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2882 gen_set_access_type(ctx, ACCESS_INT);
2883 EA = tcg_temp_new();
2884 gen_addr_imm_index(ctx, EA, 0x03);
2885 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
2886 if (Rc(ctx->opcode))
2887 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2892 /*** Integer load and store with byte reverse ***/
2894 static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
2896 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2897 if (likely(!ctx->le_mode)) {
2898 tcg_gen_bswap16_tl(arg1, arg1);
2901 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
2904 static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
2906 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2907 if (likely(!ctx->le_mode)) {
2908 tcg_gen_bswap32_tl(arg1, arg1);
2911 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
2913 #if defined(TARGET_PPC64)
2915 static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
2917 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2918 if (likely(!ctx->le_mode)) {
2919 tcg_gen_bswap64_tl(arg1, arg1);
2922 GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
2923 #endif /* TARGET_PPC64 */
2926 static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
2928 if (likely(!ctx->le_mode)) {
2929 TCGv t0 = tcg_temp_new();
2930 tcg_gen_ext16u_tl(t0, arg1);
2931 tcg_gen_bswap16_tl(t0, t0);
2932 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2935 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2938 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
2941 static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
2943 if (likely(!ctx->le_mode)) {
2944 TCGv t0 = tcg_temp_new();
2945 tcg_gen_ext32u_tl(t0, arg1);
2946 tcg_gen_bswap32_tl(t0, t0);
2947 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2950 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2953 GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
2955 #if defined(TARGET_PPC64)
2957 static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
2959 if (likely(!ctx->le_mode)) {
2960 TCGv t0 = tcg_temp_new();
2961 tcg_gen_bswap64_tl(t0, arg1);
2962 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
2965 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
2968 GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
2969 #endif /* TARGET_PPC64 */
2971 /*** Integer load and store multiple ***/
2974 static void gen_lmw(DisasContext *ctx)
2978 gen_set_access_type(ctx, ACCESS_INT);
2979 /* NIP cannot be restored if the memory exception comes from an helper */
2980 gen_update_nip(ctx, ctx->nip - 4);
2981 t0 = tcg_temp_new();
2982 t1 = tcg_const_i32(rD(ctx->opcode));
2983 gen_addr_imm_index(ctx, t0, 0);
2984 gen_helper_lmw(cpu_env, t0, t1);
2986 tcg_temp_free_i32(t1);
2990 static void gen_stmw(DisasContext *ctx)
2994 gen_set_access_type(ctx, ACCESS_INT);
2995 /* NIP cannot be restored if the memory exception comes from an helper */
2996 gen_update_nip(ctx, ctx->nip - 4);
2997 t0 = tcg_temp_new();
2998 t1 = tcg_const_i32(rS(ctx->opcode));
2999 gen_addr_imm_index(ctx, t0, 0);
3000 gen_helper_stmw(cpu_env, t0, t1);
3002 tcg_temp_free_i32(t1);
3005 /*** Integer load and store strings ***/
3008 /* PowerPC32 specification says we must generate an exception if
3009 * rA is in the range of registers to be loaded.
3010 * In an other hand, IBM says this is valid, but rA won't be loaded.
3011 * For now, I'll follow the spec...
3013 static void gen_lswi(DisasContext *ctx)
3017 int nb = NB(ctx->opcode);
3018 int start = rD(ctx->opcode);
3019 int ra = rA(ctx->opcode);
3025 if (unlikely(((start + nr) > 32 &&
3026 start <= ra && (start + nr - 32) > ra) ||
3027 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
3028 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
3031 gen_set_access_type(ctx, ACCESS_INT);
3032 /* NIP cannot be restored if the memory exception comes from an helper */
3033 gen_update_nip(ctx, ctx->nip - 4);
3034 t0 = tcg_temp_new();
3035 gen_addr_register(ctx, t0);
3036 t1 = tcg_const_i32(nb);
3037 t2 = tcg_const_i32(start);
3038 gen_helper_lsw(cpu_env, t0, t1, t2);
3040 tcg_temp_free_i32(t1);
3041 tcg_temp_free_i32(t2);
3045 static void gen_lswx(DisasContext *ctx)
3048 TCGv_i32 t1, t2, t3;
3049 gen_set_access_type(ctx, ACCESS_INT);
3050 /* NIP cannot be restored if the memory exception comes from an helper */
3051 gen_update_nip(ctx, ctx->nip - 4);
3052 t0 = tcg_temp_new();
3053 gen_addr_reg_index(ctx, t0);
3054 t1 = tcg_const_i32(rD(ctx->opcode));
3055 t2 = tcg_const_i32(rA(ctx->opcode));
3056 t3 = tcg_const_i32(rB(ctx->opcode));
3057 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
3059 tcg_temp_free_i32(t1);
3060 tcg_temp_free_i32(t2);
3061 tcg_temp_free_i32(t3);
3065 static void gen_stswi(DisasContext *ctx)
3069 int nb = NB(ctx->opcode);
3070 gen_set_access_type(ctx, ACCESS_INT);
3071 /* NIP cannot be restored if the memory exception comes from an helper */
3072 gen_update_nip(ctx, ctx->nip - 4);
3073 t0 = tcg_temp_new();
3074 gen_addr_register(ctx, t0);
3077 t1 = tcg_const_i32(nb);
3078 t2 = tcg_const_i32(rS(ctx->opcode));
3079 gen_helper_stsw(cpu_env, t0, t1, t2);
3081 tcg_temp_free_i32(t1);
3082 tcg_temp_free_i32(t2);
3086 static void gen_stswx(DisasContext *ctx)
3090 gen_set_access_type(ctx, ACCESS_INT);
3091 /* NIP cannot be restored if the memory exception comes from an helper */
3092 gen_update_nip(ctx, ctx->nip - 4);
3093 t0 = tcg_temp_new();
3094 gen_addr_reg_index(ctx, t0);
3095 t1 = tcg_temp_new_i32();
3096 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3097 tcg_gen_andi_i32(t1, t1, 0x7F);
3098 t2 = tcg_const_i32(rS(ctx->opcode));
3099 gen_helper_stsw(cpu_env, t0, t1, t2);
3101 tcg_temp_free_i32(t1);
3102 tcg_temp_free_i32(t2);
3105 /*** Memory synchronisation ***/
3107 static void gen_eieio(DisasContext *ctx)
3112 static void gen_isync(DisasContext *ctx)
3114 gen_stop_exception(ctx);
3118 static void gen_lwarx(DisasContext *ctx)
3121 TCGv gpr = cpu_gpr[rD(ctx->opcode)];
3122 gen_set_access_type(ctx, ACCESS_RES);
3123 t0 = tcg_temp_local_new();
3124 gen_addr_reg_index(ctx, t0);
3125 gen_check_align(ctx, t0, 0x03);
3126 gen_qemu_ld32u(ctx, gpr, t0);
3127 tcg_gen_mov_tl(cpu_reserve, t0);
3128 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val));
3132 #if defined(CONFIG_USER_ONLY)
3133 static void gen_conditional_store (DisasContext *ctx, TCGv EA,
3136 TCGv t0 = tcg_temp_new();
3137 uint32_t save_exception = ctx->exception;
3139 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
3140 tcg_gen_movi_tl(t0, (size << 5) | reg);
3141 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
3143 gen_update_nip(ctx, ctx->nip-4);
3144 ctx->exception = POWERPC_EXCP_BRANCH;
3145 gen_exception(ctx, POWERPC_EXCP_STCX);
3146 ctx->exception = save_exception;
3151 static void gen_stwcx_(DisasContext *ctx)
3154 gen_set_access_type(ctx, ACCESS_RES);
3155 t0 = tcg_temp_local_new();
3156 gen_addr_reg_index(ctx, t0);
3157 gen_check_align(ctx, t0, 0x03);
3158 #if defined(CONFIG_USER_ONLY)
3159 gen_conditional_store(ctx, t0, rS(ctx->opcode), 4);
3164 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3165 l1 = gen_new_label();
3166 tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3167 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3168 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3170 tcg_gen_movi_tl(cpu_reserve, -1);
3176 #if defined(TARGET_PPC64)
3178 static void gen_ldarx(DisasContext *ctx)
3181 TCGv gpr = cpu_gpr[rD(ctx->opcode)];
3182 gen_set_access_type(ctx, ACCESS_RES);
3183 t0 = tcg_temp_local_new();
3184 gen_addr_reg_index(ctx, t0);
3185 gen_check_align(ctx, t0, 0x07);
3186 gen_qemu_ld64(ctx, gpr, t0);
3187 tcg_gen_mov_tl(cpu_reserve, t0);
3188 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val));
3193 static void gen_stdcx_(DisasContext *ctx)
3196 gen_set_access_type(ctx, ACCESS_RES);
3197 t0 = tcg_temp_local_new();
3198 gen_addr_reg_index(ctx, t0);
3199 gen_check_align(ctx, t0, 0x07);
3200 #if defined(CONFIG_USER_ONLY)
3201 gen_conditional_store(ctx, t0, rS(ctx->opcode), 8);
3205 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3206 l1 = gen_new_label();
3207 tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3208 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3209 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3211 tcg_gen_movi_tl(cpu_reserve, -1);
3216 #endif /* defined(TARGET_PPC64) */
3219 static void gen_sync(DisasContext *ctx)
3224 static void gen_wait(DisasContext *ctx)
3226 TCGv_i32 t0 = tcg_temp_new_i32();
3227 tcg_gen_st_i32(t0, cpu_env,
3228 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
3229 tcg_temp_free_i32(t0);
3230 /* Stop translation, as the CPU is supposed to sleep from now */
3231 gen_exception_err(ctx, EXCP_HLT, 1);
3234 /*** Floating-point load ***/
3235 #define GEN_LDF(name, ldop, opc, type) \
3236 static void glue(gen_, name)(DisasContext *ctx) \
3239 if (unlikely(!ctx->fpu_enabled)) { \
3240 gen_exception(ctx, POWERPC_EXCP_FPU); \
3243 gen_set_access_type(ctx, ACCESS_FLOAT); \
3244 EA = tcg_temp_new(); \
3245 gen_addr_imm_index(ctx, EA, 0); \
3246 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3247 tcg_temp_free(EA); \
3250 #define GEN_LDUF(name, ldop, opc, type) \
3251 static void glue(gen_, name##u)(DisasContext *ctx) \
3254 if (unlikely(!ctx->fpu_enabled)) { \
3255 gen_exception(ctx, POWERPC_EXCP_FPU); \
3258 if (unlikely(rA(ctx->opcode) == 0)) { \
3259 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3262 gen_set_access_type(ctx, ACCESS_FLOAT); \
3263 EA = tcg_temp_new(); \
3264 gen_addr_imm_index(ctx, EA, 0); \
3265 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3266 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3267 tcg_temp_free(EA); \
3270 #define GEN_LDUXF(name, ldop, opc, type) \
3271 static void glue(gen_, name##ux)(DisasContext *ctx) \
3274 if (unlikely(!ctx->fpu_enabled)) { \
3275 gen_exception(ctx, POWERPC_EXCP_FPU); \
3278 if (unlikely(rA(ctx->opcode) == 0)) { \
3279 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3282 gen_set_access_type(ctx, ACCESS_FLOAT); \
3283 EA = tcg_temp_new(); \
3284 gen_addr_reg_index(ctx, EA); \
3285 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3286 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3287 tcg_temp_free(EA); \
3290 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3291 static void glue(gen_, name##x)(DisasContext *ctx) \
3294 if (unlikely(!ctx->fpu_enabled)) { \
3295 gen_exception(ctx, POWERPC_EXCP_FPU); \
3298 gen_set_access_type(ctx, ACCESS_FLOAT); \
3299 EA = tcg_temp_new(); \
3300 gen_addr_reg_index(ctx, EA); \
3301 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3302 tcg_temp_free(EA); \
3305 #define GEN_LDFS(name, ldop, op, type) \
3306 GEN_LDF(name, ldop, op | 0x20, type); \
3307 GEN_LDUF(name, ldop, op | 0x21, type); \
3308 GEN_LDUXF(name, ldop, op | 0x01, type); \
3309 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3311 static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3313 TCGv t0 = tcg_temp_new();
3314 TCGv_i32 t1 = tcg_temp_new_i32();
3315 gen_qemu_ld32u(ctx, t0, arg2);
3316 tcg_gen_trunc_tl_i32(t1, t0);
3318 gen_helper_float32_to_float64(arg1, cpu_env, t1);
3319 tcg_temp_free_i32(t1);
3322 /* lfd lfdu lfdux lfdx */
3323 GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3324 /* lfs lfsu lfsux lfsx */
3325 GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
3328 static void gen_lfdp(DisasContext *ctx)
3331 if (unlikely(!ctx->fpu_enabled)) {
3332 gen_exception(ctx, POWERPC_EXCP_FPU);
3335 gen_set_access_type(ctx, ACCESS_FLOAT);
3336 EA = tcg_temp_new();
3337 gen_addr_imm_index(ctx, EA, 0); \
3338 if (unlikely(ctx->le_mode)) {
3339 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3340 tcg_gen_addi_tl(EA, EA, 8);
3341 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3343 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3344 tcg_gen_addi_tl(EA, EA, 8);
3345 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3351 static void gen_lfdpx(DisasContext *ctx)
3354 if (unlikely(!ctx->fpu_enabled)) {
3355 gen_exception(ctx, POWERPC_EXCP_FPU);
3358 gen_set_access_type(ctx, ACCESS_FLOAT);
3359 EA = tcg_temp_new();
3360 gen_addr_reg_index(ctx, EA);
3361 if (unlikely(ctx->le_mode)) {
3362 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3363 tcg_gen_addi_tl(EA, EA, 8);
3364 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3366 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3367 tcg_gen_addi_tl(EA, EA, 8);
3368 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3374 static void gen_lfiwax(DisasContext *ctx)
3378 if (unlikely(!ctx->fpu_enabled)) {
3379 gen_exception(ctx, POWERPC_EXCP_FPU);
3382 gen_set_access_type(ctx, ACCESS_FLOAT);
3383 EA = tcg_temp_new();
3384 t0 = tcg_temp_new();
3385 gen_addr_reg_index(ctx, EA);
3386 gen_qemu_ld32s(ctx, t0, EA);
3387 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
3392 /*** Floating-point store ***/
3393 #define GEN_STF(name, stop, opc, type) \
3394 static void glue(gen_, name)(DisasContext *ctx) \
3397 if (unlikely(!ctx->fpu_enabled)) { \
3398 gen_exception(ctx, POWERPC_EXCP_FPU); \
3401 gen_set_access_type(ctx, ACCESS_FLOAT); \
3402 EA = tcg_temp_new(); \
3403 gen_addr_imm_index(ctx, EA, 0); \
3404 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3405 tcg_temp_free(EA); \
3408 #define GEN_STUF(name, stop, opc, type) \
3409 static void glue(gen_, name##u)(DisasContext *ctx) \
3412 if (unlikely(!ctx->fpu_enabled)) { \
3413 gen_exception(ctx, POWERPC_EXCP_FPU); \
3416 if (unlikely(rA(ctx->opcode) == 0)) { \
3417 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3420 gen_set_access_type(ctx, ACCESS_FLOAT); \
3421 EA = tcg_temp_new(); \
3422 gen_addr_imm_index(ctx, EA, 0); \
3423 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3424 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3425 tcg_temp_free(EA); \
3428 #define GEN_STUXF(name, stop, opc, type) \
3429 static void glue(gen_, name##ux)(DisasContext *ctx) \
3432 if (unlikely(!ctx->fpu_enabled)) { \
3433 gen_exception(ctx, POWERPC_EXCP_FPU); \
3436 if (unlikely(rA(ctx->opcode) == 0)) { \
3437 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3440 gen_set_access_type(ctx, ACCESS_FLOAT); \
3441 EA = tcg_temp_new(); \
3442 gen_addr_reg_index(ctx, EA); \
3443 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3444 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3445 tcg_temp_free(EA); \
3448 #define GEN_STXF(name, stop, opc2, opc3, type) \
3449 static void glue(gen_, name##x)(DisasContext *ctx) \
3452 if (unlikely(!ctx->fpu_enabled)) { \
3453 gen_exception(ctx, POWERPC_EXCP_FPU); \
3456 gen_set_access_type(ctx, ACCESS_FLOAT); \
3457 EA = tcg_temp_new(); \
3458 gen_addr_reg_index(ctx, EA); \
3459 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3460 tcg_temp_free(EA); \
3463 #define GEN_STFS(name, stop, op, type) \
3464 GEN_STF(name, stop, op | 0x20, type); \
3465 GEN_STUF(name, stop, op | 0x21, type); \
3466 GEN_STUXF(name, stop, op | 0x01, type); \
3467 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3469 static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3471 TCGv_i32 t0 = tcg_temp_new_i32();
3472 TCGv t1 = tcg_temp_new();
3473 gen_helper_float64_to_float32(t0, cpu_env, arg1);
3474 tcg_gen_extu_i32_tl(t1, t0);
3475 tcg_temp_free_i32(t0);
3476 gen_qemu_st32(ctx, t1, arg2);
3480 /* stfd stfdu stfdux stfdx */
3481 GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
3482 /* stfs stfsu stfsux stfsx */
3483 GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
3486 static void gen_stfdp(DisasContext *ctx)
3489 if (unlikely(!ctx->fpu_enabled)) {
3490 gen_exception(ctx, POWERPC_EXCP_FPU);
3493 gen_set_access_type(ctx, ACCESS_FLOAT);
3494 EA = tcg_temp_new();
3495 gen_addr_imm_index(ctx, EA, 0); \
3496 if (unlikely(ctx->le_mode)) {
3497 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3498 tcg_gen_addi_tl(EA, EA, 8);
3499 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3501 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3502 tcg_gen_addi_tl(EA, EA, 8);
3503 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3509 static void gen_stfdpx(DisasContext *ctx)
3512 if (unlikely(!ctx->fpu_enabled)) {
3513 gen_exception(ctx, POWERPC_EXCP_FPU);
3516 gen_set_access_type(ctx, ACCESS_FLOAT);
3517 EA = tcg_temp_new();
3518 gen_addr_reg_index(ctx, EA);
3519 if (unlikely(ctx->le_mode)) {
3520 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3521 tcg_gen_addi_tl(EA, EA, 8);
3522 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3524 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3525 tcg_gen_addi_tl(EA, EA, 8);
3526 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3532 static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3534 TCGv t0 = tcg_temp_new();
3535 tcg_gen_trunc_i64_tl(t0, arg1),
3536 gen_qemu_st32(ctx, t0, arg2);
3540 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
3542 static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3544 #if defined(TARGET_PPC64)
3546 tcg_gen_movi_tl(cpu_cfar, nip);
3551 static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
3553 TranslationBlock *tb;
3555 if (NARROW_MODE(ctx)) {
3556 dest = (uint32_t) dest;
3558 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
3559 likely(!ctx->singlestep_enabled)) {
3561 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3562 tcg_gen_exit_tb((uintptr_t)tb + n);
3564 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3565 if (unlikely(ctx->singlestep_enabled)) {
3566 if ((ctx->singlestep_enabled &
3567 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
3568 (ctx->exception == POWERPC_EXCP_BRANCH ||
3569 ctx->exception == POWERPC_EXCP_TRACE)) {
3570 target_ulong tmp = ctx->nip;
3572 gen_exception(ctx, POWERPC_EXCP_TRACE);
3575 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
3576 gen_debug_exception(ctx);
3583 static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
3585 if (NARROW_MODE(ctx)) {
3586 nip = (uint32_t)nip;
3588 tcg_gen_movi_tl(cpu_lr, nip);
3592 static void gen_b(DisasContext *ctx)
3594 target_ulong li, target;
3596 ctx->exception = POWERPC_EXCP_BRANCH;
3597 /* sign extend LI */
3598 li = LI(ctx->opcode);
3599 li = (li ^ 0x02000000) - 0x02000000;
3600 if (likely(AA(ctx->opcode) == 0)) {
3601 target = ctx->nip + li - 4;
3605 if (LK(ctx->opcode)) {
3606 gen_setlr(ctx, ctx->nip);
3608 gen_update_cfar(ctx, ctx->nip);
3609 gen_goto_tb(ctx, 0, target);
3616 static inline void gen_bcond(DisasContext *ctx, int type)
3618 uint32_t bo = BO(ctx->opcode);
3622 ctx->exception = POWERPC_EXCP_BRANCH;
3623 if (type == BCOND_LR || type == BCOND_CTR) {
3624 target = tcg_temp_local_new();
3625 if (type == BCOND_CTR)
3626 tcg_gen_mov_tl(target, cpu_ctr);
3628 tcg_gen_mov_tl(target, cpu_lr);
3630 TCGV_UNUSED(target);
3632 if (LK(ctx->opcode))
3633 gen_setlr(ctx, ctx->nip);
3634 l1 = gen_new_label();
3635 if ((bo & 0x4) == 0) {
3636 /* Decrement and test CTR */
3637 TCGv temp = tcg_temp_new();
3638 if (unlikely(type == BCOND_CTR)) {
3639 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3642 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3643 if (NARROW_MODE(ctx)) {
3644 tcg_gen_ext32u_tl(temp, cpu_ctr);
3646 tcg_gen_mov_tl(temp, cpu_ctr);
3649 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3651 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3653 tcg_temp_free(temp);
3655 if ((bo & 0x10) == 0) {
3657 uint32_t bi = BI(ctx->opcode);
3658 uint32_t mask = 1 << (3 - (bi & 0x03));
3659 TCGv_i32 temp = tcg_temp_new_i32();
3662 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3663 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3665 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3666 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
3668 tcg_temp_free_i32(temp);
3670 gen_update_cfar(ctx, ctx->nip);
3671 if (type == BCOND_IM) {
3672 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3673 if (likely(AA(ctx->opcode) == 0)) {
3674 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3676 gen_goto_tb(ctx, 0, li);
3679 gen_goto_tb(ctx, 1, ctx->nip);
3681 if (NARROW_MODE(ctx)) {
3682 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3684 tcg_gen_andi_tl(cpu_nip, target, ~3);
3688 gen_update_nip(ctx, ctx->nip);
3693 static void gen_bc(DisasContext *ctx)
3695 gen_bcond(ctx, BCOND_IM);
3698 static void gen_bcctr(DisasContext *ctx)
3700 gen_bcond(ctx, BCOND_CTR);
3703 static void gen_bclr(DisasContext *ctx)
3705 gen_bcond(ctx, BCOND_LR);
3708 /*** Condition register logical ***/
3709 #define GEN_CRLOGIC(name, tcg_op, opc) \
3710 static void glue(gen_, name)(DisasContext *ctx) \
3715 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3716 t0 = tcg_temp_new_i32(); \
3718 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3720 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3722 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3723 t1 = tcg_temp_new_i32(); \
3724 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3726 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3728 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3730 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3731 tcg_op(t0, t0, t1); \
3732 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3733 tcg_gen_andi_i32(t0, t0, bitmask); \
3734 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3735 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3736 tcg_temp_free_i32(t0); \
3737 tcg_temp_free_i32(t1); \
3741 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
3743 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
3745 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
3747 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
3749 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
3751 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
3753 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
3755 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
3758 static void gen_mcrf(DisasContext *ctx)
3760 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
3763 /*** System linkage ***/
3765 /* rfi (mem_idx only) */
3766 static void gen_rfi(DisasContext *ctx)
3768 #if defined(CONFIG_USER_ONLY)
3769 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3771 /* Restore CPU state */
3772 if (unlikely(!ctx->mem_idx)) {
3773 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3776 gen_update_cfar(ctx, ctx->nip);
3777 gen_helper_rfi(cpu_env);
3778 gen_sync_exception(ctx);
3782 #if defined(TARGET_PPC64)
3783 static void gen_rfid(DisasContext *ctx)
3785 #if defined(CONFIG_USER_ONLY)
3786 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3788 /* Restore CPU state */
3789 if (unlikely(!ctx->mem_idx)) {
3790 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3793 gen_update_cfar(ctx, ctx->nip);
3794 gen_helper_rfid(cpu_env);
3795 gen_sync_exception(ctx);
3799 static void gen_hrfid(DisasContext *ctx)
3801 #if defined(CONFIG_USER_ONLY)
3802 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3804 /* Restore CPU state */
3805 if (unlikely(ctx->mem_idx <= 1)) {
3806 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3809 gen_helper_hrfid(cpu_env);
3810 gen_sync_exception(ctx);
3816 #if defined(CONFIG_USER_ONLY)
3817 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3819 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3821 static void gen_sc(DisasContext *ctx)
3825 lev = (ctx->opcode >> 5) & 0x7F;
3826 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
3832 static void gen_tw(DisasContext *ctx)
3834 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
3835 /* Update the nip since this might generate a trap exception */
3836 gen_update_nip(ctx, ctx->nip);
3837 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
3839 tcg_temp_free_i32(t0);
3843 static void gen_twi(DisasContext *ctx)
3845 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3846 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
3847 /* Update the nip since this might generate a trap exception */
3848 gen_update_nip(ctx, ctx->nip);
3849 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
3851 tcg_temp_free_i32(t1);
3854 #if defined(TARGET_PPC64)
3856 static void gen_td(DisasContext *ctx)
3858 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
3859 /* Update the nip since this might generate a trap exception */
3860 gen_update_nip(ctx, ctx->nip);
3861 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
3863 tcg_temp_free_i32(t0);
3867 static void gen_tdi(DisasContext *ctx)
3869 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3870 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
3871 /* Update the nip since this might generate a trap exception */
3872 gen_update_nip(ctx, ctx->nip);
3873 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
3875 tcg_temp_free_i32(t1);
3879 /*** Processor control ***/
3881 static void gen_read_xer(TCGv dst)
3883 TCGv t0 = tcg_temp_new();
3884 TCGv t1 = tcg_temp_new();
3885 TCGv t2 = tcg_temp_new();
3886 tcg_gen_mov_tl(dst, cpu_xer);
3887 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
3888 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
3889 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
3890 tcg_gen_or_tl(t0, t0, t1);
3891 tcg_gen_or_tl(dst, dst, t2);
3892 tcg_gen_or_tl(dst, dst, t0);
3898 static void gen_write_xer(TCGv src)
3900 tcg_gen_andi_tl(cpu_xer, src,
3901 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
3902 tcg_gen_shri_tl(cpu_so, src, XER_SO);
3903 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
3904 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
3905 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
3906 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
3907 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
3911 static void gen_mcrxr(DisasContext *ctx)
3913 TCGv_i32 t0 = tcg_temp_new_i32();
3914 TCGv_i32 t1 = tcg_temp_new_i32();
3915 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
3917 tcg_gen_trunc_tl_i32(t0, cpu_so);
3918 tcg_gen_trunc_tl_i32(t1, cpu_ov);
3919 tcg_gen_trunc_tl_i32(dst, cpu_ca);
3920 tcg_gen_shri_i32(t0, t0, 2);
3921 tcg_gen_shri_i32(t1, t1, 1);
3922 tcg_gen_or_i32(dst, dst, t0);
3923 tcg_gen_or_i32(dst, dst, t1);
3924 tcg_temp_free_i32(t0);
3925 tcg_temp_free_i32(t1);
3927 tcg_gen_movi_tl(cpu_so, 0);
3928 tcg_gen_movi_tl(cpu_ov, 0);
3929 tcg_gen_movi_tl(cpu_ca, 0);
3933 static void gen_mfcr(DisasContext *ctx)
3937 if (likely(ctx->opcode & 0x00100000)) {
3938 crm = CRM(ctx->opcode);
3939 if (likely(crm && ((crm & (crm - 1)) == 0))) {
3941 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
3942 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
3943 cpu_gpr[rD(ctx->opcode)], crn * 4);
3946 TCGv_i32 t0 = tcg_temp_new_i32();
3947 tcg_gen_mov_i32(t0, cpu_crf[0]);
3948 tcg_gen_shli_i32(t0, t0, 4);
3949 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
3950 tcg_gen_shli_i32(t0, t0, 4);
3951 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
3952 tcg_gen_shli_i32(t0, t0, 4);
3953 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
3954 tcg_gen_shli_i32(t0, t0, 4);
3955 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
3956 tcg_gen_shli_i32(t0, t0, 4);
3957 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
3958 tcg_gen_shli_i32(t0, t0, 4);
3959 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
3960 tcg_gen_shli_i32(t0, t0, 4);
3961 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
3962 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
3963 tcg_temp_free_i32(t0);
3968 static void gen_mfmsr(DisasContext *ctx)
3970 #if defined(CONFIG_USER_ONLY)
3971 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3973 if (unlikely(!ctx->mem_idx)) {
3974 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3977 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
3981 static void spr_noaccess(void *opaque, int gprn, int sprn)
3984 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3985 printf("ERROR: try to access SPR %d !\n", sprn);
3988 #define SPR_NOACCESS (&spr_noaccess)
3991 static inline void gen_op_mfspr(DisasContext *ctx)
3993 void (*read_cb)(void *opaque, int gprn, int sprn);
3994 uint32_t sprn = SPR(ctx->opcode);
3996 #if !defined(CONFIG_USER_ONLY)
3997 if (ctx->mem_idx == 2)
3998 read_cb = ctx->spr_cb[sprn].hea_read;
3999 else if (ctx->mem_idx)
4000 read_cb = ctx->spr_cb[sprn].oea_read;
4003 read_cb = ctx->spr_cb[sprn].uea_read;
4004 if (likely(read_cb != NULL)) {
4005 if (likely(read_cb != SPR_NOACCESS)) {
4006 (*read_cb)(ctx, rD(ctx->opcode), sprn);
4008 /* Privilege exception */
4009 /* This is a hack to avoid warnings when running Linux:
4010 * this OS breaks the PowerPC virtualisation model,
4011 * allowing userland application to read the PVR
4013 if (sprn != SPR_PVR) {
4014 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4015 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4016 printf("Trying to read privileged spr %d (0x%03x) at "
4017 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4019 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4023 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4024 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4025 printf("Trying to read invalid spr %d (0x%03x) at "
4026 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4027 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4031 static void gen_mfspr(DisasContext *ctx)
4037 static void gen_mftb(DisasContext *ctx)
4043 static void gen_mtcrf(DisasContext *ctx)
4047 crm = CRM(ctx->opcode);
4048 if (likely((ctx->opcode & 0x00100000))) {
4049 if (crm && ((crm & (crm - 1)) == 0)) {
4050 TCGv_i32 temp = tcg_temp_new_i32();
4052 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4053 tcg_gen_shri_i32(temp, temp, crn * 4);
4054 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
4055 tcg_temp_free_i32(temp);
4058 TCGv_i32 temp = tcg_temp_new_i32();
4059 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4060 for (crn = 0 ; crn < 8 ; crn++) {
4061 if (crm & (1 << crn)) {
4062 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4063 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4066 tcg_temp_free_i32(temp);
4071 #if defined(TARGET_PPC64)
4072 static void gen_mtmsrd(DisasContext *ctx)
4074 #if defined(CONFIG_USER_ONLY)
4075 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4077 if (unlikely(!ctx->mem_idx)) {
4078 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4081 if (ctx->opcode & 0x00010000) {
4082 /* Special form that does not need any synchronisation */
4083 TCGv t0 = tcg_temp_new();
4084 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4085 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4086 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4089 /* XXX: we need to update nip before the store
4090 * if we enter power saving mode, we will exit the loop
4091 * directly from ppc_store_msr
4093 gen_update_nip(ctx, ctx->nip);
4094 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
4095 /* Must stop the translation as machine state (may have) changed */
4096 /* Note that mtmsr is not always defined as context-synchronizing */
4097 gen_stop_exception(ctx);
4103 static void gen_mtmsr(DisasContext *ctx)
4105 #if defined(CONFIG_USER_ONLY)
4106 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4108 if (unlikely(!ctx->mem_idx)) {
4109 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4112 if (ctx->opcode & 0x00010000) {
4113 /* Special form that does not need any synchronisation */
4114 TCGv t0 = tcg_temp_new();
4115 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4116 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4117 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4120 TCGv msr = tcg_temp_new();
4122 /* XXX: we need to update nip before the store
4123 * if we enter power saving mode, we will exit the loop
4124 * directly from ppc_store_msr
4126 gen_update_nip(ctx, ctx->nip);
4127 #if defined(TARGET_PPC64)
4128 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4130 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
4132 gen_helper_store_msr(cpu_env, msr);
4133 /* Must stop the translation as machine state (may have) changed */
4134 /* Note that mtmsr is not always defined as context-synchronizing */
4135 gen_stop_exception(ctx);
4141 static void gen_mtspr(DisasContext *ctx)
4143 void (*write_cb)(void *opaque, int sprn, int gprn);
4144 uint32_t sprn = SPR(ctx->opcode);
4146 #if !defined(CONFIG_USER_ONLY)
4147 if (ctx->mem_idx == 2)
4148 write_cb = ctx->spr_cb[sprn].hea_write;
4149 else if (ctx->mem_idx)
4150 write_cb = ctx->spr_cb[sprn].oea_write;
4153 write_cb = ctx->spr_cb[sprn].uea_write;
4154 if (likely(write_cb != NULL)) {
4155 if (likely(write_cb != SPR_NOACCESS)) {
4156 (*write_cb)(ctx, sprn, rS(ctx->opcode));
4158 /* Privilege exception */
4159 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4160 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4161 printf("Trying to write privileged spr %d (0x%03x) at "
4162 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4163 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4167 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4168 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4169 printf("Trying to write invalid spr %d (0x%03x) at "
4170 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4171 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
4175 /*** Cache management ***/
4178 static void gen_dcbf(DisasContext *ctx)
4180 /* XXX: specification says this is treated as a load by the MMU */
4182 gen_set_access_type(ctx, ACCESS_CACHE);
4183 t0 = tcg_temp_new();
4184 gen_addr_reg_index(ctx, t0);
4185 gen_qemu_ld8u(ctx, t0, t0);
4189 /* dcbi (Supervisor only) */
4190 static void gen_dcbi(DisasContext *ctx)
4192 #if defined(CONFIG_USER_ONLY)
4193 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4196 if (unlikely(!ctx->mem_idx)) {
4197 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4200 EA = tcg_temp_new();
4201 gen_set_access_type(ctx, ACCESS_CACHE);
4202 gen_addr_reg_index(ctx, EA);
4203 val = tcg_temp_new();
4204 /* XXX: specification says this should be treated as a store by the MMU */
4205 gen_qemu_ld8u(ctx, val, EA);
4206 gen_qemu_st8(ctx, val, EA);
4213 static void gen_dcbst(DisasContext *ctx)
4215 /* XXX: specification say this is treated as a load by the MMU */
4217 gen_set_access_type(ctx, ACCESS_CACHE);
4218 t0 = tcg_temp_new();
4219 gen_addr_reg_index(ctx, t0);
4220 gen_qemu_ld8u(ctx, t0, t0);
4225 static void gen_dcbt(DisasContext *ctx)
4227 /* interpreted as no-op */
4228 /* XXX: specification say this is treated as a load by the MMU
4229 * but does not generate any exception
4234 static void gen_dcbtst(DisasContext *ctx)
4236 /* interpreted as no-op */
4237 /* XXX: specification say this is treated as a load by the MMU
4238 * but does not generate any exception
4243 static void gen_dcbz(DisasContext *ctx)
4246 TCGv_i32 tcgv_is_dcbzl;
4247 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
4249 gen_set_access_type(ctx, ACCESS_CACHE);
4250 /* NIP cannot be restored if the memory exception comes from an helper */
4251 gen_update_nip(ctx, ctx->nip - 4);
4252 tcgv_addr = tcg_temp_new();
4253 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4255 gen_addr_reg_index(ctx, tcgv_addr);
4256 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4258 tcg_temp_free(tcgv_addr);
4259 tcg_temp_free_i32(tcgv_is_dcbzl);
4263 static void gen_dst(DisasContext *ctx)
4265 if (rA(ctx->opcode) == 0) {
4266 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4268 /* interpreted as no-op */
4273 static void gen_dstst(DisasContext *ctx)
4275 if (rA(ctx->opcode) == 0) {
4276 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4278 /* interpreted as no-op */
4284 static void gen_dss(DisasContext *ctx)
4286 /* interpreted as no-op */
4290 static void gen_icbi(DisasContext *ctx)
4293 gen_set_access_type(ctx, ACCESS_CACHE);
4294 /* NIP cannot be restored if the memory exception comes from an helper */
4295 gen_update_nip(ctx, ctx->nip - 4);
4296 t0 = tcg_temp_new();
4297 gen_addr_reg_index(ctx, t0);
4298 gen_helper_icbi(cpu_env, t0);
4304 static void gen_dcba(DisasContext *ctx)
4306 /* interpreted as no-op */
4307 /* XXX: specification say this is treated as a store by the MMU
4308 * but does not generate any exception
4312 /*** Segment register manipulation ***/
4313 /* Supervisor only: */
4316 static void gen_mfsr(DisasContext *ctx)
4318 #if defined(CONFIG_USER_ONLY)
4319 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4322 if (unlikely(!ctx->mem_idx)) {
4323 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4326 t0 = tcg_const_tl(SR(ctx->opcode));
4327 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4333 static void gen_mfsrin(DisasContext *ctx)
4335 #if defined(CONFIG_USER_ONLY)
4336 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4339 if (unlikely(!ctx->mem_idx)) {
4340 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4343 t0 = tcg_temp_new();
4344 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4345 tcg_gen_andi_tl(t0, t0, 0xF);
4346 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4352 static void gen_mtsr(DisasContext *ctx)
4354 #if defined(CONFIG_USER_ONLY)
4355 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4358 if (unlikely(!ctx->mem_idx)) {
4359 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4362 t0 = tcg_const_tl(SR(ctx->opcode));
4363 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4369 static void gen_mtsrin(DisasContext *ctx)
4371 #if defined(CONFIG_USER_ONLY)
4372 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4375 if (unlikely(!ctx->mem_idx)) {
4376 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4379 t0 = tcg_temp_new();
4380 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4381 tcg_gen_andi_tl(t0, t0, 0xF);
4382 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
4387 #if defined(TARGET_PPC64)
4388 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4391 static void gen_mfsr_64b(DisasContext *ctx)
4393 #if defined(CONFIG_USER_ONLY)
4394 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4397 if (unlikely(!ctx->mem_idx)) {
4398 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4401 t0 = tcg_const_tl(SR(ctx->opcode));
4402 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4408 static void gen_mfsrin_64b(DisasContext *ctx)
4410 #if defined(CONFIG_USER_ONLY)
4411 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4414 if (unlikely(!ctx->mem_idx)) {
4415 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4418 t0 = tcg_temp_new();
4419 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4420 tcg_gen_andi_tl(t0, t0, 0xF);
4421 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4427 static void gen_mtsr_64b(DisasContext *ctx)
4429 #if defined(CONFIG_USER_ONLY)
4430 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4433 if (unlikely(!ctx->mem_idx)) {
4434 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4437 t0 = tcg_const_tl(SR(ctx->opcode));
4438 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4444 static void gen_mtsrin_64b(DisasContext *ctx)
4446 #if defined(CONFIG_USER_ONLY)
4447 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4450 if (unlikely(!ctx->mem_idx)) {
4451 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4454 t0 = tcg_temp_new();
4455 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4456 tcg_gen_andi_tl(t0, t0, 0xF);
4457 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
4463 static void gen_slbmte(DisasContext *ctx)
4465 #if defined(CONFIG_USER_ONLY)
4466 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4468 if (unlikely(!ctx->mem_idx)) {
4469 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4472 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4473 cpu_gpr[rS(ctx->opcode)]);
4477 static void gen_slbmfee(DisasContext *ctx)
4479 #if defined(CONFIG_USER_ONLY)
4480 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4482 if (unlikely(!ctx->mem_idx)) {
4483 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4486 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
4487 cpu_gpr[rB(ctx->opcode)]);
4491 static void gen_slbmfev(DisasContext *ctx)
4493 #if defined(CONFIG_USER_ONLY)
4494 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4496 if (unlikely(!ctx->mem_idx)) {
4497 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4500 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
4501 cpu_gpr[rB(ctx->opcode)]);
4504 #endif /* defined(TARGET_PPC64) */
4506 /*** Lookaside buffer management ***/
4507 /* Optional & mem_idx only: */
4510 static void gen_tlbia(DisasContext *ctx)
4512 #if defined(CONFIG_USER_ONLY)
4513 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4515 if (unlikely(!ctx->mem_idx)) {
4516 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4519 gen_helper_tlbia(cpu_env);
4524 static void gen_tlbiel(DisasContext *ctx)
4526 #if defined(CONFIG_USER_ONLY)
4527 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4529 if (unlikely(!ctx->mem_idx)) {
4530 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4533 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4538 static void gen_tlbie(DisasContext *ctx)
4540 #if defined(CONFIG_USER_ONLY)
4541 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4543 if (unlikely(!ctx->mem_idx)) {
4544 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4547 if (NARROW_MODE(ctx)) {
4548 TCGv t0 = tcg_temp_new();
4549 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
4550 gen_helper_tlbie(cpu_env, t0);
4553 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4559 static void gen_tlbsync(DisasContext *ctx)
4561 #if defined(CONFIG_USER_ONLY)
4562 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4564 if (unlikely(!ctx->mem_idx)) {
4565 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4568 /* This has no effect: it should ensure that all previous
4569 * tlbie have completed
4571 gen_stop_exception(ctx);
4575 #if defined(TARGET_PPC64)
4577 static void gen_slbia(DisasContext *ctx)
4579 #if defined(CONFIG_USER_ONLY)
4580 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4582 if (unlikely(!ctx->mem_idx)) {
4583 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4586 gen_helper_slbia(cpu_env);
4591 static void gen_slbie(DisasContext *ctx)
4593 #if defined(CONFIG_USER_ONLY)
4594 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4596 if (unlikely(!ctx->mem_idx)) {
4597 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4600 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
4605 /*** External control ***/
4609 static void gen_eciwx(DisasContext *ctx)
4612 /* Should check EAR[E] ! */
4613 gen_set_access_type(ctx, ACCESS_EXT);
4614 t0 = tcg_temp_new();
4615 gen_addr_reg_index(ctx, t0);
4616 gen_check_align(ctx, t0, 0x03);
4617 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
4622 static void gen_ecowx(DisasContext *ctx)
4625 /* Should check EAR[E] ! */
4626 gen_set_access_type(ctx, ACCESS_EXT);
4627 t0 = tcg_temp_new();
4628 gen_addr_reg_index(ctx, t0);
4629 gen_check_align(ctx, t0, 0x03);
4630 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
4634 /* PowerPC 601 specific instructions */
4637 static void gen_abs(DisasContext *ctx)
4639 int l1 = gen_new_label();
4640 int l2 = gen_new_label();
4641 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4642 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4645 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4647 if (unlikely(Rc(ctx->opcode) != 0))
4648 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4652 static void gen_abso(DisasContext *ctx)
4654 int l1 = gen_new_label();
4655 int l2 = gen_new_label();
4656 int l3 = gen_new_label();
4657 /* Start with XER OV disabled, the most likely case */
4658 tcg_gen_movi_tl(cpu_ov, 0);
4659 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4660 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
4661 tcg_gen_movi_tl(cpu_ov, 1);
4662 tcg_gen_movi_tl(cpu_so, 1);
4665 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4668 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4670 if (unlikely(Rc(ctx->opcode) != 0))
4671 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4675 static void gen_clcs(DisasContext *ctx)
4677 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
4678 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
4679 tcg_temp_free_i32(t0);
4680 /* Rc=1 sets CR0 to an undefined state */
4684 static void gen_div(DisasContext *ctx)
4686 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4687 cpu_gpr[rB(ctx->opcode)]);
4688 if (unlikely(Rc(ctx->opcode) != 0))
4689 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4693 static void gen_divo(DisasContext *ctx)
4695 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4696 cpu_gpr[rB(ctx->opcode)]);
4697 if (unlikely(Rc(ctx->opcode) != 0))
4698 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4702 static void gen_divs(DisasContext *ctx)
4704 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4705 cpu_gpr[rB(ctx->opcode)]);
4706 if (unlikely(Rc(ctx->opcode) != 0))
4707 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4710 /* divso - divso. */
4711 static void gen_divso(DisasContext *ctx)
4713 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4714 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4715 if (unlikely(Rc(ctx->opcode) != 0))
4716 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4720 static void gen_doz(DisasContext *ctx)
4722 int l1 = gen_new_label();
4723 int l2 = gen_new_label();
4724 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4725 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4728 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4730 if (unlikely(Rc(ctx->opcode) != 0))
4731 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4735 static void gen_dozo(DisasContext *ctx)
4737 int l1 = gen_new_label();
4738 int l2 = gen_new_label();
4739 TCGv t0 = tcg_temp_new();
4740 TCGv t1 = tcg_temp_new();
4741 TCGv t2 = tcg_temp_new();
4742 /* Start with XER OV disabled, the most likely case */
4743 tcg_gen_movi_tl(cpu_ov, 0);
4744 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4745 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4746 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4747 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4748 tcg_gen_andc_tl(t1, t1, t2);
4749 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4750 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
4751 tcg_gen_movi_tl(cpu_ov, 1);
4752 tcg_gen_movi_tl(cpu_so, 1);
4755 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4760 if (unlikely(Rc(ctx->opcode) != 0))
4761 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4765 static void gen_dozi(DisasContext *ctx)
4767 target_long simm = SIMM(ctx->opcode);
4768 int l1 = gen_new_label();
4769 int l2 = gen_new_label();
4770 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
4771 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
4774 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4776 if (unlikely(Rc(ctx->opcode) != 0))
4777 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4780 /* lscbx - lscbx. */
4781 static void gen_lscbx(DisasContext *ctx)
4783 TCGv t0 = tcg_temp_new();
4784 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
4785 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
4786 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
4788 gen_addr_reg_index(ctx, t0);
4789 /* NIP cannot be restored if the memory exception comes from an helper */
4790 gen_update_nip(ctx, ctx->nip - 4);
4791 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
4792 tcg_temp_free_i32(t1);
4793 tcg_temp_free_i32(t2);
4794 tcg_temp_free_i32(t3);
4795 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
4796 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
4797 if (unlikely(Rc(ctx->opcode) != 0))
4798 gen_set_Rc0(ctx, t0);
4802 /* maskg - maskg. */
4803 static void gen_maskg(DisasContext *ctx)
4805 int l1 = gen_new_label();
4806 TCGv t0 = tcg_temp_new();
4807 TCGv t1 = tcg_temp_new();
4808 TCGv t2 = tcg_temp_new();
4809 TCGv t3 = tcg_temp_new();
4810 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
4811 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4812 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
4813 tcg_gen_addi_tl(t2, t0, 1);
4814 tcg_gen_shr_tl(t2, t3, t2);
4815 tcg_gen_shr_tl(t3, t3, t1);
4816 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
4817 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
4818 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4824 if (unlikely(Rc(ctx->opcode) != 0))
4825 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4828 /* maskir - maskir. */
4829 static void gen_maskir(DisasContext *ctx)
4831 TCGv t0 = tcg_temp_new();
4832 TCGv t1 = tcg_temp_new();
4833 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4834 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4835 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4838 if (unlikely(Rc(ctx->opcode) != 0))
4839 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4843 static void gen_mul(DisasContext *ctx)
4845 TCGv_i64 t0 = tcg_temp_new_i64();
4846 TCGv_i64 t1 = tcg_temp_new_i64();
4847 TCGv t2 = tcg_temp_new();
4848 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4849 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4850 tcg_gen_mul_i64(t0, t0, t1);
4851 tcg_gen_trunc_i64_tl(t2, t0);
4852 gen_store_spr(SPR_MQ, t2);
4853 tcg_gen_shri_i64(t1, t0, 32);
4854 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4855 tcg_temp_free_i64(t0);
4856 tcg_temp_free_i64(t1);
4858 if (unlikely(Rc(ctx->opcode) != 0))
4859 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4863 static void gen_mulo(DisasContext *ctx)
4865 int l1 = gen_new_label();
4866 TCGv_i64 t0 = tcg_temp_new_i64();
4867 TCGv_i64 t1 = tcg_temp_new_i64();
4868 TCGv t2 = tcg_temp_new();
4869 /* Start with XER OV disabled, the most likely case */
4870 tcg_gen_movi_tl(cpu_ov, 0);
4871 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4872 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4873 tcg_gen_mul_i64(t0, t0, t1);
4874 tcg_gen_trunc_i64_tl(t2, t0);
4875 gen_store_spr(SPR_MQ, t2);
4876 tcg_gen_shri_i64(t1, t0, 32);
4877 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4878 tcg_gen_ext32s_i64(t1, t0);
4879 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
4880 tcg_gen_movi_tl(cpu_ov, 1);
4881 tcg_gen_movi_tl(cpu_so, 1);
4883 tcg_temp_free_i64(t0);
4884 tcg_temp_free_i64(t1);
4886 if (unlikely(Rc(ctx->opcode) != 0))
4887 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4891 static void gen_nabs(DisasContext *ctx)
4893 int l1 = gen_new_label();
4894 int l2 = gen_new_label();
4895 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4896 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4899 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4901 if (unlikely(Rc(ctx->opcode) != 0))
4902 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4905 /* nabso - nabso. */
4906 static void gen_nabso(DisasContext *ctx)
4908 int l1 = gen_new_label();
4909 int l2 = gen_new_label();
4910 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4911 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4914 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4916 /* nabs never overflows */
4917 tcg_gen_movi_tl(cpu_ov, 0);
4918 if (unlikely(Rc(ctx->opcode) != 0))
4919 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4923 static void gen_rlmi(DisasContext *ctx)
4925 uint32_t mb = MB(ctx->opcode);
4926 uint32_t me = ME(ctx->opcode);
4927 TCGv t0 = tcg_temp_new();
4928 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4929 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4930 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
4931 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
4932 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
4934 if (unlikely(Rc(ctx->opcode) != 0))
4935 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4939 static void gen_rrib(DisasContext *ctx)
4941 TCGv t0 = tcg_temp_new();
4942 TCGv t1 = tcg_temp_new();
4943 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4944 tcg_gen_movi_tl(t1, 0x80000000);
4945 tcg_gen_shr_tl(t1, t1, t0);
4946 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4947 tcg_gen_and_tl(t0, t0, t1);
4948 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
4949 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4952 if (unlikely(Rc(ctx->opcode) != 0))
4953 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4957 static void gen_sle(DisasContext *ctx)
4959 TCGv t0 = tcg_temp_new();
4960 TCGv t1 = tcg_temp_new();
4961 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4962 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4963 tcg_gen_subfi_tl(t1, 32, t1);
4964 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4965 tcg_gen_or_tl(t1, t0, t1);
4966 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4967 gen_store_spr(SPR_MQ, t1);
4970 if (unlikely(Rc(ctx->opcode) != 0))
4971 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4975 static void gen_sleq(DisasContext *ctx)
4977 TCGv t0 = tcg_temp_new();
4978 TCGv t1 = tcg_temp_new();
4979 TCGv t2 = tcg_temp_new();
4980 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4981 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
4982 tcg_gen_shl_tl(t2, t2, t0);
4983 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4984 gen_load_spr(t1, SPR_MQ);
4985 gen_store_spr(SPR_MQ, t0);
4986 tcg_gen_and_tl(t0, t0, t2);
4987 tcg_gen_andc_tl(t1, t1, t2);
4988 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4992 if (unlikely(Rc(ctx->opcode) != 0))
4993 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4997 static void gen_sliq(DisasContext *ctx)
4999 int sh = SH(ctx->opcode);
5000 TCGv t0 = tcg_temp_new();
5001 TCGv t1 = tcg_temp_new();
5002 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5003 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5004 tcg_gen_or_tl(t1, t0, t1);
5005 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5006 gen_store_spr(SPR_MQ, t1);
5009 if (unlikely(Rc(ctx->opcode) != 0))
5010 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5013 /* slliq - slliq. */
5014 static void gen_slliq(DisasContext *ctx)
5016 int sh = SH(ctx->opcode);
5017 TCGv t0 = tcg_temp_new();
5018 TCGv t1 = tcg_temp_new();
5019 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5020 gen_load_spr(t1, SPR_MQ);
5021 gen_store_spr(SPR_MQ, t0);
5022 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5023 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5024 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5027 if (unlikely(Rc(ctx->opcode) != 0))
5028 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5032 static void gen_sllq(DisasContext *ctx)
5034 int l1 = gen_new_label();
5035 int l2 = gen_new_label();
5036 TCGv t0 = tcg_temp_local_new();
5037 TCGv t1 = tcg_temp_local_new();
5038 TCGv t2 = tcg_temp_local_new();
5039 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5040 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5041 tcg_gen_shl_tl(t1, t1, t2);
5042 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5043 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5044 gen_load_spr(t0, SPR_MQ);
5045 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5048 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5049 gen_load_spr(t2, SPR_MQ);
5050 tcg_gen_andc_tl(t1, t2, t1);
5051 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5056 if (unlikely(Rc(ctx->opcode) != 0))
5057 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5061 static void gen_slq(DisasContext *ctx)
5063 int l1 = gen_new_label();
5064 TCGv t0 = tcg_temp_new();
5065 TCGv t1 = tcg_temp_new();
5066 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5067 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5068 tcg_gen_subfi_tl(t1, 32, t1);
5069 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5070 tcg_gen_or_tl(t1, t0, t1);
5071 gen_store_spr(SPR_MQ, t1);
5072 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5073 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5074 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5075 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5079 if (unlikely(Rc(ctx->opcode) != 0))
5080 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5083 /* sraiq - sraiq. */
5084 static void gen_sraiq(DisasContext *ctx)
5086 int sh = SH(ctx->opcode);
5087 int l1 = gen_new_label();
5088 TCGv t0 = tcg_temp_new();
5089 TCGv t1 = tcg_temp_new();
5090 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5091 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5092 tcg_gen_or_tl(t0, t0, t1);
5093 gen_store_spr(SPR_MQ, t0);
5094 tcg_gen_movi_tl(cpu_ca, 0);
5095 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5096 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
5097 tcg_gen_movi_tl(cpu_ca, 1);
5099 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5102 if (unlikely(Rc(ctx->opcode) != 0))
5103 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5107 static void gen_sraq(DisasContext *ctx)
5109 int l1 = gen_new_label();
5110 int l2 = gen_new_label();
5111 TCGv t0 = tcg_temp_new();
5112 TCGv t1 = tcg_temp_local_new();
5113 TCGv t2 = tcg_temp_local_new();
5114 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5115 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5116 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5117 tcg_gen_subfi_tl(t2, 32, t2);
5118 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5119 tcg_gen_or_tl(t0, t0, t2);
5120 gen_store_spr(SPR_MQ, t0);
5121 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5122 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5123 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5124 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5127 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
5128 tcg_gen_movi_tl(cpu_ca, 0);
5129 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5130 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
5131 tcg_gen_movi_tl(cpu_ca, 1);
5135 if (unlikely(Rc(ctx->opcode) != 0))
5136 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5140 static void gen_sre(DisasContext *ctx)
5142 TCGv t0 = tcg_temp_new();
5143 TCGv t1 = tcg_temp_new();
5144 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5145 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5146 tcg_gen_subfi_tl(t1, 32, t1);
5147 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5148 tcg_gen_or_tl(t1, t0, t1);
5149 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5150 gen_store_spr(SPR_MQ, t1);
5153 if (unlikely(Rc(ctx->opcode) != 0))
5154 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5158 static void gen_srea(DisasContext *ctx)
5160 TCGv t0 = tcg_temp_new();
5161 TCGv t1 = tcg_temp_new();
5162 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5163 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5164 gen_store_spr(SPR_MQ, t0);
5165 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5168 if (unlikely(Rc(ctx->opcode) != 0))
5169 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5173 static void gen_sreq(DisasContext *ctx)
5175 TCGv t0 = tcg_temp_new();
5176 TCGv t1 = tcg_temp_new();
5177 TCGv t2 = tcg_temp_new();
5178 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5179 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5180 tcg_gen_shr_tl(t1, t1, t0);
5181 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5182 gen_load_spr(t2, SPR_MQ);
5183 gen_store_spr(SPR_MQ, t0);
5184 tcg_gen_and_tl(t0, t0, t1);
5185 tcg_gen_andc_tl(t2, t2, t1);
5186 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5190 if (unlikely(Rc(ctx->opcode) != 0))
5191 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5195 static void gen_sriq(DisasContext *ctx)
5197 int sh = SH(ctx->opcode);
5198 TCGv t0 = tcg_temp_new();
5199 TCGv t1 = tcg_temp_new();
5200 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5201 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5202 tcg_gen_or_tl(t1, t0, t1);
5203 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5204 gen_store_spr(SPR_MQ, t1);
5207 if (unlikely(Rc(ctx->opcode) != 0))
5208 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5212 static void gen_srliq(DisasContext *ctx)
5214 int sh = SH(ctx->opcode);
5215 TCGv t0 = tcg_temp_new();
5216 TCGv t1 = tcg_temp_new();
5217 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5218 gen_load_spr(t1, SPR_MQ);
5219 gen_store_spr(SPR_MQ, t0);
5220 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5221 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5222 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5225 if (unlikely(Rc(ctx->opcode) != 0))
5226 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5230 static void gen_srlq(DisasContext *ctx)
5232 int l1 = gen_new_label();
5233 int l2 = gen_new_label();
5234 TCGv t0 = tcg_temp_local_new();
5235 TCGv t1 = tcg_temp_local_new();
5236 TCGv t2 = tcg_temp_local_new();
5237 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5238 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5239 tcg_gen_shr_tl(t2, t1, t2);
5240 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5241 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5242 gen_load_spr(t0, SPR_MQ);
5243 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5246 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5247 tcg_gen_and_tl(t0, t0, t2);
5248 gen_load_spr(t1, SPR_MQ);
5249 tcg_gen_andc_tl(t1, t1, t2);
5250 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5255 if (unlikely(Rc(ctx->opcode) != 0))
5256 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5260 static void gen_srq(DisasContext *ctx)
5262 int l1 = gen_new_label();
5263 TCGv t0 = tcg_temp_new();
5264 TCGv t1 = tcg_temp_new();
5265 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5266 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5267 tcg_gen_subfi_tl(t1, 32, t1);
5268 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5269 tcg_gen_or_tl(t1, t0, t1);
5270 gen_store_spr(SPR_MQ, t1);
5271 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5272 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5273 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5274 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5278 if (unlikely(Rc(ctx->opcode) != 0))
5279 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5282 /* PowerPC 602 specific instructions */
5285 static void gen_dsa(DisasContext *ctx)
5288 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5292 static void gen_esa(DisasContext *ctx)
5295 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5299 static void gen_mfrom(DisasContext *ctx)
5301 #if defined(CONFIG_USER_ONLY)
5302 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5304 if (unlikely(!ctx->mem_idx)) {
5305 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5308 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5312 /* 602 - 603 - G2 TLB management */
5315 static void gen_tlbld_6xx(DisasContext *ctx)
5317 #if defined(CONFIG_USER_ONLY)
5318 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5320 if (unlikely(!ctx->mem_idx)) {
5321 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5324 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5329 static void gen_tlbli_6xx(DisasContext *ctx)
5331 #if defined(CONFIG_USER_ONLY)
5332 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5334 if (unlikely(!ctx->mem_idx)) {
5335 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5338 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5342 /* 74xx TLB management */
5345 static void gen_tlbld_74xx(DisasContext *ctx)
5347 #if defined(CONFIG_USER_ONLY)
5348 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5350 if (unlikely(!ctx->mem_idx)) {
5351 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5354 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5359 static void gen_tlbli_74xx(DisasContext *ctx)
5361 #if defined(CONFIG_USER_ONLY)
5362 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5364 if (unlikely(!ctx->mem_idx)) {
5365 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5368 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5372 /* POWER instructions not in PowerPC 601 */
5375 static void gen_clf(DisasContext *ctx)
5377 /* Cache line flush: implemented as no-op */
5381 static void gen_cli(DisasContext *ctx)
5383 /* Cache line invalidate: privileged and treated as no-op */
5384 #if defined(CONFIG_USER_ONLY)
5385 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5387 if (unlikely(!ctx->mem_idx)) {
5388 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5395 static void gen_dclst(DisasContext *ctx)
5397 /* Data cache line store: treated as no-op */
5400 static void gen_mfsri(DisasContext *ctx)
5402 #if defined(CONFIG_USER_ONLY)
5403 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5405 int ra = rA(ctx->opcode);
5406 int rd = rD(ctx->opcode);
5408 if (unlikely(!ctx->mem_idx)) {
5409 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5412 t0 = tcg_temp_new();
5413 gen_addr_reg_index(ctx, t0);
5414 tcg_gen_shri_tl(t0, t0, 28);
5415 tcg_gen_andi_tl(t0, t0, 0xF);
5416 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
5418 if (ra != 0 && ra != rd)
5419 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
5423 static void gen_rac(DisasContext *ctx)
5425 #if defined(CONFIG_USER_ONLY)
5426 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5429 if (unlikely(!ctx->mem_idx)) {
5430 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5433 t0 = tcg_temp_new();
5434 gen_addr_reg_index(ctx, t0);
5435 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
5440 static void gen_rfsvc(DisasContext *ctx)
5442 #if defined(CONFIG_USER_ONLY)
5443 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5445 if (unlikely(!ctx->mem_idx)) {
5446 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5449 gen_helper_rfsvc(cpu_env);
5450 gen_sync_exception(ctx);
5454 /* svc is not implemented for now */
5456 /* POWER2 specific instructions */
5457 /* Quad manipulation (load/store two floats at a time) */
5460 static void gen_lfq(DisasContext *ctx)
5462 int rd = rD(ctx->opcode);
5464 gen_set_access_type(ctx, ACCESS_FLOAT);
5465 t0 = tcg_temp_new();
5466 gen_addr_imm_index(ctx, t0, 0);
5467 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5468 gen_addr_add(ctx, t0, t0, 8);
5469 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5474 static void gen_lfqu(DisasContext *ctx)
5476 int ra = rA(ctx->opcode);
5477 int rd = rD(ctx->opcode);
5479 gen_set_access_type(ctx, ACCESS_FLOAT);
5480 t0 = tcg_temp_new();
5481 t1 = tcg_temp_new();
5482 gen_addr_imm_index(ctx, t0, 0);
5483 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5484 gen_addr_add(ctx, t1, t0, 8);
5485 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5487 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5493 static void gen_lfqux(DisasContext *ctx)
5495 int ra = rA(ctx->opcode);
5496 int rd = rD(ctx->opcode);
5497 gen_set_access_type(ctx, ACCESS_FLOAT);
5499 t0 = tcg_temp_new();
5500 gen_addr_reg_index(ctx, t0);
5501 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5502 t1 = tcg_temp_new();
5503 gen_addr_add(ctx, t1, t0, 8);
5504 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5507 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5512 static void gen_lfqx(DisasContext *ctx)
5514 int rd = rD(ctx->opcode);
5516 gen_set_access_type(ctx, ACCESS_FLOAT);
5517 t0 = tcg_temp_new();
5518 gen_addr_reg_index(ctx, t0);
5519 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5520 gen_addr_add(ctx, t0, t0, 8);
5521 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5526 static void gen_stfq(DisasContext *ctx)
5528 int rd = rD(ctx->opcode);
5530 gen_set_access_type(ctx, ACCESS_FLOAT);
5531 t0 = tcg_temp_new();
5532 gen_addr_imm_index(ctx, t0, 0);
5533 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5534 gen_addr_add(ctx, t0, t0, 8);
5535 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5540 static void gen_stfqu(DisasContext *ctx)
5542 int ra = rA(ctx->opcode);
5543 int rd = rD(ctx->opcode);
5545 gen_set_access_type(ctx, ACCESS_FLOAT);
5546 t0 = tcg_temp_new();
5547 gen_addr_imm_index(ctx, t0, 0);
5548 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5549 t1 = tcg_temp_new();
5550 gen_addr_add(ctx, t1, t0, 8);
5551 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5554 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5559 static void gen_stfqux(DisasContext *ctx)
5561 int ra = rA(ctx->opcode);
5562 int rd = rD(ctx->opcode);
5564 gen_set_access_type(ctx, ACCESS_FLOAT);
5565 t0 = tcg_temp_new();
5566 gen_addr_reg_index(ctx, t0);
5567 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5568 t1 = tcg_temp_new();
5569 gen_addr_add(ctx, t1, t0, 8);
5570 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5573 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5578 static void gen_stfqx(DisasContext *ctx)
5580 int rd = rD(ctx->opcode);
5582 gen_set_access_type(ctx, ACCESS_FLOAT);
5583 t0 = tcg_temp_new();
5584 gen_addr_reg_index(ctx, t0);
5585 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5586 gen_addr_add(ctx, t0, t0, 8);
5587 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5591 /* BookE specific instructions */
5593 /* XXX: not implemented on 440 ? */
5594 static void gen_mfapidi(DisasContext *ctx)
5597 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5600 /* XXX: not implemented on 440 ? */
5601 static void gen_tlbiva(DisasContext *ctx)
5603 #if defined(CONFIG_USER_ONLY)
5604 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5607 if (unlikely(!ctx->mem_idx)) {
5608 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5611 t0 = tcg_temp_new();
5612 gen_addr_reg_index(ctx, t0);
5613 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
5618 /* All 405 MAC instructions are translated here */
5619 static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5620 int ra, int rb, int rt, int Rc)
5624 t0 = tcg_temp_local_new();
5625 t1 = tcg_temp_local_new();
5627 switch (opc3 & 0x0D) {
5629 /* macchw - macchw. - macchwo - macchwo. */
5630 /* macchws - macchws. - macchwso - macchwso. */
5631 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5632 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5633 /* mulchw - mulchw. */
5634 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5635 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5636 tcg_gen_ext16s_tl(t1, t1);
5639 /* macchwu - macchwu. - macchwuo - macchwuo. */
5640 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5641 /* mulchwu - mulchwu. */
5642 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5643 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5644 tcg_gen_ext16u_tl(t1, t1);
5647 /* machhw - machhw. - machhwo - machhwo. */
5648 /* machhws - machhws. - machhwso - machhwso. */
5649 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5650 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5651 /* mulhhw - mulhhw. */
5652 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5653 tcg_gen_ext16s_tl(t0, t0);
5654 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5655 tcg_gen_ext16s_tl(t1, t1);
5658 /* machhwu - machhwu. - machhwuo - machhwuo. */
5659 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5660 /* mulhhwu - mulhhwu. */
5661 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5662 tcg_gen_ext16u_tl(t0, t0);
5663 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5664 tcg_gen_ext16u_tl(t1, t1);
5667 /* maclhw - maclhw. - maclhwo - maclhwo. */
5668 /* maclhws - maclhws. - maclhwso - maclhwso. */
5669 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5670 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5671 /* mullhw - mullhw. */
5672 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5673 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
5676 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5677 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5678 /* mullhwu - mullhwu. */
5679 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5680 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
5684 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5685 tcg_gen_mul_tl(t1, t0, t1);
5687 /* nmultiply-and-accumulate (0x0E) */
5688 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5690 /* multiply-and-accumulate (0x0C) */
5691 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5695 /* Check overflow and/or saturate */
5696 int l1 = gen_new_label();
5699 /* Start with XER OV disabled, the most likely case */
5700 tcg_gen_movi_tl(cpu_ov, 0);
5704 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5705 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5706 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5707 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
5710 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5711 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5715 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
5718 tcg_gen_movi_tl(t0, UINT32_MAX);
5722 /* Check overflow */
5723 tcg_gen_movi_tl(cpu_ov, 1);
5724 tcg_gen_movi_tl(cpu_so, 1);
5727 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5730 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
5734 if (unlikely(Rc) != 0) {
5736 gen_set_Rc0(ctx, cpu_gpr[rt]);
5740 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5741 static void glue(gen_, name)(DisasContext *ctx) \
5743 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5744 rD(ctx->opcode), Rc(ctx->opcode)); \
5747 /* macchw - macchw. */
5748 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
5749 /* macchwo - macchwo. */
5750 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
5751 /* macchws - macchws. */
5752 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
5753 /* macchwso - macchwso. */
5754 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
5755 /* macchwsu - macchwsu. */
5756 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
5757 /* macchwsuo - macchwsuo. */
5758 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
5759 /* macchwu - macchwu. */
5760 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
5761 /* macchwuo - macchwuo. */
5762 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
5763 /* machhw - machhw. */
5764 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
5765 /* machhwo - machhwo. */
5766 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
5767 /* machhws - machhws. */
5768 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
5769 /* machhwso - machhwso. */
5770 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
5771 /* machhwsu - machhwsu. */
5772 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
5773 /* machhwsuo - machhwsuo. */
5774 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
5775 /* machhwu - machhwu. */
5776 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
5777 /* machhwuo - machhwuo. */
5778 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
5779 /* maclhw - maclhw. */
5780 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
5781 /* maclhwo - maclhwo. */
5782 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
5783 /* maclhws - maclhws. */
5784 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
5785 /* maclhwso - maclhwso. */
5786 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
5787 /* maclhwu - maclhwu. */
5788 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
5789 /* maclhwuo - maclhwuo. */
5790 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
5791 /* maclhwsu - maclhwsu. */
5792 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
5793 /* maclhwsuo - maclhwsuo. */
5794 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
5795 /* nmacchw - nmacchw. */
5796 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
5797 /* nmacchwo - nmacchwo. */
5798 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
5799 /* nmacchws - nmacchws. */
5800 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
5801 /* nmacchwso - nmacchwso. */
5802 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
5803 /* nmachhw - nmachhw. */
5804 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
5805 /* nmachhwo - nmachhwo. */
5806 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
5807 /* nmachhws - nmachhws. */
5808 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
5809 /* nmachhwso - nmachhwso. */
5810 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
5811 /* nmaclhw - nmaclhw. */
5812 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
5813 /* nmaclhwo - nmaclhwo. */
5814 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
5815 /* nmaclhws - nmaclhws. */
5816 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
5817 /* nmaclhwso - nmaclhwso. */
5818 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
5820 /* mulchw - mulchw. */
5821 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
5822 /* mulchwu - mulchwu. */
5823 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
5824 /* mulhhw - mulhhw. */
5825 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
5826 /* mulhhwu - mulhhwu. */
5827 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
5828 /* mullhw - mullhw. */
5829 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
5830 /* mullhwu - mullhwu. */
5831 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
5834 static void gen_mfdcr(DisasContext *ctx)
5836 #if defined(CONFIG_USER_ONLY)
5837 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5840 if (unlikely(!ctx->mem_idx)) {
5841 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5844 /* NIP cannot be restored if the memory exception comes from an helper */
5845 gen_update_nip(ctx, ctx->nip - 4);
5846 dcrn = tcg_const_tl(SPR(ctx->opcode));
5847 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
5848 tcg_temp_free(dcrn);
5853 static void gen_mtdcr(DisasContext *ctx)
5855 #if defined(CONFIG_USER_ONLY)
5856 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5859 if (unlikely(!ctx->mem_idx)) {
5860 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5863 /* NIP cannot be restored if the memory exception comes from an helper */
5864 gen_update_nip(ctx, ctx->nip - 4);
5865 dcrn = tcg_const_tl(SPR(ctx->opcode));
5866 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
5867 tcg_temp_free(dcrn);
5872 /* XXX: not implemented on 440 ? */
5873 static void gen_mfdcrx(DisasContext *ctx)
5875 #if defined(CONFIG_USER_ONLY)
5876 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5878 if (unlikely(!ctx->mem_idx)) {
5879 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5882 /* NIP cannot be restored if the memory exception comes from an helper */
5883 gen_update_nip(ctx, ctx->nip - 4);
5884 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
5885 cpu_gpr[rA(ctx->opcode)]);
5886 /* Note: Rc update flag set leads to undefined state of Rc0 */
5891 /* XXX: not implemented on 440 ? */
5892 static void gen_mtdcrx(DisasContext *ctx)
5894 #if defined(CONFIG_USER_ONLY)
5895 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5897 if (unlikely(!ctx->mem_idx)) {
5898 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5901 /* NIP cannot be restored if the memory exception comes from an helper */
5902 gen_update_nip(ctx, ctx->nip - 4);
5903 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
5904 cpu_gpr[rS(ctx->opcode)]);
5905 /* Note: Rc update flag set leads to undefined state of Rc0 */
5909 /* mfdcrux (PPC 460) : user-mode access to DCR */
5910 static void gen_mfdcrux(DisasContext *ctx)
5912 /* NIP cannot be restored if the memory exception comes from an helper */
5913 gen_update_nip(ctx, ctx->nip - 4);
5914 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
5915 cpu_gpr[rA(ctx->opcode)]);
5916 /* Note: Rc update flag set leads to undefined state of Rc0 */
5919 /* mtdcrux (PPC 460) : user-mode access to DCR */
5920 static void gen_mtdcrux(DisasContext *ctx)
5922 /* NIP cannot be restored if the memory exception comes from an helper */
5923 gen_update_nip(ctx, ctx->nip - 4);
5924 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
5925 cpu_gpr[rS(ctx->opcode)]);
5926 /* Note: Rc update flag set leads to undefined state of Rc0 */
5930 static void gen_dccci(DisasContext *ctx)
5932 #if defined(CONFIG_USER_ONLY)
5933 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5935 if (unlikely(!ctx->mem_idx)) {
5936 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5939 /* interpreted as no-op */
5944 static void gen_dcread(DisasContext *ctx)
5946 #if defined(CONFIG_USER_ONLY)
5947 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5950 if (unlikely(!ctx->mem_idx)) {
5951 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5954 gen_set_access_type(ctx, ACCESS_CACHE);
5955 EA = tcg_temp_new();
5956 gen_addr_reg_index(ctx, EA);
5957 val = tcg_temp_new();
5958 gen_qemu_ld32u(ctx, val, EA);
5960 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5966 static void gen_icbt_40x(DisasContext *ctx)
5968 /* interpreted as no-op */
5969 /* XXX: specification say this is treated as a load by the MMU
5970 * but does not generate any exception
5975 static void gen_iccci(DisasContext *ctx)
5977 #if defined(CONFIG_USER_ONLY)
5978 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5980 if (unlikely(!ctx->mem_idx)) {
5981 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5984 /* interpreted as no-op */
5989 static void gen_icread(DisasContext *ctx)
5991 #if defined(CONFIG_USER_ONLY)
5992 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5994 if (unlikely(!ctx->mem_idx)) {
5995 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5998 /* interpreted as no-op */
6002 /* rfci (mem_idx only) */
6003 static void gen_rfci_40x(DisasContext *ctx)
6005 #if defined(CONFIG_USER_ONLY)
6006 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6008 if (unlikely(!ctx->mem_idx)) {
6009 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6012 /* Restore CPU state */
6013 gen_helper_40x_rfci(cpu_env);
6014 gen_sync_exception(ctx);
6018 static void gen_rfci(DisasContext *ctx)
6020 #if defined(CONFIG_USER_ONLY)
6021 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6023 if (unlikely(!ctx->mem_idx)) {
6024 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6027 /* Restore CPU state */
6028 gen_helper_rfci(cpu_env);
6029 gen_sync_exception(ctx);
6033 /* BookE specific */
6035 /* XXX: not implemented on 440 ? */
6036 static void gen_rfdi(DisasContext *ctx)
6038 #if defined(CONFIG_USER_ONLY)
6039 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6041 if (unlikely(!ctx->mem_idx)) {
6042 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6045 /* Restore CPU state */
6046 gen_helper_rfdi(cpu_env);
6047 gen_sync_exception(ctx);
6051 /* XXX: not implemented on 440 ? */
6052 static void gen_rfmci(DisasContext *ctx)
6054 #if defined(CONFIG_USER_ONLY)
6055 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6057 if (unlikely(!ctx->mem_idx)) {
6058 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6061 /* Restore CPU state */
6062 gen_helper_rfmci(cpu_env);
6063 gen_sync_exception(ctx);
6067 /* TLB management - PowerPC 405 implementation */
6070 static void gen_tlbre_40x(DisasContext *ctx)
6072 #if defined(CONFIG_USER_ONLY)
6073 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6075 if (unlikely(!ctx->mem_idx)) {
6076 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6079 switch (rB(ctx->opcode)) {
6081 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6082 cpu_gpr[rA(ctx->opcode)]);
6085 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6086 cpu_gpr[rA(ctx->opcode)]);
6089 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6095 /* tlbsx - tlbsx. */
6096 static void gen_tlbsx_40x(DisasContext *ctx)
6098 #if defined(CONFIG_USER_ONLY)
6099 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6102 if (unlikely(!ctx->mem_idx)) {
6103 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6106 t0 = tcg_temp_new();
6107 gen_addr_reg_index(ctx, t0);
6108 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6110 if (Rc(ctx->opcode)) {
6111 int l1 = gen_new_label();
6112 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
6113 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6114 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6121 static void gen_tlbwe_40x(DisasContext *ctx)
6123 #if defined(CONFIG_USER_ONLY)
6124 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6126 if (unlikely(!ctx->mem_idx)) {
6127 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6130 switch (rB(ctx->opcode)) {
6132 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6133 cpu_gpr[rS(ctx->opcode)]);
6136 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6137 cpu_gpr[rS(ctx->opcode)]);
6140 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6146 /* TLB management - PowerPC 440 implementation */
6149 static void gen_tlbre_440(DisasContext *ctx)
6151 #if defined(CONFIG_USER_ONLY)
6152 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6154 if (unlikely(!ctx->mem_idx)) {
6155 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6158 switch (rB(ctx->opcode)) {
6163 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
6164 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6165 t0, cpu_gpr[rA(ctx->opcode)]);
6166 tcg_temp_free_i32(t0);
6170 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6176 /* tlbsx - tlbsx. */
6177 static void gen_tlbsx_440(DisasContext *ctx)
6179 #if defined(CONFIG_USER_ONLY)
6180 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6183 if (unlikely(!ctx->mem_idx)) {
6184 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6187 t0 = tcg_temp_new();
6188 gen_addr_reg_index(ctx, t0);
6189 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
6191 if (Rc(ctx->opcode)) {
6192 int l1 = gen_new_label();
6193 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
6194 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6195 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6202 static void gen_tlbwe_440(DisasContext *ctx)
6204 #if defined(CONFIG_USER_ONLY)
6205 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6207 if (unlikely(!ctx->mem_idx)) {
6208 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6211 switch (rB(ctx->opcode)) {
6216 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
6217 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6218 cpu_gpr[rS(ctx->opcode)]);
6219 tcg_temp_free_i32(t0);
6223 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6229 /* TLB management - PowerPC BookE 2.06 implementation */
6232 static void gen_tlbre_booke206(DisasContext *ctx)
6234 #if defined(CONFIG_USER_ONLY)
6235 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6237 if (unlikely(!ctx->mem_idx)) {
6238 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6242 gen_helper_booke206_tlbre(cpu_env);
6246 /* tlbsx - tlbsx. */
6247 static void gen_tlbsx_booke206(DisasContext *ctx)
6249 #if defined(CONFIG_USER_ONLY)
6250 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6253 if (unlikely(!ctx->mem_idx)) {
6254 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6258 if (rA(ctx->opcode)) {
6259 t0 = tcg_temp_new();
6260 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6262 t0 = tcg_const_tl(0);
6265 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
6266 gen_helper_booke206_tlbsx(cpu_env, t0);
6271 static void gen_tlbwe_booke206(DisasContext *ctx)
6273 #if defined(CONFIG_USER_ONLY)
6274 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6276 if (unlikely(!ctx->mem_idx)) {
6277 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6280 gen_update_nip(ctx, ctx->nip - 4);
6281 gen_helper_booke206_tlbwe(cpu_env);
6285 static void gen_tlbivax_booke206(DisasContext *ctx)
6287 #if defined(CONFIG_USER_ONLY)
6288 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6291 if (unlikely(!ctx->mem_idx)) {
6292 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6296 t0 = tcg_temp_new();
6297 gen_addr_reg_index(ctx, t0);
6299 gen_helper_booke206_tlbivax(cpu_env, t0);
6303 static void gen_tlbilx_booke206(DisasContext *ctx)
6305 #if defined(CONFIG_USER_ONLY)
6306 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6309 if (unlikely(!ctx->mem_idx)) {
6310 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6314 t0 = tcg_temp_new();
6315 gen_addr_reg_index(ctx, t0);
6317 switch((ctx->opcode >> 21) & 0x3) {
6319 gen_helper_booke206_tlbilx0(cpu_env, t0);
6322 gen_helper_booke206_tlbilx1(cpu_env, t0);
6325 gen_helper_booke206_tlbilx3(cpu_env, t0);
6328 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6338 static void gen_wrtee(DisasContext *ctx)
6340 #if defined(CONFIG_USER_ONLY)
6341 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6344 if (unlikely(!ctx->mem_idx)) {
6345 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6348 t0 = tcg_temp_new();
6349 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6350 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6351 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6353 /* Stop translation to have a chance to raise an exception
6354 * if we just set msr_ee to 1
6356 gen_stop_exception(ctx);
6361 static void gen_wrteei(DisasContext *ctx)
6363 #if defined(CONFIG_USER_ONLY)
6364 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6366 if (unlikely(!ctx->mem_idx)) {
6367 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6370 if (ctx->opcode & 0x00008000) {
6371 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6372 /* Stop translation to have a chance to raise an exception */
6373 gen_stop_exception(ctx);
6375 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6380 /* PowerPC 440 specific instructions */
6383 static void gen_dlmzb(DisasContext *ctx)
6385 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
6386 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6387 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
6388 tcg_temp_free_i32(t0);
6391 /* mbar replaces eieio on 440 */
6392 static void gen_mbar(DisasContext *ctx)
6394 /* interpreted as no-op */
6397 /* msync replaces sync on 440 */
6398 static void gen_msync_4xx(DisasContext *ctx)
6400 /* interpreted as no-op */
6404 static void gen_icbt_440(DisasContext *ctx)
6406 /* interpreted as no-op */
6407 /* XXX: specification say this is treated as a load by the MMU
6408 * but does not generate any exception
6412 /* Embedded.Processor Control */
6414 static void gen_msgclr(DisasContext *ctx)
6416 #if defined(CONFIG_USER_ONLY)
6417 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6419 if (unlikely(ctx->mem_idx == 0)) {
6420 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6424 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
6428 static void gen_msgsnd(DisasContext *ctx)
6430 #if defined(CONFIG_USER_ONLY)
6431 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6433 if (unlikely(ctx->mem_idx == 0)) {
6434 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6438 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6442 /*** Altivec vector extension ***/
6443 /* Altivec registers moves */
6445 static inline TCGv_ptr gen_avr_ptr(int reg)
6447 TCGv_ptr r = tcg_temp_new_ptr();
6448 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6452 #define GEN_VR_LDX(name, opc2, opc3) \
6453 static void glue(gen_, name)(DisasContext *ctx) \
6456 if (unlikely(!ctx->altivec_enabled)) { \
6457 gen_exception(ctx, POWERPC_EXCP_VPU); \
6460 gen_set_access_type(ctx, ACCESS_INT); \
6461 EA = tcg_temp_new(); \
6462 gen_addr_reg_index(ctx, EA); \
6463 tcg_gen_andi_tl(EA, EA, ~0xf); \
6464 if (ctx->le_mode) { \
6465 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6466 tcg_gen_addi_tl(EA, EA, 8); \
6467 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6469 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6470 tcg_gen_addi_tl(EA, EA, 8); \
6471 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6473 tcg_temp_free(EA); \
6476 #define GEN_VR_STX(name, opc2, opc3) \
6477 static void gen_st##name(DisasContext *ctx) \
6480 if (unlikely(!ctx->altivec_enabled)) { \
6481 gen_exception(ctx, POWERPC_EXCP_VPU); \
6484 gen_set_access_type(ctx, ACCESS_INT); \
6485 EA = tcg_temp_new(); \
6486 gen_addr_reg_index(ctx, EA); \
6487 tcg_gen_andi_tl(EA, EA, ~0xf); \
6488 if (ctx->le_mode) { \
6489 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6490 tcg_gen_addi_tl(EA, EA, 8); \
6491 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6493 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6494 tcg_gen_addi_tl(EA, EA, 8); \
6495 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6497 tcg_temp_free(EA); \
6500 #define GEN_VR_LVE(name, opc2, opc3) \
6501 static void gen_lve##name(DisasContext *ctx) \
6505 if (unlikely(!ctx->altivec_enabled)) { \
6506 gen_exception(ctx, POWERPC_EXCP_VPU); \
6509 gen_set_access_type(ctx, ACCESS_INT); \
6510 EA = tcg_temp_new(); \
6511 gen_addr_reg_index(ctx, EA); \
6512 rs = gen_avr_ptr(rS(ctx->opcode)); \
6513 gen_helper_lve##name(cpu_env, rs, EA); \
6514 tcg_temp_free(EA); \
6515 tcg_temp_free_ptr(rs); \
6518 #define GEN_VR_STVE(name, opc2, opc3) \
6519 static void gen_stve##name(DisasContext *ctx) \
6523 if (unlikely(!ctx->altivec_enabled)) { \
6524 gen_exception(ctx, POWERPC_EXCP_VPU); \
6527 gen_set_access_type(ctx, ACCESS_INT); \
6528 EA = tcg_temp_new(); \
6529 gen_addr_reg_index(ctx, EA); \
6530 rs = gen_avr_ptr(rS(ctx->opcode)); \
6531 gen_helper_stve##name(cpu_env, rs, EA); \
6532 tcg_temp_free(EA); \
6533 tcg_temp_free_ptr(rs); \
6536 GEN_VR_LDX(lvx, 0x07, 0x03);
6537 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6538 GEN_VR_LDX(lvxl, 0x07, 0x0B);
6540 GEN_VR_LVE(bx, 0x07, 0x00);
6541 GEN_VR_LVE(hx, 0x07, 0x01);
6542 GEN_VR_LVE(wx, 0x07, 0x02);
6544 GEN_VR_STX(svx, 0x07, 0x07);
6545 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6546 GEN_VR_STX(svxl, 0x07, 0x0F);
6548 GEN_VR_STVE(bx, 0x07, 0x04);
6549 GEN_VR_STVE(hx, 0x07, 0x05);
6550 GEN_VR_STVE(wx, 0x07, 0x06);
6552 static void gen_lvsl(DisasContext *ctx)
6556 if (unlikely(!ctx->altivec_enabled)) {
6557 gen_exception(ctx, POWERPC_EXCP_VPU);
6560 EA = tcg_temp_new();
6561 gen_addr_reg_index(ctx, EA);
6562 rd = gen_avr_ptr(rD(ctx->opcode));
6563 gen_helper_lvsl(rd, EA);
6565 tcg_temp_free_ptr(rd);
6568 static void gen_lvsr(DisasContext *ctx)
6572 if (unlikely(!ctx->altivec_enabled)) {
6573 gen_exception(ctx, POWERPC_EXCP_VPU);
6576 EA = tcg_temp_new();
6577 gen_addr_reg_index(ctx, EA);
6578 rd = gen_avr_ptr(rD(ctx->opcode));
6579 gen_helper_lvsr(rd, EA);
6581 tcg_temp_free_ptr(rd);
6584 static void gen_mfvscr(DisasContext *ctx)
6587 if (unlikely(!ctx->altivec_enabled)) {
6588 gen_exception(ctx, POWERPC_EXCP_VPU);
6591 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6592 t = tcg_temp_new_i32();
6593 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
6594 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
6595 tcg_temp_free_i32(t);
6598 static void gen_mtvscr(DisasContext *ctx)
6601 if (unlikely(!ctx->altivec_enabled)) {
6602 gen_exception(ctx, POWERPC_EXCP_VPU);
6605 p = gen_avr_ptr(rD(ctx->opcode));
6606 gen_helper_mtvscr(cpu_env, p);
6607 tcg_temp_free_ptr(p);
6610 /* Logical operations */
6611 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6612 static void glue(gen_, name)(DisasContext *ctx) \
6614 if (unlikely(!ctx->altivec_enabled)) { \
6615 gen_exception(ctx, POWERPC_EXCP_VPU); \
6618 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6619 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6622 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6623 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6624 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6625 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6626 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6628 #define GEN_VXFORM(name, opc2, opc3) \
6629 static void glue(gen_, name)(DisasContext *ctx) \
6631 TCGv_ptr ra, rb, rd; \
6632 if (unlikely(!ctx->altivec_enabled)) { \
6633 gen_exception(ctx, POWERPC_EXCP_VPU); \
6636 ra = gen_avr_ptr(rA(ctx->opcode)); \
6637 rb = gen_avr_ptr(rB(ctx->opcode)); \
6638 rd = gen_avr_ptr(rD(ctx->opcode)); \
6639 gen_helper_##name (rd, ra, rb); \
6640 tcg_temp_free_ptr(ra); \
6641 tcg_temp_free_ptr(rb); \
6642 tcg_temp_free_ptr(rd); \
6645 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6646 static void glue(gen_, name)(DisasContext *ctx) \
6648 TCGv_ptr ra, rb, rd; \
6649 if (unlikely(!ctx->altivec_enabled)) { \
6650 gen_exception(ctx, POWERPC_EXCP_VPU); \
6653 ra = gen_avr_ptr(rA(ctx->opcode)); \
6654 rb = gen_avr_ptr(rB(ctx->opcode)); \
6655 rd = gen_avr_ptr(rD(ctx->opcode)); \
6656 gen_helper_##name(cpu_env, rd, ra, rb); \
6657 tcg_temp_free_ptr(ra); \
6658 tcg_temp_free_ptr(rb); \
6659 tcg_temp_free_ptr(rd); \
6662 GEN_VXFORM(vaddubm, 0, 0);
6663 GEN_VXFORM(vadduhm, 0, 1);
6664 GEN_VXFORM(vadduwm, 0, 2);
6665 GEN_VXFORM(vsububm, 0, 16);
6666 GEN_VXFORM(vsubuhm, 0, 17);
6667 GEN_VXFORM(vsubuwm, 0, 18);
6668 GEN_VXFORM(vmaxub, 1, 0);
6669 GEN_VXFORM(vmaxuh, 1, 1);
6670 GEN_VXFORM(vmaxuw, 1, 2);
6671 GEN_VXFORM(vmaxsb, 1, 4);
6672 GEN_VXFORM(vmaxsh, 1, 5);
6673 GEN_VXFORM(vmaxsw, 1, 6);
6674 GEN_VXFORM(vminub, 1, 8);
6675 GEN_VXFORM(vminuh, 1, 9);
6676 GEN_VXFORM(vminuw, 1, 10);
6677 GEN_VXFORM(vminsb, 1, 12);
6678 GEN_VXFORM(vminsh, 1, 13);
6679 GEN_VXFORM(vminsw, 1, 14);
6680 GEN_VXFORM(vavgub, 1, 16);
6681 GEN_VXFORM(vavguh, 1, 17);
6682 GEN_VXFORM(vavguw, 1, 18);
6683 GEN_VXFORM(vavgsb, 1, 20);
6684 GEN_VXFORM(vavgsh, 1, 21);
6685 GEN_VXFORM(vavgsw, 1, 22);
6686 GEN_VXFORM(vmrghb, 6, 0);
6687 GEN_VXFORM(vmrghh, 6, 1);
6688 GEN_VXFORM(vmrghw, 6, 2);
6689 GEN_VXFORM(vmrglb, 6, 4);
6690 GEN_VXFORM(vmrglh, 6, 5);
6691 GEN_VXFORM(vmrglw, 6, 6);
6692 GEN_VXFORM(vmuloub, 4, 0);
6693 GEN_VXFORM(vmulouh, 4, 1);
6694 GEN_VXFORM(vmulosb, 4, 4);
6695 GEN_VXFORM(vmulosh, 4, 5);
6696 GEN_VXFORM(vmuleub, 4, 8);
6697 GEN_VXFORM(vmuleuh, 4, 9);
6698 GEN_VXFORM(vmulesb, 4, 12);
6699 GEN_VXFORM(vmulesh, 4, 13);
6700 GEN_VXFORM(vslb, 2, 4);
6701 GEN_VXFORM(vslh, 2, 5);
6702 GEN_VXFORM(vslw, 2, 6);
6703 GEN_VXFORM(vsrb, 2, 8);
6704 GEN_VXFORM(vsrh, 2, 9);
6705 GEN_VXFORM(vsrw, 2, 10);
6706 GEN_VXFORM(vsrab, 2, 12);
6707 GEN_VXFORM(vsrah, 2, 13);
6708 GEN_VXFORM(vsraw, 2, 14);
6709 GEN_VXFORM(vslo, 6, 16);
6710 GEN_VXFORM(vsro, 6, 17);
6711 GEN_VXFORM(vaddcuw, 0, 6);
6712 GEN_VXFORM(vsubcuw, 0, 22);
6713 GEN_VXFORM_ENV(vaddubs, 0, 8);
6714 GEN_VXFORM_ENV(vadduhs, 0, 9);
6715 GEN_VXFORM_ENV(vadduws, 0, 10);
6716 GEN_VXFORM_ENV(vaddsbs, 0, 12);
6717 GEN_VXFORM_ENV(vaddshs, 0, 13);
6718 GEN_VXFORM_ENV(vaddsws, 0, 14);
6719 GEN_VXFORM_ENV(vsububs, 0, 24);
6720 GEN_VXFORM_ENV(vsubuhs, 0, 25);
6721 GEN_VXFORM_ENV(vsubuws, 0, 26);
6722 GEN_VXFORM_ENV(vsubsbs, 0, 28);
6723 GEN_VXFORM_ENV(vsubshs, 0, 29);
6724 GEN_VXFORM_ENV(vsubsws, 0, 30);
6725 GEN_VXFORM(vrlb, 2, 0);
6726 GEN_VXFORM(vrlh, 2, 1);
6727 GEN_VXFORM(vrlw, 2, 2);
6728 GEN_VXFORM(vsl, 2, 7);
6729 GEN_VXFORM(vsr, 2, 11);
6730 GEN_VXFORM_ENV(vpkuhum, 7, 0);
6731 GEN_VXFORM_ENV(vpkuwum, 7, 1);
6732 GEN_VXFORM_ENV(vpkuhus, 7, 2);
6733 GEN_VXFORM_ENV(vpkuwus, 7, 3);
6734 GEN_VXFORM_ENV(vpkshus, 7, 4);
6735 GEN_VXFORM_ENV(vpkswus, 7, 5);
6736 GEN_VXFORM_ENV(vpkshss, 7, 6);
6737 GEN_VXFORM_ENV(vpkswss, 7, 7);
6738 GEN_VXFORM(vpkpx, 7, 12);
6739 GEN_VXFORM_ENV(vsum4ubs, 4, 24);
6740 GEN_VXFORM_ENV(vsum4sbs, 4, 28);
6741 GEN_VXFORM_ENV(vsum4shs, 4, 25);
6742 GEN_VXFORM_ENV(vsum2sws, 4, 26);
6743 GEN_VXFORM_ENV(vsumsws, 4, 30);
6744 GEN_VXFORM_ENV(vaddfp, 5, 0);
6745 GEN_VXFORM_ENV(vsubfp, 5, 1);
6746 GEN_VXFORM_ENV(vmaxfp, 5, 16);
6747 GEN_VXFORM_ENV(vminfp, 5, 17);
6749 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6750 static void glue(gen_, name)(DisasContext *ctx) \
6752 TCGv_ptr ra, rb, rd; \
6753 if (unlikely(!ctx->altivec_enabled)) { \
6754 gen_exception(ctx, POWERPC_EXCP_VPU); \
6757 ra = gen_avr_ptr(rA(ctx->opcode)); \
6758 rb = gen_avr_ptr(rB(ctx->opcode)); \
6759 rd = gen_avr_ptr(rD(ctx->opcode)); \
6760 gen_helper_##opname(cpu_env, rd, ra, rb); \
6761 tcg_temp_free_ptr(ra); \
6762 tcg_temp_free_ptr(rb); \
6763 tcg_temp_free_ptr(rd); \
6766 #define GEN_VXRFORM(name, opc2, opc3) \
6767 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6768 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6770 GEN_VXRFORM(vcmpequb, 3, 0)
6771 GEN_VXRFORM(vcmpequh, 3, 1)
6772 GEN_VXRFORM(vcmpequw, 3, 2)
6773 GEN_VXRFORM(vcmpgtsb, 3, 12)
6774 GEN_VXRFORM(vcmpgtsh, 3, 13)
6775 GEN_VXRFORM(vcmpgtsw, 3, 14)
6776 GEN_VXRFORM(vcmpgtub, 3, 8)
6777 GEN_VXRFORM(vcmpgtuh, 3, 9)
6778 GEN_VXRFORM(vcmpgtuw, 3, 10)
6779 GEN_VXRFORM(vcmpeqfp, 3, 3)
6780 GEN_VXRFORM(vcmpgefp, 3, 7)
6781 GEN_VXRFORM(vcmpgtfp, 3, 11)
6782 GEN_VXRFORM(vcmpbfp, 3, 15)
6784 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6785 static void glue(gen_, name)(DisasContext *ctx) \
6789 if (unlikely(!ctx->altivec_enabled)) { \
6790 gen_exception(ctx, POWERPC_EXCP_VPU); \
6793 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6794 rd = gen_avr_ptr(rD(ctx->opcode)); \
6795 gen_helper_##name (rd, simm); \
6796 tcg_temp_free_i32(simm); \
6797 tcg_temp_free_ptr(rd); \
6800 GEN_VXFORM_SIMM(vspltisb, 6, 12);
6801 GEN_VXFORM_SIMM(vspltish, 6, 13);
6802 GEN_VXFORM_SIMM(vspltisw, 6, 14);
6804 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6805 static void glue(gen_, name)(DisasContext *ctx) \
6808 if (unlikely(!ctx->altivec_enabled)) { \
6809 gen_exception(ctx, POWERPC_EXCP_VPU); \
6812 rb = gen_avr_ptr(rB(ctx->opcode)); \
6813 rd = gen_avr_ptr(rD(ctx->opcode)); \
6814 gen_helper_##name (rd, rb); \
6815 tcg_temp_free_ptr(rb); \
6816 tcg_temp_free_ptr(rd); \
6819 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6820 static void glue(gen_, name)(DisasContext *ctx) \
6824 if (unlikely(!ctx->altivec_enabled)) { \
6825 gen_exception(ctx, POWERPC_EXCP_VPU); \
6828 rb = gen_avr_ptr(rB(ctx->opcode)); \
6829 rd = gen_avr_ptr(rD(ctx->opcode)); \
6830 gen_helper_##name(cpu_env, rd, rb); \
6831 tcg_temp_free_ptr(rb); \
6832 tcg_temp_free_ptr(rd); \
6835 GEN_VXFORM_NOA(vupkhsb, 7, 8);
6836 GEN_VXFORM_NOA(vupkhsh, 7, 9);
6837 GEN_VXFORM_NOA(vupklsb, 7, 10);
6838 GEN_VXFORM_NOA(vupklsh, 7, 11);
6839 GEN_VXFORM_NOA(vupkhpx, 7, 13);
6840 GEN_VXFORM_NOA(vupklpx, 7, 15);
6841 GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
6842 GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
6843 GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
6844 GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
6845 GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
6846 GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
6847 GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
6848 GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
6850 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6851 static void glue(gen_, name)(DisasContext *ctx) \
6855 if (unlikely(!ctx->altivec_enabled)) { \
6856 gen_exception(ctx, POWERPC_EXCP_VPU); \
6859 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6860 rd = gen_avr_ptr(rD(ctx->opcode)); \
6861 gen_helper_##name (rd, simm); \
6862 tcg_temp_free_i32(simm); \
6863 tcg_temp_free_ptr(rd); \
6866 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6867 static void glue(gen_, name)(DisasContext *ctx) \
6871 if (unlikely(!ctx->altivec_enabled)) { \
6872 gen_exception(ctx, POWERPC_EXCP_VPU); \
6875 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6876 rb = gen_avr_ptr(rB(ctx->opcode)); \
6877 rd = gen_avr_ptr(rD(ctx->opcode)); \
6878 gen_helper_##name (rd, rb, uimm); \
6879 tcg_temp_free_i32(uimm); \
6880 tcg_temp_free_ptr(rb); \
6881 tcg_temp_free_ptr(rd); \
6884 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6885 static void glue(gen_, name)(DisasContext *ctx) \
6890 if (unlikely(!ctx->altivec_enabled)) { \
6891 gen_exception(ctx, POWERPC_EXCP_VPU); \
6894 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6895 rb = gen_avr_ptr(rB(ctx->opcode)); \
6896 rd = gen_avr_ptr(rD(ctx->opcode)); \
6897 gen_helper_##name(cpu_env, rd, rb, uimm); \
6898 tcg_temp_free_i32(uimm); \
6899 tcg_temp_free_ptr(rb); \
6900 tcg_temp_free_ptr(rd); \
6903 GEN_VXFORM_UIMM(vspltb, 6, 8);
6904 GEN_VXFORM_UIMM(vsplth, 6, 9);
6905 GEN_VXFORM_UIMM(vspltw, 6, 10);
6906 GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
6907 GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
6908 GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
6909 GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
6911 static void gen_vsldoi(DisasContext *ctx)
6913 TCGv_ptr ra, rb, rd;
6915 if (unlikely(!ctx->altivec_enabled)) {
6916 gen_exception(ctx, POWERPC_EXCP_VPU);
6919 ra = gen_avr_ptr(rA(ctx->opcode));
6920 rb = gen_avr_ptr(rB(ctx->opcode));
6921 rd = gen_avr_ptr(rD(ctx->opcode));
6922 sh = tcg_const_i32(VSH(ctx->opcode));
6923 gen_helper_vsldoi (rd, ra, rb, sh);
6924 tcg_temp_free_ptr(ra);
6925 tcg_temp_free_ptr(rb);
6926 tcg_temp_free_ptr(rd);
6927 tcg_temp_free_i32(sh);
6930 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6931 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6933 TCGv_ptr ra, rb, rc, rd; \
6934 if (unlikely(!ctx->altivec_enabled)) { \
6935 gen_exception(ctx, POWERPC_EXCP_VPU); \
6938 ra = gen_avr_ptr(rA(ctx->opcode)); \
6939 rb = gen_avr_ptr(rB(ctx->opcode)); \
6940 rc = gen_avr_ptr(rC(ctx->opcode)); \
6941 rd = gen_avr_ptr(rD(ctx->opcode)); \
6942 if (Rc(ctx->opcode)) { \
6943 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
6945 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
6947 tcg_temp_free_ptr(ra); \
6948 tcg_temp_free_ptr(rb); \
6949 tcg_temp_free_ptr(rc); \
6950 tcg_temp_free_ptr(rd); \
6953 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
6955 static void gen_vmladduhm(DisasContext *ctx)
6957 TCGv_ptr ra, rb, rc, rd;
6958 if (unlikely(!ctx->altivec_enabled)) {
6959 gen_exception(ctx, POWERPC_EXCP_VPU);
6962 ra = gen_avr_ptr(rA(ctx->opcode));
6963 rb = gen_avr_ptr(rB(ctx->opcode));
6964 rc = gen_avr_ptr(rC(ctx->opcode));
6965 rd = gen_avr_ptr(rD(ctx->opcode));
6966 gen_helper_vmladduhm(rd, ra, rb, rc);
6967 tcg_temp_free_ptr(ra);
6968 tcg_temp_free_ptr(rb);
6969 tcg_temp_free_ptr(rc);
6970 tcg_temp_free_ptr(rd);
6973 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
6974 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
6975 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
6976 GEN_VAFORM_PAIRED(vsel, vperm, 21)
6977 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
6979 /*** SPE extension ***/
6980 /* Register moves */
6983 static inline void gen_evmra(DisasContext *ctx)
6986 if (unlikely(!ctx->spe_enabled)) {
6987 gen_exception(ctx, POWERPC_EXCP_SPEU);
6991 #if defined(TARGET_PPC64)
6993 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6996 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
6998 offsetof(CPUPPCState, spe_acc));
7000 TCGv_i64 tmp = tcg_temp_new_i64();
7002 /* tmp := rA_lo + rA_hi << 32 */
7003 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7005 /* spe_acc := tmp */
7006 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
7007 tcg_temp_free_i64(tmp);
7010 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7011 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7015 static inline void gen_load_gpr64(TCGv_i64 t, int reg)
7017 #if defined(TARGET_PPC64)
7018 tcg_gen_mov_i64(t, cpu_gpr[reg]);
7020 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
7024 static inline void gen_store_gpr64(int reg, TCGv_i64 t)
7026 #if defined(TARGET_PPC64)
7027 tcg_gen_mov_i64(cpu_gpr[reg], t);
7029 TCGv_i64 tmp = tcg_temp_new_i64();
7030 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
7031 tcg_gen_shri_i64(tmp, t, 32);
7032 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
7033 tcg_temp_free_i64(tmp);
7037 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
7038 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7040 if (Rc(ctx->opcode)) \
7046 /* Handler for undefined SPE opcodes */
7047 static inline void gen_speundef(DisasContext *ctx)
7049 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
7053 #if defined(TARGET_PPC64)
7054 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7055 static inline void gen_##name(DisasContext *ctx) \
7057 if (unlikely(!ctx->spe_enabled)) { \
7058 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7061 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7062 cpu_gpr[rB(ctx->opcode)]); \
7065 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7066 static inline void gen_##name(DisasContext *ctx) \
7068 if (unlikely(!ctx->spe_enabled)) { \
7069 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7072 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7073 cpu_gpr[rB(ctx->opcode)]); \
7074 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7075 cpu_gprh[rB(ctx->opcode)]); \
7079 GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
7080 GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
7081 GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
7082 GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
7083 GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
7084 GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
7085 GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
7086 GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
7088 /* SPE logic immediate */
7089 #if defined(TARGET_PPC64)
7090 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7091 static inline void gen_##name(DisasContext *ctx) \
7093 if (unlikely(!ctx->spe_enabled)) { \
7094 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7097 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7098 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7099 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7100 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7101 tcg_opi(t0, t0, rB(ctx->opcode)); \
7102 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7103 tcg_gen_trunc_i64_i32(t1, t2); \
7104 tcg_temp_free_i64(t2); \
7105 tcg_opi(t1, t1, rB(ctx->opcode)); \
7106 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7107 tcg_temp_free_i32(t0); \
7108 tcg_temp_free_i32(t1); \
7111 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7112 static inline void gen_##name(DisasContext *ctx) \
7114 if (unlikely(!ctx->spe_enabled)) { \
7115 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7118 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7120 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7124 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
7125 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
7126 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
7127 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
7129 /* SPE arithmetic */
7130 #if defined(TARGET_PPC64)
7131 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7132 static inline void gen_##name(DisasContext *ctx) \
7134 if (unlikely(!ctx->spe_enabled)) { \
7135 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7138 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7139 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7140 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7141 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7143 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7144 tcg_gen_trunc_i64_i32(t1, t2); \
7145 tcg_temp_free_i64(t2); \
7147 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7148 tcg_temp_free_i32(t0); \
7149 tcg_temp_free_i32(t1); \
7152 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7153 static inline void gen_##name(DisasContext *ctx) \
7155 if (unlikely(!ctx->spe_enabled)) { \
7156 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7159 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
7160 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
7164 static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
7166 int l1 = gen_new_label();
7167 int l2 = gen_new_label();
7169 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
7170 tcg_gen_neg_i32(ret, arg1);
7173 tcg_gen_mov_i32(ret, arg1);
7176 GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
7177 GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
7178 GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
7179 GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
7180 static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
7182 tcg_gen_addi_i32(ret, arg1, 0x8000);
7183 tcg_gen_ext16u_i32(ret, ret);
7185 GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
7186 GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
7187 GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
7189 #if defined(TARGET_PPC64)
7190 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7191 static inline void gen_##name(DisasContext *ctx) \
7193 if (unlikely(!ctx->spe_enabled)) { \
7194 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7197 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7198 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7199 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
7200 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
7201 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7202 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
7203 tcg_op(t0, t0, t2); \
7204 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
7205 tcg_gen_trunc_i64_i32(t1, t3); \
7206 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
7207 tcg_gen_trunc_i64_i32(t2, t3); \
7208 tcg_temp_free_i64(t3); \
7209 tcg_op(t1, t1, t2); \
7210 tcg_temp_free_i32(t2); \
7211 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7212 tcg_temp_free_i32(t0); \
7213 tcg_temp_free_i32(t1); \
7216 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7217 static inline void gen_##name(DisasContext *ctx) \
7219 if (unlikely(!ctx->spe_enabled)) { \
7220 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7223 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7224 cpu_gpr[rB(ctx->opcode)]); \
7225 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7226 cpu_gprh[rB(ctx->opcode)]); \
7230 static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
7235 l1 = gen_new_label();
7236 l2 = gen_new_label();
7237 t0 = tcg_temp_local_new_i32();
7238 /* No error here: 6 bits are used */
7239 tcg_gen_andi_i32(t0, arg2, 0x3F);
7240 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7241 tcg_gen_shr_i32(ret, arg1, t0);
7244 tcg_gen_movi_i32(ret, 0);
7246 tcg_temp_free_i32(t0);
7248 GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
7249 static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
7254 l1 = gen_new_label();
7255 l2 = gen_new_label();
7256 t0 = tcg_temp_local_new_i32();
7257 /* No error here: 6 bits are used */
7258 tcg_gen_andi_i32(t0, arg2, 0x3F);
7259 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7260 tcg_gen_sar_i32(ret, arg1, t0);
7263 tcg_gen_movi_i32(ret, 0);
7265 tcg_temp_free_i32(t0);
7267 GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
7268 static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
7273 l1 = gen_new_label();
7274 l2 = gen_new_label();
7275 t0 = tcg_temp_local_new_i32();
7276 /* No error here: 6 bits are used */
7277 tcg_gen_andi_i32(t0, arg2, 0x3F);
7278 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7279 tcg_gen_shl_i32(ret, arg1, t0);
7282 tcg_gen_movi_i32(ret, 0);
7284 tcg_temp_free_i32(t0);
7286 GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
7287 static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
7289 TCGv_i32 t0 = tcg_temp_new_i32();
7290 tcg_gen_andi_i32(t0, arg2, 0x1F);
7291 tcg_gen_rotl_i32(ret, arg1, t0);
7292 tcg_temp_free_i32(t0);
7294 GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
7295 static inline void gen_evmergehi(DisasContext *ctx)
7297 if (unlikely(!ctx->spe_enabled)) {
7298 gen_exception(ctx, POWERPC_EXCP_SPEU);
7301 #if defined(TARGET_PPC64)
7302 TCGv t0 = tcg_temp_new();
7303 TCGv t1 = tcg_temp_new();
7304 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
7305 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
7306 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7310 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7311 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7314 GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
7315 static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
7317 tcg_gen_sub_i32(ret, arg2, arg1);
7319 GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
7321 /* SPE arithmetic immediate */
7322 #if defined(TARGET_PPC64)
7323 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7324 static inline void gen_##name(DisasContext *ctx) \
7326 if (unlikely(!ctx->spe_enabled)) { \
7327 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7330 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7331 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7332 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7333 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7334 tcg_op(t0, t0, rA(ctx->opcode)); \
7335 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7336 tcg_gen_trunc_i64_i32(t1, t2); \
7337 tcg_temp_free_i64(t2); \
7338 tcg_op(t1, t1, rA(ctx->opcode)); \
7339 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7340 tcg_temp_free_i32(t0); \
7341 tcg_temp_free_i32(t1); \
7344 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7345 static inline void gen_##name(DisasContext *ctx) \
7347 if (unlikely(!ctx->spe_enabled)) { \
7348 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7351 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7353 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7357 GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
7358 GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
7360 /* SPE comparison */
7361 #if defined(TARGET_PPC64)
7362 #define GEN_SPEOP_COMP(name, tcg_cond) \
7363 static inline void gen_##name(DisasContext *ctx) \
7365 if (unlikely(!ctx->spe_enabled)) { \
7366 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7369 int l1 = gen_new_label(); \
7370 int l2 = gen_new_label(); \
7371 int l3 = gen_new_label(); \
7372 int l4 = gen_new_label(); \
7373 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7374 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7375 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7376 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7377 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7378 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
7379 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
7381 gen_set_label(l1); \
7382 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7383 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7384 gen_set_label(l2); \
7385 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7386 tcg_gen_trunc_i64_i32(t0, t2); \
7387 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7388 tcg_gen_trunc_i64_i32(t1, t2); \
7389 tcg_temp_free_i64(t2); \
7390 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7391 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7392 ~(CRF_CH | CRF_CH_AND_CL)); \
7394 gen_set_label(l3); \
7395 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7396 CRF_CH | CRF_CH_OR_CL); \
7397 gen_set_label(l4); \
7398 tcg_temp_free_i32(t0); \
7399 tcg_temp_free_i32(t1); \
7402 #define GEN_SPEOP_COMP(name, tcg_cond) \
7403 static inline void gen_##name(DisasContext *ctx) \
7405 if (unlikely(!ctx->spe_enabled)) { \
7406 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7409 int l1 = gen_new_label(); \
7410 int l2 = gen_new_label(); \
7411 int l3 = gen_new_label(); \
7412 int l4 = gen_new_label(); \
7414 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7415 cpu_gpr[rB(ctx->opcode)], l1); \
7416 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7418 gen_set_label(l1); \
7419 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7420 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7421 gen_set_label(l2); \
7422 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7423 cpu_gprh[rB(ctx->opcode)], l3); \
7424 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7425 ~(CRF_CH | CRF_CH_AND_CL)); \
7427 gen_set_label(l3); \
7428 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7429 CRF_CH | CRF_CH_OR_CL); \
7430 gen_set_label(l4); \
7433 GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
7434 GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
7435 GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
7436 GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
7437 GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
7440 static inline void gen_brinc(DisasContext *ctx)
7442 /* Note: brinc is usable even if SPE is disabled */
7443 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
7444 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7446 static inline void gen_evmergelo(DisasContext *ctx)
7448 if (unlikely(!ctx->spe_enabled)) {
7449 gen_exception(ctx, POWERPC_EXCP_SPEU);
7452 #if defined(TARGET_PPC64)
7453 TCGv t0 = tcg_temp_new();
7454 TCGv t1 = tcg_temp_new();
7455 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
7456 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
7457 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7461 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7462 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7465 static inline void gen_evmergehilo(DisasContext *ctx)
7467 if (unlikely(!ctx->spe_enabled)) {
7468 gen_exception(ctx, POWERPC_EXCP_SPEU);
7471 #if defined(TARGET_PPC64)
7472 TCGv t0 = tcg_temp_new();
7473 TCGv t1 = tcg_temp_new();
7474 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
7475 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
7476 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7480 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7481 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7484 static inline void gen_evmergelohi(DisasContext *ctx)
7486 if (unlikely(!ctx->spe_enabled)) {
7487 gen_exception(ctx, POWERPC_EXCP_SPEU);
7490 #if defined(TARGET_PPC64)
7491 TCGv t0 = tcg_temp_new();
7492 TCGv t1 = tcg_temp_new();
7493 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
7494 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
7495 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7499 if (rD(ctx->opcode) == rA(ctx->opcode)) {
7500 TCGv_i32 tmp = tcg_temp_new_i32();
7501 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
7502 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7503 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
7504 tcg_temp_free_i32(tmp);
7506 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7507 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7511 static inline void gen_evsplati(DisasContext *ctx)
7513 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
7515 #if defined(TARGET_PPC64)
7516 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
7518 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
7519 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
7522 static inline void gen_evsplatfi(DisasContext *ctx)
7524 uint64_t imm = rA(ctx->opcode) << 27;
7526 #if defined(TARGET_PPC64)
7527 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
7529 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
7530 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
7534 static inline void gen_evsel(DisasContext *ctx)
7536 int l1 = gen_new_label();
7537 int l2 = gen_new_label();
7538 int l3 = gen_new_label();
7539 int l4 = gen_new_label();
7540 TCGv_i32 t0 = tcg_temp_local_new_i32();
7541 #if defined(TARGET_PPC64)
7542 TCGv t1 = tcg_temp_local_new();
7543 TCGv t2 = tcg_temp_local_new();
7545 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
7546 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
7547 #if defined(TARGET_PPC64)
7548 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
7550 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7554 #if defined(TARGET_PPC64)
7555 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
7557 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7560 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
7561 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
7562 #if defined(TARGET_PPC64)
7563 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
7565 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7569 #if defined(TARGET_PPC64)
7570 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
7572 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7575 tcg_temp_free_i32(t0);
7576 #if defined(TARGET_PPC64)
7577 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
7583 static void gen_evsel0(DisasContext *ctx)
7588 static void gen_evsel1(DisasContext *ctx)
7593 static void gen_evsel2(DisasContext *ctx)
7598 static void gen_evsel3(DisasContext *ctx)
7605 static inline void gen_evmwumi(DisasContext *ctx)
7609 if (unlikely(!ctx->spe_enabled)) {
7610 gen_exception(ctx, POWERPC_EXCP_SPEU);
7614 t0 = tcg_temp_new_i64();
7615 t1 = tcg_temp_new_i64();
7617 /* t0 := rA; t1 := rB */
7618 #if defined(TARGET_PPC64)
7619 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
7620 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
7622 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
7623 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
7626 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
7628 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
7630 tcg_temp_free_i64(t0);
7631 tcg_temp_free_i64(t1);
7634 static inline void gen_evmwumia(DisasContext *ctx)
7638 if (unlikely(!ctx->spe_enabled)) {
7639 gen_exception(ctx, POWERPC_EXCP_SPEU);
7643 gen_evmwumi(ctx); /* rD := rA * rB */
7645 tmp = tcg_temp_new_i64();
7648 gen_load_gpr64(tmp, rD(ctx->opcode));
7649 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
7650 tcg_temp_free_i64(tmp);
7653 static inline void gen_evmwumiaa(DisasContext *ctx)
7658 if (unlikely(!ctx->spe_enabled)) {
7659 gen_exception(ctx, POWERPC_EXCP_SPEU);
7663 gen_evmwumi(ctx); /* rD := rA * rB */
7665 acc = tcg_temp_new_i64();
7666 tmp = tcg_temp_new_i64();
7669 gen_load_gpr64(tmp, rD(ctx->opcode));
7672 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
7674 /* acc := tmp + acc */
7675 tcg_gen_add_i64(acc, acc, tmp);
7678 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
7681 gen_store_gpr64(rD(ctx->opcode), acc);
7683 tcg_temp_free_i64(acc);
7684 tcg_temp_free_i64(tmp);
7687 static inline void gen_evmwsmi(DisasContext *ctx)
7691 if (unlikely(!ctx->spe_enabled)) {
7692 gen_exception(ctx, POWERPC_EXCP_SPEU);
7696 t0 = tcg_temp_new_i64();
7697 t1 = tcg_temp_new_i64();
7699 /* t0 := rA; t1 := rB */
7700 #if defined(TARGET_PPC64)
7701 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
7702 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
7704 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
7705 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
7708 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
7710 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
7712 tcg_temp_free_i64(t0);
7713 tcg_temp_free_i64(t1);
7716 static inline void gen_evmwsmia(DisasContext *ctx)
7720 gen_evmwsmi(ctx); /* rD := rA * rB */
7722 tmp = tcg_temp_new_i64();
7725 gen_load_gpr64(tmp, rD(ctx->opcode));
7726 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
7728 tcg_temp_free_i64(tmp);
7731 static inline void gen_evmwsmiaa(DisasContext *ctx)
7733 TCGv_i64 acc = tcg_temp_new_i64();
7734 TCGv_i64 tmp = tcg_temp_new_i64();
7736 gen_evmwsmi(ctx); /* rD := rA * rB */
7738 acc = tcg_temp_new_i64();
7739 tmp = tcg_temp_new_i64();
7742 gen_load_gpr64(tmp, rD(ctx->opcode));
7745 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
7747 /* acc := tmp + acc */
7748 tcg_gen_add_i64(acc, acc, tmp);
7751 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
7754 gen_store_gpr64(rD(ctx->opcode), acc);
7756 tcg_temp_free_i64(acc);
7757 tcg_temp_free_i64(tmp);
7760 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7761 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
7762 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7763 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
7764 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
7765 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
7766 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
7767 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
7768 GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
7769 GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
7770 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7771 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7772 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7773 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
7774 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
7775 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
7776 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
7777 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7778 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7779 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
7780 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7781 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
7782 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
7783 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
7784 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7785 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7786 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
7787 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
7788 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
7790 /* SPE load and stores */
7791 static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
7793 target_ulong uimm = rB(ctx->opcode);
7795 if (rA(ctx->opcode) == 0) {
7796 tcg_gen_movi_tl(EA, uimm << sh);
7798 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
7799 if (NARROW_MODE(ctx)) {
7800 tcg_gen_ext32u_tl(EA, EA);
7805 static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
7807 #if defined(TARGET_PPC64)
7808 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7810 TCGv_i64 t0 = tcg_temp_new_i64();
7811 gen_qemu_ld64(ctx, t0, addr);
7812 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
7813 tcg_gen_shri_i64(t0, t0, 32);
7814 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
7815 tcg_temp_free_i64(t0);
7819 static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
7821 #if defined(TARGET_PPC64)
7822 TCGv t0 = tcg_temp_new();
7823 gen_qemu_ld32u(ctx, t0, addr);
7824 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7825 gen_addr_add(ctx, addr, addr, 4);
7826 gen_qemu_ld32u(ctx, t0, addr);
7827 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7830 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7831 gen_addr_add(ctx, addr, addr, 4);
7832 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7836 static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
7838 TCGv t0 = tcg_temp_new();
7839 #if defined(TARGET_PPC64)
7840 gen_qemu_ld16u(ctx, t0, addr);
7841 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7842 gen_addr_add(ctx, addr, addr, 2);
7843 gen_qemu_ld16u(ctx, t0, addr);
7844 tcg_gen_shli_tl(t0, t0, 32);
7845 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7846 gen_addr_add(ctx, addr, addr, 2);
7847 gen_qemu_ld16u(ctx, t0, addr);
7848 tcg_gen_shli_tl(t0, t0, 16);
7849 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7850 gen_addr_add(ctx, addr, addr, 2);
7851 gen_qemu_ld16u(ctx, t0, addr);
7852 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7854 gen_qemu_ld16u(ctx, t0, addr);
7855 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7856 gen_addr_add(ctx, addr, addr, 2);
7857 gen_qemu_ld16u(ctx, t0, addr);
7858 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
7859 gen_addr_add(ctx, addr, addr, 2);
7860 gen_qemu_ld16u(ctx, t0, addr);
7861 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7862 gen_addr_add(ctx, addr, addr, 2);
7863 gen_qemu_ld16u(ctx, t0, addr);
7864 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7869 static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
7871 TCGv t0 = tcg_temp_new();
7872 gen_qemu_ld16u(ctx, t0, addr);
7873 #if defined(TARGET_PPC64)
7874 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7875 tcg_gen_shli_tl(t0, t0, 16);
7876 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7878 tcg_gen_shli_tl(t0, t0, 16);
7879 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7880 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7885 static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
7887 TCGv t0 = tcg_temp_new();
7888 gen_qemu_ld16u(ctx, t0, addr);
7889 #if defined(TARGET_PPC64)
7890 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7891 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7893 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7894 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7899 static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
7901 TCGv t0 = tcg_temp_new();
7902 gen_qemu_ld16s(ctx, t0, addr);
7903 #if defined(TARGET_PPC64)
7904 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7905 tcg_gen_ext32u_tl(t0, t0);
7906 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7908 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7909 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7914 static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
7916 TCGv t0 = tcg_temp_new();
7917 #if defined(TARGET_PPC64)
7918 gen_qemu_ld16u(ctx, t0, addr);
7919 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7920 gen_addr_add(ctx, addr, addr, 2);
7921 gen_qemu_ld16u(ctx, t0, addr);
7922 tcg_gen_shli_tl(t0, t0, 16);
7923 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7925 gen_qemu_ld16u(ctx, t0, addr);
7926 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7927 gen_addr_add(ctx, addr, addr, 2);
7928 gen_qemu_ld16u(ctx, t0, addr);
7929 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
7934 static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
7936 #if defined(TARGET_PPC64)
7937 TCGv t0 = tcg_temp_new();
7938 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7939 gen_addr_add(ctx, addr, addr, 2);
7940 gen_qemu_ld16u(ctx, t0, addr);
7941 tcg_gen_shli_tl(t0, t0, 32);
7942 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7945 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7946 gen_addr_add(ctx, addr, addr, 2);
7947 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7951 static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
7953 #if defined(TARGET_PPC64)
7954 TCGv t0 = tcg_temp_new();
7955 gen_qemu_ld16s(ctx, t0, addr);
7956 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
7957 gen_addr_add(ctx, addr, addr, 2);
7958 gen_qemu_ld16s(ctx, t0, addr);
7959 tcg_gen_shli_tl(t0, t0, 32);
7960 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7963 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7964 gen_addr_add(ctx, addr, addr, 2);
7965 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7969 static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
7971 TCGv t0 = tcg_temp_new();
7972 gen_qemu_ld32u(ctx, t0, addr);
7973 #if defined(TARGET_PPC64)
7974 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7975 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7977 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7978 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7983 static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
7985 TCGv t0 = tcg_temp_new();
7986 #if defined(TARGET_PPC64)
7987 gen_qemu_ld16u(ctx, t0, addr);
7988 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7989 tcg_gen_shli_tl(t0, t0, 32);
7990 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7991 gen_addr_add(ctx, addr, addr, 2);
7992 gen_qemu_ld16u(ctx, t0, addr);
7993 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7994 tcg_gen_shli_tl(t0, t0, 16);
7995 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7997 gen_qemu_ld16u(ctx, t0, addr);
7998 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7999 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
8000 gen_addr_add(ctx, addr, addr, 2);
8001 gen_qemu_ld16u(ctx, t0, addr);
8002 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
8003 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
8008 static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
8010 #if defined(TARGET_PPC64)
8011 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
8013 TCGv_i64 t0 = tcg_temp_new_i64();
8014 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
8015 gen_qemu_st64(ctx, t0, addr);
8016 tcg_temp_free_i64(t0);
8020 static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
8022 #if defined(TARGET_PPC64)
8023 TCGv t0 = tcg_temp_new();
8024 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
8025 gen_qemu_st32(ctx, t0, addr);
8028 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
8030 gen_addr_add(ctx, addr, addr, 4);
8031 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
8034 static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
8036 TCGv t0 = tcg_temp_new();
8037 #if defined(TARGET_PPC64)
8038 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
8040 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
8042 gen_qemu_st16(ctx, t0, addr);
8043 gen_addr_add(ctx, addr, addr, 2);
8044 #if defined(TARGET_PPC64)
8045 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
8046 gen_qemu_st16(ctx, t0, addr);
8048 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
8050 gen_addr_add(ctx, addr, addr, 2);
8051 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
8052 gen_qemu_st16(ctx, t0, addr);
8054 gen_addr_add(ctx, addr, addr, 2);
8055 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
8058 static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
8060 TCGv t0 = tcg_temp_new();
8061 #if defined(TARGET_PPC64)
8062 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
8064 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
8066 gen_qemu_st16(ctx, t0, addr);
8067 gen_addr_add(ctx, addr, addr, 2);
8068 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
8069 gen_qemu_st16(ctx, t0, addr);
8073 static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
8075 #if defined(TARGET_PPC64)
8076 TCGv t0 = tcg_temp_new();
8077 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
8078 gen_qemu_st16(ctx, t0, addr);
8081 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
8083 gen_addr_add(ctx, addr, addr, 2);
8084 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
8087 static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
8089 #if defined(TARGET_PPC64)
8090 TCGv t0 = tcg_temp_new();
8091 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
8092 gen_qemu_st32(ctx, t0, addr);
8095 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
8099 static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
8101 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
8104 #define GEN_SPEOP_LDST(name, opc2, sh) \
8105 static void glue(gen_, name)(DisasContext *ctx) \
8108 if (unlikely(!ctx->spe_enabled)) { \
8109 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8112 gen_set_access_type(ctx, ACCESS_INT); \
8113 t0 = tcg_temp_new(); \
8114 if (Rc(ctx->opcode)) { \
8115 gen_addr_spe_imm_index(ctx, t0, sh); \
8117 gen_addr_reg_index(ctx, t0); \
8119 gen_op_##name(ctx, t0); \
8120 tcg_temp_free(t0); \
8123 GEN_SPEOP_LDST(evldd, 0x00, 3);
8124 GEN_SPEOP_LDST(evldw, 0x01, 3);
8125 GEN_SPEOP_LDST(evldh, 0x02, 3);
8126 GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
8127 GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
8128 GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
8129 GEN_SPEOP_LDST(evlwhe, 0x08, 2);
8130 GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
8131 GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
8132 GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
8133 GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
8135 GEN_SPEOP_LDST(evstdd, 0x10, 3);
8136 GEN_SPEOP_LDST(evstdw, 0x11, 3);
8137 GEN_SPEOP_LDST(evstdh, 0x12, 3);
8138 GEN_SPEOP_LDST(evstwhe, 0x18, 2);
8139 GEN_SPEOP_LDST(evstwho, 0x1A, 2);
8140 GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
8141 GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
8143 /* Multiply and add - TODO */
8145 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
8146 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8147 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8148 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8149 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8150 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8151 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8152 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8153 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8154 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8155 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8156 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8158 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8159 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8160 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8161 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8162 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8163 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8164 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8165 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8166 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8167 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8168 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8169 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8171 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8172 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8173 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8174 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8175 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
8177 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8178 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8179 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8180 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8181 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8182 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8183 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8184 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8185 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8186 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8187 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8188 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8190 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8191 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8192 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8193 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8195 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8196 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8197 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8198 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8199 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8200 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8201 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8202 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8203 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8204 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8205 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8206 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8208 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
8209 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
8210 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8211 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
8212 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8215 /*** SPE floating-point extension ***/
8216 #if defined(TARGET_PPC64)
8217 #define GEN_SPEFPUOP_CONV_32_32(name) \
8218 static inline void gen_##name(DisasContext *ctx) \
8222 t0 = tcg_temp_new_i32(); \
8223 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8224 gen_helper_##name(t0, cpu_env, t0); \
8225 t1 = tcg_temp_new(); \
8226 tcg_gen_extu_i32_tl(t1, t0); \
8227 tcg_temp_free_i32(t0); \
8228 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8229 0xFFFFFFFF00000000ULL); \
8230 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8231 tcg_temp_free(t1); \
8233 #define GEN_SPEFPUOP_CONV_32_64(name) \
8234 static inline void gen_##name(DisasContext *ctx) \
8238 t0 = tcg_temp_new_i32(); \
8239 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8240 t1 = tcg_temp_new(); \
8241 tcg_gen_extu_i32_tl(t1, t0); \
8242 tcg_temp_free_i32(t0); \
8243 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8244 0xFFFFFFFF00000000ULL); \
8245 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8246 tcg_temp_free(t1); \
8248 #define GEN_SPEFPUOP_CONV_64_32(name) \
8249 static inline void gen_##name(DisasContext *ctx) \
8251 TCGv_i32 t0 = tcg_temp_new_i32(); \
8252 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8253 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8254 tcg_temp_free_i32(t0); \
8256 #define GEN_SPEFPUOP_CONV_64_64(name) \
8257 static inline void gen_##name(DisasContext *ctx) \
8259 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8260 cpu_gpr[rB(ctx->opcode)]); \
8262 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8263 static inline void gen_##name(DisasContext *ctx) \
8267 if (unlikely(!ctx->spe_enabled)) { \
8268 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8271 t0 = tcg_temp_new_i32(); \
8272 t1 = tcg_temp_new_i32(); \
8273 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8274 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8275 gen_helper_##name(t0, cpu_env, t0, t1); \
8276 tcg_temp_free_i32(t1); \
8277 t2 = tcg_temp_new(); \
8278 tcg_gen_extu_i32_tl(t2, t0); \
8279 tcg_temp_free_i32(t0); \
8280 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8281 0xFFFFFFFF00000000ULL); \
8282 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8283 tcg_temp_free(t2); \
8285 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8286 static inline void gen_##name(DisasContext *ctx) \
8288 if (unlikely(!ctx->spe_enabled)) { \
8289 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8292 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8293 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8295 #define GEN_SPEFPUOP_COMP_32(name) \
8296 static inline void gen_##name(DisasContext *ctx) \
8299 if (unlikely(!ctx->spe_enabled)) { \
8300 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8303 t0 = tcg_temp_new_i32(); \
8304 t1 = tcg_temp_new_i32(); \
8305 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8306 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8307 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8308 tcg_temp_free_i32(t0); \
8309 tcg_temp_free_i32(t1); \
8311 #define GEN_SPEFPUOP_COMP_64(name) \
8312 static inline void gen_##name(DisasContext *ctx) \
8314 if (unlikely(!ctx->spe_enabled)) { \
8315 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8318 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8319 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8322 #define GEN_SPEFPUOP_CONV_32_32(name) \
8323 static inline void gen_##name(DisasContext *ctx) \
8325 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8326 cpu_gpr[rB(ctx->opcode)]); \
8328 #define GEN_SPEFPUOP_CONV_32_64(name) \
8329 static inline void gen_##name(DisasContext *ctx) \
8331 TCGv_i64 t0 = tcg_temp_new_i64(); \
8332 gen_load_gpr64(t0, rB(ctx->opcode)); \
8333 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8334 tcg_temp_free_i64(t0); \
8336 #define GEN_SPEFPUOP_CONV_64_32(name) \
8337 static inline void gen_##name(DisasContext *ctx) \
8339 TCGv_i64 t0 = tcg_temp_new_i64(); \
8340 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8341 gen_store_gpr64(rD(ctx->opcode), t0); \
8342 tcg_temp_free_i64(t0); \
8344 #define GEN_SPEFPUOP_CONV_64_64(name) \
8345 static inline void gen_##name(DisasContext *ctx) \
8347 TCGv_i64 t0 = tcg_temp_new_i64(); \
8348 gen_load_gpr64(t0, rB(ctx->opcode)); \
8349 gen_helper_##name(t0, cpu_env, t0); \
8350 gen_store_gpr64(rD(ctx->opcode), t0); \
8351 tcg_temp_free_i64(t0); \
8353 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8354 static inline void gen_##name(DisasContext *ctx) \
8356 if (unlikely(!ctx->spe_enabled)) { \
8357 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8360 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8361 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8363 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8364 static inline void gen_##name(DisasContext *ctx) \
8367 if (unlikely(!ctx->spe_enabled)) { \
8368 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8371 t0 = tcg_temp_new_i64(); \
8372 t1 = tcg_temp_new_i64(); \
8373 gen_load_gpr64(t0, rA(ctx->opcode)); \
8374 gen_load_gpr64(t1, rB(ctx->opcode)); \
8375 gen_helper_##name(t0, cpu_env, t0, t1); \
8376 gen_store_gpr64(rD(ctx->opcode), t0); \
8377 tcg_temp_free_i64(t0); \
8378 tcg_temp_free_i64(t1); \
8380 #define GEN_SPEFPUOP_COMP_32(name) \
8381 static inline void gen_##name(DisasContext *ctx) \
8383 if (unlikely(!ctx->spe_enabled)) { \
8384 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8387 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8388 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8390 #define GEN_SPEFPUOP_COMP_64(name) \
8391 static inline void gen_##name(DisasContext *ctx) \
8394 if (unlikely(!ctx->spe_enabled)) { \
8395 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8398 t0 = tcg_temp_new_i64(); \
8399 t1 = tcg_temp_new_i64(); \
8400 gen_load_gpr64(t0, rA(ctx->opcode)); \
8401 gen_load_gpr64(t1, rB(ctx->opcode)); \
8402 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8403 tcg_temp_free_i64(t0); \
8404 tcg_temp_free_i64(t1); \
8408 /* Single precision floating-point vectors operations */
8410 GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
8411 GEN_SPEFPUOP_ARITH2_64_64(evfssub);
8412 GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
8413 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
8414 static inline void gen_evfsabs(DisasContext *ctx)
8416 if (unlikely(!ctx->spe_enabled)) {
8417 gen_exception(ctx, POWERPC_EXCP_SPEU);
8420 #if defined(TARGET_PPC64)
8421 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
8423 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
8424 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
8427 static inline void gen_evfsnabs(DisasContext *ctx)
8429 if (unlikely(!ctx->spe_enabled)) {
8430 gen_exception(ctx, POWERPC_EXCP_SPEU);
8433 #if defined(TARGET_PPC64)
8434 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
8436 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8437 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
8440 static inline void gen_evfsneg(DisasContext *ctx)
8442 if (unlikely(!ctx->spe_enabled)) {
8443 gen_exception(ctx, POWERPC_EXCP_SPEU);
8446 #if defined(TARGET_PPC64)
8447 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
8449 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8450 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
8455 GEN_SPEFPUOP_CONV_64_64(evfscfui);
8456 GEN_SPEFPUOP_CONV_64_64(evfscfsi);
8457 GEN_SPEFPUOP_CONV_64_64(evfscfuf);
8458 GEN_SPEFPUOP_CONV_64_64(evfscfsf);
8459 GEN_SPEFPUOP_CONV_64_64(evfsctui);
8460 GEN_SPEFPUOP_CONV_64_64(evfsctsi);
8461 GEN_SPEFPUOP_CONV_64_64(evfsctuf);
8462 GEN_SPEFPUOP_CONV_64_64(evfsctsf);
8463 GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
8464 GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
8467 GEN_SPEFPUOP_COMP_64(evfscmpgt);
8468 GEN_SPEFPUOP_COMP_64(evfscmplt);
8469 GEN_SPEFPUOP_COMP_64(evfscmpeq);
8470 GEN_SPEFPUOP_COMP_64(evfststgt);
8471 GEN_SPEFPUOP_COMP_64(evfststlt);
8472 GEN_SPEFPUOP_COMP_64(evfststeq);
8474 /* Opcodes definitions */
8475 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
8476 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
8477 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8478 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
8479 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
8480 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8481 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8482 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8483 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8484 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8485 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8486 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8487 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
8488 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8490 /* Single precision floating-point operations */
8492 GEN_SPEFPUOP_ARITH2_32_32(efsadd);
8493 GEN_SPEFPUOP_ARITH2_32_32(efssub);
8494 GEN_SPEFPUOP_ARITH2_32_32(efsmul);
8495 GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
8496 static inline void gen_efsabs(DisasContext *ctx)
8498 if (unlikely(!ctx->spe_enabled)) {
8499 gen_exception(ctx, POWERPC_EXCP_SPEU);
8502 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
8504 static inline void gen_efsnabs(DisasContext *ctx)
8506 if (unlikely(!ctx->spe_enabled)) {
8507 gen_exception(ctx, POWERPC_EXCP_SPEU);
8510 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8512 static inline void gen_efsneg(DisasContext *ctx)
8514 if (unlikely(!ctx->spe_enabled)) {
8515 gen_exception(ctx, POWERPC_EXCP_SPEU);
8518 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8522 GEN_SPEFPUOP_CONV_32_32(efscfui);
8523 GEN_SPEFPUOP_CONV_32_32(efscfsi);
8524 GEN_SPEFPUOP_CONV_32_32(efscfuf);
8525 GEN_SPEFPUOP_CONV_32_32(efscfsf);
8526 GEN_SPEFPUOP_CONV_32_32(efsctui);
8527 GEN_SPEFPUOP_CONV_32_32(efsctsi);
8528 GEN_SPEFPUOP_CONV_32_32(efsctuf);
8529 GEN_SPEFPUOP_CONV_32_32(efsctsf);
8530 GEN_SPEFPUOP_CONV_32_32(efsctuiz);
8531 GEN_SPEFPUOP_CONV_32_32(efsctsiz);
8532 GEN_SPEFPUOP_CONV_32_64(efscfd);
8535 GEN_SPEFPUOP_COMP_32(efscmpgt);
8536 GEN_SPEFPUOP_COMP_32(efscmplt);
8537 GEN_SPEFPUOP_COMP_32(efscmpeq);
8538 GEN_SPEFPUOP_COMP_32(efststgt);
8539 GEN_SPEFPUOP_COMP_32(efststlt);
8540 GEN_SPEFPUOP_COMP_32(efststeq);
8542 /* Opcodes definitions */
8543 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
8544 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
8545 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8546 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
8547 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
8548 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
8549 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8550 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8551 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8552 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8553 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8554 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8555 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
8556 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8558 /* Double precision floating-point operations */
8560 GEN_SPEFPUOP_ARITH2_64_64(efdadd);
8561 GEN_SPEFPUOP_ARITH2_64_64(efdsub);
8562 GEN_SPEFPUOP_ARITH2_64_64(efdmul);
8563 GEN_SPEFPUOP_ARITH2_64_64(efddiv);
8564 static inline void gen_efdabs(DisasContext *ctx)
8566 if (unlikely(!ctx->spe_enabled)) {
8567 gen_exception(ctx, POWERPC_EXCP_SPEU);
8570 #if defined(TARGET_PPC64)
8571 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
8573 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8574 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
8577 static inline void gen_efdnabs(DisasContext *ctx)
8579 if (unlikely(!ctx->spe_enabled)) {
8580 gen_exception(ctx, POWERPC_EXCP_SPEU);
8583 #if defined(TARGET_PPC64)
8584 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
8586 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8587 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
8590 static inline void gen_efdneg(DisasContext *ctx)
8592 if (unlikely(!ctx->spe_enabled)) {
8593 gen_exception(ctx, POWERPC_EXCP_SPEU);
8596 #if defined(TARGET_PPC64)
8597 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
8599 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8600 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
8605 GEN_SPEFPUOP_CONV_64_32(efdcfui);
8606 GEN_SPEFPUOP_CONV_64_32(efdcfsi);
8607 GEN_SPEFPUOP_CONV_64_32(efdcfuf);
8608 GEN_SPEFPUOP_CONV_64_32(efdcfsf);
8609 GEN_SPEFPUOP_CONV_32_64(efdctui);
8610 GEN_SPEFPUOP_CONV_32_64(efdctsi);
8611 GEN_SPEFPUOP_CONV_32_64(efdctuf);
8612 GEN_SPEFPUOP_CONV_32_64(efdctsf);
8613 GEN_SPEFPUOP_CONV_32_64(efdctuiz);
8614 GEN_SPEFPUOP_CONV_32_64(efdctsiz);
8615 GEN_SPEFPUOP_CONV_64_32(efdcfs);
8616 GEN_SPEFPUOP_CONV_64_64(efdcfuid);
8617 GEN_SPEFPUOP_CONV_64_64(efdcfsid);
8618 GEN_SPEFPUOP_CONV_64_64(efdctuidz);
8619 GEN_SPEFPUOP_CONV_64_64(efdctsidz);
8622 GEN_SPEFPUOP_COMP_64(efdcmpgt);
8623 GEN_SPEFPUOP_COMP_64(efdcmplt);
8624 GEN_SPEFPUOP_COMP_64(efdcmpeq);
8625 GEN_SPEFPUOP_COMP_64(efdtstgt);
8626 GEN_SPEFPUOP_COMP_64(efdtstlt);
8627 GEN_SPEFPUOP_COMP_64(efdtsteq);
8629 /* Opcodes definitions */
8630 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
8631 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8632 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
8633 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
8634 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
8635 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8636 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
8637 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
8638 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8639 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8640 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8641 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8642 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
8643 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
8644 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
8645 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
8647 static opcode_t opcodes[] = {
8648 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
8649 GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
8650 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
8651 GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
8652 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
8653 GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
8654 GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
8655 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8656 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8657 GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8658 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8659 GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
8660 GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
8661 GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
8662 GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
8663 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8664 #if defined(TARGET_PPC64)
8665 GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
8667 GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
8668 GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
8669 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8670 GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8671 GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8672 GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
8673 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
8674 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
8675 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8676 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8677 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8678 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8679 GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
8680 GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
8681 GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
8682 #if defined(TARGET_PPC64)
8683 GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
8684 GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
8685 GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
8687 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8688 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8689 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8690 GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
8691 GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
8692 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
8693 GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
8694 #if defined(TARGET_PPC64)
8695 GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
8696 GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
8697 GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
8698 GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
8699 GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
8701 GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
8702 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
8703 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
8704 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
8705 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
8706 GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
8707 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
8708 GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
8709 GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
8710 GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
8711 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
8712 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
8713 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
8714 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
8715 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
8716 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
8717 #if defined(TARGET_PPC64)
8718 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
8719 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
8720 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
8722 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8723 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8724 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
8725 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
8726 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
8727 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
8728 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
8729 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
8730 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
8731 GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
8732 #if defined(TARGET_PPC64)
8733 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
8734 GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
8736 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
8737 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
8738 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8739 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8740 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
8741 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
8742 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
8743 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
8744 #if defined(TARGET_PPC64)
8745 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
8746 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
8748 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
8749 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
8750 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8751 #if defined(TARGET_PPC64)
8752 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
8753 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
8755 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
8756 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
8757 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
8758 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
8759 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
8760 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
8761 #if defined(TARGET_PPC64)
8762 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
8764 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
8765 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
8766 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
8767 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
8768 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
8769 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE),
8770 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE),
8771 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
8772 GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
8773 GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
8774 GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
8775 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
8776 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
8777 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
8778 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
8779 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
8780 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
8781 #if defined(TARGET_PPC64)
8782 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
8783 GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8785 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
8786 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8788 GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
8789 GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
8790 GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
8792 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
8793 GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
8794 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
8795 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
8796 #if defined(TARGET_PPC64)
8797 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
8798 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
8800 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
8801 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
8802 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
8803 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
8804 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
8805 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
8806 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
8807 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
8808 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
8809 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
8810 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
8811 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
8812 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
8813 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
8814 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
8815 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
8816 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
8817 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
8818 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
8819 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
8820 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
8821 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
8822 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
8823 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
8824 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
8825 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
8826 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
8827 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
8828 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
8829 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
8830 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
8831 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
8832 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
8833 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
8834 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
8835 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
8836 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
8837 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
8838 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
8839 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
8840 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
8841 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
8842 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
8843 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
8844 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
8845 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
8846 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
8847 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
8848 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
8849 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8850 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8851 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
8852 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
8853 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8854 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8855 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
8856 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
8857 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
8858 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
8859 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
8860 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
8861 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
8862 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
8863 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
8864 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
8865 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
8866 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
8867 GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
8868 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
8869 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
8870 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
8871 GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
8872 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
8873 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
8874 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
8875 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
8876 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
8877 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
8878 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
8879 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
8880 GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8881 PPC_NONE, PPC2_BOOKE206),
8882 GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8883 PPC_NONE, PPC2_BOOKE206),
8884 GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8885 PPC_NONE, PPC2_BOOKE206),
8886 GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8887 PPC_NONE, PPC2_BOOKE206),
8888 GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8889 PPC_NONE, PPC2_BOOKE206),
8890 GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8891 PPC_NONE, PPC2_PRCNTL),
8892 GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8893 PPC_NONE, PPC2_PRCNTL),
8894 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
8895 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
8896 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
8897 GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
8898 PPC_BOOKE, PPC2_BOOKE206),
8899 GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
8900 GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8901 PPC_BOOKE, PPC2_BOOKE206),
8902 GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
8903 GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
8904 GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
8905 GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
8906 GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC),
8907 GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
8908 GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
8909 GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
8910 GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
8911 GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
8913 #undef GEN_INT_ARITH_ADD
8914 #undef GEN_INT_ARITH_ADD_CONST
8915 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8916 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8917 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8918 add_ca, compute_ca, compute_ov) \
8919 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8920 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
8921 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
8922 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
8923 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
8924 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
8925 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
8926 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
8927 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
8928 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
8929 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
8931 #undef GEN_INT_ARITH_DIVW
8932 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8933 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8934 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
8935 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
8936 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
8937 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
8939 #if defined(TARGET_PPC64)
8940 #undef GEN_INT_ARITH_DIVD
8941 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8942 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8943 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
8944 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
8945 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
8946 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
8948 #undef GEN_INT_ARITH_MUL_HELPER
8949 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8950 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8951 GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
8952 GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
8953 GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
8956 #undef GEN_INT_ARITH_SUBF
8957 #undef GEN_INT_ARITH_SUBF_CONST
8958 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8959 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8960 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8961 add_ca, compute_ca, compute_ov) \
8962 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8963 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
8964 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
8965 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
8966 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
8967 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
8968 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
8969 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
8970 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
8971 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
8972 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
8976 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8977 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8978 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8979 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8980 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
8981 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
8982 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
8983 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
8984 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
8985 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
8986 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
8987 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
8988 #if defined(TARGET_PPC64)
8989 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
8992 #if defined(TARGET_PPC64)
8995 #define GEN_PPC64_R2(name, opc1, opc2) \
8996 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8997 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8999 #define GEN_PPC64_R4(name, opc1, opc2) \
9000 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9001 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
9003 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9005 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
9007 GEN_PPC64_R4(rldicl, 0x1E, 0x00),
9008 GEN_PPC64_R4(rldicr, 0x1E, 0x02),
9009 GEN_PPC64_R4(rldic, 0x1E, 0x04),
9010 GEN_PPC64_R2(rldcl, 0x1E, 0x08),
9011 GEN_PPC64_R2(rldcr, 0x1E, 0x09),
9012 GEN_PPC64_R4(rldimi, 0x1E, 0x06),
9015 #undef _GEN_FLOAT_ACB
9016 #undef GEN_FLOAT_ACB
9017 #undef _GEN_FLOAT_AB
9019 #undef _GEN_FLOAT_AC
9023 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
9024 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
9025 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
9026 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
9027 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
9028 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9029 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9030 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
9031 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9032 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9033 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9034 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9035 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
9036 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9037 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9038 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
9039 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
9040 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
9041 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
9043 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
9044 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
9045 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
9046 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
9047 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
9048 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
9049 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
9050 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
9051 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
9052 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
9053 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
9054 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
9055 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
9056 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
9057 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
9058 #if defined(TARGET_PPC64)
9059 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
9060 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
9061 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
9063 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
9064 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
9065 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
9066 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
9073 #define GEN_LD(name, ldop, opc, type) \
9074 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9075 #define GEN_LDU(name, ldop, opc, type) \
9076 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9077 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
9078 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9079 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
9080 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9081 #define GEN_LDS(name, ldop, op, type) \
9082 GEN_LD(name, ldop, op | 0x20, type) \
9083 GEN_LDU(name, ldop, op | 0x21, type) \
9084 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
9085 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
9087 GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
9088 GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
9089 GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
9090 GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
9091 #if defined(TARGET_PPC64)
9092 GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
9093 GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
9094 GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
9095 GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
9096 GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
9098 GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
9099 GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
9106 #define GEN_ST(name, stop, opc, type) \
9107 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9108 #define GEN_STU(name, stop, opc, type) \
9109 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
9110 #define GEN_STUX(name, stop, opc2, opc3, type) \
9111 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9112 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
9113 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9114 #define GEN_STS(name, stop, op, type) \
9115 GEN_ST(name, stop, op | 0x20, type) \
9116 GEN_STU(name, stop, op | 0x21, type) \
9117 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
9118 GEN_STX(name, stop, 0x17, op | 0x00, type)
9120 GEN_STS(stb, st8, 0x06, PPC_INTEGER)
9121 GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
9122 GEN_STS(stw, st32, 0x04, PPC_INTEGER)
9123 #if defined(TARGET_PPC64)
9124 GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
9125 GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
9126 GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
9128 GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
9129 GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
9136 #define GEN_LDF(name, ldop, opc, type) \
9137 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9138 #define GEN_LDUF(name, ldop, opc, type) \
9139 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9140 #define GEN_LDUXF(name, ldop, opc, type) \
9141 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9142 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
9143 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9144 #define GEN_LDFS(name, ldop, op, type) \
9145 GEN_LDF(name, ldop, op | 0x20, type) \
9146 GEN_LDUF(name, ldop, op | 0x21, type) \
9147 GEN_LDUXF(name, ldop, op | 0x01, type) \
9148 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
9150 GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
9151 GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
9152 GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
9153 GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
9154 GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
9161 #define GEN_STF(name, stop, opc, type) \
9162 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9163 #define GEN_STUF(name, stop, opc, type) \
9164 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9165 #define GEN_STUXF(name, stop, opc, type) \
9166 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9167 #define GEN_STXF(name, stop, opc2, opc3, type) \
9168 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9169 #define GEN_STFS(name, stop, op, type) \
9170 GEN_STF(name, stop, op | 0x20, type) \
9171 GEN_STUF(name, stop, op | 0x21, type) \
9172 GEN_STUXF(name, stop, op | 0x01, type) \
9173 GEN_STXF(name, stop, 0x17, op | 0x00, type)
9175 GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
9176 GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
9177 GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
9178 GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
9179 GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
9182 #define GEN_CRLOGIC(name, tcg_op, opc) \
9183 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
9184 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
9185 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
9186 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
9187 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
9188 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
9189 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
9190 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
9191 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
9193 #undef GEN_MAC_HANDLER
9194 #define GEN_MAC_HANDLER(name, opc2, opc3) \
9195 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
9196 GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
9197 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
9198 GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
9199 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
9200 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
9201 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
9202 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
9203 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
9204 GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
9205 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
9206 GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
9207 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
9208 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
9209 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
9210 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
9211 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
9212 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
9213 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
9214 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
9215 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
9216 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
9217 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
9218 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
9219 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
9220 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
9221 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
9222 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
9223 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
9224 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
9225 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
9226 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
9227 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
9228 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
9229 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
9230 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
9231 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
9232 GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
9233 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
9234 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
9235 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
9236 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
9237 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
9243 #define GEN_VR_LDX(name, opc2, opc3) \
9244 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9245 #define GEN_VR_STX(name, opc2, opc3) \
9246 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9247 #define GEN_VR_LVE(name, opc2, opc3) \
9248 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9249 #define GEN_VR_STVE(name, opc2, opc3) \
9250 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9251 GEN_VR_LDX(lvx, 0x07, 0x03),
9252 GEN_VR_LDX(lvxl, 0x07, 0x0B),
9253 GEN_VR_LVE(bx, 0x07, 0x00),
9254 GEN_VR_LVE(hx, 0x07, 0x01),
9255 GEN_VR_LVE(wx, 0x07, 0x02),
9256 GEN_VR_STX(svx, 0x07, 0x07),
9257 GEN_VR_STX(svxl, 0x07, 0x0F),
9258 GEN_VR_STVE(bx, 0x07, 0x04),
9259 GEN_VR_STVE(hx, 0x07, 0x05),
9260 GEN_VR_STVE(wx, 0x07, 0x06),
9262 #undef GEN_VX_LOGICAL
9263 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9264 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9265 GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
9266 GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
9267 GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
9268 GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
9269 GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
9272 #define GEN_VXFORM(name, opc2, opc3) \
9273 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9274 GEN_VXFORM(vaddubm, 0, 0),
9275 GEN_VXFORM(vadduhm, 0, 1),
9276 GEN_VXFORM(vadduwm, 0, 2),
9277 GEN_VXFORM(vsububm, 0, 16),
9278 GEN_VXFORM(vsubuhm, 0, 17),
9279 GEN_VXFORM(vsubuwm, 0, 18),
9280 GEN_VXFORM(vmaxub, 1, 0),
9281 GEN_VXFORM(vmaxuh, 1, 1),
9282 GEN_VXFORM(vmaxuw, 1, 2),
9283 GEN_VXFORM(vmaxsb, 1, 4),
9284 GEN_VXFORM(vmaxsh, 1, 5),
9285 GEN_VXFORM(vmaxsw, 1, 6),
9286 GEN_VXFORM(vminub, 1, 8),
9287 GEN_VXFORM(vminuh, 1, 9),
9288 GEN_VXFORM(vminuw, 1, 10),
9289 GEN_VXFORM(vminsb, 1, 12),
9290 GEN_VXFORM(vminsh, 1, 13),
9291 GEN_VXFORM(vminsw, 1, 14),
9292 GEN_VXFORM(vavgub, 1, 16),
9293 GEN_VXFORM(vavguh, 1, 17),
9294 GEN_VXFORM(vavguw, 1, 18),
9295 GEN_VXFORM(vavgsb, 1, 20),
9296 GEN_VXFORM(vavgsh, 1, 21),
9297 GEN_VXFORM(vavgsw, 1, 22),
9298 GEN_VXFORM(vmrghb, 6, 0),
9299 GEN_VXFORM(vmrghh, 6, 1),
9300 GEN_VXFORM(vmrghw, 6, 2),
9301 GEN_VXFORM(vmrglb, 6, 4),
9302 GEN_VXFORM(vmrglh, 6, 5),
9303 GEN_VXFORM(vmrglw, 6, 6),
9304 GEN_VXFORM(vmuloub, 4, 0),
9305 GEN_VXFORM(vmulouh, 4, 1),
9306 GEN_VXFORM(vmulosb, 4, 4),
9307 GEN_VXFORM(vmulosh, 4, 5),
9308 GEN_VXFORM(vmuleub, 4, 8),
9309 GEN_VXFORM(vmuleuh, 4, 9),
9310 GEN_VXFORM(vmulesb, 4, 12),
9311 GEN_VXFORM(vmulesh, 4, 13),
9312 GEN_VXFORM(vslb, 2, 4),
9313 GEN_VXFORM(vslh, 2, 5),
9314 GEN_VXFORM(vslw, 2, 6),
9315 GEN_VXFORM(vsrb, 2, 8),
9316 GEN_VXFORM(vsrh, 2, 9),
9317 GEN_VXFORM(vsrw, 2, 10),
9318 GEN_VXFORM(vsrab, 2, 12),
9319 GEN_VXFORM(vsrah, 2, 13),
9320 GEN_VXFORM(vsraw, 2, 14),
9321 GEN_VXFORM(vslo, 6, 16),
9322 GEN_VXFORM(vsro, 6, 17),
9323 GEN_VXFORM(vaddcuw, 0, 6),
9324 GEN_VXFORM(vsubcuw, 0, 22),
9325 GEN_VXFORM(vaddubs, 0, 8),
9326 GEN_VXFORM(vadduhs, 0, 9),
9327 GEN_VXFORM(vadduws, 0, 10),
9328 GEN_VXFORM(vaddsbs, 0, 12),
9329 GEN_VXFORM(vaddshs, 0, 13),
9330 GEN_VXFORM(vaddsws, 0, 14),
9331 GEN_VXFORM(vsububs, 0, 24),
9332 GEN_VXFORM(vsubuhs, 0, 25),
9333 GEN_VXFORM(vsubuws, 0, 26),
9334 GEN_VXFORM(vsubsbs, 0, 28),
9335 GEN_VXFORM(vsubshs, 0, 29),
9336 GEN_VXFORM(vsubsws, 0, 30),
9337 GEN_VXFORM(vrlb, 2, 0),
9338 GEN_VXFORM(vrlh, 2, 1),
9339 GEN_VXFORM(vrlw, 2, 2),
9340 GEN_VXFORM(vsl, 2, 7),
9341 GEN_VXFORM(vsr, 2, 11),
9342 GEN_VXFORM(vpkuhum, 7, 0),
9343 GEN_VXFORM(vpkuwum, 7, 1),
9344 GEN_VXFORM(vpkuhus, 7, 2),
9345 GEN_VXFORM(vpkuwus, 7, 3),
9346 GEN_VXFORM(vpkshus, 7, 4),
9347 GEN_VXFORM(vpkswus, 7, 5),
9348 GEN_VXFORM(vpkshss, 7, 6),
9349 GEN_VXFORM(vpkswss, 7, 7),
9350 GEN_VXFORM(vpkpx, 7, 12),
9351 GEN_VXFORM(vsum4ubs, 4, 24),
9352 GEN_VXFORM(vsum4sbs, 4, 28),
9353 GEN_VXFORM(vsum4shs, 4, 25),
9354 GEN_VXFORM(vsum2sws, 4, 26),
9355 GEN_VXFORM(vsumsws, 4, 30),
9356 GEN_VXFORM(vaddfp, 5, 0),
9357 GEN_VXFORM(vsubfp, 5, 1),
9358 GEN_VXFORM(vmaxfp, 5, 16),
9359 GEN_VXFORM(vminfp, 5, 17),
9363 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
9364 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
9365 #define GEN_VXRFORM(name, opc2, opc3) \
9366 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
9367 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
9368 GEN_VXRFORM(vcmpequb, 3, 0)
9369 GEN_VXRFORM(vcmpequh, 3, 1)
9370 GEN_VXRFORM(vcmpequw, 3, 2)
9371 GEN_VXRFORM(vcmpgtsb, 3, 12)
9372 GEN_VXRFORM(vcmpgtsh, 3, 13)
9373 GEN_VXRFORM(vcmpgtsw, 3, 14)
9374 GEN_VXRFORM(vcmpgtub, 3, 8)
9375 GEN_VXRFORM(vcmpgtuh, 3, 9)
9376 GEN_VXRFORM(vcmpgtuw, 3, 10)
9377 GEN_VXRFORM(vcmpeqfp, 3, 3)
9378 GEN_VXRFORM(vcmpgefp, 3, 7)
9379 GEN_VXRFORM(vcmpgtfp, 3, 11)
9380 GEN_VXRFORM(vcmpbfp, 3, 15)
9382 #undef GEN_VXFORM_SIMM
9383 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
9384 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9385 GEN_VXFORM_SIMM(vspltisb, 6, 12),
9386 GEN_VXFORM_SIMM(vspltish, 6, 13),
9387 GEN_VXFORM_SIMM(vspltisw, 6, 14),
9389 #undef GEN_VXFORM_NOA
9390 #define GEN_VXFORM_NOA(name, opc2, opc3) \
9391 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9392 GEN_VXFORM_NOA(vupkhsb, 7, 8),
9393 GEN_VXFORM_NOA(vupkhsh, 7, 9),
9394 GEN_VXFORM_NOA(vupklsb, 7, 10),
9395 GEN_VXFORM_NOA(vupklsh, 7, 11),
9396 GEN_VXFORM_NOA(vupkhpx, 7, 13),
9397 GEN_VXFORM_NOA(vupklpx, 7, 15),
9398 GEN_VXFORM_NOA(vrefp, 5, 4),
9399 GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
9400 GEN_VXFORM_NOA(vexptefp, 5, 6),
9401 GEN_VXFORM_NOA(vlogefp, 5, 7),
9402 GEN_VXFORM_NOA(vrfim, 5, 8),
9403 GEN_VXFORM_NOA(vrfin, 5, 9),
9404 GEN_VXFORM_NOA(vrfip, 5, 10),
9405 GEN_VXFORM_NOA(vrfiz, 5, 11),
9407 #undef GEN_VXFORM_UIMM
9408 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
9409 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9410 GEN_VXFORM_UIMM(vspltb, 6, 8),
9411 GEN_VXFORM_UIMM(vsplth, 6, 9),
9412 GEN_VXFORM_UIMM(vspltw, 6, 10),
9413 GEN_VXFORM_UIMM(vcfux, 5, 12),
9414 GEN_VXFORM_UIMM(vcfsx, 5, 13),
9415 GEN_VXFORM_UIMM(vctuxs, 5, 14),
9416 GEN_VXFORM_UIMM(vctsxs, 5, 15),
9418 #undef GEN_VAFORM_PAIRED
9419 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9420 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9421 GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
9422 GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
9423 GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
9424 GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
9425 GEN_VAFORM_PAIRED(vsel, vperm, 21),
9426 GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
9429 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
9430 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
9431 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9432 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9433 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9434 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9435 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
9436 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
9437 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
9438 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
9439 GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
9440 GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
9441 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9442 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9443 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9444 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
9445 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
9446 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
9447 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
9448 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9449 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9450 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9451 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9452 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9453 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
9454 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
9455 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9456 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9457 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
9458 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
9459 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
9461 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
9462 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
9463 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
9464 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
9465 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
9466 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9467 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9468 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9469 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9470 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9471 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9472 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9473 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
9474 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9476 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
9477 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
9478 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
9479 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
9480 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
9481 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
9482 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9483 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9484 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9485 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9486 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9487 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9488 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
9489 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9491 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
9492 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9493 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
9494 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
9495 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
9496 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9497 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
9498 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
9499 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9500 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9501 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9502 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9503 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
9504 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
9505 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
9506 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
9508 #undef GEN_SPEOP_LDST
9509 #define GEN_SPEOP_LDST(name, opc2, sh) \
9510 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9511 GEN_SPEOP_LDST(evldd, 0x00, 3),
9512 GEN_SPEOP_LDST(evldw, 0x01, 3),
9513 GEN_SPEOP_LDST(evldh, 0x02, 3),
9514 GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
9515 GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
9516 GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
9517 GEN_SPEOP_LDST(evlwhe, 0x08, 2),
9518 GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
9519 GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
9520 GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
9521 GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
9523 GEN_SPEOP_LDST(evstdd, 0x10, 3),
9524 GEN_SPEOP_LDST(evstdw, 0x11, 3),
9525 GEN_SPEOP_LDST(evstdh, 0x12, 3),
9526 GEN_SPEOP_LDST(evstwhe, 0x18, 2),
9527 GEN_SPEOP_LDST(evstwho, 0x1A, 2),
9528 GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
9529 GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
9532 #include "helper_regs.h"
9533 #include "translate_init.c"
9535 /*****************************************************************************/
9536 /* Misc PowerPC helpers */
9537 void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
9543 PowerPCCPU *cpu = POWERPC_CPU(cs);
9544 CPUPPCState *env = &cpu->env;
9547 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9548 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
9549 env->nip, env->lr, env->ctr, cpu_read_xer(env));
9550 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
9551 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
9552 env->hflags, env->mmu_idx);
9553 #if !defined(NO_TIMER_DUMP)
9554 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
9555 #if !defined(CONFIG_USER_ONLY)
9559 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
9560 #if !defined(CONFIG_USER_ONLY)
9561 , cpu_ppc_load_decr(env)
9565 for (i = 0; i < 32; i++) {
9566 if ((i & (RGPL - 1)) == 0)
9567 cpu_fprintf(f, "GPR%02d", i);
9568 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
9569 if ((i & (RGPL - 1)) == (RGPL - 1))
9570 cpu_fprintf(f, "\n");
9572 cpu_fprintf(f, "CR ");
9573 for (i = 0; i < 8; i++)
9574 cpu_fprintf(f, "%01x", env->crf[i]);
9575 cpu_fprintf(f, " [");
9576 for (i = 0; i < 8; i++) {
9578 if (env->crf[i] & 0x08)
9580 else if (env->crf[i] & 0x04)
9582 else if (env->crf[i] & 0x02)
9584 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
9586 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
9588 for (i = 0; i < 32; i++) {
9589 if ((i & (RFPL - 1)) == 0)
9590 cpu_fprintf(f, "FPR%02d", i);
9591 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
9592 if ((i & (RFPL - 1)) == (RFPL - 1))
9593 cpu_fprintf(f, "\n");
9595 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
9596 #if !defined(CONFIG_USER_ONLY)
9597 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
9598 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
9599 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
9600 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
9602 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
9603 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
9604 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
9605 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
9607 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
9608 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
9609 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
9610 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
9612 if (env->excp_model == POWERPC_EXCP_BOOKE) {
9613 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
9614 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
9615 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
9616 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
9618 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
9619 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
9620 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
9621 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
9623 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
9624 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
9625 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
9626 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
9628 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
9629 " EPR " TARGET_FMT_lx "\n",
9630 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
9631 env->spr[SPR_BOOKE_EPR]);
9634 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
9635 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
9636 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
9637 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
9640 * IVORs are left out as they are large and do not change often --
9641 * they can be read with "p $ivor0", "p $ivor1", etc.
9645 #if defined(TARGET_PPC64)
9646 if (env->flags & POWERPC_FLAG_CFAR) {
9647 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
9651 switch (env->mmu_model) {
9652 case POWERPC_MMU_32B:
9653 case POWERPC_MMU_601:
9654 case POWERPC_MMU_SOFT_6xx:
9655 case POWERPC_MMU_SOFT_74xx:
9656 #if defined(TARGET_PPC64)
9657 case POWERPC_MMU_64B:
9659 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx "\n", env->spr[SPR_SDR1]);
9661 case POWERPC_MMU_BOOKE206:
9662 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
9663 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
9664 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
9665 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
9667 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
9668 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
9669 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
9670 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
9672 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
9673 " TLB1CFG " TARGET_FMT_lx "\n",
9674 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
9675 env->spr[SPR_BOOKE_TLB1CFG]);
9686 void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
9687 fprintf_function cpu_fprintf, int flags)
9689 #if defined(DO_PPC_STATISTICS)
9690 PowerPCCPU *cpu = POWERPC_CPU(cs);
9691 opc_handler_t **t1, **t2, **t3, *handler;
9694 t1 = cpu->env.opcodes;
9695 for (op1 = 0; op1 < 64; op1++) {
9697 if (is_indirect_opcode(handler)) {
9698 t2 = ind_table(handler);
9699 for (op2 = 0; op2 < 32; op2++) {
9701 if (is_indirect_opcode(handler)) {
9702 t3 = ind_table(handler);
9703 for (op3 = 0; op3 < 32; op3++) {
9705 if (handler->count == 0)
9707 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
9708 "%016" PRIx64 " %" PRId64 "\n",
9709 op1, op2, op3, op1, (op3 << 5) | op2,
9711 handler->count, handler->count);
9714 if (handler->count == 0)
9716 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
9717 "%016" PRIx64 " %" PRId64 "\n",
9718 op1, op2, op1, op2, handler->oname,
9719 handler->count, handler->count);
9723 if (handler->count == 0)
9725 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
9727 op1, op1, handler->oname,
9728 handler->count, handler->count);
9734 /*****************************************************************************/
9735 static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
9736 TranslationBlock *tb,
9739 CPUState *cs = CPU(cpu);
9740 CPUPPCState *env = &cpu->env;
9741 DisasContext ctx, *ctxp = &ctx;
9742 opc_handler_t **table, *handler;
9743 target_ulong pc_start;
9744 uint16_t *gen_opc_end;
9751 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
9754 ctx.exception = POWERPC_EXCP_NONE;
9755 ctx.spr_cb = env->spr_cb;
9756 ctx.mem_idx = env->mmu_idx;
9757 ctx.insns_flags = env->insns_flags;
9758 ctx.insns_flags2 = env->insns_flags2;
9759 ctx.access_type = -1;
9760 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
9761 #if defined(TARGET_PPC64)
9762 ctx.sf_mode = msr_is_64bit(env, env->msr);
9763 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9765 ctx.fpu_enabled = msr_fp;
9766 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
9767 ctx.spe_enabled = msr_spe;
9769 ctx.spe_enabled = 0;
9770 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
9771 ctx.altivec_enabled = msr_vr;
9773 ctx.altivec_enabled = 0;
9774 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
9775 ctx.vsx_enabled = msr_vsx;
9777 ctx.vsx_enabled = 0;
9779 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
9780 ctx.singlestep_enabled = CPU_SINGLE_STEP;
9782 ctx.singlestep_enabled = 0;
9783 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
9784 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
9785 if (unlikely(cs->singlestep_enabled)) {
9786 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
9788 #if defined (DO_SINGLE_STEP) && 0
9789 /* Single step trace mode */
9793 max_insns = tb->cflags & CF_COUNT_MASK;
9795 max_insns = CF_COUNT_MASK;
9798 /* Set env in case of segfault during code fetch */
9799 while (ctx.exception == POWERPC_EXCP_NONE
9800 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
9801 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
9802 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
9803 if (bp->pc == ctx.nip) {
9804 gen_debug_exception(ctxp);
9809 if (unlikely(search_pc)) {
9810 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9814 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9816 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
9817 tcg_ctx.gen_opc_instr_start[lj] = 1;
9818 tcg_ctx.gen_opc_icount[lj] = num_insns;
9820 LOG_DISAS("----------------\n");
9821 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
9822 ctx.nip, ctx.mem_idx, (int)msr_ir);
9823 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
9825 if (unlikely(ctx.le_mode)) {
9826 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
9828 ctx.opcode = cpu_ldl_code(env, ctx.nip);
9830 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9831 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
9832 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
9833 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
9834 tcg_gen_debug_insn_start(ctx.nip);
9837 table = env->opcodes;
9839 handler = table[opc1(ctx.opcode)];
9840 if (is_indirect_opcode(handler)) {
9841 table = ind_table(handler);
9842 handler = table[opc2(ctx.opcode)];
9843 if (is_indirect_opcode(handler)) {
9844 table = ind_table(handler);
9845 handler = table[opc3(ctx.opcode)];
9848 /* Is opcode *REALLY* valid ? */
9849 if (unlikely(handler->handler == &gen_invalid)) {
9850 if (qemu_log_enabled()) {
9851 qemu_log("invalid/unsupported opcode: "
9852 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
9853 opc1(ctx.opcode), opc2(ctx.opcode),
9854 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
9859 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
9860 inval = handler->inval2;
9862 inval = handler->inval1;
9865 if (unlikely((ctx.opcode & inval) != 0)) {
9866 if (qemu_log_enabled()) {
9867 qemu_log("invalid bits: %08x for opcode: "
9868 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
9869 ctx.opcode & inval, opc1(ctx.opcode),
9870 opc2(ctx.opcode), opc3(ctx.opcode),
9871 ctx.opcode, ctx.nip - 4);
9873 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
9877 (*(handler->handler))(&ctx);
9878 #if defined(DO_PPC_STATISTICS)
9881 /* Check trace mode exceptions */
9882 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
9883 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
9884 ctx.exception != POWERPC_SYSCALL &&
9885 ctx.exception != POWERPC_EXCP_TRAP &&
9886 ctx.exception != POWERPC_EXCP_BRANCH)) {
9887 gen_exception(ctxp, POWERPC_EXCP_TRACE);
9888 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
9889 (cs->singlestep_enabled) ||
9891 num_insns >= max_insns)) {
9892 /* if we reach a page boundary or are single stepping, stop
9898 if (tb->cflags & CF_LAST_IO)
9900 if (ctx.exception == POWERPC_EXCP_NONE) {
9901 gen_goto_tb(&ctx, 0, ctx.nip);
9902 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
9903 if (unlikely(cs->singlestep_enabled)) {
9904 gen_debug_exception(ctxp);
9906 /* Generate the return instruction */
9909 gen_tb_end(tb, num_insns);
9910 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
9911 if (unlikely(search_pc)) {
9912 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9915 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9917 tb->size = ctx.nip - pc_start;
9918 tb->icount = num_insns;
9920 #if defined(DEBUG_DISAS)
9921 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
9923 flags = env->bfd_mach;
9924 flags |= ctx.le_mode << 16;
9925 qemu_log("IN: %s\n", lookup_symbol(pc_start));
9926 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
9932 void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
9934 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
9937 void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
9939 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
9942 void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
9944 env->nip = tcg_ctx.gen_opc_pc[pc_pos];