]> Git Repo - qemu.git/blame - target-ppc/translate.c
target-ppc: Introduce DFP Shift Significand
[qemu.git] / target-ppc / translate.c
CommitLineData
79aceca5 1/*
3fc6c082 2 * PowerPC emulation for qemu: main translation routines.
5fafdf24 3 *
76a66253 4 * Copyright (c) 2003-2007 Jocelyn Mayer
90dc8812 5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
79aceca5
FB
6 *
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.
11 *
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.
16 *
17 * You should have received a copy of the GNU Lesser General Public
8167ee88 18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
79aceca5 19 */
c6a1c22b 20
79aceca5 21#include "cpu.h"
76cad711 22#include "disas/disas.h"
57fec1fe 23#include "tcg-op.h"
1de7afc9 24#include "qemu/host-utils.h"
f08b6170 25#include "exec/cpu_ldst.h"
79aceca5 26
2ef6175a
RH
27#include "exec/helper-proto.h"
28#include "exec/helper-gen.h"
a7812ae4 29
8cbcb4fa
AJ
30#define CPU_SINGLE_STEP 0x1
31#define CPU_BRANCH_STEP 0x2
32#define GDBSTUB_SINGLE_STEP 0x4
33
a750fc0b 34/* Include definitions for instructions classes and implementations flags */
9fddaa0c 35//#define PPC_DEBUG_DISAS
76a66253 36//#define DO_PPC_STATISTICS
79aceca5 37
d12d51d5 38#ifdef PPC_DEBUG_DISAS
93fcfe39 39# define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
d12d51d5
AL
40#else
41# define LOG_DISAS(...) do { } while (0)
42#endif
a750fc0b
JM
43/*****************************************************************************/
44/* Code translation helpers */
c53be334 45
f78fb44e 46/* global register indexes */
a7812ae4 47static TCGv_ptr cpu_env;
1d542695 48static char cpu_reg_names[10*3 + 22*4 /* GPR */
f78fb44e 49#if !defined(TARGET_PPC64)
1d542695 50 + 10*4 + 22*5 /* SPE GPRh */
f78fb44e 51#endif
a5e26afa 52 + 10*4 + 22*5 /* FPR */
47e4661c 53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
472b24ce 54 + 10*5 + 22*6 /* VSR */
47e4661c 55 + 8*5 /* CRF */];
f78fb44e
AJ
56static TCGv cpu_gpr[32];
57#if !defined(TARGET_PPC64)
58static TCGv cpu_gprh[32];
59#endif
a7812ae4
PB
60static TCGv_i64 cpu_fpr[32];
61static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
472b24ce 62static TCGv_i64 cpu_vsr[32];
a7812ae4 63static TCGv_i32 cpu_crf[8];
bd568f18 64static TCGv cpu_nip;
6527f6ea 65static TCGv cpu_msr;
cfdcd37a
AJ
66static TCGv cpu_ctr;
67static TCGv cpu_lr;
697ab892
DG
68#if defined(TARGET_PPC64)
69static TCGv cpu_cfar;
70#endif
da91a00f 71static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
cf360a32 72static TCGv cpu_reserve;
30304420 73static TCGv cpu_fpscr;
a7859e89 74static TCGv_i32 cpu_access_type;
f78fb44e 75
022c62cb 76#include "exec/gen-icount.h"
2e70f6ef
PB
77
78void ppc_translate_init(void)
79{
f78fb44e
AJ
80 int i;
81 char* p;
2dc766da 82 size_t cpu_reg_names_size;
b2437bf2 83 static int done_init = 0;
f78fb44e 84
2e70f6ef
PB
85 if (done_init)
86 return;
f78fb44e 87
a7812ae4 88 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
a7812ae4 89
f78fb44e 90 p = cpu_reg_names;
2dc766da 91 cpu_reg_names_size = sizeof(cpu_reg_names);
47e4661c
AJ
92
93 for (i = 0; i < 8; i++) {
2dc766da 94 snprintf(p, cpu_reg_names_size, "crf%d", i);
a7812ae4 95 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 96 offsetof(CPUPPCState, crf[i]), p);
47e4661c 97 p += 5;
2dc766da 98 cpu_reg_names_size -= 5;
47e4661c
AJ
99 }
100
f78fb44e 101 for (i = 0; i < 32; i++) {
2dc766da 102 snprintf(p, cpu_reg_names_size, "r%d", i);
a7812ae4 103 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
1328c2bf 104 offsetof(CPUPPCState, gpr[i]), p);
f78fb44e 105 p += (i < 10) ? 3 : 4;
2dc766da 106 cpu_reg_names_size -= (i < 10) ? 3 : 4;
f78fb44e 107#if !defined(TARGET_PPC64)
2dc766da 108 snprintf(p, cpu_reg_names_size, "r%dH", i);
a7812ae4 109 cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 110 offsetof(CPUPPCState, gprh[i]), p);
f78fb44e 111 p += (i < 10) ? 4 : 5;
2dc766da 112 cpu_reg_names_size -= (i < 10) ? 4 : 5;
f78fb44e 113#endif
1d542695 114
2dc766da 115 snprintf(p, cpu_reg_names_size, "fp%d", i);
a7812ae4 116 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 117 offsetof(CPUPPCState, fpr[i]), p);
ec1ac72d 118 p += (i < 10) ? 4 : 5;
2dc766da 119 cpu_reg_names_size -= (i < 10) ? 4 : 5;
a5e26afa 120
2dc766da 121 snprintf(p, cpu_reg_names_size, "avr%dH", i);
e2542fe2 122#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 123 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 124 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 125#else
a7812ae4 126 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 127 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 128#endif
1d542695 129 p += (i < 10) ? 6 : 7;
2dc766da 130 cpu_reg_names_size -= (i < 10) ? 6 : 7;
ec1ac72d 131
2dc766da 132 snprintf(p, cpu_reg_names_size, "avr%dL", i);
e2542fe2 133#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 134 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 135 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 136#else
a7812ae4 137 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 138 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 139#endif
1d542695 140 p += (i < 10) ? 6 : 7;
2dc766da 141 cpu_reg_names_size -= (i < 10) ? 6 : 7;
472b24ce
TM
142 snprintf(p, cpu_reg_names_size, "vsr%d", i);
143 cpu_vsr[i] = tcg_global_mem_new_i64(TCG_AREG0,
144 offsetof(CPUPPCState, vsr[i]), p);
145 p += (i < 10) ? 5 : 6;
146 cpu_reg_names_size -= (i < 10) ? 5 : 6;
f78fb44e 147 }
f10dc08e 148
a7812ae4 149 cpu_nip = tcg_global_mem_new(TCG_AREG0,
1328c2bf 150 offsetof(CPUPPCState, nip), "nip");
bd568f18 151
6527f6ea 152 cpu_msr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 153 offsetof(CPUPPCState, msr), "msr");
6527f6ea 154
a7812ae4 155 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 156 offsetof(CPUPPCState, ctr), "ctr");
cfdcd37a 157
a7812ae4 158 cpu_lr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 159 offsetof(CPUPPCState, lr), "lr");
cfdcd37a 160
697ab892
DG
161#if defined(TARGET_PPC64)
162 cpu_cfar = tcg_global_mem_new(TCG_AREG0,
1328c2bf 163 offsetof(CPUPPCState, cfar), "cfar");
697ab892
DG
164#endif
165
a7812ae4 166 cpu_xer = tcg_global_mem_new(TCG_AREG0,
1328c2bf 167 offsetof(CPUPPCState, xer), "xer");
da91a00f
RH
168 cpu_so = tcg_global_mem_new(TCG_AREG0,
169 offsetof(CPUPPCState, so), "SO");
170 cpu_ov = tcg_global_mem_new(TCG_AREG0,
171 offsetof(CPUPPCState, ov), "OV");
172 cpu_ca = tcg_global_mem_new(TCG_AREG0,
173 offsetof(CPUPPCState, ca), "CA");
3d7b417e 174
cf360a32 175 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
1328c2bf 176 offsetof(CPUPPCState, reserve_addr),
18b21a2f 177 "reserve_addr");
cf360a32 178
30304420
DG
179 cpu_fpscr = tcg_global_mem_new(TCG_AREG0,
180 offsetof(CPUPPCState, fpscr), "fpscr");
e1571908 181
a7859e89 182 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 183 offsetof(CPUPPCState, access_type), "access_type");
a7859e89 184
2e70f6ef
PB
185 done_init = 1;
186}
187
79aceca5
FB
188/* internal defines */
189typedef struct DisasContext {
190 struct TranslationBlock *tb;
0fa85d43 191 target_ulong nip;
79aceca5 192 uint32_t opcode;
9a64fbe4 193 uint32_t exception;
3cc62370
FB
194 /* Routine used to access memory */
195 int mem_idx;
76db3ba4 196 int access_type;
3cc62370 197 /* Translation flags */
76db3ba4 198 int le_mode;
d9bce9d9
JM
199#if defined(TARGET_PPC64)
200 int sf_mode;
697ab892 201 int has_cfar;
9a64fbe4 202#endif
3cc62370 203 int fpu_enabled;
a9d9eb8f 204 int altivec_enabled;
1f29871c 205 int vsx_enabled;
0487d6a8 206 int spe_enabled;
c227f099 207 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
ea4e754f 208 int singlestep_enabled;
7d08d856
AJ
209 uint64_t insns_flags;
210 uint64_t insns_flags2;
79aceca5
FB
211} DisasContext;
212
79482e5a
RH
213/* True when active word size < size of target_long. */
214#ifdef TARGET_PPC64
215# define NARROW_MODE(C) (!(C)->sf_mode)
216#else
217# define NARROW_MODE(C) 0
218#endif
219
c227f099 220struct opc_handler_t {
70560da7
FC
221 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
222 uint32_t inval1;
223 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
224 uint32_t inval2;
9a64fbe4 225 /* instruction type */
0487d6a8 226 uint64_t type;
a5858d7a
AG
227 /* extended instruction type */
228 uint64_t type2;
79aceca5
FB
229 /* handler */
230 void (*handler)(DisasContext *ctx);
a750fc0b 231#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
b55266b5 232 const char *oname;
a750fc0b
JM
233#endif
234#if defined(DO_PPC_STATISTICS)
76a66253
JM
235 uint64_t count;
236#endif
3fc6c082 237};
79aceca5 238
636aa200 239static inline void gen_reset_fpstatus(void)
7c58044c 240{
8e703949 241 gen_helper_reset_fpstatus(cpu_env);
7c58044c
JM
242}
243
636aa200 244static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
7c58044c 245{
0f2f39c2 246 TCGv_i32 t0 = tcg_temp_new_i32();
af12906f 247
7c58044c
JM
248 if (set_fprf != 0) {
249 /* This case might be optimized later */
0f2f39c2 250 tcg_gen_movi_i32(t0, 1);
8e703949 251 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
a7812ae4 252 if (unlikely(set_rc)) {
0f2f39c2 253 tcg_gen_mov_i32(cpu_crf[1], t0);
a7812ae4 254 }
8e703949 255 gen_helper_float_check_status(cpu_env);
7c58044c
JM
256 } else if (unlikely(set_rc)) {
257 /* We always need to compute fpcc */
0f2f39c2 258 tcg_gen_movi_i32(t0, 0);
8e703949 259 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
0f2f39c2 260 tcg_gen_mov_i32(cpu_crf[1], t0);
7c58044c 261 }
af12906f 262
0f2f39c2 263 tcg_temp_free_i32(t0);
7c58044c
JM
264}
265
636aa200 266static inline void gen_set_access_type(DisasContext *ctx, int access_type)
a7859e89 267{
76db3ba4
AJ
268 if (ctx->access_type != access_type) {
269 tcg_gen_movi_i32(cpu_access_type, access_type);
270 ctx->access_type = access_type;
271 }
a7859e89
AJ
272}
273
636aa200 274static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
d9bce9d9 275{
e0c8f9ce
RH
276 if (NARROW_MODE(ctx)) {
277 nip = (uint32_t)nip;
278 }
279 tcg_gen_movi_tl(cpu_nip, nip);
d9bce9d9
JM
280}
281
636aa200 282static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
e06fcd75
AJ
283{
284 TCGv_i32 t0, t1;
285 if (ctx->exception == POWERPC_EXCP_NONE) {
286 gen_update_nip(ctx, ctx->nip);
287 }
288 t0 = tcg_const_i32(excp);
289 t1 = tcg_const_i32(error);
e5f17ac6 290 gen_helper_raise_exception_err(cpu_env, t0, t1);
e06fcd75
AJ
291 tcg_temp_free_i32(t0);
292 tcg_temp_free_i32(t1);
293 ctx->exception = (excp);
294}
e1833e1f 295
636aa200 296static inline void gen_exception(DisasContext *ctx, uint32_t excp)
e06fcd75
AJ
297{
298 TCGv_i32 t0;
299 if (ctx->exception == POWERPC_EXCP_NONE) {
300 gen_update_nip(ctx, ctx->nip);
301 }
302 t0 = tcg_const_i32(excp);
e5f17ac6 303 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
304 tcg_temp_free_i32(t0);
305 ctx->exception = (excp);
306}
e1833e1f 307
636aa200 308static inline void gen_debug_exception(DisasContext *ctx)
e06fcd75
AJ
309{
310 TCGv_i32 t0;
5518f3a6 311
ee2b3994
SB
312 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
313 (ctx->exception != POWERPC_EXCP_SYNC)) {
5518f3a6 314 gen_update_nip(ctx, ctx->nip);
ee2b3994 315 }
e06fcd75 316 t0 = tcg_const_i32(EXCP_DEBUG);
e5f17ac6 317 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
318 tcg_temp_free_i32(t0);
319}
9a64fbe4 320
636aa200 321static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
e06fcd75
AJ
322{
323 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
324}
a9d9eb8f 325
f24e5695 326/* Stop translation */
636aa200 327static inline void gen_stop_exception(DisasContext *ctx)
3fc6c082 328{
d9bce9d9 329 gen_update_nip(ctx, ctx->nip);
e1833e1f 330 ctx->exception = POWERPC_EXCP_STOP;
3fc6c082
FB
331}
332
f24e5695 333/* No need to update nip here, as execution flow will change */
636aa200 334static inline void gen_sync_exception(DisasContext *ctx)
2be0071f 335{
e1833e1f 336 ctx->exception = POWERPC_EXCP_SYNC;
2be0071f
FB
337}
338
79aceca5 339#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
340GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
341
342#define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
343GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
79aceca5 344
c7697e1f 345#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
346GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
347
348#define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
349GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
c7697e1f 350
c227f099 351typedef struct opcode_t {
79aceca5 352 unsigned char opc1, opc2, opc3;
1235fc06 353#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
18fba28c
FB
354 unsigned char pad[5];
355#else
356 unsigned char pad[1];
357#endif
c227f099 358 opc_handler_t handler;
b55266b5 359 const char *oname;
c227f099 360} opcode_t;
79aceca5 361
a750fc0b 362/*****************************************************************************/
79aceca5
FB
363/*** Instruction decoding ***/
364#define EXTRACT_HELPER(name, shift, nb) \
636aa200 365static inline uint32_t name(uint32_t opcode) \
79aceca5
FB
366{ \
367 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
368}
369
370#define EXTRACT_SHELPER(name, shift, nb) \
636aa200 371static inline int32_t name(uint32_t opcode) \
79aceca5 372{ \
18fba28c 373 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
79aceca5
FB
374}
375
f9fc6d81
TM
376#define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
377static inline uint32_t name(uint32_t opcode) \
378{ \
379 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
380 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
381}
79aceca5
FB
382/* Opcode part 1 */
383EXTRACT_HELPER(opc1, 26, 6);
384/* Opcode part 2 */
385EXTRACT_HELPER(opc2, 1, 5);
386/* Opcode part 3 */
387EXTRACT_HELPER(opc3, 6, 5);
388/* Update Cr0 flags */
389EXTRACT_HELPER(Rc, 0, 1);
a737d3eb
TM
390/* Update Cr6 flags (Altivec) */
391EXTRACT_HELPER(Rc21, 10, 1);
79aceca5
FB
392/* Destination */
393EXTRACT_HELPER(rD, 21, 5);
394/* Source */
395EXTRACT_HELPER(rS, 21, 5);
396/* First operand */
397EXTRACT_HELPER(rA, 16, 5);
398/* Second operand */
399EXTRACT_HELPER(rB, 11, 5);
400/* Third operand */
401EXTRACT_HELPER(rC, 6, 5);
402/*** Get CRn ***/
403EXTRACT_HELPER(crfD, 23, 3);
404EXTRACT_HELPER(crfS, 18, 3);
405EXTRACT_HELPER(crbD, 21, 5);
406EXTRACT_HELPER(crbA, 16, 5);
407EXTRACT_HELPER(crbB, 11, 5);
408/* SPR / TBL */
3fc6c082 409EXTRACT_HELPER(_SPR, 11, 10);
636aa200 410static inline uint32_t SPR(uint32_t opcode)
3fc6c082
FB
411{
412 uint32_t sprn = _SPR(opcode);
413
414 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
415}
79aceca5
FB
416/*** Get constants ***/
417EXTRACT_HELPER(IMM, 12, 8);
418/* 16 bits signed immediate value */
419EXTRACT_SHELPER(SIMM, 0, 16);
420/* 16 bits unsigned immediate value */
421EXTRACT_HELPER(UIMM, 0, 16);
21d21583
AJ
422/* 5 bits signed immediate value */
423EXTRACT_HELPER(SIMM5, 16, 5);
27a4edb3
AJ
424/* 5 bits signed immediate value */
425EXTRACT_HELPER(UIMM5, 16, 5);
79aceca5
FB
426/* Bit count */
427EXTRACT_HELPER(NB, 11, 5);
428/* Shift count */
429EXTRACT_HELPER(SH, 11, 5);
cd633b10
AJ
430/* Vector shift count */
431EXTRACT_HELPER(VSH, 6, 4);
79aceca5
FB
432/* Mask start */
433EXTRACT_HELPER(MB, 6, 5);
434/* Mask end */
435EXTRACT_HELPER(ME, 1, 5);
fb0eaffc
FB
436/* Trap operand */
437EXTRACT_HELPER(TO, 21, 5);
79aceca5
FB
438
439EXTRACT_HELPER(CRM, 12, 8);
79aceca5 440EXTRACT_HELPER(SR, 16, 4);
7d08d856
AJ
441
442/* mtfsf/mtfsfi */
779f6590 443EXTRACT_HELPER(FPBF, 23, 3);
e4bb997e 444EXTRACT_HELPER(FPIMM, 12, 4);
779f6590 445EXTRACT_HELPER(FPL, 25, 1);
7d08d856
AJ
446EXTRACT_HELPER(FPFLM, 17, 8);
447EXTRACT_HELPER(FPW, 16, 1);
fb0eaffc 448
79aceca5
FB
449/*** Jump target decoding ***/
450/* Displacement */
451EXTRACT_SHELPER(d, 0, 16);
452/* Immediate address */
636aa200 453static inline target_ulong LI(uint32_t opcode)
79aceca5
FB
454{
455 return (opcode >> 0) & 0x03FFFFFC;
456}
457
636aa200 458static inline uint32_t BD(uint32_t opcode)
79aceca5
FB
459{
460 return (opcode >> 0) & 0xFFFC;
461}
462
463EXTRACT_HELPER(BO, 21, 5);
464EXTRACT_HELPER(BI, 16, 5);
465/* Absolute/relative address */
466EXTRACT_HELPER(AA, 1, 1);
467/* Link */
468EXTRACT_HELPER(LK, 0, 1);
469
f0b01f02
TM
470/* DFP Z22-form */
471EXTRACT_HELPER(DCM, 10, 6)
472
473/* DFP Z23-form */
474EXTRACT_HELPER(RMC, 9, 2)
475
79aceca5 476/* Create a mask between <start> and <end> bits */
636aa200 477static inline target_ulong MASK(uint32_t start, uint32_t end)
79aceca5 478{
76a66253 479 target_ulong ret;
79aceca5 480
76a66253
JM
481#if defined(TARGET_PPC64)
482 if (likely(start == 0)) {
6f2d8978 483 ret = UINT64_MAX << (63 - end);
76a66253 484 } else if (likely(end == 63)) {
6f2d8978 485 ret = UINT64_MAX >> start;
76a66253
JM
486 }
487#else
488 if (likely(start == 0)) {
6f2d8978 489 ret = UINT32_MAX << (31 - end);
76a66253 490 } else if (likely(end == 31)) {
6f2d8978 491 ret = UINT32_MAX >> start;
76a66253
JM
492 }
493#endif
494 else {
495 ret = (((target_ulong)(-1ULL)) >> (start)) ^
496 (((target_ulong)(-1ULL) >> (end)) >> 1);
497 if (unlikely(start > end))
498 return ~ret;
499 }
79aceca5
FB
500
501 return ret;
502}
503
f9fc6d81
TM
504EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
505EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
506EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
507EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
551e3ef7 508EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
f9fc6d81 509EXTRACT_HELPER(DM, 8, 2);
76c15fe0 510EXTRACT_HELPER(UIM, 16, 2);
acc42968 511EXTRACT_HELPER(SHW, 8, 2);
f0b01f02 512EXTRACT_HELPER(SP, 19, 2);
a750fc0b 513/*****************************************************************************/
a750fc0b 514/* PowerPC instructions table */
933dc6eb 515
76a66253 516#if defined(DO_PPC_STATISTICS)
a5858d7a 517#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 518{ \
79aceca5
FB
519 .opc1 = op1, \
520 .opc2 = op2, \
521 .opc3 = op3, \
18fba28c 522 .pad = { 0, }, \
79aceca5 523 .handler = { \
70560da7
FC
524 .inval1 = invl, \
525 .type = _typ, \
526 .type2 = _typ2, \
527 .handler = &gen_##name, \
528 .oname = stringify(name), \
529 }, \
530 .oname = stringify(name), \
531}
532#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
533{ \
534 .opc1 = op1, \
535 .opc2 = op2, \
536 .opc3 = op3, \
537 .pad = { 0, }, \
538 .handler = { \
539 .inval1 = invl1, \
540 .inval2 = invl2, \
9a64fbe4 541 .type = _typ, \
a5858d7a 542 .type2 = _typ2, \
79aceca5 543 .handler = &gen_##name, \
76a66253 544 .oname = stringify(name), \
79aceca5 545 }, \
3fc6c082 546 .oname = stringify(name), \
79aceca5 547}
a5858d7a 548#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 549{ \
c7697e1f
JM
550 .opc1 = op1, \
551 .opc2 = op2, \
552 .opc3 = op3, \
553 .pad = { 0, }, \
554 .handler = { \
70560da7 555 .inval1 = invl, \
c7697e1f 556 .type = _typ, \
a5858d7a 557 .type2 = _typ2, \
c7697e1f
JM
558 .handler = &gen_##name, \
559 .oname = onam, \
560 }, \
561 .oname = onam, \
562}
76a66253 563#else
a5858d7a 564#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 565{ \
c7697e1f
JM
566 .opc1 = op1, \
567 .opc2 = op2, \
568 .opc3 = op3, \
569 .pad = { 0, }, \
570 .handler = { \
70560da7
FC
571 .inval1 = invl, \
572 .type = _typ, \
573 .type2 = _typ2, \
574 .handler = &gen_##name, \
575 }, \
576 .oname = stringify(name), \
577}
578#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
579{ \
580 .opc1 = op1, \
581 .opc2 = op2, \
582 .opc3 = op3, \
583 .pad = { 0, }, \
584 .handler = { \
585 .inval1 = invl1, \
586 .inval2 = invl2, \
c7697e1f 587 .type = _typ, \
a5858d7a 588 .type2 = _typ2, \
c7697e1f 589 .handler = &gen_##name, \
5c55ff99
BS
590 }, \
591 .oname = stringify(name), \
592}
a5858d7a 593#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99
BS
594{ \
595 .opc1 = op1, \
596 .opc2 = op2, \
597 .opc3 = op3, \
598 .pad = { 0, }, \
599 .handler = { \
70560da7 600 .inval1 = invl, \
5c55ff99 601 .type = _typ, \
a5858d7a 602 .type2 = _typ2, \
5c55ff99
BS
603 .handler = &gen_##name, \
604 }, \
605 .oname = onam, \
606}
607#endif
2e610050 608
5c55ff99 609/* SPR load/store helpers */
636aa200 610static inline void gen_load_spr(TCGv t, int reg)
5c55ff99 611{
1328c2bf 612 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 613}
2e610050 614
636aa200 615static inline void gen_store_spr(int reg, TCGv t)
5c55ff99 616{
1328c2bf 617 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 618}
2e610050 619
54623277 620/* Invalid instruction */
99e300ef 621static void gen_invalid(DisasContext *ctx)
9a64fbe4 622{
e06fcd75 623 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
9a64fbe4
FB
624}
625
c227f099 626static opc_handler_t invalid_handler = {
70560da7
FC
627 .inval1 = 0xFFFFFFFF,
628 .inval2 = 0xFFFFFFFF,
9a64fbe4 629 .type = PPC_NONE,
a5858d7a 630 .type2 = PPC_NONE,
79aceca5
FB
631 .handler = gen_invalid,
632};
633
71a8c019
TM
634#if defined(TARGET_PPC64)
635/* NOTE: as this time, the only use of is_user_mode() is in 64 bit code. And */
636/* so the function is wrapped in the standard 64-bit ifdef in order to */
637/* avoid compiler warnings in 32-bit implementations. */
638static bool is_user_mode(DisasContext *ctx)
639{
640#if defined(CONFIG_USER_ONLY)
641 return true;
642#else
643 return ctx->mem_idx == 0;
644#endif
645}
646#endif
647
e1571908
AJ
648/*** Integer comparison ***/
649
636aa200 650static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 651{
2fdcb629
RH
652 TCGv t0 = tcg_temp_new();
653 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 654
da91a00f 655 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 656
2fdcb629
RH
657 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
658 tcg_gen_trunc_tl_i32(t1, t0);
659 tcg_gen_shli_i32(t1, t1, CRF_LT);
660 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
661
662 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
663 tcg_gen_trunc_tl_i32(t1, t0);
664 tcg_gen_shli_i32(t1, t1, CRF_GT);
665 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
666
667 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
668 tcg_gen_trunc_tl_i32(t1, t0);
669 tcg_gen_shli_i32(t1, t1, CRF_EQ);
670 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
671
672 tcg_temp_free(t0);
673 tcg_temp_free_i32(t1);
e1571908
AJ
674}
675
636aa200 676static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 677{
2fdcb629 678 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
679 gen_op_cmp(arg0, t0, s, crf);
680 tcg_temp_free(t0);
e1571908
AJ
681}
682
636aa200 683static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 684{
ea363694 685 TCGv t0, t1;
2fdcb629
RH
686 t0 = tcg_temp_new();
687 t1 = tcg_temp_new();
e1571908 688 if (s) {
ea363694
AJ
689 tcg_gen_ext32s_tl(t0, arg0);
690 tcg_gen_ext32s_tl(t1, arg1);
e1571908 691 } else {
ea363694
AJ
692 tcg_gen_ext32u_tl(t0, arg0);
693 tcg_gen_ext32u_tl(t1, arg1);
e1571908 694 }
ea363694
AJ
695 gen_op_cmp(t0, t1, s, crf);
696 tcg_temp_free(t1);
697 tcg_temp_free(t0);
e1571908
AJ
698}
699
636aa200 700static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 701{
2fdcb629 702 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
703 gen_op_cmp32(arg0, t0, s, crf);
704 tcg_temp_free(t0);
e1571908 705}
e1571908 706
636aa200 707static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908 708{
02765534 709 if (NARROW_MODE(ctx)) {
e1571908 710 gen_op_cmpi32(reg, 0, 1, 0);
02765534 711 } else {
e1571908 712 gen_op_cmpi(reg, 0, 1, 0);
02765534 713 }
e1571908
AJ
714}
715
716/* cmp */
99e300ef 717static void gen_cmp(DisasContext *ctx)
e1571908 718{
36f48d9c 719 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
720 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
721 1, crfD(ctx->opcode));
36f48d9c
AG
722 } else {
723 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
724 1, crfD(ctx->opcode));
02765534 725 }
e1571908
AJ
726}
727
728/* cmpi */
99e300ef 729static void gen_cmpi(DisasContext *ctx)
e1571908 730{
36f48d9c 731 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
732 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
733 1, crfD(ctx->opcode));
36f48d9c
AG
734 } else {
735 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
736 1, crfD(ctx->opcode));
02765534 737 }
e1571908
AJ
738}
739
740/* cmpl */
99e300ef 741static void gen_cmpl(DisasContext *ctx)
e1571908 742{
36f48d9c 743 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
744 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
745 0, crfD(ctx->opcode));
36f48d9c
AG
746 } else {
747 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
748 0, crfD(ctx->opcode));
02765534 749 }
e1571908
AJ
750}
751
752/* cmpli */
99e300ef 753static void gen_cmpli(DisasContext *ctx)
e1571908 754{
36f48d9c 755 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
756 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
757 0, crfD(ctx->opcode));
36f48d9c
AG
758 } else {
759 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
760 0, crfD(ctx->opcode));
02765534 761 }
e1571908
AJ
762}
763
764/* isel (PowerPC 2.03 specification) */
99e300ef 765static void gen_isel(DisasContext *ctx)
e1571908
AJ
766{
767 int l1, l2;
768 uint32_t bi = rC(ctx->opcode);
769 uint32_t mask;
a7812ae4 770 TCGv_i32 t0;
e1571908
AJ
771
772 l1 = gen_new_label();
773 l2 = gen_new_label();
774
775 mask = 1 << (3 - (bi & 0x03));
a7812ae4 776 t0 = tcg_temp_new_i32();
fea0c503
AJ
777 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
778 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
e1571908
AJ
779 if (rA(ctx->opcode) == 0)
780 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
781 else
782 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
783 tcg_gen_br(l2);
784 gen_set_label(l1);
785 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
786 gen_set_label(l2);
a7812ae4 787 tcg_temp_free_i32(t0);
e1571908
AJ
788}
789
fcfda20f
AJ
790/* cmpb: PowerPC 2.05 specification */
791static void gen_cmpb(DisasContext *ctx)
792{
793 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
794 cpu_gpr[rB(ctx->opcode)]);
795}
796
79aceca5 797/*** Integer arithmetic ***/
79aceca5 798
636aa200
BS
799static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
800 TCGv arg1, TCGv arg2, int sub)
74637406 801{
ffe30937 802 TCGv t0 = tcg_temp_new();
79aceca5 803
8e7a6db9 804 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
74637406 805 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
806 if (sub) {
807 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
808 } else {
809 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
810 }
811 tcg_temp_free(t0);
02765534 812 if (NARROW_MODE(ctx)) {
ffe30937
RH
813 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
814 }
ffe30937
RH
815 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
816 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
817}
818
74637406 819/* Common add function */
636aa200 820static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
821 TCGv arg2, bool add_ca, bool compute_ca,
822 bool compute_ov, bool compute_rc0)
74637406 823{
b5a73f8d 824 TCGv t0 = ret;
d9bce9d9 825
752d634e 826 if (compute_ca || compute_ov) {
146de60d 827 t0 = tcg_temp_new();
74637406 828 }
79aceca5 829
da91a00f 830 if (compute_ca) {
79482e5a 831 if (NARROW_MODE(ctx)) {
752d634e
RH
832 /* Caution: a non-obvious corner case of the spec is that we
833 must produce the *entire* 64-bit addition, but produce the
834 carry into bit 32. */
79482e5a 835 TCGv t1 = tcg_temp_new();
752d634e
RH
836 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
837 tcg_gen_add_tl(t0, arg1, arg2);
79482e5a
RH
838 if (add_ca) {
839 tcg_gen_add_tl(t0, t0, cpu_ca);
840 }
752d634e
RH
841 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
842 tcg_temp_free(t1);
843 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
844 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
b5a73f8d 845 } else {
79482e5a
RH
846 TCGv zero = tcg_const_tl(0);
847 if (add_ca) {
848 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
849 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
850 } else {
851 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
852 }
853 tcg_temp_free(zero);
b5a73f8d 854 }
b5a73f8d
RH
855 } else {
856 tcg_gen_add_tl(t0, arg1, arg2);
857 if (add_ca) {
858 tcg_gen_add_tl(t0, t0, cpu_ca);
859 }
da91a00f 860 }
79aceca5 861
74637406
AJ
862 if (compute_ov) {
863 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
864 }
b5a73f8d 865 if (unlikely(compute_rc0)) {
74637406 866 gen_set_Rc0(ctx, t0);
b5a73f8d 867 }
74637406 868
a7812ae4 869 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
870 tcg_gen_mov_tl(ret, t0);
871 tcg_temp_free(t0);
872 }
39dd32ee 873}
74637406
AJ
874/* Add functions with two operands */
875#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 876static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
877{ \
878 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
879 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 880 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
881}
882/* Add functions with one operand and one immediate */
883#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
884 add_ca, compute_ca, compute_ov) \
b5a73f8d 885static void glue(gen_, name)(DisasContext *ctx) \
74637406 886{ \
b5a73f8d 887 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
888 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
889 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 890 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
891 tcg_temp_free(t0); \
892}
893
894/* add add. addo addo. */
895GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
896GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
897/* addc addc. addco addco. */
898GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
899GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
900/* adde adde. addeo addeo. */
901GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
902GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
903/* addme addme. addmeo addmeo. */
904GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
905GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
906/* addze addze. addzeo addzeo.*/
907GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
908GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
909/* addi */
99e300ef 910static void gen_addi(DisasContext *ctx)
d9bce9d9 911{
74637406
AJ
912 target_long simm = SIMM(ctx->opcode);
913
914 if (rA(ctx->opcode) == 0) {
915 /* li case */
916 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
917 } else {
b5a73f8d
RH
918 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
919 cpu_gpr[rA(ctx->opcode)], simm);
74637406 920 }
d9bce9d9 921}
74637406 922/* addic addic.*/
b5a73f8d 923static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 924{
b5a73f8d
RH
925 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
926 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
927 c, 0, 1, 0, compute_rc0);
928 tcg_temp_free(c);
d9bce9d9 929}
99e300ef
BS
930
931static void gen_addic(DisasContext *ctx)
d9bce9d9 932{
b5a73f8d 933 gen_op_addic(ctx, 0);
d9bce9d9 934}
e8eaa2c0
BS
935
936static void gen_addic_(DisasContext *ctx)
d9bce9d9 937{
b5a73f8d 938 gen_op_addic(ctx, 1);
d9bce9d9 939}
99e300ef 940
54623277 941/* addis */
99e300ef 942static void gen_addis(DisasContext *ctx)
d9bce9d9 943{
74637406
AJ
944 target_long simm = SIMM(ctx->opcode);
945
946 if (rA(ctx->opcode) == 0) {
947 /* lis case */
948 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
949 } else {
b5a73f8d
RH
950 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
951 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 952 }
d9bce9d9 953}
74637406 954
636aa200
BS
955static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
956 TCGv arg2, int sign, int compute_ov)
d9bce9d9 957{
2ef1b120
AJ
958 int l1 = gen_new_label();
959 int l2 = gen_new_label();
a7812ae4
PB
960 TCGv_i32 t0 = tcg_temp_local_new_i32();
961 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 962
2ef1b120
AJ
963 tcg_gen_trunc_tl_i32(t0, arg1);
964 tcg_gen_trunc_tl_i32(t1, arg2);
965 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 966 if (sign) {
2ef1b120
AJ
967 int l3 = gen_new_label();
968 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
969 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 970 gen_set_label(l3);
2ef1b120 971 tcg_gen_div_i32(t0, t0, t1);
74637406 972 } else {
2ef1b120 973 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
974 }
975 if (compute_ov) {
da91a00f 976 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
977 }
978 tcg_gen_br(l2);
979 gen_set_label(l1);
980 if (sign) {
2ef1b120 981 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
982 } else {
983 tcg_gen_movi_i32(t0, 0);
984 }
985 if (compute_ov) {
da91a00f
RH
986 tcg_gen_movi_tl(cpu_ov, 1);
987 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
988 }
989 gen_set_label(l2);
2ef1b120 990 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
991 tcg_temp_free_i32(t0);
992 tcg_temp_free_i32(t1);
74637406
AJ
993 if (unlikely(Rc(ctx->opcode) != 0))
994 gen_set_Rc0(ctx, ret);
d9bce9d9 995}
74637406
AJ
996/* Div functions */
997#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 998static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
999{ \
1000 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1001 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1002 sign, compute_ov); \
1003}
1004/* divwu divwu. divwuo divwuo. */
1005GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
1006GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
1007/* divw divw. divwo divwo. */
1008GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1009GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
98d1eb27
TM
1010
1011/* div[wd]eu[o][.] */
1012#define GEN_DIVE(name, hlpr, compute_ov) \
1013static void gen_##name(DisasContext *ctx) \
1014{ \
1015 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1016 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1017 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1018 tcg_temp_free_i32(t0); \
1019 if (unlikely(Rc(ctx->opcode) != 0)) { \
1020 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1021 } \
1022}
1023
6a4fda33
TM
1024GEN_DIVE(divweu, divweu, 0);
1025GEN_DIVE(divweuo, divweu, 1);
a98eb9e9
TM
1026GEN_DIVE(divwe, divwe, 0);
1027GEN_DIVE(divweo, divwe, 1);
6a4fda33 1028
d9bce9d9 1029#if defined(TARGET_PPC64)
636aa200
BS
1030static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1031 TCGv arg2, int sign, int compute_ov)
d9bce9d9 1032{
2ef1b120
AJ
1033 int l1 = gen_new_label();
1034 int l2 = gen_new_label();
74637406
AJ
1035
1036 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1037 if (sign) {
2ef1b120 1038 int l3 = gen_new_label();
74637406
AJ
1039 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1040 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1041 gen_set_label(l3);
74637406
AJ
1042 tcg_gen_div_i64(ret, arg1, arg2);
1043 } else {
1044 tcg_gen_divu_i64(ret, arg1, arg2);
1045 }
1046 if (compute_ov) {
da91a00f 1047 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
1048 }
1049 tcg_gen_br(l2);
1050 gen_set_label(l1);
1051 if (sign) {
1052 tcg_gen_sari_i64(ret, arg1, 63);
1053 } else {
1054 tcg_gen_movi_i64(ret, 0);
1055 }
1056 if (compute_ov) {
da91a00f
RH
1057 tcg_gen_movi_tl(cpu_ov, 1);
1058 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1059 }
1060 gen_set_label(l2);
1061 if (unlikely(Rc(ctx->opcode) != 0))
1062 gen_set_Rc0(ctx, ret);
d9bce9d9 1063}
74637406 1064#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 1065static void glue(gen_, name)(DisasContext *ctx) \
74637406 1066{ \
2ef1b120
AJ
1067 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1068 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1069 sign, compute_ov); \
74637406
AJ
1070}
1071/* divwu divwu. divwuo divwuo. */
1072GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1073GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1074/* divw divw. divwo divwo. */
1075GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1076GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
98d1eb27
TM
1077
1078GEN_DIVE(divdeu, divdeu, 0);
1079GEN_DIVE(divdeuo, divdeu, 1);
e44259b6
TM
1080GEN_DIVE(divde, divde, 0);
1081GEN_DIVE(divdeo, divde, 1);
d9bce9d9 1082#endif
74637406
AJ
1083
1084/* mulhw mulhw. */
99e300ef 1085static void gen_mulhw(DisasContext *ctx)
d9bce9d9 1086{
23ad1d5d
RH
1087 TCGv_i32 t0 = tcg_temp_new_i32();
1088 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1089
23ad1d5d
RH
1090 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1091 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1092 tcg_gen_muls2_i32(t0, t1, t0, t1);
1093 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1094 tcg_temp_free_i32(t0);
1095 tcg_temp_free_i32(t1);
74637406
AJ
1096 if (unlikely(Rc(ctx->opcode) != 0))
1097 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1098}
99e300ef 1099
54623277 1100/* mulhwu mulhwu. */
99e300ef 1101static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1102{
23ad1d5d
RH
1103 TCGv_i32 t0 = tcg_temp_new_i32();
1104 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1105
23ad1d5d
RH
1106 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1107 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1108 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1109 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1110 tcg_temp_free_i32(t0);
1111 tcg_temp_free_i32(t1);
74637406
AJ
1112 if (unlikely(Rc(ctx->opcode) != 0))
1113 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1114}
99e300ef 1115
54623277 1116/* mullw mullw. */
99e300ef 1117static void gen_mullw(DisasContext *ctx)
d9bce9d9 1118{
74637406
AJ
1119 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1120 cpu_gpr[rB(ctx->opcode)]);
1e4c090f 1121 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
74637406
AJ
1122 if (unlikely(Rc(ctx->opcode) != 0))
1123 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1124}
99e300ef 1125
54623277 1126/* mullwo mullwo. */
99e300ef 1127static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1128{
e4a2c846
RH
1129 TCGv_i32 t0 = tcg_temp_new_i32();
1130 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1131
e4a2c846
RH
1132 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1133 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1134 tcg_gen_muls2_i32(t0, t1, t0, t1);
1135 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1136
1137 tcg_gen_sari_i32(t0, t0, 31);
1138 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1139 tcg_gen_extu_i32_tl(cpu_ov, t0);
1140 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1141
1142 tcg_temp_free_i32(t0);
1143 tcg_temp_free_i32(t1);
74637406
AJ
1144 if (unlikely(Rc(ctx->opcode) != 0))
1145 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1146}
99e300ef 1147
54623277 1148/* mulli */
99e300ef 1149static void gen_mulli(DisasContext *ctx)
d9bce9d9 1150{
74637406
AJ
1151 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1152 SIMM(ctx->opcode));
d9bce9d9 1153}
23ad1d5d 1154
d9bce9d9 1155#if defined(TARGET_PPC64)
74637406 1156/* mulhd mulhd. */
23ad1d5d
RH
1157static void gen_mulhd(DisasContext *ctx)
1158{
1159 TCGv lo = tcg_temp_new();
1160 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1161 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1162 tcg_temp_free(lo);
1163 if (unlikely(Rc(ctx->opcode) != 0)) {
1164 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1165 }
1166}
1167
74637406 1168/* mulhdu mulhdu. */
23ad1d5d
RH
1169static void gen_mulhdu(DisasContext *ctx)
1170{
1171 TCGv lo = tcg_temp_new();
1172 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1173 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1174 tcg_temp_free(lo);
1175 if (unlikely(Rc(ctx->opcode) != 0)) {
1176 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1177 }
1178}
99e300ef 1179
54623277 1180/* mulld mulld. */
99e300ef 1181static void gen_mulld(DisasContext *ctx)
d9bce9d9 1182{
74637406
AJ
1183 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1184 cpu_gpr[rB(ctx->opcode)]);
1185 if (unlikely(Rc(ctx->opcode) != 0))
1186 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1187}
d15f74fb 1188
74637406 1189/* mulldo mulldo. */
d15f74fb
BS
1190static void gen_mulldo(DisasContext *ctx)
1191{
1192 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1193 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1194 if (unlikely(Rc(ctx->opcode) != 0)) {
1195 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1196 }
1197}
d9bce9d9 1198#endif
74637406 1199
74637406 1200/* Common subf function */
636aa200 1201static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1202 TCGv arg2, bool add_ca, bool compute_ca,
1203 bool compute_ov, bool compute_rc0)
79aceca5 1204{
b5a73f8d 1205 TCGv t0 = ret;
79aceca5 1206
752d634e 1207 if (compute_ca || compute_ov) {
b5a73f8d 1208 t0 = tcg_temp_new();
da91a00f 1209 }
74637406 1210
79482e5a
RH
1211 if (compute_ca) {
1212 /* dest = ~arg1 + arg2 [+ ca]. */
1213 if (NARROW_MODE(ctx)) {
752d634e
RH
1214 /* Caution: a non-obvious corner case of the spec is that we
1215 must produce the *entire* 64-bit addition, but produce the
1216 carry into bit 32. */
79482e5a 1217 TCGv inv1 = tcg_temp_new();
752d634e 1218 TCGv t1 = tcg_temp_new();
79482e5a 1219 tcg_gen_not_tl(inv1, arg1);
79482e5a 1220 if (add_ca) {
752d634e 1221 tcg_gen_add_tl(t0, arg2, cpu_ca);
79482e5a 1222 } else {
752d634e 1223 tcg_gen_addi_tl(t0, arg2, 1);
79482e5a 1224 }
752d634e 1225 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
79482e5a 1226 tcg_gen_add_tl(t0, t0, inv1);
752d634e
RH
1227 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1228 tcg_temp_free(t1);
1229 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1230 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
79482e5a 1231 } else if (add_ca) {
08f4a0f7
RH
1232 TCGv zero, inv1 = tcg_temp_new();
1233 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1234 zero = tcg_const_tl(0);
1235 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1236 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1237 tcg_temp_free(zero);
08f4a0f7 1238 tcg_temp_free(inv1);
b5a73f8d 1239 } else {
79482e5a 1240 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
b5a73f8d 1241 tcg_gen_sub_tl(t0, arg2, arg1);
b5a73f8d 1242 }
79482e5a
RH
1243 } else if (add_ca) {
1244 /* Since we're ignoring carry-out, we can simplify the
1245 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1246 tcg_gen_sub_tl(t0, arg2, arg1);
1247 tcg_gen_add_tl(t0, t0, cpu_ca);
1248 tcg_gen_subi_tl(t0, t0, 1);
79aceca5 1249 } else {
b5a73f8d 1250 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1251 }
b5a73f8d 1252
74637406
AJ
1253 if (compute_ov) {
1254 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1255 }
b5a73f8d 1256 if (unlikely(compute_rc0)) {
74637406 1257 gen_set_Rc0(ctx, t0);
b5a73f8d 1258 }
74637406 1259
a7812ae4 1260 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1261 tcg_gen_mov_tl(ret, t0);
1262 tcg_temp_free(t0);
79aceca5 1263 }
79aceca5 1264}
74637406
AJ
1265/* Sub functions with Two operands functions */
1266#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1267static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1268{ \
1269 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1270 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1271 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1272}
1273/* Sub functions with one operand and one immediate */
1274#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1275 add_ca, compute_ca, compute_ov) \
b5a73f8d 1276static void glue(gen_, name)(DisasContext *ctx) \
74637406 1277{ \
b5a73f8d 1278 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1279 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1280 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1281 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1282 tcg_temp_free(t0); \
1283}
1284/* subf subf. subfo subfo. */
1285GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1286GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1287/* subfc subfc. subfco subfco. */
1288GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1289GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1290/* subfe subfe. subfeo subfo. */
1291GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1292GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1293/* subfme subfme. subfmeo subfmeo. */
1294GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1295GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1296/* subfze subfze. subfzeo subfzeo.*/
1297GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1298GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1299
54623277 1300/* subfic */
99e300ef 1301static void gen_subfic(DisasContext *ctx)
79aceca5 1302{
b5a73f8d
RH
1303 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1304 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1305 c, 0, 1, 0, 0);
1306 tcg_temp_free(c);
79aceca5
FB
1307}
1308
fd3f0081
RH
1309/* neg neg. nego nego. */
1310static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1311{
1312 TCGv zero = tcg_const_tl(0);
1313 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1314 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1315 tcg_temp_free(zero);
1316}
1317
1318static void gen_neg(DisasContext *ctx)
1319{
1320 gen_op_arith_neg(ctx, 0);
1321}
1322
1323static void gen_nego(DisasContext *ctx)
1324{
1325 gen_op_arith_neg(ctx, 1);
1326}
1327
79aceca5 1328/*** Integer logical ***/
26d67362 1329#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1330static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1331{ \
26d67362
AJ
1332 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1333 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1334 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1335 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1336}
79aceca5 1337
26d67362 1338#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1339static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1340{ \
26d67362 1341 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1342 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1343 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1344}
1345
1346/* and & and. */
26d67362 1347GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1348/* andc & andc. */
26d67362 1349GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1350
54623277 1351/* andi. */
e8eaa2c0 1352static void gen_andi_(DisasContext *ctx)
79aceca5 1353{
26d67362
AJ
1354 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1355 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1356}
e8eaa2c0 1357
54623277 1358/* andis. */
e8eaa2c0 1359static void gen_andis_(DisasContext *ctx)
79aceca5 1360{
26d67362
AJ
1361 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1362 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1363}
99e300ef 1364
54623277 1365/* cntlzw */
99e300ef 1366static void gen_cntlzw(DisasContext *ctx)
26d67362 1367{
a7812ae4 1368 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1369 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1370 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1371}
79aceca5 1372/* eqv & eqv. */
26d67362 1373GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1374/* extsb & extsb. */
26d67362 1375GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1376/* extsh & extsh. */
26d67362 1377GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1378/* nand & nand. */
26d67362 1379GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1380/* nor & nor. */
26d67362 1381GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1382
54623277 1383/* or & or. */
99e300ef 1384static void gen_or(DisasContext *ctx)
9a64fbe4 1385{
76a66253
JM
1386 int rs, ra, rb;
1387
1388 rs = rS(ctx->opcode);
1389 ra = rA(ctx->opcode);
1390 rb = rB(ctx->opcode);
1391 /* Optimisation for mr. ri case */
1392 if (rs != ra || rs != rb) {
26d67362
AJ
1393 if (rs != rb)
1394 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1395 else
1396 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1397 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1398 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1399 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1400 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1401#if defined(TARGET_PPC64)
1402 } else {
26d67362
AJ
1403 int prio = 0;
1404
c80f84e3
JM
1405 switch (rs) {
1406 case 1:
1407 /* Set process priority to low */
26d67362 1408 prio = 2;
c80f84e3
JM
1409 break;
1410 case 6:
1411 /* Set process priority to medium-low */
26d67362 1412 prio = 3;
c80f84e3
JM
1413 break;
1414 case 2:
1415 /* Set process priority to normal */
26d67362 1416 prio = 4;
c80f84e3 1417 break;
be147d08
JM
1418#if !defined(CONFIG_USER_ONLY)
1419 case 31:
76db3ba4 1420 if (ctx->mem_idx > 0) {
be147d08 1421 /* Set process priority to very low */
26d67362 1422 prio = 1;
be147d08
JM
1423 }
1424 break;
1425 case 5:
76db3ba4 1426 if (ctx->mem_idx > 0) {
be147d08 1427 /* Set process priority to medium-hight */
26d67362 1428 prio = 5;
be147d08
JM
1429 }
1430 break;
1431 case 3:
76db3ba4 1432 if (ctx->mem_idx > 0) {
be147d08 1433 /* Set process priority to high */
26d67362 1434 prio = 6;
be147d08
JM
1435 }
1436 break;
be147d08 1437 case 7:
76db3ba4 1438 if (ctx->mem_idx > 1) {
be147d08 1439 /* Set process priority to very high */
26d67362 1440 prio = 7;
be147d08
JM
1441 }
1442 break;
be147d08 1443#endif
c80f84e3
JM
1444 default:
1445 /* nop */
1446 break;
1447 }
26d67362 1448 if (prio) {
a7812ae4 1449 TCGv t0 = tcg_temp_new();
54cdcae6 1450 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1451 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1452 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1453 gen_store_spr(SPR_PPR, t0);
ea363694 1454 tcg_temp_free(t0);
26d67362 1455 }
c80f84e3 1456#endif
9a64fbe4 1457 }
9a64fbe4 1458}
79aceca5 1459/* orc & orc. */
26d67362 1460GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1461
54623277 1462/* xor & xor. */
99e300ef 1463static void gen_xor(DisasContext *ctx)
9a64fbe4 1464{
9a64fbe4 1465 /* Optimisation for "set to zero" case */
26d67362 1466 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1467 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1468 else
1469 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1470 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1471 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1472}
99e300ef 1473
54623277 1474/* ori */
99e300ef 1475static void gen_ori(DisasContext *ctx)
79aceca5 1476{
76a66253 1477 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1478
9a64fbe4
FB
1479 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1480 /* NOP */
76a66253 1481 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1482 return;
76a66253 1483 }
26d67362 1484 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1485}
99e300ef 1486
54623277 1487/* oris */
99e300ef 1488static void gen_oris(DisasContext *ctx)
79aceca5 1489{
76a66253 1490 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1491
9a64fbe4
FB
1492 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1493 /* NOP */
1494 return;
76a66253 1495 }
26d67362 1496 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1497}
99e300ef 1498
54623277 1499/* xori */
99e300ef 1500static void gen_xori(DisasContext *ctx)
79aceca5 1501{
76a66253 1502 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1503
1504 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1505 /* NOP */
1506 return;
1507 }
26d67362 1508 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1509}
99e300ef 1510
54623277 1511/* xoris */
99e300ef 1512static void gen_xoris(DisasContext *ctx)
79aceca5 1513{
76a66253 1514 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1515
1516 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1517 /* NOP */
1518 return;
1519 }
26d67362 1520 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1521}
99e300ef 1522
54623277 1523/* popcntb : PowerPC 2.03 specification */
99e300ef 1524static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1525{
eaabeef2
DG
1526 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1527}
1528
1529static void gen_popcntw(DisasContext *ctx)
1530{
1531 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1532}
1533
d9bce9d9 1534#if defined(TARGET_PPC64)
eaabeef2
DG
1535/* popcntd: PowerPC 2.06 specification */
1536static void gen_popcntd(DisasContext *ctx)
1537{
1538 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1539}
eaabeef2 1540#endif
d9bce9d9 1541
725bcec2
AJ
1542/* prtyw: PowerPC 2.05 specification */
1543static void gen_prtyw(DisasContext *ctx)
1544{
1545 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1546 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1547 TCGv t0 = tcg_temp_new();
1548 tcg_gen_shri_tl(t0, rs, 16);
1549 tcg_gen_xor_tl(ra, rs, t0);
1550 tcg_gen_shri_tl(t0, ra, 8);
1551 tcg_gen_xor_tl(ra, ra, t0);
1552 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1553 tcg_temp_free(t0);
1554}
1555
1556#if defined(TARGET_PPC64)
1557/* prtyd: PowerPC 2.05 specification */
1558static void gen_prtyd(DisasContext *ctx)
1559{
1560 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1561 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1562 TCGv t0 = tcg_temp_new();
1563 tcg_gen_shri_tl(t0, rs, 32);
1564 tcg_gen_xor_tl(ra, rs, t0);
1565 tcg_gen_shri_tl(t0, ra, 16);
1566 tcg_gen_xor_tl(ra, ra, t0);
1567 tcg_gen_shri_tl(t0, ra, 8);
1568 tcg_gen_xor_tl(ra, ra, t0);
1569 tcg_gen_andi_tl(ra, ra, 1);
1570 tcg_temp_free(t0);
1571}
1572#endif
1573
86ba37ed
TM
1574#if defined(TARGET_PPC64)
1575/* bpermd */
1576static void gen_bpermd(DisasContext *ctx)
1577{
1578 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1579 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1580}
1581#endif
1582
d9bce9d9
JM
1583#if defined(TARGET_PPC64)
1584/* extsw & extsw. */
26d67362 1585GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1586
54623277 1587/* cntlzd */
99e300ef 1588static void gen_cntlzd(DisasContext *ctx)
26d67362 1589{
a7812ae4 1590 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1591 if (unlikely(Rc(ctx->opcode) != 0))
1592 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1593}
d9bce9d9
JM
1594#endif
1595
79aceca5 1596/*** Integer rotate ***/
99e300ef 1597
54623277 1598/* rlwimi & rlwimi. */
99e300ef 1599static void gen_rlwimi(DisasContext *ctx)
79aceca5 1600{
76a66253 1601 uint32_t mb, me, sh;
79aceca5
FB
1602
1603 mb = MB(ctx->opcode);
1604 me = ME(ctx->opcode);
76a66253 1605 sh = SH(ctx->opcode);
d03ef511
AJ
1606 if (likely(sh == 0 && mb == 0 && me == 31)) {
1607 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1608 } else {
d03ef511 1609 target_ulong mask;
a7812ae4
PB
1610 TCGv t1;
1611 TCGv t0 = tcg_temp_new();
54843a58 1612#if defined(TARGET_PPC64)
a7812ae4
PB
1613 TCGv_i32 t2 = tcg_temp_new_i32();
1614 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1615 tcg_gen_rotli_i32(t2, t2, sh);
1616 tcg_gen_extu_i32_i64(t0, t2);
1617 tcg_temp_free_i32(t2);
54843a58
AJ
1618#else
1619 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1620#endif
76a66253 1621#if defined(TARGET_PPC64)
d03ef511
AJ
1622 mb += 32;
1623 me += 32;
76a66253 1624#endif
d03ef511 1625 mask = MASK(mb, me);
a7812ae4 1626 t1 = tcg_temp_new();
d03ef511
AJ
1627 tcg_gen_andi_tl(t0, t0, mask);
1628 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1629 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1630 tcg_temp_free(t0);
1631 tcg_temp_free(t1);
1632 }
76a66253 1633 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1634 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1635}
99e300ef 1636
54623277 1637/* rlwinm & rlwinm. */
99e300ef 1638static void gen_rlwinm(DisasContext *ctx)
79aceca5
FB
1639{
1640 uint32_t mb, me, sh;
3b46e624 1641
79aceca5
FB
1642 sh = SH(ctx->opcode);
1643 mb = MB(ctx->opcode);
1644 me = ME(ctx->opcode);
d03ef511
AJ
1645
1646 if (likely(mb == 0 && me == (31 - sh))) {
1647 if (likely(sh == 0)) {
1648 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1649 } else {
a7812ae4 1650 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1651 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1652 tcg_gen_shli_tl(t0, t0, sh);
1653 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1654 tcg_temp_free(t0);
79aceca5 1655 }
d03ef511 1656 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
a7812ae4 1657 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1658 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1659 tcg_gen_shri_tl(t0, t0, mb);
1660 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1661 tcg_temp_free(t0);
1662 } else {
a7812ae4 1663 TCGv t0 = tcg_temp_new();
54843a58 1664#if defined(TARGET_PPC64)
a7812ae4 1665 TCGv_i32 t1 = tcg_temp_new_i32();
54843a58
AJ
1666 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1667 tcg_gen_rotli_i32(t1, t1, sh);
1668 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4 1669 tcg_temp_free_i32(t1);
54843a58
AJ
1670#else
1671 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1672#endif
76a66253 1673#if defined(TARGET_PPC64)
d03ef511
AJ
1674 mb += 32;
1675 me += 32;
76a66253 1676#endif
d03ef511
AJ
1677 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1678 tcg_temp_free(t0);
1679 }
76a66253 1680 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1681 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1682}
99e300ef 1683
54623277 1684/* rlwnm & rlwnm. */
99e300ef 1685static void gen_rlwnm(DisasContext *ctx)
79aceca5
FB
1686{
1687 uint32_t mb, me;
54843a58
AJ
1688 TCGv t0;
1689#if defined(TARGET_PPC64)
a7812ae4 1690 TCGv_i32 t1, t2;
54843a58 1691#endif
79aceca5
FB
1692
1693 mb = MB(ctx->opcode);
1694 me = ME(ctx->opcode);
a7812ae4 1695 t0 = tcg_temp_new();
d03ef511 1696 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
54843a58 1697#if defined(TARGET_PPC64)
a7812ae4
PB
1698 t1 = tcg_temp_new_i32();
1699 t2 = tcg_temp_new_i32();
54843a58
AJ
1700 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1701 tcg_gen_trunc_i64_i32(t2, t0);
1702 tcg_gen_rotl_i32(t1, t1, t2);
1703 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4
PB
1704 tcg_temp_free_i32(t1);
1705 tcg_temp_free_i32(t2);
54843a58
AJ
1706#else
1707 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1708#endif
76a66253
JM
1709 if (unlikely(mb != 0 || me != 31)) {
1710#if defined(TARGET_PPC64)
1711 mb += 32;
1712 me += 32;
1713#endif
54843a58 1714 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
d03ef511 1715 } else {
54843a58 1716 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
79aceca5 1717 }
54843a58 1718 tcg_temp_free(t0);
76a66253 1719 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1720 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5
FB
1721}
1722
d9bce9d9
JM
1723#if defined(TARGET_PPC64)
1724#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1725static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1726{ \
1727 gen_##name(ctx, 0); \
1728} \
e8eaa2c0
BS
1729 \
1730static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1731{ \
1732 gen_##name(ctx, 1); \
1733}
1734#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1735static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1736{ \
1737 gen_##name(ctx, 0, 0); \
1738} \
e8eaa2c0
BS
1739 \
1740static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1741{ \
1742 gen_##name(ctx, 0, 1); \
1743} \
e8eaa2c0
BS
1744 \
1745static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1746{ \
1747 gen_##name(ctx, 1, 0); \
1748} \
e8eaa2c0
BS
1749 \
1750static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1751{ \
1752 gen_##name(ctx, 1, 1); \
1753}
51789c41 1754
636aa200
BS
1755static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1756 uint32_t sh)
51789c41 1757{
d03ef511
AJ
1758 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1759 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1760 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1761 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1762 } else {
a7812ae4 1763 TCGv t0 = tcg_temp_new();
54843a58 1764 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
d03ef511 1765 if (likely(mb == 0 && me == 63)) {
54843a58 1766 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
d03ef511
AJ
1767 } else {
1768 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
51789c41 1769 }
d03ef511 1770 tcg_temp_free(t0);
51789c41 1771 }
51789c41 1772 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1773 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
51789c41 1774}
d9bce9d9 1775/* rldicl - rldicl. */
636aa200 1776static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1777{
51789c41 1778 uint32_t sh, mb;
d9bce9d9 1779
9d53c753
JM
1780 sh = SH(ctx->opcode) | (shn << 5);
1781 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1782 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1783}
51789c41 1784GEN_PPC64_R4(rldicl, 0x1E, 0x00);
d9bce9d9 1785/* rldicr - rldicr. */
636aa200 1786static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1787{
51789c41 1788 uint32_t sh, me;
d9bce9d9 1789
9d53c753
JM
1790 sh = SH(ctx->opcode) | (shn << 5);
1791 me = MB(ctx->opcode) | (men << 5);
51789c41 1792 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1793}
51789c41 1794GEN_PPC64_R4(rldicr, 0x1E, 0x02);
d9bce9d9 1795/* rldic - rldic. */
636aa200 1796static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1797{
51789c41 1798 uint32_t sh, mb;
d9bce9d9 1799
9d53c753
JM
1800 sh = SH(ctx->opcode) | (shn << 5);
1801 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1802 gen_rldinm(ctx, mb, 63 - sh, sh);
1803}
1804GEN_PPC64_R4(rldic, 0x1E, 0x04);
1805
636aa200 1806static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
51789c41 1807{
54843a58 1808 TCGv t0;
d03ef511 1809
a7812ae4 1810 t0 = tcg_temp_new();
d03ef511 1811 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
54843a58 1812 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
51789c41 1813 if (unlikely(mb != 0 || me != 63)) {
54843a58
AJ
1814 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1815 } else {
1816 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1817 }
1818 tcg_temp_free(t0);
51789c41 1819 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1820 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1821}
51789c41 1822
d9bce9d9 1823/* rldcl - rldcl. */
636aa200 1824static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1825{
51789c41 1826 uint32_t mb;
d9bce9d9 1827
9d53c753 1828 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1829 gen_rldnm(ctx, mb, 63);
d9bce9d9 1830}
36081602 1831GEN_PPC64_R2(rldcl, 0x1E, 0x08);
d9bce9d9 1832/* rldcr - rldcr. */
636aa200 1833static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1834{
51789c41 1835 uint32_t me;
d9bce9d9 1836
9d53c753 1837 me = MB(ctx->opcode) | (men << 5);
51789c41 1838 gen_rldnm(ctx, 0, me);
d9bce9d9 1839}
36081602 1840GEN_PPC64_R2(rldcr, 0x1E, 0x09);
d9bce9d9 1841/* rldimi - rldimi. */
636aa200 1842static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1843{
271a916e 1844 uint32_t sh, mb, me;
d9bce9d9 1845
9d53c753
JM
1846 sh = SH(ctx->opcode) | (shn << 5);
1847 mb = MB(ctx->opcode) | (mbn << 5);
271a916e 1848 me = 63 - sh;
d03ef511
AJ
1849 if (unlikely(sh == 0 && mb == 0)) {
1850 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1851 } else {
1852 TCGv t0, t1;
1853 target_ulong mask;
1854
a7812ae4 1855 t0 = tcg_temp_new();
54843a58 1856 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
a7812ae4 1857 t1 = tcg_temp_new();
d03ef511
AJ
1858 mask = MASK(mb, me);
1859 tcg_gen_andi_tl(t0, t0, mask);
1860 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1861 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1862 tcg_temp_free(t0);
1863 tcg_temp_free(t1);
51789c41 1864 }
51789c41 1865 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1866 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1867}
36081602 1868GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1869#endif
1870
79aceca5 1871/*** Integer shift ***/
99e300ef 1872
54623277 1873/* slw & slw. */
99e300ef 1874static void gen_slw(DisasContext *ctx)
26d67362 1875{
7fd6bf7d 1876 TCGv t0, t1;
26d67362 1877
7fd6bf7d
AJ
1878 t0 = tcg_temp_new();
1879 /* AND rS with a mask that is 0 when rB >= 0x20 */
1880#if defined(TARGET_PPC64)
1881 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1882 tcg_gen_sari_tl(t0, t0, 0x3f);
1883#else
1884 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1885 tcg_gen_sari_tl(t0, t0, 0x1f);
1886#endif
1887 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1888 t1 = tcg_temp_new();
1889 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1890 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1891 tcg_temp_free(t1);
fea0c503 1892 tcg_temp_free(t0);
7fd6bf7d 1893 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1894 if (unlikely(Rc(ctx->opcode) != 0))
1895 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1896}
99e300ef 1897
54623277 1898/* sraw & sraw. */
99e300ef 1899static void gen_sraw(DisasContext *ctx)
26d67362 1900{
d15f74fb 1901 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1902 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1903 if (unlikely(Rc(ctx->opcode) != 0))
1904 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1905}
99e300ef 1906
54623277 1907/* srawi & srawi. */
99e300ef 1908static void gen_srawi(DisasContext *ctx)
79aceca5 1909{
26d67362 1910 int sh = SH(ctx->opcode);
ba4af3e4
RH
1911 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1912 TCGv src = cpu_gpr[rS(ctx->opcode)];
1913 if (sh == 0) {
1914 tcg_gen_mov_tl(dst, src);
da91a00f 1915 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1916 } else {
ba4af3e4
RH
1917 TCGv t0;
1918 tcg_gen_ext32s_tl(dst, src);
1919 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1920 t0 = tcg_temp_new();
1921 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1922 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1923 tcg_temp_free(t0);
1924 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1925 tcg_gen_sari_tl(dst, dst, sh);
1926 }
1927 if (unlikely(Rc(ctx->opcode) != 0)) {
1928 gen_set_Rc0(ctx, dst);
d9bce9d9 1929 }
79aceca5 1930}
99e300ef 1931
54623277 1932/* srw & srw. */
99e300ef 1933static void gen_srw(DisasContext *ctx)
26d67362 1934{
fea0c503 1935 TCGv t0, t1;
d9bce9d9 1936
7fd6bf7d
AJ
1937 t0 = tcg_temp_new();
1938 /* AND rS with a mask that is 0 when rB >= 0x20 */
1939#if defined(TARGET_PPC64)
1940 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1941 tcg_gen_sari_tl(t0, t0, 0x3f);
1942#else
1943 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1944 tcg_gen_sari_tl(t0, t0, 0x1f);
1945#endif
1946 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1947 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1948 t1 = tcg_temp_new();
7fd6bf7d
AJ
1949 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1950 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1951 tcg_temp_free(t1);
fea0c503 1952 tcg_temp_free(t0);
26d67362
AJ
1953 if (unlikely(Rc(ctx->opcode) != 0))
1954 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1955}
54623277 1956
d9bce9d9
JM
1957#if defined(TARGET_PPC64)
1958/* sld & sld. */
99e300ef 1959static void gen_sld(DisasContext *ctx)
26d67362 1960{
7fd6bf7d 1961 TCGv t0, t1;
26d67362 1962
7fd6bf7d
AJ
1963 t0 = tcg_temp_new();
1964 /* AND rS with a mask that is 0 when rB >= 0x40 */
1965 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1966 tcg_gen_sari_tl(t0, t0, 0x3f);
1967 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1968 t1 = tcg_temp_new();
1969 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1970 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1971 tcg_temp_free(t1);
fea0c503 1972 tcg_temp_free(t0);
26d67362
AJ
1973 if (unlikely(Rc(ctx->opcode) != 0))
1974 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1975}
99e300ef 1976
54623277 1977/* srad & srad. */
99e300ef 1978static void gen_srad(DisasContext *ctx)
26d67362 1979{
d15f74fb 1980 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1981 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1982 if (unlikely(Rc(ctx->opcode) != 0))
1983 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1984}
d9bce9d9 1985/* sradi & sradi. */
636aa200 1986static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1987{
26d67362 1988 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
1989 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1990 TCGv src = cpu_gpr[rS(ctx->opcode)];
1991 if (sh == 0) {
1992 tcg_gen_mov_tl(dst, src);
da91a00f 1993 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1994 } else {
ba4af3e4
RH
1995 TCGv t0;
1996 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1997 t0 = tcg_temp_new();
1998 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1999 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
2000 tcg_temp_free(t0);
2001 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
2002 tcg_gen_sari_tl(dst, src, sh);
2003 }
2004 if (unlikely(Rc(ctx->opcode) != 0)) {
2005 gen_set_Rc0(ctx, dst);
d9bce9d9 2006 }
d9bce9d9 2007}
e8eaa2c0
BS
2008
2009static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
2010{
2011 gen_sradi(ctx, 0);
2012}
e8eaa2c0
BS
2013
2014static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
2015{
2016 gen_sradi(ctx, 1);
2017}
99e300ef 2018
54623277 2019/* srd & srd. */
99e300ef 2020static void gen_srd(DisasContext *ctx)
26d67362 2021{
7fd6bf7d 2022 TCGv t0, t1;
26d67362 2023
7fd6bf7d
AJ
2024 t0 = tcg_temp_new();
2025 /* AND rS with a mask that is 0 when rB >= 0x40 */
2026 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2027 tcg_gen_sari_tl(t0, t0, 0x3f);
2028 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2029 t1 = tcg_temp_new();
2030 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2031 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2032 tcg_temp_free(t1);
fea0c503 2033 tcg_temp_free(t0);
26d67362
AJ
2034 if (unlikely(Rc(ctx->opcode) != 0))
2035 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2036}
d9bce9d9 2037#endif
79aceca5
FB
2038
2039/*** Floating-Point arithmetic ***/
7c58044c 2040#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 2041static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2042{ \
76a66253 2043 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2044 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2045 return; \
2046 } \
eb44b959
AJ
2047 /* NIP cannot be restored if the memory exception comes from an helper */ \
2048 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2049 gen_reset_fpstatus(); \
8e703949
BS
2050 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2051 cpu_fpr[rA(ctx->opcode)], \
af12906f 2052 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2053 if (isfloat) { \
8e703949
BS
2054 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2055 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2056 } \
af12906f
AJ
2057 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2058 Rc(ctx->opcode) != 0); \
9a64fbe4
FB
2059}
2060
7c58044c
JM
2061#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2062_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2063_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2064
7c58044c 2065#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2066static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2067{ \
76a66253 2068 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2069 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2070 return; \
2071 } \
eb44b959
AJ
2072 /* NIP cannot be restored if the memory exception comes from an helper */ \
2073 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2074 gen_reset_fpstatus(); \
8e703949
BS
2075 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2076 cpu_fpr[rA(ctx->opcode)], \
af12906f 2077 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2078 if (isfloat) { \
8e703949
BS
2079 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2080 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2081 } \
af12906f
AJ
2082 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2083 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2084}
7c58044c
JM
2085#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2086_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2087_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2088
7c58044c 2089#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2090static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2091{ \
76a66253 2092 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2093 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2094 return; \
2095 } \
eb44b959
AJ
2096 /* NIP cannot be restored if the memory exception comes from an helper */ \
2097 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2098 gen_reset_fpstatus(); \
8e703949
BS
2099 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2100 cpu_fpr[rA(ctx->opcode)], \
2101 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2102 if (isfloat) { \
8e703949
BS
2103 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2104 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2105 } \
af12906f
AJ
2106 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2107 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2108}
7c58044c
JM
2109#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2110_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2111_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2112
7c58044c 2113#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2114static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2115{ \
76a66253 2116 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2117 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2118 return; \
2119 } \
eb44b959
AJ
2120 /* NIP cannot be restored if the memory exception comes from an helper */ \
2121 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2122 gen_reset_fpstatus(); \
8e703949
BS
2123 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2124 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2125 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2126 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2127}
2128
7c58044c 2129#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2130static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2131{ \
76a66253 2132 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2133 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2134 return; \
2135 } \
eb44b959
AJ
2136 /* NIP cannot be restored if the memory exception comes from an helper */ \
2137 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2138 gen_reset_fpstatus(); \
8e703949
BS
2139 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2140 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2141 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2142 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2143}
2144
9a64fbe4 2145/* fadd - fadds */
7c58044c 2146GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2147/* fdiv - fdivs */
7c58044c 2148GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2149/* fmul - fmuls */
7c58044c 2150GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2151
d7e4b87e 2152/* fre */
7c58044c 2153GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2154
a750fc0b 2155/* fres */
7c58044c 2156GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2157
a750fc0b 2158/* frsqrte */
7c58044c
JM
2159GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2160
2161/* frsqrtes */
99e300ef 2162static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2163{
af12906f 2164 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2165 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2166 return;
2167 }
eb44b959
AJ
2168 /* NIP cannot be restored if the memory exception comes from an helper */
2169 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2170 gen_reset_fpstatus();
8e703949
BS
2171 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2172 cpu_fpr[rB(ctx->opcode)]);
2173 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2174 cpu_fpr[rD(ctx->opcode)]);
af12906f 2175 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
7c58044c 2176}
79aceca5 2177
a750fc0b 2178/* fsel */
7c58044c 2179_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2180/* fsub - fsubs */
7c58044c 2181GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2182/* Optional: */
99e300ef 2183
54623277 2184/* fsqrt */
99e300ef 2185static void gen_fsqrt(DisasContext *ctx)
c7d344af 2186{
76a66253 2187 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2188 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2189 return;
2190 }
eb44b959
AJ
2191 /* NIP cannot be restored if the memory exception comes from an helper */
2192 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2193 gen_reset_fpstatus();
8e703949
BS
2194 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2195 cpu_fpr[rB(ctx->opcode)]);
af12906f 2196 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
c7d344af 2197}
79aceca5 2198
99e300ef 2199static void gen_fsqrts(DisasContext *ctx)
79aceca5 2200{
76a66253 2201 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2202 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2203 return;
2204 }
eb44b959
AJ
2205 /* NIP cannot be restored if the memory exception comes from an helper */
2206 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2207 gen_reset_fpstatus();
8e703949
BS
2208 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2209 cpu_fpr[rB(ctx->opcode)]);
2210 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2211 cpu_fpr[rD(ctx->opcode)]);
af12906f 2212 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
79aceca5
FB
2213}
2214
2215/*** Floating-Point multiply-and-add ***/
4ecc3190 2216/* fmadd - fmadds */
7c58044c 2217GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2218/* fmsub - fmsubs */
7c58044c 2219GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2220/* fnmadd - fnmadds */
7c58044c 2221GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2222/* fnmsub - fnmsubs */
7c58044c 2223GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2224
2225/*** Floating-Point round & convert ***/
2226/* fctiw */
7c58044c 2227GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2228/* fctiwu */
2229GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2230/* fctiwz */
7c58044c 2231GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2232/* fctiwuz */
2233GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2234/* frsp */
7c58044c 2235GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db
JM
2236#if defined(TARGET_PPC64)
2237/* fcfid */
7c58044c 2238GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
28288b48
TM
2239/* fcfids */
2240GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2241/* fcfidu */
2242GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2243/* fcfidus */
2244GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
426613db 2245/* fctid */
7c58044c 2246GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
fab7fe42
TM
2247/* fctidu */
2248GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2249/* fctidz */
7c58044c 2250GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
fab7fe42
TM
2251/* fctidu */
2252GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2253#endif
79aceca5 2254
d7e4b87e 2255/* frin */
7c58044c 2256GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2257/* friz */
7c58044c 2258GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2259/* frip */
7c58044c 2260GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2261/* frim */
7c58044c 2262GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2263
da29cb7b
TM
2264static void gen_ftdiv(DisasContext *ctx)
2265{
2266 if (unlikely(!ctx->fpu_enabled)) {
2267 gen_exception(ctx, POWERPC_EXCP_FPU);
2268 return;
2269 }
2270 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2271 cpu_fpr[rB(ctx->opcode)]);
2272}
2273
6d41d146
TM
2274static void gen_ftsqrt(DisasContext *ctx)
2275{
2276 if (unlikely(!ctx->fpu_enabled)) {
2277 gen_exception(ctx, POWERPC_EXCP_FPU);
2278 return;
2279 }
2280 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2281}
2282
da29cb7b
TM
2283
2284
79aceca5 2285/*** Floating-Point compare ***/
99e300ef 2286
54623277 2287/* fcmpo */
99e300ef 2288static void gen_fcmpo(DisasContext *ctx)
79aceca5 2289{
330c483b 2290 TCGv_i32 crf;
76a66253 2291 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2292 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2293 return;
2294 }
eb44b959
AJ
2295 /* NIP cannot be restored if the memory exception comes from an helper */
2296 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2297 gen_reset_fpstatus();
9a819377 2298 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2299 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2300 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2301 tcg_temp_free_i32(crf);
8e703949 2302 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2303}
2304
2305/* fcmpu */
99e300ef 2306static void gen_fcmpu(DisasContext *ctx)
79aceca5 2307{
330c483b 2308 TCGv_i32 crf;
76a66253 2309 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2310 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2311 return;
2312 }
eb44b959
AJ
2313 /* NIP cannot be restored if the memory exception comes from an helper */
2314 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2315 gen_reset_fpstatus();
9a819377 2316 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2317 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2318 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2319 tcg_temp_free_i32(crf);
8e703949 2320 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2321}
2322
9a64fbe4
FB
2323/*** Floating-point move ***/
2324/* fabs */
7c58044c 2325/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2326static void gen_fabs(DisasContext *ctx)
2327{
2328 if (unlikely(!ctx->fpu_enabled)) {
2329 gen_exception(ctx, POWERPC_EXCP_FPU);
2330 return;
2331 }
2332 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2333 ~(1ULL << 63));
2334 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2335}
9a64fbe4
FB
2336
2337/* fmr - fmr. */
7c58044c 2338/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2339static void gen_fmr(DisasContext *ctx)
9a64fbe4 2340{
76a66253 2341 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2342 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2343 return;
2344 }
af12906f
AJ
2345 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2346 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
9a64fbe4
FB
2347}
2348
2349/* fnabs */
7c58044c 2350/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2351static void gen_fnabs(DisasContext *ctx)
2352{
2353 if (unlikely(!ctx->fpu_enabled)) {
2354 gen_exception(ctx, POWERPC_EXCP_FPU);
2355 return;
2356 }
2357 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2358 1ULL << 63);
2359 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2360}
2361
9a64fbe4 2362/* fneg */
7c58044c 2363/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2364static void gen_fneg(DisasContext *ctx)
2365{
2366 if (unlikely(!ctx->fpu_enabled)) {
2367 gen_exception(ctx, POWERPC_EXCP_FPU);
2368 return;
2369 }
2370 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2371 1ULL << 63);
2372 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2373}
9a64fbe4 2374
f0332888
AJ
2375/* fcpsgn: PowerPC 2.05 specification */
2376/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2377static void gen_fcpsgn(DisasContext *ctx)
2378{
2379 if (unlikely(!ctx->fpu_enabled)) {
2380 gen_exception(ctx, POWERPC_EXCP_FPU);
2381 return;
2382 }
2383 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2384 cpu_fpr[rB(ctx->opcode)], 0, 63);
2385 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2386}
2387
097ec5d8
TM
2388static void gen_fmrgew(DisasContext *ctx)
2389{
2390 TCGv_i64 b0;
2391 if (unlikely(!ctx->fpu_enabled)) {
2392 gen_exception(ctx, POWERPC_EXCP_FPU);
2393 return;
2394 }
2395 b0 = tcg_temp_new_i64();
2396 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2397 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2398 b0, 0, 32);
2399 tcg_temp_free_i64(b0);
2400}
2401
2402static void gen_fmrgow(DisasContext *ctx)
2403{
2404 if (unlikely(!ctx->fpu_enabled)) {
2405 gen_exception(ctx, POWERPC_EXCP_FPU);
2406 return;
2407 }
2408 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2409 cpu_fpr[rB(ctx->opcode)],
2410 cpu_fpr[rA(ctx->opcode)],
2411 32, 32);
2412}
2413
79aceca5 2414/*** Floating-Point status & ctrl register ***/
99e300ef 2415
54623277 2416/* mcrfs */
99e300ef 2417static void gen_mcrfs(DisasContext *ctx)
79aceca5 2418{
30304420 2419 TCGv tmp = tcg_temp_new();
7c58044c
JM
2420 int bfa;
2421
76a66253 2422 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2423 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2424 return;
2425 }
7c58044c 2426 bfa = 4 * (7 - crfS(ctx->opcode));
30304420
DG
2427 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2428 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2429 tcg_temp_free(tmp);
e1571908 2430 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
30304420 2431 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
79aceca5
FB
2432}
2433
2434/* mffs */
99e300ef 2435static void gen_mffs(DisasContext *ctx)
79aceca5 2436{
76a66253 2437 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2438 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2439 return;
2440 }
7c58044c 2441 gen_reset_fpstatus();
30304420 2442 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
af12906f 2443 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
79aceca5
FB
2444}
2445
2446/* mtfsb0 */
99e300ef 2447static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2448{
fb0eaffc 2449 uint8_t crb;
3b46e624 2450
76a66253 2451 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2452 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2453 return;
2454 }
6e35d524 2455 crb = 31 - crbD(ctx->opcode);
7c58044c 2456 gen_reset_fpstatus();
6e35d524 2457 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2458 TCGv_i32 t0;
2459 /* NIP cannot be restored if the memory exception comes from an helper */
2460 gen_update_nip(ctx, ctx->nip - 4);
2461 t0 = tcg_const_i32(crb);
8e703949 2462 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2463 tcg_temp_free_i32(t0);
2464 }
7c58044c 2465 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2466 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2467 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2468 }
79aceca5
FB
2469}
2470
2471/* mtfsb1 */
99e300ef 2472static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2473{
fb0eaffc 2474 uint8_t crb;
3b46e624 2475
76a66253 2476 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2477 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2478 return;
2479 }
6e35d524 2480 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2481 gen_reset_fpstatus();
2482 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2483 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2484 TCGv_i32 t0;
2485 /* NIP cannot be restored if the memory exception comes from an helper */
2486 gen_update_nip(ctx, ctx->nip - 4);
2487 t0 = tcg_const_i32(crb);
8e703949 2488 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2489 tcg_temp_free_i32(t0);
af12906f 2490 }
7c58044c 2491 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2492 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2493 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2494 }
2495 /* We can raise a differed exception */
8e703949 2496 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2497}
2498
2499/* mtfsf */
99e300ef 2500static void gen_mtfsf(DisasContext *ctx)
79aceca5 2501{
0f2f39c2 2502 TCGv_i32 t0;
7d08d856 2503 int flm, l, w;
af12906f 2504
76a66253 2505 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2506 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2507 return;
2508 }
7d08d856
AJ
2509 flm = FPFLM(ctx->opcode);
2510 l = FPL(ctx->opcode);
2511 w = FPW(ctx->opcode);
2512 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2513 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2514 return;
2515 }
eb44b959
AJ
2516 /* NIP cannot be restored if the memory exception comes from an helper */
2517 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2518 gen_reset_fpstatus();
7d08d856
AJ
2519 if (l) {
2520 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2521 } else {
2522 t0 = tcg_const_i32(flm << (w * 8));
2523 }
8e703949 2524 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2525 tcg_temp_free_i32(t0);
7c58044c 2526 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2527 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2528 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2529 }
2530 /* We can raise a differed exception */
8e703949 2531 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2532}
2533
2534/* mtfsfi */
99e300ef 2535static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2536{
7d08d856 2537 int bf, sh, w;
0f2f39c2
AJ
2538 TCGv_i64 t0;
2539 TCGv_i32 t1;
7c58044c 2540
76a66253 2541 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2542 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2543 return;
2544 }
7d08d856
AJ
2545 w = FPW(ctx->opcode);
2546 bf = FPBF(ctx->opcode);
2547 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2548 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2549 return;
2550 }
2551 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2552 /* NIP cannot be restored if the memory exception comes from an helper */
2553 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2554 gen_reset_fpstatus();
7d08d856 2555 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2556 t1 = tcg_const_i32(1 << sh);
8e703949 2557 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2558 tcg_temp_free_i64(t0);
2559 tcg_temp_free_i32(t1);
7c58044c 2560 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2561 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2562 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2563 }
2564 /* We can raise a differed exception */
8e703949 2565 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2566}
2567
76a66253
JM
2568/*** Addressing modes ***/
2569/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2570static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2571 target_long maskl)
76a66253
JM
2572{
2573 target_long simm = SIMM(ctx->opcode);
2574
be147d08 2575 simm &= ~maskl;
76db3ba4 2576 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2577 if (NARROW_MODE(ctx)) {
2578 simm = (uint32_t)simm;
2579 }
e2be8d8d 2580 tcg_gen_movi_tl(EA, simm);
76db3ba4 2581 } else if (likely(simm != 0)) {
e2be8d8d 2582 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2583 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2584 tcg_gen_ext32u_tl(EA, EA);
2585 }
76db3ba4 2586 } else {
c791fe84 2587 if (NARROW_MODE(ctx)) {
76db3ba4 2588 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2589 } else {
2590 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2591 }
76db3ba4 2592 }
76a66253
JM
2593}
2594
636aa200 2595static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2596{
76db3ba4 2597 if (rA(ctx->opcode) == 0) {
c791fe84 2598 if (NARROW_MODE(ctx)) {
76db3ba4 2599 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2600 } else {
2601 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2602 }
76db3ba4 2603 } else {
e2be8d8d 2604 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2605 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2606 tcg_gen_ext32u_tl(EA, EA);
2607 }
76db3ba4 2608 }
76a66253
JM
2609}
2610
636aa200 2611static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2612{
76db3ba4 2613 if (rA(ctx->opcode) == 0) {
e2be8d8d 2614 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2615 } else if (NARROW_MODE(ctx)) {
2616 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2617 } else {
c791fe84 2618 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2619 }
2620}
2621
636aa200
BS
2622static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2623 target_long val)
76db3ba4
AJ
2624{
2625 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2626 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2627 tcg_gen_ext32u_tl(ret, ret);
2628 }
76a66253
JM
2629}
2630
636aa200 2631static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32
AJ
2632{
2633 int l1 = gen_new_label();
2634 TCGv t0 = tcg_temp_new();
2635 TCGv_i32 t1, t2;
2636 /* NIP cannot be restored if the memory exception comes from an helper */
2637 gen_update_nip(ctx, ctx->nip - 4);
2638 tcg_gen_andi_tl(t0, EA, mask);
2639 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2640 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2641 t2 = tcg_const_i32(0);
e5f17ac6 2642 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2643 tcg_temp_free_i32(t1);
2644 tcg_temp_free_i32(t2);
2645 gen_set_label(l1);
2646 tcg_temp_free(t0);
2647}
2648
7863667f 2649/*** Integer load ***/
636aa200 2650static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2651{
2652 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2653}
2654
636aa200 2655static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2656{
2657 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2658}
2659
636aa200 2660static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2661{
2662 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2663 if (unlikely(ctx->le_mode)) {
fa3966a3 2664 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2665 }
b61f2753
AJ
2666}
2667
636aa200 2668static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2669{
76db3ba4 2670 if (unlikely(ctx->le_mode)) {
76db3ba4 2671 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
fa3966a3 2672 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2673 tcg_gen_ext16s_tl(arg1, arg1);
76db3ba4
AJ
2674 } else {
2675 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2676 }
b61f2753
AJ
2677}
2678
636aa200 2679static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2680{
76db3ba4
AJ
2681 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2682 if (unlikely(ctx->le_mode)) {
fa3966a3 2683 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2684 }
b61f2753
AJ
2685}
2686
f976b09e
AG
2687static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2688{
2689 TCGv tmp = tcg_temp_new();
2690 gen_qemu_ld32u(ctx, tmp, addr);
2691 tcg_gen_extu_tl_i64(val, tmp);
2692 tcg_temp_free(tmp);
2693}
2694
636aa200 2695static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2696{
a457e7ee 2697 if (unlikely(ctx->le_mode)) {
76db3ba4 2698 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
fa3966a3
AJ
2699 tcg_gen_bswap32_tl(arg1, arg1);
2700 tcg_gen_ext32s_tl(arg1, arg1);
b61f2753 2701 } else
76db3ba4 2702 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2703}
2704
cac7f0ba
TM
2705static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2706{
2707 TCGv tmp = tcg_temp_new();
2708 gen_qemu_ld32s(ctx, tmp, addr);
2709 tcg_gen_ext_tl_i64(val, tmp);
2710 tcg_temp_free(tmp);
2711}
2712
636aa200 2713static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2714{
76db3ba4
AJ
2715 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2716 if (unlikely(ctx->le_mode)) {
66896cb8 2717 tcg_gen_bswap64_i64(arg1, arg1);
76db3ba4 2718 }
b61f2753
AJ
2719}
2720
636aa200 2721static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2722{
76db3ba4 2723 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2724}
2725
636aa200 2726static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2727{
76db3ba4 2728 if (unlikely(ctx->le_mode)) {
76db3ba4
AJ
2729 TCGv t0 = tcg_temp_new();
2730 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2731 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2732 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2733 tcg_temp_free(t0);
76db3ba4
AJ
2734 } else {
2735 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2736 }
b61f2753
AJ
2737}
2738
636aa200 2739static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2740{
76db3ba4 2741 if (unlikely(ctx->le_mode)) {
fa3966a3
AJ
2742 TCGv t0 = tcg_temp_new();
2743 tcg_gen_ext32u_tl(t0, arg1);
2744 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2745 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2746 tcg_temp_free(t0);
76db3ba4
AJ
2747 } else {
2748 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2749 }
b61f2753
AJ
2750}
2751
f976b09e
AG
2752static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2753{
2754 TCGv tmp = tcg_temp_new();
2755 tcg_gen_trunc_i64_tl(tmp, val);
2756 gen_qemu_st32(ctx, tmp, addr);
2757 tcg_temp_free(tmp);
2758}
2759
636aa200 2760static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2761{
76db3ba4 2762 if (unlikely(ctx->le_mode)) {
a7812ae4 2763 TCGv_i64 t0 = tcg_temp_new_i64();
66896cb8 2764 tcg_gen_bswap64_i64(t0, arg1);
76db3ba4 2765 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
a7812ae4 2766 tcg_temp_free_i64(t0);
b61f2753 2767 } else
76db3ba4 2768 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2769}
2770
0c8aacd4 2771#define GEN_LD(name, ldop, opc, type) \
99e300ef 2772static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2773{ \
76db3ba4
AJ
2774 TCGv EA; \
2775 gen_set_access_type(ctx, ACCESS_INT); \
2776 EA = tcg_temp_new(); \
2777 gen_addr_imm_index(ctx, EA, 0); \
2778 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2779 tcg_temp_free(EA); \
79aceca5
FB
2780}
2781
0c8aacd4 2782#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2783static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2784{ \
b61f2753 2785 TCGv EA; \
76a66253
JM
2786 if (unlikely(rA(ctx->opcode) == 0 || \
2787 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2788 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2789 return; \
9a64fbe4 2790 } \
76db3ba4 2791 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2792 EA = tcg_temp_new(); \
9d53c753 2793 if (type == PPC_64B) \
76db3ba4 2794 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2795 else \
76db3ba4
AJ
2796 gen_addr_imm_index(ctx, EA, 0); \
2797 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2798 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2799 tcg_temp_free(EA); \
79aceca5
FB
2800}
2801
0c8aacd4 2802#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2803static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2804{ \
b61f2753 2805 TCGv EA; \
76a66253
JM
2806 if (unlikely(rA(ctx->opcode) == 0 || \
2807 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2808 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2809 return; \
9a64fbe4 2810 } \
76db3ba4 2811 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2812 EA = tcg_temp_new(); \
76db3ba4
AJ
2813 gen_addr_reg_index(ctx, EA); \
2814 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2815 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2816 tcg_temp_free(EA); \
79aceca5
FB
2817}
2818
cd6e9320 2819#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2820static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2821{ \
76db3ba4
AJ
2822 TCGv EA; \
2823 gen_set_access_type(ctx, ACCESS_INT); \
2824 EA = tcg_temp_new(); \
2825 gen_addr_reg_index(ctx, EA); \
2826 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2827 tcg_temp_free(EA); \
79aceca5 2828}
cd6e9320
TH
2829#define GEN_LDX(name, ldop, opc2, opc3, type) \
2830 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2831
0c8aacd4
AJ
2832#define GEN_LDS(name, ldop, op, type) \
2833GEN_LD(name, ldop, op | 0x20, type); \
2834GEN_LDU(name, ldop, op | 0x21, type); \
2835GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2836GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2837
2838/* lbz lbzu lbzux lbzx */
0c8aacd4 2839GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2840/* lha lhau lhaux lhax */
0c8aacd4 2841GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2842/* lhz lhzu lhzux lhzx */
0c8aacd4 2843GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2844/* lwz lwzu lwzux lwzx */
0c8aacd4 2845GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2846#if defined(TARGET_PPC64)
d9bce9d9 2847/* lwaux */
0c8aacd4 2848GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2849/* lwax */
0c8aacd4 2850GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2851/* ldux */
0c8aacd4 2852GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2853/* ldx */
0c8aacd4 2854GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2855
2856static void gen_ld(DisasContext *ctx)
d9bce9d9 2857{
b61f2753 2858 TCGv EA;
d9bce9d9
JM
2859 if (Rc(ctx->opcode)) {
2860 if (unlikely(rA(ctx->opcode) == 0 ||
2861 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2862 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2863 return;
2864 }
2865 }
76db3ba4 2866 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2867 EA = tcg_temp_new();
76db3ba4 2868 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2869 if (ctx->opcode & 0x02) {
2870 /* lwa (lwau is undefined) */
76db3ba4 2871 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2872 } else {
2873 /* ld - ldu */
76db3ba4 2874 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2875 }
d9bce9d9 2876 if (Rc(ctx->opcode))
b61f2753
AJ
2877 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2878 tcg_temp_free(EA);
d9bce9d9 2879}
99e300ef 2880
54623277 2881/* lq */
99e300ef 2882static void gen_lq(DisasContext *ctx)
be147d08 2883{
be147d08 2884 int ra, rd;
b61f2753 2885 TCGv EA;
be147d08 2886
e0498daa
TM
2887 /* lq is a legal user mode instruction starting in ISA 2.07 */
2888 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2889 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2890
2891 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 2892 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2893 return;
2894 }
e0498daa
TM
2895
2896 if (!le_is_supported && ctx->le_mode) {
2897 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2898 return;
2899 }
2900
be147d08
JM
2901 ra = rA(ctx->opcode);
2902 rd = rD(ctx->opcode);
2903 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2904 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2905 return;
2906 }
e0498daa 2907
76db3ba4 2908 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2909 EA = tcg_temp_new();
76db3ba4 2910 gen_addr_imm_index(ctx, EA, 0x0F);
e0498daa
TM
2911
2912 if (unlikely(ctx->le_mode)) {
2913 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2914 gen_addr_add(ctx, EA, EA, 8);
2915 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2916 } else {
2917 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2918 gen_addr_add(ctx, EA, EA, 8);
2919 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2920 }
b61f2753 2921 tcg_temp_free(EA);
be147d08 2922}
d9bce9d9 2923#endif
79aceca5
FB
2924
2925/*** Integer store ***/
0c8aacd4 2926#define GEN_ST(name, stop, opc, type) \
99e300ef 2927static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2928{ \
76db3ba4
AJ
2929 TCGv EA; \
2930 gen_set_access_type(ctx, ACCESS_INT); \
2931 EA = tcg_temp_new(); \
2932 gen_addr_imm_index(ctx, EA, 0); \
2933 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2934 tcg_temp_free(EA); \
79aceca5
FB
2935}
2936
0c8aacd4 2937#define GEN_STU(name, stop, opc, type) \
99e300ef 2938static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2939{ \
b61f2753 2940 TCGv EA; \
76a66253 2941 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2942 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2943 return; \
9a64fbe4 2944 } \
76db3ba4 2945 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2946 EA = tcg_temp_new(); \
9d53c753 2947 if (type == PPC_64B) \
76db3ba4 2948 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2949 else \
76db3ba4
AJ
2950 gen_addr_imm_index(ctx, EA, 0); \
2951 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2952 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2953 tcg_temp_free(EA); \
79aceca5
FB
2954}
2955
0c8aacd4 2956#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2957static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2958{ \
b61f2753 2959 TCGv EA; \
76a66253 2960 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2961 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2962 return; \
9a64fbe4 2963 } \
76db3ba4 2964 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2965 EA = tcg_temp_new(); \
76db3ba4
AJ
2966 gen_addr_reg_index(ctx, EA); \
2967 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2968 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2969 tcg_temp_free(EA); \
79aceca5
FB
2970}
2971
cd6e9320
TH
2972#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2973static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2974{ \
76db3ba4
AJ
2975 TCGv EA; \
2976 gen_set_access_type(ctx, ACCESS_INT); \
2977 EA = tcg_temp_new(); \
2978 gen_addr_reg_index(ctx, EA); \
2979 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2980 tcg_temp_free(EA); \
79aceca5 2981}
cd6e9320
TH
2982#define GEN_STX(name, stop, opc2, opc3, type) \
2983 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 2984
0c8aacd4
AJ
2985#define GEN_STS(name, stop, op, type) \
2986GEN_ST(name, stop, op | 0x20, type); \
2987GEN_STU(name, stop, op | 0x21, type); \
2988GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2989GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
2990
2991/* stb stbu stbux stbx */
0c8aacd4 2992GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 2993/* sth sthu sthux sthx */
0c8aacd4 2994GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 2995/* stw stwu stwux stwx */
0c8aacd4 2996GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 2997#if defined(TARGET_PPC64)
0c8aacd4
AJ
2998GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2999GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
3000
3001static void gen_std(DisasContext *ctx)
d9bce9d9 3002{
be147d08 3003 int rs;
b61f2753 3004 TCGv EA;
be147d08
JM
3005
3006 rs = rS(ctx->opcode);
84cab1e2
TM
3007 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3008
3009 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3010 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3011
3012 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 3013 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3014 return;
3015 }
84cab1e2
TM
3016
3017 if (!le_is_supported && ctx->le_mode) {
3018 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
d9bce9d9
JM
3019 return;
3020 }
84cab1e2
TM
3021
3022 if (unlikely(rs & 1)) {
3023 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3024 return;
3025 }
76db3ba4 3026 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3027 EA = tcg_temp_new();
76db3ba4 3028 gen_addr_imm_index(ctx, EA, 0x03);
84cab1e2
TM
3029
3030 if (unlikely(ctx->le_mode)) {
3031 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3032 gen_addr_add(ctx, EA, EA, 8);
3033 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3034 } else {
3035 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3036 gen_addr_add(ctx, EA, EA, 8);
3037 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3038 }
b61f2753 3039 tcg_temp_free(EA);
be147d08 3040 } else {
84cab1e2 3041 /* std / stdu*/
be147d08
JM
3042 if (Rc(ctx->opcode)) {
3043 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 3044 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3045 return;
3046 }
3047 }
76db3ba4 3048 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3049 EA = tcg_temp_new();
76db3ba4
AJ
3050 gen_addr_imm_index(ctx, EA, 0x03);
3051 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 3052 if (Rc(ctx->opcode))
b61f2753
AJ
3053 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3054 tcg_temp_free(EA);
d9bce9d9 3055 }
d9bce9d9
JM
3056}
3057#endif
79aceca5
FB
3058/*** Integer load and store with byte reverse ***/
3059/* lhbrx */
86178a57 3060static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3061{
76db3ba4
AJ
3062 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
3063 if (likely(!ctx->le_mode)) {
fa3966a3 3064 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 3065 }
b61f2753 3066}
0c8aacd4 3067GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 3068
79aceca5 3069/* lwbrx */
86178a57 3070static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3071{
76db3ba4
AJ
3072 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
3073 if (likely(!ctx->le_mode)) {
fa3966a3 3074 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 3075 }
b61f2753 3076}
0c8aacd4 3077GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 3078
cd6e9320
TH
3079#if defined(TARGET_PPC64)
3080/* ldbrx */
3081static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3082{
3083 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
3084 if (likely(!ctx->le_mode)) {
3085 tcg_gen_bswap64_tl(arg1, arg1);
3086 }
3087}
3088GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3089#endif /* TARGET_PPC64 */
3090
79aceca5 3091/* sthbrx */
86178a57 3092static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3093{
76db3ba4 3094 if (likely(!ctx->le_mode)) {
76db3ba4
AJ
3095 TCGv t0 = tcg_temp_new();
3096 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 3097 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
3098 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
3099 tcg_temp_free(t0);
76db3ba4
AJ
3100 } else {
3101 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
3102 }
b61f2753 3103}
0c8aacd4 3104GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 3105
79aceca5 3106/* stwbrx */
86178a57 3107static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3108{
76db3ba4 3109 if (likely(!ctx->le_mode)) {
fa3966a3
AJ
3110 TCGv t0 = tcg_temp_new();
3111 tcg_gen_ext32u_tl(t0, arg1);
3112 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
3113 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
3114 tcg_temp_free(t0);
76db3ba4
AJ
3115 } else {
3116 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
3117 }
b61f2753 3118}
0c8aacd4 3119GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 3120
cd6e9320
TH
3121#if defined(TARGET_PPC64)
3122/* stdbrx */
3123static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3124{
3125 if (likely(!ctx->le_mode)) {
3126 TCGv t0 = tcg_temp_new();
3127 tcg_gen_bswap64_tl(t0, arg1);
3128 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
3129 tcg_temp_free(t0);
3130 } else {
3131 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
3132 }
3133}
3134GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3135#endif /* TARGET_PPC64 */
3136
79aceca5 3137/*** Integer load and store multiple ***/
99e300ef 3138
54623277 3139/* lmw */
99e300ef 3140static void gen_lmw(DisasContext *ctx)
79aceca5 3141{
76db3ba4
AJ
3142 TCGv t0;
3143 TCGv_i32 t1;
3144 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3145 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3146 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3147 t0 = tcg_temp_new();
3148 t1 = tcg_const_i32(rD(ctx->opcode));
3149 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3150 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3151 tcg_temp_free(t0);
3152 tcg_temp_free_i32(t1);
79aceca5
FB
3153}
3154
3155/* stmw */
99e300ef 3156static void gen_stmw(DisasContext *ctx)
79aceca5 3157{
76db3ba4
AJ
3158 TCGv t0;
3159 TCGv_i32 t1;
3160 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3161 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3162 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3163 t0 = tcg_temp_new();
3164 t1 = tcg_const_i32(rS(ctx->opcode));
3165 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3166 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3167 tcg_temp_free(t0);
3168 tcg_temp_free_i32(t1);
79aceca5
FB
3169}
3170
3171/*** Integer load and store strings ***/
54623277 3172
79aceca5 3173/* lswi */
3fc6c082 3174/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3175 * rA is in the range of registers to be loaded.
3176 * In an other hand, IBM says this is valid, but rA won't be loaded.
3177 * For now, I'll follow the spec...
3178 */
99e300ef 3179static void gen_lswi(DisasContext *ctx)
79aceca5 3180{
dfbc799d
AJ
3181 TCGv t0;
3182 TCGv_i32 t1, t2;
79aceca5
FB
3183 int nb = NB(ctx->opcode);
3184 int start = rD(ctx->opcode);
9a64fbe4 3185 int ra = rA(ctx->opcode);
79aceca5
FB
3186 int nr;
3187
3188 if (nb == 0)
3189 nb = 32;
3190 nr = nb / 4;
76a66253
JM
3191 if (unlikely(((start + nr) > 32 &&
3192 start <= ra && (start + nr - 32) > ra) ||
3193 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
e06fcd75 3194 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3195 return;
297d8e62 3196 }
76db3ba4 3197 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3198 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3199 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3200 t0 = tcg_temp_new();
76db3ba4 3201 gen_addr_register(ctx, t0);
dfbc799d
AJ
3202 t1 = tcg_const_i32(nb);
3203 t2 = tcg_const_i32(start);
2f5a189c 3204 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3205 tcg_temp_free(t0);
3206 tcg_temp_free_i32(t1);
3207 tcg_temp_free_i32(t2);
79aceca5
FB
3208}
3209
3210/* lswx */
99e300ef 3211static void gen_lswx(DisasContext *ctx)
79aceca5 3212{
76db3ba4
AJ
3213 TCGv t0;
3214 TCGv_i32 t1, t2, t3;
3215 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3216 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3217 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3218 t0 = tcg_temp_new();
3219 gen_addr_reg_index(ctx, t0);
3220 t1 = tcg_const_i32(rD(ctx->opcode));
3221 t2 = tcg_const_i32(rA(ctx->opcode));
3222 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3223 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3224 tcg_temp_free(t0);
3225 tcg_temp_free_i32(t1);
3226 tcg_temp_free_i32(t2);
3227 tcg_temp_free_i32(t3);
79aceca5
FB
3228}
3229
3230/* stswi */
99e300ef 3231static void gen_stswi(DisasContext *ctx)
79aceca5 3232{
76db3ba4
AJ
3233 TCGv t0;
3234 TCGv_i32 t1, t2;
4b3686fa 3235 int nb = NB(ctx->opcode);
76db3ba4 3236 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3237 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3238 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3239 t0 = tcg_temp_new();
3240 gen_addr_register(ctx, t0);
4b3686fa
FB
3241 if (nb == 0)
3242 nb = 32;
dfbc799d 3243 t1 = tcg_const_i32(nb);
76db3ba4 3244 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3245 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3246 tcg_temp_free(t0);
3247 tcg_temp_free_i32(t1);
3248 tcg_temp_free_i32(t2);
79aceca5
FB
3249}
3250
3251/* stswx */
99e300ef 3252static void gen_stswx(DisasContext *ctx)
79aceca5 3253{
76db3ba4
AJ
3254 TCGv t0;
3255 TCGv_i32 t1, t2;
3256 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3257 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3258 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3259 t0 = tcg_temp_new();
3260 gen_addr_reg_index(ctx, t0);
3261 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3262 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3263 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3264 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3265 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3266 tcg_temp_free(t0);
3267 tcg_temp_free_i32(t1);
3268 tcg_temp_free_i32(t2);
79aceca5
FB
3269}
3270
3271/*** Memory synchronisation ***/
3272/* eieio */
99e300ef 3273static void gen_eieio(DisasContext *ctx)
79aceca5 3274{
79aceca5
FB
3275}
3276
3277/* isync */
99e300ef 3278static void gen_isync(DisasContext *ctx)
79aceca5 3279{
e06fcd75 3280 gen_stop_exception(ctx);
79aceca5
FB
3281}
3282
5c77a786
TM
3283#define LARX(name, len, loadop) \
3284static void gen_##name(DisasContext *ctx) \
3285{ \
3286 TCGv t0; \
3287 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3288 gen_set_access_type(ctx, ACCESS_RES); \
3289 t0 = tcg_temp_local_new(); \
3290 gen_addr_reg_index(ctx, t0); \
3291 if ((len) > 1) { \
3292 gen_check_align(ctx, t0, (len)-1); \
3293 } \
3294 gen_qemu_##loadop(ctx, gpr, t0); \
3295 tcg_gen_mov_tl(cpu_reserve, t0); \
3296 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3297 tcg_temp_free(t0); \
79aceca5
FB
3298}
3299
5c77a786
TM
3300/* lwarx */
3301LARX(lbarx, 1, ld8u);
3302LARX(lharx, 2, ld16u);
3303LARX(lwarx, 4, ld32u);
3304
3305
4425265b 3306#if defined(CONFIG_USER_ONLY)
587c51f7
TM
3307static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3308 int reg, int size)
4425265b
NF
3309{
3310 TCGv t0 = tcg_temp_new();
3311 uint32_t save_exception = ctx->exception;
3312
1328c2bf 3313 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3314 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3315 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3316 tcg_temp_free(t0);
3317 gen_update_nip(ctx, ctx->nip-4);
3318 ctx->exception = POWERPC_EXCP_BRANCH;
3319 gen_exception(ctx, POWERPC_EXCP_STCX);
3320 ctx->exception = save_exception;
3321}
4425265b 3322#else
587c51f7
TM
3323static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3324 int reg, int size)
3325{
3326 int l1;
4425265b 3327
587c51f7
TM
3328 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3329 l1 = gen_new_label();
3330 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3331 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3332#if defined(TARGET_PPC64)
3333 if (size == 8) {
3334 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3335 } else
3336#endif
3337 if (size == 4) {
3338 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3339 } else if (size == 2) {
3340 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
27b95bfe
TM
3341#if defined(TARGET_PPC64)
3342 } else if (size == 16) {
3707cd62 3343 TCGv gpr1, gpr2 , EA8;
27b95bfe
TM
3344 if (unlikely(ctx->le_mode)) {
3345 gpr1 = cpu_gpr[reg+1];
3346 gpr2 = cpu_gpr[reg];
3347 } else {
3348 gpr1 = cpu_gpr[reg];
3349 gpr2 = cpu_gpr[reg+1];
3350 }
3351 gen_qemu_st64(ctx, gpr1, EA);
3707cd62
TM
3352 EA8 = tcg_temp_local_new();
3353 gen_addr_add(ctx, EA8, EA, 8);
3354 gen_qemu_st64(ctx, gpr2, EA8);
3355 tcg_temp_free(EA8);
27b95bfe 3356#endif
587c51f7
TM
3357 } else {
3358 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
4425265b 3359 }
587c51f7
TM
3360 gen_set_label(l1);
3361 tcg_gen_movi_tl(cpu_reserve, -1);
3362}
4425265b 3363#endif
587c51f7
TM
3364
3365#define STCX(name, len) \
3366static void gen_##name(DisasContext *ctx) \
3367{ \
3368 TCGv t0; \
27b95bfe
TM
3369 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3370 gen_inval_exception(ctx, \
3371 POWERPC_EXCP_INVAL_INVAL); \
3372 return; \
3373 } \
587c51f7
TM
3374 gen_set_access_type(ctx, ACCESS_RES); \
3375 t0 = tcg_temp_local_new(); \
3376 gen_addr_reg_index(ctx, t0); \
3377 if (len > 1) { \
3378 gen_check_align(ctx, t0, (len)-1); \
3379 } \
3380 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3381 tcg_temp_free(t0); \
79aceca5
FB
3382}
3383
587c51f7
TM
3384STCX(stbcx_, 1);
3385STCX(sthcx_, 2);
3386STCX(stwcx_, 4);
3387
426613db 3388#if defined(TARGET_PPC64)
426613db 3389/* ldarx */
5c77a786 3390LARX(ldarx, 8, ld64);
426613db 3391
9c294d5a
TM
3392/* lqarx */
3393static void gen_lqarx(DisasContext *ctx)
3394{
3395 TCGv EA;
3396 int rd = rD(ctx->opcode);
3397 TCGv gpr1, gpr2;
3398
3399 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3400 (rd == rB(ctx->opcode)))) {
3401 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3402 return;
3403 }
3404
3405 gen_set_access_type(ctx, ACCESS_RES);
3406 EA = tcg_temp_local_new();
3407 gen_addr_reg_index(ctx, EA);
3408 gen_check_align(ctx, EA, 15);
3409 if (unlikely(ctx->le_mode)) {
3410 gpr1 = cpu_gpr[rd+1];
3411 gpr2 = cpu_gpr[rd];
3412 } else {
3413 gpr1 = cpu_gpr[rd];
3414 gpr2 = cpu_gpr[rd+1];
3415 }
3416 gen_qemu_ld64(ctx, gpr1, EA);
3417 tcg_gen_mov_tl(cpu_reserve, EA);
3418
3419 gen_addr_add(ctx, EA, EA, 8);
3420 gen_qemu_ld64(ctx, gpr2, EA);
3421
3422 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3423 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3424
3425 tcg_temp_free(EA);
3426}
3427
426613db 3428/* stdcx. */
587c51f7 3429STCX(stdcx_, 8);
27b95bfe 3430STCX(stqcx_, 16);
426613db
JM
3431#endif /* defined(TARGET_PPC64) */
3432
79aceca5 3433/* sync */
99e300ef 3434static void gen_sync(DisasContext *ctx)
79aceca5 3435{
79aceca5
FB
3436}
3437
0db1b20e 3438/* wait */
99e300ef 3439static void gen_wait(DisasContext *ctx)
0db1b20e 3440{
931ff272 3441 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3442 tcg_gen_st_i32(t0, cpu_env,
3443 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3444 tcg_temp_free_i32(t0);
0db1b20e 3445 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3446 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3447}
3448
79aceca5 3449/*** Floating-point load ***/
a0d7d5a7 3450#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3451static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3452{ \
a0d7d5a7 3453 TCGv EA; \
76a66253 3454 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3455 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3456 return; \
3457 } \
76db3ba4 3458 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3459 EA = tcg_temp_new(); \
76db3ba4
AJ
3460 gen_addr_imm_index(ctx, EA, 0); \
3461 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3462 tcg_temp_free(EA); \
79aceca5
FB
3463}
3464
a0d7d5a7 3465#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3466static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3467{ \
a0d7d5a7 3468 TCGv EA; \
76a66253 3469 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3470 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3471 return; \
3472 } \
76a66253 3473 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3474 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3475 return; \
9a64fbe4 3476 } \
76db3ba4 3477 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3478 EA = tcg_temp_new(); \
76db3ba4
AJ
3479 gen_addr_imm_index(ctx, EA, 0); \
3480 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3481 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3482 tcg_temp_free(EA); \
79aceca5
FB
3483}
3484
a0d7d5a7 3485#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3486static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3487{ \
a0d7d5a7 3488 TCGv EA; \
76a66253 3489 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3490 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3491 return; \
3492 } \
76a66253 3493 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3494 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3495 return; \
9a64fbe4 3496 } \
76db3ba4 3497 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3498 EA = tcg_temp_new(); \
76db3ba4
AJ
3499 gen_addr_reg_index(ctx, EA); \
3500 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3501 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3502 tcg_temp_free(EA); \
79aceca5
FB
3503}
3504
a0d7d5a7 3505#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3506static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3507{ \
a0d7d5a7 3508 TCGv EA; \
76a66253 3509 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3510 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3511 return; \
3512 } \
76db3ba4 3513 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3514 EA = tcg_temp_new(); \
76db3ba4
AJ
3515 gen_addr_reg_index(ctx, EA); \
3516 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3517 tcg_temp_free(EA); \
79aceca5
FB
3518}
3519
a0d7d5a7
AJ
3520#define GEN_LDFS(name, ldop, op, type) \
3521GEN_LDF(name, ldop, op | 0x20, type); \
3522GEN_LDUF(name, ldop, op | 0x21, type); \
3523GEN_LDUXF(name, ldop, op | 0x01, type); \
3524GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3525
636aa200 3526static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3527{
3528 TCGv t0 = tcg_temp_new();
3529 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3530 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3531 tcg_gen_trunc_tl_i32(t1, t0);
3532 tcg_temp_free(t0);
8e703949 3533 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3534 tcg_temp_free_i32(t1);
3535}
79aceca5 3536
a0d7d5a7
AJ
3537 /* lfd lfdu lfdux lfdx */
3538GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3539 /* lfs lfsu lfsux lfsx */
3540GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3541
05050ee8
AJ
3542/* lfdp */
3543static void gen_lfdp(DisasContext *ctx)
3544{
3545 TCGv EA;
3546 if (unlikely(!ctx->fpu_enabled)) {
3547 gen_exception(ctx, POWERPC_EXCP_FPU);
3548 return;
3549 }
3550 gen_set_access_type(ctx, ACCESS_FLOAT);
3551 EA = tcg_temp_new();
3552 gen_addr_imm_index(ctx, EA, 0); \
3553 if (unlikely(ctx->le_mode)) {
3554 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3555 tcg_gen_addi_tl(EA, EA, 8);
3556 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3557 } else {
3558 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3559 tcg_gen_addi_tl(EA, EA, 8);
3560 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3561 }
3562 tcg_temp_free(EA);
3563}
3564
3565/* lfdpx */
3566static void gen_lfdpx(DisasContext *ctx)
3567{
3568 TCGv EA;
3569 if (unlikely(!ctx->fpu_enabled)) {
3570 gen_exception(ctx, POWERPC_EXCP_FPU);
3571 return;
3572 }
3573 gen_set_access_type(ctx, ACCESS_FLOAT);
3574 EA = tcg_temp_new();
3575 gen_addr_reg_index(ctx, EA);
3576 if (unlikely(ctx->le_mode)) {
3577 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3578 tcg_gen_addi_tl(EA, EA, 8);
3579 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3580 } else {
3581 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3582 tcg_gen_addi_tl(EA, EA, 8);
3583 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3584 }
3585 tcg_temp_free(EA);
3586}
3587
199f830d
AJ
3588/* lfiwax */
3589static void gen_lfiwax(DisasContext *ctx)
3590{
3591 TCGv EA;
3592 TCGv t0;
3593 if (unlikely(!ctx->fpu_enabled)) {
3594 gen_exception(ctx, POWERPC_EXCP_FPU);
3595 return;
3596 }
3597 gen_set_access_type(ctx, ACCESS_FLOAT);
3598 EA = tcg_temp_new();
3599 t0 = tcg_temp_new();
3600 gen_addr_reg_index(ctx, EA);
909eedb7 3601 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3602 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3603 tcg_temp_free(EA);
3604 tcg_temp_free(t0);
3605}
3606
66c3e328
TM
3607/* lfiwzx */
3608static void gen_lfiwzx(DisasContext *ctx)
3609{
3610 TCGv EA;
3611 if (unlikely(!ctx->fpu_enabled)) {
3612 gen_exception(ctx, POWERPC_EXCP_FPU);
3613 return;
3614 }
3615 gen_set_access_type(ctx, ACCESS_FLOAT);
3616 EA = tcg_temp_new();
3617 gen_addr_reg_index(ctx, EA);
3618 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3619 tcg_temp_free(EA);
3620}
79aceca5 3621/*** Floating-point store ***/
a0d7d5a7 3622#define GEN_STF(name, stop, opc, type) \
99e300ef 3623static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3624{ \
a0d7d5a7 3625 TCGv EA; \
76a66253 3626 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3627 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3628 return; \
3629 } \
76db3ba4 3630 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3631 EA = tcg_temp_new(); \
76db3ba4
AJ
3632 gen_addr_imm_index(ctx, EA, 0); \
3633 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3634 tcg_temp_free(EA); \
79aceca5
FB
3635}
3636
a0d7d5a7 3637#define GEN_STUF(name, stop, opc, type) \
99e300ef 3638static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3639{ \
a0d7d5a7 3640 TCGv EA; \
76a66253 3641 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3642 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3643 return; \
3644 } \
76a66253 3645 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3646 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3647 return; \
9a64fbe4 3648 } \
76db3ba4 3649 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3650 EA = tcg_temp_new(); \
76db3ba4
AJ
3651 gen_addr_imm_index(ctx, EA, 0); \
3652 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3653 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3654 tcg_temp_free(EA); \
79aceca5
FB
3655}
3656
a0d7d5a7 3657#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3658static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3659{ \
a0d7d5a7 3660 TCGv EA; \
76a66253 3661 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3662 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3663 return; \
3664 } \
76a66253 3665 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3666 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3667 return; \
9a64fbe4 3668 } \
76db3ba4 3669 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3670 EA = tcg_temp_new(); \
76db3ba4
AJ
3671 gen_addr_reg_index(ctx, EA); \
3672 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3673 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3674 tcg_temp_free(EA); \
79aceca5
FB
3675}
3676
a0d7d5a7 3677#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3678static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3679{ \
a0d7d5a7 3680 TCGv EA; \
76a66253 3681 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3682 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3683 return; \
3684 } \
76db3ba4 3685 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3686 EA = tcg_temp_new(); \
76db3ba4
AJ
3687 gen_addr_reg_index(ctx, EA); \
3688 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3689 tcg_temp_free(EA); \
79aceca5
FB
3690}
3691
a0d7d5a7
AJ
3692#define GEN_STFS(name, stop, op, type) \
3693GEN_STF(name, stop, op | 0x20, type); \
3694GEN_STUF(name, stop, op | 0x21, type); \
3695GEN_STUXF(name, stop, op | 0x01, type); \
3696GEN_STXF(name, stop, 0x17, op | 0x00, type)
3697
636aa200 3698static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3699{
3700 TCGv_i32 t0 = tcg_temp_new_i32();
3701 TCGv t1 = tcg_temp_new();
8e703949 3702 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3703 tcg_gen_extu_i32_tl(t1, t0);
3704 tcg_temp_free_i32(t0);
76db3ba4 3705 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3706 tcg_temp_free(t1);
3707}
79aceca5
FB
3708
3709/* stfd stfdu stfdux stfdx */
a0d7d5a7 3710GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3711/* stfs stfsu stfsux stfsx */
a0d7d5a7 3712GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3713
44bc0c4d
AJ
3714/* stfdp */
3715static void gen_stfdp(DisasContext *ctx)
3716{
3717 TCGv EA;
3718 if (unlikely(!ctx->fpu_enabled)) {
3719 gen_exception(ctx, POWERPC_EXCP_FPU);
3720 return;
3721 }
3722 gen_set_access_type(ctx, ACCESS_FLOAT);
3723 EA = tcg_temp_new();
3724 gen_addr_imm_index(ctx, EA, 0); \
3725 if (unlikely(ctx->le_mode)) {
3726 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3727 tcg_gen_addi_tl(EA, EA, 8);
3728 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3729 } else {
3730 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3731 tcg_gen_addi_tl(EA, EA, 8);
3732 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3733 }
3734 tcg_temp_free(EA);
3735}
3736
3737/* stfdpx */
3738static void gen_stfdpx(DisasContext *ctx)
3739{
3740 TCGv EA;
3741 if (unlikely(!ctx->fpu_enabled)) {
3742 gen_exception(ctx, POWERPC_EXCP_FPU);
3743 return;
3744 }
3745 gen_set_access_type(ctx, ACCESS_FLOAT);
3746 EA = tcg_temp_new();
3747 gen_addr_reg_index(ctx, EA);
3748 if (unlikely(ctx->le_mode)) {
3749 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3750 tcg_gen_addi_tl(EA, EA, 8);
3751 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3752 } else {
3753 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3754 tcg_gen_addi_tl(EA, EA, 8);
3755 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3756 }
3757 tcg_temp_free(EA);
3758}
3759
79aceca5 3760/* Optional: */
636aa200 3761static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3762{
3763 TCGv t0 = tcg_temp_new();
3764 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3765 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3766 tcg_temp_free(t0);
3767}
79aceca5 3768/* stfiwx */
a0d7d5a7 3769GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3770
697ab892
DG
3771static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3772{
3773#if defined(TARGET_PPC64)
3774 if (ctx->has_cfar)
3775 tcg_gen_movi_tl(cpu_cfar, nip);
3776#endif
3777}
3778
79aceca5 3779/*** Branch ***/
636aa200 3780static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362
FB
3781{
3782 TranslationBlock *tb;
3783 tb = ctx->tb;
e0c8f9ce 3784 if (NARROW_MODE(ctx)) {
a2ffb812 3785 dest = (uint32_t) dest;
e0c8f9ce 3786 }
57fec1fe 3787 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
8cbcb4fa 3788 likely(!ctx->singlestep_enabled)) {
57fec1fe 3789 tcg_gen_goto_tb(n);
a2ffb812 3790 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cfd0495 3791 tcg_gen_exit_tb((uintptr_t)tb + n);
c1942362 3792 } else {
a2ffb812 3793 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3794 if (unlikely(ctx->singlestep_enabled)) {
3795 if ((ctx->singlestep_enabled &
bdc4e053 3796 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3797 (ctx->exception == POWERPC_EXCP_BRANCH ||
3798 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3799 target_ulong tmp = ctx->nip;
3800 ctx->nip = dest;
e06fcd75 3801 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3802 ctx->nip = tmp;
3803 }
3804 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3805 gen_debug_exception(ctx);
8cbcb4fa
AJ
3806 }
3807 }
57fec1fe 3808 tcg_gen_exit_tb(0);
c1942362 3809 }
c53be334
FB
3810}
3811
636aa200 3812static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3813{
e0c8f9ce
RH
3814 if (NARROW_MODE(ctx)) {
3815 nip = (uint32_t)nip;
3816 }
3817 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3818}
3819
79aceca5 3820/* b ba bl bla */
99e300ef 3821static void gen_b(DisasContext *ctx)
79aceca5 3822{
76a66253 3823 target_ulong li, target;
38a64f9d 3824
8cbcb4fa 3825 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3826 /* sign extend LI */
e0c8f9ce
RH
3827 li = LI(ctx->opcode);
3828 li = (li ^ 0x02000000) - 0x02000000;
3829 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3830 target = ctx->nip + li - 4;
e0c8f9ce 3831 } else {
9a64fbe4 3832 target = li;
e0c8f9ce
RH
3833 }
3834 if (LK(ctx->opcode)) {
e1833e1f 3835 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3836 }
697ab892 3837 gen_update_cfar(ctx, ctx->nip);
c1942362 3838 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3839}
3840
e98a6e40
FB
3841#define BCOND_IM 0
3842#define BCOND_LR 1
3843#define BCOND_CTR 2
52a4984d 3844#define BCOND_TAR 3
e98a6e40 3845
636aa200 3846static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3847{
d9bce9d9 3848 uint32_t bo = BO(ctx->opcode);
05f92404 3849 int l1;
a2ffb812 3850 TCGv target;
e98a6e40 3851
8cbcb4fa 3852 ctx->exception = POWERPC_EXCP_BRANCH;
52a4984d 3853 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
a7812ae4 3854 target = tcg_temp_local_new();
a2ffb812
AJ
3855 if (type == BCOND_CTR)
3856 tcg_gen_mov_tl(target, cpu_ctr);
52a4984d
TM
3857 else if (type == BCOND_TAR)
3858 gen_load_spr(target, SPR_TAR);
a2ffb812
AJ
3859 else
3860 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3861 } else {
3862 TCGV_UNUSED(target);
e98a6e40 3863 }
e1833e1f
JM
3864 if (LK(ctx->opcode))
3865 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3866 l1 = gen_new_label();
3867 if ((bo & 0x4) == 0) {
3868 /* Decrement and test CTR */
a7812ae4 3869 TCGv temp = tcg_temp_new();
a2ffb812 3870 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3871 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3872 return;
3873 }
3874 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3875 if (NARROW_MODE(ctx)) {
a2ffb812 3876 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3877 } else {
a2ffb812 3878 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3879 }
a2ffb812
AJ
3880 if (bo & 0x2) {
3881 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3882 } else {
3883 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3884 }
a7812ae4 3885 tcg_temp_free(temp);
a2ffb812
AJ
3886 }
3887 if ((bo & 0x10) == 0) {
3888 /* Test CR */
3889 uint32_t bi = BI(ctx->opcode);
3890 uint32_t mask = 1 << (3 - (bi & 0x03));
a7812ae4 3891 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3892
d9bce9d9 3893 if (bo & 0x8) {
a2ffb812
AJ
3894 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3895 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3896 } else {
a2ffb812
AJ
3897 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3898 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3899 }
a7812ae4 3900 tcg_temp_free_i32(temp);
d9bce9d9 3901 }
697ab892 3902 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3903 if (type == BCOND_IM) {
a2ffb812
AJ
3904 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3905 if (likely(AA(ctx->opcode) == 0)) {
3906 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3907 } else {
3908 gen_goto_tb(ctx, 0, li);
3909 }
c53be334 3910 gen_set_label(l1);
c1942362 3911 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3912 } else {
e0c8f9ce 3913 if (NARROW_MODE(ctx)) {
a2ffb812 3914 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3915 } else {
a2ffb812 3916 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3917 }
a2ffb812
AJ
3918 tcg_gen_exit_tb(0);
3919 gen_set_label(l1);
e0c8f9ce 3920 gen_update_nip(ctx, ctx->nip);
57fec1fe 3921 tcg_gen_exit_tb(0);
08e46e54 3922 }
e98a6e40
FB
3923}
3924
99e300ef 3925static void gen_bc(DisasContext *ctx)
3b46e624 3926{
e98a6e40
FB
3927 gen_bcond(ctx, BCOND_IM);
3928}
3929
99e300ef 3930static void gen_bcctr(DisasContext *ctx)
3b46e624 3931{
e98a6e40
FB
3932 gen_bcond(ctx, BCOND_CTR);
3933}
3934
99e300ef 3935static void gen_bclr(DisasContext *ctx)
3b46e624 3936{
e98a6e40
FB
3937 gen_bcond(ctx, BCOND_LR);
3938}
79aceca5 3939
52a4984d
TM
3940static void gen_bctar(DisasContext *ctx)
3941{
3942 gen_bcond(ctx, BCOND_TAR);
3943}
3944
79aceca5 3945/*** Condition register logical ***/
e1571908 3946#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 3947static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3948{ \
fc0d441e
JM
3949 uint8_t bitmask; \
3950 int sh; \
a7812ae4 3951 TCGv_i32 t0, t1; \
fc0d441e 3952 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 3953 t0 = tcg_temp_new_i32(); \
fc0d441e 3954 if (sh > 0) \
fea0c503 3955 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 3956 else if (sh < 0) \
fea0c503 3957 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 3958 else \
fea0c503 3959 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 3960 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
3961 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3962 if (sh > 0) \
fea0c503 3963 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 3964 else if (sh < 0) \
fea0c503 3965 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 3966 else \
fea0c503
AJ
3967 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3968 tcg_op(t0, t0, t1); \
fc0d441e 3969 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
fea0c503
AJ
3970 tcg_gen_andi_i32(t0, t0, bitmask); \
3971 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3972 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
3973 tcg_temp_free_i32(t0); \
3974 tcg_temp_free_i32(t1); \
79aceca5
FB
3975}
3976
3977/* crand */
e1571908 3978GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 3979/* crandc */
e1571908 3980GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 3981/* creqv */
e1571908 3982GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 3983/* crnand */
e1571908 3984GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 3985/* crnor */
e1571908 3986GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 3987/* cror */
e1571908 3988GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 3989/* crorc */
e1571908 3990GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 3991/* crxor */
e1571908 3992GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 3993
54623277 3994/* mcrf */
99e300ef 3995static void gen_mcrf(DisasContext *ctx)
79aceca5 3996{
47e4661c 3997 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
3998}
3999
4000/*** System linkage ***/
99e300ef 4001
54623277 4002/* rfi (mem_idx only) */
99e300ef 4003static void gen_rfi(DisasContext *ctx)
79aceca5 4004{
9a64fbe4 4005#if defined(CONFIG_USER_ONLY)
e06fcd75 4006 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
4007#else
4008 /* Restore CPU state */
76db3ba4 4009 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4010 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4011 return;
9a64fbe4 4012 }
697ab892 4013 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4014 gen_helper_rfi(cpu_env);
e06fcd75 4015 gen_sync_exception(ctx);
9a64fbe4 4016#endif
79aceca5
FB
4017}
4018
426613db 4019#if defined(TARGET_PPC64)
99e300ef 4020static void gen_rfid(DisasContext *ctx)
426613db
JM
4021{
4022#if defined(CONFIG_USER_ONLY)
e06fcd75 4023 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4024#else
4025 /* Restore CPU state */
76db3ba4 4026 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4027 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4028 return;
4029 }
697ab892 4030 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4031 gen_helper_rfid(cpu_env);
e06fcd75 4032 gen_sync_exception(ctx);
426613db
JM
4033#endif
4034}
426613db 4035
99e300ef 4036static void gen_hrfid(DisasContext *ctx)
be147d08
JM
4037{
4038#if defined(CONFIG_USER_ONLY)
e06fcd75 4039 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4040#else
4041 /* Restore CPU state */
76db3ba4 4042 if (unlikely(ctx->mem_idx <= 1)) {
e06fcd75 4043 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4044 return;
4045 }
e5f17ac6 4046 gen_helper_hrfid(cpu_env);
e06fcd75 4047 gen_sync_exception(ctx);
be147d08
JM
4048#endif
4049}
4050#endif
4051
79aceca5 4052/* sc */
417bf010
JM
4053#if defined(CONFIG_USER_ONLY)
4054#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4055#else
4056#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4057#endif
99e300ef 4058static void gen_sc(DisasContext *ctx)
79aceca5 4059{
e1833e1f
JM
4060 uint32_t lev;
4061
4062 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 4063 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
4064}
4065
4066/*** Trap ***/
99e300ef 4067
54623277 4068/* tw */
99e300ef 4069static void gen_tw(DisasContext *ctx)
79aceca5 4070{
cab3bee2 4071 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4072 /* Update the nip since this might generate a trap exception */
4073 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4074 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4075 t0);
cab3bee2 4076 tcg_temp_free_i32(t0);
79aceca5
FB
4077}
4078
4079/* twi */
99e300ef 4080static void gen_twi(DisasContext *ctx)
79aceca5 4081{
cab3bee2
AJ
4082 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4083 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4084 /* Update the nip since this might generate a trap exception */
4085 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4086 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4087 tcg_temp_free(t0);
4088 tcg_temp_free_i32(t1);
79aceca5
FB
4089}
4090
d9bce9d9
JM
4091#if defined(TARGET_PPC64)
4092/* td */
99e300ef 4093static void gen_td(DisasContext *ctx)
d9bce9d9 4094{
cab3bee2 4095 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4096 /* Update the nip since this might generate a trap exception */
4097 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4098 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4099 t0);
cab3bee2 4100 tcg_temp_free_i32(t0);
d9bce9d9
JM
4101}
4102
4103/* tdi */
99e300ef 4104static void gen_tdi(DisasContext *ctx)
d9bce9d9 4105{
cab3bee2
AJ
4106 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4107 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4108 /* Update the nip since this might generate a trap exception */
4109 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4110 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4111 tcg_temp_free(t0);
4112 tcg_temp_free_i32(t1);
d9bce9d9
JM
4113}
4114#endif
4115
79aceca5 4116/*** Processor control ***/
99e300ef 4117
da91a00f
RH
4118static void gen_read_xer(TCGv dst)
4119{
4120 TCGv t0 = tcg_temp_new();
4121 TCGv t1 = tcg_temp_new();
4122 TCGv t2 = tcg_temp_new();
4123 tcg_gen_mov_tl(dst, cpu_xer);
4124 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4125 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4126 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4127 tcg_gen_or_tl(t0, t0, t1);
4128 tcg_gen_or_tl(dst, dst, t2);
4129 tcg_gen_or_tl(dst, dst, t0);
4130 tcg_temp_free(t0);
4131 tcg_temp_free(t1);
4132 tcg_temp_free(t2);
4133}
4134
4135static void gen_write_xer(TCGv src)
4136{
4137 tcg_gen_andi_tl(cpu_xer, src,
4138 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4139 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4140 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4141 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4142 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4143 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4144 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4145}
4146
54623277 4147/* mcrxr */
99e300ef 4148static void gen_mcrxr(DisasContext *ctx)
79aceca5 4149{
da91a00f
RH
4150 TCGv_i32 t0 = tcg_temp_new_i32();
4151 TCGv_i32 t1 = tcg_temp_new_i32();
4152 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4153
4154 tcg_gen_trunc_tl_i32(t0, cpu_so);
4155 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4156 tcg_gen_trunc_tl_i32(dst, cpu_ca);
4157 tcg_gen_shri_i32(t0, t0, 2);
4158 tcg_gen_shri_i32(t1, t1, 1);
4159 tcg_gen_or_i32(dst, dst, t0);
4160 tcg_gen_or_i32(dst, dst, t1);
4161 tcg_temp_free_i32(t0);
4162 tcg_temp_free_i32(t1);
4163
4164 tcg_gen_movi_tl(cpu_so, 0);
4165 tcg_gen_movi_tl(cpu_ov, 0);
4166 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
4167}
4168
0cfe11ea 4169/* mfcr mfocrf */
99e300ef 4170static void gen_mfcr(DisasContext *ctx)
79aceca5 4171{
76a66253 4172 uint32_t crm, crn;
3b46e624 4173
76a66253
JM
4174 if (likely(ctx->opcode & 0x00100000)) {
4175 crm = CRM(ctx->opcode);
8dd640e4 4176 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 4177 crn = ctz32 (crm);
e1571908 4178 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
4179 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4180 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 4181 }
d9bce9d9 4182 } else {
651721b2
AJ
4183 TCGv_i32 t0 = tcg_temp_new_i32();
4184 tcg_gen_mov_i32(t0, cpu_crf[0]);
4185 tcg_gen_shli_i32(t0, t0, 4);
4186 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4187 tcg_gen_shli_i32(t0, t0, 4);
4188 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4189 tcg_gen_shli_i32(t0, t0, 4);
4190 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4191 tcg_gen_shli_i32(t0, t0, 4);
4192 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4193 tcg_gen_shli_i32(t0, t0, 4);
4194 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4195 tcg_gen_shli_i32(t0, t0, 4);
4196 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4197 tcg_gen_shli_i32(t0, t0, 4);
4198 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4199 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4200 tcg_temp_free_i32(t0);
d9bce9d9 4201 }
79aceca5
FB
4202}
4203
4204/* mfmsr */
99e300ef 4205static void gen_mfmsr(DisasContext *ctx)
79aceca5 4206{
9a64fbe4 4207#if defined(CONFIG_USER_ONLY)
e06fcd75 4208 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4209#else
76db3ba4 4210 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4211 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4212 return;
9a64fbe4 4213 }
6527f6ea 4214 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4215#endif
79aceca5
FB
4216}
4217
7b13448f 4218static void spr_noaccess(void *opaque, int gprn, int sprn)
3fc6c082 4219{
7b13448f 4220#if 0
3fc6c082
FB
4221 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4222 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4223#endif
3fc6c082
FB
4224}
4225#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4226
79aceca5 4227/* mfspr */
636aa200 4228static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4229{
45d827d2 4230 void (*read_cb)(void *opaque, int gprn, int sprn);
79aceca5
FB
4231 uint32_t sprn = SPR(ctx->opcode);
4232
3fc6c082 4233#if !defined(CONFIG_USER_ONLY)
76db3ba4 4234 if (ctx->mem_idx == 2)
be147d08 4235 read_cb = ctx->spr_cb[sprn].hea_read;
76db3ba4 4236 else if (ctx->mem_idx)
3fc6c082
FB
4237 read_cb = ctx->spr_cb[sprn].oea_read;
4238 else
9a64fbe4 4239#endif
3fc6c082 4240 read_cb = ctx->spr_cb[sprn].uea_read;
76a66253
JM
4241 if (likely(read_cb != NULL)) {
4242 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4243 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4244 } else {
4245 /* Privilege exception */
9fceefa7
JM
4246 /* This is a hack to avoid warnings when running Linux:
4247 * this OS breaks the PowerPC virtualisation model,
4248 * allowing userland application to read the PVR
4249 */
4250 if (sprn != SPR_PVR) {
c05541ee
AB
4251 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4252 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4253 printf("Trying to read privileged spr %d (0x%03x) at "
4254 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
f24e5695 4255 }
e06fcd75 4256 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4257 }
3fc6c082
FB
4258 } else {
4259 /* Not defined */
c05541ee
AB
4260 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4261 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4262 printf("Trying to read invalid spr %d (0x%03x) at "
4263 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4264 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4265 }
79aceca5
FB
4266}
4267
99e300ef 4268static void gen_mfspr(DisasContext *ctx)
79aceca5 4269{
3fc6c082 4270 gen_op_mfspr(ctx);
76a66253 4271}
3fc6c082
FB
4272
4273/* mftb */
99e300ef 4274static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4275{
4276 gen_op_mfspr(ctx);
79aceca5
FB
4277}
4278
0cfe11ea 4279/* mtcrf mtocrf*/
99e300ef 4280static void gen_mtcrf(DisasContext *ctx)
79aceca5 4281{
76a66253 4282 uint32_t crm, crn;
3b46e624 4283
76a66253 4284 crm = CRM(ctx->opcode);
8dd640e4 4285 if (likely((ctx->opcode & 0x00100000))) {
4286 if (crm && ((crm & (crm - 1)) == 0)) {
4287 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4288 crn = ctz32 (crm);
8dd640e4 4289 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4290 tcg_gen_shri_i32(temp, temp, crn * 4);
4291 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4292 tcg_temp_free_i32(temp);
4293 }
76a66253 4294 } else {
651721b2
AJ
4295 TCGv_i32 temp = tcg_temp_new_i32();
4296 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4297 for (crn = 0 ; crn < 8 ; crn++) {
4298 if (crm & (1 << crn)) {
4299 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4300 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4301 }
4302 }
a7812ae4 4303 tcg_temp_free_i32(temp);
76a66253 4304 }
79aceca5
FB
4305}
4306
4307/* mtmsr */
426613db 4308#if defined(TARGET_PPC64)
99e300ef 4309static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4310{
4311#if defined(CONFIG_USER_ONLY)
e06fcd75 4312 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4313#else
76db3ba4 4314 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4315 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4316 return;
4317 }
be147d08
JM
4318 if (ctx->opcode & 0x00010000) {
4319 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4320 TCGv t0 = tcg_temp_new();
4321 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4322 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4323 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4324 tcg_temp_free(t0);
be147d08 4325 } else {
056b05f8
JM
4326 /* XXX: we need to update nip before the store
4327 * if we enter power saving mode, we will exit the loop
4328 * directly from ppc_store_msr
4329 */
be147d08 4330 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4331 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4332 /* Must stop the translation as machine state (may have) changed */
4333 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4334 gen_stop_exception(ctx);
be147d08 4335 }
426613db
JM
4336#endif
4337}
4338#endif
4339
99e300ef 4340static void gen_mtmsr(DisasContext *ctx)
79aceca5 4341{
9a64fbe4 4342#if defined(CONFIG_USER_ONLY)
e06fcd75 4343 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4344#else
76db3ba4 4345 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4346 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4347 return;
9a64fbe4 4348 }
be147d08
JM
4349 if (ctx->opcode & 0x00010000) {
4350 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4351 TCGv t0 = tcg_temp_new();
4352 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4353 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4354 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4355 tcg_temp_free(t0);
be147d08 4356 } else {
8018dc63
AG
4357 TCGv msr = tcg_temp_new();
4358
056b05f8
JM
4359 /* XXX: we need to update nip before the store
4360 * if we enter power saving mode, we will exit the loop
4361 * directly from ppc_store_msr
4362 */
be147d08 4363 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4364#if defined(TARGET_PPC64)
8018dc63
AG
4365 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4366#else
4367 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4368#endif
e5f17ac6 4369 gen_helper_store_msr(cpu_env, msr);
be147d08 4370 /* Must stop the translation as machine state (may have) changed */
6527f6ea 4371 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4372 gen_stop_exception(ctx);
be147d08 4373 }
9a64fbe4 4374#endif
79aceca5
FB
4375}
4376
4377/* mtspr */
99e300ef 4378static void gen_mtspr(DisasContext *ctx)
79aceca5 4379{
45d827d2 4380 void (*write_cb)(void *opaque, int sprn, int gprn);
79aceca5
FB
4381 uint32_t sprn = SPR(ctx->opcode);
4382
3fc6c082 4383#if !defined(CONFIG_USER_ONLY)
76db3ba4 4384 if (ctx->mem_idx == 2)
be147d08 4385 write_cb = ctx->spr_cb[sprn].hea_write;
76db3ba4 4386 else if (ctx->mem_idx)
3fc6c082
FB
4387 write_cb = ctx->spr_cb[sprn].oea_write;
4388 else
9a64fbe4 4389#endif
3fc6c082 4390 write_cb = ctx->spr_cb[sprn].uea_write;
76a66253
JM
4391 if (likely(write_cb != NULL)) {
4392 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 4393 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
4394 } else {
4395 /* Privilege exception */
c05541ee
AB
4396 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4397 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4398 printf("Trying to write privileged spr %d (0x%03x) at "
4399 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4400 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 4401 }
3fc6c082
FB
4402 } else {
4403 /* Not defined */
c05541ee
AB
4404 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4405 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4406 printf("Trying to write invalid spr %d (0x%03x) at "
4407 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4408 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4409 }
79aceca5
FB
4410}
4411
4412/*** Cache management ***/
99e300ef 4413
54623277 4414/* dcbf */
99e300ef 4415static void gen_dcbf(DisasContext *ctx)
79aceca5 4416{
dac454af 4417 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
4418 TCGv t0;
4419 gen_set_access_type(ctx, ACCESS_CACHE);
4420 t0 = tcg_temp_new();
4421 gen_addr_reg_index(ctx, t0);
4422 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4423 tcg_temp_free(t0);
79aceca5
FB
4424}
4425
4426/* dcbi (Supervisor only) */
99e300ef 4427static void gen_dcbi(DisasContext *ctx)
79aceca5 4428{
a541f297 4429#if defined(CONFIG_USER_ONLY)
e06fcd75 4430 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 4431#else
b61f2753 4432 TCGv EA, val;
76db3ba4 4433 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4434 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4435 return;
9a64fbe4 4436 }
a7812ae4 4437 EA = tcg_temp_new();
76db3ba4
AJ
4438 gen_set_access_type(ctx, ACCESS_CACHE);
4439 gen_addr_reg_index(ctx, EA);
a7812ae4 4440 val = tcg_temp_new();
76a66253 4441 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
4442 gen_qemu_ld8u(ctx, val, EA);
4443 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
4444 tcg_temp_free(val);
4445 tcg_temp_free(EA);
a541f297 4446#endif
79aceca5
FB
4447}
4448
4449/* dcdst */
99e300ef 4450static void gen_dcbst(DisasContext *ctx)
79aceca5 4451{
76a66253 4452 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
4453 TCGv t0;
4454 gen_set_access_type(ctx, ACCESS_CACHE);
4455 t0 = tcg_temp_new();
4456 gen_addr_reg_index(ctx, t0);
4457 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4458 tcg_temp_free(t0);
79aceca5
FB
4459}
4460
4461/* dcbt */
99e300ef 4462static void gen_dcbt(DisasContext *ctx)
79aceca5 4463{
0db1b20e 4464 /* interpreted as no-op */
76a66253
JM
4465 /* XXX: specification say this is treated as a load by the MMU
4466 * but does not generate any exception
4467 */
79aceca5
FB
4468}
4469
4470/* dcbtst */
99e300ef 4471static void gen_dcbtst(DisasContext *ctx)
79aceca5 4472{
0db1b20e 4473 /* interpreted as no-op */
76a66253
JM
4474 /* XXX: specification say this is treated as a load by the MMU
4475 * but does not generate any exception
4476 */
79aceca5
FB
4477}
4478
4479/* dcbz */
99e300ef 4480static void gen_dcbz(DisasContext *ctx)
79aceca5 4481{
8e33944f
AG
4482 TCGv tcgv_addr;
4483 TCGv_i32 tcgv_is_dcbzl;
4484 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4485
76db3ba4 4486 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4487 /* NIP cannot be restored if the memory exception comes from an helper */
4488 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4489 tcgv_addr = tcg_temp_new();
4490 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4491
4492 gen_addr_reg_index(ctx, tcgv_addr);
4493 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4494
4495 tcg_temp_free(tcgv_addr);
4496 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4497}
4498
ae1c1a3d 4499/* dst / dstt */
99e300ef 4500static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4501{
4502 if (rA(ctx->opcode) == 0) {
4503 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4504 } else {
4505 /* interpreted as no-op */
4506 }
4507}
4508
4509/* dstst /dststt */
99e300ef 4510static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4511{
4512 if (rA(ctx->opcode) == 0) {
4513 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4514 } else {
4515 /* interpreted as no-op */
4516 }
4517
4518}
4519
4520/* dss / dssall */
99e300ef 4521static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4522{
4523 /* interpreted as no-op */
4524}
4525
79aceca5 4526/* icbi */
99e300ef 4527static void gen_icbi(DisasContext *ctx)
79aceca5 4528{
76db3ba4
AJ
4529 TCGv t0;
4530 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4531 /* NIP cannot be restored if the memory exception comes from an helper */
4532 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4533 t0 = tcg_temp_new();
4534 gen_addr_reg_index(ctx, t0);
2f5a189c 4535 gen_helper_icbi(cpu_env, t0);
37d269df 4536 tcg_temp_free(t0);
79aceca5
FB
4537}
4538
4539/* Optional: */
4540/* dcba */
99e300ef 4541static void gen_dcba(DisasContext *ctx)
79aceca5 4542{
0db1b20e
JM
4543 /* interpreted as no-op */
4544 /* XXX: specification say this is treated as a store by the MMU
4545 * but does not generate any exception
4546 */
79aceca5
FB
4547}
4548
4549/*** Segment register manipulation ***/
4550/* Supervisor only: */
99e300ef 4551
54623277 4552/* mfsr */
99e300ef 4553static void gen_mfsr(DisasContext *ctx)
79aceca5 4554{
9a64fbe4 4555#if defined(CONFIG_USER_ONLY)
e06fcd75 4556 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4557#else
74d37793 4558 TCGv t0;
76db3ba4 4559 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4560 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4561 return;
9a64fbe4 4562 }
74d37793 4563 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4564 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4565 tcg_temp_free(t0);
9a64fbe4 4566#endif
79aceca5
FB
4567}
4568
4569/* mfsrin */
99e300ef 4570static void gen_mfsrin(DisasContext *ctx)
79aceca5 4571{
9a64fbe4 4572#if defined(CONFIG_USER_ONLY)
e06fcd75 4573 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4574#else
74d37793 4575 TCGv t0;
76db3ba4 4576 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4577 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4578 return;
9a64fbe4 4579 }
74d37793
AJ
4580 t0 = tcg_temp_new();
4581 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4582 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4583 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4584 tcg_temp_free(t0);
9a64fbe4 4585#endif
79aceca5
FB
4586}
4587
4588/* mtsr */
99e300ef 4589static void gen_mtsr(DisasContext *ctx)
79aceca5 4590{
9a64fbe4 4591#if defined(CONFIG_USER_ONLY)
e06fcd75 4592 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4593#else
74d37793 4594 TCGv t0;
76db3ba4 4595 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4596 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4597 return;
9a64fbe4 4598 }
74d37793 4599 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4600 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4601 tcg_temp_free(t0);
9a64fbe4 4602#endif
79aceca5
FB
4603}
4604
4605/* mtsrin */
99e300ef 4606static void gen_mtsrin(DisasContext *ctx)
79aceca5 4607{
9a64fbe4 4608#if defined(CONFIG_USER_ONLY)
e06fcd75 4609 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4610#else
74d37793 4611 TCGv t0;
76db3ba4 4612 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4613 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4614 return;
9a64fbe4 4615 }
74d37793
AJ
4616 t0 = tcg_temp_new();
4617 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4618 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4619 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4620 tcg_temp_free(t0);
9a64fbe4 4621#endif
79aceca5
FB
4622}
4623
12de9a39
JM
4624#if defined(TARGET_PPC64)
4625/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4626
54623277 4627/* mfsr */
e8eaa2c0 4628static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4629{
4630#if defined(CONFIG_USER_ONLY)
e06fcd75 4631 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4632#else
74d37793 4633 TCGv t0;
76db3ba4 4634 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4635 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4636 return;
4637 }
74d37793 4638 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4639 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4640 tcg_temp_free(t0);
12de9a39
JM
4641#endif
4642}
4643
4644/* mfsrin */
e8eaa2c0 4645static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4646{
4647#if defined(CONFIG_USER_ONLY)
e06fcd75 4648 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4649#else
74d37793 4650 TCGv t0;
76db3ba4 4651 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4652 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4653 return;
4654 }
74d37793
AJ
4655 t0 = tcg_temp_new();
4656 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4657 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4658 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4659 tcg_temp_free(t0);
12de9a39
JM
4660#endif
4661}
4662
4663/* mtsr */
e8eaa2c0 4664static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4665{
4666#if defined(CONFIG_USER_ONLY)
e06fcd75 4667 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4668#else
74d37793 4669 TCGv t0;
76db3ba4 4670 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4671 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4672 return;
4673 }
74d37793 4674 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4675 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4676 tcg_temp_free(t0);
12de9a39
JM
4677#endif
4678}
4679
4680/* mtsrin */
e8eaa2c0 4681static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4682{
4683#if defined(CONFIG_USER_ONLY)
e06fcd75 4684 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4685#else
74d37793 4686 TCGv t0;
76db3ba4 4687 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4688 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4689 return;
4690 }
74d37793
AJ
4691 t0 = tcg_temp_new();
4692 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4693 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4694 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4695 tcg_temp_free(t0);
12de9a39
JM
4696#endif
4697}
f6b868fc
BS
4698
4699/* slbmte */
e8eaa2c0 4700static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4701{
4702#if defined(CONFIG_USER_ONLY)
4703 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4704#else
4705 if (unlikely(!ctx->mem_idx)) {
4706 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4707 return;
4708 }
c6c7cf05
BS
4709 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4710 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4711#endif
4712}
4713
efdef95f
DG
4714static void gen_slbmfee(DisasContext *ctx)
4715{
4716#if defined(CONFIG_USER_ONLY)
4717 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4718#else
4719 if (unlikely(!ctx->mem_idx)) {
4720 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4721 return;
4722 }
c6c7cf05 4723 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4724 cpu_gpr[rB(ctx->opcode)]);
4725#endif
4726}
4727
4728static void gen_slbmfev(DisasContext *ctx)
4729{
4730#if defined(CONFIG_USER_ONLY)
4731 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4732#else
4733 if (unlikely(!ctx->mem_idx)) {
4734 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4735 return;
4736 }
c6c7cf05 4737 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4738 cpu_gpr[rB(ctx->opcode)]);
4739#endif
4740}
12de9a39
JM
4741#endif /* defined(TARGET_PPC64) */
4742
79aceca5 4743/*** Lookaside buffer management ***/
76db3ba4 4744/* Optional & mem_idx only: */
99e300ef 4745
54623277 4746/* tlbia */
99e300ef 4747static void gen_tlbia(DisasContext *ctx)
79aceca5 4748{
9a64fbe4 4749#if defined(CONFIG_USER_ONLY)
e06fcd75 4750 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4751#else
76db3ba4 4752 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4753 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4754 return;
9a64fbe4 4755 }
c6c7cf05 4756 gen_helper_tlbia(cpu_env);
9a64fbe4 4757#endif
79aceca5
FB
4758}
4759
bf14b1ce 4760/* tlbiel */
99e300ef 4761static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4762{
4763#if defined(CONFIG_USER_ONLY)
4764 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4765#else
4766 if (unlikely(!ctx->mem_idx)) {
4767 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4768 return;
4769 }
c6c7cf05 4770 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4771#endif
4772}
4773
79aceca5 4774/* tlbie */
99e300ef 4775static void gen_tlbie(DisasContext *ctx)
79aceca5 4776{
9a64fbe4 4777#if defined(CONFIG_USER_ONLY)
e06fcd75 4778 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4779#else
76db3ba4 4780 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4781 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4782 return;
9a64fbe4 4783 }
9ca3f7f3 4784 if (NARROW_MODE(ctx)) {
74d37793
AJ
4785 TCGv t0 = tcg_temp_new();
4786 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4787 gen_helper_tlbie(cpu_env, t0);
74d37793 4788 tcg_temp_free(t0);
9ca3f7f3 4789 } else {
c6c7cf05 4790 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4791 }
9a64fbe4 4792#endif
79aceca5
FB
4793}
4794
4795/* tlbsync */
99e300ef 4796static void gen_tlbsync(DisasContext *ctx)
79aceca5 4797{
9a64fbe4 4798#if defined(CONFIG_USER_ONLY)
e06fcd75 4799 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4800#else
76db3ba4 4801 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4802 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4803 return;
9a64fbe4
FB
4804 }
4805 /* This has no effect: it should ensure that all previous
4806 * tlbie have completed
4807 */
e06fcd75 4808 gen_stop_exception(ctx);
9a64fbe4 4809#endif
79aceca5
FB
4810}
4811
426613db
JM
4812#if defined(TARGET_PPC64)
4813/* slbia */
99e300ef 4814static void gen_slbia(DisasContext *ctx)
426613db
JM
4815{
4816#if defined(CONFIG_USER_ONLY)
e06fcd75 4817 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4818#else
76db3ba4 4819 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4820 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4821 return;
4822 }
c6c7cf05 4823 gen_helper_slbia(cpu_env);
426613db
JM
4824#endif
4825}
4826
4827/* slbie */
99e300ef 4828static void gen_slbie(DisasContext *ctx)
426613db
JM
4829{
4830#if defined(CONFIG_USER_ONLY)
e06fcd75 4831 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4832#else
76db3ba4 4833 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4834 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4835 return;
4836 }
c6c7cf05 4837 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4838#endif
4839}
4840#endif
4841
79aceca5
FB
4842/*** External control ***/
4843/* Optional: */
99e300ef 4844
54623277 4845/* eciwx */
99e300ef 4846static void gen_eciwx(DisasContext *ctx)
79aceca5 4847{
76db3ba4 4848 TCGv t0;
fa407c03 4849 /* Should check EAR[E] ! */
76db3ba4
AJ
4850 gen_set_access_type(ctx, ACCESS_EXT);
4851 t0 = tcg_temp_new();
4852 gen_addr_reg_index(ctx, t0);
fa407c03 4853 gen_check_align(ctx, t0, 0x03);
76db3ba4 4854 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4855 tcg_temp_free(t0);
76a66253
JM
4856}
4857
4858/* ecowx */
99e300ef 4859static void gen_ecowx(DisasContext *ctx)
76a66253 4860{
76db3ba4 4861 TCGv t0;
fa407c03 4862 /* Should check EAR[E] ! */
76db3ba4
AJ
4863 gen_set_access_type(ctx, ACCESS_EXT);
4864 t0 = tcg_temp_new();
4865 gen_addr_reg_index(ctx, t0);
fa407c03 4866 gen_check_align(ctx, t0, 0x03);
76db3ba4 4867 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4868 tcg_temp_free(t0);
76a66253
JM
4869}
4870
4871/* PowerPC 601 specific instructions */
99e300ef 4872
54623277 4873/* abs - abs. */
99e300ef 4874static void gen_abs(DisasContext *ctx)
76a66253 4875{
22e0e173
AJ
4876 int l1 = gen_new_label();
4877 int l2 = gen_new_label();
4878 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4879 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4880 tcg_gen_br(l2);
4881 gen_set_label(l1);
4882 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4883 gen_set_label(l2);
76a66253 4884 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4885 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4886}
4887
4888/* abso - abso. */
99e300ef 4889static void gen_abso(DisasContext *ctx)
76a66253 4890{
22e0e173
AJ
4891 int l1 = gen_new_label();
4892 int l2 = gen_new_label();
4893 int l3 = gen_new_label();
4894 /* Start with XER OV disabled, the most likely case */
da91a00f 4895 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4896 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4897 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4898 tcg_gen_movi_tl(cpu_ov, 1);
4899 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4900 tcg_gen_br(l2);
4901 gen_set_label(l1);
4902 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4903 tcg_gen_br(l3);
4904 gen_set_label(l2);
4905 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4906 gen_set_label(l3);
76a66253 4907 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4908 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4909}
4910
4911/* clcs */
99e300ef 4912static void gen_clcs(DisasContext *ctx)
76a66253 4913{
22e0e173 4914 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4915 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4916 tcg_temp_free_i32(t0);
c7697e1f 4917 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
4918}
4919
4920/* div - div. */
99e300ef 4921static void gen_div(DisasContext *ctx)
76a66253 4922{
d15f74fb
BS
4923 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4924 cpu_gpr[rB(ctx->opcode)]);
76a66253 4925 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4926 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4927}
4928
4929/* divo - divo. */
99e300ef 4930static void gen_divo(DisasContext *ctx)
76a66253 4931{
d15f74fb
BS
4932 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4933 cpu_gpr[rB(ctx->opcode)]);
76a66253 4934 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4935 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4936}
4937
4938/* divs - divs. */
99e300ef 4939static void gen_divs(DisasContext *ctx)
76a66253 4940{
d15f74fb
BS
4941 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4942 cpu_gpr[rB(ctx->opcode)]);
76a66253 4943 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4944 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4945}
4946
4947/* divso - divso. */
99e300ef 4948static void gen_divso(DisasContext *ctx)
76a66253 4949{
d15f74fb
BS
4950 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4951 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 4952 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4953 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4954}
4955
4956/* doz - doz. */
99e300ef 4957static void gen_doz(DisasContext *ctx)
76a66253 4958{
22e0e173
AJ
4959 int l1 = gen_new_label();
4960 int l2 = gen_new_label();
4961 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4962 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4963 tcg_gen_br(l2);
4964 gen_set_label(l1);
4965 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4966 gen_set_label(l2);
76a66253 4967 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4968 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4969}
4970
4971/* dozo - dozo. */
99e300ef 4972static void gen_dozo(DisasContext *ctx)
76a66253 4973{
22e0e173
AJ
4974 int l1 = gen_new_label();
4975 int l2 = gen_new_label();
4976 TCGv t0 = tcg_temp_new();
4977 TCGv t1 = tcg_temp_new();
4978 TCGv t2 = tcg_temp_new();
4979 /* Start with XER OV disabled, the most likely case */
da91a00f 4980 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4981 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4982 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4983 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4984 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4985 tcg_gen_andc_tl(t1, t1, t2);
4986 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4987 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
4988 tcg_gen_movi_tl(cpu_ov, 1);
4989 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4990 tcg_gen_br(l2);
4991 gen_set_label(l1);
4992 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4993 gen_set_label(l2);
4994 tcg_temp_free(t0);
4995 tcg_temp_free(t1);
4996 tcg_temp_free(t2);
76a66253 4997 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4998 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4999}
5000
5001/* dozi */
99e300ef 5002static void gen_dozi(DisasContext *ctx)
76a66253 5003{
22e0e173
AJ
5004 target_long simm = SIMM(ctx->opcode);
5005 int l1 = gen_new_label();
5006 int l2 = gen_new_label();
5007 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5008 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5009 tcg_gen_br(l2);
5010 gen_set_label(l1);
5011 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5012 gen_set_label(l2);
5013 if (unlikely(Rc(ctx->opcode) != 0))
5014 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5015}
5016
76a66253 5017/* lscbx - lscbx. */
99e300ef 5018static void gen_lscbx(DisasContext *ctx)
76a66253 5019{
bdb4b689
AJ
5020 TCGv t0 = tcg_temp_new();
5021 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5022 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5023 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 5024
76db3ba4 5025 gen_addr_reg_index(ctx, t0);
76a66253 5026 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 5027 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 5028 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
5029 tcg_temp_free_i32(t1);
5030 tcg_temp_free_i32(t2);
5031 tcg_temp_free_i32(t3);
3d7b417e 5032 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 5033 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 5034 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
5035 gen_set_Rc0(ctx, t0);
5036 tcg_temp_free(t0);
76a66253
JM
5037}
5038
5039/* maskg - maskg. */
99e300ef 5040static void gen_maskg(DisasContext *ctx)
76a66253 5041{
22e0e173
AJ
5042 int l1 = gen_new_label();
5043 TCGv t0 = tcg_temp_new();
5044 TCGv t1 = tcg_temp_new();
5045 TCGv t2 = tcg_temp_new();
5046 TCGv t3 = tcg_temp_new();
5047 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5048 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5049 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5050 tcg_gen_addi_tl(t2, t0, 1);
5051 tcg_gen_shr_tl(t2, t3, t2);
5052 tcg_gen_shr_tl(t3, t3, t1);
5053 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5054 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5055 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5056 gen_set_label(l1);
5057 tcg_temp_free(t0);
5058 tcg_temp_free(t1);
5059 tcg_temp_free(t2);
5060 tcg_temp_free(t3);
76a66253 5061 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5062 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5063}
5064
5065/* maskir - maskir. */
99e300ef 5066static void gen_maskir(DisasContext *ctx)
76a66253 5067{
22e0e173
AJ
5068 TCGv t0 = tcg_temp_new();
5069 TCGv t1 = tcg_temp_new();
5070 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5071 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5072 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5073 tcg_temp_free(t0);
5074 tcg_temp_free(t1);
76a66253 5075 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5076 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5077}
5078
5079/* mul - mul. */
99e300ef 5080static void gen_mul(DisasContext *ctx)
76a66253 5081{
22e0e173
AJ
5082 TCGv_i64 t0 = tcg_temp_new_i64();
5083 TCGv_i64 t1 = tcg_temp_new_i64();
5084 TCGv t2 = tcg_temp_new();
5085 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5086 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5087 tcg_gen_mul_i64(t0, t0, t1);
5088 tcg_gen_trunc_i64_tl(t2, t0);
5089 gen_store_spr(SPR_MQ, t2);
5090 tcg_gen_shri_i64(t1, t0, 32);
5091 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5092 tcg_temp_free_i64(t0);
5093 tcg_temp_free_i64(t1);
5094 tcg_temp_free(t2);
76a66253 5095 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5096 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5097}
5098
5099/* mulo - mulo. */
99e300ef 5100static void gen_mulo(DisasContext *ctx)
76a66253 5101{
22e0e173
AJ
5102 int l1 = gen_new_label();
5103 TCGv_i64 t0 = tcg_temp_new_i64();
5104 TCGv_i64 t1 = tcg_temp_new_i64();
5105 TCGv t2 = tcg_temp_new();
5106 /* Start with XER OV disabled, the most likely case */
da91a00f 5107 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5108 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5109 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5110 tcg_gen_mul_i64(t0, t0, t1);
5111 tcg_gen_trunc_i64_tl(t2, t0);
5112 gen_store_spr(SPR_MQ, t2);
5113 tcg_gen_shri_i64(t1, t0, 32);
5114 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5115 tcg_gen_ext32s_i64(t1, t0);
5116 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
5117 tcg_gen_movi_tl(cpu_ov, 1);
5118 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5119 gen_set_label(l1);
5120 tcg_temp_free_i64(t0);
5121 tcg_temp_free_i64(t1);
5122 tcg_temp_free(t2);
76a66253 5123 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5124 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5125}
5126
5127/* nabs - nabs. */
99e300ef 5128static void gen_nabs(DisasContext *ctx)
76a66253 5129{
22e0e173
AJ
5130 int l1 = gen_new_label();
5131 int l2 = gen_new_label();
5132 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5133 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5134 tcg_gen_br(l2);
5135 gen_set_label(l1);
5136 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5137 gen_set_label(l2);
76a66253 5138 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5139 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5140}
5141
5142/* nabso - nabso. */
99e300ef 5143static void gen_nabso(DisasContext *ctx)
76a66253 5144{
22e0e173
AJ
5145 int l1 = gen_new_label();
5146 int l2 = gen_new_label();
5147 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5148 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5149 tcg_gen_br(l2);
5150 gen_set_label(l1);
5151 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5152 gen_set_label(l2);
5153 /* nabs never overflows */
da91a00f 5154 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 5155 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5156 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5157}
5158
5159/* rlmi - rlmi. */
99e300ef 5160static void gen_rlmi(DisasContext *ctx)
76a66253 5161{
7487953d
AJ
5162 uint32_t mb = MB(ctx->opcode);
5163 uint32_t me = ME(ctx->opcode);
5164 TCGv t0 = tcg_temp_new();
5165 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5166 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5167 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5168 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5169 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5170 tcg_temp_free(t0);
76a66253 5171 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5172 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5173}
5174
5175/* rrib - rrib. */
99e300ef 5176static void gen_rrib(DisasContext *ctx)
76a66253 5177{
7487953d
AJ
5178 TCGv t0 = tcg_temp_new();
5179 TCGv t1 = tcg_temp_new();
5180 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5181 tcg_gen_movi_tl(t1, 0x80000000);
5182 tcg_gen_shr_tl(t1, t1, t0);
5183 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5184 tcg_gen_and_tl(t0, t0, t1);
5185 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5186 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5187 tcg_temp_free(t0);
5188 tcg_temp_free(t1);
76a66253 5189 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5190 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5191}
5192
5193/* sle - sle. */
99e300ef 5194static void gen_sle(DisasContext *ctx)
76a66253 5195{
7487953d
AJ
5196 TCGv t0 = tcg_temp_new();
5197 TCGv t1 = tcg_temp_new();
5198 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5199 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5200 tcg_gen_subfi_tl(t1, 32, t1);
5201 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
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);
5205 tcg_temp_free(t0);
5206 tcg_temp_free(t1);
76a66253 5207 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5208 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5209}
5210
5211/* sleq - sleq. */
99e300ef 5212static void gen_sleq(DisasContext *ctx)
76a66253 5213{
7487953d
AJ
5214 TCGv t0 = tcg_temp_new();
5215 TCGv t1 = tcg_temp_new();
5216 TCGv t2 = tcg_temp_new();
5217 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5218 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5219 tcg_gen_shl_tl(t2, t2, t0);
5220 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5221 gen_load_spr(t1, SPR_MQ);
5222 gen_store_spr(SPR_MQ, t0);
5223 tcg_gen_and_tl(t0, t0, t2);
5224 tcg_gen_andc_tl(t1, t1, t2);
5225 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5226 tcg_temp_free(t0);
5227 tcg_temp_free(t1);
5228 tcg_temp_free(t2);
76a66253 5229 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5230 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5231}
5232
5233/* sliq - sliq. */
99e300ef 5234static void gen_sliq(DisasContext *ctx)
76a66253 5235{
7487953d
AJ
5236 int sh = SH(ctx->opcode);
5237 TCGv t0 = tcg_temp_new();
5238 TCGv t1 = tcg_temp_new();
5239 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5240 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5241 tcg_gen_or_tl(t1, t0, t1);
5242 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5243 gen_store_spr(SPR_MQ, t1);
5244 tcg_temp_free(t0);
5245 tcg_temp_free(t1);
76a66253 5246 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5247 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5248}
5249
5250/* slliq - slliq. */
99e300ef 5251static void gen_slliq(DisasContext *ctx)
76a66253 5252{
7487953d
AJ
5253 int sh = SH(ctx->opcode);
5254 TCGv t0 = tcg_temp_new();
5255 TCGv t1 = tcg_temp_new();
5256 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5257 gen_load_spr(t1, SPR_MQ);
5258 gen_store_spr(SPR_MQ, t0);
5259 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5260 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5261 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5262 tcg_temp_free(t0);
5263 tcg_temp_free(t1);
76a66253 5264 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5265 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5266}
5267
5268/* sllq - sllq. */
99e300ef 5269static void gen_sllq(DisasContext *ctx)
76a66253 5270{
7487953d
AJ
5271 int l1 = gen_new_label();
5272 int l2 = gen_new_label();
5273 TCGv t0 = tcg_temp_local_new();
5274 TCGv t1 = tcg_temp_local_new();
5275 TCGv t2 = tcg_temp_local_new();
5276 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5277 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5278 tcg_gen_shl_tl(t1, t1, t2);
5279 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5280 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5281 gen_load_spr(t0, SPR_MQ);
5282 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5283 tcg_gen_br(l2);
5284 gen_set_label(l1);
5285 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5286 gen_load_spr(t2, SPR_MQ);
5287 tcg_gen_andc_tl(t1, t2, t1);
5288 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5289 gen_set_label(l2);
5290 tcg_temp_free(t0);
5291 tcg_temp_free(t1);
5292 tcg_temp_free(t2);
76a66253 5293 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5294 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5295}
5296
5297/* slq - slq. */
99e300ef 5298static void gen_slq(DisasContext *ctx)
76a66253 5299{
7487953d
AJ
5300 int l1 = gen_new_label();
5301 TCGv t0 = tcg_temp_new();
5302 TCGv t1 = tcg_temp_new();
5303 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5304 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5305 tcg_gen_subfi_tl(t1, 32, t1);
5306 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5307 tcg_gen_or_tl(t1, t0, t1);
5308 gen_store_spr(SPR_MQ, t1);
5309 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5310 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5311 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5312 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5313 gen_set_label(l1);
5314 tcg_temp_free(t0);
5315 tcg_temp_free(t1);
76a66253 5316 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5317 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5318}
5319
d9bce9d9 5320/* sraiq - sraiq. */
99e300ef 5321static void gen_sraiq(DisasContext *ctx)
76a66253 5322{
7487953d
AJ
5323 int sh = SH(ctx->opcode);
5324 int l1 = gen_new_label();
5325 TCGv t0 = tcg_temp_new();
5326 TCGv t1 = tcg_temp_new();
5327 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5328 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5329 tcg_gen_or_tl(t0, t0, t1);
5330 gen_store_spr(SPR_MQ, t0);
da91a00f 5331 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5332 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5333 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5334 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5335 gen_set_label(l1);
5336 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5337 tcg_temp_free(t0);
5338 tcg_temp_free(t1);
76a66253 5339 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5340 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5341}
5342
5343/* sraq - sraq. */
99e300ef 5344static void gen_sraq(DisasContext *ctx)
76a66253 5345{
7487953d
AJ
5346 int l1 = gen_new_label();
5347 int l2 = gen_new_label();
5348 TCGv t0 = tcg_temp_new();
5349 TCGv t1 = tcg_temp_local_new();
5350 TCGv t2 = tcg_temp_local_new();
5351 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5352 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5353 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5354 tcg_gen_subfi_tl(t2, 32, t2);
5355 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5356 tcg_gen_or_tl(t0, t0, t2);
5357 gen_store_spr(SPR_MQ, t0);
5358 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5359 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5360 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5361 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5362 gen_set_label(l1);
5363 tcg_temp_free(t0);
5364 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5365 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5366 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5367 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5368 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5369 gen_set_label(l2);
5370 tcg_temp_free(t1);
5371 tcg_temp_free(t2);
76a66253 5372 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5373 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5374}
5375
5376/* sre - sre. */
99e300ef 5377static void gen_sre(DisasContext *ctx)
76a66253 5378{
7487953d
AJ
5379 TCGv t0 = tcg_temp_new();
5380 TCGv t1 = tcg_temp_new();
5381 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5382 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5383 tcg_gen_subfi_tl(t1, 32, t1);
5384 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5385 tcg_gen_or_tl(t1, t0, t1);
5386 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5387 gen_store_spr(SPR_MQ, t1);
5388 tcg_temp_free(t0);
5389 tcg_temp_free(t1);
76a66253 5390 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5391 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5392}
5393
5394/* srea - srea. */
99e300ef 5395static void gen_srea(DisasContext *ctx)
76a66253 5396{
7487953d
AJ
5397 TCGv t0 = tcg_temp_new();
5398 TCGv t1 = tcg_temp_new();
5399 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5400 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5401 gen_store_spr(SPR_MQ, t0);
5402 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5403 tcg_temp_free(t0);
5404 tcg_temp_free(t1);
76a66253 5405 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5406 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5407}
5408
5409/* sreq */
99e300ef 5410static void gen_sreq(DisasContext *ctx)
76a66253 5411{
7487953d
AJ
5412 TCGv t0 = tcg_temp_new();
5413 TCGv t1 = tcg_temp_new();
5414 TCGv t2 = tcg_temp_new();
5415 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5416 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5417 tcg_gen_shr_tl(t1, t1, t0);
5418 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5419 gen_load_spr(t2, SPR_MQ);
5420 gen_store_spr(SPR_MQ, t0);
5421 tcg_gen_and_tl(t0, t0, t1);
5422 tcg_gen_andc_tl(t2, t2, t1);
5423 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5424 tcg_temp_free(t0);
5425 tcg_temp_free(t1);
5426 tcg_temp_free(t2);
76a66253 5427 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5428 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5429}
5430
5431/* sriq */
99e300ef 5432static void gen_sriq(DisasContext *ctx)
76a66253 5433{
7487953d
AJ
5434 int sh = SH(ctx->opcode);
5435 TCGv t0 = tcg_temp_new();
5436 TCGv t1 = tcg_temp_new();
5437 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5438 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5439 tcg_gen_or_tl(t1, t0, t1);
5440 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5441 gen_store_spr(SPR_MQ, t1);
5442 tcg_temp_free(t0);
5443 tcg_temp_free(t1);
76a66253 5444 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5445 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5446}
5447
5448/* srliq */
99e300ef 5449static void gen_srliq(DisasContext *ctx)
76a66253 5450{
7487953d
AJ
5451 int sh = SH(ctx->opcode);
5452 TCGv t0 = tcg_temp_new();
5453 TCGv t1 = tcg_temp_new();
5454 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5455 gen_load_spr(t1, SPR_MQ);
5456 gen_store_spr(SPR_MQ, t0);
5457 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5458 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5459 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5460 tcg_temp_free(t0);
5461 tcg_temp_free(t1);
76a66253 5462 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5463 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5464}
5465
5466/* srlq */
99e300ef 5467static void gen_srlq(DisasContext *ctx)
76a66253 5468{
7487953d
AJ
5469 int l1 = gen_new_label();
5470 int l2 = gen_new_label();
5471 TCGv t0 = tcg_temp_local_new();
5472 TCGv t1 = tcg_temp_local_new();
5473 TCGv t2 = tcg_temp_local_new();
5474 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5475 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5476 tcg_gen_shr_tl(t2, t1, t2);
5477 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5478 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5479 gen_load_spr(t0, SPR_MQ);
5480 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5481 tcg_gen_br(l2);
5482 gen_set_label(l1);
5483 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5484 tcg_gen_and_tl(t0, t0, t2);
5485 gen_load_spr(t1, SPR_MQ);
5486 tcg_gen_andc_tl(t1, t1, t2);
5487 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5488 gen_set_label(l2);
5489 tcg_temp_free(t0);
5490 tcg_temp_free(t1);
5491 tcg_temp_free(t2);
76a66253 5492 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5493 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5494}
5495
5496/* srq */
99e300ef 5497static void gen_srq(DisasContext *ctx)
76a66253 5498{
7487953d
AJ
5499 int l1 = gen_new_label();
5500 TCGv t0 = tcg_temp_new();
5501 TCGv t1 = tcg_temp_new();
5502 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5503 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5504 tcg_gen_subfi_tl(t1, 32, t1);
5505 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5506 tcg_gen_or_tl(t1, t0, t1);
5507 gen_store_spr(SPR_MQ, t1);
5508 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5509 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5510 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5511 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5512 gen_set_label(l1);
5513 tcg_temp_free(t0);
5514 tcg_temp_free(t1);
76a66253 5515 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5516 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5517}
5518
5519/* PowerPC 602 specific instructions */
99e300ef 5520
54623277 5521/* dsa */
99e300ef 5522static void gen_dsa(DisasContext *ctx)
76a66253
JM
5523{
5524 /* XXX: TODO */
e06fcd75 5525 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5526}
5527
5528/* esa */
99e300ef 5529static void gen_esa(DisasContext *ctx)
76a66253
JM
5530{
5531 /* XXX: TODO */
e06fcd75 5532 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5533}
5534
5535/* mfrom */
99e300ef 5536static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5537{
5538#if defined(CONFIG_USER_ONLY)
e06fcd75 5539 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5540#else
76db3ba4 5541 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5542 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5543 return;
5544 }
cf02a65c 5545 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5546#endif
5547}
5548
5549/* 602 - 603 - G2 TLB management */
e8eaa2c0 5550
54623277 5551/* tlbld */
e8eaa2c0 5552static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5553{
5554#if defined(CONFIG_USER_ONLY)
e06fcd75 5555 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5556#else
76db3ba4 5557 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5558 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5559 return;
5560 }
c6c7cf05 5561 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5562#endif
5563}
5564
5565/* tlbli */
e8eaa2c0 5566static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5567{
5568#if defined(CONFIG_USER_ONLY)
e06fcd75 5569 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5570#else
76db3ba4 5571 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5572 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5573 return;
5574 }
c6c7cf05 5575 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5576#endif
5577}
5578
7dbe11ac 5579/* 74xx TLB management */
e8eaa2c0 5580
54623277 5581/* tlbld */
e8eaa2c0 5582static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5583{
5584#if defined(CONFIG_USER_ONLY)
e06fcd75 5585 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5586#else
76db3ba4 5587 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5588 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5589 return;
5590 }
c6c7cf05 5591 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5592#endif
5593}
5594
5595/* tlbli */
e8eaa2c0 5596static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5597{
5598#if defined(CONFIG_USER_ONLY)
e06fcd75 5599 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5600#else
76db3ba4 5601 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5602 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5603 return;
5604 }
c6c7cf05 5605 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5606#endif
5607}
5608
76a66253 5609/* POWER instructions not in PowerPC 601 */
99e300ef 5610
54623277 5611/* clf */
99e300ef 5612static void gen_clf(DisasContext *ctx)
76a66253
JM
5613{
5614 /* Cache line flush: implemented as no-op */
5615}
5616
5617/* cli */
99e300ef 5618static void gen_cli(DisasContext *ctx)
76a66253 5619{
7f75ffd3 5620 /* Cache line invalidate: privileged and treated as no-op */
76a66253 5621#if defined(CONFIG_USER_ONLY)
e06fcd75 5622 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5623#else
76db3ba4 5624 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5625 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5626 return;
5627 }
5628#endif
5629}
5630
5631/* dclst */
99e300ef 5632static void gen_dclst(DisasContext *ctx)
76a66253
JM
5633{
5634 /* Data cache line store: treated as no-op */
5635}
5636
99e300ef 5637static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5638{
5639#if defined(CONFIG_USER_ONLY)
e06fcd75 5640 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5641#else
74d37793
AJ
5642 int ra = rA(ctx->opcode);
5643 int rd = rD(ctx->opcode);
5644 TCGv t0;
76db3ba4 5645 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5646 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5647 return;
5648 }
74d37793 5649 t0 = tcg_temp_new();
76db3ba4 5650 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5651 tcg_gen_shri_tl(t0, t0, 28);
5652 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5653 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5654 tcg_temp_free(t0);
76a66253 5655 if (ra != 0 && ra != rd)
74d37793 5656 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5657#endif
5658}
5659
99e300ef 5660static void gen_rac(DisasContext *ctx)
76a66253
JM
5661{
5662#if defined(CONFIG_USER_ONLY)
e06fcd75 5663 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5664#else
22e0e173 5665 TCGv t0;
76db3ba4 5666 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5667 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5668 return;
5669 }
22e0e173 5670 t0 = tcg_temp_new();
76db3ba4 5671 gen_addr_reg_index(ctx, t0);
c6c7cf05 5672 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5673 tcg_temp_free(t0);
76a66253
JM
5674#endif
5675}
5676
99e300ef 5677static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5678{
5679#if defined(CONFIG_USER_ONLY)
e06fcd75 5680 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5681#else
76db3ba4 5682 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5683 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5684 return;
5685 }
e5f17ac6 5686 gen_helper_rfsvc(cpu_env);
e06fcd75 5687 gen_sync_exception(ctx);
76a66253
JM
5688#endif
5689}
5690
5691/* svc is not implemented for now */
5692
5693/* POWER2 specific instructions */
5694/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5695
5696/* lfq */
99e300ef 5697static void gen_lfq(DisasContext *ctx)
76a66253 5698{
01a4afeb 5699 int rd = rD(ctx->opcode);
76db3ba4
AJ
5700 TCGv t0;
5701 gen_set_access_type(ctx, ACCESS_FLOAT);
5702 t0 = tcg_temp_new();
5703 gen_addr_imm_index(ctx, t0, 0);
5704 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5705 gen_addr_add(ctx, t0, t0, 8);
5706 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5707 tcg_temp_free(t0);
76a66253
JM
5708}
5709
5710/* lfqu */
99e300ef 5711static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5712{
5713 int ra = rA(ctx->opcode);
01a4afeb 5714 int rd = rD(ctx->opcode);
76db3ba4
AJ
5715 TCGv t0, t1;
5716 gen_set_access_type(ctx, ACCESS_FLOAT);
5717 t0 = tcg_temp_new();
5718 t1 = tcg_temp_new();
5719 gen_addr_imm_index(ctx, t0, 0);
5720 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5721 gen_addr_add(ctx, t1, t0, 8);
5722 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5723 if (ra != 0)
01a4afeb
AJ
5724 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5725 tcg_temp_free(t0);
5726 tcg_temp_free(t1);
76a66253
JM
5727}
5728
5729/* lfqux */
99e300ef 5730static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5731{
5732 int ra = rA(ctx->opcode);
01a4afeb 5733 int rd = rD(ctx->opcode);
76db3ba4
AJ
5734 gen_set_access_type(ctx, ACCESS_FLOAT);
5735 TCGv t0, t1;
5736 t0 = tcg_temp_new();
5737 gen_addr_reg_index(ctx, t0);
5738 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5739 t1 = tcg_temp_new();
5740 gen_addr_add(ctx, t1, t0, 8);
5741 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5742 tcg_temp_free(t1);
76a66253 5743 if (ra != 0)
01a4afeb
AJ
5744 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5745 tcg_temp_free(t0);
76a66253
JM
5746}
5747
5748/* lfqx */
99e300ef 5749static void gen_lfqx(DisasContext *ctx)
76a66253 5750{
01a4afeb 5751 int rd = rD(ctx->opcode);
76db3ba4
AJ
5752 TCGv t0;
5753 gen_set_access_type(ctx, ACCESS_FLOAT);
5754 t0 = tcg_temp_new();
5755 gen_addr_reg_index(ctx, t0);
5756 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5757 gen_addr_add(ctx, t0, t0, 8);
5758 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5759 tcg_temp_free(t0);
76a66253
JM
5760}
5761
5762/* stfq */
99e300ef 5763static void gen_stfq(DisasContext *ctx)
76a66253 5764{
01a4afeb 5765 int rd = rD(ctx->opcode);
76db3ba4
AJ
5766 TCGv t0;
5767 gen_set_access_type(ctx, ACCESS_FLOAT);
5768 t0 = tcg_temp_new();
5769 gen_addr_imm_index(ctx, t0, 0);
5770 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5771 gen_addr_add(ctx, t0, t0, 8);
5772 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5773 tcg_temp_free(t0);
76a66253
JM
5774}
5775
5776/* stfqu */
99e300ef 5777static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5778{
5779 int ra = rA(ctx->opcode);
01a4afeb 5780 int rd = rD(ctx->opcode);
76db3ba4
AJ
5781 TCGv t0, t1;
5782 gen_set_access_type(ctx, ACCESS_FLOAT);
5783 t0 = tcg_temp_new();
5784 gen_addr_imm_index(ctx, t0, 0);
5785 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5786 t1 = tcg_temp_new();
5787 gen_addr_add(ctx, t1, t0, 8);
5788 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5789 tcg_temp_free(t1);
76a66253 5790 if (ra != 0)
01a4afeb
AJ
5791 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5792 tcg_temp_free(t0);
76a66253
JM
5793}
5794
5795/* stfqux */
99e300ef 5796static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5797{
5798 int ra = rA(ctx->opcode);
01a4afeb 5799 int rd = rD(ctx->opcode);
76db3ba4
AJ
5800 TCGv t0, t1;
5801 gen_set_access_type(ctx, ACCESS_FLOAT);
5802 t0 = tcg_temp_new();
5803 gen_addr_reg_index(ctx, t0);
5804 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5805 t1 = tcg_temp_new();
5806 gen_addr_add(ctx, t1, t0, 8);
5807 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5808 tcg_temp_free(t1);
76a66253 5809 if (ra != 0)
01a4afeb
AJ
5810 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5811 tcg_temp_free(t0);
76a66253
JM
5812}
5813
5814/* stfqx */
99e300ef 5815static void gen_stfqx(DisasContext *ctx)
76a66253 5816{
01a4afeb 5817 int rd = rD(ctx->opcode);
76db3ba4
AJ
5818 TCGv t0;
5819 gen_set_access_type(ctx, ACCESS_FLOAT);
5820 t0 = tcg_temp_new();
5821 gen_addr_reg_index(ctx, t0);
5822 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5823 gen_addr_add(ctx, t0, t0, 8);
5824 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5825 tcg_temp_free(t0);
76a66253
JM
5826}
5827
5828/* BookE specific instructions */
99e300ef 5829
54623277 5830/* XXX: not implemented on 440 ? */
99e300ef 5831static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5832{
5833 /* XXX: TODO */
e06fcd75 5834 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5835}
5836
2662a059 5837/* XXX: not implemented on 440 ? */
99e300ef 5838static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5839{
5840#if defined(CONFIG_USER_ONLY)
e06fcd75 5841 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5842#else
74d37793 5843 TCGv t0;
76db3ba4 5844 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5845 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5846 return;
5847 }
ec72e276 5848 t0 = tcg_temp_new();
76db3ba4 5849 gen_addr_reg_index(ctx, t0);
c6c7cf05 5850 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5851 tcg_temp_free(t0);
76a66253
JM
5852#endif
5853}
5854
5855/* All 405 MAC instructions are translated here */
636aa200
BS
5856static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5857 int ra, int rb, int rt, int Rc)
76a66253 5858{
182608d4
AJ
5859 TCGv t0, t1;
5860
a7812ae4
PB
5861 t0 = tcg_temp_local_new();
5862 t1 = tcg_temp_local_new();
182608d4 5863
76a66253
JM
5864 switch (opc3 & 0x0D) {
5865 case 0x05:
5866 /* macchw - macchw. - macchwo - macchwo. */
5867 /* macchws - macchws. - macchwso - macchwso. */
5868 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5869 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5870 /* mulchw - mulchw. */
182608d4
AJ
5871 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5872 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5873 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5874 break;
5875 case 0x04:
5876 /* macchwu - macchwu. - macchwuo - macchwuo. */
5877 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5878 /* mulchwu - mulchwu. */
182608d4
AJ
5879 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5880 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5881 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5882 break;
5883 case 0x01:
5884 /* machhw - machhw. - machhwo - machhwo. */
5885 /* machhws - machhws. - machhwso - machhwso. */
5886 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5887 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5888 /* mulhhw - mulhhw. */
182608d4
AJ
5889 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5890 tcg_gen_ext16s_tl(t0, t0);
5891 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5892 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5893 break;
5894 case 0x00:
5895 /* machhwu - machhwu. - machhwuo - machhwuo. */
5896 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5897 /* mulhhwu - mulhhwu. */
182608d4
AJ
5898 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5899 tcg_gen_ext16u_tl(t0, t0);
5900 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5901 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5902 break;
5903 case 0x0D:
5904 /* maclhw - maclhw. - maclhwo - maclhwo. */
5905 /* maclhws - maclhws. - maclhwso - maclhwso. */
5906 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5907 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5908 /* mullhw - mullhw. */
182608d4
AJ
5909 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5910 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5911 break;
5912 case 0x0C:
5913 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5914 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5915 /* mullhwu - mullhwu. */
182608d4
AJ
5916 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5917 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
5918 break;
5919 }
76a66253 5920 if (opc2 & 0x04) {
182608d4
AJ
5921 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5922 tcg_gen_mul_tl(t1, t0, t1);
5923 if (opc2 & 0x02) {
5924 /* nmultiply-and-accumulate (0x0E) */
5925 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5926 } else {
5927 /* multiply-and-accumulate (0x0C) */
5928 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5929 }
5930
5931 if (opc3 & 0x12) {
5932 /* Check overflow and/or saturate */
5933 int l1 = gen_new_label();
5934
5935 if (opc3 & 0x10) {
5936 /* Start with XER OV disabled, the most likely case */
da91a00f 5937 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
5938 }
5939 if (opc3 & 0x01) {
5940 /* Signed */
5941 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5942 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5943 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5944 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 5945 if (opc3 & 0x02) {
182608d4
AJ
5946 /* Saturate */
5947 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5948 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5949 }
5950 } else {
5951 /* Unsigned */
5952 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 5953 if (opc3 & 0x02) {
182608d4
AJ
5954 /* Saturate */
5955 tcg_gen_movi_tl(t0, UINT32_MAX);
5956 }
5957 }
5958 if (opc3 & 0x10) {
5959 /* Check overflow */
da91a00f
RH
5960 tcg_gen_movi_tl(cpu_ov, 1);
5961 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
5962 }
5963 gen_set_label(l1);
5964 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5965 }
5966 } else {
5967 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 5968 }
182608d4
AJ
5969 tcg_temp_free(t0);
5970 tcg_temp_free(t1);
76a66253
JM
5971 if (unlikely(Rc) != 0) {
5972 /* Update Rc0 */
182608d4 5973 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
5974 }
5975}
5976
a750fc0b 5977#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 5978static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
5979{ \
5980 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5981 rD(ctx->opcode), Rc(ctx->opcode)); \
5982}
5983
5984/* macchw - macchw. */
a750fc0b 5985GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 5986/* macchwo - macchwo. */
a750fc0b 5987GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 5988/* macchws - macchws. */
a750fc0b 5989GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 5990/* macchwso - macchwso. */
a750fc0b 5991GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 5992/* macchwsu - macchwsu. */
a750fc0b 5993GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 5994/* macchwsuo - macchwsuo. */
a750fc0b 5995GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 5996/* macchwu - macchwu. */
a750fc0b 5997GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 5998/* macchwuo - macchwuo. */
a750fc0b 5999GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 6000/* machhw - machhw. */
a750fc0b 6001GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 6002/* machhwo - machhwo. */
a750fc0b 6003GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 6004/* machhws - machhws. */
a750fc0b 6005GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 6006/* machhwso - machhwso. */
a750fc0b 6007GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 6008/* machhwsu - machhwsu. */
a750fc0b 6009GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 6010/* machhwsuo - machhwsuo. */
a750fc0b 6011GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 6012/* machhwu - machhwu. */
a750fc0b 6013GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 6014/* machhwuo - machhwuo. */
a750fc0b 6015GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 6016/* maclhw - maclhw. */
a750fc0b 6017GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 6018/* maclhwo - maclhwo. */
a750fc0b 6019GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 6020/* maclhws - maclhws. */
a750fc0b 6021GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 6022/* maclhwso - maclhwso. */
a750fc0b 6023GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 6024/* maclhwu - maclhwu. */
a750fc0b 6025GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 6026/* maclhwuo - maclhwuo. */
a750fc0b 6027GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 6028/* maclhwsu - maclhwsu. */
a750fc0b 6029GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 6030/* maclhwsuo - maclhwsuo. */
a750fc0b 6031GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 6032/* nmacchw - nmacchw. */
a750fc0b 6033GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 6034/* nmacchwo - nmacchwo. */
a750fc0b 6035GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 6036/* nmacchws - nmacchws. */
a750fc0b 6037GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 6038/* nmacchwso - nmacchwso. */
a750fc0b 6039GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 6040/* nmachhw - nmachhw. */
a750fc0b 6041GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 6042/* nmachhwo - nmachhwo. */
a750fc0b 6043GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 6044/* nmachhws - nmachhws. */
a750fc0b 6045GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 6046/* nmachhwso - nmachhwso. */
a750fc0b 6047GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 6048/* nmaclhw - nmaclhw. */
a750fc0b 6049GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 6050/* nmaclhwo - nmaclhwo. */
a750fc0b 6051GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 6052/* nmaclhws - nmaclhws. */
a750fc0b 6053GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 6054/* nmaclhwso - nmaclhwso. */
a750fc0b 6055GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
6056
6057/* mulchw - mulchw. */
a750fc0b 6058GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 6059/* mulchwu - mulchwu. */
a750fc0b 6060GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 6061/* mulhhw - mulhhw. */
a750fc0b 6062GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 6063/* mulhhwu - mulhhwu. */
a750fc0b 6064GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 6065/* mullhw - mullhw. */
a750fc0b 6066GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 6067/* mullhwu - mullhwu. */
a750fc0b 6068GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
6069
6070/* mfdcr */
99e300ef 6071static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
6072{
6073#if defined(CONFIG_USER_ONLY)
e06fcd75 6074 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6075#else
06dca6a7 6076 TCGv dcrn;
76db3ba4 6077 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6078 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6079 return;
6080 }
06dca6a7
AJ
6081 /* NIP cannot be restored if the memory exception comes from an helper */
6082 gen_update_nip(ctx, ctx->nip - 4);
6083 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6084 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 6085 tcg_temp_free(dcrn);
76a66253
JM
6086#endif
6087}
6088
6089/* mtdcr */
99e300ef 6090static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
6091{
6092#if defined(CONFIG_USER_ONLY)
e06fcd75 6093 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6094#else
06dca6a7 6095 TCGv dcrn;
76db3ba4 6096 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6097 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6098 return;
6099 }
06dca6a7
AJ
6100 /* NIP cannot be restored if the memory exception comes from an helper */
6101 gen_update_nip(ctx, ctx->nip - 4);
6102 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6103 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 6104 tcg_temp_free(dcrn);
a42bd6cc
JM
6105#endif
6106}
6107
6108/* mfdcrx */
2662a059 6109/* XXX: not implemented on 440 ? */
99e300ef 6110static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
6111{
6112#if defined(CONFIG_USER_ONLY)
e06fcd75 6113 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6114#else
76db3ba4 6115 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6116 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6117 return;
6118 }
06dca6a7
AJ
6119 /* NIP cannot be restored if the memory exception comes from an helper */
6120 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6121 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6122 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 6123 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
6124#endif
6125}
6126
6127/* mtdcrx */
2662a059 6128/* XXX: not implemented on 440 ? */
99e300ef 6129static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
6130{
6131#if defined(CONFIG_USER_ONLY)
e06fcd75 6132 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6133#else
76db3ba4 6134 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6135 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6136 return;
6137 }
06dca6a7
AJ
6138 /* NIP cannot be restored if the memory exception comes from an helper */
6139 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6140 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6141 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 6142 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
6143#endif
6144}
6145
a750fc0b 6146/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6147static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 6148{
06dca6a7
AJ
6149 /* NIP cannot be restored if the memory exception comes from an helper */
6150 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6151 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6152 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
6153 /* Note: Rc update flag set leads to undefined state of Rc0 */
6154}
6155
6156/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6157static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 6158{
06dca6a7
AJ
6159 /* NIP cannot be restored if the memory exception comes from an helper */
6160 gen_update_nip(ctx, ctx->nip - 4);
975e5463 6161 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 6162 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
6163 /* Note: Rc update flag set leads to undefined state of Rc0 */
6164}
6165
76a66253 6166/* dccci */
99e300ef 6167static void gen_dccci(DisasContext *ctx)
76a66253
JM
6168{
6169#if defined(CONFIG_USER_ONLY)
e06fcd75 6170 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6171#else
76db3ba4 6172 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6173 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6174 return;
6175 }
6176 /* interpreted as no-op */
6177#endif
6178}
6179
6180/* dcread */
99e300ef 6181static void gen_dcread(DisasContext *ctx)
76a66253
JM
6182{
6183#if defined(CONFIG_USER_ONLY)
e06fcd75 6184 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6185#else
b61f2753 6186 TCGv EA, val;
76db3ba4 6187 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6188 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6189 return;
6190 }
76db3ba4 6191 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 6192 EA = tcg_temp_new();
76db3ba4 6193 gen_addr_reg_index(ctx, EA);
a7812ae4 6194 val = tcg_temp_new();
76db3ba4 6195 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
6196 tcg_temp_free(val);
6197 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6198 tcg_temp_free(EA);
76a66253
JM
6199#endif
6200}
6201
6202/* icbt */
e8eaa2c0 6203static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6204{
6205 /* interpreted as no-op */
6206 /* XXX: specification say this is treated as a load by the MMU
6207 * but does not generate any exception
6208 */
6209}
6210
6211/* iccci */
99e300ef 6212static void gen_iccci(DisasContext *ctx)
76a66253
JM
6213{
6214#if defined(CONFIG_USER_ONLY)
e06fcd75 6215 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6216#else
76db3ba4 6217 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6218 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6219 return;
6220 }
6221 /* interpreted as no-op */
6222#endif
6223}
6224
6225/* icread */
99e300ef 6226static void gen_icread(DisasContext *ctx)
76a66253
JM
6227{
6228#if defined(CONFIG_USER_ONLY)
e06fcd75 6229 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6230#else
76db3ba4 6231 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6232 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6233 return;
6234 }
6235 /* interpreted as no-op */
6236#endif
6237}
6238
76db3ba4 6239/* rfci (mem_idx only) */
e8eaa2c0 6240static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
6241{
6242#if defined(CONFIG_USER_ONLY)
e06fcd75 6243 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6244#else
76db3ba4 6245 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6246 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6247 return;
6248 }
6249 /* Restore CPU state */
e5f17ac6 6250 gen_helper_40x_rfci(cpu_env);
e06fcd75 6251 gen_sync_exception(ctx);
a42bd6cc
JM
6252#endif
6253}
6254
99e300ef 6255static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6256{
6257#if defined(CONFIG_USER_ONLY)
e06fcd75 6258 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6259#else
76db3ba4 6260 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6261 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6262 return;
6263 }
6264 /* Restore CPU state */
e5f17ac6 6265 gen_helper_rfci(cpu_env);
e06fcd75 6266 gen_sync_exception(ctx);
a42bd6cc
JM
6267#endif
6268}
6269
6270/* BookE specific */
99e300ef 6271
54623277 6272/* XXX: not implemented on 440 ? */
99e300ef 6273static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6274{
6275#if defined(CONFIG_USER_ONLY)
e06fcd75 6276 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6277#else
76db3ba4 6278 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6279 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6280 return;
6281 }
6282 /* Restore CPU state */
e5f17ac6 6283 gen_helper_rfdi(cpu_env);
e06fcd75 6284 gen_sync_exception(ctx);
76a66253
JM
6285#endif
6286}
6287
2662a059 6288/* XXX: not implemented on 440 ? */
99e300ef 6289static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6290{
6291#if defined(CONFIG_USER_ONLY)
e06fcd75 6292 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6293#else
76db3ba4 6294 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6295 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6296 return;
6297 }
6298 /* Restore CPU state */
e5f17ac6 6299 gen_helper_rfmci(cpu_env);
e06fcd75 6300 gen_sync_exception(ctx);
a42bd6cc
JM
6301#endif
6302}
5eb7995e 6303
d9bce9d9 6304/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6305
54623277 6306/* tlbre */
e8eaa2c0 6307static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6308{
6309#if defined(CONFIG_USER_ONLY)
e06fcd75 6310 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6311#else
76db3ba4 6312 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6313 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6314 return;
6315 }
6316 switch (rB(ctx->opcode)) {
6317 case 0:
c6c7cf05
BS
6318 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6319 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6320 break;
6321 case 1:
c6c7cf05
BS
6322 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6323 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6324 break;
6325 default:
e06fcd75 6326 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6327 break;
9a64fbe4 6328 }
76a66253
JM
6329#endif
6330}
6331
d9bce9d9 6332/* tlbsx - tlbsx. */
e8eaa2c0 6333static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6334{
6335#if defined(CONFIG_USER_ONLY)
e06fcd75 6336 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6337#else
74d37793 6338 TCGv t0;
76db3ba4 6339 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6340 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6341 return;
6342 }
74d37793 6343 t0 = tcg_temp_new();
76db3ba4 6344 gen_addr_reg_index(ctx, t0);
c6c7cf05 6345 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6346 tcg_temp_free(t0);
6347 if (Rc(ctx->opcode)) {
6348 int l1 = gen_new_label();
da91a00f 6349 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6350 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6351 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6352 gen_set_label(l1);
6353 }
76a66253 6354#endif
79aceca5
FB
6355}
6356
76a66253 6357/* tlbwe */
e8eaa2c0 6358static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6359{
76a66253 6360#if defined(CONFIG_USER_ONLY)
e06fcd75 6361 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6362#else
76db3ba4 6363 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6364 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6365 return;
6366 }
6367 switch (rB(ctx->opcode)) {
6368 case 0:
c6c7cf05
BS
6369 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6370 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6371 break;
6372 case 1:
c6c7cf05
BS
6373 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6374 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6375 break;
6376 default:
e06fcd75 6377 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6378 break;
9a64fbe4 6379 }
76a66253
JM
6380#endif
6381}
6382
a4bb6c3e 6383/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6384
54623277 6385/* tlbre */
e8eaa2c0 6386static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6387{
6388#if defined(CONFIG_USER_ONLY)
e06fcd75 6389 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6390#else
76db3ba4 6391 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6392 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6393 return;
6394 }
6395 switch (rB(ctx->opcode)) {
6396 case 0:
5eb7995e 6397 case 1:
5eb7995e 6398 case 2:
74d37793
AJ
6399 {
6400 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6401 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6402 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6403 tcg_temp_free_i32(t0);
6404 }
5eb7995e
JM
6405 break;
6406 default:
e06fcd75 6407 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6408 break;
6409 }
6410#endif
6411}
6412
6413/* tlbsx - tlbsx. */
e8eaa2c0 6414static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6415{
6416#if defined(CONFIG_USER_ONLY)
e06fcd75 6417 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6418#else
74d37793 6419 TCGv t0;
76db3ba4 6420 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6421 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6422 return;
6423 }
74d37793 6424 t0 = tcg_temp_new();
76db3ba4 6425 gen_addr_reg_index(ctx, t0);
c6c7cf05 6426 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6427 tcg_temp_free(t0);
6428 if (Rc(ctx->opcode)) {
6429 int l1 = gen_new_label();
da91a00f 6430 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6431 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6432 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6433 gen_set_label(l1);
6434 }
5eb7995e
JM
6435#endif
6436}
6437
6438/* tlbwe */
e8eaa2c0 6439static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
6440{
6441#if defined(CONFIG_USER_ONLY)
e06fcd75 6442 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6443#else
76db3ba4 6444 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6445 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6446 return;
6447 }
6448 switch (rB(ctx->opcode)) {
6449 case 0:
5eb7995e 6450 case 1:
5eb7995e 6451 case 2:
74d37793
AJ
6452 {
6453 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6454 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6455 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
6456 tcg_temp_free_i32(t0);
6457 }
5eb7995e
JM
6458 break;
6459 default:
e06fcd75 6460 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6461 break;
6462 }
6463#endif
6464}
6465
01662f3e
AG
6466/* TLB management - PowerPC BookE 2.06 implementation */
6467
6468/* tlbre */
6469static void gen_tlbre_booke206(DisasContext *ctx)
6470{
6471#if defined(CONFIG_USER_ONLY)
6472 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6473#else
6474 if (unlikely(!ctx->mem_idx)) {
6475 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6476 return;
6477 }
6478
c6c7cf05 6479 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6480#endif
6481}
6482
6483/* tlbsx - tlbsx. */
6484static void gen_tlbsx_booke206(DisasContext *ctx)
6485{
6486#if defined(CONFIG_USER_ONLY)
6487 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6488#else
6489 TCGv t0;
6490 if (unlikely(!ctx->mem_idx)) {
6491 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6492 return;
6493 }
6494
6495 if (rA(ctx->opcode)) {
6496 t0 = tcg_temp_new();
6497 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6498 } else {
6499 t0 = tcg_const_tl(0);
6500 }
6501
6502 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6503 gen_helper_booke206_tlbsx(cpu_env, t0);
01662f3e
AG
6504#endif
6505}
6506
6507/* tlbwe */
6508static void gen_tlbwe_booke206(DisasContext *ctx)
6509{
6510#if defined(CONFIG_USER_ONLY)
6511 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6512#else
6513 if (unlikely(!ctx->mem_idx)) {
6514 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6515 return;
6516 }
3f162d11 6517 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6518 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6519#endif
6520}
6521
6522static void gen_tlbivax_booke206(DisasContext *ctx)
6523{
6524#if defined(CONFIG_USER_ONLY)
6525 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6526#else
6527 TCGv t0;
6528 if (unlikely(!ctx->mem_idx)) {
6529 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6530 return;
6531 }
6532
6533 t0 = tcg_temp_new();
6534 gen_addr_reg_index(ctx, t0);
6535
c6c7cf05 6536 gen_helper_booke206_tlbivax(cpu_env, t0);
01662f3e
AG
6537#endif
6538}
6539
6d3db821
AG
6540static void gen_tlbilx_booke206(DisasContext *ctx)
6541{
6542#if defined(CONFIG_USER_ONLY)
6543 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6544#else
6545 TCGv t0;
6546 if (unlikely(!ctx->mem_idx)) {
6547 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6548 return;
6549 }
6550
6551 t0 = tcg_temp_new();
6552 gen_addr_reg_index(ctx, t0);
6553
6554 switch((ctx->opcode >> 21) & 0x3) {
6555 case 0:
c6c7cf05 6556 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6557 break;
6558 case 1:
c6c7cf05 6559 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6560 break;
6561 case 3:
c6c7cf05 6562 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6563 break;
6564 default:
6565 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6566 break;
6567 }
6568
6569 tcg_temp_free(t0);
6570#endif
6571}
6572
01662f3e 6573
76a66253 6574/* wrtee */
99e300ef 6575static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6576{
6577#if defined(CONFIG_USER_ONLY)
e06fcd75 6578 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6579#else
6527f6ea 6580 TCGv t0;
76db3ba4 6581 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6582 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6583 return;
6584 }
6527f6ea
AJ
6585 t0 = tcg_temp_new();
6586 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6587 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6588 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6589 tcg_temp_free(t0);
dee96f6c
JM
6590 /* Stop translation to have a chance to raise an exception
6591 * if we just set msr_ee to 1
6592 */
e06fcd75 6593 gen_stop_exception(ctx);
76a66253
JM
6594#endif
6595}
6596
6597/* wrteei */
99e300ef 6598static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6599{
6600#if defined(CONFIG_USER_ONLY)
e06fcd75 6601 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6602#else
76db3ba4 6603 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6604 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6605 return;
6606 }
fbe73008 6607 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6608 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6609 /* Stop translation to have a chance to raise an exception */
e06fcd75 6610 gen_stop_exception(ctx);
6527f6ea 6611 } else {
1b6e5f99 6612 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6613 }
76a66253
JM
6614#endif
6615}
6616
08e46e54 6617/* PowerPC 440 specific instructions */
99e300ef 6618
54623277 6619/* dlmzb */
99e300ef 6620static void gen_dlmzb(DisasContext *ctx)
76a66253 6621{
ef0d51af 6622 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6623 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6624 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6625 tcg_temp_free_i32(t0);
76a66253
JM
6626}
6627
6628/* mbar replaces eieio on 440 */
99e300ef 6629static void gen_mbar(DisasContext *ctx)
76a66253
JM
6630{
6631 /* interpreted as no-op */
6632}
6633
6634/* msync replaces sync on 440 */
dcb2b9e1 6635static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6636{
6637 /* interpreted as no-op */
6638}
6639
6640/* icbt */
e8eaa2c0 6641static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6642{
6643 /* interpreted as no-op */
6644 /* XXX: specification say this is treated as a load by the MMU
6645 * but does not generate any exception
6646 */
79aceca5
FB
6647}
6648
9e0b5cb1
AG
6649/* Embedded.Processor Control */
6650
6651static void gen_msgclr(DisasContext *ctx)
6652{
6653#if defined(CONFIG_USER_ONLY)
6654 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6655#else
6656 if (unlikely(ctx->mem_idx == 0)) {
6657 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6658 return;
6659 }
6660
e5f17ac6 6661 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6662#endif
6663}
6664
d5d11a39
AG
6665static void gen_msgsnd(DisasContext *ctx)
6666{
6667#if defined(CONFIG_USER_ONLY)
6668 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6669#else
6670 if (unlikely(ctx->mem_idx == 0)) {
6671 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6672 return;
6673 }
6674
6675 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6676#endif
6677}
6678
a9d9eb8f
JM
6679/*** Altivec vector extension ***/
6680/* Altivec registers moves */
a9d9eb8f 6681
636aa200 6682static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6683{
e4704b3b 6684 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6685 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6686 return r;
6687}
6688
a9d9eb8f 6689#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6690static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6691{ \
fe1e5c53 6692 TCGv EA; \
a9d9eb8f 6693 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6694 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6695 return; \
6696 } \
76db3ba4 6697 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6698 EA = tcg_temp_new(); \
76db3ba4 6699 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6700 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6701 if (ctx->le_mode) { \
6702 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6703 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6704 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6705 } else { \
76db3ba4 6706 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6707 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6708 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6709 } \
6710 tcg_temp_free(EA); \
a9d9eb8f
JM
6711}
6712
6713#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6714static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6715{ \
fe1e5c53 6716 TCGv EA; \
a9d9eb8f 6717 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6718 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6719 return; \
6720 } \
76db3ba4 6721 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6722 EA = tcg_temp_new(); \
76db3ba4 6723 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6724 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6725 if (ctx->le_mode) { \
6726 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6727 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6728 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6729 } else { \
76db3ba4 6730 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6731 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6732 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6733 } \
6734 tcg_temp_free(EA); \
a9d9eb8f
JM
6735}
6736
cbfb6ae9 6737#define GEN_VR_LVE(name, opc2, opc3) \
99e300ef 6738static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6739 { \
6740 TCGv EA; \
6741 TCGv_ptr rs; \
6742 if (unlikely(!ctx->altivec_enabled)) { \
6743 gen_exception(ctx, POWERPC_EXCP_VPU); \
6744 return; \
6745 } \
6746 gen_set_access_type(ctx, ACCESS_INT); \
6747 EA = tcg_temp_new(); \
6748 gen_addr_reg_index(ctx, EA); \
6749 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6750 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6751 tcg_temp_free(EA); \
6752 tcg_temp_free_ptr(rs); \
6753 }
6754
6755#define GEN_VR_STVE(name, opc2, opc3) \
99e300ef 6756static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6757 { \
6758 TCGv EA; \
6759 TCGv_ptr rs; \
6760 if (unlikely(!ctx->altivec_enabled)) { \
6761 gen_exception(ctx, POWERPC_EXCP_VPU); \
6762 return; \
6763 } \
6764 gen_set_access_type(ctx, ACCESS_INT); \
6765 EA = tcg_temp_new(); \
6766 gen_addr_reg_index(ctx, EA); \
6767 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6768 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6769 tcg_temp_free(EA); \
6770 tcg_temp_free_ptr(rs); \
6771 }
6772
fe1e5c53 6773GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6774/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6775GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6776
cbfb6ae9
AJ
6777GEN_VR_LVE(bx, 0x07, 0x00);
6778GEN_VR_LVE(hx, 0x07, 0x01);
6779GEN_VR_LVE(wx, 0x07, 0x02);
6780
fe1e5c53 6781GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6782/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6783GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6784
cbfb6ae9
AJ
6785GEN_VR_STVE(bx, 0x07, 0x04);
6786GEN_VR_STVE(hx, 0x07, 0x05);
6787GEN_VR_STVE(wx, 0x07, 0x06);
6788
99e300ef 6789static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6790{
6791 TCGv_ptr rd;
6792 TCGv EA;
6793 if (unlikely(!ctx->altivec_enabled)) {
6794 gen_exception(ctx, POWERPC_EXCP_VPU);
6795 return;
6796 }
6797 EA = tcg_temp_new();
6798 gen_addr_reg_index(ctx, EA);
6799 rd = gen_avr_ptr(rD(ctx->opcode));
6800 gen_helper_lvsl(rd, EA);
6801 tcg_temp_free(EA);
6802 tcg_temp_free_ptr(rd);
6803}
6804
99e300ef 6805static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6806{
6807 TCGv_ptr rd;
6808 TCGv EA;
6809 if (unlikely(!ctx->altivec_enabled)) {
6810 gen_exception(ctx, POWERPC_EXCP_VPU);
6811 return;
6812 }
6813 EA = tcg_temp_new();
6814 gen_addr_reg_index(ctx, EA);
6815 rd = gen_avr_ptr(rD(ctx->opcode));
6816 gen_helper_lvsr(rd, EA);
6817 tcg_temp_free(EA);
6818 tcg_temp_free_ptr(rd);
6819}
6820
99e300ef 6821static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6822{
6823 TCGv_i32 t;
6824 if (unlikely(!ctx->altivec_enabled)) {
6825 gen_exception(ctx, POWERPC_EXCP_VPU);
6826 return;
6827 }
6828 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6829 t = tcg_temp_new_i32();
1328c2bf 6830 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6831 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6832 tcg_temp_free_i32(t);
785f451b
AJ
6833}
6834
99e300ef 6835static void gen_mtvscr(DisasContext *ctx)
785f451b 6836{
6e87b7c7 6837 TCGv_ptr p;
785f451b
AJ
6838 if (unlikely(!ctx->altivec_enabled)) {
6839 gen_exception(ctx, POWERPC_EXCP_VPU);
6840 return;
6841 }
6e87b7c7 6842 p = gen_avr_ptr(rD(ctx->opcode));
d15f74fb 6843 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6844 tcg_temp_free_ptr(p);
785f451b
AJ
6845}
6846
7a9b96cf
AJ
6847/* Logical operations */
6848#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6849static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6850{ \
6851 if (unlikely(!ctx->altivec_enabled)) { \
6852 gen_exception(ctx, POWERPC_EXCP_VPU); \
6853 return; \
6854 } \
6855 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6856 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6857}
6858
6859GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6860GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6861GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6862GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6863GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
111c5f54
TM
6864GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
6865GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
6866GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
7a9b96cf 6867
8e27dd6f 6868#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6869static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6870{ \
6871 TCGv_ptr ra, rb, rd; \
6872 if (unlikely(!ctx->altivec_enabled)) { \
6873 gen_exception(ctx, POWERPC_EXCP_VPU); \
6874 return; \
6875 } \
6876 ra = gen_avr_ptr(rA(ctx->opcode)); \
6877 rb = gen_avr_ptr(rB(ctx->opcode)); \
6878 rd = gen_avr_ptr(rD(ctx->opcode)); \
6879 gen_helper_##name (rd, ra, rb); \
6880 tcg_temp_free_ptr(ra); \
6881 tcg_temp_free_ptr(rb); \
6882 tcg_temp_free_ptr(rd); \
6883}
6884
d15f74fb
BS
6885#define GEN_VXFORM_ENV(name, opc2, opc3) \
6886static void glue(gen_, name)(DisasContext *ctx) \
6887{ \
6888 TCGv_ptr ra, rb, rd; \
6889 if (unlikely(!ctx->altivec_enabled)) { \
6890 gen_exception(ctx, POWERPC_EXCP_VPU); \
6891 return; \
6892 } \
6893 ra = gen_avr_ptr(rA(ctx->opcode)); \
6894 rb = gen_avr_ptr(rB(ctx->opcode)); \
6895 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6896 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6897 tcg_temp_free_ptr(ra); \
6898 tcg_temp_free_ptr(rb); \
6899 tcg_temp_free_ptr(rd); \
9b47bb49
TM
6900}
6901
6902#define GEN_VXFORM3(name, opc2, opc3) \
6903static void glue(gen_, name)(DisasContext *ctx) \
6904{ \
6905 TCGv_ptr ra, rb, rc, rd; \
6906 if (unlikely(!ctx->altivec_enabled)) { \
6907 gen_exception(ctx, POWERPC_EXCP_VPU); \
6908 return; \
6909 } \
6910 ra = gen_avr_ptr(rA(ctx->opcode)); \
6911 rb = gen_avr_ptr(rB(ctx->opcode)); \
6912 rc = gen_avr_ptr(rC(ctx->opcode)); \
6913 rd = gen_avr_ptr(rD(ctx->opcode)); \
6914 gen_helper_##name(rd, ra, rb, rc); \
6915 tcg_temp_free_ptr(ra); \
6916 tcg_temp_free_ptr(rb); \
6917 tcg_temp_free_ptr(rc); \
6918 tcg_temp_free_ptr(rd); \
d15f74fb
BS
6919}
6920
5dffff5a
TM
6921/*
6922 * Support for Altivec instruction pairs that use bit 31 (Rc) as
6923 * an opcode bit. In general, these pairs come from different
6924 * versions of the ISA, so we must also support a pair of flags for
6925 * each instruction.
6926 */
6927#define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
6928static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6929{ \
6930 if ((Rc(ctx->opcode) == 0) && \
6931 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
6932 gen_##name0(ctx); \
6933 } else if ((Rc(ctx->opcode) == 1) && \
6934 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
6935 gen_##name1(ctx); \
6936 } else { \
6937 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
6938 } \
6939}
6940
7872c51c
AJ
6941GEN_VXFORM(vaddubm, 0, 0);
6942GEN_VXFORM(vadduhm, 0, 1);
6943GEN_VXFORM(vadduwm, 0, 2);
56eabc75 6944GEN_VXFORM(vaddudm, 0, 3);
7872c51c
AJ
6945GEN_VXFORM(vsububm, 0, 16);
6946GEN_VXFORM(vsubuhm, 0, 17);
6947GEN_VXFORM(vsubuwm, 0, 18);
56eabc75 6948GEN_VXFORM(vsubudm, 0, 19);
e4039339
AJ
6949GEN_VXFORM(vmaxub, 1, 0);
6950GEN_VXFORM(vmaxuh, 1, 1);
6951GEN_VXFORM(vmaxuw, 1, 2);
8203e31b 6952GEN_VXFORM(vmaxud, 1, 3);
e4039339
AJ
6953GEN_VXFORM(vmaxsb, 1, 4);
6954GEN_VXFORM(vmaxsh, 1, 5);
6955GEN_VXFORM(vmaxsw, 1, 6);
8203e31b 6956GEN_VXFORM(vmaxsd, 1, 7);
e4039339
AJ
6957GEN_VXFORM(vminub, 1, 8);
6958GEN_VXFORM(vminuh, 1, 9);
6959GEN_VXFORM(vminuw, 1, 10);
8203e31b 6960GEN_VXFORM(vminud, 1, 11);
e4039339
AJ
6961GEN_VXFORM(vminsb, 1, 12);
6962GEN_VXFORM(vminsh, 1, 13);
6963GEN_VXFORM(vminsw, 1, 14);
8203e31b 6964GEN_VXFORM(vminsd, 1, 15);
fab3cbe9
AJ
6965GEN_VXFORM(vavgub, 1, 16);
6966GEN_VXFORM(vavguh, 1, 17);
6967GEN_VXFORM(vavguw, 1, 18);
6968GEN_VXFORM(vavgsb, 1, 20);
6969GEN_VXFORM(vavgsh, 1, 21);
6970GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
6971GEN_VXFORM(vmrghb, 6, 0);
6972GEN_VXFORM(vmrghh, 6, 1);
6973GEN_VXFORM(vmrghw, 6, 2);
6974GEN_VXFORM(vmrglb, 6, 4);
6975GEN_VXFORM(vmrglh, 6, 5);
6976GEN_VXFORM(vmrglw, 6, 6);
e0ffe77f
TM
6977
6978static void gen_vmrgew(DisasContext *ctx)
6979{
6980 TCGv_i64 tmp;
6981 int VT, VA, VB;
6982 if (unlikely(!ctx->altivec_enabled)) {
6983 gen_exception(ctx, POWERPC_EXCP_VPU);
6984 return;
6985 }
6986 VT = rD(ctx->opcode);
6987 VA = rA(ctx->opcode);
6988 VB = rB(ctx->opcode);
6989 tmp = tcg_temp_new_i64();
6990 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
6991 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
6992 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
6993 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
6994 tcg_temp_free_i64(tmp);
6995}
6996
6997static void gen_vmrgow(DisasContext *ctx)
6998{
6999 int VT, VA, VB;
7000 if (unlikely(!ctx->altivec_enabled)) {
7001 gen_exception(ctx, POWERPC_EXCP_VPU);
7002 return;
7003 }
7004 VT = rD(ctx->opcode);
7005 VA = rA(ctx->opcode);
7006 VB = rB(ctx->opcode);
7007
7008 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7009 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7010}
7011
2c277908
AJ
7012GEN_VXFORM(vmuloub, 4, 0);
7013GEN_VXFORM(vmulouh, 4, 1);
63be0936 7014GEN_VXFORM(vmulouw, 4, 2);
953f0f58
TM
7015GEN_VXFORM(vmuluwm, 4, 2);
7016GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7017 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
2c277908
AJ
7018GEN_VXFORM(vmulosb, 4, 4);
7019GEN_VXFORM(vmulosh, 4, 5);
63be0936 7020GEN_VXFORM(vmulosw, 4, 6);
2c277908
AJ
7021GEN_VXFORM(vmuleub, 4, 8);
7022GEN_VXFORM(vmuleuh, 4, 9);
63be0936 7023GEN_VXFORM(vmuleuw, 4, 10);
2c277908
AJ
7024GEN_VXFORM(vmulesb, 4, 12);
7025GEN_VXFORM(vmulesh, 4, 13);
63be0936 7026GEN_VXFORM(vmulesw, 4, 14);
d79f0809
AJ
7027GEN_VXFORM(vslb, 2, 4);
7028GEN_VXFORM(vslh, 2, 5);
7029GEN_VXFORM(vslw, 2, 6);
2fdf78e6 7030GEN_VXFORM(vsld, 2, 23);
07ef34c3
AJ
7031GEN_VXFORM(vsrb, 2, 8);
7032GEN_VXFORM(vsrh, 2, 9);
7033GEN_VXFORM(vsrw, 2, 10);
2fdf78e6 7034GEN_VXFORM(vsrd, 2, 27);
07ef34c3
AJ
7035GEN_VXFORM(vsrab, 2, 12);
7036GEN_VXFORM(vsrah, 2, 13);
7037GEN_VXFORM(vsraw, 2, 14);
2fdf78e6 7038GEN_VXFORM(vsrad, 2, 15);
7b239bec
AJ
7039GEN_VXFORM(vslo, 6, 16);
7040GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
7041GEN_VXFORM(vaddcuw, 0, 6);
7042GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
7043GEN_VXFORM_ENV(vaddubs, 0, 8);
7044GEN_VXFORM_ENV(vadduhs, 0, 9);
7045GEN_VXFORM_ENV(vadduws, 0, 10);
7046GEN_VXFORM_ENV(vaddsbs, 0, 12);
7047GEN_VXFORM_ENV(vaddshs, 0, 13);
7048GEN_VXFORM_ENV(vaddsws, 0, 14);
7049GEN_VXFORM_ENV(vsububs, 0, 24);
7050GEN_VXFORM_ENV(vsubuhs, 0, 25);
7051GEN_VXFORM_ENV(vsubuws, 0, 26);
7052GEN_VXFORM_ENV(vsubsbs, 0, 28);
7053GEN_VXFORM_ENV(vsubshs, 0, 29);
7054GEN_VXFORM_ENV(vsubsws, 0, 30);
b41da4eb
TM
7055GEN_VXFORM(vadduqm, 0, 4);
7056GEN_VXFORM(vaddcuq, 0, 5);
7057GEN_VXFORM3(vaddeuqm, 30, 0);
7058GEN_VXFORM3(vaddecuq, 30, 0);
7059GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7060 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7061GEN_VXFORM(vsubuqm, 0, 20);
7062GEN_VXFORM(vsubcuq, 0, 21);
7063GEN_VXFORM3(vsubeuqm, 31, 0);
7064GEN_VXFORM3(vsubecuq, 31, 0);
7065GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7066 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
5e1d0985
AJ
7067GEN_VXFORM(vrlb, 2, 0);
7068GEN_VXFORM(vrlh, 2, 1);
7069GEN_VXFORM(vrlw, 2, 2);
2fdf78e6 7070GEN_VXFORM(vrld, 2, 3);
d9430add
AJ
7071GEN_VXFORM(vsl, 2, 7);
7072GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
7073GEN_VXFORM_ENV(vpkuhum, 7, 0);
7074GEN_VXFORM_ENV(vpkuwum, 7, 1);
024215b2 7075GEN_VXFORM_ENV(vpkudum, 7, 17);
d15f74fb
BS
7076GEN_VXFORM_ENV(vpkuhus, 7, 2);
7077GEN_VXFORM_ENV(vpkuwus, 7, 3);
024215b2 7078GEN_VXFORM_ENV(vpkudus, 7, 19);
d15f74fb
BS
7079GEN_VXFORM_ENV(vpkshus, 7, 4);
7080GEN_VXFORM_ENV(vpkswus, 7, 5);
024215b2 7081GEN_VXFORM_ENV(vpksdus, 7, 21);
d15f74fb
BS
7082GEN_VXFORM_ENV(vpkshss, 7, 6);
7083GEN_VXFORM_ENV(vpkswss, 7, 7);
024215b2 7084GEN_VXFORM_ENV(vpksdss, 7, 23);
1dd9ffb9 7085GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
7086GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7087GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7088GEN_VXFORM_ENV(vsum4shs, 4, 25);
7089GEN_VXFORM_ENV(vsum2sws, 4, 26);
7090GEN_VXFORM_ENV(vsumsws, 4, 30);
7091GEN_VXFORM_ENV(vaddfp, 5, 0);
7092GEN_VXFORM_ENV(vsubfp, 5, 1);
7093GEN_VXFORM_ENV(vmaxfp, 5, 16);
7094GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 7095
0cbcd906 7096#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 7097static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
7098 { \
7099 TCGv_ptr ra, rb, rd; \
7100 if (unlikely(!ctx->altivec_enabled)) { \
7101 gen_exception(ctx, POWERPC_EXCP_VPU); \
7102 return; \
7103 } \
7104 ra = gen_avr_ptr(rA(ctx->opcode)); \
7105 rb = gen_avr_ptr(rB(ctx->opcode)); \
7106 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 7107 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
7108 tcg_temp_free_ptr(ra); \
7109 tcg_temp_free_ptr(rb); \
7110 tcg_temp_free_ptr(rd); \
7111 }
7112
7113#define GEN_VXRFORM(name, opc2, opc3) \
7114 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7115 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7116
a737d3eb
TM
7117/*
7118 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7119 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7120 * come from different versions of the ISA, so we must also support a
7121 * pair of flags for each instruction.
7122 */
7123#define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7124static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7125{ \
7126 if ((Rc(ctx->opcode) == 0) && \
7127 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7128 if (Rc21(ctx->opcode) == 0) { \
7129 gen_##name0(ctx); \
7130 } else { \
7131 gen_##name0##_(ctx); \
7132 } \
7133 } else if ((Rc(ctx->opcode) == 1) && \
7134 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7135 if (Rc21(ctx->opcode) == 0) { \
7136 gen_##name1(ctx); \
7137 } else { \
7138 gen_##name1##_(ctx); \
7139 } \
7140 } else { \
7141 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7142 } \
7143}
7144
1add6e23
AJ
7145GEN_VXRFORM(vcmpequb, 3, 0)
7146GEN_VXRFORM(vcmpequh, 3, 1)
7147GEN_VXRFORM(vcmpequw, 3, 2)
6f3dab41 7148GEN_VXRFORM(vcmpequd, 3, 3)
1add6e23
AJ
7149GEN_VXRFORM(vcmpgtsb, 3, 12)
7150GEN_VXRFORM(vcmpgtsh, 3, 13)
7151GEN_VXRFORM(vcmpgtsw, 3, 14)
6f3dab41 7152GEN_VXRFORM(vcmpgtsd, 3, 15)
1add6e23
AJ
7153GEN_VXRFORM(vcmpgtub, 3, 8)
7154GEN_VXRFORM(vcmpgtuh, 3, 9)
7155GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 7156GEN_VXRFORM(vcmpgtud, 3, 11)
819ca121
AJ
7157GEN_VXRFORM(vcmpeqfp, 3, 3)
7158GEN_VXRFORM(vcmpgefp, 3, 7)
7159GEN_VXRFORM(vcmpgtfp, 3, 11)
7160GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 7161
6f3dab41
TM
7162GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7163 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7164GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7165 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7166GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7167 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7168
c026766b 7169#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7170static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
7171 { \
7172 TCGv_ptr rd; \
7173 TCGv_i32 simm; \
7174 if (unlikely(!ctx->altivec_enabled)) { \
7175 gen_exception(ctx, POWERPC_EXCP_VPU); \
7176 return; \
7177 } \
7178 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7179 rd = gen_avr_ptr(rD(ctx->opcode)); \
7180 gen_helper_##name (rd, simm); \
7181 tcg_temp_free_i32(simm); \
7182 tcg_temp_free_ptr(rd); \
7183 }
7184
7185GEN_VXFORM_SIMM(vspltisb, 6, 12);
7186GEN_VXFORM_SIMM(vspltish, 6, 13);
7187GEN_VXFORM_SIMM(vspltisw, 6, 14);
7188
de5f2484 7189#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 7190static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
7191 { \
7192 TCGv_ptr rb, rd; \
7193 if (unlikely(!ctx->altivec_enabled)) { \
7194 gen_exception(ctx, POWERPC_EXCP_VPU); \
7195 return; \
7196 } \
7197 rb = gen_avr_ptr(rB(ctx->opcode)); \
7198 rd = gen_avr_ptr(rD(ctx->opcode)); \
7199 gen_helper_##name (rd, rb); \
7200 tcg_temp_free_ptr(rb); \
7201 tcg_temp_free_ptr(rd); \
7202 }
7203
d15f74fb
BS
7204#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7205static void glue(gen_, name)(DisasContext *ctx) \
7206 { \
7207 TCGv_ptr rb, rd; \
7208 \
7209 if (unlikely(!ctx->altivec_enabled)) { \
7210 gen_exception(ctx, POWERPC_EXCP_VPU); \
7211 return; \
7212 } \
7213 rb = gen_avr_ptr(rB(ctx->opcode)); \
7214 rd = gen_avr_ptr(rD(ctx->opcode)); \
7215 gen_helper_##name(cpu_env, rd, rb); \
7216 tcg_temp_free_ptr(rb); \
7217 tcg_temp_free_ptr(rd); \
7218 }
7219
6cf1c6e5
AJ
7220GEN_VXFORM_NOA(vupkhsb, 7, 8);
7221GEN_VXFORM_NOA(vupkhsh, 7, 9);
4430e076 7222GEN_VXFORM_NOA(vupkhsw, 7, 25);
6cf1c6e5
AJ
7223GEN_VXFORM_NOA(vupklsb, 7, 10);
7224GEN_VXFORM_NOA(vupklsh, 7, 11);
4430e076 7225GEN_VXFORM_NOA(vupklsw, 7, 27);
79f85c3a
AJ
7226GEN_VXFORM_NOA(vupkhpx, 7, 13);
7227GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
7228GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7229GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7230GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7231GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
7232GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
7233GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
7234GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
7235GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
79f85c3a 7236
21d21583 7237#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7238static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
7239 { \
7240 TCGv_ptr rd; \
7241 TCGv_i32 simm; \
7242 if (unlikely(!ctx->altivec_enabled)) { \
7243 gen_exception(ctx, POWERPC_EXCP_VPU); \
7244 return; \
7245 } \
7246 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7247 rd = gen_avr_ptr(rD(ctx->opcode)); \
7248 gen_helper_##name (rd, simm); \
7249 tcg_temp_free_i32(simm); \
7250 tcg_temp_free_ptr(rd); \
7251 }
7252
27a4edb3 7253#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 7254static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
7255 { \
7256 TCGv_ptr rb, rd; \
7257 TCGv_i32 uimm; \
7258 if (unlikely(!ctx->altivec_enabled)) { \
7259 gen_exception(ctx, POWERPC_EXCP_VPU); \
7260 return; \
7261 } \
7262 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7263 rb = gen_avr_ptr(rB(ctx->opcode)); \
7264 rd = gen_avr_ptr(rD(ctx->opcode)); \
7265 gen_helper_##name (rd, rb, uimm); \
7266 tcg_temp_free_i32(uimm); \
7267 tcg_temp_free_ptr(rb); \
7268 tcg_temp_free_ptr(rd); \
7269 }
7270
d15f74fb
BS
7271#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7272static void glue(gen_, name)(DisasContext *ctx) \
7273 { \
7274 TCGv_ptr rb, rd; \
7275 TCGv_i32 uimm; \
7276 \
7277 if (unlikely(!ctx->altivec_enabled)) { \
7278 gen_exception(ctx, POWERPC_EXCP_VPU); \
7279 return; \
7280 } \
7281 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7282 rb = gen_avr_ptr(rB(ctx->opcode)); \
7283 rd = gen_avr_ptr(rD(ctx->opcode)); \
7284 gen_helper_##name(cpu_env, rd, rb, uimm); \
7285 tcg_temp_free_i32(uimm); \
7286 tcg_temp_free_ptr(rb); \
7287 tcg_temp_free_ptr(rd); \
7288 }
7289
e4e6bee7
AJ
7290GEN_VXFORM_UIMM(vspltb, 6, 8);
7291GEN_VXFORM_UIMM(vsplth, 6, 9);
7292GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
7293GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7294GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7295GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7296GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 7297
99e300ef 7298static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
7299{
7300 TCGv_ptr ra, rb, rd;
fce5ecb7 7301 TCGv_i32 sh;
cd633b10
AJ
7302 if (unlikely(!ctx->altivec_enabled)) {
7303 gen_exception(ctx, POWERPC_EXCP_VPU);
7304 return;
7305 }
7306 ra = gen_avr_ptr(rA(ctx->opcode));
7307 rb = gen_avr_ptr(rB(ctx->opcode));
7308 rd = gen_avr_ptr(rD(ctx->opcode));
7309 sh = tcg_const_i32(VSH(ctx->opcode));
7310 gen_helper_vsldoi (rd, ra, rb, sh);
7311 tcg_temp_free_ptr(ra);
7312 tcg_temp_free_ptr(rb);
7313 tcg_temp_free_ptr(rd);
fce5ecb7 7314 tcg_temp_free_i32(sh);
cd633b10
AJ
7315}
7316
707cec33 7317#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 7318static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
7319 { \
7320 TCGv_ptr ra, rb, rc, rd; \
7321 if (unlikely(!ctx->altivec_enabled)) { \
7322 gen_exception(ctx, POWERPC_EXCP_VPU); \
7323 return; \
7324 } \
7325 ra = gen_avr_ptr(rA(ctx->opcode)); \
7326 rb = gen_avr_ptr(rB(ctx->opcode)); \
7327 rc = gen_avr_ptr(rC(ctx->opcode)); \
7328 rd = gen_avr_ptr(rD(ctx->opcode)); \
7329 if (Rc(ctx->opcode)) { \
d15f74fb 7330 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 7331 } else { \
d15f74fb 7332 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
7333 } \
7334 tcg_temp_free_ptr(ra); \
7335 tcg_temp_free_ptr(rb); \
7336 tcg_temp_free_ptr(rc); \
7337 tcg_temp_free_ptr(rd); \
7338 }
7339
b161ae27
AJ
7340GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7341
99e300ef 7342static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
7343{
7344 TCGv_ptr ra, rb, rc, rd;
7345 if (unlikely(!ctx->altivec_enabled)) {
7346 gen_exception(ctx, POWERPC_EXCP_VPU);
7347 return;
7348 }
7349 ra = gen_avr_ptr(rA(ctx->opcode));
7350 rb = gen_avr_ptr(rB(ctx->opcode));
7351 rc = gen_avr_ptr(rC(ctx->opcode));
7352 rd = gen_avr_ptr(rD(ctx->opcode));
7353 gen_helper_vmladduhm(rd, ra, rb, rc);
7354 tcg_temp_free_ptr(ra);
7355 tcg_temp_free_ptr(rb);
7356 tcg_temp_free_ptr(rc);
7357 tcg_temp_free_ptr(rd);
7358}
7359
b04ae981 7360GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7361GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7362GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7363GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7364GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7365
f293f04a
TM
7366GEN_VXFORM_NOA(vclzb, 1, 28)
7367GEN_VXFORM_NOA(vclzh, 1, 29)
7368GEN_VXFORM_NOA(vclzw, 1, 30)
7369GEN_VXFORM_NOA(vclzd, 1, 31)
e13500b3
TM
7370GEN_VXFORM_NOA(vpopcntb, 1, 28)
7371GEN_VXFORM_NOA(vpopcnth, 1, 29)
7372GEN_VXFORM_NOA(vpopcntw, 1, 30)
7373GEN_VXFORM_NOA(vpopcntd, 1, 31)
7374GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7375 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7376GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7377 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7378GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7379 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7380GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7381 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
4d82038e 7382GEN_VXFORM(vbpermq, 6, 21);
f1064f61 7383GEN_VXFORM_NOA(vgbbd, 6, 20);
b8476fc7
TM
7384GEN_VXFORM(vpmsumb, 4, 16)
7385GEN_VXFORM(vpmsumh, 4, 17)
7386GEN_VXFORM(vpmsumw, 4, 18)
7387GEN_VXFORM(vpmsumd, 4, 19)
e13500b3 7388
e8f7b27b
TM
7389#define GEN_BCD(op) \
7390static void gen_##op(DisasContext *ctx) \
7391{ \
7392 TCGv_ptr ra, rb, rd; \
7393 TCGv_i32 ps; \
7394 \
7395 if (unlikely(!ctx->altivec_enabled)) { \
7396 gen_exception(ctx, POWERPC_EXCP_VPU); \
7397 return; \
7398 } \
7399 \
7400 ra = gen_avr_ptr(rA(ctx->opcode)); \
7401 rb = gen_avr_ptr(rB(ctx->opcode)); \
7402 rd = gen_avr_ptr(rD(ctx->opcode)); \
7403 \
7404 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7405 \
7406 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7407 \
7408 tcg_temp_free_ptr(ra); \
7409 tcg_temp_free_ptr(rb); \
7410 tcg_temp_free_ptr(rd); \
7411 tcg_temp_free_i32(ps); \
7412}
7413
7414GEN_BCD(bcdadd)
7415GEN_BCD(bcdsub)
7416
7417GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7418 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7419GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7420 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7421GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7422 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7423GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7424 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7425
557d52fa
TM
7426static void gen_vsbox(DisasContext *ctx)
7427{
7428 TCGv_ptr ra, rd;
7429 if (unlikely(!ctx->altivec_enabled)) {
7430 gen_exception(ctx, POWERPC_EXCP_VPU);
7431 return;
7432 }
7433 ra = gen_avr_ptr(rA(ctx->opcode));
7434 rd = gen_avr_ptr(rD(ctx->opcode));
7435 gen_helper_vsbox(rd, ra);
7436 tcg_temp_free_ptr(ra);
7437 tcg_temp_free_ptr(rd);
7438}
7439
7440GEN_VXFORM(vcipher, 4, 20)
7441GEN_VXFORM(vcipherlast, 4, 20)
7442GEN_VXFORM(vncipher, 4, 21)
7443GEN_VXFORM(vncipherlast, 4, 21)
7444
7445GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7446 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7447GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7448 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7449
57354f8f
TM
7450#define VSHASIGMA(op) \
7451static void gen_##op(DisasContext *ctx) \
7452{ \
7453 TCGv_ptr ra, rd; \
7454 TCGv_i32 st_six; \
7455 if (unlikely(!ctx->altivec_enabled)) { \
7456 gen_exception(ctx, POWERPC_EXCP_VPU); \
7457 return; \
7458 } \
7459 ra = gen_avr_ptr(rA(ctx->opcode)); \
7460 rd = gen_avr_ptr(rD(ctx->opcode)); \
7461 st_six = tcg_const_i32(rB(ctx->opcode)); \
7462 gen_helper_##op(rd, ra, st_six); \
7463 tcg_temp_free_ptr(ra); \
7464 tcg_temp_free_ptr(rd); \
7465 tcg_temp_free_i32(st_six); \
7466}
7467
7468VSHASIGMA(vshasigmaw)
7469VSHASIGMA(vshasigmad)
7470
ac174549
TM
7471GEN_VXFORM3(vpermxor, 22, 0xFF)
7472GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7473 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7474
472b24ce
TM
7475/*** VSX extension ***/
7476
7477static inline TCGv_i64 cpu_vsrh(int n)
7478{
7479 if (n < 32) {
7480 return cpu_fpr[n];
7481 } else {
7482 return cpu_avrh[n-32];
7483 }
7484}
7485
7486static inline TCGv_i64 cpu_vsrl(int n)
7487{
7488 if (n < 32) {
7489 return cpu_vsr[n];
7490 } else {
7491 return cpu_avrl[n-32];
7492 }
7493}
7494
e072fe79
TM
7495#define VSX_LOAD_SCALAR(name, operation) \
7496static void gen_##name(DisasContext *ctx) \
7497{ \
7498 TCGv EA; \
7499 if (unlikely(!ctx->vsx_enabled)) { \
7500 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7501 return; \
7502 } \
7503 gen_set_access_type(ctx, ACCESS_INT); \
7504 EA = tcg_temp_new(); \
7505 gen_addr_reg_index(ctx, EA); \
7506 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7507 /* NOTE: cpu_vsrl is undefined */ \
7508 tcg_temp_free(EA); \
7509}
7510
7511VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7512VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7513VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7514VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7515
304af367
TM
7516static void gen_lxvd2x(DisasContext *ctx)
7517{
7518 TCGv EA;
7519 if (unlikely(!ctx->vsx_enabled)) {
7520 gen_exception(ctx, POWERPC_EXCP_VSXU);
7521 return;
7522 }
7523 gen_set_access_type(ctx, ACCESS_INT);
7524 EA = tcg_temp_new();
7525 gen_addr_reg_index(ctx, EA);
7526 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7527 tcg_gen_addi_tl(EA, EA, 8);
7528 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7529 tcg_temp_free(EA);
7530}
7531
ca03b467
TM
7532static void gen_lxvdsx(DisasContext *ctx)
7533{
7534 TCGv EA;
7535 if (unlikely(!ctx->vsx_enabled)) {
7536 gen_exception(ctx, POWERPC_EXCP_VSXU);
7537 return;
7538 }
7539 gen_set_access_type(ctx, ACCESS_INT);
7540 EA = tcg_temp_new();
7541 gen_addr_reg_index(ctx, EA);
7542 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7543 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7544 tcg_temp_free(EA);
7545}
7546
897e61d1
TM
7547static void gen_lxvw4x(DisasContext *ctx)
7548{
f976b09e
AG
7549 TCGv EA;
7550 TCGv_i64 tmp;
897e61d1
TM
7551 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7552 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7553 if (unlikely(!ctx->vsx_enabled)) {
7554 gen_exception(ctx, POWERPC_EXCP_VSXU);
7555 return;
7556 }
7557 gen_set_access_type(ctx, ACCESS_INT);
7558 EA = tcg_temp_new();
f976b09e
AG
7559 tmp = tcg_temp_new_i64();
7560
897e61d1 7561 gen_addr_reg_index(ctx, EA);
f976b09e 7562 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7563 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7564 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7565 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7566
7567 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7568 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7569 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7570 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7571 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7572
7573 tcg_temp_free(EA);
f976b09e 7574 tcg_temp_free_i64(tmp);
897e61d1
TM
7575}
7576
f026da78
TM
7577#define VSX_STORE_SCALAR(name, operation) \
7578static void gen_##name(DisasContext *ctx) \
7579{ \
7580 TCGv EA; \
7581 if (unlikely(!ctx->vsx_enabled)) { \
7582 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7583 return; \
7584 } \
7585 gen_set_access_type(ctx, ACCESS_INT); \
7586 EA = tcg_temp_new(); \
7587 gen_addr_reg_index(ctx, EA); \
7588 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7589 tcg_temp_free(EA); \
9231ba9e
TM
7590}
7591
f026da78 7592VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7593VSX_STORE_SCALAR(stxsiwx, st32_i64)
7594VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7595
fbed2478
TM
7596static void gen_stxvd2x(DisasContext *ctx)
7597{
7598 TCGv EA;
7599 if (unlikely(!ctx->vsx_enabled)) {
7600 gen_exception(ctx, POWERPC_EXCP_VSXU);
7601 return;
7602 }
7603 gen_set_access_type(ctx, ACCESS_INT);
7604 EA = tcg_temp_new();
7605 gen_addr_reg_index(ctx, EA);
7606 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7607 tcg_gen_addi_tl(EA, EA, 8);
7608 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7609 tcg_temp_free(EA);
7610}
7611
86e61ce3
TM
7612static void gen_stxvw4x(DisasContext *ctx)
7613{
f976b09e
AG
7614 TCGv_i64 tmp;
7615 TCGv EA;
86e61ce3
TM
7616 if (unlikely(!ctx->vsx_enabled)) {
7617 gen_exception(ctx, POWERPC_EXCP_VSXU);
7618 return;
7619 }
7620 gen_set_access_type(ctx, ACCESS_INT);
7621 EA = tcg_temp_new();
7622 gen_addr_reg_index(ctx, EA);
f976b09e 7623 tmp = tcg_temp_new_i64();
86e61ce3
TM
7624
7625 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7626 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7627 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7628 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7629
7630 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7631 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7632 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7633 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7634 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7635
7636 tcg_temp_free(EA);
f976b09e 7637 tcg_temp_free_i64(tmp);
86e61ce3
TM
7638}
7639
f5c0f7f9
TM
7640#define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7641static void gen_##name(DisasContext *ctx) \
7642{ \
7643 if (xS(ctx->opcode) < 32) { \
7644 if (unlikely(!ctx->fpu_enabled)) { \
7645 gen_exception(ctx, POWERPC_EXCP_FPU); \
7646 return; \
7647 } \
7648 } else { \
7649 if (unlikely(!ctx->altivec_enabled)) { \
7650 gen_exception(ctx, POWERPC_EXCP_VPU); \
7651 return; \
7652 } \
7653 } \
7654 TCGv_i64 tmp = tcg_temp_new_i64(); \
7655 tcg_gen_##tcgop1(tmp, source); \
7656 tcg_gen_##tcgop2(target, tmp); \
7657 tcg_temp_free_i64(tmp); \
7658}
7659
7660
7661MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7662 cpu_vsrh(xS(ctx->opcode)))
7663MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7664 cpu_gpr[rA(ctx->opcode)])
7665MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7666 cpu_gpr[rA(ctx->opcode)])
7667
7668#if defined(TARGET_PPC64)
7669#define MV_VSRD(name, target, source) \
7670static void gen_##name(DisasContext *ctx) \
7671{ \
7672 if (xS(ctx->opcode) < 32) { \
7673 if (unlikely(!ctx->fpu_enabled)) { \
7674 gen_exception(ctx, POWERPC_EXCP_FPU); \
7675 return; \
7676 } \
7677 } else { \
7678 if (unlikely(!ctx->altivec_enabled)) { \
7679 gen_exception(ctx, POWERPC_EXCP_VPU); \
7680 return; \
7681 } \
7682 } \
7683 tcg_gen_mov_i64(target, source); \
7684}
7685
7686MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7687MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7688
7689#endif
7690
cd73f2c9
TM
7691static void gen_xxpermdi(DisasContext *ctx)
7692{
7693 if (unlikely(!ctx->vsx_enabled)) {
7694 gen_exception(ctx, POWERPC_EXCP_VSXU);
7695 return;
7696 }
7697
f5bc1bfa
TM
7698 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7699 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7700 TCGv_i64 xh, xl;
7701
7702 xh = tcg_temp_new_i64();
7703 xl = tcg_temp_new_i64();
7704
7705 if ((DM(ctx->opcode) & 2) == 0) {
7706 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7707 } else {
7708 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7709 }
7710 if ((DM(ctx->opcode) & 1) == 0) {
7711 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7712 } else {
7713 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7714 }
7715
7716 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7717 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7718
7719 tcg_temp_free_i64(xh);
7720 tcg_temp_free_i64(xl);
cd73f2c9 7721 } else {
f5bc1bfa
TM
7722 if ((DM(ctx->opcode) & 2) == 0) {
7723 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7724 } else {
7725 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7726 }
7727 if ((DM(ctx->opcode) & 1) == 0) {
7728 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7729 } else {
7730 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7731 }
cd73f2c9
TM
7732 }
7733}
7734
df020ce0
TM
7735#define OP_ABS 1
7736#define OP_NABS 2
7737#define OP_NEG 3
7738#define OP_CPSGN 4
e5d7d2b0
PM
7739#define SGN_MASK_DP 0x8000000000000000ull
7740#define SGN_MASK_SP 0x8000000080000000ull
df020ce0
TM
7741
7742#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7743static void glue(gen_, name)(DisasContext * ctx) \
7744 { \
7745 TCGv_i64 xb, sgm; \
7746 if (unlikely(!ctx->vsx_enabled)) { \
7747 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7748 return; \
7749 } \
f976b09e
AG
7750 xb = tcg_temp_new_i64(); \
7751 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7752 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7753 tcg_gen_movi_i64(sgm, sgn_mask); \
7754 switch (op) { \
7755 case OP_ABS: { \
7756 tcg_gen_andc_i64(xb, xb, sgm); \
7757 break; \
7758 } \
7759 case OP_NABS: { \
7760 tcg_gen_or_i64(xb, xb, sgm); \
7761 break; \
7762 } \
7763 case OP_NEG: { \
7764 tcg_gen_xor_i64(xb, xb, sgm); \
7765 break; \
7766 } \
7767 case OP_CPSGN: { \
f976b09e 7768 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7769 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7770 tcg_gen_and_i64(xa, xa, sgm); \
7771 tcg_gen_andc_i64(xb, xb, sgm); \
7772 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7773 tcg_temp_free_i64(xa); \
df020ce0
TM
7774 break; \
7775 } \
7776 } \
7777 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7778 tcg_temp_free_i64(xb); \
7779 tcg_temp_free_i64(sgm); \
df020ce0
TM
7780 }
7781
7782VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7783VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7784VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7785VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7786
be574920
TM
7787#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7788static void glue(gen_, name)(DisasContext * ctx) \
7789 { \
7790 TCGv_i64 xbh, xbl, sgm; \
7791 if (unlikely(!ctx->vsx_enabled)) { \
7792 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7793 return; \
7794 } \
f976b09e
AG
7795 xbh = tcg_temp_new_i64(); \
7796 xbl = tcg_temp_new_i64(); \
7797 sgm = tcg_temp_new_i64(); \
be574920
TM
7798 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7799 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7800 tcg_gen_movi_i64(sgm, sgn_mask); \
7801 switch (op) { \
7802 case OP_ABS: { \
7803 tcg_gen_andc_i64(xbh, xbh, sgm); \
7804 tcg_gen_andc_i64(xbl, xbl, sgm); \
7805 break; \
7806 } \
7807 case OP_NABS: { \
7808 tcg_gen_or_i64(xbh, xbh, sgm); \
7809 tcg_gen_or_i64(xbl, xbl, sgm); \
7810 break; \
7811 } \
7812 case OP_NEG: { \
7813 tcg_gen_xor_i64(xbh, xbh, sgm); \
7814 tcg_gen_xor_i64(xbl, xbl, sgm); \
7815 break; \
7816 } \
7817 case OP_CPSGN: { \
f976b09e
AG
7818 TCGv_i64 xah = tcg_temp_new_i64(); \
7819 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7820 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7821 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7822 tcg_gen_and_i64(xah, xah, sgm); \
7823 tcg_gen_and_i64(xal, xal, sgm); \
7824 tcg_gen_andc_i64(xbh, xbh, sgm); \
7825 tcg_gen_andc_i64(xbl, xbl, sgm); \
7826 tcg_gen_or_i64(xbh, xbh, xah); \
7827 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7828 tcg_temp_free_i64(xah); \
7829 tcg_temp_free_i64(xal); \
be574920
TM
7830 break; \
7831 } \
7832 } \
7833 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7834 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7835 tcg_temp_free_i64(xbh); \
7836 tcg_temp_free_i64(xbl); \
7837 tcg_temp_free_i64(sgm); \
be574920
TM
7838 }
7839
7840VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7841VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7842VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7843VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7844VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7845VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7846VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7847VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7848
3c3cbbdc
TM
7849#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7850static void gen_##name(DisasContext * ctx) \
7851{ \
7852 TCGv_i32 opc; \
7853 if (unlikely(!ctx->vsx_enabled)) { \
7854 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7855 return; \
7856 } \
7857 /* NIP cannot be restored if the memory exception comes from an helper */ \
7858 gen_update_nip(ctx, ctx->nip - 4); \
7859 opc = tcg_const_i32(ctx->opcode); \
7860 gen_helper_##name(cpu_env, opc); \
7861 tcg_temp_free_i32(opc); \
7862}
be574920 7863
3d1140bf
TM
7864#define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7865static void gen_##name(DisasContext * ctx) \
7866{ \
7867 if (unlikely(!ctx->vsx_enabled)) { \
7868 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7869 return; \
7870 } \
7871 /* NIP cannot be restored if the exception comes */ \
7872 /* from a helper. */ \
7873 gen_update_nip(ctx, ctx->nip - 4); \
7874 \
7875 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7876 cpu_vsrh(xB(ctx->opcode))); \
7877}
7878
ee6e02c0
TM
7879GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7880GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7881GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7882GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7883GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7884GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7885GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7886GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7887GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7888GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7889GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7890GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7891GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7892GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7893GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7894GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7895GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
7896GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7897GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
7898GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7899GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568 7900GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7ee19fb9 7901GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
ed8ac568 7902GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7ee19fb9 7903GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
5177d2ca
TM
7904GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7905GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
7906GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
7907GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
7908GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
7909GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
7910GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
7911GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
7912GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
7913GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
7914GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
3d1140bf 7915GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
ee6e02c0 7916
3fd0aadf
TM
7917GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
7918GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 7919GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 7920GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 7921GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 7922GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
968e76bc 7923GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
f53f81e0
TM
7924GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
7925GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
7926GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
7927GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
7928GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
7929GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
7930GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
7931GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
74698350
TM
7932GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
7933GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
3fd0aadf 7934
ee6e02c0
TM
7935GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
7936GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 7937GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 7938GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 7939GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 7940GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 7941GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 7942GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 7943GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
7944GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
7945GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
7946GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
7947GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
7948GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
7949GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
7950GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
7951GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
7952GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
7953GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
7954GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
7955GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
7956GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 7957GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
7958GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
7959GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
7960GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
7961GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
7962GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
7963GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
7964GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
7965GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
7966GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
7967GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
7968GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
7969GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
7970GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
7971
7972GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
7973GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 7974GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 7975GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 7976GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 7977GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 7978GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 7979GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 7980GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
7981GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
7982GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
7983GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
7984GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
7985GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
7986GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
7987GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
7988GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
7989GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
7990GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
7991GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
7992GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
7993GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 7994GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
7995GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
7996GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
7997GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
7998GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
7999GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
8000GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
8001GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
8002GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
8003GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
8004GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
8005GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
8006GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
8007GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 8008
79ca8a6a
TM
8009#define VSX_LOGICAL(name, tcg_op) \
8010static void glue(gen_, name)(DisasContext * ctx) \
8011 { \
8012 if (unlikely(!ctx->vsx_enabled)) { \
8013 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8014 return; \
8015 } \
8016 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8017 cpu_vsrh(xB(ctx->opcode))); \
8018 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8019 cpu_vsrl(xB(ctx->opcode))); \
8020 }
8021
f976b09e
AG
8022VSX_LOGICAL(xxland, tcg_gen_and_i64)
8023VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8024VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8025VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8026VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
67a33f37
TM
8027VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8028VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8029VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
df020ce0 8030
ce577d2e
TM
8031#define VSX_XXMRG(name, high) \
8032static void glue(gen_, name)(DisasContext * ctx) \
8033 { \
8034 TCGv_i64 a0, a1, b0, b1; \
8035 if (unlikely(!ctx->vsx_enabled)) { \
8036 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8037 return; \
8038 } \
f976b09e
AG
8039 a0 = tcg_temp_new_i64(); \
8040 a1 = tcg_temp_new_i64(); \
8041 b0 = tcg_temp_new_i64(); \
8042 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
8043 if (high) { \
8044 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8045 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8046 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8047 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8048 } else { \
8049 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8050 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8051 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8052 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8053 } \
8054 tcg_gen_shri_i64(a0, a0, 32); \
8055 tcg_gen_shri_i64(b0, b0, 32); \
8056 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8057 b0, a0, 32, 32); \
8058 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8059 b1, a1, 32, 32); \
f976b09e
AG
8060 tcg_temp_free_i64(a0); \
8061 tcg_temp_free_i64(a1); \
8062 tcg_temp_free_i64(b0); \
8063 tcg_temp_free_i64(b1); \
ce577d2e
TM
8064 }
8065
8066VSX_XXMRG(xxmrghw, 1)
8067VSX_XXMRG(xxmrglw, 0)
8068
551e3ef7
TM
8069static void gen_xxsel(DisasContext * ctx)
8070{
8071 TCGv_i64 a, b, c;
8072 if (unlikely(!ctx->vsx_enabled)) {
8073 gen_exception(ctx, POWERPC_EXCP_VSXU);
8074 return;
8075 }
f976b09e
AG
8076 a = tcg_temp_new_i64();
8077 b = tcg_temp_new_i64();
8078 c = tcg_temp_new_i64();
551e3ef7
TM
8079
8080 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8081 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8082 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8083
8084 tcg_gen_and_i64(b, b, c);
8085 tcg_gen_andc_i64(a, a, c);
8086 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8087
8088 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8089 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8090 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8091
8092 tcg_gen_and_i64(b, b, c);
8093 tcg_gen_andc_i64(a, a, c);
8094 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8095
f976b09e
AG
8096 tcg_temp_free_i64(a);
8097 tcg_temp_free_i64(b);
8098 tcg_temp_free_i64(c);
551e3ef7
TM
8099}
8100
76c15fe0
TM
8101static void gen_xxspltw(DisasContext *ctx)
8102{
8103 TCGv_i64 b, b2;
8104 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8105 cpu_vsrl(xB(ctx->opcode)) :
8106 cpu_vsrh(xB(ctx->opcode));
8107
8108 if (unlikely(!ctx->vsx_enabled)) {
8109 gen_exception(ctx, POWERPC_EXCP_VSXU);
8110 return;
8111 }
8112
f976b09e
AG
8113 b = tcg_temp_new_i64();
8114 b2 = tcg_temp_new_i64();
76c15fe0
TM
8115
8116 if (UIM(ctx->opcode) & 1) {
8117 tcg_gen_ext32u_i64(b, vsr);
8118 } else {
8119 tcg_gen_shri_i64(b, vsr, 32);
8120 }
8121
8122 tcg_gen_shli_i64(b2, b, 32);
8123 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8124 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8125
f976b09e
AG
8126 tcg_temp_free_i64(b);
8127 tcg_temp_free_i64(b2);
76c15fe0
TM
8128}
8129
acc42968
TM
8130static void gen_xxsldwi(DisasContext *ctx)
8131{
8132 TCGv_i64 xth, xtl;
8133 if (unlikely(!ctx->vsx_enabled)) {
8134 gen_exception(ctx, POWERPC_EXCP_VSXU);
8135 return;
8136 }
f976b09e
AG
8137 xth = tcg_temp_new_i64();
8138 xtl = tcg_temp_new_i64();
acc42968
TM
8139
8140 switch (SHW(ctx->opcode)) {
8141 case 0: {
8142 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8143 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8144 break;
8145 }
8146 case 1: {
f976b09e 8147 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8148 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8149 tcg_gen_shli_i64(xth, xth, 32);
8150 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8151 tcg_gen_shri_i64(t0, t0, 32);
8152 tcg_gen_or_i64(xth, xth, t0);
8153 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8154 tcg_gen_shli_i64(xtl, xtl, 32);
8155 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8156 tcg_gen_shri_i64(t0, t0, 32);
8157 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8158 tcg_temp_free_i64(t0);
acc42968
TM
8159 break;
8160 }
8161 case 2: {
8162 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8163 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8164 break;
8165 }
8166 case 3: {
f976b09e 8167 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8168 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8169 tcg_gen_shli_i64(xth, xth, 32);
8170 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8171 tcg_gen_shri_i64(t0, t0, 32);
8172 tcg_gen_or_i64(xth, xth, t0);
8173 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8174 tcg_gen_shli_i64(xtl, xtl, 32);
8175 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8176 tcg_gen_shri_i64(t0, t0, 32);
8177 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8178 tcg_temp_free_i64(t0);
acc42968
TM
8179 break;
8180 }
8181 }
8182
8183 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8184 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8185
f976b09e
AG
8186 tcg_temp_free_i64(xth);
8187 tcg_temp_free_i64(xtl);
acc42968
TM
8188}
8189
f0b01f02
TM
8190/*** Decimal Floating Point ***/
8191
8192static inline TCGv_ptr gen_fprp_ptr(int reg)
8193{
8194 TCGv_ptr r = tcg_temp_new_ptr();
8195 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, fpr[reg]));
8196 return r;
8197}
8198
8199#if defined(TARGET_PPC64)
f0b01f02
TM
8200static void gen_set_cr6_from_fpscr(DisasContext *ctx)
8201{
8202 TCGv_i32 tmp = tcg_temp_new_i32();
8203 tcg_gen_trunc_tl_i32(tmp, cpu_fpscr);
8204 tcg_gen_shri_i32(cpu_crf[1], tmp, 28);
8205 tcg_temp_free_i32(tmp);
8206}
8207#else
f0b01f02
TM
8208static void gen_set_cr6_from_fpscr(DisasContext *ctx)
8209{
8210 tcg_gen_shri_tl(cpu_crf[1], cpu_fpscr, 28);
8211}
8212#endif
8213
8214#define GEN_DFP_T_A_B_Rc(name) \
8215static void gen_##name(DisasContext *ctx) \
8216{ \
8217 TCGv_ptr rd, ra, rb; \
8218 if (unlikely(!ctx->fpu_enabled)) { \
8219 gen_exception(ctx, POWERPC_EXCP_FPU); \
8220 return; \
8221 } \
8222 gen_update_nip(ctx, ctx->nip - 4); \
8223 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8224 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8225 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8226 gen_helper_##name(cpu_env, rd, ra, rb); \
8227 if (unlikely(Rc(ctx->opcode) != 0)) { \
8228 gen_set_cr6_from_fpscr(ctx); \
8229 } \
8230 tcg_temp_free_ptr(rd); \
8231 tcg_temp_free_ptr(ra); \
8232 tcg_temp_free_ptr(rb); \
8233}
8234
8235#define GEN_DFP_BF_A_B(name) \
8236static void gen_##name(DisasContext *ctx) \
8237{ \
8238 TCGv_ptr ra, rb; \
8239 if (unlikely(!ctx->fpu_enabled)) { \
8240 gen_exception(ctx, POWERPC_EXCP_FPU); \
8241 return; \
8242 } \
8243 gen_update_nip(ctx, ctx->nip - 4); \
8244 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8245 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8246 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8247 cpu_env, ra, rb); \
8248 tcg_temp_free_ptr(ra); \
8249 tcg_temp_free_ptr(rb); \
8250}
8251
8252#define GEN_DFP_BF_A_DCM(name) \
8253static void gen_##name(DisasContext *ctx) \
8254{ \
8255 TCGv_ptr ra; \
8256 TCGv_i32 dcm; \
8257 if (unlikely(!ctx->fpu_enabled)) { \
8258 gen_exception(ctx, POWERPC_EXCP_FPU); \
8259 return; \
8260 } \
8261 gen_update_nip(ctx, ctx->nip - 4); \
8262 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8263 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8264 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8265 cpu_env, ra, dcm); \
8266 tcg_temp_free_ptr(ra); \
8267 tcg_temp_free_i32(dcm); \
8268}
8269
8270#define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8271static void gen_##name(DisasContext *ctx) \
8272{ \
8273 TCGv_ptr rt, rb; \
8274 TCGv_i32 u32_1, u32_2; \
8275 if (unlikely(!ctx->fpu_enabled)) { \
8276 gen_exception(ctx, POWERPC_EXCP_FPU); \
8277 return; \
8278 } \
8279 gen_update_nip(ctx, ctx->nip - 4); \
8280 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8281 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8282 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8283 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8284 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8285 if (unlikely(Rc(ctx->opcode) != 0)) { \
8286 gen_set_cr6_from_fpscr(ctx); \
8287 } \
8288 tcg_temp_free_ptr(rt); \
8289 tcg_temp_free_ptr(rb); \
8290 tcg_temp_free_i32(u32_1); \
8291 tcg_temp_free_i32(u32_2); \
8292}
8293
8294#define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8295static void gen_##name(DisasContext *ctx) \
8296{ \
8297 TCGv_ptr rt, ra, rb; \
8298 TCGv_i32 i32; \
8299 if (unlikely(!ctx->fpu_enabled)) { \
8300 gen_exception(ctx, POWERPC_EXCP_FPU); \
8301 return; \
8302 } \
8303 gen_update_nip(ctx, ctx->nip - 4); \
8304 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8305 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8306 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8307 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8308 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8309 if (unlikely(Rc(ctx->opcode) != 0)) { \
8310 gen_set_cr6_from_fpscr(ctx); \
8311 } \
8312 tcg_temp_free_ptr(rt); \
8313 tcg_temp_free_ptr(rb); \
8314 tcg_temp_free_ptr(ra); \
8315 tcg_temp_free_i32(i32); \
8316 }
8317
8318#define GEN_DFP_T_B_Rc(name) \
8319static void gen_##name(DisasContext *ctx) \
8320{ \
8321 TCGv_ptr rt, rb; \
8322 if (unlikely(!ctx->fpu_enabled)) { \
8323 gen_exception(ctx, POWERPC_EXCP_FPU); \
8324 return; \
8325 } \
8326 gen_update_nip(ctx, ctx->nip - 4); \
8327 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8328 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8329 gen_helper_##name(cpu_env, rt, rb); \
8330 if (unlikely(Rc(ctx->opcode) != 0)) { \
8331 gen_set_cr6_from_fpscr(ctx); \
8332 } \
8333 tcg_temp_free_ptr(rt); \
8334 tcg_temp_free_ptr(rb); \
8335 }
8336
8337#define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8338static void gen_##name(DisasContext *ctx) \
8339{ \
8340 TCGv_ptr rt, rs; \
8341 TCGv_i32 i32; \
8342 if (unlikely(!ctx->fpu_enabled)) { \
8343 gen_exception(ctx, POWERPC_EXCP_FPU); \
8344 return; \
8345 } \
8346 gen_update_nip(ctx, ctx->nip - 4); \
8347 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8348 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8349 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8350 gen_helper_##name(cpu_env, rt, rs, i32); \
8351 if (unlikely(Rc(ctx->opcode) != 0)) { \
8352 gen_set_cr6_from_fpscr(ctx); \
8353 } \
8354 tcg_temp_free_ptr(rt); \
8355 tcg_temp_free_ptr(rs); \
8356 tcg_temp_free_i32(i32); \
8357}
ce577d2e 8358
a9d7ba03
TM
8359GEN_DFP_T_A_B_Rc(dadd)
8360GEN_DFP_T_A_B_Rc(daddq)
2128f8a5
TM
8361GEN_DFP_T_A_B_Rc(dsub)
8362GEN_DFP_T_A_B_Rc(dsubq)
8de6a1cc
TM
8363GEN_DFP_T_A_B_Rc(dmul)
8364GEN_DFP_T_A_B_Rc(dmulq)
9024ff40
TM
8365GEN_DFP_T_A_B_Rc(ddiv)
8366GEN_DFP_T_A_B_Rc(ddivq)
5833505b
TM
8367GEN_DFP_BF_A_B(dcmpu)
8368GEN_DFP_BF_A_B(dcmpuq)
8369GEN_DFP_BF_A_B(dcmpo)
8370GEN_DFP_BF_A_B(dcmpoq)
e601c1ee
TM
8371GEN_DFP_BF_A_DCM(dtstdc)
8372GEN_DFP_BF_A_DCM(dtstdcq)
1bf9c0e1
TM
8373GEN_DFP_BF_A_DCM(dtstdg)
8374GEN_DFP_BF_A_DCM(dtstdgq)
f3d2b0bc
TM
8375GEN_DFP_BF_A_B(dtstex)
8376GEN_DFP_BF_A_B(dtstexq)
f6022a76
TM
8377GEN_DFP_BF_A_B(dtstsf)
8378GEN_DFP_BF_A_B(dtstsfq)
5826ebe2
TM
8379GEN_DFP_T_B_U32_U32_Rc(dquai, SIMM5, RMC)
8380GEN_DFP_T_B_U32_U32_Rc(dquaiq, SIMM5, RMC)
8381GEN_DFP_T_A_B_I32_Rc(dqua, RMC)
8382GEN_DFP_T_A_B_I32_Rc(dquaq, RMC)
512918aa
TM
8383GEN_DFP_T_A_B_I32_Rc(drrnd, RMC)
8384GEN_DFP_T_A_B_I32_Rc(drrndq, RMC)
97c0d930
TM
8385GEN_DFP_T_B_U32_U32_Rc(drintx, FPW, RMC)
8386GEN_DFP_T_B_U32_U32_Rc(drintxq, FPW, RMC)
8387GEN_DFP_T_B_U32_U32_Rc(drintn, FPW, RMC)
8388GEN_DFP_T_B_U32_U32_Rc(drintnq, FPW, RMC)
290d9ee5
TM
8389GEN_DFP_T_B_Rc(dctdp)
8390GEN_DFP_T_B_Rc(dctqpq)
ca603eb4
TM
8391GEN_DFP_T_B_Rc(drsp)
8392GEN_DFP_T_B_Rc(drdpq)
f1214193
TM
8393GEN_DFP_T_B_Rc(dcffix)
8394GEN_DFP_T_B_Rc(dcffixq)
bea0dd79
TM
8395GEN_DFP_T_B_Rc(dctfix)
8396GEN_DFP_T_B_Rc(dctfixq)
7796676f
TM
8397GEN_DFP_T_FPR_I32_Rc(ddedpd, rB, SP)
8398GEN_DFP_T_FPR_I32_Rc(ddedpdq, rB, SP)
013c3ac0
TM
8399GEN_DFP_T_FPR_I32_Rc(denbcd, rB, SP)
8400GEN_DFP_T_FPR_I32_Rc(denbcdq, rB, SP)
e8a48460
TM
8401GEN_DFP_T_B_Rc(dxex)
8402GEN_DFP_T_B_Rc(dxexq)
297666eb
TM
8403GEN_DFP_T_A_B_Rc(diex)
8404GEN_DFP_T_A_B_Rc(diexq)
804e654a
TM
8405GEN_DFP_T_FPR_I32_Rc(dscli, rA, DCM)
8406GEN_DFP_T_FPR_I32_Rc(dscliq, rA, DCM)
8407GEN_DFP_T_FPR_I32_Rc(dscri, rA, DCM)
8408GEN_DFP_T_FPR_I32_Rc(dscriq, rA, DCM)
8409
0487d6a8 8410/*** SPE extension ***/
0487d6a8 8411/* Register moves */
3cd7d1dd 8412
a0e13900
FC
8413static inline void gen_evmra(DisasContext *ctx)
8414{
8415
8416 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8417 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8418 return;
8419 }
8420
8421#if defined(TARGET_PPC64)
8422 /* rD := rA */
8423 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8424
8425 /* spe_acc := rA */
8426 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
8427 cpu_env,
1328c2bf 8428 offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8429#else
8430 TCGv_i64 tmp = tcg_temp_new_i64();
8431
8432 /* tmp := rA_lo + rA_hi << 32 */
8433 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8434
8435 /* spe_acc := tmp */
1328c2bf 8436 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8437 tcg_temp_free_i64(tmp);
8438
8439 /* rD := rA */
8440 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8441 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8442#endif
8443}
8444
636aa200
BS
8445static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8446{
f78fb44e
AJ
8447#if defined(TARGET_PPC64)
8448 tcg_gen_mov_i64(t, cpu_gpr[reg]);
8449#else
36aa55dc 8450 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
3cd7d1dd 8451#endif
f78fb44e 8452}
3cd7d1dd 8453
636aa200
BS
8454static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8455{
f78fb44e
AJ
8456#if defined(TARGET_PPC64)
8457 tcg_gen_mov_i64(cpu_gpr[reg], t);
8458#else
a7812ae4 8459 TCGv_i64 tmp = tcg_temp_new_i64();
f78fb44e 8460 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
f78fb44e
AJ
8461 tcg_gen_shri_i64(tmp, t, 32);
8462 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
a7812ae4 8463 tcg_temp_free_i64(tmp);
3cd7d1dd 8464#endif
f78fb44e 8465}
3cd7d1dd 8466
70560da7 8467#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 8468static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
8469{ \
8470 if (Rc(ctx->opcode)) \
8471 gen_##name1(ctx); \
8472 else \
8473 gen_##name0(ctx); \
8474}
8475
8476/* Handler for undefined SPE opcodes */
636aa200 8477static inline void gen_speundef(DisasContext *ctx)
0487d6a8 8478{
e06fcd75 8479 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
8480}
8481
57951c27
AJ
8482/* SPE logic */
8483#if defined(TARGET_PPC64)
8484#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8485static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8486{ \
8487 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8488 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8489 return; \
8490 } \
57951c27
AJ
8491 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8492 cpu_gpr[rB(ctx->opcode)]); \
8493}
8494#else
8495#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8496static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8497{ \
8498 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8499 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8500 return; \
8501 } \
8502 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8503 cpu_gpr[rB(ctx->opcode)]); \
8504 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8505 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8506}
57951c27
AJ
8507#endif
8508
8509GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8510GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8511GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8512GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8513GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8514GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8515GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8516GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 8517
57951c27
AJ
8518/* SPE logic immediate */
8519#if defined(TARGET_PPC64)
8520#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8521static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a
AJ
8522{ \
8523 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8524 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
8525 return; \
8526 } \
a7812ae4
PB
8527 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8528 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8529 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8530 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8531 tcg_opi(t0, t0, rB(ctx->opcode)); \
8532 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8533 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8534 tcg_temp_free_i64(t2); \
57951c27
AJ
8535 tcg_opi(t1, t1, rB(ctx->opcode)); \
8536 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8537 tcg_temp_free_i32(t0); \
8538 tcg_temp_free_i32(t1); \
3d3a6a0a 8539}
57951c27
AJ
8540#else
8541#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8542static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8543{ \
8544 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8545 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8546 return; \
8547 } \
57951c27
AJ
8548 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8549 rB(ctx->opcode)); \
8550 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8551 rB(ctx->opcode)); \
0487d6a8 8552}
57951c27
AJ
8553#endif
8554GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8555GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8556GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8557GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 8558
57951c27
AJ
8559/* SPE arithmetic */
8560#if defined(TARGET_PPC64)
8561#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8562static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8563{ \
8564 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8565 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8566 return; \
8567 } \
a7812ae4
PB
8568 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8569 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8570 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8571 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8572 tcg_op(t0, t0); \
8573 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8574 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8575 tcg_temp_free_i64(t2); \
57951c27
AJ
8576 tcg_op(t1, t1); \
8577 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8578 tcg_temp_free_i32(t0); \
8579 tcg_temp_free_i32(t1); \
0487d6a8 8580}
57951c27 8581#else
a7812ae4 8582#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8583static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8584{ \
8585 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8586 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8587 return; \
8588 } \
8589 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8590 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8591}
8592#endif
0487d6a8 8593
636aa200 8594static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27
AJ
8595{
8596 int l1 = gen_new_label();
8597 int l2 = gen_new_label();
0487d6a8 8598
57951c27
AJ
8599 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8600 tcg_gen_neg_i32(ret, arg1);
8601 tcg_gen_br(l2);
8602 gen_set_label(l1);
a7812ae4 8603 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
8604 gen_set_label(l2);
8605}
8606GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8607GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8608GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8609GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 8610static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 8611{
57951c27
AJ
8612 tcg_gen_addi_i32(ret, arg1, 0x8000);
8613 tcg_gen_ext16u_i32(ret, ret);
8614}
8615GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
8616GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8617GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 8618
57951c27
AJ
8619#if defined(TARGET_PPC64)
8620#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8621static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8622{ \
8623 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8624 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8625 return; \
8626 } \
a7812ae4
PB
8627 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8628 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8629 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
501e23c4 8630 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
57951c27
AJ
8631 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8632 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
8633 tcg_op(t0, t0, t2); \
8634 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
8635 tcg_gen_trunc_i64_i32(t1, t3); \
8636 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
8637 tcg_gen_trunc_i64_i32(t2, t3); \
a7812ae4 8638 tcg_temp_free_i64(t3); \
57951c27 8639 tcg_op(t1, t1, t2); \
a7812ae4 8640 tcg_temp_free_i32(t2); \
57951c27 8641 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8642 tcg_temp_free_i32(t0); \
8643 tcg_temp_free_i32(t1); \
0487d6a8 8644}
57951c27
AJ
8645#else
8646#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8647static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8648{ \
8649 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8650 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8651 return; \
8652 } \
57951c27
AJ
8653 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8654 cpu_gpr[rB(ctx->opcode)]); \
8655 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8656 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8657}
57951c27 8658#endif
0487d6a8 8659
636aa200 8660static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8661{
a7812ae4 8662 TCGv_i32 t0;
57951c27 8663 int l1, l2;
0487d6a8 8664
57951c27
AJ
8665 l1 = gen_new_label();
8666 l2 = gen_new_label();
a7812ae4 8667 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8668 /* No error here: 6 bits are used */
8669 tcg_gen_andi_i32(t0, arg2, 0x3F);
8670 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8671 tcg_gen_shr_i32(ret, arg1, t0);
8672 tcg_gen_br(l2);
8673 gen_set_label(l1);
8674 tcg_gen_movi_i32(ret, 0);
0aef4261 8675 gen_set_label(l2);
a7812ae4 8676 tcg_temp_free_i32(t0);
57951c27
AJ
8677}
8678GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 8679static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8680{
a7812ae4 8681 TCGv_i32 t0;
57951c27
AJ
8682 int l1, l2;
8683
8684 l1 = gen_new_label();
8685 l2 = gen_new_label();
a7812ae4 8686 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8687 /* No error here: 6 bits are used */
8688 tcg_gen_andi_i32(t0, arg2, 0x3F);
8689 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8690 tcg_gen_sar_i32(ret, arg1, t0);
8691 tcg_gen_br(l2);
8692 gen_set_label(l1);
8693 tcg_gen_movi_i32(ret, 0);
0aef4261 8694 gen_set_label(l2);
a7812ae4 8695 tcg_temp_free_i32(t0);
57951c27
AJ
8696}
8697GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 8698static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8699{
a7812ae4 8700 TCGv_i32 t0;
57951c27
AJ
8701 int l1, l2;
8702
8703 l1 = gen_new_label();
8704 l2 = gen_new_label();
a7812ae4 8705 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8706 /* No error here: 6 bits are used */
8707 tcg_gen_andi_i32(t0, arg2, 0x3F);
8708 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8709 tcg_gen_shl_i32(ret, arg1, t0);
8710 tcg_gen_br(l2);
8711 gen_set_label(l1);
8712 tcg_gen_movi_i32(ret, 0);
e29ef9fa 8713 gen_set_label(l2);
a7812ae4 8714 tcg_temp_free_i32(t0);
57951c27
AJ
8715}
8716GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 8717static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8718{
a7812ae4 8719 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
8720 tcg_gen_andi_i32(t0, arg2, 0x1F);
8721 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 8722 tcg_temp_free_i32(t0);
57951c27
AJ
8723}
8724GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 8725static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
8726{
8727 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8728 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8729 return;
8730 }
8731#if defined(TARGET_PPC64)
a7812ae4
PB
8732 TCGv t0 = tcg_temp_new();
8733 TCGv t1 = tcg_temp_new();
57951c27
AJ
8734 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8735 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8736 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8737 tcg_temp_free(t0);
8738 tcg_temp_free(t1);
8739#else
8740 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8741 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8742#endif
8743}
8744GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 8745static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 8746{
57951c27
AJ
8747 tcg_gen_sub_i32(ret, arg2, arg1);
8748}
8749GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 8750
57951c27
AJ
8751/* SPE arithmetic immediate */
8752#if defined(TARGET_PPC64)
8753#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8754static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8755{ \
8756 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8757 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8758 return; \
8759 } \
a7812ae4
PB
8760 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8761 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8762 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8763 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8764 tcg_op(t0, t0, rA(ctx->opcode)); \
8765 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8766 tcg_gen_trunc_i64_i32(t1, t2); \
e06fcd75 8767 tcg_temp_free_i64(t2); \
57951c27
AJ
8768 tcg_op(t1, t1, rA(ctx->opcode)); \
8769 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8770 tcg_temp_free_i32(t0); \
8771 tcg_temp_free_i32(t1); \
57951c27
AJ
8772}
8773#else
8774#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8775static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8776{ \
8777 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8778 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8779 return; \
8780 } \
8781 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
8782 rA(ctx->opcode)); \
8783 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
8784 rA(ctx->opcode)); \
8785}
8786#endif
8787GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8788GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8789
8790/* SPE comparison */
8791#if defined(TARGET_PPC64)
8792#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8793static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8794{ \
8795 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8796 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8797 return; \
8798 } \
8799 int l1 = gen_new_label(); \
8800 int l2 = gen_new_label(); \
8801 int l3 = gen_new_label(); \
8802 int l4 = gen_new_label(); \
a7812ae4
PB
8803 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8804 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8805 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8806 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8807 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8808 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
a7812ae4 8809 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8810 tcg_gen_br(l2); \
8811 gen_set_label(l1); \
8812 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8813 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8814 gen_set_label(l2); \
8815 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8816 tcg_gen_trunc_i64_i32(t0, t2); \
8817 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8818 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8819 tcg_temp_free_i64(t2); \
57951c27
AJ
8820 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8821 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8822 ~(CRF_CH | CRF_CH_AND_CL)); \
8823 tcg_gen_br(l4); \
8824 gen_set_label(l3); \
8825 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8826 CRF_CH | CRF_CH_OR_CL); \
8827 gen_set_label(l4); \
a7812ae4
PB
8828 tcg_temp_free_i32(t0); \
8829 tcg_temp_free_i32(t1); \
57951c27
AJ
8830}
8831#else
8832#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8833static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8834{ \
8835 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8836 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8837 return; \
8838 } \
8839 int l1 = gen_new_label(); \
8840 int l2 = gen_new_label(); \
8841 int l3 = gen_new_label(); \
8842 int l4 = gen_new_label(); \
8843 \
8844 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8845 cpu_gpr[rB(ctx->opcode)], l1); \
8846 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8847 tcg_gen_br(l2); \
8848 gen_set_label(l1); \
8849 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8850 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8851 gen_set_label(l2); \
8852 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8853 cpu_gprh[rB(ctx->opcode)], l3); \
8854 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8855 ~(CRF_CH | CRF_CH_AND_CL)); \
8856 tcg_gen_br(l4); \
8857 gen_set_label(l3); \
8858 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8859 CRF_CH | CRF_CH_OR_CL); \
8860 gen_set_label(l4); \
8861}
8862#endif
8863GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8864GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8865GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8866GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8867GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8868
8869/* SPE misc */
636aa200 8870static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8871{
8872 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8873 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8874 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8875}
636aa200 8876static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8877{
8878 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8879 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8880 return;
8881 }
8882#if defined(TARGET_PPC64)
a7812ae4
PB
8883 TCGv t0 = tcg_temp_new();
8884 TCGv t1 = tcg_temp_new();
17d9b3af 8885 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8886 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8887 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8888 tcg_temp_free(t0);
8889 tcg_temp_free(t1);
8890#else
57951c27 8891 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8892 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8893#endif
8894}
636aa200 8895static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8896{
8897 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8898 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8899 return;
8900 }
8901#if defined(TARGET_PPC64)
a7812ae4
PB
8902 TCGv t0 = tcg_temp_new();
8903 TCGv t1 = tcg_temp_new();
17d9b3af 8904 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8905 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8906 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8907 tcg_temp_free(t0);
8908 tcg_temp_free(t1);
8909#else
8910 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8911 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8912#endif
8913}
636aa200 8914static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8915{
8916 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8917 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8918 return;
8919 }
8920#if defined(TARGET_PPC64)
a7812ae4
PB
8921 TCGv t0 = tcg_temp_new();
8922 TCGv t1 = tcg_temp_new();
57951c27
AJ
8923 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8924 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8925 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8926 tcg_temp_free(t0);
8927 tcg_temp_free(t1);
8928#else
33890b3e
NF
8929 if (rD(ctx->opcode) == rA(ctx->opcode)) {
8930 TCGv_i32 tmp = tcg_temp_new_i32();
8931 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
8932 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8933 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
8934 tcg_temp_free_i32(tmp);
8935 } else {
8936 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8937 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8938 }
57951c27
AJ
8939#endif
8940}
636aa200 8941static inline void gen_evsplati(DisasContext *ctx)
57951c27 8942{
ae01847f 8943 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8944
57951c27 8945#if defined(TARGET_PPC64)
38d14952 8946 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8947#else
8948 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8949 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8950#endif
8951}
636aa200 8952static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8953{
ae01847f 8954 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8955
57951c27 8956#if defined(TARGET_PPC64)
38d14952 8957 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8958#else
8959 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8960 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8961#endif
0487d6a8
JM
8962}
8963
636aa200 8964static inline void gen_evsel(DisasContext *ctx)
57951c27
AJ
8965{
8966 int l1 = gen_new_label();
8967 int l2 = gen_new_label();
8968 int l3 = gen_new_label();
8969 int l4 = gen_new_label();
a7812ae4 8970 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8971#if defined(TARGET_PPC64)
a7812ae4
PB
8972 TCGv t1 = tcg_temp_local_new();
8973 TCGv t2 = tcg_temp_local_new();
57951c27
AJ
8974#endif
8975 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8976 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
8977#if defined(TARGET_PPC64)
8978 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8979#else
8980 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8981#endif
8982 tcg_gen_br(l2);
8983 gen_set_label(l1);
8984#if defined(TARGET_PPC64)
8985 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8986#else
8987 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8988#endif
8989 gen_set_label(l2);
8990 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8991 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
8992#if defined(TARGET_PPC64)
17d9b3af 8993 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8994#else
8995 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8996#endif
8997 tcg_gen_br(l4);
8998 gen_set_label(l3);
8999#if defined(TARGET_PPC64)
17d9b3af 9000 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
9001#else
9002 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
9003#endif
9004 gen_set_label(l4);
a7812ae4 9005 tcg_temp_free_i32(t0);
57951c27
AJ
9006#if defined(TARGET_PPC64)
9007 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
9008 tcg_temp_free(t1);
9009 tcg_temp_free(t2);
9010#endif
9011}
e8eaa2c0
BS
9012
9013static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
9014{
9015 gen_evsel(ctx);
9016}
e8eaa2c0
BS
9017
9018static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
9019{
9020 gen_evsel(ctx);
9021}
e8eaa2c0
BS
9022
9023static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
9024{
9025 gen_evsel(ctx);
9026}
e8eaa2c0
BS
9027
9028static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
9029{
9030 gen_evsel(ctx);
9031}
0487d6a8 9032
a0e13900
FC
9033/* Multiply */
9034
9035static inline void gen_evmwumi(DisasContext *ctx)
9036{
9037 TCGv_i64 t0, t1;
9038
9039 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9040 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
9041 return;
9042 }
9043
9044 t0 = tcg_temp_new_i64();
9045 t1 = tcg_temp_new_i64();
9046
9047 /* t0 := rA; t1 := rB */
9048#if defined(TARGET_PPC64)
9049 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
9050 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
9051#else
9052 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
9053 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9054#endif
9055
9056 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9057
9058 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9059
9060 tcg_temp_free_i64(t0);
9061 tcg_temp_free_i64(t1);
9062}
9063
9064static inline void gen_evmwumia(DisasContext *ctx)
9065{
9066 TCGv_i64 tmp;
9067
9068 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9069 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
9070 return;
9071 }
9072
9073 gen_evmwumi(ctx); /* rD := rA * rB */
9074
9075 tmp = tcg_temp_new_i64();
9076
9077 /* acc := rD */
9078 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 9079 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9080 tcg_temp_free_i64(tmp);
9081}
9082
9083static inline void gen_evmwumiaa(DisasContext *ctx)
9084{
9085 TCGv_i64 acc;
9086 TCGv_i64 tmp;
9087
9088 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9089 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
9090 return;
9091 }
9092
9093 gen_evmwumi(ctx); /* rD := rA * rB */
9094
9095 acc = tcg_temp_new_i64();
9096 tmp = tcg_temp_new_i64();
9097
9098 /* tmp := rD */
9099 gen_load_gpr64(tmp, rD(ctx->opcode));
9100
9101 /* Load acc */
1328c2bf 9102 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9103
9104 /* acc := tmp + acc */
9105 tcg_gen_add_i64(acc, acc, tmp);
9106
9107 /* Store acc */
1328c2bf 9108 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9109
9110 /* rD := acc */
9111 gen_store_gpr64(rD(ctx->opcode), acc);
9112
9113 tcg_temp_free_i64(acc);
9114 tcg_temp_free_i64(tmp);
9115}
9116
9117static inline void gen_evmwsmi(DisasContext *ctx)
9118{
9119 TCGv_i64 t0, t1;
9120
9121 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9122 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
9123 return;
9124 }
9125
9126 t0 = tcg_temp_new_i64();
9127 t1 = tcg_temp_new_i64();
9128
9129 /* t0 := rA; t1 := rB */
9130#if defined(TARGET_PPC64)
9131 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
9132 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
9133#else
9134 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
9135 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9136#endif
9137
9138 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9139
9140 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9141
9142 tcg_temp_free_i64(t0);
9143 tcg_temp_free_i64(t1);
9144}
9145
9146static inline void gen_evmwsmia(DisasContext *ctx)
9147{
9148 TCGv_i64 tmp;
9149
9150 gen_evmwsmi(ctx); /* rD := rA * rB */
9151
9152 tmp = tcg_temp_new_i64();
9153
9154 /* acc := rD */
9155 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 9156 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9157
9158 tcg_temp_free_i64(tmp);
9159}
9160
9161static inline void gen_evmwsmiaa(DisasContext *ctx)
9162{
9163 TCGv_i64 acc = tcg_temp_new_i64();
9164 TCGv_i64 tmp = tcg_temp_new_i64();
9165
9166 gen_evmwsmi(ctx); /* rD := rA * rB */
9167
9168 acc = tcg_temp_new_i64();
9169 tmp = tcg_temp_new_i64();
9170
9171 /* tmp := rD */
9172 gen_load_gpr64(tmp, rD(ctx->opcode));
9173
9174 /* Load acc */
1328c2bf 9175 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9176
9177 /* acc := tmp + acc */
9178 tcg_gen_add_i64(acc, acc, tmp);
9179
9180 /* Store acc */
1328c2bf 9181 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9182
9183 /* rD := acc */
9184 gen_store_gpr64(rD(ctx->opcode), acc);
9185
9186 tcg_temp_free_i64(acc);
9187 tcg_temp_free_i64(tmp);
9188}
9189
70560da7
FC
9190GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9191GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9192GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9193GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9194GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9195GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9196GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9197GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
9198GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
9199GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9200GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9201GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9202GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9203GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9204GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9205GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9206GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9207GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9208GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9209GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
9210GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9211GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9212GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
9213GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
9214GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9215GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9216GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9217GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9218GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 9219
6a6ae23f 9220/* SPE load and stores */
636aa200 9221static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
9222{
9223 target_ulong uimm = rB(ctx->opcode);
9224
76db3ba4 9225 if (rA(ctx->opcode) == 0) {
6a6ae23f 9226 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 9227 } else {
6a6ae23f 9228 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 9229 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
9230 tcg_gen_ext32u_tl(EA, EA);
9231 }
76db3ba4 9232 }
0487d6a8 9233}
6a6ae23f 9234
636aa200 9235static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9236{
9237#if defined(TARGET_PPC64)
76db3ba4 9238 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9239#else
9240 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 9241 gen_qemu_ld64(ctx, t0, addr);
6a6ae23f
AJ
9242 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
9243 tcg_gen_shri_i64(t0, t0, 32);
9244 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
9245 tcg_temp_free_i64(t0);
9246#endif
0487d6a8 9247}
6a6ae23f 9248
636aa200 9249static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 9250{
0487d6a8 9251#if defined(TARGET_PPC64)
6a6ae23f 9252 TCGv t0 = tcg_temp_new();
76db3ba4 9253 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f 9254 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
76db3ba4
AJ
9255 gen_addr_add(ctx, addr, addr, 4);
9256 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
9257 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9258 tcg_temp_free(t0);
9259#else
76db3ba4
AJ
9260 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9261 gen_addr_add(ctx, addr, addr, 4);
9262 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f 9263#endif
0487d6a8 9264}
6a6ae23f 9265
636aa200 9266static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9267{
9268 TCGv t0 = tcg_temp_new();
9269#if defined(TARGET_PPC64)
76db3ba4 9270 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9271 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
9272 gen_addr_add(ctx, addr, addr, 2);
9273 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9274 tcg_gen_shli_tl(t0, t0, 32);
9275 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9276 gen_addr_add(ctx, addr, addr, 2);
9277 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9278 tcg_gen_shli_tl(t0, t0, 16);
9279 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9280 gen_addr_add(ctx, addr, addr, 2);
9281 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9282 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 9283#else
76db3ba4 9284 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9285 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9286 gen_addr_add(ctx, addr, addr, 2);
9287 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9288 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9289 gen_addr_add(ctx, addr, addr, 2);
9290 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9291 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9292 gen_addr_add(ctx, addr, addr, 2);
9293 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9294 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 9295#endif
6a6ae23f 9296 tcg_temp_free(t0);
0487d6a8
JM
9297}
9298
636aa200 9299static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9300{
9301 TCGv t0 = tcg_temp_new();
76db3ba4 9302 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9303#if defined(TARGET_PPC64)
9304 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9305 tcg_gen_shli_tl(t0, t0, 16);
9306 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9307#else
9308 tcg_gen_shli_tl(t0, t0, 16);
9309 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9310 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9311#endif
9312 tcg_temp_free(t0);
0487d6a8
JM
9313}
9314
636aa200 9315static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9316{
9317 TCGv t0 = tcg_temp_new();
76db3ba4 9318 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9319#if defined(TARGET_PPC64)
9320 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9321 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9322#else
9323 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9324 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9325#endif
9326 tcg_temp_free(t0);
0487d6a8
JM
9327}
9328
636aa200 9329static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9330{
9331 TCGv t0 = tcg_temp_new();
76db3ba4 9332 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9333#if defined(TARGET_PPC64)
9334 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9335 tcg_gen_ext32u_tl(t0, t0);
9336 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9337#else
9338 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9339 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9340#endif
9341 tcg_temp_free(t0);
9342}
9343
636aa200 9344static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9345{
9346 TCGv t0 = tcg_temp_new();
9347#if defined(TARGET_PPC64)
76db3ba4 9348 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9349 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
9350 gen_addr_add(ctx, addr, addr, 2);
9351 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9352 tcg_gen_shli_tl(t0, t0, 16);
9353 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9354#else
76db3ba4 9355 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9356 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9357 gen_addr_add(ctx, addr, addr, 2);
9358 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9359 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9360#endif
9361 tcg_temp_free(t0);
9362}
9363
636aa200 9364static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9365{
9366#if defined(TARGET_PPC64)
9367 TCGv t0 = tcg_temp_new();
76db3ba4
AJ
9368 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9369 gen_addr_add(ctx, addr, addr, 2);
9370 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9371 tcg_gen_shli_tl(t0, t0, 32);
9372 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9373 tcg_temp_free(t0);
9374#else
76db3ba4
AJ
9375 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9376 gen_addr_add(ctx, addr, addr, 2);
9377 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9378#endif
9379}
9380
636aa200 9381static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9382{
9383#if defined(TARGET_PPC64)
9384 TCGv t0 = tcg_temp_new();
76db3ba4 9385 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f 9386 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9387 gen_addr_add(ctx, addr, addr, 2);
9388 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9389 tcg_gen_shli_tl(t0, t0, 32);
9390 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9391 tcg_temp_free(t0);
9392#else
76db3ba4
AJ
9393 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9394 gen_addr_add(ctx, addr, addr, 2);
9395 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9396#endif
9397}
9398
636aa200 9399static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9400{
9401 TCGv t0 = tcg_temp_new();
76db3ba4 9402 gen_qemu_ld32u(ctx, t0, addr);
0487d6a8 9403#if defined(TARGET_PPC64)
6a6ae23f
AJ
9404 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9405 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9406#else
9407 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9408 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9409#endif
9410 tcg_temp_free(t0);
9411}
9412
636aa200 9413static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9414{
9415 TCGv t0 = tcg_temp_new();
9416#if defined(TARGET_PPC64)
76db3ba4 9417 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9418 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9419 tcg_gen_shli_tl(t0, t0, 32);
9420 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9421 gen_addr_add(ctx, addr, addr, 2);
9422 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9423 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9424 tcg_gen_shli_tl(t0, t0, 16);
9425 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9426#else
76db3ba4 9427 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9428 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9429 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9430 gen_addr_add(ctx, addr, addr, 2);
9431 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9432 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9433 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
0487d6a8 9434#endif
6a6ae23f
AJ
9435 tcg_temp_free(t0);
9436}
9437
636aa200 9438static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9439{
9440#if defined(TARGET_PPC64)
76db3ba4 9441 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
0487d6a8 9442#else
6a6ae23f
AJ
9443 TCGv_i64 t0 = tcg_temp_new_i64();
9444 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
76db3ba4 9445 gen_qemu_st64(ctx, t0, addr);
6a6ae23f
AJ
9446 tcg_temp_free_i64(t0);
9447#endif
9448}
9449
636aa200 9450static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 9451{
0487d6a8 9452#if defined(TARGET_PPC64)
6a6ae23f
AJ
9453 TCGv t0 = tcg_temp_new();
9454 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9455 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
9456 tcg_temp_free(t0);
9457#else
76db3ba4 9458 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9459#endif
76db3ba4
AJ
9460 gen_addr_add(ctx, addr, addr, 4);
9461 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9462}
9463
636aa200 9464static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9465{
9466 TCGv t0 = tcg_temp_new();
9467#if defined(TARGET_PPC64)
9468 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
9469#else
9470 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9471#endif
76db3ba4
AJ
9472 gen_qemu_st16(ctx, t0, addr);
9473 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f
AJ
9474#if defined(TARGET_PPC64)
9475 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9476 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9477#else
76db3ba4 9478 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9479#endif
76db3ba4 9480 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9481 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9482 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9483 tcg_temp_free(t0);
76db3ba4
AJ
9484 gen_addr_add(ctx, addr, addr, 2);
9485 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9486}
9487
636aa200 9488static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9489{
9490 TCGv t0 = tcg_temp_new();
9491#if defined(TARGET_PPC64)
9492 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
9493#else
9494 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9495#endif
76db3ba4
AJ
9496 gen_qemu_st16(ctx, t0, addr);
9497 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9498 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9499 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9500 tcg_temp_free(t0);
9501}
9502
636aa200 9503static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9504{
9505#if defined(TARGET_PPC64)
9506 TCGv t0 = tcg_temp_new();
9507 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9508 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9509 tcg_temp_free(t0);
9510#else
76db3ba4 9511 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9512#endif
76db3ba4
AJ
9513 gen_addr_add(ctx, addr, addr, 2);
9514 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9515}
9516
636aa200 9517static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9518{
9519#if defined(TARGET_PPC64)
9520 TCGv t0 = tcg_temp_new();
9521 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9522 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
9523 tcg_temp_free(t0);
9524#else
76db3ba4 9525 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9526#endif
9527}
9528
636aa200 9529static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 9530{
76db3ba4 9531 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9532}
9533
9534#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 9535static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
9536{ \
9537 TCGv t0; \
9538 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9539 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
9540 return; \
9541 } \
76db3ba4 9542 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
9543 t0 = tcg_temp_new(); \
9544 if (Rc(ctx->opcode)) { \
76db3ba4 9545 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 9546 } else { \
76db3ba4 9547 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
9548 } \
9549 gen_op_##name(ctx, t0); \
9550 tcg_temp_free(t0); \
9551}
9552
9553GEN_SPEOP_LDST(evldd, 0x00, 3);
9554GEN_SPEOP_LDST(evldw, 0x01, 3);
9555GEN_SPEOP_LDST(evldh, 0x02, 3);
9556GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9557GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9558GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9559GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9560GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9561GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9562GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9563GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9564
9565GEN_SPEOP_LDST(evstdd, 0x10, 3);
9566GEN_SPEOP_LDST(evstdw, 0x11, 3);
9567GEN_SPEOP_LDST(evstdh, 0x12, 3);
9568GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9569GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9570GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9571GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
9572
9573/* Multiply and add - TODO */
9574#if 0
70560da7
FC
9575GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9576GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9577GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9578GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9579GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9580GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9581GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9582GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9583GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9584GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9585GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9586GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9587
9588GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9589GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9590GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9591GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9592GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9593GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9594GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9595GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9596GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9597GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9598GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9599GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9600
9601GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9602GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9603GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9604GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9605GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9606
9607GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9608GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9609GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9610GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9611GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9612GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9613GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9614GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9615GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9616GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9617GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9618GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9619
9620GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9621GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9622GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9623GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9624
9625GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9626GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9627GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9628GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9629GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9630GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9631GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9632GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9633GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9634GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9635GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9636GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9637
9638GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9639GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9640GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9641GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9642GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
9643#endif
9644
9645/*** SPE floating-point extension ***/
1c97856d
AJ
9646#if defined(TARGET_PPC64)
9647#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9648static inline void gen_##name(DisasContext *ctx) \
0487d6a8 9649{ \
1c97856d
AJ
9650 TCGv_i32 t0; \
9651 TCGv t1; \
9652 t0 = tcg_temp_new_i32(); \
9653 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9654 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9655 t1 = tcg_temp_new(); \
9656 tcg_gen_extu_i32_tl(t1, t0); \
9657 tcg_temp_free_i32(t0); \
9658 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9659 0xFFFFFFFF00000000ULL); \
9660 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9661 tcg_temp_free(t1); \
0487d6a8 9662}
1c97856d 9663#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9664static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9665{ \
9666 TCGv_i32 t0; \
9667 TCGv t1; \
9668 t0 = tcg_temp_new_i32(); \
8e703949 9669 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9670 t1 = tcg_temp_new(); \
9671 tcg_gen_extu_i32_tl(t1, t0); \
9672 tcg_temp_free_i32(t0); \
9673 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9674 0xFFFFFFFF00000000ULL); \
9675 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9676 tcg_temp_free(t1); \
9677}
9678#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9679static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9680{ \
9681 TCGv_i32 t0 = tcg_temp_new_i32(); \
9682 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9683 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9684 tcg_temp_free_i32(t0); \
9685}
9686#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9687static inline void gen_##name(DisasContext *ctx) \
1c97856d 9688{ \
8e703949
BS
9689 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9690 cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9691}
9692#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9693static inline void gen_##name(DisasContext *ctx) \
57951c27 9694{ \
1c97856d
AJ
9695 TCGv_i32 t0, t1; \
9696 TCGv_i64 t2; \
57951c27 9697 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9698 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9699 return; \
9700 } \
1c97856d
AJ
9701 t0 = tcg_temp_new_i32(); \
9702 t1 = tcg_temp_new_i32(); \
9703 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9704 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9705 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9706 tcg_temp_free_i32(t1); \
9707 t2 = tcg_temp_new(); \
9708 tcg_gen_extu_i32_tl(t2, t0); \
9709 tcg_temp_free_i32(t0); \
9710 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9711 0xFFFFFFFF00000000ULL); \
9712 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
9713 tcg_temp_free(t2); \
57951c27 9714}
1c97856d 9715#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9716static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
9717{ \
9718 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9719 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9720 return; \
9721 } \
8e703949
BS
9722 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9723 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
57951c27 9724}
1c97856d 9725#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9726static inline void gen_##name(DisasContext *ctx) \
57951c27 9727{ \
1c97856d 9728 TCGv_i32 t0, t1; \
57951c27 9729 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9730 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9731 return; \
9732 } \
1c97856d
AJ
9733 t0 = tcg_temp_new_i32(); \
9734 t1 = tcg_temp_new_i32(); \
9735 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9736 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9737 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9738 tcg_temp_free_i32(t0); \
9739 tcg_temp_free_i32(t1); \
9740}
9741#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9742static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9743{ \
9744 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9745 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9746 return; \
9747 } \
8e703949 9748 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9749 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9750}
9751#else
9752#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9753static inline void gen_##name(DisasContext *ctx) \
1c97856d 9754{ \
8e703949
BS
9755 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9756 cpu_gpr[rB(ctx->opcode)]); \
57951c27 9757}
1c97856d 9758#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9759static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9760{ \
9761 TCGv_i64 t0 = tcg_temp_new_i64(); \
9762 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9763 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9764 tcg_temp_free_i64(t0); \
9765}
9766#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9767static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9768{ \
9769 TCGv_i64 t0 = tcg_temp_new_i64(); \
8e703949 9770 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9771 gen_store_gpr64(rD(ctx->opcode), t0); \
9772 tcg_temp_free_i64(t0); \
9773}
9774#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9775static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9776{ \
9777 TCGv_i64 t0 = tcg_temp_new_i64(); \
9778 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9779 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9780 gen_store_gpr64(rD(ctx->opcode), t0); \
9781 tcg_temp_free_i64(t0); \
9782}
9783#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9784static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9785{ \
9786 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9787 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9788 return; \
9789 } \
8e703949 9790 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9791 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9792}
9793#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9794static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9795{ \
9796 TCGv_i64 t0, t1; \
9797 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9798 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9799 return; \
9800 } \
9801 t0 = tcg_temp_new_i64(); \
9802 t1 = tcg_temp_new_i64(); \
9803 gen_load_gpr64(t0, rA(ctx->opcode)); \
9804 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9805 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9806 gen_store_gpr64(rD(ctx->opcode), t0); \
9807 tcg_temp_free_i64(t0); \
9808 tcg_temp_free_i64(t1); \
9809}
9810#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9811static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9812{ \
9813 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9814 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9815 return; \
9816 } \
8e703949 9817 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9818 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9819}
9820#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9821static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9822{ \
9823 TCGv_i64 t0, t1; \
9824 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9825 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9826 return; \
9827 } \
9828 t0 = tcg_temp_new_i64(); \
9829 t1 = tcg_temp_new_i64(); \
9830 gen_load_gpr64(t0, rA(ctx->opcode)); \
9831 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9832 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9833 tcg_temp_free_i64(t0); \
9834 tcg_temp_free_i64(t1); \
9835}
9836#endif
57951c27 9837
0487d6a8
JM
9838/* Single precision floating-point vectors operations */
9839/* Arithmetic */
1c97856d
AJ
9840GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9841GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9842GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9843GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9844static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9845{
9846 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9847 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9848 return;
9849 }
9850#if defined(TARGET_PPC64)
6d5c34fa 9851 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
1c97856d 9852#else
6d5c34fa
MP
9853 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
9854 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9855#endif
9856}
636aa200 9857static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9858{
9859 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9860 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9861 return;
9862 }
9863#if defined(TARGET_PPC64)
6d5c34fa 9864 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9865#else
6d5c34fa
MP
9866 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9867 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9868#endif
9869}
636aa200 9870static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9871{
9872 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9873 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9874 return;
9875 }
9876#if defined(TARGET_PPC64)
6d5c34fa 9877 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9878#else
6d5c34fa
MP
9879 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9880 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9881#endif
9882}
9883
0487d6a8 9884/* Conversion */
1c97856d
AJ
9885GEN_SPEFPUOP_CONV_64_64(evfscfui);
9886GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9887GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9888GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9889GEN_SPEFPUOP_CONV_64_64(evfsctui);
9890GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9891GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9892GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9893GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9894GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9895
0487d6a8 9896/* Comparison */
1c97856d
AJ
9897GEN_SPEFPUOP_COMP_64(evfscmpgt);
9898GEN_SPEFPUOP_COMP_64(evfscmplt);
9899GEN_SPEFPUOP_COMP_64(evfscmpeq);
9900GEN_SPEFPUOP_COMP_64(evfststgt);
9901GEN_SPEFPUOP_COMP_64(evfststlt);
9902GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9903
9904/* Opcodes definitions */
70560da7
FC
9905GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9906GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9907GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9908GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9909GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9910GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9911GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9912GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9913GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9914GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9915GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9916GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9917GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9918GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9919
9920/* Single precision floating-point operations */
9921/* Arithmetic */
1c97856d
AJ
9922GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9923GEN_SPEFPUOP_ARITH2_32_32(efssub);
9924GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9925GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9926static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9927{
9928 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9929 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9930 return;
9931 }
6d5c34fa 9932 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9933}
636aa200 9934static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9935{
9936 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9937 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9938 return;
9939 }
6d5c34fa 9940 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9941}
636aa200 9942static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9943{
9944 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9945 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9946 return;
9947 }
6d5c34fa 9948 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9949}
9950
0487d6a8 9951/* Conversion */
1c97856d
AJ
9952GEN_SPEFPUOP_CONV_32_32(efscfui);
9953GEN_SPEFPUOP_CONV_32_32(efscfsi);
9954GEN_SPEFPUOP_CONV_32_32(efscfuf);
9955GEN_SPEFPUOP_CONV_32_32(efscfsf);
9956GEN_SPEFPUOP_CONV_32_32(efsctui);
9957GEN_SPEFPUOP_CONV_32_32(efsctsi);
9958GEN_SPEFPUOP_CONV_32_32(efsctuf);
9959GEN_SPEFPUOP_CONV_32_32(efsctsf);
9960GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9961GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9962GEN_SPEFPUOP_CONV_32_64(efscfd);
9963
0487d6a8 9964/* Comparison */
1c97856d
AJ
9965GEN_SPEFPUOP_COMP_32(efscmpgt);
9966GEN_SPEFPUOP_COMP_32(efscmplt);
9967GEN_SPEFPUOP_COMP_32(efscmpeq);
9968GEN_SPEFPUOP_COMP_32(efststgt);
9969GEN_SPEFPUOP_COMP_32(efststlt);
9970GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9971
9972/* Opcodes definitions */
70560da7
FC
9973GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9974GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9975GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9976GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9977GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9978GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9979GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9980GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9981GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9982GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9983GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9984GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9985GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9986GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9987
9988/* Double precision floating-point operations */
9989/* Arithmetic */
1c97856d
AJ
9990GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9991GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9992GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9993GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9994static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9995{
9996 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9997 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9998 return;
9999 }
10000#if defined(TARGET_PPC64)
6d5c34fa 10001 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
1c97856d 10002#else
6d5c34fa
MP
10003 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
10004 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
10005#endif
10006}
636aa200 10007static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
10008{
10009 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 10010 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
10011 return;
10012 }
10013#if defined(TARGET_PPC64)
6d5c34fa 10014 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 10015#else
6d5c34fa
MP
10016 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
10017 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
10018#endif
10019}
636aa200 10020static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
10021{
10022 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 10023 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
10024 return;
10025 }
10026#if defined(TARGET_PPC64)
6d5c34fa 10027 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 10028#else
6d5c34fa
MP
10029 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
10030 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
10031#endif
10032}
10033
0487d6a8 10034/* Conversion */
1c97856d
AJ
10035GEN_SPEFPUOP_CONV_64_32(efdcfui);
10036GEN_SPEFPUOP_CONV_64_32(efdcfsi);
10037GEN_SPEFPUOP_CONV_64_32(efdcfuf);
10038GEN_SPEFPUOP_CONV_64_32(efdcfsf);
10039GEN_SPEFPUOP_CONV_32_64(efdctui);
10040GEN_SPEFPUOP_CONV_32_64(efdctsi);
10041GEN_SPEFPUOP_CONV_32_64(efdctuf);
10042GEN_SPEFPUOP_CONV_32_64(efdctsf);
10043GEN_SPEFPUOP_CONV_32_64(efdctuiz);
10044GEN_SPEFPUOP_CONV_32_64(efdctsiz);
10045GEN_SPEFPUOP_CONV_64_32(efdcfs);
10046GEN_SPEFPUOP_CONV_64_64(efdcfuid);
10047GEN_SPEFPUOP_CONV_64_64(efdcfsid);
10048GEN_SPEFPUOP_CONV_64_64(efdctuidz);
10049GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 10050
0487d6a8 10051/* Comparison */
1c97856d
AJ
10052GEN_SPEFPUOP_COMP_64(efdcmpgt);
10053GEN_SPEFPUOP_COMP_64(efdcmplt);
10054GEN_SPEFPUOP_COMP_64(efdcmpeq);
10055GEN_SPEFPUOP_COMP_64(efdtstgt);
10056GEN_SPEFPUOP_COMP_64(efdtstlt);
10057GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
10058
10059/* Opcodes definitions */
70560da7
FC
10060GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
10061GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10062GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
10063GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
10064GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
10065GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10066GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
10067GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
10068GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10069GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10070GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10071GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
10072GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
10073GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
10074GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
10075GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 10076
c227f099 10077static opcode_t opcodes[] = {
5c55ff99
BS
10078GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
10079GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
10080GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
10081GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
10082GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 10083GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10084GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
10085GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10086GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10087GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10088GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10089GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
10090GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
10091GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
10092GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
10093GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10094#if defined(TARGET_PPC64)
10095GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
10096#endif
10097GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
10098GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
10099GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10100GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10101GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10102GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
10103GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
10104GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
10105GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10106GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10107GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10108GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10109GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 10110GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 10111GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 10112#if defined(TARGET_PPC64)
eaabeef2 10113GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 10114GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 10115GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
86ba37ed 10116GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
5c55ff99
BS
10117#endif
10118GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10119GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10120GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10121GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
10122GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
10123GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
10124GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
10125#if defined(TARGET_PPC64)
10126GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
10127GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
10128GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
10129GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
10130GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
10131#endif
10132GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
10133GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
10134GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
10135GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
10136GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 10137GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 10138GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
10139GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
10140GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 10141GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
097ec5d8
TM
10142GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
10143GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
5c55ff99
BS
10144GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
10145GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
10146GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
10147GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
10148GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
10149GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
10150#if defined(TARGET_PPC64)
10151GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
10152GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
10153GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
10154#endif
10155GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10156GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
10157GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
10158GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
10159GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
10160GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
10161GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
10162GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
5c77a786
TM
10163GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10164GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
f844c817 10165GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
587c51f7
TM
10166GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
10167GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
5c55ff99
BS
10168GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
10169#if defined(TARGET_PPC64)
f844c817 10170GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
9c294d5a 10171GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99 10172GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
27b95bfe 10173GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99
BS
10174#endif
10175GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
10176GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
10177GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10178GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10179GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
10180GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
52a4984d 10181GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
5c55ff99
BS
10182GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
10183GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
10184#if defined(TARGET_PPC64)
10185GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
10186GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
10187#endif
10188GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
10189GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
10190GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
10191#if defined(TARGET_PPC64)
10192GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
10193GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
10194#endif
10195GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
10196GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
10197GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
10198GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
10199GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
10200GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
10201#if defined(TARGET_PPC64)
10202GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
10203#endif
10204GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
10205GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
10206GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
10207GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
10208GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
3f34cf91
CLG
10209GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
10210GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
8e33944f 10211GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
10212GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
10213GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
10214GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
10215GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
10216GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
10217GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
10218GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
10219GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
10220GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
10221#if defined(TARGET_PPC64)
10222GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
10223GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
10224 PPC_SEGMENT_64B),
10225GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
10226GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
10227 PPC_SEGMENT_64B),
efdef95f
DG
10228GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
10229GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
10230GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
10231#endif
10232GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
10233GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
10234GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
10235GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
10236#if defined(TARGET_PPC64)
10237GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
10238GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
10239#endif
10240GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
10241GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
10242GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
10243GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
10244GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
10245GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
10246GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
10247GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
10248GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
10249GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
10250GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
10251GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10252GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
10253GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
10254GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
10255GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
10256GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
10257GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
10258GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
10259GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10260GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
10261GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
10262GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
10263GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
10264GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
10265GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
10266GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
10267GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
10268GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
10269GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
10270GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
10271GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
10272GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
10273GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
10274GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
10275GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
10276GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
10277GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
10278GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
10279GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
10280GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
10281GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
10282GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
10283GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
10284GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
10285GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
10286GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
10287GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
10288GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
10289GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10290GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10291GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
10292GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
10293GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10294GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10295GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
10296GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
10297GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
10298GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
10299GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
10300GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
10301GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
10302GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
10303GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
10304GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
10305GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
10306GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
10307GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
10308GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
10309GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
10310GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 10311GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10312GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
10313GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
10314GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
10315GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
10316GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
10317GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
10318GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
10319GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
10320GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10321 PPC_NONE, PPC2_BOOKE206),
10322GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10323 PPC_NONE, PPC2_BOOKE206),
10324GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10325 PPC_NONE, PPC2_BOOKE206),
10326GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10327 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
10328GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10329 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
10330GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10331 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
10332GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10333 PPC_NONE, PPC2_PRCNTL),
5c55ff99 10334GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 10335GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 10336GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
10337GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
10338 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 10339GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
10340GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10341 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10342GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
10343GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
10344GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
10345GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
5c55ff99
BS
10346GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
10347GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
10348GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
10349GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
10350GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
10351
10352#undef GEN_INT_ARITH_ADD
10353#undef GEN_INT_ARITH_ADD_CONST
10354#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10355GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10356#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10357 add_ca, compute_ca, compute_ov) \
10358GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10359GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
10360GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
10361GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
10362GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
10363GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
10364GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
10365GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
10366GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
10367GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
10368GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
10369
10370#undef GEN_INT_ARITH_DIVW
10371#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10372GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10373GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
10374GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
10375GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
10376GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
a98eb9e9
TM
10377GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10378GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
6a4fda33
TM
10379GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10380GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
5c55ff99
BS
10381
10382#if defined(TARGET_PPC64)
10383#undef GEN_INT_ARITH_DIVD
10384#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10385GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10386GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
10387GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
10388GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
10389GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
10390
98d1eb27
TM
10391GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10392GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
e44259b6
TM
10393GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10394GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
98d1eb27 10395
5c55ff99
BS
10396#undef GEN_INT_ARITH_MUL_HELPER
10397#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10398GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10399GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
10400GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
10401GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
10402#endif
10403
10404#undef GEN_INT_ARITH_SUBF
10405#undef GEN_INT_ARITH_SUBF_CONST
10406#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10407GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10408#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10409 add_ca, compute_ca, compute_ov) \
10410GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10411GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
10412GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
10413GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
10414GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
10415GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
10416GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
10417GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
10418GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
10419GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
10420GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
10421
10422#undef GEN_LOGICAL1
10423#undef GEN_LOGICAL2
10424#define GEN_LOGICAL2(name, tcg_op, opc, type) \
10425GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10426#define GEN_LOGICAL1(name, tcg_op, opc, type) \
10427GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10428GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10429GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10430GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10431GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10432GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10433GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10434GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10435GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10436#if defined(TARGET_PPC64)
10437GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10438#endif
10439
10440#if defined(TARGET_PPC64)
10441#undef GEN_PPC64_R2
10442#undef GEN_PPC64_R4
10443#define GEN_PPC64_R2(name, opc1, opc2) \
10444GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10445GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10446 PPC_64B)
10447#define GEN_PPC64_R4(name, opc1, opc2) \
10448GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10449GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10450 PPC_64B), \
10451GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10452 PPC_64B), \
10453GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10454 PPC_64B)
10455GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10456GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10457GEN_PPC64_R4(rldic, 0x1E, 0x04),
10458GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10459GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10460GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10461#endif
10462
10463#undef _GEN_FLOAT_ACB
10464#undef GEN_FLOAT_ACB
10465#undef _GEN_FLOAT_AB
10466#undef GEN_FLOAT_AB
10467#undef _GEN_FLOAT_AC
10468#undef GEN_FLOAT_AC
10469#undef GEN_FLOAT_B
10470#undef GEN_FLOAT_BS
10471#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10472GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10473#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10474_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10475_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10476#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10477GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10478#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10479_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10480_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10481#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10482GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10483#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10484_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10485_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10486#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10487GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10488#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10489GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10490
10491GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10492GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10493GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10494GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10495GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10496GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10497_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10498GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10499GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10500GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10501GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10502GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
da29cb7b 10503GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
6d41d146 10504GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
5c55ff99 10505GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
fab7fe42 10506GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10507GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
fab7fe42 10508GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10509GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
10510#if defined(TARGET_PPC64)
10511GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
28288b48
TM
10512GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10513GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10514GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10515GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
fab7fe42 10516GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10517GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
fab7fe42 10518GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10519#endif
10520GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10521GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10522GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10523GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
10524
10525#undef GEN_LD
10526#undef GEN_LDU
10527#undef GEN_LDUX
cd6e9320 10528#undef GEN_LDX_E
5c55ff99
BS
10529#undef GEN_LDS
10530#define GEN_LD(name, ldop, opc, type) \
10531GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10532#define GEN_LDU(name, ldop, opc, type) \
10533GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10534#define GEN_LDUX(name, ldop, opc2, opc3, type) \
10535GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10536#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10537GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10538#define GEN_LDS(name, ldop, op, type) \
10539GEN_LD(name, ldop, op | 0x20, type) \
10540GEN_LDU(name, ldop, op | 0x21, type) \
10541GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10542GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10543
10544GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10545GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10546GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10547GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10548#if defined(TARGET_PPC64)
10549GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10550GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10551GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10552GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 10553GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10554#endif
10555GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10556GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10557
10558#undef GEN_ST
10559#undef GEN_STU
10560#undef GEN_STUX
cd6e9320 10561#undef GEN_STX_E
5c55ff99
BS
10562#undef GEN_STS
10563#define GEN_ST(name, stop, opc, type) \
10564GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10565#define GEN_STU(name, stop, opc, type) \
10566GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10567#define GEN_STUX(name, stop, opc2, opc3, type) \
10568GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10569#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10570GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10571#define GEN_STS(name, stop, op, type) \
10572GEN_ST(name, stop, op | 0x20, type) \
10573GEN_STU(name, stop, op | 0x21, type) \
10574GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10575GEN_STX(name, stop, 0x17, op | 0x00, type)
10576
10577GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10578GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10579GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10580#if defined(TARGET_PPC64)
10581GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10582GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 10583GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10584#endif
10585GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10586GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10587
10588#undef GEN_LDF
10589#undef GEN_LDUF
10590#undef GEN_LDUXF
10591#undef GEN_LDXF
10592#undef GEN_LDFS
10593#define GEN_LDF(name, ldop, opc, type) \
10594GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10595#define GEN_LDUF(name, ldop, opc, type) \
10596GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10597#define GEN_LDUXF(name, ldop, opc, type) \
10598GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10599#define GEN_LDXF(name, ldop, opc2, opc3, type) \
10600GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10601#define GEN_LDFS(name, ldop, op, type) \
10602GEN_LDF(name, ldop, op | 0x20, type) \
10603GEN_LDUF(name, ldop, op | 0x21, type) \
10604GEN_LDUXF(name, ldop, op | 0x01, type) \
10605GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10606
10607GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10608GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 10609GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
66c3e328 10610GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
05050ee8
AJ
10611GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10612GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10613
10614#undef GEN_STF
10615#undef GEN_STUF
10616#undef GEN_STUXF
10617#undef GEN_STXF
10618#undef GEN_STFS
10619#define GEN_STF(name, stop, opc, type) \
10620GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10621#define GEN_STUF(name, stop, opc, type) \
10622GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10623#define GEN_STUXF(name, stop, opc, type) \
10624GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10625#define GEN_STXF(name, stop, opc2, opc3, type) \
10626GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10627#define GEN_STFS(name, stop, op, type) \
10628GEN_STF(name, stop, op | 0x20, type) \
10629GEN_STUF(name, stop, op | 0x21, type) \
10630GEN_STUXF(name, stop, op | 0x01, type) \
10631GEN_STXF(name, stop, 0x17, op | 0x00, type)
10632
10633GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10634GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10635GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
10636GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10637GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10638
10639#undef GEN_CRLOGIC
10640#define GEN_CRLOGIC(name, tcg_op, opc) \
10641GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10642GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10643GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10644GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10645GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10646GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10647GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10648GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10649GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10650
10651#undef GEN_MAC_HANDLER
10652#define GEN_MAC_HANDLER(name, opc2, opc3) \
10653GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10654GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10655GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10656GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10657GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10658GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10659GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10660GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10661GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10662GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10663GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10664GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10665GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10666GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10667GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10668GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10669GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10670GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10671GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10672GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10673GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10674GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10675GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10676GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10677GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10678GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10679GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10680GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10681GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10682GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10683GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10684GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10685GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10686GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10687GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10688GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10689GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10690GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10691GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10692GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10693GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10694GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10695GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10696
10697#undef GEN_VR_LDX
10698#undef GEN_VR_STX
10699#undef GEN_VR_LVE
10700#undef GEN_VR_STVE
10701#define GEN_VR_LDX(name, opc2, opc3) \
10702GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10703#define GEN_VR_STX(name, opc2, opc3) \
10704GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10705#define GEN_VR_LVE(name, opc2, opc3) \
10706 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10707#define GEN_VR_STVE(name, opc2, opc3) \
10708 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10709GEN_VR_LDX(lvx, 0x07, 0x03),
10710GEN_VR_LDX(lvxl, 0x07, 0x0B),
10711GEN_VR_LVE(bx, 0x07, 0x00),
10712GEN_VR_LVE(hx, 0x07, 0x01),
10713GEN_VR_LVE(wx, 0x07, 0x02),
10714GEN_VR_STX(svx, 0x07, 0x07),
10715GEN_VR_STX(svxl, 0x07, 0x0F),
10716GEN_VR_STVE(bx, 0x07, 0x04),
10717GEN_VR_STVE(hx, 0x07, 0x05),
10718GEN_VR_STVE(wx, 0x07, 0x06),
10719
10720#undef GEN_VX_LOGICAL
10721#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10722GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
111c5f54
TM
10723
10724#undef GEN_VX_LOGICAL_207
10725#define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10726GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10727
5c55ff99
BS
10728GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10729GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10730GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10731GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10732GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
111c5f54
TM
10733GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10734GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10735GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
5c55ff99
BS
10736
10737#undef GEN_VXFORM
10738#define GEN_VXFORM(name, opc2, opc3) \
10739GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
50f5fc0c
TM
10740
10741#undef GEN_VXFORM_207
10742#define GEN_VXFORM_207(name, opc2, opc3) \
10743GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10744
5dffff5a
TM
10745#undef GEN_VXFORM_DUAL
10746#define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10747GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10748
a737d3eb
TM
10749#undef GEN_VXRFORM_DUAL
10750#define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10751GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10752GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10753
5c55ff99
BS
10754GEN_VXFORM(vaddubm, 0, 0),
10755GEN_VXFORM(vadduhm, 0, 1),
10756GEN_VXFORM(vadduwm, 0, 2),
56eabc75 10757GEN_VXFORM_207(vaddudm, 0, 3),
e8f7b27b
TM
10758GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10759GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
5c55ff99 10760GEN_VXFORM(vsubuwm, 0, 18),
56eabc75 10761GEN_VXFORM_207(vsubudm, 0, 19),
5c55ff99
BS
10762GEN_VXFORM(vmaxub, 1, 0),
10763GEN_VXFORM(vmaxuh, 1, 1),
10764GEN_VXFORM(vmaxuw, 1, 2),
8203e31b 10765GEN_VXFORM_207(vmaxud, 1, 3),
5c55ff99
BS
10766GEN_VXFORM(vmaxsb, 1, 4),
10767GEN_VXFORM(vmaxsh, 1, 5),
10768GEN_VXFORM(vmaxsw, 1, 6),
8203e31b 10769GEN_VXFORM_207(vmaxsd, 1, 7),
5c55ff99
BS
10770GEN_VXFORM(vminub, 1, 8),
10771GEN_VXFORM(vminuh, 1, 9),
10772GEN_VXFORM(vminuw, 1, 10),
8203e31b 10773GEN_VXFORM_207(vminud, 1, 11),
5c55ff99
BS
10774GEN_VXFORM(vminsb, 1, 12),
10775GEN_VXFORM(vminsh, 1, 13),
10776GEN_VXFORM(vminsw, 1, 14),
8203e31b 10777GEN_VXFORM_207(vminsd, 1, 15),
5c55ff99
BS
10778GEN_VXFORM(vavgub, 1, 16),
10779GEN_VXFORM(vavguh, 1, 17),
10780GEN_VXFORM(vavguw, 1, 18),
10781GEN_VXFORM(vavgsb, 1, 20),
10782GEN_VXFORM(vavgsh, 1, 21),
10783GEN_VXFORM(vavgsw, 1, 22),
10784GEN_VXFORM(vmrghb, 6, 0),
10785GEN_VXFORM(vmrghh, 6, 1),
10786GEN_VXFORM(vmrghw, 6, 2),
10787GEN_VXFORM(vmrglb, 6, 4),
10788GEN_VXFORM(vmrglh, 6, 5),
10789GEN_VXFORM(vmrglw, 6, 6),
e0ffe77f
TM
10790GEN_VXFORM_207(vmrgew, 6, 30),
10791GEN_VXFORM_207(vmrgow, 6, 26),
5c55ff99
BS
10792GEN_VXFORM(vmuloub, 4, 0),
10793GEN_VXFORM(vmulouh, 4, 1),
953f0f58 10794GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10795GEN_VXFORM(vmulosb, 4, 4),
10796GEN_VXFORM(vmulosh, 4, 5),
63be0936 10797GEN_VXFORM_207(vmulosw, 4, 6),
5c55ff99
BS
10798GEN_VXFORM(vmuleub, 4, 8),
10799GEN_VXFORM(vmuleuh, 4, 9),
63be0936 10800GEN_VXFORM_207(vmuleuw, 4, 10),
5c55ff99
BS
10801GEN_VXFORM(vmulesb, 4, 12),
10802GEN_VXFORM(vmulesh, 4, 13),
63be0936 10803GEN_VXFORM_207(vmulesw, 4, 14),
5c55ff99
BS
10804GEN_VXFORM(vslb, 2, 4),
10805GEN_VXFORM(vslh, 2, 5),
10806GEN_VXFORM(vslw, 2, 6),
2fdf78e6 10807GEN_VXFORM_207(vsld, 2, 23),
5c55ff99
BS
10808GEN_VXFORM(vsrb, 2, 8),
10809GEN_VXFORM(vsrh, 2, 9),
10810GEN_VXFORM(vsrw, 2, 10),
2fdf78e6 10811GEN_VXFORM_207(vsrd, 2, 27),
5c55ff99
BS
10812GEN_VXFORM(vsrab, 2, 12),
10813GEN_VXFORM(vsrah, 2, 13),
10814GEN_VXFORM(vsraw, 2, 14),
2fdf78e6 10815GEN_VXFORM_207(vsrad, 2, 15),
5c55ff99
BS
10816GEN_VXFORM(vslo, 6, 16),
10817GEN_VXFORM(vsro, 6, 17),
10818GEN_VXFORM(vaddcuw, 0, 6),
10819GEN_VXFORM(vsubcuw, 0, 22),
10820GEN_VXFORM(vaddubs, 0, 8),
10821GEN_VXFORM(vadduhs, 0, 9),
10822GEN_VXFORM(vadduws, 0, 10),
10823GEN_VXFORM(vaddsbs, 0, 12),
10824GEN_VXFORM(vaddshs, 0, 13),
10825GEN_VXFORM(vaddsws, 0, 14),
e8f7b27b
TM
10826GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10827GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10828GEN_VXFORM(vsubuws, 0, 26),
10829GEN_VXFORM(vsubsbs, 0, 28),
10830GEN_VXFORM(vsubshs, 0, 29),
10831GEN_VXFORM(vsubsws, 0, 30),
b41da4eb
TM
10832GEN_VXFORM_207(vadduqm, 0, 4),
10833GEN_VXFORM_207(vaddcuq, 0, 5),
10834GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10835GEN_VXFORM_207(vsubuqm, 0, 20),
10836GEN_VXFORM_207(vsubcuq, 0, 21),
10837GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
5c55ff99
BS
10838GEN_VXFORM(vrlb, 2, 0),
10839GEN_VXFORM(vrlh, 2, 1),
10840GEN_VXFORM(vrlw, 2, 2),
2fdf78e6 10841GEN_VXFORM_207(vrld, 2, 3),
5c55ff99
BS
10842GEN_VXFORM(vsl, 2, 7),
10843GEN_VXFORM(vsr, 2, 11),
10844GEN_VXFORM(vpkuhum, 7, 0),
10845GEN_VXFORM(vpkuwum, 7, 1),
024215b2 10846GEN_VXFORM_207(vpkudum, 7, 17),
5c55ff99
BS
10847GEN_VXFORM(vpkuhus, 7, 2),
10848GEN_VXFORM(vpkuwus, 7, 3),
024215b2 10849GEN_VXFORM_207(vpkudus, 7, 19),
5c55ff99
BS
10850GEN_VXFORM(vpkshus, 7, 4),
10851GEN_VXFORM(vpkswus, 7, 5),
024215b2 10852GEN_VXFORM_207(vpksdus, 7, 21),
5c55ff99
BS
10853GEN_VXFORM(vpkshss, 7, 6),
10854GEN_VXFORM(vpkswss, 7, 7),
024215b2 10855GEN_VXFORM_207(vpksdss, 7, 23),
5c55ff99
BS
10856GEN_VXFORM(vpkpx, 7, 12),
10857GEN_VXFORM(vsum4ubs, 4, 24),
10858GEN_VXFORM(vsum4sbs, 4, 28),
10859GEN_VXFORM(vsum4shs, 4, 25),
10860GEN_VXFORM(vsum2sws, 4, 26),
10861GEN_VXFORM(vsumsws, 4, 30),
10862GEN_VXFORM(vaddfp, 5, 0),
10863GEN_VXFORM(vsubfp, 5, 1),
10864GEN_VXFORM(vmaxfp, 5, 16),
10865GEN_VXFORM(vminfp, 5, 17),
10866
10867#undef GEN_VXRFORM1
10868#undef GEN_VXRFORM
10869#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10870 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10871#define GEN_VXRFORM(name, opc2, opc3) \
10872 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10873 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10874GEN_VXRFORM(vcmpequb, 3, 0)
10875GEN_VXRFORM(vcmpequh, 3, 1)
10876GEN_VXRFORM(vcmpequw, 3, 2)
10877GEN_VXRFORM(vcmpgtsb, 3, 12)
10878GEN_VXRFORM(vcmpgtsh, 3, 13)
10879GEN_VXRFORM(vcmpgtsw, 3, 14)
10880GEN_VXRFORM(vcmpgtub, 3, 8)
10881GEN_VXRFORM(vcmpgtuh, 3, 9)
10882GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 10883GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
5c55ff99 10884GEN_VXRFORM(vcmpgefp, 3, 7)
6f3dab41
TM
10885GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10886GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
5c55ff99
BS
10887
10888#undef GEN_VXFORM_SIMM
10889#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10890 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10891GEN_VXFORM_SIMM(vspltisb, 6, 12),
10892GEN_VXFORM_SIMM(vspltish, 6, 13),
10893GEN_VXFORM_SIMM(vspltisw, 6, 14),
10894
10895#undef GEN_VXFORM_NOA
10896#define GEN_VXFORM_NOA(name, opc2, opc3) \
10897 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10898GEN_VXFORM_NOA(vupkhsb, 7, 8),
10899GEN_VXFORM_NOA(vupkhsh, 7, 9),
4430e076 10900GEN_VXFORM_207(vupkhsw, 7, 25),
5c55ff99
BS
10901GEN_VXFORM_NOA(vupklsb, 7, 10),
10902GEN_VXFORM_NOA(vupklsh, 7, 11),
4430e076 10903GEN_VXFORM_207(vupklsw, 7, 27),
5c55ff99
BS
10904GEN_VXFORM_NOA(vupkhpx, 7, 13),
10905GEN_VXFORM_NOA(vupklpx, 7, 15),
10906GEN_VXFORM_NOA(vrefp, 5, 4),
10907GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10908GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99
BS
10909GEN_VXFORM_NOA(vlogefp, 5, 7),
10910GEN_VXFORM_NOA(vrfim, 5, 8),
10911GEN_VXFORM_NOA(vrfin, 5, 9),
10912GEN_VXFORM_NOA(vrfip, 5, 10),
10913GEN_VXFORM_NOA(vrfiz, 5, 11),
10914
10915#undef GEN_VXFORM_UIMM
10916#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10917 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10918GEN_VXFORM_UIMM(vspltb, 6, 8),
10919GEN_VXFORM_UIMM(vsplth, 6, 9),
10920GEN_VXFORM_UIMM(vspltw, 6, 10),
10921GEN_VXFORM_UIMM(vcfux, 5, 12),
10922GEN_VXFORM_UIMM(vcfsx, 5, 13),
10923GEN_VXFORM_UIMM(vctuxs, 5, 14),
10924GEN_VXFORM_UIMM(vctsxs, 5, 15),
10925
10926#undef GEN_VAFORM_PAIRED
10927#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10928 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10929GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10930GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10931GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10932GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10933GEN_VAFORM_PAIRED(vsel, vperm, 21),
10934GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10935
e13500b3
TM
10936GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10937GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10938GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10939GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10940
4d82038e 10941GEN_VXFORM_207(vbpermq, 6, 21),
f1064f61 10942GEN_VXFORM_207(vgbbd, 6, 20),
b8476fc7
TM
10943GEN_VXFORM_207(vpmsumb, 4, 16),
10944GEN_VXFORM_207(vpmsumh, 4, 17),
10945GEN_VXFORM_207(vpmsumw, 4, 18),
10946GEN_VXFORM_207(vpmsumd, 4, 19),
f293f04a 10947
557d52fa
TM
10948GEN_VXFORM_207(vsbox, 4, 23),
10949
10950GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10951GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10952
57354f8f
TM
10953GEN_VXFORM_207(vshasigmaw, 1, 26),
10954GEN_VXFORM_207(vshasigmad, 1, 27),
10955
ac174549
TM
10956GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10957
fa1832d7 10958GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10959GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10960GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10961GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10962GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10963GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10964GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10965
9231ba9e 10966GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10967GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10968GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10969GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10970GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10971
f5c0f7f9
TM
10972GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10973GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10974GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10975#if defined(TARGET_PPC64)
10976GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10977GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10978#endif
10979
df020ce0
TM
10980#undef GEN_XX2FORM
10981#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10982GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10983GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10984
10985#undef GEN_XX3FORM
10986#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10987GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10988GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10989GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10990GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10991
354a6dec
TM
10992#undef GEN_XX3_RC_FORM
10993#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10994GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10995GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10996GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10997GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10998GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10999GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
11000GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
11001GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
11002
cd73f2c9
TM
11003#undef GEN_XX3FORM_DM
11004#define GEN_XX3FORM_DM(name, opc2, opc3) \
11005GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11006GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11007GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11008GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11009GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11010GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11011GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11012GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11013GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11014GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11015GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11016GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11017GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11018GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11019GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11020GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
11021
df020ce0
TM
11022GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
11023GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
11024GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
11025GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
11026
be574920
TM
11027GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
11028GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
11029GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
11030GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
11031GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
11032GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
11033GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
11034GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 11035
ee6e02c0
TM
11036GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
11037GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 11038GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 11039GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 11040GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 11041GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 11042GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 11043GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 11044GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
11045GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
11046GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
11047GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
11048GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
11049GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
11050GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
11051GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
11052GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
4f17e9c7
TM
11053GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
11054GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
11055GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
11056GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568 11057GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
7ee19fb9 11058GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
ed8ac568 11059GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
7ee19fb9 11060GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
5177d2ca
TM
11061GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
11062GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
11063GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
11064GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
11065GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
11066GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
11067GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
11068GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
11069GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
11070GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
11071GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 11072
3fd0aadf
TM
11073GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
11074GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 11075GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 11076GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 11077GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
3d1140bf 11078GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
cea4e574 11079GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
968e76bc 11080GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
f53f81e0
TM
11081GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
11082GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
11083GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
11084GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
11085GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
11086GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
11087GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
11088GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
74698350
TM
11089GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
11090GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
3fd0aadf 11091
ee6e02c0
TM
11092GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
11093GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 11094GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 11095GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 11096GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 11097GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 11098GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 11099GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 11100GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
11101GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
11102GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
11103GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
11104GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
11105GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
11106GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
11107GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
11108GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
11109GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
11110GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
11111GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
11112GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
11113GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 11114GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
11115GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
11116GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
11117GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
11118GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
11119GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
11120GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
11121GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
11122GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
11123GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
11124GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
11125GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
11126GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
11127GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
11128
11129GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
11130GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 11131GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 11132GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 11133GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 11134GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 11135GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 11136GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 11137GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
11138GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
11139GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
11140GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
11141GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
11142GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
11143GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
11144GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
11145GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
11146GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
11147GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
11148GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
11149GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
11150GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 11151GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
11152GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
11153GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
11154GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
11155GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
11156GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
11157GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
11158GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
11159GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
11160GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
11161GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
11162GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
11163GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
11164GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 11165
79ca8a6a
TM
11166#undef VSX_LOGICAL
11167#define VSX_LOGICAL(name, opc2, opc3, fl2) \
11168GEN_XX3FORM(name, opc2, opc3, fl2)
11169
11170VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
11171VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
11172VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
11173VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
11174VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
67a33f37
TM
11175VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
11176VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
11177VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
ce577d2e
TM
11178GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
11179GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 11180GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 11181GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 11182
551e3ef7
TM
11183#define GEN_XXSEL_ROW(opc3) \
11184GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
11185GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
11186GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
11187GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
11188GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
11189GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
11190GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
11191GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
11192
11193GEN_XXSEL_ROW(0x00)
11194GEN_XXSEL_ROW(0x01)
11195GEN_XXSEL_ROW(0x02)
11196GEN_XXSEL_ROW(0x03)
11197GEN_XXSEL_ROW(0x04)
11198GEN_XXSEL_ROW(0x05)
11199GEN_XXSEL_ROW(0x06)
11200GEN_XXSEL_ROW(0x07)
11201GEN_XXSEL_ROW(0x08)
11202GEN_XXSEL_ROW(0x09)
11203GEN_XXSEL_ROW(0x0A)
11204GEN_XXSEL_ROW(0x0B)
11205GEN_XXSEL_ROW(0x0C)
11206GEN_XXSEL_ROW(0x0D)
11207GEN_XXSEL_ROW(0x0E)
11208GEN_XXSEL_ROW(0x0F)
11209GEN_XXSEL_ROW(0x10)
11210GEN_XXSEL_ROW(0x11)
11211GEN_XXSEL_ROW(0x12)
11212GEN_XXSEL_ROW(0x13)
11213GEN_XXSEL_ROW(0x14)
11214GEN_XXSEL_ROW(0x15)
11215GEN_XXSEL_ROW(0x16)
11216GEN_XXSEL_ROW(0x17)
11217GEN_XXSEL_ROW(0x18)
11218GEN_XXSEL_ROW(0x19)
11219GEN_XXSEL_ROW(0x1A)
11220GEN_XXSEL_ROW(0x1B)
11221GEN_XXSEL_ROW(0x1C)
11222GEN_XXSEL_ROW(0x1D)
11223GEN_XXSEL_ROW(0x1E)
11224GEN_XXSEL_ROW(0x1F)
11225
cd73f2c9
TM
11226GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
11227
275e35c6
TM
11228#undef GEN_DFP_T_A_B_Rc
11229#undef GEN_DFP_BF_A_B
11230#undef GEN_DFP_BF_A_DCM
11231#undef GEN_DFP_T_B_U32_U32_Rc
11232#undef GEN_DFP_T_A_B_I32_Rc
11233#undef GEN_DFP_T_B_Rc
11234#undef GEN_DFP_T_FPR_I32_Rc
11235
11236#define _GEN_DFP_LONG(name, op1, op2, mask) \
11237GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
11238
11239#define _GEN_DFP_LONGx2(name, op1, op2, mask) \
11240GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11241GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
11242
11243#define _GEN_DFP_LONGx4(name, op1, op2, mask) \
11244GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11245GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
11246GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
11247GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
11248
11249#define _GEN_DFP_QUAD(name, op1, op2, mask) \
11250GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
11251
11252#define _GEN_DFP_QUADx2(name, op1, op2, mask) \
11253GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11254GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
11255
11256#define _GEN_DFP_QUADx4(name, op1, op2, mask) \
11257GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11258GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
11259GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
11260GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
11261
11262#define GEN_DFP_T_A_B_Rc(name, op1, op2) \
11263_GEN_DFP_LONG(name, op1, op2, 0x00000000)
11264
11265#define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
11266_GEN_DFP_QUAD(name, op1, op2, 0x00210800)
11267
11268#define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
11269_GEN_DFP_QUAD(name, op1, op2, 0x00200800)
11270
11271#define GEN_DFP_T_B_Rc(name, op1, op2) \
11272_GEN_DFP_LONG(name, op1, op2, 0x001F0000)
11273
11274#define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
11275_GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
11276
11277#define GEN_DFP_Tp_B_Rc(name, op1, op2) \
11278_GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
11279
11280#define GEN_DFP_T_Bp_Rc(name, op1, op2) \
11281_GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
11282
11283#define GEN_DFP_BF_A_B(name, op1, op2) \
11284_GEN_DFP_LONG(name, op1, op2, 0x00000001)
11285
11286#define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
11287_GEN_DFP_QUAD(name, op1, op2, 0x00610801)
11288
11289#define GEN_DFP_BF_A_Bp(name, op1, op2) \
11290_GEN_DFP_QUAD(name, op1, op2, 0x00600801)
11291
11292#define GEN_DFP_BF_A_DCM(name, op1, op2) \
11293_GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
11294
11295#define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
11296_GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
11297
11298#define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
11299_GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11300
11301#define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
11302_GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
11303
11304#define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
11305_GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
11306
11307#define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
11308_GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11309
11310#define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
11311_GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
11312
11313#define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
11314_GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
11315
11316#define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
11317_GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
11318
11319#define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
11320_GEN_DFP_LONG(name, op1, op2, 0x00070000)
11321
11322#define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
11323_GEN_DFP_QUAD(name, op1, op2, 0x00270800)
11324
11325#define GEN_DFP_S_T_B_Rc(name, op1, op2) \
11326_GEN_DFP_LONG(name, op1, op2, 0x000F0000)
11327
11328#define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
11329_GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
11330
11331#define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
11332_GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
11333
11334#define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
11335_GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
11336
a9d7ba03
TM
11337GEN_DFP_T_A_B_Rc(dadd, 0x02, 0x00),
11338GEN_DFP_Tp_Ap_Bp_Rc(daddq, 0x02, 0x00),
2128f8a5
TM
11339GEN_DFP_T_A_B_Rc(dsub, 0x02, 0x10),
11340GEN_DFP_Tp_Ap_Bp_Rc(dsubq, 0x02, 0x10),
8de6a1cc
TM
11341GEN_DFP_T_A_B_Rc(dmul, 0x02, 0x01),
11342GEN_DFP_Tp_Ap_Bp_Rc(dmulq, 0x02, 0x01),
9024ff40
TM
11343GEN_DFP_T_A_B_Rc(ddiv, 0x02, 0x11),
11344GEN_DFP_Tp_Ap_Bp_Rc(ddivq, 0x02, 0x11),
5833505b
TM
11345GEN_DFP_BF_A_B(dcmpu, 0x02, 0x14),
11346GEN_DFP_BF_Ap_Bp(dcmpuq, 0x02, 0x14),
11347GEN_DFP_BF_A_B(dcmpo, 0x02, 0x04),
11348GEN_DFP_BF_Ap_Bp(dcmpoq, 0x02, 0x04),
e601c1ee
TM
11349GEN_DFP_BF_A_DCM(dtstdc, 0x02, 0x06),
11350GEN_DFP_BF_Ap_DCM(dtstdcq, 0x02, 0x06),
1bf9c0e1
TM
11351GEN_DFP_BF_A_DCM(dtstdg, 0x02, 0x07),
11352GEN_DFP_BF_Ap_DCM(dtstdgq, 0x02, 0x07),
f3d2b0bc
TM
11353GEN_DFP_BF_A_B(dtstex, 0x02, 0x05),
11354GEN_DFP_BF_Ap_Bp(dtstexq, 0x02, 0x05),
f6022a76
TM
11355GEN_DFP_BF_A_B(dtstsf, 0x02, 0x15),
11356GEN_DFP_BF_A_Bp(dtstsfq, 0x02, 0x15),
5826ebe2
TM
11357GEN_DFP_TE_T_B_RMC_Rc(dquai, 0x03, 0x02),
11358GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq, 0x03, 0x02),
11359GEN_DFP_T_A_B_RMC_Rc(dqua, 0x03, 0x00),
11360GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq, 0x03, 0x00),
512918aa
TM
11361GEN_DFP_T_A_B_RMC_Rc(drrnd, 0x03, 0x01),
11362GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq, 0x03, 0x01),
97c0d930
TM
11363GEN_DFP_R_T_B_RMC_Rc(drintx, 0x03, 0x03),
11364GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq, 0x03, 0x03),
11365GEN_DFP_R_T_B_RMC_Rc(drintn, 0x03, 0x07),
11366GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq, 0x03, 0x07),
290d9ee5
TM
11367GEN_DFP_T_B_Rc(dctdp, 0x02, 0x08),
11368GEN_DFP_Tp_B_Rc(dctqpq, 0x02, 0x08),
ca603eb4
TM
11369GEN_DFP_T_B_Rc(drsp, 0x02, 0x18),
11370GEN_DFP_Tp_Bp_Rc(drdpq, 0x02, 0x18),
f1214193
TM
11371GEN_DFP_T_B_Rc(dcffix, 0x02, 0x19),
11372GEN_DFP_Tp_B_Rc(dcffixq, 0x02, 0x19),
bea0dd79
TM
11373GEN_DFP_T_B_Rc(dctfix, 0x02, 0x09),
11374GEN_DFP_T_Bp_Rc(dctfixq, 0x02, 0x09),
7796676f
TM
11375GEN_DFP_SP_T_B_Rc(ddedpd, 0x02, 0x0a),
11376GEN_DFP_SP_Tp_Bp_Rc(ddedpdq, 0x02, 0x0a),
013c3ac0
TM
11377GEN_DFP_S_T_B_Rc(denbcd, 0x02, 0x1a),
11378GEN_DFP_S_Tp_Bp_Rc(denbcdq, 0x02, 0x1a),
e8a48460
TM
11379GEN_DFP_T_B_Rc(dxex, 0x02, 0x0b),
11380GEN_DFP_T_Bp_Rc(dxexq, 0x02, 0x0b),
297666eb
TM
11381GEN_DFP_T_A_B_Rc(diex, 0x02, 0x1b),
11382GEN_DFP_Tp_A_Bp_Rc(diexq, 0x02, 0x1b),
804e654a
TM
11383GEN_DFP_T_A_SH_Rc(dscli, 0x02, 0x02),
11384GEN_DFP_Tp_Ap_SH_Rc(dscliq, 0x02, 0x02),
11385GEN_DFP_T_A_SH_Rc(dscri, 0x02, 0x03),
11386GEN_DFP_Tp_Ap_SH_Rc(dscriq, 0x02, 0x03),
11387
5c55ff99 11388#undef GEN_SPE
70560da7
FC
11389#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11390 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11391GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11392GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11393GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11394GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11395GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11396GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11397GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11398GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
11399GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
11400GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11401GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11402GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11403GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11404GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11405GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11406GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
11407GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11408GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11409GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11410GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11411GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11412GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11413GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11414GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11415GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11416GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11417GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11418GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11419GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
11420
11421GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11422GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11423GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11424GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11425GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11426GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11427GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11428GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11429GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11430GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11431GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11432GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11433GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11434GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11435
11436GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11437GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11438GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11439GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11440GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11441GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11442GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11443GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11444GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11445GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11446GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11447GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11448GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11449GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11450
11451GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11452GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11453GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11454GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11455GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11456GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11457GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11458GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11459GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11460GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11461GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11462GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11463GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11464GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11465GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11466GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
11467
11468#undef GEN_SPEOP_LDST
11469#define GEN_SPEOP_LDST(name, opc2, sh) \
11470GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11471GEN_SPEOP_LDST(evldd, 0x00, 3),
11472GEN_SPEOP_LDST(evldw, 0x01, 3),
11473GEN_SPEOP_LDST(evldh, 0x02, 3),
11474GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11475GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11476GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11477GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11478GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11479GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11480GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11481GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11482
11483GEN_SPEOP_LDST(evstdd, 0x10, 3),
11484GEN_SPEOP_LDST(evstdw, 0x11, 3),
11485GEN_SPEOP_LDST(evstdh, 0x12, 3),
11486GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11487GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11488GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11489GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
11490};
11491
0411a972 11492#include "helper_regs.h"
a1389542 11493#include "translate_init.c"
79aceca5 11494
9a64fbe4 11495/*****************************************************************************/
3fc6c082 11496/* Misc PowerPC helpers */
878096ee
AF
11497void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11498 int flags)
79aceca5 11499{
3fc6c082
FB
11500#define RGPL 4
11501#define RFPL 4
3fc6c082 11502
878096ee
AF
11503 PowerPCCPU *cpu = POWERPC_CPU(cs);
11504 CPUPPCState *env = &cpu->env;
79aceca5
FB
11505 int i;
11506
90e189ec 11507 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9a78eead 11508 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
da91a00f 11509 env->nip, env->lr, env->ctr, cpu_read_xer(env));
90e189ec
BS
11510 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
11511 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
11512 env->hflags, env->mmu_idx);
d9bce9d9 11513#if !defined(NO_TIMER_DUMP)
9a78eead 11514 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 11515#if !defined(CONFIG_USER_ONLY)
9a78eead 11516 " DECR %08" PRIu32
76a66253
JM
11517#endif
11518 "\n",
077fc206 11519 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
11520#if !defined(CONFIG_USER_ONLY)
11521 , cpu_ppc_load_decr(env)
11522#endif
11523 );
077fc206 11524#endif
76a66253 11525 for (i = 0; i < 32; i++) {
3fc6c082
FB
11526 if ((i & (RGPL - 1)) == 0)
11527 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 11528 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 11529 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 11530 cpu_fprintf(f, "\n");
76a66253 11531 }
3fc6c082 11532 cpu_fprintf(f, "CR ");
76a66253 11533 for (i = 0; i < 8; i++)
7fe48483
FB
11534 cpu_fprintf(f, "%01x", env->crf[i]);
11535 cpu_fprintf(f, " [");
76a66253
JM
11536 for (i = 0; i < 8; i++) {
11537 char a = '-';
11538 if (env->crf[i] & 0x08)
11539 a = 'L';
11540 else if (env->crf[i] & 0x04)
11541 a = 'G';
11542 else if (env->crf[i] & 0x02)
11543 a = 'E';
7fe48483 11544 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 11545 }
90e189ec
BS
11546 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11547 env->reserve_addr);
3fc6c082
FB
11548 for (i = 0; i < 32; i++) {
11549 if ((i & (RFPL - 1)) == 0)
11550 cpu_fprintf(f, "FPR%02d", i);
26a76461 11551 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 11552 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 11553 cpu_fprintf(f, "\n");
79aceca5 11554 }
30304420 11555 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 11556#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
11557 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11558 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11559 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11560 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11561
11562 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11563 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11564 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11565 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11566
11567 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11568 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11569 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11570 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11571
11572 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11573 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11574 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11575 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11576 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11577
11578 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11579 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11580 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11581 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11582
11583 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11584 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11585 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11586 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11587
11588 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11589 " EPR " TARGET_FMT_lx "\n",
11590 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11591 env->spr[SPR_BOOKE_EPR]);
11592
11593 /* FSL-specific */
11594 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11595 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11596 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11597 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11598
11599 /*
11600 * IVORs are left out as they are large and do not change often --
11601 * they can be read with "p $ivor0", "p $ivor1", etc.
11602 */
11603 }
11604
697ab892
DG
11605#if defined(TARGET_PPC64)
11606 if (env->flags & POWERPC_FLAG_CFAR) {
11607 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11608 }
11609#endif
11610
90dc8812
SW
11611 switch (env->mmu_model) {
11612 case POWERPC_MMU_32B:
11613 case POWERPC_MMU_601:
11614 case POWERPC_MMU_SOFT_6xx:
11615 case POWERPC_MMU_SOFT_74xx:
11616#if defined(TARGET_PPC64)
90dc8812 11617 case POWERPC_MMU_64B:
ca480de6
AB
11618 case POWERPC_MMU_2_06:
11619 case POWERPC_MMU_2_06a:
11620 case POWERPC_MMU_2_06d:
90dc8812 11621#endif
ca480de6
AB
11622 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11623 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11624 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 11625 break;
01662f3e 11626 case POWERPC_MMU_BOOKE206:
90dc8812
SW
11627 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11628 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11629 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11630 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11631
11632 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11633 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11634 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11635 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11636
11637 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11638 " TLB1CFG " TARGET_FMT_lx "\n",
11639 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11640 env->spr[SPR_BOOKE_TLB1CFG]);
11641 break;
11642 default:
11643 break;
11644 }
f2e63a42 11645#endif
79aceca5 11646
3fc6c082
FB
11647#undef RGPL
11648#undef RFPL
79aceca5
FB
11649}
11650
878096ee
AF
11651void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11652 fprintf_function cpu_fprintf, int flags)
76a66253
JM
11653{
11654#if defined(DO_PPC_STATISTICS)
878096ee 11655 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 11656 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
11657 int op1, op2, op3;
11658
878096ee 11659 t1 = cpu->env.opcodes;
76a66253
JM
11660 for (op1 = 0; op1 < 64; op1++) {
11661 handler = t1[op1];
11662 if (is_indirect_opcode(handler)) {
11663 t2 = ind_table(handler);
11664 for (op2 = 0; op2 < 32; op2++) {
11665 handler = t2[op2];
11666 if (is_indirect_opcode(handler)) {
11667 t3 = ind_table(handler);
11668 for (op3 = 0; op3 < 32; op3++) {
11669 handler = t3[op3];
11670 if (handler->count == 0)
11671 continue;
11672 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 11673 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11674 op1, op2, op3, op1, (op3 << 5) | op2,
11675 handler->oname,
11676 handler->count, handler->count);
11677 }
11678 } else {
11679 if (handler->count == 0)
11680 continue;
11681 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 11682 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11683 op1, op2, op1, op2, handler->oname,
11684 handler->count, handler->count);
11685 }
11686 }
11687 } else {
11688 if (handler->count == 0)
11689 continue;
0bfcd599
BS
11690 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11691 " %" PRId64 "\n",
76a66253
JM
11692 op1, op1, handler->oname,
11693 handler->count, handler->count);
11694 }
11695 }
11696#endif
11697}
11698
9a64fbe4 11699/*****************************************************************************/
213fe1f5 11700static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
636aa200 11701 TranslationBlock *tb,
213fe1f5 11702 bool search_pc)
79aceca5 11703{
ed2803da 11704 CPUState *cs = CPU(cpu);
213fe1f5 11705 CPUPPCState *env = &cpu->env;
9fddaa0c 11706 DisasContext ctx, *ctxp = &ctx;
c227f099 11707 opc_handler_t **table, *handler;
0fa85d43 11708 target_ulong pc_start;
79aceca5 11709 uint16_t *gen_opc_end;
a1d1bb31 11710 CPUBreakpoint *bp;
79aceca5 11711 int j, lj = -1;
2e70f6ef
PB
11712 int num_insns;
11713 int max_insns;
79aceca5
FB
11714
11715 pc_start = tb->pc;
92414b31 11716 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
046d6672 11717 ctx.nip = pc_start;
79aceca5 11718 ctx.tb = tb;
e1833e1f 11719 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 11720 ctx.spr_cb = env->spr_cb;
76db3ba4 11721 ctx.mem_idx = env->mmu_idx;
7d08d856
AJ
11722 ctx.insns_flags = env->insns_flags;
11723 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
11724 ctx.access_type = -1;
11725 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
d9bce9d9 11726#if defined(TARGET_PPC64)
e42a61f1 11727 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 11728 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 11729#endif
3cc62370 11730 ctx.fpu_enabled = msr_fp;
a9d9eb8f 11731 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
11732 ctx.spe_enabled = msr_spe;
11733 else
11734 ctx.spe_enabled = 0;
a9d9eb8f
JM
11735 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11736 ctx.altivec_enabled = msr_vr;
11737 else
11738 ctx.altivec_enabled = 0;
1f29871c
TM
11739 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11740 ctx.vsx_enabled = msr_vsx;
11741 } else {
11742 ctx.vsx_enabled = 0;
11743 }
d26bfc9a 11744 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 11745 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 11746 else
8cbcb4fa 11747 ctx.singlestep_enabled = 0;
d26bfc9a 11748 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 11749 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 11750 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 11751 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 11752 }
3fc6c082 11753#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
11754 /* Single step trace mode */
11755 msr_se = 1;
11756#endif
2e70f6ef
PB
11757 num_insns = 0;
11758 max_insns = tb->cflags & CF_COUNT_MASK;
11759 if (max_insns == 0)
11760 max_insns = CF_COUNT_MASK;
11761
806f352d 11762 gen_tb_start();
9a64fbe4 11763 /* Set env in case of segfault during code fetch */
efd7f486
EV
11764 while (ctx.exception == POWERPC_EXCP_NONE
11765 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
f0c3c505
AF
11766 if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) {
11767 QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {
a1d1bb31 11768 if (bp->pc == ctx.nip) {
e06fcd75 11769 gen_debug_exception(ctxp);
ea4e754f
FB
11770 break;
11771 }
11772 }
11773 }
76a66253 11774 if (unlikely(search_pc)) {
92414b31 11775 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
79aceca5
FB
11776 if (lj < j) {
11777 lj++;
11778 while (lj < j)
ab1103de 11779 tcg_ctx.gen_opc_instr_start[lj++] = 0;
79aceca5 11780 }
25983cad 11781 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
ab1103de 11782 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 11783 tcg_ctx.gen_opc_icount[lj] = num_insns;
79aceca5 11784 }
d12d51d5 11785 LOG_DISAS("----------------\n");
90e189ec 11786 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 11787 ctx.nip, ctx.mem_idx, (int)msr_ir);
2e70f6ef
PB
11788 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
11789 gen_io_start();
76db3ba4 11790 if (unlikely(ctx.le_mode)) {
2f5a189c 11791 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 11792 } else {
2f5a189c 11793 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 11794 }
d12d51d5 11795 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 11796 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 11797 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
fdefe51c 11798 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
731c54f8 11799 tcg_gen_debug_insn_start(ctx.nip);
fdefe51c 11800 }
046d6672 11801 ctx.nip += 4;
3fc6c082 11802 table = env->opcodes;
2e70f6ef 11803 num_insns++;
79aceca5
FB
11804 handler = table[opc1(ctx.opcode)];
11805 if (is_indirect_opcode(handler)) {
11806 table = ind_table(handler);
11807 handler = table[opc2(ctx.opcode)];
11808 if (is_indirect_opcode(handler)) {
11809 table = ind_table(handler);
11810 handler = table[opc3(ctx.opcode)];
11811 }
11812 }
11813 /* Is opcode *REALLY* valid ? */
76a66253 11814 if (unlikely(handler->handler == &gen_invalid)) {
93fcfe39
AL
11815 if (qemu_log_enabled()) {
11816 qemu_log("invalid/unsupported opcode: "
90e189ec
BS
11817 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11818 opc1(ctx.opcode), opc2(ctx.opcode),
11819 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
4b3686fa 11820 }
76a66253 11821 } else {
70560da7
FC
11822 uint32_t inval;
11823
11824 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11825 inval = handler->inval2;
11826 } else {
11827 inval = handler->inval1;
11828 }
11829
11830 if (unlikely((ctx.opcode & inval) != 0)) {
93fcfe39
AL
11831 if (qemu_log_enabled()) {
11832 qemu_log("invalid bits: %08x for opcode: "
90e189ec 11833 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
70560da7 11834 ctx.opcode & inval, opc1(ctx.opcode),
90e189ec
BS
11835 opc2(ctx.opcode), opc3(ctx.opcode),
11836 ctx.opcode, ctx.nip - 4);
76a66253 11837 }
e06fcd75 11838 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 11839 break;
79aceca5 11840 }
79aceca5 11841 }
4b3686fa 11842 (*(handler->handler))(&ctx);
76a66253
JM
11843#if defined(DO_PPC_STATISTICS)
11844 handler->count++;
11845#endif
9a64fbe4 11846 /* Check trace mode exceptions */
8cbcb4fa
AJ
11847 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11848 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11849 ctx.exception != POWERPC_SYSCALL &&
11850 ctx.exception != POWERPC_EXCP_TRAP &&
11851 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 11852 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 11853 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 11854 (cs->singlestep_enabled) ||
1b530a6d 11855 singlestep ||
2e70f6ef 11856 num_insns >= max_insns)) {
d26bfc9a
JM
11857 /* if we reach a page boundary or are single stepping, stop
11858 * generation
11859 */
8dd4983c 11860 break;
76a66253 11861 }
3fc6c082 11862 }
2e70f6ef
PB
11863 if (tb->cflags & CF_LAST_IO)
11864 gen_io_end();
e1833e1f 11865 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 11866 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 11867 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 11868 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 11869 gen_debug_exception(ctxp);
8cbcb4fa 11870 }
76a66253 11871 /* Generate the return instruction */
57fec1fe 11872 tcg_gen_exit_tb(0);
9a64fbe4 11873 }
806f352d 11874 gen_tb_end(tb, num_insns);
efd7f486 11875 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
76a66253 11876 if (unlikely(search_pc)) {
92414b31 11877 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9a64fbe4
FB
11878 lj++;
11879 while (lj <= j)
ab1103de 11880 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9a64fbe4 11881 } else {
046d6672 11882 tb->size = ctx.nip - pc_start;
2e70f6ef 11883 tb->icount = num_insns;
9a64fbe4 11884 }
d9bce9d9 11885#if defined(DEBUG_DISAS)
8fec2b8c 11886 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 11887 int flags;
237c0af0 11888 flags = env->bfd_mach;
76db3ba4 11889 flags |= ctx.le_mode << 16;
93fcfe39 11890 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 11891 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
93fcfe39 11892 qemu_log("\n");
9fddaa0c 11893 }
79aceca5 11894#endif
79aceca5
FB
11895}
11896
1328c2bf 11897void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11898{
213fe1f5 11899 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
79aceca5
FB
11900}
11901
1328c2bf 11902void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11903{
213fe1f5 11904 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
79aceca5 11905}
d2856f1a 11906
1328c2bf 11907void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
d2856f1a 11908{
25983cad 11909 env->nip = tcg_ctx.gen_opc_pc[pc_pos];
d2856f1a 11910}
This page took 3.334195 seconds and 4 git commands to generate.