]> git.ipfire.org Git - thirdparty/qemu.git/blame - target-ppc/translate.c
cpu: Move breakpoints field from CPU_COMMON to CPUState
[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"
79aceca5 25
a7812ae4
PB
26#include "helper.h"
27#define GEN_HELPER 1
28#include "helper.h"
29
8cbcb4fa
AJ
30#define CPU_SINGLE_STEP 0x1
31#define CPU_BRANCH_STEP 0x2
32#define GDBSTUB_SINGLE_STEP 0x4
33
a750fc0b 34/* Include definitions for instructions classes and implementations flags */
9fddaa0c 35//#define PPC_DEBUG_DISAS
76a66253 36//#define DO_PPC_STATISTICS
79aceca5 37
d12d51d5 38#ifdef PPC_DEBUG_DISAS
93fcfe39 39# define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
d12d51d5
AL
40#else
41# define LOG_DISAS(...) do { } while (0)
42#endif
a750fc0b
JM
43/*****************************************************************************/
44/* Code translation helpers */
c53be334 45
f78fb44e 46/* global register indexes */
a7812ae4 47static TCGv_ptr cpu_env;
1d542695 48static char cpu_reg_names[10*3 + 22*4 /* GPR */
f78fb44e 49#if !defined(TARGET_PPC64)
1d542695 50 + 10*4 + 22*5 /* SPE GPRh */
f78fb44e 51#endif
a5e26afa 52 + 10*4 + 22*5 /* FPR */
47e4661c 53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
472b24ce 54 + 10*5 + 22*6 /* VSR */
47e4661c 55 + 8*5 /* CRF */];
f78fb44e
AJ
56static TCGv cpu_gpr[32];
57#if !defined(TARGET_PPC64)
58static TCGv cpu_gprh[32];
59#endif
a7812ae4
PB
60static TCGv_i64 cpu_fpr[32];
61static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
472b24ce 62static TCGv_i64 cpu_vsr[32];
a7812ae4 63static TCGv_i32 cpu_crf[8];
bd568f18 64static TCGv cpu_nip;
6527f6ea 65static TCGv cpu_msr;
cfdcd37a
AJ
66static TCGv cpu_ctr;
67static TCGv cpu_lr;
697ab892
DG
68#if defined(TARGET_PPC64)
69static TCGv cpu_cfar;
70#endif
da91a00f 71static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
cf360a32 72static TCGv cpu_reserve;
30304420 73static TCGv cpu_fpscr;
a7859e89 74static TCGv_i32 cpu_access_type;
f78fb44e 75
022c62cb 76#include "exec/gen-icount.h"
2e70f6ef
PB
77
78void ppc_translate_init(void)
79{
f78fb44e
AJ
80 int i;
81 char* p;
2dc766da 82 size_t cpu_reg_names_size;
b2437bf2 83 static int done_init = 0;
f78fb44e 84
2e70f6ef
PB
85 if (done_init)
86 return;
f78fb44e 87
a7812ae4 88 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
a7812ae4 89
f78fb44e 90 p = cpu_reg_names;
2dc766da 91 cpu_reg_names_size = sizeof(cpu_reg_names);
47e4661c
AJ
92
93 for (i = 0; i < 8; i++) {
2dc766da 94 snprintf(p, cpu_reg_names_size, "crf%d", i);
a7812ae4 95 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 96 offsetof(CPUPPCState, crf[i]), p);
47e4661c 97 p += 5;
2dc766da 98 cpu_reg_names_size -= 5;
47e4661c
AJ
99 }
100
f78fb44e 101 for (i = 0; i < 32; i++) {
2dc766da 102 snprintf(p, cpu_reg_names_size, "r%d", i);
a7812ae4 103 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
1328c2bf 104 offsetof(CPUPPCState, gpr[i]), p);
f78fb44e 105 p += (i < 10) ? 3 : 4;
2dc766da 106 cpu_reg_names_size -= (i < 10) ? 3 : 4;
f78fb44e 107#if !defined(TARGET_PPC64)
2dc766da 108 snprintf(p, cpu_reg_names_size, "r%dH", i);
a7812ae4 109 cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 110 offsetof(CPUPPCState, gprh[i]), p);
f78fb44e 111 p += (i < 10) ? 4 : 5;
2dc766da 112 cpu_reg_names_size -= (i < 10) ? 4 : 5;
f78fb44e 113#endif
1d542695 114
2dc766da 115 snprintf(p, cpu_reg_names_size, "fp%d", i);
a7812ae4 116 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 117 offsetof(CPUPPCState, fpr[i]), p);
ec1ac72d 118 p += (i < 10) ? 4 : 5;
2dc766da 119 cpu_reg_names_size -= (i < 10) ? 4 : 5;
a5e26afa 120
2dc766da 121 snprintf(p, cpu_reg_names_size, "avr%dH", i);
e2542fe2 122#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 123 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 124 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 125#else
a7812ae4 126 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 127 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 128#endif
1d542695 129 p += (i < 10) ? 6 : 7;
2dc766da 130 cpu_reg_names_size -= (i < 10) ? 6 : 7;
ec1ac72d 131
2dc766da 132 snprintf(p, cpu_reg_names_size, "avr%dL", i);
e2542fe2 133#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 134 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 135 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 136#else
a7812ae4 137 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 138 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 139#endif
1d542695 140 p += (i < 10) ? 6 : 7;
2dc766da 141 cpu_reg_names_size -= (i < 10) ? 6 : 7;
472b24ce
TM
142 snprintf(p, cpu_reg_names_size, "vsr%d", i);
143 cpu_vsr[i] = tcg_global_mem_new_i64(TCG_AREG0,
144 offsetof(CPUPPCState, vsr[i]), p);
145 p += (i < 10) ? 5 : 6;
146 cpu_reg_names_size -= (i < 10) ? 5 : 6;
f78fb44e 147 }
f10dc08e 148
a7812ae4 149 cpu_nip = tcg_global_mem_new(TCG_AREG0,
1328c2bf 150 offsetof(CPUPPCState, nip), "nip");
bd568f18 151
6527f6ea 152 cpu_msr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 153 offsetof(CPUPPCState, msr), "msr");
6527f6ea 154
a7812ae4 155 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 156 offsetof(CPUPPCState, ctr), "ctr");
cfdcd37a 157
a7812ae4 158 cpu_lr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 159 offsetof(CPUPPCState, lr), "lr");
cfdcd37a 160
697ab892
DG
161#if defined(TARGET_PPC64)
162 cpu_cfar = tcg_global_mem_new(TCG_AREG0,
1328c2bf 163 offsetof(CPUPPCState, cfar), "cfar");
697ab892
DG
164#endif
165
a7812ae4 166 cpu_xer = tcg_global_mem_new(TCG_AREG0,
1328c2bf 167 offsetof(CPUPPCState, xer), "xer");
da91a00f
RH
168 cpu_so = tcg_global_mem_new(TCG_AREG0,
169 offsetof(CPUPPCState, so), "SO");
170 cpu_ov = tcg_global_mem_new(TCG_AREG0,
171 offsetof(CPUPPCState, ov), "OV");
172 cpu_ca = tcg_global_mem_new(TCG_AREG0,
173 offsetof(CPUPPCState, ca), "CA");
3d7b417e 174
cf360a32 175 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
1328c2bf 176 offsetof(CPUPPCState, reserve_addr),
18b21a2f 177 "reserve_addr");
cf360a32 178
30304420
DG
179 cpu_fpscr = tcg_global_mem_new(TCG_AREG0,
180 offsetof(CPUPPCState, fpscr), "fpscr");
e1571908 181
a7859e89 182 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 183 offsetof(CPUPPCState, access_type), "access_type");
a7859e89 184
2e70f6ef
PB
185 done_init = 1;
186}
187
79aceca5
FB
188/* internal defines */
189typedef struct DisasContext {
190 struct TranslationBlock *tb;
0fa85d43 191 target_ulong nip;
79aceca5 192 uint32_t opcode;
9a64fbe4 193 uint32_t exception;
3cc62370
FB
194 /* Routine used to access memory */
195 int mem_idx;
76db3ba4 196 int access_type;
3cc62370 197 /* Translation flags */
76db3ba4 198 int le_mode;
d9bce9d9
JM
199#if defined(TARGET_PPC64)
200 int sf_mode;
697ab892 201 int has_cfar;
9a64fbe4 202#endif
3cc62370 203 int fpu_enabled;
a9d9eb8f 204 int altivec_enabled;
1f29871c 205 int vsx_enabled;
0487d6a8 206 int spe_enabled;
c227f099 207 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
ea4e754f 208 int singlestep_enabled;
7d08d856
AJ
209 uint64_t insns_flags;
210 uint64_t insns_flags2;
79aceca5
FB
211} DisasContext;
212
79482e5a
RH
213/* True when active word size < size of target_long. */
214#ifdef TARGET_PPC64
215# define NARROW_MODE(C) (!(C)->sf_mode)
216#else
217# define NARROW_MODE(C) 0
218#endif
219
c227f099 220struct opc_handler_t {
70560da7
FC
221 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
222 uint32_t inval1;
223 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
224 uint32_t inval2;
9a64fbe4 225 /* instruction type */
0487d6a8 226 uint64_t type;
a5858d7a
AG
227 /* extended instruction type */
228 uint64_t type2;
79aceca5
FB
229 /* handler */
230 void (*handler)(DisasContext *ctx);
a750fc0b 231#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
b55266b5 232 const char *oname;
a750fc0b
JM
233#endif
234#if defined(DO_PPC_STATISTICS)
76a66253
JM
235 uint64_t count;
236#endif
3fc6c082 237};
79aceca5 238
636aa200 239static inline void gen_reset_fpstatus(void)
7c58044c 240{
8e703949 241 gen_helper_reset_fpstatus(cpu_env);
7c58044c
JM
242}
243
636aa200 244static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
7c58044c 245{
0f2f39c2 246 TCGv_i32 t0 = tcg_temp_new_i32();
af12906f 247
7c58044c
JM
248 if (set_fprf != 0) {
249 /* This case might be optimized later */
0f2f39c2 250 tcg_gen_movi_i32(t0, 1);
8e703949 251 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
a7812ae4 252 if (unlikely(set_rc)) {
0f2f39c2 253 tcg_gen_mov_i32(cpu_crf[1], t0);
a7812ae4 254 }
8e703949 255 gen_helper_float_check_status(cpu_env);
7c58044c
JM
256 } else if (unlikely(set_rc)) {
257 /* We always need to compute fpcc */
0f2f39c2 258 tcg_gen_movi_i32(t0, 0);
8e703949 259 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
0f2f39c2 260 tcg_gen_mov_i32(cpu_crf[1], t0);
7c58044c 261 }
af12906f 262
0f2f39c2 263 tcg_temp_free_i32(t0);
7c58044c
JM
264}
265
636aa200 266static inline void gen_set_access_type(DisasContext *ctx, int access_type)
a7859e89 267{
76db3ba4
AJ
268 if (ctx->access_type != access_type) {
269 tcg_gen_movi_i32(cpu_access_type, access_type);
270 ctx->access_type = access_type;
271 }
a7859e89
AJ
272}
273
636aa200 274static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
d9bce9d9 275{
e0c8f9ce
RH
276 if (NARROW_MODE(ctx)) {
277 nip = (uint32_t)nip;
278 }
279 tcg_gen_movi_tl(cpu_nip, nip);
d9bce9d9
JM
280}
281
636aa200 282static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
e06fcd75
AJ
283{
284 TCGv_i32 t0, t1;
285 if (ctx->exception == POWERPC_EXCP_NONE) {
286 gen_update_nip(ctx, ctx->nip);
287 }
288 t0 = tcg_const_i32(excp);
289 t1 = tcg_const_i32(error);
e5f17ac6 290 gen_helper_raise_exception_err(cpu_env, t0, t1);
e06fcd75
AJ
291 tcg_temp_free_i32(t0);
292 tcg_temp_free_i32(t1);
293 ctx->exception = (excp);
294}
e1833e1f 295
636aa200 296static inline void gen_exception(DisasContext *ctx, uint32_t excp)
e06fcd75
AJ
297{
298 TCGv_i32 t0;
299 if (ctx->exception == POWERPC_EXCP_NONE) {
300 gen_update_nip(ctx, ctx->nip);
301 }
302 t0 = tcg_const_i32(excp);
e5f17ac6 303 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
304 tcg_temp_free_i32(t0);
305 ctx->exception = (excp);
306}
e1833e1f 307
636aa200 308static inline void gen_debug_exception(DisasContext *ctx)
e06fcd75
AJ
309{
310 TCGv_i32 t0;
5518f3a6 311
ee2b3994
SB
312 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
313 (ctx->exception != POWERPC_EXCP_SYNC)) {
5518f3a6 314 gen_update_nip(ctx, ctx->nip);
ee2b3994 315 }
e06fcd75 316 t0 = tcg_const_i32(EXCP_DEBUG);
e5f17ac6 317 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
318 tcg_temp_free_i32(t0);
319}
9a64fbe4 320
636aa200 321static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
e06fcd75
AJ
322{
323 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
324}
a9d9eb8f 325
f24e5695 326/* Stop translation */
636aa200 327static inline void gen_stop_exception(DisasContext *ctx)
3fc6c082 328{
d9bce9d9 329 gen_update_nip(ctx, ctx->nip);
e1833e1f 330 ctx->exception = POWERPC_EXCP_STOP;
3fc6c082
FB
331}
332
f24e5695 333/* No need to update nip here, as execution flow will change */
636aa200 334static inline void gen_sync_exception(DisasContext *ctx)
2be0071f 335{
e1833e1f 336 ctx->exception = POWERPC_EXCP_SYNC;
2be0071f
FB
337}
338
79aceca5 339#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
340GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
341
342#define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
343GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
79aceca5 344
c7697e1f 345#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
346GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
347
348#define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
349GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
c7697e1f 350
c227f099 351typedef struct opcode_t {
79aceca5 352 unsigned char opc1, opc2, opc3;
1235fc06 353#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
18fba28c
FB
354 unsigned char pad[5];
355#else
356 unsigned char pad[1];
357#endif
c227f099 358 opc_handler_t handler;
b55266b5 359 const char *oname;
c227f099 360} opcode_t;
79aceca5 361
a750fc0b 362/*****************************************************************************/
79aceca5
FB
363/*** Instruction decoding ***/
364#define EXTRACT_HELPER(name, shift, nb) \
636aa200 365static inline uint32_t name(uint32_t opcode) \
79aceca5
FB
366{ \
367 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
368}
369
370#define EXTRACT_SHELPER(name, shift, nb) \
636aa200 371static inline int32_t name(uint32_t opcode) \
79aceca5 372{ \
18fba28c 373 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
79aceca5
FB
374}
375
f9fc6d81
TM
376#define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
377static inline uint32_t name(uint32_t opcode) \
378{ \
379 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
380 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
381}
79aceca5
FB
382/* Opcode part 1 */
383EXTRACT_HELPER(opc1, 26, 6);
384/* Opcode part 2 */
385EXTRACT_HELPER(opc2, 1, 5);
386/* Opcode part 3 */
387EXTRACT_HELPER(opc3, 6, 5);
388/* Update Cr0 flags */
389EXTRACT_HELPER(Rc, 0, 1);
a737d3eb
TM
390/* Update Cr6 flags (Altivec) */
391EXTRACT_HELPER(Rc21, 10, 1);
79aceca5
FB
392/* Destination */
393EXTRACT_HELPER(rD, 21, 5);
394/* Source */
395EXTRACT_HELPER(rS, 21, 5);
396/* First operand */
397EXTRACT_HELPER(rA, 16, 5);
398/* Second operand */
399EXTRACT_HELPER(rB, 11, 5);
400/* Third operand */
401EXTRACT_HELPER(rC, 6, 5);
402/*** Get CRn ***/
403EXTRACT_HELPER(crfD, 23, 3);
404EXTRACT_HELPER(crfS, 18, 3);
405EXTRACT_HELPER(crbD, 21, 5);
406EXTRACT_HELPER(crbA, 16, 5);
407EXTRACT_HELPER(crbB, 11, 5);
408/* SPR / TBL */
3fc6c082 409EXTRACT_HELPER(_SPR, 11, 10);
636aa200 410static inline uint32_t SPR(uint32_t opcode)
3fc6c082
FB
411{
412 uint32_t sprn = _SPR(opcode);
413
414 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
415}
79aceca5
FB
416/*** Get constants ***/
417EXTRACT_HELPER(IMM, 12, 8);
418/* 16 bits signed immediate value */
419EXTRACT_SHELPER(SIMM, 0, 16);
420/* 16 bits unsigned immediate value */
421EXTRACT_HELPER(UIMM, 0, 16);
21d21583
AJ
422/* 5 bits signed immediate value */
423EXTRACT_HELPER(SIMM5, 16, 5);
27a4edb3
AJ
424/* 5 bits signed immediate value */
425EXTRACT_HELPER(UIMM5, 16, 5);
79aceca5
FB
426/* Bit count */
427EXTRACT_HELPER(NB, 11, 5);
428/* Shift count */
429EXTRACT_HELPER(SH, 11, 5);
cd633b10
AJ
430/* Vector shift count */
431EXTRACT_HELPER(VSH, 6, 4);
79aceca5
FB
432/* Mask start */
433EXTRACT_HELPER(MB, 6, 5);
434/* Mask end */
435EXTRACT_HELPER(ME, 1, 5);
fb0eaffc
FB
436/* Trap operand */
437EXTRACT_HELPER(TO, 21, 5);
79aceca5
FB
438
439EXTRACT_HELPER(CRM, 12, 8);
79aceca5 440EXTRACT_HELPER(SR, 16, 4);
7d08d856
AJ
441
442/* mtfsf/mtfsfi */
779f6590 443EXTRACT_HELPER(FPBF, 23, 3);
e4bb997e 444EXTRACT_HELPER(FPIMM, 12, 4);
779f6590 445EXTRACT_HELPER(FPL, 25, 1);
7d08d856
AJ
446EXTRACT_HELPER(FPFLM, 17, 8);
447EXTRACT_HELPER(FPW, 16, 1);
fb0eaffc 448
79aceca5
FB
449/*** Jump target decoding ***/
450/* Displacement */
451EXTRACT_SHELPER(d, 0, 16);
452/* Immediate address */
636aa200 453static inline target_ulong LI(uint32_t opcode)
79aceca5
FB
454{
455 return (opcode >> 0) & 0x03FFFFFC;
456}
457
636aa200 458static inline uint32_t BD(uint32_t opcode)
79aceca5
FB
459{
460 return (opcode >> 0) & 0xFFFC;
461}
462
463EXTRACT_HELPER(BO, 21, 5);
464EXTRACT_HELPER(BI, 16, 5);
465/* Absolute/relative address */
466EXTRACT_HELPER(AA, 1, 1);
467/* Link */
468EXTRACT_HELPER(LK, 0, 1);
469
470/* Create a mask between <start> and <end> bits */
636aa200 471static inline target_ulong MASK(uint32_t start, uint32_t end)
79aceca5 472{
76a66253 473 target_ulong ret;
79aceca5 474
76a66253
JM
475#if defined(TARGET_PPC64)
476 if (likely(start == 0)) {
6f2d8978 477 ret = UINT64_MAX << (63 - end);
76a66253 478 } else if (likely(end == 63)) {
6f2d8978 479 ret = UINT64_MAX >> start;
76a66253
JM
480 }
481#else
482 if (likely(start == 0)) {
6f2d8978 483 ret = UINT32_MAX << (31 - end);
76a66253 484 } else if (likely(end == 31)) {
6f2d8978 485 ret = UINT32_MAX >> start;
76a66253
JM
486 }
487#endif
488 else {
489 ret = (((target_ulong)(-1ULL)) >> (start)) ^
490 (((target_ulong)(-1ULL) >> (end)) >> 1);
491 if (unlikely(start > end))
492 return ~ret;
493 }
79aceca5
FB
494
495 return ret;
496}
497
f9fc6d81
TM
498EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
499EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
500EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
501EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
551e3ef7 502EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
f9fc6d81 503EXTRACT_HELPER(DM, 8, 2);
76c15fe0 504EXTRACT_HELPER(UIM, 16, 2);
acc42968 505EXTRACT_HELPER(SHW, 8, 2);
a750fc0b 506/*****************************************************************************/
a750fc0b 507/* PowerPC instructions table */
933dc6eb 508
76a66253 509#if defined(DO_PPC_STATISTICS)
a5858d7a 510#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 511{ \
79aceca5
FB
512 .opc1 = op1, \
513 .opc2 = op2, \
514 .opc3 = op3, \
18fba28c 515 .pad = { 0, }, \
79aceca5 516 .handler = { \
70560da7
FC
517 .inval1 = invl, \
518 .type = _typ, \
519 .type2 = _typ2, \
520 .handler = &gen_##name, \
521 .oname = stringify(name), \
522 }, \
523 .oname = stringify(name), \
524}
525#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
526{ \
527 .opc1 = op1, \
528 .opc2 = op2, \
529 .opc3 = op3, \
530 .pad = { 0, }, \
531 .handler = { \
532 .inval1 = invl1, \
533 .inval2 = invl2, \
9a64fbe4 534 .type = _typ, \
a5858d7a 535 .type2 = _typ2, \
79aceca5 536 .handler = &gen_##name, \
76a66253 537 .oname = stringify(name), \
79aceca5 538 }, \
3fc6c082 539 .oname = stringify(name), \
79aceca5 540}
a5858d7a 541#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 542{ \
c7697e1f
JM
543 .opc1 = op1, \
544 .opc2 = op2, \
545 .opc3 = op3, \
546 .pad = { 0, }, \
547 .handler = { \
70560da7 548 .inval1 = invl, \
c7697e1f 549 .type = _typ, \
a5858d7a 550 .type2 = _typ2, \
c7697e1f
JM
551 .handler = &gen_##name, \
552 .oname = onam, \
553 }, \
554 .oname = onam, \
555}
76a66253 556#else
a5858d7a 557#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 558{ \
c7697e1f
JM
559 .opc1 = op1, \
560 .opc2 = op2, \
561 .opc3 = op3, \
562 .pad = { 0, }, \
563 .handler = { \
70560da7
FC
564 .inval1 = invl, \
565 .type = _typ, \
566 .type2 = _typ2, \
567 .handler = &gen_##name, \
568 }, \
569 .oname = stringify(name), \
570}
571#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
572{ \
573 .opc1 = op1, \
574 .opc2 = op2, \
575 .opc3 = op3, \
576 .pad = { 0, }, \
577 .handler = { \
578 .inval1 = invl1, \
579 .inval2 = invl2, \
c7697e1f 580 .type = _typ, \
a5858d7a 581 .type2 = _typ2, \
c7697e1f 582 .handler = &gen_##name, \
5c55ff99
BS
583 }, \
584 .oname = stringify(name), \
585}
a5858d7a 586#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99
BS
587{ \
588 .opc1 = op1, \
589 .opc2 = op2, \
590 .opc3 = op3, \
591 .pad = { 0, }, \
592 .handler = { \
70560da7 593 .inval1 = invl, \
5c55ff99 594 .type = _typ, \
a5858d7a 595 .type2 = _typ2, \
5c55ff99
BS
596 .handler = &gen_##name, \
597 }, \
598 .oname = onam, \
599}
600#endif
2e610050 601
5c55ff99 602/* SPR load/store helpers */
636aa200 603static inline void gen_load_spr(TCGv t, int reg)
5c55ff99 604{
1328c2bf 605 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 606}
2e610050 607
636aa200 608static inline void gen_store_spr(int reg, TCGv t)
5c55ff99 609{
1328c2bf 610 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 611}
2e610050 612
54623277 613/* Invalid instruction */
99e300ef 614static void gen_invalid(DisasContext *ctx)
9a64fbe4 615{
e06fcd75 616 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
9a64fbe4
FB
617}
618
c227f099 619static opc_handler_t invalid_handler = {
70560da7
FC
620 .inval1 = 0xFFFFFFFF,
621 .inval2 = 0xFFFFFFFF,
9a64fbe4 622 .type = PPC_NONE,
a5858d7a 623 .type2 = PPC_NONE,
79aceca5
FB
624 .handler = gen_invalid,
625};
626
71a8c019
TM
627#if defined(TARGET_PPC64)
628/* NOTE: as this time, the only use of is_user_mode() is in 64 bit code. And */
629/* so the function is wrapped in the standard 64-bit ifdef in order to */
630/* avoid compiler warnings in 32-bit implementations. */
631static bool is_user_mode(DisasContext *ctx)
632{
633#if defined(CONFIG_USER_ONLY)
634 return true;
635#else
636 return ctx->mem_idx == 0;
637#endif
638}
639#endif
640
e1571908
AJ
641/*** Integer comparison ***/
642
636aa200 643static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 644{
2fdcb629
RH
645 TCGv t0 = tcg_temp_new();
646 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 647
da91a00f 648 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 649
2fdcb629
RH
650 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
651 tcg_gen_trunc_tl_i32(t1, t0);
652 tcg_gen_shli_i32(t1, t1, CRF_LT);
653 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
654
655 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
656 tcg_gen_trunc_tl_i32(t1, t0);
657 tcg_gen_shli_i32(t1, t1, CRF_GT);
658 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
659
660 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
661 tcg_gen_trunc_tl_i32(t1, t0);
662 tcg_gen_shli_i32(t1, t1, CRF_EQ);
663 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
664
665 tcg_temp_free(t0);
666 tcg_temp_free_i32(t1);
e1571908
AJ
667}
668
636aa200 669static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 670{
2fdcb629 671 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
672 gen_op_cmp(arg0, t0, s, crf);
673 tcg_temp_free(t0);
e1571908
AJ
674}
675
636aa200 676static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 677{
ea363694 678 TCGv t0, t1;
2fdcb629
RH
679 t0 = tcg_temp_new();
680 t1 = tcg_temp_new();
e1571908 681 if (s) {
ea363694
AJ
682 tcg_gen_ext32s_tl(t0, arg0);
683 tcg_gen_ext32s_tl(t1, arg1);
e1571908 684 } else {
ea363694
AJ
685 tcg_gen_ext32u_tl(t0, arg0);
686 tcg_gen_ext32u_tl(t1, arg1);
e1571908 687 }
ea363694
AJ
688 gen_op_cmp(t0, t1, s, crf);
689 tcg_temp_free(t1);
690 tcg_temp_free(t0);
e1571908
AJ
691}
692
636aa200 693static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 694{
2fdcb629 695 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
696 gen_op_cmp32(arg0, t0, s, crf);
697 tcg_temp_free(t0);
e1571908 698}
e1571908 699
636aa200 700static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908 701{
02765534 702 if (NARROW_MODE(ctx)) {
e1571908 703 gen_op_cmpi32(reg, 0, 1, 0);
02765534 704 } else {
e1571908 705 gen_op_cmpi(reg, 0, 1, 0);
02765534 706 }
e1571908
AJ
707}
708
709/* cmp */
99e300ef 710static void gen_cmp(DisasContext *ctx)
e1571908 711{
36f48d9c 712 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
713 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
714 1, crfD(ctx->opcode));
36f48d9c
AG
715 } else {
716 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
717 1, crfD(ctx->opcode));
02765534 718 }
e1571908
AJ
719}
720
721/* cmpi */
99e300ef 722static void gen_cmpi(DisasContext *ctx)
e1571908 723{
36f48d9c 724 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
725 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
726 1, crfD(ctx->opcode));
36f48d9c
AG
727 } else {
728 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
729 1, crfD(ctx->opcode));
02765534 730 }
e1571908
AJ
731}
732
733/* cmpl */
99e300ef 734static void gen_cmpl(DisasContext *ctx)
e1571908 735{
36f48d9c 736 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
737 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
738 0, crfD(ctx->opcode));
36f48d9c
AG
739 } else {
740 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
741 0, crfD(ctx->opcode));
02765534 742 }
e1571908
AJ
743}
744
745/* cmpli */
99e300ef 746static void gen_cmpli(DisasContext *ctx)
e1571908 747{
36f48d9c 748 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
749 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
750 0, crfD(ctx->opcode));
36f48d9c
AG
751 } else {
752 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
753 0, crfD(ctx->opcode));
02765534 754 }
e1571908
AJ
755}
756
757/* isel (PowerPC 2.03 specification) */
99e300ef 758static void gen_isel(DisasContext *ctx)
e1571908
AJ
759{
760 int l1, l2;
761 uint32_t bi = rC(ctx->opcode);
762 uint32_t mask;
a7812ae4 763 TCGv_i32 t0;
e1571908
AJ
764
765 l1 = gen_new_label();
766 l2 = gen_new_label();
767
768 mask = 1 << (3 - (bi & 0x03));
a7812ae4 769 t0 = tcg_temp_new_i32();
fea0c503
AJ
770 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
771 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
e1571908
AJ
772 if (rA(ctx->opcode) == 0)
773 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
774 else
775 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
776 tcg_gen_br(l2);
777 gen_set_label(l1);
778 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
779 gen_set_label(l2);
a7812ae4 780 tcg_temp_free_i32(t0);
e1571908
AJ
781}
782
fcfda20f
AJ
783/* cmpb: PowerPC 2.05 specification */
784static void gen_cmpb(DisasContext *ctx)
785{
786 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
787 cpu_gpr[rB(ctx->opcode)]);
788}
789
79aceca5 790/*** Integer arithmetic ***/
79aceca5 791
636aa200
BS
792static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
793 TCGv arg1, TCGv arg2, int sub)
74637406 794{
ffe30937 795 TCGv t0 = tcg_temp_new();
79aceca5 796
8e7a6db9 797 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
74637406 798 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
799 if (sub) {
800 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
801 } else {
802 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
803 }
804 tcg_temp_free(t0);
02765534 805 if (NARROW_MODE(ctx)) {
ffe30937
RH
806 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
807 }
ffe30937
RH
808 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
809 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
810}
811
74637406 812/* Common add function */
636aa200 813static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
814 TCGv arg2, bool add_ca, bool compute_ca,
815 bool compute_ov, bool compute_rc0)
74637406 816{
b5a73f8d 817 TCGv t0 = ret;
d9bce9d9 818
752d634e 819 if (compute_ca || compute_ov) {
146de60d 820 t0 = tcg_temp_new();
74637406 821 }
79aceca5 822
da91a00f 823 if (compute_ca) {
79482e5a 824 if (NARROW_MODE(ctx)) {
752d634e
RH
825 /* Caution: a non-obvious corner case of the spec is that we
826 must produce the *entire* 64-bit addition, but produce the
827 carry into bit 32. */
79482e5a 828 TCGv t1 = tcg_temp_new();
752d634e
RH
829 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
830 tcg_gen_add_tl(t0, arg1, arg2);
79482e5a
RH
831 if (add_ca) {
832 tcg_gen_add_tl(t0, t0, cpu_ca);
833 }
752d634e
RH
834 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
835 tcg_temp_free(t1);
836 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
837 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
b5a73f8d 838 } else {
79482e5a
RH
839 TCGv zero = tcg_const_tl(0);
840 if (add_ca) {
841 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
842 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
843 } else {
844 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
845 }
846 tcg_temp_free(zero);
b5a73f8d 847 }
b5a73f8d
RH
848 } else {
849 tcg_gen_add_tl(t0, arg1, arg2);
850 if (add_ca) {
851 tcg_gen_add_tl(t0, t0, cpu_ca);
852 }
da91a00f 853 }
79aceca5 854
74637406
AJ
855 if (compute_ov) {
856 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
857 }
b5a73f8d 858 if (unlikely(compute_rc0)) {
74637406 859 gen_set_Rc0(ctx, t0);
b5a73f8d 860 }
74637406 861
a7812ae4 862 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
863 tcg_gen_mov_tl(ret, t0);
864 tcg_temp_free(t0);
865 }
39dd32ee 866}
74637406
AJ
867/* Add functions with two operands */
868#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 869static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
870{ \
871 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
872 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 873 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
874}
875/* Add functions with one operand and one immediate */
876#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
877 add_ca, compute_ca, compute_ov) \
b5a73f8d 878static void glue(gen_, name)(DisasContext *ctx) \
74637406 879{ \
b5a73f8d 880 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
881 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
882 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 883 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
884 tcg_temp_free(t0); \
885}
886
887/* add add. addo addo. */
888GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
889GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
890/* addc addc. addco addco. */
891GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
892GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
893/* adde adde. addeo addeo. */
894GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
895GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
896/* addme addme. addmeo addmeo. */
897GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
898GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
899/* addze addze. addzeo addzeo.*/
900GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
901GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
902/* addi */
99e300ef 903static void gen_addi(DisasContext *ctx)
d9bce9d9 904{
74637406
AJ
905 target_long simm = SIMM(ctx->opcode);
906
907 if (rA(ctx->opcode) == 0) {
908 /* li case */
909 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
910 } else {
b5a73f8d
RH
911 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
912 cpu_gpr[rA(ctx->opcode)], simm);
74637406 913 }
d9bce9d9 914}
74637406 915/* addic addic.*/
b5a73f8d 916static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 917{
b5a73f8d
RH
918 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
919 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
920 c, 0, 1, 0, compute_rc0);
921 tcg_temp_free(c);
d9bce9d9 922}
99e300ef
BS
923
924static void gen_addic(DisasContext *ctx)
d9bce9d9 925{
b5a73f8d 926 gen_op_addic(ctx, 0);
d9bce9d9 927}
e8eaa2c0
BS
928
929static void gen_addic_(DisasContext *ctx)
d9bce9d9 930{
b5a73f8d 931 gen_op_addic(ctx, 1);
d9bce9d9 932}
99e300ef 933
54623277 934/* addis */
99e300ef 935static void gen_addis(DisasContext *ctx)
d9bce9d9 936{
74637406
AJ
937 target_long simm = SIMM(ctx->opcode);
938
939 if (rA(ctx->opcode) == 0) {
940 /* lis case */
941 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
942 } else {
b5a73f8d
RH
943 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
944 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 945 }
d9bce9d9 946}
74637406 947
636aa200
BS
948static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
949 TCGv arg2, int sign, int compute_ov)
d9bce9d9 950{
2ef1b120
AJ
951 int l1 = gen_new_label();
952 int l2 = gen_new_label();
a7812ae4
PB
953 TCGv_i32 t0 = tcg_temp_local_new_i32();
954 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 955
2ef1b120
AJ
956 tcg_gen_trunc_tl_i32(t0, arg1);
957 tcg_gen_trunc_tl_i32(t1, arg2);
958 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 959 if (sign) {
2ef1b120
AJ
960 int l3 = gen_new_label();
961 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
962 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 963 gen_set_label(l3);
2ef1b120 964 tcg_gen_div_i32(t0, t0, t1);
74637406 965 } else {
2ef1b120 966 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
967 }
968 if (compute_ov) {
da91a00f 969 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
970 }
971 tcg_gen_br(l2);
972 gen_set_label(l1);
973 if (sign) {
2ef1b120 974 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
975 } else {
976 tcg_gen_movi_i32(t0, 0);
977 }
978 if (compute_ov) {
da91a00f
RH
979 tcg_gen_movi_tl(cpu_ov, 1);
980 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
981 }
982 gen_set_label(l2);
2ef1b120 983 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
984 tcg_temp_free_i32(t0);
985 tcg_temp_free_i32(t1);
74637406
AJ
986 if (unlikely(Rc(ctx->opcode) != 0))
987 gen_set_Rc0(ctx, ret);
d9bce9d9 988}
74637406
AJ
989/* Div functions */
990#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 991static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
992{ \
993 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
994 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
995 sign, compute_ov); \
996}
997/* divwu divwu. divwuo divwuo. */
998GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
999GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
1000/* divw divw. divwo divwo. */
1001GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1002GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
98d1eb27
TM
1003
1004/* div[wd]eu[o][.] */
1005#define GEN_DIVE(name, hlpr, compute_ov) \
1006static void gen_##name(DisasContext *ctx) \
1007{ \
1008 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1009 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1010 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1011 tcg_temp_free_i32(t0); \
1012 if (unlikely(Rc(ctx->opcode) != 0)) { \
1013 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1014 } \
1015}
1016
6a4fda33
TM
1017GEN_DIVE(divweu, divweu, 0);
1018GEN_DIVE(divweuo, divweu, 1);
a98eb9e9
TM
1019GEN_DIVE(divwe, divwe, 0);
1020GEN_DIVE(divweo, divwe, 1);
6a4fda33 1021
d9bce9d9 1022#if defined(TARGET_PPC64)
636aa200
BS
1023static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1024 TCGv arg2, int sign, int compute_ov)
d9bce9d9 1025{
2ef1b120
AJ
1026 int l1 = gen_new_label();
1027 int l2 = gen_new_label();
74637406
AJ
1028
1029 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1030 if (sign) {
2ef1b120 1031 int l3 = gen_new_label();
74637406
AJ
1032 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1033 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1034 gen_set_label(l3);
74637406
AJ
1035 tcg_gen_div_i64(ret, arg1, arg2);
1036 } else {
1037 tcg_gen_divu_i64(ret, arg1, arg2);
1038 }
1039 if (compute_ov) {
da91a00f 1040 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
1041 }
1042 tcg_gen_br(l2);
1043 gen_set_label(l1);
1044 if (sign) {
1045 tcg_gen_sari_i64(ret, arg1, 63);
1046 } else {
1047 tcg_gen_movi_i64(ret, 0);
1048 }
1049 if (compute_ov) {
da91a00f
RH
1050 tcg_gen_movi_tl(cpu_ov, 1);
1051 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1052 }
1053 gen_set_label(l2);
1054 if (unlikely(Rc(ctx->opcode) != 0))
1055 gen_set_Rc0(ctx, ret);
d9bce9d9 1056}
74637406 1057#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 1058static void glue(gen_, name)(DisasContext *ctx) \
74637406 1059{ \
2ef1b120
AJ
1060 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1061 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1062 sign, compute_ov); \
74637406
AJ
1063}
1064/* divwu divwu. divwuo divwuo. */
1065GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1066GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1067/* divw divw. divwo divwo. */
1068GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1069GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
98d1eb27
TM
1070
1071GEN_DIVE(divdeu, divdeu, 0);
1072GEN_DIVE(divdeuo, divdeu, 1);
e44259b6
TM
1073GEN_DIVE(divde, divde, 0);
1074GEN_DIVE(divdeo, divde, 1);
d9bce9d9 1075#endif
74637406
AJ
1076
1077/* mulhw mulhw. */
99e300ef 1078static void gen_mulhw(DisasContext *ctx)
d9bce9d9 1079{
23ad1d5d
RH
1080 TCGv_i32 t0 = tcg_temp_new_i32();
1081 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1082
23ad1d5d
RH
1083 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1084 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1085 tcg_gen_muls2_i32(t0, t1, t0, t1);
1086 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1087 tcg_temp_free_i32(t0);
1088 tcg_temp_free_i32(t1);
74637406
AJ
1089 if (unlikely(Rc(ctx->opcode) != 0))
1090 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1091}
99e300ef 1092
54623277 1093/* mulhwu mulhwu. */
99e300ef 1094static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1095{
23ad1d5d
RH
1096 TCGv_i32 t0 = tcg_temp_new_i32();
1097 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1098
23ad1d5d
RH
1099 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1100 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1101 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1102 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1103 tcg_temp_free_i32(t0);
1104 tcg_temp_free_i32(t1);
74637406
AJ
1105 if (unlikely(Rc(ctx->opcode) != 0))
1106 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1107}
99e300ef 1108
54623277 1109/* mullw mullw. */
99e300ef 1110static void gen_mullw(DisasContext *ctx)
d9bce9d9 1111{
74637406
AJ
1112 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1113 cpu_gpr[rB(ctx->opcode)]);
1e4c090f 1114 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
74637406
AJ
1115 if (unlikely(Rc(ctx->opcode) != 0))
1116 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1117}
99e300ef 1118
54623277 1119/* mullwo mullwo. */
99e300ef 1120static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1121{
e4a2c846
RH
1122 TCGv_i32 t0 = tcg_temp_new_i32();
1123 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1124
e4a2c846
RH
1125 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1126 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1127 tcg_gen_muls2_i32(t0, t1, t0, t1);
1128 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1129
1130 tcg_gen_sari_i32(t0, t0, 31);
1131 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1132 tcg_gen_extu_i32_tl(cpu_ov, t0);
1133 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1134
1135 tcg_temp_free_i32(t0);
1136 tcg_temp_free_i32(t1);
74637406
AJ
1137 if (unlikely(Rc(ctx->opcode) != 0))
1138 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1139}
99e300ef 1140
54623277 1141/* mulli */
99e300ef 1142static void gen_mulli(DisasContext *ctx)
d9bce9d9 1143{
74637406
AJ
1144 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1145 SIMM(ctx->opcode));
d9bce9d9 1146}
23ad1d5d 1147
d9bce9d9 1148#if defined(TARGET_PPC64)
74637406 1149/* mulhd mulhd. */
23ad1d5d
RH
1150static void gen_mulhd(DisasContext *ctx)
1151{
1152 TCGv lo = tcg_temp_new();
1153 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1154 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1155 tcg_temp_free(lo);
1156 if (unlikely(Rc(ctx->opcode) != 0)) {
1157 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1158 }
1159}
1160
74637406 1161/* mulhdu mulhdu. */
23ad1d5d
RH
1162static void gen_mulhdu(DisasContext *ctx)
1163{
1164 TCGv lo = tcg_temp_new();
1165 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1166 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1167 tcg_temp_free(lo);
1168 if (unlikely(Rc(ctx->opcode) != 0)) {
1169 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1170 }
1171}
99e300ef 1172
54623277 1173/* mulld mulld. */
99e300ef 1174static void gen_mulld(DisasContext *ctx)
d9bce9d9 1175{
74637406
AJ
1176 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1177 cpu_gpr[rB(ctx->opcode)]);
1178 if (unlikely(Rc(ctx->opcode) != 0))
1179 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1180}
d15f74fb 1181
74637406 1182/* mulldo mulldo. */
d15f74fb
BS
1183static void gen_mulldo(DisasContext *ctx)
1184{
1185 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1186 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1187 if (unlikely(Rc(ctx->opcode) != 0)) {
1188 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1189 }
1190}
d9bce9d9 1191#endif
74637406 1192
74637406 1193/* Common subf function */
636aa200 1194static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1195 TCGv arg2, bool add_ca, bool compute_ca,
1196 bool compute_ov, bool compute_rc0)
79aceca5 1197{
b5a73f8d 1198 TCGv t0 = ret;
79aceca5 1199
752d634e 1200 if (compute_ca || compute_ov) {
b5a73f8d 1201 t0 = tcg_temp_new();
da91a00f 1202 }
74637406 1203
79482e5a
RH
1204 if (compute_ca) {
1205 /* dest = ~arg1 + arg2 [+ ca]. */
1206 if (NARROW_MODE(ctx)) {
752d634e
RH
1207 /* Caution: a non-obvious corner case of the spec is that we
1208 must produce the *entire* 64-bit addition, but produce the
1209 carry into bit 32. */
79482e5a 1210 TCGv inv1 = tcg_temp_new();
752d634e 1211 TCGv t1 = tcg_temp_new();
79482e5a 1212 tcg_gen_not_tl(inv1, arg1);
79482e5a 1213 if (add_ca) {
752d634e 1214 tcg_gen_add_tl(t0, arg2, cpu_ca);
79482e5a 1215 } else {
752d634e 1216 tcg_gen_addi_tl(t0, arg2, 1);
79482e5a 1217 }
752d634e 1218 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
79482e5a 1219 tcg_gen_add_tl(t0, t0, inv1);
752d634e
RH
1220 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1221 tcg_temp_free(t1);
1222 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1223 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
79482e5a 1224 } else if (add_ca) {
08f4a0f7
RH
1225 TCGv zero, inv1 = tcg_temp_new();
1226 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1227 zero = tcg_const_tl(0);
1228 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1229 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1230 tcg_temp_free(zero);
08f4a0f7 1231 tcg_temp_free(inv1);
b5a73f8d 1232 } else {
79482e5a 1233 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
b5a73f8d 1234 tcg_gen_sub_tl(t0, arg2, arg1);
b5a73f8d 1235 }
79482e5a
RH
1236 } else if (add_ca) {
1237 /* Since we're ignoring carry-out, we can simplify the
1238 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1239 tcg_gen_sub_tl(t0, arg2, arg1);
1240 tcg_gen_add_tl(t0, t0, cpu_ca);
1241 tcg_gen_subi_tl(t0, t0, 1);
79aceca5 1242 } else {
b5a73f8d 1243 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1244 }
b5a73f8d 1245
74637406
AJ
1246 if (compute_ov) {
1247 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1248 }
b5a73f8d 1249 if (unlikely(compute_rc0)) {
74637406 1250 gen_set_Rc0(ctx, t0);
b5a73f8d 1251 }
74637406 1252
a7812ae4 1253 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1254 tcg_gen_mov_tl(ret, t0);
1255 tcg_temp_free(t0);
79aceca5 1256 }
79aceca5 1257}
74637406
AJ
1258/* Sub functions with Two operands functions */
1259#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1260static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1261{ \
1262 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1263 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1264 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1265}
1266/* Sub functions with one operand and one immediate */
1267#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1268 add_ca, compute_ca, compute_ov) \
b5a73f8d 1269static void glue(gen_, name)(DisasContext *ctx) \
74637406 1270{ \
b5a73f8d 1271 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1272 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1273 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1274 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1275 tcg_temp_free(t0); \
1276}
1277/* subf subf. subfo subfo. */
1278GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1279GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1280/* subfc subfc. subfco subfco. */
1281GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1282GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1283/* subfe subfe. subfeo subfo. */
1284GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1285GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1286/* subfme subfme. subfmeo subfmeo. */
1287GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1288GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1289/* subfze subfze. subfzeo subfzeo.*/
1290GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1291GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1292
54623277 1293/* subfic */
99e300ef 1294static void gen_subfic(DisasContext *ctx)
79aceca5 1295{
b5a73f8d
RH
1296 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1297 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1298 c, 0, 1, 0, 0);
1299 tcg_temp_free(c);
79aceca5
FB
1300}
1301
fd3f0081
RH
1302/* neg neg. nego nego. */
1303static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1304{
1305 TCGv zero = tcg_const_tl(0);
1306 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1307 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1308 tcg_temp_free(zero);
1309}
1310
1311static void gen_neg(DisasContext *ctx)
1312{
1313 gen_op_arith_neg(ctx, 0);
1314}
1315
1316static void gen_nego(DisasContext *ctx)
1317{
1318 gen_op_arith_neg(ctx, 1);
1319}
1320
79aceca5 1321/*** Integer logical ***/
26d67362 1322#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1323static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1324{ \
26d67362
AJ
1325 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1326 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1327 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1328 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1329}
79aceca5 1330
26d67362 1331#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1332static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1333{ \
26d67362 1334 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1335 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1336 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1337}
1338
1339/* and & and. */
26d67362 1340GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1341/* andc & andc. */
26d67362 1342GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1343
54623277 1344/* andi. */
e8eaa2c0 1345static void gen_andi_(DisasContext *ctx)
79aceca5 1346{
26d67362
AJ
1347 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1348 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1349}
e8eaa2c0 1350
54623277 1351/* andis. */
e8eaa2c0 1352static void gen_andis_(DisasContext *ctx)
79aceca5 1353{
26d67362
AJ
1354 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1355 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1356}
99e300ef 1357
54623277 1358/* cntlzw */
99e300ef 1359static void gen_cntlzw(DisasContext *ctx)
26d67362 1360{
a7812ae4 1361 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1362 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1363 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1364}
79aceca5 1365/* eqv & eqv. */
26d67362 1366GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1367/* extsb & extsb. */
26d67362 1368GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1369/* extsh & extsh. */
26d67362 1370GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1371/* nand & nand. */
26d67362 1372GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1373/* nor & nor. */
26d67362 1374GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1375
54623277 1376/* or & or. */
99e300ef 1377static void gen_or(DisasContext *ctx)
9a64fbe4 1378{
76a66253
JM
1379 int rs, ra, rb;
1380
1381 rs = rS(ctx->opcode);
1382 ra = rA(ctx->opcode);
1383 rb = rB(ctx->opcode);
1384 /* Optimisation for mr. ri case */
1385 if (rs != ra || rs != rb) {
26d67362
AJ
1386 if (rs != rb)
1387 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1388 else
1389 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1390 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1391 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1392 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1393 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1394#if defined(TARGET_PPC64)
1395 } else {
26d67362
AJ
1396 int prio = 0;
1397
c80f84e3
JM
1398 switch (rs) {
1399 case 1:
1400 /* Set process priority to low */
26d67362 1401 prio = 2;
c80f84e3
JM
1402 break;
1403 case 6:
1404 /* Set process priority to medium-low */
26d67362 1405 prio = 3;
c80f84e3
JM
1406 break;
1407 case 2:
1408 /* Set process priority to normal */
26d67362 1409 prio = 4;
c80f84e3 1410 break;
be147d08
JM
1411#if !defined(CONFIG_USER_ONLY)
1412 case 31:
76db3ba4 1413 if (ctx->mem_idx > 0) {
be147d08 1414 /* Set process priority to very low */
26d67362 1415 prio = 1;
be147d08
JM
1416 }
1417 break;
1418 case 5:
76db3ba4 1419 if (ctx->mem_idx > 0) {
be147d08 1420 /* Set process priority to medium-hight */
26d67362 1421 prio = 5;
be147d08
JM
1422 }
1423 break;
1424 case 3:
76db3ba4 1425 if (ctx->mem_idx > 0) {
be147d08 1426 /* Set process priority to high */
26d67362 1427 prio = 6;
be147d08
JM
1428 }
1429 break;
be147d08 1430 case 7:
76db3ba4 1431 if (ctx->mem_idx > 1) {
be147d08 1432 /* Set process priority to very high */
26d67362 1433 prio = 7;
be147d08
JM
1434 }
1435 break;
be147d08 1436#endif
c80f84e3
JM
1437 default:
1438 /* nop */
1439 break;
1440 }
26d67362 1441 if (prio) {
a7812ae4 1442 TCGv t0 = tcg_temp_new();
54cdcae6 1443 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1444 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1445 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1446 gen_store_spr(SPR_PPR, t0);
ea363694 1447 tcg_temp_free(t0);
26d67362 1448 }
c80f84e3 1449#endif
9a64fbe4 1450 }
9a64fbe4 1451}
79aceca5 1452/* orc & orc. */
26d67362 1453GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1454
54623277 1455/* xor & xor. */
99e300ef 1456static void gen_xor(DisasContext *ctx)
9a64fbe4 1457{
9a64fbe4 1458 /* Optimisation for "set to zero" case */
26d67362 1459 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1460 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1461 else
1462 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1463 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1464 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1465}
99e300ef 1466
54623277 1467/* ori */
99e300ef 1468static void gen_ori(DisasContext *ctx)
79aceca5 1469{
76a66253 1470 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1471
9a64fbe4
FB
1472 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1473 /* NOP */
76a66253 1474 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1475 return;
76a66253 1476 }
26d67362 1477 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1478}
99e300ef 1479
54623277 1480/* oris */
99e300ef 1481static void gen_oris(DisasContext *ctx)
79aceca5 1482{
76a66253 1483 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1484
9a64fbe4
FB
1485 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1486 /* NOP */
1487 return;
76a66253 1488 }
26d67362 1489 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1490}
99e300ef 1491
54623277 1492/* xori */
99e300ef 1493static void gen_xori(DisasContext *ctx)
79aceca5 1494{
76a66253 1495 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1496
1497 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1498 /* NOP */
1499 return;
1500 }
26d67362 1501 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1502}
99e300ef 1503
54623277 1504/* xoris */
99e300ef 1505static void gen_xoris(DisasContext *ctx)
79aceca5 1506{
76a66253 1507 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1508
1509 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1510 /* NOP */
1511 return;
1512 }
26d67362 1513 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1514}
99e300ef 1515
54623277 1516/* popcntb : PowerPC 2.03 specification */
99e300ef 1517static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1518{
eaabeef2
DG
1519 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1520}
1521
1522static void gen_popcntw(DisasContext *ctx)
1523{
1524 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1525}
1526
d9bce9d9 1527#if defined(TARGET_PPC64)
eaabeef2
DG
1528/* popcntd: PowerPC 2.06 specification */
1529static void gen_popcntd(DisasContext *ctx)
1530{
1531 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1532}
eaabeef2 1533#endif
d9bce9d9 1534
725bcec2
AJ
1535/* prtyw: PowerPC 2.05 specification */
1536static void gen_prtyw(DisasContext *ctx)
1537{
1538 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1539 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1540 TCGv t0 = tcg_temp_new();
1541 tcg_gen_shri_tl(t0, rs, 16);
1542 tcg_gen_xor_tl(ra, rs, t0);
1543 tcg_gen_shri_tl(t0, ra, 8);
1544 tcg_gen_xor_tl(ra, ra, t0);
1545 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1546 tcg_temp_free(t0);
1547}
1548
1549#if defined(TARGET_PPC64)
1550/* prtyd: PowerPC 2.05 specification */
1551static void gen_prtyd(DisasContext *ctx)
1552{
1553 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1554 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1555 TCGv t0 = tcg_temp_new();
1556 tcg_gen_shri_tl(t0, rs, 32);
1557 tcg_gen_xor_tl(ra, rs, t0);
1558 tcg_gen_shri_tl(t0, ra, 16);
1559 tcg_gen_xor_tl(ra, ra, t0);
1560 tcg_gen_shri_tl(t0, ra, 8);
1561 tcg_gen_xor_tl(ra, ra, t0);
1562 tcg_gen_andi_tl(ra, ra, 1);
1563 tcg_temp_free(t0);
1564}
1565#endif
1566
86ba37ed
TM
1567#if defined(TARGET_PPC64)
1568/* bpermd */
1569static void gen_bpermd(DisasContext *ctx)
1570{
1571 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1572 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1573}
1574#endif
1575
d9bce9d9
JM
1576#if defined(TARGET_PPC64)
1577/* extsw & extsw. */
26d67362 1578GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1579
54623277 1580/* cntlzd */
99e300ef 1581static void gen_cntlzd(DisasContext *ctx)
26d67362 1582{
a7812ae4 1583 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1584 if (unlikely(Rc(ctx->opcode) != 0))
1585 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1586}
d9bce9d9
JM
1587#endif
1588
79aceca5 1589/*** Integer rotate ***/
99e300ef 1590
54623277 1591/* rlwimi & rlwimi. */
99e300ef 1592static void gen_rlwimi(DisasContext *ctx)
79aceca5 1593{
76a66253 1594 uint32_t mb, me, sh;
79aceca5
FB
1595
1596 mb = MB(ctx->opcode);
1597 me = ME(ctx->opcode);
76a66253 1598 sh = SH(ctx->opcode);
d03ef511
AJ
1599 if (likely(sh == 0 && mb == 0 && me == 31)) {
1600 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1601 } else {
d03ef511 1602 target_ulong mask;
a7812ae4
PB
1603 TCGv t1;
1604 TCGv t0 = tcg_temp_new();
54843a58 1605#if defined(TARGET_PPC64)
a7812ae4
PB
1606 TCGv_i32 t2 = tcg_temp_new_i32();
1607 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1608 tcg_gen_rotli_i32(t2, t2, sh);
1609 tcg_gen_extu_i32_i64(t0, t2);
1610 tcg_temp_free_i32(t2);
54843a58
AJ
1611#else
1612 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1613#endif
76a66253 1614#if defined(TARGET_PPC64)
d03ef511
AJ
1615 mb += 32;
1616 me += 32;
76a66253 1617#endif
d03ef511 1618 mask = MASK(mb, me);
a7812ae4 1619 t1 = tcg_temp_new();
d03ef511
AJ
1620 tcg_gen_andi_tl(t0, t0, mask);
1621 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1622 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1623 tcg_temp_free(t0);
1624 tcg_temp_free(t1);
1625 }
76a66253 1626 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1627 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1628}
99e300ef 1629
54623277 1630/* rlwinm & rlwinm. */
99e300ef 1631static void gen_rlwinm(DisasContext *ctx)
79aceca5
FB
1632{
1633 uint32_t mb, me, sh;
3b46e624 1634
79aceca5
FB
1635 sh = SH(ctx->opcode);
1636 mb = MB(ctx->opcode);
1637 me = ME(ctx->opcode);
d03ef511
AJ
1638
1639 if (likely(mb == 0 && me == (31 - sh))) {
1640 if (likely(sh == 0)) {
1641 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1642 } else {
a7812ae4 1643 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1644 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1645 tcg_gen_shli_tl(t0, t0, sh);
1646 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1647 tcg_temp_free(t0);
79aceca5 1648 }
d03ef511 1649 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
a7812ae4 1650 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1651 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1652 tcg_gen_shri_tl(t0, t0, mb);
1653 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1654 tcg_temp_free(t0);
1655 } else {
a7812ae4 1656 TCGv t0 = tcg_temp_new();
54843a58 1657#if defined(TARGET_PPC64)
a7812ae4 1658 TCGv_i32 t1 = tcg_temp_new_i32();
54843a58
AJ
1659 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1660 tcg_gen_rotli_i32(t1, t1, sh);
1661 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4 1662 tcg_temp_free_i32(t1);
54843a58
AJ
1663#else
1664 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1665#endif
76a66253 1666#if defined(TARGET_PPC64)
d03ef511
AJ
1667 mb += 32;
1668 me += 32;
76a66253 1669#endif
d03ef511
AJ
1670 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1671 tcg_temp_free(t0);
1672 }
76a66253 1673 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1674 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1675}
99e300ef 1676
54623277 1677/* rlwnm & rlwnm. */
99e300ef 1678static void gen_rlwnm(DisasContext *ctx)
79aceca5
FB
1679{
1680 uint32_t mb, me;
54843a58
AJ
1681 TCGv t0;
1682#if defined(TARGET_PPC64)
a7812ae4 1683 TCGv_i32 t1, t2;
54843a58 1684#endif
79aceca5
FB
1685
1686 mb = MB(ctx->opcode);
1687 me = ME(ctx->opcode);
a7812ae4 1688 t0 = tcg_temp_new();
d03ef511 1689 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
54843a58 1690#if defined(TARGET_PPC64)
a7812ae4
PB
1691 t1 = tcg_temp_new_i32();
1692 t2 = tcg_temp_new_i32();
54843a58
AJ
1693 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1694 tcg_gen_trunc_i64_i32(t2, t0);
1695 tcg_gen_rotl_i32(t1, t1, t2);
1696 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4
PB
1697 tcg_temp_free_i32(t1);
1698 tcg_temp_free_i32(t2);
54843a58
AJ
1699#else
1700 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1701#endif
76a66253
JM
1702 if (unlikely(mb != 0 || me != 31)) {
1703#if defined(TARGET_PPC64)
1704 mb += 32;
1705 me += 32;
1706#endif
54843a58 1707 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
d03ef511 1708 } else {
54843a58 1709 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
79aceca5 1710 }
54843a58 1711 tcg_temp_free(t0);
76a66253 1712 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1713 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5
FB
1714}
1715
d9bce9d9
JM
1716#if defined(TARGET_PPC64)
1717#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1718static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1719{ \
1720 gen_##name(ctx, 0); \
1721} \
e8eaa2c0
BS
1722 \
1723static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1724{ \
1725 gen_##name(ctx, 1); \
1726}
1727#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1728static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1729{ \
1730 gen_##name(ctx, 0, 0); \
1731} \
e8eaa2c0
BS
1732 \
1733static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1734{ \
1735 gen_##name(ctx, 0, 1); \
1736} \
e8eaa2c0
BS
1737 \
1738static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1739{ \
1740 gen_##name(ctx, 1, 0); \
1741} \
e8eaa2c0
BS
1742 \
1743static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1744{ \
1745 gen_##name(ctx, 1, 1); \
1746}
51789c41 1747
636aa200
BS
1748static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1749 uint32_t sh)
51789c41 1750{
d03ef511
AJ
1751 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1752 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1753 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1754 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1755 } else {
a7812ae4 1756 TCGv t0 = tcg_temp_new();
54843a58 1757 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
d03ef511 1758 if (likely(mb == 0 && me == 63)) {
54843a58 1759 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
d03ef511
AJ
1760 } else {
1761 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
51789c41 1762 }
d03ef511 1763 tcg_temp_free(t0);
51789c41 1764 }
51789c41 1765 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1766 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
51789c41 1767}
d9bce9d9 1768/* rldicl - rldicl. */
636aa200 1769static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1770{
51789c41 1771 uint32_t sh, mb;
d9bce9d9 1772
9d53c753
JM
1773 sh = SH(ctx->opcode) | (shn << 5);
1774 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1775 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1776}
51789c41 1777GEN_PPC64_R4(rldicl, 0x1E, 0x00);
d9bce9d9 1778/* rldicr - rldicr. */
636aa200 1779static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1780{
51789c41 1781 uint32_t sh, me;
d9bce9d9 1782
9d53c753
JM
1783 sh = SH(ctx->opcode) | (shn << 5);
1784 me = MB(ctx->opcode) | (men << 5);
51789c41 1785 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1786}
51789c41 1787GEN_PPC64_R4(rldicr, 0x1E, 0x02);
d9bce9d9 1788/* rldic - rldic. */
636aa200 1789static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1790{
51789c41 1791 uint32_t sh, mb;
d9bce9d9 1792
9d53c753
JM
1793 sh = SH(ctx->opcode) | (shn << 5);
1794 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1795 gen_rldinm(ctx, mb, 63 - sh, sh);
1796}
1797GEN_PPC64_R4(rldic, 0x1E, 0x04);
1798
636aa200 1799static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
51789c41 1800{
54843a58 1801 TCGv t0;
d03ef511 1802
a7812ae4 1803 t0 = tcg_temp_new();
d03ef511 1804 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
54843a58 1805 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
51789c41 1806 if (unlikely(mb != 0 || me != 63)) {
54843a58
AJ
1807 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1808 } else {
1809 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1810 }
1811 tcg_temp_free(t0);
51789c41 1812 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1813 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1814}
51789c41 1815
d9bce9d9 1816/* rldcl - rldcl. */
636aa200 1817static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1818{
51789c41 1819 uint32_t mb;
d9bce9d9 1820
9d53c753 1821 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1822 gen_rldnm(ctx, mb, 63);
d9bce9d9 1823}
36081602 1824GEN_PPC64_R2(rldcl, 0x1E, 0x08);
d9bce9d9 1825/* rldcr - rldcr. */
636aa200 1826static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1827{
51789c41 1828 uint32_t me;
d9bce9d9 1829
9d53c753 1830 me = MB(ctx->opcode) | (men << 5);
51789c41 1831 gen_rldnm(ctx, 0, me);
d9bce9d9 1832}
36081602 1833GEN_PPC64_R2(rldcr, 0x1E, 0x09);
d9bce9d9 1834/* rldimi - rldimi. */
636aa200 1835static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1836{
271a916e 1837 uint32_t sh, mb, me;
d9bce9d9 1838
9d53c753
JM
1839 sh = SH(ctx->opcode) | (shn << 5);
1840 mb = MB(ctx->opcode) | (mbn << 5);
271a916e 1841 me = 63 - sh;
d03ef511
AJ
1842 if (unlikely(sh == 0 && mb == 0)) {
1843 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1844 } else {
1845 TCGv t0, t1;
1846 target_ulong mask;
1847
a7812ae4 1848 t0 = tcg_temp_new();
54843a58 1849 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
a7812ae4 1850 t1 = tcg_temp_new();
d03ef511
AJ
1851 mask = MASK(mb, me);
1852 tcg_gen_andi_tl(t0, t0, mask);
1853 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1854 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1855 tcg_temp_free(t0);
1856 tcg_temp_free(t1);
51789c41 1857 }
51789c41 1858 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1859 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1860}
36081602 1861GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1862#endif
1863
79aceca5 1864/*** Integer shift ***/
99e300ef 1865
54623277 1866/* slw & slw. */
99e300ef 1867static void gen_slw(DisasContext *ctx)
26d67362 1868{
7fd6bf7d 1869 TCGv t0, t1;
26d67362 1870
7fd6bf7d
AJ
1871 t0 = tcg_temp_new();
1872 /* AND rS with a mask that is 0 when rB >= 0x20 */
1873#if defined(TARGET_PPC64)
1874 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1875 tcg_gen_sari_tl(t0, t0, 0x3f);
1876#else
1877 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1878 tcg_gen_sari_tl(t0, t0, 0x1f);
1879#endif
1880 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1881 t1 = tcg_temp_new();
1882 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1883 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1884 tcg_temp_free(t1);
fea0c503 1885 tcg_temp_free(t0);
7fd6bf7d 1886 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1887 if (unlikely(Rc(ctx->opcode) != 0))
1888 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1889}
99e300ef 1890
54623277 1891/* sraw & sraw. */
99e300ef 1892static void gen_sraw(DisasContext *ctx)
26d67362 1893{
d15f74fb 1894 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1895 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1896 if (unlikely(Rc(ctx->opcode) != 0))
1897 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1898}
99e300ef 1899
54623277 1900/* srawi & srawi. */
99e300ef 1901static void gen_srawi(DisasContext *ctx)
79aceca5 1902{
26d67362 1903 int sh = SH(ctx->opcode);
ba4af3e4
RH
1904 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1905 TCGv src = cpu_gpr[rS(ctx->opcode)];
1906 if (sh == 0) {
1907 tcg_gen_mov_tl(dst, src);
da91a00f 1908 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1909 } else {
ba4af3e4
RH
1910 TCGv t0;
1911 tcg_gen_ext32s_tl(dst, src);
1912 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1913 t0 = tcg_temp_new();
1914 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1915 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1916 tcg_temp_free(t0);
1917 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1918 tcg_gen_sari_tl(dst, dst, sh);
1919 }
1920 if (unlikely(Rc(ctx->opcode) != 0)) {
1921 gen_set_Rc0(ctx, dst);
d9bce9d9 1922 }
79aceca5 1923}
99e300ef 1924
54623277 1925/* srw & srw. */
99e300ef 1926static void gen_srw(DisasContext *ctx)
26d67362 1927{
fea0c503 1928 TCGv t0, t1;
d9bce9d9 1929
7fd6bf7d
AJ
1930 t0 = tcg_temp_new();
1931 /* AND rS with a mask that is 0 when rB >= 0x20 */
1932#if defined(TARGET_PPC64)
1933 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1934 tcg_gen_sari_tl(t0, t0, 0x3f);
1935#else
1936 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1937 tcg_gen_sari_tl(t0, t0, 0x1f);
1938#endif
1939 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1940 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1941 t1 = tcg_temp_new();
7fd6bf7d
AJ
1942 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1943 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1944 tcg_temp_free(t1);
fea0c503 1945 tcg_temp_free(t0);
26d67362
AJ
1946 if (unlikely(Rc(ctx->opcode) != 0))
1947 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1948}
54623277 1949
d9bce9d9
JM
1950#if defined(TARGET_PPC64)
1951/* sld & sld. */
99e300ef 1952static void gen_sld(DisasContext *ctx)
26d67362 1953{
7fd6bf7d 1954 TCGv t0, t1;
26d67362 1955
7fd6bf7d
AJ
1956 t0 = tcg_temp_new();
1957 /* AND rS with a mask that is 0 when rB >= 0x40 */
1958 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1959 tcg_gen_sari_tl(t0, t0, 0x3f);
1960 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1961 t1 = tcg_temp_new();
1962 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1963 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1964 tcg_temp_free(t1);
fea0c503 1965 tcg_temp_free(t0);
26d67362
AJ
1966 if (unlikely(Rc(ctx->opcode) != 0))
1967 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1968}
99e300ef 1969
54623277 1970/* srad & srad. */
99e300ef 1971static void gen_srad(DisasContext *ctx)
26d67362 1972{
d15f74fb 1973 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1974 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1975 if (unlikely(Rc(ctx->opcode) != 0))
1976 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1977}
d9bce9d9 1978/* sradi & sradi. */
636aa200 1979static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1980{
26d67362 1981 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
1982 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1983 TCGv src = cpu_gpr[rS(ctx->opcode)];
1984 if (sh == 0) {
1985 tcg_gen_mov_tl(dst, src);
da91a00f 1986 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1987 } else {
ba4af3e4
RH
1988 TCGv t0;
1989 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1990 t0 = tcg_temp_new();
1991 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1992 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1993 tcg_temp_free(t0);
1994 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1995 tcg_gen_sari_tl(dst, src, sh);
1996 }
1997 if (unlikely(Rc(ctx->opcode) != 0)) {
1998 gen_set_Rc0(ctx, dst);
d9bce9d9 1999 }
d9bce9d9 2000}
e8eaa2c0
BS
2001
2002static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
2003{
2004 gen_sradi(ctx, 0);
2005}
e8eaa2c0
BS
2006
2007static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
2008{
2009 gen_sradi(ctx, 1);
2010}
99e300ef 2011
54623277 2012/* srd & srd. */
99e300ef 2013static void gen_srd(DisasContext *ctx)
26d67362 2014{
7fd6bf7d 2015 TCGv t0, t1;
26d67362 2016
7fd6bf7d
AJ
2017 t0 = tcg_temp_new();
2018 /* AND rS with a mask that is 0 when rB >= 0x40 */
2019 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2020 tcg_gen_sari_tl(t0, t0, 0x3f);
2021 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2022 t1 = tcg_temp_new();
2023 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2024 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2025 tcg_temp_free(t1);
fea0c503 2026 tcg_temp_free(t0);
26d67362
AJ
2027 if (unlikely(Rc(ctx->opcode) != 0))
2028 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2029}
d9bce9d9 2030#endif
79aceca5
FB
2031
2032/*** Floating-Point arithmetic ***/
7c58044c 2033#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 2034static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2035{ \
76a66253 2036 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2037 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2038 return; \
2039 } \
eb44b959
AJ
2040 /* NIP cannot be restored if the memory exception comes from an helper */ \
2041 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2042 gen_reset_fpstatus(); \
8e703949
BS
2043 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2044 cpu_fpr[rA(ctx->opcode)], \
af12906f 2045 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2046 if (isfloat) { \
8e703949
BS
2047 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2048 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2049 } \
af12906f
AJ
2050 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2051 Rc(ctx->opcode) != 0); \
9a64fbe4
FB
2052}
2053
7c58044c
JM
2054#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2055_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2056_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2057
7c58044c 2058#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2059static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2060{ \
76a66253 2061 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2062 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2063 return; \
2064 } \
eb44b959
AJ
2065 /* NIP cannot be restored if the memory exception comes from an helper */ \
2066 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2067 gen_reset_fpstatus(); \
8e703949
BS
2068 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2069 cpu_fpr[rA(ctx->opcode)], \
af12906f 2070 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2071 if (isfloat) { \
8e703949
BS
2072 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2073 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2074 } \
af12906f
AJ
2075 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2076 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2077}
7c58044c
JM
2078#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2079_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2080_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2081
7c58044c 2082#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2083static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2084{ \
76a66253 2085 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2086 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2087 return; \
2088 } \
eb44b959
AJ
2089 /* NIP cannot be restored if the memory exception comes from an helper */ \
2090 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2091 gen_reset_fpstatus(); \
8e703949
BS
2092 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2093 cpu_fpr[rA(ctx->opcode)], \
2094 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2095 if (isfloat) { \
8e703949
BS
2096 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2097 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2098 } \
af12906f
AJ
2099 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2100 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2101}
7c58044c
JM
2102#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2103_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2104_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2105
7c58044c 2106#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2107static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2108{ \
76a66253 2109 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2110 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2111 return; \
2112 } \
eb44b959
AJ
2113 /* NIP cannot be restored if the memory exception comes from an helper */ \
2114 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2115 gen_reset_fpstatus(); \
8e703949
BS
2116 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2117 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2118 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2119 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2120}
2121
7c58044c 2122#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2123static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2124{ \
76a66253 2125 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2126 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2127 return; \
2128 } \
eb44b959
AJ
2129 /* NIP cannot be restored if the memory exception comes from an helper */ \
2130 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2131 gen_reset_fpstatus(); \
8e703949
BS
2132 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2133 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2134 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2135 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2136}
2137
9a64fbe4 2138/* fadd - fadds */
7c58044c 2139GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2140/* fdiv - fdivs */
7c58044c 2141GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2142/* fmul - fmuls */
7c58044c 2143GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2144
d7e4b87e 2145/* fre */
7c58044c 2146GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2147
a750fc0b 2148/* fres */
7c58044c 2149GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2150
a750fc0b 2151/* frsqrte */
7c58044c
JM
2152GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2153
2154/* frsqrtes */
99e300ef 2155static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2156{
af12906f 2157 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2158 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2159 return;
2160 }
eb44b959
AJ
2161 /* NIP cannot be restored if the memory exception comes from an helper */
2162 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2163 gen_reset_fpstatus();
8e703949
BS
2164 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2165 cpu_fpr[rB(ctx->opcode)]);
2166 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2167 cpu_fpr[rD(ctx->opcode)]);
af12906f 2168 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
7c58044c 2169}
79aceca5 2170
a750fc0b 2171/* fsel */
7c58044c 2172_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2173/* fsub - fsubs */
7c58044c 2174GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2175/* Optional: */
99e300ef 2176
54623277 2177/* fsqrt */
99e300ef 2178static void gen_fsqrt(DisasContext *ctx)
c7d344af 2179{
76a66253 2180 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2181 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2182 return;
2183 }
eb44b959
AJ
2184 /* NIP cannot be restored if the memory exception comes from an helper */
2185 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2186 gen_reset_fpstatus();
8e703949
BS
2187 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2188 cpu_fpr[rB(ctx->opcode)]);
af12906f 2189 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
c7d344af 2190}
79aceca5 2191
99e300ef 2192static void gen_fsqrts(DisasContext *ctx)
79aceca5 2193{
76a66253 2194 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2195 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2196 return;
2197 }
eb44b959
AJ
2198 /* NIP cannot be restored if the memory exception comes from an helper */
2199 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2200 gen_reset_fpstatus();
8e703949
BS
2201 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2202 cpu_fpr[rB(ctx->opcode)]);
2203 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2204 cpu_fpr[rD(ctx->opcode)]);
af12906f 2205 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
79aceca5
FB
2206}
2207
2208/*** Floating-Point multiply-and-add ***/
4ecc3190 2209/* fmadd - fmadds */
7c58044c 2210GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2211/* fmsub - fmsubs */
7c58044c 2212GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2213/* fnmadd - fnmadds */
7c58044c 2214GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2215/* fnmsub - fnmsubs */
7c58044c 2216GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2217
2218/*** Floating-Point round & convert ***/
2219/* fctiw */
7c58044c 2220GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2221/* fctiwu */
2222GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2223/* fctiwz */
7c58044c 2224GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2225/* fctiwuz */
2226GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2227/* frsp */
7c58044c 2228GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db
JM
2229#if defined(TARGET_PPC64)
2230/* fcfid */
7c58044c 2231GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
28288b48
TM
2232/* fcfids */
2233GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2234/* fcfidu */
2235GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2236/* fcfidus */
2237GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
426613db 2238/* fctid */
7c58044c 2239GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
fab7fe42
TM
2240/* fctidu */
2241GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2242/* fctidz */
7c58044c 2243GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
fab7fe42
TM
2244/* fctidu */
2245GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2246#endif
79aceca5 2247
d7e4b87e 2248/* frin */
7c58044c 2249GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2250/* friz */
7c58044c 2251GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2252/* frip */
7c58044c 2253GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2254/* frim */
7c58044c 2255GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2256
da29cb7b
TM
2257static void gen_ftdiv(DisasContext *ctx)
2258{
2259 if (unlikely(!ctx->fpu_enabled)) {
2260 gen_exception(ctx, POWERPC_EXCP_FPU);
2261 return;
2262 }
2263 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2264 cpu_fpr[rB(ctx->opcode)]);
2265}
2266
6d41d146
TM
2267static void gen_ftsqrt(DisasContext *ctx)
2268{
2269 if (unlikely(!ctx->fpu_enabled)) {
2270 gen_exception(ctx, POWERPC_EXCP_FPU);
2271 return;
2272 }
2273 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2274}
2275
da29cb7b
TM
2276
2277
79aceca5 2278/*** Floating-Point compare ***/
99e300ef 2279
54623277 2280/* fcmpo */
99e300ef 2281static void gen_fcmpo(DisasContext *ctx)
79aceca5 2282{
330c483b 2283 TCGv_i32 crf;
76a66253 2284 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2285 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2286 return;
2287 }
eb44b959
AJ
2288 /* NIP cannot be restored if the memory exception comes from an helper */
2289 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2290 gen_reset_fpstatus();
9a819377 2291 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2292 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2293 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2294 tcg_temp_free_i32(crf);
8e703949 2295 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2296}
2297
2298/* fcmpu */
99e300ef 2299static void gen_fcmpu(DisasContext *ctx)
79aceca5 2300{
330c483b 2301 TCGv_i32 crf;
76a66253 2302 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2303 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2304 return;
2305 }
eb44b959
AJ
2306 /* NIP cannot be restored if the memory exception comes from an helper */
2307 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2308 gen_reset_fpstatus();
9a819377 2309 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2310 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2311 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2312 tcg_temp_free_i32(crf);
8e703949 2313 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2314}
2315
9a64fbe4
FB
2316/*** Floating-point move ***/
2317/* fabs */
7c58044c 2318/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2319static void gen_fabs(DisasContext *ctx)
2320{
2321 if (unlikely(!ctx->fpu_enabled)) {
2322 gen_exception(ctx, POWERPC_EXCP_FPU);
2323 return;
2324 }
2325 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2326 ~(1ULL << 63));
2327 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2328}
9a64fbe4
FB
2329
2330/* fmr - fmr. */
7c58044c 2331/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2332static void gen_fmr(DisasContext *ctx)
9a64fbe4 2333{
76a66253 2334 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2335 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2336 return;
2337 }
af12906f
AJ
2338 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2339 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
9a64fbe4
FB
2340}
2341
2342/* fnabs */
7c58044c 2343/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2344static void gen_fnabs(DisasContext *ctx)
2345{
2346 if (unlikely(!ctx->fpu_enabled)) {
2347 gen_exception(ctx, POWERPC_EXCP_FPU);
2348 return;
2349 }
2350 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2351 1ULL << 63);
2352 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2353}
2354
9a64fbe4 2355/* fneg */
7c58044c 2356/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2357static void gen_fneg(DisasContext *ctx)
2358{
2359 if (unlikely(!ctx->fpu_enabled)) {
2360 gen_exception(ctx, POWERPC_EXCP_FPU);
2361 return;
2362 }
2363 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2364 1ULL << 63);
2365 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2366}
9a64fbe4 2367
f0332888
AJ
2368/* fcpsgn: PowerPC 2.05 specification */
2369/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2370static void gen_fcpsgn(DisasContext *ctx)
2371{
2372 if (unlikely(!ctx->fpu_enabled)) {
2373 gen_exception(ctx, POWERPC_EXCP_FPU);
2374 return;
2375 }
2376 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2377 cpu_fpr[rB(ctx->opcode)], 0, 63);
2378 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2379}
2380
097ec5d8
TM
2381static void gen_fmrgew(DisasContext *ctx)
2382{
2383 TCGv_i64 b0;
2384 if (unlikely(!ctx->fpu_enabled)) {
2385 gen_exception(ctx, POWERPC_EXCP_FPU);
2386 return;
2387 }
2388 b0 = tcg_temp_new_i64();
2389 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2390 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2391 b0, 0, 32);
2392 tcg_temp_free_i64(b0);
2393}
2394
2395static void gen_fmrgow(DisasContext *ctx)
2396{
2397 if (unlikely(!ctx->fpu_enabled)) {
2398 gen_exception(ctx, POWERPC_EXCP_FPU);
2399 return;
2400 }
2401 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2402 cpu_fpr[rB(ctx->opcode)],
2403 cpu_fpr[rA(ctx->opcode)],
2404 32, 32);
2405}
2406
79aceca5 2407/*** Floating-Point status & ctrl register ***/
99e300ef 2408
54623277 2409/* mcrfs */
99e300ef 2410static void gen_mcrfs(DisasContext *ctx)
79aceca5 2411{
30304420 2412 TCGv tmp = tcg_temp_new();
7c58044c
JM
2413 int bfa;
2414
76a66253 2415 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2416 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2417 return;
2418 }
7c58044c 2419 bfa = 4 * (7 - crfS(ctx->opcode));
30304420
DG
2420 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2421 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2422 tcg_temp_free(tmp);
e1571908 2423 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
30304420 2424 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
79aceca5
FB
2425}
2426
2427/* mffs */
99e300ef 2428static void gen_mffs(DisasContext *ctx)
79aceca5 2429{
76a66253 2430 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2431 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2432 return;
2433 }
7c58044c 2434 gen_reset_fpstatus();
30304420 2435 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
af12906f 2436 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
79aceca5
FB
2437}
2438
2439/* mtfsb0 */
99e300ef 2440static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2441{
fb0eaffc 2442 uint8_t crb;
3b46e624 2443
76a66253 2444 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2445 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2446 return;
2447 }
6e35d524 2448 crb = 31 - crbD(ctx->opcode);
7c58044c 2449 gen_reset_fpstatus();
6e35d524 2450 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2451 TCGv_i32 t0;
2452 /* NIP cannot be restored if the memory exception comes from an helper */
2453 gen_update_nip(ctx, ctx->nip - 4);
2454 t0 = tcg_const_i32(crb);
8e703949 2455 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2456 tcg_temp_free_i32(t0);
2457 }
7c58044c 2458 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2459 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2460 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2461 }
79aceca5
FB
2462}
2463
2464/* mtfsb1 */
99e300ef 2465static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2466{
fb0eaffc 2467 uint8_t crb;
3b46e624 2468
76a66253 2469 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2470 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2471 return;
2472 }
6e35d524 2473 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2474 gen_reset_fpstatus();
2475 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2476 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2477 TCGv_i32 t0;
2478 /* NIP cannot be restored if the memory exception comes from an helper */
2479 gen_update_nip(ctx, ctx->nip - 4);
2480 t0 = tcg_const_i32(crb);
8e703949 2481 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2482 tcg_temp_free_i32(t0);
af12906f 2483 }
7c58044c 2484 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2485 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2486 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2487 }
2488 /* We can raise a differed exception */
8e703949 2489 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2490}
2491
2492/* mtfsf */
99e300ef 2493static void gen_mtfsf(DisasContext *ctx)
79aceca5 2494{
0f2f39c2 2495 TCGv_i32 t0;
7d08d856 2496 int flm, l, w;
af12906f 2497
76a66253 2498 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2499 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2500 return;
2501 }
7d08d856
AJ
2502 flm = FPFLM(ctx->opcode);
2503 l = FPL(ctx->opcode);
2504 w = FPW(ctx->opcode);
2505 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2506 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2507 return;
2508 }
eb44b959
AJ
2509 /* NIP cannot be restored if the memory exception comes from an helper */
2510 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2511 gen_reset_fpstatus();
7d08d856
AJ
2512 if (l) {
2513 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2514 } else {
2515 t0 = tcg_const_i32(flm << (w * 8));
2516 }
8e703949 2517 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2518 tcg_temp_free_i32(t0);
7c58044c 2519 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2520 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2521 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2522 }
2523 /* We can raise a differed exception */
8e703949 2524 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2525}
2526
2527/* mtfsfi */
99e300ef 2528static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2529{
7d08d856 2530 int bf, sh, w;
0f2f39c2
AJ
2531 TCGv_i64 t0;
2532 TCGv_i32 t1;
7c58044c 2533
76a66253 2534 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2535 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2536 return;
2537 }
7d08d856
AJ
2538 w = FPW(ctx->opcode);
2539 bf = FPBF(ctx->opcode);
2540 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2541 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2542 return;
2543 }
2544 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2545 /* NIP cannot be restored if the memory exception comes from an helper */
2546 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2547 gen_reset_fpstatus();
7d08d856 2548 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2549 t1 = tcg_const_i32(1 << sh);
8e703949 2550 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2551 tcg_temp_free_i64(t0);
2552 tcg_temp_free_i32(t1);
7c58044c 2553 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2554 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2555 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2556 }
2557 /* We can raise a differed exception */
8e703949 2558 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2559}
2560
76a66253
JM
2561/*** Addressing modes ***/
2562/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2563static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2564 target_long maskl)
76a66253
JM
2565{
2566 target_long simm = SIMM(ctx->opcode);
2567
be147d08 2568 simm &= ~maskl;
76db3ba4 2569 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2570 if (NARROW_MODE(ctx)) {
2571 simm = (uint32_t)simm;
2572 }
e2be8d8d 2573 tcg_gen_movi_tl(EA, simm);
76db3ba4 2574 } else if (likely(simm != 0)) {
e2be8d8d 2575 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2576 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2577 tcg_gen_ext32u_tl(EA, EA);
2578 }
76db3ba4 2579 } else {
c791fe84 2580 if (NARROW_MODE(ctx)) {
76db3ba4 2581 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2582 } else {
2583 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2584 }
76db3ba4 2585 }
76a66253
JM
2586}
2587
636aa200 2588static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2589{
76db3ba4 2590 if (rA(ctx->opcode) == 0) {
c791fe84 2591 if (NARROW_MODE(ctx)) {
76db3ba4 2592 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2593 } else {
2594 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2595 }
76db3ba4 2596 } else {
e2be8d8d 2597 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2598 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2599 tcg_gen_ext32u_tl(EA, EA);
2600 }
76db3ba4 2601 }
76a66253
JM
2602}
2603
636aa200 2604static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2605{
76db3ba4 2606 if (rA(ctx->opcode) == 0) {
e2be8d8d 2607 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2608 } else if (NARROW_MODE(ctx)) {
2609 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2610 } else {
c791fe84 2611 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2612 }
2613}
2614
636aa200
BS
2615static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2616 target_long val)
76db3ba4
AJ
2617{
2618 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2619 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2620 tcg_gen_ext32u_tl(ret, ret);
2621 }
76a66253
JM
2622}
2623
636aa200 2624static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32
AJ
2625{
2626 int l1 = gen_new_label();
2627 TCGv t0 = tcg_temp_new();
2628 TCGv_i32 t1, t2;
2629 /* NIP cannot be restored if the memory exception comes from an helper */
2630 gen_update_nip(ctx, ctx->nip - 4);
2631 tcg_gen_andi_tl(t0, EA, mask);
2632 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2633 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2634 t2 = tcg_const_i32(0);
e5f17ac6 2635 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2636 tcg_temp_free_i32(t1);
2637 tcg_temp_free_i32(t2);
2638 gen_set_label(l1);
2639 tcg_temp_free(t0);
2640}
2641
7863667f 2642/*** Integer load ***/
636aa200 2643static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2644{
2645 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2646}
2647
636aa200 2648static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2649{
2650 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2651}
2652
636aa200 2653static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2654{
2655 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2656 if (unlikely(ctx->le_mode)) {
fa3966a3 2657 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2658 }
b61f2753
AJ
2659}
2660
636aa200 2661static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2662{
76db3ba4 2663 if (unlikely(ctx->le_mode)) {
76db3ba4 2664 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
fa3966a3 2665 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2666 tcg_gen_ext16s_tl(arg1, arg1);
76db3ba4
AJ
2667 } else {
2668 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2669 }
b61f2753
AJ
2670}
2671
636aa200 2672static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2673{
76db3ba4
AJ
2674 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2675 if (unlikely(ctx->le_mode)) {
fa3966a3 2676 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2677 }
b61f2753
AJ
2678}
2679
f976b09e
AG
2680static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2681{
2682 TCGv tmp = tcg_temp_new();
2683 gen_qemu_ld32u(ctx, tmp, addr);
2684 tcg_gen_extu_tl_i64(val, tmp);
2685 tcg_temp_free(tmp);
2686}
2687
636aa200 2688static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2689{
a457e7ee 2690 if (unlikely(ctx->le_mode)) {
76db3ba4 2691 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
fa3966a3
AJ
2692 tcg_gen_bswap32_tl(arg1, arg1);
2693 tcg_gen_ext32s_tl(arg1, arg1);
b61f2753 2694 } else
76db3ba4 2695 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2696}
2697
cac7f0ba
TM
2698static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2699{
2700 TCGv tmp = tcg_temp_new();
2701 gen_qemu_ld32s(ctx, tmp, addr);
2702 tcg_gen_ext_tl_i64(val, tmp);
2703 tcg_temp_free(tmp);
2704}
2705
636aa200 2706static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2707{
76db3ba4
AJ
2708 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2709 if (unlikely(ctx->le_mode)) {
66896cb8 2710 tcg_gen_bswap64_i64(arg1, arg1);
76db3ba4 2711 }
b61f2753
AJ
2712}
2713
636aa200 2714static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2715{
76db3ba4 2716 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2717}
2718
636aa200 2719static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2720{
76db3ba4 2721 if (unlikely(ctx->le_mode)) {
76db3ba4
AJ
2722 TCGv t0 = tcg_temp_new();
2723 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2724 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2725 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2726 tcg_temp_free(t0);
76db3ba4
AJ
2727 } else {
2728 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2729 }
b61f2753
AJ
2730}
2731
636aa200 2732static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2733{
76db3ba4 2734 if (unlikely(ctx->le_mode)) {
fa3966a3
AJ
2735 TCGv t0 = tcg_temp_new();
2736 tcg_gen_ext32u_tl(t0, arg1);
2737 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2738 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2739 tcg_temp_free(t0);
76db3ba4
AJ
2740 } else {
2741 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2742 }
b61f2753
AJ
2743}
2744
f976b09e
AG
2745static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2746{
2747 TCGv tmp = tcg_temp_new();
2748 tcg_gen_trunc_i64_tl(tmp, val);
2749 gen_qemu_st32(ctx, tmp, addr);
2750 tcg_temp_free(tmp);
2751}
2752
636aa200 2753static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2754{
76db3ba4 2755 if (unlikely(ctx->le_mode)) {
a7812ae4 2756 TCGv_i64 t0 = tcg_temp_new_i64();
66896cb8 2757 tcg_gen_bswap64_i64(t0, arg1);
76db3ba4 2758 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
a7812ae4 2759 tcg_temp_free_i64(t0);
b61f2753 2760 } else
76db3ba4 2761 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2762}
2763
0c8aacd4 2764#define GEN_LD(name, ldop, opc, type) \
99e300ef 2765static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2766{ \
76db3ba4
AJ
2767 TCGv EA; \
2768 gen_set_access_type(ctx, ACCESS_INT); \
2769 EA = tcg_temp_new(); \
2770 gen_addr_imm_index(ctx, EA, 0); \
2771 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2772 tcg_temp_free(EA); \
79aceca5
FB
2773}
2774
0c8aacd4 2775#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2776static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2777{ \
b61f2753 2778 TCGv EA; \
76a66253
JM
2779 if (unlikely(rA(ctx->opcode) == 0 || \
2780 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2781 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2782 return; \
9a64fbe4 2783 } \
76db3ba4 2784 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2785 EA = tcg_temp_new(); \
9d53c753 2786 if (type == PPC_64B) \
76db3ba4 2787 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2788 else \
76db3ba4
AJ
2789 gen_addr_imm_index(ctx, EA, 0); \
2790 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2791 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2792 tcg_temp_free(EA); \
79aceca5
FB
2793}
2794
0c8aacd4 2795#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2796static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2797{ \
b61f2753 2798 TCGv EA; \
76a66253
JM
2799 if (unlikely(rA(ctx->opcode) == 0 || \
2800 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2801 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2802 return; \
9a64fbe4 2803 } \
76db3ba4 2804 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2805 EA = tcg_temp_new(); \
76db3ba4
AJ
2806 gen_addr_reg_index(ctx, EA); \
2807 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2808 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2809 tcg_temp_free(EA); \
79aceca5
FB
2810}
2811
cd6e9320 2812#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2813static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2814{ \
76db3ba4
AJ
2815 TCGv EA; \
2816 gen_set_access_type(ctx, ACCESS_INT); \
2817 EA = tcg_temp_new(); \
2818 gen_addr_reg_index(ctx, EA); \
2819 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2820 tcg_temp_free(EA); \
79aceca5 2821}
cd6e9320
TH
2822#define GEN_LDX(name, ldop, opc2, opc3, type) \
2823 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2824
0c8aacd4
AJ
2825#define GEN_LDS(name, ldop, op, type) \
2826GEN_LD(name, ldop, op | 0x20, type); \
2827GEN_LDU(name, ldop, op | 0x21, type); \
2828GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2829GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2830
2831/* lbz lbzu lbzux lbzx */
0c8aacd4 2832GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2833/* lha lhau lhaux lhax */
0c8aacd4 2834GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2835/* lhz lhzu lhzux lhzx */
0c8aacd4 2836GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2837/* lwz lwzu lwzux lwzx */
0c8aacd4 2838GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2839#if defined(TARGET_PPC64)
d9bce9d9 2840/* lwaux */
0c8aacd4 2841GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2842/* lwax */
0c8aacd4 2843GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2844/* ldux */
0c8aacd4 2845GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2846/* ldx */
0c8aacd4 2847GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2848
2849static void gen_ld(DisasContext *ctx)
d9bce9d9 2850{
b61f2753 2851 TCGv EA;
d9bce9d9
JM
2852 if (Rc(ctx->opcode)) {
2853 if (unlikely(rA(ctx->opcode) == 0 ||
2854 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2855 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2856 return;
2857 }
2858 }
76db3ba4 2859 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2860 EA = tcg_temp_new();
76db3ba4 2861 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2862 if (ctx->opcode & 0x02) {
2863 /* lwa (lwau is undefined) */
76db3ba4 2864 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2865 } else {
2866 /* ld - ldu */
76db3ba4 2867 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2868 }
d9bce9d9 2869 if (Rc(ctx->opcode))
b61f2753
AJ
2870 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2871 tcg_temp_free(EA);
d9bce9d9 2872}
99e300ef 2873
54623277 2874/* lq */
99e300ef 2875static void gen_lq(DisasContext *ctx)
be147d08 2876{
be147d08 2877 int ra, rd;
b61f2753 2878 TCGv EA;
be147d08 2879
e0498daa
TM
2880 /* lq is a legal user mode instruction starting in ISA 2.07 */
2881 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2882 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2883
2884 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 2885 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2886 return;
2887 }
e0498daa
TM
2888
2889 if (!le_is_supported && ctx->le_mode) {
2890 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2891 return;
2892 }
2893
be147d08
JM
2894 ra = rA(ctx->opcode);
2895 rd = rD(ctx->opcode);
2896 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2897 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2898 return;
2899 }
e0498daa 2900
76db3ba4 2901 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2902 EA = tcg_temp_new();
76db3ba4 2903 gen_addr_imm_index(ctx, EA, 0x0F);
e0498daa
TM
2904
2905 if (unlikely(ctx->le_mode)) {
2906 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2907 gen_addr_add(ctx, EA, EA, 8);
2908 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2909 } else {
2910 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2911 gen_addr_add(ctx, EA, EA, 8);
2912 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2913 }
b61f2753 2914 tcg_temp_free(EA);
be147d08 2915}
d9bce9d9 2916#endif
79aceca5
FB
2917
2918/*** Integer store ***/
0c8aacd4 2919#define GEN_ST(name, stop, opc, type) \
99e300ef 2920static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2921{ \
76db3ba4
AJ
2922 TCGv EA; \
2923 gen_set_access_type(ctx, ACCESS_INT); \
2924 EA = tcg_temp_new(); \
2925 gen_addr_imm_index(ctx, EA, 0); \
2926 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2927 tcg_temp_free(EA); \
79aceca5
FB
2928}
2929
0c8aacd4 2930#define GEN_STU(name, stop, opc, type) \
99e300ef 2931static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2932{ \
b61f2753 2933 TCGv EA; \
76a66253 2934 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2935 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2936 return; \
9a64fbe4 2937 } \
76db3ba4 2938 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2939 EA = tcg_temp_new(); \
9d53c753 2940 if (type == PPC_64B) \
76db3ba4 2941 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2942 else \
76db3ba4
AJ
2943 gen_addr_imm_index(ctx, EA, 0); \
2944 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2945 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2946 tcg_temp_free(EA); \
79aceca5
FB
2947}
2948
0c8aacd4 2949#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2950static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2951{ \
b61f2753 2952 TCGv EA; \
76a66253 2953 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2954 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2955 return; \
9a64fbe4 2956 } \
76db3ba4 2957 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2958 EA = tcg_temp_new(); \
76db3ba4
AJ
2959 gen_addr_reg_index(ctx, EA); \
2960 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2961 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2962 tcg_temp_free(EA); \
79aceca5
FB
2963}
2964
cd6e9320
TH
2965#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2966static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2967{ \
76db3ba4
AJ
2968 TCGv EA; \
2969 gen_set_access_type(ctx, ACCESS_INT); \
2970 EA = tcg_temp_new(); \
2971 gen_addr_reg_index(ctx, EA); \
2972 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2973 tcg_temp_free(EA); \
79aceca5 2974}
cd6e9320
TH
2975#define GEN_STX(name, stop, opc2, opc3, type) \
2976 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 2977
0c8aacd4
AJ
2978#define GEN_STS(name, stop, op, type) \
2979GEN_ST(name, stop, op | 0x20, type); \
2980GEN_STU(name, stop, op | 0x21, type); \
2981GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2982GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
2983
2984/* stb stbu stbux stbx */
0c8aacd4 2985GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 2986/* sth sthu sthux sthx */
0c8aacd4 2987GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 2988/* stw stwu stwux stwx */
0c8aacd4 2989GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 2990#if defined(TARGET_PPC64)
0c8aacd4
AJ
2991GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2992GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
2993
2994static void gen_std(DisasContext *ctx)
d9bce9d9 2995{
be147d08 2996 int rs;
b61f2753 2997 TCGv EA;
be147d08
JM
2998
2999 rs = rS(ctx->opcode);
84cab1e2
TM
3000 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3001
3002 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3003 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3004
3005 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 3006 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3007 return;
3008 }
84cab1e2
TM
3009
3010 if (!le_is_supported && ctx->le_mode) {
3011 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
d9bce9d9
JM
3012 return;
3013 }
84cab1e2
TM
3014
3015 if (unlikely(rs & 1)) {
3016 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3017 return;
3018 }
76db3ba4 3019 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3020 EA = tcg_temp_new();
76db3ba4 3021 gen_addr_imm_index(ctx, EA, 0x03);
84cab1e2
TM
3022
3023 if (unlikely(ctx->le_mode)) {
3024 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3025 gen_addr_add(ctx, EA, EA, 8);
3026 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3027 } else {
3028 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3029 gen_addr_add(ctx, EA, EA, 8);
3030 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3031 }
b61f2753 3032 tcg_temp_free(EA);
be147d08 3033 } else {
84cab1e2 3034 /* std / stdu*/
be147d08
JM
3035 if (Rc(ctx->opcode)) {
3036 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 3037 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3038 return;
3039 }
3040 }
76db3ba4 3041 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3042 EA = tcg_temp_new();
76db3ba4
AJ
3043 gen_addr_imm_index(ctx, EA, 0x03);
3044 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 3045 if (Rc(ctx->opcode))
b61f2753
AJ
3046 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3047 tcg_temp_free(EA);
d9bce9d9 3048 }
d9bce9d9
JM
3049}
3050#endif
79aceca5
FB
3051/*** Integer load and store with byte reverse ***/
3052/* lhbrx */
86178a57 3053static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3054{
76db3ba4
AJ
3055 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
3056 if (likely(!ctx->le_mode)) {
fa3966a3 3057 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 3058 }
b61f2753 3059}
0c8aacd4 3060GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 3061
79aceca5 3062/* lwbrx */
86178a57 3063static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3064{
76db3ba4
AJ
3065 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
3066 if (likely(!ctx->le_mode)) {
fa3966a3 3067 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 3068 }
b61f2753 3069}
0c8aacd4 3070GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 3071
cd6e9320
TH
3072#if defined(TARGET_PPC64)
3073/* ldbrx */
3074static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3075{
3076 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
3077 if (likely(!ctx->le_mode)) {
3078 tcg_gen_bswap64_tl(arg1, arg1);
3079 }
3080}
3081GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3082#endif /* TARGET_PPC64 */
3083
79aceca5 3084/* sthbrx */
86178a57 3085static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3086{
76db3ba4 3087 if (likely(!ctx->le_mode)) {
76db3ba4
AJ
3088 TCGv t0 = tcg_temp_new();
3089 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 3090 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
3091 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
3092 tcg_temp_free(t0);
76db3ba4
AJ
3093 } else {
3094 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
3095 }
b61f2753 3096}
0c8aacd4 3097GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 3098
79aceca5 3099/* stwbrx */
86178a57 3100static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3101{
76db3ba4 3102 if (likely(!ctx->le_mode)) {
fa3966a3
AJ
3103 TCGv t0 = tcg_temp_new();
3104 tcg_gen_ext32u_tl(t0, arg1);
3105 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
3106 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
3107 tcg_temp_free(t0);
76db3ba4
AJ
3108 } else {
3109 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
3110 }
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{
3118 if (likely(!ctx->le_mode)) {
3119 TCGv t0 = tcg_temp_new();
3120 tcg_gen_bswap64_tl(t0, arg1);
3121 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
3122 tcg_temp_free(t0);
3123 } else {
3124 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
3125 }
3126}
3127GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3128#endif /* TARGET_PPC64 */
3129
79aceca5 3130/*** Integer load and store multiple ***/
99e300ef 3131
54623277 3132/* lmw */
99e300ef 3133static void gen_lmw(DisasContext *ctx)
79aceca5 3134{
76db3ba4
AJ
3135 TCGv t0;
3136 TCGv_i32 t1;
3137 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3138 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3139 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3140 t0 = tcg_temp_new();
3141 t1 = tcg_const_i32(rD(ctx->opcode));
3142 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3143 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3144 tcg_temp_free(t0);
3145 tcg_temp_free_i32(t1);
79aceca5
FB
3146}
3147
3148/* stmw */
99e300ef 3149static void gen_stmw(DisasContext *ctx)
79aceca5 3150{
76db3ba4
AJ
3151 TCGv t0;
3152 TCGv_i32 t1;
3153 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3154 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3155 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3156 t0 = tcg_temp_new();
3157 t1 = tcg_const_i32(rS(ctx->opcode));
3158 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3159 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3160 tcg_temp_free(t0);
3161 tcg_temp_free_i32(t1);
79aceca5
FB
3162}
3163
3164/*** Integer load and store strings ***/
54623277 3165
79aceca5 3166/* lswi */
3fc6c082 3167/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3168 * rA is in the range of registers to be loaded.
3169 * In an other hand, IBM says this is valid, but rA won't be loaded.
3170 * For now, I'll follow the spec...
3171 */
99e300ef 3172static void gen_lswi(DisasContext *ctx)
79aceca5 3173{
dfbc799d
AJ
3174 TCGv t0;
3175 TCGv_i32 t1, t2;
79aceca5
FB
3176 int nb = NB(ctx->opcode);
3177 int start = rD(ctx->opcode);
9a64fbe4 3178 int ra = rA(ctx->opcode);
79aceca5
FB
3179 int nr;
3180
3181 if (nb == 0)
3182 nb = 32;
3183 nr = nb / 4;
76a66253
JM
3184 if (unlikely(((start + nr) > 32 &&
3185 start <= ra && (start + nr - 32) > ra) ||
3186 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
e06fcd75 3187 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3188 return;
297d8e62 3189 }
76db3ba4 3190 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3191 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3192 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3193 t0 = tcg_temp_new();
76db3ba4 3194 gen_addr_register(ctx, t0);
dfbc799d
AJ
3195 t1 = tcg_const_i32(nb);
3196 t2 = tcg_const_i32(start);
2f5a189c 3197 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3198 tcg_temp_free(t0);
3199 tcg_temp_free_i32(t1);
3200 tcg_temp_free_i32(t2);
79aceca5
FB
3201}
3202
3203/* lswx */
99e300ef 3204static void gen_lswx(DisasContext *ctx)
79aceca5 3205{
76db3ba4
AJ
3206 TCGv t0;
3207 TCGv_i32 t1, t2, t3;
3208 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3209 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3210 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3211 t0 = tcg_temp_new();
3212 gen_addr_reg_index(ctx, t0);
3213 t1 = tcg_const_i32(rD(ctx->opcode));
3214 t2 = tcg_const_i32(rA(ctx->opcode));
3215 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3216 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3217 tcg_temp_free(t0);
3218 tcg_temp_free_i32(t1);
3219 tcg_temp_free_i32(t2);
3220 tcg_temp_free_i32(t3);
79aceca5
FB
3221}
3222
3223/* stswi */
99e300ef 3224static void gen_stswi(DisasContext *ctx)
79aceca5 3225{
76db3ba4
AJ
3226 TCGv t0;
3227 TCGv_i32 t1, t2;
4b3686fa 3228 int nb = NB(ctx->opcode);
76db3ba4 3229 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3230 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3231 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3232 t0 = tcg_temp_new();
3233 gen_addr_register(ctx, t0);
4b3686fa
FB
3234 if (nb == 0)
3235 nb = 32;
dfbc799d 3236 t1 = tcg_const_i32(nb);
76db3ba4 3237 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3238 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3239 tcg_temp_free(t0);
3240 tcg_temp_free_i32(t1);
3241 tcg_temp_free_i32(t2);
79aceca5
FB
3242}
3243
3244/* stswx */
99e300ef 3245static void gen_stswx(DisasContext *ctx)
79aceca5 3246{
76db3ba4
AJ
3247 TCGv t0;
3248 TCGv_i32 t1, t2;
3249 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3250 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3251 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3252 t0 = tcg_temp_new();
3253 gen_addr_reg_index(ctx, t0);
3254 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3255 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3256 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3257 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3258 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3259 tcg_temp_free(t0);
3260 tcg_temp_free_i32(t1);
3261 tcg_temp_free_i32(t2);
79aceca5
FB
3262}
3263
3264/*** Memory synchronisation ***/
3265/* eieio */
99e300ef 3266static void gen_eieio(DisasContext *ctx)
79aceca5 3267{
79aceca5
FB
3268}
3269
3270/* isync */
99e300ef 3271static void gen_isync(DisasContext *ctx)
79aceca5 3272{
e06fcd75 3273 gen_stop_exception(ctx);
79aceca5
FB
3274}
3275
5c77a786
TM
3276#define LARX(name, len, loadop) \
3277static void gen_##name(DisasContext *ctx) \
3278{ \
3279 TCGv t0; \
3280 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3281 gen_set_access_type(ctx, ACCESS_RES); \
3282 t0 = tcg_temp_local_new(); \
3283 gen_addr_reg_index(ctx, t0); \
3284 if ((len) > 1) { \
3285 gen_check_align(ctx, t0, (len)-1); \
3286 } \
3287 gen_qemu_##loadop(ctx, gpr, t0); \
3288 tcg_gen_mov_tl(cpu_reserve, t0); \
3289 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3290 tcg_temp_free(t0); \
79aceca5
FB
3291}
3292
5c77a786
TM
3293/* lwarx */
3294LARX(lbarx, 1, ld8u);
3295LARX(lharx, 2, ld16u);
3296LARX(lwarx, 4, ld32u);
3297
3298
4425265b 3299#if defined(CONFIG_USER_ONLY)
587c51f7
TM
3300static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3301 int reg, int size)
4425265b
NF
3302{
3303 TCGv t0 = tcg_temp_new();
3304 uint32_t save_exception = ctx->exception;
3305
1328c2bf 3306 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3307 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3308 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3309 tcg_temp_free(t0);
3310 gen_update_nip(ctx, ctx->nip-4);
3311 ctx->exception = POWERPC_EXCP_BRANCH;
3312 gen_exception(ctx, POWERPC_EXCP_STCX);
3313 ctx->exception = save_exception;
3314}
4425265b 3315#else
587c51f7
TM
3316static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3317 int reg, int size)
3318{
3319 int l1;
4425265b 3320
587c51f7
TM
3321 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3322 l1 = gen_new_label();
3323 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3324 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3325#if defined(TARGET_PPC64)
3326 if (size == 8) {
3327 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3328 } else
3329#endif
3330 if (size == 4) {
3331 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3332 } else if (size == 2) {
3333 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
27b95bfe
TM
3334#if defined(TARGET_PPC64)
3335 } else if (size == 16) {
3707cd62 3336 TCGv gpr1, gpr2 , EA8;
27b95bfe
TM
3337 if (unlikely(ctx->le_mode)) {
3338 gpr1 = cpu_gpr[reg+1];
3339 gpr2 = cpu_gpr[reg];
3340 } else {
3341 gpr1 = cpu_gpr[reg];
3342 gpr2 = cpu_gpr[reg+1];
3343 }
3344 gen_qemu_st64(ctx, gpr1, EA);
3707cd62
TM
3345 EA8 = tcg_temp_local_new();
3346 gen_addr_add(ctx, EA8, EA, 8);
3347 gen_qemu_st64(ctx, gpr2, EA8);
3348 tcg_temp_free(EA8);
27b95bfe 3349#endif
587c51f7
TM
3350 } else {
3351 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
4425265b 3352 }
587c51f7
TM
3353 gen_set_label(l1);
3354 tcg_gen_movi_tl(cpu_reserve, -1);
3355}
4425265b 3356#endif
587c51f7
TM
3357
3358#define STCX(name, len) \
3359static void gen_##name(DisasContext *ctx) \
3360{ \
3361 TCGv t0; \
27b95bfe
TM
3362 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3363 gen_inval_exception(ctx, \
3364 POWERPC_EXCP_INVAL_INVAL); \
3365 return; \
3366 } \
587c51f7
TM
3367 gen_set_access_type(ctx, ACCESS_RES); \
3368 t0 = tcg_temp_local_new(); \
3369 gen_addr_reg_index(ctx, t0); \
3370 if (len > 1) { \
3371 gen_check_align(ctx, t0, (len)-1); \
3372 } \
3373 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3374 tcg_temp_free(t0); \
79aceca5
FB
3375}
3376
587c51f7
TM
3377STCX(stbcx_, 1);
3378STCX(sthcx_, 2);
3379STCX(stwcx_, 4);
3380
426613db 3381#if defined(TARGET_PPC64)
426613db 3382/* ldarx */
5c77a786 3383LARX(ldarx, 8, ld64);
426613db 3384
9c294d5a
TM
3385/* lqarx */
3386static void gen_lqarx(DisasContext *ctx)
3387{
3388 TCGv EA;
3389 int rd = rD(ctx->opcode);
3390 TCGv gpr1, gpr2;
3391
3392 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3393 (rd == rB(ctx->opcode)))) {
3394 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3395 return;
3396 }
3397
3398 gen_set_access_type(ctx, ACCESS_RES);
3399 EA = tcg_temp_local_new();
3400 gen_addr_reg_index(ctx, EA);
3401 gen_check_align(ctx, EA, 15);
3402 if (unlikely(ctx->le_mode)) {
3403 gpr1 = cpu_gpr[rd+1];
3404 gpr2 = cpu_gpr[rd];
3405 } else {
3406 gpr1 = cpu_gpr[rd];
3407 gpr2 = cpu_gpr[rd+1];
3408 }
3409 gen_qemu_ld64(ctx, gpr1, EA);
3410 tcg_gen_mov_tl(cpu_reserve, EA);
3411
3412 gen_addr_add(ctx, EA, EA, 8);
3413 gen_qemu_ld64(ctx, gpr2, EA);
3414
3415 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3416 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3417
3418 tcg_temp_free(EA);
3419}
3420
426613db 3421/* stdcx. */
587c51f7 3422STCX(stdcx_, 8);
27b95bfe 3423STCX(stqcx_, 16);
426613db
JM
3424#endif /* defined(TARGET_PPC64) */
3425
79aceca5 3426/* sync */
99e300ef 3427static void gen_sync(DisasContext *ctx)
79aceca5 3428{
79aceca5
FB
3429}
3430
0db1b20e 3431/* wait */
99e300ef 3432static void gen_wait(DisasContext *ctx)
0db1b20e 3433{
931ff272 3434 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3435 tcg_gen_st_i32(t0, cpu_env,
3436 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3437 tcg_temp_free_i32(t0);
0db1b20e 3438 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3439 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3440}
3441
79aceca5 3442/*** Floating-point load ***/
a0d7d5a7 3443#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3444static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3445{ \
a0d7d5a7 3446 TCGv EA; \
76a66253 3447 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3448 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3449 return; \
3450 } \
76db3ba4 3451 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3452 EA = tcg_temp_new(); \
76db3ba4
AJ
3453 gen_addr_imm_index(ctx, EA, 0); \
3454 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3455 tcg_temp_free(EA); \
79aceca5
FB
3456}
3457
a0d7d5a7 3458#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3459static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3460{ \
a0d7d5a7 3461 TCGv EA; \
76a66253 3462 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3463 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3464 return; \
3465 } \
76a66253 3466 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3467 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3468 return; \
9a64fbe4 3469 } \
76db3ba4 3470 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3471 EA = tcg_temp_new(); \
76db3ba4
AJ
3472 gen_addr_imm_index(ctx, EA, 0); \
3473 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3474 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3475 tcg_temp_free(EA); \
79aceca5
FB
3476}
3477
a0d7d5a7 3478#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3479static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3480{ \
a0d7d5a7 3481 TCGv EA; \
76a66253 3482 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3483 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3484 return; \
3485 } \
76a66253 3486 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3487 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3488 return; \
9a64fbe4 3489 } \
76db3ba4 3490 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3491 EA = tcg_temp_new(); \
76db3ba4
AJ
3492 gen_addr_reg_index(ctx, EA); \
3493 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3494 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3495 tcg_temp_free(EA); \
79aceca5
FB
3496}
3497
a0d7d5a7 3498#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3499static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3500{ \
a0d7d5a7 3501 TCGv EA; \
76a66253 3502 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3503 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3504 return; \
3505 } \
76db3ba4 3506 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3507 EA = tcg_temp_new(); \
76db3ba4
AJ
3508 gen_addr_reg_index(ctx, EA); \
3509 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3510 tcg_temp_free(EA); \
79aceca5
FB
3511}
3512
a0d7d5a7
AJ
3513#define GEN_LDFS(name, ldop, op, type) \
3514GEN_LDF(name, ldop, op | 0x20, type); \
3515GEN_LDUF(name, ldop, op | 0x21, type); \
3516GEN_LDUXF(name, ldop, op | 0x01, type); \
3517GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3518
636aa200 3519static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3520{
3521 TCGv t0 = tcg_temp_new();
3522 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3523 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3524 tcg_gen_trunc_tl_i32(t1, t0);
3525 tcg_temp_free(t0);
8e703949 3526 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3527 tcg_temp_free_i32(t1);
3528}
79aceca5 3529
a0d7d5a7
AJ
3530 /* lfd lfdu lfdux lfdx */
3531GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3532 /* lfs lfsu lfsux lfsx */
3533GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3534
05050ee8
AJ
3535/* lfdp */
3536static void gen_lfdp(DisasContext *ctx)
3537{
3538 TCGv EA;
3539 if (unlikely(!ctx->fpu_enabled)) {
3540 gen_exception(ctx, POWERPC_EXCP_FPU);
3541 return;
3542 }
3543 gen_set_access_type(ctx, ACCESS_FLOAT);
3544 EA = tcg_temp_new();
3545 gen_addr_imm_index(ctx, EA, 0); \
3546 if (unlikely(ctx->le_mode)) {
3547 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3548 tcg_gen_addi_tl(EA, EA, 8);
3549 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3550 } else {
3551 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3552 tcg_gen_addi_tl(EA, EA, 8);
3553 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3554 }
3555 tcg_temp_free(EA);
3556}
3557
3558/* lfdpx */
3559static void gen_lfdpx(DisasContext *ctx)
3560{
3561 TCGv EA;
3562 if (unlikely(!ctx->fpu_enabled)) {
3563 gen_exception(ctx, POWERPC_EXCP_FPU);
3564 return;
3565 }
3566 gen_set_access_type(ctx, ACCESS_FLOAT);
3567 EA = tcg_temp_new();
3568 gen_addr_reg_index(ctx, EA);
3569 if (unlikely(ctx->le_mode)) {
3570 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3571 tcg_gen_addi_tl(EA, EA, 8);
3572 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3573 } else {
3574 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3575 tcg_gen_addi_tl(EA, EA, 8);
3576 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3577 }
3578 tcg_temp_free(EA);
3579}
3580
199f830d
AJ
3581/* lfiwax */
3582static void gen_lfiwax(DisasContext *ctx)
3583{
3584 TCGv EA;
3585 TCGv t0;
3586 if (unlikely(!ctx->fpu_enabled)) {
3587 gen_exception(ctx, POWERPC_EXCP_FPU);
3588 return;
3589 }
3590 gen_set_access_type(ctx, ACCESS_FLOAT);
3591 EA = tcg_temp_new();
3592 t0 = tcg_temp_new();
3593 gen_addr_reg_index(ctx, EA);
909eedb7 3594 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3595 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3596 tcg_temp_free(EA);
3597 tcg_temp_free(t0);
3598}
3599
66c3e328
TM
3600/* lfiwzx */
3601static void gen_lfiwzx(DisasContext *ctx)
3602{
3603 TCGv EA;
3604 if (unlikely(!ctx->fpu_enabled)) {
3605 gen_exception(ctx, POWERPC_EXCP_FPU);
3606 return;
3607 }
3608 gen_set_access_type(ctx, ACCESS_FLOAT);
3609 EA = tcg_temp_new();
3610 gen_addr_reg_index(ctx, EA);
3611 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3612 tcg_temp_free(EA);
3613}
79aceca5 3614/*** Floating-point store ***/
a0d7d5a7 3615#define GEN_STF(name, stop, opc, type) \
99e300ef 3616static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3617{ \
a0d7d5a7 3618 TCGv EA; \
76a66253 3619 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3620 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3621 return; \
3622 } \
76db3ba4 3623 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3624 EA = tcg_temp_new(); \
76db3ba4
AJ
3625 gen_addr_imm_index(ctx, EA, 0); \
3626 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3627 tcg_temp_free(EA); \
79aceca5
FB
3628}
3629
a0d7d5a7 3630#define GEN_STUF(name, stop, opc, type) \
99e300ef 3631static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3632{ \
a0d7d5a7 3633 TCGv EA; \
76a66253 3634 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3635 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3636 return; \
3637 } \
76a66253 3638 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3639 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3640 return; \
9a64fbe4 3641 } \
76db3ba4 3642 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3643 EA = tcg_temp_new(); \
76db3ba4
AJ
3644 gen_addr_imm_index(ctx, EA, 0); \
3645 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3646 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3647 tcg_temp_free(EA); \
79aceca5
FB
3648}
3649
a0d7d5a7 3650#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3651static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3652{ \
a0d7d5a7 3653 TCGv EA; \
76a66253 3654 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3655 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3656 return; \
3657 } \
76a66253 3658 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3659 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3660 return; \
9a64fbe4 3661 } \
76db3ba4 3662 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3663 EA = tcg_temp_new(); \
76db3ba4
AJ
3664 gen_addr_reg_index(ctx, EA); \
3665 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3666 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3667 tcg_temp_free(EA); \
79aceca5
FB
3668}
3669
a0d7d5a7 3670#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3671static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3672{ \
a0d7d5a7 3673 TCGv EA; \
76a66253 3674 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3675 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3676 return; \
3677 } \
76db3ba4 3678 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3679 EA = tcg_temp_new(); \
76db3ba4
AJ
3680 gen_addr_reg_index(ctx, EA); \
3681 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3682 tcg_temp_free(EA); \
79aceca5
FB
3683}
3684
a0d7d5a7
AJ
3685#define GEN_STFS(name, stop, op, type) \
3686GEN_STF(name, stop, op | 0x20, type); \
3687GEN_STUF(name, stop, op | 0x21, type); \
3688GEN_STUXF(name, stop, op | 0x01, type); \
3689GEN_STXF(name, stop, 0x17, op | 0x00, type)
3690
636aa200 3691static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3692{
3693 TCGv_i32 t0 = tcg_temp_new_i32();
3694 TCGv t1 = tcg_temp_new();
8e703949 3695 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3696 tcg_gen_extu_i32_tl(t1, t0);
3697 tcg_temp_free_i32(t0);
76db3ba4 3698 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3699 tcg_temp_free(t1);
3700}
79aceca5
FB
3701
3702/* stfd stfdu stfdux stfdx */
a0d7d5a7 3703GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3704/* stfs stfsu stfsux stfsx */
a0d7d5a7 3705GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3706
44bc0c4d
AJ
3707/* stfdp */
3708static void gen_stfdp(DisasContext *ctx)
3709{
3710 TCGv EA;
3711 if (unlikely(!ctx->fpu_enabled)) {
3712 gen_exception(ctx, POWERPC_EXCP_FPU);
3713 return;
3714 }
3715 gen_set_access_type(ctx, ACCESS_FLOAT);
3716 EA = tcg_temp_new();
3717 gen_addr_imm_index(ctx, EA, 0); \
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);
3741 if (unlikely(ctx->le_mode)) {
3742 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3743 tcg_gen_addi_tl(EA, EA, 8);
3744 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3745 } else {
3746 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3747 tcg_gen_addi_tl(EA, EA, 8);
3748 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3749 }
3750 tcg_temp_free(EA);
3751}
3752
79aceca5 3753/* Optional: */
636aa200 3754static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3755{
3756 TCGv t0 = tcg_temp_new();
3757 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3758 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3759 tcg_temp_free(t0);
3760}
79aceca5 3761/* stfiwx */
a0d7d5a7 3762GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3763
697ab892
DG
3764static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3765{
3766#if defined(TARGET_PPC64)
3767 if (ctx->has_cfar)
3768 tcg_gen_movi_tl(cpu_cfar, nip);
3769#endif
3770}
3771
79aceca5 3772/*** Branch ***/
636aa200 3773static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362
FB
3774{
3775 TranslationBlock *tb;
3776 tb = ctx->tb;
e0c8f9ce 3777 if (NARROW_MODE(ctx)) {
a2ffb812 3778 dest = (uint32_t) dest;
e0c8f9ce 3779 }
57fec1fe 3780 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
8cbcb4fa 3781 likely(!ctx->singlestep_enabled)) {
57fec1fe 3782 tcg_gen_goto_tb(n);
a2ffb812 3783 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cfd0495 3784 tcg_gen_exit_tb((uintptr_t)tb + n);
c1942362 3785 } else {
a2ffb812 3786 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3787 if (unlikely(ctx->singlestep_enabled)) {
3788 if ((ctx->singlestep_enabled &
bdc4e053 3789 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3790 (ctx->exception == POWERPC_EXCP_BRANCH ||
3791 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3792 target_ulong tmp = ctx->nip;
3793 ctx->nip = dest;
e06fcd75 3794 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3795 ctx->nip = tmp;
3796 }
3797 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3798 gen_debug_exception(ctx);
8cbcb4fa
AJ
3799 }
3800 }
57fec1fe 3801 tcg_gen_exit_tb(0);
c1942362 3802 }
c53be334
FB
3803}
3804
636aa200 3805static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3806{
e0c8f9ce
RH
3807 if (NARROW_MODE(ctx)) {
3808 nip = (uint32_t)nip;
3809 }
3810 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3811}
3812
79aceca5 3813/* b ba bl bla */
99e300ef 3814static void gen_b(DisasContext *ctx)
79aceca5 3815{
76a66253 3816 target_ulong li, target;
38a64f9d 3817
8cbcb4fa 3818 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3819 /* sign extend LI */
e0c8f9ce
RH
3820 li = LI(ctx->opcode);
3821 li = (li ^ 0x02000000) - 0x02000000;
3822 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3823 target = ctx->nip + li - 4;
e0c8f9ce 3824 } else {
9a64fbe4 3825 target = li;
e0c8f9ce
RH
3826 }
3827 if (LK(ctx->opcode)) {
e1833e1f 3828 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3829 }
697ab892 3830 gen_update_cfar(ctx, ctx->nip);
c1942362 3831 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3832}
3833
e98a6e40
FB
3834#define BCOND_IM 0
3835#define BCOND_LR 1
3836#define BCOND_CTR 2
52a4984d 3837#define BCOND_TAR 3
e98a6e40 3838
636aa200 3839static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3840{
d9bce9d9 3841 uint32_t bo = BO(ctx->opcode);
05f92404 3842 int l1;
a2ffb812 3843 TCGv target;
e98a6e40 3844
8cbcb4fa 3845 ctx->exception = POWERPC_EXCP_BRANCH;
52a4984d 3846 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
a7812ae4 3847 target = tcg_temp_local_new();
a2ffb812
AJ
3848 if (type == BCOND_CTR)
3849 tcg_gen_mov_tl(target, cpu_ctr);
52a4984d
TM
3850 else if (type == BCOND_TAR)
3851 gen_load_spr(target, SPR_TAR);
a2ffb812
AJ
3852 else
3853 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3854 } else {
3855 TCGV_UNUSED(target);
e98a6e40 3856 }
e1833e1f
JM
3857 if (LK(ctx->opcode))
3858 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3859 l1 = gen_new_label();
3860 if ((bo & 0x4) == 0) {
3861 /* Decrement and test CTR */
a7812ae4 3862 TCGv temp = tcg_temp_new();
a2ffb812 3863 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3864 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3865 return;
3866 }
3867 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3868 if (NARROW_MODE(ctx)) {
a2ffb812 3869 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3870 } else {
a2ffb812 3871 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3872 }
a2ffb812
AJ
3873 if (bo & 0x2) {
3874 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3875 } else {
3876 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3877 }
a7812ae4 3878 tcg_temp_free(temp);
a2ffb812
AJ
3879 }
3880 if ((bo & 0x10) == 0) {
3881 /* Test CR */
3882 uint32_t bi = BI(ctx->opcode);
3883 uint32_t mask = 1 << (3 - (bi & 0x03));
a7812ae4 3884 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3885
d9bce9d9 3886 if (bo & 0x8) {
a2ffb812
AJ
3887 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3888 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3889 } else {
a2ffb812
AJ
3890 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3891 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3892 }
a7812ae4 3893 tcg_temp_free_i32(temp);
d9bce9d9 3894 }
697ab892 3895 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3896 if (type == BCOND_IM) {
a2ffb812
AJ
3897 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3898 if (likely(AA(ctx->opcode) == 0)) {
3899 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3900 } else {
3901 gen_goto_tb(ctx, 0, li);
3902 }
c53be334 3903 gen_set_label(l1);
c1942362 3904 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3905 } else {
e0c8f9ce 3906 if (NARROW_MODE(ctx)) {
a2ffb812 3907 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3908 } else {
a2ffb812 3909 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3910 }
a2ffb812
AJ
3911 tcg_gen_exit_tb(0);
3912 gen_set_label(l1);
e0c8f9ce 3913 gen_update_nip(ctx, ctx->nip);
57fec1fe 3914 tcg_gen_exit_tb(0);
08e46e54 3915 }
e98a6e40
FB
3916}
3917
99e300ef 3918static void gen_bc(DisasContext *ctx)
3b46e624 3919{
e98a6e40
FB
3920 gen_bcond(ctx, BCOND_IM);
3921}
3922
99e300ef 3923static void gen_bcctr(DisasContext *ctx)
3b46e624 3924{
e98a6e40
FB
3925 gen_bcond(ctx, BCOND_CTR);
3926}
3927
99e300ef 3928static void gen_bclr(DisasContext *ctx)
3b46e624 3929{
e98a6e40
FB
3930 gen_bcond(ctx, BCOND_LR);
3931}
79aceca5 3932
52a4984d
TM
3933static void gen_bctar(DisasContext *ctx)
3934{
3935 gen_bcond(ctx, BCOND_TAR);
3936}
3937
79aceca5 3938/*** Condition register logical ***/
e1571908 3939#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 3940static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3941{ \
fc0d441e
JM
3942 uint8_t bitmask; \
3943 int sh; \
a7812ae4 3944 TCGv_i32 t0, t1; \
fc0d441e 3945 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 3946 t0 = tcg_temp_new_i32(); \
fc0d441e 3947 if (sh > 0) \
fea0c503 3948 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 3949 else if (sh < 0) \
fea0c503 3950 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 3951 else \
fea0c503 3952 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 3953 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
3954 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3955 if (sh > 0) \
fea0c503 3956 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 3957 else if (sh < 0) \
fea0c503 3958 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 3959 else \
fea0c503
AJ
3960 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3961 tcg_op(t0, t0, t1); \
fc0d441e 3962 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
fea0c503
AJ
3963 tcg_gen_andi_i32(t0, t0, bitmask); \
3964 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3965 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
3966 tcg_temp_free_i32(t0); \
3967 tcg_temp_free_i32(t1); \
79aceca5
FB
3968}
3969
3970/* crand */
e1571908 3971GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 3972/* crandc */
e1571908 3973GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 3974/* creqv */
e1571908 3975GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 3976/* crnand */
e1571908 3977GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 3978/* crnor */
e1571908 3979GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 3980/* cror */
e1571908 3981GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 3982/* crorc */
e1571908 3983GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 3984/* crxor */
e1571908 3985GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 3986
54623277 3987/* mcrf */
99e300ef 3988static void gen_mcrf(DisasContext *ctx)
79aceca5 3989{
47e4661c 3990 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
3991}
3992
3993/*** System linkage ***/
99e300ef 3994
54623277 3995/* rfi (mem_idx only) */
99e300ef 3996static void gen_rfi(DisasContext *ctx)
79aceca5 3997{
9a64fbe4 3998#if defined(CONFIG_USER_ONLY)
e06fcd75 3999 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
4000#else
4001 /* Restore CPU state */
76db3ba4 4002 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4003 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4004 return;
9a64fbe4 4005 }
697ab892 4006 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4007 gen_helper_rfi(cpu_env);
e06fcd75 4008 gen_sync_exception(ctx);
9a64fbe4 4009#endif
79aceca5
FB
4010}
4011
426613db 4012#if defined(TARGET_PPC64)
99e300ef 4013static void gen_rfid(DisasContext *ctx)
426613db
JM
4014{
4015#if defined(CONFIG_USER_ONLY)
e06fcd75 4016 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4017#else
4018 /* Restore CPU state */
76db3ba4 4019 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4020 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4021 return;
4022 }
697ab892 4023 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4024 gen_helper_rfid(cpu_env);
e06fcd75 4025 gen_sync_exception(ctx);
426613db
JM
4026#endif
4027}
426613db 4028
99e300ef 4029static void gen_hrfid(DisasContext *ctx)
be147d08
JM
4030{
4031#if defined(CONFIG_USER_ONLY)
e06fcd75 4032 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4033#else
4034 /* Restore CPU state */
76db3ba4 4035 if (unlikely(ctx->mem_idx <= 1)) {
e06fcd75 4036 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4037 return;
4038 }
e5f17ac6 4039 gen_helper_hrfid(cpu_env);
e06fcd75 4040 gen_sync_exception(ctx);
be147d08
JM
4041#endif
4042}
4043#endif
4044
79aceca5 4045/* sc */
417bf010
JM
4046#if defined(CONFIG_USER_ONLY)
4047#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4048#else
4049#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4050#endif
99e300ef 4051static void gen_sc(DisasContext *ctx)
79aceca5 4052{
e1833e1f
JM
4053 uint32_t lev;
4054
4055 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 4056 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
4057}
4058
4059/*** Trap ***/
99e300ef 4060
54623277 4061/* tw */
99e300ef 4062static void gen_tw(DisasContext *ctx)
79aceca5 4063{
cab3bee2 4064 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4065 /* Update the nip since this might generate a trap exception */
4066 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4067 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4068 t0);
cab3bee2 4069 tcg_temp_free_i32(t0);
79aceca5
FB
4070}
4071
4072/* twi */
99e300ef 4073static void gen_twi(DisasContext *ctx)
79aceca5 4074{
cab3bee2
AJ
4075 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4076 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4077 /* Update the nip since this might generate a trap exception */
4078 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4079 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4080 tcg_temp_free(t0);
4081 tcg_temp_free_i32(t1);
79aceca5
FB
4082}
4083
d9bce9d9
JM
4084#if defined(TARGET_PPC64)
4085/* td */
99e300ef 4086static void gen_td(DisasContext *ctx)
d9bce9d9 4087{
cab3bee2 4088 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4089 /* Update the nip since this might generate a trap exception */
4090 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4091 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4092 t0);
cab3bee2 4093 tcg_temp_free_i32(t0);
d9bce9d9
JM
4094}
4095
4096/* tdi */
99e300ef 4097static void gen_tdi(DisasContext *ctx)
d9bce9d9 4098{
cab3bee2
AJ
4099 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4100 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4101 /* Update the nip since this might generate a trap exception */
4102 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4103 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4104 tcg_temp_free(t0);
4105 tcg_temp_free_i32(t1);
d9bce9d9
JM
4106}
4107#endif
4108
79aceca5 4109/*** Processor control ***/
99e300ef 4110
da91a00f
RH
4111static void gen_read_xer(TCGv dst)
4112{
4113 TCGv t0 = tcg_temp_new();
4114 TCGv t1 = tcg_temp_new();
4115 TCGv t2 = tcg_temp_new();
4116 tcg_gen_mov_tl(dst, cpu_xer);
4117 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4118 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4119 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4120 tcg_gen_or_tl(t0, t0, t1);
4121 tcg_gen_or_tl(dst, dst, t2);
4122 tcg_gen_or_tl(dst, dst, t0);
4123 tcg_temp_free(t0);
4124 tcg_temp_free(t1);
4125 tcg_temp_free(t2);
4126}
4127
4128static void gen_write_xer(TCGv src)
4129{
4130 tcg_gen_andi_tl(cpu_xer, src,
4131 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4132 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4133 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4134 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4135 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4136 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4137 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4138}
4139
54623277 4140/* mcrxr */
99e300ef 4141static void gen_mcrxr(DisasContext *ctx)
79aceca5 4142{
da91a00f
RH
4143 TCGv_i32 t0 = tcg_temp_new_i32();
4144 TCGv_i32 t1 = tcg_temp_new_i32();
4145 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4146
4147 tcg_gen_trunc_tl_i32(t0, cpu_so);
4148 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4149 tcg_gen_trunc_tl_i32(dst, cpu_ca);
4150 tcg_gen_shri_i32(t0, t0, 2);
4151 tcg_gen_shri_i32(t1, t1, 1);
4152 tcg_gen_or_i32(dst, dst, t0);
4153 tcg_gen_or_i32(dst, dst, t1);
4154 tcg_temp_free_i32(t0);
4155 tcg_temp_free_i32(t1);
4156
4157 tcg_gen_movi_tl(cpu_so, 0);
4158 tcg_gen_movi_tl(cpu_ov, 0);
4159 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
4160}
4161
0cfe11ea 4162/* mfcr mfocrf */
99e300ef 4163static void gen_mfcr(DisasContext *ctx)
79aceca5 4164{
76a66253 4165 uint32_t crm, crn;
3b46e624 4166
76a66253
JM
4167 if (likely(ctx->opcode & 0x00100000)) {
4168 crm = CRM(ctx->opcode);
8dd640e4 4169 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 4170 crn = ctz32 (crm);
e1571908 4171 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
4172 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4173 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 4174 }
d9bce9d9 4175 } else {
651721b2
AJ
4176 TCGv_i32 t0 = tcg_temp_new_i32();
4177 tcg_gen_mov_i32(t0, cpu_crf[0]);
4178 tcg_gen_shli_i32(t0, t0, 4);
4179 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4180 tcg_gen_shli_i32(t0, t0, 4);
4181 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4182 tcg_gen_shli_i32(t0, t0, 4);
4183 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4184 tcg_gen_shli_i32(t0, t0, 4);
4185 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4186 tcg_gen_shli_i32(t0, t0, 4);
4187 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4188 tcg_gen_shli_i32(t0, t0, 4);
4189 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4190 tcg_gen_shli_i32(t0, t0, 4);
4191 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4192 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4193 tcg_temp_free_i32(t0);
d9bce9d9 4194 }
79aceca5
FB
4195}
4196
4197/* mfmsr */
99e300ef 4198static void gen_mfmsr(DisasContext *ctx)
79aceca5 4199{
9a64fbe4 4200#if defined(CONFIG_USER_ONLY)
e06fcd75 4201 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4202#else
76db3ba4 4203 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4204 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4205 return;
9a64fbe4 4206 }
6527f6ea 4207 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4208#endif
79aceca5
FB
4209}
4210
7b13448f 4211static void spr_noaccess(void *opaque, int gprn, int sprn)
3fc6c082 4212{
7b13448f 4213#if 0
3fc6c082
FB
4214 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4215 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4216#endif
3fc6c082
FB
4217}
4218#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4219
79aceca5 4220/* mfspr */
636aa200 4221static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4222{
45d827d2 4223 void (*read_cb)(void *opaque, int gprn, int sprn);
79aceca5
FB
4224 uint32_t sprn = SPR(ctx->opcode);
4225
3fc6c082 4226#if !defined(CONFIG_USER_ONLY)
76db3ba4 4227 if (ctx->mem_idx == 2)
be147d08 4228 read_cb = ctx->spr_cb[sprn].hea_read;
76db3ba4 4229 else if (ctx->mem_idx)
3fc6c082
FB
4230 read_cb = ctx->spr_cb[sprn].oea_read;
4231 else
9a64fbe4 4232#endif
3fc6c082 4233 read_cb = ctx->spr_cb[sprn].uea_read;
76a66253
JM
4234 if (likely(read_cb != NULL)) {
4235 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4236 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4237 } else {
4238 /* Privilege exception */
9fceefa7
JM
4239 /* This is a hack to avoid warnings when running Linux:
4240 * this OS breaks the PowerPC virtualisation model,
4241 * allowing userland application to read the PVR
4242 */
4243 if (sprn != SPR_PVR) {
c05541ee
AB
4244 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4245 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4246 printf("Trying to read privileged spr %d (0x%03x) at "
4247 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
f24e5695 4248 }
e06fcd75 4249 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4250 }
3fc6c082
FB
4251 } else {
4252 /* Not defined */
c05541ee
AB
4253 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4254 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4255 printf("Trying to read invalid spr %d (0x%03x) at "
4256 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4257 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4258 }
79aceca5
FB
4259}
4260
99e300ef 4261static void gen_mfspr(DisasContext *ctx)
79aceca5 4262{
3fc6c082 4263 gen_op_mfspr(ctx);
76a66253 4264}
3fc6c082
FB
4265
4266/* mftb */
99e300ef 4267static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4268{
4269 gen_op_mfspr(ctx);
79aceca5
FB
4270}
4271
0cfe11ea 4272/* mtcrf mtocrf*/
99e300ef 4273static void gen_mtcrf(DisasContext *ctx)
79aceca5 4274{
76a66253 4275 uint32_t crm, crn;
3b46e624 4276
76a66253 4277 crm = CRM(ctx->opcode);
8dd640e4 4278 if (likely((ctx->opcode & 0x00100000))) {
4279 if (crm && ((crm & (crm - 1)) == 0)) {
4280 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4281 crn = ctz32 (crm);
8dd640e4 4282 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4283 tcg_gen_shri_i32(temp, temp, crn * 4);
4284 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4285 tcg_temp_free_i32(temp);
4286 }
76a66253 4287 } else {
651721b2
AJ
4288 TCGv_i32 temp = tcg_temp_new_i32();
4289 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4290 for (crn = 0 ; crn < 8 ; crn++) {
4291 if (crm & (1 << crn)) {
4292 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4293 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4294 }
4295 }
a7812ae4 4296 tcg_temp_free_i32(temp);
76a66253 4297 }
79aceca5
FB
4298}
4299
4300/* mtmsr */
426613db 4301#if defined(TARGET_PPC64)
99e300ef 4302static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4303{
4304#if defined(CONFIG_USER_ONLY)
e06fcd75 4305 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4306#else
76db3ba4 4307 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4308 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4309 return;
4310 }
be147d08
JM
4311 if (ctx->opcode & 0x00010000) {
4312 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4313 TCGv t0 = tcg_temp_new();
4314 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4315 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4316 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4317 tcg_temp_free(t0);
be147d08 4318 } else {
056b05f8
JM
4319 /* XXX: we need to update nip before the store
4320 * if we enter power saving mode, we will exit the loop
4321 * directly from ppc_store_msr
4322 */
be147d08 4323 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4324 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4325 /* Must stop the translation as machine state (may have) changed */
4326 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4327 gen_stop_exception(ctx);
be147d08 4328 }
426613db
JM
4329#endif
4330}
4331#endif
4332
99e300ef 4333static void gen_mtmsr(DisasContext *ctx)
79aceca5 4334{
9a64fbe4 4335#if defined(CONFIG_USER_ONLY)
e06fcd75 4336 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4337#else
76db3ba4 4338 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4339 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4340 return;
9a64fbe4 4341 }
be147d08
JM
4342 if (ctx->opcode & 0x00010000) {
4343 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4344 TCGv t0 = tcg_temp_new();
4345 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4346 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4347 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4348 tcg_temp_free(t0);
be147d08 4349 } else {
8018dc63
AG
4350 TCGv msr = tcg_temp_new();
4351
056b05f8
JM
4352 /* XXX: we need to update nip before the store
4353 * if we enter power saving mode, we will exit the loop
4354 * directly from ppc_store_msr
4355 */
be147d08 4356 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4357#if defined(TARGET_PPC64)
8018dc63
AG
4358 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4359#else
4360 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4361#endif
e5f17ac6 4362 gen_helper_store_msr(cpu_env, msr);
be147d08 4363 /* Must stop the translation as machine state (may have) changed */
6527f6ea 4364 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4365 gen_stop_exception(ctx);
be147d08 4366 }
9a64fbe4 4367#endif
79aceca5
FB
4368}
4369
4370/* mtspr */
99e300ef 4371static void gen_mtspr(DisasContext *ctx)
79aceca5 4372{
45d827d2 4373 void (*write_cb)(void *opaque, int sprn, int gprn);
79aceca5
FB
4374 uint32_t sprn = SPR(ctx->opcode);
4375
3fc6c082 4376#if !defined(CONFIG_USER_ONLY)
76db3ba4 4377 if (ctx->mem_idx == 2)
be147d08 4378 write_cb = ctx->spr_cb[sprn].hea_write;
76db3ba4 4379 else if (ctx->mem_idx)
3fc6c082
FB
4380 write_cb = ctx->spr_cb[sprn].oea_write;
4381 else
9a64fbe4 4382#endif
3fc6c082 4383 write_cb = ctx->spr_cb[sprn].uea_write;
76a66253
JM
4384 if (likely(write_cb != NULL)) {
4385 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 4386 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
4387 } else {
4388 /* Privilege exception */
c05541ee
AB
4389 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4390 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4391 printf("Trying to write privileged spr %d (0x%03x) at "
4392 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4393 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 4394 }
3fc6c082
FB
4395 } else {
4396 /* Not defined */
c05541ee
AB
4397 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4398 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4399 printf("Trying to write invalid spr %d (0x%03x) at "
4400 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4401 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4402 }
79aceca5
FB
4403}
4404
4405/*** Cache management ***/
99e300ef 4406
54623277 4407/* dcbf */
99e300ef 4408static void gen_dcbf(DisasContext *ctx)
79aceca5 4409{
dac454af 4410 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
4411 TCGv t0;
4412 gen_set_access_type(ctx, ACCESS_CACHE);
4413 t0 = tcg_temp_new();
4414 gen_addr_reg_index(ctx, t0);
4415 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4416 tcg_temp_free(t0);
79aceca5
FB
4417}
4418
4419/* dcbi (Supervisor only) */
99e300ef 4420static void gen_dcbi(DisasContext *ctx)
79aceca5 4421{
a541f297 4422#if defined(CONFIG_USER_ONLY)
e06fcd75 4423 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 4424#else
b61f2753 4425 TCGv EA, val;
76db3ba4 4426 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4427 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4428 return;
9a64fbe4 4429 }
a7812ae4 4430 EA = tcg_temp_new();
76db3ba4
AJ
4431 gen_set_access_type(ctx, ACCESS_CACHE);
4432 gen_addr_reg_index(ctx, EA);
a7812ae4 4433 val = tcg_temp_new();
76a66253 4434 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
4435 gen_qemu_ld8u(ctx, val, EA);
4436 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
4437 tcg_temp_free(val);
4438 tcg_temp_free(EA);
a541f297 4439#endif
79aceca5
FB
4440}
4441
4442/* dcdst */
99e300ef 4443static void gen_dcbst(DisasContext *ctx)
79aceca5 4444{
76a66253 4445 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
4446 TCGv t0;
4447 gen_set_access_type(ctx, ACCESS_CACHE);
4448 t0 = tcg_temp_new();
4449 gen_addr_reg_index(ctx, t0);
4450 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4451 tcg_temp_free(t0);
79aceca5
FB
4452}
4453
4454/* dcbt */
99e300ef 4455static void gen_dcbt(DisasContext *ctx)
79aceca5 4456{
0db1b20e 4457 /* interpreted as no-op */
76a66253
JM
4458 /* XXX: specification say this is treated as a load by the MMU
4459 * but does not generate any exception
4460 */
79aceca5
FB
4461}
4462
4463/* dcbtst */
99e300ef 4464static void gen_dcbtst(DisasContext *ctx)
79aceca5 4465{
0db1b20e 4466 /* interpreted as no-op */
76a66253
JM
4467 /* XXX: specification say this is treated as a load by the MMU
4468 * but does not generate any exception
4469 */
79aceca5
FB
4470}
4471
4472/* dcbz */
99e300ef 4473static void gen_dcbz(DisasContext *ctx)
79aceca5 4474{
8e33944f
AG
4475 TCGv tcgv_addr;
4476 TCGv_i32 tcgv_is_dcbzl;
4477 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4478
76db3ba4 4479 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4480 /* NIP cannot be restored if the memory exception comes from an helper */
4481 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4482 tcgv_addr = tcg_temp_new();
4483 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4484
4485 gen_addr_reg_index(ctx, tcgv_addr);
4486 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4487
4488 tcg_temp_free(tcgv_addr);
4489 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4490}
4491
ae1c1a3d 4492/* dst / dstt */
99e300ef 4493static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4494{
4495 if (rA(ctx->opcode) == 0) {
4496 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4497 } else {
4498 /* interpreted as no-op */
4499 }
4500}
4501
4502/* dstst /dststt */
99e300ef 4503static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4504{
4505 if (rA(ctx->opcode) == 0) {
4506 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4507 } else {
4508 /* interpreted as no-op */
4509 }
4510
4511}
4512
4513/* dss / dssall */
99e300ef 4514static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4515{
4516 /* interpreted as no-op */
4517}
4518
79aceca5 4519/* icbi */
99e300ef 4520static void gen_icbi(DisasContext *ctx)
79aceca5 4521{
76db3ba4
AJ
4522 TCGv t0;
4523 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4524 /* NIP cannot be restored if the memory exception comes from an helper */
4525 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4526 t0 = tcg_temp_new();
4527 gen_addr_reg_index(ctx, t0);
2f5a189c 4528 gen_helper_icbi(cpu_env, t0);
37d269df 4529 tcg_temp_free(t0);
79aceca5
FB
4530}
4531
4532/* Optional: */
4533/* dcba */
99e300ef 4534static void gen_dcba(DisasContext *ctx)
79aceca5 4535{
0db1b20e
JM
4536 /* interpreted as no-op */
4537 /* XXX: specification say this is treated as a store by the MMU
4538 * but does not generate any exception
4539 */
79aceca5
FB
4540}
4541
4542/*** Segment register manipulation ***/
4543/* Supervisor only: */
99e300ef 4544
54623277 4545/* mfsr */
99e300ef 4546static void gen_mfsr(DisasContext *ctx)
79aceca5 4547{
9a64fbe4 4548#if defined(CONFIG_USER_ONLY)
e06fcd75 4549 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4550#else
74d37793 4551 TCGv t0;
76db3ba4 4552 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4553 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4554 return;
9a64fbe4 4555 }
74d37793 4556 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4557 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4558 tcg_temp_free(t0);
9a64fbe4 4559#endif
79aceca5
FB
4560}
4561
4562/* mfsrin */
99e300ef 4563static void gen_mfsrin(DisasContext *ctx)
79aceca5 4564{
9a64fbe4 4565#if defined(CONFIG_USER_ONLY)
e06fcd75 4566 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4567#else
74d37793 4568 TCGv t0;
76db3ba4 4569 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4570 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4571 return;
9a64fbe4 4572 }
74d37793
AJ
4573 t0 = tcg_temp_new();
4574 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4575 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4576 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4577 tcg_temp_free(t0);
9a64fbe4 4578#endif
79aceca5
FB
4579}
4580
4581/* mtsr */
99e300ef 4582static void gen_mtsr(DisasContext *ctx)
79aceca5 4583{
9a64fbe4 4584#if defined(CONFIG_USER_ONLY)
e06fcd75 4585 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4586#else
74d37793 4587 TCGv t0;
76db3ba4 4588 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4589 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4590 return;
9a64fbe4 4591 }
74d37793 4592 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4593 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4594 tcg_temp_free(t0);
9a64fbe4 4595#endif
79aceca5
FB
4596}
4597
4598/* mtsrin */
99e300ef 4599static void gen_mtsrin(DisasContext *ctx)
79aceca5 4600{
9a64fbe4 4601#if defined(CONFIG_USER_ONLY)
e06fcd75 4602 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4603#else
74d37793 4604 TCGv t0;
76db3ba4 4605 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4606 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4607 return;
9a64fbe4 4608 }
74d37793
AJ
4609 t0 = tcg_temp_new();
4610 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4611 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4612 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4613 tcg_temp_free(t0);
9a64fbe4 4614#endif
79aceca5
FB
4615}
4616
12de9a39
JM
4617#if defined(TARGET_PPC64)
4618/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4619
54623277 4620/* mfsr */
e8eaa2c0 4621static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4622{
4623#if defined(CONFIG_USER_ONLY)
e06fcd75 4624 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4625#else
74d37793 4626 TCGv t0;
76db3ba4 4627 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4628 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4629 return;
4630 }
74d37793 4631 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4632 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4633 tcg_temp_free(t0);
12de9a39
JM
4634#endif
4635}
4636
4637/* mfsrin */
e8eaa2c0 4638static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4639{
4640#if defined(CONFIG_USER_ONLY)
e06fcd75 4641 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4642#else
74d37793 4643 TCGv t0;
76db3ba4 4644 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4645 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4646 return;
4647 }
74d37793
AJ
4648 t0 = tcg_temp_new();
4649 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4650 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4651 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4652 tcg_temp_free(t0);
12de9a39
JM
4653#endif
4654}
4655
4656/* mtsr */
e8eaa2c0 4657static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4658{
4659#if defined(CONFIG_USER_ONLY)
e06fcd75 4660 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4661#else
74d37793 4662 TCGv t0;
76db3ba4 4663 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4664 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4665 return;
4666 }
74d37793 4667 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4668 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4669 tcg_temp_free(t0);
12de9a39
JM
4670#endif
4671}
4672
4673/* mtsrin */
e8eaa2c0 4674static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4675{
4676#if defined(CONFIG_USER_ONLY)
e06fcd75 4677 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4678#else
74d37793 4679 TCGv t0;
76db3ba4 4680 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4681 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4682 return;
4683 }
74d37793
AJ
4684 t0 = tcg_temp_new();
4685 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4686 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4687 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4688 tcg_temp_free(t0);
12de9a39
JM
4689#endif
4690}
f6b868fc
BS
4691
4692/* slbmte */
e8eaa2c0 4693static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4694{
4695#if defined(CONFIG_USER_ONLY)
4696 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4697#else
4698 if (unlikely(!ctx->mem_idx)) {
4699 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4700 return;
4701 }
c6c7cf05
BS
4702 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4703 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4704#endif
4705}
4706
efdef95f
DG
4707static void gen_slbmfee(DisasContext *ctx)
4708{
4709#if defined(CONFIG_USER_ONLY)
4710 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4711#else
4712 if (unlikely(!ctx->mem_idx)) {
4713 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4714 return;
4715 }
c6c7cf05 4716 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4717 cpu_gpr[rB(ctx->opcode)]);
4718#endif
4719}
4720
4721static void gen_slbmfev(DisasContext *ctx)
4722{
4723#if defined(CONFIG_USER_ONLY)
4724 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4725#else
4726 if (unlikely(!ctx->mem_idx)) {
4727 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4728 return;
4729 }
c6c7cf05 4730 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4731 cpu_gpr[rB(ctx->opcode)]);
4732#endif
4733}
12de9a39
JM
4734#endif /* defined(TARGET_PPC64) */
4735
79aceca5 4736/*** Lookaside buffer management ***/
76db3ba4 4737/* Optional & mem_idx only: */
99e300ef 4738
54623277 4739/* tlbia */
99e300ef 4740static void gen_tlbia(DisasContext *ctx)
79aceca5 4741{
9a64fbe4 4742#if defined(CONFIG_USER_ONLY)
e06fcd75 4743 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4744#else
76db3ba4 4745 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4746 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4747 return;
9a64fbe4 4748 }
c6c7cf05 4749 gen_helper_tlbia(cpu_env);
9a64fbe4 4750#endif
79aceca5
FB
4751}
4752
bf14b1ce 4753/* tlbiel */
99e300ef 4754static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4755{
4756#if defined(CONFIG_USER_ONLY)
4757 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4758#else
4759 if (unlikely(!ctx->mem_idx)) {
4760 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4761 return;
4762 }
c6c7cf05 4763 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4764#endif
4765}
4766
79aceca5 4767/* tlbie */
99e300ef 4768static void gen_tlbie(DisasContext *ctx)
79aceca5 4769{
9a64fbe4 4770#if defined(CONFIG_USER_ONLY)
e06fcd75 4771 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4772#else
76db3ba4 4773 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4774 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4775 return;
9a64fbe4 4776 }
9ca3f7f3 4777 if (NARROW_MODE(ctx)) {
74d37793
AJ
4778 TCGv t0 = tcg_temp_new();
4779 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4780 gen_helper_tlbie(cpu_env, t0);
74d37793 4781 tcg_temp_free(t0);
9ca3f7f3 4782 } else {
c6c7cf05 4783 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4784 }
9a64fbe4 4785#endif
79aceca5
FB
4786}
4787
4788/* tlbsync */
99e300ef 4789static void gen_tlbsync(DisasContext *ctx)
79aceca5 4790{
9a64fbe4 4791#if defined(CONFIG_USER_ONLY)
e06fcd75 4792 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4793#else
76db3ba4 4794 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4795 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4796 return;
9a64fbe4
FB
4797 }
4798 /* This has no effect: it should ensure that all previous
4799 * tlbie have completed
4800 */
e06fcd75 4801 gen_stop_exception(ctx);
9a64fbe4 4802#endif
79aceca5
FB
4803}
4804
426613db
JM
4805#if defined(TARGET_PPC64)
4806/* slbia */
99e300ef 4807static void gen_slbia(DisasContext *ctx)
426613db
JM
4808{
4809#if defined(CONFIG_USER_ONLY)
e06fcd75 4810 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4811#else
76db3ba4 4812 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4813 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4814 return;
4815 }
c6c7cf05 4816 gen_helper_slbia(cpu_env);
426613db
JM
4817#endif
4818}
4819
4820/* slbie */
99e300ef 4821static void gen_slbie(DisasContext *ctx)
426613db
JM
4822{
4823#if defined(CONFIG_USER_ONLY)
e06fcd75 4824 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4825#else
76db3ba4 4826 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4827 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4828 return;
4829 }
c6c7cf05 4830 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4831#endif
4832}
4833#endif
4834
79aceca5
FB
4835/*** External control ***/
4836/* Optional: */
99e300ef 4837
54623277 4838/* eciwx */
99e300ef 4839static void gen_eciwx(DisasContext *ctx)
79aceca5 4840{
76db3ba4 4841 TCGv t0;
fa407c03 4842 /* Should check EAR[E] ! */
76db3ba4
AJ
4843 gen_set_access_type(ctx, ACCESS_EXT);
4844 t0 = tcg_temp_new();
4845 gen_addr_reg_index(ctx, t0);
fa407c03 4846 gen_check_align(ctx, t0, 0x03);
76db3ba4 4847 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4848 tcg_temp_free(t0);
76a66253
JM
4849}
4850
4851/* ecowx */
99e300ef 4852static void gen_ecowx(DisasContext *ctx)
76a66253 4853{
76db3ba4 4854 TCGv t0;
fa407c03 4855 /* Should check EAR[E] ! */
76db3ba4
AJ
4856 gen_set_access_type(ctx, ACCESS_EXT);
4857 t0 = tcg_temp_new();
4858 gen_addr_reg_index(ctx, t0);
fa407c03 4859 gen_check_align(ctx, t0, 0x03);
76db3ba4 4860 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4861 tcg_temp_free(t0);
76a66253
JM
4862}
4863
4864/* PowerPC 601 specific instructions */
99e300ef 4865
54623277 4866/* abs - abs. */
99e300ef 4867static void gen_abs(DisasContext *ctx)
76a66253 4868{
22e0e173
AJ
4869 int l1 = gen_new_label();
4870 int l2 = gen_new_label();
4871 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4872 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4873 tcg_gen_br(l2);
4874 gen_set_label(l1);
4875 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4876 gen_set_label(l2);
76a66253 4877 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4878 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4879}
4880
4881/* abso - abso. */
99e300ef 4882static void gen_abso(DisasContext *ctx)
76a66253 4883{
22e0e173
AJ
4884 int l1 = gen_new_label();
4885 int l2 = gen_new_label();
4886 int l3 = gen_new_label();
4887 /* Start with XER OV disabled, the most likely case */
da91a00f 4888 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4889 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4890 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4891 tcg_gen_movi_tl(cpu_ov, 1);
4892 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4893 tcg_gen_br(l2);
4894 gen_set_label(l1);
4895 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4896 tcg_gen_br(l3);
4897 gen_set_label(l2);
4898 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4899 gen_set_label(l3);
76a66253 4900 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4901 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4902}
4903
4904/* clcs */
99e300ef 4905static void gen_clcs(DisasContext *ctx)
76a66253 4906{
22e0e173 4907 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4908 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4909 tcg_temp_free_i32(t0);
c7697e1f 4910 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
4911}
4912
4913/* div - div. */
99e300ef 4914static void gen_div(DisasContext *ctx)
76a66253 4915{
d15f74fb
BS
4916 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4917 cpu_gpr[rB(ctx->opcode)]);
76a66253 4918 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4919 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4920}
4921
4922/* divo - divo. */
99e300ef 4923static void gen_divo(DisasContext *ctx)
76a66253 4924{
d15f74fb
BS
4925 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4926 cpu_gpr[rB(ctx->opcode)]);
76a66253 4927 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4928 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4929}
4930
4931/* divs - divs. */
99e300ef 4932static void gen_divs(DisasContext *ctx)
76a66253 4933{
d15f74fb
BS
4934 gen_helper_divs(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/* divso - divso. */
99e300ef 4941static void gen_divso(DisasContext *ctx)
76a66253 4942{
d15f74fb
BS
4943 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4944 cpu_gpr[rA(ctx->opcode)], 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/* doz - doz. */
99e300ef 4950static void gen_doz(DisasContext *ctx)
76a66253 4951{
22e0e173
AJ
4952 int l1 = gen_new_label();
4953 int l2 = gen_new_label();
4954 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4955 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4956 tcg_gen_br(l2);
4957 gen_set_label(l1);
4958 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4959 gen_set_label(l2);
76a66253 4960 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4961 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4962}
4963
4964/* dozo - dozo. */
99e300ef 4965static void gen_dozo(DisasContext *ctx)
76a66253 4966{
22e0e173
AJ
4967 int l1 = gen_new_label();
4968 int l2 = gen_new_label();
4969 TCGv t0 = tcg_temp_new();
4970 TCGv t1 = tcg_temp_new();
4971 TCGv t2 = tcg_temp_new();
4972 /* Start with XER OV disabled, the most likely case */
da91a00f 4973 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4974 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4975 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4976 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4977 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4978 tcg_gen_andc_tl(t1, t1, t2);
4979 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4980 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
4981 tcg_gen_movi_tl(cpu_ov, 1);
4982 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4983 tcg_gen_br(l2);
4984 gen_set_label(l1);
4985 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4986 gen_set_label(l2);
4987 tcg_temp_free(t0);
4988 tcg_temp_free(t1);
4989 tcg_temp_free(t2);
76a66253 4990 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4991 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4992}
4993
4994/* dozi */
99e300ef 4995static void gen_dozi(DisasContext *ctx)
76a66253 4996{
22e0e173
AJ
4997 target_long simm = SIMM(ctx->opcode);
4998 int l1 = gen_new_label();
4999 int l2 = gen_new_label();
5000 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5001 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5002 tcg_gen_br(l2);
5003 gen_set_label(l1);
5004 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5005 gen_set_label(l2);
5006 if (unlikely(Rc(ctx->opcode) != 0))
5007 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5008}
5009
76a66253 5010/* lscbx - lscbx. */
99e300ef 5011static void gen_lscbx(DisasContext *ctx)
76a66253 5012{
bdb4b689
AJ
5013 TCGv t0 = tcg_temp_new();
5014 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5015 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5016 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 5017
76db3ba4 5018 gen_addr_reg_index(ctx, t0);
76a66253 5019 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 5020 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 5021 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
5022 tcg_temp_free_i32(t1);
5023 tcg_temp_free_i32(t2);
5024 tcg_temp_free_i32(t3);
3d7b417e 5025 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 5026 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 5027 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
5028 gen_set_Rc0(ctx, t0);
5029 tcg_temp_free(t0);
76a66253
JM
5030}
5031
5032/* maskg - maskg. */
99e300ef 5033static void gen_maskg(DisasContext *ctx)
76a66253 5034{
22e0e173
AJ
5035 int l1 = gen_new_label();
5036 TCGv t0 = tcg_temp_new();
5037 TCGv t1 = tcg_temp_new();
5038 TCGv t2 = tcg_temp_new();
5039 TCGv t3 = tcg_temp_new();
5040 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5041 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5042 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5043 tcg_gen_addi_tl(t2, t0, 1);
5044 tcg_gen_shr_tl(t2, t3, t2);
5045 tcg_gen_shr_tl(t3, t3, t1);
5046 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5047 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5048 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5049 gen_set_label(l1);
5050 tcg_temp_free(t0);
5051 tcg_temp_free(t1);
5052 tcg_temp_free(t2);
5053 tcg_temp_free(t3);
76a66253 5054 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5055 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5056}
5057
5058/* maskir - maskir. */
99e300ef 5059static void gen_maskir(DisasContext *ctx)
76a66253 5060{
22e0e173
AJ
5061 TCGv t0 = tcg_temp_new();
5062 TCGv t1 = tcg_temp_new();
5063 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5064 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5065 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5066 tcg_temp_free(t0);
5067 tcg_temp_free(t1);
76a66253 5068 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5069 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5070}
5071
5072/* mul - mul. */
99e300ef 5073static void gen_mul(DisasContext *ctx)
76a66253 5074{
22e0e173
AJ
5075 TCGv_i64 t0 = tcg_temp_new_i64();
5076 TCGv_i64 t1 = tcg_temp_new_i64();
5077 TCGv t2 = tcg_temp_new();
5078 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5079 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5080 tcg_gen_mul_i64(t0, t0, t1);
5081 tcg_gen_trunc_i64_tl(t2, t0);
5082 gen_store_spr(SPR_MQ, t2);
5083 tcg_gen_shri_i64(t1, t0, 32);
5084 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5085 tcg_temp_free_i64(t0);
5086 tcg_temp_free_i64(t1);
5087 tcg_temp_free(t2);
76a66253 5088 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5089 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5090}
5091
5092/* mulo - mulo. */
99e300ef 5093static void gen_mulo(DisasContext *ctx)
76a66253 5094{
22e0e173
AJ
5095 int l1 = gen_new_label();
5096 TCGv_i64 t0 = tcg_temp_new_i64();
5097 TCGv_i64 t1 = tcg_temp_new_i64();
5098 TCGv t2 = tcg_temp_new();
5099 /* Start with XER OV disabled, the most likely case */
da91a00f 5100 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5101 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5102 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5103 tcg_gen_mul_i64(t0, t0, t1);
5104 tcg_gen_trunc_i64_tl(t2, t0);
5105 gen_store_spr(SPR_MQ, t2);
5106 tcg_gen_shri_i64(t1, t0, 32);
5107 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5108 tcg_gen_ext32s_i64(t1, t0);
5109 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
5110 tcg_gen_movi_tl(cpu_ov, 1);
5111 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5112 gen_set_label(l1);
5113 tcg_temp_free_i64(t0);
5114 tcg_temp_free_i64(t1);
5115 tcg_temp_free(t2);
76a66253 5116 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5117 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5118}
5119
5120/* nabs - nabs. */
99e300ef 5121static void gen_nabs(DisasContext *ctx)
76a66253 5122{
22e0e173
AJ
5123 int l1 = gen_new_label();
5124 int l2 = gen_new_label();
5125 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5126 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5127 tcg_gen_br(l2);
5128 gen_set_label(l1);
5129 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5130 gen_set_label(l2);
76a66253 5131 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5132 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5133}
5134
5135/* nabso - nabso. */
99e300ef 5136static void gen_nabso(DisasContext *ctx)
76a66253 5137{
22e0e173
AJ
5138 int l1 = gen_new_label();
5139 int l2 = gen_new_label();
5140 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5141 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5142 tcg_gen_br(l2);
5143 gen_set_label(l1);
5144 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5145 gen_set_label(l2);
5146 /* nabs never overflows */
da91a00f 5147 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 5148 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5149 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5150}
5151
5152/* rlmi - rlmi. */
99e300ef 5153static void gen_rlmi(DisasContext *ctx)
76a66253 5154{
7487953d
AJ
5155 uint32_t mb = MB(ctx->opcode);
5156 uint32_t me = ME(ctx->opcode);
5157 TCGv t0 = tcg_temp_new();
5158 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5159 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5160 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5161 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5162 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5163 tcg_temp_free(t0);
76a66253 5164 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5165 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5166}
5167
5168/* rrib - rrib. */
99e300ef 5169static void gen_rrib(DisasContext *ctx)
76a66253 5170{
7487953d
AJ
5171 TCGv t0 = tcg_temp_new();
5172 TCGv t1 = tcg_temp_new();
5173 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5174 tcg_gen_movi_tl(t1, 0x80000000);
5175 tcg_gen_shr_tl(t1, t1, t0);
5176 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5177 tcg_gen_and_tl(t0, t0, t1);
5178 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5179 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5180 tcg_temp_free(t0);
5181 tcg_temp_free(t1);
76a66253 5182 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5183 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5184}
5185
5186/* sle - sle. */
99e300ef 5187static void gen_sle(DisasContext *ctx)
76a66253 5188{
7487953d
AJ
5189 TCGv t0 = tcg_temp_new();
5190 TCGv t1 = tcg_temp_new();
5191 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5192 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5193 tcg_gen_subfi_tl(t1, 32, t1);
5194 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5195 tcg_gen_or_tl(t1, t0, t1);
5196 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5197 gen_store_spr(SPR_MQ, 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/* sleq - sleq. */
99e300ef 5205static void gen_sleq(DisasContext *ctx)
76a66253 5206{
7487953d
AJ
5207 TCGv t0 = tcg_temp_new();
5208 TCGv t1 = tcg_temp_new();
5209 TCGv t2 = tcg_temp_new();
5210 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5211 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5212 tcg_gen_shl_tl(t2, t2, t0);
5213 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5214 gen_load_spr(t1, SPR_MQ);
5215 gen_store_spr(SPR_MQ, t0);
5216 tcg_gen_and_tl(t0, t0, t2);
5217 tcg_gen_andc_tl(t1, t1, t2);
5218 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5219 tcg_temp_free(t0);
5220 tcg_temp_free(t1);
5221 tcg_temp_free(t2);
76a66253 5222 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5223 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5224}
5225
5226/* sliq - sliq. */
99e300ef 5227static void gen_sliq(DisasContext *ctx)
76a66253 5228{
7487953d
AJ
5229 int sh = SH(ctx->opcode);
5230 TCGv t0 = tcg_temp_new();
5231 TCGv t1 = tcg_temp_new();
5232 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5233 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5234 tcg_gen_or_tl(t1, t0, t1);
5235 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5236 gen_store_spr(SPR_MQ, t1);
5237 tcg_temp_free(t0);
5238 tcg_temp_free(t1);
76a66253 5239 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5240 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5241}
5242
5243/* slliq - slliq. */
99e300ef 5244static void gen_slliq(DisasContext *ctx)
76a66253 5245{
7487953d
AJ
5246 int sh = SH(ctx->opcode);
5247 TCGv t0 = tcg_temp_new();
5248 TCGv t1 = tcg_temp_new();
5249 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5250 gen_load_spr(t1, SPR_MQ);
5251 gen_store_spr(SPR_MQ, t0);
5252 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5253 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5254 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, 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/* sllq - sllq. */
99e300ef 5262static void gen_sllq(DisasContext *ctx)
76a66253 5263{
7487953d
AJ
5264 int l1 = gen_new_label();
5265 int l2 = gen_new_label();
5266 TCGv t0 = tcg_temp_local_new();
5267 TCGv t1 = tcg_temp_local_new();
5268 TCGv t2 = tcg_temp_local_new();
5269 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5270 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5271 tcg_gen_shl_tl(t1, t1, t2);
5272 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5273 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5274 gen_load_spr(t0, SPR_MQ);
5275 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5276 tcg_gen_br(l2);
5277 gen_set_label(l1);
5278 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5279 gen_load_spr(t2, SPR_MQ);
5280 tcg_gen_andc_tl(t1, t2, t1);
5281 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5282 gen_set_label(l2);
5283 tcg_temp_free(t0);
5284 tcg_temp_free(t1);
5285 tcg_temp_free(t2);
76a66253 5286 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5287 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5288}
5289
5290/* slq - slq. */
99e300ef 5291static void gen_slq(DisasContext *ctx)
76a66253 5292{
7487953d
AJ
5293 int l1 = gen_new_label();
5294 TCGv t0 = tcg_temp_new();
5295 TCGv t1 = tcg_temp_new();
5296 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5297 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5298 tcg_gen_subfi_tl(t1, 32, t1);
5299 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5300 tcg_gen_or_tl(t1, t0, t1);
5301 gen_store_spr(SPR_MQ, t1);
5302 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5303 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5304 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5305 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5306 gen_set_label(l1);
5307 tcg_temp_free(t0);
5308 tcg_temp_free(t1);
76a66253 5309 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5310 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5311}
5312
d9bce9d9 5313/* sraiq - sraiq. */
99e300ef 5314static void gen_sraiq(DisasContext *ctx)
76a66253 5315{
7487953d
AJ
5316 int sh = SH(ctx->opcode);
5317 int l1 = gen_new_label();
5318 TCGv t0 = tcg_temp_new();
5319 TCGv t1 = tcg_temp_new();
5320 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5321 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5322 tcg_gen_or_tl(t0, t0, t1);
5323 gen_store_spr(SPR_MQ, t0);
da91a00f 5324 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5325 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5326 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5327 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5328 gen_set_label(l1);
5329 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5330 tcg_temp_free(t0);
5331 tcg_temp_free(t1);
76a66253 5332 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5333 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5334}
5335
5336/* sraq - sraq. */
99e300ef 5337static void gen_sraq(DisasContext *ctx)
76a66253 5338{
7487953d
AJ
5339 int l1 = gen_new_label();
5340 int l2 = gen_new_label();
5341 TCGv t0 = tcg_temp_new();
5342 TCGv t1 = tcg_temp_local_new();
5343 TCGv t2 = tcg_temp_local_new();
5344 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5345 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5346 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5347 tcg_gen_subfi_tl(t2, 32, t2);
5348 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5349 tcg_gen_or_tl(t0, t0, t2);
5350 gen_store_spr(SPR_MQ, t0);
5351 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5352 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5353 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5354 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5355 gen_set_label(l1);
5356 tcg_temp_free(t0);
5357 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5358 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5359 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5360 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5361 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5362 gen_set_label(l2);
5363 tcg_temp_free(t1);
5364 tcg_temp_free(t2);
76a66253 5365 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5366 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5367}
5368
5369/* sre - sre. */
99e300ef 5370static void gen_sre(DisasContext *ctx)
76a66253 5371{
7487953d
AJ
5372 TCGv t0 = tcg_temp_new();
5373 TCGv t1 = tcg_temp_new();
5374 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5375 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5376 tcg_gen_subfi_tl(t1, 32, t1);
5377 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5378 tcg_gen_or_tl(t1, t0, t1);
5379 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5380 gen_store_spr(SPR_MQ, t1);
5381 tcg_temp_free(t0);
5382 tcg_temp_free(t1);
76a66253 5383 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5384 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5385}
5386
5387/* srea - srea. */
99e300ef 5388static void gen_srea(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_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5394 gen_store_spr(SPR_MQ, t0);
5395 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5396 tcg_temp_free(t0);
5397 tcg_temp_free(t1);
76a66253 5398 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5399 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5400}
5401
5402/* sreq */
99e300ef 5403static void gen_sreq(DisasContext *ctx)
76a66253 5404{
7487953d
AJ
5405 TCGv t0 = tcg_temp_new();
5406 TCGv t1 = tcg_temp_new();
5407 TCGv t2 = tcg_temp_new();
5408 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5409 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5410 tcg_gen_shr_tl(t1, t1, t0);
5411 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5412 gen_load_spr(t2, SPR_MQ);
5413 gen_store_spr(SPR_MQ, t0);
5414 tcg_gen_and_tl(t0, t0, t1);
5415 tcg_gen_andc_tl(t2, t2, t1);
5416 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5417 tcg_temp_free(t0);
5418 tcg_temp_free(t1);
5419 tcg_temp_free(t2);
76a66253 5420 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5421 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5422}
5423
5424/* sriq */
99e300ef 5425static void gen_sriq(DisasContext *ctx)
76a66253 5426{
7487953d
AJ
5427 int sh = SH(ctx->opcode);
5428 TCGv t0 = tcg_temp_new();
5429 TCGv t1 = tcg_temp_new();
5430 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5431 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5432 tcg_gen_or_tl(t1, t0, t1);
5433 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5434 gen_store_spr(SPR_MQ, t1);
5435 tcg_temp_free(t0);
5436 tcg_temp_free(t1);
76a66253 5437 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5438 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5439}
5440
5441/* srliq */
99e300ef 5442static void gen_srliq(DisasContext *ctx)
76a66253 5443{
7487953d
AJ
5444 int sh = SH(ctx->opcode);
5445 TCGv t0 = tcg_temp_new();
5446 TCGv t1 = tcg_temp_new();
5447 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5448 gen_load_spr(t1, SPR_MQ);
5449 gen_store_spr(SPR_MQ, t0);
5450 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5451 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5452 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, 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/* srlq */
99e300ef 5460static void gen_srlq(DisasContext *ctx)
76a66253 5461{
7487953d
AJ
5462 int l1 = gen_new_label();
5463 int l2 = gen_new_label();
5464 TCGv t0 = tcg_temp_local_new();
5465 TCGv t1 = tcg_temp_local_new();
5466 TCGv t2 = tcg_temp_local_new();
5467 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5468 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5469 tcg_gen_shr_tl(t2, t1, t2);
5470 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5471 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5472 gen_load_spr(t0, SPR_MQ);
5473 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5474 tcg_gen_br(l2);
5475 gen_set_label(l1);
5476 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5477 tcg_gen_and_tl(t0, t0, t2);
5478 gen_load_spr(t1, SPR_MQ);
5479 tcg_gen_andc_tl(t1, t1, t2);
5480 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5481 gen_set_label(l2);
5482 tcg_temp_free(t0);
5483 tcg_temp_free(t1);
5484 tcg_temp_free(t2);
76a66253 5485 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5486 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5487}
5488
5489/* srq */
99e300ef 5490static void gen_srq(DisasContext *ctx)
76a66253 5491{
7487953d
AJ
5492 int l1 = gen_new_label();
5493 TCGv t0 = tcg_temp_new();
5494 TCGv t1 = tcg_temp_new();
5495 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5496 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5497 tcg_gen_subfi_tl(t1, 32, t1);
5498 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5499 tcg_gen_or_tl(t1, t0, t1);
5500 gen_store_spr(SPR_MQ, t1);
5501 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5502 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5503 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5504 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5505 gen_set_label(l1);
5506 tcg_temp_free(t0);
5507 tcg_temp_free(t1);
76a66253 5508 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5509 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5510}
5511
5512/* PowerPC 602 specific instructions */
99e300ef 5513
54623277 5514/* dsa */
99e300ef 5515static void gen_dsa(DisasContext *ctx)
76a66253
JM
5516{
5517 /* XXX: TODO */
e06fcd75 5518 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5519}
5520
5521/* esa */
99e300ef 5522static void gen_esa(DisasContext *ctx)
76a66253
JM
5523{
5524 /* XXX: TODO */
e06fcd75 5525 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5526}
5527
5528/* mfrom */
99e300ef 5529static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5530{
5531#if defined(CONFIG_USER_ONLY)
e06fcd75 5532 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5533#else
76db3ba4 5534 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5535 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5536 return;
5537 }
cf02a65c 5538 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5539#endif
5540}
5541
5542/* 602 - 603 - G2 TLB management */
e8eaa2c0 5543
54623277 5544/* tlbld */
e8eaa2c0 5545static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5546{
5547#if defined(CONFIG_USER_ONLY)
e06fcd75 5548 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5549#else
76db3ba4 5550 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5551 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5552 return;
5553 }
c6c7cf05 5554 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5555#endif
5556}
5557
5558/* tlbli */
e8eaa2c0 5559static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5560{
5561#if defined(CONFIG_USER_ONLY)
e06fcd75 5562 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5563#else
76db3ba4 5564 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5565 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5566 return;
5567 }
c6c7cf05 5568 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5569#endif
5570}
5571
7dbe11ac 5572/* 74xx TLB management */
e8eaa2c0 5573
54623277 5574/* tlbld */
e8eaa2c0 5575static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5576{
5577#if defined(CONFIG_USER_ONLY)
e06fcd75 5578 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5579#else
76db3ba4 5580 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5581 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5582 return;
5583 }
c6c7cf05 5584 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5585#endif
5586}
5587
5588/* tlbli */
e8eaa2c0 5589static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5590{
5591#if defined(CONFIG_USER_ONLY)
e06fcd75 5592 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5593#else
76db3ba4 5594 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5595 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5596 return;
5597 }
c6c7cf05 5598 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5599#endif
5600}
5601
76a66253 5602/* POWER instructions not in PowerPC 601 */
99e300ef 5603
54623277 5604/* clf */
99e300ef 5605static void gen_clf(DisasContext *ctx)
76a66253
JM
5606{
5607 /* Cache line flush: implemented as no-op */
5608}
5609
5610/* cli */
99e300ef 5611static void gen_cli(DisasContext *ctx)
76a66253 5612{
7f75ffd3 5613 /* Cache line invalidate: privileged and treated as no-op */
76a66253 5614#if defined(CONFIG_USER_ONLY)
e06fcd75 5615 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5616#else
76db3ba4 5617 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5618 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5619 return;
5620 }
5621#endif
5622}
5623
5624/* dclst */
99e300ef 5625static void gen_dclst(DisasContext *ctx)
76a66253
JM
5626{
5627 /* Data cache line store: treated as no-op */
5628}
5629
99e300ef 5630static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5631{
5632#if defined(CONFIG_USER_ONLY)
e06fcd75 5633 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5634#else
74d37793
AJ
5635 int ra = rA(ctx->opcode);
5636 int rd = rD(ctx->opcode);
5637 TCGv t0;
76db3ba4 5638 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5639 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5640 return;
5641 }
74d37793 5642 t0 = tcg_temp_new();
76db3ba4 5643 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5644 tcg_gen_shri_tl(t0, t0, 28);
5645 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5646 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5647 tcg_temp_free(t0);
76a66253 5648 if (ra != 0 && ra != rd)
74d37793 5649 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5650#endif
5651}
5652
99e300ef 5653static void gen_rac(DisasContext *ctx)
76a66253
JM
5654{
5655#if defined(CONFIG_USER_ONLY)
e06fcd75 5656 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5657#else
22e0e173 5658 TCGv t0;
76db3ba4 5659 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5660 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5661 return;
5662 }
22e0e173 5663 t0 = tcg_temp_new();
76db3ba4 5664 gen_addr_reg_index(ctx, t0);
c6c7cf05 5665 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5666 tcg_temp_free(t0);
76a66253
JM
5667#endif
5668}
5669
99e300ef 5670static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5671{
5672#if defined(CONFIG_USER_ONLY)
e06fcd75 5673 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5674#else
76db3ba4 5675 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5676 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5677 return;
5678 }
e5f17ac6 5679 gen_helper_rfsvc(cpu_env);
e06fcd75 5680 gen_sync_exception(ctx);
76a66253
JM
5681#endif
5682}
5683
5684/* svc is not implemented for now */
5685
5686/* POWER2 specific instructions */
5687/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5688
5689/* lfq */
99e300ef 5690static void gen_lfq(DisasContext *ctx)
76a66253 5691{
01a4afeb 5692 int rd = rD(ctx->opcode);
76db3ba4
AJ
5693 TCGv t0;
5694 gen_set_access_type(ctx, ACCESS_FLOAT);
5695 t0 = tcg_temp_new();
5696 gen_addr_imm_index(ctx, t0, 0);
5697 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5698 gen_addr_add(ctx, t0, t0, 8);
5699 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5700 tcg_temp_free(t0);
76a66253
JM
5701}
5702
5703/* lfqu */
99e300ef 5704static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5705{
5706 int ra = rA(ctx->opcode);
01a4afeb 5707 int rd = rD(ctx->opcode);
76db3ba4
AJ
5708 TCGv t0, t1;
5709 gen_set_access_type(ctx, ACCESS_FLOAT);
5710 t0 = tcg_temp_new();
5711 t1 = tcg_temp_new();
5712 gen_addr_imm_index(ctx, t0, 0);
5713 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5714 gen_addr_add(ctx, t1, t0, 8);
5715 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5716 if (ra != 0)
01a4afeb
AJ
5717 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5718 tcg_temp_free(t0);
5719 tcg_temp_free(t1);
76a66253
JM
5720}
5721
5722/* lfqux */
99e300ef 5723static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5724{
5725 int ra = rA(ctx->opcode);
01a4afeb 5726 int rd = rD(ctx->opcode);
76db3ba4
AJ
5727 gen_set_access_type(ctx, ACCESS_FLOAT);
5728 TCGv t0, t1;
5729 t0 = tcg_temp_new();
5730 gen_addr_reg_index(ctx, t0);
5731 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5732 t1 = tcg_temp_new();
5733 gen_addr_add(ctx, t1, t0, 8);
5734 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5735 tcg_temp_free(t1);
76a66253 5736 if (ra != 0)
01a4afeb
AJ
5737 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5738 tcg_temp_free(t0);
76a66253
JM
5739}
5740
5741/* lfqx */
99e300ef 5742static void gen_lfqx(DisasContext *ctx)
76a66253 5743{
01a4afeb 5744 int rd = rD(ctx->opcode);
76db3ba4
AJ
5745 TCGv t0;
5746 gen_set_access_type(ctx, ACCESS_FLOAT);
5747 t0 = tcg_temp_new();
5748 gen_addr_reg_index(ctx, t0);
5749 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5750 gen_addr_add(ctx, t0, t0, 8);
5751 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5752 tcg_temp_free(t0);
76a66253
JM
5753}
5754
5755/* stfq */
99e300ef 5756static void gen_stfq(DisasContext *ctx)
76a66253 5757{
01a4afeb 5758 int rd = rD(ctx->opcode);
76db3ba4
AJ
5759 TCGv t0;
5760 gen_set_access_type(ctx, ACCESS_FLOAT);
5761 t0 = tcg_temp_new();
5762 gen_addr_imm_index(ctx, t0, 0);
5763 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5764 gen_addr_add(ctx, t0, t0, 8);
5765 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5766 tcg_temp_free(t0);
76a66253
JM
5767}
5768
5769/* stfqu */
99e300ef 5770static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5771{
5772 int ra = rA(ctx->opcode);
01a4afeb 5773 int rd = rD(ctx->opcode);
76db3ba4
AJ
5774 TCGv t0, t1;
5775 gen_set_access_type(ctx, ACCESS_FLOAT);
5776 t0 = tcg_temp_new();
5777 gen_addr_imm_index(ctx, t0, 0);
5778 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5779 t1 = tcg_temp_new();
5780 gen_addr_add(ctx, t1, t0, 8);
5781 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5782 tcg_temp_free(t1);
76a66253 5783 if (ra != 0)
01a4afeb
AJ
5784 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5785 tcg_temp_free(t0);
76a66253
JM
5786}
5787
5788/* stfqux */
99e300ef 5789static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5790{
5791 int ra = rA(ctx->opcode);
01a4afeb 5792 int rd = rD(ctx->opcode);
76db3ba4
AJ
5793 TCGv t0, t1;
5794 gen_set_access_type(ctx, ACCESS_FLOAT);
5795 t0 = tcg_temp_new();
5796 gen_addr_reg_index(ctx, t0);
5797 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5798 t1 = tcg_temp_new();
5799 gen_addr_add(ctx, t1, t0, 8);
5800 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5801 tcg_temp_free(t1);
76a66253 5802 if (ra != 0)
01a4afeb
AJ
5803 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5804 tcg_temp_free(t0);
76a66253
JM
5805}
5806
5807/* stfqx */
99e300ef 5808static void gen_stfqx(DisasContext *ctx)
76a66253 5809{
01a4afeb 5810 int rd = rD(ctx->opcode);
76db3ba4
AJ
5811 TCGv t0;
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 gen_addr_add(ctx, t0, t0, 8);
5817 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5818 tcg_temp_free(t0);
76a66253
JM
5819}
5820
5821/* BookE specific instructions */
99e300ef 5822
54623277 5823/* XXX: not implemented on 440 ? */
99e300ef 5824static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5825{
5826 /* XXX: TODO */
e06fcd75 5827 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5828}
5829
2662a059 5830/* XXX: not implemented on 440 ? */
99e300ef 5831static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5832{
5833#if defined(CONFIG_USER_ONLY)
e06fcd75 5834 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5835#else
74d37793 5836 TCGv t0;
76db3ba4 5837 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5838 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5839 return;
5840 }
ec72e276 5841 t0 = tcg_temp_new();
76db3ba4 5842 gen_addr_reg_index(ctx, t0);
c6c7cf05 5843 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5844 tcg_temp_free(t0);
76a66253
JM
5845#endif
5846}
5847
5848/* All 405 MAC instructions are translated here */
636aa200
BS
5849static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5850 int ra, int rb, int rt, int Rc)
76a66253 5851{
182608d4
AJ
5852 TCGv t0, t1;
5853
a7812ae4
PB
5854 t0 = tcg_temp_local_new();
5855 t1 = tcg_temp_local_new();
182608d4 5856
76a66253
JM
5857 switch (opc3 & 0x0D) {
5858 case 0x05:
5859 /* macchw - macchw. - macchwo - macchwo. */
5860 /* macchws - macchws. - macchwso - macchwso. */
5861 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5862 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5863 /* mulchw - mulchw. */
182608d4
AJ
5864 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5865 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5866 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5867 break;
5868 case 0x04:
5869 /* macchwu - macchwu. - macchwuo - macchwuo. */
5870 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5871 /* mulchwu - mulchwu. */
182608d4
AJ
5872 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5873 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5874 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5875 break;
5876 case 0x01:
5877 /* machhw - machhw. - machhwo - machhwo. */
5878 /* machhws - machhws. - machhwso - machhwso. */
5879 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5880 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5881 /* mulhhw - mulhhw. */
182608d4
AJ
5882 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5883 tcg_gen_ext16s_tl(t0, t0);
5884 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5885 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5886 break;
5887 case 0x00:
5888 /* machhwu - machhwu. - machhwuo - machhwuo. */
5889 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5890 /* mulhhwu - mulhhwu. */
182608d4
AJ
5891 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5892 tcg_gen_ext16u_tl(t0, t0);
5893 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5894 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5895 break;
5896 case 0x0D:
5897 /* maclhw - maclhw. - maclhwo - maclhwo. */
5898 /* maclhws - maclhws. - maclhwso - maclhwso. */
5899 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5900 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5901 /* mullhw - mullhw. */
182608d4
AJ
5902 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5903 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5904 break;
5905 case 0x0C:
5906 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5907 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5908 /* mullhwu - mullhwu. */
182608d4
AJ
5909 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5910 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
5911 break;
5912 }
76a66253 5913 if (opc2 & 0x04) {
182608d4
AJ
5914 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5915 tcg_gen_mul_tl(t1, t0, t1);
5916 if (opc2 & 0x02) {
5917 /* nmultiply-and-accumulate (0x0E) */
5918 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5919 } else {
5920 /* multiply-and-accumulate (0x0C) */
5921 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5922 }
5923
5924 if (opc3 & 0x12) {
5925 /* Check overflow and/or saturate */
5926 int l1 = gen_new_label();
5927
5928 if (opc3 & 0x10) {
5929 /* Start with XER OV disabled, the most likely case */
da91a00f 5930 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
5931 }
5932 if (opc3 & 0x01) {
5933 /* Signed */
5934 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5935 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5936 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5937 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 5938 if (opc3 & 0x02) {
182608d4
AJ
5939 /* Saturate */
5940 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5941 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5942 }
5943 } else {
5944 /* Unsigned */
5945 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 5946 if (opc3 & 0x02) {
182608d4
AJ
5947 /* Saturate */
5948 tcg_gen_movi_tl(t0, UINT32_MAX);
5949 }
5950 }
5951 if (opc3 & 0x10) {
5952 /* Check overflow */
da91a00f
RH
5953 tcg_gen_movi_tl(cpu_ov, 1);
5954 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
5955 }
5956 gen_set_label(l1);
5957 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5958 }
5959 } else {
5960 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 5961 }
182608d4
AJ
5962 tcg_temp_free(t0);
5963 tcg_temp_free(t1);
76a66253
JM
5964 if (unlikely(Rc) != 0) {
5965 /* Update Rc0 */
182608d4 5966 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
5967 }
5968}
5969
a750fc0b 5970#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 5971static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
5972{ \
5973 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5974 rD(ctx->opcode), Rc(ctx->opcode)); \
5975}
5976
5977/* macchw - macchw. */
a750fc0b 5978GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 5979/* macchwo - macchwo. */
a750fc0b 5980GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 5981/* macchws - macchws. */
a750fc0b 5982GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 5983/* macchwso - macchwso. */
a750fc0b 5984GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 5985/* macchwsu - macchwsu. */
a750fc0b 5986GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 5987/* macchwsuo - macchwsuo. */
a750fc0b 5988GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 5989/* macchwu - macchwu. */
a750fc0b 5990GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 5991/* macchwuo - macchwuo. */
a750fc0b 5992GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 5993/* machhw - machhw. */
a750fc0b 5994GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 5995/* machhwo - machhwo. */
a750fc0b 5996GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 5997/* machhws - machhws. */
a750fc0b 5998GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 5999/* machhwso - machhwso. */
a750fc0b 6000GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 6001/* machhwsu - machhwsu. */
a750fc0b 6002GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 6003/* machhwsuo - machhwsuo. */
a750fc0b 6004GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 6005/* machhwu - machhwu. */
a750fc0b 6006GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 6007/* machhwuo - machhwuo. */
a750fc0b 6008GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 6009/* maclhw - maclhw. */
a750fc0b 6010GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 6011/* maclhwo - maclhwo. */
a750fc0b 6012GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 6013/* maclhws - maclhws. */
a750fc0b 6014GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 6015/* maclhwso - maclhwso. */
a750fc0b 6016GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 6017/* maclhwu - maclhwu. */
a750fc0b 6018GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 6019/* maclhwuo - maclhwuo. */
a750fc0b 6020GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 6021/* maclhwsu - maclhwsu. */
a750fc0b 6022GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 6023/* maclhwsuo - maclhwsuo. */
a750fc0b 6024GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 6025/* nmacchw - nmacchw. */
a750fc0b 6026GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 6027/* nmacchwo - nmacchwo. */
a750fc0b 6028GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 6029/* nmacchws - nmacchws. */
a750fc0b 6030GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 6031/* nmacchwso - nmacchwso. */
a750fc0b 6032GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 6033/* nmachhw - nmachhw. */
a750fc0b 6034GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 6035/* nmachhwo - nmachhwo. */
a750fc0b 6036GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 6037/* nmachhws - nmachhws. */
a750fc0b 6038GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 6039/* nmachhwso - nmachhwso. */
a750fc0b 6040GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 6041/* nmaclhw - nmaclhw. */
a750fc0b 6042GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 6043/* nmaclhwo - nmaclhwo. */
a750fc0b 6044GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 6045/* nmaclhws - nmaclhws. */
a750fc0b 6046GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 6047/* nmaclhwso - nmaclhwso. */
a750fc0b 6048GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
6049
6050/* mulchw - mulchw. */
a750fc0b 6051GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 6052/* mulchwu - mulchwu. */
a750fc0b 6053GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 6054/* mulhhw - mulhhw. */
a750fc0b 6055GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 6056/* mulhhwu - mulhhwu. */
a750fc0b 6057GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 6058/* mullhw - mullhw. */
a750fc0b 6059GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 6060/* mullhwu - mullhwu. */
a750fc0b 6061GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
6062
6063/* mfdcr */
99e300ef 6064static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
6065{
6066#if defined(CONFIG_USER_ONLY)
e06fcd75 6067 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6068#else
06dca6a7 6069 TCGv dcrn;
76db3ba4 6070 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6071 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6072 return;
6073 }
06dca6a7
AJ
6074 /* NIP cannot be restored if the memory exception comes from an helper */
6075 gen_update_nip(ctx, ctx->nip - 4);
6076 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6077 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 6078 tcg_temp_free(dcrn);
76a66253
JM
6079#endif
6080}
6081
6082/* mtdcr */
99e300ef 6083static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
6084{
6085#if defined(CONFIG_USER_ONLY)
e06fcd75 6086 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6087#else
06dca6a7 6088 TCGv dcrn;
76db3ba4 6089 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6090 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6091 return;
6092 }
06dca6a7
AJ
6093 /* NIP cannot be restored if the memory exception comes from an helper */
6094 gen_update_nip(ctx, ctx->nip - 4);
6095 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6096 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 6097 tcg_temp_free(dcrn);
a42bd6cc
JM
6098#endif
6099}
6100
6101/* mfdcrx */
2662a059 6102/* XXX: not implemented on 440 ? */
99e300ef 6103static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
6104{
6105#if defined(CONFIG_USER_ONLY)
e06fcd75 6106 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6107#else
76db3ba4 6108 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6109 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6110 return;
6111 }
06dca6a7
AJ
6112 /* NIP cannot be restored if the memory exception comes from an helper */
6113 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6114 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6115 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 6116 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
6117#endif
6118}
6119
6120/* mtdcrx */
2662a059 6121/* XXX: not implemented on 440 ? */
99e300ef 6122static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
6123{
6124#if defined(CONFIG_USER_ONLY)
e06fcd75 6125 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6126#else
76db3ba4 6127 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6128 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6129 return;
6130 }
06dca6a7
AJ
6131 /* NIP cannot be restored if the memory exception comes from an helper */
6132 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6133 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6134 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 6135 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
6136#endif
6137}
6138
a750fc0b 6139/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6140static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 6141{
06dca6a7
AJ
6142 /* NIP cannot be restored if the memory exception comes from an helper */
6143 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6144 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6145 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
6146 /* Note: Rc update flag set leads to undefined state of Rc0 */
6147}
6148
6149/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6150static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 6151{
06dca6a7
AJ
6152 /* NIP cannot be restored if the memory exception comes from an helper */
6153 gen_update_nip(ctx, ctx->nip - 4);
975e5463 6154 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 6155 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
6156 /* Note: Rc update flag set leads to undefined state of Rc0 */
6157}
6158
76a66253 6159/* dccci */
99e300ef 6160static void gen_dccci(DisasContext *ctx)
76a66253
JM
6161{
6162#if defined(CONFIG_USER_ONLY)
e06fcd75 6163 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6164#else
76db3ba4 6165 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6166 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6167 return;
6168 }
6169 /* interpreted as no-op */
6170#endif
6171}
6172
6173/* dcread */
99e300ef 6174static void gen_dcread(DisasContext *ctx)
76a66253
JM
6175{
6176#if defined(CONFIG_USER_ONLY)
e06fcd75 6177 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6178#else
b61f2753 6179 TCGv EA, val;
76db3ba4 6180 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6181 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6182 return;
6183 }
76db3ba4 6184 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 6185 EA = tcg_temp_new();
76db3ba4 6186 gen_addr_reg_index(ctx, EA);
a7812ae4 6187 val = tcg_temp_new();
76db3ba4 6188 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
6189 tcg_temp_free(val);
6190 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6191 tcg_temp_free(EA);
76a66253
JM
6192#endif
6193}
6194
6195/* icbt */
e8eaa2c0 6196static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6197{
6198 /* interpreted as no-op */
6199 /* XXX: specification say this is treated as a load by the MMU
6200 * but does not generate any exception
6201 */
6202}
6203
6204/* iccci */
99e300ef 6205static void gen_iccci(DisasContext *ctx)
76a66253
JM
6206{
6207#if defined(CONFIG_USER_ONLY)
e06fcd75 6208 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6209#else
76db3ba4 6210 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6211 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6212 return;
6213 }
6214 /* interpreted as no-op */
6215#endif
6216}
6217
6218/* icread */
99e300ef 6219static void gen_icread(DisasContext *ctx)
76a66253
JM
6220{
6221#if defined(CONFIG_USER_ONLY)
e06fcd75 6222 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6223#else
76db3ba4 6224 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6225 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6226 return;
6227 }
6228 /* interpreted as no-op */
6229#endif
6230}
6231
76db3ba4 6232/* rfci (mem_idx only) */
e8eaa2c0 6233static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
6234{
6235#if defined(CONFIG_USER_ONLY)
e06fcd75 6236 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6237#else
76db3ba4 6238 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6239 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6240 return;
6241 }
6242 /* Restore CPU state */
e5f17ac6 6243 gen_helper_40x_rfci(cpu_env);
e06fcd75 6244 gen_sync_exception(ctx);
a42bd6cc
JM
6245#endif
6246}
6247
99e300ef 6248static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6249{
6250#if defined(CONFIG_USER_ONLY)
e06fcd75 6251 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6252#else
76db3ba4 6253 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6254 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6255 return;
6256 }
6257 /* Restore CPU state */
e5f17ac6 6258 gen_helper_rfci(cpu_env);
e06fcd75 6259 gen_sync_exception(ctx);
a42bd6cc
JM
6260#endif
6261}
6262
6263/* BookE specific */
99e300ef 6264
54623277 6265/* XXX: not implemented on 440 ? */
99e300ef 6266static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6267{
6268#if defined(CONFIG_USER_ONLY)
e06fcd75 6269 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6270#else
76db3ba4 6271 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6272 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6273 return;
6274 }
6275 /* Restore CPU state */
e5f17ac6 6276 gen_helper_rfdi(cpu_env);
e06fcd75 6277 gen_sync_exception(ctx);
76a66253
JM
6278#endif
6279}
6280
2662a059 6281/* XXX: not implemented on 440 ? */
99e300ef 6282static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6283{
6284#if defined(CONFIG_USER_ONLY)
e06fcd75 6285 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6286#else
76db3ba4 6287 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6288 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6289 return;
6290 }
6291 /* Restore CPU state */
e5f17ac6 6292 gen_helper_rfmci(cpu_env);
e06fcd75 6293 gen_sync_exception(ctx);
a42bd6cc
JM
6294#endif
6295}
5eb7995e 6296
d9bce9d9 6297/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6298
54623277 6299/* tlbre */
e8eaa2c0 6300static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6301{
6302#if defined(CONFIG_USER_ONLY)
e06fcd75 6303 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6304#else
76db3ba4 6305 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6306 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6307 return;
6308 }
6309 switch (rB(ctx->opcode)) {
6310 case 0:
c6c7cf05
BS
6311 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6312 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6313 break;
6314 case 1:
c6c7cf05
BS
6315 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6316 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6317 break;
6318 default:
e06fcd75 6319 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6320 break;
9a64fbe4 6321 }
76a66253
JM
6322#endif
6323}
6324
d9bce9d9 6325/* tlbsx - tlbsx. */
e8eaa2c0 6326static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6327{
6328#if defined(CONFIG_USER_ONLY)
e06fcd75 6329 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6330#else
74d37793 6331 TCGv t0;
76db3ba4 6332 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6333 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6334 return;
6335 }
74d37793 6336 t0 = tcg_temp_new();
76db3ba4 6337 gen_addr_reg_index(ctx, t0);
c6c7cf05 6338 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6339 tcg_temp_free(t0);
6340 if (Rc(ctx->opcode)) {
6341 int l1 = gen_new_label();
da91a00f 6342 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6343 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6344 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6345 gen_set_label(l1);
6346 }
76a66253 6347#endif
79aceca5
FB
6348}
6349
76a66253 6350/* tlbwe */
e8eaa2c0 6351static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6352{
76a66253 6353#if defined(CONFIG_USER_ONLY)
e06fcd75 6354 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6355#else
76db3ba4 6356 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6357 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6358 return;
6359 }
6360 switch (rB(ctx->opcode)) {
6361 case 0:
c6c7cf05
BS
6362 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6363 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6364 break;
6365 case 1:
c6c7cf05
BS
6366 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6367 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6368 break;
6369 default:
e06fcd75 6370 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6371 break;
9a64fbe4 6372 }
76a66253
JM
6373#endif
6374}
6375
a4bb6c3e 6376/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6377
54623277 6378/* tlbre */
e8eaa2c0 6379static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6380{
6381#if defined(CONFIG_USER_ONLY)
e06fcd75 6382 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6383#else
76db3ba4 6384 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6385 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6386 return;
6387 }
6388 switch (rB(ctx->opcode)) {
6389 case 0:
5eb7995e 6390 case 1:
5eb7995e 6391 case 2:
74d37793
AJ
6392 {
6393 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6394 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6395 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6396 tcg_temp_free_i32(t0);
6397 }
5eb7995e
JM
6398 break;
6399 default:
e06fcd75 6400 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6401 break;
6402 }
6403#endif
6404}
6405
6406/* tlbsx - tlbsx. */
e8eaa2c0 6407static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6408{
6409#if defined(CONFIG_USER_ONLY)
e06fcd75 6410 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6411#else
74d37793 6412 TCGv t0;
76db3ba4 6413 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6414 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6415 return;
6416 }
74d37793 6417 t0 = tcg_temp_new();
76db3ba4 6418 gen_addr_reg_index(ctx, t0);
c6c7cf05 6419 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6420 tcg_temp_free(t0);
6421 if (Rc(ctx->opcode)) {
6422 int l1 = gen_new_label();
da91a00f 6423 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6424 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6425 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6426 gen_set_label(l1);
6427 }
5eb7995e
JM
6428#endif
6429}
6430
6431/* tlbwe */
e8eaa2c0 6432static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
6433{
6434#if defined(CONFIG_USER_ONLY)
e06fcd75 6435 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6436#else
76db3ba4 6437 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6438 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6439 return;
6440 }
6441 switch (rB(ctx->opcode)) {
6442 case 0:
5eb7995e 6443 case 1:
5eb7995e 6444 case 2:
74d37793
AJ
6445 {
6446 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6447 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6448 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
6449 tcg_temp_free_i32(t0);
6450 }
5eb7995e
JM
6451 break;
6452 default:
e06fcd75 6453 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6454 break;
6455 }
6456#endif
6457}
6458
01662f3e
AG
6459/* TLB management - PowerPC BookE 2.06 implementation */
6460
6461/* tlbre */
6462static void gen_tlbre_booke206(DisasContext *ctx)
6463{
6464#if defined(CONFIG_USER_ONLY)
6465 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6466#else
6467 if (unlikely(!ctx->mem_idx)) {
6468 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6469 return;
6470 }
6471
c6c7cf05 6472 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6473#endif
6474}
6475
6476/* tlbsx - tlbsx. */
6477static void gen_tlbsx_booke206(DisasContext *ctx)
6478{
6479#if defined(CONFIG_USER_ONLY)
6480 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6481#else
6482 TCGv t0;
6483 if (unlikely(!ctx->mem_idx)) {
6484 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6485 return;
6486 }
6487
6488 if (rA(ctx->opcode)) {
6489 t0 = tcg_temp_new();
6490 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6491 } else {
6492 t0 = tcg_const_tl(0);
6493 }
6494
6495 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6496 gen_helper_booke206_tlbsx(cpu_env, t0);
01662f3e
AG
6497#endif
6498}
6499
6500/* tlbwe */
6501static void gen_tlbwe_booke206(DisasContext *ctx)
6502{
6503#if defined(CONFIG_USER_ONLY)
6504 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6505#else
6506 if (unlikely(!ctx->mem_idx)) {
6507 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6508 return;
6509 }
3f162d11 6510 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6511 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6512#endif
6513}
6514
6515static void gen_tlbivax_booke206(DisasContext *ctx)
6516{
6517#if defined(CONFIG_USER_ONLY)
6518 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6519#else
6520 TCGv t0;
6521 if (unlikely(!ctx->mem_idx)) {
6522 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6523 return;
6524 }
6525
6526 t0 = tcg_temp_new();
6527 gen_addr_reg_index(ctx, t0);
6528
c6c7cf05 6529 gen_helper_booke206_tlbivax(cpu_env, t0);
01662f3e
AG
6530#endif
6531}
6532
6d3db821
AG
6533static void gen_tlbilx_booke206(DisasContext *ctx)
6534{
6535#if defined(CONFIG_USER_ONLY)
6536 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6537#else
6538 TCGv t0;
6539 if (unlikely(!ctx->mem_idx)) {
6540 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6541 return;
6542 }
6543
6544 t0 = tcg_temp_new();
6545 gen_addr_reg_index(ctx, t0);
6546
6547 switch((ctx->opcode >> 21) & 0x3) {
6548 case 0:
c6c7cf05 6549 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6550 break;
6551 case 1:
c6c7cf05 6552 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6553 break;
6554 case 3:
c6c7cf05 6555 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6556 break;
6557 default:
6558 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6559 break;
6560 }
6561
6562 tcg_temp_free(t0);
6563#endif
6564}
6565
01662f3e 6566
76a66253 6567/* wrtee */
99e300ef 6568static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6569{
6570#if defined(CONFIG_USER_ONLY)
e06fcd75 6571 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6572#else
6527f6ea 6573 TCGv t0;
76db3ba4 6574 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6575 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6576 return;
6577 }
6527f6ea
AJ
6578 t0 = tcg_temp_new();
6579 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6580 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6581 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6582 tcg_temp_free(t0);
dee96f6c
JM
6583 /* Stop translation to have a chance to raise an exception
6584 * if we just set msr_ee to 1
6585 */
e06fcd75 6586 gen_stop_exception(ctx);
76a66253
JM
6587#endif
6588}
6589
6590/* wrteei */
99e300ef 6591static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6592{
6593#if defined(CONFIG_USER_ONLY)
e06fcd75 6594 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6595#else
76db3ba4 6596 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6597 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6598 return;
6599 }
fbe73008 6600 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6601 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6602 /* Stop translation to have a chance to raise an exception */
e06fcd75 6603 gen_stop_exception(ctx);
6527f6ea 6604 } else {
1b6e5f99 6605 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6606 }
76a66253
JM
6607#endif
6608}
6609
08e46e54 6610/* PowerPC 440 specific instructions */
99e300ef 6611
54623277 6612/* dlmzb */
99e300ef 6613static void gen_dlmzb(DisasContext *ctx)
76a66253 6614{
ef0d51af 6615 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6616 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6617 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6618 tcg_temp_free_i32(t0);
76a66253
JM
6619}
6620
6621/* mbar replaces eieio on 440 */
99e300ef 6622static void gen_mbar(DisasContext *ctx)
76a66253
JM
6623{
6624 /* interpreted as no-op */
6625}
6626
6627/* msync replaces sync on 440 */
dcb2b9e1 6628static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6629{
6630 /* interpreted as no-op */
6631}
6632
6633/* icbt */
e8eaa2c0 6634static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6635{
6636 /* interpreted as no-op */
6637 /* XXX: specification say this is treated as a load by the MMU
6638 * but does not generate any exception
6639 */
79aceca5
FB
6640}
6641
9e0b5cb1
AG
6642/* Embedded.Processor Control */
6643
6644static void gen_msgclr(DisasContext *ctx)
6645{
6646#if defined(CONFIG_USER_ONLY)
6647 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6648#else
6649 if (unlikely(ctx->mem_idx == 0)) {
6650 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6651 return;
6652 }
6653
e5f17ac6 6654 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6655#endif
6656}
6657
d5d11a39
AG
6658static void gen_msgsnd(DisasContext *ctx)
6659{
6660#if defined(CONFIG_USER_ONLY)
6661 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6662#else
6663 if (unlikely(ctx->mem_idx == 0)) {
6664 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6665 return;
6666 }
6667
6668 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6669#endif
6670}
6671
a9d9eb8f
JM
6672/*** Altivec vector extension ***/
6673/* Altivec registers moves */
a9d9eb8f 6674
636aa200 6675static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6676{
e4704b3b 6677 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6678 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6679 return r;
6680}
6681
a9d9eb8f 6682#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6683static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6684{ \
fe1e5c53 6685 TCGv EA; \
a9d9eb8f 6686 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6687 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6688 return; \
6689 } \
76db3ba4 6690 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6691 EA = tcg_temp_new(); \
76db3ba4 6692 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6693 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6694 if (ctx->le_mode) { \
6695 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6696 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6697 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6698 } else { \
76db3ba4 6699 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6700 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6701 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6702 } \
6703 tcg_temp_free(EA); \
a9d9eb8f
JM
6704}
6705
6706#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6707static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6708{ \
fe1e5c53 6709 TCGv EA; \
a9d9eb8f 6710 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6711 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6712 return; \
6713 } \
76db3ba4 6714 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6715 EA = tcg_temp_new(); \
76db3ba4 6716 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6717 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6718 if (ctx->le_mode) { \
6719 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6720 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6721 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6722 } else { \
76db3ba4 6723 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6724 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6725 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6726 } \
6727 tcg_temp_free(EA); \
a9d9eb8f
JM
6728}
6729
cbfb6ae9 6730#define GEN_VR_LVE(name, opc2, opc3) \
99e300ef 6731static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6732 { \
6733 TCGv EA; \
6734 TCGv_ptr rs; \
6735 if (unlikely(!ctx->altivec_enabled)) { \
6736 gen_exception(ctx, POWERPC_EXCP_VPU); \
6737 return; \
6738 } \
6739 gen_set_access_type(ctx, ACCESS_INT); \
6740 EA = tcg_temp_new(); \
6741 gen_addr_reg_index(ctx, EA); \
6742 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6743 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6744 tcg_temp_free(EA); \
6745 tcg_temp_free_ptr(rs); \
6746 }
6747
6748#define GEN_VR_STVE(name, opc2, opc3) \
99e300ef 6749static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6750 { \
6751 TCGv EA; \
6752 TCGv_ptr rs; \
6753 if (unlikely(!ctx->altivec_enabled)) { \
6754 gen_exception(ctx, POWERPC_EXCP_VPU); \
6755 return; \
6756 } \
6757 gen_set_access_type(ctx, ACCESS_INT); \
6758 EA = tcg_temp_new(); \
6759 gen_addr_reg_index(ctx, EA); \
6760 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6761 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6762 tcg_temp_free(EA); \
6763 tcg_temp_free_ptr(rs); \
6764 }
6765
fe1e5c53 6766GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6767/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6768GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6769
cbfb6ae9
AJ
6770GEN_VR_LVE(bx, 0x07, 0x00);
6771GEN_VR_LVE(hx, 0x07, 0x01);
6772GEN_VR_LVE(wx, 0x07, 0x02);
6773
fe1e5c53 6774GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6775/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6776GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6777
cbfb6ae9
AJ
6778GEN_VR_STVE(bx, 0x07, 0x04);
6779GEN_VR_STVE(hx, 0x07, 0x05);
6780GEN_VR_STVE(wx, 0x07, 0x06);
6781
99e300ef 6782static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6783{
6784 TCGv_ptr rd;
6785 TCGv EA;
6786 if (unlikely(!ctx->altivec_enabled)) {
6787 gen_exception(ctx, POWERPC_EXCP_VPU);
6788 return;
6789 }
6790 EA = tcg_temp_new();
6791 gen_addr_reg_index(ctx, EA);
6792 rd = gen_avr_ptr(rD(ctx->opcode));
6793 gen_helper_lvsl(rd, EA);
6794 tcg_temp_free(EA);
6795 tcg_temp_free_ptr(rd);
6796}
6797
99e300ef 6798static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6799{
6800 TCGv_ptr rd;
6801 TCGv EA;
6802 if (unlikely(!ctx->altivec_enabled)) {
6803 gen_exception(ctx, POWERPC_EXCP_VPU);
6804 return;
6805 }
6806 EA = tcg_temp_new();
6807 gen_addr_reg_index(ctx, EA);
6808 rd = gen_avr_ptr(rD(ctx->opcode));
6809 gen_helper_lvsr(rd, EA);
6810 tcg_temp_free(EA);
6811 tcg_temp_free_ptr(rd);
6812}
6813
99e300ef 6814static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6815{
6816 TCGv_i32 t;
6817 if (unlikely(!ctx->altivec_enabled)) {
6818 gen_exception(ctx, POWERPC_EXCP_VPU);
6819 return;
6820 }
6821 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6822 t = tcg_temp_new_i32();
1328c2bf 6823 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6824 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6825 tcg_temp_free_i32(t);
785f451b
AJ
6826}
6827
99e300ef 6828static void gen_mtvscr(DisasContext *ctx)
785f451b 6829{
6e87b7c7 6830 TCGv_ptr p;
785f451b
AJ
6831 if (unlikely(!ctx->altivec_enabled)) {
6832 gen_exception(ctx, POWERPC_EXCP_VPU);
6833 return;
6834 }
6e87b7c7 6835 p = gen_avr_ptr(rD(ctx->opcode));
d15f74fb 6836 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6837 tcg_temp_free_ptr(p);
785f451b
AJ
6838}
6839
7a9b96cf
AJ
6840/* Logical operations */
6841#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6842static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6843{ \
6844 if (unlikely(!ctx->altivec_enabled)) { \
6845 gen_exception(ctx, POWERPC_EXCP_VPU); \
6846 return; \
6847 } \
6848 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6849 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6850}
6851
6852GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6853GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6854GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6855GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6856GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
111c5f54
TM
6857GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
6858GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
6859GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
7a9b96cf 6860
8e27dd6f 6861#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6862static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6863{ \
6864 TCGv_ptr ra, rb, rd; \
6865 if (unlikely(!ctx->altivec_enabled)) { \
6866 gen_exception(ctx, POWERPC_EXCP_VPU); \
6867 return; \
6868 } \
6869 ra = gen_avr_ptr(rA(ctx->opcode)); \
6870 rb = gen_avr_ptr(rB(ctx->opcode)); \
6871 rd = gen_avr_ptr(rD(ctx->opcode)); \
6872 gen_helper_##name (rd, ra, rb); \
6873 tcg_temp_free_ptr(ra); \
6874 tcg_temp_free_ptr(rb); \
6875 tcg_temp_free_ptr(rd); \
6876}
6877
d15f74fb
BS
6878#define GEN_VXFORM_ENV(name, opc2, opc3) \
6879static void glue(gen_, name)(DisasContext *ctx) \
6880{ \
6881 TCGv_ptr ra, rb, rd; \
6882 if (unlikely(!ctx->altivec_enabled)) { \
6883 gen_exception(ctx, POWERPC_EXCP_VPU); \
6884 return; \
6885 } \
6886 ra = gen_avr_ptr(rA(ctx->opcode)); \
6887 rb = gen_avr_ptr(rB(ctx->opcode)); \
6888 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6889 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6890 tcg_temp_free_ptr(ra); \
6891 tcg_temp_free_ptr(rb); \
6892 tcg_temp_free_ptr(rd); \
9b47bb49
TM
6893}
6894
6895#define GEN_VXFORM3(name, opc2, opc3) \
6896static void glue(gen_, name)(DisasContext *ctx) \
6897{ \
6898 TCGv_ptr ra, rb, rc, rd; \
6899 if (unlikely(!ctx->altivec_enabled)) { \
6900 gen_exception(ctx, POWERPC_EXCP_VPU); \
6901 return; \
6902 } \
6903 ra = gen_avr_ptr(rA(ctx->opcode)); \
6904 rb = gen_avr_ptr(rB(ctx->opcode)); \
6905 rc = gen_avr_ptr(rC(ctx->opcode)); \
6906 rd = gen_avr_ptr(rD(ctx->opcode)); \
6907 gen_helper_##name(rd, ra, rb, rc); \
6908 tcg_temp_free_ptr(ra); \
6909 tcg_temp_free_ptr(rb); \
6910 tcg_temp_free_ptr(rc); \
6911 tcg_temp_free_ptr(rd); \
d15f74fb
BS
6912}
6913
5dffff5a
TM
6914/*
6915 * Support for Altivec instruction pairs that use bit 31 (Rc) as
6916 * an opcode bit. In general, these pairs come from different
6917 * versions of the ISA, so we must also support a pair of flags for
6918 * each instruction.
6919 */
6920#define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
6921static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6922{ \
6923 if ((Rc(ctx->opcode) == 0) && \
6924 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
6925 gen_##name0(ctx); \
6926 } else if ((Rc(ctx->opcode) == 1) && \
6927 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
6928 gen_##name1(ctx); \
6929 } else { \
6930 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
6931 } \
6932}
6933
7872c51c
AJ
6934GEN_VXFORM(vaddubm, 0, 0);
6935GEN_VXFORM(vadduhm, 0, 1);
6936GEN_VXFORM(vadduwm, 0, 2);
56eabc75 6937GEN_VXFORM(vaddudm, 0, 3);
7872c51c
AJ
6938GEN_VXFORM(vsububm, 0, 16);
6939GEN_VXFORM(vsubuhm, 0, 17);
6940GEN_VXFORM(vsubuwm, 0, 18);
56eabc75 6941GEN_VXFORM(vsubudm, 0, 19);
e4039339
AJ
6942GEN_VXFORM(vmaxub, 1, 0);
6943GEN_VXFORM(vmaxuh, 1, 1);
6944GEN_VXFORM(vmaxuw, 1, 2);
8203e31b 6945GEN_VXFORM(vmaxud, 1, 3);
e4039339
AJ
6946GEN_VXFORM(vmaxsb, 1, 4);
6947GEN_VXFORM(vmaxsh, 1, 5);
6948GEN_VXFORM(vmaxsw, 1, 6);
8203e31b 6949GEN_VXFORM(vmaxsd, 1, 7);
e4039339
AJ
6950GEN_VXFORM(vminub, 1, 8);
6951GEN_VXFORM(vminuh, 1, 9);
6952GEN_VXFORM(vminuw, 1, 10);
8203e31b 6953GEN_VXFORM(vminud, 1, 11);
e4039339
AJ
6954GEN_VXFORM(vminsb, 1, 12);
6955GEN_VXFORM(vminsh, 1, 13);
6956GEN_VXFORM(vminsw, 1, 14);
8203e31b 6957GEN_VXFORM(vminsd, 1, 15);
fab3cbe9
AJ
6958GEN_VXFORM(vavgub, 1, 16);
6959GEN_VXFORM(vavguh, 1, 17);
6960GEN_VXFORM(vavguw, 1, 18);
6961GEN_VXFORM(vavgsb, 1, 20);
6962GEN_VXFORM(vavgsh, 1, 21);
6963GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
6964GEN_VXFORM(vmrghb, 6, 0);
6965GEN_VXFORM(vmrghh, 6, 1);
6966GEN_VXFORM(vmrghw, 6, 2);
6967GEN_VXFORM(vmrglb, 6, 4);
6968GEN_VXFORM(vmrglh, 6, 5);
6969GEN_VXFORM(vmrglw, 6, 6);
e0ffe77f
TM
6970
6971static void gen_vmrgew(DisasContext *ctx)
6972{
6973 TCGv_i64 tmp;
6974 int VT, VA, VB;
6975 if (unlikely(!ctx->altivec_enabled)) {
6976 gen_exception(ctx, POWERPC_EXCP_VPU);
6977 return;
6978 }
6979 VT = rD(ctx->opcode);
6980 VA = rA(ctx->opcode);
6981 VB = rB(ctx->opcode);
6982 tmp = tcg_temp_new_i64();
6983 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
6984 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
6985 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
6986 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
6987 tcg_temp_free_i64(tmp);
6988}
6989
6990static void gen_vmrgow(DisasContext *ctx)
6991{
6992 int VT, VA, VB;
6993 if (unlikely(!ctx->altivec_enabled)) {
6994 gen_exception(ctx, POWERPC_EXCP_VPU);
6995 return;
6996 }
6997 VT = rD(ctx->opcode);
6998 VA = rA(ctx->opcode);
6999 VB = rB(ctx->opcode);
7000
7001 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7002 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7003}
7004
2c277908
AJ
7005GEN_VXFORM(vmuloub, 4, 0);
7006GEN_VXFORM(vmulouh, 4, 1);
63be0936 7007GEN_VXFORM(vmulouw, 4, 2);
953f0f58
TM
7008GEN_VXFORM(vmuluwm, 4, 2);
7009GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7010 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
2c277908
AJ
7011GEN_VXFORM(vmulosb, 4, 4);
7012GEN_VXFORM(vmulosh, 4, 5);
63be0936 7013GEN_VXFORM(vmulosw, 4, 6);
2c277908
AJ
7014GEN_VXFORM(vmuleub, 4, 8);
7015GEN_VXFORM(vmuleuh, 4, 9);
63be0936 7016GEN_VXFORM(vmuleuw, 4, 10);
2c277908
AJ
7017GEN_VXFORM(vmulesb, 4, 12);
7018GEN_VXFORM(vmulesh, 4, 13);
63be0936 7019GEN_VXFORM(vmulesw, 4, 14);
d79f0809
AJ
7020GEN_VXFORM(vslb, 2, 4);
7021GEN_VXFORM(vslh, 2, 5);
7022GEN_VXFORM(vslw, 2, 6);
2fdf78e6 7023GEN_VXFORM(vsld, 2, 23);
07ef34c3
AJ
7024GEN_VXFORM(vsrb, 2, 8);
7025GEN_VXFORM(vsrh, 2, 9);
7026GEN_VXFORM(vsrw, 2, 10);
2fdf78e6 7027GEN_VXFORM(vsrd, 2, 27);
07ef34c3
AJ
7028GEN_VXFORM(vsrab, 2, 12);
7029GEN_VXFORM(vsrah, 2, 13);
7030GEN_VXFORM(vsraw, 2, 14);
2fdf78e6 7031GEN_VXFORM(vsrad, 2, 15);
7b239bec
AJ
7032GEN_VXFORM(vslo, 6, 16);
7033GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
7034GEN_VXFORM(vaddcuw, 0, 6);
7035GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
7036GEN_VXFORM_ENV(vaddubs, 0, 8);
7037GEN_VXFORM_ENV(vadduhs, 0, 9);
7038GEN_VXFORM_ENV(vadduws, 0, 10);
7039GEN_VXFORM_ENV(vaddsbs, 0, 12);
7040GEN_VXFORM_ENV(vaddshs, 0, 13);
7041GEN_VXFORM_ENV(vaddsws, 0, 14);
7042GEN_VXFORM_ENV(vsububs, 0, 24);
7043GEN_VXFORM_ENV(vsubuhs, 0, 25);
7044GEN_VXFORM_ENV(vsubuws, 0, 26);
7045GEN_VXFORM_ENV(vsubsbs, 0, 28);
7046GEN_VXFORM_ENV(vsubshs, 0, 29);
7047GEN_VXFORM_ENV(vsubsws, 0, 30);
b41da4eb
TM
7048GEN_VXFORM(vadduqm, 0, 4);
7049GEN_VXFORM(vaddcuq, 0, 5);
7050GEN_VXFORM3(vaddeuqm, 30, 0);
7051GEN_VXFORM3(vaddecuq, 30, 0);
7052GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7053 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7054GEN_VXFORM(vsubuqm, 0, 20);
7055GEN_VXFORM(vsubcuq, 0, 21);
7056GEN_VXFORM3(vsubeuqm, 31, 0);
7057GEN_VXFORM3(vsubecuq, 31, 0);
7058GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7059 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
5e1d0985
AJ
7060GEN_VXFORM(vrlb, 2, 0);
7061GEN_VXFORM(vrlh, 2, 1);
7062GEN_VXFORM(vrlw, 2, 2);
2fdf78e6 7063GEN_VXFORM(vrld, 2, 3);
d9430add
AJ
7064GEN_VXFORM(vsl, 2, 7);
7065GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
7066GEN_VXFORM_ENV(vpkuhum, 7, 0);
7067GEN_VXFORM_ENV(vpkuwum, 7, 1);
024215b2 7068GEN_VXFORM_ENV(vpkudum, 7, 17);
d15f74fb
BS
7069GEN_VXFORM_ENV(vpkuhus, 7, 2);
7070GEN_VXFORM_ENV(vpkuwus, 7, 3);
024215b2 7071GEN_VXFORM_ENV(vpkudus, 7, 19);
d15f74fb
BS
7072GEN_VXFORM_ENV(vpkshus, 7, 4);
7073GEN_VXFORM_ENV(vpkswus, 7, 5);
024215b2 7074GEN_VXFORM_ENV(vpksdus, 7, 21);
d15f74fb
BS
7075GEN_VXFORM_ENV(vpkshss, 7, 6);
7076GEN_VXFORM_ENV(vpkswss, 7, 7);
024215b2 7077GEN_VXFORM_ENV(vpksdss, 7, 23);
1dd9ffb9 7078GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
7079GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7080GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7081GEN_VXFORM_ENV(vsum4shs, 4, 25);
7082GEN_VXFORM_ENV(vsum2sws, 4, 26);
7083GEN_VXFORM_ENV(vsumsws, 4, 30);
7084GEN_VXFORM_ENV(vaddfp, 5, 0);
7085GEN_VXFORM_ENV(vsubfp, 5, 1);
7086GEN_VXFORM_ENV(vmaxfp, 5, 16);
7087GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 7088
0cbcd906 7089#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 7090static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
7091 { \
7092 TCGv_ptr ra, rb, rd; \
7093 if (unlikely(!ctx->altivec_enabled)) { \
7094 gen_exception(ctx, POWERPC_EXCP_VPU); \
7095 return; \
7096 } \
7097 ra = gen_avr_ptr(rA(ctx->opcode)); \
7098 rb = gen_avr_ptr(rB(ctx->opcode)); \
7099 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 7100 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
7101 tcg_temp_free_ptr(ra); \
7102 tcg_temp_free_ptr(rb); \
7103 tcg_temp_free_ptr(rd); \
7104 }
7105
7106#define GEN_VXRFORM(name, opc2, opc3) \
7107 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7108 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7109
a737d3eb
TM
7110/*
7111 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7112 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7113 * come from different versions of the ISA, so we must also support a
7114 * pair of flags for each instruction.
7115 */
7116#define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7117static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7118{ \
7119 if ((Rc(ctx->opcode) == 0) && \
7120 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7121 if (Rc21(ctx->opcode) == 0) { \
7122 gen_##name0(ctx); \
7123 } else { \
7124 gen_##name0##_(ctx); \
7125 } \
7126 } else if ((Rc(ctx->opcode) == 1) && \
7127 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7128 if (Rc21(ctx->opcode) == 0) { \
7129 gen_##name1(ctx); \
7130 } else { \
7131 gen_##name1##_(ctx); \
7132 } \
7133 } else { \
7134 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7135 } \
7136}
7137
1add6e23
AJ
7138GEN_VXRFORM(vcmpequb, 3, 0)
7139GEN_VXRFORM(vcmpequh, 3, 1)
7140GEN_VXRFORM(vcmpequw, 3, 2)
6f3dab41 7141GEN_VXRFORM(vcmpequd, 3, 3)
1add6e23
AJ
7142GEN_VXRFORM(vcmpgtsb, 3, 12)
7143GEN_VXRFORM(vcmpgtsh, 3, 13)
7144GEN_VXRFORM(vcmpgtsw, 3, 14)
6f3dab41 7145GEN_VXRFORM(vcmpgtsd, 3, 15)
1add6e23
AJ
7146GEN_VXRFORM(vcmpgtub, 3, 8)
7147GEN_VXRFORM(vcmpgtuh, 3, 9)
7148GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 7149GEN_VXRFORM(vcmpgtud, 3, 11)
819ca121
AJ
7150GEN_VXRFORM(vcmpeqfp, 3, 3)
7151GEN_VXRFORM(vcmpgefp, 3, 7)
7152GEN_VXRFORM(vcmpgtfp, 3, 11)
7153GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 7154
6f3dab41
TM
7155GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7156 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7157GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7158 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7159GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7160 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7161
c026766b 7162#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7163static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
7164 { \
7165 TCGv_ptr rd; \
7166 TCGv_i32 simm; \
7167 if (unlikely(!ctx->altivec_enabled)) { \
7168 gen_exception(ctx, POWERPC_EXCP_VPU); \
7169 return; \
7170 } \
7171 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7172 rd = gen_avr_ptr(rD(ctx->opcode)); \
7173 gen_helper_##name (rd, simm); \
7174 tcg_temp_free_i32(simm); \
7175 tcg_temp_free_ptr(rd); \
7176 }
7177
7178GEN_VXFORM_SIMM(vspltisb, 6, 12);
7179GEN_VXFORM_SIMM(vspltish, 6, 13);
7180GEN_VXFORM_SIMM(vspltisw, 6, 14);
7181
de5f2484 7182#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 7183static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
7184 { \
7185 TCGv_ptr rb, rd; \
7186 if (unlikely(!ctx->altivec_enabled)) { \
7187 gen_exception(ctx, POWERPC_EXCP_VPU); \
7188 return; \
7189 } \
7190 rb = gen_avr_ptr(rB(ctx->opcode)); \
7191 rd = gen_avr_ptr(rD(ctx->opcode)); \
7192 gen_helper_##name (rd, rb); \
7193 tcg_temp_free_ptr(rb); \
7194 tcg_temp_free_ptr(rd); \
7195 }
7196
d15f74fb
BS
7197#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7198static void glue(gen_, name)(DisasContext *ctx) \
7199 { \
7200 TCGv_ptr rb, rd; \
7201 \
7202 if (unlikely(!ctx->altivec_enabled)) { \
7203 gen_exception(ctx, POWERPC_EXCP_VPU); \
7204 return; \
7205 } \
7206 rb = gen_avr_ptr(rB(ctx->opcode)); \
7207 rd = gen_avr_ptr(rD(ctx->opcode)); \
7208 gen_helper_##name(cpu_env, rd, rb); \
7209 tcg_temp_free_ptr(rb); \
7210 tcg_temp_free_ptr(rd); \
7211 }
7212
6cf1c6e5
AJ
7213GEN_VXFORM_NOA(vupkhsb, 7, 8);
7214GEN_VXFORM_NOA(vupkhsh, 7, 9);
4430e076 7215GEN_VXFORM_NOA(vupkhsw, 7, 25);
6cf1c6e5
AJ
7216GEN_VXFORM_NOA(vupklsb, 7, 10);
7217GEN_VXFORM_NOA(vupklsh, 7, 11);
4430e076 7218GEN_VXFORM_NOA(vupklsw, 7, 27);
79f85c3a
AJ
7219GEN_VXFORM_NOA(vupkhpx, 7, 13);
7220GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
7221GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7222GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7223GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7224GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
7225GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
7226GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
7227GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
7228GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
79f85c3a 7229
21d21583 7230#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7231static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
7232 { \
7233 TCGv_ptr rd; \
7234 TCGv_i32 simm; \
7235 if (unlikely(!ctx->altivec_enabled)) { \
7236 gen_exception(ctx, POWERPC_EXCP_VPU); \
7237 return; \
7238 } \
7239 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7240 rd = gen_avr_ptr(rD(ctx->opcode)); \
7241 gen_helper_##name (rd, simm); \
7242 tcg_temp_free_i32(simm); \
7243 tcg_temp_free_ptr(rd); \
7244 }
7245
27a4edb3 7246#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 7247static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
7248 { \
7249 TCGv_ptr rb, rd; \
7250 TCGv_i32 uimm; \
7251 if (unlikely(!ctx->altivec_enabled)) { \
7252 gen_exception(ctx, POWERPC_EXCP_VPU); \
7253 return; \
7254 } \
7255 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7256 rb = gen_avr_ptr(rB(ctx->opcode)); \
7257 rd = gen_avr_ptr(rD(ctx->opcode)); \
7258 gen_helper_##name (rd, rb, uimm); \
7259 tcg_temp_free_i32(uimm); \
7260 tcg_temp_free_ptr(rb); \
7261 tcg_temp_free_ptr(rd); \
7262 }
7263
d15f74fb
BS
7264#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7265static void glue(gen_, name)(DisasContext *ctx) \
7266 { \
7267 TCGv_ptr rb, rd; \
7268 TCGv_i32 uimm; \
7269 \
7270 if (unlikely(!ctx->altivec_enabled)) { \
7271 gen_exception(ctx, POWERPC_EXCP_VPU); \
7272 return; \
7273 } \
7274 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7275 rb = gen_avr_ptr(rB(ctx->opcode)); \
7276 rd = gen_avr_ptr(rD(ctx->opcode)); \
7277 gen_helper_##name(cpu_env, rd, rb, uimm); \
7278 tcg_temp_free_i32(uimm); \
7279 tcg_temp_free_ptr(rb); \
7280 tcg_temp_free_ptr(rd); \
7281 }
7282
e4e6bee7
AJ
7283GEN_VXFORM_UIMM(vspltb, 6, 8);
7284GEN_VXFORM_UIMM(vsplth, 6, 9);
7285GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
7286GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7287GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7288GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7289GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 7290
99e300ef 7291static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
7292{
7293 TCGv_ptr ra, rb, rd;
fce5ecb7 7294 TCGv_i32 sh;
cd633b10
AJ
7295 if (unlikely(!ctx->altivec_enabled)) {
7296 gen_exception(ctx, POWERPC_EXCP_VPU);
7297 return;
7298 }
7299 ra = gen_avr_ptr(rA(ctx->opcode));
7300 rb = gen_avr_ptr(rB(ctx->opcode));
7301 rd = gen_avr_ptr(rD(ctx->opcode));
7302 sh = tcg_const_i32(VSH(ctx->opcode));
7303 gen_helper_vsldoi (rd, ra, rb, sh);
7304 tcg_temp_free_ptr(ra);
7305 tcg_temp_free_ptr(rb);
7306 tcg_temp_free_ptr(rd);
fce5ecb7 7307 tcg_temp_free_i32(sh);
cd633b10
AJ
7308}
7309
707cec33 7310#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 7311static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
7312 { \
7313 TCGv_ptr ra, rb, rc, rd; \
7314 if (unlikely(!ctx->altivec_enabled)) { \
7315 gen_exception(ctx, POWERPC_EXCP_VPU); \
7316 return; \
7317 } \
7318 ra = gen_avr_ptr(rA(ctx->opcode)); \
7319 rb = gen_avr_ptr(rB(ctx->opcode)); \
7320 rc = gen_avr_ptr(rC(ctx->opcode)); \
7321 rd = gen_avr_ptr(rD(ctx->opcode)); \
7322 if (Rc(ctx->opcode)) { \
d15f74fb 7323 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 7324 } else { \
d15f74fb 7325 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
7326 } \
7327 tcg_temp_free_ptr(ra); \
7328 tcg_temp_free_ptr(rb); \
7329 tcg_temp_free_ptr(rc); \
7330 tcg_temp_free_ptr(rd); \
7331 }
7332
b161ae27
AJ
7333GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7334
99e300ef 7335static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
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 gen_helper_vmladduhm(rd, ra, rb, rc);
7347 tcg_temp_free_ptr(ra);
7348 tcg_temp_free_ptr(rb);
7349 tcg_temp_free_ptr(rc);
7350 tcg_temp_free_ptr(rd);
7351}
7352
b04ae981 7353GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7354GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7355GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7356GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7357GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7358
f293f04a
TM
7359GEN_VXFORM_NOA(vclzb, 1, 28)
7360GEN_VXFORM_NOA(vclzh, 1, 29)
7361GEN_VXFORM_NOA(vclzw, 1, 30)
7362GEN_VXFORM_NOA(vclzd, 1, 31)
e13500b3
TM
7363GEN_VXFORM_NOA(vpopcntb, 1, 28)
7364GEN_VXFORM_NOA(vpopcnth, 1, 29)
7365GEN_VXFORM_NOA(vpopcntw, 1, 30)
7366GEN_VXFORM_NOA(vpopcntd, 1, 31)
7367GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7368 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7369GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7370 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7371GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7372 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7373GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7374 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
4d82038e 7375GEN_VXFORM(vbpermq, 6, 21);
f1064f61 7376GEN_VXFORM_NOA(vgbbd, 6, 20);
b8476fc7
TM
7377GEN_VXFORM(vpmsumb, 4, 16)
7378GEN_VXFORM(vpmsumh, 4, 17)
7379GEN_VXFORM(vpmsumw, 4, 18)
7380GEN_VXFORM(vpmsumd, 4, 19)
e13500b3 7381
e8f7b27b
TM
7382#define GEN_BCD(op) \
7383static void gen_##op(DisasContext *ctx) \
7384{ \
7385 TCGv_ptr ra, rb, rd; \
7386 TCGv_i32 ps; \
7387 \
7388 if (unlikely(!ctx->altivec_enabled)) { \
7389 gen_exception(ctx, POWERPC_EXCP_VPU); \
7390 return; \
7391 } \
7392 \
7393 ra = gen_avr_ptr(rA(ctx->opcode)); \
7394 rb = gen_avr_ptr(rB(ctx->opcode)); \
7395 rd = gen_avr_ptr(rD(ctx->opcode)); \
7396 \
7397 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7398 \
7399 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7400 \
7401 tcg_temp_free_ptr(ra); \
7402 tcg_temp_free_ptr(rb); \
7403 tcg_temp_free_ptr(rd); \
7404 tcg_temp_free_i32(ps); \
7405}
7406
7407GEN_BCD(bcdadd)
7408GEN_BCD(bcdsub)
7409
7410GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7411 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7412GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7413 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7414GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7415 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7416GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7417 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7418
557d52fa
TM
7419static void gen_vsbox(DisasContext *ctx)
7420{
7421 TCGv_ptr ra, rd;
7422 if (unlikely(!ctx->altivec_enabled)) {
7423 gen_exception(ctx, POWERPC_EXCP_VPU);
7424 return;
7425 }
7426 ra = gen_avr_ptr(rA(ctx->opcode));
7427 rd = gen_avr_ptr(rD(ctx->opcode));
7428 gen_helper_vsbox(rd, ra);
7429 tcg_temp_free_ptr(ra);
7430 tcg_temp_free_ptr(rd);
7431}
7432
7433GEN_VXFORM(vcipher, 4, 20)
7434GEN_VXFORM(vcipherlast, 4, 20)
7435GEN_VXFORM(vncipher, 4, 21)
7436GEN_VXFORM(vncipherlast, 4, 21)
7437
7438GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7439 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7440GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7441 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7442
57354f8f
TM
7443#define VSHASIGMA(op) \
7444static void gen_##op(DisasContext *ctx) \
7445{ \
7446 TCGv_ptr ra, rd; \
7447 TCGv_i32 st_six; \
7448 if (unlikely(!ctx->altivec_enabled)) { \
7449 gen_exception(ctx, POWERPC_EXCP_VPU); \
7450 return; \
7451 } \
7452 ra = gen_avr_ptr(rA(ctx->opcode)); \
7453 rd = gen_avr_ptr(rD(ctx->opcode)); \
7454 st_six = tcg_const_i32(rB(ctx->opcode)); \
7455 gen_helper_##op(rd, ra, st_six); \
7456 tcg_temp_free_ptr(ra); \
7457 tcg_temp_free_ptr(rd); \
7458 tcg_temp_free_i32(st_six); \
7459}
7460
7461VSHASIGMA(vshasigmaw)
7462VSHASIGMA(vshasigmad)
7463
ac174549
TM
7464GEN_VXFORM3(vpermxor, 22, 0xFF)
7465GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7466 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7467
472b24ce
TM
7468/*** VSX extension ***/
7469
7470static inline TCGv_i64 cpu_vsrh(int n)
7471{
7472 if (n < 32) {
7473 return cpu_fpr[n];
7474 } else {
7475 return cpu_avrh[n-32];
7476 }
7477}
7478
7479static inline TCGv_i64 cpu_vsrl(int n)
7480{
7481 if (n < 32) {
7482 return cpu_vsr[n];
7483 } else {
7484 return cpu_avrl[n-32];
7485 }
7486}
7487
e072fe79
TM
7488#define VSX_LOAD_SCALAR(name, operation) \
7489static void gen_##name(DisasContext *ctx) \
7490{ \
7491 TCGv EA; \
7492 if (unlikely(!ctx->vsx_enabled)) { \
7493 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7494 return; \
7495 } \
7496 gen_set_access_type(ctx, ACCESS_INT); \
7497 EA = tcg_temp_new(); \
7498 gen_addr_reg_index(ctx, EA); \
7499 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7500 /* NOTE: cpu_vsrl is undefined */ \
7501 tcg_temp_free(EA); \
7502}
7503
7504VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7505VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7506VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7507VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7508
304af367
TM
7509static void gen_lxvd2x(DisasContext *ctx)
7510{
7511 TCGv EA;
7512 if (unlikely(!ctx->vsx_enabled)) {
7513 gen_exception(ctx, POWERPC_EXCP_VSXU);
7514 return;
7515 }
7516 gen_set_access_type(ctx, ACCESS_INT);
7517 EA = tcg_temp_new();
7518 gen_addr_reg_index(ctx, EA);
7519 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7520 tcg_gen_addi_tl(EA, EA, 8);
7521 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7522 tcg_temp_free(EA);
7523}
7524
ca03b467
TM
7525static void gen_lxvdsx(DisasContext *ctx)
7526{
7527 TCGv EA;
7528 if (unlikely(!ctx->vsx_enabled)) {
7529 gen_exception(ctx, POWERPC_EXCP_VSXU);
7530 return;
7531 }
7532 gen_set_access_type(ctx, ACCESS_INT);
7533 EA = tcg_temp_new();
7534 gen_addr_reg_index(ctx, EA);
7535 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7536 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7537 tcg_temp_free(EA);
7538}
7539
897e61d1
TM
7540static void gen_lxvw4x(DisasContext *ctx)
7541{
f976b09e
AG
7542 TCGv EA;
7543 TCGv_i64 tmp;
897e61d1
TM
7544 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7545 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7546 if (unlikely(!ctx->vsx_enabled)) {
7547 gen_exception(ctx, POWERPC_EXCP_VSXU);
7548 return;
7549 }
7550 gen_set_access_type(ctx, ACCESS_INT);
7551 EA = tcg_temp_new();
f976b09e
AG
7552 tmp = tcg_temp_new_i64();
7553
897e61d1 7554 gen_addr_reg_index(ctx, EA);
f976b09e 7555 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7556 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7557 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7558 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7559
7560 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7561 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7562 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7563 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7564 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7565
7566 tcg_temp_free(EA);
f976b09e 7567 tcg_temp_free_i64(tmp);
897e61d1
TM
7568}
7569
f026da78
TM
7570#define VSX_STORE_SCALAR(name, operation) \
7571static void gen_##name(DisasContext *ctx) \
7572{ \
7573 TCGv EA; \
7574 if (unlikely(!ctx->vsx_enabled)) { \
7575 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7576 return; \
7577 } \
7578 gen_set_access_type(ctx, ACCESS_INT); \
7579 EA = tcg_temp_new(); \
7580 gen_addr_reg_index(ctx, EA); \
7581 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7582 tcg_temp_free(EA); \
9231ba9e
TM
7583}
7584
f026da78 7585VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7586VSX_STORE_SCALAR(stxsiwx, st32_i64)
7587VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7588
fbed2478
TM
7589static void gen_stxvd2x(DisasContext *ctx)
7590{
7591 TCGv EA;
7592 if (unlikely(!ctx->vsx_enabled)) {
7593 gen_exception(ctx, POWERPC_EXCP_VSXU);
7594 return;
7595 }
7596 gen_set_access_type(ctx, ACCESS_INT);
7597 EA = tcg_temp_new();
7598 gen_addr_reg_index(ctx, EA);
7599 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7600 tcg_gen_addi_tl(EA, EA, 8);
7601 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7602 tcg_temp_free(EA);
7603}
7604
86e61ce3
TM
7605static void gen_stxvw4x(DisasContext *ctx)
7606{
f976b09e
AG
7607 TCGv_i64 tmp;
7608 TCGv EA;
86e61ce3
TM
7609 if (unlikely(!ctx->vsx_enabled)) {
7610 gen_exception(ctx, POWERPC_EXCP_VSXU);
7611 return;
7612 }
7613 gen_set_access_type(ctx, ACCESS_INT);
7614 EA = tcg_temp_new();
7615 gen_addr_reg_index(ctx, EA);
f976b09e 7616 tmp = tcg_temp_new_i64();
86e61ce3
TM
7617
7618 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7619 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7620 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7621 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7622
7623 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7624 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7625 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7626 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7627 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7628
7629 tcg_temp_free(EA);
f976b09e 7630 tcg_temp_free_i64(tmp);
86e61ce3
TM
7631}
7632
f5c0f7f9
TM
7633#define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7634static void gen_##name(DisasContext *ctx) \
7635{ \
7636 if (xS(ctx->opcode) < 32) { \
7637 if (unlikely(!ctx->fpu_enabled)) { \
7638 gen_exception(ctx, POWERPC_EXCP_FPU); \
7639 return; \
7640 } \
7641 } else { \
7642 if (unlikely(!ctx->altivec_enabled)) { \
7643 gen_exception(ctx, POWERPC_EXCP_VPU); \
7644 return; \
7645 } \
7646 } \
7647 TCGv_i64 tmp = tcg_temp_new_i64(); \
7648 tcg_gen_##tcgop1(tmp, source); \
7649 tcg_gen_##tcgop2(target, tmp); \
7650 tcg_temp_free_i64(tmp); \
7651}
7652
7653
7654MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7655 cpu_vsrh(xS(ctx->opcode)))
7656MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7657 cpu_gpr[rA(ctx->opcode)])
7658MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7659 cpu_gpr[rA(ctx->opcode)])
7660
7661#if defined(TARGET_PPC64)
7662#define MV_VSRD(name, target, source) \
7663static void gen_##name(DisasContext *ctx) \
7664{ \
7665 if (xS(ctx->opcode) < 32) { \
7666 if (unlikely(!ctx->fpu_enabled)) { \
7667 gen_exception(ctx, POWERPC_EXCP_FPU); \
7668 return; \
7669 } \
7670 } else { \
7671 if (unlikely(!ctx->altivec_enabled)) { \
7672 gen_exception(ctx, POWERPC_EXCP_VPU); \
7673 return; \
7674 } \
7675 } \
7676 tcg_gen_mov_i64(target, source); \
7677}
7678
7679MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7680MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7681
7682#endif
7683
cd73f2c9
TM
7684static void gen_xxpermdi(DisasContext *ctx)
7685{
7686 if (unlikely(!ctx->vsx_enabled)) {
7687 gen_exception(ctx, POWERPC_EXCP_VSXU);
7688 return;
7689 }
7690
f5bc1bfa
TM
7691 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7692 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7693 TCGv_i64 xh, xl;
7694
7695 xh = tcg_temp_new_i64();
7696 xl = tcg_temp_new_i64();
7697
7698 if ((DM(ctx->opcode) & 2) == 0) {
7699 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7700 } else {
7701 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7702 }
7703 if ((DM(ctx->opcode) & 1) == 0) {
7704 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7705 } else {
7706 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7707 }
7708
7709 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7710 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7711
7712 tcg_temp_free_i64(xh);
7713 tcg_temp_free_i64(xl);
cd73f2c9 7714 } else {
f5bc1bfa
TM
7715 if ((DM(ctx->opcode) & 2) == 0) {
7716 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7717 } else {
7718 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7719 }
7720 if ((DM(ctx->opcode) & 1) == 0) {
7721 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7722 } else {
7723 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7724 }
cd73f2c9
TM
7725 }
7726}
7727
df020ce0
TM
7728#define OP_ABS 1
7729#define OP_NABS 2
7730#define OP_NEG 3
7731#define OP_CPSGN 4
e5d7d2b0
PM
7732#define SGN_MASK_DP 0x8000000000000000ull
7733#define SGN_MASK_SP 0x8000000080000000ull
df020ce0
TM
7734
7735#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7736static void glue(gen_, name)(DisasContext * ctx) \
7737 { \
7738 TCGv_i64 xb, sgm; \
7739 if (unlikely(!ctx->vsx_enabled)) { \
7740 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7741 return; \
7742 } \
f976b09e
AG
7743 xb = tcg_temp_new_i64(); \
7744 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7745 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7746 tcg_gen_movi_i64(sgm, sgn_mask); \
7747 switch (op) { \
7748 case OP_ABS: { \
7749 tcg_gen_andc_i64(xb, xb, sgm); \
7750 break; \
7751 } \
7752 case OP_NABS: { \
7753 tcg_gen_or_i64(xb, xb, sgm); \
7754 break; \
7755 } \
7756 case OP_NEG: { \
7757 tcg_gen_xor_i64(xb, xb, sgm); \
7758 break; \
7759 } \
7760 case OP_CPSGN: { \
f976b09e 7761 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7762 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7763 tcg_gen_and_i64(xa, xa, sgm); \
7764 tcg_gen_andc_i64(xb, xb, sgm); \
7765 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7766 tcg_temp_free_i64(xa); \
df020ce0
TM
7767 break; \
7768 } \
7769 } \
7770 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7771 tcg_temp_free_i64(xb); \
7772 tcg_temp_free_i64(sgm); \
df020ce0
TM
7773 }
7774
7775VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7776VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7777VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7778VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7779
be574920
TM
7780#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7781static void glue(gen_, name)(DisasContext * ctx) \
7782 { \
7783 TCGv_i64 xbh, xbl, sgm; \
7784 if (unlikely(!ctx->vsx_enabled)) { \
7785 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7786 return; \
7787 } \
f976b09e
AG
7788 xbh = tcg_temp_new_i64(); \
7789 xbl = tcg_temp_new_i64(); \
7790 sgm = tcg_temp_new_i64(); \
be574920
TM
7791 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7792 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7793 tcg_gen_movi_i64(sgm, sgn_mask); \
7794 switch (op) { \
7795 case OP_ABS: { \
7796 tcg_gen_andc_i64(xbh, xbh, sgm); \
7797 tcg_gen_andc_i64(xbl, xbl, sgm); \
7798 break; \
7799 } \
7800 case OP_NABS: { \
7801 tcg_gen_or_i64(xbh, xbh, sgm); \
7802 tcg_gen_or_i64(xbl, xbl, sgm); \
7803 break; \
7804 } \
7805 case OP_NEG: { \
7806 tcg_gen_xor_i64(xbh, xbh, sgm); \
7807 tcg_gen_xor_i64(xbl, xbl, sgm); \
7808 break; \
7809 } \
7810 case OP_CPSGN: { \
f976b09e
AG
7811 TCGv_i64 xah = tcg_temp_new_i64(); \
7812 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7813 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7814 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7815 tcg_gen_and_i64(xah, xah, sgm); \
7816 tcg_gen_and_i64(xal, xal, sgm); \
7817 tcg_gen_andc_i64(xbh, xbh, sgm); \
7818 tcg_gen_andc_i64(xbl, xbl, sgm); \
7819 tcg_gen_or_i64(xbh, xbh, xah); \
7820 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7821 tcg_temp_free_i64(xah); \
7822 tcg_temp_free_i64(xal); \
be574920
TM
7823 break; \
7824 } \
7825 } \
7826 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7827 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7828 tcg_temp_free_i64(xbh); \
7829 tcg_temp_free_i64(xbl); \
7830 tcg_temp_free_i64(sgm); \
be574920
TM
7831 }
7832
7833VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7834VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7835VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7836VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7837VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7838VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7839VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7840VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7841
3c3cbbdc
TM
7842#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7843static void gen_##name(DisasContext * ctx) \
7844{ \
7845 TCGv_i32 opc; \
7846 if (unlikely(!ctx->vsx_enabled)) { \
7847 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7848 return; \
7849 } \
7850 /* NIP cannot be restored if the memory exception comes from an helper */ \
7851 gen_update_nip(ctx, ctx->nip - 4); \
7852 opc = tcg_const_i32(ctx->opcode); \
7853 gen_helper_##name(cpu_env, opc); \
7854 tcg_temp_free_i32(opc); \
7855}
be574920 7856
3d1140bf
TM
7857#define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7858static void gen_##name(DisasContext * ctx) \
7859{ \
7860 if (unlikely(!ctx->vsx_enabled)) { \
7861 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7862 return; \
7863 } \
7864 /* NIP cannot be restored if the exception comes */ \
7865 /* from a helper. */ \
7866 gen_update_nip(ctx, ctx->nip - 4); \
7867 \
7868 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7869 cpu_vsrh(xB(ctx->opcode))); \
7870}
7871
ee6e02c0
TM
7872GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7873GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7874GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7875GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7876GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7877GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7878GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7879GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7880GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7881GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7882GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7883GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7884GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7885GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7886GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7887GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7888GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
7889GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7890GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
7891GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7892GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568 7893GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7ee19fb9 7894GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
ed8ac568 7895GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7ee19fb9 7896GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
5177d2ca
TM
7897GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7898GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
7899GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
7900GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
7901GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
7902GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
7903GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
7904GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
7905GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
7906GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
7907GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
3d1140bf 7908GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
ee6e02c0 7909
3fd0aadf
TM
7910GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
7911GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 7912GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 7913GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 7914GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 7915GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
968e76bc 7916GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
f53f81e0
TM
7917GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
7918GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
7919GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
7920GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
7921GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
7922GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
7923GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
7924GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
74698350
TM
7925GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
7926GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
3fd0aadf 7927
ee6e02c0
TM
7928GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
7929GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 7930GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 7931GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 7932GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 7933GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 7934GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 7935GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 7936GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
7937GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
7938GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
7939GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
7940GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
7941GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
7942GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
7943GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
7944GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
7945GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
7946GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
7947GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
7948GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
7949GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 7950GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
7951GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
7952GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
7953GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
7954GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
7955GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
7956GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
7957GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
7958GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
7959GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
7960GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
7961GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
7962GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
7963GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
7964
7965GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
7966GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 7967GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 7968GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 7969GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 7970GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 7971GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 7972GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 7973GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
7974GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
7975GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
7976GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
7977GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
7978GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
7979GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
7980GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
7981GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
7982GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
7983GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
7984GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
7985GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
7986GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 7987GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
7988GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
7989GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
7990GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
7991GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
7992GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
7993GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
7994GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
7995GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
7996GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
7997GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
7998GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
7999GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
8000GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 8001
79ca8a6a
TM
8002#define VSX_LOGICAL(name, tcg_op) \
8003static void glue(gen_, name)(DisasContext * ctx) \
8004 { \
8005 if (unlikely(!ctx->vsx_enabled)) { \
8006 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8007 return; \
8008 } \
8009 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8010 cpu_vsrh(xB(ctx->opcode))); \
8011 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8012 cpu_vsrl(xB(ctx->opcode))); \
8013 }
8014
f976b09e
AG
8015VSX_LOGICAL(xxland, tcg_gen_and_i64)
8016VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8017VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8018VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8019VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
67a33f37
TM
8020VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8021VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8022VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
df020ce0 8023
ce577d2e
TM
8024#define VSX_XXMRG(name, high) \
8025static void glue(gen_, name)(DisasContext * ctx) \
8026 { \
8027 TCGv_i64 a0, a1, b0, b1; \
8028 if (unlikely(!ctx->vsx_enabled)) { \
8029 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8030 return; \
8031 } \
f976b09e
AG
8032 a0 = tcg_temp_new_i64(); \
8033 a1 = tcg_temp_new_i64(); \
8034 b0 = tcg_temp_new_i64(); \
8035 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
8036 if (high) { \
8037 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8038 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8039 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8040 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8041 } else { \
8042 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8043 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8044 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8045 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8046 } \
8047 tcg_gen_shri_i64(a0, a0, 32); \
8048 tcg_gen_shri_i64(b0, b0, 32); \
8049 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8050 b0, a0, 32, 32); \
8051 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8052 b1, a1, 32, 32); \
f976b09e
AG
8053 tcg_temp_free_i64(a0); \
8054 tcg_temp_free_i64(a1); \
8055 tcg_temp_free_i64(b0); \
8056 tcg_temp_free_i64(b1); \
ce577d2e
TM
8057 }
8058
8059VSX_XXMRG(xxmrghw, 1)
8060VSX_XXMRG(xxmrglw, 0)
8061
551e3ef7
TM
8062static void gen_xxsel(DisasContext * ctx)
8063{
8064 TCGv_i64 a, b, c;
8065 if (unlikely(!ctx->vsx_enabled)) {
8066 gen_exception(ctx, POWERPC_EXCP_VSXU);
8067 return;
8068 }
f976b09e
AG
8069 a = tcg_temp_new_i64();
8070 b = tcg_temp_new_i64();
8071 c = tcg_temp_new_i64();
551e3ef7
TM
8072
8073 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8074 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8075 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8076
8077 tcg_gen_and_i64(b, b, c);
8078 tcg_gen_andc_i64(a, a, c);
8079 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8080
8081 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8082 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8083 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8084
8085 tcg_gen_and_i64(b, b, c);
8086 tcg_gen_andc_i64(a, a, c);
8087 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8088
f976b09e
AG
8089 tcg_temp_free_i64(a);
8090 tcg_temp_free_i64(b);
8091 tcg_temp_free_i64(c);
551e3ef7
TM
8092}
8093
76c15fe0
TM
8094static void gen_xxspltw(DisasContext *ctx)
8095{
8096 TCGv_i64 b, b2;
8097 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8098 cpu_vsrl(xB(ctx->opcode)) :
8099 cpu_vsrh(xB(ctx->opcode));
8100
8101 if (unlikely(!ctx->vsx_enabled)) {
8102 gen_exception(ctx, POWERPC_EXCP_VSXU);
8103 return;
8104 }
8105
f976b09e
AG
8106 b = tcg_temp_new_i64();
8107 b2 = tcg_temp_new_i64();
76c15fe0
TM
8108
8109 if (UIM(ctx->opcode) & 1) {
8110 tcg_gen_ext32u_i64(b, vsr);
8111 } else {
8112 tcg_gen_shri_i64(b, vsr, 32);
8113 }
8114
8115 tcg_gen_shli_i64(b2, b, 32);
8116 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8117 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8118
f976b09e
AG
8119 tcg_temp_free_i64(b);
8120 tcg_temp_free_i64(b2);
76c15fe0
TM
8121}
8122
acc42968
TM
8123static void gen_xxsldwi(DisasContext *ctx)
8124{
8125 TCGv_i64 xth, xtl;
8126 if (unlikely(!ctx->vsx_enabled)) {
8127 gen_exception(ctx, POWERPC_EXCP_VSXU);
8128 return;
8129 }
f976b09e
AG
8130 xth = tcg_temp_new_i64();
8131 xtl = tcg_temp_new_i64();
acc42968
TM
8132
8133 switch (SHW(ctx->opcode)) {
8134 case 0: {
8135 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8136 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8137 break;
8138 }
8139 case 1: {
f976b09e 8140 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8141 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8142 tcg_gen_shli_i64(xth, xth, 32);
8143 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8144 tcg_gen_shri_i64(t0, t0, 32);
8145 tcg_gen_or_i64(xth, xth, t0);
8146 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8147 tcg_gen_shli_i64(xtl, xtl, 32);
8148 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8149 tcg_gen_shri_i64(t0, t0, 32);
8150 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8151 tcg_temp_free_i64(t0);
acc42968
TM
8152 break;
8153 }
8154 case 2: {
8155 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8156 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8157 break;
8158 }
8159 case 3: {
f976b09e 8160 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8161 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8162 tcg_gen_shli_i64(xth, xth, 32);
8163 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8164 tcg_gen_shri_i64(t0, t0, 32);
8165 tcg_gen_or_i64(xth, xth, t0);
8166 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8167 tcg_gen_shli_i64(xtl, xtl, 32);
8168 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8169 tcg_gen_shri_i64(t0, t0, 32);
8170 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8171 tcg_temp_free_i64(t0);
acc42968
TM
8172 break;
8173 }
8174 }
8175
8176 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8177 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8178
f976b09e
AG
8179 tcg_temp_free_i64(xth);
8180 tcg_temp_free_i64(xtl);
acc42968
TM
8181}
8182
ce577d2e 8183
0487d6a8 8184/*** SPE extension ***/
0487d6a8 8185/* Register moves */
3cd7d1dd 8186
a0e13900
FC
8187static inline void gen_evmra(DisasContext *ctx)
8188{
8189
8190 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8191 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8192 return;
8193 }
8194
8195#if defined(TARGET_PPC64)
8196 /* rD := rA */
8197 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8198
8199 /* spe_acc := rA */
8200 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
8201 cpu_env,
1328c2bf 8202 offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8203#else
8204 TCGv_i64 tmp = tcg_temp_new_i64();
8205
8206 /* tmp := rA_lo + rA_hi << 32 */
8207 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8208
8209 /* spe_acc := tmp */
1328c2bf 8210 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8211 tcg_temp_free_i64(tmp);
8212
8213 /* rD := rA */
8214 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8215 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8216#endif
8217}
8218
636aa200
BS
8219static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8220{
f78fb44e
AJ
8221#if defined(TARGET_PPC64)
8222 tcg_gen_mov_i64(t, cpu_gpr[reg]);
8223#else
36aa55dc 8224 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
3cd7d1dd 8225#endif
f78fb44e 8226}
3cd7d1dd 8227
636aa200
BS
8228static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8229{
f78fb44e
AJ
8230#if defined(TARGET_PPC64)
8231 tcg_gen_mov_i64(cpu_gpr[reg], t);
8232#else
a7812ae4 8233 TCGv_i64 tmp = tcg_temp_new_i64();
f78fb44e 8234 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
f78fb44e
AJ
8235 tcg_gen_shri_i64(tmp, t, 32);
8236 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
a7812ae4 8237 tcg_temp_free_i64(tmp);
3cd7d1dd 8238#endif
f78fb44e 8239}
3cd7d1dd 8240
70560da7 8241#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 8242static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
8243{ \
8244 if (Rc(ctx->opcode)) \
8245 gen_##name1(ctx); \
8246 else \
8247 gen_##name0(ctx); \
8248}
8249
8250/* Handler for undefined SPE opcodes */
636aa200 8251static inline void gen_speundef(DisasContext *ctx)
0487d6a8 8252{
e06fcd75 8253 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
8254}
8255
57951c27
AJ
8256/* SPE logic */
8257#if defined(TARGET_PPC64)
8258#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8259static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8260{ \
8261 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8262 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8263 return; \
8264 } \
57951c27
AJ
8265 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8266 cpu_gpr[rB(ctx->opcode)]); \
8267}
8268#else
8269#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8270static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8271{ \
8272 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8273 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8274 return; \
8275 } \
8276 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8277 cpu_gpr[rB(ctx->opcode)]); \
8278 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8279 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8280}
57951c27
AJ
8281#endif
8282
8283GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8284GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8285GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8286GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8287GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8288GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8289GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8290GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 8291
57951c27
AJ
8292/* SPE logic immediate */
8293#if defined(TARGET_PPC64)
8294#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8295static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a
AJ
8296{ \
8297 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8298 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
8299 return; \
8300 } \
a7812ae4
PB
8301 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8302 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8303 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8304 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8305 tcg_opi(t0, t0, rB(ctx->opcode)); \
8306 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8307 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8308 tcg_temp_free_i64(t2); \
57951c27
AJ
8309 tcg_opi(t1, t1, rB(ctx->opcode)); \
8310 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8311 tcg_temp_free_i32(t0); \
8312 tcg_temp_free_i32(t1); \
3d3a6a0a 8313}
57951c27
AJ
8314#else
8315#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8316static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8317{ \
8318 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8319 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8320 return; \
8321 } \
57951c27
AJ
8322 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8323 rB(ctx->opcode)); \
8324 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8325 rB(ctx->opcode)); \
0487d6a8 8326}
57951c27
AJ
8327#endif
8328GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8329GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8330GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8331GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 8332
57951c27
AJ
8333/* SPE arithmetic */
8334#if defined(TARGET_PPC64)
8335#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8336static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8337{ \
8338 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8339 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8340 return; \
8341 } \
a7812ae4
PB
8342 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8343 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8344 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8345 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8346 tcg_op(t0, t0); \
8347 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8348 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8349 tcg_temp_free_i64(t2); \
57951c27
AJ
8350 tcg_op(t1, t1); \
8351 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8352 tcg_temp_free_i32(t0); \
8353 tcg_temp_free_i32(t1); \
0487d6a8 8354}
57951c27 8355#else
a7812ae4 8356#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8357static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8358{ \
8359 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8360 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8361 return; \
8362 } \
8363 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8364 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8365}
8366#endif
0487d6a8 8367
636aa200 8368static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27
AJ
8369{
8370 int l1 = gen_new_label();
8371 int l2 = gen_new_label();
0487d6a8 8372
57951c27
AJ
8373 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8374 tcg_gen_neg_i32(ret, arg1);
8375 tcg_gen_br(l2);
8376 gen_set_label(l1);
a7812ae4 8377 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
8378 gen_set_label(l2);
8379}
8380GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8381GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8382GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8383GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 8384static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 8385{
57951c27
AJ
8386 tcg_gen_addi_i32(ret, arg1, 0x8000);
8387 tcg_gen_ext16u_i32(ret, ret);
8388}
8389GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
8390GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8391GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 8392
57951c27
AJ
8393#if defined(TARGET_PPC64)
8394#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8395static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8396{ \
8397 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8398 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8399 return; \
8400 } \
a7812ae4
PB
8401 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8402 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8403 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
501e23c4 8404 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
57951c27
AJ
8405 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8406 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
8407 tcg_op(t0, t0, t2); \
8408 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
8409 tcg_gen_trunc_i64_i32(t1, t3); \
8410 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
8411 tcg_gen_trunc_i64_i32(t2, t3); \
a7812ae4 8412 tcg_temp_free_i64(t3); \
57951c27 8413 tcg_op(t1, t1, t2); \
a7812ae4 8414 tcg_temp_free_i32(t2); \
57951c27 8415 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8416 tcg_temp_free_i32(t0); \
8417 tcg_temp_free_i32(t1); \
0487d6a8 8418}
57951c27
AJ
8419#else
8420#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8421static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8422{ \
8423 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8424 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8425 return; \
8426 } \
57951c27
AJ
8427 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8428 cpu_gpr[rB(ctx->opcode)]); \
8429 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8430 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8431}
57951c27 8432#endif
0487d6a8 8433
636aa200 8434static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8435{
a7812ae4 8436 TCGv_i32 t0;
57951c27 8437 int l1, l2;
0487d6a8 8438
57951c27
AJ
8439 l1 = gen_new_label();
8440 l2 = gen_new_label();
a7812ae4 8441 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8442 /* No error here: 6 bits are used */
8443 tcg_gen_andi_i32(t0, arg2, 0x3F);
8444 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8445 tcg_gen_shr_i32(ret, arg1, t0);
8446 tcg_gen_br(l2);
8447 gen_set_label(l1);
8448 tcg_gen_movi_i32(ret, 0);
0aef4261 8449 gen_set_label(l2);
a7812ae4 8450 tcg_temp_free_i32(t0);
57951c27
AJ
8451}
8452GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 8453static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8454{
a7812ae4 8455 TCGv_i32 t0;
57951c27
AJ
8456 int l1, l2;
8457
8458 l1 = gen_new_label();
8459 l2 = gen_new_label();
a7812ae4 8460 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8461 /* No error here: 6 bits are used */
8462 tcg_gen_andi_i32(t0, arg2, 0x3F);
8463 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8464 tcg_gen_sar_i32(ret, arg1, t0);
8465 tcg_gen_br(l2);
8466 gen_set_label(l1);
8467 tcg_gen_movi_i32(ret, 0);
0aef4261 8468 gen_set_label(l2);
a7812ae4 8469 tcg_temp_free_i32(t0);
57951c27
AJ
8470}
8471GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 8472static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8473{
a7812ae4 8474 TCGv_i32 t0;
57951c27
AJ
8475 int l1, l2;
8476
8477 l1 = gen_new_label();
8478 l2 = gen_new_label();
a7812ae4 8479 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8480 /* No error here: 6 bits are used */
8481 tcg_gen_andi_i32(t0, arg2, 0x3F);
8482 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8483 tcg_gen_shl_i32(ret, arg1, t0);
8484 tcg_gen_br(l2);
8485 gen_set_label(l1);
8486 tcg_gen_movi_i32(ret, 0);
e29ef9fa 8487 gen_set_label(l2);
a7812ae4 8488 tcg_temp_free_i32(t0);
57951c27
AJ
8489}
8490GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 8491static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8492{
a7812ae4 8493 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
8494 tcg_gen_andi_i32(t0, arg2, 0x1F);
8495 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 8496 tcg_temp_free_i32(t0);
57951c27
AJ
8497}
8498GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 8499static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
8500{
8501 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8502 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8503 return;
8504 }
8505#if defined(TARGET_PPC64)
a7812ae4
PB
8506 TCGv t0 = tcg_temp_new();
8507 TCGv t1 = tcg_temp_new();
57951c27
AJ
8508 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8509 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8510 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8511 tcg_temp_free(t0);
8512 tcg_temp_free(t1);
8513#else
8514 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8515 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8516#endif
8517}
8518GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 8519static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 8520{
57951c27
AJ
8521 tcg_gen_sub_i32(ret, arg2, arg1);
8522}
8523GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 8524
57951c27
AJ
8525/* SPE arithmetic immediate */
8526#if defined(TARGET_PPC64)
8527#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8528static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8529{ \
8530 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8531 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8532 return; \
8533 } \
a7812ae4
PB
8534 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8535 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8536 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8537 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8538 tcg_op(t0, t0, rA(ctx->opcode)); \
8539 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8540 tcg_gen_trunc_i64_i32(t1, t2); \
e06fcd75 8541 tcg_temp_free_i64(t2); \
57951c27
AJ
8542 tcg_op(t1, t1, rA(ctx->opcode)); \
8543 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8544 tcg_temp_free_i32(t0); \
8545 tcg_temp_free_i32(t1); \
57951c27
AJ
8546}
8547#else
8548#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8549static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8550{ \
8551 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8552 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8553 return; \
8554 } \
8555 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
8556 rA(ctx->opcode)); \
8557 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
8558 rA(ctx->opcode)); \
8559}
8560#endif
8561GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8562GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8563
8564/* SPE comparison */
8565#if defined(TARGET_PPC64)
8566#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8567static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8568{ \
8569 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8570 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8571 return; \
8572 } \
8573 int l1 = gen_new_label(); \
8574 int l2 = gen_new_label(); \
8575 int l3 = gen_new_label(); \
8576 int l4 = gen_new_label(); \
a7812ae4
PB
8577 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8578 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8579 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8580 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8581 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8582 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
a7812ae4 8583 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8584 tcg_gen_br(l2); \
8585 gen_set_label(l1); \
8586 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8587 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8588 gen_set_label(l2); \
8589 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8590 tcg_gen_trunc_i64_i32(t0, t2); \
8591 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8592 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8593 tcg_temp_free_i64(t2); \
57951c27
AJ
8594 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8595 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8596 ~(CRF_CH | CRF_CH_AND_CL)); \
8597 tcg_gen_br(l4); \
8598 gen_set_label(l3); \
8599 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8600 CRF_CH | CRF_CH_OR_CL); \
8601 gen_set_label(l4); \
a7812ae4
PB
8602 tcg_temp_free_i32(t0); \
8603 tcg_temp_free_i32(t1); \
57951c27
AJ
8604}
8605#else
8606#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8607static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8608{ \
8609 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8610 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8611 return; \
8612 } \
8613 int l1 = gen_new_label(); \
8614 int l2 = gen_new_label(); \
8615 int l3 = gen_new_label(); \
8616 int l4 = gen_new_label(); \
8617 \
8618 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8619 cpu_gpr[rB(ctx->opcode)], l1); \
8620 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8621 tcg_gen_br(l2); \
8622 gen_set_label(l1); \
8623 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8624 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8625 gen_set_label(l2); \
8626 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8627 cpu_gprh[rB(ctx->opcode)], l3); \
8628 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8629 ~(CRF_CH | CRF_CH_AND_CL)); \
8630 tcg_gen_br(l4); \
8631 gen_set_label(l3); \
8632 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8633 CRF_CH | CRF_CH_OR_CL); \
8634 gen_set_label(l4); \
8635}
8636#endif
8637GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8638GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8639GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8640GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8641GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8642
8643/* SPE misc */
636aa200 8644static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8645{
8646 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8647 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8648 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8649}
636aa200 8650static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8651{
8652 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8653 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8654 return;
8655 }
8656#if defined(TARGET_PPC64)
a7812ae4
PB
8657 TCGv t0 = tcg_temp_new();
8658 TCGv t1 = tcg_temp_new();
17d9b3af 8659 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8660 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8661 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8662 tcg_temp_free(t0);
8663 tcg_temp_free(t1);
8664#else
57951c27 8665 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8666 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8667#endif
8668}
636aa200 8669static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8670{
8671 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8672 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8673 return;
8674 }
8675#if defined(TARGET_PPC64)
a7812ae4
PB
8676 TCGv t0 = tcg_temp_new();
8677 TCGv t1 = tcg_temp_new();
17d9b3af 8678 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8679 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8680 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8681 tcg_temp_free(t0);
8682 tcg_temp_free(t1);
8683#else
8684 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8685 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8686#endif
8687}
636aa200 8688static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8689{
8690 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8691 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8692 return;
8693 }
8694#if defined(TARGET_PPC64)
a7812ae4
PB
8695 TCGv t0 = tcg_temp_new();
8696 TCGv t1 = tcg_temp_new();
57951c27
AJ
8697 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8698 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8699 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8700 tcg_temp_free(t0);
8701 tcg_temp_free(t1);
8702#else
33890b3e
NF
8703 if (rD(ctx->opcode) == rA(ctx->opcode)) {
8704 TCGv_i32 tmp = tcg_temp_new_i32();
8705 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
8706 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8707 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
8708 tcg_temp_free_i32(tmp);
8709 } else {
8710 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8711 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8712 }
57951c27
AJ
8713#endif
8714}
636aa200 8715static inline void gen_evsplati(DisasContext *ctx)
57951c27 8716{
ae01847f 8717 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8718
57951c27 8719#if defined(TARGET_PPC64)
38d14952 8720 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8721#else
8722 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8723 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8724#endif
8725}
636aa200 8726static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8727{
ae01847f 8728 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8729
57951c27 8730#if defined(TARGET_PPC64)
38d14952 8731 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8732#else
8733 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8734 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8735#endif
0487d6a8
JM
8736}
8737
636aa200 8738static inline void gen_evsel(DisasContext *ctx)
57951c27
AJ
8739{
8740 int l1 = gen_new_label();
8741 int l2 = gen_new_label();
8742 int l3 = gen_new_label();
8743 int l4 = gen_new_label();
a7812ae4 8744 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8745#if defined(TARGET_PPC64)
a7812ae4
PB
8746 TCGv t1 = tcg_temp_local_new();
8747 TCGv t2 = tcg_temp_local_new();
57951c27
AJ
8748#endif
8749 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8750 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
8751#if defined(TARGET_PPC64)
8752 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8753#else
8754 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8755#endif
8756 tcg_gen_br(l2);
8757 gen_set_label(l1);
8758#if defined(TARGET_PPC64)
8759 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8760#else
8761 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8762#endif
8763 gen_set_label(l2);
8764 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8765 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
8766#if defined(TARGET_PPC64)
17d9b3af 8767 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8768#else
8769 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8770#endif
8771 tcg_gen_br(l4);
8772 gen_set_label(l3);
8773#if defined(TARGET_PPC64)
17d9b3af 8774 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8775#else
8776 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8777#endif
8778 gen_set_label(l4);
a7812ae4 8779 tcg_temp_free_i32(t0);
57951c27
AJ
8780#if defined(TARGET_PPC64)
8781 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
8782 tcg_temp_free(t1);
8783 tcg_temp_free(t2);
8784#endif
8785}
e8eaa2c0
BS
8786
8787static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
8788{
8789 gen_evsel(ctx);
8790}
e8eaa2c0
BS
8791
8792static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
8793{
8794 gen_evsel(ctx);
8795}
e8eaa2c0
BS
8796
8797static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
8798{
8799 gen_evsel(ctx);
8800}
e8eaa2c0
BS
8801
8802static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
8803{
8804 gen_evsel(ctx);
8805}
0487d6a8 8806
a0e13900
FC
8807/* Multiply */
8808
8809static inline void gen_evmwumi(DisasContext *ctx)
8810{
8811 TCGv_i64 t0, t1;
8812
8813 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8814 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8815 return;
8816 }
8817
8818 t0 = tcg_temp_new_i64();
8819 t1 = tcg_temp_new_i64();
8820
8821 /* t0 := rA; t1 := rB */
8822#if defined(TARGET_PPC64)
8823 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8824 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8825#else
8826 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8827 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8828#endif
8829
8830 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8831
8832 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8833
8834 tcg_temp_free_i64(t0);
8835 tcg_temp_free_i64(t1);
8836}
8837
8838static inline void gen_evmwumia(DisasContext *ctx)
8839{
8840 TCGv_i64 tmp;
8841
8842 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8843 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8844 return;
8845 }
8846
8847 gen_evmwumi(ctx); /* rD := rA * rB */
8848
8849 tmp = tcg_temp_new_i64();
8850
8851 /* acc := rD */
8852 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8853 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8854 tcg_temp_free_i64(tmp);
8855}
8856
8857static inline void gen_evmwumiaa(DisasContext *ctx)
8858{
8859 TCGv_i64 acc;
8860 TCGv_i64 tmp;
8861
8862 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8863 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8864 return;
8865 }
8866
8867 gen_evmwumi(ctx); /* rD := rA * rB */
8868
8869 acc = tcg_temp_new_i64();
8870 tmp = tcg_temp_new_i64();
8871
8872 /* tmp := rD */
8873 gen_load_gpr64(tmp, rD(ctx->opcode));
8874
8875 /* Load acc */
1328c2bf 8876 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8877
8878 /* acc := tmp + acc */
8879 tcg_gen_add_i64(acc, acc, tmp);
8880
8881 /* Store acc */
1328c2bf 8882 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8883
8884 /* rD := acc */
8885 gen_store_gpr64(rD(ctx->opcode), acc);
8886
8887 tcg_temp_free_i64(acc);
8888 tcg_temp_free_i64(tmp);
8889}
8890
8891static inline void gen_evmwsmi(DisasContext *ctx)
8892{
8893 TCGv_i64 t0, t1;
8894
8895 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8896 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8897 return;
8898 }
8899
8900 t0 = tcg_temp_new_i64();
8901 t1 = tcg_temp_new_i64();
8902
8903 /* t0 := rA; t1 := rB */
8904#if defined(TARGET_PPC64)
8905 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8906 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8907#else
8908 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8909 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8910#endif
8911
8912 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8913
8914 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8915
8916 tcg_temp_free_i64(t0);
8917 tcg_temp_free_i64(t1);
8918}
8919
8920static inline void gen_evmwsmia(DisasContext *ctx)
8921{
8922 TCGv_i64 tmp;
8923
8924 gen_evmwsmi(ctx); /* rD := rA * rB */
8925
8926 tmp = tcg_temp_new_i64();
8927
8928 /* acc := rD */
8929 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8930 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8931
8932 tcg_temp_free_i64(tmp);
8933}
8934
8935static inline void gen_evmwsmiaa(DisasContext *ctx)
8936{
8937 TCGv_i64 acc = tcg_temp_new_i64();
8938 TCGv_i64 tmp = tcg_temp_new_i64();
8939
8940 gen_evmwsmi(ctx); /* rD := rA * rB */
8941
8942 acc = tcg_temp_new_i64();
8943 tmp = tcg_temp_new_i64();
8944
8945 /* tmp := rD */
8946 gen_load_gpr64(tmp, rD(ctx->opcode));
8947
8948 /* Load acc */
1328c2bf 8949 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8950
8951 /* acc := tmp + acc */
8952 tcg_gen_add_i64(acc, acc, tmp);
8953
8954 /* Store acc */
1328c2bf 8955 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8956
8957 /* rD := acc */
8958 gen_store_gpr64(rD(ctx->opcode), acc);
8959
8960 tcg_temp_free_i64(acc);
8961 tcg_temp_free_i64(tmp);
8962}
8963
70560da7
FC
8964GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8965GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8966GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8967GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8968GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8969GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8970GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8971GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
8972GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
8973GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8974GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8975GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8976GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8977GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8978GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8979GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8980GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8981GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8982GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8983GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
8984GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8985GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8986GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
8987GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
8988GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8989GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8990GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8991GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8992GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 8993
6a6ae23f 8994/* SPE load and stores */
636aa200 8995static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
8996{
8997 target_ulong uimm = rB(ctx->opcode);
8998
76db3ba4 8999 if (rA(ctx->opcode) == 0) {
6a6ae23f 9000 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 9001 } else {
6a6ae23f 9002 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 9003 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
9004 tcg_gen_ext32u_tl(EA, EA);
9005 }
76db3ba4 9006 }
0487d6a8 9007}
6a6ae23f 9008
636aa200 9009static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9010{
9011#if defined(TARGET_PPC64)
76db3ba4 9012 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9013#else
9014 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 9015 gen_qemu_ld64(ctx, t0, addr);
6a6ae23f
AJ
9016 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
9017 tcg_gen_shri_i64(t0, t0, 32);
9018 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
9019 tcg_temp_free_i64(t0);
9020#endif
0487d6a8 9021}
6a6ae23f 9022
636aa200 9023static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 9024{
0487d6a8 9025#if defined(TARGET_PPC64)
6a6ae23f 9026 TCGv t0 = tcg_temp_new();
76db3ba4 9027 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f 9028 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
76db3ba4
AJ
9029 gen_addr_add(ctx, addr, addr, 4);
9030 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
9031 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9032 tcg_temp_free(t0);
9033#else
76db3ba4
AJ
9034 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9035 gen_addr_add(ctx, addr, addr, 4);
9036 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f 9037#endif
0487d6a8 9038}
6a6ae23f 9039
636aa200 9040static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9041{
9042 TCGv t0 = tcg_temp_new();
9043#if defined(TARGET_PPC64)
76db3ba4 9044 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9045 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
9046 gen_addr_add(ctx, addr, addr, 2);
9047 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9048 tcg_gen_shli_tl(t0, t0, 32);
9049 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9050 gen_addr_add(ctx, addr, addr, 2);
9051 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9052 tcg_gen_shli_tl(t0, t0, 16);
9053 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9054 gen_addr_add(ctx, addr, addr, 2);
9055 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9056 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 9057#else
76db3ba4 9058 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9059 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9060 gen_addr_add(ctx, addr, addr, 2);
9061 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9062 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9063 gen_addr_add(ctx, addr, addr, 2);
9064 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9065 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9066 gen_addr_add(ctx, addr, addr, 2);
9067 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9068 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 9069#endif
6a6ae23f 9070 tcg_temp_free(t0);
0487d6a8
JM
9071}
9072
636aa200 9073static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9074{
9075 TCGv t0 = tcg_temp_new();
76db3ba4 9076 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9077#if defined(TARGET_PPC64)
9078 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9079 tcg_gen_shli_tl(t0, t0, 16);
9080 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9081#else
9082 tcg_gen_shli_tl(t0, t0, 16);
9083 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9084 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9085#endif
9086 tcg_temp_free(t0);
0487d6a8
JM
9087}
9088
636aa200 9089static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9090{
9091 TCGv t0 = tcg_temp_new();
76db3ba4 9092 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9093#if defined(TARGET_PPC64)
9094 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9095 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9096#else
9097 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9098 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9099#endif
9100 tcg_temp_free(t0);
0487d6a8
JM
9101}
9102
636aa200 9103static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9104{
9105 TCGv t0 = tcg_temp_new();
76db3ba4 9106 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9107#if defined(TARGET_PPC64)
9108 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9109 tcg_gen_ext32u_tl(t0, t0);
9110 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9111#else
9112 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9113 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9114#endif
9115 tcg_temp_free(t0);
9116}
9117
636aa200 9118static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9119{
9120 TCGv t0 = tcg_temp_new();
9121#if defined(TARGET_PPC64)
76db3ba4 9122 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9123 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
9124 gen_addr_add(ctx, addr, addr, 2);
9125 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9126 tcg_gen_shli_tl(t0, t0, 16);
9127 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9128#else
76db3ba4 9129 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9130 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9131 gen_addr_add(ctx, addr, addr, 2);
9132 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9133 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9134#endif
9135 tcg_temp_free(t0);
9136}
9137
636aa200 9138static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9139{
9140#if defined(TARGET_PPC64)
9141 TCGv t0 = tcg_temp_new();
76db3ba4
AJ
9142 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
9143 gen_addr_add(ctx, addr, addr, 2);
9144 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9145 tcg_gen_shli_tl(t0, t0, 32);
9146 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9147 tcg_temp_free(t0);
9148#else
76db3ba4
AJ
9149 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9150 gen_addr_add(ctx, addr, addr, 2);
9151 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9152#endif
9153}
9154
636aa200 9155static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9156{
9157#if defined(TARGET_PPC64)
9158 TCGv t0 = tcg_temp_new();
76db3ba4 9159 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f 9160 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9161 gen_addr_add(ctx, addr, addr, 2);
9162 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9163 tcg_gen_shli_tl(t0, t0, 32);
9164 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9165 tcg_temp_free(t0);
9166#else
76db3ba4
AJ
9167 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9168 gen_addr_add(ctx, addr, addr, 2);
9169 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9170#endif
9171}
9172
636aa200 9173static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9174{
9175 TCGv t0 = tcg_temp_new();
76db3ba4 9176 gen_qemu_ld32u(ctx, t0, addr);
0487d6a8 9177#if defined(TARGET_PPC64)
6a6ae23f
AJ
9178 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
9179 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9180#else
9181 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9182 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
9183#endif
9184 tcg_temp_free(t0);
9185}
9186
636aa200 9187static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9188{
9189 TCGv t0 = tcg_temp_new();
9190#if defined(TARGET_PPC64)
76db3ba4 9191 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9192 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
9193 tcg_gen_shli_tl(t0, t0, 32);
9194 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
9195 gen_addr_add(ctx, addr, addr, 2);
9196 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9197 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9198 tcg_gen_shli_tl(t0, t0, 16);
9199 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
9200#else
76db3ba4 9201 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9202 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9203 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9204 gen_addr_add(ctx, addr, addr, 2);
9205 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9206 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9207 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
0487d6a8 9208#endif
6a6ae23f
AJ
9209 tcg_temp_free(t0);
9210}
9211
636aa200 9212static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9213{
9214#if defined(TARGET_PPC64)
76db3ba4 9215 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
0487d6a8 9216#else
6a6ae23f
AJ
9217 TCGv_i64 t0 = tcg_temp_new_i64();
9218 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
76db3ba4 9219 gen_qemu_st64(ctx, t0, addr);
6a6ae23f
AJ
9220 tcg_temp_free_i64(t0);
9221#endif
9222}
9223
636aa200 9224static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 9225{
0487d6a8 9226#if defined(TARGET_PPC64)
6a6ae23f
AJ
9227 TCGv t0 = tcg_temp_new();
9228 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9229 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
9230 tcg_temp_free(t0);
9231#else
76db3ba4 9232 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9233#endif
76db3ba4
AJ
9234 gen_addr_add(ctx, addr, addr, 4);
9235 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9236}
9237
636aa200 9238static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9239{
9240 TCGv t0 = tcg_temp_new();
9241#if defined(TARGET_PPC64)
9242 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
9243#else
9244 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9245#endif
76db3ba4
AJ
9246 gen_qemu_st16(ctx, t0, addr);
9247 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f
AJ
9248#if defined(TARGET_PPC64)
9249 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9250 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9251#else
76db3ba4 9252 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9253#endif
76db3ba4 9254 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9255 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9256 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9257 tcg_temp_free(t0);
76db3ba4
AJ
9258 gen_addr_add(ctx, addr, addr, 2);
9259 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9260}
9261
636aa200 9262static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9263{
9264 TCGv t0 = tcg_temp_new();
9265#if defined(TARGET_PPC64)
9266 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
9267#else
9268 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
9269#endif
76db3ba4
AJ
9270 gen_qemu_st16(ctx, t0, addr);
9271 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9272 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9273 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9274 tcg_temp_free(t0);
9275}
9276
636aa200 9277static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9278{
9279#if defined(TARGET_PPC64)
9280 TCGv t0 = tcg_temp_new();
9281 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9282 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9283 tcg_temp_free(t0);
9284#else
76db3ba4 9285 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 9286#endif
76db3ba4
AJ
9287 gen_addr_add(ctx, addr, addr, 2);
9288 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9289}
9290
636aa200 9291static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9292{
9293#if defined(TARGET_PPC64)
9294 TCGv t0 = tcg_temp_new();
9295 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 9296 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
9297 tcg_temp_free(t0);
9298#else
76db3ba4 9299 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9300#endif
9301}
9302
636aa200 9303static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 9304{
76db3ba4 9305 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9306}
9307
9308#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 9309static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
9310{ \
9311 TCGv t0; \
9312 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9313 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
9314 return; \
9315 } \
76db3ba4 9316 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
9317 t0 = tcg_temp_new(); \
9318 if (Rc(ctx->opcode)) { \
76db3ba4 9319 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 9320 } else { \
76db3ba4 9321 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
9322 } \
9323 gen_op_##name(ctx, t0); \
9324 tcg_temp_free(t0); \
9325}
9326
9327GEN_SPEOP_LDST(evldd, 0x00, 3);
9328GEN_SPEOP_LDST(evldw, 0x01, 3);
9329GEN_SPEOP_LDST(evldh, 0x02, 3);
9330GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9331GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9332GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9333GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9334GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9335GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9336GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9337GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9338
9339GEN_SPEOP_LDST(evstdd, 0x10, 3);
9340GEN_SPEOP_LDST(evstdw, 0x11, 3);
9341GEN_SPEOP_LDST(evstdh, 0x12, 3);
9342GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9343GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9344GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9345GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
9346
9347/* Multiply and add - TODO */
9348#if 0
70560da7
FC
9349GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9350GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9351GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9352GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9353GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9354GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9355GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9356GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9357GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9358GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9359GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9360GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9361
9362GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9363GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9364GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9365GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9366GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9367GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9368GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9369GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9370GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9371GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9372GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9373GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9374
9375GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9376GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9377GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9378GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9379GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9380
9381GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9382GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9383GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9384GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9385GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9386GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9387GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9388GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9389GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9390GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9391GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9392GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9393
9394GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9395GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9396GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9397GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9398
9399GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9400GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9401GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9402GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9403GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9404GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9405GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9406GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9407GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9408GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9409GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9410GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9411
9412GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9413GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9414GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9415GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9416GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
9417#endif
9418
9419/*** SPE floating-point extension ***/
1c97856d
AJ
9420#if defined(TARGET_PPC64)
9421#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9422static inline void gen_##name(DisasContext *ctx) \
0487d6a8 9423{ \
1c97856d
AJ
9424 TCGv_i32 t0; \
9425 TCGv t1; \
9426 t0 = tcg_temp_new_i32(); \
9427 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9428 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9429 t1 = tcg_temp_new(); \
9430 tcg_gen_extu_i32_tl(t1, t0); \
9431 tcg_temp_free_i32(t0); \
9432 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9433 0xFFFFFFFF00000000ULL); \
9434 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9435 tcg_temp_free(t1); \
0487d6a8 9436}
1c97856d 9437#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9438static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9439{ \
9440 TCGv_i32 t0; \
9441 TCGv t1; \
9442 t0 = tcg_temp_new_i32(); \
8e703949 9443 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9444 t1 = tcg_temp_new(); \
9445 tcg_gen_extu_i32_tl(t1, t0); \
9446 tcg_temp_free_i32(t0); \
9447 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9448 0xFFFFFFFF00000000ULL); \
9449 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9450 tcg_temp_free(t1); \
9451}
9452#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9453static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9454{ \
9455 TCGv_i32 t0 = tcg_temp_new_i32(); \
9456 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9457 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9458 tcg_temp_free_i32(t0); \
9459}
9460#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9461static inline void gen_##name(DisasContext *ctx) \
1c97856d 9462{ \
8e703949
BS
9463 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9464 cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9465}
9466#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9467static inline void gen_##name(DisasContext *ctx) \
57951c27 9468{ \
1c97856d
AJ
9469 TCGv_i32 t0, t1; \
9470 TCGv_i64 t2; \
57951c27 9471 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9472 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9473 return; \
9474 } \
1c97856d
AJ
9475 t0 = tcg_temp_new_i32(); \
9476 t1 = tcg_temp_new_i32(); \
9477 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9478 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9479 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9480 tcg_temp_free_i32(t1); \
9481 t2 = tcg_temp_new(); \
9482 tcg_gen_extu_i32_tl(t2, t0); \
9483 tcg_temp_free_i32(t0); \
9484 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9485 0xFFFFFFFF00000000ULL); \
9486 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
9487 tcg_temp_free(t2); \
57951c27 9488}
1c97856d 9489#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9490static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
9491{ \
9492 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9493 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9494 return; \
9495 } \
8e703949
BS
9496 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9497 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
57951c27 9498}
1c97856d 9499#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9500static inline void gen_##name(DisasContext *ctx) \
57951c27 9501{ \
1c97856d 9502 TCGv_i32 t0, t1; \
57951c27 9503 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9504 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9505 return; \
9506 } \
1c97856d
AJ
9507 t0 = tcg_temp_new_i32(); \
9508 t1 = tcg_temp_new_i32(); \
9509 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9510 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9511 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9512 tcg_temp_free_i32(t0); \
9513 tcg_temp_free_i32(t1); \
9514}
9515#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9516static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9517{ \
9518 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9519 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9520 return; \
9521 } \
8e703949 9522 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9523 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9524}
9525#else
9526#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9527static inline void gen_##name(DisasContext *ctx) \
1c97856d 9528{ \
8e703949
BS
9529 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9530 cpu_gpr[rB(ctx->opcode)]); \
57951c27 9531}
1c97856d 9532#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9533static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9534{ \
9535 TCGv_i64 t0 = tcg_temp_new_i64(); \
9536 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9537 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9538 tcg_temp_free_i64(t0); \
9539}
9540#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9541static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9542{ \
9543 TCGv_i64 t0 = tcg_temp_new_i64(); \
8e703949 9544 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9545 gen_store_gpr64(rD(ctx->opcode), t0); \
9546 tcg_temp_free_i64(t0); \
9547}
9548#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9549static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9550{ \
9551 TCGv_i64 t0 = tcg_temp_new_i64(); \
9552 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9553 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9554 gen_store_gpr64(rD(ctx->opcode), t0); \
9555 tcg_temp_free_i64(t0); \
9556}
9557#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9558static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9559{ \
9560 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9561 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9562 return; \
9563 } \
8e703949 9564 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9565 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9566}
9567#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9568static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9569{ \
9570 TCGv_i64 t0, t1; \
9571 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9572 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9573 return; \
9574 } \
9575 t0 = tcg_temp_new_i64(); \
9576 t1 = tcg_temp_new_i64(); \
9577 gen_load_gpr64(t0, rA(ctx->opcode)); \
9578 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9579 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9580 gen_store_gpr64(rD(ctx->opcode), t0); \
9581 tcg_temp_free_i64(t0); \
9582 tcg_temp_free_i64(t1); \
9583}
9584#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9585static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9586{ \
9587 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9588 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9589 return; \
9590 } \
8e703949 9591 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9592 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9593}
9594#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9595static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9596{ \
9597 TCGv_i64 t0, t1; \
9598 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9599 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9600 return; \
9601 } \
9602 t0 = tcg_temp_new_i64(); \
9603 t1 = tcg_temp_new_i64(); \
9604 gen_load_gpr64(t0, rA(ctx->opcode)); \
9605 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9606 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9607 tcg_temp_free_i64(t0); \
9608 tcg_temp_free_i64(t1); \
9609}
9610#endif
57951c27 9611
0487d6a8
JM
9612/* Single precision floating-point vectors operations */
9613/* Arithmetic */
1c97856d
AJ
9614GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9615GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9616GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9617GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9618static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9619{
9620 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9621 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9622 return;
9623 }
9624#if defined(TARGET_PPC64)
6d5c34fa 9625 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
1c97856d 9626#else
6d5c34fa
MP
9627 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
9628 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9629#endif
9630}
636aa200 9631static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9632{
9633 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9634 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9635 return;
9636 }
9637#if defined(TARGET_PPC64)
6d5c34fa 9638 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9639#else
6d5c34fa
MP
9640 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9641 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9642#endif
9643}
636aa200 9644static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9645{
9646 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9647 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9648 return;
9649 }
9650#if defined(TARGET_PPC64)
6d5c34fa 9651 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9652#else
6d5c34fa
MP
9653 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9654 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9655#endif
9656}
9657
0487d6a8 9658/* Conversion */
1c97856d
AJ
9659GEN_SPEFPUOP_CONV_64_64(evfscfui);
9660GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9661GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9662GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9663GEN_SPEFPUOP_CONV_64_64(evfsctui);
9664GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9665GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9666GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9667GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9668GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9669
0487d6a8 9670/* Comparison */
1c97856d
AJ
9671GEN_SPEFPUOP_COMP_64(evfscmpgt);
9672GEN_SPEFPUOP_COMP_64(evfscmplt);
9673GEN_SPEFPUOP_COMP_64(evfscmpeq);
9674GEN_SPEFPUOP_COMP_64(evfststgt);
9675GEN_SPEFPUOP_COMP_64(evfststlt);
9676GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9677
9678/* Opcodes definitions */
70560da7
FC
9679GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9680GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9681GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9682GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9683GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9684GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9685GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9686GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9687GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9688GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9689GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9690GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9691GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9692GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9693
9694/* Single precision floating-point operations */
9695/* Arithmetic */
1c97856d
AJ
9696GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9697GEN_SPEFPUOP_ARITH2_32_32(efssub);
9698GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9699GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9700static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9701{
9702 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9703 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9704 return;
9705 }
6d5c34fa 9706 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9707}
636aa200 9708static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9709{
9710 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9711 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9712 return;
9713 }
6d5c34fa 9714 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9715}
636aa200 9716static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9717{
9718 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9719 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9720 return;
9721 }
6d5c34fa 9722 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9723}
9724
0487d6a8 9725/* Conversion */
1c97856d
AJ
9726GEN_SPEFPUOP_CONV_32_32(efscfui);
9727GEN_SPEFPUOP_CONV_32_32(efscfsi);
9728GEN_SPEFPUOP_CONV_32_32(efscfuf);
9729GEN_SPEFPUOP_CONV_32_32(efscfsf);
9730GEN_SPEFPUOP_CONV_32_32(efsctui);
9731GEN_SPEFPUOP_CONV_32_32(efsctsi);
9732GEN_SPEFPUOP_CONV_32_32(efsctuf);
9733GEN_SPEFPUOP_CONV_32_32(efsctsf);
9734GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9735GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9736GEN_SPEFPUOP_CONV_32_64(efscfd);
9737
0487d6a8 9738/* Comparison */
1c97856d
AJ
9739GEN_SPEFPUOP_COMP_32(efscmpgt);
9740GEN_SPEFPUOP_COMP_32(efscmplt);
9741GEN_SPEFPUOP_COMP_32(efscmpeq);
9742GEN_SPEFPUOP_COMP_32(efststgt);
9743GEN_SPEFPUOP_COMP_32(efststlt);
9744GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9745
9746/* Opcodes definitions */
70560da7
FC
9747GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9748GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9749GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9750GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9751GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9752GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9753GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9754GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9755GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9756GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9757GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9758GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9759GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9760GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9761
9762/* Double precision floating-point operations */
9763/* Arithmetic */
1c97856d
AJ
9764GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9765GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9766GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9767GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9768static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9769{
9770 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9771 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9772 return;
9773 }
9774#if defined(TARGET_PPC64)
6d5c34fa 9775 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
1c97856d 9776#else
6d5c34fa
MP
9777 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9778 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9779#endif
9780}
636aa200 9781static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
9782{
9783 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9784 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9785 return;
9786 }
9787#if defined(TARGET_PPC64)
6d5c34fa 9788 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9789#else
6d5c34fa
MP
9790 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9791 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9792#endif
9793}
636aa200 9794static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
9795{
9796 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9797 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9798 return;
9799 }
9800#if defined(TARGET_PPC64)
6d5c34fa 9801 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9802#else
6d5c34fa
MP
9803 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9804 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9805#endif
9806}
9807
0487d6a8 9808/* Conversion */
1c97856d
AJ
9809GEN_SPEFPUOP_CONV_64_32(efdcfui);
9810GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9811GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9812GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9813GEN_SPEFPUOP_CONV_32_64(efdctui);
9814GEN_SPEFPUOP_CONV_32_64(efdctsi);
9815GEN_SPEFPUOP_CONV_32_64(efdctuf);
9816GEN_SPEFPUOP_CONV_32_64(efdctsf);
9817GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9818GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9819GEN_SPEFPUOP_CONV_64_32(efdcfs);
9820GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9821GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9822GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9823GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 9824
0487d6a8 9825/* Comparison */
1c97856d
AJ
9826GEN_SPEFPUOP_COMP_64(efdcmpgt);
9827GEN_SPEFPUOP_COMP_64(efdcmplt);
9828GEN_SPEFPUOP_COMP_64(efdcmpeq);
9829GEN_SPEFPUOP_COMP_64(efdtstgt);
9830GEN_SPEFPUOP_COMP_64(efdtstlt);
9831GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
9832
9833/* Opcodes definitions */
70560da7
FC
9834GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9835GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9836GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9837GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9838GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9839GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9840GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9841GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9842GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9843GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9844GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9845GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9846GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9847GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9848GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9849GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 9850
c227f099 9851static opcode_t opcodes[] = {
5c55ff99
BS
9852GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9853GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9854GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9855GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9856GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 9857GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9858GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9859GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9860GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9861GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9862GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9863GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9864GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9865GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9866GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9867GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9868#if defined(TARGET_PPC64)
9869GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9870#endif
9871GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9872GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9873GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9874GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9875GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9876GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9877GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9878GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9879GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9880GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9881GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9882GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9883GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 9884GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 9885GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 9886#if defined(TARGET_PPC64)
eaabeef2 9887GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 9888GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 9889GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
86ba37ed 9890GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
5c55ff99
BS
9891#endif
9892GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9893GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9894GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9895GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9896GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9897GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9898GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9899#if defined(TARGET_PPC64)
9900GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9901GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9902GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9903GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9904GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9905#endif
9906GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9907GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9908GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9909GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9910GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 9911GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 9912GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
9913GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9914GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 9915GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
097ec5d8
TM
9916GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
9917GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
5c55ff99
BS
9918GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9919GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9920GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9921GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
9922GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9923GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
9924#if defined(TARGET_PPC64)
9925GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9926GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9927GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9928#endif
9929GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9930GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9931GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9932GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9933GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9934GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9935GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9936GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
5c77a786
TM
9937GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9938GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
f844c817 9939GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
587c51f7
TM
9940GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9941GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
5c55ff99
BS
9942GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9943#if defined(TARGET_PPC64)
f844c817 9944GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
9c294d5a 9945GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99 9946GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
27b95bfe 9947GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99
BS
9948#endif
9949GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9950GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9951GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9952GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9953GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9954GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
52a4984d 9955GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
5c55ff99
BS
9956GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9957GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9958#if defined(TARGET_PPC64)
9959GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9960GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9961#endif
9962GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9963GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9964GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9965#if defined(TARGET_PPC64)
9966GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9967GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9968#endif
9969GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9970GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9971GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9972GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9973GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9974GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9975#if defined(TARGET_PPC64)
9976GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9977#endif
9978GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
9979GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
9980GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9981GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9982GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
3f34cf91
CLG
9983GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
9984GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
8e33944f 9985GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
9986GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9987GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9988GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9989GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9990GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9991GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9992GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9993GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9994GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9995#if defined(TARGET_PPC64)
9996GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9997GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9998 PPC_SEGMENT_64B),
9999GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
10000GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
10001 PPC_SEGMENT_64B),
efdef95f
DG
10002GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
10003GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
10004GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
10005#endif
10006GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
10007GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
10008GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
10009GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
10010#if defined(TARGET_PPC64)
10011GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
10012GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
10013#endif
10014GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
10015GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
10016GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
10017GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
10018GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
10019GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
10020GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
10021GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
10022GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
10023GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
10024GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
10025GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10026GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
10027GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
10028GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
10029GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
10030GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
10031GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
10032GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
10033GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
10034GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
10035GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
10036GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
10037GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
10038GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
10039GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
10040GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
10041GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
10042GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
10043GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
10044GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
10045GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
10046GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
10047GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
10048GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
10049GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
10050GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
10051GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
10052GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
10053GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
10054GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
10055GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
10056GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
10057GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
10058GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
10059GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
10060GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
10061GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
10062GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
10063GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10064GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10065GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
10066GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
10067GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10068GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10069GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
10070GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
10071GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
10072GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
10073GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
10074GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
10075GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
10076GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
10077GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
10078GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
10079GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
10080GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
10081GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
10082GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
10083GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
10084GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 10085GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10086GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
10087GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
10088GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
10089GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
10090GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
10091GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
10092GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
10093GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
10094GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10095 PPC_NONE, PPC2_BOOKE206),
10096GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10097 PPC_NONE, PPC2_BOOKE206),
10098GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10099 PPC_NONE, PPC2_BOOKE206),
10100GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10101 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
10102GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10103 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
10104GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10105 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
10106GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10107 PPC_NONE, PPC2_PRCNTL),
5c55ff99 10108GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 10109GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 10110GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
10111GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
10112 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 10113GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
10114GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10115 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10116GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
10117GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
10118GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
10119GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
5c55ff99
BS
10120GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
10121GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
10122GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
10123GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
10124GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
10125
10126#undef GEN_INT_ARITH_ADD
10127#undef GEN_INT_ARITH_ADD_CONST
10128#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10129GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10130#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10131 add_ca, compute_ca, compute_ov) \
10132GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10133GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
10134GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
10135GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
10136GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
10137GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
10138GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
10139GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
10140GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
10141GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
10142GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
10143
10144#undef GEN_INT_ARITH_DIVW
10145#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10146GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10147GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
10148GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
10149GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
10150GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
a98eb9e9
TM
10151GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10152GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
6a4fda33
TM
10153GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10154GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
5c55ff99
BS
10155
10156#if defined(TARGET_PPC64)
10157#undef GEN_INT_ARITH_DIVD
10158#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10159GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10160GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
10161GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
10162GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
10163GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
10164
98d1eb27
TM
10165GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10166GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
e44259b6
TM
10167GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10168GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
98d1eb27 10169
5c55ff99
BS
10170#undef GEN_INT_ARITH_MUL_HELPER
10171#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10172GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10173GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
10174GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
10175GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
10176#endif
10177
10178#undef GEN_INT_ARITH_SUBF
10179#undef GEN_INT_ARITH_SUBF_CONST
10180#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10181GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10182#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10183 add_ca, compute_ca, compute_ov) \
10184GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10185GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
10186GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
10187GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
10188GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
10189GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
10190GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
10191GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
10192GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
10193GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
10194GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
10195
10196#undef GEN_LOGICAL1
10197#undef GEN_LOGICAL2
10198#define GEN_LOGICAL2(name, tcg_op, opc, type) \
10199GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10200#define GEN_LOGICAL1(name, tcg_op, opc, type) \
10201GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10202GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10203GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10204GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10205GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10206GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10207GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10208GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10209GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10210#if defined(TARGET_PPC64)
10211GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10212#endif
10213
10214#if defined(TARGET_PPC64)
10215#undef GEN_PPC64_R2
10216#undef GEN_PPC64_R4
10217#define GEN_PPC64_R2(name, opc1, opc2) \
10218GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10219GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10220 PPC_64B)
10221#define GEN_PPC64_R4(name, opc1, opc2) \
10222GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10223GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10224 PPC_64B), \
10225GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10226 PPC_64B), \
10227GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10228 PPC_64B)
10229GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10230GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10231GEN_PPC64_R4(rldic, 0x1E, 0x04),
10232GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10233GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10234GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10235#endif
10236
10237#undef _GEN_FLOAT_ACB
10238#undef GEN_FLOAT_ACB
10239#undef _GEN_FLOAT_AB
10240#undef GEN_FLOAT_AB
10241#undef _GEN_FLOAT_AC
10242#undef GEN_FLOAT_AC
10243#undef GEN_FLOAT_B
10244#undef GEN_FLOAT_BS
10245#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10246GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10247#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10248_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10249_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10250#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10251GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10252#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10253_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10254_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10255#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10256GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10257#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10258_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10259_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10260#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10261GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10262#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10263GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10264
10265GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10266GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10267GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10268GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10269GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10270GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10271_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10272GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10273GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10274GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10275GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10276GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
da29cb7b 10277GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
6d41d146 10278GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
5c55ff99 10279GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
fab7fe42 10280GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10281GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
fab7fe42 10282GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10283GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
10284#if defined(TARGET_PPC64)
10285GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
28288b48
TM
10286GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10287GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10288GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10289GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
fab7fe42 10290GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10291GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
fab7fe42 10292GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10293#endif
10294GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10295GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10296GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10297GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
10298
10299#undef GEN_LD
10300#undef GEN_LDU
10301#undef GEN_LDUX
cd6e9320 10302#undef GEN_LDX_E
5c55ff99
BS
10303#undef GEN_LDS
10304#define GEN_LD(name, ldop, opc, type) \
10305GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10306#define GEN_LDU(name, ldop, opc, type) \
10307GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10308#define GEN_LDUX(name, ldop, opc2, opc3, type) \
10309GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10310#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10311GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10312#define GEN_LDS(name, ldop, op, type) \
10313GEN_LD(name, ldop, op | 0x20, type) \
10314GEN_LDU(name, ldop, op | 0x21, type) \
10315GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10316GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10317
10318GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10319GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10320GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10321GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10322#if defined(TARGET_PPC64)
10323GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10324GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10325GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10326GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 10327GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10328#endif
10329GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10330GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10331
10332#undef GEN_ST
10333#undef GEN_STU
10334#undef GEN_STUX
cd6e9320 10335#undef GEN_STX_E
5c55ff99
BS
10336#undef GEN_STS
10337#define GEN_ST(name, stop, opc, type) \
10338GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10339#define GEN_STU(name, stop, opc, type) \
10340GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10341#define GEN_STUX(name, stop, opc2, opc3, type) \
10342GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10343#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10344GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10345#define GEN_STS(name, stop, op, type) \
10346GEN_ST(name, stop, op | 0x20, type) \
10347GEN_STU(name, stop, op | 0x21, type) \
10348GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10349GEN_STX(name, stop, 0x17, op | 0x00, type)
10350
10351GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10352GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10353GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10354#if defined(TARGET_PPC64)
10355GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10356GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 10357GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10358#endif
10359GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10360GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10361
10362#undef GEN_LDF
10363#undef GEN_LDUF
10364#undef GEN_LDUXF
10365#undef GEN_LDXF
10366#undef GEN_LDFS
10367#define GEN_LDF(name, ldop, opc, type) \
10368GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10369#define GEN_LDUF(name, ldop, opc, type) \
10370GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10371#define GEN_LDUXF(name, ldop, opc, type) \
10372GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10373#define GEN_LDXF(name, ldop, opc2, opc3, type) \
10374GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10375#define GEN_LDFS(name, ldop, op, type) \
10376GEN_LDF(name, ldop, op | 0x20, type) \
10377GEN_LDUF(name, ldop, op | 0x21, type) \
10378GEN_LDUXF(name, ldop, op | 0x01, type) \
10379GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10380
10381GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10382GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 10383GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
66c3e328 10384GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
05050ee8
AJ
10385GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10386GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10387
10388#undef GEN_STF
10389#undef GEN_STUF
10390#undef GEN_STUXF
10391#undef GEN_STXF
10392#undef GEN_STFS
10393#define GEN_STF(name, stop, opc, type) \
10394GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10395#define GEN_STUF(name, stop, opc, type) \
10396GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10397#define GEN_STUXF(name, stop, opc, type) \
10398GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10399#define GEN_STXF(name, stop, opc2, opc3, type) \
10400GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10401#define GEN_STFS(name, stop, op, type) \
10402GEN_STF(name, stop, op | 0x20, type) \
10403GEN_STUF(name, stop, op | 0x21, type) \
10404GEN_STUXF(name, stop, op | 0x01, type) \
10405GEN_STXF(name, stop, 0x17, op | 0x00, type)
10406
10407GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10408GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10409GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
10410GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10411GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10412
10413#undef GEN_CRLOGIC
10414#define GEN_CRLOGIC(name, tcg_op, opc) \
10415GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10416GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10417GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10418GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10419GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10420GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10421GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10422GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10423GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10424
10425#undef GEN_MAC_HANDLER
10426#define GEN_MAC_HANDLER(name, opc2, opc3) \
10427GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10428GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10429GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10430GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10431GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10432GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10433GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10434GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10435GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10436GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10437GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10438GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10439GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10440GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10441GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10442GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10443GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10444GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10445GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10446GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10447GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10448GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10449GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10450GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10451GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10452GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10453GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10454GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10455GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10456GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10457GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10458GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10459GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10460GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10461GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10462GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10463GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10464GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10465GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10466GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10467GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10468GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10469GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10470
10471#undef GEN_VR_LDX
10472#undef GEN_VR_STX
10473#undef GEN_VR_LVE
10474#undef GEN_VR_STVE
10475#define GEN_VR_LDX(name, opc2, opc3) \
10476GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10477#define GEN_VR_STX(name, opc2, opc3) \
10478GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10479#define GEN_VR_LVE(name, opc2, opc3) \
10480 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10481#define GEN_VR_STVE(name, opc2, opc3) \
10482 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10483GEN_VR_LDX(lvx, 0x07, 0x03),
10484GEN_VR_LDX(lvxl, 0x07, 0x0B),
10485GEN_VR_LVE(bx, 0x07, 0x00),
10486GEN_VR_LVE(hx, 0x07, 0x01),
10487GEN_VR_LVE(wx, 0x07, 0x02),
10488GEN_VR_STX(svx, 0x07, 0x07),
10489GEN_VR_STX(svxl, 0x07, 0x0F),
10490GEN_VR_STVE(bx, 0x07, 0x04),
10491GEN_VR_STVE(hx, 0x07, 0x05),
10492GEN_VR_STVE(wx, 0x07, 0x06),
10493
10494#undef GEN_VX_LOGICAL
10495#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10496GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
111c5f54
TM
10497
10498#undef GEN_VX_LOGICAL_207
10499#define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10500GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10501
5c55ff99
BS
10502GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10503GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10504GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10505GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10506GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
111c5f54
TM
10507GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10508GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10509GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
5c55ff99
BS
10510
10511#undef GEN_VXFORM
10512#define GEN_VXFORM(name, opc2, opc3) \
10513GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
50f5fc0c
TM
10514
10515#undef GEN_VXFORM_207
10516#define GEN_VXFORM_207(name, opc2, opc3) \
10517GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10518
5dffff5a
TM
10519#undef GEN_VXFORM_DUAL
10520#define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10521GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10522
a737d3eb
TM
10523#undef GEN_VXRFORM_DUAL
10524#define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10525GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10526GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10527
5c55ff99
BS
10528GEN_VXFORM(vaddubm, 0, 0),
10529GEN_VXFORM(vadduhm, 0, 1),
10530GEN_VXFORM(vadduwm, 0, 2),
56eabc75 10531GEN_VXFORM_207(vaddudm, 0, 3),
e8f7b27b
TM
10532GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10533GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
5c55ff99 10534GEN_VXFORM(vsubuwm, 0, 18),
56eabc75 10535GEN_VXFORM_207(vsubudm, 0, 19),
5c55ff99
BS
10536GEN_VXFORM(vmaxub, 1, 0),
10537GEN_VXFORM(vmaxuh, 1, 1),
10538GEN_VXFORM(vmaxuw, 1, 2),
8203e31b 10539GEN_VXFORM_207(vmaxud, 1, 3),
5c55ff99
BS
10540GEN_VXFORM(vmaxsb, 1, 4),
10541GEN_VXFORM(vmaxsh, 1, 5),
10542GEN_VXFORM(vmaxsw, 1, 6),
8203e31b 10543GEN_VXFORM_207(vmaxsd, 1, 7),
5c55ff99
BS
10544GEN_VXFORM(vminub, 1, 8),
10545GEN_VXFORM(vminuh, 1, 9),
10546GEN_VXFORM(vminuw, 1, 10),
8203e31b 10547GEN_VXFORM_207(vminud, 1, 11),
5c55ff99
BS
10548GEN_VXFORM(vminsb, 1, 12),
10549GEN_VXFORM(vminsh, 1, 13),
10550GEN_VXFORM(vminsw, 1, 14),
8203e31b 10551GEN_VXFORM_207(vminsd, 1, 15),
5c55ff99
BS
10552GEN_VXFORM(vavgub, 1, 16),
10553GEN_VXFORM(vavguh, 1, 17),
10554GEN_VXFORM(vavguw, 1, 18),
10555GEN_VXFORM(vavgsb, 1, 20),
10556GEN_VXFORM(vavgsh, 1, 21),
10557GEN_VXFORM(vavgsw, 1, 22),
10558GEN_VXFORM(vmrghb, 6, 0),
10559GEN_VXFORM(vmrghh, 6, 1),
10560GEN_VXFORM(vmrghw, 6, 2),
10561GEN_VXFORM(vmrglb, 6, 4),
10562GEN_VXFORM(vmrglh, 6, 5),
10563GEN_VXFORM(vmrglw, 6, 6),
e0ffe77f
TM
10564GEN_VXFORM_207(vmrgew, 6, 30),
10565GEN_VXFORM_207(vmrgow, 6, 26),
5c55ff99
BS
10566GEN_VXFORM(vmuloub, 4, 0),
10567GEN_VXFORM(vmulouh, 4, 1),
953f0f58 10568GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10569GEN_VXFORM(vmulosb, 4, 4),
10570GEN_VXFORM(vmulosh, 4, 5),
63be0936 10571GEN_VXFORM_207(vmulosw, 4, 6),
5c55ff99
BS
10572GEN_VXFORM(vmuleub, 4, 8),
10573GEN_VXFORM(vmuleuh, 4, 9),
63be0936 10574GEN_VXFORM_207(vmuleuw, 4, 10),
5c55ff99
BS
10575GEN_VXFORM(vmulesb, 4, 12),
10576GEN_VXFORM(vmulesh, 4, 13),
63be0936 10577GEN_VXFORM_207(vmulesw, 4, 14),
5c55ff99
BS
10578GEN_VXFORM(vslb, 2, 4),
10579GEN_VXFORM(vslh, 2, 5),
10580GEN_VXFORM(vslw, 2, 6),
2fdf78e6 10581GEN_VXFORM_207(vsld, 2, 23),
5c55ff99
BS
10582GEN_VXFORM(vsrb, 2, 8),
10583GEN_VXFORM(vsrh, 2, 9),
10584GEN_VXFORM(vsrw, 2, 10),
2fdf78e6 10585GEN_VXFORM_207(vsrd, 2, 27),
5c55ff99
BS
10586GEN_VXFORM(vsrab, 2, 12),
10587GEN_VXFORM(vsrah, 2, 13),
10588GEN_VXFORM(vsraw, 2, 14),
2fdf78e6 10589GEN_VXFORM_207(vsrad, 2, 15),
5c55ff99
BS
10590GEN_VXFORM(vslo, 6, 16),
10591GEN_VXFORM(vsro, 6, 17),
10592GEN_VXFORM(vaddcuw, 0, 6),
10593GEN_VXFORM(vsubcuw, 0, 22),
10594GEN_VXFORM(vaddubs, 0, 8),
10595GEN_VXFORM(vadduhs, 0, 9),
10596GEN_VXFORM(vadduws, 0, 10),
10597GEN_VXFORM(vaddsbs, 0, 12),
10598GEN_VXFORM(vaddshs, 0, 13),
10599GEN_VXFORM(vaddsws, 0, 14),
e8f7b27b
TM
10600GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10601GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10602GEN_VXFORM(vsubuws, 0, 26),
10603GEN_VXFORM(vsubsbs, 0, 28),
10604GEN_VXFORM(vsubshs, 0, 29),
10605GEN_VXFORM(vsubsws, 0, 30),
b41da4eb
TM
10606GEN_VXFORM_207(vadduqm, 0, 4),
10607GEN_VXFORM_207(vaddcuq, 0, 5),
10608GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10609GEN_VXFORM_207(vsubuqm, 0, 20),
10610GEN_VXFORM_207(vsubcuq, 0, 21),
10611GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
5c55ff99
BS
10612GEN_VXFORM(vrlb, 2, 0),
10613GEN_VXFORM(vrlh, 2, 1),
10614GEN_VXFORM(vrlw, 2, 2),
2fdf78e6 10615GEN_VXFORM_207(vrld, 2, 3),
5c55ff99
BS
10616GEN_VXFORM(vsl, 2, 7),
10617GEN_VXFORM(vsr, 2, 11),
10618GEN_VXFORM(vpkuhum, 7, 0),
10619GEN_VXFORM(vpkuwum, 7, 1),
024215b2 10620GEN_VXFORM_207(vpkudum, 7, 17),
5c55ff99
BS
10621GEN_VXFORM(vpkuhus, 7, 2),
10622GEN_VXFORM(vpkuwus, 7, 3),
024215b2 10623GEN_VXFORM_207(vpkudus, 7, 19),
5c55ff99
BS
10624GEN_VXFORM(vpkshus, 7, 4),
10625GEN_VXFORM(vpkswus, 7, 5),
024215b2 10626GEN_VXFORM_207(vpksdus, 7, 21),
5c55ff99
BS
10627GEN_VXFORM(vpkshss, 7, 6),
10628GEN_VXFORM(vpkswss, 7, 7),
024215b2 10629GEN_VXFORM_207(vpksdss, 7, 23),
5c55ff99
BS
10630GEN_VXFORM(vpkpx, 7, 12),
10631GEN_VXFORM(vsum4ubs, 4, 24),
10632GEN_VXFORM(vsum4sbs, 4, 28),
10633GEN_VXFORM(vsum4shs, 4, 25),
10634GEN_VXFORM(vsum2sws, 4, 26),
10635GEN_VXFORM(vsumsws, 4, 30),
10636GEN_VXFORM(vaddfp, 5, 0),
10637GEN_VXFORM(vsubfp, 5, 1),
10638GEN_VXFORM(vmaxfp, 5, 16),
10639GEN_VXFORM(vminfp, 5, 17),
10640
10641#undef GEN_VXRFORM1
10642#undef GEN_VXRFORM
10643#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10644 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10645#define GEN_VXRFORM(name, opc2, opc3) \
10646 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10647 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10648GEN_VXRFORM(vcmpequb, 3, 0)
10649GEN_VXRFORM(vcmpequh, 3, 1)
10650GEN_VXRFORM(vcmpequw, 3, 2)
10651GEN_VXRFORM(vcmpgtsb, 3, 12)
10652GEN_VXRFORM(vcmpgtsh, 3, 13)
10653GEN_VXRFORM(vcmpgtsw, 3, 14)
10654GEN_VXRFORM(vcmpgtub, 3, 8)
10655GEN_VXRFORM(vcmpgtuh, 3, 9)
10656GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 10657GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
5c55ff99 10658GEN_VXRFORM(vcmpgefp, 3, 7)
6f3dab41
TM
10659GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10660GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
5c55ff99
BS
10661
10662#undef GEN_VXFORM_SIMM
10663#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10664 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10665GEN_VXFORM_SIMM(vspltisb, 6, 12),
10666GEN_VXFORM_SIMM(vspltish, 6, 13),
10667GEN_VXFORM_SIMM(vspltisw, 6, 14),
10668
10669#undef GEN_VXFORM_NOA
10670#define GEN_VXFORM_NOA(name, opc2, opc3) \
10671 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10672GEN_VXFORM_NOA(vupkhsb, 7, 8),
10673GEN_VXFORM_NOA(vupkhsh, 7, 9),
4430e076 10674GEN_VXFORM_207(vupkhsw, 7, 25),
5c55ff99
BS
10675GEN_VXFORM_NOA(vupklsb, 7, 10),
10676GEN_VXFORM_NOA(vupklsh, 7, 11),
4430e076 10677GEN_VXFORM_207(vupklsw, 7, 27),
5c55ff99
BS
10678GEN_VXFORM_NOA(vupkhpx, 7, 13),
10679GEN_VXFORM_NOA(vupklpx, 7, 15),
10680GEN_VXFORM_NOA(vrefp, 5, 4),
10681GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10682GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99
BS
10683GEN_VXFORM_NOA(vlogefp, 5, 7),
10684GEN_VXFORM_NOA(vrfim, 5, 8),
10685GEN_VXFORM_NOA(vrfin, 5, 9),
10686GEN_VXFORM_NOA(vrfip, 5, 10),
10687GEN_VXFORM_NOA(vrfiz, 5, 11),
10688
10689#undef GEN_VXFORM_UIMM
10690#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10691 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10692GEN_VXFORM_UIMM(vspltb, 6, 8),
10693GEN_VXFORM_UIMM(vsplth, 6, 9),
10694GEN_VXFORM_UIMM(vspltw, 6, 10),
10695GEN_VXFORM_UIMM(vcfux, 5, 12),
10696GEN_VXFORM_UIMM(vcfsx, 5, 13),
10697GEN_VXFORM_UIMM(vctuxs, 5, 14),
10698GEN_VXFORM_UIMM(vctsxs, 5, 15),
10699
10700#undef GEN_VAFORM_PAIRED
10701#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10702 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10703GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10704GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10705GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10706GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10707GEN_VAFORM_PAIRED(vsel, vperm, 21),
10708GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10709
e13500b3
TM
10710GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10711GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10712GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10713GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10714
4d82038e 10715GEN_VXFORM_207(vbpermq, 6, 21),
f1064f61 10716GEN_VXFORM_207(vgbbd, 6, 20),
b8476fc7
TM
10717GEN_VXFORM_207(vpmsumb, 4, 16),
10718GEN_VXFORM_207(vpmsumh, 4, 17),
10719GEN_VXFORM_207(vpmsumw, 4, 18),
10720GEN_VXFORM_207(vpmsumd, 4, 19),
f293f04a 10721
557d52fa
TM
10722GEN_VXFORM_207(vsbox, 4, 23),
10723
10724GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10725GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10726
57354f8f
TM
10727GEN_VXFORM_207(vshasigmaw, 1, 26),
10728GEN_VXFORM_207(vshasigmad, 1, 27),
10729
ac174549
TM
10730GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10731
fa1832d7 10732GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10733GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10734GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10735GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10736GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10737GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10738GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10739
9231ba9e 10740GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10741GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10742GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10743GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10744GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10745
f5c0f7f9
TM
10746GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10747GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10748GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10749#if defined(TARGET_PPC64)
10750GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10751GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10752#endif
10753
df020ce0
TM
10754#undef GEN_XX2FORM
10755#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10756GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10757GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10758
10759#undef GEN_XX3FORM
10760#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10761GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10762GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10763GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10764GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10765
354a6dec
TM
10766#undef GEN_XX3_RC_FORM
10767#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10768GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10769GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10770GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10771GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10772GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10773GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10774GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10775GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10776
cd73f2c9
TM
10777#undef GEN_XX3FORM_DM
10778#define GEN_XX3FORM_DM(name, opc2, opc3) \
10779GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10780GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10781GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10782GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10783GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10784GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10785GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10786GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10787GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10788GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10789GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10790GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10791GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10792GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10793GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10794GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10795
df020ce0
TM
10796GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10797GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10798GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10799GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10800
be574920
TM
10801GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10802GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10803GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10804GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10805GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10806GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10807GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10808GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 10809
ee6e02c0
TM
10810GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10811GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 10812GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 10813GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 10814GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 10815GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 10816GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 10817GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 10818GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
10819GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10820GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10821GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10822GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10823GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10824GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10825GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10826GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
4f17e9c7
TM
10827GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10828GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
10829GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10830GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568 10831GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
7ee19fb9 10832GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
ed8ac568 10833GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
7ee19fb9 10834GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
5177d2ca
TM
10835GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10836GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10837GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10838GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10839GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10840GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
10841GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10842GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10843GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10844GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10845GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 10846
3fd0aadf
TM
10847GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10848GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 10849GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 10850GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 10851GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
3d1140bf 10852GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
cea4e574 10853GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
968e76bc 10854GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
f53f81e0
TM
10855GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
10856GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
10857GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
10858GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
10859GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
10860GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
10861GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
10862GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
74698350
TM
10863GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
10864GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
3fd0aadf 10865
ee6e02c0
TM
10866GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10867GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 10868GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 10869GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 10870GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 10871GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 10872GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 10873GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 10874GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
10875GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10876GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10877GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10878GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10879GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10880GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10881GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10882GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
10883GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10884GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
10885GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10886GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10887GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 10888GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
10889GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10890GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10891GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10892GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10893GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10894GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10895GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10896GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
10897GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10898GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10899GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10900GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10901GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
10902
10903GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10904GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 10905GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 10906GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 10907GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 10908GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 10909GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 10910GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 10911GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
10912GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10913GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10914GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10915GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10916GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10917GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10918GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10919GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
10920GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10921GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
10922GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10923GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10924GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 10925GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
10926GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10927GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10928GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10929GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10930GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10931GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10932GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10933GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
10934GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10935GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10936GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10937GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10938GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 10939
79ca8a6a
TM
10940#undef VSX_LOGICAL
10941#define VSX_LOGICAL(name, opc2, opc3, fl2) \
10942GEN_XX3FORM(name, opc2, opc3, fl2)
10943
10944VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10945VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10946VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10947VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10948VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
67a33f37
TM
10949VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
10950VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
10951VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
ce577d2e
TM
10952GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10953GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 10954GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 10955GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 10956
551e3ef7
TM
10957#define GEN_XXSEL_ROW(opc3) \
10958GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10959GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10960GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10961GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10962GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10963GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10964GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10965GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10966
10967GEN_XXSEL_ROW(0x00)
10968GEN_XXSEL_ROW(0x01)
10969GEN_XXSEL_ROW(0x02)
10970GEN_XXSEL_ROW(0x03)
10971GEN_XXSEL_ROW(0x04)
10972GEN_XXSEL_ROW(0x05)
10973GEN_XXSEL_ROW(0x06)
10974GEN_XXSEL_ROW(0x07)
10975GEN_XXSEL_ROW(0x08)
10976GEN_XXSEL_ROW(0x09)
10977GEN_XXSEL_ROW(0x0A)
10978GEN_XXSEL_ROW(0x0B)
10979GEN_XXSEL_ROW(0x0C)
10980GEN_XXSEL_ROW(0x0D)
10981GEN_XXSEL_ROW(0x0E)
10982GEN_XXSEL_ROW(0x0F)
10983GEN_XXSEL_ROW(0x10)
10984GEN_XXSEL_ROW(0x11)
10985GEN_XXSEL_ROW(0x12)
10986GEN_XXSEL_ROW(0x13)
10987GEN_XXSEL_ROW(0x14)
10988GEN_XXSEL_ROW(0x15)
10989GEN_XXSEL_ROW(0x16)
10990GEN_XXSEL_ROW(0x17)
10991GEN_XXSEL_ROW(0x18)
10992GEN_XXSEL_ROW(0x19)
10993GEN_XXSEL_ROW(0x1A)
10994GEN_XXSEL_ROW(0x1B)
10995GEN_XXSEL_ROW(0x1C)
10996GEN_XXSEL_ROW(0x1D)
10997GEN_XXSEL_ROW(0x1E)
10998GEN_XXSEL_ROW(0x1F)
10999
cd73f2c9
TM
11000GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
11001
5c55ff99 11002#undef GEN_SPE
70560da7
FC
11003#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11004 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11005GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11006GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11007GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11008GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11009GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11010GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11011GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11012GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
11013GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
11014GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11015GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11016GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11017GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11018GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11019GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11020GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
11021GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11022GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11023GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11024GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11025GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11026GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11027GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11028GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11029GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11030GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11031GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11032GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11033GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
11034
11035GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11036GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11037GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11038GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11039GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11040GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11041GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11042GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11043GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11044GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11045GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11046GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11047GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11048GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11049
11050GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11051GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11052GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11053GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11054GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11055GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11056GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11057GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11058GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11059GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11060GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11061GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11062GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11063GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11064
11065GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11066GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11067GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11068GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11069GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11070GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11071GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11072GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11073GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11074GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11075GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11076GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11077GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11078GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11079GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11080GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
11081
11082#undef GEN_SPEOP_LDST
11083#define GEN_SPEOP_LDST(name, opc2, sh) \
11084GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11085GEN_SPEOP_LDST(evldd, 0x00, 3),
11086GEN_SPEOP_LDST(evldw, 0x01, 3),
11087GEN_SPEOP_LDST(evldh, 0x02, 3),
11088GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11089GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11090GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11091GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11092GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11093GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11094GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11095GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11096
11097GEN_SPEOP_LDST(evstdd, 0x10, 3),
11098GEN_SPEOP_LDST(evstdw, 0x11, 3),
11099GEN_SPEOP_LDST(evstdh, 0x12, 3),
11100GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11101GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11102GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11103GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
11104};
11105
0411a972 11106#include "helper_regs.h"
a1389542 11107#include "translate_init.c"
79aceca5 11108
9a64fbe4 11109/*****************************************************************************/
3fc6c082 11110/* Misc PowerPC helpers */
878096ee
AF
11111void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11112 int flags)
79aceca5 11113{
3fc6c082
FB
11114#define RGPL 4
11115#define RFPL 4
3fc6c082 11116
878096ee
AF
11117 PowerPCCPU *cpu = POWERPC_CPU(cs);
11118 CPUPPCState *env = &cpu->env;
79aceca5
FB
11119 int i;
11120
90e189ec 11121 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9a78eead 11122 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
da91a00f 11123 env->nip, env->lr, env->ctr, cpu_read_xer(env));
90e189ec
BS
11124 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
11125 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
11126 env->hflags, env->mmu_idx);
d9bce9d9 11127#if !defined(NO_TIMER_DUMP)
9a78eead 11128 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 11129#if !defined(CONFIG_USER_ONLY)
9a78eead 11130 " DECR %08" PRIu32
76a66253
JM
11131#endif
11132 "\n",
077fc206 11133 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
11134#if !defined(CONFIG_USER_ONLY)
11135 , cpu_ppc_load_decr(env)
11136#endif
11137 );
077fc206 11138#endif
76a66253 11139 for (i = 0; i < 32; i++) {
3fc6c082
FB
11140 if ((i & (RGPL - 1)) == 0)
11141 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 11142 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 11143 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 11144 cpu_fprintf(f, "\n");
76a66253 11145 }
3fc6c082 11146 cpu_fprintf(f, "CR ");
76a66253 11147 for (i = 0; i < 8; i++)
7fe48483
FB
11148 cpu_fprintf(f, "%01x", env->crf[i]);
11149 cpu_fprintf(f, " [");
76a66253
JM
11150 for (i = 0; i < 8; i++) {
11151 char a = '-';
11152 if (env->crf[i] & 0x08)
11153 a = 'L';
11154 else if (env->crf[i] & 0x04)
11155 a = 'G';
11156 else if (env->crf[i] & 0x02)
11157 a = 'E';
7fe48483 11158 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 11159 }
90e189ec
BS
11160 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11161 env->reserve_addr);
3fc6c082
FB
11162 for (i = 0; i < 32; i++) {
11163 if ((i & (RFPL - 1)) == 0)
11164 cpu_fprintf(f, "FPR%02d", i);
26a76461 11165 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 11166 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 11167 cpu_fprintf(f, "\n");
79aceca5 11168 }
30304420 11169 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 11170#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
11171 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11172 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11173 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11174 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11175
11176 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11177 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11178 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11179 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11180
11181 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11182 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11183 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11184 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11185
11186 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11187 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11188 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11189 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11190 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11191
11192 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11193 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11194 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11195 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11196
11197 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11198 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11199 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11200 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11201
11202 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11203 " EPR " TARGET_FMT_lx "\n",
11204 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11205 env->spr[SPR_BOOKE_EPR]);
11206
11207 /* FSL-specific */
11208 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11209 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11210 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11211 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11212
11213 /*
11214 * IVORs are left out as they are large and do not change often --
11215 * they can be read with "p $ivor0", "p $ivor1", etc.
11216 */
11217 }
11218
697ab892
DG
11219#if defined(TARGET_PPC64)
11220 if (env->flags & POWERPC_FLAG_CFAR) {
11221 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11222 }
11223#endif
11224
90dc8812
SW
11225 switch (env->mmu_model) {
11226 case POWERPC_MMU_32B:
11227 case POWERPC_MMU_601:
11228 case POWERPC_MMU_SOFT_6xx:
11229 case POWERPC_MMU_SOFT_74xx:
11230#if defined(TARGET_PPC64)
90dc8812 11231 case POWERPC_MMU_64B:
ca480de6
AB
11232 case POWERPC_MMU_2_06:
11233 case POWERPC_MMU_2_06a:
11234 case POWERPC_MMU_2_06d:
90dc8812 11235#endif
ca480de6
AB
11236 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11237 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11238 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 11239 break;
01662f3e 11240 case POWERPC_MMU_BOOKE206:
90dc8812
SW
11241 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11242 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11243 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11244 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11245
11246 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11247 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11248 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11249 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11250
11251 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11252 " TLB1CFG " TARGET_FMT_lx "\n",
11253 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11254 env->spr[SPR_BOOKE_TLB1CFG]);
11255 break;
11256 default:
11257 break;
11258 }
f2e63a42 11259#endif
79aceca5 11260
3fc6c082
FB
11261#undef RGPL
11262#undef RFPL
79aceca5
FB
11263}
11264
878096ee
AF
11265void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11266 fprintf_function cpu_fprintf, int flags)
76a66253
JM
11267{
11268#if defined(DO_PPC_STATISTICS)
878096ee 11269 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 11270 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
11271 int op1, op2, op3;
11272
878096ee 11273 t1 = cpu->env.opcodes;
76a66253
JM
11274 for (op1 = 0; op1 < 64; op1++) {
11275 handler = t1[op1];
11276 if (is_indirect_opcode(handler)) {
11277 t2 = ind_table(handler);
11278 for (op2 = 0; op2 < 32; op2++) {
11279 handler = t2[op2];
11280 if (is_indirect_opcode(handler)) {
11281 t3 = ind_table(handler);
11282 for (op3 = 0; op3 < 32; op3++) {
11283 handler = t3[op3];
11284 if (handler->count == 0)
11285 continue;
11286 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 11287 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11288 op1, op2, op3, op1, (op3 << 5) | op2,
11289 handler->oname,
11290 handler->count, handler->count);
11291 }
11292 } else {
11293 if (handler->count == 0)
11294 continue;
11295 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 11296 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11297 op1, op2, op1, op2, handler->oname,
11298 handler->count, handler->count);
11299 }
11300 }
11301 } else {
11302 if (handler->count == 0)
11303 continue;
0bfcd599
BS
11304 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11305 " %" PRId64 "\n",
76a66253
JM
11306 op1, op1, handler->oname,
11307 handler->count, handler->count);
11308 }
11309 }
11310#endif
11311}
11312
9a64fbe4 11313/*****************************************************************************/
213fe1f5 11314static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
636aa200 11315 TranslationBlock *tb,
213fe1f5 11316 bool search_pc)
79aceca5 11317{
ed2803da 11318 CPUState *cs = CPU(cpu);
213fe1f5 11319 CPUPPCState *env = &cpu->env;
9fddaa0c 11320 DisasContext ctx, *ctxp = &ctx;
c227f099 11321 opc_handler_t **table, *handler;
0fa85d43 11322 target_ulong pc_start;
79aceca5 11323 uint16_t *gen_opc_end;
a1d1bb31 11324 CPUBreakpoint *bp;
79aceca5 11325 int j, lj = -1;
2e70f6ef
PB
11326 int num_insns;
11327 int max_insns;
79aceca5
FB
11328
11329 pc_start = tb->pc;
92414b31 11330 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
046d6672 11331 ctx.nip = pc_start;
79aceca5 11332 ctx.tb = tb;
e1833e1f 11333 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 11334 ctx.spr_cb = env->spr_cb;
76db3ba4 11335 ctx.mem_idx = env->mmu_idx;
7d08d856
AJ
11336 ctx.insns_flags = env->insns_flags;
11337 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
11338 ctx.access_type = -1;
11339 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
d9bce9d9 11340#if defined(TARGET_PPC64)
e42a61f1 11341 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 11342 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 11343#endif
3cc62370 11344 ctx.fpu_enabled = msr_fp;
a9d9eb8f 11345 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
11346 ctx.spe_enabled = msr_spe;
11347 else
11348 ctx.spe_enabled = 0;
a9d9eb8f
JM
11349 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11350 ctx.altivec_enabled = msr_vr;
11351 else
11352 ctx.altivec_enabled = 0;
1f29871c
TM
11353 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11354 ctx.vsx_enabled = msr_vsx;
11355 } else {
11356 ctx.vsx_enabled = 0;
11357 }
d26bfc9a 11358 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 11359 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 11360 else
8cbcb4fa 11361 ctx.singlestep_enabled = 0;
d26bfc9a 11362 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 11363 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 11364 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 11365 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 11366 }
3fc6c082 11367#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
11368 /* Single step trace mode */
11369 msr_se = 1;
11370#endif
2e70f6ef
PB
11371 num_insns = 0;
11372 max_insns = tb->cflags & CF_COUNT_MASK;
11373 if (max_insns == 0)
11374 max_insns = CF_COUNT_MASK;
11375
806f352d 11376 gen_tb_start();
9a64fbe4 11377 /* Set env in case of segfault during code fetch */
efd7f486
EV
11378 while (ctx.exception == POWERPC_EXCP_NONE
11379 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
f0c3c505
AF
11380 if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) {
11381 QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {
a1d1bb31 11382 if (bp->pc == ctx.nip) {
e06fcd75 11383 gen_debug_exception(ctxp);
ea4e754f
FB
11384 break;
11385 }
11386 }
11387 }
76a66253 11388 if (unlikely(search_pc)) {
92414b31 11389 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
79aceca5
FB
11390 if (lj < j) {
11391 lj++;
11392 while (lj < j)
ab1103de 11393 tcg_ctx.gen_opc_instr_start[lj++] = 0;
79aceca5 11394 }
25983cad 11395 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
ab1103de 11396 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 11397 tcg_ctx.gen_opc_icount[lj] = num_insns;
79aceca5 11398 }
d12d51d5 11399 LOG_DISAS("----------------\n");
90e189ec 11400 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 11401 ctx.nip, ctx.mem_idx, (int)msr_ir);
2e70f6ef
PB
11402 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
11403 gen_io_start();
76db3ba4 11404 if (unlikely(ctx.le_mode)) {
2f5a189c 11405 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 11406 } else {
2f5a189c 11407 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 11408 }
d12d51d5 11409 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 11410 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 11411 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
fdefe51c 11412 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
731c54f8 11413 tcg_gen_debug_insn_start(ctx.nip);
fdefe51c 11414 }
046d6672 11415 ctx.nip += 4;
3fc6c082 11416 table = env->opcodes;
2e70f6ef 11417 num_insns++;
79aceca5
FB
11418 handler = table[opc1(ctx.opcode)];
11419 if (is_indirect_opcode(handler)) {
11420 table = ind_table(handler);
11421 handler = table[opc2(ctx.opcode)];
11422 if (is_indirect_opcode(handler)) {
11423 table = ind_table(handler);
11424 handler = table[opc3(ctx.opcode)];
11425 }
11426 }
11427 /* Is opcode *REALLY* valid ? */
76a66253 11428 if (unlikely(handler->handler == &gen_invalid)) {
93fcfe39
AL
11429 if (qemu_log_enabled()) {
11430 qemu_log("invalid/unsupported opcode: "
90e189ec
BS
11431 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11432 opc1(ctx.opcode), opc2(ctx.opcode),
11433 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
4b3686fa 11434 }
76a66253 11435 } else {
70560da7
FC
11436 uint32_t inval;
11437
11438 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11439 inval = handler->inval2;
11440 } else {
11441 inval = handler->inval1;
11442 }
11443
11444 if (unlikely((ctx.opcode & inval) != 0)) {
93fcfe39
AL
11445 if (qemu_log_enabled()) {
11446 qemu_log("invalid bits: %08x for opcode: "
90e189ec 11447 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
70560da7 11448 ctx.opcode & inval, opc1(ctx.opcode),
90e189ec
BS
11449 opc2(ctx.opcode), opc3(ctx.opcode),
11450 ctx.opcode, ctx.nip - 4);
76a66253 11451 }
e06fcd75 11452 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 11453 break;
79aceca5 11454 }
79aceca5 11455 }
4b3686fa 11456 (*(handler->handler))(&ctx);
76a66253
JM
11457#if defined(DO_PPC_STATISTICS)
11458 handler->count++;
11459#endif
9a64fbe4 11460 /* Check trace mode exceptions */
8cbcb4fa
AJ
11461 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11462 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11463 ctx.exception != POWERPC_SYSCALL &&
11464 ctx.exception != POWERPC_EXCP_TRAP &&
11465 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 11466 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 11467 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 11468 (cs->singlestep_enabled) ||
1b530a6d 11469 singlestep ||
2e70f6ef 11470 num_insns >= max_insns)) {
d26bfc9a
JM
11471 /* if we reach a page boundary or are single stepping, stop
11472 * generation
11473 */
8dd4983c 11474 break;
76a66253 11475 }
3fc6c082 11476 }
2e70f6ef
PB
11477 if (tb->cflags & CF_LAST_IO)
11478 gen_io_end();
e1833e1f 11479 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 11480 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 11481 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 11482 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 11483 gen_debug_exception(ctxp);
8cbcb4fa 11484 }
76a66253 11485 /* Generate the return instruction */
57fec1fe 11486 tcg_gen_exit_tb(0);
9a64fbe4 11487 }
806f352d 11488 gen_tb_end(tb, num_insns);
efd7f486 11489 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
76a66253 11490 if (unlikely(search_pc)) {
92414b31 11491 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9a64fbe4
FB
11492 lj++;
11493 while (lj <= j)
ab1103de 11494 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9a64fbe4 11495 } else {
046d6672 11496 tb->size = ctx.nip - pc_start;
2e70f6ef 11497 tb->icount = num_insns;
9a64fbe4 11498 }
d9bce9d9 11499#if defined(DEBUG_DISAS)
8fec2b8c 11500 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 11501 int flags;
237c0af0 11502 flags = env->bfd_mach;
76db3ba4 11503 flags |= ctx.le_mode << 16;
93fcfe39 11504 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 11505 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
93fcfe39 11506 qemu_log("\n");
9fddaa0c 11507 }
79aceca5 11508#endif
79aceca5
FB
11509}
11510
1328c2bf 11511void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11512{
213fe1f5 11513 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
79aceca5
FB
11514}
11515
1328c2bf 11516void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11517{
213fe1f5 11518 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
79aceca5 11519}
d2856f1a 11520
1328c2bf 11521void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
d2856f1a 11522{
25983cad 11523 env->nip = tcg_ctx.gen_opc_pc[pc_pos];
d2856f1a 11524}