]> Git Repo - qemu.git/blame - target-ppc/translate.c
target-ppc: Add ISA 2.06 ftdiv Instruction
[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
e1571908
AJ
625/*** Integer comparison ***/
626
636aa200 627static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 628{
2fdcb629
RH
629 TCGv t0 = tcg_temp_new();
630 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 631
da91a00f 632 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 633
2fdcb629
RH
634 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
635 tcg_gen_trunc_tl_i32(t1, t0);
636 tcg_gen_shli_i32(t1, t1, CRF_LT);
637 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
638
639 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
640 tcg_gen_trunc_tl_i32(t1, t0);
641 tcg_gen_shli_i32(t1, t1, CRF_GT);
642 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
643
644 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
645 tcg_gen_trunc_tl_i32(t1, t0);
646 tcg_gen_shli_i32(t1, t1, CRF_EQ);
647 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
648
649 tcg_temp_free(t0);
650 tcg_temp_free_i32(t1);
e1571908
AJ
651}
652
636aa200 653static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 654{
2fdcb629 655 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
656 gen_op_cmp(arg0, t0, s, crf);
657 tcg_temp_free(t0);
e1571908
AJ
658}
659
636aa200 660static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 661{
ea363694 662 TCGv t0, t1;
2fdcb629
RH
663 t0 = tcg_temp_new();
664 t1 = tcg_temp_new();
e1571908 665 if (s) {
ea363694
AJ
666 tcg_gen_ext32s_tl(t0, arg0);
667 tcg_gen_ext32s_tl(t1, arg1);
e1571908 668 } else {
ea363694
AJ
669 tcg_gen_ext32u_tl(t0, arg0);
670 tcg_gen_ext32u_tl(t1, arg1);
e1571908 671 }
ea363694
AJ
672 gen_op_cmp(t0, t1, s, crf);
673 tcg_temp_free(t1);
674 tcg_temp_free(t0);
e1571908
AJ
675}
676
636aa200 677static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 678{
2fdcb629 679 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
680 gen_op_cmp32(arg0, t0, s, crf);
681 tcg_temp_free(t0);
e1571908 682}
e1571908 683
636aa200 684static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908 685{
02765534 686 if (NARROW_MODE(ctx)) {
e1571908 687 gen_op_cmpi32(reg, 0, 1, 0);
02765534 688 } else {
e1571908 689 gen_op_cmpi(reg, 0, 1, 0);
02765534 690 }
e1571908
AJ
691}
692
693/* cmp */
99e300ef 694static void gen_cmp(DisasContext *ctx)
e1571908 695{
36f48d9c 696 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
697 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
698 1, crfD(ctx->opcode));
36f48d9c
AG
699 } else {
700 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
701 1, crfD(ctx->opcode));
02765534 702 }
e1571908
AJ
703}
704
705/* cmpi */
99e300ef 706static void gen_cmpi(DisasContext *ctx)
e1571908 707{
36f48d9c 708 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
709 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
710 1, crfD(ctx->opcode));
36f48d9c
AG
711 } else {
712 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
713 1, crfD(ctx->opcode));
02765534 714 }
e1571908
AJ
715}
716
717/* cmpl */
99e300ef 718static void gen_cmpl(DisasContext *ctx)
e1571908 719{
36f48d9c 720 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
721 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
722 0, crfD(ctx->opcode));
36f48d9c
AG
723 } else {
724 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
725 0, crfD(ctx->opcode));
02765534 726 }
e1571908
AJ
727}
728
729/* cmpli */
99e300ef 730static void gen_cmpli(DisasContext *ctx)
e1571908 731{
36f48d9c 732 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
733 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
734 0, crfD(ctx->opcode));
36f48d9c
AG
735 } else {
736 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
737 0, crfD(ctx->opcode));
02765534 738 }
e1571908
AJ
739}
740
741/* isel (PowerPC 2.03 specification) */
99e300ef 742static void gen_isel(DisasContext *ctx)
e1571908
AJ
743{
744 int l1, l2;
745 uint32_t bi = rC(ctx->opcode);
746 uint32_t mask;
a7812ae4 747 TCGv_i32 t0;
e1571908
AJ
748
749 l1 = gen_new_label();
750 l2 = gen_new_label();
751
752 mask = 1 << (3 - (bi & 0x03));
a7812ae4 753 t0 = tcg_temp_new_i32();
fea0c503
AJ
754 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
755 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
e1571908
AJ
756 if (rA(ctx->opcode) == 0)
757 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
758 else
759 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
760 tcg_gen_br(l2);
761 gen_set_label(l1);
762 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
763 gen_set_label(l2);
a7812ae4 764 tcg_temp_free_i32(t0);
e1571908
AJ
765}
766
fcfda20f
AJ
767/* cmpb: PowerPC 2.05 specification */
768static void gen_cmpb(DisasContext *ctx)
769{
770 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
771 cpu_gpr[rB(ctx->opcode)]);
772}
773
79aceca5 774/*** Integer arithmetic ***/
79aceca5 775
636aa200
BS
776static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
777 TCGv arg1, TCGv arg2, int sub)
74637406 778{
ffe30937 779 TCGv t0 = tcg_temp_new();
79aceca5 780
8e7a6db9 781 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
74637406 782 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
783 if (sub) {
784 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
785 } else {
786 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
787 }
788 tcg_temp_free(t0);
02765534 789 if (NARROW_MODE(ctx)) {
ffe30937
RH
790 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
791 }
ffe30937
RH
792 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
793 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
794}
795
74637406 796/* Common add function */
636aa200 797static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
798 TCGv arg2, bool add_ca, bool compute_ca,
799 bool compute_ov, bool compute_rc0)
74637406 800{
b5a73f8d 801 TCGv t0 = ret;
d9bce9d9 802
752d634e 803 if (compute_ca || compute_ov) {
146de60d 804 t0 = tcg_temp_new();
74637406 805 }
79aceca5 806
da91a00f 807 if (compute_ca) {
79482e5a 808 if (NARROW_MODE(ctx)) {
752d634e
RH
809 /* Caution: a non-obvious corner case of the spec is that we
810 must produce the *entire* 64-bit addition, but produce the
811 carry into bit 32. */
79482e5a 812 TCGv t1 = tcg_temp_new();
752d634e
RH
813 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
814 tcg_gen_add_tl(t0, arg1, arg2);
79482e5a
RH
815 if (add_ca) {
816 tcg_gen_add_tl(t0, t0, cpu_ca);
817 }
752d634e
RH
818 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
819 tcg_temp_free(t1);
820 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
821 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
b5a73f8d 822 } else {
79482e5a
RH
823 TCGv zero = tcg_const_tl(0);
824 if (add_ca) {
825 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
826 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
827 } else {
828 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
829 }
830 tcg_temp_free(zero);
b5a73f8d 831 }
b5a73f8d
RH
832 } else {
833 tcg_gen_add_tl(t0, arg1, arg2);
834 if (add_ca) {
835 tcg_gen_add_tl(t0, t0, cpu_ca);
836 }
da91a00f 837 }
79aceca5 838
74637406
AJ
839 if (compute_ov) {
840 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
841 }
b5a73f8d 842 if (unlikely(compute_rc0)) {
74637406 843 gen_set_Rc0(ctx, t0);
b5a73f8d 844 }
74637406 845
a7812ae4 846 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
847 tcg_gen_mov_tl(ret, t0);
848 tcg_temp_free(t0);
849 }
39dd32ee 850}
74637406
AJ
851/* Add functions with two operands */
852#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 853static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
854{ \
855 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
856 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 857 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
858}
859/* Add functions with one operand and one immediate */
860#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
861 add_ca, compute_ca, compute_ov) \
b5a73f8d 862static void glue(gen_, name)(DisasContext *ctx) \
74637406 863{ \
b5a73f8d 864 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
865 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
866 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 867 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
868 tcg_temp_free(t0); \
869}
870
871/* add add. addo addo. */
872GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
873GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
874/* addc addc. addco addco. */
875GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
876GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
877/* adde adde. addeo addeo. */
878GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
879GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
880/* addme addme. addmeo addmeo. */
881GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
882GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
883/* addze addze. addzeo addzeo.*/
884GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
885GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
886/* addi */
99e300ef 887static void gen_addi(DisasContext *ctx)
d9bce9d9 888{
74637406
AJ
889 target_long simm = SIMM(ctx->opcode);
890
891 if (rA(ctx->opcode) == 0) {
892 /* li case */
893 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
894 } else {
b5a73f8d
RH
895 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
896 cpu_gpr[rA(ctx->opcode)], simm);
74637406 897 }
d9bce9d9 898}
74637406 899/* addic addic.*/
b5a73f8d 900static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 901{
b5a73f8d
RH
902 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
903 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
904 c, 0, 1, 0, compute_rc0);
905 tcg_temp_free(c);
d9bce9d9 906}
99e300ef
BS
907
908static void gen_addic(DisasContext *ctx)
d9bce9d9 909{
b5a73f8d 910 gen_op_addic(ctx, 0);
d9bce9d9 911}
e8eaa2c0
BS
912
913static void gen_addic_(DisasContext *ctx)
d9bce9d9 914{
b5a73f8d 915 gen_op_addic(ctx, 1);
d9bce9d9 916}
99e300ef 917
54623277 918/* addis */
99e300ef 919static void gen_addis(DisasContext *ctx)
d9bce9d9 920{
74637406
AJ
921 target_long simm = SIMM(ctx->opcode);
922
923 if (rA(ctx->opcode) == 0) {
924 /* lis case */
925 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
926 } else {
b5a73f8d
RH
927 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
928 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 929 }
d9bce9d9 930}
74637406 931
636aa200
BS
932static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
933 TCGv arg2, int sign, int compute_ov)
d9bce9d9 934{
2ef1b120
AJ
935 int l1 = gen_new_label();
936 int l2 = gen_new_label();
a7812ae4
PB
937 TCGv_i32 t0 = tcg_temp_local_new_i32();
938 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 939
2ef1b120
AJ
940 tcg_gen_trunc_tl_i32(t0, arg1);
941 tcg_gen_trunc_tl_i32(t1, arg2);
942 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 943 if (sign) {
2ef1b120
AJ
944 int l3 = gen_new_label();
945 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
946 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 947 gen_set_label(l3);
2ef1b120 948 tcg_gen_div_i32(t0, t0, t1);
74637406 949 } else {
2ef1b120 950 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
951 }
952 if (compute_ov) {
da91a00f 953 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
954 }
955 tcg_gen_br(l2);
956 gen_set_label(l1);
957 if (sign) {
2ef1b120 958 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
959 } else {
960 tcg_gen_movi_i32(t0, 0);
961 }
962 if (compute_ov) {
da91a00f
RH
963 tcg_gen_movi_tl(cpu_ov, 1);
964 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
965 }
966 gen_set_label(l2);
2ef1b120 967 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
968 tcg_temp_free_i32(t0);
969 tcg_temp_free_i32(t1);
74637406
AJ
970 if (unlikely(Rc(ctx->opcode) != 0))
971 gen_set_Rc0(ctx, ret);
d9bce9d9 972}
74637406
AJ
973/* Div functions */
974#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 975static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
976{ \
977 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
978 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
979 sign, compute_ov); \
980}
981/* divwu divwu. divwuo divwuo. */
982GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
983GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
984/* divw divw. divwo divwo. */
985GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
986GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
98d1eb27
TM
987
988/* div[wd]eu[o][.] */
989#define GEN_DIVE(name, hlpr, compute_ov) \
990static void gen_##name(DisasContext *ctx) \
991{ \
992 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
993 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
994 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
995 tcg_temp_free_i32(t0); \
996 if (unlikely(Rc(ctx->opcode) != 0)) { \
997 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
998 } \
999}
1000
6a4fda33
TM
1001GEN_DIVE(divweu, divweu, 0);
1002GEN_DIVE(divweuo, divweu, 1);
a98eb9e9
TM
1003GEN_DIVE(divwe, divwe, 0);
1004GEN_DIVE(divweo, divwe, 1);
6a4fda33 1005
d9bce9d9 1006#if defined(TARGET_PPC64)
636aa200
BS
1007static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1008 TCGv arg2, int sign, int compute_ov)
d9bce9d9 1009{
2ef1b120
AJ
1010 int l1 = gen_new_label();
1011 int l2 = gen_new_label();
74637406
AJ
1012
1013 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1014 if (sign) {
2ef1b120 1015 int l3 = gen_new_label();
74637406
AJ
1016 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1017 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1018 gen_set_label(l3);
74637406
AJ
1019 tcg_gen_div_i64(ret, arg1, arg2);
1020 } else {
1021 tcg_gen_divu_i64(ret, arg1, arg2);
1022 }
1023 if (compute_ov) {
da91a00f 1024 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
1025 }
1026 tcg_gen_br(l2);
1027 gen_set_label(l1);
1028 if (sign) {
1029 tcg_gen_sari_i64(ret, arg1, 63);
1030 } else {
1031 tcg_gen_movi_i64(ret, 0);
1032 }
1033 if (compute_ov) {
da91a00f
RH
1034 tcg_gen_movi_tl(cpu_ov, 1);
1035 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1036 }
1037 gen_set_label(l2);
1038 if (unlikely(Rc(ctx->opcode) != 0))
1039 gen_set_Rc0(ctx, ret);
d9bce9d9 1040}
74637406 1041#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 1042static void glue(gen_, name)(DisasContext *ctx) \
74637406 1043{ \
2ef1b120
AJ
1044 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1045 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1046 sign, compute_ov); \
74637406
AJ
1047}
1048/* divwu divwu. divwuo divwuo. */
1049GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1050GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1051/* divw divw. divwo divwo. */
1052GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1053GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
98d1eb27
TM
1054
1055GEN_DIVE(divdeu, divdeu, 0);
1056GEN_DIVE(divdeuo, divdeu, 1);
e44259b6
TM
1057GEN_DIVE(divde, divde, 0);
1058GEN_DIVE(divdeo, divde, 1);
d9bce9d9 1059#endif
74637406
AJ
1060
1061/* mulhw mulhw. */
99e300ef 1062static void gen_mulhw(DisasContext *ctx)
d9bce9d9 1063{
23ad1d5d
RH
1064 TCGv_i32 t0 = tcg_temp_new_i32();
1065 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1066
23ad1d5d
RH
1067 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1068 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1069 tcg_gen_muls2_i32(t0, t1, t0, t1);
1070 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1071 tcg_temp_free_i32(t0);
1072 tcg_temp_free_i32(t1);
74637406
AJ
1073 if (unlikely(Rc(ctx->opcode) != 0))
1074 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1075}
99e300ef 1076
54623277 1077/* mulhwu mulhwu. */
99e300ef 1078static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1079{
23ad1d5d
RH
1080 TCGv_i32 t0 = tcg_temp_new_i32();
1081 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1082
23ad1d5d
RH
1083 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1084 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1085 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1086 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1087 tcg_temp_free_i32(t0);
1088 tcg_temp_free_i32(t1);
74637406
AJ
1089 if (unlikely(Rc(ctx->opcode) != 0))
1090 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1091}
99e300ef 1092
54623277 1093/* mullw mullw. */
99e300ef 1094static void gen_mullw(DisasContext *ctx)
d9bce9d9 1095{
74637406
AJ
1096 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1097 cpu_gpr[rB(ctx->opcode)]);
1e4c090f 1098 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
74637406
AJ
1099 if (unlikely(Rc(ctx->opcode) != 0))
1100 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1101}
99e300ef 1102
54623277 1103/* mullwo mullwo. */
99e300ef 1104static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1105{
e4a2c846
RH
1106 TCGv_i32 t0 = tcg_temp_new_i32();
1107 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1108
e4a2c846
RH
1109 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1110 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1111 tcg_gen_muls2_i32(t0, t1, t0, t1);
1112 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1113
1114 tcg_gen_sari_i32(t0, t0, 31);
1115 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1116 tcg_gen_extu_i32_tl(cpu_ov, t0);
1117 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1118
1119 tcg_temp_free_i32(t0);
1120 tcg_temp_free_i32(t1);
74637406
AJ
1121 if (unlikely(Rc(ctx->opcode) != 0))
1122 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1123}
99e300ef 1124
54623277 1125/* mulli */
99e300ef 1126static void gen_mulli(DisasContext *ctx)
d9bce9d9 1127{
74637406
AJ
1128 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1129 SIMM(ctx->opcode));
d9bce9d9 1130}
23ad1d5d 1131
d9bce9d9 1132#if defined(TARGET_PPC64)
74637406 1133/* mulhd mulhd. */
23ad1d5d
RH
1134static void gen_mulhd(DisasContext *ctx)
1135{
1136 TCGv lo = tcg_temp_new();
1137 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1138 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1139 tcg_temp_free(lo);
1140 if (unlikely(Rc(ctx->opcode) != 0)) {
1141 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1142 }
1143}
1144
74637406 1145/* mulhdu mulhdu. */
23ad1d5d
RH
1146static void gen_mulhdu(DisasContext *ctx)
1147{
1148 TCGv lo = tcg_temp_new();
1149 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1150 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1151 tcg_temp_free(lo);
1152 if (unlikely(Rc(ctx->opcode) != 0)) {
1153 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1154 }
1155}
99e300ef 1156
54623277 1157/* mulld mulld. */
99e300ef 1158static void gen_mulld(DisasContext *ctx)
d9bce9d9 1159{
74637406
AJ
1160 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1161 cpu_gpr[rB(ctx->opcode)]);
1162 if (unlikely(Rc(ctx->opcode) != 0))
1163 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1164}
d15f74fb 1165
74637406 1166/* mulldo mulldo. */
d15f74fb
BS
1167static void gen_mulldo(DisasContext *ctx)
1168{
1169 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1170 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1171 if (unlikely(Rc(ctx->opcode) != 0)) {
1172 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1173 }
1174}
d9bce9d9 1175#endif
74637406 1176
74637406 1177/* Common subf function */
636aa200 1178static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1179 TCGv arg2, bool add_ca, bool compute_ca,
1180 bool compute_ov, bool compute_rc0)
79aceca5 1181{
b5a73f8d 1182 TCGv t0 = ret;
79aceca5 1183
752d634e 1184 if (compute_ca || compute_ov) {
b5a73f8d 1185 t0 = tcg_temp_new();
da91a00f 1186 }
74637406 1187
79482e5a
RH
1188 if (compute_ca) {
1189 /* dest = ~arg1 + arg2 [+ ca]. */
1190 if (NARROW_MODE(ctx)) {
752d634e
RH
1191 /* Caution: a non-obvious corner case of the spec is that we
1192 must produce the *entire* 64-bit addition, but produce the
1193 carry into bit 32. */
79482e5a 1194 TCGv inv1 = tcg_temp_new();
752d634e 1195 TCGv t1 = tcg_temp_new();
79482e5a 1196 tcg_gen_not_tl(inv1, arg1);
79482e5a 1197 if (add_ca) {
752d634e 1198 tcg_gen_add_tl(t0, arg2, cpu_ca);
79482e5a 1199 } else {
752d634e 1200 tcg_gen_addi_tl(t0, arg2, 1);
79482e5a 1201 }
752d634e 1202 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
79482e5a 1203 tcg_gen_add_tl(t0, t0, inv1);
752d634e
RH
1204 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1205 tcg_temp_free(t1);
1206 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1207 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
79482e5a 1208 } else if (add_ca) {
08f4a0f7
RH
1209 TCGv zero, inv1 = tcg_temp_new();
1210 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1211 zero = tcg_const_tl(0);
1212 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1213 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1214 tcg_temp_free(zero);
08f4a0f7 1215 tcg_temp_free(inv1);
b5a73f8d 1216 } else {
79482e5a 1217 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
b5a73f8d 1218 tcg_gen_sub_tl(t0, arg2, arg1);
b5a73f8d 1219 }
79482e5a
RH
1220 } else if (add_ca) {
1221 /* Since we're ignoring carry-out, we can simplify the
1222 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1223 tcg_gen_sub_tl(t0, arg2, arg1);
1224 tcg_gen_add_tl(t0, t0, cpu_ca);
1225 tcg_gen_subi_tl(t0, t0, 1);
79aceca5 1226 } else {
b5a73f8d 1227 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1228 }
b5a73f8d 1229
74637406
AJ
1230 if (compute_ov) {
1231 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1232 }
b5a73f8d 1233 if (unlikely(compute_rc0)) {
74637406 1234 gen_set_Rc0(ctx, t0);
b5a73f8d 1235 }
74637406 1236
a7812ae4 1237 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1238 tcg_gen_mov_tl(ret, t0);
1239 tcg_temp_free(t0);
79aceca5 1240 }
79aceca5 1241}
74637406
AJ
1242/* Sub functions with Two operands functions */
1243#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1244static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1245{ \
1246 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1247 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1248 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1249}
1250/* Sub functions with one operand and one immediate */
1251#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1252 add_ca, compute_ca, compute_ov) \
b5a73f8d 1253static void glue(gen_, name)(DisasContext *ctx) \
74637406 1254{ \
b5a73f8d 1255 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1256 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1257 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1258 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1259 tcg_temp_free(t0); \
1260}
1261/* subf subf. subfo subfo. */
1262GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1263GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1264/* subfc subfc. subfco subfco. */
1265GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1266GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1267/* subfe subfe. subfeo subfo. */
1268GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1269GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1270/* subfme subfme. subfmeo subfmeo. */
1271GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1272GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1273/* subfze subfze. subfzeo subfzeo.*/
1274GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1275GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1276
54623277 1277/* subfic */
99e300ef 1278static void gen_subfic(DisasContext *ctx)
79aceca5 1279{
b5a73f8d
RH
1280 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1281 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1282 c, 0, 1, 0, 0);
1283 tcg_temp_free(c);
79aceca5
FB
1284}
1285
fd3f0081
RH
1286/* neg neg. nego nego. */
1287static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1288{
1289 TCGv zero = tcg_const_tl(0);
1290 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1291 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1292 tcg_temp_free(zero);
1293}
1294
1295static void gen_neg(DisasContext *ctx)
1296{
1297 gen_op_arith_neg(ctx, 0);
1298}
1299
1300static void gen_nego(DisasContext *ctx)
1301{
1302 gen_op_arith_neg(ctx, 1);
1303}
1304
79aceca5 1305/*** Integer logical ***/
26d67362 1306#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1307static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1308{ \
26d67362
AJ
1309 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1310 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1311 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1312 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1313}
79aceca5 1314
26d67362 1315#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1316static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1317{ \
26d67362 1318 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1319 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1320 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1321}
1322
1323/* and & and. */
26d67362 1324GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1325/* andc & andc. */
26d67362 1326GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1327
54623277 1328/* andi. */
e8eaa2c0 1329static void gen_andi_(DisasContext *ctx)
79aceca5 1330{
26d67362
AJ
1331 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1332 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1333}
e8eaa2c0 1334
54623277 1335/* andis. */
e8eaa2c0 1336static void gen_andis_(DisasContext *ctx)
79aceca5 1337{
26d67362
AJ
1338 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1339 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1340}
99e300ef 1341
54623277 1342/* cntlzw */
99e300ef 1343static void gen_cntlzw(DisasContext *ctx)
26d67362 1344{
a7812ae4 1345 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1346 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1347 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1348}
79aceca5 1349/* eqv & eqv. */
26d67362 1350GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1351/* extsb & extsb. */
26d67362 1352GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1353/* extsh & extsh. */
26d67362 1354GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1355/* nand & nand. */
26d67362 1356GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1357/* nor & nor. */
26d67362 1358GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1359
54623277 1360/* or & or. */
99e300ef 1361static void gen_or(DisasContext *ctx)
9a64fbe4 1362{
76a66253
JM
1363 int rs, ra, rb;
1364
1365 rs = rS(ctx->opcode);
1366 ra = rA(ctx->opcode);
1367 rb = rB(ctx->opcode);
1368 /* Optimisation for mr. ri case */
1369 if (rs != ra || rs != rb) {
26d67362
AJ
1370 if (rs != rb)
1371 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1372 else
1373 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1374 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1375 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1376 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1377 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1378#if defined(TARGET_PPC64)
1379 } else {
26d67362
AJ
1380 int prio = 0;
1381
c80f84e3
JM
1382 switch (rs) {
1383 case 1:
1384 /* Set process priority to low */
26d67362 1385 prio = 2;
c80f84e3
JM
1386 break;
1387 case 6:
1388 /* Set process priority to medium-low */
26d67362 1389 prio = 3;
c80f84e3
JM
1390 break;
1391 case 2:
1392 /* Set process priority to normal */
26d67362 1393 prio = 4;
c80f84e3 1394 break;
be147d08
JM
1395#if !defined(CONFIG_USER_ONLY)
1396 case 31:
76db3ba4 1397 if (ctx->mem_idx > 0) {
be147d08 1398 /* Set process priority to very low */
26d67362 1399 prio = 1;
be147d08
JM
1400 }
1401 break;
1402 case 5:
76db3ba4 1403 if (ctx->mem_idx > 0) {
be147d08 1404 /* Set process priority to medium-hight */
26d67362 1405 prio = 5;
be147d08
JM
1406 }
1407 break;
1408 case 3:
76db3ba4 1409 if (ctx->mem_idx > 0) {
be147d08 1410 /* Set process priority to high */
26d67362 1411 prio = 6;
be147d08
JM
1412 }
1413 break;
be147d08 1414 case 7:
76db3ba4 1415 if (ctx->mem_idx > 1) {
be147d08 1416 /* Set process priority to very high */
26d67362 1417 prio = 7;
be147d08
JM
1418 }
1419 break;
be147d08 1420#endif
c80f84e3
JM
1421 default:
1422 /* nop */
1423 break;
1424 }
26d67362 1425 if (prio) {
a7812ae4 1426 TCGv t0 = tcg_temp_new();
54cdcae6 1427 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1428 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1429 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1430 gen_store_spr(SPR_PPR, t0);
ea363694 1431 tcg_temp_free(t0);
26d67362 1432 }
c80f84e3 1433#endif
9a64fbe4 1434 }
9a64fbe4 1435}
79aceca5 1436/* orc & orc. */
26d67362 1437GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1438
54623277 1439/* xor & xor. */
99e300ef 1440static void gen_xor(DisasContext *ctx)
9a64fbe4 1441{
9a64fbe4 1442 /* Optimisation for "set to zero" case */
26d67362 1443 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1444 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1445 else
1446 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1447 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1448 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1449}
99e300ef 1450
54623277 1451/* ori */
99e300ef 1452static void gen_ori(DisasContext *ctx)
79aceca5 1453{
76a66253 1454 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1455
9a64fbe4
FB
1456 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1457 /* NOP */
76a66253 1458 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1459 return;
76a66253 1460 }
26d67362 1461 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1462}
99e300ef 1463
54623277 1464/* oris */
99e300ef 1465static void gen_oris(DisasContext *ctx)
79aceca5 1466{
76a66253 1467 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1468
9a64fbe4
FB
1469 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1470 /* NOP */
1471 return;
76a66253 1472 }
26d67362 1473 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1474}
99e300ef 1475
54623277 1476/* xori */
99e300ef 1477static void gen_xori(DisasContext *ctx)
79aceca5 1478{
76a66253 1479 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1480
1481 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1482 /* NOP */
1483 return;
1484 }
26d67362 1485 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1486}
99e300ef 1487
54623277 1488/* xoris */
99e300ef 1489static void gen_xoris(DisasContext *ctx)
79aceca5 1490{
76a66253 1491 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1492
1493 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1494 /* NOP */
1495 return;
1496 }
26d67362 1497 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1498}
99e300ef 1499
54623277 1500/* popcntb : PowerPC 2.03 specification */
99e300ef 1501static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1502{
eaabeef2
DG
1503 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1504}
1505
1506static void gen_popcntw(DisasContext *ctx)
1507{
1508 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1509}
1510
d9bce9d9 1511#if defined(TARGET_PPC64)
eaabeef2
DG
1512/* popcntd: PowerPC 2.06 specification */
1513static void gen_popcntd(DisasContext *ctx)
1514{
1515 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1516}
eaabeef2 1517#endif
d9bce9d9 1518
725bcec2
AJ
1519/* prtyw: PowerPC 2.05 specification */
1520static void gen_prtyw(DisasContext *ctx)
1521{
1522 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1523 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1524 TCGv t0 = tcg_temp_new();
1525 tcg_gen_shri_tl(t0, rs, 16);
1526 tcg_gen_xor_tl(ra, rs, t0);
1527 tcg_gen_shri_tl(t0, ra, 8);
1528 tcg_gen_xor_tl(ra, ra, t0);
1529 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1530 tcg_temp_free(t0);
1531}
1532
1533#if defined(TARGET_PPC64)
1534/* prtyd: PowerPC 2.05 specification */
1535static void gen_prtyd(DisasContext *ctx)
1536{
1537 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1538 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1539 TCGv t0 = tcg_temp_new();
1540 tcg_gen_shri_tl(t0, rs, 32);
1541 tcg_gen_xor_tl(ra, rs, t0);
1542 tcg_gen_shri_tl(t0, ra, 16);
1543 tcg_gen_xor_tl(ra, ra, t0);
1544 tcg_gen_shri_tl(t0, ra, 8);
1545 tcg_gen_xor_tl(ra, ra, t0);
1546 tcg_gen_andi_tl(ra, ra, 1);
1547 tcg_temp_free(t0);
1548}
1549#endif
1550
86ba37ed
TM
1551#if defined(TARGET_PPC64)
1552/* bpermd */
1553static void gen_bpermd(DisasContext *ctx)
1554{
1555 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1556 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1557}
1558#endif
1559
d9bce9d9
JM
1560#if defined(TARGET_PPC64)
1561/* extsw & extsw. */
26d67362 1562GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1563
54623277 1564/* cntlzd */
99e300ef 1565static void gen_cntlzd(DisasContext *ctx)
26d67362 1566{
a7812ae4 1567 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1568 if (unlikely(Rc(ctx->opcode) != 0))
1569 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1570}
d9bce9d9
JM
1571#endif
1572
79aceca5 1573/*** Integer rotate ***/
99e300ef 1574
54623277 1575/* rlwimi & rlwimi. */
99e300ef 1576static void gen_rlwimi(DisasContext *ctx)
79aceca5 1577{
76a66253 1578 uint32_t mb, me, sh;
79aceca5
FB
1579
1580 mb = MB(ctx->opcode);
1581 me = ME(ctx->opcode);
76a66253 1582 sh = SH(ctx->opcode);
d03ef511
AJ
1583 if (likely(sh == 0 && mb == 0 && me == 31)) {
1584 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1585 } else {
d03ef511 1586 target_ulong mask;
a7812ae4
PB
1587 TCGv t1;
1588 TCGv t0 = tcg_temp_new();
54843a58 1589#if defined(TARGET_PPC64)
a7812ae4
PB
1590 TCGv_i32 t2 = tcg_temp_new_i32();
1591 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1592 tcg_gen_rotli_i32(t2, t2, sh);
1593 tcg_gen_extu_i32_i64(t0, t2);
1594 tcg_temp_free_i32(t2);
54843a58
AJ
1595#else
1596 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1597#endif
76a66253 1598#if defined(TARGET_PPC64)
d03ef511
AJ
1599 mb += 32;
1600 me += 32;
76a66253 1601#endif
d03ef511 1602 mask = MASK(mb, me);
a7812ae4 1603 t1 = tcg_temp_new();
d03ef511
AJ
1604 tcg_gen_andi_tl(t0, t0, mask);
1605 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1606 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1607 tcg_temp_free(t0);
1608 tcg_temp_free(t1);
1609 }
76a66253 1610 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1611 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1612}
99e300ef 1613
54623277 1614/* rlwinm & rlwinm. */
99e300ef 1615static void gen_rlwinm(DisasContext *ctx)
79aceca5
FB
1616{
1617 uint32_t mb, me, sh;
3b46e624 1618
79aceca5
FB
1619 sh = SH(ctx->opcode);
1620 mb = MB(ctx->opcode);
1621 me = ME(ctx->opcode);
d03ef511
AJ
1622
1623 if (likely(mb == 0 && me == (31 - sh))) {
1624 if (likely(sh == 0)) {
1625 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1626 } else {
a7812ae4 1627 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1628 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1629 tcg_gen_shli_tl(t0, t0, sh);
1630 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1631 tcg_temp_free(t0);
79aceca5 1632 }
d03ef511 1633 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
a7812ae4 1634 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1635 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1636 tcg_gen_shri_tl(t0, t0, mb);
1637 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1638 tcg_temp_free(t0);
1639 } else {
a7812ae4 1640 TCGv t0 = tcg_temp_new();
54843a58 1641#if defined(TARGET_PPC64)
a7812ae4 1642 TCGv_i32 t1 = tcg_temp_new_i32();
54843a58
AJ
1643 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1644 tcg_gen_rotli_i32(t1, t1, sh);
1645 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4 1646 tcg_temp_free_i32(t1);
54843a58
AJ
1647#else
1648 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1649#endif
76a66253 1650#if defined(TARGET_PPC64)
d03ef511
AJ
1651 mb += 32;
1652 me += 32;
76a66253 1653#endif
d03ef511
AJ
1654 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1655 tcg_temp_free(t0);
1656 }
76a66253 1657 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1658 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1659}
99e300ef 1660
54623277 1661/* rlwnm & rlwnm. */
99e300ef 1662static void gen_rlwnm(DisasContext *ctx)
79aceca5
FB
1663{
1664 uint32_t mb, me;
54843a58
AJ
1665 TCGv t0;
1666#if defined(TARGET_PPC64)
a7812ae4 1667 TCGv_i32 t1, t2;
54843a58 1668#endif
79aceca5
FB
1669
1670 mb = MB(ctx->opcode);
1671 me = ME(ctx->opcode);
a7812ae4 1672 t0 = tcg_temp_new();
d03ef511 1673 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
54843a58 1674#if defined(TARGET_PPC64)
a7812ae4
PB
1675 t1 = tcg_temp_new_i32();
1676 t2 = tcg_temp_new_i32();
54843a58
AJ
1677 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1678 tcg_gen_trunc_i64_i32(t2, t0);
1679 tcg_gen_rotl_i32(t1, t1, t2);
1680 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4
PB
1681 tcg_temp_free_i32(t1);
1682 tcg_temp_free_i32(t2);
54843a58
AJ
1683#else
1684 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1685#endif
76a66253
JM
1686 if (unlikely(mb != 0 || me != 31)) {
1687#if defined(TARGET_PPC64)
1688 mb += 32;
1689 me += 32;
1690#endif
54843a58 1691 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
d03ef511 1692 } else {
54843a58 1693 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
79aceca5 1694 }
54843a58 1695 tcg_temp_free(t0);
76a66253 1696 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1697 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5
FB
1698}
1699
d9bce9d9
JM
1700#if defined(TARGET_PPC64)
1701#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1702static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1703{ \
1704 gen_##name(ctx, 0); \
1705} \
e8eaa2c0
BS
1706 \
1707static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1708{ \
1709 gen_##name(ctx, 1); \
1710}
1711#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1712static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1713{ \
1714 gen_##name(ctx, 0, 0); \
1715} \
e8eaa2c0
BS
1716 \
1717static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1718{ \
1719 gen_##name(ctx, 0, 1); \
1720} \
e8eaa2c0
BS
1721 \
1722static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1723{ \
1724 gen_##name(ctx, 1, 0); \
1725} \
e8eaa2c0
BS
1726 \
1727static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1728{ \
1729 gen_##name(ctx, 1, 1); \
1730}
51789c41 1731
636aa200
BS
1732static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1733 uint32_t sh)
51789c41 1734{
d03ef511
AJ
1735 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1736 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1737 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1738 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1739 } else {
a7812ae4 1740 TCGv t0 = tcg_temp_new();
54843a58 1741 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
d03ef511 1742 if (likely(mb == 0 && me == 63)) {
54843a58 1743 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
d03ef511
AJ
1744 } else {
1745 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
51789c41 1746 }
d03ef511 1747 tcg_temp_free(t0);
51789c41 1748 }
51789c41 1749 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1750 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
51789c41 1751}
d9bce9d9 1752/* rldicl - rldicl. */
636aa200 1753static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1754{
51789c41 1755 uint32_t sh, mb;
d9bce9d9 1756
9d53c753
JM
1757 sh = SH(ctx->opcode) | (shn << 5);
1758 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1759 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1760}
51789c41 1761GEN_PPC64_R4(rldicl, 0x1E, 0x00);
d9bce9d9 1762/* rldicr - rldicr. */
636aa200 1763static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1764{
51789c41 1765 uint32_t sh, me;
d9bce9d9 1766
9d53c753
JM
1767 sh = SH(ctx->opcode) | (shn << 5);
1768 me = MB(ctx->opcode) | (men << 5);
51789c41 1769 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1770}
51789c41 1771GEN_PPC64_R4(rldicr, 0x1E, 0x02);
d9bce9d9 1772/* rldic - rldic. */
636aa200 1773static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1774{
51789c41 1775 uint32_t sh, mb;
d9bce9d9 1776
9d53c753
JM
1777 sh = SH(ctx->opcode) | (shn << 5);
1778 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1779 gen_rldinm(ctx, mb, 63 - sh, sh);
1780}
1781GEN_PPC64_R4(rldic, 0x1E, 0x04);
1782
636aa200 1783static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
51789c41 1784{
54843a58 1785 TCGv t0;
d03ef511 1786
a7812ae4 1787 t0 = tcg_temp_new();
d03ef511 1788 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
54843a58 1789 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
51789c41 1790 if (unlikely(mb != 0 || me != 63)) {
54843a58
AJ
1791 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1792 } else {
1793 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1794 }
1795 tcg_temp_free(t0);
51789c41 1796 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1797 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1798}
51789c41 1799
d9bce9d9 1800/* rldcl - rldcl. */
636aa200 1801static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1802{
51789c41 1803 uint32_t mb;
d9bce9d9 1804
9d53c753 1805 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1806 gen_rldnm(ctx, mb, 63);
d9bce9d9 1807}
36081602 1808GEN_PPC64_R2(rldcl, 0x1E, 0x08);
d9bce9d9 1809/* rldcr - rldcr. */
636aa200 1810static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1811{
51789c41 1812 uint32_t me;
d9bce9d9 1813
9d53c753 1814 me = MB(ctx->opcode) | (men << 5);
51789c41 1815 gen_rldnm(ctx, 0, me);
d9bce9d9 1816}
36081602 1817GEN_PPC64_R2(rldcr, 0x1E, 0x09);
d9bce9d9 1818/* rldimi - rldimi. */
636aa200 1819static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1820{
271a916e 1821 uint32_t sh, mb, me;
d9bce9d9 1822
9d53c753
JM
1823 sh = SH(ctx->opcode) | (shn << 5);
1824 mb = MB(ctx->opcode) | (mbn << 5);
271a916e 1825 me = 63 - sh;
d03ef511
AJ
1826 if (unlikely(sh == 0 && mb == 0)) {
1827 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1828 } else {
1829 TCGv t0, t1;
1830 target_ulong mask;
1831
a7812ae4 1832 t0 = tcg_temp_new();
54843a58 1833 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
a7812ae4 1834 t1 = tcg_temp_new();
d03ef511
AJ
1835 mask = MASK(mb, me);
1836 tcg_gen_andi_tl(t0, t0, mask);
1837 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1838 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1839 tcg_temp_free(t0);
1840 tcg_temp_free(t1);
51789c41 1841 }
51789c41 1842 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1843 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1844}
36081602 1845GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1846#endif
1847
79aceca5 1848/*** Integer shift ***/
99e300ef 1849
54623277 1850/* slw & slw. */
99e300ef 1851static void gen_slw(DisasContext *ctx)
26d67362 1852{
7fd6bf7d 1853 TCGv t0, t1;
26d67362 1854
7fd6bf7d
AJ
1855 t0 = tcg_temp_new();
1856 /* AND rS with a mask that is 0 when rB >= 0x20 */
1857#if defined(TARGET_PPC64)
1858 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1859 tcg_gen_sari_tl(t0, t0, 0x3f);
1860#else
1861 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1862 tcg_gen_sari_tl(t0, t0, 0x1f);
1863#endif
1864 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1865 t1 = tcg_temp_new();
1866 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1867 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1868 tcg_temp_free(t1);
fea0c503 1869 tcg_temp_free(t0);
7fd6bf7d 1870 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1871 if (unlikely(Rc(ctx->opcode) != 0))
1872 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1873}
99e300ef 1874
54623277 1875/* sraw & sraw. */
99e300ef 1876static void gen_sraw(DisasContext *ctx)
26d67362 1877{
d15f74fb 1878 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1879 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1880 if (unlikely(Rc(ctx->opcode) != 0))
1881 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1882}
99e300ef 1883
54623277 1884/* srawi & srawi. */
99e300ef 1885static void gen_srawi(DisasContext *ctx)
79aceca5 1886{
26d67362 1887 int sh = SH(ctx->opcode);
ba4af3e4
RH
1888 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1889 TCGv src = cpu_gpr[rS(ctx->opcode)];
1890 if (sh == 0) {
1891 tcg_gen_mov_tl(dst, src);
da91a00f 1892 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1893 } else {
ba4af3e4
RH
1894 TCGv t0;
1895 tcg_gen_ext32s_tl(dst, src);
1896 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1897 t0 = tcg_temp_new();
1898 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1899 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1900 tcg_temp_free(t0);
1901 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1902 tcg_gen_sari_tl(dst, dst, sh);
1903 }
1904 if (unlikely(Rc(ctx->opcode) != 0)) {
1905 gen_set_Rc0(ctx, dst);
d9bce9d9 1906 }
79aceca5 1907}
99e300ef 1908
54623277 1909/* srw & srw. */
99e300ef 1910static void gen_srw(DisasContext *ctx)
26d67362 1911{
fea0c503 1912 TCGv t0, t1;
d9bce9d9 1913
7fd6bf7d
AJ
1914 t0 = tcg_temp_new();
1915 /* AND rS with a mask that is 0 when rB >= 0x20 */
1916#if defined(TARGET_PPC64)
1917 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1918 tcg_gen_sari_tl(t0, t0, 0x3f);
1919#else
1920 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1921 tcg_gen_sari_tl(t0, t0, 0x1f);
1922#endif
1923 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1924 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1925 t1 = tcg_temp_new();
7fd6bf7d
AJ
1926 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1927 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1928 tcg_temp_free(t1);
fea0c503 1929 tcg_temp_free(t0);
26d67362
AJ
1930 if (unlikely(Rc(ctx->opcode) != 0))
1931 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1932}
54623277 1933
d9bce9d9
JM
1934#if defined(TARGET_PPC64)
1935/* sld & sld. */
99e300ef 1936static void gen_sld(DisasContext *ctx)
26d67362 1937{
7fd6bf7d 1938 TCGv t0, t1;
26d67362 1939
7fd6bf7d
AJ
1940 t0 = tcg_temp_new();
1941 /* AND rS with a mask that is 0 when rB >= 0x40 */
1942 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1943 tcg_gen_sari_tl(t0, t0, 0x3f);
1944 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1945 t1 = tcg_temp_new();
1946 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1947 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1948 tcg_temp_free(t1);
fea0c503 1949 tcg_temp_free(t0);
26d67362
AJ
1950 if (unlikely(Rc(ctx->opcode) != 0))
1951 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1952}
99e300ef 1953
54623277 1954/* srad & srad. */
99e300ef 1955static void gen_srad(DisasContext *ctx)
26d67362 1956{
d15f74fb 1957 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1958 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1959 if (unlikely(Rc(ctx->opcode) != 0))
1960 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1961}
d9bce9d9 1962/* sradi & sradi. */
636aa200 1963static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1964{
26d67362 1965 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
1966 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1967 TCGv src = cpu_gpr[rS(ctx->opcode)];
1968 if (sh == 0) {
1969 tcg_gen_mov_tl(dst, src);
da91a00f 1970 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1971 } else {
ba4af3e4
RH
1972 TCGv t0;
1973 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1974 t0 = tcg_temp_new();
1975 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1976 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1977 tcg_temp_free(t0);
1978 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1979 tcg_gen_sari_tl(dst, src, sh);
1980 }
1981 if (unlikely(Rc(ctx->opcode) != 0)) {
1982 gen_set_Rc0(ctx, dst);
d9bce9d9 1983 }
d9bce9d9 1984}
e8eaa2c0
BS
1985
1986static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
1987{
1988 gen_sradi(ctx, 0);
1989}
e8eaa2c0
BS
1990
1991static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
1992{
1993 gen_sradi(ctx, 1);
1994}
99e300ef 1995
54623277 1996/* srd & srd. */
99e300ef 1997static void gen_srd(DisasContext *ctx)
26d67362 1998{
7fd6bf7d 1999 TCGv t0, t1;
26d67362 2000
7fd6bf7d
AJ
2001 t0 = tcg_temp_new();
2002 /* AND rS with a mask that is 0 when rB >= 0x40 */
2003 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2004 tcg_gen_sari_tl(t0, t0, 0x3f);
2005 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2006 t1 = tcg_temp_new();
2007 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2008 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2009 tcg_temp_free(t1);
fea0c503 2010 tcg_temp_free(t0);
26d67362
AJ
2011 if (unlikely(Rc(ctx->opcode) != 0))
2012 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2013}
d9bce9d9 2014#endif
79aceca5
FB
2015
2016/*** Floating-Point arithmetic ***/
7c58044c 2017#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 2018static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2019{ \
76a66253 2020 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2021 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2022 return; \
2023 } \
eb44b959
AJ
2024 /* NIP cannot be restored if the memory exception comes from an helper */ \
2025 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2026 gen_reset_fpstatus(); \
8e703949
BS
2027 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2028 cpu_fpr[rA(ctx->opcode)], \
af12906f 2029 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2030 if (isfloat) { \
8e703949
BS
2031 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2032 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2033 } \
af12906f
AJ
2034 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2035 Rc(ctx->opcode) != 0); \
9a64fbe4
FB
2036}
2037
7c58044c
JM
2038#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2039_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2040_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2041
7c58044c 2042#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2043static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2044{ \
76a66253 2045 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2046 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2047 return; \
2048 } \
eb44b959
AJ
2049 /* NIP cannot be restored if the memory exception comes from an helper */ \
2050 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2051 gen_reset_fpstatus(); \
8e703949
BS
2052 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2053 cpu_fpr[rA(ctx->opcode)], \
af12906f 2054 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2055 if (isfloat) { \
8e703949
BS
2056 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2057 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2058 } \
af12906f
AJ
2059 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2060 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2061}
7c58044c
JM
2062#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2063_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2064_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2065
7c58044c 2066#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2067static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2068{ \
76a66253 2069 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2070 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2071 return; \
2072 } \
eb44b959
AJ
2073 /* NIP cannot be restored if the memory exception comes from an helper */ \
2074 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2075 gen_reset_fpstatus(); \
8e703949
BS
2076 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2077 cpu_fpr[rA(ctx->opcode)], \
2078 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2079 if (isfloat) { \
8e703949
BS
2080 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2081 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2082 } \
af12906f
AJ
2083 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2084 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2085}
7c58044c
JM
2086#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2087_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2088_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2089
7c58044c 2090#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2091static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2092{ \
76a66253 2093 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2094 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2095 return; \
2096 } \
eb44b959
AJ
2097 /* NIP cannot be restored if the memory exception comes from an helper */ \
2098 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2099 gen_reset_fpstatus(); \
8e703949
BS
2100 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2101 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2102 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2103 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2104}
2105
7c58044c 2106#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2107static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2108{ \
76a66253 2109 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2110 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2111 return; \
2112 } \
eb44b959
AJ
2113 /* NIP cannot be restored if the memory exception comes from an helper */ \
2114 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2115 gen_reset_fpstatus(); \
8e703949
BS
2116 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2117 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2118 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2119 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2120}
2121
9a64fbe4 2122/* fadd - fadds */
7c58044c 2123GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2124/* fdiv - fdivs */
7c58044c 2125GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2126/* fmul - fmuls */
7c58044c 2127GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2128
d7e4b87e 2129/* fre */
7c58044c 2130GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2131
a750fc0b 2132/* fres */
7c58044c 2133GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2134
a750fc0b 2135/* frsqrte */
7c58044c
JM
2136GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2137
2138/* frsqrtes */
99e300ef 2139static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2140{
af12906f 2141 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2142 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2143 return;
2144 }
eb44b959
AJ
2145 /* NIP cannot be restored if the memory exception comes from an helper */
2146 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2147 gen_reset_fpstatus();
8e703949
BS
2148 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2149 cpu_fpr[rB(ctx->opcode)]);
2150 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2151 cpu_fpr[rD(ctx->opcode)]);
af12906f 2152 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
7c58044c 2153}
79aceca5 2154
a750fc0b 2155/* fsel */
7c58044c 2156_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2157/* fsub - fsubs */
7c58044c 2158GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2159/* Optional: */
99e300ef 2160
54623277 2161/* fsqrt */
99e300ef 2162static void gen_fsqrt(DisasContext *ctx)
c7d344af 2163{
76a66253 2164 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2165 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2166 return;
2167 }
eb44b959
AJ
2168 /* NIP cannot be restored if the memory exception comes from an helper */
2169 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2170 gen_reset_fpstatus();
8e703949
BS
2171 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2172 cpu_fpr[rB(ctx->opcode)]);
af12906f 2173 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
c7d344af 2174}
79aceca5 2175
99e300ef 2176static void gen_fsqrts(DisasContext *ctx)
79aceca5 2177{
76a66253 2178 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2179 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
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)]);
2187 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2188 cpu_fpr[rD(ctx->opcode)]);
af12906f 2189 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
79aceca5
FB
2190}
2191
2192/*** Floating-Point multiply-and-add ***/
4ecc3190 2193/* fmadd - fmadds */
7c58044c 2194GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2195/* fmsub - fmsubs */
7c58044c 2196GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2197/* fnmadd - fnmadds */
7c58044c 2198GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2199/* fnmsub - fnmsubs */
7c58044c 2200GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2201
2202/*** Floating-Point round & convert ***/
2203/* fctiw */
7c58044c 2204GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2205/* fctiwu */
2206GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2207/* fctiwz */
7c58044c 2208GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2209/* fctiwuz */
2210GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2211/* frsp */
7c58044c 2212GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db
JM
2213#if defined(TARGET_PPC64)
2214/* fcfid */
7c58044c 2215GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
28288b48
TM
2216/* fcfids */
2217GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2218/* fcfidu */
2219GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2220/* fcfidus */
2221GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
426613db 2222/* fctid */
7c58044c 2223GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
fab7fe42
TM
2224/* fctidu */
2225GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2226/* fctidz */
7c58044c 2227GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
fab7fe42
TM
2228/* fctidu */
2229GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2230#endif
79aceca5 2231
d7e4b87e 2232/* frin */
7c58044c 2233GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2234/* friz */
7c58044c 2235GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2236/* frip */
7c58044c 2237GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2238/* frim */
7c58044c 2239GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2240
da29cb7b
TM
2241static void gen_ftdiv(DisasContext *ctx)
2242{
2243 if (unlikely(!ctx->fpu_enabled)) {
2244 gen_exception(ctx, POWERPC_EXCP_FPU);
2245 return;
2246 }
2247 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2248 cpu_fpr[rB(ctx->opcode)]);
2249}
2250
2251
2252
79aceca5 2253/*** Floating-Point compare ***/
99e300ef 2254
54623277 2255/* fcmpo */
99e300ef 2256static void gen_fcmpo(DisasContext *ctx)
79aceca5 2257{
330c483b 2258 TCGv_i32 crf;
76a66253 2259 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2260 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2261 return;
2262 }
eb44b959
AJ
2263 /* NIP cannot be restored if the memory exception comes from an helper */
2264 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2265 gen_reset_fpstatus();
9a819377 2266 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2267 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2268 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2269 tcg_temp_free_i32(crf);
8e703949 2270 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2271}
2272
2273/* fcmpu */
99e300ef 2274static void gen_fcmpu(DisasContext *ctx)
79aceca5 2275{
330c483b 2276 TCGv_i32 crf;
76a66253 2277 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2278 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2279 return;
2280 }
eb44b959
AJ
2281 /* NIP cannot be restored if the memory exception comes from an helper */
2282 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2283 gen_reset_fpstatus();
9a819377 2284 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2285 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2286 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2287 tcg_temp_free_i32(crf);
8e703949 2288 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2289}
2290
9a64fbe4
FB
2291/*** Floating-point move ***/
2292/* fabs */
7c58044c 2293/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2294static void gen_fabs(DisasContext *ctx)
2295{
2296 if (unlikely(!ctx->fpu_enabled)) {
2297 gen_exception(ctx, POWERPC_EXCP_FPU);
2298 return;
2299 }
2300 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2301 ~(1ULL << 63));
2302 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2303}
9a64fbe4
FB
2304
2305/* fmr - fmr. */
7c58044c 2306/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2307static void gen_fmr(DisasContext *ctx)
9a64fbe4 2308{
76a66253 2309 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2310 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2311 return;
2312 }
af12906f
AJ
2313 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2314 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
9a64fbe4
FB
2315}
2316
2317/* fnabs */
7c58044c 2318/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2319static void gen_fnabs(DisasContext *ctx)
2320{
2321 if (unlikely(!ctx->fpu_enabled)) {
2322 gen_exception(ctx, POWERPC_EXCP_FPU);
2323 return;
2324 }
2325 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2326 1ULL << 63);
2327 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2328}
2329
9a64fbe4 2330/* fneg */
7c58044c 2331/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2332static void gen_fneg(DisasContext *ctx)
2333{
2334 if (unlikely(!ctx->fpu_enabled)) {
2335 gen_exception(ctx, POWERPC_EXCP_FPU);
2336 return;
2337 }
2338 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2339 1ULL << 63);
2340 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2341}
9a64fbe4 2342
f0332888
AJ
2343/* fcpsgn: PowerPC 2.05 specification */
2344/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2345static void gen_fcpsgn(DisasContext *ctx)
2346{
2347 if (unlikely(!ctx->fpu_enabled)) {
2348 gen_exception(ctx, POWERPC_EXCP_FPU);
2349 return;
2350 }
2351 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2352 cpu_fpr[rB(ctx->opcode)], 0, 63);
2353 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2354}
2355
097ec5d8
TM
2356static void gen_fmrgew(DisasContext *ctx)
2357{
2358 TCGv_i64 b0;
2359 if (unlikely(!ctx->fpu_enabled)) {
2360 gen_exception(ctx, POWERPC_EXCP_FPU);
2361 return;
2362 }
2363 b0 = tcg_temp_new_i64();
2364 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2365 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2366 b0, 0, 32);
2367 tcg_temp_free_i64(b0);
2368}
2369
2370static void gen_fmrgow(DisasContext *ctx)
2371{
2372 if (unlikely(!ctx->fpu_enabled)) {
2373 gen_exception(ctx, POWERPC_EXCP_FPU);
2374 return;
2375 }
2376 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2377 cpu_fpr[rB(ctx->opcode)],
2378 cpu_fpr[rA(ctx->opcode)],
2379 32, 32);
2380}
2381
79aceca5 2382/*** Floating-Point status & ctrl register ***/
99e300ef 2383
54623277 2384/* mcrfs */
99e300ef 2385static void gen_mcrfs(DisasContext *ctx)
79aceca5 2386{
30304420 2387 TCGv tmp = tcg_temp_new();
7c58044c
JM
2388 int bfa;
2389
76a66253 2390 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2391 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2392 return;
2393 }
7c58044c 2394 bfa = 4 * (7 - crfS(ctx->opcode));
30304420
DG
2395 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2396 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2397 tcg_temp_free(tmp);
e1571908 2398 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
30304420 2399 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
79aceca5
FB
2400}
2401
2402/* mffs */
99e300ef 2403static void gen_mffs(DisasContext *ctx)
79aceca5 2404{
76a66253 2405 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2406 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2407 return;
2408 }
7c58044c 2409 gen_reset_fpstatus();
30304420 2410 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
af12906f 2411 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
79aceca5
FB
2412}
2413
2414/* mtfsb0 */
99e300ef 2415static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2416{
fb0eaffc 2417 uint8_t crb;
3b46e624 2418
76a66253 2419 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2420 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2421 return;
2422 }
6e35d524 2423 crb = 31 - crbD(ctx->opcode);
7c58044c 2424 gen_reset_fpstatus();
6e35d524 2425 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2426 TCGv_i32 t0;
2427 /* NIP cannot be restored if the memory exception comes from an helper */
2428 gen_update_nip(ctx, ctx->nip - 4);
2429 t0 = tcg_const_i32(crb);
8e703949 2430 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2431 tcg_temp_free_i32(t0);
2432 }
7c58044c 2433 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2434 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2435 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2436 }
79aceca5
FB
2437}
2438
2439/* mtfsb1 */
99e300ef 2440static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2441{
fb0eaffc 2442 uint8_t crb;
3b46e624 2443
76a66253 2444 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2445 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2446 return;
2447 }
6e35d524 2448 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2449 gen_reset_fpstatus();
2450 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2451 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2452 TCGv_i32 t0;
2453 /* NIP cannot be restored if the memory exception comes from an helper */
2454 gen_update_nip(ctx, ctx->nip - 4);
2455 t0 = tcg_const_i32(crb);
8e703949 2456 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2457 tcg_temp_free_i32(t0);
af12906f 2458 }
7c58044c 2459 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2460 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2461 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2462 }
2463 /* We can raise a differed exception */
8e703949 2464 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2465}
2466
2467/* mtfsf */
99e300ef 2468static void gen_mtfsf(DisasContext *ctx)
79aceca5 2469{
0f2f39c2 2470 TCGv_i32 t0;
7d08d856 2471 int flm, l, w;
af12906f 2472
76a66253 2473 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2474 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2475 return;
2476 }
7d08d856
AJ
2477 flm = FPFLM(ctx->opcode);
2478 l = FPL(ctx->opcode);
2479 w = FPW(ctx->opcode);
2480 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2481 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2482 return;
2483 }
eb44b959
AJ
2484 /* NIP cannot be restored if the memory exception comes from an helper */
2485 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2486 gen_reset_fpstatus();
7d08d856
AJ
2487 if (l) {
2488 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2489 } else {
2490 t0 = tcg_const_i32(flm << (w * 8));
2491 }
8e703949 2492 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2493 tcg_temp_free_i32(t0);
7c58044c 2494 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2495 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2496 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2497 }
2498 /* We can raise a differed exception */
8e703949 2499 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2500}
2501
2502/* mtfsfi */
99e300ef 2503static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2504{
7d08d856 2505 int bf, sh, w;
0f2f39c2
AJ
2506 TCGv_i64 t0;
2507 TCGv_i32 t1;
7c58044c 2508
76a66253 2509 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2510 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2511 return;
2512 }
7d08d856
AJ
2513 w = FPW(ctx->opcode);
2514 bf = FPBF(ctx->opcode);
2515 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2516 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2517 return;
2518 }
2519 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2520 /* NIP cannot be restored if the memory exception comes from an helper */
2521 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2522 gen_reset_fpstatus();
7d08d856 2523 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2524 t1 = tcg_const_i32(1 << sh);
8e703949 2525 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2526 tcg_temp_free_i64(t0);
2527 tcg_temp_free_i32(t1);
7c58044c 2528 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2529 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2530 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2531 }
2532 /* We can raise a differed exception */
8e703949 2533 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2534}
2535
76a66253
JM
2536/*** Addressing modes ***/
2537/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2538static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2539 target_long maskl)
76a66253
JM
2540{
2541 target_long simm = SIMM(ctx->opcode);
2542
be147d08 2543 simm &= ~maskl;
76db3ba4 2544 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2545 if (NARROW_MODE(ctx)) {
2546 simm = (uint32_t)simm;
2547 }
e2be8d8d 2548 tcg_gen_movi_tl(EA, simm);
76db3ba4 2549 } else if (likely(simm != 0)) {
e2be8d8d 2550 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2551 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2552 tcg_gen_ext32u_tl(EA, EA);
2553 }
76db3ba4 2554 } else {
c791fe84 2555 if (NARROW_MODE(ctx)) {
76db3ba4 2556 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2557 } else {
2558 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2559 }
76db3ba4 2560 }
76a66253
JM
2561}
2562
636aa200 2563static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2564{
76db3ba4 2565 if (rA(ctx->opcode) == 0) {
c791fe84 2566 if (NARROW_MODE(ctx)) {
76db3ba4 2567 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2568 } else {
2569 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2570 }
76db3ba4 2571 } else {
e2be8d8d 2572 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2573 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2574 tcg_gen_ext32u_tl(EA, EA);
2575 }
76db3ba4 2576 }
76a66253
JM
2577}
2578
636aa200 2579static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2580{
76db3ba4 2581 if (rA(ctx->opcode) == 0) {
e2be8d8d 2582 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2583 } else if (NARROW_MODE(ctx)) {
2584 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2585 } else {
c791fe84 2586 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2587 }
2588}
2589
636aa200
BS
2590static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2591 target_long val)
76db3ba4
AJ
2592{
2593 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2594 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2595 tcg_gen_ext32u_tl(ret, ret);
2596 }
76a66253
JM
2597}
2598
636aa200 2599static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32
AJ
2600{
2601 int l1 = gen_new_label();
2602 TCGv t0 = tcg_temp_new();
2603 TCGv_i32 t1, t2;
2604 /* NIP cannot be restored if the memory exception comes from an helper */
2605 gen_update_nip(ctx, ctx->nip - 4);
2606 tcg_gen_andi_tl(t0, EA, mask);
2607 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2608 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2609 t2 = tcg_const_i32(0);
e5f17ac6 2610 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2611 tcg_temp_free_i32(t1);
2612 tcg_temp_free_i32(t2);
2613 gen_set_label(l1);
2614 tcg_temp_free(t0);
2615}
2616
7863667f 2617/*** Integer load ***/
636aa200 2618static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2619{
2620 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2621}
2622
636aa200 2623static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2624{
2625 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2626}
2627
636aa200 2628static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2629{
2630 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2631 if (unlikely(ctx->le_mode)) {
fa3966a3 2632 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2633 }
b61f2753
AJ
2634}
2635
636aa200 2636static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2637{
76db3ba4 2638 if (unlikely(ctx->le_mode)) {
76db3ba4 2639 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
fa3966a3 2640 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2641 tcg_gen_ext16s_tl(arg1, arg1);
76db3ba4
AJ
2642 } else {
2643 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2644 }
b61f2753
AJ
2645}
2646
636aa200 2647static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2648{
76db3ba4
AJ
2649 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2650 if (unlikely(ctx->le_mode)) {
fa3966a3 2651 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2652 }
b61f2753
AJ
2653}
2654
f976b09e
AG
2655static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2656{
2657 TCGv tmp = tcg_temp_new();
2658 gen_qemu_ld32u(ctx, tmp, addr);
2659 tcg_gen_extu_tl_i64(val, tmp);
2660 tcg_temp_free(tmp);
2661}
2662
636aa200 2663static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2664{
a457e7ee 2665 if (unlikely(ctx->le_mode)) {
76db3ba4 2666 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
fa3966a3
AJ
2667 tcg_gen_bswap32_tl(arg1, arg1);
2668 tcg_gen_ext32s_tl(arg1, arg1);
b61f2753 2669 } else
76db3ba4 2670 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2671}
2672
cac7f0ba
TM
2673static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2674{
2675 TCGv tmp = tcg_temp_new();
2676 gen_qemu_ld32s(ctx, tmp, addr);
2677 tcg_gen_ext_tl_i64(val, tmp);
2678 tcg_temp_free(tmp);
2679}
2680
636aa200 2681static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2682{
76db3ba4
AJ
2683 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2684 if (unlikely(ctx->le_mode)) {
66896cb8 2685 tcg_gen_bswap64_i64(arg1, arg1);
76db3ba4 2686 }
b61f2753
AJ
2687}
2688
636aa200 2689static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2690{
76db3ba4 2691 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2692}
2693
636aa200 2694static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2695{
76db3ba4 2696 if (unlikely(ctx->le_mode)) {
76db3ba4
AJ
2697 TCGv t0 = tcg_temp_new();
2698 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2699 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2700 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2701 tcg_temp_free(t0);
76db3ba4
AJ
2702 } else {
2703 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2704 }
b61f2753
AJ
2705}
2706
636aa200 2707static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2708{
76db3ba4 2709 if (unlikely(ctx->le_mode)) {
fa3966a3
AJ
2710 TCGv t0 = tcg_temp_new();
2711 tcg_gen_ext32u_tl(t0, arg1);
2712 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2713 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2714 tcg_temp_free(t0);
76db3ba4
AJ
2715 } else {
2716 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2717 }
b61f2753
AJ
2718}
2719
f976b09e
AG
2720static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2721{
2722 TCGv tmp = tcg_temp_new();
2723 tcg_gen_trunc_i64_tl(tmp, val);
2724 gen_qemu_st32(ctx, tmp, addr);
2725 tcg_temp_free(tmp);
2726}
2727
636aa200 2728static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2729{
76db3ba4 2730 if (unlikely(ctx->le_mode)) {
a7812ae4 2731 TCGv_i64 t0 = tcg_temp_new_i64();
66896cb8 2732 tcg_gen_bswap64_i64(t0, arg1);
76db3ba4 2733 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
a7812ae4 2734 tcg_temp_free_i64(t0);
b61f2753 2735 } else
76db3ba4 2736 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2737}
2738
0c8aacd4 2739#define GEN_LD(name, ldop, opc, type) \
99e300ef 2740static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2741{ \
76db3ba4
AJ
2742 TCGv EA; \
2743 gen_set_access_type(ctx, ACCESS_INT); \
2744 EA = tcg_temp_new(); \
2745 gen_addr_imm_index(ctx, EA, 0); \
2746 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2747 tcg_temp_free(EA); \
79aceca5
FB
2748}
2749
0c8aacd4 2750#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2751static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2752{ \
b61f2753 2753 TCGv EA; \
76a66253
JM
2754 if (unlikely(rA(ctx->opcode) == 0 || \
2755 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2756 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2757 return; \
9a64fbe4 2758 } \
76db3ba4 2759 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2760 EA = tcg_temp_new(); \
9d53c753 2761 if (type == PPC_64B) \
76db3ba4 2762 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2763 else \
76db3ba4
AJ
2764 gen_addr_imm_index(ctx, EA, 0); \
2765 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2766 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2767 tcg_temp_free(EA); \
79aceca5
FB
2768}
2769
0c8aacd4 2770#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2771static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2772{ \
b61f2753 2773 TCGv EA; \
76a66253
JM
2774 if (unlikely(rA(ctx->opcode) == 0 || \
2775 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2776 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2777 return; \
9a64fbe4 2778 } \
76db3ba4 2779 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2780 EA = tcg_temp_new(); \
76db3ba4
AJ
2781 gen_addr_reg_index(ctx, EA); \
2782 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2783 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2784 tcg_temp_free(EA); \
79aceca5
FB
2785}
2786
cd6e9320 2787#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2788static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2789{ \
76db3ba4
AJ
2790 TCGv EA; \
2791 gen_set_access_type(ctx, ACCESS_INT); \
2792 EA = tcg_temp_new(); \
2793 gen_addr_reg_index(ctx, EA); \
2794 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2795 tcg_temp_free(EA); \
79aceca5 2796}
cd6e9320
TH
2797#define GEN_LDX(name, ldop, opc2, opc3, type) \
2798 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2799
0c8aacd4
AJ
2800#define GEN_LDS(name, ldop, op, type) \
2801GEN_LD(name, ldop, op | 0x20, type); \
2802GEN_LDU(name, ldop, op | 0x21, type); \
2803GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2804GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2805
2806/* lbz lbzu lbzux lbzx */
0c8aacd4 2807GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2808/* lha lhau lhaux lhax */
0c8aacd4 2809GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2810/* lhz lhzu lhzux lhzx */
0c8aacd4 2811GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2812/* lwz lwzu lwzux lwzx */
0c8aacd4 2813GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2814#if defined(TARGET_PPC64)
d9bce9d9 2815/* lwaux */
0c8aacd4 2816GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2817/* lwax */
0c8aacd4 2818GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2819/* ldux */
0c8aacd4 2820GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2821/* ldx */
0c8aacd4 2822GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2823
2824static void gen_ld(DisasContext *ctx)
d9bce9d9 2825{
b61f2753 2826 TCGv EA;
d9bce9d9
JM
2827 if (Rc(ctx->opcode)) {
2828 if (unlikely(rA(ctx->opcode) == 0 ||
2829 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2830 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2831 return;
2832 }
2833 }
76db3ba4 2834 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2835 EA = tcg_temp_new();
76db3ba4 2836 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2837 if (ctx->opcode & 0x02) {
2838 /* lwa (lwau is undefined) */
76db3ba4 2839 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2840 } else {
2841 /* ld - ldu */
76db3ba4 2842 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2843 }
d9bce9d9 2844 if (Rc(ctx->opcode))
b61f2753
AJ
2845 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2846 tcg_temp_free(EA);
d9bce9d9 2847}
99e300ef 2848
54623277 2849/* lq */
99e300ef 2850static void gen_lq(DisasContext *ctx)
be147d08
JM
2851{
2852#if defined(CONFIG_USER_ONLY)
e06fcd75 2853 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2854#else
2855 int ra, rd;
b61f2753 2856 TCGv EA;
be147d08
JM
2857
2858 /* Restore CPU state */
76db3ba4 2859 if (unlikely(ctx->mem_idx == 0)) {
e06fcd75 2860 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2861 return;
2862 }
2863 ra = rA(ctx->opcode);
2864 rd = rD(ctx->opcode);
2865 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2866 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2867 return;
2868 }
76db3ba4 2869 if (unlikely(ctx->le_mode)) {
be147d08 2870 /* Little-endian mode is not handled */
e06fcd75 2871 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
be147d08
JM
2872 return;
2873 }
76db3ba4 2874 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2875 EA = tcg_temp_new();
76db3ba4
AJ
2876 gen_addr_imm_index(ctx, EA, 0x0F);
2877 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2878 gen_addr_add(ctx, EA, EA, 8);
2879 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
b61f2753 2880 tcg_temp_free(EA);
be147d08
JM
2881#endif
2882}
d9bce9d9 2883#endif
79aceca5
FB
2884
2885/*** Integer store ***/
0c8aacd4 2886#define GEN_ST(name, stop, opc, type) \
99e300ef 2887static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2888{ \
76db3ba4
AJ
2889 TCGv EA; \
2890 gen_set_access_type(ctx, ACCESS_INT); \
2891 EA = tcg_temp_new(); \
2892 gen_addr_imm_index(ctx, EA, 0); \
2893 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2894 tcg_temp_free(EA); \
79aceca5
FB
2895}
2896
0c8aacd4 2897#define GEN_STU(name, stop, opc, type) \
99e300ef 2898static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2899{ \
b61f2753 2900 TCGv EA; \
76a66253 2901 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2902 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2903 return; \
9a64fbe4 2904 } \
76db3ba4 2905 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2906 EA = tcg_temp_new(); \
9d53c753 2907 if (type == PPC_64B) \
76db3ba4 2908 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2909 else \
76db3ba4
AJ
2910 gen_addr_imm_index(ctx, EA, 0); \
2911 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2912 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2913 tcg_temp_free(EA); \
79aceca5
FB
2914}
2915
0c8aacd4 2916#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2917static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2918{ \
b61f2753 2919 TCGv EA; \
76a66253 2920 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2921 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2922 return; \
9a64fbe4 2923 } \
76db3ba4 2924 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2925 EA = tcg_temp_new(); \
76db3ba4
AJ
2926 gen_addr_reg_index(ctx, EA); \
2927 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2928 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2929 tcg_temp_free(EA); \
79aceca5
FB
2930}
2931
cd6e9320
TH
2932#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2933static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2934{ \
76db3ba4
AJ
2935 TCGv EA; \
2936 gen_set_access_type(ctx, ACCESS_INT); \
2937 EA = tcg_temp_new(); \
2938 gen_addr_reg_index(ctx, EA); \
2939 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2940 tcg_temp_free(EA); \
79aceca5 2941}
cd6e9320
TH
2942#define GEN_STX(name, stop, opc2, opc3, type) \
2943 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 2944
0c8aacd4
AJ
2945#define GEN_STS(name, stop, op, type) \
2946GEN_ST(name, stop, op | 0x20, type); \
2947GEN_STU(name, stop, op | 0x21, type); \
2948GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2949GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
2950
2951/* stb stbu stbux stbx */
0c8aacd4 2952GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 2953/* sth sthu sthux sthx */
0c8aacd4 2954GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 2955/* stw stwu stwux stwx */
0c8aacd4 2956GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 2957#if defined(TARGET_PPC64)
0c8aacd4
AJ
2958GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2959GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
2960
2961static void gen_std(DisasContext *ctx)
d9bce9d9 2962{
be147d08 2963 int rs;
b61f2753 2964 TCGv EA;
be147d08
JM
2965
2966 rs = rS(ctx->opcode);
2967 if ((ctx->opcode & 0x3) == 0x2) {
2968#if defined(CONFIG_USER_ONLY)
e06fcd75 2969 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2970#else
2971 /* stq */
76db3ba4 2972 if (unlikely(ctx->mem_idx == 0)) {
e06fcd75 2973 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2974 return;
2975 }
2976 if (unlikely(rs & 1)) {
e06fcd75 2977 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2978 return;
2979 }
76db3ba4 2980 if (unlikely(ctx->le_mode)) {
be147d08 2981 /* Little-endian mode is not handled */
e06fcd75 2982 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
be147d08
JM
2983 return;
2984 }
76db3ba4 2985 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2986 EA = tcg_temp_new();
76db3ba4
AJ
2987 gen_addr_imm_index(ctx, EA, 0x03);
2988 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
2989 gen_addr_add(ctx, EA, EA, 8);
2990 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
b61f2753 2991 tcg_temp_free(EA);
be147d08
JM
2992#endif
2993 } else {
2994 /* std / stdu */
2995 if (Rc(ctx->opcode)) {
2996 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 2997 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2998 return;
2999 }
3000 }
76db3ba4 3001 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3002 EA = tcg_temp_new();
76db3ba4
AJ
3003 gen_addr_imm_index(ctx, EA, 0x03);
3004 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 3005 if (Rc(ctx->opcode))
b61f2753
AJ
3006 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3007 tcg_temp_free(EA);
d9bce9d9 3008 }
d9bce9d9
JM
3009}
3010#endif
79aceca5
FB
3011/*** Integer load and store with byte reverse ***/
3012/* lhbrx */
86178a57 3013static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3014{
76db3ba4
AJ
3015 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
3016 if (likely(!ctx->le_mode)) {
fa3966a3 3017 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 3018 }
b61f2753 3019}
0c8aacd4 3020GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 3021
79aceca5 3022/* lwbrx */
86178a57 3023static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3024{
76db3ba4
AJ
3025 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
3026 if (likely(!ctx->le_mode)) {
fa3966a3 3027 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 3028 }
b61f2753 3029}
0c8aacd4 3030GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 3031
cd6e9320
TH
3032#if defined(TARGET_PPC64)
3033/* ldbrx */
3034static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3035{
3036 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
3037 if (likely(!ctx->le_mode)) {
3038 tcg_gen_bswap64_tl(arg1, arg1);
3039 }
3040}
3041GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3042#endif /* TARGET_PPC64 */
3043
79aceca5 3044/* sthbrx */
86178a57 3045static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3046{
76db3ba4 3047 if (likely(!ctx->le_mode)) {
76db3ba4
AJ
3048 TCGv t0 = tcg_temp_new();
3049 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 3050 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
3051 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
3052 tcg_temp_free(t0);
76db3ba4
AJ
3053 } else {
3054 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
3055 }
b61f2753 3056}
0c8aacd4 3057GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 3058
79aceca5 3059/* stwbrx */
86178a57 3060static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3061{
76db3ba4 3062 if (likely(!ctx->le_mode)) {
fa3966a3
AJ
3063 TCGv t0 = tcg_temp_new();
3064 tcg_gen_ext32u_tl(t0, arg1);
3065 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
3066 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
3067 tcg_temp_free(t0);
76db3ba4
AJ
3068 } else {
3069 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
3070 }
b61f2753 3071}
0c8aacd4 3072GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 3073
cd6e9320
TH
3074#if defined(TARGET_PPC64)
3075/* stdbrx */
3076static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3077{
3078 if (likely(!ctx->le_mode)) {
3079 TCGv t0 = tcg_temp_new();
3080 tcg_gen_bswap64_tl(t0, arg1);
3081 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
3082 tcg_temp_free(t0);
3083 } else {
3084 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
3085 }
3086}
3087GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3088#endif /* TARGET_PPC64 */
3089
79aceca5 3090/*** Integer load and store multiple ***/
99e300ef 3091
54623277 3092/* lmw */
99e300ef 3093static void gen_lmw(DisasContext *ctx)
79aceca5 3094{
76db3ba4
AJ
3095 TCGv t0;
3096 TCGv_i32 t1;
3097 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3098 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3099 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3100 t0 = tcg_temp_new();
3101 t1 = tcg_const_i32(rD(ctx->opcode));
3102 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3103 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3104 tcg_temp_free(t0);
3105 tcg_temp_free_i32(t1);
79aceca5
FB
3106}
3107
3108/* stmw */
99e300ef 3109static void gen_stmw(DisasContext *ctx)
79aceca5 3110{
76db3ba4
AJ
3111 TCGv t0;
3112 TCGv_i32 t1;
3113 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3114 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3115 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3116 t0 = tcg_temp_new();
3117 t1 = tcg_const_i32(rS(ctx->opcode));
3118 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3119 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3120 tcg_temp_free(t0);
3121 tcg_temp_free_i32(t1);
79aceca5
FB
3122}
3123
3124/*** Integer load and store strings ***/
54623277 3125
79aceca5 3126/* lswi */
3fc6c082 3127/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3128 * rA is in the range of registers to be loaded.
3129 * In an other hand, IBM says this is valid, but rA won't be loaded.
3130 * For now, I'll follow the spec...
3131 */
99e300ef 3132static void gen_lswi(DisasContext *ctx)
79aceca5 3133{
dfbc799d
AJ
3134 TCGv t0;
3135 TCGv_i32 t1, t2;
79aceca5
FB
3136 int nb = NB(ctx->opcode);
3137 int start = rD(ctx->opcode);
9a64fbe4 3138 int ra = rA(ctx->opcode);
79aceca5
FB
3139 int nr;
3140
3141 if (nb == 0)
3142 nb = 32;
3143 nr = nb / 4;
76a66253
JM
3144 if (unlikely(((start + nr) > 32 &&
3145 start <= ra && (start + nr - 32) > ra) ||
3146 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
e06fcd75 3147 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3148 return;
297d8e62 3149 }
76db3ba4 3150 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3151 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3152 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3153 t0 = tcg_temp_new();
76db3ba4 3154 gen_addr_register(ctx, t0);
dfbc799d
AJ
3155 t1 = tcg_const_i32(nb);
3156 t2 = tcg_const_i32(start);
2f5a189c 3157 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3158 tcg_temp_free(t0);
3159 tcg_temp_free_i32(t1);
3160 tcg_temp_free_i32(t2);
79aceca5
FB
3161}
3162
3163/* lswx */
99e300ef 3164static void gen_lswx(DisasContext *ctx)
79aceca5 3165{
76db3ba4
AJ
3166 TCGv t0;
3167 TCGv_i32 t1, t2, t3;
3168 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3169 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3170 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3171 t0 = tcg_temp_new();
3172 gen_addr_reg_index(ctx, t0);
3173 t1 = tcg_const_i32(rD(ctx->opcode));
3174 t2 = tcg_const_i32(rA(ctx->opcode));
3175 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3176 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3177 tcg_temp_free(t0);
3178 tcg_temp_free_i32(t1);
3179 tcg_temp_free_i32(t2);
3180 tcg_temp_free_i32(t3);
79aceca5
FB
3181}
3182
3183/* stswi */
99e300ef 3184static void gen_stswi(DisasContext *ctx)
79aceca5 3185{
76db3ba4
AJ
3186 TCGv t0;
3187 TCGv_i32 t1, t2;
4b3686fa 3188 int nb = NB(ctx->opcode);
76db3ba4 3189 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3190 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3191 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3192 t0 = tcg_temp_new();
3193 gen_addr_register(ctx, t0);
4b3686fa
FB
3194 if (nb == 0)
3195 nb = 32;
dfbc799d 3196 t1 = tcg_const_i32(nb);
76db3ba4 3197 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3198 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3199 tcg_temp_free(t0);
3200 tcg_temp_free_i32(t1);
3201 tcg_temp_free_i32(t2);
79aceca5
FB
3202}
3203
3204/* stswx */
99e300ef 3205static void gen_stswx(DisasContext *ctx)
79aceca5 3206{
76db3ba4
AJ
3207 TCGv t0;
3208 TCGv_i32 t1, t2;
3209 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3210 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3211 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3212 t0 = tcg_temp_new();
3213 gen_addr_reg_index(ctx, t0);
3214 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3215 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3216 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3217 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3218 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3219 tcg_temp_free(t0);
3220 tcg_temp_free_i32(t1);
3221 tcg_temp_free_i32(t2);
79aceca5
FB
3222}
3223
3224/*** Memory synchronisation ***/
3225/* eieio */
99e300ef 3226static void gen_eieio(DisasContext *ctx)
79aceca5 3227{
79aceca5
FB
3228}
3229
3230/* isync */
99e300ef 3231static void gen_isync(DisasContext *ctx)
79aceca5 3232{
e06fcd75 3233 gen_stop_exception(ctx);
79aceca5
FB
3234}
3235
5c77a786
TM
3236#define LARX(name, len, loadop) \
3237static void gen_##name(DisasContext *ctx) \
3238{ \
3239 TCGv t0; \
3240 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3241 gen_set_access_type(ctx, ACCESS_RES); \
3242 t0 = tcg_temp_local_new(); \
3243 gen_addr_reg_index(ctx, t0); \
3244 if ((len) > 1) { \
3245 gen_check_align(ctx, t0, (len)-1); \
3246 } \
3247 gen_qemu_##loadop(ctx, gpr, t0); \
3248 tcg_gen_mov_tl(cpu_reserve, t0); \
3249 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3250 tcg_temp_free(t0); \
79aceca5
FB
3251}
3252
5c77a786
TM
3253/* lwarx */
3254LARX(lbarx, 1, ld8u);
3255LARX(lharx, 2, ld16u);
3256LARX(lwarx, 4, ld32u);
3257
3258
4425265b 3259#if defined(CONFIG_USER_ONLY)
587c51f7
TM
3260static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3261 int reg, int size)
4425265b
NF
3262{
3263 TCGv t0 = tcg_temp_new();
3264 uint32_t save_exception = ctx->exception;
3265
1328c2bf 3266 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3267 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3268 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3269 tcg_temp_free(t0);
3270 gen_update_nip(ctx, ctx->nip-4);
3271 ctx->exception = POWERPC_EXCP_BRANCH;
3272 gen_exception(ctx, POWERPC_EXCP_STCX);
3273 ctx->exception = save_exception;
3274}
4425265b 3275#else
587c51f7
TM
3276static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3277 int reg, int size)
3278{
3279 int l1;
4425265b 3280
587c51f7
TM
3281 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3282 l1 = gen_new_label();
3283 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3284 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3285#if defined(TARGET_PPC64)
3286 if (size == 8) {
3287 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3288 } else
3289#endif
3290 if (size == 4) {
3291 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3292 } else if (size == 2) {
3293 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
3294 } else {
3295 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
4425265b 3296 }
587c51f7
TM
3297 gen_set_label(l1);
3298 tcg_gen_movi_tl(cpu_reserve, -1);
3299}
4425265b 3300#endif
587c51f7
TM
3301
3302#define STCX(name, len) \
3303static void gen_##name(DisasContext *ctx) \
3304{ \
3305 TCGv t0; \
3306 gen_set_access_type(ctx, ACCESS_RES); \
3307 t0 = tcg_temp_local_new(); \
3308 gen_addr_reg_index(ctx, t0); \
3309 if (len > 1) { \
3310 gen_check_align(ctx, t0, (len)-1); \
3311 } \
3312 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3313 tcg_temp_free(t0); \
79aceca5
FB
3314}
3315
587c51f7
TM
3316STCX(stbcx_, 1);
3317STCX(sthcx_, 2);
3318STCX(stwcx_, 4);
3319
426613db 3320#if defined(TARGET_PPC64)
426613db 3321/* ldarx */
5c77a786 3322LARX(ldarx, 8, ld64);
426613db
JM
3323
3324/* stdcx. */
587c51f7 3325STCX(stdcx_, 8);
426613db
JM
3326#endif /* defined(TARGET_PPC64) */
3327
79aceca5 3328/* sync */
99e300ef 3329static void gen_sync(DisasContext *ctx)
79aceca5 3330{
79aceca5
FB
3331}
3332
0db1b20e 3333/* wait */
99e300ef 3334static void gen_wait(DisasContext *ctx)
0db1b20e 3335{
931ff272 3336 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3337 tcg_gen_st_i32(t0, cpu_env,
3338 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3339 tcg_temp_free_i32(t0);
0db1b20e 3340 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3341 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3342}
3343
79aceca5 3344/*** Floating-point load ***/
a0d7d5a7 3345#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3346static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3347{ \
a0d7d5a7 3348 TCGv EA; \
76a66253 3349 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3350 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3351 return; \
3352 } \
76db3ba4 3353 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3354 EA = tcg_temp_new(); \
76db3ba4
AJ
3355 gen_addr_imm_index(ctx, EA, 0); \
3356 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3357 tcg_temp_free(EA); \
79aceca5
FB
3358}
3359
a0d7d5a7 3360#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3361static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3362{ \
a0d7d5a7 3363 TCGv EA; \
76a66253 3364 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3365 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3366 return; \
3367 } \
76a66253 3368 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3369 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3370 return; \
9a64fbe4 3371 } \
76db3ba4 3372 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3373 EA = tcg_temp_new(); \
76db3ba4
AJ
3374 gen_addr_imm_index(ctx, EA, 0); \
3375 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3376 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3377 tcg_temp_free(EA); \
79aceca5
FB
3378}
3379
a0d7d5a7 3380#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3381static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3382{ \
a0d7d5a7 3383 TCGv EA; \
76a66253 3384 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3385 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3386 return; \
3387 } \
76a66253 3388 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3389 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3390 return; \
9a64fbe4 3391 } \
76db3ba4 3392 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3393 EA = tcg_temp_new(); \
76db3ba4
AJ
3394 gen_addr_reg_index(ctx, EA); \
3395 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3396 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3397 tcg_temp_free(EA); \
79aceca5
FB
3398}
3399
a0d7d5a7 3400#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3401static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3402{ \
a0d7d5a7 3403 TCGv EA; \
76a66253 3404 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3405 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3406 return; \
3407 } \
76db3ba4 3408 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3409 EA = tcg_temp_new(); \
76db3ba4
AJ
3410 gen_addr_reg_index(ctx, EA); \
3411 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3412 tcg_temp_free(EA); \
79aceca5
FB
3413}
3414
a0d7d5a7
AJ
3415#define GEN_LDFS(name, ldop, op, type) \
3416GEN_LDF(name, ldop, op | 0x20, type); \
3417GEN_LDUF(name, ldop, op | 0x21, type); \
3418GEN_LDUXF(name, ldop, op | 0x01, type); \
3419GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3420
636aa200 3421static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3422{
3423 TCGv t0 = tcg_temp_new();
3424 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3425 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3426 tcg_gen_trunc_tl_i32(t1, t0);
3427 tcg_temp_free(t0);
8e703949 3428 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3429 tcg_temp_free_i32(t1);
3430}
79aceca5 3431
a0d7d5a7
AJ
3432 /* lfd lfdu lfdux lfdx */
3433GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3434 /* lfs lfsu lfsux lfsx */
3435GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3436
05050ee8
AJ
3437/* lfdp */
3438static void gen_lfdp(DisasContext *ctx)
3439{
3440 TCGv EA;
3441 if (unlikely(!ctx->fpu_enabled)) {
3442 gen_exception(ctx, POWERPC_EXCP_FPU);
3443 return;
3444 }
3445 gen_set_access_type(ctx, ACCESS_FLOAT);
3446 EA = tcg_temp_new();
3447 gen_addr_imm_index(ctx, EA, 0); \
3448 if (unlikely(ctx->le_mode)) {
3449 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3450 tcg_gen_addi_tl(EA, EA, 8);
3451 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3452 } else {
3453 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3454 tcg_gen_addi_tl(EA, EA, 8);
3455 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3456 }
3457 tcg_temp_free(EA);
3458}
3459
3460/* lfdpx */
3461static void gen_lfdpx(DisasContext *ctx)
3462{
3463 TCGv EA;
3464 if (unlikely(!ctx->fpu_enabled)) {
3465 gen_exception(ctx, POWERPC_EXCP_FPU);
3466 return;
3467 }
3468 gen_set_access_type(ctx, ACCESS_FLOAT);
3469 EA = tcg_temp_new();
3470 gen_addr_reg_index(ctx, EA);
3471 if (unlikely(ctx->le_mode)) {
3472 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3473 tcg_gen_addi_tl(EA, EA, 8);
3474 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3475 } else {
3476 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3477 tcg_gen_addi_tl(EA, EA, 8);
3478 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3479 }
3480 tcg_temp_free(EA);
3481}
3482
199f830d
AJ
3483/* lfiwax */
3484static void gen_lfiwax(DisasContext *ctx)
3485{
3486 TCGv EA;
3487 TCGv t0;
3488 if (unlikely(!ctx->fpu_enabled)) {
3489 gen_exception(ctx, POWERPC_EXCP_FPU);
3490 return;
3491 }
3492 gen_set_access_type(ctx, ACCESS_FLOAT);
3493 EA = tcg_temp_new();
3494 t0 = tcg_temp_new();
3495 gen_addr_reg_index(ctx, EA);
909eedb7 3496 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3497 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3498 tcg_temp_free(EA);
3499 tcg_temp_free(t0);
3500}
3501
79aceca5 3502/*** Floating-point store ***/
a0d7d5a7 3503#define GEN_STF(name, stop, opc, type) \
99e300ef 3504static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3505{ \
a0d7d5a7 3506 TCGv EA; \
76a66253 3507 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3508 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3509 return; \
3510 } \
76db3ba4 3511 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3512 EA = tcg_temp_new(); \
76db3ba4
AJ
3513 gen_addr_imm_index(ctx, EA, 0); \
3514 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3515 tcg_temp_free(EA); \
79aceca5
FB
3516}
3517
a0d7d5a7 3518#define GEN_STUF(name, stop, opc, type) \
99e300ef 3519static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3520{ \
a0d7d5a7 3521 TCGv EA; \
76a66253 3522 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3523 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3524 return; \
3525 } \
76a66253 3526 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3527 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3528 return; \
9a64fbe4 3529 } \
76db3ba4 3530 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3531 EA = tcg_temp_new(); \
76db3ba4
AJ
3532 gen_addr_imm_index(ctx, EA, 0); \
3533 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3534 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3535 tcg_temp_free(EA); \
79aceca5
FB
3536}
3537
a0d7d5a7 3538#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3539static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3540{ \
a0d7d5a7 3541 TCGv EA; \
76a66253 3542 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3543 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3544 return; \
3545 } \
76a66253 3546 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3547 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3548 return; \
9a64fbe4 3549 } \
76db3ba4 3550 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3551 EA = tcg_temp_new(); \
76db3ba4
AJ
3552 gen_addr_reg_index(ctx, EA); \
3553 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3554 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3555 tcg_temp_free(EA); \
79aceca5
FB
3556}
3557
a0d7d5a7 3558#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3559static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3560{ \
a0d7d5a7 3561 TCGv EA; \
76a66253 3562 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3563 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3564 return; \
3565 } \
76db3ba4 3566 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3567 EA = tcg_temp_new(); \
76db3ba4
AJ
3568 gen_addr_reg_index(ctx, EA); \
3569 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3570 tcg_temp_free(EA); \
79aceca5
FB
3571}
3572
a0d7d5a7
AJ
3573#define GEN_STFS(name, stop, op, type) \
3574GEN_STF(name, stop, op | 0x20, type); \
3575GEN_STUF(name, stop, op | 0x21, type); \
3576GEN_STUXF(name, stop, op | 0x01, type); \
3577GEN_STXF(name, stop, 0x17, op | 0x00, type)
3578
636aa200 3579static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3580{
3581 TCGv_i32 t0 = tcg_temp_new_i32();
3582 TCGv t1 = tcg_temp_new();
8e703949 3583 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3584 tcg_gen_extu_i32_tl(t1, t0);
3585 tcg_temp_free_i32(t0);
76db3ba4 3586 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3587 tcg_temp_free(t1);
3588}
79aceca5
FB
3589
3590/* stfd stfdu stfdux stfdx */
a0d7d5a7 3591GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3592/* stfs stfsu stfsux stfsx */
a0d7d5a7 3593GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3594
44bc0c4d
AJ
3595/* stfdp */
3596static void gen_stfdp(DisasContext *ctx)
3597{
3598 TCGv EA;
3599 if (unlikely(!ctx->fpu_enabled)) {
3600 gen_exception(ctx, POWERPC_EXCP_FPU);
3601 return;
3602 }
3603 gen_set_access_type(ctx, ACCESS_FLOAT);
3604 EA = tcg_temp_new();
3605 gen_addr_imm_index(ctx, EA, 0); \
3606 if (unlikely(ctx->le_mode)) {
3607 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3608 tcg_gen_addi_tl(EA, EA, 8);
3609 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3610 } else {
3611 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3612 tcg_gen_addi_tl(EA, EA, 8);
3613 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3614 }
3615 tcg_temp_free(EA);
3616}
3617
3618/* stfdpx */
3619static void gen_stfdpx(DisasContext *ctx)
3620{
3621 TCGv EA;
3622 if (unlikely(!ctx->fpu_enabled)) {
3623 gen_exception(ctx, POWERPC_EXCP_FPU);
3624 return;
3625 }
3626 gen_set_access_type(ctx, ACCESS_FLOAT);
3627 EA = tcg_temp_new();
3628 gen_addr_reg_index(ctx, EA);
3629 if (unlikely(ctx->le_mode)) {
3630 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3631 tcg_gen_addi_tl(EA, EA, 8);
3632 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3633 } else {
3634 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3635 tcg_gen_addi_tl(EA, EA, 8);
3636 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3637 }
3638 tcg_temp_free(EA);
3639}
3640
79aceca5 3641/* Optional: */
636aa200 3642static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3643{
3644 TCGv t0 = tcg_temp_new();
3645 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3646 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3647 tcg_temp_free(t0);
3648}
79aceca5 3649/* stfiwx */
a0d7d5a7 3650GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3651
697ab892
DG
3652static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3653{
3654#if defined(TARGET_PPC64)
3655 if (ctx->has_cfar)
3656 tcg_gen_movi_tl(cpu_cfar, nip);
3657#endif
3658}
3659
79aceca5 3660/*** Branch ***/
636aa200 3661static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362
FB
3662{
3663 TranslationBlock *tb;
3664 tb = ctx->tb;
e0c8f9ce 3665 if (NARROW_MODE(ctx)) {
a2ffb812 3666 dest = (uint32_t) dest;
e0c8f9ce 3667 }
57fec1fe 3668 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
8cbcb4fa 3669 likely(!ctx->singlestep_enabled)) {
57fec1fe 3670 tcg_gen_goto_tb(n);
a2ffb812 3671 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cfd0495 3672 tcg_gen_exit_tb((uintptr_t)tb + n);
c1942362 3673 } else {
a2ffb812 3674 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3675 if (unlikely(ctx->singlestep_enabled)) {
3676 if ((ctx->singlestep_enabled &
bdc4e053 3677 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3678 (ctx->exception == POWERPC_EXCP_BRANCH ||
3679 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3680 target_ulong tmp = ctx->nip;
3681 ctx->nip = dest;
e06fcd75 3682 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3683 ctx->nip = tmp;
3684 }
3685 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3686 gen_debug_exception(ctx);
8cbcb4fa
AJ
3687 }
3688 }
57fec1fe 3689 tcg_gen_exit_tb(0);
c1942362 3690 }
c53be334
FB
3691}
3692
636aa200 3693static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3694{
e0c8f9ce
RH
3695 if (NARROW_MODE(ctx)) {
3696 nip = (uint32_t)nip;
3697 }
3698 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3699}
3700
79aceca5 3701/* b ba bl bla */
99e300ef 3702static void gen_b(DisasContext *ctx)
79aceca5 3703{
76a66253 3704 target_ulong li, target;
38a64f9d 3705
8cbcb4fa 3706 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3707 /* sign extend LI */
e0c8f9ce
RH
3708 li = LI(ctx->opcode);
3709 li = (li ^ 0x02000000) - 0x02000000;
3710 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3711 target = ctx->nip + li - 4;
e0c8f9ce 3712 } else {
9a64fbe4 3713 target = li;
e0c8f9ce
RH
3714 }
3715 if (LK(ctx->opcode)) {
e1833e1f 3716 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3717 }
697ab892 3718 gen_update_cfar(ctx, ctx->nip);
c1942362 3719 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3720}
3721
e98a6e40
FB
3722#define BCOND_IM 0
3723#define BCOND_LR 1
3724#define BCOND_CTR 2
3725
636aa200 3726static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3727{
d9bce9d9 3728 uint32_t bo = BO(ctx->opcode);
05f92404 3729 int l1;
a2ffb812 3730 TCGv target;
e98a6e40 3731
8cbcb4fa 3732 ctx->exception = POWERPC_EXCP_BRANCH;
a2ffb812 3733 if (type == BCOND_LR || type == BCOND_CTR) {
a7812ae4 3734 target = tcg_temp_local_new();
a2ffb812
AJ
3735 if (type == BCOND_CTR)
3736 tcg_gen_mov_tl(target, cpu_ctr);
3737 else
3738 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3739 } else {
3740 TCGV_UNUSED(target);
e98a6e40 3741 }
e1833e1f
JM
3742 if (LK(ctx->opcode))
3743 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3744 l1 = gen_new_label();
3745 if ((bo & 0x4) == 0) {
3746 /* Decrement and test CTR */
a7812ae4 3747 TCGv temp = tcg_temp_new();
a2ffb812 3748 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3749 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3750 return;
3751 }
3752 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3753 if (NARROW_MODE(ctx)) {
a2ffb812 3754 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3755 } else {
a2ffb812 3756 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3757 }
a2ffb812
AJ
3758 if (bo & 0x2) {
3759 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3760 } else {
3761 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3762 }
a7812ae4 3763 tcg_temp_free(temp);
a2ffb812
AJ
3764 }
3765 if ((bo & 0x10) == 0) {
3766 /* Test CR */
3767 uint32_t bi = BI(ctx->opcode);
3768 uint32_t mask = 1 << (3 - (bi & 0x03));
a7812ae4 3769 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3770
d9bce9d9 3771 if (bo & 0x8) {
a2ffb812
AJ
3772 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3773 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3774 } else {
a2ffb812
AJ
3775 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3776 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3777 }
a7812ae4 3778 tcg_temp_free_i32(temp);
d9bce9d9 3779 }
697ab892 3780 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3781 if (type == BCOND_IM) {
a2ffb812
AJ
3782 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3783 if (likely(AA(ctx->opcode) == 0)) {
3784 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3785 } else {
3786 gen_goto_tb(ctx, 0, li);
3787 }
c53be334 3788 gen_set_label(l1);
c1942362 3789 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3790 } else {
e0c8f9ce 3791 if (NARROW_MODE(ctx)) {
a2ffb812 3792 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3793 } else {
a2ffb812 3794 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3795 }
a2ffb812
AJ
3796 tcg_gen_exit_tb(0);
3797 gen_set_label(l1);
e0c8f9ce 3798 gen_update_nip(ctx, ctx->nip);
57fec1fe 3799 tcg_gen_exit_tb(0);
08e46e54 3800 }
e98a6e40
FB
3801}
3802
99e300ef 3803static void gen_bc(DisasContext *ctx)
3b46e624 3804{
e98a6e40
FB
3805 gen_bcond(ctx, BCOND_IM);
3806}
3807
99e300ef 3808static void gen_bcctr(DisasContext *ctx)
3b46e624 3809{
e98a6e40
FB
3810 gen_bcond(ctx, BCOND_CTR);
3811}
3812
99e300ef 3813static void gen_bclr(DisasContext *ctx)
3b46e624 3814{
e98a6e40
FB
3815 gen_bcond(ctx, BCOND_LR);
3816}
79aceca5
FB
3817
3818/*** Condition register logical ***/
e1571908 3819#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 3820static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3821{ \
fc0d441e
JM
3822 uint8_t bitmask; \
3823 int sh; \
a7812ae4 3824 TCGv_i32 t0, t1; \
fc0d441e 3825 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 3826 t0 = tcg_temp_new_i32(); \
fc0d441e 3827 if (sh > 0) \
fea0c503 3828 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 3829 else if (sh < 0) \
fea0c503 3830 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 3831 else \
fea0c503 3832 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 3833 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
3834 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3835 if (sh > 0) \
fea0c503 3836 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 3837 else if (sh < 0) \
fea0c503 3838 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 3839 else \
fea0c503
AJ
3840 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3841 tcg_op(t0, t0, t1); \
fc0d441e 3842 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
fea0c503
AJ
3843 tcg_gen_andi_i32(t0, t0, bitmask); \
3844 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3845 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
3846 tcg_temp_free_i32(t0); \
3847 tcg_temp_free_i32(t1); \
79aceca5
FB
3848}
3849
3850/* crand */
e1571908 3851GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 3852/* crandc */
e1571908 3853GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 3854/* creqv */
e1571908 3855GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 3856/* crnand */
e1571908 3857GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 3858/* crnor */
e1571908 3859GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 3860/* cror */
e1571908 3861GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 3862/* crorc */
e1571908 3863GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 3864/* crxor */
e1571908 3865GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 3866
54623277 3867/* mcrf */
99e300ef 3868static void gen_mcrf(DisasContext *ctx)
79aceca5 3869{
47e4661c 3870 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
3871}
3872
3873/*** System linkage ***/
99e300ef 3874
54623277 3875/* rfi (mem_idx only) */
99e300ef 3876static void gen_rfi(DisasContext *ctx)
79aceca5 3877{
9a64fbe4 3878#if defined(CONFIG_USER_ONLY)
e06fcd75 3879 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
3880#else
3881 /* Restore CPU state */
76db3ba4 3882 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3883 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 3884 return;
9a64fbe4 3885 }
697ab892 3886 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 3887 gen_helper_rfi(cpu_env);
e06fcd75 3888 gen_sync_exception(ctx);
9a64fbe4 3889#endif
79aceca5
FB
3890}
3891
426613db 3892#if defined(TARGET_PPC64)
99e300ef 3893static void gen_rfid(DisasContext *ctx)
426613db
JM
3894{
3895#if defined(CONFIG_USER_ONLY)
e06fcd75 3896 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
3897#else
3898 /* Restore CPU state */
76db3ba4 3899 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3900 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
3901 return;
3902 }
697ab892 3903 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 3904 gen_helper_rfid(cpu_env);
e06fcd75 3905 gen_sync_exception(ctx);
426613db
JM
3906#endif
3907}
426613db 3908
99e300ef 3909static void gen_hrfid(DisasContext *ctx)
be147d08
JM
3910{
3911#if defined(CONFIG_USER_ONLY)
e06fcd75 3912 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3913#else
3914 /* Restore CPU state */
76db3ba4 3915 if (unlikely(ctx->mem_idx <= 1)) {
e06fcd75 3916 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3917 return;
3918 }
e5f17ac6 3919 gen_helper_hrfid(cpu_env);
e06fcd75 3920 gen_sync_exception(ctx);
be147d08
JM
3921#endif
3922}
3923#endif
3924
79aceca5 3925/* sc */
417bf010
JM
3926#if defined(CONFIG_USER_ONLY)
3927#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3928#else
3929#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3930#endif
99e300ef 3931static void gen_sc(DisasContext *ctx)
79aceca5 3932{
e1833e1f
JM
3933 uint32_t lev;
3934
3935 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 3936 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
3937}
3938
3939/*** Trap ***/
99e300ef 3940
54623277 3941/* tw */
99e300ef 3942static void gen_tw(DisasContext *ctx)
79aceca5 3943{
cab3bee2 3944 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3945 /* Update the nip since this might generate a trap exception */
3946 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
3947 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
3948 t0);
cab3bee2 3949 tcg_temp_free_i32(t0);
79aceca5
FB
3950}
3951
3952/* twi */
99e300ef 3953static void gen_twi(DisasContext *ctx)
79aceca5 3954{
cab3bee2
AJ
3955 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3956 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3957 /* Update the nip since this might generate a trap exception */
3958 gen_update_nip(ctx, ctx->nip);
e5f17ac6 3959 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
3960 tcg_temp_free(t0);
3961 tcg_temp_free_i32(t1);
79aceca5
FB
3962}
3963
d9bce9d9
JM
3964#if defined(TARGET_PPC64)
3965/* td */
99e300ef 3966static void gen_td(DisasContext *ctx)
d9bce9d9 3967{
cab3bee2 3968 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3969 /* Update the nip since this might generate a trap exception */
3970 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
3971 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
3972 t0);
cab3bee2 3973 tcg_temp_free_i32(t0);
d9bce9d9
JM
3974}
3975
3976/* tdi */
99e300ef 3977static void gen_tdi(DisasContext *ctx)
d9bce9d9 3978{
cab3bee2
AJ
3979 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3980 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3981 /* Update the nip since this might generate a trap exception */
3982 gen_update_nip(ctx, ctx->nip);
e5f17ac6 3983 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
3984 tcg_temp_free(t0);
3985 tcg_temp_free_i32(t1);
d9bce9d9
JM
3986}
3987#endif
3988
79aceca5 3989/*** Processor control ***/
99e300ef 3990
da91a00f
RH
3991static void gen_read_xer(TCGv dst)
3992{
3993 TCGv t0 = tcg_temp_new();
3994 TCGv t1 = tcg_temp_new();
3995 TCGv t2 = tcg_temp_new();
3996 tcg_gen_mov_tl(dst, cpu_xer);
3997 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
3998 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
3999 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4000 tcg_gen_or_tl(t0, t0, t1);
4001 tcg_gen_or_tl(dst, dst, t2);
4002 tcg_gen_or_tl(dst, dst, t0);
4003 tcg_temp_free(t0);
4004 tcg_temp_free(t1);
4005 tcg_temp_free(t2);
4006}
4007
4008static void gen_write_xer(TCGv src)
4009{
4010 tcg_gen_andi_tl(cpu_xer, src,
4011 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4012 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4013 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4014 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4015 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4016 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4017 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4018}
4019
54623277 4020/* mcrxr */
99e300ef 4021static void gen_mcrxr(DisasContext *ctx)
79aceca5 4022{
da91a00f
RH
4023 TCGv_i32 t0 = tcg_temp_new_i32();
4024 TCGv_i32 t1 = tcg_temp_new_i32();
4025 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4026
4027 tcg_gen_trunc_tl_i32(t0, cpu_so);
4028 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4029 tcg_gen_trunc_tl_i32(dst, cpu_ca);
4030 tcg_gen_shri_i32(t0, t0, 2);
4031 tcg_gen_shri_i32(t1, t1, 1);
4032 tcg_gen_or_i32(dst, dst, t0);
4033 tcg_gen_or_i32(dst, dst, t1);
4034 tcg_temp_free_i32(t0);
4035 tcg_temp_free_i32(t1);
4036
4037 tcg_gen_movi_tl(cpu_so, 0);
4038 tcg_gen_movi_tl(cpu_ov, 0);
4039 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
4040}
4041
0cfe11ea 4042/* mfcr mfocrf */
99e300ef 4043static void gen_mfcr(DisasContext *ctx)
79aceca5 4044{
76a66253 4045 uint32_t crm, crn;
3b46e624 4046
76a66253
JM
4047 if (likely(ctx->opcode & 0x00100000)) {
4048 crm = CRM(ctx->opcode);
8dd640e4 4049 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 4050 crn = ctz32 (crm);
e1571908 4051 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
4052 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4053 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 4054 }
d9bce9d9 4055 } else {
651721b2
AJ
4056 TCGv_i32 t0 = tcg_temp_new_i32();
4057 tcg_gen_mov_i32(t0, cpu_crf[0]);
4058 tcg_gen_shli_i32(t0, t0, 4);
4059 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4060 tcg_gen_shli_i32(t0, t0, 4);
4061 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4062 tcg_gen_shli_i32(t0, t0, 4);
4063 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4064 tcg_gen_shli_i32(t0, t0, 4);
4065 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4066 tcg_gen_shli_i32(t0, t0, 4);
4067 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4068 tcg_gen_shli_i32(t0, t0, 4);
4069 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4070 tcg_gen_shli_i32(t0, t0, 4);
4071 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4072 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4073 tcg_temp_free_i32(t0);
d9bce9d9 4074 }
79aceca5
FB
4075}
4076
4077/* mfmsr */
99e300ef 4078static void gen_mfmsr(DisasContext *ctx)
79aceca5 4079{
9a64fbe4 4080#if defined(CONFIG_USER_ONLY)
e06fcd75 4081 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4082#else
76db3ba4 4083 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4084 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4085 return;
9a64fbe4 4086 }
6527f6ea 4087 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4088#endif
79aceca5
FB
4089}
4090
7b13448f 4091static void spr_noaccess(void *opaque, int gprn, int sprn)
3fc6c082 4092{
7b13448f 4093#if 0
3fc6c082
FB
4094 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4095 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4096#endif
3fc6c082
FB
4097}
4098#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4099
79aceca5 4100/* mfspr */
636aa200 4101static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4102{
45d827d2 4103 void (*read_cb)(void *opaque, int gprn, int sprn);
79aceca5
FB
4104 uint32_t sprn = SPR(ctx->opcode);
4105
3fc6c082 4106#if !defined(CONFIG_USER_ONLY)
76db3ba4 4107 if (ctx->mem_idx == 2)
be147d08 4108 read_cb = ctx->spr_cb[sprn].hea_read;
76db3ba4 4109 else if (ctx->mem_idx)
3fc6c082
FB
4110 read_cb = ctx->spr_cb[sprn].oea_read;
4111 else
9a64fbe4 4112#endif
3fc6c082 4113 read_cb = ctx->spr_cb[sprn].uea_read;
76a66253
JM
4114 if (likely(read_cb != NULL)) {
4115 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4116 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4117 } else {
4118 /* Privilege exception */
9fceefa7
JM
4119 /* This is a hack to avoid warnings when running Linux:
4120 * this OS breaks the PowerPC virtualisation model,
4121 * allowing userland application to read the PVR
4122 */
4123 if (sprn != SPR_PVR) {
c05541ee
AB
4124 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4125 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4126 printf("Trying to read privileged spr %d (0x%03x) at "
4127 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
f24e5695 4128 }
e06fcd75 4129 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4130 }
3fc6c082
FB
4131 } else {
4132 /* Not defined */
c05541ee
AB
4133 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4134 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4135 printf("Trying to read invalid spr %d (0x%03x) at "
4136 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4137 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4138 }
79aceca5
FB
4139}
4140
99e300ef 4141static void gen_mfspr(DisasContext *ctx)
79aceca5 4142{
3fc6c082 4143 gen_op_mfspr(ctx);
76a66253 4144}
3fc6c082
FB
4145
4146/* mftb */
99e300ef 4147static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4148{
4149 gen_op_mfspr(ctx);
79aceca5
FB
4150}
4151
0cfe11ea 4152/* mtcrf mtocrf*/
99e300ef 4153static void gen_mtcrf(DisasContext *ctx)
79aceca5 4154{
76a66253 4155 uint32_t crm, crn;
3b46e624 4156
76a66253 4157 crm = CRM(ctx->opcode);
8dd640e4 4158 if (likely((ctx->opcode & 0x00100000))) {
4159 if (crm && ((crm & (crm - 1)) == 0)) {
4160 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4161 crn = ctz32 (crm);
8dd640e4 4162 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4163 tcg_gen_shri_i32(temp, temp, crn * 4);
4164 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4165 tcg_temp_free_i32(temp);
4166 }
76a66253 4167 } else {
651721b2
AJ
4168 TCGv_i32 temp = tcg_temp_new_i32();
4169 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4170 for (crn = 0 ; crn < 8 ; crn++) {
4171 if (crm & (1 << crn)) {
4172 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4173 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4174 }
4175 }
a7812ae4 4176 tcg_temp_free_i32(temp);
76a66253 4177 }
79aceca5
FB
4178}
4179
4180/* mtmsr */
426613db 4181#if defined(TARGET_PPC64)
99e300ef 4182static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4183{
4184#if defined(CONFIG_USER_ONLY)
e06fcd75 4185 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4186#else
76db3ba4 4187 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4188 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4189 return;
4190 }
be147d08
JM
4191 if (ctx->opcode & 0x00010000) {
4192 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4193 TCGv t0 = tcg_temp_new();
4194 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4195 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4196 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4197 tcg_temp_free(t0);
be147d08 4198 } else {
056b05f8
JM
4199 /* XXX: we need to update nip before the store
4200 * if we enter power saving mode, we will exit the loop
4201 * directly from ppc_store_msr
4202 */
be147d08 4203 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4204 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4205 /* Must stop the translation as machine state (may have) changed */
4206 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4207 gen_stop_exception(ctx);
be147d08 4208 }
426613db
JM
4209#endif
4210}
4211#endif
4212
99e300ef 4213static void gen_mtmsr(DisasContext *ctx)
79aceca5 4214{
9a64fbe4 4215#if defined(CONFIG_USER_ONLY)
e06fcd75 4216 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4217#else
76db3ba4 4218 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4219 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4220 return;
9a64fbe4 4221 }
be147d08
JM
4222 if (ctx->opcode & 0x00010000) {
4223 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4224 TCGv t0 = tcg_temp_new();
4225 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4226 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4227 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4228 tcg_temp_free(t0);
be147d08 4229 } else {
8018dc63
AG
4230 TCGv msr = tcg_temp_new();
4231
056b05f8
JM
4232 /* XXX: we need to update nip before the store
4233 * if we enter power saving mode, we will exit the loop
4234 * directly from ppc_store_msr
4235 */
be147d08 4236 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4237#if defined(TARGET_PPC64)
8018dc63
AG
4238 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4239#else
4240 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4241#endif
e5f17ac6 4242 gen_helper_store_msr(cpu_env, msr);
be147d08 4243 /* Must stop the translation as machine state (may have) changed */
6527f6ea 4244 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4245 gen_stop_exception(ctx);
be147d08 4246 }
9a64fbe4 4247#endif
79aceca5
FB
4248}
4249
4250/* mtspr */
99e300ef 4251static void gen_mtspr(DisasContext *ctx)
79aceca5 4252{
45d827d2 4253 void (*write_cb)(void *opaque, int sprn, int gprn);
79aceca5
FB
4254 uint32_t sprn = SPR(ctx->opcode);
4255
3fc6c082 4256#if !defined(CONFIG_USER_ONLY)
76db3ba4 4257 if (ctx->mem_idx == 2)
be147d08 4258 write_cb = ctx->spr_cb[sprn].hea_write;
76db3ba4 4259 else if (ctx->mem_idx)
3fc6c082
FB
4260 write_cb = ctx->spr_cb[sprn].oea_write;
4261 else
9a64fbe4 4262#endif
3fc6c082 4263 write_cb = ctx->spr_cb[sprn].uea_write;
76a66253
JM
4264 if (likely(write_cb != NULL)) {
4265 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 4266 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
4267 } else {
4268 /* Privilege exception */
c05541ee
AB
4269 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4270 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4271 printf("Trying to write privileged spr %d (0x%03x) at "
4272 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4273 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 4274 }
3fc6c082
FB
4275 } else {
4276 /* Not defined */
c05541ee
AB
4277 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4278 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4279 printf("Trying to write invalid spr %d (0x%03x) at "
4280 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4281 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4282 }
79aceca5
FB
4283}
4284
4285/*** Cache management ***/
99e300ef 4286
54623277 4287/* dcbf */
99e300ef 4288static void gen_dcbf(DisasContext *ctx)
79aceca5 4289{
dac454af 4290 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
4291 TCGv t0;
4292 gen_set_access_type(ctx, ACCESS_CACHE);
4293 t0 = tcg_temp_new();
4294 gen_addr_reg_index(ctx, t0);
4295 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4296 tcg_temp_free(t0);
79aceca5
FB
4297}
4298
4299/* dcbi (Supervisor only) */
99e300ef 4300static void gen_dcbi(DisasContext *ctx)
79aceca5 4301{
a541f297 4302#if defined(CONFIG_USER_ONLY)
e06fcd75 4303 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 4304#else
b61f2753 4305 TCGv EA, val;
76db3ba4 4306 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4307 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4308 return;
9a64fbe4 4309 }
a7812ae4 4310 EA = tcg_temp_new();
76db3ba4
AJ
4311 gen_set_access_type(ctx, ACCESS_CACHE);
4312 gen_addr_reg_index(ctx, EA);
a7812ae4 4313 val = tcg_temp_new();
76a66253 4314 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
4315 gen_qemu_ld8u(ctx, val, EA);
4316 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
4317 tcg_temp_free(val);
4318 tcg_temp_free(EA);
a541f297 4319#endif
79aceca5
FB
4320}
4321
4322/* dcdst */
99e300ef 4323static void gen_dcbst(DisasContext *ctx)
79aceca5 4324{
76a66253 4325 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
4326 TCGv t0;
4327 gen_set_access_type(ctx, ACCESS_CACHE);
4328 t0 = tcg_temp_new();
4329 gen_addr_reg_index(ctx, t0);
4330 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4331 tcg_temp_free(t0);
79aceca5
FB
4332}
4333
4334/* dcbt */
99e300ef 4335static void gen_dcbt(DisasContext *ctx)
79aceca5 4336{
0db1b20e 4337 /* interpreted as no-op */
76a66253
JM
4338 /* XXX: specification say this is treated as a load by the MMU
4339 * but does not generate any exception
4340 */
79aceca5
FB
4341}
4342
4343/* dcbtst */
99e300ef 4344static void gen_dcbtst(DisasContext *ctx)
79aceca5 4345{
0db1b20e 4346 /* interpreted as no-op */
76a66253
JM
4347 /* XXX: specification say this is treated as a load by the MMU
4348 * but does not generate any exception
4349 */
79aceca5
FB
4350}
4351
4352/* dcbz */
99e300ef 4353static void gen_dcbz(DisasContext *ctx)
79aceca5 4354{
8e33944f
AG
4355 TCGv tcgv_addr;
4356 TCGv_i32 tcgv_is_dcbzl;
4357 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4358
76db3ba4 4359 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4360 /* NIP cannot be restored if the memory exception comes from an helper */
4361 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4362 tcgv_addr = tcg_temp_new();
4363 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4364
4365 gen_addr_reg_index(ctx, tcgv_addr);
4366 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4367
4368 tcg_temp_free(tcgv_addr);
4369 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4370}
4371
ae1c1a3d 4372/* dst / dstt */
99e300ef 4373static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4374{
4375 if (rA(ctx->opcode) == 0) {
4376 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4377 } else {
4378 /* interpreted as no-op */
4379 }
4380}
4381
4382/* dstst /dststt */
99e300ef 4383static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4384{
4385 if (rA(ctx->opcode) == 0) {
4386 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4387 } else {
4388 /* interpreted as no-op */
4389 }
4390
4391}
4392
4393/* dss / dssall */
99e300ef 4394static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4395{
4396 /* interpreted as no-op */
4397}
4398
79aceca5 4399/* icbi */
99e300ef 4400static void gen_icbi(DisasContext *ctx)
79aceca5 4401{
76db3ba4
AJ
4402 TCGv t0;
4403 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4404 /* NIP cannot be restored if the memory exception comes from an helper */
4405 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4406 t0 = tcg_temp_new();
4407 gen_addr_reg_index(ctx, t0);
2f5a189c 4408 gen_helper_icbi(cpu_env, t0);
37d269df 4409 tcg_temp_free(t0);
79aceca5
FB
4410}
4411
4412/* Optional: */
4413/* dcba */
99e300ef 4414static void gen_dcba(DisasContext *ctx)
79aceca5 4415{
0db1b20e
JM
4416 /* interpreted as no-op */
4417 /* XXX: specification say this is treated as a store by the MMU
4418 * but does not generate any exception
4419 */
79aceca5
FB
4420}
4421
4422/*** Segment register manipulation ***/
4423/* Supervisor only: */
99e300ef 4424
54623277 4425/* mfsr */
99e300ef 4426static void gen_mfsr(DisasContext *ctx)
79aceca5 4427{
9a64fbe4 4428#if defined(CONFIG_USER_ONLY)
e06fcd75 4429 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4430#else
74d37793 4431 TCGv t0;
76db3ba4 4432 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4433 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4434 return;
9a64fbe4 4435 }
74d37793 4436 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4437 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4438 tcg_temp_free(t0);
9a64fbe4 4439#endif
79aceca5
FB
4440}
4441
4442/* mfsrin */
99e300ef 4443static void gen_mfsrin(DisasContext *ctx)
79aceca5 4444{
9a64fbe4 4445#if defined(CONFIG_USER_ONLY)
e06fcd75 4446 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4447#else
74d37793 4448 TCGv t0;
76db3ba4 4449 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4450 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4451 return;
9a64fbe4 4452 }
74d37793
AJ
4453 t0 = tcg_temp_new();
4454 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4455 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4456 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4457 tcg_temp_free(t0);
9a64fbe4 4458#endif
79aceca5
FB
4459}
4460
4461/* mtsr */
99e300ef 4462static void gen_mtsr(DisasContext *ctx)
79aceca5 4463{
9a64fbe4 4464#if defined(CONFIG_USER_ONLY)
e06fcd75 4465 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4466#else
74d37793 4467 TCGv t0;
76db3ba4 4468 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4469 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4470 return;
9a64fbe4 4471 }
74d37793 4472 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4473 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4474 tcg_temp_free(t0);
9a64fbe4 4475#endif
79aceca5
FB
4476}
4477
4478/* mtsrin */
99e300ef 4479static void gen_mtsrin(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
AJ
4489 t0 = tcg_temp_new();
4490 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4491 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4492 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4493 tcg_temp_free(t0);
9a64fbe4 4494#endif
79aceca5
FB
4495}
4496
12de9a39
JM
4497#if defined(TARGET_PPC64)
4498/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4499
54623277 4500/* mfsr */
e8eaa2c0 4501static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4502{
4503#if defined(CONFIG_USER_ONLY)
e06fcd75 4504 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4505#else
74d37793 4506 TCGv t0;
76db3ba4 4507 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4508 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4509 return;
4510 }
74d37793 4511 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4512 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4513 tcg_temp_free(t0);
12de9a39
JM
4514#endif
4515}
4516
4517/* mfsrin */
e8eaa2c0 4518static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4519{
4520#if defined(CONFIG_USER_ONLY)
e06fcd75 4521 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4522#else
74d37793 4523 TCGv t0;
76db3ba4 4524 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4525 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4526 return;
4527 }
74d37793
AJ
4528 t0 = tcg_temp_new();
4529 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4530 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4531 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4532 tcg_temp_free(t0);
12de9a39
JM
4533#endif
4534}
4535
4536/* mtsr */
e8eaa2c0 4537static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4538{
4539#if defined(CONFIG_USER_ONLY)
e06fcd75 4540 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4541#else
74d37793 4542 TCGv t0;
76db3ba4 4543 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4544 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4545 return;
4546 }
74d37793 4547 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4548 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4549 tcg_temp_free(t0);
12de9a39
JM
4550#endif
4551}
4552
4553/* mtsrin */
e8eaa2c0 4554static void gen_mtsrin_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
AJ
4564 t0 = tcg_temp_new();
4565 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4566 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4567 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4568 tcg_temp_free(t0);
12de9a39
JM
4569#endif
4570}
f6b868fc
BS
4571
4572/* slbmte */
e8eaa2c0 4573static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4574{
4575#if defined(CONFIG_USER_ONLY)
4576 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4577#else
4578 if (unlikely(!ctx->mem_idx)) {
4579 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4580 return;
4581 }
c6c7cf05
BS
4582 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4583 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4584#endif
4585}
4586
efdef95f
DG
4587static void gen_slbmfee(DisasContext *ctx)
4588{
4589#if defined(CONFIG_USER_ONLY)
4590 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4591#else
4592 if (unlikely(!ctx->mem_idx)) {
4593 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4594 return;
4595 }
c6c7cf05 4596 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4597 cpu_gpr[rB(ctx->opcode)]);
4598#endif
4599}
4600
4601static void gen_slbmfev(DisasContext *ctx)
4602{
4603#if defined(CONFIG_USER_ONLY)
4604 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4605#else
4606 if (unlikely(!ctx->mem_idx)) {
4607 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4608 return;
4609 }
c6c7cf05 4610 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4611 cpu_gpr[rB(ctx->opcode)]);
4612#endif
4613}
12de9a39
JM
4614#endif /* defined(TARGET_PPC64) */
4615
79aceca5 4616/*** Lookaside buffer management ***/
76db3ba4 4617/* Optional & mem_idx only: */
99e300ef 4618
54623277 4619/* tlbia */
99e300ef 4620static void gen_tlbia(DisasContext *ctx)
79aceca5 4621{
9a64fbe4 4622#if defined(CONFIG_USER_ONLY)
e06fcd75 4623 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4624#else
76db3ba4 4625 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4626 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4627 return;
9a64fbe4 4628 }
c6c7cf05 4629 gen_helper_tlbia(cpu_env);
9a64fbe4 4630#endif
79aceca5
FB
4631}
4632
bf14b1ce 4633/* tlbiel */
99e300ef 4634static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4635{
4636#if defined(CONFIG_USER_ONLY)
4637 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4638#else
4639 if (unlikely(!ctx->mem_idx)) {
4640 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4641 return;
4642 }
c6c7cf05 4643 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4644#endif
4645}
4646
79aceca5 4647/* tlbie */
99e300ef 4648static void gen_tlbie(DisasContext *ctx)
79aceca5 4649{
9a64fbe4 4650#if defined(CONFIG_USER_ONLY)
e06fcd75 4651 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4652#else
76db3ba4 4653 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4654 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4655 return;
9a64fbe4 4656 }
9ca3f7f3 4657 if (NARROW_MODE(ctx)) {
74d37793
AJ
4658 TCGv t0 = tcg_temp_new();
4659 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4660 gen_helper_tlbie(cpu_env, t0);
74d37793 4661 tcg_temp_free(t0);
9ca3f7f3 4662 } else {
c6c7cf05 4663 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4664 }
9a64fbe4 4665#endif
79aceca5
FB
4666}
4667
4668/* tlbsync */
99e300ef 4669static void gen_tlbsync(DisasContext *ctx)
79aceca5 4670{
9a64fbe4 4671#if defined(CONFIG_USER_ONLY)
e06fcd75 4672 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4673#else
76db3ba4 4674 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4675 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4676 return;
9a64fbe4
FB
4677 }
4678 /* This has no effect: it should ensure that all previous
4679 * tlbie have completed
4680 */
e06fcd75 4681 gen_stop_exception(ctx);
9a64fbe4 4682#endif
79aceca5
FB
4683}
4684
426613db
JM
4685#if defined(TARGET_PPC64)
4686/* slbia */
99e300ef 4687static void gen_slbia(DisasContext *ctx)
426613db
JM
4688{
4689#if defined(CONFIG_USER_ONLY)
e06fcd75 4690 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4691#else
76db3ba4 4692 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4693 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4694 return;
4695 }
c6c7cf05 4696 gen_helper_slbia(cpu_env);
426613db
JM
4697#endif
4698}
4699
4700/* slbie */
99e300ef 4701static void gen_slbie(DisasContext *ctx)
426613db
JM
4702{
4703#if defined(CONFIG_USER_ONLY)
e06fcd75 4704 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4705#else
76db3ba4 4706 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4707 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4708 return;
4709 }
c6c7cf05 4710 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4711#endif
4712}
4713#endif
4714
79aceca5
FB
4715/*** External control ***/
4716/* Optional: */
99e300ef 4717
54623277 4718/* eciwx */
99e300ef 4719static void gen_eciwx(DisasContext *ctx)
79aceca5 4720{
76db3ba4 4721 TCGv t0;
fa407c03 4722 /* Should check EAR[E] ! */
76db3ba4
AJ
4723 gen_set_access_type(ctx, ACCESS_EXT);
4724 t0 = tcg_temp_new();
4725 gen_addr_reg_index(ctx, t0);
fa407c03 4726 gen_check_align(ctx, t0, 0x03);
76db3ba4 4727 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4728 tcg_temp_free(t0);
76a66253
JM
4729}
4730
4731/* ecowx */
99e300ef 4732static void gen_ecowx(DisasContext *ctx)
76a66253 4733{
76db3ba4 4734 TCGv t0;
fa407c03 4735 /* Should check EAR[E] ! */
76db3ba4
AJ
4736 gen_set_access_type(ctx, ACCESS_EXT);
4737 t0 = tcg_temp_new();
4738 gen_addr_reg_index(ctx, t0);
fa407c03 4739 gen_check_align(ctx, t0, 0x03);
76db3ba4 4740 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4741 tcg_temp_free(t0);
76a66253
JM
4742}
4743
4744/* PowerPC 601 specific instructions */
99e300ef 4745
54623277 4746/* abs - abs. */
99e300ef 4747static void gen_abs(DisasContext *ctx)
76a66253 4748{
22e0e173
AJ
4749 int l1 = gen_new_label();
4750 int l2 = gen_new_label();
4751 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4752 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4753 tcg_gen_br(l2);
4754 gen_set_label(l1);
4755 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4756 gen_set_label(l2);
76a66253 4757 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4758 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4759}
4760
4761/* abso - abso. */
99e300ef 4762static void gen_abso(DisasContext *ctx)
76a66253 4763{
22e0e173
AJ
4764 int l1 = gen_new_label();
4765 int l2 = gen_new_label();
4766 int l3 = gen_new_label();
4767 /* Start with XER OV disabled, the most likely case */
da91a00f 4768 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4769 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4770 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4771 tcg_gen_movi_tl(cpu_ov, 1);
4772 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4773 tcg_gen_br(l2);
4774 gen_set_label(l1);
4775 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4776 tcg_gen_br(l3);
4777 gen_set_label(l2);
4778 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4779 gen_set_label(l3);
76a66253 4780 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4781 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4782}
4783
4784/* clcs */
99e300ef 4785static void gen_clcs(DisasContext *ctx)
76a66253 4786{
22e0e173 4787 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4788 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4789 tcg_temp_free_i32(t0);
c7697e1f 4790 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
4791}
4792
4793/* div - div. */
99e300ef 4794static void gen_div(DisasContext *ctx)
76a66253 4795{
d15f74fb
BS
4796 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4797 cpu_gpr[rB(ctx->opcode)]);
76a66253 4798 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4799 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4800}
4801
4802/* divo - divo. */
99e300ef 4803static void gen_divo(DisasContext *ctx)
76a66253 4804{
d15f74fb
BS
4805 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4806 cpu_gpr[rB(ctx->opcode)]);
76a66253 4807 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4808 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4809}
4810
4811/* divs - divs. */
99e300ef 4812static void gen_divs(DisasContext *ctx)
76a66253 4813{
d15f74fb
BS
4814 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4815 cpu_gpr[rB(ctx->opcode)]);
76a66253 4816 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4817 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4818}
4819
4820/* divso - divso. */
99e300ef 4821static void gen_divso(DisasContext *ctx)
76a66253 4822{
d15f74fb
BS
4823 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4824 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 4825 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4826 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4827}
4828
4829/* doz - doz. */
99e300ef 4830static void gen_doz(DisasContext *ctx)
76a66253 4831{
22e0e173
AJ
4832 int l1 = gen_new_label();
4833 int l2 = gen_new_label();
4834 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4835 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4836 tcg_gen_br(l2);
4837 gen_set_label(l1);
4838 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4839 gen_set_label(l2);
76a66253 4840 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4841 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4842}
4843
4844/* dozo - dozo. */
99e300ef 4845static void gen_dozo(DisasContext *ctx)
76a66253 4846{
22e0e173
AJ
4847 int l1 = gen_new_label();
4848 int l2 = gen_new_label();
4849 TCGv t0 = tcg_temp_new();
4850 TCGv t1 = tcg_temp_new();
4851 TCGv t2 = tcg_temp_new();
4852 /* Start with XER OV disabled, the most likely case */
da91a00f 4853 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4854 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4855 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4856 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4857 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4858 tcg_gen_andc_tl(t1, t1, t2);
4859 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4860 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
4861 tcg_gen_movi_tl(cpu_ov, 1);
4862 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4863 tcg_gen_br(l2);
4864 gen_set_label(l1);
4865 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4866 gen_set_label(l2);
4867 tcg_temp_free(t0);
4868 tcg_temp_free(t1);
4869 tcg_temp_free(t2);
76a66253 4870 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4871 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4872}
4873
4874/* dozi */
99e300ef 4875static void gen_dozi(DisasContext *ctx)
76a66253 4876{
22e0e173
AJ
4877 target_long simm = SIMM(ctx->opcode);
4878 int l1 = gen_new_label();
4879 int l2 = gen_new_label();
4880 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
4881 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
4882 tcg_gen_br(l2);
4883 gen_set_label(l1);
4884 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4885 gen_set_label(l2);
4886 if (unlikely(Rc(ctx->opcode) != 0))
4887 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4888}
4889
76a66253 4890/* lscbx - lscbx. */
99e300ef 4891static void gen_lscbx(DisasContext *ctx)
76a66253 4892{
bdb4b689
AJ
4893 TCGv t0 = tcg_temp_new();
4894 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
4895 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
4896 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 4897
76db3ba4 4898 gen_addr_reg_index(ctx, t0);
76a66253 4899 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 4900 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 4901 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
4902 tcg_temp_free_i32(t1);
4903 tcg_temp_free_i32(t2);
4904 tcg_temp_free_i32(t3);
3d7b417e 4905 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 4906 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 4907 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
4908 gen_set_Rc0(ctx, t0);
4909 tcg_temp_free(t0);
76a66253
JM
4910}
4911
4912/* maskg - maskg. */
99e300ef 4913static void gen_maskg(DisasContext *ctx)
76a66253 4914{
22e0e173
AJ
4915 int l1 = gen_new_label();
4916 TCGv t0 = tcg_temp_new();
4917 TCGv t1 = tcg_temp_new();
4918 TCGv t2 = tcg_temp_new();
4919 TCGv t3 = tcg_temp_new();
4920 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
4921 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4922 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
4923 tcg_gen_addi_tl(t2, t0, 1);
4924 tcg_gen_shr_tl(t2, t3, t2);
4925 tcg_gen_shr_tl(t3, t3, t1);
4926 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
4927 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
4928 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4929 gen_set_label(l1);
4930 tcg_temp_free(t0);
4931 tcg_temp_free(t1);
4932 tcg_temp_free(t2);
4933 tcg_temp_free(t3);
76a66253 4934 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4935 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4936}
4937
4938/* maskir - maskir. */
99e300ef 4939static void gen_maskir(DisasContext *ctx)
76a66253 4940{
22e0e173
AJ
4941 TCGv t0 = tcg_temp_new();
4942 TCGv t1 = tcg_temp_new();
4943 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4944 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4945 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4946 tcg_temp_free(t0);
4947 tcg_temp_free(t1);
76a66253 4948 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4949 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4950}
4951
4952/* mul - mul. */
99e300ef 4953static void gen_mul(DisasContext *ctx)
76a66253 4954{
22e0e173
AJ
4955 TCGv_i64 t0 = tcg_temp_new_i64();
4956 TCGv_i64 t1 = tcg_temp_new_i64();
4957 TCGv t2 = tcg_temp_new();
4958 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4959 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4960 tcg_gen_mul_i64(t0, t0, t1);
4961 tcg_gen_trunc_i64_tl(t2, t0);
4962 gen_store_spr(SPR_MQ, t2);
4963 tcg_gen_shri_i64(t1, t0, 32);
4964 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4965 tcg_temp_free_i64(t0);
4966 tcg_temp_free_i64(t1);
4967 tcg_temp_free(t2);
76a66253 4968 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4969 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4970}
4971
4972/* mulo - mulo. */
99e300ef 4973static void gen_mulo(DisasContext *ctx)
76a66253 4974{
22e0e173
AJ
4975 int l1 = gen_new_label();
4976 TCGv_i64 t0 = tcg_temp_new_i64();
4977 TCGv_i64 t1 = tcg_temp_new_i64();
4978 TCGv t2 = tcg_temp_new();
4979 /* Start with XER OV disabled, the most likely case */
da91a00f 4980 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4981 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4982 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4983 tcg_gen_mul_i64(t0, t0, t1);
4984 tcg_gen_trunc_i64_tl(t2, t0);
4985 gen_store_spr(SPR_MQ, t2);
4986 tcg_gen_shri_i64(t1, t0, 32);
4987 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4988 tcg_gen_ext32s_i64(t1, t0);
4989 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
4990 tcg_gen_movi_tl(cpu_ov, 1);
4991 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4992 gen_set_label(l1);
4993 tcg_temp_free_i64(t0);
4994 tcg_temp_free_i64(t1);
4995 tcg_temp_free(t2);
76a66253 4996 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4997 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4998}
4999
5000/* nabs - nabs. */
99e300ef 5001static void gen_nabs(DisasContext *ctx)
76a66253 5002{
22e0e173
AJ
5003 int l1 = gen_new_label();
5004 int l2 = gen_new_label();
5005 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5006 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5007 tcg_gen_br(l2);
5008 gen_set_label(l1);
5009 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5010 gen_set_label(l2);
76a66253 5011 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5012 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5013}
5014
5015/* nabso - nabso. */
99e300ef 5016static void gen_nabso(DisasContext *ctx)
76a66253 5017{
22e0e173
AJ
5018 int l1 = gen_new_label();
5019 int l2 = gen_new_label();
5020 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5021 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5022 tcg_gen_br(l2);
5023 gen_set_label(l1);
5024 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5025 gen_set_label(l2);
5026 /* nabs never overflows */
da91a00f 5027 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 5028 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5029 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5030}
5031
5032/* rlmi - rlmi. */
99e300ef 5033static void gen_rlmi(DisasContext *ctx)
76a66253 5034{
7487953d
AJ
5035 uint32_t mb = MB(ctx->opcode);
5036 uint32_t me = ME(ctx->opcode);
5037 TCGv t0 = tcg_temp_new();
5038 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5039 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5040 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5041 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5042 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5043 tcg_temp_free(t0);
76a66253 5044 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5045 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5046}
5047
5048/* rrib - rrib. */
99e300ef 5049static void gen_rrib(DisasContext *ctx)
76a66253 5050{
7487953d
AJ
5051 TCGv t0 = tcg_temp_new();
5052 TCGv t1 = tcg_temp_new();
5053 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5054 tcg_gen_movi_tl(t1, 0x80000000);
5055 tcg_gen_shr_tl(t1, t1, t0);
5056 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5057 tcg_gen_and_tl(t0, t0, t1);
5058 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5059 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5060 tcg_temp_free(t0);
5061 tcg_temp_free(t1);
76a66253 5062 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5063 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5064}
5065
5066/* sle - sle. */
99e300ef 5067static void gen_sle(DisasContext *ctx)
76a66253 5068{
7487953d
AJ
5069 TCGv t0 = tcg_temp_new();
5070 TCGv t1 = tcg_temp_new();
5071 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5072 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5073 tcg_gen_subfi_tl(t1, 32, t1);
5074 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5075 tcg_gen_or_tl(t1, t0, t1);
5076 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5077 gen_store_spr(SPR_MQ, t1);
5078 tcg_temp_free(t0);
5079 tcg_temp_free(t1);
76a66253 5080 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5081 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5082}
5083
5084/* sleq - sleq. */
99e300ef 5085static void gen_sleq(DisasContext *ctx)
76a66253 5086{
7487953d
AJ
5087 TCGv t0 = tcg_temp_new();
5088 TCGv t1 = tcg_temp_new();
5089 TCGv t2 = tcg_temp_new();
5090 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5091 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5092 tcg_gen_shl_tl(t2, t2, t0);
5093 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5094 gen_load_spr(t1, SPR_MQ);
5095 gen_store_spr(SPR_MQ, t0);
5096 tcg_gen_and_tl(t0, t0, t2);
5097 tcg_gen_andc_tl(t1, t1, t2);
5098 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5099 tcg_temp_free(t0);
5100 tcg_temp_free(t1);
5101 tcg_temp_free(t2);
76a66253 5102 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5103 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5104}
5105
5106/* sliq - sliq. */
99e300ef 5107static void gen_sliq(DisasContext *ctx)
76a66253 5108{
7487953d
AJ
5109 int sh = SH(ctx->opcode);
5110 TCGv t0 = tcg_temp_new();
5111 TCGv t1 = tcg_temp_new();
5112 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5113 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5114 tcg_gen_or_tl(t1, t0, t1);
5115 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5116 gen_store_spr(SPR_MQ, t1);
5117 tcg_temp_free(t0);
5118 tcg_temp_free(t1);
76a66253 5119 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5120 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5121}
5122
5123/* slliq - slliq. */
99e300ef 5124static void gen_slliq(DisasContext *ctx)
76a66253 5125{
7487953d
AJ
5126 int sh = SH(ctx->opcode);
5127 TCGv t0 = tcg_temp_new();
5128 TCGv t1 = tcg_temp_new();
5129 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5130 gen_load_spr(t1, SPR_MQ);
5131 gen_store_spr(SPR_MQ, t0);
5132 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5133 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5134 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5135 tcg_temp_free(t0);
5136 tcg_temp_free(t1);
76a66253 5137 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5138 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5139}
5140
5141/* sllq - sllq. */
99e300ef 5142static void gen_sllq(DisasContext *ctx)
76a66253 5143{
7487953d
AJ
5144 int l1 = gen_new_label();
5145 int l2 = gen_new_label();
5146 TCGv t0 = tcg_temp_local_new();
5147 TCGv t1 = tcg_temp_local_new();
5148 TCGv t2 = tcg_temp_local_new();
5149 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5150 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5151 tcg_gen_shl_tl(t1, t1, t2);
5152 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5153 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5154 gen_load_spr(t0, SPR_MQ);
5155 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5156 tcg_gen_br(l2);
5157 gen_set_label(l1);
5158 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5159 gen_load_spr(t2, SPR_MQ);
5160 tcg_gen_andc_tl(t1, t2, t1);
5161 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5162 gen_set_label(l2);
5163 tcg_temp_free(t0);
5164 tcg_temp_free(t1);
5165 tcg_temp_free(t2);
76a66253 5166 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5167 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5168}
5169
5170/* slq - slq. */
99e300ef 5171static void gen_slq(DisasContext *ctx)
76a66253 5172{
7487953d
AJ
5173 int l1 = gen_new_label();
5174 TCGv t0 = tcg_temp_new();
5175 TCGv t1 = tcg_temp_new();
5176 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5177 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5178 tcg_gen_subfi_tl(t1, 32, t1);
5179 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5180 tcg_gen_or_tl(t1, t0, t1);
5181 gen_store_spr(SPR_MQ, t1);
5182 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5183 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5184 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5185 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5186 gen_set_label(l1);
5187 tcg_temp_free(t0);
5188 tcg_temp_free(t1);
76a66253 5189 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5190 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5191}
5192
d9bce9d9 5193/* sraiq - sraiq. */
99e300ef 5194static void gen_sraiq(DisasContext *ctx)
76a66253 5195{
7487953d
AJ
5196 int sh = SH(ctx->opcode);
5197 int l1 = gen_new_label();
5198 TCGv t0 = tcg_temp_new();
5199 TCGv t1 = tcg_temp_new();
5200 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5201 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5202 tcg_gen_or_tl(t0, t0, t1);
5203 gen_store_spr(SPR_MQ, t0);
da91a00f 5204 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5205 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5206 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5207 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5208 gen_set_label(l1);
5209 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5210 tcg_temp_free(t0);
5211 tcg_temp_free(t1);
76a66253 5212 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5213 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5214}
5215
5216/* sraq - sraq. */
99e300ef 5217static void gen_sraq(DisasContext *ctx)
76a66253 5218{
7487953d
AJ
5219 int l1 = gen_new_label();
5220 int l2 = gen_new_label();
5221 TCGv t0 = tcg_temp_new();
5222 TCGv t1 = tcg_temp_local_new();
5223 TCGv t2 = tcg_temp_local_new();
5224 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5225 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5226 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5227 tcg_gen_subfi_tl(t2, 32, t2);
5228 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5229 tcg_gen_or_tl(t0, t0, t2);
5230 gen_store_spr(SPR_MQ, t0);
5231 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5232 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5233 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5234 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5235 gen_set_label(l1);
5236 tcg_temp_free(t0);
5237 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5238 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5239 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5240 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5241 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5242 gen_set_label(l2);
5243 tcg_temp_free(t1);
5244 tcg_temp_free(t2);
76a66253 5245 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5246 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5247}
5248
5249/* sre - sre. */
99e300ef 5250static void gen_sre(DisasContext *ctx)
76a66253 5251{
7487953d
AJ
5252 TCGv t0 = tcg_temp_new();
5253 TCGv t1 = tcg_temp_new();
5254 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5255 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5256 tcg_gen_subfi_tl(t1, 32, t1);
5257 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5258 tcg_gen_or_tl(t1, t0, t1);
5259 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5260 gen_store_spr(SPR_MQ, t1);
5261 tcg_temp_free(t0);
5262 tcg_temp_free(t1);
76a66253 5263 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5264 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5265}
5266
5267/* srea - srea. */
99e300ef 5268static void gen_srea(DisasContext *ctx)
76a66253 5269{
7487953d
AJ
5270 TCGv t0 = tcg_temp_new();
5271 TCGv t1 = tcg_temp_new();
5272 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5273 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5274 gen_store_spr(SPR_MQ, t0);
5275 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5276 tcg_temp_free(t0);
5277 tcg_temp_free(t1);
76a66253 5278 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5279 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5280}
5281
5282/* sreq */
99e300ef 5283static void gen_sreq(DisasContext *ctx)
76a66253 5284{
7487953d
AJ
5285 TCGv t0 = tcg_temp_new();
5286 TCGv t1 = tcg_temp_new();
5287 TCGv t2 = tcg_temp_new();
5288 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5289 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5290 tcg_gen_shr_tl(t1, t1, t0);
5291 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5292 gen_load_spr(t2, SPR_MQ);
5293 gen_store_spr(SPR_MQ, t0);
5294 tcg_gen_and_tl(t0, t0, t1);
5295 tcg_gen_andc_tl(t2, t2, t1);
5296 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5297 tcg_temp_free(t0);
5298 tcg_temp_free(t1);
5299 tcg_temp_free(t2);
76a66253 5300 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5301 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5302}
5303
5304/* sriq */
99e300ef 5305static void gen_sriq(DisasContext *ctx)
76a66253 5306{
7487953d
AJ
5307 int sh = SH(ctx->opcode);
5308 TCGv t0 = tcg_temp_new();
5309 TCGv t1 = tcg_temp_new();
5310 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5311 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5312 tcg_gen_or_tl(t1, t0, t1);
5313 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5314 gen_store_spr(SPR_MQ, t1);
5315 tcg_temp_free(t0);
5316 tcg_temp_free(t1);
76a66253 5317 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5318 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5319}
5320
5321/* srliq */
99e300ef 5322static void gen_srliq(DisasContext *ctx)
76a66253 5323{
7487953d
AJ
5324 int sh = SH(ctx->opcode);
5325 TCGv t0 = tcg_temp_new();
5326 TCGv t1 = tcg_temp_new();
5327 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5328 gen_load_spr(t1, SPR_MQ);
5329 gen_store_spr(SPR_MQ, t0);
5330 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5331 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5332 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5333 tcg_temp_free(t0);
5334 tcg_temp_free(t1);
76a66253 5335 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5336 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5337}
5338
5339/* srlq */
99e300ef 5340static void gen_srlq(DisasContext *ctx)
76a66253 5341{
7487953d
AJ
5342 int l1 = gen_new_label();
5343 int l2 = gen_new_label();
5344 TCGv t0 = tcg_temp_local_new();
5345 TCGv t1 = tcg_temp_local_new();
5346 TCGv t2 = tcg_temp_local_new();
5347 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5348 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5349 tcg_gen_shr_tl(t2, t1, t2);
5350 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5351 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5352 gen_load_spr(t0, SPR_MQ);
5353 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5354 tcg_gen_br(l2);
5355 gen_set_label(l1);
5356 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5357 tcg_gen_and_tl(t0, t0, t2);
5358 gen_load_spr(t1, SPR_MQ);
5359 tcg_gen_andc_tl(t1, t1, t2);
5360 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5361 gen_set_label(l2);
5362 tcg_temp_free(t0);
5363 tcg_temp_free(t1);
5364 tcg_temp_free(t2);
76a66253 5365 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5366 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5367}
5368
5369/* srq */
99e300ef 5370static void gen_srq(DisasContext *ctx)
76a66253 5371{
7487953d
AJ
5372 int l1 = gen_new_label();
5373 TCGv t0 = tcg_temp_new();
5374 TCGv t1 = tcg_temp_new();
5375 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5376 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5377 tcg_gen_subfi_tl(t1, 32, t1);
5378 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5379 tcg_gen_or_tl(t1, t0, t1);
5380 gen_store_spr(SPR_MQ, t1);
5381 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5382 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5383 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5384 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5385 gen_set_label(l1);
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/* PowerPC 602 specific instructions */
99e300ef 5393
54623277 5394/* dsa */
99e300ef 5395static void gen_dsa(DisasContext *ctx)
76a66253
JM
5396{
5397 /* XXX: TODO */
e06fcd75 5398 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5399}
5400
5401/* esa */
99e300ef 5402static void gen_esa(DisasContext *ctx)
76a66253
JM
5403{
5404 /* XXX: TODO */
e06fcd75 5405 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5406}
5407
5408/* mfrom */
99e300ef 5409static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5410{
5411#if defined(CONFIG_USER_ONLY)
e06fcd75 5412 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5413#else
76db3ba4 5414 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5415 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5416 return;
5417 }
cf02a65c 5418 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5419#endif
5420}
5421
5422/* 602 - 603 - G2 TLB management */
e8eaa2c0 5423
54623277 5424/* tlbld */
e8eaa2c0 5425static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5426{
5427#if defined(CONFIG_USER_ONLY)
e06fcd75 5428 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5429#else
76db3ba4 5430 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5431 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5432 return;
5433 }
c6c7cf05 5434 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5435#endif
5436}
5437
5438/* tlbli */
e8eaa2c0 5439static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5440{
5441#if defined(CONFIG_USER_ONLY)
e06fcd75 5442 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5443#else
76db3ba4 5444 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5445 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5446 return;
5447 }
c6c7cf05 5448 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5449#endif
5450}
5451
7dbe11ac 5452/* 74xx TLB management */
e8eaa2c0 5453
54623277 5454/* tlbld */
e8eaa2c0 5455static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5456{
5457#if defined(CONFIG_USER_ONLY)
e06fcd75 5458 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5459#else
76db3ba4 5460 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5461 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5462 return;
5463 }
c6c7cf05 5464 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5465#endif
5466}
5467
5468/* tlbli */
e8eaa2c0 5469static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5470{
5471#if defined(CONFIG_USER_ONLY)
e06fcd75 5472 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5473#else
76db3ba4 5474 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5475 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5476 return;
5477 }
c6c7cf05 5478 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5479#endif
5480}
5481
76a66253 5482/* POWER instructions not in PowerPC 601 */
99e300ef 5483
54623277 5484/* clf */
99e300ef 5485static void gen_clf(DisasContext *ctx)
76a66253
JM
5486{
5487 /* Cache line flush: implemented as no-op */
5488}
5489
5490/* cli */
99e300ef 5491static void gen_cli(DisasContext *ctx)
76a66253 5492{
7f75ffd3 5493 /* Cache line invalidate: privileged and treated as no-op */
76a66253 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 }
5501#endif
5502}
5503
5504/* dclst */
99e300ef 5505static void gen_dclst(DisasContext *ctx)
76a66253
JM
5506{
5507 /* Data cache line store: treated as no-op */
5508}
5509
99e300ef 5510static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5511{
5512#if defined(CONFIG_USER_ONLY)
e06fcd75 5513 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5514#else
74d37793
AJ
5515 int ra = rA(ctx->opcode);
5516 int rd = rD(ctx->opcode);
5517 TCGv t0;
76db3ba4 5518 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5519 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5520 return;
5521 }
74d37793 5522 t0 = tcg_temp_new();
76db3ba4 5523 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5524 tcg_gen_shri_tl(t0, t0, 28);
5525 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5526 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5527 tcg_temp_free(t0);
76a66253 5528 if (ra != 0 && ra != rd)
74d37793 5529 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5530#endif
5531}
5532
99e300ef 5533static void gen_rac(DisasContext *ctx)
76a66253
JM
5534{
5535#if defined(CONFIG_USER_ONLY)
e06fcd75 5536 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5537#else
22e0e173 5538 TCGv t0;
76db3ba4 5539 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5540 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5541 return;
5542 }
22e0e173 5543 t0 = tcg_temp_new();
76db3ba4 5544 gen_addr_reg_index(ctx, t0);
c6c7cf05 5545 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5546 tcg_temp_free(t0);
76a66253
JM
5547#endif
5548}
5549
99e300ef 5550static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5551{
5552#if defined(CONFIG_USER_ONLY)
e06fcd75 5553 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5554#else
76db3ba4 5555 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5556 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5557 return;
5558 }
e5f17ac6 5559 gen_helper_rfsvc(cpu_env);
e06fcd75 5560 gen_sync_exception(ctx);
76a66253
JM
5561#endif
5562}
5563
5564/* svc is not implemented for now */
5565
5566/* POWER2 specific instructions */
5567/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5568
5569/* lfq */
99e300ef 5570static void gen_lfq(DisasContext *ctx)
76a66253 5571{
01a4afeb 5572 int rd = rD(ctx->opcode);
76db3ba4
AJ
5573 TCGv t0;
5574 gen_set_access_type(ctx, ACCESS_FLOAT);
5575 t0 = tcg_temp_new();
5576 gen_addr_imm_index(ctx, t0, 0);
5577 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5578 gen_addr_add(ctx, t0, t0, 8);
5579 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5580 tcg_temp_free(t0);
76a66253
JM
5581}
5582
5583/* lfqu */
99e300ef 5584static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5585{
5586 int ra = rA(ctx->opcode);
01a4afeb 5587 int rd = rD(ctx->opcode);
76db3ba4
AJ
5588 TCGv t0, t1;
5589 gen_set_access_type(ctx, ACCESS_FLOAT);
5590 t0 = tcg_temp_new();
5591 t1 = tcg_temp_new();
5592 gen_addr_imm_index(ctx, t0, 0);
5593 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5594 gen_addr_add(ctx, t1, t0, 8);
5595 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5596 if (ra != 0)
01a4afeb
AJ
5597 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5598 tcg_temp_free(t0);
5599 tcg_temp_free(t1);
76a66253
JM
5600}
5601
5602/* lfqux */
99e300ef 5603static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5604{
5605 int ra = rA(ctx->opcode);
01a4afeb 5606 int rd = rD(ctx->opcode);
76db3ba4
AJ
5607 gen_set_access_type(ctx, ACCESS_FLOAT);
5608 TCGv t0, t1;
5609 t0 = tcg_temp_new();
5610 gen_addr_reg_index(ctx, t0);
5611 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5612 t1 = tcg_temp_new();
5613 gen_addr_add(ctx, t1, t0, 8);
5614 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5615 tcg_temp_free(t1);
76a66253 5616 if (ra != 0)
01a4afeb
AJ
5617 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5618 tcg_temp_free(t0);
76a66253
JM
5619}
5620
5621/* lfqx */
99e300ef 5622static void gen_lfqx(DisasContext *ctx)
76a66253 5623{
01a4afeb 5624 int rd = rD(ctx->opcode);
76db3ba4
AJ
5625 TCGv t0;
5626 gen_set_access_type(ctx, ACCESS_FLOAT);
5627 t0 = tcg_temp_new();
5628 gen_addr_reg_index(ctx, t0);
5629 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5630 gen_addr_add(ctx, t0, t0, 8);
5631 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5632 tcg_temp_free(t0);
76a66253
JM
5633}
5634
5635/* stfq */
99e300ef 5636static void gen_stfq(DisasContext *ctx)
76a66253 5637{
01a4afeb 5638 int rd = rD(ctx->opcode);
76db3ba4
AJ
5639 TCGv t0;
5640 gen_set_access_type(ctx, ACCESS_FLOAT);
5641 t0 = tcg_temp_new();
5642 gen_addr_imm_index(ctx, t0, 0);
5643 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5644 gen_addr_add(ctx, t0, t0, 8);
5645 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5646 tcg_temp_free(t0);
76a66253
JM
5647}
5648
5649/* stfqu */
99e300ef 5650static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5651{
5652 int ra = rA(ctx->opcode);
01a4afeb 5653 int rd = rD(ctx->opcode);
76db3ba4
AJ
5654 TCGv t0, t1;
5655 gen_set_access_type(ctx, ACCESS_FLOAT);
5656 t0 = tcg_temp_new();
5657 gen_addr_imm_index(ctx, t0, 0);
5658 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5659 t1 = tcg_temp_new();
5660 gen_addr_add(ctx, t1, t0, 8);
5661 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5662 tcg_temp_free(t1);
76a66253 5663 if (ra != 0)
01a4afeb
AJ
5664 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5665 tcg_temp_free(t0);
76a66253
JM
5666}
5667
5668/* stfqux */
99e300ef 5669static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5670{
5671 int ra = rA(ctx->opcode);
01a4afeb 5672 int rd = rD(ctx->opcode);
76db3ba4
AJ
5673 TCGv t0, t1;
5674 gen_set_access_type(ctx, ACCESS_FLOAT);
5675 t0 = tcg_temp_new();
5676 gen_addr_reg_index(ctx, t0);
5677 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5678 t1 = tcg_temp_new();
5679 gen_addr_add(ctx, t1, t0, 8);
5680 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5681 tcg_temp_free(t1);
76a66253 5682 if (ra != 0)
01a4afeb
AJ
5683 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5684 tcg_temp_free(t0);
76a66253
JM
5685}
5686
5687/* stfqx */
99e300ef 5688static void gen_stfqx(DisasContext *ctx)
76a66253 5689{
01a4afeb 5690 int rd = rD(ctx->opcode);
76db3ba4
AJ
5691 TCGv t0;
5692 gen_set_access_type(ctx, ACCESS_FLOAT);
5693 t0 = tcg_temp_new();
5694 gen_addr_reg_index(ctx, t0);
5695 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5696 gen_addr_add(ctx, t0, t0, 8);
5697 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5698 tcg_temp_free(t0);
76a66253
JM
5699}
5700
5701/* BookE specific instructions */
99e300ef 5702
54623277 5703/* XXX: not implemented on 440 ? */
99e300ef 5704static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5705{
5706 /* XXX: TODO */
e06fcd75 5707 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5708}
5709
2662a059 5710/* XXX: not implemented on 440 ? */
99e300ef 5711static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5712{
5713#if defined(CONFIG_USER_ONLY)
e06fcd75 5714 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5715#else
74d37793 5716 TCGv t0;
76db3ba4 5717 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5718 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5719 return;
5720 }
ec72e276 5721 t0 = tcg_temp_new();
76db3ba4 5722 gen_addr_reg_index(ctx, t0);
c6c7cf05 5723 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5724 tcg_temp_free(t0);
76a66253
JM
5725#endif
5726}
5727
5728/* All 405 MAC instructions are translated here */
636aa200
BS
5729static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5730 int ra, int rb, int rt, int Rc)
76a66253 5731{
182608d4
AJ
5732 TCGv t0, t1;
5733
a7812ae4
PB
5734 t0 = tcg_temp_local_new();
5735 t1 = tcg_temp_local_new();
182608d4 5736
76a66253
JM
5737 switch (opc3 & 0x0D) {
5738 case 0x05:
5739 /* macchw - macchw. - macchwo - macchwo. */
5740 /* macchws - macchws. - macchwso - macchwso. */
5741 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5742 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5743 /* mulchw - mulchw. */
182608d4
AJ
5744 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5745 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5746 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5747 break;
5748 case 0x04:
5749 /* macchwu - macchwu. - macchwuo - macchwuo. */
5750 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5751 /* mulchwu - mulchwu. */
182608d4
AJ
5752 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5753 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5754 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5755 break;
5756 case 0x01:
5757 /* machhw - machhw. - machhwo - machhwo. */
5758 /* machhws - machhws. - machhwso - machhwso. */
5759 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5760 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5761 /* mulhhw - mulhhw. */
182608d4
AJ
5762 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5763 tcg_gen_ext16s_tl(t0, t0);
5764 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5765 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5766 break;
5767 case 0x00:
5768 /* machhwu - machhwu. - machhwuo - machhwuo. */
5769 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5770 /* mulhhwu - mulhhwu. */
182608d4
AJ
5771 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5772 tcg_gen_ext16u_tl(t0, t0);
5773 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5774 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5775 break;
5776 case 0x0D:
5777 /* maclhw - maclhw. - maclhwo - maclhwo. */
5778 /* maclhws - maclhws. - maclhwso - maclhwso. */
5779 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5780 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5781 /* mullhw - mullhw. */
182608d4
AJ
5782 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5783 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5784 break;
5785 case 0x0C:
5786 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5787 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5788 /* mullhwu - mullhwu. */
182608d4
AJ
5789 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5790 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
5791 break;
5792 }
76a66253 5793 if (opc2 & 0x04) {
182608d4
AJ
5794 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5795 tcg_gen_mul_tl(t1, t0, t1);
5796 if (opc2 & 0x02) {
5797 /* nmultiply-and-accumulate (0x0E) */
5798 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5799 } else {
5800 /* multiply-and-accumulate (0x0C) */
5801 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5802 }
5803
5804 if (opc3 & 0x12) {
5805 /* Check overflow and/or saturate */
5806 int l1 = gen_new_label();
5807
5808 if (opc3 & 0x10) {
5809 /* Start with XER OV disabled, the most likely case */
da91a00f 5810 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
5811 }
5812 if (opc3 & 0x01) {
5813 /* Signed */
5814 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5815 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5816 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5817 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 5818 if (opc3 & 0x02) {
182608d4
AJ
5819 /* Saturate */
5820 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5821 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5822 }
5823 } else {
5824 /* Unsigned */
5825 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 5826 if (opc3 & 0x02) {
182608d4
AJ
5827 /* Saturate */
5828 tcg_gen_movi_tl(t0, UINT32_MAX);
5829 }
5830 }
5831 if (opc3 & 0x10) {
5832 /* Check overflow */
da91a00f
RH
5833 tcg_gen_movi_tl(cpu_ov, 1);
5834 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
5835 }
5836 gen_set_label(l1);
5837 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5838 }
5839 } else {
5840 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 5841 }
182608d4
AJ
5842 tcg_temp_free(t0);
5843 tcg_temp_free(t1);
76a66253
JM
5844 if (unlikely(Rc) != 0) {
5845 /* Update Rc0 */
182608d4 5846 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
5847 }
5848}
5849
a750fc0b 5850#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 5851static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
5852{ \
5853 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5854 rD(ctx->opcode), Rc(ctx->opcode)); \
5855}
5856
5857/* macchw - macchw. */
a750fc0b 5858GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 5859/* macchwo - macchwo. */
a750fc0b 5860GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 5861/* macchws - macchws. */
a750fc0b 5862GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 5863/* macchwso - macchwso. */
a750fc0b 5864GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 5865/* macchwsu - macchwsu. */
a750fc0b 5866GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 5867/* macchwsuo - macchwsuo. */
a750fc0b 5868GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 5869/* macchwu - macchwu. */
a750fc0b 5870GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 5871/* macchwuo - macchwuo. */
a750fc0b 5872GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 5873/* machhw - machhw. */
a750fc0b 5874GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 5875/* machhwo - machhwo. */
a750fc0b 5876GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 5877/* machhws - machhws. */
a750fc0b 5878GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 5879/* machhwso - machhwso. */
a750fc0b 5880GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 5881/* machhwsu - machhwsu. */
a750fc0b 5882GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 5883/* machhwsuo - machhwsuo. */
a750fc0b 5884GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 5885/* machhwu - machhwu. */
a750fc0b 5886GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 5887/* machhwuo - machhwuo. */
a750fc0b 5888GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 5889/* maclhw - maclhw. */
a750fc0b 5890GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 5891/* maclhwo - maclhwo. */
a750fc0b 5892GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 5893/* maclhws - maclhws. */
a750fc0b 5894GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 5895/* maclhwso - maclhwso. */
a750fc0b 5896GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 5897/* maclhwu - maclhwu. */
a750fc0b 5898GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 5899/* maclhwuo - maclhwuo. */
a750fc0b 5900GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 5901/* maclhwsu - maclhwsu. */
a750fc0b 5902GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 5903/* maclhwsuo - maclhwsuo. */
a750fc0b 5904GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 5905/* nmacchw - nmacchw. */
a750fc0b 5906GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 5907/* nmacchwo - nmacchwo. */
a750fc0b 5908GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 5909/* nmacchws - nmacchws. */
a750fc0b 5910GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 5911/* nmacchwso - nmacchwso. */
a750fc0b 5912GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 5913/* nmachhw - nmachhw. */
a750fc0b 5914GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 5915/* nmachhwo - nmachhwo. */
a750fc0b 5916GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 5917/* nmachhws - nmachhws. */
a750fc0b 5918GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 5919/* nmachhwso - nmachhwso. */
a750fc0b 5920GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 5921/* nmaclhw - nmaclhw. */
a750fc0b 5922GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 5923/* nmaclhwo - nmaclhwo. */
a750fc0b 5924GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 5925/* nmaclhws - nmaclhws. */
a750fc0b 5926GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 5927/* nmaclhwso - nmaclhwso. */
a750fc0b 5928GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
5929
5930/* mulchw - mulchw. */
a750fc0b 5931GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 5932/* mulchwu - mulchwu. */
a750fc0b 5933GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 5934/* mulhhw - mulhhw. */
a750fc0b 5935GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 5936/* mulhhwu - mulhhwu. */
a750fc0b 5937GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 5938/* mullhw - mullhw. */
a750fc0b 5939GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 5940/* mullhwu - mullhwu. */
a750fc0b 5941GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
5942
5943/* mfdcr */
99e300ef 5944static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
5945{
5946#if defined(CONFIG_USER_ONLY)
e06fcd75 5947 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 5948#else
06dca6a7 5949 TCGv dcrn;
76db3ba4 5950 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5951 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
5952 return;
5953 }
06dca6a7
AJ
5954 /* NIP cannot be restored if the memory exception comes from an helper */
5955 gen_update_nip(ctx, ctx->nip - 4);
5956 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 5957 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 5958 tcg_temp_free(dcrn);
76a66253
JM
5959#endif
5960}
5961
5962/* mtdcr */
99e300ef 5963static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
5964{
5965#if defined(CONFIG_USER_ONLY)
e06fcd75 5966 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 5967#else
06dca6a7 5968 TCGv dcrn;
76db3ba4 5969 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5970 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
5971 return;
5972 }
06dca6a7
AJ
5973 /* NIP cannot be restored if the memory exception comes from an helper */
5974 gen_update_nip(ctx, ctx->nip - 4);
5975 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 5976 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 5977 tcg_temp_free(dcrn);
a42bd6cc
JM
5978#endif
5979}
5980
5981/* mfdcrx */
2662a059 5982/* XXX: not implemented on 440 ? */
99e300ef 5983static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
5984{
5985#if defined(CONFIG_USER_ONLY)
e06fcd75 5986 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 5987#else
76db3ba4 5988 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5989 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
5990 return;
5991 }
06dca6a7
AJ
5992 /* NIP cannot be restored if the memory exception comes from an helper */
5993 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
5994 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
5995 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 5996 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
5997#endif
5998}
5999
6000/* mtdcrx */
2662a059 6001/* XXX: not implemented on 440 ? */
99e300ef 6002static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
6003{
6004#if defined(CONFIG_USER_ONLY)
e06fcd75 6005 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6006#else
76db3ba4 6007 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6008 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6009 return;
6010 }
06dca6a7
AJ
6011 /* NIP cannot be restored if the memory exception comes from an helper */
6012 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6013 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6014 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 6015 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
6016#endif
6017}
6018
a750fc0b 6019/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6020static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 6021{
06dca6a7
AJ
6022 /* NIP cannot be restored if the memory exception comes from an helper */
6023 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6024 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6025 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
6026 /* Note: Rc update flag set leads to undefined state of Rc0 */
6027}
6028
6029/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6030static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 6031{
06dca6a7
AJ
6032 /* NIP cannot be restored if the memory exception comes from an helper */
6033 gen_update_nip(ctx, ctx->nip - 4);
975e5463 6034 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 6035 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
6036 /* Note: Rc update flag set leads to undefined state of Rc0 */
6037}
6038
76a66253 6039/* dccci */
99e300ef 6040static void gen_dccci(DisasContext *ctx)
76a66253
JM
6041{
6042#if defined(CONFIG_USER_ONLY)
e06fcd75 6043 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6044#else
76db3ba4 6045 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6046 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6047 return;
6048 }
6049 /* interpreted as no-op */
6050#endif
6051}
6052
6053/* dcread */
99e300ef 6054static void gen_dcread(DisasContext *ctx)
76a66253
JM
6055{
6056#if defined(CONFIG_USER_ONLY)
e06fcd75 6057 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6058#else
b61f2753 6059 TCGv EA, val;
76db3ba4 6060 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6061 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6062 return;
6063 }
76db3ba4 6064 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 6065 EA = tcg_temp_new();
76db3ba4 6066 gen_addr_reg_index(ctx, EA);
a7812ae4 6067 val = tcg_temp_new();
76db3ba4 6068 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
6069 tcg_temp_free(val);
6070 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6071 tcg_temp_free(EA);
76a66253
JM
6072#endif
6073}
6074
6075/* icbt */
e8eaa2c0 6076static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6077{
6078 /* interpreted as no-op */
6079 /* XXX: specification say this is treated as a load by the MMU
6080 * but does not generate any exception
6081 */
6082}
6083
6084/* iccci */
99e300ef 6085static void gen_iccci(DisasContext *ctx)
76a66253
JM
6086{
6087#if defined(CONFIG_USER_ONLY)
e06fcd75 6088 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6089#else
76db3ba4 6090 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6091 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6092 return;
6093 }
6094 /* interpreted as no-op */
6095#endif
6096}
6097
6098/* icread */
99e300ef 6099static void gen_icread(DisasContext *ctx)
76a66253
JM
6100{
6101#if defined(CONFIG_USER_ONLY)
e06fcd75 6102 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6103#else
76db3ba4 6104 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6105 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6106 return;
6107 }
6108 /* interpreted as no-op */
6109#endif
6110}
6111
76db3ba4 6112/* rfci (mem_idx only) */
e8eaa2c0 6113static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
6114{
6115#if defined(CONFIG_USER_ONLY)
e06fcd75 6116 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6117#else
76db3ba4 6118 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6119 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6120 return;
6121 }
6122 /* Restore CPU state */
e5f17ac6 6123 gen_helper_40x_rfci(cpu_env);
e06fcd75 6124 gen_sync_exception(ctx);
a42bd6cc
JM
6125#endif
6126}
6127
99e300ef 6128static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6129{
6130#if defined(CONFIG_USER_ONLY)
e06fcd75 6131 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6132#else
76db3ba4 6133 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6134 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6135 return;
6136 }
6137 /* Restore CPU state */
e5f17ac6 6138 gen_helper_rfci(cpu_env);
e06fcd75 6139 gen_sync_exception(ctx);
a42bd6cc
JM
6140#endif
6141}
6142
6143/* BookE specific */
99e300ef 6144
54623277 6145/* XXX: not implemented on 440 ? */
99e300ef 6146static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6147{
6148#if defined(CONFIG_USER_ONLY)
e06fcd75 6149 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6150#else
76db3ba4 6151 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6152 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6153 return;
6154 }
6155 /* Restore CPU state */
e5f17ac6 6156 gen_helper_rfdi(cpu_env);
e06fcd75 6157 gen_sync_exception(ctx);
76a66253
JM
6158#endif
6159}
6160
2662a059 6161/* XXX: not implemented on 440 ? */
99e300ef 6162static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6163{
6164#if defined(CONFIG_USER_ONLY)
e06fcd75 6165 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6166#else
76db3ba4 6167 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6168 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6169 return;
6170 }
6171 /* Restore CPU state */
e5f17ac6 6172 gen_helper_rfmci(cpu_env);
e06fcd75 6173 gen_sync_exception(ctx);
a42bd6cc
JM
6174#endif
6175}
5eb7995e 6176
d9bce9d9 6177/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6178
54623277 6179/* tlbre */
e8eaa2c0 6180static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6181{
6182#if defined(CONFIG_USER_ONLY)
e06fcd75 6183 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6184#else
76db3ba4 6185 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6186 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6187 return;
6188 }
6189 switch (rB(ctx->opcode)) {
6190 case 0:
c6c7cf05
BS
6191 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6192 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6193 break;
6194 case 1:
c6c7cf05
BS
6195 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6196 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6197 break;
6198 default:
e06fcd75 6199 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6200 break;
9a64fbe4 6201 }
76a66253
JM
6202#endif
6203}
6204
d9bce9d9 6205/* tlbsx - tlbsx. */
e8eaa2c0 6206static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6207{
6208#if defined(CONFIG_USER_ONLY)
e06fcd75 6209 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6210#else
74d37793 6211 TCGv t0;
76db3ba4 6212 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6213 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6214 return;
6215 }
74d37793 6216 t0 = tcg_temp_new();
76db3ba4 6217 gen_addr_reg_index(ctx, t0);
c6c7cf05 6218 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6219 tcg_temp_free(t0);
6220 if (Rc(ctx->opcode)) {
6221 int l1 = gen_new_label();
da91a00f 6222 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6223 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6224 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6225 gen_set_label(l1);
6226 }
76a66253 6227#endif
79aceca5
FB
6228}
6229
76a66253 6230/* tlbwe */
e8eaa2c0 6231static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6232{
76a66253 6233#if defined(CONFIG_USER_ONLY)
e06fcd75 6234 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6235#else
76db3ba4 6236 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6237 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6238 return;
6239 }
6240 switch (rB(ctx->opcode)) {
6241 case 0:
c6c7cf05
BS
6242 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6243 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6244 break;
6245 case 1:
c6c7cf05
BS
6246 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6247 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6248 break;
6249 default:
e06fcd75 6250 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6251 break;
9a64fbe4 6252 }
76a66253
JM
6253#endif
6254}
6255
a4bb6c3e 6256/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6257
54623277 6258/* tlbre */
e8eaa2c0 6259static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6260{
6261#if defined(CONFIG_USER_ONLY)
e06fcd75 6262 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6263#else
76db3ba4 6264 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6265 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6266 return;
6267 }
6268 switch (rB(ctx->opcode)) {
6269 case 0:
5eb7995e 6270 case 1:
5eb7995e 6271 case 2:
74d37793
AJ
6272 {
6273 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6274 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6275 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6276 tcg_temp_free_i32(t0);
6277 }
5eb7995e
JM
6278 break;
6279 default:
e06fcd75 6280 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6281 break;
6282 }
6283#endif
6284}
6285
6286/* tlbsx - tlbsx. */
e8eaa2c0 6287static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6288{
6289#if defined(CONFIG_USER_ONLY)
e06fcd75 6290 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6291#else
74d37793 6292 TCGv t0;
76db3ba4 6293 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6294 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6295 return;
6296 }
74d37793 6297 t0 = tcg_temp_new();
76db3ba4 6298 gen_addr_reg_index(ctx, t0);
c6c7cf05 6299 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6300 tcg_temp_free(t0);
6301 if (Rc(ctx->opcode)) {
6302 int l1 = gen_new_label();
da91a00f 6303 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6304 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6305 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6306 gen_set_label(l1);
6307 }
5eb7995e
JM
6308#endif
6309}
6310
6311/* tlbwe */
e8eaa2c0 6312static void gen_tlbwe_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_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6328 cpu_gpr[rS(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
01662f3e
AG
6339/* TLB management - PowerPC BookE 2.06 implementation */
6340
6341/* tlbre */
6342static void gen_tlbre_booke206(DisasContext *ctx)
6343{
6344#if defined(CONFIG_USER_ONLY)
6345 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6346#else
6347 if (unlikely(!ctx->mem_idx)) {
6348 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6349 return;
6350 }
6351
c6c7cf05 6352 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6353#endif
6354}
6355
6356/* tlbsx - tlbsx. */
6357static void gen_tlbsx_booke206(DisasContext *ctx)
6358{
6359#if defined(CONFIG_USER_ONLY)
6360 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6361#else
6362 TCGv t0;
6363 if (unlikely(!ctx->mem_idx)) {
6364 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6365 return;
6366 }
6367
6368 if (rA(ctx->opcode)) {
6369 t0 = tcg_temp_new();
6370 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6371 } else {
6372 t0 = tcg_const_tl(0);
6373 }
6374
6375 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6376 gen_helper_booke206_tlbsx(cpu_env, t0);
01662f3e
AG
6377#endif
6378}
6379
6380/* tlbwe */
6381static void gen_tlbwe_booke206(DisasContext *ctx)
6382{
6383#if defined(CONFIG_USER_ONLY)
6384 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6385#else
6386 if (unlikely(!ctx->mem_idx)) {
6387 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6388 return;
6389 }
3f162d11 6390 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6391 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6392#endif
6393}
6394
6395static void gen_tlbivax_booke206(DisasContext *ctx)
6396{
6397#if defined(CONFIG_USER_ONLY)
6398 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6399#else
6400 TCGv t0;
6401 if (unlikely(!ctx->mem_idx)) {
6402 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6403 return;
6404 }
6405
6406 t0 = tcg_temp_new();
6407 gen_addr_reg_index(ctx, t0);
6408
c6c7cf05 6409 gen_helper_booke206_tlbivax(cpu_env, t0);
01662f3e
AG
6410#endif
6411}
6412
6d3db821
AG
6413static void gen_tlbilx_booke206(DisasContext *ctx)
6414{
6415#if defined(CONFIG_USER_ONLY)
6416 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6417#else
6418 TCGv t0;
6419 if (unlikely(!ctx->mem_idx)) {
6420 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6421 return;
6422 }
6423
6424 t0 = tcg_temp_new();
6425 gen_addr_reg_index(ctx, t0);
6426
6427 switch((ctx->opcode >> 21) & 0x3) {
6428 case 0:
c6c7cf05 6429 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6430 break;
6431 case 1:
c6c7cf05 6432 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6433 break;
6434 case 3:
c6c7cf05 6435 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6436 break;
6437 default:
6438 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6439 break;
6440 }
6441
6442 tcg_temp_free(t0);
6443#endif
6444}
6445
01662f3e 6446
76a66253 6447/* wrtee */
99e300ef 6448static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6449{
6450#if defined(CONFIG_USER_ONLY)
e06fcd75 6451 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6452#else
6527f6ea 6453 TCGv t0;
76db3ba4 6454 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6455 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6456 return;
6457 }
6527f6ea
AJ
6458 t0 = tcg_temp_new();
6459 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6460 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6461 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6462 tcg_temp_free(t0);
dee96f6c
JM
6463 /* Stop translation to have a chance to raise an exception
6464 * if we just set msr_ee to 1
6465 */
e06fcd75 6466 gen_stop_exception(ctx);
76a66253
JM
6467#endif
6468}
6469
6470/* wrteei */
99e300ef 6471static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6472{
6473#if defined(CONFIG_USER_ONLY)
e06fcd75 6474 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6475#else
76db3ba4 6476 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6477 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6478 return;
6479 }
fbe73008 6480 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6481 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6482 /* Stop translation to have a chance to raise an exception */
e06fcd75 6483 gen_stop_exception(ctx);
6527f6ea 6484 } else {
1b6e5f99 6485 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6486 }
76a66253
JM
6487#endif
6488}
6489
08e46e54 6490/* PowerPC 440 specific instructions */
99e300ef 6491
54623277 6492/* dlmzb */
99e300ef 6493static void gen_dlmzb(DisasContext *ctx)
76a66253 6494{
ef0d51af 6495 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6496 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6497 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6498 tcg_temp_free_i32(t0);
76a66253
JM
6499}
6500
6501/* mbar replaces eieio on 440 */
99e300ef 6502static void gen_mbar(DisasContext *ctx)
76a66253
JM
6503{
6504 /* interpreted as no-op */
6505}
6506
6507/* msync replaces sync on 440 */
dcb2b9e1 6508static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6509{
6510 /* interpreted as no-op */
6511}
6512
6513/* icbt */
e8eaa2c0 6514static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6515{
6516 /* interpreted as no-op */
6517 /* XXX: specification say this is treated as a load by the MMU
6518 * but does not generate any exception
6519 */
79aceca5
FB
6520}
6521
9e0b5cb1
AG
6522/* Embedded.Processor Control */
6523
6524static void gen_msgclr(DisasContext *ctx)
6525{
6526#if defined(CONFIG_USER_ONLY)
6527 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6528#else
6529 if (unlikely(ctx->mem_idx == 0)) {
6530 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6531 return;
6532 }
6533
e5f17ac6 6534 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6535#endif
6536}
6537
d5d11a39
AG
6538static void gen_msgsnd(DisasContext *ctx)
6539{
6540#if defined(CONFIG_USER_ONLY)
6541 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6542#else
6543 if (unlikely(ctx->mem_idx == 0)) {
6544 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6545 return;
6546 }
6547
6548 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6549#endif
6550}
6551
a9d9eb8f
JM
6552/*** Altivec vector extension ***/
6553/* Altivec registers moves */
a9d9eb8f 6554
636aa200 6555static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6556{
e4704b3b 6557 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6558 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6559 return r;
6560}
6561
a9d9eb8f 6562#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6563static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6564{ \
fe1e5c53 6565 TCGv EA; \
a9d9eb8f 6566 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6567 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6568 return; \
6569 } \
76db3ba4 6570 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6571 EA = tcg_temp_new(); \
76db3ba4 6572 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6573 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6574 if (ctx->le_mode) { \
6575 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6576 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6577 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6578 } else { \
76db3ba4 6579 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6580 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6581 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6582 } \
6583 tcg_temp_free(EA); \
a9d9eb8f
JM
6584}
6585
6586#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6587static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6588{ \
fe1e5c53 6589 TCGv EA; \
a9d9eb8f 6590 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6591 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6592 return; \
6593 } \
76db3ba4 6594 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6595 EA = tcg_temp_new(); \
76db3ba4 6596 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6597 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6598 if (ctx->le_mode) { \
6599 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6600 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6601 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6602 } else { \
76db3ba4 6603 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6604 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6605 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6606 } \
6607 tcg_temp_free(EA); \
a9d9eb8f
JM
6608}
6609
cbfb6ae9 6610#define GEN_VR_LVE(name, opc2, opc3) \
99e300ef 6611static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6612 { \
6613 TCGv EA; \
6614 TCGv_ptr rs; \
6615 if (unlikely(!ctx->altivec_enabled)) { \
6616 gen_exception(ctx, POWERPC_EXCP_VPU); \
6617 return; \
6618 } \
6619 gen_set_access_type(ctx, ACCESS_INT); \
6620 EA = tcg_temp_new(); \
6621 gen_addr_reg_index(ctx, EA); \
6622 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6623 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6624 tcg_temp_free(EA); \
6625 tcg_temp_free_ptr(rs); \
6626 }
6627
6628#define GEN_VR_STVE(name, opc2, opc3) \
99e300ef 6629static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6630 { \
6631 TCGv EA; \
6632 TCGv_ptr rs; \
6633 if (unlikely(!ctx->altivec_enabled)) { \
6634 gen_exception(ctx, POWERPC_EXCP_VPU); \
6635 return; \
6636 } \
6637 gen_set_access_type(ctx, ACCESS_INT); \
6638 EA = tcg_temp_new(); \
6639 gen_addr_reg_index(ctx, EA); \
6640 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6641 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6642 tcg_temp_free(EA); \
6643 tcg_temp_free_ptr(rs); \
6644 }
6645
fe1e5c53 6646GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6647/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6648GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6649
cbfb6ae9
AJ
6650GEN_VR_LVE(bx, 0x07, 0x00);
6651GEN_VR_LVE(hx, 0x07, 0x01);
6652GEN_VR_LVE(wx, 0x07, 0x02);
6653
fe1e5c53 6654GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6655/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6656GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6657
cbfb6ae9
AJ
6658GEN_VR_STVE(bx, 0x07, 0x04);
6659GEN_VR_STVE(hx, 0x07, 0x05);
6660GEN_VR_STVE(wx, 0x07, 0x06);
6661
99e300ef 6662static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6663{
6664 TCGv_ptr rd;
6665 TCGv EA;
6666 if (unlikely(!ctx->altivec_enabled)) {
6667 gen_exception(ctx, POWERPC_EXCP_VPU);
6668 return;
6669 }
6670 EA = tcg_temp_new();
6671 gen_addr_reg_index(ctx, EA);
6672 rd = gen_avr_ptr(rD(ctx->opcode));
6673 gen_helper_lvsl(rd, EA);
6674 tcg_temp_free(EA);
6675 tcg_temp_free_ptr(rd);
6676}
6677
99e300ef 6678static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6679{
6680 TCGv_ptr rd;
6681 TCGv EA;
6682 if (unlikely(!ctx->altivec_enabled)) {
6683 gen_exception(ctx, POWERPC_EXCP_VPU);
6684 return;
6685 }
6686 EA = tcg_temp_new();
6687 gen_addr_reg_index(ctx, EA);
6688 rd = gen_avr_ptr(rD(ctx->opcode));
6689 gen_helper_lvsr(rd, EA);
6690 tcg_temp_free(EA);
6691 tcg_temp_free_ptr(rd);
6692}
6693
99e300ef 6694static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6695{
6696 TCGv_i32 t;
6697 if (unlikely(!ctx->altivec_enabled)) {
6698 gen_exception(ctx, POWERPC_EXCP_VPU);
6699 return;
6700 }
6701 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6702 t = tcg_temp_new_i32();
1328c2bf 6703 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6704 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6705 tcg_temp_free_i32(t);
785f451b
AJ
6706}
6707
99e300ef 6708static void gen_mtvscr(DisasContext *ctx)
785f451b 6709{
6e87b7c7 6710 TCGv_ptr p;
785f451b
AJ
6711 if (unlikely(!ctx->altivec_enabled)) {
6712 gen_exception(ctx, POWERPC_EXCP_VPU);
6713 return;
6714 }
6e87b7c7 6715 p = gen_avr_ptr(rD(ctx->opcode));
d15f74fb 6716 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6717 tcg_temp_free_ptr(p);
785f451b
AJ
6718}
6719
7a9b96cf
AJ
6720/* Logical operations */
6721#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6722static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6723{ \
6724 if (unlikely(!ctx->altivec_enabled)) { \
6725 gen_exception(ctx, POWERPC_EXCP_VPU); \
6726 return; \
6727 } \
6728 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6729 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6730}
6731
6732GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6733GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6734GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6735GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6736GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6737
8e27dd6f 6738#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6739static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6740{ \
6741 TCGv_ptr ra, rb, rd; \
6742 if (unlikely(!ctx->altivec_enabled)) { \
6743 gen_exception(ctx, POWERPC_EXCP_VPU); \
6744 return; \
6745 } \
6746 ra = gen_avr_ptr(rA(ctx->opcode)); \
6747 rb = gen_avr_ptr(rB(ctx->opcode)); \
6748 rd = gen_avr_ptr(rD(ctx->opcode)); \
6749 gen_helper_##name (rd, ra, rb); \
6750 tcg_temp_free_ptr(ra); \
6751 tcg_temp_free_ptr(rb); \
6752 tcg_temp_free_ptr(rd); \
6753}
6754
d15f74fb
BS
6755#define GEN_VXFORM_ENV(name, opc2, opc3) \
6756static void glue(gen_, name)(DisasContext *ctx) \
6757{ \
6758 TCGv_ptr ra, rb, rd; \
6759 if (unlikely(!ctx->altivec_enabled)) { \
6760 gen_exception(ctx, POWERPC_EXCP_VPU); \
6761 return; \
6762 } \
6763 ra = gen_avr_ptr(rA(ctx->opcode)); \
6764 rb = gen_avr_ptr(rB(ctx->opcode)); \
6765 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6766 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6767 tcg_temp_free_ptr(ra); \
6768 tcg_temp_free_ptr(rb); \
6769 tcg_temp_free_ptr(rd); \
6770}
6771
7872c51c
AJ
6772GEN_VXFORM(vaddubm, 0, 0);
6773GEN_VXFORM(vadduhm, 0, 1);
6774GEN_VXFORM(vadduwm, 0, 2);
6775GEN_VXFORM(vsububm, 0, 16);
6776GEN_VXFORM(vsubuhm, 0, 17);
6777GEN_VXFORM(vsubuwm, 0, 18);
e4039339
AJ
6778GEN_VXFORM(vmaxub, 1, 0);
6779GEN_VXFORM(vmaxuh, 1, 1);
6780GEN_VXFORM(vmaxuw, 1, 2);
6781GEN_VXFORM(vmaxsb, 1, 4);
6782GEN_VXFORM(vmaxsh, 1, 5);
6783GEN_VXFORM(vmaxsw, 1, 6);
6784GEN_VXFORM(vminub, 1, 8);
6785GEN_VXFORM(vminuh, 1, 9);
6786GEN_VXFORM(vminuw, 1, 10);
6787GEN_VXFORM(vminsb, 1, 12);
6788GEN_VXFORM(vminsh, 1, 13);
6789GEN_VXFORM(vminsw, 1, 14);
fab3cbe9
AJ
6790GEN_VXFORM(vavgub, 1, 16);
6791GEN_VXFORM(vavguh, 1, 17);
6792GEN_VXFORM(vavguw, 1, 18);
6793GEN_VXFORM(vavgsb, 1, 20);
6794GEN_VXFORM(vavgsh, 1, 21);
6795GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
6796GEN_VXFORM(vmrghb, 6, 0);
6797GEN_VXFORM(vmrghh, 6, 1);
6798GEN_VXFORM(vmrghw, 6, 2);
6799GEN_VXFORM(vmrglb, 6, 4);
6800GEN_VXFORM(vmrglh, 6, 5);
6801GEN_VXFORM(vmrglw, 6, 6);
2c277908
AJ
6802GEN_VXFORM(vmuloub, 4, 0);
6803GEN_VXFORM(vmulouh, 4, 1);
6804GEN_VXFORM(vmulosb, 4, 4);
6805GEN_VXFORM(vmulosh, 4, 5);
6806GEN_VXFORM(vmuleub, 4, 8);
6807GEN_VXFORM(vmuleuh, 4, 9);
6808GEN_VXFORM(vmulesb, 4, 12);
6809GEN_VXFORM(vmulesh, 4, 13);
d79f0809
AJ
6810GEN_VXFORM(vslb, 2, 4);
6811GEN_VXFORM(vslh, 2, 5);
6812GEN_VXFORM(vslw, 2, 6);
07ef34c3
AJ
6813GEN_VXFORM(vsrb, 2, 8);
6814GEN_VXFORM(vsrh, 2, 9);
6815GEN_VXFORM(vsrw, 2, 10);
6816GEN_VXFORM(vsrab, 2, 12);
6817GEN_VXFORM(vsrah, 2, 13);
6818GEN_VXFORM(vsraw, 2, 14);
7b239bec
AJ
6819GEN_VXFORM(vslo, 6, 16);
6820GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
6821GEN_VXFORM(vaddcuw, 0, 6);
6822GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
6823GEN_VXFORM_ENV(vaddubs, 0, 8);
6824GEN_VXFORM_ENV(vadduhs, 0, 9);
6825GEN_VXFORM_ENV(vadduws, 0, 10);
6826GEN_VXFORM_ENV(vaddsbs, 0, 12);
6827GEN_VXFORM_ENV(vaddshs, 0, 13);
6828GEN_VXFORM_ENV(vaddsws, 0, 14);
6829GEN_VXFORM_ENV(vsububs, 0, 24);
6830GEN_VXFORM_ENV(vsubuhs, 0, 25);
6831GEN_VXFORM_ENV(vsubuws, 0, 26);
6832GEN_VXFORM_ENV(vsubsbs, 0, 28);
6833GEN_VXFORM_ENV(vsubshs, 0, 29);
6834GEN_VXFORM_ENV(vsubsws, 0, 30);
5e1d0985
AJ
6835GEN_VXFORM(vrlb, 2, 0);
6836GEN_VXFORM(vrlh, 2, 1);
6837GEN_VXFORM(vrlw, 2, 2);
d9430add
AJ
6838GEN_VXFORM(vsl, 2, 7);
6839GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
6840GEN_VXFORM_ENV(vpkuhum, 7, 0);
6841GEN_VXFORM_ENV(vpkuwum, 7, 1);
6842GEN_VXFORM_ENV(vpkuhus, 7, 2);
6843GEN_VXFORM_ENV(vpkuwus, 7, 3);
6844GEN_VXFORM_ENV(vpkshus, 7, 4);
6845GEN_VXFORM_ENV(vpkswus, 7, 5);
6846GEN_VXFORM_ENV(vpkshss, 7, 6);
6847GEN_VXFORM_ENV(vpkswss, 7, 7);
1dd9ffb9 6848GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
6849GEN_VXFORM_ENV(vsum4ubs, 4, 24);
6850GEN_VXFORM_ENV(vsum4sbs, 4, 28);
6851GEN_VXFORM_ENV(vsum4shs, 4, 25);
6852GEN_VXFORM_ENV(vsum2sws, 4, 26);
6853GEN_VXFORM_ENV(vsumsws, 4, 30);
6854GEN_VXFORM_ENV(vaddfp, 5, 0);
6855GEN_VXFORM_ENV(vsubfp, 5, 1);
6856GEN_VXFORM_ENV(vmaxfp, 5, 16);
6857GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 6858
0cbcd906 6859#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 6860static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
6861 { \
6862 TCGv_ptr ra, rb, rd; \
6863 if (unlikely(!ctx->altivec_enabled)) { \
6864 gen_exception(ctx, POWERPC_EXCP_VPU); \
6865 return; \
6866 } \
6867 ra = gen_avr_ptr(rA(ctx->opcode)); \
6868 rb = gen_avr_ptr(rB(ctx->opcode)); \
6869 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 6870 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
6871 tcg_temp_free_ptr(ra); \
6872 tcg_temp_free_ptr(rb); \
6873 tcg_temp_free_ptr(rd); \
6874 }
6875
6876#define GEN_VXRFORM(name, opc2, opc3) \
6877 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6878 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6879
1add6e23
AJ
6880GEN_VXRFORM(vcmpequb, 3, 0)
6881GEN_VXRFORM(vcmpequh, 3, 1)
6882GEN_VXRFORM(vcmpequw, 3, 2)
6883GEN_VXRFORM(vcmpgtsb, 3, 12)
6884GEN_VXRFORM(vcmpgtsh, 3, 13)
6885GEN_VXRFORM(vcmpgtsw, 3, 14)
6886GEN_VXRFORM(vcmpgtub, 3, 8)
6887GEN_VXRFORM(vcmpgtuh, 3, 9)
6888GEN_VXRFORM(vcmpgtuw, 3, 10)
819ca121
AJ
6889GEN_VXRFORM(vcmpeqfp, 3, 3)
6890GEN_VXRFORM(vcmpgefp, 3, 7)
6891GEN_VXRFORM(vcmpgtfp, 3, 11)
6892GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 6893
c026766b 6894#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 6895static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
6896 { \
6897 TCGv_ptr rd; \
6898 TCGv_i32 simm; \
6899 if (unlikely(!ctx->altivec_enabled)) { \
6900 gen_exception(ctx, POWERPC_EXCP_VPU); \
6901 return; \
6902 } \
6903 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6904 rd = gen_avr_ptr(rD(ctx->opcode)); \
6905 gen_helper_##name (rd, simm); \
6906 tcg_temp_free_i32(simm); \
6907 tcg_temp_free_ptr(rd); \
6908 }
6909
6910GEN_VXFORM_SIMM(vspltisb, 6, 12);
6911GEN_VXFORM_SIMM(vspltish, 6, 13);
6912GEN_VXFORM_SIMM(vspltisw, 6, 14);
6913
de5f2484 6914#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 6915static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
6916 { \
6917 TCGv_ptr rb, rd; \
6918 if (unlikely(!ctx->altivec_enabled)) { \
6919 gen_exception(ctx, POWERPC_EXCP_VPU); \
6920 return; \
6921 } \
6922 rb = gen_avr_ptr(rB(ctx->opcode)); \
6923 rd = gen_avr_ptr(rD(ctx->opcode)); \
6924 gen_helper_##name (rd, rb); \
6925 tcg_temp_free_ptr(rb); \
6926 tcg_temp_free_ptr(rd); \
6927 }
6928
d15f74fb
BS
6929#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6930static void glue(gen_, name)(DisasContext *ctx) \
6931 { \
6932 TCGv_ptr rb, rd; \
6933 \
6934 if (unlikely(!ctx->altivec_enabled)) { \
6935 gen_exception(ctx, POWERPC_EXCP_VPU); \
6936 return; \
6937 } \
6938 rb = gen_avr_ptr(rB(ctx->opcode)); \
6939 rd = gen_avr_ptr(rD(ctx->opcode)); \
6940 gen_helper_##name(cpu_env, rd, rb); \
6941 tcg_temp_free_ptr(rb); \
6942 tcg_temp_free_ptr(rd); \
6943 }
6944
6cf1c6e5
AJ
6945GEN_VXFORM_NOA(vupkhsb, 7, 8);
6946GEN_VXFORM_NOA(vupkhsh, 7, 9);
6947GEN_VXFORM_NOA(vupklsb, 7, 10);
6948GEN_VXFORM_NOA(vupklsh, 7, 11);
79f85c3a
AJ
6949GEN_VXFORM_NOA(vupkhpx, 7, 13);
6950GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
6951GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
6952GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
6953GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
6954GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
6955GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
6956GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
6957GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
6958GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
79f85c3a 6959
21d21583 6960#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 6961static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
6962 { \
6963 TCGv_ptr rd; \
6964 TCGv_i32 simm; \
6965 if (unlikely(!ctx->altivec_enabled)) { \
6966 gen_exception(ctx, POWERPC_EXCP_VPU); \
6967 return; \
6968 } \
6969 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6970 rd = gen_avr_ptr(rD(ctx->opcode)); \
6971 gen_helper_##name (rd, simm); \
6972 tcg_temp_free_i32(simm); \
6973 tcg_temp_free_ptr(rd); \
6974 }
6975
27a4edb3 6976#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 6977static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
6978 { \
6979 TCGv_ptr rb, rd; \
6980 TCGv_i32 uimm; \
6981 if (unlikely(!ctx->altivec_enabled)) { \
6982 gen_exception(ctx, POWERPC_EXCP_VPU); \
6983 return; \
6984 } \
6985 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6986 rb = gen_avr_ptr(rB(ctx->opcode)); \
6987 rd = gen_avr_ptr(rD(ctx->opcode)); \
6988 gen_helper_##name (rd, rb, uimm); \
6989 tcg_temp_free_i32(uimm); \
6990 tcg_temp_free_ptr(rb); \
6991 tcg_temp_free_ptr(rd); \
6992 }
6993
d15f74fb
BS
6994#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6995static void glue(gen_, name)(DisasContext *ctx) \
6996 { \
6997 TCGv_ptr rb, rd; \
6998 TCGv_i32 uimm; \
6999 \
7000 if (unlikely(!ctx->altivec_enabled)) { \
7001 gen_exception(ctx, POWERPC_EXCP_VPU); \
7002 return; \
7003 } \
7004 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7005 rb = gen_avr_ptr(rB(ctx->opcode)); \
7006 rd = gen_avr_ptr(rD(ctx->opcode)); \
7007 gen_helper_##name(cpu_env, rd, rb, uimm); \
7008 tcg_temp_free_i32(uimm); \
7009 tcg_temp_free_ptr(rb); \
7010 tcg_temp_free_ptr(rd); \
7011 }
7012
e4e6bee7
AJ
7013GEN_VXFORM_UIMM(vspltb, 6, 8);
7014GEN_VXFORM_UIMM(vsplth, 6, 9);
7015GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
7016GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7017GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7018GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7019GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 7020
99e300ef 7021static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
7022{
7023 TCGv_ptr ra, rb, rd;
fce5ecb7 7024 TCGv_i32 sh;
cd633b10
AJ
7025 if (unlikely(!ctx->altivec_enabled)) {
7026 gen_exception(ctx, POWERPC_EXCP_VPU);
7027 return;
7028 }
7029 ra = gen_avr_ptr(rA(ctx->opcode));
7030 rb = gen_avr_ptr(rB(ctx->opcode));
7031 rd = gen_avr_ptr(rD(ctx->opcode));
7032 sh = tcg_const_i32(VSH(ctx->opcode));
7033 gen_helper_vsldoi (rd, ra, rb, sh);
7034 tcg_temp_free_ptr(ra);
7035 tcg_temp_free_ptr(rb);
7036 tcg_temp_free_ptr(rd);
fce5ecb7 7037 tcg_temp_free_i32(sh);
cd633b10
AJ
7038}
7039
707cec33 7040#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 7041static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
7042 { \
7043 TCGv_ptr ra, rb, rc, rd; \
7044 if (unlikely(!ctx->altivec_enabled)) { \
7045 gen_exception(ctx, POWERPC_EXCP_VPU); \
7046 return; \
7047 } \
7048 ra = gen_avr_ptr(rA(ctx->opcode)); \
7049 rb = gen_avr_ptr(rB(ctx->opcode)); \
7050 rc = gen_avr_ptr(rC(ctx->opcode)); \
7051 rd = gen_avr_ptr(rD(ctx->opcode)); \
7052 if (Rc(ctx->opcode)) { \
d15f74fb 7053 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 7054 } else { \
d15f74fb 7055 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
7056 } \
7057 tcg_temp_free_ptr(ra); \
7058 tcg_temp_free_ptr(rb); \
7059 tcg_temp_free_ptr(rc); \
7060 tcg_temp_free_ptr(rd); \
7061 }
7062
b161ae27
AJ
7063GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7064
99e300ef 7065static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
7066{
7067 TCGv_ptr ra, rb, rc, rd;
7068 if (unlikely(!ctx->altivec_enabled)) {
7069 gen_exception(ctx, POWERPC_EXCP_VPU);
7070 return;
7071 }
7072 ra = gen_avr_ptr(rA(ctx->opcode));
7073 rb = gen_avr_ptr(rB(ctx->opcode));
7074 rc = gen_avr_ptr(rC(ctx->opcode));
7075 rd = gen_avr_ptr(rD(ctx->opcode));
7076 gen_helper_vmladduhm(rd, ra, rb, rc);
7077 tcg_temp_free_ptr(ra);
7078 tcg_temp_free_ptr(rb);
7079 tcg_temp_free_ptr(rc);
7080 tcg_temp_free_ptr(rd);
7081}
7082
b04ae981 7083GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7084GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7085GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7086GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7087GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7088
472b24ce
TM
7089/*** VSX extension ***/
7090
7091static inline TCGv_i64 cpu_vsrh(int n)
7092{
7093 if (n < 32) {
7094 return cpu_fpr[n];
7095 } else {
7096 return cpu_avrh[n-32];
7097 }
7098}
7099
7100static inline TCGv_i64 cpu_vsrl(int n)
7101{
7102 if (n < 32) {
7103 return cpu_vsr[n];
7104 } else {
7105 return cpu_avrl[n-32];
7106 }
7107}
7108
e072fe79
TM
7109#define VSX_LOAD_SCALAR(name, operation) \
7110static void gen_##name(DisasContext *ctx) \
7111{ \
7112 TCGv EA; \
7113 if (unlikely(!ctx->vsx_enabled)) { \
7114 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7115 return; \
7116 } \
7117 gen_set_access_type(ctx, ACCESS_INT); \
7118 EA = tcg_temp_new(); \
7119 gen_addr_reg_index(ctx, EA); \
7120 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7121 /* NOTE: cpu_vsrl is undefined */ \
7122 tcg_temp_free(EA); \
7123}
7124
7125VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7126VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7127VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7128VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7129
304af367
TM
7130static void gen_lxvd2x(DisasContext *ctx)
7131{
7132 TCGv EA;
7133 if (unlikely(!ctx->vsx_enabled)) {
7134 gen_exception(ctx, POWERPC_EXCP_VSXU);
7135 return;
7136 }
7137 gen_set_access_type(ctx, ACCESS_INT);
7138 EA = tcg_temp_new();
7139 gen_addr_reg_index(ctx, EA);
7140 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7141 tcg_gen_addi_tl(EA, EA, 8);
7142 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7143 tcg_temp_free(EA);
7144}
7145
ca03b467
TM
7146static void gen_lxvdsx(DisasContext *ctx)
7147{
7148 TCGv EA;
7149 if (unlikely(!ctx->vsx_enabled)) {
7150 gen_exception(ctx, POWERPC_EXCP_VSXU);
7151 return;
7152 }
7153 gen_set_access_type(ctx, ACCESS_INT);
7154 EA = tcg_temp_new();
7155 gen_addr_reg_index(ctx, EA);
7156 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7157 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7158 tcg_temp_free(EA);
7159}
7160
897e61d1
TM
7161static void gen_lxvw4x(DisasContext *ctx)
7162{
f976b09e
AG
7163 TCGv EA;
7164 TCGv_i64 tmp;
897e61d1
TM
7165 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7166 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7167 if (unlikely(!ctx->vsx_enabled)) {
7168 gen_exception(ctx, POWERPC_EXCP_VSXU);
7169 return;
7170 }
7171 gen_set_access_type(ctx, ACCESS_INT);
7172 EA = tcg_temp_new();
f976b09e
AG
7173 tmp = tcg_temp_new_i64();
7174
897e61d1 7175 gen_addr_reg_index(ctx, EA);
f976b09e 7176 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7177 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7178 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7179 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7180
7181 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7182 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7183 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7184 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7185 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7186
7187 tcg_temp_free(EA);
f976b09e 7188 tcg_temp_free_i64(tmp);
897e61d1
TM
7189}
7190
f026da78
TM
7191#define VSX_STORE_SCALAR(name, operation) \
7192static void gen_##name(DisasContext *ctx) \
7193{ \
7194 TCGv EA; \
7195 if (unlikely(!ctx->vsx_enabled)) { \
7196 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7197 return; \
7198 } \
7199 gen_set_access_type(ctx, ACCESS_INT); \
7200 EA = tcg_temp_new(); \
7201 gen_addr_reg_index(ctx, EA); \
7202 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7203 tcg_temp_free(EA); \
9231ba9e
TM
7204}
7205
f026da78 7206VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7207VSX_STORE_SCALAR(stxsiwx, st32_i64)
7208VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7209
fbed2478
TM
7210static void gen_stxvd2x(DisasContext *ctx)
7211{
7212 TCGv EA;
7213 if (unlikely(!ctx->vsx_enabled)) {
7214 gen_exception(ctx, POWERPC_EXCP_VSXU);
7215 return;
7216 }
7217 gen_set_access_type(ctx, ACCESS_INT);
7218 EA = tcg_temp_new();
7219 gen_addr_reg_index(ctx, EA);
7220 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7221 tcg_gen_addi_tl(EA, EA, 8);
7222 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7223 tcg_temp_free(EA);
7224}
7225
86e61ce3
TM
7226static void gen_stxvw4x(DisasContext *ctx)
7227{
f976b09e
AG
7228 TCGv_i64 tmp;
7229 TCGv EA;
86e61ce3
TM
7230 if (unlikely(!ctx->vsx_enabled)) {
7231 gen_exception(ctx, POWERPC_EXCP_VSXU);
7232 return;
7233 }
7234 gen_set_access_type(ctx, ACCESS_INT);
7235 EA = tcg_temp_new();
7236 gen_addr_reg_index(ctx, EA);
f976b09e 7237 tmp = tcg_temp_new_i64();
86e61ce3
TM
7238
7239 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7240 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7241 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7242 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7243
7244 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7245 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7246 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7247 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7248 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7249
7250 tcg_temp_free(EA);
f976b09e 7251 tcg_temp_free_i64(tmp);
86e61ce3
TM
7252}
7253
f5c0f7f9
TM
7254#define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7255static void gen_##name(DisasContext *ctx) \
7256{ \
7257 if (xS(ctx->opcode) < 32) { \
7258 if (unlikely(!ctx->fpu_enabled)) { \
7259 gen_exception(ctx, POWERPC_EXCP_FPU); \
7260 return; \
7261 } \
7262 } else { \
7263 if (unlikely(!ctx->altivec_enabled)) { \
7264 gen_exception(ctx, POWERPC_EXCP_VPU); \
7265 return; \
7266 } \
7267 } \
7268 TCGv_i64 tmp = tcg_temp_new_i64(); \
7269 tcg_gen_##tcgop1(tmp, source); \
7270 tcg_gen_##tcgop2(target, tmp); \
7271 tcg_temp_free_i64(tmp); \
7272}
7273
7274
7275MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7276 cpu_vsrh(xS(ctx->opcode)))
7277MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7278 cpu_gpr[rA(ctx->opcode)])
7279MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7280 cpu_gpr[rA(ctx->opcode)])
7281
7282#if defined(TARGET_PPC64)
7283#define MV_VSRD(name, target, source) \
7284static void gen_##name(DisasContext *ctx) \
7285{ \
7286 if (xS(ctx->opcode) < 32) { \
7287 if (unlikely(!ctx->fpu_enabled)) { \
7288 gen_exception(ctx, POWERPC_EXCP_FPU); \
7289 return; \
7290 } \
7291 } else { \
7292 if (unlikely(!ctx->altivec_enabled)) { \
7293 gen_exception(ctx, POWERPC_EXCP_VPU); \
7294 return; \
7295 } \
7296 } \
7297 tcg_gen_mov_i64(target, source); \
7298}
7299
7300MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7301MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7302
7303#endif
7304
cd73f2c9
TM
7305static void gen_xxpermdi(DisasContext *ctx)
7306{
7307 if (unlikely(!ctx->vsx_enabled)) {
7308 gen_exception(ctx, POWERPC_EXCP_VSXU);
7309 return;
7310 }
7311
7312 if ((DM(ctx->opcode) & 2) == 0) {
7313 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7314 } else {
7315 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7316 }
7317 if ((DM(ctx->opcode) & 1) == 0) {
7318 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7319 } else {
7320 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7321 }
7322}
7323
df020ce0
TM
7324#define OP_ABS 1
7325#define OP_NABS 2
7326#define OP_NEG 3
7327#define OP_CPSGN 4
7328#define SGN_MASK_DP 0x8000000000000000ul
7329#define SGN_MASK_SP 0x8000000080000000ul
7330
7331#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7332static void glue(gen_, name)(DisasContext * ctx) \
7333 { \
7334 TCGv_i64 xb, sgm; \
7335 if (unlikely(!ctx->vsx_enabled)) { \
7336 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7337 return; \
7338 } \
f976b09e
AG
7339 xb = tcg_temp_new_i64(); \
7340 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7341 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7342 tcg_gen_movi_i64(sgm, sgn_mask); \
7343 switch (op) { \
7344 case OP_ABS: { \
7345 tcg_gen_andc_i64(xb, xb, sgm); \
7346 break; \
7347 } \
7348 case OP_NABS: { \
7349 tcg_gen_or_i64(xb, xb, sgm); \
7350 break; \
7351 } \
7352 case OP_NEG: { \
7353 tcg_gen_xor_i64(xb, xb, sgm); \
7354 break; \
7355 } \
7356 case OP_CPSGN: { \
f976b09e 7357 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7358 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7359 tcg_gen_and_i64(xa, xa, sgm); \
7360 tcg_gen_andc_i64(xb, xb, sgm); \
7361 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7362 tcg_temp_free_i64(xa); \
df020ce0
TM
7363 break; \
7364 } \
7365 } \
7366 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7367 tcg_temp_free_i64(xb); \
7368 tcg_temp_free_i64(sgm); \
df020ce0
TM
7369 }
7370
7371VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7372VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7373VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7374VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7375
be574920
TM
7376#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7377static void glue(gen_, name)(DisasContext * ctx) \
7378 { \
7379 TCGv_i64 xbh, xbl, sgm; \
7380 if (unlikely(!ctx->vsx_enabled)) { \
7381 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7382 return; \
7383 } \
f976b09e
AG
7384 xbh = tcg_temp_new_i64(); \
7385 xbl = tcg_temp_new_i64(); \
7386 sgm = tcg_temp_new_i64(); \
be574920
TM
7387 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7388 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7389 tcg_gen_movi_i64(sgm, sgn_mask); \
7390 switch (op) { \
7391 case OP_ABS: { \
7392 tcg_gen_andc_i64(xbh, xbh, sgm); \
7393 tcg_gen_andc_i64(xbl, xbl, sgm); \
7394 break; \
7395 } \
7396 case OP_NABS: { \
7397 tcg_gen_or_i64(xbh, xbh, sgm); \
7398 tcg_gen_or_i64(xbl, xbl, sgm); \
7399 break; \
7400 } \
7401 case OP_NEG: { \
7402 tcg_gen_xor_i64(xbh, xbh, sgm); \
7403 tcg_gen_xor_i64(xbl, xbl, sgm); \
7404 break; \
7405 } \
7406 case OP_CPSGN: { \
f976b09e
AG
7407 TCGv_i64 xah = tcg_temp_new_i64(); \
7408 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7409 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7410 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7411 tcg_gen_and_i64(xah, xah, sgm); \
7412 tcg_gen_and_i64(xal, xal, sgm); \
7413 tcg_gen_andc_i64(xbh, xbh, sgm); \
7414 tcg_gen_andc_i64(xbl, xbl, sgm); \
7415 tcg_gen_or_i64(xbh, xbh, xah); \
7416 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7417 tcg_temp_free_i64(xah); \
7418 tcg_temp_free_i64(xal); \
be574920
TM
7419 break; \
7420 } \
7421 } \
7422 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7423 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7424 tcg_temp_free_i64(xbh); \
7425 tcg_temp_free_i64(xbl); \
7426 tcg_temp_free_i64(sgm); \
be574920
TM
7427 }
7428
7429VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7430VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7431VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7432VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7433VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7434VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7435VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7436VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7437
3c3cbbdc
TM
7438#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7439static void gen_##name(DisasContext * ctx) \
7440{ \
7441 TCGv_i32 opc; \
7442 if (unlikely(!ctx->vsx_enabled)) { \
7443 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7444 return; \
7445 } \
7446 /* NIP cannot be restored if the memory exception comes from an helper */ \
7447 gen_update_nip(ctx, ctx->nip - 4); \
7448 opc = tcg_const_i32(ctx->opcode); \
7449 gen_helper_##name(cpu_env, opc); \
7450 tcg_temp_free_i32(opc); \
7451}
be574920 7452
3d1140bf
TM
7453#define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7454static void gen_##name(DisasContext * ctx) \
7455{ \
7456 if (unlikely(!ctx->vsx_enabled)) { \
7457 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7458 return; \
7459 } \
7460 /* NIP cannot be restored if the exception comes */ \
7461 /* from a helper. */ \
7462 gen_update_nip(ctx, ctx->nip - 4); \
7463 \
7464 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7465 cpu_vsrh(xB(ctx->opcode))); \
7466}
7467
ee6e02c0
TM
7468GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7469GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7470GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7471GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7472GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7473GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7474GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7475GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7476GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7477GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7478GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7479GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7480GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7481GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7482GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7483GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7484GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
7485GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7486GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
7487GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7488GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568 7489GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7ee19fb9 7490GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
ed8ac568 7491GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7ee19fb9 7492GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
5177d2ca
TM
7493GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7494GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
7495GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
7496GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
7497GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
7498GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
7499GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
7500GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
7501GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
7502GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
7503GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
3d1140bf 7504GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
ee6e02c0 7505
3fd0aadf
TM
7506GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
7507GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 7508GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 7509GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 7510GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 7511GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
968e76bc 7512GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
f53f81e0
TM
7513GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
7514GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
7515GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
7516GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
7517GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
7518GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
7519GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
7520GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
74698350
TM
7521GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
7522GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
3fd0aadf 7523
ee6e02c0
TM
7524GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
7525GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 7526GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 7527GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 7528GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 7529GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 7530GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 7531GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 7532GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
7533GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
7534GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
7535GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
7536GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
7537GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
7538GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
7539GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
7540GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
7541GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
7542GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
7543GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
7544GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
7545GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 7546GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
7547GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
7548GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
7549GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
7550GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
7551GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
7552GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
7553GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
7554GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
7555GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
7556GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
7557GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
7558GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
7559GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
7560
7561GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
7562GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 7563GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 7564GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 7565GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 7566GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 7567GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 7568GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 7569GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
7570GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
7571GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
7572GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
7573GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
7574GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
7575GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
7576GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
7577GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
7578GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
7579GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
7580GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
7581GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
7582GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 7583GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
7584GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
7585GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
7586GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
7587GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
7588GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
7589GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
7590GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
7591GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
7592GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
7593GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
7594GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
7595GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
7596GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 7597
79ca8a6a
TM
7598#define VSX_LOGICAL(name, tcg_op) \
7599static void glue(gen_, name)(DisasContext * ctx) \
7600 { \
7601 if (unlikely(!ctx->vsx_enabled)) { \
7602 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7603 return; \
7604 } \
7605 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
7606 cpu_vsrh(xB(ctx->opcode))); \
7607 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
7608 cpu_vsrl(xB(ctx->opcode))); \
7609 }
7610
f976b09e
AG
7611VSX_LOGICAL(xxland, tcg_gen_and_i64)
7612VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
7613VSX_LOGICAL(xxlor, tcg_gen_or_i64)
7614VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
7615VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
67a33f37
TM
7616VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
7617VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
7618VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
df020ce0 7619
ce577d2e
TM
7620#define VSX_XXMRG(name, high) \
7621static void glue(gen_, name)(DisasContext * ctx) \
7622 { \
7623 TCGv_i64 a0, a1, b0, b1; \
7624 if (unlikely(!ctx->vsx_enabled)) { \
7625 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7626 return; \
7627 } \
f976b09e
AG
7628 a0 = tcg_temp_new_i64(); \
7629 a1 = tcg_temp_new_i64(); \
7630 b0 = tcg_temp_new_i64(); \
7631 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
7632 if (high) { \
7633 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
7634 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
7635 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
7636 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
7637 } else { \
7638 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
7639 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
7640 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
7641 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
7642 } \
7643 tcg_gen_shri_i64(a0, a0, 32); \
7644 tcg_gen_shri_i64(b0, b0, 32); \
7645 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
7646 b0, a0, 32, 32); \
7647 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
7648 b1, a1, 32, 32); \
f976b09e
AG
7649 tcg_temp_free_i64(a0); \
7650 tcg_temp_free_i64(a1); \
7651 tcg_temp_free_i64(b0); \
7652 tcg_temp_free_i64(b1); \
ce577d2e
TM
7653 }
7654
7655VSX_XXMRG(xxmrghw, 1)
7656VSX_XXMRG(xxmrglw, 0)
7657
551e3ef7
TM
7658static void gen_xxsel(DisasContext * ctx)
7659{
7660 TCGv_i64 a, b, c;
7661 if (unlikely(!ctx->vsx_enabled)) {
7662 gen_exception(ctx, POWERPC_EXCP_VSXU);
7663 return;
7664 }
f976b09e
AG
7665 a = tcg_temp_new_i64();
7666 b = tcg_temp_new_i64();
7667 c = tcg_temp_new_i64();
551e3ef7
TM
7668
7669 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
7670 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
7671 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
7672
7673 tcg_gen_and_i64(b, b, c);
7674 tcg_gen_andc_i64(a, a, c);
7675 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
7676
7677 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
7678 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
7679 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
7680
7681 tcg_gen_and_i64(b, b, c);
7682 tcg_gen_andc_i64(a, a, c);
7683 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
7684
f976b09e
AG
7685 tcg_temp_free_i64(a);
7686 tcg_temp_free_i64(b);
7687 tcg_temp_free_i64(c);
551e3ef7
TM
7688}
7689
76c15fe0
TM
7690static void gen_xxspltw(DisasContext *ctx)
7691{
7692 TCGv_i64 b, b2;
7693 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
7694 cpu_vsrl(xB(ctx->opcode)) :
7695 cpu_vsrh(xB(ctx->opcode));
7696
7697 if (unlikely(!ctx->vsx_enabled)) {
7698 gen_exception(ctx, POWERPC_EXCP_VSXU);
7699 return;
7700 }
7701
f976b09e
AG
7702 b = tcg_temp_new_i64();
7703 b2 = tcg_temp_new_i64();
76c15fe0
TM
7704
7705 if (UIM(ctx->opcode) & 1) {
7706 tcg_gen_ext32u_i64(b, vsr);
7707 } else {
7708 tcg_gen_shri_i64(b, vsr, 32);
7709 }
7710
7711 tcg_gen_shli_i64(b2, b, 32);
7712 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
7713 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
7714
f976b09e
AG
7715 tcg_temp_free_i64(b);
7716 tcg_temp_free_i64(b2);
76c15fe0
TM
7717}
7718
acc42968
TM
7719static void gen_xxsldwi(DisasContext *ctx)
7720{
7721 TCGv_i64 xth, xtl;
7722 if (unlikely(!ctx->vsx_enabled)) {
7723 gen_exception(ctx, POWERPC_EXCP_VSXU);
7724 return;
7725 }
f976b09e
AG
7726 xth = tcg_temp_new_i64();
7727 xtl = tcg_temp_new_i64();
acc42968
TM
7728
7729 switch (SHW(ctx->opcode)) {
7730 case 0: {
7731 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
7732 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
7733 break;
7734 }
7735 case 1: {
f976b09e 7736 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
7737 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
7738 tcg_gen_shli_i64(xth, xth, 32);
7739 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
7740 tcg_gen_shri_i64(t0, t0, 32);
7741 tcg_gen_or_i64(xth, xth, t0);
7742 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
7743 tcg_gen_shli_i64(xtl, xtl, 32);
7744 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
7745 tcg_gen_shri_i64(t0, t0, 32);
7746 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 7747 tcg_temp_free_i64(t0);
acc42968
TM
7748 break;
7749 }
7750 case 2: {
7751 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
7752 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
7753 break;
7754 }
7755 case 3: {
f976b09e 7756 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
7757 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
7758 tcg_gen_shli_i64(xth, xth, 32);
7759 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
7760 tcg_gen_shri_i64(t0, t0, 32);
7761 tcg_gen_or_i64(xth, xth, t0);
7762 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
7763 tcg_gen_shli_i64(xtl, xtl, 32);
7764 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
7765 tcg_gen_shri_i64(t0, t0, 32);
7766 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 7767 tcg_temp_free_i64(t0);
acc42968
TM
7768 break;
7769 }
7770 }
7771
7772 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
7773 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
7774
f976b09e
AG
7775 tcg_temp_free_i64(xth);
7776 tcg_temp_free_i64(xtl);
acc42968
TM
7777}
7778
ce577d2e 7779
0487d6a8 7780/*** SPE extension ***/
0487d6a8 7781/* Register moves */
3cd7d1dd 7782
a0e13900
FC
7783static inline void gen_evmra(DisasContext *ctx)
7784{
7785
7786 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7787 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
7788 return;
7789 }
7790
7791#if defined(TARGET_PPC64)
7792 /* rD := rA */
7793 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7794
7795 /* spe_acc := rA */
7796 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
7797 cpu_env,
1328c2bf 7798 offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7799#else
7800 TCGv_i64 tmp = tcg_temp_new_i64();
7801
7802 /* tmp := rA_lo + rA_hi << 32 */
7803 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7804
7805 /* spe_acc := tmp */
1328c2bf 7806 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7807 tcg_temp_free_i64(tmp);
7808
7809 /* rD := rA */
7810 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7811 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7812#endif
7813}
7814
636aa200
BS
7815static inline void gen_load_gpr64(TCGv_i64 t, int reg)
7816{
f78fb44e
AJ
7817#if defined(TARGET_PPC64)
7818 tcg_gen_mov_i64(t, cpu_gpr[reg]);
7819#else
36aa55dc 7820 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
3cd7d1dd 7821#endif
f78fb44e 7822}
3cd7d1dd 7823
636aa200
BS
7824static inline void gen_store_gpr64(int reg, TCGv_i64 t)
7825{
f78fb44e
AJ
7826#if defined(TARGET_PPC64)
7827 tcg_gen_mov_i64(cpu_gpr[reg], t);
7828#else
a7812ae4 7829 TCGv_i64 tmp = tcg_temp_new_i64();
f78fb44e 7830 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
f78fb44e
AJ
7831 tcg_gen_shri_i64(tmp, t, 32);
7832 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
a7812ae4 7833 tcg_temp_free_i64(tmp);
3cd7d1dd 7834#endif
f78fb44e 7835}
3cd7d1dd 7836
70560da7 7837#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 7838static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
7839{ \
7840 if (Rc(ctx->opcode)) \
7841 gen_##name1(ctx); \
7842 else \
7843 gen_##name0(ctx); \
7844}
7845
7846/* Handler for undefined SPE opcodes */
636aa200 7847static inline void gen_speundef(DisasContext *ctx)
0487d6a8 7848{
e06fcd75 7849 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
7850}
7851
57951c27
AJ
7852/* SPE logic */
7853#if defined(TARGET_PPC64)
7854#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 7855static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7856{ \
7857 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7858 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7859 return; \
7860 } \
57951c27
AJ
7861 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7862 cpu_gpr[rB(ctx->opcode)]); \
7863}
7864#else
7865#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 7866static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7867{ \
7868 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7869 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7870 return; \
7871 } \
7872 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7873 cpu_gpr[rB(ctx->opcode)]); \
7874 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7875 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 7876}
57951c27
AJ
7877#endif
7878
7879GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
7880GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
7881GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
7882GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
7883GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
7884GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
7885GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
7886GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 7887
57951c27
AJ
7888/* SPE logic immediate */
7889#if defined(TARGET_PPC64)
7890#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 7891static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a
AJ
7892{ \
7893 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7894 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
7895 return; \
7896 } \
a7812ae4
PB
7897 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7898 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7899 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
7900 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7901 tcg_opi(t0, t0, rB(ctx->opcode)); \
7902 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7903 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 7904 tcg_temp_free_i64(t2); \
57951c27
AJ
7905 tcg_opi(t1, t1, rB(ctx->opcode)); \
7906 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
7907 tcg_temp_free_i32(t0); \
7908 tcg_temp_free_i32(t1); \
3d3a6a0a 7909}
57951c27
AJ
7910#else
7911#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 7912static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7913{ \
7914 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7915 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7916 return; \
7917 } \
57951c27
AJ
7918 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7919 rB(ctx->opcode)); \
7920 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7921 rB(ctx->opcode)); \
0487d6a8 7922}
57951c27
AJ
7923#endif
7924GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
7925GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
7926GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
7927GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 7928
57951c27
AJ
7929/* SPE arithmetic */
7930#if defined(TARGET_PPC64)
7931#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 7932static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7933{ \
7934 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7935 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7936 return; \
7937 } \
a7812ae4
PB
7938 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7939 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7940 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
7941 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7942 tcg_op(t0, t0); \
7943 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7944 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 7945 tcg_temp_free_i64(t2); \
57951c27
AJ
7946 tcg_op(t1, t1); \
7947 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
7948 tcg_temp_free_i32(t0); \
7949 tcg_temp_free_i32(t1); \
0487d6a8 7950}
57951c27 7951#else
a7812ae4 7952#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 7953static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7954{ \
7955 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7956 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7957 return; \
7958 } \
7959 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
7960 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
7961}
7962#endif
0487d6a8 7963
636aa200 7964static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27
AJ
7965{
7966 int l1 = gen_new_label();
7967 int l2 = gen_new_label();
0487d6a8 7968
57951c27
AJ
7969 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
7970 tcg_gen_neg_i32(ret, arg1);
7971 tcg_gen_br(l2);
7972 gen_set_label(l1);
a7812ae4 7973 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
7974 gen_set_label(l2);
7975}
7976GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
7977GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
7978GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
7979GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 7980static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 7981{
57951c27
AJ
7982 tcg_gen_addi_i32(ret, arg1, 0x8000);
7983 tcg_gen_ext16u_i32(ret, ret);
7984}
7985GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
7986GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
7987GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 7988
57951c27
AJ
7989#if defined(TARGET_PPC64)
7990#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 7991static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7992{ \
7993 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7994 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7995 return; \
7996 } \
a7812ae4
PB
7997 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7998 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7999 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
501e23c4 8000 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
57951c27
AJ
8001 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8002 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
8003 tcg_op(t0, t0, t2); \
8004 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
8005 tcg_gen_trunc_i64_i32(t1, t3); \
8006 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
8007 tcg_gen_trunc_i64_i32(t2, t3); \
a7812ae4 8008 tcg_temp_free_i64(t3); \
57951c27 8009 tcg_op(t1, t1, t2); \
a7812ae4 8010 tcg_temp_free_i32(t2); \
57951c27 8011 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8012 tcg_temp_free_i32(t0); \
8013 tcg_temp_free_i32(t1); \
0487d6a8 8014}
57951c27
AJ
8015#else
8016#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8017static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
8018{ \
8019 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8020 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8021 return; \
8022 } \
57951c27
AJ
8023 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8024 cpu_gpr[rB(ctx->opcode)]); \
8025 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8026 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8027}
57951c27 8028#endif
0487d6a8 8029
636aa200 8030static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8031{
a7812ae4 8032 TCGv_i32 t0;
57951c27 8033 int l1, l2;
0487d6a8 8034
57951c27
AJ
8035 l1 = gen_new_label();
8036 l2 = gen_new_label();
a7812ae4 8037 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8038 /* No error here: 6 bits are used */
8039 tcg_gen_andi_i32(t0, arg2, 0x3F);
8040 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8041 tcg_gen_shr_i32(ret, arg1, t0);
8042 tcg_gen_br(l2);
8043 gen_set_label(l1);
8044 tcg_gen_movi_i32(ret, 0);
0aef4261 8045 gen_set_label(l2);
a7812ae4 8046 tcg_temp_free_i32(t0);
57951c27
AJ
8047}
8048GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 8049static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8050{
a7812ae4 8051 TCGv_i32 t0;
57951c27
AJ
8052 int l1, l2;
8053
8054 l1 = gen_new_label();
8055 l2 = gen_new_label();
a7812ae4 8056 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8057 /* No error here: 6 bits are used */
8058 tcg_gen_andi_i32(t0, arg2, 0x3F);
8059 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8060 tcg_gen_sar_i32(ret, arg1, t0);
8061 tcg_gen_br(l2);
8062 gen_set_label(l1);
8063 tcg_gen_movi_i32(ret, 0);
0aef4261 8064 gen_set_label(l2);
a7812ae4 8065 tcg_temp_free_i32(t0);
57951c27
AJ
8066}
8067GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 8068static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8069{
a7812ae4 8070 TCGv_i32 t0;
57951c27
AJ
8071 int l1, l2;
8072
8073 l1 = gen_new_label();
8074 l2 = gen_new_label();
a7812ae4 8075 t0 = tcg_temp_local_new_i32();
57951c27
AJ
8076 /* No error here: 6 bits are used */
8077 tcg_gen_andi_i32(t0, arg2, 0x3F);
8078 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8079 tcg_gen_shl_i32(ret, arg1, t0);
8080 tcg_gen_br(l2);
8081 gen_set_label(l1);
8082 tcg_gen_movi_i32(ret, 0);
e29ef9fa 8083 gen_set_label(l2);
a7812ae4 8084 tcg_temp_free_i32(t0);
57951c27
AJ
8085}
8086GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 8087static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8088{
a7812ae4 8089 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
8090 tcg_gen_andi_i32(t0, arg2, 0x1F);
8091 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 8092 tcg_temp_free_i32(t0);
57951c27
AJ
8093}
8094GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 8095static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
8096{
8097 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8098 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8099 return;
8100 }
8101#if defined(TARGET_PPC64)
a7812ae4
PB
8102 TCGv t0 = tcg_temp_new();
8103 TCGv t1 = tcg_temp_new();
57951c27
AJ
8104 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8105 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8106 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8107 tcg_temp_free(t0);
8108 tcg_temp_free(t1);
8109#else
8110 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8111 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8112#endif
8113}
8114GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 8115static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 8116{
57951c27
AJ
8117 tcg_gen_sub_i32(ret, arg2, arg1);
8118}
8119GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 8120
57951c27
AJ
8121/* SPE arithmetic immediate */
8122#if defined(TARGET_PPC64)
8123#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8124static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8125{ \
8126 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8127 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8128 return; \
8129 } \
a7812ae4
PB
8130 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8131 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8132 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8133 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8134 tcg_op(t0, t0, rA(ctx->opcode)); \
8135 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8136 tcg_gen_trunc_i64_i32(t1, t2); \
e06fcd75 8137 tcg_temp_free_i64(t2); \
57951c27
AJ
8138 tcg_op(t1, t1, rA(ctx->opcode)); \
8139 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
8140 tcg_temp_free_i32(t0); \
8141 tcg_temp_free_i32(t1); \
57951c27
AJ
8142}
8143#else
8144#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8145static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8146{ \
8147 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8148 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8149 return; \
8150 } \
8151 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
8152 rA(ctx->opcode)); \
8153 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
8154 rA(ctx->opcode)); \
8155}
8156#endif
8157GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8158GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8159
8160/* SPE comparison */
8161#if defined(TARGET_PPC64)
8162#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8163static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8164{ \
8165 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8166 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8167 return; \
8168 } \
8169 int l1 = gen_new_label(); \
8170 int l2 = gen_new_label(); \
8171 int l3 = gen_new_label(); \
8172 int l4 = gen_new_label(); \
a7812ae4
PB
8173 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8174 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8175 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8176 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8177 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8178 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
a7812ae4 8179 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8180 tcg_gen_br(l2); \
8181 gen_set_label(l1); \
8182 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8183 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8184 gen_set_label(l2); \
8185 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8186 tcg_gen_trunc_i64_i32(t0, t2); \
8187 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8188 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8189 tcg_temp_free_i64(t2); \
57951c27
AJ
8190 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8191 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8192 ~(CRF_CH | CRF_CH_AND_CL)); \
8193 tcg_gen_br(l4); \
8194 gen_set_label(l3); \
8195 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8196 CRF_CH | CRF_CH_OR_CL); \
8197 gen_set_label(l4); \
a7812ae4
PB
8198 tcg_temp_free_i32(t0); \
8199 tcg_temp_free_i32(t1); \
57951c27
AJ
8200}
8201#else
8202#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8203static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8204{ \
8205 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8206 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8207 return; \
8208 } \
8209 int l1 = gen_new_label(); \
8210 int l2 = gen_new_label(); \
8211 int l3 = gen_new_label(); \
8212 int l4 = gen_new_label(); \
8213 \
8214 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8215 cpu_gpr[rB(ctx->opcode)], l1); \
8216 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8217 tcg_gen_br(l2); \
8218 gen_set_label(l1); \
8219 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8220 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8221 gen_set_label(l2); \
8222 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8223 cpu_gprh[rB(ctx->opcode)], l3); \
8224 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8225 ~(CRF_CH | CRF_CH_AND_CL)); \
8226 tcg_gen_br(l4); \
8227 gen_set_label(l3); \
8228 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8229 CRF_CH | CRF_CH_OR_CL); \
8230 gen_set_label(l4); \
8231}
8232#endif
8233GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8234GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8235GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8236GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8237GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8238
8239/* SPE misc */
636aa200 8240static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8241{
8242 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8243 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8244 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8245}
636aa200 8246static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8247{
8248 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8249 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8250 return;
8251 }
8252#if defined(TARGET_PPC64)
a7812ae4
PB
8253 TCGv t0 = tcg_temp_new();
8254 TCGv t1 = tcg_temp_new();
17d9b3af 8255 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8256 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8257 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8258 tcg_temp_free(t0);
8259 tcg_temp_free(t1);
8260#else
57951c27 8261 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8262 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8263#endif
8264}
636aa200 8265static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8266{
8267 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8268 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8269 return;
8270 }
8271#if defined(TARGET_PPC64)
a7812ae4
PB
8272 TCGv t0 = tcg_temp_new();
8273 TCGv t1 = tcg_temp_new();
17d9b3af 8274 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8275 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8276 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8277 tcg_temp_free(t0);
8278 tcg_temp_free(t1);
8279#else
8280 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8281 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8282#endif
8283}
636aa200 8284static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8285{
8286 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8287 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8288 return;
8289 }
8290#if defined(TARGET_PPC64)
a7812ae4
PB
8291 TCGv t0 = tcg_temp_new();
8292 TCGv t1 = tcg_temp_new();
57951c27
AJ
8293 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8294 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8295 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8296 tcg_temp_free(t0);
8297 tcg_temp_free(t1);
8298#else
33890b3e
NF
8299 if (rD(ctx->opcode) == rA(ctx->opcode)) {
8300 TCGv_i32 tmp = tcg_temp_new_i32();
8301 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
8302 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8303 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
8304 tcg_temp_free_i32(tmp);
8305 } else {
8306 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8307 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8308 }
57951c27
AJ
8309#endif
8310}
636aa200 8311static inline void gen_evsplati(DisasContext *ctx)
57951c27 8312{
ae01847f 8313 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8314
57951c27 8315#if defined(TARGET_PPC64)
38d14952 8316 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8317#else
8318 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8319 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8320#endif
8321}
636aa200 8322static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8323{
ae01847f 8324 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8325
57951c27 8326#if defined(TARGET_PPC64)
38d14952 8327 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8328#else
8329 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8330 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8331#endif
0487d6a8
JM
8332}
8333
636aa200 8334static inline void gen_evsel(DisasContext *ctx)
57951c27
AJ
8335{
8336 int l1 = gen_new_label();
8337 int l2 = gen_new_label();
8338 int l3 = gen_new_label();
8339 int l4 = gen_new_label();
a7812ae4 8340 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8341#if defined(TARGET_PPC64)
a7812ae4
PB
8342 TCGv t1 = tcg_temp_local_new();
8343 TCGv t2 = tcg_temp_local_new();
57951c27
AJ
8344#endif
8345 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8346 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
8347#if defined(TARGET_PPC64)
8348 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8349#else
8350 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8351#endif
8352 tcg_gen_br(l2);
8353 gen_set_label(l1);
8354#if defined(TARGET_PPC64)
8355 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8356#else
8357 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8358#endif
8359 gen_set_label(l2);
8360 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8361 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
8362#if defined(TARGET_PPC64)
17d9b3af 8363 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8364#else
8365 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8366#endif
8367 tcg_gen_br(l4);
8368 gen_set_label(l3);
8369#if defined(TARGET_PPC64)
17d9b3af 8370 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8371#else
8372 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8373#endif
8374 gen_set_label(l4);
a7812ae4 8375 tcg_temp_free_i32(t0);
57951c27
AJ
8376#if defined(TARGET_PPC64)
8377 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
8378 tcg_temp_free(t1);
8379 tcg_temp_free(t2);
8380#endif
8381}
e8eaa2c0
BS
8382
8383static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
8384{
8385 gen_evsel(ctx);
8386}
e8eaa2c0
BS
8387
8388static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
8389{
8390 gen_evsel(ctx);
8391}
e8eaa2c0
BS
8392
8393static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
8394{
8395 gen_evsel(ctx);
8396}
e8eaa2c0
BS
8397
8398static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
8399{
8400 gen_evsel(ctx);
8401}
0487d6a8 8402
a0e13900
FC
8403/* Multiply */
8404
8405static inline void gen_evmwumi(DisasContext *ctx)
8406{
8407 TCGv_i64 t0, t1;
8408
8409 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8410 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8411 return;
8412 }
8413
8414 t0 = tcg_temp_new_i64();
8415 t1 = tcg_temp_new_i64();
8416
8417 /* t0 := rA; t1 := rB */
8418#if defined(TARGET_PPC64)
8419 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8420 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8421#else
8422 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8423 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8424#endif
8425
8426 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8427
8428 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8429
8430 tcg_temp_free_i64(t0);
8431 tcg_temp_free_i64(t1);
8432}
8433
8434static inline void gen_evmwumia(DisasContext *ctx)
8435{
8436 TCGv_i64 tmp;
8437
8438 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8439 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8440 return;
8441 }
8442
8443 gen_evmwumi(ctx); /* rD := rA * rB */
8444
8445 tmp = tcg_temp_new_i64();
8446
8447 /* acc := rD */
8448 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8449 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8450 tcg_temp_free_i64(tmp);
8451}
8452
8453static inline void gen_evmwumiaa(DisasContext *ctx)
8454{
8455 TCGv_i64 acc;
8456 TCGv_i64 tmp;
8457
8458 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8459 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8460 return;
8461 }
8462
8463 gen_evmwumi(ctx); /* rD := rA * rB */
8464
8465 acc = tcg_temp_new_i64();
8466 tmp = tcg_temp_new_i64();
8467
8468 /* tmp := rD */
8469 gen_load_gpr64(tmp, rD(ctx->opcode));
8470
8471 /* Load acc */
1328c2bf 8472 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8473
8474 /* acc := tmp + acc */
8475 tcg_gen_add_i64(acc, acc, tmp);
8476
8477 /* Store acc */
1328c2bf 8478 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8479
8480 /* rD := acc */
8481 gen_store_gpr64(rD(ctx->opcode), acc);
8482
8483 tcg_temp_free_i64(acc);
8484 tcg_temp_free_i64(tmp);
8485}
8486
8487static inline void gen_evmwsmi(DisasContext *ctx)
8488{
8489 TCGv_i64 t0, t1;
8490
8491 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8492 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8493 return;
8494 }
8495
8496 t0 = tcg_temp_new_i64();
8497 t1 = tcg_temp_new_i64();
8498
8499 /* t0 := rA; t1 := rB */
8500#if defined(TARGET_PPC64)
8501 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8502 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8503#else
8504 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8505 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8506#endif
8507
8508 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8509
8510 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8511
8512 tcg_temp_free_i64(t0);
8513 tcg_temp_free_i64(t1);
8514}
8515
8516static inline void gen_evmwsmia(DisasContext *ctx)
8517{
8518 TCGv_i64 tmp;
8519
8520 gen_evmwsmi(ctx); /* rD := rA * rB */
8521
8522 tmp = tcg_temp_new_i64();
8523
8524 /* acc := rD */
8525 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8526 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8527
8528 tcg_temp_free_i64(tmp);
8529}
8530
8531static inline void gen_evmwsmiaa(DisasContext *ctx)
8532{
8533 TCGv_i64 acc = tcg_temp_new_i64();
8534 TCGv_i64 tmp = tcg_temp_new_i64();
8535
8536 gen_evmwsmi(ctx); /* rD := rA * rB */
8537
8538 acc = tcg_temp_new_i64();
8539 tmp = tcg_temp_new_i64();
8540
8541 /* tmp := rD */
8542 gen_load_gpr64(tmp, rD(ctx->opcode));
8543
8544 /* Load acc */
1328c2bf 8545 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8546
8547 /* acc := tmp + acc */
8548 tcg_gen_add_i64(acc, acc, tmp);
8549
8550 /* Store acc */
1328c2bf 8551 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8552
8553 /* rD := acc */
8554 gen_store_gpr64(rD(ctx->opcode), acc);
8555
8556 tcg_temp_free_i64(acc);
8557 tcg_temp_free_i64(tmp);
8558}
8559
70560da7
FC
8560GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8561GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8562GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8563GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8564GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8565GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8566GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8567GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
8568GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
8569GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8570GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8571GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8572GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8573GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8574GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8575GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8576GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8577GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8578GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8579GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
8580GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8581GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8582GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
8583GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
8584GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8585GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8586GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8587GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8588GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 8589
6a6ae23f 8590/* SPE load and stores */
636aa200 8591static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
8592{
8593 target_ulong uimm = rB(ctx->opcode);
8594
76db3ba4 8595 if (rA(ctx->opcode) == 0) {
6a6ae23f 8596 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 8597 } else {
6a6ae23f 8598 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 8599 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
8600 tcg_gen_ext32u_tl(EA, EA);
8601 }
76db3ba4 8602 }
0487d6a8 8603}
6a6ae23f 8604
636aa200 8605static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8606{
8607#if defined(TARGET_PPC64)
76db3ba4 8608 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8609#else
8610 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 8611 gen_qemu_ld64(ctx, t0, addr);
6a6ae23f
AJ
8612 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
8613 tcg_gen_shri_i64(t0, t0, 32);
8614 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
8615 tcg_temp_free_i64(t0);
8616#endif
0487d6a8 8617}
6a6ae23f 8618
636aa200 8619static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 8620{
0487d6a8 8621#if defined(TARGET_PPC64)
6a6ae23f 8622 TCGv t0 = tcg_temp_new();
76db3ba4 8623 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f 8624 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
76db3ba4
AJ
8625 gen_addr_add(ctx, addr, addr, 4);
8626 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
8627 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8628 tcg_temp_free(t0);
8629#else
76db3ba4
AJ
8630 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8631 gen_addr_add(ctx, addr, addr, 4);
8632 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f 8633#endif
0487d6a8 8634}
6a6ae23f 8635
636aa200 8636static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8637{
8638 TCGv t0 = tcg_temp_new();
8639#if defined(TARGET_PPC64)
76db3ba4 8640 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8641 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
8642 gen_addr_add(ctx, addr, addr, 2);
8643 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8644 tcg_gen_shli_tl(t0, t0, 32);
8645 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8646 gen_addr_add(ctx, addr, addr, 2);
8647 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8648 tcg_gen_shli_tl(t0, t0, 16);
8649 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8650 gen_addr_add(ctx, addr, addr, 2);
8651 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8652 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 8653#else
76db3ba4 8654 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8655 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8656 gen_addr_add(ctx, addr, addr, 2);
8657 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8658 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
8659 gen_addr_add(ctx, addr, addr, 2);
8660 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8661 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8662 gen_addr_add(ctx, addr, addr, 2);
8663 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8664 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 8665#endif
6a6ae23f 8666 tcg_temp_free(t0);
0487d6a8
JM
8667}
8668
636aa200 8669static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8670{
8671 TCGv t0 = tcg_temp_new();
76db3ba4 8672 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8673#if defined(TARGET_PPC64)
8674 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
8675 tcg_gen_shli_tl(t0, t0, 16);
8676 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8677#else
8678 tcg_gen_shli_tl(t0, t0, 16);
8679 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8680 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8681#endif
8682 tcg_temp_free(t0);
0487d6a8
JM
8683}
8684
636aa200 8685static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8686{
8687 TCGv t0 = tcg_temp_new();
76db3ba4 8688 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8689#if defined(TARGET_PPC64)
8690 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8691 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8692#else
8693 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8694 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8695#endif
8696 tcg_temp_free(t0);
0487d6a8
JM
8697}
8698
636aa200 8699static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8700{
8701 TCGv t0 = tcg_temp_new();
76db3ba4 8702 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
8703#if defined(TARGET_PPC64)
8704 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8705 tcg_gen_ext32u_tl(t0, t0);
8706 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8707#else
8708 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8709 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8710#endif
8711 tcg_temp_free(t0);
8712}
8713
636aa200 8714static inline void gen_op_evlwhe(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, 16);
8723 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8724#else
76db3ba4 8725 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8726 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8727 gen_addr_add(ctx, addr, addr, 2);
8728 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8729 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
8730#endif
8731 tcg_temp_free(t0);
8732}
8733
636aa200 8734static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8735{
8736#if defined(TARGET_PPC64)
8737 TCGv t0 = tcg_temp_new();
76db3ba4
AJ
8738 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
8739 gen_addr_add(ctx, addr, addr, 2);
8740 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8741 tcg_gen_shli_tl(t0, t0, 32);
8742 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8743 tcg_temp_free(t0);
8744#else
76db3ba4
AJ
8745 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8746 gen_addr_add(ctx, addr, addr, 2);
8747 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8748#endif
8749}
8750
636aa200 8751static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8752{
8753#if defined(TARGET_PPC64)
8754 TCGv t0 = tcg_temp_new();
76db3ba4 8755 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f 8756 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8757 gen_addr_add(ctx, addr, addr, 2);
8758 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
8759 tcg_gen_shli_tl(t0, t0, 32);
8760 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8761 tcg_temp_free(t0);
8762#else
76db3ba4
AJ
8763 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8764 gen_addr_add(ctx, addr, addr, 2);
8765 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8766#endif
8767}
8768
636aa200 8769static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8770{
8771 TCGv t0 = tcg_temp_new();
76db3ba4 8772 gen_qemu_ld32u(ctx, t0, addr);
0487d6a8 8773#if defined(TARGET_PPC64)
6a6ae23f
AJ
8774 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8775 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8776#else
8777 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8778 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8779#endif
8780 tcg_temp_free(t0);
8781}
8782
636aa200 8783static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8784{
8785 TCGv t0 = tcg_temp_new();
8786#if defined(TARGET_PPC64)
76db3ba4 8787 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8788 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
8789 tcg_gen_shli_tl(t0, t0, 32);
8790 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8791 gen_addr_add(ctx, addr, addr, 2);
8792 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8793 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8794 tcg_gen_shli_tl(t0, t0, 16);
8795 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8796#else
76db3ba4 8797 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8798 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
8799 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
8800 gen_addr_add(ctx, addr, addr, 2);
8801 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8802 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
8803 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
0487d6a8 8804#endif
6a6ae23f
AJ
8805 tcg_temp_free(t0);
8806}
8807
636aa200 8808static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8809{
8810#if defined(TARGET_PPC64)
76db3ba4 8811 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
0487d6a8 8812#else
6a6ae23f
AJ
8813 TCGv_i64 t0 = tcg_temp_new_i64();
8814 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
76db3ba4 8815 gen_qemu_st64(ctx, t0, addr);
6a6ae23f
AJ
8816 tcg_temp_free_i64(t0);
8817#endif
8818}
8819
636aa200 8820static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 8821{
0487d6a8 8822#if defined(TARGET_PPC64)
6a6ae23f
AJ
8823 TCGv t0 = tcg_temp_new();
8824 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8825 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
8826 tcg_temp_free(t0);
8827#else
76db3ba4 8828 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8829#endif
76db3ba4
AJ
8830 gen_addr_add(ctx, addr, addr, 4);
8831 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8832}
8833
636aa200 8834static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8835{
8836 TCGv t0 = tcg_temp_new();
8837#if defined(TARGET_PPC64)
8838 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
8839#else
8840 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
8841#endif
76db3ba4
AJ
8842 gen_qemu_st16(ctx, t0, addr);
8843 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f
AJ
8844#if defined(TARGET_PPC64)
8845 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8846 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 8847#else
76db3ba4 8848 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8849#endif
76db3ba4 8850 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 8851 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 8852 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 8853 tcg_temp_free(t0);
76db3ba4
AJ
8854 gen_addr_add(ctx, addr, addr, 2);
8855 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8856}
8857
636aa200 8858static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8859{
8860 TCGv t0 = tcg_temp_new();
8861#if defined(TARGET_PPC64)
8862 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
8863#else
8864 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
8865#endif
76db3ba4
AJ
8866 gen_qemu_st16(ctx, t0, addr);
8867 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 8868 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 8869 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
8870 tcg_temp_free(t0);
8871}
8872
636aa200 8873static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8874{
8875#if defined(TARGET_PPC64)
8876 TCGv t0 = tcg_temp_new();
8877 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8878 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
8879 tcg_temp_free(t0);
8880#else
76db3ba4 8881 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8882#endif
76db3ba4
AJ
8883 gen_addr_add(ctx, addr, addr, 2);
8884 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8885}
8886
636aa200 8887static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8888{
8889#if defined(TARGET_PPC64)
8890 TCGv t0 = tcg_temp_new();
8891 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8892 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
8893 tcg_temp_free(t0);
8894#else
76db3ba4 8895 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8896#endif
8897}
8898
636aa200 8899static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 8900{
76db3ba4 8901 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8902}
8903
8904#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 8905static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
8906{ \
8907 TCGv t0; \
8908 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8909 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
8910 return; \
8911 } \
76db3ba4 8912 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
8913 t0 = tcg_temp_new(); \
8914 if (Rc(ctx->opcode)) { \
76db3ba4 8915 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 8916 } else { \
76db3ba4 8917 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
8918 } \
8919 gen_op_##name(ctx, t0); \
8920 tcg_temp_free(t0); \
8921}
8922
8923GEN_SPEOP_LDST(evldd, 0x00, 3);
8924GEN_SPEOP_LDST(evldw, 0x01, 3);
8925GEN_SPEOP_LDST(evldh, 0x02, 3);
8926GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
8927GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
8928GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
8929GEN_SPEOP_LDST(evlwhe, 0x08, 2);
8930GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
8931GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
8932GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
8933GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
8934
8935GEN_SPEOP_LDST(evstdd, 0x10, 3);
8936GEN_SPEOP_LDST(evstdw, 0x11, 3);
8937GEN_SPEOP_LDST(evstdh, 0x12, 3);
8938GEN_SPEOP_LDST(evstwhe, 0x18, 2);
8939GEN_SPEOP_LDST(evstwho, 0x1A, 2);
8940GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
8941GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
8942
8943/* Multiply and add - TODO */
8944#if 0
70560da7
FC
8945GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
8946GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8947GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8948GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8949GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8950GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8951GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8952GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8953GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8954GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8955GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8956GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8957
8958GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8959GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8960GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8961GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8962GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8963GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8964GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8965GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8966GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8967GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8968GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8969GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8970
8971GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8972GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8973GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8974GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8975GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
8976
8977GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8978GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8979GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8980GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8981GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8982GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8983GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8984GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8985GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8986GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8987GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8988GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8989
8990GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8991GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8992GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8993GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8994
8995GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8996GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8997GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8998GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8999GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9000GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9001GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9002GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9003GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9004GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9005GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9006GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9007
9008GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9009GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9010GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9011GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9012GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
9013#endif
9014
9015/*** SPE floating-point extension ***/
1c97856d
AJ
9016#if defined(TARGET_PPC64)
9017#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9018static inline void gen_##name(DisasContext *ctx) \
0487d6a8 9019{ \
1c97856d
AJ
9020 TCGv_i32 t0; \
9021 TCGv t1; \
9022 t0 = tcg_temp_new_i32(); \
9023 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9024 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9025 t1 = tcg_temp_new(); \
9026 tcg_gen_extu_i32_tl(t1, t0); \
9027 tcg_temp_free_i32(t0); \
9028 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9029 0xFFFFFFFF00000000ULL); \
9030 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9031 tcg_temp_free(t1); \
0487d6a8 9032}
1c97856d 9033#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9034static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9035{ \
9036 TCGv_i32 t0; \
9037 TCGv t1; \
9038 t0 = tcg_temp_new_i32(); \
8e703949 9039 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9040 t1 = tcg_temp_new(); \
9041 tcg_gen_extu_i32_tl(t1, t0); \
9042 tcg_temp_free_i32(t0); \
9043 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9044 0xFFFFFFFF00000000ULL); \
9045 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9046 tcg_temp_free(t1); \
9047}
9048#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9049static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9050{ \
9051 TCGv_i32 t0 = tcg_temp_new_i32(); \
9052 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9053 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9054 tcg_temp_free_i32(t0); \
9055}
9056#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9057static inline void gen_##name(DisasContext *ctx) \
1c97856d 9058{ \
8e703949
BS
9059 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9060 cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9061}
9062#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9063static inline void gen_##name(DisasContext *ctx) \
57951c27 9064{ \
1c97856d
AJ
9065 TCGv_i32 t0, t1; \
9066 TCGv_i64 t2; \
57951c27 9067 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9068 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9069 return; \
9070 } \
1c97856d
AJ
9071 t0 = tcg_temp_new_i32(); \
9072 t1 = tcg_temp_new_i32(); \
9073 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9074 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9075 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9076 tcg_temp_free_i32(t1); \
9077 t2 = tcg_temp_new(); \
9078 tcg_gen_extu_i32_tl(t2, t0); \
9079 tcg_temp_free_i32(t0); \
9080 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9081 0xFFFFFFFF00000000ULL); \
9082 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
9083 tcg_temp_free(t2); \
57951c27 9084}
1c97856d 9085#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9086static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
9087{ \
9088 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9089 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9090 return; \
9091 } \
8e703949
BS
9092 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9093 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
57951c27 9094}
1c97856d 9095#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9096static inline void gen_##name(DisasContext *ctx) \
57951c27 9097{ \
1c97856d 9098 TCGv_i32 t0, t1; \
57951c27 9099 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9100 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
9101 return; \
9102 } \
1c97856d
AJ
9103 t0 = tcg_temp_new_i32(); \
9104 t1 = tcg_temp_new_i32(); \
9105 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9106 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 9107 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9108 tcg_temp_free_i32(t0); \
9109 tcg_temp_free_i32(t1); \
9110}
9111#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9112static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9113{ \
9114 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9115 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9116 return; \
9117 } \
8e703949 9118 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9119 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9120}
9121#else
9122#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9123static inline void gen_##name(DisasContext *ctx) \
1c97856d 9124{ \
8e703949
BS
9125 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9126 cpu_gpr[rB(ctx->opcode)]); \
57951c27 9127}
1c97856d 9128#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9129static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9130{ \
9131 TCGv_i64 t0 = tcg_temp_new_i64(); \
9132 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9133 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
9134 tcg_temp_free_i64(t0); \
9135}
9136#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9137static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9138{ \
9139 TCGv_i64 t0 = tcg_temp_new_i64(); \
8e703949 9140 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
9141 gen_store_gpr64(rD(ctx->opcode), t0); \
9142 tcg_temp_free_i64(t0); \
9143}
9144#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9145static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9146{ \
9147 TCGv_i64 t0 = tcg_temp_new_i64(); \
9148 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9149 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9150 gen_store_gpr64(rD(ctx->opcode), t0); \
9151 tcg_temp_free_i64(t0); \
9152}
9153#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9154static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9155{ \
9156 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9157 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9158 return; \
9159 } \
8e703949 9160 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9161 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9162}
9163#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9164static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9165{ \
9166 TCGv_i64 t0, t1; \
9167 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9168 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9169 return; \
9170 } \
9171 t0 = tcg_temp_new_i64(); \
9172 t1 = tcg_temp_new_i64(); \
9173 gen_load_gpr64(t0, rA(ctx->opcode)); \
9174 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9175 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9176 gen_store_gpr64(rD(ctx->opcode), t0); \
9177 tcg_temp_free_i64(t0); \
9178 tcg_temp_free_i64(t1); \
9179}
9180#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9181static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9182{ \
9183 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9184 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9185 return; \
9186 } \
8e703949 9187 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9188 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9189}
9190#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9191static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9192{ \
9193 TCGv_i64 t0, t1; \
9194 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9195 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9196 return; \
9197 } \
9198 t0 = tcg_temp_new_i64(); \
9199 t1 = tcg_temp_new_i64(); \
9200 gen_load_gpr64(t0, rA(ctx->opcode)); \
9201 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9202 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9203 tcg_temp_free_i64(t0); \
9204 tcg_temp_free_i64(t1); \
9205}
9206#endif
57951c27 9207
0487d6a8
JM
9208/* Single precision floating-point vectors operations */
9209/* Arithmetic */
1c97856d
AJ
9210GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9211GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9212GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9213GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9214static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9215{
9216 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9217 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9218 return;
9219 }
9220#if defined(TARGET_PPC64)
6d5c34fa 9221 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
1c97856d 9222#else
6d5c34fa
MP
9223 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
9224 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9225#endif
9226}
636aa200 9227static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9228{
9229 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9230 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9231 return;
9232 }
9233#if defined(TARGET_PPC64)
6d5c34fa 9234 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9235#else
6d5c34fa
MP
9236 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9237 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9238#endif
9239}
636aa200 9240static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9241{
9242 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9243 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9244 return;
9245 }
9246#if defined(TARGET_PPC64)
6d5c34fa 9247 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9248#else
6d5c34fa
MP
9249 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9250 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9251#endif
9252}
9253
0487d6a8 9254/* Conversion */
1c97856d
AJ
9255GEN_SPEFPUOP_CONV_64_64(evfscfui);
9256GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9257GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9258GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9259GEN_SPEFPUOP_CONV_64_64(evfsctui);
9260GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9261GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9262GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9263GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9264GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9265
0487d6a8 9266/* Comparison */
1c97856d
AJ
9267GEN_SPEFPUOP_COMP_64(evfscmpgt);
9268GEN_SPEFPUOP_COMP_64(evfscmplt);
9269GEN_SPEFPUOP_COMP_64(evfscmpeq);
9270GEN_SPEFPUOP_COMP_64(evfststgt);
9271GEN_SPEFPUOP_COMP_64(evfststlt);
9272GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9273
9274/* Opcodes definitions */
70560da7
FC
9275GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9276GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9277GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9278GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9279GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9280GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9281GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9282GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9283GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9284GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9285GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9286GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9287GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9288GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9289
9290/* Single precision floating-point operations */
9291/* Arithmetic */
1c97856d
AJ
9292GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9293GEN_SPEFPUOP_ARITH2_32_32(efssub);
9294GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9295GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9296static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9297{
9298 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9299 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9300 return;
9301 }
6d5c34fa 9302 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9303}
636aa200 9304static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9305{
9306 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9307 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9308 return;
9309 }
6d5c34fa 9310 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9311}
636aa200 9312static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9313{
9314 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9315 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9316 return;
9317 }
6d5c34fa 9318 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9319}
9320
0487d6a8 9321/* Conversion */
1c97856d
AJ
9322GEN_SPEFPUOP_CONV_32_32(efscfui);
9323GEN_SPEFPUOP_CONV_32_32(efscfsi);
9324GEN_SPEFPUOP_CONV_32_32(efscfuf);
9325GEN_SPEFPUOP_CONV_32_32(efscfsf);
9326GEN_SPEFPUOP_CONV_32_32(efsctui);
9327GEN_SPEFPUOP_CONV_32_32(efsctsi);
9328GEN_SPEFPUOP_CONV_32_32(efsctuf);
9329GEN_SPEFPUOP_CONV_32_32(efsctsf);
9330GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9331GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9332GEN_SPEFPUOP_CONV_32_64(efscfd);
9333
0487d6a8 9334/* Comparison */
1c97856d
AJ
9335GEN_SPEFPUOP_COMP_32(efscmpgt);
9336GEN_SPEFPUOP_COMP_32(efscmplt);
9337GEN_SPEFPUOP_COMP_32(efscmpeq);
9338GEN_SPEFPUOP_COMP_32(efststgt);
9339GEN_SPEFPUOP_COMP_32(efststlt);
9340GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9341
9342/* Opcodes definitions */
70560da7
FC
9343GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9344GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9345GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9346GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9347GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9348GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9349GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9350GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9351GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9352GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9353GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9354GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9355GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9356GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9357
9358/* Double precision floating-point operations */
9359/* Arithmetic */
1c97856d
AJ
9360GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9361GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9362GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9363GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9364static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9365{
9366 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9367 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9368 return;
9369 }
9370#if defined(TARGET_PPC64)
6d5c34fa 9371 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
1c97856d 9372#else
6d5c34fa
MP
9373 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9374 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9375#endif
9376}
636aa200 9377static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
9378{
9379 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9380 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9381 return;
9382 }
9383#if defined(TARGET_PPC64)
6d5c34fa 9384 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9385#else
6d5c34fa
MP
9386 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9387 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9388#endif
9389}
636aa200 9390static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
9391{
9392 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9393 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9394 return;
9395 }
9396#if defined(TARGET_PPC64)
6d5c34fa 9397 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9398#else
6d5c34fa
MP
9399 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9400 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9401#endif
9402}
9403
0487d6a8 9404/* Conversion */
1c97856d
AJ
9405GEN_SPEFPUOP_CONV_64_32(efdcfui);
9406GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9407GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9408GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9409GEN_SPEFPUOP_CONV_32_64(efdctui);
9410GEN_SPEFPUOP_CONV_32_64(efdctsi);
9411GEN_SPEFPUOP_CONV_32_64(efdctuf);
9412GEN_SPEFPUOP_CONV_32_64(efdctsf);
9413GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9414GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9415GEN_SPEFPUOP_CONV_64_32(efdcfs);
9416GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9417GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9418GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9419GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 9420
0487d6a8 9421/* Comparison */
1c97856d
AJ
9422GEN_SPEFPUOP_COMP_64(efdcmpgt);
9423GEN_SPEFPUOP_COMP_64(efdcmplt);
9424GEN_SPEFPUOP_COMP_64(efdcmpeq);
9425GEN_SPEFPUOP_COMP_64(efdtstgt);
9426GEN_SPEFPUOP_COMP_64(efdtstlt);
9427GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
9428
9429/* Opcodes definitions */
70560da7
FC
9430GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9431GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9432GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9433GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9434GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9435GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9436GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9437GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9438GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9439GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9440GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9441GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9442GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9443GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9444GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9445GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 9446
c227f099 9447static opcode_t opcodes[] = {
5c55ff99
BS
9448GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9449GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9450GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9451GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9452GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 9453GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9454GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9455GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9456GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9457GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9458GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9459GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9460GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9461GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9462GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9463GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9464#if defined(TARGET_PPC64)
9465GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9466#endif
9467GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9468GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9469GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9470GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9471GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9472GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9473GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9474GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9475GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9476GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9477GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9478GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9479GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 9480GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 9481GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 9482#if defined(TARGET_PPC64)
eaabeef2 9483GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 9484GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 9485GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
86ba37ed 9486GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
5c55ff99
BS
9487#endif
9488GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9489GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9490GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9491GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9492GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9493GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9494GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9495#if defined(TARGET_PPC64)
9496GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9497GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9498GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9499GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9500GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9501#endif
9502GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9503GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9504GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9505GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9506GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 9507GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 9508GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
9509GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9510GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 9511GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
097ec5d8
TM
9512GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
9513GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
5c55ff99
BS
9514GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9515GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9516GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9517GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
9518GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9519GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
9520#if defined(TARGET_PPC64)
9521GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9522GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9523GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9524#endif
9525GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9526GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9527GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9528GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9529GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9530GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9531GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9532GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
5c77a786
TM
9533GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9534GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
f844c817 9535GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
587c51f7
TM
9536GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9537GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
5c55ff99
BS
9538GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9539#if defined(TARGET_PPC64)
f844c817 9540GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
5c55ff99
BS
9541GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
9542#endif
9543GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9544GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9545GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9546GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9547GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9548GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
9549GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9550GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9551#if defined(TARGET_PPC64)
9552GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9553GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9554#endif
9555GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9556GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9557GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9558#if defined(TARGET_PPC64)
9559GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9560GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9561#endif
9562GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9563GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9564GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9565GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9566GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9567GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9568#if defined(TARGET_PPC64)
9569GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9570#endif
9571GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
9572GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
9573GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9574GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9575GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
9576GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE),
9577GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE),
8e33944f 9578GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
9579GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9580GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9581GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9582GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9583GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9584GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9585GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9586GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9587GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9588#if defined(TARGET_PPC64)
9589GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9590GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9591 PPC_SEGMENT_64B),
9592GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
9593GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9594 PPC_SEGMENT_64B),
efdef95f
DG
9595GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
9596GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
9597GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
9598#endif
9599GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
9600GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
9601GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
9602GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
9603#if defined(TARGET_PPC64)
9604GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
9605GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
9606#endif
9607GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
9608GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
9609GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
9610GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
9611GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
9612GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
9613GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
9614GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
9615GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
9616GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
9617GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
9618GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9619GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
9620GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
9621GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
9622GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
9623GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
9624GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
9625GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
9626GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9627GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
9628GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
9629GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
9630GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
9631GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
9632GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
9633GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
9634GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
9635GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
9636GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
9637GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
9638GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
9639GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
9640GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
9641GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
9642GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
9643GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
9644GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
9645GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
9646GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
9647GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
9648GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
9649GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
9650GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
9651GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
9652GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
9653GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
9654GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
9655GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
9656GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9657GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9658GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
9659GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
9660GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9661GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9662GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
9663GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
9664GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
9665GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
9666GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
9667GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
9668GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
9669GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
9670GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
9671GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
9672GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
9673GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
9674GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
9675GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
9676GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
9677GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 9678GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
9679GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
9680GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
9681GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
9682GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
9683GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
9684GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
9685GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
9686GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
9687GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
9688 PPC_NONE, PPC2_BOOKE206),
9689GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
9690 PPC_NONE, PPC2_BOOKE206),
9691GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
9692 PPC_NONE, PPC2_BOOKE206),
9693GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
9694 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
9695GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
9696 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
9697GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
9698 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
9699GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
9700 PPC_NONE, PPC2_PRCNTL),
5c55ff99 9701GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 9702GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 9703GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
9704GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
9705 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 9706GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
9707GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
9708 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
9709GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
9710GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
9711GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
9712GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
9713GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC),
9714GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
9715GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
9716GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
9717GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
9718GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
9719
9720#undef GEN_INT_ARITH_ADD
9721#undef GEN_INT_ARITH_ADD_CONST
9722#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
9723GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
9724#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
9725 add_ca, compute_ca, compute_ov) \
9726GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
9727GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
9728GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
9729GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
9730GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
9731GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
9732GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
9733GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
9734GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
9735GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
9736GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
9737
9738#undef GEN_INT_ARITH_DIVW
9739#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
9740GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
9741GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
9742GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
9743GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
9744GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
a98eb9e9
TM
9745GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
9746GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
6a4fda33
TM
9747GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
9748GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
5c55ff99
BS
9749
9750#if defined(TARGET_PPC64)
9751#undef GEN_INT_ARITH_DIVD
9752#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
9753GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9754GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
9755GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
9756GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
9757GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
9758
98d1eb27
TM
9759GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
9760GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
e44259b6
TM
9761GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
9762GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
98d1eb27 9763
5c55ff99
BS
9764#undef GEN_INT_ARITH_MUL_HELPER
9765#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
9766GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9767GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
9768GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
9769GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
9770#endif
9771
9772#undef GEN_INT_ARITH_SUBF
9773#undef GEN_INT_ARITH_SUBF_CONST
9774#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
9775GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
9776#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
9777 add_ca, compute_ca, compute_ov) \
9778GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
9779GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
9780GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
9781GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
9782GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
9783GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
9784GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
9785GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
9786GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
9787GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
9788GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
9789
9790#undef GEN_LOGICAL1
9791#undef GEN_LOGICAL2
9792#define GEN_LOGICAL2(name, tcg_op, opc, type) \
9793GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
9794#define GEN_LOGICAL1(name, tcg_op, opc, type) \
9795GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
9796GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
9797GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
9798GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
9799GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
9800GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
9801GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
9802GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
9803GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
9804#if defined(TARGET_PPC64)
9805GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
9806#endif
9807
9808#if defined(TARGET_PPC64)
9809#undef GEN_PPC64_R2
9810#undef GEN_PPC64_R4
9811#define GEN_PPC64_R2(name, opc1, opc2) \
9812GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9813GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9814 PPC_64B)
9815#define GEN_PPC64_R4(name, opc1, opc2) \
9816GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9817GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
9818 PPC_64B), \
9819GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9820 PPC_64B), \
9821GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
9822 PPC_64B)
9823GEN_PPC64_R4(rldicl, 0x1E, 0x00),
9824GEN_PPC64_R4(rldicr, 0x1E, 0x02),
9825GEN_PPC64_R4(rldic, 0x1E, 0x04),
9826GEN_PPC64_R2(rldcl, 0x1E, 0x08),
9827GEN_PPC64_R2(rldcr, 0x1E, 0x09),
9828GEN_PPC64_R4(rldimi, 0x1E, 0x06),
9829#endif
9830
9831#undef _GEN_FLOAT_ACB
9832#undef GEN_FLOAT_ACB
9833#undef _GEN_FLOAT_AB
9834#undef GEN_FLOAT_AB
9835#undef _GEN_FLOAT_AC
9836#undef GEN_FLOAT_AC
9837#undef GEN_FLOAT_B
9838#undef GEN_FLOAT_BS
9839#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
9840GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
9841#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
9842_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
9843_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
9844#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9845GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9846#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
9847_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9848_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9849#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9850GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9851#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
9852_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9853_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9854#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
9855GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
9856#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
9857GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
9858
9859GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
9860GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
9861GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
9862GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
9863GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
9864GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
9865_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
9866GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
9867GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
9868GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
9869GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
9870GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
da29cb7b 9871GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
5c55ff99 9872GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
fab7fe42 9873GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 9874GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
fab7fe42 9875GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
9876GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
9877#if defined(TARGET_PPC64)
9878GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
28288b48
TM
9879GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
9880GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
9881GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 9882GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
fab7fe42 9883GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 9884GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
fab7fe42 9885GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
9886#endif
9887GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
9888GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
9889GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
9890GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
9891
9892#undef GEN_LD
9893#undef GEN_LDU
9894#undef GEN_LDUX
cd6e9320 9895#undef GEN_LDX_E
5c55ff99
BS
9896#undef GEN_LDS
9897#define GEN_LD(name, ldop, opc, type) \
9898GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9899#define GEN_LDU(name, ldop, opc, type) \
9900GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9901#define GEN_LDUX(name, ldop, opc2, opc3, type) \
9902GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
9903#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
9904GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
9905#define GEN_LDS(name, ldop, op, type) \
9906GEN_LD(name, ldop, op | 0x20, type) \
9907GEN_LDU(name, ldop, op | 0x21, type) \
9908GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
9909GEN_LDX(name, ldop, 0x17, op | 0x00, type)
9910
9911GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
9912GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
9913GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
9914GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
9915#if defined(TARGET_PPC64)
9916GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
9917GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
9918GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
9919GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 9920GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
9921#endif
9922GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
9923GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
9924
9925#undef GEN_ST
9926#undef GEN_STU
9927#undef GEN_STUX
cd6e9320 9928#undef GEN_STX_E
5c55ff99
BS
9929#undef GEN_STS
9930#define GEN_ST(name, stop, opc, type) \
9931GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9932#define GEN_STU(name, stop, opc, type) \
9933GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
9934#define GEN_STUX(name, stop, opc2, opc3, type) \
9935GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
9936#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
9937GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
9938#define GEN_STS(name, stop, op, type) \
9939GEN_ST(name, stop, op | 0x20, type) \
9940GEN_STU(name, stop, op | 0x21, type) \
9941GEN_STUX(name, stop, 0x17, op | 0x01, type) \
9942GEN_STX(name, stop, 0x17, op | 0x00, type)
9943
9944GEN_STS(stb, st8, 0x06, PPC_INTEGER)
9945GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
9946GEN_STS(stw, st32, 0x04, PPC_INTEGER)
9947#if defined(TARGET_PPC64)
9948GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
9949GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 9950GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
9951#endif
9952GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
9953GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
9954
9955#undef GEN_LDF
9956#undef GEN_LDUF
9957#undef GEN_LDUXF
9958#undef GEN_LDXF
9959#undef GEN_LDFS
9960#define GEN_LDF(name, ldop, opc, type) \
9961GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9962#define GEN_LDUF(name, ldop, opc, type) \
9963GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9964#define GEN_LDUXF(name, ldop, opc, type) \
9965GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9966#define GEN_LDXF(name, ldop, opc2, opc3, type) \
9967GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9968#define GEN_LDFS(name, ldop, op, type) \
9969GEN_LDF(name, ldop, op | 0x20, type) \
9970GEN_LDUF(name, ldop, op | 0x21, type) \
9971GEN_LDUXF(name, ldop, op | 0x01, type) \
9972GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
9973
9974GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
9975GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 9976GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
05050ee8
AJ
9977GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
9978GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9979
9980#undef GEN_STF
9981#undef GEN_STUF
9982#undef GEN_STUXF
9983#undef GEN_STXF
9984#undef GEN_STFS
9985#define GEN_STF(name, stop, opc, type) \
9986GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9987#define GEN_STUF(name, stop, opc, type) \
9988GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9989#define GEN_STUXF(name, stop, opc, type) \
9990GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9991#define GEN_STXF(name, stop, opc2, opc3, type) \
9992GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9993#define GEN_STFS(name, stop, op, type) \
9994GEN_STF(name, stop, op | 0x20, type) \
9995GEN_STUF(name, stop, op | 0x21, type) \
9996GEN_STUXF(name, stop, op | 0x01, type) \
9997GEN_STXF(name, stop, 0x17, op | 0x00, type)
9998
9999GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10000GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10001GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
10002GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10003GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10004
10005#undef GEN_CRLOGIC
10006#define GEN_CRLOGIC(name, tcg_op, opc) \
10007GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10008GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10009GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10010GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10011GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10012GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10013GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10014GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10015GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10016
10017#undef GEN_MAC_HANDLER
10018#define GEN_MAC_HANDLER(name, opc2, opc3) \
10019GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10020GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10021GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10022GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10023GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10024GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10025GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10026GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10027GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10028GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10029GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10030GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10031GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10032GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10033GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10034GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10035GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10036GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10037GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10038GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10039GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10040GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10041GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10042GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10043GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10044GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10045GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10046GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10047GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10048GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10049GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10050GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10051GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10052GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10053GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10054GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10055GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10056GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10057GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10058GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10059GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10060GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10061GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10062
10063#undef GEN_VR_LDX
10064#undef GEN_VR_STX
10065#undef GEN_VR_LVE
10066#undef GEN_VR_STVE
10067#define GEN_VR_LDX(name, opc2, opc3) \
10068GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10069#define GEN_VR_STX(name, opc2, opc3) \
10070GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10071#define GEN_VR_LVE(name, opc2, opc3) \
10072 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10073#define GEN_VR_STVE(name, opc2, opc3) \
10074 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10075GEN_VR_LDX(lvx, 0x07, 0x03),
10076GEN_VR_LDX(lvxl, 0x07, 0x0B),
10077GEN_VR_LVE(bx, 0x07, 0x00),
10078GEN_VR_LVE(hx, 0x07, 0x01),
10079GEN_VR_LVE(wx, 0x07, 0x02),
10080GEN_VR_STX(svx, 0x07, 0x07),
10081GEN_VR_STX(svxl, 0x07, 0x0F),
10082GEN_VR_STVE(bx, 0x07, 0x04),
10083GEN_VR_STVE(hx, 0x07, 0x05),
10084GEN_VR_STVE(wx, 0x07, 0x06),
10085
10086#undef GEN_VX_LOGICAL
10087#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10088GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10089GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10090GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10091GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10092GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10093GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
10094
10095#undef GEN_VXFORM
10096#define GEN_VXFORM(name, opc2, opc3) \
10097GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10098GEN_VXFORM(vaddubm, 0, 0),
10099GEN_VXFORM(vadduhm, 0, 1),
10100GEN_VXFORM(vadduwm, 0, 2),
10101GEN_VXFORM(vsububm, 0, 16),
10102GEN_VXFORM(vsubuhm, 0, 17),
10103GEN_VXFORM(vsubuwm, 0, 18),
10104GEN_VXFORM(vmaxub, 1, 0),
10105GEN_VXFORM(vmaxuh, 1, 1),
10106GEN_VXFORM(vmaxuw, 1, 2),
10107GEN_VXFORM(vmaxsb, 1, 4),
10108GEN_VXFORM(vmaxsh, 1, 5),
10109GEN_VXFORM(vmaxsw, 1, 6),
10110GEN_VXFORM(vminub, 1, 8),
10111GEN_VXFORM(vminuh, 1, 9),
10112GEN_VXFORM(vminuw, 1, 10),
10113GEN_VXFORM(vminsb, 1, 12),
10114GEN_VXFORM(vminsh, 1, 13),
10115GEN_VXFORM(vminsw, 1, 14),
10116GEN_VXFORM(vavgub, 1, 16),
10117GEN_VXFORM(vavguh, 1, 17),
10118GEN_VXFORM(vavguw, 1, 18),
10119GEN_VXFORM(vavgsb, 1, 20),
10120GEN_VXFORM(vavgsh, 1, 21),
10121GEN_VXFORM(vavgsw, 1, 22),
10122GEN_VXFORM(vmrghb, 6, 0),
10123GEN_VXFORM(vmrghh, 6, 1),
10124GEN_VXFORM(vmrghw, 6, 2),
10125GEN_VXFORM(vmrglb, 6, 4),
10126GEN_VXFORM(vmrglh, 6, 5),
10127GEN_VXFORM(vmrglw, 6, 6),
10128GEN_VXFORM(vmuloub, 4, 0),
10129GEN_VXFORM(vmulouh, 4, 1),
10130GEN_VXFORM(vmulosb, 4, 4),
10131GEN_VXFORM(vmulosh, 4, 5),
10132GEN_VXFORM(vmuleub, 4, 8),
10133GEN_VXFORM(vmuleuh, 4, 9),
10134GEN_VXFORM(vmulesb, 4, 12),
10135GEN_VXFORM(vmulesh, 4, 13),
10136GEN_VXFORM(vslb, 2, 4),
10137GEN_VXFORM(vslh, 2, 5),
10138GEN_VXFORM(vslw, 2, 6),
10139GEN_VXFORM(vsrb, 2, 8),
10140GEN_VXFORM(vsrh, 2, 9),
10141GEN_VXFORM(vsrw, 2, 10),
10142GEN_VXFORM(vsrab, 2, 12),
10143GEN_VXFORM(vsrah, 2, 13),
10144GEN_VXFORM(vsraw, 2, 14),
10145GEN_VXFORM(vslo, 6, 16),
10146GEN_VXFORM(vsro, 6, 17),
10147GEN_VXFORM(vaddcuw, 0, 6),
10148GEN_VXFORM(vsubcuw, 0, 22),
10149GEN_VXFORM(vaddubs, 0, 8),
10150GEN_VXFORM(vadduhs, 0, 9),
10151GEN_VXFORM(vadduws, 0, 10),
10152GEN_VXFORM(vaddsbs, 0, 12),
10153GEN_VXFORM(vaddshs, 0, 13),
10154GEN_VXFORM(vaddsws, 0, 14),
10155GEN_VXFORM(vsububs, 0, 24),
10156GEN_VXFORM(vsubuhs, 0, 25),
10157GEN_VXFORM(vsubuws, 0, 26),
10158GEN_VXFORM(vsubsbs, 0, 28),
10159GEN_VXFORM(vsubshs, 0, 29),
10160GEN_VXFORM(vsubsws, 0, 30),
10161GEN_VXFORM(vrlb, 2, 0),
10162GEN_VXFORM(vrlh, 2, 1),
10163GEN_VXFORM(vrlw, 2, 2),
10164GEN_VXFORM(vsl, 2, 7),
10165GEN_VXFORM(vsr, 2, 11),
10166GEN_VXFORM(vpkuhum, 7, 0),
10167GEN_VXFORM(vpkuwum, 7, 1),
10168GEN_VXFORM(vpkuhus, 7, 2),
10169GEN_VXFORM(vpkuwus, 7, 3),
10170GEN_VXFORM(vpkshus, 7, 4),
10171GEN_VXFORM(vpkswus, 7, 5),
10172GEN_VXFORM(vpkshss, 7, 6),
10173GEN_VXFORM(vpkswss, 7, 7),
10174GEN_VXFORM(vpkpx, 7, 12),
10175GEN_VXFORM(vsum4ubs, 4, 24),
10176GEN_VXFORM(vsum4sbs, 4, 28),
10177GEN_VXFORM(vsum4shs, 4, 25),
10178GEN_VXFORM(vsum2sws, 4, 26),
10179GEN_VXFORM(vsumsws, 4, 30),
10180GEN_VXFORM(vaddfp, 5, 0),
10181GEN_VXFORM(vsubfp, 5, 1),
10182GEN_VXFORM(vmaxfp, 5, 16),
10183GEN_VXFORM(vminfp, 5, 17),
10184
10185#undef GEN_VXRFORM1
10186#undef GEN_VXRFORM
10187#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10188 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10189#define GEN_VXRFORM(name, opc2, opc3) \
10190 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10191 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10192GEN_VXRFORM(vcmpequb, 3, 0)
10193GEN_VXRFORM(vcmpequh, 3, 1)
10194GEN_VXRFORM(vcmpequw, 3, 2)
10195GEN_VXRFORM(vcmpgtsb, 3, 12)
10196GEN_VXRFORM(vcmpgtsh, 3, 13)
10197GEN_VXRFORM(vcmpgtsw, 3, 14)
10198GEN_VXRFORM(vcmpgtub, 3, 8)
10199GEN_VXRFORM(vcmpgtuh, 3, 9)
10200GEN_VXRFORM(vcmpgtuw, 3, 10)
10201GEN_VXRFORM(vcmpeqfp, 3, 3)
10202GEN_VXRFORM(vcmpgefp, 3, 7)
10203GEN_VXRFORM(vcmpgtfp, 3, 11)
10204GEN_VXRFORM(vcmpbfp, 3, 15)
10205
10206#undef GEN_VXFORM_SIMM
10207#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10208 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10209GEN_VXFORM_SIMM(vspltisb, 6, 12),
10210GEN_VXFORM_SIMM(vspltish, 6, 13),
10211GEN_VXFORM_SIMM(vspltisw, 6, 14),
10212
10213#undef GEN_VXFORM_NOA
10214#define GEN_VXFORM_NOA(name, opc2, opc3) \
10215 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10216GEN_VXFORM_NOA(vupkhsb, 7, 8),
10217GEN_VXFORM_NOA(vupkhsh, 7, 9),
10218GEN_VXFORM_NOA(vupklsb, 7, 10),
10219GEN_VXFORM_NOA(vupklsh, 7, 11),
10220GEN_VXFORM_NOA(vupkhpx, 7, 13),
10221GEN_VXFORM_NOA(vupklpx, 7, 15),
10222GEN_VXFORM_NOA(vrefp, 5, 4),
10223GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10224GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99
BS
10225GEN_VXFORM_NOA(vlogefp, 5, 7),
10226GEN_VXFORM_NOA(vrfim, 5, 8),
10227GEN_VXFORM_NOA(vrfin, 5, 9),
10228GEN_VXFORM_NOA(vrfip, 5, 10),
10229GEN_VXFORM_NOA(vrfiz, 5, 11),
10230
10231#undef GEN_VXFORM_UIMM
10232#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10233 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10234GEN_VXFORM_UIMM(vspltb, 6, 8),
10235GEN_VXFORM_UIMM(vsplth, 6, 9),
10236GEN_VXFORM_UIMM(vspltw, 6, 10),
10237GEN_VXFORM_UIMM(vcfux, 5, 12),
10238GEN_VXFORM_UIMM(vcfsx, 5, 13),
10239GEN_VXFORM_UIMM(vctuxs, 5, 14),
10240GEN_VXFORM_UIMM(vctsxs, 5, 15),
10241
10242#undef GEN_VAFORM_PAIRED
10243#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10244 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10245GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10246GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10247GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10248GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10249GEN_VAFORM_PAIRED(vsel, vperm, 21),
10250GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10251
fa1832d7 10252GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10253GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10254GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10255GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10256GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10257GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10258GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10259
9231ba9e 10260GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10261GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10262GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10263GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10264GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10265
f5c0f7f9
TM
10266GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10267GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10268GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10269#if defined(TARGET_PPC64)
10270GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10271GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10272#endif
10273
df020ce0
TM
10274#undef GEN_XX2FORM
10275#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10276GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10277GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10278
10279#undef GEN_XX3FORM
10280#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10281GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10282GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10283GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10284GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10285
354a6dec
TM
10286#undef GEN_XX3_RC_FORM
10287#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10288GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10289GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10290GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10291GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10292GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10293GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10294GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10295GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10296
cd73f2c9
TM
10297#undef GEN_XX3FORM_DM
10298#define GEN_XX3FORM_DM(name, opc2, opc3) \
10299GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10300GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10301GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10302GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10303GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10304GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10305GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10306GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10307GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10308GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10309GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10310GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10311GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10312GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10313GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10314GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10315
df020ce0
TM
10316GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10317GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10318GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10319GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10320
be574920
TM
10321GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10322GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10323GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10324GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10325GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10326GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10327GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10328GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 10329
ee6e02c0
TM
10330GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10331GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 10332GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 10333GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 10334GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 10335GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 10336GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 10337GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 10338GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
10339GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10340GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10341GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10342GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10343GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10344GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10345GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10346GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
4f17e9c7
TM
10347GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10348GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
10349GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10350GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568 10351GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
7ee19fb9 10352GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
ed8ac568 10353GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
7ee19fb9 10354GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
5177d2ca
TM
10355GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10356GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10357GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10358GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10359GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10360GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
10361GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10362GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10363GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10364GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10365GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 10366
3fd0aadf
TM
10367GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10368GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 10369GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 10370GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 10371GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
3d1140bf 10372GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
cea4e574 10373GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
968e76bc 10374GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
f53f81e0
TM
10375GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
10376GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
10377GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
10378GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
10379GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
10380GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
10381GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
10382GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
74698350
TM
10383GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
10384GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
3fd0aadf 10385
ee6e02c0
TM
10386GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10387GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 10388GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 10389GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 10390GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 10391GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 10392GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 10393GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 10394GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
10395GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10396GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10397GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10398GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10399GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10400GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10401GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10402GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
10403GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10404GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
10405GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10406GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10407GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 10408GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
10409GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10410GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10411GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10412GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10413GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10414GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10415GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10416GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
10417GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10418GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10419GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10420GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10421GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
10422
10423GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10424GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 10425GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 10426GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 10427GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 10428GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 10429GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 10430GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 10431GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
10432GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10433GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10434GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10435GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10436GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10437GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10438GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10439GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
10440GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10441GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
10442GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10443GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10444GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 10445GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
10446GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10447GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10448GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10449GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10450GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10451GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10452GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10453GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
10454GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10455GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10456GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10457GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10458GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 10459
79ca8a6a
TM
10460#undef VSX_LOGICAL
10461#define VSX_LOGICAL(name, opc2, opc3, fl2) \
10462GEN_XX3FORM(name, opc2, opc3, fl2)
10463
10464VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10465VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10466VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10467VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10468VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
67a33f37
TM
10469VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
10470VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
10471VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
ce577d2e
TM
10472GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10473GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 10474GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 10475GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 10476
551e3ef7
TM
10477#define GEN_XXSEL_ROW(opc3) \
10478GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10479GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10480GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10481GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10482GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10483GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10484GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10485GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10486
10487GEN_XXSEL_ROW(0x00)
10488GEN_XXSEL_ROW(0x01)
10489GEN_XXSEL_ROW(0x02)
10490GEN_XXSEL_ROW(0x03)
10491GEN_XXSEL_ROW(0x04)
10492GEN_XXSEL_ROW(0x05)
10493GEN_XXSEL_ROW(0x06)
10494GEN_XXSEL_ROW(0x07)
10495GEN_XXSEL_ROW(0x08)
10496GEN_XXSEL_ROW(0x09)
10497GEN_XXSEL_ROW(0x0A)
10498GEN_XXSEL_ROW(0x0B)
10499GEN_XXSEL_ROW(0x0C)
10500GEN_XXSEL_ROW(0x0D)
10501GEN_XXSEL_ROW(0x0E)
10502GEN_XXSEL_ROW(0x0F)
10503GEN_XXSEL_ROW(0x10)
10504GEN_XXSEL_ROW(0x11)
10505GEN_XXSEL_ROW(0x12)
10506GEN_XXSEL_ROW(0x13)
10507GEN_XXSEL_ROW(0x14)
10508GEN_XXSEL_ROW(0x15)
10509GEN_XXSEL_ROW(0x16)
10510GEN_XXSEL_ROW(0x17)
10511GEN_XXSEL_ROW(0x18)
10512GEN_XXSEL_ROW(0x19)
10513GEN_XXSEL_ROW(0x1A)
10514GEN_XXSEL_ROW(0x1B)
10515GEN_XXSEL_ROW(0x1C)
10516GEN_XXSEL_ROW(0x1D)
10517GEN_XXSEL_ROW(0x1E)
10518GEN_XXSEL_ROW(0x1F)
10519
cd73f2c9
TM
10520GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
10521
5c55ff99 10522#undef GEN_SPE
70560da7
FC
10523#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
10524 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
10525GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10526GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10527GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10528GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10529GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10530GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10531GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10532GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
10533GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
10534GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
10535GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10536GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10537GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10538GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
10539GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
10540GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
10541GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
10542GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10543GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10544GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10545GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10546GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10547GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
10548GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
10549GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10550GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10551GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
10552GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
10553GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
10554
10555GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10556GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
10557GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
10558GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10559GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10560GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10561GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10562GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10563GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10564GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10565GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10566GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10567GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10568GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10569
10570GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10571GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
10572GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
10573GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10574GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10575GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
10576GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10577GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10578GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10579GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10580GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10581GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10582GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10583GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10584
10585GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
10586GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10587GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
10588GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10589GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
10590GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10591GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
10592GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
10593GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10594GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10595GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10596GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10597GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10598GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10599GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
10600GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
10601
10602#undef GEN_SPEOP_LDST
10603#define GEN_SPEOP_LDST(name, opc2, sh) \
10604GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
10605GEN_SPEOP_LDST(evldd, 0x00, 3),
10606GEN_SPEOP_LDST(evldw, 0x01, 3),
10607GEN_SPEOP_LDST(evldh, 0x02, 3),
10608GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
10609GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
10610GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
10611GEN_SPEOP_LDST(evlwhe, 0x08, 2),
10612GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
10613GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
10614GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
10615GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
10616
10617GEN_SPEOP_LDST(evstdd, 0x10, 3),
10618GEN_SPEOP_LDST(evstdw, 0x11, 3),
10619GEN_SPEOP_LDST(evstdh, 0x12, 3),
10620GEN_SPEOP_LDST(evstwhe, 0x18, 2),
10621GEN_SPEOP_LDST(evstwho, 0x1A, 2),
10622GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
10623GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
10624};
10625
0411a972 10626#include "helper_regs.h"
a1389542 10627#include "translate_init.c"
79aceca5 10628
9a64fbe4 10629/*****************************************************************************/
3fc6c082 10630/* Misc PowerPC helpers */
878096ee
AF
10631void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
10632 int flags)
79aceca5 10633{
3fc6c082
FB
10634#define RGPL 4
10635#define RFPL 4
3fc6c082 10636
878096ee
AF
10637 PowerPCCPU *cpu = POWERPC_CPU(cs);
10638 CPUPPCState *env = &cpu->env;
79aceca5
FB
10639 int i;
10640
90e189ec 10641 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9a78eead 10642 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
da91a00f 10643 env->nip, env->lr, env->ctr, cpu_read_xer(env));
90e189ec
BS
10644 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
10645 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
10646 env->hflags, env->mmu_idx);
d9bce9d9 10647#if !defined(NO_TIMER_DUMP)
9a78eead 10648 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 10649#if !defined(CONFIG_USER_ONLY)
9a78eead 10650 " DECR %08" PRIu32
76a66253
JM
10651#endif
10652 "\n",
077fc206 10653 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
10654#if !defined(CONFIG_USER_ONLY)
10655 , cpu_ppc_load_decr(env)
10656#endif
10657 );
077fc206 10658#endif
76a66253 10659 for (i = 0; i < 32; i++) {
3fc6c082
FB
10660 if ((i & (RGPL - 1)) == 0)
10661 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 10662 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 10663 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 10664 cpu_fprintf(f, "\n");
76a66253 10665 }
3fc6c082 10666 cpu_fprintf(f, "CR ");
76a66253 10667 for (i = 0; i < 8; i++)
7fe48483
FB
10668 cpu_fprintf(f, "%01x", env->crf[i]);
10669 cpu_fprintf(f, " [");
76a66253
JM
10670 for (i = 0; i < 8; i++) {
10671 char a = '-';
10672 if (env->crf[i] & 0x08)
10673 a = 'L';
10674 else if (env->crf[i] & 0x04)
10675 a = 'G';
10676 else if (env->crf[i] & 0x02)
10677 a = 'E';
7fe48483 10678 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 10679 }
90e189ec
BS
10680 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
10681 env->reserve_addr);
3fc6c082
FB
10682 for (i = 0; i < 32; i++) {
10683 if ((i & (RFPL - 1)) == 0)
10684 cpu_fprintf(f, "FPR%02d", i);
26a76461 10685 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 10686 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 10687 cpu_fprintf(f, "\n");
79aceca5 10688 }
30304420 10689 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 10690#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
10691 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
10692 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
10693 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
10694 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
10695
10696 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
10697 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
10698 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
10699 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
10700
10701 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
10702 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
10703 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
10704 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
10705
10706 if (env->excp_model == POWERPC_EXCP_BOOKE) {
10707 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
10708 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
10709 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
10710 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
10711
10712 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
10713 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
10714 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
10715 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
10716
10717 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
10718 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
10719 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
10720 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
10721
10722 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
10723 " EPR " TARGET_FMT_lx "\n",
10724 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
10725 env->spr[SPR_BOOKE_EPR]);
10726
10727 /* FSL-specific */
10728 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
10729 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
10730 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
10731 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
10732
10733 /*
10734 * IVORs are left out as they are large and do not change often --
10735 * they can be read with "p $ivor0", "p $ivor1", etc.
10736 */
10737 }
10738
697ab892
DG
10739#if defined(TARGET_PPC64)
10740 if (env->flags & POWERPC_FLAG_CFAR) {
10741 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
10742 }
10743#endif
10744
90dc8812
SW
10745 switch (env->mmu_model) {
10746 case POWERPC_MMU_32B:
10747 case POWERPC_MMU_601:
10748 case POWERPC_MMU_SOFT_6xx:
10749 case POWERPC_MMU_SOFT_74xx:
10750#if defined(TARGET_PPC64)
90dc8812 10751 case POWERPC_MMU_64B:
ca480de6
AB
10752 case POWERPC_MMU_2_06:
10753 case POWERPC_MMU_2_06a:
10754 case POWERPC_MMU_2_06d:
90dc8812 10755#endif
ca480de6
AB
10756 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
10757 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
10758 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 10759 break;
01662f3e 10760 case POWERPC_MMU_BOOKE206:
90dc8812
SW
10761 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
10762 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
10763 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
10764 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
10765
10766 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
10767 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
10768 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
10769 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
10770
10771 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
10772 " TLB1CFG " TARGET_FMT_lx "\n",
10773 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
10774 env->spr[SPR_BOOKE_TLB1CFG]);
10775 break;
10776 default:
10777 break;
10778 }
f2e63a42 10779#endif
79aceca5 10780
3fc6c082
FB
10781#undef RGPL
10782#undef RFPL
79aceca5
FB
10783}
10784
878096ee
AF
10785void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
10786 fprintf_function cpu_fprintf, int flags)
76a66253
JM
10787{
10788#if defined(DO_PPC_STATISTICS)
878096ee 10789 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 10790 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
10791 int op1, op2, op3;
10792
878096ee 10793 t1 = cpu->env.opcodes;
76a66253
JM
10794 for (op1 = 0; op1 < 64; op1++) {
10795 handler = t1[op1];
10796 if (is_indirect_opcode(handler)) {
10797 t2 = ind_table(handler);
10798 for (op2 = 0; op2 < 32; op2++) {
10799 handler = t2[op2];
10800 if (is_indirect_opcode(handler)) {
10801 t3 = ind_table(handler);
10802 for (op3 = 0; op3 < 32; op3++) {
10803 handler = t3[op3];
10804 if (handler->count == 0)
10805 continue;
10806 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 10807 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
10808 op1, op2, op3, op1, (op3 << 5) | op2,
10809 handler->oname,
10810 handler->count, handler->count);
10811 }
10812 } else {
10813 if (handler->count == 0)
10814 continue;
10815 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 10816 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
10817 op1, op2, op1, op2, handler->oname,
10818 handler->count, handler->count);
10819 }
10820 }
10821 } else {
10822 if (handler->count == 0)
10823 continue;
0bfcd599
BS
10824 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
10825 " %" PRId64 "\n",
76a66253
JM
10826 op1, op1, handler->oname,
10827 handler->count, handler->count);
10828 }
10829 }
10830#endif
10831}
10832
9a64fbe4 10833/*****************************************************************************/
213fe1f5 10834static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
636aa200 10835 TranslationBlock *tb,
213fe1f5 10836 bool search_pc)
79aceca5 10837{
ed2803da 10838 CPUState *cs = CPU(cpu);
213fe1f5 10839 CPUPPCState *env = &cpu->env;
9fddaa0c 10840 DisasContext ctx, *ctxp = &ctx;
c227f099 10841 opc_handler_t **table, *handler;
0fa85d43 10842 target_ulong pc_start;
79aceca5 10843 uint16_t *gen_opc_end;
a1d1bb31 10844 CPUBreakpoint *bp;
79aceca5 10845 int j, lj = -1;
2e70f6ef
PB
10846 int num_insns;
10847 int max_insns;
79aceca5
FB
10848
10849 pc_start = tb->pc;
92414b31 10850 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
046d6672 10851 ctx.nip = pc_start;
79aceca5 10852 ctx.tb = tb;
e1833e1f 10853 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 10854 ctx.spr_cb = env->spr_cb;
76db3ba4 10855 ctx.mem_idx = env->mmu_idx;
7d08d856
AJ
10856 ctx.insns_flags = env->insns_flags;
10857 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
10858 ctx.access_type = -1;
10859 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
d9bce9d9 10860#if defined(TARGET_PPC64)
e42a61f1 10861 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 10862 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 10863#endif
3cc62370 10864 ctx.fpu_enabled = msr_fp;
a9d9eb8f 10865 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
10866 ctx.spe_enabled = msr_spe;
10867 else
10868 ctx.spe_enabled = 0;
a9d9eb8f
JM
10869 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
10870 ctx.altivec_enabled = msr_vr;
10871 else
10872 ctx.altivec_enabled = 0;
1f29871c
TM
10873 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
10874 ctx.vsx_enabled = msr_vsx;
10875 } else {
10876 ctx.vsx_enabled = 0;
10877 }
d26bfc9a 10878 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 10879 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 10880 else
8cbcb4fa 10881 ctx.singlestep_enabled = 0;
d26bfc9a 10882 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 10883 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 10884 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 10885 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 10886 }
3fc6c082 10887#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
10888 /* Single step trace mode */
10889 msr_se = 1;
10890#endif
2e70f6ef
PB
10891 num_insns = 0;
10892 max_insns = tb->cflags & CF_COUNT_MASK;
10893 if (max_insns == 0)
10894 max_insns = CF_COUNT_MASK;
10895
806f352d 10896 gen_tb_start();
9a64fbe4 10897 /* Set env in case of segfault during code fetch */
efd7f486
EV
10898 while (ctx.exception == POWERPC_EXCP_NONE
10899 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
72cf2d4f
BS
10900 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
10901 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
a1d1bb31 10902 if (bp->pc == ctx.nip) {
e06fcd75 10903 gen_debug_exception(ctxp);
ea4e754f
FB
10904 break;
10905 }
10906 }
10907 }
76a66253 10908 if (unlikely(search_pc)) {
92414b31 10909 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
79aceca5
FB
10910 if (lj < j) {
10911 lj++;
10912 while (lj < j)
ab1103de 10913 tcg_ctx.gen_opc_instr_start[lj++] = 0;
79aceca5 10914 }
25983cad 10915 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
ab1103de 10916 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 10917 tcg_ctx.gen_opc_icount[lj] = num_insns;
79aceca5 10918 }
d12d51d5 10919 LOG_DISAS("----------------\n");
90e189ec 10920 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 10921 ctx.nip, ctx.mem_idx, (int)msr_ir);
2e70f6ef
PB
10922 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
10923 gen_io_start();
76db3ba4 10924 if (unlikely(ctx.le_mode)) {
2f5a189c 10925 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 10926 } else {
2f5a189c 10927 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 10928 }
d12d51d5 10929 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 10930 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 10931 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
fdefe51c 10932 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
731c54f8 10933 tcg_gen_debug_insn_start(ctx.nip);
fdefe51c 10934 }
046d6672 10935 ctx.nip += 4;
3fc6c082 10936 table = env->opcodes;
2e70f6ef 10937 num_insns++;
79aceca5
FB
10938 handler = table[opc1(ctx.opcode)];
10939 if (is_indirect_opcode(handler)) {
10940 table = ind_table(handler);
10941 handler = table[opc2(ctx.opcode)];
10942 if (is_indirect_opcode(handler)) {
10943 table = ind_table(handler);
10944 handler = table[opc3(ctx.opcode)];
10945 }
10946 }
10947 /* Is opcode *REALLY* valid ? */
76a66253 10948 if (unlikely(handler->handler == &gen_invalid)) {
93fcfe39
AL
10949 if (qemu_log_enabled()) {
10950 qemu_log("invalid/unsupported opcode: "
90e189ec
BS
10951 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
10952 opc1(ctx.opcode), opc2(ctx.opcode),
10953 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
4b3686fa 10954 }
76a66253 10955 } else {
70560da7
FC
10956 uint32_t inval;
10957
10958 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
10959 inval = handler->inval2;
10960 } else {
10961 inval = handler->inval1;
10962 }
10963
10964 if (unlikely((ctx.opcode & inval) != 0)) {
93fcfe39
AL
10965 if (qemu_log_enabled()) {
10966 qemu_log("invalid bits: %08x for opcode: "
90e189ec 10967 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
70560da7 10968 ctx.opcode & inval, opc1(ctx.opcode),
90e189ec
BS
10969 opc2(ctx.opcode), opc3(ctx.opcode),
10970 ctx.opcode, ctx.nip - 4);
76a66253 10971 }
e06fcd75 10972 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 10973 break;
79aceca5 10974 }
79aceca5 10975 }
4b3686fa 10976 (*(handler->handler))(&ctx);
76a66253
JM
10977#if defined(DO_PPC_STATISTICS)
10978 handler->count++;
10979#endif
9a64fbe4 10980 /* Check trace mode exceptions */
8cbcb4fa
AJ
10981 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
10982 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
10983 ctx.exception != POWERPC_SYSCALL &&
10984 ctx.exception != POWERPC_EXCP_TRAP &&
10985 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 10986 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 10987 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 10988 (cs->singlestep_enabled) ||
1b530a6d 10989 singlestep ||
2e70f6ef 10990 num_insns >= max_insns)) {
d26bfc9a
JM
10991 /* if we reach a page boundary or are single stepping, stop
10992 * generation
10993 */
8dd4983c 10994 break;
76a66253 10995 }
3fc6c082 10996 }
2e70f6ef
PB
10997 if (tb->cflags & CF_LAST_IO)
10998 gen_io_end();
e1833e1f 10999 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 11000 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 11001 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 11002 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 11003 gen_debug_exception(ctxp);
8cbcb4fa 11004 }
76a66253 11005 /* Generate the return instruction */
57fec1fe 11006 tcg_gen_exit_tb(0);
9a64fbe4 11007 }
806f352d 11008 gen_tb_end(tb, num_insns);
efd7f486 11009 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
76a66253 11010 if (unlikely(search_pc)) {
92414b31 11011 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9a64fbe4
FB
11012 lj++;
11013 while (lj <= j)
ab1103de 11014 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9a64fbe4 11015 } else {
046d6672 11016 tb->size = ctx.nip - pc_start;
2e70f6ef 11017 tb->icount = num_insns;
9a64fbe4 11018 }
d9bce9d9 11019#if defined(DEBUG_DISAS)
8fec2b8c 11020 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 11021 int flags;
237c0af0 11022 flags = env->bfd_mach;
76db3ba4 11023 flags |= ctx.le_mode << 16;
93fcfe39 11024 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 11025 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
93fcfe39 11026 qemu_log("\n");
9fddaa0c 11027 }
79aceca5 11028#endif
79aceca5
FB
11029}
11030
1328c2bf 11031void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11032{
213fe1f5 11033 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
79aceca5
FB
11034}
11035
1328c2bf 11036void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11037{
213fe1f5 11038 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
79aceca5 11039}
d2856f1a 11040
1328c2bf 11041void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
d2856f1a 11042{
25983cad 11043 env->nip = tcg_ctx.gen_opc_pc[pc_pos];
d2856f1a 11044}
This page took 2.939895 seconds and 4 git commands to generate.