]> git.ipfire.org Git - thirdparty/qemu.git/blame - target-ppc/translate.c
target-ppc: Clean Up mullw
[thirdparty/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
a7e30d84
LV
30#include "trace-tcg.h"
31
32
8cbcb4fa
AJ
33#define CPU_SINGLE_STEP 0x1
34#define CPU_BRANCH_STEP 0x2
35#define GDBSTUB_SINGLE_STEP 0x4
36
a750fc0b 37/* Include definitions for instructions classes and implementations flags */
9fddaa0c 38//#define PPC_DEBUG_DISAS
76a66253 39//#define DO_PPC_STATISTICS
79aceca5 40
d12d51d5 41#ifdef PPC_DEBUG_DISAS
93fcfe39 42# define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
d12d51d5
AL
43#else
44# define LOG_DISAS(...) do { } while (0)
45#endif
a750fc0b
JM
46/*****************************************************************************/
47/* Code translation helpers */
c53be334 48
f78fb44e 49/* global register indexes */
a7812ae4 50static TCGv_ptr cpu_env;
1d542695 51static char cpu_reg_names[10*3 + 22*4 /* GPR */
1d542695 52 + 10*4 + 22*5 /* SPE GPRh */
a5e26afa 53 + 10*4 + 22*5 /* FPR */
47e4661c 54 + 2*(10*6 + 22*7) /* AVRh, AVRl */
472b24ce 55 + 10*5 + 22*6 /* VSR */
47e4661c 56 + 8*5 /* CRF */];
f78fb44e 57static TCGv cpu_gpr[32];
f78fb44e 58static TCGv cpu_gprh[32];
a7812ae4
PB
59static TCGv_i64 cpu_fpr[32];
60static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
472b24ce 61static TCGv_i64 cpu_vsr[32];
a7812ae4 62static TCGv_i32 cpu_crf[8];
bd568f18 63static TCGv cpu_nip;
6527f6ea 64static TCGv cpu_msr;
cfdcd37a
AJ
65static TCGv cpu_ctr;
66static TCGv cpu_lr;
697ab892
DG
67#if defined(TARGET_PPC64)
68static TCGv cpu_cfar;
69#endif
da91a00f 70static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
cf360a32 71static TCGv cpu_reserve;
30304420 72static TCGv cpu_fpscr;
a7859e89 73static TCGv_i32 cpu_access_type;
f78fb44e 74
022c62cb 75#include "exec/gen-icount.h"
2e70f6ef
PB
76
77void ppc_translate_init(void)
78{
f78fb44e
AJ
79 int i;
80 char* p;
2dc766da 81 size_t cpu_reg_names_size;
b2437bf2 82 static int done_init = 0;
f78fb44e 83
2e70f6ef
PB
84 if (done_init)
85 return;
f78fb44e 86
a7812ae4 87 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
a7812ae4 88
f78fb44e 89 p = cpu_reg_names;
2dc766da 90 cpu_reg_names_size = sizeof(cpu_reg_names);
47e4661c
AJ
91
92 for (i = 0; i < 8; i++) {
2dc766da 93 snprintf(p, cpu_reg_names_size, "crf%d", i);
a7812ae4 94 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 95 offsetof(CPUPPCState, crf[i]), p);
47e4661c 96 p += 5;
2dc766da 97 cpu_reg_names_size -= 5;
47e4661c
AJ
98 }
99
f78fb44e 100 for (i = 0; i < 32; i++) {
2dc766da 101 snprintf(p, cpu_reg_names_size, "r%d", i);
a7812ae4 102 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
1328c2bf 103 offsetof(CPUPPCState, gpr[i]), p);
f78fb44e 104 p += (i < 10) ? 3 : 4;
2dc766da 105 cpu_reg_names_size -= (i < 10) ? 3 : 4;
2dc766da 106 snprintf(p, cpu_reg_names_size, "r%dH", i);
13b6a455
AG
107 cpu_gprh[i] = tcg_global_mem_new(TCG_AREG0,
108 offsetof(CPUPPCState, gprh[i]), p);
f78fb44e 109 p += (i < 10) ? 4 : 5;
2dc766da 110 cpu_reg_names_size -= (i < 10) ? 4 : 5;
1d542695 111
2dc766da 112 snprintf(p, cpu_reg_names_size, "fp%d", i);
a7812ae4 113 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 114 offsetof(CPUPPCState, fpr[i]), p);
ec1ac72d 115 p += (i < 10) ? 4 : 5;
2dc766da 116 cpu_reg_names_size -= (i < 10) ? 4 : 5;
a5e26afa 117
2dc766da 118 snprintf(p, cpu_reg_names_size, "avr%dH", i);
e2542fe2 119#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 120 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 121 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 122#else
a7812ae4 123 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 124 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 125#endif
1d542695 126 p += (i < 10) ? 6 : 7;
2dc766da 127 cpu_reg_names_size -= (i < 10) ? 6 : 7;
ec1ac72d 128
2dc766da 129 snprintf(p, cpu_reg_names_size, "avr%dL", i);
e2542fe2 130#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 131 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 132 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 133#else
a7812ae4 134 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 135 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 136#endif
1d542695 137 p += (i < 10) ? 6 : 7;
2dc766da 138 cpu_reg_names_size -= (i < 10) ? 6 : 7;
472b24ce
TM
139 snprintf(p, cpu_reg_names_size, "vsr%d", i);
140 cpu_vsr[i] = tcg_global_mem_new_i64(TCG_AREG0,
141 offsetof(CPUPPCState, vsr[i]), p);
142 p += (i < 10) ? 5 : 6;
143 cpu_reg_names_size -= (i < 10) ? 5 : 6;
f78fb44e 144 }
f10dc08e 145
a7812ae4 146 cpu_nip = tcg_global_mem_new(TCG_AREG0,
1328c2bf 147 offsetof(CPUPPCState, nip), "nip");
bd568f18 148
6527f6ea 149 cpu_msr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 150 offsetof(CPUPPCState, msr), "msr");
6527f6ea 151
a7812ae4 152 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 153 offsetof(CPUPPCState, ctr), "ctr");
cfdcd37a 154
a7812ae4 155 cpu_lr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 156 offsetof(CPUPPCState, lr), "lr");
cfdcd37a 157
697ab892
DG
158#if defined(TARGET_PPC64)
159 cpu_cfar = tcg_global_mem_new(TCG_AREG0,
1328c2bf 160 offsetof(CPUPPCState, cfar), "cfar");
697ab892
DG
161#endif
162
a7812ae4 163 cpu_xer = tcg_global_mem_new(TCG_AREG0,
1328c2bf 164 offsetof(CPUPPCState, xer), "xer");
da91a00f
RH
165 cpu_so = tcg_global_mem_new(TCG_AREG0,
166 offsetof(CPUPPCState, so), "SO");
167 cpu_ov = tcg_global_mem_new(TCG_AREG0,
168 offsetof(CPUPPCState, ov), "OV");
169 cpu_ca = tcg_global_mem_new(TCG_AREG0,
170 offsetof(CPUPPCState, ca), "CA");
3d7b417e 171
cf360a32 172 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
1328c2bf 173 offsetof(CPUPPCState, reserve_addr),
18b21a2f 174 "reserve_addr");
cf360a32 175
30304420
DG
176 cpu_fpscr = tcg_global_mem_new(TCG_AREG0,
177 offsetof(CPUPPCState, fpscr), "fpscr");
e1571908 178
a7859e89 179 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 180 offsetof(CPUPPCState, access_type), "access_type");
a7859e89 181
2e70f6ef
PB
182 done_init = 1;
183}
184
79aceca5
FB
185/* internal defines */
186typedef struct DisasContext {
187 struct TranslationBlock *tb;
0fa85d43 188 target_ulong nip;
79aceca5 189 uint32_t opcode;
9a64fbe4 190 uint32_t exception;
3cc62370
FB
191 /* Routine used to access memory */
192 int mem_idx;
76db3ba4 193 int access_type;
3cc62370 194 /* Translation flags */
76db3ba4 195 int le_mode;
e22c357b 196 TCGMemOp default_tcg_memop_mask;
d9bce9d9
JM
197#if defined(TARGET_PPC64)
198 int sf_mode;
697ab892 199 int has_cfar;
9a64fbe4 200#endif
3cc62370 201 int fpu_enabled;
a9d9eb8f 202 int altivec_enabled;
1f29871c 203 int vsx_enabled;
0487d6a8 204 int spe_enabled;
c227f099 205 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
ea4e754f 206 int singlestep_enabled;
7d08d856
AJ
207 uint64_t insns_flags;
208 uint64_t insns_flags2;
79aceca5
FB
209} DisasContext;
210
e22c357b
DK
211/* Return true iff byteswap is needed in a scalar memop */
212static inline bool need_byteswap(const DisasContext *ctx)
213{
214#if defined(TARGET_WORDS_BIGENDIAN)
215 return ctx->le_mode;
216#else
217 return !ctx->le_mode;
218#endif
219}
220
79482e5a
RH
221/* True when active word size < size of target_long. */
222#ifdef TARGET_PPC64
223# define NARROW_MODE(C) (!(C)->sf_mode)
224#else
225# define NARROW_MODE(C) 0
226#endif
227
c227f099 228struct opc_handler_t {
70560da7
FC
229 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
230 uint32_t inval1;
231 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
232 uint32_t inval2;
9a64fbe4 233 /* instruction type */
0487d6a8 234 uint64_t type;
a5858d7a
AG
235 /* extended instruction type */
236 uint64_t type2;
79aceca5
FB
237 /* handler */
238 void (*handler)(DisasContext *ctx);
a750fc0b 239#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
b55266b5 240 const char *oname;
a750fc0b
JM
241#endif
242#if defined(DO_PPC_STATISTICS)
76a66253
JM
243 uint64_t count;
244#endif
3fc6c082 245};
79aceca5 246
636aa200 247static inline void gen_reset_fpstatus(void)
7c58044c 248{
8e703949 249 gen_helper_reset_fpstatus(cpu_env);
7c58044c
JM
250}
251
636aa200 252static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
7c58044c 253{
0f2f39c2 254 TCGv_i32 t0 = tcg_temp_new_i32();
af12906f 255
7c58044c
JM
256 if (set_fprf != 0) {
257 /* This case might be optimized later */
0f2f39c2 258 tcg_gen_movi_i32(t0, 1);
8e703949 259 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
a7812ae4 260 if (unlikely(set_rc)) {
0f2f39c2 261 tcg_gen_mov_i32(cpu_crf[1], t0);
a7812ae4 262 }
8e703949 263 gen_helper_float_check_status(cpu_env);
7c58044c
JM
264 } else if (unlikely(set_rc)) {
265 /* We always need to compute fpcc */
0f2f39c2 266 tcg_gen_movi_i32(t0, 0);
8e703949 267 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
0f2f39c2 268 tcg_gen_mov_i32(cpu_crf[1], t0);
7c58044c 269 }
af12906f 270
0f2f39c2 271 tcg_temp_free_i32(t0);
7c58044c
JM
272}
273
636aa200 274static inline void gen_set_access_type(DisasContext *ctx, int access_type)
a7859e89 275{
76db3ba4
AJ
276 if (ctx->access_type != access_type) {
277 tcg_gen_movi_i32(cpu_access_type, access_type);
278 ctx->access_type = access_type;
279 }
a7859e89
AJ
280}
281
636aa200 282static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
d9bce9d9 283{
e0c8f9ce
RH
284 if (NARROW_MODE(ctx)) {
285 nip = (uint32_t)nip;
286 }
287 tcg_gen_movi_tl(cpu_nip, nip);
d9bce9d9
JM
288}
289
7019cb3d
AK
290void gen_update_current_nip(void *opaque)
291{
292 DisasContext *ctx = opaque;
293
294 tcg_gen_movi_tl(cpu_nip, ctx->nip);
295}
296
636aa200 297static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
e06fcd75
AJ
298{
299 TCGv_i32 t0, t1;
300 if (ctx->exception == POWERPC_EXCP_NONE) {
301 gen_update_nip(ctx, ctx->nip);
302 }
303 t0 = tcg_const_i32(excp);
304 t1 = tcg_const_i32(error);
e5f17ac6 305 gen_helper_raise_exception_err(cpu_env, t0, t1);
e06fcd75
AJ
306 tcg_temp_free_i32(t0);
307 tcg_temp_free_i32(t1);
308 ctx->exception = (excp);
309}
e1833e1f 310
636aa200 311static inline void gen_exception(DisasContext *ctx, uint32_t excp)
e06fcd75
AJ
312{
313 TCGv_i32 t0;
314 if (ctx->exception == POWERPC_EXCP_NONE) {
315 gen_update_nip(ctx, ctx->nip);
316 }
317 t0 = tcg_const_i32(excp);
e5f17ac6 318 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
319 tcg_temp_free_i32(t0);
320 ctx->exception = (excp);
321}
e1833e1f 322
636aa200 323static inline void gen_debug_exception(DisasContext *ctx)
e06fcd75
AJ
324{
325 TCGv_i32 t0;
5518f3a6 326
ee2b3994
SB
327 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
328 (ctx->exception != POWERPC_EXCP_SYNC)) {
5518f3a6 329 gen_update_nip(ctx, ctx->nip);
ee2b3994 330 }
e06fcd75 331 t0 = tcg_const_i32(EXCP_DEBUG);
e5f17ac6 332 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
333 tcg_temp_free_i32(t0);
334}
9a64fbe4 335
636aa200 336static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
e06fcd75
AJ
337{
338 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
339}
a9d9eb8f 340
f24e5695 341/* Stop translation */
636aa200 342static inline void gen_stop_exception(DisasContext *ctx)
3fc6c082 343{
d9bce9d9 344 gen_update_nip(ctx, ctx->nip);
e1833e1f 345 ctx->exception = POWERPC_EXCP_STOP;
3fc6c082
FB
346}
347
f24e5695 348/* No need to update nip here, as execution flow will change */
636aa200 349static inline void gen_sync_exception(DisasContext *ctx)
2be0071f 350{
e1833e1f 351 ctx->exception = POWERPC_EXCP_SYNC;
2be0071f
FB
352}
353
79aceca5 354#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
355GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
356
357#define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
358GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
79aceca5 359
c7697e1f 360#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
361GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
362
363#define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
364GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
c7697e1f 365
c227f099 366typedef struct opcode_t {
79aceca5 367 unsigned char opc1, opc2, opc3;
1235fc06 368#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
18fba28c
FB
369 unsigned char pad[5];
370#else
371 unsigned char pad[1];
372#endif
c227f099 373 opc_handler_t handler;
b55266b5 374 const char *oname;
c227f099 375} opcode_t;
79aceca5 376
a750fc0b 377/*****************************************************************************/
79aceca5
FB
378/*** Instruction decoding ***/
379#define EXTRACT_HELPER(name, shift, nb) \
636aa200 380static inline uint32_t name(uint32_t opcode) \
79aceca5
FB
381{ \
382 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
383}
384
385#define EXTRACT_SHELPER(name, shift, nb) \
636aa200 386static inline int32_t name(uint32_t opcode) \
79aceca5 387{ \
18fba28c 388 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
79aceca5
FB
389}
390
f9fc6d81
TM
391#define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
392static inline uint32_t name(uint32_t opcode) \
393{ \
394 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
395 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
396}
79aceca5
FB
397/* Opcode part 1 */
398EXTRACT_HELPER(opc1, 26, 6);
399/* Opcode part 2 */
400EXTRACT_HELPER(opc2, 1, 5);
401/* Opcode part 3 */
402EXTRACT_HELPER(opc3, 6, 5);
403/* Update Cr0 flags */
404EXTRACT_HELPER(Rc, 0, 1);
a737d3eb
TM
405/* Update Cr6 flags (Altivec) */
406EXTRACT_HELPER(Rc21, 10, 1);
79aceca5
FB
407/* Destination */
408EXTRACT_HELPER(rD, 21, 5);
409/* Source */
410EXTRACT_HELPER(rS, 21, 5);
411/* First operand */
412EXTRACT_HELPER(rA, 16, 5);
413/* Second operand */
414EXTRACT_HELPER(rB, 11, 5);
415/* Third operand */
416EXTRACT_HELPER(rC, 6, 5);
417/*** Get CRn ***/
418EXTRACT_HELPER(crfD, 23, 3);
419EXTRACT_HELPER(crfS, 18, 3);
420EXTRACT_HELPER(crbD, 21, 5);
421EXTRACT_HELPER(crbA, 16, 5);
422EXTRACT_HELPER(crbB, 11, 5);
423/* SPR / TBL */
3fc6c082 424EXTRACT_HELPER(_SPR, 11, 10);
636aa200 425static inline uint32_t SPR(uint32_t opcode)
3fc6c082
FB
426{
427 uint32_t sprn = _SPR(opcode);
428
429 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
430}
79aceca5 431/*** Get constants ***/
79aceca5
FB
432/* 16 bits signed immediate value */
433EXTRACT_SHELPER(SIMM, 0, 16);
434/* 16 bits unsigned immediate value */
435EXTRACT_HELPER(UIMM, 0, 16);
21d21583
AJ
436/* 5 bits signed immediate value */
437EXTRACT_HELPER(SIMM5, 16, 5);
27a4edb3
AJ
438/* 5 bits signed immediate value */
439EXTRACT_HELPER(UIMM5, 16, 5);
79aceca5
FB
440/* Bit count */
441EXTRACT_HELPER(NB, 11, 5);
442/* Shift count */
443EXTRACT_HELPER(SH, 11, 5);
cd633b10
AJ
444/* Vector shift count */
445EXTRACT_HELPER(VSH, 6, 4);
79aceca5
FB
446/* Mask start */
447EXTRACT_HELPER(MB, 6, 5);
448/* Mask end */
449EXTRACT_HELPER(ME, 1, 5);
fb0eaffc
FB
450/* Trap operand */
451EXTRACT_HELPER(TO, 21, 5);
79aceca5
FB
452
453EXTRACT_HELPER(CRM, 12, 8);
79aceca5 454EXTRACT_HELPER(SR, 16, 4);
7d08d856
AJ
455
456/* mtfsf/mtfsfi */
779f6590 457EXTRACT_HELPER(FPBF, 23, 3);
e4bb997e 458EXTRACT_HELPER(FPIMM, 12, 4);
779f6590 459EXTRACT_HELPER(FPL, 25, 1);
7d08d856
AJ
460EXTRACT_HELPER(FPFLM, 17, 8);
461EXTRACT_HELPER(FPW, 16, 1);
fb0eaffc 462
79aceca5 463/*** Jump target decoding ***/
79aceca5 464/* Immediate address */
636aa200 465static inline target_ulong LI(uint32_t opcode)
79aceca5
FB
466{
467 return (opcode >> 0) & 0x03FFFFFC;
468}
469
636aa200 470static inline uint32_t BD(uint32_t opcode)
79aceca5
FB
471{
472 return (opcode >> 0) & 0xFFFC;
473}
474
475EXTRACT_HELPER(BO, 21, 5);
476EXTRACT_HELPER(BI, 16, 5);
477/* Absolute/relative address */
478EXTRACT_HELPER(AA, 1, 1);
479/* Link */
480EXTRACT_HELPER(LK, 0, 1);
481
f0b01f02
TM
482/* DFP Z22-form */
483EXTRACT_HELPER(DCM, 10, 6)
484
485/* DFP Z23-form */
486EXTRACT_HELPER(RMC, 9, 2)
487
79aceca5 488/* Create a mask between <start> and <end> bits */
636aa200 489static inline target_ulong MASK(uint32_t start, uint32_t end)
79aceca5 490{
76a66253 491 target_ulong ret;
79aceca5 492
76a66253
JM
493#if defined(TARGET_PPC64)
494 if (likely(start == 0)) {
6f2d8978 495 ret = UINT64_MAX << (63 - end);
76a66253 496 } else if (likely(end == 63)) {
6f2d8978 497 ret = UINT64_MAX >> start;
76a66253
JM
498 }
499#else
500 if (likely(start == 0)) {
6f2d8978 501 ret = UINT32_MAX << (31 - end);
76a66253 502 } else if (likely(end == 31)) {
6f2d8978 503 ret = UINT32_MAX >> start;
76a66253
JM
504 }
505#endif
506 else {
507 ret = (((target_ulong)(-1ULL)) >> (start)) ^
508 (((target_ulong)(-1ULL) >> (end)) >> 1);
509 if (unlikely(start > end))
510 return ~ret;
511 }
79aceca5
FB
512
513 return ret;
514}
515
f9fc6d81
TM
516EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
517EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
518EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
519EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
551e3ef7 520EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
f9fc6d81 521EXTRACT_HELPER(DM, 8, 2);
76c15fe0 522EXTRACT_HELPER(UIM, 16, 2);
acc42968 523EXTRACT_HELPER(SHW, 8, 2);
f0b01f02 524EXTRACT_HELPER(SP, 19, 2);
a750fc0b 525/*****************************************************************************/
a750fc0b 526/* PowerPC instructions table */
933dc6eb 527
76a66253 528#if defined(DO_PPC_STATISTICS)
a5858d7a 529#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 530{ \
79aceca5
FB
531 .opc1 = op1, \
532 .opc2 = op2, \
533 .opc3 = op3, \
18fba28c 534 .pad = { 0, }, \
79aceca5 535 .handler = { \
70560da7
FC
536 .inval1 = invl, \
537 .type = _typ, \
538 .type2 = _typ2, \
539 .handler = &gen_##name, \
540 .oname = stringify(name), \
541 }, \
542 .oname = stringify(name), \
543}
544#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
545{ \
546 .opc1 = op1, \
547 .opc2 = op2, \
548 .opc3 = op3, \
549 .pad = { 0, }, \
550 .handler = { \
551 .inval1 = invl1, \
552 .inval2 = invl2, \
9a64fbe4 553 .type = _typ, \
a5858d7a 554 .type2 = _typ2, \
79aceca5 555 .handler = &gen_##name, \
76a66253 556 .oname = stringify(name), \
79aceca5 557 }, \
3fc6c082 558 .oname = stringify(name), \
79aceca5 559}
a5858d7a 560#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 561{ \
c7697e1f
JM
562 .opc1 = op1, \
563 .opc2 = op2, \
564 .opc3 = op3, \
565 .pad = { 0, }, \
566 .handler = { \
70560da7 567 .inval1 = invl, \
c7697e1f 568 .type = _typ, \
a5858d7a 569 .type2 = _typ2, \
c7697e1f
JM
570 .handler = &gen_##name, \
571 .oname = onam, \
572 }, \
573 .oname = onam, \
574}
76a66253 575#else
a5858d7a 576#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 577{ \
c7697e1f
JM
578 .opc1 = op1, \
579 .opc2 = op2, \
580 .opc3 = op3, \
581 .pad = { 0, }, \
582 .handler = { \
70560da7
FC
583 .inval1 = invl, \
584 .type = _typ, \
585 .type2 = _typ2, \
586 .handler = &gen_##name, \
587 }, \
588 .oname = stringify(name), \
589}
590#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
591{ \
592 .opc1 = op1, \
593 .opc2 = op2, \
594 .opc3 = op3, \
595 .pad = { 0, }, \
596 .handler = { \
597 .inval1 = invl1, \
598 .inval2 = invl2, \
c7697e1f 599 .type = _typ, \
a5858d7a 600 .type2 = _typ2, \
c7697e1f 601 .handler = &gen_##name, \
5c55ff99
BS
602 }, \
603 .oname = stringify(name), \
604}
a5858d7a 605#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99
BS
606{ \
607 .opc1 = op1, \
608 .opc2 = op2, \
609 .opc3 = op3, \
610 .pad = { 0, }, \
611 .handler = { \
70560da7 612 .inval1 = invl, \
5c55ff99 613 .type = _typ, \
a5858d7a 614 .type2 = _typ2, \
5c55ff99
BS
615 .handler = &gen_##name, \
616 }, \
617 .oname = onam, \
618}
619#endif
2e610050 620
5c55ff99 621/* SPR load/store helpers */
636aa200 622static inline void gen_load_spr(TCGv t, int reg)
5c55ff99 623{
1328c2bf 624 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 625}
2e610050 626
636aa200 627static inline void gen_store_spr(int reg, TCGv t)
5c55ff99 628{
1328c2bf 629 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 630}
2e610050 631
54623277 632/* Invalid instruction */
99e300ef 633static void gen_invalid(DisasContext *ctx)
9a64fbe4 634{
e06fcd75 635 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
9a64fbe4
FB
636}
637
c227f099 638static opc_handler_t invalid_handler = {
70560da7
FC
639 .inval1 = 0xFFFFFFFF,
640 .inval2 = 0xFFFFFFFF,
9a64fbe4 641 .type = PPC_NONE,
a5858d7a 642 .type2 = PPC_NONE,
79aceca5
FB
643 .handler = gen_invalid,
644};
645
71a8c019
TM
646#if defined(TARGET_PPC64)
647/* NOTE: as this time, the only use of is_user_mode() is in 64 bit code. And */
648/* so the function is wrapped in the standard 64-bit ifdef in order to */
649/* avoid compiler warnings in 32-bit implementations. */
650static bool is_user_mode(DisasContext *ctx)
651{
652#if defined(CONFIG_USER_ONLY)
653 return true;
654#else
655 return ctx->mem_idx == 0;
656#endif
657}
658#endif
659
e1571908
AJ
660/*** Integer comparison ***/
661
636aa200 662static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 663{
2fdcb629
RH
664 TCGv t0 = tcg_temp_new();
665 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 666
da91a00f 667 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 668
2fdcb629
RH
669 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
670 tcg_gen_trunc_tl_i32(t1, t0);
671 tcg_gen_shli_i32(t1, t1, CRF_LT);
672 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
673
674 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
675 tcg_gen_trunc_tl_i32(t1, t0);
676 tcg_gen_shli_i32(t1, t1, CRF_GT);
677 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
678
679 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
680 tcg_gen_trunc_tl_i32(t1, t0);
681 tcg_gen_shli_i32(t1, t1, CRF_EQ);
682 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
683
684 tcg_temp_free(t0);
685 tcg_temp_free_i32(t1);
e1571908
AJ
686}
687
636aa200 688static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 689{
2fdcb629 690 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
691 gen_op_cmp(arg0, t0, s, crf);
692 tcg_temp_free(t0);
e1571908
AJ
693}
694
636aa200 695static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 696{
ea363694 697 TCGv t0, t1;
2fdcb629
RH
698 t0 = tcg_temp_new();
699 t1 = tcg_temp_new();
e1571908 700 if (s) {
ea363694
AJ
701 tcg_gen_ext32s_tl(t0, arg0);
702 tcg_gen_ext32s_tl(t1, arg1);
e1571908 703 } else {
ea363694
AJ
704 tcg_gen_ext32u_tl(t0, arg0);
705 tcg_gen_ext32u_tl(t1, arg1);
e1571908 706 }
ea363694
AJ
707 gen_op_cmp(t0, t1, s, crf);
708 tcg_temp_free(t1);
709 tcg_temp_free(t0);
e1571908
AJ
710}
711
636aa200 712static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 713{
2fdcb629 714 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
715 gen_op_cmp32(arg0, t0, s, crf);
716 tcg_temp_free(t0);
e1571908 717}
e1571908 718
636aa200 719static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908 720{
02765534 721 if (NARROW_MODE(ctx)) {
e1571908 722 gen_op_cmpi32(reg, 0, 1, 0);
02765534 723 } else {
e1571908 724 gen_op_cmpi(reg, 0, 1, 0);
02765534 725 }
e1571908
AJ
726}
727
728/* cmp */
99e300ef 729static void gen_cmp(DisasContext *ctx)
e1571908 730{
36f48d9c 731 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
732 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
733 1, crfD(ctx->opcode));
36f48d9c
AG
734 } else {
735 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
736 1, crfD(ctx->opcode));
02765534 737 }
e1571908
AJ
738}
739
740/* cmpi */
99e300ef 741static void gen_cmpi(DisasContext *ctx)
e1571908 742{
36f48d9c 743 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
744 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
745 1, crfD(ctx->opcode));
36f48d9c
AG
746 } else {
747 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
748 1, crfD(ctx->opcode));
02765534 749 }
e1571908
AJ
750}
751
752/* cmpl */
99e300ef 753static void gen_cmpl(DisasContext *ctx)
e1571908 754{
36f48d9c 755 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
756 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
757 0, crfD(ctx->opcode));
36f48d9c
AG
758 } else {
759 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
760 0, crfD(ctx->opcode));
02765534 761 }
e1571908
AJ
762}
763
764/* cmpli */
99e300ef 765static void gen_cmpli(DisasContext *ctx)
e1571908 766{
36f48d9c 767 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
768 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
769 0, crfD(ctx->opcode));
36f48d9c
AG
770 } else {
771 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
772 0, crfD(ctx->opcode));
02765534 773 }
e1571908
AJ
774}
775
776/* isel (PowerPC 2.03 specification) */
99e300ef 777static void gen_isel(DisasContext *ctx)
e1571908
AJ
778{
779 int l1, l2;
780 uint32_t bi = rC(ctx->opcode);
781 uint32_t mask;
a7812ae4 782 TCGv_i32 t0;
e1571908
AJ
783
784 l1 = gen_new_label();
785 l2 = gen_new_label();
786
787 mask = 1 << (3 - (bi & 0x03));
a7812ae4 788 t0 = tcg_temp_new_i32();
fea0c503
AJ
789 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
790 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
e1571908
AJ
791 if (rA(ctx->opcode) == 0)
792 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
793 else
794 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
795 tcg_gen_br(l2);
796 gen_set_label(l1);
797 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
798 gen_set_label(l2);
a7812ae4 799 tcg_temp_free_i32(t0);
e1571908
AJ
800}
801
fcfda20f
AJ
802/* cmpb: PowerPC 2.05 specification */
803static void gen_cmpb(DisasContext *ctx)
804{
805 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
806 cpu_gpr[rB(ctx->opcode)]);
807}
808
79aceca5 809/*** Integer arithmetic ***/
79aceca5 810
636aa200
BS
811static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
812 TCGv arg1, TCGv arg2, int sub)
74637406 813{
ffe30937 814 TCGv t0 = tcg_temp_new();
79aceca5 815
8e7a6db9 816 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
74637406 817 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
818 if (sub) {
819 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
820 } else {
821 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
822 }
823 tcg_temp_free(t0);
02765534 824 if (NARROW_MODE(ctx)) {
ffe30937
RH
825 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
826 }
ffe30937
RH
827 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
828 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
829}
830
74637406 831/* Common add function */
636aa200 832static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
833 TCGv arg2, bool add_ca, bool compute_ca,
834 bool compute_ov, bool compute_rc0)
74637406 835{
b5a73f8d 836 TCGv t0 = ret;
d9bce9d9 837
752d634e 838 if (compute_ca || compute_ov) {
146de60d 839 t0 = tcg_temp_new();
74637406 840 }
79aceca5 841
da91a00f 842 if (compute_ca) {
79482e5a 843 if (NARROW_MODE(ctx)) {
752d634e
RH
844 /* Caution: a non-obvious corner case of the spec is that we
845 must produce the *entire* 64-bit addition, but produce the
846 carry into bit 32. */
79482e5a 847 TCGv t1 = tcg_temp_new();
752d634e
RH
848 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
849 tcg_gen_add_tl(t0, arg1, arg2);
79482e5a
RH
850 if (add_ca) {
851 tcg_gen_add_tl(t0, t0, cpu_ca);
852 }
752d634e
RH
853 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
854 tcg_temp_free(t1);
855 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
856 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
b5a73f8d 857 } else {
79482e5a
RH
858 TCGv zero = tcg_const_tl(0);
859 if (add_ca) {
860 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
861 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
862 } else {
863 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
864 }
865 tcg_temp_free(zero);
b5a73f8d 866 }
b5a73f8d
RH
867 } else {
868 tcg_gen_add_tl(t0, arg1, arg2);
869 if (add_ca) {
870 tcg_gen_add_tl(t0, t0, cpu_ca);
871 }
da91a00f 872 }
79aceca5 873
74637406
AJ
874 if (compute_ov) {
875 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
876 }
b5a73f8d 877 if (unlikely(compute_rc0)) {
74637406 878 gen_set_Rc0(ctx, t0);
b5a73f8d 879 }
74637406 880
a7812ae4 881 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
882 tcg_gen_mov_tl(ret, t0);
883 tcg_temp_free(t0);
884 }
39dd32ee 885}
74637406
AJ
886/* Add functions with two operands */
887#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 888static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
889{ \
890 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
891 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 892 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
893}
894/* Add functions with one operand and one immediate */
895#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
896 add_ca, compute_ca, compute_ov) \
b5a73f8d 897static void glue(gen_, name)(DisasContext *ctx) \
74637406 898{ \
b5a73f8d 899 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
900 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
901 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 902 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
903 tcg_temp_free(t0); \
904}
905
906/* add add. addo addo. */
907GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
908GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
909/* addc addc. addco addco. */
910GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
911GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
912/* adde adde. addeo addeo. */
913GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
914GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
915/* addme addme. addmeo addmeo. */
916GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
917GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
918/* addze addze. addzeo addzeo.*/
919GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
920GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
921/* addi */
99e300ef 922static void gen_addi(DisasContext *ctx)
d9bce9d9 923{
74637406
AJ
924 target_long simm = SIMM(ctx->opcode);
925
926 if (rA(ctx->opcode) == 0) {
927 /* li case */
928 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
929 } else {
b5a73f8d
RH
930 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
931 cpu_gpr[rA(ctx->opcode)], simm);
74637406 932 }
d9bce9d9 933}
74637406 934/* addic addic.*/
b5a73f8d 935static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 936{
b5a73f8d
RH
937 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
938 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
939 c, 0, 1, 0, compute_rc0);
940 tcg_temp_free(c);
d9bce9d9 941}
99e300ef
BS
942
943static void gen_addic(DisasContext *ctx)
d9bce9d9 944{
b5a73f8d 945 gen_op_addic(ctx, 0);
d9bce9d9 946}
e8eaa2c0
BS
947
948static void gen_addic_(DisasContext *ctx)
d9bce9d9 949{
b5a73f8d 950 gen_op_addic(ctx, 1);
d9bce9d9 951}
99e300ef 952
54623277 953/* addis */
99e300ef 954static void gen_addis(DisasContext *ctx)
d9bce9d9 955{
74637406
AJ
956 target_long simm = SIMM(ctx->opcode);
957
958 if (rA(ctx->opcode) == 0) {
959 /* lis case */
960 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
961 } else {
b5a73f8d
RH
962 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
963 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 964 }
d9bce9d9 965}
74637406 966
636aa200
BS
967static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
968 TCGv arg2, int sign, int compute_ov)
d9bce9d9 969{
2ef1b120
AJ
970 int l1 = gen_new_label();
971 int l2 = gen_new_label();
a7812ae4
PB
972 TCGv_i32 t0 = tcg_temp_local_new_i32();
973 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 974
2ef1b120
AJ
975 tcg_gen_trunc_tl_i32(t0, arg1);
976 tcg_gen_trunc_tl_i32(t1, arg2);
977 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 978 if (sign) {
2ef1b120
AJ
979 int l3 = gen_new_label();
980 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
981 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 982 gen_set_label(l3);
2ef1b120 983 tcg_gen_div_i32(t0, t0, t1);
74637406 984 } else {
2ef1b120 985 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
986 }
987 if (compute_ov) {
da91a00f 988 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
989 }
990 tcg_gen_br(l2);
991 gen_set_label(l1);
992 if (sign) {
2ef1b120 993 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
994 } else {
995 tcg_gen_movi_i32(t0, 0);
996 }
997 if (compute_ov) {
da91a00f
RH
998 tcg_gen_movi_tl(cpu_ov, 1);
999 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1000 }
1001 gen_set_label(l2);
2ef1b120 1002 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
1003 tcg_temp_free_i32(t0);
1004 tcg_temp_free_i32(t1);
74637406
AJ
1005 if (unlikely(Rc(ctx->opcode) != 0))
1006 gen_set_Rc0(ctx, ret);
d9bce9d9 1007}
74637406
AJ
1008/* Div functions */
1009#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 1010static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1011{ \
1012 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1013 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1014 sign, compute_ov); \
1015}
1016/* divwu divwu. divwuo divwuo. */
1017GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
1018GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
1019/* divw divw. divwo divwo. */
1020GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1021GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
98d1eb27
TM
1022
1023/* div[wd]eu[o][.] */
1024#define GEN_DIVE(name, hlpr, compute_ov) \
1025static void gen_##name(DisasContext *ctx) \
1026{ \
1027 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1028 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1029 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1030 tcg_temp_free_i32(t0); \
1031 if (unlikely(Rc(ctx->opcode) != 0)) { \
1032 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1033 } \
1034}
1035
6a4fda33
TM
1036GEN_DIVE(divweu, divweu, 0);
1037GEN_DIVE(divweuo, divweu, 1);
a98eb9e9
TM
1038GEN_DIVE(divwe, divwe, 0);
1039GEN_DIVE(divweo, divwe, 1);
6a4fda33 1040
d9bce9d9 1041#if defined(TARGET_PPC64)
636aa200
BS
1042static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1043 TCGv arg2, int sign, int compute_ov)
d9bce9d9 1044{
2ef1b120
AJ
1045 int l1 = gen_new_label();
1046 int l2 = gen_new_label();
74637406
AJ
1047
1048 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1049 if (sign) {
2ef1b120 1050 int l3 = gen_new_label();
74637406
AJ
1051 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1052 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1053 gen_set_label(l3);
74637406
AJ
1054 tcg_gen_div_i64(ret, arg1, arg2);
1055 } else {
1056 tcg_gen_divu_i64(ret, arg1, arg2);
1057 }
1058 if (compute_ov) {
da91a00f 1059 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
1060 }
1061 tcg_gen_br(l2);
1062 gen_set_label(l1);
1063 if (sign) {
1064 tcg_gen_sari_i64(ret, arg1, 63);
1065 } else {
1066 tcg_gen_movi_i64(ret, 0);
1067 }
1068 if (compute_ov) {
da91a00f
RH
1069 tcg_gen_movi_tl(cpu_ov, 1);
1070 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1071 }
1072 gen_set_label(l2);
1073 if (unlikely(Rc(ctx->opcode) != 0))
1074 gen_set_Rc0(ctx, ret);
d9bce9d9 1075}
74637406 1076#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 1077static void glue(gen_, name)(DisasContext *ctx) \
74637406 1078{ \
2ef1b120
AJ
1079 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1080 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1081 sign, compute_ov); \
74637406
AJ
1082}
1083/* divwu divwu. divwuo divwuo. */
1084GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1085GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1086/* divw divw. divwo divwo. */
1087GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1088GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
98d1eb27
TM
1089
1090GEN_DIVE(divdeu, divdeu, 0);
1091GEN_DIVE(divdeuo, divdeu, 1);
e44259b6
TM
1092GEN_DIVE(divde, divde, 0);
1093GEN_DIVE(divdeo, divde, 1);
d9bce9d9 1094#endif
74637406
AJ
1095
1096/* mulhw mulhw. */
99e300ef 1097static void gen_mulhw(DisasContext *ctx)
d9bce9d9 1098{
23ad1d5d
RH
1099 TCGv_i32 t0 = tcg_temp_new_i32();
1100 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1101
23ad1d5d
RH
1102 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1103 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1104 tcg_gen_muls2_i32(t0, t1, t0, t1);
1105 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1106 tcg_temp_free_i32(t0);
1107 tcg_temp_free_i32(t1);
74637406
AJ
1108 if (unlikely(Rc(ctx->opcode) != 0))
1109 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1110}
99e300ef 1111
54623277 1112/* mulhwu mulhwu. */
99e300ef 1113static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1114{
23ad1d5d
RH
1115 TCGv_i32 t0 = tcg_temp_new_i32();
1116 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1117
23ad1d5d
RH
1118 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1119 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1120 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1121 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1122 tcg_temp_free_i32(t0);
1123 tcg_temp_free_i32(t1);
74637406
AJ
1124 if (unlikely(Rc(ctx->opcode) != 0))
1125 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1126}
99e300ef 1127
54623277 1128/* mullw mullw. */
99e300ef 1129static void gen_mullw(DisasContext *ctx)
d9bce9d9 1130{
1fa74845
TM
1131#if defined(TARGET_PPC64)
1132 TCGv_i64 t0, t1;
1133 t0 = tcg_temp_new_i64();
1134 t1 = tcg_temp_new_i64();
1135 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1136 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1137 tcg_gen_mul_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);
1138 tcg_temp_free(t0);
1139 tcg_temp_free(t1);
1140#else
03039e5e
TM
1141 tcg_gen_mul_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1142 cpu_gpr[rB(ctx->opcode)]);
1fa74845 1143#endif
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/* mullwo mullwo. */
99e300ef 1149static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1150{
e4a2c846
RH
1151 TCGv_i32 t0 = tcg_temp_new_i32();
1152 TCGv_i32 t1 = tcg_temp_new_i32();
f11ebbf8
TM
1153#if defined(TARGET_PPC64)
1154 TCGv_i64 t2 = tcg_temp_new_i64();
1155#endif
74637406 1156
e4a2c846
RH
1157 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1158 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1159 tcg_gen_muls2_i32(t0, t1, t0, t1);
1160 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
f11ebbf8
TM
1161#if defined(TARGET_PPC64)
1162 tcg_gen_ext_i32_tl(t2, t1);
1163 tcg_gen_deposit_i64(cpu_gpr[rD(ctx->opcode)],
1164 cpu_gpr[rD(ctx->opcode)], t2, 32, 32);
1165 tcg_temp_free(t2);
1166#endif
e4a2c846
RH
1167
1168 tcg_gen_sari_i32(t0, t0, 31);
1169 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1170 tcg_gen_extu_i32_tl(cpu_ov, t0);
1171 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1172
1173 tcg_temp_free_i32(t0);
1174 tcg_temp_free_i32(t1);
74637406
AJ
1175 if (unlikely(Rc(ctx->opcode) != 0))
1176 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1177}
99e300ef 1178
54623277 1179/* mulli */
99e300ef 1180static void gen_mulli(DisasContext *ctx)
d9bce9d9 1181{
74637406
AJ
1182 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1183 SIMM(ctx->opcode));
d9bce9d9 1184}
23ad1d5d 1185
d9bce9d9 1186#if defined(TARGET_PPC64)
74637406 1187/* mulhd mulhd. */
23ad1d5d
RH
1188static void gen_mulhd(DisasContext *ctx)
1189{
1190 TCGv lo = tcg_temp_new();
1191 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1192 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1193 tcg_temp_free(lo);
1194 if (unlikely(Rc(ctx->opcode) != 0)) {
1195 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1196 }
1197}
1198
74637406 1199/* mulhdu mulhdu. */
23ad1d5d
RH
1200static void gen_mulhdu(DisasContext *ctx)
1201{
1202 TCGv lo = tcg_temp_new();
1203 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1204 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1205 tcg_temp_free(lo);
1206 if (unlikely(Rc(ctx->opcode) != 0)) {
1207 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1208 }
1209}
99e300ef 1210
54623277 1211/* mulld mulld. */
99e300ef 1212static void gen_mulld(DisasContext *ctx)
d9bce9d9 1213{
74637406
AJ
1214 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1215 cpu_gpr[rB(ctx->opcode)]);
1216 if (unlikely(Rc(ctx->opcode) != 0))
1217 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1218}
d15f74fb 1219
74637406 1220/* mulldo mulldo. */
d15f74fb
BS
1221static void gen_mulldo(DisasContext *ctx)
1222{
1223 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1224 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1225 if (unlikely(Rc(ctx->opcode) != 0)) {
1226 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1227 }
1228}
d9bce9d9 1229#endif
74637406 1230
74637406 1231/* Common subf function */
636aa200 1232static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1233 TCGv arg2, bool add_ca, bool compute_ca,
1234 bool compute_ov, bool compute_rc0)
79aceca5 1235{
b5a73f8d 1236 TCGv t0 = ret;
79aceca5 1237
752d634e 1238 if (compute_ca || compute_ov) {
b5a73f8d 1239 t0 = tcg_temp_new();
da91a00f 1240 }
74637406 1241
79482e5a
RH
1242 if (compute_ca) {
1243 /* dest = ~arg1 + arg2 [+ ca]. */
1244 if (NARROW_MODE(ctx)) {
752d634e
RH
1245 /* Caution: a non-obvious corner case of the spec is that we
1246 must produce the *entire* 64-bit addition, but produce the
1247 carry into bit 32. */
79482e5a 1248 TCGv inv1 = tcg_temp_new();
752d634e 1249 TCGv t1 = tcg_temp_new();
79482e5a 1250 tcg_gen_not_tl(inv1, arg1);
79482e5a 1251 if (add_ca) {
752d634e 1252 tcg_gen_add_tl(t0, arg2, cpu_ca);
79482e5a 1253 } else {
752d634e 1254 tcg_gen_addi_tl(t0, arg2, 1);
79482e5a 1255 }
752d634e 1256 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
79482e5a 1257 tcg_gen_add_tl(t0, t0, inv1);
c80d1df5 1258 tcg_temp_free(inv1);
752d634e
RH
1259 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1260 tcg_temp_free(t1);
1261 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1262 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
79482e5a 1263 } else if (add_ca) {
08f4a0f7
RH
1264 TCGv zero, inv1 = tcg_temp_new();
1265 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1266 zero = tcg_const_tl(0);
1267 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1268 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1269 tcg_temp_free(zero);
08f4a0f7 1270 tcg_temp_free(inv1);
b5a73f8d 1271 } else {
79482e5a 1272 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
b5a73f8d 1273 tcg_gen_sub_tl(t0, arg2, arg1);
b5a73f8d 1274 }
79482e5a
RH
1275 } else if (add_ca) {
1276 /* Since we're ignoring carry-out, we can simplify the
1277 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1278 tcg_gen_sub_tl(t0, arg2, arg1);
1279 tcg_gen_add_tl(t0, t0, cpu_ca);
1280 tcg_gen_subi_tl(t0, t0, 1);
79aceca5 1281 } else {
b5a73f8d 1282 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1283 }
b5a73f8d 1284
74637406
AJ
1285 if (compute_ov) {
1286 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1287 }
b5a73f8d 1288 if (unlikely(compute_rc0)) {
74637406 1289 gen_set_Rc0(ctx, t0);
b5a73f8d 1290 }
74637406 1291
a7812ae4 1292 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1293 tcg_gen_mov_tl(ret, t0);
1294 tcg_temp_free(t0);
79aceca5 1295 }
79aceca5 1296}
74637406
AJ
1297/* Sub functions with Two operands functions */
1298#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1299static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1300{ \
1301 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1302 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1303 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1304}
1305/* Sub functions with one operand and one immediate */
1306#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1307 add_ca, compute_ca, compute_ov) \
b5a73f8d 1308static void glue(gen_, name)(DisasContext *ctx) \
74637406 1309{ \
b5a73f8d 1310 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1311 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1312 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1313 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1314 tcg_temp_free(t0); \
1315}
1316/* subf subf. subfo subfo. */
1317GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1318GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1319/* subfc subfc. subfco subfco. */
1320GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1321GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1322/* subfe subfe. subfeo subfo. */
1323GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1324GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1325/* subfme subfme. subfmeo subfmeo. */
1326GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1327GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1328/* subfze subfze. subfzeo subfzeo.*/
1329GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1330GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1331
54623277 1332/* subfic */
99e300ef 1333static void gen_subfic(DisasContext *ctx)
79aceca5 1334{
b5a73f8d
RH
1335 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1336 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1337 c, 0, 1, 0, 0);
1338 tcg_temp_free(c);
79aceca5
FB
1339}
1340
fd3f0081
RH
1341/* neg neg. nego nego. */
1342static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1343{
1344 TCGv zero = tcg_const_tl(0);
1345 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1346 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1347 tcg_temp_free(zero);
1348}
1349
1350static void gen_neg(DisasContext *ctx)
1351{
1352 gen_op_arith_neg(ctx, 0);
1353}
1354
1355static void gen_nego(DisasContext *ctx)
1356{
1357 gen_op_arith_neg(ctx, 1);
1358}
1359
79aceca5 1360/*** Integer logical ***/
26d67362 1361#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1362static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1363{ \
26d67362
AJ
1364 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1365 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1366 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1367 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1368}
79aceca5 1369
26d67362 1370#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1371static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1372{ \
26d67362 1373 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1374 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1375 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1376}
1377
1378/* and & and. */
26d67362 1379GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1380/* andc & andc. */
26d67362 1381GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1382
54623277 1383/* andi. */
e8eaa2c0 1384static void gen_andi_(DisasContext *ctx)
79aceca5 1385{
26d67362
AJ
1386 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1387 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1388}
e8eaa2c0 1389
54623277 1390/* andis. */
e8eaa2c0 1391static void gen_andis_(DisasContext *ctx)
79aceca5 1392{
26d67362
AJ
1393 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1394 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1395}
99e300ef 1396
54623277 1397/* cntlzw */
99e300ef 1398static void gen_cntlzw(DisasContext *ctx)
26d67362 1399{
a7812ae4 1400 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1401 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1402 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1403}
79aceca5 1404/* eqv & eqv. */
26d67362 1405GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1406/* extsb & extsb. */
26d67362 1407GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1408/* extsh & extsh. */
26d67362 1409GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1410/* nand & nand. */
26d67362 1411GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1412/* nor & nor. */
26d67362 1413GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1414
54623277 1415/* or & or. */
99e300ef 1416static void gen_or(DisasContext *ctx)
9a64fbe4 1417{
76a66253
JM
1418 int rs, ra, rb;
1419
1420 rs = rS(ctx->opcode);
1421 ra = rA(ctx->opcode);
1422 rb = rB(ctx->opcode);
1423 /* Optimisation for mr. ri case */
1424 if (rs != ra || rs != rb) {
26d67362
AJ
1425 if (rs != rb)
1426 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1427 else
1428 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1429 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1430 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1431 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1432 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1433#if defined(TARGET_PPC64)
1434 } else {
26d67362
AJ
1435 int prio = 0;
1436
c80f84e3
JM
1437 switch (rs) {
1438 case 1:
1439 /* Set process priority to low */
26d67362 1440 prio = 2;
c80f84e3
JM
1441 break;
1442 case 6:
1443 /* Set process priority to medium-low */
26d67362 1444 prio = 3;
c80f84e3
JM
1445 break;
1446 case 2:
1447 /* Set process priority to normal */
26d67362 1448 prio = 4;
c80f84e3 1449 break;
be147d08
JM
1450#if !defined(CONFIG_USER_ONLY)
1451 case 31:
76db3ba4 1452 if (ctx->mem_idx > 0) {
be147d08 1453 /* Set process priority to very low */
26d67362 1454 prio = 1;
be147d08
JM
1455 }
1456 break;
1457 case 5:
76db3ba4 1458 if (ctx->mem_idx > 0) {
be147d08 1459 /* Set process priority to medium-hight */
26d67362 1460 prio = 5;
be147d08
JM
1461 }
1462 break;
1463 case 3:
76db3ba4 1464 if (ctx->mem_idx > 0) {
be147d08 1465 /* Set process priority to high */
26d67362 1466 prio = 6;
be147d08
JM
1467 }
1468 break;
be147d08 1469 case 7:
76db3ba4 1470 if (ctx->mem_idx > 1) {
be147d08 1471 /* Set process priority to very high */
26d67362 1472 prio = 7;
be147d08
JM
1473 }
1474 break;
be147d08 1475#endif
c80f84e3
JM
1476 default:
1477 /* nop */
1478 break;
1479 }
26d67362 1480 if (prio) {
a7812ae4 1481 TCGv t0 = tcg_temp_new();
54cdcae6 1482 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1483 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1484 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1485 gen_store_spr(SPR_PPR, t0);
ea363694 1486 tcg_temp_free(t0);
26d67362 1487 }
c80f84e3 1488#endif
9a64fbe4 1489 }
9a64fbe4 1490}
79aceca5 1491/* orc & orc. */
26d67362 1492GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1493
54623277 1494/* xor & xor. */
99e300ef 1495static void gen_xor(DisasContext *ctx)
9a64fbe4 1496{
9a64fbe4 1497 /* Optimisation for "set to zero" case */
26d67362 1498 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1499 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1500 else
1501 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1502 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1503 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1504}
99e300ef 1505
54623277 1506/* ori */
99e300ef 1507static void gen_ori(DisasContext *ctx)
79aceca5 1508{
76a66253 1509 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1510
9a64fbe4
FB
1511 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1512 /* NOP */
76a66253 1513 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1514 return;
76a66253 1515 }
26d67362 1516 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1517}
99e300ef 1518
54623277 1519/* oris */
99e300ef 1520static void gen_oris(DisasContext *ctx)
79aceca5 1521{
76a66253 1522 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1523
9a64fbe4
FB
1524 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1525 /* NOP */
1526 return;
76a66253 1527 }
26d67362 1528 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1529}
99e300ef 1530
54623277 1531/* xori */
99e300ef 1532static void gen_xori(DisasContext *ctx)
79aceca5 1533{
76a66253 1534 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1535
1536 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1537 /* NOP */
1538 return;
1539 }
26d67362 1540 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1541}
99e300ef 1542
54623277 1543/* xoris */
99e300ef 1544static void gen_xoris(DisasContext *ctx)
79aceca5 1545{
76a66253 1546 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1547
1548 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1549 /* NOP */
1550 return;
1551 }
26d67362 1552 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1553}
99e300ef 1554
54623277 1555/* popcntb : PowerPC 2.03 specification */
99e300ef 1556static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1557{
eaabeef2
DG
1558 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1559}
1560
1561static void gen_popcntw(DisasContext *ctx)
1562{
1563 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1564}
1565
d9bce9d9 1566#if defined(TARGET_PPC64)
eaabeef2
DG
1567/* popcntd: PowerPC 2.06 specification */
1568static void gen_popcntd(DisasContext *ctx)
1569{
1570 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1571}
eaabeef2 1572#endif
d9bce9d9 1573
725bcec2
AJ
1574/* prtyw: PowerPC 2.05 specification */
1575static void gen_prtyw(DisasContext *ctx)
1576{
1577 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1578 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1579 TCGv t0 = tcg_temp_new();
1580 tcg_gen_shri_tl(t0, rs, 16);
1581 tcg_gen_xor_tl(ra, rs, t0);
1582 tcg_gen_shri_tl(t0, ra, 8);
1583 tcg_gen_xor_tl(ra, ra, t0);
1584 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1585 tcg_temp_free(t0);
1586}
1587
1588#if defined(TARGET_PPC64)
1589/* prtyd: PowerPC 2.05 specification */
1590static void gen_prtyd(DisasContext *ctx)
1591{
1592 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1593 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1594 TCGv t0 = tcg_temp_new();
1595 tcg_gen_shri_tl(t0, rs, 32);
1596 tcg_gen_xor_tl(ra, rs, t0);
1597 tcg_gen_shri_tl(t0, ra, 16);
1598 tcg_gen_xor_tl(ra, ra, t0);
1599 tcg_gen_shri_tl(t0, ra, 8);
1600 tcg_gen_xor_tl(ra, ra, t0);
1601 tcg_gen_andi_tl(ra, ra, 1);
1602 tcg_temp_free(t0);
1603}
1604#endif
1605
86ba37ed
TM
1606#if defined(TARGET_PPC64)
1607/* bpermd */
1608static void gen_bpermd(DisasContext *ctx)
1609{
1610 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1611 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1612}
1613#endif
1614
d9bce9d9
JM
1615#if defined(TARGET_PPC64)
1616/* extsw & extsw. */
26d67362 1617GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1618
54623277 1619/* cntlzd */
99e300ef 1620static void gen_cntlzd(DisasContext *ctx)
26d67362 1621{
a7812ae4 1622 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1623 if (unlikely(Rc(ctx->opcode) != 0))
1624 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1625}
d9bce9d9
JM
1626#endif
1627
79aceca5 1628/*** Integer rotate ***/
99e300ef 1629
54623277 1630/* rlwimi & rlwimi. */
99e300ef 1631static void gen_rlwimi(DisasContext *ctx)
79aceca5 1632{
76a66253 1633 uint32_t mb, me, sh;
79aceca5
FB
1634
1635 mb = MB(ctx->opcode);
1636 me = ME(ctx->opcode);
76a66253 1637 sh = SH(ctx->opcode);
ab92678d
TM
1638 if (likely(sh == (31-me) && mb <= me)) {
1639 tcg_gen_deposit_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1640 cpu_gpr[rS(ctx->opcode)], sh, me - mb + 1);
d03ef511 1641 } else {
d03ef511 1642 target_ulong mask;
a7812ae4
PB
1643 TCGv t1;
1644 TCGv t0 = tcg_temp_new();
54843a58 1645#if defined(TARGET_PPC64)
6ea7b35c
TM
1646 tcg_gen_deposit_i64(t0, cpu_gpr[rS(ctx->opcode)],
1647 cpu_gpr[rS(ctx->opcode)], 32, 32);
1648 tcg_gen_rotli_i64(t0, t0, sh);
54843a58
AJ
1649#else
1650 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1651#endif
76a66253 1652#if defined(TARGET_PPC64)
d03ef511
AJ
1653 mb += 32;
1654 me += 32;
76a66253 1655#endif
d03ef511 1656 mask = MASK(mb, me);
a7812ae4 1657 t1 = tcg_temp_new();
d03ef511
AJ
1658 tcg_gen_andi_tl(t0, t0, mask);
1659 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1660 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1661 tcg_temp_free(t0);
1662 tcg_temp_free(t1);
1663 }
76a66253 1664 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1665 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1666}
99e300ef 1667
54623277 1668/* rlwinm & rlwinm. */
99e300ef 1669static void gen_rlwinm(DisasContext *ctx)
79aceca5
FB
1670{
1671 uint32_t mb, me, sh;
3b46e624 1672
79aceca5
FB
1673 sh = SH(ctx->opcode);
1674 mb = MB(ctx->opcode);
1675 me = ME(ctx->opcode);
d03ef511
AJ
1676
1677 if (likely(mb == 0 && me == (31 - sh))) {
1678 if (likely(sh == 0)) {
1679 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1680 } else {
a7812ae4 1681 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1682 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1683 tcg_gen_shli_tl(t0, t0, sh);
1684 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1685 tcg_temp_free(t0);
79aceca5 1686 }
d03ef511 1687 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
a7812ae4 1688 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1689 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1690 tcg_gen_shri_tl(t0, t0, mb);
1691 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1692 tcg_temp_free(t0);
8979c2f6
TM
1693 } else if (likely(mb == 0 && me == 31)) {
1694 TCGv_i32 t0 = tcg_temp_new_i32();
1695 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rS(ctx->opcode)]);
1696 tcg_gen_rotli_i32(t0, t0, sh);
1697 tcg_gen_extu_i32_tl(cpu_gpr[rA(ctx->opcode)], t0);
1698 tcg_temp_free_i32(t0);
d03ef511 1699 } else {
a7812ae4 1700 TCGv t0 = tcg_temp_new();
54843a58 1701#if defined(TARGET_PPC64)
a7f23d0f
TM
1702 tcg_gen_deposit_i64(t0, cpu_gpr[rS(ctx->opcode)],
1703 cpu_gpr[rS(ctx->opcode)], 32, 32);
1704 tcg_gen_rotli_i64(t0, t0, sh);
54843a58
AJ
1705#else
1706 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1707#endif
76a66253 1708#if defined(TARGET_PPC64)
d03ef511
AJ
1709 mb += 32;
1710 me += 32;
76a66253 1711#endif
d03ef511
AJ
1712 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1713 tcg_temp_free(t0);
1714 }
76a66253 1715 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1716 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1717}
99e300ef 1718
54623277 1719/* rlwnm & rlwnm. */
99e300ef 1720static void gen_rlwnm(DisasContext *ctx)
79aceca5
FB
1721{
1722 uint32_t mb, me;
79aceca5
FB
1723 mb = MB(ctx->opcode);
1724 me = ME(ctx->opcode);
57fca134
TM
1725
1726 if (likely(mb == 0 && me == 31)) {
1727 TCGv_i32 t0, t1;
1728 t0 = tcg_temp_new_i32();
1729 t1 = tcg_temp_new_i32();
1730 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]);
1731 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1732 tcg_gen_andi_i32(t0, t0, 0x1f);
1733 tcg_gen_rotl_i32(t1, t1, t0);
1734 tcg_gen_extu_i32_tl(cpu_gpr[rA(ctx->opcode)], t1);
1735 tcg_temp_free_i32(t0);
1736 tcg_temp_free_i32(t1);
1737 } else {
1738 TCGv t0;
54843a58 1739#if defined(TARGET_PPC64)
57fca134 1740 TCGv t1;
54843a58 1741#endif
57fca134
TM
1742
1743 t0 = tcg_temp_new();
1744 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
76a66253 1745#if defined(TARGET_PPC64)
57fca134
TM
1746 t1 = tcg_temp_new_i64();
1747 tcg_gen_deposit_i64(t1, cpu_gpr[rS(ctx->opcode)],
1748 cpu_gpr[rS(ctx->opcode)], 32, 32);
1749 tcg_gen_rotl_i64(t0, t1, t0);
1750 tcg_temp_free_i64(t1);
1751#else
1752 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
76a66253 1753#endif
57fca134 1754 if (unlikely(mb != 0 || me != 31)) {
1c0a150f 1755#if defined(TARGET_PPC64)
57fca134
TM
1756 mb += 32;
1757 me += 32;
1c0a150f 1758#endif
57fca134
TM
1759 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1760 } else {
1761 tcg_gen_andi_tl(t0, t0, MASK(32, 63));
1762 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1763 }
1764 tcg_temp_free(t0);
79aceca5 1765 }
76a66253 1766 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1767 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5
FB
1768}
1769
d9bce9d9
JM
1770#if defined(TARGET_PPC64)
1771#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1772static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1773{ \
1774 gen_##name(ctx, 0); \
1775} \
e8eaa2c0
BS
1776 \
1777static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1778{ \
1779 gen_##name(ctx, 1); \
1780}
1781#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1782static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1783{ \
1784 gen_##name(ctx, 0, 0); \
1785} \
e8eaa2c0
BS
1786 \
1787static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1788{ \
1789 gen_##name(ctx, 0, 1); \
1790} \
e8eaa2c0
BS
1791 \
1792static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1793{ \
1794 gen_##name(ctx, 1, 0); \
1795} \
e8eaa2c0
BS
1796 \
1797static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1798{ \
1799 gen_##name(ctx, 1, 1); \
1800}
51789c41 1801
636aa200
BS
1802static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1803 uint32_t sh)
51789c41 1804{
d03ef511
AJ
1805 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1806 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1807 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1808 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1809 } else {
a7812ae4 1810 TCGv t0 = tcg_temp_new();
54843a58 1811 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
d03ef511 1812 if (likely(mb == 0 && me == 63)) {
54843a58 1813 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
d03ef511
AJ
1814 } else {
1815 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
51789c41 1816 }
d03ef511 1817 tcg_temp_free(t0);
51789c41 1818 }
51789c41 1819 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1820 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
51789c41 1821}
d9bce9d9 1822/* rldicl - rldicl. */
636aa200 1823static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1824{
51789c41 1825 uint32_t sh, mb;
d9bce9d9 1826
9d53c753
JM
1827 sh = SH(ctx->opcode) | (shn << 5);
1828 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1829 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1830}
51789c41 1831GEN_PPC64_R4(rldicl, 0x1E, 0x00);
d9bce9d9 1832/* rldicr - rldicr. */
636aa200 1833static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1834{
51789c41 1835 uint32_t sh, me;
d9bce9d9 1836
9d53c753
JM
1837 sh = SH(ctx->opcode) | (shn << 5);
1838 me = MB(ctx->opcode) | (men << 5);
51789c41 1839 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1840}
51789c41 1841GEN_PPC64_R4(rldicr, 0x1E, 0x02);
d9bce9d9 1842/* rldic - rldic. */
636aa200 1843static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1844{
51789c41 1845 uint32_t sh, mb;
d9bce9d9 1846
9d53c753
JM
1847 sh = SH(ctx->opcode) | (shn << 5);
1848 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1849 gen_rldinm(ctx, mb, 63 - sh, sh);
1850}
1851GEN_PPC64_R4(rldic, 0x1E, 0x04);
1852
636aa200 1853static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
51789c41 1854{
54843a58 1855 TCGv t0;
d03ef511 1856
a7812ae4 1857 t0 = tcg_temp_new();
d03ef511 1858 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
54843a58 1859 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
51789c41 1860 if (unlikely(mb != 0 || me != 63)) {
54843a58
AJ
1861 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1862 } else {
1863 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1864 }
1865 tcg_temp_free(t0);
51789c41 1866 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1867 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1868}
51789c41 1869
d9bce9d9 1870/* rldcl - rldcl. */
636aa200 1871static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1872{
51789c41 1873 uint32_t mb;
d9bce9d9 1874
9d53c753 1875 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1876 gen_rldnm(ctx, mb, 63);
d9bce9d9 1877}
36081602 1878GEN_PPC64_R2(rldcl, 0x1E, 0x08);
d9bce9d9 1879/* rldcr - rldcr. */
636aa200 1880static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1881{
51789c41 1882 uint32_t me;
d9bce9d9 1883
9d53c753 1884 me = MB(ctx->opcode) | (men << 5);
51789c41 1885 gen_rldnm(ctx, 0, me);
d9bce9d9 1886}
36081602 1887GEN_PPC64_R2(rldcr, 0x1E, 0x09);
d9bce9d9 1888/* rldimi - rldimi. */
636aa200 1889static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1890{
271a916e 1891 uint32_t sh, mb, me;
d9bce9d9 1892
9d53c753
JM
1893 sh = SH(ctx->opcode) | (shn << 5);
1894 mb = MB(ctx->opcode) | (mbn << 5);
271a916e 1895 me = 63 - sh;
d03ef511
AJ
1896 if (unlikely(sh == 0 && mb == 0)) {
1897 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1898 } else {
1899 TCGv t0, t1;
1900 target_ulong mask;
1901
a7812ae4 1902 t0 = tcg_temp_new();
54843a58 1903 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
a7812ae4 1904 t1 = tcg_temp_new();
d03ef511
AJ
1905 mask = MASK(mb, me);
1906 tcg_gen_andi_tl(t0, t0, mask);
1907 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1908 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1909 tcg_temp_free(t0);
1910 tcg_temp_free(t1);
51789c41 1911 }
51789c41 1912 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1913 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1914}
36081602 1915GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1916#endif
1917
79aceca5 1918/*** Integer shift ***/
99e300ef 1919
54623277 1920/* slw & slw. */
99e300ef 1921static void gen_slw(DisasContext *ctx)
26d67362 1922{
7fd6bf7d 1923 TCGv t0, t1;
26d67362 1924
7fd6bf7d
AJ
1925 t0 = tcg_temp_new();
1926 /* AND rS with a mask that is 0 when rB >= 0x20 */
1927#if defined(TARGET_PPC64)
1928 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1929 tcg_gen_sari_tl(t0, t0, 0x3f);
1930#else
1931 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1932 tcg_gen_sari_tl(t0, t0, 0x1f);
1933#endif
1934 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1935 t1 = tcg_temp_new();
1936 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1937 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1938 tcg_temp_free(t1);
fea0c503 1939 tcg_temp_free(t0);
7fd6bf7d 1940 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1941 if (unlikely(Rc(ctx->opcode) != 0))
1942 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1943}
99e300ef 1944
54623277 1945/* sraw & sraw. */
99e300ef 1946static void gen_sraw(DisasContext *ctx)
26d67362 1947{
d15f74fb 1948 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1949 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1950 if (unlikely(Rc(ctx->opcode) != 0))
1951 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1952}
99e300ef 1953
54623277 1954/* srawi & srawi. */
99e300ef 1955static void gen_srawi(DisasContext *ctx)
79aceca5 1956{
26d67362 1957 int sh = SH(ctx->opcode);
ba4af3e4
RH
1958 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1959 TCGv src = cpu_gpr[rS(ctx->opcode)];
1960 if (sh == 0) {
34a0fad1 1961 tcg_gen_ext32s_tl(dst, src);
da91a00f 1962 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1963 } else {
ba4af3e4
RH
1964 TCGv t0;
1965 tcg_gen_ext32s_tl(dst, src);
1966 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1967 t0 = tcg_temp_new();
1968 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1969 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1970 tcg_temp_free(t0);
1971 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1972 tcg_gen_sari_tl(dst, dst, sh);
1973 }
1974 if (unlikely(Rc(ctx->opcode) != 0)) {
1975 gen_set_Rc0(ctx, dst);
d9bce9d9 1976 }
79aceca5 1977}
99e300ef 1978
54623277 1979/* srw & srw. */
99e300ef 1980static void gen_srw(DisasContext *ctx)
26d67362 1981{
fea0c503 1982 TCGv t0, t1;
d9bce9d9 1983
7fd6bf7d
AJ
1984 t0 = tcg_temp_new();
1985 /* AND rS with a mask that is 0 when rB >= 0x20 */
1986#if defined(TARGET_PPC64)
1987 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1988 tcg_gen_sari_tl(t0, t0, 0x3f);
1989#else
1990 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1991 tcg_gen_sari_tl(t0, t0, 0x1f);
1992#endif
1993 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1994 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1995 t1 = tcg_temp_new();
7fd6bf7d
AJ
1996 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1997 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1998 tcg_temp_free(t1);
fea0c503 1999 tcg_temp_free(t0);
26d67362
AJ
2000 if (unlikely(Rc(ctx->opcode) != 0))
2001 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2002}
54623277 2003
d9bce9d9
JM
2004#if defined(TARGET_PPC64)
2005/* sld & sld. */
99e300ef 2006static void gen_sld(DisasContext *ctx)
26d67362 2007{
7fd6bf7d 2008 TCGv t0, t1;
26d67362 2009
7fd6bf7d
AJ
2010 t0 = tcg_temp_new();
2011 /* AND rS with a mask that is 0 when rB >= 0x40 */
2012 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2013 tcg_gen_sari_tl(t0, t0, 0x3f);
2014 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2015 t1 = tcg_temp_new();
2016 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2017 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2018 tcg_temp_free(t1);
fea0c503 2019 tcg_temp_free(t0);
26d67362
AJ
2020 if (unlikely(Rc(ctx->opcode) != 0))
2021 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2022}
99e300ef 2023
54623277 2024/* srad & srad. */
99e300ef 2025static void gen_srad(DisasContext *ctx)
26d67362 2026{
d15f74fb 2027 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 2028 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
2029 if (unlikely(Rc(ctx->opcode) != 0))
2030 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2031}
d9bce9d9 2032/* sradi & sradi. */
636aa200 2033static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 2034{
26d67362 2035 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
2036 TCGv dst = cpu_gpr[rA(ctx->opcode)];
2037 TCGv src = cpu_gpr[rS(ctx->opcode)];
2038 if (sh == 0) {
2039 tcg_gen_mov_tl(dst, src);
da91a00f 2040 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 2041 } else {
ba4af3e4
RH
2042 TCGv t0;
2043 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
2044 t0 = tcg_temp_new();
2045 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
2046 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
2047 tcg_temp_free(t0);
2048 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
2049 tcg_gen_sari_tl(dst, src, sh);
2050 }
2051 if (unlikely(Rc(ctx->opcode) != 0)) {
2052 gen_set_Rc0(ctx, dst);
d9bce9d9 2053 }
d9bce9d9 2054}
e8eaa2c0
BS
2055
2056static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
2057{
2058 gen_sradi(ctx, 0);
2059}
e8eaa2c0
BS
2060
2061static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
2062{
2063 gen_sradi(ctx, 1);
2064}
99e300ef 2065
54623277 2066/* srd & srd. */
99e300ef 2067static void gen_srd(DisasContext *ctx)
26d67362 2068{
7fd6bf7d 2069 TCGv t0, t1;
26d67362 2070
7fd6bf7d
AJ
2071 t0 = tcg_temp_new();
2072 /* AND rS with a mask that is 0 when rB >= 0x40 */
2073 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2074 tcg_gen_sari_tl(t0, t0, 0x3f);
2075 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2076 t1 = tcg_temp_new();
2077 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2078 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2079 tcg_temp_free(t1);
fea0c503 2080 tcg_temp_free(t0);
26d67362
AJ
2081 if (unlikely(Rc(ctx->opcode) != 0))
2082 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2083}
d9bce9d9 2084#endif
79aceca5
FB
2085
2086/*** Floating-Point arithmetic ***/
7c58044c 2087#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 2088static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2089{ \
76a66253 2090 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2091 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2092 return; \
2093 } \
eb44b959
AJ
2094 /* NIP cannot be restored if the memory exception comes from an helper */ \
2095 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2096 gen_reset_fpstatus(); \
8e703949
BS
2097 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2098 cpu_fpr[rA(ctx->opcode)], \
af12906f 2099 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2100 if (isfloat) { \
8e703949
BS
2101 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2102 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2103 } \
af12906f
AJ
2104 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2105 Rc(ctx->opcode) != 0); \
9a64fbe4
FB
2106}
2107
7c58044c
JM
2108#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2109_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2110_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2111
7c58044c 2112#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2113static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2114{ \
76a66253 2115 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2116 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2117 return; \
2118 } \
eb44b959
AJ
2119 /* NIP cannot be restored if the memory exception comes from an helper */ \
2120 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2121 gen_reset_fpstatus(); \
8e703949
BS
2122 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2123 cpu_fpr[rA(ctx->opcode)], \
af12906f 2124 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2125 if (isfloat) { \
8e703949
BS
2126 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2127 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2128 } \
af12906f
AJ
2129 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2130 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2131}
7c58044c
JM
2132#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2133_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2134_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2135
7c58044c 2136#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2137static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2138{ \
76a66253 2139 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2140 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2141 return; \
2142 } \
eb44b959
AJ
2143 /* NIP cannot be restored if the memory exception comes from an helper */ \
2144 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2145 gen_reset_fpstatus(); \
8e703949
BS
2146 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2147 cpu_fpr[rA(ctx->opcode)], \
2148 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2149 if (isfloat) { \
8e703949
BS
2150 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2151 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2152 } \
af12906f
AJ
2153 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2154 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2155}
7c58044c
JM
2156#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2157_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2158_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2159
7c58044c 2160#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2161static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2162{ \
76a66253 2163 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2164 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2165 return; \
2166 } \
eb44b959
AJ
2167 /* NIP cannot be restored if the memory exception comes from an helper */ \
2168 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2169 gen_reset_fpstatus(); \
8e703949
BS
2170 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2171 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2172 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2173 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2174}
2175
7c58044c 2176#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2177static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2178{ \
76a66253 2179 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2180 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2181 return; \
2182 } \
eb44b959
AJ
2183 /* NIP cannot be restored if the memory exception comes from an helper */ \
2184 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2185 gen_reset_fpstatus(); \
8e703949
BS
2186 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2187 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2188 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2189 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2190}
2191
9a64fbe4 2192/* fadd - fadds */
7c58044c 2193GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2194/* fdiv - fdivs */
7c58044c 2195GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2196/* fmul - fmuls */
7c58044c 2197GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2198
d7e4b87e 2199/* fre */
7c58044c 2200GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2201
a750fc0b 2202/* fres */
7c58044c 2203GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2204
a750fc0b 2205/* frsqrte */
7c58044c
JM
2206GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2207
2208/* frsqrtes */
99e300ef 2209static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2210{
af12906f 2211 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2212 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2213 return;
2214 }
eb44b959
AJ
2215 /* NIP cannot be restored if the memory exception comes from an helper */
2216 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2217 gen_reset_fpstatus();
8e703949
BS
2218 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2219 cpu_fpr[rB(ctx->opcode)]);
2220 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2221 cpu_fpr[rD(ctx->opcode)]);
af12906f 2222 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
7c58044c 2223}
79aceca5 2224
a750fc0b 2225/* fsel */
7c58044c 2226_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2227/* fsub - fsubs */
7c58044c 2228GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2229/* Optional: */
99e300ef 2230
54623277 2231/* fsqrt */
99e300ef 2232static void gen_fsqrt(DisasContext *ctx)
c7d344af 2233{
76a66253 2234 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2235 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2236 return;
2237 }
eb44b959
AJ
2238 /* NIP cannot be restored if the memory exception comes from an helper */
2239 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2240 gen_reset_fpstatus();
8e703949
BS
2241 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2242 cpu_fpr[rB(ctx->opcode)]);
af12906f 2243 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
c7d344af 2244}
79aceca5 2245
99e300ef 2246static void gen_fsqrts(DisasContext *ctx)
79aceca5 2247{
76a66253 2248 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2249 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2250 return;
2251 }
eb44b959
AJ
2252 /* NIP cannot be restored if the memory exception comes from an helper */
2253 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2254 gen_reset_fpstatus();
8e703949
BS
2255 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2256 cpu_fpr[rB(ctx->opcode)]);
2257 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2258 cpu_fpr[rD(ctx->opcode)]);
af12906f 2259 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
79aceca5
FB
2260}
2261
2262/*** Floating-Point multiply-and-add ***/
4ecc3190 2263/* fmadd - fmadds */
7c58044c 2264GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2265/* fmsub - fmsubs */
7c58044c 2266GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2267/* fnmadd - fnmadds */
7c58044c 2268GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2269/* fnmsub - fnmsubs */
7c58044c 2270GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2271
2272/*** Floating-Point round & convert ***/
2273/* fctiw */
7c58044c 2274GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2275/* fctiwu */
2276GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2277/* fctiwz */
7c58044c 2278GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2279/* fctiwuz */
2280GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2281/* frsp */
7c58044c 2282GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db
JM
2283#if defined(TARGET_PPC64)
2284/* fcfid */
7c58044c 2285GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
28288b48
TM
2286/* fcfids */
2287GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2288/* fcfidu */
2289GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2290/* fcfidus */
2291GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
426613db 2292/* fctid */
7c58044c 2293GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
fab7fe42
TM
2294/* fctidu */
2295GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2296/* fctidz */
7c58044c 2297GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
fab7fe42
TM
2298/* fctidu */
2299GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2300#endif
79aceca5 2301
d7e4b87e 2302/* frin */
7c58044c 2303GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2304/* friz */
7c58044c 2305GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2306/* frip */
7c58044c 2307GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2308/* frim */
7c58044c 2309GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2310
da29cb7b
TM
2311static void gen_ftdiv(DisasContext *ctx)
2312{
2313 if (unlikely(!ctx->fpu_enabled)) {
2314 gen_exception(ctx, POWERPC_EXCP_FPU);
2315 return;
2316 }
2317 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2318 cpu_fpr[rB(ctx->opcode)]);
2319}
2320
6d41d146
TM
2321static void gen_ftsqrt(DisasContext *ctx)
2322{
2323 if (unlikely(!ctx->fpu_enabled)) {
2324 gen_exception(ctx, POWERPC_EXCP_FPU);
2325 return;
2326 }
2327 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2328}
2329
da29cb7b
TM
2330
2331
79aceca5 2332/*** Floating-Point compare ***/
99e300ef 2333
54623277 2334/* fcmpo */
99e300ef 2335static void gen_fcmpo(DisasContext *ctx)
79aceca5 2336{
330c483b 2337 TCGv_i32 crf;
76a66253 2338 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2339 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2340 return;
2341 }
eb44b959
AJ
2342 /* NIP cannot be restored if the memory exception comes from an helper */
2343 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2344 gen_reset_fpstatus();
9a819377 2345 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2346 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2347 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2348 tcg_temp_free_i32(crf);
8e703949 2349 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2350}
2351
2352/* fcmpu */
99e300ef 2353static void gen_fcmpu(DisasContext *ctx)
79aceca5 2354{
330c483b 2355 TCGv_i32 crf;
76a66253 2356 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2357 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2358 return;
2359 }
eb44b959
AJ
2360 /* NIP cannot be restored if the memory exception comes from an helper */
2361 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2362 gen_reset_fpstatus();
9a819377 2363 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2364 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2365 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2366 tcg_temp_free_i32(crf);
8e703949 2367 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2368}
2369
9a64fbe4
FB
2370/*** Floating-point move ***/
2371/* fabs */
7c58044c 2372/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2373static void gen_fabs(DisasContext *ctx)
2374{
2375 if (unlikely(!ctx->fpu_enabled)) {
2376 gen_exception(ctx, POWERPC_EXCP_FPU);
2377 return;
2378 }
2379 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2380 ~(1ULL << 63));
2381 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2382}
9a64fbe4
FB
2383
2384/* fmr - fmr. */
7c58044c 2385/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2386static void gen_fmr(DisasContext *ctx)
9a64fbe4 2387{
76a66253 2388 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2389 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2390 return;
2391 }
af12906f
AJ
2392 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2393 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
9a64fbe4
FB
2394}
2395
2396/* fnabs */
7c58044c 2397/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2398static void gen_fnabs(DisasContext *ctx)
2399{
2400 if (unlikely(!ctx->fpu_enabled)) {
2401 gen_exception(ctx, POWERPC_EXCP_FPU);
2402 return;
2403 }
2404 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2405 1ULL << 63);
2406 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2407}
2408
9a64fbe4 2409/* fneg */
7c58044c 2410/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2411static void gen_fneg(DisasContext *ctx)
2412{
2413 if (unlikely(!ctx->fpu_enabled)) {
2414 gen_exception(ctx, POWERPC_EXCP_FPU);
2415 return;
2416 }
2417 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2418 1ULL << 63);
2419 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2420}
9a64fbe4 2421
f0332888
AJ
2422/* fcpsgn: PowerPC 2.05 specification */
2423/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2424static void gen_fcpsgn(DisasContext *ctx)
2425{
2426 if (unlikely(!ctx->fpu_enabled)) {
2427 gen_exception(ctx, POWERPC_EXCP_FPU);
2428 return;
2429 }
2430 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2431 cpu_fpr[rB(ctx->opcode)], 0, 63);
2432 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2433}
2434
097ec5d8
TM
2435static void gen_fmrgew(DisasContext *ctx)
2436{
2437 TCGv_i64 b0;
2438 if (unlikely(!ctx->fpu_enabled)) {
2439 gen_exception(ctx, POWERPC_EXCP_FPU);
2440 return;
2441 }
2442 b0 = tcg_temp_new_i64();
2443 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2444 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2445 b0, 0, 32);
2446 tcg_temp_free_i64(b0);
2447}
2448
2449static void gen_fmrgow(DisasContext *ctx)
2450{
2451 if (unlikely(!ctx->fpu_enabled)) {
2452 gen_exception(ctx, POWERPC_EXCP_FPU);
2453 return;
2454 }
2455 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2456 cpu_fpr[rB(ctx->opcode)],
2457 cpu_fpr[rA(ctx->opcode)],
2458 32, 32);
2459}
2460
79aceca5 2461/*** Floating-Point status & ctrl register ***/
99e300ef 2462
54623277 2463/* mcrfs */
99e300ef 2464static void gen_mcrfs(DisasContext *ctx)
79aceca5 2465{
30304420 2466 TCGv tmp = tcg_temp_new();
7c58044c
JM
2467 int bfa;
2468
76a66253 2469 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2470 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2471 return;
2472 }
7c58044c 2473 bfa = 4 * (7 - crfS(ctx->opcode));
30304420
DG
2474 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2475 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2476 tcg_temp_free(tmp);
e1571908 2477 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
30304420 2478 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
79aceca5
FB
2479}
2480
2481/* mffs */
99e300ef 2482static void gen_mffs(DisasContext *ctx)
79aceca5 2483{
76a66253 2484 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2485 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2486 return;
2487 }
7c58044c 2488 gen_reset_fpstatus();
30304420 2489 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
af12906f 2490 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
79aceca5
FB
2491}
2492
2493/* mtfsb0 */
99e300ef 2494static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2495{
fb0eaffc 2496 uint8_t crb;
3b46e624 2497
76a66253 2498 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2499 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2500 return;
2501 }
6e35d524 2502 crb = 31 - crbD(ctx->opcode);
7c58044c 2503 gen_reset_fpstatus();
6e35d524 2504 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2505 TCGv_i32 t0;
2506 /* NIP cannot be restored if the memory exception comes from an helper */
2507 gen_update_nip(ctx, ctx->nip - 4);
2508 t0 = tcg_const_i32(crb);
8e703949 2509 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2510 tcg_temp_free_i32(t0);
2511 }
7c58044c 2512 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2513 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2514 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2515 }
79aceca5
FB
2516}
2517
2518/* mtfsb1 */
99e300ef 2519static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2520{
fb0eaffc 2521 uint8_t crb;
3b46e624 2522
76a66253 2523 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2524 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2525 return;
2526 }
6e35d524 2527 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2528 gen_reset_fpstatus();
2529 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2530 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2531 TCGv_i32 t0;
2532 /* NIP cannot be restored if the memory exception comes from an helper */
2533 gen_update_nip(ctx, ctx->nip - 4);
2534 t0 = tcg_const_i32(crb);
8e703949 2535 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2536 tcg_temp_free_i32(t0);
af12906f 2537 }
7c58044c 2538 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2539 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2540 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2541 }
2542 /* We can raise a differed exception */
8e703949 2543 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2544}
2545
2546/* mtfsf */
99e300ef 2547static void gen_mtfsf(DisasContext *ctx)
79aceca5 2548{
0f2f39c2 2549 TCGv_i32 t0;
7d08d856 2550 int flm, l, w;
af12906f 2551
76a66253 2552 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2553 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2554 return;
2555 }
7d08d856
AJ
2556 flm = FPFLM(ctx->opcode);
2557 l = FPL(ctx->opcode);
2558 w = FPW(ctx->opcode);
2559 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2560 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2561 return;
2562 }
eb44b959
AJ
2563 /* NIP cannot be restored if the memory exception comes from an helper */
2564 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2565 gen_reset_fpstatus();
7d08d856
AJ
2566 if (l) {
2567 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2568 } else {
2569 t0 = tcg_const_i32(flm << (w * 8));
2570 }
8e703949 2571 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2572 tcg_temp_free_i32(t0);
7c58044c 2573 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2574 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2575 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2576 }
2577 /* We can raise a differed exception */
8e703949 2578 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2579}
2580
2581/* mtfsfi */
99e300ef 2582static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2583{
7d08d856 2584 int bf, sh, w;
0f2f39c2
AJ
2585 TCGv_i64 t0;
2586 TCGv_i32 t1;
7c58044c 2587
76a66253 2588 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2589 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2590 return;
2591 }
7d08d856
AJ
2592 w = FPW(ctx->opcode);
2593 bf = FPBF(ctx->opcode);
2594 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2595 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2596 return;
2597 }
2598 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2599 /* NIP cannot be restored if the memory exception comes from an helper */
2600 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2601 gen_reset_fpstatus();
7d08d856 2602 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2603 t1 = tcg_const_i32(1 << sh);
8e703949 2604 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2605 tcg_temp_free_i64(t0);
2606 tcg_temp_free_i32(t1);
7c58044c 2607 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2608 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2609 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2610 }
2611 /* We can raise a differed exception */
8e703949 2612 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2613}
2614
76a66253
JM
2615/*** Addressing modes ***/
2616/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2617static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2618 target_long maskl)
76a66253
JM
2619{
2620 target_long simm = SIMM(ctx->opcode);
2621
be147d08 2622 simm &= ~maskl;
76db3ba4 2623 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2624 if (NARROW_MODE(ctx)) {
2625 simm = (uint32_t)simm;
2626 }
e2be8d8d 2627 tcg_gen_movi_tl(EA, simm);
76db3ba4 2628 } else if (likely(simm != 0)) {
e2be8d8d 2629 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2630 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2631 tcg_gen_ext32u_tl(EA, EA);
2632 }
76db3ba4 2633 } else {
c791fe84 2634 if (NARROW_MODE(ctx)) {
76db3ba4 2635 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2636 } else {
2637 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2638 }
76db3ba4 2639 }
76a66253
JM
2640}
2641
636aa200 2642static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2643{
76db3ba4 2644 if (rA(ctx->opcode) == 0) {
c791fe84 2645 if (NARROW_MODE(ctx)) {
76db3ba4 2646 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2647 } else {
2648 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2649 }
76db3ba4 2650 } else {
e2be8d8d 2651 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2652 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2653 tcg_gen_ext32u_tl(EA, EA);
2654 }
76db3ba4 2655 }
76a66253
JM
2656}
2657
636aa200 2658static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2659{
76db3ba4 2660 if (rA(ctx->opcode) == 0) {
e2be8d8d 2661 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2662 } else if (NARROW_MODE(ctx)) {
2663 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2664 } else {
c791fe84 2665 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2666 }
2667}
2668
636aa200
BS
2669static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2670 target_long val)
76db3ba4
AJ
2671{
2672 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2673 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2674 tcg_gen_ext32u_tl(ret, ret);
2675 }
76a66253
JM
2676}
2677
636aa200 2678static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32
AJ
2679{
2680 int l1 = gen_new_label();
2681 TCGv t0 = tcg_temp_new();
2682 TCGv_i32 t1, t2;
2683 /* NIP cannot be restored if the memory exception comes from an helper */
2684 gen_update_nip(ctx, ctx->nip - 4);
2685 tcg_gen_andi_tl(t0, EA, mask);
2686 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2687 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2688 t2 = tcg_const_i32(0);
e5f17ac6 2689 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2690 tcg_temp_free_i32(t1);
2691 tcg_temp_free_i32(t2);
2692 gen_set_label(l1);
2693 tcg_temp_free(t0);
2694}
2695
7863667f 2696/*** Integer load ***/
636aa200 2697static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2698{
2699 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2700}
2701
636aa200 2702static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4 2703{
e22c357b
DK
2704 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2705 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2706}
2707
636aa200 2708static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2709{
e22c357b
DK
2710 TCGMemOp op = MO_SW | ctx->default_tcg_memop_mask;
2711 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2712}
2713
636aa200 2714static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2715{
e22c357b
DK
2716 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2717 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2718}
2719
f976b09e
AG
2720static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2721{
2722 TCGv tmp = tcg_temp_new();
2723 gen_qemu_ld32u(ctx, tmp, addr);
2724 tcg_gen_extu_tl_i64(val, tmp);
2725 tcg_temp_free(tmp);
2726}
2727
636aa200 2728static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2729{
e22c357b
DK
2730 TCGMemOp op = MO_SL | ctx->default_tcg_memop_mask;
2731 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2732}
2733
cac7f0ba
TM
2734static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2735{
2736 TCGv tmp = tcg_temp_new();
2737 gen_qemu_ld32s(ctx, tmp, addr);
2738 tcg_gen_ext_tl_i64(val, tmp);
2739 tcg_temp_free(tmp);
2740}
2741
636aa200 2742static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2743{
e22c357b
DK
2744 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2745 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2746}
2747
636aa200 2748static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2749{
76db3ba4 2750 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2751}
2752
636aa200 2753static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2754{
e22c357b
DK
2755 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2756 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2757}
2758
636aa200 2759static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2760{
e22c357b
DK
2761 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2762 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2763}
2764
f976b09e
AG
2765static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2766{
2767 TCGv tmp = tcg_temp_new();
2768 tcg_gen_trunc_i64_tl(tmp, val);
2769 gen_qemu_st32(ctx, tmp, addr);
2770 tcg_temp_free(tmp);
2771}
2772
636aa200 2773static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2774{
e22c357b
DK
2775 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2776 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2777}
2778
0c8aacd4 2779#define GEN_LD(name, ldop, opc, type) \
99e300ef 2780static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2781{ \
76db3ba4
AJ
2782 TCGv EA; \
2783 gen_set_access_type(ctx, ACCESS_INT); \
2784 EA = tcg_temp_new(); \
2785 gen_addr_imm_index(ctx, EA, 0); \
2786 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2787 tcg_temp_free(EA); \
79aceca5
FB
2788}
2789
0c8aacd4 2790#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2791static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2792{ \
b61f2753 2793 TCGv EA; \
76a66253
JM
2794 if (unlikely(rA(ctx->opcode) == 0 || \
2795 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2796 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2797 return; \
9a64fbe4 2798 } \
76db3ba4 2799 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2800 EA = tcg_temp_new(); \
9d53c753 2801 if (type == PPC_64B) \
76db3ba4 2802 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2803 else \
76db3ba4
AJ
2804 gen_addr_imm_index(ctx, EA, 0); \
2805 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2806 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2807 tcg_temp_free(EA); \
79aceca5
FB
2808}
2809
0c8aacd4 2810#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2811static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2812{ \
b61f2753 2813 TCGv EA; \
76a66253
JM
2814 if (unlikely(rA(ctx->opcode) == 0 || \
2815 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2816 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2817 return; \
9a64fbe4 2818 } \
76db3ba4 2819 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2820 EA = tcg_temp_new(); \
76db3ba4
AJ
2821 gen_addr_reg_index(ctx, EA); \
2822 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2823 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2824 tcg_temp_free(EA); \
79aceca5
FB
2825}
2826
cd6e9320 2827#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2828static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2829{ \
76db3ba4
AJ
2830 TCGv EA; \
2831 gen_set_access_type(ctx, ACCESS_INT); \
2832 EA = tcg_temp_new(); \
2833 gen_addr_reg_index(ctx, EA); \
2834 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2835 tcg_temp_free(EA); \
79aceca5 2836}
cd6e9320
TH
2837#define GEN_LDX(name, ldop, opc2, opc3, type) \
2838 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2839
0c8aacd4
AJ
2840#define GEN_LDS(name, ldop, op, type) \
2841GEN_LD(name, ldop, op | 0x20, type); \
2842GEN_LDU(name, ldop, op | 0x21, type); \
2843GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2844GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2845
2846/* lbz lbzu lbzux lbzx */
0c8aacd4 2847GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2848/* lha lhau lhaux lhax */
0c8aacd4 2849GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2850/* lhz lhzu lhzux lhzx */
0c8aacd4 2851GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2852/* lwz lwzu lwzux lwzx */
0c8aacd4 2853GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2854#if defined(TARGET_PPC64)
d9bce9d9 2855/* lwaux */
0c8aacd4 2856GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2857/* lwax */
0c8aacd4 2858GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2859/* ldux */
0c8aacd4 2860GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2861/* ldx */
0c8aacd4 2862GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2863
2864static void gen_ld(DisasContext *ctx)
d9bce9d9 2865{
b61f2753 2866 TCGv EA;
d9bce9d9
JM
2867 if (Rc(ctx->opcode)) {
2868 if (unlikely(rA(ctx->opcode) == 0 ||
2869 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2870 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2871 return;
2872 }
2873 }
76db3ba4 2874 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2875 EA = tcg_temp_new();
76db3ba4 2876 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2877 if (ctx->opcode & 0x02) {
2878 /* lwa (lwau is undefined) */
76db3ba4 2879 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2880 } else {
2881 /* ld - ldu */
76db3ba4 2882 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2883 }
d9bce9d9 2884 if (Rc(ctx->opcode))
b61f2753
AJ
2885 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2886 tcg_temp_free(EA);
d9bce9d9 2887}
99e300ef 2888
54623277 2889/* lq */
99e300ef 2890static void gen_lq(DisasContext *ctx)
be147d08 2891{
be147d08 2892 int ra, rd;
b61f2753 2893 TCGv EA;
be147d08 2894
e0498daa
TM
2895 /* lq is a legal user mode instruction starting in ISA 2.07 */
2896 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2897 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2898
2899 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 2900 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2901 return;
2902 }
e0498daa
TM
2903
2904 if (!le_is_supported && ctx->le_mode) {
2905 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2906 return;
2907 }
2908
be147d08
JM
2909 ra = rA(ctx->opcode);
2910 rd = rD(ctx->opcode);
2911 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2912 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2913 return;
2914 }
e0498daa 2915
76db3ba4 2916 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2917 EA = tcg_temp_new();
76db3ba4 2918 gen_addr_imm_index(ctx, EA, 0x0F);
e0498daa 2919
e22c357b
DK
2920 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
2921 64-bit byteswap already. */
e0498daa
TM
2922 if (unlikely(ctx->le_mode)) {
2923 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2924 gen_addr_add(ctx, EA, EA, 8);
2925 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2926 } else {
2927 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2928 gen_addr_add(ctx, EA, EA, 8);
2929 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2930 }
b61f2753 2931 tcg_temp_free(EA);
be147d08 2932}
d9bce9d9 2933#endif
79aceca5
FB
2934
2935/*** Integer store ***/
0c8aacd4 2936#define GEN_ST(name, stop, opc, type) \
99e300ef 2937static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2938{ \
76db3ba4
AJ
2939 TCGv EA; \
2940 gen_set_access_type(ctx, ACCESS_INT); \
2941 EA = tcg_temp_new(); \
2942 gen_addr_imm_index(ctx, EA, 0); \
2943 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2944 tcg_temp_free(EA); \
79aceca5
FB
2945}
2946
0c8aacd4 2947#define GEN_STU(name, stop, opc, type) \
99e300ef 2948static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2949{ \
b61f2753 2950 TCGv EA; \
76a66253 2951 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2952 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2953 return; \
9a64fbe4 2954 } \
76db3ba4 2955 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2956 EA = tcg_temp_new(); \
9d53c753 2957 if (type == PPC_64B) \
76db3ba4 2958 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2959 else \
76db3ba4
AJ
2960 gen_addr_imm_index(ctx, EA, 0); \
2961 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2962 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2963 tcg_temp_free(EA); \
79aceca5
FB
2964}
2965
0c8aacd4 2966#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2967static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2968{ \
b61f2753 2969 TCGv EA; \
76a66253 2970 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2971 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2972 return; \
9a64fbe4 2973 } \
76db3ba4 2974 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2975 EA = tcg_temp_new(); \
76db3ba4
AJ
2976 gen_addr_reg_index(ctx, EA); \
2977 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2978 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2979 tcg_temp_free(EA); \
79aceca5
FB
2980}
2981
cd6e9320
TH
2982#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2983static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2984{ \
76db3ba4
AJ
2985 TCGv EA; \
2986 gen_set_access_type(ctx, ACCESS_INT); \
2987 EA = tcg_temp_new(); \
2988 gen_addr_reg_index(ctx, EA); \
2989 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2990 tcg_temp_free(EA); \
79aceca5 2991}
cd6e9320
TH
2992#define GEN_STX(name, stop, opc2, opc3, type) \
2993 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 2994
0c8aacd4
AJ
2995#define GEN_STS(name, stop, op, type) \
2996GEN_ST(name, stop, op | 0x20, type); \
2997GEN_STU(name, stop, op | 0x21, type); \
2998GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2999GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
3000
3001/* stb stbu stbux stbx */
0c8aacd4 3002GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 3003/* sth sthu sthux sthx */
0c8aacd4 3004GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 3005/* stw stwu stwux stwx */
0c8aacd4 3006GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 3007#if defined(TARGET_PPC64)
0c8aacd4
AJ
3008GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
3009GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
3010
3011static void gen_std(DisasContext *ctx)
d9bce9d9 3012{
be147d08 3013 int rs;
b61f2753 3014 TCGv EA;
be147d08
JM
3015
3016 rs = rS(ctx->opcode);
84cab1e2
TM
3017 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3018
3019 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3020 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3021
3022 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 3023 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3024 return;
3025 }
84cab1e2
TM
3026
3027 if (!le_is_supported && ctx->le_mode) {
3028 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
d9bce9d9
JM
3029 return;
3030 }
84cab1e2
TM
3031
3032 if (unlikely(rs & 1)) {
3033 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3034 return;
3035 }
76db3ba4 3036 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3037 EA = tcg_temp_new();
76db3ba4 3038 gen_addr_imm_index(ctx, EA, 0x03);
84cab1e2 3039
e22c357b
DK
3040 /* We only need to swap high and low halves. gen_qemu_st64 does
3041 necessary 64-bit byteswap already. */
84cab1e2
TM
3042 if (unlikely(ctx->le_mode)) {
3043 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3044 gen_addr_add(ctx, EA, EA, 8);
3045 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3046 } else {
3047 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3048 gen_addr_add(ctx, EA, EA, 8);
3049 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3050 }
b61f2753 3051 tcg_temp_free(EA);
be147d08 3052 } else {
84cab1e2 3053 /* std / stdu*/
be147d08
JM
3054 if (Rc(ctx->opcode)) {
3055 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 3056 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3057 return;
3058 }
3059 }
76db3ba4 3060 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3061 EA = tcg_temp_new();
76db3ba4
AJ
3062 gen_addr_imm_index(ctx, EA, 0x03);
3063 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 3064 if (Rc(ctx->opcode))
b61f2753
AJ
3065 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3066 tcg_temp_free(EA);
d9bce9d9 3067 }
d9bce9d9
JM
3068}
3069#endif
79aceca5 3070/*** Integer load and store with byte reverse ***/
e22c357b 3071
79aceca5 3072/* lhbrx */
86178a57 3073static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3074{
e22c357b
DK
3075 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3076 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3077}
0c8aacd4 3078GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 3079
79aceca5 3080/* lwbrx */
86178a57 3081static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3082{
e22c357b
DK
3083 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3084 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3085}
0c8aacd4 3086GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 3087
cd6e9320
TH
3088#if defined(TARGET_PPC64)
3089/* ldbrx */
3090static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3091{
e22c357b
DK
3092 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3093 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
cd6e9320
TH
3094}
3095GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3096#endif /* TARGET_PPC64 */
3097
79aceca5 3098/* sthbrx */
86178a57 3099static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3100{
e22c357b
DK
3101 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3102 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
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{
e22c357b
DK
3109 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3110 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3111}
0c8aacd4 3112GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 3113
cd6e9320
TH
3114#if defined(TARGET_PPC64)
3115/* stdbrx */
3116static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3117{
e22c357b
DK
3118 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3119 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
cd6e9320
TH
3120}
3121GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3122#endif /* TARGET_PPC64 */
3123
79aceca5 3124/*** Integer load and store multiple ***/
99e300ef 3125
54623277 3126/* lmw */
99e300ef 3127static void gen_lmw(DisasContext *ctx)
79aceca5 3128{
76db3ba4
AJ
3129 TCGv t0;
3130 TCGv_i32 t1;
3131 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3132 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3133 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3134 t0 = tcg_temp_new();
3135 t1 = tcg_const_i32(rD(ctx->opcode));
3136 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3137 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3138 tcg_temp_free(t0);
3139 tcg_temp_free_i32(t1);
79aceca5
FB
3140}
3141
3142/* stmw */
99e300ef 3143static void gen_stmw(DisasContext *ctx)
79aceca5 3144{
76db3ba4
AJ
3145 TCGv t0;
3146 TCGv_i32 t1;
3147 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3148 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3149 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3150 t0 = tcg_temp_new();
3151 t1 = tcg_const_i32(rS(ctx->opcode));
3152 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3153 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3154 tcg_temp_free(t0);
3155 tcg_temp_free_i32(t1);
79aceca5
FB
3156}
3157
3158/*** Integer load and store strings ***/
54623277 3159
79aceca5 3160/* lswi */
3fc6c082 3161/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3162 * rA is in the range of registers to be loaded.
3163 * In an other hand, IBM says this is valid, but rA won't be loaded.
3164 * For now, I'll follow the spec...
3165 */
99e300ef 3166static void gen_lswi(DisasContext *ctx)
79aceca5 3167{
dfbc799d
AJ
3168 TCGv t0;
3169 TCGv_i32 t1, t2;
79aceca5
FB
3170 int nb = NB(ctx->opcode);
3171 int start = rD(ctx->opcode);
9a64fbe4 3172 int ra = rA(ctx->opcode);
79aceca5
FB
3173 int nr;
3174
3175 if (nb == 0)
3176 nb = 32;
3177 nr = nb / 4;
76a66253
JM
3178 if (unlikely(((start + nr) > 32 &&
3179 start <= ra && (start + nr - 32) > ra) ||
3180 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
e06fcd75 3181 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3182 return;
297d8e62 3183 }
76db3ba4 3184 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3185 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3186 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3187 t0 = tcg_temp_new();
76db3ba4 3188 gen_addr_register(ctx, t0);
dfbc799d
AJ
3189 t1 = tcg_const_i32(nb);
3190 t2 = tcg_const_i32(start);
2f5a189c 3191 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3192 tcg_temp_free(t0);
3193 tcg_temp_free_i32(t1);
3194 tcg_temp_free_i32(t2);
79aceca5
FB
3195}
3196
3197/* lswx */
99e300ef 3198static void gen_lswx(DisasContext *ctx)
79aceca5 3199{
76db3ba4
AJ
3200 TCGv t0;
3201 TCGv_i32 t1, t2, t3;
3202 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3203 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3204 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3205 t0 = tcg_temp_new();
3206 gen_addr_reg_index(ctx, t0);
3207 t1 = tcg_const_i32(rD(ctx->opcode));
3208 t2 = tcg_const_i32(rA(ctx->opcode));
3209 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3210 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3211 tcg_temp_free(t0);
3212 tcg_temp_free_i32(t1);
3213 tcg_temp_free_i32(t2);
3214 tcg_temp_free_i32(t3);
79aceca5
FB
3215}
3216
3217/* stswi */
99e300ef 3218static void gen_stswi(DisasContext *ctx)
79aceca5 3219{
76db3ba4
AJ
3220 TCGv t0;
3221 TCGv_i32 t1, t2;
4b3686fa 3222 int nb = NB(ctx->opcode);
76db3ba4 3223 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3224 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3225 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3226 t0 = tcg_temp_new();
3227 gen_addr_register(ctx, t0);
4b3686fa
FB
3228 if (nb == 0)
3229 nb = 32;
dfbc799d 3230 t1 = tcg_const_i32(nb);
76db3ba4 3231 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3232 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3233 tcg_temp_free(t0);
3234 tcg_temp_free_i32(t1);
3235 tcg_temp_free_i32(t2);
79aceca5
FB
3236}
3237
3238/* stswx */
99e300ef 3239static void gen_stswx(DisasContext *ctx)
79aceca5 3240{
76db3ba4
AJ
3241 TCGv t0;
3242 TCGv_i32 t1, t2;
3243 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3244 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3245 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3246 t0 = tcg_temp_new();
3247 gen_addr_reg_index(ctx, t0);
3248 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3249 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3250 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3251 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3252 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3253 tcg_temp_free(t0);
3254 tcg_temp_free_i32(t1);
3255 tcg_temp_free_i32(t2);
79aceca5
FB
3256}
3257
3258/*** Memory synchronisation ***/
3259/* eieio */
99e300ef 3260static void gen_eieio(DisasContext *ctx)
79aceca5 3261{
79aceca5
FB
3262}
3263
3264/* isync */
99e300ef 3265static void gen_isync(DisasContext *ctx)
79aceca5 3266{
e06fcd75 3267 gen_stop_exception(ctx);
79aceca5
FB
3268}
3269
5c77a786
TM
3270#define LARX(name, len, loadop) \
3271static void gen_##name(DisasContext *ctx) \
3272{ \
3273 TCGv t0; \
3274 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3275 gen_set_access_type(ctx, ACCESS_RES); \
3276 t0 = tcg_temp_local_new(); \
3277 gen_addr_reg_index(ctx, t0); \
3278 if ((len) > 1) { \
3279 gen_check_align(ctx, t0, (len)-1); \
3280 } \
3281 gen_qemu_##loadop(ctx, gpr, t0); \
3282 tcg_gen_mov_tl(cpu_reserve, t0); \
3283 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3284 tcg_temp_free(t0); \
79aceca5
FB
3285}
3286
5c77a786
TM
3287/* lwarx */
3288LARX(lbarx, 1, ld8u);
3289LARX(lharx, 2, ld16u);
3290LARX(lwarx, 4, ld32u);
3291
3292
4425265b 3293#if defined(CONFIG_USER_ONLY)
587c51f7
TM
3294static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3295 int reg, int size)
4425265b
NF
3296{
3297 TCGv t0 = tcg_temp_new();
3298 uint32_t save_exception = ctx->exception;
3299
1328c2bf 3300 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3301 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3302 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3303 tcg_temp_free(t0);
3304 gen_update_nip(ctx, ctx->nip-4);
3305 ctx->exception = POWERPC_EXCP_BRANCH;
3306 gen_exception(ctx, POWERPC_EXCP_STCX);
3307 ctx->exception = save_exception;
3308}
4425265b 3309#else
587c51f7
TM
3310static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3311 int reg, int size)
3312{
3313 int l1;
4425265b 3314
587c51f7
TM
3315 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3316 l1 = gen_new_label();
3317 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3318 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3319#if defined(TARGET_PPC64)
3320 if (size == 8) {
3321 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3322 } else
3323#endif
3324 if (size == 4) {
3325 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3326 } else if (size == 2) {
3327 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
27b95bfe
TM
3328#if defined(TARGET_PPC64)
3329 } else if (size == 16) {
3707cd62 3330 TCGv gpr1, gpr2 , EA8;
27b95bfe
TM
3331 if (unlikely(ctx->le_mode)) {
3332 gpr1 = cpu_gpr[reg+1];
3333 gpr2 = cpu_gpr[reg];
3334 } else {
3335 gpr1 = cpu_gpr[reg];
3336 gpr2 = cpu_gpr[reg+1];
3337 }
3338 gen_qemu_st64(ctx, gpr1, EA);
3707cd62
TM
3339 EA8 = tcg_temp_local_new();
3340 gen_addr_add(ctx, EA8, EA, 8);
3341 gen_qemu_st64(ctx, gpr2, EA8);
3342 tcg_temp_free(EA8);
27b95bfe 3343#endif
587c51f7
TM
3344 } else {
3345 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
4425265b 3346 }
587c51f7
TM
3347 gen_set_label(l1);
3348 tcg_gen_movi_tl(cpu_reserve, -1);
3349}
4425265b 3350#endif
587c51f7
TM
3351
3352#define STCX(name, len) \
3353static void gen_##name(DisasContext *ctx) \
3354{ \
3355 TCGv t0; \
27b95bfe
TM
3356 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3357 gen_inval_exception(ctx, \
3358 POWERPC_EXCP_INVAL_INVAL); \
3359 return; \
3360 } \
587c51f7
TM
3361 gen_set_access_type(ctx, ACCESS_RES); \
3362 t0 = tcg_temp_local_new(); \
3363 gen_addr_reg_index(ctx, t0); \
3364 if (len > 1) { \
3365 gen_check_align(ctx, t0, (len)-1); \
3366 } \
3367 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3368 tcg_temp_free(t0); \
79aceca5
FB
3369}
3370
587c51f7
TM
3371STCX(stbcx_, 1);
3372STCX(sthcx_, 2);
3373STCX(stwcx_, 4);
3374
426613db 3375#if defined(TARGET_PPC64)
426613db 3376/* ldarx */
5c77a786 3377LARX(ldarx, 8, ld64);
426613db 3378
9c294d5a
TM
3379/* lqarx */
3380static void gen_lqarx(DisasContext *ctx)
3381{
3382 TCGv EA;
3383 int rd = rD(ctx->opcode);
3384 TCGv gpr1, gpr2;
3385
3386 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3387 (rd == rB(ctx->opcode)))) {
3388 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3389 return;
3390 }
3391
3392 gen_set_access_type(ctx, ACCESS_RES);
3393 EA = tcg_temp_local_new();
3394 gen_addr_reg_index(ctx, EA);
3395 gen_check_align(ctx, EA, 15);
3396 if (unlikely(ctx->le_mode)) {
3397 gpr1 = cpu_gpr[rd+1];
3398 gpr2 = cpu_gpr[rd];
3399 } else {
3400 gpr1 = cpu_gpr[rd];
3401 gpr2 = cpu_gpr[rd+1];
3402 }
3403 gen_qemu_ld64(ctx, gpr1, EA);
3404 tcg_gen_mov_tl(cpu_reserve, EA);
3405
3406 gen_addr_add(ctx, EA, EA, 8);
3407 gen_qemu_ld64(ctx, gpr2, EA);
3408
3409 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3410 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3411
3412 tcg_temp_free(EA);
3413}
3414
426613db 3415/* stdcx. */
587c51f7 3416STCX(stdcx_, 8);
27b95bfe 3417STCX(stqcx_, 16);
426613db
JM
3418#endif /* defined(TARGET_PPC64) */
3419
79aceca5 3420/* sync */
99e300ef 3421static void gen_sync(DisasContext *ctx)
79aceca5 3422{
79aceca5
FB
3423}
3424
0db1b20e 3425/* wait */
99e300ef 3426static void gen_wait(DisasContext *ctx)
0db1b20e 3427{
931ff272 3428 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3429 tcg_gen_st_i32(t0, cpu_env,
3430 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3431 tcg_temp_free_i32(t0);
0db1b20e 3432 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3433 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3434}
3435
79aceca5 3436/*** Floating-point load ***/
a0d7d5a7 3437#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3438static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3439{ \
a0d7d5a7 3440 TCGv EA; \
76a66253 3441 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3442 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3443 return; \
3444 } \
76db3ba4 3445 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3446 EA = tcg_temp_new(); \
76db3ba4
AJ
3447 gen_addr_imm_index(ctx, EA, 0); \
3448 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3449 tcg_temp_free(EA); \
79aceca5
FB
3450}
3451
a0d7d5a7 3452#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3453static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3454{ \
a0d7d5a7 3455 TCGv EA; \
76a66253 3456 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3457 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3458 return; \
3459 } \
76a66253 3460 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3461 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3462 return; \
9a64fbe4 3463 } \
76db3ba4 3464 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3465 EA = tcg_temp_new(); \
76db3ba4
AJ
3466 gen_addr_imm_index(ctx, EA, 0); \
3467 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3468 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3469 tcg_temp_free(EA); \
79aceca5
FB
3470}
3471
a0d7d5a7 3472#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3473static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3474{ \
a0d7d5a7 3475 TCGv EA; \
76a66253 3476 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3477 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3478 return; \
3479 } \
76a66253 3480 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3481 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3482 return; \
9a64fbe4 3483 } \
76db3ba4 3484 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3485 EA = tcg_temp_new(); \
76db3ba4
AJ
3486 gen_addr_reg_index(ctx, EA); \
3487 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3488 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3489 tcg_temp_free(EA); \
79aceca5
FB
3490}
3491
a0d7d5a7 3492#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3493static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3494{ \
a0d7d5a7 3495 TCGv EA; \
76a66253 3496 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3497 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3498 return; \
3499 } \
76db3ba4 3500 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3501 EA = tcg_temp_new(); \
76db3ba4
AJ
3502 gen_addr_reg_index(ctx, EA); \
3503 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3504 tcg_temp_free(EA); \
79aceca5
FB
3505}
3506
a0d7d5a7
AJ
3507#define GEN_LDFS(name, ldop, op, type) \
3508GEN_LDF(name, ldop, op | 0x20, type); \
3509GEN_LDUF(name, ldop, op | 0x21, type); \
3510GEN_LDUXF(name, ldop, op | 0x01, type); \
3511GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3512
636aa200 3513static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3514{
3515 TCGv t0 = tcg_temp_new();
3516 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3517 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3518 tcg_gen_trunc_tl_i32(t1, t0);
3519 tcg_temp_free(t0);
8e703949 3520 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3521 tcg_temp_free_i32(t1);
3522}
79aceca5 3523
a0d7d5a7
AJ
3524 /* lfd lfdu lfdux lfdx */
3525GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3526 /* lfs lfsu lfsux lfsx */
3527GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3528
05050ee8
AJ
3529/* lfdp */
3530static void gen_lfdp(DisasContext *ctx)
3531{
3532 TCGv EA;
3533 if (unlikely(!ctx->fpu_enabled)) {
3534 gen_exception(ctx, POWERPC_EXCP_FPU);
3535 return;
3536 }
3537 gen_set_access_type(ctx, ACCESS_FLOAT);
3538 EA = tcg_temp_new();
e22c357b
DK
3539 gen_addr_imm_index(ctx, EA, 0);
3540 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3541 64-bit byteswap already. */
05050ee8
AJ
3542 if (unlikely(ctx->le_mode)) {
3543 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3544 tcg_gen_addi_tl(EA, EA, 8);
3545 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3546 } else {
3547 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3548 tcg_gen_addi_tl(EA, EA, 8);
3549 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3550 }
3551 tcg_temp_free(EA);
3552}
3553
3554/* lfdpx */
3555static void gen_lfdpx(DisasContext *ctx)
3556{
3557 TCGv EA;
3558 if (unlikely(!ctx->fpu_enabled)) {
3559 gen_exception(ctx, POWERPC_EXCP_FPU);
3560 return;
3561 }
3562 gen_set_access_type(ctx, ACCESS_FLOAT);
3563 EA = tcg_temp_new();
3564 gen_addr_reg_index(ctx, EA);
e22c357b
DK
3565 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3566 64-bit byteswap already. */
05050ee8
AJ
3567 if (unlikely(ctx->le_mode)) {
3568 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3569 tcg_gen_addi_tl(EA, EA, 8);
3570 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3571 } else {
3572 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3573 tcg_gen_addi_tl(EA, EA, 8);
3574 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3575 }
3576 tcg_temp_free(EA);
3577}
3578
199f830d
AJ
3579/* lfiwax */
3580static void gen_lfiwax(DisasContext *ctx)
3581{
3582 TCGv EA;
3583 TCGv t0;
3584 if (unlikely(!ctx->fpu_enabled)) {
3585 gen_exception(ctx, POWERPC_EXCP_FPU);
3586 return;
3587 }
3588 gen_set_access_type(ctx, ACCESS_FLOAT);
3589 EA = tcg_temp_new();
3590 t0 = tcg_temp_new();
3591 gen_addr_reg_index(ctx, EA);
909eedb7 3592 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3593 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3594 tcg_temp_free(EA);
3595 tcg_temp_free(t0);
3596}
3597
66c3e328
TM
3598/* lfiwzx */
3599static void gen_lfiwzx(DisasContext *ctx)
3600{
3601 TCGv EA;
3602 if (unlikely(!ctx->fpu_enabled)) {
3603 gen_exception(ctx, POWERPC_EXCP_FPU);
3604 return;
3605 }
3606 gen_set_access_type(ctx, ACCESS_FLOAT);
3607 EA = tcg_temp_new();
3608 gen_addr_reg_index(ctx, EA);
3609 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3610 tcg_temp_free(EA);
3611}
79aceca5 3612/*** Floating-point store ***/
a0d7d5a7 3613#define GEN_STF(name, stop, opc, type) \
99e300ef 3614static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3615{ \
a0d7d5a7 3616 TCGv EA; \
76a66253 3617 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3618 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3619 return; \
3620 } \
76db3ba4 3621 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3622 EA = tcg_temp_new(); \
76db3ba4
AJ
3623 gen_addr_imm_index(ctx, EA, 0); \
3624 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3625 tcg_temp_free(EA); \
79aceca5
FB
3626}
3627
a0d7d5a7 3628#define GEN_STUF(name, stop, opc, type) \
99e300ef 3629static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3630{ \
a0d7d5a7 3631 TCGv EA; \
76a66253 3632 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3633 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3634 return; \
3635 } \
76a66253 3636 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3637 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3638 return; \
9a64fbe4 3639 } \
76db3ba4 3640 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3641 EA = tcg_temp_new(); \
76db3ba4
AJ
3642 gen_addr_imm_index(ctx, EA, 0); \
3643 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3644 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3645 tcg_temp_free(EA); \
79aceca5
FB
3646}
3647
a0d7d5a7 3648#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3649static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3650{ \
a0d7d5a7 3651 TCGv EA; \
76a66253 3652 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3653 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3654 return; \
3655 } \
76a66253 3656 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3657 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3658 return; \
9a64fbe4 3659 } \
76db3ba4 3660 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3661 EA = tcg_temp_new(); \
76db3ba4
AJ
3662 gen_addr_reg_index(ctx, EA); \
3663 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3664 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3665 tcg_temp_free(EA); \
79aceca5
FB
3666}
3667
a0d7d5a7 3668#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3669static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3670{ \
a0d7d5a7 3671 TCGv EA; \
76a66253 3672 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3673 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3674 return; \
3675 } \
76db3ba4 3676 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3677 EA = tcg_temp_new(); \
76db3ba4
AJ
3678 gen_addr_reg_index(ctx, EA); \
3679 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3680 tcg_temp_free(EA); \
79aceca5
FB
3681}
3682
a0d7d5a7
AJ
3683#define GEN_STFS(name, stop, op, type) \
3684GEN_STF(name, stop, op | 0x20, type); \
3685GEN_STUF(name, stop, op | 0x21, type); \
3686GEN_STUXF(name, stop, op | 0x01, type); \
3687GEN_STXF(name, stop, 0x17, op | 0x00, type)
3688
636aa200 3689static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3690{
3691 TCGv_i32 t0 = tcg_temp_new_i32();
3692 TCGv t1 = tcg_temp_new();
8e703949 3693 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3694 tcg_gen_extu_i32_tl(t1, t0);
3695 tcg_temp_free_i32(t0);
76db3ba4 3696 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3697 tcg_temp_free(t1);
3698}
79aceca5
FB
3699
3700/* stfd stfdu stfdux stfdx */
a0d7d5a7 3701GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3702/* stfs stfsu stfsux stfsx */
a0d7d5a7 3703GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3704
44bc0c4d
AJ
3705/* stfdp */
3706static void gen_stfdp(DisasContext *ctx)
3707{
3708 TCGv EA;
3709 if (unlikely(!ctx->fpu_enabled)) {
3710 gen_exception(ctx, POWERPC_EXCP_FPU);
3711 return;
3712 }
3713 gen_set_access_type(ctx, ACCESS_FLOAT);
3714 EA = tcg_temp_new();
e22c357b
DK
3715 gen_addr_imm_index(ctx, EA, 0);
3716 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3717 64-bit byteswap already. */
44bc0c4d
AJ
3718 if (unlikely(ctx->le_mode)) {
3719 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3720 tcg_gen_addi_tl(EA, EA, 8);
3721 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3722 } else {
3723 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3724 tcg_gen_addi_tl(EA, EA, 8);
3725 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3726 }
3727 tcg_temp_free(EA);
3728}
3729
3730/* stfdpx */
3731static void gen_stfdpx(DisasContext *ctx)
3732{
3733 TCGv EA;
3734 if (unlikely(!ctx->fpu_enabled)) {
3735 gen_exception(ctx, POWERPC_EXCP_FPU);
3736 return;
3737 }
3738 gen_set_access_type(ctx, ACCESS_FLOAT);
3739 EA = tcg_temp_new();
3740 gen_addr_reg_index(ctx, EA);
e22c357b
DK
3741 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3742 64-bit byteswap already. */
44bc0c4d
AJ
3743 if (unlikely(ctx->le_mode)) {
3744 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3745 tcg_gen_addi_tl(EA, EA, 8);
3746 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3747 } else {
3748 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3749 tcg_gen_addi_tl(EA, EA, 8);
3750 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3751 }
3752 tcg_temp_free(EA);
3753}
3754
79aceca5 3755/* Optional: */
636aa200 3756static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3757{
3758 TCGv t0 = tcg_temp_new();
3759 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3760 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3761 tcg_temp_free(t0);
3762}
79aceca5 3763/* stfiwx */
a0d7d5a7 3764GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3765
697ab892
DG
3766static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3767{
3768#if defined(TARGET_PPC64)
3769 if (ctx->has_cfar)
3770 tcg_gen_movi_tl(cpu_cfar, nip);
3771#endif
3772}
3773
79aceca5 3774/*** Branch ***/
636aa200 3775static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362
FB
3776{
3777 TranslationBlock *tb;
3778 tb = ctx->tb;
e0c8f9ce 3779 if (NARROW_MODE(ctx)) {
a2ffb812 3780 dest = (uint32_t) dest;
e0c8f9ce 3781 }
57fec1fe 3782 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
8cbcb4fa 3783 likely(!ctx->singlestep_enabled)) {
57fec1fe 3784 tcg_gen_goto_tb(n);
a2ffb812 3785 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cfd0495 3786 tcg_gen_exit_tb((uintptr_t)tb + n);
c1942362 3787 } else {
a2ffb812 3788 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3789 if (unlikely(ctx->singlestep_enabled)) {
3790 if ((ctx->singlestep_enabled &
bdc4e053 3791 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3792 (ctx->exception == POWERPC_EXCP_BRANCH ||
3793 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3794 target_ulong tmp = ctx->nip;
3795 ctx->nip = dest;
e06fcd75 3796 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3797 ctx->nip = tmp;
3798 }
3799 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3800 gen_debug_exception(ctx);
8cbcb4fa
AJ
3801 }
3802 }
57fec1fe 3803 tcg_gen_exit_tb(0);
c1942362 3804 }
c53be334
FB
3805}
3806
636aa200 3807static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3808{
e0c8f9ce
RH
3809 if (NARROW_MODE(ctx)) {
3810 nip = (uint32_t)nip;
3811 }
3812 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3813}
3814
79aceca5 3815/* b ba bl bla */
99e300ef 3816static void gen_b(DisasContext *ctx)
79aceca5 3817{
76a66253 3818 target_ulong li, target;
38a64f9d 3819
8cbcb4fa 3820 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3821 /* sign extend LI */
e0c8f9ce
RH
3822 li = LI(ctx->opcode);
3823 li = (li ^ 0x02000000) - 0x02000000;
3824 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3825 target = ctx->nip + li - 4;
e0c8f9ce 3826 } else {
9a64fbe4 3827 target = li;
e0c8f9ce
RH
3828 }
3829 if (LK(ctx->opcode)) {
e1833e1f 3830 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3831 }
697ab892 3832 gen_update_cfar(ctx, ctx->nip);
c1942362 3833 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3834}
3835
e98a6e40
FB
3836#define BCOND_IM 0
3837#define BCOND_LR 1
3838#define BCOND_CTR 2
52a4984d 3839#define BCOND_TAR 3
e98a6e40 3840
636aa200 3841static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3842{
d9bce9d9 3843 uint32_t bo = BO(ctx->opcode);
05f92404 3844 int l1;
a2ffb812 3845 TCGv target;
e98a6e40 3846
8cbcb4fa 3847 ctx->exception = POWERPC_EXCP_BRANCH;
52a4984d 3848 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
a7812ae4 3849 target = tcg_temp_local_new();
a2ffb812
AJ
3850 if (type == BCOND_CTR)
3851 tcg_gen_mov_tl(target, cpu_ctr);
52a4984d
TM
3852 else if (type == BCOND_TAR)
3853 gen_load_spr(target, SPR_TAR);
a2ffb812
AJ
3854 else
3855 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3856 } else {
3857 TCGV_UNUSED(target);
e98a6e40 3858 }
e1833e1f
JM
3859 if (LK(ctx->opcode))
3860 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3861 l1 = gen_new_label();
3862 if ((bo & 0x4) == 0) {
3863 /* Decrement and test CTR */
a7812ae4 3864 TCGv temp = tcg_temp_new();
a2ffb812 3865 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3866 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3867 return;
3868 }
3869 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3870 if (NARROW_MODE(ctx)) {
a2ffb812 3871 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3872 } else {
a2ffb812 3873 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3874 }
a2ffb812
AJ
3875 if (bo & 0x2) {
3876 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3877 } else {
3878 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3879 }
a7812ae4 3880 tcg_temp_free(temp);
a2ffb812
AJ
3881 }
3882 if ((bo & 0x10) == 0) {
3883 /* Test CR */
3884 uint32_t bi = BI(ctx->opcode);
3885 uint32_t mask = 1 << (3 - (bi & 0x03));
a7812ae4 3886 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3887
d9bce9d9 3888 if (bo & 0x8) {
a2ffb812
AJ
3889 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3890 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3891 } else {
a2ffb812
AJ
3892 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3893 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3894 }
a7812ae4 3895 tcg_temp_free_i32(temp);
d9bce9d9 3896 }
697ab892 3897 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3898 if (type == BCOND_IM) {
a2ffb812
AJ
3899 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3900 if (likely(AA(ctx->opcode) == 0)) {
3901 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3902 } else {
3903 gen_goto_tb(ctx, 0, li);
3904 }
c53be334 3905 gen_set_label(l1);
c1942362 3906 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3907 } else {
e0c8f9ce 3908 if (NARROW_MODE(ctx)) {
a2ffb812 3909 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3910 } else {
a2ffb812 3911 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3912 }
a2ffb812
AJ
3913 tcg_gen_exit_tb(0);
3914 gen_set_label(l1);
e0c8f9ce 3915 gen_update_nip(ctx, ctx->nip);
57fec1fe 3916 tcg_gen_exit_tb(0);
08e46e54 3917 }
a9e8f4e7 3918 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
c80d1df5
AG
3919 tcg_temp_free(target);
3920 }
e98a6e40
FB
3921}
3922
99e300ef 3923static void gen_bc(DisasContext *ctx)
3b46e624 3924{
e98a6e40
FB
3925 gen_bcond(ctx, BCOND_IM);
3926}
3927
99e300ef 3928static void gen_bcctr(DisasContext *ctx)
3b46e624 3929{
e98a6e40
FB
3930 gen_bcond(ctx, BCOND_CTR);
3931}
3932
99e300ef 3933static void gen_bclr(DisasContext *ctx)
3b46e624 3934{
e98a6e40
FB
3935 gen_bcond(ctx, BCOND_LR);
3936}
79aceca5 3937
52a4984d
TM
3938static void gen_bctar(DisasContext *ctx)
3939{
3940 gen_bcond(ctx, BCOND_TAR);
3941}
3942
79aceca5 3943/*** Condition register logical ***/
e1571908 3944#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 3945static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3946{ \
fc0d441e
JM
3947 uint8_t bitmask; \
3948 int sh; \
a7812ae4 3949 TCGv_i32 t0, t1; \
fc0d441e 3950 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 3951 t0 = tcg_temp_new_i32(); \
fc0d441e 3952 if (sh > 0) \
fea0c503 3953 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 3954 else if (sh < 0) \
fea0c503 3955 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 3956 else \
fea0c503 3957 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 3958 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
3959 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3960 if (sh > 0) \
fea0c503 3961 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 3962 else if (sh < 0) \
fea0c503 3963 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 3964 else \
fea0c503
AJ
3965 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3966 tcg_op(t0, t0, t1); \
fc0d441e 3967 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
fea0c503
AJ
3968 tcg_gen_andi_i32(t0, t0, bitmask); \
3969 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3970 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
3971 tcg_temp_free_i32(t0); \
3972 tcg_temp_free_i32(t1); \
79aceca5
FB
3973}
3974
3975/* crand */
e1571908 3976GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 3977/* crandc */
e1571908 3978GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 3979/* creqv */
e1571908 3980GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 3981/* crnand */
e1571908 3982GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 3983/* crnor */
e1571908 3984GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 3985/* cror */
e1571908 3986GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 3987/* crorc */
e1571908 3988GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 3989/* crxor */
e1571908 3990GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 3991
54623277 3992/* mcrf */
99e300ef 3993static void gen_mcrf(DisasContext *ctx)
79aceca5 3994{
47e4661c 3995 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
3996}
3997
3998/*** System linkage ***/
99e300ef 3999
54623277 4000/* rfi (mem_idx only) */
99e300ef 4001static void gen_rfi(DisasContext *ctx)
79aceca5 4002{
9a64fbe4 4003#if defined(CONFIG_USER_ONLY)
e06fcd75 4004 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
4005#else
4006 /* Restore CPU state */
76db3ba4 4007 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4008 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4009 return;
9a64fbe4 4010 }
697ab892 4011 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4012 gen_helper_rfi(cpu_env);
e06fcd75 4013 gen_sync_exception(ctx);
9a64fbe4 4014#endif
79aceca5
FB
4015}
4016
426613db 4017#if defined(TARGET_PPC64)
99e300ef 4018static void gen_rfid(DisasContext *ctx)
426613db
JM
4019{
4020#if defined(CONFIG_USER_ONLY)
e06fcd75 4021 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4022#else
4023 /* Restore CPU state */
76db3ba4 4024 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4025 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4026 return;
4027 }
697ab892 4028 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4029 gen_helper_rfid(cpu_env);
e06fcd75 4030 gen_sync_exception(ctx);
426613db
JM
4031#endif
4032}
426613db 4033
99e300ef 4034static void gen_hrfid(DisasContext *ctx)
be147d08
JM
4035{
4036#if defined(CONFIG_USER_ONLY)
e06fcd75 4037 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4038#else
4039 /* Restore CPU state */
76db3ba4 4040 if (unlikely(ctx->mem_idx <= 1)) {
e06fcd75 4041 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4042 return;
4043 }
e5f17ac6 4044 gen_helper_hrfid(cpu_env);
e06fcd75 4045 gen_sync_exception(ctx);
be147d08
JM
4046#endif
4047}
4048#endif
4049
79aceca5 4050/* sc */
417bf010
JM
4051#if defined(CONFIG_USER_ONLY)
4052#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4053#else
4054#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4055#endif
99e300ef 4056static void gen_sc(DisasContext *ctx)
79aceca5 4057{
e1833e1f
JM
4058 uint32_t lev;
4059
4060 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 4061 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
4062}
4063
4064/*** Trap ***/
99e300ef 4065
54623277 4066/* tw */
99e300ef 4067static void gen_tw(DisasContext *ctx)
79aceca5 4068{
cab3bee2 4069 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4070 /* Update the nip since this might generate a trap exception */
4071 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4072 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4073 t0);
cab3bee2 4074 tcg_temp_free_i32(t0);
79aceca5
FB
4075}
4076
4077/* twi */
99e300ef 4078static void gen_twi(DisasContext *ctx)
79aceca5 4079{
cab3bee2
AJ
4080 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4081 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4082 /* Update the nip since this might generate a trap exception */
4083 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4084 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4085 tcg_temp_free(t0);
4086 tcg_temp_free_i32(t1);
79aceca5
FB
4087}
4088
d9bce9d9
JM
4089#if defined(TARGET_PPC64)
4090/* td */
99e300ef 4091static void gen_td(DisasContext *ctx)
d9bce9d9 4092{
cab3bee2 4093 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4094 /* Update the nip since this might generate a trap exception */
4095 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4096 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4097 t0);
cab3bee2 4098 tcg_temp_free_i32(t0);
d9bce9d9
JM
4099}
4100
4101/* tdi */
99e300ef 4102static void gen_tdi(DisasContext *ctx)
d9bce9d9 4103{
cab3bee2
AJ
4104 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4105 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4106 /* Update the nip since this might generate a trap exception */
4107 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4108 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4109 tcg_temp_free(t0);
4110 tcg_temp_free_i32(t1);
d9bce9d9
JM
4111}
4112#endif
4113
79aceca5 4114/*** Processor control ***/
99e300ef 4115
da91a00f
RH
4116static void gen_read_xer(TCGv dst)
4117{
4118 TCGv t0 = tcg_temp_new();
4119 TCGv t1 = tcg_temp_new();
4120 TCGv t2 = tcg_temp_new();
4121 tcg_gen_mov_tl(dst, cpu_xer);
4122 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4123 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4124 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4125 tcg_gen_or_tl(t0, t0, t1);
4126 tcg_gen_or_tl(dst, dst, t2);
4127 tcg_gen_or_tl(dst, dst, t0);
4128 tcg_temp_free(t0);
4129 tcg_temp_free(t1);
4130 tcg_temp_free(t2);
4131}
4132
4133static void gen_write_xer(TCGv src)
4134{
4135 tcg_gen_andi_tl(cpu_xer, src,
4136 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4137 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4138 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4139 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4140 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4141 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4142 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4143}
4144
54623277 4145/* mcrxr */
99e300ef 4146static void gen_mcrxr(DisasContext *ctx)
79aceca5 4147{
da91a00f
RH
4148 TCGv_i32 t0 = tcg_temp_new_i32();
4149 TCGv_i32 t1 = tcg_temp_new_i32();
4150 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4151
4152 tcg_gen_trunc_tl_i32(t0, cpu_so);
4153 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4154 tcg_gen_trunc_tl_i32(dst, cpu_ca);
294d1292
SB
4155 tcg_gen_shli_i32(t0, t0, 3);
4156 tcg_gen_shli_i32(t1, t1, 2);
4157 tcg_gen_shli_i32(dst, dst, 1);
da91a00f
RH
4158 tcg_gen_or_i32(dst, dst, t0);
4159 tcg_gen_or_i32(dst, dst, t1);
4160 tcg_temp_free_i32(t0);
4161 tcg_temp_free_i32(t1);
4162
4163 tcg_gen_movi_tl(cpu_so, 0);
4164 tcg_gen_movi_tl(cpu_ov, 0);
4165 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
4166}
4167
0cfe11ea 4168/* mfcr mfocrf */
99e300ef 4169static void gen_mfcr(DisasContext *ctx)
79aceca5 4170{
76a66253 4171 uint32_t crm, crn;
3b46e624 4172
76a66253
JM
4173 if (likely(ctx->opcode & 0x00100000)) {
4174 crm = CRM(ctx->opcode);
8dd640e4 4175 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 4176 crn = ctz32 (crm);
e1571908 4177 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
4178 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4179 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 4180 }
d9bce9d9 4181 } else {
651721b2
AJ
4182 TCGv_i32 t0 = tcg_temp_new_i32();
4183 tcg_gen_mov_i32(t0, cpu_crf[0]);
4184 tcg_gen_shli_i32(t0, t0, 4);
4185 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4186 tcg_gen_shli_i32(t0, t0, 4);
4187 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4188 tcg_gen_shli_i32(t0, t0, 4);
4189 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4190 tcg_gen_shli_i32(t0, t0, 4);
4191 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4192 tcg_gen_shli_i32(t0, t0, 4);
4193 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4194 tcg_gen_shli_i32(t0, t0, 4);
4195 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4196 tcg_gen_shli_i32(t0, t0, 4);
4197 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4198 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4199 tcg_temp_free_i32(t0);
d9bce9d9 4200 }
79aceca5
FB
4201}
4202
4203/* mfmsr */
99e300ef 4204static void gen_mfmsr(DisasContext *ctx)
79aceca5 4205{
9a64fbe4 4206#if defined(CONFIG_USER_ONLY)
e06fcd75 4207 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4208#else
76db3ba4 4209 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4210 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4211 return;
9a64fbe4 4212 }
6527f6ea 4213 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4214#endif
79aceca5
FB
4215}
4216
7b13448f 4217static void spr_noaccess(void *opaque, int gprn, int sprn)
3fc6c082 4218{
7b13448f 4219#if 0
3fc6c082
FB
4220 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4221 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4222#endif
3fc6c082
FB
4223}
4224#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4225
79aceca5 4226/* mfspr */
636aa200 4227static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4228{
45d827d2 4229 void (*read_cb)(void *opaque, int gprn, int sprn);
79aceca5
FB
4230 uint32_t sprn = SPR(ctx->opcode);
4231
3fc6c082 4232#if !defined(CONFIG_USER_ONLY)
76db3ba4 4233 if (ctx->mem_idx == 2)
be147d08 4234 read_cb = ctx->spr_cb[sprn].hea_read;
76db3ba4 4235 else if (ctx->mem_idx)
3fc6c082
FB
4236 read_cb = ctx->spr_cb[sprn].oea_read;
4237 else
9a64fbe4 4238#endif
3fc6c082 4239 read_cb = ctx->spr_cb[sprn].uea_read;
76a66253
JM
4240 if (likely(read_cb != NULL)) {
4241 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4242 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4243 } else {
4244 /* Privilege exception */
9fceefa7
JM
4245 /* This is a hack to avoid warnings when running Linux:
4246 * this OS breaks the PowerPC virtualisation model,
4247 * allowing userland application to read the PVR
4248 */
4249 if (sprn != SPR_PVR) {
c05541ee
AB
4250 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4251 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4252 printf("Trying to read privileged spr %d (0x%03x) at "
4253 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
f24e5695 4254 }
e06fcd75 4255 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4256 }
3fc6c082
FB
4257 } else {
4258 /* Not defined */
c05541ee
AB
4259 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4260 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4261 printf("Trying to read invalid spr %d (0x%03x) at "
4262 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4263 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4264 }
79aceca5
FB
4265}
4266
99e300ef 4267static void gen_mfspr(DisasContext *ctx)
79aceca5 4268{
3fc6c082 4269 gen_op_mfspr(ctx);
76a66253 4270}
3fc6c082
FB
4271
4272/* mftb */
99e300ef 4273static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4274{
4275 gen_op_mfspr(ctx);
79aceca5
FB
4276}
4277
0cfe11ea 4278/* mtcrf mtocrf*/
99e300ef 4279static void gen_mtcrf(DisasContext *ctx)
79aceca5 4280{
76a66253 4281 uint32_t crm, crn;
3b46e624 4282
76a66253 4283 crm = CRM(ctx->opcode);
8dd640e4 4284 if (likely((ctx->opcode & 0x00100000))) {
4285 if (crm && ((crm & (crm - 1)) == 0)) {
4286 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4287 crn = ctz32 (crm);
8dd640e4 4288 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4289 tcg_gen_shri_i32(temp, temp, crn * 4);
4290 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4291 tcg_temp_free_i32(temp);
4292 }
76a66253 4293 } else {
651721b2
AJ
4294 TCGv_i32 temp = tcg_temp_new_i32();
4295 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4296 for (crn = 0 ; crn < 8 ; crn++) {
4297 if (crm & (1 << crn)) {
4298 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4299 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4300 }
4301 }
a7812ae4 4302 tcg_temp_free_i32(temp);
76a66253 4303 }
79aceca5
FB
4304}
4305
4306/* mtmsr */
426613db 4307#if defined(TARGET_PPC64)
99e300ef 4308static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4309{
4310#if defined(CONFIG_USER_ONLY)
e06fcd75 4311 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4312#else
76db3ba4 4313 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4314 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4315 return;
4316 }
be147d08
JM
4317 if (ctx->opcode & 0x00010000) {
4318 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4319 TCGv t0 = tcg_temp_new();
4320 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4321 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4322 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4323 tcg_temp_free(t0);
be147d08 4324 } else {
056b05f8
JM
4325 /* XXX: we need to update nip before the store
4326 * if we enter power saving mode, we will exit the loop
4327 * directly from ppc_store_msr
4328 */
be147d08 4329 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4330 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4331 /* Must stop the translation as machine state (may have) changed */
4332 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4333 gen_stop_exception(ctx);
be147d08 4334 }
426613db
JM
4335#endif
4336}
4337#endif
4338
99e300ef 4339static void gen_mtmsr(DisasContext *ctx)
79aceca5 4340{
9a64fbe4 4341#if defined(CONFIG_USER_ONLY)
e06fcd75 4342 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4343#else
76db3ba4 4344 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4345 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4346 return;
9a64fbe4 4347 }
be147d08
JM
4348 if (ctx->opcode & 0x00010000) {
4349 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4350 TCGv t0 = tcg_temp_new();
4351 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4352 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4353 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4354 tcg_temp_free(t0);
be147d08 4355 } else {
8018dc63
AG
4356 TCGv msr = tcg_temp_new();
4357
056b05f8
JM
4358 /* XXX: we need to update nip before the store
4359 * if we enter power saving mode, we will exit the loop
4360 * directly from ppc_store_msr
4361 */
be147d08 4362 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4363#if defined(TARGET_PPC64)
8018dc63
AG
4364 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4365#else
4366 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4367#endif
e5f17ac6 4368 gen_helper_store_msr(cpu_env, msr);
c80d1df5 4369 tcg_temp_free(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
4d09d529
AG
4479/* dcbtls */
4480static void gen_dcbtls(DisasContext *ctx)
4481{
4482 /* Always fails locking the cache */
4483 TCGv t0 = tcg_temp_new();
4484 gen_load_spr(t0, SPR_Exxx_L1CSR0);
4485 tcg_gen_ori_tl(t0, t0, L1CSR0_CUL);
4486 gen_store_spr(SPR_Exxx_L1CSR0, t0);
4487 tcg_temp_free(t0);
4488}
4489
79aceca5 4490/* dcbz */
99e300ef 4491static void gen_dcbz(DisasContext *ctx)
79aceca5 4492{
8e33944f
AG
4493 TCGv tcgv_addr;
4494 TCGv_i32 tcgv_is_dcbzl;
4495 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4496
76db3ba4 4497 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4498 /* NIP cannot be restored if the memory exception comes from an helper */
4499 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4500 tcgv_addr = tcg_temp_new();
4501 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4502
4503 gen_addr_reg_index(ctx, tcgv_addr);
4504 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4505
4506 tcg_temp_free(tcgv_addr);
4507 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4508}
4509
ae1c1a3d 4510/* dst / dstt */
99e300ef 4511static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4512{
4513 if (rA(ctx->opcode) == 0) {
4514 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4515 } else {
4516 /* interpreted as no-op */
4517 }
4518}
4519
4520/* dstst /dststt */
99e300ef 4521static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4522{
4523 if (rA(ctx->opcode) == 0) {
4524 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4525 } else {
4526 /* interpreted as no-op */
4527 }
4528
4529}
4530
4531/* dss / dssall */
99e300ef 4532static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4533{
4534 /* interpreted as no-op */
4535}
4536
79aceca5 4537/* icbi */
99e300ef 4538static void gen_icbi(DisasContext *ctx)
79aceca5 4539{
76db3ba4
AJ
4540 TCGv t0;
4541 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4542 /* NIP cannot be restored if the memory exception comes from an helper */
4543 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4544 t0 = tcg_temp_new();
4545 gen_addr_reg_index(ctx, t0);
2f5a189c 4546 gen_helper_icbi(cpu_env, t0);
37d269df 4547 tcg_temp_free(t0);
79aceca5
FB
4548}
4549
4550/* Optional: */
4551/* dcba */
99e300ef 4552static void gen_dcba(DisasContext *ctx)
79aceca5 4553{
0db1b20e
JM
4554 /* interpreted as no-op */
4555 /* XXX: specification say this is treated as a store by the MMU
4556 * but does not generate any exception
4557 */
79aceca5
FB
4558}
4559
4560/*** Segment register manipulation ***/
4561/* Supervisor only: */
99e300ef 4562
54623277 4563/* mfsr */
99e300ef 4564static void gen_mfsr(DisasContext *ctx)
79aceca5 4565{
9a64fbe4 4566#if defined(CONFIG_USER_ONLY)
e06fcd75 4567 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4568#else
74d37793 4569 TCGv t0;
76db3ba4 4570 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4571 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4572 return;
9a64fbe4 4573 }
74d37793 4574 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4575 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4576 tcg_temp_free(t0);
9a64fbe4 4577#endif
79aceca5
FB
4578}
4579
4580/* mfsrin */
99e300ef 4581static void gen_mfsrin(DisasContext *ctx)
79aceca5 4582{
9a64fbe4 4583#if defined(CONFIG_USER_ONLY)
e06fcd75 4584 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4585#else
74d37793 4586 TCGv t0;
76db3ba4 4587 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4588 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4589 return;
9a64fbe4 4590 }
74d37793
AJ
4591 t0 = tcg_temp_new();
4592 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4593 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4594 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4595 tcg_temp_free(t0);
9a64fbe4 4596#endif
79aceca5
FB
4597}
4598
4599/* mtsr */
99e300ef 4600static void gen_mtsr(DisasContext *ctx)
79aceca5 4601{
9a64fbe4 4602#if defined(CONFIG_USER_ONLY)
e06fcd75 4603 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4604#else
74d37793 4605 TCGv t0;
76db3ba4 4606 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4607 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4608 return;
9a64fbe4 4609 }
74d37793 4610 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4611 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4612 tcg_temp_free(t0);
9a64fbe4 4613#endif
79aceca5
FB
4614}
4615
4616/* mtsrin */
99e300ef 4617static void gen_mtsrin(DisasContext *ctx)
79aceca5 4618{
9a64fbe4 4619#if defined(CONFIG_USER_ONLY)
e06fcd75 4620 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4621#else
74d37793 4622 TCGv t0;
76db3ba4 4623 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4624 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4625 return;
9a64fbe4 4626 }
74d37793
AJ
4627 t0 = tcg_temp_new();
4628 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4629 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4630 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4631 tcg_temp_free(t0);
9a64fbe4 4632#endif
79aceca5
FB
4633}
4634
12de9a39
JM
4635#if defined(TARGET_PPC64)
4636/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4637
54623277 4638/* mfsr */
e8eaa2c0 4639static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4640{
4641#if defined(CONFIG_USER_ONLY)
e06fcd75 4642 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4643#else
74d37793 4644 TCGv t0;
76db3ba4 4645 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4646 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4647 return;
4648 }
74d37793 4649 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4650 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4651 tcg_temp_free(t0);
12de9a39
JM
4652#endif
4653}
4654
4655/* mfsrin */
e8eaa2c0 4656static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4657{
4658#if defined(CONFIG_USER_ONLY)
e06fcd75 4659 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4660#else
74d37793 4661 TCGv t0;
76db3ba4 4662 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4663 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4664 return;
4665 }
74d37793
AJ
4666 t0 = tcg_temp_new();
4667 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4668 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4669 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4670 tcg_temp_free(t0);
12de9a39
JM
4671#endif
4672}
4673
4674/* mtsr */
e8eaa2c0 4675static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4676{
4677#if defined(CONFIG_USER_ONLY)
e06fcd75 4678 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4679#else
74d37793 4680 TCGv t0;
76db3ba4 4681 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4682 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4683 return;
4684 }
74d37793 4685 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4686 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4687 tcg_temp_free(t0);
12de9a39
JM
4688#endif
4689}
4690
4691/* mtsrin */
e8eaa2c0 4692static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4693{
4694#if defined(CONFIG_USER_ONLY)
e06fcd75 4695 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4696#else
74d37793 4697 TCGv t0;
76db3ba4 4698 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4699 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4700 return;
4701 }
74d37793
AJ
4702 t0 = tcg_temp_new();
4703 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4704 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4705 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4706 tcg_temp_free(t0);
12de9a39
JM
4707#endif
4708}
f6b868fc
BS
4709
4710/* slbmte */
e8eaa2c0 4711static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4712{
4713#if defined(CONFIG_USER_ONLY)
4714 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4715#else
4716 if (unlikely(!ctx->mem_idx)) {
4717 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4718 return;
4719 }
c6c7cf05
BS
4720 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4721 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4722#endif
4723}
4724
efdef95f
DG
4725static void gen_slbmfee(DisasContext *ctx)
4726{
4727#if defined(CONFIG_USER_ONLY)
4728 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4729#else
4730 if (unlikely(!ctx->mem_idx)) {
4731 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4732 return;
4733 }
c6c7cf05 4734 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4735 cpu_gpr[rB(ctx->opcode)]);
4736#endif
4737}
4738
4739static void gen_slbmfev(DisasContext *ctx)
4740{
4741#if defined(CONFIG_USER_ONLY)
4742 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4743#else
4744 if (unlikely(!ctx->mem_idx)) {
4745 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4746 return;
4747 }
c6c7cf05 4748 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4749 cpu_gpr[rB(ctx->opcode)]);
4750#endif
4751}
12de9a39
JM
4752#endif /* defined(TARGET_PPC64) */
4753
79aceca5 4754/*** Lookaside buffer management ***/
76db3ba4 4755/* Optional & mem_idx only: */
99e300ef 4756
54623277 4757/* tlbia */
99e300ef 4758static void gen_tlbia(DisasContext *ctx)
79aceca5 4759{
9a64fbe4 4760#if defined(CONFIG_USER_ONLY)
e06fcd75 4761 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4762#else
76db3ba4 4763 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4764 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4765 return;
9a64fbe4 4766 }
c6c7cf05 4767 gen_helper_tlbia(cpu_env);
9a64fbe4 4768#endif
79aceca5
FB
4769}
4770
bf14b1ce 4771/* tlbiel */
99e300ef 4772static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4773{
4774#if defined(CONFIG_USER_ONLY)
4775 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4776#else
4777 if (unlikely(!ctx->mem_idx)) {
4778 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4779 return;
4780 }
c6c7cf05 4781 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4782#endif
4783}
4784
79aceca5 4785/* tlbie */
99e300ef 4786static void gen_tlbie(DisasContext *ctx)
79aceca5 4787{
9a64fbe4 4788#if defined(CONFIG_USER_ONLY)
e06fcd75 4789 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4790#else
76db3ba4 4791 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4792 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4793 return;
9a64fbe4 4794 }
9ca3f7f3 4795 if (NARROW_MODE(ctx)) {
74d37793
AJ
4796 TCGv t0 = tcg_temp_new();
4797 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4798 gen_helper_tlbie(cpu_env, t0);
74d37793 4799 tcg_temp_free(t0);
9ca3f7f3 4800 } else {
c6c7cf05 4801 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4802 }
9a64fbe4 4803#endif
79aceca5
FB
4804}
4805
4806/* tlbsync */
99e300ef 4807static void gen_tlbsync(DisasContext *ctx)
79aceca5 4808{
9a64fbe4 4809#if defined(CONFIG_USER_ONLY)
e06fcd75 4810 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4811#else
76db3ba4 4812 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4813 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4814 return;
9a64fbe4
FB
4815 }
4816 /* This has no effect: it should ensure that all previous
4817 * tlbie have completed
4818 */
e06fcd75 4819 gen_stop_exception(ctx);
9a64fbe4 4820#endif
79aceca5
FB
4821}
4822
426613db
JM
4823#if defined(TARGET_PPC64)
4824/* slbia */
99e300ef 4825static void gen_slbia(DisasContext *ctx)
426613db
JM
4826{
4827#if defined(CONFIG_USER_ONLY)
e06fcd75 4828 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4829#else
76db3ba4 4830 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4831 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4832 return;
4833 }
c6c7cf05 4834 gen_helper_slbia(cpu_env);
426613db
JM
4835#endif
4836}
4837
4838/* slbie */
99e300ef 4839static void gen_slbie(DisasContext *ctx)
426613db
JM
4840{
4841#if defined(CONFIG_USER_ONLY)
e06fcd75 4842 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4843#else
76db3ba4 4844 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4845 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4846 return;
4847 }
c6c7cf05 4848 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4849#endif
4850}
4851#endif
4852
79aceca5
FB
4853/*** External control ***/
4854/* Optional: */
99e300ef 4855
54623277 4856/* eciwx */
99e300ef 4857static void gen_eciwx(DisasContext *ctx)
79aceca5 4858{
76db3ba4 4859 TCGv t0;
fa407c03 4860 /* Should check EAR[E] ! */
76db3ba4
AJ
4861 gen_set_access_type(ctx, ACCESS_EXT);
4862 t0 = tcg_temp_new();
4863 gen_addr_reg_index(ctx, t0);
fa407c03 4864 gen_check_align(ctx, t0, 0x03);
76db3ba4 4865 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4866 tcg_temp_free(t0);
76a66253
JM
4867}
4868
4869/* ecowx */
99e300ef 4870static void gen_ecowx(DisasContext *ctx)
76a66253 4871{
76db3ba4 4872 TCGv t0;
fa407c03 4873 /* Should check EAR[E] ! */
76db3ba4
AJ
4874 gen_set_access_type(ctx, ACCESS_EXT);
4875 t0 = tcg_temp_new();
4876 gen_addr_reg_index(ctx, t0);
fa407c03 4877 gen_check_align(ctx, t0, 0x03);
76db3ba4 4878 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4879 tcg_temp_free(t0);
76a66253
JM
4880}
4881
4882/* PowerPC 601 specific instructions */
99e300ef 4883
54623277 4884/* abs - abs. */
99e300ef 4885static void gen_abs(DisasContext *ctx)
76a66253 4886{
22e0e173
AJ
4887 int l1 = gen_new_label();
4888 int l2 = gen_new_label();
4889 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4890 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4891 tcg_gen_br(l2);
4892 gen_set_label(l1);
4893 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4894 gen_set_label(l2);
76a66253 4895 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4896 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4897}
4898
4899/* abso - abso. */
99e300ef 4900static void gen_abso(DisasContext *ctx)
76a66253 4901{
22e0e173
AJ
4902 int l1 = gen_new_label();
4903 int l2 = gen_new_label();
4904 int l3 = gen_new_label();
4905 /* Start with XER OV disabled, the most likely case */
da91a00f 4906 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4907 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4908 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4909 tcg_gen_movi_tl(cpu_ov, 1);
4910 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4911 tcg_gen_br(l2);
4912 gen_set_label(l1);
4913 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4914 tcg_gen_br(l3);
4915 gen_set_label(l2);
4916 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4917 gen_set_label(l3);
76a66253 4918 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4919 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4920}
4921
4922/* clcs */
99e300ef 4923static void gen_clcs(DisasContext *ctx)
76a66253 4924{
22e0e173 4925 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4926 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4927 tcg_temp_free_i32(t0);
c7697e1f 4928 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
4929}
4930
4931/* div - div. */
99e300ef 4932static void gen_div(DisasContext *ctx)
76a66253 4933{
d15f74fb
BS
4934 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4935 cpu_gpr[rB(ctx->opcode)]);
76a66253 4936 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4937 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4938}
4939
4940/* divo - divo. */
99e300ef 4941static void gen_divo(DisasContext *ctx)
76a66253 4942{
d15f74fb
BS
4943 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4944 cpu_gpr[rB(ctx->opcode)]);
76a66253 4945 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4946 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4947}
4948
4949/* divs - divs. */
99e300ef 4950static void gen_divs(DisasContext *ctx)
76a66253 4951{
d15f74fb
BS
4952 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4953 cpu_gpr[rB(ctx->opcode)]);
76a66253 4954 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4955 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4956}
4957
4958/* divso - divso. */
99e300ef 4959static void gen_divso(DisasContext *ctx)
76a66253 4960{
d15f74fb
BS
4961 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4962 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 4963 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4964 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4965}
4966
4967/* doz - doz. */
99e300ef 4968static void gen_doz(DisasContext *ctx)
76a66253 4969{
22e0e173
AJ
4970 int l1 = gen_new_label();
4971 int l2 = gen_new_label();
4972 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4973 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4974 tcg_gen_br(l2);
4975 gen_set_label(l1);
4976 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4977 gen_set_label(l2);
76a66253 4978 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4979 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4980}
4981
4982/* dozo - dozo. */
99e300ef 4983static void gen_dozo(DisasContext *ctx)
76a66253 4984{
22e0e173
AJ
4985 int l1 = gen_new_label();
4986 int l2 = gen_new_label();
4987 TCGv t0 = tcg_temp_new();
4988 TCGv t1 = tcg_temp_new();
4989 TCGv t2 = tcg_temp_new();
4990 /* Start with XER OV disabled, the most likely case */
da91a00f 4991 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4992 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4993 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4994 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4995 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4996 tcg_gen_andc_tl(t1, t1, t2);
4997 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4998 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
4999 tcg_gen_movi_tl(cpu_ov, 1);
5000 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5001 tcg_gen_br(l2);
5002 gen_set_label(l1);
5003 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5004 gen_set_label(l2);
5005 tcg_temp_free(t0);
5006 tcg_temp_free(t1);
5007 tcg_temp_free(t2);
76a66253 5008 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5009 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5010}
5011
5012/* dozi */
99e300ef 5013static void gen_dozi(DisasContext *ctx)
76a66253 5014{
22e0e173
AJ
5015 target_long simm = SIMM(ctx->opcode);
5016 int l1 = gen_new_label();
5017 int l2 = gen_new_label();
5018 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5019 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5020 tcg_gen_br(l2);
5021 gen_set_label(l1);
5022 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5023 gen_set_label(l2);
5024 if (unlikely(Rc(ctx->opcode) != 0))
5025 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5026}
5027
76a66253 5028/* lscbx - lscbx. */
99e300ef 5029static void gen_lscbx(DisasContext *ctx)
76a66253 5030{
bdb4b689
AJ
5031 TCGv t0 = tcg_temp_new();
5032 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5033 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5034 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 5035
76db3ba4 5036 gen_addr_reg_index(ctx, t0);
76a66253 5037 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 5038 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 5039 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
5040 tcg_temp_free_i32(t1);
5041 tcg_temp_free_i32(t2);
5042 tcg_temp_free_i32(t3);
3d7b417e 5043 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 5044 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 5045 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
5046 gen_set_Rc0(ctx, t0);
5047 tcg_temp_free(t0);
76a66253
JM
5048}
5049
5050/* maskg - maskg. */
99e300ef 5051static void gen_maskg(DisasContext *ctx)
76a66253 5052{
22e0e173
AJ
5053 int l1 = gen_new_label();
5054 TCGv t0 = tcg_temp_new();
5055 TCGv t1 = tcg_temp_new();
5056 TCGv t2 = tcg_temp_new();
5057 TCGv t3 = tcg_temp_new();
5058 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5059 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5060 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5061 tcg_gen_addi_tl(t2, t0, 1);
5062 tcg_gen_shr_tl(t2, t3, t2);
5063 tcg_gen_shr_tl(t3, t3, t1);
5064 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5065 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5066 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5067 gen_set_label(l1);
5068 tcg_temp_free(t0);
5069 tcg_temp_free(t1);
5070 tcg_temp_free(t2);
5071 tcg_temp_free(t3);
76a66253 5072 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5073 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5074}
5075
5076/* maskir - maskir. */
99e300ef 5077static void gen_maskir(DisasContext *ctx)
76a66253 5078{
22e0e173
AJ
5079 TCGv t0 = tcg_temp_new();
5080 TCGv t1 = tcg_temp_new();
5081 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5082 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5083 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5084 tcg_temp_free(t0);
5085 tcg_temp_free(t1);
76a66253 5086 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5087 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5088}
5089
5090/* mul - mul. */
99e300ef 5091static void gen_mul(DisasContext *ctx)
76a66253 5092{
22e0e173
AJ
5093 TCGv_i64 t0 = tcg_temp_new_i64();
5094 TCGv_i64 t1 = tcg_temp_new_i64();
5095 TCGv t2 = tcg_temp_new();
5096 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5097 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5098 tcg_gen_mul_i64(t0, t0, t1);
5099 tcg_gen_trunc_i64_tl(t2, t0);
5100 gen_store_spr(SPR_MQ, t2);
5101 tcg_gen_shri_i64(t1, t0, 32);
5102 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5103 tcg_temp_free_i64(t0);
5104 tcg_temp_free_i64(t1);
5105 tcg_temp_free(t2);
76a66253 5106 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5107 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5108}
5109
5110/* mulo - mulo. */
99e300ef 5111static void gen_mulo(DisasContext *ctx)
76a66253 5112{
22e0e173
AJ
5113 int l1 = gen_new_label();
5114 TCGv_i64 t0 = tcg_temp_new_i64();
5115 TCGv_i64 t1 = tcg_temp_new_i64();
5116 TCGv t2 = tcg_temp_new();
5117 /* Start with XER OV disabled, the most likely case */
da91a00f 5118 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5119 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5120 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5121 tcg_gen_mul_i64(t0, t0, t1);
5122 tcg_gen_trunc_i64_tl(t2, t0);
5123 gen_store_spr(SPR_MQ, t2);
5124 tcg_gen_shri_i64(t1, t0, 32);
5125 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5126 tcg_gen_ext32s_i64(t1, t0);
5127 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
5128 tcg_gen_movi_tl(cpu_ov, 1);
5129 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5130 gen_set_label(l1);
5131 tcg_temp_free_i64(t0);
5132 tcg_temp_free_i64(t1);
5133 tcg_temp_free(t2);
76a66253 5134 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5135 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5136}
5137
5138/* nabs - nabs. */
99e300ef 5139static void gen_nabs(DisasContext *ctx)
76a66253 5140{
22e0e173
AJ
5141 int l1 = gen_new_label();
5142 int l2 = gen_new_label();
5143 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5144 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5145 tcg_gen_br(l2);
5146 gen_set_label(l1);
5147 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5148 gen_set_label(l2);
76a66253 5149 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5150 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5151}
5152
5153/* nabso - nabso. */
99e300ef 5154static void gen_nabso(DisasContext *ctx)
76a66253 5155{
22e0e173
AJ
5156 int l1 = gen_new_label();
5157 int l2 = gen_new_label();
5158 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5159 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5160 tcg_gen_br(l2);
5161 gen_set_label(l1);
5162 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5163 gen_set_label(l2);
5164 /* nabs never overflows */
da91a00f 5165 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 5166 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5167 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5168}
5169
5170/* rlmi - rlmi. */
99e300ef 5171static void gen_rlmi(DisasContext *ctx)
76a66253 5172{
7487953d
AJ
5173 uint32_t mb = MB(ctx->opcode);
5174 uint32_t me = ME(ctx->opcode);
5175 TCGv t0 = tcg_temp_new();
5176 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5177 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5178 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5179 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5180 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5181 tcg_temp_free(t0);
76a66253 5182 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5183 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5184}
5185
5186/* rrib - rrib. */
99e300ef 5187static void gen_rrib(DisasContext *ctx)
76a66253 5188{
7487953d
AJ
5189 TCGv t0 = tcg_temp_new();
5190 TCGv t1 = tcg_temp_new();
5191 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5192 tcg_gen_movi_tl(t1, 0x80000000);
5193 tcg_gen_shr_tl(t1, t1, t0);
5194 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5195 tcg_gen_and_tl(t0, t0, t1);
5196 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5197 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5198 tcg_temp_free(t0);
5199 tcg_temp_free(t1);
76a66253 5200 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5201 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5202}
5203
5204/* sle - sle. */
99e300ef 5205static void gen_sle(DisasContext *ctx)
76a66253 5206{
7487953d
AJ
5207 TCGv t0 = tcg_temp_new();
5208 TCGv t1 = tcg_temp_new();
5209 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5210 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5211 tcg_gen_subfi_tl(t1, 32, t1);
5212 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5213 tcg_gen_or_tl(t1, t0, t1);
5214 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5215 gen_store_spr(SPR_MQ, t1);
5216 tcg_temp_free(t0);
5217 tcg_temp_free(t1);
76a66253 5218 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5219 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5220}
5221
5222/* sleq - sleq. */
99e300ef 5223static void gen_sleq(DisasContext *ctx)
76a66253 5224{
7487953d
AJ
5225 TCGv t0 = tcg_temp_new();
5226 TCGv t1 = tcg_temp_new();
5227 TCGv t2 = tcg_temp_new();
5228 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5229 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5230 tcg_gen_shl_tl(t2, t2, t0);
5231 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5232 gen_load_spr(t1, SPR_MQ);
5233 gen_store_spr(SPR_MQ, t0);
5234 tcg_gen_and_tl(t0, t0, t2);
5235 tcg_gen_andc_tl(t1, t1, t2);
5236 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5237 tcg_temp_free(t0);
5238 tcg_temp_free(t1);
5239 tcg_temp_free(t2);
76a66253 5240 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5241 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5242}
5243
5244/* sliq - sliq. */
99e300ef 5245static void gen_sliq(DisasContext *ctx)
76a66253 5246{
7487953d
AJ
5247 int sh = SH(ctx->opcode);
5248 TCGv t0 = tcg_temp_new();
5249 TCGv t1 = tcg_temp_new();
5250 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5251 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5252 tcg_gen_or_tl(t1, t0, t1);
5253 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5254 gen_store_spr(SPR_MQ, t1);
5255 tcg_temp_free(t0);
5256 tcg_temp_free(t1);
76a66253 5257 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5258 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5259}
5260
5261/* slliq - slliq. */
99e300ef 5262static void gen_slliq(DisasContext *ctx)
76a66253 5263{
7487953d
AJ
5264 int sh = SH(ctx->opcode);
5265 TCGv t0 = tcg_temp_new();
5266 TCGv t1 = tcg_temp_new();
5267 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5268 gen_load_spr(t1, SPR_MQ);
5269 gen_store_spr(SPR_MQ, t0);
5270 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5271 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5272 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5273 tcg_temp_free(t0);
5274 tcg_temp_free(t1);
76a66253 5275 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5276 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5277}
5278
5279/* sllq - sllq. */
99e300ef 5280static void gen_sllq(DisasContext *ctx)
76a66253 5281{
7487953d
AJ
5282 int l1 = gen_new_label();
5283 int l2 = gen_new_label();
5284 TCGv t0 = tcg_temp_local_new();
5285 TCGv t1 = tcg_temp_local_new();
5286 TCGv t2 = tcg_temp_local_new();
5287 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5288 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5289 tcg_gen_shl_tl(t1, t1, t2);
5290 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5291 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5292 gen_load_spr(t0, SPR_MQ);
5293 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5294 tcg_gen_br(l2);
5295 gen_set_label(l1);
5296 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5297 gen_load_spr(t2, SPR_MQ);
5298 tcg_gen_andc_tl(t1, t2, t1);
5299 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5300 gen_set_label(l2);
5301 tcg_temp_free(t0);
5302 tcg_temp_free(t1);
5303 tcg_temp_free(t2);
76a66253 5304 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5305 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5306}
5307
5308/* slq - slq. */
99e300ef 5309static void gen_slq(DisasContext *ctx)
76a66253 5310{
7487953d
AJ
5311 int l1 = gen_new_label();
5312 TCGv t0 = tcg_temp_new();
5313 TCGv t1 = tcg_temp_new();
5314 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5315 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5316 tcg_gen_subfi_tl(t1, 32, t1);
5317 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5318 tcg_gen_or_tl(t1, t0, t1);
5319 gen_store_spr(SPR_MQ, t1);
5320 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5321 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5322 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5323 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5324 gen_set_label(l1);
5325 tcg_temp_free(t0);
5326 tcg_temp_free(t1);
76a66253 5327 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5328 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5329}
5330
d9bce9d9 5331/* sraiq - sraiq. */
99e300ef 5332static void gen_sraiq(DisasContext *ctx)
76a66253 5333{
7487953d
AJ
5334 int sh = SH(ctx->opcode);
5335 int l1 = gen_new_label();
5336 TCGv t0 = tcg_temp_new();
5337 TCGv t1 = tcg_temp_new();
5338 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5339 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5340 tcg_gen_or_tl(t0, t0, t1);
5341 gen_store_spr(SPR_MQ, t0);
da91a00f 5342 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5343 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5344 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5345 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5346 gen_set_label(l1);
5347 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5348 tcg_temp_free(t0);
5349 tcg_temp_free(t1);
76a66253 5350 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5351 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5352}
5353
5354/* sraq - sraq. */
99e300ef 5355static void gen_sraq(DisasContext *ctx)
76a66253 5356{
7487953d
AJ
5357 int l1 = gen_new_label();
5358 int l2 = gen_new_label();
5359 TCGv t0 = tcg_temp_new();
5360 TCGv t1 = tcg_temp_local_new();
5361 TCGv t2 = tcg_temp_local_new();
5362 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5363 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5364 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5365 tcg_gen_subfi_tl(t2, 32, t2);
5366 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5367 tcg_gen_or_tl(t0, t0, t2);
5368 gen_store_spr(SPR_MQ, t0);
5369 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5370 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5371 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5372 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5373 gen_set_label(l1);
5374 tcg_temp_free(t0);
5375 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5376 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5377 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5378 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5379 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5380 gen_set_label(l2);
5381 tcg_temp_free(t1);
5382 tcg_temp_free(t2);
76a66253 5383 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5384 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5385}
5386
5387/* sre - sre. */
99e300ef 5388static void gen_sre(DisasContext *ctx)
76a66253 5389{
7487953d
AJ
5390 TCGv t0 = tcg_temp_new();
5391 TCGv t1 = tcg_temp_new();
5392 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5393 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5394 tcg_gen_subfi_tl(t1, 32, t1);
5395 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5396 tcg_gen_or_tl(t1, t0, t1);
5397 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5398 gen_store_spr(SPR_MQ, t1);
5399 tcg_temp_free(t0);
5400 tcg_temp_free(t1);
76a66253 5401 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5402 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5403}
5404
5405/* srea - srea. */
99e300ef 5406static void gen_srea(DisasContext *ctx)
76a66253 5407{
7487953d
AJ
5408 TCGv t0 = tcg_temp_new();
5409 TCGv t1 = tcg_temp_new();
5410 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5411 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5412 gen_store_spr(SPR_MQ, t0);
5413 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5414 tcg_temp_free(t0);
5415 tcg_temp_free(t1);
76a66253 5416 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5417 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5418}
5419
5420/* sreq */
99e300ef 5421static void gen_sreq(DisasContext *ctx)
76a66253 5422{
7487953d
AJ
5423 TCGv t0 = tcg_temp_new();
5424 TCGv t1 = tcg_temp_new();
5425 TCGv t2 = tcg_temp_new();
5426 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5427 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5428 tcg_gen_shr_tl(t1, t1, t0);
5429 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5430 gen_load_spr(t2, SPR_MQ);
5431 gen_store_spr(SPR_MQ, t0);
5432 tcg_gen_and_tl(t0, t0, t1);
5433 tcg_gen_andc_tl(t2, t2, t1);
5434 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5435 tcg_temp_free(t0);
5436 tcg_temp_free(t1);
5437 tcg_temp_free(t2);
76a66253 5438 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5439 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5440}
5441
5442/* sriq */
99e300ef 5443static void gen_sriq(DisasContext *ctx)
76a66253 5444{
7487953d
AJ
5445 int sh = SH(ctx->opcode);
5446 TCGv t0 = tcg_temp_new();
5447 TCGv t1 = tcg_temp_new();
5448 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5449 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5450 tcg_gen_or_tl(t1, t0, t1);
5451 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5452 gen_store_spr(SPR_MQ, t1);
5453 tcg_temp_free(t0);
5454 tcg_temp_free(t1);
76a66253 5455 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5456 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5457}
5458
5459/* srliq */
99e300ef 5460static void gen_srliq(DisasContext *ctx)
76a66253 5461{
7487953d
AJ
5462 int sh = SH(ctx->opcode);
5463 TCGv t0 = tcg_temp_new();
5464 TCGv t1 = tcg_temp_new();
5465 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5466 gen_load_spr(t1, SPR_MQ);
5467 gen_store_spr(SPR_MQ, t0);
5468 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5469 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5470 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5471 tcg_temp_free(t0);
5472 tcg_temp_free(t1);
76a66253 5473 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5474 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5475}
5476
5477/* srlq */
99e300ef 5478static void gen_srlq(DisasContext *ctx)
76a66253 5479{
7487953d
AJ
5480 int l1 = gen_new_label();
5481 int l2 = gen_new_label();
5482 TCGv t0 = tcg_temp_local_new();
5483 TCGv t1 = tcg_temp_local_new();
5484 TCGv t2 = tcg_temp_local_new();
5485 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5486 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5487 tcg_gen_shr_tl(t2, t1, t2);
5488 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5489 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5490 gen_load_spr(t0, SPR_MQ);
5491 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5492 tcg_gen_br(l2);
5493 gen_set_label(l1);
5494 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5495 tcg_gen_and_tl(t0, t0, t2);
5496 gen_load_spr(t1, SPR_MQ);
5497 tcg_gen_andc_tl(t1, t1, t2);
5498 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5499 gen_set_label(l2);
5500 tcg_temp_free(t0);
5501 tcg_temp_free(t1);
5502 tcg_temp_free(t2);
76a66253 5503 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5504 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5505}
5506
5507/* srq */
99e300ef 5508static void gen_srq(DisasContext *ctx)
76a66253 5509{
7487953d
AJ
5510 int l1 = gen_new_label();
5511 TCGv t0 = tcg_temp_new();
5512 TCGv t1 = tcg_temp_new();
5513 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5514 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5515 tcg_gen_subfi_tl(t1, 32, t1);
5516 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5517 tcg_gen_or_tl(t1, t0, t1);
5518 gen_store_spr(SPR_MQ, t1);
5519 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5520 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5521 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5522 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5523 gen_set_label(l1);
5524 tcg_temp_free(t0);
5525 tcg_temp_free(t1);
76a66253 5526 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5527 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5528}
5529
5530/* PowerPC 602 specific instructions */
99e300ef 5531
54623277 5532/* dsa */
99e300ef 5533static void gen_dsa(DisasContext *ctx)
76a66253
JM
5534{
5535 /* XXX: TODO */
e06fcd75 5536 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5537}
5538
5539/* esa */
99e300ef 5540static void gen_esa(DisasContext *ctx)
76a66253
JM
5541{
5542 /* XXX: TODO */
e06fcd75 5543 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5544}
5545
5546/* mfrom */
99e300ef 5547static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5548{
5549#if defined(CONFIG_USER_ONLY)
e06fcd75 5550 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5551#else
76db3ba4 5552 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5553 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5554 return;
5555 }
cf02a65c 5556 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5557#endif
5558}
5559
5560/* 602 - 603 - G2 TLB management */
e8eaa2c0 5561
54623277 5562/* tlbld */
e8eaa2c0 5563static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5564{
5565#if defined(CONFIG_USER_ONLY)
e06fcd75 5566 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5567#else
76db3ba4 5568 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5569 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5570 return;
5571 }
c6c7cf05 5572 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5573#endif
5574}
5575
5576/* tlbli */
e8eaa2c0 5577static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5578{
5579#if defined(CONFIG_USER_ONLY)
e06fcd75 5580 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5581#else
76db3ba4 5582 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5583 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5584 return;
5585 }
c6c7cf05 5586 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5587#endif
5588}
5589
7dbe11ac 5590/* 74xx TLB management */
e8eaa2c0 5591
54623277 5592/* tlbld */
e8eaa2c0 5593static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5594{
5595#if defined(CONFIG_USER_ONLY)
e06fcd75 5596 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5597#else
76db3ba4 5598 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5599 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5600 return;
5601 }
c6c7cf05 5602 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5603#endif
5604}
5605
5606/* tlbli */
e8eaa2c0 5607static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5608{
5609#if defined(CONFIG_USER_ONLY)
e06fcd75 5610 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5611#else
76db3ba4 5612 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5613 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5614 return;
5615 }
c6c7cf05 5616 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5617#endif
5618}
5619
76a66253 5620/* POWER instructions not in PowerPC 601 */
99e300ef 5621
54623277 5622/* clf */
99e300ef 5623static void gen_clf(DisasContext *ctx)
76a66253
JM
5624{
5625 /* Cache line flush: implemented as no-op */
5626}
5627
5628/* cli */
99e300ef 5629static void gen_cli(DisasContext *ctx)
76a66253 5630{
7f75ffd3 5631 /* Cache line invalidate: privileged and treated as no-op */
76a66253 5632#if defined(CONFIG_USER_ONLY)
e06fcd75 5633 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5634#else
76db3ba4 5635 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5636 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5637 return;
5638 }
5639#endif
5640}
5641
5642/* dclst */
99e300ef 5643static void gen_dclst(DisasContext *ctx)
76a66253
JM
5644{
5645 /* Data cache line store: treated as no-op */
5646}
5647
99e300ef 5648static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5649{
5650#if defined(CONFIG_USER_ONLY)
e06fcd75 5651 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5652#else
74d37793
AJ
5653 int ra = rA(ctx->opcode);
5654 int rd = rD(ctx->opcode);
5655 TCGv t0;
76db3ba4 5656 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5657 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5658 return;
5659 }
74d37793 5660 t0 = tcg_temp_new();
76db3ba4 5661 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5662 tcg_gen_shri_tl(t0, t0, 28);
5663 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5664 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5665 tcg_temp_free(t0);
76a66253 5666 if (ra != 0 && ra != rd)
74d37793 5667 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5668#endif
5669}
5670
99e300ef 5671static void gen_rac(DisasContext *ctx)
76a66253
JM
5672{
5673#if defined(CONFIG_USER_ONLY)
e06fcd75 5674 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5675#else
22e0e173 5676 TCGv t0;
76db3ba4 5677 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5678 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5679 return;
5680 }
22e0e173 5681 t0 = tcg_temp_new();
76db3ba4 5682 gen_addr_reg_index(ctx, t0);
c6c7cf05 5683 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5684 tcg_temp_free(t0);
76a66253
JM
5685#endif
5686}
5687
99e300ef 5688static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5689{
5690#if defined(CONFIG_USER_ONLY)
e06fcd75 5691 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5692#else
76db3ba4 5693 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5694 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5695 return;
5696 }
e5f17ac6 5697 gen_helper_rfsvc(cpu_env);
e06fcd75 5698 gen_sync_exception(ctx);
76a66253
JM
5699#endif
5700}
5701
5702/* svc is not implemented for now */
5703
5704/* POWER2 specific instructions */
5705/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5706
5707/* lfq */
99e300ef 5708static void gen_lfq(DisasContext *ctx)
76a66253 5709{
01a4afeb 5710 int rd = rD(ctx->opcode);
76db3ba4
AJ
5711 TCGv t0;
5712 gen_set_access_type(ctx, ACCESS_FLOAT);
5713 t0 = tcg_temp_new();
5714 gen_addr_imm_index(ctx, t0, 0);
5715 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5716 gen_addr_add(ctx, t0, t0, 8);
5717 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5718 tcg_temp_free(t0);
76a66253
JM
5719}
5720
5721/* lfqu */
99e300ef 5722static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5723{
5724 int ra = rA(ctx->opcode);
01a4afeb 5725 int rd = rD(ctx->opcode);
76db3ba4
AJ
5726 TCGv t0, t1;
5727 gen_set_access_type(ctx, ACCESS_FLOAT);
5728 t0 = tcg_temp_new();
5729 t1 = tcg_temp_new();
5730 gen_addr_imm_index(ctx, t0, 0);
5731 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5732 gen_addr_add(ctx, t1, t0, 8);
5733 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5734 if (ra != 0)
01a4afeb
AJ
5735 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5736 tcg_temp_free(t0);
5737 tcg_temp_free(t1);
76a66253
JM
5738}
5739
5740/* lfqux */
99e300ef 5741static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5742{
5743 int ra = rA(ctx->opcode);
01a4afeb 5744 int rd = rD(ctx->opcode);
76db3ba4
AJ
5745 gen_set_access_type(ctx, ACCESS_FLOAT);
5746 TCGv t0, t1;
5747 t0 = tcg_temp_new();
5748 gen_addr_reg_index(ctx, t0);
5749 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5750 t1 = tcg_temp_new();
5751 gen_addr_add(ctx, t1, t0, 8);
5752 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5753 tcg_temp_free(t1);
76a66253 5754 if (ra != 0)
01a4afeb
AJ
5755 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5756 tcg_temp_free(t0);
76a66253
JM
5757}
5758
5759/* lfqx */
99e300ef 5760static void gen_lfqx(DisasContext *ctx)
76a66253 5761{
01a4afeb 5762 int rd = rD(ctx->opcode);
76db3ba4
AJ
5763 TCGv t0;
5764 gen_set_access_type(ctx, ACCESS_FLOAT);
5765 t0 = tcg_temp_new();
5766 gen_addr_reg_index(ctx, t0);
5767 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5768 gen_addr_add(ctx, t0, t0, 8);
5769 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5770 tcg_temp_free(t0);
76a66253
JM
5771}
5772
5773/* stfq */
99e300ef 5774static void gen_stfq(DisasContext *ctx)
76a66253 5775{
01a4afeb 5776 int rd = rD(ctx->opcode);
76db3ba4
AJ
5777 TCGv t0;
5778 gen_set_access_type(ctx, ACCESS_FLOAT);
5779 t0 = tcg_temp_new();
5780 gen_addr_imm_index(ctx, t0, 0);
5781 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5782 gen_addr_add(ctx, t0, t0, 8);
5783 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5784 tcg_temp_free(t0);
76a66253
JM
5785}
5786
5787/* stfqu */
99e300ef 5788static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5789{
5790 int ra = rA(ctx->opcode);
01a4afeb 5791 int rd = rD(ctx->opcode);
76db3ba4
AJ
5792 TCGv t0, t1;
5793 gen_set_access_type(ctx, ACCESS_FLOAT);
5794 t0 = tcg_temp_new();
5795 gen_addr_imm_index(ctx, t0, 0);
5796 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5797 t1 = tcg_temp_new();
5798 gen_addr_add(ctx, t1, t0, 8);
5799 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5800 tcg_temp_free(t1);
76a66253 5801 if (ra != 0)
01a4afeb
AJ
5802 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5803 tcg_temp_free(t0);
76a66253
JM
5804}
5805
5806/* stfqux */
99e300ef 5807static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5808{
5809 int ra = rA(ctx->opcode);
01a4afeb 5810 int rd = rD(ctx->opcode);
76db3ba4
AJ
5811 TCGv t0, t1;
5812 gen_set_access_type(ctx, ACCESS_FLOAT);
5813 t0 = tcg_temp_new();
5814 gen_addr_reg_index(ctx, t0);
5815 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5816 t1 = tcg_temp_new();
5817 gen_addr_add(ctx, t1, t0, 8);
5818 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5819 tcg_temp_free(t1);
76a66253 5820 if (ra != 0)
01a4afeb
AJ
5821 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5822 tcg_temp_free(t0);
76a66253
JM
5823}
5824
5825/* stfqx */
99e300ef 5826static void gen_stfqx(DisasContext *ctx)
76a66253 5827{
01a4afeb 5828 int rd = rD(ctx->opcode);
76db3ba4
AJ
5829 TCGv t0;
5830 gen_set_access_type(ctx, ACCESS_FLOAT);
5831 t0 = tcg_temp_new();
5832 gen_addr_reg_index(ctx, t0);
5833 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5834 gen_addr_add(ctx, t0, t0, 8);
5835 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5836 tcg_temp_free(t0);
76a66253
JM
5837}
5838
5839/* BookE specific instructions */
99e300ef 5840
54623277 5841/* XXX: not implemented on 440 ? */
99e300ef 5842static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5843{
5844 /* XXX: TODO */
e06fcd75 5845 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5846}
5847
2662a059 5848/* XXX: not implemented on 440 ? */
99e300ef 5849static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5850{
5851#if defined(CONFIG_USER_ONLY)
e06fcd75 5852 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5853#else
74d37793 5854 TCGv t0;
76db3ba4 5855 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5856 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5857 return;
5858 }
ec72e276 5859 t0 = tcg_temp_new();
76db3ba4 5860 gen_addr_reg_index(ctx, t0);
c6c7cf05 5861 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5862 tcg_temp_free(t0);
76a66253
JM
5863#endif
5864}
5865
5866/* All 405 MAC instructions are translated here */
636aa200
BS
5867static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5868 int ra, int rb, int rt, int Rc)
76a66253 5869{
182608d4
AJ
5870 TCGv t0, t1;
5871
a7812ae4
PB
5872 t0 = tcg_temp_local_new();
5873 t1 = tcg_temp_local_new();
182608d4 5874
76a66253
JM
5875 switch (opc3 & 0x0D) {
5876 case 0x05:
5877 /* macchw - macchw. - macchwo - macchwo. */
5878 /* macchws - macchws. - macchwso - macchwso. */
5879 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5880 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5881 /* mulchw - mulchw. */
182608d4
AJ
5882 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5883 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5884 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5885 break;
5886 case 0x04:
5887 /* macchwu - macchwu. - macchwuo - macchwuo. */
5888 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5889 /* mulchwu - mulchwu. */
182608d4
AJ
5890 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5891 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5892 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5893 break;
5894 case 0x01:
5895 /* machhw - machhw. - machhwo - machhwo. */
5896 /* machhws - machhws. - machhwso - machhwso. */
5897 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5898 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5899 /* mulhhw - mulhhw. */
182608d4
AJ
5900 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5901 tcg_gen_ext16s_tl(t0, t0);
5902 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5903 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5904 break;
5905 case 0x00:
5906 /* machhwu - machhwu. - machhwuo - machhwuo. */
5907 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5908 /* mulhhwu - mulhhwu. */
182608d4
AJ
5909 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5910 tcg_gen_ext16u_tl(t0, t0);
5911 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5912 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5913 break;
5914 case 0x0D:
5915 /* maclhw - maclhw. - maclhwo - maclhwo. */
5916 /* maclhws - maclhws. - maclhwso - maclhwso. */
5917 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5918 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5919 /* mullhw - mullhw. */
182608d4
AJ
5920 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5921 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5922 break;
5923 case 0x0C:
5924 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5925 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5926 /* mullhwu - mullhwu. */
182608d4
AJ
5927 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5928 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
5929 break;
5930 }
76a66253 5931 if (opc2 & 0x04) {
182608d4
AJ
5932 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5933 tcg_gen_mul_tl(t1, t0, t1);
5934 if (opc2 & 0x02) {
5935 /* nmultiply-and-accumulate (0x0E) */
5936 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5937 } else {
5938 /* multiply-and-accumulate (0x0C) */
5939 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5940 }
5941
5942 if (opc3 & 0x12) {
5943 /* Check overflow and/or saturate */
5944 int l1 = gen_new_label();
5945
5946 if (opc3 & 0x10) {
5947 /* Start with XER OV disabled, the most likely case */
da91a00f 5948 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
5949 }
5950 if (opc3 & 0x01) {
5951 /* Signed */
5952 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5953 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5954 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5955 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 5956 if (opc3 & 0x02) {
182608d4
AJ
5957 /* Saturate */
5958 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5959 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5960 }
5961 } else {
5962 /* Unsigned */
5963 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 5964 if (opc3 & 0x02) {
182608d4
AJ
5965 /* Saturate */
5966 tcg_gen_movi_tl(t0, UINT32_MAX);
5967 }
5968 }
5969 if (opc3 & 0x10) {
5970 /* Check overflow */
da91a00f
RH
5971 tcg_gen_movi_tl(cpu_ov, 1);
5972 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
5973 }
5974 gen_set_label(l1);
5975 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5976 }
5977 } else {
5978 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 5979 }
182608d4
AJ
5980 tcg_temp_free(t0);
5981 tcg_temp_free(t1);
76a66253
JM
5982 if (unlikely(Rc) != 0) {
5983 /* Update Rc0 */
182608d4 5984 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
5985 }
5986}
5987
a750fc0b 5988#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 5989static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
5990{ \
5991 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5992 rD(ctx->opcode), Rc(ctx->opcode)); \
5993}
5994
5995/* macchw - macchw. */
a750fc0b 5996GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 5997/* macchwo - macchwo. */
a750fc0b 5998GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 5999/* macchws - macchws. */
a750fc0b 6000GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 6001/* macchwso - macchwso. */
a750fc0b 6002GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 6003/* macchwsu - macchwsu. */
a750fc0b 6004GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 6005/* macchwsuo - macchwsuo. */
a750fc0b 6006GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 6007/* macchwu - macchwu. */
a750fc0b 6008GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 6009/* macchwuo - macchwuo. */
a750fc0b 6010GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 6011/* machhw - machhw. */
a750fc0b 6012GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 6013/* machhwo - machhwo. */
a750fc0b 6014GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 6015/* machhws - machhws. */
a750fc0b 6016GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 6017/* machhwso - machhwso. */
a750fc0b 6018GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 6019/* machhwsu - machhwsu. */
a750fc0b 6020GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 6021/* machhwsuo - machhwsuo. */
a750fc0b 6022GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 6023/* machhwu - machhwu. */
a750fc0b 6024GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 6025/* machhwuo - machhwuo. */
a750fc0b 6026GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 6027/* maclhw - maclhw. */
a750fc0b 6028GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 6029/* maclhwo - maclhwo. */
a750fc0b 6030GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 6031/* maclhws - maclhws. */
a750fc0b 6032GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 6033/* maclhwso - maclhwso. */
a750fc0b 6034GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 6035/* maclhwu - maclhwu. */
a750fc0b 6036GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 6037/* maclhwuo - maclhwuo. */
a750fc0b 6038GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 6039/* maclhwsu - maclhwsu. */
a750fc0b 6040GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 6041/* maclhwsuo - maclhwsuo. */
a750fc0b 6042GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 6043/* nmacchw - nmacchw. */
a750fc0b 6044GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 6045/* nmacchwo - nmacchwo. */
a750fc0b 6046GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 6047/* nmacchws - nmacchws. */
a750fc0b 6048GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 6049/* nmacchwso - nmacchwso. */
a750fc0b 6050GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 6051/* nmachhw - nmachhw. */
a750fc0b 6052GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 6053/* nmachhwo - nmachhwo. */
a750fc0b 6054GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 6055/* nmachhws - nmachhws. */
a750fc0b 6056GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 6057/* nmachhwso - nmachhwso. */
a750fc0b 6058GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 6059/* nmaclhw - nmaclhw. */
a750fc0b 6060GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 6061/* nmaclhwo - nmaclhwo. */
a750fc0b 6062GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 6063/* nmaclhws - nmaclhws. */
a750fc0b 6064GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 6065/* nmaclhwso - nmaclhwso. */
a750fc0b 6066GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
6067
6068/* mulchw - mulchw. */
a750fc0b 6069GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 6070/* mulchwu - mulchwu. */
a750fc0b 6071GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 6072/* mulhhw - mulhhw. */
a750fc0b 6073GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 6074/* mulhhwu - mulhhwu. */
a750fc0b 6075GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 6076/* mullhw - mullhw. */
a750fc0b 6077GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 6078/* mullhwu - mullhwu. */
a750fc0b 6079GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
6080
6081/* mfdcr */
99e300ef 6082static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
6083{
6084#if defined(CONFIG_USER_ONLY)
e06fcd75 6085 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6086#else
06dca6a7 6087 TCGv dcrn;
76db3ba4 6088 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6089 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6090 return;
6091 }
06dca6a7
AJ
6092 /* NIP cannot be restored if the memory exception comes from an helper */
6093 gen_update_nip(ctx, ctx->nip - 4);
6094 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6095 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 6096 tcg_temp_free(dcrn);
76a66253
JM
6097#endif
6098}
6099
6100/* mtdcr */
99e300ef 6101static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
6102{
6103#if defined(CONFIG_USER_ONLY)
e06fcd75 6104 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6105#else
06dca6a7 6106 TCGv dcrn;
76db3ba4 6107 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6108 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6109 return;
6110 }
06dca6a7
AJ
6111 /* NIP cannot be restored if the memory exception comes from an helper */
6112 gen_update_nip(ctx, ctx->nip - 4);
6113 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6114 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 6115 tcg_temp_free(dcrn);
a42bd6cc
JM
6116#endif
6117}
6118
6119/* mfdcrx */
2662a059 6120/* XXX: not implemented on 440 ? */
99e300ef 6121static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
6122{
6123#if defined(CONFIG_USER_ONLY)
e06fcd75 6124 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6125#else
76db3ba4 6126 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6127 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6128 return;
6129 }
06dca6a7
AJ
6130 /* NIP cannot be restored if the memory exception comes from an helper */
6131 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6132 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6133 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 6134 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
6135#endif
6136}
6137
6138/* mtdcrx */
2662a059 6139/* XXX: not implemented on 440 ? */
99e300ef 6140static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
6141{
6142#if defined(CONFIG_USER_ONLY)
e06fcd75 6143 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6144#else
76db3ba4 6145 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6146 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6147 return;
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_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6152 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 6153 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
6154#endif
6155}
6156
a750fc0b 6157/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6158static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 6159{
06dca6a7
AJ
6160 /* NIP cannot be restored if the memory exception comes from an helper */
6161 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6162 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6163 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
6164 /* Note: Rc update flag set leads to undefined state of Rc0 */
6165}
6166
6167/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6168static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 6169{
06dca6a7
AJ
6170 /* NIP cannot be restored if the memory exception comes from an helper */
6171 gen_update_nip(ctx, ctx->nip - 4);
975e5463 6172 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 6173 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
6174 /* Note: Rc update flag set leads to undefined state of Rc0 */
6175}
6176
76a66253 6177/* dccci */
99e300ef 6178static void gen_dccci(DisasContext *ctx)
76a66253
JM
6179{
6180#if defined(CONFIG_USER_ONLY)
e06fcd75 6181 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6182#else
76db3ba4 6183 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6184 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6185 return;
6186 }
6187 /* interpreted as no-op */
6188#endif
6189}
6190
6191/* dcread */
99e300ef 6192static void gen_dcread(DisasContext *ctx)
76a66253
JM
6193{
6194#if defined(CONFIG_USER_ONLY)
e06fcd75 6195 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6196#else
b61f2753 6197 TCGv EA, val;
76db3ba4 6198 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6199 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6200 return;
6201 }
76db3ba4 6202 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 6203 EA = tcg_temp_new();
76db3ba4 6204 gen_addr_reg_index(ctx, EA);
a7812ae4 6205 val = tcg_temp_new();
76db3ba4 6206 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
6207 tcg_temp_free(val);
6208 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6209 tcg_temp_free(EA);
76a66253
JM
6210#endif
6211}
6212
6213/* icbt */
e8eaa2c0 6214static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6215{
6216 /* interpreted as no-op */
6217 /* XXX: specification say this is treated as a load by the MMU
6218 * but does not generate any exception
6219 */
6220}
6221
6222/* iccci */
99e300ef 6223static void gen_iccci(DisasContext *ctx)
76a66253
JM
6224{
6225#if defined(CONFIG_USER_ONLY)
e06fcd75 6226 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6227#else
76db3ba4 6228 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6229 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6230 return;
6231 }
6232 /* interpreted as no-op */
6233#endif
6234}
6235
6236/* icread */
99e300ef 6237static void gen_icread(DisasContext *ctx)
76a66253
JM
6238{
6239#if defined(CONFIG_USER_ONLY)
e06fcd75 6240 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6241#else
76db3ba4 6242 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6243 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6244 return;
6245 }
6246 /* interpreted as no-op */
6247#endif
6248}
6249
76db3ba4 6250/* rfci (mem_idx only) */
e8eaa2c0 6251static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
6252{
6253#if defined(CONFIG_USER_ONLY)
e06fcd75 6254 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6255#else
76db3ba4 6256 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6257 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6258 return;
6259 }
6260 /* Restore CPU state */
e5f17ac6 6261 gen_helper_40x_rfci(cpu_env);
e06fcd75 6262 gen_sync_exception(ctx);
a42bd6cc
JM
6263#endif
6264}
6265
99e300ef 6266static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6267{
6268#if defined(CONFIG_USER_ONLY)
e06fcd75 6269 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6270#else
76db3ba4 6271 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6272 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6273 return;
6274 }
6275 /* Restore CPU state */
e5f17ac6 6276 gen_helper_rfci(cpu_env);
e06fcd75 6277 gen_sync_exception(ctx);
a42bd6cc
JM
6278#endif
6279}
6280
6281/* BookE specific */
99e300ef 6282
54623277 6283/* XXX: not implemented on 440 ? */
99e300ef 6284static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6285{
6286#if defined(CONFIG_USER_ONLY)
e06fcd75 6287 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6288#else
76db3ba4 6289 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6290 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6291 return;
6292 }
6293 /* Restore CPU state */
e5f17ac6 6294 gen_helper_rfdi(cpu_env);
e06fcd75 6295 gen_sync_exception(ctx);
76a66253
JM
6296#endif
6297}
6298
2662a059 6299/* XXX: not implemented on 440 ? */
99e300ef 6300static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6301{
6302#if defined(CONFIG_USER_ONLY)
e06fcd75 6303 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6304#else
76db3ba4 6305 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6306 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6307 return;
6308 }
6309 /* Restore CPU state */
e5f17ac6 6310 gen_helper_rfmci(cpu_env);
e06fcd75 6311 gen_sync_exception(ctx);
a42bd6cc
JM
6312#endif
6313}
5eb7995e 6314
d9bce9d9 6315/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6316
54623277 6317/* tlbre */
e8eaa2c0 6318static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6319{
6320#if defined(CONFIG_USER_ONLY)
e06fcd75 6321 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6322#else
76db3ba4 6323 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6324 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6325 return;
6326 }
6327 switch (rB(ctx->opcode)) {
6328 case 0:
c6c7cf05
BS
6329 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6330 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6331 break;
6332 case 1:
c6c7cf05
BS
6333 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6334 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6335 break;
6336 default:
e06fcd75 6337 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6338 break;
9a64fbe4 6339 }
76a66253
JM
6340#endif
6341}
6342
d9bce9d9 6343/* tlbsx - tlbsx. */
e8eaa2c0 6344static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6345{
6346#if defined(CONFIG_USER_ONLY)
e06fcd75 6347 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6348#else
74d37793 6349 TCGv t0;
76db3ba4 6350 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6351 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6352 return;
6353 }
74d37793 6354 t0 = tcg_temp_new();
76db3ba4 6355 gen_addr_reg_index(ctx, t0);
c6c7cf05 6356 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6357 tcg_temp_free(t0);
6358 if (Rc(ctx->opcode)) {
6359 int l1 = gen_new_label();
da91a00f 6360 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6361 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6362 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6363 gen_set_label(l1);
6364 }
76a66253 6365#endif
79aceca5
FB
6366}
6367
76a66253 6368/* tlbwe */
e8eaa2c0 6369static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6370{
76a66253 6371#if defined(CONFIG_USER_ONLY)
e06fcd75 6372 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6373#else
76db3ba4 6374 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6375 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6376 return;
6377 }
6378 switch (rB(ctx->opcode)) {
6379 case 0:
c6c7cf05
BS
6380 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6381 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6382 break;
6383 case 1:
c6c7cf05
BS
6384 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6385 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6386 break;
6387 default:
e06fcd75 6388 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6389 break;
9a64fbe4 6390 }
76a66253
JM
6391#endif
6392}
6393
a4bb6c3e 6394/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6395
54623277 6396/* tlbre */
e8eaa2c0 6397static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6398{
6399#if defined(CONFIG_USER_ONLY)
e06fcd75 6400 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6401#else
76db3ba4 6402 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6403 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6404 return;
6405 }
6406 switch (rB(ctx->opcode)) {
6407 case 0:
5eb7995e 6408 case 1:
5eb7995e 6409 case 2:
74d37793
AJ
6410 {
6411 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6412 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6413 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6414 tcg_temp_free_i32(t0);
6415 }
5eb7995e
JM
6416 break;
6417 default:
e06fcd75 6418 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6419 break;
6420 }
6421#endif
6422}
6423
6424/* tlbsx - tlbsx. */
e8eaa2c0 6425static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6426{
6427#if defined(CONFIG_USER_ONLY)
e06fcd75 6428 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6429#else
74d37793 6430 TCGv t0;
76db3ba4 6431 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6432 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6433 return;
6434 }
74d37793 6435 t0 = tcg_temp_new();
76db3ba4 6436 gen_addr_reg_index(ctx, t0);
c6c7cf05 6437 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6438 tcg_temp_free(t0);
6439 if (Rc(ctx->opcode)) {
6440 int l1 = gen_new_label();
da91a00f 6441 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6442 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6443 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6444 gen_set_label(l1);
6445 }
5eb7995e
JM
6446#endif
6447}
6448
6449/* tlbwe */
e8eaa2c0 6450static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
6451{
6452#if defined(CONFIG_USER_ONLY)
e06fcd75 6453 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6454#else
76db3ba4 6455 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6456 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6457 return;
6458 }
6459 switch (rB(ctx->opcode)) {
6460 case 0:
5eb7995e 6461 case 1:
5eb7995e 6462 case 2:
74d37793
AJ
6463 {
6464 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6465 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6466 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
6467 tcg_temp_free_i32(t0);
6468 }
5eb7995e
JM
6469 break;
6470 default:
e06fcd75 6471 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6472 break;
6473 }
6474#endif
6475}
6476
01662f3e
AG
6477/* TLB management - PowerPC BookE 2.06 implementation */
6478
6479/* tlbre */
6480static void gen_tlbre_booke206(DisasContext *ctx)
6481{
6482#if defined(CONFIG_USER_ONLY)
6483 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6484#else
6485 if (unlikely(!ctx->mem_idx)) {
6486 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6487 return;
6488 }
6489
c6c7cf05 6490 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6491#endif
6492}
6493
6494/* tlbsx - tlbsx. */
6495static void gen_tlbsx_booke206(DisasContext *ctx)
6496{
6497#if defined(CONFIG_USER_ONLY)
6498 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6499#else
6500 TCGv t0;
6501 if (unlikely(!ctx->mem_idx)) {
6502 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6503 return;
6504 }
6505
6506 if (rA(ctx->opcode)) {
6507 t0 = tcg_temp_new();
6508 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6509 } else {
6510 t0 = tcg_const_tl(0);
6511 }
6512
6513 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6514 gen_helper_booke206_tlbsx(cpu_env, t0);
c80d1df5 6515 tcg_temp_free(t0);
01662f3e
AG
6516#endif
6517}
6518
6519/* tlbwe */
6520static void gen_tlbwe_booke206(DisasContext *ctx)
6521{
6522#if defined(CONFIG_USER_ONLY)
6523 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6524#else
6525 if (unlikely(!ctx->mem_idx)) {
6526 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6527 return;
6528 }
3f162d11 6529 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6530 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6531#endif
6532}
6533
6534static void gen_tlbivax_booke206(DisasContext *ctx)
6535{
6536#if defined(CONFIG_USER_ONLY)
6537 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6538#else
6539 TCGv t0;
6540 if (unlikely(!ctx->mem_idx)) {
6541 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6542 return;
6543 }
6544
6545 t0 = tcg_temp_new();
6546 gen_addr_reg_index(ctx, t0);
6547
c6c7cf05 6548 gen_helper_booke206_tlbivax(cpu_env, t0);
c80d1df5 6549 tcg_temp_free(t0);
01662f3e
AG
6550#endif
6551}
6552
6d3db821
AG
6553static void gen_tlbilx_booke206(DisasContext *ctx)
6554{
6555#if defined(CONFIG_USER_ONLY)
6556 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6557#else
6558 TCGv t0;
6559 if (unlikely(!ctx->mem_idx)) {
6560 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6561 return;
6562 }
6563
6564 t0 = tcg_temp_new();
6565 gen_addr_reg_index(ctx, t0);
6566
6567 switch((ctx->opcode >> 21) & 0x3) {
6568 case 0:
c6c7cf05 6569 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6570 break;
6571 case 1:
c6c7cf05 6572 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6573 break;
6574 case 3:
c6c7cf05 6575 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6576 break;
6577 default:
6578 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6579 break;
6580 }
6581
6582 tcg_temp_free(t0);
6583#endif
6584}
6585
01662f3e 6586
76a66253 6587/* wrtee */
99e300ef 6588static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6589{
6590#if defined(CONFIG_USER_ONLY)
e06fcd75 6591 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6592#else
6527f6ea 6593 TCGv t0;
76db3ba4 6594 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6595 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6596 return;
6597 }
6527f6ea
AJ
6598 t0 = tcg_temp_new();
6599 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6600 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6601 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6602 tcg_temp_free(t0);
dee96f6c
JM
6603 /* Stop translation to have a chance to raise an exception
6604 * if we just set msr_ee to 1
6605 */
e06fcd75 6606 gen_stop_exception(ctx);
76a66253
JM
6607#endif
6608}
6609
6610/* wrteei */
99e300ef 6611static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6612{
6613#if defined(CONFIG_USER_ONLY)
e06fcd75 6614 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6615#else
76db3ba4 6616 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6617 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6618 return;
6619 }
fbe73008 6620 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6621 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6622 /* Stop translation to have a chance to raise an exception */
e06fcd75 6623 gen_stop_exception(ctx);
6527f6ea 6624 } else {
1b6e5f99 6625 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6626 }
76a66253
JM
6627#endif
6628}
6629
08e46e54 6630/* PowerPC 440 specific instructions */
99e300ef 6631
54623277 6632/* dlmzb */
99e300ef 6633static void gen_dlmzb(DisasContext *ctx)
76a66253 6634{
ef0d51af 6635 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6636 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6637 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6638 tcg_temp_free_i32(t0);
76a66253
JM
6639}
6640
6641/* mbar replaces eieio on 440 */
99e300ef 6642static void gen_mbar(DisasContext *ctx)
76a66253
JM
6643{
6644 /* interpreted as no-op */
6645}
6646
6647/* msync replaces sync on 440 */
dcb2b9e1 6648static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6649{
6650 /* interpreted as no-op */
6651}
6652
6653/* icbt */
e8eaa2c0 6654static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6655{
6656 /* interpreted as no-op */
6657 /* XXX: specification say this is treated as a load by the MMU
6658 * but does not generate any exception
6659 */
79aceca5
FB
6660}
6661
9e0b5cb1
AG
6662/* Embedded.Processor Control */
6663
6664static void gen_msgclr(DisasContext *ctx)
6665{
6666#if defined(CONFIG_USER_ONLY)
6667 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6668#else
6669 if (unlikely(ctx->mem_idx == 0)) {
6670 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6671 return;
6672 }
6673
e5f17ac6 6674 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6675#endif
6676}
6677
d5d11a39
AG
6678static void gen_msgsnd(DisasContext *ctx)
6679{
6680#if defined(CONFIG_USER_ONLY)
6681 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6682#else
6683 if (unlikely(ctx->mem_idx == 0)) {
6684 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6685 return;
6686 }
6687
6688 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6689#endif
6690}
6691
a9d9eb8f
JM
6692/*** Altivec vector extension ***/
6693/* Altivec registers moves */
a9d9eb8f 6694
636aa200 6695static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6696{
e4704b3b 6697 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6698 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6699 return r;
6700}
6701
a9d9eb8f 6702#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6703static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6704{ \
fe1e5c53 6705 TCGv EA; \
a9d9eb8f 6706 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6707 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6708 return; \
6709 } \
76db3ba4 6710 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6711 EA = tcg_temp_new(); \
76db3ba4 6712 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6713 tcg_gen_andi_tl(EA, EA, ~0xf); \
e22c357b
DK
6714 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
6715 64-bit byteswap already. */ \
76db3ba4
AJ
6716 if (ctx->le_mode) { \
6717 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6718 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6719 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6720 } else { \
76db3ba4 6721 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6722 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6723 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6724 } \
6725 tcg_temp_free(EA); \
a9d9eb8f
JM
6726}
6727
6728#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6729static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6730{ \
fe1e5c53 6731 TCGv EA; \
a9d9eb8f 6732 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6733 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6734 return; \
6735 } \
76db3ba4 6736 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6737 EA = tcg_temp_new(); \
76db3ba4 6738 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6739 tcg_gen_andi_tl(EA, EA, ~0xf); \
e22c357b
DK
6740 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
6741 64-bit byteswap already. */ \
76db3ba4
AJ
6742 if (ctx->le_mode) { \
6743 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6744 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6745 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6746 } else { \
76db3ba4 6747 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6748 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6749 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6750 } \
6751 tcg_temp_free(EA); \
a9d9eb8f
JM
6752}
6753
cbfb6ae9 6754#define GEN_VR_LVE(name, opc2, opc3) \
99e300ef 6755static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6756 { \
6757 TCGv EA; \
6758 TCGv_ptr rs; \
6759 if (unlikely(!ctx->altivec_enabled)) { \
6760 gen_exception(ctx, POWERPC_EXCP_VPU); \
6761 return; \
6762 } \
6763 gen_set_access_type(ctx, ACCESS_INT); \
6764 EA = tcg_temp_new(); \
6765 gen_addr_reg_index(ctx, EA); \
6766 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6767 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6768 tcg_temp_free(EA); \
6769 tcg_temp_free_ptr(rs); \
6770 }
6771
6772#define GEN_VR_STVE(name, opc2, opc3) \
99e300ef 6773static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6774 { \
6775 TCGv EA; \
6776 TCGv_ptr rs; \
6777 if (unlikely(!ctx->altivec_enabled)) { \
6778 gen_exception(ctx, POWERPC_EXCP_VPU); \
6779 return; \
6780 } \
6781 gen_set_access_type(ctx, ACCESS_INT); \
6782 EA = tcg_temp_new(); \
6783 gen_addr_reg_index(ctx, EA); \
6784 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6785 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6786 tcg_temp_free(EA); \
6787 tcg_temp_free_ptr(rs); \
6788 }
6789
fe1e5c53 6790GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6791/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6792GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6793
cbfb6ae9
AJ
6794GEN_VR_LVE(bx, 0x07, 0x00);
6795GEN_VR_LVE(hx, 0x07, 0x01);
6796GEN_VR_LVE(wx, 0x07, 0x02);
6797
fe1e5c53 6798GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6799/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6800GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6801
cbfb6ae9
AJ
6802GEN_VR_STVE(bx, 0x07, 0x04);
6803GEN_VR_STVE(hx, 0x07, 0x05);
6804GEN_VR_STVE(wx, 0x07, 0x06);
6805
99e300ef 6806static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6807{
6808 TCGv_ptr rd;
6809 TCGv EA;
6810 if (unlikely(!ctx->altivec_enabled)) {
6811 gen_exception(ctx, POWERPC_EXCP_VPU);
6812 return;
6813 }
6814 EA = tcg_temp_new();
6815 gen_addr_reg_index(ctx, EA);
6816 rd = gen_avr_ptr(rD(ctx->opcode));
6817 gen_helper_lvsl(rd, EA);
6818 tcg_temp_free(EA);
6819 tcg_temp_free_ptr(rd);
6820}
6821
99e300ef 6822static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6823{
6824 TCGv_ptr rd;
6825 TCGv EA;
6826 if (unlikely(!ctx->altivec_enabled)) {
6827 gen_exception(ctx, POWERPC_EXCP_VPU);
6828 return;
6829 }
6830 EA = tcg_temp_new();
6831 gen_addr_reg_index(ctx, EA);
6832 rd = gen_avr_ptr(rD(ctx->opcode));
6833 gen_helper_lvsr(rd, EA);
6834 tcg_temp_free(EA);
6835 tcg_temp_free_ptr(rd);
6836}
6837
99e300ef 6838static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6839{
6840 TCGv_i32 t;
6841 if (unlikely(!ctx->altivec_enabled)) {
6842 gen_exception(ctx, POWERPC_EXCP_VPU);
6843 return;
6844 }
6845 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6846 t = tcg_temp_new_i32();
1328c2bf 6847 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6848 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6849 tcg_temp_free_i32(t);
785f451b
AJ
6850}
6851
99e300ef 6852static void gen_mtvscr(DisasContext *ctx)
785f451b 6853{
6e87b7c7 6854 TCGv_ptr p;
785f451b
AJ
6855 if (unlikely(!ctx->altivec_enabled)) {
6856 gen_exception(ctx, POWERPC_EXCP_VPU);
6857 return;
6858 }
6e87b7c7 6859 p = gen_avr_ptr(rD(ctx->opcode));
d15f74fb 6860 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6861 tcg_temp_free_ptr(p);
785f451b
AJ
6862}
6863
7a9b96cf
AJ
6864/* Logical operations */
6865#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6866static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6867{ \
6868 if (unlikely(!ctx->altivec_enabled)) { \
6869 gen_exception(ctx, POWERPC_EXCP_VPU); \
6870 return; \
6871 } \
6872 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6873 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6874}
6875
6876GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6877GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6878GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6879GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6880GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
111c5f54
TM
6881GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
6882GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
6883GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
7a9b96cf 6884
8e27dd6f 6885#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6886static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
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)); \
6896 gen_helper_##name (rd, ra, rb); \
6897 tcg_temp_free_ptr(ra); \
6898 tcg_temp_free_ptr(rb); \
6899 tcg_temp_free_ptr(rd); \
6900}
6901
d15f74fb
BS
6902#define GEN_VXFORM_ENV(name, opc2, opc3) \
6903static void glue(gen_, name)(DisasContext *ctx) \
6904{ \
6905 TCGv_ptr ra, rb, 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 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6913 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6914 tcg_temp_free_ptr(ra); \
6915 tcg_temp_free_ptr(rb); \
6916 tcg_temp_free_ptr(rd); \
9b47bb49
TM
6917}
6918
6919#define GEN_VXFORM3(name, opc2, opc3) \
6920static void glue(gen_, name)(DisasContext *ctx) \
6921{ \
6922 TCGv_ptr ra, rb, rc, rd; \
6923 if (unlikely(!ctx->altivec_enabled)) { \
6924 gen_exception(ctx, POWERPC_EXCP_VPU); \
6925 return; \
6926 } \
6927 ra = gen_avr_ptr(rA(ctx->opcode)); \
6928 rb = gen_avr_ptr(rB(ctx->opcode)); \
6929 rc = gen_avr_ptr(rC(ctx->opcode)); \
6930 rd = gen_avr_ptr(rD(ctx->opcode)); \
6931 gen_helper_##name(rd, ra, rb, rc); \
6932 tcg_temp_free_ptr(ra); \
6933 tcg_temp_free_ptr(rb); \
6934 tcg_temp_free_ptr(rc); \
6935 tcg_temp_free_ptr(rd); \
d15f74fb
BS
6936}
6937
5dffff5a
TM
6938/*
6939 * Support for Altivec instruction pairs that use bit 31 (Rc) as
6940 * an opcode bit. In general, these pairs come from different
6941 * versions of the ISA, so we must also support a pair of flags for
6942 * each instruction.
6943 */
6944#define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
6945static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6946{ \
6947 if ((Rc(ctx->opcode) == 0) && \
6948 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
6949 gen_##name0(ctx); \
6950 } else if ((Rc(ctx->opcode) == 1) && \
6951 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
6952 gen_##name1(ctx); \
6953 } else { \
6954 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
6955 } \
6956}
6957
7872c51c
AJ
6958GEN_VXFORM(vaddubm, 0, 0);
6959GEN_VXFORM(vadduhm, 0, 1);
6960GEN_VXFORM(vadduwm, 0, 2);
56eabc75 6961GEN_VXFORM(vaddudm, 0, 3);
7872c51c
AJ
6962GEN_VXFORM(vsububm, 0, 16);
6963GEN_VXFORM(vsubuhm, 0, 17);
6964GEN_VXFORM(vsubuwm, 0, 18);
56eabc75 6965GEN_VXFORM(vsubudm, 0, 19);
e4039339
AJ
6966GEN_VXFORM(vmaxub, 1, 0);
6967GEN_VXFORM(vmaxuh, 1, 1);
6968GEN_VXFORM(vmaxuw, 1, 2);
8203e31b 6969GEN_VXFORM(vmaxud, 1, 3);
e4039339
AJ
6970GEN_VXFORM(vmaxsb, 1, 4);
6971GEN_VXFORM(vmaxsh, 1, 5);
6972GEN_VXFORM(vmaxsw, 1, 6);
8203e31b 6973GEN_VXFORM(vmaxsd, 1, 7);
e4039339
AJ
6974GEN_VXFORM(vminub, 1, 8);
6975GEN_VXFORM(vminuh, 1, 9);
6976GEN_VXFORM(vminuw, 1, 10);
8203e31b 6977GEN_VXFORM(vminud, 1, 11);
e4039339
AJ
6978GEN_VXFORM(vminsb, 1, 12);
6979GEN_VXFORM(vminsh, 1, 13);
6980GEN_VXFORM(vminsw, 1, 14);
8203e31b 6981GEN_VXFORM(vminsd, 1, 15);
fab3cbe9
AJ
6982GEN_VXFORM(vavgub, 1, 16);
6983GEN_VXFORM(vavguh, 1, 17);
6984GEN_VXFORM(vavguw, 1, 18);
6985GEN_VXFORM(vavgsb, 1, 20);
6986GEN_VXFORM(vavgsh, 1, 21);
6987GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
6988GEN_VXFORM(vmrghb, 6, 0);
6989GEN_VXFORM(vmrghh, 6, 1);
6990GEN_VXFORM(vmrghw, 6, 2);
6991GEN_VXFORM(vmrglb, 6, 4);
6992GEN_VXFORM(vmrglh, 6, 5);
6993GEN_VXFORM(vmrglw, 6, 6);
e0ffe77f
TM
6994
6995static void gen_vmrgew(DisasContext *ctx)
6996{
6997 TCGv_i64 tmp;
6998 int VT, VA, VB;
6999 if (unlikely(!ctx->altivec_enabled)) {
7000 gen_exception(ctx, POWERPC_EXCP_VPU);
7001 return;
7002 }
7003 VT = rD(ctx->opcode);
7004 VA = rA(ctx->opcode);
7005 VB = rB(ctx->opcode);
7006 tmp = tcg_temp_new_i64();
7007 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
7008 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
7009 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
7010 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
7011 tcg_temp_free_i64(tmp);
7012}
7013
7014static void gen_vmrgow(DisasContext *ctx)
7015{
7016 int VT, VA, VB;
7017 if (unlikely(!ctx->altivec_enabled)) {
7018 gen_exception(ctx, POWERPC_EXCP_VPU);
7019 return;
7020 }
7021 VT = rD(ctx->opcode);
7022 VA = rA(ctx->opcode);
7023 VB = rB(ctx->opcode);
7024
7025 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7026 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7027}
7028
2c277908
AJ
7029GEN_VXFORM(vmuloub, 4, 0);
7030GEN_VXFORM(vmulouh, 4, 1);
63be0936 7031GEN_VXFORM(vmulouw, 4, 2);
953f0f58
TM
7032GEN_VXFORM(vmuluwm, 4, 2);
7033GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7034 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
2c277908
AJ
7035GEN_VXFORM(vmulosb, 4, 4);
7036GEN_VXFORM(vmulosh, 4, 5);
63be0936 7037GEN_VXFORM(vmulosw, 4, 6);
2c277908
AJ
7038GEN_VXFORM(vmuleub, 4, 8);
7039GEN_VXFORM(vmuleuh, 4, 9);
63be0936 7040GEN_VXFORM(vmuleuw, 4, 10);
2c277908
AJ
7041GEN_VXFORM(vmulesb, 4, 12);
7042GEN_VXFORM(vmulesh, 4, 13);
63be0936 7043GEN_VXFORM(vmulesw, 4, 14);
d79f0809
AJ
7044GEN_VXFORM(vslb, 2, 4);
7045GEN_VXFORM(vslh, 2, 5);
7046GEN_VXFORM(vslw, 2, 6);
2fdf78e6 7047GEN_VXFORM(vsld, 2, 23);
07ef34c3
AJ
7048GEN_VXFORM(vsrb, 2, 8);
7049GEN_VXFORM(vsrh, 2, 9);
7050GEN_VXFORM(vsrw, 2, 10);
2fdf78e6 7051GEN_VXFORM(vsrd, 2, 27);
07ef34c3
AJ
7052GEN_VXFORM(vsrab, 2, 12);
7053GEN_VXFORM(vsrah, 2, 13);
7054GEN_VXFORM(vsraw, 2, 14);
2fdf78e6 7055GEN_VXFORM(vsrad, 2, 15);
7b239bec
AJ
7056GEN_VXFORM(vslo, 6, 16);
7057GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
7058GEN_VXFORM(vaddcuw, 0, 6);
7059GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
7060GEN_VXFORM_ENV(vaddubs, 0, 8);
7061GEN_VXFORM_ENV(vadduhs, 0, 9);
7062GEN_VXFORM_ENV(vadduws, 0, 10);
7063GEN_VXFORM_ENV(vaddsbs, 0, 12);
7064GEN_VXFORM_ENV(vaddshs, 0, 13);
7065GEN_VXFORM_ENV(vaddsws, 0, 14);
7066GEN_VXFORM_ENV(vsububs, 0, 24);
7067GEN_VXFORM_ENV(vsubuhs, 0, 25);
7068GEN_VXFORM_ENV(vsubuws, 0, 26);
7069GEN_VXFORM_ENV(vsubsbs, 0, 28);
7070GEN_VXFORM_ENV(vsubshs, 0, 29);
7071GEN_VXFORM_ENV(vsubsws, 0, 30);
b41da4eb
TM
7072GEN_VXFORM(vadduqm, 0, 4);
7073GEN_VXFORM(vaddcuq, 0, 5);
7074GEN_VXFORM3(vaddeuqm, 30, 0);
7075GEN_VXFORM3(vaddecuq, 30, 0);
7076GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7077 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7078GEN_VXFORM(vsubuqm, 0, 20);
7079GEN_VXFORM(vsubcuq, 0, 21);
7080GEN_VXFORM3(vsubeuqm, 31, 0);
7081GEN_VXFORM3(vsubecuq, 31, 0);
7082GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7083 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
5e1d0985
AJ
7084GEN_VXFORM(vrlb, 2, 0);
7085GEN_VXFORM(vrlh, 2, 1);
7086GEN_VXFORM(vrlw, 2, 2);
2fdf78e6 7087GEN_VXFORM(vrld, 2, 3);
d9430add
AJ
7088GEN_VXFORM(vsl, 2, 7);
7089GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
7090GEN_VXFORM_ENV(vpkuhum, 7, 0);
7091GEN_VXFORM_ENV(vpkuwum, 7, 1);
024215b2 7092GEN_VXFORM_ENV(vpkudum, 7, 17);
d15f74fb
BS
7093GEN_VXFORM_ENV(vpkuhus, 7, 2);
7094GEN_VXFORM_ENV(vpkuwus, 7, 3);
024215b2 7095GEN_VXFORM_ENV(vpkudus, 7, 19);
d15f74fb
BS
7096GEN_VXFORM_ENV(vpkshus, 7, 4);
7097GEN_VXFORM_ENV(vpkswus, 7, 5);
024215b2 7098GEN_VXFORM_ENV(vpksdus, 7, 21);
d15f74fb
BS
7099GEN_VXFORM_ENV(vpkshss, 7, 6);
7100GEN_VXFORM_ENV(vpkswss, 7, 7);
024215b2 7101GEN_VXFORM_ENV(vpksdss, 7, 23);
1dd9ffb9 7102GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
7103GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7104GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7105GEN_VXFORM_ENV(vsum4shs, 4, 25);
7106GEN_VXFORM_ENV(vsum2sws, 4, 26);
7107GEN_VXFORM_ENV(vsumsws, 4, 30);
7108GEN_VXFORM_ENV(vaddfp, 5, 0);
7109GEN_VXFORM_ENV(vsubfp, 5, 1);
7110GEN_VXFORM_ENV(vmaxfp, 5, 16);
7111GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 7112
0cbcd906 7113#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 7114static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
7115 { \
7116 TCGv_ptr ra, rb, rd; \
7117 if (unlikely(!ctx->altivec_enabled)) { \
7118 gen_exception(ctx, POWERPC_EXCP_VPU); \
7119 return; \
7120 } \
7121 ra = gen_avr_ptr(rA(ctx->opcode)); \
7122 rb = gen_avr_ptr(rB(ctx->opcode)); \
7123 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 7124 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
7125 tcg_temp_free_ptr(ra); \
7126 tcg_temp_free_ptr(rb); \
7127 tcg_temp_free_ptr(rd); \
7128 }
7129
7130#define GEN_VXRFORM(name, opc2, opc3) \
7131 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7132 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7133
a737d3eb
TM
7134/*
7135 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7136 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7137 * come from different versions of the ISA, so we must also support a
7138 * pair of flags for each instruction.
7139 */
7140#define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7141static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7142{ \
7143 if ((Rc(ctx->opcode) == 0) && \
7144 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7145 if (Rc21(ctx->opcode) == 0) { \
7146 gen_##name0(ctx); \
7147 } else { \
7148 gen_##name0##_(ctx); \
7149 } \
7150 } else if ((Rc(ctx->opcode) == 1) && \
7151 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7152 if (Rc21(ctx->opcode) == 0) { \
7153 gen_##name1(ctx); \
7154 } else { \
7155 gen_##name1##_(ctx); \
7156 } \
7157 } else { \
7158 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7159 } \
7160}
7161
1add6e23
AJ
7162GEN_VXRFORM(vcmpequb, 3, 0)
7163GEN_VXRFORM(vcmpequh, 3, 1)
7164GEN_VXRFORM(vcmpequw, 3, 2)
6f3dab41 7165GEN_VXRFORM(vcmpequd, 3, 3)
1add6e23
AJ
7166GEN_VXRFORM(vcmpgtsb, 3, 12)
7167GEN_VXRFORM(vcmpgtsh, 3, 13)
7168GEN_VXRFORM(vcmpgtsw, 3, 14)
6f3dab41 7169GEN_VXRFORM(vcmpgtsd, 3, 15)
1add6e23
AJ
7170GEN_VXRFORM(vcmpgtub, 3, 8)
7171GEN_VXRFORM(vcmpgtuh, 3, 9)
7172GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 7173GEN_VXRFORM(vcmpgtud, 3, 11)
819ca121
AJ
7174GEN_VXRFORM(vcmpeqfp, 3, 3)
7175GEN_VXRFORM(vcmpgefp, 3, 7)
7176GEN_VXRFORM(vcmpgtfp, 3, 11)
7177GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 7178
6f3dab41
TM
7179GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7180 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7181GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7182 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7183GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7184 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7185
c026766b 7186#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7187static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
7188 { \
7189 TCGv_ptr rd; \
7190 TCGv_i32 simm; \
7191 if (unlikely(!ctx->altivec_enabled)) { \
7192 gen_exception(ctx, POWERPC_EXCP_VPU); \
7193 return; \
7194 } \
7195 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7196 rd = gen_avr_ptr(rD(ctx->opcode)); \
7197 gen_helper_##name (rd, simm); \
7198 tcg_temp_free_i32(simm); \
7199 tcg_temp_free_ptr(rd); \
7200 }
7201
7202GEN_VXFORM_SIMM(vspltisb, 6, 12);
7203GEN_VXFORM_SIMM(vspltish, 6, 13);
7204GEN_VXFORM_SIMM(vspltisw, 6, 14);
7205
de5f2484 7206#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 7207static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
7208 { \
7209 TCGv_ptr rb, rd; \
7210 if (unlikely(!ctx->altivec_enabled)) { \
7211 gen_exception(ctx, POWERPC_EXCP_VPU); \
7212 return; \
7213 } \
7214 rb = gen_avr_ptr(rB(ctx->opcode)); \
7215 rd = gen_avr_ptr(rD(ctx->opcode)); \
7216 gen_helper_##name (rd, rb); \
7217 tcg_temp_free_ptr(rb); \
7218 tcg_temp_free_ptr(rd); \
7219 }
7220
d15f74fb
BS
7221#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7222static void glue(gen_, name)(DisasContext *ctx) \
7223 { \
7224 TCGv_ptr rb, rd; \
7225 \
7226 if (unlikely(!ctx->altivec_enabled)) { \
7227 gen_exception(ctx, POWERPC_EXCP_VPU); \
7228 return; \
7229 } \
7230 rb = gen_avr_ptr(rB(ctx->opcode)); \
7231 rd = gen_avr_ptr(rD(ctx->opcode)); \
7232 gen_helper_##name(cpu_env, rd, rb); \
7233 tcg_temp_free_ptr(rb); \
7234 tcg_temp_free_ptr(rd); \
7235 }
7236
6cf1c6e5
AJ
7237GEN_VXFORM_NOA(vupkhsb, 7, 8);
7238GEN_VXFORM_NOA(vupkhsh, 7, 9);
4430e076 7239GEN_VXFORM_NOA(vupkhsw, 7, 25);
6cf1c6e5
AJ
7240GEN_VXFORM_NOA(vupklsb, 7, 10);
7241GEN_VXFORM_NOA(vupklsh, 7, 11);
4430e076 7242GEN_VXFORM_NOA(vupklsw, 7, 27);
79f85c3a
AJ
7243GEN_VXFORM_NOA(vupkhpx, 7, 13);
7244GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
7245GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7246GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7247GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7248GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
7249GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
7250GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
7251GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
7252GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
79f85c3a 7253
21d21583 7254#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7255static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
7256 { \
7257 TCGv_ptr rd; \
7258 TCGv_i32 simm; \
7259 if (unlikely(!ctx->altivec_enabled)) { \
7260 gen_exception(ctx, POWERPC_EXCP_VPU); \
7261 return; \
7262 } \
7263 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7264 rd = gen_avr_ptr(rD(ctx->opcode)); \
7265 gen_helper_##name (rd, simm); \
7266 tcg_temp_free_i32(simm); \
7267 tcg_temp_free_ptr(rd); \
7268 }
7269
27a4edb3 7270#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 7271static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
7272 { \
7273 TCGv_ptr rb, rd; \
7274 TCGv_i32 uimm; \
7275 if (unlikely(!ctx->altivec_enabled)) { \
7276 gen_exception(ctx, POWERPC_EXCP_VPU); \
7277 return; \
7278 } \
7279 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7280 rb = gen_avr_ptr(rB(ctx->opcode)); \
7281 rd = gen_avr_ptr(rD(ctx->opcode)); \
7282 gen_helper_##name (rd, rb, uimm); \
7283 tcg_temp_free_i32(uimm); \
7284 tcg_temp_free_ptr(rb); \
7285 tcg_temp_free_ptr(rd); \
7286 }
7287
d15f74fb
BS
7288#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7289static void glue(gen_, name)(DisasContext *ctx) \
7290 { \
7291 TCGv_ptr rb, rd; \
7292 TCGv_i32 uimm; \
7293 \
7294 if (unlikely(!ctx->altivec_enabled)) { \
7295 gen_exception(ctx, POWERPC_EXCP_VPU); \
7296 return; \
7297 } \
7298 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7299 rb = gen_avr_ptr(rB(ctx->opcode)); \
7300 rd = gen_avr_ptr(rD(ctx->opcode)); \
7301 gen_helper_##name(cpu_env, rd, rb, uimm); \
7302 tcg_temp_free_i32(uimm); \
7303 tcg_temp_free_ptr(rb); \
7304 tcg_temp_free_ptr(rd); \
7305 }
7306
e4e6bee7
AJ
7307GEN_VXFORM_UIMM(vspltb, 6, 8);
7308GEN_VXFORM_UIMM(vsplth, 6, 9);
7309GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
7310GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7311GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7312GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7313GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 7314
99e300ef 7315static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
7316{
7317 TCGv_ptr ra, rb, rd;
fce5ecb7 7318 TCGv_i32 sh;
cd633b10
AJ
7319 if (unlikely(!ctx->altivec_enabled)) {
7320 gen_exception(ctx, POWERPC_EXCP_VPU);
7321 return;
7322 }
7323 ra = gen_avr_ptr(rA(ctx->opcode));
7324 rb = gen_avr_ptr(rB(ctx->opcode));
7325 rd = gen_avr_ptr(rD(ctx->opcode));
7326 sh = tcg_const_i32(VSH(ctx->opcode));
7327 gen_helper_vsldoi (rd, ra, rb, sh);
7328 tcg_temp_free_ptr(ra);
7329 tcg_temp_free_ptr(rb);
7330 tcg_temp_free_ptr(rd);
fce5ecb7 7331 tcg_temp_free_i32(sh);
cd633b10
AJ
7332}
7333
707cec33 7334#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 7335static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
7336 { \
7337 TCGv_ptr ra, rb, rc, rd; \
7338 if (unlikely(!ctx->altivec_enabled)) { \
7339 gen_exception(ctx, POWERPC_EXCP_VPU); \
7340 return; \
7341 } \
7342 ra = gen_avr_ptr(rA(ctx->opcode)); \
7343 rb = gen_avr_ptr(rB(ctx->opcode)); \
7344 rc = gen_avr_ptr(rC(ctx->opcode)); \
7345 rd = gen_avr_ptr(rD(ctx->opcode)); \
7346 if (Rc(ctx->opcode)) { \
d15f74fb 7347 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 7348 } else { \
d15f74fb 7349 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
7350 } \
7351 tcg_temp_free_ptr(ra); \
7352 tcg_temp_free_ptr(rb); \
7353 tcg_temp_free_ptr(rc); \
7354 tcg_temp_free_ptr(rd); \
7355 }
7356
b161ae27
AJ
7357GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7358
99e300ef 7359static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
7360{
7361 TCGv_ptr ra, rb, rc, rd;
7362 if (unlikely(!ctx->altivec_enabled)) {
7363 gen_exception(ctx, POWERPC_EXCP_VPU);
7364 return;
7365 }
7366 ra = gen_avr_ptr(rA(ctx->opcode));
7367 rb = gen_avr_ptr(rB(ctx->opcode));
7368 rc = gen_avr_ptr(rC(ctx->opcode));
7369 rd = gen_avr_ptr(rD(ctx->opcode));
7370 gen_helper_vmladduhm(rd, ra, rb, rc);
7371 tcg_temp_free_ptr(ra);
7372 tcg_temp_free_ptr(rb);
7373 tcg_temp_free_ptr(rc);
7374 tcg_temp_free_ptr(rd);
7375}
7376
b04ae981 7377GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7378GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7379GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7380GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7381GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7382
f293f04a
TM
7383GEN_VXFORM_NOA(vclzb, 1, 28)
7384GEN_VXFORM_NOA(vclzh, 1, 29)
7385GEN_VXFORM_NOA(vclzw, 1, 30)
7386GEN_VXFORM_NOA(vclzd, 1, 31)
e13500b3
TM
7387GEN_VXFORM_NOA(vpopcntb, 1, 28)
7388GEN_VXFORM_NOA(vpopcnth, 1, 29)
7389GEN_VXFORM_NOA(vpopcntw, 1, 30)
7390GEN_VXFORM_NOA(vpopcntd, 1, 31)
7391GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7392 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7393GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7394 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7395GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7396 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7397GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7398 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
4d82038e 7399GEN_VXFORM(vbpermq, 6, 21);
f1064f61 7400GEN_VXFORM_NOA(vgbbd, 6, 20);
b8476fc7
TM
7401GEN_VXFORM(vpmsumb, 4, 16)
7402GEN_VXFORM(vpmsumh, 4, 17)
7403GEN_VXFORM(vpmsumw, 4, 18)
7404GEN_VXFORM(vpmsumd, 4, 19)
e13500b3 7405
e8f7b27b
TM
7406#define GEN_BCD(op) \
7407static void gen_##op(DisasContext *ctx) \
7408{ \
7409 TCGv_ptr ra, rb, rd; \
7410 TCGv_i32 ps; \
7411 \
7412 if (unlikely(!ctx->altivec_enabled)) { \
7413 gen_exception(ctx, POWERPC_EXCP_VPU); \
7414 return; \
7415 } \
7416 \
7417 ra = gen_avr_ptr(rA(ctx->opcode)); \
7418 rb = gen_avr_ptr(rB(ctx->opcode)); \
7419 rd = gen_avr_ptr(rD(ctx->opcode)); \
7420 \
7421 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7422 \
7423 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7424 \
7425 tcg_temp_free_ptr(ra); \
7426 tcg_temp_free_ptr(rb); \
7427 tcg_temp_free_ptr(rd); \
7428 tcg_temp_free_i32(ps); \
7429}
7430
7431GEN_BCD(bcdadd)
7432GEN_BCD(bcdsub)
7433
7434GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7435 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7436GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7437 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7438GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7439 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7440GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7441 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7442
557d52fa
TM
7443static void gen_vsbox(DisasContext *ctx)
7444{
7445 TCGv_ptr ra, rd;
7446 if (unlikely(!ctx->altivec_enabled)) {
7447 gen_exception(ctx, POWERPC_EXCP_VPU);
7448 return;
7449 }
7450 ra = gen_avr_ptr(rA(ctx->opcode));
7451 rd = gen_avr_ptr(rD(ctx->opcode));
7452 gen_helper_vsbox(rd, ra);
7453 tcg_temp_free_ptr(ra);
7454 tcg_temp_free_ptr(rd);
7455}
7456
7457GEN_VXFORM(vcipher, 4, 20)
7458GEN_VXFORM(vcipherlast, 4, 20)
7459GEN_VXFORM(vncipher, 4, 21)
7460GEN_VXFORM(vncipherlast, 4, 21)
7461
7462GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7463 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7464GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7465 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7466
57354f8f
TM
7467#define VSHASIGMA(op) \
7468static void gen_##op(DisasContext *ctx) \
7469{ \
7470 TCGv_ptr ra, rd; \
7471 TCGv_i32 st_six; \
7472 if (unlikely(!ctx->altivec_enabled)) { \
7473 gen_exception(ctx, POWERPC_EXCP_VPU); \
7474 return; \
7475 } \
7476 ra = gen_avr_ptr(rA(ctx->opcode)); \
7477 rd = gen_avr_ptr(rD(ctx->opcode)); \
7478 st_six = tcg_const_i32(rB(ctx->opcode)); \
7479 gen_helper_##op(rd, ra, st_six); \
7480 tcg_temp_free_ptr(ra); \
7481 tcg_temp_free_ptr(rd); \
7482 tcg_temp_free_i32(st_six); \
7483}
7484
7485VSHASIGMA(vshasigmaw)
7486VSHASIGMA(vshasigmad)
7487
ac174549
TM
7488GEN_VXFORM3(vpermxor, 22, 0xFF)
7489GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7490 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7491
472b24ce
TM
7492/*** VSX extension ***/
7493
7494static inline TCGv_i64 cpu_vsrh(int n)
7495{
7496 if (n < 32) {
7497 return cpu_fpr[n];
7498 } else {
7499 return cpu_avrh[n-32];
7500 }
7501}
7502
7503static inline TCGv_i64 cpu_vsrl(int n)
7504{
7505 if (n < 32) {
7506 return cpu_vsr[n];
7507 } else {
7508 return cpu_avrl[n-32];
7509 }
7510}
7511
e072fe79
TM
7512#define VSX_LOAD_SCALAR(name, operation) \
7513static void gen_##name(DisasContext *ctx) \
7514{ \
7515 TCGv EA; \
7516 if (unlikely(!ctx->vsx_enabled)) { \
7517 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7518 return; \
7519 } \
7520 gen_set_access_type(ctx, ACCESS_INT); \
7521 EA = tcg_temp_new(); \
7522 gen_addr_reg_index(ctx, EA); \
7523 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7524 /* NOTE: cpu_vsrl is undefined */ \
7525 tcg_temp_free(EA); \
7526}
7527
7528VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7529VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7530VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7531VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7532
304af367
TM
7533static void gen_lxvd2x(DisasContext *ctx)
7534{
7535 TCGv EA;
7536 if (unlikely(!ctx->vsx_enabled)) {
7537 gen_exception(ctx, POWERPC_EXCP_VSXU);
7538 return;
7539 }
7540 gen_set_access_type(ctx, ACCESS_INT);
7541 EA = tcg_temp_new();
7542 gen_addr_reg_index(ctx, EA);
7543 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7544 tcg_gen_addi_tl(EA, EA, 8);
7545 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7546 tcg_temp_free(EA);
7547}
7548
ca03b467
TM
7549static void gen_lxvdsx(DisasContext *ctx)
7550{
7551 TCGv EA;
7552 if (unlikely(!ctx->vsx_enabled)) {
7553 gen_exception(ctx, POWERPC_EXCP_VSXU);
7554 return;
7555 }
7556 gen_set_access_type(ctx, ACCESS_INT);
7557 EA = tcg_temp_new();
7558 gen_addr_reg_index(ctx, EA);
7559 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7560 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7561 tcg_temp_free(EA);
7562}
7563
897e61d1
TM
7564static void gen_lxvw4x(DisasContext *ctx)
7565{
f976b09e
AG
7566 TCGv EA;
7567 TCGv_i64 tmp;
897e61d1
TM
7568 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7569 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7570 if (unlikely(!ctx->vsx_enabled)) {
7571 gen_exception(ctx, POWERPC_EXCP_VSXU);
7572 return;
7573 }
7574 gen_set_access_type(ctx, ACCESS_INT);
7575 EA = tcg_temp_new();
f976b09e
AG
7576 tmp = tcg_temp_new_i64();
7577
897e61d1 7578 gen_addr_reg_index(ctx, EA);
f976b09e 7579 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7580 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7581 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7582 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7583
7584 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7585 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7586 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7587 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7588 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7589
7590 tcg_temp_free(EA);
f976b09e 7591 tcg_temp_free_i64(tmp);
897e61d1
TM
7592}
7593
f026da78
TM
7594#define VSX_STORE_SCALAR(name, operation) \
7595static void gen_##name(DisasContext *ctx) \
7596{ \
7597 TCGv EA; \
7598 if (unlikely(!ctx->vsx_enabled)) { \
7599 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7600 return; \
7601 } \
7602 gen_set_access_type(ctx, ACCESS_INT); \
7603 EA = tcg_temp_new(); \
7604 gen_addr_reg_index(ctx, EA); \
7605 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7606 tcg_temp_free(EA); \
9231ba9e
TM
7607}
7608
f026da78 7609VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7610VSX_STORE_SCALAR(stxsiwx, st32_i64)
7611VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7612
fbed2478
TM
7613static void gen_stxvd2x(DisasContext *ctx)
7614{
7615 TCGv EA;
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);
7623 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7624 tcg_gen_addi_tl(EA, EA, 8);
7625 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7626 tcg_temp_free(EA);
7627}
7628
86e61ce3
TM
7629static void gen_stxvw4x(DisasContext *ctx)
7630{
f976b09e
AG
7631 TCGv_i64 tmp;
7632 TCGv EA;
86e61ce3
TM
7633 if (unlikely(!ctx->vsx_enabled)) {
7634 gen_exception(ctx, POWERPC_EXCP_VSXU);
7635 return;
7636 }
7637 gen_set_access_type(ctx, ACCESS_INT);
7638 EA = tcg_temp_new();
7639 gen_addr_reg_index(ctx, EA);
f976b09e 7640 tmp = tcg_temp_new_i64();
86e61ce3
TM
7641
7642 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7643 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7644 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7645 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7646
7647 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7648 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7649 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7650 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7651 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7652
7653 tcg_temp_free(EA);
f976b09e 7654 tcg_temp_free_i64(tmp);
86e61ce3
TM
7655}
7656
f5c0f7f9
TM
7657#define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7658static void gen_##name(DisasContext *ctx) \
7659{ \
7660 if (xS(ctx->opcode) < 32) { \
7661 if (unlikely(!ctx->fpu_enabled)) { \
7662 gen_exception(ctx, POWERPC_EXCP_FPU); \
7663 return; \
7664 } \
7665 } else { \
7666 if (unlikely(!ctx->altivec_enabled)) { \
7667 gen_exception(ctx, POWERPC_EXCP_VPU); \
7668 return; \
7669 } \
7670 } \
7671 TCGv_i64 tmp = tcg_temp_new_i64(); \
7672 tcg_gen_##tcgop1(tmp, source); \
7673 tcg_gen_##tcgop2(target, tmp); \
7674 tcg_temp_free_i64(tmp); \
7675}
7676
7677
7678MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7679 cpu_vsrh(xS(ctx->opcode)))
7680MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7681 cpu_gpr[rA(ctx->opcode)])
7682MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7683 cpu_gpr[rA(ctx->opcode)])
7684
7685#if defined(TARGET_PPC64)
7686#define MV_VSRD(name, target, source) \
7687static void gen_##name(DisasContext *ctx) \
7688{ \
7689 if (xS(ctx->opcode) < 32) { \
7690 if (unlikely(!ctx->fpu_enabled)) { \
7691 gen_exception(ctx, POWERPC_EXCP_FPU); \
7692 return; \
7693 } \
7694 } else { \
7695 if (unlikely(!ctx->altivec_enabled)) { \
7696 gen_exception(ctx, POWERPC_EXCP_VPU); \
7697 return; \
7698 } \
7699 } \
7700 tcg_gen_mov_i64(target, source); \
7701}
7702
7703MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7704MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7705
7706#endif
7707
cd73f2c9
TM
7708static void gen_xxpermdi(DisasContext *ctx)
7709{
7710 if (unlikely(!ctx->vsx_enabled)) {
7711 gen_exception(ctx, POWERPC_EXCP_VSXU);
7712 return;
7713 }
7714
f5bc1bfa
TM
7715 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7716 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7717 TCGv_i64 xh, xl;
7718
7719 xh = tcg_temp_new_i64();
7720 xl = tcg_temp_new_i64();
7721
7722 if ((DM(ctx->opcode) & 2) == 0) {
7723 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7724 } else {
7725 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7726 }
7727 if ((DM(ctx->opcode) & 1) == 0) {
7728 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7729 } else {
7730 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7731 }
7732
7733 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7734 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7735
7736 tcg_temp_free_i64(xh);
7737 tcg_temp_free_i64(xl);
cd73f2c9 7738 } else {
f5bc1bfa
TM
7739 if ((DM(ctx->opcode) & 2) == 0) {
7740 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7741 } else {
7742 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7743 }
7744 if ((DM(ctx->opcode) & 1) == 0) {
7745 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7746 } else {
7747 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7748 }
cd73f2c9
TM
7749 }
7750}
7751
df020ce0
TM
7752#define OP_ABS 1
7753#define OP_NABS 2
7754#define OP_NEG 3
7755#define OP_CPSGN 4
e5d7d2b0
PM
7756#define SGN_MASK_DP 0x8000000000000000ull
7757#define SGN_MASK_SP 0x8000000080000000ull
df020ce0
TM
7758
7759#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7760static void glue(gen_, name)(DisasContext * ctx) \
7761 { \
7762 TCGv_i64 xb, sgm; \
7763 if (unlikely(!ctx->vsx_enabled)) { \
7764 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7765 return; \
7766 } \
f976b09e
AG
7767 xb = tcg_temp_new_i64(); \
7768 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7769 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7770 tcg_gen_movi_i64(sgm, sgn_mask); \
7771 switch (op) { \
7772 case OP_ABS: { \
7773 tcg_gen_andc_i64(xb, xb, sgm); \
7774 break; \
7775 } \
7776 case OP_NABS: { \
7777 tcg_gen_or_i64(xb, xb, sgm); \
7778 break; \
7779 } \
7780 case OP_NEG: { \
7781 tcg_gen_xor_i64(xb, xb, sgm); \
7782 break; \
7783 } \
7784 case OP_CPSGN: { \
f976b09e 7785 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7786 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7787 tcg_gen_and_i64(xa, xa, sgm); \
7788 tcg_gen_andc_i64(xb, xb, sgm); \
7789 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7790 tcg_temp_free_i64(xa); \
df020ce0
TM
7791 break; \
7792 } \
7793 } \
7794 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7795 tcg_temp_free_i64(xb); \
7796 tcg_temp_free_i64(sgm); \
df020ce0
TM
7797 }
7798
7799VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7800VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7801VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7802VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7803
be574920
TM
7804#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7805static void glue(gen_, name)(DisasContext * ctx) \
7806 { \
7807 TCGv_i64 xbh, xbl, sgm; \
7808 if (unlikely(!ctx->vsx_enabled)) { \
7809 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7810 return; \
7811 } \
f976b09e
AG
7812 xbh = tcg_temp_new_i64(); \
7813 xbl = tcg_temp_new_i64(); \
7814 sgm = tcg_temp_new_i64(); \
be574920
TM
7815 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7816 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7817 tcg_gen_movi_i64(sgm, sgn_mask); \
7818 switch (op) { \
7819 case OP_ABS: { \
7820 tcg_gen_andc_i64(xbh, xbh, sgm); \
7821 tcg_gen_andc_i64(xbl, xbl, sgm); \
7822 break; \
7823 } \
7824 case OP_NABS: { \
7825 tcg_gen_or_i64(xbh, xbh, sgm); \
7826 tcg_gen_or_i64(xbl, xbl, sgm); \
7827 break; \
7828 } \
7829 case OP_NEG: { \
7830 tcg_gen_xor_i64(xbh, xbh, sgm); \
7831 tcg_gen_xor_i64(xbl, xbl, sgm); \
7832 break; \
7833 } \
7834 case OP_CPSGN: { \
f976b09e
AG
7835 TCGv_i64 xah = tcg_temp_new_i64(); \
7836 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7837 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7838 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7839 tcg_gen_and_i64(xah, xah, sgm); \
7840 tcg_gen_and_i64(xal, xal, sgm); \
7841 tcg_gen_andc_i64(xbh, xbh, sgm); \
7842 tcg_gen_andc_i64(xbl, xbl, sgm); \
7843 tcg_gen_or_i64(xbh, xbh, xah); \
7844 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7845 tcg_temp_free_i64(xah); \
7846 tcg_temp_free_i64(xal); \
be574920
TM
7847 break; \
7848 } \
7849 } \
7850 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7851 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7852 tcg_temp_free_i64(xbh); \
7853 tcg_temp_free_i64(xbl); \
7854 tcg_temp_free_i64(sgm); \
be574920
TM
7855 }
7856
7857VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7858VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7859VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7860VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7861VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7862VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7863VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7864VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7865
3c3cbbdc
TM
7866#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7867static void gen_##name(DisasContext * ctx) \
7868{ \
7869 TCGv_i32 opc; \
7870 if (unlikely(!ctx->vsx_enabled)) { \
7871 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7872 return; \
7873 } \
7874 /* NIP cannot be restored if the memory exception comes from an helper */ \
7875 gen_update_nip(ctx, ctx->nip - 4); \
7876 opc = tcg_const_i32(ctx->opcode); \
7877 gen_helper_##name(cpu_env, opc); \
7878 tcg_temp_free_i32(opc); \
7879}
be574920 7880
3d1140bf
TM
7881#define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7882static void gen_##name(DisasContext * ctx) \
7883{ \
7884 if (unlikely(!ctx->vsx_enabled)) { \
7885 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7886 return; \
7887 } \
7888 /* NIP cannot be restored if the exception comes */ \
7889 /* from a helper. */ \
7890 gen_update_nip(ctx, ctx->nip - 4); \
7891 \
7892 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7893 cpu_vsrh(xB(ctx->opcode))); \
7894}
7895
ee6e02c0
TM
7896GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7897GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7898GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7899GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7900GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7901GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7902GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7903GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7904GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7905GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7906GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7907GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7908GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7909GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7910GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7911GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7912GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
7913GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7914GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
7915GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7916GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568 7917GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7ee19fb9 7918GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
ed8ac568 7919GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7ee19fb9 7920GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
5177d2ca
TM
7921GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7922GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
7923GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
7924GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
7925GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
7926GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
7927GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
7928GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
7929GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
7930GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
7931GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
3d1140bf 7932GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
ee6e02c0 7933
3fd0aadf
TM
7934GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
7935GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 7936GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 7937GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 7938GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 7939GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
968e76bc 7940GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
f53f81e0
TM
7941GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
7942GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
7943GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
7944GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
7945GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
7946GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
7947GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
7948GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
74698350
TM
7949GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
7950GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
3fd0aadf 7951
ee6e02c0
TM
7952GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
7953GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 7954GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 7955GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 7956GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 7957GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 7958GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 7959GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 7960GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
7961GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
7962GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
7963GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
7964GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
7965GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
7966GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
7967GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
7968GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
7969GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
7970GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
7971GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
7972GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
7973GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 7974GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
7975GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
7976GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
7977GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
7978GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
7979GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
7980GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
7981GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
7982GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
7983GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
7984GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
7985GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
7986GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
7987GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
7988
7989GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
7990GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 7991GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 7992GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 7993GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 7994GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 7995GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 7996GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 7997GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
7998GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
7999GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
8000GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
8001GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
8002GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
8003GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
8004GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
8005GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
8006GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
8007GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
8008GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
8009GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
8010GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 8011GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
8012GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
8013GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
8014GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
8015GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
8016GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
8017GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
8018GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
8019GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
8020GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
8021GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
8022GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
8023GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
8024GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 8025
79ca8a6a
TM
8026#define VSX_LOGICAL(name, tcg_op) \
8027static void glue(gen_, name)(DisasContext * ctx) \
8028 { \
8029 if (unlikely(!ctx->vsx_enabled)) { \
8030 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8031 return; \
8032 } \
8033 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8034 cpu_vsrh(xB(ctx->opcode))); \
8035 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8036 cpu_vsrl(xB(ctx->opcode))); \
8037 }
8038
f976b09e
AG
8039VSX_LOGICAL(xxland, tcg_gen_and_i64)
8040VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8041VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8042VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8043VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
67a33f37
TM
8044VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8045VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8046VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
df020ce0 8047
ce577d2e
TM
8048#define VSX_XXMRG(name, high) \
8049static void glue(gen_, name)(DisasContext * ctx) \
8050 { \
8051 TCGv_i64 a0, a1, b0, b1; \
8052 if (unlikely(!ctx->vsx_enabled)) { \
8053 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8054 return; \
8055 } \
f976b09e
AG
8056 a0 = tcg_temp_new_i64(); \
8057 a1 = tcg_temp_new_i64(); \
8058 b0 = tcg_temp_new_i64(); \
8059 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
8060 if (high) { \
8061 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8062 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8063 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8064 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8065 } else { \
8066 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8067 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8068 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8069 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8070 } \
8071 tcg_gen_shri_i64(a0, a0, 32); \
8072 tcg_gen_shri_i64(b0, b0, 32); \
8073 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8074 b0, a0, 32, 32); \
8075 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8076 b1, a1, 32, 32); \
f976b09e
AG
8077 tcg_temp_free_i64(a0); \
8078 tcg_temp_free_i64(a1); \
8079 tcg_temp_free_i64(b0); \
8080 tcg_temp_free_i64(b1); \
ce577d2e
TM
8081 }
8082
8083VSX_XXMRG(xxmrghw, 1)
8084VSX_XXMRG(xxmrglw, 0)
8085
551e3ef7
TM
8086static void gen_xxsel(DisasContext * ctx)
8087{
8088 TCGv_i64 a, b, c;
8089 if (unlikely(!ctx->vsx_enabled)) {
8090 gen_exception(ctx, POWERPC_EXCP_VSXU);
8091 return;
8092 }
f976b09e
AG
8093 a = tcg_temp_new_i64();
8094 b = tcg_temp_new_i64();
8095 c = tcg_temp_new_i64();
551e3ef7
TM
8096
8097 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8098 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8099 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8100
8101 tcg_gen_and_i64(b, b, c);
8102 tcg_gen_andc_i64(a, a, c);
8103 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8104
8105 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8106 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8107 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8108
8109 tcg_gen_and_i64(b, b, c);
8110 tcg_gen_andc_i64(a, a, c);
8111 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8112
f976b09e
AG
8113 tcg_temp_free_i64(a);
8114 tcg_temp_free_i64(b);
8115 tcg_temp_free_i64(c);
551e3ef7
TM
8116}
8117
76c15fe0
TM
8118static void gen_xxspltw(DisasContext *ctx)
8119{
8120 TCGv_i64 b, b2;
8121 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8122 cpu_vsrl(xB(ctx->opcode)) :
8123 cpu_vsrh(xB(ctx->opcode));
8124
8125 if (unlikely(!ctx->vsx_enabled)) {
8126 gen_exception(ctx, POWERPC_EXCP_VSXU);
8127 return;
8128 }
8129
f976b09e
AG
8130 b = tcg_temp_new_i64();
8131 b2 = tcg_temp_new_i64();
76c15fe0
TM
8132
8133 if (UIM(ctx->opcode) & 1) {
8134 tcg_gen_ext32u_i64(b, vsr);
8135 } else {
8136 tcg_gen_shri_i64(b, vsr, 32);
8137 }
8138
8139 tcg_gen_shli_i64(b2, b, 32);
8140 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8141 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8142
f976b09e
AG
8143 tcg_temp_free_i64(b);
8144 tcg_temp_free_i64(b2);
76c15fe0
TM
8145}
8146
acc42968
TM
8147static void gen_xxsldwi(DisasContext *ctx)
8148{
8149 TCGv_i64 xth, xtl;
8150 if (unlikely(!ctx->vsx_enabled)) {
8151 gen_exception(ctx, POWERPC_EXCP_VSXU);
8152 return;
8153 }
f976b09e
AG
8154 xth = tcg_temp_new_i64();
8155 xtl = tcg_temp_new_i64();
acc42968
TM
8156
8157 switch (SHW(ctx->opcode)) {
8158 case 0: {
8159 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8160 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8161 break;
8162 }
8163 case 1: {
f976b09e 8164 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8165 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8166 tcg_gen_shli_i64(xth, xth, 32);
8167 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8168 tcg_gen_shri_i64(t0, t0, 32);
8169 tcg_gen_or_i64(xth, xth, t0);
8170 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8171 tcg_gen_shli_i64(xtl, xtl, 32);
8172 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8173 tcg_gen_shri_i64(t0, t0, 32);
8174 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8175 tcg_temp_free_i64(t0);
acc42968
TM
8176 break;
8177 }
8178 case 2: {
8179 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8180 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8181 break;
8182 }
8183 case 3: {
f976b09e 8184 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8185 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8186 tcg_gen_shli_i64(xth, xth, 32);
8187 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8188 tcg_gen_shri_i64(t0, t0, 32);
8189 tcg_gen_or_i64(xth, xth, t0);
8190 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8191 tcg_gen_shli_i64(xtl, xtl, 32);
8192 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8193 tcg_gen_shri_i64(t0, t0, 32);
8194 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8195 tcg_temp_free_i64(t0);
acc42968
TM
8196 break;
8197 }
8198 }
8199
8200 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8201 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8202
f976b09e
AG
8203 tcg_temp_free_i64(xth);
8204 tcg_temp_free_i64(xtl);
acc42968
TM
8205}
8206
f0b01f02
TM
8207/*** Decimal Floating Point ***/
8208
8209static inline TCGv_ptr gen_fprp_ptr(int reg)
8210{
8211 TCGv_ptr r = tcg_temp_new_ptr();
8212 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, fpr[reg]));
8213 return r;
8214}
8215
8216#if defined(TARGET_PPC64)
f0b01f02
TM
8217static void gen_set_cr6_from_fpscr(DisasContext *ctx)
8218{
8219 TCGv_i32 tmp = tcg_temp_new_i32();
8220 tcg_gen_trunc_tl_i32(tmp, cpu_fpscr);
8221 tcg_gen_shri_i32(cpu_crf[1], tmp, 28);
8222 tcg_temp_free_i32(tmp);
8223}
8224#else
f0b01f02
TM
8225static void gen_set_cr6_from_fpscr(DisasContext *ctx)
8226{
8227 tcg_gen_shri_tl(cpu_crf[1], cpu_fpscr, 28);
8228}
8229#endif
8230
8231#define GEN_DFP_T_A_B_Rc(name) \
8232static void gen_##name(DisasContext *ctx) \
8233{ \
8234 TCGv_ptr rd, ra, rb; \
8235 if (unlikely(!ctx->fpu_enabled)) { \
8236 gen_exception(ctx, POWERPC_EXCP_FPU); \
8237 return; \
8238 } \
8239 gen_update_nip(ctx, ctx->nip - 4); \
8240 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8241 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8242 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8243 gen_helper_##name(cpu_env, rd, ra, rb); \
8244 if (unlikely(Rc(ctx->opcode) != 0)) { \
8245 gen_set_cr6_from_fpscr(ctx); \
8246 } \
8247 tcg_temp_free_ptr(rd); \
8248 tcg_temp_free_ptr(ra); \
8249 tcg_temp_free_ptr(rb); \
8250}
8251
8252#define GEN_DFP_BF_A_B(name) \
8253static void gen_##name(DisasContext *ctx) \
8254{ \
8255 TCGv_ptr ra, rb; \
8256 if (unlikely(!ctx->fpu_enabled)) { \
8257 gen_exception(ctx, POWERPC_EXCP_FPU); \
8258 return; \
8259 } \
8260 gen_update_nip(ctx, ctx->nip - 4); \
8261 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8262 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8263 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8264 cpu_env, ra, rb); \
8265 tcg_temp_free_ptr(ra); \
8266 tcg_temp_free_ptr(rb); \
8267}
8268
8269#define GEN_DFP_BF_A_DCM(name) \
8270static void gen_##name(DisasContext *ctx) \
8271{ \
8272 TCGv_ptr ra; \
8273 TCGv_i32 dcm; \
8274 if (unlikely(!ctx->fpu_enabled)) { \
8275 gen_exception(ctx, POWERPC_EXCP_FPU); \
8276 return; \
8277 } \
8278 gen_update_nip(ctx, ctx->nip - 4); \
8279 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8280 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8281 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8282 cpu_env, ra, dcm); \
8283 tcg_temp_free_ptr(ra); \
8284 tcg_temp_free_i32(dcm); \
8285}
8286
8287#define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8288static void gen_##name(DisasContext *ctx) \
8289{ \
8290 TCGv_ptr rt, rb; \
8291 TCGv_i32 u32_1, u32_2; \
8292 if (unlikely(!ctx->fpu_enabled)) { \
8293 gen_exception(ctx, POWERPC_EXCP_FPU); \
8294 return; \
8295 } \
8296 gen_update_nip(ctx, ctx->nip - 4); \
8297 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8298 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8299 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8300 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8301 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8302 if (unlikely(Rc(ctx->opcode) != 0)) { \
8303 gen_set_cr6_from_fpscr(ctx); \
8304 } \
8305 tcg_temp_free_ptr(rt); \
8306 tcg_temp_free_ptr(rb); \
8307 tcg_temp_free_i32(u32_1); \
8308 tcg_temp_free_i32(u32_2); \
8309}
8310
8311#define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8312static void gen_##name(DisasContext *ctx) \
8313{ \
8314 TCGv_ptr rt, ra, rb; \
8315 TCGv_i32 i32; \
8316 if (unlikely(!ctx->fpu_enabled)) { \
8317 gen_exception(ctx, POWERPC_EXCP_FPU); \
8318 return; \
8319 } \
8320 gen_update_nip(ctx, ctx->nip - 4); \
8321 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8322 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8323 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8324 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8325 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8326 if (unlikely(Rc(ctx->opcode) != 0)) { \
8327 gen_set_cr6_from_fpscr(ctx); \
8328 } \
8329 tcg_temp_free_ptr(rt); \
8330 tcg_temp_free_ptr(rb); \
8331 tcg_temp_free_ptr(ra); \
8332 tcg_temp_free_i32(i32); \
8333 }
8334
8335#define GEN_DFP_T_B_Rc(name) \
8336static void gen_##name(DisasContext *ctx) \
8337{ \
8338 TCGv_ptr rt, rb; \
8339 if (unlikely(!ctx->fpu_enabled)) { \
8340 gen_exception(ctx, POWERPC_EXCP_FPU); \
8341 return; \
8342 } \
8343 gen_update_nip(ctx, ctx->nip - 4); \
8344 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8345 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8346 gen_helper_##name(cpu_env, rt, rb); \
8347 if (unlikely(Rc(ctx->opcode) != 0)) { \
8348 gen_set_cr6_from_fpscr(ctx); \
8349 } \
8350 tcg_temp_free_ptr(rt); \
8351 tcg_temp_free_ptr(rb); \
8352 }
8353
8354#define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8355static void gen_##name(DisasContext *ctx) \
8356{ \
8357 TCGv_ptr rt, rs; \
8358 TCGv_i32 i32; \
8359 if (unlikely(!ctx->fpu_enabled)) { \
8360 gen_exception(ctx, POWERPC_EXCP_FPU); \
8361 return; \
8362 } \
8363 gen_update_nip(ctx, ctx->nip - 4); \
8364 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8365 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8366 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8367 gen_helper_##name(cpu_env, rt, rs, i32); \
8368 if (unlikely(Rc(ctx->opcode) != 0)) { \
8369 gen_set_cr6_from_fpscr(ctx); \
8370 } \
8371 tcg_temp_free_ptr(rt); \
8372 tcg_temp_free_ptr(rs); \
8373 tcg_temp_free_i32(i32); \
8374}
ce577d2e 8375
a9d7ba03
TM
8376GEN_DFP_T_A_B_Rc(dadd)
8377GEN_DFP_T_A_B_Rc(daddq)
2128f8a5
TM
8378GEN_DFP_T_A_B_Rc(dsub)
8379GEN_DFP_T_A_B_Rc(dsubq)
8de6a1cc
TM
8380GEN_DFP_T_A_B_Rc(dmul)
8381GEN_DFP_T_A_B_Rc(dmulq)
9024ff40
TM
8382GEN_DFP_T_A_B_Rc(ddiv)
8383GEN_DFP_T_A_B_Rc(ddivq)
5833505b
TM
8384GEN_DFP_BF_A_B(dcmpu)
8385GEN_DFP_BF_A_B(dcmpuq)
8386GEN_DFP_BF_A_B(dcmpo)
8387GEN_DFP_BF_A_B(dcmpoq)
e601c1ee
TM
8388GEN_DFP_BF_A_DCM(dtstdc)
8389GEN_DFP_BF_A_DCM(dtstdcq)
1bf9c0e1
TM
8390GEN_DFP_BF_A_DCM(dtstdg)
8391GEN_DFP_BF_A_DCM(dtstdgq)
f3d2b0bc
TM
8392GEN_DFP_BF_A_B(dtstex)
8393GEN_DFP_BF_A_B(dtstexq)
f6022a76
TM
8394GEN_DFP_BF_A_B(dtstsf)
8395GEN_DFP_BF_A_B(dtstsfq)
5826ebe2
TM
8396GEN_DFP_T_B_U32_U32_Rc(dquai, SIMM5, RMC)
8397GEN_DFP_T_B_U32_U32_Rc(dquaiq, SIMM5, RMC)
8398GEN_DFP_T_A_B_I32_Rc(dqua, RMC)
8399GEN_DFP_T_A_B_I32_Rc(dquaq, RMC)
512918aa
TM
8400GEN_DFP_T_A_B_I32_Rc(drrnd, RMC)
8401GEN_DFP_T_A_B_I32_Rc(drrndq, RMC)
97c0d930
TM
8402GEN_DFP_T_B_U32_U32_Rc(drintx, FPW, RMC)
8403GEN_DFP_T_B_U32_U32_Rc(drintxq, FPW, RMC)
8404GEN_DFP_T_B_U32_U32_Rc(drintn, FPW, RMC)
8405GEN_DFP_T_B_U32_U32_Rc(drintnq, FPW, RMC)
290d9ee5
TM
8406GEN_DFP_T_B_Rc(dctdp)
8407GEN_DFP_T_B_Rc(dctqpq)
ca603eb4
TM
8408GEN_DFP_T_B_Rc(drsp)
8409GEN_DFP_T_B_Rc(drdpq)
f1214193
TM
8410GEN_DFP_T_B_Rc(dcffix)
8411GEN_DFP_T_B_Rc(dcffixq)
bea0dd79
TM
8412GEN_DFP_T_B_Rc(dctfix)
8413GEN_DFP_T_B_Rc(dctfixq)
7796676f
TM
8414GEN_DFP_T_FPR_I32_Rc(ddedpd, rB, SP)
8415GEN_DFP_T_FPR_I32_Rc(ddedpdq, rB, SP)
013c3ac0
TM
8416GEN_DFP_T_FPR_I32_Rc(denbcd, rB, SP)
8417GEN_DFP_T_FPR_I32_Rc(denbcdq, rB, SP)
e8a48460
TM
8418GEN_DFP_T_B_Rc(dxex)
8419GEN_DFP_T_B_Rc(dxexq)
297666eb
TM
8420GEN_DFP_T_A_B_Rc(diex)
8421GEN_DFP_T_A_B_Rc(diexq)
804e654a
TM
8422GEN_DFP_T_FPR_I32_Rc(dscli, rA, DCM)
8423GEN_DFP_T_FPR_I32_Rc(dscliq, rA, DCM)
8424GEN_DFP_T_FPR_I32_Rc(dscri, rA, DCM)
8425GEN_DFP_T_FPR_I32_Rc(dscriq, rA, DCM)
8426
0487d6a8 8427/*** SPE extension ***/
0487d6a8 8428/* Register moves */
3cd7d1dd 8429
a0e13900
FC
8430static inline void gen_evmra(DisasContext *ctx)
8431{
8432
8433 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8434 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8435 return;
8436 }
8437
a0e13900
FC
8438 TCGv_i64 tmp = tcg_temp_new_i64();
8439
8440 /* tmp := rA_lo + rA_hi << 32 */
13b6a455 8441 tcg_gen_concat_tl_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
a0e13900
FC
8442
8443 /* spe_acc := tmp */
1328c2bf 8444 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8445 tcg_temp_free_i64(tmp);
8446
8447 /* rD := rA */
13b6a455
AG
8448 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8449 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
a0e13900
FC
8450}
8451
636aa200
BS
8452static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8453{
13b6a455 8454 tcg_gen_concat_tl_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
f78fb44e 8455}
3cd7d1dd 8456
636aa200
BS
8457static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8458{
13b6a455 8459 tcg_gen_extr_i64_tl(cpu_gpr[reg], cpu_gprh[reg], t);
f78fb44e 8460}
3cd7d1dd 8461
70560da7 8462#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 8463static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
8464{ \
8465 if (Rc(ctx->opcode)) \
8466 gen_##name1(ctx); \
8467 else \
8468 gen_##name0(ctx); \
8469}
8470
8471/* Handler for undefined SPE opcodes */
636aa200 8472static inline void gen_speundef(DisasContext *ctx)
0487d6a8 8473{
e06fcd75 8474 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
8475}
8476
57951c27 8477/* SPE logic */
57951c27 8478#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8479static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8480{ \
8481 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8482 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8483 return; \
8484 } \
8485 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8486 cpu_gpr[rB(ctx->opcode)]); \
8487 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8488 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8489}
57951c27
AJ
8490
8491GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8492GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8493GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8494GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8495GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8496GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8497GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8498GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 8499
57951c27 8500/* SPE logic immediate */
57951c27 8501#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8502static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a 8503{ \
13b6a455 8504 TCGv_i32 t0; \
3d3a6a0a 8505 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8506 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
8507 return; \
8508 } \
13b6a455
AG
8509 t0 = tcg_temp_new_i32(); \
8510 \
8511 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8512 tcg_opi(t0, t0, rB(ctx->opcode)); \
8513 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8514 \
8515 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
57951c27 8516 tcg_opi(t0, t0, rB(ctx->opcode)); \
13b6a455
AG
8517 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8518 \
a7812ae4 8519 tcg_temp_free_i32(t0); \
3d3a6a0a 8520}
57951c27
AJ
8521GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8522GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8523GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8524GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 8525
57951c27 8526/* SPE arithmetic */
57951c27 8527#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8528static inline void gen_##name(DisasContext *ctx) \
0487d6a8 8529{ \
13b6a455 8530 TCGv_i32 t0; \
0487d6a8 8531 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8532 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8533 return; \
8534 } \
13b6a455
AG
8535 t0 = tcg_temp_new_i32(); \
8536 \
8537 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
57951c27 8538 tcg_op(t0, t0); \
13b6a455
AG
8539 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8540 \
8541 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8542 tcg_op(t0, t0); \
8543 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8544 \
a7812ae4 8545 tcg_temp_free_i32(t0); \
57951c27 8546}
0487d6a8 8547
636aa200 8548static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27
AJ
8549{
8550 int l1 = gen_new_label();
8551 int l2 = gen_new_label();
0487d6a8 8552
57951c27
AJ
8553 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8554 tcg_gen_neg_i32(ret, arg1);
8555 tcg_gen_br(l2);
8556 gen_set_label(l1);
a7812ae4 8557 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
8558 gen_set_label(l2);
8559}
8560GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8561GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8562GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8563GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 8564static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 8565{
57951c27
AJ
8566 tcg_gen_addi_i32(ret, arg1, 0x8000);
8567 tcg_gen_ext16u_i32(ret, ret);
8568}
8569GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
8570GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8571GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 8572
57951c27 8573#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8574static inline void gen_##name(DisasContext *ctx) \
0487d6a8 8575{ \
13b6a455 8576 TCGv_i32 t0, t1; \
0487d6a8 8577 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8578 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8579 return; \
8580 } \
13b6a455
AG
8581 t0 = tcg_temp_new_i32(); \
8582 t1 = tcg_temp_new_i32(); \
8583 \
8584 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8585 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8586 tcg_op(t0, t0, t1); \
8587 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8588 \
8589 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8590 tcg_gen_trunc_tl_i32(t1, cpu_gprh[rB(ctx->opcode)]); \
8591 tcg_op(t0, t0, t1); \
8592 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8593 \
a7812ae4
PB
8594 tcg_temp_free_i32(t0); \
8595 tcg_temp_free_i32(t1); \
0487d6a8 8596}
0487d6a8 8597
636aa200 8598static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8599{
a7812ae4 8600 TCGv_i32 t0;
57951c27 8601 int l1, l2;
0487d6a8 8602
57951c27
AJ
8603 l1 = gen_new_label();
8604 l2 = gen_new_label();
a7812ae4 8605 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8606 /* No error here: 6 bits are used */
8607 tcg_gen_andi_i32(t0, arg2, 0x3F);
8608 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8609 tcg_gen_shr_i32(ret, arg1, t0);
8610 tcg_gen_br(l2);
8611 gen_set_label(l1);
8612 tcg_gen_movi_i32(ret, 0);
0aef4261 8613 gen_set_label(l2);
a7812ae4 8614 tcg_temp_free_i32(t0);
57951c27
AJ
8615}
8616GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 8617static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8618{
a7812ae4 8619 TCGv_i32 t0;
57951c27
AJ
8620 int l1, l2;
8621
8622 l1 = gen_new_label();
8623 l2 = gen_new_label();
a7812ae4 8624 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8625 /* No error here: 6 bits are used */
8626 tcg_gen_andi_i32(t0, arg2, 0x3F);
8627 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8628 tcg_gen_sar_i32(ret, arg1, t0);
8629 tcg_gen_br(l2);
8630 gen_set_label(l1);
8631 tcg_gen_movi_i32(ret, 0);
0aef4261 8632 gen_set_label(l2);
a7812ae4 8633 tcg_temp_free_i32(t0);
57951c27
AJ
8634}
8635GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 8636static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8637{
a7812ae4 8638 TCGv_i32 t0;
57951c27
AJ
8639 int l1, l2;
8640
8641 l1 = gen_new_label();
8642 l2 = gen_new_label();
a7812ae4 8643 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8644 /* No error here: 6 bits are used */
8645 tcg_gen_andi_i32(t0, arg2, 0x3F);
8646 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8647 tcg_gen_shl_i32(ret, arg1, t0);
8648 tcg_gen_br(l2);
8649 gen_set_label(l1);
8650 tcg_gen_movi_i32(ret, 0);
e29ef9fa 8651 gen_set_label(l2);
a7812ae4 8652 tcg_temp_free_i32(t0);
57951c27
AJ
8653}
8654GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 8655static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8656{
a7812ae4 8657 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
8658 tcg_gen_andi_i32(t0, arg2, 0x1F);
8659 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 8660 tcg_temp_free_i32(t0);
57951c27
AJ
8661}
8662GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 8663static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
8664{
8665 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8666 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8667 return;
8668 }
13b6a455
AG
8669 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8670 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27
AJ
8671}
8672GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 8673static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 8674{
57951c27
AJ
8675 tcg_gen_sub_i32(ret, arg2, arg1);
8676}
8677GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 8678
57951c27 8679/* SPE arithmetic immediate */
57951c27 8680#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8681static inline void gen_##name(DisasContext *ctx) \
57951c27 8682{ \
13b6a455 8683 TCGv_i32 t0; \
57951c27 8684 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8685 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8686 return; \
8687 } \
13b6a455
AG
8688 t0 = tcg_temp_new_i32(); \
8689 \
8690 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
57951c27 8691 tcg_op(t0, t0, rA(ctx->opcode)); \
13b6a455
AG
8692 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8693 \
8694 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rB(ctx->opcode)]); \
8695 tcg_op(t0, t0, rA(ctx->opcode)); \
8696 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8697 \
a7812ae4 8698 tcg_temp_free_i32(t0); \
57951c27 8699}
57951c27
AJ
8700GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8701GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8702
8703/* SPE comparison */
57951c27 8704#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8705static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8706{ \
8707 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8708 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8709 return; \
8710 } \
8711 int l1 = gen_new_label(); \
8712 int l2 = gen_new_label(); \
8713 int l3 = gen_new_label(); \
8714 int l4 = gen_new_label(); \
8715 \
13b6a455
AG
8716 tcg_gen_ext32s_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8717 tcg_gen_ext32s_tl(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8718 tcg_gen_ext32s_tl(cpu_gprh[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8719 tcg_gen_ext32s_tl(cpu_gprh[rB(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); \
8720 \
8721 tcg_gen_brcond_tl(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
57951c27 8722 cpu_gpr[rB(ctx->opcode)], l1); \
13b6a455 8723 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8724 tcg_gen_br(l2); \
8725 gen_set_label(l1); \
8726 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8727 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8728 gen_set_label(l2); \
13b6a455 8729 tcg_gen_brcond_tl(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
57951c27
AJ
8730 cpu_gprh[rB(ctx->opcode)], l3); \
8731 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8732 ~(CRF_CH | CRF_CH_AND_CL)); \
8733 tcg_gen_br(l4); \
8734 gen_set_label(l3); \
8735 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8736 CRF_CH | CRF_CH_OR_CL); \
8737 gen_set_label(l4); \
8738}
57951c27
AJ
8739GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8740GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8741GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8742GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8743GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8744
8745/* SPE misc */
636aa200 8746static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8747{
8748 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8749 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8750 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8751}
636aa200 8752static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8753{
8754 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8755 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8756 return;
8757 }
13b6a455
AG
8758 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8759 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27 8760}
636aa200 8761static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8762{
8763 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8764 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8765 return;
8766 }
13b6a455
AG
8767 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8768 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27 8769}
636aa200 8770static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8771{
8772 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8773 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8774 return;
8775 }
33890b3e 8776 if (rD(ctx->opcode) == rA(ctx->opcode)) {
13b6a455
AG
8777 TCGv tmp = tcg_temp_new();
8778 tcg_gen_mov_tl(tmp, cpu_gpr[rA(ctx->opcode)]);
8779 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8780 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], tmp);
8781 tcg_temp_free(tmp);
33890b3e 8782 } else {
13b6a455
AG
8783 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8784 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8785 }
57951c27 8786}
636aa200 8787static inline void gen_evsplati(DisasContext *ctx)
57951c27 8788{
ae01847f 8789 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8790
13b6a455
AG
8791 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
8792 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
57951c27 8793}
636aa200 8794static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8795{
ae01847f 8796 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8797
13b6a455
AG
8798 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
8799 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
0487d6a8
JM
8800}
8801
636aa200 8802static inline void gen_evsel(DisasContext *ctx)
57951c27
AJ
8803{
8804 int l1 = gen_new_label();
8805 int l2 = gen_new_label();
8806 int l3 = gen_new_label();
8807 int l4 = gen_new_label();
a7812ae4 8808 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8809 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8810 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
57951c27 8811 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27
AJ
8812 tcg_gen_br(l2);
8813 gen_set_label(l1);
57951c27 8814 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
57951c27
AJ
8815 gen_set_label(l2);
8816 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8817 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
57951c27 8818 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8819 tcg_gen_br(l4);
8820 gen_set_label(l3);
57951c27 8821 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27 8822 gen_set_label(l4);
a7812ae4 8823 tcg_temp_free_i32(t0);
57951c27 8824}
e8eaa2c0
BS
8825
8826static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
8827{
8828 gen_evsel(ctx);
8829}
e8eaa2c0
BS
8830
8831static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
8832{
8833 gen_evsel(ctx);
8834}
e8eaa2c0
BS
8835
8836static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
8837{
8838 gen_evsel(ctx);
8839}
e8eaa2c0
BS
8840
8841static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
8842{
8843 gen_evsel(ctx);
8844}
0487d6a8 8845
a0e13900
FC
8846/* Multiply */
8847
8848static inline void gen_evmwumi(DisasContext *ctx)
8849{
8850 TCGv_i64 t0, t1;
8851
8852 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8853 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8854 return;
8855 }
8856
8857 t0 = tcg_temp_new_i64();
8858 t1 = tcg_temp_new_i64();
8859
8860 /* t0 := rA; t1 := rB */
a0e13900 8861 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
13b6a455 8862 tcg_gen_ext32u_i64(t0, t0);
a0e13900 8863 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
13b6a455 8864 tcg_gen_ext32u_i64(t1, t1);
a0e13900
FC
8865
8866 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8867
8868 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8869
8870 tcg_temp_free_i64(t0);
8871 tcg_temp_free_i64(t1);
8872}
8873
8874static inline void gen_evmwumia(DisasContext *ctx)
8875{
8876 TCGv_i64 tmp;
8877
8878 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8879 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8880 return;
8881 }
8882
8883 gen_evmwumi(ctx); /* rD := rA * rB */
8884
8885 tmp = tcg_temp_new_i64();
8886
8887 /* acc := rD */
8888 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8889 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8890 tcg_temp_free_i64(tmp);
8891}
8892
8893static inline void gen_evmwumiaa(DisasContext *ctx)
8894{
8895 TCGv_i64 acc;
8896 TCGv_i64 tmp;
8897
8898 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8899 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8900 return;
8901 }
8902
8903 gen_evmwumi(ctx); /* rD := rA * rB */
8904
8905 acc = tcg_temp_new_i64();
8906 tmp = tcg_temp_new_i64();
8907
8908 /* tmp := rD */
8909 gen_load_gpr64(tmp, rD(ctx->opcode));
8910
8911 /* Load acc */
1328c2bf 8912 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8913
8914 /* acc := tmp + acc */
8915 tcg_gen_add_i64(acc, acc, tmp);
8916
8917 /* Store acc */
1328c2bf 8918 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8919
8920 /* rD := acc */
8921 gen_store_gpr64(rD(ctx->opcode), acc);
8922
8923 tcg_temp_free_i64(acc);
8924 tcg_temp_free_i64(tmp);
8925}
8926
8927static inline void gen_evmwsmi(DisasContext *ctx)
8928{
8929 TCGv_i64 t0, t1;
8930
8931 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8932 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8933 return;
8934 }
8935
8936 t0 = tcg_temp_new_i64();
8937 t1 = tcg_temp_new_i64();
8938
8939 /* t0 := rA; t1 := rB */
13b6a455
AG
8940 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8941 tcg_gen_ext32s_i64(t0, t0);
8942 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8943 tcg_gen_ext32s_i64(t1, t1);
a0e13900
FC
8944
8945 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8946
8947 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8948
8949 tcg_temp_free_i64(t0);
8950 tcg_temp_free_i64(t1);
8951}
8952
8953static inline void gen_evmwsmia(DisasContext *ctx)
8954{
8955 TCGv_i64 tmp;
8956
8957 gen_evmwsmi(ctx); /* rD := rA * rB */
8958
8959 tmp = tcg_temp_new_i64();
8960
8961 /* acc := rD */
8962 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8963 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8964
8965 tcg_temp_free_i64(tmp);
8966}
8967
8968static inline void gen_evmwsmiaa(DisasContext *ctx)
8969{
8970 TCGv_i64 acc = tcg_temp_new_i64();
8971 TCGv_i64 tmp = tcg_temp_new_i64();
8972
8973 gen_evmwsmi(ctx); /* rD := rA * rB */
8974
8975 acc = tcg_temp_new_i64();
8976 tmp = tcg_temp_new_i64();
8977
8978 /* tmp := rD */
8979 gen_load_gpr64(tmp, rD(ctx->opcode));
8980
8981 /* Load acc */
1328c2bf 8982 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8983
8984 /* acc := tmp + acc */
8985 tcg_gen_add_i64(acc, acc, tmp);
8986
8987 /* Store acc */
1328c2bf 8988 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8989
8990 /* rD := acc */
8991 gen_store_gpr64(rD(ctx->opcode), acc);
8992
8993 tcg_temp_free_i64(acc);
8994 tcg_temp_free_i64(tmp);
8995}
8996
70560da7
FC
8997GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8998GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8999GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9000GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9001GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9002GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9003GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9004GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
9005GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
9006GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9007GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9008GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9009GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9010GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9011GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9012GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9013GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9014GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9015GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9016GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
9017GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9018GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9019GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
9020GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
9021GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9022GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9023GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9024GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9025GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 9026
6a6ae23f 9027/* SPE load and stores */
636aa200 9028static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
9029{
9030 target_ulong uimm = rB(ctx->opcode);
9031
76db3ba4 9032 if (rA(ctx->opcode) == 0) {
6a6ae23f 9033 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 9034 } else {
6a6ae23f 9035 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 9036 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
9037 tcg_gen_ext32u_tl(EA, EA);
9038 }
76db3ba4 9039 }
0487d6a8 9040}
6a6ae23f 9041
636aa200 9042static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f 9043{
6a6ae23f 9044 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 9045 gen_qemu_ld64(ctx, t0, addr);
13b6a455 9046 gen_store_gpr64(rD(ctx->opcode), t0);
6a6ae23f 9047 tcg_temp_free_i64(t0);
0487d6a8 9048}
6a6ae23f 9049
636aa200 9050static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 9051{
76db3ba4
AJ
9052 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9053 gen_addr_add(ctx, addr, addr, 4);
9054 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
0487d6a8 9055}
6a6ae23f 9056
636aa200 9057static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9058{
9059 TCGv t0 = tcg_temp_new();
76db3ba4 9060 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9061 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9062 gen_addr_add(ctx, addr, addr, 2);
9063 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9064 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9065 gen_addr_add(ctx, addr, addr, 2);
9066 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9067 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9068 gen_addr_add(ctx, addr, addr, 2);
9069 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9070 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9071 tcg_temp_free(t0);
0487d6a8
JM
9072}
9073
636aa200 9074static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9075{
9076 TCGv t0 = tcg_temp_new();
76db3ba4 9077 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9078 tcg_gen_shli_tl(t0, t0, 16);
9079 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9080 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9081 tcg_temp_free(t0);
0487d6a8
JM
9082}
9083
636aa200 9084static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9085{
9086 TCGv t0 = tcg_temp_new();
76db3ba4 9087 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9088 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9089 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9090 tcg_temp_free(t0);
0487d6a8
JM
9091}
9092
636aa200 9093static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9094{
9095 TCGv t0 = tcg_temp_new();
76db3ba4 9096 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9097 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9098 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9099 tcg_temp_free(t0);
9100}
9101
636aa200 9102static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9103{
9104 TCGv t0 = tcg_temp_new();
76db3ba4 9105 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9106 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9107 gen_addr_add(ctx, addr, addr, 2);
9108 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9109 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
6a6ae23f
AJ
9110 tcg_temp_free(t0);
9111}
9112
636aa200 9113static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f 9114{
76db3ba4
AJ
9115 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9116 gen_addr_add(ctx, addr, addr, 2);
9117 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9118}
9119
636aa200 9120static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f 9121{
76db3ba4
AJ
9122 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9123 gen_addr_add(ctx, addr, addr, 2);
9124 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9125}
9126
636aa200 9127static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9128{
9129 TCGv t0 = tcg_temp_new();
76db3ba4 9130 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
9131 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9132 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9133 tcg_temp_free(t0);
9134}
9135
636aa200 9136static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9137{
9138 TCGv t0 = tcg_temp_new();
76db3ba4 9139 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9140 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9141 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9142 gen_addr_add(ctx, addr, addr, 2);
9143 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9144 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9145 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9146 tcg_temp_free(t0);
9147}
9148
636aa200 9149static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f 9150{
6a6ae23f 9151 TCGv_i64 t0 = tcg_temp_new_i64();
13b6a455 9152 gen_load_gpr64(t0, rS(ctx->opcode));
76db3ba4 9153 gen_qemu_st64(ctx, t0, addr);
6a6ae23f 9154 tcg_temp_free_i64(t0);
6a6ae23f
AJ
9155}
9156
636aa200 9157static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 9158{
76db3ba4 9159 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4
AJ
9160 gen_addr_add(ctx, addr, addr, 4);
9161 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9162}
9163
636aa200 9164static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9165{
9166 TCGv t0 = tcg_temp_new();
6a6ae23f 9167 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
76db3ba4
AJ
9168 gen_qemu_st16(ctx, t0, addr);
9169 gen_addr_add(ctx, addr, addr, 2);
76db3ba4 9170 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4 9171 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9172 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9173 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9174 tcg_temp_free(t0);
76db3ba4
AJ
9175 gen_addr_add(ctx, addr, addr, 2);
9176 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9177}
9178
636aa200 9179static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9180{
9181 TCGv t0 = tcg_temp_new();
6a6ae23f 9182 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
76db3ba4
AJ
9183 gen_qemu_st16(ctx, t0, addr);
9184 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9185 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9186 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9187 tcg_temp_free(t0);
9188}
9189
636aa200 9190static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f 9191{
76db3ba4 9192 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4
AJ
9193 gen_addr_add(ctx, addr, addr, 2);
9194 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9195}
9196
636aa200 9197static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f 9198{
76db3ba4 9199 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9200}
9201
636aa200 9202static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 9203{
76db3ba4 9204 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9205}
9206
9207#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 9208static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
9209{ \
9210 TCGv t0; \
9211 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9212 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
9213 return; \
9214 } \
76db3ba4 9215 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
9216 t0 = tcg_temp_new(); \
9217 if (Rc(ctx->opcode)) { \
76db3ba4 9218 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 9219 } else { \
76db3ba4 9220 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
9221 } \
9222 gen_op_##name(ctx, t0); \
9223 tcg_temp_free(t0); \
9224}
9225
9226GEN_SPEOP_LDST(evldd, 0x00, 3);
9227GEN_SPEOP_LDST(evldw, 0x01, 3);
9228GEN_SPEOP_LDST(evldh, 0x02, 3);
9229GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9230GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9231GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9232GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9233GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9234GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9235GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9236GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9237
9238GEN_SPEOP_LDST(evstdd, 0x10, 3);
9239GEN_SPEOP_LDST(evstdw, 0x11, 3);
9240GEN_SPEOP_LDST(evstdh, 0x12, 3);
9241GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9242GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9243GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9244GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
9245
9246/* Multiply and add - TODO */
9247#if 0
70560da7
FC
9248GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9249GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9250GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9251GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9252GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9253GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9254GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9255GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9256GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9257GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9258GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9259GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9260
9261GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9262GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9263GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9264GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9265GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9266GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9267GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9268GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9269GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9270GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9271GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9272GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9273
9274GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9275GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9276GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9277GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9278GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9279
9280GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9281GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9282GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9283GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9284GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9285GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9286GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9287GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9288GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9289GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9290GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9291GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9292
9293GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9294GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9295GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9296GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9297
9298GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9299GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9300GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9301GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9302GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9303GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9304GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9305GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9306GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9307GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9308GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9309GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9310
9311GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9312GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9313GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9314GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9315GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
9316#endif
9317
9318/*** SPE floating-point extension ***/
1c97856d 9319#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9320static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9321{ \
9322 TCGv_i32 t0 = tcg_temp_new_i32(); \
9323 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
13b6a455
AG
9324 gen_helper_##name(t0, cpu_env, t0); \
9325 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
1c97856d 9326 tcg_temp_free_i32(t0); \
57951c27 9327}
1c97856d 9328#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9329static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9330{ \
9331 TCGv_i64 t0 = tcg_temp_new_i64(); \
13b6a455 9332 TCGv_i32 t1 = tcg_temp_new_i32(); \
1c97856d 9333 gen_load_gpr64(t0, rB(ctx->opcode)); \
13b6a455
AG
9334 gen_helper_##name(t1, cpu_env, t0); \
9335 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); \
1c97856d 9336 tcg_temp_free_i64(t0); \
13b6a455 9337 tcg_temp_free_i32(t1); \
1c97856d
AJ
9338}
9339#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9340static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9341{ \
9342 TCGv_i64 t0 = tcg_temp_new_i64(); \
13b6a455
AG
9343 TCGv_i32 t1 = tcg_temp_new_i32(); \
9344 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9345 gen_helper_##name(t0, cpu_env, t1); \
1c97856d
AJ
9346 gen_store_gpr64(rD(ctx->opcode), t0); \
9347 tcg_temp_free_i64(t0); \
13b6a455 9348 tcg_temp_free_i32(t1); \
1c97856d
AJ
9349}
9350#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9351static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9352{ \
9353 TCGv_i64 t0 = tcg_temp_new_i64(); \
9354 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9355 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9356 gen_store_gpr64(rD(ctx->opcode), t0); \
9357 tcg_temp_free_i64(t0); \
9358}
9359#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9360static inline void gen_##name(DisasContext *ctx) \
1c97856d 9361{ \
13b6a455 9362 TCGv_i32 t0, t1; \
1c97856d 9363 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9364 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9365 return; \
9366 } \
13b6a455
AG
9367 t0 = tcg_temp_new_i32(); \
9368 t1 = tcg_temp_new_i32(); \
9369 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9370 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9371 gen_helper_##name(t0, cpu_env, t0, t1); \
9372 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9373 \
9374 tcg_temp_free_i32(t0); \
9375 tcg_temp_free_i32(t1); \
1c97856d
AJ
9376}
9377#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9378static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9379{ \
9380 TCGv_i64 t0, t1; \
9381 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9382 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9383 return; \
9384 } \
9385 t0 = tcg_temp_new_i64(); \
9386 t1 = tcg_temp_new_i64(); \
9387 gen_load_gpr64(t0, rA(ctx->opcode)); \
9388 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9389 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9390 gen_store_gpr64(rD(ctx->opcode), t0); \
9391 tcg_temp_free_i64(t0); \
9392 tcg_temp_free_i64(t1); \
9393}
9394#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9395static inline void gen_##name(DisasContext *ctx) \
1c97856d 9396{ \
13b6a455 9397 TCGv_i32 t0, t1; \
1c97856d 9398 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9399 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9400 return; \
9401 } \
13b6a455
AG
9402 t0 = tcg_temp_new_i32(); \
9403 t1 = tcg_temp_new_i32(); \
9404 \
9405 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9406 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9407 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9408 \
9409 tcg_temp_free_i32(t0); \
9410 tcg_temp_free_i32(t1); \
1c97856d
AJ
9411}
9412#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9413static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9414{ \
9415 TCGv_i64 t0, t1; \
9416 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9417 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9418 return; \
9419 } \
9420 t0 = tcg_temp_new_i64(); \
9421 t1 = tcg_temp_new_i64(); \
9422 gen_load_gpr64(t0, rA(ctx->opcode)); \
9423 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9424 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9425 tcg_temp_free_i64(t0); \
9426 tcg_temp_free_i64(t1); \
9427}
57951c27 9428
0487d6a8
JM
9429/* Single precision floating-point vectors operations */
9430/* Arithmetic */
1c97856d
AJ
9431GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9432GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9433GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9434GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9435static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9436{
9437 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9438 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9439 return;
9440 }
13b6a455
AG
9441 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9442 ~0x80000000);
9443 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9444 ~0x80000000);
1c97856d 9445}
636aa200 9446static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9447{
9448 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9449 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9450 return;
9451 }
13b6a455
AG
9452 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9453 0x80000000);
9454 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9455 0x80000000);
1c97856d 9456}
636aa200 9457static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9458{
9459 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9460 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9461 return;
9462 }
13b6a455
AG
9463 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9464 0x80000000);
9465 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9466 0x80000000);
1c97856d
AJ
9467}
9468
0487d6a8 9469/* Conversion */
1c97856d
AJ
9470GEN_SPEFPUOP_CONV_64_64(evfscfui);
9471GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9472GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9473GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9474GEN_SPEFPUOP_CONV_64_64(evfsctui);
9475GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9476GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9477GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9478GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9479GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9480
0487d6a8 9481/* Comparison */
1c97856d
AJ
9482GEN_SPEFPUOP_COMP_64(evfscmpgt);
9483GEN_SPEFPUOP_COMP_64(evfscmplt);
9484GEN_SPEFPUOP_COMP_64(evfscmpeq);
9485GEN_SPEFPUOP_COMP_64(evfststgt);
9486GEN_SPEFPUOP_COMP_64(evfststlt);
9487GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9488
9489/* Opcodes definitions */
70560da7
FC
9490GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9491GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9492GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9493GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9494GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9495GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9496GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9497GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9498GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9499GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9500GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9501GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9502GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9503GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9504
9505/* Single precision floating-point operations */
9506/* Arithmetic */
1c97856d
AJ
9507GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9508GEN_SPEFPUOP_ARITH2_32_32(efssub);
9509GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9510GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9511static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9512{
9513 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9514 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9515 return;
9516 }
6d5c34fa 9517 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9518}
636aa200 9519static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9520{
9521 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9522 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9523 return;
9524 }
6d5c34fa 9525 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9526}
636aa200 9527static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9528{
9529 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9530 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9531 return;
9532 }
6d5c34fa 9533 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9534}
9535
0487d6a8 9536/* Conversion */
1c97856d
AJ
9537GEN_SPEFPUOP_CONV_32_32(efscfui);
9538GEN_SPEFPUOP_CONV_32_32(efscfsi);
9539GEN_SPEFPUOP_CONV_32_32(efscfuf);
9540GEN_SPEFPUOP_CONV_32_32(efscfsf);
9541GEN_SPEFPUOP_CONV_32_32(efsctui);
9542GEN_SPEFPUOP_CONV_32_32(efsctsi);
9543GEN_SPEFPUOP_CONV_32_32(efsctuf);
9544GEN_SPEFPUOP_CONV_32_32(efsctsf);
9545GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9546GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9547GEN_SPEFPUOP_CONV_32_64(efscfd);
9548
0487d6a8 9549/* Comparison */
1c97856d
AJ
9550GEN_SPEFPUOP_COMP_32(efscmpgt);
9551GEN_SPEFPUOP_COMP_32(efscmplt);
9552GEN_SPEFPUOP_COMP_32(efscmpeq);
9553GEN_SPEFPUOP_COMP_32(efststgt);
9554GEN_SPEFPUOP_COMP_32(efststlt);
9555GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9556
9557/* Opcodes definitions */
70560da7
FC
9558GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9559GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9560GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9561GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9562GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9563GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9564GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9565GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9566GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9567GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9568GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9569GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9570GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9571GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9572
9573/* Double precision floating-point operations */
9574/* Arithmetic */
1c97856d
AJ
9575GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9576GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9577GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9578GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9579static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9580{
9581 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9582 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9583 return;
9584 }
6d5c34fa 9585 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9586 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9587 ~0x80000000);
1c97856d 9588}
636aa200 9589static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
9590{
9591 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9592 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9593 return;
9594 }
6d5c34fa 9595 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9596 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9597 0x80000000);
1c97856d 9598}
636aa200 9599static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
9600{
9601 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9602 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9603 return;
9604 }
6d5c34fa 9605 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9606 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9607 0x80000000);
1c97856d
AJ
9608}
9609
0487d6a8 9610/* Conversion */
1c97856d
AJ
9611GEN_SPEFPUOP_CONV_64_32(efdcfui);
9612GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9613GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9614GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9615GEN_SPEFPUOP_CONV_32_64(efdctui);
9616GEN_SPEFPUOP_CONV_32_64(efdctsi);
9617GEN_SPEFPUOP_CONV_32_64(efdctuf);
9618GEN_SPEFPUOP_CONV_32_64(efdctsf);
9619GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9620GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9621GEN_SPEFPUOP_CONV_64_32(efdcfs);
9622GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9623GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9624GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9625GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 9626
0487d6a8 9627/* Comparison */
1c97856d
AJ
9628GEN_SPEFPUOP_COMP_64(efdcmpgt);
9629GEN_SPEFPUOP_COMP_64(efdcmplt);
9630GEN_SPEFPUOP_COMP_64(efdcmpeq);
9631GEN_SPEFPUOP_COMP_64(efdtstgt);
9632GEN_SPEFPUOP_COMP_64(efdtstlt);
9633GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
9634
9635/* Opcodes definitions */
70560da7
FC
9636GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9637GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9638GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9639GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9640GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9641GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9642GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9643GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9644GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9645GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9646GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9647GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9648GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9649GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9650GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9651GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 9652
c227f099 9653static opcode_t opcodes[] = {
5c55ff99
BS
9654GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9655GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9656GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9657GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9658GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 9659GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9660GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9661GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9662GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9663GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9664GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9665GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9666GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9667GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9668GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9669GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9670#if defined(TARGET_PPC64)
9671GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9672#endif
9673GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9674GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9675GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9676GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9677GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9678GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9679GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9680GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9681GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9682GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9683GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9684GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
6ab39b1b 9685GEN_HANDLER(popcntb, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 9686GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 9687GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 9688#if defined(TARGET_PPC64)
eaabeef2 9689GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 9690GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 9691GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
86ba37ed 9692GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
5c55ff99
BS
9693#endif
9694GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9695GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9696GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9697GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9698GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9699GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9700GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9701#if defined(TARGET_PPC64)
9702GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9703GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9704GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9705GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9706GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9707#endif
9708GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9709GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9710GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9711GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9712GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 9713GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 9714GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
9715GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9716GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 9717GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
097ec5d8
TM
9718GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
9719GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
5c55ff99
BS
9720GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9721GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9722GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9723GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
9724GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9725GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
9726#if defined(TARGET_PPC64)
9727GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9728GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9729GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9730#endif
9731GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9732GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9733GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9734GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9735GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9736GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9737GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9738GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
5c77a786
TM
9739GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9740GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
f844c817 9741GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
587c51f7
TM
9742GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9743GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
5c55ff99
BS
9744GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9745#if defined(TARGET_PPC64)
f844c817 9746GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
9c294d5a 9747GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99 9748GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
27b95bfe 9749GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99
BS
9750#endif
9751GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9752GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9753GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9754GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9755GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9756GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
52a4984d 9757GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
5c55ff99
BS
9758GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9759GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9760#if defined(TARGET_PPC64)
9761GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9762GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9763#endif
9764GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9765GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9766GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9767#if defined(TARGET_PPC64)
9768GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9769GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9770#endif
9771GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9772GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9773GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9774GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9775GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9776GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9777#if defined(TARGET_PPC64)
9778GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9779#endif
9780GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
9781GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
9782GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9783GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9784GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
3f34cf91
CLG
9785GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
9786GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
4d09d529 9787GEN_HANDLER_E(dcbtls, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE, PPC2_BOOKE206),
8e33944f 9788GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
9789GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9790GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9791GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9792GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9793GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9794GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9795GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9796GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9797GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9798#if defined(TARGET_PPC64)
9799GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9800GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9801 PPC_SEGMENT_64B),
9802GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
9803GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9804 PPC_SEGMENT_64B),
efdef95f
DG
9805GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
9806GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
9807GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
9808#endif
9809GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
9810GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
9811GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
9812GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
9813#if defined(TARGET_PPC64)
9814GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
9815GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
9816#endif
9817GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
9818GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
9819GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
9820GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
9821GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
9822GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
9823GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
9824GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
9825GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
9826GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
9827GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
9828GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9829GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
9830GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
9831GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
9832GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
9833GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
9834GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
9835GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
9836GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9837GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
9838GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
9839GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
9840GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
9841GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
9842GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
9843GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
9844GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
9845GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
9846GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
9847GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
9848GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
9849GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
9850GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
9851GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
9852GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
9853GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
9854GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
9855GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
9856GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
9857GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
9858GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
9859GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
9860GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
9861GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
9862GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
9863GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
9864GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
9865GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
9866GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9867GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9868GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
9869GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
9870GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9871GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9872GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
9873GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
9874GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
9875GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
9876GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
9877GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
9878GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
9879GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
9880GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
9881GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
9882GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
9883GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
9884GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
9885GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
9886GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
9887GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 9888GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
9889GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
9890GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
9891GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
9892GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
9893GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
9894GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
9895GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
9896GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
9897GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
9898 PPC_NONE, PPC2_BOOKE206),
9899GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
9900 PPC_NONE, PPC2_BOOKE206),
9901GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
9902 PPC_NONE, PPC2_BOOKE206),
9903GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
9904 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
9905GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
9906 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
9907GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
9908 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
9909GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
9910 PPC_NONE, PPC2_PRCNTL),
5c55ff99 9911GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 9912GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 9913GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
9914GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
9915 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 9916GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
9917GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
9918 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
9919GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
9920GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
9921GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
9922GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
5c55ff99
BS
9923GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
9924GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
9925GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
9926GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
9927GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
9928
9929#undef GEN_INT_ARITH_ADD
9930#undef GEN_INT_ARITH_ADD_CONST
9931#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
9932GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
9933#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
9934 add_ca, compute_ca, compute_ov) \
9935GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
9936GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
9937GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
9938GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
9939GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
9940GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
9941GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
9942GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
9943GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
9944GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
9945GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
9946
9947#undef GEN_INT_ARITH_DIVW
9948#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
9949GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
9950GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
9951GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
9952GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
9953GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
a98eb9e9
TM
9954GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
9955GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
6a4fda33
TM
9956GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
9957GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
5c55ff99
BS
9958
9959#if defined(TARGET_PPC64)
9960#undef GEN_INT_ARITH_DIVD
9961#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
9962GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9963GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
9964GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
9965GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
9966GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
9967
98d1eb27
TM
9968GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
9969GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
e44259b6
TM
9970GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
9971GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
98d1eb27 9972
5c55ff99
BS
9973#undef GEN_INT_ARITH_MUL_HELPER
9974#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
9975GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9976GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
9977GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
9978GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
9979#endif
9980
9981#undef GEN_INT_ARITH_SUBF
9982#undef GEN_INT_ARITH_SUBF_CONST
9983#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
9984GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
9985#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
9986 add_ca, compute_ca, compute_ov) \
9987GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
9988GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
9989GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
9990GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
9991GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
9992GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
9993GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
9994GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
9995GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
9996GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
9997GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
9998
9999#undef GEN_LOGICAL1
10000#undef GEN_LOGICAL2
10001#define GEN_LOGICAL2(name, tcg_op, opc, type) \
10002GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10003#define GEN_LOGICAL1(name, tcg_op, opc, type) \
10004GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10005GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10006GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10007GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10008GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10009GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10010GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10011GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10012GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10013#if defined(TARGET_PPC64)
10014GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10015#endif
10016
10017#if defined(TARGET_PPC64)
10018#undef GEN_PPC64_R2
10019#undef GEN_PPC64_R4
10020#define GEN_PPC64_R2(name, opc1, opc2) \
10021GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10022GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10023 PPC_64B)
10024#define GEN_PPC64_R4(name, opc1, opc2) \
10025GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10026GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10027 PPC_64B), \
10028GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10029 PPC_64B), \
10030GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10031 PPC_64B)
10032GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10033GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10034GEN_PPC64_R4(rldic, 0x1E, 0x04),
10035GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10036GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10037GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10038#endif
10039
10040#undef _GEN_FLOAT_ACB
10041#undef GEN_FLOAT_ACB
10042#undef _GEN_FLOAT_AB
10043#undef GEN_FLOAT_AB
10044#undef _GEN_FLOAT_AC
10045#undef GEN_FLOAT_AC
10046#undef GEN_FLOAT_B
10047#undef GEN_FLOAT_BS
10048#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10049GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10050#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10051_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10052_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10053#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10054GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10055#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10056_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10057_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10058#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10059GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10060#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10061_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10062_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10063#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10064GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10065#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10066GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10067
10068GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10069GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10070GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10071GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10072GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10073GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10074_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10075GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10076GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10077GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10078GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10079GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
da29cb7b 10080GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
6d41d146 10081GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
5c55ff99 10082GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
fab7fe42 10083GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10084GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
fab7fe42 10085GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10086GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
10087#if defined(TARGET_PPC64)
10088GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
28288b48
TM
10089GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10090GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10091GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10092GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
fab7fe42 10093GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10094GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
fab7fe42 10095GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10096#endif
10097GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10098GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10099GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10100GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
10101
10102#undef GEN_LD
10103#undef GEN_LDU
10104#undef GEN_LDUX
cd6e9320 10105#undef GEN_LDX_E
5c55ff99
BS
10106#undef GEN_LDS
10107#define GEN_LD(name, ldop, opc, type) \
10108GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10109#define GEN_LDU(name, ldop, opc, type) \
10110GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10111#define GEN_LDUX(name, ldop, opc2, opc3, type) \
10112GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10113#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10114GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10115#define GEN_LDS(name, ldop, op, type) \
10116GEN_LD(name, ldop, op | 0x20, type) \
10117GEN_LDU(name, ldop, op | 0x21, type) \
10118GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10119GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10120
10121GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10122GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10123GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10124GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10125#if defined(TARGET_PPC64)
10126GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10127GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10128GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10129GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 10130GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10131#endif
10132GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10133GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10134
10135#undef GEN_ST
10136#undef GEN_STU
10137#undef GEN_STUX
cd6e9320 10138#undef GEN_STX_E
5c55ff99
BS
10139#undef GEN_STS
10140#define GEN_ST(name, stop, opc, type) \
10141GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10142#define GEN_STU(name, stop, opc, type) \
10143GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10144#define GEN_STUX(name, stop, opc2, opc3, type) \
10145GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10146#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10147GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10148#define GEN_STS(name, stop, op, type) \
10149GEN_ST(name, stop, op | 0x20, type) \
10150GEN_STU(name, stop, op | 0x21, type) \
10151GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10152GEN_STX(name, stop, 0x17, op | 0x00, type)
10153
10154GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10155GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10156GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10157#if defined(TARGET_PPC64)
10158GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10159GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 10160GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10161#endif
10162GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10163GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10164
10165#undef GEN_LDF
10166#undef GEN_LDUF
10167#undef GEN_LDUXF
10168#undef GEN_LDXF
10169#undef GEN_LDFS
10170#define GEN_LDF(name, ldop, opc, type) \
10171GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10172#define GEN_LDUF(name, ldop, opc, type) \
10173GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10174#define GEN_LDUXF(name, ldop, opc, type) \
10175GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10176#define GEN_LDXF(name, ldop, opc2, opc3, type) \
10177GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10178#define GEN_LDFS(name, ldop, op, type) \
10179GEN_LDF(name, ldop, op | 0x20, type) \
10180GEN_LDUF(name, ldop, op | 0x21, type) \
10181GEN_LDUXF(name, ldop, op | 0x01, type) \
10182GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10183
10184GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10185GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 10186GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
66c3e328 10187GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
05050ee8
AJ
10188GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10189GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10190
10191#undef GEN_STF
10192#undef GEN_STUF
10193#undef GEN_STUXF
10194#undef GEN_STXF
10195#undef GEN_STFS
10196#define GEN_STF(name, stop, opc, type) \
10197GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10198#define GEN_STUF(name, stop, opc, type) \
10199GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10200#define GEN_STUXF(name, stop, opc, type) \
10201GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10202#define GEN_STXF(name, stop, opc2, opc3, type) \
10203GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10204#define GEN_STFS(name, stop, op, type) \
10205GEN_STF(name, stop, op | 0x20, type) \
10206GEN_STUF(name, stop, op | 0x21, type) \
10207GEN_STUXF(name, stop, op | 0x01, type) \
10208GEN_STXF(name, stop, 0x17, op | 0x00, type)
10209
10210GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10211GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10212GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
10213GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10214GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10215
10216#undef GEN_CRLOGIC
10217#define GEN_CRLOGIC(name, tcg_op, opc) \
10218GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10219GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10220GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10221GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10222GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10223GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10224GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10225GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10226GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10227
10228#undef GEN_MAC_HANDLER
10229#define GEN_MAC_HANDLER(name, opc2, opc3) \
10230GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10231GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10232GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10233GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10234GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10235GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10236GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10237GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10238GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10239GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10240GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10241GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10242GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10243GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10244GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10245GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10246GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10247GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10248GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10249GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10250GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10251GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10252GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10253GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10254GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10255GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10256GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10257GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10258GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10259GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10260GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10261GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10262GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10263GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10264GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10265GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10266GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10267GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10268GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10269GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10270GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10271GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10272GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10273
10274#undef GEN_VR_LDX
10275#undef GEN_VR_STX
10276#undef GEN_VR_LVE
10277#undef GEN_VR_STVE
10278#define GEN_VR_LDX(name, opc2, opc3) \
10279GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10280#define GEN_VR_STX(name, opc2, opc3) \
10281GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10282#define GEN_VR_LVE(name, opc2, opc3) \
10283 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10284#define GEN_VR_STVE(name, opc2, opc3) \
10285 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10286GEN_VR_LDX(lvx, 0x07, 0x03),
10287GEN_VR_LDX(lvxl, 0x07, 0x0B),
10288GEN_VR_LVE(bx, 0x07, 0x00),
10289GEN_VR_LVE(hx, 0x07, 0x01),
10290GEN_VR_LVE(wx, 0x07, 0x02),
10291GEN_VR_STX(svx, 0x07, 0x07),
10292GEN_VR_STX(svxl, 0x07, 0x0F),
10293GEN_VR_STVE(bx, 0x07, 0x04),
10294GEN_VR_STVE(hx, 0x07, 0x05),
10295GEN_VR_STVE(wx, 0x07, 0x06),
10296
10297#undef GEN_VX_LOGICAL
10298#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10299GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
111c5f54
TM
10300
10301#undef GEN_VX_LOGICAL_207
10302#define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10303GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10304
5c55ff99
BS
10305GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10306GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10307GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10308GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10309GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
111c5f54
TM
10310GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10311GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10312GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
5c55ff99
BS
10313
10314#undef GEN_VXFORM
10315#define GEN_VXFORM(name, opc2, opc3) \
10316GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
50f5fc0c
TM
10317
10318#undef GEN_VXFORM_207
10319#define GEN_VXFORM_207(name, opc2, opc3) \
10320GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10321
5dffff5a
TM
10322#undef GEN_VXFORM_DUAL
10323#define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10324GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10325
a737d3eb
TM
10326#undef GEN_VXRFORM_DUAL
10327#define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10328GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10329GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10330
5c55ff99
BS
10331GEN_VXFORM(vaddubm, 0, 0),
10332GEN_VXFORM(vadduhm, 0, 1),
10333GEN_VXFORM(vadduwm, 0, 2),
56eabc75 10334GEN_VXFORM_207(vaddudm, 0, 3),
e8f7b27b
TM
10335GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10336GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
5c55ff99 10337GEN_VXFORM(vsubuwm, 0, 18),
56eabc75 10338GEN_VXFORM_207(vsubudm, 0, 19),
5c55ff99
BS
10339GEN_VXFORM(vmaxub, 1, 0),
10340GEN_VXFORM(vmaxuh, 1, 1),
10341GEN_VXFORM(vmaxuw, 1, 2),
8203e31b 10342GEN_VXFORM_207(vmaxud, 1, 3),
5c55ff99
BS
10343GEN_VXFORM(vmaxsb, 1, 4),
10344GEN_VXFORM(vmaxsh, 1, 5),
10345GEN_VXFORM(vmaxsw, 1, 6),
8203e31b 10346GEN_VXFORM_207(vmaxsd, 1, 7),
5c55ff99
BS
10347GEN_VXFORM(vminub, 1, 8),
10348GEN_VXFORM(vminuh, 1, 9),
10349GEN_VXFORM(vminuw, 1, 10),
8203e31b 10350GEN_VXFORM_207(vminud, 1, 11),
5c55ff99
BS
10351GEN_VXFORM(vminsb, 1, 12),
10352GEN_VXFORM(vminsh, 1, 13),
10353GEN_VXFORM(vminsw, 1, 14),
8203e31b 10354GEN_VXFORM_207(vminsd, 1, 15),
5c55ff99
BS
10355GEN_VXFORM(vavgub, 1, 16),
10356GEN_VXFORM(vavguh, 1, 17),
10357GEN_VXFORM(vavguw, 1, 18),
10358GEN_VXFORM(vavgsb, 1, 20),
10359GEN_VXFORM(vavgsh, 1, 21),
10360GEN_VXFORM(vavgsw, 1, 22),
10361GEN_VXFORM(vmrghb, 6, 0),
10362GEN_VXFORM(vmrghh, 6, 1),
10363GEN_VXFORM(vmrghw, 6, 2),
10364GEN_VXFORM(vmrglb, 6, 4),
10365GEN_VXFORM(vmrglh, 6, 5),
10366GEN_VXFORM(vmrglw, 6, 6),
e0ffe77f
TM
10367GEN_VXFORM_207(vmrgew, 6, 30),
10368GEN_VXFORM_207(vmrgow, 6, 26),
5c55ff99
BS
10369GEN_VXFORM(vmuloub, 4, 0),
10370GEN_VXFORM(vmulouh, 4, 1),
953f0f58 10371GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10372GEN_VXFORM(vmulosb, 4, 4),
10373GEN_VXFORM(vmulosh, 4, 5),
63be0936 10374GEN_VXFORM_207(vmulosw, 4, 6),
5c55ff99
BS
10375GEN_VXFORM(vmuleub, 4, 8),
10376GEN_VXFORM(vmuleuh, 4, 9),
63be0936 10377GEN_VXFORM_207(vmuleuw, 4, 10),
5c55ff99
BS
10378GEN_VXFORM(vmulesb, 4, 12),
10379GEN_VXFORM(vmulesh, 4, 13),
63be0936 10380GEN_VXFORM_207(vmulesw, 4, 14),
5c55ff99
BS
10381GEN_VXFORM(vslb, 2, 4),
10382GEN_VXFORM(vslh, 2, 5),
10383GEN_VXFORM(vslw, 2, 6),
2fdf78e6 10384GEN_VXFORM_207(vsld, 2, 23),
5c55ff99
BS
10385GEN_VXFORM(vsrb, 2, 8),
10386GEN_VXFORM(vsrh, 2, 9),
10387GEN_VXFORM(vsrw, 2, 10),
2fdf78e6 10388GEN_VXFORM_207(vsrd, 2, 27),
5c55ff99
BS
10389GEN_VXFORM(vsrab, 2, 12),
10390GEN_VXFORM(vsrah, 2, 13),
10391GEN_VXFORM(vsraw, 2, 14),
2fdf78e6 10392GEN_VXFORM_207(vsrad, 2, 15),
5c55ff99
BS
10393GEN_VXFORM(vslo, 6, 16),
10394GEN_VXFORM(vsro, 6, 17),
10395GEN_VXFORM(vaddcuw, 0, 6),
10396GEN_VXFORM(vsubcuw, 0, 22),
10397GEN_VXFORM(vaddubs, 0, 8),
10398GEN_VXFORM(vadduhs, 0, 9),
10399GEN_VXFORM(vadduws, 0, 10),
10400GEN_VXFORM(vaddsbs, 0, 12),
10401GEN_VXFORM(vaddshs, 0, 13),
10402GEN_VXFORM(vaddsws, 0, 14),
e8f7b27b
TM
10403GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10404GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10405GEN_VXFORM(vsubuws, 0, 26),
10406GEN_VXFORM(vsubsbs, 0, 28),
10407GEN_VXFORM(vsubshs, 0, 29),
10408GEN_VXFORM(vsubsws, 0, 30),
b41da4eb
TM
10409GEN_VXFORM_207(vadduqm, 0, 4),
10410GEN_VXFORM_207(vaddcuq, 0, 5),
10411GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10412GEN_VXFORM_207(vsubuqm, 0, 20),
10413GEN_VXFORM_207(vsubcuq, 0, 21),
10414GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
5c55ff99
BS
10415GEN_VXFORM(vrlb, 2, 0),
10416GEN_VXFORM(vrlh, 2, 1),
10417GEN_VXFORM(vrlw, 2, 2),
2fdf78e6 10418GEN_VXFORM_207(vrld, 2, 3),
5c55ff99
BS
10419GEN_VXFORM(vsl, 2, 7),
10420GEN_VXFORM(vsr, 2, 11),
10421GEN_VXFORM(vpkuhum, 7, 0),
10422GEN_VXFORM(vpkuwum, 7, 1),
024215b2 10423GEN_VXFORM_207(vpkudum, 7, 17),
5c55ff99
BS
10424GEN_VXFORM(vpkuhus, 7, 2),
10425GEN_VXFORM(vpkuwus, 7, 3),
024215b2 10426GEN_VXFORM_207(vpkudus, 7, 19),
5c55ff99
BS
10427GEN_VXFORM(vpkshus, 7, 4),
10428GEN_VXFORM(vpkswus, 7, 5),
024215b2 10429GEN_VXFORM_207(vpksdus, 7, 21),
5c55ff99
BS
10430GEN_VXFORM(vpkshss, 7, 6),
10431GEN_VXFORM(vpkswss, 7, 7),
024215b2 10432GEN_VXFORM_207(vpksdss, 7, 23),
5c55ff99
BS
10433GEN_VXFORM(vpkpx, 7, 12),
10434GEN_VXFORM(vsum4ubs, 4, 24),
10435GEN_VXFORM(vsum4sbs, 4, 28),
10436GEN_VXFORM(vsum4shs, 4, 25),
10437GEN_VXFORM(vsum2sws, 4, 26),
10438GEN_VXFORM(vsumsws, 4, 30),
10439GEN_VXFORM(vaddfp, 5, 0),
10440GEN_VXFORM(vsubfp, 5, 1),
10441GEN_VXFORM(vmaxfp, 5, 16),
10442GEN_VXFORM(vminfp, 5, 17),
10443
10444#undef GEN_VXRFORM1
10445#undef GEN_VXRFORM
10446#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10447 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10448#define GEN_VXRFORM(name, opc2, opc3) \
10449 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10450 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10451GEN_VXRFORM(vcmpequb, 3, 0)
10452GEN_VXRFORM(vcmpequh, 3, 1)
10453GEN_VXRFORM(vcmpequw, 3, 2)
10454GEN_VXRFORM(vcmpgtsb, 3, 12)
10455GEN_VXRFORM(vcmpgtsh, 3, 13)
10456GEN_VXRFORM(vcmpgtsw, 3, 14)
10457GEN_VXRFORM(vcmpgtub, 3, 8)
10458GEN_VXRFORM(vcmpgtuh, 3, 9)
10459GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 10460GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
5c55ff99 10461GEN_VXRFORM(vcmpgefp, 3, 7)
6f3dab41
TM
10462GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10463GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
5c55ff99
BS
10464
10465#undef GEN_VXFORM_SIMM
10466#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10467 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10468GEN_VXFORM_SIMM(vspltisb, 6, 12),
10469GEN_VXFORM_SIMM(vspltish, 6, 13),
10470GEN_VXFORM_SIMM(vspltisw, 6, 14),
10471
10472#undef GEN_VXFORM_NOA
10473#define GEN_VXFORM_NOA(name, opc2, opc3) \
10474 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10475GEN_VXFORM_NOA(vupkhsb, 7, 8),
10476GEN_VXFORM_NOA(vupkhsh, 7, 9),
4430e076 10477GEN_VXFORM_207(vupkhsw, 7, 25),
5c55ff99
BS
10478GEN_VXFORM_NOA(vupklsb, 7, 10),
10479GEN_VXFORM_NOA(vupklsh, 7, 11),
4430e076 10480GEN_VXFORM_207(vupklsw, 7, 27),
5c55ff99
BS
10481GEN_VXFORM_NOA(vupkhpx, 7, 13),
10482GEN_VXFORM_NOA(vupklpx, 7, 15),
10483GEN_VXFORM_NOA(vrefp, 5, 4),
10484GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10485GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99
BS
10486GEN_VXFORM_NOA(vlogefp, 5, 7),
10487GEN_VXFORM_NOA(vrfim, 5, 8),
10488GEN_VXFORM_NOA(vrfin, 5, 9),
10489GEN_VXFORM_NOA(vrfip, 5, 10),
10490GEN_VXFORM_NOA(vrfiz, 5, 11),
10491
10492#undef GEN_VXFORM_UIMM
10493#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10494 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10495GEN_VXFORM_UIMM(vspltb, 6, 8),
10496GEN_VXFORM_UIMM(vsplth, 6, 9),
10497GEN_VXFORM_UIMM(vspltw, 6, 10),
10498GEN_VXFORM_UIMM(vcfux, 5, 12),
10499GEN_VXFORM_UIMM(vcfsx, 5, 13),
10500GEN_VXFORM_UIMM(vctuxs, 5, 14),
10501GEN_VXFORM_UIMM(vctsxs, 5, 15),
10502
10503#undef GEN_VAFORM_PAIRED
10504#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10505 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10506GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10507GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10508GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10509GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10510GEN_VAFORM_PAIRED(vsel, vperm, 21),
10511GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10512
e13500b3
TM
10513GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10514GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10515GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10516GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10517
4d82038e 10518GEN_VXFORM_207(vbpermq, 6, 21),
f1064f61 10519GEN_VXFORM_207(vgbbd, 6, 20),
b8476fc7
TM
10520GEN_VXFORM_207(vpmsumb, 4, 16),
10521GEN_VXFORM_207(vpmsumh, 4, 17),
10522GEN_VXFORM_207(vpmsumw, 4, 18),
10523GEN_VXFORM_207(vpmsumd, 4, 19),
f293f04a 10524
557d52fa
TM
10525GEN_VXFORM_207(vsbox, 4, 23),
10526
10527GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10528GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10529
57354f8f
TM
10530GEN_VXFORM_207(vshasigmaw, 1, 26),
10531GEN_VXFORM_207(vshasigmad, 1, 27),
10532
ac174549
TM
10533GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10534
fa1832d7 10535GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10536GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10537GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10538GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10539GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10540GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10541GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10542
9231ba9e 10543GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10544GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10545GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10546GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10547GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10548
f5c0f7f9
TM
10549GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10550GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10551GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10552#if defined(TARGET_PPC64)
10553GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10554GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10555#endif
10556
df020ce0
TM
10557#undef GEN_XX2FORM
10558#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10559GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10560GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10561
10562#undef GEN_XX3FORM
10563#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10564GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10565GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10566GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10567GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10568
354a6dec
TM
10569#undef GEN_XX3_RC_FORM
10570#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10571GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10572GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10573GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10574GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10575GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10576GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10577GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10578GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10579
cd73f2c9
TM
10580#undef GEN_XX3FORM_DM
10581#define GEN_XX3FORM_DM(name, opc2, opc3) \
10582GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10583GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10584GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10585GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10586GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10587GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10588GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10589GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10590GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10591GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10592GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10593GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10594GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10595GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10596GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10597GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10598
df020ce0
TM
10599GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10600GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10601GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10602GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10603
be574920
TM
10604GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10605GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10606GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10607GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10608GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10609GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10610GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10611GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 10612
ee6e02c0
TM
10613GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10614GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 10615GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 10616GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 10617GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 10618GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 10619GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 10620GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 10621GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
10622GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10623GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10624GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10625GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10626GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10627GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10628GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10629GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
4f17e9c7
TM
10630GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10631GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
10632GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10633GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568 10634GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
7ee19fb9 10635GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
ed8ac568 10636GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
7ee19fb9 10637GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
5177d2ca
TM
10638GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10639GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10640GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10641GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10642GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10643GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
10644GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10645GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10646GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10647GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10648GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 10649
3fd0aadf
TM
10650GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10651GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 10652GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 10653GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 10654GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
3d1140bf 10655GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
cea4e574 10656GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
968e76bc 10657GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
f53f81e0
TM
10658GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
10659GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
10660GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
10661GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
10662GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
10663GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
10664GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
10665GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
74698350
TM
10666GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
10667GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
3fd0aadf 10668
ee6e02c0
TM
10669GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10670GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 10671GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 10672GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 10673GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 10674GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 10675GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 10676GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 10677GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
10678GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10679GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10680GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10681GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10682GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10683GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10684GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10685GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
10686GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10687GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
10688GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10689GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10690GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 10691GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
10692GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10693GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10694GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10695GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10696GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10697GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10698GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10699GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
10700GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10701GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10702GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10703GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10704GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
10705
10706GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10707GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 10708GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 10709GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 10710GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 10711GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 10712GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 10713GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 10714GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
10715GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10716GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10717GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10718GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10719GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10720GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10721GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10722GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
10723GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10724GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
10725GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10726GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10727GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 10728GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
10729GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10730GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10731GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10732GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10733GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10734GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10735GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10736GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
10737GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10738GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10739GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10740GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10741GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 10742
79ca8a6a
TM
10743#undef VSX_LOGICAL
10744#define VSX_LOGICAL(name, opc2, opc3, fl2) \
10745GEN_XX3FORM(name, opc2, opc3, fl2)
10746
10747VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10748VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10749VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10750VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10751VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
67a33f37
TM
10752VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
10753VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
10754VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
ce577d2e
TM
10755GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10756GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 10757GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 10758GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 10759
551e3ef7
TM
10760#define GEN_XXSEL_ROW(opc3) \
10761GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10762GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10763GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10764GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10765GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10766GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10767GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10768GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10769
10770GEN_XXSEL_ROW(0x00)
10771GEN_XXSEL_ROW(0x01)
10772GEN_XXSEL_ROW(0x02)
10773GEN_XXSEL_ROW(0x03)
10774GEN_XXSEL_ROW(0x04)
10775GEN_XXSEL_ROW(0x05)
10776GEN_XXSEL_ROW(0x06)
10777GEN_XXSEL_ROW(0x07)
10778GEN_XXSEL_ROW(0x08)
10779GEN_XXSEL_ROW(0x09)
10780GEN_XXSEL_ROW(0x0A)
10781GEN_XXSEL_ROW(0x0B)
10782GEN_XXSEL_ROW(0x0C)
10783GEN_XXSEL_ROW(0x0D)
10784GEN_XXSEL_ROW(0x0E)
10785GEN_XXSEL_ROW(0x0F)
10786GEN_XXSEL_ROW(0x10)
10787GEN_XXSEL_ROW(0x11)
10788GEN_XXSEL_ROW(0x12)
10789GEN_XXSEL_ROW(0x13)
10790GEN_XXSEL_ROW(0x14)
10791GEN_XXSEL_ROW(0x15)
10792GEN_XXSEL_ROW(0x16)
10793GEN_XXSEL_ROW(0x17)
10794GEN_XXSEL_ROW(0x18)
10795GEN_XXSEL_ROW(0x19)
10796GEN_XXSEL_ROW(0x1A)
10797GEN_XXSEL_ROW(0x1B)
10798GEN_XXSEL_ROW(0x1C)
10799GEN_XXSEL_ROW(0x1D)
10800GEN_XXSEL_ROW(0x1E)
10801GEN_XXSEL_ROW(0x1F)
10802
cd73f2c9
TM
10803GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
10804
275e35c6
TM
10805#undef GEN_DFP_T_A_B_Rc
10806#undef GEN_DFP_BF_A_B
10807#undef GEN_DFP_BF_A_DCM
10808#undef GEN_DFP_T_B_U32_U32_Rc
10809#undef GEN_DFP_T_A_B_I32_Rc
10810#undef GEN_DFP_T_B_Rc
10811#undef GEN_DFP_T_FPR_I32_Rc
10812
10813#define _GEN_DFP_LONG(name, op1, op2, mask) \
10814GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
10815
10816#define _GEN_DFP_LONGx2(name, op1, op2, mask) \
10817GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10818GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10819
10820#define _GEN_DFP_LONGx4(name, op1, op2, mask) \
10821GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10822GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10823GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10824GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10825
10826#define _GEN_DFP_QUAD(name, op1, op2, mask) \
10827GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
10828
10829#define _GEN_DFP_QUADx2(name, op1, op2, mask) \
10830GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10831GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10832
10833#define _GEN_DFP_QUADx4(name, op1, op2, mask) \
10834GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10835GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10836GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10837GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10838
10839#define GEN_DFP_T_A_B_Rc(name, op1, op2) \
10840_GEN_DFP_LONG(name, op1, op2, 0x00000000)
10841
10842#define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
10843_GEN_DFP_QUAD(name, op1, op2, 0x00210800)
10844
10845#define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
10846_GEN_DFP_QUAD(name, op1, op2, 0x00200800)
10847
10848#define GEN_DFP_T_B_Rc(name, op1, op2) \
10849_GEN_DFP_LONG(name, op1, op2, 0x001F0000)
10850
10851#define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
10852_GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
10853
10854#define GEN_DFP_Tp_B_Rc(name, op1, op2) \
10855_GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
10856
10857#define GEN_DFP_T_Bp_Rc(name, op1, op2) \
10858_GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
10859
10860#define GEN_DFP_BF_A_B(name, op1, op2) \
10861_GEN_DFP_LONG(name, op1, op2, 0x00000001)
10862
10863#define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
10864_GEN_DFP_QUAD(name, op1, op2, 0x00610801)
10865
10866#define GEN_DFP_BF_A_Bp(name, op1, op2) \
10867_GEN_DFP_QUAD(name, op1, op2, 0x00600801)
10868
10869#define GEN_DFP_BF_A_DCM(name, op1, op2) \
10870_GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
10871
10872#define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
10873_GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
10874
10875#define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
10876_GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
10877
10878#define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
10879_GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
10880
10881#define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
10882_GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
10883
10884#define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
10885_GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
10886
10887#define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
10888_GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
10889
10890#define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
10891_GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
10892
10893#define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
10894_GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
10895
10896#define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
10897_GEN_DFP_LONG(name, op1, op2, 0x00070000)
10898
10899#define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
10900_GEN_DFP_QUAD(name, op1, op2, 0x00270800)
10901
10902#define GEN_DFP_S_T_B_Rc(name, op1, op2) \
10903_GEN_DFP_LONG(name, op1, op2, 0x000F0000)
10904
10905#define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
10906_GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
10907
10908#define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
10909_GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
10910
10911#define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
10912_GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
10913
a9d7ba03
TM
10914GEN_DFP_T_A_B_Rc(dadd, 0x02, 0x00),
10915GEN_DFP_Tp_Ap_Bp_Rc(daddq, 0x02, 0x00),
2128f8a5
TM
10916GEN_DFP_T_A_B_Rc(dsub, 0x02, 0x10),
10917GEN_DFP_Tp_Ap_Bp_Rc(dsubq, 0x02, 0x10),
8de6a1cc
TM
10918GEN_DFP_T_A_B_Rc(dmul, 0x02, 0x01),
10919GEN_DFP_Tp_Ap_Bp_Rc(dmulq, 0x02, 0x01),
9024ff40
TM
10920GEN_DFP_T_A_B_Rc(ddiv, 0x02, 0x11),
10921GEN_DFP_Tp_Ap_Bp_Rc(ddivq, 0x02, 0x11),
5833505b
TM
10922GEN_DFP_BF_A_B(dcmpu, 0x02, 0x14),
10923GEN_DFP_BF_Ap_Bp(dcmpuq, 0x02, 0x14),
10924GEN_DFP_BF_A_B(dcmpo, 0x02, 0x04),
10925GEN_DFP_BF_Ap_Bp(dcmpoq, 0x02, 0x04),
e601c1ee
TM
10926GEN_DFP_BF_A_DCM(dtstdc, 0x02, 0x06),
10927GEN_DFP_BF_Ap_DCM(dtstdcq, 0x02, 0x06),
1bf9c0e1
TM
10928GEN_DFP_BF_A_DCM(dtstdg, 0x02, 0x07),
10929GEN_DFP_BF_Ap_DCM(dtstdgq, 0x02, 0x07),
f3d2b0bc
TM
10930GEN_DFP_BF_A_B(dtstex, 0x02, 0x05),
10931GEN_DFP_BF_Ap_Bp(dtstexq, 0x02, 0x05),
f6022a76
TM
10932GEN_DFP_BF_A_B(dtstsf, 0x02, 0x15),
10933GEN_DFP_BF_A_Bp(dtstsfq, 0x02, 0x15),
5826ebe2
TM
10934GEN_DFP_TE_T_B_RMC_Rc(dquai, 0x03, 0x02),
10935GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq, 0x03, 0x02),
10936GEN_DFP_T_A_B_RMC_Rc(dqua, 0x03, 0x00),
10937GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq, 0x03, 0x00),
512918aa
TM
10938GEN_DFP_T_A_B_RMC_Rc(drrnd, 0x03, 0x01),
10939GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq, 0x03, 0x01),
97c0d930
TM
10940GEN_DFP_R_T_B_RMC_Rc(drintx, 0x03, 0x03),
10941GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq, 0x03, 0x03),
10942GEN_DFP_R_T_B_RMC_Rc(drintn, 0x03, 0x07),
10943GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq, 0x03, 0x07),
290d9ee5
TM
10944GEN_DFP_T_B_Rc(dctdp, 0x02, 0x08),
10945GEN_DFP_Tp_B_Rc(dctqpq, 0x02, 0x08),
ca603eb4
TM
10946GEN_DFP_T_B_Rc(drsp, 0x02, 0x18),
10947GEN_DFP_Tp_Bp_Rc(drdpq, 0x02, 0x18),
f1214193
TM
10948GEN_DFP_T_B_Rc(dcffix, 0x02, 0x19),
10949GEN_DFP_Tp_B_Rc(dcffixq, 0x02, 0x19),
bea0dd79
TM
10950GEN_DFP_T_B_Rc(dctfix, 0x02, 0x09),
10951GEN_DFP_T_Bp_Rc(dctfixq, 0x02, 0x09),
7796676f
TM
10952GEN_DFP_SP_T_B_Rc(ddedpd, 0x02, 0x0a),
10953GEN_DFP_SP_Tp_Bp_Rc(ddedpdq, 0x02, 0x0a),
013c3ac0
TM
10954GEN_DFP_S_T_B_Rc(denbcd, 0x02, 0x1a),
10955GEN_DFP_S_Tp_Bp_Rc(denbcdq, 0x02, 0x1a),
e8a48460
TM
10956GEN_DFP_T_B_Rc(dxex, 0x02, 0x0b),
10957GEN_DFP_T_Bp_Rc(dxexq, 0x02, 0x0b),
297666eb
TM
10958GEN_DFP_T_A_B_Rc(diex, 0x02, 0x1b),
10959GEN_DFP_Tp_A_Bp_Rc(diexq, 0x02, 0x1b),
804e654a
TM
10960GEN_DFP_T_A_SH_Rc(dscli, 0x02, 0x02),
10961GEN_DFP_Tp_Ap_SH_Rc(dscliq, 0x02, 0x02),
10962GEN_DFP_T_A_SH_Rc(dscri, 0x02, 0x03),
10963GEN_DFP_Tp_Ap_SH_Rc(dscriq, 0x02, 0x03),
10964
5c55ff99 10965#undef GEN_SPE
70560da7
FC
10966#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
10967 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
10968GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10969GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10970GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10971GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10972GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10973GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10974GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10975GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
10976GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
10977GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
10978GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10979GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10980GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10981GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
10982GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
10983GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
10984GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
10985GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10986GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10987GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10988GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10989GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10990GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
10991GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
10992GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10993GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10994GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
10995GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
10996GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
10997
10998GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10999GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11000GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11001GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11002GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11003GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11004GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11005GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11006GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11007GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11008GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11009GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11010GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11011GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11012
11013GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11014GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11015GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11016GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11017GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11018GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11019GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11020GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11021GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11022GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11023GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11024GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11025GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11026GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11027
11028GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11029GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11030GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11031GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11032GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11033GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11034GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11035GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11036GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11037GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11038GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11039GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11040GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11041GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11042GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11043GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
11044
11045#undef GEN_SPEOP_LDST
11046#define GEN_SPEOP_LDST(name, opc2, sh) \
11047GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11048GEN_SPEOP_LDST(evldd, 0x00, 3),
11049GEN_SPEOP_LDST(evldw, 0x01, 3),
11050GEN_SPEOP_LDST(evldh, 0x02, 3),
11051GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11052GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11053GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11054GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11055GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11056GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11057GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11058GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11059
11060GEN_SPEOP_LDST(evstdd, 0x10, 3),
11061GEN_SPEOP_LDST(evstdw, 0x11, 3),
11062GEN_SPEOP_LDST(evstdh, 0x12, 3),
11063GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11064GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11065GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11066GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
11067};
11068
0411a972 11069#include "helper_regs.h"
a1389542 11070#include "translate_init.c"
79aceca5 11071
9a64fbe4 11072/*****************************************************************************/
3fc6c082 11073/* Misc PowerPC helpers */
878096ee
AF
11074void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11075 int flags)
79aceca5 11076{
3fc6c082
FB
11077#define RGPL 4
11078#define RFPL 4
3fc6c082 11079
878096ee
AF
11080 PowerPCCPU *cpu = POWERPC_CPU(cs);
11081 CPUPPCState *env = &cpu->env;
79aceca5
FB
11082 int i;
11083
90e189ec 11084 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9a78eead 11085 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
da91a00f 11086 env->nip, env->lr, env->ctr, cpu_read_xer(env));
90e189ec
BS
11087 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
11088 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
11089 env->hflags, env->mmu_idx);
d9bce9d9 11090#if !defined(NO_TIMER_DUMP)
9a78eead 11091 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 11092#if !defined(CONFIG_USER_ONLY)
9a78eead 11093 " DECR %08" PRIu32
76a66253
JM
11094#endif
11095 "\n",
077fc206 11096 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
11097#if !defined(CONFIG_USER_ONLY)
11098 , cpu_ppc_load_decr(env)
11099#endif
11100 );
077fc206 11101#endif
76a66253 11102 for (i = 0; i < 32; i++) {
3fc6c082
FB
11103 if ((i & (RGPL - 1)) == 0)
11104 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 11105 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 11106 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 11107 cpu_fprintf(f, "\n");
76a66253 11108 }
3fc6c082 11109 cpu_fprintf(f, "CR ");
76a66253 11110 for (i = 0; i < 8; i++)
7fe48483
FB
11111 cpu_fprintf(f, "%01x", env->crf[i]);
11112 cpu_fprintf(f, " [");
76a66253
JM
11113 for (i = 0; i < 8; i++) {
11114 char a = '-';
11115 if (env->crf[i] & 0x08)
11116 a = 'L';
11117 else if (env->crf[i] & 0x04)
11118 a = 'G';
11119 else if (env->crf[i] & 0x02)
11120 a = 'E';
7fe48483 11121 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 11122 }
90e189ec
BS
11123 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11124 env->reserve_addr);
3fc6c082
FB
11125 for (i = 0; i < 32; i++) {
11126 if ((i & (RFPL - 1)) == 0)
11127 cpu_fprintf(f, "FPR%02d", i);
26a76461 11128 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 11129 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 11130 cpu_fprintf(f, "\n");
79aceca5 11131 }
30304420 11132 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 11133#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
11134 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11135 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11136 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11137 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11138
11139 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11140 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11141 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11142 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11143
11144 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11145 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11146 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11147 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11148
11149 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11150 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11151 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11152 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11153 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11154
11155 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11156 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11157 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11158 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11159
11160 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11161 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11162 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11163 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11164
11165 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11166 " EPR " TARGET_FMT_lx "\n",
11167 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11168 env->spr[SPR_BOOKE_EPR]);
11169
11170 /* FSL-specific */
11171 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11172 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11173 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11174 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11175
11176 /*
11177 * IVORs are left out as they are large and do not change often --
11178 * they can be read with "p $ivor0", "p $ivor1", etc.
11179 */
11180 }
11181
697ab892
DG
11182#if defined(TARGET_PPC64)
11183 if (env->flags & POWERPC_FLAG_CFAR) {
11184 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11185 }
11186#endif
11187
90dc8812
SW
11188 switch (env->mmu_model) {
11189 case POWERPC_MMU_32B:
11190 case POWERPC_MMU_601:
11191 case POWERPC_MMU_SOFT_6xx:
11192 case POWERPC_MMU_SOFT_74xx:
11193#if defined(TARGET_PPC64)
90dc8812 11194 case POWERPC_MMU_64B:
ca480de6
AB
11195 case POWERPC_MMU_2_06:
11196 case POWERPC_MMU_2_06a:
11197 case POWERPC_MMU_2_06d:
90dc8812 11198#endif
ca480de6
AB
11199 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11200 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11201 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 11202 break;
01662f3e 11203 case POWERPC_MMU_BOOKE206:
90dc8812
SW
11204 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11205 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11206 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11207 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11208
11209 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11210 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11211 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11212 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11213
11214 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11215 " TLB1CFG " TARGET_FMT_lx "\n",
11216 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11217 env->spr[SPR_BOOKE_TLB1CFG]);
11218 break;
11219 default:
11220 break;
11221 }
f2e63a42 11222#endif
79aceca5 11223
3fc6c082
FB
11224#undef RGPL
11225#undef RFPL
79aceca5
FB
11226}
11227
878096ee
AF
11228void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11229 fprintf_function cpu_fprintf, int flags)
76a66253
JM
11230{
11231#if defined(DO_PPC_STATISTICS)
878096ee 11232 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 11233 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
11234 int op1, op2, op3;
11235
878096ee 11236 t1 = cpu->env.opcodes;
76a66253
JM
11237 for (op1 = 0; op1 < 64; op1++) {
11238 handler = t1[op1];
11239 if (is_indirect_opcode(handler)) {
11240 t2 = ind_table(handler);
11241 for (op2 = 0; op2 < 32; op2++) {
11242 handler = t2[op2];
11243 if (is_indirect_opcode(handler)) {
11244 t3 = ind_table(handler);
11245 for (op3 = 0; op3 < 32; op3++) {
11246 handler = t3[op3];
11247 if (handler->count == 0)
11248 continue;
11249 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 11250 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11251 op1, op2, op3, op1, (op3 << 5) | op2,
11252 handler->oname,
11253 handler->count, handler->count);
11254 }
11255 } else {
11256 if (handler->count == 0)
11257 continue;
11258 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 11259 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11260 op1, op2, op1, op2, handler->oname,
11261 handler->count, handler->count);
11262 }
11263 }
11264 } else {
11265 if (handler->count == 0)
11266 continue;
0bfcd599
BS
11267 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11268 " %" PRId64 "\n",
76a66253
JM
11269 op1, op1, handler->oname,
11270 handler->count, handler->count);
11271 }
11272 }
11273#endif
11274}
11275
9a64fbe4 11276/*****************************************************************************/
213fe1f5 11277static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
636aa200 11278 TranslationBlock *tb,
213fe1f5 11279 bool search_pc)
79aceca5 11280{
ed2803da 11281 CPUState *cs = CPU(cpu);
213fe1f5 11282 CPUPPCState *env = &cpu->env;
9fddaa0c 11283 DisasContext ctx, *ctxp = &ctx;
c227f099 11284 opc_handler_t **table, *handler;
0fa85d43 11285 target_ulong pc_start;
79aceca5 11286 uint16_t *gen_opc_end;
a1d1bb31 11287 CPUBreakpoint *bp;
79aceca5 11288 int j, lj = -1;
2e70f6ef
PB
11289 int num_insns;
11290 int max_insns;
79aceca5
FB
11291
11292 pc_start = tb->pc;
92414b31 11293 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
046d6672 11294 ctx.nip = pc_start;
79aceca5 11295 ctx.tb = tb;
e1833e1f 11296 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 11297 ctx.spr_cb = env->spr_cb;
76db3ba4 11298 ctx.mem_idx = env->mmu_idx;
7d08d856
AJ
11299 ctx.insns_flags = env->insns_flags;
11300 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
11301 ctx.access_type = -1;
11302 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
e22c357b 11303 ctx.default_tcg_memop_mask = ctx.le_mode ? MO_LE : MO_BE;
d9bce9d9 11304#if defined(TARGET_PPC64)
e42a61f1 11305 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 11306 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 11307#endif
3cc62370 11308 ctx.fpu_enabled = msr_fp;
a9d9eb8f 11309 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
11310 ctx.spe_enabled = msr_spe;
11311 else
11312 ctx.spe_enabled = 0;
a9d9eb8f
JM
11313 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11314 ctx.altivec_enabled = msr_vr;
11315 else
11316 ctx.altivec_enabled = 0;
1f29871c
TM
11317 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11318 ctx.vsx_enabled = msr_vsx;
11319 } else {
11320 ctx.vsx_enabled = 0;
11321 }
d26bfc9a 11322 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 11323 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 11324 else
8cbcb4fa 11325 ctx.singlestep_enabled = 0;
d26bfc9a 11326 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 11327 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 11328 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 11329 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 11330 }
3fc6c082 11331#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
11332 /* Single step trace mode */
11333 msr_se = 1;
11334#endif
2e70f6ef
PB
11335 num_insns = 0;
11336 max_insns = tb->cflags & CF_COUNT_MASK;
11337 if (max_insns == 0)
11338 max_insns = CF_COUNT_MASK;
11339
806f352d 11340 gen_tb_start();
3de31797 11341 tcg_clear_temp_count();
9a64fbe4 11342 /* Set env in case of segfault during code fetch */
efd7f486
EV
11343 while (ctx.exception == POWERPC_EXCP_NONE
11344 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
f0c3c505
AF
11345 if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) {
11346 QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {
a1d1bb31 11347 if (bp->pc == ctx.nip) {
e06fcd75 11348 gen_debug_exception(ctxp);
ea4e754f
FB
11349 break;
11350 }
11351 }
11352 }
76a66253 11353 if (unlikely(search_pc)) {
92414b31 11354 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
79aceca5
FB
11355 if (lj < j) {
11356 lj++;
11357 while (lj < j)
ab1103de 11358 tcg_ctx.gen_opc_instr_start[lj++] = 0;
79aceca5 11359 }
25983cad 11360 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
ab1103de 11361 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 11362 tcg_ctx.gen_opc_icount[lj] = num_insns;
79aceca5 11363 }
d12d51d5 11364 LOG_DISAS("----------------\n");
90e189ec 11365 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 11366 ctx.nip, ctx.mem_idx, (int)msr_ir);
2e70f6ef
PB
11367 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
11368 gen_io_start();
e22c357b 11369 if (unlikely(need_byteswap(&ctx))) {
2f5a189c 11370 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 11371 } else {
2f5a189c 11372 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 11373 }
d12d51d5 11374 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 11375 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 11376 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
fdefe51c 11377 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
731c54f8 11378 tcg_gen_debug_insn_start(ctx.nip);
fdefe51c 11379 }
046d6672 11380 ctx.nip += 4;
3fc6c082 11381 table = env->opcodes;
2e70f6ef 11382 num_insns++;
79aceca5
FB
11383 handler = table[opc1(ctx.opcode)];
11384 if (is_indirect_opcode(handler)) {
11385 table = ind_table(handler);
11386 handler = table[opc2(ctx.opcode)];
11387 if (is_indirect_opcode(handler)) {
11388 table = ind_table(handler);
11389 handler = table[opc3(ctx.opcode)];
11390 }
11391 }
11392 /* Is opcode *REALLY* valid ? */
76a66253 11393 if (unlikely(handler->handler == &gen_invalid)) {
93fcfe39
AL
11394 if (qemu_log_enabled()) {
11395 qemu_log("invalid/unsupported opcode: "
90e189ec
BS
11396 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11397 opc1(ctx.opcode), opc2(ctx.opcode),
11398 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
4b3686fa 11399 }
76a66253 11400 } else {
70560da7
FC
11401 uint32_t inval;
11402
11403 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11404 inval = handler->inval2;
11405 } else {
11406 inval = handler->inval1;
11407 }
11408
11409 if (unlikely((ctx.opcode & inval) != 0)) {
93fcfe39
AL
11410 if (qemu_log_enabled()) {
11411 qemu_log("invalid bits: %08x for opcode: "
90e189ec 11412 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
70560da7 11413 ctx.opcode & inval, opc1(ctx.opcode),
90e189ec
BS
11414 opc2(ctx.opcode), opc3(ctx.opcode),
11415 ctx.opcode, ctx.nip - 4);
76a66253 11416 }
e06fcd75 11417 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 11418 break;
79aceca5 11419 }
79aceca5 11420 }
4b3686fa 11421 (*(handler->handler))(&ctx);
76a66253
JM
11422#if defined(DO_PPC_STATISTICS)
11423 handler->count++;
11424#endif
9a64fbe4 11425 /* Check trace mode exceptions */
8cbcb4fa
AJ
11426 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11427 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11428 ctx.exception != POWERPC_SYSCALL &&
11429 ctx.exception != POWERPC_EXCP_TRAP &&
11430 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 11431 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 11432 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 11433 (cs->singlestep_enabled) ||
1b530a6d 11434 singlestep ||
2e70f6ef 11435 num_insns >= max_insns)) {
d26bfc9a
JM
11436 /* if we reach a page boundary or are single stepping, stop
11437 * generation
11438 */
8dd4983c 11439 break;
76a66253 11440 }
3de31797
AG
11441 if (tcg_check_temp_count()) {
11442 fprintf(stderr, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11443 opc1(ctx.opcode), opc2(ctx.opcode), opc3(ctx.opcode),
11444 ctx.opcode);
11445 exit(1);
11446 }
3fc6c082 11447 }
2e70f6ef
PB
11448 if (tb->cflags & CF_LAST_IO)
11449 gen_io_end();
e1833e1f 11450 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 11451 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 11452 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 11453 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 11454 gen_debug_exception(ctxp);
8cbcb4fa 11455 }
76a66253 11456 /* Generate the return instruction */
57fec1fe 11457 tcg_gen_exit_tb(0);
9a64fbe4 11458 }
806f352d 11459 gen_tb_end(tb, num_insns);
efd7f486 11460 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
76a66253 11461 if (unlikely(search_pc)) {
92414b31 11462 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9a64fbe4
FB
11463 lj++;
11464 while (lj <= j)
ab1103de 11465 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9a64fbe4 11466 } else {
046d6672 11467 tb->size = ctx.nip - pc_start;
2e70f6ef 11468 tb->icount = num_insns;
9a64fbe4 11469 }
d9bce9d9 11470#if defined(DEBUG_DISAS)
8fec2b8c 11471 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 11472 int flags;
237c0af0 11473 flags = env->bfd_mach;
76db3ba4 11474 flags |= ctx.le_mode << 16;
93fcfe39 11475 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 11476 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
93fcfe39 11477 qemu_log("\n");
9fddaa0c 11478 }
79aceca5 11479#endif
79aceca5
FB
11480}
11481
1328c2bf 11482void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11483{
213fe1f5 11484 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
79aceca5
FB
11485}
11486
1328c2bf 11487void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11488{
213fe1f5 11489 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
79aceca5 11490}
d2856f1a 11491
1328c2bf 11492void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
d2856f1a 11493{
25983cad 11494 env->nip = tcg_ctx.gen_opc_pc[pc_pos];
d2856f1a 11495}