]> git.ipfire.org Git - thirdparty/qemu.git/blame - target-ppc/translate.c
target-ppc: Load Quadword
[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);
390/* Destination */
391EXTRACT_HELPER(rD, 21, 5);
392/* Source */
393EXTRACT_HELPER(rS, 21, 5);
394/* First operand */
395EXTRACT_HELPER(rA, 16, 5);
396/* Second operand */
397EXTRACT_HELPER(rB, 11, 5);
398/* Third operand */
399EXTRACT_HELPER(rC, 6, 5);
400/*** Get CRn ***/
401EXTRACT_HELPER(crfD, 23, 3);
402EXTRACT_HELPER(crfS, 18, 3);
403EXTRACT_HELPER(crbD, 21, 5);
404EXTRACT_HELPER(crbA, 16, 5);
405EXTRACT_HELPER(crbB, 11, 5);
406/* SPR / TBL */
3fc6c082 407EXTRACT_HELPER(_SPR, 11, 10);
636aa200 408static inline uint32_t SPR(uint32_t opcode)
3fc6c082
FB
409{
410 uint32_t sprn = _SPR(opcode);
411
412 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
413}
79aceca5
FB
414/*** Get constants ***/
415EXTRACT_HELPER(IMM, 12, 8);
416/* 16 bits signed immediate value */
417EXTRACT_SHELPER(SIMM, 0, 16);
418/* 16 bits unsigned immediate value */
419EXTRACT_HELPER(UIMM, 0, 16);
21d21583
AJ
420/* 5 bits signed immediate value */
421EXTRACT_HELPER(SIMM5, 16, 5);
27a4edb3
AJ
422/* 5 bits signed immediate value */
423EXTRACT_HELPER(UIMM5, 16, 5);
79aceca5
FB
424/* Bit count */
425EXTRACT_HELPER(NB, 11, 5);
426/* Shift count */
427EXTRACT_HELPER(SH, 11, 5);
cd633b10
AJ
428/* Vector shift count */
429EXTRACT_HELPER(VSH, 6, 4);
79aceca5
FB
430/* Mask start */
431EXTRACT_HELPER(MB, 6, 5);
432/* Mask end */
433EXTRACT_HELPER(ME, 1, 5);
fb0eaffc
FB
434/* Trap operand */
435EXTRACT_HELPER(TO, 21, 5);
79aceca5
FB
436
437EXTRACT_HELPER(CRM, 12, 8);
79aceca5 438EXTRACT_HELPER(SR, 16, 4);
7d08d856
AJ
439
440/* mtfsf/mtfsfi */
779f6590 441EXTRACT_HELPER(FPBF, 23, 3);
e4bb997e 442EXTRACT_HELPER(FPIMM, 12, 4);
779f6590 443EXTRACT_HELPER(FPL, 25, 1);
7d08d856
AJ
444EXTRACT_HELPER(FPFLM, 17, 8);
445EXTRACT_HELPER(FPW, 16, 1);
fb0eaffc 446
79aceca5
FB
447/*** Jump target decoding ***/
448/* Displacement */
449EXTRACT_SHELPER(d, 0, 16);
450/* Immediate address */
636aa200 451static inline target_ulong LI(uint32_t opcode)
79aceca5
FB
452{
453 return (opcode >> 0) & 0x03FFFFFC;
454}
455
636aa200 456static inline uint32_t BD(uint32_t opcode)
79aceca5
FB
457{
458 return (opcode >> 0) & 0xFFFC;
459}
460
461EXTRACT_HELPER(BO, 21, 5);
462EXTRACT_HELPER(BI, 16, 5);
463/* Absolute/relative address */
464EXTRACT_HELPER(AA, 1, 1);
465/* Link */
466EXTRACT_HELPER(LK, 0, 1);
467
468/* Create a mask between <start> and <end> bits */
636aa200 469static inline target_ulong MASK(uint32_t start, uint32_t end)
79aceca5 470{
76a66253 471 target_ulong ret;
79aceca5 472
76a66253
JM
473#if defined(TARGET_PPC64)
474 if (likely(start == 0)) {
6f2d8978 475 ret = UINT64_MAX << (63 - end);
76a66253 476 } else if (likely(end == 63)) {
6f2d8978 477 ret = UINT64_MAX >> start;
76a66253
JM
478 }
479#else
480 if (likely(start == 0)) {
6f2d8978 481 ret = UINT32_MAX << (31 - end);
76a66253 482 } else if (likely(end == 31)) {
6f2d8978 483 ret = UINT32_MAX >> start;
76a66253
JM
484 }
485#endif
486 else {
487 ret = (((target_ulong)(-1ULL)) >> (start)) ^
488 (((target_ulong)(-1ULL) >> (end)) >> 1);
489 if (unlikely(start > end))
490 return ~ret;
491 }
79aceca5
FB
492
493 return ret;
494}
495
f9fc6d81
TM
496EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
497EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
498EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
499EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
551e3ef7 500EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
f9fc6d81 501EXTRACT_HELPER(DM, 8, 2);
76c15fe0 502EXTRACT_HELPER(UIM, 16, 2);
acc42968 503EXTRACT_HELPER(SHW, 8, 2);
a750fc0b 504/*****************************************************************************/
a750fc0b 505/* PowerPC instructions table */
933dc6eb 506
76a66253 507#if defined(DO_PPC_STATISTICS)
a5858d7a 508#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 509{ \
79aceca5
FB
510 .opc1 = op1, \
511 .opc2 = op2, \
512 .opc3 = op3, \
18fba28c 513 .pad = { 0, }, \
79aceca5 514 .handler = { \
70560da7
FC
515 .inval1 = invl, \
516 .type = _typ, \
517 .type2 = _typ2, \
518 .handler = &gen_##name, \
519 .oname = stringify(name), \
520 }, \
521 .oname = stringify(name), \
522}
523#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
524{ \
525 .opc1 = op1, \
526 .opc2 = op2, \
527 .opc3 = op3, \
528 .pad = { 0, }, \
529 .handler = { \
530 .inval1 = invl1, \
531 .inval2 = invl2, \
9a64fbe4 532 .type = _typ, \
a5858d7a 533 .type2 = _typ2, \
79aceca5 534 .handler = &gen_##name, \
76a66253 535 .oname = stringify(name), \
79aceca5 536 }, \
3fc6c082 537 .oname = stringify(name), \
79aceca5 538}
a5858d7a 539#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 540{ \
c7697e1f
JM
541 .opc1 = op1, \
542 .opc2 = op2, \
543 .opc3 = op3, \
544 .pad = { 0, }, \
545 .handler = { \
70560da7 546 .inval1 = invl, \
c7697e1f 547 .type = _typ, \
a5858d7a 548 .type2 = _typ2, \
c7697e1f
JM
549 .handler = &gen_##name, \
550 .oname = onam, \
551 }, \
552 .oname = onam, \
553}
76a66253 554#else
a5858d7a 555#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 556{ \
c7697e1f
JM
557 .opc1 = op1, \
558 .opc2 = op2, \
559 .opc3 = op3, \
560 .pad = { 0, }, \
561 .handler = { \
70560da7
FC
562 .inval1 = invl, \
563 .type = _typ, \
564 .type2 = _typ2, \
565 .handler = &gen_##name, \
566 }, \
567 .oname = stringify(name), \
568}
569#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
570{ \
571 .opc1 = op1, \
572 .opc2 = op2, \
573 .opc3 = op3, \
574 .pad = { 0, }, \
575 .handler = { \
576 .inval1 = invl1, \
577 .inval2 = invl2, \
c7697e1f 578 .type = _typ, \
a5858d7a 579 .type2 = _typ2, \
c7697e1f 580 .handler = &gen_##name, \
5c55ff99
BS
581 }, \
582 .oname = stringify(name), \
583}
a5858d7a 584#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99
BS
585{ \
586 .opc1 = op1, \
587 .opc2 = op2, \
588 .opc3 = op3, \
589 .pad = { 0, }, \
590 .handler = { \
70560da7 591 .inval1 = invl, \
5c55ff99 592 .type = _typ, \
a5858d7a 593 .type2 = _typ2, \
5c55ff99
BS
594 .handler = &gen_##name, \
595 }, \
596 .oname = onam, \
597}
598#endif
2e610050 599
5c55ff99 600/* SPR load/store helpers */
636aa200 601static inline void gen_load_spr(TCGv t, int reg)
5c55ff99 602{
1328c2bf 603 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 604}
2e610050 605
636aa200 606static inline void gen_store_spr(int reg, TCGv t)
5c55ff99 607{
1328c2bf 608 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 609}
2e610050 610
54623277 611/* Invalid instruction */
99e300ef 612static void gen_invalid(DisasContext *ctx)
9a64fbe4 613{
e06fcd75 614 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
9a64fbe4
FB
615}
616
c227f099 617static opc_handler_t invalid_handler = {
70560da7
FC
618 .inval1 = 0xFFFFFFFF,
619 .inval2 = 0xFFFFFFFF,
9a64fbe4 620 .type = PPC_NONE,
a5858d7a 621 .type2 = PPC_NONE,
79aceca5
FB
622 .handler = gen_invalid,
623};
624
71a8c019
TM
625#if defined(TARGET_PPC64)
626/* NOTE: as this time, the only use of is_user_mode() is in 64 bit code. And */
627/* so the function is wrapped in the standard 64-bit ifdef in order to */
628/* avoid compiler warnings in 32-bit implementations. */
629static bool is_user_mode(DisasContext *ctx)
630{
631#if defined(CONFIG_USER_ONLY)
632 return true;
633#else
634 return ctx->mem_idx == 0;
635#endif
636}
637#endif
638
e1571908
AJ
639/*** Integer comparison ***/
640
636aa200 641static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 642{
2fdcb629
RH
643 TCGv t0 = tcg_temp_new();
644 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 645
da91a00f 646 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 647
2fdcb629
RH
648 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
649 tcg_gen_trunc_tl_i32(t1, t0);
650 tcg_gen_shli_i32(t1, t1, CRF_LT);
651 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
652
653 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
654 tcg_gen_trunc_tl_i32(t1, t0);
655 tcg_gen_shli_i32(t1, t1, CRF_GT);
656 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
657
658 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
659 tcg_gen_trunc_tl_i32(t1, t0);
660 tcg_gen_shli_i32(t1, t1, CRF_EQ);
661 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
662
663 tcg_temp_free(t0);
664 tcg_temp_free_i32(t1);
e1571908
AJ
665}
666
636aa200 667static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 668{
2fdcb629 669 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
670 gen_op_cmp(arg0, t0, s, crf);
671 tcg_temp_free(t0);
e1571908
AJ
672}
673
636aa200 674static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 675{
ea363694 676 TCGv t0, t1;
2fdcb629
RH
677 t0 = tcg_temp_new();
678 t1 = tcg_temp_new();
e1571908 679 if (s) {
ea363694
AJ
680 tcg_gen_ext32s_tl(t0, arg0);
681 tcg_gen_ext32s_tl(t1, arg1);
e1571908 682 } else {
ea363694
AJ
683 tcg_gen_ext32u_tl(t0, arg0);
684 tcg_gen_ext32u_tl(t1, arg1);
e1571908 685 }
ea363694
AJ
686 gen_op_cmp(t0, t1, s, crf);
687 tcg_temp_free(t1);
688 tcg_temp_free(t0);
e1571908
AJ
689}
690
636aa200 691static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 692{
2fdcb629 693 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
694 gen_op_cmp32(arg0, t0, s, crf);
695 tcg_temp_free(t0);
e1571908 696}
e1571908 697
636aa200 698static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908 699{
02765534 700 if (NARROW_MODE(ctx)) {
e1571908 701 gen_op_cmpi32(reg, 0, 1, 0);
02765534 702 } else {
e1571908 703 gen_op_cmpi(reg, 0, 1, 0);
02765534 704 }
e1571908
AJ
705}
706
707/* cmp */
99e300ef 708static void gen_cmp(DisasContext *ctx)
e1571908 709{
36f48d9c 710 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
711 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
712 1, crfD(ctx->opcode));
36f48d9c
AG
713 } else {
714 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
715 1, crfD(ctx->opcode));
02765534 716 }
e1571908
AJ
717}
718
719/* cmpi */
99e300ef 720static void gen_cmpi(DisasContext *ctx)
e1571908 721{
36f48d9c 722 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
723 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
724 1, crfD(ctx->opcode));
36f48d9c
AG
725 } else {
726 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
727 1, crfD(ctx->opcode));
02765534 728 }
e1571908
AJ
729}
730
731/* cmpl */
99e300ef 732static void gen_cmpl(DisasContext *ctx)
e1571908 733{
36f48d9c 734 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
735 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
736 0, crfD(ctx->opcode));
36f48d9c
AG
737 } else {
738 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
739 0, crfD(ctx->opcode));
02765534 740 }
e1571908
AJ
741}
742
743/* cmpli */
99e300ef 744static void gen_cmpli(DisasContext *ctx)
e1571908 745{
36f48d9c 746 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
747 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
748 0, crfD(ctx->opcode));
36f48d9c
AG
749 } else {
750 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
751 0, crfD(ctx->opcode));
02765534 752 }
e1571908
AJ
753}
754
755/* isel (PowerPC 2.03 specification) */
99e300ef 756static void gen_isel(DisasContext *ctx)
e1571908
AJ
757{
758 int l1, l2;
759 uint32_t bi = rC(ctx->opcode);
760 uint32_t mask;
a7812ae4 761 TCGv_i32 t0;
e1571908
AJ
762
763 l1 = gen_new_label();
764 l2 = gen_new_label();
765
766 mask = 1 << (3 - (bi & 0x03));
a7812ae4 767 t0 = tcg_temp_new_i32();
fea0c503
AJ
768 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
769 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
e1571908
AJ
770 if (rA(ctx->opcode) == 0)
771 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
772 else
773 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
774 tcg_gen_br(l2);
775 gen_set_label(l1);
776 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
777 gen_set_label(l2);
a7812ae4 778 tcg_temp_free_i32(t0);
e1571908
AJ
779}
780
fcfda20f
AJ
781/* cmpb: PowerPC 2.05 specification */
782static void gen_cmpb(DisasContext *ctx)
783{
784 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
785 cpu_gpr[rB(ctx->opcode)]);
786}
787
79aceca5 788/*** Integer arithmetic ***/
79aceca5 789
636aa200
BS
790static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
791 TCGv arg1, TCGv arg2, int sub)
74637406 792{
ffe30937 793 TCGv t0 = tcg_temp_new();
79aceca5 794
8e7a6db9 795 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
74637406 796 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
797 if (sub) {
798 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
799 } else {
800 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
801 }
802 tcg_temp_free(t0);
02765534 803 if (NARROW_MODE(ctx)) {
ffe30937
RH
804 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
805 }
ffe30937
RH
806 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
807 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
808}
809
74637406 810/* Common add function */
636aa200 811static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
812 TCGv arg2, bool add_ca, bool compute_ca,
813 bool compute_ov, bool compute_rc0)
74637406 814{
b5a73f8d 815 TCGv t0 = ret;
d9bce9d9 816
752d634e 817 if (compute_ca || compute_ov) {
146de60d 818 t0 = tcg_temp_new();
74637406 819 }
79aceca5 820
da91a00f 821 if (compute_ca) {
79482e5a 822 if (NARROW_MODE(ctx)) {
752d634e
RH
823 /* Caution: a non-obvious corner case of the spec is that we
824 must produce the *entire* 64-bit addition, but produce the
825 carry into bit 32. */
79482e5a 826 TCGv t1 = tcg_temp_new();
752d634e
RH
827 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
828 tcg_gen_add_tl(t0, arg1, arg2);
79482e5a
RH
829 if (add_ca) {
830 tcg_gen_add_tl(t0, t0, cpu_ca);
831 }
752d634e
RH
832 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
833 tcg_temp_free(t1);
834 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
835 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
b5a73f8d 836 } else {
79482e5a
RH
837 TCGv zero = tcg_const_tl(0);
838 if (add_ca) {
839 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
840 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
841 } else {
842 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
843 }
844 tcg_temp_free(zero);
b5a73f8d 845 }
b5a73f8d
RH
846 } else {
847 tcg_gen_add_tl(t0, arg1, arg2);
848 if (add_ca) {
849 tcg_gen_add_tl(t0, t0, cpu_ca);
850 }
da91a00f 851 }
79aceca5 852
74637406
AJ
853 if (compute_ov) {
854 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
855 }
b5a73f8d 856 if (unlikely(compute_rc0)) {
74637406 857 gen_set_Rc0(ctx, t0);
b5a73f8d 858 }
74637406 859
a7812ae4 860 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
861 tcg_gen_mov_tl(ret, t0);
862 tcg_temp_free(t0);
863 }
39dd32ee 864}
74637406
AJ
865/* Add functions with two operands */
866#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 867static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
868{ \
869 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
870 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 871 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
872}
873/* Add functions with one operand and one immediate */
874#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
875 add_ca, compute_ca, compute_ov) \
b5a73f8d 876static void glue(gen_, name)(DisasContext *ctx) \
74637406 877{ \
b5a73f8d 878 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
879 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
880 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 881 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
882 tcg_temp_free(t0); \
883}
884
885/* add add. addo addo. */
886GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
887GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
888/* addc addc. addco addco. */
889GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
890GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
891/* adde adde. addeo addeo. */
892GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
893GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
894/* addme addme. addmeo addmeo. */
895GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
896GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
897/* addze addze. addzeo addzeo.*/
898GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
899GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
900/* addi */
99e300ef 901static void gen_addi(DisasContext *ctx)
d9bce9d9 902{
74637406
AJ
903 target_long simm = SIMM(ctx->opcode);
904
905 if (rA(ctx->opcode) == 0) {
906 /* li case */
907 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
908 } else {
b5a73f8d
RH
909 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
910 cpu_gpr[rA(ctx->opcode)], simm);
74637406 911 }
d9bce9d9 912}
74637406 913/* addic addic.*/
b5a73f8d 914static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 915{
b5a73f8d
RH
916 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
917 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
918 c, 0, 1, 0, compute_rc0);
919 tcg_temp_free(c);
d9bce9d9 920}
99e300ef
BS
921
922static void gen_addic(DisasContext *ctx)
d9bce9d9 923{
b5a73f8d 924 gen_op_addic(ctx, 0);
d9bce9d9 925}
e8eaa2c0
BS
926
927static void gen_addic_(DisasContext *ctx)
d9bce9d9 928{
b5a73f8d 929 gen_op_addic(ctx, 1);
d9bce9d9 930}
99e300ef 931
54623277 932/* addis */
99e300ef 933static void gen_addis(DisasContext *ctx)
d9bce9d9 934{
74637406
AJ
935 target_long simm = SIMM(ctx->opcode);
936
937 if (rA(ctx->opcode) == 0) {
938 /* lis case */
939 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
940 } else {
b5a73f8d
RH
941 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
942 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 943 }
d9bce9d9 944}
74637406 945
636aa200
BS
946static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
947 TCGv arg2, int sign, int compute_ov)
d9bce9d9 948{
2ef1b120
AJ
949 int l1 = gen_new_label();
950 int l2 = gen_new_label();
a7812ae4
PB
951 TCGv_i32 t0 = tcg_temp_local_new_i32();
952 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 953
2ef1b120
AJ
954 tcg_gen_trunc_tl_i32(t0, arg1);
955 tcg_gen_trunc_tl_i32(t1, arg2);
956 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 957 if (sign) {
2ef1b120
AJ
958 int l3 = gen_new_label();
959 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
960 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 961 gen_set_label(l3);
2ef1b120 962 tcg_gen_div_i32(t0, t0, t1);
74637406 963 } else {
2ef1b120 964 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
965 }
966 if (compute_ov) {
da91a00f 967 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
968 }
969 tcg_gen_br(l2);
970 gen_set_label(l1);
971 if (sign) {
2ef1b120 972 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
973 } else {
974 tcg_gen_movi_i32(t0, 0);
975 }
976 if (compute_ov) {
da91a00f
RH
977 tcg_gen_movi_tl(cpu_ov, 1);
978 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
979 }
980 gen_set_label(l2);
2ef1b120 981 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
982 tcg_temp_free_i32(t0);
983 tcg_temp_free_i32(t1);
74637406
AJ
984 if (unlikely(Rc(ctx->opcode) != 0))
985 gen_set_Rc0(ctx, ret);
d9bce9d9 986}
74637406
AJ
987/* Div functions */
988#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 989static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
990{ \
991 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
992 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
993 sign, compute_ov); \
994}
995/* divwu divwu. divwuo divwuo. */
996GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
997GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
998/* divw divw. divwo divwo. */
999GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1000GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
98d1eb27
TM
1001
1002/* div[wd]eu[o][.] */
1003#define GEN_DIVE(name, hlpr, compute_ov) \
1004static void gen_##name(DisasContext *ctx) \
1005{ \
1006 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1007 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1008 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1009 tcg_temp_free_i32(t0); \
1010 if (unlikely(Rc(ctx->opcode) != 0)) { \
1011 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1012 } \
1013}
1014
6a4fda33
TM
1015GEN_DIVE(divweu, divweu, 0);
1016GEN_DIVE(divweuo, divweu, 1);
a98eb9e9
TM
1017GEN_DIVE(divwe, divwe, 0);
1018GEN_DIVE(divweo, divwe, 1);
6a4fda33 1019
d9bce9d9 1020#if defined(TARGET_PPC64)
636aa200
BS
1021static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1022 TCGv arg2, int sign, int compute_ov)
d9bce9d9 1023{
2ef1b120
AJ
1024 int l1 = gen_new_label();
1025 int l2 = gen_new_label();
74637406
AJ
1026
1027 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1028 if (sign) {
2ef1b120 1029 int l3 = gen_new_label();
74637406
AJ
1030 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1031 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1032 gen_set_label(l3);
74637406
AJ
1033 tcg_gen_div_i64(ret, arg1, arg2);
1034 } else {
1035 tcg_gen_divu_i64(ret, arg1, arg2);
1036 }
1037 if (compute_ov) {
da91a00f 1038 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
1039 }
1040 tcg_gen_br(l2);
1041 gen_set_label(l1);
1042 if (sign) {
1043 tcg_gen_sari_i64(ret, arg1, 63);
1044 } else {
1045 tcg_gen_movi_i64(ret, 0);
1046 }
1047 if (compute_ov) {
da91a00f
RH
1048 tcg_gen_movi_tl(cpu_ov, 1);
1049 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1050 }
1051 gen_set_label(l2);
1052 if (unlikely(Rc(ctx->opcode) != 0))
1053 gen_set_Rc0(ctx, ret);
d9bce9d9 1054}
74637406 1055#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 1056static void glue(gen_, name)(DisasContext *ctx) \
74637406 1057{ \
2ef1b120
AJ
1058 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1059 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1060 sign, compute_ov); \
74637406
AJ
1061}
1062/* divwu divwu. divwuo divwuo. */
1063GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1064GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1065/* divw divw. divwo divwo. */
1066GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1067GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
98d1eb27
TM
1068
1069GEN_DIVE(divdeu, divdeu, 0);
1070GEN_DIVE(divdeuo, divdeu, 1);
e44259b6
TM
1071GEN_DIVE(divde, divde, 0);
1072GEN_DIVE(divdeo, divde, 1);
d9bce9d9 1073#endif
74637406
AJ
1074
1075/* mulhw mulhw. */
99e300ef 1076static void gen_mulhw(DisasContext *ctx)
d9bce9d9 1077{
23ad1d5d
RH
1078 TCGv_i32 t0 = tcg_temp_new_i32();
1079 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1080
23ad1d5d
RH
1081 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1082 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1083 tcg_gen_muls2_i32(t0, t1, t0, t1);
1084 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1085 tcg_temp_free_i32(t0);
1086 tcg_temp_free_i32(t1);
74637406
AJ
1087 if (unlikely(Rc(ctx->opcode) != 0))
1088 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1089}
99e300ef 1090
54623277 1091/* mulhwu mulhwu. */
99e300ef 1092static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1093{
23ad1d5d
RH
1094 TCGv_i32 t0 = tcg_temp_new_i32();
1095 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1096
23ad1d5d
RH
1097 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1098 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1099 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1100 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1101 tcg_temp_free_i32(t0);
1102 tcg_temp_free_i32(t1);
74637406
AJ
1103 if (unlikely(Rc(ctx->opcode) != 0))
1104 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1105}
99e300ef 1106
54623277 1107/* mullw mullw. */
99e300ef 1108static void gen_mullw(DisasContext *ctx)
d9bce9d9 1109{
74637406
AJ
1110 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1111 cpu_gpr[rB(ctx->opcode)]);
1e4c090f 1112 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
74637406
AJ
1113 if (unlikely(Rc(ctx->opcode) != 0))
1114 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1115}
99e300ef 1116
54623277 1117/* mullwo mullwo. */
99e300ef 1118static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1119{
e4a2c846
RH
1120 TCGv_i32 t0 = tcg_temp_new_i32();
1121 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1122
e4a2c846
RH
1123 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1124 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1125 tcg_gen_muls2_i32(t0, t1, t0, t1);
1126 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1127
1128 tcg_gen_sari_i32(t0, t0, 31);
1129 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1130 tcg_gen_extu_i32_tl(cpu_ov, t0);
1131 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1132
1133 tcg_temp_free_i32(t0);
1134 tcg_temp_free_i32(t1);
74637406
AJ
1135 if (unlikely(Rc(ctx->opcode) != 0))
1136 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1137}
99e300ef 1138
54623277 1139/* mulli */
99e300ef 1140static void gen_mulli(DisasContext *ctx)
d9bce9d9 1141{
74637406
AJ
1142 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1143 SIMM(ctx->opcode));
d9bce9d9 1144}
23ad1d5d 1145
d9bce9d9 1146#if defined(TARGET_PPC64)
74637406 1147/* mulhd mulhd. */
23ad1d5d
RH
1148static void gen_mulhd(DisasContext *ctx)
1149{
1150 TCGv lo = tcg_temp_new();
1151 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1152 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1153 tcg_temp_free(lo);
1154 if (unlikely(Rc(ctx->opcode) != 0)) {
1155 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1156 }
1157}
1158
74637406 1159/* mulhdu mulhdu. */
23ad1d5d
RH
1160static void gen_mulhdu(DisasContext *ctx)
1161{
1162 TCGv lo = tcg_temp_new();
1163 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1164 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1165 tcg_temp_free(lo);
1166 if (unlikely(Rc(ctx->opcode) != 0)) {
1167 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1168 }
1169}
99e300ef 1170
54623277 1171/* mulld mulld. */
99e300ef 1172static void gen_mulld(DisasContext *ctx)
d9bce9d9 1173{
74637406
AJ
1174 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1175 cpu_gpr[rB(ctx->opcode)]);
1176 if (unlikely(Rc(ctx->opcode) != 0))
1177 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1178}
d15f74fb 1179
74637406 1180/* mulldo mulldo. */
d15f74fb
BS
1181static void gen_mulldo(DisasContext *ctx)
1182{
1183 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1184 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1185 if (unlikely(Rc(ctx->opcode) != 0)) {
1186 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1187 }
1188}
d9bce9d9 1189#endif
74637406 1190
74637406 1191/* Common subf function */
636aa200 1192static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1193 TCGv arg2, bool add_ca, bool compute_ca,
1194 bool compute_ov, bool compute_rc0)
79aceca5 1195{
b5a73f8d 1196 TCGv t0 = ret;
79aceca5 1197
752d634e 1198 if (compute_ca || compute_ov) {
b5a73f8d 1199 t0 = tcg_temp_new();
da91a00f 1200 }
74637406 1201
79482e5a
RH
1202 if (compute_ca) {
1203 /* dest = ~arg1 + arg2 [+ ca]. */
1204 if (NARROW_MODE(ctx)) {
752d634e
RH
1205 /* Caution: a non-obvious corner case of the spec is that we
1206 must produce the *entire* 64-bit addition, but produce the
1207 carry into bit 32. */
79482e5a 1208 TCGv inv1 = tcg_temp_new();
752d634e 1209 TCGv t1 = tcg_temp_new();
79482e5a 1210 tcg_gen_not_tl(inv1, arg1);
79482e5a 1211 if (add_ca) {
752d634e 1212 tcg_gen_add_tl(t0, arg2, cpu_ca);
79482e5a 1213 } else {
752d634e 1214 tcg_gen_addi_tl(t0, arg2, 1);
79482e5a 1215 }
752d634e 1216 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
79482e5a 1217 tcg_gen_add_tl(t0, t0, inv1);
752d634e
RH
1218 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1219 tcg_temp_free(t1);
1220 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1221 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
79482e5a 1222 } else if (add_ca) {
08f4a0f7
RH
1223 TCGv zero, inv1 = tcg_temp_new();
1224 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1225 zero = tcg_const_tl(0);
1226 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1227 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1228 tcg_temp_free(zero);
08f4a0f7 1229 tcg_temp_free(inv1);
b5a73f8d 1230 } else {
79482e5a 1231 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
b5a73f8d 1232 tcg_gen_sub_tl(t0, arg2, arg1);
b5a73f8d 1233 }
79482e5a
RH
1234 } else if (add_ca) {
1235 /* Since we're ignoring carry-out, we can simplify the
1236 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1237 tcg_gen_sub_tl(t0, arg2, arg1);
1238 tcg_gen_add_tl(t0, t0, cpu_ca);
1239 tcg_gen_subi_tl(t0, t0, 1);
79aceca5 1240 } else {
b5a73f8d 1241 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1242 }
b5a73f8d 1243
74637406
AJ
1244 if (compute_ov) {
1245 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1246 }
b5a73f8d 1247 if (unlikely(compute_rc0)) {
74637406 1248 gen_set_Rc0(ctx, t0);
b5a73f8d 1249 }
74637406 1250
a7812ae4 1251 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1252 tcg_gen_mov_tl(ret, t0);
1253 tcg_temp_free(t0);
79aceca5 1254 }
79aceca5 1255}
74637406
AJ
1256/* Sub functions with Two operands functions */
1257#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1258static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1259{ \
1260 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1261 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1262 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1263}
1264/* Sub functions with one operand and one immediate */
1265#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1266 add_ca, compute_ca, compute_ov) \
b5a73f8d 1267static void glue(gen_, name)(DisasContext *ctx) \
74637406 1268{ \
b5a73f8d 1269 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1270 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1271 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1272 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1273 tcg_temp_free(t0); \
1274}
1275/* subf subf. subfo subfo. */
1276GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1277GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1278/* subfc subfc. subfco subfco. */
1279GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1280GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1281/* subfe subfe. subfeo subfo. */
1282GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1283GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1284/* subfme subfme. subfmeo subfmeo. */
1285GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1286GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1287/* subfze subfze. subfzeo subfzeo.*/
1288GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1289GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1290
54623277 1291/* subfic */
99e300ef 1292static void gen_subfic(DisasContext *ctx)
79aceca5 1293{
b5a73f8d
RH
1294 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1295 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1296 c, 0, 1, 0, 0);
1297 tcg_temp_free(c);
79aceca5
FB
1298}
1299
fd3f0081
RH
1300/* neg neg. nego nego. */
1301static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1302{
1303 TCGv zero = tcg_const_tl(0);
1304 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1305 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1306 tcg_temp_free(zero);
1307}
1308
1309static void gen_neg(DisasContext *ctx)
1310{
1311 gen_op_arith_neg(ctx, 0);
1312}
1313
1314static void gen_nego(DisasContext *ctx)
1315{
1316 gen_op_arith_neg(ctx, 1);
1317}
1318
79aceca5 1319/*** Integer logical ***/
26d67362 1320#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1321static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1322{ \
26d67362
AJ
1323 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1324 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1325 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1326 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1327}
79aceca5 1328
26d67362 1329#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1330static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1331{ \
26d67362 1332 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1333 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1334 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1335}
1336
1337/* and & and. */
26d67362 1338GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1339/* andc & andc. */
26d67362 1340GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1341
54623277 1342/* andi. */
e8eaa2c0 1343static void gen_andi_(DisasContext *ctx)
79aceca5 1344{
26d67362
AJ
1345 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1346 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1347}
e8eaa2c0 1348
54623277 1349/* andis. */
e8eaa2c0 1350static void gen_andis_(DisasContext *ctx)
79aceca5 1351{
26d67362
AJ
1352 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1353 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1354}
99e300ef 1355
54623277 1356/* cntlzw */
99e300ef 1357static void gen_cntlzw(DisasContext *ctx)
26d67362 1358{
a7812ae4 1359 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1360 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1361 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1362}
79aceca5 1363/* eqv & eqv. */
26d67362 1364GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1365/* extsb & extsb. */
26d67362 1366GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1367/* extsh & extsh. */
26d67362 1368GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1369/* nand & nand. */
26d67362 1370GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1371/* nor & nor. */
26d67362 1372GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1373
54623277 1374/* or & or. */
99e300ef 1375static void gen_or(DisasContext *ctx)
9a64fbe4 1376{
76a66253
JM
1377 int rs, ra, rb;
1378
1379 rs = rS(ctx->opcode);
1380 ra = rA(ctx->opcode);
1381 rb = rB(ctx->opcode);
1382 /* Optimisation for mr. ri case */
1383 if (rs != ra || rs != rb) {
26d67362
AJ
1384 if (rs != rb)
1385 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1386 else
1387 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1388 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1389 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1390 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1391 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1392#if defined(TARGET_PPC64)
1393 } else {
26d67362
AJ
1394 int prio = 0;
1395
c80f84e3
JM
1396 switch (rs) {
1397 case 1:
1398 /* Set process priority to low */
26d67362 1399 prio = 2;
c80f84e3
JM
1400 break;
1401 case 6:
1402 /* Set process priority to medium-low */
26d67362 1403 prio = 3;
c80f84e3
JM
1404 break;
1405 case 2:
1406 /* Set process priority to normal */
26d67362 1407 prio = 4;
c80f84e3 1408 break;
be147d08
JM
1409#if !defined(CONFIG_USER_ONLY)
1410 case 31:
76db3ba4 1411 if (ctx->mem_idx > 0) {
be147d08 1412 /* Set process priority to very low */
26d67362 1413 prio = 1;
be147d08
JM
1414 }
1415 break;
1416 case 5:
76db3ba4 1417 if (ctx->mem_idx > 0) {
be147d08 1418 /* Set process priority to medium-hight */
26d67362 1419 prio = 5;
be147d08
JM
1420 }
1421 break;
1422 case 3:
76db3ba4 1423 if (ctx->mem_idx > 0) {
be147d08 1424 /* Set process priority to high */
26d67362 1425 prio = 6;
be147d08
JM
1426 }
1427 break;
be147d08 1428 case 7:
76db3ba4 1429 if (ctx->mem_idx > 1) {
be147d08 1430 /* Set process priority to very high */
26d67362 1431 prio = 7;
be147d08
JM
1432 }
1433 break;
be147d08 1434#endif
c80f84e3
JM
1435 default:
1436 /* nop */
1437 break;
1438 }
26d67362 1439 if (prio) {
a7812ae4 1440 TCGv t0 = tcg_temp_new();
54cdcae6 1441 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1442 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1443 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1444 gen_store_spr(SPR_PPR, t0);
ea363694 1445 tcg_temp_free(t0);
26d67362 1446 }
c80f84e3 1447#endif
9a64fbe4 1448 }
9a64fbe4 1449}
79aceca5 1450/* orc & orc. */
26d67362 1451GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1452
54623277 1453/* xor & xor. */
99e300ef 1454static void gen_xor(DisasContext *ctx)
9a64fbe4 1455{
9a64fbe4 1456 /* Optimisation for "set to zero" case */
26d67362 1457 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1458 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1459 else
1460 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1461 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1462 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1463}
99e300ef 1464
54623277 1465/* ori */
99e300ef 1466static void gen_ori(DisasContext *ctx)
79aceca5 1467{
76a66253 1468 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1469
9a64fbe4
FB
1470 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1471 /* NOP */
76a66253 1472 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1473 return;
76a66253 1474 }
26d67362 1475 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1476}
99e300ef 1477
54623277 1478/* oris */
99e300ef 1479static void gen_oris(DisasContext *ctx)
79aceca5 1480{
76a66253 1481 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1482
9a64fbe4
FB
1483 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1484 /* NOP */
1485 return;
76a66253 1486 }
26d67362 1487 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1488}
99e300ef 1489
54623277 1490/* xori */
99e300ef 1491static void gen_xori(DisasContext *ctx)
79aceca5 1492{
76a66253 1493 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1494
1495 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1496 /* NOP */
1497 return;
1498 }
26d67362 1499 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1500}
99e300ef 1501
54623277 1502/* xoris */
99e300ef 1503static void gen_xoris(DisasContext *ctx)
79aceca5 1504{
76a66253 1505 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1506
1507 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1508 /* NOP */
1509 return;
1510 }
26d67362 1511 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1512}
99e300ef 1513
54623277 1514/* popcntb : PowerPC 2.03 specification */
99e300ef 1515static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1516{
eaabeef2
DG
1517 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1518}
1519
1520static void gen_popcntw(DisasContext *ctx)
1521{
1522 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1523}
1524
d9bce9d9 1525#if defined(TARGET_PPC64)
eaabeef2
DG
1526/* popcntd: PowerPC 2.06 specification */
1527static void gen_popcntd(DisasContext *ctx)
1528{
1529 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1530}
eaabeef2 1531#endif
d9bce9d9 1532
725bcec2
AJ
1533/* prtyw: PowerPC 2.05 specification */
1534static void gen_prtyw(DisasContext *ctx)
1535{
1536 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1537 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1538 TCGv t0 = tcg_temp_new();
1539 tcg_gen_shri_tl(t0, rs, 16);
1540 tcg_gen_xor_tl(ra, rs, t0);
1541 tcg_gen_shri_tl(t0, ra, 8);
1542 tcg_gen_xor_tl(ra, ra, t0);
1543 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1544 tcg_temp_free(t0);
1545}
1546
1547#if defined(TARGET_PPC64)
1548/* prtyd: PowerPC 2.05 specification */
1549static void gen_prtyd(DisasContext *ctx)
1550{
1551 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1552 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1553 TCGv t0 = tcg_temp_new();
1554 tcg_gen_shri_tl(t0, rs, 32);
1555 tcg_gen_xor_tl(ra, rs, t0);
1556 tcg_gen_shri_tl(t0, ra, 16);
1557 tcg_gen_xor_tl(ra, ra, t0);
1558 tcg_gen_shri_tl(t0, ra, 8);
1559 tcg_gen_xor_tl(ra, ra, t0);
1560 tcg_gen_andi_tl(ra, ra, 1);
1561 tcg_temp_free(t0);
1562}
1563#endif
1564
86ba37ed
TM
1565#if defined(TARGET_PPC64)
1566/* bpermd */
1567static void gen_bpermd(DisasContext *ctx)
1568{
1569 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1570 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1571}
1572#endif
1573
d9bce9d9
JM
1574#if defined(TARGET_PPC64)
1575/* extsw & extsw. */
26d67362 1576GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1577
54623277 1578/* cntlzd */
99e300ef 1579static void gen_cntlzd(DisasContext *ctx)
26d67362 1580{
a7812ae4 1581 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1582 if (unlikely(Rc(ctx->opcode) != 0))
1583 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1584}
d9bce9d9
JM
1585#endif
1586
79aceca5 1587/*** Integer rotate ***/
99e300ef 1588
54623277 1589/* rlwimi & rlwimi. */
99e300ef 1590static void gen_rlwimi(DisasContext *ctx)
79aceca5 1591{
76a66253 1592 uint32_t mb, me, sh;
79aceca5
FB
1593
1594 mb = MB(ctx->opcode);
1595 me = ME(ctx->opcode);
76a66253 1596 sh = SH(ctx->opcode);
d03ef511
AJ
1597 if (likely(sh == 0 && mb == 0 && me == 31)) {
1598 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1599 } else {
d03ef511 1600 target_ulong mask;
a7812ae4
PB
1601 TCGv t1;
1602 TCGv t0 = tcg_temp_new();
54843a58 1603#if defined(TARGET_PPC64)
a7812ae4
PB
1604 TCGv_i32 t2 = tcg_temp_new_i32();
1605 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1606 tcg_gen_rotli_i32(t2, t2, sh);
1607 tcg_gen_extu_i32_i64(t0, t2);
1608 tcg_temp_free_i32(t2);
54843a58
AJ
1609#else
1610 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1611#endif
76a66253 1612#if defined(TARGET_PPC64)
d03ef511
AJ
1613 mb += 32;
1614 me += 32;
76a66253 1615#endif
d03ef511 1616 mask = MASK(mb, me);
a7812ae4 1617 t1 = tcg_temp_new();
d03ef511
AJ
1618 tcg_gen_andi_tl(t0, t0, mask);
1619 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1620 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1621 tcg_temp_free(t0);
1622 tcg_temp_free(t1);
1623 }
76a66253 1624 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1625 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1626}
99e300ef 1627
54623277 1628/* rlwinm & rlwinm. */
99e300ef 1629static void gen_rlwinm(DisasContext *ctx)
79aceca5
FB
1630{
1631 uint32_t mb, me, sh;
3b46e624 1632
79aceca5
FB
1633 sh = SH(ctx->opcode);
1634 mb = MB(ctx->opcode);
1635 me = ME(ctx->opcode);
d03ef511
AJ
1636
1637 if (likely(mb == 0 && me == (31 - sh))) {
1638 if (likely(sh == 0)) {
1639 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1640 } else {
a7812ae4 1641 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1642 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1643 tcg_gen_shli_tl(t0, t0, sh);
1644 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1645 tcg_temp_free(t0);
79aceca5 1646 }
d03ef511 1647 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
a7812ae4 1648 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1649 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1650 tcg_gen_shri_tl(t0, t0, mb);
1651 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1652 tcg_temp_free(t0);
1653 } else {
a7812ae4 1654 TCGv t0 = tcg_temp_new();
54843a58 1655#if defined(TARGET_PPC64)
a7812ae4 1656 TCGv_i32 t1 = tcg_temp_new_i32();
54843a58
AJ
1657 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1658 tcg_gen_rotli_i32(t1, t1, sh);
1659 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4 1660 tcg_temp_free_i32(t1);
54843a58
AJ
1661#else
1662 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1663#endif
76a66253 1664#if defined(TARGET_PPC64)
d03ef511
AJ
1665 mb += 32;
1666 me += 32;
76a66253 1667#endif
d03ef511
AJ
1668 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1669 tcg_temp_free(t0);
1670 }
76a66253 1671 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1672 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1673}
99e300ef 1674
54623277 1675/* rlwnm & rlwnm. */
99e300ef 1676static void gen_rlwnm(DisasContext *ctx)
79aceca5
FB
1677{
1678 uint32_t mb, me;
54843a58
AJ
1679 TCGv t0;
1680#if defined(TARGET_PPC64)
a7812ae4 1681 TCGv_i32 t1, t2;
54843a58 1682#endif
79aceca5
FB
1683
1684 mb = MB(ctx->opcode);
1685 me = ME(ctx->opcode);
a7812ae4 1686 t0 = tcg_temp_new();
d03ef511 1687 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
54843a58 1688#if defined(TARGET_PPC64)
a7812ae4
PB
1689 t1 = tcg_temp_new_i32();
1690 t2 = tcg_temp_new_i32();
54843a58
AJ
1691 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1692 tcg_gen_trunc_i64_i32(t2, t0);
1693 tcg_gen_rotl_i32(t1, t1, t2);
1694 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4
PB
1695 tcg_temp_free_i32(t1);
1696 tcg_temp_free_i32(t2);
54843a58
AJ
1697#else
1698 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1699#endif
76a66253
JM
1700 if (unlikely(mb != 0 || me != 31)) {
1701#if defined(TARGET_PPC64)
1702 mb += 32;
1703 me += 32;
1704#endif
54843a58 1705 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
d03ef511 1706 } else {
54843a58 1707 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
79aceca5 1708 }
54843a58 1709 tcg_temp_free(t0);
76a66253 1710 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1711 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5
FB
1712}
1713
d9bce9d9
JM
1714#if defined(TARGET_PPC64)
1715#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1716static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1717{ \
1718 gen_##name(ctx, 0); \
1719} \
e8eaa2c0
BS
1720 \
1721static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1722{ \
1723 gen_##name(ctx, 1); \
1724}
1725#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1726static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1727{ \
1728 gen_##name(ctx, 0, 0); \
1729} \
e8eaa2c0
BS
1730 \
1731static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1732{ \
1733 gen_##name(ctx, 0, 1); \
1734} \
e8eaa2c0
BS
1735 \
1736static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1737{ \
1738 gen_##name(ctx, 1, 0); \
1739} \
e8eaa2c0
BS
1740 \
1741static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1742{ \
1743 gen_##name(ctx, 1, 1); \
1744}
51789c41 1745
636aa200
BS
1746static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1747 uint32_t sh)
51789c41 1748{
d03ef511
AJ
1749 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1750 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1751 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1752 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1753 } else {
a7812ae4 1754 TCGv t0 = tcg_temp_new();
54843a58 1755 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
d03ef511 1756 if (likely(mb == 0 && me == 63)) {
54843a58 1757 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
d03ef511
AJ
1758 } else {
1759 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
51789c41 1760 }
d03ef511 1761 tcg_temp_free(t0);
51789c41 1762 }
51789c41 1763 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1764 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
51789c41 1765}
d9bce9d9 1766/* rldicl - rldicl. */
636aa200 1767static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1768{
51789c41 1769 uint32_t sh, mb;
d9bce9d9 1770
9d53c753
JM
1771 sh = SH(ctx->opcode) | (shn << 5);
1772 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1773 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1774}
51789c41 1775GEN_PPC64_R4(rldicl, 0x1E, 0x00);
d9bce9d9 1776/* rldicr - rldicr. */
636aa200 1777static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1778{
51789c41 1779 uint32_t sh, me;
d9bce9d9 1780
9d53c753
JM
1781 sh = SH(ctx->opcode) | (shn << 5);
1782 me = MB(ctx->opcode) | (men << 5);
51789c41 1783 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1784}
51789c41 1785GEN_PPC64_R4(rldicr, 0x1E, 0x02);
d9bce9d9 1786/* rldic - rldic. */
636aa200 1787static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1788{
51789c41 1789 uint32_t sh, mb;
d9bce9d9 1790
9d53c753
JM
1791 sh = SH(ctx->opcode) | (shn << 5);
1792 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1793 gen_rldinm(ctx, mb, 63 - sh, sh);
1794}
1795GEN_PPC64_R4(rldic, 0x1E, 0x04);
1796
636aa200 1797static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
51789c41 1798{
54843a58 1799 TCGv t0;
d03ef511 1800
a7812ae4 1801 t0 = tcg_temp_new();
d03ef511 1802 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
54843a58 1803 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
51789c41 1804 if (unlikely(mb != 0 || me != 63)) {
54843a58
AJ
1805 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1806 } else {
1807 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1808 }
1809 tcg_temp_free(t0);
51789c41 1810 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1811 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1812}
51789c41 1813
d9bce9d9 1814/* rldcl - rldcl. */
636aa200 1815static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1816{
51789c41 1817 uint32_t mb;
d9bce9d9 1818
9d53c753 1819 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1820 gen_rldnm(ctx, mb, 63);
d9bce9d9 1821}
36081602 1822GEN_PPC64_R2(rldcl, 0x1E, 0x08);
d9bce9d9 1823/* rldcr - rldcr. */
636aa200 1824static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1825{
51789c41 1826 uint32_t me;
d9bce9d9 1827
9d53c753 1828 me = MB(ctx->opcode) | (men << 5);
51789c41 1829 gen_rldnm(ctx, 0, me);
d9bce9d9 1830}
36081602 1831GEN_PPC64_R2(rldcr, 0x1E, 0x09);
d9bce9d9 1832/* rldimi - rldimi. */
636aa200 1833static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1834{
271a916e 1835 uint32_t sh, mb, me;
d9bce9d9 1836
9d53c753
JM
1837 sh = SH(ctx->opcode) | (shn << 5);
1838 mb = MB(ctx->opcode) | (mbn << 5);
271a916e 1839 me = 63 - sh;
d03ef511
AJ
1840 if (unlikely(sh == 0 && mb == 0)) {
1841 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1842 } else {
1843 TCGv t0, t1;
1844 target_ulong mask;
1845
a7812ae4 1846 t0 = tcg_temp_new();
54843a58 1847 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
a7812ae4 1848 t1 = tcg_temp_new();
d03ef511
AJ
1849 mask = MASK(mb, me);
1850 tcg_gen_andi_tl(t0, t0, mask);
1851 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1852 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1853 tcg_temp_free(t0);
1854 tcg_temp_free(t1);
51789c41 1855 }
51789c41 1856 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1857 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1858}
36081602 1859GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1860#endif
1861
79aceca5 1862/*** Integer shift ***/
99e300ef 1863
54623277 1864/* slw & slw. */
99e300ef 1865static void gen_slw(DisasContext *ctx)
26d67362 1866{
7fd6bf7d 1867 TCGv t0, t1;
26d67362 1868
7fd6bf7d
AJ
1869 t0 = tcg_temp_new();
1870 /* AND rS with a mask that is 0 when rB >= 0x20 */
1871#if defined(TARGET_PPC64)
1872 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1873 tcg_gen_sari_tl(t0, t0, 0x3f);
1874#else
1875 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1876 tcg_gen_sari_tl(t0, t0, 0x1f);
1877#endif
1878 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1879 t1 = tcg_temp_new();
1880 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1881 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1882 tcg_temp_free(t1);
fea0c503 1883 tcg_temp_free(t0);
7fd6bf7d 1884 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1885 if (unlikely(Rc(ctx->opcode) != 0))
1886 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1887}
99e300ef 1888
54623277 1889/* sraw & sraw. */
99e300ef 1890static void gen_sraw(DisasContext *ctx)
26d67362 1891{
d15f74fb 1892 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1893 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1894 if (unlikely(Rc(ctx->opcode) != 0))
1895 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1896}
99e300ef 1897
54623277 1898/* srawi & srawi. */
99e300ef 1899static void gen_srawi(DisasContext *ctx)
79aceca5 1900{
26d67362 1901 int sh = SH(ctx->opcode);
ba4af3e4
RH
1902 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1903 TCGv src = cpu_gpr[rS(ctx->opcode)];
1904 if (sh == 0) {
1905 tcg_gen_mov_tl(dst, src);
da91a00f 1906 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1907 } else {
ba4af3e4
RH
1908 TCGv t0;
1909 tcg_gen_ext32s_tl(dst, src);
1910 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1911 t0 = tcg_temp_new();
1912 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1913 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1914 tcg_temp_free(t0);
1915 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1916 tcg_gen_sari_tl(dst, dst, sh);
1917 }
1918 if (unlikely(Rc(ctx->opcode) != 0)) {
1919 gen_set_Rc0(ctx, dst);
d9bce9d9 1920 }
79aceca5 1921}
99e300ef 1922
54623277 1923/* srw & srw. */
99e300ef 1924static void gen_srw(DisasContext *ctx)
26d67362 1925{
fea0c503 1926 TCGv t0, t1;
d9bce9d9 1927
7fd6bf7d
AJ
1928 t0 = tcg_temp_new();
1929 /* AND rS with a mask that is 0 when rB >= 0x20 */
1930#if defined(TARGET_PPC64)
1931 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1932 tcg_gen_sari_tl(t0, t0, 0x3f);
1933#else
1934 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1935 tcg_gen_sari_tl(t0, t0, 0x1f);
1936#endif
1937 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1938 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1939 t1 = tcg_temp_new();
7fd6bf7d
AJ
1940 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1941 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1942 tcg_temp_free(t1);
fea0c503 1943 tcg_temp_free(t0);
26d67362
AJ
1944 if (unlikely(Rc(ctx->opcode) != 0))
1945 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1946}
54623277 1947
d9bce9d9
JM
1948#if defined(TARGET_PPC64)
1949/* sld & sld. */
99e300ef 1950static void gen_sld(DisasContext *ctx)
26d67362 1951{
7fd6bf7d 1952 TCGv t0, t1;
26d67362 1953
7fd6bf7d
AJ
1954 t0 = tcg_temp_new();
1955 /* AND rS with a mask that is 0 when rB >= 0x40 */
1956 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1957 tcg_gen_sari_tl(t0, t0, 0x3f);
1958 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1959 t1 = tcg_temp_new();
1960 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1961 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1962 tcg_temp_free(t1);
fea0c503 1963 tcg_temp_free(t0);
26d67362
AJ
1964 if (unlikely(Rc(ctx->opcode) != 0))
1965 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1966}
99e300ef 1967
54623277 1968/* srad & srad. */
99e300ef 1969static void gen_srad(DisasContext *ctx)
26d67362 1970{
d15f74fb 1971 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1972 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1973 if (unlikely(Rc(ctx->opcode) != 0))
1974 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1975}
d9bce9d9 1976/* sradi & sradi. */
636aa200 1977static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1978{
26d67362 1979 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
1980 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1981 TCGv src = cpu_gpr[rS(ctx->opcode)];
1982 if (sh == 0) {
1983 tcg_gen_mov_tl(dst, src);
da91a00f 1984 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1985 } else {
ba4af3e4
RH
1986 TCGv t0;
1987 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1988 t0 = tcg_temp_new();
1989 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1990 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1991 tcg_temp_free(t0);
1992 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1993 tcg_gen_sari_tl(dst, src, sh);
1994 }
1995 if (unlikely(Rc(ctx->opcode) != 0)) {
1996 gen_set_Rc0(ctx, dst);
d9bce9d9 1997 }
d9bce9d9 1998}
e8eaa2c0
BS
1999
2000static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
2001{
2002 gen_sradi(ctx, 0);
2003}
e8eaa2c0
BS
2004
2005static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
2006{
2007 gen_sradi(ctx, 1);
2008}
99e300ef 2009
54623277 2010/* srd & srd. */
99e300ef 2011static void gen_srd(DisasContext *ctx)
26d67362 2012{
7fd6bf7d 2013 TCGv t0, t1;
26d67362 2014
7fd6bf7d
AJ
2015 t0 = tcg_temp_new();
2016 /* AND rS with a mask that is 0 when rB >= 0x40 */
2017 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2018 tcg_gen_sari_tl(t0, t0, 0x3f);
2019 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2020 t1 = tcg_temp_new();
2021 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2022 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2023 tcg_temp_free(t1);
fea0c503 2024 tcg_temp_free(t0);
26d67362
AJ
2025 if (unlikely(Rc(ctx->opcode) != 0))
2026 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2027}
d9bce9d9 2028#endif
79aceca5
FB
2029
2030/*** Floating-Point arithmetic ***/
7c58044c 2031#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 2032static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2033{ \
76a66253 2034 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2035 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2036 return; \
2037 } \
eb44b959
AJ
2038 /* NIP cannot be restored if the memory exception comes from an helper */ \
2039 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2040 gen_reset_fpstatus(); \
8e703949
BS
2041 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2042 cpu_fpr[rA(ctx->opcode)], \
af12906f 2043 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2044 if (isfloat) { \
8e703949
BS
2045 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2046 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2047 } \
af12906f
AJ
2048 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2049 Rc(ctx->opcode) != 0); \
9a64fbe4
FB
2050}
2051
7c58044c
JM
2052#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2053_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2054_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2055
7c58044c 2056#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2057static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2058{ \
76a66253 2059 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2060 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2061 return; \
2062 } \
eb44b959
AJ
2063 /* NIP cannot be restored if the memory exception comes from an helper */ \
2064 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2065 gen_reset_fpstatus(); \
8e703949
BS
2066 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2067 cpu_fpr[rA(ctx->opcode)], \
af12906f 2068 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2069 if (isfloat) { \
8e703949
BS
2070 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2071 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2072 } \
af12906f
AJ
2073 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2074 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2075}
7c58044c
JM
2076#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2077_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2078_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2079
7c58044c 2080#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2081static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2082{ \
76a66253 2083 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2084 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2085 return; \
2086 } \
eb44b959
AJ
2087 /* NIP cannot be restored if the memory exception comes from an helper */ \
2088 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2089 gen_reset_fpstatus(); \
8e703949
BS
2090 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2091 cpu_fpr[rA(ctx->opcode)], \
2092 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2093 if (isfloat) { \
8e703949
BS
2094 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2095 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2096 } \
af12906f
AJ
2097 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2098 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2099}
7c58044c
JM
2100#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2101_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2102_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2103
7c58044c 2104#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2105static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2106{ \
76a66253 2107 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2108 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2109 return; \
2110 } \
eb44b959
AJ
2111 /* NIP cannot be restored if the memory exception comes from an helper */ \
2112 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2113 gen_reset_fpstatus(); \
8e703949
BS
2114 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2115 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2116 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2117 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2118}
2119
7c58044c 2120#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2121static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2122{ \
76a66253 2123 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2124 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2125 return; \
2126 } \
eb44b959
AJ
2127 /* NIP cannot be restored if the memory exception comes from an helper */ \
2128 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2129 gen_reset_fpstatus(); \
8e703949
BS
2130 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2131 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2132 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2133 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2134}
2135
9a64fbe4 2136/* fadd - fadds */
7c58044c 2137GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2138/* fdiv - fdivs */
7c58044c 2139GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2140/* fmul - fmuls */
7c58044c 2141GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2142
d7e4b87e 2143/* fre */
7c58044c 2144GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2145
a750fc0b 2146/* fres */
7c58044c 2147GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2148
a750fc0b 2149/* frsqrte */
7c58044c
JM
2150GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2151
2152/* frsqrtes */
99e300ef 2153static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2154{
af12906f 2155 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2156 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2157 return;
2158 }
eb44b959
AJ
2159 /* NIP cannot be restored if the memory exception comes from an helper */
2160 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2161 gen_reset_fpstatus();
8e703949
BS
2162 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2163 cpu_fpr[rB(ctx->opcode)]);
2164 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2165 cpu_fpr[rD(ctx->opcode)]);
af12906f 2166 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
7c58044c 2167}
79aceca5 2168
a750fc0b 2169/* fsel */
7c58044c 2170_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2171/* fsub - fsubs */
7c58044c 2172GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2173/* Optional: */
99e300ef 2174
54623277 2175/* fsqrt */
99e300ef 2176static void gen_fsqrt(DisasContext *ctx)
c7d344af 2177{
76a66253 2178 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2179 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2180 return;
2181 }
eb44b959
AJ
2182 /* NIP cannot be restored if the memory exception comes from an helper */
2183 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2184 gen_reset_fpstatus();
8e703949
BS
2185 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2186 cpu_fpr[rB(ctx->opcode)]);
af12906f 2187 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
c7d344af 2188}
79aceca5 2189
99e300ef 2190static void gen_fsqrts(DisasContext *ctx)
79aceca5 2191{
76a66253 2192 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2193 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2194 return;
2195 }
eb44b959
AJ
2196 /* NIP cannot be restored if the memory exception comes from an helper */
2197 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2198 gen_reset_fpstatus();
8e703949
BS
2199 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2200 cpu_fpr[rB(ctx->opcode)]);
2201 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2202 cpu_fpr[rD(ctx->opcode)]);
af12906f 2203 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
79aceca5
FB
2204}
2205
2206/*** Floating-Point multiply-and-add ***/
4ecc3190 2207/* fmadd - fmadds */
7c58044c 2208GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2209/* fmsub - fmsubs */
7c58044c 2210GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2211/* fnmadd - fnmadds */
7c58044c 2212GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2213/* fnmsub - fnmsubs */
7c58044c 2214GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2215
2216/*** Floating-Point round & convert ***/
2217/* fctiw */
7c58044c 2218GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2219/* fctiwu */
2220GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2221/* fctiwz */
7c58044c 2222GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2223/* fctiwuz */
2224GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2225/* frsp */
7c58044c 2226GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db
JM
2227#if defined(TARGET_PPC64)
2228/* fcfid */
7c58044c 2229GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
28288b48
TM
2230/* fcfids */
2231GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2232/* fcfidu */
2233GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2234/* fcfidus */
2235GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
426613db 2236/* fctid */
7c58044c 2237GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
fab7fe42
TM
2238/* fctidu */
2239GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2240/* fctidz */
7c58044c 2241GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
fab7fe42
TM
2242/* fctidu */
2243GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2244#endif
79aceca5 2245
d7e4b87e 2246/* frin */
7c58044c 2247GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2248/* friz */
7c58044c 2249GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2250/* frip */
7c58044c 2251GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2252/* frim */
7c58044c 2253GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2254
da29cb7b
TM
2255static void gen_ftdiv(DisasContext *ctx)
2256{
2257 if (unlikely(!ctx->fpu_enabled)) {
2258 gen_exception(ctx, POWERPC_EXCP_FPU);
2259 return;
2260 }
2261 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2262 cpu_fpr[rB(ctx->opcode)]);
2263}
2264
6d41d146
TM
2265static void gen_ftsqrt(DisasContext *ctx)
2266{
2267 if (unlikely(!ctx->fpu_enabled)) {
2268 gen_exception(ctx, POWERPC_EXCP_FPU);
2269 return;
2270 }
2271 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2272}
2273
da29cb7b
TM
2274
2275
79aceca5 2276/*** Floating-Point compare ***/
99e300ef 2277
54623277 2278/* fcmpo */
99e300ef 2279static void gen_fcmpo(DisasContext *ctx)
79aceca5 2280{
330c483b 2281 TCGv_i32 crf;
76a66253 2282 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2283 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2284 return;
2285 }
eb44b959
AJ
2286 /* NIP cannot be restored if the memory exception comes from an helper */
2287 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2288 gen_reset_fpstatus();
9a819377 2289 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2290 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2291 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2292 tcg_temp_free_i32(crf);
8e703949 2293 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2294}
2295
2296/* fcmpu */
99e300ef 2297static void gen_fcmpu(DisasContext *ctx)
79aceca5 2298{
330c483b 2299 TCGv_i32 crf;
76a66253 2300 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2301 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2302 return;
2303 }
eb44b959
AJ
2304 /* NIP cannot be restored if the memory exception comes from an helper */
2305 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2306 gen_reset_fpstatus();
9a819377 2307 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2308 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2309 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2310 tcg_temp_free_i32(crf);
8e703949 2311 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2312}
2313
9a64fbe4
FB
2314/*** Floating-point move ***/
2315/* fabs */
7c58044c 2316/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2317static void gen_fabs(DisasContext *ctx)
2318{
2319 if (unlikely(!ctx->fpu_enabled)) {
2320 gen_exception(ctx, POWERPC_EXCP_FPU);
2321 return;
2322 }
2323 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2324 ~(1ULL << 63));
2325 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2326}
9a64fbe4
FB
2327
2328/* fmr - fmr. */
7c58044c 2329/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2330static void gen_fmr(DisasContext *ctx)
9a64fbe4 2331{
76a66253 2332 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2333 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2334 return;
2335 }
af12906f
AJ
2336 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2337 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
9a64fbe4
FB
2338}
2339
2340/* fnabs */
7c58044c 2341/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2342static void gen_fnabs(DisasContext *ctx)
2343{
2344 if (unlikely(!ctx->fpu_enabled)) {
2345 gen_exception(ctx, POWERPC_EXCP_FPU);
2346 return;
2347 }
2348 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2349 1ULL << 63);
2350 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2351}
2352
9a64fbe4 2353/* fneg */
7c58044c 2354/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2355static void gen_fneg(DisasContext *ctx)
2356{
2357 if (unlikely(!ctx->fpu_enabled)) {
2358 gen_exception(ctx, POWERPC_EXCP_FPU);
2359 return;
2360 }
2361 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2362 1ULL << 63);
2363 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2364}
9a64fbe4 2365
f0332888
AJ
2366/* fcpsgn: PowerPC 2.05 specification */
2367/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2368static void gen_fcpsgn(DisasContext *ctx)
2369{
2370 if (unlikely(!ctx->fpu_enabled)) {
2371 gen_exception(ctx, POWERPC_EXCP_FPU);
2372 return;
2373 }
2374 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2375 cpu_fpr[rB(ctx->opcode)], 0, 63);
2376 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2377}
2378
097ec5d8
TM
2379static void gen_fmrgew(DisasContext *ctx)
2380{
2381 TCGv_i64 b0;
2382 if (unlikely(!ctx->fpu_enabled)) {
2383 gen_exception(ctx, POWERPC_EXCP_FPU);
2384 return;
2385 }
2386 b0 = tcg_temp_new_i64();
2387 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2388 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2389 b0, 0, 32);
2390 tcg_temp_free_i64(b0);
2391}
2392
2393static void gen_fmrgow(DisasContext *ctx)
2394{
2395 if (unlikely(!ctx->fpu_enabled)) {
2396 gen_exception(ctx, POWERPC_EXCP_FPU);
2397 return;
2398 }
2399 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2400 cpu_fpr[rB(ctx->opcode)],
2401 cpu_fpr[rA(ctx->opcode)],
2402 32, 32);
2403}
2404
79aceca5 2405/*** Floating-Point status & ctrl register ***/
99e300ef 2406
54623277 2407/* mcrfs */
99e300ef 2408static void gen_mcrfs(DisasContext *ctx)
79aceca5 2409{
30304420 2410 TCGv tmp = tcg_temp_new();
7c58044c
JM
2411 int bfa;
2412
76a66253 2413 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2414 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2415 return;
2416 }
7c58044c 2417 bfa = 4 * (7 - crfS(ctx->opcode));
30304420
DG
2418 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2419 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2420 tcg_temp_free(tmp);
e1571908 2421 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
30304420 2422 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
79aceca5
FB
2423}
2424
2425/* mffs */
99e300ef 2426static void gen_mffs(DisasContext *ctx)
79aceca5 2427{
76a66253 2428 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2429 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2430 return;
2431 }
7c58044c 2432 gen_reset_fpstatus();
30304420 2433 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
af12906f 2434 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
79aceca5
FB
2435}
2436
2437/* mtfsb0 */
99e300ef 2438static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2439{
fb0eaffc 2440 uint8_t crb;
3b46e624 2441
76a66253 2442 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2443 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2444 return;
2445 }
6e35d524 2446 crb = 31 - crbD(ctx->opcode);
7c58044c 2447 gen_reset_fpstatus();
6e35d524 2448 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2449 TCGv_i32 t0;
2450 /* NIP cannot be restored if the memory exception comes from an helper */
2451 gen_update_nip(ctx, ctx->nip - 4);
2452 t0 = tcg_const_i32(crb);
8e703949 2453 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2454 tcg_temp_free_i32(t0);
2455 }
7c58044c 2456 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2457 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2458 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2459 }
79aceca5
FB
2460}
2461
2462/* mtfsb1 */
99e300ef 2463static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2464{
fb0eaffc 2465 uint8_t crb;
3b46e624 2466
76a66253 2467 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2468 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2469 return;
2470 }
6e35d524 2471 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2472 gen_reset_fpstatus();
2473 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2474 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2475 TCGv_i32 t0;
2476 /* NIP cannot be restored if the memory exception comes from an helper */
2477 gen_update_nip(ctx, ctx->nip - 4);
2478 t0 = tcg_const_i32(crb);
8e703949 2479 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2480 tcg_temp_free_i32(t0);
af12906f 2481 }
7c58044c 2482 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2483 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2484 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2485 }
2486 /* We can raise a differed exception */
8e703949 2487 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2488}
2489
2490/* mtfsf */
99e300ef 2491static void gen_mtfsf(DisasContext *ctx)
79aceca5 2492{
0f2f39c2 2493 TCGv_i32 t0;
7d08d856 2494 int flm, l, w;
af12906f 2495
76a66253 2496 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2497 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2498 return;
2499 }
7d08d856
AJ
2500 flm = FPFLM(ctx->opcode);
2501 l = FPL(ctx->opcode);
2502 w = FPW(ctx->opcode);
2503 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2504 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2505 return;
2506 }
eb44b959
AJ
2507 /* NIP cannot be restored if the memory exception comes from an helper */
2508 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2509 gen_reset_fpstatus();
7d08d856
AJ
2510 if (l) {
2511 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2512 } else {
2513 t0 = tcg_const_i32(flm << (w * 8));
2514 }
8e703949 2515 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2516 tcg_temp_free_i32(t0);
7c58044c 2517 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2518 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2519 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2520 }
2521 /* We can raise a differed exception */
8e703949 2522 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2523}
2524
2525/* mtfsfi */
99e300ef 2526static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2527{
7d08d856 2528 int bf, sh, w;
0f2f39c2
AJ
2529 TCGv_i64 t0;
2530 TCGv_i32 t1;
7c58044c 2531
76a66253 2532 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2533 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2534 return;
2535 }
7d08d856
AJ
2536 w = FPW(ctx->opcode);
2537 bf = FPBF(ctx->opcode);
2538 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2539 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2540 return;
2541 }
2542 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2543 /* NIP cannot be restored if the memory exception comes from an helper */
2544 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2545 gen_reset_fpstatus();
7d08d856 2546 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2547 t1 = tcg_const_i32(1 << sh);
8e703949 2548 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2549 tcg_temp_free_i64(t0);
2550 tcg_temp_free_i32(t1);
7c58044c 2551 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2552 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2553 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2554 }
2555 /* We can raise a differed exception */
8e703949 2556 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2557}
2558
76a66253
JM
2559/*** Addressing modes ***/
2560/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2561static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2562 target_long maskl)
76a66253
JM
2563{
2564 target_long simm = SIMM(ctx->opcode);
2565
be147d08 2566 simm &= ~maskl;
76db3ba4 2567 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2568 if (NARROW_MODE(ctx)) {
2569 simm = (uint32_t)simm;
2570 }
e2be8d8d 2571 tcg_gen_movi_tl(EA, simm);
76db3ba4 2572 } else if (likely(simm != 0)) {
e2be8d8d 2573 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2574 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2575 tcg_gen_ext32u_tl(EA, EA);
2576 }
76db3ba4 2577 } else {
c791fe84 2578 if (NARROW_MODE(ctx)) {
76db3ba4 2579 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2580 } else {
2581 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2582 }
76db3ba4 2583 }
76a66253
JM
2584}
2585
636aa200 2586static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2587{
76db3ba4 2588 if (rA(ctx->opcode) == 0) {
c791fe84 2589 if (NARROW_MODE(ctx)) {
76db3ba4 2590 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2591 } else {
2592 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2593 }
76db3ba4 2594 } else {
e2be8d8d 2595 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2596 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2597 tcg_gen_ext32u_tl(EA, EA);
2598 }
76db3ba4 2599 }
76a66253
JM
2600}
2601
636aa200 2602static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2603{
76db3ba4 2604 if (rA(ctx->opcode) == 0) {
e2be8d8d 2605 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2606 } else if (NARROW_MODE(ctx)) {
2607 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2608 } else {
c791fe84 2609 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2610 }
2611}
2612
636aa200
BS
2613static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2614 target_long val)
76db3ba4
AJ
2615{
2616 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2617 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2618 tcg_gen_ext32u_tl(ret, ret);
2619 }
76a66253
JM
2620}
2621
636aa200 2622static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32
AJ
2623{
2624 int l1 = gen_new_label();
2625 TCGv t0 = tcg_temp_new();
2626 TCGv_i32 t1, t2;
2627 /* NIP cannot be restored if the memory exception comes from an helper */
2628 gen_update_nip(ctx, ctx->nip - 4);
2629 tcg_gen_andi_tl(t0, EA, mask);
2630 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2631 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2632 t2 = tcg_const_i32(0);
e5f17ac6 2633 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2634 tcg_temp_free_i32(t1);
2635 tcg_temp_free_i32(t2);
2636 gen_set_label(l1);
2637 tcg_temp_free(t0);
2638}
2639
7863667f 2640/*** Integer load ***/
636aa200 2641static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2642{
2643 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2644}
2645
636aa200 2646static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2647{
2648 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2649}
2650
636aa200 2651static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2652{
2653 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2654 if (unlikely(ctx->le_mode)) {
fa3966a3 2655 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2656 }
b61f2753
AJ
2657}
2658
636aa200 2659static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2660{
76db3ba4 2661 if (unlikely(ctx->le_mode)) {
76db3ba4 2662 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
fa3966a3 2663 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2664 tcg_gen_ext16s_tl(arg1, arg1);
76db3ba4
AJ
2665 } else {
2666 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2667 }
b61f2753
AJ
2668}
2669
636aa200 2670static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2671{
76db3ba4
AJ
2672 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2673 if (unlikely(ctx->le_mode)) {
fa3966a3 2674 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2675 }
b61f2753
AJ
2676}
2677
f976b09e
AG
2678static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2679{
2680 TCGv tmp = tcg_temp_new();
2681 gen_qemu_ld32u(ctx, tmp, addr);
2682 tcg_gen_extu_tl_i64(val, tmp);
2683 tcg_temp_free(tmp);
2684}
2685
636aa200 2686static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2687{
a457e7ee 2688 if (unlikely(ctx->le_mode)) {
76db3ba4 2689 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
fa3966a3
AJ
2690 tcg_gen_bswap32_tl(arg1, arg1);
2691 tcg_gen_ext32s_tl(arg1, arg1);
b61f2753 2692 } else
76db3ba4 2693 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2694}
2695
cac7f0ba
TM
2696static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2697{
2698 TCGv tmp = tcg_temp_new();
2699 gen_qemu_ld32s(ctx, tmp, addr);
2700 tcg_gen_ext_tl_i64(val, tmp);
2701 tcg_temp_free(tmp);
2702}
2703
636aa200 2704static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2705{
76db3ba4
AJ
2706 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2707 if (unlikely(ctx->le_mode)) {
66896cb8 2708 tcg_gen_bswap64_i64(arg1, arg1);
76db3ba4 2709 }
b61f2753
AJ
2710}
2711
636aa200 2712static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2713{
76db3ba4 2714 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2715}
2716
636aa200 2717static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2718{
76db3ba4 2719 if (unlikely(ctx->le_mode)) {
76db3ba4
AJ
2720 TCGv t0 = tcg_temp_new();
2721 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2722 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2723 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2724 tcg_temp_free(t0);
76db3ba4
AJ
2725 } else {
2726 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2727 }
b61f2753
AJ
2728}
2729
636aa200 2730static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2731{
76db3ba4 2732 if (unlikely(ctx->le_mode)) {
fa3966a3
AJ
2733 TCGv t0 = tcg_temp_new();
2734 tcg_gen_ext32u_tl(t0, arg1);
2735 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2736 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2737 tcg_temp_free(t0);
76db3ba4
AJ
2738 } else {
2739 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2740 }
b61f2753
AJ
2741}
2742
f976b09e
AG
2743static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2744{
2745 TCGv tmp = tcg_temp_new();
2746 tcg_gen_trunc_i64_tl(tmp, val);
2747 gen_qemu_st32(ctx, tmp, addr);
2748 tcg_temp_free(tmp);
2749}
2750
636aa200 2751static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2752{
76db3ba4 2753 if (unlikely(ctx->le_mode)) {
a7812ae4 2754 TCGv_i64 t0 = tcg_temp_new_i64();
66896cb8 2755 tcg_gen_bswap64_i64(t0, arg1);
76db3ba4 2756 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
a7812ae4 2757 tcg_temp_free_i64(t0);
b61f2753 2758 } else
76db3ba4 2759 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2760}
2761
0c8aacd4 2762#define GEN_LD(name, ldop, opc, type) \
99e300ef 2763static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2764{ \
76db3ba4
AJ
2765 TCGv EA; \
2766 gen_set_access_type(ctx, ACCESS_INT); \
2767 EA = tcg_temp_new(); \
2768 gen_addr_imm_index(ctx, EA, 0); \
2769 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2770 tcg_temp_free(EA); \
79aceca5
FB
2771}
2772
0c8aacd4 2773#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2774static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2775{ \
b61f2753 2776 TCGv EA; \
76a66253
JM
2777 if (unlikely(rA(ctx->opcode) == 0 || \
2778 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2779 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2780 return; \
9a64fbe4 2781 } \
76db3ba4 2782 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2783 EA = tcg_temp_new(); \
9d53c753 2784 if (type == PPC_64B) \
76db3ba4 2785 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2786 else \
76db3ba4
AJ
2787 gen_addr_imm_index(ctx, EA, 0); \
2788 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2789 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2790 tcg_temp_free(EA); \
79aceca5
FB
2791}
2792
0c8aacd4 2793#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2794static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2795{ \
b61f2753 2796 TCGv EA; \
76a66253
JM
2797 if (unlikely(rA(ctx->opcode) == 0 || \
2798 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2799 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2800 return; \
9a64fbe4 2801 } \
76db3ba4 2802 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2803 EA = tcg_temp_new(); \
76db3ba4
AJ
2804 gen_addr_reg_index(ctx, EA); \
2805 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2806 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2807 tcg_temp_free(EA); \
79aceca5
FB
2808}
2809
cd6e9320 2810#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2811static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2812{ \
76db3ba4
AJ
2813 TCGv EA; \
2814 gen_set_access_type(ctx, ACCESS_INT); \
2815 EA = tcg_temp_new(); \
2816 gen_addr_reg_index(ctx, EA); \
2817 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2818 tcg_temp_free(EA); \
79aceca5 2819}
cd6e9320
TH
2820#define GEN_LDX(name, ldop, opc2, opc3, type) \
2821 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2822
0c8aacd4
AJ
2823#define GEN_LDS(name, ldop, op, type) \
2824GEN_LD(name, ldop, op | 0x20, type); \
2825GEN_LDU(name, ldop, op | 0x21, type); \
2826GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2827GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2828
2829/* lbz lbzu lbzux lbzx */
0c8aacd4 2830GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2831/* lha lhau lhaux lhax */
0c8aacd4 2832GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2833/* lhz lhzu lhzux lhzx */
0c8aacd4 2834GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2835/* lwz lwzu lwzux lwzx */
0c8aacd4 2836GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2837#if defined(TARGET_PPC64)
d9bce9d9 2838/* lwaux */
0c8aacd4 2839GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2840/* lwax */
0c8aacd4 2841GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2842/* ldux */
0c8aacd4 2843GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2844/* ldx */
0c8aacd4 2845GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2846
2847static void gen_ld(DisasContext *ctx)
d9bce9d9 2848{
b61f2753 2849 TCGv EA;
d9bce9d9
JM
2850 if (Rc(ctx->opcode)) {
2851 if (unlikely(rA(ctx->opcode) == 0 ||
2852 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2853 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2854 return;
2855 }
2856 }
76db3ba4 2857 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2858 EA = tcg_temp_new();
76db3ba4 2859 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2860 if (ctx->opcode & 0x02) {
2861 /* lwa (lwau is undefined) */
76db3ba4 2862 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2863 } else {
2864 /* ld - ldu */
76db3ba4 2865 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2866 }
d9bce9d9 2867 if (Rc(ctx->opcode))
b61f2753
AJ
2868 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2869 tcg_temp_free(EA);
d9bce9d9 2870}
99e300ef 2871
54623277 2872/* lq */
99e300ef 2873static void gen_lq(DisasContext *ctx)
be147d08 2874{
be147d08 2875 int ra, rd;
b61f2753 2876 TCGv EA;
be147d08 2877
e0498daa
TM
2878 /* lq is a legal user mode instruction starting in ISA 2.07 */
2879 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2880 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2881
2882 if (!legal_in_user_mode && is_user_mode(ctx)) {
e06fcd75 2883 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2884 return;
2885 }
e0498daa
TM
2886
2887 if (!le_is_supported && ctx->le_mode) {
2888 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2889 return;
2890 }
2891
be147d08
JM
2892 ra = rA(ctx->opcode);
2893 rd = rD(ctx->opcode);
2894 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2895 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2896 return;
2897 }
e0498daa 2898
76db3ba4 2899 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2900 EA = tcg_temp_new();
76db3ba4 2901 gen_addr_imm_index(ctx, EA, 0x0F);
e0498daa
TM
2902
2903 if (unlikely(ctx->le_mode)) {
2904 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2905 gen_addr_add(ctx, EA, EA, 8);
2906 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2907 } else {
2908 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2909 gen_addr_add(ctx, EA, EA, 8);
2910 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2911 }
b61f2753 2912 tcg_temp_free(EA);
be147d08 2913}
d9bce9d9 2914#endif
79aceca5
FB
2915
2916/*** Integer store ***/
0c8aacd4 2917#define GEN_ST(name, stop, opc, type) \
99e300ef 2918static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2919{ \
76db3ba4
AJ
2920 TCGv EA; \
2921 gen_set_access_type(ctx, ACCESS_INT); \
2922 EA = tcg_temp_new(); \
2923 gen_addr_imm_index(ctx, EA, 0); \
2924 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2925 tcg_temp_free(EA); \
79aceca5
FB
2926}
2927
0c8aacd4 2928#define GEN_STU(name, stop, opc, type) \
99e300ef 2929static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2930{ \
b61f2753 2931 TCGv EA; \
76a66253 2932 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2933 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2934 return; \
9a64fbe4 2935 } \
76db3ba4 2936 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2937 EA = tcg_temp_new(); \
9d53c753 2938 if (type == PPC_64B) \
76db3ba4 2939 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2940 else \
76db3ba4
AJ
2941 gen_addr_imm_index(ctx, EA, 0); \
2942 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2943 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2944 tcg_temp_free(EA); \
79aceca5
FB
2945}
2946
0c8aacd4 2947#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2948static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2949{ \
b61f2753 2950 TCGv EA; \
76a66253 2951 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2952 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2953 return; \
9a64fbe4 2954 } \
76db3ba4 2955 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2956 EA = tcg_temp_new(); \
76db3ba4
AJ
2957 gen_addr_reg_index(ctx, EA); \
2958 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2959 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2960 tcg_temp_free(EA); \
79aceca5
FB
2961}
2962
cd6e9320
TH
2963#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2964static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2965{ \
76db3ba4
AJ
2966 TCGv EA; \
2967 gen_set_access_type(ctx, ACCESS_INT); \
2968 EA = tcg_temp_new(); \
2969 gen_addr_reg_index(ctx, EA); \
2970 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2971 tcg_temp_free(EA); \
79aceca5 2972}
cd6e9320
TH
2973#define GEN_STX(name, stop, opc2, opc3, type) \
2974 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 2975
0c8aacd4
AJ
2976#define GEN_STS(name, stop, op, type) \
2977GEN_ST(name, stop, op | 0x20, type); \
2978GEN_STU(name, stop, op | 0x21, type); \
2979GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2980GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
2981
2982/* stb stbu stbux stbx */
0c8aacd4 2983GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 2984/* sth sthu sthux sthx */
0c8aacd4 2985GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 2986/* stw stwu stwux stwx */
0c8aacd4 2987GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 2988#if defined(TARGET_PPC64)
0c8aacd4
AJ
2989GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2990GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
2991
2992static void gen_std(DisasContext *ctx)
d9bce9d9 2993{
be147d08 2994 int rs;
b61f2753 2995 TCGv EA;
be147d08
JM
2996
2997 rs = rS(ctx->opcode);
2998 if ((ctx->opcode & 0x3) == 0x2) {
2999#if defined(CONFIG_USER_ONLY)
e06fcd75 3000 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3001#else
3002 /* stq */
76db3ba4 3003 if (unlikely(ctx->mem_idx == 0)) {
e06fcd75 3004 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3005 return;
3006 }
3007 if (unlikely(rs & 1)) {
e06fcd75 3008 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
3009 return;
3010 }
76db3ba4 3011 if (unlikely(ctx->le_mode)) {
be147d08 3012 /* Little-endian mode is not handled */
e06fcd75 3013 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
be147d08
JM
3014 return;
3015 }
76db3ba4 3016 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3017 EA = tcg_temp_new();
76db3ba4
AJ
3018 gen_addr_imm_index(ctx, EA, 0x03);
3019 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3020 gen_addr_add(ctx, EA, EA, 8);
3021 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
b61f2753 3022 tcg_temp_free(EA);
be147d08
JM
3023#endif
3024 } else {
3025 /* std / stdu */
3026 if (Rc(ctx->opcode)) {
3027 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 3028 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3029 return;
3030 }
3031 }
76db3ba4 3032 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3033 EA = tcg_temp_new();
76db3ba4
AJ
3034 gen_addr_imm_index(ctx, EA, 0x03);
3035 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 3036 if (Rc(ctx->opcode))
b61f2753
AJ
3037 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3038 tcg_temp_free(EA);
d9bce9d9 3039 }
d9bce9d9
JM
3040}
3041#endif
79aceca5
FB
3042/*** Integer load and store with byte reverse ***/
3043/* lhbrx */
86178a57 3044static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3045{
76db3ba4
AJ
3046 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
3047 if (likely(!ctx->le_mode)) {
fa3966a3 3048 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 3049 }
b61f2753 3050}
0c8aacd4 3051GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 3052
79aceca5 3053/* lwbrx */
86178a57 3054static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3055{
76db3ba4
AJ
3056 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
3057 if (likely(!ctx->le_mode)) {
fa3966a3 3058 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 3059 }
b61f2753 3060}
0c8aacd4 3061GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 3062
cd6e9320
TH
3063#if defined(TARGET_PPC64)
3064/* ldbrx */
3065static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3066{
3067 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
3068 if (likely(!ctx->le_mode)) {
3069 tcg_gen_bswap64_tl(arg1, arg1);
3070 }
3071}
3072GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3073#endif /* TARGET_PPC64 */
3074
79aceca5 3075/* sthbrx */
86178a57 3076static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3077{
76db3ba4 3078 if (likely(!ctx->le_mode)) {
76db3ba4
AJ
3079 TCGv t0 = tcg_temp_new();
3080 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 3081 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
3082 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
3083 tcg_temp_free(t0);
76db3ba4
AJ
3084 } else {
3085 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
3086 }
b61f2753 3087}
0c8aacd4 3088GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 3089
79aceca5 3090/* stwbrx */
86178a57 3091static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3092{
76db3ba4 3093 if (likely(!ctx->le_mode)) {
fa3966a3
AJ
3094 TCGv t0 = tcg_temp_new();
3095 tcg_gen_ext32u_tl(t0, arg1);
3096 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
3097 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
3098 tcg_temp_free(t0);
76db3ba4
AJ
3099 } else {
3100 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
3101 }
b61f2753 3102}
0c8aacd4 3103GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 3104
cd6e9320
TH
3105#if defined(TARGET_PPC64)
3106/* stdbrx */
3107static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3108{
3109 if (likely(!ctx->le_mode)) {
3110 TCGv t0 = tcg_temp_new();
3111 tcg_gen_bswap64_tl(t0, arg1);
3112 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
3113 tcg_temp_free(t0);
3114 } else {
3115 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
3116 }
3117}
3118GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3119#endif /* TARGET_PPC64 */
3120
79aceca5 3121/*** Integer load and store multiple ***/
99e300ef 3122
54623277 3123/* lmw */
99e300ef 3124static void gen_lmw(DisasContext *ctx)
79aceca5 3125{
76db3ba4
AJ
3126 TCGv t0;
3127 TCGv_i32 t1;
3128 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3129 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3130 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3131 t0 = tcg_temp_new();
3132 t1 = tcg_const_i32(rD(ctx->opcode));
3133 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3134 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3135 tcg_temp_free(t0);
3136 tcg_temp_free_i32(t1);
79aceca5
FB
3137}
3138
3139/* stmw */
99e300ef 3140static void gen_stmw(DisasContext *ctx)
79aceca5 3141{
76db3ba4
AJ
3142 TCGv t0;
3143 TCGv_i32 t1;
3144 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3145 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3146 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3147 t0 = tcg_temp_new();
3148 t1 = tcg_const_i32(rS(ctx->opcode));
3149 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3150 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3151 tcg_temp_free(t0);
3152 tcg_temp_free_i32(t1);
79aceca5
FB
3153}
3154
3155/*** Integer load and store strings ***/
54623277 3156
79aceca5 3157/* lswi */
3fc6c082 3158/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3159 * rA is in the range of registers to be loaded.
3160 * In an other hand, IBM says this is valid, but rA won't be loaded.
3161 * For now, I'll follow the spec...
3162 */
99e300ef 3163static void gen_lswi(DisasContext *ctx)
79aceca5 3164{
dfbc799d
AJ
3165 TCGv t0;
3166 TCGv_i32 t1, t2;
79aceca5
FB
3167 int nb = NB(ctx->opcode);
3168 int start = rD(ctx->opcode);
9a64fbe4 3169 int ra = rA(ctx->opcode);
79aceca5
FB
3170 int nr;
3171
3172 if (nb == 0)
3173 nb = 32;
3174 nr = nb / 4;
76a66253
JM
3175 if (unlikely(((start + nr) > 32 &&
3176 start <= ra && (start + nr - 32) > ra) ||
3177 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
e06fcd75 3178 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3179 return;
297d8e62 3180 }
76db3ba4 3181 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3182 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3183 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3184 t0 = tcg_temp_new();
76db3ba4 3185 gen_addr_register(ctx, t0);
dfbc799d
AJ
3186 t1 = tcg_const_i32(nb);
3187 t2 = tcg_const_i32(start);
2f5a189c 3188 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3189 tcg_temp_free(t0);
3190 tcg_temp_free_i32(t1);
3191 tcg_temp_free_i32(t2);
79aceca5
FB
3192}
3193
3194/* lswx */
99e300ef 3195static void gen_lswx(DisasContext *ctx)
79aceca5 3196{
76db3ba4
AJ
3197 TCGv t0;
3198 TCGv_i32 t1, t2, t3;
3199 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3200 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3201 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3202 t0 = tcg_temp_new();
3203 gen_addr_reg_index(ctx, t0);
3204 t1 = tcg_const_i32(rD(ctx->opcode));
3205 t2 = tcg_const_i32(rA(ctx->opcode));
3206 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3207 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3208 tcg_temp_free(t0);
3209 tcg_temp_free_i32(t1);
3210 tcg_temp_free_i32(t2);
3211 tcg_temp_free_i32(t3);
79aceca5
FB
3212}
3213
3214/* stswi */
99e300ef 3215static void gen_stswi(DisasContext *ctx)
79aceca5 3216{
76db3ba4
AJ
3217 TCGv t0;
3218 TCGv_i32 t1, t2;
4b3686fa 3219 int nb = NB(ctx->opcode);
76db3ba4 3220 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3221 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3222 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3223 t0 = tcg_temp_new();
3224 gen_addr_register(ctx, t0);
4b3686fa
FB
3225 if (nb == 0)
3226 nb = 32;
dfbc799d 3227 t1 = tcg_const_i32(nb);
76db3ba4 3228 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3229 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3230 tcg_temp_free(t0);
3231 tcg_temp_free_i32(t1);
3232 tcg_temp_free_i32(t2);
79aceca5
FB
3233}
3234
3235/* stswx */
99e300ef 3236static void gen_stswx(DisasContext *ctx)
79aceca5 3237{
76db3ba4
AJ
3238 TCGv t0;
3239 TCGv_i32 t1, t2;
3240 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3241 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3242 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3243 t0 = tcg_temp_new();
3244 gen_addr_reg_index(ctx, t0);
3245 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3246 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3247 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3248 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3249 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3250 tcg_temp_free(t0);
3251 tcg_temp_free_i32(t1);
3252 tcg_temp_free_i32(t2);
79aceca5
FB
3253}
3254
3255/*** Memory synchronisation ***/
3256/* eieio */
99e300ef 3257static void gen_eieio(DisasContext *ctx)
79aceca5 3258{
79aceca5
FB
3259}
3260
3261/* isync */
99e300ef 3262static void gen_isync(DisasContext *ctx)
79aceca5 3263{
e06fcd75 3264 gen_stop_exception(ctx);
79aceca5
FB
3265}
3266
5c77a786
TM
3267#define LARX(name, len, loadop) \
3268static void gen_##name(DisasContext *ctx) \
3269{ \
3270 TCGv t0; \
3271 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3272 gen_set_access_type(ctx, ACCESS_RES); \
3273 t0 = tcg_temp_local_new(); \
3274 gen_addr_reg_index(ctx, t0); \
3275 if ((len) > 1) { \
3276 gen_check_align(ctx, t0, (len)-1); \
3277 } \
3278 gen_qemu_##loadop(ctx, gpr, t0); \
3279 tcg_gen_mov_tl(cpu_reserve, t0); \
3280 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3281 tcg_temp_free(t0); \
79aceca5
FB
3282}
3283
5c77a786
TM
3284/* lwarx */
3285LARX(lbarx, 1, ld8u);
3286LARX(lharx, 2, ld16u);
3287LARX(lwarx, 4, ld32u);
3288
3289
4425265b 3290#if defined(CONFIG_USER_ONLY)
587c51f7
TM
3291static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3292 int reg, int size)
4425265b
NF
3293{
3294 TCGv t0 = tcg_temp_new();
3295 uint32_t save_exception = ctx->exception;
3296
1328c2bf 3297 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3298 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3299 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3300 tcg_temp_free(t0);
3301 gen_update_nip(ctx, ctx->nip-4);
3302 ctx->exception = POWERPC_EXCP_BRANCH;
3303 gen_exception(ctx, POWERPC_EXCP_STCX);
3304 ctx->exception = save_exception;
3305}
4425265b 3306#else
587c51f7
TM
3307static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3308 int reg, int size)
3309{
3310 int l1;
4425265b 3311
587c51f7
TM
3312 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3313 l1 = gen_new_label();
3314 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3315 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3316#if defined(TARGET_PPC64)
3317 if (size == 8) {
3318 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3319 } else
3320#endif
3321 if (size == 4) {
3322 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3323 } else if (size == 2) {
3324 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
3325 } else {
3326 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
4425265b 3327 }
587c51f7
TM
3328 gen_set_label(l1);
3329 tcg_gen_movi_tl(cpu_reserve, -1);
3330}
4425265b 3331#endif
587c51f7
TM
3332
3333#define STCX(name, len) \
3334static void gen_##name(DisasContext *ctx) \
3335{ \
3336 TCGv t0; \
3337 gen_set_access_type(ctx, ACCESS_RES); \
3338 t0 = tcg_temp_local_new(); \
3339 gen_addr_reg_index(ctx, t0); \
3340 if (len > 1) { \
3341 gen_check_align(ctx, t0, (len)-1); \
3342 } \
3343 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3344 tcg_temp_free(t0); \
79aceca5
FB
3345}
3346
587c51f7
TM
3347STCX(stbcx_, 1);
3348STCX(sthcx_, 2);
3349STCX(stwcx_, 4);
3350
426613db 3351#if defined(TARGET_PPC64)
426613db 3352/* ldarx */
5c77a786 3353LARX(ldarx, 8, ld64);
426613db
JM
3354
3355/* stdcx. */
587c51f7 3356STCX(stdcx_, 8);
426613db
JM
3357#endif /* defined(TARGET_PPC64) */
3358
79aceca5 3359/* sync */
99e300ef 3360static void gen_sync(DisasContext *ctx)
79aceca5 3361{
79aceca5
FB
3362}
3363
0db1b20e 3364/* wait */
99e300ef 3365static void gen_wait(DisasContext *ctx)
0db1b20e 3366{
931ff272 3367 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3368 tcg_gen_st_i32(t0, cpu_env,
3369 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3370 tcg_temp_free_i32(t0);
0db1b20e 3371 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3372 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3373}
3374
79aceca5 3375/*** Floating-point load ***/
a0d7d5a7 3376#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3377static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3378{ \
a0d7d5a7 3379 TCGv EA; \
76a66253 3380 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3381 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3382 return; \
3383 } \
76db3ba4 3384 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3385 EA = tcg_temp_new(); \
76db3ba4
AJ
3386 gen_addr_imm_index(ctx, EA, 0); \
3387 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3388 tcg_temp_free(EA); \
79aceca5
FB
3389}
3390
a0d7d5a7 3391#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3392static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3393{ \
a0d7d5a7 3394 TCGv EA; \
76a66253 3395 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3396 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3397 return; \
3398 } \
76a66253 3399 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3400 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3401 return; \
9a64fbe4 3402 } \
76db3ba4 3403 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3404 EA = tcg_temp_new(); \
76db3ba4
AJ
3405 gen_addr_imm_index(ctx, EA, 0); \
3406 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3407 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3408 tcg_temp_free(EA); \
79aceca5
FB
3409}
3410
a0d7d5a7 3411#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3412static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3413{ \
a0d7d5a7 3414 TCGv EA; \
76a66253 3415 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3416 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3417 return; \
3418 } \
76a66253 3419 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3420 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3421 return; \
9a64fbe4 3422 } \
76db3ba4 3423 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3424 EA = tcg_temp_new(); \
76db3ba4
AJ
3425 gen_addr_reg_index(ctx, EA); \
3426 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3427 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3428 tcg_temp_free(EA); \
79aceca5
FB
3429}
3430
a0d7d5a7 3431#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3432static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3433{ \
a0d7d5a7 3434 TCGv EA; \
76a66253 3435 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3436 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3437 return; \
3438 } \
76db3ba4 3439 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3440 EA = tcg_temp_new(); \
76db3ba4
AJ
3441 gen_addr_reg_index(ctx, EA); \
3442 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3443 tcg_temp_free(EA); \
79aceca5
FB
3444}
3445
a0d7d5a7
AJ
3446#define GEN_LDFS(name, ldop, op, type) \
3447GEN_LDF(name, ldop, op | 0x20, type); \
3448GEN_LDUF(name, ldop, op | 0x21, type); \
3449GEN_LDUXF(name, ldop, op | 0x01, type); \
3450GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3451
636aa200 3452static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3453{
3454 TCGv t0 = tcg_temp_new();
3455 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3456 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3457 tcg_gen_trunc_tl_i32(t1, t0);
3458 tcg_temp_free(t0);
8e703949 3459 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3460 tcg_temp_free_i32(t1);
3461}
79aceca5 3462
a0d7d5a7
AJ
3463 /* lfd lfdu lfdux lfdx */
3464GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3465 /* lfs lfsu lfsux lfsx */
3466GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3467
05050ee8
AJ
3468/* lfdp */
3469static void gen_lfdp(DisasContext *ctx)
3470{
3471 TCGv EA;
3472 if (unlikely(!ctx->fpu_enabled)) {
3473 gen_exception(ctx, POWERPC_EXCP_FPU);
3474 return;
3475 }
3476 gen_set_access_type(ctx, ACCESS_FLOAT);
3477 EA = tcg_temp_new();
3478 gen_addr_imm_index(ctx, EA, 0); \
3479 if (unlikely(ctx->le_mode)) {
3480 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3481 tcg_gen_addi_tl(EA, EA, 8);
3482 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3483 } else {
3484 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3485 tcg_gen_addi_tl(EA, EA, 8);
3486 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3487 }
3488 tcg_temp_free(EA);
3489}
3490
3491/* lfdpx */
3492static void gen_lfdpx(DisasContext *ctx)
3493{
3494 TCGv EA;
3495 if (unlikely(!ctx->fpu_enabled)) {
3496 gen_exception(ctx, POWERPC_EXCP_FPU);
3497 return;
3498 }
3499 gen_set_access_type(ctx, ACCESS_FLOAT);
3500 EA = tcg_temp_new();
3501 gen_addr_reg_index(ctx, EA);
3502 if (unlikely(ctx->le_mode)) {
3503 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3504 tcg_gen_addi_tl(EA, EA, 8);
3505 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3506 } else {
3507 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3508 tcg_gen_addi_tl(EA, EA, 8);
3509 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3510 }
3511 tcg_temp_free(EA);
3512}
3513
199f830d
AJ
3514/* lfiwax */
3515static void gen_lfiwax(DisasContext *ctx)
3516{
3517 TCGv EA;
3518 TCGv t0;
3519 if (unlikely(!ctx->fpu_enabled)) {
3520 gen_exception(ctx, POWERPC_EXCP_FPU);
3521 return;
3522 }
3523 gen_set_access_type(ctx, ACCESS_FLOAT);
3524 EA = tcg_temp_new();
3525 t0 = tcg_temp_new();
3526 gen_addr_reg_index(ctx, EA);
909eedb7 3527 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3528 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3529 tcg_temp_free(EA);
3530 tcg_temp_free(t0);
3531}
3532
66c3e328
TM
3533/* lfiwzx */
3534static void gen_lfiwzx(DisasContext *ctx)
3535{
3536 TCGv EA;
3537 if (unlikely(!ctx->fpu_enabled)) {
3538 gen_exception(ctx, POWERPC_EXCP_FPU);
3539 return;
3540 }
3541 gen_set_access_type(ctx, ACCESS_FLOAT);
3542 EA = tcg_temp_new();
3543 gen_addr_reg_index(ctx, EA);
3544 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3545 tcg_temp_free(EA);
3546}
79aceca5 3547/*** Floating-point store ***/
a0d7d5a7 3548#define GEN_STF(name, stop, opc, type) \
99e300ef 3549static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3550{ \
a0d7d5a7 3551 TCGv EA; \
76a66253 3552 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3553 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3554 return; \
3555 } \
76db3ba4 3556 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3557 EA = tcg_temp_new(); \
76db3ba4
AJ
3558 gen_addr_imm_index(ctx, EA, 0); \
3559 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3560 tcg_temp_free(EA); \
79aceca5
FB
3561}
3562
a0d7d5a7 3563#define GEN_STUF(name, stop, opc, type) \
99e300ef 3564static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3565{ \
a0d7d5a7 3566 TCGv EA; \
76a66253 3567 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3568 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3569 return; \
3570 } \
76a66253 3571 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3572 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3573 return; \
9a64fbe4 3574 } \
76db3ba4 3575 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3576 EA = tcg_temp_new(); \
76db3ba4
AJ
3577 gen_addr_imm_index(ctx, EA, 0); \
3578 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3579 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3580 tcg_temp_free(EA); \
79aceca5
FB
3581}
3582
a0d7d5a7 3583#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3584static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3585{ \
a0d7d5a7 3586 TCGv EA; \
76a66253 3587 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3588 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3589 return; \
3590 } \
76a66253 3591 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3592 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3593 return; \
9a64fbe4 3594 } \
76db3ba4 3595 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3596 EA = tcg_temp_new(); \
76db3ba4
AJ
3597 gen_addr_reg_index(ctx, EA); \
3598 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3599 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3600 tcg_temp_free(EA); \
79aceca5
FB
3601}
3602
a0d7d5a7 3603#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3604static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3605{ \
a0d7d5a7 3606 TCGv EA; \
76a66253 3607 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3608 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3609 return; \
3610 } \
76db3ba4 3611 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3612 EA = tcg_temp_new(); \
76db3ba4
AJ
3613 gen_addr_reg_index(ctx, EA); \
3614 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3615 tcg_temp_free(EA); \
79aceca5
FB
3616}
3617
a0d7d5a7
AJ
3618#define GEN_STFS(name, stop, op, type) \
3619GEN_STF(name, stop, op | 0x20, type); \
3620GEN_STUF(name, stop, op | 0x21, type); \
3621GEN_STUXF(name, stop, op | 0x01, type); \
3622GEN_STXF(name, stop, 0x17, op | 0x00, type)
3623
636aa200 3624static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3625{
3626 TCGv_i32 t0 = tcg_temp_new_i32();
3627 TCGv t1 = tcg_temp_new();
8e703949 3628 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3629 tcg_gen_extu_i32_tl(t1, t0);
3630 tcg_temp_free_i32(t0);
76db3ba4 3631 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3632 tcg_temp_free(t1);
3633}
79aceca5
FB
3634
3635/* stfd stfdu stfdux stfdx */
a0d7d5a7 3636GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3637/* stfs stfsu stfsux stfsx */
a0d7d5a7 3638GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3639
44bc0c4d
AJ
3640/* stfdp */
3641static void gen_stfdp(DisasContext *ctx)
3642{
3643 TCGv EA;
3644 if (unlikely(!ctx->fpu_enabled)) {
3645 gen_exception(ctx, POWERPC_EXCP_FPU);
3646 return;
3647 }
3648 gen_set_access_type(ctx, ACCESS_FLOAT);
3649 EA = tcg_temp_new();
3650 gen_addr_imm_index(ctx, EA, 0); \
3651 if (unlikely(ctx->le_mode)) {
3652 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3653 tcg_gen_addi_tl(EA, EA, 8);
3654 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3655 } else {
3656 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3657 tcg_gen_addi_tl(EA, EA, 8);
3658 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3659 }
3660 tcg_temp_free(EA);
3661}
3662
3663/* stfdpx */
3664static void gen_stfdpx(DisasContext *ctx)
3665{
3666 TCGv EA;
3667 if (unlikely(!ctx->fpu_enabled)) {
3668 gen_exception(ctx, POWERPC_EXCP_FPU);
3669 return;
3670 }
3671 gen_set_access_type(ctx, ACCESS_FLOAT);
3672 EA = tcg_temp_new();
3673 gen_addr_reg_index(ctx, EA);
3674 if (unlikely(ctx->le_mode)) {
3675 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3676 tcg_gen_addi_tl(EA, EA, 8);
3677 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3678 } else {
3679 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3680 tcg_gen_addi_tl(EA, EA, 8);
3681 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3682 }
3683 tcg_temp_free(EA);
3684}
3685
79aceca5 3686/* Optional: */
636aa200 3687static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3688{
3689 TCGv t0 = tcg_temp_new();
3690 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3691 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3692 tcg_temp_free(t0);
3693}
79aceca5 3694/* stfiwx */
a0d7d5a7 3695GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3696
697ab892
DG
3697static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3698{
3699#if defined(TARGET_PPC64)
3700 if (ctx->has_cfar)
3701 tcg_gen_movi_tl(cpu_cfar, nip);
3702#endif
3703}
3704
79aceca5 3705/*** Branch ***/
636aa200 3706static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362
FB
3707{
3708 TranslationBlock *tb;
3709 tb = ctx->tb;
e0c8f9ce 3710 if (NARROW_MODE(ctx)) {
a2ffb812 3711 dest = (uint32_t) dest;
e0c8f9ce 3712 }
57fec1fe 3713 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
8cbcb4fa 3714 likely(!ctx->singlestep_enabled)) {
57fec1fe 3715 tcg_gen_goto_tb(n);
a2ffb812 3716 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cfd0495 3717 tcg_gen_exit_tb((uintptr_t)tb + n);
c1942362 3718 } else {
a2ffb812 3719 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3720 if (unlikely(ctx->singlestep_enabled)) {
3721 if ((ctx->singlestep_enabled &
bdc4e053 3722 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3723 (ctx->exception == POWERPC_EXCP_BRANCH ||
3724 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3725 target_ulong tmp = ctx->nip;
3726 ctx->nip = dest;
e06fcd75 3727 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3728 ctx->nip = tmp;
3729 }
3730 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3731 gen_debug_exception(ctx);
8cbcb4fa
AJ
3732 }
3733 }
57fec1fe 3734 tcg_gen_exit_tb(0);
c1942362 3735 }
c53be334
FB
3736}
3737
636aa200 3738static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3739{
e0c8f9ce
RH
3740 if (NARROW_MODE(ctx)) {
3741 nip = (uint32_t)nip;
3742 }
3743 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3744}
3745
79aceca5 3746/* b ba bl bla */
99e300ef 3747static void gen_b(DisasContext *ctx)
79aceca5 3748{
76a66253 3749 target_ulong li, target;
38a64f9d 3750
8cbcb4fa 3751 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3752 /* sign extend LI */
e0c8f9ce
RH
3753 li = LI(ctx->opcode);
3754 li = (li ^ 0x02000000) - 0x02000000;
3755 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3756 target = ctx->nip + li - 4;
e0c8f9ce 3757 } else {
9a64fbe4 3758 target = li;
e0c8f9ce
RH
3759 }
3760 if (LK(ctx->opcode)) {
e1833e1f 3761 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3762 }
697ab892 3763 gen_update_cfar(ctx, ctx->nip);
c1942362 3764 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3765}
3766
e98a6e40
FB
3767#define BCOND_IM 0
3768#define BCOND_LR 1
3769#define BCOND_CTR 2
52a4984d 3770#define BCOND_TAR 3
e98a6e40 3771
636aa200 3772static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3773{
d9bce9d9 3774 uint32_t bo = BO(ctx->opcode);
05f92404 3775 int l1;
a2ffb812 3776 TCGv target;
e98a6e40 3777
8cbcb4fa 3778 ctx->exception = POWERPC_EXCP_BRANCH;
52a4984d 3779 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
a7812ae4 3780 target = tcg_temp_local_new();
a2ffb812
AJ
3781 if (type == BCOND_CTR)
3782 tcg_gen_mov_tl(target, cpu_ctr);
52a4984d
TM
3783 else if (type == BCOND_TAR)
3784 gen_load_spr(target, SPR_TAR);
a2ffb812
AJ
3785 else
3786 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3787 } else {
3788 TCGV_UNUSED(target);
e98a6e40 3789 }
e1833e1f
JM
3790 if (LK(ctx->opcode))
3791 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3792 l1 = gen_new_label();
3793 if ((bo & 0x4) == 0) {
3794 /* Decrement and test CTR */
a7812ae4 3795 TCGv temp = tcg_temp_new();
a2ffb812 3796 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3797 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3798 return;
3799 }
3800 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3801 if (NARROW_MODE(ctx)) {
a2ffb812 3802 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3803 } else {
a2ffb812 3804 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3805 }
a2ffb812
AJ
3806 if (bo & 0x2) {
3807 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3808 } else {
3809 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3810 }
a7812ae4 3811 tcg_temp_free(temp);
a2ffb812
AJ
3812 }
3813 if ((bo & 0x10) == 0) {
3814 /* Test CR */
3815 uint32_t bi = BI(ctx->opcode);
3816 uint32_t mask = 1 << (3 - (bi & 0x03));
a7812ae4 3817 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3818
d9bce9d9 3819 if (bo & 0x8) {
a2ffb812
AJ
3820 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3821 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3822 } else {
a2ffb812
AJ
3823 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3824 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3825 }
a7812ae4 3826 tcg_temp_free_i32(temp);
d9bce9d9 3827 }
697ab892 3828 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3829 if (type == BCOND_IM) {
a2ffb812
AJ
3830 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3831 if (likely(AA(ctx->opcode) == 0)) {
3832 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3833 } else {
3834 gen_goto_tb(ctx, 0, li);
3835 }
c53be334 3836 gen_set_label(l1);
c1942362 3837 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3838 } else {
e0c8f9ce 3839 if (NARROW_MODE(ctx)) {
a2ffb812 3840 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3841 } else {
a2ffb812 3842 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3843 }
a2ffb812
AJ
3844 tcg_gen_exit_tb(0);
3845 gen_set_label(l1);
e0c8f9ce 3846 gen_update_nip(ctx, ctx->nip);
57fec1fe 3847 tcg_gen_exit_tb(0);
08e46e54 3848 }
e98a6e40
FB
3849}
3850
99e300ef 3851static void gen_bc(DisasContext *ctx)
3b46e624 3852{
e98a6e40
FB
3853 gen_bcond(ctx, BCOND_IM);
3854}
3855
99e300ef 3856static void gen_bcctr(DisasContext *ctx)
3b46e624 3857{
e98a6e40
FB
3858 gen_bcond(ctx, BCOND_CTR);
3859}
3860
99e300ef 3861static void gen_bclr(DisasContext *ctx)
3b46e624 3862{
e98a6e40
FB
3863 gen_bcond(ctx, BCOND_LR);
3864}
79aceca5 3865
52a4984d
TM
3866static void gen_bctar(DisasContext *ctx)
3867{
3868 gen_bcond(ctx, BCOND_TAR);
3869}
3870
79aceca5 3871/*** Condition register logical ***/
e1571908 3872#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 3873static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3874{ \
fc0d441e
JM
3875 uint8_t bitmask; \
3876 int sh; \
a7812ae4 3877 TCGv_i32 t0, t1; \
fc0d441e 3878 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 3879 t0 = tcg_temp_new_i32(); \
fc0d441e 3880 if (sh > 0) \
fea0c503 3881 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 3882 else if (sh < 0) \
fea0c503 3883 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 3884 else \
fea0c503 3885 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 3886 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
3887 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3888 if (sh > 0) \
fea0c503 3889 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 3890 else if (sh < 0) \
fea0c503 3891 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 3892 else \
fea0c503
AJ
3893 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3894 tcg_op(t0, t0, t1); \
fc0d441e 3895 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
fea0c503
AJ
3896 tcg_gen_andi_i32(t0, t0, bitmask); \
3897 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3898 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
3899 tcg_temp_free_i32(t0); \
3900 tcg_temp_free_i32(t1); \
79aceca5
FB
3901}
3902
3903/* crand */
e1571908 3904GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 3905/* crandc */
e1571908 3906GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 3907/* creqv */
e1571908 3908GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 3909/* crnand */
e1571908 3910GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 3911/* crnor */
e1571908 3912GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 3913/* cror */
e1571908 3914GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 3915/* crorc */
e1571908 3916GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 3917/* crxor */
e1571908 3918GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 3919
54623277 3920/* mcrf */
99e300ef 3921static void gen_mcrf(DisasContext *ctx)
79aceca5 3922{
47e4661c 3923 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
3924}
3925
3926/*** System linkage ***/
99e300ef 3927
54623277 3928/* rfi (mem_idx only) */
99e300ef 3929static void gen_rfi(DisasContext *ctx)
79aceca5 3930{
9a64fbe4 3931#if defined(CONFIG_USER_ONLY)
e06fcd75 3932 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
3933#else
3934 /* Restore CPU state */
76db3ba4 3935 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3936 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 3937 return;
9a64fbe4 3938 }
697ab892 3939 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 3940 gen_helper_rfi(cpu_env);
e06fcd75 3941 gen_sync_exception(ctx);
9a64fbe4 3942#endif
79aceca5
FB
3943}
3944
426613db 3945#if defined(TARGET_PPC64)
99e300ef 3946static void gen_rfid(DisasContext *ctx)
426613db
JM
3947{
3948#if defined(CONFIG_USER_ONLY)
e06fcd75 3949 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
3950#else
3951 /* Restore CPU state */
76db3ba4 3952 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3953 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
3954 return;
3955 }
697ab892 3956 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 3957 gen_helper_rfid(cpu_env);
e06fcd75 3958 gen_sync_exception(ctx);
426613db
JM
3959#endif
3960}
426613db 3961
99e300ef 3962static void gen_hrfid(DisasContext *ctx)
be147d08
JM
3963{
3964#if defined(CONFIG_USER_ONLY)
e06fcd75 3965 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3966#else
3967 /* Restore CPU state */
76db3ba4 3968 if (unlikely(ctx->mem_idx <= 1)) {
e06fcd75 3969 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3970 return;
3971 }
e5f17ac6 3972 gen_helper_hrfid(cpu_env);
e06fcd75 3973 gen_sync_exception(ctx);
be147d08
JM
3974#endif
3975}
3976#endif
3977
79aceca5 3978/* sc */
417bf010
JM
3979#if defined(CONFIG_USER_ONLY)
3980#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3981#else
3982#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3983#endif
99e300ef 3984static void gen_sc(DisasContext *ctx)
79aceca5 3985{
e1833e1f
JM
3986 uint32_t lev;
3987
3988 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 3989 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
3990}
3991
3992/*** Trap ***/
99e300ef 3993
54623277 3994/* tw */
99e300ef 3995static void gen_tw(DisasContext *ctx)
79aceca5 3996{
cab3bee2 3997 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3998 /* Update the nip since this might generate a trap exception */
3999 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4000 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4001 t0);
cab3bee2 4002 tcg_temp_free_i32(t0);
79aceca5
FB
4003}
4004
4005/* twi */
99e300ef 4006static void gen_twi(DisasContext *ctx)
79aceca5 4007{
cab3bee2
AJ
4008 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4009 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4010 /* Update the nip since this might generate a trap exception */
4011 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4012 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4013 tcg_temp_free(t0);
4014 tcg_temp_free_i32(t1);
79aceca5
FB
4015}
4016
d9bce9d9
JM
4017#if defined(TARGET_PPC64)
4018/* td */
99e300ef 4019static void gen_td(DisasContext *ctx)
d9bce9d9 4020{
cab3bee2 4021 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4022 /* Update the nip since this might generate a trap exception */
4023 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4024 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4025 t0);
cab3bee2 4026 tcg_temp_free_i32(t0);
d9bce9d9
JM
4027}
4028
4029/* tdi */
99e300ef 4030static void gen_tdi(DisasContext *ctx)
d9bce9d9 4031{
cab3bee2
AJ
4032 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4033 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4034 /* Update the nip since this might generate a trap exception */
4035 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4036 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4037 tcg_temp_free(t0);
4038 tcg_temp_free_i32(t1);
d9bce9d9
JM
4039}
4040#endif
4041
79aceca5 4042/*** Processor control ***/
99e300ef 4043
da91a00f
RH
4044static void gen_read_xer(TCGv dst)
4045{
4046 TCGv t0 = tcg_temp_new();
4047 TCGv t1 = tcg_temp_new();
4048 TCGv t2 = tcg_temp_new();
4049 tcg_gen_mov_tl(dst, cpu_xer);
4050 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4051 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4052 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4053 tcg_gen_or_tl(t0, t0, t1);
4054 tcg_gen_or_tl(dst, dst, t2);
4055 tcg_gen_or_tl(dst, dst, t0);
4056 tcg_temp_free(t0);
4057 tcg_temp_free(t1);
4058 tcg_temp_free(t2);
4059}
4060
4061static void gen_write_xer(TCGv src)
4062{
4063 tcg_gen_andi_tl(cpu_xer, src,
4064 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4065 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4066 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4067 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4068 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4069 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4070 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4071}
4072
54623277 4073/* mcrxr */
99e300ef 4074static void gen_mcrxr(DisasContext *ctx)
79aceca5 4075{
da91a00f
RH
4076 TCGv_i32 t0 = tcg_temp_new_i32();
4077 TCGv_i32 t1 = tcg_temp_new_i32();
4078 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4079
4080 tcg_gen_trunc_tl_i32(t0, cpu_so);
4081 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4082 tcg_gen_trunc_tl_i32(dst, cpu_ca);
4083 tcg_gen_shri_i32(t0, t0, 2);
4084 tcg_gen_shri_i32(t1, t1, 1);
4085 tcg_gen_or_i32(dst, dst, t0);
4086 tcg_gen_or_i32(dst, dst, t1);
4087 tcg_temp_free_i32(t0);
4088 tcg_temp_free_i32(t1);
4089
4090 tcg_gen_movi_tl(cpu_so, 0);
4091 tcg_gen_movi_tl(cpu_ov, 0);
4092 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
4093}
4094
0cfe11ea 4095/* mfcr mfocrf */
99e300ef 4096static void gen_mfcr(DisasContext *ctx)
79aceca5 4097{
76a66253 4098 uint32_t crm, crn;
3b46e624 4099
76a66253
JM
4100 if (likely(ctx->opcode & 0x00100000)) {
4101 crm = CRM(ctx->opcode);
8dd640e4 4102 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 4103 crn = ctz32 (crm);
e1571908 4104 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
4105 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4106 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 4107 }
d9bce9d9 4108 } else {
651721b2
AJ
4109 TCGv_i32 t0 = tcg_temp_new_i32();
4110 tcg_gen_mov_i32(t0, cpu_crf[0]);
4111 tcg_gen_shli_i32(t0, t0, 4);
4112 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4113 tcg_gen_shli_i32(t0, t0, 4);
4114 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4115 tcg_gen_shli_i32(t0, t0, 4);
4116 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4117 tcg_gen_shli_i32(t0, t0, 4);
4118 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4119 tcg_gen_shli_i32(t0, t0, 4);
4120 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4121 tcg_gen_shli_i32(t0, t0, 4);
4122 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4123 tcg_gen_shli_i32(t0, t0, 4);
4124 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4125 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4126 tcg_temp_free_i32(t0);
d9bce9d9 4127 }
79aceca5
FB
4128}
4129
4130/* mfmsr */
99e300ef 4131static void gen_mfmsr(DisasContext *ctx)
79aceca5 4132{
9a64fbe4 4133#if defined(CONFIG_USER_ONLY)
e06fcd75 4134 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4135#else
76db3ba4 4136 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4137 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4138 return;
9a64fbe4 4139 }
6527f6ea 4140 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4141#endif
79aceca5
FB
4142}
4143
7b13448f 4144static void spr_noaccess(void *opaque, int gprn, int sprn)
3fc6c082 4145{
7b13448f 4146#if 0
3fc6c082
FB
4147 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4148 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4149#endif
3fc6c082
FB
4150}
4151#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4152
79aceca5 4153/* mfspr */
636aa200 4154static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4155{
45d827d2 4156 void (*read_cb)(void *opaque, int gprn, int sprn);
79aceca5
FB
4157 uint32_t sprn = SPR(ctx->opcode);
4158
3fc6c082 4159#if !defined(CONFIG_USER_ONLY)
76db3ba4 4160 if (ctx->mem_idx == 2)
be147d08 4161 read_cb = ctx->spr_cb[sprn].hea_read;
76db3ba4 4162 else if (ctx->mem_idx)
3fc6c082
FB
4163 read_cb = ctx->spr_cb[sprn].oea_read;
4164 else
9a64fbe4 4165#endif
3fc6c082 4166 read_cb = ctx->spr_cb[sprn].uea_read;
76a66253
JM
4167 if (likely(read_cb != NULL)) {
4168 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4169 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4170 } else {
4171 /* Privilege exception */
9fceefa7
JM
4172 /* This is a hack to avoid warnings when running Linux:
4173 * this OS breaks the PowerPC virtualisation model,
4174 * allowing userland application to read the PVR
4175 */
4176 if (sprn != SPR_PVR) {
c05541ee
AB
4177 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4178 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4179 printf("Trying to read privileged spr %d (0x%03x) at "
4180 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
f24e5695 4181 }
e06fcd75 4182 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4183 }
3fc6c082
FB
4184 } else {
4185 /* Not defined */
c05541ee
AB
4186 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4187 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4188 printf("Trying to read invalid spr %d (0x%03x) at "
4189 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4190 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4191 }
79aceca5
FB
4192}
4193
99e300ef 4194static void gen_mfspr(DisasContext *ctx)
79aceca5 4195{
3fc6c082 4196 gen_op_mfspr(ctx);
76a66253 4197}
3fc6c082
FB
4198
4199/* mftb */
99e300ef 4200static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4201{
4202 gen_op_mfspr(ctx);
79aceca5
FB
4203}
4204
0cfe11ea 4205/* mtcrf mtocrf*/
99e300ef 4206static void gen_mtcrf(DisasContext *ctx)
79aceca5 4207{
76a66253 4208 uint32_t crm, crn;
3b46e624 4209
76a66253 4210 crm = CRM(ctx->opcode);
8dd640e4 4211 if (likely((ctx->opcode & 0x00100000))) {
4212 if (crm && ((crm & (crm - 1)) == 0)) {
4213 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4214 crn = ctz32 (crm);
8dd640e4 4215 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4216 tcg_gen_shri_i32(temp, temp, crn * 4);
4217 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4218 tcg_temp_free_i32(temp);
4219 }
76a66253 4220 } else {
651721b2
AJ
4221 TCGv_i32 temp = tcg_temp_new_i32();
4222 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4223 for (crn = 0 ; crn < 8 ; crn++) {
4224 if (crm & (1 << crn)) {
4225 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4226 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4227 }
4228 }
a7812ae4 4229 tcg_temp_free_i32(temp);
76a66253 4230 }
79aceca5
FB
4231}
4232
4233/* mtmsr */
426613db 4234#if defined(TARGET_PPC64)
99e300ef 4235static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4236{
4237#if defined(CONFIG_USER_ONLY)
e06fcd75 4238 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4239#else
76db3ba4 4240 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4241 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4242 return;
4243 }
be147d08
JM
4244 if (ctx->opcode & 0x00010000) {
4245 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4246 TCGv t0 = tcg_temp_new();
4247 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4248 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4249 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4250 tcg_temp_free(t0);
be147d08 4251 } else {
056b05f8
JM
4252 /* XXX: we need to update nip before the store
4253 * if we enter power saving mode, we will exit the loop
4254 * directly from ppc_store_msr
4255 */
be147d08 4256 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4257 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4258 /* Must stop the translation as machine state (may have) changed */
4259 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4260 gen_stop_exception(ctx);
be147d08 4261 }
426613db
JM
4262#endif
4263}
4264#endif
4265
99e300ef 4266static void gen_mtmsr(DisasContext *ctx)
79aceca5 4267{
9a64fbe4 4268#if defined(CONFIG_USER_ONLY)
e06fcd75 4269 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4270#else
76db3ba4 4271 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4272 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4273 return;
9a64fbe4 4274 }
be147d08
JM
4275 if (ctx->opcode & 0x00010000) {
4276 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4277 TCGv t0 = tcg_temp_new();
4278 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4279 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4280 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4281 tcg_temp_free(t0);
be147d08 4282 } else {
8018dc63
AG
4283 TCGv msr = tcg_temp_new();
4284
056b05f8
JM
4285 /* XXX: we need to update nip before the store
4286 * if we enter power saving mode, we will exit the loop
4287 * directly from ppc_store_msr
4288 */
be147d08 4289 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4290#if defined(TARGET_PPC64)
8018dc63
AG
4291 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4292#else
4293 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4294#endif
e5f17ac6 4295 gen_helper_store_msr(cpu_env, msr);
be147d08 4296 /* Must stop the translation as machine state (may have) changed */
6527f6ea 4297 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4298 gen_stop_exception(ctx);
be147d08 4299 }
9a64fbe4 4300#endif
79aceca5
FB
4301}
4302
4303/* mtspr */
99e300ef 4304static void gen_mtspr(DisasContext *ctx)
79aceca5 4305{
45d827d2 4306 void (*write_cb)(void *opaque, int sprn, int gprn);
79aceca5
FB
4307 uint32_t sprn = SPR(ctx->opcode);
4308
3fc6c082 4309#if !defined(CONFIG_USER_ONLY)
76db3ba4 4310 if (ctx->mem_idx == 2)
be147d08 4311 write_cb = ctx->spr_cb[sprn].hea_write;
76db3ba4 4312 else if (ctx->mem_idx)
3fc6c082
FB
4313 write_cb = ctx->spr_cb[sprn].oea_write;
4314 else
9a64fbe4 4315#endif
3fc6c082 4316 write_cb = ctx->spr_cb[sprn].uea_write;
76a66253
JM
4317 if (likely(write_cb != NULL)) {
4318 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 4319 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
4320 } else {
4321 /* Privilege exception */
c05541ee
AB
4322 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4323 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4324 printf("Trying to write privileged spr %d (0x%03x) at "
4325 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4326 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 4327 }
3fc6c082
FB
4328 } else {
4329 /* Not defined */
c05541ee
AB
4330 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4331 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4332 printf("Trying to write invalid spr %d (0x%03x) at "
4333 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4334 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4335 }
79aceca5
FB
4336}
4337
4338/*** Cache management ***/
99e300ef 4339
54623277 4340/* dcbf */
99e300ef 4341static void gen_dcbf(DisasContext *ctx)
79aceca5 4342{
dac454af 4343 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
4344 TCGv t0;
4345 gen_set_access_type(ctx, ACCESS_CACHE);
4346 t0 = tcg_temp_new();
4347 gen_addr_reg_index(ctx, t0);
4348 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4349 tcg_temp_free(t0);
79aceca5
FB
4350}
4351
4352/* dcbi (Supervisor only) */
99e300ef 4353static void gen_dcbi(DisasContext *ctx)
79aceca5 4354{
a541f297 4355#if defined(CONFIG_USER_ONLY)
e06fcd75 4356 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 4357#else
b61f2753 4358 TCGv EA, val;
76db3ba4 4359 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4360 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4361 return;
9a64fbe4 4362 }
a7812ae4 4363 EA = tcg_temp_new();
76db3ba4
AJ
4364 gen_set_access_type(ctx, ACCESS_CACHE);
4365 gen_addr_reg_index(ctx, EA);
a7812ae4 4366 val = tcg_temp_new();
76a66253 4367 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
4368 gen_qemu_ld8u(ctx, val, EA);
4369 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
4370 tcg_temp_free(val);
4371 tcg_temp_free(EA);
a541f297 4372#endif
79aceca5
FB
4373}
4374
4375/* dcdst */
99e300ef 4376static void gen_dcbst(DisasContext *ctx)
79aceca5 4377{
76a66253 4378 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
4379 TCGv t0;
4380 gen_set_access_type(ctx, ACCESS_CACHE);
4381 t0 = tcg_temp_new();
4382 gen_addr_reg_index(ctx, t0);
4383 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4384 tcg_temp_free(t0);
79aceca5
FB
4385}
4386
4387/* dcbt */
99e300ef 4388static void gen_dcbt(DisasContext *ctx)
79aceca5 4389{
0db1b20e 4390 /* interpreted as no-op */
76a66253
JM
4391 /* XXX: specification say this is treated as a load by the MMU
4392 * but does not generate any exception
4393 */
79aceca5
FB
4394}
4395
4396/* dcbtst */
99e300ef 4397static void gen_dcbtst(DisasContext *ctx)
79aceca5 4398{
0db1b20e 4399 /* interpreted as no-op */
76a66253
JM
4400 /* XXX: specification say this is treated as a load by the MMU
4401 * but does not generate any exception
4402 */
79aceca5
FB
4403}
4404
4405/* dcbz */
99e300ef 4406static void gen_dcbz(DisasContext *ctx)
79aceca5 4407{
8e33944f
AG
4408 TCGv tcgv_addr;
4409 TCGv_i32 tcgv_is_dcbzl;
4410 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4411
76db3ba4 4412 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4413 /* NIP cannot be restored if the memory exception comes from an helper */
4414 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4415 tcgv_addr = tcg_temp_new();
4416 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4417
4418 gen_addr_reg_index(ctx, tcgv_addr);
4419 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4420
4421 tcg_temp_free(tcgv_addr);
4422 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4423}
4424
ae1c1a3d 4425/* dst / dstt */
99e300ef 4426static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4427{
4428 if (rA(ctx->opcode) == 0) {
4429 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4430 } else {
4431 /* interpreted as no-op */
4432 }
4433}
4434
4435/* dstst /dststt */
99e300ef 4436static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4437{
4438 if (rA(ctx->opcode) == 0) {
4439 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4440 } else {
4441 /* interpreted as no-op */
4442 }
4443
4444}
4445
4446/* dss / dssall */
99e300ef 4447static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4448{
4449 /* interpreted as no-op */
4450}
4451
79aceca5 4452/* icbi */
99e300ef 4453static void gen_icbi(DisasContext *ctx)
79aceca5 4454{
76db3ba4
AJ
4455 TCGv t0;
4456 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4457 /* NIP cannot be restored if the memory exception comes from an helper */
4458 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4459 t0 = tcg_temp_new();
4460 gen_addr_reg_index(ctx, t0);
2f5a189c 4461 gen_helper_icbi(cpu_env, t0);
37d269df 4462 tcg_temp_free(t0);
79aceca5
FB
4463}
4464
4465/* Optional: */
4466/* dcba */
99e300ef 4467static void gen_dcba(DisasContext *ctx)
79aceca5 4468{
0db1b20e
JM
4469 /* interpreted as no-op */
4470 /* XXX: specification say this is treated as a store by the MMU
4471 * but does not generate any exception
4472 */
79aceca5
FB
4473}
4474
4475/*** Segment register manipulation ***/
4476/* Supervisor only: */
99e300ef 4477
54623277 4478/* mfsr */
99e300ef 4479static void gen_mfsr(DisasContext *ctx)
79aceca5 4480{
9a64fbe4 4481#if defined(CONFIG_USER_ONLY)
e06fcd75 4482 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4483#else
74d37793 4484 TCGv t0;
76db3ba4 4485 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4486 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4487 return;
9a64fbe4 4488 }
74d37793 4489 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4490 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4491 tcg_temp_free(t0);
9a64fbe4 4492#endif
79aceca5
FB
4493}
4494
4495/* mfsrin */
99e300ef 4496static void gen_mfsrin(DisasContext *ctx)
79aceca5 4497{
9a64fbe4 4498#if defined(CONFIG_USER_ONLY)
e06fcd75 4499 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4500#else
74d37793 4501 TCGv t0;
76db3ba4 4502 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4503 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4504 return;
9a64fbe4 4505 }
74d37793
AJ
4506 t0 = tcg_temp_new();
4507 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4508 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4509 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4510 tcg_temp_free(t0);
9a64fbe4 4511#endif
79aceca5
FB
4512}
4513
4514/* mtsr */
99e300ef 4515static void gen_mtsr(DisasContext *ctx)
79aceca5 4516{
9a64fbe4 4517#if defined(CONFIG_USER_ONLY)
e06fcd75 4518 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4519#else
74d37793 4520 TCGv t0;
76db3ba4 4521 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4522 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4523 return;
9a64fbe4 4524 }
74d37793 4525 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4526 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4527 tcg_temp_free(t0);
9a64fbe4 4528#endif
79aceca5
FB
4529}
4530
4531/* mtsrin */
99e300ef 4532static void gen_mtsrin(DisasContext *ctx)
79aceca5 4533{
9a64fbe4 4534#if defined(CONFIG_USER_ONLY)
e06fcd75 4535 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4536#else
74d37793 4537 TCGv t0;
76db3ba4 4538 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4539 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4540 return;
9a64fbe4 4541 }
74d37793
AJ
4542 t0 = tcg_temp_new();
4543 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4544 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4545 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4546 tcg_temp_free(t0);
9a64fbe4 4547#endif
79aceca5
FB
4548}
4549
12de9a39
JM
4550#if defined(TARGET_PPC64)
4551/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4552
54623277 4553/* mfsr */
e8eaa2c0 4554static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4555{
4556#if defined(CONFIG_USER_ONLY)
e06fcd75 4557 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4558#else
74d37793 4559 TCGv t0;
76db3ba4 4560 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4561 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4562 return;
4563 }
74d37793 4564 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4565 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4566 tcg_temp_free(t0);
12de9a39
JM
4567#endif
4568}
4569
4570/* mfsrin */
e8eaa2c0 4571static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4572{
4573#if defined(CONFIG_USER_ONLY)
e06fcd75 4574 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4575#else
74d37793 4576 TCGv t0;
76db3ba4 4577 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4578 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4579 return;
4580 }
74d37793
AJ
4581 t0 = tcg_temp_new();
4582 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4583 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4584 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4585 tcg_temp_free(t0);
12de9a39
JM
4586#endif
4587}
4588
4589/* mtsr */
e8eaa2c0 4590static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4591{
4592#if defined(CONFIG_USER_ONLY)
e06fcd75 4593 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4594#else
74d37793 4595 TCGv t0;
76db3ba4 4596 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4597 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4598 return;
4599 }
74d37793 4600 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4601 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4602 tcg_temp_free(t0);
12de9a39
JM
4603#endif
4604}
4605
4606/* mtsrin */
e8eaa2c0 4607static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4608{
4609#if defined(CONFIG_USER_ONLY)
e06fcd75 4610 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4611#else
74d37793 4612 TCGv t0;
76db3ba4 4613 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4614 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4615 return;
4616 }
74d37793
AJ
4617 t0 = tcg_temp_new();
4618 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4619 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4620 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4621 tcg_temp_free(t0);
12de9a39
JM
4622#endif
4623}
f6b868fc
BS
4624
4625/* slbmte */
e8eaa2c0 4626static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4627{
4628#if defined(CONFIG_USER_ONLY)
4629 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4630#else
4631 if (unlikely(!ctx->mem_idx)) {
4632 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4633 return;
4634 }
c6c7cf05
BS
4635 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4636 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4637#endif
4638}
4639
efdef95f
DG
4640static void gen_slbmfee(DisasContext *ctx)
4641{
4642#if defined(CONFIG_USER_ONLY)
4643 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4644#else
4645 if (unlikely(!ctx->mem_idx)) {
4646 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4647 return;
4648 }
c6c7cf05 4649 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4650 cpu_gpr[rB(ctx->opcode)]);
4651#endif
4652}
4653
4654static void gen_slbmfev(DisasContext *ctx)
4655{
4656#if defined(CONFIG_USER_ONLY)
4657 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4658#else
4659 if (unlikely(!ctx->mem_idx)) {
4660 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4661 return;
4662 }
c6c7cf05 4663 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4664 cpu_gpr[rB(ctx->opcode)]);
4665#endif
4666}
12de9a39
JM
4667#endif /* defined(TARGET_PPC64) */
4668
79aceca5 4669/*** Lookaside buffer management ***/
76db3ba4 4670/* Optional & mem_idx only: */
99e300ef 4671
54623277 4672/* tlbia */
99e300ef 4673static void gen_tlbia(DisasContext *ctx)
79aceca5 4674{
9a64fbe4 4675#if defined(CONFIG_USER_ONLY)
e06fcd75 4676 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4677#else
76db3ba4 4678 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4679 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4680 return;
9a64fbe4 4681 }
c6c7cf05 4682 gen_helper_tlbia(cpu_env);
9a64fbe4 4683#endif
79aceca5
FB
4684}
4685
bf14b1ce 4686/* tlbiel */
99e300ef 4687static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4688{
4689#if defined(CONFIG_USER_ONLY)
4690 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4691#else
4692 if (unlikely(!ctx->mem_idx)) {
4693 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4694 return;
4695 }
c6c7cf05 4696 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4697#endif
4698}
4699
79aceca5 4700/* tlbie */
99e300ef 4701static void gen_tlbie(DisasContext *ctx)
79aceca5 4702{
9a64fbe4 4703#if defined(CONFIG_USER_ONLY)
e06fcd75 4704 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4705#else
76db3ba4 4706 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4707 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4708 return;
9a64fbe4 4709 }
9ca3f7f3 4710 if (NARROW_MODE(ctx)) {
74d37793
AJ
4711 TCGv t0 = tcg_temp_new();
4712 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4713 gen_helper_tlbie(cpu_env, t0);
74d37793 4714 tcg_temp_free(t0);
9ca3f7f3 4715 } else {
c6c7cf05 4716 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4717 }
9a64fbe4 4718#endif
79aceca5
FB
4719}
4720
4721/* tlbsync */
99e300ef 4722static void gen_tlbsync(DisasContext *ctx)
79aceca5 4723{
9a64fbe4 4724#if defined(CONFIG_USER_ONLY)
e06fcd75 4725 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4726#else
76db3ba4 4727 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4728 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4729 return;
9a64fbe4
FB
4730 }
4731 /* This has no effect: it should ensure that all previous
4732 * tlbie have completed
4733 */
e06fcd75 4734 gen_stop_exception(ctx);
9a64fbe4 4735#endif
79aceca5
FB
4736}
4737
426613db
JM
4738#if defined(TARGET_PPC64)
4739/* slbia */
99e300ef 4740static void gen_slbia(DisasContext *ctx)
426613db
JM
4741{
4742#if defined(CONFIG_USER_ONLY)
e06fcd75 4743 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4744#else
76db3ba4 4745 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4746 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4747 return;
4748 }
c6c7cf05 4749 gen_helper_slbia(cpu_env);
426613db
JM
4750#endif
4751}
4752
4753/* slbie */
99e300ef 4754static void gen_slbie(DisasContext *ctx)
426613db
JM
4755{
4756#if defined(CONFIG_USER_ONLY)
e06fcd75 4757 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4758#else
76db3ba4 4759 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4760 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4761 return;
4762 }
c6c7cf05 4763 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4764#endif
4765}
4766#endif
4767
79aceca5
FB
4768/*** External control ***/
4769/* Optional: */
99e300ef 4770
54623277 4771/* eciwx */
99e300ef 4772static void gen_eciwx(DisasContext *ctx)
79aceca5 4773{
76db3ba4 4774 TCGv t0;
fa407c03 4775 /* Should check EAR[E] ! */
76db3ba4
AJ
4776 gen_set_access_type(ctx, ACCESS_EXT);
4777 t0 = tcg_temp_new();
4778 gen_addr_reg_index(ctx, t0);
fa407c03 4779 gen_check_align(ctx, t0, 0x03);
76db3ba4 4780 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4781 tcg_temp_free(t0);
76a66253
JM
4782}
4783
4784/* ecowx */
99e300ef 4785static void gen_ecowx(DisasContext *ctx)
76a66253 4786{
76db3ba4 4787 TCGv t0;
fa407c03 4788 /* Should check EAR[E] ! */
76db3ba4
AJ
4789 gen_set_access_type(ctx, ACCESS_EXT);
4790 t0 = tcg_temp_new();
4791 gen_addr_reg_index(ctx, t0);
fa407c03 4792 gen_check_align(ctx, t0, 0x03);
76db3ba4 4793 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4794 tcg_temp_free(t0);
76a66253
JM
4795}
4796
4797/* PowerPC 601 specific instructions */
99e300ef 4798
54623277 4799/* abs - abs. */
99e300ef 4800static void gen_abs(DisasContext *ctx)
76a66253 4801{
22e0e173
AJ
4802 int l1 = gen_new_label();
4803 int l2 = gen_new_label();
4804 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4805 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4806 tcg_gen_br(l2);
4807 gen_set_label(l1);
4808 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4809 gen_set_label(l2);
76a66253 4810 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4811 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4812}
4813
4814/* abso - abso. */
99e300ef 4815static void gen_abso(DisasContext *ctx)
76a66253 4816{
22e0e173
AJ
4817 int l1 = gen_new_label();
4818 int l2 = gen_new_label();
4819 int l3 = gen_new_label();
4820 /* Start with XER OV disabled, the most likely case */
da91a00f 4821 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4822 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4823 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4824 tcg_gen_movi_tl(cpu_ov, 1);
4825 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4826 tcg_gen_br(l2);
4827 gen_set_label(l1);
4828 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4829 tcg_gen_br(l3);
4830 gen_set_label(l2);
4831 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4832 gen_set_label(l3);
76a66253 4833 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4834 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4835}
4836
4837/* clcs */
99e300ef 4838static void gen_clcs(DisasContext *ctx)
76a66253 4839{
22e0e173 4840 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4841 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4842 tcg_temp_free_i32(t0);
c7697e1f 4843 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
4844}
4845
4846/* div - div. */
99e300ef 4847static void gen_div(DisasContext *ctx)
76a66253 4848{
d15f74fb
BS
4849 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4850 cpu_gpr[rB(ctx->opcode)]);
76a66253 4851 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4852 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4853}
4854
4855/* divo - divo. */
99e300ef 4856static void gen_divo(DisasContext *ctx)
76a66253 4857{
d15f74fb
BS
4858 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4859 cpu_gpr[rB(ctx->opcode)]);
76a66253 4860 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4861 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4862}
4863
4864/* divs - divs. */
99e300ef 4865static void gen_divs(DisasContext *ctx)
76a66253 4866{
d15f74fb
BS
4867 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4868 cpu_gpr[rB(ctx->opcode)]);
76a66253 4869 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4870 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4871}
4872
4873/* divso - divso. */
99e300ef 4874static void gen_divso(DisasContext *ctx)
76a66253 4875{
d15f74fb
BS
4876 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4877 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 4878 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4879 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4880}
4881
4882/* doz - doz. */
99e300ef 4883static void gen_doz(DisasContext *ctx)
76a66253 4884{
22e0e173
AJ
4885 int l1 = gen_new_label();
4886 int l2 = gen_new_label();
4887 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4888 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4889 tcg_gen_br(l2);
4890 gen_set_label(l1);
4891 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4892 gen_set_label(l2);
76a66253 4893 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4894 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4895}
4896
4897/* dozo - dozo. */
99e300ef 4898static void gen_dozo(DisasContext *ctx)
76a66253 4899{
22e0e173
AJ
4900 int l1 = gen_new_label();
4901 int l2 = gen_new_label();
4902 TCGv t0 = tcg_temp_new();
4903 TCGv t1 = tcg_temp_new();
4904 TCGv t2 = tcg_temp_new();
4905 /* Start with XER OV disabled, the most likely case */
da91a00f 4906 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4907 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4908 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4909 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4910 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4911 tcg_gen_andc_tl(t1, t1, t2);
4912 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4913 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
4914 tcg_gen_movi_tl(cpu_ov, 1);
4915 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4916 tcg_gen_br(l2);
4917 gen_set_label(l1);
4918 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4919 gen_set_label(l2);
4920 tcg_temp_free(t0);
4921 tcg_temp_free(t1);
4922 tcg_temp_free(t2);
76a66253 4923 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4924 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4925}
4926
4927/* dozi */
99e300ef 4928static void gen_dozi(DisasContext *ctx)
76a66253 4929{
22e0e173
AJ
4930 target_long simm = SIMM(ctx->opcode);
4931 int l1 = gen_new_label();
4932 int l2 = gen_new_label();
4933 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
4934 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
4935 tcg_gen_br(l2);
4936 gen_set_label(l1);
4937 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4938 gen_set_label(l2);
4939 if (unlikely(Rc(ctx->opcode) != 0))
4940 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4941}
4942
76a66253 4943/* lscbx - lscbx. */
99e300ef 4944static void gen_lscbx(DisasContext *ctx)
76a66253 4945{
bdb4b689
AJ
4946 TCGv t0 = tcg_temp_new();
4947 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
4948 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
4949 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 4950
76db3ba4 4951 gen_addr_reg_index(ctx, t0);
76a66253 4952 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 4953 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 4954 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
4955 tcg_temp_free_i32(t1);
4956 tcg_temp_free_i32(t2);
4957 tcg_temp_free_i32(t3);
3d7b417e 4958 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 4959 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 4960 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
4961 gen_set_Rc0(ctx, t0);
4962 tcg_temp_free(t0);
76a66253
JM
4963}
4964
4965/* maskg - maskg. */
99e300ef 4966static void gen_maskg(DisasContext *ctx)
76a66253 4967{
22e0e173
AJ
4968 int l1 = gen_new_label();
4969 TCGv t0 = tcg_temp_new();
4970 TCGv t1 = tcg_temp_new();
4971 TCGv t2 = tcg_temp_new();
4972 TCGv t3 = tcg_temp_new();
4973 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
4974 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4975 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
4976 tcg_gen_addi_tl(t2, t0, 1);
4977 tcg_gen_shr_tl(t2, t3, t2);
4978 tcg_gen_shr_tl(t3, t3, t1);
4979 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
4980 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
4981 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4982 gen_set_label(l1);
4983 tcg_temp_free(t0);
4984 tcg_temp_free(t1);
4985 tcg_temp_free(t2);
4986 tcg_temp_free(t3);
76a66253 4987 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4988 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4989}
4990
4991/* maskir - maskir. */
99e300ef 4992static void gen_maskir(DisasContext *ctx)
76a66253 4993{
22e0e173
AJ
4994 TCGv t0 = tcg_temp_new();
4995 TCGv t1 = tcg_temp_new();
4996 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4997 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4998 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4999 tcg_temp_free(t0);
5000 tcg_temp_free(t1);
76a66253 5001 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5002 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5003}
5004
5005/* mul - mul. */
99e300ef 5006static void gen_mul(DisasContext *ctx)
76a66253 5007{
22e0e173
AJ
5008 TCGv_i64 t0 = tcg_temp_new_i64();
5009 TCGv_i64 t1 = tcg_temp_new_i64();
5010 TCGv t2 = tcg_temp_new();
5011 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5012 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5013 tcg_gen_mul_i64(t0, t0, t1);
5014 tcg_gen_trunc_i64_tl(t2, t0);
5015 gen_store_spr(SPR_MQ, t2);
5016 tcg_gen_shri_i64(t1, t0, 32);
5017 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5018 tcg_temp_free_i64(t0);
5019 tcg_temp_free_i64(t1);
5020 tcg_temp_free(t2);
76a66253 5021 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5022 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5023}
5024
5025/* mulo - mulo. */
99e300ef 5026static void gen_mulo(DisasContext *ctx)
76a66253 5027{
22e0e173
AJ
5028 int l1 = gen_new_label();
5029 TCGv_i64 t0 = tcg_temp_new_i64();
5030 TCGv_i64 t1 = tcg_temp_new_i64();
5031 TCGv t2 = tcg_temp_new();
5032 /* Start with XER OV disabled, the most likely case */
da91a00f 5033 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5034 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5035 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5036 tcg_gen_mul_i64(t0, t0, t1);
5037 tcg_gen_trunc_i64_tl(t2, t0);
5038 gen_store_spr(SPR_MQ, t2);
5039 tcg_gen_shri_i64(t1, t0, 32);
5040 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5041 tcg_gen_ext32s_i64(t1, t0);
5042 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
5043 tcg_gen_movi_tl(cpu_ov, 1);
5044 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5045 gen_set_label(l1);
5046 tcg_temp_free_i64(t0);
5047 tcg_temp_free_i64(t1);
5048 tcg_temp_free(t2);
76a66253 5049 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5050 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5051}
5052
5053/* nabs - nabs. */
99e300ef 5054static void gen_nabs(DisasContext *ctx)
76a66253 5055{
22e0e173
AJ
5056 int l1 = gen_new_label();
5057 int l2 = gen_new_label();
5058 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5059 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5060 tcg_gen_br(l2);
5061 gen_set_label(l1);
5062 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5063 gen_set_label(l2);
76a66253 5064 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5065 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5066}
5067
5068/* nabso - nabso. */
99e300ef 5069static void gen_nabso(DisasContext *ctx)
76a66253 5070{
22e0e173
AJ
5071 int l1 = gen_new_label();
5072 int l2 = gen_new_label();
5073 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5074 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5075 tcg_gen_br(l2);
5076 gen_set_label(l1);
5077 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5078 gen_set_label(l2);
5079 /* nabs never overflows */
da91a00f 5080 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 5081 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5082 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5083}
5084
5085/* rlmi - rlmi. */
99e300ef 5086static void gen_rlmi(DisasContext *ctx)
76a66253 5087{
7487953d
AJ
5088 uint32_t mb = MB(ctx->opcode);
5089 uint32_t me = ME(ctx->opcode);
5090 TCGv t0 = tcg_temp_new();
5091 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5092 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5093 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5094 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5095 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5096 tcg_temp_free(t0);
76a66253 5097 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5098 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5099}
5100
5101/* rrib - rrib. */
99e300ef 5102static void gen_rrib(DisasContext *ctx)
76a66253 5103{
7487953d
AJ
5104 TCGv t0 = tcg_temp_new();
5105 TCGv t1 = tcg_temp_new();
5106 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5107 tcg_gen_movi_tl(t1, 0x80000000);
5108 tcg_gen_shr_tl(t1, t1, t0);
5109 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5110 tcg_gen_and_tl(t0, t0, t1);
5111 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5112 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5113 tcg_temp_free(t0);
5114 tcg_temp_free(t1);
76a66253 5115 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5116 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5117}
5118
5119/* sle - sle. */
99e300ef 5120static void gen_sle(DisasContext *ctx)
76a66253 5121{
7487953d
AJ
5122 TCGv t0 = tcg_temp_new();
5123 TCGv t1 = tcg_temp_new();
5124 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5125 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5126 tcg_gen_subfi_tl(t1, 32, t1);
5127 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5128 tcg_gen_or_tl(t1, t0, t1);
5129 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5130 gen_store_spr(SPR_MQ, t1);
5131 tcg_temp_free(t0);
5132 tcg_temp_free(t1);
76a66253 5133 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5134 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5135}
5136
5137/* sleq - sleq. */
99e300ef 5138static void gen_sleq(DisasContext *ctx)
76a66253 5139{
7487953d
AJ
5140 TCGv t0 = tcg_temp_new();
5141 TCGv t1 = tcg_temp_new();
5142 TCGv t2 = tcg_temp_new();
5143 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5144 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5145 tcg_gen_shl_tl(t2, t2, t0);
5146 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5147 gen_load_spr(t1, SPR_MQ);
5148 gen_store_spr(SPR_MQ, t0);
5149 tcg_gen_and_tl(t0, t0, t2);
5150 tcg_gen_andc_tl(t1, t1, t2);
5151 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5152 tcg_temp_free(t0);
5153 tcg_temp_free(t1);
5154 tcg_temp_free(t2);
76a66253 5155 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5156 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5157}
5158
5159/* sliq - sliq. */
99e300ef 5160static void gen_sliq(DisasContext *ctx)
76a66253 5161{
7487953d
AJ
5162 int sh = SH(ctx->opcode);
5163 TCGv t0 = tcg_temp_new();
5164 TCGv t1 = tcg_temp_new();
5165 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5166 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5167 tcg_gen_or_tl(t1, t0, t1);
5168 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5169 gen_store_spr(SPR_MQ, t1);
5170 tcg_temp_free(t0);
5171 tcg_temp_free(t1);
76a66253 5172 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5173 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5174}
5175
5176/* slliq - slliq. */
99e300ef 5177static void gen_slliq(DisasContext *ctx)
76a66253 5178{
7487953d
AJ
5179 int sh = SH(ctx->opcode);
5180 TCGv t0 = tcg_temp_new();
5181 TCGv t1 = tcg_temp_new();
5182 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5183 gen_load_spr(t1, SPR_MQ);
5184 gen_store_spr(SPR_MQ, t0);
5185 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5186 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5187 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5188 tcg_temp_free(t0);
5189 tcg_temp_free(t1);
76a66253 5190 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5191 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5192}
5193
5194/* sllq - sllq. */
99e300ef 5195static void gen_sllq(DisasContext *ctx)
76a66253 5196{
7487953d
AJ
5197 int l1 = gen_new_label();
5198 int l2 = gen_new_label();
5199 TCGv t0 = tcg_temp_local_new();
5200 TCGv t1 = tcg_temp_local_new();
5201 TCGv t2 = tcg_temp_local_new();
5202 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5203 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5204 tcg_gen_shl_tl(t1, t1, t2);
5205 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5206 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5207 gen_load_spr(t0, SPR_MQ);
5208 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5209 tcg_gen_br(l2);
5210 gen_set_label(l1);
5211 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5212 gen_load_spr(t2, SPR_MQ);
5213 tcg_gen_andc_tl(t1, t2, t1);
5214 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5215 gen_set_label(l2);
5216 tcg_temp_free(t0);
5217 tcg_temp_free(t1);
5218 tcg_temp_free(t2);
76a66253 5219 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5220 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5221}
5222
5223/* slq - slq. */
99e300ef 5224static void gen_slq(DisasContext *ctx)
76a66253 5225{
7487953d
AJ
5226 int l1 = gen_new_label();
5227 TCGv t0 = tcg_temp_new();
5228 TCGv t1 = tcg_temp_new();
5229 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5230 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5231 tcg_gen_subfi_tl(t1, 32, t1);
5232 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5233 tcg_gen_or_tl(t1, t0, t1);
5234 gen_store_spr(SPR_MQ, t1);
5235 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5236 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5237 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5238 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5239 gen_set_label(l1);
5240 tcg_temp_free(t0);
5241 tcg_temp_free(t1);
76a66253 5242 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5243 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5244}
5245
d9bce9d9 5246/* sraiq - sraiq. */
99e300ef 5247static void gen_sraiq(DisasContext *ctx)
76a66253 5248{
7487953d
AJ
5249 int sh = SH(ctx->opcode);
5250 int l1 = gen_new_label();
5251 TCGv t0 = tcg_temp_new();
5252 TCGv t1 = tcg_temp_new();
5253 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5254 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5255 tcg_gen_or_tl(t0, t0, t1);
5256 gen_store_spr(SPR_MQ, t0);
da91a00f 5257 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5258 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5259 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5260 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5261 gen_set_label(l1);
5262 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5263 tcg_temp_free(t0);
5264 tcg_temp_free(t1);
76a66253 5265 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5266 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5267}
5268
5269/* sraq - sraq. */
99e300ef 5270static void gen_sraq(DisasContext *ctx)
76a66253 5271{
7487953d
AJ
5272 int l1 = gen_new_label();
5273 int l2 = gen_new_label();
5274 TCGv t0 = tcg_temp_new();
5275 TCGv t1 = tcg_temp_local_new();
5276 TCGv t2 = tcg_temp_local_new();
5277 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5278 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5279 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5280 tcg_gen_subfi_tl(t2, 32, t2);
5281 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5282 tcg_gen_or_tl(t0, t0, t2);
5283 gen_store_spr(SPR_MQ, t0);
5284 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5285 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5286 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5287 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5288 gen_set_label(l1);
5289 tcg_temp_free(t0);
5290 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5291 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5292 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5293 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5294 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5295 gen_set_label(l2);
5296 tcg_temp_free(t1);
5297 tcg_temp_free(t2);
76a66253 5298 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5299 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5300}
5301
5302/* sre - sre. */
99e300ef 5303static void gen_sre(DisasContext *ctx)
76a66253 5304{
7487953d
AJ
5305 TCGv t0 = tcg_temp_new();
5306 TCGv t1 = tcg_temp_new();
5307 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5308 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5309 tcg_gen_subfi_tl(t1, 32, t1);
5310 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5311 tcg_gen_or_tl(t1, t0, t1);
5312 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5313 gen_store_spr(SPR_MQ, t1);
5314 tcg_temp_free(t0);
5315 tcg_temp_free(t1);
76a66253 5316 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5317 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5318}
5319
5320/* srea - srea. */
99e300ef 5321static void gen_srea(DisasContext *ctx)
76a66253 5322{
7487953d
AJ
5323 TCGv t0 = tcg_temp_new();
5324 TCGv t1 = tcg_temp_new();
5325 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5326 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5327 gen_store_spr(SPR_MQ, t0);
5328 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5329 tcg_temp_free(t0);
5330 tcg_temp_free(t1);
76a66253 5331 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5332 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5333}
5334
5335/* sreq */
99e300ef 5336static void gen_sreq(DisasContext *ctx)
76a66253 5337{
7487953d
AJ
5338 TCGv t0 = tcg_temp_new();
5339 TCGv t1 = tcg_temp_new();
5340 TCGv t2 = tcg_temp_new();
5341 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5342 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5343 tcg_gen_shr_tl(t1, t1, t0);
5344 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5345 gen_load_spr(t2, SPR_MQ);
5346 gen_store_spr(SPR_MQ, t0);
5347 tcg_gen_and_tl(t0, t0, t1);
5348 tcg_gen_andc_tl(t2, t2, t1);
5349 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5350 tcg_temp_free(t0);
5351 tcg_temp_free(t1);
5352 tcg_temp_free(t2);
76a66253 5353 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5354 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5355}
5356
5357/* sriq */
99e300ef 5358static void gen_sriq(DisasContext *ctx)
76a66253 5359{
7487953d
AJ
5360 int sh = SH(ctx->opcode);
5361 TCGv t0 = tcg_temp_new();
5362 TCGv t1 = tcg_temp_new();
5363 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5364 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5365 tcg_gen_or_tl(t1, t0, t1);
5366 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5367 gen_store_spr(SPR_MQ, t1);
5368 tcg_temp_free(t0);
5369 tcg_temp_free(t1);
76a66253 5370 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5371 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5372}
5373
5374/* srliq */
99e300ef 5375static void gen_srliq(DisasContext *ctx)
76a66253 5376{
7487953d
AJ
5377 int sh = SH(ctx->opcode);
5378 TCGv t0 = tcg_temp_new();
5379 TCGv t1 = tcg_temp_new();
5380 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5381 gen_load_spr(t1, SPR_MQ);
5382 gen_store_spr(SPR_MQ, t0);
5383 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5384 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5385 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5386 tcg_temp_free(t0);
5387 tcg_temp_free(t1);
76a66253 5388 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5389 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5390}
5391
5392/* srlq */
99e300ef 5393static void gen_srlq(DisasContext *ctx)
76a66253 5394{
7487953d
AJ
5395 int l1 = gen_new_label();
5396 int l2 = gen_new_label();
5397 TCGv t0 = tcg_temp_local_new();
5398 TCGv t1 = tcg_temp_local_new();
5399 TCGv t2 = tcg_temp_local_new();
5400 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5401 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5402 tcg_gen_shr_tl(t2, t1, t2);
5403 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5404 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5405 gen_load_spr(t0, SPR_MQ);
5406 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5407 tcg_gen_br(l2);
5408 gen_set_label(l1);
5409 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5410 tcg_gen_and_tl(t0, t0, t2);
5411 gen_load_spr(t1, SPR_MQ);
5412 tcg_gen_andc_tl(t1, t1, t2);
5413 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5414 gen_set_label(l2);
5415 tcg_temp_free(t0);
5416 tcg_temp_free(t1);
5417 tcg_temp_free(t2);
76a66253 5418 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5419 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5420}
5421
5422/* srq */
99e300ef 5423static void gen_srq(DisasContext *ctx)
76a66253 5424{
7487953d
AJ
5425 int l1 = gen_new_label();
5426 TCGv t0 = tcg_temp_new();
5427 TCGv t1 = tcg_temp_new();
5428 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5429 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5430 tcg_gen_subfi_tl(t1, 32, t1);
5431 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5432 tcg_gen_or_tl(t1, t0, t1);
5433 gen_store_spr(SPR_MQ, t1);
5434 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5435 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5436 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5437 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5438 gen_set_label(l1);
5439 tcg_temp_free(t0);
5440 tcg_temp_free(t1);
76a66253 5441 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5442 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5443}
5444
5445/* PowerPC 602 specific instructions */
99e300ef 5446
54623277 5447/* dsa */
99e300ef 5448static void gen_dsa(DisasContext *ctx)
76a66253
JM
5449{
5450 /* XXX: TODO */
e06fcd75 5451 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5452}
5453
5454/* esa */
99e300ef 5455static void gen_esa(DisasContext *ctx)
76a66253
JM
5456{
5457 /* XXX: TODO */
e06fcd75 5458 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5459}
5460
5461/* mfrom */
99e300ef 5462static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5463{
5464#if defined(CONFIG_USER_ONLY)
e06fcd75 5465 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5466#else
76db3ba4 5467 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5468 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5469 return;
5470 }
cf02a65c 5471 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5472#endif
5473}
5474
5475/* 602 - 603 - G2 TLB management */
e8eaa2c0 5476
54623277 5477/* tlbld */
e8eaa2c0 5478static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5479{
5480#if defined(CONFIG_USER_ONLY)
e06fcd75 5481 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5482#else
76db3ba4 5483 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5484 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5485 return;
5486 }
c6c7cf05 5487 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5488#endif
5489}
5490
5491/* tlbli */
e8eaa2c0 5492static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5493{
5494#if defined(CONFIG_USER_ONLY)
e06fcd75 5495 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5496#else
76db3ba4 5497 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5498 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5499 return;
5500 }
c6c7cf05 5501 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5502#endif
5503}
5504
7dbe11ac 5505/* 74xx TLB management */
e8eaa2c0 5506
54623277 5507/* tlbld */
e8eaa2c0 5508static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5509{
5510#if defined(CONFIG_USER_ONLY)
e06fcd75 5511 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5512#else
76db3ba4 5513 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5514 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5515 return;
5516 }
c6c7cf05 5517 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5518#endif
5519}
5520
5521/* tlbli */
e8eaa2c0 5522static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5523{
5524#if defined(CONFIG_USER_ONLY)
e06fcd75 5525 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5526#else
76db3ba4 5527 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5528 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5529 return;
5530 }
c6c7cf05 5531 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5532#endif
5533}
5534
76a66253 5535/* POWER instructions not in PowerPC 601 */
99e300ef 5536
54623277 5537/* clf */
99e300ef 5538static void gen_clf(DisasContext *ctx)
76a66253
JM
5539{
5540 /* Cache line flush: implemented as no-op */
5541}
5542
5543/* cli */
99e300ef 5544static void gen_cli(DisasContext *ctx)
76a66253 5545{
7f75ffd3 5546 /* Cache line invalidate: privileged and treated as no-op */
76a66253 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 }
5554#endif
5555}
5556
5557/* dclst */
99e300ef 5558static void gen_dclst(DisasContext *ctx)
76a66253
JM
5559{
5560 /* Data cache line store: treated as no-op */
5561}
5562
99e300ef 5563static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5564{
5565#if defined(CONFIG_USER_ONLY)
e06fcd75 5566 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5567#else
74d37793
AJ
5568 int ra = rA(ctx->opcode);
5569 int rd = rD(ctx->opcode);
5570 TCGv t0;
76db3ba4 5571 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5572 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5573 return;
5574 }
74d37793 5575 t0 = tcg_temp_new();
76db3ba4 5576 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5577 tcg_gen_shri_tl(t0, t0, 28);
5578 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5579 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5580 tcg_temp_free(t0);
76a66253 5581 if (ra != 0 && ra != rd)
74d37793 5582 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5583#endif
5584}
5585
99e300ef 5586static void gen_rac(DisasContext *ctx)
76a66253
JM
5587{
5588#if defined(CONFIG_USER_ONLY)
e06fcd75 5589 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5590#else
22e0e173 5591 TCGv t0;
76db3ba4 5592 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5593 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5594 return;
5595 }
22e0e173 5596 t0 = tcg_temp_new();
76db3ba4 5597 gen_addr_reg_index(ctx, t0);
c6c7cf05 5598 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5599 tcg_temp_free(t0);
76a66253
JM
5600#endif
5601}
5602
99e300ef 5603static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5604{
5605#if defined(CONFIG_USER_ONLY)
e06fcd75 5606 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5607#else
76db3ba4 5608 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5609 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5610 return;
5611 }
e5f17ac6 5612 gen_helper_rfsvc(cpu_env);
e06fcd75 5613 gen_sync_exception(ctx);
76a66253
JM
5614#endif
5615}
5616
5617/* svc is not implemented for now */
5618
5619/* POWER2 specific instructions */
5620/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5621
5622/* lfq */
99e300ef 5623static void gen_lfq(DisasContext *ctx)
76a66253 5624{
01a4afeb 5625 int rd = rD(ctx->opcode);
76db3ba4
AJ
5626 TCGv t0;
5627 gen_set_access_type(ctx, ACCESS_FLOAT);
5628 t0 = tcg_temp_new();
5629 gen_addr_imm_index(ctx, t0, 0);
5630 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5631 gen_addr_add(ctx, t0, t0, 8);
5632 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5633 tcg_temp_free(t0);
76a66253
JM
5634}
5635
5636/* lfqu */
99e300ef 5637static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5638{
5639 int ra = rA(ctx->opcode);
01a4afeb 5640 int rd = rD(ctx->opcode);
76db3ba4
AJ
5641 TCGv t0, t1;
5642 gen_set_access_type(ctx, ACCESS_FLOAT);
5643 t0 = tcg_temp_new();
5644 t1 = tcg_temp_new();
5645 gen_addr_imm_index(ctx, t0, 0);
5646 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5647 gen_addr_add(ctx, t1, t0, 8);
5648 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5649 if (ra != 0)
01a4afeb
AJ
5650 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5651 tcg_temp_free(t0);
5652 tcg_temp_free(t1);
76a66253
JM
5653}
5654
5655/* lfqux */
99e300ef 5656static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5657{
5658 int ra = rA(ctx->opcode);
01a4afeb 5659 int rd = rD(ctx->opcode);
76db3ba4
AJ
5660 gen_set_access_type(ctx, ACCESS_FLOAT);
5661 TCGv t0, t1;
5662 t0 = tcg_temp_new();
5663 gen_addr_reg_index(ctx, t0);
5664 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5665 t1 = tcg_temp_new();
5666 gen_addr_add(ctx, t1, t0, 8);
5667 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5668 tcg_temp_free(t1);
76a66253 5669 if (ra != 0)
01a4afeb
AJ
5670 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5671 tcg_temp_free(t0);
76a66253
JM
5672}
5673
5674/* lfqx */
99e300ef 5675static void gen_lfqx(DisasContext *ctx)
76a66253 5676{
01a4afeb 5677 int rd = rD(ctx->opcode);
76db3ba4
AJ
5678 TCGv t0;
5679 gen_set_access_type(ctx, ACCESS_FLOAT);
5680 t0 = tcg_temp_new();
5681 gen_addr_reg_index(ctx, t0);
5682 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5683 gen_addr_add(ctx, t0, t0, 8);
5684 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5685 tcg_temp_free(t0);
76a66253
JM
5686}
5687
5688/* stfq */
99e300ef 5689static void gen_stfq(DisasContext *ctx)
76a66253 5690{
01a4afeb 5691 int rd = rD(ctx->opcode);
76db3ba4
AJ
5692 TCGv t0;
5693 gen_set_access_type(ctx, ACCESS_FLOAT);
5694 t0 = tcg_temp_new();
5695 gen_addr_imm_index(ctx, t0, 0);
5696 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5697 gen_addr_add(ctx, t0, t0, 8);
5698 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5699 tcg_temp_free(t0);
76a66253
JM
5700}
5701
5702/* stfqu */
99e300ef 5703static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5704{
5705 int ra = rA(ctx->opcode);
01a4afeb 5706 int rd = rD(ctx->opcode);
76db3ba4
AJ
5707 TCGv t0, t1;
5708 gen_set_access_type(ctx, ACCESS_FLOAT);
5709 t0 = tcg_temp_new();
5710 gen_addr_imm_index(ctx, t0, 0);
5711 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5712 t1 = tcg_temp_new();
5713 gen_addr_add(ctx, t1, t0, 8);
5714 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5715 tcg_temp_free(t1);
76a66253 5716 if (ra != 0)
01a4afeb
AJ
5717 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5718 tcg_temp_free(t0);
76a66253
JM
5719}
5720
5721/* stfqux */
99e300ef 5722static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5723{
5724 int ra = rA(ctx->opcode);
01a4afeb 5725 int rd = rD(ctx->opcode);
76db3ba4
AJ
5726 TCGv t0, t1;
5727 gen_set_access_type(ctx, ACCESS_FLOAT);
5728 t0 = tcg_temp_new();
5729 gen_addr_reg_index(ctx, t0);
5730 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5731 t1 = tcg_temp_new();
5732 gen_addr_add(ctx, t1, t0, 8);
5733 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5734 tcg_temp_free(t1);
76a66253 5735 if (ra != 0)
01a4afeb
AJ
5736 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5737 tcg_temp_free(t0);
76a66253
JM
5738}
5739
5740/* stfqx */
99e300ef 5741static void gen_stfqx(DisasContext *ctx)
76a66253 5742{
01a4afeb 5743 int rd = rD(ctx->opcode);
76db3ba4
AJ
5744 TCGv t0;
5745 gen_set_access_type(ctx, ACCESS_FLOAT);
5746 t0 = tcg_temp_new();
5747 gen_addr_reg_index(ctx, t0);
5748 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5749 gen_addr_add(ctx, t0, t0, 8);
5750 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5751 tcg_temp_free(t0);
76a66253
JM
5752}
5753
5754/* BookE specific instructions */
99e300ef 5755
54623277 5756/* XXX: not implemented on 440 ? */
99e300ef 5757static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5758{
5759 /* XXX: TODO */
e06fcd75 5760 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5761}
5762
2662a059 5763/* XXX: not implemented on 440 ? */
99e300ef 5764static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5765{
5766#if defined(CONFIG_USER_ONLY)
e06fcd75 5767 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5768#else
74d37793 5769 TCGv t0;
76db3ba4 5770 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5771 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5772 return;
5773 }
ec72e276 5774 t0 = tcg_temp_new();
76db3ba4 5775 gen_addr_reg_index(ctx, t0);
c6c7cf05 5776 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5777 tcg_temp_free(t0);
76a66253
JM
5778#endif
5779}
5780
5781/* All 405 MAC instructions are translated here */
636aa200
BS
5782static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5783 int ra, int rb, int rt, int Rc)
76a66253 5784{
182608d4
AJ
5785 TCGv t0, t1;
5786
a7812ae4
PB
5787 t0 = tcg_temp_local_new();
5788 t1 = tcg_temp_local_new();
182608d4 5789
76a66253
JM
5790 switch (opc3 & 0x0D) {
5791 case 0x05:
5792 /* macchw - macchw. - macchwo - macchwo. */
5793 /* macchws - macchws. - macchwso - macchwso. */
5794 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5795 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5796 /* mulchw - mulchw. */
182608d4
AJ
5797 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5798 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5799 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5800 break;
5801 case 0x04:
5802 /* macchwu - macchwu. - macchwuo - macchwuo. */
5803 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5804 /* mulchwu - mulchwu. */
182608d4
AJ
5805 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5806 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5807 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5808 break;
5809 case 0x01:
5810 /* machhw - machhw. - machhwo - machhwo. */
5811 /* machhws - machhws. - machhwso - machhwso. */
5812 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5813 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5814 /* mulhhw - mulhhw. */
182608d4
AJ
5815 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5816 tcg_gen_ext16s_tl(t0, t0);
5817 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5818 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5819 break;
5820 case 0x00:
5821 /* machhwu - machhwu. - machhwuo - machhwuo. */
5822 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5823 /* mulhhwu - mulhhwu. */
182608d4
AJ
5824 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5825 tcg_gen_ext16u_tl(t0, t0);
5826 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5827 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5828 break;
5829 case 0x0D:
5830 /* maclhw - maclhw. - maclhwo - maclhwo. */
5831 /* maclhws - maclhws. - maclhwso - maclhwso. */
5832 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5833 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5834 /* mullhw - mullhw. */
182608d4
AJ
5835 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5836 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5837 break;
5838 case 0x0C:
5839 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5840 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5841 /* mullhwu - mullhwu. */
182608d4
AJ
5842 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5843 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
5844 break;
5845 }
76a66253 5846 if (opc2 & 0x04) {
182608d4
AJ
5847 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5848 tcg_gen_mul_tl(t1, t0, t1);
5849 if (opc2 & 0x02) {
5850 /* nmultiply-and-accumulate (0x0E) */
5851 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5852 } else {
5853 /* multiply-and-accumulate (0x0C) */
5854 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5855 }
5856
5857 if (opc3 & 0x12) {
5858 /* Check overflow and/or saturate */
5859 int l1 = gen_new_label();
5860
5861 if (opc3 & 0x10) {
5862 /* Start with XER OV disabled, the most likely case */
da91a00f 5863 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
5864 }
5865 if (opc3 & 0x01) {
5866 /* Signed */
5867 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5868 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5869 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5870 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 5871 if (opc3 & 0x02) {
182608d4
AJ
5872 /* Saturate */
5873 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5874 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5875 }
5876 } else {
5877 /* Unsigned */
5878 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 5879 if (opc3 & 0x02) {
182608d4
AJ
5880 /* Saturate */
5881 tcg_gen_movi_tl(t0, UINT32_MAX);
5882 }
5883 }
5884 if (opc3 & 0x10) {
5885 /* Check overflow */
da91a00f
RH
5886 tcg_gen_movi_tl(cpu_ov, 1);
5887 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
5888 }
5889 gen_set_label(l1);
5890 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5891 }
5892 } else {
5893 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 5894 }
182608d4
AJ
5895 tcg_temp_free(t0);
5896 tcg_temp_free(t1);
76a66253
JM
5897 if (unlikely(Rc) != 0) {
5898 /* Update Rc0 */
182608d4 5899 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
5900 }
5901}
5902
a750fc0b 5903#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 5904static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
5905{ \
5906 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5907 rD(ctx->opcode), Rc(ctx->opcode)); \
5908}
5909
5910/* macchw - macchw. */
a750fc0b 5911GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 5912/* macchwo - macchwo. */
a750fc0b 5913GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 5914/* macchws - macchws. */
a750fc0b 5915GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 5916/* macchwso - macchwso. */
a750fc0b 5917GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 5918/* macchwsu - macchwsu. */
a750fc0b 5919GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 5920/* macchwsuo - macchwsuo. */
a750fc0b 5921GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 5922/* macchwu - macchwu. */
a750fc0b 5923GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 5924/* macchwuo - macchwuo. */
a750fc0b 5925GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 5926/* machhw - machhw. */
a750fc0b 5927GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 5928/* machhwo - machhwo. */
a750fc0b 5929GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 5930/* machhws - machhws. */
a750fc0b 5931GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 5932/* machhwso - machhwso. */
a750fc0b 5933GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 5934/* machhwsu - machhwsu. */
a750fc0b 5935GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 5936/* machhwsuo - machhwsuo. */
a750fc0b 5937GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 5938/* machhwu - machhwu. */
a750fc0b 5939GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 5940/* machhwuo - machhwuo. */
a750fc0b 5941GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 5942/* maclhw - maclhw. */
a750fc0b 5943GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 5944/* maclhwo - maclhwo. */
a750fc0b 5945GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 5946/* maclhws - maclhws. */
a750fc0b 5947GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 5948/* maclhwso - maclhwso. */
a750fc0b 5949GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 5950/* maclhwu - maclhwu. */
a750fc0b 5951GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 5952/* maclhwuo - maclhwuo. */
a750fc0b 5953GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 5954/* maclhwsu - maclhwsu. */
a750fc0b 5955GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 5956/* maclhwsuo - maclhwsuo. */
a750fc0b 5957GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 5958/* nmacchw - nmacchw. */
a750fc0b 5959GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 5960/* nmacchwo - nmacchwo. */
a750fc0b 5961GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 5962/* nmacchws - nmacchws. */
a750fc0b 5963GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 5964/* nmacchwso - nmacchwso. */
a750fc0b 5965GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 5966/* nmachhw - nmachhw. */
a750fc0b 5967GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 5968/* nmachhwo - nmachhwo. */
a750fc0b 5969GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 5970/* nmachhws - nmachhws. */
a750fc0b 5971GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 5972/* nmachhwso - nmachhwso. */
a750fc0b 5973GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 5974/* nmaclhw - nmaclhw. */
a750fc0b 5975GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 5976/* nmaclhwo - nmaclhwo. */
a750fc0b 5977GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 5978/* nmaclhws - nmaclhws. */
a750fc0b 5979GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 5980/* nmaclhwso - nmaclhwso. */
a750fc0b 5981GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
5982
5983/* mulchw - mulchw. */
a750fc0b 5984GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 5985/* mulchwu - mulchwu. */
a750fc0b 5986GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 5987/* mulhhw - mulhhw. */
a750fc0b 5988GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 5989/* mulhhwu - mulhhwu. */
a750fc0b 5990GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 5991/* mullhw - mullhw. */
a750fc0b 5992GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 5993/* mullhwu - mullhwu. */
a750fc0b 5994GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
5995
5996/* mfdcr */
99e300ef 5997static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
5998{
5999#if defined(CONFIG_USER_ONLY)
e06fcd75 6000 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6001#else
06dca6a7 6002 TCGv dcrn;
76db3ba4 6003 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6004 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6005 return;
6006 }
06dca6a7
AJ
6007 /* NIP cannot be restored if the memory exception comes from an helper */
6008 gen_update_nip(ctx, ctx->nip - 4);
6009 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6010 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 6011 tcg_temp_free(dcrn);
76a66253
JM
6012#endif
6013}
6014
6015/* mtdcr */
99e300ef 6016static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
6017{
6018#if defined(CONFIG_USER_ONLY)
e06fcd75 6019 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6020#else
06dca6a7 6021 TCGv dcrn;
76db3ba4 6022 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6023 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6024 return;
6025 }
06dca6a7
AJ
6026 /* NIP cannot be restored if the memory exception comes from an helper */
6027 gen_update_nip(ctx, ctx->nip - 4);
6028 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6029 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 6030 tcg_temp_free(dcrn);
a42bd6cc
JM
6031#endif
6032}
6033
6034/* mfdcrx */
2662a059 6035/* XXX: not implemented on 440 ? */
99e300ef 6036static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
6037{
6038#if defined(CONFIG_USER_ONLY)
e06fcd75 6039 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6040#else
76db3ba4 6041 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6042 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6043 return;
6044 }
06dca6a7
AJ
6045 /* NIP cannot be restored if the memory exception comes from an helper */
6046 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6047 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6048 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 6049 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
6050#endif
6051}
6052
6053/* mtdcrx */
2662a059 6054/* XXX: not implemented on 440 ? */
99e300ef 6055static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
6056{
6057#if defined(CONFIG_USER_ONLY)
e06fcd75 6058 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6059#else
76db3ba4 6060 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6061 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6062 return;
6063 }
06dca6a7
AJ
6064 /* NIP cannot be restored if the memory exception comes from an helper */
6065 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6066 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6067 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 6068 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
6069#endif
6070}
6071
a750fc0b 6072/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6073static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 6074{
06dca6a7
AJ
6075 /* NIP cannot be restored if the memory exception comes from an helper */
6076 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6077 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6078 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
6079 /* Note: Rc update flag set leads to undefined state of Rc0 */
6080}
6081
6082/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6083static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 6084{
06dca6a7
AJ
6085 /* NIP cannot be restored if the memory exception comes from an helper */
6086 gen_update_nip(ctx, ctx->nip - 4);
975e5463 6087 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 6088 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
6089 /* Note: Rc update flag set leads to undefined state of Rc0 */
6090}
6091
76a66253 6092/* dccci */
99e300ef 6093static void gen_dccci(DisasContext *ctx)
76a66253
JM
6094{
6095#if defined(CONFIG_USER_ONLY)
e06fcd75 6096 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6097#else
76db3ba4 6098 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6099 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6100 return;
6101 }
6102 /* interpreted as no-op */
6103#endif
6104}
6105
6106/* dcread */
99e300ef 6107static void gen_dcread(DisasContext *ctx)
76a66253
JM
6108{
6109#if defined(CONFIG_USER_ONLY)
e06fcd75 6110 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6111#else
b61f2753 6112 TCGv EA, val;
76db3ba4 6113 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6114 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6115 return;
6116 }
76db3ba4 6117 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 6118 EA = tcg_temp_new();
76db3ba4 6119 gen_addr_reg_index(ctx, EA);
a7812ae4 6120 val = tcg_temp_new();
76db3ba4 6121 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
6122 tcg_temp_free(val);
6123 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6124 tcg_temp_free(EA);
76a66253
JM
6125#endif
6126}
6127
6128/* icbt */
e8eaa2c0 6129static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6130{
6131 /* interpreted as no-op */
6132 /* XXX: specification say this is treated as a load by the MMU
6133 * but does not generate any exception
6134 */
6135}
6136
6137/* iccci */
99e300ef 6138static void gen_iccci(DisasContext *ctx)
76a66253
JM
6139{
6140#if defined(CONFIG_USER_ONLY)
e06fcd75 6141 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6142#else
76db3ba4 6143 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6144 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6145 return;
6146 }
6147 /* interpreted as no-op */
6148#endif
6149}
6150
6151/* icread */
99e300ef 6152static void gen_icread(DisasContext *ctx)
76a66253
JM
6153{
6154#if defined(CONFIG_USER_ONLY)
e06fcd75 6155 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6156#else
76db3ba4 6157 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6158 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6159 return;
6160 }
6161 /* interpreted as no-op */
6162#endif
6163}
6164
76db3ba4 6165/* rfci (mem_idx only) */
e8eaa2c0 6166static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
6167{
6168#if defined(CONFIG_USER_ONLY)
e06fcd75 6169 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6170#else
76db3ba4 6171 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6172 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6173 return;
6174 }
6175 /* Restore CPU state */
e5f17ac6 6176 gen_helper_40x_rfci(cpu_env);
e06fcd75 6177 gen_sync_exception(ctx);
a42bd6cc
JM
6178#endif
6179}
6180
99e300ef 6181static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6182{
6183#if defined(CONFIG_USER_ONLY)
e06fcd75 6184 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6185#else
76db3ba4 6186 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6187 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6188 return;
6189 }
6190 /* Restore CPU state */
e5f17ac6 6191 gen_helper_rfci(cpu_env);
e06fcd75 6192 gen_sync_exception(ctx);
a42bd6cc
JM
6193#endif
6194}
6195
6196/* BookE specific */
99e300ef 6197
54623277 6198/* XXX: not implemented on 440 ? */
99e300ef 6199static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6200{
6201#if defined(CONFIG_USER_ONLY)
e06fcd75 6202 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6203#else
76db3ba4 6204 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6205 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6206 return;
6207 }
6208 /* Restore CPU state */
e5f17ac6 6209 gen_helper_rfdi(cpu_env);
e06fcd75 6210 gen_sync_exception(ctx);
76a66253
JM
6211#endif
6212}
6213
2662a059 6214/* XXX: not implemented on 440 ? */
99e300ef 6215static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6216{
6217#if defined(CONFIG_USER_ONLY)
e06fcd75 6218 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6219#else
76db3ba4 6220 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6221 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6222 return;
6223 }
6224 /* Restore CPU state */
e5f17ac6 6225 gen_helper_rfmci(cpu_env);
e06fcd75 6226 gen_sync_exception(ctx);
a42bd6cc
JM
6227#endif
6228}
5eb7995e 6229
d9bce9d9 6230/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6231
54623277 6232/* tlbre */
e8eaa2c0 6233static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6234{
6235#if defined(CONFIG_USER_ONLY)
e06fcd75 6236 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6237#else
76db3ba4 6238 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6239 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6240 return;
6241 }
6242 switch (rB(ctx->opcode)) {
6243 case 0:
c6c7cf05
BS
6244 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6245 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6246 break;
6247 case 1:
c6c7cf05
BS
6248 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6249 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6250 break;
6251 default:
e06fcd75 6252 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6253 break;
9a64fbe4 6254 }
76a66253
JM
6255#endif
6256}
6257
d9bce9d9 6258/* tlbsx - tlbsx. */
e8eaa2c0 6259static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6260{
6261#if defined(CONFIG_USER_ONLY)
e06fcd75 6262 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6263#else
74d37793 6264 TCGv t0;
76db3ba4 6265 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6266 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6267 return;
6268 }
74d37793 6269 t0 = tcg_temp_new();
76db3ba4 6270 gen_addr_reg_index(ctx, t0);
c6c7cf05 6271 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6272 tcg_temp_free(t0);
6273 if (Rc(ctx->opcode)) {
6274 int l1 = gen_new_label();
da91a00f 6275 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6276 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6277 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6278 gen_set_label(l1);
6279 }
76a66253 6280#endif
79aceca5
FB
6281}
6282
76a66253 6283/* tlbwe */
e8eaa2c0 6284static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6285{
76a66253 6286#if defined(CONFIG_USER_ONLY)
e06fcd75 6287 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6288#else
76db3ba4 6289 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6290 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6291 return;
6292 }
6293 switch (rB(ctx->opcode)) {
6294 case 0:
c6c7cf05
BS
6295 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6296 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6297 break;
6298 case 1:
c6c7cf05
BS
6299 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6300 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6301 break;
6302 default:
e06fcd75 6303 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6304 break;
9a64fbe4 6305 }
76a66253
JM
6306#endif
6307}
6308
a4bb6c3e 6309/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6310
54623277 6311/* tlbre */
e8eaa2c0 6312static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6313{
6314#if defined(CONFIG_USER_ONLY)
e06fcd75 6315 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6316#else
76db3ba4 6317 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6318 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6319 return;
6320 }
6321 switch (rB(ctx->opcode)) {
6322 case 0:
5eb7995e 6323 case 1:
5eb7995e 6324 case 2:
74d37793
AJ
6325 {
6326 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6327 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6328 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6329 tcg_temp_free_i32(t0);
6330 }
5eb7995e
JM
6331 break;
6332 default:
e06fcd75 6333 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6334 break;
6335 }
6336#endif
6337}
6338
6339/* tlbsx - tlbsx. */
e8eaa2c0 6340static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6341{
6342#if defined(CONFIG_USER_ONLY)
e06fcd75 6343 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6344#else
74d37793 6345 TCGv t0;
76db3ba4 6346 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6347 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6348 return;
6349 }
74d37793 6350 t0 = tcg_temp_new();
76db3ba4 6351 gen_addr_reg_index(ctx, t0);
c6c7cf05 6352 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6353 tcg_temp_free(t0);
6354 if (Rc(ctx->opcode)) {
6355 int l1 = gen_new_label();
da91a00f 6356 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6357 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6358 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6359 gen_set_label(l1);
6360 }
5eb7995e
JM
6361#endif
6362}
6363
6364/* tlbwe */
e8eaa2c0 6365static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
6366{
6367#if defined(CONFIG_USER_ONLY)
e06fcd75 6368 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6369#else
76db3ba4 6370 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6371 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6372 return;
6373 }
6374 switch (rB(ctx->opcode)) {
6375 case 0:
5eb7995e 6376 case 1:
5eb7995e 6377 case 2:
74d37793
AJ
6378 {
6379 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6380 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6381 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
6382 tcg_temp_free_i32(t0);
6383 }
5eb7995e
JM
6384 break;
6385 default:
e06fcd75 6386 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6387 break;
6388 }
6389#endif
6390}
6391
01662f3e
AG
6392/* TLB management - PowerPC BookE 2.06 implementation */
6393
6394/* tlbre */
6395static void gen_tlbre_booke206(DisasContext *ctx)
6396{
6397#if defined(CONFIG_USER_ONLY)
6398 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6399#else
6400 if (unlikely(!ctx->mem_idx)) {
6401 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6402 return;
6403 }
6404
c6c7cf05 6405 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6406#endif
6407}
6408
6409/* tlbsx - tlbsx. */
6410static void gen_tlbsx_booke206(DisasContext *ctx)
6411{
6412#if defined(CONFIG_USER_ONLY)
6413 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6414#else
6415 TCGv t0;
6416 if (unlikely(!ctx->mem_idx)) {
6417 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6418 return;
6419 }
6420
6421 if (rA(ctx->opcode)) {
6422 t0 = tcg_temp_new();
6423 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6424 } else {
6425 t0 = tcg_const_tl(0);
6426 }
6427
6428 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6429 gen_helper_booke206_tlbsx(cpu_env, t0);
01662f3e
AG
6430#endif
6431}
6432
6433/* tlbwe */
6434static void gen_tlbwe_booke206(DisasContext *ctx)
6435{
6436#if defined(CONFIG_USER_ONLY)
6437 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6438#else
6439 if (unlikely(!ctx->mem_idx)) {
6440 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6441 return;
6442 }
3f162d11 6443 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6444 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6445#endif
6446}
6447
6448static void gen_tlbivax_booke206(DisasContext *ctx)
6449{
6450#if defined(CONFIG_USER_ONLY)
6451 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6452#else
6453 TCGv t0;
6454 if (unlikely(!ctx->mem_idx)) {
6455 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6456 return;
6457 }
6458
6459 t0 = tcg_temp_new();
6460 gen_addr_reg_index(ctx, t0);
6461
c6c7cf05 6462 gen_helper_booke206_tlbivax(cpu_env, t0);
01662f3e
AG
6463#endif
6464}
6465
6d3db821
AG
6466static void gen_tlbilx_booke206(DisasContext *ctx)
6467{
6468#if defined(CONFIG_USER_ONLY)
6469 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6470#else
6471 TCGv t0;
6472 if (unlikely(!ctx->mem_idx)) {
6473 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6474 return;
6475 }
6476
6477 t0 = tcg_temp_new();
6478 gen_addr_reg_index(ctx, t0);
6479
6480 switch((ctx->opcode >> 21) & 0x3) {
6481 case 0:
c6c7cf05 6482 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6483 break;
6484 case 1:
c6c7cf05 6485 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6486 break;
6487 case 3:
c6c7cf05 6488 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6489 break;
6490 default:
6491 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6492 break;
6493 }
6494
6495 tcg_temp_free(t0);
6496#endif
6497}
6498
01662f3e 6499
76a66253 6500/* wrtee */
99e300ef 6501static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6502{
6503#if defined(CONFIG_USER_ONLY)
e06fcd75 6504 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6505#else
6527f6ea 6506 TCGv t0;
76db3ba4 6507 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6508 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6509 return;
6510 }
6527f6ea
AJ
6511 t0 = tcg_temp_new();
6512 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6513 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6514 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6515 tcg_temp_free(t0);
dee96f6c
JM
6516 /* Stop translation to have a chance to raise an exception
6517 * if we just set msr_ee to 1
6518 */
e06fcd75 6519 gen_stop_exception(ctx);
76a66253
JM
6520#endif
6521}
6522
6523/* wrteei */
99e300ef 6524static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6525{
6526#if defined(CONFIG_USER_ONLY)
e06fcd75 6527 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6528#else
76db3ba4 6529 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6530 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6531 return;
6532 }
fbe73008 6533 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6534 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6535 /* Stop translation to have a chance to raise an exception */
e06fcd75 6536 gen_stop_exception(ctx);
6527f6ea 6537 } else {
1b6e5f99 6538 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6539 }
76a66253
JM
6540#endif
6541}
6542
08e46e54 6543/* PowerPC 440 specific instructions */
99e300ef 6544
54623277 6545/* dlmzb */
99e300ef 6546static void gen_dlmzb(DisasContext *ctx)
76a66253 6547{
ef0d51af 6548 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6549 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6550 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6551 tcg_temp_free_i32(t0);
76a66253
JM
6552}
6553
6554/* mbar replaces eieio on 440 */
99e300ef 6555static void gen_mbar(DisasContext *ctx)
76a66253
JM
6556{
6557 /* interpreted as no-op */
6558}
6559
6560/* msync replaces sync on 440 */
dcb2b9e1 6561static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6562{
6563 /* interpreted as no-op */
6564}
6565
6566/* icbt */
e8eaa2c0 6567static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6568{
6569 /* interpreted as no-op */
6570 /* XXX: specification say this is treated as a load by the MMU
6571 * but does not generate any exception
6572 */
79aceca5
FB
6573}
6574
9e0b5cb1
AG
6575/* Embedded.Processor Control */
6576
6577static void gen_msgclr(DisasContext *ctx)
6578{
6579#if defined(CONFIG_USER_ONLY)
6580 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6581#else
6582 if (unlikely(ctx->mem_idx == 0)) {
6583 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6584 return;
6585 }
6586
e5f17ac6 6587 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6588#endif
6589}
6590
d5d11a39
AG
6591static void gen_msgsnd(DisasContext *ctx)
6592{
6593#if defined(CONFIG_USER_ONLY)
6594 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6595#else
6596 if (unlikely(ctx->mem_idx == 0)) {
6597 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6598 return;
6599 }
6600
6601 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6602#endif
6603}
6604
a9d9eb8f
JM
6605/*** Altivec vector extension ***/
6606/* Altivec registers moves */
a9d9eb8f 6607
636aa200 6608static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6609{
e4704b3b 6610 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6611 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6612 return r;
6613}
6614
a9d9eb8f 6615#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6616static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6617{ \
fe1e5c53 6618 TCGv EA; \
a9d9eb8f 6619 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6620 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6621 return; \
6622 } \
76db3ba4 6623 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6624 EA = tcg_temp_new(); \
76db3ba4 6625 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6626 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6627 if (ctx->le_mode) { \
6628 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6629 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6630 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6631 } else { \
76db3ba4 6632 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6633 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6634 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6635 } \
6636 tcg_temp_free(EA); \
a9d9eb8f
JM
6637}
6638
6639#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6640static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6641{ \
fe1e5c53 6642 TCGv EA; \
a9d9eb8f 6643 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6644 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6645 return; \
6646 } \
76db3ba4 6647 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6648 EA = tcg_temp_new(); \
76db3ba4 6649 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6650 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6651 if (ctx->le_mode) { \
6652 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6653 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6654 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6655 } else { \
76db3ba4 6656 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6657 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6658 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6659 } \
6660 tcg_temp_free(EA); \
a9d9eb8f
JM
6661}
6662
cbfb6ae9 6663#define GEN_VR_LVE(name, opc2, opc3) \
99e300ef 6664static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6665 { \
6666 TCGv EA; \
6667 TCGv_ptr rs; \
6668 if (unlikely(!ctx->altivec_enabled)) { \
6669 gen_exception(ctx, POWERPC_EXCP_VPU); \
6670 return; \
6671 } \
6672 gen_set_access_type(ctx, ACCESS_INT); \
6673 EA = tcg_temp_new(); \
6674 gen_addr_reg_index(ctx, EA); \
6675 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6676 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6677 tcg_temp_free(EA); \
6678 tcg_temp_free_ptr(rs); \
6679 }
6680
6681#define GEN_VR_STVE(name, opc2, opc3) \
99e300ef 6682static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6683 { \
6684 TCGv EA; \
6685 TCGv_ptr rs; \
6686 if (unlikely(!ctx->altivec_enabled)) { \
6687 gen_exception(ctx, POWERPC_EXCP_VPU); \
6688 return; \
6689 } \
6690 gen_set_access_type(ctx, ACCESS_INT); \
6691 EA = tcg_temp_new(); \
6692 gen_addr_reg_index(ctx, EA); \
6693 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6694 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6695 tcg_temp_free(EA); \
6696 tcg_temp_free_ptr(rs); \
6697 }
6698
fe1e5c53 6699GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6700/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6701GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6702
cbfb6ae9
AJ
6703GEN_VR_LVE(bx, 0x07, 0x00);
6704GEN_VR_LVE(hx, 0x07, 0x01);
6705GEN_VR_LVE(wx, 0x07, 0x02);
6706
fe1e5c53 6707GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6708/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6709GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6710
cbfb6ae9
AJ
6711GEN_VR_STVE(bx, 0x07, 0x04);
6712GEN_VR_STVE(hx, 0x07, 0x05);
6713GEN_VR_STVE(wx, 0x07, 0x06);
6714
99e300ef 6715static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6716{
6717 TCGv_ptr rd;
6718 TCGv EA;
6719 if (unlikely(!ctx->altivec_enabled)) {
6720 gen_exception(ctx, POWERPC_EXCP_VPU);
6721 return;
6722 }
6723 EA = tcg_temp_new();
6724 gen_addr_reg_index(ctx, EA);
6725 rd = gen_avr_ptr(rD(ctx->opcode));
6726 gen_helper_lvsl(rd, EA);
6727 tcg_temp_free(EA);
6728 tcg_temp_free_ptr(rd);
6729}
6730
99e300ef 6731static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6732{
6733 TCGv_ptr rd;
6734 TCGv EA;
6735 if (unlikely(!ctx->altivec_enabled)) {
6736 gen_exception(ctx, POWERPC_EXCP_VPU);
6737 return;
6738 }
6739 EA = tcg_temp_new();
6740 gen_addr_reg_index(ctx, EA);
6741 rd = gen_avr_ptr(rD(ctx->opcode));
6742 gen_helper_lvsr(rd, EA);
6743 tcg_temp_free(EA);
6744 tcg_temp_free_ptr(rd);
6745}
6746
99e300ef 6747static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6748{
6749 TCGv_i32 t;
6750 if (unlikely(!ctx->altivec_enabled)) {
6751 gen_exception(ctx, POWERPC_EXCP_VPU);
6752 return;
6753 }
6754 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6755 t = tcg_temp_new_i32();
1328c2bf 6756 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6757 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6758 tcg_temp_free_i32(t);
785f451b
AJ
6759}
6760
99e300ef 6761static void gen_mtvscr(DisasContext *ctx)
785f451b 6762{
6e87b7c7 6763 TCGv_ptr p;
785f451b
AJ
6764 if (unlikely(!ctx->altivec_enabled)) {
6765 gen_exception(ctx, POWERPC_EXCP_VPU);
6766 return;
6767 }
6e87b7c7 6768 p = gen_avr_ptr(rD(ctx->opcode));
d15f74fb 6769 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6770 tcg_temp_free_ptr(p);
785f451b
AJ
6771}
6772
7a9b96cf
AJ
6773/* Logical operations */
6774#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6775static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6776{ \
6777 if (unlikely(!ctx->altivec_enabled)) { \
6778 gen_exception(ctx, POWERPC_EXCP_VPU); \
6779 return; \
6780 } \
6781 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6782 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6783}
6784
6785GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6786GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6787GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6788GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6789GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6790
8e27dd6f 6791#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6792static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6793{ \
6794 TCGv_ptr ra, rb, rd; \
6795 if (unlikely(!ctx->altivec_enabled)) { \
6796 gen_exception(ctx, POWERPC_EXCP_VPU); \
6797 return; \
6798 } \
6799 ra = gen_avr_ptr(rA(ctx->opcode)); \
6800 rb = gen_avr_ptr(rB(ctx->opcode)); \
6801 rd = gen_avr_ptr(rD(ctx->opcode)); \
6802 gen_helper_##name (rd, ra, rb); \
6803 tcg_temp_free_ptr(ra); \
6804 tcg_temp_free_ptr(rb); \
6805 tcg_temp_free_ptr(rd); \
6806}
6807
d15f74fb
BS
6808#define GEN_VXFORM_ENV(name, opc2, opc3) \
6809static void glue(gen_, name)(DisasContext *ctx) \
6810{ \
6811 TCGv_ptr ra, rb, rd; \
6812 if (unlikely(!ctx->altivec_enabled)) { \
6813 gen_exception(ctx, POWERPC_EXCP_VPU); \
6814 return; \
6815 } \
6816 ra = gen_avr_ptr(rA(ctx->opcode)); \
6817 rb = gen_avr_ptr(rB(ctx->opcode)); \
6818 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6819 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6820 tcg_temp_free_ptr(ra); \
6821 tcg_temp_free_ptr(rb); \
6822 tcg_temp_free_ptr(rd); \
6823}
6824
7872c51c
AJ
6825GEN_VXFORM(vaddubm, 0, 0);
6826GEN_VXFORM(vadduhm, 0, 1);
6827GEN_VXFORM(vadduwm, 0, 2);
6828GEN_VXFORM(vsububm, 0, 16);
6829GEN_VXFORM(vsubuhm, 0, 17);
6830GEN_VXFORM(vsubuwm, 0, 18);
e4039339
AJ
6831GEN_VXFORM(vmaxub, 1, 0);
6832GEN_VXFORM(vmaxuh, 1, 1);
6833GEN_VXFORM(vmaxuw, 1, 2);
6834GEN_VXFORM(vmaxsb, 1, 4);
6835GEN_VXFORM(vmaxsh, 1, 5);
6836GEN_VXFORM(vmaxsw, 1, 6);
6837GEN_VXFORM(vminub, 1, 8);
6838GEN_VXFORM(vminuh, 1, 9);
6839GEN_VXFORM(vminuw, 1, 10);
6840GEN_VXFORM(vminsb, 1, 12);
6841GEN_VXFORM(vminsh, 1, 13);
6842GEN_VXFORM(vminsw, 1, 14);
fab3cbe9
AJ
6843GEN_VXFORM(vavgub, 1, 16);
6844GEN_VXFORM(vavguh, 1, 17);
6845GEN_VXFORM(vavguw, 1, 18);
6846GEN_VXFORM(vavgsb, 1, 20);
6847GEN_VXFORM(vavgsh, 1, 21);
6848GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
6849GEN_VXFORM(vmrghb, 6, 0);
6850GEN_VXFORM(vmrghh, 6, 1);
6851GEN_VXFORM(vmrghw, 6, 2);
6852GEN_VXFORM(vmrglb, 6, 4);
6853GEN_VXFORM(vmrglh, 6, 5);
6854GEN_VXFORM(vmrglw, 6, 6);
2c277908
AJ
6855GEN_VXFORM(vmuloub, 4, 0);
6856GEN_VXFORM(vmulouh, 4, 1);
6857GEN_VXFORM(vmulosb, 4, 4);
6858GEN_VXFORM(vmulosh, 4, 5);
6859GEN_VXFORM(vmuleub, 4, 8);
6860GEN_VXFORM(vmuleuh, 4, 9);
6861GEN_VXFORM(vmulesb, 4, 12);
6862GEN_VXFORM(vmulesh, 4, 13);
d79f0809
AJ
6863GEN_VXFORM(vslb, 2, 4);
6864GEN_VXFORM(vslh, 2, 5);
6865GEN_VXFORM(vslw, 2, 6);
07ef34c3
AJ
6866GEN_VXFORM(vsrb, 2, 8);
6867GEN_VXFORM(vsrh, 2, 9);
6868GEN_VXFORM(vsrw, 2, 10);
6869GEN_VXFORM(vsrab, 2, 12);
6870GEN_VXFORM(vsrah, 2, 13);
6871GEN_VXFORM(vsraw, 2, 14);
7b239bec
AJ
6872GEN_VXFORM(vslo, 6, 16);
6873GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
6874GEN_VXFORM(vaddcuw, 0, 6);
6875GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
6876GEN_VXFORM_ENV(vaddubs, 0, 8);
6877GEN_VXFORM_ENV(vadduhs, 0, 9);
6878GEN_VXFORM_ENV(vadduws, 0, 10);
6879GEN_VXFORM_ENV(vaddsbs, 0, 12);
6880GEN_VXFORM_ENV(vaddshs, 0, 13);
6881GEN_VXFORM_ENV(vaddsws, 0, 14);
6882GEN_VXFORM_ENV(vsububs, 0, 24);
6883GEN_VXFORM_ENV(vsubuhs, 0, 25);
6884GEN_VXFORM_ENV(vsubuws, 0, 26);
6885GEN_VXFORM_ENV(vsubsbs, 0, 28);
6886GEN_VXFORM_ENV(vsubshs, 0, 29);
6887GEN_VXFORM_ENV(vsubsws, 0, 30);
5e1d0985
AJ
6888GEN_VXFORM(vrlb, 2, 0);
6889GEN_VXFORM(vrlh, 2, 1);
6890GEN_VXFORM(vrlw, 2, 2);
d9430add
AJ
6891GEN_VXFORM(vsl, 2, 7);
6892GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
6893GEN_VXFORM_ENV(vpkuhum, 7, 0);
6894GEN_VXFORM_ENV(vpkuwum, 7, 1);
6895GEN_VXFORM_ENV(vpkuhus, 7, 2);
6896GEN_VXFORM_ENV(vpkuwus, 7, 3);
6897GEN_VXFORM_ENV(vpkshus, 7, 4);
6898GEN_VXFORM_ENV(vpkswus, 7, 5);
6899GEN_VXFORM_ENV(vpkshss, 7, 6);
6900GEN_VXFORM_ENV(vpkswss, 7, 7);
1dd9ffb9 6901GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
6902GEN_VXFORM_ENV(vsum4ubs, 4, 24);
6903GEN_VXFORM_ENV(vsum4sbs, 4, 28);
6904GEN_VXFORM_ENV(vsum4shs, 4, 25);
6905GEN_VXFORM_ENV(vsum2sws, 4, 26);
6906GEN_VXFORM_ENV(vsumsws, 4, 30);
6907GEN_VXFORM_ENV(vaddfp, 5, 0);
6908GEN_VXFORM_ENV(vsubfp, 5, 1);
6909GEN_VXFORM_ENV(vmaxfp, 5, 16);
6910GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 6911
0cbcd906 6912#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 6913static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
6914 { \
6915 TCGv_ptr ra, rb, rd; \
6916 if (unlikely(!ctx->altivec_enabled)) { \
6917 gen_exception(ctx, POWERPC_EXCP_VPU); \
6918 return; \
6919 } \
6920 ra = gen_avr_ptr(rA(ctx->opcode)); \
6921 rb = gen_avr_ptr(rB(ctx->opcode)); \
6922 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 6923 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
6924 tcg_temp_free_ptr(ra); \
6925 tcg_temp_free_ptr(rb); \
6926 tcg_temp_free_ptr(rd); \
6927 }
6928
6929#define GEN_VXRFORM(name, opc2, opc3) \
6930 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6931 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6932
1add6e23
AJ
6933GEN_VXRFORM(vcmpequb, 3, 0)
6934GEN_VXRFORM(vcmpequh, 3, 1)
6935GEN_VXRFORM(vcmpequw, 3, 2)
6936GEN_VXRFORM(vcmpgtsb, 3, 12)
6937GEN_VXRFORM(vcmpgtsh, 3, 13)
6938GEN_VXRFORM(vcmpgtsw, 3, 14)
6939GEN_VXRFORM(vcmpgtub, 3, 8)
6940GEN_VXRFORM(vcmpgtuh, 3, 9)
6941GEN_VXRFORM(vcmpgtuw, 3, 10)
819ca121
AJ
6942GEN_VXRFORM(vcmpeqfp, 3, 3)
6943GEN_VXRFORM(vcmpgefp, 3, 7)
6944GEN_VXRFORM(vcmpgtfp, 3, 11)
6945GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 6946
c026766b 6947#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 6948static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
6949 { \
6950 TCGv_ptr rd; \
6951 TCGv_i32 simm; \
6952 if (unlikely(!ctx->altivec_enabled)) { \
6953 gen_exception(ctx, POWERPC_EXCP_VPU); \
6954 return; \
6955 } \
6956 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6957 rd = gen_avr_ptr(rD(ctx->opcode)); \
6958 gen_helper_##name (rd, simm); \
6959 tcg_temp_free_i32(simm); \
6960 tcg_temp_free_ptr(rd); \
6961 }
6962
6963GEN_VXFORM_SIMM(vspltisb, 6, 12);
6964GEN_VXFORM_SIMM(vspltish, 6, 13);
6965GEN_VXFORM_SIMM(vspltisw, 6, 14);
6966
de5f2484 6967#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 6968static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
6969 { \
6970 TCGv_ptr rb, rd; \
6971 if (unlikely(!ctx->altivec_enabled)) { \
6972 gen_exception(ctx, POWERPC_EXCP_VPU); \
6973 return; \
6974 } \
6975 rb = gen_avr_ptr(rB(ctx->opcode)); \
6976 rd = gen_avr_ptr(rD(ctx->opcode)); \
6977 gen_helper_##name (rd, rb); \
6978 tcg_temp_free_ptr(rb); \
6979 tcg_temp_free_ptr(rd); \
6980 }
6981
d15f74fb
BS
6982#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6983static void glue(gen_, name)(DisasContext *ctx) \
6984 { \
6985 TCGv_ptr rb, rd; \
6986 \
6987 if (unlikely(!ctx->altivec_enabled)) { \
6988 gen_exception(ctx, POWERPC_EXCP_VPU); \
6989 return; \
6990 } \
6991 rb = gen_avr_ptr(rB(ctx->opcode)); \
6992 rd = gen_avr_ptr(rD(ctx->opcode)); \
6993 gen_helper_##name(cpu_env, rd, rb); \
6994 tcg_temp_free_ptr(rb); \
6995 tcg_temp_free_ptr(rd); \
6996 }
6997
6cf1c6e5
AJ
6998GEN_VXFORM_NOA(vupkhsb, 7, 8);
6999GEN_VXFORM_NOA(vupkhsh, 7, 9);
7000GEN_VXFORM_NOA(vupklsb, 7, 10);
7001GEN_VXFORM_NOA(vupklsh, 7, 11);
79f85c3a
AJ
7002GEN_VXFORM_NOA(vupkhpx, 7, 13);
7003GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
7004GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7005GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7006GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7007GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
7008GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
7009GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
7010GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
7011GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
79f85c3a 7012
21d21583 7013#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7014static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
7015 { \
7016 TCGv_ptr rd; \
7017 TCGv_i32 simm; \
7018 if (unlikely(!ctx->altivec_enabled)) { \
7019 gen_exception(ctx, POWERPC_EXCP_VPU); \
7020 return; \
7021 } \
7022 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7023 rd = gen_avr_ptr(rD(ctx->opcode)); \
7024 gen_helper_##name (rd, simm); \
7025 tcg_temp_free_i32(simm); \
7026 tcg_temp_free_ptr(rd); \
7027 }
7028
27a4edb3 7029#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 7030static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
7031 { \
7032 TCGv_ptr rb, rd; \
7033 TCGv_i32 uimm; \
7034 if (unlikely(!ctx->altivec_enabled)) { \
7035 gen_exception(ctx, POWERPC_EXCP_VPU); \
7036 return; \
7037 } \
7038 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7039 rb = gen_avr_ptr(rB(ctx->opcode)); \
7040 rd = gen_avr_ptr(rD(ctx->opcode)); \
7041 gen_helper_##name (rd, rb, uimm); \
7042 tcg_temp_free_i32(uimm); \
7043 tcg_temp_free_ptr(rb); \
7044 tcg_temp_free_ptr(rd); \
7045 }
7046
d15f74fb
BS
7047#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7048static void glue(gen_, name)(DisasContext *ctx) \
7049 { \
7050 TCGv_ptr rb, rd; \
7051 TCGv_i32 uimm; \
7052 \
7053 if (unlikely(!ctx->altivec_enabled)) { \
7054 gen_exception(ctx, POWERPC_EXCP_VPU); \
7055 return; \
7056 } \
7057 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7058 rb = gen_avr_ptr(rB(ctx->opcode)); \
7059 rd = gen_avr_ptr(rD(ctx->opcode)); \
7060 gen_helper_##name(cpu_env, rd, rb, uimm); \
7061 tcg_temp_free_i32(uimm); \
7062 tcg_temp_free_ptr(rb); \
7063 tcg_temp_free_ptr(rd); \
7064 }
7065
e4e6bee7
AJ
7066GEN_VXFORM_UIMM(vspltb, 6, 8);
7067GEN_VXFORM_UIMM(vsplth, 6, 9);
7068GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
7069GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7070GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7071GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7072GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 7073
99e300ef 7074static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
7075{
7076 TCGv_ptr ra, rb, rd;
fce5ecb7 7077 TCGv_i32 sh;
cd633b10
AJ
7078 if (unlikely(!ctx->altivec_enabled)) {
7079 gen_exception(ctx, POWERPC_EXCP_VPU);
7080 return;
7081 }
7082 ra = gen_avr_ptr(rA(ctx->opcode));
7083 rb = gen_avr_ptr(rB(ctx->opcode));
7084 rd = gen_avr_ptr(rD(ctx->opcode));
7085 sh = tcg_const_i32(VSH(ctx->opcode));
7086 gen_helper_vsldoi (rd, ra, rb, sh);
7087 tcg_temp_free_ptr(ra);
7088 tcg_temp_free_ptr(rb);
7089 tcg_temp_free_ptr(rd);
fce5ecb7 7090 tcg_temp_free_i32(sh);
cd633b10
AJ
7091}
7092
707cec33 7093#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 7094static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
7095 { \
7096 TCGv_ptr ra, rb, rc, rd; \
7097 if (unlikely(!ctx->altivec_enabled)) { \
7098 gen_exception(ctx, POWERPC_EXCP_VPU); \
7099 return; \
7100 } \
7101 ra = gen_avr_ptr(rA(ctx->opcode)); \
7102 rb = gen_avr_ptr(rB(ctx->opcode)); \
7103 rc = gen_avr_ptr(rC(ctx->opcode)); \
7104 rd = gen_avr_ptr(rD(ctx->opcode)); \
7105 if (Rc(ctx->opcode)) { \
d15f74fb 7106 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 7107 } else { \
d15f74fb 7108 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
7109 } \
7110 tcg_temp_free_ptr(ra); \
7111 tcg_temp_free_ptr(rb); \
7112 tcg_temp_free_ptr(rc); \
7113 tcg_temp_free_ptr(rd); \
7114 }
7115
b161ae27
AJ
7116GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7117
99e300ef 7118static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
7119{
7120 TCGv_ptr ra, rb, rc, rd;
7121 if (unlikely(!ctx->altivec_enabled)) {
7122 gen_exception(ctx, POWERPC_EXCP_VPU);
7123 return;
7124 }
7125 ra = gen_avr_ptr(rA(ctx->opcode));
7126 rb = gen_avr_ptr(rB(ctx->opcode));
7127 rc = gen_avr_ptr(rC(ctx->opcode));
7128 rd = gen_avr_ptr(rD(ctx->opcode));
7129 gen_helper_vmladduhm(rd, ra, rb, rc);
7130 tcg_temp_free_ptr(ra);
7131 tcg_temp_free_ptr(rb);
7132 tcg_temp_free_ptr(rc);
7133 tcg_temp_free_ptr(rd);
7134}
7135
b04ae981 7136GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7137GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7138GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7139GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7140GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7141
472b24ce
TM
7142/*** VSX extension ***/
7143
7144static inline TCGv_i64 cpu_vsrh(int n)
7145{
7146 if (n < 32) {
7147 return cpu_fpr[n];
7148 } else {
7149 return cpu_avrh[n-32];
7150 }
7151}
7152
7153static inline TCGv_i64 cpu_vsrl(int n)
7154{
7155 if (n < 32) {
7156 return cpu_vsr[n];
7157 } else {
7158 return cpu_avrl[n-32];
7159 }
7160}
7161
e072fe79
TM
7162#define VSX_LOAD_SCALAR(name, operation) \
7163static void gen_##name(DisasContext *ctx) \
7164{ \
7165 TCGv EA; \
7166 if (unlikely(!ctx->vsx_enabled)) { \
7167 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7168 return; \
7169 } \
7170 gen_set_access_type(ctx, ACCESS_INT); \
7171 EA = tcg_temp_new(); \
7172 gen_addr_reg_index(ctx, EA); \
7173 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7174 /* NOTE: cpu_vsrl is undefined */ \
7175 tcg_temp_free(EA); \
7176}
7177
7178VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7179VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7180VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7181VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7182
304af367
TM
7183static void gen_lxvd2x(DisasContext *ctx)
7184{
7185 TCGv EA;
7186 if (unlikely(!ctx->vsx_enabled)) {
7187 gen_exception(ctx, POWERPC_EXCP_VSXU);
7188 return;
7189 }
7190 gen_set_access_type(ctx, ACCESS_INT);
7191 EA = tcg_temp_new();
7192 gen_addr_reg_index(ctx, EA);
7193 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7194 tcg_gen_addi_tl(EA, EA, 8);
7195 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7196 tcg_temp_free(EA);
7197}
7198
ca03b467
TM
7199static void gen_lxvdsx(DisasContext *ctx)
7200{
7201 TCGv EA;
7202 if (unlikely(!ctx->vsx_enabled)) {
7203 gen_exception(ctx, POWERPC_EXCP_VSXU);
7204 return;
7205 }
7206 gen_set_access_type(ctx, ACCESS_INT);
7207 EA = tcg_temp_new();
7208 gen_addr_reg_index(ctx, EA);
7209 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7210 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7211 tcg_temp_free(EA);
7212}
7213
897e61d1
TM
7214static void gen_lxvw4x(DisasContext *ctx)
7215{
f976b09e
AG
7216 TCGv EA;
7217 TCGv_i64 tmp;
897e61d1
TM
7218 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7219 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7220 if (unlikely(!ctx->vsx_enabled)) {
7221 gen_exception(ctx, POWERPC_EXCP_VSXU);
7222 return;
7223 }
7224 gen_set_access_type(ctx, ACCESS_INT);
7225 EA = tcg_temp_new();
f976b09e
AG
7226 tmp = tcg_temp_new_i64();
7227
897e61d1 7228 gen_addr_reg_index(ctx, EA);
f976b09e 7229 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7230 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7231 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7232 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7233
7234 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7235 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7236 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7237 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7238 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7239
7240 tcg_temp_free(EA);
f976b09e 7241 tcg_temp_free_i64(tmp);
897e61d1
TM
7242}
7243
f026da78
TM
7244#define VSX_STORE_SCALAR(name, operation) \
7245static void gen_##name(DisasContext *ctx) \
7246{ \
7247 TCGv EA; \
7248 if (unlikely(!ctx->vsx_enabled)) { \
7249 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7250 return; \
7251 } \
7252 gen_set_access_type(ctx, ACCESS_INT); \
7253 EA = tcg_temp_new(); \
7254 gen_addr_reg_index(ctx, EA); \
7255 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7256 tcg_temp_free(EA); \
9231ba9e
TM
7257}
7258
f026da78 7259VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7260VSX_STORE_SCALAR(stxsiwx, st32_i64)
7261VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7262
fbed2478
TM
7263static void gen_stxvd2x(DisasContext *ctx)
7264{
7265 TCGv EA;
7266 if (unlikely(!ctx->vsx_enabled)) {
7267 gen_exception(ctx, POWERPC_EXCP_VSXU);
7268 return;
7269 }
7270 gen_set_access_type(ctx, ACCESS_INT);
7271 EA = tcg_temp_new();
7272 gen_addr_reg_index(ctx, EA);
7273 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7274 tcg_gen_addi_tl(EA, EA, 8);
7275 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7276 tcg_temp_free(EA);
7277}
7278
86e61ce3
TM
7279static void gen_stxvw4x(DisasContext *ctx)
7280{
f976b09e
AG
7281 TCGv_i64 tmp;
7282 TCGv EA;
86e61ce3
TM
7283 if (unlikely(!ctx->vsx_enabled)) {
7284 gen_exception(ctx, POWERPC_EXCP_VSXU);
7285 return;
7286 }
7287 gen_set_access_type(ctx, ACCESS_INT);
7288 EA = tcg_temp_new();
7289 gen_addr_reg_index(ctx, EA);
f976b09e 7290 tmp = tcg_temp_new_i64();
86e61ce3
TM
7291
7292 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7293 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7294 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7295 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7296
7297 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7298 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7299 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7300 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7301 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7302
7303 tcg_temp_free(EA);
f976b09e 7304 tcg_temp_free_i64(tmp);
86e61ce3
TM
7305}
7306
f5c0f7f9
TM
7307#define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7308static void gen_##name(DisasContext *ctx) \
7309{ \
7310 if (xS(ctx->opcode) < 32) { \
7311 if (unlikely(!ctx->fpu_enabled)) { \
7312 gen_exception(ctx, POWERPC_EXCP_FPU); \
7313 return; \
7314 } \
7315 } else { \
7316 if (unlikely(!ctx->altivec_enabled)) { \
7317 gen_exception(ctx, POWERPC_EXCP_VPU); \
7318 return; \
7319 } \
7320 } \
7321 TCGv_i64 tmp = tcg_temp_new_i64(); \
7322 tcg_gen_##tcgop1(tmp, source); \
7323 tcg_gen_##tcgop2(target, tmp); \
7324 tcg_temp_free_i64(tmp); \
7325}
7326
7327
7328MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7329 cpu_vsrh(xS(ctx->opcode)))
7330MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7331 cpu_gpr[rA(ctx->opcode)])
7332MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7333 cpu_gpr[rA(ctx->opcode)])
7334
7335#if defined(TARGET_PPC64)
7336#define MV_VSRD(name, target, source) \
7337static void gen_##name(DisasContext *ctx) \
7338{ \
7339 if (xS(ctx->opcode) < 32) { \
7340 if (unlikely(!ctx->fpu_enabled)) { \
7341 gen_exception(ctx, POWERPC_EXCP_FPU); \
7342 return; \
7343 } \
7344 } else { \
7345 if (unlikely(!ctx->altivec_enabled)) { \
7346 gen_exception(ctx, POWERPC_EXCP_VPU); \
7347 return; \
7348 } \
7349 } \
7350 tcg_gen_mov_i64(target, source); \
7351}
7352
7353MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7354MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7355
7356#endif
7357
cd73f2c9
TM
7358static void gen_xxpermdi(DisasContext *ctx)
7359{
7360 if (unlikely(!ctx->vsx_enabled)) {
7361 gen_exception(ctx, POWERPC_EXCP_VSXU);
7362 return;
7363 }
7364
f5bc1bfa
TM
7365 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7366 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7367 TCGv_i64 xh, xl;
7368
7369 xh = tcg_temp_new_i64();
7370 xl = tcg_temp_new_i64();
7371
7372 if ((DM(ctx->opcode) & 2) == 0) {
7373 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7374 } else {
7375 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7376 }
7377 if ((DM(ctx->opcode) & 1) == 0) {
7378 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7379 } else {
7380 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7381 }
7382
7383 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7384 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7385
7386 tcg_temp_free_i64(xh);
7387 tcg_temp_free_i64(xl);
cd73f2c9 7388 } else {
f5bc1bfa
TM
7389 if ((DM(ctx->opcode) & 2) == 0) {
7390 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7391 } else {
7392 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7393 }
7394 if ((DM(ctx->opcode) & 1) == 0) {
7395 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7396 } else {
7397 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7398 }
cd73f2c9
TM
7399 }
7400}
7401
df020ce0
TM
7402#define OP_ABS 1
7403#define OP_NABS 2
7404#define OP_NEG 3
7405#define OP_CPSGN 4
7406#define SGN_MASK_DP 0x8000000000000000ul
7407#define SGN_MASK_SP 0x8000000080000000ul
7408
7409#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7410static void glue(gen_, name)(DisasContext * ctx) \
7411 { \
7412 TCGv_i64 xb, sgm; \
7413 if (unlikely(!ctx->vsx_enabled)) { \
7414 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7415 return; \
7416 } \
f976b09e
AG
7417 xb = tcg_temp_new_i64(); \
7418 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7419 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7420 tcg_gen_movi_i64(sgm, sgn_mask); \
7421 switch (op) { \
7422 case OP_ABS: { \
7423 tcg_gen_andc_i64(xb, xb, sgm); \
7424 break; \
7425 } \
7426 case OP_NABS: { \
7427 tcg_gen_or_i64(xb, xb, sgm); \
7428 break; \
7429 } \
7430 case OP_NEG: { \
7431 tcg_gen_xor_i64(xb, xb, sgm); \
7432 break; \
7433 } \
7434 case OP_CPSGN: { \
f976b09e 7435 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7436 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7437 tcg_gen_and_i64(xa, xa, sgm); \
7438 tcg_gen_andc_i64(xb, xb, sgm); \
7439 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7440 tcg_temp_free_i64(xa); \
df020ce0
TM
7441 break; \
7442 } \
7443 } \
7444 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7445 tcg_temp_free_i64(xb); \
7446 tcg_temp_free_i64(sgm); \
df020ce0
TM
7447 }
7448
7449VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7450VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7451VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7452VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7453
be574920
TM
7454#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7455static void glue(gen_, name)(DisasContext * ctx) \
7456 { \
7457 TCGv_i64 xbh, xbl, sgm; \
7458 if (unlikely(!ctx->vsx_enabled)) { \
7459 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7460 return; \
7461 } \
f976b09e
AG
7462 xbh = tcg_temp_new_i64(); \
7463 xbl = tcg_temp_new_i64(); \
7464 sgm = tcg_temp_new_i64(); \
be574920
TM
7465 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7466 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7467 tcg_gen_movi_i64(sgm, sgn_mask); \
7468 switch (op) { \
7469 case OP_ABS: { \
7470 tcg_gen_andc_i64(xbh, xbh, sgm); \
7471 tcg_gen_andc_i64(xbl, xbl, sgm); \
7472 break; \
7473 } \
7474 case OP_NABS: { \
7475 tcg_gen_or_i64(xbh, xbh, sgm); \
7476 tcg_gen_or_i64(xbl, xbl, sgm); \
7477 break; \
7478 } \
7479 case OP_NEG: { \
7480 tcg_gen_xor_i64(xbh, xbh, sgm); \
7481 tcg_gen_xor_i64(xbl, xbl, sgm); \
7482 break; \
7483 } \
7484 case OP_CPSGN: { \
f976b09e
AG
7485 TCGv_i64 xah = tcg_temp_new_i64(); \
7486 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7487 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7488 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7489 tcg_gen_and_i64(xah, xah, sgm); \
7490 tcg_gen_and_i64(xal, xal, sgm); \
7491 tcg_gen_andc_i64(xbh, xbh, sgm); \
7492 tcg_gen_andc_i64(xbl, xbl, sgm); \
7493 tcg_gen_or_i64(xbh, xbh, xah); \
7494 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7495 tcg_temp_free_i64(xah); \
7496 tcg_temp_free_i64(xal); \
be574920
TM
7497 break; \
7498 } \
7499 } \
7500 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7501 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7502 tcg_temp_free_i64(xbh); \
7503 tcg_temp_free_i64(xbl); \
7504 tcg_temp_free_i64(sgm); \
be574920
TM
7505 }
7506
7507VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7508VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7509VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7510VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7511VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7512VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7513VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7514VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7515
3c3cbbdc
TM
7516#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7517static void gen_##name(DisasContext * ctx) \
7518{ \
7519 TCGv_i32 opc; \
7520 if (unlikely(!ctx->vsx_enabled)) { \
7521 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7522 return; \
7523 } \
7524 /* NIP cannot be restored if the memory exception comes from an helper */ \
7525 gen_update_nip(ctx, ctx->nip - 4); \
7526 opc = tcg_const_i32(ctx->opcode); \
7527 gen_helper_##name(cpu_env, opc); \
7528 tcg_temp_free_i32(opc); \
7529}
be574920 7530
3d1140bf
TM
7531#define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7532static void gen_##name(DisasContext * ctx) \
7533{ \
7534 if (unlikely(!ctx->vsx_enabled)) { \
7535 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7536 return; \
7537 } \
7538 /* NIP cannot be restored if the exception comes */ \
7539 /* from a helper. */ \
7540 gen_update_nip(ctx, ctx->nip - 4); \
7541 \
7542 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7543 cpu_vsrh(xB(ctx->opcode))); \
7544}
7545
ee6e02c0
TM
7546GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7547GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7548GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7549GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7550GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7551GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7552GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7553GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7554GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7555GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7556GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7557GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7558GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7559GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7560GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7561GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7562GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
7563GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7564GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
7565GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7566GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568 7567GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7ee19fb9 7568GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
ed8ac568 7569GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7ee19fb9 7570GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
5177d2ca
TM
7571GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7572GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
7573GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
7574GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
7575GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
7576GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
7577GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
7578GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
7579GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
7580GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
7581GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
3d1140bf 7582GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
ee6e02c0 7583
3fd0aadf
TM
7584GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
7585GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 7586GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 7587GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 7588GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 7589GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
968e76bc 7590GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
f53f81e0
TM
7591GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
7592GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
7593GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
7594GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
7595GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
7596GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
7597GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
7598GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
74698350
TM
7599GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
7600GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
3fd0aadf 7601
ee6e02c0
TM
7602GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
7603GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 7604GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 7605GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 7606GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 7607GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 7608GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 7609GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 7610GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
7611GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
7612GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
7613GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
7614GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
7615GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
7616GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
7617GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
7618GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
7619GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
7620GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
7621GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
7622GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
7623GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 7624GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
7625GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
7626GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
7627GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
7628GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
7629GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
7630GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
7631GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
7632GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
7633GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
7634GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
7635GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
7636GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
7637GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
7638
7639GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
7640GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 7641GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 7642GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 7643GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 7644GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 7645GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 7646GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 7647GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
7648GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
7649GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
7650GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
7651GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
7652GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
7653GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
7654GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
7655GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
7656GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
7657GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
7658GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
7659GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
7660GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 7661GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
7662GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
7663GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
7664GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
7665GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
7666GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
7667GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
7668GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
7669GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
7670GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
7671GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
7672GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
7673GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
7674GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 7675
79ca8a6a
TM
7676#define VSX_LOGICAL(name, tcg_op) \
7677static void glue(gen_, name)(DisasContext * ctx) \
7678 { \
7679 if (unlikely(!ctx->vsx_enabled)) { \
7680 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7681 return; \
7682 } \
7683 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
7684 cpu_vsrh(xB(ctx->opcode))); \
7685 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
7686 cpu_vsrl(xB(ctx->opcode))); \
7687 }
7688
f976b09e
AG
7689VSX_LOGICAL(xxland, tcg_gen_and_i64)
7690VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
7691VSX_LOGICAL(xxlor, tcg_gen_or_i64)
7692VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
7693VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
67a33f37
TM
7694VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
7695VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
7696VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
df020ce0 7697
ce577d2e
TM
7698#define VSX_XXMRG(name, high) \
7699static void glue(gen_, name)(DisasContext * ctx) \
7700 { \
7701 TCGv_i64 a0, a1, b0, b1; \
7702 if (unlikely(!ctx->vsx_enabled)) { \
7703 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7704 return; \
7705 } \
f976b09e
AG
7706 a0 = tcg_temp_new_i64(); \
7707 a1 = tcg_temp_new_i64(); \
7708 b0 = tcg_temp_new_i64(); \
7709 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
7710 if (high) { \
7711 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
7712 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
7713 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
7714 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
7715 } else { \
7716 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
7717 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
7718 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
7719 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
7720 } \
7721 tcg_gen_shri_i64(a0, a0, 32); \
7722 tcg_gen_shri_i64(b0, b0, 32); \
7723 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
7724 b0, a0, 32, 32); \
7725 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
7726 b1, a1, 32, 32); \
f976b09e
AG
7727 tcg_temp_free_i64(a0); \
7728 tcg_temp_free_i64(a1); \
7729 tcg_temp_free_i64(b0); \
7730 tcg_temp_free_i64(b1); \
ce577d2e
TM
7731 }
7732
7733VSX_XXMRG(xxmrghw, 1)
7734VSX_XXMRG(xxmrglw, 0)
7735
551e3ef7
TM
7736static void gen_xxsel(DisasContext * ctx)
7737{
7738 TCGv_i64 a, b, c;
7739 if (unlikely(!ctx->vsx_enabled)) {
7740 gen_exception(ctx, POWERPC_EXCP_VSXU);
7741 return;
7742 }
f976b09e
AG
7743 a = tcg_temp_new_i64();
7744 b = tcg_temp_new_i64();
7745 c = tcg_temp_new_i64();
551e3ef7
TM
7746
7747 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
7748 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
7749 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
7750
7751 tcg_gen_and_i64(b, b, c);
7752 tcg_gen_andc_i64(a, a, c);
7753 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
7754
7755 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
7756 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
7757 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
7758
7759 tcg_gen_and_i64(b, b, c);
7760 tcg_gen_andc_i64(a, a, c);
7761 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
7762
f976b09e
AG
7763 tcg_temp_free_i64(a);
7764 tcg_temp_free_i64(b);
7765 tcg_temp_free_i64(c);
551e3ef7
TM
7766}
7767
76c15fe0
TM
7768static void gen_xxspltw(DisasContext *ctx)
7769{
7770 TCGv_i64 b, b2;
7771 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
7772 cpu_vsrl(xB(ctx->opcode)) :
7773 cpu_vsrh(xB(ctx->opcode));
7774
7775 if (unlikely(!ctx->vsx_enabled)) {
7776 gen_exception(ctx, POWERPC_EXCP_VSXU);
7777 return;
7778 }
7779
f976b09e
AG
7780 b = tcg_temp_new_i64();
7781 b2 = tcg_temp_new_i64();
76c15fe0
TM
7782
7783 if (UIM(ctx->opcode) & 1) {
7784 tcg_gen_ext32u_i64(b, vsr);
7785 } else {
7786 tcg_gen_shri_i64(b, vsr, 32);
7787 }
7788
7789 tcg_gen_shli_i64(b2, b, 32);
7790 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
7791 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
7792
f976b09e
AG
7793 tcg_temp_free_i64(b);
7794 tcg_temp_free_i64(b2);
76c15fe0
TM
7795}
7796
acc42968
TM
7797static void gen_xxsldwi(DisasContext *ctx)
7798{
7799 TCGv_i64 xth, xtl;
7800 if (unlikely(!ctx->vsx_enabled)) {
7801 gen_exception(ctx, POWERPC_EXCP_VSXU);
7802 return;
7803 }
f976b09e
AG
7804 xth = tcg_temp_new_i64();
7805 xtl = tcg_temp_new_i64();
acc42968
TM
7806
7807 switch (SHW(ctx->opcode)) {
7808 case 0: {
7809 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
7810 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
7811 break;
7812 }
7813 case 1: {
f976b09e 7814 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
7815 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
7816 tcg_gen_shli_i64(xth, xth, 32);
7817 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
7818 tcg_gen_shri_i64(t0, t0, 32);
7819 tcg_gen_or_i64(xth, xth, t0);
7820 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
7821 tcg_gen_shli_i64(xtl, xtl, 32);
7822 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
7823 tcg_gen_shri_i64(t0, t0, 32);
7824 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 7825 tcg_temp_free_i64(t0);
acc42968
TM
7826 break;
7827 }
7828 case 2: {
7829 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
7830 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
7831 break;
7832 }
7833 case 3: {
f976b09e 7834 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
7835 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
7836 tcg_gen_shli_i64(xth, xth, 32);
7837 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
7838 tcg_gen_shri_i64(t0, t0, 32);
7839 tcg_gen_or_i64(xth, xth, t0);
7840 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
7841 tcg_gen_shli_i64(xtl, xtl, 32);
7842 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
7843 tcg_gen_shri_i64(t0, t0, 32);
7844 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 7845 tcg_temp_free_i64(t0);
acc42968
TM
7846 break;
7847 }
7848 }
7849
7850 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
7851 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
7852
f976b09e
AG
7853 tcg_temp_free_i64(xth);
7854 tcg_temp_free_i64(xtl);
acc42968
TM
7855}
7856
ce577d2e 7857
0487d6a8 7858/*** SPE extension ***/
0487d6a8 7859/* Register moves */
3cd7d1dd 7860
a0e13900
FC
7861static inline void gen_evmra(DisasContext *ctx)
7862{
7863
7864 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7865 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
7866 return;
7867 }
7868
7869#if defined(TARGET_PPC64)
7870 /* rD := rA */
7871 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7872
7873 /* spe_acc := rA */
7874 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
7875 cpu_env,
1328c2bf 7876 offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7877#else
7878 TCGv_i64 tmp = tcg_temp_new_i64();
7879
7880 /* tmp := rA_lo + rA_hi << 32 */
7881 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7882
7883 /* spe_acc := tmp */
1328c2bf 7884 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7885 tcg_temp_free_i64(tmp);
7886
7887 /* rD := rA */
7888 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7889 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7890#endif
7891}
7892
636aa200
BS
7893static inline void gen_load_gpr64(TCGv_i64 t, int reg)
7894{
f78fb44e
AJ
7895#if defined(TARGET_PPC64)
7896 tcg_gen_mov_i64(t, cpu_gpr[reg]);
7897#else
36aa55dc 7898 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
3cd7d1dd 7899#endif
f78fb44e 7900}
3cd7d1dd 7901
636aa200
BS
7902static inline void gen_store_gpr64(int reg, TCGv_i64 t)
7903{
f78fb44e
AJ
7904#if defined(TARGET_PPC64)
7905 tcg_gen_mov_i64(cpu_gpr[reg], t);
7906#else
a7812ae4 7907 TCGv_i64 tmp = tcg_temp_new_i64();
f78fb44e 7908 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
f78fb44e
AJ
7909 tcg_gen_shri_i64(tmp, t, 32);
7910 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
a7812ae4 7911 tcg_temp_free_i64(tmp);
3cd7d1dd 7912#endif
f78fb44e 7913}
3cd7d1dd 7914
70560da7 7915#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 7916static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
7917{ \
7918 if (Rc(ctx->opcode)) \
7919 gen_##name1(ctx); \
7920 else \
7921 gen_##name0(ctx); \
7922}
7923
7924/* Handler for undefined SPE opcodes */
636aa200 7925static inline void gen_speundef(DisasContext *ctx)
0487d6a8 7926{
e06fcd75 7927 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
7928}
7929
57951c27
AJ
7930/* SPE logic */
7931#if defined(TARGET_PPC64)
7932#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 7933static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7934{ \
7935 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7936 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7937 return; \
7938 } \
57951c27
AJ
7939 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7940 cpu_gpr[rB(ctx->opcode)]); \
7941}
7942#else
7943#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 7944static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7945{ \
7946 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7947 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7948 return; \
7949 } \
7950 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7951 cpu_gpr[rB(ctx->opcode)]); \
7952 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7953 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 7954}
57951c27
AJ
7955#endif
7956
7957GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
7958GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
7959GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
7960GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
7961GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
7962GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
7963GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
7964GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 7965
57951c27
AJ
7966/* SPE logic immediate */
7967#if defined(TARGET_PPC64)
7968#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 7969static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a
AJ
7970{ \
7971 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7972 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
7973 return; \
7974 } \
a7812ae4
PB
7975 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7976 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7977 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
7978 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7979 tcg_opi(t0, t0, rB(ctx->opcode)); \
7980 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7981 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 7982 tcg_temp_free_i64(t2); \
57951c27
AJ
7983 tcg_opi(t1, t1, rB(ctx->opcode)); \
7984 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
7985 tcg_temp_free_i32(t0); \
7986 tcg_temp_free_i32(t1); \
3d3a6a0a 7987}
57951c27
AJ
7988#else
7989#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 7990static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7991{ \
7992 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7993 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7994 return; \
7995 } \
57951c27
AJ
7996 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7997 rB(ctx->opcode)); \
7998 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7999 rB(ctx->opcode)); \
0487d6a8 8000}
57951c27
AJ
8001#endif
8002GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8003GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8004GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8005GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 8006
57951c27
AJ
8007/* SPE arithmetic */
8008#if defined(TARGET_PPC64)
8009#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8010static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8011{ \
8012 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8013 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8014 return; \
8015 } \
a7812ae4
PB
8016 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8017 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8018 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8019 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8020 tcg_op(t0, t0); \
8021 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8022 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8023 tcg_temp_free_i64(t2); \
57951c27
AJ
8024 tcg_op(t1, t1); \
8025 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8026 tcg_temp_free_i32(t0); \
8027 tcg_temp_free_i32(t1); \
0487d6a8 8028}
57951c27 8029#else
a7812ae4 8030#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8031static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8032{ \
8033 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8034 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8035 return; \
8036 } \
8037 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8038 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8039}
8040#endif
0487d6a8 8041
636aa200 8042static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27
AJ
8043{
8044 int l1 = gen_new_label();
8045 int l2 = gen_new_label();
0487d6a8 8046
57951c27
AJ
8047 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8048 tcg_gen_neg_i32(ret, arg1);
8049 tcg_gen_br(l2);
8050 gen_set_label(l1);
a7812ae4 8051 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
8052 gen_set_label(l2);
8053}
8054GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8055GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8056GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8057GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 8058static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 8059{
57951c27
AJ
8060 tcg_gen_addi_i32(ret, arg1, 0x8000);
8061 tcg_gen_ext16u_i32(ret, ret);
8062}
8063GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
8064GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8065GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 8066
57951c27
AJ
8067#if defined(TARGET_PPC64)
8068#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8069static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8070{ \
8071 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8072 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8073 return; \
8074 } \
a7812ae4
PB
8075 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8076 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8077 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
501e23c4 8078 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
57951c27
AJ
8079 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8080 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
8081 tcg_op(t0, t0, t2); \
8082 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
8083 tcg_gen_trunc_i64_i32(t1, t3); \
8084 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
8085 tcg_gen_trunc_i64_i32(t2, t3); \
a7812ae4 8086 tcg_temp_free_i64(t3); \
57951c27 8087 tcg_op(t1, t1, t2); \
a7812ae4 8088 tcg_temp_free_i32(t2); \
57951c27 8089 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8090 tcg_temp_free_i32(t0); \
8091 tcg_temp_free_i32(t1); \
0487d6a8 8092}
57951c27
AJ
8093#else
8094#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8095static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8096{ \
8097 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8098 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8099 return; \
8100 } \
57951c27
AJ
8101 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8102 cpu_gpr[rB(ctx->opcode)]); \
8103 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8104 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8105}
57951c27 8106#endif
0487d6a8 8107
636aa200 8108static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8109{
a7812ae4 8110 TCGv_i32 t0;
57951c27 8111 int l1, l2;
0487d6a8 8112
57951c27
AJ
8113 l1 = gen_new_label();
8114 l2 = gen_new_label();
a7812ae4 8115 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8116 /* No error here: 6 bits are used */
8117 tcg_gen_andi_i32(t0, arg2, 0x3F);
8118 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8119 tcg_gen_shr_i32(ret, arg1, t0);
8120 tcg_gen_br(l2);
8121 gen_set_label(l1);
8122 tcg_gen_movi_i32(ret, 0);
0aef4261 8123 gen_set_label(l2);
a7812ae4 8124 tcg_temp_free_i32(t0);
57951c27
AJ
8125}
8126GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 8127static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8128{
a7812ae4 8129 TCGv_i32 t0;
57951c27
AJ
8130 int l1, l2;
8131
8132 l1 = gen_new_label();
8133 l2 = gen_new_label();
a7812ae4 8134 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8135 /* No error here: 6 bits are used */
8136 tcg_gen_andi_i32(t0, arg2, 0x3F);
8137 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8138 tcg_gen_sar_i32(ret, arg1, t0);
8139 tcg_gen_br(l2);
8140 gen_set_label(l1);
8141 tcg_gen_movi_i32(ret, 0);
0aef4261 8142 gen_set_label(l2);
a7812ae4 8143 tcg_temp_free_i32(t0);
57951c27
AJ
8144}
8145GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 8146static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8147{
a7812ae4 8148 TCGv_i32 t0;
57951c27
AJ
8149 int l1, l2;
8150
8151 l1 = gen_new_label();
8152 l2 = gen_new_label();
a7812ae4 8153 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8154 /* No error here: 6 bits are used */
8155 tcg_gen_andi_i32(t0, arg2, 0x3F);
8156 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8157 tcg_gen_shl_i32(ret, arg1, t0);
8158 tcg_gen_br(l2);
8159 gen_set_label(l1);
8160 tcg_gen_movi_i32(ret, 0);
e29ef9fa 8161 gen_set_label(l2);
a7812ae4 8162 tcg_temp_free_i32(t0);
57951c27
AJ
8163}
8164GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 8165static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8166{
a7812ae4 8167 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
8168 tcg_gen_andi_i32(t0, arg2, 0x1F);
8169 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 8170 tcg_temp_free_i32(t0);
57951c27
AJ
8171}
8172GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 8173static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
8174{
8175 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8176 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8177 return;
8178 }
8179#if defined(TARGET_PPC64)
a7812ae4
PB
8180 TCGv t0 = tcg_temp_new();
8181 TCGv t1 = tcg_temp_new();
57951c27
AJ
8182 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8183 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8184 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8185 tcg_temp_free(t0);
8186 tcg_temp_free(t1);
8187#else
8188 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8189 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8190#endif
8191}
8192GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 8193static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 8194{
57951c27
AJ
8195 tcg_gen_sub_i32(ret, arg2, arg1);
8196}
8197GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 8198
57951c27
AJ
8199/* SPE arithmetic immediate */
8200#if defined(TARGET_PPC64)
8201#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8202static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8203{ \
8204 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8205 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8206 return; \
8207 } \
a7812ae4
PB
8208 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8209 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8210 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8211 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8212 tcg_op(t0, t0, rA(ctx->opcode)); \
8213 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8214 tcg_gen_trunc_i64_i32(t1, t2); \
e06fcd75 8215 tcg_temp_free_i64(t2); \
57951c27
AJ
8216 tcg_op(t1, t1, rA(ctx->opcode)); \
8217 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8218 tcg_temp_free_i32(t0); \
8219 tcg_temp_free_i32(t1); \
57951c27
AJ
8220}
8221#else
8222#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8223static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8224{ \
8225 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8226 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8227 return; \
8228 } \
8229 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
8230 rA(ctx->opcode)); \
8231 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
8232 rA(ctx->opcode)); \
8233}
8234#endif
8235GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8236GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8237
8238/* SPE comparison */
8239#if defined(TARGET_PPC64)
8240#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8241static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8242{ \
8243 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8244 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8245 return; \
8246 } \
8247 int l1 = gen_new_label(); \
8248 int l2 = gen_new_label(); \
8249 int l3 = gen_new_label(); \
8250 int l4 = gen_new_label(); \
a7812ae4
PB
8251 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8252 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8253 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8254 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8255 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8256 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
a7812ae4 8257 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8258 tcg_gen_br(l2); \
8259 gen_set_label(l1); \
8260 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8261 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8262 gen_set_label(l2); \
8263 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8264 tcg_gen_trunc_i64_i32(t0, t2); \
8265 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8266 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8267 tcg_temp_free_i64(t2); \
57951c27
AJ
8268 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8269 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8270 ~(CRF_CH | CRF_CH_AND_CL)); \
8271 tcg_gen_br(l4); \
8272 gen_set_label(l3); \
8273 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8274 CRF_CH | CRF_CH_OR_CL); \
8275 gen_set_label(l4); \
a7812ae4
PB
8276 tcg_temp_free_i32(t0); \
8277 tcg_temp_free_i32(t1); \
57951c27
AJ
8278}
8279#else
8280#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8281static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8282{ \
8283 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8284 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8285 return; \
8286 } \
8287 int l1 = gen_new_label(); \
8288 int l2 = gen_new_label(); \
8289 int l3 = gen_new_label(); \
8290 int l4 = gen_new_label(); \
8291 \
8292 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8293 cpu_gpr[rB(ctx->opcode)], l1); \
8294 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8295 tcg_gen_br(l2); \
8296 gen_set_label(l1); \
8297 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8298 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8299 gen_set_label(l2); \
8300 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8301 cpu_gprh[rB(ctx->opcode)], l3); \
8302 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8303 ~(CRF_CH | CRF_CH_AND_CL)); \
8304 tcg_gen_br(l4); \
8305 gen_set_label(l3); \
8306 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8307 CRF_CH | CRF_CH_OR_CL); \
8308 gen_set_label(l4); \
8309}
8310#endif
8311GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8312GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8313GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8314GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8315GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8316
8317/* SPE misc */
636aa200 8318static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8319{
8320 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8321 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8322 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8323}
636aa200 8324static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8325{
8326 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8327 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8328 return;
8329 }
8330#if defined(TARGET_PPC64)
a7812ae4
PB
8331 TCGv t0 = tcg_temp_new();
8332 TCGv t1 = tcg_temp_new();
17d9b3af 8333 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8334 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8335 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8336 tcg_temp_free(t0);
8337 tcg_temp_free(t1);
8338#else
57951c27 8339 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8340 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8341#endif
8342}
636aa200 8343static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8344{
8345 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8346 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8347 return;
8348 }
8349#if defined(TARGET_PPC64)
a7812ae4
PB
8350 TCGv t0 = tcg_temp_new();
8351 TCGv t1 = tcg_temp_new();
17d9b3af 8352 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8353 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8354 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8355 tcg_temp_free(t0);
8356 tcg_temp_free(t1);
8357#else
8358 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8359 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8360#endif
8361}
636aa200 8362static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8363{
8364 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8365 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8366 return;
8367 }
8368#if defined(TARGET_PPC64)
a7812ae4
PB
8369 TCGv t0 = tcg_temp_new();
8370 TCGv t1 = tcg_temp_new();
57951c27
AJ
8371 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8372 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8373 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8374 tcg_temp_free(t0);
8375 tcg_temp_free(t1);
8376#else
33890b3e
NF
8377 if (rD(ctx->opcode) == rA(ctx->opcode)) {
8378 TCGv_i32 tmp = tcg_temp_new_i32();
8379 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
8380 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8381 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
8382 tcg_temp_free_i32(tmp);
8383 } else {
8384 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8385 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8386 }
57951c27
AJ
8387#endif
8388}
636aa200 8389static inline void gen_evsplati(DisasContext *ctx)
57951c27 8390{
ae01847f 8391 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8392
57951c27 8393#if defined(TARGET_PPC64)
38d14952 8394 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8395#else
8396 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8397 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8398#endif
8399}
636aa200 8400static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8401{
ae01847f 8402 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8403
57951c27 8404#if defined(TARGET_PPC64)
38d14952 8405 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8406#else
8407 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8408 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8409#endif
0487d6a8
JM
8410}
8411
636aa200 8412static inline void gen_evsel(DisasContext *ctx)
57951c27
AJ
8413{
8414 int l1 = gen_new_label();
8415 int l2 = gen_new_label();
8416 int l3 = gen_new_label();
8417 int l4 = gen_new_label();
a7812ae4 8418 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8419#if defined(TARGET_PPC64)
a7812ae4
PB
8420 TCGv t1 = tcg_temp_local_new();
8421 TCGv t2 = tcg_temp_local_new();
57951c27
AJ
8422#endif
8423 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8424 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
8425#if defined(TARGET_PPC64)
8426 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8427#else
8428 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8429#endif
8430 tcg_gen_br(l2);
8431 gen_set_label(l1);
8432#if defined(TARGET_PPC64)
8433 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8434#else
8435 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8436#endif
8437 gen_set_label(l2);
8438 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8439 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
8440#if defined(TARGET_PPC64)
17d9b3af 8441 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8442#else
8443 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8444#endif
8445 tcg_gen_br(l4);
8446 gen_set_label(l3);
8447#if defined(TARGET_PPC64)
17d9b3af 8448 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8449#else
8450 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8451#endif
8452 gen_set_label(l4);
a7812ae4 8453 tcg_temp_free_i32(t0);
57951c27
AJ
8454#if defined(TARGET_PPC64)
8455 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
8456 tcg_temp_free(t1);
8457 tcg_temp_free(t2);
8458#endif
8459}
e8eaa2c0
BS
8460
8461static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
8462{
8463 gen_evsel(ctx);
8464}
e8eaa2c0
BS
8465
8466static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
8467{
8468 gen_evsel(ctx);
8469}
e8eaa2c0
BS
8470
8471static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
8472{
8473 gen_evsel(ctx);
8474}
e8eaa2c0
BS
8475
8476static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
8477{
8478 gen_evsel(ctx);
8479}
0487d6a8 8480
a0e13900
FC
8481/* Multiply */
8482
8483static inline void gen_evmwumi(DisasContext *ctx)
8484{
8485 TCGv_i64 t0, t1;
8486
8487 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8488 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8489 return;
8490 }
8491
8492 t0 = tcg_temp_new_i64();
8493 t1 = tcg_temp_new_i64();
8494
8495 /* t0 := rA; t1 := rB */
8496#if defined(TARGET_PPC64)
8497 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8498 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8499#else
8500 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8501 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8502#endif
8503
8504 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8505
8506 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8507
8508 tcg_temp_free_i64(t0);
8509 tcg_temp_free_i64(t1);
8510}
8511
8512static inline void gen_evmwumia(DisasContext *ctx)
8513{
8514 TCGv_i64 tmp;
8515
8516 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8517 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8518 return;
8519 }
8520
8521 gen_evmwumi(ctx); /* rD := rA * rB */
8522
8523 tmp = tcg_temp_new_i64();
8524
8525 /* acc := rD */
8526 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8527 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8528 tcg_temp_free_i64(tmp);
8529}
8530
8531static inline void gen_evmwumiaa(DisasContext *ctx)
8532{
8533 TCGv_i64 acc;
8534 TCGv_i64 tmp;
8535
8536 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8537 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8538 return;
8539 }
8540
8541 gen_evmwumi(ctx); /* rD := rA * rB */
8542
8543 acc = tcg_temp_new_i64();
8544 tmp = tcg_temp_new_i64();
8545
8546 /* tmp := rD */
8547 gen_load_gpr64(tmp, rD(ctx->opcode));
8548
8549 /* Load acc */
1328c2bf 8550 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8551
8552 /* acc := tmp + acc */
8553 tcg_gen_add_i64(acc, acc, tmp);
8554
8555 /* Store acc */
1328c2bf 8556 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8557
8558 /* rD := acc */
8559 gen_store_gpr64(rD(ctx->opcode), acc);
8560
8561 tcg_temp_free_i64(acc);
8562 tcg_temp_free_i64(tmp);
8563}
8564
8565static inline void gen_evmwsmi(DisasContext *ctx)
8566{
8567 TCGv_i64 t0, t1;
8568
8569 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8570 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8571 return;
8572 }
8573
8574 t0 = tcg_temp_new_i64();
8575 t1 = tcg_temp_new_i64();
8576
8577 /* t0 := rA; t1 := rB */
8578#if defined(TARGET_PPC64)
8579 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8580 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8581#else
8582 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8583 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8584#endif
8585
8586 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8587
8588 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8589
8590 tcg_temp_free_i64(t0);
8591 tcg_temp_free_i64(t1);
8592}
8593
8594static inline void gen_evmwsmia(DisasContext *ctx)
8595{
8596 TCGv_i64 tmp;
8597
8598 gen_evmwsmi(ctx); /* rD := rA * rB */
8599
8600 tmp = tcg_temp_new_i64();
8601
8602 /* acc := rD */
8603 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8604 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8605
8606 tcg_temp_free_i64(tmp);
8607}
8608
8609static inline void gen_evmwsmiaa(DisasContext *ctx)
8610{
8611 TCGv_i64 acc = tcg_temp_new_i64();
8612 TCGv_i64 tmp = tcg_temp_new_i64();
8613
8614 gen_evmwsmi(ctx); /* rD := rA * rB */
8615
8616 acc = tcg_temp_new_i64();
8617 tmp = tcg_temp_new_i64();
8618
8619 /* tmp := rD */
8620 gen_load_gpr64(tmp, rD(ctx->opcode));
8621
8622 /* Load acc */
1328c2bf 8623 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8624
8625 /* acc := tmp + acc */
8626 tcg_gen_add_i64(acc, acc, tmp);
8627
8628 /* Store acc */
1328c2bf 8629 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8630
8631 /* rD := acc */
8632 gen_store_gpr64(rD(ctx->opcode), acc);
8633
8634 tcg_temp_free_i64(acc);
8635 tcg_temp_free_i64(tmp);
8636}
8637
70560da7
FC
8638GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8639GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8640GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8641GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8642GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8643GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8644GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8645GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
8646GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
8647GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8648GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8649GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8650GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8651GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8652GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8653GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8654GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8655GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8656GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8657GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
8658GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8659GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8660GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
8661GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
8662GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8663GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8664GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8665GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8666GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 8667
6a6ae23f 8668/* SPE load and stores */
636aa200 8669static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
8670{
8671 target_ulong uimm = rB(ctx->opcode);
8672
76db3ba4 8673 if (rA(ctx->opcode) == 0) {
6a6ae23f 8674 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 8675 } else {
6a6ae23f 8676 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 8677 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
8678 tcg_gen_ext32u_tl(EA, EA);
8679 }
76db3ba4 8680 }
0487d6a8 8681}
6a6ae23f 8682
636aa200 8683static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8684{
8685#if defined(TARGET_PPC64)
76db3ba4 8686 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8687#else
8688 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 8689 gen_qemu_ld64(ctx, t0, addr);
6a6ae23f
AJ
8690 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
8691 tcg_gen_shri_i64(t0, t0, 32);
8692 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
8693 tcg_temp_free_i64(t0);
8694#endif
0487d6a8 8695}
6a6ae23f 8696
636aa200 8697static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 8698{
0487d6a8 8699#if defined(TARGET_PPC64)
6a6ae23f 8700 TCGv t0 = tcg_temp_new();
76db3ba4 8701 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f 8702 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
76db3ba4
AJ
8703 gen_addr_add(ctx, addr, addr, 4);
8704 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
8705 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8706 tcg_temp_free(t0);
8707#else
76db3ba4
AJ
8708 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8709 gen_addr_add(ctx, addr, addr, 4);
8710 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f 8711#endif
0487d6a8 8712}
6a6ae23f 8713
636aa200 8714static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8715{
8716 TCGv t0 = tcg_temp_new();
8717#if defined(TARGET_PPC64)
76db3ba4 8718 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8719 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
8720 gen_addr_add(ctx, addr, addr, 2);
8721 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8722 tcg_gen_shli_tl(t0, t0, 32);
8723 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8724 gen_addr_add(ctx, addr, addr, 2);
8725 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8726 tcg_gen_shli_tl(t0, t0, 16);
8727 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8728 gen_addr_add(ctx, addr, addr, 2);
8729 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8730 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 8731#else
76db3ba4 8732 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8733 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8734 gen_addr_add(ctx, addr, addr, 2);
8735 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8736 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
8737 gen_addr_add(ctx, addr, addr, 2);
8738 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8739 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8740 gen_addr_add(ctx, addr, addr, 2);
8741 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8742 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 8743#endif
6a6ae23f 8744 tcg_temp_free(t0);
0487d6a8
JM
8745}
8746
636aa200 8747static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8748{
8749 TCGv t0 = tcg_temp_new();
76db3ba4 8750 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8751#if defined(TARGET_PPC64)
8752 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
8753 tcg_gen_shli_tl(t0, t0, 16);
8754 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8755#else
8756 tcg_gen_shli_tl(t0, t0, 16);
8757 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8758 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8759#endif
8760 tcg_temp_free(t0);
0487d6a8
JM
8761}
8762
636aa200 8763static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8764{
8765 TCGv t0 = tcg_temp_new();
76db3ba4 8766 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8767#if defined(TARGET_PPC64)
8768 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8769 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8770#else
8771 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8772 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8773#endif
8774 tcg_temp_free(t0);
0487d6a8
JM
8775}
8776
636aa200 8777static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8778{
8779 TCGv t0 = tcg_temp_new();
76db3ba4 8780 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
8781#if defined(TARGET_PPC64)
8782 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8783 tcg_gen_ext32u_tl(t0, t0);
8784 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8785#else
8786 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8787 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8788#endif
8789 tcg_temp_free(t0);
8790}
8791
636aa200 8792static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8793{
8794 TCGv t0 = tcg_temp_new();
8795#if defined(TARGET_PPC64)
76db3ba4 8796 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8797 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
8798 gen_addr_add(ctx, addr, addr, 2);
8799 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8800 tcg_gen_shli_tl(t0, t0, 16);
8801 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8802#else
76db3ba4 8803 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8804 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8805 gen_addr_add(ctx, addr, addr, 2);
8806 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8807 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
8808#endif
8809 tcg_temp_free(t0);
8810}
8811
636aa200 8812static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8813{
8814#if defined(TARGET_PPC64)
8815 TCGv t0 = tcg_temp_new();
76db3ba4
AJ
8816 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
8817 gen_addr_add(ctx, addr, addr, 2);
8818 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8819 tcg_gen_shli_tl(t0, t0, 32);
8820 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8821 tcg_temp_free(t0);
8822#else
76db3ba4
AJ
8823 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8824 gen_addr_add(ctx, addr, addr, 2);
8825 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8826#endif
8827}
8828
636aa200 8829static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8830{
8831#if defined(TARGET_PPC64)
8832 TCGv t0 = tcg_temp_new();
76db3ba4 8833 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f 8834 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8835 gen_addr_add(ctx, addr, addr, 2);
8836 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
8837 tcg_gen_shli_tl(t0, t0, 32);
8838 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8839 tcg_temp_free(t0);
8840#else
76db3ba4
AJ
8841 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8842 gen_addr_add(ctx, addr, addr, 2);
8843 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8844#endif
8845}
8846
636aa200 8847static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8848{
8849 TCGv t0 = tcg_temp_new();
76db3ba4 8850 gen_qemu_ld32u(ctx, t0, addr);
0487d6a8 8851#if defined(TARGET_PPC64)
6a6ae23f
AJ
8852 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8853 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8854#else
8855 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8856 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8857#endif
8858 tcg_temp_free(t0);
8859}
8860
636aa200 8861static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8862{
8863 TCGv t0 = tcg_temp_new();
8864#if defined(TARGET_PPC64)
76db3ba4 8865 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8866 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
8867 tcg_gen_shli_tl(t0, t0, 32);
8868 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8869 gen_addr_add(ctx, addr, addr, 2);
8870 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8871 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8872 tcg_gen_shli_tl(t0, t0, 16);
8873 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8874#else
76db3ba4 8875 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8876 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
8877 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
8878 gen_addr_add(ctx, addr, addr, 2);
8879 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8880 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
8881 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
0487d6a8 8882#endif
6a6ae23f
AJ
8883 tcg_temp_free(t0);
8884}
8885
636aa200 8886static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8887{
8888#if defined(TARGET_PPC64)
76db3ba4 8889 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
0487d6a8 8890#else
6a6ae23f
AJ
8891 TCGv_i64 t0 = tcg_temp_new_i64();
8892 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
76db3ba4 8893 gen_qemu_st64(ctx, t0, addr);
6a6ae23f
AJ
8894 tcg_temp_free_i64(t0);
8895#endif
8896}
8897
636aa200 8898static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 8899{
0487d6a8 8900#if defined(TARGET_PPC64)
6a6ae23f
AJ
8901 TCGv t0 = tcg_temp_new();
8902 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8903 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
8904 tcg_temp_free(t0);
8905#else
76db3ba4 8906 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8907#endif
76db3ba4
AJ
8908 gen_addr_add(ctx, addr, addr, 4);
8909 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8910}
8911
636aa200 8912static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8913{
8914 TCGv t0 = tcg_temp_new();
8915#if defined(TARGET_PPC64)
8916 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
8917#else
8918 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
8919#endif
76db3ba4
AJ
8920 gen_qemu_st16(ctx, t0, addr);
8921 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f
AJ
8922#if defined(TARGET_PPC64)
8923 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8924 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 8925#else
76db3ba4 8926 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8927#endif
76db3ba4 8928 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 8929 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 8930 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 8931 tcg_temp_free(t0);
76db3ba4
AJ
8932 gen_addr_add(ctx, addr, addr, 2);
8933 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8934}
8935
636aa200 8936static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8937{
8938 TCGv t0 = tcg_temp_new();
8939#if defined(TARGET_PPC64)
8940 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
8941#else
8942 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
8943#endif
76db3ba4
AJ
8944 gen_qemu_st16(ctx, t0, addr);
8945 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 8946 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 8947 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
8948 tcg_temp_free(t0);
8949}
8950
636aa200 8951static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8952{
8953#if defined(TARGET_PPC64)
8954 TCGv t0 = tcg_temp_new();
8955 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8956 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
8957 tcg_temp_free(t0);
8958#else
76db3ba4 8959 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8960#endif
76db3ba4
AJ
8961 gen_addr_add(ctx, addr, addr, 2);
8962 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8963}
8964
636aa200 8965static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8966{
8967#if defined(TARGET_PPC64)
8968 TCGv t0 = tcg_temp_new();
8969 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8970 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
8971 tcg_temp_free(t0);
8972#else
76db3ba4 8973 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8974#endif
8975}
8976
636aa200 8977static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 8978{
76db3ba4 8979 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8980}
8981
8982#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 8983static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
8984{ \
8985 TCGv t0; \
8986 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8987 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
8988 return; \
8989 } \
76db3ba4 8990 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
8991 t0 = tcg_temp_new(); \
8992 if (Rc(ctx->opcode)) { \
76db3ba4 8993 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 8994 } else { \
76db3ba4 8995 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
8996 } \
8997 gen_op_##name(ctx, t0); \
8998 tcg_temp_free(t0); \
8999}
9000
9001GEN_SPEOP_LDST(evldd, 0x00, 3);
9002GEN_SPEOP_LDST(evldw, 0x01, 3);
9003GEN_SPEOP_LDST(evldh, 0x02, 3);
9004GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9005GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9006GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9007GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9008GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9009GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9010GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9011GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9012
9013GEN_SPEOP_LDST(evstdd, 0x10, 3);
9014GEN_SPEOP_LDST(evstdw, 0x11, 3);
9015GEN_SPEOP_LDST(evstdh, 0x12, 3);
9016GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9017GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9018GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9019GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
9020
9021/* Multiply and add - TODO */
9022#if 0
70560da7
FC
9023GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9024GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9025GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9026GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9027GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9028GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9029GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9030GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9031GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9032GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9033GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9034GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9035
9036GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9037GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9038GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9039GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9040GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9041GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9042GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9043GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9044GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9045GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9046GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9047GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9048
9049GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9050GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9051GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9052GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9053GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9054
9055GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9056GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9057GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9058GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9059GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9060GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9061GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9062GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9063GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9064GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9065GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9066GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9067
9068GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9069GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9070GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9071GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9072
9073GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9074GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9075GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9076GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9077GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9078GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9079GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9080GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9081GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9082GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9083GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9084GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9085
9086GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9087GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9088GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9089GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9090GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
9091#endif
9092
9093/*** SPE floating-point extension ***/
1c97856d
AJ
9094#if defined(TARGET_PPC64)
9095#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9096static inline void gen_##name(DisasContext *ctx) \
0487d6a8 9097{ \
1c97856d
AJ
9098 TCGv_i32 t0; \
9099 TCGv t1; \
9100 t0 = tcg_temp_new_i32(); \
9101 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9102 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9103 t1 = tcg_temp_new(); \
9104 tcg_gen_extu_i32_tl(t1, t0); \
9105 tcg_temp_free_i32(t0); \
9106 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9107 0xFFFFFFFF00000000ULL); \
9108 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9109 tcg_temp_free(t1); \
0487d6a8 9110}
1c97856d 9111#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9112static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9113{ \
9114 TCGv_i32 t0; \
9115 TCGv t1; \
9116 t0 = tcg_temp_new_i32(); \
8e703949 9117 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9118 t1 = tcg_temp_new(); \
9119 tcg_gen_extu_i32_tl(t1, t0); \
9120 tcg_temp_free_i32(t0); \
9121 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9122 0xFFFFFFFF00000000ULL); \
9123 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9124 tcg_temp_free(t1); \
9125}
9126#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9127static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9128{ \
9129 TCGv_i32 t0 = tcg_temp_new_i32(); \
9130 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9131 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9132 tcg_temp_free_i32(t0); \
9133}
9134#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9135static inline void gen_##name(DisasContext *ctx) \
1c97856d 9136{ \
8e703949
BS
9137 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9138 cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9139}
9140#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9141static inline void gen_##name(DisasContext *ctx) \
57951c27 9142{ \
1c97856d
AJ
9143 TCGv_i32 t0, t1; \
9144 TCGv_i64 t2; \
57951c27 9145 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9146 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9147 return; \
9148 } \
1c97856d
AJ
9149 t0 = tcg_temp_new_i32(); \
9150 t1 = tcg_temp_new_i32(); \
9151 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9152 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9153 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9154 tcg_temp_free_i32(t1); \
9155 t2 = tcg_temp_new(); \
9156 tcg_gen_extu_i32_tl(t2, t0); \
9157 tcg_temp_free_i32(t0); \
9158 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9159 0xFFFFFFFF00000000ULL); \
9160 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
9161 tcg_temp_free(t2); \
57951c27 9162}
1c97856d 9163#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9164static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
9165{ \
9166 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9167 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9168 return; \
9169 } \
8e703949
BS
9170 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9171 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
57951c27 9172}
1c97856d 9173#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9174static inline void gen_##name(DisasContext *ctx) \
57951c27 9175{ \
1c97856d 9176 TCGv_i32 t0, t1; \
57951c27 9177 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9178 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9179 return; \
9180 } \
1c97856d
AJ
9181 t0 = tcg_temp_new_i32(); \
9182 t1 = tcg_temp_new_i32(); \
9183 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9184 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9185 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9186 tcg_temp_free_i32(t0); \
9187 tcg_temp_free_i32(t1); \
9188}
9189#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9190static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9191{ \
9192 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9193 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9194 return; \
9195 } \
8e703949 9196 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9197 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9198}
9199#else
9200#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9201static inline void gen_##name(DisasContext *ctx) \
1c97856d 9202{ \
8e703949
BS
9203 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9204 cpu_gpr[rB(ctx->opcode)]); \
57951c27 9205}
1c97856d 9206#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9207static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9208{ \
9209 TCGv_i64 t0 = tcg_temp_new_i64(); \
9210 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9211 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9212 tcg_temp_free_i64(t0); \
9213}
9214#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9215static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9216{ \
9217 TCGv_i64 t0 = tcg_temp_new_i64(); \
8e703949 9218 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9219 gen_store_gpr64(rD(ctx->opcode), t0); \
9220 tcg_temp_free_i64(t0); \
9221}
9222#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9223static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9224{ \
9225 TCGv_i64 t0 = tcg_temp_new_i64(); \
9226 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9227 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9228 gen_store_gpr64(rD(ctx->opcode), t0); \
9229 tcg_temp_free_i64(t0); \
9230}
9231#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9232static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9233{ \
9234 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9235 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9236 return; \
9237 } \
8e703949 9238 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9239 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9240}
9241#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9242static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9243{ \
9244 TCGv_i64 t0, t1; \
9245 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9246 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9247 return; \
9248 } \
9249 t0 = tcg_temp_new_i64(); \
9250 t1 = tcg_temp_new_i64(); \
9251 gen_load_gpr64(t0, rA(ctx->opcode)); \
9252 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9253 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9254 gen_store_gpr64(rD(ctx->opcode), t0); \
9255 tcg_temp_free_i64(t0); \
9256 tcg_temp_free_i64(t1); \
9257}
9258#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9259static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9260{ \
9261 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9262 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9263 return; \
9264 } \
8e703949 9265 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9266 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9267}
9268#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9269static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9270{ \
9271 TCGv_i64 t0, t1; \
9272 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9273 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9274 return; \
9275 } \
9276 t0 = tcg_temp_new_i64(); \
9277 t1 = tcg_temp_new_i64(); \
9278 gen_load_gpr64(t0, rA(ctx->opcode)); \
9279 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9280 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9281 tcg_temp_free_i64(t0); \
9282 tcg_temp_free_i64(t1); \
9283}
9284#endif
57951c27 9285
0487d6a8
JM
9286/* Single precision floating-point vectors operations */
9287/* Arithmetic */
1c97856d
AJ
9288GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9289GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9290GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9291GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9292static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9293{
9294 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9295 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9296 return;
9297 }
9298#if defined(TARGET_PPC64)
6d5c34fa 9299 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
1c97856d 9300#else
6d5c34fa
MP
9301 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
9302 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9303#endif
9304}
636aa200 9305static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9306{
9307 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9308 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9309 return;
9310 }
9311#if defined(TARGET_PPC64)
6d5c34fa 9312 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9313#else
6d5c34fa
MP
9314 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9315 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9316#endif
9317}
636aa200 9318static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9319{
9320 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9321 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9322 return;
9323 }
9324#if defined(TARGET_PPC64)
6d5c34fa 9325 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9326#else
6d5c34fa
MP
9327 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9328 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9329#endif
9330}
9331
0487d6a8 9332/* Conversion */
1c97856d
AJ
9333GEN_SPEFPUOP_CONV_64_64(evfscfui);
9334GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9335GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9336GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9337GEN_SPEFPUOP_CONV_64_64(evfsctui);
9338GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9339GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9340GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9341GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9342GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9343
0487d6a8 9344/* Comparison */
1c97856d
AJ
9345GEN_SPEFPUOP_COMP_64(evfscmpgt);
9346GEN_SPEFPUOP_COMP_64(evfscmplt);
9347GEN_SPEFPUOP_COMP_64(evfscmpeq);
9348GEN_SPEFPUOP_COMP_64(evfststgt);
9349GEN_SPEFPUOP_COMP_64(evfststlt);
9350GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9351
9352/* Opcodes definitions */
70560da7
FC
9353GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9354GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9355GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9356GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9357GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9358GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9359GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9360GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9361GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9362GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9363GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9364GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9365GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9366GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9367
9368/* Single precision floating-point operations */
9369/* Arithmetic */
1c97856d
AJ
9370GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9371GEN_SPEFPUOP_ARITH2_32_32(efssub);
9372GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9373GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9374static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9375{
9376 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9377 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9378 return;
9379 }
6d5c34fa 9380 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9381}
636aa200 9382static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9383{
9384 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9385 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9386 return;
9387 }
6d5c34fa 9388 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9389}
636aa200 9390static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9391{
9392 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9393 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9394 return;
9395 }
6d5c34fa 9396 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9397}
9398
0487d6a8 9399/* Conversion */
1c97856d
AJ
9400GEN_SPEFPUOP_CONV_32_32(efscfui);
9401GEN_SPEFPUOP_CONV_32_32(efscfsi);
9402GEN_SPEFPUOP_CONV_32_32(efscfuf);
9403GEN_SPEFPUOP_CONV_32_32(efscfsf);
9404GEN_SPEFPUOP_CONV_32_32(efsctui);
9405GEN_SPEFPUOP_CONV_32_32(efsctsi);
9406GEN_SPEFPUOP_CONV_32_32(efsctuf);
9407GEN_SPEFPUOP_CONV_32_32(efsctsf);
9408GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9409GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9410GEN_SPEFPUOP_CONV_32_64(efscfd);
9411
0487d6a8 9412/* Comparison */
1c97856d
AJ
9413GEN_SPEFPUOP_COMP_32(efscmpgt);
9414GEN_SPEFPUOP_COMP_32(efscmplt);
9415GEN_SPEFPUOP_COMP_32(efscmpeq);
9416GEN_SPEFPUOP_COMP_32(efststgt);
9417GEN_SPEFPUOP_COMP_32(efststlt);
9418GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9419
9420/* Opcodes definitions */
70560da7
FC
9421GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9422GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9423GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9424GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9425GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9426GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9427GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9428GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9429GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9430GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9431GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9432GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9433GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9434GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9435
9436/* Double precision floating-point operations */
9437/* Arithmetic */
1c97856d
AJ
9438GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9439GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9440GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9441GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9442static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9443{
9444 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9445 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9446 return;
9447 }
9448#if defined(TARGET_PPC64)
6d5c34fa 9449 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
1c97856d 9450#else
6d5c34fa
MP
9451 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9452 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9453#endif
9454}
636aa200 9455static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
9456{
9457 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9458 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9459 return;
9460 }
9461#if defined(TARGET_PPC64)
6d5c34fa 9462 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9463#else
6d5c34fa
MP
9464 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9465 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9466#endif
9467}
636aa200 9468static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
9469{
9470 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9471 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9472 return;
9473 }
9474#if defined(TARGET_PPC64)
6d5c34fa 9475 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9476#else
6d5c34fa
MP
9477 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9478 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9479#endif
9480}
9481
0487d6a8 9482/* Conversion */
1c97856d
AJ
9483GEN_SPEFPUOP_CONV_64_32(efdcfui);
9484GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9485GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9486GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9487GEN_SPEFPUOP_CONV_32_64(efdctui);
9488GEN_SPEFPUOP_CONV_32_64(efdctsi);
9489GEN_SPEFPUOP_CONV_32_64(efdctuf);
9490GEN_SPEFPUOP_CONV_32_64(efdctsf);
9491GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9492GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9493GEN_SPEFPUOP_CONV_64_32(efdcfs);
9494GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9495GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9496GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9497GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 9498
0487d6a8 9499/* Comparison */
1c97856d
AJ
9500GEN_SPEFPUOP_COMP_64(efdcmpgt);
9501GEN_SPEFPUOP_COMP_64(efdcmplt);
9502GEN_SPEFPUOP_COMP_64(efdcmpeq);
9503GEN_SPEFPUOP_COMP_64(efdtstgt);
9504GEN_SPEFPUOP_COMP_64(efdtstlt);
9505GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
9506
9507/* Opcodes definitions */
70560da7
FC
9508GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9509GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9510GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9511GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9512GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9513GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9514GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9515GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9516GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9517GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9518GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9519GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9520GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9521GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9522GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9523GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 9524
c227f099 9525static opcode_t opcodes[] = {
5c55ff99
BS
9526GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9527GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9528GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9529GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9530GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 9531GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9532GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9533GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9534GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9535GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9536GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9537GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9538GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9539GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9540GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9541GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9542#if defined(TARGET_PPC64)
9543GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9544#endif
9545GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9546GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9547GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9548GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9549GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9550GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9551GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9552GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9553GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9554GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9555GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9556GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9557GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 9558GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 9559GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 9560#if defined(TARGET_PPC64)
eaabeef2 9561GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 9562GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 9563GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
86ba37ed 9564GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
5c55ff99
BS
9565#endif
9566GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9567GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9568GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9569GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9570GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9571GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9572GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9573#if defined(TARGET_PPC64)
9574GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9575GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9576GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9577GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9578GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9579#endif
9580GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9581GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9582GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9583GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9584GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 9585GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 9586GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
9587GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9588GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 9589GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
097ec5d8
TM
9590GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
9591GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
5c55ff99
BS
9592GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9593GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9594GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9595GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
9596GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9597GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
9598#if defined(TARGET_PPC64)
9599GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9600GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9601GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9602#endif
9603GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9604GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9605GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9606GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9607GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9608GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9609GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9610GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
5c77a786
TM
9611GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9612GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
f844c817 9613GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
587c51f7
TM
9614GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9615GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
5c55ff99
BS
9616GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9617#if defined(TARGET_PPC64)
f844c817 9618GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
5c55ff99
BS
9619GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
9620#endif
9621GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9622GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9623GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9624GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9625GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9626GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
52a4984d 9627GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
5c55ff99
BS
9628GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9629GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9630#if defined(TARGET_PPC64)
9631GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9632GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9633#endif
9634GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9635GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9636GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9637#if defined(TARGET_PPC64)
9638GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9639GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9640#endif
9641GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9642GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9643GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9644GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9645GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9646GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9647#if defined(TARGET_PPC64)
9648GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9649#endif
9650GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
9651GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
9652GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9653GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9654GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
3f34cf91
CLG
9655GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
9656GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
8e33944f 9657GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
9658GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9659GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9660GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9661GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9662GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9663GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9664GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9665GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9666GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9667#if defined(TARGET_PPC64)
9668GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9669GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9670 PPC_SEGMENT_64B),
9671GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
9672GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9673 PPC_SEGMENT_64B),
efdef95f
DG
9674GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
9675GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
9676GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
9677#endif
9678GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
9679GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
9680GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
9681GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
9682#if defined(TARGET_PPC64)
9683GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
9684GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
9685#endif
9686GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
9687GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
9688GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
9689GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
9690GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
9691GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
9692GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
9693GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
9694GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
9695GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
9696GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
9697GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9698GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
9699GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
9700GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
9701GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
9702GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
9703GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
9704GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
9705GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9706GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
9707GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
9708GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
9709GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
9710GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
9711GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
9712GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
9713GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
9714GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
9715GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
9716GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
9717GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
9718GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
9719GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
9720GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
9721GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
9722GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
9723GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
9724GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
9725GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
9726GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
9727GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
9728GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
9729GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
9730GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
9731GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
9732GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
9733GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
9734GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
9735GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9736GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9737GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
9738GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
9739GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9740GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9741GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
9742GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
9743GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
9744GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
9745GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
9746GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
9747GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
9748GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
9749GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
9750GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
9751GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
9752GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
9753GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
9754GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
9755GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
9756GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 9757GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
9758GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
9759GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
9760GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
9761GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
9762GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
9763GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
9764GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
9765GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
9766GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
9767 PPC_NONE, PPC2_BOOKE206),
9768GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
9769 PPC_NONE, PPC2_BOOKE206),
9770GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
9771 PPC_NONE, PPC2_BOOKE206),
9772GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
9773 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
9774GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
9775 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
9776GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
9777 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
9778GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
9779 PPC_NONE, PPC2_PRCNTL),
5c55ff99 9780GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 9781GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 9782GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
9783GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
9784 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 9785GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
9786GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
9787 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
9788GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
9789GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
9790GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
9791GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
9792GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC),
9793GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
9794GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
9795GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
9796GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
9797GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
9798
9799#undef GEN_INT_ARITH_ADD
9800#undef GEN_INT_ARITH_ADD_CONST
9801#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
9802GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
9803#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
9804 add_ca, compute_ca, compute_ov) \
9805GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
9806GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
9807GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
9808GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
9809GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
9810GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
9811GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
9812GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
9813GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
9814GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
9815GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
9816
9817#undef GEN_INT_ARITH_DIVW
9818#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
9819GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
9820GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
9821GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
9822GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
9823GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
a98eb9e9
TM
9824GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
9825GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
6a4fda33
TM
9826GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
9827GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
5c55ff99
BS
9828
9829#if defined(TARGET_PPC64)
9830#undef GEN_INT_ARITH_DIVD
9831#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
9832GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9833GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
9834GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
9835GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
9836GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
9837
98d1eb27
TM
9838GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
9839GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
e44259b6
TM
9840GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
9841GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
98d1eb27 9842
5c55ff99
BS
9843#undef GEN_INT_ARITH_MUL_HELPER
9844#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
9845GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9846GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
9847GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
9848GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
9849#endif
9850
9851#undef GEN_INT_ARITH_SUBF
9852#undef GEN_INT_ARITH_SUBF_CONST
9853#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
9854GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
9855#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
9856 add_ca, compute_ca, compute_ov) \
9857GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
9858GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
9859GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
9860GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
9861GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
9862GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
9863GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
9864GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
9865GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
9866GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
9867GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
9868
9869#undef GEN_LOGICAL1
9870#undef GEN_LOGICAL2
9871#define GEN_LOGICAL2(name, tcg_op, opc, type) \
9872GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
9873#define GEN_LOGICAL1(name, tcg_op, opc, type) \
9874GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
9875GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
9876GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
9877GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
9878GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
9879GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
9880GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
9881GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
9882GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
9883#if defined(TARGET_PPC64)
9884GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
9885#endif
9886
9887#if defined(TARGET_PPC64)
9888#undef GEN_PPC64_R2
9889#undef GEN_PPC64_R4
9890#define GEN_PPC64_R2(name, opc1, opc2) \
9891GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9892GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9893 PPC_64B)
9894#define GEN_PPC64_R4(name, opc1, opc2) \
9895GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9896GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
9897 PPC_64B), \
9898GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9899 PPC_64B), \
9900GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
9901 PPC_64B)
9902GEN_PPC64_R4(rldicl, 0x1E, 0x00),
9903GEN_PPC64_R4(rldicr, 0x1E, 0x02),
9904GEN_PPC64_R4(rldic, 0x1E, 0x04),
9905GEN_PPC64_R2(rldcl, 0x1E, 0x08),
9906GEN_PPC64_R2(rldcr, 0x1E, 0x09),
9907GEN_PPC64_R4(rldimi, 0x1E, 0x06),
9908#endif
9909
9910#undef _GEN_FLOAT_ACB
9911#undef GEN_FLOAT_ACB
9912#undef _GEN_FLOAT_AB
9913#undef GEN_FLOAT_AB
9914#undef _GEN_FLOAT_AC
9915#undef GEN_FLOAT_AC
9916#undef GEN_FLOAT_B
9917#undef GEN_FLOAT_BS
9918#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
9919GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
9920#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
9921_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
9922_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
9923#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9924GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9925#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
9926_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9927_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9928#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9929GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9930#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
9931_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9932_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9933#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
9934GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
9935#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
9936GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
9937
9938GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
9939GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
9940GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
9941GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
9942GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
9943GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
9944_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
9945GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
9946GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
9947GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
9948GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
9949GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
da29cb7b 9950GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
6d41d146 9951GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
5c55ff99 9952GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
fab7fe42 9953GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 9954GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
fab7fe42 9955GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
9956GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
9957#if defined(TARGET_PPC64)
9958GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
28288b48
TM
9959GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
9960GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
9961GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 9962GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
fab7fe42 9963GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 9964GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
fab7fe42 9965GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
9966#endif
9967GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
9968GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
9969GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
9970GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
9971
9972#undef GEN_LD
9973#undef GEN_LDU
9974#undef GEN_LDUX
cd6e9320 9975#undef GEN_LDX_E
5c55ff99
BS
9976#undef GEN_LDS
9977#define GEN_LD(name, ldop, opc, type) \
9978GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9979#define GEN_LDU(name, ldop, opc, type) \
9980GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9981#define GEN_LDUX(name, ldop, opc2, opc3, type) \
9982GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
9983#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
9984GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
9985#define GEN_LDS(name, ldop, op, type) \
9986GEN_LD(name, ldop, op | 0x20, type) \
9987GEN_LDU(name, ldop, op | 0x21, type) \
9988GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
9989GEN_LDX(name, ldop, 0x17, op | 0x00, type)
9990
9991GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
9992GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
9993GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
9994GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
9995#if defined(TARGET_PPC64)
9996GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
9997GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
9998GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
9999GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 10000GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10001#endif
10002GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10003GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10004
10005#undef GEN_ST
10006#undef GEN_STU
10007#undef GEN_STUX
cd6e9320 10008#undef GEN_STX_E
5c55ff99
BS
10009#undef GEN_STS
10010#define GEN_ST(name, stop, opc, type) \
10011GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10012#define GEN_STU(name, stop, opc, type) \
10013GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10014#define GEN_STUX(name, stop, opc2, opc3, type) \
10015GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10016#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10017GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10018#define GEN_STS(name, stop, op, type) \
10019GEN_ST(name, stop, op | 0x20, type) \
10020GEN_STU(name, stop, op | 0x21, type) \
10021GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10022GEN_STX(name, stop, 0x17, op | 0x00, type)
10023
10024GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10025GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10026GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10027#if defined(TARGET_PPC64)
10028GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10029GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 10030GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10031#endif
10032GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10033GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10034
10035#undef GEN_LDF
10036#undef GEN_LDUF
10037#undef GEN_LDUXF
10038#undef GEN_LDXF
10039#undef GEN_LDFS
10040#define GEN_LDF(name, ldop, opc, type) \
10041GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10042#define GEN_LDUF(name, ldop, opc, type) \
10043GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10044#define GEN_LDUXF(name, ldop, opc, type) \
10045GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10046#define GEN_LDXF(name, ldop, opc2, opc3, type) \
10047GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10048#define GEN_LDFS(name, ldop, op, type) \
10049GEN_LDF(name, ldop, op | 0x20, type) \
10050GEN_LDUF(name, ldop, op | 0x21, type) \
10051GEN_LDUXF(name, ldop, op | 0x01, type) \
10052GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10053
10054GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10055GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 10056GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
66c3e328 10057GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
05050ee8
AJ
10058GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10059GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10060
10061#undef GEN_STF
10062#undef GEN_STUF
10063#undef GEN_STUXF
10064#undef GEN_STXF
10065#undef GEN_STFS
10066#define GEN_STF(name, stop, opc, type) \
10067GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10068#define GEN_STUF(name, stop, opc, type) \
10069GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10070#define GEN_STUXF(name, stop, opc, type) \
10071GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10072#define GEN_STXF(name, stop, opc2, opc3, type) \
10073GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10074#define GEN_STFS(name, stop, op, type) \
10075GEN_STF(name, stop, op | 0x20, type) \
10076GEN_STUF(name, stop, op | 0x21, type) \
10077GEN_STUXF(name, stop, op | 0x01, type) \
10078GEN_STXF(name, stop, 0x17, op | 0x00, type)
10079
10080GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10081GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10082GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
10083GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10084GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10085
10086#undef GEN_CRLOGIC
10087#define GEN_CRLOGIC(name, tcg_op, opc) \
10088GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10089GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10090GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10091GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10092GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10093GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10094GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10095GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10096GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10097
10098#undef GEN_MAC_HANDLER
10099#define GEN_MAC_HANDLER(name, opc2, opc3) \
10100GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10101GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10102GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10103GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10104GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10105GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10106GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10107GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10108GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10109GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10110GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10111GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10112GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10113GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10114GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10115GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10116GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10117GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10118GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10119GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10120GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10121GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10122GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10123GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10124GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10125GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10126GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10127GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10128GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10129GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10130GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10131GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10132GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10133GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10134GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10135GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10136GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10137GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10138GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10139GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10140GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10141GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10142GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10143
10144#undef GEN_VR_LDX
10145#undef GEN_VR_STX
10146#undef GEN_VR_LVE
10147#undef GEN_VR_STVE
10148#define GEN_VR_LDX(name, opc2, opc3) \
10149GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10150#define GEN_VR_STX(name, opc2, opc3) \
10151GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10152#define GEN_VR_LVE(name, opc2, opc3) \
10153 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10154#define GEN_VR_STVE(name, opc2, opc3) \
10155 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10156GEN_VR_LDX(lvx, 0x07, 0x03),
10157GEN_VR_LDX(lvxl, 0x07, 0x0B),
10158GEN_VR_LVE(bx, 0x07, 0x00),
10159GEN_VR_LVE(hx, 0x07, 0x01),
10160GEN_VR_LVE(wx, 0x07, 0x02),
10161GEN_VR_STX(svx, 0x07, 0x07),
10162GEN_VR_STX(svxl, 0x07, 0x0F),
10163GEN_VR_STVE(bx, 0x07, 0x04),
10164GEN_VR_STVE(hx, 0x07, 0x05),
10165GEN_VR_STVE(wx, 0x07, 0x06),
10166
10167#undef GEN_VX_LOGICAL
10168#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10169GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10170GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10171GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10172GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10173GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10174GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
10175
10176#undef GEN_VXFORM
10177#define GEN_VXFORM(name, opc2, opc3) \
10178GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10179GEN_VXFORM(vaddubm, 0, 0),
10180GEN_VXFORM(vadduhm, 0, 1),
10181GEN_VXFORM(vadduwm, 0, 2),
10182GEN_VXFORM(vsububm, 0, 16),
10183GEN_VXFORM(vsubuhm, 0, 17),
10184GEN_VXFORM(vsubuwm, 0, 18),
10185GEN_VXFORM(vmaxub, 1, 0),
10186GEN_VXFORM(vmaxuh, 1, 1),
10187GEN_VXFORM(vmaxuw, 1, 2),
10188GEN_VXFORM(vmaxsb, 1, 4),
10189GEN_VXFORM(vmaxsh, 1, 5),
10190GEN_VXFORM(vmaxsw, 1, 6),
10191GEN_VXFORM(vminub, 1, 8),
10192GEN_VXFORM(vminuh, 1, 9),
10193GEN_VXFORM(vminuw, 1, 10),
10194GEN_VXFORM(vminsb, 1, 12),
10195GEN_VXFORM(vminsh, 1, 13),
10196GEN_VXFORM(vminsw, 1, 14),
10197GEN_VXFORM(vavgub, 1, 16),
10198GEN_VXFORM(vavguh, 1, 17),
10199GEN_VXFORM(vavguw, 1, 18),
10200GEN_VXFORM(vavgsb, 1, 20),
10201GEN_VXFORM(vavgsh, 1, 21),
10202GEN_VXFORM(vavgsw, 1, 22),
10203GEN_VXFORM(vmrghb, 6, 0),
10204GEN_VXFORM(vmrghh, 6, 1),
10205GEN_VXFORM(vmrghw, 6, 2),
10206GEN_VXFORM(vmrglb, 6, 4),
10207GEN_VXFORM(vmrglh, 6, 5),
10208GEN_VXFORM(vmrglw, 6, 6),
10209GEN_VXFORM(vmuloub, 4, 0),
10210GEN_VXFORM(vmulouh, 4, 1),
10211GEN_VXFORM(vmulosb, 4, 4),
10212GEN_VXFORM(vmulosh, 4, 5),
10213GEN_VXFORM(vmuleub, 4, 8),
10214GEN_VXFORM(vmuleuh, 4, 9),
10215GEN_VXFORM(vmulesb, 4, 12),
10216GEN_VXFORM(vmulesh, 4, 13),
10217GEN_VXFORM(vslb, 2, 4),
10218GEN_VXFORM(vslh, 2, 5),
10219GEN_VXFORM(vslw, 2, 6),
10220GEN_VXFORM(vsrb, 2, 8),
10221GEN_VXFORM(vsrh, 2, 9),
10222GEN_VXFORM(vsrw, 2, 10),
10223GEN_VXFORM(vsrab, 2, 12),
10224GEN_VXFORM(vsrah, 2, 13),
10225GEN_VXFORM(vsraw, 2, 14),
10226GEN_VXFORM(vslo, 6, 16),
10227GEN_VXFORM(vsro, 6, 17),
10228GEN_VXFORM(vaddcuw, 0, 6),
10229GEN_VXFORM(vsubcuw, 0, 22),
10230GEN_VXFORM(vaddubs, 0, 8),
10231GEN_VXFORM(vadduhs, 0, 9),
10232GEN_VXFORM(vadduws, 0, 10),
10233GEN_VXFORM(vaddsbs, 0, 12),
10234GEN_VXFORM(vaddshs, 0, 13),
10235GEN_VXFORM(vaddsws, 0, 14),
10236GEN_VXFORM(vsububs, 0, 24),
10237GEN_VXFORM(vsubuhs, 0, 25),
10238GEN_VXFORM(vsubuws, 0, 26),
10239GEN_VXFORM(vsubsbs, 0, 28),
10240GEN_VXFORM(vsubshs, 0, 29),
10241GEN_VXFORM(vsubsws, 0, 30),
10242GEN_VXFORM(vrlb, 2, 0),
10243GEN_VXFORM(vrlh, 2, 1),
10244GEN_VXFORM(vrlw, 2, 2),
10245GEN_VXFORM(vsl, 2, 7),
10246GEN_VXFORM(vsr, 2, 11),
10247GEN_VXFORM(vpkuhum, 7, 0),
10248GEN_VXFORM(vpkuwum, 7, 1),
10249GEN_VXFORM(vpkuhus, 7, 2),
10250GEN_VXFORM(vpkuwus, 7, 3),
10251GEN_VXFORM(vpkshus, 7, 4),
10252GEN_VXFORM(vpkswus, 7, 5),
10253GEN_VXFORM(vpkshss, 7, 6),
10254GEN_VXFORM(vpkswss, 7, 7),
10255GEN_VXFORM(vpkpx, 7, 12),
10256GEN_VXFORM(vsum4ubs, 4, 24),
10257GEN_VXFORM(vsum4sbs, 4, 28),
10258GEN_VXFORM(vsum4shs, 4, 25),
10259GEN_VXFORM(vsum2sws, 4, 26),
10260GEN_VXFORM(vsumsws, 4, 30),
10261GEN_VXFORM(vaddfp, 5, 0),
10262GEN_VXFORM(vsubfp, 5, 1),
10263GEN_VXFORM(vmaxfp, 5, 16),
10264GEN_VXFORM(vminfp, 5, 17),
10265
10266#undef GEN_VXRFORM1
10267#undef GEN_VXRFORM
10268#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10269 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10270#define GEN_VXRFORM(name, opc2, opc3) \
10271 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10272 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10273GEN_VXRFORM(vcmpequb, 3, 0)
10274GEN_VXRFORM(vcmpequh, 3, 1)
10275GEN_VXRFORM(vcmpequw, 3, 2)
10276GEN_VXRFORM(vcmpgtsb, 3, 12)
10277GEN_VXRFORM(vcmpgtsh, 3, 13)
10278GEN_VXRFORM(vcmpgtsw, 3, 14)
10279GEN_VXRFORM(vcmpgtub, 3, 8)
10280GEN_VXRFORM(vcmpgtuh, 3, 9)
10281GEN_VXRFORM(vcmpgtuw, 3, 10)
10282GEN_VXRFORM(vcmpeqfp, 3, 3)
10283GEN_VXRFORM(vcmpgefp, 3, 7)
10284GEN_VXRFORM(vcmpgtfp, 3, 11)
10285GEN_VXRFORM(vcmpbfp, 3, 15)
10286
10287#undef GEN_VXFORM_SIMM
10288#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10289 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10290GEN_VXFORM_SIMM(vspltisb, 6, 12),
10291GEN_VXFORM_SIMM(vspltish, 6, 13),
10292GEN_VXFORM_SIMM(vspltisw, 6, 14),
10293
10294#undef GEN_VXFORM_NOA
10295#define GEN_VXFORM_NOA(name, opc2, opc3) \
10296 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10297GEN_VXFORM_NOA(vupkhsb, 7, 8),
10298GEN_VXFORM_NOA(vupkhsh, 7, 9),
10299GEN_VXFORM_NOA(vupklsb, 7, 10),
10300GEN_VXFORM_NOA(vupklsh, 7, 11),
10301GEN_VXFORM_NOA(vupkhpx, 7, 13),
10302GEN_VXFORM_NOA(vupklpx, 7, 15),
10303GEN_VXFORM_NOA(vrefp, 5, 4),
10304GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10305GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99
BS
10306GEN_VXFORM_NOA(vlogefp, 5, 7),
10307GEN_VXFORM_NOA(vrfim, 5, 8),
10308GEN_VXFORM_NOA(vrfin, 5, 9),
10309GEN_VXFORM_NOA(vrfip, 5, 10),
10310GEN_VXFORM_NOA(vrfiz, 5, 11),
10311
10312#undef GEN_VXFORM_UIMM
10313#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10314 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10315GEN_VXFORM_UIMM(vspltb, 6, 8),
10316GEN_VXFORM_UIMM(vsplth, 6, 9),
10317GEN_VXFORM_UIMM(vspltw, 6, 10),
10318GEN_VXFORM_UIMM(vcfux, 5, 12),
10319GEN_VXFORM_UIMM(vcfsx, 5, 13),
10320GEN_VXFORM_UIMM(vctuxs, 5, 14),
10321GEN_VXFORM_UIMM(vctsxs, 5, 15),
10322
10323#undef GEN_VAFORM_PAIRED
10324#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10325 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10326GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10327GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10328GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10329GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10330GEN_VAFORM_PAIRED(vsel, vperm, 21),
10331GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10332
fa1832d7 10333GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10334GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10335GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10336GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10337GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10338GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10339GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10340
9231ba9e 10341GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10342GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10343GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10344GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10345GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10346
f5c0f7f9
TM
10347GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10348GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10349GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10350#if defined(TARGET_PPC64)
10351GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10352GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10353#endif
10354
df020ce0
TM
10355#undef GEN_XX2FORM
10356#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10357GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10358GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10359
10360#undef GEN_XX3FORM
10361#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10362GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10363GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10364GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10365GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10366
354a6dec
TM
10367#undef GEN_XX3_RC_FORM
10368#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10369GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10370GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10371GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10372GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10373GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10374GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10375GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10376GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10377
cd73f2c9
TM
10378#undef GEN_XX3FORM_DM
10379#define GEN_XX3FORM_DM(name, opc2, opc3) \
10380GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10381GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10382GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10383GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10384GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10385GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10386GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10387GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10388GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10389GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10390GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10391GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10392GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10393GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10394GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10395GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10396
df020ce0
TM
10397GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10398GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10399GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10400GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10401
be574920
TM
10402GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10403GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10404GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10405GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10406GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10407GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10408GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10409GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 10410
ee6e02c0
TM
10411GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10412GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 10413GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 10414GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 10415GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 10416GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 10417GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 10418GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 10419GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
10420GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10421GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10422GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10423GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10424GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10425GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10426GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10427GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
4f17e9c7
TM
10428GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10429GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
10430GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10431GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568 10432GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
7ee19fb9 10433GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
ed8ac568 10434GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
7ee19fb9 10435GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
5177d2ca
TM
10436GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10437GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10438GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10439GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10440GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10441GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
10442GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10443GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10444GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10445GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10446GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 10447
3fd0aadf
TM
10448GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10449GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 10450GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 10451GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 10452GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
3d1140bf 10453GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
cea4e574 10454GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
968e76bc 10455GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
f53f81e0
TM
10456GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
10457GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
10458GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
10459GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
10460GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
10461GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
10462GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
10463GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
74698350
TM
10464GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
10465GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
3fd0aadf 10466
ee6e02c0
TM
10467GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10468GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 10469GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 10470GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 10471GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 10472GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 10473GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 10474GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 10475GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
10476GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10477GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10478GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10479GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10480GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10481GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10482GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10483GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
10484GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10485GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
10486GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10487GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10488GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 10489GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
10490GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10491GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10492GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10493GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10494GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10495GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10496GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10497GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
10498GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10499GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10500GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10501GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10502GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
10503
10504GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10505GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 10506GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 10507GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 10508GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 10509GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 10510GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 10511GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 10512GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
10513GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10514GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10515GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10516GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10517GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10518GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10519GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10520GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
10521GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10522GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
10523GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10524GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10525GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 10526GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
10527GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10528GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10529GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10530GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10531GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10532GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10533GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10534GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
10535GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10536GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10537GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10538GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10539GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 10540
79ca8a6a
TM
10541#undef VSX_LOGICAL
10542#define VSX_LOGICAL(name, opc2, opc3, fl2) \
10543GEN_XX3FORM(name, opc2, opc3, fl2)
10544
10545VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10546VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10547VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10548VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10549VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
67a33f37
TM
10550VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
10551VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
10552VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
ce577d2e
TM
10553GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10554GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 10555GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 10556GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 10557
551e3ef7
TM
10558#define GEN_XXSEL_ROW(opc3) \
10559GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10560GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10561GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10562GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10563GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10564GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10565GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10566GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10567
10568GEN_XXSEL_ROW(0x00)
10569GEN_XXSEL_ROW(0x01)
10570GEN_XXSEL_ROW(0x02)
10571GEN_XXSEL_ROW(0x03)
10572GEN_XXSEL_ROW(0x04)
10573GEN_XXSEL_ROW(0x05)
10574GEN_XXSEL_ROW(0x06)
10575GEN_XXSEL_ROW(0x07)
10576GEN_XXSEL_ROW(0x08)
10577GEN_XXSEL_ROW(0x09)
10578GEN_XXSEL_ROW(0x0A)
10579GEN_XXSEL_ROW(0x0B)
10580GEN_XXSEL_ROW(0x0C)
10581GEN_XXSEL_ROW(0x0D)
10582GEN_XXSEL_ROW(0x0E)
10583GEN_XXSEL_ROW(0x0F)
10584GEN_XXSEL_ROW(0x10)
10585GEN_XXSEL_ROW(0x11)
10586GEN_XXSEL_ROW(0x12)
10587GEN_XXSEL_ROW(0x13)
10588GEN_XXSEL_ROW(0x14)
10589GEN_XXSEL_ROW(0x15)
10590GEN_XXSEL_ROW(0x16)
10591GEN_XXSEL_ROW(0x17)
10592GEN_XXSEL_ROW(0x18)
10593GEN_XXSEL_ROW(0x19)
10594GEN_XXSEL_ROW(0x1A)
10595GEN_XXSEL_ROW(0x1B)
10596GEN_XXSEL_ROW(0x1C)
10597GEN_XXSEL_ROW(0x1D)
10598GEN_XXSEL_ROW(0x1E)
10599GEN_XXSEL_ROW(0x1F)
10600
cd73f2c9
TM
10601GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
10602
5c55ff99 10603#undef GEN_SPE
70560da7
FC
10604#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
10605 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
10606GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10607GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10608GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10609GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10610GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10611GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10612GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10613GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
10614GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
10615GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
10616GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10617GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10618GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10619GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
10620GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
10621GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
10622GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
10623GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10624GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10625GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10626GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10627GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10628GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
10629GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
10630GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10631GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10632GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
10633GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
10634GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
10635
10636GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10637GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
10638GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
10639GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10640GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10641GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10642GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10643GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10644GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10645GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10646GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10647GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10648GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10649GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10650
10651GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10652GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
10653GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
10654GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10655GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10656GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
10657GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10658GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10659GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10660GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10661GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10662GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10663GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10664GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10665
10666GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
10667GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10668GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
10669GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10670GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
10671GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10672GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
10673GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
10674GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10675GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10676GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10677GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10678GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10679GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10680GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
10681GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
10682
10683#undef GEN_SPEOP_LDST
10684#define GEN_SPEOP_LDST(name, opc2, sh) \
10685GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
10686GEN_SPEOP_LDST(evldd, 0x00, 3),
10687GEN_SPEOP_LDST(evldw, 0x01, 3),
10688GEN_SPEOP_LDST(evldh, 0x02, 3),
10689GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
10690GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
10691GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
10692GEN_SPEOP_LDST(evlwhe, 0x08, 2),
10693GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
10694GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
10695GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
10696GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
10697
10698GEN_SPEOP_LDST(evstdd, 0x10, 3),
10699GEN_SPEOP_LDST(evstdw, 0x11, 3),
10700GEN_SPEOP_LDST(evstdh, 0x12, 3),
10701GEN_SPEOP_LDST(evstwhe, 0x18, 2),
10702GEN_SPEOP_LDST(evstwho, 0x1A, 2),
10703GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
10704GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
10705};
10706
0411a972 10707#include "helper_regs.h"
a1389542 10708#include "translate_init.c"
79aceca5 10709
9a64fbe4 10710/*****************************************************************************/
3fc6c082 10711/* Misc PowerPC helpers */
878096ee
AF
10712void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
10713 int flags)
79aceca5 10714{
3fc6c082
FB
10715#define RGPL 4
10716#define RFPL 4
3fc6c082 10717
878096ee
AF
10718 PowerPCCPU *cpu = POWERPC_CPU(cs);
10719 CPUPPCState *env = &cpu->env;
79aceca5
FB
10720 int i;
10721
90e189ec 10722 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9a78eead 10723 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
da91a00f 10724 env->nip, env->lr, env->ctr, cpu_read_xer(env));
90e189ec
BS
10725 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
10726 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
10727 env->hflags, env->mmu_idx);
d9bce9d9 10728#if !defined(NO_TIMER_DUMP)
9a78eead 10729 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 10730#if !defined(CONFIG_USER_ONLY)
9a78eead 10731 " DECR %08" PRIu32
76a66253
JM
10732#endif
10733 "\n",
077fc206 10734 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
10735#if !defined(CONFIG_USER_ONLY)
10736 , cpu_ppc_load_decr(env)
10737#endif
10738 );
077fc206 10739#endif
76a66253 10740 for (i = 0; i < 32; i++) {
3fc6c082
FB
10741 if ((i & (RGPL - 1)) == 0)
10742 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 10743 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 10744 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 10745 cpu_fprintf(f, "\n");
76a66253 10746 }
3fc6c082 10747 cpu_fprintf(f, "CR ");
76a66253 10748 for (i = 0; i < 8; i++)
7fe48483
FB
10749 cpu_fprintf(f, "%01x", env->crf[i]);
10750 cpu_fprintf(f, " [");
76a66253
JM
10751 for (i = 0; i < 8; i++) {
10752 char a = '-';
10753 if (env->crf[i] & 0x08)
10754 a = 'L';
10755 else if (env->crf[i] & 0x04)
10756 a = 'G';
10757 else if (env->crf[i] & 0x02)
10758 a = 'E';
7fe48483 10759 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 10760 }
90e189ec
BS
10761 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
10762 env->reserve_addr);
3fc6c082
FB
10763 for (i = 0; i < 32; i++) {
10764 if ((i & (RFPL - 1)) == 0)
10765 cpu_fprintf(f, "FPR%02d", i);
26a76461 10766 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 10767 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 10768 cpu_fprintf(f, "\n");
79aceca5 10769 }
30304420 10770 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 10771#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
10772 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
10773 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
10774 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
10775 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
10776
10777 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
10778 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
10779 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
10780 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
10781
10782 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
10783 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
10784 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
10785 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
10786
10787 if (env->excp_model == POWERPC_EXCP_BOOKE) {
10788 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
10789 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
10790 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
10791 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
10792
10793 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
10794 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
10795 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
10796 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
10797
10798 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
10799 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
10800 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
10801 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
10802
10803 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
10804 " EPR " TARGET_FMT_lx "\n",
10805 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
10806 env->spr[SPR_BOOKE_EPR]);
10807
10808 /* FSL-specific */
10809 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
10810 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
10811 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
10812 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
10813
10814 /*
10815 * IVORs are left out as they are large and do not change often --
10816 * they can be read with "p $ivor0", "p $ivor1", etc.
10817 */
10818 }
10819
697ab892
DG
10820#if defined(TARGET_PPC64)
10821 if (env->flags & POWERPC_FLAG_CFAR) {
10822 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
10823 }
10824#endif
10825
90dc8812
SW
10826 switch (env->mmu_model) {
10827 case POWERPC_MMU_32B:
10828 case POWERPC_MMU_601:
10829 case POWERPC_MMU_SOFT_6xx:
10830 case POWERPC_MMU_SOFT_74xx:
10831#if defined(TARGET_PPC64)
90dc8812 10832 case POWERPC_MMU_64B:
ca480de6
AB
10833 case POWERPC_MMU_2_06:
10834 case POWERPC_MMU_2_06a:
10835 case POWERPC_MMU_2_06d:
90dc8812 10836#endif
ca480de6
AB
10837 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
10838 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
10839 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 10840 break;
01662f3e 10841 case POWERPC_MMU_BOOKE206:
90dc8812
SW
10842 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
10843 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
10844 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
10845 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
10846
10847 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
10848 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
10849 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
10850 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
10851
10852 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
10853 " TLB1CFG " TARGET_FMT_lx "\n",
10854 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
10855 env->spr[SPR_BOOKE_TLB1CFG]);
10856 break;
10857 default:
10858 break;
10859 }
f2e63a42 10860#endif
79aceca5 10861
3fc6c082
FB
10862#undef RGPL
10863#undef RFPL
79aceca5
FB
10864}
10865
878096ee
AF
10866void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
10867 fprintf_function cpu_fprintf, int flags)
76a66253
JM
10868{
10869#if defined(DO_PPC_STATISTICS)
878096ee 10870 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 10871 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
10872 int op1, op2, op3;
10873
878096ee 10874 t1 = cpu->env.opcodes;
76a66253
JM
10875 for (op1 = 0; op1 < 64; op1++) {
10876 handler = t1[op1];
10877 if (is_indirect_opcode(handler)) {
10878 t2 = ind_table(handler);
10879 for (op2 = 0; op2 < 32; op2++) {
10880 handler = t2[op2];
10881 if (is_indirect_opcode(handler)) {
10882 t3 = ind_table(handler);
10883 for (op3 = 0; op3 < 32; op3++) {
10884 handler = t3[op3];
10885 if (handler->count == 0)
10886 continue;
10887 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 10888 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
10889 op1, op2, op3, op1, (op3 << 5) | op2,
10890 handler->oname,
10891 handler->count, handler->count);
10892 }
10893 } else {
10894 if (handler->count == 0)
10895 continue;
10896 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 10897 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
10898 op1, op2, op1, op2, handler->oname,
10899 handler->count, handler->count);
10900 }
10901 }
10902 } else {
10903 if (handler->count == 0)
10904 continue;
0bfcd599
BS
10905 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
10906 " %" PRId64 "\n",
76a66253
JM
10907 op1, op1, handler->oname,
10908 handler->count, handler->count);
10909 }
10910 }
10911#endif
10912}
10913
9a64fbe4 10914/*****************************************************************************/
213fe1f5 10915static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
636aa200 10916 TranslationBlock *tb,
213fe1f5 10917 bool search_pc)
79aceca5 10918{
ed2803da 10919 CPUState *cs = CPU(cpu);
213fe1f5 10920 CPUPPCState *env = &cpu->env;
9fddaa0c 10921 DisasContext ctx, *ctxp = &ctx;
c227f099 10922 opc_handler_t **table, *handler;
0fa85d43 10923 target_ulong pc_start;
79aceca5 10924 uint16_t *gen_opc_end;
a1d1bb31 10925 CPUBreakpoint *bp;
79aceca5 10926 int j, lj = -1;
2e70f6ef
PB
10927 int num_insns;
10928 int max_insns;
79aceca5
FB
10929
10930 pc_start = tb->pc;
92414b31 10931 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
046d6672 10932 ctx.nip = pc_start;
79aceca5 10933 ctx.tb = tb;
e1833e1f 10934 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 10935 ctx.spr_cb = env->spr_cb;
76db3ba4 10936 ctx.mem_idx = env->mmu_idx;
7d08d856
AJ
10937 ctx.insns_flags = env->insns_flags;
10938 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
10939 ctx.access_type = -1;
10940 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
d9bce9d9 10941#if defined(TARGET_PPC64)
e42a61f1 10942 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 10943 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 10944#endif
3cc62370 10945 ctx.fpu_enabled = msr_fp;
a9d9eb8f 10946 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
10947 ctx.spe_enabled = msr_spe;
10948 else
10949 ctx.spe_enabled = 0;
a9d9eb8f
JM
10950 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
10951 ctx.altivec_enabled = msr_vr;
10952 else
10953 ctx.altivec_enabled = 0;
1f29871c
TM
10954 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
10955 ctx.vsx_enabled = msr_vsx;
10956 } else {
10957 ctx.vsx_enabled = 0;
10958 }
d26bfc9a 10959 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 10960 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 10961 else
8cbcb4fa 10962 ctx.singlestep_enabled = 0;
d26bfc9a 10963 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 10964 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 10965 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 10966 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 10967 }
3fc6c082 10968#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
10969 /* Single step trace mode */
10970 msr_se = 1;
10971#endif
2e70f6ef
PB
10972 num_insns = 0;
10973 max_insns = tb->cflags & CF_COUNT_MASK;
10974 if (max_insns == 0)
10975 max_insns = CF_COUNT_MASK;
10976
806f352d 10977 gen_tb_start();
9a64fbe4 10978 /* Set env in case of segfault during code fetch */
efd7f486
EV
10979 while (ctx.exception == POWERPC_EXCP_NONE
10980 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
72cf2d4f
BS
10981 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
10982 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
a1d1bb31 10983 if (bp->pc == ctx.nip) {
e06fcd75 10984 gen_debug_exception(ctxp);
ea4e754f
FB
10985 break;
10986 }
10987 }
10988 }
76a66253 10989 if (unlikely(search_pc)) {
92414b31 10990 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
79aceca5
FB
10991 if (lj < j) {
10992 lj++;
10993 while (lj < j)
ab1103de 10994 tcg_ctx.gen_opc_instr_start[lj++] = 0;
79aceca5 10995 }
25983cad 10996 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
ab1103de 10997 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 10998 tcg_ctx.gen_opc_icount[lj] = num_insns;
79aceca5 10999 }
d12d51d5 11000 LOG_DISAS("----------------\n");
90e189ec 11001 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 11002 ctx.nip, ctx.mem_idx, (int)msr_ir);
2e70f6ef
PB
11003 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
11004 gen_io_start();
76db3ba4 11005 if (unlikely(ctx.le_mode)) {
2f5a189c 11006 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 11007 } else {
2f5a189c 11008 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 11009 }
d12d51d5 11010 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 11011 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 11012 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
fdefe51c 11013 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
731c54f8 11014 tcg_gen_debug_insn_start(ctx.nip);
fdefe51c 11015 }
046d6672 11016 ctx.nip += 4;
3fc6c082 11017 table = env->opcodes;
2e70f6ef 11018 num_insns++;
79aceca5
FB
11019 handler = table[opc1(ctx.opcode)];
11020 if (is_indirect_opcode(handler)) {
11021 table = ind_table(handler);
11022 handler = table[opc2(ctx.opcode)];
11023 if (is_indirect_opcode(handler)) {
11024 table = ind_table(handler);
11025 handler = table[opc3(ctx.opcode)];
11026 }
11027 }
11028 /* Is opcode *REALLY* valid ? */
76a66253 11029 if (unlikely(handler->handler == &gen_invalid)) {
93fcfe39
AL
11030 if (qemu_log_enabled()) {
11031 qemu_log("invalid/unsupported opcode: "
90e189ec
BS
11032 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11033 opc1(ctx.opcode), opc2(ctx.opcode),
11034 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
4b3686fa 11035 }
76a66253 11036 } else {
70560da7
FC
11037 uint32_t inval;
11038
11039 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11040 inval = handler->inval2;
11041 } else {
11042 inval = handler->inval1;
11043 }
11044
11045 if (unlikely((ctx.opcode & inval) != 0)) {
93fcfe39
AL
11046 if (qemu_log_enabled()) {
11047 qemu_log("invalid bits: %08x for opcode: "
90e189ec 11048 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
70560da7 11049 ctx.opcode & inval, opc1(ctx.opcode),
90e189ec
BS
11050 opc2(ctx.opcode), opc3(ctx.opcode),
11051 ctx.opcode, ctx.nip - 4);
76a66253 11052 }
e06fcd75 11053 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 11054 break;
79aceca5 11055 }
79aceca5 11056 }
4b3686fa 11057 (*(handler->handler))(&ctx);
76a66253
JM
11058#if defined(DO_PPC_STATISTICS)
11059 handler->count++;
11060#endif
9a64fbe4 11061 /* Check trace mode exceptions */
8cbcb4fa
AJ
11062 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11063 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11064 ctx.exception != POWERPC_SYSCALL &&
11065 ctx.exception != POWERPC_EXCP_TRAP &&
11066 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 11067 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 11068 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 11069 (cs->singlestep_enabled) ||
1b530a6d 11070 singlestep ||
2e70f6ef 11071 num_insns >= max_insns)) {
d26bfc9a
JM
11072 /* if we reach a page boundary or are single stepping, stop
11073 * generation
11074 */
8dd4983c 11075 break;
76a66253 11076 }
3fc6c082 11077 }
2e70f6ef
PB
11078 if (tb->cflags & CF_LAST_IO)
11079 gen_io_end();
e1833e1f 11080 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 11081 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 11082 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 11083 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 11084 gen_debug_exception(ctxp);
8cbcb4fa 11085 }
76a66253 11086 /* Generate the return instruction */
57fec1fe 11087 tcg_gen_exit_tb(0);
9a64fbe4 11088 }
806f352d 11089 gen_tb_end(tb, num_insns);
efd7f486 11090 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
76a66253 11091 if (unlikely(search_pc)) {
92414b31 11092 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9a64fbe4
FB
11093 lj++;
11094 while (lj <= j)
ab1103de 11095 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9a64fbe4 11096 } else {
046d6672 11097 tb->size = ctx.nip - pc_start;
2e70f6ef 11098 tb->icount = num_insns;
9a64fbe4 11099 }
d9bce9d9 11100#if defined(DEBUG_DISAS)
8fec2b8c 11101 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 11102 int flags;
237c0af0 11103 flags = env->bfd_mach;
76db3ba4 11104 flags |= ctx.le_mode << 16;
93fcfe39 11105 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 11106 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
93fcfe39 11107 qemu_log("\n");
9fddaa0c 11108 }
79aceca5 11109#endif
79aceca5
FB
11110}
11111
1328c2bf 11112void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11113{
213fe1f5 11114 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
79aceca5
FB
11115}
11116
1328c2bf 11117void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11118{
213fe1f5 11119 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
79aceca5 11120}
d2856f1a 11121
1328c2bf 11122void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
d2856f1a 11123{
25983cad 11124 env->nip = tcg_ctx.gen_opc_pc[pc_pos];
d2856f1a 11125}