]> git.proxmox.com Git - mirror_qemu.git/blame - target-ppc/translate.c
target-ppc: VSX Stage 4: Add xssqrtsp
[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
79aceca5 21#include "cpu.h"
76cad711 22#include "disas/disas.h"
57fec1fe 23#include "tcg-op.h"
1de7afc9 24#include "qemu/host-utils.h"
79aceca5 25
a7812ae4
PB
26#include "helper.h"
27#define GEN_HELPER 1
28#include "helper.h"
29
8cbcb4fa
AJ
30#define CPU_SINGLE_STEP 0x1
31#define CPU_BRANCH_STEP 0x2
32#define GDBSTUB_SINGLE_STEP 0x4
33
a750fc0b 34/* Include definitions for instructions classes and implementations flags */
9fddaa0c 35//#define PPC_DEBUG_DISAS
76a66253 36//#define DO_PPC_STATISTICS
79aceca5 37
d12d51d5 38#ifdef PPC_DEBUG_DISAS
93fcfe39 39# define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
d12d51d5
AL
40#else
41# define LOG_DISAS(...) do { } while (0)
42#endif
a750fc0b
JM
43/*****************************************************************************/
44/* Code translation helpers */
c53be334 45
f78fb44e 46/* global register indexes */
a7812ae4 47static TCGv_ptr cpu_env;
1d542695 48static char cpu_reg_names[10*3 + 22*4 /* GPR */
f78fb44e 49#if !defined(TARGET_PPC64)
1d542695 50 + 10*4 + 22*5 /* SPE GPRh */
f78fb44e 51#endif
a5e26afa 52 + 10*4 + 22*5 /* FPR */
47e4661c 53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
472b24ce 54 + 10*5 + 22*6 /* VSR */
47e4661c 55 + 8*5 /* CRF */];
f78fb44e
AJ
56static TCGv cpu_gpr[32];
57#if !defined(TARGET_PPC64)
58static TCGv cpu_gprh[32];
59#endif
a7812ae4
PB
60static TCGv_i64 cpu_fpr[32];
61static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
472b24ce 62static TCGv_i64 cpu_vsr[32];
a7812ae4 63static TCGv_i32 cpu_crf[8];
bd568f18 64static TCGv cpu_nip;
6527f6ea 65static TCGv cpu_msr;
cfdcd37a
AJ
66static TCGv cpu_ctr;
67static TCGv cpu_lr;
697ab892
DG
68#if defined(TARGET_PPC64)
69static TCGv cpu_cfar;
70#endif
da91a00f 71static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
cf360a32 72static TCGv cpu_reserve;
30304420 73static TCGv cpu_fpscr;
a7859e89 74static TCGv_i32 cpu_access_type;
f78fb44e 75
022c62cb 76#include "exec/gen-icount.h"
2e70f6ef
PB
77
78void ppc_translate_init(void)
79{
f78fb44e
AJ
80 int i;
81 char* p;
2dc766da 82 size_t cpu_reg_names_size;
b2437bf2 83 static int done_init = 0;
f78fb44e 84
2e70f6ef
PB
85 if (done_init)
86 return;
f78fb44e 87
a7812ae4 88 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
a7812ae4 89
f78fb44e 90 p = cpu_reg_names;
2dc766da 91 cpu_reg_names_size = sizeof(cpu_reg_names);
47e4661c
AJ
92
93 for (i = 0; i < 8; i++) {
2dc766da 94 snprintf(p, cpu_reg_names_size, "crf%d", i);
a7812ae4 95 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 96 offsetof(CPUPPCState, crf[i]), p);
47e4661c 97 p += 5;
2dc766da 98 cpu_reg_names_size -= 5;
47e4661c
AJ
99 }
100
f78fb44e 101 for (i = 0; i < 32; i++) {
2dc766da 102 snprintf(p, cpu_reg_names_size, "r%d", i);
a7812ae4 103 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
1328c2bf 104 offsetof(CPUPPCState, gpr[i]), p);
f78fb44e 105 p += (i < 10) ? 3 : 4;
2dc766da 106 cpu_reg_names_size -= (i < 10) ? 3 : 4;
f78fb44e 107#if !defined(TARGET_PPC64)
2dc766da 108 snprintf(p, cpu_reg_names_size, "r%dH", i);
a7812ae4 109 cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 110 offsetof(CPUPPCState, gprh[i]), p);
f78fb44e 111 p += (i < 10) ? 4 : 5;
2dc766da 112 cpu_reg_names_size -= (i < 10) ? 4 : 5;
f78fb44e 113#endif
1d542695 114
2dc766da 115 snprintf(p, cpu_reg_names_size, "fp%d", i);
a7812ae4 116 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 117 offsetof(CPUPPCState, fpr[i]), p);
ec1ac72d 118 p += (i < 10) ? 4 : 5;
2dc766da 119 cpu_reg_names_size -= (i < 10) ? 4 : 5;
a5e26afa 120
2dc766da 121 snprintf(p, cpu_reg_names_size, "avr%dH", i);
e2542fe2 122#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 123 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 124 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 125#else
a7812ae4 126 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 127 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 128#endif
1d542695 129 p += (i < 10) ? 6 : 7;
2dc766da 130 cpu_reg_names_size -= (i < 10) ? 6 : 7;
ec1ac72d 131
2dc766da 132 snprintf(p, cpu_reg_names_size, "avr%dL", i);
e2542fe2 133#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 134 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 135 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 136#else
a7812ae4 137 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 138 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 139#endif
1d542695 140 p += (i < 10) ? 6 : 7;
2dc766da 141 cpu_reg_names_size -= (i < 10) ? 6 : 7;
472b24ce
TM
142 snprintf(p, cpu_reg_names_size, "vsr%d", i);
143 cpu_vsr[i] = tcg_global_mem_new_i64(TCG_AREG0,
144 offsetof(CPUPPCState, vsr[i]), p);
145 p += (i < 10) ? 5 : 6;
146 cpu_reg_names_size -= (i < 10) ? 5 : 6;
f78fb44e 147 }
f10dc08e 148
a7812ae4 149 cpu_nip = tcg_global_mem_new(TCG_AREG0,
1328c2bf 150 offsetof(CPUPPCState, nip), "nip");
bd568f18 151
6527f6ea 152 cpu_msr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 153 offsetof(CPUPPCState, msr), "msr");
6527f6ea 154
a7812ae4 155 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 156 offsetof(CPUPPCState, ctr), "ctr");
cfdcd37a 157
a7812ae4 158 cpu_lr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 159 offsetof(CPUPPCState, lr), "lr");
cfdcd37a 160
697ab892
DG
161#if defined(TARGET_PPC64)
162 cpu_cfar = tcg_global_mem_new(TCG_AREG0,
1328c2bf 163 offsetof(CPUPPCState, cfar), "cfar");
697ab892
DG
164#endif
165
a7812ae4 166 cpu_xer = tcg_global_mem_new(TCG_AREG0,
1328c2bf 167 offsetof(CPUPPCState, xer), "xer");
da91a00f
RH
168 cpu_so = tcg_global_mem_new(TCG_AREG0,
169 offsetof(CPUPPCState, so), "SO");
170 cpu_ov = tcg_global_mem_new(TCG_AREG0,
171 offsetof(CPUPPCState, ov), "OV");
172 cpu_ca = tcg_global_mem_new(TCG_AREG0,
173 offsetof(CPUPPCState, ca), "CA");
3d7b417e 174
cf360a32 175 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
1328c2bf 176 offsetof(CPUPPCState, reserve_addr),
18b21a2f 177 "reserve_addr");
cf360a32 178
30304420
DG
179 cpu_fpscr = tcg_global_mem_new(TCG_AREG0,
180 offsetof(CPUPPCState, fpscr), "fpscr");
e1571908 181
a7859e89 182 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 183 offsetof(CPUPPCState, access_type), "access_type");
a7859e89 184
2e70f6ef
PB
185 done_init = 1;
186}
187
79aceca5
FB
188/* internal defines */
189typedef struct DisasContext {
190 struct TranslationBlock *tb;
0fa85d43 191 target_ulong nip;
79aceca5 192 uint32_t opcode;
9a64fbe4 193 uint32_t exception;
3cc62370
FB
194 /* Routine used to access memory */
195 int mem_idx;
76db3ba4 196 int access_type;
3cc62370 197 /* Translation flags */
76db3ba4 198 int le_mode;
d9bce9d9
JM
199#if defined(TARGET_PPC64)
200 int sf_mode;
697ab892 201 int has_cfar;
9a64fbe4 202#endif
3cc62370 203 int fpu_enabled;
a9d9eb8f 204 int altivec_enabled;
1f29871c 205 int vsx_enabled;
0487d6a8 206 int spe_enabled;
c227f099 207 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
ea4e754f 208 int singlestep_enabled;
7d08d856
AJ
209 uint64_t insns_flags;
210 uint64_t insns_flags2;
79aceca5
FB
211} DisasContext;
212
79482e5a
RH
213/* True when active word size < size of target_long. */
214#ifdef TARGET_PPC64
215# define NARROW_MODE(C) (!(C)->sf_mode)
216#else
217# define NARROW_MODE(C) 0
218#endif
219
c227f099 220struct opc_handler_t {
70560da7
FC
221 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
222 uint32_t inval1;
223 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
224 uint32_t inval2;
9a64fbe4 225 /* instruction type */
0487d6a8 226 uint64_t type;
a5858d7a
AG
227 /* extended instruction type */
228 uint64_t type2;
79aceca5
FB
229 /* handler */
230 void (*handler)(DisasContext *ctx);
a750fc0b 231#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
b55266b5 232 const char *oname;
a750fc0b
JM
233#endif
234#if defined(DO_PPC_STATISTICS)
76a66253
JM
235 uint64_t count;
236#endif
3fc6c082 237};
79aceca5 238
636aa200 239static inline void gen_reset_fpstatus(void)
7c58044c 240{
8e703949 241 gen_helper_reset_fpstatus(cpu_env);
7c58044c
JM
242}
243
636aa200 244static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
7c58044c 245{
0f2f39c2 246 TCGv_i32 t0 = tcg_temp_new_i32();
af12906f 247
7c58044c
JM
248 if (set_fprf != 0) {
249 /* This case might be optimized later */
0f2f39c2 250 tcg_gen_movi_i32(t0, 1);
8e703949 251 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
a7812ae4 252 if (unlikely(set_rc)) {
0f2f39c2 253 tcg_gen_mov_i32(cpu_crf[1], t0);
a7812ae4 254 }
8e703949 255 gen_helper_float_check_status(cpu_env);
7c58044c
JM
256 } else if (unlikely(set_rc)) {
257 /* We always need to compute fpcc */
0f2f39c2 258 tcg_gen_movi_i32(t0, 0);
8e703949 259 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
0f2f39c2 260 tcg_gen_mov_i32(cpu_crf[1], t0);
7c58044c 261 }
af12906f 262
0f2f39c2 263 tcg_temp_free_i32(t0);
7c58044c
JM
264}
265
636aa200 266static inline void gen_set_access_type(DisasContext *ctx, int access_type)
a7859e89 267{
76db3ba4
AJ
268 if (ctx->access_type != access_type) {
269 tcg_gen_movi_i32(cpu_access_type, access_type);
270 ctx->access_type = access_type;
271 }
a7859e89
AJ
272}
273
636aa200 274static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
d9bce9d9 275{
e0c8f9ce
RH
276 if (NARROW_MODE(ctx)) {
277 nip = (uint32_t)nip;
278 }
279 tcg_gen_movi_tl(cpu_nip, nip);
d9bce9d9
JM
280}
281
636aa200 282static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
e06fcd75
AJ
283{
284 TCGv_i32 t0, t1;
285 if (ctx->exception == POWERPC_EXCP_NONE) {
286 gen_update_nip(ctx, ctx->nip);
287 }
288 t0 = tcg_const_i32(excp);
289 t1 = tcg_const_i32(error);
e5f17ac6 290 gen_helper_raise_exception_err(cpu_env, t0, t1);
e06fcd75
AJ
291 tcg_temp_free_i32(t0);
292 tcg_temp_free_i32(t1);
293 ctx->exception = (excp);
294}
e1833e1f 295
636aa200 296static inline void gen_exception(DisasContext *ctx, uint32_t excp)
e06fcd75
AJ
297{
298 TCGv_i32 t0;
299 if (ctx->exception == POWERPC_EXCP_NONE) {
300 gen_update_nip(ctx, ctx->nip);
301 }
302 t0 = tcg_const_i32(excp);
e5f17ac6 303 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
304 tcg_temp_free_i32(t0);
305 ctx->exception = (excp);
306}
e1833e1f 307
636aa200 308static inline void gen_debug_exception(DisasContext *ctx)
e06fcd75
AJ
309{
310 TCGv_i32 t0;
5518f3a6 311
ee2b3994
SB
312 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
313 (ctx->exception != POWERPC_EXCP_SYNC)) {
5518f3a6 314 gen_update_nip(ctx, ctx->nip);
ee2b3994 315 }
e06fcd75 316 t0 = tcg_const_i32(EXCP_DEBUG);
e5f17ac6 317 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
318 tcg_temp_free_i32(t0);
319}
9a64fbe4 320
636aa200 321static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
e06fcd75
AJ
322{
323 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
324}
a9d9eb8f 325
f24e5695 326/* Stop translation */
636aa200 327static inline void gen_stop_exception(DisasContext *ctx)
3fc6c082 328{
d9bce9d9 329 gen_update_nip(ctx, ctx->nip);
e1833e1f 330 ctx->exception = POWERPC_EXCP_STOP;
3fc6c082
FB
331}
332
f24e5695 333/* No need to update nip here, as execution flow will change */
636aa200 334static inline void gen_sync_exception(DisasContext *ctx)
2be0071f 335{
e1833e1f 336 ctx->exception = POWERPC_EXCP_SYNC;
2be0071f
FB
337}
338
79aceca5 339#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
340GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
341
342#define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
343GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
79aceca5 344
c7697e1f 345#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
346GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
347
348#define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
349GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
c7697e1f 350
c227f099 351typedef struct opcode_t {
79aceca5 352 unsigned char opc1, opc2, opc3;
1235fc06 353#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
18fba28c
FB
354 unsigned char pad[5];
355#else
356 unsigned char pad[1];
357#endif
c227f099 358 opc_handler_t handler;
b55266b5 359 const char *oname;
c227f099 360} opcode_t;
79aceca5 361
a750fc0b 362/*****************************************************************************/
79aceca5
FB
363/*** Instruction decoding ***/
364#define EXTRACT_HELPER(name, shift, nb) \
636aa200 365static inline uint32_t name(uint32_t opcode) \
79aceca5
FB
366{ \
367 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
368}
369
370#define EXTRACT_SHELPER(name, shift, nb) \
636aa200 371static inline int32_t name(uint32_t opcode) \
79aceca5 372{ \
18fba28c 373 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
79aceca5
FB
374}
375
f9fc6d81
TM
376#define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
377static inline uint32_t name(uint32_t opcode) \
378{ \
379 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
380 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
381}
79aceca5
FB
382/* Opcode part 1 */
383EXTRACT_HELPER(opc1, 26, 6);
384/* Opcode part 2 */
385EXTRACT_HELPER(opc2, 1, 5);
386/* Opcode part 3 */
387EXTRACT_HELPER(opc3, 6, 5);
388/* Update Cr0 flags */
389EXTRACT_HELPER(Rc, 0, 1);
390/* Destination */
391EXTRACT_HELPER(rD, 21, 5);
392/* Source */
393EXTRACT_HELPER(rS, 21, 5);
394/* First operand */
395EXTRACT_HELPER(rA, 16, 5);
396/* Second operand */
397EXTRACT_HELPER(rB, 11, 5);
398/* Third operand */
399EXTRACT_HELPER(rC, 6, 5);
400/*** Get CRn ***/
401EXTRACT_HELPER(crfD, 23, 3);
402EXTRACT_HELPER(crfS, 18, 3);
403EXTRACT_HELPER(crbD, 21, 5);
404EXTRACT_HELPER(crbA, 16, 5);
405EXTRACT_HELPER(crbB, 11, 5);
406/* SPR / TBL */
3fc6c082 407EXTRACT_HELPER(_SPR, 11, 10);
636aa200 408static inline uint32_t SPR(uint32_t opcode)
3fc6c082
FB
409{
410 uint32_t sprn = _SPR(opcode);
411
412 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
413}
79aceca5
FB
414/*** Get constants ***/
415EXTRACT_HELPER(IMM, 12, 8);
416/* 16 bits signed immediate value */
417EXTRACT_SHELPER(SIMM, 0, 16);
418/* 16 bits unsigned immediate value */
419EXTRACT_HELPER(UIMM, 0, 16);
21d21583
AJ
420/* 5 bits signed immediate value */
421EXTRACT_HELPER(SIMM5, 16, 5);
27a4edb3
AJ
422/* 5 bits signed immediate value */
423EXTRACT_HELPER(UIMM5, 16, 5);
79aceca5
FB
424/* Bit count */
425EXTRACT_HELPER(NB, 11, 5);
426/* Shift count */
427EXTRACT_HELPER(SH, 11, 5);
cd633b10
AJ
428/* Vector shift count */
429EXTRACT_HELPER(VSH, 6, 4);
79aceca5
FB
430/* Mask start */
431EXTRACT_HELPER(MB, 6, 5);
432/* Mask end */
433EXTRACT_HELPER(ME, 1, 5);
fb0eaffc
FB
434/* Trap operand */
435EXTRACT_HELPER(TO, 21, 5);
79aceca5
FB
436
437EXTRACT_HELPER(CRM, 12, 8);
79aceca5 438EXTRACT_HELPER(SR, 16, 4);
7d08d856
AJ
439
440/* mtfsf/mtfsfi */
779f6590 441EXTRACT_HELPER(FPBF, 23, 3);
e4bb997e 442EXTRACT_HELPER(FPIMM, 12, 4);
779f6590 443EXTRACT_HELPER(FPL, 25, 1);
7d08d856
AJ
444EXTRACT_HELPER(FPFLM, 17, 8);
445EXTRACT_HELPER(FPW, 16, 1);
fb0eaffc 446
79aceca5
FB
447/*** Jump target decoding ***/
448/* Displacement */
449EXTRACT_SHELPER(d, 0, 16);
450/* Immediate address */
636aa200 451static inline target_ulong LI(uint32_t opcode)
79aceca5
FB
452{
453 return (opcode >> 0) & 0x03FFFFFC;
454}
455
636aa200 456static inline uint32_t BD(uint32_t opcode)
79aceca5
FB
457{
458 return (opcode >> 0) & 0xFFFC;
459}
460
461EXTRACT_HELPER(BO, 21, 5);
462EXTRACT_HELPER(BI, 16, 5);
463/* Absolute/relative address */
464EXTRACT_HELPER(AA, 1, 1);
465/* Link */
466EXTRACT_HELPER(LK, 0, 1);
467
468/* Create a mask between <start> and <end> bits */
636aa200 469static inline target_ulong MASK(uint32_t start, uint32_t end)
79aceca5 470{
76a66253 471 target_ulong ret;
79aceca5 472
76a66253
JM
473#if defined(TARGET_PPC64)
474 if (likely(start == 0)) {
6f2d8978 475 ret = UINT64_MAX << (63 - end);
76a66253 476 } else if (likely(end == 63)) {
6f2d8978 477 ret = UINT64_MAX >> start;
76a66253
JM
478 }
479#else
480 if (likely(start == 0)) {
6f2d8978 481 ret = UINT32_MAX << (31 - end);
76a66253 482 } else if (likely(end == 31)) {
6f2d8978 483 ret = UINT32_MAX >> start;
76a66253
JM
484 }
485#endif
486 else {
487 ret = (((target_ulong)(-1ULL)) >> (start)) ^
488 (((target_ulong)(-1ULL) >> (end)) >> 1);
489 if (unlikely(start > end))
490 return ~ret;
491 }
79aceca5
FB
492
493 return ret;
494}
495
f9fc6d81
TM
496EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5);
497EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5);
498EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5);
499EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5);
551e3ef7 500EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5);
f9fc6d81 501EXTRACT_HELPER(DM, 8, 2);
76c15fe0 502EXTRACT_HELPER(UIM, 16, 2);
acc42968 503EXTRACT_HELPER(SHW, 8, 2);
a750fc0b 504/*****************************************************************************/
a750fc0b 505/* PowerPC instructions table */
933dc6eb 506
76a66253 507#if defined(DO_PPC_STATISTICS)
a5858d7a 508#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 509{ \
79aceca5
FB
510 .opc1 = op1, \
511 .opc2 = op2, \
512 .opc3 = op3, \
18fba28c 513 .pad = { 0, }, \
79aceca5 514 .handler = { \
70560da7
FC
515 .inval1 = invl, \
516 .type = _typ, \
517 .type2 = _typ2, \
518 .handler = &gen_##name, \
519 .oname = stringify(name), \
520 }, \
521 .oname = stringify(name), \
522}
523#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
524{ \
525 .opc1 = op1, \
526 .opc2 = op2, \
527 .opc3 = op3, \
528 .pad = { 0, }, \
529 .handler = { \
530 .inval1 = invl1, \
531 .inval2 = invl2, \
9a64fbe4 532 .type = _typ, \
a5858d7a 533 .type2 = _typ2, \
79aceca5 534 .handler = &gen_##name, \
76a66253 535 .oname = stringify(name), \
79aceca5 536 }, \
3fc6c082 537 .oname = stringify(name), \
79aceca5 538}
a5858d7a 539#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 540{ \
c7697e1f
JM
541 .opc1 = op1, \
542 .opc2 = op2, \
543 .opc3 = op3, \
544 .pad = { 0, }, \
545 .handler = { \
70560da7 546 .inval1 = invl, \
c7697e1f 547 .type = _typ, \
a5858d7a 548 .type2 = _typ2, \
c7697e1f
JM
549 .handler = &gen_##name, \
550 .oname = onam, \
551 }, \
552 .oname = onam, \
553}
76a66253 554#else
a5858d7a 555#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 556{ \
c7697e1f
JM
557 .opc1 = op1, \
558 .opc2 = op2, \
559 .opc3 = op3, \
560 .pad = { 0, }, \
561 .handler = { \
70560da7
FC
562 .inval1 = invl, \
563 .type = _typ, \
564 .type2 = _typ2, \
565 .handler = &gen_##name, \
566 }, \
567 .oname = stringify(name), \
568}
569#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
570{ \
571 .opc1 = op1, \
572 .opc2 = op2, \
573 .opc3 = op3, \
574 .pad = { 0, }, \
575 .handler = { \
576 .inval1 = invl1, \
577 .inval2 = invl2, \
c7697e1f 578 .type = _typ, \
a5858d7a 579 .type2 = _typ2, \
c7697e1f 580 .handler = &gen_##name, \
5c55ff99
BS
581 }, \
582 .oname = stringify(name), \
583}
a5858d7a 584#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99
BS
585{ \
586 .opc1 = op1, \
587 .opc2 = op2, \
588 .opc3 = op3, \
589 .pad = { 0, }, \
590 .handler = { \
70560da7 591 .inval1 = invl, \
5c55ff99 592 .type = _typ, \
a5858d7a 593 .type2 = _typ2, \
5c55ff99
BS
594 .handler = &gen_##name, \
595 }, \
596 .oname = onam, \
597}
598#endif
2e610050 599
5c55ff99 600/* SPR load/store helpers */
636aa200 601static inline void gen_load_spr(TCGv t, int reg)
5c55ff99 602{
1328c2bf 603 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 604}
2e610050 605
636aa200 606static inline void gen_store_spr(int reg, TCGv t)
5c55ff99 607{
1328c2bf 608 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 609}
2e610050 610
54623277 611/* Invalid instruction */
99e300ef 612static void gen_invalid(DisasContext *ctx)
9a64fbe4 613{
e06fcd75 614 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
9a64fbe4
FB
615}
616
c227f099 617static opc_handler_t invalid_handler = {
70560da7
FC
618 .inval1 = 0xFFFFFFFF,
619 .inval2 = 0xFFFFFFFF,
9a64fbe4 620 .type = PPC_NONE,
a5858d7a 621 .type2 = PPC_NONE,
79aceca5
FB
622 .handler = gen_invalid,
623};
624
e1571908
AJ
625/*** Integer comparison ***/
626
636aa200 627static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 628{
2fdcb629
RH
629 TCGv t0 = tcg_temp_new();
630 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 631
da91a00f 632 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 633
2fdcb629
RH
634 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
635 tcg_gen_trunc_tl_i32(t1, t0);
636 tcg_gen_shli_i32(t1, t1, CRF_LT);
637 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
638
639 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
640 tcg_gen_trunc_tl_i32(t1, t0);
641 tcg_gen_shli_i32(t1, t1, CRF_GT);
642 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
643
644 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
645 tcg_gen_trunc_tl_i32(t1, t0);
646 tcg_gen_shli_i32(t1, t1, CRF_EQ);
647 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
648
649 tcg_temp_free(t0);
650 tcg_temp_free_i32(t1);
e1571908
AJ
651}
652
636aa200 653static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 654{
2fdcb629 655 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
656 gen_op_cmp(arg0, t0, s, crf);
657 tcg_temp_free(t0);
e1571908
AJ
658}
659
636aa200 660static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 661{
ea363694 662 TCGv t0, t1;
2fdcb629
RH
663 t0 = tcg_temp_new();
664 t1 = tcg_temp_new();
e1571908 665 if (s) {
ea363694
AJ
666 tcg_gen_ext32s_tl(t0, arg0);
667 tcg_gen_ext32s_tl(t1, arg1);
e1571908 668 } else {
ea363694
AJ
669 tcg_gen_ext32u_tl(t0, arg0);
670 tcg_gen_ext32u_tl(t1, arg1);
e1571908 671 }
ea363694
AJ
672 gen_op_cmp(t0, t1, s, crf);
673 tcg_temp_free(t1);
674 tcg_temp_free(t0);
e1571908
AJ
675}
676
636aa200 677static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 678{
2fdcb629 679 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
680 gen_op_cmp32(arg0, t0, s, crf);
681 tcg_temp_free(t0);
e1571908 682}
e1571908 683
636aa200 684static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908 685{
02765534 686 if (NARROW_MODE(ctx)) {
e1571908 687 gen_op_cmpi32(reg, 0, 1, 0);
02765534 688 } else {
e1571908 689 gen_op_cmpi(reg, 0, 1, 0);
02765534 690 }
e1571908
AJ
691}
692
693/* cmp */
99e300ef 694static void gen_cmp(DisasContext *ctx)
e1571908 695{
36f48d9c 696 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
697 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
698 1, crfD(ctx->opcode));
36f48d9c
AG
699 } else {
700 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
701 1, crfD(ctx->opcode));
02765534 702 }
e1571908
AJ
703}
704
705/* cmpi */
99e300ef 706static void gen_cmpi(DisasContext *ctx)
e1571908 707{
36f48d9c 708 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
709 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
710 1, crfD(ctx->opcode));
36f48d9c
AG
711 } else {
712 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
713 1, crfD(ctx->opcode));
02765534 714 }
e1571908
AJ
715}
716
717/* cmpl */
99e300ef 718static void gen_cmpl(DisasContext *ctx)
e1571908 719{
36f48d9c 720 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
721 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
722 0, crfD(ctx->opcode));
36f48d9c
AG
723 } else {
724 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
725 0, crfD(ctx->opcode));
02765534 726 }
e1571908
AJ
727}
728
729/* cmpli */
99e300ef 730static void gen_cmpli(DisasContext *ctx)
e1571908 731{
36f48d9c 732 if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) {
e1571908
AJ
733 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
734 0, crfD(ctx->opcode));
36f48d9c
AG
735 } else {
736 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
737 0, crfD(ctx->opcode));
02765534 738 }
e1571908
AJ
739}
740
741/* isel (PowerPC 2.03 specification) */
99e300ef 742static void gen_isel(DisasContext *ctx)
e1571908
AJ
743{
744 int l1, l2;
745 uint32_t bi = rC(ctx->opcode);
746 uint32_t mask;
a7812ae4 747 TCGv_i32 t0;
e1571908
AJ
748
749 l1 = gen_new_label();
750 l2 = gen_new_label();
751
752 mask = 1 << (3 - (bi & 0x03));
a7812ae4 753 t0 = tcg_temp_new_i32();
fea0c503
AJ
754 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
755 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
e1571908
AJ
756 if (rA(ctx->opcode) == 0)
757 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
758 else
759 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
760 tcg_gen_br(l2);
761 gen_set_label(l1);
762 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
763 gen_set_label(l2);
a7812ae4 764 tcg_temp_free_i32(t0);
e1571908
AJ
765}
766
fcfda20f
AJ
767/* cmpb: PowerPC 2.05 specification */
768static void gen_cmpb(DisasContext *ctx)
769{
770 gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
771 cpu_gpr[rB(ctx->opcode)]);
772}
773
79aceca5 774/*** Integer arithmetic ***/
79aceca5 775
636aa200
BS
776static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
777 TCGv arg1, TCGv arg2, int sub)
74637406 778{
ffe30937 779 TCGv t0 = tcg_temp_new();
79aceca5 780
8e7a6db9 781 tcg_gen_xor_tl(cpu_ov, arg0, arg2);
74637406 782 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
783 if (sub) {
784 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
785 } else {
786 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
787 }
788 tcg_temp_free(t0);
02765534 789 if (NARROW_MODE(ctx)) {
ffe30937
RH
790 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
791 }
ffe30937
RH
792 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
793 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
794}
795
74637406 796/* Common add function */
636aa200 797static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
798 TCGv arg2, bool add_ca, bool compute_ca,
799 bool compute_ov, bool compute_rc0)
74637406 800{
b5a73f8d 801 TCGv t0 = ret;
d9bce9d9 802
752d634e 803 if (compute_ca || compute_ov) {
146de60d 804 t0 = tcg_temp_new();
74637406 805 }
79aceca5 806
da91a00f 807 if (compute_ca) {
79482e5a 808 if (NARROW_MODE(ctx)) {
752d634e
RH
809 /* Caution: a non-obvious corner case of the spec is that we
810 must produce the *entire* 64-bit addition, but produce the
811 carry into bit 32. */
79482e5a 812 TCGv t1 = tcg_temp_new();
752d634e
RH
813 tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */
814 tcg_gen_add_tl(t0, arg1, arg2);
79482e5a
RH
815 if (add_ca) {
816 tcg_gen_add_tl(t0, t0, cpu_ca);
817 }
752d634e
RH
818 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */
819 tcg_temp_free(t1);
820 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
821 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
b5a73f8d 822 } else {
79482e5a
RH
823 TCGv zero = tcg_const_tl(0);
824 if (add_ca) {
825 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
826 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
827 } else {
828 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
829 }
830 tcg_temp_free(zero);
b5a73f8d 831 }
b5a73f8d
RH
832 } else {
833 tcg_gen_add_tl(t0, arg1, arg2);
834 if (add_ca) {
835 tcg_gen_add_tl(t0, t0, cpu_ca);
836 }
da91a00f 837 }
79aceca5 838
74637406
AJ
839 if (compute_ov) {
840 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
841 }
b5a73f8d 842 if (unlikely(compute_rc0)) {
74637406 843 gen_set_Rc0(ctx, t0);
b5a73f8d 844 }
74637406 845
a7812ae4 846 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
847 tcg_gen_mov_tl(ret, t0);
848 tcg_temp_free(t0);
849 }
39dd32ee 850}
74637406
AJ
851/* Add functions with two operands */
852#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 853static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
854{ \
855 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
856 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 857 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
858}
859/* Add functions with one operand and one immediate */
860#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
861 add_ca, compute_ca, compute_ov) \
b5a73f8d 862static void glue(gen_, name)(DisasContext *ctx) \
74637406 863{ \
b5a73f8d 864 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
865 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
866 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 867 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
868 tcg_temp_free(t0); \
869}
870
871/* add add. addo addo. */
872GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
873GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
874/* addc addc. addco addco. */
875GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
876GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
877/* adde adde. addeo addeo. */
878GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
879GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
880/* addme addme. addmeo addmeo. */
881GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
882GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
883/* addze addze. addzeo addzeo.*/
884GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
885GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
886/* addi */
99e300ef 887static void gen_addi(DisasContext *ctx)
d9bce9d9 888{
74637406
AJ
889 target_long simm = SIMM(ctx->opcode);
890
891 if (rA(ctx->opcode) == 0) {
892 /* li case */
893 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
894 } else {
b5a73f8d
RH
895 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
896 cpu_gpr[rA(ctx->opcode)], simm);
74637406 897 }
d9bce9d9 898}
74637406 899/* addic addic.*/
b5a73f8d 900static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 901{
b5a73f8d
RH
902 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
903 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
904 c, 0, 1, 0, compute_rc0);
905 tcg_temp_free(c);
d9bce9d9 906}
99e300ef
BS
907
908static void gen_addic(DisasContext *ctx)
d9bce9d9 909{
b5a73f8d 910 gen_op_addic(ctx, 0);
d9bce9d9 911}
e8eaa2c0
BS
912
913static void gen_addic_(DisasContext *ctx)
d9bce9d9 914{
b5a73f8d 915 gen_op_addic(ctx, 1);
d9bce9d9 916}
99e300ef 917
54623277 918/* addis */
99e300ef 919static void gen_addis(DisasContext *ctx)
d9bce9d9 920{
74637406
AJ
921 target_long simm = SIMM(ctx->opcode);
922
923 if (rA(ctx->opcode) == 0) {
924 /* lis case */
925 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
926 } else {
b5a73f8d
RH
927 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
928 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 929 }
d9bce9d9 930}
74637406 931
636aa200
BS
932static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
933 TCGv arg2, int sign, int compute_ov)
d9bce9d9 934{
2ef1b120
AJ
935 int l1 = gen_new_label();
936 int l2 = gen_new_label();
a7812ae4
PB
937 TCGv_i32 t0 = tcg_temp_local_new_i32();
938 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 939
2ef1b120
AJ
940 tcg_gen_trunc_tl_i32(t0, arg1);
941 tcg_gen_trunc_tl_i32(t1, arg2);
942 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 943 if (sign) {
2ef1b120
AJ
944 int l3 = gen_new_label();
945 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
946 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 947 gen_set_label(l3);
2ef1b120 948 tcg_gen_div_i32(t0, t0, t1);
74637406 949 } else {
2ef1b120 950 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
951 }
952 if (compute_ov) {
da91a00f 953 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
954 }
955 tcg_gen_br(l2);
956 gen_set_label(l1);
957 if (sign) {
2ef1b120 958 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
959 } else {
960 tcg_gen_movi_i32(t0, 0);
961 }
962 if (compute_ov) {
da91a00f
RH
963 tcg_gen_movi_tl(cpu_ov, 1);
964 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
965 }
966 gen_set_label(l2);
2ef1b120 967 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
968 tcg_temp_free_i32(t0);
969 tcg_temp_free_i32(t1);
74637406
AJ
970 if (unlikely(Rc(ctx->opcode) != 0))
971 gen_set_Rc0(ctx, ret);
d9bce9d9 972}
74637406
AJ
973/* Div functions */
974#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 975static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
976{ \
977 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
978 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
979 sign, compute_ov); \
980}
981/* divwu divwu. divwuo divwuo. */
982GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
983GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
984/* divw divw. divwo divwo. */
985GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
986GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
d9bce9d9 987#if defined(TARGET_PPC64)
636aa200
BS
988static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
989 TCGv arg2, int sign, int compute_ov)
d9bce9d9 990{
2ef1b120
AJ
991 int l1 = gen_new_label();
992 int l2 = gen_new_label();
74637406
AJ
993
994 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
995 if (sign) {
2ef1b120 996 int l3 = gen_new_label();
74637406
AJ
997 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
998 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
999 gen_set_label(l3);
74637406
AJ
1000 tcg_gen_div_i64(ret, arg1, arg2);
1001 } else {
1002 tcg_gen_divu_i64(ret, arg1, arg2);
1003 }
1004 if (compute_ov) {
da91a00f 1005 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
1006 }
1007 tcg_gen_br(l2);
1008 gen_set_label(l1);
1009 if (sign) {
1010 tcg_gen_sari_i64(ret, arg1, 63);
1011 } else {
1012 tcg_gen_movi_i64(ret, 0);
1013 }
1014 if (compute_ov) {
da91a00f
RH
1015 tcg_gen_movi_tl(cpu_ov, 1);
1016 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
1017 }
1018 gen_set_label(l2);
1019 if (unlikely(Rc(ctx->opcode) != 0))
1020 gen_set_Rc0(ctx, ret);
d9bce9d9 1021}
74637406 1022#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 1023static void glue(gen_, name)(DisasContext *ctx) \
74637406 1024{ \
2ef1b120
AJ
1025 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1026 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1027 sign, compute_ov); \
74637406
AJ
1028}
1029/* divwu divwu. divwuo divwuo. */
1030GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1031GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1032/* divw divw. divwo divwo. */
1033GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1034GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
d9bce9d9 1035#endif
74637406
AJ
1036
1037/* mulhw mulhw. */
99e300ef 1038static void gen_mulhw(DisasContext *ctx)
d9bce9d9 1039{
23ad1d5d
RH
1040 TCGv_i32 t0 = tcg_temp_new_i32();
1041 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1042
23ad1d5d
RH
1043 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1044 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1045 tcg_gen_muls2_i32(t0, t1, t0, t1);
1046 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1047 tcg_temp_free_i32(t0);
1048 tcg_temp_free_i32(t1);
74637406
AJ
1049 if (unlikely(Rc(ctx->opcode) != 0))
1050 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1051}
99e300ef 1052
54623277 1053/* mulhwu mulhwu. */
99e300ef 1054static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1055{
23ad1d5d
RH
1056 TCGv_i32 t0 = tcg_temp_new_i32();
1057 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1058
23ad1d5d
RH
1059 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1060 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1061 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1062 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1063 tcg_temp_free_i32(t0);
1064 tcg_temp_free_i32(t1);
74637406
AJ
1065 if (unlikely(Rc(ctx->opcode) != 0))
1066 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1067}
99e300ef 1068
54623277 1069/* mullw mullw. */
99e300ef 1070static void gen_mullw(DisasContext *ctx)
d9bce9d9 1071{
74637406
AJ
1072 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1073 cpu_gpr[rB(ctx->opcode)]);
1e4c090f 1074 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
74637406
AJ
1075 if (unlikely(Rc(ctx->opcode) != 0))
1076 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1077}
99e300ef 1078
54623277 1079/* mullwo mullwo. */
99e300ef 1080static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1081{
e4a2c846
RH
1082 TCGv_i32 t0 = tcg_temp_new_i32();
1083 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1084
e4a2c846
RH
1085 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1086 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1087 tcg_gen_muls2_i32(t0, t1, t0, t1);
1088 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1089
1090 tcg_gen_sari_i32(t0, t0, 31);
1091 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1092 tcg_gen_extu_i32_tl(cpu_ov, t0);
1093 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1094
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/* mulli */
99e300ef 1102static void gen_mulli(DisasContext *ctx)
d9bce9d9 1103{
74637406
AJ
1104 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1105 SIMM(ctx->opcode));
d9bce9d9 1106}
23ad1d5d 1107
d9bce9d9 1108#if defined(TARGET_PPC64)
74637406 1109/* mulhd mulhd. */
23ad1d5d
RH
1110static void gen_mulhd(DisasContext *ctx)
1111{
1112 TCGv lo = tcg_temp_new();
1113 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1114 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1115 tcg_temp_free(lo);
1116 if (unlikely(Rc(ctx->opcode) != 0)) {
1117 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1118 }
1119}
1120
74637406 1121/* mulhdu mulhdu. */
23ad1d5d
RH
1122static void gen_mulhdu(DisasContext *ctx)
1123{
1124 TCGv lo = tcg_temp_new();
1125 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1126 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1127 tcg_temp_free(lo);
1128 if (unlikely(Rc(ctx->opcode) != 0)) {
1129 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1130 }
1131}
99e300ef 1132
54623277 1133/* mulld mulld. */
99e300ef 1134static void gen_mulld(DisasContext *ctx)
d9bce9d9 1135{
74637406
AJ
1136 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1137 cpu_gpr[rB(ctx->opcode)]);
1138 if (unlikely(Rc(ctx->opcode) != 0))
1139 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1140}
d15f74fb 1141
74637406 1142/* mulldo mulldo. */
d15f74fb
BS
1143static void gen_mulldo(DisasContext *ctx)
1144{
1145 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1146 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1147 if (unlikely(Rc(ctx->opcode) != 0)) {
1148 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1149 }
1150}
d9bce9d9 1151#endif
74637406 1152
74637406 1153/* Common subf function */
636aa200 1154static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1155 TCGv arg2, bool add_ca, bool compute_ca,
1156 bool compute_ov, bool compute_rc0)
79aceca5 1157{
b5a73f8d 1158 TCGv t0 = ret;
79aceca5 1159
752d634e 1160 if (compute_ca || compute_ov) {
b5a73f8d 1161 t0 = tcg_temp_new();
da91a00f 1162 }
74637406 1163
79482e5a
RH
1164 if (compute_ca) {
1165 /* dest = ~arg1 + arg2 [+ ca]. */
1166 if (NARROW_MODE(ctx)) {
752d634e
RH
1167 /* Caution: a non-obvious corner case of the spec is that we
1168 must produce the *entire* 64-bit addition, but produce the
1169 carry into bit 32. */
79482e5a 1170 TCGv inv1 = tcg_temp_new();
752d634e 1171 TCGv t1 = tcg_temp_new();
79482e5a 1172 tcg_gen_not_tl(inv1, arg1);
79482e5a 1173 if (add_ca) {
752d634e 1174 tcg_gen_add_tl(t0, arg2, cpu_ca);
79482e5a 1175 } else {
752d634e 1176 tcg_gen_addi_tl(t0, arg2, 1);
79482e5a 1177 }
752d634e 1178 tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */
79482e5a 1179 tcg_gen_add_tl(t0, t0, inv1);
752d634e
RH
1180 tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */
1181 tcg_temp_free(t1);
1182 tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */
1183 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
79482e5a 1184 } else if (add_ca) {
08f4a0f7
RH
1185 TCGv zero, inv1 = tcg_temp_new();
1186 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1187 zero = tcg_const_tl(0);
1188 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1189 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1190 tcg_temp_free(zero);
08f4a0f7 1191 tcg_temp_free(inv1);
b5a73f8d 1192 } else {
79482e5a 1193 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
b5a73f8d 1194 tcg_gen_sub_tl(t0, arg2, arg1);
b5a73f8d 1195 }
79482e5a
RH
1196 } else if (add_ca) {
1197 /* Since we're ignoring carry-out, we can simplify the
1198 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1199 tcg_gen_sub_tl(t0, arg2, arg1);
1200 tcg_gen_add_tl(t0, t0, cpu_ca);
1201 tcg_gen_subi_tl(t0, t0, 1);
79aceca5 1202 } else {
b5a73f8d 1203 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1204 }
b5a73f8d 1205
74637406
AJ
1206 if (compute_ov) {
1207 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1208 }
b5a73f8d 1209 if (unlikely(compute_rc0)) {
74637406 1210 gen_set_Rc0(ctx, t0);
b5a73f8d 1211 }
74637406 1212
a7812ae4 1213 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1214 tcg_gen_mov_tl(ret, t0);
1215 tcg_temp_free(t0);
79aceca5 1216 }
79aceca5 1217}
74637406
AJ
1218/* Sub functions with Two operands functions */
1219#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1220static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1221{ \
1222 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1223 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1224 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1225}
1226/* Sub functions with one operand and one immediate */
1227#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1228 add_ca, compute_ca, compute_ov) \
b5a73f8d 1229static void glue(gen_, name)(DisasContext *ctx) \
74637406 1230{ \
b5a73f8d 1231 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1232 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1233 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1234 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1235 tcg_temp_free(t0); \
1236}
1237/* subf subf. subfo subfo. */
1238GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1239GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1240/* subfc subfc. subfco subfco. */
1241GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1242GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1243/* subfe subfe. subfeo subfo. */
1244GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1245GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1246/* subfme subfme. subfmeo subfmeo. */
1247GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1248GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1249/* subfze subfze. subfzeo subfzeo.*/
1250GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1251GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1252
54623277 1253/* subfic */
99e300ef 1254static void gen_subfic(DisasContext *ctx)
79aceca5 1255{
b5a73f8d
RH
1256 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1257 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1258 c, 0, 1, 0, 0);
1259 tcg_temp_free(c);
79aceca5
FB
1260}
1261
fd3f0081
RH
1262/* neg neg. nego nego. */
1263static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1264{
1265 TCGv zero = tcg_const_tl(0);
1266 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1267 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1268 tcg_temp_free(zero);
1269}
1270
1271static void gen_neg(DisasContext *ctx)
1272{
1273 gen_op_arith_neg(ctx, 0);
1274}
1275
1276static void gen_nego(DisasContext *ctx)
1277{
1278 gen_op_arith_neg(ctx, 1);
1279}
1280
79aceca5 1281/*** Integer logical ***/
26d67362 1282#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1283static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1284{ \
26d67362
AJ
1285 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1286 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1287 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1288 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1289}
79aceca5 1290
26d67362 1291#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1292static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1293{ \
26d67362 1294 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1295 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1296 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1297}
1298
1299/* and & and. */
26d67362 1300GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1301/* andc & andc. */
26d67362 1302GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1303
54623277 1304/* andi. */
e8eaa2c0 1305static void gen_andi_(DisasContext *ctx)
79aceca5 1306{
26d67362
AJ
1307 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1308 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1309}
e8eaa2c0 1310
54623277 1311/* andis. */
e8eaa2c0 1312static void gen_andis_(DisasContext *ctx)
79aceca5 1313{
26d67362
AJ
1314 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1315 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1316}
99e300ef 1317
54623277 1318/* cntlzw */
99e300ef 1319static void gen_cntlzw(DisasContext *ctx)
26d67362 1320{
a7812ae4 1321 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1322 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1323 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1324}
79aceca5 1325/* eqv & eqv. */
26d67362 1326GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1327/* extsb & extsb. */
26d67362 1328GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1329/* extsh & extsh. */
26d67362 1330GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1331/* nand & nand. */
26d67362 1332GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1333/* nor & nor. */
26d67362 1334GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1335
54623277 1336/* or & or. */
99e300ef 1337static void gen_or(DisasContext *ctx)
9a64fbe4 1338{
76a66253
JM
1339 int rs, ra, rb;
1340
1341 rs = rS(ctx->opcode);
1342 ra = rA(ctx->opcode);
1343 rb = rB(ctx->opcode);
1344 /* Optimisation for mr. ri case */
1345 if (rs != ra || rs != rb) {
26d67362
AJ
1346 if (rs != rb)
1347 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1348 else
1349 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1350 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1351 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1352 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1353 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1354#if defined(TARGET_PPC64)
1355 } else {
26d67362
AJ
1356 int prio = 0;
1357
c80f84e3
JM
1358 switch (rs) {
1359 case 1:
1360 /* Set process priority to low */
26d67362 1361 prio = 2;
c80f84e3
JM
1362 break;
1363 case 6:
1364 /* Set process priority to medium-low */
26d67362 1365 prio = 3;
c80f84e3
JM
1366 break;
1367 case 2:
1368 /* Set process priority to normal */
26d67362 1369 prio = 4;
c80f84e3 1370 break;
be147d08
JM
1371#if !defined(CONFIG_USER_ONLY)
1372 case 31:
76db3ba4 1373 if (ctx->mem_idx > 0) {
be147d08 1374 /* Set process priority to very low */
26d67362 1375 prio = 1;
be147d08
JM
1376 }
1377 break;
1378 case 5:
76db3ba4 1379 if (ctx->mem_idx > 0) {
be147d08 1380 /* Set process priority to medium-hight */
26d67362 1381 prio = 5;
be147d08
JM
1382 }
1383 break;
1384 case 3:
76db3ba4 1385 if (ctx->mem_idx > 0) {
be147d08 1386 /* Set process priority to high */
26d67362 1387 prio = 6;
be147d08
JM
1388 }
1389 break;
be147d08 1390 case 7:
76db3ba4 1391 if (ctx->mem_idx > 1) {
be147d08 1392 /* Set process priority to very high */
26d67362 1393 prio = 7;
be147d08
JM
1394 }
1395 break;
be147d08 1396#endif
c80f84e3
JM
1397 default:
1398 /* nop */
1399 break;
1400 }
26d67362 1401 if (prio) {
a7812ae4 1402 TCGv t0 = tcg_temp_new();
54cdcae6 1403 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1404 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1405 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1406 gen_store_spr(SPR_PPR, t0);
ea363694 1407 tcg_temp_free(t0);
26d67362 1408 }
c80f84e3 1409#endif
9a64fbe4 1410 }
9a64fbe4 1411}
79aceca5 1412/* orc & orc. */
26d67362 1413GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1414
54623277 1415/* xor & xor. */
99e300ef 1416static void gen_xor(DisasContext *ctx)
9a64fbe4 1417{
9a64fbe4 1418 /* Optimisation for "set to zero" case */
26d67362 1419 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1420 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1421 else
1422 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1423 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1424 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1425}
99e300ef 1426
54623277 1427/* ori */
99e300ef 1428static void gen_ori(DisasContext *ctx)
79aceca5 1429{
76a66253 1430 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1431
9a64fbe4
FB
1432 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1433 /* NOP */
76a66253 1434 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1435 return;
76a66253 1436 }
26d67362 1437 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1438}
99e300ef 1439
54623277 1440/* oris */
99e300ef 1441static void gen_oris(DisasContext *ctx)
79aceca5 1442{
76a66253 1443 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1444
9a64fbe4
FB
1445 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1446 /* NOP */
1447 return;
76a66253 1448 }
26d67362 1449 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1450}
99e300ef 1451
54623277 1452/* xori */
99e300ef 1453static void gen_xori(DisasContext *ctx)
79aceca5 1454{
76a66253 1455 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1456
1457 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1458 /* NOP */
1459 return;
1460 }
26d67362 1461 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1462}
99e300ef 1463
54623277 1464/* xoris */
99e300ef 1465static void gen_xoris(DisasContext *ctx)
79aceca5 1466{
76a66253 1467 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1468
1469 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1470 /* NOP */
1471 return;
1472 }
26d67362 1473 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1474}
99e300ef 1475
54623277 1476/* popcntb : PowerPC 2.03 specification */
99e300ef 1477static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1478{
eaabeef2
DG
1479 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1480}
1481
1482static void gen_popcntw(DisasContext *ctx)
1483{
1484 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1485}
1486
d9bce9d9 1487#if defined(TARGET_PPC64)
eaabeef2
DG
1488/* popcntd: PowerPC 2.06 specification */
1489static void gen_popcntd(DisasContext *ctx)
1490{
1491 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1492}
eaabeef2 1493#endif
d9bce9d9 1494
725bcec2
AJ
1495/* prtyw: PowerPC 2.05 specification */
1496static void gen_prtyw(DisasContext *ctx)
1497{
1498 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1499 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1500 TCGv t0 = tcg_temp_new();
1501 tcg_gen_shri_tl(t0, rs, 16);
1502 tcg_gen_xor_tl(ra, rs, t0);
1503 tcg_gen_shri_tl(t0, ra, 8);
1504 tcg_gen_xor_tl(ra, ra, t0);
1505 tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL);
1506 tcg_temp_free(t0);
1507}
1508
1509#if defined(TARGET_PPC64)
1510/* prtyd: PowerPC 2.05 specification */
1511static void gen_prtyd(DisasContext *ctx)
1512{
1513 TCGv ra = cpu_gpr[rA(ctx->opcode)];
1514 TCGv rs = cpu_gpr[rS(ctx->opcode)];
1515 TCGv t0 = tcg_temp_new();
1516 tcg_gen_shri_tl(t0, rs, 32);
1517 tcg_gen_xor_tl(ra, rs, t0);
1518 tcg_gen_shri_tl(t0, ra, 16);
1519 tcg_gen_xor_tl(ra, ra, t0);
1520 tcg_gen_shri_tl(t0, ra, 8);
1521 tcg_gen_xor_tl(ra, ra, t0);
1522 tcg_gen_andi_tl(ra, ra, 1);
1523 tcg_temp_free(t0);
1524}
1525#endif
1526
d9bce9d9
JM
1527#if defined(TARGET_PPC64)
1528/* extsw & extsw. */
26d67362 1529GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1530
54623277 1531/* cntlzd */
99e300ef 1532static void gen_cntlzd(DisasContext *ctx)
26d67362 1533{
a7812ae4 1534 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1535 if (unlikely(Rc(ctx->opcode) != 0))
1536 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1537}
d9bce9d9
JM
1538#endif
1539
79aceca5 1540/*** Integer rotate ***/
99e300ef 1541
54623277 1542/* rlwimi & rlwimi. */
99e300ef 1543static void gen_rlwimi(DisasContext *ctx)
79aceca5 1544{
76a66253 1545 uint32_t mb, me, sh;
79aceca5
FB
1546
1547 mb = MB(ctx->opcode);
1548 me = ME(ctx->opcode);
76a66253 1549 sh = SH(ctx->opcode);
d03ef511
AJ
1550 if (likely(sh == 0 && mb == 0 && me == 31)) {
1551 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1552 } else {
d03ef511 1553 target_ulong mask;
a7812ae4
PB
1554 TCGv t1;
1555 TCGv t0 = tcg_temp_new();
54843a58 1556#if defined(TARGET_PPC64)
a7812ae4
PB
1557 TCGv_i32 t2 = tcg_temp_new_i32();
1558 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1559 tcg_gen_rotli_i32(t2, t2, sh);
1560 tcg_gen_extu_i32_i64(t0, t2);
1561 tcg_temp_free_i32(t2);
54843a58
AJ
1562#else
1563 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1564#endif
76a66253 1565#if defined(TARGET_PPC64)
d03ef511
AJ
1566 mb += 32;
1567 me += 32;
76a66253 1568#endif
d03ef511 1569 mask = MASK(mb, me);
a7812ae4 1570 t1 = tcg_temp_new();
d03ef511
AJ
1571 tcg_gen_andi_tl(t0, t0, mask);
1572 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1573 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1574 tcg_temp_free(t0);
1575 tcg_temp_free(t1);
1576 }
76a66253 1577 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1578 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1579}
99e300ef 1580
54623277 1581/* rlwinm & rlwinm. */
99e300ef 1582static void gen_rlwinm(DisasContext *ctx)
79aceca5
FB
1583{
1584 uint32_t mb, me, sh;
3b46e624 1585
79aceca5
FB
1586 sh = SH(ctx->opcode);
1587 mb = MB(ctx->opcode);
1588 me = ME(ctx->opcode);
d03ef511
AJ
1589
1590 if (likely(mb == 0 && me == (31 - sh))) {
1591 if (likely(sh == 0)) {
1592 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1593 } else {
a7812ae4 1594 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1595 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1596 tcg_gen_shli_tl(t0, t0, sh);
1597 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1598 tcg_temp_free(t0);
79aceca5 1599 }
d03ef511 1600 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
a7812ae4 1601 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1602 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1603 tcg_gen_shri_tl(t0, t0, mb);
1604 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1605 tcg_temp_free(t0);
1606 } else {
a7812ae4 1607 TCGv t0 = tcg_temp_new();
54843a58 1608#if defined(TARGET_PPC64)
a7812ae4 1609 TCGv_i32 t1 = tcg_temp_new_i32();
54843a58
AJ
1610 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1611 tcg_gen_rotli_i32(t1, t1, sh);
1612 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4 1613 tcg_temp_free_i32(t1);
54843a58
AJ
1614#else
1615 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1616#endif
76a66253 1617#if defined(TARGET_PPC64)
d03ef511
AJ
1618 mb += 32;
1619 me += 32;
76a66253 1620#endif
d03ef511
AJ
1621 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1622 tcg_temp_free(t0);
1623 }
76a66253 1624 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1625 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1626}
99e300ef 1627
54623277 1628/* rlwnm & rlwnm. */
99e300ef 1629static void gen_rlwnm(DisasContext *ctx)
79aceca5
FB
1630{
1631 uint32_t mb, me;
54843a58
AJ
1632 TCGv t0;
1633#if defined(TARGET_PPC64)
a7812ae4 1634 TCGv_i32 t1, t2;
54843a58 1635#endif
79aceca5
FB
1636
1637 mb = MB(ctx->opcode);
1638 me = ME(ctx->opcode);
a7812ae4 1639 t0 = tcg_temp_new();
d03ef511 1640 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
54843a58 1641#if defined(TARGET_PPC64)
a7812ae4
PB
1642 t1 = tcg_temp_new_i32();
1643 t2 = tcg_temp_new_i32();
54843a58
AJ
1644 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1645 tcg_gen_trunc_i64_i32(t2, t0);
1646 tcg_gen_rotl_i32(t1, t1, t2);
1647 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4
PB
1648 tcg_temp_free_i32(t1);
1649 tcg_temp_free_i32(t2);
54843a58
AJ
1650#else
1651 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1652#endif
76a66253
JM
1653 if (unlikely(mb != 0 || me != 31)) {
1654#if defined(TARGET_PPC64)
1655 mb += 32;
1656 me += 32;
1657#endif
54843a58 1658 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
d03ef511 1659 } else {
54843a58 1660 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
79aceca5 1661 }
54843a58 1662 tcg_temp_free(t0);
76a66253 1663 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1664 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5
FB
1665}
1666
d9bce9d9
JM
1667#if defined(TARGET_PPC64)
1668#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1669static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1670{ \
1671 gen_##name(ctx, 0); \
1672} \
e8eaa2c0
BS
1673 \
1674static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1675{ \
1676 gen_##name(ctx, 1); \
1677}
1678#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1679static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1680{ \
1681 gen_##name(ctx, 0, 0); \
1682} \
e8eaa2c0
BS
1683 \
1684static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1685{ \
1686 gen_##name(ctx, 0, 1); \
1687} \
e8eaa2c0
BS
1688 \
1689static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1690{ \
1691 gen_##name(ctx, 1, 0); \
1692} \
e8eaa2c0
BS
1693 \
1694static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1695{ \
1696 gen_##name(ctx, 1, 1); \
1697}
51789c41 1698
636aa200
BS
1699static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1700 uint32_t sh)
51789c41 1701{
d03ef511
AJ
1702 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1703 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1704 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1705 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1706 } else {
a7812ae4 1707 TCGv t0 = tcg_temp_new();
54843a58 1708 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
d03ef511 1709 if (likely(mb == 0 && me == 63)) {
54843a58 1710 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
d03ef511
AJ
1711 } else {
1712 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
51789c41 1713 }
d03ef511 1714 tcg_temp_free(t0);
51789c41 1715 }
51789c41 1716 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1717 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
51789c41 1718}
d9bce9d9 1719/* rldicl - rldicl. */
636aa200 1720static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1721{
51789c41 1722 uint32_t sh, mb;
d9bce9d9 1723
9d53c753
JM
1724 sh = SH(ctx->opcode) | (shn << 5);
1725 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1726 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1727}
51789c41 1728GEN_PPC64_R4(rldicl, 0x1E, 0x00);
d9bce9d9 1729/* rldicr - rldicr. */
636aa200 1730static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1731{
51789c41 1732 uint32_t sh, me;
d9bce9d9 1733
9d53c753
JM
1734 sh = SH(ctx->opcode) | (shn << 5);
1735 me = MB(ctx->opcode) | (men << 5);
51789c41 1736 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1737}
51789c41 1738GEN_PPC64_R4(rldicr, 0x1E, 0x02);
d9bce9d9 1739/* rldic - rldic. */
636aa200 1740static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1741{
51789c41 1742 uint32_t sh, mb;
d9bce9d9 1743
9d53c753
JM
1744 sh = SH(ctx->opcode) | (shn << 5);
1745 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1746 gen_rldinm(ctx, mb, 63 - sh, sh);
1747}
1748GEN_PPC64_R4(rldic, 0x1E, 0x04);
1749
636aa200 1750static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
51789c41 1751{
54843a58 1752 TCGv t0;
d03ef511 1753
a7812ae4 1754 t0 = tcg_temp_new();
d03ef511 1755 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
54843a58 1756 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
51789c41 1757 if (unlikely(mb != 0 || me != 63)) {
54843a58
AJ
1758 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1759 } else {
1760 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1761 }
1762 tcg_temp_free(t0);
51789c41 1763 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1764 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1765}
51789c41 1766
d9bce9d9 1767/* rldcl - rldcl. */
636aa200 1768static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1769{
51789c41 1770 uint32_t mb;
d9bce9d9 1771
9d53c753 1772 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1773 gen_rldnm(ctx, mb, 63);
d9bce9d9 1774}
36081602 1775GEN_PPC64_R2(rldcl, 0x1E, 0x08);
d9bce9d9 1776/* rldcr - rldcr. */
636aa200 1777static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1778{
51789c41 1779 uint32_t me;
d9bce9d9 1780
9d53c753 1781 me = MB(ctx->opcode) | (men << 5);
51789c41 1782 gen_rldnm(ctx, 0, me);
d9bce9d9 1783}
36081602 1784GEN_PPC64_R2(rldcr, 0x1E, 0x09);
d9bce9d9 1785/* rldimi - rldimi. */
636aa200 1786static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1787{
271a916e 1788 uint32_t sh, mb, me;
d9bce9d9 1789
9d53c753
JM
1790 sh = SH(ctx->opcode) | (shn << 5);
1791 mb = MB(ctx->opcode) | (mbn << 5);
271a916e 1792 me = 63 - sh;
d03ef511
AJ
1793 if (unlikely(sh == 0 && mb == 0)) {
1794 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1795 } else {
1796 TCGv t0, t1;
1797 target_ulong mask;
1798
a7812ae4 1799 t0 = tcg_temp_new();
54843a58 1800 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
a7812ae4 1801 t1 = tcg_temp_new();
d03ef511
AJ
1802 mask = MASK(mb, me);
1803 tcg_gen_andi_tl(t0, t0, mask);
1804 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1805 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1806 tcg_temp_free(t0);
1807 tcg_temp_free(t1);
51789c41 1808 }
51789c41 1809 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1810 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1811}
36081602 1812GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1813#endif
1814
79aceca5 1815/*** Integer shift ***/
99e300ef 1816
54623277 1817/* slw & slw. */
99e300ef 1818static void gen_slw(DisasContext *ctx)
26d67362 1819{
7fd6bf7d 1820 TCGv t0, t1;
26d67362 1821
7fd6bf7d
AJ
1822 t0 = tcg_temp_new();
1823 /* AND rS with a mask that is 0 when rB >= 0x20 */
1824#if defined(TARGET_PPC64)
1825 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1826 tcg_gen_sari_tl(t0, t0, 0x3f);
1827#else
1828 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1829 tcg_gen_sari_tl(t0, t0, 0x1f);
1830#endif
1831 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1832 t1 = tcg_temp_new();
1833 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1834 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1835 tcg_temp_free(t1);
fea0c503 1836 tcg_temp_free(t0);
7fd6bf7d 1837 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1838 if (unlikely(Rc(ctx->opcode) != 0))
1839 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1840}
99e300ef 1841
54623277 1842/* sraw & sraw. */
99e300ef 1843static void gen_sraw(DisasContext *ctx)
26d67362 1844{
d15f74fb 1845 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1846 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1847 if (unlikely(Rc(ctx->opcode) != 0))
1848 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1849}
99e300ef 1850
54623277 1851/* srawi & srawi. */
99e300ef 1852static void gen_srawi(DisasContext *ctx)
79aceca5 1853{
26d67362 1854 int sh = SH(ctx->opcode);
ba4af3e4
RH
1855 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1856 TCGv src = cpu_gpr[rS(ctx->opcode)];
1857 if (sh == 0) {
1858 tcg_gen_mov_tl(dst, src);
da91a00f 1859 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1860 } else {
ba4af3e4
RH
1861 TCGv t0;
1862 tcg_gen_ext32s_tl(dst, src);
1863 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1864 t0 = tcg_temp_new();
1865 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1866 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1867 tcg_temp_free(t0);
1868 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1869 tcg_gen_sari_tl(dst, dst, sh);
1870 }
1871 if (unlikely(Rc(ctx->opcode) != 0)) {
1872 gen_set_Rc0(ctx, dst);
d9bce9d9 1873 }
79aceca5 1874}
99e300ef 1875
54623277 1876/* srw & srw. */
99e300ef 1877static void gen_srw(DisasContext *ctx)
26d67362 1878{
fea0c503 1879 TCGv t0, t1;
d9bce9d9 1880
7fd6bf7d
AJ
1881 t0 = tcg_temp_new();
1882 /* AND rS with a mask that is 0 when rB >= 0x20 */
1883#if defined(TARGET_PPC64)
1884 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1885 tcg_gen_sari_tl(t0, t0, 0x3f);
1886#else
1887 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1888 tcg_gen_sari_tl(t0, t0, 0x1f);
1889#endif
1890 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1891 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1892 t1 = tcg_temp_new();
7fd6bf7d
AJ
1893 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1894 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1895 tcg_temp_free(t1);
fea0c503 1896 tcg_temp_free(t0);
26d67362
AJ
1897 if (unlikely(Rc(ctx->opcode) != 0))
1898 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1899}
54623277 1900
d9bce9d9
JM
1901#if defined(TARGET_PPC64)
1902/* sld & sld. */
99e300ef 1903static void gen_sld(DisasContext *ctx)
26d67362 1904{
7fd6bf7d 1905 TCGv t0, t1;
26d67362 1906
7fd6bf7d
AJ
1907 t0 = tcg_temp_new();
1908 /* AND rS with a mask that is 0 when rB >= 0x40 */
1909 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1910 tcg_gen_sari_tl(t0, t0, 0x3f);
1911 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1912 t1 = tcg_temp_new();
1913 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1914 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1915 tcg_temp_free(t1);
fea0c503 1916 tcg_temp_free(t0);
26d67362
AJ
1917 if (unlikely(Rc(ctx->opcode) != 0))
1918 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1919}
99e300ef 1920
54623277 1921/* srad & srad. */
99e300ef 1922static void gen_srad(DisasContext *ctx)
26d67362 1923{
d15f74fb 1924 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1925 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1926 if (unlikely(Rc(ctx->opcode) != 0))
1927 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1928}
d9bce9d9 1929/* sradi & sradi. */
636aa200 1930static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1931{
26d67362 1932 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
1933 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1934 TCGv src = cpu_gpr[rS(ctx->opcode)];
1935 if (sh == 0) {
1936 tcg_gen_mov_tl(dst, src);
da91a00f 1937 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1938 } else {
ba4af3e4
RH
1939 TCGv t0;
1940 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1941 t0 = tcg_temp_new();
1942 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1943 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1944 tcg_temp_free(t0);
1945 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1946 tcg_gen_sari_tl(dst, src, sh);
1947 }
1948 if (unlikely(Rc(ctx->opcode) != 0)) {
1949 gen_set_Rc0(ctx, dst);
d9bce9d9 1950 }
d9bce9d9 1951}
e8eaa2c0
BS
1952
1953static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
1954{
1955 gen_sradi(ctx, 0);
1956}
e8eaa2c0
BS
1957
1958static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
1959{
1960 gen_sradi(ctx, 1);
1961}
99e300ef 1962
54623277 1963/* srd & srd. */
99e300ef 1964static void gen_srd(DisasContext *ctx)
26d67362 1965{
7fd6bf7d 1966 TCGv t0, t1;
26d67362 1967
7fd6bf7d
AJ
1968 t0 = tcg_temp_new();
1969 /* AND rS with a mask that is 0 when rB >= 0x40 */
1970 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1971 tcg_gen_sari_tl(t0, t0, 0x3f);
1972 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1973 t1 = tcg_temp_new();
1974 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1975 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1976 tcg_temp_free(t1);
fea0c503 1977 tcg_temp_free(t0);
26d67362
AJ
1978 if (unlikely(Rc(ctx->opcode) != 0))
1979 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1980}
d9bce9d9 1981#endif
79aceca5
FB
1982
1983/*** Floating-Point arithmetic ***/
7c58044c 1984#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 1985static void gen_f##name(DisasContext *ctx) \
9a64fbe4 1986{ \
76a66253 1987 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 1988 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
1989 return; \
1990 } \
eb44b959
AJ
1991 /* NIP cannot be restored if the memory exception comes from an helper */ \
1992 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 1993 gen_reset_fpstatus(); \
8e703949
BS
1994 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1995 cpu_fpr[rA(ctx->opcode)], \
af12906f 1996 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 1997 if (isfloat) { \
8e703949
BS
1998 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1999 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2000 } \
af12906f
AJ
2001 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2002 Rc(ctx->opcode) != 0); \
9a64fbe4
FB
2003}
2004
7c58044c
JM
2005#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2006_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2007_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 2008
7c58044c 2009#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2010static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2011{ \
76a66253 2012 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2013 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2014 return; \
2015 } \
eb44b959
AJ
2016 /* NIP cannot be restored if the memory exception comes from an helper */ \
2017 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2018 gen_reset_fpstatus(); \
8e703949
BS
2019 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2020 cpu_fpr[rA(ctx->opcode)], \
af12906f 2021 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 2022 if (isfloat) { \
8e703949
BS
2023 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2024 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2025 } \
af12906f
AJ
2026 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2027 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2028}
7c58044c
JM
2029#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2030_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2031_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2032
7c58044c 2033#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 2034static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2035{ \
76a66253 2036 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2037 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2038 return; \
2039 } \
eb44b959
AJ
2040 /* NIP cannot be restored if the memory exception comes from an helper */ \
2041 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2042 gen_reset_fpstatus(); \
8e703949
BS
2043 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2044 cpu_fpr[rA(ctx->opcode)], \
2045 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 2046 if (isfloat) { \
8e703949
BS
2047 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2048 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 2049 } \
af12906f
AJ
2050 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2051 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 2052}
7c58044c
JM
2053#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2054_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2055_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 2056
7c58044c 2057#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 2058static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2059{ \
76a66253 2060 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2061 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2062 return; \
2063 } \
eb44b959
AJ
2064 /* NIP cannot be restored if the memory exception comes from an helper */ \
2065 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2066 gen_reset_fpstatus(); \
8e703949
BS
2067 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2068 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2069 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2070 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2071}
2072
7c58044c 2073#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 2074static void gen_f##name(DisasContext *ctx) \
9a64fbe4 2075{ \
76a66253 2076 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 2077 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
2078 return; \
2079 } \
eb44b959
AJ
2080 /* NIP cannot be restored if the memory exception comes from an helper */ \
2081 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 2082 gen_reset_fpstatus(); \
8e703949
BS
2083 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2084 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
2085 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2086 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
2087}
2088
9a64fbe4 2089/* fadd - fadds */
7c58044c 2090GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2091/* fdiv - fdivs */
7c58044c 2092GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2093/* fmul - fmuls */
7c58044c 2094GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2095
d7e4b87e 2096/* fre */
7c58044c 2097GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2098
a750fc0b 2099/* fres */
7c58044c 2100GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2101
a750fc0b 2102/* frsqrte */
7c58044c
JM
2103GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2104
2105/* frsqrtes */
99e300ef 2106static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2107{
af12906f 2108 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2109 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2110 return;
2111 }
eb44b959
AJ
2112 /* NIP cannot be restored if the memory exception comes from an helper */
2113 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2114 gen_reset_fpstatus();
8e703949
BS
2115 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2116 cpu_fpr[rB(ctx->opcode)]);
2117 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2118 cpu_fpr[rD(ctx->opcode)]);
af12906f 2119 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
7c58044c 2120}
79aceca5 2121
a750fc0b 2122/* fsel */
7c58044c 2123_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2124/* fsub - fsubs */
7c58044c 2125GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2126/* Optional: */
99e300ef 2127
54623277 2128/* fsqrt */
99e300ef 2129static void gen_fsqrt(DisasContext *ctx)
c7d344af 2130{
76a66253 2131 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2132 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2133 return;
2134 }
eb44b959
AJ
2135 /* NIP cannot be restored if the memory exception comes from an helper */
2136 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2137 gen_reset_fpstatus();
8e703949
BS
2138 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2139 cpu_fpr[rB(ctx->opcode)]);
af12906f 2140 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
c7d344af 2141}
79aceca5 2142
99e300ef 2143static void gen_fsqrts(DisasContext *ctx)
79aceca5 2144{
76a66253 2145 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2146 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2147 return;
2148 }
eb44b959
AJ
2149 /* NIP cannot be restored if the memory exception comes from an helper */
2150 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2151 gen_reset_fpstatus();
8e703949
BS
2152 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2153 cpu_fpr[rB(ctx->opcode)]);
2154 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2155 cpu_fpr[rD(ctx->opcode)]);
af12906f 2156 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
79aceca5
FB
2157}
2158
2159/*** Floating-Point multiply-and-add ***/
4ecc3190 2160/* fmadd - fmadds */
7c58044c 2161GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2162/* fmsub - fmsubs */
7c58044c 2163GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2164/* fnmadd - fnmadds */
7c58044c 2165GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2166/* fnmsub - fnmsubs */
7c58044c 2167GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2168
2169/*** Floating-Point round & convert ***/
2170/* fctiw */
7c58044c 2171GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
79aceca5 2172/* fctiwz */
7c58044c 2173GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
79aceca5 2174/* frsp */
7c58044c 2175GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db
JM
2176#if defined(TARGET_PPC64)
2177/* fcfid */
7c58044c 2178GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
426613db 2179/* fctid */
7c58044c 2180GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
426613db 2181/* fctidz */
7c58044c 2182GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
426613db 2183#endif
79aceca5 2184
d7e4b87e 2185/* frin */
7c58044c 2186GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2187/* friz */
7c58044c 2188GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2189/* frip */
7c58044c 2190GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2191/* frim */
7c58044c 2192GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2193
79aceca5 2194/*** Floating-Point compare ***/
99e300ef 2195
54623277 2196/* fcmpo */
99e300ef 2197static void gen_fcmpo(DisasContext *ctx)
79aceca5 2198{
330c483b 2199 TCGv_i32 crf;
76a66253 2200 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2201 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2202 return;
2203 }
eb44b959
AJ
2204 /* NIP cannot be restored if the memory exception comes from an helper */
2205 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2206 gen_reset_fpstatus();
9a819377 2207 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2208 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2209 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2210 tcg_temp_free_i32(crf);
8e703949 2211 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2212}
2213
2214/* fcmpu */
99e300ef 2215static void gen_fcmpu(DisasContext *ctx)
79aceca5 2216{
330c483b 2217 TCGv_i32 crf;
76a66253 2218 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2219 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2220 return;
2221 }
eb44b959
AJ
2222 /* NIP cannot be restored if the memory exception comes from an helper */
2223 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2224 gen_reset_fpstatus();
9a819377 2225 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2226 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2227 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2228 tcg_temp_free_i32(crf);
8e703949 2229 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2230}
2231
9a64fbe4
FB
2232/*** Floating-point move ***/
2233/* fabs */
7c58044c 2234/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2235static void gen_fabs(DisasContext *ctx)
2236{
2237 if (unlikely(!ctx->fpu_enabled)) {
2238 gen_exception(ctx, POWERPC_EXCP_FPU);
2239 return;
2240 }
2241 tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2242 ~(1ULL << 63));
2243 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2244}
9a64fbe4
FB
2245
2246/* fmr - fmr. */
7c58044c 2247/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2248static void gen_fmr(DisasContext *ctx)
9a64fbe4 2249{
76a66253 2250 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2251 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2252 return;
2253 }
af12906f
AJ
2254 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2255 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
9a64fbe4
FB
2256}
2257
2258/* fnabs */
7c58044c 2259/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2260static void gen_fnabs(DisasContext *ctx)
2261{
2262 if (unlikely(!ctx->fpu_enabled)) {
2263 gen_exception(ctx, POWERPC_EXCP_FPU);
2264 return;
2265 }
2266 tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2267 1ULL << 63);
2268 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2269}
2270
9a64fbe4 2271/* fneg */
7c58044c 2272/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
bf45a2e6
AJ
2273static void gen_fneg(DisasContext *ctx)
2274{
2275 if (unlikely(!ctx->fpu_enabled)) {
2276 gen_exception(ctx, POWERPC_EXCP_FPU);
2277 return;
2278 }
2279 tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)],
2280 1ULL << 63);
2281 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2282}
9a64fbe4 2283
f0332888
AJ
2284/* fcpsgn: PowerPC 2.05 specification */
2285/* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2286static void gen_fcpsgn(DisasContext *ctx)
2287{
2288 if (unlikely(!ctx->fpu_enabled)) {
2289 gen_exception(ctx, POWERPC_EXCP_FPU);
2290 return;
2291 }
2292 tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],
2293 cpu_fpr[rB(ctx->opcode)], 0, 63);
2294 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2295}
2296
79aceca5 2297/*** Floating-Point status & ctrl register ***/
99e300ef 2298
54623277 2299/* mcrfs */
99e300ef 2300static void gen_mcrfs(DisasContext *ctx)
79aceca5 2301{
30304420 2302 TCGv tmp = tcg_temp_new();
7c58044c
JM
2303 int bfa;
2304
76a66253 2305 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2306 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2307 return;
2308 }
7c58044c 2309 bfa = 4 * (7 - crfS(ctx->opcode));
30304420
DG
2310 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2311 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2312 tcg_temp_free(tmp);
e1571908 2313 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
30304420 2314 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
79aceca5
FB
2315}
2316
2317/* mffs */
99e300ef 2318static void gen_mffs(DisasContext *ctx)
79aceca5 2319{
76a66253 2320 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2321 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2322 return;
2323 }
7c58044c 2324 gen_reset_fpstatus();
30304420 2325 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
af12906f 2326 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
79aceca5
FB
2327}
2328
2329/* mtfsb0 */
99e300ef 2330static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2331{
fb0eaffc 2332 uint8_t crb;
3b46e624 2333
76a66253 2334 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2335 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2336 return;
2337 }
6e35d524 2338 crb = 31 - crbD(ctx->opcode);
7c58044c 2339 gen_reset_fpstatus();
6e35d524 2340 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2341 TCGv_i32 t0;
2342 /* NIP cannot be restored if the memory exception comes from an helper */
2343 gen_update_nip(ctx, ctx->nip - 4);
2344 t0 = tcg_const_i32(crb);
8e703949 2345 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2346 tcg_temp_free_i32(t0);
2347 }
7c58044c 2348 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2349 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2350 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2351 }
79aceca5
FB
2352}
2353
2354/* mtfsb1 */
99e300ef 2355static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2356{
fb0eaffc 2357 uint8_t crb;
3b46e624 2358
76a66253 2359 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2360 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2361 return;
2362 }
6e35d524 2363 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2364 gen_reset_fpstatus();
2365 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2366 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2367 TCGv_i32 t0;
2368 /* NIP cannot be restored if the memory exception comes from an helper */
2369 gen_update_nip(ctx, ctx->nip - 4);
2370 t0 = tcg_const_i32(crb);
8e703949 2371 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2372 tcg_temp_free_i32(t0);
af12906f 2373 }
7c58044c 2374 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2375 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2376 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2377 }
2378 /* We can raise a differed exception */
8e703949 2379 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2380}
2381
2382/* mtfsf */
99e300ef 2383static void gen_mtfsf(DisasContext *ctx)
79aceca5 2384{
0f2f39c2 2385 TCGv_i32 t0;
7d08d856 2386 int flm, l, w;
af12906f 2387
76a66253 2388 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2389 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2390 return;
2391 }
7d08d856
AJ
2392 flm = FPFLM(ctx->opcode);
2393 l = FPL(ctx->opcode);
2394 w = FPW(ctx->opcode);
2395 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2396 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2397 return;
2398 }
eb44b959
AJ
2399 /* NIP cannot be restored if the memory exception comes from an helper */
2400 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2401 gen_reset_fpstatus();
7d08d856
AJ
2402 if (l) {
2403 t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff);
2404 } else {
2405 t0 = tcg_const_i32(flm << (w * 8));
2406 }
8e703949 2407 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2408 tcg_temp_free_i32(t0);
7c58044c 2409 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2410 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2411 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2412 }
2413 /* We can raise a differed exception */
8e703949 2414 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2415}
2416
2417/* mtfsfi */
99e300ef 2418static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2419{
7d08d856 2420 int bf, sh, w;
0f2f39c2
AJ
2421 TCGv_i64 t0;
2422 TCGv_i32 t1;
7c58044c 2423
76a66253 2424 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2425 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2426 return;
2427 }
7d08d856
AJ
2428 w = FPW(ctx->opcode);
2429 bf = FPBF(ctx->opcode);
2430 if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) {
2431 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2432 return;
2433 }
2434 sh = (8 * w) + 7 - bf;
eb44b959
AJ
2435 /* NIP cannot be restored if the memory exception comes from an helper */
2436 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2437 gen_reset_fpstatus();
7d08d856 2438 t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh));
af12906f 2439 t1 = tcg_const_i32(1 << sh);
8e703949 2440 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2441 tcg_temp_free_i64(t0);
2442 tcg_temp_free_i32(t1);
7c58044c 2443 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2444 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2445 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2446 }
2447 /* We can raise a differed exception */
8e703949 2448 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2449}
2450
76a66253
JM
2451/*** Addressing modes ***/
2452/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2453static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2454 target_long maskl)
76a66253
JM
2455{
2456 target_long simm = SIMM(ctx->opcode);
2457
be147d08 2458 simm &= ~maskl;
76db3ba4 2459 if (rA(ctx->opcode) == 0) {
c791fe84
RH
2460 if (NARROW_MODE(ctx)) {
2461 simm = (uint32_t)simm;
2462 }
e2be8d8d 2463 tcg_gen_movi_tl(EA, simm);
76db3ba4 2464 } else if (likely(simm != 0)) {
e2be8d8d 2465 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
c791fe84 2466 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2467 tcg_gen_ext32u_tl(EA, EA);
2468 }
76db3ba4 2469 } else {
c791fe84 2470 if (NARROW_MODE(ctx)) {
76db3ba4 2471 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
c791fe84
RH
2472 } else {
2473 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2474 }
76db3ba4 2475 }
76a66253
JM
2476}
2477
636aa200 2478static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2479{
76db3ba4 2480 if (rA(ctx->opcode) == 0) {
c791fe84 2481 if (NARROW_MODE(ctx)) {
76db3ba4 2482 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
c791fe84
RH
2483 } else {
2484 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2485 }
76db3ba4 2486 } else {
e2be8d8d 2487 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
c791fe84 2488 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2489 tcg_gen_ext32u_tl(EA, EA);
2490 }
76db3ba4 2491 }
76a66253
JM
2492}
2493
636aa200 2494static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2495{
76db3ba4 2496 if (rA(ctx->opcode) == 0) {
e2be8d8d 2497 tcg_gen_movi_tl(EA, 0);
c791fe84
RH
2498 } else if (NARROW_MODE(ctx)) {
2499 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2500 } else {
c791fe84 2501 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4
AJ
2502 }
2503}
2504
636aa200
BS
2505static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2506 target_long val)
76db3ba4
AJ
2507{
2508 tcg_gen_addi_tl(ret, arg1, val);
c791fe84 2509 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
2510 tcg_gen_ext32u_tl(ret, ret);
2511 }
76a66253
JM
2512}
2513
636aa200 2514static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32
AJ
2515{
2516 int l1 = gen_new_label();
2517 TCGv t0 = tcg_temp_new();
2518 TCGv_i32 t1, t2;
2519 /* NIP cannot be restored if the memory exception comes from an helper */
2520 gen_update_nip(ctx, ctx->nip - 4);
2521 tcg_gen_andi_tl(t0, EA, mask);
2522 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2523 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2524 t2 = tcg_const_i32(0);
e5f17ac6 2525 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2526 tcg_temp_free_i32(t1);
2527 tcg_temp_free_i32(t2);
2528 gen_set_label(l1);
2529 tcg_temp_free(t0);
2530}
2531
7863667f 2532/*** Integer load ***/
636aa200 2533static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2534{
2535 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2536}
2537
636aa200 2538static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2539{
2540 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2541}
2542
636aa200 2543static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2544{
2545 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2546 if (unlikely(ctx->le_mode)) {
fa3966a3 2547 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2548 }
b61f2753
AJ
2549}
2550
636aa200 2551static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2552{
76db3ba4 2553 if (unlikely(ctx->le_mode)) {
76db3ba4 2554 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
fa3966a3 2555 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2556 tcg_gen_ext16s_tl(arg1, arg1);
76db3ba4
AJ
2557 } else {
2558 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2559 }
b61f2753
AJ
2560}
2561
636aa200 2562static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2563{
76db3ba4
AJ
2564 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2565 if (unlikely(ctx->le_mode)) {
fa3966a3 2566 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2567 }
b61f2753
AJ
2568}
2569
f976b09e
AG
2570static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2571{
2572 TCGv tmp = tcg_temp_new();
2573 gen_qemu_ld32u(ctx, tmp, addr);
2574 tcg_gen_extu_tl_i64(val, tmp);
2575 tcg_temp_free(tmp);
2576}
2577
636aa200 2578static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2579{
a457e7ee 2580 if (unlikely(ctx->le_mode)) {
76db3ba4 2581 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
fa3966a3
AJ
2582 tcg_gen_bswap32_tl(arg1, arg1);
2583 tcg_gen_ext32s_tl(arg1, arg1);
b61f2753 2584 } else
76db3ba4 2585 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2586}
2587
cac7f0ba
TM
2588static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2589{
2590 TCGv tmp = tcg_temp_new();
2591 gen_qemu_ld32s(ctx, tmp, addr);
2592 tcg_gen_ext_tl_i64(val, tmp);
2593 tcg_temp_free(tmp);
2594}
2595
636aa200 2596static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2597{
76db3ba4
AJ
2598 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2599 if (unlikely(ctx->le_mode)) {
66896cb8 2600 tcg_gen_bswap64_i64(arg1, arg1);
76db3ba4 2601 }
b61f2753
AJ
2602}
2603
636aa200 2604static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2605{
76db3ba4 2606 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2607}
2608
636aa200 2609static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2610{
76db3ba4 2611 if (unlikely(ctx->le_mode)) {
76db3ba4
AJ
2612 TCGv t0 = tcg_temp_new();
2613 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2614 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2615 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2616 tcg_temp_free(t0);
76db3ba4
AJ
2617 } else {
2618 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2619 }
b61f2753
AJ
2620}
2621
636aa200 2622static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2623{
76db3ba4 2624 if (unlikely(ctx->le_mode)) {
fa3966a3
AJ
2625 TCGv t0 = tcg_temp_new();
2626 tcg_gen_ext32u_tl(t0, arg1);
2627 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2628 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2629 tcg_temp_free(t0);
76db3ba4
AJ
2630 } else {
2631 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2632 }
b61f2753
AJ
2633}
2634
f976b09e
AG
2635static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
2636{
2637 TCGv tmp = tcg_temp_new();
2638 tcg_gen_trunc_i64_tl(tmp, val);
2639 gen_qemu_st32(ctx, tmp, addr);
2640 tcg_temp_free(tmp);
2641}
2642
636aa200 2643static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2644{
76db3ba4 2645 if (unlikely(ctx->le_mode)) {
a7812ae4 2646 TCGv_i64 t0 = tcg_temp_new_i64();
66896cb8 2647 tcg_gen_bswap64_i64(t0, arg1);
76db3ba4 2648 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
a7812ae4 2649 tcg_temp_free_i64(t0);
b61f2753 2650 } else
76db3ba4 2651 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2652}
2653
0c8aacd4 2654#define GEN_LD(name, ldop, opc, type) \
99e300ef 2655static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2656{ \
76db3ba4
AJ
2657 TCGv EA; \
2658 gen_set_access_type(ctx, ACCESS_INT); \
2659 EA = tcg_temp_new(); \
2660 gen_addr_imm_index(ctx, EA, 0); \
2661 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2662 tcg_temp_free(EA); \
79aceca5
FB
2663}
2664
0c8aacd4 2665#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2666static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2667{ \
b61f2753 2668 TCGv EA; \
76a66253
JM
2669 if (unlikely(rA(ctx->opcode) == 0 || \
2670 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2671 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2672 return; \
9a64fbe4 2673 } \
76db3ba4 2674 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2675 EA = tcg_temp_new(); \
9d53c753 2676 if (type == PPC_64B) \
76db3ba4 2677 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2678 else \
76db3ba4
AJ
2679 gen_addr_imm_index(ctx, EA, 0); \
2680 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2681 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2682 tcg_temp_free(EA); \
79aceca5
FB
2683}
2684
0c8aacd4 2685#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2686static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2687{ \
b61f2753 2688 TCGv EA; \
76a66253
JM
2689 if (unlikely(rA(ctx->opcode) == 0 || \
2690 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2691 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2692 return; \
9a64fbe4 2693 } \
76db3ba4 2694 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2695 EA = tcg_temp_new(); \
76db3ba4
AJ
2696 gen_addr_reg_index(ctx, EA); \
2697 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2698 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2699 tcg_temp_free(EA); \
79aceca5
FB
2700}
2701
cd6e9320 2702#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2703static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2704{ \
76db3ba4
AJ
2705 TCGv EA; \
2706 gen_set_access_type(ctx, ACCESS_INT); \
2707 EA = tcg_temp_new(); \
2708 gen_addr_reg_index(ctx, EA); \
2709 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2710 tcg_temp_free(EA); \
79aceca5 2711}
cd6e9320
TH
2712#define GEN_LDX(name, ldop, opc2, opc3, type) \
2713 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2714
0c8aacd4
AJ
2715#define GEN_LDS(name, ldop, op, type) \
2716GEN_LD(name, ldop, op | 0x20, type); \
2717GEN_LDU(name, ldop, op | 0x21, type); \
2718GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2719GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2720
2721/* lbz lbzu lbzux lbzx */
0c8aacd4 2722GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2723/* lha lhau lhaux lhax */
0c8aacd4 2724GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2725/* lhz lhzu lhzux lhzx */
0c8aacd4 2726GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2727/* lwz lwzu lwzux lwzx */
0c8aacd4 2728GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2729#if defined(TARGET_PPC64)
d9bce9d9 2730/* lwaux */
0c8aacd4 2731GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2732/* lwax */
0c8aacd4 2733GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2734/* ldux */
0c8aacd4 2735GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2736/* ldx */
0c8aacd4 2737GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2738
2739static void gen_ld(DisasContext *ctx)
d9bce9d9 2740{
b61f2753 2741 TCGv EA;
d9bce9d9
JM
2742 if (Rc(ctx->opcode)) {
2743 if (unlikely(rA(ctx->opcode) == 0 ||
2744 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2745 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2746 return;
2747 }
2748 }
76db3ba4 2749 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2750 EA = tcg_temp_new();
76db3ba4 2751 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2752 if (ctx->opcode & 0x02) {
2753 /* lwa (lwau is undefined) */
76db3ba4 2754 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2755 } else {
2756 /* ld - ldu */
76db3ba4 2757 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2758 }
d9bce9d9 2759 if (Rc(ctx->opcode))
b61f2753
AJ
2760 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2761 tcg_temp_free(EA);
d9bce9d9 2762}
99e300ef 2763
54623277 2764/* lq */
99e300ef 2765static void gen_lq(DisasContext *ctx)
be147d08
JM
2766{
2767#if defined(CONFIG_USER_ONLY)
e06fcd75 2768 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2769#else
2770 int ra, rd;
b61f2753 2771 TCGv EA;
be147d08
JM
2772
2773 /* Restore CPU state */
76db3ba4 2774 if (unlikely(ctx->mem_idx == 0)) {
e06fcd75 2775 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2776 return;
2777 }
2778 ra = rA(ctx->opcode);
2779 rd = rD(ctx->opcode);
2780 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2781 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2782 return;
2783 }
76db3ba4 2784 if (unlikely(ctx->le_mode)) {
be147d08 2785 /* Little-endian mode is not handled */
e06fcd75 2786 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
be147d08
JM
2787 return;
2788 }
76db3ba4 2789 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2790 EA = tcg_temp_new();
76db3ba4
AJ
2791 gen_addr_imm_index(ctx, EA, 0x0F);
2792 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2793 gen_addr_add(ctx, EA, EA, 8);
2794 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
b61f2753 2795 tcg_temp_free(EA);
be147d08
JM
2796#endif
2797}
d9bce9d9 2798#endif
79aceca5
FB
2799
2800/*** Integer store ***/
0c8aacd4 2801#define GEN_ST(name, stop, opc, type) \
99e300ef 2802static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2803{ \
76db3ba4
AJ
2804 TCGv EA; \
2805 gen_set_access_type(ctx, ACCESS_INT); \
2806 EA = tcg_temp_new(); \
2807 gen_addr_imm_index(ctx, EA, 0); \
2808 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2809 tcg_temp_free(EA); \
79aceca5
FB
2810}
2811
0c8aacd4 2812#define GEN_STU(name, stop, opc, type) \
99e300ef 2813static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2814{ \
b61f2753 2815 TCGv EA; \
76a66253 2816 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2817 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2818 return; \
9a64fbe4 2819 } \
76db3ba4 2820 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2821 EA = tcg_temp_new(); \
9d53c753 2822 if (type == PPC_64B) \
76db3ba4 2823 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2824 else \
76db3ba4
AJ
2825 gen_addr_imm_index(ctx, EA, 0); \
2826 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2827 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2828 tcg_temp_free(EA); \
79aceca5
FB
2829}
2830
0c8aacd4 2831#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2832static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2833{ \
b61f2753 2834 TCGv EA; \
76a66253 2835 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2836 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2837 return; \
9a64fbe4 2838 } \
76db3ba4 2839 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2840 EA = tcg_temp_new(); \
76db3ba4
AJ
2841 gen_addr_reg_index(ctx, EA); \
2842 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2843 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2844 tcg_temp_free(EA); \
79aceca5
FB
2845}
2846
cd6e9320
TH
2847#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2848static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2849{ \
76db3ba4
AJ
2850 TCGv EA; \
2851 gen_set_access_type(ctx, ACCESS_INT); \
2852 EA = tcg_temp_new(); \
2853 gen_addr_reg_index(ctx, EA); \
2854 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2855 tcg_temp_free(EA); \
79aceca5 2856}
cd6e9320
TH
2857#define GEN_STX(name, stop, opc2, opc3, type) \
2858 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 2859
0c8aacd4
AJ
2860#define GEN_STS(name, stop, op, type) \
2861GEN_ST(name, stop, op | 0x20, type); \
2862GEN_STU(name, stop, op | 0x21, type); \
2863GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2864GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
2865
2866/* stb stbu stbux stbx */
0c8aacd4 2867GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 2868/* sth sthu sthux sthx */
0c8aacd4 2869GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 2870/* stw stwu stwux stwx */
0c8aacd4 2871GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 2872#if defined(TARGET_PPC64)
0c8aacd4
AJ
2873GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2874GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
2875
2876static void gen_std(DisasContext *ctx)
d9bce9d9 2877{
be147d08 2878 int rs;
b61f2753 2879 TCGv EA;
be147d08
JM
2880
2881 rs = rS(ctx->opcode);
2882 if ((ctx->opcode & 0x3) == 0x2) {
2883#if defined(CONFIG_USER_ONLY)
e06fcd75 2884 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2885#else
2886 /* stq */
76db3ba4 2887 if (unlikely(ctx->mem_idx == 0)) {
e06fcd75 2888 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2889 return;
2890 }
2891 if (unlikely(rs & 1)) {
e06fcd75 2892 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2893 return;
2894 }
76db3ba4 2895 if (unlikely(ctx->le_mode)) {
be147d08 2896 /* Little-endian mode is not handled */
e06fcd75 2897 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
be147d08
JM
2898 return;
2899 }
76db3ba4 2900 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2901 EA = tcg_temp_new();
76db3ba4
AJ
2902 gen_addr_imm_index(ctx, EA, 0x03);
2903 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
2904 gen_addr_add(ctx, EA, EA, 8);
2905 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
b61f2753 2906 tcg_temp_free(EA);
be147d08
JM
2907#endif
2908 } else {
2909 /* std / stdu */
2910 if (Rc(ctx->opcode)) {
2911 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 2912 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2913 return;
2914 }
2915 }
76db3ba4 2916 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2917 EA = tcg_temp_new();
76db3ba4
AJ
2918 gen_addr_imm_index(ctx, EA, 0x03);
2919 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 2920 if (Rc(ctx->opcode))
b61f2753
AJ
2921 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2922 tcg_temp_free(EA);
d9bce9d9 2923 }
d9bce9d9
JM
2924}
2925#endif
79aceca5
FB
2926/*** Integer load and store with byte reverse ***/
2927/* lhbrx */
86178a57 2928static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2929{
76db3ba4
AJ
2930 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2931 if (likely(!ctx->le_mode)) {
fa3966a3 2932 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2933 }
b61f2753 2934}
0c8aacd4 2935GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 2936
79aceca5 2937/* lwbrx */
86178a57 2938static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2939{
76db3ba4
AJ
2940 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2941 if (likely(!ctx->le_mode)) {
fa3966a3 2942 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2943 }
b61f2753 2944}
0c8aacd4 2945GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 2946
cd6e9320
TH
2947#if defined(TARGET_PPC64)
2948/* ldbrx */
2949static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
2950{
2951 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2952 if (likely(!ctx->le_mode)) {
2953 tcg_gen_bswap64_tl(arg1, arg1);
2954 }
2955}
2956GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
2957#endif /* TARGET_PPC64 */
2958
79aceca5 2959/* sthbrx */
86178a57 2960static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2961{
76db3ba4 2962 if (likely(!ctx->le_mode)) {
76db3ba4
AJ
2963 TCGv t0 = tcg_temp_new();
2964 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2965 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2966 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2967 tcg_temp_free(t0);
76db3ba4
AJ
2968 } else {
2969 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2970 }
b61f2753 2971}
0c8aacd4 2972GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 2973
79aceca5 2974/* stwbrx */
86178a57 2975static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2976{
76db3ba4 2977 if (likely(!ctx->le_mode)) {
fa3966a3
AJ
2978 TCGv t0 = tcg_temp_new();
2979 tcg_gen_ext32u_tl(t0, arg1);
2980 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2981 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2982 tcg_temp_free(t0);
76db3ba4
AJ
2983 } else {
2984 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2985 }
b61f2753 2986}
0c8aacd4 2987GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 2988
cd6e9320
TH
2989#if defined(TARGET_PPC64)
2990/* stdbrx */
2991static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
2992{
2993 if (likely(!ctx->le_mode)) {
2994 TCGv t0 = tcg_temp_new();
2995 tcg_gen_bswap64_tl(t0, arg1);
2996 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
2997 tcg_temp_free(t0);
2998 } else {
2999 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
3000 }
3001}
3002GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
3003#endif /* TARGET_PPC64 */
3004
79aceca5 3005/*** Integer load and store multiple ***/
99e300ef 3006
54623277 3007/* lmw */
99e300ef 3008static void gen_lmw(DisasContext *ctx)
79aceca5 3009{
76db3ba4
AJ
3010 TCGv t0;
3011 TCGv_i32 t1;
3012 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3013 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3014 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3015 t0 = tcg_temp_new();
3016 t1 = tcg_const_i32(rD(ctx->opcode));
3017 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3018 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
3019 tcg_temp_free(t0);
3020 tcg_temp_free_i32(t1);
79aceca5
FB
3021}
3022
3023/* stmw */
99e300ef 3024static void gen_stmw(DisasContext *ctx)
79aceca5 3025{
76db3ba4
AJ
3026 TCGv t0;
3027 TCGv_i32 t1;
3028 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3029 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3030 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3031 t0 = tcg_temp_new();
3032 t1 = tcg_const_i32(rS(ctx->opcode));
3033 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 3034 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
3035 tcg_temp_free(t0);
3036 tcg_temp_free_i32(t1);
79aceca5
FB
3037}
3038
3039/*** Integer load and store strings ***/
54623277 3040
79aceca5 3041/* lswi */
3fc6c082 3042/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
3043 * rA is in the range of registers to be loaded.
3044 * In an other hand, IBM says this is valid, but rA won't be loaded.
3045 * For now, I'll follow the spec...
3046 */
99e300ef 3047static void gen_lswi(DisasContext *ctx)
79aceca5 3048{
dfbc799d
AJ
3049 TCGv t0;
3050 TCGv_i32 t1, t2;
79aceca5
FB
3051 int nb = NB(ctx->opcode);
3052 int start = rD(ctx->opcode);
9a64fbe4 3053 int ra = rA(ctx->opcode);
79aceca5
FB
3054 int nr;
3055
3056 if (nb == 0)
3057 nb = 32;
3058 nr = nb / 4;
76a66253
JM
3059 if (unlikely(((start + nr) > 32 &&
3060 start <= ra && (start + nr - 32) > ra) ||
3061 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
e06fcd75 3062 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 3063 return;
297d8e62 3064 }
76db3ba4 3065 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3066 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3067 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 3068 t0 = tcg_temp_new();
76db3ba4 3069 gen_addr_register(ctx, t0);
dfbc799d
AJ
3070 t1 = tcg_const_i32(nb);
3071 t2 = tcg_const_i32(start);
2f5a189c 3072 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3073 tcg_temp_free(t0);
3074 tcg_temp_free_i32(t1);
3075 tcg_temp_free_i32(t2);
79aceca5
FB
3076}
3077
3078/* lswx */
99e300ef 3079static void gen_lswx(DisasContext *ctx)
79aceca5 3080{
76db3ba4
AJ
3081 TCGv t0;
3082 TCGv_i32 t1, t2, t3;
3083 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3084 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3085 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3086 t0 = tcg_temp_new();
3087 gen_addr_reg_index(ctx, t0);
3088 t1 = tcg_const_i32(rD(ctx->opcode));
3089 t2 = tcg_const_i32(rA(ctx->opcode));
3090 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 3091 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
3092 tcg_temp_free(t0);
3093 tcg_temp_free_i32(t1);
3094 tcg_temp_free_i32(t2);
3095 tcg_temp_free_i32(t3);
79aceca5
FB
3096}
3097
3098/* stswi */
99e300ef 3099static void gen_stswi(DisasContext *ctx)
79aceca5 3100{
76db3ba4
AJ
3101 TCGv t0;
3102 TCGv_i32 t1, t2;
4b3686fa 3103 int nb = NB(ctx->opcode);
76db3ba4 3104 gen_set_access_type(ctx, ACCESS_INT);
76a66253 3105 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 3106 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3107 t0 = tcg_temp_new();
3108 gen_addr_register(ctx, t0);
4b3686fa
FB
3109 if (nb == 0)
3110 nb = 32;
dfbc799d 3111 t1 = tcg_const_i32(nb);
76db3ba4 3112 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3113 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3114 tcg_temp_free(t0);
3115 tcg_temp_free_i32(t1);
3116 tcg_temp_free_i32(t2);
79aceca5
FB
3117}
3118
3119/* stswx */
99e300ef 3120static void gen_stswx(DisasContext *ctx)
79aceca5 3121{
76db3ba4
AJ
3122 TCGv t0;
3123 TCGv_i32 t1, t2;
3124 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 3125 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 3126 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
3127 t0 = tcg_temp_new();
3128 gen_addr_reg_index(ctx, t0);
3129 t1 = tcg_temp_new_i32();
dfbc799d
AJ
3130 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3131 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 3132 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 3133 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
3134 tcg_temp_free(t0);
3135 tcg_temp_free_i32(t1);
3136 tcg_temp_free_i32(t2);
79aceca5
FB
3137}
3138
3139/*** Memory synchronisation ***/
3140/* eieio */
99e300ef 3141static void gen_eieio(DisasContext *ctx)
79aceca5 3142{
79aceca5
FB
3143}
3144
3145/* isync */
99e300ef 3146static void gen_isync(DisasContext *ctx)
79aceca5 3147{
e06fcd75 3148 gen_stop_exception(ctx);
79aceca5
FB
3149}
3150
111bfab3 3151/* lwarx */
99e300ef 3152static void gen_lwarx(DisasContext *ctx)
79aceca5 3153{
76db3ba4 3154 TCGv t0;
18b21a2f 3155 TCGv gpr = cpu_gpr[rD(ctx->opcode)];
76db3ba4
AJ
3156 gen_set_access_type(ctx, ACCESS_RES);
3157 t0 = tcg_temp_local_new();
3158 gen_addr_reg_index(ctx, t0);
cf360a32 3159 gen_check_align(ctx, t0, 0x03);
18b21a2f 3160 gen_qemu_ld32u(ctx, gpr, t0);
cf360a32 3161 tcg_gen_mov_tl(cpu_reserve, t0);
1328c2bf 3162 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val));
cf360a32 3163 tcg_temp_free(t0);
79aceca5
FB
3164}
3165
4425265b
NF
3166#if defined(CONFIG_USER_ONLY)
3167static void gen_conditional_store (DisasContext *ctx, TCGv EA,
3168 int reg, int size)
3169{
3170 TCGv t0 = tcg_temp_new();
3171 uint32_t save_exception = ctx->exception;
3172
1328c2bf 3173 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3174 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3175 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3176 tcg_temp_free(t0);
3177 gen_update_nip(ctx, ctx->nip-4);
3178 ctx->exception = POWERPC_EXCP_BRANCH;
3179 gen_exception(ctx, POWERPC_EXCP_STCX);
3180 ctx->exception = save_exception;
3181}
3182#endif
3183
79aceca5 3184/* stwcx. */
e8eaa2c0 3185static void gen_stwcx_(DisasContext *ctx)
79aceca5 3186{
76db3ba4
AJ
3187 TCGv t0;
3188 gen_set_access_type(ctx, ACCESS_RES);
3189 t0 = tcg_temp_local_new();
3190 gen_addr_reg_index(ctx, t0);
cf360a32 3191 gen_check_align(ctx, t0, 0x03);
4425265b
NF
3192#if defined(CONFIG_USER_ONLY)
3193 gen_conditional_store(ctx, t0, rS(ctx->opcode), 4);
3194#else
3195 {
3196 int l1;
3197
da91a00f 3198 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
4425265b
NF
3199 l1 = gen_new_label();
3200 tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3201 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3202 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3203 gen_set_label(l1);
3204 tcg_gen_movi_tl(cpu_reserve, -1);
3205 }
3206#endif
cf360a32 3207 tcg_temp_free(t0);
79aceca5
FB
3208}
3209
426613db 3210#if defined(TARGET_PPC64)
426613db 3211/* ldarx */
99e300ef 3212static void gen_ldarx(DisasContext *ctx)
426613db 3213{
76db3ba4 3214 TCGv t0;
18b21a2f 3215 TCGv gpr = cpu_gpr[rD(ctx->opcode)];
76db3ba4
AJ
3216 gen_set_access_type(ctx, ACCESS_RES);
3217 t0 = tcg_temp_local_new();
3218 gen_addr_reg_index(ctx, t0);
cf360a32 3219 gen_check_align(ctx, t0, 0x07);
18b21a2f 3220 gen_qemu_ld64(ctx, gpr, t0);
cf360a32 3221 tcg_gen_mov_tl(cpu_reserve, t0);
1328c2bf 3222 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val));
cf360a32 3223 tcg_temp_free(t0);
426613db
JM
3224}
3225
3226/* stdcx. */
e8eaa2c0 3227static void gen_stdcx_(DisasContext *ctx)
426613db 3228{
76db3ba4
AJ
3229 TCGv t0;
3230 gen_set_access_type(ctx, ACCESS_RES);
3231 t0 = tcg_temp_local_new();
3232 gen_addr_reg_index(ctx, t0);
cf360a32 3233 gen_check_align(ctx, t0, 0x07);
4425265b
NF
3234#if defined(CONFIG_USER_ONLY)
3235 gen_conditional_store(ctx, t0, rS(ctx->opcode), 8);
3236#else
3237 {
3238 int l1;
da91a00f 3239 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
4425265b
NF
3240 l1 = gen_new_label();
3241 tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3242 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3243 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3244 gen_set_label(l1);
3245 tcg_gen_movi_tl(cpu_reserve, -1);
3246 }
3247#endif
cf360a32 3248 tcg_temp_free(t0);
426613db
JM
3249}
3250#endif /* defined(TARGET_PPC64) */
3251
79aceca5 3252/* sync */
99e300ef 3253static void gen_sync(DisasContext *ctx)
79aceca5 3254{
79aceca5
FB
3255}
3256
0db1b20e 3257/* wait */
99e300ef 3258static void gen_wait(DisasContext *ctx)
0db1b20e 3259{
931ff272 3260 TCGv_i32 t0 = tcg_temp_new_i32();
259186a7
AF
3261 tcg_gen_st_i32(t0, cpu_env,
3262 -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted));
931ff272 3263 tcg_temp_free_i32(t0);
0db1b20e 3264 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3265 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3266}
3267
79aceca5 3268/*** Floating-point load ***/
a0d7d5a7 3269#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3270static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3271{ \
a0d7d5a7 3272 TCGv EA; \
76a66253 3273 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3274 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3275 return; \
3276 } \
76db3ba4 3277 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3278 EA = tcg_temp_new(); \
76db3ba4
AJ
3279 gen_addr_imm_index(ctx, EA, 0); \
3280 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3281 tcg_temp_free(EA); \
79aceca5
FB
3282}
3283
a0d7d5a7 3284#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3285static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3286{ \
a0d7d5a7 3287 TCGv EA; \
76a66253 3288 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3289 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3290 return; \
3291 } \
76a66253 3292 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3293 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3294 return; \
9a64fbe4 3295 } \
76db3ba4 3296 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3297 EA = tcg_temp_new(); \
76db3ba4
AJ
3298 gen_addr_imm_index(ctx, EA, 0); \
3299 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3300 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3301 tcg_temp_free(EA); \
79aceca5
FB
3302}
3303
a0d7d5a7 3304#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3305static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3306{ \
a0d7d5a7 3307 TCGv EA; \
76a66253 3308 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3309 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3310 return; \
3311 } \
76a66253 3312 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3313 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3314 return; \
9a64fbe4 3315 } \
76db3ba4 3316 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3317 EA = tcg_temp_new(); \
76db3ba4
AJ
3318 gen_addr_reg_index(ctx, EA); \
3319 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3320 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3321 tcg_temp_free(EA); \
79aceca5
FB
3322}
3323
a0d7d5a7 3324#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3325static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3326{ \
a0d7d5a7 3327 TCGv EA; \
76a66253 3328 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3329 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3330 return; \
3331 } \
76db3ba4 3332 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3333 EA = tcg_temp_new(); \
76db3ba4
AJ
3334 gen_addr_reg_index(ctx, EA); \
3335 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3336 tcg_temp_free(EA); \
79aceca5
FB
3337}
3338
a0d7d5a7
AJ
3339#define GEN_LDFS(name, ldop, op, type) \
3340GEN_LDF(name, ldop, op | 0x20, type); \
3341GEN_LDUF(name, ldop, op | 0x21, type); \
3342GEN_LDUXF(name, ldop, op | 0x01, type); \
3343GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3344
636aa200 3345static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3346{
3347 TCGv t0 = tcg_temp_new();
3348 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3349 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3350 tcg_gen_trunc_tl_i32(t1, t0);
3351 tcg_temp_free(t0);
8e703949 3352 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3353 tcg_temp_free_i32(t1);
3354}
79aceca5 3355
a0d7d5a7
AJ
3356 /* lfd lfdu lfdux lfdx */
3357GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3358 /* lfs lfsu lfsux lfsx */
3359GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5 3360
05050ee8
AJ
3361/* lfdp */
3362static void gen_lfdp(DisasContext *ctx)
3363{
3364 TCGv EA;
3365 if (unlikely(!ctx->fpu_enabled)) {
3366 gen_exception(ctx, POWERPC_EXCP_FPU);
3367 return;
3368 }
3369 gen_set_access_type(ctx, ACCESS_FLOAT);
3370 EA = tcg_temp_new();
3371 gen_addr_imm_index(ctx, EA, 0); \
3372 if (unlikely(ctx->le_mode)) {
3373 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3374 tcg_gen_addi_tl(EA, EA, 8);
3375 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3376 } else {
3377 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3378 tcg_gen_addi_tl(EA, EA, 8);
3379 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3380 }
3381 tcg_temp_free(EA);
3382}
3383
3384/* lfdpx */
3385static void gen_lfdpx(DisasContext *ctx)
3386{
3387 TCGv EA;
3388 if (unlikely(!ctx->fpu_enabled)) {
3389 gen_exception(ctx, POWERPC_EXCP_FPU);
3390 return;
3391 }
3392 gen_set_access_type(ctx, ACCESS_FLOAT);
3393 EA = tcg_temp_new();
3394 gen_addr_reg_index(ctx, EA);
3395 if (unlikely(ctx->le_mode)) {
3396 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3397 tcg_gen_addi_tl(EA, EA, 8);
3398 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3399 } else {
3400 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3401 tcg_gen_addi_tl(EA, EA, 8);
3402 gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3403 }
3404 tcg_temp_free(EA);
3405}
3406
199f830d
AJ
3407/* lfiwax */
3408static void gen_lfiwax(DisasContext *ctx)
3409{
3410 TCGv EA;
3411 TCGv t0;
3412 if (unlikely(!ctx->fpu_enabled)) {
3413 gen_exception(ctx, POWERPC_EXCP_FPU);
3414 return;
3415 }
3416 gen_set_access_type(ctx, ACCESS_FLOAT);
3417 EA = tcg_temp_new();
3418 t0 = tcg_temp_new();
3419 gen_addr_reg_index(ctx, EA);
909eedb7 3420 gen_qemu_ld32s(ctx, t0, EA);
199f830d 3421 tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0);
199f830d
AJ
3422 tcg_temp_free(EA);
3423 tcg_temp_free(t0);
3424}
3425
79aceca5 3426/*** Floating-point store ***/
a0d7d5a7 3427#define GEN_STF(name, stop, opc, type) \
99e300ef 3428static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3429{ \
a0d7d5a7 3430 TCGv EA; \
76a66253 3431 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3432 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3433 return; \
3434 } \
76db3ba4 3435 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3436 EA = tcg_temp_new(); \
76db3ba4
AJ
3437 gen_addr_imm_index(ctx, EA, 0); \
3438 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3439 tcg_temp_free(EA); \
79aceca5
FB
3440}
3441
a0d7d5a7 3442#define GEN_STUF(name, stop, opc, type) \
99e300ef 3443static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3444{ \
a0d7d5a7 3445 TCGv EA; \
76a66253 3446 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3447 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3448 return; \
3449 } \
76a66253 3450 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3451 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3452 return; \
9a64fbe4 3453 } \
76db3ba4 3454 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3455 EA = tcg_temp_new(); \
76db3ba4
AJ
3456 gen_addr_imm_index(ctx, EA, 0); \
3457 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3458 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3459 tcg_temp_free(EA); \
79aceca5
FB
3460}
3461
a0d7d5a7 3462#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3463static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3464{ \
a0d7d5a7 3465 TCGv EA; \
76a66253 3466 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3467 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3468 return; \
3469 } \
76a66253 3470 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3471 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3472 return; \
9a64fbe4 3473 } \
76db3ba4 3474 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3475 EA = tcg_temp_new(); \
76db3ba4
AJ
3476 gen_addr_reg_index(ctx, EA); \
3477 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3478 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3479 tcg_temp_free(EA); \
79aceca5
FB
3480}
3481
a0d7d5a7 3482#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3483static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3484{ \
a0d7d5a7 3485 TCGv EA; \
76a66253 3486 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3487 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3488 return; \
3489 } \
76db3ba4 3490 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3491 EA = tcg_temp_new(); \
76db3ba4
AJ
3492 gen_addr_reg_index(ctx, EA); \
3493 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3494 tcg_temp_free(EA); \
79aceca5
FB
3495}
3496
a0d7d5a7
AJ
3497#define GEN_STFS(name, stop, op, type) \
3498GEN_STF(name, stop, op | 0x20, type); \
3499GEN_STUF(name, stop, op | 0x21, type); \
3500GEN_STUXF(name, stop, op | 0x01, type); \
3501GEN_STXF(name, stop, 0x17, op | 0x00, type)
3502
636aa200 3503static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3504{
3505 TCGv_i32 t0 = tcg_temp_new_i32();
3506 TCGv t1 = tcg_temp_new();
8e703949 3507 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3508 tcg_gen_extu_i32_tl(t1, t0);
3509 tcg_temp_free_i32(t0);
76db3ba4 3510 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3511 tcg_temp_free(t1);
3512}
79aceca5
FB
3513
3514/* stfd stfdu stfdux stfdx */
a0d7d5a7 3515GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3516/* stfs stfsu stfsux stfsx */
a0d7d5a7 3517GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5 3518
44bc0c4d
AJ
3519/* stfdp */
3520static void gen_stfdp(DisasContext *ctx)
3521{
3522 TCGv EA;
3523 if (unlikely(!ctx->fpu_enabled)) {
3524 gen_exception(ctx, POWERPC_EXCP_FPU);
3525 return;
3526 }
3527 gen_set_access_type(ctx, ACCESS_FLOAT);
3528 EA = tcg_temp_new();
3529 gen_addr_imm_index(ctx, EA, 0); \
3530 if (unlikely(ctx->le_mode)) {
3531 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3532 tcg_gen_addi_tl(EA, EA, 8);
3533 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3534 } else {
3535 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3536 tcg_gen_addi_tl(EA, EA, 8);
3537 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3538 }
3539 tcg_temp_free(EA);
3540}
3541
3542/* stfdpx */
3543static void gen_stfdpx(DisasContext *ctx)
3544{
3545 TCGv EA;
3546 if (unlikely(!ctx->fpu_enabled)) {
3547 gen_exception(ctx, POWERPC_EXCP_FPU);
3548 return;
3549 }
3550 gen_set_access_type(ctx, ACCESS_FLOAT);
3551 EA = tcg_temp_new();
3552 gen_addr_reg_index(ctx, EA);
3553 if (unlikely(ctx->le_mode)) {
3554 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3555 tcg_gen_addi_tl(EA, EA, 8);
3556 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3557 } else {
3558 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA);
3559 tcg_gen_addi_tl(EA, EA, 8);
3560 gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA);
3561 }
3562 tcg_temp_free(EA);
3563}
3564
79aceca5 3565/* Optional: */
636aa200 3566static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3567{
3568 TCGv t0 = tcg_temp_new();
3569 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3570 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3571 tcg_temp_free(t0);
3572}
79aceca5 3573/* stfiwx */
a0d7d5a7 3574GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3575
697ab892
DG
3576static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3577{
3578#if defined(TARGET_PPC64)
3579 if (ctx->has_cfar)
3580 tcg_gen_movi_tl(cpu_cfar, nip);
3581#endif
3582}
3583
79aceca5 3584/*** Branch ***/
636aa200 3585static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362
FB
3586{
3587 TranslationBlock *tb;
3588 tb = ctx->tb;
e0c8f9ce 3589 if (NARROW_MODE(ctx)) {
a2ffb812 3590 dest = (uint32_t) dest;
e0c8f9ce 3591 }
57fec1fe 3592 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
8cbcb4fa 3593 likely(!ctx->singlestep_enabled)) {
57fec1fe 3594 tcg_gen_goto_tb(n);
a2ffb812 3595 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cfd0495 3596 tcg_gen_exit_tb((uintptr_t)tb + n);
c1942362 3597 } else {
a2ffb812 3598 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3599 if (unlikely(ctx->singlestep_enabled)) {
3600 if ((ctx->singlestep_enabled &
bdc4e053 3601 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3602 (ctx->exception == POWERPC_EXCP_BRANCH ||
3603 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3604 target_ulong tmp = ctx->nip;
3605 ctx->nip = dest;
e06fcd75 3606 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3607 ctx->nip = tmp;
3608 }
3609 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3610 gen_debug_exception(ctx);
8cbcb4fa
AJ
3611 }
3612 }
57fec1fe 3613 tcg_gen_exit_tb(0);
c1942362 3614 }
c53be334
FB
3615}
3616
636aa200 3617static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f 3618{
e0c8f9ce
RH
3619 if (NARROW_MODE(ctx)) {
3620 nip = (uint32_t)nip;
3621 }
3622 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3623}
3624
79aceca5 3625/* b ba bl bla */
99e300ef 3626static void gen_b(DisasContext *ctx)
79aceca5 3627{
76a66253 3628 target_ulong li, target;
38a64f9d 3629
8cbcb4fa 3630 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3631 /* sign extend LI */
e0c8f9ce
RH
3632 li = LI(ctx->opcode);
3633 li = (li ^ 0x02000000) - 0x02000000;
3634 if (likely(AA(ctx->opcode) == 0)) {
046d6672 3635 target = ctx->nip + li - 4;
e0c8f9ce 3636 } else {
9a64fbe4 3637 target = li;
e0c8f9ce
RH
3638 }
3639 if (LK(ctx->opcode)) {
e1833e1f 3640 gen_setlr(ctx, ctx->nip);
e0c8f9ce 3641 }
697ab892 3642 gen_update_cfar(ctx, ctx->nip);
c1942362 3643 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3644}
3645
e98a6e40
FB
3646#define BCOND_IM 0
3647#define BCOND_LR 1
3648#define BCOND_CTR 2
3649
636aa200 3650static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3651{
d9bce9d9 3652 uint32_t bo = BO(ctx->opcode);
05f92404 3653 int l1;
a2ffb812 3654 TCGv target;
e98a6e40 3655
8cbcb4fa 3656 ctx->exception = POWERPC_EXCP_BRANCH;
a2ffb812 3657 if (type == BCOND_LR || type == BCOND_CTR) {
a7812ae4 3658 target = tcg_temp_local_new();
a2ffb812
AJ
3659 if (type == BCOND_CTR)
3660 tcg_gen_mov_tl(target, cpu_ctr);
3661 else
3662 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3663 } else {
3664 TCGV_UNUSED(target);
e98a6e40 3665 }
e1833e1f
JM
3666 if (LK(ctx->opcode))
3667 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3668 l1 = gen_new_label();
3669 if ((bo & 0x4) == 0) {
3670 /* Decrement and test CTR */
a7812ae4 3671 TCGv temp = tcg_temp_new();
a2ffb812 3672 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3673 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3674 return;
3675 }
3676 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
e0c8f9ce 3677 if (NARROW_MODE(ctx)) {
a2ffb812 3678 tcg_gen_ext32u_tl(temp, cpu_ctr);
e0c8f9ce 3679 } else {
a2ffb812 3680 tcg_gen_mov_tl(temp, cpu_ctr);
e0c8f9ce 3681 }
a2ffb812
AJ
3682 if (bo & 0x2) {
3683 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3684 } else {
3685 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3686 }
a7812ae4 3687 tcg_temp_free(temp);
a2ffb812
AJ
3688 }
3689 if ((bo & 0x10) == 0) {
3690 /* Test CR */
3691 uint32_t bi = BI(ctx->opcode);
3692 uint32_t mask = 1 << (3 - (bi & 0x03));
a7812ae4 3693 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3694
d9bce9d9 3695 if (bo & 0x8) {
a2ffb812
AJ
3696 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3697 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3698 } else {
a2ffb812
AJ
3699 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3700 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3701 }
a7812ae4 3702 tcg_temp_free_i32(temp);
d9bce9d9 3703 }
697ab892 3704 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3705 if (type == BCOND_IM) {
a2ffb812
AJ
3706 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3707 if (likely(AA(ctx->opcode) == 0)) {
3708 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3709 } else {
3710 gen_goto_tb(ctx, 0, li);
3711 }
c53be334 3712 gen_set_label(l1);
c1942362 3713 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3714 } else {
e0c8f9ce 3715 if (NARROW_MODE(ctx)) {
a2ffb812 3716 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
e0c8f9ce 3717 } else {
a2ffb812 3718 tcg_gen_andi_tl(cpu_nip, target, ~3);
e0c8f9ce 3719 }
a2ffb812
AJ
3720 tcg_gen_exit_tb(0);
3721 gen_set_label(l1);
e0c8f9ce 3722 gen_update_nip(ctx, ctx->nip);
57fec1fe 3723 tcg_gen_exit_tb(0);
08e46e54 3724 }
e98a6e40
FB
3725}
3726
99e300ef 3727static void gen_bc(DisasContext *ctx)
3b46e624 3728{
e98a6e40
FB
3729 gen_bcond(ctx, BCOND_IM);
3730}
3731
99e300ef 3732static void gen_bcctr(DisasContext *ctx)
3b46e624 3733{
e98a6e40
FB
3734 gen_bcond(ctx, BCOND_CTR);
3735}
3736
99e300ef 3737static void gen_bclr(DisasContext *ctx)
3b46e624 3738{
e98a6e40
FB
3739 gen_bcond(ctx, BCOND_LR);
3740}
79aceca5
FB
3741
3742/*** Condition register logical ***/
e1571908 3743#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 3744static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3745{ \
fc0d441e
JM
3746 uint8_t bitmask; \
3747 int sh; \
a7812ae4 3748 TCGv_i32 t0, t1; \
fc0d441e 3749 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 3750 t0 = tcg_temp_new_i32(); \
fc0d441e 3751 if (sh > 0) \
fea0c503 3752 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 3753 else if (sh < 0) \
fea0c503 3754 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 3755 else \
fea0c503 3756 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 3757 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
3758 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3759 if (sh > 0) \
fea0c503 3760 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 3761 else if (sh < 0) \
fea0c503 3762 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 3763 else \
fea0c503
AJ
3764 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3765 tcg_op(t0, t0, t1); \
fc0d441e 3766 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
fea0c503
AJ
3767 tcg_gen_andi_i32(t0, t0, bitmask); \
3768 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3769 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
3770 tcg_temp_free_i32(t0); \
3771 tcg_temp_free_i32(t1); \
79aceca5
FB
3772}
3773
3774/* crand */
e1571908 3775GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 3776/* crandc */
e1571908 3777GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 3778/* creqv */
e1571908 3779GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 3780/* crnand */
e1571908 3781GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 3782/* crnor */
e1571908 3783GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 3784/* cror */
e1571908 3785GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 3786/* crorc */
e1571908 3787GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 3788/* crxor */
e1571908 3789GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 3790
54623277 3791/* mcrf */
99e300ef 3792static void gen_mcrf(DisasContext *ctx)
79aceca5 3793{
47e4661c 3794 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
3795}
3796
3797/*** System linkage ***/
99e300ef 3798
54623277 3799/* rfi (mem_idx only) */
99e300ef 3800static void gen_rfi(DisasContext *ctx)
79aceca5 3801{
9a64fbe4 3802#if defined(CONFIG_USER_ONLY)
e06fcd75 3803 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
3804#else
3805 /* Restore CPU state */
76db3ba4 3806 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3807 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 3808 return;
9a64fbe4 3809 }
697ab892 3810 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 3811 gen_helper_rfi(cpu_env);
e06fcd75 3812 gen_sync_exception(ctx);
9a64fbe4 3813#endif
79aceca5
FB
3814}
3815
426613db 3816#if defined(TARGET_PPC64)
99e300ef 3817static void gen_rfid(DisasContext *ctx)
426613db
JM
3818{
3819#if defined(CONFIG_USER_ONLY)
e06fcd75 3820 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
3821#else
3822 /* Restore CPU state */
76db3ba4 3823 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3824 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
3825 return;
3826 }
697ab892 3827 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 3828 gen_helper_rfid(cpu_env);
e06fcd75 3829 gen_sync_exception(ctx);
426613db
JM
3830#endif
3831}
426613db 3832
99e300ef 3833static void gen_hrfid(DisasContext *ctx)
be147d08
JM
3834{
3835#if defined(CONFIG_USER_ONLY)
e06fcd75 3836 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3837#else
3838 /* Restore CPU state */
76db3ba4 3839 if (unlikely(ctx->mem_idx <= 1)) {
e06fcd75 3840 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3841 return;
3842 }
e5f17ac6 3843 gen_helper_hrfid(cpu_env);
e06fcd75 3844 gen_sync_exception(ctx);
be147d08
JM
3845#endif
3846}
3847#endif
3848
79aceca5 3849/* sc */
417bf010
JM
3850#if defined(CONFIG_USER_ONLY)
3851#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3852#else
3853#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3854#endif
99e300ef 3855static void gen_sc(DisasContext *ctx)
79aceca5 3856{
e1833e1f
JM
3857 uint32_t lev;
3858
3859 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 3860 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
3861}
3862
3863/*** Trap ***/
99e300ef 3864
54623277 3865/* tw */
99e300ef 3866static void gen_tw(DisasContext *ctx)
79aceca5 3867{
cab3bee2 3868 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3869 /* Update the nip since this might generate a trap exception */
3870 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
3871 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
3872 t0);
cab3bee2 3873 tcg_temp_free_i32(t0);
79aceca5
FB
3874}
3875
3876/* twi */
99e300ef 3877static void gen_twi(DisasContext *ctx)
79aceca5 3878{
cab3bee2
AJ
3879 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3880 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3881 /* Update the nip since this might generate a trap exception */
3882 gen_update_nip(ctx, ctx->nip);
e5f17ac6 3883 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
3884 tcg_temp_free(t0);
3885 tcg_temp_free_i32(t1);
79aceca5
FB
3886}
3887
d9bce9d9
JM
3888#if defined(TARGET_PPC64)
3889/* td */
99e300ef 3890static void gen_td(DisasContext *ctx)
d9bce9d9 3891{
cab3bee2 3892 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3893 /* Update the nip since this might generate a trap exception */
3894 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
3895 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
3896 t0);
cab3bee2 3897 tcg_temp_free_i32(t0);
d9bce9d9
JM
3898}
3899
3900/* tdi */
99e300ef 3901static void gen_tdi(DisasContext *ctx)
d9bce9d9 3902{
cab3bee2
AJ
3903 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3904 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3905 /* Update the nip since this might generate a trap exception */
3906 gen_update_nip(ctx, ctx->nip);
e5f17ac6 3907 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
3908 tcg_temp_free(t0);
3909 tcg_temp_free_i32(t1);
d9bce9d9
JM
3910}
3911#endif
3912
79aceca5 3913/*** Processor control ***/
99e300ef 3914
da91a00f
RH
3915static void gen_read_xer(TCGv dst)
3916{
3917 TCGv t0 = tcg_temp_new();
3918 TCGv t1 = tcg_temp_new();
3919 TCGv t2 = tcg_temp_new();
3920 tcg_gen_mov_tl(dst, cpu_xer);
3921 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
3922 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
3923 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
3924 tcg_gen_or_tl(t0, t0, t1);
3925 tcg_gen_or_tl(dst, dst, t2);
3926 tcg_gen_or_tl(dst, dst, t0);
3927 tcg_temp_free(t0);
3928 tcg_temp_free(t1);
3929 tcg_temp_free(t2);
3930}
3931
3932static void gen_write_xer(TCGv src)
3933{
3934 tcg_gen_andi_tl(cpu_xer, src,
3935 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
3936 tcg_gen_shri_tl(cpu_so, src, XER_SO);
3937 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
3938 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
3939 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
3940 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
3941 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
3942}
3943
54623277 3944/* mcrxr */
99e300ef 3945static void gen_mcrxr(DisasContext *ctx)
79aceca5 3946{
da91a00f
RH
3947 TCGv_i32 t0 = tcg_temp_new_i32();
3948 TCGv_i32 t1 = tcg_temp_new_i32();
3949 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
3950
3951 tcg_gen_trunc_tl_i32(t0, cpu_so);
3952 tcg_gen_trunc_tl_i32(t1, cpu_ov);
3953 tcg_gen_trunc_tl_i32(dst, cpu_ca);
3954 tcg_gen_shri_i32(t0, t0, 2);
3955 tcg_gen_shri_i32(t1, t1, 1);
3956 tcg_gen_or_i32(dst, dst, t0);
3957 tcg_gen_or_i32(dst, dst, t1);
3958 tcg_temp_free_i32(t0);
3959 tcg_temp_free_i32(t1);
3960
3961 tcg_gen_movi_tl(cpu_so, 0);
3962 tcg_gen_movi_tl(cpu_ov, 0);
3963 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
3964}
3965
0cfe11ea 3966/* mfcr mfocrf */
99e300ef 3967static void gen_mfcr(DisasContext *ctx)
79aceca5 3968{
76a66253 3969 uint32_t crm, crn;
3b46e624 3970
76a66253
JM
3971 if (likely(ctx->opcode & 0x00100000)) {
3972 crm = CRM(ctx->opcode);
8dd640e4 3973 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 3974 crn = ctz32 (crm);
e1571908 3975 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
3976 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
3977 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 3978 }
d9bce9d9 3979 } else {
651721b2
AJ
3980 TCGv_i32 t0 = tcg_temp_new_i32();
3981 tcg_gen_mov_i32(t0, cpu_crf[0]);
3982 tcg_gen_shli_i32(t0, t0, 4);
3983 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
3984 tcg_gen_shli_i32(t0, t0, 4);
3985 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
3986 tcg_gen_shli_i32(t0, t0, 4);
3987 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
3988 tcg_gen_shli_i32(t0, t0, 4);
3989 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
3990 tcg_gen_shli_i32(t0, t0, 4);
3991 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
3992 tcg_gen_shli_i32(t0, t0, 4);
3993 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
3994 tcg_gen_shli_i32(t0, t0, 4);
3995 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
3996 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
3997 tcg_temp_free_i32(t0);
d9bce9d9 3998 }
79aceca5
FB
3999}
4000
4001/* mfmsr */
99e300ef 4002static void gen_mfmsr(DisasContext *ctx)
79aceca5 4003{
9a64fbe4 4004#if defined(CONFIG_USER_ONLY)
e06fcd75 4005 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4006#else
76db3ba4 4007 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4008 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4009 return;
9a64fbe4 4010 }
6527f6ea 4011 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 4012#endif
79aceca5
FB
4013}
4014
7b13448f 4015static void spr_noaccess(void *opaque, int gprn, int sprn)
3fc6c082 4016{
7b13448f 4017#if 0
3fc6c082
FB
4018 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
4019 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 4020#endif
3fc6c082
FB
4021}
4022#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 4023
79aceca5 4024/* mfspr */
636aa200 4025static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 4026{
45d827d2 4027 void (*read_cb)(void *opaque, int gprn, int sprn);
79aceca5
FB
4028 uint32_t sprn = SPR(ctx->opcode);
4029
3fc6c082 4030#if !defined(CONFIG_USER_ONLY)
76db3ba4 4031 if (ctx->mem_idx == 2)
be147d08 4032 read_cb = ctx->spr_cb[sprn].hea_read;
76db3ba4 4033 else if (ctx->mem_idx)
3fc6c082
FB
4034 read_cb = ctx->spr_cb[sprn].oea_read;
4035 else
9a64fbe4 4036#endif
3fc6c082 4037 read_cb = ctx->spr_cb[sprn].uea_read;
76a66253
JM
4038 if (likely(read_cb != NULL)) {
4039 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 4040 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
4041 } else {
4042 /* Privilege exception */
9fceefa7
JM
4043 /* This is a hack to avoid warnings when running Linux:
4044 * this OS breaks the PowerPC virtualisation model,
4045 * allowing userland application to read the PVR
4046 */
4047 if (sprn != SPR_PVR) {
c05541ee
AB
4048 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4049 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4050 printf("Trying to read privileged spr %d (0x%03x) at "
4051 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
f24e5695 4052 }
e06fcd75 4053 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 4054 }
3fc6c082
FB
4055 } else {
4056 /* Not defined */
c05541ee
AB
4057 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4058 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4059 printf("Trying to read invalid spr %d (0x%03x) at "
4060 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4061 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4062 }
79aceca5
FB
4063}
4064
99e300ef 4065static void gen_mfspr(DisasContext *ctx)
79aceca5 4066{
3fc6c082 4067 gen_op_mfspr(ctx);
76a66253 4068}
3fc6c082
FB
4069
4070/* mftb */
99e300ef 4071static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
4072{
4073 gen_op_mfspr(ctx);
79aceca5
FB
4074}
4075
0cfe11ea 4076/* mtcrf mtocrf*/
99e300ef 4077static void gen_mtcrf(DisasContext *ctx)
79aceca5 4078{
76a66253 4079 uint32_t crm, crn;
3b46e624 4080
76a66253 4081 crm = CRM(ctx->opcode);
8dd640e4 4082 if (likely((ctx->opcode & 0x00100000))) {
4083 if (crm && ((crm & (crm - 1)) == 0)) {
4084 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 4085 crn = ctz32 (crm);
8dd640e4 4086 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
4087 tcg_gen_shri_i32(temp, temp, crn * 4);
4088 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 4089 tcg_temp_free_i32(temp);
4090 }
76a66253 4091 } else {
651721b2
AJ
4092 TCGv_i32 temp = tcg_temp_new_i32();
4093 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
4094 for (crn = 0 ; crn < 8 ; crn++) {
4095 if (crm & (1 << crn)) {
4096 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
4097 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
4098 }
4099 }
a7812ae4 4100 tcg_temp_free_i32(temp);
76a66253 4101 }
79aceca5
FB
4102}
4103
4104/* mtmsr */
426613db 4105#if defined(TARGET_PPC64)
99e300ef 4106static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
4107{
4108#if defined(CONFIG_USER_ONLY)
e06fcd75 4109 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 4110#else
76db3ba4 4111 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4112 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
4113 return;
4114 }
be147d08
JM
4115 if (ctx->opcode & 0x00010000) {
4116 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4117 TCGv t0 = tcg_temp_new();
4118 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4119 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4120 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4121 tcg_temp_free(t0);
be147d08 4122 } else {
056b05f8
JM
4123 /* XXX: we need to update nip before the store
4124 * if we enter power saving mode, we will exit the loop
4125 * directly from ppc_store_msr
4126 */
be147d08 4127 gen_update_nip(ctx, ctx->nip);
e5f17ac6 4128 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
4129 /* Must stop the translation as machine state (may have) changed */
4130 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4131 gen_stop_exception(ctx);
be147d08 4132 }
426613db
JM
4133#endif
4134}
4135#endif
4136
99e300ef 4137static void gen_mtmsr(DisasContext *ctx)
79aceca5 4138{
9a64fbe4 4139#if defined(CONFIG_USER_ONLY)
e06fcd75 4140 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4141#else
76db3ba4 4142 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4143 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4144 return;
9a64fbe4 4145 }
be147d08
JM
4146 if (ctx->opcode & 0x00010000) {
4147 /* Special form that does not need any synchronisation */
6527f6ea
AJ
4148 TCGv t0 = tcg_temp_new();
4149 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
4150 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
4151 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
4152 tcg_temp_free(t0);
be147d08 4153 } else {
8018dc63
AG
4154 TCGv msr = tcg_temp_new();
4155
056b05f8
JM
4156 /* XXX: we need to update nip before the store
4157 * if we enter power saving mode, we will exit the loop
4158 * directly from ppc_store_msr
4159 */
be147d08 4160 gen_update_nip(ctx, ctx->nip);
d9bce9d9 4161#if defined(TARGET_PPC64)
8018dc63
AG
4162 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
4163#else
4164 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 4165#endif
e5f17ac6 4166 gen_helper_store_msr(cpu_env, msr);
be147d08 4167 /* Must stop the translation as machine state (may have) changed */
6527f6ea 4168 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 4169 gen_stop_exception(ctx);
be147d08 4170 }
9a64fbe4 4171#endif
79aceca5
FB
4172}
4173
4174/* mtspr */
99e300ef 4175static void gen_mtspr(DisasContext *ctx)
79aceca5 4176{
45d827d2 4177 void (*write_cb)(void *opaque, int sprn, int gprn);
79aceca5
FB
4178 uint32_t sprn = SPR(ctx->opcode);
4179
3fc6c082 4180#if !defined(CONFIG_USER_ONLY)
76db3ba4 4181 if (ctx->mem_idx == 2)
be147d08 4182 write_cb = ctx->spr_cb[sprn].hea_write;
76db3ba4 4183 else if (ctx->mem_idx)
3fc6c082
FB
4184 write_cb = ctx->spr_cb[sprn].oea_write;
4185 else
9a64fbe4 4186#endif
3fc6c082 4187 write_cb = ctx->spr_cb[sprn].uea_write;
76a66253
JM
4188 if (likely(write_cb != NULL)) {
4189 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 4190 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
4191 } else {
4192 /* Privilege exception */
c05541ee
AB
4193 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4194 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4195 printf("Trying to write privileged spr %d (0x%03x) at "
4196 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4197 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 4198 }
3fc6c082
FB
4199 } else {
4200 /* Not defined */
c05541ee
AB
4201 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4202 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
4203 printf("Trying to write invalid spr %d (0x%03x) at "
4204 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4);
e06fcd75 4205 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 4206 }
79aceca5
FB
4207}
4208
4209/*** Cache management ***/
99e300ef 4210
54623277 4211/* dcbf */
99e300ef 4212static void gen_dcbf(DisasContext *ctx)
79aceca5 4213{
dac454af 4214 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
4215 TCGv t0;
4216 gen_set_access_type(ctx, ACCESS_CACHE);
4217 t0 = tcg_temp_new();
4218 gen_addr_reg_index(ctx, t0);
4219 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4220 tcg_temp_free(t0);
79aceca5
FB
4221}
4222
4223/* dcbi (Supervisor only) */
99e300ef 4224static void gen_dcbi(DisasContext *ctx)
79aceca5 4225{
a541f297 4226#if defined(CONFIG_USER_ONLY)
e06fcd75 4227 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 4228#else
b61f2753 4229 TCGv EA, val;
76db3ba4 4230 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4231 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4232 return;
9a64fbe4 4233 }
a7812ae4 4234 EA = tcg_temp_new();
76db3ba4
AJ
4235 gen_set_access_type(ctx, ACCESS_CACHE);
4236 gen_addr_reg_index(ctx, EA);
a7812ae4 4237 val = tcg_temp_new();
76a66253 4238 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
4239 gen_qemu_ld8u(ctx, val, EA);
4240 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
4241 tcg_temp_free(val);
4242 tcg_temp_free(EA);
a541f297 4243#endif
79aceca5
FB
4244}
4245
4246/* dcdst */
99e300ef 4247static void gen_dcbst(DisasContext *ctx)
79aceca5 4248{
76a66253 4249 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
4250 TCGv t0;
4251 gen_set_access_type(ctx, ACCESS_CACHE);
4252 t0 = tcg_temp_new();
4253 gen_addr_reg_index(ctx, t0);
4254 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4255 tcg_temp_free(t0);
79aceca5
FB
4256}
4257
4258/* dcbt */
99e300ef 4259static void gen_dcbt(DisasContext *ctx)
79aceca5 4260{
0db1b20e 4261 /* interpreted as no-op */
76a66253
JM
4262 /* XXX: specification say this is treated as a load by the MMU
4263 * but does not generate any exception
4264 */
79aceca5
FB
4265}
4266
4267/* dcbtst */
99e300ef 4268static void gen_dcbtst(DisasContext *ctx)
79aceca5 4269{
0db1b20e 4270 /* interpreted as no-op */
76a66253
JM
4271 /* XXX: specification say this is treated as a load by the MMU
4272 * but does not generate any exception
4273 */
79aceca5
FB
4274}
4275
4276/* dcbz */
99e300ef 4277static void gen_dcbz(DisasContext *ctx)
79aceca5 4278{
8e33944f
AG
4279 TCGv tcgv_addr;
4280 TCGv_i32 tcgv_is_dcbzl;
4281 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4282
76db3ba4 4283 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4284 /* NIP cannot be restored if the memory exception comes from an helper */
4285 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4286 tcgv_addr = tcg_temp_new();
4287 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4288
4289 gen_addr_reg_index(ctx, tcgv_addr);
4290 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4291
4292 tcg_temp_free(tcgv_addr);
4293 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4294}
4295
ae1c1a3d 4296/* dst / dstt */
99e300ef 4297static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4298{
4299 if (rA(ctx->opcode) == 0) {
4300 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4301 } else {
4302 /* interpreted as no-op */
4303 }
4304}
4305
4306/* dstst /dststt */
99e300ef 4307static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4308{
4309 if (rA(ctx->opcode) == 0) {
4310 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4311 } else {
4312 /* interpreted as no-op */
4313 }
4314
4315}
4316
4317/* dss / dssall */
99e300ef 4318static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4319{
4320 /* interpreted as no-op */
4321}
4322
79aceca5 4323/* icbi */
99e300ef 4324static void gen_icbi(DisasContext *ctx)
79aceca5 4325{
76db3ba4
AJ
4326 TCGv t0;
4327 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4328 /* NIP cannot be restored if the memory exception comes from an helper */
4329 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4330 t0 = tcg_temp_new();
4331 gen_addr_reg_index(ctx, t0);
2f5a189c 4332 gen_helper_icbi(cpu_env, t0);
37d269df 4333 tcg_temp_free(t0);
79aceca5
FB
4334}
4335
4336/* Optional: */
4337/* dcba */
99e300ef 4338static void gen_dcba(DisasContext *ctx)
79aceca5 4339{
0db1b20e
JM
4340 /* interpreted as no-op */
4341 /* XXX: specification say this is treated as a store by the MMU
4342 * but does not generate any exception
4343 */
79aceca5
FB
4344}
4345
4346/*** Segment register manipulation ***/
4347/* Supervisor only: */
99e300ef 4348
54623277 4349/* mfsr */
99e300ef 4350static void gen_mfsr(DisasContext *ctx)
79aceca5 4351{
9a64fbe4 4352#if defined(CONFIG_USER_ONLY)
e06fcd75 4353 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4354#else
74d37793 4355 TCGv t0;
76db3ba4 4356 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4357 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4358 return;
9a64fbe4 4359 }
74d37793 4360 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4361 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4362 tcg_temp_free(t0);
9a64fbe4 4363#endif
79aceca5
FB
4364}
4365
4366/* mfsrin */
99e300ef 4367static void gen_mfsrin(DisasContext *ctx)
79aceca5 4368{
9a64fbe4 4369#if defined(CONFIG_USER_ONLY)
e06fcd75 4370 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4371#else
74d37793 4372 TCGv t0;
76db3ba4 4373 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4374 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4375 return;
9a64fbe4 4376 }
74d37793
AJ
4377 t0 = tcg_temp_new();
4378 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4379 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4380 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4381 tcg_temp_free(t0);
9a64fbe4 4382#endif
79aceca5
FB
4383}
4384
4385/* mtsr */
99e300ef 4386static void gen_mtsr(DisasContext *ctx)
79aceca5 4387{
9a64fbe4 4388#if defined(CONFIG_USER_ONLY)
e06fcd75 4389 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4390#else
74d37793 4391 TCGv t0;
76db3ba4 4392 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4393 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4394 return;
9a64fbe4 4395 }
74d37793 4396 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4397 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4398 tcg_temp_free(t0);
9a64fbe4 4399#endif
79aceca5
FB
4400}
4401
4402/* mtsrin */
99e300ef 4403static void gen_mtsrin(DisasContext *ctx)
79aceca5 4404{
9a64fbe4 4405#if defined(CONFIG_USER_ONLY)
e06fcd75 4406 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4407#else
74d37793 4408 TCGv t0;
76db3ba4 4409 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4410 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4411 return;
9a64fbe4 4412 }
74d37793
AJ
4413 t0 = tcg_temp_new();
4414 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4415 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4416 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4417 tcg_temp_free(t0);
9a64fbe4 4418#endif
79aceca5
FB
4419}
4420
12de9a39
JM
4421#if defined(TARGET_PPC64)
4422/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4423
54623277 4424/* mfsr */
e8eaa2c0 4425static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4426{
4427#if defined(CONFIG_USER_ONLY)
e06fcd75 4428 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4429#else
74d37793 4430 TCGv t0;
76db3ba4 4431 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4432 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4433 return;
4434 }
74d37793 4435 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4436 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4437 tcg_temp_free(t0);
12de9a39
JM
4438#endif
4439}
4440
4441/* mfsrin */
e8eaa2c0 4442static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4443{
4444#if defined(CONFIG_USER_ONLY)
e06fcd75 4445 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4446#else
74d37793 4447 TCGv t0;
76db3ba4 4448 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4449 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4450 return;
4451 }
74d37793
AJ
4452 t0 = tcg_temp_new();
4453 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4454 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4455 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4456 tcg_temp_free(t0);
12de9a39
JM
4457#endif
4458}
4459
4460/* mtsr */
e8eaa2c0 4461static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4462{
4463#if defined(CONFIG_USER_ONLY)
e06fcd75 4464 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4465#else
74d37793 4466 TCGv t0;
76db3ba4 4467 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4468 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4469 return;
4470 }
74d37793 4471 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4472 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4473 tcg_temp_free(t0);
12de9a39
JM
4474#endif
4475}
4476
4477/* mtsrin */
e8eaa2c0 4478static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4479{
4480#if defined(CONFIG_USER_ONLY)
e06fcd75 4481 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4482#else
74d37793 4483 TCGv t0;
76db3ba4 4484 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4485 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4486 return;
4487 }
74d37793
AJ
4488 t0 = tcg_temp_new();
4489 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4490 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4491 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4492 tcg_temp_free(t0);
12de9a39
JM
4493#endif
4494}
f6b868fc
BS
4495
4496/* slbmte */
e8eaa2c0 4497static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4498{
4499#if defined(CONFIG_USER_ONLY)
4500 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4501#else
4502 if (unlikely(!ctx->mem_idx)) {
4503 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4504 return;
4505 }
c6c7cf05
BS
4506 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4507 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4508#endif
4509}
4510
efdef95f
DG
4511static void gen_slbmfee(DisasContext *ctx)
4512{
4513#if defined(CONFIG_USER_ONLY)
4514 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4515#else
4516 if (unlikely(!ctx->mem_idx)) {
4517 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4518 return;
4519 }
c6c7cf05 4520 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4521 cpu_gpr[rB(ctx->opcode)]);
4522#endif
4523}
4524
4525static void gen_slbmfev(DisasContext *ctx)
4526{
4527#if defined(CONFIG_USER_ONLY)
4528 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4529#else
4530 if (unlikely(!ctx->mem_idx)) {
4531 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4532 return;
4533 }
c6c7cf05 4534 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4535 cpu_gpr[rB(ctx->opcode)]);
4536#endif
4537}
12de9a39
JM
4538#endif /* defined(TARGET_PPC64) */
4539
79aceca5 4540/*** Lookaside buffer management ***/
76db3ba4 4541/* Optional & mem_idx only: */
99e300ef 4542
54623277 4543/* tlbia */
99e300ef 4544static void gen_tlbia(DisasContext *ctx)
79aceca5 4545{
9a64fbe4 4546#if defined(CONFIG_USER_ONLY)
e06fcd75 4547 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4548#else
76db3ba4 4549 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4550 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4551 return;
9a64fbe4 4552 }
c6c7cf05 4553 gen_helper_tlbia(cpu_env);
9a64fbe4 4554#endif
79aceca5
FB
4555}
4556
bf14b1ce 4557/* tlbiel */
99e300ef 4558static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4559{
4560#if defined(CONFIG_USER_ONLY)
4561 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4562#else
4563 if (unlikely(!ctx->mem_idx)) {
4564 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4565 return;
4566 }
c6c7cf05 4567 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4568#endif
4569}
4570
79aceca5 4571/* tlbie */
99e300ef 4572static void gen_tlbie(DisasContext *ctx)
79aceca5 4573{
9a64fbe4 4574#if defined(CONFIG_USER_ONLY)
e06fcd75 4575 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4576#else
76db3ba4 4577 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4578 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4579 return;
9a64fbe4 4580 }
9ca3f7f3 4581 if (NARROW_MODE(ctx)) {
74d37793
AJ
4582 TCGv t0 = tcg_temp_new();
4583 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4584 gen_helper_tlbie(cpu_env, t0);
74d37793 4585 tcg_temp_free(t0);
9ca3f7f3 4586 } else {
c6c7cf05 4587 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9ca3f7f3 4588 }
9a64fbe4 4589#endif
79aceca5
FB
4590}
4591
4592/* tlbsync */
99e300ef 4593static void gen_tlbsync(DisasContext *ctx)
79aceca5 4594{
9a64fbe4 4595#if defined(CONFIG_USER_ONLY)
e06fcd75 4596 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4597#else
76db3ba4 4598 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4599 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4600 return;
9a64fbe4
FB
4601 }
4602 /* This has no effect: it should ensure that all previous
4603 * tlbie have completed
4604 */
e06fcd75 4605 gen_stop_exception(ctx);
9a64fbe4 4606#endif
79aceca5
FB
4607}
4608
426613db
JM
4609#if defined(TARGET_PPC64)
4610/* slbia */
99e300ef 4611static void gen_slbia(DisasContext *ctx)
426613db
JM
4612{
4613#if defined(CONFIG_USER_ONLY)
e06fcd75 4614 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4615#else
76db3ba4 4616 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4617 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4618 return;
4619 }
c6c7cf05 4620 gen_helper_slbia(cpu_env);
426613db
JM
4621#endif
4622}
4623
4624/* slbie */
99e300ef 4625static void gen_slbie(DisasContext *ctx)
426613db
JM
4626{
4627#if defined(CONFIG_USER_ONLY)
e06fcd75 4628 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4629#else
76db3ba4 4630 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4631 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4632 return;
4633 }
c6c7cf05 4634 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4635#endif
4636}
4637#endif
4638
79aceca5
FB
4639/*** External control ***/
4640/* Optional: */
99e300ef 4641
54623277 4642/* eciwx */
99e300ef 4643static void gen_eciwx(DisasContext *ctx)
79aceca5 4644{
76db3ba4 4645 TCGv t0;
fa407c03 4646 /* Should check EAR[E] ! */
76db3ba4
AJ
4647 gen_set_access_type(ctx, ACCESS_EXT);
4648 t0 = tcg_temp_new();
4649 gen_addr_reg_index(ctx, t0);
fa407c03 4650 gen_check_align(ctx, t0, 0x03);
76db3ba4 4651 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4652 tcg_temp_free(t0);
76a66253
JM
4653}
4654
4655/* ecowx */
99e300ef 4656static void gen_ecowx(DisasContext *ctx)
76a66253 4657{
76db3ba4 4658 TCGv t0;
fa407c03 4659 /* Should check EAR[E] ! */
76db3ba4
AJ
4660 gen_set_access_type(ctx, ACCESS_EXT);
4661 t0 = tcg_temp_new();
4662 gen_addr_reg_index(ctx, t0);
fa407c03 4663 gen_check_align(ctx, t0, 0x03);
76db3ba4 4664 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4665 tcg_temp_free(t0);
76a66253
JM
4666}
4667
4668/* PowerPC 601 specific instructions */
99e300ef 4669
54623277 4670/* abs - abs. */
99e300ef 4671static void gen_abs(DisasContext *ctx)
76a66253 4672{
22e0e173
AJ
4673 int l1 = gen_new_label();
4674 int l2 = gen_new_label();
4675 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4676 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4677 tcg_gen_br(l2);
4678 gen_set_label(l1);
4679 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4680 gen_set_label(l2);
76a66253 4681 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4682 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4683}
4684
4685/* abso - abso. */
99e300ef 4686static void gen_abso(DisasContext *ctx)
76a66253 4687{
22e0e173
AJ
4688 int l1 = gen_new_label();
4689 int l2 = gen_new_label();
4690 int l3 = gen_new_label();
4691 /* Start with XER OV disabled, the most likely case */
da91a00f 4692 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4693 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4694 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4695 tcg_gen_movi_tl(cpu_ov, 1);
4696 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4697 tcg_gen_br(l2);
4698 gen_set_label(l1);
4699 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4700 tcg_gen_br(l3);
4701 gen_set_label(l2);
4702 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4703 gen_set_label(l3);
76a66253 4704 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4705 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4706}
4707
4708/* clcs */
99e300ef 4709static void gen_clcs(DisasContext *ctx)
76a66253 4710{
22e0e173 4711 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4712 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4713 tcg_temp_free_i32(t0);
c7697e1f 4714 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
4715}
4716
4717/* div - div. */
99e300ef 4718static void gen_div(DisasContext *ctx)
76a66253 4719{
d15f74fb
BS
4720 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4721 cpu_gpr[rB(ctx->opcode)]);
76a66253 4722 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4723 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4724}
4725
4726/* divo - divo. */
99e300ef 4727static void gen_divo(DisasContext *ctx)
76a66253 4728{
d15f74fb
BS
4729 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4730 cpu_gpr[rB(ctx->opcode)]);
76a66253 4731 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4732 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4733}
4734
4735/* divs - divs. */
99e300ef 4736static void gen_divs(DisasContext *ctx)
76a66253 4737{
d15f74fb
BS
4738 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4739 cpu_gpr[rB(ctx->opcode)]);
76a66253 4740 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4741 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4742}
4743
4744/* divso - divso. */
99e300ef 4745static void gen_divso(DisasContext *ctx)
76a66253 4746{
d15f74fb
BS
4747 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4748 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 4749 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4750 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4751}
4752
4753/* doz - doz. */
99e300ef 4754static void gen_doz(DisasContext *ctx)
76a66253 4755{
22e0e173
AJ
4756 int l1 = gen_new_label();
4757 int l2 = gen_new_label();
4758 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4759 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4760 tcg_gen_br(l2);
4761 gen_set_label(l1);
4762 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4763 gen_set_label(l2);
76a66253 4764 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4765 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4766}
4767
4768/* dozo - dozo. */
99e300ef 4769static void gen_dozo(DisasContext *ctx)
76a66253 4770{
22e0e173
AJ
4771 int l1 = gen_new_label();
4772 int l2 = gen_new_label();
4773 TCGv t0 = tcg_temp_new();
4774 TCGv t1 = tcg_temp_new();
4775 TCGv t2 = tcg_temp_new();
4776 /* Start with XER OV disabled, the most likely case */
da91a00f 4777 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4778 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4779 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4780 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4781 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4782 tcg_gen_andc_tl(t1, t1, t2);
4783 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4784 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
4785 tcg_gen_movi_tl(cpu_ov, 1);
4786 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4787 tcg_gen_br(l2);
4788 gen_set_label(l1);
4789 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4790 gen_set_label(l2);
4791 tcg_temp_free(t0);
4792 tcg_temp_free(t1);
4793 tcg_temp_free(t2);
76a66253 4794 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4795 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4796}
4797
4798/* dozi */
99e300ef 4799static void gen_dozi(DisasContext *ctx)
76a66253 4800{
22e0e173
AJ
4801 target_long simm = SIMM(ctx->opcode);
4802 int l1 = gen_new_label();
4803 int l2 = gen_new_label();
4804 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
4805 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
4806 tcg_gen_br(l2);
4807 gen_set_label(l1);
4808 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4809 gen_set_label(l2);
4810 if (unlikely(Rc(ctx->opcode) != 0))
4811 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4812}
4813
76a66253 4814/* lscbx - lscbx. */
99e300ef 4815static void gen_lscbx(DisasContext *ctx)
76a66253 4816{
bdb4b689
AJ
4817 TCGv t0 = tcg_temp_new();
4818 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
4819 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
4820 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 4821
76db3ba4 4822 gen_addr_reg_index(ctx, t0);
76a66253 4823 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 4824 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 4825 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
4826 tcg_temp_free_i32(t1);
4827 tcg_temp_free_i32(t2);
4828 tcg_temp_free_i32(t3);
3d7b417e 4829 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 4830 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 4831 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
4832 gen_set_Rc0(ctx, t0);
4833 tcg_temp_free(t0);
76a66253
JM
4834}
4835
4836/* maskg - maskg. */
99e300ef 4837static void gen_maskg(DisasContext *ctx)
76a66253 4838{
22e0e173
AJ
4839 int l1 = gen_new_label();
4840 TCGv t0 = tcg_temp_new();
4841 TCGv t1 = tcg_temp_new();
4842 TCGv t2 = tcg_temp_new();
4843 TCGv t3 = tcg_temp_new();
4844 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
4845 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4846 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
4847 tcg_gen_addi_tl(t2, t0, 1);
4848 tcg_gen_shr_tl(t2, t3, t2);
4849 tcg_gen_shr_tl(t3, t3, t1);
4850 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
4851 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
4852 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4853 gen_set_label(l1);
4854 tcg_temp_free(t0);
4855 tcg_temp_free(t1);
4856 tcg_temp_free(t2);
4857 tcg_temp_free(t3);
76a66253 4858 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4859 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4860}
4861
4862/* maskir - maskir. */
99e300ef 4863static void gen_maskir(DisasContext *ctx)
76a66253 4864{
22e0e173
AJ
4865 TCGv t0 = tcg_temp_new();
4866 TCGv t1 = tcg_temp_new();
4867 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4868 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4869 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4870 tcg_temp_free(t0);
4871 tcg_temp_free(t1);
76a66253 4872 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4873 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4874}
4875
4876/* mul - mul. */
99e300ef 4877static void gen_mul(DisasContext *ctx)
76a66253 4878{
22e0e173
AJ
4879 TCGv_i64 t0 = tcg_temp_new_i64();
4880 TCGv_i64 t1 = tcg_temp_new_i64();
4881 TCGv t2 = tcg_temp_new();
4882 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4883 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4884 tcg_gen_mul_i64(t0, t0, t1);
4885 tcg_gen_trunc_i64_tl(t2, t0);
4886 gen_store_spr(SPR_MQ, t2);
4887 tcg_gen_shri_i64(t1, t0, 32);
4888 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4889 tcg_temp_free_i64(t0);
4890 tcg_temp_free_i64(t1);
4891 tcg_temp_free(t2);
76a66253 4892 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4893 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4894}
4895
4896/* mulo - mulo. */
99e300ef 4897static void gen_mulo(DisasContext *ctx)
76a66253 4898{
22e0e173
AJ
4899 int l1 = gen_new_label();
4900 TCGv_i64 t0 = tcg_temp_new_i64();
4901 TCGv_i64 t1 = tcg_temp_new_i64();
4902 TCGv t2 = tcg_temp_new();
4903 /* Start with XER OV disabled, the most likely case */
da91a00f 4904 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4905 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4906 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4907 tcg_gen_mul_i64(t0, t0, t1);
4908 tcg_gen_trunc_i64_tl(t2, t0);
4909 gen_store_spr(SPR_MQ, t2);
4910 tcg_gen_shri_i64(t1, t0, 32);
4911 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4912 tcg_gen_ext32s_i64(t1, t0);
4913 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
4914 tcg_gen_movi_tl(cpu_ov, 1);
4915 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4916 gen_set_label(l1);
4917 tcg_temp_free_i64(t0);
4918 tcg_temp_free_i64(t1);
4919 tcg_temp_free(t2);
76a66253 4920 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4921 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4922}
4923
4924/* nabs - nabs. */
99e300ef 4925static void gen_nabs(DisasContext *ctx)
76a66253 4926{
22e0e173
AJ
4927 int l1 = gen_new_label();
4928 int l2 = gen_new_label();
4929 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4930 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4931 tcg_gen_br(l2);
4932 gen_set_label(l1);
4933 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4934 gen_set_label(l2);
76a66253 4935 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4936 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4937}
4938
4939/* nabso - nabso. */
99e300ef 4940static void gen_nabso(DisasContext *ctx)
76a66253 4941{
22e0e173
AJ
4942 int l1 = gen_new_label();
4943 int l2 = gen_new_label();
4944 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4945 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4946 tcg_gen_br(l2);
4947 gen_set_label(l1);
4948 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4949 gen_set_label(l2);
4950 /* nabs never overflows */
da91a00f 4951 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 4952 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4953 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4954}
4955
4956/* rlmi - rlmi. */
99e300ef 4957static void gen_rlmi(DisasContext *ctx)
76a66253 4958{
7487953d
AJ
4959 uint32_t mb = MB(ctx->opcode);
4960 uint32_t me = ME(ctx->opcode);
4961 TCGv t0 = tcg_temp_new();
4962 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4963 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4964 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
4965 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
4966 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
4967 tcg_temp_free(t0);
76a66253 4968 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4969 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4970}
4971
4972/* rrib - rrib. */
99e300ef 4973static void gen_rrib(DisasContext *ctx)
76a66253 4974{
7487953d
AJ
4975 TCGv t0 = tcg_temp_new();
4976 TCGv t1 = tcg_temp_new();
4977 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4978 tcg_gen_movi_tl(t1, 0x80000000);
4979 tcg_gen_shr_tl(t1, t1, t0);
4980 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4981 tcg_gen_and_tl(t0, t0, t1);
4982 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
4983 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4984 tcg_temp_free(t0);
4985 tcg_temp_free(t1);
76a66253 4986 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4987 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4988}
4989
4990/* sle - sle. */
99e300ef 4991static void gen_sle(DisasContext *ctx)
76a66253 4992{
7487953d
AJ
4993 TCGv t0 = tcg_temp_new();
4994 TCGv t1 = tcg_temp_new();
4995 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4996 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4997 tcg_gen_subfi_tl(t1, 32, t1);
4998 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4999 tcg_gen_or_tl(t1, t0, t1);
5000 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5001 gen_store_spr(SPR_MQ, t1);
5002 tcg_temp_free(t0);
5003 tcg_temp_free(t1);
76a66253 5004 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5005 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5006}
5007
5008/* sleq - sleq. */
99e300ef 5009static void gen_sleq(DisasContext *ctx)
76a66253 5010{
7487953d
AJ
5011 TCGv t0 = tcg_temp_new();
5012 TCGv t1 = tcg_temp_new();
5013 TCGv t2 = tcg_temp_new();
5014 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5015 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
5016 tcg_gen_shl_tl(t2, t2, t0);
5017 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5018 gen_load_spr(t1, SPR_MQ);
5019 gen_store_spr(SPR_MQ, t0);
5020 tcg_gen_and_tl(t0, t0, t2);
5021 tcg_gen_andc_tl(t1, t1, t2);
5022 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5023 tcg_temp_free(t0);
5024 tcg_temp_free(t1);
5025 tcg_temp_free(t2);
76a66253 5026 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5027 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5028}
5029
5030/* sliq - sliq. */
99e300ef 5031static void gen_sliq(DisasContext *ctx)
76a66253 5032{
7487953d
AJ
5033 int sh = SH(ctx->opcode);
5034 TCGv t0 = tcg_temp_new();
5035 TCGv t1 = tcg_temp_new();
5036 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5037 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5038 tcg_gen_or_tl(t1, t0, t1);
5039 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5040 gen_store_spr(SPR_MQ, t1);
5041 tcg_temp_free(t0);
5042 tcg_temp_free(t1);
76a66253 5043 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5044 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5045}
5046
5047/* slliq - slliq. */
99e300ef 5048static void gen_slliq(DisasContext *ctx)
76a66253 5049{
7487953d
AJ
5050 int sh = SH(ctx->opcode);
5051 TCGv t0 = tcg_temp_new();
5052 TCGv t1 = tcg_temp_new();
5053 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5054 gen_load_spr(t1, SPR_MQ);
5055 gen_store_spr(SPR_MQ, t0);
5056 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
5057 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
5058 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5059 tcg_temp_free(t0);
5060 tcg_temp_free(t1);
76a66253 5061 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5062 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5063}
5064
5065/* sllq - sllq. */
99e300ef 5066static void gen_sllq(DisasContext *ctx)
76a66253 5067{
7487953d
AJ
5068 int l1 = gen_new_label();
5069 int l2 = gen_new_label();
5070 TCGv t0 = tcg_temp_local_new();
5071 TCGv t1 = tcg_temp_local_new();
5072 TCGv t2 = tcg_temp_local_new();
5073 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5074 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5075 tcg_gen_shl_tl(t1, t1, t2);
5076 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5077 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5078 gen_load_spr(t0, SPR_MQ);
5079 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5080 tcg_gen_br(l2);
5081 gen_set_label(l1);
5082 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5083 gen_load_spr(t2, SPR_MQ);
5084 tcg_gen_andc_tl(t1, t2, t1);
5085 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5086 gen_set_label(l2);
5087 tcg_temp_free(t0);
5088 tcg_temp_free(t1);
5089 tcg_temp_free(t2);
76a66253 5090 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5091 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5092}
5093
5094/* slq - slq. */
99e300ef 5095static void gen_slq(DisasContext *ctx)
76a66253 5096{
7487953d
AJ
5097 int l1 = gen_new_label();
5098 TCGv t0 = tcg_temp_new();
5099 TCGv t1 = tcg_temp_new();
5100 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5101 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5102 tcg_gen_subfi_tl(t1, 32, t1);
5103 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5104 tcg_gen_or_tl(t1, t0, t1);
5105 gen_store_spr(SPR_MQ, t1);
5106 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5107 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5108 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5109 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5110 gen_set_label(l1);
5111 tcg_temp_free(t0);
5112 tcg_temp_free(t1);
76a66253 5113 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5114 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5115}
5116
d9bce9d9 5117/* sraiq - sraiq. */
99e300ef 5118static void gen_sraiq(DisasContext *ctx)
76a66253 5119{
7487953d
AJ
5120 int sh = SH(ctx->opcode);
5121 int l1 = gen_new_label();
5122 TCGv t0 = tcg_temp_new();
5123 TCGv t1 = tcg_temp_new();
5124 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5125 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5126 tcg_gen_or_tl(t0, t0, t1);
5127 gen_store_spr(SPR_MQ, t0);
da91a00f 5128 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5129 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
5130 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 5131 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5132 gen_set_label(l1);
5133 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
5134 tcg_temp_free(t0);
5135 tcg_temp_free(t1);
76a66253 5136 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5137 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5138}
5139
5140/* sraq - sraq. */
99e300ef 5141static void gen_sraq(DisasContext *ctx)
76a66253 5142{
7487953d
AJ
5143 int l1 = gen_new_label();
5144 int l2 = gen_new_label();
5145 TCGv t0 = tcg_temp_new();
5146 TCGv t1 = tcg_temp_local_new();
5147 TCGv t2 = tcg_temp_local_new();
5148 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5149 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5150 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
5151 tcg_gen_subfi_tl(t2, 32, t2);
5152 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
5153 tcg_gen_or_tl(t0, t0, t2);
5154 gen_store_spr(SPR_MQ, t0);
5155 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5156 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
5157 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
5158 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
5159 gen_set_label(l1);
5160 tcg_temp_free(t0);
5161 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 5162 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
5163 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
5164 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 5165 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
5166 gen_set_label(l2);
5167 tcg_temp_free(t1);
5168 tcg_temp_free(t2);
76a66253 5169 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5170 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5171}
5172
5173/* sre - sre. */
99e300ef 5174static void gen_sre(DisasContext *ctx)
76a66253 5175{
7487953d
AJ
5176 TCGv t0 = tcg_temp_new();
5177 TCGv t1 = tcg_temp_new();
5178 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5179 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5180 tcg_gen_subfi_tl(t1, 32, t1);
5181 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5182 tcg_gen_or_tl(t1, t0, t1);
5183 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5184 gen_store_spr(SPR_MQ, t1);
5185 tcg_temp_free(t0);
5186 tcg_temp_free(t1);
76a66253 5187 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5188 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5189}
5190
5191/* srea - srea. */
99e300ef 5192static void gen_srea(DisasContext *ctx)
76a66253 5193{
7487953d
AJ
5194 TCGv t0 = tcg_temp_new();
5195 TCGv t1 = tcg_temp_new();
5196 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5197 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5198 gen_store_spr(SPR_MQ, t0);
5199 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
5200 tcg_temp_free(t0);
5201 tcg_temp_free(t1);
76a66253 5202 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5203 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5204}
5205
5206/* sreq */
99e300ef 5207static void gen_sreq(DisasContext *ctx)
76a66253 5208{
7487953d
AJ
5209 TCGv t0 = tcg_temp_new();
5210 TCGv t1 = tcg_temp_new();
5211 TCGv t2 = tcg_temp_new();
5212 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
5213 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5214 tcg_gen_shr_tl(t1, t1, t0);
5215 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
5216 gen_load_spr(t2, SPR_MQ);
5217 gen_store_spr(SPR_MQ, t0);
5218 tcg_gen_and_tl(t0, t0, t1);
5219 tcg_gen_andc_tl(t2, t2, t1);
5220 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5221 tcg_temp_free(t0);
5222 tcg_temp_free(t1);
5223 tcg_temp_free(t2);
76a66253 5224 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5225 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5226}
5227
5228/* sriq */
99e300ef 5229static void gen_sriq(DisasContext *ctx)
76a66253 5230{
7487953d
AJ
5231 int sh = SH(ctx->opcode);
5232 TCGv t0 = tcg_temp_new();
5233 TCGv t1 = tcg_temp_new();
5234 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5235 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
5236 tcg_gen_or_tl(t1, t0, t1);
5237 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5238 gen_store_spr(SPR_MQ, t1);
5239 tcg_temp_free(t0);
5240 tcg_temp_free(t1);
76a66253 5241 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5242 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5243}
5244
5245/* srliq */
99e300ef 5246static void gen_srliq(DisasContext *ctx)
76a66253 5247{
7487953d
AJ
5248 int sh = SH(ctx->opcode);
5249 TCGv t0 = tcg_temp_new();
5250 TCGv t1 = tcg_temp_new();
5251 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
5252 gen_load_spr(t1, SPR_MQ);
5253 gen_store_spr(SPR_MQ, t0);
5254 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5255 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5256 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5257 tcg_temp_free(t0);
5258 tcg_temp_free(t1);
76a66253 5259 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5260 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5261}
5262
5263/* srlq */
99e300ef 5264static void gen_srlq(DisasContext *ctx)
76a66253 5265{
7487953d
AJ
5266 int l1 = gen_new_label();
5267 int l2 = gen_new_label();
5268 TCGv t0 = tcg_temp_local_new();
5269 TCGv t1 = tcg_temp_local_new();
5270 TCGv t2 = tcg_temp_local_new();
5271 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5272 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5273 tcg_gen_shr_tl(t2, t1, t2);
5274 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5275 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5276 gen_load_spr(t0, SPR_MQ);
5277 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5278 tcg_gen_br(l2);
5279 gen_set_label(l1);
5280 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5281 tcg_gen_and_tl(t0, t0, t2);
5282 gen_load_spr(t1, SPR_MQ);
5283 tcg_gen_andc_tl(t1, t1, t2);
5284 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5285 gen_set_label(l2);
5286 tcg_temp_free(t0);
5287 tcg_temp_free(t1);
5288 tcg_temp_free(t2);
76a66253 5289 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5290 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5291}
5292
5293/* srq */
99e300ef 5294static void gen_srq(DisasContext *ctx)
76a66253 5295{
7487953d
AJ
5296 int l1 = gen_new_label();
5297 TCGv t0 = tcg_temp_new();
5298 TCGv t1 = tcg_temp_new();
5299 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5300 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5301 tcg_gen_subfi_tl(t1, 32, t1);
5302 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5303 tcg_gen_or_tl(t1, t0, t1);
5304 gen_store_spr(SPR_MQ, t1);
5305 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5306 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5307 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5308 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5309 gen_set_label(l1);
5310 tcg_temp_free(t0);
5311 tcg_temp_free(t1);
76a66253 5312 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5313 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5314}
5315
5316/* PowerPC 602 specific instructions */
99e300ef 5317
54623277 5318/* dsa */
99e300ef 5319static void gen_dsa(DisasContext *ctx)
76a66253
JM
5320{
5321 /* XXX: TODO */
e06fcd75 5322 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5323}
5324
5325/* esa */
99e300ef 5326static void gen_esa(DisasContext *ctx)
76a66253
JM
5327{
5328 /* XXX: TODO */
e06fcd75 5329 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5330}
5331
5332/* mfrom */
99e300ef 5333static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5334{
5335#if defined(CONFIG_USER_ONLY)
e06fcd75 5336 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5337#else
76db3ba4 5338 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5339 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5340 return;
5341 }
cf02a65c 5342 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5343#endif
5344}
5345
5346/* 602 - 603 - G2 TLB management */
e8eaa2c0 5347
54623277 5348/* tlbld */
e8eaa2c0 5349static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5350{
5351#if defined(CONFIG_USER_ONLY)
e06fcd75 5352 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5353#else
76db3ba4 5354 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5355 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5356 return;
5357 }
c6c7cf05 5358 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5359#endif
5360}
5361
5362/* tlbli */
e8eaa2c0 5363static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5364{
5365#if defined(CONFIG_USER_ONLY)
e06fcd75 5366 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5367#else
76db3ba4 5368 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5369 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5370 return;
5371 }
c6c7cf05 5372 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5373#endif
5374}
5375
7dbe11ac 5376/* 74xx TLB management */
e8eaa2c0 5377
54623277 5378/* tlbld */
e8eaa2c0 5379static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5380{
5381#if defined(CONFIG_USER_ONLY)
e06fcd75 5382 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5383#else
76db3ba4 5384 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5385 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5386 return;
5387 }
c6c7cf05 5388 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5389#endif
5390}
5391
5392/* tlbli */
e8eaa2c0 5393static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5394{
5395#if defined(CONFIG_USER_ONLY)
e06fcd75 5396 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5397#else
76db3ba4 5398 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5399 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5400 return;
5401 }
c6c7cf05 5402 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5403#endif
5404}
5405
76a66253 5406/* POWER instructions not in PowerPC 601 */
99e300ef 5407
54623277 5408/* clf */
99e300ef 5409static void gen_clf(DisasContext *ctx)
76a66253
JM
5410{
5411 /* Cache line flush: implemented as no-op */
5412}
5413
5414/* cli */
99e300ef 5415static void gen_cli(DisasContext *ctx)
76a66253 5416{
7f75ffd3 5417 /* Cache line invalidate: privileged and treated as no-op */
76a66253 5418#if defined(CONFIG_USER_ONLY)
e06fcd75 5419 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5420#else
76db3ba4 5421 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5422 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5423 return;
5424 }
5425#endif
5426}
5427
5428/* dclst */
99e300ef 5429static void gen_dclst(DisasContext *ctx)
76a66253
JM
5430{
5431 /* Data cache line store: treated as no-op */
5432}
5433
99e300ef 5434static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5435{
5436#if defined(CONFIG_USER_ONLY)
e06fcd75 5437 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5438#else
74d37793
AJ
5439 int ra = rA(ctx->opcode);
5440 int rd = rD(ctx->opcode);
5441 TCGv t0;
76db3ba4 5442 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5443 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5444 return;
5445 }
74d37793 5446 t0 = tcg_temp_new();
76db3ba4 5447 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5448 tcg_gen_shri_tl(t0, t0, 28);
5449 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5450 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5451 tcg_temp_free(t0);
76a66253 5452 if (ra != 0 && ra != rd)
74d37793 5453 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5454#endif
5455}
5456
99e300ef 5457static void gen_rac(DisasContext *ctx)
76a66253
JM
5458{
5459#if defined(CONFIG_USER_ONLY)
e06fcd75 5460 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5461#else
22e0e173 5462 TCGv t0;
76db3ba4 5463 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5464 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5465 return;
5466 }
22e0e173 5467 t0 = tcg_temp_new();
76db3ba4 5468 gen_addr_reg_index(ctx, t0);
c6c7cf05 5469 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5470 tcg_temp_free(t0);
76a66253
JM
5471#endif
5472}
5473
99e300ef 5474static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5475{
5476#if defined(CONFIG_USER_ONLY)
e06fcd75 5477 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5478#else
76db3ba4 5479 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5480 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5481 return;
5482 }
e5f17ac6 5483 gen_helper_rfsvc(cpu_env);
e06fcd75 5484 gen_sync_exception(ctx);
76a66253
JM
5485#endif
5486}
5487
5488/* svc is not implemented for now */
5489
5490/* POWER2 specific instructions */
5491/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5492
5493/* lfq */
99e300ef 5494static void gen_lfq(DisasContext *ctx)
76a66253 5495{
01a4afeb 5496 int rd = rD(ctx->opcode);
76db3ba4
AJ
5497 TCGv t0;
5498 gen_set_access_type(ctx, ACCESS_FLOAT);
5499 t0 = tcg_temp_new();
5500 gen_addr_imm_index(ctx, t0, 0);
5501 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5502 gen_addr_add(ctx, t0, t0, 8);
5503 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5504 tcg_temp_free(t0);
76a66253
JM
5505}
5506
5507/* lfqu */
99e300ef 5508static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5509{
5510 int ra = rA(ctx->opcode);
01a4afeb 5511 int rd = rD(ctx->opcode);
76db3ba4
AJ
5512 TCGv t0, t1;
5513 gen_set_access_type(ctx, ACCESS_FLOAT);
5514 t0 = tcg_temp_new();
5515 t1 = tcg_temp_new();
5516 gen_addr_imm_index(ctx, t0, 0);
5517 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5518 gen_addr_add(ctx, t1, t0, 8);
5519 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5520 if (ra != 0)
01a4afeb
AJ
5521 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5522 tcg_temp_free(t0);
5523 tcg_temp_free(t1);
76a66253
JM
5524}
5525
5526/* lfqux */
99e300ef 5527static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5528{
5529 int ra = rA(ctx->opcode);
01a4afeb 5530 int rd = rD(ctx->opcode);
76db3ba4
AJ
5531 gen_set_access_type(ctx, ACCESS_FLOAT);
5532 TCGv t0, t1;
5533 t0 = tcg_temp_new();
5534 gen_addr_reg_index(ctx, t0);
5535 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5536 t1 = tcg_temp_new();
5537 gen_addr_add(ctx, t1, t0, 8);
5538 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5539 tcg_temp_free(t1);
76a66253 5540 if (ra != 0)
01a4afeb
AJ
5541 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5542 tcg_temp_free(t0);
76a66253
JM
5543}
5544
5545/* lfqx */
99e300ef 5546static void gen_lfqx(DisasContext *ctx)
76a66253 5547{
01a4afeb 5548 int rd = rD(ctx->opcode);
76db3ba4
AJ
5549 TCGv t0;
5550 gen_set_access_type(ctx, ACCESS_FLOAT);
5551 t0 = tcg_temp_new();
5552 gen_addr_reg_index(ctx, t0);
5553 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5554 gen_addr_add(ctx, t0, t0, 8);
5555 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5556 tcg_temp_free(t0);
76a66253
JM
5557}
5558
5559/* stfq */
99e300ef 5560static void gen_stfq(DisasContext *ctx)
76a66253 5561{
01a4afeb 5562 int rd = rD(ctx->opcode);
76db3ba4
AJ
5563 TCGv t0;
5564 gen_set_access_type(ctx, ACCESS_FLOAT);
5565 t0 = tcg_temp_new();
5566 gen_addr_imm_index(ctx, t0, 0);
5567 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5568 gen_addr_add(ctx, t0, t0, 8);
5569 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5570 tcg_temp_free(t0);
76a66253
JM
5571}
5572
5573/* stfqu */
99e300ef 5574static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5575{
5576 int ra = rA(ctx->opcode);
01a4afeb 5577 int rd = rD(ctx->opcode);
76db3ba4
AJ
5578 TCGv t0, t1;
5579 gen_set_access_type(ctx, ACCESS_FLOAT);
5580 t0 = tcg_temp_new();
5581 gen_addr_imm_index(ctx, t0, 0);
5582 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5583 t1 = tcg_temp_new();
5584 gen_addr_add(ctx, t1, t0, 8);
5585 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5586 tcg_temp_free(t1);
76a66253 5587 if (ra != 0)
01a4afeb
AJ
5588 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5589 tcg_temp_free(t0);
76a66253
JM
5590}
5591
5592/* stfqux */
99e300ef 5593static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5594{
5595 int ra = rA(ctx->opcode);
01a4afeb 5596 int rd = rD(ctx->opcode);
76db3ba4
AJ
5597 TCGv t0, t1;
5598 gen_set_access_type(ctx, ACCESS_FLOAT);
5599 t0 = tcg_temp_new();
5600 gen_addr_reg_index(ctx, t0);
5601 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5602 t1 = tcg_temp_new();
5603 gen_addr_add(ctx, t1, t0, 8);
5604 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5605 tcg_temp_free(t1);
76a66253 5606 if (ra != 0)
01a4afeb
AJ
5607 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5608 tcg_temp_free(t0);
76a66253
JM
5609}
5610
5611/* stfqx */
99e300ef 5612static void gen_stfqx(DisasContext *ctx)
76a66253 5613{
01a4afeb 5614 int rd = rD(ctx->opcode);
76db3ba4
AJ
5615 TCGv t0;
5616 gen_set_access_type(ctx, ACCESS_FLOAT);
5617 t0 = tcg_temp_new();
5618 gen_addr_reg_index(ctx, t0);
5619 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5620 gen_addr_add(ctx, t0, t0, 8);
5621 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5622 tcg_temp_free(t0);
76a66253
JM
5623}
5624
5625/* BookE specific instructions */
99e300ef 5626
54623277 5627/* XXX: not implemented on 440 ? */
99e300ef 5628static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5629{
5630 /* XXX: TODO */
e06fcd75 5631 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5632}
5633
2662a059 5634/* XXX: not implemented on 440 ? */
99e300ef 5635static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5636{
5637#if defined(CONFIG_USER_ONLY)
e06fcd75 5638 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5639#else
74d37793 5640 TCGv t0;
76db3ba4 5641 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5642 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5643 return;
5644 }
ec72e276 5645 t0 = tcg_temp_new();
76db3ba4 5646 gen_addr_reg_index(ctx, t0);
c6c7cf05 5647 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5648 tcg_temp_free(t0);
76a66253
JM
5649#endif
5650}
5651
5652/* All 405 MAC instructions are translated here */
636aa200
BS
5653static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5654 int ra, int rb, int rt, int Rc)
76a66253 5655{
182608d4
AJ
5656 TCGv t0, t1;
5657
a7812ae4
PB
5658 t0 = tcg_temp_local_new();
5659 t1 = tcg_temp_local_new();
182608d4 5660
76a66253
JM
5661 switch (opc3 & 0x0D) {
5662 case 0x05:
5663 /* macchw - macchw. - macchwo - macchwo. */
5664 /* macchws - macchws. - macchwso - macchwso. */
5665 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5666 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5667 /* mulchw - mulchw. */
182608d4
AJ
5668 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5669 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5670 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5671 break;
5672 case 0x04:
5673 /* macchwu - macchwu. - macchwuo - macchwuo. */
5674 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5675 /* mulchwu - mulchwu. */
182608d4
AJ
5676 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5677 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5678 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5679 break;
5680 case 0x01:
5681 /* machhw - machhw. - machhwo - machhwo. */
5682 /* machhws - machhws. - machhwso - machhwso. */
5683 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5684 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5685 /* mulhhw - mulhhw. */
182608d4
AJ
5686 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5687 tcg_gen_ext16s_tl(t0, t0);
5688 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5689 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5690 break;
5691 case 0x00:
5692 /* machhwu - machhwu. - machhwuo - machhwuo. */
5693 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5694 /* mulhhwu - mulhhwu. */
182608d4
AJ
5695 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5696 tcg_gen_ext16u_tl(t0, t0);
5697 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5698 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5699 break;
5700 case 0x0D:
5701 /* maclhw - maclhw. - maclhwo - maclhwo. */
5702 /* maclhws - maclhws. - maclhwso - maclhwso. */
5703 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5704 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5705 /* mullhw - mullhw. */
182608d4
AJ
5706 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5707 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5708 break;
5709 case 0x0C:
5710 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5711 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5712 /* mullhwu - mullhwu. */
182608d4
AJ
5713 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5714 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
5715 break;
5716 }
76a66253 5717 if (opc2 & 0x04) {
182608d4
AJ
5718 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5719 tcg_gen_mul_tl(t1, t0, t1);
5720 if (opc2 & 0x02) {
5721 /* nmultiply-and-accumulate (0x0E) */
5722 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5723 } else {
5724 /* multiply-and-accumulate (0x0C) */
5725 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5726 }
5727
5728 if (opc3 & 0x12) {
5729 /* Check overflow and/or saturate */
5730 int l1 = gen_new_label();
5731
5732 if (opc3 & 0x10) {
5733 /* Start with XER OV disabled, the most likely case */
da91a00f 5734 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
5735 }
5736 if (opc3 & 0x01) {
5737 /* Signed */
5738 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5739 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5740 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5741 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 5742 if (opc3 & 0x02) {
182608d4
AJ
5743 /* Saturate */
5744 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5745 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5746 }
5747 } else {
5748 /* Unsigned */
5749 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 5750 if (opc3 & 0x02) {
182608d4
AJ
5751 /* Saturate */
5752 tcg_gen_movi_tl(t0, UINT32_MAX);
5753 }
5754 }
5755 if (opc3 & 0x10) {
5756 /* Check overflow */
da91a00f
RH
5757 tcg_gen_movi_tl(cpu_ov, 1);
5758 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
5759 }
5760 gen_set_label(l1);
5761 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5762 }
5763 } else {
5764 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 5765 }
182608d4
AJ
5766 tcg_temp_free(t0);
5767 tcg_temp_free(t1);
76a66253
JM
5768 if (unlikely(Rc) != 0) {
5769 /* Update Rc0 */
182608d4 5770 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
5771 }
5772}
5773
a750fc0b 5774#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 5775static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
5776{ \
5777 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5778 rD(ctx->opcode), Rc(ctx->opcode)); \
5779}
5780
5781/* macchw - macchw. */
a750fc0b 5782GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 5783/* macchwo - macchwo. */
a750fc0b 5784GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 5785/* macchws - macchws. */
a750fc0b 5786GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 5787/* macchwso - macchwso. */
a750fc0b 5788GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 5789/* macchwsu - macchwsu. */
a750fc0b 5790GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 5791/* macchwsuo - macchwsuo. */
a750fc0b 5792GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 5793/* macchwu - macchwu. */
a750fc0b 5794GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 5795/* macchwuo - macchwuo. */
a750fc0b 5796GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 5797/* machhw - machhw. */
a750fc0b 5798GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 5799/* machhwo - machhwo. */
a750fc0b 5800GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 5801/* machhws - machhws. */
a750fc0b 5802GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 5803/* machhwso - machhwso. */
a750fc0b 5804GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 5805/* machhwsu - machhwsu. */
a750fc0b 5806GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 5807/* machhwsuo - machhwsuo. */
a750fc0b 5808GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 5809/* machhwu - machhwu. */
a750fc0b 5810GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 5811/* machhwuo - machhwuo. */
a750fc0b 5812GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 5813/* maclhw - maclhw. */
a750fc0b 5814GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 5815/* maclhwo - maclhwo. */
a750fc0b 5816GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 5817/* maclhws - maclhws. */
a750fc0b 5818GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 5819/* maclhwso - maclhwso. */
a750fc0b 5820GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 5821/* maclhwu - maclhwu. */
a750fc0b 5822GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 5823/* maclhwuo - maclhwuo. */
a750fc0b 5824GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 5825/* maclhwsu - maclhwsu. */
a750fc0b 5826GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 5827/* maclhwsuo - maclhwsuo. */
a750fc0b 5828GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 5829/* nmacchw - nmacchw. */
a750fc0b 5830GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 5831/* nmacchwo - nmacchwo. */
a750fc0b 5832GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 5833/* nmacchws - nmacchws. */
a750fc0b 5834GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 5835/* nmacchwso - nmacchwso. */
a750fc0b 5836GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 5837/* nmachhw - nmachhw. */
a750fc0b 5838GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 5839/* nmachhwo - nmachhwo. */
a750fc0b 5840GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 5841/* nmachhws - nmachhws. */
a750fc0b 5842GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 5843/* nmachhwso - nmachhwso. */
a750fc0b 5844GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 5845/* nmaclhw - nmaclhw. */
a750fc0b 5846GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 5847/* nmaclhwo - nmaclhwo. */
a750fc0b 5848GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 5849/* nmaclhws - nmaclhws. */
a750fc0b 5850GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 5851/* nmaclhwso - nmaclhwso. */
a750fc0b 5852GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
5853
5854/* mulchw - mulchw. */
a750fc0b 5855GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 5856/* mulchwu - mulchwu. */
a750fc0b 5857GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 5858/* mulhhw - mulhhw. */
a750fc0b 5859GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 5860/* mulhhwu - mulhhwu. */
a750fc0b 5861GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 5862/* mullhw - mullhw. */
a750fc0b 5863GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 5864/* mullhwu - mullhwu. */
a750fc0b 5865GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
5866
5867/* mfdcr */
99e300ef 5868static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
5869{
5870#if defined(CONFIG_USER_ONLY)
e06fcd75 5871 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 5872#else
06dca6a7 5873 TCGv dcrn;
76db3ba4 5874 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5875 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
5876 return;
5877 }
06dca6a7
AJ
5878 /* NIP cannot be restored if the memory exception comes from an helper */
5879 gen_update_nip(ctx, ctx->nip - 4);
5880 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 5881 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 5882 tcg_temp_free(dcrn);
76a66253
JM
5883#endif
5884}
5885
5886/* mtdcr */
99e300ef 5887static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
5888{
5889#if defined(CONFIG_USER_ONLY)
e06fcd75 5890 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 5891#else
06dca6a7 5892 TCGv dcrn;
76db3ba4 5893 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5894 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
5895 return;
5896 }
06dca6a7
AJ
5897 /* NIP cannot be restored if the memory exception comes from an helper */
5898 gen_update_nip(ctx, ctx->nip - 4);
5899 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 5900 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 5901 tcg_temp_free(dcrn);
a42bd6cc
JM
5902#endif
5903}
5904
5905/* mfdcrx */
2662a059 5906/* XXX: not implemented on 440 ? */
99e300ef 5907static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
5908{
5909#if defined(CONFIG_USER_ONLY)
e06fcd75 5910 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 5911#else
76db3ba4 5912 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5913 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
5914 return;
5915 }
06dca6a7
AJ
5916 /* NIP cannot be restored if the memory exception comes from an helper */
5917 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
5918 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
5919 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 5920 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
5921#endif
5922}
5923
5924/* mtdcrx */
2662a059 5925/* XXX: not implemented on 440 ? */
99e300ef 5926static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
5927{
5928#if defined(CONFIG_USER_ONLY)
e06fcd75 5929 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 5930#else
76db3ba4 5931 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5932 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
5933 return;
5934 }
06dca6a7
AJ
5935 /* NIP cannot be restored if the memory exception comes from an helper */
5936 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
5937 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
5938 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 5939 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
5940#endif
5941}
5942
a750fc0b 5943/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 5944static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 5945{
06dca6a7
AJ
5946 /* NIP cannot be restored if the memory exception comes from an helper */
5947 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
5948 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
5949 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
5950 /* Note: Rc update flag set leads to undefined state of Rc0 */
5951}
5952
5953/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 5954static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 5955{
06dca6a7
AJ
5956 /* NIP cannot be restored if the memory exception comes from an helper */
5957 gen_update_nip(ctx, ctx->nip - 4);
975e5463 5958 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 5959 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
5960 /* Note: Rc update flag set leads to undefined state of Rc0 */
5961}
5962
76a66253 5963/* dccci */
99e300ef 5964static void gen_dccci(DisasContext *ctx)
76a66253
JM
5965{
5966#if defined(CONFIG_USER_ONLY)
e06fcd75 5967 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5968#else
76db3ba4 5969 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5970 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5971 return;
5972 }
5973 /* interpreted as no-op */
5974#endif
5975}
5976
5977/* dcread */
99e300ef 5978static void gen_dcread(DisasContext *ctx)
76a66253
JM
5979{
5980#if defined(CONFIG_USER_ONLY)
e06fcd75 5981 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5982#else
b61f2753 5983 TCGv EA, val;
76db3ba4 5984 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5985 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5986 return;
5987 }
76db3ba4 5988 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 5989 EA = tcg_temp_new();
76db3ba4 5990 gen_addr_reg_index(ctx, EA);
a7812ae4 5991 val = tcg_temp_new();
76db3ba4 5992 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
5993 tcg_temp_free(val);
5994 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5995 tcg_temp_free(EA);
76a66253
JM
5996#endif
5997}
5998
5999/* icbt */
e8eaa2c0 6000static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
6001{
6002 /* interpreted as no-op */
6003 /* XXX: specification say this is treated as a load by the MMU
6004 * but does not generate any exception
6005 */
6006}
6007
6008/* iccci */
99e300ef 6009static void gen_iccci(DisasContext *ctx)
76a66253
JM
6010{
6011#if defined(CONFIG_USER_ONLY)
e06fcd75 6012 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6013#else
76db3ba4 6014 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6015 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6016 return;
6017 }
6018 /* interpreted as no-op */
6019#endif
6020}
6021
6022/* icread */
99e300ef 6023static void gen_icread(DisasContext *ctx)
76a66253
JM
6024{
6025#if defined(CONFIG_USER_ONLY)
e06fcd75 6026 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6027#else
76db3ba4 6028 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6029 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6030 return;
6031 }
6032 /* interpreted as no-op */
6033#endif
6034}
6035
76db3ba4 6036/* rfci (mem_idx only) */
e8eaa2c0 6037static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
6038{
6039#if defined(CONFIG_USER_ONLY)
e06fcd75 6040 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6041#else
76db3ba4 6042 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6043 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6044 return;
6045 }
6046 /* Restore CPU state */
e5f17ac6 6047 gen_helper_40x_rfci(cpu_env);
e06fcd75 6048 gen_sync_exception(ctx);
a42bd6cc
JM
6049#endif
6050}
6051
99e300ef 6052static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
6053{
6054#if defined(CONFIG_USER_ONLY)
e06fcd75 6055 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6056#else
76db3ba4 6057 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6058 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6059 return;
6060 }
6061 /* Restore CPU state */
e5f17ac6 6062 gen_helper_rfci(cpu_env);
e06fcd75 6063 gen_sync_exception(ctx);
a42bd6cc
JM
6064#endif
6065}
6066
6067/* BookE specific */
99e300ef 6068
54623277 6069/* XXX: not implemented on 440 ? */
99e300ef 6070static void gen_rfdi(DisasContext *ctx)
76a66253
JM
6071{
6072#if defined(CONFIG_USER_ONLY)
e06fcd75 6073 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6074#else
76db3ba4 6075 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6076 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6077 return;
6078 }
6079 /* Restore CPU state */
e5f17ac6 6080 gen_helper_rfdi(cpu_env);
e06fcd75 6081 gen_sync_exception(ctx);
76a66253
JM
6082#endif
6083}
6084
2662a059 6085/* XXX: not implemented on 440 ? */
99e300ef 6086static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
6087{
6088#if defined(CONFIG_USER_ONLY)
e06fcd75 6089 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 6090#else
76db3ba4 6091 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6092 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
6093 return;
6094 }
6095 /* Restore CPU state */
e5f17ac6 6096 gen_helper_rfmci(cpu_env);
e06fcd75 6097 gen_sync_exception(ctx);
a42bd6cc
JM
6098#endif
6099}
5eb7995e 6100
d9bce9d9 6101/* TLB management - PowerPC 405 implementation */
e8eaa2c0 6102
54623277 6103/* tlbre */
e8eaa2c0 6104static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
6105{
6106#if defined(CONFIG_USER_ONLY)
e06fcd75 6107 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6108#else
76db3ba4 6109 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6110 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6111 return;
6112 }
6113 switch (rB(ctx->opcode)) {
6114 case 0:
c6c7cf05
BS
6115 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
6116 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6117 break;
6118 case 1:
c6c7cf05
BS
6119 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
6120 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
6121 break;
6122 default:
e06fcd75 6123 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6124 break;
9a64fbe4 6125 }
76a66253
JM
6126#endif
6127}
6128
d9bce9d9 6129/* tlbsx - tlbsx. */
e8eaa2c0 6130static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
6131{
6132#if defined(CONFIG_USER_ONLY)
e06fcd75 6133 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6134#else
74d37793 6135 TCGv t0;
76db3ba4 6136 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6137 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6138 return;
6139 }
74d37793 6140 t0 = tcg_temp_new();
76db3ba4 6141 gen_addr_reg_index(ctx, t0);
c6c7cf05 6142 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6143 tcg_temp_free(t0);
6144 if (Rc(ctx->opcode)) {
6145 int l1 = gen_new_label();
da91a00f 6146 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6147 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6148 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6149 gen_set_label(l1);
6150 }
76a66253 6151#endif
79aceca5
FB
6152}
6153
76a66253 6154/* tlbwe */
e8eaa2c0 6155static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 6156{
76a66253 6157#if defined(CONFIG_USER_ONLY)
e06fcd75 6158 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6159#else
76db3ba4 6160 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6161 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6162 return;
6163 }
6164 switch (rB(ctx->opcode)) {
6165 case 0:
c6c7cf05
BS
6166 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
6167 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6168 break;
6169 case 1:
c6c7cf05
BS
6170 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
6171 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
6172 break;
6173 default:
e06fcd75 6174 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 6175 break;
9a64fbe4 6176 }
76a66253
JM
6177#endif
6178}
6179
a4bb6c3e 6180/* TLB management - PowerPC 440 implementation */
e8eaa2c0 6181
54623277 6182/* tlbre */
e8eaa2c0 6183static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
6184{
6185#if defined(CONFIG_USER_ONLY)
e06fcd75 6186 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6187#else
76db3ba4 6188 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6189 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6190 return;
6191 }
6192 switch (rB(ctx->opcode)) {
6193 case 0:
5eb7995e 6194 case 1:
5eb7995e 6195 case 2:
74d37793
AJ
6196 {
6197 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6198 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
6199 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
6200 tcg_temp_free_i32(t0);
6201 }
5eb7995e
JM
6202 break;
6203 default:
e06fcd75 6204 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6205 break;
6206 }
6207#endif
6208}
6209
6210/* tlbsx - tlbsx. */
e8eaa2c0 6211static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
6212{
6213#if defined(CONFIG_USER_ONLY)
e06fcd75 6214 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6215#else
74d37793 6216 TCGv t0;
76db3ba4 6217 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6218 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6219 return;
6220 }
74d37793 6221 t0 = tcg_temp_new();
76db3ba4 6222 gen_addr_reg_index(ctx, t0);
c6c7cf05 6223 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
6224 tcg_temp_free(t0);
6225 if (Rc(ctx->opcode)) {
6226 int l1 = gen_new_label();
da91a00f 6227 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
6228 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
6229 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
6230 gen_set_label(l1);
6231 }
5eb7995e
JM
6232#endif
6233}
6234
6235/* tlbwe */
e8eaa2c0 6236static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
6237{
6238#if defined(CONFIG_USER_ONLY)
e06fcd75 6239 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 6240#else
76db3ba4 6241 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6242 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
6243 return;
6244 }
6245 switch (rB(ctx->opcode)) {
6246 case 0:
5eb7995e 6247 case 1:
5eb7995e 6248 case 2:
74d37793
AJ
6249 {
6250 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
6251 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
6252 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
6253 tcg_temp_free_i32(t0);
6254 }
5eb7995e
JM
6255 break;
6256 default:
e06fcd75 6257 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6258 break;
6259 }
6260#endif
6261}
6262
01662f3e
AG
6263/* TLB management - PowerPC BookE 2.06 implementation */
6264
6265/* tlbre */
6266static void gen_tlbre_booke206(DisasContext *ctx)
6267{
6268#if defined(CONFIG_USER_ONLY)
6269 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6270#else
6271 if (unlikely(!ctx->mem_idx)) {
6272 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6273 return;
6274 }
6275
c6c7cf05 6276 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6277#endif
6278}
6279
6280/* tlbsx - tlbsx. */
6281static void gen_tlbsx_booke206(DisasContext *ctx)
6282{
6283#if defined(CONFIG_USER_ONLY)
6284 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6285#else
6286 TCGv t0;
6287 if (unlikely(!ctx->mem_idx)) {
6288 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6289 return;
6290 }
6291
6292 if (rA(ctx->opcode)) {
6293 t0 = tcg_temp_new();
6294 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6295 } else {
6296 t0 = tcg_const_tl(0);
6297 }
6298
6299 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6300 gen_helper_booke206_tlbsx(cpu_env, t0);
01662f3e
AG
6301#endif
6302}
6303
6304/* tlbwe */
6305static void gen_tlbwe_booke206(DisasContext *ctx)
6306{
6307#if defined(CONFIG_USER_ONLY)
6308 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6309#else
6310 if (unlikely(!ctx->mem_idx)) {
6311 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6312 return;
6313 }
3f162d11 6314 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6315 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6316#endif
6317}
6318
6319static void gen_tlbivax_booke206(DisasContext *ctx)
6320{
6321#if defined(CONFIG_USER_ONLY)
6322 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6323#else
6324 TCGv t0;
6325 if (unlikely(!ctx->mem_idx)) {
6326 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6327 return;
6328 }
6329
6330 t0 = tcg_temp_new();
6331 gen_addr_reg_index(ctx, t0);
6332
c6c7cf05 6333 gen_helper_booke206_tlbivax(cpu_env, t0);
01662f3e
AG
6334#endif
6335}
6336
6d3db821
AG
6337static void gen_tlbilx_booke206(DisasContext *ctx)
6338{
6339#if defined(CONFIG_USER_ONLY)
6340 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6341#else
6342 TCGv t0;
6343 if (unlikely(!ctx->mem_idx)) {
6344 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6345 return;
6346 }
6347
6348 t0 = tcg_temp_new();
6349 gen_addr_reg_index(ctx, t0);
6350
6351 switch((ctx->opcode >> 21) & 0x3) {
6352 case 0:
c6c7cf05 6353 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6354 break;
6355 case 1:
c6c7cf05 6356 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6357 break;
6358 case 3:
c6c7cf05 6359 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6360 break;
6361 default:
6362 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6363 break;
6364 }
6365
6366 tcg_temp_free(t0);
6367#endif
6368}
6369
01662f3e 6370
76a66253 6371/* wrtee */
99e300ef 6372static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6373{
6374#if defined(CONFIG_USER_ONLY)
e06fcd75 6375 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6376#else
6527f6ea 6377 TCGv t0;
76db3ba4 6378 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6379 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6380 return;
6381 }
6527f6ea
AJ
6382 t0 = tcg_temp_new();
6383 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6384 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6385 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6386 tcg_temp_free(t0);
dee96f6c
JM
6387 /* Stop translation to have a chance to raise an exception
6388 * if we just set msr_ee to 1
6389 */
e06fcd75 6390 gen_stop_exception(ctx);
76a66253
JM
6391#endif
6392}
6393
6394/* wrteei */
99e300ef 6395static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6396{
6397#if defined(CONFIG_USER_ONLY)
e06fcd75 6398 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6399#else
76db3ba4 6400 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6401 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6402 return;
6403 }
fbe73008 6404 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6405 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6406 /* Stop translation to have a chance to raise an exception */
e06fcd75 6407 gen_stop_exception(ctx);
6527f6ea 6408 } else {
1b6e5f99 6409 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6410 }
76a66253
JM
6411#endif
6412}
6413
08e46e54 6414/* PowerPC 440 specific instructions */
99e300ef 6415
54623277 6416/* dlmzb */
99e300ef 6417static void gen_dlmzb(DisasContext *ctx)
76a66253 6418{
ef0d51af 6419 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6420 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6421 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6422 tcg_temp_free_i32(t0);
76a66253
JM
6423}
6424
6425/* mbar replaces eieio on 440 */
99e300ef 6426static void gen_mbar(DisasContext *ctx)
76a66253
JM
6427{
6428 /* interpreted as no-op */
6429}
6430
6431/* msync replaces sync on 440 */
dcb2b9e1 6432static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6433{
6434 /* interpreted as no-op */
6435}
6436
6437/* icbt */
e8eaa2c0 6438static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6439{
6440 /* interpreted as no-op */
6441 /* XXX: specification say this is treated as a load by the MMU
6442 * but does not generate any exception
6443 */
79aceca5
FB
6444}
6445
9e0b5cb1
AG
6446/* Embedded.Processor Control */
6447
6448static void gen_msgclr(DisasContext *ctx)
6449{
6450#if defined(CONFIG_USER_ONLY)
6451 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6452#else
6453 if (unlikely(ctx->mem_idx == 0)) {
6454 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6455 return;
6456 }
6457
e5f17ac6 6458 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6459#endif
6460}
6461
d5d11a39
AG
6462static void gen_msgsnd(DisasContext *ctx)
6463{
6464#if defined(CONFIG_USER_ONLY)
6465 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6466#else
6467 if (unlikely(ctx->mem_idx == 0)) {
6468 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6469 return;
6470 }
6471
6472 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6473#endif
6474}
6475
a9d9eb8f
JM
6476/*** Altivec vector extension ***/
6477/* Altivec registers moves */
a9d9eb8f 6478
636aa200 6479static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6480{
e4704b3b 6481 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6482 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6483 return r;
6484}
6485
a9d9eb8f 6486#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6487static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6488{ \
fe1e5c53 6489 TCGv EA; \
a9d9eb8f 6490 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6491 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6492 return; \
6493 } \
76db3ba4 6494 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6495 EA = tcg_temp_new(); \
76db3ba4 6496 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6497 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6498 if (ctx->le_mode) { \
6499 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6500 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6501 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6502 } else { \
76db3ba4 6503 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6504 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6505 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6506 } \
6507 tcg_temp_free(EA); \
a9d9eb8f
JM
6508}
6509
6510#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6511static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6512{ \
fe1e5c53 6513 TCGv EA; \
a9d9eb8f 6514 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6515 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6516 return; \
6517 } \
76db3ba4 6518 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6519 EA = tcg_temp_new(); \
76db3ba4 6520 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6521 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6522 if (ctx->le_mode) { \
6523 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6524 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6525 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6526 } else { \
76db3ba4 6527 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6528 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6529 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6530 } \
6531 tcg_temp_free(EA); \
a9d9eb8f
JM
6532}
6533
cbfb6ae9 6534#define GEN_VR_LVE(name, opc2, opc3) \
99e300ef 6535static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6536 { \
6537 TCGv EA; \
6538 TCGv_ptr rs; \
6539 if (unlikely(!ctx->altivec_enabled)) { \
6540 gen_exception(ctx, POWERPC_EXCP_VPU); \
6541 return; \
6542 } \
6543 gen_set_access_type(ctx, ACCESS_INT); \
6544 EA = tcg_temp_new(); \
6545 gen_addr_reg_index(ctx, EA); \
6546 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6547 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6548 tcg_temp_free(EA); \
6549 tcg_temp_free_ptr(rs); \
6550 }
6551
6552#define GEN_VR_STVE(name, opc2, opc3) \
99e300ef 6553static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6554 { \
6555 TCGv EA; \
6556 TCGv_ptr rs; \
6557 if (unlikely(!ctx->altivec_enabled)) { \
6558 gen_exception(ctx, POWERPC_EXCP_VPU); \
6559 return; \
6560 } \
6561 gen_set_access_type(ctx, ACCESS_INT); \
6562 EA = tcg_temp_new(); \
6563 gen_addr_reg_index(ctx, EA); \
6564 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6565 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6566 tcg_temp_free(EA); \
6567 tcg_temp_free_ptr(rs); \
6568 }
6569
fe1e5c53 6570GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6571/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6572GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6573
cbfb6ae9
AJ
6574GEN_VR_LVE(bx, 0x07, 0x00);
6575GEN_VR_LVE(hx, 0x07, 0x01);
6576GEN_VR_LVE(wx, 0x07, 0x02);
6577
fe1e5c53 6578GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6579/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6580GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6581
cbfb6ae9
AJ
6582GEN_VR_STVE(bx, 0x07, 0x04);
6583GEN_VR_STVE(hx, 0x07, 0x05);
6584GEN_VR_STVE(wx, 0x07, 0x06);
6585
99e300ef 6586static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6587{
6588 TCGv_ptr rd;
6589 TCGv EA;
6590 if (unlikely(!ctx->altivec_enabled)) {
6591 gen_exception(ctx, POWERPC_EXCP_VPU);
6592 return;
6593 }
6594 EA = tcg_temp_new();
6595 gen_addr_reg_index(ctx, EA);
6596 rd = gen_avr_ptr(rD(ctx->opcode));
6597 gen_helper_lvsl(rd, EA);
6598 tcg_temp_free(EA);
6599 tcg_temp_free_ptr(rd);
6600}
6601
99e300ef 6602static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6603{
6604 TCGv_ptr rd;
6605 TCGv EA;
6606 if (unlikely(!ctx->altivec_enabled)) {
6607 gen_exception(ctx, POWERPC_EXCP_VPU);
6608 return;
6609 }
6610 EA = tcg_temp_new();
6611 gen_addr_reg_index(ctx, EA);
6612 rd = gen_avr_ptr(rD(ctx->opcode));
6613 gen_helper_lvsr(rd, EA);
6614 tcg_temp_free(EA);
6615 tcg_temp_free_ptr(rd);
6616}
6617
99e300ef 6618static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6619{
6620 TCGv_i32 t;
6621 if (unlikely(!ctx->altivec_enabled)) {
6622 gen_exception(ctx, POWERPC_EXCP_VPU);
6623 return;
6624 }
6625 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6626 t = tcg_temp_new_i32();
1328c2bf 6627 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6628 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6629 tcg_temp_free_i32(t);
785f451b
AJ
6630}
6631
99e300ef 6632static void gen_mtvscr(DisasContext *ctx)
785f451b 6633{
6e87b7c7 6634 TCGv_ptr p;
785f451b
AJ
6635 if (unlikely(!ctx->altivec_enabled)) {
6636 gen_exception(ctx, POWERPC_EXCP_VPU);
6637 return;
6638 }
6e87b7c7 6639 p = gen_avr_ptr(rD(ctx->opcode));
d15f74fb 6640 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6641 tcg_temp_free_ptr(p);
785f451b
AJ
6642}
6643
7a9b96cf
AJ
6644/* Logical operations */
6645#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6646static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6647{ \
6648 if (unlikely(!ctx->altivec_enabled)) { \
6649 gen_exception(ctx, POWERPC_EXCP_VPU); \
6650 return; \
6651 } \
6652 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6653 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6654}
6655
6656GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6657GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6658GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6659GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6660GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6661
8e27dd6f 6662#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6663static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6664{ \
6665 TCGv_ptr ra, rb, rd; \
6666 if (unlikely(!ctx->altivec_enabled)) { \
6667 gen_exception(ctx, POWERPC_EXCP_VPU); \
6668 return; \
6669 } \
6670 ra = gen_avr_ptr(rA(ctx->opcode)); \
6671 rb = gen_avr_ptr(rB(ctx->opcode)); \
6672 rd = gen_avr_ptr(rD(ctx->opcode)); \
6673 gen_helper_##name (rd, ra, rb); \
6674 tcg_temp_free_ptr(ra); \
6675 tcg_temp_free_ptr(rb); \
6676 tcg_temp_free_ptr(rd); \
6677}
6678
d15f74fb
BS
6679#define GEN_VXFORM_ENV(name, opc2, opc3) \
6680static void glue(gen_, name)(DisasContext *ctx) \
6681{ \
6682 TCGv_ptr ra, rb, rd; \
6683 if (unlikely(!ctx->altivec_enabled)) { \
6684 gen_exception(ctx, POWERPC_EXCP_VPU); \
6685 return; \
6686 } \
6687 ra = gen_avr_ptr(rA(ctx->opcode)); \
6688 rb = gen_avr_ptr(rB(ctx->opcode)); \
6689 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6690 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6691 tcg_temp_free_ptr(ra); \
6692 tcg_temp_free_ptr(rb); \
6693 tcg_temp_free_ptr(rd); \
6694}
6695
7872c51c
AJ
6696GEN_VXFORM(vaddubm, 0, 0);
6697GEN_VXFORM(vadduhm, 0, 1);
6698GEN_VXFORM(vadduwm, 0, 2);
6699GEN_VXFORM(vsububm, 0, 16);
6700GEN_VXFORM(vsubuhm, 0, 17);
6701GEN_VXFORM(vsubuwm, 0, 18);
e4039339
AJ
6702GEN_VXFORM(vmaxub, 1, 0);
6703GEN_VXFORM(vmaxuh, 1, 1);
6704GEN_VXFORM(vmaxuw, 1, 2);
6705GEN_VXFORM(vmaxsb, 1, 4);
6706GEN_VXFORM(vmaxsh, 1, 5);
6707GEN_VXFORM(vmaxsw, 1, 6);
6708GEN_VXFORM(vminub, 1, 8);
6709GEN_VXFORM(vminuh, 1, 9);
6710GEN_VXFORM(vminuw, 1, 10);
6711GEN_VXFORM(vminsb, 1, 12);
6712GEN_VXFORM(vminsh, 1, 13);
6713GEN_VXFORM(vminsw, 1, 14);
fab3cbe9
AJ
6714GEN_VXFORM(vavgub, 1, 16);
6715GEN_VXFORM(vavguh, 1, 17);
6716GEN_VXFORM(vavguw, 1, 18);
6717GEN_VXFORM(vavgsb, 1, 20);
6718GEN_VXFORM(vavgsh, 1, 21);
6719GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
6720GEN_VXFORM(vmrghb, 6, 0);
6721GEN_VXFORM(vmrghh, 6, 1);
6722GEN_VXFORM(vmrghw, 6, 2);
6723GEN_VXFORM(vmrglb, 6, 4);
6724GEN_VXFORM(vmrglh, 6, 5);
6725GEN_VXFORM(vmrglw, 6, 6);
2c277908
AJ
6726GEN_VXFORM(vmuloub, 4, 0);
6727GEN_VXFORM(vmulouh, 4, 1);
6728GEN_VXFORM(vmulosb, 4, 4);
6729GEN_VXFORM(vmulosh, 4, 5);
6730GEN_VXFORM(vmuleub, 4, 8);
6731GEN_VXFORM(vmuleuh, 4, 9);
6732GEN_VXFORM(vmulesb, 4, 12);
6733GEN_VXFORM(vmulesh, 4, 13);
d79f0809
AJ
6734GEN_VXFORM(vslb, 2, 4);
6735GEN_VXFORM(vslh, 2, 5);
6736GEN_VXFORM(vslw, 2, 6);
07ef34c3
AJ
6737GEN_VXFORM(vsrb, 2, 8);
6738GEN_VXFORM(vsrh, 2, 9);
6739GEN_VXFORM(vsrw, 2, 10);
6740GEN_VXFORM(vsrab, 2, 12);
6741GEN_VXFORM(vsrah, 2, 13);
6742GEN_VXFORM(vsraw, 2, 14);
7b239bec
AJ
6743GEN_VXFORM(vslo, 6, 16);
6744GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
6745GEN_VXFORM(vaddcuw, 0, 6);
6746GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
6747GEN_VXFORM_ENV(vaddubs, 0, 8);
6748GEN_VXFORM_ENV(vadduhs, 0, 9);
6749GEN_VXFORM_ENV(vadduws, 0, 10);
6750GEN_VXFORM_ENV(vaddsbs, 0, 12);
6751GEN_VXFORM_ENV(vaddshs, 0, 13);
6752GEN_VXFORM_ENV(vaddsws, 0, 14);
6753GEN_VXFORM_ENV(vsububs, 0, 24);
6754GEN_VXFORM_ENV(vsubuhs, 0, 25);
6755GEN_VXFORM_ENV(vsubuws, 0, 26);
6756GEN_VXFORM_ENV(vsubsbs, 0, 28);
6757GEN_VXFORM_ENV(vsubshs, 0, 29);
6758GEN_VXFORM_ENV(vsubsws, 0, 30);
5e1d0985
AJ
6759GEN_VXFORM(vrlb, 2, 0);
6760GEN_VXFORM(vrlh, 2, 1);
6761GEN_VXFORM(vrlw, 2, 2);
d9430add
AJ
6762GEN_VXFORM(vsl, 2, 7);
6763GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
6764GEN_VXFORM_ENV(vpkuhum, 7, 0);
6765GEN_VXFORM_ENV(vpkuwum, 7, 1);
6766GEN_VXFORM_ENV(vpkuhus, 7, 2);
6767GEN_VXFORM_ENV(vpkuwus, 7, 3);
6768GEN_VXFORM_ENV(vpkshus, 7, 4);
6769GEN_VXFORM_ENV(vpkswus, 7, 5);
6770GEN_VXFORM_ENV(vpkshss, 7, 6);
6771GEN_VXFORM_ENV(vpkswss, 7, 7);
1dd9ffb9 6772GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
6773GEN_VXFORM_ENV(vsum4ubs, 4, 24);
6774GEN_VXFORM_ENV(vsum4sbs, 4, 28);
6775GEN_VXFORM_ENV(vsum4shs, 4, 25);
6776GEN_VXFORM_ENV(vsum2sws, 4, 26);
6777GEN_VXFORM_ENV(vsumsws, 4, 30);
6778GEN_VXFORM_ENV(vaddfp, 5, 0);
6779GEN_VXFORM_ENV(vsubfp, 5, 1);
6780GEN_VXFORM_ENV(vmaxfp, 5, 16);
6781GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 6782
0cbcd906 6783#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 6784static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
6785 { \
6786 TCGv_ptr ra, rb, rd; \
6787 if (unlikely(!ctx->altivec_enabled)) { \
6788 gen_exception(ctx, POWERPC_EXCP_VPU); \
6789 return; \
6790 } \
6791 ra = gen_avr_ptr(rA(ctx->opcode)); \
6792 rb = gen_avr_ptr(rB(ctx->opcode)); \
6793 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 6794 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
6795 tcg_temp_free_ptr(ra); \
6796 tcg_temp_free_ptr(rb); \
6797 tcg_temp_free_ptr(rd); \
6798 }
6799
6800#define GEN_VXRFORM(name, opc2, opc3) \
6801 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6802 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6803
1add6e23
AJ
6804GEN_VXRFORM(vcmpequb, 3, 0)
6805GEN_VXRFORM(vcmpequh, 3, 1)
6806GEN_VXRFORM(vcmpequw, 3, 2)
6807GEN_VXRFORM(vcmpgtsb, 3, 12)
6808GEN_VXRFORM(vcmpgtsh, 3, 13)
6809GEN_VXRFORM(vcmpgtsw, 3, 14)
6810GEN_VXRFORM(vcmpgtub, 3, 8)
6811GEN_VXRFORM(vcmpgtuh, 3, 9)
6812GEN_VXRFORM(vcmpgtuw, 3, 10)
819ca121
AJ
6813GEN_VXRFORM(vcmpeqfp, 3, 3)
6814GEN_VXRFORM(vcmpgefp, 3, 7)
6815GEN_VXRFORM(vcmpgtfp, 3, 11)
6816GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 6817
c026766b 6818#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 6819static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
6820 { \
6821 TCGv_ptr rd; \
6822 TCGv_i32 simm; \
6823 if (unlikely(!ctx->altivec_enabled)) { \
6824 gen_exception(ctx, POWERPC_EXCP_VPU); \
6825 return; \
6826 } \
6827 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6828 rd = gen_avr_ptr(rD(ctx->opcode)); \
6829 gen_helper_##name (rd, simm); \
6830 tcg_temp_free_i32(simm); \
6831 tcg_temp_free_ptr(rd); \
6832 }
6833
6834GEN_VXFORM_SIMM(vspltisb, 6, 12);
6835GEN_VXFORM_SIMM(vspltish, 6, 13);
6836GEN_VXFORM_SIMM(vspltisw, 6, 14);
6837
de5f2484 6838#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 6839static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
6840 { \
6841 TCGv_ptr rb, rd; \
6842 if (unlikely(!ctx->altivec_enabled)) { \
6843 gen_exception(ctx, POWERPC_EXCP_VPU); \
6844 return; \
6845 } \
6846 rb = gen_avr_ptr(rB(ctx->opcode)); \
6847 rd = gen_avr_ptr(rD(ctx->opcode)); \
6848 gen_helper_##name (rd, rb); \
6849 tcg_temp_free_ptr(rb); \
6850 tcg_temp_free_ptr(rd); \
6851 }
6852
d15f74fb
BS
6853#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6854static void glue(gen_, name)(DisasContext *ctx) \
6855 { \
6856 TCGv_ptr rb, rd; \
6857 \
6858 if (unlikely(!ctx->altivec_enabled)) { \
6859 gen_exception(ctx, POWERPC_EXCP_VPU); \
6860 return; \
6861 } \
6862 rb = gen_avr_ptr(rB(ctx->opcode)); \
6863 rd = gen_avr_ptr(rD(ctx->opcode)); \
6864 gen_helper_##name(cpu_env, rd, rb); \
6865 tcg_temp_free_ptr(rb); \
6866 tcg_temp_free_ptr(rd); \
6867 }
6868
6cf1c6e5
AJ
6869GEN_VXFORM_NOA(vupkhsb, 7, 8);
6870GEN_VXFORM_NOA(vupkhsh, 7, 9);
6871GEN_VXFORM_NOA(vupklsb, 7, 10);
6872GEN_VXFORM_NOA(vupklsh, 7, 11);
79f85c3a
AJ
6873GEN_VXFORM_NOA(vupkhpx, 7, 13);
6874GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
6875GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
6876GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
6877GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
6878GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
6879GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
6880GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
6881GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
6882GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
79f85c3a 6883
21d21583 6884#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 6885static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
6886 { \
6887 TCGv_ptr rd; \
6888 TCGv_i32 simm; \
6889 if (unlikely(!ctx->altivec_enabled)) { \
6890 gen_exception(ctx, POWERPC_EXCP_VPU); \
6891 return; \
6892 } \
6893 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6894 rd = gen_avr_ptr(rD(ctx->opcode)); \
6895 gen_helper_##name (rd, simm); \
6896 tcg_temp_free_i32(simm); \
6897 tcg_temp_free_ptr(rd); \
6898 }
6899
27a4edb3 6900#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 6901static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
6902 { \
6903 TCGv_ptr rb, rd; \
6904 TCGv_i32 uimm; \
6905 if (unlikely(!ctx->altivec_enabled)) { \
6906 gen_exception(ctx, POWERPC_EXCP_VPU); \
6907 return; \
6908 } \
6909 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6910 rb = gen_avr_ptr(rB(ctx->opcode)); \
6911 rd = gen_avr_ptr(rD(ctx->opcode)); \
6912 gen_helper_##name (rd, rb, uimm); \
6913 tcg_temp_free_i32(uimm); \
6914 tcg_temp_free_ptr(rb); \
6915 tcg_temp_free_ptr(rd); \
6916 }
6917
d15f74fb
BS
6918#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6919static void glue(gen_, name)(DisasContext *ctx) \
6920 { \
6921 TCGv_ptr rb, rd; \
6922 TCGv_i32 uimm; \
6923 \
6924 if (unlikely(!ctx->altivec_enabled)) { \
6925 gen_exception(ctx, POWERPC_EXCP_VPU); \
6926 return; \
6927 } \
6928 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6929 rb = gen_avr_ptr(rB(ctx->opcode)); \
6930 rd = gen_avr_ptr(rD(ctx->opcode)); \
6931 gen_helper_##name(cpu_env, rd, rb, uimm); \
6932 tcg_temp_free_i32(uimm); \
6933 tcg_temp_free_ptr(rb); \
6934 tcg_temp_free_ptr(rd); \
6935 }
6936
e4e6bee7
AJ
6937GEN_VXFORM_UIMM(vspltb, 6, 8);
6938GEN_VXFORM_UIMM(vsplth, 6, 9);
6939GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
6940GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
6941GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
6942GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
6943GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 6944
99e300ef 6945static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
6946{
6947 TCGv_ptr ra, rb, rd;
fce5ecb7 6948 TCGv_i32 sh;
cd633b10
AJ
6949 if (unlikely(!ctx->altivec_enabled)) {
6950 gen_exception(ctx, POWERPC_EXCP_VPU);
6951 return;
6952 }
6953 ra = gen_avr_ptr(rA(ctx->opcode));
6954 rb = gen_avr_ptr(rB(ctx->opcode));
6955 rd = gen_avr_ptr(rD(ctx->opcode));
6956 sh = tcg_const_i32(VSH(ctx->opcode));
6957 gen_helper_vsldoi (rd, ra, rb, sh);
6958 tcg_temp_free_ptr(ra);
6959 tcg_temp_free_ptr(rb);
6960 tcg_temp_free_ptr(rd);
fce5ecb7 6961 tcg_temp_free_i32(sh);
cd633b10
AJ
6962}
6963
707cec33 6964#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 6965static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
6966 { \
6967 TCGv_ptr ra, rb, rc, rd; \
6968 if (unlikely(!ctx->altivec_enabled)) { \
6969 gen_exception(ctx, POWERPC_EXCP_VPU); \
6970 return; \
6971 } \
6972 ra = gen_avr_ptr(rA(ctx->opcode)); \
6973 rb = gen_avr_ptr(rB(ctx->opcode)); \
6974 rc = gen_avr_ptr(rC(ctx->opcode)); \
6975 rd = gen_avr_ptr(rD(ctx->opcode)); \
6976 if (Rc(ctx->opcode)) { \
d15f74fb 6977 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 6978 } else { \
d15f74fb 6979 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
6980 } \
6981 tcg_temp_free_ptr(ra); \
6982 tcg_temp_free_ptr(rb); \
6983 tcg_temp_free_ptr(rc); \
6984 tcg_temp_free_ptr(rd); \
6985 }
6986
b161ae27
AJ
6987GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
6988
99e300ef 6989static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
6990{
6991 TCGv_ptr ra, rb, rc, rd;
6992 if (unlikely(!ctx->altivec_enabled)) {
6993 gen_exception(ctx, POWERPC_EXCP_VPU);
6994 return;
6995 }
6996 ra = gen_avr_ptr(rA(ctx->opcode));
6997 rb = gen_avr_ptr(rB(ctx->opcode));
6998 rc = gen_avr_ptr(rC(ctx->opcode));
6999 rd = gen_avr_ptr(rD(ctx->opcode));
7000 gen_helper_vmladduhm(rd, ra, rb, rc);
7001 tcg_temp_free_ptr(ra);
7002 tcg_temp_free_ptr(rb);
7003 tcg_temp_free_ptr(rc);
7004 tcg_temp_free_ptr(rd);
7005}
7006
b04ae981 7007GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 7008GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 7009GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 7010GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 7011GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 7012
472b24ce
TM
7013/*** VSX extension ***/
7014
7015static inline TCGv_i64 cpu_vsrh(int n)
7016{
7017 if (n < 32) {
7018 return cpu_fpr[n];
7019 } else {
7020 return cpu_avrh[n-32];
7021 }
7022}
7023
7024static inline TCGv_i64 cpu_vsrl(int n)
7025{
7026 if (n < 32) {
7027 return cpu_vsr[n];
7028 } else {
7029 return cpu_avrl[n-32];
7030 }
7031}
7032
e072fe79
TM
7033#define VSX_LOAD_SCALAR(name, operation) \
7034static void gen_##name(DisasContext *ctx) \
7035{ \
7036 TCGv EA; \
7037 if (unlikely(!ctx->vsx_enabled)) { \
7038 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7039 return; \
7040 } \
7041 gen_set_access_type(ctx, ACCESS_INT); \
7042 EA = tcg_temp_new(); \
7043 gen_addr_reg_index(ctx, EA); \
7044 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7045 /* NOTE: cpu_vsrl is undefined */ \
7046 tcg_temp_free(EA); \
7047}
7048
7049VSX_LOAD_SCALAR(lxsdx, ld64)
cac7f0ba
TM
7050VSX_LOAD_SCALAR(lxsiwax, ld32s_i64)
7051VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64)
7052VSX_LOAD_SCALAR(lxsspx, ld32fs)
fa1832d7 7053
304af367
TM
7054static void gen_lxvd2x(DisasContext *ctx)
7055{
7056 TCGv EA;
7057 if (unlikely(!ctx->vsx_enabled)) {
7058 gen_exception(ctx, POWERPC_EXCP_VSXU);
7059 return;
7060 }
7061 gen_set_access_type(ctx, ACCESS_INT);
7062 EA = tcg_temp_new();
7063 gen_addr_reg_index(ctx, EA);
7064 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
7065 tcg_gen_addi_tl(EA, EA, 8);
7066 gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA);
7067 tcg_temp_free(EA);
7068}
7069
ca03b467
TM
7070static void gen_lxvdsx(DisasContext *ctx)
7071{
7072 TCGv EA;
7073 if (unlikely(!ctx->vsx_enabled)) {
7074 gen_exception(ctx, POWERPC_EXCP_VSXU);
7075 return;
7076 }
7077 gen_set_access_type(ctx, ACCESS_INT);
7078 EA = tcg_temp_new();
7079 gen_addr_reg_index(ctx, EA);
7080 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA);
f976b09e 7081 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
ca03b467
TM
7082 tcg_temp_free(EA);
7083}
7084
897e61d1
TM
7085static void gen_lxvw4x(DisasContext *ctx)
7086{
f976b09e
AG
7087 TCGv EA;
7088 TCGv_i64 tmp;
897e61d1
TM
7089 TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode));
7090 TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode));
7091 if (unlikely(!ctx->vsx_enabled)) {
7092 gen_exception(ctx, POWERPC_EXCP_VSXU);
7093 return;
7094 }
7095 gen_set_access_type(ctx, ACCESS_INT);
7096 EA = tcg_temp_new();
f976b09e
AG
7097 tmp = tcg_temp_new_i64();
7098
897e61d1 7099 gen_addr_reg_index(ctx, EA);
f976b09e 7100 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7101 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7102 gen_qemu_ld32u_i64(ctx, xth, EA);
897e61d1
TM
7103 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
7104
7105 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7106 gen_qemu_ld32u_i64(ctx, tmp, EA);
897e61d1 7107 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7108 gen_qemu_ld32u_i64(ctx, xtl, EA);
897e61d1
TM
7109 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
7110
7111 tcg_temp_free(EA);
f976b09e 7112 tcg_temp_free_i64(tmp);
897e61d1
TM
7113}
7114
f026da78
TM
7115#define VSX_STORE_SCALAR(name, operation) \
7116static void gen_##name(DisasContext *ctx) \
7117{ \
7118 TCGv EA; \
7119 if (unlikely(!ctx->vsx_enabled)) { \
7120 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7121 return; \
7122 } \
7123 gen_set_access_type(ctx, ACCESS_INT); \
7124 EA = tcg_temp_new(); \
7125 gen_addr_reg_index(ctx, EA); \
7126 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7127 tcg_temp_free(EA); \
9231ba9e
TM
7128}
7129
f026da78 7130VSX_STORE_SCALAR(stxsdx, st64)
e16a626b
TM
7131VSX_STORE_SCALAR(stxsiwx, st32_i64)
7132VSX_STORE_SCALAR(stxsspx, st32fs)
f026da78 7133
fbed2478
TM
7134static void gen_stxvd2x(DisasContext *ctx)
7135{
7136 TCGv EA;
7137 if (unlikely(!ctx->vsx_enabled)) {
7138 gen_exception(ctx, POWERPC_EXCP_VSXU);
7139 return;
7140 }
7141 gen_set_access_type(ctx, ACCESS_INT);
7142 EA = tcg_temp_new();
7143 gen_addr_reg_index(ctx, EA);
7144 gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
7145 tcg_gen_addi_tl(EA, EA, 8);
7146 gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
7147 tcg_temp_free(EA);
7148}
7149
86e61ce3
TM
7150static void gen_stxvw4x(DisasContext *ctx)
7151{
f976b09e
AG
7152 TCGv_i64 tmp;
7153 TCGv EA;
86e61ce3
TM
7154 if (unlikely(!ctx->vsx_enabled)) {
7155 gen_exception(ctx, POWERPC_EXCP_VSXU);
7156 return;
7157 }
7158 gen_set_access_type(ctx, ACCESS_INT);
7159 EA = tcg_temp_new();
7160 gen_addr_reg_index(ctx, EA);
f976b09e 7161 tmp = tcg_temp_new_i64();
86e61ce3
TM
7162
7163 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32);
f976b09e 7164 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7165 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7166 gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA);
86e61ce3
TM
7167
7168 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32);
7169 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7170 gen_qemu_st32_i64(ctx, tmp, EA);
86e61ce3 7171 tcg_gen_addi_tl(EA, EA, 4);
f976b09e 7172 gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA);
86e61ce3
TM
7173
7174 tcg_temp_free(EA);
f976b09e 7175 tcg_temp_free_i64(tmp);
86e61ce3
TM
7176}
7177
cd73f2c9
TM
7178static void gen_xxpermdi(DisasContext *ctx)
7179{
7180 if (unlikely(!ctx->vsx_enabled)) {
7181 gen_exception(ctx, POWERPC_EXCP_VSXU);
7182 return;
7183 }
7184
7185 if ((DM(ctx->opcode) & 2) == 0) {
7186 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)));
7187 } else {
7188 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)));
7189 }
7190 if ((DM(ctx->opcode) & 1) == 0) {
7191 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode)));
7192 } else {
7193 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode)));
7194 }
7195}
7196
df020ce0
TM
7197#define OP_ABS 1
7198#define OP_NABS 2
7199#define OP_NEG 3
7200#define OP_CPSGN 4
7201#define SGN_MASK_DP 0x8000000000000000ul
7202#define SGN_MASK_SP 0x8000000080000000ul
7203
7204#define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7205static void glue(gen_, name)(DisasContext * ctx) \
7206 { \
7207 TCGv_i64 xb, sgm; \
7208 if (unlikely(!ctx->vsx_enabled)) { \
7209 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7210 return; \
7211 } \
f976b09e
AG
7212 xb = tcg_temp_new_i64(); \
7213 sgm = tcg_temp_new_i64(); \
df020ce0
TM
7214 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7215 tcg_gen_movi_i64(sgm, sgn_mask); \
7216 switch (op) { \
7217 case OP_ABS: { \
7218 tcg_gen_andc_i64(xb, xb, sgm); \
7219 break; \
7220 } \
7221 case OP_NABS: { \
7222 tcg_gen_or_i64(xb, xb, sgm); \
7223 break; \
7224 } \
7225 case OP_NEG: { \
7226 tcg_gen_xor_i64(xb, xb, sgm); \
7227 break; \
7228 } \
7229 case OP_CPSGN: { \
f976b09e 7230 TCGv_i64 xa = tcg_temp_new_i64(); \
df020ce0
TM
7231 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7232 tcg_gen_and_i64(xa, xa, sgm); \
7233 tcg_gen_andc_i64(xb, xb, sgm); \
7234 tcg_gen_or_i64(xb, xb, xa); \
f976b09e 7235 tcg_temp_free_i64(xa); \
df020ce0
TM
7236 break; \
7237 } \
7238 } \
7239 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
f976b09e
AG
7240 tcg_temp_free_i64(xb); \
7241 tcg_temp_free_i64(sgm); \
df020ce0
TM
7242 }
7243
7244VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP)
7245VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP)
7246VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP)
7247VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP)
7248
be574920
TM
7249#define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7250static void glue(gen_, name)(DisasContext * ctx) \
7251 { \
7252 TCGv_i64 xbh, xbl, sgm; \
7253 if (unlikely(!ctx->vsx_enabled)) { \
7254 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7255 return; \
7256 } \
f976b09e
AG
7257 xbh = tcg_temp_new_i64(); \
7258 xbl = tcg_temp_new_i64(); \
7259 sgm = tcg_temp_new_i64(); \
be574920
TM
7260 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7261 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7262 tcg_gen_movi_i64(sgm, sgn_mask); \
7263 switch (op) { \
7264 case OP_ABS: { \
7265 tcg_gen_andc_i64(xbh, xbh, sgm); \
7266 tcg_gen_andc_i64(xbl, xbl, sgm); \
7267 break; \
7268 } \
7269 case OP_NABS: { \
7270 tcg_gen_or_i64(xbh, xbh, sgm); \
7271 tcg_gen_or_i64(xbl, xbl, sgm); \
7272 break; \
7273 } \
7274 case OP_NEG: { \
7275 tcg_gen_xor_i64(xbh, xbh, sgm); \
7276 tcg_gen_xor_i64(xbl, xbl, sgm); \
7277 break; \
7278 } \
7279 case OP_CPSGN: { \
f976b09e
AG
7280 TCGv_i64 xah = tcg_temp_new_i64(); \
7281 TCGv_i64 xal = tcg_temp_new_i64(); \
be574920
TM
7282 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7283 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7284 tcg_gen_and_i64(xah, xah, sgm); \
7285 tcg_gen_and_i64(xal, xal, sgm); \
7286 tcg_gen_andc_i64(xbh, xbh, sgm); \
7287 tcg_gen_andc_i64(xbl, xbl, sgm); \
7288 tcg_gen_or_i64(xbh, xbh, xah); \
7289 tcg_gen_or_i64(xbl, xbl, xal); \
f976b09e
AG
7290 tcg_temp_free_i64(xah); \
7291 tcg_temp_free_i64(xal); \
be574920
TM
7292 break; \
7293 } \
7294 } \
7295 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7296 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
f976b09e
AG
7297 tcg_temp_free_i64(xbh); \
7298 tcg_temp_free_i64(xbl); \
7299 tcg_temp_free_i64(sgm); \
be574920
TM
7300 }
7301
7302VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP)
7303VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP)
7304VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP)
7305VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP)
7306VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP)
7307VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP)
7308VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP)
7309VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP)
7310
3c3cbbdc
TM
7311#define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7312static void gen_##name(DisasContext * ctx) \
7313{ \
7314 TCGv_i32 opc; \
7315 if (unlikely(!ctx->vsx_enabled)) { \
7316 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7317 return; \
7318 } \
7319 /* NIP cannot be restored if the memory exception comes from an helper */ \
7320 gen_update_nip(ctx, ctx->nip - 4); \
7321 opc = tcg_const_i32(ctx->opcode); \
7322 gen_helper_##name(cpu_env, opc); \
7323 tcg_temp_free_i32(opc); \
7324}
be574920 7325
ee6e02c0
TM
7326GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX)
7327GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX)
5e591d88 7328GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX)
4b98eeef 7329GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX)
2009227f 7330GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX)
d32404fe 7331GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX)
d3f9df8f 7332GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX)
bc80838f 7333GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX)
5cb151ac 7334GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX)
595c6eef
TM
7335GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX)
7336GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX)
7337GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX)
7338GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX)
7339GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX)
7340GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX)
7341GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX)
7342GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX)
4f17e9c7
TM
7343GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX)
7344GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX)
959e9c9d
TM
7345GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX)
7346GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX)
ed8ac568
TM
7347GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX)
7348GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX)
5177d2ca
TM
7349GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX)
7350GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX)
7351GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX)
7352GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX)
7353GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX)
7354GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX)
88e33d08
TM
7355GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX)
7356GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX)
7357GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX)
7358GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX)
7359GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX)
ee6e02c0 7360
3fd0aadf
TM
7361GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207)
7362GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207)
ab9408a2 7363GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207)
b24d0b47 7364GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207)
2c0c52ae 7365GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207)
cea4e574 7366GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207)
3fd0aadf 7367
ee6e02c0
TM
7368GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX)
7369GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX)
5e591d88 7370GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX)
4b98eeef 7371GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX)
2009227f 7372GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX)
d32404fe 7373GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX)
d3f9df8f 7374GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX)
bc80838f 7375GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX)
5cb151ac 7376GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX)
595c6eef
TM
7377GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX)
7378GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX)
7379GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX)
7380GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX)
7381GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX)
7382GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX)
7383GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX)
7384GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX)
959e9c9d
TM
7385GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX)
7386GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX)
354a6dec
TM
7387GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX)
7388GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX)
7389GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX)
ed8ac568 7390GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX)
5177d2ca
TM
7391GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX)
7392GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX)
7393GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX)
7394GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX)
7395GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX)
7396GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX)
7397GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX)
7398GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX)
88e33d08
TM
7399GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX)
7400GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX)
7401GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX)
7402GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX)
7403GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX)
ee6e02c0
TM
7404
7405GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX)
7406GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX)
5e591d88 7407GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX)
4b98eeef 7408GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX)
2009227f 7409GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX)
d32404fe 7410GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX)
d3f9df8f 7411GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX)
bc80838f 7412GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX)
5cb151ac 7413GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX)
595c6eef
TM
7414GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX)
7415GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX)
7416GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX)
7417GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX)
7418GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX)
7419GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX)
7420GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX)
7421GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX)
959e9c9d
TM
7422GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX)
7423GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX)
354a6dec
TM
7424GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX)
7425GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX)
7426GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX)
ed8ac568 7427GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX)
5177d2ca
TM
7428GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX)
7429GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX)
7430GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX)
7431GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX)
7432GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX)
7433GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX)
7434GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX)
7435GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX)
88e33d08
TM
7436GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX)
7437GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX)
7438GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX)
7439GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX)
7440GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX)
ee6e02c0 7441
79ca8a6a
TM
7442#define VSX_LOGICAL(name, tcg_op) \
7443static void glue(gen_, name)(DisasContext * ctx) \
7444 { \
7445 if (unlikely(!ctx->vsx_enabled)) { \
7446 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7447 return; \
7448 } \
7449 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
7450 cpu_vsrh(xB(ctx->opcode))); \
7451 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
7452 cpu_vsrl(xB(ctx->opcode))); \
7453 }
7454
f976b09e
AG
7455VSX_LOGICAL(xxland, tcg_gen_and_i64)
7456VSX_LOGICAL(xxlandc, tcg_gen_andc_i64)
7457VSX_LOGICAL(xxlor, tcg_gen_or_i64)
7458VSX_LOGICAL(xxlxor, tcg_gen_xor_i64)
7459VSX_LOGICAL(xxlnor, tcg_gen_nor_i64)
df020ce0 7460
ce577d2e
TM
7461#define VSX_XXMRG(name, high) \
7462static void glue(gen_, name)(DisasContext * ctx) \
7463 { \
7464 TCGv_i64 a0, a1, b0, b1; \
7465 if (unlikely(!ctx->vsx_enabled)) { \
7466 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7467 return; \
7468 } \
f976b09e
AG
7469 a0 = tcg_temp_new_i64(); \
7470 a1 = tcg_temp_new_i64(); \
7471 b0 = tcg_temp_new_i64(); \
7472 b1 = tcg_temp_new_i64(); \
ce577d2e
TM
7473 if (high) { \
7474 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
7475 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
7476 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
7477 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
7478 } else { \
7479 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
7480 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
7481 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
7482 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
7483 } \
7484 tcg_gen_shri_i64(a0, a0, 32); \
7485 tcg_gen_shri_i64(b0, b0, 32); \
7486 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
7487 b0, a0, 32, 32); \
7488 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
7489 b1, a1, 32, 32); \
f976b09e
AG
7490 tcg_temp_free_i64(a0); \
7491 tcg_temp_free_i64(a1); \
7492 tcg_temp_free_i64(b0); \
7493 tcg_temp_free_i64(b1); \
ce577d2e
TM
7494 }
7495
7496VSX_XXMRG(xxmrghw, 1)
7497VSX_XXMRG(xxmrglw, 0)
7498
551e3ef7
TM
7499static void gen_xxsel(DisasContext * ctx)
7500{
7501 TCGv_i64 a, b, c;
7502 if (unlikely(!ctx->vsx_enabled)) {
7503 gen_exception(ctx, POWERPC_EXCP_VSXU);
7504 return;
7505 }
f976b09e
AG
7506 a = tcg_temp_new_i64();
7507 b = tcg_temp_new_i64();
7508 c = tcg_temp_new_i64();
551e3ef7
TM
7509
7510 tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode)));
7511 tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode)));
7512 tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode)));
7513
7514 tcg_gen_and_i64(b, b, c);
7515 tcg_gen_andc_i64(a, a, c);
7516 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b);
7517
7518 tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode)));
7519 tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode)));
7520 tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode)));
7521
7522 tcg_gen_and_i64(b, b, c);
7523 tcg_gen_andc_i64(a, a, c);
7524 tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b);
7525
f976b09e
AG
7526 tcg_temp_free_i64(a);
7527 tcg_temp_free_i64(b);
7528 tcg_temp_free_i64(c);
551e3ef7
TM
7529}
7530
76c15fe0
TM
7531static void gen_xxspltw(DisasContext *ctx)
7532{
7533 TCGv_i64 b, b2;
7534 TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ?
7535 cpu_vsrl(xB(ctx->opcode)) :
7536 cpu_vsrh(xB(ctx->opcode));
7537
7538 if (unlikely(!ctx->vsx_enabled)) {
7539 gen_exception(ctx, POWERPC_EXCP_VSXU);
7540 return;
7541 }
7542
f976b09e
AG
7543 b = tcg_temp_new_i64();
7544 b2 = tcg_temp_new_i64();
76c15fe0
TM
7545
7546 if (UIM(ctx->opcode) & 1) {
7547 tcg_gen_ext32u_i64(b, vsr);
7548 } else {
7549 tcg_gen_shri_i64(b, vsr, 32);
7550 }
7551
7552 tcg_gen_shli_i64(b2, b, 32);
7553 tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2);
7554 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode)));
7555
f976b09e
AG
7556 tcg_temp_free_i64(b);
7557 tcg_temp_free_i64(b2);
76c15fe0
TM
7558}
7559
acc42968
TM
7560static void gen_xxsldwi(DisasContext *ctx)
7561{
7562 TCGv_i64 xth, xtl;
7563 if (unlikely(!ctx->vsx_enabled)) {
7564 gen_exception(ctx, POWERPC_EXCP_VSXU);
7565 return;
7566 }
f976b09e
AG
7567 xth = tcg_temp_new_i64();
7568 xtl = tcg_temp_new_i64();
acc42968
TM
7569
7570 switch (SHW(ctx->opcode)) {
7571 case 0: {
7572 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
7573 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
7574 break;
7575 }
7576 case 1: {
f976b09e 7577 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
7578 tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode)));
7579 tcg_gen_shli_i64(xth, xth, 32);
7580 tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode)));
7581 tcg_gen_shri_i64(t0, t0, 32);
7582 tcg_gen_or_i64(xth, xth, t0);
7583 tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode)));
7584 tcg_gen_shli_i64(xtl, xtl, 32);
7585 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
7586 tcg_gen_shri_i64(t0, t0, 32);
7587 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 7588 tcg_temp_free_i64(t0);
acc42968
TM
7589 break;
7590 }
7591 case 2: {
7592 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
7593 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
7594 break;
7595 }
7596 case 3: {
f976b09e 7597 TCGv_i64 t0 = tcg_temp_new_i64();
acc42968
TM
7598 tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode)));
7599 tcg_gen_shli_i64(xth, xth, 32);
7600 tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode)));
7601 tcg_gen_shri_i64(t0, t0, 32);
7602 tcg_gen_or_i64(xth, xth, t0);
7603 tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode)));
7604 tcg_gen_shli_i64(xtl, xtl, 32);
7605 tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode)));
7606 tcg_gen_shri_i64(t0, t0, 32);
7607 tcg_gen_or_i64(xtl, xtl, t0);
f976b09e 7608 tcg_temp_free_i64(t0);
acc42968
TM
7609 break;
7610 }
7611 }
7612
7613 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth);
7614 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl);
7615
f976b09e
AG
7616 tcg_temp_free_i64(xth);
7617 tcg_temp_free_i64(xtl);
acc42968
TM
7618}
7619
ce577d2e 7620
0487d6a8 7621/*** SPE extension ***/
0487d6a8 7622/* Register moves */
3cd7d1dd 7623
a0e13900
FC
7624static inline void gen_evmra(DisasContext *ctx)
7625{
7626
7627 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7628 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
7629 return;
7630 }
7631
7632#if defined(TARGET_PPC64)
7633 /* rD := rA */
7634 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7635
7636 /* spe_acc := rA */
7637 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
7638 cpu_env,
1328c2bf 7639 offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7640#else
7641 TCGv_i64 tmp = tcg_temp_new_i64();
7642
7643 /* tmp := rA_lo + rA_hi << 32 */
7644 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7645
7646 /* spe_acc := tmp */
1328c2bf 7647 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7648 tcg_temp_free_i64(tmp);
7649
7650 /* rD := rA */
7651 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7652 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7653#endif
7654}
7655
636aa200
BS
7656static inline void gen_load_gpr64(TCGv_i64 t, int reg)
7657{
f78fb44e
AJ
7658#if defined(TARGET_PPC64)
7659 tcg_gen_mov_i64(t, cpu_gpr[reg]);
7660#else
36aa55dc 7661 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
3cd7d1dd 7662#endif
f78fb44e 7663}
3cd7d1dd 7664
636aa200
BS
7665static inline void gen_store_gpr64(int reg, TCGv_i64 t)
7666{
f78fb44e
AJ
7667#if defined(TARGET_PPC64)
7668 tcg_gen_mov_i64(cpu_gpr[reg], t);
7669#else
a7812ae4 7670 TCGv_i64 tmp = tcg_temp_new_i64();
f78fb44e 7671 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
f78fb44e
AJ
7672 tcg_gen_shri_i64(tmp, t, 32);
7673 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
a7812ae4 7674 tcg_temp_free_i64(tmp);
3cd7d1dd 7675#endif
f78fb44e 7676}
3cd7d1dd 7677
70560da7 7678#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 7679static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
7680{ \
7681 if (Rc(ctx->opcode)) \
7682 gen_##name1(ctx); \
7683 else \
7684 gen_##name0(ctx); \
7685}
7686
7687/* Handler for undefined SPE opcodes */
636aa200 7688static inline void gen_speundef(DisasContext *ctx)
0487d6a8 7689{
e06fcd75 7690 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
7691}
7692
57951c27
AJ
7693/* SPE logic */
7694#if defined(TARGET_PPC64)
7695#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 7696static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7697{ \
7698 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7699 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7700 return; \
7701 } \
57951c27
AJ
7702 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7703 cpu_gpr[rB(ctx->opcode)]); \
7704}
7705#else
7706#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 7707static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7708{ \
7709 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7710 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7711 return; \
7712 } \
7713 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7714 cpu_gpr[rB(ctx->opcode)]); \
7715 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7716 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 7717}
57951c27
AJ
7718#endif
7719
7720GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
7721GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
7722GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
7723GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
7724GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
7725GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
7726GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
7727GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 7728
57951c27
AJ
7729/* SPE logic immediate */
7730#if defined(TARGET_PPC64)
7731#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 7732static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a
AJ
7733{ \
7734 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7735 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
7736 return; \
7737 } \
a7812ae4
PB
7738 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7739 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7740 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
7741 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7742 tcg_opi(t0, t0, rB(ctx->opcode)); \
7743 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7744 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 7745 tcg_temp_free_i64(t2); \
57951c27
AJ
7746 tcg_opi(t1, t1, rB(ctx->opcode)); \
7747 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
7748 tcg_temp_free_i32(t0); \
7749 tcg_temp_free_i32(t1); \
3d3a6a0a 7750}
57951c27
AJ
7751#else
7752#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 7753static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7754{ \
7755 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7756 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7757 return; \
7758 } \
57951c27
AJ
7759 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7760 rB(ctx->opcode)); \
7761 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7762 rB(ctx->opcode)); \
0487d6a8 7763}
57951c27
AJ
7764#endif
7765GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
7766GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
7767GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
7768GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 7769
57951c27
AJ
7770/* SPE arithmetic */
7771#if defined(TARGET_PPC64)
7772#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 7773static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7774{ \
7775 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7776 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7777 return; \
7778 } \
a7812ae4
PB
7779 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7780 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7781 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
7782 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7783 tcg_op(t0, t0); \
7784 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7785 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 7786 tcg_temp_free_i64(t2); \
57951c27
AJ
7787 tcg_op(t1, t1); \
7788 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
7789 tcg_temp_free_i32(t0); \
7790 tcg_temp_free_i32(t1); \
0487d6a8 7791}
57951c27 7792#else
a7812ae4 7793#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 7794static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7795{ \
7796 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7797 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7798 return; \
7799 } \
7800 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
7801 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
7802}
7803#endif
0487d6a8 7804
636aa200 7805static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27
AJ
7806{
7807 int l1 = gen_new_label();
7808 int l2 = gen_new_label();
0487d6a8 7809
57951c27
AJ
7810 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
7811 tcg_gen_neg_i32(ret, arg1);
7812 tcg_gen_br(l2);
7813 gen_set_label(l1);
a7812ae4 7814 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
7815 gen_set_label(l2);
7816}
7817GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
7818GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
7819GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
7820GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 7821static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 7822{
57951c27
AJ
7823 tcg_gen_addi_i32(ret, arg1, 0x8000);
7824 tcg_gen_ext16u_i32(ret, ret);
7825}
7826GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
7827GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
7828GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 7829
57951c27
AJ
7830#if defined(TARGET_PPC64)
7831#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 7832static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7833{ \
7834 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7835 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7836 return; \
7837 } \
a7812ae4
PB
7838 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7839 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7840 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
501e23c4 7841 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
57951c27
AJ
7842 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7843 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
7844 tcg_op(t0, t0, t2); \
7845 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
7846 tcg_gen_trunc_i64_i32(t1, t3); \
7847 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
7848 tcg_gen_trunc_i64_i32(t2, t3); \
a7812ae4 7849 tcg_temp_free_i64(t3); \
57951c27 7850 tcg_op(t1, t1, t2); \
a7812ae4 7851 tcg_temp_free_i32(t2); \
57951c27 7852 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
7853 tcg_temp_free_i32(t0); \
7854 tcg_temp_free_i32(t1); \
0487d6a8 7855}
57951c27
AJ
7856#else
7857#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 7858static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
7859{ \
7860 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7861 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7862 return; \
7863 } \
57951c27
AJ
7864 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7865 cpu_gpr[rB(ctx->opcode)]); \
7866 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7867 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 7868}
57951c27 7869#endif
0487d6a8 7870
636aa200 7871static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 7872{
a7812ae4 7873 TCGv_i32 t0;
57951c27 7874 int l1, l2;
0487d6a8 7875
57951c27
AJ
7876 l1 = gen_new_label();
7877 l2 = gen_new_label();
a7812ae4 7878 t0 = tcg_temp_local_new_i32();
57951c27
AJ
7879 /* No error here: 6 bits are used */
7880 tcg_gen_andi_i32(t0, arg2, 0x3F);
7881 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7882 tcg_gen_shr_i32(ret, arg1, t0);
7883 tcg_gen_br(l2);
7884 gen_set_label(l1);
7885 tcg_gen_movi_i32(ret, 0);
0aef4261 7886 gen_set_label(l2);
a7812ae4 7887 tcg_temp_free_i32(t0);
57951c27
AJ
7888}
7889GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 7890static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 7891{
a7812ae4 7892 TCGv_i32 t0;
57951c27
AJ
7893 int l1, l2;
7894
7895 l1 = gen_new_label();
7896 l2 = gen_new_label();
a7812ae4 7897 t0 = tcg_temp_local_new_i32();
57951c27
AJ
7898 /* No error here: 6 bits are used */
7899 tcg_gen_andi_i32(t0, arg2, 0x3F);
7900 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7901 tcg_gen_sar_i32(ret, arg1, t0);
7902 tcg_gen_br(l2);
7903 gen_set_label(l1);
7904 tcg_gen_movi_i32(ret, 0);
0aef4261 7905 gen_set_label(l2);
a7812ae4 7906 tcg_temp_free_i32(t0);
57951c27
AJ
7907}
7908GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 7909static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 7910{
a7812ae4 7911 TCGv_i32 t0;
57951c27
AJ
7912 int l1, l2;
7913
7914 l1 = gen_new_label();
7915 l2 = gen_new_label();
a7812ae4 7916 t0 = tcg_temp_local_new_i32();
57951c27
AJ
7917 /* No error here: 6 bits are used */
7918 tcg_gen_andi_i32(t0, arg2, 0x3F);
7919 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7920 tcg_gen_shl_i32(ret, arg1, t0);
7921 tcg_gen_br(l2);
7922 gen_set_label(l1);
7923 tcg_gen_movi_i32(ret, 0);
e29ef9fa 7924 gen_set_label(l2);
a7812ae4 7925 tcg_temp_free_i32(t0);
57951c27
AJ
7926}
7927GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 7928static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 7929{
a7812ae4 7930 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
7931 tcg_gen_andi_i32(t0, arg2, 0x1F);
7932 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 7933 tcg_temp_free_i32(t0);
57951c27
AJ
7934}
7935GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 7936static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
7937{
7938 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7939 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
7940 return;
7941 }
7942#if defined(TARGET_PPC64)
a7812ae4
PB
7943 TCGv t0 = tcg_temp_new();
7944 TCGv t1 = tcg_temp_new();
57951c27
AJ
7945 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
7946 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
7947 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7948 tcg_temp_free(t0);
7949 tcg_temp_free(t1);
7950#else
7951 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7952 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7953#endif
7954}
7955GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 7956static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 7957{
57951c27
AJ
7958 tcg_gen_sub_i32(ret, arg2, arg1);
7959}
7960GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 7961
57951c27
AJ
7962/* SPE arithmetic immediate */
7963#if defined(TARGET_PPC64)
7964#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 7965static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7966{ \
7967 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7968 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7969 return; \
7970 } \
a7812ae4
PB
7971 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7972 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7973 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
7974 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7975 tcg_op(t0, t0, rA(ctx->opcode)); \
7976 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7977 tcg_gen_trunc_i64_i32(t1, t2); \
e06fcd75 7978 tcg_temp_free_i64(t2); \
57951c27
AJ
7979 tcg_op(t1, t1, rA(ctx->opcode)); \
7980 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
7981 tcg_temp_free_i32(t0); \
7982 tcg_temp_free_i32(t1); \
57951c27
AJ
7983}
7984#else
7985#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 7986static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7987{ \
7988 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7989 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7990 return; \
7991 } \
7992 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7993 rA(ctx->opcode)); \
7994 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7995 rA(ctx->opcode)); \
7996}
7997#endif
7998GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
7999GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
8000
8001/* SPE comparison */
8002#if defined(TARGET_PPC64)
8003#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8004static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8005{ \
8006 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8007 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8008 return; \
8009 } \
8010 int l1 = gen_new_label(); \
8011 int l2 = gen_new_label(); \
8012 int l3 = gen_new_label(); \
8013 int l4 = gen_new_label(); \
a7812ae4
PB
8014 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8015 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8016 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
8017 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8018 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8019 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
a7812ae4 8020 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
8021 tcg_gen_br(l2); \
8022 gen_set_label(l1); \
8023 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8024 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8025 gen_set_label(l2); \
8026 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8027 tcg_gen_trunc_i64_i32(t0, t2); \
8028 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8029 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 8030 tcg_temp_free_i64(t2); \
57951c27
AJ
8031 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8032 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8033 ~(CRF_CH | CRF_CH_AND_CL)); \
8034 tcg_gen_br(l4); \
8035 gen_set_label(l3); \
8036 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8037 CRF_CH | CRF_CH_OR_CL); \
8038 gen_set_label(l4); \
a7812ae4
PB
8039 tcg_temp_free_i32(t0); \
8040 tcg_temp_free_i32(t1); \
57951c27
AJ
8041}
8042#else
8043#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 8044static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8045{ \
8046 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8047 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8048 return; \
8049 } \
8050 int l1 = gen_new_label(); \
8051 int l2 = gen_new_label(); \
8052 int l3 = gen_new_label(); \
8053 int l4 = gen_new_label(); \
8054 \
8055 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8056 cpu_gpr[rB(ctx->opcode)], l1); \
8057 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8058 tcg_gen_br(l2); \
8059 gen_set_label(l1); \
8060 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8061 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8062 gen_set_label(l2); \
8063 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8064 cpu_gprh[rB(ctx->opcode)], l3); \
8065 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8066 ~(CRF_CH | CRF_CH_AND_CL)); \
8067 tcg_gen_br(l4); \
8068 gen_set_label(l3); \
8069 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8070 CRF_CH | CRF_CH_OR_CL); \
8071 gen_set_label(l4); \
8072}
8073#endif
8074GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
8075GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
8076GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
8077GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
8078GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
8079
8080/* SPE misc */
636aa200 8081static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
8082{
8083 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
8084 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
8085 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 8086}
636aa200 8087static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
8088{
8089 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8090 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8091 return;
8092 }
8093#if defined(TARGET_PPC64)
a7812ae4
PB
8094 TCGv t0 = tcg_temp_new();
8095 TCGv t1 = tcg_temp_new();
17d9b3af 8096 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8097 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8098 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8099 tcg_temp_free(t0);
8100 tcg_temp_free(t1);
8101#else
57951c27 8102 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 8103 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8104#endif
8105}
636aa200 8106static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
8107{
8108 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8109 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8110 return;
8111 }
8112#if defined(TARGET_PPC64)
a7812ae4
PB
8113 TCGv t0 = tcg_temp_new();
8114 TCGv t1 = tcg_temp_new();
17d9b3af 8115 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8116 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
8117 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8118 tcg_temp_free(t0);
8119 tcg_temp_free(t1);
8120#else
8121 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8122 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8123#endif
8124}
636aa200 8125static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
8126{
8127 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8128 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
8129 return;
8130 }
8131#if defined(TARGET_PPC64)
a7812ae4
PB
8132 TCGv t0 = tcg_temp_new();
8133 TCGv t1 = tcg_temp_new();
57951c27
AJ
8134 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
8135 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
8136 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
8137 tcg_temp_free(t0);
8138 tcg_temp_free(t1);
8139#else
33890b3e
NF
8140 if (rD(ctx->opcode) == rA(ctx->opcode)) {
8141 TCGv_i32 tmp = tcg_temp_new_i32();
8142 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
8143 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8144 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
8145 tcg_temp_free_i32(tmp);
8146 } else {
8147 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8148 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8149 }
57951c27
AJ
8150#endif
8151}
636aa200 8152static inline void gen_evsplati(DisasContext *ctx)
57951c27 8153{
ae01847f 8154 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 8155
57951c27 8156#if defined(TARGET_PPC64)
38d14952 8157 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8158#else
8159 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8160 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8161#endif
8162}
636aa200 8163static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 8164{
ae01847f 8165 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 8166
57951c27 8167#if defined(TARGET_PPC64)
38d14952 8168 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
8169#else
8170 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
8171 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
8172#endif
0487d6a8
JM
8173}
8174
636aa200 8175static inline void gen_evsel(DisasContext *ctx)
57951c27
AJ
8176{
8177 int l1 = gen_new_label();
8178 int l2 = gen_new_label();
8179 int l3 = gen_new_label();
8180 int l4 = gen_new_label();
a7812ae4 8181 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 8182#if defined(TARGET_PPC64)
a7812ae4
PB
8183 TCGv t1 = tcg_temp_local_new();
8184 TCGv t2 = tcg_temp_local_new();
57951c27
AJ
8185#endif
8186 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
8187 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
8188#if defined(TARGET_PPC64)
8189 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8190#else
8191 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
8192#endif
8193 tcg_gen_br(l2);
8194 gen_set_label(l1);
8195#if defined(TARGET_PPC64)
8196 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
8197#else
8198 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
8199#endif
8200 gen_set_label(l2);
8201 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
8202 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
8203#if defined(TARGET_PPC64)
17d9b3af 8204 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
8205#else
8206 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8207#endif
8208 tcg_gen_br(l4);
8209 gen_set_label(l3);
8210#if defined(TARGET_PPC64)
17d9b3af 8211 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
8212#else
8213 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
8214#endif
8215 gen_set_label(l4);
a7812ae4 8216 tcg_temp_free_i32(t0);
57951c27
AJ
8217#if defined(TARGET_PPC64)
8218 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
8219 tcg_temp_free(t1);
8220 tcg_temp_free(t2);
8221#endif
8222}
e8eaa2c0
BS
8223
8224static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
8225{
8226 gen_evsel(ctx);
8227}
e8eaa2c0
BS
8228
8229static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
8230{
8231 gen_evsel(ctx);
8232}
e8eaa2c0
BS
8233
8234static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
8235{
8236 gen_evsel(ctx);
8237}
e8eaa2c0
BS
8238
8239static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
8240{
8241 gen_evsel(ctx);
8242}
0487d6a8 8243
a0e13900
FC
8244/* Multiply */
8245
8246static inline void gen_evmwumi(DisasContext *ctx)
8247{
8248 TCGv_i64 t0, t1;
8249
8250 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8251 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8252 return;
8253 }
8254
8255 t0 = tcg_temp_new_i64();
8256 t1 = tcg_temp_new_i64();
8257
8258 /* t0 := rA; t1 := rB */
8259#if defined(TARGET_PPC64)
8260 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8261 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8262#else
8263 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8264 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8265#endif
8266
8267 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8268
8269 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8270
8271 tcg_temp_free_i64(t0);
8272 tcg_temp_free_i64(t1);
8273}
8274
8275static inline void gen_evmwumia(DisasContext *ctx)
8276{
8277 TCGv_i64 tmp;
8278
8279 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8280 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8281 return;
8282 }
8283
8284 gen_evmwumi(ctx); /* rD := rA * rB */
8285
8286 tmp = tcg_temp_new_i64();
8287
8288 /* acc := rD */
8289 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8290 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8291 tcg_temp_free_i64(tmp);
8292}
8293
8294static inline void gen_evmwumiaa(DisasContext *ctx)
8295{
8296 TCGv_i64 acc;
8297 TCGv_i64 tmp;
8298
8299 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8300 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8301 return;
8302 }
8303
8304 gen_evmwumi(ctx); /* rD := rA * rB */
8305
8306 acc = tcg_temp_new_i64();
8307 tmp = tcg_temp_new_i64();
8308
8309 /* tmp := rD */
8310 gen_load_gpr64(tmp, rD(ctx->opcode));
8311
8312 /* Load acc */
1328c2bf 8313 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8314
8315 /* acc := tmp + acc */
8316 tcg_gen_add_i64(acc, acc, tmp);
8317
8318 /* Store acc */
1328c2bf 8319 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8320
8321 /* rD := acc */
8322 gen_store_gpr64(rD(ctx->opcode), acc);
8323
8324 tcg_temp_free_i64(acc);
8325 tcg_temp_free_i64(tmp);
8326}
8327
8328static inline void gen_evmwsmi(DisasContext *ctx)
8329{
8330 TCGv_i64 t0, t1;
8331
8332 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8333 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
8334 return;
8335 }
8336
8337 t0 = tcg_temp_new_i64();
8338 t1 = tcg_temp_new_i64();
8339
8340 /* t0 := rA; t1 := rB */
8341#if defined(TARGET_PPC64)
8342 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
8343 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
8344#else
8345 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
8346 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
8347#endif
8348
8349 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
8350
8351 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
8352
8353 tcg_temp_free_i64(t0);
8354 tcg_temp_free_i64(t1);
8355}
8356
8357static inline void gen_evmwsmia(DisasContext *ctx)
8358{
8359 TCGv_i64 tmp;
8360
8361 gen_evmwsmi(ctx); /* rD := rA * rB */
8362
8363 tmp = tcg_temp_new_i64();
8364
8365 /* acc := rD */
8366 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 8367 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8368
8369 tcg_temp_free_i64(tmp);
8370}
8371
8372static inline void gen_evmwsmiaa(DisasContext *ctx)
8373{
8374 TCGv_i64 acc = tcg_temp_new_i64();
8375 TCGv_i64 tmp = tcg_temp_new_i64();
8376
8377 gen_evmwsmi(ctx); /* rD := rA * rB */
8378
8379 acc = tcg_temp_new_i64();
8380 tmp = tcg_temp_new_i64();
8381
8382 /* tmp := rD */
8383 gen_load_gpr64(tmp, rD(ctx->opcode));
8384
8385 /* Load acc */
1328c2bf 8386 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8387
8388 /* acc := tmp + acc */
8389 tcg_gen_add_i64(acc, acc, tmp);
8390
8391 /* Store acc */
1328c2bf 8392 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
8393
8394 /* rD := acc */
8395 gen_store_gpr64(rD(ctx->opcode), acc);
8396
8397 tcg_temp_free_i64(acc);
8398 tcg_temp_free_i64(tmp);
8399}
8400
70560da7
FC
8401GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8402GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8403GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8404GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8405GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8406GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8407GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
8408GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
8409GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
8410GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8411GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8412GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8413GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8414GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8415GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8416GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8417GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
8418GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8419GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8420GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
8421GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
8422GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8423GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
8424GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
8425GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8426GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
8427GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8428GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
8429GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 8430
6a6ae23f 8431/* SPE load and stores */
636aa200 8432static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
8433{
8434 target_ulong uimm = rB(ctx->opcode);
8435
76db3ba4 8436 if (rA(ctx->opcode) == 0) {
6a6ae23f 8437 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 8438 } else {
6a6ae23f 8439 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
c791fe84 8440 if (NARROW_MODE(ctx)) {
76db3ba4
AJ
8441 tcg_gen_ext32u_tl(EA, EA);
8442 }
76db3ba4 8443 }
0487d6a8 8444}
6a6ae23f 8445
636aa200 8446static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8447{
8448#if defined(TARGET_PPC64)
76db3ba4 8449 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8450#else
8451 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 8452 gen_qemu_ld64(ctx, t0, addr);
6a6ae23f
AJ
8453 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
8454 tcg_gen_shri_i64(t0, t0, 32);
8455 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
8456 tcg_temp_free_i64(t0);
8457#endif
0487d6a8 8458}
6a6ae23f 8459
636aa200 8460static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 8461{
0487d6a8 8462#if defined(TARGET_PPC64)
6a6ae23f 8463 TCGv t0 = tcg_temp_new();
76db3ba4 8464 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f 8465 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
76db3ba4
AJ
8466 gen_addr_add(ctx, addr, addr, 4);
8467 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
8468 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8469 tcg_temp_free(t0);
8470#else
76db3ba4
AJ
8471 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8472 gen_addr_add(ctx, addr, addr, 4);
8473 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f 8474#endif
0487d6a8 8475}
6a6ae23f 8476
636aa200 8477static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8478{
8479 TCGv t0 = tcg_temp_new();
8480#if defined(TARGET_PPC64)
76db3ba4 8481 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8482 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
8483 gen_addr_add(ctx, addr, addr, 2);
8484 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8485 tcg_gen_shli_tl(t0, t0, 32);
8486 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8487 gen_addr_add(ctx, addr, addr, 2);
8488 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8489 tcg_gen_shli_tl(t0, t0, 16);
8490 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8491 gen_addr_add(ctx, addr, addr, 2);
8492 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8493 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 8494#else
76db3ba4 8495 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8496 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8497 gen_addr_add(ctx, addr, addr, 2);
8498 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8499 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
8500 gen_addr_add(ctx, addr, addr, 2);
8501 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8502 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8503 gen_addr_add(ctx, addr, addr, 2);
8504 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8505 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 8506#endif
6a6ae23f 8507 tcg_temp_free(t0);
0487d6a8
JM
8508}
8509
636aa200 8510static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8511{
8512 TCGv t0 = tcg_temp_new();
76db3ba4 8513 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8514#if defined(TARGET_PPC64)
8515 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
8516 tcg_gen_shli_tl(t0, t0, 16);
8517 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8518#else
8519 tcg_gen_shli_tl(t0, t0, 16);
8520 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8521 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8522#endif
8523 tcg_temp_free(t0);
0487d6a8
JM
8524}
8525
636aa200 8526static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8527{
8528 TCGv t0 = tcg_temp_new();
76db3ba4 8529 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8530#if defined(TARGET_PPC64)
8531 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8532 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8533#else
8534 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8535 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8536#endif
8537 tcg_temp_free(t0);
0487d6a8
JM
8538}
8539
636aa200 8540static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8541{
8542 TCGv t0 = tcg_temp_new();
76db3ba4 8543 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
8544#if defined(TARGET_PPC64)
8545 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8546 tcg_gen_ext32u_tl(t0, t0);
8547 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8548#else
8549 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8550 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8551#endif
8552 tcg_temp_free(t0);
8553}
8554
636aa200 8555static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8556{
8557 TCGv t0 = tcg_temp_new();
8558#if defined(TARGET_PPC64)
76db3ba4 8559 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8560 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
8561 gen_addr_add(ctx, addr, addr, 2);
8562 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8563 tcg_gen_shli_tl(t0, t0, 16);
8564 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8565#else
76db3ba4 8566 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 8567 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
8568 gen_addr_add(ctx, addr, addr, 2);
8569 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8570 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
8571#endif
8572 tcg_temp_free(t0);
8573}
8574
636aa200 8575static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8576{
8577#if defined(TARGET_PPC64)
8578 TCGv t0 = tcg_temp_new();
76db3ba4
AJ
8579 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
8580 gen_addr_add(ctx, addr, addr, 2);
8581 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8582 tcg_gen_shli_tl(t0, t0, 32);
8583 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8584 tcg_temp_free(t0);
8585#else
76db3ba4
AJ
8586 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8587 gen_addr_add(ctx, addr, addr, 2);
8588 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8589#endif
8590}
8591
636aa200 8592static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8593{
8594#if defined(TARGET_PPC64)
8595 TCGv t0 = tcg_temp_new();
76db3ba4 8596 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f 8597 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8598 gen_addr_add(ctx, addr, addr, 2);
8599 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
8600 tcg_gen_shli_tl(t0, t0, 32);
8601 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8602 tcg_temp_free(t0);
8603#else
76db3ba4
AJ
8604 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
8605 gen_addr_add(ctx, addr, addr, 2);
8606 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
8607#endif
8608}
8609
636aa200 8610static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8611{
8612 TCGv t0 = tcg_temp_new();
76db3ba4 8613 gen_qemu_ld32u(ctx, t0, addr);
0487d6a8 8614#if defined(TARGET_PPC64)
6a6ae23f
AJ
8615 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
8616 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8617#else
8618 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
8619 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
8620#endif
8621 tcg_temp_free(t0);
8622}
8623
636aa200 8624static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8625{
8626 TCGv t0 = tcg_temp_new();
8627#if defined(TARGET_PPC64)
76db3ba4 8628 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8629 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
8630 tcg_gen_shli_tl(t0, t0, 32);
8631 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
8632 gen_addr_add(ctx, addr, addr, 2);
8633 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8634 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8635 tcg_gen_shli_tl(t0, t0, 16);
8636 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
8637#else
76db3ba4 8638 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8639 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
8640 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
8641 gen_addr_add(ctx, addr, addr, 2);
8642 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
8643 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
8644 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
0487d6a8 8645#endif
6a6ae23f
AJ
8646 tcg_temp_free(t0);
8647}
8648
636aa200 8649static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8650{
8651#if defined(TARGET_PPC64)
76db3ba4 8652 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
0487d6a8 8653#else
6a6ae23f
AJ
8654 TCGv_i64 t0 = tcg_temp_new_i64();
8655 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
76db3ba4 8656 gen_qemu_st64(ctx, t0, addr);
6a6ae23f
AJ
8657 tcg_temp_free_i64(t0);
8658#endif
8659}
8660
636aa200 8661static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 8662{
0487d6a8 8663#if defined(TARGET_PPC64)
6a6ae23f
AJ
8664 TCGv t0 = tcg_temp_new();
8665 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8666 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
8667 tcg_temp_free(t0);
8668#else
76db3ba4 8669 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8670#endif
76db3ba4
AJ
8671 gen_addr_add(ctx, addr, addr, 4);
8672 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8673}
8674
636aa200 8675static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8676{
8677 TCGv t0 = tcg_temp_new();
8678#if defined(TARGET_PPC64)
8679 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
8680#else
8681 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
8682#endif
76db3ba4
AJ
8683 gen_qemu_st16(ctx, t0, addr);
8684 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f
AJ
8685#if defined(TARGET_PPC64)
8686 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8687 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 8688#else
76db3ba4 8689 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8690#endif
76db3ba4 8691 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 8692 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 8693 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 8694 tcg_temp_free(t0);
76db3ba4
AJ
8695 gen_addr_add(ctx, addr, addr, 2);
8696 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8697}
8698
636aa200 8699static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8700{
8701 TCGv t0 = tcg_temp_new();
8702#if defined(TARGET_PPC64)
8703 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
8704#else
8705 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
8706#endif
76db3ba4
AJ
8707 gen_qemu_st16(ctx, t0, addr);
8708 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 8709 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 8710 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
8711 tcg_temp_free(t0);
8712}
8713
636aa200 8714static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8715{
8716#if defined(TARGET_PPC64)
8717 TCGv t0 = tcg_temp_new();
8718 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8719 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
8720 tcg_temp_free(t0);
8721#else
76db3ba4 8722 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 8723#endif
76db3ba4
AJ
8724 gen_addr_add(ctx, addr, addr, 2);
8725 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8726}
8727
636aa200 8728static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
8729{
8730#if defined(TARGET_PPC64)
8731 TCGv t0 = tcg_temp_new();
8732 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 8733 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
8734 tcg_temp_free(t0);
8735#else
76db3ba4 8736 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8737#endif
8738}
8739
636aa200 8740static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 8741{
76db3ba4 8742 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
8743}
8744
8745#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 8746static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
8747{ \
8748 TCGv t0; \
8749 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8750 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
8751 return; \
8752 } \
76db3ba4 8753 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
8754 t0 = tcg_temp_new(); \
8755 if (Rc(ctx->opcode)) { \
76db3ba4 8756 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 8757 } else { \
76db3ba4 8758 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
8759 } \
8760 gen_op_##name(ctx, t0); \
8761 tcg_temp_free(t0); \
8762}
8763
8764GEN_SPEOP_LDST(evldd, 0x00, 3);
8765GEN_SPEOP_LDST(evldw, 0x01, 3);
8766GEN_SPEOP_LDST(evldh, 0x02, 3);
8767GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
8768GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
8769GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
8770GEN_SPEOP_LDST(evlwhe, 0x08, 2);
8771GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
8772GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
8773GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
8774GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
8775
8776GEN_SPEOP_LDST(evstdd, 0x10, 3);
8777GEN_SPEOP_LDST(evstdw, 0x11, 3);
8778GEN_SPEOP_LDST(evstdh, 0x12, 3);
8779GEN_SPEOP_LDST(evstwhe, 0x18, 2);
8780GEN_SPEOP_LDST(evstwho, 0x1A, 2);
8781GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
8782GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
8783
8784/* Multiply and add - TODO */
8785#if 0
70560da7
FC
8786GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
8787GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8788GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8789GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8790GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8791GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8792GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8793GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8794GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8795GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8796GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
8797GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8798
8799GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8800GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8801GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8802GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8803GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8804GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8805GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8806GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
8807GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
8808GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8809GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8810GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8811
8812GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8813GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8814GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8815GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
8816GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
8817
8818GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8819GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8820GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8821GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8822GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8823GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8824GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8825GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8826GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8827GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8828GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
8829GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8830
8831GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8832GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
8833GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8834GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8835
8836GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8837GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8838GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8839GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8840GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8841GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8842GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8843GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8844GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8845GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8846GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
8847GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8848
8849GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
8850GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
8851GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
8852GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
8853GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
8854#endif
8855
8856/*** SPE floating-point extension ***/
1c97856d
AJ
8857#if defined(TARGET_PPC64)
8858#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 8859static inline void gen_##name(DisasContext *ctx) \
0487d6a8 8860{ \
1c97856d
AJ
8861 TCGv_i32 t0; \
8862 TCGv t1; \
8863 t0 = tcg_temp_new_i32(); \
8864 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 8865 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
8866 t1 = tcg_temp_new(); \
8867 tcg_gen_extu_i32_tl(t1, t0); \
8868 tcg_temp_free_i32(t0); \
8869 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8870 0xFFFFFFFF00000000ULL); \
8871 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8872 tcg_temp_free(t1); \
0487d6a8 8873}
1c97856d 8874#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 8875static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8876{ \
8877 TCGv_i32 t0; \
8878 TCGv t1; \
8879 t0 = tcg_temp_new_i32(); \
8e703949 8880 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
8881 t1 = tcg_temp_new(); \
8882 tcg_gen_extu_i32_tl(t1, t0); \
8883 tcg_temp_free_i32(t0); \
8884 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8885 0xFFFFFFFF00000000ULL); \
8886 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8887 tcg_temp_free(t1); \
8888}
8889#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 8890static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8891{ \
8892 TCGv_i32 t0 = tcg_temp_new_i32(); \
8893 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 8894 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
8895 tcg_temp_free_i32(t0); \
8896}
8897#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 8898static inline void gen_##name(DisasContext *ctx) \
1c97856d 8899{ \
8e703949
BS
8900 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8901 cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
8902}
8903#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 8904static inline void gen_##name(DisasContext *ctx) \
57951c27 8905{ \
1c97856d
AJ
8906 TCGv_i32 t0, t1; \
8907 TCGv_i64 t2; \
57951c27 8908 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8909 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8910 return; \
8911 } \
1c97856d
AJ
8912 t0 = tcg_temp_new_i32(); \
8913 t1 = tcg_temp_new_i32(); \
8914 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8915 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 8916 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
8917 tcg_temp_free_i32(t1); \
8918 t2 = tcg_temp_new(); \
8919 tcg_gen_extu_i32_tl(t2, t0); \
8920 tcg_temp_free_i32(t0); \
8921 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8922 0xFFFFFFFF00000000ULL); \
8923 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8924 tcg_temp_free(t2); \
57951c27 8925}
1c97856d 8926#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 8927static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8928{ \
8929 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8930 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8931 return; \
8932 } \
8e703949
BS
8933 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8934 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
57951c27 8935}
1c97856d 8936#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 8937static inline void gen_##name(DisasContext *ctx) \
57951c27 8938{ \
1c97856d 8939 TCGv_i32 t0, t1; \
57951c27 8940 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8941 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8942 return; \
8943 } \
1c97856d
AJ
8944 t0 = tcg_temp_new_i32(); \
8945 t1 = tcg_temp_new_i32(); \
8946 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8947 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 8948 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
8949 tcg_temp_free_i32(t0); \
8950 tcg_temp_free_i32(t1); \
8951}
8952#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 8953static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8954{ \
8955 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8956 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
8957 return; \
8958 } \
8e703949 8959 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
8960 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8961}
8962#else
8963#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 8964static inline void gen_##name(DisasContext *ctx) \
1c97856d 8965{ \
8e703949
BS
8966 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8967 cpu_gpr[rB(ctx->opcode)]); \
57951c27 8968}
1c97856d 8969#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 8970static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8971{ \
8972 TCGv_i64 t0 = tcg_temp_new_i64(); \
8973 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 8974 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
8975 tcg_temp_free_i64(t0); \
8976}
8977#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 8978static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8979{ \
8980 TCGv_i64 t0 = tcg_temp_new_i64(); \
8e703949 8981 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
8982 gen_store_gpr64(rD(ctx->opcode), t0); \
8983 tcg_temp_free_i64(t0); \
8984}
8985#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 8986static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8987{ \
8988 TCGv_i64 t0 = tcg_temp_new_i64(); \
8989 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 8990 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
8991 gen_store_gpr64(rD(ctx->opcode), t0); \
8992 tcg_temp_free_i64(t0); \
8993}
8994#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 8995static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8996{ \
8997 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8998 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
8999 return; \
9000 } \
8e703949 9001 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9002 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9003}
9004#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 9005static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9006{ \
9007 TCGv_i64 t0, t1; \
9008 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9009 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9010 return; \
9011 } \
9012 t0 = tcg_temp_new_i64(); \
9013 t1 = tcg_temp_new_i64(); \
9014 gen_load_gpr64(t0, rA(ctx->opcode)); \
9015 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9016 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
9017 gen_store_gpr64(rD(ctx->opcode), t0); \
9018 tcg_temp_free_i64(t0); \
9019 tcg_temp_free_i64(t1); \
9020}
9021#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 9022static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9023{ \
9024 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9025 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9026 return; \
9027 } \
8e703949 9028 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
9029 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9030}
9031#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 9032static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
9033{ \
9034 TCGv_i64 t0, t1; \
9035 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 9036 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
9037 return; \
9038 } \
9039 t0 = tcg_temp_new_i64(); \
9040 t1 = tcg_temp_new_i64(); \
9041 gen_load_gpr64(t0, rA(ctx->opcode)); \
9042 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 9043 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
9044 tcg_temp_free_i64(t0); \
9045 tcg_temp_free_i64(t1); \
9046}
9047#endif
57951c27 9048
0487d6a8
JM
9049/* Single precision floating-point vectors operations */
9050/* Arithmetic */
1c97856d
AJ
9051GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
9052GEN_SPEFPUOP_ARITH2_64_64(evfssub);
9053GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
9054GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 9055static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
9056{
9057 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9058 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9059 return;
9060 }
9061#if defined(TARGET_PPC64)
6d5c34fa 9062 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
1c97856d 9063#else
6d5c34fa
MP
9064 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
9065 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9066#endif
9067}
636aa200 9068static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
9069{
9070 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9071 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9072 return;
9073 }
9074#if defined(TARGET_PPC64)
6d5c34fa 9075 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9076#else
6d5c34fa
MP
9077 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9078 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9079#endif
9080}
636aa200 9081static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
9082{
9083 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9084 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9085 return;
9086 }
9087#if defined(TARGET_PPC64)
6d5c34fa 9088 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 9089#else
6d5c34fa
MP
9090 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
9091 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9092#endif
9093}
9094
0487d6a8 9095/* Conversion */
1c97856d
AJ
9096GEN_SPEFPUOP_CONV_64_64(evfscfui);
9097GEN_SPEFPUOP_CONV_64_64(evfscfsi);
9098GEN_SPEFPUOP_CONV_64_64(evfscfuf);
9099GEN_SPEFPUOP_CONV_64_64(evfscfsf);
9100GEN_SPEFPUOP_CONV_64_64(evfsctui);
9101GEN_SPEFPUOP_CONV_64_64(evfsctsi);
9102GEN_SPEFPUOP_CONV_64_64(evfsctuf);
9103GEN_SPEFPUOP_CONV_64_64(evfsctsf);
9104GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
9105GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
9106
0487d6a8 9107/* Comparison */
1c97856d
AJ
9108GEN_SPEFPUOP_COMP_64(evfscmpgt);
9109GEN_SPEFPUOP_COMP_64(evfscmplt);
9110GEN_SPEFPUOP_COMP_64(evfscmpeq);
9111GEN_SPEFPUOP_COMP_64(evfststgt);
9112GEN_SPEFPUOP_COMP_64(evfststlt);
9113GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
9114
9115/* Opcodes definitions */
70560da7
FC
9116GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9117GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9118GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9119GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9120GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9121GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9122GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9123GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9124GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9125GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9126GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9127GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9128GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9129GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9130
9131/* Single precision floating-point operations */
9132/* Arithmetic */
1c97856d
AJ
9133GEN_SPEFPUOP_ARITH2_32_32(efsadd);
9134GEN_SPEFPUOP_ARITH2_32_32(efssub);
9135GEN_SPEFPUOP_ARITH2_32_32(efsmul);
9136GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 9137static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
9138{
9139 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9140 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9141 return;
9142 }
6d5c34fa 9143 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 9144}
636aa200 9145static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
9146{
9147 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9148 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9149 return;
9150 }
6d5c34fa 9151 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 9152}
636aa200 9153static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
9154{
9155 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9156 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9157 return;
9158 }
6d5c34fa 9159 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9160}
9161
0487d6a8 9162/* Conversion */
1c97856d
AJ
9163GEN_SPEFPUOP_CONV_32_32(efscfui);
9164GEN_SPEFPUOP_CONV_32_32(efscfsi);
9165GEN_SPEFPUOP_CONV_32_32(efscfuf);
9166GEN_SPEFPUOP_CONV_32_32(efscfsf);
9167GEN_SPEFPUOP_CONV_32_32(efsctui);
9168GEN_SPEFPUOP_CONV_32_32(efsctsi);
9169GEN_SPEFPUOP_CONV_32_32(efsctuf);
9170GEN_SPEFPUOP_CONV_32_32(efsctsf);
9171GEN_SPEFPUOP_CONV_32_32(efsctuiz);
9172GEN_SPEFPUOP_CONV_32_32(efsctsiz);
9173GEN_SPEFPUOP_CONV_32_64(efscfd);
9174
0487d6a8 9175/* Comparison */
1c97856d
AJ
9176GEN_SPEFPUOP_COMP_32(efscmpgt);
9177GEN_SPEFPUOP_COMP_32(efscmplt);
9178GEN_SPEFPUOP_COMP_32(efscmpeq);
9179GEN_SPEFPUOP_COMP_32(efststgt);
9180GEN_SPEFPUOP_COMP_32(efststlt);
9181GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
9182
9183/* Opcodes definitions */
70560da7
FC
9184GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9185GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
9186GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9187GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
9188GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9189GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
9190GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9191GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9192GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9193GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
9194GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9195GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
9196GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
9197GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
9198
9199/* Double precision floating-point operations */
9200/* Arithmetic */
1c97856d
AJ
9201GEN_SPEFPUOP_ARITH2_64_64(efdadd);
9202GEN_SPEFPUOP_ARITH2_64_64(efdsub);
9203GEN_SPEFPUOP_ARITH2_64_64(efdmul);
9204GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 9205static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
9206{
9207 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9208 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9209 return;
9210 }
9211#if defined(TARGET_PPC64)
6d5c34fa 9212 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
1c97856d 9213#else
6d5c34fa
MP
9214 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9215 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
9216#endif
9217}
636aa200 9218static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
9219{
9220 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9221 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9222 return;
9223 }
9224#if defined(TARGET_PPC64)
6d5c34fa 9225 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9226#else
6d5c34fa
MP
9227 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9228 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9229#endif
9230}
636aa200 9231static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
9232{
9233 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 9234 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
9235 return;
9236 }
9237#if defined(TARGET_PPC64)
6d5c34fa 9238 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 9239#else
6d5c34fa
MP
9240 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
9241 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
9242#endif
9243}
9244
0487d6a8 9245/* Conversion */
1c97856d
AJ
9246GEN_SPEFPUOP_CONV_64_32(efdcfui);
9247GEN_SPEFPUOP_CONV_64_32(efdcfsi);
9248GEN_SPEFPUOP_CONV_64_32(efdcfuf);
9249GEN_SPEFPUOP_CONV_64_32(efdcfsf);
9250GEN_SPEFPUOP_CONV_32_64(efdctui);
9251GEN_SPEFPUOP_CONV_32_64(efdctsi);
9252GEN_SPEFPUOP_CONV_32_64(efdctuf);
9253GEN_SPEFPUOP_CONV_32_64(efdctsf);
9254GEN_SPEFPUOP_CONV_32_64(efdctuiz);
9255GEN_SPEFPUOP_CONV_32_64(efdctsiz);
9256GEN_SPEFPUOP_CONV_64_32(efdcfs);
9257GEN_SPEFPUOP_CONV_64_64(efdcfuid);
9258GEN_SPEFPUOP_CONV_64_64(efdcfsid);
9259GEN_SPEFPUOP_CONV_64_64(efdctuidz);
9260GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 9261
0487d6a8 9262/* Comparison */
1c97856d
AJ
9263GEN_SPEFPUOP_COMP_64(efdcmpgt);
9264GEN_SPEFPUOP_COMP_64(efdcmplt);
9265GEN_SPEFPUOP_COMP_64(efdcmpeq);
9266GEN_SPEFPUOP_COMP_64(efdtstgt);
9267GEN_SPEFPUOP_COMP_64(efdtstlt);
9268GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
9269
9270/* Opcodes definitions */
70560da7
FC
9271GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9272GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9273GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
9274GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9275GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
9276GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9277GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9278GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
9279GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9280GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9281GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9282GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
9283GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9284GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
9285GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
9286GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 9287
c227f099 9288static opcode_t opcodes[] = {
5c55ff99
BS
9289GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
9290GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
9291GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
9292GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
9293GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
fcfda20f 9294GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9295GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
9296GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9297GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9298GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9299GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9300GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
9301GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
9302GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
9303GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
9304GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9305#if defined(TARGET_PPC64)
9306GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
9307#endif
9308GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
9309GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
9310GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9311GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9312GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9313GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
9314GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
9315GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
9316GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9317GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9318GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9319GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9320GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 9321GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
725bcec2 9322GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99 9323#if defined(TARGET_PPC64)
eaabeef2 9324GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99 9325GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
725bcec2 9326GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9327#endif
9328GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9329GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9330GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9331GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
9332GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
9333GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
9334GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
9335#if defined(TARGET_PPC64)
9336GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
9337GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
9338GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
9339GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
9340GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
9341#endif
9342GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
9343GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9344GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
9345GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
9346GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
bf45a2e6 9347GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT),
5c55ff99 9348GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
bf45a2e6
AJ
9349GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT),
9350GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT),
f0332888 9351GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9352GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
9353GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
9354GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
9355GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
7d08d856
AJ
9356GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT),
9357GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT),
5c55ff99
BS
9358#if defined(TARGET_PPC64)
9359GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
9360GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
9361GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
9362#endif
9363GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9364GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
9365GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
9366GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
9367GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
9368GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
9369GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
9370GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
f844c817 9371GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
5c55ff99
BS
9372GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
9373#if defined(TARGET_PPC64)
f844c817 9374GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
5c55ff99
BS
9375GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
9376#endif
9377GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
9378GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
9379GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9380GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9381GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
9382GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
9383GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
9384GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
9385#if defined(TARGET_PPC64)
9386GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
9387GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
9388#endif
9389GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
9390GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
9391GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
9392#if defined(TARGET_PPC64)
9393GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
9394GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
9395#endif
9396GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
9397GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
9398GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
9399GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
9400GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
9401GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
9402#if defined(TARGET_PPC64)
9403GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
9404#endif
9405GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
9406GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
9407GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
9408GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
9409GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
9410GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE),
9411GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE),
8e33944f 9412GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
9413GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
9414GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
9415GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
9416GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
9417GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
9418GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
9419GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
9420GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
9421GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
9422#if defined(TARGET_PPC64)
9423GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
9424GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9425 PPC_SEGMENT_64B),
9426GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
9427GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9428 PPC_SEGMENT_64B),
efdef95f
DG
9429GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
9430GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
9431GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
9432#endif
9433GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
9434GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
9435GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
9436GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
9437#if defined(TARGET_PPC64)
9438GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
9439GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
9440#endif
9441GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
9442GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
9443GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
9444GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
9445GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
9446GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
9447GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
9448GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
9449GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
9450GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
9451GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
9452GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9453GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
9454GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
9455GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
9456GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
9457GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
9458GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
9459GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
9460GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
9461GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
9462GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
9463GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
9464GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
9465GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
9466GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
9467GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
9468GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
9469GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
9470GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
9471GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
9472GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
9473GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
9474GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
9475GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
9476GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
9477GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
9478GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
9479GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
9480GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
9481GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
9482GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
9483GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
9484GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
9485GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
9486GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
9487GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
9488GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
9489GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
9490GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9491GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9492GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
9493GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
9494GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9495GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
9496GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
9497GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
9498GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
9499GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
9500GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
9501GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
9502GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
9503GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
9504GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
9505GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
9506GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
9507GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
9508GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
9509GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
9510GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
9511GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 9512GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
9513GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
9514GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
9515GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
9516GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
9517GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
9518GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
9519GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
9520GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
9521GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
9522 PPC_NONE, PPC2_BOOKE206),
9523GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
9524 PPC_NONE, PPC2_BOOKE206),
9525GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
9526 PPC_NONE, PPC2_BOOKE206),
9527GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
9528 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
9529GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
9530 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
9531GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
9532 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
9533GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
9534 PPC_NONE, PPC2_PRCNTL),
5c55ff99 9535GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 9536GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 9537GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
9538GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
9539 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 9540GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
9541GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
9542 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
9543GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
9544GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
9545GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
9546GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
9547GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC),
9548GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
9549GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
9550GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
9551GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
9552GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
9553
9554#undef GEN_INT_ARITH_ADD
9555#undef GEN_INT_ARITH_ADD_CONST
9556#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
9557GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
9558#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
9559 add_ca, compute_ca, compute_ov) \
9560GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
9561GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
9562GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
9563GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
9564GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
9565GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
9566GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
9567GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
9568GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
9569GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
9570GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
9571
9572#undef GEN_INT_ARITH_DIVW
9573#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
9574GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
9575GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
9576GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
9577GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
9578GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
9579
9580#if defined(TARGET_PPC64)
9581#undef GEN_INT_ARITH_DIVD
9582#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
9583GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9584GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
9585GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
9586GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
9587GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
9588
9589#undef GEN_INT_ARITH_MUL_HELPER
9590#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
9591GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9592GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
9593GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
9594GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
9595#endif
9596
9597#undef GEN_INT_ARITH_SUBF
9598#undef GEN_INT_ARITH_SUBF_CONST
9599#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
9600GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
9601#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
9602 add_ca, compute_ca, compute_ov) \
9603GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
9604GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
9605GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
9606GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
9607GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
9608GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
9609GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
9610GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
9611GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
9612GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
9613GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
9614
9615#undef GEN_LOGICAL1
9616#undef GEN_LOGICAL2
9617#define GEN_LOGICAL2(name, tcg_op, opc, type) \
9618GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
9619#define GEN_LOGICAL1(name, tcg_op, opc, type) \
9620GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
9621GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
9622GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
9623GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
9624GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
9625GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
9626GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
9627GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
9628GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
9629#if defined(TARGET_PPC64)
9630GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
9631#endif
9632
9633#if defined(TARGET_PPC64)
9634#undef GEN_PPC64_R2
9635#undef GEN_PPC64_R4
9636#define GEN_PPC64_R2(name, opc1, opc2) \
9637GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9638GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9639 PPC_64B)
9640#define GEN_PPC64_R4(name, opc1, opc2) \
9641GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9642GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
9643 PPC_64B), \
9644GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9645 PPC_64B), \
9646GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
9647 PPC_64B)
9648GEN_PPC64_R4(rldicl, 0x1E, 0x00),
9649GEN_PPC64_R4(rldicr, 0x1E, 0x02),
9650GEN_PPC64_R4(rldic, 0x1E, 0x04),
9651GEN_PPC64_R2(rldcl, 0x1E, 0x08),
9652GEN_PPC64_R2(rldcr, 0x1E, 0x09),
9653GEN_PPC64_R4(rldimi, 0x1E, 0x06),
9654#endif
9655
9656#undef _GEN_FLOAT_ACB
9657#undef GEN_FLOAT_ACB
9658#undef _GEN_FLOAT_AB
9659#undef GEN_FLOAT_AB
9660#undef _GEN_FLOAT_AC
9661#undef GEN_FLOAT_AC
9662#undef GEN_FLOAT_B
9663#undef GEN_FLOAT_BS
9664#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
9665GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
9666#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
9667_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
9668_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
9669#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9670GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9671#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
9672_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9673_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9674#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9675GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9676#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
9677_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9678_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9679#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
9680GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
9681#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
9682GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
9683
9684GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
9685GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
9686GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
9687GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
9688GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
9689GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
9690_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
9691GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
9692GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
9693GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
9694GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
9695GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
9696GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
9697GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
9698GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
9699#if defined(TARGET_PPC64)
9700GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
9701GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
9702GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
9703#endif
9704GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
9705GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
9706GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
9707GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
5c55ff99
BS
9708
9709#undef GEN_LD
9710#undef GEN_LDU
9711#undef GEN_LDUX
cd6e9320 9712#undef GEN_LDX_E
5c55ff99
BS
9713#undef GEN_LDS
9714#define GEN_LD(name, ldop, opc, type) \
9715GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9716#define GEN_LDU(name, ldop, opc, type) \
9717GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9718#define GEN_LDUX(name, ldop, opc2, opc3, type) \
9719GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
9720#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
9721GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
9722#define GEN_LDS(name, ldop, op, type) \
9723GEN_LD(name, ldop, op | 0x20, type) \
9724GEN_LDU(name, ldop, op | 0x21, type) \
9725GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
9726GEN_LDX(name, ldop, 0x17, op | 0x00, type)
9727
9728GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
9729GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
9730GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
9731GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
9732#if defined(TARGET_PPC64)
9733GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
9734GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
9735GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
9736GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 9737GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
9738#endif
9739GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
9740GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
9741
9742#undef GEN_ST
9743#undef GEN_STU
9744#undef GEN_STUX
cd6e9320 9745#undef GEN_STX_E
5c55ff99
BS
9746#undef GEN_STS
9747#define GEN_ST(name, stop, opc, type) \
9748GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9749#define GEN_STU(name, stop, opc, type) \
9750GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
9751#define GEN_STUX(name, stop, opc2, opc3, type) \
9752GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
9753#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
9754GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
9755#define GEN_STS(name, stop, op, type) \
9756GEN_ST(name, stop, op | 0x20, type) \
9757GEN_STU(name, stop, op | 0x21, type) \
9758GEN_STUX(name, stop, 0x17, op | 0x01, type) \
9759GEN_STX(name, stop, 0x17, op | 0x00, type)
9760
9761GEN_STS(stb, st8, 0x06, PPC_INTEGER)
9762GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
9763GEN_STS(stw, st32, 0x04, PPC_INTEGER)
9764#if defined(TARGET_PPC64)
9765GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
9766GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 9767GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
9768#endif
9769GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
9770GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
9771
9772#undef GEN_LDF
9773#undef GEN_LDUF
9774#undef GEN_LDUXF
9775#undef GEN_LDXF
9776#undef GEN_LDFS
9777#define GEN_LDF(name, ldop, opc, type) \
9778GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9779#define GEN_LDUF(name, ldop, opc, type) \
9780GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9781#define GEN_LDUXF(name, ldop, opc, type) \
9782GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9783#define GEN_LDXF(name, ldop, opc2, opc3, type) \
9784GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9785#define GEN_LDFS(name, ldop, op, type) \
9786GEN_LDF(name, ldop, op | 0x20, type) \
9787GEN_LDUF(name, ldop, op | 0x21, type) \
9788GEN_LDUXF(name, ldop, op | 0x01, type) \
9789GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
9790
9791GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
9792GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
199f830d 9793GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205),
05050ee8
AJ
9794GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
9795GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9796
9797#undef GEN_STF
9798#undef GEN_STUF
9799#undef GEN_STUXF
9800#undef GEN_STXF
9801#undef GEN_STFS
9802#define GEN_STF(name, stop, opc, type) \
9803GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9804#define GEN_STUF(name, stop, opc, type) \
9805GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9806#define GEN_STUXF(name, stop, opc, type) \
9807GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9808#define GEN_STXF(name, stop, opc2, opc3, type) \
9809GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9810#define GEN_STFS(name, stop, op, type) \
9811GEN_STF(name, stop, op | 0x20, type) \
9812GEN_STUF(name, stop, op | 0x21, type) \
9813GEN_STUXF(name, stop, op | 0x01, type) \
9814GEN_STXF(name, stop, 0x17, op | 0x00, type)
9815
9816GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
9817GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
9818GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
44bc0c4d
AJ
9819GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205),
9820GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205),
5c55ff99
BS
9821
9822#undef GEN_CRLOGIC
9823#define GEN_CRLOGIC(name, tcg_op, opc) \
9824GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
9825GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
9826GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
9827GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
9828GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
9829GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
9830GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
9831GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
9832GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
9833
9834#undef GEN_MAC_HANDLER
9835#define GEN_MAC_HANDLER(name, opc2, opc3) \
9836GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
9837GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
9838GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
9839GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
9840GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
9841GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
9842GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
9843GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
9844GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
9845GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
9846GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
9847GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
9848GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
9849GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
9850GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
9851GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
9852GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
9853GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
9854GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
9855GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
9856GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
9857GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
9858GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
9859GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
9860GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
9861GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
9862GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
9863GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
9864GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
9865GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
9866GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
9867GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
9868GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
9869GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
9870GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
9871GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
9872GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
9873GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
9874GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
9875GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
9876GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
9877GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
9878GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
9879
9880#undef GEN_VR_LDX
9881#undef GEN_VR_STX
9882#undef GEN_VR_LVE
9883#undef GEN_VR_STVE
9884#define GEN_VR_LDX(name, opc2, opc3) \
9885GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9886#define GEN_VR_STX(name, opc2, opc3) \
9887GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9888#define GEN_VR_LVE(name, opc2, opc3) \
9889 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9890#define GEN_VR_STVE(name, opc2, opc3) \
9891 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9892GEN_VR_LDX(lvx, 0x07, 0x03),
9893GEN_VR_LDX(lvxl, 0x07, 0x0B),
9894GEN_VR_LVE(bx, 0x07, 0x00),
9895GEN_VR_LVE(hx, 0x07, 0x01),
9896GEN_VR_LVE(wx, 0x07, 0x02),
9897GEN_VR_STX(svx, 0x07, 0x07),
9898GEN_VR_STX(svxl, 0x07, 0x0F),
9899GEN_VR_STVE(bx, 0x07, 0x04),
9900GEN_VR_STVE(hx, 0x07, 0x05),
9901GEN_VR_STVE(wx, 0x07, 0x06),
9902
9903#undef GEN_VX_LOGICAL
9904#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9905GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9906GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
9907GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
9908GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
9909GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
9910GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
9911
9912#undef GEN_VXFORM
9913#define GEN_VXFORM(name, opc2, opc3) \
9914GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9915GEN_VXFORM(vaddubm, 0, 0),
9916GEN_VXFORM(vadduhm, 0, 1),
9917GEN_VXFORM(vadduwm, 0, 2),
9918GEN_VXFORM(vsububm, 0, 16),
9919GEN_VXFORM(vsubuhm, 0, 17),
9920GEN_VXFORM(vsubuwm, 0, 18),
9921GEN_VXFORM(vmaxub, 1, 0),
9922GEN_VXFORM(vmaxuh, 1, 1),
9923GEN_VXFORM(vmaxuw, 1, 2),
9924GEN_VXFORM(vmaxsb, 1, 4),
9925GEN_VXFORM(vmaxsh, 1, 5),
9926GEN_VXFORM(vmaxsw, 1, 6),
9927GEN_VXFORM(vminub, 1, 8),
9928GEN_VXFORM(vminuh, 1, 9),
9929GEN_VXFORM(vminuw, 1, 10),
9930GEN_VXFORM(vminsb, 1, 12),
9931GEN_VXFORM(vminsh, 1, 13),
9932GEN_VXFORM(vminsw, 1, 14),
9933GEN_VXFORM(vavgub, 1, 16),
9934GEN_VXFORM(vavguh, 1, 17),
9935GEN_VXFORM(vavguw, 1, 18),
9936GEN_VXFORM(vavgsb, 1, 20),
9937GEN_VXFORM(vavgsh, 1, 21),
9938GEN_VXFORM(vavgsw, 1, 22),
9939GEN_VXFORM(vmrghb, 6, 0),
9940GEN_VXFORM(vmrghh, 6, 1),
9941GEN_VXFORM(vmrghw, 6, 2),
9942GEN_VXFORM(vmrglb, 6, 4),
9943GEN_VXFORM(vmrglh, 6, 5),
9944GEN_VXFORM(vmrglw, 6, 6),
9945GEN_VXFORM(vmuloub, 4, 0),
9946GEN_VXFORM(vmulouh, 4, 1),
9947GEN_VXFORM(vmulosb, 4, 4),
9948GEN_VXFORM(vmulosh, 4, 5),
9949GEN_VXFORM(vmuleub, 4, 8),
9950GEN_VXFORM(vmuleuh, 4, 9),
9951GEN_VXFORM(vmulesb, 4, 12),
9952GEN_VXFORM(vmulesh, 4, 13),
9953GEN_VXFORM(vslb, 2, 4),
9954GEN_VXFORM(vslh, 2, 5),
9955GEN_VXFORM(vslw, 2, 6),
9956GEN_VXFORM(vsrb, 2, 8),
9957GEN_VXFORM(vsrh, 2, 9),
9958GEN_VXFORM(vsrw, 2, 10),
9959GEN_VXFORM(vsrab, 2, 12),
9960GEN_VXFORM(vsrah, 2, 13),
9961GEN_VXFORM(vsraw, 2, 14),
9962GEN_VXFORM(vslo, 6, 16),
9963GEN_VXFORM(vsro, 6, 17),
9964GEN_VXFORM(vaddcuw, 0, 6),
9965GEN_VXFORM(vsubcuw, 0, 22),
9966GEN_VXFORM(vaddubs, 0, 8),
9967GEN_VXFORM(vadduhs, 0, 9),
9968GEN_VXFORM(vadduws, 0, 10),
9969GEN_VXFORM(vaddsbs, 0, 12),
9970GEN_VXFORM(vaddshs, 0, 13),
9971GEN_VXFORM(vaddsws, 0, 14),
9972GEN_VXFORM(vsububs, 0, 24),
9973GEN_VXFORM(vsubuhs, 0, 25),
9974GEN_VXFORM(vsubuws, 0, 26),
9975GEN_VXFORM(vsubsbs, 0, 28),
9976GEN_VXFORM(vsubshs, 0, 29),
9977GEN_VXFORM(vsubsws, 0, 30),
9978GEN_VXFORM(vrlb, 2, 0),
9979GEN_VXFORM(vrlh, 2, 1),
9980GEN_VXFORM(vrlw, 2, 2),
9981GEN_VXFORM(vsl, 2, 7),
9982GEN_VXFORM(vsr, 2, 11),
9983GEN_VXFORM(vpkuhum, 7, 0),
9984GEN_VXFORM(vpkuwum, 7, 1),
9985GEN_VXFORM(vpkuhus, 7, 2),
9986GEN_VXFORM(vpkuwus, 7, 3),
9987GEN_VXFORM(vpkshus, 7, 4),
9988GEN_VXFORM(vpkswus, 7, 5),
9989GEN_VXFORM(vpkshss, 7, 6),
9990GEN_VXFORM(vpkswss, 7, 7),
9991GEN_VXFORM(vpkpx, 7, 12),
9992GEN_VXFORM(vsum4ubs, 4, 24),
9993GEN_VXFORM(vsum4sbs, 4, 28),
9994GEN_VXFORM(vsum4shs, 4, 25),
9995GEN_VXFORM(vsum2sws, 4, 26),
9996GEN_VXFORM(vsumsws, 4, 30),
9997GEN_VXFORM(vaddfp, 5, 0),
9998GEN_VXFORM(vsubfp, 5, 1),
9999GEN_VXFORM(vmaxfp, 5, 16),
10000GEN_VXFORM(vminfp, 5, 17),
10001
10002#undef GEN_VXRFORM1
10003#undef GEN_VXRFORM
10004#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10005 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10006#define GEN_VXRFORM(name, opc2, opc3) \
10007 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10008 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10009GEN_VXRFORM(vcmpequb, 3, 0)
10010GEN_VXRFORM(vcmpequh, 3, 1)
10011GEN_VXRFORM(vcmpequw, 3, 2)
10012GEN_VXRFORM(vcmpgtsb, 3, 12)
10013GEN_VXRFORM(vcmpgtsh, 3, 13)
10014GEN_VXRFORM(vcmpgtsw, 3, 14)
10015GEN_VXRFORM(vcmpgtub, 3, 8)
10016GEN_VXRFORM(vcmpgtuh, 3, 9)
10017GEN_VXRFORM(vcmpgtuw, 3, 10)
10018GEN_VXRFORM(vcmpeqfp, 3, 3)
10019GEN_VXRFORM(vcmpgefp, 3, 7)
10020GEN_VXRFORM(vcmpgtfp, 3, 11)
10021GEN_VXRFORM(vcmpbfp, 3, 15)
10022
10023#undef GEN_VXFORM_SIMM
10024#define GEN_VXFORM_SIMM(name, opc2, opc3) \
10025 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10026GEN_VXFORM_SIMM(vspltisb, 6, 12),
10027GEN_VXFORM_SIMM(vspltish, 6, 13),
10028GEN_VXFORM_SIMM(vspltisw, 6, 14),
10029
10030#undef GEN_VXFORM_NOA
10031#define GEN_VXFORM_NOA(name, opc2, opc3) \
10032 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10033GEN_VXFORM_NOA(vupkhsb, 7, 8),
10034GEN_VXFORM_NOA(vupkhsh, 7, 9),
10035GEN_VXFORM_NOA(vupklsb, 7, 10),
10036GEN_VXFORM_NOA(vupklsh, 7, 11),
10037GEN_VXFORM_NOA(vupkhpx, 7, 13),
10038GEN_VXFORM_NOA(vupklpx, 7, 15),
10039GEN_VXFORM_NOA(vrefp, 5, 4),
10040GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 10041GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99
BS
10042GEN_VXFORM_NOA(vlogefp, 5, 7),
10043GEN_VXFORM_NOA(vrfim, 5, 8),
10044GEN_VXFORM_NOA(vrfin, 5, 9),
10045GEN_VXFORM_NOA(vrfip, 5, 10),
10046GEN_VXFORM_NOA(vrfiz, 5, 11),
10047
10048#undef GEN_VXFORM_UIMM
10049#define GEN_VXFORM_UIMM(name, opc2, opc3) \
10050 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10051GEN_VXFORM_UIMM(vspltb, 6, 8),
10052GEN_VXFORM_UIMM(vsplth, 6, 9),
10053GEN_VXFORM_UIMM(vspltw, 6, 10),
10054GEN_VXFORM_UIMM(vcfux, 5, 12),
10055GEN_VXFORM_UIMM(vcfsx, 5, 13),
10056GEN_VXFORM_UIMM(vctuxs, 5, 14),
10057GEN_VXFORM_UIMM(vctsxs, 5, 15),
10058
10059#undef GEN_VAFORM_PAIRED
10060#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10061 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10062GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
10063GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
10064GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
10065GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
10066GEN_VAFORM_PAIRED(vsel, vperm, 21),
10067GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
10068
fa1832d7 10069GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX),
cac7f0ba
TM
10070GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207),
10071GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207),
10072GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207),
304af367 10073GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX),
ca03b467 10074GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX),
897e61d1 10075GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX),
304af367 10076
9231ba9e 10077GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX),
e16a626b
TM
10078GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207),
10079GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207),
fbed2478 10080GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX),
86e61ce3 10081GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX),
fbed2478 10082
df020ce0
TM
10083#undef GEN_XX2FORM
10084#define GEN_XX2FORM(name, opc2, opc3, fl2) \
10085GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10086GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10087
10088#undef GEN_XX3FORM
10089#define GEN_XX3FORM(name, opc2, opc3, fl2) \
10090GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10091GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10092GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10093GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10094
354a6dec
TM
10095#undef GEN_XX3_RC_FORM
10096#define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10097GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10098GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10099GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10100GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10101GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10102GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10103GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10104GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10105
cd73f2c9
TM
10106#undef GEN_XX3FORM_DM
10107#define GEN_XX3FORM_DM(name, opc2, opc3) \
10108GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10109GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10110GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10111GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10112GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10113GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10114GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10115GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10116GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10117GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10118GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10119GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10120GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10121GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10122GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10123GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10124
df020ce0
TM
10125GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX),
10126GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX),
10127GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX),
10128GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX),
10129
be574920
TM
10130GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX),
10131GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX),
10132GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX),
10133GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX),
10134GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX),
10135GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX),
10136GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX),
10137GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX),
79ca8a6a 10138
ee6e02c0
TM
10139GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX),
10140GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX),
5e591d88 10141GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX),
4b98eeef 10142GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX),
2009227f 10143GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX),
d32404fe 10144GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX),
d3f9df8f 10145GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX),
bc80838f 10146GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX),
5cb151ac 10147GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX),
595c6eef
TM
10148GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX),
10149GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX),
10150GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX),
10151GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX),
10152GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX),
10153GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX),
10154GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX),
10155GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX),
4f17e9c7
TM
10156GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX),
10157GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX),
959e9c9d
TM
10158GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX),
10159GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX),
ed8ac568
TM
10160GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX),
10161GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX),
5177d2ca
TM
10162GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX),
10163GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX),
10164GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX),
10165GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX),
10166GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX),
10167GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX),
88e33d08
TM
10168GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX),
10169GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX),
10170GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX),
10171GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX),
10172GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX),
ee6e02c0 10173
3fd0aadf
TM
10174GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207),
10175GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207),
ab9408a2 10176GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207),
b24d0b47 10177GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207),
2c0c52ae 10178GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207),
cea4e574 10179GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207),
3fd0aadf 10180
ee6e02c0
TM
10181GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX),
10182GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX),
5e591d88 10183GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX),
4b98eeef 10184GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX),
2009227f 10185GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX),
d32404fe 10186GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX),
d3f9df8f 10187GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX),
bc80838f 10188GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX),
5cb151ac 10189GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX),
595c6eef
TM
10190GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX),
10191GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX),
10192GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX),
10193GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX),
10194GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX),
10195GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX),
10196GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX),
10197GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX),
959e9c9d
TM
10198GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX),
10199GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX),
354a6dec
TM
10200GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX),
10201GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX),
10202GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX),
ed8ac568 10203GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX),
5177d2ca
TM
10204GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX),
10205GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX),
10206GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX),
10207GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX),
10208GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX),
10209GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX),
10210GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX),
10211GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX),
88e33d08
TM
10212GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX),
10213GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX),
10214GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX),
10215GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX),
10216GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX),
ee6e02c0
TM
10217
10218GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX),
10219GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX),
5e591d88 10220GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX),
4b98eeef 10221GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX),
2009227f 10222GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX),
d32404fe 10223GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX),
d3f9df8f 10224GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX),
bc80838f 10225GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX),
5cb151ac 10226GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX),
595c6eef
TM
10227GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX),
10228GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX),
10229GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX),
10230GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX),
10231GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX),
10232GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX),
10233GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX),
10234GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX),
959e9c9d
TM
10235GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX),
10236GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX),
354a6dec
TM
10237GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX),
10238GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX),
10239GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX),
ed8ac568 10240GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX),
5177d2ca
TM
10241GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX),
10242GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX),
10243GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX),
10244GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX),
10245GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX),
10246GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX),
10247GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX),
10248GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX),
88e33d08
TM
10249GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX),
10250GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX),
10251GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX),
10252GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX),
10253GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX),
ee6e02c0 10254
79ca8a6a
TM
10255#undef VSX_LOGICAL
10256#define VSX_LOGICAL(name, opc2, opc3, fl2) \
10257GEN_XX3FORM(name, opc2, opc3, fl2)
10258
10259VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX),
10260VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX),
10261VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX),
10262VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX),
10263VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX),
ce577d2e
TM
10264GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX),
10265GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX),
76c15fe0 10266GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX),
acc42968 10267GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00),
79ca8a6a 10268
551e3ef7
TM
10269#define GEN_XXSEL_ROW(opc3) \
10270GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10271GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10272GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10273GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10274GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10275GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10276GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10277GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10278
10279GEN_XXSEL_ROW(0x00)
10280GEN_XXSEL_ROW(0x01)
10281GEN_XXSEL_ROW(0x02)
10282GEN_XXSEL_ROW(0x03)
10283GEN_XXSEL_ROW(0x04)
10284GEN_XXSEL_ROW(0x05)
10285GEN_XXSEL_ROW(0x06)
10286GEN_XXSEL_ROW(0x07)
10287GEN_XXSEL_ROW(0x08)
10288GEN_XXSEL_ROW(0x09)
10289GEN_XXSEL_ROW(0x0A)
10290GEN_XXSEL_ROW(0x0B)
10291GEN_XXSEL_ROW(0x0C)
10292GEN_XXSEL_ROW(0x0D)
10293GEN_XXSEL_ROW(0x0E)
10294GEN_XXSEL_ROW(0x0F)
10295GEN_XXSEL_ROW(0x10)
10296GEN_XXSEL_ROW(0x11)
10297GEN_XXSEL_ROW(0x12)
10298GEN_XXSEL_ROW(0x13)
10299GEN_XXSEL_ROW(0x14)
10300GEN_XXSEL_ROW(0x15)
10301GEN_XXSEL_ROW(0x16)
10302GEN_XXSEL_ROW(0x17)
10303GEN_XXSEL_ROW(0x18)
10304GEN_XXSEL_ROW(0x19)
10305GEN_XXSEL_ROW(0x1A)
10306GEN_XXSEL_ROW(0x1B)
10307GEN_XXSEL_ROW(0x1C)
10308GEN_XXSEL_ROW(0x1D)
10309GEN_XXSEL_ROW(0x1E)
10310GEN_XXSEL_ROW(0x1F)
10311
cd73f2c9
TM
10312GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01),
10313
5c55ff99 10314#undef GEN_SPE
70560da7
FC
10315#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
10316 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
10317GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10318GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10319GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10320GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10321GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10322GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10323GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
10324GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
10325GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
10326GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
10327GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10328GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10329GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10330GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
10331GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
10332GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
10333GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
10334GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10335GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10336GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10337GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10338GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
10339GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
10340GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
10341GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10342GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
10343GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
10344GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
10345GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
10346
10347GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10348GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
10349GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
10350GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10351GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10352GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10353GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10354GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10355GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10356GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10357GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10358GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10359GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10360GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10361
10362GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10363GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
10364GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
10365GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
10366GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10367GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
10368GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10369GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10370GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10371GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
10372GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10373GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10374GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
10375GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
10376
10377GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
10378GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10379GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
10380GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10381GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
10382GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10383GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
10384GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
10385GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10386GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10387GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10388GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
10389GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10390GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
10391GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
10392GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
10393
10394#undef GEN_SPEOP_LDST
10395#define GEN_SPEOP_LDST(name, opc2, sh) \
10396GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
10397GEN_SPEOP_LDST(evldd, 0x00, 3),
10398GEN_SPEOP_LDST(evldw, 0x01, 3),
10399GEN_SPEOP_LDST(evldh, 0x02, 3),
10400GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
10401GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
10402GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
10403GEN_SPEOP_LDST(evlwhe, 0x08, 2),
10404GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
10405GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
10406GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
10407GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
10408
10409GEN_SPEOP_LDST(evstdd, 0x10, 3),
10410GEN_SPEOP_LDST(evstdw, 0x11, 3),
10411GEN_SPEOP_LDST(evstdh, 0x12, 3),
10412GEN_SPEOP_LDST(evstwhe, 0x18, 2),
10413GEN_SPEOP_LDST(evstwho, 0x1A, 2),
10414GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
10415GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
10416};
10417
0411a972 10418#include "helper_regs.h"
a1389542 10419#include "translate_init.c"
79aceca5 10420
9a64fbe4 10421/*****************************************************************************/
3fc6c082 10422/* Misc PowerPC helpers */
878096ee
AF
10423void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
10424 int flags)
79aceca5 10425{
3fc6c082
FB
10426#define RGPL 4
10427#define RFPL 4
3fc6c082 10428
878096ee
AF
10429 PowerPCCPU *cpu = POWERPC_CPU(cs);
10430 CPUPPCState *env = &cpu->env;
79aceca5
FB
10431 int i;
10432
90e189ec 10433 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9a78eead 10434 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
da91a00f 10435 env->nip, env->lr, env->ctr, cpu_read_xer(env));
90e189ec
BS
10436 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
10437 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
10438 env->hflags, env->mmu_idx);
d9bce9d9 10439#if !defined(NO_TIMER_DUMP)
9a78eead 10440 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 10441#if !defined(CONFIG_USER_ONLY)
9a78eead 10442 " DECR %08" PRIu32
76a66253
JM
10443#endif
10444 "\n",
077fc206 10445 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
10446#if !defined(CONFIG_USER_ONLY)
10447 , cpu_ppc_load_decr(env)
10448#endif
10449 );
077fc206 10450#endif
76a66253 10451 for (i = 0; i < 32; i++) {
3fc6c082
FB
10452 if ((i & (RGPL - 1)) == 0)
10453 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 10454 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 10455 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 10456 cpu_fprintf(f, "\n");
76a66253 10457 }
3fc6c082 10458 cpu_fprintf(f, "CR ");
76a66253 10459 for (i = 0; i < 8; i++)
7fe48483
FB
10460 cpu_fprintf(f, "%01x", env->crf[i]);
10461 cpu_fprintf(f, " [");
76a66253
JM
10462 for (i = 0; i < 8; i++) {
10463 char a = '-';
10464 if (env->crf[i] & 0x08)
10465 a = 'L';
10466 else if (env->crf[i] & 0x04)
10467 a = 'G';
10468 else if (env->crf[i] & 0x02)
10469 a = 'E';
7fe48483 10470 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 10471 }
90e189ec
BS
10472 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
10473 env->reserve_addr);
3fc6c082
FB
10474 for (i = 0; i < 32; i++) {
10475 if ((i & (RFPL - 1)) == 0)
10476 cpu_fprintf(f, "FPR%02d", i);
26a76461 10477 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 10478 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 10479 cpu_fprintf(f, "\n");
79aceca5 10480 }
30304420 10481 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 10482#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
10483 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
10484 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
10485 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
10486 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
10487
10488 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
10489 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
10490 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
10491 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
10492
10493 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
10494 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
10495 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
10496 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
10497
10498 if (env->excp_model == POWERPC_EXCP_BOOKE) {
10499 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
10500 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
10501 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
10502 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
10503
10504 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
10505 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
10506 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
10507 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
10508
10509 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
10510 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
10511 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
10512 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
10513
10514 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
10515 " EPR " TARGET_FMT_lx "\n",
10516 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
10517 env->spr[SPR_BOOKE_EPR]);
10518
10519 /* FSL-specific */
10520 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
10521 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
10522 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
10523 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
10524
10525 /*
10526 * IVORs are left out as they are large and do not change often --
10527 * they can be read with "p $ivor0", "p $ivor1", etc.
10528 */
10529 }
10530
697ab892
DG
10531#if defined(TARGET_PPC64)
10532 if (env->flags & POWERPC_FLAG_CFAR) {
10533 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
10534 }
10535#endif
10536
90dc8812
SW
10537 switch (env->mmu_model) {
10538 case POWERPC_MMU_32B:
10539 case POWERPC_MMU_601:
10540 case POWERPC_MMU_SOFT_6xx:
10541 case POWERPC_MMU_SOFT_74xx:
10542#if defined(TARGET_PPC64)
90dc8812 10543 case POWERPC_MMU_64B:
ca480de6
AB
10544 case POWERPC_MMU_2_06:
10545 case POWERPC_MMU_2_06a:
10546 case POWERPC_MMU_2_06d:
90dc8812 10547#endif
ca480de6
AB
10548 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx
10549 " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1],
10550 env->spr[SPR_DAR], env->spr[SPR_DSISR]);
90dc8812 10551 break;
01662f3e 10552 case POWERPC_MMU_BOOKE206:
90dc8812
SW
10553 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
10554 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
10555 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
10556 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
10557
10558 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
10559 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
10560 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
10561 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
10562
10563 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
10564 " TLB1CFG " TARGET_FMT_lx "\n",
10565 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
10566 env->spr[SPR_BOOKE_TLB1CFG]);
10567 break;
10568 default:
10569 break;
10570 }
f2e63a42 10571#endif
79aceca5 10572
3fc6c082
FB
10573#undef RGPL
10574#undef RFPL
79aceca5
FB
10575}
10576
878096ee
AF
10577void ppc_cpu_dump_statistics(CPUState *cs, FILE*f,
10578 fprintf_function cpu_fprintf, int flags)
76a66253
JM
10579{
10580#if defined(DO_PPC_STATISTICS)
878096ee 10581 PowerPCCPU *cpu = POWERPC_CPU(cs);
c227f099 10582 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
10583 int op1, op2, op3;
10584
878096ee 10585 t1 = cpu->env.opcodes;
76a66253
JM
10586 for (op1 = 0; op1 < 64; op1++) {
10587 handler = t1[op1];
10588 if (is_indirect_opcode(handler)) {
10589 t2 = ind_table(handler);
10590 for (op2 = 0; op2 < 32; op2++) {
10591 handler = t2[op2];
10592 if (is_indirect_opcode(handler)) {
10593 t3 = ind_table(handler);
10594 for (op3 = 0; op3 < 32; op3++) {
10595 handler = t3[op3];
10596 if (handler->count == 0)
10597 continue;
10598 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 10599 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
10600 op1, op2, op3, op1, (op3 << 5) | op2,
10601 handler->oname,
10602 handler->count, handler->count);
10603 }
10604 } else {
10605 if (handler->count == 0)
10606 continue;
10607 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 10608 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
10609 op1, op2, op1, op2, handler->oname,
10610 handler->count, handler->count);
10611 }
10612 }
10613 } else {
10614 if (handler->count == 0)
10615 continue;
0bfcd599
BS
10616 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
10617 " %" PRId64 "\n",
76a66253
JM
10618 op1, op1, handler->oname,
10619 handler->count, handler->count);
10620 }
10621 }
10622#endif
10623}
10624
9a64fbe4 10625/*****************************************************************************/
213fe1f5 10626static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,
636aa200 10627 TranslationBlock *tb,
213fe1f5 10628 bool search_pc)
79aceca5 10629{
ed2803da 10630 CPUState *cs = CPU(cpu);
213fe1f5 10631 CPUPPCState *env = &cpu->env;
9fddaa0c 10632 DisasContext ctx, *ctxp = &ctx;
c227f099 10633 opc_handler_t **table, *handler;
0fa85d43 10634 target_ulong pc_start;
79aceca5 10635 uint16_t *gen_opc_end;
a1d1bb31 10636 CPUBreakpoint *bp;
79aceca5 10637 int j, lj = -1;
2e70f6ef
PB
10638 int num_insns;
10639 int max_insns;
79aceca5
FB
10640
10641 pc_start = tb->pc;
92414b31 10642 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
046d6672 10643 ctx.nip = pc_start;
79aceca5 10644 ctx.tb = tb;
e1833e1f 10645 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 10646 ctx.spr_cb = env->spr_cb;
76db3ba4 10647 ctx.mem_idx = env->mmu_idx;
7d08d856
AJ
10648 ctx.insns_flags = env->insns_flags;
10649 ctx.insns_flags2 = env->insns_flags2;
76db3ba4
AJ
10650 ctx.access_type = -1;
10651 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
d9bce9d9 10652#if defined(TARGET_PPC64)
e42a61f1 10653 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 10654 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 10655#endif
3cc62370 10656 ctx.fpu_enabled = msr_fp;
a9d9eb8f 10657 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
10658 ctx.spe_enabled = msr_spe;
10659 else
10660 ctx.spe_enabled = 0;
a9d9eb8f
JM
10661 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
10662 ctx.altivec_enabled = msr_vr;
10663 else
10664 ctx.altivec_enabled = 0;
1f29871c
TM
10665 if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) {
10666 ctx.vsx_enabled = msr_vsx;
10667 } else {
10668 ctx.vsx_enabled = 0;
10669 }
d26bfc9a 10670 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 10671 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 10672 else
8cbcb4fa 10673 ctx.singlestep_enabled = 0;
d26bfc9a 10674 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa 10675 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
ed2803da 10676 if (unlikely(cs->singlestep_enabled)) {
8cbcb4fa 10677 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
ed2803da 10678 }
3fc6c082 10679#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
10680 /* Single step trace mode */
10681 msr_se = 1;
10682#endif
2e70f6ef
PB
10683 num_insns = 0;
10684 max_insns = tb->cflags & CF_COUNT_MASK;
10685 if (max_insns == 0)
10686 max_insns = CF_COUNT_MASK;
10687
806f352d 10688 gen_tb_start();
9a64fbe4 10689 /* Set env in case of segfault during code fetch */
efd7f486
EV
10690 while (ctx.exception == POWERPC_EXCP_NONE
10691 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
72cf2d4f
BS
10692 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
10693 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
a1d1bb31 10694 if (bp->pc == ctx.nip) {
e06fcd75 10695 gen_debug_exception(ctxp);
ea4e754f
FB
10696 break;
10697 }
10698 }
10699 }
76a66253 10700 if (unlikely(search_pc)) {
92414b31 10701 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
79aceca5
FB
10702 if (lj < j) {
10703 lj++;
10704 while (lj < j)
ab1103de 10705 tcg_ctx.gen_opc_instr_start[lj++] = 0;
79aceca5 10706 }
25983cad 10707 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
ab1103de 10708 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 10709 tcg_ctx.gen_opc_icount[lj] = num_insns;
79aceca5 10710 }
d12d51d5 10711 LOG_DISAS("----------------\n");
90e189ec 10712 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 10713 ctx.nip, ctx.mem_idx, (int)msr_ir);
2e70f6ef
PB
10714 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
10715 gen_io_start();
76db3ba4 10716 if (unlikely(ctx.le_mode)) {
2f5a189c 10717 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 10718 } else {
2f5a189c 10719 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 10720 }
d12d51d5 10721 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 10722 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 10723 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
fdefe51c 10724 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
731c54f8 10725 tcg_gen_debug_insn_start(ctx.nip);
fdefe51c 10726 }
046d6672 10727 ctx.nip += 4;
3fc6c082 10728 table = env->opcodes;
2e70f6ef 10729 num_insns++;
79aceca5
FB
10730 handler = table[opc1(ctx.opcode)];
10731 if (is_indirect_opcode(handler)) {
10732 table = ind_table(handler);
10733 handler = table[opc2(ctx.opcode)];
10734 if (is_indirect_opcode(handler)) {
10735 table = ind_table(handler);
10736 handler = table[opc3(ctx.opcode)];
10737 }
10738 }
10739 /* Is opcode *REALLY* valid ? */
76a66253 10740 if (unlikely(handler->handler == &gen_invalid)) {
93fcfe39
AL
10741 if (qemu_log_enabled()) {
10742 qemu_log("invalid/unsupported opcode: "
90e189ec
BS
10743 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
10744 opc1(ctx.opcode), opc2(ctx.opcode),
10745 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
4b3686fa 10746 }
76a66253 10747 } else {
70560da7
FC
10748 uint32_t inval;
10749
10750 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
10751 inval = handler->inval2;
10752 } else {
10753 inval = handler->inval1;
10754 }
10755
10756 if (unlikely((ctx.opcode & inval) != 0)) {
93fcfe39
AL
10757 if (qemu_log_enabled()) {
10758 qemu_log("invalid bits: %08x for opcode: "
90e189ec 10759 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
70560da7 10760 ctx.opcode & inval, opc1(ctx.opcode),
90e189ec
BS
10761 opc2(ctx.opcode), opc3(ctx.opcode),
10762 ctx.opcode, ctx.nip - 4);
76a66253 10763 }
e06fcd75 10764 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 10765 break;
79aceca5 10766 }
79aceca5 10767 }
4b3686fa 10768 (*(handler->handler))(&ctx);
76a66253
JM
10769#if defined(DO_PPC_STATISTICS)
10770 handler->count++;
10771#endif
9a64fbe4 10772 /* Check trace mode exceptions */
8cbcb4fa
AJ
10773 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
10774 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
10775 ctx.exception != POWERPC_SYSCALL &&
10776 ctx.exception != POWERPC_EXCP_TRAP &&
10777 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 10778 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 10779 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
ed2803da 10780 (cs->singlestep_enabled) ||
1b530a6d 10781 singlestep ||
2e70f6ef 10782 num_insns >= max_insns)) {
d26bfc9a
JM
10783 /* if we reach a page boundary or are single stepping, stop
10784 * generation
10785 */
8dd4983c 10786 break;
76a66253 10787 }
3fc6c082 10788 }
2e70f6ef
PB
10789 if (tb->cflags & CF_LAST_IO)
10790 gen_io_end();
e1833e1f 10791 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 10792 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 10793 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
ed2803da 10794 if (unlikely(cs->singlestep_enabled)) {
e06fcd75 10795 gen_debug_exception(ctxp);
8cbcb4fa 10796 }
76a66253 10797 /* Generate the return instruction */
57fec1fe 10798 tcg_gen_exit_tb(0);
9a64fbe4 10799 }
806f352d 10800 gen_tb_end(tb, num_insns);
efd7f486 10801 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
76a66253 10802 if (unlikely(search_pc)) {
92414b31 10803 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9a64fbe4
FB
10804 lj++;
10805 while (lj <= j)
ab1103de 10806 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9a64fbe4 10807 } else {
046d6672 10808 tb->size = ctx.nip - pc_start;
2e70f6ef 10809 tb->icount = num_insns;
9a64fbe4 10810 }
d9bce9d9 10811#if defined(DEBUG_DISAS)
8fec2b8c 10812 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 10813 int flags;
237c0af0 10814 flags = env->bfd_mach;
76db3ba4 10815 flags |= ctx.le_mode << 16;
93fcfe39 10816 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 10817 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
93fcfe39 10818 qemu_log("\n");
9fddaa0c 10819 }
79aceca5 10820#endif
79aceca5
FB
10821}
10822
1328c2bf 10823void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 10824{
213fe1f5 10825 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false);
79aceca5
FB
10826}
10827
1328c2bf 10828void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 10829{
213fe1f5 10830 gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true);
79aceca5 10831}
d2856f1a 10832
1328c2bf 10833void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
d2856f1a 10834{
25983cad 10835 env->nip = tcg_ctx.gen_opc_pc[pc_pos];
d2856f1a 10836}