]> git.proxmox.com Git - mirror_qemu.git/blame - target-ppc/translate.c
ppc: Fix tlb invalidations on 6xx/7xx/7xxx 32-bit processors
[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
b68e60e6
BH
1395#if defined(TARGET_PPC64)
1396static void gen_pause(DisasContext *ctx)
1397{
1398 TCGv_i32 t0 = tcg_const_i32(0);
1399 tcg_gen_st_i32(t0, cpu_env,
1400 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
1401 tcg_temp_free_i32(t0);
1402
1403 /* Stop translation, this gives other CPUs a chance to run */
1404 gen_exception_err(ctx, EXCP_HLT, 1);
1405}
1406#endif /* defined(TARGET_PPC64) */
1407
54623277 1408/* or & or. */
99e300ef 1409static void gen_or(DisasContext *ctx)
9a64fbe4 1410{
76a66253
JM
1411 int rs, ra, rb;
1412
1413 rs = rS(ctx->opcode);
1414 ra = rA(ctx->opcode);
1415 rb = rB(ctx->opcode);
1416 /* Optimisation for mr. ri case */
1417 if (rs != ra || rs != rb) {
26d67362
AJ
1418 if (rs != rb)
1419 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1420 else
1421 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1422 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1423 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1424 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1425 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1426#if defined(TARGET_PPC64)
1427 } else {
26d67362
AJ
1428 int prio = 0;
1429
c80f84e3
JM
1430 switch (rs) {
1431 case 1:
1432 /* Set process priority to low */
26d67362 1433 prio = 2;
c80f84e3
JM
1434 break;
1435 case 6:
1436 /* Set process priority to medium-low */
26d67362 1437 prio = 3;
c80f84e3
JM
1438 break;
1439 case 2:
1440 /* Set process priority to normal */
26d67362 1441 prio = 4;
c80f84e3 1442 break;
be147d08
JM
1443#if !defined(CONFIG_USER_ONLY)
1444 case 31:
c47493f2 1445 if (!ctx->pr) {
be147d08 1446 /* Set process priority to very low */
26d67362 1447 prio = 1;
be147d08
JM
1448 }
1449 break;
1450 case 5:
c47493f2 1451 if (!ctx->pr) {
be147d08 1452 /* Set process priority to medium-hight */
26d67362 1453 prio = 5;
be147d08
JM
1454 }
1455 break;
1456 case 3:
c47493f2 1457 if (!ctx->pr) {
be147d08 1458 /* Set process priority to high */
26d67362 1459 prio = 6;
be147d08
JM
1460 }
1461 break;
be147d08 1462 case 7:
b68e60e6 1463 if (ctx->hv && !ctx->pr) {
be147d08 1464 /* Set process priority to very high */
26d67362 1465 prio = 7;
be147d08
JM
1466 }
1467 break;
be147d08 1468#endif
c80f84e3
JM
1469 default:
1470 /* nop */
1471 break;
1472 }
26d67362 1473 if (prio) {
a7812ae4 1474 TCGv t0 = tcg_temp_new();
54cdcae6 1475 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1476 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1477 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1478 gen_store_spr(SPR_PPR, t0);
ea363694 1479 tcg_temp_free(t0);
b68e60e6
BH
1480 /* Pause us out of TCG otherwise spin loops with smt_low
1481 * eat too much CPU and the kernel hangs
1482 */
1483 gen_pause(ctx);
26d67362 1484 }
c80f84e3 1485#endif
9a64fbe4 1486 }
9a64fbe4 1487}
79aceca5 1488/* orc & orc. */
26d67362 1489GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1490
54623277 1491/* xor & xor. */
99e300ef 1492static void gen_xor(DisasContext *ctx)
9a64fbe4 1493{
9a64fbe4 1494 /* Optimisation for "set to zero" case */
26d67362 1495 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1496 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1497 else
1498 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1499 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1500 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1501}
99e300ef 1502
54623277 1503/* ori */
99e300ef 1504static void gen_ori(DisasContext *ctx)
79aceca5 1505{
76a66253 1506 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1507
9a64fbe4 1508 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
9a64fbe4 1509 return;
76a66253 1510 }
26d67362 1511 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1512}
99e300ef 1513
54623277 1514/* oris */
99e300ef 1515static void gen_oris(DisasContext *ctx)
79aceca5 1516{
76a66253 1517 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1518
9a64fbe4
FB
1519 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1520 /* NOP */
1521 return;
76a66253 1522 }
26d67362 1523 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1524}
99e300ef 1525
54623277 1526/* xori */
99e300ef 1527static void gen_xori(DisasContext *ctx)
79aceca5 1528{
76a66253 1529 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1530
1531 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1532 /* NOP */
1533 return;
1534 }
26d67362 1535 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1536}
99e300ef 1537
54623277 1538/* xoris */
99e300ef 1539static void gen_xoris(DisasContext *ctx)
79aceca5 1540{
76a66253 1541 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1542
1543 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1544 /* NOP */
1545 return;
1546 }
26d67362 1547 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1548}
99e300ef 1549
54623277 1550/* popcntb : PowerPC 2.03 specification */
99e300ef 1551static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1552{
eaabeef2
DG
1553 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1554}
1555
1556static void gen_popcntw(DisasContext *ctx)
1557{
1558 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1559}
1560
d9bce9d9 1561#if defined(TARGET_PPC64)
eaabeef2
DG
1562/* popcntd: PowerPC 2.06 specification */
1563static void gen_popcntd(DisasContext *ctx)
1564{
1565 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1566}
eaabeef2 1567#endif
d9bce9d9 1568
725bcec2
AJ
1569/* prtyw: PowerPC 2.05 specification */
1570static void gen_prtyw(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, 16);
1576 tcg_gen_xor_tl(ra, rs, t0);
1577 tcg_gen_shri_tl(t0, ra, 8);
1578 tcg_gen_xor_tl(ra, ra, t0);
1579 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1580 tcg_temp_free(t0);
1581}
1582
1583#if defined(TARGET_PPC64)
1584/* prtyd: PowerPC 2.05 specification */
1585static void gen_prtyd(DisasContext *ctx)
1586{
1587 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1588 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1589 TCGv t0 = tcg_temp_new();
1590 tcg_gen_shri_tl(t0, rs, 32);
1591 tcg_gen_xor_tl(ra, rs, t0);
1592 tcg_gen_shri_tl(t0, ra, 16);
1593 tcg_gen_xor_tl(ra, ra, t0);
1594 tcg_gen_shri_tl(t0, ra, 8);
1595 tcg_gen_xor_tl(ra, ra, t0);
1596 tcg_gen_andi_tl(ra, ra, 1);
1597 tcg_temp_free(t0);
1598}
1599#endif
1600
86ba37ed
TM
1601#if defined(TARGET_PPC64)
1602/* bpermd */
1603static void gen_bpermd(DisasContext *ctx)
1604{
1605 gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)],
1606 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1607}
1608#endif
1609
d9bce9d9
JM
1610#if defined(TARGET_PPC64)
1611/* extsw & extsw. */
26d67362 1612GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1613
54623277 1614/* cntlzd */
99e300ef 1615static void gen_cntlzd(DisasContext *ctx)
26d67362 1616{
a7812ae4 1617 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1618 if (unlikely(Rc(ctx->opcode) != 0))
1619 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1620}
d9bce9d9
JM
1621#endif
1622
79aceca5 1623/*** Integer rotate ***/
99e300ef 1624
54623277 1625/* rlwimi & rlwimi. */
99e300ef 1626static void gen_rlwimi(DisasContext *ctx)
79aceca5 1627{
63ae0915
RH
1628 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1629 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1630 uint32_t sh = SH(ctx->opcode);
1631 uint32_t mb = MB(ctx->opcode);
1632 uint32_t me = ME(ctx->opcode);
1633
1634 if (sh == (31-me) && mb <= me) {
1635 tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1);
d03ef511 1636 } else {
d03ef511 1637 target_ulong mask;
63ae0915 1638 TCGv_i32 t0;
a7812ae4 1639 TCGv t1;
63ae0915 1640
76a66253 1641#if defined(TARGET_PPC64)
d03ef511
AJ
1642 mb += 32;
1643 me += 32;
76a66253 1644#endif
d03ef511 1645 mask = MASK(mb, me);
63ae0915
RH
1646
1647 t0 = tcg_temp_new_i32();
a7812ae4 1648 t1 = tcg_temp_new();
63ae0915
RH
1649 tcg_gen_trunc_tl_i32(t0, t_rs);
1650 tcg_gen_rotli_i32(t0, t0, sh);
1651 tcg_gen_extu_i32_tl(t1, t0);
1652 tcg_temp_free_i32(t0);
1653
1654 tcg_gen_andi_tl(t1, t1, mask);
1655 tcg_gen_andi_tl(t_ra, t_ra, ~mask);
1656 tcg_gen_or_tl(t_ra, t_ra, t1);
d03ef511
AJ
1657 tcg_temp_free(t1);
1658 }
63ae0915
RH
1659 if (unlikely(Rc(ctx->opcode) != 0)) {
1660 gen_set_Rc0(ctx, t_ra);
1661 }
79aceca5 1662}
99e300ef 1663
54623277 1664/* rlwinm & rlwinm. */
99e300ef 1665static void gen_rlwinm(DisasContext *ctx)
79aceca5 1666{
63ae0915
RH
1667 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1668 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1669 uint32_t sh = SH(ctx->opcode);
1670 uint32_t mb = MB(ctx->opcode);
1671 uint32_t me = ME(ctx->opcode);
1672
1673 if (mb == 0 && me == (31 - sh)) {
1674 tcg_gen_shli_tl(t_ra, t_rs, sh);
1675 tcg_gen_ext32u_tl(t_ra, t_ra);
1676 } else if (sh != 0 && me == 31 && sh == (32 - mb)) {
1677 tcg_gen_ext32u_tl(t_ra, t_rs);
1678 tcg_gen_shri_tl(t_ra, t_ra, mb);
d03ef511 1679 } else {
76a66253 1680#if defined(TARGET_PPC64)
d03ef511
AJ
1681 mb += 32;
1682 me += 32;
76a66253 1683#endif
63ae0915
RH
1684 if (sh == 0) {
1685 tcg_gen_andi_tl(t_ra, t_rs, MASK(mb, me));
1686 } else {
1687 TCGv_i32 t0 = tcg_temp_new_i32();
1688
1689 tcg_gen_trunc_tl_i32(t0, t_rs);
1690 tcg_gen_rotli_i32(t0, t0, sh);
1691 tcg_gen_andi_i32(t0, t0, MASK(mb, me));
1692 tcg_gen_extu_i32_tl(t_ra, t0);
1693 tcg_temp_free_i32(t0);
1694 }
1695 }
1696 if (unlikely(Rc(ctx->opcode) != 0)) {
1697 gen_set_Rc0(ctx, t_ra);
d03ef511 1698 }
79aceca5 1699}
99e300ef 1700
54623277 1701/* rlwnm & rlwnm. */
99e300ef 1702static void gen_rlwnm(DisasContext *ctx)
79aceca5 1703{
63ae0915
RH
1704 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1705 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1706 TCGv t_rb = cpu_gpr[rB(ctx->opcode)];
1707 uint32_t mb = MB(ctx->opcode);
1708 uint32_t me = ME(ctx->opcode);
1709 TCGv_i32 t0, t1;
57fca134 1710
54843a58 1711#if defined(TARGET_PPC64)
63ae0915
RH
1712 mb += 32;
1713 me += 32;
54843a58 1714#endif
57fca134 1715
63ae0915
RH
1716 t0 = tcg_temp_new_i32();
1717 t1 = tcg_temp_new_i32();
1718 tcg_gen_trunc_tl_i32(t0, t_rb);
1719 tcg_gen_trunc_tl_i32(t1, t_rs);
1720 tcg_gen_andi_i32(t0, t0, 0x1f);
1721 tcg_gen_rotl_i32(t1, t1, t0);
1722 tcg_temp_free_i32(t0);
1723
1724 tcg_gen_andi_i32(t1, t1, MASK(mb, me));
1725 tcg_gen_extu_i32_tl(t_ra, t1);
1726 tcg_temp_free_i32(t1);
1727
1728 if (unlikely(Rc(ctx->opcode) != 0)) {
1729 gen_set_Rc0(ctx, t_ra);
79aceca5 1730 }
79aceca5
FB
1731}
1732
d9bce9d9
JM
1733#if defined(TARGET_PPC64)
1734#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1735static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1736{ \
1737 gen_##name(ctx, 0); \
1738} \
e8eaa2c0
BS
1739 \
1740static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1741{ \
1742 gen_##name(ctx, 1); \
1743}
1744#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1745static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1746{ \
1747 gen_##name(ctx, 0, 0); \
1748} \
e8eaa2c0
BS
1749 \
1750static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1751{ \
1752 gen_##name(ctx, 0, 1); \
1753} \
e8eaa2c0
BS
1754 \
1755static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1756{ \
1757 gen_##name(ctx, 1, 0); \
1758} \
e8eaa2c0
BS
1759 \
1760static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1761{ \
1762 gen_##name(ctx, 1, 1); \
1763}
51789c41 1764
a7b2c8b9 1765static void gen_rldinm(DisasContext *ctx, int mb, int me, int sh)
51789c41 1766{
a7b2c8b9
RH
1767 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1768 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1769
1770 if (sh != 0 && mb == 0 && me == (63 - sh)) {
1771 tcg_gen_shli_tl(t_ra, t_rs, sh);
1772 } else if (sh != 0 && me == 63 && sh == (64 - mb)) {
1773 tcg_gen_shri_tl(t_ra, t_rs, mb);
d03ef511 1774 } else {
a7b2c8b9
RH
1775 tcg_gen_rotli_tl(t_ra, t_rs, sh);
1776 tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me));
1777 }
1778 if (unlikely(Rc(ctx->opcode) != 0)) {
1779 gen_set_Rc0(ctx, t_ra);
51789c41 1780 }
51789c41 1781}
a7b2c8b9 1782
d9bce9d9 1783/* rldicl - rldicl. */
636aa200 1784static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1785{
51789c41 1786 uint32_t sh, mb;
d9bce9d9 1787
9d53c753
JM
1788 sh = SH(ctx->opcode) | (shn << 5);
1789 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1790 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1791}
51789c41 1792GEN_PPC64_R4(rldicl, 0x1E, 0x00);
a7b2c8b9 1793
d9bce9d9 1794/* rldicr - rldicr. */
636aa200 1795static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1796{
51789c41 1797 uint32_t sh, me;
d9bce9d9 1798
9d53c753
JM
1799 sh = SH(ctx->opcode) | (shn << 5);
1800 me = MB(ctx->opcode) | (men << 5);
51789c41 1801 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1802}
51789c41 1803GEN_PPC64_R4(rldicr, 0x1E, 0x02);
a7b2c8b9 1804
d9bce9d9 1805/* rldic - rldic. */
636aa200 1806static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1807{
51789c41 1808 uint32_t sh, mb;
d9bce9d9 1809
9d53c753
JM
1810 sh = SH(ctx->opcode) | (shn << 5);
1811 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1812 gen_rldinm(ctx, mb, 63 - sh, sh);
1813}
1814GEN_PPC64_R4(rldic, 0x1E, 0x04);
1815
a7b2c8b9 1816static void gen_rldnm(DisasContext *ctx, int mb, int me)
51789c41 1817{
a7b2c8b9
RH
1818 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1819 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1820 TCGv t_rb = cpu_gpr[rB(ctx->opcode)];
54843a58 1821 TCGv t0;
d03ef511 1822
a7812ae4 1823 t0 = tcg_temp_new();
a7b2c8b9
RH
1824 tcg_gen_andi_tl(t0, t_rb, 0x3f);
1825 tcg_gen_rotl_tl(t_ra, t_rs, t0);
54843a58 1826 tcg_temp_free(t0);
a7b2c8b9
RH
1827
1828 tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me));
1829 if (unlikely(Rc(ctx->opcode) != 0)) {
1830 gen_set_Rc0(ctx, t_ra);
1831 }
d9bce9d9 1832}
51789c41 1833
d9bce9d9 1834/* rldcl - rldcl. */
636aa200 1835static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1836{
51789c41 1837 uint32_t mb;
d9bce9d9 1838
9d53c753 1839 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1840 gen_rldnm(ctx, mb, 63);
d9bce9d9 1841}
36081602 1842GEN_PPC64_R2(rldcl, 0x1E, 0x08);
a7b2c8b9 1843
d9bce9d9 1844/* rldcr - rldcr. */
636aa200 1845static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1846{
51789c41 1847 uint32_t me;
d9bce9d9 1848
9d53c753 1849 me = MB(ctx->opcode) | (men << 5);
51789c41 1850 gen_rldnm(ctx, 0, me);
d9bce9d9 1851}
36081602 1852GEN_PPC64_R2(rldcr, 0x1E, 0x09);
a7b2c8b9 1853
d9bce9d9 1854/* rldimi - rldimi. */
a7b2c8b9 1855static void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1856{
a7b2c8b9
RH
1857 TCGv t_ra = cpu_gpr[rA(ctx->opcode)];
1858 TCGv t_rs = cpu_gpr[rS(ctx->opcode)];
1859 uint32_t sh = SH(ctx->opcode) | (shn << 5);
1860 uint32_t mb = MB(ctx->opcode) | (mbn << 5);
1861 uint32_t me = 63 - sh;
d9bce9d9 1862
a7b2c8b9
RH
1863 if (mb <= me) {
1864 tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1);
d03ef511 1865 } else {
a7b2c8b9
RH
1866 target_ulong mask = MASK(mb, me);
1867 TCGv t1 = tcg_temp_new();
d03ef511 1868
a7b2c8b9
RH
1869 tcg_gen_rotli_tl(t1, t_rs, sh);
1870 tcg_gen_andi_tl(t1, t1, mask);
1871 tcg_gen_andi_tl(t_ra, t_ra, ~mask);
1872 tcg_gen_or_tl(t_ra, t_ra, t1);
d03ef511 1873 tcg_temp_free(t1);
51789c41 1874 }
a7b2c8b9
RH
1875 if (unlikely(Rc(ctx->opcode) != 0)) {
1876 gen_set_Rc0(ctx, t_ra);
1877 }
d9bce9d9 1878}
36081602 1879GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1880#endif
1881
79aceca5 1882/*** Integer shift ***/
99e300ef 1883
54623277 1884/* slw & slw. */
99e300ef 1885static void gen_slw(DisasContext *ctx)
26d67362 1886{
7fd6bf7d 1887 TCGv t0, t1;
26d67362 1888
7fd6bf7d
AJ
1889 t0 = tcg_temp_new();
1890 /* AND rS with a mask that is 0 when rB >= 0x20 */
1891#if defined(TARGET_PPC64)
1892 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1893 tcg_gen_sari_tl(t0, t0, 0x3f);
1894#else
1895 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1896 tcg_gen_sari_tl(t0, t0, 0x1f);
1897#endif
1898 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1899 t1 = tcg_temp_new();
1900 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1901 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1902 tcg_temp_free(t1);
fea0c503 1903 tcg_temp_free(t0);
7fd6bf7d 1904 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1905 if (unlikely(Rc(ctx->opcode) != 0))
1906 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1907}
99e300ef 1908
54623277 1909/* sraw & sraw. */
99e300ef 1910static void gen_sraw(DisasContext *ctx)
26d67362 1911{
d15f74fb 1912 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1913 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1914 if (unlikely(Rc(ctx->opcode) != 0))
1915 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1916}
99e300ef 1917
54623277 1918/* srawi & srawi. */
99e300ef 1919static void gen_srawi(DisasContext *ctx)
79aceca5 1920{
26d67362 1921 int sh = SH(ctx->opcode);
ba4af3e4
RH
1922 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1923 TCGv src = cpu_gpr[rS(ctx->opcode)];
1924 if (sh == 0) {
34a0fad1 1925 tcg_gen_ext32s_tl(dst, src);
da91a00f 1926 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1927 } else {
ba4af3e4
RH
1928 TCGv t0;
1929 tcg_gen_ext32s_tl(dst, src);
1930 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1931 t0 = tcg_temp_new();
1932 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1933 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1934 tcg_temp_free(t0);
1935 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1936 tcg_gen_sari_tl(dst, dst, sh);
1937 }
1938 if (unlikely(Rc(ctx->opcode) != 0)) {
1939 gen_set_Rc0(ctx, dst);
d9bce9d9 1940 }
79aceca5 1941}
99e300ef 1942
54623277 1943/* srw & srw. */
99e300ef 1944static void gen_srw(DisasContext *ctx)
26d67362 1945{
fea0c503 1946 TCGv t0, t1;
d9bce9d9 1947
7fd6bf7d
AJ
1948 t0 = tcg_temp_new();
1949 /* AND rS with a mask that is 0 when rB >= 0x20 */
1950#if defined(TARGET_PPC64)
1951 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1952 tcg_gen_sari_tl(t0, t0, 0x3f);
1953#else
1954 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1955 tcg_gen_sari_tl(t0, t0, 0x1f);
1956#endif
1957 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1958 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1959 t1 = tcg_temp_new();
7fd6bf7d
AJ
1960 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1961 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1962 tcg_temp_free(t1);
fea0c503 1963 tcg_temp_free(t0);
26d67362
AJ
1964 if (unlikely(Rc(ctx->opcode) != 0))
1965 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1966}
54623277 1967
d9bce9d9
JM
1968#if defined(TARGET_PPC64)
1969/* sld & sld. */
99e300ef 1970static void gen_sld(DisasContext *ctx)
26d67362 1971{
7fd6bf7d 1972 TCGv t0, t1;
26d67362 1973
7fd6bf7d
AJ
1974 t0 = tcg_temp_new();
1975 /* AND rS with a mask that is 0 when rB >= 0x40 */
1976 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1977 tcg_gen_sari_tl(t0, t0, 0x3f);
1978 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1979 t1 = tcg_temp_new();
1980 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1981 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1982 tcg_temp_free(t1);
fea0c503 1983 tcg_temp_free(t0);
26d67362
AJ
1984 if (unlikely(Rc(ctx->opcode) != 0))
1985 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1986}
99e300ef 1987
54623277 1988/* srad & srad. */
99e300ef 1989static void gen_srad(DisasContext *ctx)
26d67362 1990{
d15f74fb 1991 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1992 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1993 if (unlikely(Rc(ctx->opcode) != 0))
1994 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1995}
d9bce9d9 1996/* sradi & sradi. */
636aa200 1997static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1998{
26d67362 1999 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
2000 TCGv dst = cpu_gpr[rA(ctx->opcode)];
2001 TCGv src = cpu_gpr[rS(ctx->opcode)];
2002 if (sh == 0) {
2003 tcg_gen_mov_tl(dst, src);
da91a00f 2004 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 2005 } else {
ba4af3e4
RH
2006 TCGv t0;
2007 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
2008 t0 = tcg_temp_new();
2009 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
2010 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
2011 tcg_temp_free(t0);
2012 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
2013 tcg_gen_sari_tl(dst, src, sh);
2014 }
2015 if (unlikely(Rc(ctx->opcode) != 0)) {
2016 gen_set_Rc0(ctx, dst);
d9bce9d9 2017 }
d9bce9d9 2018}
e8eaa2c0
BS
2019
2020static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
2021{
2022 gen_sradi(ctx, 0);
2023}
e8eaa2c0
BS
2024
2025static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
2026{
2027 gen_sradi(ctx, 1);
2028}
99e300ef 2029
54623277 2030/* srd & srd. */
99e300ef 2031static void gen_srd(DisasContext *ctx)
26d67362 2032{
7fd6bf7d 2033 TCGv t0, t1;
26d67362 2034
7fd6bf7d
AJ
2035 t0 = tcg_temp_new();
2036 /* AND rS with a mask that is 0 when rB >= 0x40 */
2037 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
2038 tcg_gen_sari_tl(t0, t0, 0x3f);
2039 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
2040 t1 = tcg_temp_new();
2041 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
2042 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
2043 tcg_temp_free(t1);
fea0c503 2044 tcg_temp_free(t0);
26d67362
AJ
2045 if (unlikely(Rc(ctx->opcode) != 0))
2046 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2047}
d9bce9d9 2048#endif
79aceca5 2049
4814f2d1
TM
2050#if defined(TARGET_PPC64)
2051static void gen_set_cr1_from_fpscr(DisasContext *ctx)
2052{
2053 TCGv_i32 tmp = tcg_temp_new_i32();
2054 tcg_gen_trunc_tl_i32(tmp, cpu_fpscr);
2055 tcg_gen_shri_i32(cpu_crf[1], tmp, 28);
2056 tcg_temp_free_i32(tmp);
2057}
2058#else
2059static void gen_set_cr1_from_fpscr(DisasContext *ctx)
2060{
2061 tcg_gen_shri_tl(cpu_crf[1], cpu_fpscr, 28);
2062}
2063#endif
2064
79aceca5 2065/*** Floating-Point arithmetic ***/
7c58044c 2066#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 2067static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2068{ \
76a66253 2069 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2070 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2071 return; \
2072 } \
eb44b959
AJ
2073 /* NIP cannot be restored if the memory exception comes from an helper */ \
2074 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2075 gen_reset_fpstatus(); \
8e703949
BS
2076 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2077 cpu_fpr[rA(ctx->opcode)], \
af12906f 2078 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2079 if (isfloat) { \
8e703949
BS
2080 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2081 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2082 } \
7d45556e
TM
2083 if (set_fprf) { \
2084 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2085 } \
00e6fd3e
TM
2086 if (unlikely(Rc(ctx->opcode) != 0)) { \
2087 gen_set_cr1_from_fpscr(ctx); \
2088 } \
9a64fbe4
FB
2089}
2090
7c58044c
JM
2091#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2092_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2093_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2094
7c58044c 2095#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2096static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2097{ \
76a66253 2098 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2099 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2100 return; \
2101 } \
eb44b959
AJ
2102 /* NIP cannot be restored if the memory exception comes from an helper */ \
2103 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2104 gen_reset_fpstatus(); \
8e703949
BS
2105 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2106 cpu_fpr[rA(ctx->opcode)], \
af12906f 2107 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2108 if (isfloat) { \
8e703949
BS
2109 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2110 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2111 } \
7d45556e
TM
2112 if (set_fprf) { \
2113 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2114 } \
00e6fd3e
TM
2115 if (unlikely(Rc(ctx->opcode) != 0)) { \
2116 gen_set_cr1_from_fpscr(ctx); \
2117 } \
9a64fbe4 2118}
7c58044c
JM
2119#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2120_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2121_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2122
7c58044c 2123#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2124static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2125{ \
76a66253 2126 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2127 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2128 return; \
2129 } \
eb44b959
AJ
2130 /* NIP cannot be restored if the memory exception comes from an helper */ \
2131 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2132 gen_reset_fpstatus(); \
8e703949
BS
2133 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2134 cpu_fpr[rA(ctx->opcode)], \
2135 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2136 if (isfloat) { \
8e703949
BS
2137 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2138 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2139 } \
7d45556e
TM
2140 if (set_fprf) { \
2141 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2142 } \
00e6fd3e
TM
2143 if (unlikely(Rc(ctx->opcode) != 0)) { \
2144 gen_set_cr1_from_fpscr(ctx); \
2145 } \
9a64fbe4 2146}
7c58044c
JM
2147#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2148_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2149_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2150
7c58044c 2151#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2152static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2153{ \
76a66253 2154 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2155 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2156 return; \
2157 } \
eb44b959
AJ
2158 /* NIP cannot be restored if the memory exception comes from an helper */ \
2159 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2160 gen_reset_fpstatus(); \
8e703949
BS
2161 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2162 cpu_fpr[rB(ctx->opcode)]); \
7d45556e
TM
2163 if (set_fprf) { \
2164 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2165 } \
00e6fd3e
TM
2166 if (unlikely(Rc(ctx->opcode) != 0)) { \
2167 gen_set_cr1_from_fpscr(ctx); \
2168 } \
79aceca5
FB
2169}
2170
7c58044c 2171#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2172static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2173{ \
76a66253 2174 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2175 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2176 return; \
2177 } \
eb44b959
AJ
2178 /* NIP cannot be restored if the memory exception comes from an helper */ \
2179 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2180 gen_reset_fpstatus(); \
8e703949
BS
2181 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2182 cpu_fpr[rB(ctx->opcode)]); \
7d45556e
TM
2183 if (set_fprf) { \
2184 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2185 } \
00e6fd3e
TM
2186 if (unlikely(Rc(ctx->opcode) != 0)) { \
2187 gen_set_cr1_from_fpscr(ctx); \
2188 } \
79aceca5
FB
2189}
2190
9a64fbe4 2191/* fadd - fadds */
7c58044c 2192GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2193/* fdiv - fdivs */
7c58044c 2194GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2195/* fmul - fmuls */
7c58044c 2196GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2197
d7e4b87e 2198/* fre */
7c58044c 2199GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2200
a750fc0b 2201/* fres */
7c58044c 2202GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2203
a750fc0b 2204/* frsqrte */
7c58044c
JM
2205GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2206
2207/* frsqrtes */
99e300ef 2208static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2209{
af12906f 2210 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2211 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2212 return;
2213 }
eb44b959
AJ
2214 /* NIP cannot be restored if the memory exception comes from an helper */
2215 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2216 gen_reset_fpstatus();
8e703949
BS
2217 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2218 cpu_fpr[rB(ctx->opcode)]);
2219 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2220 cpu_fpr[rD(ctx->opcode)]);
7d45556e 2221 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
00e6fd3e
TM
2222 if (unlikely(Rc(ctx->opcode) != 0)) {
2223 gen_set_cr1_from_fpscr(ctx);
2224 }
7c58044c 2225}
79aceca5 2226
a750fc0b 2227/* fsel */
7c58044c 2228_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2229/* fsub - fsubs */
7c58044c 2230GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2231/* Optional: */
99e300ef 2232
54623277 2233/* fsqrt */
99e300ef 2234static void gen_fsqrt(DisasContext *ctx)
c7d344af 2235{
76a66253 2236 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2237 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2238 return;
2239 }
eb44b959
AJ
2240 /* NIP cannot be restored if the memory exception comes from an helper */
2241 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2242 gen_reset_fpstatus();
8e703949
BS
2243 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2244 cpu_fpr[rB(ctx->opcode)]);
7d45556e 2245 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
00e6fd3e
TM
2246 if (unlikely(Rc(ctx->opcode) != 0)) {
2247 gen_set_cr1_from_fpscr(ctx);
2248 }
c7d344af 2249}
79aceca5 2250
99e300ef 2251static void gen_fsqrts(DisasContext *ctx)
79aceca5 2252{
76a66253 2253 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2254 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2255 return;
2256 }
eb44b959
AJ
2257 /* NIP cannot be restored if the memory exception comes from an helper */
2258 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2259 gen_reset_fpstatus();
8e703949
BS
2260 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2261 cpu_fpr[rB(ctx->opcode)]);
2262 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2263 cpu_fpr[rD(ctx->opcode)]);
7d45556e 2264 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]);
00e6fd3e
TM
2265 if (unlikely(Rc(ctx->opcode) != 0)) {
2266 gen_set_cr1_from_fpscr(ctx);
2267 }
79aceca5
FB
2268}
2269
2270/*** Floating-Point multiply-and-add ***/
4ecc3190 2271/* fmadd - fmadds */
7c58044c 2272GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2273/* fmsub - fmsubs */
7c58044c 2274GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2275/* fnmadd - fnmadds */
7c58044c 2276GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2277/* fnmsub - fnmsubs */
7c58044c 2278GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2279
2280/*** Floating-Point round & convert ***/
2281/* fctiw */
7c58044c 2282GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2283/* fctiwu */
2284GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2285/* fctiwz */
7c58044c 2286GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
fab7fe42
TM
2287/* fctiwuz */
2288GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206);
79aceca5 2289/* frsp */
7c58044c 2290GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db 2291/* fcfid */
4171853c 2292GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC2_FP_CVT_S64);
28288b48
TM
2293/* fcfids */
2294GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206);
2295/* fcfidu */
2296GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
2297/* fcfidus */
2298GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206);
426613db 2299/* fctid */
4171853c 2300GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC2_FP_CVT_S64);
fab7fe42
TM
2301/* fctidu */
2302GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206);
426613db 2303/* fctidz */
4171853c 2304GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC2_FP_CVT_S64);
fab7fe42
TM
2305/* fctidu */
2306GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206);
79aceca5 2307
d7e4b87e 2308/* frin */
7c58044c 2309GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2310/* friz */
7c58044c 2311GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2312/* frip */
7c58044c 2313GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2314/* frim */
7c58044c 2315GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2316
da29cb7b
TM
2317static void gen_ftdiv(DisasContext *ctx)
2318{
2319 if (unlikely(!ctx->fpu_enabled)) {
2320 gen_exception(ctx, POWERPC_EXCP_FPU);
2321 return;
2322 }
2323 gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2324 cpu_fpr[rB(ctx->opcode)]);
2325}
2326
6d41d146
TM
2327static void gen_ftsqrt(DisasContext *ctx)
2328{
2329 if (unlikely(!ctx->fpu_enabled)) {
2330 gen_exception(ctx, POWERPC_EXCP_FPU);
2331 return;
2332 }
2333 gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2334}
2335
da29cb7b
TM
2336
2337
79aceca5 2338/*** Floating-Point compare ***/
99e300ef 2339
54623277 2340/* fcmpo */
99e300ef 2341static void gen_fcmpo(DisasContext *ctx)
79aceca5 2342{
330c483b 2343 TCGv_i32 crf;
76a66253 2344 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2345 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2346 return;
2347 }
eb44b959
AJ
2348 /* NIP cannot be restored if the memory exception comes from an helper */
2349 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2350 gen_reset_fpstatus();
9a819377 2351 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2352 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2353 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2354 tcg_temp_free_i32(crf);
8e703949 2355 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2356}
2357
2358/* fcmpu */
99e300ef 2359static void gen_fcmpu(DisasContext *ctx)
79aceca5 2360{
330c483b 2361 TCGv_i32 crf;
76a66253 2362 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2363 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2364 return;
2365 }
eb44b959
AJ
2366 /* NIP cannot be restored if the memory exception comes from an helper */
2367 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2368 gen_reset_fpstatus();
9a819377 2369 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2370 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2371 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2372 tcg_temp_free_i32(crf);
8e703949 2373 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2374}
2375
9a64fbe4
FB
2376/*** Floating-point move ***/
2377/* fabs */
7c58044c 2378/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2379static void gen_fabs(DisasContext *ctx)
2380{
2381 if (unlikely(!ctx->fpu_enabled)) {
2382 gen_exception(ctx, POWERPC_EXCP_FPU);
2383 return;
2384 }
2385 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2386 ~(1ULL << 63));
4814f2d1
TM
2387 if (unlikely(Rc(ctx->opcode))) {
2388 gen_set_cr1_from_fpscr(ctx);
2389 }
bf45a2e6 2390}
9a64fbe4
FB
2391
2392/* fmr - fmr. */
7c58044c 2393/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2394static void gen_fmr(DisasContext *ctx)
9a64fbe4 2395{
76a66253 2396 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2397 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2398 return;
2399 }
af12906f 2400 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
4814f2d1
TM
2401 if (unlikely(Rc(ctx->opcode))) {
2402 gen_set_cr1_from_fpscr(ctx);
2403 }
9a64fbe4
FB
2404}
2405
2406/* fnabs */
7c58044c 2407/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2408static void gen_fnabs(DisasContext *ctx)
2409{
2410 if (unlikely(!ctx->fpu_enabled)) {
2411 gen_exception(ctx, POWERPC_EXCP_FPU);
2412 return;
2413 }
2414 tcg_gen_ori_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
AJ
2419}
2420
9a64fbe4 2421/* fneg */
7c58044c 2422/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2423static void gen_fneg(DisasContext *ctx)
2424{
2425 if (unlikely(!ctx->fpu_enabled)) {
2426 gen_exception(ctx, POWERPC_EXCP_FPU);
2427 return;
2428 }
2429 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2430 1ULL << 63);
4814f2d1
TM
2431 if (unlikely(Rc(ctx->opcode))) {
2432 gen_set_cr1_from_fpscr(ctx);
2433 }
bf45a2e6 2434}
9a64fbe4 2435
f0332888
AJ
2436/* fcpsgn: PowerPC 2.05 specification */
2437/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2438static void gen_fcpsgn(DisasContext *ctx)
2439{
2440 if (unlikely(!ctx->fpu_enabled)) {
2441 gen_exception(ctx, POWERPC_EXCP_FPU);
2442 return;
2443 }
2444 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2445 cpu_fpr[rB(ctx->opcode)], 0, 63);
4814f2d1
TM
2446 if (unlikely(Rc(ctx->opcode))) {
2447 gen_set_cr1_from_fpscr(ctx);
2448 }
f0332888
AJ
2449}
2450
097ec5d8
TM
2451static void gen_fmrgew(DisasContext *ctx)
2452{
2453 TCGv_i64 b0;
2454 if (unlikely(!ctx->fpu_enabled)) {
2455 gen_exception(ctx, POWERPC_EXCP_FPU);
2456 return;
2457 }
2458 b0 = tcg_temp_new_i64();
2459 tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32);
2460 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2461 b0, 0, 32);
2462 tcg_temp_free_i64(b0);
2463}
2464
2465static void gen_fmrgow(DisasContext *ctx)
2466{
2467 if (unlikely(!ctx->fpu_enabled)) {
2468 gen_exception(ctx, POWERPC_EXCP_FPU);
2469 return;
2470 }
2471 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)],
2472 cpu_fpr[rB(ctx->opcode)],
2473 cpu_fpr[rA(ctx->opcode)],
2474 32, 32);
2475}
2476
79aceca5 2477/*** Floating-Point status & ctrl register ***/
99e300ef 2478
54623277 2479/* mcrfs */
99e300ef 2480static void gen_mcrfs(DisasContext *ctx)
79aceca5 2481{
30304420 2482 TCGv tmp = tcg_temp_new();
d1277156
JC
2483 TCGv_i32 tmask;
2484 TCGv_i64 tnew_fpscr = tcg_temp_new_i64();
7c58044c 2485 int bfa;
d1277156
JC
2486 int nibble;
2487 int shift;
7c58044c 2488
76a66253 2489 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2490 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2491 return;
2492 }
d1277156
JC
2493 bfa = crfS(ctx->opcode);
2494 nibble = 7 - bfa;
2495 shift = 4 * nibble;
2496 tcg_gen_shri_tl(tmp, cpu_fpscr, shift);
30304420 2497 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
e1571908 2498 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
d1277156
JC
2499 tcg_temp_free(tmp);
2500 tcg_gen_extu_tl_i64(tnew_fpscr, cpu_fpscr);
2501 /* Only the exception bits (including FX) should be cleared if read */
2502 tcg_gen_andi_i64(tnew_fpscr, tnew_fpscr, ~((0xF << shift) & FP_EX_CLEAR_BITS));
2503 /* FEX and VX need to be updated, so don't set fpscr directly */
2504 tmask = tcg_const_i32(1 << nibble);
2505 gen_helper_store_fpscr(cpu_env, tnew_fpscr, tmask);
2506 tcg_temp_free_i32(tmask);
2507 tcg_temp_free_i64(tnew_fpscr);
79aceca5
FB
2508}
2509
2510/* mffs */
99e300ef 2511static void gen_mffs(DisasContext *ctx)
79aceca5 2512{
76a66253 2513 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2514 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2515 return;
2516 }
7c58044c 2517 gen_reset_fpstatus();
30304420 2518 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
14ba79c7
TM
2519 if (unlikely(Rc(ctx->opcode))) {
2520 gen_set_cr1_from_fpscr(ctx);
2521 }
79aceca5
FB
2522}
2523
2524/* mtfsb0 */
99e300ef 2525static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2526{
fb0eaffc 2527 uint8_t crb;
3b46e624 2528
76a66253 2529 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2530 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2531 return;
2532 }
6e35d524 2533 crb = 31 - crbD(ctx->opcode);
7c58044c 2534 gen_reset_fpstatus();
6e35d524 2535 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2536 TCGv_i32 t0;
2537 /* NIP cannot be restored if the memory exception comes from an helper */
2538 gen_update_nip(ctx, ctx->nip - 4);
2539 t0 = tcg_const_i32(crb);
8e703949 2540 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2541 tcg_temp_free_i32(t0);
2542 }
7c58044c 2543 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2544 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2545 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2546 }
79aceca5
FB
2547}
2548
2549/* mtfsb1 */
99e300ef 2550static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2551{
fb0eaffc 2552 uint8_t crb;
3b46e624 2553
76a66253 2554 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2555 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2556 return;
2557 }
6e35d524 2558 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2559 gen_reset_fpstatus();
2560 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2561 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2562 TCGv_i32 t0;
2563 /* NIP cannot be restored if the memory exception comes from an helper */
2564 gen_update_nip(ctx, ctx->nip - 4);
2565 t0 = tcg_const_i32(crb);
8e703949 2566 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2567 tcg_temp_free_i32(t0);
af12906f 2568 }
7c58044c 2569 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2570 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2571 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2572 }
2573 /* We can raise a differed exception */
8e703949 2574 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2575}
2576
2577/* mtfsf */
99e300ef 2578static void gen_mtfsf(DisasContext *ctx)
79aceca5 2579{
0f2f39c2 2580 TCGv_i32 t0;
7d08d856 2581 int flm, l, w;
af12906f 2582
76a66253 2583 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2584 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2585 return;
2586 }
7d08d856
AJ
2587 flm = FPFLM(ctx->opcode);
2588 l = FPL(ctx->opcode);
2589 w = FPW(ctx->opcode);
2590 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2591 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2592 return;
2593 }
eb44b959
AJ
2594 /* NIP cannot be restored if the memory exception comes from an helper */
2595 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2596 gen_reset_fpstatus();
7d08d856
AJ
2597 if (l) {
2598 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2599 } else {
2600 t0 = tcg_const_i32(flm << (w * 8));
2601 }
8e703949 2602 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2603 tcg_temp_free_i32(t0);
7c58044c 2604 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2605 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2606 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2607 }
2608 /* We can raise a differed exception */
8e703949 2609 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2610}
2611
2612/* mtfsfi */
99e300ef 2613static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2614{
7d08d856 2615 int bf, sh, w;
0f2f39c2
AJ
2616 TCGv_i64 t0;
2617 TCGv_i32 t1;
7c58044c 2618
76a66253 2619 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2620 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2621 return;
2622 }
7d08d856
AJ
2623 w = FPW(ctx->opcode);
2624 bf = FPBF(ctx->opcode);
2625 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2626 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2627 return;
2628 }
2629 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2630 /* NIP cannot be restored if the memory exception comes from an helper */
2631 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2632 gen_reset_fpstatus();
7d08d856 2633 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2634 t1 = tcg_const_i32(1 << sh);
8e703949 2635 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2636 tcg_temp_free_i64(t0);
2637 tcg_temp_free_i32(t1);
7c58044c 2638 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2639 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2640 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2641 }
2642 /* We can raise a differed exception */
8e703949 2643 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2644}
2645
76a66253
JM
2646/*** Addressing modes ***/
2647/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2648static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2649 target_long maskl)
76a66253
JM
2650{
2651 target_long simm = SIMM(ctx->opcode);
2652
be147d08 2653 simm &= ~maskl;
76db3ba4 2654 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2655 if (NARROW_MODE(ctx)) {
2656 simm = (uint32_t)simm;
2657 }
e2be8d8d 2658 tcg_gen_movi_tl(EA, simm);
76db3ba4 2659 } else if (likely(simm != 0)) {
e2be8d8d 2660 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2661 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2662 tcg_gen_ext32u_tl(EA, EA);
2663 }
76db3ba4 2664 } else {
c791fe84 2665 if (NARROW_MODE(ctx)) {
76db3ba4 2666 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2667 } else {
2668 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2669 }
76db3ba4 2670 }
76a66253
JM
2671}
2672
636aa200 2673static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2674{
76db3ba4 2675 if (rA(ctx->opcode) == 0) {
c791fe84 2676 if (NARROW_MODE(ctx)) {
76db3ba4 2677 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2678 } else {
2679 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2680 }
76db3ba4 2681 } else {
e2be8d8d 2682 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2683 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2684 tcg_gen_ext32u_tl(EA, EA);
2685 }
76db3ba4 2686 }
76a66253
JM
2687}
2688
636aa200 2689static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2690{
76db3ba4 2691 if (rA(ctx->opcode) == 0) {
e2be8d8d 2692 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2693 } else if (NARROW_MODE(ctx)) {
2694 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2695 } else {
c791fe84 2696 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2697 }
2698}
2699
636aa200
BS
2700static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2701 target_long val)
76db3ba4
AJ
2702{
2703 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2704 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2705 tcg_gen_ext32u_tl(ret, ret);
2706 }
76a66253
JM
2707}
2708
636aa200 2709static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32 2710{
42a268c2 2711 TCGLabel *l1 = gen_new_label();
cf360a32
AJ
2712 TCGv t0 = tcg_temp_new();
2713 TCGv_i32 t1, t2;
2714 /* NIP cannot be restored if the memory exception comes from an helper */
2715 gen_update_nip(ctx, ctx->nip - 4);
2716 tcg_gen_andi_tl(t0, EA, mask);
2717 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2718 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2719 t2 = tcg_const_i32(0);
e5f17ac6 2720 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2721 tcg_temp_free_i32(t1);
2722 tcg_temp_free_i32(t2);
2723 gen_set_label(l1);
2724 tcg_temp_free(t0);
2725}
2726
7863667f 2727/*** Integer load ***/
636aa200 2728static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2729{
2730 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2731}
2732
636aa200 2733static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4 2734{
e22c357b
DK
2735 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2736 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2737}
2738
636aa200 2739static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2740{
e22c357b
DK
2741 TCGMemOp op = MO_SW | ctx->default_tcg_memop_mask;
2742 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2743}
2744
636aa200 2745static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2746{
e22c357b
DK
2747 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2748 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2749}
2750
f976b09e
AG
2751static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2752{
2753 TCGv tmp = tcg_temp_new();
2754 gen_qemu_ld32u(ctx, tmp, addr);
2755 tcg_gen_extu_tl_i64(val, tmp);
2756 tcg_temp_free(tmp);
2757}
2758
636aa200 2759static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2760{
e22c357b
DK
2761 TCGMemOp op = MO_SL | ctx->default_tcg_memop_mask;
2762 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2763}
2764
cac7f0ba
TM
2765static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2766{
2767 TCGv tmp = tcg_temp_new();
2768 gen_qemu_ld32s(ctx, tmp, addr);
2769 tcg_gen_ext_tl_i64(val, tmp);
2770 tcg_temp_free(tmp);
2771}
2772
636aa200 2773static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2774{
e22c357b
DK
2775 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2776 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2777}
2778
636aa200 2779static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2780{
76db3ba4 2781 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2782}
2783
636aa200 2784static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2785{
e22c357b
DK
2786 TCGMemOp op = MO_UW | ctx->default_tcg_memop_mask;
2787 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2788}
2789
636aa200 2790static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2791{
e22c357b
DK
2792 TCGMemOp op = MO_UL | ctx->default_tcg_memop_mask;
2793 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2794}
2795
f976b09e
AG
2796static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2797{
2798 TCGv tmp = tcg_temp_new();
2799 tcg_gen_trunc_i64_tl(tmp, val);
2800 gen_qemu_st32(ctx, tmp, addr);
2801 tcg_temp_free(tmp);
2802}
2803
636aa200 2804static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2805{
e22c357b
DK
2806 TCGMemOp op = MO_Q | ctx->default_tcg_memop_mask;
2807 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
b61f2753
AJ
2808}
2809
0c8aacd4 2810#define GEN_LD(name, ldop, opc, type) \
99e300ef 2811static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2812{ \
76db3ba4
AJ
2813 TCGv EA; \
2814 gen_set_access_type(ctx, ACCESS_INT); \
2815 EA = tcg_temp_new(); \
2816 gen_addr_imm_index(ctx, EA, 0); \
2817 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2818 tcg_temp_free(EA); \
79aceca5
FB
2819}
2820
0c8aacd4 2821#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2822static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2823{ \
b61f2753 2824 TCGv EA; \
76a66253
JM
2825 if (unlikely(rA(ctx->opcode) == 0 || \
2826 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2827 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2828 return; \
9a64fbe4 2829 } \
76db3ba4 2830 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2831 EA = tcg_temp_new(); \
9d53c753 2832 if (type == PPC_64B) \
76db3ba4 2833 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2834 else \
76db3ba4
AJ
2835 gen_addr_imm_index(ctx, EA, 0); \
2836 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2837 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2838 tcg_temp_free(EA); \
79aceca5
FB
2839}
2840
0c8aacd4 2841#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2842static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2843{ \
b61f2753 2844 TCGv EA; \
76a66253
JM
2845 if (unlikely(rA(ctx->opcode) == 0 || \
2846 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2847 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2848 return; \
9a64fbe4 2849 } \
76db3ba4 2850 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2851 EA = tcg_temp_new(); \
76db3ba4
AJ
2852 gen_addr_reg_index(ctx, EA); \
2853 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2854 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2855 tcg_temp_free(EA); \
79aceca5
FB
2856}
2857
cd6e9320 2858#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2859static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2860{ \
76db3ba4
AJ
2861 TCGv EA; \
2862 gen_set_access_type(ctx, ACCESS_INT); \
2863 EA = tcg_temp_new(); \
2864 gen_addr_reg_index(ctx, EA); \
2865 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2866 tcg_temp_free(EA); \
79aceca5 2867}
cd6e9320
TH
2868#define GEN_LDX(name, ldop, opc2, opc3, type) \
2869 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2870
0c8aacd4
AJ
2871#define GEN_LDS(name, ldop, op, type) \
2872GEN_LD(name, ldop, op | 0x20, type); \
2873GEN_LDU(name, ldop, op | 0x21, type); \
2874GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2875GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2876
2877/* lbz lbzu lbzux lbzx */
0c8aacd4 2878GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2879/* lha lhau lhaux lhax */
0c8aacd4 2880GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2881/* lhz lhzu lhzux lhzx */
0c8aacd4 2882GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2883/* lwz lwzu lwzux lwzx */
0c8aacd4 2884GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2885#if defined(TARGET_PPC64)
d9bce9d9 2886/* lwaux */
0c8aacd4 2887GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2888/* lwax */
0c8aacd4 2889GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2890/* ldux */
0c8aacd4 2891GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2892/* ldx */
0c8aacd4 2893GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2894
2895static void gen_ld(DisasContext *ctx)
d9bce9d9 2896{
b61f2753 2897 TCGv EA;
d9bce9d9
JM
2898 if (Rc(ctx->opcode)) {
2899 if (unlikely(rA(ctx->opcode) == 0 ||
2900 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2901 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2902 return;
2903 }
2904 }
76db3ba4 2905 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2906 EA = tcg_temp_new();
76db3ba4 2907 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2908 if (ctx->opcode & 0x02) {
2909 /* lwa (lwau is undefined) */
76db3ba4 2910 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2911 } else {
2912 /* ld - ldu */
76db3ba4 2913 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2914 }
d9bce9d9 2915 if (Rc(ctx->opcode))
b61f2753
AJ
2916 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2917 tcg_temp_free(EA);
d9bce9d9 2918}
99e300ef 2919
54623277 2920/* lq */
99e300ef 2921static void gen_lq(DisasContext *ctx)
be147d08 2922{
be147d08 2923 int ra, rd;
b61f2753 2924 TCGv EA;
be147d08 2925
e0498daa
TM
2926 /* lq is a legal user mode instruction starting in ISA 2.07 */
2927 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2928 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
2929
c47493f2 2930 if (!legal_in_user_mode && ctx->pr) {
e06fcd75 2931 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2932 return;
2933 }
e0498daa
TM
2934
2935 if (!le_is_supported && ctx->le_mode) {
2936 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2937 return;
2938 }
2939
be147d08
JM
2940 ra = rA(ctx->opcode);
2941 rd = rD(ctx->opcode);
2942 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2943 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2944 return;
2945 }
e0498daa 2946
76db3ba4 2947 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2948 EA = tcg_temp_new();
76db3ba4 2949 gen_addr_imm_index(ctx, EA, 0x0F);
e0498daa 2950
e22c357b
DK
2951 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
2952 64-bit byteswap already. */
e0498daa
TM
2953 if (unlikely(ctx->le_mode)) {
2954 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2955 gen_addr_add(ctx, EA, EA, 8);
2956 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2957 } else {
2958 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2959 gen_addr_add(ctx, EA, EA, 8);
2960 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2961 }
b61f2753 2962 tcg_temp_free(EA);
be147d08 2963}
d9bce9d9 2964#endif
79aceca5
FB
2965
2966/*** Integer store ***/
0c8aacd4 2967#define GEN_ST(name, stop, opc, type) \
99e300ef 2968static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2969{ \
76db3ba4
AJ
2970 TCGv EA; \
2971 gen_set_access_type(ctx, ACCESS_INT); \
2972 EA = tcg_temp_new(); \
2973 gen_addr_imm_index(ctx, EA, 0); \
2974 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2975 tcg_temp_free(EA); \
79aceca5
FB
2976}
2977
0c8aacd4 2978#define GEN_STU(name, stop, opc, type) \
99e300ef 2979static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2980{ \
b61f2753 2981 TCGv EA; \
76a66253 2982 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2983 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2984 return; \
9a64fbe4 2985 } \
76db3ba4 2986 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2987 EA = tcg_temp_new(); \
9d53c753 2988 if (type == PPC_64B) \
76db3ba4 2989 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2990 else \
76db3ba4
AJ
2991 gen_addr_imm_index(ctx, EA, 0); \
2992 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2993 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2994 tcg_temp_free(EA); \
79aceca5
FB
2995}
2996
0c8aacd4 2997#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2998static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2999{ \
b61f2753 3000 TCGv EA; \
76a66253 3001 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3002 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3003 return; \
9a64fbe4 3004 } \
76db3ba4 3005 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 3006 EA = tcg_temp_new(); \
76db3ba4
AJ
3007 gen_addr_reg_index(ctx, EA); \
3008 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
3009 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3010 tcg_temp_free(EA); \
79aceca5
FB
3011}
3012
cd6e9320
TH
3013#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
3014static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3015{ \
76db3ba4
AJ
3016 TCGv EA; \
3017 gen_set_access_type(ctx, ACCESS_INT); \
3018 EA = tcg_temp_new(); \
3019 gen_addr_reg_index(ctx, EA); \
3020 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 3021 tcg_temp_free(EA); \
79aceca5 3022}
cd6e9320
TH
3023#define GEN_STX(name, stop, opc2, opc3, type) \
3024 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 3025
0c8aacd4
AJ
3026#define GEN_STS(name, stop, op, type) \
3027GEN_ST(name, stop, op | 0x20, type); \
3028GEN_STU(name, stop, op | 0x21, type); \
3029GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3030GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
3031
3032/* stb stbu stbux stbx */
0c8aacd4 3033GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 3034/* sth sthu sthux sthx */
0c8aacd4 3035GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 3036/* stw stwu stwux stwx */
0c8aacd4 3037GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 3038#if defined(TARGET_PPC64)
0c8aacd4
AJ
3039GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
3040GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
3041
3042static void gen_std(DisasContext *ctx)
d9bce9d9 3043{
be147d08 3044 int rs;
b61f2753 3045 TCGv EA;
be147d08
JM
3046
3047 rs = rS(ctx->opcode);
84cab1e2
TM
3048 if ((ctx->opcode & 0x3) == 0x2) { /* stq */
3049
3050 bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3051 bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0;
3052
c47493f2 3053 if (!legal_in_user_mode && ctx->pr) {
e06fcd75 3054 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3055 return;
3056 }
84cab1e2
TM
3057
3058 if (!le_is_supported && ctx->le_mode) {
3059 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
d9bce9d9
JM
3060 return;
3061 }
84cab1e2
TM
3062
3063 if (unlikely(rs & 1)) {
3064 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3065 return;
3066 }
76db3ba4 3067 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3068 EA = tcg_temp_new();
76db3ba4 3069 gen_addr_imm_index(ctx, EA, 0x03);
84cab1e2 3070
e22c357b
DK
3071 /* We only need to swap high and low halves. gen_qemu_st64 does
3072 necessary 64-bit byteswap already. */
84cab1e2
TM
3073 if (unlikely(ctx->le_mode)) {
3074 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3075 gen_addr_add(ctx, EA, EA, 8);
3076 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3077 } else {
3078 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
3079 gen_addr_add(ctx, EA, EA, 8);
3080 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
3081 }
b61f2753 3082 tcg_temp_free(EA);
be147d08 3083 } else {
84cab1e2 3084 /* std / stdu*/
be147d08
JM
3085 if (Rc(ctx->opcode)) {
3086 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 3087 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
3088 return;
3089 }
3090 }
76db3ba4 3091 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 3092 EA = tcg_temp_new();
76db3ba4
AJ
3093 gen_addr_imm_index(ctx, EA, 0x03);
3094 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 3095 if (Rc(ctx->opcode))
b61f2753
AJ
3096 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3097 tcg_temp_free(EA);
d9bce9d9 3098 }
d9bce9d9
JM
3099}
3100#endif
79aceca5 3101/*** Integer load and store with byte reverse ***/
e22c357b 3102
79aceca5 3103/* lhbrx */
86178a57 3104static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3105{
e22c357b
DK
3106 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3107 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3108}
0c8aacd4 3109GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 3110
79aceca5 3111/* lwbrx */
86178a57 3112static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3113{
e22c357b
DK
3114 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3115 tcg_gen_qemu_ld_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3116}
0c8aacd4 3117GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 3118
cd6e9320
TH
3119#if defined(TARGET_PPC64)
3120/* ldbrx */
3121static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
3122{
e22c357b
DK
3123 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3124 tcg_gen_qemu_ld_i64(arg1, arg2, ctx->mem_idx, op);
cd6e9320
TH
3125}
3126GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
3127#endif /* TARGET_PPC64 */
3128
79aceca5 3129/* sthbrx */
86178a57 3130static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3131{
e22c357b
DK
3132 TCGMemOp op = MO_UW | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3133 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3134}
0c8aacd4 3135GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 3136
79aceca5 3137/* stwbrx */
86178a57 3138static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 3139{
e22c357b
DK
3140 TCGMemOp op = MO_UL | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3141 tcg_gen_qemu_st_tl(arg1, arg2, ctx->mem_idx, op);
b61f2753 3142}
0c8aacd4 3143GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 3144
cd6e9320
TH
3145#if defined(TARGET_PPC64)
3146/* stdbrx */
3147static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
3148{
e22c357b
DK
3149 TCGMemOp op = MO_Q | (ctx->default_tcg_memop_mask ^ MO_BSWAP);
3150 tcg_gen_qemu_st_i64(arg1, arg2, ctx->mem_idx, op);
cd6e9320
TH
3151}
3152GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3153#endif /* TARGET_PPC64 */
3154
79aceca5 3155/*** Integer load and store multiple ***/
99e300ef 3156
54623277 3157/* lmw */
99e300ef 3158static void gen_lmw(DisasContext *ctx)
79aceca5 3159{
76db3ba4
AJ
3160 TCGv t0;
3161 TCGv_i32 t1;
3162 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3163 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3164 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3165 t0 = tcg_temp_new();
3166 t1 = tcg_const_i32(rD(ctx->opcode));
3167 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3168 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3169 tcg_temp_free(t0);
3170 tcg_temp_free_i32(t1);
79aceca5
FB
3171}
3172
3173/* stmw */
99e300ef 3174static void gen_stmw(DisasContext *ctx)
79aceca5 3175{
76db3ba4
AJ
3176 TCGv t0;
3177 TCGv_i32 t1;
3178 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3179 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3180 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3181 t0 = tcg_temp_new();
3182 t1 = tcg_const_i32(rS(ctx->opcode));
3183 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3184 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3185 tcg_temp_free(t0);
3186 tcg_temp_free_i32(t1);
79aceca5
FB
3187}
3188
3189/*** Integer load and store strings ***/
54623277 3190
79aceca5 3191/* lswi */
3fc6c082 3192/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3193 * rA is in the range of registers to be loaded.
3194 * In an other hand, IBM says this is valid, but rA won't be loaded.
3195 * For now, I'll follow the spec...
3196 */
99e300ef 3197static void gen_lswi(DisasContext *ctx)
79aceca5 3198{
dfbc799d
AJ
3199 TCGv t0;
3200 TCGv_i32 t1, t2;
79aceca5
FB
3201 int nb = NB(ctx->opcode);
3202 int start = rD(ctx->opcode);
9a64fbe4 3203 int ra = rA(ctx->opcode);
79aceca5
FB
3204 int nr;
3205
3206 if (nb == 0)
3207 nb = 32;
afbee712
TH
3208 nr = (nb + 3) / 4;
3209 if (unlikely(lsw_reg_in_range(start, nr, ra))) {
e06fcd75 3210 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3211 return;
297d8e62 3212 }
76db3ba4 3213 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3214 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3215 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3216 t0 = tcg_temp_new();
76db3ba4 3217 gen_addr_register(ctx, t0);
dfbc799d
AJ
3218 t1 = tcg_const_i32(nb);
3219 t2 = tcg_const_i32(start);
2f5a189c 3220 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3221 tcg_temp_free(t0);
3222 tcg_temp_free_i32(t1);
3223 tcg_temp_free_i32(t2);
79aceca5
FB
3224}
3225
3226/* lswx */
99e300ef 3227static void gen_lswx(DisasContext *ctx)
79aceca5 3228{
76db3ba4
AJ
3229 TCGv t0;
3230 TCGv_i32 t1, t2, t3;
3231 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3232 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3233 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3234 t0 = tcg_temp_new();
3235 gen_addr_reg_index(ctx, t0);
3236 t1 = tcg_const_i32(rD(ctx->opcode));
3237 t2 = tcg_const_i32(rA(ctx->opcode));
3238 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3239 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3240 tcg_temp_free(t0);
3241 tcg_temp_free_i32(t1);
3242 tcg_temp_free_i32(t2);
3243 tcg_temp_free_i32(t3);
79aceca5
FB
3244}
3245
3246/* stswi */
99e300ef 3247static void gen_stswi(DisasContext *ctx)
79aceca5 3248{
76db3ba4
AJ
3249 TCGv t0;
3250 TCGv_i32 t1, t2;
4b3686fa 3251 int nb = NB(ctx->opcode);
76db3ba4 3252 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3253 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3254 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3255 t0 = tcg_temp_new();
3256 gen_addr_register(ctx, t0);
4b3686fa
FB
3257 if (nb == 0)
3258 nb = 32;
dfbc799d 3259 t1 = tcg_const_i32(nb);
76db3ba4 3260 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3261 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3262 tcg_temp_free(t0);
3263 tcg_temp_free_i32(t1);
3264 tcg_temp_free_i32(t2);
79aceca5
FB
3265}
3266
3267/* stswx */
99e300ef 3268static void gen_stswx(DisasContext *ctx)
79aceca5 3269{
76db3ba4
AJ
3270 TCGv t0;
3271 TCGv_i32 t1, t2;
3272 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3273 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3274 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3275 t0 = tcg_temp_new();
3276 gen_addr_reg_index(ctx, t0);
3277 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3278 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3279 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3280 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3281 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3282 tcg_temp_free(t0);
3283 tcg_temp_free_i32(t1);
3284 tcg_temp_free_i32(t2);
79aceca5
FB
3285}
3286
3287/*** Memory synchronisation ***/
3288/* eieio */
99e300ef 3289static void gen_eieio(DisasContext *ctx)
79aceca5 3290{
79aceca5
FB
3291}
3292
cd0c6f47
BH
3293#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
3294static inline void gen_check_tlb_flush(DisasContext *ctx)
3295{
3296 TCGv_i32 t = tcg_temp_new_i32();
3297 TCGLabel *l = gen_new_label();
3298
3299 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, tlb_need_flush));
3300 tcg_gen_brcondi_i32(TCG_COND_EQ, t, 0, l);
3301 gen_helper_check_tlb_flush(cpu_env);
3302 gen_set_label(l);
3303 tcg_temp_free_i32(t);
3304}
3305#else
3306static inline void gen_check_tlb_flush(DisasContext *ctx) { }
3307#endif
3308
79aceca5 3309/* isync */
99e300ef 3310static void gen_isync(DisasContext *ctx)
79aceca5 3311{
cd0c6f47
BH
3312 /*
3313 * We need to check for a pending TLB flush. This can only happen in
3314 * kernel mode however so check MSR_PR
3315 */
3316 if (!ctx->pr) {
3317 gen_check_tlb_flush(ctx);
3318 }
e06fcd75 3319 gen_stop_exception(ctx);
79aceca5
FB
3320}
3321
5c77a786
TM
3322#define LARX(name, len, loadop) \
3323static void gen_##name(DisasContext *ctx) \
3324{ \
3325 TCGv t0; \
3326 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3327 gen_set_access_type(ctx, ACCESS_RES); \
3328 t0 = tcg_temp_local_new(); \
3329 gen_addr_reg_index(ctx, t0); \
3330 if ((len) > 1) { \
3331 gen_check_align(ctx, t0, (len)-1); \
3332 } \
3333 gen_qemu_##loadop(ctx, gpr, t0); \
3334 tcg_gen_mov_tl(cpu_reserve, t0); \
3335 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3336 tcg_temp_free(t0); \
79aceca5
FB
3337}
3338
5c77a786
TM
3339/* lwarx */
3340LARX(lbarx, 1, ld8u);
3341LARX(lharx, 2, ld16u);
3342LARX(lwarx, 4, ld32u);
3343
3344
4425265b 3345#if defined(CONFIG_USER_ONLY)
587c51f7
TM
3346static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3347 int reg, int size)
4425265b
NF
3348{
3349 TCGv t0 = tcg_temp_new();
3350 uint32_t save_exception = ctx->exception;
3351
1328c2bf 3352 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3353 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3354 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3355 tcg_temp_free(t0);
3356 gen_update_nip(ctx, ctx->nip-4);
3357 ctx->exception = POWERPC_EXCP_BRANCH;
3358 gen_exception(ctx, POWERPC_EXCP_STCX);
3359 ctx->exception = save_exception;
3360}
4425265b 3361#else
587c51f7
TM
3362static void gen_conditional_store(DisasContext *ctx, TCGv EA,
3363 int reg, int size)
3364{
42a268c2 3365 TCGLabel *l1;
4425265b 3366
587c51f7
TM
3367 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
3368 l1 = gen_new_label();
3369 tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1);
3370 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3371#if defined(TARGET_PPC64)
3372 if (size == 8) {
3373 gen_qemu_st64(ctx, cpu_gpr[reg], EA);
3374 } else
3375#endif
3376 if (size == 4) {
3377 gen_qemu_st32(ctx, cpu_gpr[reg], EA);
3378 } else if (size == 2) {
3379 gen_qemu_st16(ctx, cpu_gpr[reg], EA);
27b95bfe
TM
3380#if defined(TARGET_PPC64)
3381 } else if (size == 16) {
3707cd62 3382 TCGv gpr1, gpr2 , EA8;
27b95bfe
TM
3383 if (unlikely(ctx->le_mode)) {
3384 gpr1 = cpu_gpr[reg+1];
3385 gpr2 = cpu_gpr[reg];
3386 } else {
3387 gpr1 = cpu_gpr[reg];
3388 gpr2 = cpu_gpr[reg+1];
3389 }
3390 gen_qemu_st64(ctx, gpr1, EA);
3707cd62
TM
3391 EA8 = tcg_temp_local_new();
3392 gen_addr_add(ctx, EA8, EA, 8);
3393 gen_qemu_st64(ctx, gpr2, EA8);
3394 tcg_temp_free(EA8);
27b95bfe 3395#endif
587c51f7
TM
3396 } else {
3397 gen_qemu_st8(ctx, cpu_gpr[reg], EA);
4425265b 3398 }
587c51f7
TM
3399 gen_set_label(l1);
3400 tcg_gen_movi_tl(cpu_reserve, -1);
3401}
4425265b 3402#endif
587c51f7
TM
3403
3404#define STCX(name, len) \
3405static void gen_##name(DisasContext *ctx) \
3406{ \
3407 TCGv t0; \
27b95bfe
TM
3408 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3409 gen_inval_exception(ctx, \
3410 POWERPC_EXCP_INVAL_INVAL); \
3411 return; \
3412 } \
587c51f7
TM
3413 gen_set_access_type(ctx, ACCESS_RES); \
3414 t0 = tcg_temp_local_new(); \
3415 gen_addr_reg_index(ctx, t0); \
3416 if (len > 1) { \
3417 gen_check_align(ctx, t0, (len)-1); \
3418 } \
3419 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3420 tcg_temp_free(t0); \
79aceca5
FB
3421}
3422
587c51f7
TM
3423STCX(stbcx_, 1);
3424STCX(sthcx_, 2);
3425STCX(stwcx_, 4);
3426
426613db 3427#if defined(TARGET_PPC64)
426613db 3428/* ldarx */
5c77a786 3429LARX(ldarx, 8, ld64);
426613db 3430
9c294d5a
TM
3431/* lqarx */
3432static void gen_lqarx(DisasContext *ctx)
3433{
3434 TCGv EA;
3435 int rd = rD(ctx->opcode);
3436 TCGv gpr1, gpr2;
3437
3438 if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) ||
3439 (rd == rB(ctx->opcode)))) {
3440 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3441 return;
3442 }
3443
3444 gen_set_access_type(ctx, ACCESS_RES);
3445 EA = tcg_temp_local_new();
3446 gen_addr_reg_index(ctx, EA);
3447 gen_check_align(ctx, EA, 15);
3448 if (unlikely(ctx->le_mode)) {
3449 gpr1 = cpu_gpr[rd+1];
3450 gpr2 = cpu_gpr[rd];
3451 } else {
3452 gpr1 = cpu_gpr[rd];
3453 gpr2 = cpu_gpr[rd+1];
3454 }
3455 gen_qemu_ld64(ctx, gpr1, EA);
3456 tcg_gen_mov_tl(cpu_reserve, EA);
3457
3458 gen_addr_add(ctx, EA, EA, 8);
3459 gen_qemu_ld64(ctx, gpr2, EA);
3460
3461 tcg_gen_st_tl(gpr1, cpu_env, offsetof(CPUPPCState, reserve_val));
3462 tcg_gen_st_tl(gpr2, cpu_env, offsetof(CPUPPCState, reserve_val2));
3463
3464 tcg_temp_free(EA);
3465}
3466
426613db 3467/* stdcx. */
587c51f7 3468STCX(stdcx_, 8);
27b95bfe 3469STCX(stqcx_, 16);
426613db
JM
3470#endif /* defined(TARGET_PPC64) */
3471
79aceca5 3472/* sync */
99e300ef 3473static void gen_sync(DisasContext *ctx)
79aceca5 3474{
cd0c6f47
BH
3475 uint32_t l = (ctx->opcode >> 21) & 3;
3476
3477 /*
3478 * For l == 2, it's a ptesync, We need to check for a pending TLB flush.
3479 * This can only happen in kernel mode however so check MSR_PR as well.
3480 */
3481 if (l == 2 && !ctx->pr) {
3482 gen_check_tlb_flush(ctx);
3483 }
79aceca5
FB
3484}
3485
0db1b20e 3486/* wait */
99e300ef 3487static void gen_wait(DisasContext *ctx)
0db1b20e 3488{
931ff272 3489 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3490 tcg_gen_st_i32(t0, cpu_env,
3491 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3492 tcg_temp_free_i32(t0);
0db1b20e 3493 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3494 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3495}
3496
79aceca5 3497/*** Floating-point load ***/
a0d7d5a7 3498#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3499static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3500{ \
a0d7d5a7 3501 TCGv EA; \
76a66253 3502 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3503 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3504 return; \
3505 } \
76db3ba4 3506 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3507 EA = tcg_temp_new(); \
76db3ba4
AJ
3508 gen_addr_imm_index(ctx, EA, 0); \
3509 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3510 tcg_temp_free(EA); \
79aceca5
FB
3511}
3512
a0d7d5a7 3513#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3514static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3515{ \
a0d7d5a7 3516 TCGv EA; \
76a66253 3517 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3518 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3519 return; \
3520 } \
76a66253 3521 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3522 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3523 return; \
9a64fbe4 3524 } \
76db3ba4 3525 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3526 EA = tcg_temp_new(); \
76db3ba4
AJ
3527 gen_addr_imm_index(ctx, EA, 0); \
3528 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3529 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3530 tcg_temp_free(EA); \
79aceca5
FB
3531}
3532
a0d7d5a7 3533#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3534static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3535{ \
a0d7d5a7 3536 TCGv EA; \
76a66253 3537 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3538 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3539 return; \
3540 } \
76a66253 3541 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3542 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3543 return; \
9a64fbe4 3544 } \
76db3ba4 3545 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3546 EA = tcg_temp_new(); \
76db3ba4
AJ
3547 gen_addr_reg_index(ctx, EA); \
3548 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3549 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3550 tcg_temp_free(EA); \
79aceca5
FB
3551}
3552
a0d7d5a7 3553#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3554static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3555{ \
a0d7d5a7 3556 TCGv EA; \
76a66253 3557 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3558 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3559 return; \
3560 } \
76db3ba4 3561 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3562 EA = tcg_temp_new(); \
76db3ba4
AJ
3563 gen_addr_reg_index(ctx, EA); \
3564 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3565 tcg_temp_free(EA); \
79aceca5
FB
3566}
3567
a0d7d5a7
AJ
3568#define GEN_LDFS(name, ldop, op, type) \
3569GEN_LDF(name, ldop, op | 0x20, type); \
3570GEN_LDUF(name, ldop, op | 0x21, type); \
3571GEN_LDUXF(name, ldop, op | 0x01, type); \
3572GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3573
636aa200 3574static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3575{
3576 TCGv t0 = tcg_temp_new();
3577 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3578 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3579 tcg_gen_trunc_tl_i32(t1, t0);
3580 tcg_temp_free(t0);
8e703949 3581 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3582 tcg_temp_free_i32(t1);
3583}
79aceca5 3584
a0d7d5a7
AJ
3585 /* lfd lfdu lfdux lfdx */
3586GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3587 /* lfs lfsu lfsux lfsx */
3588GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3589
05050ee8
AJ
3590/* lfdp */
3591static void gen_lfdp(DisasContext *ctx)
3592{
3593 TCGv EA;
3594 if (unlikely(!ctx->fpu_enabled)) {
3595 gen_exception(ctx, POWERPC_EXCP_FPU);
3596 return;
3597 }
3598 gen_set_access_type(ctx, ACCESS_FLOAT);
3599 EA = tcg_temp_new();
e22c357b
DK
3600 gen_addr_imm_index(ctx, EA, 0);
3601 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3602 64-bit byteswap already. */
05050ee8
AJ
3603 if (unlikely(ctx->le_mode)) {
3604 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3605 tcg_gen_addi_tl(EA, EA, 8);
3606 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3607 } else {
3608 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3609 tcg_gen_addi_tl(EA, EA, 8);
3610 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3611 }
3612 tcg_temp_free(EA);
3613}
3614
3615/* lfdpx */
3616static void gen_lfdpx(DisasContext *ctx)
3617{
3618 TCGv EA;
3619 if (unlikely(!ctx->fpu_enabled)) {
3620 gen_exception(ctx, POWERPC_EXCP_FPU);
3621 return;
3622 }
3623 gen_set_access_type(ctx, ACCESS_FLOAT);
3624 EA = tcg_temp_new();
3625 gen_addr_reg_index(ctx, EA);
e22c357b
DK
3626 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3627 64-bit byteswap already. */
05050ee8
AJ
3628 if (unlikely(ctx->le_mode)) {
3629 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3630 tcg_gen_addi_tl(EA, EA, 8);
3631 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3632 } else {
3633 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3634 tcg_gen_addi_tl(EA, EA, 8);
3635 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3636 }
3637 tcg_temp_free(EA);
3638}
3639
199f830d
AJ
3640/* lfiwax */
3641static void gen_lfiwax(DisasContext *ctx)
3642{
3643 TCGv EA;
3644 TCGv t0;
3645 if (unlikely(!ctx->fpu_enabled)) {
3646 gen_exception(ctx, POWERPC_EXCP_FPU);
3647 return;
3648 }
3649 gen_set_access_type(ctx, ACCESS_FLOAT);
3650 EA = tcg_temp_new();
3651 t0 = tcg_temp_new();
3652 gen_addr_reg_index(ctx, EA);
909eedb7 3653 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3654 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3655 tcg_temp_free(EA);
3656 tcg_temp_free(t0);
3657}
3658
66c3e328
TM
3659/* lfiwzx */
3660static void gen_lfiwzx(DisasContext *ctx)
3661{
3662 TCGv EA;
3663 if (unlikely(!ctx->fpu_enabled)) {
3664 gen_exception(ctx, POWERPC_EXCP_FPU);
3665 return;
3666 }
3667 gen_set_access_type(ctx, ACCESS_FLOAT);
3668 EA = tcg_temp_new();
3669 gen_addr_reg_index(ctx, EA);
3670 gen_qemu_ld32u_i64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3671 tcg_temp_free(EA);
3672}
79aceca5 3673/*** Floating-point store ***/
a0d7d5a7 3674#define GEN_STF(name, stop, opc, type) \
99e300ef 3675static void glue(gen_, name)(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 } \
76db3ba4 3682 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3683 EA = tcg_temp_new(); \
76db3ba4
AJ
3684 gen_addr_imm_index(ctx, EA, 0); \
3685 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3686 tcg_temp_free(EA); \
79aceca5
FB
3687}
3688
a0d7d5a7 3689#define GEN_STUF(name, stop, opc, type) \
99e300ef 3690static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3691{ \
a0d7d5a7 3692 TCGv EA; \
76a66253 3693 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3694 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3695 return; \
3696 } \
76a66253 3697 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3698 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3699 return; \
9a64fbe4 3700 } \
76db3ba4 3701 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3702 EA = tcg_temp_new(); \
76db3ba4
AJ
3703 gen_addr_imm_index(ctx, EA, 0); \
3704 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3705 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3706 tcg_temp_free(EA); \
79aceca5
FB
3707}
3708
a0d7d5a7 3709#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3710static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3711{ \
a0d7d5a7 3712 TCGv EA; \
76a66253 3713 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3714 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3715 return; \
3716 } \
76a66253 3717 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3718 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3719 return; \
9a64fbe4 3720 } \
76db3ba4 3721 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3722 EA = tcg_temp_new(); \
76db3ba4
AJ
3723 gen_addr_reg_index(ctx, EA); \
3724 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3725 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3726 tcg_temp_free(EA); \
79aceca5
FB
3727}
3728
a0d7d5a7 3729#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3730static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3731{ \
a0d7d5a7 3732 TCGv EA; \
76a66253 3733 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3734 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3735 return; \
3736 } \
76db3ba4 3737 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3738 EA = tcg_temp_new(); \
76db3ba4
AJ
3739 gen_addr_reg_index(ctx, EA); \
3740 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3741 tcg_temp_free(EA); \
79aceca5
FB
3742}
3743
a0d7d5a7
AJ
3744#define GEN_STFS(name, stop, op, type) \
3745GEN_STF(name, stop, op | 0x20, type); \
3746GEN_STUF(name, stop, op | 0x21, type); \
3747GEN_STUXF(name, stop, op | 0x01, type); \
3748GEN_STXF(name, stop, 0x17, op | 0x00, type)
3749
636aa200 3750static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3751{
3752 TCGv_i32 t0 = tcg_temp_new_i32();
3753 TCGv t1 = tcg_temp_new();
8e703949 3754 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3755 tcg_gen_extu_i32_tl(t1, t0);
3756 tcg_temp_free_i32(t0);
76db3ba4 3757 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3758 tcg_temp_free(t1);
3759}
79aceca5
FB
3760
3761/* stfd stfdu stfdux stfdx */
a0d7d5a7 3762GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3763/* stfs stfsu stfsux stfsx */
a0d7d5a7 3764GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3765
44bc0c4d
AJ
3766/* stfdp */
3767static void gen_stfdp(DisasContext *ctx)
3768{
3769 TCGv EA;
3770 if (unlikely(!ctx->fpu_enabled)) {
3771 gen_exception(ctx, POWERPC_EXCP_FPU);
3772 return;
3773 }
3774 gen_set_access_type(ctx, ACCESS_FLOAT);
3775 EA = tcg_temp_new();
e22c357b
DK
3776 gen_addr_imm_index(ctx, EA, 0);
3777 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3778 64-bit byteswap already. */
44bc0c4d
AJ
3779 if (unlikely(ctx->le_mode)) {
3780 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3781 tcg_gen_addi_tl(EA, EA, 8);
3782 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3783 } else {
3784 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3785 tcg_gen_addi_tl(EA, EA, 8);
3786 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3787 }
3788 tcg_temp_free(EA);
3789}
3790
3791/* stfdpx */
3792static void gen_stfdpx(DisasContext *ctx)
3793{
3794 TCGv EA;
3795 if (unlikely(!ctx->fpu_enabled)) {
3796 gen_exception(ctx, POWERPC_EXCP_FPU);
3797 return;
3798 }
3799 gen_set_access_type(ctx, ACCESS_FLOAT);
3800 EA = tcg_temp_new();
3801 gen_addr_reg_index(ctx, EA);
e22c357b
DK
3802 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3803 64-bit byteswap already. */
44bc0c4d
AJ
3804 if (unlikely(ctx->le_mode)) {
3805 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3806 tcg_gen_addi_tl(EA, EA, 8);
3807 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3808 } else {
3809 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3810 tcg_gen_addi_tl(EA, EA, 8);
3811 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3812 }
3813 tcg_temp_free(EA);
3814}
3815
79aceca5 3816/* Optional: */
636aa200 3817static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3818{
3819 TCGv t0 = tcg_temp_new();
3820 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3821 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3822 tcg_temp_free(t0);
3823}
79aceca5 3824/* stfiwx */
a0d7d5a7 3825GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3826
697ab892
DG
3827static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3828{
3829#if defined(TARGET_PPC64)
3830 if (ctx->has_cfar)
3831 tcg_gen_movi_tl(cpu_cfar, nip);
3832#endif
3833}
3834
90aa39a1
SF
3835static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest)
3836{
3837 if (unlikely(ctx->singlestep_enabled)) {
3838 return false;
3839 }
3840
3841#ifndef CONFIG_USER_ONLY
3842 return (ctx->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK);
3843#else
3844 return true;
3845#endif
3846}
3847
79aceca5 3848/*** Branch ***/
636aa200 3849static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362 3850{
e0c8f9ce 3851 if (NARROW_MODE(ctx)) {
a2ffb812 3852 dest = (uint32_t) dest;
e0c8f9ce 3853 }
90aa39a1 3854 if (use_goto_tb(ctx, dest)) {
57fec1fe 3855 tcg_gen_goto_tb(n);
a2ffb812 3856 tcg_gen_movi_tl(cpu_nip, dest & ~3);
90aa39a1 3857 tcg_gen_exit_tb((uintptr_t)ctx->tb + n);
c1942362 3858 } else {
a2ffb812 3859 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3860 if (unlikely(ctx->singlestep_enabled)) {
3861 if ((ctx->singlestep_enabled &
bdc4e053 3862 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3863 (ctx->exception == POWERPC_EXCP_BRANCH ||
3864 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3865 target_ulong tmp = ctx->nip;
3866 ctx->nip = dest;
e06fcd75 3867 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3868 ctx->nip = tmp;
3869 }
3870 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3871 gen_debug_exception(ctx);
8cbcb4fa
AJ
3872 }
3873 }
57fec1fe 3874 tcg_gen_exit_tb(0);
c1942362 3875 }
c53be334
FB
3876}
3877
636aa200 3878static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3879{
e0c8f9ce
RH
3880 if (NARROW_MODE(ctx)) {
3881 nip = (uint32_t)nip;
3882 }
3883 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3884}
3885
79aceca5 3886/* b ba bl bla */
99e300ef 3887static void gen_b(DisasContext *ctx)
79aceca5 3888{
76a66253 3889 target_ulong li, target;
38a64f9d 3890
8cbcb4fa 3891 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3892 /* sign extend LI */
e0c8f9ce
RH
3893 li = LI(ctx->opcode);
3894 li = (li ^ 0x02000000) - 0x02000000;
3895 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3896 target = ctx->nip + li - 4;
e0c8f9ce 3897 } else {
9a64fbe4 3898 target = li;
e0c8f9ce
RH
3899 }
3900 if (LK(ctx->opcode)) {
e1833e1f 3901 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3902 }
697ab892 3903 gen_update_cfar(ctx, ctx->nip);
c1942362 3904 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3905}
3906
e98a6e40
FB
3907#define BCOND_IM 0
3908#define BCOND_LR 1
3909#define BCOND_CTR 2
52a4984d 3910#define BCOND_TAR 3
e98a6e40 3911
636aa200 3912static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3913{
d9bce9d9 3914 uint32_t bo = BO(ctx->opcode);
42a268c2 3915 TCGLabel *l1;
a2ffb812 3916 TCGv target;
e98a6e40 3917
8cbcb4fa 3918 ctx->exception = POWERPC_EXCP_BRANCH;
52a4984d 3919 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
a7812ae4 3920 target = tcg_temp_local_new();
a2ffb812
AJ
3921 if (type == BCOND_CTR)
3922 tcg_gen_mov_tl(target, cpu_ctr);
52a4984d
TM
3923 else if (type == BCOND_TAR)
3924 gen_load_spr(target, SPR_TAR);
a2ffb812
AJ
3925 else
3926 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3927 } else {
3928 TCGV_UNUSED(target);
e98a6e40 3929 }
e1833e1f
JM
3930 if (LK(ctx->opcode))
3931 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3932 l1 = gen_new_label();
3933 if ((bo & 0x4) == 0) {
3934 /* Decrement and test CTR */
a7812ae4 3935 TCGv temp = tcg_temp_new();
a2ffb812 3936 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3937 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3938 return;
3939 }
3940 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3941 if (NARROW_MODE(ctx)) {
a2ffb812 3942 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3943 } else {
a2ffb812 3944 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3945 }
a2ffb812
AJ
3946 if (bo & 0x2) {
3947 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3948 } else {
3949 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3950 }
a7812ae4 3951 tcg_temp_free(temp);
a2ffb812
AJ
3952 }
3953 if ((bo & 0x10) == 0) {
3954 /* Test CR */
3955 uint32_t bi = BI(ctx->opcode);
8f9fb7ac 3956 uint32_t mask = 0x08 >> (bi & 0x03);
a7812ae4 3957 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3958
d9bce9d9 3959 if (bo & 0x8) {
a2ffb812
AJ
3960 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3961 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3962 } else {
a2ffb812
AJ
3963 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3964 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3965 }
a7812ae4 3966 tcg_temp_free_i32(temp);
d9bce9d9 3967 }
697ab892 3968 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3969 if (type == BCOND_IM) {
a2ffb812
AJ
3970 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3971 if (likely(AA(ctx->opcode) == 0)) {
3972 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3973 } else {
3974 gen_goto_tb(ctx, 0, li);
3975 }
c53be334 3976 gen_set_label(l1);
c1942362 3977 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3978 } else {
e0c8f9ce 3979 if (NARROW_MODE(ctx)) {
a2ffb812 3980 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3981 } else {
a2ffb812 3982 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3983 }
a2ffb812
AJ
3984 tcg_gen_exit_tb(0);
3985 gen_set_label(l1);
e0c8f9ce 3986 gen_update_nip(ctx, ctx->nip);
57fec1fe 3987 tcg_gen_exit_tb(0);
08e46e54 3988 }
a9e8f4e7 3989 if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
c80d1df5
AG
3990 tcg_temp_free(target);
3991 }
e98a6e40
FB
3992}
3993
99e300ef 3994static void gen_bc(DisasContext *ctx)
3b46e624 3995{
e98a6e40
FB
3996 gen_bcond(ctx, BCOND_IM);
3997}
3998
99e300ef 3999static void gen_bcctr(DisasContext *ctx)
3b46e624 4000{
e98a6e40
FB
4001 gen_bcond(ctx, BCOND_CTR);
4002}
4003
99e300ef 4004static void gen_bclr(DisasContext *ctx)
3b46e624 4005{
e98a6e40
FB
4006 gen_bcond(ctx, BCOND_LR);
4007}
79aceca5 4008
52a4984d
TM
4009static void gen_bctar(DisasContext *ctx)
4010{
4011 gen_bcond(ctx, BCOND_TAR);
4012}
4013
79aceca5 4014/*** Condition register logical ***/
e1571908 4015#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 4016static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 4017{ \
fc0d441e
JM
4018 uint8_t bitmask; \
4019 int sh; \
a7812ae4 4020 TCGv_i32 t0, t1; \
fc0d441e 4021 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 4022 t0 = tcg_temp_new_i32(); \
fc0d441e 4023 if (sh > 0) \
fea0c503 4024 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 4025 else if (sh < 0) \
fea0c503 4026 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 4027 else \
fea0c503 4028 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 4029 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
4030 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4031 if (sh > 0) \
fea0c503 4032 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 4033 else if (sh < 0) \
fea0c503 4034 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 4035 else \
fea0c503
AJ
4036 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4037 tcg_op(t0, t0, t1); \
8f9fb7ac 4038 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
fea0c503
AJ
4039 tcg_gen_andi_i32(t0, t0, bitmask); \
4040 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4041 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
4042 tcg_temp_free_i32(t0); \
4043 tcg_temp_free_i32(t1); \
79aceca5
FB
4044}
4045
4046/* crand */
e1571908 4047GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 4048/* crandc */
e1571908 4049GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 4050/* creqv */
e1571908 4051GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 4052/* crnand */
e1571908 4053GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 4054/* crnor */
e1571908 4055GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 4056/* cror */
e1571908 4057GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 4058/* crorc */
e1571908 4059GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 4060/* crxor */
e1571908 4061GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 4062
54623277 4063/* mcrf */
99e300ef 4064static void gen_mcrf(DisasContext *ctx)
79aceca5 4065{
47e4661c 4066 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
4067}
4068
4069/*** System linkage ***/
99e300ef 4070
c47493f2 4071/* rfi (supervisor only) */
99e300ef 4072static void gen_rfi(DisasContext *ctx)
79aceca5 4073{
9a64fbe4 4074#if defined(CONFIG_USER_ONLY)
e06fcd75 4075 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
4076#else
4077 /* Restore CPU state */
c47493f2 4078 if (unlikely(ctx->pr)) {
e06fcd75 4079 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4080 return;
9a64fbe4 4081 }
697ab892 4082 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4083 gen_helper_rfi(cpu_env);
e06fcd75 4084 gen_sync_exception(ctx);
9a64fbe4 4085#endif
79aceca5
FB
4086}
4087
426613db 4088#if defined(TARGET_PPC64)
99e300ef 4089static void gen_rfid(DisasContext *ctx)
426613db
JM
4090{
4091#if defined(CONFIG_USER_ONLY)
e06fcd75 4092 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4093#else
4094 /* Restore CPU state */
c47493f2 4095 if (unlikely(ctx->pr)) {
e06fcd75 4096 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4097 return;
4098 }
697ab892 4099 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 4100 gen_helper_rfid(cpu_env);
e06fcd75 4101 gen_sync_exception(ctx);
426613db
JM
4102#endif
4103}
426613db 4104
99e300ef 4105static void gen_hrfid(DisasContext *ctx)
be147d08
JM
4106{
4107#if defined(CONFIG_USER_ONLY)
e06fcd75 4108 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4109#else
4110 /* Restore CPU state */
1c7336c5 4111 if (unlikely(ctx->pr || !ctx->hv)) {
e06fcd75 4112 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
4113 return;
4114 }
e5f17ac6 4115 gen_helper_hrfid(cpu_env);
e06fcd75 4116 gen_sync_exception(ctx);
be147d08
JM
4117#endif
4118}
4119#endif
4120
79aceca5 4121/* sc */
417bf010
JM
4122#if defined(CONFIG_USER_ONLY)
4123#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4124#else
4125#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4126#endif
99e300ef 4127static void gen_sc(DisasContext *ctx)
79aceca5 4128{
e1833e1f
JM
4129 uint32_t lev;
4130
4131 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 4132 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
4133}
4134
4135/*** Trap ***/
99e300ef 4136
54623277 4137/* tw */
99e300ef 4138static void gen_tw(DisasContext *ctx)
79aceca5 4139{
cab3bee2 4140 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4141 /* Update the nip since this might generate a trap exception */
4142 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4143 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4144 t0);
cab3bee2 4145 tcg_temp_free_i32(t0);
79aceca5
FB
4146}
4147
4148/* twi */
99e300ef 4149static void gen_twi(DisasContext *ctx)
79aceca5 4150{
cab3bee2
AJ
4151 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4152 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4153 /* Update the nip since this might generate a trap exception */
4154 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4155 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4156 tcg_temp_free(t0);
4157 tcg_temp_free_i32(t1);
79aceca5
FB
4158}
4159
d9bce9d9
JM
4160#if defined(TARGET_PPC64)
4161/* td */
99e300ef 4162static void gen_td(DisasContext *ctx)
d9bce9d9 4163{
cab3bee2 4164 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4165 /* Update the nip since this might generate a trap exception */
4166 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
4167 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
4168 t0);
cab3bee2 4169 tcg_temp_free_i32(t0);
d9bce9d9
JM
4170}
4171
4172/* tdi */
99e300ef 4173static void gen_tdi(DisasContext *ctx)
d9bce9d9 4174{
cab3bee2
AJ
4175 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
4176 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
4177 /* Update the nip since this might generate a trap exception */
4178 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4179 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
4180 tcg_temp_free(t0);
4181 tcg_temp_free_i32(t1);
d9bce9d9
JM
4182}
4183#endif
4184
79aceca5 4185/*** Processor control ***/
99e300ef 4186
da91a00f
RH
4187static void gen_read_xer(TCGv dst)
4188{
4189 TCGv t0 = tcg_temp_new();
4190 TCGv t1 = tcg_temp_new();
4191 TCGv t2 = tcg_temp_new();
4192 tcg_gen_mov_tl(dst, cpu_xer);
4193 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
4194 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
4195 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
4196 tcg_gen_or_tl(t0, t0, t1);
4197 tcg_gen_or_tl(dst, dst, t2);
4198 tcg_gen_or_tl(dst, dst, t0);
4199 tcg_temp_free(t0);
4200 tcg_temp_free(t1);
4201 tcg_temp_free(t2);
4202}
4203
4204static void gen_write_xer(TCGv src)
4205{
4206 tcg_gen_andi_tl(cpu_xer, src,
4207 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
4208 tcg_gen_shri_tl(cpu_so, src, XER_SO);
4209 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
4210 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
4211 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
4212 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
4213 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
4214}
4215
54623277 4216/* mcrxr */
99e300ef 4217static void gen_mcrxr(DisasContext *ctx)
79aceca5 4218{
da91a00f
RH
4219 TCGv_i32 t0 = tcg_temp_new_i32();
4220 TCGv_i32 t1 = tcg_temp_new_i32();
4221 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
4222
4223 tcg_gen_trunc_tl_i32(t0, cpu_so);
4224 tcg_gen_trunc_tl_i32(t1, cpu_ov);
4225 tcg_gen_trunc_tl_i32(dst, cpu_ca);
294d1292
SB
4226 tcg_gen_shli_i32(t0, t0, 3);
4227 tcg_gen_shli_i32(t1, t1, 2);
4228 tcg_gen_shli_i32(dst, dst, 1);
da91a00f
RH
4229 tcg_gen_or_i32(dst, dst, t0);
4230 tcg_gen_or_i32(dst, dst, t1);
4231 tcg_temp_free_i32(t0);
4232 tcg_temp_free_i32(t1);
4233
4234 tcg_gen_movi_tl(cpu_so, 0);
4235 tcg_gen_movi_tl(cpu_ov, 0);
4236 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
4237}
4238
0cfe11ea 4239/* mfcr mfocrf */
99e300ef 4240static void gen_mfcr(DisasContext *ctx)
79aceca5 4241{
76a66253 4242 uint32_t crm, crn;
3b46e624 4243
76a66253
JM
4244 if (likely(ctx->opcode & 0x00100000)) {
4245 crm = CRM(ctx->opcode);
8dd640e4 4246 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 4247 crn = ctz32 (crm);
e1571908 4248 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
4249 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
4250 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 4251 }
d9bce9d9 4252 } else {
651721b2
AJ
4253 TCGv_i32 t0 = tcg_temp_new_i32();
4254 tcg_gen_mov_i32(t0, cpu_crf[0]);
4255 tcg_gen_shli_i32(t0, t0, 4);
4256 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
4257 tcg_gen_shli_i32(t0, t0, 4);
4258 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
4259 tcg_gen_shli_i32(t0, t0, 4);
4260 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
4261 tcg_gen_shli_i32(t0, t0, 4);
4262 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
4263 tcg_gen_shli_i32(t0, t0, 4);
4264 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
4265 tcg_gen_shli_i32(t0, t0, 4);
4266 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
4267 tcg_gen_shli_i32(t0, t0, 4);
4268 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
4269 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
4270 tcg_temp_free_i32(t0);
d9bce9d9 4271 }
79aceca5
FB
4272}
4273
4274/* mfmsr */
99e300ef 4275static void gen_mfmsr(DisasContext *ctx)
79aceca5 4276{
9a64fbe4 4277#if defined(CONFIG_USER_ONLY)
e06fcd75 4278 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4279#else
c47493f2 4280 if (unlikely(ctx->pr)) {
e06fcd75 4281 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4282 return;
9a64fbe4 4283 }
6527f6ea 4284 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4285#endif
79aceca5
FB
4286}
4287
69b058c8 4288static void spr_noaccess(DisasContext *ctx, int gprn, int sprn)
3fc6c082 4289{
7b13448f 4290#if 0
3fc6c082
FB
4291 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4292 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4293#endif
3fc6c082
FB
4294}
4295#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4296
79aceca5 4297/* mfspr */
636aa200 4298static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4299{
69b058c8 4300 void (*read_cb)(DisasContext *ctx, int gprn, int sprn);
79aceca5
FB
4301 uint32_t sprn = SPR(ctx->opcode);
4302
eb94268e
BH
4303#if defined(CONFIG_USER_ONLY)
4304 read_cb = ctx->spr_cb[sprn].uea_read;
4305#else
4306 if (ctx->pr) {
4307 read_cb = ctx->spr_cb[sprn].uea_read;
4308 } else if (ctx->hv) {
be147d08 4309 read_cb = ctx->spr_cb[sprn].hea_read;
eb94268e 4310 } else {
3fc6c082 4311 read_cb = ctx->spr_cb[sprn].oea_read;
eb94268e 4312 }
9a64fbe4 4313#endif
76a66253
JM
4314 if (likely(read_cb != NULL)) {
4315 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4316 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4317 } else {
4318 /* Privilege exception */
9fceefa7
JM
4319 /* This is a hack to avoid warnings when running Linux:
4320 * this OS breaks the PowerPC virtualisation model,
4321 * allowing userland application to read the PVR
4322 */
4323 if (sprn != SPR_PVR) {
013a2942
PB
4324 fprintf(stderr, "Trying to read privileged spr %d (0x%03x) at "
4325 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4326 if (qemu_log_separate()) {
4327 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4328 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4329 }
f24e5695 4330 }
e06fcd75 4331 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4332 }
3fc6c082
FB
4333 } else {
4334 /* Not defined */
013a2942
PB
4335 fprintf(stderr, "Trying to read invalid spr %d (0x%03x) at "
4336 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4337 if (qemu_log_separate()) {
4338 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4339 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4340 }
e06fcd75 4341 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4342 }
79aceca5
FB
4343}
4344
99e300ef 4345static void gen_mfspr(DisasContext *ctx)
79aceca5 4346{
3fc6c082 4347 gen_op_mfspr(ctx);
76a66253 4348}
3fc6c082
FB
4349
4350/* mftb */
99e300ef 4351static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4352{
4353 gen_op_mfspr(ctx);
79aceca5
FB
4354}
4355
0cfe11ea 4356/* mtcrf mtocrf*/
99e300ef 4357static void gen_mtcrf(DisasContext *ctx)
79aceca5 4358{
76a66253 4359 uint32_t crm, crn;
3b46e624 4360
76a66253 4361 crm = CRM(ctx->opcode);
8dd640e4 4362 if (likely((ctx->opcode & 0x00100000))) {
4363 if (crm && ((crm & (crm - 1)) == 0)) {
4364 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4365 crn = ctz32 (crm);
8dd640e4 4366 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4367 tcg_gen_shri_i32(temp, temp, crn * 4);
4368 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4369 tcg_temp_free_i32(temp);
4370 }
76a66253 4371 } else {
651721b2
AJ
4372 TCGv_i32 temp = tcg_temp_new_i32();
4373 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4374 for (crn = 0 ; crn < 8 ; crn++) {
4375 if (crm & (1 << crn)) {
4376 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4377 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4378 }
4379 }
a7812ae4 4380 tcg_temp_free_i32(temp);
76a66253 4381 }
79aceca5
FB
4382}
4383
4384/* mtmsr */
426613db 4385#if defined(TARGET_PPC64)
99e300ef 4386static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4387{
4388#if defined(CONFIG_USER_ONLY)
e06fcd75 4389 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4390#else
c47493f2 4391 if (unlikely(ctx->pr)) {
e06fcd75 4392 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4393 return;
4394 }
be147d08
JM
4395 if (ctx->opcode & 0x00010000) {
4396 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4397 TCGv t0 = tcg_temp_new();
4398 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
c409bc5d 4399 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(target_ulong)((1 << MSR_RI) | (1 << MSR_EE)));
6527f6ea
AJ
4400 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4401 tcg_temp_free(t0);
be147d08 4402 } else {
056b05f8
JM
4403 /* XXX: we need to update nip before the store
4404 * if we enter power saving mode, we will exit the loop
4405 * directly from ppc_store_msr
4406 */
be147d08 4407 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4408 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4409 /* Must stop the translation as machine state (may have) changed */
4410 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4411 gen_stop_exception(ctx);
be147d08 4412 }
426613db
JM
4413#endif
4414}
4415#endif
4416
99e300ef 4417static void gen_mtmsr(DisasContext *ctx)
79aceca5 4418{
9a64fbe4 4419#if defined(CONFIG_USER_ONLY)
e06fcd75 4420 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4421#else
c47493f2 4422 if (unlikely(ctx->pr)) {
e06fcd75 4423 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4424 return;
9a64fbe4 4425 }
be147d08
JM
4426 if (ctx->opcode & 0x00010000) {
4427 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4428 TCGv t0 = tcg_temp_new();
4429 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
c409bc5d 4430 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(target_ulong)((1 << MSR_RI) | (1 << MSR_EE)));
6527f6ea
AJ
4431 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4432 tcg_temp_free(t0);
be147d08 4433 } else {
8018dc63
AG
4434 TCGv msr = tcg_temp_new();
4435
056b05f8
JM
4436 /* XXX: we need to update nip before the store
4437 * if we enter power saving mode, we will exit the loop
4438 * directly from ppc_store_msr
4439 */
be147d08 4440 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4441#if defined(TARGET_PPC64)
8018dc63
AG
4442 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4443#else
4444 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4445#endif
e5f17ac6 4446 gen_helper_store_msr(cpu_env, msr);
c80d1df5 4447 tcg_temp_free(msr);
be147d08 4448 /* Must stop the translation as machine state (may have) changed */
6527f6ea 4449 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4450 gen_stop_exception(ctx);
be147d08 4451 }
9a64fbe4 4452#endif
79aceca5
FB
4453}
4454
4455/* mtspr */
99e300ef 4456static void gen_mtspr(DisasContext *ctx)
79aceca5 4457{
69b058c8 4458 void (*write_cb)(DisasContext *ctx, int sprn, int gprn);
79aceca5
FB
4459 uint32_t sprn = SPR(ctx->opcode);
4460
eb94268e
BH
4461#if defined(CONFIG_USER_ONLY)
4462 write_cb = ctx->spr_cb[sprn].uea_write;
4463#else
4464 if (ctx->pr) {
4465 write_cb = ctx->spr_cb[sprn].uea_write;
4466 } else if (ctx->hv) {
be147d08 4467 write_cb = ctx->spr_cb[sprn].hea_write;
eb94268e 4468 } else {
3fc6c082 4469 write_cb = ctx->spr_cb[sprn].oea_write;
eb94268e 4470 }
9a64fbe4 4471#endif
76a66253
JM
4472 if (likely(write_cb != NULL)) {
4473 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 4474 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
4475 } else {
4476 /* Privilege exception */
013a2942
PB
4477 fprintf(stderr, "Trying to write privileged spr %d (0x%03x) at "
4478 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4479 if (qemu_log_separate()) {
4480 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4481 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4482 }
e06fcd75 4483 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 4484 }
3fc6c082
FB
4485 } else {
4486 /* Not defined */
013a2942
PB
4487 if (qemu_log_separate()) {
4488 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4489 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4490 }
4491 fprintf(stderr, "Trying to write invalid spr %d (0x%03x) at "
4492 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4493 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4494 }
79aceca5
FB
4495}
4496
4497/*** Cache management ***/
99e300ef 4498
54623277 4499/* dcbf */
99e300ef 4500static void gen_dcbf(DisasContext *ctx)
79aceca5 4501{
dac454af 4502 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
4503 TCGv t0;
4504 gen_set_access_type(ctx, ACCESS_CACHE);
4505 t0 = tcg_temp_new();
4506 gen_addr_reg_index(ctx, t0);
4507 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4508 tcg_temp_free(t0);
79aceca5
FB
4509}
4510
4511/* dcbi (Supervisor only) */
99e300ef 4512static void gen_dcbi(DisasContext *ctx)
79aceca5 4513{
a541f297 4514#if defined(CONFIG_USER_ONLY)
e06fcd75 4515 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 4516#else
b61f2753 4517 TCGv EA, val;
c47493f2 4518 if (unlikely(ctx->pr)) {
e06fcd75 4519 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4520 return;
9a64fbe4 4521 }
a7812ae4 4522 EA = tcg_temp_new();
76db3ba4
AJ
4523 gen_set_access_type(ctx, ACCESS_CACHE);
4524 gen_addr_reg_index(ctx, EA);
a7812ae4 4525 val = tcg_temp_new();
76a66253 4526 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
4527 gen_qemu_ld8u(ctx, val, EA);
4528 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
4529 tcg_temp_free(val);
4530 tcg_temp_free(EA);
a541f297 4531#endif
79aceca5
FB
4532}
4533
4534/* dcdst */
99e300ef 4535static void gen_dcbst(DisasContext *ctx)
79aceca5 4536{
76a66253 4537 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
4538 TCGv t0;
4539 gen_set_access_type(ctx, ACCESS_CACHE);
4540 t0 = tcg_temp_new();
4541 gen_addr_reg_index(ctx, t0);
4542 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4543 tcg_temp_free(t0);
79aceca5
FB
4544}
4545
4546/* dcbt */
99e300ef 4547static void gen_dcbt(DisasContext *ctx)
79aceca5 4548{
0db1b20e 4549 /* interpreted as no-op */
76a66253
JM
4550 /* XXX: specification say this is treated as a load by the MMU
4551 * but does not generate any exception
4552 */
79aceca5
FB
4553}
4554
4555/* dcbtst */
99e300ef 4556static void gen_dcbtst(DisasContext *ctx)
79aceca5 4557{
0db1b20e 4558 /* interpreted as no-op */
76a66253
JM
4559 /* XXX: specification say this is treated as a load by the MMU
4560 * but does not generate any exception
4561 */
79aceca5
FB
4562}
4563
4d09d529
AG
4564/* dcbtls */
4565static void gen_dcbtls(DisasContext *ctx)
4566{
4567 /* Always fails locking the cache */
4568 TCGv t0 = tcg_temp_new();
4569 gen_load_spr(t0, SPR_Exxx_L1CSR0);
4570 tcg_gen_ori_tl(t0, t0, L1CSR0_CUL);
4571 gen_store_spr(SPR_Exxx_L1CSR0, t0);
4572 tcg_temp_free(t0);
4573}
4574
79aceca5 4575/* dcbz */
99e300ef 4576static void gen_dcbz(DisasContext *ctx)
79aceca5 4577{
8e33944f
AG
4578 TCGv tcgv_addr;
4579 TCGv_i32 tcgv_is_dcbzl;
4580 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4581
76db3ba4 4582 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4583 /* NIP cannot be restored if the memory exception comes from an helper */
4584 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4585 tcgv_addr = tcg_temp_new();
4586 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4587
4588 gen_addr_reg_index(ctx, tcgv_addr);
4589 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4590
4591 tcg_temp_free(tcgv_addr);
4592 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4593}
4594
ae1c1a3d 4595/* dst / dstt */
99e300ef 4596static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4597{
4598 if (rA(ctx->opcode) == 0) {
4599 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4600 } else {
4601 /* interpreted as no-op */
4602 }
4603}
4604
4605/* dstst /dststt */
99e300ef 4606static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4607{
4608 if (rA(ctx->opcode) == 0) {
4609 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4610 } else {
4611 /* interpreted as no-op */
4612 }
4613
4614}
4615
4616/* dss / dssall */
99e300ef 4617static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4618{
4619 /* interpreted as no-op */
4620}
4621
79aceca5 4622/* icbi */
99e300ef 4623static void gen_icbi(DisasContext *ctx)
79aceca5 4624{
76db3ba4
AJ
4625 TCGv t0;
4626 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4627 /* NIP cannot be restored if the memory exception comes from an helper */
4628 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4629 t0 = tcg_temp_new();
4630 gen_addr_reg_index(ctx, t0);
2f5a189c 4631 gen_helper_icbi(cpu_env, t0);
37d269df 4632 tcg_temp_free(t0);
79aceca5
FB
4633}
4634
4635/* Optional: */
4636/* dcba */
99e300ef 4637static void gen_dcba(DisasContext *ctx)
79aceca5 4638{
0db1b20e
JM
4639 /* interpreted as no-op */
4640 /* XXX: specification say this is treated as a store by the MMU
4641 * but does not generate any exception
4642 */
79aceca5
FB
4643}
4644
4645/*** Segment register manipulation ***/
4646/* Supervisor only: */
99e300ef 4647
54623277 4648/* mfsr */
99e300ef 4649static void gen_mfsr(DisasContext *ctx)
79aceca5 4650{
9a64fbe4 4651#if defined(CONFIG_USER_ONLY)
e06fcd75 4652 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4653#else
74d37793 4654 TCGv t0;
c47493f2 4655 if (unlikely(ctx->pr)) {
e06fcd75 4656 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4657 return;
9a64fbe4 4658 }
74d37793 4659 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4660 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4661 tcg_temp_free(t0);
9a64fbe4 4662#endif
79aceca5
FB
4663}
4664
4665/* mfsrin */
99e300ef 4666static void gen_mfsrin(DisasContext *ctx)
79aceca5 4667{
9a64fbe4 4668#if defined(CONFIG_USER_ONLY)
e06fcd75 4669 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4670#else
74d37793 4671 TCGv t0;
c47493f2 4672 if (unlikely(ctx->pr)) {
e06fcd75 4673 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4674 return;
9a64fbe4 4675 }
74d37793
AJ
4676 t0 = tcg_temp_new();
4677 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4678 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4679 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4680 tcg_temp_free(t0);
9a64fbe4 4681#endif
79aceca5
FB
4682}
4683
4684/* mtsr */
99e300ef 4685static void gen_mtsr(DisasContext *ctx)
79aceca5 4686{
9a64fbe4 4687#if defined(CONFIG_USER_ONLY)
e06fcd75 4688 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4689#else
74d37793 4690 TCGv t0;
c47493f2 4691 if (unlikely(ctx->pr)) {
e06fcd75 4692 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4693 return;
9a64fbe4 4694 }
74d37793 4695 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4696 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4697 tcg_temp_free(t0);
9a64fbe4 4698#endif
79aceca5
FB
4699}
4700
4701/* mtsrin */
99e300ef 4702static void gen_mtsrin(DisasContext *ctx)
79aceca5 4703{
9a64fbe4 4704#if defined(CONFIG_USER_ONLY)
e06fcd75 4705 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4706#else
74d37793 4707 TCGv t0;
c47493f2 4708 if (unlikely(ctx->pr)) {
e06fcd75 4709 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4710 return;
9a64fbe4 4711 }
74d37793
AJ
4712 t0 = tcg_temp_new();
4713 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4714 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4715 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4716 tcg_temp_free(t0);
9a64fbe4 4717#endif
79aceca5
FB
4718}
4719
12de9a39
JM
4720#if defined(TARGET_PPC64)
4721/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4722
54623277 4723/* mfsr */
e8eaa2c0 4724static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4725{
4726#if defined(CONFIG_USER_ONLY)
e06fcd75 4727 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4728#else
74d37793 4729 TCGv t0;
c47493f2 4730 if (unlikely(ctx->pr)) {
e06fcd75 4731 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4732 return;
4733 }
74d37793 4734 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4735 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4736 tcg_temp_free(t0);
12de9a39
JM
4737#endif
4738}
4739
4740/* mfsrin */
e8eaa2c0 4741static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4742{
4743#if defined(CONFIG_USER_ONLY)
e06fcd75 4744 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4745#else
74d37793 4746 TCGv t0;
c47493f2 4747 if (unlikely(ctx->pr)) {
e06fcd75 4748 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4749 return;
4750 }
74d37793
AJ
4751 t0 = tcg_temp_new();
4752 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4753 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4754 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4755 tcg_temp_free(t0);
12de9a39
JM
4756#endif
4757}
4758
4759/* mtsr */
e8eaa2c0 4760static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4761{
4762#if defined(CONFIG_USER_ONLY)
e06fcd75 4763 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4764#else
74d37793 4765 TCGv t0;
c47493f2 4766 if (unlikely(ctx->pr)) {
e06fcd75 4767 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4768 return;
4769 }
74d37793 4770 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4771 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4772 tcg_temp_free(t0);
12de9a39
JM
4773#endif
4774}
4775
4776/* mtsrin */
e8eaa2c0 4777static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4778{
4779#if defined(CONFIG_USER_ONLY)
e06fcd75 4780 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4781#else
74d37793 4782 TCGv t0;
c47493f2 4783 if (unlikely(ctx->pr)) {
e06fcd75 4784 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4785 return;
4786 }
74d37793
AJ
4787 t0 = tcg_temp_new();
4788 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4789 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4790 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4791 tcg_temp_free(t0);
12de9a39
JM
4792#endif
4793}
f6b868fc
BS
4794
4795/* slbmte */
e8eaa2c0 4796static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4797{
4798#if defined(CONFIG_USER_ONLY)
4799 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4800#else
c47493f2 4801 if (unlikely(ctx->pr)) {
f6b868fc
BS
4802 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4803 return;
4804 }
c6c7cf05
BS
4805 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4806 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4807#endif
4808}
4809
efdef95f
DG
4810static void gen_slbmfee(DisasContext *ctx)
4811{
4812#if defined(CONFIG_USER_ONLY)
4813 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4814#else
c47493f2 4815 if (unlikely(ctx->pr)) {
efdef95f
DG
4816 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4817 return;
4818 }
c6c7cf05 4819 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4820 cpu_gpr[rB(ctx->opcode)]);
4821#endif
4822}
4823
4824static void gen_slbmfev(DisasContext *ctx)
4825{
4826#if defined(CONFIG_USER_ONLY)
4827 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4828#else
c47493f2 4829 if (unlikely(ctx->pr)) {
efdef95f
DG
4830 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4831 return;
4832 }
c6c7cf05 4833 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4834 cpu_gpr[rB(ctx->opcode)]);
4835#endif
4836}
12de9a39
JM
4837#endif /* defined(TARGET_PPC64) */
4838
79aceca5 4839/*** Lookaside buffer management ***/
c47493f2 4840/* Optional & supervisor only: */
99e300ef 4841
54623277 4842/* tlbia */
99e300ef 4843static void gen_tlbia(DisasContext *ctx)
79aceca5 4844{
9a64fbe4 4845#if defined(CONFIG_USER_ONLY)
e06fcd75 4846 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4847#else
1c7336c5 4848 if (unlikely(ctx->pr || !ctx->hv)) {
e06fcd75 4849 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4850 return;
9a64fbe4 4851 }
c6c7cf05 4852 gen_helper_tlbia(cpu_env);
9a64fbe4 4853#endif
79aceca5
FB
4854}
4855
bf14b1ce 4856/* tlbiel */
99e300ef 4857static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4858{
4859#if defined(CONFIG_USER_ONLY)
4860 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4861#else
c47493f2 4862 if (unlikely(ctx->pr)) {
bf14b1ce
BS
4863 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4864 return;
4865 }
c6c7cf05 4866 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4867#endif
4868}
4869
79aceca5 4870/* tlbie */
99e300ef 4871static void gen_tlbie(DisasContext *ctx)
79aceca5 4872{
9a64fbe4 4873#if defined(CONFIG_USER_ONLY)
e06fcd75 4874 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4875#else
74693da9 4876 if (unlikely(ctx->pr || !ctx->hv)) {
e06fcd75 4877 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4878 return;
9a64fbe4 4879 }
9ca3f7f3 4880 if (NARROW_MODE(ctx)) {
74d37793
AJ
4881 TCGv t0 = tcg_temp_new();
4882 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4883 gen_helper_tlbie(cpu_env, t0);
74d37793 4884 tcg_temp_free(t0);
9ca3f7f3 4885 } else {
c6c7cf05 4886 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4887 }
9a64fbe4 4888#endif
79aceca5
FB
4889}
4890
4891/* tlbsync */
99e300ef 4892static void gen_tlbsync(DisasContext *ctx)
79aceca5 4893{
9a64fbe4 4894#if defined(CONFIG_USER_ONLY)
e06fcd75 4895 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4896#else
74693da9 4897 if (unlikely(ctx->pr || !ctx->hv)) {
e06fcd75 4898 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4899 return;
9a64fbe4 4900 }
cd0c6f47
BH
4901 /* tlbsync is a nop for server, ptesync handles delayed tlb flush,
4902 * embedded however needs to deal with tlbsync. We don't try to be
4903 * fancy and swallow the overhead of checking for both.
9a64fbe4 4904 */
cd0c6f47 4905 gen_check_tlb_flush(ctx);
9a64fbe4 4906#endif
79aceca5
FB
4907}
4908
426613db
JM
4909#if defined(TARGET_PPC64)
4910/* slbia */
99e300ef 4911static void gen_slbia(DisasContext *ctx)
426613db
JM
4912{
4913#if defined(CONFIG_USER_ONLY)
e06fcd75 4914 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4915#else
1c7336c5 4916 if (unlikely(ctx->pr)) {
e06fcd75 4917 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4918 return;
4919 }
c6c7cf05 4920 gen_helper_slbia(cpu_env);
426613db
JM
4921#endif
4922}
4923
4924/* slbie */
99e300ef 4925static void gen_slbie(DisasContext *ctx)
426613db
JM
4926{
4927#if defined(CONFIG_USER_ONLY)
e06fcd75 4928 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4929#else
c47493f2 4930 if (unlikely(ctx->pr)) {
e06fcd75 4931 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4932 return;
4933 }
c6c7cf05 4934 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4935#endif
4936}
4937#endif
4938
79aceca5
FB
4939/*** External control ***/
4940/* Optional: */
99e300ef 4941
54623277 4942/* eciwx */
99e300ef 4943static void gen_eciwx(DisasContext *ctx)
79aceca5 4944{
76db3ba4 4945 TCGv t0;
fa407c03 4946 /* Should check EAR[E] ! */
76db3ba4
AJ
4947 gen_set_access_type(ctx, ACCESS_EXT);
4948 t0 = tcg_temp_new();
4949 gen_addr_reg_index(ctx, t0);
fa407c03 4950 gen_check_align(ctx, t0, 0x03);
76db3ba4 4951 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4952 tcg_temp_free(t0);
76a66253
JM
4953}
4954
4955/* ecowx */
99e300ef 4956static void gen_ecowx(DisasContext *ctx)
76a66253 4957{
76db3ba4 4958 TCGv t0;
fa407c03 4959 /* Should check EAR[E] ! */
76db3ba4
AJ
4960 gen_set_access_type(ctx, ACCESS_EXT);
4961 t0 = tcg_temp_new();
4962 gen_addr_reg_index(ctx, t0);
fa407c03 4963 gen_check_align(ctx, t0, 0x03);
76db3ba4 4964 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4965 tcg_temp_free(t0);
76a66253
JM
4966}
4967
4968/* PowerPC 601 specific instructions */
99e300ef 4969
54623277 4970/* abs - abs. */
99e300ef 4971static void gen_abs(DisasContext *ctx)
76a66253 4972{
42a268c2
RH
4973 TCGLabel *l1 = gen_new_label();
4974 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
4975 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4976 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4977 tcg_gen_br(l2);
4978 gen_set_label(l1);
4979 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4980 gen_set_label(l2);
76a66253 4981 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4982 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4983}
4984
4985/* abso - abso. */
99e300ef 4986static void gen_abso(DisasContext *ctx)
76a66253 4987{
42a268c2
RH
4988 TCGLabel *l1 = gen_new_label();
4989 TCGLabel *l2 = gen_new_label();
4990 TCGLabel *l3 = gen_new_label();
22e0e173 4991 /* Start with XER OV disabled, the most likely case */
da91a00f 4992 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4993 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4994 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4995 tcg_gen_movi_tl(cpu_ov, 1);
4996 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4997 tcg_gen_br(l2);
4998 gen_set_label(l1);
4999 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5000 tcg_gen_br(l3);
5001 gen_set_label(l2);
5002 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5003 gen_set_label(l3);
76a66253 5004 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5005 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5006}
5007
5008/* clcs */
99e300ef 5009static void gen_clcs(DisasContext *ctx)
76a66253 5010{
22e0e173 5011 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 5012 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5013 tcg_temp_free_i32(t0);
c7697e1f 5014 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
5015}
5016
5017/* div - div. */
99e300ef 5018static void gen_div(DisasContext *ctx)
76a66253 5019{
d15f74fb
BS
5020 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5021 cpu_gpr[rB(ctx->opcode)]);
76a66253 5022 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5023 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5024}
5025
5026/* divo - divo. */
99e300ef 5027static void gen_divo(DisasContext *ctx)
76a66253 5028{
d15f74fb
BS
5029 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5030 cpu_gpr[rB(ctx->opcode)]);
76a66253 5031 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5032 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5033}
5034
5035/* divs - divs. */
99e300ef 5036static void gen_divs(DisasContext *ctx)
76a66253 5037{
d15f74fb
BS
5038 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
5039 cpu_gpr[rB(ctx->opcode)]);
76a66253 5040 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5041 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5042}
5043
5044/* divso - divso. */
99e300ef 5045static void gen_divso(DisasContext *ctx)
76a66253 5046{
d15f74fb
BS
5047 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
5048 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 5049 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5050 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5051}
5052
5053/* doz - doz. */
99e300ef 5054static void gen_doz(DisasContext *ctx)
76a66253 5055{
42a268c2
RH
5056 TCGLabel *l1 = gen_new_label();
5057 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5058 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
5059 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5060 tcg_gen_br(l2);
5061 gen_set_label(l1);
5062 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5063 gen_set_label(l2);
76a66253 5064 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5065 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5066}
5067
5068/* dozo - dozo. */
99e300ef 5069static void gen_dozo(DisasContext *ctx)
76a66253 5070{
42a268c2
RH
5071 TCGLabel *l1 = gen_new_label();
5072 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5073 TCGv t0 = tcg_temp_new();
5074 TCGv t1 = tcg_temp_new();
5075 TCGv t2 = tcg_temp_new();
5076 /* Start with XER OV disabled, the most likely case */
da91a00f 5077 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5078 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
5079 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5080 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5081 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
5082 tcg_gen_andc_tl(t1, t1, t2);
5083 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
5084 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
5085 tcg_gen_movi_tl(cpu_ov, 1);
5086 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5087 tcg_gen_br(l2);
5088 gen_set_label(l1);
5089 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5090 gen_set_label(l2);
5091 tcg_temp_free(t0);
5092 tcg_temp_free(t1);
5093 tcg_temp_free(t2);
76a66253 5094 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5095 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5096}
5097
5098/* dozi */
99e300ef 5099static void gen_dozi(DisasContext *ctx)
76a66253 5100{
22e0e173 5101 target_long simm = SIMM(ctx->opcode);
42a268c2
RH
5102 TCGLabel *l1 = gen_new_label();
5103 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5104 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
5105 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
5106 tcg_gen_br(l2);
5107 gen_set_label(l1);
5108 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
5109 gen_set_label(l2);
5110 if (unlikely(Rc(ctx->opcode) != 0))
5111 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5112}
5113
76a66253 5114/* lscbx - lscbx. */
99e300ef 5115static void gen_lscbx(DisasContext *ctx)
76a66253 5116{
bdb4b689
AJ
5117 TCGv t0 = tcg_temp_new();
5118 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
5119 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
5120 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 5121
76db3ba4 5122 gen_addr_reg_index(ctx, t0);
76a66253 5123 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 5124 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 5125 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
5126 tcg_temp_free_i32(t1);
5127 tcg_temp_free_i32(t2);
5128 tcg_temp_free_i32(t3);
3d7b417e 5129 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 5130 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 5131 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
5132 gen_set_Rc0(ctx, t0);
5133 tcg_temp_free(t0);
76a66253
JM
5134}
5135
5136/* maskg - maskg. */
99e300ef 5137static void gen_maskg(DisasContext *ctx)
76a66253 5138{
42a268c2 5139 TCGLabel *l1 = gen_new_label();
22e0e173
AJ
5140 TCGv t0 = tcg_temp_new();
5141 TCGv t1 = tcg_temp_new();
5142 TCGv t2 = tcg_temp_new();
5143 TCGv t3 = tcg_temp_new();
5144 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
5145 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5146 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
5147 tcg_gen_addi_tl(t2, t0, 1);
5148 tcg_gen_shr_tl(t2, t3, t2);
5149 tcg_gen_shr_tl(t3, t3, t1);
5150 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
5151 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
5152 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5153 gen_set_label(l1);
5154 tcg_temp_free(t0);
5155 tcg_temp_free(t1);
5156 tcg_temp_free(t2);
5157 tcg_temp_free(t3);
76a66253 5158 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5159 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5160}
5161
5162/* maskir - maskir. */
99e300ef 5163static void gen_maskir(DisasContext *ctx)
76a66253 5164{
22e0e173
AJ
5165 TCGv t0 = tcg_temp_new();
5166 TCGv t1 = tcg_temp_new();
5167 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5168 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
5169 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5170 tcg_temp_free(t0);
5171 tcg_temp_free(t1);
76a66253 5172 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5173 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5174}
5175
5176/* mul - mul. */
99e300ef 5177static void gen_mul(DisasContext *ctx)
76a66253 5178{
22e0e173
AJ
5179 TCGv_i64 t0 = tcg_temp_new_i64();
5180 TCGv_i64 t1 = tcg_temp_new_i64();
5181 TCGv t2 = tcg_temp_new();
5182 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5183 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5184 tcg_gen_mul_i64(t0, t0, t1);
5185 tcg_gen_trunc_i64_tl(t2, t0);
5186 gen_store_spr(SPR_MQ, t2);
5187 tcg_gen_shri_i64(t1, t0, 32);
5188 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5189 tcg_temp_free_i64(t0);
5190 tcg_temp_free_i64(t1);
5191 tcg_temp_free(t2);
76a66253 5192 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5193 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5194}
5195
5196/* mulo - mulo. */
99e300ef 5197static void gen_mulo(DisasContext *ctx)
76a66253 5198{
42a268c2 5199 TCGLabel *l1 = gen_new_label();
22e0e173
AJ
5200 TCGv_i64 t0 = tcg_temp_new_i64();
5201 TCGv_i64 t1 = tcg_temp_new_i64();
5202 TCGv t2 = tcg_temp_new();
5203 /* Start with XER OV disabled, the most likely case */
da91a00f 5204 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
5205 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
5206 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
5207 tcg_gen_mul_i64(t0, t0, t1);
5208 tcg_gen_trunc_i64_tl(t2, t0);
5209 gen_store_spr(SPR_MQ, t2);
5210 tcg_gen_shri_i64(t1, t0, 32);
5211 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
5212 tcg_gen_ext32s_i64(t1, t0);
5213 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
5214 tcg_gen_movi_tl(cpu_ov, 1);
5215 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
5216 gen_set_label(l1);
5217 tcg_temp_free_i64(t0);
5218 tcg_temp_free_i64(t1);
5219 tcg_temp_free(t2);
76a66253 5220 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5221 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5222}
5223
5224/* nabs - nabs. */
99e300ef 5225static void gen_nabs(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);
76a66253 5235 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5236 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5237}
5238
5239/* nabso - nabso. */
99e300ef 5240static void gen_nabso(DisasContext *ctx)
76a66253 5241{
42a268c2
RH
5242 TCGLabel *l1 = gen_new_label();
5243 TCGLabel *l2 = gen_new_label();
22e0e173
AJ
5244 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
5245 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5246 tcg_gen_br(l2);
5247 gen_set_label(l1);
5248 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5249 gen_set_label(l2);
5250 /* nabs never overflows */
da91a00f 5251 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 5252 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 5253 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
5254}
5255
5256/* rlmi - rlmi. */
99e300ef 5257static void gen_rlmi(DisasContext *ctx)
76a66253 5258{
7487953d
AJ
5259 uint32_t mb = MB(ctx->opcode);
5260 uint32_t me = ME(ctx->opcode);
5261 TCGv t0 = tcg_temp_new();
5262 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5263 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5264 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
5265 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
5266 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
5267 tcg_temp_free(t0);
76a66253 5268 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5269 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5270}
5271
5272/* rrib - rrib. */
99e300ef 5273static void gen_rrib(DisasContext *ctx)
76a66253 5274{
7487953d
AJ
5275 TCGv t0 = tcg_temp_new();
5276 TCGv t1 = tcg_temp_new();
5277 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5278 tcg_gen_movi_tl(t1, 0x80000000);
5279 tcg_gen_shr_tl(t1, t1, t0);
5280 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5281 tcg_gen_and_tl(t0, t0, t1);
5282 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
5283 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5284 tcg_temp_free(t0);
5285 tcg_temp_free(t1);
76a66253 5286 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5287 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5288}
5289
5290/* sle - sle. */
99e300ef 5291static void gen_sle(DisasContext *ctx)
76a66253 5292{
7487953d
AJ
5293 TCGv t0 = tcg_temp_new();
5294 TCGv t1 = tcg_temp_new();
5295 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5296 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5297 tcg_gen_subfi_tl(t1, 32, t1);
5298 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5299 tcg_gen_or_tl(t1, t0, t1);
5300 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5301 gen_store_spr(SPR_MQ, t1);
5302 tcg_temp_free(t0);
5303 tcg_temp_free(t1);
76a66253 5304 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5305 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5306}
5307
5308/* sleq - sleq. */
99e300ef 5309static void gen_sleq(DisasContext *ctx)
76a66253 5310{
7487953d
AJ
5311 TCGv t0 = tcg_temp_new();
5312 TCGv t1 = tcg_temp_new();
5313 TCGv t2 = tcg_temp_new();
5314 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5315 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5316 tcg_gen_shl_tl(t2, t2, t0);
5317 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5318 gen_load_spr(t1, SPR_MQ);
5319 gen_store_spr(SPR_MQ, t0);
5320 tcg_gen_and_tl(t0, t0, t2);
5321 tcg_gen_andc_tl(t1, t1, t2);
5322 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5323 tcg_temp_free(t0);
5324 tcg_temp_free(t1);
5325 tcg_temp_free(t2);
76a66253 5326 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5327 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5328}
5329
5330/* sliq - sliq. */
99e300ef 5331static void gen_sliq(DisasContext *ctx)
76a66253 5332{
7487953d
AJ
5333 int sh = SH(ctx->opcode);
5334 TCGv t0 = tcg_temp_new();
5335 TCGv t1 = tcg_temp_new();
5336 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5337 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5338 tcg_gen_or_tl(t1, t0, t1);
5339 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5340 gen_store_spr(SPR_MQ, t1);
5341 tcg_temp_free(t0);
5342 tcg_temp_free(t1);
76a66253 5343 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5344 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5345}
5346
5347/* slliq - slliq. */
99e300ef 5348static void gen_slliq(DisasContext *ctx)
76a66253 5349{
7487953d
AJ
5350 int sh = SH(ctx->opcode);
5351 TCGv t0 = tcg_temp_new();
5352 TCGv t1 = tcg_temp_new();
5353 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5354 gen_load_spr(t1, SPR_MQ);
5355 gen_store_spr(SPR_MQ, t0);
5356 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5357 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5358 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5359 tcg_temp_free(t0);
5360 tcg_temp_free(t1);
76a66253 5361 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5362 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5363}
5364
5365/* sllq - sllq. */
99e300ef 5366static void gen_sllq(DisasContext *ctx)
76a66253 5367{
42a268c2
RH
5368 TCGLabel *l1 = gen_new_label();
5369 TCGLabel *l2 = gen_new_label();
7487953d
AJ
5370 TCGv t0 = tcg_temp_local_new();
5371 TCGv t1 = tcg_temp_local_new();
5372 TCGv t2 = tcg_temp_local_new();
5373 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5374 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5375 tcg_gen_shl_tl(t1, t1, t2);
5376 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5377 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5378 gen_load_spr(t0, SPR_MQ);
5379 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5380 tcg_gen_br(l2);
5381 gen_set_label(l1);
5382 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5383 gen_load_spr(t2, SPR_MQ);
5384 tcg_gen_andc_tl(t1, t2, t1);
5385 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5386 gen_set_label(l2);
5387 tcg_temp_free(t0);
5388 tcg_temp_free(t1);
5389 tcg_temp_free(t2);
76a66253 5390 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5391 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5392}
5393
5394/* slq - slq. */
99e300ef 5395static void gen_slq(DisasContext *ctx)
76a66253 5396{
42a268c2 5397 TCGLabel *l1 = gen_new_label();
7487953d
AJ
5398 TCGv t0 = tcg_temp_new();
5399 TCGv t1 = tcg_temp_new();
5400 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5401 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5402 tcg_gen_subfi_tl(t1, 32, t1);
5403 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5404 tcg_gen_or_tl(t1, t0, t1);
5405 gen_store_spr(SPR_MQ, t1);
5406 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5407 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5408 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5409 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5410 gen_set_label(l1);
5411 tcg_temp_free(t0);
5412 tcg_temp_free(t1);
76a66253 5413 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5414 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5415}
5416
d9bce9d9 5417/* sraiq - sraiq. */
99e300ef 5418static void gen_sraiq(DisasContext *ctx)
76a66253 5419{
7487953d 5420 int sh = SH(ctx->opcode);
42a268c2 5421 TCGLabel *l1 = gen_new_label();
7487953d
AJ
5422 TCGv t0 = tcg_temp_new();
5423 TCGv t1 = tcg_temp_new();
5424 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5425 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5426 tcg_gen_or_tl(t0, t0, t1);
5427 gen_store_spr(SPR_MQ, t0);
da91a00f 5428 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5429 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5430 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5431 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5432 gen_set_label(l1);
5433 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5434 tcg_temp_free(t0);
5435 tcg_temp_free(t1);
76a66253 5436 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5437 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5438}
5439
5440/* sraq - sraq. */
99e300ef 5441static void gen_sraq(DisasContext *ctx)
76a66253 5442{
42a268c2
RH
5443 TCGLabel *l1 = gen_new_label();
5444 TCGLabel *l2 = gen_new_label();
7487953d
AJ
5445 TCGv t0 = tcg_temp_new();
5446 TCGv t1 = tcg_temp_local_new();
5447 TCGv t2 = tcg_temp_local_new();
5448 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5449 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5450 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5451 tcg_gen_subfi_tl(t2, 32, t2);
5452 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5453 tcg_gen_or_tl(t0, t0, t2);
5454 gen_store_spr(SPR_MQ, t0);
5455 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5456 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5457 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5458 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5459 gen_set_label(l1);
5460 tcg_temp_free(t0);
5461 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5462 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5463 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5464 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5465 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5466 gen_set_label(l2);
5467 tcg_temp_free(t1);
5468 tcg_temp_free(t2);
76a66253 5469 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5470 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5471}
5472
5473/* sre - sre. */
99e300ef 5474static void gen_sre(DisasContext *ctx)
76a66253 5475{
7487953d
AJ
5476 TCGv t0 = tcg_temp_new();
5477 TCGv t1 = tcg_temp_new();
5478 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5479 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5480 tcg_gen_subfi_tl(t1, 32, t1);
5481 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5482 tcg_gen_or_tl(t1, t0, t1);
5483 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5484 gen_store_spr(SPR_MQ, 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/* srea - srea. */
99e300ef 5492static void gen_srea(DisasContext *ctx)
76a66253 5493{
7487953d
AJ
5494 TCGv t0 = tcg_temp_new();
5495 TCGv t1 = tcg_temp_new();
5496 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5497 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5498 gen_store_spr(SPR_MQ, t0);
5499 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5500 tcg_temp_free(t0);
5501 tcg_temp_free(t1);
76a66253 5502 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5503 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5504}
5505
5506/* sreq */
99e300ef 5507static void gen_sreq(DisasContext *ctx)
76a66253 5508{
7487953d
AJ
5509 TCGv t0 = tcg_temp_new();
5510 TCGv t1 = tcg_temp_new();
5511 TCGv t2 = tcg_temp_new();
5512 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5513 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5514 tcg_gen_shr_tl(t1, t1, t0);
5515 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5516 gen_load_spr(t2, SPR_MQ);
5517 gen_store_spr(SPR_MQ, t0);
5518 tcg_gen_and_tl(t0, t0, t1);
5519 tcg_gen_andc_tl(t2, t2, t1);
5520 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5521 tcg_temp_free(t0);
5522 tcg_temp_free(t1);
5523 tcg_temp_free(t2);
76a66253 5524 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5525 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5526}
5527
5528/* sriq */
99e300ef 5529static void gen_sriq(DisasContext *ctx)
76a66253 5530{
7487953d
AJ
5531 int sh = SH(ctx->opcode);
5532 TCGv t0 = tcg_temp_new();
5533 TCGv t1 = tcg_temp_new();
5534 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5535 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5536 tcg_gen_or_tl(t1, t0, t1);
5537 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5538 gen_store_spr(SPR_MQ, t1);
5539 tcg_temp_free(t0);
5540 tcg_temp_free(t1);
76a66253 5541 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5542 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5543}
5544
5545/* srliq */
99e300ef 5546static void gen_srliq(DisasContext *ctx)
76a66253 5547{
7487953d
AJ
5548 int sh = SH(ctx->opcode);
5549 TCGv t0 = tcg_temp_new();
5550 TCGv t1 = tcg_temp_new();
5551 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5552 gen_load_spr(t1, SPR_MQ);
5553 gen_store_spr(SPR_MQ, t0);
5554 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5555 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5556 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5557 tcg_temp_free(t0);
5558 tcg_temp_free(t1);
76a66253 5559 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5560 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5561}
5562
5563/* srlq */
99e300ef 5564static void gen_srlq(DisasContext *ctx)
76a66253 5565{
42a268c2
RH
5566 TCGLabel *l1 = gen_new_label();
5567 TCGLabel *l2 = gen_new_label();
7487953d
AJ
5568 TCGv t0 = tcg_temp_local_new();
5569 TCGv t1 = tcg_temp_local_new();
5570 TCGv t2 = tcg_temp_local_new();
5571 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5572 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5573 tcg_gen_shr_tl(t2, t1, t2);
5574 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5575 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5576 gen_load_spr(t0, SPR_MQ);
5577 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5578 tcg_gen_br(l2);
5579 gen_set_label(l1);
5580 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5581 tcg_gen_and_tl(t0, t0, t2);
5582 gen_load_spr(t1, SPR_MQ);
5583 tcg_gen_andc_tl(t1, t1, t2);
5584 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5585 gen_set_label(l2);
5586 tcg_temp_free(t0);
5587 tcg_temp_free(t1);
5588 tcg_temp_free(t2);
76a66253 5589 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5590 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5591}
5592
5593/* srq */
99e300ef 5594static void gen_srq(DisasContext *ctx)
76a66253 5595{
42a268c2 5596 TCGLabel *l1 = gen_new_label();
7487953d
AJ
5597 TCGv t0 = tcg_temp_new();
5598 TCGv t1 = tcg_temp_new();
5599 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5600 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5601 tcg_gen_subfi_tl(t1, 32, t1);
5602 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5603 tcg_gen_or_tl(t1, t0, t1);
5604 gen_store_spr(SPR_MQ, t1);
5605 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5606 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5607 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5608 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5609 gen_set_label(l1);
5610 tcg_temp_free(t0);
5611 tcg_temp_free(t1);
76a66253 5612 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5613 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5614}
5615
5616/* PowerPC 602 specific instructions */
99e300ef 5617
54623277 5618/* dsa */
99e300ef 5619static void gen_dsa(DisasContext *ctx)
76a66253
JM
5620{
5621 /* XXX: TODO */
e06fcd75 5622 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5623}
5624
5625/* esa */
99e300ef 5626static void gen_esa(DisasContext *ctx)
76a66253
JM
5627{
5628 /* XXX: TODO */
e06fcd75 5629 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5630}
5631
5632/* mfrom */
99e300ef 5633static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5634{
5635#if defined(CONFIG_USER_ONLY)
e06fcd75 5636 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5637#else
c47493f2 5638 if (unlikely(ctx->pr)) {
e06fcd75 5639 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5640 return;
5641 }
cf02a65c 5642 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5643#endif
5644}
5645
5646/* 602 - 603 - G2 TLB management */
e8eaa2c0 5647
54623277 5648/* tlbld */
e8eaa2c0 5649static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5650{
5651#if defined(CONFIG_USER_ONLY)
e06fcd75 5652 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5653#else
c47493f2 5654 if (unlikely(ctx->pr)) {
e06fcd75 5655 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5656 return;
5657 }
c6c7cf05 5658 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5659#endif
5660}
5661
5662/* tlbli */
e8eaa2c0 5663static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5664{
5665#if defined(CONFIG_USER_ONLY)
e06fcd75 5666 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5667#else
c47493f2 5668 if (unlikely(ctx->pr)) {
e06fcd75 5669 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5670 return;
5671 }
c6c7cf05 5672 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5673#endif
5674}
5675
7dbe11ac 5676/* 74xx TLB management */
e8eaa2c0 5677
54623277 5678/* tlbld */
e8eaa2c0 5679static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5680{
5681#if defined(CONFIG_USER_ONLY)
e06fcd75 5682 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5683#else
c47493f2 5684 if (unlikely(ctx->pr)) {
e06fcd75 5685 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5686 return;
5687 }
c6c7cf05 5688 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5689#endif
5690}
5691
5692/* tlbli */
e8eaa2c0 5693static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5694{
5695#if defined(CONFIG_USER_ONLY)
e06fcd75 5696 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5697#else
c47493f2 5698 if (unlikely(ctx->pr)) {
e06fcd75 5699 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5700 return;
5701 }
c6c7cf05 5702 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5703#endif
5704}
5705
76a66253 5706/* POWER instructions not in PowerPC 601 */
99e300ef 5707
54623277 5708/* clf */
99e300ef 5709static void gen_clf(DisasContext *ctx)
76a66253
JM
5710{
5711 /* Cache line flush: implemented as no-op */
5712}
5713
5714/* cli */
99e300ef 5715static void gen_cli(DisasContext *ctx)
76a66253 5716{
7f75ffd3 5717 /* Cache line invalidate: privileged and treated as no-op */
76a66253 5718#if defined(CONFIG_USER_ONLY)
e06fcd75 5719 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5720#else
c47493f2 5721 if (unlikely(ctx->pr)) {
e06fcd75 5722 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5723 return;
5724 }
5725#endif
5726}
5727
5728/* dclst */
99e300ef 5729static void gen_dclst(DisasContext *ctx)
76a66253
JM
5730{
5731 /* Data cache line store: treated as no-op */
5732}
5733
99e300ef 5734static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5735{
5736#if defined(CONFIG_USER_ONLY)
e06fcd75 5737 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5738#else
74d37793
AJ
5739 int ra = rA(ctx->opcode);
5740 int rd = rD(ctx->opcode);
5741 TCGv t0;
c47493f2 5742 if (unlikely(ctx->pr)) {
e06fcd75 5743 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5744 return;
5745 }
74d37793 5746 t0 = tcg_temp_new();
76db3ba4 5747 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5748 tcg_gen_shri_tl(t0, t0, 28);
5749 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5750 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5751 tcg_temp_free(t0);
76a66253 5752 if (ra != 0 && ra != rd)
74d37793 5753 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5754#endif
5755}
5756
99e300ef 5757static void gen_rac(DisasContext *ctx)
76a66253
JM
5758{
5759#if defined(CONFIG_USER_ONLY)
e06fcd75 5760 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5761#else
22e0e173 5762 TCGv t0;
c47493f2 5763 if (unlikely(ctx->pr)) {
e06fcd75 5764 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5765 return;
5766 }
22e0e173 5767 t0 = tcg_temp_new();
76db3ba4 5768 gen_addr_reg_index(ctx, t0);
c6c7cf05 5769 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5770 tcg_temp_free(t0);
76a66253
JM
5771#endif
5772}
5773
99e300ef 5774static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5775{
5776#if defined(CONFIG_USER_ONLY)
e06fcd75 5777 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5778#else
c47493f2 5779 if (unlikely(ctx->pr)) {
e06fcd75 5780 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5781 return;
5782 }
e5f17ac6 5783 gen_helper_rfsvc(cpu_env);
e06fcd75 5784 gen_sync_exception(ctx);
76a66253
JM
5785#endif
5786}
5787
5788/* svc is not implemented for now */
5789
5790/* POWER2 specific instructions */
5791/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5792
5793/* lfq */
99e300ef 5794static void gen_lfq(DisasContext *ctx)
76a66253 5795{
01a4afeb 5796 int rd = rD(ctx->opcode);
76db3ba4
AJ
5797 TCGv t0;
5798 gen_set_access_type(ctx, ACCESS_FLOAT);
5799 t0 = tcg_temp_new();
5800 gen_addr_imm_index(ctx, t0, 0);
5801 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5802 gen_addr_add(ctx, t0, t0, 8);
5803 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5804 tcg_temp_free(t0);
76a66253
JM
5805}
5806
5807/* lfqu */
99e300ef 5808static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5809{
5810 int ra = rA(ctx->opcode);
01a4afeb 5811 int rd = rD(ctx->opcode);
76db3ba4
AJ
5812 TCGv t0, t1;
5813 gen_set_access_type(ctx, ACCESS_FLOAT);
5814 t0 = tcg_temp_new();
5815 t1 = tcg_temp_new();
5816 gen_addr_imm_index(ctx, t0, 0);
5817 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5818 gen_addr_add(ctx, t1, t0, 8);
5819 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5820 if (ra != 0)
01a4afeb
AJ
5821 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5822 tcg_temp_free(t0);
5823 tcg_temp_free(t1);
76a66253
JM
5824}
5825
5826/* lfqux */
99e300ef 5827static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5828{
5829 int ra = rA(ctx->opcode);
01a4afeb 5830 int rd = rD(ctx->opcode);
76db3ba4
AJ
5831 gen_set_access_type(ctx, ACCESS_FLOAT);
5832 TCGv t0, t1;
5833 t0 = tcg_temp_new();
5834 gen_addr_reg_index(ctx, t0);
5835 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5836 t1 = tcg_temp_new();
5837 gen_addr_add(ctx, t1, t0, 8);
5838 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5839 tcg_temp_free(t1);
76a66253 5840 if (ra != 0)
01a4afeb
AJ
5841 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5842 tcg_temp_free(t0);
76a66253
JM
5843}
5844
5845/* lfqx */
99e300ef 5846static void gen_lfqx(DisasContext *ctx)
76a66253 5847{
01a4afeb 5848 int rd = rD(ctx->opcode);
76db3ba4
AJ
5849 TCGv t0;
5850 gen_set_access_type(ctx, ACCESS_FLOAT);
5851 t0 = tcg_temp_new();
5852 gen_addr_reg_index(ctx, t0);
5853 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5854 gen_addr_add(ctx, t0, t0, 8);
5855 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5856 tcg_temp_free(t0);
76a66253
JM
5857}
5858
5859/* stfq */
99e300ef 5860static void gen_stfq(DisasContext *ctx)
76a66253 5861{
01a4afeb 5862 int rd = rD(ctx->opcode);
76db3ba4
AJ
5863 TCGv t0;
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 gen_addr_add(ctx, t0, t0, 8);
5869 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5870 tcg_temp_free(t0);
76a66253
JM
5871}
5872
5873/* stfqu */
99e300ef 5874static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5875{
5876 int ra = rA(ctx->opcode);
01a4afeb 5877 int rd = rD(ctx->opcode);
76db3ba4
AJ
5878 TCGv t0, t1;
5879 gen_set_access_type(ctx, ACCESS_FLOAT);
5880 t0 = tcg_temp_new();
5881 gen_addr_imm_index(ctx, t0, 0);
5882 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5883 t1 = tcg_temp_new();
5884 gen_addr_add(ctx, t1, t0, 8);
5885 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5886 tcg_temp_free(t1);
76a66253 5887 if (ra != 0)
01a4afeb
AJ
5888 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5889 tcg_temp_free(t0);
76a66253
JM
5890}
5891
5892/* stfqux */
99e300ef 5893static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5894{
5895 int ra = rA(ctx->opcode);
01a4afeb 5896 int rd = rD(ctx->opcode);
76db3ba4
AJ
5897 TCGv t0, t1;
5898 gen_set_access_type(ctx, ACCESS_FLOAT);
5899 t0 = tcg_temp_new();
5900 gen_addr_reg_index(ctx, t0);
5901 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5902 t1 = tcg_temp_new();
5903 gen_addr_add(ctx, t1, t0, 8);
5904 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5905 tcg_temp_free(t1);
76a66253 5906 if (ra != 0)
01a4afeb
AJ
5907 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5908 tcg_temp_free(t0);
76a66253
JM
5909}
5910
5911/* stfqx */
99e300ef 5912static void gen_stfqx(DisasContext *ctx)
76a66253 5913{
01a4afeb 5914 int rd = rD(ctx->opcode);
76db3ba4
AJ
5915 TCGv t0;
5916 gen_set_access_type(ctx, ACCESS_FLOAT);
5917 t0 = tcg_temp_new();
5918 gen_addr_reg_index(ctx, t0);
5919 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5920 gen_addr_add(ctx, t0, t0, 8);
5921 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5922 tcg_temp_free(t0);
76a66253
JM
5923}
5924
5925/* BookE specific instructions */
99e300ef 5926
54623277 5927/* XXX: not implemented on 440 ? */
99e300ef 5928static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5929{
5930 /* XXX: TODO */
e06fcd75 5931 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5932}
5933
2662a059 5934/* XXX: not implemented on 440 ? */
99e300ef 5935static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5936{
5937#if defined(CONFIG_USER_ONLY)
e06fcd75 5938 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5939#else
74d37793 5940 TCGv t0;
c47493f2 5941 if (unlikely(ctx->pr)) {
e06fcd75 5942 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5943 return;
5944 }
ec72e276 5945 t0 = tcg_temp_new();
76db3ba4 5946 gen_addr_reg_index(ctx, t0);
4693364f 5947 gen_helper_tlbiva(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5948 tcg_temp_free(t0);
76a66253
JM
5949#endif
5950}
5951
5952/* All 405 MAC instructions are translated here */
636aa200
BS
5953static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5954 int ra, int rb, int rt, int Rc)
76a66253 5955{
182608d4
AJ
5956 TCGv t0, t1;
5957
a7812ae4
PB
5958 t0 = tcg_temp_local_new();
5959 t1 = tcg_temp_local_new();
182608d4 5960
76a66253
JM
5961 switch (opc3 & 0x0D) {
5962 case 0x05:
5963 /* macchw - macchw. - macchwo - macchwo. */
5964 /* macchws - macchws. - macchwso - macchwso. */
5965 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5966 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5967 /* mulchw - mulchw. */
182608d4
AJ
5968 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5969 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5970 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5971 break;
5972 case 0x04:
5973 /* macchwu - macchwu. - macchwuo - macchwuo. */
5974 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5975 /* mulchwu - mulchwu. */
182608d4
AJ
5976 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5977 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5978 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5979 break;
5980 case 0x01:
5981 /* machhw - machhw. - machhwo - machhwo. */
5982 /* machhws - machhws. - machhwso - machhwso. */
5983 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5984 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5985 /* mulhhw - mulhhw. */
182608d4
AJ
5986 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5987 tcg_gen_ext16s_tl(t0, t0);
5988 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5989 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5990 break;
5991 case 0x00:
5992 /* machhwu - machhwu. - machhwuo - machhwuo. */
5993 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5994 /* mulhhwu - mulhhwu. */
182608d4
AJ
5995 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5996 tcg_gen_ext16u_tl(t0, t0);
5997 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5998 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5999 break;
6000 case 0x0D:
6001 /* maclhw - maclhw. - maclhwo - maclhwo. */
6002 /* maclhws - maclhws. - maclhwso - maclhwso. */
6003 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
6004 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
6005 /* mullhw - mullhw. */
182608d4
AJ
6006 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
6007 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
6008 break;
6009 case 0x0C:
6010 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
6011 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
6012 /* mullhwu - mullhwu. */
182608d4
AJ
6013 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
6014 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
6015 break;
6016 }
76a66253 6017 if (opc2 & 0x04) {
182608d4
AJ
6018 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
6019 tcg_gen_mul_tl(t1, t0, t1);
6020 if (opc2 & 0x02) {
6021 /* nmultiply-and-accumulate (0x0E) */
6022 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
6023 } else {
6024 /* multiply-and-accumulate (0x0C) */
6025 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
6026 }
6027
6028 if (opc3 & 0x12) {
6029 /* Check overflow and/or saturate */
42a268c2 6030 TCGLabel *l1 = gen_new_label();
182608d4
AJ
6031
6032 if (opc3 & 0x10) {
6033 /* Start with XER OV disabled, the most likely case */
da91a00f 6034 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
6035 }
6036 if (opc3 & 0x01) {
6037 /* Signed */
6038 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
6039 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
6040 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
6041 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 6042 if (opc3 & 0x02) {
182608d4
AJ
6043 /* Saturate */
6044 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
6045 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
6046 }
6047 } else {
6048 /* Unsigned */
6049 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 6050 if (opc3 & 0x02) {
182608d4
AJ
6051 /* Saturate */
6052 tcg_gen_movi_tl(t0, UINT32_MAX);
6053 }
6054 }
6055 if (opc3 & 0x10) {
6056 /* Check overflow */
da91a00f
RH
6057 tcg_gen_movi_tl(cpu_ov, 1);
6058 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
6059 }
6060 gen_set_label(l1);
6061 tcg_gen_mov_tl(cpu_gpr[rt], t0);
6062 }
6063 } else {
6064 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 6065 }
182608d4
AJ
6066 tcg_temp_free(t0);
6067 tcg_temp_free(t1);
76a66253
JM
6068 if (unlikely(Rc) != 0) {
6069 /* Update Rc0 */
182608d4 6070 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
6071 }
6072}
6073
a750fc0b 6074#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 6075static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
6076{ \
6077 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6078 rD(ctx->opcode), Rc(ctx->opcode)); \
6079}
6080
6081/* macchw - macchw. */
a750fc0b 6082GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 6083/* macchwo - macchwo. */
a750fc0b 6084GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 6085/* macchws - macchws. */
a750fc0b 6086GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 6087/* macchwso - macchwso. */
a750fc0b 6088GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 6089/* macchwsu - macchwsu. */
a750fc0b 6090GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 6091/* macchwsuo - macchwsuo. */
a750fc0b 6092GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 6093/* macchwu - macchwu. */
a750fc0b 6094GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 6095/* macchwuo - macchwuo. */
a750fc0b 6096GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 6097/* machhw - machhw. */
a750fc0b 6098GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 6099/* machhwo - machhwo. */
a750fc0b 6100GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 6101/* machhws - machhws. */
a750fc0b 6102GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 6103/* machhwso - machhwso. */
a750fc0b 6104GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 6105/* machhwsu - machhwsu. */
a750fc0b 6106GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 6107/* machhwsuo - machhwsuo. */
a750fc0b 6108GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 6109/* machhwu - machhwu. */
a750fc0b 6110GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 6111/* machhwuo - machhwuo. */
a750fc0b 6112GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 6113/* maclhw - maclhw. */
a750fc0b 6114GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 6115/* maclhwo - maclhwo. */
a750fc0b 6116GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 6117/* maclhws - maclhws. */
a750fc0b 6118GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 6119/* maclhwso - maclhwso. */
a750fc0b 6120GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 6121/* maclhwu - maclhwu. */
a750fc0b 6122GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 6123/* maclhwuo - maclhwuo. */
a750fc0b 6124GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 6125/* maclhwsu - maclhwsu. */
a750fc0b 6126GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 6127/* maclhwsuo - maclhwsuo. */
a750fc0b 6128GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 6129/* nmacchw - nmacchw. */
a750fc0b 6130GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 6131/* nmacchwo - nmacchwo. */
a750fc0b 6132GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 6133/* nmacchws - nmacchws. */
a750fc0b 6134GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 6135/* nmacchwso - nmacchwso. */
a750fc0b 6136GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 6137/* nmachhw - nmachhw. */
a750fc0b 6138GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 6139/* nmachhwo - nmachhwo. */
a750fc0b 6140GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 6141/* nmachhws - nmachhws. */
a750fc0b 6142GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 6143/* nmachhwso - nmachhwso. */
a750fc0b 6144GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 6145/* nmaclhw - nmaclhw. */
a750fc0b 6146GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 6147/* nmaclhwo - nmaclhwo. */
a750fc0b 6148GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 6149/* nmaclhws - nmaclhws. */
a750fc0b 6150GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 6151/* nmaclhwso - nmaclhwso. */
a750fc0b 6152GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
6153
6154/* mulchw - mulchw. */
a750fc0b 6155GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 6156/* mulchwu - mulchwu. */
a750fc0b 6157GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 6158/* mulhhw - mulhhw. */
a750fc0b 6159GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 6160/* mulhhwu - mulhhwu. */
a750fc0b 6161GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 6162/* mullhw - mullhw. */
a750fc0b 6163GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 6164/* mullhwu - mullhwu. */
a750fc0b 6165GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
6166
6167/* mfdcr */
99e300ef 6168static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
6169{
6170#if defined(CONFIG_USER_ONLY)
e06fcd75 6171 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6172#else
06dca6a7 6173 TCGv dcrn;
c47493f2 6174 if (unlikely(ctx->pr)) {
e06fcd75 6175 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6176 return;
6177 }
06dca6a7
AJ
6178 /* NIP cannot be restored if the memory exception comes from an helper */
6179 gen_update_nip(ctx, ctx->nip - 4);
6180 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6181 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 6182 tcg_temp_free(dcrn);
76a66253
JM
6183#endif
6184}
6185
6186/* mtdcr */
99e300ef 6187static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
6188{
6189#if defined(CONFIG_USER_ONLY)
e06fcd75 6190 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 6191#else
06dca6a7 6192 TCGv dcrn;
c47493f2 6193 if (unlikely(ctx->pr)) {
e06fcd75 6194 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
6195 return;
6196 }
06dca6a7
AJ
6197 /* NIP cannot be restored if the memory exception comes from an helper */
6198 gen_update_nip(ctx, ctx->nip - 4);
6199 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 6200 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 6201 tcg_temp_free(dcrn);
a42bd6cc
JM
6202#endif
6203}
6204
6205/* mfdcrx */
2662a059 6206/* XXX: not implemented on 440 ? */
99e300ef 6207static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
6208{
6209#if defined(CONFIG_USER_ONLY)
e06fcd75 6210 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6211#else
c47493f2 6212 if (unlikely(ctx->pr)) {
e06fcd75 6213 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6214 return;
6215 }
06dca6a7
AJ
6216 /* NIP cannot be restored if the memory exception comes from an helper */
6217 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6218 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6219 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 6220 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
6221#endif
6222}
6223
6224/* mtdcrx */
2662a059 6225/* XXX: not implemented on 440 ? */
99e300ef 6226static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
6227{
6228#if defined(CONFIG_USER_ONLY)
e06fcd75 6229 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 6230#else
c47493f2 6231 if (unlikely(ctx->pr)) {
e06fcd75 6232 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
6233 return;
6234 }
06dca6a7
AJ
6235 /* NIP cannot be restored if the memory exception comes from an helper */
6236 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6237 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
6238 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 6239 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
6240#endif
6241}
6242
a750fc0b 6243/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6244static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 6245{
06dca6a7
AJ
6246 /* NIP cannot be restored if the memory exception comes from an helper */
6247 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
6248 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
6249 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
6250 /* Note: Rc update flag set leads to undefined state of Rc0 */
6251}
6252
6253/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 6254static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 6255{
06dca6a7
AJ
6256 /* NIP cannot be restored if the memory exception comes from an helper */
6257 gen_update_nip(ctx, ctx->nip - 4);
975e5463 6258 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 6259 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
6260 /* Note: Rc update flag set leads to undefined state of Rc0 */
6261}
6262
76a66253 6263/* dccci */
99e300ef 6264static void gen_dccci(DisasContext *ctx)
76a66253
JM
6265{
6266#if defined(CONFIG_USER_ONLY)
e06fcd75 6267 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6268#else
c47493f2 6269 if (unlikely(ctx->pr)) {
e06fcd75 6270 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6271 return;
6272 }
6273 /* interpreted as no-op */
6274#endif
6275}
6276
6277/* dcread */
99e300ef 6278static void gen_dcread(DisasContext *ctx)
76a66253
JM
6279{
6280#if defined(CONFIG_USER_ONLY)
e06fcd75 6281 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6282#else
b61f2753 6283 TCGv EA, val;
c47493f2 6284 if (unlikely(ctx->pr)) {
e06fcd75 6285 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6286 return;
6287 }
76db3ba4 6288 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 6289 EA = tcg_temp_new();
76db3ba4 6290 gen_addr_reg_index(ctx, EA);
a7812ae4 6291 val = tcg_temp_new();
76db3ba4 6292 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
6293 tcg_temp_free(val);
6294 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
6295 tcg_temp_free(EA);
76a66253
JM
6296#endif
6297}
6298
6299/* icbt */
e8eaa2c0 6300static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6301{
6302 /* interpreted as no-op */
6303 /* XXX: specification say this is treated as a load by the MMU
6304 * but does not generate any exception
6305 */
6306}
6307
6308/* iccci */
99e300ef 6309static void gen_iccci(DisasContext *ctx)
76a66253
JM
6310{
6311#if defined(CONFIG_USER_ONLY)
e06fcd75 6312 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6313#else
c47493f2 6314 if (unlikely(ctx->pr)) {
e06fcd75 6315 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6316 return;
6317 }
6318 /* interpreted as no-op */
6319#endif
6320}
6321
6322/* icread */
99e300ef 6323static void gen_icread(DisasContext *ctx)
76a66253
JM
6324{
6325#if defined(CONFIG_USER_ONLY)
e06fcd75 6326 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6327#else
c47493f2 6328 if (unlikely(ctx->pr)) {
e06fcd75 6329 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6330 return;
6331 }
6332 /* interpreted as no-op */
6333#endif
6334}
6335
c47493f2 6336/* rfci (supervisor only) */
e8eaa2c0 6337static void gen_rfci_40x(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_40x_rfci(cpu_env);
e06fcd75 6348 gen_sync_exception(ctx);
a42bd6cc
JM
6349#endif
6350}
6351
99e300ef 6352static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6353{
6354#if defined(CONFIG_USER_ONLY)
e06fcd75 6355 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6356#else
c47493f2 6357 if (unlikely(ctx->pr)) {
e06fcd75 6358 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6359 return;
6360 }
6361 /* Restore CPU state */
e5f17ac6 6362 gen_helper_rfci(cpu_env);
e06fcd75 6363 gen_sync_exception(ctx);
a42bd6cc
JM
6364#endif
6365}
6366
6367/* BookE specific */
99e300ef 6368
54623277 6369/* XXX: not implemented on 440 ? */
99e300ef 6370static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6371{
6372#if defined(CONFIG_USER_ONLY)
e06fcd75 6373 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6374#else
c47493f2 6375 if (unlikely(ctx->pr)) {
e06fcd75 6376 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6377 return;
6378 }
6379 /* Restore CPU state */
e5f17ac6 6380 gen_helper_rfdi(cpu_env);
e06fcd75 6381 gen_sync_exception(ctx);
76a66253
JM
6382#endif
6383}
6384
2662a059 6385/* XXX: not implemented on 440 ? */
99e300ef 6386static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6387{
6388#if defined(CONFIG_USER_ONLY)
e06fcd75 6389 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6390#else
c47493f2 6391 if (unlikely(ctx->pr)) {
e06fcd75 6392 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6393 return;
6394 }
6395 /* Restore CPU state */
e5f17ac6 6396 gen_helper_rfmci(cpu_env);
e06fcd75 6397 gen_sync_exception(ctx);
a42bd6cc
JM
6398#endif
6399}
5eb7995e 6400
d9bce9d9 6401/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6402
54623277 6403/* tlbre */
e8eaa2c0 6404static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6405{
6406#if defined(CONFIG_USER_ONLY)
e06fcd75 6407 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6408#else
c47493f2 6409 if (unlikely(ctx->pr)) {
e06fcd75 6410 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6411 return;
6412 }
6413 switch (rB(ctx->opcode)) {
6414 case 0:
c6c7cf05
BS
6415 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6416 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6417 break;
6418 case 1:
c6c7cf05
BS
6419 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6420 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6421 break;
6422 default:
e06fcd75 6423 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6424 break;
9a64fbe4 6425 }
76a66253
JM
6426#endif
6427}
6428
d9bce9d9 6429/* tlbsx - tlbsx. */
e8eaa2c0 6430static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6431{
6432#if defined(CONFIG_USER_ONLY)
e06fcd75 6433 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6434#else
74d37793 6435 TCGv t0;
c47493f2 6436 if (unlikely(ctx->pr)) {
e06fcd75 6437 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6438 return;
6439 }
74d37793 6440 t0 = tcg_temp_new();
76db3ba4 6441 gen_addr_reg_index(ctx, t0);
c6c7cf05 6442 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6443 tcg_temp_free(t0);
6444 if (Rc(ctx->opcode)) {
42a268c2 6445 TCGLabel *l1 = gen_new_label();
da91a00f 6446 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6447 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6448 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6449 gen_set_label(l1);
6450 }
76a66253 6451#endif
79aceca5
FB
6452}
6453
76a66253 6454/* tlbwe */
e8eaa2c0 6455static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6456{
76a66253 6457#if defined(CONFIG_USER_ONLY)
e06fcd75 6458 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6459#else
c47493f2 6460 if (unlikely(ctx->pr)) {
e06fcd75 6461 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6462 return;
6463 }
6464 switch (rB(ctx->opcode)) {
6465 case 0:
c6c7cf05
BS
6466 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6467 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6468 break;
6469 case 1:
c6c7cf05
BS
6470 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6471 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6472 break;
6473 default:
e06fcd75 6474 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6475 break;
9a64fbe4 6476 }
76a66253
JM
6477#endif
6478}
6479
a4bb6c3e 6480/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6481
54623277 6482/* tlbre */
e8eaa2c0 6483static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6484{
6485#if defined(CONFIG_USER_ONLY)
e06fcd75 6486 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6487#else
c47493f2 6488 if (unlikely(ctx->pr)) {
e06fcd75 6489 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6490 return;
6491 }
6492 switch (rB(ctx->opcode)) {
6493 case 0:
5eb7995e 6494 case 1:
5eb7995e 6495 case 2:
74d37793
AJ
6496 {
6497 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6498 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6499 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6500 tcg_temp_free_i32(t0);
6501 }
5eb7995e
JM
6502 break;
6503 default:
e06fcd75 6504 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6505 break;
6506 }
6507#endif
6508}
6509
6510/* tlbsx - tlbsx. */
e8eaa2c0 6511static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6512{
6513#if defined(CONFIG_USER_ONLY)
e06fcd75 6514 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6515#else
74d37793 6516 TCGv t0;
c47493f2 6517 if (unlikely(ctx->pr)) {
e06fcd75 6518 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6519 return;
6520 }
74d37793 6521 t0 = tcg_temp_new();
76db3ba4 6522 gen_addr_reg_index(ctx, t0);
c6c7cf05 6523 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6524 tcg_temp_free(t0);
6525 if (Rc(ctx->opcode)) {
42a268c2 6526 TCGLabel *l1 = gen_new_label();
da91a00f 6527 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6528 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6529 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6530 gen_set_label(l1);
6531 }
5eb7995e
JM
6532#endif
6533}
6534
6535/* tlbwe */
e8eaa2c0 6536static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
6537{
6538#if defined(CONFIG_USER_ONLY)
e06fcd75 6539 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6540#else
c47493f2 6541 if (unlikely(ctx->pr)) {
e06fcd75 6542 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6543 return;
6544 }
6545 switch (rB(ctx->opcode)) {
6546 case 0:
5eb7995e 6547 case 1:
5eb7995e 6548 case 2:
74d37793
AJ
6549 {
6550 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6551 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6552 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
6553 tcg_temp_free_i32(t0);
6554 }
5eb7995e
JM
6555 break;
6556 default:
e06fcd75 6557 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6558 break;
6559 }
6560#endif
6561}
6562
01662f3e
AG
6563/* TLB management - PowerPC BookE 2.06 implementation */
6564
6565/* tlbre */
6566static void gen_tlbre_booke206(DisasContext *ctx)
6567{
6568#if defined(CONFIG_USER_ONLY)
6569 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6570#else
c47493f2 6571 if (unlikely(ctx->pr)) {
01662f3e
AG
6572 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6573 return;
6574 }
6575
c6c7cf05 6576 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6577#endif
6578}
6579
6580/* tlbsx - tlbsx. */
6581static void gen_tlbsx_booke206(DisasContext *ctx)
6582{
6583#if defined(CONFIG_USER_ONLY)
6584 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6585#else
6586 TCGv t0;
c47493f2 6587 if (unlikely(ctx->pr)) {
01662f3e
AG
6588 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6589 return;
6590 }
6591
6592 if (rA(ctx->opcode)) {
6593 t0 = tcg_temp_new();
6594 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6595 } else {
6596 t0 = tcg_const_tl(0);
6597 }
6598
6599 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6600 gen_helper_booke206_tlbsx(cpu_env, t0);
c80d1df5 6601 tcg_temp_free(t0);
01662f3e
AG
6602#endif
6603}
6604
6605/* tlbwe */
6606static void gen_tlbwe_booke206(DisasContext *ctx)
6607{
6608#if defined(CONFIG_USER_ONLY)
6609 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6610#else
c47493f2 6611 if (unlikely(ctx->pr)) {
01662f3e
AG
6612 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6613 return;
6614 }
3f162d11 6615 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6616 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6617#endif
6618}
6619
6620static void gen_tlbivax_booke206(DisasContext *ctx)
6621{
6622#if defined(CONFIG_USER_ONLY)
6623 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6624#else
6625 TCGv t0;
c47493f2 6626 if (unlikely(ctx->pr)) {
01662f3e
AG
6627 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6628 return;
6629 }
6630
6631 t0 = tcg_temp_new();
6632 gen_addr_reg_index(ctx, t0);
6633
c6c7cf05 6634 gen_helper_booke206_tlbivax(cpu_env, t0);
c80d1df5 6635 tcg_temp_free(t0);
01662f3e
AG
6636#endif
6637}
6638
6d3db821
AG
6639static void gen_tlbilx_booke206(DisasContext *ctx)
6640{
6641#if defined(CONFIG_USER_ONLY)
6642 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6643#else
6644 TCGv t0;
c47493f2 6645 if (unlikely(ctx->pr)) {
6d3db821
AG
6646 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6647 return;
6648 }
6649
6650 t0 = tcg_temp_new();
6651 gen_addr_reg_index(ctx, t0);
6652
6653 switch((ctx->opcode >> 21) & 0x3) {
6654 case 0:
c6c7cf05 6655 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6656 break;
6657 case 1:
c6c7cf05 6658 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6659 break;
6660 case 3:
c6c7cf05 6661 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6662 break;
6663 default:
6664 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6665 break;
6666 }
6667
6668 tcg_temp_free(t0);
6669#endif
6670}
6671
01662f3e 6672
76a66253 6673/* wrtee */
99e300ef 6674static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6675{
6676#if defined(CONFIG_USER_ONLY)
e06fcd75 6677 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6678#else
6527f6ea 6679 TCGv t0;
c47493f2 6680 if (unlikely(ctx->pr)) {
e06fcd75 6681 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6682 return;
6683 }
6527f6ea
AJ
6684 t0 = tcg_temp_new();
6685 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6686 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6687 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6688 tcg_temp_free(t0);
dee96f6c
JM
6689 /* Stop translation to have a chance to raise an exception
6690 * if we just set msr_ee to 1
6691 */
e06fcd75 6692 gen_stop_exception(ctx);
76a66253
JM
6693#endif
6694}
6695
6696/* wrteei */
99e300ef 6697static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6698{
6699#if defined(CONFIG_USER_ONLY)
e06fcd75 6700 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6701#else
c47493f2 6702 if (unlikely(ctx->pr)) {
e06fcd75 6703 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6704 return;
6705 }
fbe73008 6706 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6707 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6708 /* Stop translation to have a chance to raise an exception */
e06fcd75 6709 gen_stop_exception(ctx);
6527f6ea 6710 } else {
1b6e5f99 6711 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6712 }
76a66253
JM
6713#endif
6714}
6715
08e46e54 6716/* PowerPC 440 specific instructions */
99e300ef 6717
54623277 6718/* dlmzb */
99e300ef 6719static void gen_dlmzb(DisasContext *ctx)
76a66253 6720{
ef0d51af 6721 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6722 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6723 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6724 tcg_temp_free_i32(t0);
76a66253
JM
6725}
6726
6727/* mbar replaces eieio on 440 */
99e300ef 6728static void gen_mbar(DisasContext *ctx)
76a66253
JM
6729{
6730 /* interpreted as no-op */
6731}
6732
6733/* msync replaces sync on 440 */
dcb2b9e1 6734static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6735{
6736 /* interpreted as no-op */
6737}
6738
6739/* icbt */
e8eaa2c0 6740static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6741{
6742 /* interpreted as no-op */
6743 /* XXX: specification say this is treated as a load by the MMU
6744 * but does not generate any exception
6745 */
79aceca5
FB
6746}
6747
9e0b5cb1
AG
6748/* Embedded.Processor Control */
6749
6750static void gen_msgclr(DisasContext *ctx)
6751{
6752#if defined(CONFIG_USER_ONLY)
6753 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6754#else
c47493f2 6755 if (unlikely(ctx->pr)) {
9e0b5cb1
AG
6756 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6757 return;
6758 }
6759
e5f17ac6 6760 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6761#endif
6762}
6763
d5d11a39
AG
6764static void gen_msgsnd(DisasContext *ctx)
6765{
6766#if defined(CONFIG_USER_ONLY)
6767 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6768#else
c47493f2 6769 if (unlikely(ctx->pr)) {
d5d11a39
AG
6770 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6771 return;
6772 }
6773
6774 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6775#endif
6776}
6777
a9d9eb8f
JM
6778/*** Altivec vector extension ***/
6779/* Altivec registers moves */
a9d9eb8f 6780
636aa200 6781static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6782{
e4704b3b 6783 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6784 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6785 return r;
6786}
6787
a9d9eb8f 6788#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6789static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6790{ \
fe1e5c53 6791 TCGv EA; \
a9d9eb8f 6792 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6793 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6794 return; \
6795 } \
76db3ba4 6796 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6797 EA = tcg_temp_new(); \
76db3ba4 6798 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6799 tcg_gen_andi_tl(EA, EA, ~0xf); \
e22c357b
DK
6800 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
6801 64-bit byteswap already. */ \
76db3ba4
AJ
6802 if (ctx->le_mode) { \
6803 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6804 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6805 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6806 } else { \
76db3ba4 6807 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6808 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6809 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6810 } \
6811 tcg_temp_free(EA); \
a9d9eb8f
JM
6812}
6813
6814#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6815static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6816{ \
fe1e5c53 6817 TCGv EA; \
a9d9eb8f 6818 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6819 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6820 return; \
6821 } \
76db3ba4 6822 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6823 EA = tcg_temp_new(); \
76db3ba4 6824 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6825 tcg_gen_andi_tl(EA, EA, ~0xf); \
e22c357b
DK
6826 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
6827 64-bit byteswap already. */ \
76db3ba4
AJ
6828 if (ctx->le_mode) { \
6829 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6830 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6831 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6832 } else { \
76db3ba4 6833 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6834 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6835 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6836 } \
6837 tcg_temp_free(EA); \
a9d9eb8f
JM
6838}
6839
2791128e 6840#define GEN_VR_LVE(name, opc2, opc3, size) \
99e300ef 6841static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6842 { \
6843 TCGv EA; \
6844 TCGv_ptr rs; \
6845 if (unlikely(!ctx->altivec_enabled)) { \
6846 gen_exception(ctx, POWERPC_EXCP_VPU); \
6847 return; \
6848 } \
6849 gen_set_access_type(ctx, ACCESS_INT); \
6850 EA = tcg_temp_new(); \
6851 gen_addr_reg_index(ctx, EA); \
2791128e
TM
6852 if (size > 1) { \
6853 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
6854 } \
cbfb6ae9 6855 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6856 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6857 tcg_temp_free(EA); \
6858 tcg_temp_free_ptr(rs); \
6859 }
6860
2791128e 6861#define GEN_VR_STVE(name, opc2, opc3, size) \
99e300ef 6862static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6863 { \
6864 TCGv EA; \
6865 TCGv_ptr rs; \
6866 if (unlikely(!ctx->altivec_enabled)) { \
6867 gen_exception(ctx, POWERPC_EXCP_VPU); \
6868 return; \
6869 } \
6870 gen_set_access_type(ctx, ACCESS_INT); \
6871 EA = tcg_temp_new(); \
6872 gen_addr_reg_index(ctx, EA); \
2791128e
TM
6873 if (size > 1) { \
6874 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
6875 } \
cbfb6ae9 6876 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6877 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6878 tcg_temp_free(EA); \
6879 tcg_temp_free_ptr(rs); \
6880 }
6881
fe1e5c53 6882GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6883/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6884GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6885
2791128e
TM
6886GEN_VR_LVE(bx, 0x07, 0x00, 1);
6887GEN_VR_LVE(hx, 0x07, 0x01, 2);
6888GEN_VR_LVE(wx, 0x07, 0x02, 4);
cbfb6ae9 6889
fe1e5c53 6890GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6891/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6892GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6893
2791128e
TM
6894GEN_VR_STVE(bx, 0x07, 0x04, 1);
6895GEN_VR_STVE(hx, 0x07, 0x05, 2);
6896GEN_VR_STVE(wx, 0x07, 0x06, 4);
cbfb6ae9 6897
99e300ef 6898static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6899{
6900 TCGv_ptr rd;
6901 TCGv EA;
6902 if (unlikely(!ctx->altivec_enabled)) {
6903 gen_exception(ctx, POWERPC_EXCP_VPU);
6904 return;
6905 }
6906 EA = tcg_temp_new();
6907 gen_addr_reg_index(ctx, EA);
6908 rd = gen_avr_ptr(rD(ctx->opcode));
6909 gen_helper_lvsl(rd, EA);
6910 tcg_temp_free(EA);
6911 tcg_temp_free_ptr(rd);
6912}
6913
99e300ef 6914static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6915{
6916 TCGv_ptr rd;
6917 TCGv EA;
6918 if (unlikely(!ctx->altivec_enabled)) {
6919 gen_exception(ctx, POWERPC_EXCP_VPU);
6920 return;
6921 }
6922 EA = tcg_temp_new();
6923 gen_addr_reg_index(ctx, EA);
6924 rd = gen_avr_ptr(rD(ctx->opcode));
6925 gen_helper_lvsr(rd, EA);
6926 tcg_temp_free(EA);
6927 tcg_temp_free_ptr(rd);
6928}
6929
99e300ef 6930static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6931{
6932 TCGv_i32 t;
6933 if (unlikely(!ctx->altivec_enabled)) {
6934 gen_exception(ctx, POWERPC_EXCP_VPU);
6935 return;
6936 }
6937 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6938 t = tcg_temp_new_i32();
1328c2bf 6939 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6940 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6941 tcg_temp_free_i32(t);
785f451b
AJ
6942}
6943
99e300ef 6944static void gen_mtvscr(DisasContext *ctx)
785f451b 6945{
6e87b7c7 6946 TCGv_ptr p;
785f451b
AJ
6947 if (unlikely(!ctx->altivec_enabled)) {
6948 gen_exception(ctx, POWERPC_EXCP_VPU);
6949 return;
6950 }
76cb6584 6951 p = gen_avr_ptr(rB(ctx->opcode));
d15f74fb 6952 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6953 tcg_temp_free_ptr(p);
785f451b
AJ
6954}
6955
7a9b96cf
AJ
6956/* Logical operations */
6957#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6958static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6959{ \
6960 if (unlikely(!ctx->altivec_enabled)) { \
6961 gen_exception(ctx, POWERPC_EXCP_VPU); \
6962 return; \
6963 } \
6964 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6965 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6966}
6967
6968GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6969GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6970GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6971GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6972GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
111c5f54
TM
6973GEN_VX_LOGICAL(veqv, tcg_gen_eqv_i64, 2, 26);
6974GEN_VX_LOGICAL(vnand, tcg_gen_nand_i64, 2, 22);
6975GEN_VX_LOGICAL(vorc, tcg_gen_orc_i64, 2, 21);
7a9b96cf 6976
8e27dd6f 6977#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6978static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6979{ \
6980 TCGv_ptr ra, rb, rd; \
6981 if (unlikely(!ctx->altivec_enabled)) { \
6982 gen_exception(ctx, POWERPC_EXCP_VPU); \
6983 return; \
6984 } \
6985 ra = gen_avr_ptr(rA(ctx->opcode)); \
6986 rb = gen_avr_ptr(rB(ctx->opcode)); \
6987 rd = gen_avr_ptr(rD(ctx->opcode)); \
6988 gen_helper_##name (rd, ra, rb); \
6989 tcg_temp_free_ptr(ra); \
6990 tcg_temp_free_ptr(rb); \
6991 tcg_temp_free_ptr(rd); \
6992}
6993
d15f74fb
BS
6994#define GEN_VXFORM_ENV(name, opc2, opc3) \
6995static void glue(gen_, name)(DisasContext *ctx) \
6996{ \
6997 TCGv_ptr ra, rb, rd; \
6998 if (unlikely(!ctx->altivec_enabled)) { \
6999 gen_exception(ctx, POWERPC_EXCP_VPU); \
7000 return; \
7001 } \
7002 ra = gen_avr_ptr(rA(ctx->opcode)); \
7003 rb = gen_avr_ptr(rB(ctx->opcode)); \
7004 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 7005 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
7006 tcg_temp_free_ptr(ra); \
7007 tcg_temp_free_ptr(rb); \
7008 tcg_temp_free_ptr(rd); \
9b47bb49
TM
7009}
7010
7011#define GEN_VXFORM3(name, opc2, opc3) \
7012static void glue(gen_, name)(DisasContext *ctx) \
7013{ \
7014 TCGv_ptr ra, rb, rc, rd; \
7015 if (unlikely(!ctx->altivec_enabled)) { \
7016 gen_exception(ctx, POWERPC_EXCP_VPU); \
7017 return; \
7018 } \
7019 ra = gen_avr_ptr(rA(ctx->opcode)); \
7020 rb = gen_avr_ptr(rB(ctx->opcode)); \
7021 rc = gen_avr_ptr(rC(ctx->opcode)); \
7022 rd = gen_avr_ptr(rD(ctx->opcode)); \
7023 gen_helper_##name(rd, ra, rb, rc); \
7024 tcg_temp_free_ptr(ra); \
7025 tcg_temp_free_ptr(rb); \
7026 tcg_temp_free_ptr(rc); \
7027 tcg_temp_free_ptr(rd); \
d15f74fb
BS
7028}
7029
5dffff5a
TM
7030/*
7031 * Support for Altivec instruction pairs that use bit 31 (Rc) as
7032 * an opcode bit. In general, these pairs come from different
7033 * versions of the ISA, so we must also support a pair of flags for
7034 * each instruction.
7035 */
7036#define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7037static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7038{ \
7039 if ((Rc(ctx->opcode) == 0) && \
7040 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7041 gen_##name0(ctx); \
7042 } else if ((Rc(ctx->opcode) == 1) && \
7043 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7044 gen_##name1(ctx); \
7045 } else { \
7046 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7047 } \
7048}
7049
7872c51c
AJ
7050GEN_VXFORM(vaddubm, 0, 0);
7051GEN_VXFORM(vadduhm, 0, 1);
7052GEN_VXFORM(vadduwm, 0, 2);
56eabc75 7053GEN_VXFORM(vaddudm, 0, 3);
7872c51c
AJ
7054GEN_VXFORM(vsububm, 0, 16);
7055GEN_VXFORM(vsubuhm, 0, 17);
7056GEN_VXFORM(vsubuwm, 0, 18);
56eabc75 7057GEN_VXFORM(vsubudm, 0, 19);
e4039339
AJ
7058GEN_VXFORM(vmaxub, 1, 0);
7059GEN_VXFORM(vmaxuh, 1, 1);
7060GEN_VXFORM(vmaxuw, 1, 2);
8203e31b 7061GEN_VXFORM(vmaxud, 1, 3);
e4039339
AJ
7062GEN_VXFORM(vmaxsb, 1, 4);
7063GEN_VXFORM(vmaxsh, 1, 5);
7064GEN_VXFORM(vmaxsw, 1, 6);
8203e31b 7065GEN_VXFORM(vmaxsd, 1, 7);
e4039339
AJ
7066GEN_VXFORM(vminub, 1, 8);
7067GEN_VXFORM(vminuh, 1, 9);
7068GEN_VXFORM(vminuw, 1, 10);
8203e31b 7069GEN_VXFORM(vminud, 1, 11);
e4039339
AJ
7070GEN_VXFORM(vminsb, 1, 12);
7071GEN_VXFORM(vminsh, 1, 13);
7072GEN_VXFORM(vminsw, 1, 14);
8203e31b 7073GEN_VXFORM(vminsd, 1, 15);
fab3cbe9
AJ
7074GEN_VXFORM(vavgub, 1, 16);
7075GEN_VXFORM(vavguh, 1, 17);
7076GEN_VXFORM(vavguw, 1, 18);
7077GEN_VXFORM(vavgsb, 1, 20);
7078GEN_VXFORM(vavgsh, 1, 21);
7079GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
7080GEN_VXFORM(vmrghb, 6, 0);
7081GEN_VXFORM(vmrghh, 6, 1);
7082GEN_VXFORM(vmrghw, 6, 2);
7083GEN_VXFORM(vmrglb, 6, 4);
7084GEN_VXFORM(vmrglh, 6, 5);
7085GEN_VXFORM(vmrglw, 6, 6);
e0ffe77f
TM
7086
7087static void gen_vmrgew(DisasContext *ctx)
7088{
7089 TCGv_i64 tmp;
7090 int VT, VA, VB;
7091 if (unlikely(!ctx->altivec_enabled)) {
7092 gen_exception(ctx, POWERPC_EXCP_VPU);
7093 return;
7094 }
7095 VT = rD(ctx->opcode);
7096 VA = rA(ctx->opcode);
7097 VB = rB(ctx->opcode);
7098 tmp = tcg_temp_new_i64();
7099 tcg_gen_shri_i64(tmp, cpu_avrh[VB], 32);
7100 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VA], tmp, 0, 32);
7101 tcg_gen_shri_i64(tmp, cpu_avrl[VB], 32);
7102 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VA], tmp, 0, 32);
7103 tcg_temp_free_i64(tmp);
7104}
7105
7106static void gen_vmrgow(DisasContext *ctx)
7107{
7108 int VT, VA, VB;
7109 if (unlikely(!ctx->altivec_enabled)) {
7110 gen_exception(ctx, POWERPC_EXCP_VPU);
7111 return;
7112 }
7113 VT = rD(ctx->opcode);
7114 VA = rA(ctx->opcode);
7115 VB = rB(ctx->opcode);
7116
7117 tcg_gen_deposit_i64(cpu_avrh[VT], cpu_avrh[VB], cpu_avrh[VA], 32, 32);
7118 tcg_gen_deposit_i64(cpu_avrl[VT], cpu_avrl[VB], cpu_avrl[VA], 32, 32);
7119}
7120
2c277908
AJ
7121GEN_VXFORM(vmuloub, 4, 0);
7122GEN_VXFORM(vmulouh, 4, 1);
63be0936 7123GEN_VXFORM(vmulouw, 4, 2);
953f0f58
TM
7124GEN_VXFORM(vmuluwm, 4, 2);
7125GEN_VXFORM_DUAL(vmulouw, PPC_ALTIVEC, PPC_NONE,
7126 vmuluwm, PPC_NONE, PPC2_ALTIVEC_207)
2c277908
AJ
7127GEN_VXFORM(vmulosb, 4, 4);
7128GEN_VXFORM(vmulosh, 4, 5);
63be0936 7129GEN_VXFORM(vmulosw, 4, 6);
2c277908
AJ
7130GEN_VXFORM(vmuleub, 4, 8);
7131GEN_VXFORM(vmuleuh, 4, 9);
63be0936 7132GEN_VXFORM(vmuleuw, 4, 10);
2c277908
AJ
7133GEN_VXFORM(vmulesb, 4, 12);
7134GEN_VXFORM(vmulesh, 4, 13);
63be0936 7135GEN_VXFORM(vmulesw, 4, 14);
d79f0809
AJ
7136GEN_VXFORM(vslb, 2, 4);
7137GEN_VXFORM(vslh, 2, 5);
7138GEN_VXFORM(vslw, 2, 6);
2fdf78e6 7139GEN_VXFORM(vsld, 2, 23);
07ef34c3
AJ
7140GEN_VXFORM(vsrb, 2, 8);
7141GEN_VXFORM(vsrh, 2, 9);
7142GEN_VXFORM(vsrw, 2, 10);
2fdf78e6 7143GEN_VXFORM(vsrd, 2, 27);
07ef34c3
AJ
7144GEN_VXFORM(vsrab, 2, 12);
7145GEN_VXFORM(vsrah, 2, 13);
7146GEN_VXFORM(vsraw, 2, 14);
2fdf78e6 7147GEN_VXFORM(vsrad, 2, 15);
7b239bec
AJ
7148GEN_VXFORM(vslo, 6, 16);
7149GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
7150GEN_VXFORM(vaddcuw, 0, 6);
7151GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
7152GEN_VXFORM_ENV(vaddubs, 0, 8);
7153GEN_VXFORM_ENV(vadduhs, 0, 9);
7154GEN_VXFORM_ENV(vadduws, 0, 10);
7155GEN_VXFORM_ENV(vaddsbs, 0, 12);
7156GEN_VXFORM_ENV(vaddshs, 0, 13);
7157GEN_VXFORM_ENV(vaddsws, 0, 14);
7158GEN_VXFORM_ENV(vsububs, 0, 24);
7159GEN_VXFORM_ENV(vsubuhs, 0, 25);
7160GEN_VXFORM_ENV(vsubuws, 0, 26);
7161GEN_VXFORM_ENV(vsubsbs, 0, 28);
7162GEN_VXFORM_ENV(vsubshs, 0, 29);
7163GEN_VXFORM_ENV(vsubsws, 0, 30);
b41da4eb
TM
7164GEN_VXFORM(vadduqm, 0, 4);
7165GEN_VXFORM(vaddcuq, 0, 5);
7166GEN_VXFORM3(vaddeuqm, 30, 0);
7167GEN_VXFORM3(vaddecuq, 30, 0);
7168GEN_VXFORM_DUAL(vaddeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7169 vaddecuq, PPC_NONE, PPC2_ALTIVEC_207)
7170GEN_VXFORM(vsubuqm, 0, 20);
7171GEN_VXFORM(vsubcuq, 0, 21);
7172GEN_VXFORM3(vsubeuqm, 31, 0);
7173GEN_VXFORM3(vsubecuq, 31, 0);
7174GEN_VXFORM_DUAL(vsubeuqm, PPC_NONE, PPC2_ALTIVEC_207, \
7175 vsubecuq, PPC_NONE, PPC2_ALTIVEC_207)
5e1d0985
AJ
7176GEN_VXFORM(vrlb, 2, 0);
7177GEN_VXFORM(vrlh, 2, 1);
7178GEN_VXFORM(vrlw, 2, 2);
2fdf78e6 7179GEN_VXFORM(vrld, 2, 3);
d9430add
AJ
7180GEN_VXFORM(vsl, 2, 7);
7181GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
7182GEN_VXFORM_ENV(vpkuhum, 7, 0);
7183GEN_VXFORM_ENV(vpkuwum, 7, 1);
024215b2 7184GEN_VXFORM_ENV(vpkudum, 7, 17);
d15f74fb
BS
7185GEN_VXFORM_ENV(vpkuhus, 7, 2);
7186GEN_VXFORM_ENV(vpkuwus, 7, 3);
024215b2 7187GEN_VXFORM_ENV(vpkudus, 7, 19);
d15f74fb
BS
7188GEN_VXFORM_ENV(vpkshus, 7, 4);
7189GEN_VXFORM_ENV(vpkswus, 7, 5);
024215b2 7190GEN_VXFORM_ENV(vpksdus, 7, 21);
d15f74fb
BS
7191GEN_VXFORM_ENV(vpkshss, 7, 6);
7192GEN_VXFORM_ENV(vpkswss, 7, 7);
024215b2 7193GEN_VXFORM_ENV(vpksdss, 7, 23);
1dd9ffb9 7194GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
7195GEN_VXFORM_ENV(vsum4ubs, 4, 24);
7196GEN_VXFORM_ENV(vsum4sbs, 4, 28);
7197GEN_VXFORM_ENV(vsum4shs, 4, 25);
7198GEN_VXFORM_ENV(vsum2sws, 4, 26);
7199GEN_VXFORM_ENV(vsumsws, 4, 30);
7200GEN_VXFORM_ENV(vaddfp, 5, 0);
7201GEN_VXFORM_ENV(vsubfp, 5, 1);
7202GEN_VXFORM_ENV(vmaxfp, 5, 16);
7203GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 7204
0cbcd906 7205#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 7206static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
7207 { \
7208 TCGv_ptr ra, rb, rd; \
7209 if (unlikely(!ctx->altivec_enabled)) { \
7210 gen_exception(ctx, POWERPC_EXCP_VPU); \
7211 return; \
7212 } \
7213 ra = gen_avr_ptr(rA(ctx->opcode)); \
7214 rb = gen_avr_ptr(rB(ctx->opcode)); \
7215 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 7216 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
7217 tcg_temp_free_ptr(ra); \
7218 tcg_temp_free_ptr(rb); \
7219 tcg_temp_free_ptr(rd); \
7220 }
7221
7222#define GEN_VXRFORM(name, opc2, opc3) \
7223 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7224 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7225
a737d3eb
TM
7226/*
7227 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7228 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7229 * come from different versions of the ISA, so we must also support a
7230 * pair of flags for each instruction.
7231 */
7232#define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7233static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7234{ \
7235 if ((Rc(ctx->opcode) == 0) && \
7236 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7237 if (Rc21(ctx->opcode) == 0) { \
7238 gen_##name0(ctx); \
7239 } else { \
7240 gen_##name0##_(ctx); \
7241 } \
7242 } else if ((Rc(ctx->opcode) == 1) && \
7243 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7244 if (Rc21(ctx->opcode) == 0) { \
7245 gen_##name1(ctx); \
7246 } else { \
7247 gen_##name1##_(ctx); \
7248 } \
7249 } else { \
7250 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7251 } \
7252}
7253
1add6e23
AJ
7254GEN_VXRFORM(vcmpequb, 3, 0)
7255GEN_VXRFORM(vcmpequh, 3, 1)
7256GEN_VXRFORM(vcmpequw, 3, 2)
6f3dab41 7257GEN_VXRFORM(vcmpequd, 3, 3)
1add6e23
AJ
7258GEN_VXRFORM(vcmpgtsb, 3, 12)
7259GEN_VXRFORM(vcmpgtsh, 3, 13)
7260GEN_VXRFORM(vcmpgtsw, 3, 14)
6f3dab41 7261GEN_VXRFORM(vcmpgtsd, 3, 15)
1add6e23
AJ
7262GEN_VXRFORM(vcmpgtub, 3, 8)
7263GEN_VXRFORM(vcmpgtuh, 3, 9)
7264GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 7265GEN_VXRFORM(vcmpgtud, 3, 11)
819ca121
AJ
7266GEN_VXRFORM(vcmpeqfp, 3, 3)
7267GEN_VXRFORM(vcmpgefp, 3, 7)
7268GEN_VXRFORM(vcmpgtfp, 3, 11)
7269GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 7270
6f3dab41
TM
7271GEN_VXRFORM_DUAL(vcmpeqfp, PPC_ALTIVEC, PPC_NONE, \
7272 vcmpequd, PPC_NONE, PPC2_ALTIVEC_207)
7273GEN_VXRFORM_DUAL(vcmpbfp, PPC_ALTIVEC, PPC_NONE, \
7274 vcmpgtsd, PPC_NONE, PPC2_ALTIVEC_207)
7275GEN_VXRFORM_DUAL(vcmpgtfp, PPC_ALTIVEC, PPC_NONE, \
7276 vcmpgtud, PPC_NONE, PPC2_ALTIVEC_207)
7277
c026766b 7278#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7279static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
7280 { \
7281 TCGv_ptr rd; \
7282 TCGv_i32 simm; \
7283 if (unlikely(!ctx->altivec_enabled)) { \
7284 gen_exception(ctx, POWERPC_EXCP_VPU); \
7285 return; \
7286 } \
7287 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7288 rd = gen_avr_ptr(rD(ctx->opcode)); \
7289 gen_helper_##name (rd, simm); \
7290 tcg_temp_free_i32(simm); \
7291 tcg_temp_free_ptr(rd); \
7292 }
7293
7294GEN_VXFORM_SIMM(vspltisb, 6, 12);
7295GEN_VXFORM_SIMM(vspltish, 6, 13);
7296GEN_VXFORM_SIMM(vspltisw, 6, 14);
7297
de5f2484 7298#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 7299static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
7300 { \
7301 TCGv_ptr rb, rd; \
7302 if (unlikely(!ctx->altivec_enabled)) { \
7303 gen_exception(ctx, POWERPC_EXCP_VPU); \
7304 return; \
7305 } \
7306 rb = gen_avr_ptr(rB(ctx->opcode)); \
7307 rd = gen_avr_ptr(rD(ctx->opcode)); \
7308 gen_helper_##name (rd, rb); \
7309 tcg_temp_free_ptr(rb); \
7310 tcg_temp_free_ptr(rd); \
7311 }
7312
d15f74fb
BS
7313#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7314static void glue(gen_, name)(DisasContext *ctx) \
7315 { \
7316 TCGv_ptr rb, rd; \
7317 \
7318 if (unlikely(!ctx->altivec_enabled)) { \
7319 gen_exception(ctx, POWERPC_EXCP_VPU); \
7320 return; \
7321 } \
7322 rb = gen_avr_ptr(rB(ctx->opcode)); \
7323 rd = gen_avr_ptr(rD(ctx->opcode)); \
7324 gen_helper_##name(cpu_env, rd, rb); \
7325 tcg_temp_free_ptr(rb); \
7326 tcg_temp_free_ptr(rd); \
7327 }
7328
6cf1c6e5
AJ
7329GEN_VXFORM_NOA(vupkhsb, 7, 8);
7330GEN_VXFORM_NOA(vupkhsh, 7, 9);
4430e076 7331GEN_VXFORM_NOA(vupkhsw, 7, 25);
6cf1c6e5
AJ
7332GEN_VXFORM_NOA(vupklsb, 7, 10);
7333GEN_VXFORM_NOA(vupklsh, 7, 11);
4430e076 7334GEN_VXFORM_NOA(vupklsw, 7, 27);
79f85c3a
AJ
7335GEN_VXFORM_NOA(vupkhpx, 7, 13);
7336GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
7337GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
7338GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
7339GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
7340GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
abe60a43
TM
7341GEN_VXFORM_NOA_ENV(vrfim, 5, 11);
7342GEN_VXFORM_NOA_ENV(vrfin, 5, 8);
d15f74fb 7343GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
abe60a43 7344GEN_VXFORM_NOA_ENV(vrfiz, 5, 9);
79f85c3a 7345
21d21583 7346#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 7347static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
7348 { \
7349 TCGv_ptr rd; \
7350 TCGv_i32 simm; \
7351 if (unlikely(!ctx->altivec_enabled)) { \
7352 gen_exception(ctx, POWERPC_EXCP_VPU); \
7353 return; \
7354 } \
7355 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7356 rd = gen_avr_ptr(rD(ctx->opcode)); \
7357 gen_helper_##name (rd, simm); \
7358 tcg_temp_free_i32(simm); \
7359 tcg_temp_free_ptr(rd); \
7360 }
7361
27a4edb3 7362#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 7363static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
7364 { \
7365 TCGv_ptr rb, rd; \
7366 TCGv_i32 uimm; \
7367 if (unlikely(!ctx->altivec_enabled)) { \
7368 gen_exception(ctx, POWERPC_EXCP_VPU); \
7369 return; \
7370 } \
7371 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7372 rb = gen_avr_ptr(rB(ctx->opcode)); \
7373 rd = gen_avr_ptr(rD(ctx->opcode)); \
7374 gen_helper_##name (rd, rb, uimm); \
7375 tcg_temp_free_i32(uimm); \
7376 tcg_temp_free_ptr(rb); \
7377 tcg_temp_free_ptr(rd); \
7378 }
7379
d15f74fb
BS
7380#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7381static void glue(gen_, name)(DisasContext *ctx) \
7382 { \
7383 TCGv_ptr rb, rd; \
7384 TCGv_i32 uimm; \
7385 \
7386 if (unlikely(!ctx->altivec_enabled)) { \
7387 gen_exception(ctx, POWERPC_EXCP_VPU); \
7388 return; \
7389 } \
7390 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7391 rb = gen_avr_ptr(rB(ctx->opcode)); \
7392 rd = gen_avr_ptr(rD(ctx->opcode)); \
7393 gen_helper_##name(cpu_env, rd, rb, uimm); \
7394 tcg_temp_free_i32(uimm); \
7395 tcg_temp_free_ptr(rb); \
7396 tcg_temp_free_ptr(rd); \
7397 }
7398
e4e6bee7
AJ
7399GEN_VXFORM_UIMM(vspltb, 6, 8);
7400GEN_VXFORM_UIMM(vsplth, 6, 9);
7401GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
7402GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
7403GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
7404GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
7405GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 7406
99e300ef 7407static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
7408{
7409 TCGv_ptr ra, rb, rd;
fce5ecb7 7410 TCGv_i32 sh;
cd633b10
AJ
7411 if (unlikely(!ctx->altivec_enabled)) {
7412 gen_exception(ctx, POWERPC_EXCP_VPU);
7413 return;
7414 }
7415 ra = gen_avr_ptr(rA(ctx->opcode));
7416 rb = gen_avr_ptr(rB(ctx->opcode));
7417 rd = gen_avr_ptr(rD(ctx->opcode));
7418 sh = tcg_const_i32(VSH(ctx->opcode));
7419 gen_helper_vsldoi (rd, ra, rb, sh);
7420 tcg_temp_free_ptr(ra);
7421 tcg_temp_free_ptr(rb);
7422 tcg_temp_free_ptr(rd);
fce5ecb7 7423 tcg_temp_free_i32(sh);
cd633b10
AJ
7424}
7425
707cec33 7426#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 7427static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
7428 { \
7429 TCGv_ptr ra, rb, rc, rd; \
7430 if (unlikely(!ctx->altivec_enabled)) { \
7431 gen_exception(ctx, POWERPC_EXCP_VPU); \
7432 return; \
7433 } \
7434 ra = gen_avr_ptr(rA(ctx->opcode)); \
7435 rb = gen_avr_ptr(rB(ctx->opcode)); \
7436 rc = gen_avr_ptr(rC(ctx->opcode)); \
7437 rd = gen_avr_ptr(rD(ctx->opcode)); \
7438 if (Rc(ctx->opcode)) { \
d15f74fb 7439 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 7440 } else { \
d15f74fb 7441 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
7442 } \
7443 tcg_temp_free_ptr(ra); \
7444 tcg_temp_free_ptr(rb); \
7445 tcg_temp_free_ptr(rc); \
7446 tcg_temp_free_ptr(rd); \
7447 }
7448
b161ae27
AJ
7449GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
7450
99e300ef 7451static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
7452{
7453 TCGv_ptr ra, rb, rc, rd;
7454 if (unlikely(!ctx->altivec_enabled)) {
7455 gen_exception(ctx, POWERPC_EXCP_VPU);
7456 return;
7457 }
7458 ra = gen_avr_ptr(rA(ctx->opcode));
7459 rb = gen_avr_ptr(rB(ctx->opcode));
7460 rc = gen_avr_ptr(rC(ctx->opcode));
7461 rd = gen_avr_ptr(rD(ctx->opcode));
7462 gen_helper_vmladduhm(rd, ra, rb, rc);
7463 tcg_temp_free_ptr(ra);
7464 tcg_temp_free_ptr(rb);
7465 tcg_temp_free_ptr(rc);
7466 tcg_temp_free_ptr(rd);
7467}
7468
b04ae981 7469GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7470GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7471GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7472GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7473GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7474
f293f04a
TM
7475GEN_VXFORM_NOA(vclzb, 1, 28)
7476GEN_VXFORM_NOA(vclzh, 1, 29)
7477GEN_VXFORM_NOA(vclzw, 1, 30)
7478GEN_VXFORM_NOA(vclzd, 1, 31)
e13500b3
TM
7479GEN_VXFORM_NOA(vpopcntb, 1, 28)
7480GEN_VXFORM_NOA(vpopcnth, 1, 29)
7481GEN_VXFORM_NOA(vpopcntw, 1, 30)
7482GEN_VXFORM_NOA(vpopcntd, 1, 31)
7483GEN_VXFORM_DUAL(vclzb, PPC_NONE, PPC2_ALTIVEC_207, \
7484 vpopcntb, PPC_NONE, PPC2_ALTIVEC_207)
7485GEN_VXFORM_DUAL(vclzh, PPC_NONE, PPC2_ALTIVEC_207, \
7486 vpopcnth, PPC_NONE, PPC2_ALTIVEC_207)
7487GEN_VXFORM_DUAL(vclzw, PPC_NONE, PPC2_ALTIVEC_207, \
7488 vpopcntw, PPC_NONE, PPC2_ALTIVEC_207)
7489GEN_VXFORM_DUAL(vclzd, PPC_NONE, PPC2_ALTIVEC_207, \
7490 vpopcntd, PPC_NONE, PPC2_ALTIVEC_207)
4d82038e 7491GEN_VXFORM(vbpermq, 6, 21);
f1064f61 7492GEN_VXFORM_NOA(vgbbd, 6, 20);
b8476fc7
TM
7493GEN_VXFORM(vpmsumb, 4, 16)
7494GEN_VXFORM(vpmsumh, 4, 17)
7495GEN_VXFORM(vpmsumw, 4, 18)
7496GEN_VXFORM(vpmsumd, 4, 19)
e13500b3 7497
e8f7b27b
TM
7498#define GEN_BCD(op) \
7499static void gen_##op(DisasContext *ctx) \
7500{ \
7501 TCGv_ptr ra, rb, rd; \
7502 TCGv_i32 ps; \
7503 \
7504 if (unlikely(!ctx->altivec_enabled)) { \
7505 gen_exception(ctx, POWERPC_EXCP_VPU); \
7506 return; \
7507 } \
7508 \
7509 ra = gen_avr_ptr(rA(ctx->opcode)); \
7510 rb = gen_avr_ptr(rB(ctx->opcode)); \
7511 rd = gen_avr_ptr(rD(ctx->opcode)); \
7512 \
7513 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7514 \
7515 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7516 \
7517 tcg_temp_free_ptr(ra); \
7518 tcg_temp_free_ptr(rb); \
7519 tcg_temp_free_ptr(rd); \
7520 tcg_temp_free_i32(ps); \
7521}
7522
7523GEN_BCD(bcdadd)
7524GEN_BCD(bcdsub)
7525
7526GEN_VXFORM_DUAL(vsububm, PPC_ALTIVEC, PPC_NONE, \
7527 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7528GEN_VXFORM_DUAL(vsububs, PPC_ALTIVEC, PPC_NONE, \
7529 bcdadd, PPC_NONE, PPC2_ALTIVEC_207)
7530GEN_VXFORM_DUAL(vsubuhm, PPC_ALTIVEC, PPC_NONE, \
7531 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7532GEN_VXFORM_DUAL(vsubuhs, PPC_ALTIVEC, PPC_NONE, \
7533 bcdsub, PPC_NONE, PPC2_ALTIVEC_207)
7534
557d52fa
TM
7535static void gen_vsbox(DisasContext *ctx)
7536{
7537 TCGv_ptr ra, rd;
7538 if (unlikely(!ctx->altivec_enabled)) {
7539 gen_exception(ctx, POWERPC_EXCP_VPU);
7540 return;
7541 }
7542 ra = gen_avr_ptr(rA(ctx->opcode));
7543 rd = gen_avr_ptr(rD(ctx->opcode));
7544 gen_helper_vsbox(rd, ra);
7545 tcg_temp_free_ptr(ra);
7546 tcg_temp_free_ptr(rd);
7547}
7548
7549GEN_VXFORM(vcipher, 4, 20)
7550GEN_VXFORM(vcipherlast, 4, 20)
7551GEN_VXFORM(vncipher, 4, 21)
7552GEN_VXFORM(vncipherlast, 4, 21)
7553
7554GEN_VXFORM_DUAL(vcipher, PPC_NONE, PPC2_ALTIVEC_207,
7555 vcipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7556GEN_VXFORM_DUAL(vncipher, PPC_NONE, PPC2_ALTIVEC_207,
7557 vncipherlast, PPC_NONE, PPC2_ALTIVEC_207)
7558
57354f8f
TM
7559#define VSHASIGMA(op) \
7560static void gen_##op(DisasContext *ctx) \
7561{ \
7562 TCGv_ptr ra, rd; \
7563 TCGv_i32 st_six; \
7564 if (unlikely(!ctx->altivec_enabled)) { \
7565 gen_exception(ctx, POWERPC_EXCP_VPU); \
7566 return; \
7567 } \
7568 ra = gen_avr_ptr(rA(ctx->opcode)); \
7569 rd = gen_avr_ptr(rD(ctx->opcode)); \
7570 st_six = tcg_const_i32(rB(ctx->opcode)); \
7571 gen_helper_##op(rd, ra, st_six); \
7572 tcg_temp_free_ptr(ra); \
7573 tcg_temp_free_ptr(rd); \
7574 tcg_temp_free_i32(st_six); \
7575}
7576
7577VSHASIGMA(vshasigmaw)
7578VSHASIGMA(vshasigmad)
7579
ac174549
TM
7580GEN_VXFORM3(vpermxor, 22, 0xFF)
7581GEN_VXFORM_DUAL(vsldoi, PPC_ALTIVEC, PPC_NONE,
7582 vpermxor, PPC_NONE, PPC2_ALTIVEC_207)
7583
472b24ce
TM
7584/*** VSX extension ***/
7585
7586static inline TCGv_i64 cpu_vsrh(int n)
7587{
7588 if (n < 32) {
7589 return cpu_fpr[n];
7590 } else {
7591 return cpu_avrh[n-32];
7592 }
7593}
7594
7595static inline TCGv_i64 cpu_vsrl(int n)
7596{
7597 if (n < 32) {
7598 return cpu_vsr[n];
7599 } else {
7600 return cpu_avrl[n-32];
7601 }
7602}
7603
e072fe79
TM
7604#define VSX_LOAD_SCALAR(name, operation) \
7605static void gen_##name(DisasContext *ctx) \
7606{ \
7607 TCGv EA; \
7608 if (unlikely(!ctx->vsx_enabled)) { \
7609 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7610 return; \
7611 } \
7612 gen_set_access_type(ctx, ACCESS_INT); \
7613 EA = tcg_temp_new(); \
7614 gen_addr_reg_index(ctx, EA); \
7615 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7616 /* NOTE: cpu_vsrl is undefined */ \
7617 tcg_temp_free(EA); \
7618}
7619
7620VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7621VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7622VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7623VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7624
304af367
TM
7625static void gen_lxvd2x(DisasContext *ctx)
7626{
7627 TCGv EA;
7628 if (unlikely(!ctx->vsx_enabled)) {
7629 gen_exception(ctx, POWERPC_EXCP_VSXU);
7630 return;
7631 }
7632 gen_set_access_type(ctx, ACCESS_INT);
7633 EA = tcg_temp_new();
7634 gen_addr_reg_index(ctx, EA);
7635 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7636 tcg_gen_addi_tl(EA, EA, 8);
7637 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7638 tcg_temp_free(EA);
7639}
7640
ca03b467
TM
7641static void gen_lxvdsx(DisasContext *ctx)
7642{
7643 TCGv EA;
7644 if (unlikely(!ctx->vsx_enabled)) {
7645 gen_exception(ctx, POWERPC_EXCP_VSXU);
7646 return;
7647 }
7648 gen_set_access_type(ctx, ACCESS_INT);
7649 EA = tcg_temp_new();
7650 gen_addr_reg_index(ctx, EA);
7651 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7652 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7653 tcg_temp_free(EA);
7654}
7655
897e61d1
TM
7656static void gen_lxvw4x(DisasContext *ctx)
7657{
f976b09e
AG
7658 TCGv EA;
7659 TCGv_i64 tmp;
897e61d1
TM
7660 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7661 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7662 if (unlikely(!ctx->vsx_enabled)) {
7663 gen_exception(ctx, POWERPC_EXCP_VSXU);
7664 return;
7665 }
7666 gen_set_access_type(ctx, ACCESS_INT);
7667 EA = tcg_temp_new();
f976b09e
AG
7668 tmp = tcg_temp_new_i64();
7669
897e61d1 7670 gen_addr_reg_index(ctx, EA);
f976b09e 7671 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7672 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7673 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7674 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7675
7676 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7677 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7678 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7679 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7680 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7681
7682 tcg_temp_free(EA);
f976b09e 7683 tcg_temp_free_i64(tmp);
897e61d1
TM
7684}
7685
f026da78
TM
7686#define VSX_STORE_SCALAR(name, operation) \
7687static void gen_##name(DisasContext *ctx) \
7688{ \
7689 TCGv EA; \
7690 if (unlikely(!ctx->vsx_enabled)) { \
7691 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7692 return; \
7693 } \
7694 gen_set_access_type(ctx, ACCESS_INT); \
7695 EA = tcg_temp_new(); \
7696 gen_addr_reg_index(ctx, EA); \
7697 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7698 tcg_temp_free(EA); \
9231ba9e
TM
7699}
7700
f026da78 7701VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7702VSX_STORE_SCALAR(stxsiwx, st32_i64)
7703VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7704
fbed2478
TM
7705static void gen_stxvd2x(DisasContext *ctx)
7706{
7707 TCGv EA;
7708 if (unlikely(!ctx->vsx_enabled)) {
7709 gen_exception(ctx, POWERPC_EXCP_VSXU);
7710 return;
7711 }
7712 gen_set_access_type(ctx, ACCESS_INT);
7713 EA = tcg_temp_new();
7714 gen_addr_reg_index(ctx, EA);
7715 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7716 tcg_gen_addi_tl(EA, EA, 8);
7717 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7718 tcg_temp_free(EA);
7719}
7720
86e61ce3
TM
7721static void gen_stxvw4x(DisasContext *ctx)
7722{
f976b09e
AG
7723 TCGv_i64 tmp;
7724 TCGv EA;
86e61ce3
TM
7725 if (unlikely(!ctx->vsx_enabled)) {
7726 gen_exception(ctx, POWERPC_EXCP_VSXU);
7727 return;
7728 }
7729 gen_set_access_type(ctx, ACCESS_INT);
7730 EA = tcg_temp_new();
7731 gen_addr_reg_index(ctx, EA);
f976b09e 7732 tmp = tcg_temp_new_i64();
86e61ce3
TM
7733
7734 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7735 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7736 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7737 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7738
7739 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7740 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7741 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7742 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7743 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7744
7745 tcg_temp_free(EA);
f976b09e 7746 tcg_temp_free_i64(tmp);
86e61ce3
TM
7747}
7748
f5c0f7f9
TM
7749#define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7750static void gen_##name(DisasContext *ctx) \
7751{ \
7752 if (xS(ctx->opcode) < 32) { \
7753 if (unlikely(!ctx->fpu_enabled)) { \
7754 gen_exception(ctx, POWERPC_EXCP_FPU); \
7755 return; \
7756 } \
7757 } else { \
7758 if (unlikely(!ctx->altivec_enabled)) { \
7759 gen_exception(ctx, POWERPC_EXCP_VPU); \
7760 return; \
7761 } \
7762 } \
7763 TCGv_i64 tmp = tcg_temp_new_i64(); \
7764 tcg_gen_##tcgop1(tmp, source); \
7765 tcg_gen_##tcgop2(target, tmp); \
7766 tcg_temp_free_i64(tmp); \
7767}
7768
7769
7770MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \
7771 cpu_vsrh(xS(ctx->opcode)))
7772MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \
7773 cpu_gpr[rA(ctx->opcode)])
7774MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \
7775 cpu_gpr[rA(ctx->opcode)])
7776
7777#if defined(TARGET_PPC64)
7778#define MV_VSRD(name, target, source) \
7779static void gen_##name(DisasContext *ctx) \
7780{ \
7781 if (xS(ctx->opcode) < 32) { \
7782 if (unlikely(!ctx->fpu_enabled)) { \
7783 gen_exception(ctx, POWERPC_EXCP_FPU); \
7784 return; \
7785 } \
7786 } else { \
7787 if (unlikely(!ctx->altivec_enabled)) { \
7788 gen_exception(ctx, POWERPC_EXCP_VPU); \
7789 return; \
7790 } \
7791 } \
7792 tcg_gen_mov_i64(target, source); \
7793}
7794
7795MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode)))
7796MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)])
7797
7798#endif
7799
cd73f2c9
TM
7800static void gen_xxpermdi(DisasContext *ctx)
7801{
7802 if (unlikely(!ctx->vsx_enabled)) {
7803 gen_exception(ctx, POWERPC_EXCP_VSXU);
7804 return;
7805 }
7806
f5bc1bfa
TM
7807 if (unlikely((xT(ctx->opcode) == xA(ctx->opcode)) ||
7808 (xT(ctx->opcode) == xB(ctx->opcode)))) {
7809 TCGv_i64 xh, xl;
7810
7811 xh = tcg_temp_new_i64();
7812 xl = tcg_temp_new_i64();
7813
7814 if ((DM(ctx->opcode) & 2) == 0) {
7815 tcg_gen_mov_i64(xh, cpu_vsrh(xA(ctx->opcode)));
7816 } else {
7817 tcg_gen_mov_i64(xh, cpu_vsrl(xA(ctx->opcode)));
7818 }
7819 if ((DM(ctx->opcode) & 1) == 0) {
7820 tcg_gen_mov_i64(xl, cpu_vsrh(xB(ctx->opcode)));
7821 } else {
7822 tcg_gen_mov_i64(xl, cpu_vsrl(xB(ctx->opcode)));
7823 }
7824
7825 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xh);
7826 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xl);
7827
7828 tcg_temp_free_i64(xh);
7829 tcg_temp_free_i64(xl);
cd73f2c9 7830 } else {
f5bc1bfa
TM
7831 if ((DM(ctx->opcode) & 2) == 0) {
7832 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7833 } else {
7834 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7835 }
7836 if ((DM(ctx->opcode) & 1) == 0) {
7837 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7838 } else {
7839 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7840 }
cd73f2c9
TM
7841 }
7842}
7843
df020ce0
TM
7844#define OP_ABS 1
7845#define OP_NABS 2
7846#define OP_NEG 3
7847#define OP_CPSGN 4
e5d7d2b0
PM
7848#define SGN_MASK_DP 0x8000000000000000ull
7849#define SGN_MASK_SP 0x8000000080000000ull
df020ce0
TM
7850
7851#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7852static void glue(gen_, name)(DisasContext * ctx) \
7853 { \
7854 TCGv_i64 xb, sgm; \
7855 if (unlikely(!ctx->vsx_enabled)) { \
7856 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7857 return; \
7858 } \
f976b09e
AG
7859 xb = tcg_temp_new_i64(); \
7860 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7861 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7862 tcg_gen_movi_i64(sgm, sgn_mask); \
7863 switch (op) { \
7864 case OP_ABS: { \
7865 tcg_gen_andc_i64(xb, xb, sgm); \
7866 break; \
7867 } \
7868 case OP_NABS: { \
7869 tcg_gen_or_i64(xb, xb, sgm); \
7870 break; \
7871 } \
7872 case OP_NEG: { \
7873 tcg_gen_xor_i64(xb, xb, sgm); \
7874 break; \
7875 } \
7876 case OP_CPSGN: { \
f976b09e 7877 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7878 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7879 tcg_gen_and_i64(xa, xa, sgm); \
7880 tcg_gen_andc_i64(xb, xb, sgm); \
7881 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7882 tcg_temp_free_i64(xa); \
df020ce0
TM
7883 break; \
7884 } \
7885 } \
7886 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7887 tcg_temp_free_i64(xb); \
7888 tcg_temp_free_i64(sgm); \
df020ce0
TM
7889 }
7890
7891VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7892VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7893VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7894VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7895
be574920
TM
7896#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7897static void glue(gen_, name)(DisasContext * ctx) \
7898 { \
7899 TCGv_i64 xbh, xbl, sgm; \
7900 if (unlikely(!ctx->vsx_enabled)) { \
7901 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7902 return; \
7903 } \
f976b09e
AG
7904 xbh = tcg_temp_new_i64(); \
7905 xbl = tcg_temp_new_i64(); \
7906 sgm = tcg_temp_new_i64(); \
be574920
TM
7907 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7908 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7909 tcg_gen_movi_i64(sgm, sgn_mask); \
7910 switch (op) { \
7911 case OP_ABS: { \
7912 tcg_gen_andc_i64(xbh, xbh, sgm); \
7913 tcg_gen_andc_i64(xbl, xbl, sgm); \
7914 break; \
7915 } \
7916 case OP_NABS: { \
7917 tcg_gen_or_i64(xbh, xbh, sgm); \
7918 tcg_gen_or_i64(xbl, xbl, sgm); \
7919 break; \
7920 } \
7921 case OP_NEG: { \
7922 tcg_gen_xor_i64(xbh, xbh, sgm); \
7923 tcg_gen_xor_i64(xbl, xbl, sgm); \
7924 break; \
7925 } \
7926 case OP_CPSGN: { \
f976b09e
AG
7927 TCGv_i64 xah = tcg_temp_new_i64(); \
7928 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7929 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7930 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7931 tcg_gen_and_i64(xah, xah, sgm); \
7932 tcg_gen_and_i64(xal, xal, sgm); \
7933 tcg_gen_andc_i64(xbh, xbh, sgm); \
7934 tcg_gen_andc_i64(xbl, xbl, sgm); \
7935 tcg_gen_or_i64(xbh, xbh, xah); \
7936 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7937 tcg_temp_free_i64(xah); \
7938 tcg_temp_free_i64(xal); \
be574920
TM
7939 break; \
7940 } \
7941 } \
7942 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7943 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7944 tcg_temp_free_i64(xbh); \
7945 tcg_temp_free_i64(xbl); \
7946 tcg_temp_free_i64(sgm); \
be574920
TM
7947 }
7948
7949VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7950VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7951VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7952VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7953VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7954VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7955VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7956VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7957
3c3cbbdc
TM
7958#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7959static void gen_##name(DisasContext * ctx) \
7960{ \
7961 TCGv_i32 opc; \
7962 if (unlikely(!ctx->vsx_enabled)) { \
7963 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7964 return; \
7965 } \
7966 /* NIP cannot be restored if the memory exception comes from an helper */ \
7967 gen_update_nip(ctx, ctx->nip - 4); \
7968 opc = tcg_const_i32(ctx->opcode); \
7969 gen_helper_##name(cpu_env, opc); \
7970 tcg_temp_free_i32(opc); \
7971}
be574920 7972
3d1140bf
TM
7973#define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7974static void gen_##name(DisasContext * ctx) \
7975{ \
7976 if (unlikely(!ctx->vsx_enabled)) { \
7977 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7978 return; \
7979 } \
7980 /* NIP cannot be restored if the exception comes */ \
7981 /* from a helper. */ \
7982 gen_update_nip(ctx, ctx->nip - 4); \
7983 \
7984 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7985 cpu_vsrh(xB(ctx->opcode))); \
7986}
7987
ee6e02c0
TM
7988GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7989GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7990GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7991GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7992GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7993GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7994GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7995GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7996GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7997GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7998GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7999GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
8000GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
8001GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
8002GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
8003GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
8004GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
8005GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
8006GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
8007GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
8008GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568 8009GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7ee19fb9 8010GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207)
ed8ac568 8011GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
7ee19fb9 8012GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207)
5177d2ca
TM
8013GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
8014GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
8015GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
8016GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
8017GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
8018GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
8019GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
8020GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
8021GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
8022GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
8023GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
3d1140bf 8024GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207)
ee6e02c0 8025
3fd0aadf
TM
8026GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
8027GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 8028GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 8029GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 8030GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 8031GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
968e76bc 8032GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207)
f53f81e0
TM
8033GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207)
8034GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207)
8035GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207)
8036GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207)
8037GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207)
8038GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207)
8039GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207)
8040GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207)
74698350
TM
8041GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207)
8042GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207)
3fd0aadf 8043
ee6e02c0
TM
8044GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
8045GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 8046GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 8047GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 8048GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 8049GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 8050GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 8051GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 8052GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
8053GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
8054GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
8055GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
8056GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
8057GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
8058GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
8059GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
8060GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
8061GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
8062GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
8063GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
8064GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
8065GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 8066GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
8067GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
8068GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
8069GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
8070GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
8071GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
8072GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
8073GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
8074GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
8075GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
8076GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
8077GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
8078GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
8079GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
8080
8081GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
8082GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 8083GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 8084GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 8085GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 8086GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 8087GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 8088GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 8089GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
8090GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
8091GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
8092GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
8093GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
8094GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
8095GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
8096GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
8097GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
8098GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
8099GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
8100GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
8101GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
8102GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 8103GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
8104GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
8105GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
8106GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
8107GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
8108GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
8109GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
8110GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
8111GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
8112GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
8113GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
8114GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
8115GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
8116GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 8117
79ca8a6a
TM
8118#define VSX_LOGICAL(name, tcg_op) \
8119static void glue(gen_, name)(DisasContext * ctx) \
8120 { \
8121 if (unlikely(!ctx->vsx_enabled)) { \
8122 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8123 return; \
8124 } \
8125 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8126 cpu_vsrh(xB(ctx->opcode))); \
8127 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8128 cpu_vsrl(xB(ctx->opcode))); \
8129 }
8130
f976b09e
AG
8131VSX_LOGICAL(xxland, tcg_gen_and_i64)
8132VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
8133VSX_LOGICAL(xxlor, tcg_gen_or_i64)
8134VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
8135VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
67a33f37
TM
8136VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64)
8137VSX_LOGICAL(xxlnand, tcg_gen_nand_i64)
8138VSX_LOGICAL(xxlorc, tcg_gen_orc_i64)
df020ce0 8139
ce577d2e
TM
8140#define VSX_XXMRG(name, high) \
8141static void glue(gen_, name)(DisasContext * ctx) \
8142 { \
8143 TCGv_i64 a0, a1, b0, b1; \
8144 if (unlikely(!ctx->vsx_enabled)) { \
8145 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8146 return; \
8147 } \
f976b09e
AG
8148 a0 = tcg_temp_new_i64(); \
8149 a1 = tcg_temp_new_i64(); \
8150 b0 = tcg_temp_new_i64(); \
8151 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
8152 if (high) { \
8153 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8154 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8155 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8156 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8157 } else { \
8158 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8159 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8160 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8161 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8162 } \
8163 tcg_gen_shri_i64(a0, a0, 32); \
8164 tcg_gen_shri_i64(b0, b0, 32); \
8165 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8166 b0, a0, 32, 32); \
8167 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8168 b1, a1, 32, 32); \
f976b09e
AG
8169 tcg_temp_free_i64(a0); \
8170 tcg_temp_free_i64(a1); \
8171 tcg_temp_free_i64(b0); \
8172 tcg_temp_free_i64(b1); \
ce577d2e
TM
8173 }
8174
8175VSX_XXMRG(xxmrghw, 1)
8176VSX_XXMRG(xxmrglw, 0)
8177
551e3ef7
TM
8178static void gen_xxsel(DisasContext * ctx)
8179{
8180 TCGv_i64 a, b, c;
8181 if (unlikely(!ctx->vsx_enabled)) {
8182 gen_exception(ctx, POWERPC_EXCP_VSXU);
8183 return;
8184 }
f976b09e
AG
8185 a = tcg_temp_new_i64();
8186 b = tcg_temp_new_i64();
8187 c = tcg_temp_new_i64();
551e3ef7
TM
8188
8189 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
8190 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
8191 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
8192
8193 tcg_gen_and_i64(b, b, c);
8194 tcg_gen_andc_i64(a, a, c);
8195 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
8196
8197 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
8198 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
8199 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
8200
8201 tcg_gen_and_i64(b, b, c);
8202 tcg_gen_andc_i64(a, a, c);
8203 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
8204
f976b09e
AG
8205 tcg_temp_free_i64(a);
8206 tcg_temp_free_i64(b);
8207 tcg_temp_free_i64(c);
551e3ef7
TM
8208}
8209
76c15fe0
TM
8210static void gen_xxspltw(DisasContext *ctx)
8211{
8212 TCGv_i64 b, b2;
8213 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
8214 cpu_vsrl(xB(ctx->opcode)) :
8215 cpu_vsrh(xB(ctx->opcode));
8216
8217 if (unlikely(!ctx->vsx_enabled)) {
8218 gen_exception(ctx, POWERPC_EXCP_VSXU);
8219 return;
8220 }
8221
f976b09e
AG
8222 b = tcg_temp_new_i64();
8223 b2 = tcg_temp_new_i64();
76c15fe0
TM
8224
8225 if (UIM(ctx->opcode) & 1) {
8226 tcg_gen_ext32u_i64(b, vsr);
8227 } else {
8228 tcg_gen_shri_i64(b, vsr, 32);
8229 }
8230
8231 tcg_gen_shli_i64(b2, b, 32);
8232 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
8233 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
8234
f976b09e
AG
8235 tcg_temp_free_i64(b);
8236 tcg_temp_free_i64(b2);
76c15fe0
TM
8237}
8238
acc42968
TM
8239static void gen_xxsldwi(DisasContext *ctx)
8240{
8241 TCGv_i64 xth, xtl;
8242 if (unlikely(!ctx->vsx_enabled)) {
8243 gen_exception(ctx, POWERPC_EXCP_VSXU);
8244 return;
8245 }
f976b09e
AG
8246 xth = tcg_temp_new_i64();
8247 xtl = tcg_temp_new_i64();
acc42968
TM
8248
8249 switch (SHW(ctx->opcode)) {
8250 case 0: {
8251 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8252 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8253 break;
8254 }
8255 case 1: {
f976b09e 8256 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8257 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
8258 tcg_gen_shli_i64(xth, xth, 32);
8259 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
8260 tcg_gen_shri_i64(t0, t0, 32);
8261 tcg_gen_or_i64(xth, xth, t0);
8262 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
8263 tcg_gen_shli_i64(xtl, xtl, 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(xtl, xtl, t0);
f976b09e 8267 tcg_temp_free_i64(t0);
acc42968
TM
8268 break;
8269 }
8270 case 2: {
8271 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8272 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8273 break;
8274 }
8275 case 3: {
f976b09e 8276 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
8277 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
8278 tcg_gen_shli_i64(xth, xth, 32);
8279 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
8280 tcg_gen_shri_i64(t0, t0, 32);
8281 tcg_gen_or_i64(xth, xth, t0);
8282 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
8283 tcg_gen_shli_i64(xtl, xtl, 32);
8284 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
8285 tcg_gen_shri_i64(t0, t0, 32);
8286 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 8287 tcg_temp_free_i64(t0);
acc42968
TM
8288 break;
8289 }
8290 }
8291
8292 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
8293 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
8294
f976b09e
AG
8295 tcg_temp_free_i64(xth);
8296 tcg_temp_free_i64(xtl);
acc42968
TM
8297}
8298
f0b01f02
TM
8299/*** Decimal Floating Point ***/
8300
8301static inline TCGv_ptr gen_fprp_ptr(int reg)
8302{
8303 TCGv_ptr r = tcg_temp_new_ptr();
8304 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, fpr[reg]));
8305 return r;
8306}
8307
f0b01f02
TM
8308#define GEN_DFP_T_A_B_Rc(name) \
8309static void gen_##name(DisasContext *ctx) \
8310{ \
8311 TCGv_ptr rd, ra, rb; \
8312 if (unlikely(!ctx->fpu_enabled)) { \
8313 gen_exception(ctx, POWERPC_EXCP_FPU); \
8314 return; \
8315 } \
8316 gen_update_nip(ctx, ctx->nip - 4); \
8317 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8318 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8319 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8320 gen_helper_##name(cpu_env, rd, ra, rb); \
8321 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8322 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8323 } \
8324 tcg_temp_free_ptr(rd); \
8325 tcg_temp_free_ptr(ra); \
8326 tcg_temp_free_ptr(rb); \
8327}
8328
8329#define GEN_DFP_BF_A_B(name) \
8330static void gen_##name(DisasContext *ctx) \
8331{ \
8332 TCGv_ptr ra, rb; \
8333 if (unlikely(!ctx->fpu_enabled)) { \
8334 gen_exception(ctx, POWERPC_EXCP_FPU); \
8335 return; \
8336 } \
8337 gen_update_nip(ctx, ctx->nip - 4); \
8338 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8339 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8340 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8341 cpu_env, ra, rb); \
8342 tcg_temp_free_ptr(ra); \
8343 tcg_temp_free_ptr(rb); \
8344}
8345
8346#define GEN_DFP_BF_A_DCM(name) \
8347static void gen_##name(DisasContext *ctx) \
8348{ \
8349 TCGv_ptr ra; \
8350 TCGv_i32 dcm; \
8351 if (unlikely(!ctx->fpu_enabled)) { \
8352 gen_exception(ctx, POWERPC_EXCP_FPU); \
8353 return; \
8354 } \
8355 gen_update_nip(ctx, ctx->nip - 4); \
8356 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8357 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8358 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8359 cpu_env, ra, dcm); \
8360 tcg_temp_free_ptr(ra); \
8361 tcg_temp_free_i32(dcm); \
8362}
8363
8364#define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8365static void gen_##name(DisasContext *ctx) \
8366{ \
8367 TCGv_ptr rt, rb; \
8368 TCGv_i32 u32_1, u32_2; \
8369 if (unlikely(!ctx->fpu_enabled)) { \
8370 gen_exception(ctx, POWERPC_EXCP_FPU); \
8371 return; \
8372 } \
8373 gen_update_nip(ctx, ctx->nip - 4); \
8374 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8375 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8376 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8377 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8378 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8379 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8380 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8381 } \
8382 tcg_temp_free_ptr(rt); \
8383 tcg_temp_free_ptr(rb); \
8384 tcg_temp_free_i32(u32_1); \
8385 tcg_temp_free_i32(u32_2); \
8386}
8387
8388#define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8389static void gen_##name(DisasContext *ctx) \
8390{ \
8391 TCGv_ptr rt, ra, rb; \
8392 TCGv_i32 i32; \
8393 if (unlikely(!ctx->fpu_enabled)) { \
8394 gen_exception(ctx, POWERPC_EXCP_FPU); \
8395 return; \
8396 } \
8397 gen_update_nip(ctx, ctx->nip - 4); \
8398 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8399 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8400 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8401 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8402 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8403 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8404 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8405 } \
8406 tcg_temp_free_ptr(rt); \
8407 tcg_temp_free_ptr(rb); \
8408 tcg_temp_free_ptr(ra); \
8409 tcg_temp_free_i32(i32); \
8410 }
8411
8412#define GEN_DFP_T_B_Rc(name) \
8413static void gen_##name(DisasContext *ctx) \
8414{ \
8415 TCGv_ptr rt, rb; \
8416 if (unlikely(!ctx->fpu_enabled)) { \
8417 gen_exception(ctx, POWERPC_EXCP_FPU); \
8418 return; \
8419 } \
8420 gen_update_nip(ctx, ctx->nip - 4); \
8421 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8422 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8423 gen_helper_##name(cpu_env, rt, rb); \
8424 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8425 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8426 } \
8427 tcg_temp_free_ptr(rt); \
8428 tcg_temp_free_ptr(rb); \
8429 }
8430
8431#define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8432static void gen_##name(DisasContext *ctx) \
8433{ \
8434 TCGv_ptr rt, rs; \
8435 TCGv_i32 i32; \
8436 if (unlikely(!ctx->fpu_enabled)) { \
8437 gen_exception(ctx, POWERPC_EXCP_FPU); \
8438 return; \
8439 } \
8440 gen_update_nip(ctx, ctx->nip - 4); \
8441 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8442 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8443 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8444 gen_helper_##name(cpu_env, rt, rs, i32); \
8445 if (unlikely(Rc(ctx->opcode) != 0)) { \
e57d0202 8446 gen_set_cr1_from_fpscr(ctx); \
f0b01f02
TM
8447 } \
8448 tcg_temp_free_ptr(rt); \
8449 tcg_temp_free_ptr(rs); \
8450 tcg_temp_free_i32(i32); \
8451}
ce577d2e 8452
a9d7ba03
TM
8453GEN_DFP_T_A_B_Rc(dadd)
8454GEN_DFP_T_A_B_Rc(daddq)
2128f8a5
TM
8455GEN_DFP_T_A_B_Rc(dsub)
8456GEN_DFP_T_A_B_Rc(dsubq)
8de6a1cc
TM
8457GEN_DFP_T_A_B_Rc(dmul)
8458GEN_DFP_T_A_B_Rc(dmulq)
9024ff40
TM
8459GEN_DFP_T_A_B_Rc(ddiv)
8460GEN_DFP_T_A_B_Rc(ddivq)
5833505b
TM
8461GEN_DFP_BF_A_B(dcmpu)
8462GEN_DFP_BF_A_B(dcmpuq)
8463GEN_DFP_BF_A_B(dcmpo)
8464GEN_DFP_BF_A_B(dcmpoq)
e601c1ee
TM
8465GEN_DFP_BF_A_DCM(dtstdc)
8466GEN_DFP_BF_A_DCM(dtstdcq)
1bf9c0e1
TM
8467GEN_DFP_BF_A_DCM(dtstdg)
8468GEN_DFP_BF_A_DCM(dtstdgq)
f3d2b0bc
TM
8469GEN_DFP_BF_A_B(dtstex)
8470GEN_DFP_BF_A_B(dtstexq)
f6022a76
TM
8471GEN_DFP_BF_A_B(dtstsf)
8472GEN_DFP_BF_A_B(dtstsfq)
5826ebe2
TM
8473GEN_DFP_T_B_U32_U32_Rc(dquai, SIMM5, RMC)
8474GEN_DFP_T_B_U32_U32_Rc(dquaiq, SIMM5, RMC)
8475GEN_DFP_T_A_B_I32_Rc(dqua, RMC)
8476GEN_DFP_T_A_B_I32_Rc(dquaq, RMC)
512918aa
TM
8477GEN_DFP_T_A_B_I32_Rc(drrnd, RMC)
8478GEN_DFP_T_A_B_I32_Rc(drrndq, RMC)
97c0d930
TM
8479GEN_DFP_T_B_U32_U32_Rc(drintx, FPW, RMC)
8480GEN_DFP_T_B_U32_U32_Rc(drintxq, FPW, RMC)
8481GEN_DFP_T_B_U32_U32_Rc(drintn, FPW, RMC)
8482GEN_DFP_T_B_U32_U32_Rc(drintnq, FPW, RMC)
290d9ee5
TM
8483GEN_DFP_T_B_Rc(dctdp)
8484GEN_DFP_T_B_Rc(dctqpq)
ca603eb4
TM
8485GEN_DFP_T_B_Rc(drsp)
8486GEN_DFP_T_B_Rc(drdpq)
f1214193
TM
8487GEN_DFP_T_B_Rc(dcffix)
8488GEN_DFP_T_B_Rc(dcffixq)
bea0dd79
TM
8489GEN_DFP_T_B_Rc(dctfix)
8490GEN_DFP_T_B_Rc(dctfixq)
7796676f
TM
8491GEN_DFP_T_FPR_I32_Rc(ddedpd, rB, SP)
8492GEN_DFP_T_FPR_I32_Rc(ddedpdq, rB, SP)
013c3ac0
TM
8493GEN_DFP_T_FPR_I32_Rc(denbcd, rB, SP)
8494GEN_DFP_T_FPR_I32_Rc(denbcdq, rB, SP)
e8a48460
TM
8495GEN_DFP_T_B_Rc(dxex)
8496GEN_DFP_T_B_Rc(dxexq)
297666eb
TM
8497GEN_DFP_T_A_B_Rc(diex)
8498GEN_DFP_T_A_B_Rc(diexq)
804e654a
TM
8499GEN_DFP_T_FPR_I32_Rc(dscli, rA, DCM)
8500GEN_DFP_T_FPR_I32_Rc(dscliq, rA, DCM)
8501GEN_DFP_T_FPR_I32_Rc(dscri, rA, DCM)
8502GEN_DFP_T_FPR_I32_Rc(dscriq, rA, DCM)
8503
0487d6a8 8504/*** SPE extension ***/
0487d6a8 8505/* Register moves */
3cd7d1dd 8506
a0e13900
FC
8507static inline void gen_evmra(DisasContext *ctx)
8508{
8509
8510 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8511 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8512 return;
8513 }
8514
a0e13900
FC
8515 TCGv_i64 tmp = tcg_temp_new_i64();
8516
8517 /* tmp := rA_lo + rA_hi << 32 */
13b6a455 8518 tcg_gen_concat_tl_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
a0e13900
FC
8519
8520 /* spe_acc := tmp */
1328c2bf 8521 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8522 tcg_temp_free_i64(tmp);
8523
8524 /* rD := rA */
13b6a455
AG
8525 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8526 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
a0e13900
FC
8527}
8528
636aa200
BS
8529static inline void gen_load_gpr64(TCGv_i64 t, int reg)
8530{
13b6a455 8531 tcg_gen_concat_tl_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
f78fb44e 8532}
3cd7d1dd 8533
636aa200
BS
8534static inline void gen_store_gpr64(int reg, TCGv_i64 t)
8535{
13b6a455 8536 tcg_gen_extr_i64_tl(cpu_gpr[reg], cpu_gprh[reg], t);
f78fb44e 8537}
3cd7d1dd 8538
70560da7 8539#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 8540static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
8541{ \
8542 if (Rc(ctx->opcode)) \
8543 gen_##name1(ctx); \
8544 else \
8545 gen_##name0(ctx); \
8546}
8547
8548/* Handler for undefined SPE opcodes */
636aa200 8549static inline void gen_speundef(DisasContext *ctx)
0487d6a8 8550{
e06fcd75 8551 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
8552}
8553
57951c27 8554/* SPE logic */
57951c27 8555#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 8556static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8557{ \
8558 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8559 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8560 return; \
8561 } \
8562 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8563 cpu_gpr[rB(ctx->opcode)]); \
8564 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8565 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 8566}
57951c27
AJ
8567
8568GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
8569GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
8570GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
8571GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
8572GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
8573GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
8574GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
8575GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 8576
57951c27 8577/* SPE logic immediate */
57951c27 8578#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 8579static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a 8580{ \
13b6a455 8581 TCGv_i32 t0; \
3d3a6a0a 8582 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8583 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
8584 return; \
8585 } \
13b6a455
AG
8586 t0 = tcg_temp_new_i32(); \
8587 \
8588 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8589 tcg_opi(t0, t0, rB(ctx->opcode)); \
8590 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8591 \
8592 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
57951c27 8593 tcg_opi(t0, t0, rB(ctx->opcode)); \
13b6a455
AG
8594 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8595 \
a7812ae4 8596 tcg_temp_free_i32(t0); \
3d3a6a0a 8597}
57951c27
AJ
8598GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
8599GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
8600GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
8601GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 8602
57951c27 8603/* SPE arithmetic */
57951c27 8604#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 8605static inline void gen_##name(DisasContext *ctx) \
0487d6a8 8606{ \
13b6a455 8607 TCGv_i32 t0; \
0487d6a8 8608 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8609 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8610 return; \
8611 } \
13b6a455
AG
8612 t0 = tcg_temp_new_i32(); \
8613 \
8614 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
57951c27 8615 tcg_op(t0, t0); \
13b6a455
AG
8616 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8617 \
8618 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8619 tcg_op(t0, t0); \
8620 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8621 \
a7812ae4 8622 tcg_temp_free_i32(t0); \
57951c27 8623}
0487d6a8 8624
636aa200 8625static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27 8626{
42a268c2
RH
8627 TCGLabel *l1 = gen_new_label();
8628 TCGLabel *l2 = gen_new_label();
0487d6a8 8629
57951c27
AJ
8630 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
8631 tcg_gen_neg_i32(ret, arg1);
8632 tcg_gen_br(l2);
8633 gen_set_label(l1);
a7812ae4 8634 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
8635 gen_set_label(l2);
8636}
8637GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
8638GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
8639GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
8640GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 8641static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 8642{
57951c27
AJ
8643 tcg_gen_addi_i32(ret, arg1, 0x8000);
8644 tcg_gen_ext16u_i32(ret, ret);
8645}
8646GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
8647GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
8648GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 8649
57951c27 8650#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 8651static inline void gen_##name(DisasContext *ctx) \
0487d6a8 8652{ \
13b6a455 8653 TCGv_i32 t0, t1; \
0487d6a8 8654 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8655 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
8656 return; \
8657 } \
13b6a455
AG
8658 t0 = tcg_temp_new_i32(); \
8659 t1 = tcg_temp_new_i32(); \
8660 \
8661 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8662 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8663 tcg_op(t0, t0, t1); \
8664 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8665 \
8666 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8667 tcg_gen_trunc_tl_i32(t1, cpu_gprh[rB(ctx->opcode)]); \
8668 tcg_op(t0, t0, t1); \
8669 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8670 \
a7812ae4
PB
8671 tcg_temp_free_i32(t0); \
8672 tcg_temp_free_i32(t1); \
0487d6a8 8673}
0487d6a8 8674
636aa200 8675static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8676{
42a268c2
RH
8677 TCGLabel *l1 = gen_new_label();
8678 TCGLabel *l2 = gen_new_label();
8679 TCGv_i32 t0 = tcg_temp_local_new_i32();
0487d6a8 8680
57951c27
AJ
8681 /* No error here: 6 bits are used */
8682 tcg_gen_andi_i32(t0, arg2, 0x3F);
8683 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8684 tcg_gen_shr_i32(ret, arg1, t0);
8685 tcg_gen_br(l2);
8686 gen_set_label(l1);
8687 tcg_gen_movi_i32(ret, 0);
0aef4261 8688 gen_set_label(l2);
a7812ae4 8689 tcg_temp_free_i32(t0);
57951c27
AJ
8690}
8691GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 8692static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8693{
42a268c2
RH
8694 TCGLabel *l1 = gen_new_label();
8695 TCGLabel *l2 = gen_new_label();
8696 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8697
57951c27
AJ
8698 /* No error here: 6 bits are used */
8699 tcg_gen_andi_i32(t0, arg2, 0x3F);
8700 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8701 tcg_gen_sar_i32(ret, arg1, t0);
8702 tcg_gen_br(l2);
8703 gen_set_label(l1);
8704 tcg_gen_movi_i32(ret, 0);
0aef4261 8705 gen_set_label(l2);
a7812ae4 8706 tcg_temp_free_i32(t0);
57951c27
AJ
8707}
8708GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 8709static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8710{
42a268c2
RH
8711 TCGLabel *l1 = gen_new_label();
8712 TCGLabel *l2 = gen_new_label();
8713 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8714
57951c27
AJ
8715 /* No error here: 6 bits are used */
8716 tcg_gen_andi_i32(t0, arg2, 0x3F);
8717 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
8718 tcg_gen_shl_i32(ret, arg1, t0);
8719 tcg_gen_br(l2);
8720 gen_set_label(l1);
8721 tcg_gen_movi_i32(ret, 0);
e29ef9fa 8722 gen_set_label(l2);
a7812ae4 8723 tcg_temp_free_i32(t0);
57951c27
AJ
8724}
8725GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 8726static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 8727{
a7812ae4 8728 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
8729 tcg_gen_andi_i32(t0, arg2, 0x1F);
8730 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 8731 tcg_temp_free_i32(t0);
57951c27
AJ
8732}
8733GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 8734static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
8735{
8736 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8737 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8738 return;
8739 }
13b6a455
AG
8740 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8741 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27
AJ
8742}
8743GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 8744static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 8745{
57951c27
AJ
8746 tcg_gen_sub_i32(ret, arg2, arg1);
8747}
8748GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 8749
57951c27 8750/* SPE arithmetic immediate */
57951c27 8751#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 8752static inline void gen_##name(DisasContext *ctx) \
57951c27 8753{ \
13b6a455 8754 TCGv_i32 t0; \
57951c27 8755 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8756 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8757 return; \
8758 } \
13b6a455
AG
8759 t0 = tcg_temp_new_i32(); \
8760 \
8761 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
57951c27 8762 tcg_op(t0, t0, rA(ctx->opcode)); \
13b6a455
AG
8763 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8764 \
8765 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rB(ctx->opcode)]); \
8766 tcg_op(t0, t0, rA(ctx->opcode)); \
8767 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8768 \
a7812ae4 8769 tcg_temp_free_i32(t0); \
57951c27 8770}
57951c27
AJ
8771GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
8772GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8773
8774/* SPE comparison */
57951c27 8775#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8776static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8777{ \
8778 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8779 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8780 return; \
8781 } \
42a268c2
RH
8782 TCGLabel *l1 = gen_new_label(); \
8783 TCGLabel *l2 = gen_new_label(); \
8784 TCGLabel *l3 = gen_new_label(); \
8785 TCGLabel *l4 = gen_new_label(); \
57951c27 8786 \
13b6a455
AG
8787 tcg_gen_ext32s_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8788 tcg_gen_ext32s_tl(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8789 tcg_gen_ext32s_tl(cpu_gprh[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8790 tcg_gen_ext32s_tl(cpu_gprh[rB(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); \
8791 \
8792 tcg_gen_brcond_tl(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
57951c27 8793 cpu_gpr[rB(ctx->opcode)], l1); \
13b6a455 8794 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8795 tcg_gen_br(l2); \
8796 gen_set_label(l1); \
8797 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8798 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8799 gen_set_label(l2); \
13b6a455 8800 tcg_gen_brcond_tl(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
57951c27
AJ
8801 cpu_gprh[rB(ctx->opcode)], l3); \
8802 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8803 ~(CRF_CH | CRF_CH_AND_CL)); \
8804 tcg_gen_br(l4); \
8805 gen_set_label(l3); \
8806 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8807 CRF_CH | CRF_CH_OR_CL); \
8808 gen_set_label(l4); \
8809}
57951c27
AJ
8810GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8811GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8812GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8813GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8814GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8815
8816/* SPE misc */
636aa200 8817static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8818{
8819 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8820 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8821 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8822}
636aa200 8823static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8824{
8825 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8826 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8827 return;
8828 }
13b6a455
AG
8829 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8830 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27 8831}
636aa200 8832static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8833{
8834 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8835 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8836 return;
8837 }
13b6a455
AG
8838 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8839 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27 8840}
636aa200 8841static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8842{
8843 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8844 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8845 return;
8846 }
33890b3e 8847 if (rD(ctx->opcode) == rA(ctx->opcode)) {
13b6a455
AG
8848 TCGv tmp = tcg_temp_new();
8849 tcg_gen_mov_tl(tmp, cpu_gpr[rA(ctx->opcode)]);
8850 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8851 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], tmp);
8852 tcg_temp_free(tmp);
33890b3e 8853 } else {
13b6a455
AG
8854 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8855 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8856 }
57951c27 8857}
636aa200 8858static inline void gen_evsplati(DisasContext *ctx)
57951c27 8859{
ae01847f 8860 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8861
13b6a455
AG
8862 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
8863 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
57951c27 8864}
636aa200 8865static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8866{
ae01847f 8867 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8868
13b6a455
AG
8869 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], imm);
8870 tcg_gen_movi_tl(cpu_gprh[rD(ctx->opcode)], imm);
0487d6a8
JM
8871}
8872
636aa200 8873static inline void gen_evsel(DisasContext *ctx)
57951c27 8874{
42a268c2
RH
8875 TCGLabel *l1 = gen_new_label();
8876 TCGLabel *l2 = gen_new_label();
8877 TCGLabel *l3 = gen_new_label();
8878 TCGLabel *l4 = gen_new_label();
a7812ae4 8879 TCGv_i32 t0 = tcg_temp_local_new_i32();
42a268c2 8880
57951c27
AJ
8881 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8882 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
57951c27 8883 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
57951c27
AJ
8884 tcg_gen_br(l2);
8885 gen_set_label(l1);
57951c27 8886 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
57951c27
AJ
8887 gen_set_label(l2);
8888 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8889 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
57951c27 8890 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8891 tcg_gen_br(l4);
8892 gen_set_label(l3);
57951c27 8893 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27 8894 gen_set_label(l4);
a7812ae4 8895 tcg_temp_free_i32(t0);
57951c27 8896}
e8eaa2c0
BS
8897
8898static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
8899{
8900 gen_evsel(ctx);
8901}
e8eaa2c0
BS
8902
8903static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
8904{
8905 gen_evsel(ctx);
8906}
e8eaa2c0
BS
8907
8908static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
8909{
8910 gen_evsel(ctx);
8911}
e8eaa2c0
BS
8912
8913static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
8914{
8915 gen_evsel(ctx);
8916}
0487d6a8 8917
a0e13900
FC
8918/* Multiply */
8919
8920static inline void gen_evmwumi(DisasContext *ctx)
8921{
8922 TCGv_i64 t0, t1;
8923
8924 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8925 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8926 return;
8927 }
8928
8929 t0 = tcg_temp_new_i64();
8930 t1 = tcg_temp_new_i64();
8931
8932 /* t0 := rA; t1 := rB */
a0e13900 8933 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
13b6a455 8934 tcg_gen_ext32u_i64(t0, t0);
a0e13900 8935 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
13b6a455 8936 tcg_gen_ext32u_i64(t1, t1);
a0e13900
FC
8937
8938 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8939
8940 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8941
8942 tcg_temp_free_i64(t0);
8943 tcg_temp_free_i64(t1);
8944}
8945
8946static inline void gen_evmwumia(DisasContext *ctx)
8947{
8948 TCGv_i64 tmp;
8949
8950 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8951 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8952 return;
8953 }
8954
8955 gen_evmwumi(ctx); /* rD := rA * rB */
8956
8957 tmp = tcg_temp_new_i64();
8958
8959 /* acc := rD */
8960 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8961 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8962 tcg_temp_free_i64(tmp);
8963}
8964
8965static inline void gen_evmwumiaa(DisasContext *ctx)
8966{
8967 TCGv_i64 acc;
8968 TCGv_i64 tmp;
8969
8970 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8971 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8972 return;
8973 }
8974
8975 gen_evmwumi(ctx); /* rD := rA * rB */
8976
8977 acc = tcg_temp_new_i64();
8978 tmp = tcg_temp_new_i64();
8979
8980 /* tmp := rD */
8981 gen_load_gpr64(tmp, rD(ctx->opcode));
8982
8983 /* Load acc */
1328c2bf 8984 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8985
8986 /* acc := tmp + acc */
8987 tcg_gen_add_i64(acc, acc, tmp);
8988
8989 /* Store acc */
1328c2bf 8990 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8991
8992 /* rD := acc */
8993 gen_store_gpr64(rD(ctx->opcode), acc);
8994
8995 tcg_temp_free_i64(acc);
8996 tcg_temp_free_i64(tmp);
8997}
8998
8999static inline void gen_evmwsmi(DisasContext *ctx)
9000{
9001 TCGv_i64 t0, t1;
9002
9003 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9004 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
9005 return;
9006 }
9007
9008 t0 = tcg_temp_new_i64();
9009 t1 = tcg_temp_new_i64();
9010
9011 /* t0 := rA; t1 := rB */
13b6a455
AG
9012 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
9013 tcg_gen_ext32s_i64(t0, t0);
9014 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
9015 tcg_gen_ext32s_i64(t1, t1);
a0e13900
FC
9016
9017 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
9018
9019 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
9020
9021 tcg_temp_free_i64(t0);
9022 tcg_temp_free_i64(t1);
9023}
9024
9025static inline void gen_evmwsmia(DisasContext *ctx)
9026{
9027 TCGv_i64 tmp;
9028
9029 gen_evmwsmi(ctx); /* rD := rA * rB */
9030
9031 tmp = tcg_temp_new_i64();
9032
9033 /* acc := rD */
9034 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 9035 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9036
9037 tcg_temp_free_i64(tmp);
9038}
9039
9040static inline void gen_evmwsmiaa(DisasContext *ctx)
9041{
9042 TCGv_i64 acc = tcg_temp_new_i64();
9043 TCGv_i64 tmp = tcg_temp_new_i64();
9044
9045 gen_evmwsmi(ctx); /* rD := rA * rB */
9046
9047 acc = tcg_temp_new_i64();
9048 tmp = tcg_temp_new_i64();
9049
9050 /* tmp := rD */
9051 gen_load_gpr64(tmp, rD(ctx->opcode));
9052
9053 /* Load acc */
1328c2bf 9054 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9055
9056 /* acc := tmp + acc */
9057 tcg_gen_add_i64(acc, acc, tmp);
9058
9059 /* Store acc */
1328c2bf 9060 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
9061
9062 /* rD := acc */
9063 gen_store_gpr64(rD(ctx->opcode), acc);
9064
9065 tcg_temp_free_i64(acc);
9066 tcg_temp_free_i64(tmp);
9067}
9068
70560da7
FC
9069GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9070GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9071GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9072GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9073GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9074GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9075GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
9076GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
9077GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
9078GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9079GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9080GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9081GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9082GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9083GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9084GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9085GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
9086GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9087GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9088GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
9089GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
9090GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9091GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
9092GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
9093GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9094GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
9095GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9096GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
9097GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 9098
6a6ae23f 9099/* SPE load and stores */
636aa200 9100static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
9101{
9102 target_ulong uimm = rB(ctx->opcode);
9103
76db3ba4 9104 if (rA(ctx->opcode) == 0) {
6a6ae23f 9105 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 9106 } else {
6a6ae23f 9107 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 9108 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
9109 tcg_gen_ext32u_tl(EA, EA);
9110 }
76db3ba4 9111 }
0487d6a8 9112}
6a6ae23f 9113
636aa200 9114static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f 9115{
6a6ae23f 9116 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 9117 gen_qemu_ld64(ctx, t0, addr);
13b6a455 9118 gen_store_gpr64(rD(ctx->opcode), t0);
6a6ae23f 9119 tcg_temp_free_i64(t0);
0487d6a8 9120}
6a6ae23f 9121
636aa200 9122static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 9123{
76db3ba4
AJ
9124 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9125 gen_addr_add(ctx, addr, addr, 4);
9126 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
0487d6a8 9127}
6a6ae23f 9128
636aa200 9129static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9130{
9131 TCGv t0 = tcg_temp_new();
76db3ba4 9132 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9133 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9134 gen_addr_add(ctx, addr, addr, 2);
9135 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9136 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9137 gen_addr_add(ctx, addr, addr, 2);
9138 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9139 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9140 gen_addr_add(ctx, addr, addr, 2);
9141 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9142 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9143 tcg_temp_free(t0);
0487d6a8
JM
9144}
9145
636aa200 9146static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9147{
9148 TCGv t0 = tcg_temp_new();
76db3ba4 9149 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9150 tcg_gen_shli_tl(t0, t0, 16);
9151 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9152 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9153 tcg_temp_free(t0);
0487d6a8
JM
9154}
9155
636aa200 9156static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9157{
9158 TCGv t0 = tcg_temp_new();
76db3ba4 9159 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9160 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9161 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f 9162 tcg_temp_free(t0);
0487d6a8
JM
9163}
9164
636aa200 9165static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9166{
9167 TCGv t0 = tcg_temp_new();
76db3ba4 9168 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
9169 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9170 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9171 tcg_temp_free(t0);
9172}
9173
636aa200 9174static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9175{
9176 TCGv t0 = tcg_temp_new();
76db3ba4 9177 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9178 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
9179 gen_addr_add(ctx, addr, addr, 2);
9180 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 9181 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
6a6ae23f
AJ
9182 tcg_temp_free(t0);
9183}
9184
636aa200 9185static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f 9186{
76db3ba4
AJ
9187 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9188 gen_addr_add(ctx, addr, addr, 2);
9189 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9190}
9191
636aa200 9192static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f 9193{
76db3ba4
AJ
9194 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
9195 gen_addr_add(ctx, addr, addr, 2);
9196 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
9197}
9198
636aa200 9199static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9200{
9201 TCGv t0 = tcg_temp_new();
76db3ba4 9202 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
9203 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
9204 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9205 tcg_temp_free(t0);
9206}
9207
636aa200 9208static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9209{
9210 TCGv t0 = tcg_temp_new();
76db3ba4 9211 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9212 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
9213 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
9214 gen_addr_add(ctx, addr, addr, 2);
9215 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
9216 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
9217 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
6a6ae23f
AJ
9218 tcg_temp_free(t0);
9219}
9220
636aa200 9221static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f 9222{
6a6ae23f 9223 TCGv_i64 t0 = tcg_temp_new_i64();
13b6a455 9224 gen_load_gpr64(t0, rS(ctx->opcode));
76db3ba4 9225 gen_qemu_st64(ctx, t0, addr);
6a6ae23f 9226 tcg_temp_free_i64(t0);
6a6ae23f
AJ
9227}
9228
636aa200 9229static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 9230{
76db3ba4 9231 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4
AJ
9232 gen_addr_add(ctx, addr, addr, 4);
9233 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9234}
9235
636aa200 9236static inline void gen_op_evstdh(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);
76db3ba4 9242 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4 9243 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9244 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9245 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 9246 tcg_temp_free(t0);
76db3ba4
AJ
9247 gen_addr_add(ctx, addr, addr, 2);
9248 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9249}
9250
636aa200 9251static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
9252{
9253 TCGv t0 = tcg_temp_new();
6a6ae23f 9254 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
76db3ba4
AJ
9255 gen_qemu_st16(ctx, t0, addr);
9256 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 9257 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 9258 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
9259 tcg_temp_free(t0);
9260}
9261
636aa200 9262static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f 9263{
76db3ba4 9264 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
76db3ba4
AJ
9265 gen_addr_add(ctx, addr, addr, 2);
9266 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9267}
9268
636aa200 9269static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f 9270{
76db3ba4 9271 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9272}
9273
636aa200 9274static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 9275{
76db3ba4 9276 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
9277}
9278
9279#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 9280static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
9281{ \
9282 TCGv t0; \
9283 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9284 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
9285 return; \
9286 } \
76db3ba4 9287 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
9288 t0 = tcg_temp_new(); \
9289 if (Rc(ctx->opcode)) { \
76db3ba4 9290 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 9291 } else { \
76db3ba4 9292 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
9293 } \
9294 gen_op_##name(ctx, t0); \
9295 tcg_temp_free(t0); \
9296}
9297
9298GEN_SPEOP_LDST(evldd, 0x00, 3);
9299GEN_SPEOP_LDST(evldw, 0x01, 3);
9300GEN_SPEOP_LDST(evldh, 0x02, 3);
9301GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
9302GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
9303GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
9304GEN_SPEOP_LDST(evlwhe, 0x08, 2);
9305GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
9306GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
9307GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
9308GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
9309
9310GEN_SPEOP_LDST(evstdd, 0x10, 3);
9311GEN_SPEOP_LDST(evstdw, 0x11, 3);
9312GEN_SPEOP_LDST(evstdh, 0x12, 3);
9313GEN_SPEOP_LDST(evstwhe, 0x18, 2);
9314GEN_SPEOP_LDST(evstwho, 0x1A, 2);
9315GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
9316GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
9317
9318/* Multiply and add - TODO */
9319#if 0
70560da7
FC
9320GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
9321GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9322GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9323GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9324GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9325GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9326GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9327GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9328GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9329GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9330GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
9331GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9332
9333GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9334GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9335GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9336GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9337GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9338GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9339GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9340GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
9341GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
9342GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9343GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9344GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9345
9346GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9347GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9348GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9349GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
9350GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
9351
9352GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9353GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9354GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9355GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9356GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9357GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9358GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9359GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9360GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9361GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9362GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
9363GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9364
9365GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9366GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
9367GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9368GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9369
9370GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9371GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9372GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9373GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9374GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9375GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9376GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9377GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9378GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9379GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9380GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
9381GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9382
9383GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9384GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9385GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
9386GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
9387GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
9388#endif
9389
9390/*** SPE floating-point extension ***/
1c97856d 9391#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 9392static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9393{ \
9394 TCGv_i32 t0 = tcg_temp_new_i32(); \
9395 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
13b6a455
AG
9396 gen_helper_##name(t0, cpu_env, t0); \
9397 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
1c97856d 9398 tcg_temp_free_i32(t0); \
57951c27 9399}
1c97856d 9400#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 9401static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9402{ \
9403 TCGv_i64 t0 = tcg_temp_new_i64(); \
13b6a455 9404 TCGv_i32 t1 = tcg_temp_new_i32(); \
1c97856d 9405 gen_load_gpr64(t0, rB(ctx->opcode)); \
13b6a455
AG
9406 gen_helper_##name(t1, cpu_env, t0); \
9407 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); \
1c97856d 9408 tcg_temp_free_i64(t0); \
13b6a455 9409 tcg_temp_free_i32(t1); \
1c97856d
AJ
9410}
9411#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 9412static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9413{ \
9414 TCGv_i64 t0 = tcg_temp_new_i64(); \
13b6a455
AG
9415 TCGv_i32 t1 = tcg_temp_new_i32(); \
9416 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9417 gen_helper_##name(t0, cpu_env, t1); \
1c97856d
AJ
9418 gen_store_gpr64(rD(ctx->opcode), t0); \
9419 tcg_temp_free_i64(t0); \
13b6a455 9420 tcg_temp_free_i32(t1); \
1c97856d
AJ
9421}
9422#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 9423static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9424{ \
9425 TCGv_i64 t0 = tcg_temp_new_i64(); \
9426 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 9427 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
9428 gen_store_gpr64(rD(ctx->opcode), t0); \
9429 tcg_temp_free_i64(t0); \
9430}
9431#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 9432static inline void gen_##name(DisasContext *ctx) \
1c97856d 9433{ \
13b6a455 9434 TCGv_i32 t0, t1; \
1c97856d 9435 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9436 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9437 return; \
9438 } \
13b6a455
AG
9439 t0 = tcg_temp_new_i32(); \
9440 t1 = tcg_temp_new_i32(); \
9441 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9442 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9443 gen_helper_##name(t0, cpu_env, t0, t1); \
9444 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9445 \
9446 tcg_temp_free_i32(t0); \
9447 tcg_temp_free_i32(t1); \
1c97856d
AJ
9448}
9449#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9450static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9451{ \
9452 TCGv_i64 t0, t1; \
9453 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9454 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9455 return; \
9456 } \
9457 t0 = tcg_temp_new_i64(); \
9458 t1 = tcg_temp_new_i64(); \
9459 gen_load_gpr64(t0, rA(ctx->opcode)); \
9460 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9461 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9462 gen_store_gpr64(rD(ctx->opcode), t0); \
9463 tcg_temp_free_i64(t0); \
9464 tcg_temp_free_i64(t1); \
9465}
9466#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9467static inline void gen_##name(DisasContext *ctx) \
1c97856d 9468{ \
13b6a455 9469 TCGv_i32 t0, t1; \
1c97856d 9470 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9471 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9472 return; \
9473 } \
13b6a455
AG
9474 t0 = tcg_temp_new_i32(); \
9475 t1 = tcg_temp_new_i32(); \
9476 \
9477 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9478 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9479 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9480 \
9481 tcg_temp_free_i32(t0); \
9482 tcg_temp_free_i32(t1); \
1c97856d
AJ
9483}
9484#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9485static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9486{ \
9487 TCGv_i64 t0, t1; \
9488 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9489 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9490 return; \
9491 } \
9492 t0 = tcg_temp_new_i64(); \
9493 t1 = tcg_temp_new_i64(); \
9494 gen_load_gpr64(t0, rA(ctx->opcode)); \
9495 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9496 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9497 tcg_temp_free_i64(t0); \
9498 tcg_temp_free_i64(t1); \
9499}
57951c27 9500
0487d6a8
JM
9501/* Single precision floating-point vectors operations */
9502/* Arithmetic */
1c97856d
AJ
9503GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9504GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9505GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9506GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9507static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9508{
9509 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9510 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9511 return;
9512 }
13b6a455
AG
9513 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9514 ~0x80000000);
9515 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9516 ~0x80000000);
1c97856d 9517}
636aa200 9518static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9519{
9520 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9521 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9522 return;
9523 }
13b6a455
AG
9524 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9525 0x80000000);
9526 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9527 0x80000000);
1c97856d 9528}
636aa200 9529static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9530{
9531 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9532 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9533 return;
9534 }
13b6a455
AG
9535 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
9536 0x80000000);
9537 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9538 0x80000000);
1c97856d
AJ
9539}
9540
0487d6a8 9541/* Conversion */
1c97856d
AJ
9542GEN_SPEFPUOP_CONV_64_64(evfscfui);
9543GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9544GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9545GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9546GEN_SPEFPUOP_CONV_64_64(evfsctui);
9547GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9548GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9549GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9550GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9551GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9552
0487d6a8 9553/* Comparison */
1c97856d
AJ
9554GEN_SPEFPUOP_COMP_64(evfscmpgt);
9555GEN_SPEFPUOP_COMP_64(evfscmplt);
9556GEN_SPEFPUOP_COMP_64(evfscmpeq);
9557GEN_SPEFPUOP_COMP_64(evfststgt);
9558GEN_SPEFPUOP_COMP_64(evfststlt);
9559GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9560
9561/* Opcodes definitions */
70560da7
FC
9562GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9563GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9564GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9565GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9566GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9567GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9568GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9569GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9570GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9571GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9572GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9573GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9574GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9575GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9576
9577/* Single precision floating-point operations */
9578/* Arithmetic */
1c97856d
AJ
9579GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9580GEN_SPEFPUOP_ARITH2_32_32(efssub);
9581GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9582GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9583static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9584{
9585 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9586 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9587 return;
9588 }
6d5c34fa 9589 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9590}
636aa200 9591static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9592{
9593 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9594 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9595 return;
9596 }
6d5c34fa 9597 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9598}
636aa200 9599static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9600{
9601 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9602 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9603 return;
9604 }
6d5c34fa 9605 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9606}
9607
0487d6a8 9608/* Conversion */
1c97856d
AJ
9609GEN_SPEFPUOP_CONV_32_32(efscfui);
9610GEN_SPEFPUOP_CONV_32_32(efscfsi);
9611GEN_SPEFPUOP_CONV_32_32(efscfuf);
9612GEN_SPEFPUOP_CONV_32_32(efscfsf);
9613GEN_SPEFPUOP_CONV_32_32(efsctui);
9614GEN_SPEFPUOP_CONV_32_32(efsctsi);
9615GEN_SPEFPUOP_CONV_32_32(efsctuf);
9616GEN_SPEFPUOP_CONV_32_32(efsctsf);
9617GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9618GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9619GEN_SPEFPUOP_CONV_32_64(efscfd);
9620
0487d6a8 9621/* Comparison */
1c97856d
AJ
9622GEN_SPEFPUOP_COMP_32(efscmpgt);
9623GEN_SPEFPUOP_COMP_32(efscmplt);
9624GEN_SPEFPUOP_COMP_32(efscmpeq);
9625GEN_SPEFPUOP_COMP_32(efststgt);
9626GEN_SPEFPUOP_COMP_32(efststlt);
9627GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9628
9629/* Opcodes definitions */
70560da7
FC
9630GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9631GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9632GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9633GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9634GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9635GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9636GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9637GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9638GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9639GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9640GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9641GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9642GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9643GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9644
9645/* Double precision floating-point operations */
9646/* Arithmetic */
1c97856d
AJ
9647GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9648GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9649GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9650GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9651static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9652{
9653 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9654 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9655 return;
9656 }
6d5c34fa 9657 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9658 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9659 ~0x80000000);
1c97856d 9660}
636aa200 9661static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
9662{
9663 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9664 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9665 return;
9666 }
6d5c34fa 9667 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9668 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9669 0x80000000);
1c97856d 9670}
636aa200 9671static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
9672{
9673 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9674 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9675 return;
9676 }
6d5c34fa 9677 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
13b6a455
AG
9678 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],
9679 0x80000000);
1c97856d
AJ
9680}
9681
0487d6a8 9682/* Conversion */
1c97856d
AJ
9683GEN_SPEFPUOP_CONV_64_32(efdcfui);
9684GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9685GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9686GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9687GEN_SPEFPUOP_CONV_32_64(efdctui);
9688GEN_SPEFPUOP_CONV_32_64(efdctsi);
9689GEN_SPEFPUOP_CONV_32_64(efdctuf);
9690GEN_SPEFPUOP_CONV_32_64(efdctsf);
9691GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9692GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9693GEN_SPEFPUOP_CONV_64_32(efdcfs);
9694GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9695GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9696GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9697GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 9698
0487d6a8 9699/* Comparison */
1c97856d
AJ
9700GEN_SPEFPUOP_COMP_64(efdcmpgt);
9701GEN_SPEFPUOP_COMP_64(efdcmplt);
9702GEN_SPEFPUOP_COMP_64(efdcmpeq);
9703GEN_SPEFPUOP_COMP_64(efdtstgt);
9704GEN_SPEFPUOP_COMP_64(efdtstlt);
9705GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
9706
9707/* Opcodes definitions */
70560da7
FC
9708GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9709GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9710GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9711GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9712GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9713GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9714GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9715GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9716GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9717GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9718GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9719GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9720GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9721GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9722GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9723GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 9724
0ff93d11
TM
9725static void gen_tbegin(DisasContext *ctx)
9726{
9727 if (unlikely(!ctx->tm_enabled)) {
9728 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM);
9729 return;
9730 }
9731 gen_helper_tbegin(cpu_env);
9732}
9733
56a84615
TM
9734#define GEN_TM_NOOP(name) \
9735static inline void gen_##name(DisasContext *ctx) \
9736{ \
9737 if (unlikely(!ctx->tm_enabled)) { \
9738 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9739 return; \
9740 } \
9741 /* Because tbegin always fails in QEMU, these user \
9742 * space instructions all have a simple implementation: \
9743 * \
9744 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9745 * = 0b0 || 0b00 || 0b0 \
9746 */ \
9747 tcg_gen_movi_i32(cpu_crf[0], 0); \
9748}
9749
9750GEN_TM_NOOP(tend);
9751GEN_TM_NOOP(tabort);
9752GEN_TM_NOOP(tabortwc);
9753GEN_TM_NOOP(tabortwci);
9754GEN_TM_NOOP(tabortdc);
9755GEN_TM_NOOP(tabortdci);
9756GEN_TM_NOOP(tsr);
9757
aeedd582
TM
9758static void gen_tcheck(DisasContext *ctx)
9759{
9760 if (unlikely(!ctx->tm_enabled)) {
9761 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM);
9762 return;
9763 }
9764 /* Because tbegin always fails, the tcheck implementation
9765 * is simple:
9766 *
9767 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
9768 * = 0b1 || 0b00 || 0b0
9769 */
9770 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0x8);
9771}
9772
f83c2378
TM
9773#if defined(CONFIG_USER_ONLY)
9774#define GEN_TM_PRIV_NOOP(name) \
9775static inline void gen_##name(DisasContext *ctx) \
9776{ \
9777 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9778}
9779
9780#else
9781
9782#define GEN_TM_PRIV_NOOP(name) \
9783static inline void gen_##name(DisasContext *ctx) \
9784{ \
9785 if (unlikely(ctx->pr)) { \
9786 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9787 return; \
9788 } \
9789 if (unlikely(!ctx->tm_enabled)) { \
9790 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9791 return; \
9792 } \
9793 /* Because tbegin always fails, the implementation is \
9794 * simple: \
9795 * \
9796 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9797 * = 0b0 || 0b00 | 0b0 \
9798 */ \
9799 tcg_gen_movi_i32(cpu_crf[0], 0); \
9800}
9801
9802#endif
9803
9804GEN_TM_PRIV_NOOP(treclaim);
9805GEN_TM_PRIV_NOOP(trechkpt);
9806
c227f099 9807static opcode_t opcodes[] = {
5c55ff99
BS
9808GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9809GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9810GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9811GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9812GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 9813GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9814GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9815GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9816GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9817GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9818GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9819GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9820GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9821GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9822GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9823GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9824#if defined(TARGET_PPC64)
9825GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9826#endif
9827GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9828GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9829GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9830GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9831GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9832GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9833GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9834GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9835GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9836GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9837GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9838GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
6ab39b1b 9839GEN_HANDLER(popcntb, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 9840GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 9841GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 9842#if defined(TARGET_PPC64)
eaabeef2 9843GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 9844GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 9845GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
86ba37ed 9846GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206),
5c55ff99
BS
9847#endif
9848GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9849GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9850GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9851GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9852GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9853GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9854GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9855#if defined(TARGET_PPC64)
9856GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9857GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9858GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9859GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9860GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9861#endif
9862GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9863GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9864GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9865GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9866GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 9867GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 9868GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
9869GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9870GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 9871GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
097ec5d8
TM
9872GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207),
9873GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207),
5c55ff99
BS
9874GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9875GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9876GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9877GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
9878GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9879GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
9880#if defined(TARGET_PPC64)
9881GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9882GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9883GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9884#endif
9885GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9886GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9887GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9888GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9889GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9890GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9891GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9892GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
5c77a786
TM
9893GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9894GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
f844c817 9895GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
587c51f7
TM
9896GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
9897GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206),
5c55ff99
BS
9898GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9899#if defined(TARGET_PPC64)
f844c817 9900GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
9c294d5a 9901GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99 9902GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
27b95bfe 9903GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207),
5c55ff99
BS
9904#endif
9905GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9906GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9907GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9908GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9909GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9910GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
52a4984d 9911GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0, PPC_NONE, PPC2_BCTAR_ISA207),
5c55ff99
BS
9912GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9913GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9914#if defined(TARGET_PPC64)
9915GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9916GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9917#endif
9918GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9919GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9920GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9921#if defined(TARGET_PPC64)
9922GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9923GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9924#endif
9925GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9926GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9927GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9928GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9929GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9930GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9931#if defined(TARGET_PPC64)
9932GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9933#endif
9934GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
4248b336 9935GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC),
5c55ff99
BS
9936GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9937GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9938GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
3f34cf91
CLG
9939GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE),
9940GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE),
4d09d529 9941GEN_HANDLER_E(dcbtls, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE, PPC2_BOOKE206),
8e33944f 9942GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
9943GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9944GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9945GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9946GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9947GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9948GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9949GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9950GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9951GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9952#if defined(TARGET_PPC64)
9953GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9954GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9955 PPC_SEGMENT_64B),
9956GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
9957GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9958 PPC_SEGMENT_64B),
efdef95f
DG
9959GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
9960GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
9961GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
9962#endif
9963GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
f9ef0527
BH
9964/* XXX Those instructions will need to be handled differently for
9965 * different ISA versions */
9966GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE),
9967GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE),
5c55ff99
BS
9968GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
9969#if defined(TARGET_PPC64)
9970GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
9971GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
9972#endif
9973GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
9974GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
9975GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
9976GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
9977GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
9978GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
9979GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
9980GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
9981GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
9982GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
9983GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
9984GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9985GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
9986GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
9987GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
9988GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
9989GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
9990GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
9991GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
9992GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9993GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
9994GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
9995GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
9996GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
9997GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
9998GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
9999GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
10000GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
10001GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
10002GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
10003GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
10004GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
10005GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
10006GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
10007GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
10008GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
10009GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
10010GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
10011GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
10012GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
10013GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
10014GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
10015GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
10016GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
10017GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
10018GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
10019GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
10020GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
10021GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
10022GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10023GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10024GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
10025GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
10026GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10027GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
10028GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
10029GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
10030GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
10031GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
10032GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
10033GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
10034GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
10035GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
10036GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
10037GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
10038GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
10039GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
10040GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
10041GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
10042GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
10043GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 10044GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10045GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
10046GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
10047GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
10048GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
10049GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
10050GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
10051GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
10052GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
10053GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10054 PPC_NONE, PPC2_BOOKE206),
10055GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10056 PPC_NONE, PPC2_BOOKE206),
10057GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10058 PPC_NONE, PPC2_BOOKE206),
10059GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10060 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
10061GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10062 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
10063GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10064 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
10065GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10066 PPC_NONE, PPC2_PRCNTL),
5c55ff99 10067GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 10068GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 10069GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
10070GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
10071 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 10072GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
10073GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10074 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
10075GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
10076GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
10077GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
10078GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
5c55ff99
BS
10079GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
10080GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
10081GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
10082GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
10083GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
10084
10085#undef GEN_INT_ARITH_ADD
10086#undef GEN_INT_ARITH_ADD_CONST
10087#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10088GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10089#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10090 add_ca, compute_ca, compute_ov) \
10091GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10092GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
10093GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
10094GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
10095GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
10096GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
10097GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
10098GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
10099GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
10100GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
10101GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
10102
10103#undef GEN_INT_ARITH_DIVW
10104#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10105GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10106GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
10107GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
10108GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
10109GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
a98eb9e9
TM
10110GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10111GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
6a4fda33
TM
10112GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10113GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
5c55ff99
BS
10114
10115#if defined(TARGET_PPC64)
10116#undef GEN_INT_ARITH_DIVD
10117#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10118GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10119GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
10120GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
10121GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
10122GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
10123
98d1eb27
TM
10124GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206),
10125GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206),
e44259b6
TM
10126GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206),
10127GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206),
98d1eb27 10128
5c55ff99
BS
10129#undef GEN_INT_ARITH_MUL_HELPER
10130#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10131GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10132GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
10133GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
10134GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
10135#endif
10136
10137#undef GEN_INT_ARITH_SUBF
10138#undef GEN_INT_ARITH_SUBF_CONST
10139#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10140GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10141#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10142 add_ca, compute_ca, compute_ov) \
10143GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10144GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
10145GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
10146GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
10147GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
10148GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
10149GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
10150GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
10151GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
10152GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
10153GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
10154
10155#undef GEN_LOGICAL1
10156#undef GEN_LOGICAL2
10157#define GEN_LOGICAL2(name, tcg_op, opc, type) \
10158GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10159#define GEN_LOGICAL1(name, tcg_op, opc, type) \
10160GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10161GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
10162GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
10163GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
10164GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
10165GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
10166GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
10167GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
10168GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
10169#if defined(TARGET_PPC64)
10170GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
10171#endif
10172
10173#if defined(TARGET_PPC64)
10174#undef GEN_PPC64_R2
10175#undef GEN_PPC64_R4
10176#define GEN_PPC64_R2(name, opc1, opc2) \
10177GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10178GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10179 PPC_64B)
10180#define GEN_PPC64_R4(name, opc1, opc2) \
10181GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10182GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10183 PPC_64B), \
10184GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10185 PPC_64B), \
10186GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10187 PPC_64B)
10188GEN_PPC64_R4(rldicl, 0x1E, 0x00),
10189GEN_PPC64_R4(rldicr, 0x1E, 0x02),
10190GEN_PPC64_R4(rldic, 0x1E, 0x04),
10191GEN_PPC64_R2(rldcl, 0x1E, 0x08),
10192GEN_PPC64_R2(rldcr, 0x1E, 0x09),
10193GEN_PPC64_R4(rldimi, 0x1E, 0x06),
10194#endif
10195
10196#undef _GEN_FLOAT_ACB
10197#undef GEN_FLOAT_ACB
10198#undef _GEN_FLOAT_AB
10199#undef GEN_FLOAT_AB
10200#undef _GEN_FLOAT_AC
10201#undef GEN_FLOAT_AC
10202#undef GEN_FLOAT_B
10203#undef GEN_FLOAT_BS
10204#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10205GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10206#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10207_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10208_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10209#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10210GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10211#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10212_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10213_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10214#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10215GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10216#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10217_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10218_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10219#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10220GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10221#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10222GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10223
10224GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
10225GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
10226GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
10227GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
10228GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
10229GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
10230_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
10231GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
10232GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
10233GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
10234GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
10235GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
da29cb7b 10236GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206),
6d41d146 10237GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206),
5c55ff99 10238GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
fab7fe42 10239GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10240GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
fab7fe42 10241GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99 10242GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
4171853c 10243GEN_HANDLER_E(fcfid, 0x3F, 0x0E, 0x1A, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
28288b48
TM
10244GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10245GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
10246GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
4171853c 10247GEN_HANDLER_E(fctid, 0x3F, 0x0E, 0x19, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
fab7fe42 10248GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
4171853c 10249GEN_HANDLER_E(fctidz, 0x3F, 0x0F, 0x19, 0x001F0000, PPC_NONE, PPC2_FP_CVT_S64),
fab7fe42 10250GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206),
5c55ff99
BS
10251GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
10252GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
10253GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
10254GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
10255
10256#undef GEN_LD
10257#undef GEN_LDU
10258#undef GEN_LDUX
cd6e9320 10259#undef GEN_LDX_E
5c55ff99
BS
10260#undef GEN_LDS
10261#define GEN_LD(name, ldop, opc, type) \
10262GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10263#define GEN_LDU(name, ldop, opc, type) \
10264GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10265#define GEN_LDUX(name, ldop, opc2, opc3, type) \
10266GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10267#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10268GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10269#define GEN_LDS(name, ldop, op, type) \
10270GEN_LD(name, ldop, op | 0x20, type) \
10271GEN_LDU(name, ldop, op | 0x21, type) \
10272GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10273GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10274
10275GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
10276GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
10277GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
10278GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
10279#if defined(TARGET_PPC64)
10280GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
10281GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
10282GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
10283GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 10284GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10285#endif
10286GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
10287GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
10288
10289#undef GEN_ST
10290#undef GEN_STU
10291#undef GEN_STUX
cd6e9320 10292#undef GEN_STX_E
5c55ff99
BS
10293#undef GEN_STS
10294#define GEN_ST(name, stop, opc, type) \
10295GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10296#define GEN_STU(name, stop, opc, type) \
10297GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10298#define GEN_STUX(name, stop, opc2, opc3, type) \
10299GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
10300#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10301GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
10302#define GEN_STS(name, stop, op, type) \
10303GEN_ST(name, stop, op | 0x20, type) \
10304GEN_STU(name, stop, op | 0x21, type) \
10305GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10306GEN_STX(name, stop, 0x17, op | 0x00, type)
10307
10308GEN_STS(stb, st8, 0x06, PPC_INTEGER)
10309GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
10310GEN_STS(stw, st32, 0x04, PPC_INTEGER)
10311#if defined(TARGET_PPC64)
10312GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
10313GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 10314GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
10315#endif
10316GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
10317GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
10318
10319#undef GEN_LDF
10320#undef GEN_LDUF
10321#undef GEN_LDUXF
10322#undef GEN_LDXF
10323#undef GEN_LDFS
10324#define GEN_LDF(name, ldop, opc, type) \
10325GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10326#define GEN_LDUF(name, ldop, opc, type) \
10327GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10328#define GEN_LDUXF(name, ldop, opc, type) \
10329GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10330#define GEN_LDXF(name, ldop, opc2, opc3, type) \
10331GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10332#define GEN_LDFS(name, ldop, op, type) \
10333GEN_LDF(name, ldop, op | 0x20, type) \
10334GEN_LDUF(name, ldop, op | 0x21, type) \
10335GEN_LDUXF(name, ldop, op | 0x01, type) \
10336GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10337
10338GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
10339GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 10340GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
66c3e328 10341GEN_HANDLER_E(lfiwzx, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE, PPC2_FP_CVT_ISA206),
05050ee8
AJ
10342GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10343GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10344
10345#undef GEN_STF
10346#undef GEN_STUF
10347#undef GEN_STUXF
10348#undef GEN_STXF
10349#undef GEN_STFS
10350#define GEN_STF(name, stop, opc, type) \
10351GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10352#define GEN_STUF(name, stop, opc, type) \
10353GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10354#define GEN_STUXF(name, stop, opc, type) \
10355GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10356#define GEN_STXF(name, stop, opc2, opc3, type) \
10357GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10358#define GEN_STFS(name, stop, op, type) \
10359GEN_STF(name, stop, op | 0x20, type) \
10360GEN_STUF(name, stop, op | 0x21, type) \
10361GEN_STUXF(name, stop, op | 0x01, type) \
10362GEN_STXF(name, stop, 0x17, op | 0x00, type)
10363
10364GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
10365GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
10366GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
10367GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
10368GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
10369
10370#undef GEN_CRLOGIC
10371#define GEN_CRLOGIC(name, tcg_op, opc) \
10372GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10373GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
10374GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
10375GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
10376GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
10377GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
10378GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
10379GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
10380GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
10381
10382#undef GEN_MAC_HANDLER
10383#define GEN_MAC_HANDLER(name, opc2, opc3) \
10384GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10385GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
10386GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
10387GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
10388GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
10389GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
10390GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
10391GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
10392GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
10393GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
10394GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
10395GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
10396GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
10397GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
10398GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
10399GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
10400GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
10401GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
10402GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
10403GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
10404GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
10405GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
10406GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
10407GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
10408GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
10409GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
10410GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
10411GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
10412GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
10413GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
10414GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
10415GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
10416GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
10417GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
10418GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
10419GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
10420GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
10421GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
10422GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
10423GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
10424GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
10425GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
10426GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
10427
10428#undef GEN_VR_LDX
10429#undef GEN_VR_STX
10430#undef GEN_VR_LVE
10431#undef GEN_VR_STVE
10432#define GEN_VR_LDX(name, opc2, opc3) \
10433GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10434#define GEN_VR_STX(name, opc2, opc3) \
10435GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10436#define GEN_VR_LVE(name, opc2, opc3) \
10437 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10438#define GEN_VR_STVE(name, opc2, opc3) \
10439 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10440GEN_VR_LDX(lvx, 0x07, 0x03),
10441GEN_VR_LDX(lvxl, 0x07, 0x0B),
10442GEN_VR_LVE(bx, 0x07, 0x00),
10443GEN_VR_LVE(hx, 0x07, 0x01),
10444GEN_VR_LVE(wx, 0x07, 0x02),
10445GEN_VR_STX(svx, 0x07, 0x07),
10446GEN_VR_STX(svxl, 0x07, 0x0F),
10447GEN_VR_STVE(bx, 0x07, 0x04),
10448GEN_VR_STVE(hx, 0x07, 0x05),
10449GEN_VR_STVE(wx, 0x07, 0x06),
10450
10451#undef GEN_VX_LOGICAL
10452#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10453GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
111c5f54
TM
10454
10455#undef GEN_VX_LOGICAL_207
10456#define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10457GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10458
5c55ff99
BS
10459GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
10460GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
10461GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
10462GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
10463GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
111c5f54
TM
10464GEN_VX_LOGICAL_207(veqv, tcg_gen_eqv_i64, 2, 26),
10465GEN_VX_LOGICAL_207(vnand, tcg_gen_nand_i64, 2, 22),
10466GEN_VX_LOGICAL_207(vorc, tcg_gen_orc_i64, 2, 21),
5c55ff99
BS
10467
10468#undef GEN_VXFORM
10469#define GEN_VXFORM(name, opc2, opc3) \
10470GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
50f5fc0c
TM
10471
10472#undef GEN_VXFORM_207
10473#define GEN_VXFORM_207(name, opc2, opc3) \
10474GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10475
5dffff5a
TM
10476#undef GEN_VXFORM_DUAL
10477#define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10478GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10479
a737d3eb
TM
10480#undef GEN_VXRFORM_DUAL
10481#define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10482GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10483GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10484
5c55ff99
BS
10485GEN_VXFORM(vaddubm, 0, 0),
10486GEN_VXFORM(vadduhm, 0, 1),
10487GEN_VXFORM(vadduwm, 0, 2),
56eabc75 10488GEN_VXFORM_207(vaddudm, 0, 3),
e8f7b27b
TM
10489GEN_VXFORM_DUAL(vsububm, bcdadd, 0, 16, PPC_ALTIVEC, PPC_NONE),
10490GEN_VXFORM_DUAL(vsubuhm, bcdsub, 0, 17, PPC_ALTIVEC, PPC_NONE),
5c55ff99 10491GEN_VXFORM(vsubuwm, 0, 18),
56eabc75 10492GEN_VXFORM_207(vsubudm, 0, 19),
5c55ff99
BS
10493GEN_VXFORM(vmaxub, 1, 0),
10494GEN_VXFORM(vmaxuh, 1, 1),
10495GEN_VXFORM(vmaxuw, 1, 2),
8203e31b 10496GEN_VXFORM_207(vmaxud, 1, 3),
5c55ff99
BS
10497GEN_VXFORM(vmaxsb, 1, 4),
10498GEN_VXFORM(vmaxsh, 1, 5),
10499GEN_VXFORM(vmaxsw, 1, 6),
8203e31b 10500GEN_VXFORM_207(vmaxsd, 1, 7),
5c55ff99
BS
10501GEN_VXFORM(vminub, 1, 8),
10502GEN_VXFORM(vminuh, 1, 9),
10503GEN_VXFORM(vminuw, 1, 10),
8203e31b 10504GEN_VXFORM_207(vminud, 1, 11),
5c55ff99
BS
10505GEN_VXFORM(vminsb, 1, 12),
10506GEN_VXFORM(vminsh, 1, 13),
10507GEN_VXFORM(vminsw, 1, 14),
8203e31b 10508GEN_VXFORM_207(vminsd, 1, 15),
5c55ff99
BS
10509GEN_VXFORM(vavgub, 1, 16),
10510GEN_VXFORM(vavguh, 1, 17),
10511GEN_VXFORM(vavguw, 1, 18),
10512GEN_VXFORM(vavgsb, 1, 20),
10513GEN_VXFORM(vavgsh, 1, 21),
10514GEN_VXFORM(vavgsw, 1, 22),
10515GEN_VXFORM(vmrghb, 6, 0),
10516GEN_VXFORM(vmrghh, 6, 1),
10517GEN_VXFORM(vmrghw, 6, 2),
10518GEN_VXFORM(vmrglb, 6, 4),
10519GEN_VXFORM(vmrglh, 6, 5),
10520GEN_VXFORM(vmrglw, 6, 6),
e0ffe77f
TM
10521GEN_VXFORM_207(vmrgew, 6, 30),
10522GEN_VXFORM_207(vmrgow, 6, 26),
5c55ff99
BS
10523GEN_VXFORM(vmuloub, 4, 0),
10524GEN_VXFORM(vmulouh, 4, 1),
953f0f58 10525GEN_VXFORM_DUAL(vmulouw, vmuluwm, 4, 2, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10526GEN_VXFORM(vmulosb, 4, 4),
10527GEN_VXFORM(vmulosh, 4, 5),
63be0936 10528GEN_VXFORM_207(vmulosw, 4, 6),
5c55ff99
BS
10529GEN_VXFORM(vmuleub, 4, 8),
10530GEN_VXFORM(vmuleuh, 4, 9),
63be0936 10531GEN_VXFORM_207(vmuleuw, 4, 10),
5c55ff99
BS
10532GEN_VXFORM(vmulesb, 4, 12),
10533GEN_VXFORM(vmulesh, 4, 13),
63be0936 10534GEN_VXFORM_207(vmulesw, 4, 14),
5c55ff99
BS
10535GEN_VXFORM(vslb, 2, 4),
10536GEN_VXFORM(vslh, 2, 5),
10537GEN_VXFORM(vslw, 2, 6),
2fdf78e6 10538GEN_VXFORM_207(vsld, 2, 23),
5c55ff99
BS
10539GEN_VXFORM(vsrb, 2, 8),
10540GEN_VXFORM(vsrh, 2, 9),
10541GEN_VXFORM(vsrw, 2, 10),
2fdf78e6 10542GEN_VXFORM_207(vsrd, 2, 27),
5c55ff99
BS
10543GEN_VXFORM(vsrab, 2, 12),
10544GEN_VXFORM(vsrah, 2, 13),
10545GEN_VXFORM(vsraw, 2, 14),
2fdf78e6 10546GEN_VXFORM_207(vsrad, 2, 15),
5c55ff99
BS
10547GEN_VXFORM(vslo, 6, 16),
10548GEN_VXFORM(vsro, 6, 17),
10549GEN_VXFORM(vaddcuw, 0, 6),
10550GEN_VXFORM(vsubcuw, 0, 22),
10551GEN_VXFORM(vaddubs, 0, 8),
10552GEN_VXFORM(vadduhs, 0, 9),
10553GEN_VXFORM(vadduws, 0, 10),
10554GEN_VXFORM(vaddsbs, 0, 12),
10555GEN_VXFORM(vaddshs, 0, 13),
10556GEN_VXFORM(vaddsws, 0, 14),
e8f7b27b
TM
10557GEN_VXFORM_DUAL(vsububs, bcdadd, 0, 24, PPC_ALTIVEC, PPC_NONE),
10558GEN_VXFORM_DUAL(vsubuhs, bcdsub, 0, 25, PPC_ALTIVEC, PPC_NONE),
5c55ff99
BS
10559GEN_VXFORM(vsubuws, 0, 26),
10560GEN_VXFORM(vsubsbs, 0, 28),
10561GEN_VXFORM(vsubshs, 0, 29),
10562GEN_VXFORM(vsubsws, 0, 30),
b41da4eb
TM
10563GEN_VXFORM_207(vadduqm, 0, 4),
10564GEN_VXFORM_207(vaddcuq, 0, 5),
10565GEN_VXFORM_DUAL(vaddeuqm, vaddecuq, 30, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
10566GEN_VXFORM_207(vsubuqm, 0, 20),
10567GEN_VXFORM_207(vsubcuq, 0, 21),
10568GEN_VXFORM_DUAL(vsubeuqm, vsubecuq, 31, 0xFF, PPC_NONE, PPC2_ALTIVEC_207),
5c55ff99
BS
10569GEN_VXFORM(vrlb, 2, 0),
10570GEN_VXFORM(vrlh, 2, 1),
10571GEN_VXFORM(vrlw, 2, 2),
2fdf78e6 10572GEN_VXFORM_207(vrld, 2, 3),
5c55ff99
BS
10573GEN_VXFORM(vsl, 2, 7),
10574GEN_VXFORM(vsr, 2, 11),
10575GEN_VXFORM(vpkuhum, 7, 0),
10576GEN_VXFORM(vpkuwum, 7, 1),
024215b2 10577GEN_VXFORM_207(vpkudum, 7, 17),
5c55ff99
BS
10578GEN_VXFORM(vpkuhus, 7, 2),
10579GEN_VXFORM(vpkuwus, 7, 3),
024215b2 10580GEN_VXFORM_207(vpkudus, 7, 19),
5c55ff99
BS
10581GEN_VXFORM(vpkshus, 7, 4),
10582GEN_VXFORM(vpkswus, 7, 5),
024215b2 10583GEN_VXFORM_207(vpksdus, 7, 21),
5c55ff99
BS
10584GEN_VXFORM(vpkshss, 7, 6),
10585GEN_VXFORM(vpkswss, 7, 7),
024215b2 10586GEN_VXFORM_207(vpksdss, 7, 23),
5c55ff99
BS
10587GEN_VXFORM(vpkpx, 7, 12),
10588GEN_VXFORM(vsum4ubs, 4, 24),
10589GEN_VXFORM(vsum4sbs, 4, 28),
10590GEN_VXFORM(vsum4shs, 4, 25),
10591GEN_VXFORM(vsum2sws, 4, 26),
10592GEN_VXFORM(vsumsws, 4, 30),
10593GEN_VXFORM(vaddfp, 5, 0),
10594GEN_VXFORM(vsubfp, 5, 1),
10595GEN_VXFORM(vmaxfp, 5, 16),
10596GEN_VXFORM(vminfp, 5, 17),
10597
10598#undef GEN_VXRFORM1
10599#undef GEN_VXRFORM
10600#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10601 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10602#define GEN_VXRFORM(name, opc2, opc3) \
10603 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10604 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10605GEN_VXRFORM(vcmpequb, 3, 0)
10606GEN_VXRFORM(vcmpequh, 3, 1)
10607GEN_VXRFORM(vcmpequw, 3, 2)
10608GEN_VXRFORM(vcmpgtsb, 3, 12)
10609GEN_VXRFORM(vcmpgtsh, 3, 13)
10610GEN_VXRFORM(vcmpgtsw, 3, 14)
10611GEN_VXRFORM(vcmpgtub, 3, 8)
10612GEN_VXRFORM(vcmpgtuh, 3, 9)
10613GEN_VXRFORM(vcmpgtuw, 3, 10)
6f3dab41 10614GEN_VXRFORM_DUAL(vcmpeqfp, vcmpequd, 3, 3, PPC_ALTIVEC, PPC_NONE)
5c55ff99 10615GEN_VXRFORM(vcmpgefp, 3, 7)
6f3dab41
TM
10616GEN_VXRFORM_DUAL(vcmpgtfp, vcmpgtud, 3, 11, PPC_ALTIVEC, PPC_NONE)
10617GEN_VXRFORM_DUAL(vcmpbfp, vcmpgtsd, 3, 15, PPC_ALTIVEC, PPC_NONE)
5c55ff99
BS
10618
10619#undef GEN_VXFORM_SIMM
10620#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10621 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10622GEN_VXFORM_SIMM(vspltisb, 6, 12),
10623GEN_VXFORM_SIMM(vspltish, 6, 13),
10624GEN_VXFORM_SIMM(vspltisw, 6, 14),
10625
10626#undef GEN_VXFORM_NOA
10627#define GEN_VXFORM_NOA(name, opc2, opc3) \
10628 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10629GEN_VXFORM_NOA(vupkhsb, 7, 8),
10630GEN_VXFORM_NOA(vupkhsh, 7, 9),
4430e076 10631GEN_VXFORM_207(vupkhsw, 7, 25),
5c55ff99
BS
10632GEN_VXFORM_NOA(vupklsb, 7, 10),
10633GEN_VXFORM_NOA(vupklsh, 7, 11),
4430e076 10634GEN_VXFORM_207(vupklsw, 7, 27),
5c55ff99
BS
10635GEN_VXFORM_NOA(vupkhpx, 7, 13),
10636GEN_VXFORM_NOA(vupklpx, 7, 15),
10637GEN_VXFORM_NOA(vrefp, 5, 4),
10638GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10639GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99 10640GEN_VXFORM_NOA(vlogefp, 5, 7),
abe60a43
TM
10641GEN_VXFORM_NOA(vrfim, 5, 11),
10642GEN_VXFORM_NOA(vrfin, 5, 8),
5c55ff99 10643GEN_VXFORM_NOA(vrfip, 5, 10),
abe60a43 10644GEN_VXFORM_NOA(vrfiz, 5, 9),
5c55ff99
BS
10645
10646#undef GEN_VXFORM_UIMM
10647#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10648 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10649GEN_VXFORM_UIMM(vspltb, 6, 8),
10650GEN_VXFORM_UIMM(vsplth, 6, 9),
10651GEN_VXFORM_UIMM(vspltw, 6, 10),
10652GEN_VXFORM_UIMM(vcfux, 5, 12),
10653GEN_VXFORM_UIMM(vcfsx, 5, 13),
10654GEN_VXFORM_UIMM(vctuxs, 5, 14),
10655GEN_VXFORM_UIMM(vctsxs, 5, 15),
10656
10657#undef GEN_VAFORM_PAIRED
10658#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10659 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10660GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10661GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10662GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10663GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10664GEN_VAFORM_PAIRED(vsel, vperm, 21),
10665GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10666
e13500b3
TM
10667GEN_VXFORM_DUAL(vclzb, vpopcntb, 1, 28, PPC_NONE, PPC2_ALTIVEC_207),
10668GEN_VXFORM_DUAL(vclzh, vpopcnth, 1, 29, PPC_NONE, PPC2_ALTIVEC_207),
10669GEN_VXFORM_DUAL(vclzw, vpopcntw, 1, 30, PPC_NONE, PPC2_ALTIVEC_207),
10670GEN_VXFORM_DUAL(vclzd, vpopcntd, 1, 31, PPC_NONE, PPC2_ALTIVEC_207),
10671
4d82038e 10672GEN_VXFORM_207(vbpermq, 6, 21),
f1064f61 10673GEN_VXFORM_207(vgbbd, 6, 20),
b8476fc7
TM
10674GEN_VXFORM_207(vpmsumb, 4, 16),
10675GEN_VXFORM_207(vpmsumh, 4, 17),
10676GEN_VXFORM_207(vpmsumw, 4, 18),
10677GEN_VXFORM_207(vpmsumd, 4, 19),
f293f04a 10678
557d52fa
TM
10679GEN_VXFORM_207(vsbox, 4, 23),
10680
10681GEN_VXFORM_DUAL(vcipher, vcipherlast, 4, 20, PPC_NONE, PPC2_ALTIVEC_207),
10682GEN_VXFORM_DUAL(vncipher, vncipherlast, 4, 21, PPC_NONE, PPC2_ALTIVEC_207),
10683
57354f8f
TM
10684GEN_VXFORM_207(vshasigmaw, 1, 26),
10685GEN_VXFORM_207(vshasigmad, 1, 27),
10686
ac174549
TM
10687GEN_VXFORM_DUAL(vsldoi, vpermxor, 22, 0xFF, PPC_ALTIVEC, PPC_NONE),
10688
fa1832d7 10689GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10690GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10691GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10692GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10693GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10694GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10695GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10696
9231ba9e 10697GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10698GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10699GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10700GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10701GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10702
f5c0f7f9
TM
10703GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207),
10704GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207),
10705GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207),
10706#if defined(TARGET_PPC64)
10707GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207),
10708GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207),
10709#endif
10710
df020ce0
TM
10711#undef GEN_XX2FORM
10712#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10713GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10714GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10715
10716#undef GEN_XX3FORM
10717#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10718GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10719GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10720GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10721GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10722
8f60f8e2
AJ
10723#undef GEN_XX2IFORM
10724#define GEN_XX2IFORM(name, opc2, opc3, fl2) \
10725GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 1, PPC_NONE, fl2), \
10726GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 1, PPC_NONE, fl2), \
10727GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 1, PPC_NONE, fl2), \
10728GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 1, PPC_NONE, fl2)
10729
354a6dec
TM
10730#undef GEN_XX3_RC_FORM
10731#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10732GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10733GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10734GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10735GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10736GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10737GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10738GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10739GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10740
cd73f2c9
TM
10741#undef GEN_XX3FORM_DM
10742#define GEN_XX3FORM_DM(name, opc2, opc3) \
10743GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10744GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10745GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10746GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10747GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10748GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10749GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10750GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10751GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10752GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10753GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10754GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10755GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10756GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10757GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10758GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10759
df020ce0
TM
10760GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10761GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10762GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10763GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10764
be574920
TM
10765GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10766GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10767GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10768GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10769GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10770GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10771GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10772GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 10773
ee6e02c0
TM
10774GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10775GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 10776GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 10777GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 10778GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 10779GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 10780GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 10781GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 10782GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
10783GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10784GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10785GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10786GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10787GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10788GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10789GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10790GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
8f60f8e2
AJ
10791GEN_XX2IFORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10792GEN_XX2IFORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
10793GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10794GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568 10795GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
7ee19fb9 10796GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207),
ed8ac568 10797GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
7ee19fb9 10798GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207),
5177d2ca
TM
10799GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10800GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10801GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10802GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10803GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10804GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
10805GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10806GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10807GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10808GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10809GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 10810
3fd0aadf
TM
10811GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10812GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 10813GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 10814GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 10815GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
3d1140bf 10816GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207),
cea4e574 10817GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
968e76bc 10818GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207),
f53f81e0
TM
10819GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207),
10820GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207),
10821GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207),
10822GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207),
10823GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207),
10824GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207),
10825GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207),
10826GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207),
74698350
TM
10827GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207),
10828GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207),
3fd0aadf 10829
ee6e02c0
TM
10830GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10831GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 10832GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 10833GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 10834GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 10835GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 10836GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 10837GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 10838GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
10839GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10840GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10841GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10842GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10843GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10844GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10845GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10846GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
10847GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10848GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
10849GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10850GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10851GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 10852GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
10853GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10854GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10855GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10856GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10857GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10858GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10859GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10860GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
10861GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10862GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10863GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10864GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10865GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
10866
10867GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10868GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 10869GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 10870GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 10871GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 10872GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 10873GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 10874GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 10875GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
10876GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10877GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10878GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10879GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10880GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10881GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10882GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10883GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
10884GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10885GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
10886GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10887GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10888GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 10889GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
10890GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10891GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10892GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10893GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10894GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10895GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10896GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10897GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
10898GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10899GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10900GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10901GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10902GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 10903
79ca8a6a
TM
10904#undef VSX_LOGICAL
10905#define VSX_LOGICAL(name, opc2, opc3, fl2) \
10906GEN_XX3FORM(name, opc2, opc3, fl2)
10907
10908VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10909VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10910VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10911VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10912VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
67a33f37
TM
10913VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207),
10914VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207),
10915VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207),
ce577d2e
TM
10916GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10917GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 10918GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 10919GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 10920
551e3ef7
TM
10921#define GEN_XXSEL_ROW(opc3) \
10922GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10923GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10924GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10925GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10926GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10927GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10928GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10929GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10930
10931GEN_XXSEL_ROW(0x00)
10932GEN_XXSEL_ROW(0x01)
10933GEN_XXSEL_ROW(0x02)
10934GEN_XXSEL_ROW(0x03)
10935GEN_XXSEL_ROW(0x04)
10936GEN_XXSEL_ROW(0x05)
10937GEN_XXSEL_ROW(0x06)
10938GEN_XXSEL_ROW(0x07)
10939GEN_XXSEL_ROW(0x08)
10940GEN_XXSEL_ROW(0x09)
10941GEN_XXSEL_ROW(0x0A)
10942GEN_XXSEL_ROW(0x0B)
10943GEN_XXSEL_ROW(0x0C)
10944GEN_XXSEL_ROW(0x0D)
10945GEN_XXSEL_ROW(0x0E)
10946GEN_XXSEL_ROW(0x0F)
10947GEN_XXSEL_ROW(0x10)
10948GEN_XXSEL_ROW(0x11)
10949GEN_XXSEL_ROW(0x12)
10950GEN_XXSEL_ROW(0x13)
10951GEN_XXSEL_ROW(0x14)
10952GEN_XXSEL_ROW(0x15)
10953GEN_XXSEL_ROW(0x16)
10954GEN_XXSEL_ROW(0x17)
10955GEN_XXSEL_ROW(0x18)
10956GEN_XXSEL_ROW(0x19)
10957GEN_XXSEL_ROW(0x1A)
10958GEN_XXSEL_ROW(0x1B)
10959GEN_XXSEL_ROW(0x1C)
10960GEN_XXSEL_ROW(0x1D)
10961GEN_XXSEL_ROW(0x1E)
10962GEN_XXSEL_ROW(0x1F)
10963
cd73f2c9
TM
10964GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
10965
275e35c6
TM
10966#undef GEN_DFP_T_A_B_Rc
10967#undef GEN_DFP_BF_A_B
10968#undef GEN_DFP_BF_A_DCM
10969#undef GEN_DFP_T_B_U32_U32_Rc
10970#undef GEN_DFP_T_A_B_I32_Rc
10971#undef GEN_DFP_T_B_Rc
10972#undef GEN_DFP_T_FPR_I32_Rc
10973
10974#define _GEN_DFP_LONG(name, op1, op2, mask) \
10975GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
10976
10977#define _GEN_DFP_LONGx2(name, op1, op2, mask) \
10978GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10979GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10980
10981#define _GEN_DFP_LONGx4(name, op1, op2, mask) \
10982GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10983GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10984GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10985GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10986
10987#define _GEN_DFP_QUAD(name, op1, op2, mask) \
10988GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
10989
10990#define _GEN_DFP_QUADx2(name, op1, op2, mask) \
10991GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10992GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10993
10994#define _GEN_DFP_QUADx4(name, op1, op2, mask) \
10995GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10996GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10997GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10998GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10999
11000#define GEN_DFP_T_A_B_Rc(name, op1, op2) \
11001_GEN_DFP_LONG(name, op1, op2, 0x00000000)
11002
11003#define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
11004_GEN_DFP_QUAD(name, op1, op2, 0x00210800)
11005
11006#define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
11007_GEN_DFP_QUAD(name, op1, op2, 0x00200800)
11008
11009#define GEN_DFP_T_B_Rc(name, op1, op2) \
11010_GEN_DFP_LONG(name, op1, op2, 0x001F0000)
11011
11012#define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
11013_GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
11014
11015#define GEN_DFP_Tp_B_Rc(name, op1, op2) \
11016_GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
11017
11018#define GEN_DFP_T_Bp_Rc(name, op1, op2) \
11019_GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
11020
11021#define GEN_DFP_BF_A_B(name, op1, op2) \
11022_GEN_DFP_LONG(name, op1, op2, 0x00000001)
11023
11024#define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
11025_GEN_DFP_QUAD(name, op1, op2, 0x00610801)
11026
11027#define GEN_DFP_BF_A_Bp(name, op1, op2) \
11028_GEN_DFP_QUAD(name, op1, op2, 0x00600801)
11029
11030#define GEN_DFP_BF_A_DCM(name, op1, op2) \
11031_GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
11032
11033#define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
11034_GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
11035
11036#define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
11037_GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11038
11039#define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
11040_GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
11041
11042#define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
11043_GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
11044
11045#define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
11046_GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11047
11048#define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
11049_GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
11050
11051#define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
11052_GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
11053
11054#define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
11055_GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
11056
11057#define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
11058_GEN_DFP_LONG(name, op1, op2, 0x00070000)
11059
11060#define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
11061_GEN_DFP_QUAD(name, op1, op2, 0x00270800)
11062
11063#define GEN_DFP_S_T_B_Rc(name, op1, op2) \
11064_GEN_DFP_LONG(name, op1, op2, 0x000F0000)
11065
11066#define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
11067_GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
11068
11069#define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
11070_GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
11071
11072#define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
11073_GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
11074
a9d7ba03
TM
11075GEN_DFP_T_A_B_Rc(dadd, 0x02, 0x00),
11076GEN_DFP_Tp_Ap_Bp_Rc(daddq, 0x02, 0x00),
2128f8a5
TM
11077GEN_DFP_T_A_B_Rc(dsub, 0x02, 0x10),
11078GEN_DFP_Tp_Ap_Bp_Rc(dsubq, 0x02, 0x10),
8de6a1cc
TM
11079GEN_DFP_T_A_B_Rc(dmul, 0x02, 0x01),
11080GEN_DFP_Tp_Ap_Bp_Rc(dmulq, 0x02, 0x01),
9024ff40
TM
11081GEN_DFP_T_A_B_Rc(ddiv, 0x02, 0x11),
11082GEN_DFP_Tp_Ap_Bp_Rc(ddivq, 0x02, 0x11),
5833505b
TM
11083GEN_DFP_BF_A_B(dcmpu, 0x02, 0x14),
11084GEN_DFP_BF_Ap_Bp(dcmpuq, 0x02, 0x14),
11085GEN_DFP_BF_A_B(dcmpo, 0x02, 0x04),
11086GEN_DFP_BF_Ap_Bp(dcmpoq, 0x02, 0x04),
e601c1ee
TM
11087GEN_DFP_BF_A_DCM(dtstdc, 0x02, 0x06),
11088GEN_DFP_BF_Ap_DCM(dtstdcq, 0x02, 0x06),
1bf9c0e1
TM
11089GEN_DFP_BF_A_DCM(dtstdg, 0x02, 0x07),
11090GEN_DFP_BF_Ap_DCM(dtstdgq, 0x02, 0x07),
f3d2b0bc
TM
11091GEN_DFP_BF_A_B(dtstex, 0x02, 0x05),
11092GEN_DFP_BF_Ap_Bp(dtstexq, 0x02, 0x05),
f6022a76
TM
11093GEN_DFP_BF_A_B(dtstsf, 0x02, 0x15),
11094GEN_DFP_BF_A_Bp(dtstsfq, 0x02, 0x15),
5826ebe2
TM
11095GEN_DFP_TE_T_B_RMC_Rc(dquai, 0x03, 0x02),
11096GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq, 0x03, 0x02),
11097GEN_DFP_T_A_B_RMC_Rc(dqua, 0x03, 0x00),
11098GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq, 0x03, 0x00),
512918aa
TM
11099GEN_DFP_T_A_B_RMC_Rc(drrnd, 0x03, 0x01),
11100GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq, 0x03, 0x01),
97c0d930
TM
11101GEN_DFP_R_T_B_RMC_Rc(drintx, 0x03, 0x03),
11102GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq, 0x03, 0x03),
11103GEN_DFP_R_T_B_RMC_Rc(drintn, 0x03, 0x07),
11104GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq, 0x03, 0x07),
290d9ee5
TM
11105GEN_DFP_T_B_Rc(dctdp, 0x02, 0x08),
11106GEN_DFP_Tp_B_Rc(dctqpq, 0x02, 0x08),
ca603eb4
TM
11107GEN_DFP_T_B_Rc(drsp, 0x02, 0x18),
11108GEN_DFP_Tp_Bp_Rc(drdpq, 0x02, 0x18),
f1214193
TM
11109GEN_DFP_T_B_Rc(dcffix, 0x02, 0x19),
11110GEN_DFP_Tp_B_Rc(dcffixq, 0x02, 0x19),
bea0dd79
TM
11111GEN_DFP_T_B_Rc(dctfix, 0x02, 0x09),
11112GEN_DFP_T_Bp_Rc(dctfixq, 0x02, 0x09),
7796676f
TM
11113GEN_DFP_SP_T_B_Rc(ddedpd, 0x02, 0x0a),
11114GEN_DFP_SP_Tp_Bp_Rc(ddedpdq, 0x02, 0x0a),
013c3ac0
TM
11115GEN_DFP_S_T_B_Rc(denbcd, 0x02, 0x1a),
11116GEN_DFP_S_Tp_Bp_Rc(denbcdq, 0x02, 0x1a),
e8a48460
TM
11117GEN_DFP_T_B_Rc(dxex, 0x02, 0x0b),
11118GEN_DFP_T_Bp_Rc(dxexq, 0x02, 0x0b),
297666eb
TM
11119GEN_DFP_T_A_B_Rc(diex, 0x02, 0x1b),
11120GEN_DFP_Tp_A_Bp_Rc(diexq, 0x02, 0x1b),
804e654a
TM
11121GEN_DFP_T_A_SH_Rc(dscli, 0x02, 0x02),
11122GEN_DFP_Tp_Ap_SH_Rc(dscliq, 0x02, 0x02),
11123GEN_DFP_T_A_SH_Rc(dscri, 0x02, 0x03),
11124GEN_DFP_Tp_Ap_SH_Rc(dscriq, 0x02, 0x03),
11125
5c55ff99 11126#undef GEN_SPE
70560da7
FC
11127#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11128 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11129GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11130GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11131GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11132GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11133GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11134GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11135GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
11136GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
11137GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
11138GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11139GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11140GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11141GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11142GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11143GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
11144GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
11145GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
11146GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11147GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11148GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11149GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11150GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
11151GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11152GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
11153GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11154GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
11155GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11156GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
11157GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
11158
11159GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11160GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11161GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11162GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11163GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11164GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11165GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11166GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11167GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11168GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11169GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11170GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11171GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11172GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11173
11174GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11175GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
11176GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
11177GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
11178GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11179GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
11180GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11181GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11182GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11183GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
11184GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11185GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11186GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
11187GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
11188
11189GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11190GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11191GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
11192GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11193GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
11194GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11195GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11196GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
11197GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11198GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11199GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11200GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
11201GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11202GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
11203GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
11204GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
11205
11206#undef GEN_SPEOP_LDST
11207#define GEN_SPEOP_LDST(name, opc2, sh) \
11208GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11209GEN_SPEOP_LDST(evldd, 0x00, 3),
11210GEN_SPEOP_LDST(evldw, 0x01, 3),
11211GEN_SPEOP_LDST(evldh, 0x02, 3),
11212GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
11213GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
11214GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
11215GEN_SPEOP_LDST(evlwhe, 0x08, 2),
11216GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
11217GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
11218GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
11219GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
11220
11221GEN_SPEOP_LDST(evstdd, 0x10, 3),
11222GEN_SPEOP_LDST(evstdw, 0x11, 3),
11223GEN_SPEOP_LDST(evstdh, 0x12, 3),
11224GEN_SPEOP_LDST(evstwhe, 0x18, 2),
11225GEN_SPEOP_LDST(evstwho, 0x1A, 2),
11226GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
11227GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
0ff93d11
TM
11228
11229GEN_HANDLER2_E(tbegin, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
11230 PPC_NONE, PPC2_TM),
56a84615
TM
11231GEN_HANDLER2_E(tend, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
11232 PPC_NONE, PPC2_TM),
11233GEN_HANDLER2_E(tabort, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
11234 PPC_NONE, PPC2_TM),
11235GEN_HANDLER2_E(tabortwc, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
11236 PPC_NONE, PPC2_TM),
11237GEN_HANDLER2_E(tabortwci, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
11238 PPC_NONE, PPC2_TM),
11239GEN_HANDLER2_E(tabortdc, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
11240 PPC_NONE, PPC2_TM),
11241GEN_HANDLER2_E(tabortdci, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
11242 PPC_NONE, PPC2_TM),
11243GEN_HANDLER2_E(tsr, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
11244 PPC_NONE, PPC2_TM),
aeedd582
TM
11245GEN_HANDLER2_E(tcheck, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
11246 PPC_NONE, PPC2_TM),
f83c2378
TM
11247GEN_HANDLER2_E(treclaim, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
11248 PPC_NONE, PPC2_TM),
11249GEN_HANDLER2_E(trechkpt, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
11250 PPC_NONE, PPC2_TM),
5c55ff99
BS
11251};
11252
0411a972 11253#include "helper_regs.h"
a1389542 11254#include "translate_init.c"
79aceca5 11255
9a64fbe4 11256/*****************************************************************************/
3fc6c082 11257/* Misc PowerPC helpers */
878096ee
AF
11258void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
11259 int flags)
79aceca5 11260{
3fc6c082
FB
11261#define RGPL 4
11262#define RFPL 4
3fc6c082 11263
878096ee
AF
11264 PowerPCCPU *cpu = POWERPC_CPU(cs);
11265 CPUPPCState *env = &cpu->env;
79aceca5
FB
11266 int i;
11267
90e189ec 11268 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
21e5d28a
TG
11269 TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n",
11270 env->nip, env->lr, env->ctr, cpu_read_xer(env),
11271 cs->cpu_index);
90e189ec 11272 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
9fb04491
BH
11273 TARGET_FMT_lx " iidx %d didx %d\n",
11274 env->msr, env->spr[SPR_HID0],
11275 env->hflags, env->immu_idx, env->dmmu_idx);
d9bce9d9 11276#if !defined(NO_TIMER_DUMP)
9a78eead 11277 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 11278#if !defined(CONFIG_USER_ONLY)
9a78eead 11279 " DECR %08" PRIu32
76a66253
JM
11280#endif
11281 "\n",
077fc206 11282 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
11283#if !defined(CONFIG_USER_ONLY)
11284 , cpu_ppc_load_decr(env)
11285#endif
11286 );
077fc206 11287#endif
76a66253 11288 for (i = 0; i < 32; i++) {
3fc6c082
FB
11289 if ((i & (RGPL - 1)) == 0)
11290 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 11291 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 11292 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 11293 cpu_fprintf(f, "\n");
76a66253 11294 }
3fc6c082 11295 cpu_fprintf(f, "CR ");
76a66253 11296 for (i = 0; i < 8; i++)
7fe48483
FB
11297 cpu_fprintf(f, "%01x", env->crf[i]);
11298 cpu_fprintf(f, " [");
76a66253
JM
11299 for (i = 0; i < 8; i++) {
11300 char a = '-';
11301 if (env->crf[i] & 0x08)
11302 a = 'L';
11303 else if (env->crf[i] & 0x04)
11304 a = 'G';
11305 else if (env->crf[i] & 0x02)
11306 a = 'E';
7fe48483 11307 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 11308 }
90e189ec
BS
11309 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
11310 env->reserve_addr);
3fc6c082
FB
11311 for (i = 0; i < 32; i++) {
11312 if ((i & (RFPL - 1)) == 0)
11313 cpu_fprintf(f, "FPR%02d", i);
26a76461 11314 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 11315 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 11316 cpu_fprintf(f, "\n");
79aceca5 11317 }
30304420 11318 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 11319#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
11320 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
11321 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
11322 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
11323 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
11324
11325 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
11326 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
11327 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
11328 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
11329
11330 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
11331 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
11332 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
11333 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
11334
11335 if (env->excp_model == POWERPC_EXCP_BOOKE) {
11336 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
11337 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
11338 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
11339 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
11340
11341 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
11342 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
11343 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
11344 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
11345
11346 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
11347 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
11348 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
11349 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
11350
11351 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
11352 " EPR " TARGET_FMT_lx "\n",
11353 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
11354 env->spr[SPR_BOOKE_EPR]);
11355
11356 /* FSL-specific */
11357 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
11358 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
11359 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
11360 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
11361
11362 /*
11363 * IVORs are left out as they are large and do not change often --
11364 * they can be read with "p $ivor0", "p $ivor1", etc.
11365 */
11366 }
11367
697ab892
DG
11368#if defined(TARGET_PPC64)
11369 if (env->flags & POWERPC_FLAG_CFAR) {
11370 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
11371 }
11372#endif
11373
90dc8812
SW
11374 switch (env->mmu_model) {
11375 case POWERPC_MMU_32B:
11376 case POWERPC_MMU_601:
11377 case POWERPC_MMU_SOFT_6xx:
11378 case POWERPC_MMU_SOFT_74xx:
11379#if defined(TARGET_PPC64)
90dc8812 11380 case POWERPC_MMU_64B:
aa4bb587 11381 case POWERPC_MMU_2_03:
ca480de6 11382 case POWERPC_MMU_2_06:
808bc3b0 11383 case POWERPC_MMU_2_06a:
aa4bb587 11384 case POWERPC_MMU_2_07:
808bc3b0 11385 case POWERPC_MMU_2_07a:
90dc8812 11386#endif
ca480de6
AB
11387 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
11388 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
11389 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 11390 break;
01662f3e 11391 case POWERPC_MMU_BOOKE206:
90dc8812
SW
11392 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
11393 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
11394 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
11395 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
11396
11397 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
11398 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
11399 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
11400 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
11401
11402 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
11403 " TLB1CFG " TARGET_FMT_lx "\n",
11404 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
11405 env->spr[SPR_BOOKE_TLB1CFG]);
11406 break;
11407 default:
11408 break;
11409 }
f2e63a42 11410#endif
79aceca5 11411
3fc6c082
FB
11412#undef RGPL
11413#undef RFPL
79aceca5
FB
11414}
11415
878096ee
AF
11416void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
11417 fprintf_function cpu_fprintf, int flags)
76a66253
JM
11418{
11419#if defined(DO_PPC_STATISTICS)
878096ee 11420 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 11421 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
11422 int op1, op2, op3;
11423
878096ee 11424 t1 = cpu->env.opcodes;
76a66253
JM
11425 for (op1 = 0; op1 < 64; op1++) {
11426 handler = t1[op1];
11427 if (is_indirect_opcode(handler)) {
11428 t2 = ind_table(handler);
11429 for (op2 = 0; op2 < 32; op2++) {
11430 handler = t2[op2];
11431 if (is_indirect_opcode(handler)) {
11432 t3 = ind_table(handler);
11433 for (op3 = 0; op3 < 32; op3++) {
11434 handler = t3[op3];
11435 if (handler->count == 0)
11436 continue;
11437 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 11438 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11439 op1, op2, op3, op1, (op3 << 5) | op2,
11440 handler->oname,
11441 handler->count, handler->count);
11442 }
11443 } else {
11444 if (handler->count == 0)
11445 continue;
11446 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 11447 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
11448 op1, op2, op1, op2, handler->oname,
11449 handler->count, handler->count);
11450 }
11451 }
11452 } else {
11453 if (handler->count == 0)
11454 continue;
0bfcd599
BS
11455 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
11456 " %" PRId64 "\n",
76a66253
JM
11457 op1, op1, handler->oname,
11458 handler->count, handler->count);
11459 }
11460 }
11461#endif
11462}
11463
9a64fbe4 11464/*****************************************************************************/
4e5e1215 11465void gen_intermediate_code(CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 11466{
4e5e1215 11467 PowerPCCPU *cpu = ppc_env_get_cpu(env);
ed2803da 11468 CPUState *cs = CPU(cpu);
9fddaa0c 11469 DisasContext ctx, *ctxp = &ctx;
c227f099 11470 opc_handler_t **table, *handler;
0fa85d43 11471 target_ulong pc_start;
2e70f6ef
PB
11472 int num_insns;
11473 int max_insns;
79aceca5
FB
11474
11475 pc_start = tb->pc;
046d6672 11476 ctx.nip = pc_start;
79aceca5 11477 ctx.tb = tb;
e1833e1f 11478 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 11479 ctx.spr_cb = env->spr_cb;
c47493f2 11480 ctx.pr = msr_pr;
9fb04491 11481 ctx.mem_idx = env->dmmu_idx;
932ccbdd
BH
11482#if !defined(CONFIG_USER_ONLY)
11483 ctx.hv = msr_hv || !env->has_hv_mode;
11484#endif
7d08d856
AJ
11485 ctx.insns_flags = env->insns_flags;
11486 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
11487 ctx.access_type = -1;
11488 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
e22c357b 11489 ctx.default_tcg_memop_mask = ctx.le_mode ? MO_LE : MO_BE;
d9bce9d9 11490#if defined(TARGET_PPC64)
e42a61f1 11491 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 11492 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 11493#endif
3cc62370 11494 ctx.fpu_enabled = msr_fp;
a9d9eb8f 11495 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
11496 ctx.spe_enabled = msr_spe;
11497 else
11498 ctx.spe_enabled = 0;
a9d9eb8f
JM
11499 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
11500 ctx.altivec_enabled = msr_vr;
11501 else
11502 ctx.altivec_enabled = 0;
1f29871c
TM
11503 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
11504 ctx.vsx_enabled = msr_vsx;
11505 } else {
11506 ctx.vsx_enabled = 0;
11507 }
69d1a937
TM
11508#if defined(TARGET_PPC64)
11509 if ((env->flags & POWERPC_FLAG_TM) && msr_tm) {
11510 ctx.tm_enabled = msr_tm;
11511 } else {
11512 ctx.tm_enabled = 0;
11513 }
11514#endif
d26bfc9a 11515 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 11516 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 11517 else
8cbcb4fa 11518 ctx.singlestep_enabled = 0;
d26bfc9a 11519 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 11520 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 11521 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 11522 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 11523 }
3fc6c082 11524#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
11525 /* Single step trace mode */
11526 msr_se = 1;
11527#endif
2e70f6ef
PB
11528 num_insns = 0;
11529 max_insns = tb->cflags & CF_COUNT_MASK;
190ce7fb 11530 if (max_insns == 0) {
2e70f6ef 11531 max_insns = CF_COUNT_MASK;
190ce7fb
RH
11532 }
11533 if (max_insns > TCG_MAX_INSNS) {
11534 max_insns = TCG_MAX_INSNS;
11535 }
2e70f6ef 11536
cd42d5b2 11537 gen_tb_start(tb);
3de31797 11538 tcg_clear_temp_count();
9a64fbe4 11539 /* Set env in case of segfault during code fetch */
fe700adb 11540 while (ctx.exception == POWERPC_EXCP_NONE && !tcg_op_buf_full()) {
667b8e29 11541 tcg_gen_insn_start(ctx.nip);
959082fc 11542 num_insns++;
667b8e29 11543
b933066a
RH
11544 if (unlikely(cpu_breakpoint_test(cs, ctx.nip, BP_ANY))) {
11545 gen_debug_exception(ctxp);
522a0d4e
RH
11546 /* The address covered by the breakpoint must be included in
11547 [tb->pc, tb->pc + tb->size) in order to for it to be
11548 properly cleared -- thus we increment the PC here so that
11549 the logic setting tb->size below does the right thing. */
11550 ctx.nip += 4;
b933066a
RH
11551 break;
11552 }
11553
d12d51d5 11554 LOG_DISAS("----------------\n");
90e189ec 11555 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 11556 ctx.nip, ctx.mem_idx, (int)msr_ir);
959082fc 11557 if (num_insns == max_insns && (tb->cflags & CF_LAST_IO))
2e70f6ef 11558 gen_io_start();
e22c357b 11559 if (unlikely(need_byteswap(&ctx))) {
2f5a189c 11560 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 11561 } else {
2f5a189c 11562 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 11563 }
d12d51d5 11564 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 11565 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 11566 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
046d6672 11567 ctx.nip += 4;
3fc6c082 11568 table = env->opcodes;
79aceca5
FB
11569 handler = table[opc1(ctx.opcode)];
11570 if (is_indirect_opcode(handler)) {
11571 table = ind_table(handler);
11572 handler = table[opc2(ctx.opcode)];
11573 if (is_indirect_opcode(handler)) {
11574 table = ind_table(handler);
11575 handler = table[opc3(ctx.opcode)];
11576 }
11577 }
11578 /* Is opcode *REALLY* valid ? */
76a66253 11579 if (unlikely(handler->handler == &gen_invalid)) {
48880da6
PB
11580 qemu_log_mask(LOG_GUEST_ERROR, "invalid/unsupported opcode: "
11581 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
11582 opc1(ctx.opcode), opc2(ctx.opcode),
11583 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
76a66253 11584 } else {
70560da7
FC
11585 uint32_t inval;
11586
11587 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
11588 inval = handler->inval2;
11589 } else {
11590 inval = handler->inval1;
11591 }
11592
11593 if (unlikely((ctx.opcode & inval) != 0)) {
48880da6
PB
11594 qemu_log_mask(LOG_GUEST_ERROR, "invalid bits: %08x for opcode: "
11595 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
11596 ctx.opcode & inval, opc1(ctx.opcode),
11597 opc2(ctx.opcode), opc3(ctx.opcode),
11598 ctx.opcode, ctx.nip - 4);
e06fcd75 11599 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 11600 break;
79aceca5 11601 }
79aceca5 11602 }
4b3686fa 11603 (*(handler->handler))(&ctx);
76a66253
JM
11604#if defined(DO_PPC_STATISTICS)
11605 handler->count++;
11606#endif
9a64fbe4 11607 /* Check trace mode exceptions */
8cbcb4fa
AJ
11608 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
11609 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
11610 ctx.exception != POWERPC_SYSCALL &&
11611 ctx.exception != POWERPC_EXCP_TRAP &&
11612 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 11613 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 11614 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 11615 (cs->singlestep_enabled) ||
1b530a6d 11616 singlestep ||
2e70f6ef 11617 num_insns >= max_insns)) {
d26bfc9a
JM
11618 /* if we reach a page boundary or are single stepping, stop
11619 * generation
11620 */
8dd4983c 11621 break;
76a66253 11622 }
3de31797
AG
11623 if (tcg_check_temp_count()) {
11624 fprintf(stderr, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11625 opc1(ctx.opcode), opc2(ctx.opcode), opc3(ctx.opcode),
11626 ctx.opcode);
11627 exit(1);
11628 }
3fc6c082 11629 }
2e70f6ef
PB
11630 if (tb->cflags & CF_LAST_IO)
11631 gen_io_end();
e1833e1f 11632 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 11633 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 11634 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 11635 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 11636 gen_debug_exception(ctxp);
8cbcb4fa 11637 }
76a66253 11638 /* Generate the return instruction */
57fec1fe 11639 tcg_gen_exit_tb(0);
9a64fbe4 11640 }
806f352d 11641 gen_tb_end(tb, num_insns);
0a7df5da 11642
4e5e1215
RH
11643 tb->size = ctx.nip - pc_start;
11644 tb->icount = num_insns;
11645
d9bce9d9 11646#if defined(DEBUG_DISAS)
4910e6e4
RH
11647 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
11648 && qemu_log_in_addr_range(pc_start)) {
76a66253 11649 int flags;
237c0af0 11650 flags = env->bfd_mach;
76db3ba4 11651 flags |= ctx.le_mode << 16;
93fcfe39 11652 qemu_log("IN: %s\n", lookup_symbol(pc_start));
d49190c4 11653 log_target_disas(cs, pc_start, ctx.nip - pc_start, flags);
93fcfe39 11654 qemu_log("\n");
9fddaa0c 11655 }
79aceca5 11656#endif
79aceca5
FB
11657}
11658
bad729e2
RH
11659void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb,
11660 target_ulong *data)
d2856f1a 11661{
bad729e2 11662 env->nip = data[0];
d2856f1a 11663}