]> git.proxmox.com Git - mirror_qemu.git/blame - target-ppc/translate.c
ppc: Do some batching of TCG tlb flushes
[mirror_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
0d75590d 21#include "qemu/osdep.h"
79aceca5 22#include "cpu.h"
76cad711 23#include "disas/disas.h"
63c91552 24#include "exec/exec-all.h"
57fec1fe 25#include "tcg-op.h"
1de7afc9 26#include "qemu/host-utils.h"
f08b6170 27#include "exec/cpu_ldst.h"
79aceca5 28
2ef6175a
RH
29#include "exec/helper-proto.h"
30#include "exec/helper-gen.h"
a7812ae4 31
a7e30d84 32#include "trace-tcg.h"
508127e2 33#include "exec/log.h"
a7e30d84
LV
34
35
8cbcb4fa
AJ
36#define CPU_SINGLE_STEP 0x1
37#define CPU_BRANCH_STEP 0x2
38#define GDBSTUB_SINGLE_STEP 0x4
39
a750fc0b 40/* Include definitions for instructions classes and implementations flags */
9fddaa0c 41//#define PPC_DEBUG_DISAS
76a66253 42//#define DO_PPC_STATISTICS
79aceca5 43
d12d51d5 44#ifdef PPC_DEBUG_DISAS
93fcfe39 45# define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
d12d51d5
AL
46#else
47# define LOG_DISAS(...) do { } while (0)
48#endif
a750fc0b
JM
49/*****************************************************************************/
50/* Code translation helpers */
c53be334 51
f78fb44e 52/* global register indexes */
1bcea73e 53static TCGv_env cpu_env;
1d542695 54static char cpu_reg_names[10*3 + 22*4 /* GPR */
1d542695 55 + 10*4 + 22*5 /* SPE GPRh */
a5e26afa 56 + 10*4 + 22*5 /* FPR */
47e4661c 57 + 2*(10*6 + 22*7) /* AVRh, AVRl */
472b24ce 58 + 10*5 + 22*6 /* VSR */
47e4661c 59 + 8*5 /* CRF */];
f78fb44e 60static TCGv cpu_gpr[32];
f78fb44e 61static TCGv cpu_gprh[32];
a7812ae4
PB
62static TCGv_i64 cpu_fpr[32];
63static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
472b24ce 64static TCGv_i64 cpu_vsr[32];
a7812ae4 65static TCGv_i32 cpu_crf[8];
bd568f18 66static TCGv cpu_nip;
6527f6ea 67static TCGv cpu_msr;
cfdcd37a
AJ
68static TCGv cpu_ctr;
69static TCGv cpu_lr;
697ab892
DG
70#if defined(TARGET_PPC64)
71static TCGv cpu_cfar;
72#endif
da91a00f 73static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
cf360a32 74static TCGv cpu_reserve;
30304420 75static TCGv cpu_fpscr;
a7859e89 76static TCGv_i32 cpu_access_type;
f78fb44e 77
022c62cb 78#include "exec/gen-icount.h"
2e70f6ef
PB
79
80void ppc_translate_init(void)
81{
f78fb44e
AJ
82 int i;
83 char* p;
2dc766da 84 size_t cpu_reg_names_size;
b2437bf2 85 static int done_init = 0;
f78fb44e 86
2e70f6ef
PB
87 if (done_init)
88 return;
f78fb44e 89
a7812ae4 90 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
a7812ae4 91
f78fb44e 92 p = cpu_reg_names;
2dc766da 93 cpu_reg_names_size = sizeof(cpu_reg_names);
47e4661c
AJ
94
95 for (i = 0; i < 8; i++) {
2dc766da 96 snprintf(p, cpu_reg_names_size, "crf%d", i);
e1ccc054 97 cpu_crf[i] = tcg_global_mem_new_i32(cpu_env,
1328c2bf 98 offsetof(CPUPPCState, crf[i]), p);
47e4661c 99 p += 5;
2dc766da 100 cpu_reg_names_size -= 5;
47e4661c
AJ
101 }
102
f78fb44e 103 for (i = 0; i < 32; i++) {
2dc766da 104 snprintf(p, cpu_reg_names_size, "r%d", i);
e1ccc054 105 cpu_gpr[i] = tcg_global_mem_new(cpu_env,
1328c2bf 106 offsetof(CPUPPCState, gpr[i]), p);
f78fb44e 107 p += (i < 10) ? 3 : 4;
2dc766da 108 cpu_reg_names_size -= (i < 10) ? 3 : 4;
2dc766da 109 snprintf(p, cpu_reg_names_size, "r%dH", i);
e1ccc054 110 cpu_gprh[i] = tcg_global_mem_new(cpu_env,
13b6a455 111 offsetof(CPUPPCState, gprh[i]), p);
f78fb44e 112 p += (i < 10) ? 4 : 5;
2dc766da 113 cpu_reg_names_size -= (i < 10) ? 4 : 5;
1d542695 114
2dc766da 115 snprintf(p, cpu_reg_names_size, "fp%d", i);
e1ccc054 116 cpu_fpr[i] = tcg_global_mem_new_i64(cpu_env,
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
e1ccc054 123 cpu_avrh[i] = tcg_global_mem_new_i64(cpu_env,
1328c2bf 124 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 125#else
e1ccc054 126 cpu_avrh[i] = tcg_global_mem_new_i64(cpu_env,
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
e1ccc054 134 cpu_avrl[i] = tcg_global_mem_new_i64(cpu_env,
1328c2bf 135 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 136#else
e1ccc054 137 cpu_avrl[i] = tcg_global_mem_new_i64(cpu_env,
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 142 snprintf(p, cpu_reg_names_size, "vsr%d", i);
e1ccc054
RH
143 cpu_vsr[i] = tcg_global_mem_new_i64(cpu_env,
144 offsetof(CPUPPCState, vsr[i]), p);
472b24ce
TM
145 p += (i < 10) ? 5 : 6;
146 cpu_reg_names_size -= (i < 10) ? 5 : 6;
f78fb44e 147 }
f10dc08e 148
e1ccc054 149 cpu_nip = tcg_global_mem_new(cpu_env,
1328c2bf 150 offsetof(CPUPPCState, nip), "nip");
bd568f18 151
e1ccc054 152 cpu_msr = tcg_global_mem_new(cpu_env,
1328c2bf 153 offsetof(CPUPPCState, msr), "msr");
6527f6ea 154
e1ccc054 155 cpu_ctr = tcg_global_mem_new(cpu_env,
1328c2bf 156 offsetof(CPUPPCState, ctr), "ctr");
cfdcd37a 157
e1ccc054 158 cpu_lr = tcg_global_mem_new(cpu_env,
1328c2bf 159 offsetof(CPUPPCState, lr), "lr");
cfdcd37a 160
697ab892 161#if defined(TARGET_PPC64)
e1ccc054 162 cpu_cfar = tcg_global_mem_new(cpu_env,
1328c2bf 163 offsetof(CPUPPCState, cfar), "cfar");
697ab892
DG
164#endif
165
e1ccc054 166 cpu_xer = tcg_global_mem_new(cpu_env,
1328c2bf 167 offsetof(CPUPPCState, xer), "xer");
e1ccc054 168 cpu_so = tcg_global_mem_new(cpu_env,
da91a00f 169 offsetof(CPUPPCState, so), "SO");
e1ccc054 170 cpu_ov = tcg_global_mem_new(cpu_env,
da91a00f 171 offsetof(CPUPPCState, ov), "OV");
e1ccc054 172 cpu_ca = tcg_global_mem_new(cpu_env,
da91a00f 173 offsetof(CPUPPCState, ca), "CA");
3d7b417e 174
e1ccc054 175 cpu_reserve = tcg_global_mem_new(cpu_env,
1328c2bf 176 offsetof(CPUPPCState, reserve_addr),
18b21a2f 177 "reserve_addr");
cf360a32 178
e1ccc054 179 cpu_fpscr = tcg_global_mem_new(cpu_env,
30304420 180 offsetof(CPUPPCState, fpscr), "fpscr");
e1571908 181
e1ccc054 182 cpu_access_type = tcg_global_mem_new_i32(cpu_env,
1328c2bf 183 offsetof(CPUPPCState, access_type), "access_type");
a7859e89 184
2e70f6ef
PB
185 done_init = 1;
186}
187
79aceca5 188/* internal defines */
69b058c8 189struct DisasContext {
79aceca5 190 struct TranslationBlock *tb;
0fa85d43 191 target_ulong nip;
79aceca5 192 uint32_t opcode;
9a64fbe4 193 uint32_t exception;
3cc62370 194 /* Routine used to access memory */
c47493f2 195 bool pr, hv;
3cc62370 196 int mem_idx;
76db3ba4 197 int access_type;
3cc62370 198 /* Translation flags */
76db3ba4 199 int le_mode;
e22c357b 200 TCGMemOp default_tcg_memop_mask;
d9bce9d9
JM
201#if defined(TARGET_PPC64)
202 int sf_mode;
697ab892 203 int has_cfar;
9a64fbe4 204#endif
3cc62370 205 int fpu_enabled;
a9d9eb8f 206 int altivec_enabled;
1f29871c 207 int vsx_enabled;
0487d6a8 208 int spe_enabled;
69d1a937 209 int tm_enabled;
c227f099 210 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
ea4e754f 211 int singlestep_enabled;
7d08d856
AJ
212 uint64_t insns_flags;
213 uint64_t insns_flags2;
69b058c8 214};
79aceca5 215
e22c357b
DK
216/* Return true iff byteswap is needed in a scalar memop */
217static inline bool need_byteswap(const DisasContext *ctx)
218{
219#if defined(TARGET_WORDS_BIGENDIAN)
220 return ctx->le_mode;
221#else
222 return !ctx->le_mode;
223#endif
224}
225
79482e5a
RH
226/* True when active word size < size of target_long. */
227#ifdef TARGET_PPC64
228# define NARROW_MODE(C) (!(C)->sf_mode)
229#else
230# define NARROW_MODE(C) 0
231#endif
232
c227f099 233struct opc_handler_t {
70560da7
FC
234 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
235 uint32_t inval1;
236 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
237 uint32_t inval2;
9a64fbe4 238 /* instruction type */
0487d6a8 239 uint64_t type;
a5858d7a
AG
240 /* extended instruction type */
241 uint64_t type2;
79aceca5
FB
242 /* handler */
243 void (*handler)(DisasContext *ctx);
a750fc0b 244#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
b55266b5 245 const char *oname;
a750fc0b
JM
246#endif
247#if defined(DO_PPC_STATISTICS)
76a66253
JM
248 uint64_t count;
249#endif
3fc6c082 250};
79aceca5 251
636aa200 252static inline void gen_reset_fpstatus(void)
7c58044c 253{
8e703949 254 gen_helper_reset_fpstatus(cpu_env);
7c58044c
JM
255}
256
7d45556e 257static inline void gen_compute_fprf(TCGv_i64 arg)
7c58044c 258{
58dd0a47 259 gen_helper_compute_fprf(cpu_env, arg);
7d45556e 260 gen_helper_float_check_status(cpu_env);
7c58044c
JM
261}
262
636aa200 263static inline void gen_set_access_type(DisasContext *ctx, int access_type)
a7859e89 264{
76db3ba4
AJ
265 if (ctx->access_type != access_type) {
266 tcg_gen_movi_i32(cpu_access_type, access_type);
267 ctx->access_type = access_type;
268 }
a7859e89
AJ
269}
270
636aa200 271static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
d9bce9d9 272{
e0c8f9ce
RH
273 if (NARROW_MODE(ctx)) {
274 nip = (uint32_t)nip;
275 }
276 tcg_gen_movi_tl(cpu_nip, nip);
d9bce9d9
JM
277}
278
7019cb3d
AK
279void gen_update_current_nip(void *opaque)
280{
281 DisasContext *ctx = opaque;
282
283 tcg_gen_movi_tl(cpu_nip, ctx->nip);
284}
285
636aa200 286static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
e06fcd75
AJ
287{
288 TCGv_i32 t0, t1;
289 if (ctx->exception == POWERPC_EXCP_NONE) {
290 gen_update_nip(ctx, ctx->nip);
291 }
292 t0 = tcg_const_i32(excp);
293 t1 = tcg_const_i32(error);
e5f17ac6 294 gen_helper_raise_exception_err(cpu_env, t0, t1);
e06fcd75
AJ
295 tcg_temp_free_i32(t0);
296 tcg_temp_free_i32(t1);
297 ctx->exception = (excp);
298}
e1833e1f 299
636aa200 300static inline void gen_exception(DisasContext *ctx, uint32_t excp)
e06fcd75
AJ
301{
302 TCGv_i32 t0;
303 if (ctx->exception == POWERPC_EXCP_NONE) {
304 gen_update_nip(ctx, ctx->nip);
305 }
306 t0 = tcg_const_i32(excp);
e5f17ac6 307 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
308 tcg_temp_free_i32(t0);
309 ctx->exception = (excp);
310}
e1833e1f 311
636aa200 312static inline void gen_debug_exception(DisasContext *ctx)
e06fcd75
AJ
313{
314 TCGv_i32 t0;
5518f3a6 315
ee2b3994
SB
316 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
317 (ctx->exception != POWERPC_EXCP_SYNC)) {
5518f3a6 318 gen_update_nip(ctx, ctx->nip);
ee2b3994 319 }
e06fcd75 320 t0 = tcg_const_i32(EXCP_DEBUG);
e5f17ac6 321 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
322 tcg_temp_free_i32(t0);
323}
9a64fbe4 324
636aa200 325static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
e06fcd75
AJ
326{
327 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
328}
a9d9eb8f 329
f24e5695 330/* Stop translation */
636aa200 331static inline void gen_stop_exception(DisasContext *ctx)
3fc6c082 332{
d9bce9d9 333 gen_update_nip(ctx, ctx->nip);
e1833e1f 334 ctx->exception = POWERPC_EXCP_STOP;
3fc6c082
FB
335}
336
466976d9 337#ifndef CONFIG_USER_ONLY
f24e5695 338/* No need to update nip here, as execution flow will change */
636aa200 339static inline void gen_sync_exception(DisasContext *ctx)
2be0071f 340{
e1833e1f 341 ctx->exception = POWERPC_EXCP_SYNC;
2be0071f 342}
466976d9 343#endif
2be0071f 344
79aceca5 345#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
346GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
347
348#define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
349GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
79aceca5 350
c7697e1f 351#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
352GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
353
354#define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
355GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
c7697e1f 356
c227f099 357typedef struct opcode_t {
79aceca5 358 unsigned char opc1, opc2, opc3;
1235fc06 359#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
18fba28c
FB
360 unsigned char pad[5];
361#else
362 unsigned char pad[1];
363#endif
c227f099 364 opc_handler_t handler;
b55266b5 365 const char *oname;
c227f099 366} opcode_t;
79aceca5 367
a750fc0b 368/*****************************************************************************/
79aceca5
FB
369/*** Instruction decoding ***/
370#define EXTRACT_HELPER(name, shift, nb) \
636aa200 371static inline uint32_t name(uint32_t opcode) \
79aceca5
FB
372{ \
373 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
374}
375
376#define EXTRACT_SHELPER(name, shift, nb) \
636aa200 377static inline int32_t name(uint32_t opcode) \
79aceca5 378{ \
18fba28c 379 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
79aceca5
FB
380}
381
f9fc6d81
TM
382#define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
383static inline uint32_t name(uint32_t opcode) \
384{ \
385 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
386 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
387}
79aceca5
FB
388/* Opcode part 1 */
389EXTRACT_HELPER(opc1, 26, 6);
390/* Opcode part 2 */
391EXTRACT_HELPER(opc2, 1, 5);
392/* Opcode part 3 */
393EXTRACT_HELPER(opc3, 6, 5);
394/* Update Cr0 flags */
395EXTRACT_HELPER(Rc, 0, 1);
a737d3eb
TM
396/* Update Cr6 flags (Altivec) */
397EXTRACT_HELPER(Rc21, 10, 1);
79aceca5
FB
398/* Destination */
399EXTRACT_HELPER(rD, 21, 5);
400/* Source */
401EXTRACT_HELPER(rS, 21, 5);
402/* First operand */
403EXTRACT_HELPER(rA, 16, 5);
404/* Second operand */
405EXTRACT_HELPER(rB, 11, 5);
406/* Third operand */
407EXTRACT_HELPER(rC, 6, 5);
408/*** Get CRn ***/
409EXTRACT_HELPER(crfD, 23, 3);
410EXTRACT_HELPER(crfS, 18, 3);
411EXTRACT_HELPER(crbD, 21, 5);
412EXTRACT_HELPER(crbA, 16, 5);
413EXTRACT_HELPER(crbB, 11, 5);
414/* SPR / TBL */
3fc6c082 415EXTRACT_HELPER(_SPR, 11, 10);
636aa200 416static inline uint32_t SPR(uint32_t opcode)
3fc6c082
FB
417{
418 uint32_t sprn = _SPR(opcode);
419
420 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
421}
79aceca5 422/*** Get constants ***/
79aceca5
FB
423/* 16 bits signed immediate value */
424EXTRACT_SHELPER(SIMM, 0, 16);
425/* 16 bits unsigned immediate value */
426EXTRACT_HELPER(UIMM, 0, 16);
21d21583
AJ
427/* 5 bits signed immediate value */
428EXTRACT_HELPER(SIMM5, 16, 5);
27a4edb3
AJ
429/* 5 bits signed immediate value */
430EXTRACT_HELPER(UIMM5, 16, 5);
79aceca5
FB
431/* Bit count */
432EXTRACT_HELPER(NB, 11, 5);
433/* Shift count */
434EXTRACT_HELPER(SH, 11, 5);
cd633b10
AJ
435/* Vector shift count */
436EXTRACT_HELPER(VSH, 6, 4);
79aceca5
FB
437/* Mask start */
438EXTRACT_HELPER(MB, 6, 5);
439/* Mask end */
440EXTRACT_HELPER(ME, 1, 5);
fb0eaffc
FB
441/* Trap operand */
442EXTRACT_HELPER(TO, 21, 5);
79aceca5
FB
443
444EXTRACT_HELPER(CRM, 12, 8);
466976d9
PM
445
446#ifndef CONFIG_USER_ONLY
79aceca5 447EXTRACT_HELPER(SR, 16, 4);
466976d9 448#endif
7d08d856
AJ
449
450/* mtfsf/mtfsfi */
779f6590 451EXTRACT_HELPER(FPBF, 23, 3);
e4bb997e 452EXTRACT_HELPER(FPIMM, 12, 4);
779f6590 453EXTRACT_HELPER(FPL, 25, 1);
7d08d856
AJ
454EXTRACT_HELPER(FPFLM, 17, 8);
455EXTRACT_HELPER(FPW, 16, 1);
fb0eaffc 456
79aceca5 457/*** Jump target decoding ***/
79aceca5 458/* Immediate address */
636aa200 459static inline target_ulong LI(uint32_t opcode)
79aceca5
FB
460{
461 return (opcode >> 0) & 0x03FFFFFC;
462}
463
636aa200 464static inline uint32_t BD(uint32_t opcode)
79aceca5
FB
465{
466 return (opcode >> 0) & 0xFFFC;
467}
468
469EXTRACT_HELPER(BO, 21, 5);
470EXTRACT_HELPER(BI, 16, 5);
471/* Absolute/relative address */
472EXTRACT_HELPER(AA, 1, 1);
473/* Link */
474EXTRACT_HELPER(LK, 0, 1);
475
f0b01f02
TM
476/* DFP Z22-form */
477EXTRACT_HELPER(DCM, 10, 6)
478
479/* DFP Z23-form */
480EXTRACT_HELPER(RMC, 9, 2)
481
79aceca5 482/* Create a mask between <start> and <end> bits */
636aa200 483static inline target_ulong MASK(uint32_t start, uint32_t end)
79aceca5 484{
76a66253 485 target_ulong ret;
79aceca5 486
76a66253
JM
487#if defined(TARGET_PPC64)
488 if (likely(start == 0)) {
6f2d8978 489 ret = UINT64_MAX << (63 - end);
76a66253 490 } else if (likely(end == 63)) {
6f2d8978 491 ret = UINT64_MAX >> start;
76a66253
JM
492 }
493#else
494 if (likely(start == 0)) {
6f2d8978 495 ret = UINT32_MAX << (31 - end);
76a66253 496 } else if (likely(end == 31)) {
6f2d8978 497 ret = UINT32_MAX >> start;
76a66253
JM
498 }
499#endif
500 else {
501 ret = (((target_ulong)(-1ULL)) >> (start)) ^
502 (((target_ulong)(-1ULL) >> (end)) >> 1);
503 if (unlikely(start > end))
504 return ~ret;
505 }
79aceca5
FB
506
507 return ret;
508}
509
f9fc6d81
TM
510EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
511EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
512EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
513EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
551e3ef7 514EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
f9fc6d81 515EXTRACT_HELPER(DM, 8, 2);
76c15fe0 516EXTRACT_HELPER(UIM, 16, 2);
acc42968 517EXTRACT_HELPER(SHW, 8, 2);
f0b01f02 518EXTRACT_HELPER(SP, 19, 2);
a750fc0b 519/*****************************************************************************/
a750fc0b 520/* PowerPC instructions table */
933dc6eb 521
76a66253 522#if defined(DO_PPC_STATISTICS)
a5858d7a 523#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 524{ \
79aceca5
FB
525 .opc1 = op1, \
526 .opc2 = op2, \
527 .opc3 = op3, \
18fba28c 528 .pad = { 0, }, \
79aceca5 529 .handler = { \
70560da7
FC
530 .inval1 = invl, \
531 .type = _typ, \
532 .type2 = _typ2, \
533 .handler = &gen_##name, \
534 .oname = stringify(name), \
535 }, \
536 .oname = stringify(name), \
537}
538#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
539{ \
540 .opc1 = op1, \
541 .opc2 = op2, \
542 .opc3 = op3, \
543 .pad = { 0, }, \
544 .handler = { \
545 .inval1 = invl1, \
546 .inval2 = invl2, \
9a64fbe4 547 .type = _typ, \
a5858d7a 548 .type2 = _typ2, \
79aceca5 549 .handler = &gen_##name, \
76a66253 550 .oname = stringify(name), \
79aceca5 551 }, \
3fc6c082 552 .oname = stringify(name), \
79aceca5 553}
a5858d7a 554#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 555{ \
c7697e1f
JM
556 .opc1 = op1, \
557 .opc2 = op2, \
558 .opc3 = op3, \
559 .pad = { 0, }, \
560 .handler = { \
70560da7 561 .inval1 = invl, \
c7697e1f 562 .type = _typ, \
a5858d7a 563 .type2 = _typ2, \
c7697e1f
JM
564 .handler = &gen_##name, \
565 .oname = onam, \
566 }, \
567 .oname = onam, \
568}
76a66253 569#else
a5858d7a 570#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 571{ \
c7697e1f
JM
572 .opc1 = op1, \
573 .opc2 = op2, \
574 .opc3 = op3, \
575 .pad = { 0, }, \
576 .handler = { \
70560da7
FC
577 .inval1 = invl, \
578 .type = _typ, \
579 .type2 = _typ2, \
580 .handler = &gen_##name, \
581 }, \
582 .oname = stringify(name), \
583}
584#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
585{ \
586 .opc1 = op1, \
587 .opc2 = op2, \
588 .opc3 = op3, \
589 .pad = { 0, }, \
590 .handler = { \
591 .inval1 = invl1, \
592 .inval2 = invl2, \
c7697e1f 593 .type = _typ, \
a5858d7a 594 .type2 = _typ2, \
c7697e1f 595 .handler = &gen_##name, \
5c55ff99
BS
596 }, \
597 .oname = stringify(name), \
598}
a5858d7a 599#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99
BS
600{ \
601 .opc1 = op1, \
602 .opc2 = op2, \
603 .opc3 = op3, \
604 .pad = { 0, }, \
605 .handler = { \
70560da7 606 .inval1 = invl, \
5c55ff99 607 .type = _typ, \
a5858d7a 608 .type2 = _typ2, \
5c55ff99
BS
609 .handler = &gen_##name, \
610 }, \
611 .oname = onam, \
612}
613#endif
2e610050 614
5c55ff99 615/* SPR load/store helpers */
636aa200 616static inline void gen_load_spr(TCGv t, int reg)
5c55ff99 617{
1328c2bf 618 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 619}
2e610050 620
636aa200 621static inline void gen_store_spr(int reg, TCGv t)
5c55ff99 622{
1328c2bf 623 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 624}
2e610050 625
54623277 626/* Invalid instruction */
99e300ef 627static void gen_invalid(DisasContext *ctx)
9a64fbe4 628{
e06fcd75 629 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
9a64fbe4
FB
630}
631
c227f099 632static opc_handler_t invalid_handler = {
70560da7
FC
633 .inval1 = 0xFFFFFFFF,
634 .inval2 = 0xFFFFFFFF,
9a64fbe4 635 .type = PPC_NONE,
a5858d7a 636 .type2 = PPC_NONE,
79aceca5
FB
637 .handler = gen_invalid,
638};
639
e1571908
AJ
640/*** Integer comparison ***/
641
636aa200 642static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 643{
2fdcb629
RH
644 TCGv t0 = tcg_temp_new();
645 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 646
da91a00f 647 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 648
2fdcb629
RH
649 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
650 tcg_gen_trunc_tl_i32(t1, t0);
651 tcg_gen_shli_i32(t1, t1, CRF_LT);
652 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
653
654 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
655 tcg_gen_trunc_tl_i32(t1, t0);
656 tcg_gen_shli_i32(t1, t1, CRF_GT);
657 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
658
659 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
660 tcg_gen_trunc_tl_i32(t1, t0);
661 tcg_gen_shli_i32(t1, t1, CRF_EQ);
662 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
663
664 tcg_temp_free(t0);
665 tcg_temp_free_i32(t1);
e1571908
AJ
666}
667
636aa200 668static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 669{
2fdcb629 670 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
671 gen_op_cmp(arg0, t0, s, crf);
672 tcg_temp_free(t0);
e1571908
AJ
673}
674
636aa200 675static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 676{
ea363694 677 TCGv t0, t1;
2fdcb629
RH
678 t0 = tcg_temp_new();
679 t1 = tcg_temp_new();
e1571908 680 if (s) {
ea363694
AJ
681 tcg_gen_ext32s_tl(t0, arg0);
682 tcg_gen_ext32s_tl(t1, arg1);
e1571908 683 } else {
ea363694
AJ
684 tcg_gen_ext32u_tl(t0, arg0);
685 tcg_gen_ext32u_tl(t1, arg1);
e1571908 686 }
ea363694
AJ
687 gen_op_cmp(t0, t1, s, crf);
688 tcg_temp_free(t1);
689 tcg_temp_free(t0);
e1571908
AJ
690}
691
636aa200 692static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 693{
2fdcb629 694 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
695 gen_op_cmp32(arg0, t0, s, crf);
696 tcg_temp_free(t0);
e1571908 697}
e1571908 698
636aa200 699static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908 700{
02765534 701 if (NARROW_MODE(ctx)) {
e1571908 702 gen_op_cmpi32(reg, 0, 1, 0);
02765534 703 } else {
e1571908 704 gen_op_cmpi(reg, 0, 1, 0);
02765534 705 }
e1571908
AJ
706}
707
708/* cmp */
99e300ef 709static void gen_cmp(DisasContext *ctx)
e1571908 710{
36f48d9c 711 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
712 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
713 1, crfD(ctx->opcode));
36f48d9c
AG
714 } else {
715 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
716 1, crfD(ctx->opcode));
02765534 717 }
e1571908
AJ
718}
719
720/* cmpi */
99e300ef 721static void gen_cmpi(DisasContext *ctx)
e1571908 722{
36f48d9c 723 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
724 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
725 1, crfD(ctx->opcode));
36f48d9c
AG
726 } else {
727 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
728 1, crfD(ctx->opcode));
02765534 729 }
e1571908
AJ
730}
731
732/* cmpl */
99e300ef 733static void gen_cmpl(DisasContext *ctx)
e1571908 734{
36f48d9c 735 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
736 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
737 0, crfD(ctx->opcode));
36f48d9c
AG
738 } else {
739 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
740 0, crfD(ctx->opcode));
02765534 741 }
e1571908
AJ
742}
743
744/* cmpli */
99e300ef 745static void gen_cmpli(DisasContext *ctx)
e1571908 746{
36f48d9c 747 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
748 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
749 0, crfD(ctx->opcode));
36f48d9c
AG
750 } else {
751 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
752 0, crfD(ctx->opcode));
02765534 753 }
e1571908
AJ
754}
755
756/* isel (PowerPC 2.03 specification) */
99e300ef 757static void gen_isel(DisasContext *ctx)
e1571908 758{
e1571908 759 uint32_t bi = rC(ctx->opcode);
24f9cd95
RH
760 uint32_t mask = 0x08 >> (bi & 0x03);
761 TCGv t0 = tcg_temp_new();
762 TCGv zr;
e1571908 763
24f9cd95
RH
764 tcg_gen_extu_i32_tl(t0, cpu_crf[bi >> 2]);
765 tcg_gen_andi_tl(t0, t0, mask);
766
767 zr = tcg_const_tl(0);
768 tcg_gen_movcond_tl(TCG_COND_NE, cpu_gpr[rD(ctx->opcode)], t0, zr,
769 rA(ctx->opcode) ? cpu_gpr[rA(ctx->opcode)] : zr,
770 cpu_gpr[rB(ctx->opcode)]);
771 tcg_temp_free(zr);
772 tcg_temp_free(t0);
e1571908
AJ
773}
774
fcfda20f
AJ
775/* cmpb: PowerPC 2.05 specification */
776static void gen_cmpb(DisasContext *ctx)
777{
778 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
779 cpu_gpr[rB(ctx->opcode)]);
780}
781
79aceca5 782/*** Integer arithmetic ***/
79aceca5 783
636aa200
BS
784static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
785 TCGv arg1, TCGv arg2, int sub)
74637406 786{
ffe30937 787 TCGv t0 = tcg_temp_new();
79aceca5 788
8e7a6db9 789 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
74637406 790 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
791 if (sub) {
792 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
793 } else {
794 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
795 }
796 tcg_temp_free(t0);
02765534 797 if (NARROW_MODE(ctx)) {
ffe30937
RH
798 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
799 }
ffe30937
RH
800 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
801 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
802}
803
74637406 804/* Common add function */
636aa200 805static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
806 TCGv arg2, bool add_ca, bool compute_ca,
807 bool compute_ov, bool compute_rc0)
74637406 808{
b5a73f8d 809 TCGv t0 = ret;
d9bce9d9 810
752d634e 811 if (compute_ca || compute_ov) {
146de60d 812 t0 = tcg_temp_new();
74637406 813 }
79aceca5 814
da91a00f 815 if (compute_ca) {
79482e5a 816 if (NARROW_MODE(ctx)) {
752d634e
RH
817 /* Caution: a non-obvious corner case of the spec is that we
818 must produce the *entire* 64-bit addition, but produce the
819 carry into bit 32. */
79482e5a 820 TCGv t1 = tcg_temp_new();
752d634e
RH
821 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
822 tcg_gen_add_tl(t0, arg1, arg2);
79482e5a
RH
823 if (add_ca) {
824 tcg_gen_add_tl(t0, t0, cpu_ca);
825 }
752d634e
RH
826 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
827 tcg_temp_free(t1);
828 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
829 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
b5a73f8d 830 } else {
79482e5a
RH
831 TCGv zero = tcg_const_tl(0);
832 if (add_ca) {
833 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
834 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
835 } else {
836 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
837 }
838 tcg_temp_free(zero);
b5a73f8d 839 }
b5a73f8d
RH
840 } else {
841 tcg_gen_add_tl(t0, arg1, arg2);
842 if (add_ca) {
843 tcg_gen_add_tl(t0, t0, cpu_ca);
844 }
da91a00f 845 }
79aceca5 846
74637406
AJ
847 if (compute_ov) {
848 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
849 }
b5a73f8d 850 if (unlikely(compute_rc0)) {
74637406 851 gen_set_Rc0(ctx, t0);
b5a73f8d 852 }
74637406 853
a7812ae4 854 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
855 tcg_gen_mov_tl(ret, t0);
856 tcg_temp_free(t0);
857 }
39dd32ee 858}
74637406
AJ
859/* Add functions with two operands */
860#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 861static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
862{ \
863 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
864 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 865 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
866}
867/* Add functions with one operand and one immediate */
868#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
869 add_ca, compute_ca, compute_ov) \
b5a73f8d 870static void glue(gen_, name)(DisasContext *ctx) \
74637406 871{ \
b5a73f8d 872 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
873 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
874 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 875 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
876 tcg_temp_free(t0); \
877}
878
879/* add add. addo addo. */
880GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
881GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
882/* addc addc. addco addco. */
883GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
884GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
885/* adde adde. addeo addeo. */
886GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
887GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
888/* addme addme. addmeo addmeo. */
889GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
890GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
891/* addze addze. addzeo addzeo.*/
892GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
893GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
894/* addi */
99e300ef 895static void gen_addi(DisasContext *ctx)
d9bce9d9 896{
74637406
AJ
897 target_long simm = SIMM(ctx->opcode);
898
899 if (rA(ctx->opcode) == 0) {
900 /* li case */
901 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
902 } else {
b5a73f8d
RH
903 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
904 cpu_gpr[rA(ctx->opcode)], simm);
74637406 905 }
d9bce9d9 906}
74637406 907/* addic addic.*/
b5a73f8d 908static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 909{
b5a73f8d
RH
910 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
911 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
912 c, 0, 1, 0, compute_rc0);
913 tcg_temp_free(c);
d9bce9d9 914}
99e300ef
BS
915
916static void gen_addic(DisasContext *ctx)
d9bce9d9 917{
b5a73f8d 918 gen_op_addic(ctx, 0);
d9bce9d9 919}
e8eaa2c0
BS
920
921static void gen_addic_(DisasContext *ctx)
d9bce9d9 922{
b5a73f8d 923 gen_op_addic(ctx, 1);
d9bce9d9 924}
99e300ef 925
54623277 926/* addis */
99e300ef 927static void gen_addis(DisasContext *ctx)
d9bce9d9 928{
74637406
AJ
929 target_long simm = SIMM(ctx->opcode);
930
931 if (rA(ctx->opcode) == 0) {
932 /* lis case */
933 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
934 } else {
b5a73f8d
RH
935 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
936 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 937 }
d9bce9d9 938}
74637406 939
636aa200
BS
940static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
941 TCGv arg2, int sign, int compute_ov)
d9bce9d9 942{
42a268c2
RH
943 TCGLabel *l1 = gen_new_label();
944 TCGLabel *l2 = gen_new_label();
a7812ae4
PB
945 TCGv_i32 t0 = tcg_temp_local_new_i32();
946 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 947
2ef1b120
AJ
948 tcg_gen_trunc_tl_i32(t0, arg1);
949 tcg_gen_trunc_tl_i32(t1, arg2);
950 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 951 if (sign) {
42a268c2 952 TCGLabel *l3 = gen_new_label();
2ef1b120
AJ
953 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
954 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 955 gen_set_label(l3);
2ef1b120 956 tcg_gen_div_i32(t0, t0, t1);
74637406 957 } else {
2ef1b120 958 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
959 }
960 if (compute_ov) {
da91a00f 961 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
962 }
963 tcg_gen_br(l2);
964 gen_set_label(l1);
965 if (sign) {
2ef1b120 966 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
967 } else {
968 tcg_gen_movi_i32(t0, 0);
969 }
970 if (compute_ov) {
da91a00f
RH
971 tcg_gen_movi_tl(cpu_ov, 1);
972 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
973 }
974 gen_set_label(l2);
2ef1b120 975 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
976 tcg_temp_free_i32(t0);
977 tcg_temp_free_i32(t1);
74637406
AJ
978 if (unlikely(Rc(ctx->opcode) != 0))
979 gen_set_Rc0(ctx, ret);
d9bce9d9 980}
74637406
AJ
981/* Div functions */
982#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 983static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
984{ \
985 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
986 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
987 sign, compute_ov); \
988}
989/* divwu divwu. divwuo divwuo. */
990GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
991GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
992/* divw divw. divwo divwo. */
993GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
994GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
98d1eb27
TM
995
996/* div[wd]eu[o][.] */
997#define GEN_DIVE(name, hlpr, compute_ov) \
998static void gen_##name(DisasContext *ctx) \
999{ \
1000 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1001 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1002 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1003 tcg_temp_free_i32(t0); \
1004 if (unlikely(Rc(ctx->opcode) != 0)) { \
1005 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1006 } \
1007}
1008
6a4fda33
TM
1009GEN_DIVE(divweu, divweu, 0);
1010GEN_DIVE(divweuo, divweu, 1);
a98eb9e9
TM
1011GEN_DIVE(divwe, divwe, 0);
1012GEN_DIVE(divweo, divwe, 1);
6a4fda33 1013
d9bce9d9 1014#if defined(TARGET_PPC64)
636aa200
BS
1015static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
1016 TCGv arg2, int sign, int compute_ov)
d9bce9d9 1017{
42a268c2
RH
1018 TCGLabel *l1 = gen_new_label();
1019 TCGLabel *l2 = gen_new_label();
74637406
AJ
1020
1021 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1022 if (sign) {
42a268c2 1023 TCGLabel *l3 = gen_new_label();
74637406
AJ
1024 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1025 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1026 gen_set_label(l3);
74637406
AJ
1027 tcg_gen_div_i64(ret, arg1, arg2);
1028 } else {
1029 tcg_gen_divu_i64(ret, arg1, arg2);
1030 }
1031 if (compute_ov) {
da91a00f 1032 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
1033 }
1034 tcg_gen_br(l2);
1035 gen_set_label(l1);
1036 if (sign) {
1037 tcg_gen_sari_i64(ret, arg1, 63);
1038 } else {
1039 tcg_gen_movi_i64(ret, 0);
1040 }
1041 if (compute_ov) {
da91a00f
RH
1042 tcg_gen_movi_tl(cpu_ov, 1);
1043 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1044 }
1045 gen_set_label(l2);
1046 if (unlikely(Rc(ctx->opcode) != 0))
1047 gen_set_Rc0(ctx, ret);
d9bce9d9 1048}
74637406 1049#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 1050static void glue(gen_, name)(DisasContext *ctx) \
74637406 1051{ \
2ef1b120
AJ
1052 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1053 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1054 sign, compute_ov); \
74637406
AJ
1055}
1056/* divwu divwu. divwuo divwuo. */
1057GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1058GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1059/* divw divw. divwo divwo. */
1060GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1061GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
98d1eb27
TM
1062
1063GEN_DIVE(divdeu, divdeu, 0);
1064GEN_DIVE(divdeuo, divdeu, 1);
e44259b6
TM
1065GEN_DIVE(divde, divde, 0);
1066GEN_DIVE(divdeo, divde, 1);
d9bce9d9 1067#endif
74637406
AJ
1068
1069/* mulhw mulhw. */
99e300ef 1070static void gen_mulhw(DisasContext *ctx)
d9bce9d9 1071{
23ad1d5d
RH
1072 TCGv_i32 t0 = tcg_temp_new_i32();
1073 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1074
23ad1d5d
RH
1075 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1076 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1077 tcg_gen_muls2_i32(t0, t1, t0, t1);
1078 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1079 tcg_temp_free_i32(t0);
1080 tcg_temp_free_i32(t1);
74637406
AJ
1081 if (unlikely(Rc(ctx->opcode) != 0))
1082 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1083}
99e300ef 1084
54623277 1085/* mulhwu mulhwu. */
99e300ef 1086static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1087{
23ad1d5d
RH
1088 TCGv_i32 t0 = tcg_temp_new_i32();
1089 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1090
23ad1d5d
RH
1091 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1092 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1093 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1094 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1095 tcg_temp_free_i32(t0);
1096 tcg_temp_free_i32(t1);
74637406
AJ
1097 if (unlikely(Rc(ctx->opcode) != 0))
1098 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1099}
99e300ef 1100
54623277 1101/* mullw mullw. */
99e300ef 1102static void gen_mullw(DisasContext *ctx)
d9bce9d9 1103{
1fa74845
TM
1104#if defined(TARGET_PPC64)
1105 TCGv_i64 t0, t1;
1106 t0 = tcg_temp_new_i64();
1107 t1 = tcg_temp_new_i64();
1108 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1109 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1110 tcg_gen_mul_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);
1111 tcg_temp_free(t0);
1112 tcg_temp_free(t1);
1113#else
03039e5e
TM
1114 tcg_gen_mul_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1115 cpu_gpr[rB(ctx->opcode)]);
1fa74845 1116#endif
74637406
AJ
1117 if (unlikely(Rc(ctx->opcode) != 0))
1118 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1119}
99e300ef 1120
54623277 1121/* mullwo mullwo. */
99e300ef 1122static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1123{
e4a2c846
RH
1124 TCGv_i32 t0 = tcg_temp_new_i32();
1125 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1126
e4a2c846
RH
1127 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1128 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1129 tcg_gen_muls2_i32(t0, t1, t0, t1);
f11ebbf8 1130#if defined(TARGET_PPC64)
26977876
TM
1131 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);
1132#else
1133 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], t0);
f11ebbf8 1134#endif
e4a2c846
RH
1135
1136 tcg_gen_sari_i32(t0, t0, 31);
1137 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1138 tcg_gen_extu_i32_tl(cpu_ov, t0);
1139 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1140
1141 tcg_temp_free_i32(t0);
1142 tcg_temp_free_i32(t1);
74637406
AJ
1143 if (unlikely(Rc(ctx->opcode) != 0))
1144 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1145}
99e300ef 1146
54623277 1147/* mulli */
99e300ef 1148static void gen_mulli(DisasContext *ctx)
d9bce9d9 1149{
74637406
AJ
1150 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1151 SIMM(ctx->opcode));
d9bce9d9 1152}
23ad1d5d 1153
d9bce9d9 1154#if defined(TARGET_PPC64)
74637406 1155/* mulhd mulhd. */
23ad1d5d
RH
1156static void gen_mulhd(DisasContext *ctx)
1157{
1158 TCGv lo = tcg_temp_new();
1159 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1160 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1161 tcg_temp_free(lo);
1162 if (unlikely(Rc(ctx->opcode) != 0)) {
1163 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1164 }
1165}
1166
74637406 1167/* mulhdu mulhdu. */
23ad1d5d
RH
1168static void gen_mulhdu(DisasContext *ctx)
1169{
1170 TCGv lo = tcg_temp_new();
1171 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1172 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1173 tcg_temp_free(lo);
1174 if (unlikely(Rc(ctx->opcode) != 0)) {
1175 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1176 }
1177}
99e300ef 1178
54623277 1179/* mulld mulld. */
99e300ef 1180static void gen_mulld(DisasContext *ctx)
d9bce9d9 1181{
74637406
AJ
1182 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1183 cpu_gpr[rB(ctx->opcode)]);
1184 if (unlikely(Rc(ctx->opcode) != 0))
1185 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1186}
d15f74fb 1187
74637406 1188/* mulldo mulldo. */
d15f74fb
BS
1189static void gen_mulldo(DisasContext *ctx)
1190{
22ffad31
TM
1191 TCGv_i64 t0 = tcg_temp_new_i64();
1192 TCGv_i64 t1 = tcg_temp_new_i64();
1193
1194 tcg_gen_muls2_i64(t0, t1, cpu_gpr[rA(ctx->opcode)],
1195 cpu_gpr[rB(ctx->opcode)]);
1196 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], t0);
1197
1198 tcg_gen_sari_i64(t0, t0, 63);
1199 tcg_gen_setcond_i64(TCG_COND_NE, cpu_ov, t0, t1);
1200 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1201
1202 tcg_temp_free_i64(t0);
1203 tcg_temp_free_i64(t1);
1204
d15f74fb
BS
1205 if (unlikely(Rc(ctx->opcode) != 0)) {
1206 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1207 }
1208}
d9bce9d9 1209#endif
74637406 1210
74637406 1211/* Common subf function */
636aa200 1212static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1213 TCGv arg2, bool add_ca, bool compute_ca,
1214 bool compute_ov, bool compute_rc0)
79aceca5 1215{
b5a73f8d 1216 TCGv t0 = ret;
79aceca5 1217
752d634e 1218 if (compute_ca || compute_ov) {
b5a73f8d 1219 t0 = tcg_temp_new();
da91a00f 1220 }
74637406 1221
79482e5a
RH
1222 if (compute_ca) {
1223 /* dest = ~arg1 + arg2 [+ ca]. */
1224 if (NARROW_MODE(ctx)) {
752d634e
RH
1225 /* Caution: a non-obvious corner case of the spec is that we
1226 must produce the *entire* 64-bit addition, but produce the
1227 carry into bit 32. */
79482e5a 1228 TCGv inv1 = tcg_temp_new();
752d634e 1229 TCGv t1 = tcg_temp_new();
79482e5a 1230 tcg_gen_not_tl(inv1, arg1);
79482e5a 1231 if (add_ca) {
752d634e 1232 tcg_gen_add_tl(t0, arg2, cpu_ca);
79482e5a 1233 } else {
752d634e 1234 tcg_gen_addi_tl(t0, arg2, 1);
79482e5a 1235 }
752d634e 1236 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
79482e5a 1237 tcg_gen_add_tl(t0, t0, inv1);
c80d1df5 1238 tcg_temp_free(inv1);
752d634e
RH
1239 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1240 tcg_temp_free(t1);
1241 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1242 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
79482e5a 1243 } else if (add_ca) {
08f4a0f7
RH
1244 TCGv zero, inv1 = tcg_temp_new();
1245 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1246 zero = tcg_const_tl(0);
1247 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1248 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1249 tcg_temp_free(zero);
08f4a0f7 1250 tcg_temp_free(inv1);
b5a73f8d 1251 } else {
79482e5a 1252 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
b5a73f8d 1253 tcg_gen_sub_tl(t0, arg2, arg1);
b5a73f8d 1254 }
79482e5a
RH
1255 } else if (add_ca) {
1256 /* Since we're ignoring carry-out, we can simplify the
1257 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1258 tcg_gen_sub_tl(t0, arg2, arg1);
1259 tcg_gen_add_tl(t0, t0, cpu_ca);
1260 tcg_gen_subi_tl(t0, t0, 1);
79aceca5 1261 } else {
b5a73f8d 1262 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1263 }
b5a73f8d 1264
74637406
AJ
1265 if (compute_ov) {
1266 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1267 }
b5a73f8d 1268 if (unlikely(compute_rc0)) {
74637406 1269 gen_set_Rc0(ctx, t0);
b5a73f8d 1270 }
74637406 1271
a7812ae4 1272 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1273 tcg_gen_mov_tl(ret, t0);
1274 tcg_temp_free(t0);
79aceca5 1275 }
79aceca5 1276}
74637406
AJ
1277/* Sub functions with Two operands functions */
1278#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1279static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1280{ \
1281 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1282 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1283 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1284}
1285/* Sub functions with one operand and one immediate */
1286#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1287 add_ca, compute_ca, compute_ov) \
b5a73f8d 1288static void glue(gen_, name)(DisasContext *ctx) \
74637406 1289{ \
b5a73f8d 1290 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1291 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1292 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1293 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1294 tcg_temp_free(t0); \
1295}
1296/* subf subf. subfo subfo. */
1297GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1298GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1299/* subfc subfc. subfco subfco. */
1300GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1301GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1302/* subfe subfe. subfeo subfo. */
1303GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1304GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1305/* subfme subfme. subfmeo subfmeo. */
1306GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1307GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1308/* subfze subfze. subfzeo subfzeo.*/
1309GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1310GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1311
54623277 1312/* subfic */
99e300ef 1313static void gen_subfic(DisasContext *ctx)
79aceca5 1314{
b5a73f8d
RH
1315 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1316 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1317 c, 0, 1, 0, 0);
1318 tcg_temp_free(c);
79aceca5
FB
1319}
1320
fd3f0081
RH
1321/* neg neg. nego nego. */
1322static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1323{
1324 TCGv zero = tcg_const_tl(0);
1325 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1326 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1327 tcg_temp_free(zero);
1328}
1329
1330static void gen_neg(DisasContext *ctx)
1331{
1332 gen_op_arith_neg(ctx, 0);
1333}
1334
1335static void gen_nego(DisasContext *ctx)
1336{
1337 gen_op_arith_neg(ctx, 1);
1338}
1339
79aceca5 1340/*** Integer logical ***/
26d67362 1341#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1342static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1343{ \
26d67362
AJ
1344 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1345 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1346 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1347 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1348}
79aceca5 1349
26d67362 1350#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1351static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1352{ \
26d67362 1353 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1354 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1355 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1356}
1357
1358/* and & and. */
26d67362 1359GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1360/* andc & andc. */
26d67362 1361GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1362
54623277 1363/* andi. */
e8eaa2c0 1364static void gen_andi_(DisasContext *ctx)
79aceca5 1365{
26d67362
AJ
1366 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1367 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1368}
e8eaa2c0 1369
54623277 1370/* andis. */
e8eaa2c0 1371static void gen_andis_(DisasContext *ctx)
79aceca5 1372{
26d67362
AJ
1373 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1374 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1375}
99e300ef 1376
54623277 1377/* cntlzw */
99e300ef 1378static void gen_cntlzw(DisasContext *ctx)
26d67362 1379{
a7812ae4 1380 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1381 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1382 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1383}
79aceca5 1384/* eqv & eqv. */
26d67362 1385GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1386/* extsb & extsb. */
26d67362 1387GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1388/* extsh & extsh. */
26d67362 1389GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1390/* nand & nand. */
26d67362 1391GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1392/* nor & nor. */
26d67362 1393GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1394
54623277 1395/* or & or. */
99e300ef 1396static void gen_or(DisasContext *ctx)
9a64fbe4 1397{
76a66253
JM
1398 int rs, ra, rb;
1399
1400 rs = rS(ctx->opcode);
1401 ra = rA(ctx->opcode);
1402 rb = rB(ctx->opcode);
1403 /* Optimisation for mr. ri case */
1404 if (rs != ra || rs != rb) {
26d67362
AJ
1405 if (rs != rb)
1406 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1407 else
1408 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1409 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1410 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1411 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1412 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1413#if defined(TARGET_PPC64)
1414 } else {
26d67362
AJ
1415 int prio = 0;
1416
c80f84e3
JM
1417 switch (rs) {
1418 case 1:
1419 /* Set process priority to low */
26d67362 1420 prio = 2;
c80f84e3
JM
1421 break;
1422 case 6:
1423 /* Set process priority to medium-low */
26d67362 1424 prio = 3;
c80f84e3
JM
1425 break;
1426 case 2:
1427 /* Set process priority to normal */
26d67362 1428 prio = 4;
c80f84e3 1429 break;
be147d08
JM
1430#if !defined(CONFIG_USER_ONLY)
1431 case 31:
c47493f2 1432 if (!ctx->pr) {
be147d08 1433 /* Set process priority to very low */
26d67362 1434 prio = 1;
be147d08
JM
1435 }
1436 break;
1437 case 5:
c47493f2 1438 if (!ctx->pr) {
be147d08 1439 /* Set process priority to medium-hight */
26d67362 1440 prio = 5;
be147d08
JM
1441 }
1442 break;
1443 case 3:
c47493f2 1444 if (!ctx->pr) {
be147d08 1445 /* Set process priority to high */
26d67362 1446 prio = 6;
be147d08
JM
1447 }
1448 break;
be147d08 1449 case 7:
c47493f2 1450 if (ctx->hv) {
be147d08 1451 /* Set process priority to very high */
26d67362 1452 prio = 7;
be147d08
JM
1453 }
1454 break;
be147d08 1455#endif
c80f84e3
JM
1456 default:
1457 /* nop */
1458 break;
1459 }
26d67362 1460 if (prio) {
a7812ae4 1461 TCGv t0 = tcg_temp_new();
54cdcae6 1462 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1463 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1464 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1465 gen_store_spr(SPR_PPR, t0);
ea363694 1466 tcg_temp_free(t0);
26d67362 1467 }
c80f84e3 1468#endif
9a64fbe4 1469 }
9a64fbe4 1470}
79aceca5 1471/* orc & orc. */
26d67362 1472GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1473
54623277 1474/* xor & xor. */
99e300ef 1475static void gen_xor(DisasContext *ctx)
9a64fbe4 1476{
9a64fbe4 1477 /* Optimisation for "set to zero" case */
26d67362 1478 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1479 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1480 else
1481 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1482 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1483 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1484}
99e300ef 1485
54623277 1486/* ori */
99e300ef 1487static void gen_ori(DisasContext *ctx)
79aceca5 1488{
76a66253 1489 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1490
9a64fbe4
FB
1491 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1492 /* NOP */
76a66253 1493 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1494 return;
76a66253 1495 }
26d67362 1496 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1497}
99e300ef 1498
54623277 1499/* oris */
99e300ef 1500static void gen_oris(DisasContext *ctx)
79aceca5 1501{
76a66253 1502 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1503
9a64fbe4
FB
1504 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1505 /* NOP */
1506 return;
76a66253 1507 }
26d67362 1508 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1509}
99e300ef 1510
54623277 1511/* xori */
99e300ef 1512static void gen_xori(DisasContext *ctx)
79aceca5 1513{
76a66253 1514 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1515
1516 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1517 /* NOP */
1518 return;
1519 }
26d67362 1520 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1521}
99e300ef 1522
54623277 1523/* xoris */
99e300ef 1524static void gen_xoris(DisasContext *ctx)
79aceca5 1525{
76a66253 1526 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1527
1528 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1529 /* NOP */
1530 return;
1531 }
26d67362 1532 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1533}
99e300ef 1534
54623277 1535/* popcntb : PowerPC 2.03 specification */
99e300ef 1536static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1537{
eaabeef2
DG
1538 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1539}
1540
1541static void gen_popcntw(DisasContext *ctx)
1542{
1543 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1544}
1545
d9bce9d9 1546#if defined(TARGET_PPC64)
eaabeef2
DG
1547/* popcntd: PowerPC 2.06 specification */
1548static void gen_popcntd(DisasContext *ctx)
1549{
1550 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1551}
eaabeef2 1552#endif
d9bce9d9 1553
725bcec2
AJ
1554/* prtyw: PowerPC 2.05 specification */
1555static void gen_prtyw(DisasContext *ctx)
1556{
1557 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1558 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1559 TCGv t0 = tcg_temp_new();
1560 tcg_gen_shri_tl(t0, rs, 16);
1561 tcg_gen_xor_tl(ra, rs, t0);
1562 tcg_gen_shri_tl(t0, ra, 8);
1563 tcg_gen_xor_tl(ra, ra, t0);
1564 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1565 tcg_temp_free(t0);
1566}
1567
1568#if defined(TARGET_PPC64)
1569/* prtyd: PowerPC 2.05 specification */
1570static void gen_prtyd(DisasContext *ctx)
1571{
1572 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1573 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1574 TCGv t0 = tcg_temp_new();
1575 tcg_gen_shri_tl(t0, rs, 32);
1576 tcg_gen_xor_tl(ra, rs, t0);
1577 tcg_gen_shri_tl(t0, ra, 16);
1578 tcg_gen_xor_tl(ra, ra, t0);
1579 tcg_gen_shri_tl(t0, ra, 8);
1580 tcg_gen_xor_tl(ra, ra, t0);
1581 tcg_gen_andi_tl(ra, ra, 1);
1582 tcg_temp_free(t0);
1583}
1584#endif
1585
86ba37ed
TM
1586#if defined(TARGET_PPC64)
1587/* bpermd */
1588static void gen_bpermd(DisasContext *ctx)
1589{
1590 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1591 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1592}
1593#endif
1594
d9bce9d9
JM
1595#if defined(TARGET_PPC64)
1596/* extsw & extsw. */
26d67362 1597GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1598
54623277 1599/* cntlzd */
99e300ef 1600static void gen_cntlzd(DisasContext *ctx)
26d67362 1601{
a7812ae4 1602 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1603 if (unlikely(Rc(ctx->opcode) != 0))
1604 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1605}
d9bce9d9
JM
1606#endif
1607
79aceca5 1608/*** Integer rotate ***/
99e300ef 1609
54623277 1610/* rlwimi & rlwimi. */
99e300ef 1611static void gen_rlwimi(DisasContext *ctx)
79aceca5 1612{
63ae0915
RH
1613 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1614 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1615 uint32_t sh = SH(ctx->opcode);
1616 uint32_t mb = MB(ctx->opcode);
1617 uint32_t me = ME(ctx->opcode);
1618
1619 if (sh == (31-me) && mb <= me) {
1620 tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1);
d03ef511 1621 } else {
d03ef511 1622 target_ulong mask;
63ae0915 1623 TCGv_i32 t0;
a7812ae4 1624 TCGv t1;
63ae0915 1625
76a66253 1626#if defined(TARGET_PPC64)
d03ef511
AJ
1627 mb += 32;
1628 me += 32;
76a66253 1629#endif
d03ef511 1630 mask = MASK(mb, me);
63ae0915
RH
1631
1632 t0 = tcg_temp_new_i32();
a7812ae4 1633 t1 = tcg_temp_new();
63ae0915
RH
1634 tcg_gen_trunc_tl_i32(t0, t_rs);
1635 tcg_gen_rotli_i32(t0, t0, sh);
1636 tcg_gen_extu_i32_tl(t1, t0);
1637 tcg_temp_free_i32(t0);
1638
1639 tcg_gen_andi_tl(t1, t1, mask);
1640 tcg_gen_andi_tl(t_ra, t_ra, ~mask);
1641 tcg_gen_or_tl(t_ra, t_ra, t1);
d03ef511
AJ
1642 tcg_temp_free(t1);
1643 }
63ae0915
RH
1644 if (unlikely(Rc(ctx->opcode) != 0)) {
1645 gen_set_Rc0(ctx, t_ra);
1646 }
79aceca5 1647}
99e300ef 1648
54623277 1649/* rlwinm & rlwinm. */
99e300ef 1650static void gen_rlwinm(DisasContext *ctx)
79aceca5 1651{
63ae0915
RH
1652 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1653 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1654 uint32_t sh = SH(ctx->opcode);
1655 uint32_t mb = MB(ctx->opcode);
1656 uint32_t me = ME(ctx->opcode);
1657
1658 if (mb == 0 && me == (31 - sh)) {
1659 tcg_gen_shli_tl(t_ra, t_rs, sh);
1660 tcg_gen_ext32u_tl(t_ra, t_ra);
1661 } else if (sh != 0 && me == 31 && sh == (32 - mb)) {
1662 tcg_gen_ext32u_tl(t_ra, t_rs);
1663 tcg_gen_shri_tl(t_ra, t_ra, mb);
d03ef511 1664 } else {
76a66253 1665#if defined(TARGET_PPC64)
d03ef511
AJ
1666 mb += 32;
1667 me += 32;
76a66253 1668#endif
63ae0915
RH
1669 if (sh == 0) {
1670 tcg_gen_andi_tl(t_ra, t_rs, MASK(mb, me));
1671 } else {
1672 TCGv_i32 t0 = tcg_temp_new_i32();
1673
1674 tcg_gen_trunc_tl_i32(t0, t_rs);
1675 tcg_gen_rotli_i32(t0, t0, sh);
1676 tcg_gen_andi_i32(t0, t0, MASK(mb, me));
1677 tcg_gen_extu_i32_tl(t_ra, t0);
1678 tcg_temp_free_i32(t0);
1679 }
1680 }
1681 if (unlikely(Rc(ctx->opcode) != 0)) {
1682 gen_set_Rc0(ctx, t_ra);
d03ef511 1683 }
79aceca5 1684}
99e300ef 1685
54623277 1686/* rlwnm & rlwnm. */
99e300ef 1687static void gen_rlwnm(DisasContext *ctx)
79aceca5 1688{
63ae0915
RH
1689 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1690 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1691 TCGv t_rb = cpu_gpr[rB(ctx->opcode)];
1692 uint32_t mb = MB(ctx->opcode);
1693 uint32_t me = ME(ctx->opcode);
1694 TCGv_i32 t0, t1;
57fca134 1695
54843a58 1696#if defined(TARGET_PPC64)
63ae0915
RH
1697 mb += 32;
1698 me += 32;
54843a58 1699#endif
57fca134 1700
63ae0915
RH
1701 t0 = tcg_temp_new_i32();
1702 t1 = tcg_temp_new_i32();
1703 tcg_gen_trunc_tl_i32(t0, t_rb);
1704 tcg_gen_trunc_tl_i32(t1, t_rs);
1705 tcg_gen_andi_i32(t0, t0, 0x1f);
1706 tcg_gen_rotl_i32(t1, t1, t0);
1707 tcg_temp_free_i32(t0);
1708
1709 tcg_gen_andi_i32(t1, t1, MASK(mb, me));
1710 tcg_gen_extu_i32_tl(t_ra, t1);
1711 tcg_temp_free_i32(t1);
1712
1713 if (unlikely(Rc(ctx->opcode) != 0)) {
1714 gen_set_Rc0(ctx, t_ra);
79aceca5 1715 }
79aceca5
FB
1716}
1717
d9bce9d9
JM
1718#if defined(TARGET_PPC64)
1719#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1720static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1721{ \
1722 gen_##name(ctx, 0); \
1723} \
e8eaa2c0
BS
1724 \
1725static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1726{ \
1727 gen_##name(ctx, 1); \
1728}
1729#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1730static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1731{ \
1732 gen_##name(ctx, 0, 0); \
1733} \
e8eaa2c0
BS
1734 \
1735static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1736{ \
1737 gen_##name(ctx, 0, 1); \
1738} \
e8eaa2c0
BS
1739 \
1740static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1741{ \
1742 gen_##name(ctx, 1, 0); \
1743} \
e8eaa2c0
BS
1744 \
1745static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1746{ \
1747 gen_##name(ctx, 1, 1); \
1748}
51789c41 1749
a7b2c8b9 1750static void gen_rldinm(DisasContext *ctx, int mb, int me, int sh)
51789c41 1751{
a7b2c8b9
RH
1752 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1753 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1754
1755 if (sh != 0 && mb == 0 && me == (63 - sh)) {
1756 tcg_gen_shli_tl(t_ra, t_rs, sh);
1757 } else if (sh != 0 && me == 63 && sh == (64 - mb)) {
1758 tcg_gen_shri_tl(t_ra, t_rs, mb);
d03ef511 1759 } else {
a7b2c8b9
RH
1760 tcg_gen_rotli_tl(t_ra, t_rs, sh);
1761 tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me));
1762 }
1763 if (unlikely(Rc(ctx->opcode) != 0)) {
1764 gen_set_Rc0(ctx, t_ra);
51789c41 1765 }
51789c41 1766}
a7b2c8b9 1767
d9bce9d9 1768/* rldicl - rldicl. */
636aa200 1769static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1770{
51789c41 1771 uint32_t sh, mb;
d9bce9d9 1772
9d53c753
JM
1773 sh = SH(ctx->opcode) | (shn << 5);
1774 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1775 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1776}
51789c41 1777GEN_PPC64_R4(rldicl, 0x1E, 0x00);
a7b2c8b9 1778
d9bce9d9 1779/* rldicr - rldicr. */
636aa200 1780static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1781{
51789c41 1782 uint32_t sh, me;
d9bce9d9 1783
9d53c753
JM
1784 sh = SH(ctx->opcode) | (shn << 5);
1785 me = MB(ctx->opcode) | (men << 5);
51789c41 1786 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1787}
51789c41 1788GEN_PPC64_R4(rldicr, 0x1E, 0x02);
a7b2c8b9 1789
d9bce9d9 1790/* rldic - rldic. */
636aa200 1791static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1792{
51789c41 1793 uint32_t sh, mb;
d9bce9d9 1794
9d53c753
JM
1795 sh = SH(ctx->opcode) | (shn << 5);
1796 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1797 gen_rldinm(ctx, mb, 63 - sh, sh);
1798}
1799GEN_PPC64_R4(rldic, 0x1E, 0x04);
1800
a7b2c8b9 1801static void gen_rldnm(DisasContext *ctx, int mb, int me)
51789c41 1802{
a7b2c8b9
RH
1803 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1804 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1805 TCGv t_rb = cpu_gpr[rB(ctx->opcode)];
54843a58 1806 TCGv t0;
d03ef511 1807
a7812ae4 1808 t0 = tcg_temp_new();
a7b2c8b9
RH
1809 tcg_gen_andi_tl(t0, t_rb, 0x3f);
1810 tcg_gen_rotl_tl(t_ra, t_rs, t0);
54843a58 1811 tcg_temp_free(t0);
a7b2c8b9
RH
1812
1813 tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me));
1814 if (unlikely(Rc(ctx->opcode) != 0)) {
1815 gen_set_Rc0(ctx, t_ra);
1816 }
d9bce9d9 1817}
51789c41 1818
d9bce9d9 1819/* rldcl - rldcl. */
636aa200 1820static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1821{
51789c41 1822 uint32_t mb;
d9bce9d9 1823
9d53c753 1824 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1825 gen_rldnm(ctx, mb, 63);
d9bce9d9 1826}
36081602 1827GEN_PPC64_R2(rldcl, 0x1E, 0x08);
a7b2c8b9 1828
d9bce9d9 1829/* rldcr - rldcr. */
636aa200 1830static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1831{
51789c41 1832 uint32_t me;
d9bce9d9 1833
9d53c753 1834 me = MB(ctx->opcode) | (men << 5);
51789c41 1835 gen_rldnm(ctx, 0, me);
d9bce9d9 1836}
36081602 1837GEN_PPC64_R2(rldcr, 0x1E, 0x09);
a7b2c8b9 1838
d9bce9d9 1839/* rldimi - rldimi. */
a7b2c8b9 1840static void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1841{
a7b2c8b9
RH
1842 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1843 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1844 uint32_t sh = SH(ctx->opcode) | (shn << 5);
1845 uint32_t mb = MB(ctx->opcode) | (mbn << 5);
1846 uint32_t me = 63 - sh;
d9bce9d9 1847
a7b2c8b9
RH
1848 if (mb <= me) {
1849 tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1);
d03ef511 1850 } else {
a7b2c8b9
RH
1851 target_ulong mask = MASK(mb, me);
1852 TCGv t1 = tcg_temp_new();
d03ef511 1853
a7b2c8b9
RH
1854 tcg_gen_rotli_tl(t1, t_rs, sh);
1855 tcg_gen_andi_tl(t1, t1, mask);
1856 tcg_gen_andi_tl(t_ra, t_ra, ~mask);
1857 tcg_gen_or_tl(t_ra, t_ra, t1);
d03ef511 1858 tcg_temp_free(t1);
51789c41 1859 }
a7b2c8b9
RH
1860 if (unlikely(Rc(ctx->opcode) != 0)) {
1861 gen_set_Rc0(ctx, t_ra);
1862 }
d9bce9d9 1863}
36081602 1864GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1865#endif
1866
79aceca5 1867/*** Integer shift ***/
99e300ef 1868
54623277 1869/* slw & slw. */
99e300ef 1870static void gen_slw(DisasContext *ctx)
26d67362 1871{
7fd6bf7d 1872 TCGv t0, t1;
26d67362 1873
7fd6bf7d
AJ
1874 t0 = tcg_temp_new();
1875 /* AND rS with a mask that is 0 when rB >= 0x20 */
1876#if defined(TARGET_PPC64)
1877 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1878 tcg_gen_sari_tl(t0, t0, 0x3f);
1879#else
1880 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1881 tcg_gen_sari_tl(t0, t0, 0x1f);
1882#endif
1883 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1884 t1 = tcg_temp_new();
1885 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1886 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1887 tcg_temp_free(t1);
fea0c503 1888 tcg_temp_free(t0);
7fd6bf7d 1889 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1890 if (unlikely(Rc(ctx->opcode) != 0))
1891 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1892}
99e300ef 1893
54623277 1894/* sraw & sraw. */
99e300ef 1895static void gen_sraw(DisasContext *ctx)
26d67362 1896{
d15f74fb 1897 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1898 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1899 if (unlikely(Rc(ctx->opcode) != 0))
1900 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1901}
99e300ef 1902
54623277 1903/* srawi & srawi. */
99e300ef 1904static void gen_srawi(DisasContext *ctx)
79aceca5 1905{
26d67362 1906 int sh = SH(ctx->opcode);
ba4af3e4
RH
1907 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1908 TCGv src = cpu_gpr[rS(ctx->opcode)];
1909 if (sh == 0) {
34a0fad1 1910 tcg_gen_ext32s_tl(dst, src);
da91a00f 1911 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1912 } else {
ba4af3e4
RH
1913 TCGv t0;
1914 tcg_gen_ext32s_tl(dst, src);
1915 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1916 t0 = tcg_temp_new();
1917 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1918 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1919 tcg_temp_free(t0);
1920 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1921 tcg_gen_sari_tl(dst, dst, sh);
1922 }
1923 if (unlikely(Rc(ctx->opcode) != 0)) {
1924 gen_set_Rc0(ctx, dst);
d9bce9d9 1925 }
79aceca5 1926}
99e300ef 1927
54623277 1928/* srw & srw. */
99e300ef 1929static void gen_srw(DisasContext *ctx)
26d67362 1930{
fea0c503 1931 TCGv t0, t1;
d9bce9d9 1932
7fd6bf7d
AJ
1933 t0 = tcg_temp_new();
1934 /* AND rS with a mask that is 0 when rB >= 0x20 */
1935#if defined(TARGET_PPC64)
1936 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1937 tcg_gen_sari_tl(t0, t0, 0x3f);
1938#else
1939 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1940 tcg_gen_sari_tl(t0, t0, 0x1f);
1941#endif
1942 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1943 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1944 t1 = tcg_temp_new();
7fd6bf7d
AJ
1945 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1946 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1947 tcg_temp_free(t1);
fea0c503 1948 tcg_temp_free(t0);
26d67362
AJ
1949 if (unlikely(Rc(ctx->opcode) != 0))
1950 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1951}
54623277 1952
d9bce9d9
JM
1953#if defined(TARGET_PPC64)
1954/* sld & sld. */
99e300ef 1955static void gen_sld(DisasContext *ctx)
26d67362 1956{
7fd6bf7d 1957 TCGv t0, t1;
26d67362 1958
7fd6bf7d
AJ
1959 t0 = tcg_temp_new();
1960 /* AND rS with a mask that is 0 when rB >= 0x40 */
1961 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1962 tcg_gen_sari_tl(t0, t0, 0x3f);
1963 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1964 t1 = tcg_temp_new();
1965 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1966 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1967 tcg_temp_free(t1);
fea0c503 1968 tcg_temp_free(t0);
26d67362
AJ
1969 if (unlikely(Rc(ctx->opcode) != 0))
1970 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1971}
99e300ef 1972
54623277 1973/* srad & srad. */
99e300ef 1974static void gen_srad(DisasContext *ctx)
26d67362 1975{
d15f74fb 1976 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1977 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1978 if (unlikely(Rc(ctx->opcode) != 0))
1979 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1980}
d9bce9d9 1981/* sradi & sradi. */
636aa200 1982static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1983{
26d67362 1984 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
1985 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1986 TCGv src = cpu_gpr[rS(ctx->opcode)];
1987 if (sh == 0) {
1988 tcg_gen_mov_tl(dst, src);
da91a00f 1989 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1990 } else {
ba4af3e4
RH
1991 TCGv t0;
1992 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1993 t0 = tcg_temp_new();
1994 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1995 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1996 tcg_temp_free(t0);
1997 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1998 tcg_gen_sari_tl(dst, src, sh);
1999 }
2000 if (unlikely(Rc(ctx->opcode) != 0)) {
2001 gen_set_Rc0(ctx, dst);
d9bce9d9 2002 }
d9bce9d9 2003}
e8eaa2c0
BS
2004
2005static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
2006{
2007 gen_sradi(ctx, 0);
2008}
e8eaa2c0
BS
2009
2010static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
2011{
2012 gen_sradi(ctx, 1);
2013}
99e300ef 2014
54623277 2015/* srd & srd. */
99e300ef 2016static void gen_srd(DisasContext *ctx)
26d67362 2017{
7fd6bf7d 2018 TCGv t0, t1;
26d67362 2019
7fd6bf7d
AJ
2020 t0 = tcg_temp_new();
2021 /* AND rS with a mask that is 0 when rB >= 0x40 */
2022 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2023 tcg_gen_sari_tl(t0, t0, 0x3f);
2024 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2025 t1 = tcg_temp_new();
2026 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2027 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2028 tcg_temp_free(t1);
fea0c503 2029 tcg_temp_free(t0);
26d67362
AJ
2030 if (unlikely(Rc(ctx->opcode) != 0))
2031 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2032}
d9bce9d9 2033#endif
79aceca5 2034
4814f2d1
TM
2035#if defined(TARGET_PPC64)
2036static void gen_set_cr1_from_fpscr(DisasContext *ctx)
2037{
2038 TCGv_i32 tmp = tcg_temp_new_i32();
2039 tcg_gen_trunc_tl_i32(tmp, cpu_fpscr);
2040 tcg_gen_shri_i32(cpu_crf[1], tmp, 28);
2041 tcg_temp_free_i32(tmp);
2042}
2043#else
2044static void gen_set_cr1_from_fpscr(DisasContext *ctx)
2045{
2046 tcg_gen_shri_tl(cpu_crf[1], cpu_fpscr, 28);
2047}
2048#endif
2049
79aceca5 2050/*** Floating-Point arithmetic ***/
7c58044c 2051#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 2052static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2053{ \
76a66253 2054 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2055 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2056 return; \
2057 } \
eb44b959
AJ
2058 /* NIP cannot be restored if the memory exception comes from an helper */ \
2059 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2060 gen_reset_fpstatus(); \
8e703949
BS
2061 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2062 cpu_fpr[rA(ctx->opcode)], \
af12906f 2063 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2064 if (isfloat) { \
8e703949
BS
2065 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2066 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2067 } \
7d45556e
TM
2068 if (set_fprf) { \
2069 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2070 } \
00e6fd3e
TM
2071 if (unlikely(Rc(ctx->opcode) != 0)) { \
2072 gen_set_cr1_from_fpscr(ctx); \
2073 } \
9a64fbe4
FB
2074}
2075
7c58044c
JM
2076#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2077_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2078_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2079
7c58044c 2080#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2081static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2082{ \
76a66253 2083 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2084 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2085 return; \
2086 } \
eb44b959
AJ
2087 /* NIP cannot be restored if the memory exception comes from an helper */ \
2088 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2089 gen_reset_fpstatus(); \
8e703949
BS
2090 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2091 cpu_fpr[rA(ctx->opcode)], \
af12906f 2092 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2093 if (isfloat) { \
8e703949
BS
2094 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2095 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2096 } \
7d45556e
TM
2097 if (set_fprf) { \
2098 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2099 } \
00e6fd3e
TM
2100 if (unlikely(Rc(ctx->opcode) != 0)) { \
2101 gen_set_cr1_from_fpscr(ctx); \
2102 } \
9a64fbe4 2103}
7c58044c
JM
2104#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2105_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2106_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2107
7c58044c 2108#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2109static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2110{ \
76a66253 2111 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2112 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2113 return; \
2114 } \
eb44b959
AJ
2115 /* NIP cannot be restored if the memory exception comes from an helper */ \
2116 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2117 gen_reset_fpstatus(); \
8e703949
BS
2118 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2119 cpu_fpr[rA(ctx->opcode)], \
2120 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2121 if (isfloat) { \
8e703949
BS
2122 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2123 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2124 } \
7d45556e
TM
2125 if (set_fprf) { \
2126 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2127 } \
00e6fd3e
TM
2128 if (unlikely(Rc(ctx->opcode) != 0)) { \
2129 gen_set_cr1_from_fpscr(ctx); \
2130 } \
9a64fbe4 2131}
7c58044c
JM
2132#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2133_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2134_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2135
7c58044c 2136#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2137static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2138{ \
76a66253 2139 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2140 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2141 return; \
2142 } \
eb44b959
AJ
2143 /* NIP cannot be restored if the memory exception comes from an helper */ \
2144 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2145 gen_reset_fpstatus(); \
8e703949
BS
2146 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2147 cpu_fpr[rB(ctx->opcode)]); \
7d45556e
TM
2148 if (set_fprf) { \
2149 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2150 } \
00e6fd3e
TM
2151 if (unlikely(Rc(ctx->opcode) != 0)) { \
2152 gen_set_cr1_from_fpscr(ctx); \
2153 } \
79aceca5
FB
2154}
2155
7c58044c 2156#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2157static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2158{ \
76a66253 2159 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2160 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2161 return; \
2162 } \
eb44b959
AJ
2163 /* NIP cannot be restored if the memory exception comes from an helper */ \
2164 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2165 gen_reset_fpstatus(); \
8e703949
BS
2166 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2167 cpu_fpr[rB(ctx->opcode)]); \
7d45556e
TM
2168 if (set_fprf) { \
2169 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2170 } \
00e6fd3e
TM
2171 if (unlikely(Rc(ctx->opcode) != 0)) { \
2172 gen_set_cr1_from_fpscr(ctx); \
2173 } \
79aceca5
FB
2174}
2175
9a64fbe4 2176/* fadd - fadds */
7c58044c 2177GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2178/* fdiv - fdivs */
7c58044c 2179GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2180/* fmul - fmuls */
7c58044c 2181GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2182
d7e4b87e 2183/* fre */
7c58044c 2184GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2185
a750fc0b 2186/* fres */
7c58044c 2187GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2188
a750fc0b 2189/* frsqrte */
7c58044c
JM
2190GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2191
2192/* frsqrtes */
99e300ef 2193static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2194{
af12906f 2195 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2196 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2197 return;
2198 }
eb44b959
AJ
2199 /* NIP cannot be restored if the memory exception comes from an helper */
2200 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2201 gen_reset_fpstatus();
8e703949
BS
2202 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2203 cpu_fpr[rB(ctx->opcode)]);
2204 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2205 cpu_fpr[rD(ctx->opcode)]);
7d45556e 2206 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
00e6fd3e
TM
2207 if (unlikely(Rc(ctx->opcode) != 0)) {
2208 gen_set_cr1_from_fpscr(ctx);
2209 }
7c58044c 2210}
79aceca5 2211
a750fc0b 2212/* fsel */
7c58044c 2213_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2214/* fsub - fsubs */
7c58044c 2215GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2216/* Optional: */
99e300ef 2217
54623277 2218/* fsqrt */
99e300ef 2219static void gen_fsqrt(DisasContext *ctx)
c7d344af 2220{
76a66253 2221 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2222 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2223 return;
2224 }
eb44b959
AJ
2225 /* NIP cannot be restored if the memory exception comes from an helper */
2226 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2227 gen_reset_fpstatus();
8e703949
BS
2228 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2229 cpu_fpr[rB(ctx->opcode)]);
7d45556e 2230 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
00e6fd3e
TM
2231 if (unlikely(Rc(ctx->opcode) != 0)) {
2232 gen_set_cr1_from_fpscr(ctx);
2233 }
c7d344af 2234}
79aceca5 2235
99e300ef 2236static void gen_fsqrts(DisasContext *ctx)
79aceca5 2237{
76a66253 2238 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2239 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2240 return;
2241 }
eb44b959
AJ
2242 /* NIP cannot be restored if the memory exception comes from an helper */
2243 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2244 gen_reset_fpstatus();
8e703949
BS
2245 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2246 cpu_fpr[rB(ctx->opcode)]);
2247 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2248 cpu_fpr[rD(ctx->opcode)]);
7d45556e 2249 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
00e6fd3e
TM
2250 if (unlikely(Rc(ctx->opcode) != 0)) {
2251 gen_set_cr1_from_fpscr(ctx);
2252 }
79aceca5
FB
2253}
2254
2255/*** Floating-Point multiply-and-add ***/
4ecc3190 2256/* fmadd - fmadds */
7c58044c 2257GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2258/* fmsub - fmsubs */
7c58044c 2259GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2260/* fnmadd - fnmadds */
7c58044c 2261GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2262/* fnmsub - fnmsubs */
7c58044c 2263GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2264
2265/*** Floating-Point round & convert ***/
2266/* fctiw */
7c58044c 2267GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2268/* fctiwu */
2269GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2270/* fctiwz */
7c58044c 2271GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2272/* fctiwuz */
2273GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2274/* frsp */
7c58044c 2275GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db 2276/* fcfid */
4171853c 2277GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC2_FP_CVT_S64);
28288b48
TM
2278/* fcfids */
2279GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2280/* fcfidu */
2281GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2282/* fcfidus */
2283GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
426613db 2284/* fctid */
4171853c 2285GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC2_FP_CVT_S64);
fab7fe42
TM
2286/* fctidu */
2287GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2288/* fctidz */
4171853c 2289GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC2_FP_CVT_S64);
fab7fe42
TM
2290/* fctidu */
2291GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
79aceca5 2292
d7e4b87e 2293/* frin */
7c58044c 2294GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2295/* friz */
7c58044c 2296GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2297/* frip */
7c58044c 2298GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2299/* frim */
7c58044c 2300GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2301
da29cb7b
TM
2302static void gen_ftdiv(DisasContext *ctx)
2303{
2304 if (unlikely(!ctx->fpu_enabled)) {
2305 gen_exception(ctx, POWERPC_EXCP_FPU);
2306 return;
2307 }
2308 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2309 cpu_fpr[rB(ctx->opcode)]);
2310}
2311
6d41d146
TM
2312static void gen_ftsqrt(DisasContext *ctx)
2313{
2314 if (unlikely(!ctx->fpu_enabled)) {
2315 gen_exception(ctx, POWERPC_EXCP_FPU);
2316 return;
2317 }
2318 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2319}
2320
da29cb7b
TM
2321
2322
79aceca5 2323/*** Floating-Point compare ***/
99e300ef 2324
54623277 2325/* fcmpo */
99e300ef 2326static void gen_fcmpo(DisasContext *ctx)
79aceca5 2327{
330c483b 2328 TCGv_i32 crf;
76a66253 2329 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2330 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2331 return;
2332 }
eb44b959
AJ
2333 /* NIP cannot be restored if the memory exception comes from an helper */
2334 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2335 gen_reset_fpstatus();
9a819377 2336 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2337 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2338 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2339 tcg_temp_free_i32(crf);
8e703949 2340 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2341}
2342
2343/* fcmpu */
99e300ef 2344static void gen_fcmpu(DisasContext *ctx)
79aceca5 2345{
330c483b 2346 TCGv_i32 crf;
76a66253 2347 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2348 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2349 return;
2350 }
eb44b959
AJ
2351 /* NIP cannot be restored if the memory exception comes from an helper */
2352 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2353 gen_reset_fpstatus();
9a819377 2354 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2355 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2356 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2357 tcg_temp_free_i32(crf);
8e703949 2358 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2359}
2360
9a64fbe4
FB
2361/*** Floating-point move ***/
2362/* fabs */
7c58044c 2363/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2364static void gen_fabs(DisasContext *ctx)
2365{
2366 if (unlikely(!ctx->fpu_enabled)) {
2367 gen_exception(ctx, POWERPC_EXCP_FPU);
2368 return;
2369 }
2370 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2371 ~(1ULL << 63));
4814f2d1
TM
2372 if (unlikely(Rc(ctx->opcode))) {
2373 gen_set_cr1_from_fpscr(ctx);
2374 }
bf45a2e6 2375}
9a64fbe4
FB
2376
2377/* fmr - fmr. */
7c58044c 2378/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2379static void gen_fmr(DisasContext *ctx)
9a64fbe4 2380{
76a66253 2381 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2382 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2383 return;
2384 }
af12906f 2385 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
4814f2d1
TM
2386 if (unlikely(Rc(ctx->opcode))) {
2387 gen_set_cr1_from_fpscr(ctx);
2388 }
9a64fbe4
FB
2389}
2390
2391/* fnabs */
7c58044c 2392/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2393static void gen_fnabs(DisasContext *ctx)
2394{
2395 if (unlikely(!ctx->fpu_enabled)) {
2396 gen_exception(ctx, POWERPC_EXCP_FPU);
2397 return;
2398 }
2399 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2400 1ULL << 63);
4814f2d1
TM
2401 if (unlikely(Rc(ctx->opcode))) {
2402 gen_set_cr1_from_fpscr(ctx);
2403 }
bf45a2e6
AJ
2404}
2405
9a64fbe4 2406/* fneg */
7c58044c 2407/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2408static void gen_fneg(DisasContext *ctx)
2409{
2410 if (unlikely(!ctx->fpu_enabled)) {
2411 gen_exception(ctx, POWERPC_EXCP_FPU);
2412 return;
2413 }
2414 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2415 1ULL << 63);
4814f2d1
TM
2416 if (unlikely(Rc(ctx->opcode))) {
2417 gen_set_cr1_from_fpscr(ctx);
2418 }
bf45a2e6 2419}
9a64fbe4 2420
f0332888
AJ
2421/* fcpsgn: PowerPC 2.05 specification */
2422/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2423static void gen_fcpsgn(DisasContext *ctx)
2424{
2425 if (unlikely(!ctx->fpu_enabled)) {
2426 gen_exception(ctx, POWERPC_EXCP_FPU);
2427 return;
2428 }
2429 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2430 cpu_fpr[rB(ctx->opcode)], 0, 63);
4814f2d1
TM
2431 if (unlikely(Rc(ctx->opcode))) {
2432 gen_set_cr1_from_fpscr(ctx);
2433 }
f0332888
AJ
2434}
2435
097ec5d8
TM
2436static void gen_fmrgew(DisasContext *ctx)
2437{
2438 TCGv_i64 b0;
2439 if (unlikely(!ctx->fpu_enabled)) {
2440 gen_exception(ctx, POWERPC_EXCP_FPU);
2441 return;
2442 }
2443 b0 = tcg_temp_new_i64();
2444 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2445 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2446 b0, 0, 32);
2447 tcg_temp_free_i64(b0);
2448}
2449
2450static void gen_fmrgow(DisasContext *ctx)
2451{
2452 if (unlikely(!ctx->fpu_enabled)) {
2453 gen_exception(ctx, POWERPC_EXCP_FPU);
2454 return;
2455 }
2456 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2457 cpu_fpr[rB(ctx->opcode)],
2458 cpu_fpr[rA(ctx->opcode)],
2459 32, 32);
2460}
2461
79aceca5 2462/*** Floating-Point status & ctrl register ***/
99e300ef 2463
54623277 2464/* mcrfs */
99e300ef 2465static void gen_mcrfs(DisasContext *ctx)
79aceca5 2466{
30304420 2467 TCGv tmp = tcg_temp_new();
d1277156
JC
2468 TCGv_i32 tmask;
2469 TCGv_i64 tnew_fpscr = tcg_temp_new_i64();
7c58044c 2470 int bfa;
d1277156
JC
2471 int nibble;
2472 int shift;
7c58044c 2473
76a66253 2474 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2475 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2476 return;
2477 }
d1277156
JC
2478 bfa = crfS(ctx->opcode);
2479 nibble = 7 - bfa;
2480 shift = 4 * nibble;
2481 tcg_gen_shri_tl(tmp, cpu_fpscr, shift);
30304420 2482 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
e1571908 2483 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
d1277156
JC
2484 tcg_temp_free(tmp);
2485 tcg_gen_extu_tl_i64(tnew_fpscr, cpu_fpscr);
2486 /* Only the exception bits (including FX) should be cleared if read */
2487 tcg_gen_andi_i64(tnew_fpscr, tnew_fpscr, ~((0xF << shift) & FP_EX_CLEAR_BITS));
2488 /* FEX and VX need to be updated, so don't set fpscr directly */
2489 tmask = tcg_const_i32(1 << nibble);
2490 gen_helper_store_fpscr(cpu_env, tnew_fpscr, tmask);
2491 tcg_temp_free_i32(tmask);
2492 tcg_temp_free_i64(tnew_fpscr);
79aceca5
FB
2493}
2494
2495/* mffs */
99e300ef 2496static void gen_mffs(DisasContext *ctx)
79aceca5 2497{
76a66253 2498 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2499 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2500 return;
2501 }
7c58044c 2502 gen_reset_fpstatus();
30304420 2503 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
14ba79c7
TM
2504 if (unlikely(Rc(ctx->opcode))) {
2505 gen_set_cr1_from_fpscr(ctx);
2506 }
79aceca5
FB
2507}
2508
2509/* mtfsb0 */
99e300ef 2510static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2511{
fb0eaffc 2512 uint8_t crb;
3b46e624 2513
76a66253 2514 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2515 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2516 return;
2517 }
6e35d524 2518 crb = 31 - crbD(ctx->opcode);
7c58044c 2519 gen_reset_fpstatus();
6e35d524 2520 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2521 TCGv_i32 t0;
2522 /* NIP cannot be restored if the memory exception comes from an helper */
2523 gen_update_nip(ctx, ctx->nip - 4);
2524 t0 = tcg_const_i32(crb);
8e703949 2525 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2526 tcg_temp_free_i32(t0);
2527 }
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 2531 }
79aceca5
FB
2532}
2533
2534/* mtfsb1 */
99e300ef 2535static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2536{
fb0eaffc 2537 uint8_t crb;
3b46e624 2538
76a66253 2539 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2540 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2541 return;
2542 }
6e35d524 2543 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2544 gen_reset_fpstatus();
2545 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2546 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2547 TCGv_i32 t0;
2548 /* NIP cannot be restored if the memory exception comes from an helper */
2549 gen_update_nip(ctx, ctx->nip - 4);
2550 t0 = tcg_const_i32(crb);
8e703949 2551 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2552 tcg_temp_free_i32(t0);
af12906f 2553 }
7c58044c 2554 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2555 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2556 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2557 }
2558 /* We can raise a differed exception */
8e703949 2559 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2560}
2561
2562/* mtfsf */
99e300ef 2563static void gen_mtfsf(DisasContext *ctx)
79aceca5 2564{
0f2f39c2 2565 TCGv_i32 t0;
7d08d856 2566 int flm, l, w;
af12906f 2567
76a66253 2568 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2569 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2570 return;
2571 }
7d08d856
AJ
2572 flm = FPFLM(ctx->opcode);
2573 l = FPL(ctx->opcode);
2574 w = FPW(ctx->opcode);
2575 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2576 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2577 return;
2578 }
eb44b959
AJ
2579 /* NIP cannot be restored if the memory exception comes from an helper */
2580 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2581 gen_reset_fpstatus();
7d08d856
AJ
2582 if (l) {
2583 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2584 } else {
2585 t0 = tcg_const_i32(flm << (w * 8));
2586 }
8e703949 2587 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2588 tcg_temp_free_i32(t0);
7c58044c 2589 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2590 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2591 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2592 }
2593 /* We can raise a differed exception */
8e703949 2594 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2595}
2596
2597/* mtfsfi */
99e300ef 2598static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2599{
7d08d856 2600 int bf, sh, w;
0f2f39c2
AJ
2601 TCGv_i64 t0;
2602 TCGv_i32 t1;
7c58044c 2603
76a66253 2604 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2605 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2606 return;
2607 }
7d08d856
AJ
2608 w = FPW(ctx->opcode);
2609 bf = FPBF(ctx->opcode);
2610 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2611 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2612 return;
2613 }
2614 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2615 /* NIP cannot be restored if the memory exception comes from an helper */
2616 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2617 gen_reset_fpstatus();
7d08d856 2618 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2619 t1 = tcg_const_i32(1 << sh);
8e703949 2620 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2621 tcg_temp_free_i64(t0);
2622 tcg_temp_free_i32(t1);
7c58044c 2623 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2624 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2625 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2626 }
2627 /* We can raise a differed exception */
8e703949 2628 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2629}
2630
76a66253
JM
2631/*** Addressing modes ***/
2632/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2633static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2634 target_long maskl)
76a66253
JM
2635{
2636 target_long simm = SIMM(ctx->opcode);
2637
be147d08 2638 simm &= ~maskl;
76db3ba4 2639 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2640 if (NARROW_MODE(ctx)) {
2641 simm = (uint32_t)simm;
2642 }
e2be8d8d 2643 tcg_gen_movi_tl(EA, simm);
76db3ba4 2644 } else if (likely(simm != 0)) {
e2be8d8d 2645 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2646 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2647 tcg_gen_ext32u_tl(EA, EA);
2648 }
76db3ba4 2649 } else {
c791fe84 2650 if (NARROW_MODE(ctx)) {
76db3ba4 2651 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2652 } else {
2653 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2654 }
76db3ba4 2655 }
76a66253
JM
2656}
2657
636aa200 2658static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2659{
76db3ba4 2660 if (rA(ctx->opcode) == 0) {
c791fe84 2661 if (NARROW_MODE(ctx)) {
76db3ba4 2662 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2663 } else {
2664 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2665 }
76db3ba4 2666 } else {
e2be8d8d 2667 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2668 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2669 tcg_gen_ext32u_tl(EA, EA);
2670 }
76db3ba4 2671 }
76a66253
JM
2672}
2673
636aa200 2674static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2675{
76db3ba4 2676 if (rA(ctx->opcode) == 0) {
e2be8d8d 2677 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2678 } else if (NARROW_MODE(ctx)) {
2679 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2680 } else {
c791fe84 2681 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2682 }
2683}
2684
636aa200
BS
2685static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2686 target_long val)
76db3ba4
AJ
2687{
2688 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2689 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2690 tcg_gen_ext32u_tl(ret, ret);
2691 }
76a66253
JM
2692}
2693
636aa200 2694static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32 2695{
42a268c2 2696 TCGLabel *l1 = gen_new_label();
cf360a32
AJ
2697 TCGv t0 = tcg_temp_new();
2698 TCGv_i32 t1, t2;
2699 /* NIP cannot be restored if the memory exception comes from an helper */
2700 gen_update_nip(ctx, ctx->nip - 4);
2701 tcg_gen_andi_tl(t0, EA, mask);
2702 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2703 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2704 t2 = tcg_const_i32(0);
e5f17ac6 2705 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2706 tcg_temp_free_i32(t1);
2707 tcg_temp_free_i32(t2);
2708 gen_set_label(l1);
2709 tcg_temp_free(t0);
2710}
2711
7863667f 2712/*** Integer load ***/
636aa200 2713static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2714{
2715 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2716}
2717
636aa200 2718static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4 2719{
e22c357b
DK
2720 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2721 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2722}
2723
636aa200 2724static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2725{
e22c357b
DK
2726 TCGMemOp op = MO_SW | ctx->default_tcg_memop_mask;
2727 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2728}
2729
636aa200 2730static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2731{
e22c357b
DK
2732 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2733 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2734}
2735
f976b09e
AG
2736static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2737{
2738 TCGv tmp = tcg_temp_new();
2739 gen_qemu_ld32u(ctx, tmp, addr);
2740 tcg_gen_extu_tl_i64(val, tmp);
2741 tcg_temp_free(tmp);
2742}
2743
636aa200 2744static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2745{
e22c357b
DK
2746 TCGMemOp op = MO_SL | ctx->default_tcg_memop_mask;
2747 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2748}
2749
cac7f0ba
TM
2750static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2751{
2752 TCGv tmp = tcg_temp_new();
2753 gen_qemu_ld32s(ctx, tmp, addr);
2754 tcg_gen_ext_tl_i64(val, tmp);
2755 tcg_temp_free(tmp);
2756}
2757
636aa200 2758static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2759{
e22c357b
DK
2760 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2761 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2762}
2763
636aa200 2764static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2765{
76db3ba4 2766 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2767}
2768
636aa200 2769static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2770{
e22c357b
DK
2771 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2772 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2773}
2774
636aa200 2775static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2776{
e22c357b
DK
2777 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2778 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2779}
2780
f976b09e
AG
2781static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2782{
2783 TCGv tmp = tcg_temp_new();
2784 tcg_gen_trunc_i64_tl(tmp, val);
2785 gen_qemu_st32(ctx, tmp, addr);
2786 tcg_temp_free(tmp);
2787}
2788
636aa200 2789static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2790{
e22c357b
DK
2791 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2792 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2793}
2794
0c8aacd4 2795#define GEN_LD(name, ldop, opc, type) \
99e300ef 2796static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2797{ \
76db3ba4
AJ
2798 TCGv EA; \
2799 gen_set_access_type(ctx, ACCESS_INT); \
2800 EA = tcg_temp_new(); \
2801 gen_addr_imm_index(ctx, EA, 0); \
2802 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2803 tcg_temp_free(EA); \
79aceca5
FB
2804}
2805
0c8aacd4 2806#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2807static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2808{ \
b61f2753 2809 TCGv EA; \
76a66253
JM
2810 if (unlikely(rA(ctx->opcode) == 0 || \
2811 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2812 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2813 return; \
9a64fbe4 2814 } \
76db3ba4 2815 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2816 EA = tcg_temp_new(); \
9d53c753 2817 if (type == PPC_64B) \
76db3ba4 2818 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2819 else \
76db3ba4
AJ
2820 gen_addr_imm_index(ctx, EA, 0); \
2821 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2822 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2823 tcg_temp_free(EA); \
79aceca5
FB
2824}
2825
0c8aacd4 2826#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2827static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2828{ \
b61f2753 2829 TCGv EA; \
76a66253
JM
2830 if (unlikely(rA(ctx->opcode) == 0 || \
2831 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2832 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2833 return; \
9a64fbe4 2834 } \
76db3ba4 2835 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2836 EA = tcg_temp_new(); \
76db3ba4
AJ
2837 gen_addr_reg_index(ctx, EA); \
2838 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2839 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2840 tcg_temp_free(EA); \
79aceca5
FB
2841}
2842
cd6e9320 2843#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2844static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2845{ \
76db3ba4
AJ
2846 TCGv EA; \
2847 gen_set_access_type(ctx, ACCESS_INT); \
2848 EA = tcg_temp_new(); \
2849 gen_addr_reg_index(ctx, EA); \
2850 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2851 tcg_temp_free(EA); \
79aceca5 2852}
cd6e9320
TH
2853#define GEN_LDX(name, ldop, opc2, opc3, type) \
2854 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2855
0c8aacd4
AJ
2856#define GEN_LDS(name, ldop, op, type) \
2857GEN_LD(name, ldop, op | 0x20, type); \
2858GEN_LDU(name, ldop, op | 0x21, type); \
2859GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2860GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2861
2862/* lbz lbzu lbzux lbzx */
0c8aacd4 2863GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2864/* lha lhau lhaux lhax */
0c8aacd4 2865GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2866/* lhz lhzu lhzux lhzx */
0c8aacd4 2867GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2868/* lwz lwzu lwzux lwzx */
0c8aacd4 2869GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2870#if defined(TARGET_PPC64)
d9bce9d9 2871/* lwaux */
0c8aacd4 2872GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2873/* lwax */
0c8aacd4 2874GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2875/* ldux */
0c8aacd4 2876GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2877/* ldx */
0c8aacd4 2878GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2879
2880static void gen_ld(DisasContext *ctx)
d9bce9d9 2881{
b61f2753 2882 TCGv EA;
d9bce9d9
JM
2883 if (Rc(ctx->opcode)) {
2884 if (unlikely(rA(ctx->opcode) == 0 ||
2885 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2886 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2887 return;
2888 }
2889 }
76db3ba4 2890 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2891 EA = tcg_temp_new();
76db3ba4 2892 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2893 if (ctx->opcode & 0x02) {
2894 /* lwa (lwau is undefined) */
76db3ba4 2895 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2896 } else {
2897 /* ld - ldu */
76db3ba4 2898 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2899 }
d9bce9d9 2900 if (Rc(ctx->opcode))
b61f2753
AJ
2901 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2902 tcg_temp_free(EA);
d9bce9d9 2903}
99e300ef 2904
54623277 2905/* lq */
99e300ef 2906static void gen_lq(DisasContext *ctx)
be147d08 2907{
be147d08 2908 int ra, rd;
b61f2753 2909 TCGv EA;
be147d08 2910
e0498daa
TM
2911 /* lq is a legal user mode instruction starting in ISA 2.07 */
2912 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2913 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2914
c47493f2 2915 if (!legal_in_user_mode && ctx->pr) {
e06fcd75 2916 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2917 return;
2918 }
e0498daa
TM
2919
2920 if (!le_is_supported && ctx->le_mode) {
2921 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2922 return;
2923 }
2924
be147d08
JM
2925 ra = rA(ctx->opcode);
2926 rd = rD(ctx->opcode);
2927 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2928 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2929 return;
2930 }
e0498daa 2931
76db3ba4 2932 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2933 EA = tcg_temp_new();
76db3ba4 2934 gen_addr_imm_index(ctx, EA, 0x0F);
e0498daa 2935
e22c357b
DK
2936 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
2937 64-bit byteswap already. */
e0498daa
TM
2938 if (unlikely(ctx->le_mode)) {
2939 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2940 gen_addr_add(ctx, EA, EA, 8);
2941 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2942 } else {
2943 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2944 gen_addr_add(ctx, EA, EA, 8);
2945 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2946 }
b61f2753 2947 tcg_temp_free(EA);
be147d08 2948}
d9bce9d9 2949#endif
79aceca5
FB
2950
2951/*** Integer store ***/
0c8aacd4 2952#define GEN_ST(name, stop, opc, type) \
99e300ef 2953static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2954{ \
76db3ba4
AJ
2955 TCGv EA; \
2956 gen_set_access_type(ctx, ACCESS_INT); \
2957 EA = tcg_temp_new(); \
2958 gen_addr_imm_index(ctx, EA, 0); \
2959 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2960 tcg_temp_free(EA); \
79aceca5
FB
2961}
2962
0c8aacd4 2963#define GEN_STU(name, stop, opc, type) \
99e300ef 2964static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2965{ \
b61f2753 2966 TCGv EA; \
76a66253 2967 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2968 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2969 return; \
9a64fbe4 2970 } \
76db3ba4 2971 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2972 EA = tcg_temp_new(); \
9d53c753 2973 if (type == PPC_64B) \
76db3ba4 2974 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2975 else \
76db3ba4
AJ
2976 gen_addr_imm_index(ctx, EA, 0); \
2977 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2978 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2979 tcg_temp_free(EA); \
79aceca5
FB
2980}
2981
0c8aacd4 2982#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2983static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2984{ \
b61f2753 2985 TCGv EA; \
76a66253 2986 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2987 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2988 return; \
9a64fbe4 2989 } \
76db3ba4 2990 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2991 EA = tcg_temp_new(); \
76db3ba4
AJ
2992 gen_addr_reg_index(ctx, EA); \
2993 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2994 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2995 tcg_temp_free(EA); \
79aceca5
FB
2996}
2997
cd6e9320
TH
2998#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2999static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3000{ \
76db3ba4
AJ
3001 TCGv EA; \
3002 gen_set_access_type(ctx, ACCESS_INT); \
3003 EA = tcg_temp_new(); \
3004 gen_addr_reg_index(ctx, EA); \
3005 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 3006 tcg_temp_free(EA); \
79aceca5 3007}
cd6e9320
TH
3008#define GEN_STX(name, stop, opc2, opc3, type) \
3009 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 3010
0c8aacd4
AJ
3011#define GEN_STS(name, stop, op, type) \
3012GEN_ST(name, stop, op | 0x20, type); \
3013GEN_STU(name, stop, op | 0x21, type); \
3014GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3015GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
3016
3017/* stb stbu stbux stbx */
0c8aacd4 3018GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 3019/* sth sthu sthux sthx */
0c8aacd4 3020GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 3021/* stw stwu stwux stwx */
0c8aacd4 3022GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 3023#if defined(TARGET_PPC64)
0c8aacd4
AJ
3024GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
3025GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
3026
3027static void gen_std(DisasContext *ctx)
d9bce9d9 3028{
be147d08 3029 int rs;
b61f2753 3030 TCGv EA;
be147d08
JM
3031
3032 rs = rS(ctx->opcode);
84cab1e2
TM
3033 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3034
3035 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3036 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3037
c47493f2 3038 if (!legal_in_user_mode && ctx->pr) {
e06fcd75 3039 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3040 return;
3041 }
84cab1e2
TM
3042
3043 if (!le_is_supported && ctx->le_mode) {
3044 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
d9bce9d9
JM
3045 return;
3046 }
84cab1e2
TM
3047
3048 if (unlikely(rs & 1)) {
3049 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3050 return;
3051 }
76db3ba4 3052 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3053 EA = tcg_temp_new();
76db3ba4 3054 gen_addr_imm_index(ctx, EA, 0x03);
84cab1e2 3055
e22c357b
DK
3056 /* We only need to swap high and low halves. gen_qemu_st64 does
3057 necessary 64-bit byteswap already. */
84cab1e2
TM
3058 if (unlikely(ctx->le_mode)) {
3059 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3060 gen_addr_add(ctx, EA, EA, 8);
3061 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3062 } else {
3063 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3064 gen_addr_add(ctx, EA, EA, 8);
3065 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3066 }
b61f2753 3067 tcg_temp_free(EA);
be147d08 3068 } else {
84cab1e2 3069 /* std / stdu*/
be147d08
JM
3070 if (Rc(ctx->opcode)) {
3071 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 3072 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3073 return;
3074 }
3075 }
76db3ba4 3076 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3077 EA = tcg_temp_new();
76db3ba4
AJ
3078 gen_addr_imm_index(ctx, EA, 0x03);
3079 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 3080 if (Rc(ctx->opcode))
b61f2753
AJ
3081 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3082 tcg_temp_free(EA);
d9bce9d9 3083 }
d9bce9d9
JM
3084}
3085#endif
79aceca5 3086/*** Integer load and store with byte reverse ***/
e22c357b 3087
79aceca5 3088/* lhbrx */
86178a57 3089static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3090{
e22c357b
DK
3091 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3092 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3093}
0c8aacd4 3094GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 3095
79aceca5 3096/* lwbrx */
86178a57 3097static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3098{
e22c357b
DK
3099 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3100 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3101}
0c8aacd4 3102GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 3103
cd6e9320
TH
3104#if defined(TARGET_PPC64)
3105/* ldbrx */
3106static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3107{
e22c357b
DK
3108 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3109 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
cd6e9320
TH
3110}
3111GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3112#endif /* TARGET_PPC64 */
3113
79aceca5 3114/* sthbrx */
86178a57 3115static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3116{
e22c357b
DK
3117 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3118 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3119}
0c8aacd4 3120GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 3121
79aceca5 3122/* stwbrx */
86178a57 3123static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3124{
e22c357b
DK
3125 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3126 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3127}
0c8aacd4 3128GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 3129
cd6e9320
TH
3130#if defined(TARGET_PPC64)
3131/* stdbrx */
3132static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3133{
e22c357b
DK
3134 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3135 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
cd6e9320
TH
3136}
3137GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3138#endif /* TARGET_PPC64 */
3139
79aceca5 3140/*** Integer load and store multiple ***/
99e300ef 3141
54623277 3142/* lmw */
99e300ef 3143static void gen_lmw(DisasContext *ctx)
79aceca5 3144{
76db3ba4
AJ
3145 TCGv t0;
3146 TCGv_i32 t1;
3147 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3148 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3149 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3150 t0 = tcg_temp_new();
3151 t1 = tcg_const_i32(rD(ctx->opcode));
3152 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3153 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3154 tcg_temp_free(t0);
3155 tcg_temp_free_i32(t1);
79aceca5
FB
3156}
3157
3158/* stmw */
99e300ef 3159static void gen_stmw(DisasContext *ctx)
79aceca5 3160{
76db3ba4
AJ
3161 TCGv t0;
3162 TCGv_i32 t1;
3163 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3164 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3165 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3166 t0 = tcg_temp_new();
3167 t1 = tcg_const_i32(rS(ctx->opcode));
3168 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3169 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3170 tcg_temp_free(t0);
3171 tcg_temp_free_i32(t1);
79aceca5
FB
3172}
3173
3174/*** Integer load and store strings ***/
54623277 3175
79aceca5 3176/* lswi */
3fc6c082 3177/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3178 * rA is in the range of registers to be loaded.
3179 * In an other hand, IBM says this is valid, but rA won't be loaded.
3180 * For now, I'll follow the spec...
3181 */
99e300ef 3182static void gen_lswi(DisasContext *ctx)
79aceca5 3183{
dfbc799d
AJ
3184 TCGv t0;
3185 TCGv_i32 t1, t2;
79aceca5
FB
3186 int nb = NB(ctx->opcode);
3187 int start = rD(ctx->opcode);
9a64fbe4 3188 int ra = rA(ctx->opcode);
79aceca5
FB
3189 int nr;
3190
3191 if (nb == 0)
3192 nb = 32;
afbee712
TH
3193 nr = (nb + 3) / 4;
3194 if (unlikely(lsw_reg_in_range(start, nr, ra))) {
e06fcd75 3195 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3196 return;
297d8e62 3197 }
76db3ba4 3198 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3199 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3200 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3201 t0 = tcg_temp_new();
76db3ba4 3202 gen_addr_register(ctx, t0);
dfbc799d
AJ
3203 t1 = tcg_const_i32(nb);
3204 t2 = tcg_const_i32(start);
2f5a189c 3205 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3206 tcg_temp_free(t0);
3207 tcg_temp_free_i32(t1);
3208 tcg_temp_free_i32(t2);
79aceca5
FB
3209}
3210
3211/* lswx */
99e300ef 3212static void gen_lswx(DisasContext *ctx)
79aceca5 3213{
76db3ba4
AJ
3214 TCGv t0;
3215 TCGv_i32 t1, t2, t3;
3216 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3217 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3218 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3219 t0 = tcg_temp_new();
3220 gen_addr_reg_index(ctx, t0);
3221 t1 = tcg_const_i32(rD(ctx->opcode));
3222 t2 = tcg_const_i32(rA(ctx->opcode));
3223 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3224 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3225 tcg_temp_free(t0);
3226 tcg_temp_free_i32(t1);
3227 tcg_temp_free_i32(t2);
3228 tcg_temp_free_i32(t3);
79aceca5
FB
3229}
3230
3231/* stswi */
99e300ef 3232static void gen_stswi(DisasContext *ctx)
79aceca5 3233{
76db3ba4
AJ
3234 TCGv t0;
3235 TCGv_i32 t1, t2;
4b3686fa 3236 int nb = NB(ctx->opcode);
76db3ba4 3237 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3238 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3239 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3240 t0 = tcg_temp_new();
3241 gen_addr_register(ctx, t0);
4b3686fa
FB
3242 if (nb == 0)
3243 nb = 32;
dfbc799d 3244 t1 = tcg_const_i32(nb);
76db3ba4 3245 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3246 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3247 tcg_temp_free(t0);
3248 tcg_temp_free_i32(t1);
3249 tcg_temp_free_i32(t2);
79aceca5
FB
3250}
3251
3252/* stswx */
99e300ef 3253static void gen_stswx(DisasContext *ctx)
79aceca5 3254{
76db3ba4
AJ
3255 TCGv t0;
3256 TCGv_i32 t1, t2;
3257 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3258 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3259 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3260 t0 = tcg_temp_new();
3261 gen_addr_reg_index(ctx, t0);
3262 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3263 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3264 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3265 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3266 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3267 tcg_temp_free(t0);
3268 tcg_temp_free_i32(t1);
3269 tcg_temp_free_i32(t2);
79aceca5
FB
3270}
3271
3272/*** Memory synchronisation ***/
3273/* eieio */
99e300ef 3274static void gen_eieio(DisasContext *ctx)
79aceca5 3275{
79aceca5
FB
3276}
3277
cd0c6f47
BH
3278#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
3279static inline void gen_check_tlb_flush(DisasContext *ctx)
3280{
3281 TCGv_i32 t = tcg_temp_new_i32();
3282 TCGLabel *l = gen_new_label();
3283
3284 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, tlb_need_flush));
3285 tcg_gen_brcondi_i32(TCG_COND_EQ, t, 0, l);
3286 gen_helper_check_tlb_flush(cpu_env);
3287 gen_set_label(l);
3288 tcg_temp_free_i32(t);
3289}
3290#else
3291static inline void gen_check_tlb_flush(DisasContext *ctx) { }
3292#endif
3293
79aceca5 3294/* isync */
99e300ef 3295static void gen_isync(DisasContext *ctx)
79aceca5 3296{
cd0c6f47
BH
3297 /*
3298 * We need to check for a pending TLB flush. This can only happen in
3299 * kernel mode however so check MSR_PR
3300 */
3301 if (!ctx->pr) {
3302 gen_check_tlb_flush(ctx);
3303 }
e06fcd75 3304 gen_stop_exception(ctx);
79aceca5
FB
3305}
3306
5c77a786
TM
3307#define LARX(name, len, loadop) \
3308static void gen_##name(DisasContext *ctx) \
3309{ \
3310 TCGv t0; \
3311 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3312 gen_set_access_type(ctx, ACCESS_RES); \
3313 t0 = tcg_temp_local_new(); \
3314 gen_addr_reg_index(ctx, t0); \
3315 if ((len) > 1) { \
3316 gen_check_align(ctx, t0, (len)-1); \
3317 } \
3318 gen_qemu_##loadop(ctx, gpr, t0); \
3319 tcg_gen_mov_tl(cpu_reserve, t0); \
3320 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3321 tcg_temp_free(t0); \
79aceca5
FB
3322}
3323
5c77a786
TM
3324/* lwarx */
3325LARX(lbarx, 1, ld8u);
3326LARX(lharx, 2, ld16u);
3327LARX(lwarx, 4, ld32u);
3328
3329
4425265b 3330#if defined(CONFIG_USER_ONLY)
587c51f7
TM
3331static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3332 int reg, int size)
4425265b
NF
3333{
3334 TCGv t0 = tcg_temp_new();
3335 uint32_t save_exception = ctx->exception;
3336
1328c2bf 3337 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3338 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3339 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3340 tcg_temp_free(t0);
3341 gen_update_nip(ctx, ctx->nip-4);
3342 ctx->exception = POWERPC_EXCP_BRANCH;
3343 gen_exception(ctx, POWERPC_EXCP_STCX);
3344 ctx->exception = save_exception;
3345}
4425265b 3346#else
587c51f7
TM
3347static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3348 int reg, int size)
3349{
42a268c2 3350 TCGLabel *l1;
4425265b 3351
587c51f7
TM
3352 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3353 l1 = gen_new_label();
3354 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3355 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3356#if defined(TARGET_PPC64)
3357 if (size == 8) {
3358 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3359 } else
3360#endif
3361 if (size == 4) {
3362 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3363 } else if (size == 2) {
3364 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
27b95bfe
TM
3365#if defined(TARGET_PPC64)
3366 } else if (size == 16) {
3707cd62 3367 TCGv gpr1, gpr2 , EA8;
27b95bfe
TM
3368 if (unlikely(ctx->le_mode)) {
3369 gpr1 = cpu_gpr[reg+1];
3370 gpr2 = cpu_gpr[reg];
3371 } else {
3372 gpr1 = cpu_gpr[reg];
3373 gpr2 = cpu_gpr[reg+1];
3374 }
3375 gen_qemu_st64(ctx, gpr1, EA);
3707cd62
TM
3376 EA8 = tcg_temp_local_new();
3377 gen_addr_add(ctx, EA8, EA, 8);
3378 gen_qemu_st64(ctx, gpr2, EA8);
3379 tcg_temp_free(EA8);
27b95bfe 3380#endif
587c51f7
TM
3381 } else {
3382 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
4425265b 3383 }
587c51f7
TM
3384 gen_set_label(l1);
3385 tcg_gen_movi_tl(cpu_reserve, -1);
3386}
4425265b 3387#endif
587c51f7
TM
3388
3389#define STCX(name, len) \
3390static void gen_##name(DisasContext *ctx) \
3391{ \
3392 TCGv t0; \
27b95bfe
TM
3393 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3394 gen_inval_exception(ctx, \
3395 POWERPC_EXCP_INVAL_INVAL); \
3396 return; \
3397 } \
587c51f7
TM
3398 gen_set_access_type(ctx, ACCESS_RES); \
3399 t0 = tcg_temp_local_new(); \
3400 gen_addr_reg_index(ctx, t0); \
3401 if (len > 1) { \
3402 gen_check_align(ctx, t0, (len)-1); \
3403 } \
3404 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3405 tcg_temp_free(t0); \
79aceca5
FB
3406}
3407
587c51f7
TM
3408STCX(stbcx_, 1);
3409STCX(sthcx_, 2);
3410STCX(stwcx_, 4);
3411
426613db 3412#if defined(TARGET_PPC64)
426613db 3413/* ldarx */
5c77a786 3414LARX(ldarx, 8, ld64);
426613db 3415
9c294d5a
TM
3416/* lqarx */
3417static void gen_lqarx(DisasContext *ctx)
3418{
3419 TCGv EA;
3420 int rd = rD(ctx->opcode);
3421 TCGv gpr1, gpr2;
3422
3423 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3424 (rd == rB(ctx->opcode)))) {
3425 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3426 return;
3427 }
3428
3429 gen_set_access_type(ctx, ACCESS_RES);
3430 EA = tcg_temp_local_new();
3431 gen_addr_reg_index(ctx, EA);
3432 gen_check_align(ctx, EA, 15);
3433 if (unlikely(ctx->le_mode)) {
3434 gpr1 = cpu_gpr[rd+1];
3435 gpr2 = cpu_gpr[rd];
3436 } else {
3437 gpr1 = cpu_gpr[rd];
3438 gpr2 = cpu_gpr[rd+1];
3439 }
3440 gen_qemu_ld64(ctx, gpr1, EA);
3441 tcg_gen_mov_tl(cpu_reserve, EA);
3442
3443 gen_addr_add(ctx, EA, EA, 8);
3444 gen_qemu_ld64(ctx, gpr2, EA);
3445
3446 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3447 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3448
3449 tcg_temp_free(EA);
3450}
3451
426613db 3452/* stdcx. */
587c51f7 3453STCX(stdcx_, 8);
27b95bfe 3454STCX(stqcx_, 16);
426613db
JM
3455#endif /* defined(TARGET_PPC64) */
3456
79aceca5 3457/* sync */
99e300ef 3458static void gen_sync(DisasContext *ctx)
79aceca5 3459{
cd0c6f47
BH
3460 uint32_t l = (ctx->opcode >> 21) & 3;
3461
3462 /*
3463 * For l == 2, it's a ptesync, We need to check for a pending TLB flush.
3464 * This can only happen in kernel mode however so check MSR_PR as well.
3465 */
3466 if (l == 2 && !ctx->pr) {
3467 gen_check_tlb_flush(ctx);
3468 }
79aceca5
FB
3469}
3470
0db1b20e 3471/* wait */
99e300ef 3472static void gen_wait(DisasContext *ctx)
0db1b20e 3473{
931ff272 3474 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3475 tcg_gen_st_i32(t0, cpu_env,
3476 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3477 tcg_temp_free_i32(t0);
0db1b20e 3478 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3479 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3480}
3481
79aceca5 3482/*** Floating-point load ***/
a0d7d5a7 3483#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3484static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3485{ \
a0d7d5a7 3486 TCGv EA; \
76a66253 3487 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3488 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3489 return; \
3490 } \
76db3ba4 3491 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3492 EA = tcg_temp_new(); \
76db3ba4
AJ
3493 gen_addr_imm_index(ctx, EA, 0); \
3494 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3495 tcg_temp_free(EA); \
79aceca5
FB
3496}
3497
a0d7d5a7 3498#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3499static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3500{ \
a0d7d5a7 3501 TCGv EA; \
76a66253 3502 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3503 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3504 return; \
3505 } \
76a66253 3506 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3507 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3508 return; \
9a64fbe4 3509 } \
76db3ba4 3510 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3511 EA = tcg_temp_new(); \
76db3ba4
AJ
3512 gen_addr_imm_index(ctx, EA, 0); \
3513 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3514 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3515 tcg_temp_free(EA); \
79aceca5
FB
3516}
3517
a0d7d5a7 3518#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3519static void glue(gen_, name##ux)(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_reg_index(ctx, EA); \
3533 gen_qemu_##ldop(ctx, cpu_fpr[rD(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_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3539static void glue(gen_, name##x)(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 } \
76db3ba4 3546 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3547 EA = tcg_temp_new(); \
76db3ba4
AJ
3548 gen_addr_reg_index(ctx, EA); \
3549 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3550 tcg_temp_free(EA); \
79aceca5
FB
3551}
3552
a0d7d5a7
AJ
3553#define GEN_LDFS(name, ldop, op, type) \
3554GEN_LDF(name, ldop, op | 0x20, type); \
3555GEN_LDUF(name, ldop, op | 0x21, type); \
3556GEN_LDUXF(name, ldop, op | 0x01, type); \
3557GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3558
636aa200 3559static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3560{
3561 TCGv t0 = tcg_temp_new();
3562 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3563 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3564 tcg_gen_trunc_tl_i32(t1, t0);
3565 tcg_temp_free(t0);
8e703949 3566 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3567 tcg_temp_free_i32(t1);
3568}
79aceca5 3569
a0d7d5a7
AJ
3570 /* lfd lfdu lfdux lfdx */
3571GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3572 /* lfs lfsu lfsux lfsx */
3573GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3574
05050ee8
AJ
3575/* lfdp */
3576static void gen_lfdp(DisasContext *ctx)
3577{
3578 TCGv EA;
3579 if (unlikely(!ctx->fpu_enabled)) {
3580 gen_exception(ctx, POWERPC_EXCP_FPU);
3581 return;
3582 }
3583 gen_set_access_type(ctx, ACCESS_FLOAT);
3584 EA = tcg_temp_new();
e22c357b
DK
3585 gen_addr_imm_index(ctx, EA, 0);
3586 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3587 64-bit byteswap already. */
05050ee8
AJ
3588 if (unlikely(ctx->le_mode)) {
3589 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3590 tcg_gen_addi_tl(EA, EA, 8);
3591 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3592 } else {
3593 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3594 tcg_gen_addi_tl(EA, EA, 8);
3595 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3596 }
3597 tcg_temp_free(EA);
3598}
3599
3600/* lfdpx */
3601static void gen_lfdpx(DisasContext *ctx)
3602{
3603 TCGv EA;
3604 if (unlikely(!ctx->fpu_enabled)) {
3605 gen_exception(ctx, POWERPC_EXCP_FPU);
3606 return;
3607 }
3608 gen_set_access_type(ctx, ACCESS_FLOAT);
3609 EA = tcg_temp_new();
3610 gen_addr_reg_index(ctx, EA);
e22c357b
DK
3611 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3612 64-bit byteswap already. */
05050ee8
AJ
3613 if (unlikely(ctx->le_mode)) {
3614 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3615 tcg_gen_addi_tl(EA, EA, 8);
3616 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3617 } else {
3618 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3619 tcg_gen_addi_tl(EA, EA, 8);
3620 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3621 }
3622 tcg_temp_free(EA);
3623}
3624
199f830d
AJ
3625/* lfiwax */
3626static void gen_lfiwax(DisasContext *ctx)
3627{
3628 TCGv EA;
3629 TCGv t0;
3630 if (unlikely(!ctx->fpu_enabled)) {
3631 gen_exception(ctx, POWERPC_EXCP_FPU);
3632 return;
3633 }
3634 gen_set_access_type(ctx, ACCESS_FLOAT);
3635 EA = tcg_temp_new();
3636 t0 = tcg_temp_new();
3637 gen_addr_reg_index(ctx, EA);
909eedb7 3638 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3639 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3640 tcg_temp_free(EA);
3641 tcg_temp_free(t0);
3642}
3643
66c3e328
TM
3644/* lfiwzx */
3645static void gen_lfiwzx(DisasContext *ctx)
3646{
3647 TCGv EA;
3648 if (unlikely(!ctx->fpu_enabled)) {
3649 gen_exception(ctx, POWERPC_EXCP_FPU);
3650 return;
3651 }
3652 gen_set_access_type(ctx, ACCESS_FLOAT);
3653 EA = tcg_temp_new();
3654 gen_addr_reg_index(ctx, EA);
3655 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3656 tcg_temp_free(EA);
3657}
79aceca5 3658/*** Floating-point store ***/
a0d7d5a7 3659#define GEN_STF(name, stop, opc, type) \
99e300ef 3660static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3661{ \
a0d7d5a7 3662 TCGv EA; \
76a66253 3663 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3664 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3665 return; \
3666 } \
76db3ba4 3667 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3668 EA = tcg_temp_new(); \
76db3ba4
AJ
3669 gen_addr_imm_index(ctx, EA, 0); \
3670 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3671 tcg_temp_free(EA); \
79aceca5
FB
3672}
3673
a0d7d5a7 3674#define GEN_STUF(name, stop, opc, type) \
99e300ef 3675static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3676{ \
a0d7d5a7 3677 TCGv EA; \
76a66253 3678 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3679 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3680 return; \
3681 } \
76a66253 3682 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3683 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3684 return; \
9a64fbe4 3685 } \
76db3ba4 3686 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3687 EA = tcg_temp_new(); \
76db3ba4
AJ
3688 gen_addr_imm_index(ctx, EA, 0); \
3689 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3690 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3691 tcg_temp_free(EA); \
79aceca5
FB
3692}
3693
a0d7d5a7 3694#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3695static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3696{ \
a0d7d5a7 3697 TCGv EA; \
76a66253 3698 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3699 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3700 return; \
3701 } \
76a66253 3702 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3703 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3704 return; \
9a64fbe4 3705 } \
76db3ba4 3706 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3707 EA = tcg_temp_new(); \
76db3ba4
AJ
3708 gen_addr_reg_index(ctx, EA); \
3709 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3710 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3711 tcg_temp_free(EA); \
79aceca5
FB
3712}
3713
a0d7d5a7 3714#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3715static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3716{ \
a0d7d5a7 3717 TCGv EA; \
76a66253 3718 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3719 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3720 return; \
3721 } \
76db3ba4 3722 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3723 EA = tcg_temp_new(); \
76db3ba4
AJ
3724 gen_addr_reg_index(ctx, EA); \
3725 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3726 tcg_temp_free(EA); \
79aceca5
FB
3727}
3728
a0d7d5a7
AJ
3729#define GEN_STFS(name, stop, op, type) \
3730GEN_STF(name, stop, op | 0x20, type); \
3731GEN_STUF(name, stop, op | 0x21, type); \
3732GEN_STUXF(name, stop, op | 0x01, type); \
3733GEN_STXF(name, stop, 0x17, op | 0x00, type)
3734
636aa200 3735static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3736{
3737 TCGv_i32 t0 = tcg_temp_new_i32();
3738 TCGv t1 = tcg_temp_new();
8e703949 3739 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3740 tcg_gen_extu_i32_tl(t1, t0);
3741 tcg_temp_free_i32(t0);
76db3ba4 3742 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3743 tcg_temp_free(t1);
3744}
79aceca5
FB
3745
3746/* stfd stfdu stfdux stfdx */
a0d7d5a7 3747GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3748/* stfs stfsu stfsux stfsx */
a0d7d5a7 3749GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3750
44bc0c4d
AJ
3751/* stfdp */
3752static void gen_stfdp(DisasContext *ctx)
3753{
3754 TCGv EA;
3755 if (unlikely(!ctx->fpu_enabled)) {
3756 gen_exception(ctx, POWERPC_EXCP_FPU);
3757 return;
3758 }
3759 gen_set_access_type(ctx, ACCESS_FLOAT);
3760 EA = tcg_temp_new();
e22c357b
DK
3761 gen_addr_imm_index(ctx, EA, 0);
3762 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3763 64-bit byteswap already. */
44bc0c4d
AJ
3764 if (unlikely(ctx->le_mode)) {
3765 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3766 tcg_gen_addi_tl(EA, EA, 8);
3767 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3768 } else {
3769 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3770 tcg_gen_addi_tl(EA, EA, 8);
3771 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3772 }
3773 tcg_temp_free(EA);
3774}
3775
3776/* stfdpx */
3777static void gen_stfdpx(DisasContext *ctx)
3778{
3779 TCGv EA;
3780 if (unlikely(!ctx->fpu_enabled)) {
3781 gen_exception(ctx, POWERPC_EXCP_FPU);
3782 return;
3783 }
3784 gen_set_access_type(ctx, ACCESS_FLOAT);
3785 EA = tcg_temp_new();
3786 gen_addr_reg_index(ctx, EA);
e22c357b
DK
3787 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3788 64-bit byteswap already. */
44bc0c4d
AJ
3789 if (unlikely(ctx->le_mode)) {
3790 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3791 tcg_gen_addi_tl(EA, EA, 8);
3792 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3793 } else {
3794 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3795 tcg_gen_addi_tl(EA, EA, 8);
3796 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3797 }
3798 tcg_temp_free(EA);
3799}
3800
79aceca5 3801/* Optional: */
636aa200 3802static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3803{
3804 TCGv t0 = tcg_temp_new();
3805 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3806 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3807 tcg_temp_free(t0);
3808}
79aceca5 3809/* stfiwx */
a0d7d5a7 3810GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3811
697ab892
DG
3812static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3813{
3814#if defined(TARGET_PPC64)
3815 if (ctx->has_cfar)
3816 tcg_gen_movi_tl(cpu_cfar, nip);
3817#endif
3818}
3819
90aa39a1
SF
3820static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest)
3821{
3822 if (unlikely(ctx->singlestep_enabled)) {
3823 return false;
3824 }
3825
3826#ifndef CONFIG_USER_ONLY
3827 return (ctx->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK);
3828#else
3829 return true;
3830#endif
3831}
3832
79aceca5 3833/*** Branch ***/
636aa200 3834static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362 3835{
e0c8f9ce 3836 if (NARROW_MODE(ctx)) {
a2ffb812 3837 dest = (uint32_t) dest;
e0c8f9ce 3838 }
90aa39a1 3839 if (use_goto_tb(ctx, dest)) {
57fec1fe 3840 tcg_gen_goto_tb(n);
a2ffb812 3841 tcg_gen_movi_tl(cpu_nip, dest & ~3);
90aa39a1 3842 tcg_gen_exit_tb((uintptr_t)ctx->tb + n);
c1942362 3843 } else {
a2ffb812 3844 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3845 if (unlikely(ctx->singlestep_enabled)) {
3846 if ((ctx->singlestep_enabled &
bdc4e053 3847 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3848 (ctx->exception == POWERPC_EXCP_BRANCH ||
3849 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3850 target_ulong tmp = ctx->nip;
3851 ctx->nip = dest;
e06fcd75 3852 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3853 ctx->nip = tmp;
3854 }
3855 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3856 gen_debug_exception(ctx);
8cbcb4fa
AJ
3857 }
3858 }
57fec1fe 3859 tcg_gen_exit_tb(0);
c1942362 3860 }
c53be334
FB
3861}
3862
636aa200 3863static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3864{
e0c8f9ce
RH
3865 if (NARROW_MODE(ctx)) {
3866 nip = (uint32_t)nip;
3867 }
3868 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3869}
3870
79aceca5 3871/* b ba bl bla */
99e300ef 3872static void gen_b(DisasContext *ctx)
79aceca5 3873{
76a66253 3874 target_ulong li, target;
38a64f9d 3875
8cbcb4fa 3876 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3877 /* sign extend LI */
e0c8f9ce
RH
3878 li = LI(ctx->opcode);
3879 li = (li ^ 0x02000000) - 0x02000000;
3880 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3881 target = ctx->nip + li - 4;
e0c8f9ce 3882 } else {
9a64fbe4 3883 target = li;
e0c8f9ce
RH
3884 }
3885 if (LK(ctx->opcode)) {
e1833e1f 3886 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3887 }
697ab892 3888 gen_update_cfar(ctx, ctx->nip);
c1942362 3889 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3890}
3891
e98a6e40
FB
3892#define BCOND_IM 0
3893#define BCOND_LR 1
3894#define BCOND_CTR 2
52a4984d 3895#define BCOND_TAR 3
e98a6e40 3896
636aa200 3897static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3898{
d9bce9d9 3899 uint32_t bo = BO(ctx->opcode);
42a268c2 3900 TCGLabel *l1;
a2ffb812 3901 TCGv target;
e98a6e40 3902
8cbcb4fa 3903 ctx->exception = POWERPC_EXCP_BRANCH;
52a4984d 3904 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
a7812ae4 3905 target = tcg_temp_local_new();
a2ffb812
AJ
3906 if (type == BCOND_CTR)
3907 tcg_gen_mov_tl(target, cpu_ctr);
52a4984d
TM
3908 else if (type == BCOND_TAR)
3909 gen_load_spr(target, SPR_TAR);
a2ffb812
AJ
3910 else
3911 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3912 } else {
3913 TCGV_UNUSED(target);
e98a6e40 3914 }
e1833e1f
JM
3915 if (LK(ctx->opcode))
3916 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3917 l1 = gen_new_label();
3918 if ((bo & 0x4) == 0) {
3919 /* Decrement and test CTR */
a7812ae4 3920 TCGv temp = tcg_temp_new();
a2ffb812 3921 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3922 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3923 return;
3924 }
3925 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3926 if (NARROW_MODE(ctx)) {
a2ffb812 3927 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3928 } else {
a2ffb812 3929 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3930 }
a2ffb812
AJ
3931 if (bo & 0x2) {
3932 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3933 } else {
3934 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3935 }
a7812ae4 3936 tcg_temp_free(temp);
a2ffb812
AJ
3937 }
3938 if ((bo & 0x10) == 0) {
3939 /* Test CR */
3940 uint32_t bi = BI(ctx->opcode);
8f9fb7ac 3941 uint32_t mask = 0x08 >> (bi & 0x03);
a7812ae4 3942 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3943
d9bce9d9 3944 if (bo & 0x8) {
a2ffb812
AJ
3945 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3946 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3947 } else {
a2ffb812
AJ
3948 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3949 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3950 }
a7812ae4 3951 tcg_temp_free_i32(temp);
d9bce9d9 3952 }
697ab892 3953 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3954 if (type == BCOND_IM) {
a2ffb812
AJ
3955 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3956 if (likely(AA(ctx->opcode) == 0)) {
3957 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3958 } else {
3959 gen_goto_tb(ctx, 0, li);
3960 }
c53be334 3961 gen_set_label(l1);
c1942362 3962 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3963 } else {
e0c8f9ce 3964 if (NARROW_MODE(ctx)) {
a2ffb812 3965 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3966 } else {
a2ffb812 3967 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3968 }
a2ffb812
AJ
3969 tcg_gen_exit_tb(0);
3970 gen_set_label(l1);
e0c8f9ce 3971 gen_update_nip(ctx, ctx->nip);
57fec1fe 3972 tcg_gen_exit_tb(0);
08e46e54 3973 }
a9e8f4e7 3974 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
c80d1df5
AG
3975 tcg_temp_free(target);
3976 }
e98a6e40
FB
3977}
3978
99e300ef 3979static void gen_bc(DisasContext *ctx)
3b46e624 3980{
e98a6e40
FB
3981 gen_bcond(ctx, BCOND_IM);
3982}
3983
99e300ef 3984static void gen_bcctr(DisasContext *ctx)
3b46e624 3985{
e98a6e40
FB
3986 gen_bcond(ctx, BCOND_CTR);
3987}
3988
99e300ef 3989static void gen_bclr(DisasContext *ctx)
3b46e624 3990{
e98a6e40
FB
3991 gen_bcond(ctx, BCOND_LR);
3992}
79aceca5 3993
52a4984d
TM
3994static void gen_bctar(DisasContext *ctx)
3995{
3996 gen_bcond(ctx, BCOND_TAR);
3997}
3998
79aceca5 3999/*** Condition register logical ***/
e1571908 4000#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 4001static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 4002{ \
fc0d441e
JM
4003 uint8_t bitmask; \
4004 int sh; \
a7812ae4 4005 TCGv_i32 t0, t1; \
fc0d441e 4006 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 4007 t0 = tcg_temp_new_i32(); \
fc0d441e 4008 if (sh > 0) \
fea0c503 4009 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 4010 else if (sh < 0) \
fea0c503 4011 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 4012 else \
fea0c503 4013 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 4014 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
4015 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4016 if (sh > 0) \
fea0c503 4017 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 4018 else if (sh < 0) \
fea0c503 4019 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 4020 else \
fea0c503
AJ
4021 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4022 tcg_op(t0, t0, t1); \
8f9fb7ac 4023 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
fea0c503
AJ
4024 tcg_gen_andi_i32(t0, t0, bitmask); \
4025 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4026 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
4027 tcg_temp_free_i32(t0); \
4028 tcg_temp_free_i32(t1); \
79aceca5
FB
4029}
4030
4031/* crand */
e1571908 4032GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 4033/* crandc */
e1571908 4034GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 4035/* creqv */
e1571908 4036GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 4037/* crnand */
e1571908 4038GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 4039/* crnor */
e1571908 4040GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 4041/* cror */
e1571908 4042GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 4043/* crorc */
e1571908 4044GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 4045/* crxor */
e1571908 4046GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 4047
54623277 4048/* mcrf */
99e300ef 4049static void gen_mcrf(DisasContext *ctx)
79aceca5 4050{
47e4661c 4051 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
4052}
4053
4054/*** System linkage ***/
99e300ef 4055
c47493f2 4056/* rfi (supervisor only) */
99e300ef 4057static void gen_rfi(DisasContext *ctx)
79aceca5 4058{
9a64fbe4 4059#if defined(CONFIG_USER_ONLY)
e06fcd75 4060 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
4061#else
4062 /* Restore CPU state */
c47493f2 4063 if (unlikely(ctx->pr)) {
e06fcd75 4064 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4065 return;
9a64fbe4 4066 }
697ab892 4067 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4068 gen_helper_rfi(cpu_env);
e06fcd75 4069 gen_sync_exception(ctx);
9a64fbe4 4070#endif
79aceca5
FB
4071}
4072
426613db 4073#if defined(TARGET_PPC64)
99e300ef 4074static void gen_rfid(DisasContext *ctx)
426613db
JM
4075{
4076#if defined(CONFIG_USER_ONLY)
e06fcd75 4077 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4078#else
4079 /* Restore CPU state */
c47493f2 4080 if (unlikely(ctx->pr)) {
e06fcd75 4081 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4082 return;
4083 }
697ab892 4084 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4085 gen_helper_rfid(cpu_env);
e06fcd75 4086 gen_sync_exception(ctx);
426613db
JM
4087#endif
4088}
426613db 4089
99e300ef 4090static void gen_hrfid(DisasContext *ctx)
be147d08
JM
4091{
4092#if defined(CONFIG_USER_ONLY)
e06fcd75 4093 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4094#else
4095 /* Restore CPU state */
c47493f2 4096 if (unlikely(!ctx->hv)) {
e06fcd75 4097 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4098 return;
4099 }
e5f17ac6 4100 gen_helper_hrfid(cpu_env);
e06fcd75 4101 gen_sync_exception(ctx);
be147d08
JM
4102#endif
4103}
4104#endif
4105
79aceca5 4106/* sc */
417bf010
JM
4107#if defined(CONFIG_USER_ONLY)
4108#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4109#else
4110#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4111#endif
99e300ef 4112static void gen_sc(DisasContext *ctx)
79aceca5 4113{
e1833e1f
JM
4114 uint32_t lev;
4115
4116 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 4117 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
4118}
4119
4120/*** Trap ***/
99e300ef 4121
54623277 4122/* tw */
99e300ef 4123static void gen_tw(DisasContext *ctx)
79aceca5 4124{
cab3bee2 4125 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4126 /* Update the nip since this might generate a trap exception */
4127 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4128 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4129 t0);
cab3bee2 4130 tcg_temp_free_i32(t0);
79aceca5
FB
4131}
4132
4133/* twi */
99e300ef 4134static void gen_twi(DisasContext *ctx)
79aceca5 4135{
cab3bee2
AJ
4136 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4137 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4138 /* Update the nip since this might generate a trap exception */
4139 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4140 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4141 tcg_temp_free(t0);
4142 tcg_temp_free_i32(t1);
79aceca5
FB
4143}
4144
d9bce9d9
JM
4145#if defined(TARGET_PPC64)
4146/* td */
99e300ef 4147static void gen_td(DisasContext *ctx)
d9bce9d9 4148{
cab3bee2 4149 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4150 /* Update the nip since this might generate a trap exception */
4151 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4152 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4153 t0);
cab3bee2 4154 tcg_temp_free_i32(t0);
d9bce9d9
JM
4155}
4156
4157/* tdi */
99e300ef 4158static void gen_tdi(DisasContext *ctx)
d9bce9d9 4159{
cab3bee2
AJ
4160 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4161 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4162 /* Update the nip since this might generate a trap exception */
4163 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4164 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4165 tcg_temp_free(t0);
4166 tcg_temp_free_i32(t1);
d9bce9d9
JM
4167}
4168#endif
4169
79aceca5 4170/*** Processor control ***/
99e300ef 4171
da91a00f
RH
4172static void gen_read_xer(TCGv dst)
4173{
4174 TCGv t0 = tcg_temp_new();
4175 TCGv t1 = tcg_temp_new();
4176 TCGv t2 = tcg_temp_new();
4177 tcg_gen_mov_tl(dst, cpu_xer);
4178 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4179 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4180 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4181 tcg_gen_or_tl(t0, t0, t1);
4182 tcg_gen_or_tl(dst, dst, t2);
4183 tcg_gen_or_tl(dst, dst, t0);
4184 tcg_temp_free(t0);
4185 tcg_temp_free(t1);
4186 tcg_temp_free(t2);
4187}
4188
4189static void gen_write_xer(TCGv src)
4190{
4191 tcg_gen_andi_tl(cpu_xer, src,
4192 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4193 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4194 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4195 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4196 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4197 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4198 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4199}
4200
54623277 4201/* mcrxr */
99e300ef 4202static void gen_mcrxr(DisasContext *ctx)
79aceca5 4203{
da91a00f
RH
4204 TCGv_i32 t0 = tcg_temp_new_i32();
4205 TCGv_i32 t1 = tcg_temp_new_i32();
4206 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4207
4208 tcg_gen_trunc_tl_i32(t0, cpu_so);
4209 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4210 tcg_gen_trunc_tl_i32(dst, cpu_ca);
294d1292
SB
4211 tcg_gen_shli_i32(t0, t0, 3);
4212 tcg_gen_shli_i32(t1, t1, 2);
4213 tcg_gen_shli_i32(dst, dst, 1);
da91a00f
RH
4214 tcg_gen_or_i32(dst, dst, t0);
4215 tcg_gen_or_i32(dst, dst, t1);
4216 tcg_temp_free_i32(t0);
4217 tcg_temp_free_i32(t1);
4218
4219 tcg_gen_movi_tl(cpu_so, 0);
4220 tcg_gen_movi_tl(cpu_ov, 0);
4221 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
4222}
4223
0cfe11ea 4224/* mfcr mfocrf */
99e300ef 4225static void gen_mfcr(DisasContext *ctx)
79aceca5 4226{
76a66253 4227 uint32_t crm, crn;
3b46e624 4228
76a66253
JM
4229 if (likely(ctx->opcode & 0x00100000)) {
4230 crm = CRM(ctx->opcode);
8dd640e4 4231 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 4232 crn = ctz32 (crm);
e1571908 4233 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
4234 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4235 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 4236 }
d9bce9d9 4237 } else {
651721b2
AJ
4238 TCGv_i32 t0 = tcg_temp_new_i32();
4239 tcg_gen_mov_i32(t0, cpu_crf[0]);
4240 tcg_gen_shli_i32(t0, t0, 4);
4241 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4242 tcg_gen_shli_i32(t0, t0, 4);
4243 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4244 tcg_gen_shli_i32(t0, t0, 4);
4245 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4246 tcg_gen_shli_i32(t0, t0, 4);
4247 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4248 tcg_gen_shli_i32(t0, t0, 4);
4249 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4250 tcg_gen_shli_i32(t0, t0, 4);
4251 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4252 tcg_gen_shli_i32(t0, t0, 4);
4253 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4254 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4255 tcg_temp_free_i32(t0);
d9bce9d9 4256 }
79aceca5
FB
4257}
4258
4259/* mfmsr */
99e300ef 4260static void gen_mfmsr(DisasContext *ctx)
79aceca5 4261{
9a64fbe4 4262#if defined(CONFIG_USER_ONLY)
e06fcd75 4263 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4264#else
c47493f2 4265 if (unlikely(ctx->pr)) {
e06fcd75 4266 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4267 return;
9a64fbe4 4268 }
6527f6ea 4269 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4270#endif
79aceca5
FB
4271}
4272
69b058c8 4273static void spr_noaccess(DisasContext *ctx, int gprn, int sprn)
3fc6c082 4274{
7b13448f 4275#if 0
3fc6c082
FB
4276 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4277 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4278#endif
3fc6c082
FB
4279}
4280#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4281
79aceca5 4282/* mfspr */
636aa200 4283static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4284{
69b058c8 4285 void (*read_cb)(DisasContext *ctx, int gprn, int sprn);
79aceca5
FB
4286 uint32_t sprn = SPR(ctx->opcode);
4287
eb94268e
BH
4288#if defined(CONFIG_USER_ONLY)
4289 read_cb = ctx->spr_cb[sprn].uea_read;
4290#else
4291 if (ctx->pr) {
4292 read_cb = ctx->spr_cb[sprn].uea_read;
4293 } else if (ctx->hv) {
be147d08 4294 read_cb = ctx->spr_cb[sprn].hea_read;
eb94268e 4295 } else {
3fc6c082 4296 read_cb = ctx->spr_cb[sprn].oea_read;
eb94268e 4297 }
9a64fbe4 4298#endif
76a66253
JM
4299 if (likely(read_cb != NULL)) {
4300 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4301 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4302 } else {
4303 /* Privilege exception */
9fceefa7
JM
4304 /* This is a hack to avoid warnings when running Linux:
4305 * this OS breaks the PowerPC virtualisation model,
4306 * allowing userland application to read the PVR
4307 */
4308 if (sprn != SPR_PVR) {
013a2942
PB
4309 fprintf(stderr, "Trying to read privileged spr %d (0x%03x) at "
4310 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4311 if (qemu_log_separate()) {
4312 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4313 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4314 }
f24e5695 4315 }
e06fcd75 4316 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4317 }
3fc6c082
FB
4318 } else {
4319 /* Not defined */
013a2942
PB
4320 fprintf(stderr, "Trying to read invalid spr %d (0x%03x) at "
4321 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4322 if (qemu_log_separate()) {
4323 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4324 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4325 }
e06fcd75 4326 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4327 }
79aceca5
FB
4328}
4329
99e300ef 4330static void gen_mfspr(DisasContext *ctx)
79aceca5 4331{
3fc6c082 4332 gen_op_mfspr(ctx);
76a66253 4333}
3fc6c082
FB
4334
4335/* mftb */
99e300ef 4336static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4337{
4338 gen_op_mfspr(ctx);
79aceca5
FB
4339}
4340
0cfe11ea 4341/* mtcrf mtocrf*/
99e300ef 4342static void gen_mtcrf(DisasContext *ctx)
79aceca5 4343{
76a66253 4344 uint32_t crm, crn;
3b46e624 4345
76a66253 4346 crm = CRM(ctx->opcode);
8dd640e4 4347 if (likely((ctx->opcode & 0x00100000))) {
4348 if (crm && ((crm & (crm - 1)) == 0)) {
4349 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4350 crn = ctz32 (crm);
8dd640e4 4351 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4352 tcg_gen_shri_i32(temp, temp, crn * 4);
4353 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4354 tcg_temp_free_i32(temp);
4355 }
76a66253 4356 } else {
651721b2
AJ
4357 TCGv_i32 temp = tcg_temp_new_i32();
4358 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4359 for (crn = 0 ; crn < 8 ; crn++) {
4360 if (crm & (1 << crn)) {
4361 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4362 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4363 }
4364 }
a7812ae4 4365 tcg_temp_free_i32(temp);
76a66253 4366 }
79aceca5
FB
4367}
4368
4369/* mtmsr */
426613db 4370#if defined(TARGET_PPC64)
99e300ef 4371static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4372{
4373#if defined(CONFIG_USER_ONLY)
e06fcd75 4374 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4375#else
c47493f2 4376 if (unlikely(ctx->pr)) {
e06fcd75 4377 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4378 return;
4379 }
be147d08
JM
4380 if (ctx->opcode & 0x00010000) {
4381 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4382 TCGv t0 = tcg_temp_new();
4383 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4384 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4385 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4386 tcg_temp_free(t0);
be147d08 4387 } else {
056b05f8
JM
4388 /* XXX: we need to update nip before the store
4389 * if we enter power saving mode, we will exit the loop
4390 * directly from ppc_store_msr
4391 */
be147d08 4392 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4393 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4394 /* Must stop the translation as machine state (may have) changed */
4395 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4396 gen_stop_exception(ctx);
be147d08 4397 }
426613db
JM
4398#endif
4399}
4400#endif
4401
99e300ef 4402static void gen_mtmsr(DisasContext *ctx)
79aceca5 4403{
9a64fbe4 4404#if defined(CONFIG_USER_ONLY)
e06fcd75 4405 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4406#else
c47493f2 4407 if (unlikely(ctx->pr)) {
e06fcd75 4408 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4409 return;
9a64fbe4 4410 }
be147d08
JM
4411 if (ctx->opcode & 0x00010000) {
4412 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4413 TCGv t0 = tcg_temp_new();
4414 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4415 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4416 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4417 tcg_temp_free(t0);
be147d08 4418 } else {
8018dc63
AG
4419 TCGv msr = tcg_temp_new();
4420
056b05f8
JM
4421 /* XXX: we need to update nip before the store
4422 * if we enter power saving mode, we will exit the loop
4423 * directly from ppc_store_msr
4424 */
be147d08 4425 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4426#if defined(TARGET_PPC64)
8018dc63
AG
4427 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4428#else
4429 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4430#endif
e5f17ac6 4431 gen_helper_store_msr(cpu_env, msr);
c80d1df5 4432 tcg_temp_free(msr);
be147d08 4433 /* Must stop the translation as machine state (may have) changed */
6527f6ea 4434 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4435 gen_stop_exception(ctx);
be147d08 4436 }
9a64fbe4 4437#endif
79aceca5
FB
4438}
4439
4440/* mtspr */
99e300ef 4441static void gen_mtspr(DisasContext *ctx)
79aceca5 4442{
69b058c8 4443 void (*write_cb)(DisasContext *ctx, int sprn, int gprn);
79aceca5
FB
4444 uint32_t sprn = SPR(ctx->opcode);
4445
eb94268e
BH
4446#if defined(CONFIG_USER_ONLY)
4447 write_cb = ctx->spr_cb[sprn].uea_write;
4448#else
4449 if (ctx->pr) {
4450 write_cb = ctx->spr_cb[sprn].uea_write;
4451 } else if (ctx->hv) {
be147d08 4452 write_cb = ctx->spr_cb[sprn].hea_write;
eb94268e 4453 } else {
3fc6c082 4454 write_cb = ctx->spr_cb[sprn].oea_write;
eb94268e 4455 }
9a64fbe4 4456#endif
76a66253
JM
4457 if (likely(write_cb != NULL)) {
4458 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 4459 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
4460 } else {
4461 /* Privilege exception */
013a2942
PB
4462 fprintf(stderr, "Trying to write privileged spr %d (0x%03x) at "
4463 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4464 if (qemu_log_separate()) {
4465 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4466 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4467 }
e06fcd75 4468 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 4469 }
3fc6c082
FB
4470 } else {
4471 /* Not defined */
013a2942
PB
4472 if (qemu_log_separate()) {
4473 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4474 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4475 }
4476 fprintf(stderr, "Trying to write invalid spr %d (0x%03x) at "
4477 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4478 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4479 }
79aceca5
FB
4480}
4481
4482/*** Cache management ***/
99e300ef 4483
54623277 4484/* dcbf */
99e300ef 4485static void gen_dcbf(DisasContext *ctx)
79aceca5 4486{
dac454af 4487 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
4488 TCGv t0;
4489 gen_set_access_type(ctx, ACCESS_CACHE);
4490 t0 = tcg_temp_new();
4491 gen_addr_reg_index(ctx, t0);
4492 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4493 tcg_temp_free(t0);
79aceca5
FB
4494}
4495
4496/* dcbi (Supervisor only) */
99e300ef 4497static void gen_dcbi(DisasContext *ctx)
79aceca5 4498{
a541f297 4499#if defined(CONFIG_USER_ONLY)
e06fcd75 4500 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 4501#else
b61f2753 4502 TCGv EA, val;
c47493f2 4503 if (unlikely(ctx->pr)) {
e06fcd75 4504 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4505 return;
9a64fbe4 4506 }
a7812ae4 4507 EA = tcg_temp_new();
76db3ba4
AJ
4508 gen_set_access_type(ctx, ACCESS_CACHE);
4509 gen_addr_reg_index(ctx, EA);
a7812ae4 4510 val = tcg_temp_new();
76a66253 4511 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
4512 gen_qemu_ld8u(ctx, val, EA);
4513 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
4514 tcg_temp_free(val);
4515 tcg_temp_free(EA);
a541f297 4516#endif
79aceca5
FB
4517}
4518
4519/* dcdst */
99e300ef 4520static void gen_dcbst(DisasContext *ctx)
79aceca5 4521{
76a66253 4522 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
4523 TCGv t0;
4524 gen_set_access_type(ctx, ACCESS_CACHE);
4525 t0 = tcg_temp_new();
4526 gen_addr_reg_index(ctx, t0);
4527 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4528 tcg_temp_free(t0);
79aceca5
FB
4529}
4530
4531/* dcbt */
99e300ef 4532static void gen_dcbt(DisasContext *ctx)
79aceca5 4533{
0db1b20e 4534 /* interpreted as no-op */
76a66253
JM
4535 /* XXX: specification say this is treated as a load by the MMU
4536 * but does not generate any exception
4537 */
79aceca5
FB
4538}
4539
4540/* dcbtst */
99e300ef 4541static void gen_dcbtst(DisasContext *ctx)
79aceca5 4542{
0db1b20e 4543 /* interpreted as no-op */
76a66253
JM
4544 /* XXX: specification say this is treated as a load by the MMU
4545 * but does not generate any exception
4546 */
79aceca5
FB
4547}
4548
4d09d529
AG
4549/* dcbtls */
4550static void gen_dcbtls(DisasContext *ctx)
4551{
4552 /* Always fails locking the cache */
4553 TCGv t0 = tcg_temp_new();
4554 gen_load_spr(t0, SPR_Exxx_L1CSR0);
4555 tcg_gen_ori_tl(t0, t0, L1CSR0_CUL);
4556 gen_store_spr(SPR_Exxx_L1CSR0, t0);
4557 tcg_temp_free(t0);
4558}
4559
79aceca5 4560/* dcbz */
99e300ef 4561static void gen_dcbz(DisasContext *ctx)
79aceca5 4562{
8e33944f
AG
4563 TCGv tcgv_addr;
4564 TCGv_i32 tcgv_is_dcbzl;
4565 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4566
76db3ba4 4567 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4568 /* NIP cannot be restored if the memory exception comes from an helper */
4569 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4570 tcgv_addr = tcg_temp_new();
4571 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4572
4573 gen_addr_reg_index(ctx, tcgv_addr);
4574 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4575
4576 tcg_temp_free(tcgv_addr);
4577 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4578}
4579
ae1c1a3d 4580/* dst / dstt */
99e300ef 4581static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4582{
4583 if (rA(ctx->opcode) == 0) {
4584 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4585 } else {
4586 /* interpreted as no-op */
4587 }
4588}
4589
4590/* dstst /dststt */
99e300ef 4591static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4592{
4593 if (rA(ctx->opcode) == 0) {
4594 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4595 } else {
4596 /* interpreted as no-op */
4597 }
4598
4599}
4600
4601/* dss / dssall */
99e300ef 4602static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4603{
4604 /* interpreted as no-op */
4605}
4606
79aceca5 4607/* icbi */
99e300ef 4608static void gen_icbi(DisasContext *ctx)
79aceca5 4609{
76db3ba4
AJ
4610 TCGv t0;
4611 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4612 /* NIP cannot be restored if the memory exception comes from an helper */
4613 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4614 t0 = tcg_temp_new();
4615 gen_addr_reg_index(ctx, t0);
2f5a189c 4616 gen_helper_icbi(cpu_env, t0);
37d269df 4617 tcg_temp_free(t0);
79aceca5
FB
4618}
4619
4620/* Optional: */
4621/* dcba */
99e300ef 4622static void gen_dcba(DisasContext *ctx)
79aceca5 4623{
0db1b20e
JM
4624 /* interpreted as no-op */
4625 /* XXX: specification say this is treated as a store by the MMU
4626 * but does not generate any exception
4627 */
79aceca5
FB
4628}
4629
4630/*** Segment register manipulation ***/
4631/* Supervisor only: */
99e300ef 4632
54623277 4633/* mfsr */
99e300ef 4634static void gen_mfsr(DisasContext *ctx)
79aceca5 4635{
9a64fbe4 4636#if defined(CONFIG_USER_ONLY)
e06fcd75 4637 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4638#else
74d37793 4639 TCGv t0;
c47493f2 4640 if (unlikely(ctx->pr)) {
e06fcd75 4641 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4642 return;
9a64fbe4 4643 }
74d37793 4644 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4645 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4646 tcg_temp_free(t0);
9a64fbe4 4647#endif
79aceca5
FB
4648}
4649
4650/* mfsrin */
99e300ef 4651static void gen_mfsrin(DisasContext *ctx)
79aceca5 4652{
9a64fbe4 4653#if defined(CONFIG_USER_ONLY)
e06fcd75 4654 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4655#else
74d37793 4656 TCGv t0;
c47493f2 4657 if (unlikely(ctx->pr)) {
e06fcd75 4658 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4659 return;
9a64fbe4 4660 }
74d37793
AJ
4661 t0 = tcg_temp_new();
4662 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4663 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4664 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4665 tcg_temp_free(t0);
9a64fbe4 4666#endif
79aceca5
FB
4667}
4668
4669/* mtsr */
99e300ef 4670static void gen_mtsr(DisasContext *ctx)
79aceca5 4671{
9a64fbe4 4672#if defined(CONFIG_USER_ONLY)
e06fcd75 4673 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4674#else
74d37793 4675 TCGv t0;
c47493f2 4676 if (unlikely(ctx->pr)) {
e06fcd75 4677 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4678 return;
9a64fbe4 4679 }
74d37793 4680 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4681 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4682 tcg_temp_free(t0);
9a64fbe4 4683#endif
79aceca5
FB
4684}
4685
4686/* mtsrin */
99e300ef 4687static void gen_mtsrin(DisasContext *ctx)
79aceca5 4688{
9a64fbe4 4689#if defined(CONFIG_USER_ONLY)
e06fcd75 4690 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4691#else
74d37793 4692 TCGv t0;
c47493f2 4693 if (unlikely(ctx->pr)) {
e06fcd75 4694 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4695 return;
9a64fbe4 4696 }
74d37793
AJ
4697 t0 = tcg_temp_new();
4698 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4699 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4700 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4701 tcg_temp_free(t0);
9a64fbe4 4702#endif
79aceca5
FB
4703}
4704
12de9a39
JM
4705#if defined(TARGET_PPC64)
4706/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4707
54623277 4708/* mfsr */
e8eaa2c0 4709static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4710{
4711#if defined(CONFIG_USER_ONLY)
e06fcd75 4712 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4713#else
74d37793 4714 TCGv t0;
c47493f2 4715 if (unlikely(ctx->pr)) {
e06fcd75 4716 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4717 return;
4718 }
74d37793 4719 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4720 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4721 tcg_temp_free(t0);
12de9a39
JM
4722#endif
4723}
4724
4725/* mfsrin */
e8eaa2c0 4726static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4727{
4728#if defined(CONFIG_USER_ONLY)
e06fcd75 4729 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4730#else
74d37793 4731 TCGv t0;
c47493f2 4732 if (unlikely(ctx->pr)) {
e06fcd75 4733 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4734 return;
4735 }
74d37793
AJ
4736 t0 = tcg_temp_new();
4737 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4738 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4739 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4740 tcg_temp_free(t0);
12de9a39
JM
4741#endif
4742}
4743
4744/* mtsr */
e8eaa2c0 4745static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4746{
4747#if defined(CONFIG_USER_ONLY)
e06fcd75 4748 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4749#else
74d37793 4750 TCGv t0;
c47493f2 4751 if (unlikely(ctx->pr)) {
e06fcd75 4752 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4753 return;
4754 }
74d37793 4755 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4756 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4757 tcg_temp_free(t0);
12de9a39
JM
4758#endif
4759}
4760
4761/* mtsrin */
e8eaa2c0 4762static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4763{
4764#if defined(CONFIG_USER_ONLY)
e06fcd75 4765 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4766#else
74d37793 4767 TCGv t0;
c47493f2 4768 if (unlikely(ctx->pr)) {
e06fcd75 4769 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4770 return;
4771 }
74d37793
AJ
4772 t0 = tcg_temp_new();
4773 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4774 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4775 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4776 tcg_temp_free(t0);
12de9a39
JM
4777#endif
4778}
f6b868fc
BS
4779
4780/* slbmte */
e8eaa2c0 4781static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4782{
4783#if defined(CONFIG_USER_ONLY)
4784 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4785#else
c47493f2 4786 if (unlikely(ctx->pr)) {
f6b868fc
BS
4787 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4788 return;
4789 }
c6c7cf05
BS
4790 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4791 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4792#endif
4793}
4794
efdef95f
DG
4795static void gen_slbmfee(DisasContext *ctx)
4796{
4797#if defined(CONFIG_USER_ONLY)
4798 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4799#else
c47493f2 4800 if (unlikely(ctx->pr)) {
efdef95f
DG
4801 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4802 return;
4803 }
c6c7cf05 4804 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4805 cpu_gpr[rB(ctx->opcode)]);
4806#endif
4807}
4808
4809static void gen_slbmfev(DisasContext *ctx)
4810{
4811#if defined(CONFIG_USER_ONLY)
4812 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4813#else
c47493f2 4814 if (unlikely(ctx->pr)) {
efdef95f
DG
4815 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4816 return;
4817 }
c6c7cf05 4818 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4819 cpu_gpr[rB(ctx->opcode)]);
4820#endif
4821}
12de9a39
JM
4822#endif /* defined(TARGET_PPC64) */
4823
79aceca5 4824/*** Lookaside buffer management ***/
c47493f2 4825/* Optional & supervisor only: */
99e300ef 4826
54623277 4827/* tlbia */
99e300ef 4828static void gen_tlbia(DisasContext *ctx)
79aceca5 4829{
9a64fbe4 4830#if defined(CONFIG_USER_ONLY)
e06fcd75 4831 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4832#else
c47493f2 4833 if (unlikely(ctx->pr)) {
e06fcd75 4834 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4835 return;
9a64fbe4 4836 }
c6c7cf05 4837 gen_helper_tlbia(cpu_env);
9a64fbe4 4838#endif
79aceca5
FB
4839}
4840
bf14b1ce 4841/* tlbiel */
99e300ef 4842static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4843{
4844#if defined(CONFIG_USER_ONLY)
4845 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4846#else
c47493f2 4847 if (unlikely(ctx->pr)) {
bf14b1ce
BS
4848 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4849 return;
4850 }
c6c7cf05 4851 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4852#endif
4853}
4854
79aceca5 4855/* tlbie */
99e300ef 4856static void gen_tlbie(DisasContext *ctx)
79aceca5 4857{
9a64fbe4 4858#if defined(CONFIG_USER_ONLY)
e06fcd75 4859 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4860#else
c47493f2 4861 if (unlikely(ctx->pr)) {
e06fcd75 4862 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4863 return;
9a64fbe4 4864 }
9ca3f7f3 4865 if (NARROW_MODE(ctx)) {
74d37793
AJ
4866 TCGv t0 = tcg_temp_new();
4867 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4868 gen_helper_tlbie(cpu_env, t0);
74d37793 4869 tcg_temp_free(t0);
9ca3f7f3 4870 } else {
c6c7cf05 4871 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4872 }
9a64fbe4 4873#endif
79aceca5
FB
4874}
4875
4876/* tlbsync */
99e300ef 4877static void gen_tlbsync(DisasContext *ctx)
79aceca5 4878{
9a64fbe4 4879#if defined(CONFIG_USER_ONLY)
e06fcd75 4880 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4881#else
c47493f2 4882 if (unlikely(ctx->pr)) {
e06fcd75 4883 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4884 return;
9a64fbe4 4885 }
cd0c6f47
BH
4886 /* tlbsync is a nop for server, ptesync handles delayed tlb flush,
4887 * embedded however needs to deal with tlbsync. We don't try to be
4888 * fancy and swallow the overhead of checking for both.
9a64fbe4 4889 */
cd0c6f47 4890 gen_check_tlb_flush(ctx);
9a64fbe4 4891#endif
79aceca5
FB
4892}
4893
426613db
JM
4894#if defined(TARGET_PPC64)
4895/* slbia */
99e300ef 4896static void gen_slbia(DisasContext *ctx)
426613db
JM
4897{
4898#if defined(CONFIG_USER_ONLY)
e06fcd75 4899 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4900#else
c47493f2 4901 if (unlikely(ctx->pr)) {
e06fcd75 4902 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4903 return;
4904 }
c6c7cf05 4905 gen_helper_slbia(cpu_env);
426613db
JM
4906#endif
4907}
4908
4909/* slbie */
99e300ef 4910static void gen_slbie(DisasContext *ctx)
426613db
JM
4911{
4912#if defined(CONFIG_USER_ONLY)
e06fcd75 4913 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4914#else
c47493f2 4915 if (unlikely(ctx->pr)) {
e06fcd75 4916 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4917 return;
4918 }
c6c7cf05 4919 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4920#endif
4921}
4922#endif
4923
79aceca5
FB
4924/*** External control ***/
4925/* Optional: */
99e300ef 4926
54623277 4927/* eciwx */
99e300ef 4928static void gen_eciwx(DisasContext *ctx)
79aceca5 4929{
76db3ba4 4930 TCGv t0;
fa407c03 4931 /* Should check EAR[E] ! */
76db3ba4
AJ
4932 gen_set_access_type(ctx, ACCESS_EXT);
4933 t0 = tcg_temp_new();
4934 gen_addr_reg_index(ctx, t0);
fa407c03 4935 gen_check_align(ctx, t0, 0x03);
76db3ba4 4936 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4937 tcg_temp_free(t0);
76a66253
JM
4938}
4939
4940/* ecowx */
99e300ef 4941static void gen_ecowx(DisasContext *ctx)
76a66253 4942{
76db3ba4 4943 TCGv t0;
fa407c03 4944 /* Should check EAR[E] ! */
76db3ba4
AJ
4945 gen_set_access_type(ctx, ACCESS_EXT);
4946 t0 = tcg_temp_new();
4947 gen_addr_reg_index(ctx, t0);
fa407c03 4948 gen_check_align(ctx, t0, 0x03);
76db3ba4 4949 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4950 tcg_temp_free(t0);
76a66253
JM
4951}
4952
4953/* PowerPC 601 specific instructions */
99e300ef 4954
54623277 4955/* abs - abs. */
99e300ef 4956static void gen_abs(DisasContext *ctx)
76a66253 4957{
42a268c2
RH
4958 TCGLabel *l1 = gen_new_label();
4959 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
4960 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4961 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4962 tcg_gen_br(l2);
4963 gen_set_label(l1);
4964 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4965 gen_set_label(l2);
76a66253 4966 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4967 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4968}
4969
4970/* abso - abso. */
99e300ef 4971static void gen_abso(DisasContext *ctx)
76a66253 4972{
42a268c2
RH
4973 TCGLabel *l1 = gen_new_label();
4974 TCGLabel *l2 = gen_new_label();
4975 TCGLabel *l3 = gen_new_label();
22e0e173 4976 /* Start with XER OV disabled, the most likely case */
da91a00f 4977 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4978 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4979 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4980 tcg_gen_movi_tl(cpu_ov, 1);
4981 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4982 tcg_gen_br(l2);
4983 gen_set_label(l1);
4984 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4985 tcg_gen_br(l3);
4986 gen_set_label(l2);
4987 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4988 gen_set_label(l3);
76a66253 4989 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4990 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4991}
4992
4993/* clcs */
99e300ef 4994static void gen_clcs(DisasContext *ctx)
76a66253 4995{
22e0e173 4996 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4997 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4998 tcg_temp_free_i32(t0);
c7697e1f 4999 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
5000}
5001
5002/* div - div. */
99e300ef 5003static void gen_div(DisasContext *ctx)
76a66253 5004{
d15f74fb
BS
5005 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5006 cpu_gpr[rB(ctx->opcode)]);
76a66253 5007 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5008 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5009}
5010
5011/* divo - divo. */
99e300ef 5012static void gen_divo(DisasContext *ctx)
76a66253 5013{
d15f74fb
BS
5014 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5015 cpu_gpr[rB(ctx->opcode)]);
76a66253 5016 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5017 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5018}
5019
5020/* divs - divs. */
99e300ef 5021static void gen_divs(DisasContext *ctx)
76a66253 5022{
d15f74fb
BS
5023 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5024 cpu_gpr[rB(ctx->opcode)]);
76a66253 5025 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5026 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5027}
5028
5029/* divso - divso. */
99e300ef 5030static void gen_divso(DisasContext *ctx)
76a66253 5031{
d15f74fb
BS
5032 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
5033 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 5034 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5035 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5036}
5037
5038/* doz - doz. */
99e300ef 5039static void gen_doz(DisasContext *ctx)
76a66253 5040{
42a268c2
RH
5041 TCGLabel *l1 = gen_new_label();
5042 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5043 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
5044 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5045 tcg_gen_br(l2);
5046 gen_set_label(l1);
5047 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5048 gen_set_label(l2);
76a66253 5049 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5050 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5051}
5052
5053/* dozo - dozo. */
99e300ef 5054static void gen_dozo(DisasContext *ctx)
76a66253 5055{
42a268c2
RH
5056 TCGLabel *l1 = gen_new_label();
5057 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5058 TCGv t0 = tcg_temp_new();
5059 TCGv t1 = tcg_temp_new();
5060 TCGv t2 = tcg_temp_new();
5061 /* Start with XER OV disabled, the most likely case */
da91a00f 5062 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5063 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
5064 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5065 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5066 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
5067 tcg_gen_andc_tl(t1, t1, t2);
5068 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
5069 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
5070 tcg_gen_movi_tl(cpu_ov, 1);
5071 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5072 tcg_gen_br(l2);
5073 gen_set_label(l1);
5074 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5075 gen_set_label(l2);
5076 tcg_temp_free(t0);
5077 tcg_temp_free(t1);
5078 tcg_temp_free(t2);
76a66253 5079 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5080 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5081}
5082
5083/* dozi */
99e300ef 5084static void gen_dozi(DisasContext *ctx)
76a66253 5085{
22e0e173 5086 target_long simm = SIMM(ctx->opcode);
42a268c2
RH
5087 TCGLabel *l1 = gen_new_label();
5088 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5089 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5090 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5091 tcg_gen_br(l2);
5092 gen_set_label(l1);
5093 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5094 gen_set_label(l2);
5095 if (unlikely(Rc(ctx->opcode) != 0))
5096 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5097}
5098
76a66253 5099/* lscbx - lscbx. */
99e300ef 5100static void gen_lscbx(DisasContext *ctx)
76a66253 5101{
bdb4b689
AJ
5102 TCGv t0 = tcg_temp_new();
5103 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5104 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5105 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 5106
76db3ba4 5107 gen_addr_reg_index(ctx, t0);
76a66253 5108 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 5109 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 5110 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
5111 tcg_temp_free_i32(t1);
5112 tcg_temp_free_i32(t2);
5113 tcg_temp_free_i32(t3);
3d7b417e 5114 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 5115 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 5116 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
5117 gen_set_Rc0(ctx, t0);
5118 tcg_temp_free(t0);
76a66253
JM
5119}
5120
5121/* maskg - maskg. */
99e300ef 5122static void gen_maskg(DisasContext *ctx)
76a66253 5123{
42a268c2 5124 TCGLabel *l1 = gen_new_label();
22e0e173
AJ
5125 TCGv t0 = tcg_temp_new();
5126 TCGv t1 = tcg_temp_new();
5127 TCGv t2 = tcg_temp_new();
5128 TCGv t3 = tcg_temp_new();
5129 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5130 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5131 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5132 tcg_gen_addi_tl(t2, t0, 1);
5133 tcg_gen_shr_tl(t2, t3, t2);
5134 tcg_gen_shr_tl(t3, t3, t1);
5135 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5136 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5137 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5138 gen_set_label(l1);
5139 tcg_temp_free(t0);
5140 tcg_temp_free(t1);
5141 tcg_temp_free(t2);
5142 tcg_temp_free(t3);
76a66253 5143 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5144 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5145}
5146
5147/* maskir - maskir. */
99e300ef 5148static void gen_maskir(DisasContext *ctx)
76a66253 5149{
22e0e173
AJ
5150 TCGv t0 = tcg_temp_new();
5151 TCGv t1 = tcg_temp_new();
5152 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5153 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5154 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5155 tcg_temp_free(t0);
5156 tcg_temp_free(t1);
76a66253 5157 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5158 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5159}
5160
5161/* mul - mul. */
99e300ef 5162static void gen_mul(DisasContext *ctx)
76a66253 5163{
22e0e173
AJ
5164 TCGv_i64 t0 = tcg_temp_new_i64();
5165 TCGv_i64 t1 = tcg_temp_new_i64();
5166 TCGv t2 = tcg_temp_new();
5167 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5168 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5169 tcg_gen_mul_i64(t0, t0, t1);
5170 tcg_gen_trunc_i64_tl(t2, t0);
5171 gen_store_spr(SPR_MQ, t2);
5172 tcg_gen_shri_i64(t1, t0, 32);
5173 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5174 tcg_temp_free_i64(t0);
5175 tcg_temp_free_i64(t1);
5176 tcg_temp_free(t2);
76a66253 5177 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5178 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5179}
5180
5181/* mulo - mulo. */
99e300ef 5182static void gen_mulo(DisasContext *ctx)
76a66253 5183{
42a268c2 5184 TCGLabel *l1 = gen_new_label();
22e0e173
AJ
5185 TCGv_i64 t0 = tcg_temp_new_i64();
5186 TCGv_i64 t1 = tcg_temp_new_i64();
5187 TCGv t2 = tcg_temp_new();
5188 /* Start with XER OV disabled, the most likely case */
da91a00f 5189 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5190 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5191 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5192 tcg_gen_mul_i64(t0, t0, t1);
5193 tcg_gen_trunc_i64_tl(t2, t0);
5194 gen_store_spr(SPR_MQ, t2);
5195 tcg_gen_shri_i64(t1, t0, 32);
5196 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5197 tcg_gen_ext32s_i64(t1, t0);
5198 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
5199 tcg_gen_movi_tl(cpu_ov, 1);
5200 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5201 gen_set_label(l1);
5202 tcg_temp_free_i64(t0);
5203 tcg_temp_free_i64(t1);
5204 tcg_temp_free(t2);
76a66253 5205 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5206 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5207}
5208
5209/* nabs - nabs. */
99e300ef 5210static void gen_nabs(DisasContext *ctx)
76a66253 5211{
42a268c2
RH
5212 TCGLabel *l1 = gen_new_label();
5213 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5214 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5215 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5216 tcg_gen_br(l2);
5217 gen_set_label(l1);
5218 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5219 gen_set_label(l2);
76a66253 5220 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5221 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5222}
5223
5224/* nabso - nabso. */
99e300ef 5225static void gen_nabso(DisasContext *ctx)
76a66253 5226{
42a268c2
RH
5227 TCGLabel *l1 = gen_new_label();
5228 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5229 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5230 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5231 tcg_gen_br(l2);
5232 gen_set_label(l1);
5233 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5234 gen_set_label(l2);
5235 /* nabs never overflows */
da91a00f 5236 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 5237 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5238 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5239}
5240
5241/* rlmi - rlmi. */
99e300ef 5242static void gen_rlmi(DisasContext *ctx)
76a66253 5243{
7487953d
AJ
5244 uint32_t mb = MB(ctx->opcode);
5245 uint32_t me = ME(ctx->opcode);
5246 TCGv t0 = tcg_temp_new();
5247 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5248 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5249 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5250 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5251 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5252 tcg_temp_free(t0);
76a66253 5253 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5254 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5255}
5256
5257/* rrib - rrib. */
99e300ef 5258static void gen_rrib(DisasContext *ctx)
76a66253 5259{
7487953d
AJ
5260 TCGv t0 = tcg_temp_new();
5261 TCGv t1 = tcg_temp_new();
5262 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5263 tcg_gen_movi_tl(t1, 0x80000000);
5264 tcg_gen_shr_tl(t1, t1, t0);
5265 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5266 tcg_gen_and_tl(t0, t0, t1);
5267 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5268 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5269 tcg_temp_free(t0);
5270 tcg_temp_free(t1);
76a66253 5271 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5272 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5273}
5274
5275/* sle - sle. */
99e300ef 5276static void gen_sle(DisasContext *ctx)
76a66253 5277{
7487953d
AJ
5278 TCGv t0 = tcg_temp_new();
5279 TCGv t1 = tcg_temp_new();
5280 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5281 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5282 tcg_gen_subfi_tl(t1, 32, t1);
5283 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5284 tcg_gen_or_tl(t1, t0, t1);
5285 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5286 gen_store_spr(SPR_MQ, t1);
5287 tcg_temp_free(t0);
5288 tcg_temp_free(t1);
76a66253 5289 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5290 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5291}
5292
5293/* sleq - sleq. */
99e300ef 5294static void gen_sleq(DisasContext *ctx)
76a66253 5295{
7487953d
AJ
5296 TCGv t0 = tcg_temp_new();
5297 TCGv t1 = tcg_temp_new();
5298 TCGv t2 = tcg_temp_new();
5299 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5300 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5301 tcg_gen_shl_tl(t2, t2, t0);
5302 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5303 gen_load_spr(t1, SPR_MQ);
5304 gen_store_spr(SPR_MQ, t0);
5305 tcg_gen_and_tl(t0, t0, t2);
5306 tcg_gen_andc_tl(t1, t1, t2);
5307 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5308 tcg_temp_free(t0);
5309 tcg_temp_free(t1);
5310 tcg_temp_free(t2);
76a66253 5311 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5312 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5313}
5314
5315/* sliq - sliq. */
99e300ef 5316static void gen_sliq(DisasContext *ctx)
76a66253 5317{
7487953d
AJ
5318 int sh = SH(ctx->opcode);
5319 TCGv t0 = tcg_temp_new();
5320 TCGv t1 = tcg_temp_new();
5321 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5322 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5323 tcg_gen_or_tl(t1, t0, t1);
5324 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5325 gen_store_spr(SPR_MQ, t1);
5326 tcg_temp_free(t0);
5327 tcg_temp_free(t1);
76a66253 5328 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5329 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5330}
5331
5332/* slliq - slliq. */
99e300ef 5333static void gen_slliq(DisasContext *ctx)
76a66253 5334{
7487953d
AJ
5335 int sh = SH(ctx->opcode);
5336 TCGv t0 = tcg_temp_new();
5337 TCGv t1 = tcg_temp_new();
5338 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5339 gen_load_spr(t1, SPR_MQ);
5340 gen_store_spr(SPR_MQ, t0);
5341 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5342 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5343 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5344 tcg_temp_free(t0);
5345 tcg_temp_free(t1);
76a66253 5346 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5347 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5348}
5349
5350/* sllq - sllq. */
99e300ef 5351static void gen_sllq(DisasContext *ctx)
76a66253 5352{
42a268c2
RH
5353 TCGLabel *l1 = gen_new_label();
5354 TCGLabel *l2 = gen_new_label();
7487953d
AJ
5355 TCGv t0 = tcg_temp_local_new();
5356 TCGv t1 = tcg_temp_local_new();
5357 TCGv t2 = tcg_temp_local_new();
5358 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5359 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5360 tcg_gen_shl_tl(t1, t1, t2);
5361 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5362 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5363 gen_load_spr(t0, SPR_MQ);
5364 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5365 tcg_gen_br(l2);
5366 gen_set_label(l1);
5367 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5368 gen_load_spr(t2, SPR_MQ);
5369 tcg_gen_andc_tl(t1, t2, t1);
5370 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5371 gen_set_label(l2);
5372 tcg_temp_free(t0);
5373 tcg_temp_free(t1);
5374 tcg_temp_free(t2);
76a66253 5375 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5376 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5377}
5378
5379/* slq - slq. */
99e300ef 5380static void gen_slq(DisasContext *ctx)
76a66253 5381{
42a268c2 5382 TCGLabel *l1 = gen_new_label();
7487953d
AJ
5383 TCGv t0 = tcg_temp_new();
5384 TCGv t1 = tcg_temp_new();
5385 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5386 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5387 tcg_gen_subfi_tl(t1, 32, t1);
5388 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5389 tcg_gen_or_tl(t1, t0, t1);
5390 gen_store_spr(SPR_MQ, t1);
5391 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5392 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5393 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5394 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5395 gen_set_label(l1);
5396 tcg_temp_free(t0);
5397 tcg_temp_free(t1);
76a66253 5398 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5399 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5400}
5401
d9bce9d9 5402/* sraiq - sraiq. */
99e300ef 5403static void gen_sraiq(DisasContext *ctx)
76a66253 5404{
7487953d 5405 int sh = SH(ctx->opcode);
42a268c2 5406 TCGLabel *l1 = gen_new_label();
7487953d
AJ
5407 TCGv t0 = tcg_temp_new();
5408 TCGv t1 = tcg_temp_new();
5409 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5410 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5411 tcg_gen_or_tl(t0, t0, t1);
5412 gen_store_spr(SPR_MQ, t0);
da91a00f 5413 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5414 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5415 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5416 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5417 gen_set_label(l1);
5418 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5419 tcg_temp_free(t0);
5420 tcg_temp_free(t1);
76a66253 5421 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5422 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5423}
5424
5425/* sraq - sraq. */
99e300ef 5426static void gen_sraq(DisasContext *ctx)
76a66253 5427{
42a268c2
RH
5428 TCGLabel *l1 = gen_new_label();
5429 TCGLabel *l2 = gen_new_label();
7487953d
AJ
5430 TCGv t0 = tcg_temp_new();
5431 TCGv t1 = tcg_temp_local_new();
5432 TCGv t2 = tcg_temp_local_new();
5433 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5434 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5435 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5436 tcg_gen_subfi_tl(t2, 32, t2);
5437 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5438 tcg_gen_or_tl(t0, t0, t2);
5439 gen_store_spr(SPR_MQ, t0);
5440 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5441 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5442 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5443 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5444 gen_set_label(l1);
5445 tcg_temp_free(t0);
5446 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5447 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5448 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5449 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5450 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5451 gen_set_label(l2);
5452 tcg_temp_free(t1);
5453 tcg_temp_free(t2);
76a66253 5454 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5455 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5456}
5457
5458/* sre - sre. */
99e300ef 5459static void gen_sre(DisasContext *ctx)
76a66253 5460{
7487953d
AJ
5461 TCGv t0 = tcg_temp_new();
5462 TCGv t1 = tcg_temp_new();
5463 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5464 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5465 tcg_gen_subfi_tl(t1, 32, t1);
5466 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5467 tcg_gen_or_tl(t1, t0, t1);
5468 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5469 gen_store_spr(SPR_MQ, t1);
5470 tcg_temp_free(t0);
5471 tcg_temp_free(t1);
76a66253 5472 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5473 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5474}
5475
5476/* srea - srea. */
99e300ef 5477static void gen_srea(DisasContext *ctx)
76a66253 5478{
7487953d
AJ
5479 TCGv t0 = tcg_temp_new();
5480 TCGv t1 = tcg_temp_new();
5481 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5482 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5483 gen_store_spr(SPR_MQ, t0);
5484 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5485 tcg_temp_free(t0);
5486 tcg_temp_free(t1);
76a66253 5487 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5488 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5489}
5490
5491/* sreq */
99e300ef 5492static void gen_sreq(DisasContext *ctx)
76a66253 5493{
7487953d
AJ
5494 TCGv t0 = tcg_temp_new();
5495 TCGv t1 = tcg_temp_new();
5496 TCGv t2 = tcg_temp_new();
5497 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5498 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5499 tcg_gen_shr_tl(t1, t1, t0);
5500 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5501 gen_load_spr(t2, SPR_MQ);
5502 gen_store_spr(SPR_MQ, t0);
5503 tcg_gen_and_tl(t0, t0, t1);
5504 tcg_gen_andc_tl(t2, t2, t1);
5505 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5506 tcg_temp_free(t0);
5507 tcg_temp_free(t1);
5508 tcg_temp_free(t2);
76a66253 5509 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5510 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5511}
5512
5513/* sriq */
99e300ef 5514static void gen_sriq(DisasContext *ctx)
76a66253 5515{
7487953d
AJ
5516 int sh = SH(ctx->opcode);
5517 TCGv t0 = tcg_temp_new();
5518 TCGv t1 = tcg_temp_new();
5519 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5520 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5521 tcg_gen_or_tl(t1, t0, t1);
5522 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5523 gen_store_spr(SPR_MQ, t1);
5524 tcg_temp_free(t0);
5525 tcg_temp_free(t1);
76a66253 5526 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5527 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5528}
5529
5530/* srliq */
99e300ef 5531static void gen_srliq(DisasContext *ctx)
76a66253 5532{
7487953d
AJ
5533 int sh = SH(ctx->opcode);
5534 TCGv t0 = tcg_temp_new();
5535 TCGv t1 = tcg_temp_new();
5536 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5537 gen_load_spr(t1, SPR_MQ);
5538 gen_store_spr(SPR_MQ, t0);
5539 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5540 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5541 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5542 tcg_temp_free(t0);
5543 tcg_temp_free(t1);
76a66253 5544 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5545 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5546}
5547
5548/* srlq */
99e300ef 5549static void gen_srlq(DisasContext *ctx)
76a66253 5550{
42a268c2
RH
5551 TCGLabel *l1 = gen_new_label();
5552 TCGLabel *l2 = gen_new_label();
7487953d
AJ
5553 TCGv t0 = tcg_temp_local_new();
5554 TCGv t1 = tcg_temp_local_new();
5555 TCGv t2 = tcg_temp_local_new();
5556 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5557 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5558 tcg_gen_shr_tl(t2, t1, t2);
5559 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5560 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5561 gen_load_spr(t0, SPR_MQ);
5562 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5563 tcg_gen_br(l2);
5564 gen_set_label(l1);
5565 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5566 tcg_gen_and_tl(t0, t0, t2);
5567 gen_load_spr(t1, SPR_MQ);
5568 tcg_gen_andc_tl(t1, t1, t2);
5569 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5570 gen_set_label(l2);
5571 tcg_temp_free(t0);
5572 tcg_temp_free(t1);
5573 tcg_temp_free(t2);
76a66253 5574 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5575 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5576}
5577
5578/* srq */
99e300ef 5579static void gen_srq(DisasContext *ctx)
76a66253 5580{
42a268c2 5581 TCGLabel *l1 = gen_new_label();
7487953d
AJ
5582 TCGv t0 = tcg_temp_new();
5583 TCGv t1 = tcg_temp_new();
5584 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5585 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5586 tcg_gen_subfi_tl(t1, 32, t1);
5587 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5588 tcg_gen_or_tl(t1, t0, t1);
5589 gen_store_spr(SPR_MQ, t1);
5590 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5591 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5592 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5593 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5594 gen_set_label(l1);
5595 tcg_temp_free(t0);
5596 tcg_temp_free(t1);
76a66253 5597 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5598 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5599}
5600
5601/* PowerPC 602 specific instructions */
99e300ef 5602
54623277 5603/* dsa */
99e300ef 5604static void gen_dsa(DisasContext *ctx)
76a66253
JM
5605{
5606 /* XXX: TODO */
e06fcd75 5607 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5608}
5609
5610/* esa */
99e300ef 5611static void gen_esa(DisasContext *ctx)
76a66253
JM
5612{
5613 /* XXX: TODO */
e06fcd75 5614 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5615}
5616
5617/* mfrom */
99e300ef 5618static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5619{
5620#if defined(CONFIG_USER_ONLY)
e06fcd75 5621 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5622#else
c47493f2 5623 if (unlikely(ctx->pr)) {
e06fcd75 5624 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5625 return;
5626 }
cf02a65c 5627 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5628#endif
5629}
5630
5631/* 602 - 603 - G2 TLB management */
e8eaa2c0 5632
54623277 5633/* tlbld */
e8eaa2c0 5634static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5635{
5636#if defined(CONFIG_USER_ONLY)
e06fcd75 5637 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5638#else
c47493f2 5639 if (unlikely(ctx->pr)) {
e06fcd75 5640 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5641 return;
5642 }
c6c7cf05 5643 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5644#endif
5645}
5646
5647/* tlbli */
e8eaa2c0 5648static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5649{
5650#if defined(CONFIG_USER_ONLY)
e06fcd75 5651 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5652#else
c47493f2 5653 if (unlikely(ctx->pr)) {
e06fcd75 5654 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5655 return;
5656 }
c6c7cf05 5657 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5658#endif
5659}
5660
7dbe11ac 5661/* 74xx TLB management */
e8eaa2c0 5662
54623277 5663/* tlbld */
e8eaa2c0 5664static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5665{
5666#if defined(CONFIG_USER_ONLY)
e06fcd75 5667 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5668#else
c47493f2 5669 if (unlikely(ctx->pr)) {
e06fcd75 5670 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5671 return;
5672 }
c6c7cf05 5673 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5674#endif
5675}
5676
5677/* tlbli */
e8eaa2c0 5678static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5679{
5680#if defined(CONFIG_USER_ONLY)
e06fcd75 5681 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5682#else
c47493f2 5683 if (unlikely(ctx->pr)) {
e06fcd75 5684 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5685 return;
5686 }
c6c7cf05 5687 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5688#endif
5689}
5690
76a66253 5691/* POWER instructions not in PowerPC 601 */
99e300ef 5692
54623277 5693/* clf */
99e300ef 5694static void gen_clf(DisasContext *ctx)
76a66253
JM
5695{
5696 /* Cache line flush: implemented as no-op */
5697}
5698
5699/* cli */
99e300ef 5700static void gen_cli(DisasContext *ctx)
76a66253 5701{
7f75ffd3 5702 /* Cache line invalidate: privileged and treated as no-op */
76a66253 5703#if defined(CONFIG_USER_ONLY)
e06fcd75 5704 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5705#else
c47493f2 5706 if (unlikely(ctx->pr)) {
e06fcd75 5707 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5708 return;
5709 }
5710#endif
5711}
5712
5713/* dclst */
99e300ef 5714static void gen_dclst(DisasContext *ctx)
76a66253
JM
5715{
5716 /* Data cache line store: treated as no-op */
5717}
5718
99e300ef 5719static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5720{
5721#if defined(CONFIG_USER_ONLY)
e06fcd75 5722 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5723#else
74d37793
AJ
5724 int ra = rA(ctx->opcode);
5725 int rd = rD(ctx->opcode);
5726 TCGv t0;
c47493f2 5727 if (unlikely(ctx->pr)) {
e06fcd75 5728 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5729 return;
5730 }
74d37793 5731 t0 = tcg_temp_new();
76db3ba4 5732 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5733 tcg_gen_shri_tl(t0, t0, 28);
5734 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5735 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5736 tcg_temp_free(t0);
76a66253 5737 if (ra != 0 && ra != rd)
74d37793 5738 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5739#endif
5740}
5741
99e300ef 5742static void gen_rac(DisasContext *ctx)
76a66253
JM
5743{
5744#if defined(CONFIG_USER_ONLY)
e06fcd75 5745 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5746#else
22e0e173 5747 TCGv t0;
c47493f2 5748 if (unlikely(ctx->pr)) {
e06fcd75 5749 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5750 return;
5751 }
22e0e173 5752 t0 = tcg_temp_new();
76db3ba4 5753 gen_addr_reg_index(ctx, t0);
c6c7cf05 5754 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5755 tcg_temp_free(t0);
76a66253
JM
5756#endif
5757}
5758
99e300ef 5759static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5760{
5761#if defined(CONFIG_USER_ONLY)
e06fcd75 5762 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5763#else
c47493f2 5764 if (unlikely(ctx->pr)) {
e06fcd75 5765 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5766 return;
5767 }
e5f17ac6 5768 gen_helper_rfsvc(cpu_env);
e06fcd75 5769 gen_sync_exception(ctx);
76a66253
JM
5770#endif
5771}
5772
5773/* svc is not implemented for now */
5774
5775/* POWER2 specific instructions */
5776/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5777
5778/* lfq */
99e300ef 5779static void gen_lfq(DisasContext *ctx)
76a66253 5780{
01a4afeb 5781 int rd = rD(ctx->opcode);
76db3ba4
AJ
5782 TCGv t0;
5783 gen_set_access_type(ctx, ACCESS_FLOAT);
5784 t0 = tcg_temp_new();
5785 gen_addr_imm_index(ctx, t0, 0);
5786 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5787 gen_addr_add(ctx, t0, t0, 8);
5788 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5789 tcg_temp_free(t0);
76a66253
JM
5790}
5791
5792/* lfqu */
99e300ef 5793static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5794{
5795 int ra = rA(ctx->opcode);
01a4afeb 5796 int rd = rD(ctx->opcode);
76db3ba4
AJ
5797 TCGv t0, t1;
5798 gen_set_access_type(ctx, ACCESS_FLOAT);
5799 t0 = tcg_temp_new();
5800 t1 = tcg_temp_new();
5801 gen_addr_imm_index(ctx, t0, 0);
5802 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5803 gen_addr_add(ctx, t1, t0, 8);
5804 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5805 if (ra != 0)
01a4afeb
AJ
5806 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5807 tcg_temp_free(t0);
5808 tcg_temp_free(t1);
76a66253
JM
5809}
5810
5811/* lfqux */
99e300ef 5812static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5813{
5814 int ra = rA(ctx->opcode);
01a4afeb 5815 int rd = rD(ctx->opcode);
76db3ba4
AJ
5816 gen_set_access_type(ctx, ACCESS_FLOAT);
5817 TCGv t0, t1;
5818 t0 = tcg_temp_new();
5819 gen_addr_reg_index(ctx, t0);
5820 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5821 t1 = tcg_temp_new();
5822 gen_addr_add(ctx, t1, t0, 8);
5823 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5824 tcg_temp_free(t1);
76a66253 5825 if (ra != 0)
01a4afeb
AJ
5826 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5827 tcg_temp_free(t0);
76a66253
JM
5828}
5829
5830/* lfqx */
99e300ef 5831static void gen_lfqx(DisasContext *ctx)
76a66253 5832{
01a4afeb 5833 int rd = rD(ctx->opcode);
76db3ba4
AJ
5834 TCGv t0;
5835 gen_set_access_type(ctx, ACCESS_FLOAT);
5836 t0 = tcg_temp_new();
5837 gen_addr_reg_index(ctx, t0);
5838 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5839 gen_addr_add(ctx, t0, t0, 8);
5840 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5841 tcg_temp_free(t0);
76a66253
JM
5842}
5843
5844/* stfq */
99e300ef 5845static void gen_stfq(DisasContext *ctx)
76a66253 5846{
01a4afeb 5847 int rd = rD(ctx->opcode);
76db3ba4
AJ
5848 TCGv t0;
5849 gen_set_access_type(ctx, ACCESS_FLOAT);
5850 t0 = tcg_temp_new();
5851 gen_addr_imm_index(ctx, t0, 0);
5852 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5853 gen_addr_add(ctx, t0, t0, 8);
5854 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5855 tcg_temp_free(t0);
76a66253
JM
5856}
5857
5858/* stfqu */
99e300ef 5859static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5860{
5861 int ra = rA(ctx->opcode);
01a4afeb 5862 int rd = rD(ctx->opcode);
76db3ba4
AJ
5863 TCGv t0, t1;
5864 gen_set_access_type(ctx, ACCESS_FLOAT);
5865 t0 = tcg_temp_new();
5866 gen_addr_imm_index(ctx, t0, 0);
5867 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5868 t1 = tcg_temp_new();
5869 gen_addr_add(ctx, t1, t0, 8);
5870 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5871 tcg_temp_free(t1);
76a66253 5872 if (ra != 0)
01a4afeb
AJ
5873 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5874 tcg_temp_free(t0);
76a66253
JM
5875}
5876
5877/* stfqux */
99e300ef 5878static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5879{
5880 int ra = rA(ctx->opcode);
01a4afeb 5881 int rd = rD(ctx->opcode);
76db3ba4
AJ
5882 TCGv t0, t1;
5883 gen_set_access_type(ctx, ACCESS_FLOAT);
5884 t0 = tcg_temp_new();
5885 gen_addr_reg_index(ctx, t0);
5886 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5887 t1 = tcg_temp_new();
5888 gen_addr_add(ctx, t1, t0, 8);
5889 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5890 tcg_temp_free(t1);
76a66253 5891 if (ra != 0)
01a4afeb
AJ
5892 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5893 tcg_temp_free(t0);
76a66253
JM
5894}
5895
5896/* stfqx */
99e300ef 5897static void gen_stfqx(DisasContext *ctx)
76a66253 5898{
01a4afeb 5899 int rd = rD(ctx->opcode);
76db3ba4
AJ
5900 TCGv t0;
5901 gen_set_access_type(ctx, ACCESS_FLOAT);
5902 t0 = tcg_temp_new();
5903 gen_addr_reg_index(ctx, t0);
5904 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5905 gen_addr_add(ctx, t0, t0, 8);
5906 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5907 tcg_temp_free(t0);
76a66253
JM
5908}
5909
5910/* BookE specific instructions */
99e300ef 5911
54623277 5912/* XXX: not implemented on 440 ? */
99e300ef 5913static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5914{
5915 /* XXX: TODO */
e06fcd75 5916 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5917}
5918
2662a059 5919/* XXX: not implemented on 440 ? */
99e300ef 5920static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5921{
5922#if defined(CONFIG_USER_ONLY)
e06fcd75 5923 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5924#else
74d37793 5925 TCGv t0;
c47493f2 5926 if (unlikely(ctx->pr)) {
e06fcd75 5927 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5928 return;
5929 }
ec72e276 5930 t0 = tcg_temp_new();
76db3ba4 5931 gen_addr_reg_index(ctx, t0);
4693364f 5932 gen_helper_tlbiva(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5933 tcg_temp_free(t0);
76a66253
JM
5934#endif
5935}
5936
5937/* All 405 MAC instructions are translated here */
636aa200
BS
5938static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5939 int ra, int rb, int rt, int Rc)
76a66253 5940{
182608d4
AJ
5941 TCGv t0, t1;
5942
a7812ae4
PB
5943 t0 = tcg_temp_local_new();
5944 t1 = tcg_temp_local_new();
182608d4 5945
76a66253
JM
5946 switch (opc3 & 0x0D) {
5947 case 0x05:
5948 /* macchw - macchw. - macchwo - macchwo. */
5949 /* macchws - macchws. - macchwso - macchwso. */
5950 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5951 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5952 /* mulchw - mulchw. */
182608d4
AJ
5953 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5954 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5955 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5956 break;
5957 case 0x04:
5958 /* macchwu - macchwu. - macchwuo - macchwuo. */
5959 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5960 /* mulchwu - mulchwu. */
182608d4
AJ
5961 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5962 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5963 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5964 break;
5965 case 0x01:
5966 /* machhw - machhw. - machhwo - machhwo. */
5967 /* machhws - machhws. - machhwso - machhwso. */
5968 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5969 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5970 /* mulhhw - mulhhw. */
182608d4
AJ
5971 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5972 tcg_gen_ext16s_tl(t0, t0);
5973 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5974 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5975 break;
5976 case 0x00:
5977 /* machhwu - machhwu. - machhwuo - machhwuo. */
5978 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5979 /* mulhhwu - mulhhwu. */
182608d4
AJ
5980 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5981 tcg_gen_ext16u_tl(t0, t0);
5982 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5983 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5984 break;
5985 case 0x0D:
5986 /* maclhw - maclhw. - maclhwo - maclhwo. */
5987 /* maclhws - maclhws. - maclhwso - maclhwso. */
5988 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5989 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5990 /* mullhw - mullhw. */
182608d4
AJ
5991 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5992 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5993 break;
5994 case 0x0C:
5995 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5996 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5997 /* mullhwu - mullhwu. */
182608d4
AJ
5998 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5999 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
6000 break;
6001 }
76a66253 6002 if (opc2 & 0x04) {
182608d4
AJ
6003 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
6004 tcg_gen_mul_tl(t1, t0, t1);
6005 if (opc2 & 0x02) {
6006 /* nmultiply-and-accumulate (0x0E) */
6007 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
6008 } else {
6009 /* multiply-and-accumulate (0x0C) */
6010 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
6011 }
6012
6013 if (opc3 & 0x12) {
6014 /* Check overflow and/or saturate */
42a268c2 6015 TCGLabel *l1 = gen_new_label();
182608d4
AJ
6016
6017 if (opc3 & 0x10) {
6018 /* Start with XER OV disabled, the most likely case */
da91a00f 6019 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
6020 }
6021 if (opc3 & 0x01) {
6022 /* Signed */
6023 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
6024 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
6025 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
6026 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 6027 if (opc3 & 0x02) {
182608d4
AJ
6028 /* Saturate */
6029 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
6030 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
6031 }
6032 } else {
6033 /* Unsigned */
6034 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 6035 if (opc3 & 0x02) {
182608d4
AJ
6036 /* Saturate */
6037 tcg_gen_movi_tl(t0, UINT32_MAX);
6038 }
6039 }
6040 if (opc3 & 0x10) {
6041 /* Check overflow */
da91a00f
RH
6042 tcg_gen_movi_tl(cpu_ov, 1);
6043 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
6044 }
6045 gen_set_label(l1);
6046 tcg_gen_mov_tl(cpu_gpr[rt], t0);
6047 }
6048 } else {
6049 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 6050 }
182608d4
AJ
6051 tcg_temp_free(t0);
6052 tcg_temp_free(t1);
76a66253
JM
6053 if (unlikely(Rc) != 0) {
6054 /* Update Rc0 */
182608d4 6055 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
6056 }
6057}
6058
a750fc0b 6059#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 6060static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
6061{ \
6062 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6063 rD(ctx->opcode), Rc(ctx->opcode)); \
6064}
6065
6066/* macchw - macchw. */
a750fc0b 6067GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 6068/* macchwo - macchwo. */
a750fc0b 6069GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 6070/* macchws - macchws. */
a750fc0b 6071GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 6072/* macchwso - macchwso. */
a750fc0b 6073GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 6074/* macchwsu - macchwsu. */
a750fc0b 6075GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 6076/* macchwsuo - macchwsuo. */
a750fc0b 6077GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 6078/* macchwu - macchwu. */
a750fc0b 6079GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 6080/* macchwuo - macchwuo. */
a750fc0b 6081GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 6082/* machhw - machhw. */
a750fc0b 6083GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 6084/* machhwo - machhwo. */
a750fc0b 6085GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 6086/* machhws - machhws. */
a750fc0b 6087GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 6088/* machhwso - machhwso. */
a750fc0b 6089GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 6090/* machhwsu - machhwsu. */
a750fc0b 6091GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 6092/* machhwsuo - machhwsuo. */
a750fc0b 6093GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 6094/* machhwu - machhwu. */
a750fc0b 6095GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 6096/* machhwuo - machhwuo. */
a750fc0b 6097GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 6098/* maclhw - maclhw. */
a750fc0b 6099GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 6100/* maclhwo - maclhwo. */
a750fc0b 6101GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 6102/* maclhws - maclhws. */
a750fc0b 6103GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 6104/* maclhwso - maclhwso. */
a750fc0b 6105GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 6106/* maclhwu - maclhwu. */
a750fc0b 6107GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 6108/* maclhwuo - maclhwuo. */
a750fc0b 6109GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 6110/* maclhwsu - maclhwsu. */
a750fc0b 6111GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 6112/* maclhwsuo - maclhwsuo. */
a750fc0b 6113GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 6114/* nmacchw - nmacchw. */
a750fc0b 6115GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 6116/* nmacchwo - nmacchwo. */
a750fc0b 6117GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 6118/* nmacchws - nmacchws. */
a750fc0b 6119GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 6120/* nmacchwso - nmacchwso. */
a750fc0b 6121GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 6122/* nmachhw - nmachhw. */
a750fc0b 6123GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 6124/* nmachhwo - nmachhwo. */
a750fc0b 6125GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 6126/* nmachhws - nmachhws. */
a750fc0b 6127GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 6128/* nmachhwso - nmachhwso. */
a750fc0b 6129GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 6130/* nmaclhw - nmaclhw. */
a750fc0b 6131GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 6132/* nmaclhwo - nmaclhwo. */
a750fc0b 6133GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 6134/* nmaclhws - nmaclhws. */
a750fc0b 6135GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 6136/* nmaclhwso - nmaclhwso. */
a750fc0b 6137GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
6138
6139/* mulchw - mulchw. */
a750fc0b 6140GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 6141/* mulchwu - mulchwu. */
a750fc0b 6142GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 6143/* mulhhw - mulhhw. */
a750fc0b 6144GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 6145/* mulhhwu - mulhhwu. */
a750fc0b 6146GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 6147/* mullhw - mullhw. */
a750fc0b 6148GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 6149/* mullhwu - mullhwu. */
a750fc0b 6150GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
6151
6152/* mfdcr */
99e300ef 6153static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
6154{
6155#if defined(CONFIG_USER_ONLY)
e06fcd75 6156 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6157#else
06dca6a7 6158 TCGv dcrn;
c47493f2 6159 if (unlikely(ctx->pr)) {
e06fcd75 6160 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6161 return;
6162 }
06dca6a7
AJ
6163 /* NIP cannot be restored if the memory exception comes from an helper */
6164 gen_update_nip(ctx, ctx->nip - 4);
6165 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6166 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 6167 tcg_temp_free(dcrn);
76a66253
JM
6168#endif
6169}
6170
6171/* mtdcr */
99e300ef 6172static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
6173{
6174#if defined(CONFIG_USER_ONLY)
e06fcd75 6175 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6176#else
06dca6a7 6177 TCGv dcrn;
c47493f2 6178 if (unlikely(ctx->pr)) {
e06fcd75 6179 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6180 return;
6181 }
06dca6a7
AJ
6182 /* NIP cannot be restored if the memory exception comes from an helper */
6183 gen_update_nip(ctx, ctx->nip - 4);
6184 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6185 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 6186 tcg_temp_free(dcrn);
a42bd6cc
JM
6187#endif
6188}
6189
6190/* mfdcrx */
2662a059 6191/* XXX: not implemented on 440 ? */
99e300ef 6192static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
6193{
6194#if defined(CONFIG_USER_ONLY)
e06fcd75 6195 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6196#else
c47493f2 6197 if (unlikely(ctx->pr)) {
e06fcd75 6198 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6199 return;
6200 }
06dca6a7
AJ
6201 /* NIP cannot be restored if the memory exception comes from an helper */
6202 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6203 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6204 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 6205 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
6206#endif
6207}
6208
6209/* mtdcrx */
2662a059 6210/* XXX: not implemented on 440 ? */
99e300ef 6211static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
6212{
6213#if defined(CONFIG_USER_ONLY)
e06fcd75 6214 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6215#else
c47493f2 6216 if (unlikely(ctx->pr)) {
e06fcd75 6217 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6218 return;
6219 }
06dca6a7
AJ
6220 /* NIP cannot be restored if the memory exception comes from an helper */
6221 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6222 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6223 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 6224 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
6225#endif
6226}
6227
a750fc0b 6228/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6229static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 6230{
06dca6a7
AJ
6231 /* NIP cannot be restored if the memory exception comes from an helper */
6232 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6233 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6234 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
6235 /* Note: Rc update flag set leads to undefined state of Rc0 */
6236}
6237
6238/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6239static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 6240{
06dca6a7
AJ
6241 /* NIP cannot be restored if the memory exception comes from an helper */
6242 gen_update_nip(ctx, ctx->nip - 4);
975e5463 6243 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 6244 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
6245 /* Note: Rc update flag set leads to undefined state of Rc0 */
6246}
6247
76a66253 6248/* dccci */
99e300ef 6249static void gen_dccci(DisasContext *ctx)
76a66253
JM
6250{
6251#if defined(CONFIG_USER_ONLY)
e06fcd75 6252 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6253#else
c47493f2 6254 if (unlikely(ctx->pr)) {
e06fcd75 6255 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6256 return;
6257 }
6258 /* interpreted as no-op */
6259#endif
6260}
6261
6262/* dcread */
99e300ef 6263static void gen_dcread(DisasContext *ctx)
76a66253
JM
6264{
6265#if defined(CONFIG_USER_ONLY)
e06fcd75 6266 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6267#else
b61f2753 6268 TCGv EA, val;
c47493f2 6269 if (unlikely(ctx->pr)) {
e06fcd75 6270 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6271 return;
6272 }
76db3ba4 6273 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 6274 EA = tcg_temp_new();
76db3ba4 6275 gen_addr_reg_index(ctx, EA);
a7812ae4 6276 val = tcg_temp_new();
76db3ba4 6277 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
6278 tcg_temp_free(val);
6279 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6280 tcg_temp_free(EA);
76a66253
JM
6281#endif
6282}
6283
6284/* icbt */
e8eaa2c0 6285static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6286{
6287 /* interpreted as no-op */
6288 /* XXX: specification say this is treated as a load by the MMU
6289 * but does not generate any exception
6290 */
6291}
6292
6293/* iccci */
99e300ef 6294static void gen_iccci(DisasContext *ctx)
76a66253
JM
6295{
6296#if defined(CONFIG_USER_ONLY)
e06fcd75 6297 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6298#else
c47493f2 6299 if (unlikely(ctx->pr)) {
e06fcd75 6300 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6301 return;
6302 }
6303 /* interpreted as no-op */
6304#endif
6305}
6306
6307/* icread */
99e300ef 6308static void gen_icread(DisasContext *ctx)
76a66253
JM
6309{
6310#if defined(CONFIG_USER_ONLY)
e06fcd75 6311 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6312#else
c47493f2 6313 if (unlikely(ctx->pr)) {
e06fcd75 6314 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6315 return;
6316 }
6317 /* interpreted as no-op */
6318#endif
6319}
6320
c47493f2 6321/* rfci (supervisor only) */
e8eaa2c0 6322static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
6323{
6324#if defined(CONFIG_USER_ONLY)
e06fcd75 6325 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6326#else
c47493f2 6327 if (unlikely(ctx->pr)) {
e06fcd75 6328 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6329 return;
6330 }
6331 /* Restore CPU state */
e5f17ac6 6332 gen_helper_40x_rfci(cpu_env);
e06fcd75 6333 gen_sync_exception(ctx);
a42bd6cc
JM
6334#endif
6335}
6336
99e300ef 6337static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6338{
6339#if defined(CONFIG_USER_ONLY)
e06fcd75 6340 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6341#else
c47493f2 6342 if (unlikely(ctx->pr)) {
e06fcd75 6343 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6344 return;
6345 }
6346 /* Restore CPU state */
e5f17ac6 6347 gen_helper_rfci(cpu_env);
e06fcd75 6348 gen_sync_exception(ctx);
a42bd6cc
JM
6349#endif
6350}
6351
6352/* BookE specific */
99e300ef 6353
54623277 6354/* XXX: not implemented on 440 ? */
99e300ef 6355static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6356{
6357#if defined(CONFIG_USER_ONLY)
e06fcd75 6358 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6359#else
c47493f2 6360 if (unlikely(ctx->pr)) {
e06fcd75 6361 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6362 return;
6363 }
6364 /* Restore CPU state */
e5f17ac6 6365 gen_helper_rfdi(cpu_env);
e06fcd75 6366 gen_sync_exception(ctx);
76a66253
JM
6367#endif
6368}
6369
2662a059 6370/* XXX: not implemented on 440 ? */
99e300ef 6371static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6372{
6373#if defined(CONFIG_USER_ONLY)
e06fcd75 6374 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6375#else
c47493f2 6376 if (unlikely(ctx->pr)) {
e06fcd75 6377 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6378 return;
6379 }
6380 /* Restore CPU state */
e5f17ac6 6381 gen_helper_rfmci(cpu_env);
e06fcd75 6382 gen_sync_exception(ctx);
a42bd6cc
JM
6383#endif
6384}
5eb7995e 6385
d9bce9d9 6386/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6387
54623277 6388/* tlbre */
e8eaa2c0 6389static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6390{
6391#if defined(CONFIG_USER_ONLY)
e06fcd75 6392 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6393#else
c47493f2 6394 if (unlikely(ctx->pr)) {
e06fcd75 6395 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6396 return;
6397 }
6398 switch (rB(ctx->opcode)) {
6399 case 0:
c6c7cf05
BS
6400 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6401 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6402 break;
6403 case 1:
c6c7cf05
BS
6404 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6405 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6406 break;
6407 default:
e06fcd75 6408 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6409 break;
9a64fbe4 6410 }
76a66253
JM
6411#endif
6412}
6413
d9bce9d9 6414/* tlbsx - tlbsx. */
e8eaa2c0 6415static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6416{
6417#if defined(CONFIG_USER_ONLY)
e06fcd75 6418 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6419#else
74d37793 6420 TCGv t0;
c47493f2 6421 if (unlikely(ctx->pr)) {
e06fcd75 6422 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6423 return;
6424 }
74d37793 6425 t0 = tcg_temp_new();
76db3ba4 6426 gen_addr_reg_index(ctx, t0);
c6c7cf05 6427 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6428 tcg_temp_free(t0);
6429 if (Rc(ctx->opcode)) {
42a268c2 6430 TCGLabel *l1 = gen_new_label();
da91a00f 6431 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6432 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6433 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6434 gen_set_label(l1);
6435 }
76a66253 6436#endif
79aceca5
FB
6437}
6438
76a66253 6439/* tlbwe */
e8eaa2c0 6440static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6441{
76a66253 6442#if defined(CONFIG_USER_ONLY)
e06fcd75 6443 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6444#else
c47493f2 6445 if (unlikely(ctx->pr)) {
e06fcd75 6446 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6447 return;
6448 }
6449 switch (rB(ctx->opcode)) {
6450 case 0:
c6c7cf05
BS
6451 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6452 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6453 break;
6454 case 1:
c6c7cf05
BS
6455 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6456 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6457 break;
6458 default:
e06fcd75 6459 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6460 break;
9a64fbe4 6461 }
76a66253
JM
6462#endif
6463}
6464
a4bb6c3e 6465/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6466
54623277 6467/* tlbre */
e8eaa2c0 6468static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6469{
6470#if defined(CONFIG_USER_ONLY)
e06fcd75 6471 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6472#else
c47493f2 6473 if (unlikely(ctx->pr)) {
e06fcd75 6474 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6475 return;
6476 }
6477 switch (rB(ctx->opcode)) {
6478 case 0:
5eb7995e 6479 case 1:
5eb7995e 6480 case 2:
74d37793
AJ
6481 {
6482 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6483 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6484 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6485 tcg_temp_free_i32(t0);
6486 }
5eb7995e
JM
6487 break;
6488 default:
e06fcd75 6489 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6490 break;
6491 }
6492#endif
6493}
6494
6495/* tlbsx - tlbsx. */
e8eaa2c0 6496static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6497{
6498#if defined(CONFIG_USER_ONLY)
e06fcd75 6499 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6500#else
74d37793 6501 TCGv t0;
c47493f2 6502 if (unlikely(ctx->pr)) {
e06fcd75 6503 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6504 return;
6505 }
74d37793 6506 t0 = tcg_temp_new();
76db3ba4 6507 gen_addr_reg_index(ctx, t0);
c6c7cf05 6508 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6509 tcg_temp_free(t0);
6510 if (Rc(ctx->opcode)) {
42a268c2 6511 TCGLabel *l1 = gen_new_label();
da91a00f 6512 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6513 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6514 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6515 gen_set_label(l1);
6516 }
5eb7995e
JM
6517#endif
6518}
6519
6520/* tlbwe */
e8eaa2c0 6521static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
6522{
6523#if defined(CONFIG_USER_ONLY)
e06fcd75 6524 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6525#else
c47493f2 6526 if (unlikely(ctx->pr)) {
e06fcd75 6527 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6528 return;
6529 }
6530 switch (rB(ctx->opcode)) {
6531 case 0:
5eb7995e 6532 case 1:
5eb7995e 6533 case 2:
74d37793
AJ
6534 {
6535 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6536 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6537 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
6538 tcg_temp_free_i32(t0);
6539 }
5eb7995e
JM
6540 break;
6541 default:
e06fcd75 6542 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6543 break;
6544 }
6545#endif
6546}
6547
01662f3e
AG
6548/* TLB management - PowerPC BookE 2.06 implementation */
6549
6550/* tlbre */
6551static void gen_tlbre_booke206(DisasContext *ctx)
6552{
6553#if defined(CONFIG_USER_ONLY)
6554 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6555#else
c47493f2 6556 if (unlikely(ctx->pr)) {
01662f3e
AG
6557 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6558 return;
6559 }
6560
c6c7cf05 6561 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6562#endif
6563}
6564
6565/* tlbsx - tlbsx. */
6566static void gen_tlbsx_booke206(DisasContext *ctx)
6567{
6568#if defined(CONFIG_USER_ONLY)
6569 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6570#else
6571 TCGv t0;
c47493f2 6572 if (unlikely(ctx->pr)) {
01662f3e
AG
6573 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6574 return;
6575 }
6576
6577 if (rA(ctx->opcode)) {
6578 t0 = tcg_temp_new();
6579 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6580 } else {
6581 t0 = tcg_const_tl(0);
6582 }
6583
6584 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6585 gen_helper_booke206_tlbsx(cpu_env, t0);
c80d1df5 6586 tcg_temp_free(t0);
01662f3e
AG
6587#endif
6588}
6589
6590/* tlbwe */
6591static void gen_tlbwe_booke206(DisasContext *ctx)
6592{
6593#if defined(CONFIG_USER_ONLY)
6594 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6595#else
c47493f2 6596 if (unlikely(ctx->pr)) {
01662f3e
AG
6597 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6598 return;
6599 }
3f162d11 6600 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6601 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6602#endif
6603}
6604
6605static void gen_tlbivax_booke206(DisasContext *ctx)
6606{
6607#if defined(CONFIG_USER_ONLY)
6608 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6609#else
6610 TCGv t0;
c47493f2 6611 if (unlikely(ctx->pr)) {
01662f3e
AG
6612 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6613 return;
6614 }
6615
6616 t0 = tcg_temp_new();
6617 gen_addr_reg_index(ctx, t0);
6618
c6c7cf05 6619 gen_helper_booke206_tlbivax(cpu_env, t0);
c80d1df5 6620 tcg_temp_free(t0);
01662f3e
AG
6621#endif
6622}
6623
6d3db821
AG
6624static void gen_tlbilx_booke206(DisasContext *ctx)
6625{
6626#if defined(CONFIG_USER_ONLY)
6627 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6628#else
6629 TCGv t0;
c47493f2 6630 if (unlikely(ctx->pr)) {
6d3db821
AG
6631 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6632 return;
6633 }
6634
6635 t0 = tcg_temp_new();
6636 gen_addr_reg_index(ctx, t0);
6637
6638 switch((ctx->opcode >> 21) & 0x3) {
6639 case 0:
c6c7cf05 6640 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6641 break;
6642 case 1:
c6c7cf05 6643 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6644 break;
6645 case 3:
c6c7cf05 6646 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6647 break;
6648 default:
6649 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6650 break;
6651 }
6652
6653 tcg_temp_free(t0);
6654#endif
6655}
6656
01662f3e 6657
76a66253 6658/* wrtee */
99e300ef 6659static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6660{
6661#if defined(CONFIG_USER_ONLY)
e06fcd75 6662 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6663#else
6527f6ea 6664 TCGv t0;
c47493f2 6665 if (unlikely(ctx->pr)) {
e06fcd75 6666 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6667 return;
6668 }
6527f6ea
AJ
6669 t0 = tcg_temp_new();
6670 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6671 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6672 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6673 tcg_temp_free(t0);
dee96f6c
JM
6674 /* Stop translation to have a chance to raise an exception
6675 * if we just set msr_ee to 1
6676 */
e06fcd75 6677 gen_stop_exception(ctx);
76a66253
JM
6678#endif
6679}
6680
6681/* wrteei */
99e300ef 6682static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6683{
6684#if defined(CONFIG_USER_ONLY)
e06fcd75 6685 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6686#else
c47493f2 6687 if (unlikely(ctx->pr)) {
e06fcd75 6688 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6689 return;
6690 }
fbe73008 6691 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6692 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6693 /* Stop translation to have a chance to raise an exception */
e06fcd75 6694 gen_stop_exception(ctx);
6527f6ea 6695 } else {
1b6e5f99 6696 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6697 }
76a66253
JM
6698#endif
6699}
6700
08e46e54 6701/* PowerPC 440 specific instructions */
99e300ef 6702
54623277 6703/* dlmzb */
99e300ef 6704static void gen_dlmzb(DisasContext *ctx)
76a66253 6705{
ef0d51af 6706 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6707 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6708 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6709 tcg_temp_free_i32(t0);
76a66253
JM
6710}
6711
6712/* mbar replaces eieio on 440 */
99e300ef 6713static void gen_mbar(DisasContext *ctx)
76a66253
JM
6714{
6715 /* interpreted as no-op */
6716}
6717
6718/* msync replaces sync on 440 */
dcb2b9e1 6719static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6720{
6721 /* interpreted as no-op */
6722}
6723
6724/* icbt */
e8eaa2c0 6725static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6726{
6727 /* interpreted as no-op */
6728 /* XXX: specification say this is treated as a load by the MMU
6729 * but does not generate any exception
6730 */
79aceca5
FB
6731}
6732
9e0b5cb1
AG
6733/* Embedded.Processor Control */
6734
6735static void gen_msgclr(DisasContext *ctx)
6736{
6737#if defined(CONFIG_USER_ONLY)
6738 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6739#else
c47493f2 6740 if (unlikely(ctx->pr)) {
9e0b5cb1
AG
6741 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6742 return;
6743 }
6744
e5f17ac6 6745 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6746#endif
6747}
6748
d5d11a39
AG
6749static void gen_msgsnd(DisasContext *ctx)
6750{
6751#if defined(CONFIG_USER_ONLY)
6752 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6753#else
c47493f2 6754 if (unlikely(ctx->pr)) {
d5d11a39
AG
6755 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6756 return;
6757 }
6758
6759 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6760#endif
6761}
6762
a9d9eb8f
JM
6763/*** Altivec vector extension ***/
6764/* Altivec registers moves */
a9d9eb8f 6765
636aa200 6766static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6767{
e4704b3b 6768 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6769 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6770 return r;
6771}
6772
a9d9eb8f 6773#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6774static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6775{ \
fe1e5c53 6776 TCGv EA; \
a9d9eb8f 6777 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6778 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6779 return; \
6780 } \
76db3ba4 6781 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6782 EA = tcg_temp_new(); \
76db3ba4 6783 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6784 tcg_gen_andi_tl(EA, EA, ~0xf); \
e22c357b
DK
6785 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
6786 64-bit byteswap already. */ \
76db3ba4
AJ
6787 if (ctx->le_mode) { \
6788 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6789 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6790 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6791 } else { \
76db3ba4 6792 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6793 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6794 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6795 } \
6796 tcg_temp_free(EA); \
a9d9eb8f
JM
6797}
6798
6799#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6800static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6801{ \
fe1e5c53 6802 TCGv EA; \
a9d9eb8f 6803 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6804 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6805 return; \
6806 } \
76db3ba4 6807 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6808 EA = tcg_temp_new(); \
76db3ba4 6809 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6810 tcg_gen_andi_tl(EA, EA, ~0xf); \
e22c357b
DK
6811 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
6812 64-bit byteswap already. */ \
76db3ba4
AJ
6813 if (ctx->le_mode) { \
6814 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6815 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6816 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6817 } else { \
76db3ba4 6818 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6819 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6820 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6821 } \
6822 tcg_temp_free(EA); \
a9d9eb8f
JM
6823}
6824
2791128e 6825#define GEN_VR_LVE(name, opc2, opc3, size) \
99e300ef 6826static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6827 { \
6828 TCGv EA; \
6829 TCGv_ptr rs; \
6830 if (unlikely(!ctx->altivec_enabled)) { \
6831 gen_exception(ctx, POWERPC_EXCP_VPU); \
6832 return; \
6833 } \
6834 gen_set_access_type(ctx, ACCESS_INT); \
6835 EA = tcg_temp_new(); \
6836 gen_addr_reg_index(ctx, EA); \
2791128e
TM
6837 if (size > 1) { \
6838 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
6839 } \
cbfb6ae9 6840 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6841 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6842 tcg_temp_free(EA); \
6843 tcg_temp_free_ptr(rs); \
6844 }
6845
2791128e 6846#define GEN_VR_STVE(name, opc2, opc3, size) \
99e300ef 6847static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6848 { \
6849 TCGv EA; \
6850 TCGv_ptr rs; \
6851 if (unlikely(!ctx->altivec_enabled)) { \
6852 gen_exception(ctx, POWERPC_EXCP_VPU); \
6853 return; \
6854 } \
6855 gen_set_access_type(ctx, ACCESS_INT); \
6856 EA = tcg_temp_new(); \
6857 gen_addr_reg_index(ctx, EA); \
2791128e
TM
6858 if (size > 1) { \
6859 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
6860 } \
cbfb6ae9 6861 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6862 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6863 tcg_temp_free(EA); \
6864 tcg_temp_free_ptr(rs); \
6865 }
6866
fe1e5c53 6867GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6868/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6869GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6870
2791128e
TM
6871GEN_VR_LVE(bx, 0x07, 0x00, 1);
6872GEN_VR_LVE(hx, 0x07, 0x01, 2);
6873GEN_VR_LVE(wx, 0x07, 0x02, 4);
cbfb6ae9 6874
fe1e5c53 6875GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6876/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6877GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6878
2791128e
TM
6879GEN_VR_STVE(bx, 0x07, 0x04, 1);
6880GEN_VR_STVE(hx, 0x07, 0x05, 2);
6881GEN_VR_STVE(wx, 0x07, 0x06, 4);
cbfb6ae9 6882
99e300ef 6883static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6884{
6885 TCGv_ptr rd;
6886 TCGv EA;
6887 if (unlikely(!ctx->altivec_enabled)) {
6888 gen_exception(ctx, POWERPC_EXCP_VPU);
6889 return;
6890 }
6891 EA = tcg_temp_new();
6892 gen_addr_reg_index(ctx, EA);
6893 rd = gen_avr_ptr(rD(ctx->opcode));
6894 gen_helper_lvsl(rd, EA);
6895 tcg_temp_free(EA);
6896 tcg_temp_free_ptr(rd);
6897}
6898
99e300ef 6899static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6900{
6901 TCGv_ptr rd;
6902 TCGv EA;
6903 if (unlikely(!ctx->altivec_enabled)) {
6904 gen_exception(ctx, POWERPC_EXCP_VPU);
6905 return;
6906 }
6907 EA = tcg_temp_new();
6908 gen_addr_reg_index(ctx, EA);
6909 rd = gen_avr_ptr(rD(ctx->opcode));
6910 gen_helper_lvsr(rd, EA);
6911 tcg_temp_free(EA);
6912 tcg_temp_free_ptr(rd);
6913}
6914
99e300ef 6915static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6916{
6917 TCGv_i32 t;
6918 if (unlikely(!ctx->altivec_enabled)) {
6919 gen_exception(ctx, POWERPC_EXCP_VPU);
6920 return;
6921 }
6922 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6923 t = tcg_temp_new_i32();
1328c2bf 6924 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6925 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6926 tcg_temp_free_i32(t);
785f451b
AJ
6927}
6928
99e300ef 6929static void gen_mtvscr(DisasContext *ctx)
785f451b 6930{
6e87b7c7 6931 TCGv_ptr p;
785f451b
AJ
6932 if (unlikely(!ctx->altivec_enabled)) {
6933 gen_exception(ctx, POWERPC_EXCP_VPU);
6934 return;
6935 }
76cb6584 6936 p = gen_avr_ptr(rB(ctx->opcode));
d15f74fb 6937 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6938 tcg_temp_free_ptr(p);
785f451b
AJ
6939}
6940
7a9b96cf
AJ
6941/* Logical operations */
6942#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6943static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6944{ \
6945 if (unlikely(!ctx->altivec_enabled)) { \
6946 gen_exception(ctx, POWERPC_EXCP_VPU); \
6947 return; \
6948 } \
6949 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6950 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6951}
6952
6953GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6954GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6955GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6956GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6957GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
111c5f54
TM
6958GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
6959GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
6960GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
7a9b96cf 6961
8e27dd6f 6962#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6963static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6964{ \
6965 TCGv_ptr ra, rb, rd; \
6966 if (unlikely(!ctx->altivec_enabled)) { \
6967 gen_exception(ctx, POWERPC_EXCP_VPU); \
6968 return; \
6969 } \
6970 ra = gen_avr_ptr(rA(ctx->opcode)); \
6971 rb = gen_avr_ptr(rB(ctx->opcode)); \
6972 rd = gen_avr_ptr(rD(ctx->opcode)); \
6973 gen_helper_##name (rd, ra, rb); \
6974 tcg_temp_free_ptr(ra); \
6975 tcg_temp_free_ptr(rb); \
6976 tcg_temp_free_ptr(rd); \
6977}
6978
d15f74fb
BS
6979#define GEN_VXFORM_ENV(name, opc2, opc3) \
6980static void glue(gen_, name)(DisasContext *ctx) \
6981{ \
6982 TCGv_ptr ra, rb, rd; \
6983 if (unlikely(!ctx->altivec_enabled)) { \
6984 gen_exception(ctx, POWERPC_EXCP_VPU); \
6985 return; \
6986 } \
6987 ra = gen_avr_ptr(rA(ctx->opcode)); \
6988 rb = gen_avr_ptr(rB(ctx->opcode)); \
6989 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6990 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6991 tcg_temp_free_ptr(ra); \
6992 tcg_temp_free_ptr(rb); \
6993 tcg_temp_free_ptr(rd); \
9b47bb49
TM
6994}
6995
6996#define GEN_VXFORM3(name, opc2, opc3) \
6997static void glue(gen_, name)(DisasContext *ctx) \
6998{ \
6999 TCGv_ptr ra, rb, rc, rd; \
7000 if (unlikely(!ctx->altivec_enabled)) { \
7001 gen_exception(ctx, POWERPC_EXCP_VPU); \
7002 return; \
7003 } \
7004 ra = gen_avr_ptr(rA(ctx->opcode)); \
7005 rb = gen_avr_ptr(rB(ctx->opcode)); \
7006 rc = gen_avr_ptr(rC(ctx->opcode)); \
7007 rd = gen_avr_ptr(rD(ctx->opcode)); \
7008 gen_helper_##name(rd, ra, rb, rc); \
7009 tcg_temp_free_ptr(ra); \
7010 tcg_temp_free_ptr(rb); \
7011 tcg_temp_free_ptr(rc); \
7012 tcg_temp_free_ptr(rd); \
d15f74fb
BS
7013}
7014
5dffff5a
TM
7015/*
7016 * Support for Altivec instruction pairs that use bit 31 (Rc) as
7017 * an opcode bit. In general, these pairs come from different
7018 * versions of the ISA, so we must also support a pair of flags for
7019 * each instruction.
7020 */
7021#define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7022static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7023{ \
7024 if ((Rc(ctx->opcode) == 0) && \
7025 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7026 gen_##name0(ctx); \
7027 } else if ((Rc(ctx->opcode) == 1) && \
7028 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7029 gen_##name1(ctx); \
7030 } else { \
7031 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7032 } \
7033}
7034
7872c51c
AJ
7035GEN_VXFORM(vaddubm, 0, 0);
7036GEN_VXFORM(vadduhm, 0, 1);
7037GEN_VXFORM(vadduwm, 0, 2);
56eabc75 7038GEN_VXFORM(vaddudm, 0, 3);
7872c51c
AJ
7039GEN_VXFORM(vsububm, 0, 16);
7040GEN_VXFORM(vsubuhm, 0, 17);
7041GEN_VXFORM(vsubuwm, 0, 18);
56eabc75 7042GEN_VXFORM(vsubudm, 0, 19);
e4039339
AJ
7043GEN_VXFORM(vmaxub, 1, 0);
7044GEN_VXFORM(vmaxuh, 1, 1);
7045GEN_VXFORM(vmaxuw, 1, 2);
8203e31b 7046GEN_VXFORM(vmaxud, 1, 3);
e4039339
AJ
7047GEN_VXFORM(vmaxsb, 1, 4);
7048GEN_VXFORM(vmaxsh, 1, 5);
7049GEN_VXFORM(vmaxsw, 1, 6);
8203e31b 7050GEN_VXFORM(vmaxsd, 1, 7);
e4039339
AJ
7051GEN_VXFORM(vminub, 1, 8);
7052GEN_VXFORM(vminuh, 1, 9);
7053GEN_VXFORM(vminuw, 1, 10);
8203e31b 7054GEN_VXFORM(vminud, 1, 11);
e4039339
AJ
7055GEN_VXFORM(vminsb, 1, 12);
7056GEN_VXFORM(vminsh, 1, 13);
7057GEN_VXFORM(vminsw, 1, 14);
8203e31b 7058GEN_VXFORM(vminsd, 1, 15);
fab3cbe9
AJ
7059GEN_VXFORM(vavgub, 1, 16);
7060GEN_VXFORM(vavguh, 1, 17);
7061GEN_VXFORM(vavguw, 1, 18);
7062GEN_VXFORM(vavgsb, 1, 20);
7063GEN_VXFORM(vavgsh, 1, 21);
7064GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
7065GEN_VXFORM(vmrghb, 6, 0);
7066GEN_VXFORM(vmrghh, 6, 1);
7067GEN_VXFORM(vmrghw, 6, 2);
7068GEN_VXFORM(vmrglb, 6, 4);
7069GEN_VXFORM(vmrglh, 6, 5);
7070GEN_VXFORM(vmrglw, 6, 6);
e0ffe77f
TM
7071
7072static void gen_vmrgew(DisasContext *ctx)
7073{
7074 TCGv_i64 tmp;
7075 int VT, VA, VB;
7076 if (unlikely(!ctx->altivec_enabled)) {
7077 gen_exception(ctx, POWERPC_EXCP_VPU);
7078 return;
7079 }
7080 VT = rD(ctx->opcode);
7081 VA = rA(ctx->opcode);
7082 VB = rB(ctx->opcode);
7083 tmp = tcg_temp_new_i64();
7084 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
7085 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
7086 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
7087 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
7088 tcg_temp_free_i64(tmp);
7089}
7090
7091static void gen_vmrgow(DisasContext *ctx)
7092{
7093 int VT, VA, VB;
7094 if (unlikely(!ctx->altivec_enabled)) {
7095 gen_exception(ctx, POWERPC_EXCP_VPU);
7096 return;
7097 }
7098 VT = rD(ctx->opcode);
7099 VA = rA(ctx->opcode);
7100 VB = rB(ctx->opcode);
7101
7102 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7103 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7104}
7105
2c277908
AJ
7106GEN_VXFORM(vmuloub, 4, 0);
7107GEN_VXFORM(vmulouh, 4, 1);
63be0936 7108GEN_VXFORM(vmulouw, 4, 2);
953f0f58
TM
7109GEN_VXFORM(vmuluwm, 4, 2);
7110GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7111 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
2c277908
AJ
7112GEN_VXFORM(vmulosb, 4, 4);
7113GEN_VXFORM(vmulosh, 4, 5);
63be0936 7114GEN_VXFORM(vmulosw, 4, 6);
2c277908
AJ
7115GEN_VXFORM(vmuleub, 4, 8);
7116GEN_VXFORM(vmuleuh, 4, 9);
63be0936 7117GEN_VXFORM(vmuleuw, 4, 10);
2c277908
AJ
7118GEN_VXFORM(vmulesb, 4, 12);
7119GEN_VXFORM(vmulesh, 4, 13);
63be0936 7120GEN_VXFORM(vmulesw, 4, 14);
d79f0809
AJ
7121GEN_VXFORM(vslb, 2, 4);
7122GEN_VXFORM(vslh, 2, 5);
7123GEN_VXFORM(vslw, 2, 6);
2fdf78e6 7124GEN_VXFORM(vsld, 2, 23);
07ef34c3
AJ
7125GEN_VXFORM(vsrb, 2, 8);
7126GEN_VXFORM(vsrh, 2, 9);
7127GEN_VXFORM(vsrw, 2, 10);
2fdf78e6 7128GEN_VXFORM(vsrd, 2, 27);
07ef34c3
AJ
7129GEN_VXFORM(vsrab, 2, 12);
7130GEN_VXFORM(vsrah, 2, 13);
7131GEN_VXFORM(vsraw, 2, 14);
2fdf78e6 7132GEN_VXFORM(vsrad, 2, 15);
7b239bec
AJ
7133GEN_VXFORM(vslo, 6, 16);
7134GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
7135GEN_VXFORM(vaddcuw, 0, 6);
7136GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
7137GEN_VXFORM_ENV(vaddubs, 0, 8);
7138GEN_VXFORM_ENV(vadduhs, 0, 9);
7139GEN_VXFORM_ENV(vadduws, 0, 10);
7140GEN_VXFORM_ENV(vaddsbs, 0, 12);
7141GEN_VXFORM_ENV(vaddshs, 0, 13);
7142GEN_VXFORM_ENV(vaddsws, 0, 14);
7143GEN_VXFORM_ENV(vsububs, 0, 24);
7144GEN_VXFORM_ENV(vsubuhs, 0, 25);
7145GEN_VXFORM_ENV(vsubuws, 0, 26);
7146GEN_VXFORM_ENV(vsubsbs, 0, 28);
7147GEN_VXFORM_ENV(vsubshs, 0, 29);
7148GEN_VXFORM_ENV(vsubsws, 0, 30);
b41da4eb
TM
7149GEN_VXFORM(vadduqm, 0, 4);
7150GEN_VXFORM(vaddcuq, 0, 5);
7151GEN_VXFORM3(vaddeuqm, 30, 0);
7152GEN_VXFORM3(vaddecuq, 30, 0);
7153GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7154 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7155GEN_VXFORM(vsubuqm, 0, 20);
7156GEN_VXFORM(vsubcuq, 0, 21);
7157GEN_VXFORM3(vsubeuqm, 31, 0);
7158GEN_VXFORM3(vsubecuq, 31, 0);
7159GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7160 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
5e1d0985
AJ
7161GEN_VXFORM(vrlb, 2, 0);
7162GEN_VXFORM(vrlh, 2, 1);
7163GEN_VXFORM(vrlw, 2, 2);
2fdf78e6 7164GEN_VXFORM(vrld, 2, 3);
d9430add
AJ
7165GEN_VXFORM(vsl, 2, 7);
7166GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
7167GEN_VXFORM_ENV(vpkuhum, 7, 0);
7168GEN_VXFORM_ENV(vpkuwum, 7, 1);
024215b2 7169GEN_VXFORM_ENV(vpkudum, 7, 17);
d15f74fb
BS
7170GEN_VXFORM_ENV(vpkuhus, 7, 2);
7171GEN_VXFORM_ENV(vpkuwus, 7, 3);
024215b2 7172GEN_VXFORM_ENV(vpkudus, 7, 19);
d15f74fb
BS
7173GEN_VXFORM_ENV(vpkshus, 7, 4);
7174GEN_VXFORM_ENV(vpkswus, 7, 5);
024215b2 7175GEN_VXFORM_ENV(vpksdus, 7, 21);
d15f74fb
BS
7176GEN_VXFORM_ENV(vpkshss, 7, 6);
7177GEN_VXFORM_ENV(vpkswss, 7, 7);
024215b2 7178GEN_VXFORM_ENV(vpksdss, 7, 23);
1dd9ffb9 7179GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
7180GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7181GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7182GEN_VXFORM_ENV(vsum4shs, 4, 25);
7183GEN_VXFORM_ENV(vsum2sws, 4, 26);
7184GEN_VXFORM_ENV(vsumsws, 4, 30);
7185GEN_VXFORM_ENV(vaddfp, 5, 0);
7186GEN_VXFORM_ENV(vsubfp, 5, 1);
7187GEN_VXFORM_ENV(vmaxfp, 5, 16);
7188GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 7189
0cbcd906 7190#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 7191static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
7192 { \
7193 TCGv_ptr ra, rb, rd; \
7194 if (unlikely(!ctx->altivec_enabled)) { \
7195 gen_exception(ctx, POWERPC_EXCP_VPU); \
7196 return; \
7197 } \
7198 ra = gen_avr_ptr(rA(ctx->opcode)); \
7199 rb = gen_avr_ptr(rB(ctx->opcode)); \
7200 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 7201 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
7202 tcg_temp_free_ptr(ra); \
7203 tcg_temp_free_ptr(rb); \
7204 tcg_temp_free_ptr(rd); \
7205 }
7206
7207#define GEN_VXRFORM(name, opc2, opc3) \
7208 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7209 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7210
a737d3eb
TM
7211/*
7212 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7213 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7214 * come from different versions of the ISA, so we must also support a
7215 * pair of flags for each instruction.
7216 */
7217#define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7218static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7219{ \
7220 if ((Rc(ctx->opcode) == 0) && \
7221 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7222 if (Rc21(ctx->opcode) == 0) { \
7223 gen_##name0(ctx); \
7224 } else { \
7225 gen_##name0##_(ctx); \
7226 } \
7227 } else if ((Rc(ctx->opcode) == 1) && \
7228 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7229 if (Rc21(ctx->opcode) == 0) { \
7230 gen_##name1(ctx); \
7231 } else { \
7232 gen_##name1##_(ctx); \
7233 } \
7234 } else { \
7235 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7236 } \
7237}
7238
1add6e23
AJ
7239GEN_VXRFORM(vcmpequb, 3, 0)
7240GEN_VXRFORM(vcmpequh, 3, 1)
7241GEN_VXRFORM(vcmpequw, 3, 2)
6f3dab41 7242GEN_VXRFORM(vcmpequd, 3, 3)
1add6e23
AJ
7243GEN_VXRFORM(vcmpgtsb, 3, 12)
7244GEN_VXRFORM(vcmpgtsh, 3, 13)
7245GEN_VXRFORM(vcmpgtsw, 3, 14)
6f3dab41 7246GEN_VXRFORM(vcmpgtsd, 3, 15)
1add6e23
AJ
7247GEN_VXRFORM(vcmpgtub, 3, 8)
7248GEN_VXRFORM(vcmpgtuh, 3, 9)
7249GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 7250GEN_VXRFORM(vcmpgtud, 3, 11)
819ca121
AJ
7251GEN_VXRFORM(vcmpeqfp, 3, 3)
7252GEN_VXRFORM(vcmpgefp, 3, 7)
7253GEN_VXRFORM(vcmpgtfp, 3, 11)
7254GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 7255
6f3dab41
TM
7256GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7257 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7258GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7259 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7260GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7261 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7262
c026766b 7263#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7264static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
7265 { \
7266 TCGv_ptr rd; \
7267 TCGv_i32 simm; \
7268 if (unlikely(!ctx->altivec_enabled)) { \
7269 gen_exception(ctx, POWERPC_EXCP_VPU); \
7270 return; \
7271 } \
7272 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7273 rd = gen_avr_ptr(rD(ctx->opcode)); \
7274 gen_helper_##name (rd, simm); \
7275 tcg_temp_free_i32(simm); \
7276 tcg_temp_free_ptr(rd); \
7277 }
7278
7279GEN_VXFORM_SIMM(vspltisb, 6, 12);
7280GEN_VXFORM_SIMM(vspltish, 6, 13);
7281GEN_VXFORM_SIMM(vspltisw, 6, 14);
7282
de5f2484 7283#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 7284static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
7285 { \
7286 TCGv_ptr rb, rd; \
7287 if (unlikely(!ctx->altivec_enabled)) { \
7288 gen_exception(ctx, POWERPC_EXCP_VPU); \
7289 return; \
7290 } \
7291 rb = gen_avr_ptr(rB(ctx->opcode)); \
7292 rd = gen_avr_ptr(rD(ctx->opcode)); \
7293 gen_helper_##name (rd, rb); \
7294 tcg_temp_free_ptr(rb); \
7295 tcg_temp_free_ptr(rd); \
7296 }
7297
d15f74fb
BS
7298#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7299static void glue(gen_, name)(DisasContext *ctx) \
7300 { \
7301 TCGv_ptr rb, rd; \
7302 \
7303 if (unlikely(!ctx->altivec_enabled)) { \
7304 gen_exception(ctx, POWERPC_EXCP_VPU); \
7305 return; \
7306 } \
7307 rb = gen_avr_ptr(rB(ctx->opcode)); \
7308 rd = gen_avr_ptr(rD(ctx->opcode)); \
7309 gen_helper_##name(cpu_env, rd, rb); \
7310 tcg_temp_free_ptr(rb); \
7311 tcg_temp_free_ptr(rd); \
7312 }
7313
6cf1c6e5
AJ
7314GEN_VXFORM_NOA(vupkhsb, 7, 8);
7315GEN_VXFORM_NOA(vupkhsh, 7, 9);
4430e076 7316GEN_VXFORM_NOA(vupkhsw, 7, 25);
6cf1c6e5
AJ
7317GEN_VXFORM_NOA(vupklsb, 7, 10);
7318GEN_VXFORM_NOA(vupklsh, 7, 11);
4430e076 7319GEN_VXFORM_NOA(vupklsw, 7, 27);
79f85c3a
AJ
7320GEN_VXFORM_NOA(vupkhpx, 7, 13);
7321GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
7322GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7323GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7324GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7325GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
abe60a43
TM
7326GEN_VXFORM_NOA_ENV(vrfim, 5, 11);
7327GEN_VXFORM_NOA_ENV(vrfin, 5, 8);
d15f74fb 7328GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
abe60a43 7329GEN_VXFORM_NOA_ENV(vrfiz, 5, 9);
79f85c3a 7330
21d21583 7331#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7332static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
7333 { \
7334 TCGv_ptr rd; \
7335 TCGv_i32 simm; \
7336 if (unlikely(!ctx->altivec_enabled)) { \
7337 gen_exception(ctx, POWERPC_EXCP_VPU); \
7338 return; \
7339 } \
7340 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7341 rd = gen_avr_ptr(rD(ctx->opcode)); \
7342 gen_helper_##name (rd, simm); \
7343 tcg_temp_free_i32(simm); \
7344 tcg_temp_free_ptr(rd); \
7345 }
7346
27a4edb3 7347#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 7348static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
7349 { \
7350 TCGv_ptr rb, rd; \
7351 TCGv_i32 uimm; \
7352 if (unlikely(!ctx->altivec_enabled)) { \
7353 gen_exception(ctx, POWERPC_EXCP_VPU); \
7354 return; \
7355 } \
7356 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7357 rb = gen_avr_ptr(rB(ctx->opcode)); \
7358 rd = gen_avr_ptr(rD(ctx->opcode)); \
7359 gen_helper_##name (rd, rb, uimm); \
7360 tcg_temp_free_i32(uimm); \
7361 tcg_temp_free_ptr(rb); \
7362 tcg_temp_free_ptr(rd); \
7363 }
7364
d15f74fb
BS
7365#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7366static void glue(gen_, name)(DisasContext *ctx) \
7367 { \
7368 TCGv_ptr rb, rd; \
7369 TCGv_i32 uimm; \
7370 \
7371 if (unlikely(!ctx->altivec_enabled)) { \
7372 gen_exception(ctx, POWERPC_EXCP_VPU); \
7373 return; \
7374 } \
7375 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7376 rb = gen_avr_ptr(rB(ctx->opcode)); \
7377 rd = gen_avr_ptr(rD(ctx->opcode)); \
7378 gen_helper_##name(cpu_env, rd, rb, uimm); \
7379 tcg_temp_free_i32(uimm); \
7380 tcg_temp_free_ptr(rb); \
7381 tcg_temp_free_ptr(rd); \
7382 }
7383
e4e6bee7
AJ
7384GEN_VXFORM_UIMM(vspltb, 6, 8);
7385GEN_VXFORM_UIMM(vsplth, 6, 9);
7386GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
7387GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7388GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7389GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7390GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 7391
99e300ef 7392static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
7393{
7394 TCGv_ptr ra, rb, rd;
fce5ecb7 7395 TCGv_i32 sh;
cd633b10
AJ
7396 if (unlikely(!ctx->altivec_enabled)) {
7397 gen_exception(ctx, POWERPC_EXCP_VPU);
7398 return;
7399 }
7400 ra = gen_avr_ptr(rA(ctx->opcode));
7401 rb = gen_avr_ptr(rB(ctx->opcode));
7402 rd = gen_avr_ptr(rD(ctx->opcode));
7403 sh = tcg_const_i32(VSH(ctx->opcode));
7404 gen_helper_vsldoi (rd, ra, rb, sh);
7405 tcg_temp_free_ptr(ra);
7406 tcg_temp_free_ptr(rb);
7407 tcg_temp_free_ptr(rd);
fce5ecb7 7408 tcg_temp_free_i32(sh);
cd633b10
AJ
7409}
7410
707cec33 7411#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 7412static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
7413 { \
7414 TCGv_ptr ra, rb, rc, rd; \
7415 if (unlikely(!ctx->altivec_enabled)) { \
7416 gen_exception(ctx, POWERPC_EXCP_VPU); \
7417 return; \
7418 } \
7419 ra = gen_avr_ptr(rA(ctx->opcode)); \
7420 rb = gen_avr_ptr(rB(ctx->opcode)); \
7421 rc = gen_avr_ptr(rC(ctx->opcode)); \
7422 rd = gen_avr_ptr(rD(ctx->opcode)); \
7423 if (Rc(ctx->opcode)) { \
d15f74fb 7424 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 7425 } else { \
d15f74fb 7426 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
7427 } \
7428 tcg_temp_free_ptr(ra); \
7429 tcg_temp_free_ptr(rb); \
7430 tcg_temp_free_ptr(rc); \
7431 tcg_temp_free_ptr(rd); \
7432 }
7433
b161ae27
AJ
7434GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7435
99e300ef 7436static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
7437{
7438 TCGv_ptr ra, rb, rc, rd;
7439 if (unlikely(!ctx->altivec_enabled)) {
7440 gen_exception(ctx, POWERPC_EXCP_VPU);
7441 return;
7442 }
7443 ra = gen_avr_ptr(rA(ctx->opcode));
7444 rb = gen_avr_ptr(rB(ctx->opcode));
7445 rc = gen_avr_ptr(rC(ctx->opcode));
7446 rd = gen_avr_ptr(rD(ctx->opcode));
7447 gen_helper_vmladduhm(rd, ra, rb, rc);
7448 tcg_temp_free_ptr(ra);
7449 tcg_temp_free_ptr(rb);
7450 tcg_temp_free_ptr(rc);
7451 tcg_temp_free_ptr(rd);
7452}
7453
b04ae981 7454GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7455GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7456GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7457GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7458GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7459
f293f04a
TM
7460GEN_VXFORM_NOA(vclzb, 1, 28)
7461GEN_VXFORM_NOA(vclzh, 1, 29)
7462GEN_VXFORM_NOA(vclzw, 1, 30)
7463GEN_VXFORM_NOA(vclzd, 1, 31)
e13500b3
TM
7464GEN_VXFORM_NOA(vpopcntb, 1, 28)
7465GEN_VXFORM_NOA(vpopcnth, 1, 29)
7466GEN_VXFORM_NOA(vpopcntw, 1, 30)
7467GEN_VXFORM_NOA(vpopcntd, 1, 31)
7468GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7469 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7470GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7471 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7472GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7473 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7474GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7475 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
4d82038e 7476GEN_VXFORM(vbpermq, 6, 21);
f1064f61 7477GEN_VXFORM_NOA(vgbbd, 6, 20);
b8476fc7
TM
7478GEN_VXFORM(vpmsumb, 4, 16)
7479GEN_VXFORM(vpmsumh, 4, 17)
7480GEN_VXFORM(vpmsumw, 4, 18)
7481GEN_VXFORM(vpmsumd, 4, 19)
e13500b3 7482
e8f7b27b
TM
7483#define GEN_BCD(op) \
7484static void gen_##op(DisasContext *ctx) \
7485{ \
7486 TCGv_ptr ra, rb, rd; \
7487 TCGv_i32 ps; \
7488 \
7489 if (unlikely(!ctx->altivec_enabled)) { \
7490 gen_exception(ctx, POWERPC_EXCP_VPU); \
7491 return; \
7492 } \
7493 \
7494 ra = gen_avr_ptr(rA(ctx->opcode)); \
7495 rb = gen_avr_ptr(rB(ctx->opcode)); \
7496 rd = gen_avr_ptr(rD(ctx->opcode)); \
7497 \
7498 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7499 \
7500 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7501 \
7502 tcg_temp_free_ptr(ra); \
7503 tcg_temp_free_ptr(rb); \
7504 tcg_temp_free_ptr(rd); \
7505 tcg_temp_free_i32(ps); \
7506}
7507
7508GEN_BCD(bcdadd)
7509GEN_BCD(bcdsub)
7510
7511GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7512 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7513GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7514 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7515GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7516 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7517GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7518 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7519
557d52fa
TM
7520static void gen_vsbox(DisasContext *ctx)
7521{
7522 TCGv_ptr ra, rd;
7523 if (unlikely(!ctx->altivec_enabled)) {
7524 gen_exception(ctx, POWERPC_EXCP_VPU);
7525 return;
7526 }
7527 ra = gen_avr_ptr(rA(ctx->opcode));
7528 rd = gen_avr_ptr(rD(ctx->opcode));
7529 gen_helper_vsbox(rd, ra);
7530 tcg_temp_free_ptr(ra);
7531 tcg_temp_free_ptr(rd);
7532}
7533
7534GEN_VXFORM(vcipher, 4, 20)
7535GEN_VXFORM(vcipherlast, 4, 20)
7536GEN_VXFORM(vncipher, 4, 21)
7537GEN_VXFORM(vncipherlast, 4, 21)
7538
7539GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7540 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7541GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7542 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7543
57354f8f
TM
7544#define VSHASIGMA(op) \
7545static void gen_##op(DisasContext *ctx) \
7546{ \
7547 TCGv_ptr ra, rd; \
7548 TCGv_i32 st_six; \
7549 if (unlikely(!ctx->altivec_enabled)) { \
7550 gen_exception(ctx, POWERPC_EXCP_VPU); \
7551 return; \
7552 } \
7553 ra = gen_avr_ptr(rA(ctx->opcode)); \
7554 rd = gen_avr_ptr(rD(ctx->opcode)); \
7555 st_six = tcg_const_i32(rB(ctx->opcode)); \
7556 gen_helper_##op(rd, ra, st_six); \
7557 tcg_temp_free_ptr(ra); \
7558 tcg_temp_free_ptr(rd); \
7559 tcg_temp_free_i32(st_six); \
7560}
7561
7562VSHASIGMA(vshasigmaw)
7563VSHASIGMA(vshasigmad)
7564
ac174549
TM
7565GEN_VXFORM3(vpermxor, 22, 0xFF)
7566GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7567 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7568
472b24ce
TM
7569/*** VSX extension ***/
7570
7571static inline TCGv_i64 cpu_vsrh(int n)
7572{
7573 if (n < 32) {
7574 return cpu_fpr[n];
7575 } else {
7576 return cpu_avrh[n-32];
7577 }
7578}
7579
7580static inline TCGv_i64 cpu_vsrl(int n)
7581{
7582 if (n < 32) {
7583 return cpu_vsr[n];
7584 } else {
7585 return cpu_avrl[n-32];
7586 }
7587}
7588
e072fe79
TM
7589#define VSX_LOAD_SCALAR(name, operation) \
7590static void gen_##name(DisasContext *ctx) \
7591{ \
7592 TCGv EA; \
7593 if (unlikely(!ctx->vsx_enabled)) { \
7594 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7595 return; \
7596 } \
7597 gen_set_access_type(ctx, ACCESS_INT); \
7598 EA = tcg_temp_new(); \
7599 gen_addr_reg_index(ctx, EA); \
7600 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7601 /* NOTE: cpu_vsrl is undefined */ \
7602 tcg_temp_free(EA); \
7603}
7604
7605VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7606VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7607VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7608VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7609
304af367
TM
7610static void gen_lxvd2x(DisasContext *ctx)
7611{
7612 TCGv EA;
7613 if (unlikely(!ctx->vsx_enabled)) {
7614 gen_exception(ctx, POWERPC_EXCP_VSXU);
7615 return;
7616 }
7617 gen_set_access_type(ctx, ACCESS_INT);
7618 EA = tcg_temp_new();
7619 gen_addr_reg_index(ctx, EA);
7620 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7621 tcg_gen_addi_tl(EA, EA, 8);
7622 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7623 tcg_temp_free(EA);
7624}
7625
ca03b467
TM
7626static void gen_lxvdsx(DisasContext *ctx)
7627{
7628 TCGv EA;
7629 if (unlikely(!ctx->vsx_enabled)) {
7630 gen_exception(ctx, POWERPC_EXCP_VSXU);
7631 return;
7632 }
7633 gen_set_access_type(ctx, ACCESS_INT);
7634 EA = tcg_temp_new();
7635 gen_addr_reg_index(ctx, EA);
7636 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7637 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7638 tcg_temp_free(EA);
7639}
7640
897e61d1
TM
7641static void gen_lxvw4x(DisasContext *ctx)
7642{
f976b09e
AG
7643 TCGv EA;
7644 TCGv_i64 tmp;
897e61d1
TM
7645 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7646 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7647 if (unlikely(!ctx->vsx_enabled)) {
7648 gen_exception(ctx, POWERPC_EXCP_VSXU);
7649 return;
7650 }
7651 gen_set_access_type(ctx, ACCESS_INT);
7652 EA = tcg_temp_new();
f976b09e
AG
7653 tmp = tcg_temp_new_i64();
7654
897e61d1 7655 gen_addr_reg_index(ctx, EA);
f976b09e 7656 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7657 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7658 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7659 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7660
7661 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7662 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7663 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7664 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7665 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7666
7667 tcg_temp_free(EA);
f976b09e 7668 tcg_temp_free_i64(tmp);
897e61d1
TM
7669}
7670
f026da78
TM
7671#define VSX_STORE_SCALAR(name, operation) \
7672static void gen_##name(DisasContext *ctx) \
7673{ \
7674 TCGv EA; \
7675 if (unlikely(!ctx->vsx_enabled)) { \
7676 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7677 return; \
7678 } \
7679 gen_set_access_type(ctx, ACCESS_INT); \
7680 EA = tcg_temp_new(); \
7681 gen_addr_reg_index(ctx, EA); \
7682 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7683 tcg_temp_free(EA); \
9231ba9e
TM
7684}
7685
f026da78 7686VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7687VSX_STORE_SCALAR(stxsiwx, st32_i64)
7688VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7689
fbed2478
TM
7690static void gen_stxvd2x(DisasContext *ctx)
7691{
7692 TCGv EA;
7693 if (unlikely(!ctx->vsx_enabled)) {
7694 gen_exception(ctx, POWERPC_EXCP_VSXU);
7695 return;
7696 }
7697 gen_set_access_type(ctx, ACCESS_INT);
7698 EA = tcg_temp_new();
7699 gen_addr_reg_index(ctx, EA);
7700 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7701 tcg_gen_addi_tl(EA, EA, 8);
7702 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7703 tcg_temp_free(EA);
7704}
7705
86e61ce3
TM
7706static void gen_stxvw4x(DisasContext *ctx)
7707{
f976b09e
AG
7708 TCGv_i64 tmp;
7709 TCGv EA;
86e61ce3
TM
7710 if (unlikely(!ctx->vsx_enabled)) {
7711 gen_exception(ctx, POWERPC_EXCP_VSXU);
7712 return;
7713 }
7714 gen_set_access_type(ctx, ACCESS_INT);
7715 EA = tcg_temp_new();
7716 gen_addr_reg_index(ctx, EA);
f976b09e 7717 tmp = tcg_temp_new_i64();
86e61ce3
TM
7718
7719 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7720 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7721 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7722 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7723
7724 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7725 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7726 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7727 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7728 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7729
7730 tcg_temp_free(EA);
f976b09e 7731 tcg_temp_free_i64(tmp);
86e61ce3
TM
7732}
7733
f5c0f7f9
TM
7734#define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7735static void gen_##name(DisasContext *ctx) \
7736{ \
7737 if (xS(ctx->opcode) < 32) { \
7738 if (unlikely(!ctx->fpu_enabled)) { \
7739 gen_exception(ctx, POWERPC_EXCP_FPU); \
7740 return; \
7741 } \
7742 } else { \
7743 if (unlikely(!ctx->altivec_enabled)) { \
7744 gen_exception(ctx, POWERPC_EXCP_VPU); \
7745 return; \
7746 } \
7747 } \
7748 TCGv_i64 tmp = tcg_temp_new_i64(); \
7749 tcg_gen_##tcgop1(tmp, source); \
7750 tcg_gen_##tcgop2(target, tmp); \
7751 tcg_temp_free_i64(tmp); \
7752}
7753
7754
7755MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7756 cpu_vsrh(xS(ctx->opcode)))
7757MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7758 cpu_gpr[rA(ctx->opcode)])
7759MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7760 cpu_gpr[rA(ctx->opcode)])
7761
7762#if defined(TARGET_PPC64)
7763#define MV_VSRD(name, target, source) \
7764static void gen_##name(DisasContext *ctx) \
7765{ \
7766 if (xS(ctx->opcode) < 32) { \
7767 if (unlikely(!ctx->fpu_enabled)) { \
7768 gen_exception(ctx, POWERPC_EXCP_FPU); \
7769 return; \
7770 } \
7771 } else { \
7772 if (unlikely(!ctx->altivec_enabled)) { \
7773 gen_exception(ctx, POWERPC_EXCP_VPU); \
7774 return; \
7775 } \
7776 } \
7777 tcg_gen_mov_i64(target, source); \
7778}
7779
7780MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7781MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7782
7783#endif
7784
cd73f2c9
TM
7785static void gen_xxpermdi(DisasContext *ctx)
7786{
7787 if (unlikely(!ctx->vsx_enabled)) {
7788 gen_exception(ctx, POWERPC_EXCP_VSXU);
7789 return;
7790 }
7791
f5bc1bfa
TM
7792 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7793 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7794 TCGv_i64 xh, xl;
7795
7796 xh = tcg_temp_new_i64();
7797 xl = tcg_temp_new_i64();
7798
7799 if ((DM(ctx->opcode) & 2) == 0) {
7800 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7801 } else {
7802 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7803 }
7804 if ((DM(ctx->opcode) & 1) == 0) {
7805 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7806 } else {
7807 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7808 }
7809
7810 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7811 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7812
7813 tcg_temp_free_i64(xh);
7814 tcg_temp_free_i64(xl);
cd73f2c9 7815 } else {
f5bc1bfa
TM
7816 if ((DM(ctx->opcode) & 2) == 0) {
7817 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7818 } else {
7819 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7820 }
7821 if ((DM(ctx->opcode) & 1) == 0) {
7822 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7823 } else {
7824 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7825 }
cd73f2c9
TM
7826 }
7827}
7828
df020ce0
TM
7829#define OP_ABS 1
7830#define OP_NABS 2
7831#define OP_NEG 3
7832#define OP_CPSGN 4
e5d7d2b0
PM
7833#define SGN_MASK_DP 0x8000000000000000ull
7834#define SGN_MASK_SP 0x8000000080000000ull
df020ce0
TM
7835
7836#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7837static void glue(gen_, name)(DisasContext * ctx) \
7838 { \
7839 TCGv_i64 xb, sgm; \
7840 if (unlikely(!ctx->vsx_enabled)) { \
7841 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7842 return; \
7843 } \
f976b09e
AG
7844 xb = tcg_temp_new_i64(); \
7845 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7846 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7847 tcg_gen_movi_i64(sgm, sgn_mask); \
7848 switch (op) { \
7849 case OP_ABS: { \
7850 tcg_gen_andc_i64(xb, xb, sgm); \
7851 break; \
7852 } \
7853 case OP_NABS: { \
7854 tcg_gen_or_i64(xb, xb, sgm); \
7855 break; \
7856 } \
7857 case OP_NEG: { \
7858 tcg_gen_xor_i64(xb, xb, sgm); \
7859 break; \
7860 } \
7861 case OP_CPSGN: { \
f976b09e 7862 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7863 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7864 tcg_gen_and_i64(xa, xa, sgm); \
7865 tcg_gen_andc_i64(xb, xb, sgm); \
7866 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7867 tcg_temp_free_i64(xa); \
df020ce0
TM
7868 break; \
7869 } \
7870 } \
7871 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7872 tcg_temp_free_i64(xb); \
7873 tcg_temp_free_i64(sgm); \
df020ce0
TM
7874 }
7875
7876VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7877VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7878VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7879VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7880
be574920
TM
7881#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7882static void glue(gen_, name)(DisasContext * ctx) \
7883 { \
7884 TCGv_i64 xbh, xbl, sgm; \
7885 if (unlikely(!ctx->vsx_enabled)) { \
7886 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7887 return; \
7888 } \
f976b09e
AG
7889 xbh = tcg_temp_new_i64(); \
7890 xbl = tcg_temp_new_i64(); \
7891 sgm = tcg_temp_new_i64(); \
be574920
TM
7892 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7893 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7894 tcg_gen_movi_i64(sgm, sgn_mask); \
7895 switch (op) { \
7896 case OP_ABS: { \
7897 tcg_gen_andc_i64(xbh, xbh, sgm); \
7898 tcg_gen_andc_i64(xbl, xbl, sgm); \
7899 break; \
7900 } \
7901 case OP_NABS: { \
7902 tcg_gen_or_i64(xbh, xbh, sgm); \
7903 tcg_gen_or_i64(xbl, xbl, sgm); \
7904 break; \
7905 } \
7906 case OP_NEG: { \
7907 tcg_gen_xor_i64(xbh, xbh, sgm); \
7908 tcg_gen_xor_i64(xbl, xbl, sgm); \
7909 break; \
7910 } \
7911 case OP_CPSGN: { \
f976b09e
AG
7912 TCGv_i64 xah = tcg_temp_new_i64(); \
7913 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7914 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7915 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7916 tcg_gen_and_i64(xah, xah, sgm); \
7917 tcg_gen_and_i64(xal, xal, sgm); \
7918 tcg_gen_andc_i64(xbh, xbh, sgm); \
7919 tcg_gen_andc_i64(xbl, xbl, sgm); \
7920 tcg_gen_or_i64(xbh, xbh, xah); \
7921 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7922 tcg_temp_free_i64(xah); \
7923 tcg_temp_free_i64(xal); \
be574920
TM
7924 break; \
7925 } \
7926 } \
7927 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7928 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7929 tcg_temp_free_i64(xbh); \
7930 tcg_temp_free_i64(xbl); \
7931 tcg_temp_free_i64(sgm); \
be574920
TM
7932 }
7933
7934VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7935VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7936VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7937VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7938VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7939VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7940VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7941VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7942
3c3cbbdc
TM
7943#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7944static void gen_##name(DisasContext * ctx) \
7945{ \
7946 TCGv_i32 opc; \
7947 if (unlikely(!ctx->vsx_enabled)) { \
7948 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7949 return; \
7950 } \
7951 /* NIP cannot be restored if the memory exception comes from an helper */ \
7952 gen_update_nip(ctx, ctx->nip - 4); \
7953 opc = tcg_const_i32(ctx->opcode); \
7954 gen_helper_##name(cpu_env, opc); \
7955 tcg_temp_free_i32(opc); \
7956}
be574920 7957
3d1140bf
TM
7958#define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7959static void gen_##name(DisasContext * ctx) \
7960{ \
7961 if (unlikely(!ctx->vsx_enabled)) { \
7962 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7963 return; \
7964 } \
7965 /* NIP cannot be restored if the exception comes */ \
7966 /* from a helper. */ \
7967 gen_update_nip(ctx, ctx->nip - 4); \
7968 \
7969 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7970 cpu_vsrh(xB(ctx->opcode))); \
7971}
7972
ee6e02c0
TM
7973GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7974GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7975GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7976GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7977GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7978GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7979GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7980GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7981GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7982GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7983GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7984GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7985GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7986GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7987GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7988GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7989GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
7990GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7991GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
7992GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7993GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568 7994GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7ee19fb9 7995GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
ed8ac568 7996GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7ee19fb9 7997GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
5177d2ca
TM
7998GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7999GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
8000GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
8001GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
8002GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
8003GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
8004GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
8005GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
8006GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
8007GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
8008GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
3d1140bf 8009GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
ee6e02c0 8010
3fd0aadf
TM
8011GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
8012GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 8013GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 8014GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 8015GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 8016GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
968e76bc 8017GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
f53f81e0
TM
8018GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
8019GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
8020GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
8021GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
8022GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
8023GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
8024GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
8025GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
74698350
TM
8026GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
8027GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
3fd0aadf 8028
ee6e02c0
TM
8029GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
8030GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 8031GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 8032GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 8033GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 8034GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 8035GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 8036GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 8037GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
8038GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
8039GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
8040GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
8041GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
8042GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
8043GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
8044GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
8045GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
8046GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
8047GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
8048GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
8049GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
8050GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 8051GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
8052GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
8053GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
8054GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
8055GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
8056GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
8057GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
8058GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
8059GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
8060GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
8061GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
8062GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
8063GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
8064GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
8065
8066GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
8067GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 8068GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 8069GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 8070GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 8071GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 8072GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 8073GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 8074GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
8075GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
8076GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
8077GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
8078GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
8079GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
8080GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
8081GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
8082GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
8083GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
8084GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
8085GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
8086GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
8087GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 8088GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
8089GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
8090GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
8091GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
8092GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
8093GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
8094GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
8095GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
8096GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
8097GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
8098GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
8099GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
8100GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
8101GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 8102
79ca8a6a
TM
8103#define VSX_LOGICAL(name, tcg_op) \
8104static void glue(gen_, name)(DisasContext * ctx) \
8105 { \
8106 if (unlikely(!ctx->vsx_enabled)) { \
8107 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8108 return; \
8109 } \
8110 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8111 cpu_vsrh(xB(ctx->opcode))); \
8112 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8113 cpu_vsrl(xB(ctx->opcode))); \
8114 }
8115
f976b09e
AG
8116VSX_LOGICAL(xxland, tcg_gen_and_i64)
8117VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8118VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8119VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8120VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
67a33f37
TM
8121VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8122VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8123VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
df020ce0 8124
ce577d2e
TM
8125#define VSX_XXMRG(name, high) \
8126static void glue(gen_, name)(DisasContext * ctx) \
8127 { \
8128 TCGv_i64 a0, a1, b0, b1; \
8129 if (unlikely(!ctx->vsx_enabled)) { \
8130 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8131 return; \
8132 } \
f976b09e
AG
8133 a0 = tcg_temp_new_i64(); \
8134 a1 = tcg_temp_new_i64(); \
8135 b0 = tcg_temp_new_i64(); \
8136 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
8137 if (high) { \
8138 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8139 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8140 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8141 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8142 } else { \
8143 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8144 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8145 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8146 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8147 } \
8148 tcg_gen_shri_i64(a0, a0, 32); \
8149 tcg_gen_shri_i64(b0, b0, 32); \
8150 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8151 b0, a0, 32, 32); \
8152 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8153 b1, a1, 32, 32); \
f976b09e
AG
8154 tcg_temp_free_i64(a0); \
8155 tcg_temp_free_i64(a1); \
8156 tcg_temp_free_i64(b0); \
8157 tcg_temp_free_i64(b1); \
ce577d2e
TM
8158 }
8159
8160VSX_XXMRG(xxmrghw, 1)
8161VSX_XXMRG(xxmrglw, 0)
8162
551e3ef7
TM
8163static void gen_xxsel(DisasContext * ctx)
8164{
8165 TCGv_i64 a, b, c;
8166 if (unlikely(!ctx->vsx_enabled)) {
8167 gen_exception(ctx, POWERPC_EXCP_VSXU);
8168 return;
8169 }
f976b09e
AG
8170 a = tcg_temp_new_i64();
8171 b = tcg_temp_new_i64();
8172 c = tcg_temp_new_i64();
551e3ef7
TM
8173
8174 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8175 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8176 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8177
8178 tcg_gen_and_i64(b, b, c);
8179 tcg_gen_andc_i64(a, a, c);
8180 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8181
8182 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8183 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8184 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8185
8186 tcg_gen_and_i64(b, b, c);
8187 tcg_gen_andc_i64(a, a, c);
8188 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8189
f976b09e
AG
8190 tcg_temp_free_i64(a);
8191 tcg_temp_free_i64(b);
8192 tcg_temp_free_i64(c);
551e3ef7
TM
8193}
8194
76c15fe0
TM
8195static void gen_xxspltw(DisasContext *ctx)
8196{
8197 TCGv_i64 b, b2;
8198 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8199 cpu_vsrl(xB(ctx->opcode)) :
8200 cpu_vsrh(xB(ctx->opcode));
8201
8202 if (unlikely(!ctx->vsx_enabled)) {
8203 gen_exception(ctx, POWERPC_EXCP_VSXU);
8204 return;
8205 }
8206
f976b09e
AG
8207 b = tcg_temp_new_i64();
8208 b2 = tcg_temp_new_i64();
76c15fe0
TM
8209
8210 if (UIM(ctx->opcode) & 1) {
8211 tcg_gen_ext32u_i64(b, vsr);
8212 } else {
8213 tcg_gen_shri_i64(b, vsr, 32);
8214 }
8215
8216 tcg_gen_shli_i64(b2, b, 32);
8217 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8218 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8219
f976b09e
AG
8220 tcg_temp_free_i64(b);
8221 tcg_temp_free_i64(b2);
76c15fe0
TM
8222}
8223
acc42968
TM
8224static void gen_xxsldwi(DisasContext *ctx)
8225{
8226 TCGv_i64 xth, xtl;
8227 if (unlikely(!ctx->vsx_enabled)) {
8228 gen_exception(ctx, POWERPC_EXCP_VSXU);
8229 return;
8230 }
f976b09e
AG
8231 xth = tcg_temp_new_i64();
8232 xtl = tcg_temp_new_i64();
acc42968
TM
8233
8234 switch (SHW(ctx->opcode)) {
8235 case 0: {
8236 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8237 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8238 break;
8239 }
8240 case 1: {
f976b09e 8241 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8242 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8243 tcg_gen_shli_i64(xth, xth, 32);
8244 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8245 tcg_gen_shri_i64(t0, t0, 32);
8246 tcg_gen_or_i64(xth, xth, t0);
8247 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8248 tcg_gen_shli_i64(xtl, xtl, 32);
8249 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8250 tcg_gen_shri_i64(t0, t0, 32);
8251 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8252 tcg_temp_free_i64(t0);
acc42968
TM
8253 break;
8254 }
8255 case 2: {
8256 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8257 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8258 break;
8259 }
8260 case 3: {
f976b09e 8261 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8262 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8263 tcg_gen_shli_i64(xth, xth, 32);
8264 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8265 tcg_gen_shri_i64(t0, t0, 32);
8266 tcg_gen_or_i64(xth, xth, t0);
8267 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8268 tcg_gen_shli_i64(xtl, xtl, 32);
8269 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8270 tcg_gen_shri_i64(t0, t0, 32);
8271 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8272 tcg_temp_free_i64(t0);
acc42968
TM
8273 break;
8274 }
8275 }
8276
8277 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8278 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8279
f976b09e
AG
8280 tcg_temp_free_i64(xth);
8281 tcg_temp_free_i64(xtl);
acc42968
TM
8282}
8283
f0b01f02
TM
8284/*** Decimal Floating Point ***/
8285
8286static inline TCGv_ptr gen_fprp_ptr(int reg)
8287{
8288 TCGv_ptr r = tcg_temp_new_ptr();
8289 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, fpr[reg]));
8290 return r;
8291}
8292
f0b01f02
TM
8293#define GEN_DFP_T_A_B_Rc(name) \
8294static void gen_##name(DisasContext *ctx) \
8295{ \
8296 TCGv_ptr rd, ra, rb; \
8297 if (unlikely(!ctx->fpu_enabled)) { \
8298 gen_exception(ctx, POWERPC_EXCP_FPU); \
8299 return; \
8300 } \
8301 gen_update_nip(ctx, ctx->nip - 4); \
8302 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8303 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8304 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8305 gen_helper_##name(cpu_env, rd, ra, rb); \
8306 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8307 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8308 } \
8309 tcg_temp_free_ptr(rd); \
8310 tcg_temp_free_ptr(ra); \
8311 tcg_temp_free_ptr(rb); \
8312}
8313
8314#define GEN_DFP_BF_A_B(name) \
8315static void gen_##name(DisasContext *ctx) \
8316{ \
8317 TCGv_ptr ra, rb; \
8318 if (unlikely(!ctx->fpu_enabled)) { \
8319 gen_exception(ctx, POWERPC_EXCP_FPU); \
8320 return; \
8321 } \
8322 gen_update_nip(ctx, ctx->nip - 4); \
8323 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8324 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8325 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8326 cpu_env, ra, rb); \
8327 tcg_temp_free_ptr(ra); \
8328 tcg_temp_free_ptr(rb); \
8329}
8330
8331#define GEN_DFP_BF_A_DCM(name) \
8332static void gen_##name(DisasContext *ctx) \
8333{ \
8334 TCGv_ptr ra; \
8335 TCGv_i32 dcm; \
8336 if (unlikely(!ctx->fpu_enabled)) { \
8337 gen_exception(ctx, POWERPC_EXCP_FPU); \
8338 return; \
8339 } \
8340 gen_update_nip(ctx, ctx->nip - 4); \
8341 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8342 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8343 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8344 cpu_env, ra, dcm); \
8345 tcg_temp_free_ptr(ra); \
8346 tcg_temp_free_i32(dcm); \
8347}
8348
8349#define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8350static void gen_##name(DisasContext *ctx) \
8351{ \
8352 TCGv_ptr rt, rb; \
8353 TCGv_i32 u32_1, u32_2; \
8354 if (unlikely(!ctx->fpu_enabled)) { \
8355 gen_exception(ctx, POWERPC_EXCP_FPU); \
8356 return; \
8357 } \
8358 gen_update_nip(ctx, ctx->nip - 4); \
8359 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8360 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8361 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8362 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8363 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8364 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8365 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8366 } \
8367 tcg_temp_free_ptr(rt); \
8368 tcg_temp_free_ptr(rb); \
8369 tcg_temp_free_i32(u32_1); \
8370 tcg_temp_free_i32(u32_2); \
8371}
8372
8373#define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8374static void gen_##name(DisasContext *ctx) \
8375{ \
8376 TCGv_ptr rt, ra, rb; \
8377 TCGv_i32 i32; \
8378 if (unlikely(!ctx->fpu_enabled)) { \
8379 gen_exception(ctx, POWERPC_EXCP_FPU); \
8380 return; \
8381 } \
8382 gen_update_nip(ctx, ctx->nip - 4); \
8383 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8384 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8385 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8386 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8387 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8388 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8389 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8390 } \
8391 tcg_temp_free_ptr(rt); \
8392 tcg_temp_free_ptr(rb); \
8393 tcg_temp_free_ptr(ra); \
8394 tcg_temp_free_i32(i32); \
8395 }
8396
8397#define GEN_DFP_T_B_Rc(name) \
8398static void gen_##name(DisasContext *ctx) \
8399{ \
8400 TCGv_ptr rt, rb; \
8401 if (unlikely(!ctx->fpu_enabled)) { \
8402 gen_exception(ctx, POWERPC_EXCP_FPU); \
8403 return; \
8404 } \
8405 gen_update_nip(ctx, ctx->nip - 4); \
8406 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8407 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8408 gen_helper_##name(cpu_env, rt, rb); \
8409 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8410 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8411 } \
8412 tcg_temp_free_ptr(rt); \
8413 tcg_temp_free_ptr(rb); \
8414 }
8415
8416#define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8417static void gen_##name(DisasContext *ctx) \
8418{ \
8419 TCGv_ptr rt, rs; \
8420 TCGv_i32 i32; \
8421 if (unlikely(!ctx->fpu_enabled)) { \
8422 gen_exception(ctx, POWERPC_EXCP_FPU); \
8423 return; \
8424 } \
8425 gen_update_nip(ctx, ctx->nip - 4); \
8426 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8427 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8428 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8429 gen_helper_##name(cpu_env, rt, rs, i32); \
8430 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8431 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8432 } \
8433 tcg_temp_free_ptr(rt); \
8434 tcg_temp_free_ptr(rs); \
8435 tcg_temp_free_i32(i32); \
8436}
ce577d2e 8437
a9d7ba03
TM
8438GEN_DFP_T_A_B_Rc(dadd)
8439GEN_DFP_T_A_B_Rc(daddq)
2128f8a5
TM
8440GEN_DFP_T_A_B_Rc(dsub)
8441GEN_DFP_T_A_B_Rc(dsubq)
8de6a1cc
TM
8442GEN_DFP_T_A_B_Rc(dmul)
8443GEN_DFP_T_A_B_Rc(dmulq)
9024ff40
TM
8444GEN_DFP_T_A_B_Rc(ddiv)
8445GEN_DFP_T_A_B_Rc(ddivq)
5833505b
TM
8446GEN_DFP_BF_A_B(dcmpu)
8447GEN_DFP_BF_A_B(dcmpuq)
8448GEN_DFP_BF_A_B(dcmpo)
8449GEN_DFP_BF_A_B(dcmpoq)
e601c1ee
TM
8450GEN_DFP_BF_A_DCM(dtstdc)
8451GEN_DFP_BF_A_DCM(dtstdcq)
1bf9c0e1
TM
8452GEN_DFP_BF_A_DCM(dtstdg)
8453GEN_DFP_BF_A_DCM(dtstdgq)
f3d2b0bc
TM
8454GEN_DFP_BF_A_B(dtstex)
8455GEN_DFP_BF_A_B(dtstexq)
f6022a76
TM
8456GEN_DFP_BF_A_B(dtstsf)
8457GEN_DFP_BF_A_B(dtstsfq)
5826ebe2
TM
8458GEN_DFP_T_B_U32_U32_Rc(dquai, SIMM5, RMC)
8459GEN_DFP_T_B_U32_U32_Rc(dquaiq, SIMM5, RMC)
8460GEN_DFP_T_A_B_I32_Rc(dqua, RMC)
8461GEN_DFP_T_A_B_I32_Rc(dquaq, RMC)
512918aa
TM
8462GEN_DFP_T_A_B_I32_Rc(drrnd, RMC)
8463GEN_DFP_T_A_B_I32_Rc(drrndq, RMC)
97c0d930
TM
8464GEN_DFP_T_B_U32_U32_Rc(drintx, FPW, RMC)
8465GEN_DFP_T_B_U32_U32_Rc(drintxq, FPW, RMC)
8466GEN_DFP_T_B_U32_U32_Rc(drintn, FPW, RMC)
8467GEN_DFP_T_B_U32_U32_Rc(drintnq, FPW, RMC)
290d9ee5
TM
8468GEN_DFP_T_B_Rc(dctdp)
8469GEN_DFP_T_B_Rc(dctqpq)
ca603eb4
TM
8470GEN_DFP_T_B_Rc(drsp)
8471GEN_DFP_T_B_Rc(drdpq)
f1214193
TM
8472GEN_DFP_T_B_Rc(dcffix)
8473GEN_DFP_T_B_Rc(dcffixq)
bea0dd79
TM
8474GEN_DFP_T_B_Rc(dctfix)
8475GEN_DFP_T_B_Rc(dctfixq)
7796676f
TM
8476GEN_DFP_T_FPR_I32_Rc(ddedpd, rB, SP)
8477GEN_DFP_T_FPR_I32_Rc(ddedpdq, rB, SP)
013c3ac0
TM
8478GEN_DFP_T_FPR_I32_Rc(denbcd, rB, SP)
8479GEN_DFP_T_FPR_I32_Rc(denbcdq, rB, SP)
e8a48460
TM
8480GEN_DFP_T_B_Rc(dxex)
8481GEN_DFP_T_B_Rc(dxexq)
297666eb
TM
8482GEN_DFP_T_A_B_Rc(diex)
8483GEN_DFP_T_A_B_Rc(diexq)
804e654a
TM
8484GEN_DFP_T_FPR_I32_Rc(dscli, rA, DCM)
8485GEN_DFP_T_FPR_I32_Rc(dscliq, rA, DCM)
8486GEN_DFP_T_FPR_I32_Rc(dscri, rA, DCM)
8487GEN_DFP_T_FPR_I32_Rc(dscriq, rA, DCM)
8488
0487d6a8 8489/*** SPE extension ***/
0487d6a8 8490/* Register moves */
3cd7d1dd 8491
a0e13900
FC
8492static inline void gen_evmra(DisasContext *ctx)
8493{
8494
8495 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8496 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8497 return;
8498 }
8499
a0e13900
FC
8500 TCGv_i64 tmp = tcg_temp_new_i64();
8501
8502 /* tmp := rA_lo + rA_hi << 32 */
13b6a455 8503 tcg_gen_concat_tl_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
a0e13900
FC
8504
8505 /* spe_acc := tmp */
1328c2bf 8506 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8507 tcg_temp_free_i64(tmp);
8508
8509 /* rD := rA */
13b6a455
AG
8510 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8511 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
a0e13900
FC
8512}
8513
636aa200
BS
8514static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8515{
13b6a455 8516 tcg_gen_concat_tl_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
f78fb44e 8517}
3cd7d1dd 8518
636aa200
BS
8519static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8520{
13b6a455 8521 tcg_gen_extr_i64_tl(cpu_gpr[reg], cpu_gprh[reg], t);
f78fb44e 8522}
3cd7d1dd 8523
70560da7 8524#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 8525static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
8526{ \
8527 if (Rc(ctx->opcode)) \
8528 gen_##name1(ctx); \
8529 else \
8530 gen_##name0(ctx); \
8531}
8532
8533/* Handler for undefined SPE opcodes */
636aa200 8534static inline void gen_speundef(DisasContext *ctx)
0487d6a8 8535{
e06fcd75 8536 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
8537}
8538
57951c27 8539/* SPE logic */
57951c27 8540#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8541static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8542{ \
8543 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8544 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8545 return; \
8546 } \
8547 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8548 cpu_gpr[rB(ctx->opcode)]); \
8549 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8550 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8551}
57951c27
AJ
8552
8553GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8554GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8555GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8556GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8557GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8558GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8559GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8560GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 8561
57951c27 8562/* SPE logic immediate */
57951c27 8563#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8564static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a 8565{ \
13b6a455 8566 TCGv_i32 t0; \
3d3a6a0a 8567 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8568 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
8569 return; \
8570 } \
13b6a455
AG
8571 t0 = tcg_temp_new_i32(); \
8572 \
8573 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8574 tcg_opi(t0, t0, rB(ctx->opcode)); \
8575 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8576 \
8577 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
57951c27 8578 tcg_opi(t0, t0, rB(ctx->opcode)); \
13b6a455
AG
8579 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8580 \
a7812ae4 8581 tcg_temp_free_i32(t0); \
3d3a6a0a 8582}
57951c27
AJ
8583GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8584GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8585GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8586GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 8587
57951c27 8588/* SPE arithmetic */
57951c27 8589#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8590static inline void gen_##name(DisasContext *ctx) \
0487d6a8 8591{ \
13b6a455 8592 TCGv_i32 t0; \
0487d6a8 8593 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8594 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8595 return; \
8596 } \
13b6a455
AG
8597 t0 = tcg_temp_new_i32(); \
8598 \
8599 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
57951c27 8600 tcg_op(t0, t0); \
13b6a455
AG
8601 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8602 \
8603 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8604 tcg_op(t0, t0); \
8605 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8606 \
a7812ae4 8607 tcg_temp_free_i32(t0); \
57951c27 8608}
0487d6a8 8609
636aa200 8610static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27 8611{
42a268c2
RH
8612 TCGLabel *l1 = gen_new_label();
8613 TCGLabel *l2 = gen_new_label();
0487d6a8 8614
57951c27
AJ
8615 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8616 tcg_gen_neg_i32(ret, arg1);
8617 tcg_gen_br(l2);
8618 gen_set_label(l1);
a7812ae4 8619 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
8620 gen_set_label(l2);
8621}
8622GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8623GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8624GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8625GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 8626static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 8627{
57951c27
AJ
8628 tcg_gen_addi_i32(ret, arg1, 0x8000);
8629 tcg_gen_ext16u_i32(ret, ret);
8630}
8631GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
8632GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8633GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 8634
57951c27 8635#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8636static inline void gen_##name(DisasContext *ctx) \
0487d6a8 8637{ \
13b6a455 8638 TCGv_i32 t0, t1; \
0487d6a8 8639 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8640 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8641 return; \
8642 } \
13b6a455
AG
8643 t0 = tcg_temp_new_i32(); \
8644 t1 = tcg_temp_new_i32(); \
8645 \
8646 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8647 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8648 tcg_op(t0, t0, t1); \
8649 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8650 \
8651 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8652 tcg_gen_trunc_tl_i32(t1, cpu_gprh[rB(ctx->opcode)]); \
8653 tcg_op(t0, t0, t1); \
8654 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8655 \
a7812ae4
PB
8656 tcg_temp_free_i32(t0); \
8657 tcg_temp_free_i32(t1); \
0487d6a8 8658}
0487d6a8 8659
636aa200 8660static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8661{
42a268c2
RH
8662 TCGLabel *l1 = gen_new_label();
8663 TCGLabel *l2 = gen_new_label();
8664 TCGv_i32 t0 = tcg_temp_local_new_i32();
0487d6a8 8665
57951c27
AJ
8666 /* No error here: 6 bits are used */
8667 tcg_gen_andi_i32(t0, arg2, 0x3F);
8668 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8669 tcg_gen_shr_i32(ret, arg1, t0);
8670 tcg_gen_br(l2);
8671 gen_set_label(l1);
8672 tcg_gen_movi_i32(ret, 0);
0aef4261 8673 gen_set_label(l2);
a7812ae4 8674 tcg_temp_free_i32(t0);
57951c27
AJ
8675}
8676GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 8677static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8678{
42a268c2
RH
8679 TCGLabel *l1 = gen_new_label();
8680 TCGLabel *l2 = gen_new_label();
8681 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8682
57951c27
AJ
8683 /* No error here: 6 bits are used */
8684 tcg_gen_andi_i32(t0, arg2, 0x3F);
8685 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8686 tcg_gen_sar_i32(ret, arg1, t0);
8687 tcg_gen_br(l2);
8688 gen_set_label(l1);
8689 tcg_gen_movi_i32(ret, 0);
0aef4261 8690 gen_set_label(l2);
a7812ae4 8691 tcg_temp_free_i32(t0);
57951c27
AJ
8692}
8693GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 8694static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8695{
42a268c2
RH
8696 TCGLabel *l1 = gen_new_label();
8697 TCGLabel *l2 = gen_new_label();
8698 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8699
57951c27
AJ
8700 /* No error here: 6 bits are used */
8701 tcg_gen_andi_i32(t0, arg2, 0x3F);
8702 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8703 tcg_gen_shl_i32(ret, arg1, t0);
8704 tcg_gen_br(l2);
8705 gen_set_label(l1);
8706 tcg_gen_movi_i32(ret, 0);
e29ef9fa 8707 gen_set_label(l2);
a7812ae4 8708 tcg_temp_free_i32(t0);
57951c27
AJ
8709}
8710GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 8711static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8712{
a7812ae4 8713 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
8714 tcg_gen_andi_i32(t0, arg2, 0x1F);
8715 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 8716 tcg_temp_free_i32(t0);
57951c27
AJ
8717}
8718GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 8719static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
8720{
8721 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8722 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8723 return;
8724 }
13b6a455
AG
8725 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8726 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27
AJ
8727}
8728GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 8729static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 8730{
57951c27
AJ
8731 tcg_gen_sub_i32(ret, arg2, arg1);
8732}
8733GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 8734
57951c27 8735/* SPE arithmetic immediate */
57951c27 8736#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8737static inline void gen_##name(DisasContext *ctx) \
57951c27 8738{ \
13b6a455 8739 TCGv_i32 t0; \
57951c27 8740 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8741 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8742 return; \
8743 } \
13b6a455
AG
8744 t0 = tcg_temp_new_i32(); \
8745 \
8746 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
57951c27 8747 tcg_op(t0, t0, rA(ctx->opcode)); \
13b6a455
AG
8748 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8749 \
8750 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rB(ctx->opcode)]); \
8751 tcg_op(t0, t0, rA(ctx->opcode)); \
8752 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8753 \
a7812ae4 8754 tcg_temp_free_i32(t0); \
57951c27 8755}
57951c27
AJ
8756GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8757GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8758
8759/* SPE comparison */
57951c27 8760#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8761static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8762{ \
8763 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8764 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8765 return; \
8766 } \
42a268c2
RH
8767 TCGLabel *l1 = gen_new_label(); \
8768 TCGLabel *l2 = gen_new_label(); \
8769 TCGLabel *l3 = gen_new_label(); \
8770 TCGLabel *l4 = gen_new_label(); \
57951c27 8771 \
13b6a455
AG
8772 tcg_gen_ext32s_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8773 tcg_gen_ext32s_tl(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8774 tcg_gen_ext32s_tl(cpu_gprh[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8775 tcg_gen_ext32s_tl(cpu_gprh[rB(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); \
8776 \
8777 tcg_gen_brcond_tl(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
57951c27 8778 cpu_gpr[rB(ctx->opcode)], l1); \
13b6a455 8779 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8780 tcg_gen_br(l2); \
8781 gen_set_label(l1); \
8782 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8783 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8784 gen_set_label(l2); \
13b6a455 8785 tcg_gen_brcond_tl(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
57951c27
AJ
8786 cpu_gprh[rB(ctx->opcode)], l3); \
8787 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8788 ~(CRF_CH | CRF_CH_AND_CL)); \
8789 tcg_gen_br(l4); \
8790 gen_set_label(l3); \
8791 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8792 CRF_CH | CRF_CH_OR_CL); \
8793 gen_set_label(l4); \
8794}
57951c27
AJ
8795GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8796GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8797GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8798GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8799GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8800
8801/* SPE misc */
636aa200 8802static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8803{
8804 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8805 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8806 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8807}
636aa200 8808static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8809{
8810 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8811 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8812 return;
8813 }
13b6a455
AG
8814 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8815 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27 8816}
636aa200 8817static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8818{
8819 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8820 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8821 return;
8822 }
13b6a455
AG
8823 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8824 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27 8825}
636aa200 8826static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8827{
8828 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8829 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8830 return;
8831 }
33890b3e 8832 if (rD(ctx->opcode) == rA(ctx->opcode)) {
13b6a455
AG
8833 TCGv tmp = tcg_temp_new();
8834 tcg_gen_mov_tl(tmp, cpu_gpr[rA(ctx->opcode)]);
8835 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8836 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], tmp);
8837 tcg_temp_free(tmp);
33890b3e 8838 } else {
13b6a455
AG
8839 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8840 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8841 }
57951c27 8842}
636aa200 8843static inline void gen_evsplati(DisasContext *ctx)
57951c27 8844{
ae01847f 8845 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8846
13b6a455
AG
8847 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
8848 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
57951c27 8849}
636aa200 8850static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8851{
ae01847f 8852 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8853
13b6a455
AG
8854 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
8855 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
0487d6a8
JM
8856}
8857
636aa200 8858static inline void gen_evsel(DisasContext *ctx)
57951c27 8859{
42a268c2
RH
8860 TCGLabel *l1 = gen_new_label();
8861 TCGLabel *l2 = gen_new_label();
8862 TCGLabel *l3 = gen_new_label();
8863 TCGLabel *l4 = gen_new_label();
a7812ae4 8864 TCGv_i32 t0 = tcg_temp_local_new_i32();
42a268c2 8865
57951c27
AJ
8866 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8867 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
57951c27 8868 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27
AJ
8869 tcg_gen_br(l2);
8870 gen_set_label(l1);
57951c27 8871 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
57951c27
AJ
8872 gen_set_label(l2);
8873 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8874 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
57951c27 8875 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8876 tcg_gen_br(l4);
8877 gen_set_label(l3);
57951c27 8878 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27 8879 gen_set_label(l4);
a7812ae4 8880 tcg_temp_free_i32(t0);
57951c27 8881}
e8eaa2c0
BS
8882
8883static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
8884{
8885 gen_evsel(ctx);
8886}
e8eaa2c0
BS
8887
8888static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
8889{
8890 gen_evsel(ctx);
8891}
e8eaa2c0
BS
8892
8893static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
8894{
8895 gen_evsel(ctx);
8896}
e8eaa2c0
BS
8897
8898static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
8899{
8900 gen_evsel(ctx);
8901}
0487d6a8 8902
a0e13900
FC
8903/* Multiply */
8904
8905static inline void gen_evmwumi(DisasContext *ctx)
8906{
8907 TCGv_i64 t0, t1;
8908
8909 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8910 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8911 return;
8912 }
8913
8914 t0 = tcg_temp_new_i64();
8915 t1 = tcg_temp_new_i64();
8916
8917 /* t0 := rA; t1 := rB */
a0e13900 8918 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
13b6a455 8919 tcg_gen_ext32u_i64(t0, t0);
a0e13900 8920 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
13b6a455 8921 tcg_gen_ext32u_i64(t1, t1);
a0e13900
FC
8922
8923 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8924
8925 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8926
8927 tcg_temp_free_i64(t0);
8928 tcg_temp_free_i64(t1);
8929}
8930
8931static inline void gen_evmwumia(DisasContext *ctx)
8932{
8933 TCGv_i64 tmp;
8934
8935 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8936 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8937 return;
8938 }
8939
8940 gen_evmwumi(ctx); /* rD := rA * rB */
8941
8942 tmp = tcg_temp_new_i64();
8943
8944 /* acc := rD */
8945 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8946 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8947 tcg_temp_free_i64(tmp);
8948}
8949
8950static inline void gen_evmwumiaa(DisasContext *ctx)
8951{
8952 TCGv_i64 acc;
8953 TCGv_i64 tmp;
8954
8955 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8956 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8957 return;
8958 }
8959
8960 gen_evmwumi(ctx); /* rD := rA * rB */
8961
8962 acc = tcg_temp_new_i64();
8963 tmp = tcg_temp_new_i64();
8964
8965 /* tmp := rD */
8966 gen_load_gpr64(tmp, rD(ctx->opcode));
8967
8968 /* Load acc */
1328c2bf 8969 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8970
8971 /* acc := tmp + acc */
8972 tcg_gen_add_i64(acc, acc, tmp);
8973
8974 /* Store acc */
1328c2bf 8975 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8976
8977 /* rD := acc */
8978 gen_store_gpr64(rD(ctx->opcode), acc);
8979
8980 tcg_temp_free_i64(acc);
8981 tcg_temp_free_i64(tmp);
8982}
8983
8984static inline void gen_evmwsmi(DisasContext *ctx)
8985{
8986 TCGv_i64 t0, t1;
8987
8988 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8989 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8990 return;
8991 }
8992
8993 t0 = tcg_temp_new_i64();
8994 t1 = tcg_temp_new_i64();
8995
8996 /* t0 := rA; t1 := rB */
13b6a455
AG
8997 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8998 tcg_gen_ext32s_i64(t0, t0);
8999 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9000 tcg_gen_ext32s_i64(t1, t1);
a0e13900
FC
9001
9002 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9003
9004 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9005
9006 tcg_temp_free_i64(t0);
9007 tcg_temp_free_i64(t1);
9008}
9009
9010static inline void gen_evmwsmia(DisasContext *ctx)
9011{
9012 TCGv_i64 tmp;
9013
9014 gen_evmwsmi(ctx); /* rD := rA * rB */
9015
9016 tmp = tcg_temp_new_i64();
9017
9018 /* acc := rD */
9019 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 9020 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9021
9022 tcg_temp_free_i64(tmp);
9023}
9024
9025static inline void gen_evmwsmiaa(DisasContext *ctx)
9026{
9027 TCGv_i64 acc = tcg_temp_new_i64();
9028 TCGv_i64 tmp = tcg_temp_new_i64();
9029
9030 gen_evmwsmi(ctx); /* rD := rA * rB */
9031
9032 acc = tcg_temp_new_i64();
9033 tmp = tcg_temp_new_i64();
9034
9035 /* tmp := rD */
9036 gen_load_gpr64(tmp, rD(ctx->opcode));
9037
9038 /* Load acc */
1328c2bf 9039 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9040
9041 /* acc := tmp + acc */
9042 tcg_gen_add_i64(acc, acc, tmp);
9043
9044 /* Store acc */
1328c2bf 9045 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9046
9047 /* rD := acc */
9048 gen_store_gpr64(rD(ctx->opcode), acc);
9049
9050 tcg_temp_free_i64(acc);
9051 tcg_temp_free_i64(tmp);
9052}
9053
70560da7
FC
9054GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9055GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9056GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9057GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9058GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9059GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9060GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9061GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
9062GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
9063GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9064GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9065GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9066GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9067GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9068GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9069GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9070GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9071GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9072GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9073GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
9074GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9075GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9076GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
9077GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
9078GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9079GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9080GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9081GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9082GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 9083
6a6ae23f 9084/* SPE load and stores */
636aa200 9085static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
9086{
9087 target_ulong uimm = rB(ctx->opcode);
9088
76db3ba4 9089 if (rA(ctx->opcode) == 0) {
6a6ae23f 9090 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 9091 } else {
6a6ae23f 9092 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 9093 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
9094 tcg_gen_ext32u_tl(EA, EA);
9095 }
76db3ba4 9096 }
0487d6a8 9097}
6a6ae23f 9098
636aa200 9099static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f 9100{
6a6ae23f 9101 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 9102 gen_qemu_ld64(ctx, t0, addr);
13b6a455 9103 gen_store_gpr64(rD(ctx->opcode), t0);
6a6ae23f 9104 tcg_temp_free_i64(t0);
0487d6a8 9105}
6a6ae23f 9106
636aa200 9107static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 9108{
76db3ba4
AJ
9109 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9110 gen_addr_add(ctx, addr, addr, 4);
9111 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
0487d6a8 9112}
6a6ae23f 9113
636aa200 9114static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9115{
9116 TCGv t0 = tcg_temp_new();
76db3ba4 9117 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9118 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9119 gen_addr_add(ctx, addr, addr, 2);
9120 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9121 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9122 gen_addr_add(ctx, addr, addr, 2);
9123 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9124 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9125 gen_addr_add(ctx, addr, addr, 2);
9126 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9127 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9128 tcg_temp_free(t0);
0487d6a8
JM
9129}
9130
636aa200 9131static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9132{
9133 TCGv t0 = tcg_temp_new();
76db3ba4 9134 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9135 tcg_gen_shli_tl(t0, t0, 16);
9136 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9137 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9138 tcg_temp_free(t0);
0487d6a8
JM
9139}
9140
636aa200 9141static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9142{
9143 TCGv t0 = tcg_temp_new();
76db3ba4 9144 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9145 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9146 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9147 tcg_temp_free(t0);
0487d6a8
JM
9148}
9149
636aa200 9150static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9151{
9152 TCGv t0 = tcg_temp_new();
76db3ba4 9153 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9154 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9155 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9156 tcg_temp_free(t0);
9157}
9158
636aa200 9159static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9160{
9161 TCGv t0 = tcg_temp_new();
76db3ba4 9162 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9163 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9164 gen_addr_add(ctx, addr, addr, 2);
9165 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9166 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
6a6ae23f
AJ
9167 tcg_temp_free(t0);
9168}
9169
636aa200 9170static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f 9171{
76db3ba4
AJ
9172 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9173 gen_addr_add(ctx, addr, addr, 2);
9174 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9175}
9176
636aa200 9177static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f 9178{
76db3ba4
AJ
9179 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9180 gen_addr_add(ctx, addr, addr, 2);
9181 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9182}
9183
636aa200 9184static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9185{
9186 TCGv t0 = tcg_temp_new();
76db3ba4 9187 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
9188 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9189 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9190 tcg_temp_free(t0);
9191}
9192
636aa200 9193static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9194{
9195 TCGv t0 = tcg_temp_new();
76db3ba4 9196 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9197 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9198 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9199 gen_addr_add(ctx, addr, addr, 2);
9200 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9201 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9202 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9203 tcg_temp_free(t0);
9204}
9205
636aa200 9206static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f 9207{
6a6ae23f 9208 TCGv_i64 t0 = tcg_temp_new_i64();
13b6a455 9209 gen_load_gpr64(t0, rS(ctx->opcode));
76db3ba4 9210 gen_qemu_st64(ctx, t0, addr);
6a6ae23f 9211 tcg_temp_free_i64(t0);
6a6ae23f
AJ
9212}
9213
636aa200 9214static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 9215{
76db3ba4 9216 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4
AJ
9217 gen_addr_add(ctx, addr, addr, 4);
9218 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9219}
9220
636aa200 9221static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9222{
9223 TCGv t0 = tcg_temp_new();
6a6ae23f 9224 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
76db3ba4
AJ
9225 gen_qemu_st16(ctx, t0, addr);
9226 gen_addr_add(ctx, addr, addr, 2);
76db3ba4 9227 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4 9228 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9229 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9230 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9231 tcg_temp_free(t0);
76db3ba4
AJ
9232 gen_addr_add(ctx, addr, addr, 2);
9233 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9234}
9235
636aa200 9236static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9237{
9238 TCGv t0 = tcg_temp_new();
6a6ae23f 9239 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
76db3ba4
AJ
9240 gen_qemu_st16(ctx, t0, addr);
9241 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9242 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9243 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9244 tcg_temp_free(t0);
9245}
9246
636aa200 9247static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f 9248{
76db3ba4 9249 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4
AJ
9250 gen_addr_add(ctx, addr, addr, 2);
9251 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9252}
9253
636aa200 9254static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f 9255{
76db3ba4 9256 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9257}
9258
636aa200 9259static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 9260{
76db3ba4 9261 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9262}
9263
9264#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 9265static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
9266{ \
9267 TCGv t0; \
9268 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9269 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
9270 return; \
9271 } \
76db3ba4 9272 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
9273 t0 = tcg_temp_new(); \
9274 if (Rc(ctx->opcode)) { \
76db3ba4 9275 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 9276 } else { \
76db3ba4 9277 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
9278 } \
9279 gen_op_##name(ctx, t0); \
9280 tcg_temp_free(t0); \
9281}
9282
9283GEN_SPEOP_LDST(evldd, 0x00, 3);
9284GEN_SPEOP_LDST(evldw, 0x01, 3);
9285GEN_SPEOP_LDST(evldh, 0x02, 3);
9286GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9287GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9288GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9289GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9290GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9291GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9292GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9293GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9294
9295GEN_SPEOP_LDST(evstdd, 0x10, 3);
9296GEN_SPEOP_LDST(evstdw, 0x11, 3);
9297GEN_SPEOP_LDST(evstdh, 0x12, 3);
9298GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9299GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9300GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9301GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
9302
9303/* Multiply and add - TODO */
9304#if 0
70560da7
FC
9305GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9306GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9307GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9308GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9309GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9310GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9311GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9312GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9313GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9314GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9315GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9316GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9317
9318GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9319GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9320GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9321GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9322GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9323GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9324GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9325GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9326GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9327GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9328GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9329GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9330
9331GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9332GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9333GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9334GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9335GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9336
9337GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9338GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9339GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9340GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9341GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9342GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9343GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9344GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9345GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9346GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9347GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9348GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9349
9350GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9351GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9352GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9353GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9354
9355GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9356GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9357GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9358GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9359GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9360GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9361GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9362GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9363GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9364GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9365GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9366GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9367
9368GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9369GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9370GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9371GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9372GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
9373#endif
9374
9375/*** SPE floating-point extension ***/
1c97856d 9376#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9377static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9378{ \
9379 TCGv_i32 t0 = tcg_temp_new_i32(); \
9380 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
13b6a455
AG
9381 gen_helper_##name(t0, cpu_env, t0); \
9382 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
1c97856d 9383 tcg_temp_free_i32(t0); \
57951c27 9384}
1c97856d 9385#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9386static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9387{ \
9388 TCGv_i64 t0 = tcg_temp_new_i64(); \
13b6a455 9389 TCGv_i32 t1 = tcg_temp_new_i32(); \
1c97856d 9390 gen_load_gpr64(t0, rB(ctx->opcode)); \
13b6a455
AG
9391 gen_helper_##name(t1, cpu_env, t0); \
9392 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); \
1c97856d 9393 tcg_temp_free_i64(t0); \
13b6a455 9394 tcg_temp_free_i32(t1); \
1c97856d
AJ
9395}
9396#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9397static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9398{ \
9399 TCGv_i64 t0 = tcg_temp_new_i64(); \
13b6a455
AG
9400 TCGv_i32 t1 = tcg_temp_new_i32(); \
9401 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9402 gen_helper_##name(t0, cpu_env, t1); \
1c97856d
AJ
9403 gen_store_gpr64(rD(ctx->opcode), t0); \
9404 tcg_temp_free_i64(t0); \
13b6a455 9405 tcg_temp_free_i32(t1); \
1c97856d
AJ
9406}
9407#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9408static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9409{ \
9410 TCGv_i64 t0 = tcg_temp_new_i64(); \
9411 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9412 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9413 gen_store_gpr64(rD(ctx->opcode), t0); \
9414 tcg_temp_free_i64(t0); \
9415}
9416#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9417static inline void gen_##name(DisasContext *ctx) \
1c97856d 9418{ \
13b6a455 9419 TCGv_i32 t0, t1; \
1c97856d 9420 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9421 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9422 return; \
9423 } \
13b6a455
AG
9424 t0 = tcg_temp_new_i32(); \
9425 t1 = tcg_temp_new_i32(); \
9426 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9427 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9428 gen_helper_##name(t0, cpu_env, t0, t1); \
9429 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9430 \
9431 tcg_temp_free_i32(t0); \
9432 tcg_temp_free_i32(t1); \
1c97856d
AJ
9433}
9434#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9435static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9436{ \
9437 TCGv_i64 t0, t1; \
9438 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9439 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9440 return; \
9441 } \
9442 t0 = tcg_temp_new_i64(); \
9443 t1 = tcg_temp_new_i64(); \
9444 gen_load_gpr64(t0, rA(ctx->opcode)); \
9445 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9446 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9447 gen_store_gpr64(rD(ctx->opcode), t0); \
9448 tcg_temp_free_i64(t0); \
9449 tcg_temp_free_i64(t1); \
9450}
9451#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9452static inline void gen_##name(DisasContext *ctx) \
1c97856d 9453{ \
13b6a455 9454 TCGv_i32 t0, t1; \
1c97856d 9455 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9456 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9457 return; \
9458 } \
13b6a455
AG
9459 t0 = tcg_temp_new_i32(); \
9460 t1 = tcg_temp_new_i32(); \
9461 \
9462 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9463 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9464 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9465 \
9466 tcg_temp_free_i32(t0); \
9467 tcg_temp_free_i32(t1); \
1c97856d
AJ
9468}
9469#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9470static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9471{ \
9472 TCGv_i64 t0, t1; \
9473 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9474 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9475 return; \
9476 } \
9477 t0 = tcg_temp_new_i64(); \
9478 t1 = tcg_temp_new_i64(); \
9479 gen_load_gpr64(t0, rA(ctx->opcode)); \
9480 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9481 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9482 tcg_temp_free_i64(t0); \
9483 tcg_temp_free_i64(t1); \
9484}
57951c27 9485
0487d6a8
JM
9486/* Single precision floating-point vectors operations */
9487/* Arithmetic */
1c97856d
AJ
9488GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9489GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9490GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9491GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9492static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9493{
9494 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9495 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9496 return;
9497 }
13b6a455
AG
9498 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9499 ~0x80000000);
9500 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9501 ~0x80000000);
1c97856d 9502}
636aa200 9503static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9504{
9505 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9506 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9507 return;
9508 }
13b6a455
AG
9509 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9510 0x80000000);
9511 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9512 0x80000000);
1c97856d 9513}
636aa200 9514static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9515{
9516 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9517 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9518 return;
9519 }
13b6a455
AG
9520 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9521 0x80000000);
9522 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9523 0x80000000);
1c97856d
AJ
9524}
9525
0487d6a8 9526/* Conversion */
1c97856d
AJ
9527GEN_SPEFPUOP_CONV_64_64(evfscfui);
9528GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9529GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9530GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9531GEN_SPEFPUOP_CONV_64_64(evfsctui);
9532GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9533GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9534GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9535GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9536GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9537
0487d6a8 9538/* Comparison */
1c97856d
AJ
9539GEN_SPEFPUOP_COMP_64(evfscmpgt);
9540GEN_SPEFPUOP_COMP_64(evfscmplt);
9541GEN_SPEFPUOP_COMP_64(evfscmpeq);
9542GEN_SPEFPUOP_COMP_64(evfststgt);
9543GEN_SPEFPUOP_COMP_64(evfststlt);
9544GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9545
9546/* Opcodes definitions */
70560da7
FC
9547GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9548GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9549GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9550GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9551GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9552GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9553GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9554GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9555GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9556GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9557GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9558GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9559GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9560GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9561
9562/* Single precision floating-point operations */
9563/* Arithmetic */
1c97856d
AJ
9564GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9565GEN_SPEFPUOP_ARITH2_32_32(efssub);
9566GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9567GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9568static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9569{
9570 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9571 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9572 return;
9573 }
6d5c34fa 9574 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9575}
636aa200 9576static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9577{
9578 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9579 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9580 return;
9581 }
6d5c34fa 9582 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9583}
636aa200 9584static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9585{
9586 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9587 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9588 return;
9589 }
6d5c34fa 9590 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9591}
9592
0487d6a8 9593/* Conversion */
1c97856d
AJ
9594GEN_SPEFPUOP_CONV_32_32(efscfui);
9595GEN_SPEFPUOP_CONV_32_32(efscfsi);
9596GEN_SPEFPUOP_CONV_32_32(efscfuf);
9597GEN_SPEFPUOP_CONV_32_32(efscfsf);
9598GEN_SPEFPUOP_CONV_32_32(efsctui);
9599GEN_SPEFPUOP_CONV_32_32(efsctsi);
9600GEN_SPEFPUOP_CONV_32_32(efsctuf);
9601GEN_SPEFPUOP_CONV_32_32(efsctsf);
9602GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9603GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9604GEN_SPEFPUOP_CONV_32_64(efscfd);
9605
0487d6a8 9606/* Comparison */
1c97856d
AJ
9607GEN_SPEFPUOP_COMP_32(efscmpgt);
9608GEN_SPEFPUOP_COMP_32(efscmplt);
9609GEN_SPEFPUOP_COMP_32(efscmpeq);
9610GEN_SPEFPUOP_COMP_32(efststgt);
9611GEN_SPEFPUOP_COMP_32(efststlt);
9612GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9613
9614/* Opcodes definitions */
70560da7
FC
9615GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9616GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9617GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9618GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9619GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9620GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9621GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9622GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9623GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9624GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9625GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9626GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9627GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9628GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9629
9630/* Double precision floating-point operations */
9631/* Arithmetic */
1c97856d
AJ
9632GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9633GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9634GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9635GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9636static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9637{
9638 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9639 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9640 return;
9641 }
6d5c34fa 9642 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9643 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9644 ~0x80000000);
1c97856d 9645}
636aa200 9646static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
9647{
9648 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9649 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9650 return;
9651 }
6d5c34fa 9652 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9653 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9654 0x80000000);
1c97856d 9655}
636aa200 9656static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
9657{
9658 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9659 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9660 return;
9661 }
6d5c34fa 9662 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9663 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9664 0x80000000);
1c97856d
AJ
9665}
9666
0487d6a8 9667/* Conversion */
1c97856d
AJ
9668GEN_SPEFPUOP_CONV_64_32(efdcfui);
9669GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9670GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9671GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9672GEN_SPEFPUOP_CONV_32_64(efdctui);
9673GEN_SPEFPUOP_CONV_32_64(efdctsi);
9674GEN_SPEFPUOP_CONV_32_64(efdctuf);
9675GEN_SPEFPUOP_CONV_32_64(efdctsf);
9676GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9677GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9678GEN_SPEFPUOP_CONV_64_32(efdcfs);
9679GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9680GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9681GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9682GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 9683
0487d6a8 9684/* Comparison */
1c97856d
AJ
9685GEN_SPEFPUOP_COMP_64(efdcmpgt);
9686GEN_SPEFPUOP_COMP_64(efdcmplt);
9687GEN_SPEFPUOP_COMP_64(efdcmpeq);
9688GEN_SPEFPUOP_COMP_64(efdtstgt);
9689GEN_SPEFPUOP_COMP_64(efdtstlt);
9690GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
9691
9692/* Opcodes definitions */
70560da7
FC
9693GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9694GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9695GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9696GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9697GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9698GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9699GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9700GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9701GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9702GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9703GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9704GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9705GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9706GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9707GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9708GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 9709
0ff93d11
TM
9710static void gen_tbegin(DisasContext *ctx)
9711{
9712 if (unlikely(!ctx->tm_enabled)) {
9713 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM);
9714 return;
9715 }
9716 gen_helper_tbegin(cpu_env);
9717}
9718
56a84615
TM
9719#define GEN_TM_NOOP(name) \
9720static inline void gen_##name(DisasContext *ctx) \
9721{ \
9722 if (unlikely(!ctx->tm_enabled)) { \
9723 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9724 return; \
9725 } \
9726 /* Because tbegin always fails in QEMU, these user \
9727 * space instructions all have a simple implementation: \
9728 * \
9729 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9730 * = 0b0 || 0b00 || 0b0 \
9731 */ \
9732 tcg_gen_movi_i32(cpu_crf[0], 0); \
9733}
9734
9735GEN_TM_NOOP(tend);
9736GEN_TM_NOOP(tabort);
9737GEN_TM_NOOP(tabortwc);
9738GEN_TM_NOOP(tabortwci);
9739GEN_TM_NOOP(tabortdc);
9740GEN_TM_NOOP(tabortdci);
9741GEN_TM_NOOP(tsr);
9742
aeedd582
TM
9743static void gen_tcheck(DisasContext *ctx)
9744{
9745 if (unlikely(!ctx->tm_enabled)) {
9746 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM);
9747 return;
9748 }
9749 /* Because tbegin always fails, the tcheck implementation
9750 * is simple:
9751 *
9752 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
9753 * = 0b1 || 0b00 || 0b0
9754 */
9755 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0x8);
9756}
9757
f83c2378
TM
9758#if defined(CONFIG_USER_ONLY)
9759#define GEN_TM_PRIV_NOOP(name) \
9760static inline void gen_##name(DisasContext *ctx) \
9761{ \
9762 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9763}
9764
9765#else
9766
9767#define GEN_TM_PRIV_NOOP(name) \
9768static inline void gen_##name(DisasContext *ctx) \
9769{ \
9770 if (unlikely(ctx->pr)) { \
9771 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9772 return; \
9773 } \
9774 if (unlikely(!ctx->tm_enabled)) { \
9775 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9776 return; \
9777 } \
9778 /* Because tbegin always fails, the implementation is \
9779 * simple: \
9780 * \
9781 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9782 * = 0b0 || 0b00 | 0b0 \
9783 */ \
9784 tcg_gen_movi_i32(cpu_crf[0], 0); \
9785}
9786
9787#endif
9788
9789GEN_TM_PRIV_NOOP(treclaim);
9790GEN_TM_PRIV_NOOP(trechkpt);
9791
c227f099 9792static opcode_t opcodes[] = {
5c55ff99
BS
9793GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9794GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9795GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9796GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9797GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 9798GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9799GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9800GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9801GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9802GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9803GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9804GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9805GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9806GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9807GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9808GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9809#if defined(TARGET_PPC64)
9810GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9811#endif
9812GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9813GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9814GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9815GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9816GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9817GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9818GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9819GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9820GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9821GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9822GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9823GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
6ab39b1b 9824GEN_HANDLER(popcntb, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 9825GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 9826GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 9827#if defined(TARGET_PPC64)
eaabeef2 9828GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 9829GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 9830GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
86ba37ed 9831GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
5c55ff99
BS
9832#endif
9833GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9834GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9835GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9836GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9837GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9838GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9839GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9840#if defined(TARGET_PPC64)
9841GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9842GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9843GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9844GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9845GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9846#endif
9847GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9848GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9849GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9850GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9851GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 9852GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 9853GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
9854GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9855GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 9856GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
097ec5d8
TM
9857GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
9858GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
5c55ff99
BS
9859GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9860GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9861GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9862GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
9863GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9864GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
9865#if defined(TARGET_PPC64)
9866GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9867GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9868GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9869#endif
9870GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9871GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9872GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9873GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9874GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9875GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9876GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9877GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
5c77a786
TM
9878GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9879GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
f844c817 9880GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
587c51f7
TM
9881GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9882GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
5c55ff99
BS
9883GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9884#if defined(TARGET_PPC64)
f844c817 9885GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
9c294d5a 9886GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99 9887GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
27b95bfe 9888GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99
BS
9889#endif
9890GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9891GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9892GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9893GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9894GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9895GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
52a4984d 9896GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
5c55ff99
BS
9897GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9898GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9899#if defined(TARGET_PPC64)
9900GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9901GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9902#endif
9903GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9904GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9905GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9906#if defined(TARGET_PPC64)
9907GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9908GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9909#endif
9910GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9911GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9912GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9913GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9914GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9915GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9916#if defined(TARGET_PPC64)
9917GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9918#endif
9919GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
4248b336 9920GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC),
5c55ff99
BS
9921GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9922GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9923GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
3f34cf91
CLG
9924GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
9925GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
4d09d529 9926GEN_HANDLER_E(dcbtls, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE, PPC2_BOOKE206),
8e33944f 9927GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
9928GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9929GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9930GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9931GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9932GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9933GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9934GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9935GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9936GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9937#if defined(TARGET_PPC64)
9938GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9939GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9940 PPC_SEGMENT_64B),
9941GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
9942GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9943 PPC_SEGMENT_64B),
efdef95f
DG
9944GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
9945GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
9946GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
9947#endif
9948GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
9949GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
9950GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
9951GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
9952#if defined(TARGET_PPC64)
9953GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
9954GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
9955#endif
9956GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
9957GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
9958GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
9959GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
9960GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
9961GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
9962GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
9963GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
9964GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
9965GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
9966GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
9967GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9968GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
9969GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
9970GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
9971GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
9972GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
9973GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
9974GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
9975GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9976GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
9977GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
9978GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
9979GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
9980GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
9981GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
9982GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
9983GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
9984GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
9985GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
9986GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
9987GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
9988GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
9989GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
9990GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
9991GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
9992GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
9993GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
9994GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
9995GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
9996GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
9997GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
9998GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
9999GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
10000GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
10001GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
10002GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
10003GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
10004GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
10005GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10006GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10007GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
10008GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
10009GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10010GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10011GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
10012GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
10013GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
10014GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
10015GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
10016GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
10017GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
10018GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
10019GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
10020GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
10021GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
10022GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
10023GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
10024GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
10025GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
10026GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 10027GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10028GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
10029GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
10030GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
10031GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
10032GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
10033GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
10034GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
10035GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
10036GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10037 PPC_NONE, PPC2_BOOKE206),
10038GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10039 PPC_NONE, PPC2_BOOKE206),
10040GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10041 PPC_NONE, PPC2_BOOKE206),
10042GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10043 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
10044GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10045 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
10046GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10047 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
10048GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10049 PPC_NONE, PPC2_PRCNTL),
5c55ff99 10050GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 10051GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 10052GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
10053GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
10054 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 10055GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
10056GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10057 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10058GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
10059GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
10060GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
10061GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
5c55ff99
BS
10062GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
10063GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
10064GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
10065GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
10066GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
10067
10068#undef GEN_INT_ARITH_ADD
10069#undef GEN_INT_ARITH_ADD_CONST
10070#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10071GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10072#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10073 add_ca, compute_ca, compute_ov) \
10074GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10075GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
10076GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
10077GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
10078GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
10079GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
10080GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
10081GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
10082GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
10083GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
10084GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
10085
10086#undef GEN_INT_ARITH_DIVW
10087#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10088GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10089GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
10090GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
10091GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
10092GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
a98eb9e9
TM
10093GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10094GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
6a4fda33
TM
10095GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10096GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
5c55ff99
BS
10097
10098#if defined(TARGET_PPC64)
10099#undef GEN_INT_ARITH_DIVD
10100#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10101GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10102GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
10103GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
10104GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
10105GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
10106
98d1eb27
TM
10107GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10108GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
e44259b6
TM
10109GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10110GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
98d1eb27 10111
5c55ff99
BS
10112#undef GEN_INT_ARITH_MUL_HELPER
10113#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10114GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10115GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
10116GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
10117GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
10118#endif
10119
10120#undef GEN_INT_ARITH_SUBF
10121#undef GEN_INT_ARITH_SUBF_CONST
10122#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10123GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10124#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10125 add_ca, compute_ca, compute_ov) \
10126GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10127GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
10128GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
10129GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
10130GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
10131GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
10132GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
10133GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
10134GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
10135GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
10136GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
10137
10138#undef GEN_LOGICAL1
10139#undef GEN_LOGICAL2
10140#define GEN_LOGICAL2(name, tcg_op, opc, type) \
10141GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10142#define GEN_LOGICAL1(name, tcg_op, opc, type) \
10143GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10144GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10145GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10146GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10147GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10148GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10149GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10150GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10151GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10152#if defined(TARGET_PPC64)
10153GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10154#endif
10155
10156#if defined(TARGET_PPC64)
10157#undef GEN_PPC64_R2
10158#undef GEN_PPC64_R4
10159#define GEN_PPC64_R2(name, opc1, opc2) \
10160GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10161GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10162 PPC_64B)
10163#define GEN_PPC64_R4(name, opc1, opc2) \
10164GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10165GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10166 PPC_64B), \
10167GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10168 PPC_64B), \
10169GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10170 PPC_64B)
10171GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10172GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10173GEN_PPC64_R4(rldic, 0x1E, 0x04),
10174GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10175GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10176GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10177#endif
10178
10179#undef _GEN_FLOAT_ACB
10180#undef GEN_FLOAT_ACB
10181#undef _GEN_FLOAT_AB
10182#undef GEN_FLOAT_AB
10183#undef _GEN_FLOAT_AC
10184#undef GEN_FLOAT_AC
10185#undef GEN_FLOAT_B
10186#undef GEN_FLOAT_BS
10187#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10188GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10189#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10190_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10191_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10192#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10193GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10194#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10195_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10196_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10197#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10198GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10199#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10200_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10201_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10202#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10203GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10204#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10205GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10206
10207GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10208GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10209GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10210GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10211GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10212GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10213_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10214GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10215GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10216GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10217GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10218GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
da29cb7b 10219GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
6d41d146 10220GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
5c55ff99 10221GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
fab7fe42 10222GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10223GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
fab7fe42 10224GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10225GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
4171853c 10226GEN_HANDLER_E(fcfid, 0x3F, 0x0E, 0x1A, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
28288b48
TM
10227GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10228GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10229GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
4171853c 10230GEN_HANDLER_E(fctid, 0x3F, 0x0E, 0x19, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
fab7fe42 10231GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
4171853c 10232GEN_HANDLER_E(fctidz, 0x3F, 0x0F, 0x19, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
fab7fe42 10233GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10234GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10235GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10236GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10237GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
10238
10239#undef GEN_LD
10240#undef GEN_LDU
10241#undef GEN_LDUX
cd6e9320 10242#undef GEN_LDX_E
5c55ff99
BS
10243#undef GEN_LDS
10244#define GEN_LD(name, ldop, opc, type) \
10245GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10246#define GEN_LDU(name, ldop, opc, type) \
10247GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10248#define GEN_LDUX(name, ldop, opc2, opc3, type) \
10249GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10250#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10251GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10252#define GEN_LDS(name, ldop, op, type) \
10253GEN_LD(name, ldop, op | 0x20, type) \
10254GEN_LDU(name, ldop, op | 0x21, type) \
10255GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10256GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10257
10258GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10259GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10260GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10261GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10262#if defined(TARGET_PPC64)
10263GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10264GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10265GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10266GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 10267GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10268#endif
10269GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10270GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10271
10272#undef GEN_ST
10273#undef GEN_STU
10274#undef GEN_STUX
cd6e9320 10275#undef GEN_STX_E
5c55ff99
BS
10276#undef GEN_STS
10277#define GEN_ST(name, stop, opc, type) \
10278GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10279#define GEN_STU(name, stop, opc, type) \
10280GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10281#define GEN_STUX(name, stop, opc2, opc3, type) \
10282GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10283#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10284GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10285#define GEN_STS(name, stop, op, type) \
10286GEN_ST(name, stop, op | 0x20, type) \
10287GEN_STU(name, stop, op | 0x21, type) \
10288GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10289GEN_STX(name, stop, 0x17, op | 0x00, type)
10290
10291GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10292GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10293GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10294#if defined(TARGET_PPC64)
10295GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10296GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 10297GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10298#endif
10299GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10300GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10301
10302#undef GEN_LDF
10303#undef GEN_LDUF
10304#undef GEN_LDUXF
10305#undef GEN_LDXF
10306#undef GEN_LDFS
10307#define GEN_LDF(name, ldop, opc, type) \
10308GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10309#define GEN_LDUF(name, ldop, opc, type) \
10310GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10311#define GEN_LDUXF(name, ldop, opc, type) \
10312GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10313#define GEN_LDXF(name, ldop, opc2, opc3, type) \
10314GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10315#define GEN_LDFS(name, ldop, op, type) \
10316GEN_LDF(name, ldop, op | 0x20, type) \
10317GEN_LDUF(name, ldop, op | 0x21, type) \
10318GEN_LDUXF(name, ldop, op | 0x01, type) \
10319GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10320
10321GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10322GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 10323GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
66c3e328 10324GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
05050ee8
AJ
10325GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10326GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10327
10328#undef GEN_STF
10329#undef GEN_STUF
10330#undef GEN_STUXF
10331#undef GEN_STXF
10332#undef GEN_STFS
10333#define GEN_STF(name, stop, opc, type) \
10334GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10335#define GEN_STUF(name, stop, opc, type) \
10336GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10337#define GEN_STUXF(name, stop, opc, type) \
10338GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10339#define GEN_STXF(name, stop, opc2, opc3, type) \
10340GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10341#define GEN_STFS(name, stop, op, type) \
10342GEN_STF(name, stop, op | 0x20, type) \
10343GEN_STUF(name, stop, op | 0x21, type) \
10344GEN_STUXF(name, stop, op | 0x01, type) \
10345GEN_STXF(name, stop, 0x17, op | 0x00, type)
10346
10347GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10348GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10349GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
10350GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10351GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10352
10353#undef GEN_CRLOGIC
10354#define GEN_CRLOGIC(name, tcg_op, opc) \
10355GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10356GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10357GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10358GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10359GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10360GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10361GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10362GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10363GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10364
10365#undef GEN_MAC_HANDLER
10366#define GEN_MAC_HANDLER(name, opc2, opc3) \
10367GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10368GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10369GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10370GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10371GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10372GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10373GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10374GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10375GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10376GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10377GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10378GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10379GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10380GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10381GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10382GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10383GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10384GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10385GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10386GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10387GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10388GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10389GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10390GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10391GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10392GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10393GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10394GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10395GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10396GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10397GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10398GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10399GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10400GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10401GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10402GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10403GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10404GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10405GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10406GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10407GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10408GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10409GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10410
10411#undef GEN_VR_LDX
10412#undef GEN_VR_STX
10413#undef GEN_VR_LVE
10414#undef GEN_VR_STVE
10415#define GEN_VR_LDX(name, opc2, opc3) \
10416GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10417#define GEN_VR_STX(name, opc2, opc3) \
10418GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10419#define GEN_VR_LVE(name, opc2, opc3) \
10420 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10421#define GEN_VR_STVE(name, opc2, opc3) \
10422 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10423GEN_VR_LDX(lvx, 0x07, 0x03),
10424GEN_VR_LDX(lvxl, 0x07, 0x0B),
10425GEN_VR_LVE(bx, 0x07, 0x00),
10426GEN_VR_LVE(hx, 0x07, 0x01),
10427GEN_VR_LVE(wx, 0x07, 0x02),
10428GEN_VR_STX(svx, 0x07, 0x07),
10429GEN_VR_STX(svxl, 0x07, 0x0F),
10430GEN_VR_STVE(bx, 0x07, 0x04),
10431GEN_VR_STVE(hx, 0x07, 0x05),
10432GEN_VR_STVE(wx, 0x07, 0x06),
10433
10434#undef GEN_VX_LOGICAL
10435#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10436GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
111c5f54
TM
10437
10438#undef GEN_VX_LOGICAL_207
10439#define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10440GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10441
5c55ff99
BS
10442GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10443GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10444GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10445GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10446GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
111c5f54
TM
10447GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10448GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10449GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
5c55ff99
BS
10450
10451#undef GEN_VXFORM
10452#define GEN_VXFORM(name, opc2, opc3) \
10453GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
50f5fc0c
TM
10454
10455#undef GEN_VXFORM_207
10456#define GEN_VXFORM_207(name, opc2, opc3) \
10457GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10458
5dffff5a
TM
10459#undef GEN_VXFORM_DUAL
10460#define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10461GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10462
a737d3eb
TM
10463#undef GEN_VXRFORM_DUAL
10464#define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10465GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10466GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10467
5c55ff99
BS
10468GEN_VXFORM(vaddubm, 0, 0),
10469GEN_VXFORM(vadduhm, 0, 1),
10470GEN_VXFORM(vadduwm, 0, 2),
56eabc75 10471GEN_VXFORM_207(vaddudm, 0, 3),
e8f7b27b
TM
10472GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10473GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
5c55ff99 10474GEN_VXFORM(vsubuwm, 0, 18),
56eabc75 10475GEN_VXFORM_207(vsubudm, 0, 19),
5c55ff99
BS
10476GEN_VXFORM(vmaxub, 1, 0),
10477GEN_VXFORM(vmaxuh, 1, 1),
10478GEN_VXFORM(vmaxuw, 1, 2),
8203e31b 10479GEN_VXFORM_207(vmaxud, 1, 3),
5c55ff99
BS
10480GEN_VXFORM(vmaxsb, 1, 4),
10481GEN_VXFORM(vmaxsh, 1, 5),
10482GEN_VXFORM(vmaxsw, 1, 6),
8203e31b 10483GEN_VXFORM_207(vmaxsd, 1, 7),
5c55ff99
BS
10484GEN_VXFORM(vminub, 1, 8),
10485GEN_VXFORM(vminuh, 1, 9),
10486GEN_VXFORM(vminuw, 1, 10),
8203e31b 10487GEN_VXFORM_207(vminud, 1, 11),
5c55ff99
BS
10488GEN_VXFORM(vminsb, 1, 12),
10489GEN_VXFORM(vminsh, 1, 13),
10490GEN_VXFORM(vminsw, 1, 14),
8203e31b 10491GEN_VXFORM_207(vminsd, 1, 15),
5c55ff99
BS
10492GEN_VXFORM(vavgub, 1, 16),
10493GEN_VXFORM(vavguh, 1, 17),
10494GEN_VXFORM(vavguw, 1, 18),
10495GEN_VXFORM(vavgsb, 1, 20),
10496GEN_VXFORM(vavgsh, 1, 21),
10497GEN_VXFORM(vavgsw, 1, 22),
10498GEN_VXFORM(vmrghb, 6, 0),
10499GEN_VXFORM(vmrghh, 6, 1),
10500GEN_VXFORM(vmrghw, 6, 2),
10501GEN_VXFORM(vmrglb, 6, 4),
10502GEN_VXFORM(vmrglh, 6, 5),
10503GEN_VXFORM(vmrglw, 6, 6),
e0ffe77f
TM
10504GEN_VXFORM_207(vmrgew, 6, 30),
10505GEN_VXFORM_207(vmrgow, 6, 26),
5c55ff99
BS
10506GEN_VXFORM(vmuloub, 4, 0),
10507GEN_VXFORM(vmulouh, 4, 1),
953f0f58 10508GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10509GEN_VXFORM(vmulosb, 4, 4),
10510GEN_VXFORM(vmulosh, 4, 5),
63be0936 10511GEN_VXFORM_207(vmulosw, 4, 6),
5c55ff99
BS
10512GEN_VXFORM(vmuleub, 4, 8),
10513GEN_VXFORM(vmuleuh, 4, 9),
63be0936 10514GEN_VXFORM_207(vmuleuw, 4, 10),
5c55ff99
BS
10515GEN_VXFORM(vmulesb, 4, 12),
10516GEN_VXFORM(vmulesh, 4, 13),
63be0936 10517GEN_VXFORM_207(vmulesw, 4, 14),
5c55ff99
BS
10518GEN_VXFORM(vslb, 2, 4),
10519GEN_VXFORM(vslh, 2, 5),
10520GEN_VXFORM(vslw, 2, 6),
2fdf78e6 10521GEN_VXFORM_207(vsld, 2, 23),
5c55ff99
BS
10522GEN_VXFORM(vsrb, 2, 8),
10523GEN_VXFORM(vsrh, 2, 9),
10524GEN_VXFORM(vsrw, 2, 10),
2fdf78e6 10525GEN_VXFORM_207(vsrd, 2, 27),
5c55ff99
BS
10526GEN_VXFORM(vsrab, 2, 12),
10527GEN_VXFORM(vsrah, 2, 13),
10528GEN_VXFORM(vsraw, 2, 14),
2fdf78e6 10529GEN_VXFORM_207(vsrad, 2, 15),
5c55ff99
BS
10530GEN_VXFORM(vslo, 6, 16),
10531GEN_VXFORM(vsro, 6, 17),
10532GEN_VXFORM(vaddcuw, 0, 6),
10533GEN_VXFORM(vsubcuw, 0, 22),
10534GEN_VXFORM(vaddubs, 0, 8),
10535GEN_VXFORM(vadduhs, 0, 9),
10536GEN_VXFORM(vadduws, 0, 10),
10537GEN_VXFORM(vaddsbs, 0, 12),
10538GEN_VXFORM(vaddshs, 0, 13),
10539GEN_VXFORM(vaddsws, 0, 14),
e8f7b27b
TM
10540GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10541GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10542GEN_VXFORM(vsubuws, 0, 26),
10543GEN_VXFORM(vsubsbs, 0, 28),
10544GEN_VXFORM(vsubshs, 0, 29),
10545GEN_VXFORM(vsubsws, 0, 30),
b41da4eb
TM
10546GEN_VXFORM_207(vadduqm, 0, 4),
10547GEN_VXFORM_207(vaddcuq, 0, 5),
10548GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10549GEN_VXFORM_207(vsubuqm, 0, 20),
10550GEN_VXFORM_207(vsubcuq, 0, 21),
10551GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
5c55ff99
BS
10552GEN_VXFORM(vrlb, 2, 0),
10553GEN_VXFORM(vrlh, 2, 1),
10554GEN_VXFORM(vrlw, 2, 2),
2fdf78e6 10555GEN_VXFORM_207(vrld, 2, 3),
5c55ff99
BS
10556GEN_VXFORM(vsl, 2, 7),
10557GEN_VXFORM(vsr, 2, 11),
10558GEN_VXFORM(vpkuhum, 7, 0),
10559GEN_VXFORM(vpkuwum, 7, 1),
024215b2 10560GEN_VXFORM_207(vpkudum, 7, 17),
5c55ff99
BS
10561GEN_VXFORM(vpkuhus, 7, 2),
10562GEN_VXFORM(vpkuwus, 7, 3),
024215b2 10563GEN_VXFORM_207(vpkudus, 7, 19),
5c55ff99
BS
10564GEN_VXFORM(vpkshus, 7, 4),
10565GEN_VXFORM(vpkswus, 7, 5),
024215b2 10566GEN_VXFORM_207(vpksdus, 7, 21),
5c55ff99
BS
10567GEN_VXFORM(vpkshss, 7, 6),
10568GEN_VXFORM(vpkswss, 7, 7),
024215b2 10569GEN_VXFORM_207(vpksdss, 7, 23),
5c55ff99
BS
10570GEN_VXFORM(vpkpx, 7, 12),
10571GEN_VXFORM(vsum4ubs, 4, 24),
10572GEN_VXFORM(vsum4sbs, 4, 28),
10573GEN_VXFORM(vsum4shs, 4, 25),
10574GEN_VXFORM(vsum2sws, 4, 26),
10575GEN_VXFORM(vsumsws, 4, 30),
10576GEN_VXFORM(vaddfp, 5, 0),
10577GEN_VXFORM(vsubfp, 5, 1),
10578GEN_VXFORM(vmaxfp, 5, 16),
10579GEN_VXFORM(vminfp, 5, 17),
10580
10581#undef GEN_VXRFORM1
10582#undef GEN_VXRFORM
10583#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10584 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10585#define GEN_VXRFORM(name, opc2, opc3) \
10586 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10587 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10588GEN_VXRFORM(vcmpequb, 3, 0)
10589GEN_VXRFORM(vcmpequh, 3, 1)
10590GEN_VXRFORM(vcmpequw, 3, 2)
10591GEN_VXRFORM(vcmpgtsb, 3, 12)
10592GEN_VXRFORM(vcmpgtsh, 3, 13)
10593GEN_VXRFORM(vcmpgtsw, 3, 14)
10594GEN_VXRFORM(vcmpgtub, 3, 8)
10595GEN_VXRFORM(vcmpgtuh, 3, 9)
10596GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 10597GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
5c55ff99 10598GEN_VXRFORM(vcmpgefp, 3, 7)
6f3dab41
TM
10599GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10600GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
5c55ff99
BS
10601
10602#undef GEN_VXFORM_SIMM
10603#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10604 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10605GEN_VXFORM_SIMM(vspltisb, 6, 12),
10606GEN_VXFORM_SIMM(vspltish, 6, 13),
10607GEN_VXFORM_SIMM(vspltisw, 6, 14),
10608
10609#undef GEN_VXFORM_NOA
10610#define GEN_VXFORM_NOA(name, opc2, opc3) \
10611 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10612GEN_VXFORM_NOA(vupkhsb, 7, 8),
10613GEN_VXFORM_NOA(vupkhsh, 7, 9),
4430e076 10614GEN_VXFORM_207(vupkhsw, 7, 25),
5c55ff99
BS
10615GEN_VXFORM_NOA(vupklsb, 7, 10),
10616GEN_VXFORM_NOA(vupklsh, 7, 11),
4430e076 10617GEN_VXFORM_207(vupklsw, 7, 27),
5c55ff99
BS
10618GEN_VXFORM_NOA(vupkhpx, 7, 13),
10619GEN_VXFORM_NOA(vupklpx, 7, 15),
10620GEN_VXFORM_NOA(vrefp, 5, 4),
10621GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10622GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99 10623GEN_VXFORM_NOA(vlogefp, 5, 7),
abe60a43
TM
10624GEN_VXFORM_NOA(vrfim, 5, 11),
10625GEN_VXFORM_NOA(vrfin, 5, 8),
5c55ff99 10626GEN_VXFORM_NOA(vrfip, 5, 10),
abe60a43 10627GEN_VXFORM_NOA(vrfiz, 5, 9),
5c55ff99
BS
10628
10629#undef GEN_VXFORM_UIMM
10630#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10631 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10632GEN_VXFORM_UIMM(vspltb, 6, 8),
10633GEN_VXFORM_UIMM(vsplth, 6, 9),
10634GEN_VXFORM_UIMM(vspltw, 6, 10),
10635GEN_VXFORM_UIMM(vcfux, 5, 12),
10636GEN_VXFORM_UIMM(vcfsx, 5, 13),
10637GEN_VXFORM_UIMM(vctuxs, 5, 14),
10638GEN_VXFORM_UIMM(vctsxs, 5, 15),
10639
10640#undef GEN_VAFORM_PAIRED
10641#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10642 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10643GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10644GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10645GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10646GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10647GEN_VAFORM_PAIRED(vsel, vperm, 21),
10648GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10649
e13500b3
TM
10650GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10651GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10652GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10653GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10654
4d82038e 10655GEN_VXFORM_207(vbpermq, 6, 21),
f1064f61 10656GEN_VXFORM_207(vgbbd, 6, 20),
b8476fc7
TM
10657GEN_VXFORM_207(vpmsumb, 4, 16),
10658GEN_VXFORM_207(vpmsumh, 4, 17),
10659GEN_VXFORM_207(vpmsumw, 4, 18),
10660GEN_VXFORM_207(vpmsumd, 4, 19),
f293f04a 10661
557d52fa
TM
10662GEN_VXFORM_207(vsbox, 4, 23),
10663
10664GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10665GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10666
57354f8f
TM
10667GEN_VXFORM_207(vshasigmaw, 1, 26),
10668GEN_VXFORM_207(vshasigmad, 1, 27),
10669
ac174549
TM
10670GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10671
fa1832d7 10672GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10673GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10674GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10675GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10676GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10677GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10678GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10679
9231ba9e 10680GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10681GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10682GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10683GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10684GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10685
f5c0f7f9
TM
10686GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10687GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10688GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10689#if defined(TARGET_PPC64)
10690GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10691GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10692#endif
10693
df020ce0
TM
10694#undef GEN_XX2FORM
10695#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10696GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10697GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10698
10699#undef GEN_XX3FORM
10700#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10701GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10702GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10703GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10704GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10705
8f60f8e2
AJ
10706#undef GEN_XX2IFORM
10707#define GEN_XX2IFORM(name, opc2, opc3, fl2) \
10708GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 1, PPC_NONE, fl2), \
10709GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 1, PPC_NONE, fl2), \
10710GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 1, PPC_NONE, fl2), \
10711GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 1, PPC_NONE, fl2)
10712
354a6dec
TM
10713#undef GEN_XX3_RC_FORM
10714#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10715GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10716GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10717GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10718GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10719GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10720GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10721GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10722GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10723
cd73f2c9
TM
10724#undef GEN_XX3FORM_DM
10725#define GEN_XX3FORM_DM(name, opc2, opc3) \
10726GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10727GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10728GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10729GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10730GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10731GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10732GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10733GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10734GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10735GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10736GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10737GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10738GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10739GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10740GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10741GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10742
df020ce0
TM
10743GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10744GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10745GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10746GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10747
be574920
TM
10748GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10749GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10750GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10751GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10752GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10753GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10754GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10755GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 10756
ee6e02c0
TM
10757GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10758GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 10759GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 10760GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 10761GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 10762GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 10763GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 10764GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 10765GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
10766GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10767GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10768GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10769GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10770GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10771GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10772GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10773GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
8f60f8e2
AJ
10774GEN_XX2IFORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10775GEN_XX2IFORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
10776GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10777GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568 10778GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
7ee19fb9 10779GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
ed8ac568 10780GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
7ee19fb9 10781GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
5177d2ca
TM
10782GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10783GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10784GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10785GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10786GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10787GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
10788GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10789GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10790GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10791GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10792GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 10793
3fd0aadf
TM
10794GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10795GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 10796GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 10797GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 10798GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
3d1140bf 10799GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
cea4e574 10800GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
968e76bc 10801GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
f53f81e0
TM
10802GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
10803GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
10804GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
10805GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
10806GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
10807GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
10808GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
10809GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
74698350
TM
10810GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
10811GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
3fd0aadf 10812
ee6e02c0
TM
10813GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10814GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 10815GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 10816GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 10817GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 10818GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 10819GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 10820GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 10821GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
10822GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10823GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10824GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10825GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10826GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10827GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10828GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10829GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
10830GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10831GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
10832GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10833GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10834GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 10835GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
10836GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10837GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10838GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10839GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10840GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10841GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10842GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10843GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
10844GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10845GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10846GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10847GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10848GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
10849
10850GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10851GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 10852GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 10853GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 10854GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 10855GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 10856GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 10857GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 10858GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
10859GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10860GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10861GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10862GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10863GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10864GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10865GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10866GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
10867GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10868GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
10869GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10870GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10871GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 10872GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
10873GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10874GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10875GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10876GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10877GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10878GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10879GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10880GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
10881GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10882GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10883GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10884GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10885GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 10886
79ca8a6a
TM
10887#undef VSX_LOGICAL
10888#define VSX_LOGICAL(name, opc2, opc3, fl2) \
10889GEN_XX3FORM(name, opc2, opc3, fl2)
10890
10891VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10892VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10893VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10894VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10895VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
67a33f37
TM
10896VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
10897VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
10898VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
ce577d2e
TM
10899GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10900GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 10901GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 10902GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 10903
551e3ef7
TM
10904#define GEN_XXSEL_ROW(opc3) \
10905GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10906GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10907GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10908GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10909GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10910GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10911GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10912GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10913
10914GEN_XXSEL_ROW(0x00)
10915GEN_XXSEL_ROW(0x01)
10916GEN_XXSEL_ROW(0x02)
10917GEN_XXSEL_ROW(0x03)
10918GEN_XXSEL_ROW(0x04)
10919GEN_XXSEL_ROW(0x05)
10920GEN_XXSEL_ROW(0x06)
10921GEN_XXSEL_ROW(0x07)
10922GEN_XXSEL_ROW(0x08)
10923GEN_XXSEL_ROW(0x09)
10924GEN_XXSEL_ROW(0x0A)
10925GEN_XXSEL_ROW(0x0B)
10926GEN_XXSEL_ROW(0x0C)
10927GEN_XXSEL_ROW(0x0D)
10928GEN_XXSEL_ROW(0x0E)
10929GEN_XXSEL_ROW(0x0F)
10930GEN_XXSEL_ROW(0x10)
10931GEN_XXSEL_ROW(0x11)
10932GEN_XXSEL_ROW(0x12)
10933GEN_XXSEL_ROW(0x13)
10934GEN_XXSEL_ROW(0x14)
10935GEN_XXSEL_ROW(0x15)
10936GEN_XXSEL_ROW(0x16)
10937GEN_XXSEL_ROW(0x17)
10938GEN_XXSEL_ROW(0x18)
10939GEN_XXSEL_ROW(0x19)
10940GEN_XXSEL_ROW(0x1A)
10941GEN_XXSEL_ROW(0x1B)
10942GEN_XXSEL_ROW(0x1C)
10943GEN_XXSEL_ROW(0x1D)
10944GEN_XXSEL_ROW(0x1E)
10945GEN_XXSEL_ROW(0x1F)
10946
cd73f2c9
TM
10947GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
10948
275e35c6
TM
10949#undef GEN_DFP_T_A_B_Rc
10950#undef GEN_DFP_BF_A_B
10951#undef GEN_DFP_BF_A_DCM
10952#undef GEN_DFP_T_B_U32_U32_Rc
10953#undef GEN_DFP_T_A_B_I32_Rc
10954#undef GEN_DFP_T_B_Rc
10955#undef GEN_DFP_T_FPR_I32_Rc
10956
10957#define _GEN_DFP_LONG(name, op1, op2, mask) \
10958GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
10959
10960#define _GEN_DFP_LONGx2(name, op1, op2, mask) \
10961GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10962GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10963
10964#define _GEN_DFP_LONGx4(name, op1, op2, mask) \
10965GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10966GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10967GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10968GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10969
10970#define _GEN_DFP_QUAD(name, op1, op2, mask) \
10971GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
10972
10973#define _GEN_DFP_QUADx2(name, op1, op2, mask) \
10974GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10975GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10976
10977#define _GEN_DFP_QUADx4(name, op1, op2, mask) \
10978GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10979GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10980GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10981GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10982
10983#define GEN_DFP_T_A_B_Rc(name, op1, op2) \
10984_GEN_DFP_LONG(name, op1, op2, 0x00000000)
10985
10986#define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
10987_GEN_DFP_QUAD(name, op1, op2, 0x00210800)
10988
10989#define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
10990_GEN_DFP_QUAD(name, op1, op2, 0x00200800)
10991
10992#define GEN_DFP_T_B_Rc(name, op1, op2) \
10993_GEN_DFP_LONG(name, op1, op2, 0x001F0000)
10994
10995#define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
10996_GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
10997
10998#define GEN_DFP_Tp_B_Rc(name, op1, op2) \
10999_GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
11000
11001#define GEN_DFP_T_Bp_Rc(name, op1, op2) \
11002_GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
11003
11004#define GEN_DFP_BF_A_B(name, op1, op2) \
11005_GEN_DFP_LONG(name, op1, op2, 0x00000001)
11006
11007#define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
11008_GEN_DFP_QUAD(name, op1, op2, 0x00610801)
11009
11010#define GEN_DFP_BF_A_Bp(name, op1, op2) \
11011_GEN_DFP_QUAD(name, op1, op2, 0x00600801)
11012
11013#define GEN_DFP_BF_A_DCM(name, op1, op2) \
11014_GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
11015
11016#define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
11017_GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
11018
11019#define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
11020_GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11021
11022#define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
11023_GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
11024
11025#define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
11026_GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
11027
11028#define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
11029_GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11030
11031#define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
11032_GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
11033
11034#define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
11035_GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
11036
11037#define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
11038_GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
11039
11040#define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
11041_GEN_DFP_LONG(name, op1, op2, 0x00070000)
11042
11043#define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
11044_GEN_DFP_QUAD(name, op1, op2, 0x00270800)
11045
11046#define GEN_DFP_S_T_B_Rc(name, op1, op2) \
11047_GEN_DFP_LONG(name, op1, op2, 0x000F0000)
11048
11049#define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
11050_GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
11051
11052#define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
11053_GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
11054
11055#define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
11056_GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
11057
a9d7ba03
TM
11058GEN_DFP_T_A_B_Rc(dadd, 0x02, 0x00),
11059GEN_DFP_Tp_Ap_Bp_Rc(daddq, 0x02, 0x00),
2128f8a5
TM
11060GEN_DFP_T_A_B_Rc(dsub, 0x02, 0x10),
11061GEN_DFP_Tp_Ap_Bp_Rc(dsubq, 0x02, 0x10),
8de6a1cc
TM
11062GEN_DFP_T_A_B_Rc(dmul, 0x02, 0x01),
11063GEN_DFP_Tp_Ap_Bp_Rc(dmulq, 0x02, 0x01),
9024ff40
TM
11064GEN_DFP_T_A_B_Rc(ddiv, 0x02, 0x11),
11065GEN_DFP_Tp_Ap_Bp_Rc(ddivq, 0x02, 0x11),
5833505b
TM
11066GEN_DFP_BF_A_B(dcmpu, 0x02, 0x14),
11067GEN_DFP_BF_Ap_Bp(dcmpuq, 0x02, 0x14),
11068GEN_DFP_BF_A_B(dcmpo, 0x02, 0x04),
11069GEN_DFP_BF_Ap_Bp(dcmpoq, 0x02, 0x04),
e601c1ee
TM
11070GEN_DFP_BF_A_DCM(dtstdc, 0x02, 0x06),
11071GEN_DFP_BF_Ap_DCM(dtstdcq, 0x02, 0x06),
1bf9c0e1
TM
11072GEN_DFP_BF_A_DCM(dtstdg, 0x02, 0x07),
11073GEN_DFP_BF_Ap_DCM(dtstdgq, 0x02, 0x07),
f3d2b0bc
TM
11074GEN_DFP_BF_A_B(dtstex, 0x02, 0x05),
11075GEN_DFP_BF_Ap_Bp(dtstexq, 0x02, 0x05),
f6022a76
TM
11076GEN_DFP_BF_A_B(dtstsf, 0x02, 0x15),
11077GEN_DFP_BF_A_Bp(dtstsfq, 0x02, 0x15),
5826ebe2
TM
11078GEN_DFP_TE_T_B_RMC_Rc(dquai, 0x03, 0x02),
11079GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq, 0x03, 0x02),
11080GEN_DFP_T_A_B_RMC_Rc(dqua, 0x03, 0x00),
11081GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq, 0x03, 0x00),
512918aa
TM
11082GEN_DFP_T_A_B_RMC_Rc(drrnd, 0x03, 0x01),
11083GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq, 0x03, 0x01),
97c0d930
TM
11084GEN_DFP_R_T_B_RMC_Rc(drintx, 0x03, 0x03),
11085GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq, 0x03, 0x03),
11086GEN_DFP_R_T_B_RMC_Rc(drintn, 0x03, 0x07),
11087GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq, 0x03, 0x07),
290d9ee5
TM
11088GEN_DFP_T_B_Rc(dctdp, 0x02, 0x08),
11089GEN_DFP_Tp_B_Rc(dctqpq, 0x02, 0x08),
ca603eb4
TM
11090GEN_DFP_T_B_Rc(drsp, 0x02, 0x18),
11091GEN_DFP_Tp_Bp_Rc(drdpq, 0x02, 0x18),
f1214193
TM
11092GEN_DFP_T_B_Rc(dcffix, 0x02, 0x19),
11093GEN_DFP_Tp_B_Rc(dcffixq, 0x02, 0x19),
bea0dd79
TM
11094GEN_DFP_T_B_Rc(dctfix, 0x02, 0x09),
11095GEN_DFP_T_Bp_Rc(dctfixq, 0x02, 0x09),
7796676f
TM
11096GEN_DFP_SP_T_B_Rc(ddedpd, 0x02, 0x0a),
11097GEN_DFP_SP_Tp_Bp_Rc(ddedpdq, 0x02, 0x0a),
013c3ac0
TM
11098GEN_DFP_S_T_B_Rc(denbcd, 0x02, 0x1a),
11099GEN_DFP_S_Tp_Bp_Rc(denbcdq, 0x02, 0x1a),
e8a48460
TM
11100GEN_DFP_T_B_Rc(dxex, 0x02, 0x0b),
11101GEN_DFP_T_Bp_Rc(dxexq, 0x02, 0x0b),
297666eb
TM
11102GEN_DFP_T_A_B_Rc(diex, 0x02, 0x1b),
11103GEN_DFP_Tp_A_Bp_Rc(diexq, 0x02, 0x1b),
804e654a
TM
11104GEN_DFP_T_A_SH_Rc(dscli, 0x02, 0x02),
11105GEN_DFP_Tp_Ap_SH_Rc(dscliq, 0x02, 0x02),
11106GEN_DFP_T_A_SH_Rc(dscri, 0x02, 0x03),
11107GEN_DFP_Tp_Ap_SH_Rc(dscriq, 0x02, 0x03),
11108
5c55ff99 11109#undef GEN_SPE
70560da7
FC
11110#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11111 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11112GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11113GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11114GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11115GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11116GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11117GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11118GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11119GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
11120GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
11121GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11122GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11123GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11124GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11125GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11126GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11127GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
11128GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11129GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11130GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11131GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11132GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11133GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11134GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11135GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11136GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11137GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11138GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11139GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11140GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
11141
11142GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11143GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11144GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11145GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11146GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11147GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11148GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11149GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11150GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11151GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11152GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11153GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11154GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11155GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11156
11157GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11158GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11159GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11160GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11161GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11162GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11163GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11164GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11165GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11166GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11167GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11168GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11169GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11170GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11171
11172GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11173GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11174GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11175GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11176GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11177GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11178GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11179GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11180GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11181GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11182GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11183GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11184GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11185GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11186GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11187GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
11188
11189#undef GEN_SPEOP_LDST
11190#define GEN_SPEOP_LDST(name, opc2, sh) \
11191GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11192GEN_SPEOP_LDST(evldd, 0x00, 3),
11193GEN_SPEOP_LDST(evldw, 0x01, 3),
11194GEN_SPEOP_LDST(evldh, 0x02, 3),
11195GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11196GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11197GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11198GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11199GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11200GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11201GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11202GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11203
11204GEN_SPEOP_LDST(evstdd, 0x10, 3),
11205GEN_SPEOP_LDST(evstdw, 0x11, 3),
11206GEN_SPEOP_LDST(evstdh, 0x12, 3),
11207GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11208GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11209GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11210GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
0ff93d11
TM
11211
11212GEN_HANDLER2_E(tbegin, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
11213 PPC_NONE, PPC2_TM),
56a84615
TM
11214GEN_HANDLER2_E(tend, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
11215 PPC_NONE, PPC2_TM),
11216GEN_HANDLER2_E(tabort, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
11217 PPC_NONE, PPC2_TM),
11218GEN_HANDLER2_E(tabortwc, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
11219 PPC_NONE, PPC2_TM),
11220GEN_HANDLER2_E(tabortwci, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
11221 PPC_NONE, PPC2_TM),
11222GEN_HANDLER2_E(tabortdc, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
11223 PPC_NONE, PPC2_TM),
11224GEN_HANDLER2_E(tabortdci, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
11225 PPC_NONE, PPC2_TM),
11226GEN_HANDLER2_E(tsr, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
11227 PPC_NONE, PPC2_TM),
aeedd582
TM
11228GEN_HANDLER2_E(tcheck, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
11229 PPC_NONE, PPC2_TM),
f83c2378
TM
11230GEN_HANDLER2_E(treclaim, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
11231 PPC_NONE, PPC2_TM),
11232GEN_HANDLER2_E(trechkpt, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
11233 PPC_NONE, PPC2_TM),
5c55ff99
BS
11234};
11235
0411a972 11236#include "helper_regs.h"
a1389542 11237#include "translate_init.c"
79aceca5 11238
9a64fbe4 11239/*****************************************************************************/
3fc6c082 11240/* Misc PowerPC helpers */
878096ee
AF
11241void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11242 int flags)
79aceca5 11243{
3fc6c082
FB
11244#define RGPL 4
11245#define RFPL 4
3fc6c082 11246
878096ee
AF
11247 PowerPCCPU *cpu = POWERPC_CPU(cs);
11248 CPUPPCState *env = &cpu->env;
79aceca5
FB
11249 int i;
11250
90e189ec 11251 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
21e5d28a
TG
11252 TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
11253 env->nip, env->lr, env->ctr, cpu_read_xer(env),
11254 cs->cpu_index);
90e189ec 11255 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
9fb04491
BH
11256 TARGET_FMT_lx " iidx %d didx %d\n",
11257 env->msr, env->spr[SPR_HID0],
11258 env->hflags, env->immu_idx, env->dmmu_idx);
d9bce9d9 11259#if !defined(NO_TIMER_DUMP)
9a78eead 11260 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 11261#if !defined(CONFIG_USER_ONLY)
9a78eead 11262 " DECR %08" PRIu32
76a66253
JM
11263#endif
11264 "\n",
077fc206 11265 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
11266#if !defined(CONFIG_USER_ONLY)
11267 , cpu_ppc_load_decr(env)
11268#endif
11269 );
077fc206 11270#endif
76a66253 11271 for (i = 0; i < 32; i++) {
3fc6c082
FB
11272 if ((i & (RGPL - 1)) == 0)
11273 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 11274 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 11275 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 11276 cpu_fprintf(f, "\n");
76a66253 11277 }
3fc6c082 11278 cpu_fprintf(f, "CR ");
76a66253 11279 for (i = 0; i < 8; i++)
7fe48483
FB
11280 cpu_fprintf(f, "%01x", env->crf[i]);
11281 cpu_fprintf(f, " [");
76a66253
JM
11282 for (i = 0; i < 8; i++) {
11283 char a = '-';
11284 if (env->crf[i] & 0x08)
11285 a = 'L';
11286 else if (env->crf[i] & 0x04)
11287 a = 'G';
11288 else if (env->crf[i] & 0x02)
11289 a = 'E';
7fe48483 11290 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 11291 }
90e189ec
BS
11292 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11293 env->reserve_addr);
3fc6c082
FB
11294 for (i = 0; i < 32; i++) {
11295 if ((i & (RFPL - 1)) == 0)
11296 cpu_fprintf(f, "FPR%02d", i);
26a76461 11297 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 11298 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 11299 cpu_fprintf(f, "\n");
79aceca5 11300 }
30304420 11301 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 11302#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
11303 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11304 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11305 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11306 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11307
11308 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11309 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11310 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11311 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11312
11313 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11314 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11315 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11316 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11317
11318 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11319 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11320 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11321 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11322 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11323
11324 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11325 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11326 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11327 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11328
11329 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11330 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11331 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11332 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11333
11334 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11335 " EPR " TARGET_FMT_lx "\n",
11336 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11337 env->spr[SPR_BOOKE_EPR]);
11338
11339 /* FSL-specific */
11340 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11341 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11342 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11343 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11344
11345 /*
11346 * IVORs are left out as they are large and do not change often --
11347 * they can be read with "p $ivor0", "p $ivor1", etc.
11348 */
11349 }
11350
697ab892
DG
11351#if defined(TARGET_PPC64)
11352 if (env->flags & POWERPC_FLAG_CFAR) {
11353 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11354 }
11355#endif
11356
90dc8812
SW
11357 switch (env->mmu_model) {
11358 case POWERPC_MMU_32B:
11359 case POWERPC_MMU_601:
11360 case POWERPC_MMU_SOFT_6xx:
11361 case POWERPC_MMU_SOFT_74xx:
11362#if defined(TARGET_PPC64)
90dc8812 11363 case POWERPC_MMU_64B:
aa4bb587 11364 case POWERPC_MMU_2_03:
ca480de6 11365 case POWERPC_MMU_2_06:
808bc3b0 11366 case POWERPC_MMU_2_06a:
aa4bb587 11367 case POWERPC_MMU_2_07:
808bc3b0 11368 case POWERPC_MMU_2_07a:
90dc8812 11369#endif
ca480de6
AB
11370 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11371 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11372 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 11373 break;
01662f3e 11374 case POWERPC_MMU_BOOKE206:
90dc8812
SW
11375 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11376 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11377 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11378 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11379
11380 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11381 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11382 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11383 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11384
11385 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11386 " TLB1CFG " TARGET_FMT_lx "\n",
11387 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11388 env->spr[SPR_BOOKE_TLB1CFG]);
11389 break;
11390 default:
11391 break;
11392 }
f2e63a42 11393#endif
79aceca5 11394
3fc6c082
FB
11395#undef RGPL
11396#undef RFPL
79aceca5
FB
11397}
11398
878096ee
AF
11399void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11400 fprintf_function cpu_fprintf, int flags)
76a66253
JM
11401{
11402#if defined(DO_PPC_STATISTICS)
878096ee 11403 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 11404 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
11405 int op1, op2, op3;
11406
878096ee 11407 t1 = cpu->env.opcodes;
76a66253
JM
11408 for (op1 = 0; op1 < 64; op1++) {
11409 handler = t1[op1];
11410 if (is_indirect_opcode(handler)) {
11411 t2 = ind_table(handler);
11412 for (op2 = 0; op2 < 32; op2++) {
11413 handler = t2[op2];
11414 if (is_indirect_opcode(handler)) {
11415 t3 = ind_table(handler);
11416 for (op3 = 0; op3 < 32; op3++) {
11417 handler = t3[op3];
11418 if (handler->count == 0)
11419 continue;
11420 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 11421 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11422 op1, op2, op3, op1, (op3 << 5) | op2,
11423 handler->oname,
11424 handler->count, handler->count);
11425 }
11426 } else {
11427 if (handler->count == 0)
11428 continue;
11429 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 11430 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11431 op1, op2, op1, op2, handler->oname,
11432 handler->count, handler->count);
11433 }
11434 }
11435 } else {
11436 if (handler->count == 0)
11437 continue;
0bfcd599
BS
11438 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11439 " %" PRId64 "\n",
76a66253
JM
11440 op1, op1, handler->oname,
11441 handler->count, handler->count);
11442 }
11443 }
11444#endif
11445}
11446
9a64fbe4 11447/*****************************************************************************/
4e5e1215 11448void gen_intermediate_code(CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11449{
4e5e1215 11450 PowerPCCPU *cpu = ppc_env_get_cpu(env);
ed2803da 11451 CPUState *cs = CPU(cpu);
9fddaa0c 11452 DisasContext ctx, *ctxp = &ctx;
c227f099 11453 opc_handler_t **table, *handler;
0fa85d43 11454 target_ulong pc_start;
2e70f6ef
PB
11455 int num_insns;
11456 int max_insns;
79aceca5
FB
11457
11458 pc_start = tb->pc;
046d6672 11459 ctx.nip = pc_start;
79aceca5 11460 ctx.tb = tb;
e1833e1f 11461 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 11462 ctx.spr_cb = env->spr_cb;
c47493f2
PB
11463 ctx.pr = msr_pr;
11464 ctx.hv = !msr_pr && msr_hv;
9fb04491 11465 ctx.mem_idx = env->dmmu_idx;
7d08d856
AJ
11466 ctx.insns_flags = env->insns_flags;
11467 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
11468 ctx.access_type = -1;
11469 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
e22c357b 11470 ctx.default_tcg_memop_mask = ctx.le_mode ? MO_LE : MO_BE;
d9bce9d9 11471#if defined(TARGET_PPC64)
e42a61f1 11472 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 11473 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 11474#endif
3cc62370 11475 ctx.fpu_enabled = msr_fp;
a9d9eb8f 11476 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
11477 ctx.spe_enabled = msr_spe;
11478 else
11479 ctx.spe_enabled = 0;
a9d9eb8f
JM
11480 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11481 ctx.altivec_enabled = msr_vr;
11482 else
11483 ctx.altivec_enabled = 0;
1f29871c
TM
11484 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11485 ctx.vsx_enabled = msr_vsx;
11486 } else {
11487 ctx.vsx_enabled = 0;
11488 }
69d1a937
TM
11489#if defined(TARGET_PPC64)
11490 if ((env->flags & POWERPC_FLAG_TM) && msr_tm) {
11491 ctx.tm_enabled = msr_tm;
11492 } else {
11493 ctx.tm_enabled = 0;
11494 }
11495#endif
d26bfc9a 11496 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 11497 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 11498 else
8cbcb4fa 11499 ctx.singlestep_enabled = 0;
d26bfc9a 11500 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 11501 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 11502 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 11503 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 11504 }
3fc6c082 11505#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
11506 /* Single step trace mode */
11507 msr_se = 1;
11508#endif
2e70f6ef
PB
11509 num_insns = 0;
11510 max_insns = tb->cflags & CF_COUNT_MASK;
190ce7fb 11511 if (max_insns == 0) {
2e70f6ef 11512 max_insns = CF_COUNT_MASK;
190ce7fb
RH
11513 }
11514 if (max_insns > TCG_MAX_INSNS) {
11515 max_insns = TCG_MAX_INSNS;
11516 }
2e70f6ef 11517
cd42d5b2 11518 gen_tb_start(tb);
3de31797 11519 tcg_clear_temp_count();
9a64fbe4 11520 /* Set env in case of segfault during code fetch */
fe700adb 11521 while (ctx.exception == POWERPC_EXCP_NONE && !tcg_op_buf_full()) {
667b8e29 11522 tcg_gen_insn_start(ctx.nip);
959082fc 11523 num_insns++;
667b8e29 11524
b933066a
RH
11525 if (unlikely(cpu_breakpoint_test(cs, ctx.nip, BP_ANY))) {
11526 gen_debug_exception(ctxp);
522a0d4e
RH
11527 /* The address covered by the breakpoint must be included in
11528 [tb->pc, tb->pc + tb->size) in order to for it to be
11529 properly cleared -- thus we increment the PC here so that
11530 the logic setting tb->size below does the right thing. */
11531 ctx.nip += 4;
b933066a
RH
11532 break;
11533 }
11534
d12d51d5 11535 LOG_DISAS("----------------\n");
90e189ec 11536 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 11537 ctx.nip, ctx.mem_idx, (int)msr_ir);
959082fc 11538 if (num_insns == max_insns && (tb->cflags & CF_LAST_IO))
2e70f6ef 11539 gen_io_start();
e22c357b 11540 if (unlikely(need_byteswap(&ctx))) {
2f5a189c 11541 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 11542 } else {
2f5a189c 11543 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 11544 }
d12d51d5 11545 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 11546 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 11547 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
046d6672 11548 ctx.nip += 4;
3fc6c082 11549 table = env->opcodes;
79aceca5
FB
11550 handler = table[opc1(ctx.opcode)];
11551 if (is_indirect_opcode(handler)) {
11552 table = ind_table(handler);
11553 handler = table[opc2(ctx.opcode)];
11554 if (is_indirect_opcode(handler)) {
11555 table = ind_table(handler);
11556 handler = table[opc3(ctx.opcode)];
11557 }
11558 }
11559 /* Is opcode *REALLY* valid ? */
76a66253 11560 if (unlikely(handler->handler == &gen_invalid)) {
48880da6
PB
11561 qemu_log_mask(LOG_GUEST_ERROR, "invalid/unsupported opcode: "
11562 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11563 opc1(ctx.opcode), opc2(ctx.opcode),
11564 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
76a66253 11565 } else {
70560da7
FC
11566 uint32_t inval;
11567
11568 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11569 inval = handler->inval2;
11570 } else {
11571 inval = handler->inval1;
11572 }
11573
11574 if (unlikely((ctx.opcode & inval) != 0)) {
48880da6
PB
11575 qemu_log_mask(LOG_GUEST_ERROR, "invalid bits: %08x for opcode: "
11576 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
11577 ctx.opcode & inval, opc1(ctx.opcode),
11578 opc2(ctx.opcode), opc3(ctx.opcode),
11579 ctx.opcode, ctx.nip - 4);
e06fcd75 11580 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 11581 break;
79aceca5 11582 }
79aceca5 11583 }
4b3686fa 11584 (*(handler->handler))(&ctx);
76a66253
JM
11585#if defined(DO_PPC_STATISTICS)
11586 handler->count++;
11587#endif
9a64fbe4 11588 /* Check trace mode exceptions */
8cbcb4fa
AJ
11589 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11590 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11591 ctx.exception != POWERPC_SYSCALL &&
11592 ctx.exception != POWERPC_EXCP_TRAP &&
11593 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 11594 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 11595 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 11596 (cs->singlestep_enabled) ||
1b530a6d 11597 singlestep ||
2e70f6ef 11598 num_insns >= max_insns)) {
d26bfc9a
JM
11599 /* if we reach a page boundary or are single stepping, stop
11600 * generation
11601 */
8dd4983c 11602 break;
76a66253 11603 }
3de31797
AG
11604 if (tcg_check_temp_count()) {
11605 fprintf(stderr, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11606 opc1(ctx.opcode), opc2(ctx.opcode), opc3(ctx.opcode),
11607 ctx.opcode);
11608 exit(1);
11609 }
3fc6c082 11610 }
2e70f6ef
PB
11611 if (tb->cflags & CF_LAST_IO)
11612 gen_io_end();
e1833e1f 11613 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 11614 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 11615 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 11616 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 11617 gen_debug_exception(ctxp);
8cbcb4fa 11618 }
76a66253 11619 /* Generate the return instruction */
57fec1fe 11620 tcg_gen_exit_tb(0);
9a64fbe4 11621 }
806f352d 11622 gen_tb_end(tb, num_insns);
0a7df5da 11623
4e5e1215
RH
11624 tb->size = ctx.nip - pc_start;
11625 tb->icount = num_insns;
11626
d9bce9d9 11627#if defined(DEBUG_DISAS)
8fec2b8c 11628 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 11629 int flags;
237c0af0 11630 flags = env->bfd_mach;
76db3ba4 11631 flags |= ctx.le_mode << 16;
93fcfe39 11632 qemu_log("IN: %s\n", lookup_symbol(pc_start));
d49190c4 11633 log_target_disas(cs, pc_start, ctx.nip - pc_start, flags);
93fcfe39 11634 qemu_log("\n");
9fddaa0c 11635 }
79aceca5 11636#endif
79aceca5
FB
11637}
11638
bad729e2
RH
11639void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb,
11640 target_ulong *data)
d2856f1a 11641{
bad729e2 11642 env->nip = data[0];
d2856f1a 11643}