]> git.proxmox.com Git - qemu.git/blame - target-ppc/translate.c
target-cris/helper.c: Update Coding Style
[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
AJ
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
54 + 8*5 /* CRF */];
f78fb44e
AJ
55static TCGv cpu_gpr[32];
56#if !defined(TARGET_PPC64)
57static TCGv cpu_gprh[32];
58#endif
a7812ae4
PB
59static TCGv_i64 cpu_fpr[32];
60static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
61static TCGv_i32 cpu_crf[8];
bd568f18 62static TCGv cpu_nip;
6527f6ea 63static TCGv cpu_msr;
cfdcd37a
AJ
64static TCGv cpu_ctr;
65static TCGv cpu_lr;
697ab892
DG
66#if defined(TARGET_PPC64)
67static TCGv cpu_cfar;
68#endif
da91a00f 69static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca;
cf360a32 70static TCGv cpu_reserve;
30304420 71static TCGv cpu_fpscr;
a7859e89 72static TCGv_i32 cpu_access_type;
f78fb44e 73
022c62cb 74#include "exec/gen-icount.h"
2e70f6ef
PB
75
76void ppc_translate_init(void)
77{
f78fb44e
AJ
78 int i;
79 char* p;
2dc766da 80 size_t cpu_reg_names_size;
b2437bf2 81 static int done_init = 0;
f78fb44e 82
2e70f6ef
PB
83 if (done_init)
84 return;
f78fb44e 85
a7812ae4 86 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
a7812ae4 87
f78fb44e 88 p = cpu_reg_names;
2dc766da 89 cpu_reg_names_size = sizeof(cpu_reg_names);
47e4661c
AJ
90
91 for (i = 0; i < 8; i++) {
2dc766da 92 snprintf(p, cpu_reg_names_size, "crf%d", i);
a7812ae4 93 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 94 offsetof(CPUPPCState, crf[i]), p);
47e4661c 95 p += 5;
2dc766da 96 cpu_reg_names_size -= 5;
47e4661c
AJ
97 }
98
f78fb44e 99 for (i = 0; i < 32; i++) {
2dc766da 100 snprintf(p, cpu_reg_names_size, "r%d", i);
a7812ae4 101 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
1328c2bf 102 offsetof(CPUPPCState, gpr[i]), p);
f78fb44e 103 p += (i < 10) ? 3 : 4;
2dc766da 104 cpu_reg_names_size -= (i < 10) ? 3 : 4;
f78fb44e 105#if !defined(TARGET_PPC64)
2dc766da 106 snprintf(p, cpu_reg_names_size, "r%dH", i);
a7812ae4 107 cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 108 offsetof(CPUPPCState, gprh[i]), p);
f78fb44e 109 p += (i < 10) ? 4 : 5;
2dc766da 110 cpu_reg_names_size -= (i < 10) ? 4 : 5;
f78fb44e 111#endif
1d542695 112
2dc766da 113 snprintf(p, cpu_reg_names_size, "fp%d", i);
a7812ae4 114 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 115 offsetof(CPUPPCState, fpr[i]), p);
ec1ac72d 116 p += (i < 10) ? 4 : 5;
2dc766da 117 cpu_reg_names_size -= (i < 10) ? 4 : 5;
a5e26afa 118
2dc766da 119 snprintf(p, cpu_reg_names_size, "avr%dH", i);
e2542fe2 120#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 121 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 122 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 123#else
a7812ae4 124 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 125 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 126#endif
1d542695 127 p += (i < 10) ? 6 : 7;
2dc766da 128 cpu_reg_names_size -= (i < 10) ? 6 : 7;
ec1ac72d 129
2dc766da 130 snprintf(p, cpu_reg_names_size, "avr%dL", i);
e2542fe2 131#ifdef HOST_WORDS_BIGENDIAN
fe1e5c53 132 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 133 offsetof(CPUPPCState, avr[i].u64[1]), p);
fe1e5c53 134#else
a7812ae4 135 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
1328c2bf 136 offsetof(CPUPPCState, avr[i].u64[0]), p);
fe1e5c53 137#endif
1d542695 138 p += (i < 10) ? 6 : 7;
2dc766da 139 cpu_reg_names_size -= (i < 10) ? 6 : 7;
f78fb44e 140 }
f10dc08e 141
a7812ae4 142 cpu_nip = tcg_global_mem_new(TCG_AREG0,
1328c2bf 143 offsetof(CPUPPCState, nip), "nip");
bd568f18 144
6527f6ea 145 cpu_msr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 146 offsetof(CPUPPCState, msr), "msr");
6527f6ea 147
a7812ae4 148 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 149 offsetof(CPUPPCState, ctr), "ctr");
cfdcd37a 150
a7812ae4 151 cpu_lr = tcg_global_mem_new(TCG_AREG0,
1328c2bf 152 offsetof(CPUPPCState, lr), "lr");
cfdcd37a 153
697ab892
DG
154#if defined(TARGET_PPC64)
155 cpu_cfar = tcg_global_mem_new(TCG_AREG0,
1328c2bf 156 offsetof(CPUPPCState, cfar), "cfar");
697ab892
DG
157#endif
158
a7812ae4 159 cpu_xer = tcg_global_mem_new(TCG_AREG0,
1328c2bf 160 offsetof(CPUPPCState, xer), "xer");
da91a00f
RH
161 cpu_so = tcg_global_mem_new(TCG_AREG0,
162 offsetof(CPUPPCState, so), "SO");
163 cpu_ov = tcg_global_mem_new(TCG_AREG0,
164 offsetof(CPUPPCState, ov), "OV");
165 cpu_ca = tcg_global_mem_new(TCG_AREG0,
166 offsetof(CPUPPCState, ca), "CA");
3d7b417e 167
cf360a32 168 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
1328c2bf 169 offsetof(CPUPPCState, reserve_addr),
18b21a2f 170 "reserve_addr");
cf360a32 171
30304420
DG
172 cpu_fpscr = tcg_global_mem_new(TCG_AREG0,
173 offsetof(CPUPPCState, fpscr), "fpscr");
e1571908 174
a7859e89 175 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
1328c2bf 176 offsetof(CPUPPCState, access_type), "access_type");
a7859e89 177
f10dc08e 178 /* register helpers */
a7812ae4 179#define GEN_HELPER 2
f10dc08e
AJ
180#include "helper.h"
181
2e70f6ef
PB
182 done_init = 1;
183}
184
79aceca5
FB
185/* internal defines */
186typedef struct DisasContext {
187 struct TranslationBlock *tb;
0fa85d43 188 target_ulong nip;
79aceca5 189 uint32_t opcode;
9a64fbe4 190 uint32_t exception;
3cc62370
FB
191 /* Routine used to access memory */
192 int mem_idx;
76db3ba4 193 int access_type;
3cc62370 194 /* Translation flags */
76db3ba4 195 int le_mode;
d9bce9d9
JM
196#if defined(TARGET_PPC64)
197 int sf_mode;
697ab892 198 int has_cfar;
9a64fbe4 199#endif
3cc62370 200 int fpu_enabled;
a9d9eb8f 201 int altivec_enabled;
0487d6a8 202 int spe_enabled;
c227f099 203 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
ea4e754f 204 int singlestep_enabled;
79aceca5
FB
205} DisasContext;
206
c227f099 207struct opc_handler_t {
70560da7
FC
208 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
209 uint32_t inval1;
210 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
211 uint32_t inval2;
9a64fbe4 212 /* instruction type */
0487d6a8 213 uint64_t type;
a5858d7a
AG
214 /* extended instruction type */
215 uint64_t type2;
79aceca5
FB
216 /* handler */
217 void (*handler)(DisasContext *ctx);
a750fc0b 218#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
b55266b5 219 const char *oname;
a750fc0b
JM
220#endif
221#if defined(DO_PPC_STATISTICS)
76a66253
JM
222 uint64_t count;
223#endif
3fc6c082 224};
79aceca5 225
636aa200 226static inline void gen_reset_fpstatus(void)
7c58044c 227{
8e703949 228 gen_helper_reset_fpstatus(cpu_env);
7c58044c
JM
229}
230
636aa200 231static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
7c58044c 232{
0f2f39c2 233 TCGv_i32 t0 = tcg_temp_new_i32();
af12906f 234
7c58044c
JM
235 if (set_fprf != 0) {
236 /* This case might be optimized later */
0f2f39c2 237 tcg_gen_movi_i32(t0, 1);
8e703949 238 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
a7812ae4 239 if (unlikely(set_rc)) {
0f2f39c2 240 tcg_gen_mov_i32(cpu_crf[1], t0);
a7812ae4 241 }
8e703949 242 gen_helper_float_check_status(cpu_env);
7c58044c
JM
243 } else if (unlikely(set_rc)) {
244 /* We always need to compute fpcc */
0f2f39c2 245 tcg_gen_movi_i32(t0, 0);
8e703949 246 gen_helper_compute_fprf(t0, cpu_env, arg, t0);
0f2f39c2 247 tcg_gen_mov_i32(cpu_crf[1], t0);
7c58044c 248 }
af12906f 249
0f2f39c2 250 tcg_temp_free_i32(t0);
7c58044c
JM
251}
252
636aa200 253static inline void gen_set_access_type(DisasContext *ctx, int access_type)
a7859e89 254{
76db3ba4
AJ
255 if (ctx->access_type != access_type) {
256 tcg_gen_movi_i32(cpu_access_type, access_type);
257 ctx->access_type = access_type;
258 }
a7859e89
AJ
259}
260
636aa200 261static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
d9bce9d9
JM
262{
263#if defined(TARGET_PPC64)
264 if (ctx->sf_mode)
bd568f18 265 tcg_gen_movi_tl(cpu_nip, nip);
d9bce9d9
JM
266 else
267#endif
bd568f18 268 tcg_gen_movi_tl(cpu_nip, (uint32_t)nip);
d9bce9d9
JM
269}
270
636aa200 271static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
e06fcd75
AJ
272{
273 TCGv_i32 t0, t1;
274 if (ctx->exception == POWERPC_EXCP_NONE) {
275 gen_update_nip(ctx, ctx->nip);
276 }
277 t0 = tcg_const_i32(excp);
278 t1 = tcg_const_i32(error);
e5f17ac6 279 gen_helper_raise_exception_err(cpu_env, t0, t1);
e06fcd75
AJ
280 tcg_temp_free_i32(t0);
281 tcg_temp_free_i32(t1);
282 ctx->exception = (excp);
283}
e1833e1f 284
636aa200 285static inline void gen_exception(DisasContext *ctx, uint32_t excp)
e06fcd75
AJ
286{
287 TCGv_i32 t0;
288 if (ctx->exception == POWERPC_EXCP_NONE) {
289 gen_update_nip(ctx, ctx->nip);
290 }
291 t0 = tcg_const_i32(excp);
e5f17ac6 292 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
293 tcg_temp_free_i32(t0);
294 ctx->exception = (excp);
295}
e1833e1f 296
636aa200 297static inline void gen_debug_exception(DisasContext *ctx)
e06fcd75
AJ
298{
299 TCGv_i32 t0;
5518f3a6 300
ee2b3994
SB
301 if ((ctx->exception != POWERPC_EXCP_BRANCH) &&
302 (ctx->exception != POWERPC_EXCP_SYNC)) {
5518f3a6 303 gen_update_nip(ctx, ctx->nip);
ee2b3994 304 }
e06fcd75 305 t0 = tcg_const_i32(EXCP_DEBUG);
e5f17ac6 306 gen_helper_raise_exception(cpu_env, t0);
e06fcd75
AJ
307 tcg_temp_free_i32(t0);
308}
9a64fbe4 309
636aa200 310static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
e06fcd75
AJ
311{
312 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
313}
a9d9eb8f 314
f24e5695 315/* Stop translation */
636aa200 316static inline void gen_stop_exception(DisasContext *ctx)
3fc6c082 317{
d9bce9d9 318 gen_update_nip(ctx, ctx->nip);
e1833e1f 319 ctx->exception = POWERPC_EXCP_STOP;
3fc6c082
FB
320}
321
f24e5695 322/* No need to update nip here, as execution flow will change */
636aa200 323static inline void gen_sync_exception(DisasContext *ctx)
2be0071f 324{
e1833e1f 325 ctx->exception = POWERPC_EXCP_SYNC;
2be0071f
FB
326}
327
79aceca5 328#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
329GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
330
331#define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
332GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
79aceca5 333
c7697e1f 334#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
a5858d7a
AG
335GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
336
337#define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
338GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
c7697e1f 339
c227f099 340typedef struct opcode_t {
79aceca5 341 unsigned char opc1, opc2, opc3;
1235fc06 342#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
18fba28c
FB
343 unsigned char pad[5];
344#else
345 unsigned char pad[1];
346#endif
c227f099 347 opc_handler_t handler;
b55266b5 348 const char *oname;
c227f099 349} opcode_t;
79aceca5 350
a750fc0b 351/*****************************************************************************/
79aceca5
FB
352/*** Instruction decoding ***/
353#define EXTRACT_HELPER(name, shift, nb) \
636aa200 354static inline uint32_t name(uint32_t opcode) \
79aceca5
FB
355{ \
356 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
357}
358
359#define EXTRACT_SHELPER(name, shift, nb) \
636aa200 360static inline int32_t name(uint32_t opcode) \
79aceca5 361{ \
18fba28c 362 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
79aceca5
FB
363}
364
365/* Opcode part 1 */
366EXTRACT_HELPER(opc1, 26, 6);
367/* Opcode part 2 */
368EXTRACT_HELPER(opc2, 1, 5);
369/* Opcode part 3 */
370EXTRACT_HELPER(opc3, 6, 5);
371/* Update Cr0 flags */
372EXTRACT_HELPER(Rc, 0, 1);
373/* Destination */
374EXTRACT_HELPER(rD, 21, 5);
375/* Source */
376EXTRACT_HELPER(rS, 21, 5);
377/* First operand */
378EXTRACT_HELPER(rA, 16, 5);
379/* Second operand */
380EXTRACT_HELPER(rB, 11, 5);
381/* Third operand */
382EXTRACT_HELPER(rC, 6, 5);
383/*** Get CRn ***/
384EXTRACT_HELPER(crfD, 23, 3);
385EXTRACT_HELPER(crfS, 18, 3);
386EXTRACT_HELPER(crbD, 21, 5);
387EXTRACT_HELPER(crbA, 16, 5);
388EXTRACT_HELPER(crbB, 11, 5);
389/* SPR / TBL */
3fc6c082 390EXTRACT_HELPER(_SPR, 11, 10);
636aa200 391static inline uint32_t SPR(uint32_t opcode)
3fc6c082
FB
392{
393 uint32_t sprn = _SPR(opcode);
394
395 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
396}
79aceca5
FB
397/*** Get constants ***/
398EXTRACT_HELPER(IMM, 12, 8);
399/* 16 bits signed immediate value */
400EXTRACT_SHELPER(SIMM, 0, 16);
401/* 16 bits unsigned immediate value */
402EXTRACT_HELPER(UIMM, 0, 16);
21d21583
AJ
403/* 5 bits signed immediate value */
404EXTRACT_HELPER(SIMM5, 16, 5);
27a4edb3
AJ
405/* 5 bits signed immediate value */
406EXTRACT_HELPER(UIMM5, 16, 5);
79aceca5
FB
407/* Bit count */
408EXTRACT_HELPER(NB, 11, 5);
409/* Shift count */
410EXTRACT_HELPER(SH, 11, 5);
cd633b10
AJ
411/* Vector shift count */
412EXTRACT_HELPER(VSH, 6, 4);
79aceca5
FB
413/* Mask start */
414EXTRACT_HELPER(MB, 6, 5);
415/* Mask end */
416EXTRACT_HELPER(ME, 1, 5);
fb0eaffc
FB
417/* Trap operand */
418EXTRACT_HELPER(TO, 21, 5);
79aceca5
FB
419
420EXTRACT_HELPER(CRM, 12, 8);
421EXTRACT_HELPER(FM, 17, 8);
422EXTRACT_HELPER(SR, 16, 4);
e4bb997e 423EXTRACT_HELPER(FPIMM, 12, 4);
fb0eaffc 424
79aceca5
FB
425/*** Jump target decoding ***/
426/* Displacement */
427EXTRACT_SHELPER(d, 0, 16);
428/* Immediate address */
636aa200 429static inline target_ulong LI(uint32_t opcode)
79aceca5
FB
430{
431 return (opcode >> 0) & 0x03FFFFFC;
432}
433
636aa200 434static inline uint32_t BD(uint32_t opcode)
79aceca5
FB
435{
436 return (opcode >> 0) & 0xFFFC;
437}
438
439EXTRACT_HELPER(BO, 21, 5);
440EXTRACT_HELPER(BI, 16, 5);
441/* Absolute/relative address */
442EXTRACT_HELPER(AA, 1, 1);
443/* Link */
444EXTRACT_HELPER(LK, 0, 1);
445
446/* Create a mask between <start> and <end> bits */
636aa200 447static inline target_ulong MASK(uint32_t start, uint32_t end)
79aceca5 448{
76a66253 449 target_ulong ret;
79aceca5 450
76a66253
JM
451#if defined(TARGET_PPC64)
452 if (likely(start == 0)) {
6f2d8978 453 ret = UINT64_MAX << (63 - end);
76a66253 454 } else if (likely(end == 63)) {
6f2d8978 455 ret = UINT64_MAX >> start;
76a66253
JM
456 }
457#else
458 if (likely(start == 0)) {
6f2d8978 459 ret = UINT32_MAX << (31 - end);
76a66253 460 } else if (likely(end == 31)) {
6f2d8978 461 ret = UINT32_MAX >> start;
76a66253
JM
462 }
463#endif
464 else {
465 ret = (((target_ulong)(-1ULL)) >> (start)) ^
466 (((target_ulong)(-1ULL) >> (end)) >> 1);
467 if (unlikely(start > end))
468 return ~ret;
469 }
79aceca5
FB
470
471 return ret;
472}
473
a750fc0b 474/*****************************************************************************/
a750fc0b 475/* PowerPC instructions table */
933dc6eb 476
76a66253 477#if defined(DO_PPC_STATISTICS)
a5858d7a 478#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 479{ \
79aceca5
FB
480 .opc1 = op1, \
481 .opc2 = op2, \
482 .opc3 = op3, \
18fba28c 483 .pad = { 0, }, \
79aceca5 484 .handler = { \
70560da7
FC
485 .inval1 = invl, \
486 .type = _typ, \
487 .type2 = _typ2, \
488 .handler = &gen_##name, \
489 .oname = stringify(name), \
490 }, \
491 .oname = stringify(name), \
492}
493#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
494{ \
495 .opc1 = op1, \
496 .opc2 = op2, \
497 .opc3 = op3, \
498 .pad = { 0, }, \
499 .handler = { \
500 .inval1 = invl1, \
501 .inval2 = invl2, \
9a64fbe4 502 .type = _typ, \
a5858d7a 503 .type2 = _typ2, \
79aceca5 504 .handler = &gen_##name, \
76a66253 505 .oname = stringify(name), \
79aceca5 506 }, \
3fc6c082 507 .oname = stringify(name), \
79aceca5 508}
a5858d7a 509#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 510{ \
c7697e1f
JM
511 .opc1 = op1, \
512 .opc2 = op2, \
513 .opc3 = op3, \
514 .pad = { 0, }, \
515 .handler = { \
70560da7 516 .inval1 = invl, \
c7697e1f 517 .type = _typ, \
a5858d7a 518 .type2 = _typ2, \
c7697e1f
JM
519 .handler = &gen_##name, \
520 .oname = onam, \
521 }, \
522 .oname = onam, \
523}
76a66253 524#else
a5858d7a 525#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99 526{ \
c7697e1f
JM
527 .opc1 = op1, \
528 .opc2 = op2, \
529 .opc3 = op3, \
530 .pad = { 0, }, \
531 .handler = { \
70560da7
FC
532 .inval1 = invl, \
533 .type = _typ, \
534 .type2 = _typ2, \
535 .handler = &gen_##name, \
536 }, \
537 .oname = stringify(name), \
538}
539#define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
540{ \
541 .opc1 = op1, \
542 .opc2 = op2, \
543 .opc3 = op3, \
544 .pad = { 0, }, \
545 .handler = { \
546 .inval1 = invl1, \
547 .inval2 = invl2, \
c7697e1f 548 .type = _typ, \
a5858d7a 549 .type2 = _typ2, \
c7697e1f 550 .handler = &gen_##name, \
5c55ff99
BS
551 }, \
552 .oname = stringify(name), \
553}
a5858d7a 554#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
5c55ff99
BS
555{ \
556 .opc1 = op1, \
557 .opc2 = op2, \
558 .opc3 = op3, \
559 .pad = { 0, }, \
560 .handler = { \
70560da7 561 .inval1 = invl, \
5c55ff99 562 .type = _typ, \
a5858d7a 563 .type2 = _typ2, \
5c55ff99
BS
564 .handler = &gen_##name, \
565 }, \
566 .oname = onam, \
567}
568#endif
2e610050 569
5c55ff99 570/* SPR load/store helpers */
636aa200 571static inline void gen_load_spr(TCGv t, int reg)
5c55ff99 572{
1328c2bf 573 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 574}
2e610050 575
636aa200 576static inline void gen_store_spr(int reg, TCGv t)
5c55ff99 577{
1328c2bf 578 tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg]));
5c55ff99 579}
2e610050 580
54623277 581/* Invalid instruction */
99e300ef 582static void gen_invalid(DisasContext *ctx)
9a64fbe4 583{
e06fcd75 584 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
9a64fbe4
FB
585}
586
c227f099 587static opc_handler_t invalid_handler = {
70560da7
FC
588 .inval1 = 0xFFFFFFFF,
589 .inval2 = 0xFFFFFFFF,
9a64fbe4 590 .type = PPC_NONE,
a5858d7a 591 .type2 = PPC_NONE,
79aceca5
FB
592 .handler = gen_invalid,
593};
594
e1571908
AJ
595/*** Integer comparison ***/
596
636aa200 597static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 598{
2fdcb629
RH
599 TCGv t0 = tcg_temp_new();
600 TCGv_i32 t1 = tcg_temp_new_i32();
e1571908 601
da91a00f 602 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so);
e1571908 603
2fdcb629
RH
604 tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1);
605 tcg_gen_trunc_tl_i32(t1, t0);
606 tcg_gen_shli_i32(t1, t1, CRF_LT);
607 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
608
609 tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1);
610 tcg_gen_trunc_tl_i32(t1, t0);
611 tcg_gen_shli_i32(t1, t1, CRF_GT);
612 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
613
614 tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1);
615 tcg_gen_trunc_tl_i32(t1, t0);
616 tcg_gen_shli_i32(t1, t1, CRF_EQ);
617 tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1);
618
619 tcg_temp_free(t0);
620 tcg_temp_free_i32(t1);
e1571908
AJ
621}
622
636aa200 623static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 624{
2fdcb629 625 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
626 gen_op_cmp(arg0, t0, s, crf);
627 tcg_temp_free(t0);
e1571908
AJ
628}
629
630#if defined(TARGET_PPC64)
636aa200 631static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
e1571908 632{
ea363694 633 TCGv t0, t1;
2fdcb629
RH
634 t0 = tcg_temp_new();
635 t1 = tcg_temp_new();
e1571908 636 if (s) {
ea363694
AJ
637 tcg_gen_ext32s_tl(t0, arg0);
638 tcg_gen_ext32s_tl(t1, arg1);
e1571908 639 } else {
ea363694
AJ
640 tcg_gen_ext32u_tl(t0, arg0);
641 tcg_gen_ext32u_tl(t1, arg1);
e1571908 642 }
ea363694
AJ
643 gen_op_cmp(t0, t1, s, crf);
644 tcg_temp_free(t1);
645 tcg_temp_free(t0);
e1571908
AJ
646}
647
636aa200 648static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
e1571908 649{
2fdcb629 650 TCGv t0 = tcg_const_tl(arg1);
ea363694
AJ
651 gen_op_cmp32(arg0, t0, s, crf);
652 tcg_temp_free(t0);
e1571908
AJ
653}
654#endif
655
636aa200 656static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
e1571908
AJ
657{
658#if defined(TARGET_PPC64)
659 if (!(ctx->sf_mode))
660 gen_op_cmpi32(reg, 0, 1, 0);
661 else
662#endif
663 gen_op_cmpi(reg, 0, 1, 0);
664}
665
666/* cmp */
99e300ef 667static void gen_cmp(DisasContext *ctx)
e1571908
AJ
668{
669#if defined(TARGET_PPC64)
670 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
671 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
672 1, crfD(ctx->opcode));
673 else
674#endif
675 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
676 1, crfD(ctx->opcode));
677}
678
679/* cmpi */
99e300ef 680static void gen_cmpi(DisasContext *ctx)
e1571908
AJ
681{
682#if defined(TARGET_PPC64)
683 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
684 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
685 1, crfD(ctx->opcode));
686 else
687#endif
688 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
689 1, crfD(ctx->opcode));
690}
691
692/* cmpl */
99e300ef 693static void gen_cmpl(DisasContext *ctx)
e1571908
AJ
694{
695#if defined(TARGET_PPC64)
696 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
697 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
698 0, crfD(ctx->opcode));
699 else
700#endif
701 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
702 0, crfD(ctx->opcode));
703}
704
705/* cmpli */
99e300ef 706static void gen_cmpli(DisasContext *ctx)
e1571908
AJ
707{
708#if defined(TARGET_PPC64)
709 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
710 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
711 0, crfD(ctx->opcode));
712 else
713#endif
714 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
715 0, crfD(ctx->opcode));
716}
717
718/* isel (PowerPC 2.03 specification) */
99e300ef 719static void gen_isel(DisasContext *ctx)
e1571908
AJ
720{
721 int l1, l2;
722 uint32_t bi = rC(ctx->opcode);
723 uint32_t mask;
a7812ae4 724 TCGv_i32 t0;
e1571908
AJ
725
726 l1 = gen_new_label();
727 l2 = gen_new_label();
728
729 mask = 1 << (3 - (bi & 0x03));
a7812ae4 730 t0 = tcg_temp_new_i32();
fea0c503
AJ
731 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
732 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
e1571908
AJ
733 if (rA(ctx->opcode) == 0)
734 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
735 else
736 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
737 tcg_gen_br(l2);
738 gen_set_label(l1);
739 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
740 gen_set_label(l2);
a7812ae4 741 tcg_temp_free_i32(t0);
e1571908
AJ
742}
743
79aceca5 744/*** Integer arithmetic ***/
79aceca5 745
636aa200
BS
746static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
747 TCGv arg1, TCGv arg2, int sub)
74637406 748{
ffe30937 749 TCGv t0 = tcg_temp_new();
79aceca5 750
ffe30937 751 tcg_gen_xor_tl(cpu_ov, arg0, arg1);
74637406 752 tcg_gen_xor_tl(t0, arg1, arg2);
ffe30937
RH
753 if (sub) {
754 tcg_gen_and_tl(cpu_ov, cpu_ov, t0);
755 } else {
756 tcg_gen_andc_tl(cpu_ov, cpu_ov, t0);
757 }
758 tcg_temp_free(t0);
74637406 759#if defined(TARGET_PPC64)
ffe30937
RH
760 if (!ctx->sf_mode) {
761 tcg_gen_ext32s_tl(cpu_ov, cpu_ov);
762 }
74637406 763#endif
ffe30937
RH
764 tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1);
765 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
79aceca5
FB
766}
767
74637406 768/* Common add function */
636aa200 769static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
770 TCGv arg2, bool add_ca, bool compute_ca,
771 bool compute_ov, bool compute_rc0)
74637406 772{
b5a73f8d 773 TCGv t0 = ret;
d9bce9d9 774
b5a73f8d
RH
775 if (((compute_ca && add_ca) || compute_ov)
776 && (TCGV_EQUAL(ret, arg1) || TCGV_EQUAL(ret, arg2))) {
146de60d 777 t0 = tcg_temp_new();
74637406 778 }
79aceca5 779
da91a00f 780 if (compute_ca) {
b5a73f8d
RH
781 TCGv zero = tcg_const_tl(0);
782 if (add_ca) {
783 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero);
784 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero);
785 } else {
786 tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero);
787 }
788 tcg_temp_free(zero);
789 } else {
790 tcg_gen_add_tl(t0, arg1, arg2);
791 if (add_ca) {
792 tcg_gen_add_tl(t0, t0, cpu_ca);
793 }
da91a00f 794 }
79aceca5 795
74637406
AJ
796 if (compute_ov) {
797 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
798 }
b5a73f8d 799 if (unlikely(compute_rc0)) {
74637406 800 gen_set_Rc0(ctx, t0);
b5a73f8d 801 }
74637406 802
a7812ae4 803 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
804 tcg_gen_mov_tl(ret, t0);
805 tcg_temp_free(t0);
806 }
39dd32ee 807}
74637406
AJ
808/* Add functions with two operands */
809#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 810static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
811{ \
812 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
813 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 814 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
815}
816/* Add functions with one operand and one immediate */
817#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
818 add_ca, compute_ca, compute_ov) \
b5a73f8d 819static void glue(gen_, name)(DisasContext *ctx) \
74637406 820{ \
b5a73f8d 821 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
822 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
823 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 824 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
825 tcg_temp_free(t0); \
826}
827
828/* add add. addo addo. */
829GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
830GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
831/* addc addc. addco addco. */
832GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
833GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
834/* adde adde. addeo addeo. */
835GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
836GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
837/* addme addme. addmeo addmeo. */
838GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
839GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
840/* addze addze. addzeo addzeo.*/
841GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
842GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
843/* addi */
99e300ef 844static void gen_addi(DisasContext *ctx)
d9bce9d9 845{
74637406
AJ
846 target_long simm = SIMM(ctx->opcode);
847
848 if (rA(ctx->opcode) == 0) {
849 /* li case */
850 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
851 } else {
b5a73f8d
RH
852 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
853 cpu_gpr[rA(ctx->opcode)], simm);
74637406 854 }
d9bce9d9 855}
74637406 856/* addic addic.*/
b5a73f8d 857static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0)
d9bce9d9 858{
b5a73f8d
RH
859 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
860 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
861 c, 0, 1, 0, compute_rc0);
862 tcg_temp_free(c);
d9bce9d9 863}
99e300ef
BS
864
865static void gen_addic(DisasContext *ctx)
d9bce9d9 866{
b5a73f8d 867 gen_op_addic(ctx, 0);
d9bce9d9 868}
e8eaa2c0
BS
869
870static void gen_addic_(DisasContext *ctx)
d9bce9d9 871{
b5a73f8d 872 gen_op_addic(ctx, 1);
d9bce9d9 873}
99e300ef 874
54623277 875/* addis */
99e300ef 876static void gen_addis(DisasContext *ctx)
d9bce9d9 877{
74637406
AJ
878 target_long simm = SIMM(ctx->opcode);
879
880 if (rA(ctx->opcode) == 0) {
881 /* lis case */
882 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
883 } else {
b5a73f8d
RH
884 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)],
885 cpu_gpr[rA(ctx->opcode)], simm << 16);
74637406 886 }
d9bce9d9 887}
74637406 888
636aa200
BS
889static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
890 TCGv arg2, int sign, int compute_ov)
d9bce9d9 891{
2ef1b120
AJ
892 int l1 = gen_new_label();
893 int l2 = gen_new_label();
a7812ae4
PB
894 TCGv_i32 t0 = tcg_temp_local_new_i32();
895 TCGv_i32 t1 = tcg_temp_local_new_i32();
74637406 896
2ef1b120
AJ
897 tcg_gen_trunc_tl_i32(t0, arg1);
898 tcg_gen_trunc_tl_i32(t1, arg2);
899 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
74637406 900 if (sign) {
2ef1b120
AJ
901 int l3 = gen_new_label();
902 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
903 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
74637406 904 gen_set_label(l3);
2ef1b120 905 tcg_gen_div_i32(t0, t0, t1);
74637406 906 } else {
2ef1b120 907 tcg_gen_divu_i32(t0, t0, t1);
74637406
AJ
908 }
909 if (compute_ov) {
da91a00f 910 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
911 }
912 tcg_gen_br(l2);
913 gen_set_label(l1);
914 if (sign) {
2ef1b120 915 tcg_gen_sari_i32(t0, t0, 31);
74637406
AJ
916 } else {
917 tcg_gen_movi_i32(t0, 0);
918 }
919 if (compute_ov) {
da91a00f
RH
920 tcg_gen_movi_tl(cpu_ov, 1);
921 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
922 }
923 gen_set_label(l2);
2ef1b120 924 tcg_gen_extu_i32_tl(ret, t0);
a7812ae4
PB
925 tcg_temp_free_i32(t0);
926 tcg_temp_free_i32(t1);
74637406
AJ
927 if (unlikely(Rc(ctx->opcode) != 0))
928 gen_set_Rc0(ctx, ret);
d9bce9d9 929}
74637406
AJ
930/* Div functions */
931#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
99e300ef 932static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
933{ \
934 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
935 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
936 sign, compute_ov); \
937}
938/* divwu divwu. divwuo divwuo. */
939GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
940GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
941/* divw divw. divwo divwo. */
942GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
943GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
d9bce9d9 944#if defined(TARGET_PPC64)
636aa200
BS
945static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
946 TCGv arg2, int sign, int compute_ov)
d9bce9d9 947{
2ef1b120
AJ
948 int l1 = gen_new_label();
949 int l2 = gen_new_label();
74637406
AJ
950
951 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
952 if (sign) {
2ef1b120 953 int l3 = gen_new_label();
74637406
AJ
954 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
955 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
956 gen_set_label(l3);
74637406
AJ
957 tcg_gen_div_i64(ret, arg1, arg2);
958 } else {
959 tcg_gen_divu_i64(ret, arg1, arg2);
960 }
961 if (compute_ov) {
da91a00f 962 tcg_gen_movi_tl(cpu_ov, 0);
74637406
AJ
963 }
964 tcg_gen_br(l2);
965 gen_set_label(l1);
966 if (sign) {
967 tcg_gen_sari_i64(ret, arg1, 63);
968 } else {
969 tcg_gen_movi_i64(ret, 0);
970 }
971 if (compute_ov) {
da91a00f
RH
972 tcg_gen_movi_tl(cpu_ov, 1);
973 tcg_gen_movi_tl(cpu_so, 1);
74637406
AJ
974 }
975 gen_set_label(l2);
976 if (unlikely(Rc(ctx->opcode) != 0))
977 gen_set_Rc0(ctx, ret);
d9bce9d9 978}
74637406 979#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
99e300ef 980static void glue(gen_, name)(DisasContext *ctx) \
74637406 981{ \
2ef1b120
AJ
982 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
983 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
984 sign, compute_ov); \
74637406
AJ
985}
986/* divwu divwu. divwuo divwuo. */
987GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
988GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
989/* divw divw. divwo divwo. */
990GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
991GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
d9bce9d9 992#endif
74637406
AJ
993
994/* mulhw mulhw. */
99e300ef 995static void gen_mulhw(DisasContext *ctx)
d9bce9d9 996{
23ad1d5d
RH
997 TCGv_i32 t0 = tcg_temp_new_i32();
998 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 999
23ad1d5d
RH
1000 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1001 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1002 tcg_gen_muls2_i32(t0, t1, t0, t1);
1003 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1004 tcg_temp_free_i32(t0);
1005 tcg_temp_free_i32(t1);
74637406
AJ
1006 if (unlikely(Rc(ctx->opcode) != 0))
1007 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1008}
99e300ef 1009
54623277 1010/* mulhwu mulhwu. */
99e300ef 1011static void gen_mulhwu(DisasContext *ctx)
d9bce9d9 1012{
23ad1d5d
RH
1013 TCGv_i32 t0 = tcg_temp_new_i32();
1014 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1015
23ad1d5d
RH
1016 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1017 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1018 tcg_gen_mulu2_i32(t0, t1, t0, t1);
1019 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1);
1020 tcg_temp_free_i32(t0);
1021 tcg_temp_free_i32(t1);
74637406
AJ
1022 if (unlikely(Rc(ctx->opcode) != 0))
1023 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1024}
99e300ef 1025
54623277 1026/* mullw mullw. */
99e300ef 1027static void gen_mullw(DisasContext *ctx)
d9bce9d9 1028{
74637406
AJ
1029 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1030 cpu_gpr[rB(ctx->opcode)]);
1e4c090f 1031 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
74637406
AJ
1032 if (unlikely(Rc(ctx->opcode) != 0))
1033 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1034}
99e300ef 1035
54623277 1036/* mullwo mullwo. */
99e300ef 1037static void gen_mullwo(DisasContext *ctx)
d9bce9d9 1038{
e4a2c846
RH
1039 TCGv_i32 t0 = tcg_temp_new_i32();
1040 TCGv_i32 t1 = tcg_temp_new_i32();
74637406 1041
e4a2c846
RH
1042 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);
1043 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);
1044 tcg_gen_muls2_i32(t0, t1, t0, t1);
1045 tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
1046
1047 tcg_gen_sari_i32(t0, t0, 31);
1048 tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1);
1049 tcg_gen_extu_i32_tl(cpu_ov, t0);
1050 tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov);
1051
1052 tcg_temp_free_i32(t0);
1053 tcg_temp_free_i32(t1);
74637406
AJ
1054 if (unlikely(Rc(ctx->opcode) != 0))
1055 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1056}
99e300ef 1057
54623277 1058/* mulli */
99e300ef 1059static void gen_mulli(DisasContext *ctx)
d9bce9d9 1060{
74637406
AJ
1061 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1062 SIMM(ctx->opcode));
d9bce9d9 1063}
23ad1d5d 1064
d9bce9d9 1065#if defined(TARGET_PPC64)
74637406 1066/* mulhd mulhd. */
23ad1d5d
RH
1067static void gen_mulhd(DisasContext *ctx)
1068{
1069 TCGv lo = tcg_temp_new();
1070 tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1071 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1072 tcg_temp_free(lo);
1073 if (unlikely(Rc(ctx->opcode) != 0)) {
1074 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1075 }
1076}
1077
74637406 1078/* mulhdu mulhdu. */
23ad1d5d
RH
1079static void gen_mulhdu(DisasContext *ctx)
1080{
1081 TCGv lo = tcg_temp_new();
1082 tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)],
1083 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1084 tcg_temp_free(lo);
1085 if (unlikely(Rc(ctx->opcode) != 0)) {
1086 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1087 }
1088}
99e300ef 1089
54623277 1090/* mulld mulld. */
99e300ef 1091static void gen_mulld(DisasContext *ctx)
d9bce9d9 1092{
74637406
AJ
1093 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1094 cpu_gpr[rB(ctx->opcode)]);
1095 if (unlikely(Rc(ctx->opcode) != 0))
1096 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
d9bce9d9 1097}
d15f74fb 1098
74637406 1099/* mulldo mulldo. */
d15f74fb
BS
1100static void gen_mulldo(DisasContext *ctx)
1101{
1102 gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env,
1103 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1104 if (unlikely(Rc(ctx->opcode) != 0)) {
1105 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1106 }
1107}
d9bce9d9 1108#endif
74637406 1109
74637406 1110/* Common subf function */
636aa200 1111static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
b5a73f8d
RH
1112 TCGv arg2, bool add_ca, bool compute_ca,
1113 bool compute_ov, bool compute_rc0)
79aceca5 1114{
b5a73f8d 1115 TCGv t0 = ret;
79aceca5 1116
b5a73f8d
RH
1117 if (((add_ca && compute_ca) || compute_ov)
1118 && (TCGV_EQUAL(ret, arg1) || TCGV_EQUAL(ret, arg2))) {
1119 t0 = tcg_temp_new();
da91a00f 1120 }
74637406
AJ
1121
1122 if (add_ca) {
08f4a0f7 1123 /* dest = ~arg1 + arg2 + ca. */
b5a73f8d 1124 if (compute_ca) {
08f4a0f7
RH
1125 TCGv zero, inv1 = tcg_temp_new();
1126 tcg_gen_not_tl(inv1, arg1);
b5a73f8d
RH
1127 zero = tcg_const_tl(0);
1128 tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero);
08f4a0f7 1129 tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero);
b5a73f8d 1130 tcg_temp_free(zero);
08f4a0f7 1131 tcg_temp_free(inv1);
b5a73f8d
RH
1132 } else {
1133 tcg_gen_sub_tl(t0, arg2, arg1);
1134 tcg_gen_add_tl(t0, t0, cpu_ca);
1135 tcg_gen_subi_tl(t0, t0, 1);
1136 }
79aceca5 1137 } else {
74637406 1138 if (compute_ca) {
b5a73f8d 1139 tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1);
74637406 1140 }
b5a73f8d 1141 tcg_gen_sub_tl(t0, arg2, arg1);
74637406 1142 }
b5a73f8d 1143
74637406
AJ
1144 if (compute_ov) {
1145 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1146 }
b5a73f8d 1147 if (unlikely(compute_rc0)) {
74637406 1148 gen_set_Rc0(ctx, t0);
b5a73f8d 1149 }
74637406 1150
a7812ae4 1151 if (!TCGV_EQUAL(t0, ret)) {
74637406
AJ
1152 tcg_gen_mov_tl(ret, t0);
1153 tcg_temp_free(t0);
79aceca5 1154 }
79aceca5 1155}
74637406
AJ
1156/* Sub functions with Two operands functions */
1157#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
b5a73f8d 1158static void glue(gen_, name)(DisasContext *ctx) \
74637406
AJ
1159{ \
1160 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1161 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
b5a73f8d 1162 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1163}
1164/* Sub functions with one operand and one immediate */
1165#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1166 add_ca, compute_ca, compute_ov) \
b5a73f8d 1167static void glue(gen_, name)(DisasContext *ctx) \
74637406 1168{ \
b5a73f8d 1169 TCGv t0 = tcg_const_tl(const_val); \
74637406
AJ
1170 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1171 cpu_gpr[rA(ctx->opcode)], t0, \
b5a73f8d 1172 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
74637406
AJ
1173 tcg_temp_free(t0); \
1174}
1175/* subf subf. subfo subfo. */
1176GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1177GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1178/* subfc subfc. subfco subfco. */
1179GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1180GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1181/* subfe subfe. subfeo subfo. */
1182GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1183GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1184/* subfme subfme. subfmeo subfmeo. */
1185GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1186GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1187/* subfze subfze. subfzeo subfzeo.*/
1188GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1189GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
99e300ef 1190
54623277 1191/* subfic */
99e300ef 1192static void gen_subfic(DisasContext *ctx)
79aceca5 1193{
b5a73f8d
RH
1194 TCGv c = tcg_const_tl(SIMM(ctx->opcode));
1195 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1196 c, 0, 1, 0, 0);
1197 tcg_temp_free(c);
79aceca5
FB
1198}
1199
fd3f0081
RH
1200/* neg neg. nego nego. */
1201static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov)
1202{
1203 TCGv zero = tcg_const_tl(0);
1204 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1205 zero, 0, 0, compute_ov, Rc(ctx->opcode));
1206 tcg_temp_free(zero);
1207}
1208
1209static void gen_neg(DisasContext *ctx)
1210{
1211 gen_op_arith_neg(ctx, 0);
1212}
1213
1214static void gen_nego(DisasContext *ctx)
1215{
1216 gen_op_arith_neg(ctx, 1);
1217}
1218
79aceca5 1219/*** Integer logical ***/
26d67362 1220#define GEN_LOGICAL2(name, tcg_op, opc, type) \
99e300ef 1221static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1222{ \
26d67362
AJ
1223 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1224 cpu_gpr[rB(ctx->opcode)]); \
76a66253 1225 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1226 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5 1227}
79aceca5 1228
26d67362 1229#define GEN_LOGICAL1(name, tcg_op, opc, type) \
99e300ef 1230static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 1231{ \
26d67362 1232 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
76a66253 1233 if (unlikely(Rc(ctx->opcode) != 0)) \
26d67362 1234 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
79aceca5
FB
1235}
1236
1237/* and & and. */
26d67362 1238GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
79aceca5 1239/* andc & andc. */
26d67362 1240GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
e8eaa2c0 1241
54623277 1242/* andi. */
e8eaa2c0 1243static void gen_andi_(DisasContext *ctx)
79aceca5 1244{
26d67362
AJ
1245 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1246 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1247}
e8eaa2c0 1248
54623277 1249/* andis. */
e8eaa2c0 1250static void gen_andis_(DisasContext *ctx)
79aceca5 1251{
26d67362
AJ
1252 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1253 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1254}
99e300ef 1255
54623277 1256/* cntlzw */
99e300ef 1257static void gen_cntlzw(DisasContext *ctx)
26d67362 1258{
a7812ae4 1259 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362 1260 if (unlikely(Rc(ctx->opcode) != 0))
2e31f5d3 1261 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
26d67362 1262}
79aceca5 1263/* eqv & eqv. */
26d67362 1264GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
79aceca5 1265/* extsb & extsb. */
26d67362 1266GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
79aceca5 1267/* extsh & extsh. */
26d67362 1268GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
79aceca5 1269/* nand & nand. */
26d67362 1270GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
79aceca5 1271/* nor & nor. */
26d67362 1272GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
99e300ef 1273
54623277 1274/* or & or. */
99e300ef 1275static void gen_or(DisasContext *ctx)
9a64fbe4 1276{
76a66253
JM
1277 int rs, ra, rb;
1278
1279 rs = rS(ctx->opcode);
1280 ra = rA(ctx->opcode);
1281 rb = rB(ctx->opcode);
1282 /* Optimisation for mr. ri case */
1283 if (rs != ra || rs != rb) {
26d67362
AJ
1284 if (rs != rb)
1285 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1286 else
1287 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
76a66253 1288 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1289 gen_set_Rc0(ctx, cpu_gpr[ra]);
76a66253 1290 } else if (unlikely(Rc(ctx->opcode) != 0)) {
26d67362 1291 gen_set_Rc0(ctx, cpu_gpr[rs]);
c80f84e3
JM
1292#if defined(TARGET_PPC64)
1293 } else {
26d67362
AJ
1294 int prio = 0;
1295
c80f84e3
JM
1296 switch (rs) {
1297 case 1:
1298 /* Set process priority to low */
26d67362 1299 prio = 2;
c80f84e3
JM
1300 break;
1301 case 6:
1302 /* Set process priority to medium-low */
26d67362 1303 prio = 3;
c80f84e3
JM
1304 break;
1305 case 2:
1306 /* Set process priority to normal */
26d67362 1307 prio = 4;
c80f84e3 1308 break;
be147d08
JM
1309#if !defined(CONFIG_USER_ONLY)
1310 case 31:
76db3ba4 1311 if (ctx->mem_idx > 0) {
be147d08 1312 /* Set process priority to very low */
26d67362 1313 prio = 1;
be147d08
JM
1314 }
1315 break;
1316 case 5:
76db3ba4 1317 if (ctx->mem_idx > 0) {
be147d08 1318 /* Set process priority to medium-hight */
26d67362 1319 prio = 5;
be147d08
JM
1320 }
1321 break;
1322 case 3:
76db3ba4 1323 if (ctx->mem_idx > 0) {
be147d08 1324 /* Set process priority to high */
26d67362 1325 prio = 6;
be147d08
JM
1326 }
1327 break;
be147d08 1328 case 7:
76db3ba4 1329 if (ctx->mem_idx > 1) {
be147d08 1330 /* Set process priority to very high */
26d67362 1331 prio = 7;
be147d08
JM
1332 }
1333 break;
be147d08 1334#endif
c80f84e3
JM
1335 default:
1336 /* nop */
1337 break;
1338 }
26d67362 1339 if (prio) {
a7812ae4 1340 TCGv t0 = tcg_temp_new();
54cdcae6 1341 gen_load_spr(t0, SPR_PPR);
ea363694
AJ
1342 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1343 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
54cdcae6 1344 gen_store_spr(SPR_PPR, t0);
ea363694 1345 tcg_temp_free(t0);
26d67362 1346 }
c80f84e3 1347#endif
9a64fbe4 1348 }
9a64fbe4 1349}
79aceca5 1350/* orc & orc. */
26d67362 1351GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
99e300ef 1352
54623277 1353/* xor & xor. */
99e300ef 1354static void gen_xor(DisasContext *ctx)
9a64fbe4 1355{
9a64fbe4 1356 /* Optimisation for "set to zero" case */
26d67362 1357 if (rS(ctx->opcode) != rB(ctx->opcode))
312179c4 1358 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1359 else
1360 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
76a66253 1361 if (unlikely(Rc(ctx->opcode) != 0))
26d67362 1362 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
9a64fbe4 1363}
99e300ef 1364
54623277 1365/* ori */
99e300ef 1366static void gen_ori(DisasContext *ctx)
79aceca5 1367{
76a66253 1368 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1369
9a64fbe4
FB
1370 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1371 /* NOP */
76a66253 1372 /* XXX: should handle special NOPs for POWER series */
9a64fbe4 1373 return;
76a66253 1374 }
26d67362 1375 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1376}
99e300ef 1377
54623277 1378/* oris */
99e300ef 1379static void gen_oris(DisasContext *ctx)
79aceca5 1380{
76a66253 1381 target_ulong uimm = UIMM(ctx->opcode);
79aceca5 1382
9a64fbe4
FB
1383 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1384 /* NOP */
1385 return;
76a66253 1386 }
26d67362 1387 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1388}
99e300ef 1389
54623277 1390/* xori */
99e300ef 1391static void gen_xori(DisasContext *ctx)
79aceca5 1392{
76a66253 1393 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1394
1395 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1396 /* NOP */
1397 return;
1398 }
26d67362 1399 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
79aceca5 1400}
99e300ef 1401
54623277 1402/* xoris */
99e300ef 1403static void gen_xoris(DisasContext *ctx)
79aceca5 1404{
76a66253 1405 target_ulong uimm = UIMM(ctx->opcode);
9a64fbe4
FB
1406
1407 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1408 /* NOP */
1409 return;
1410 }
26d67362 1411 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
79aceca5 1412}
99e300ef 1413
54623277 1414/* popcntb : PowerPC 2.03 specification */
99e300ef 1415static void gen_popcntb(DisasContext *ctx)
d9bce9d9 1416{
eaabeef2
DG
1417 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1418}
1419
1420static void gen_popcntw(DisasContext *ctx)
1421{
1422 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1423}
1424
d9bce9d9 1425#if defined(TARGET_PPC64)
eaabeef2
DG
1426/* popcntd: PowerPC 2.06 specification */
1427static void gen_popcntd(DisasContext *ctx)
1428{
1429 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 1430}
eaabeef2 1431#endif
d9bce9d9
JM
1432
1433#if defined(TARGET_PPC64)
1434/* extsw & extsw. */
26d67362 1435GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
99e300ef 1436
54623277 1437/* cntlzd */
99e300ef 1438static void gen_cntlzd(DisasContext *ctx)
26d67362 1439{
a7812ae4 1440 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
26d67362
AJ
1441 if (unlikely(Rc(ctx->opcode) != 0))
1442 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1443}
d9bce9d9
JM
1444#endif
1445
79aceca5 1446/*** Integer rotate ***/
99e300ef 1447
54623277 1448/* rlwimi & rlwimi. */
99e300ef 1449static void gen_rlwimi(DisasContext *ctx)
79aceca5 1450{
76a66253 1451 uint32_t mb, me, sh;
79aceca5
FB
1452
1453 mb = MB(ctx->opcode);
1454 me = ME(ctx->opcode);
76a66253 1455 sh = SH(ctx->opcode);
d03ef511
AJ
1456 if (likely(sh == 0 && mb == 0 && me == 31)) {
1457 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1458 } else {
d03ef511 1459 target_ulong mask;
a7812ae4
PB
1460 TCGv t1;
1461 TCGv t0 = tcg_temp_new();
54843a58 1462#if defined(TARGET_PPC64)
a7812ae4
PB
1463 TCGv_i32 t2 = tcg_temp_new_i32();
1464 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1465 tcg_gen_rotli_i32(t2, t2, sh);
1466 tcg_gen_extu_i32_i64(t0, t2);
1467 tcg_temp_free_i32(t2);
54843a58
AJ
1468#else
1469 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1470#endif
76a66253 1471#if defined(TARGET_PPC64)
d03ef511
AJ
1472 mb += 32;
1473 me += 32;
76a66253 1474#endif
d03ef511 1475 mask = MASK(mb, me);
a7812ae4 1476 t1 = tcg_temp_new();
d03ef511
AJ
1477 tcg_gen_andi_tl(t0, t0, mask);
1478 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1479 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1480 tcg_temp_free(t0);
1481 tcg_temp_free(t1);
1482 }
76a66253 1483 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1484 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1485}
99e300ef 1486
54623277 1487/* rlwinm & rlwinm. */
99e300ef 1488static void gen_rlwinm(DisasContext *ctx)
79aceca5
FB
1489{
1490 uint32_t mb, me, sh;
3b46e624 1491
79aceca5
FB
1492 sh = SH(ctx->opcode);
1493 mb = MB(ctx->opcode);
1494 me = ME(ctx->opcode);
d03ef511
AJ
1495
1496 if (likely(mb == 0 && me == (31 - sh))) {
1497 if (likely(sh == 0)) {
1498 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1499 } else {
a7812ae4 1500 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1501 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1502 tcg_gen_shli_tl(t0, t0, sh);
1503 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1504 tcg_temp_free(t0);
79aceca5 1505 }
d03ef511 1506 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
a7812ae4 1507 TCGv t0 = tcg_temp_new();
d03ef511
AJ
1508 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1509 tcg_gen_shri_tl(t0, t0, mb);
1510 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1511 tcg_temp_free(t0);
1512 } else {
a7812ae4 1513 TCGv t0 = tcg_temp_new();
54843a58 1514#if defined(TARGET_PPC64)
a7812ae4 1515 TCGv_i32 t1 = tcg_temp_new_i32();
54843a58
AJ
1516 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1517 tcg_gen_rotli_i32(t1, t1, sh);
1518 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4 1519 tcg_temp_free_i32(t1);
54843a58
AJ
1520#else
1521 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1522#endif
76a66253 1523#if defined(TARGET_PPC64)
d03ef511
AJ
1524 mb += 32;
1525 me += 32;
76a66253 1526#endif
d03ef511
AJ
1527 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1528 tcg_temp_free(t0);
1529 }
76a66253 1530 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1531 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5 1532}
99e300ef 1533
54623277 1534/* rlwnm & rlwnm. */
99e300ef 1535static void gen_rlwnm(DisasContext *ctx)
79aceca5
FB
1536{
1537 uint32_t mb, me;
54843a58
AJ
1538 TCGv t0;
1539#if defined(TARGET_PPC64)
a7812ae4 1540 TCGv_i32 t1, t2;
54843a58 1541#endif
79aceca5
FB
1542
1543 mb = MB(ctx->opcode);
1544 me = ME(ctx->opcode);
a7812ae4 1545 t0 = tcg_temp_new();
d03ef511 1546 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
54843a58 1547#if defined(TARGET_PPC64)
a7812ae4
PB
1548 t1 = tcg_temp_new_i32();
1549 t2 = tcg_temp_new_i32();
54843a58
AJ
1550 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1551 tcg_gen_trunc_i64_i32(t2, t0);
1552 tcg_gen_rotl_i32(t1, t1, t2);
1553 tcg_gen_extu_i32_i64(t0, t1);
a7812ae4
PB
1554 tcg_temp_free_i32(t1);
1555 tcg_temp_free_i32(t2);
54843a58
AJ
1556#else
1557 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1558#endif
76a66253
JM
1559 if (unlikely(mb != 0 || me != 31)) {
1560#if defined(TARGET_PPC64)
1561 mb += 32;
1562 me += 32;
1563#endif
54843a58 1564 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
d03ef511 1565 } else {
54843a58 1566 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
79aceca5 1567 }
54843a58 1568 tcg_temp_free(t0);
76a66253 1569 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1570 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
79aceca5
FB
1571}
1572
d9bce9d9
JM
1573#if defined(TARGET_PPC64)
1574#define GEN_PPC64_R2(name, opc1, opc2) \
e8eaa2c0 1575static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1576{ \
1577 gen_##name(ctx, 0); \
1578} \
e8eaa2c0
BS
1579 \
1580static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1581{ \
1582 gen_##name(ctx, 1); \
1583}
1584#define GEN_PPC64_R4(name, opc1, opc2) \
e8eaa2c0 1585static void glue(gen_, name##0)(DisasContext *ctx) \
d9bce9d9
JM
1586{ \
1587 gen_##name(ctx, 0, 0); \
1588} \
e8eaa2c0
BS
1589 \
1590static void glue(gen_, name##1)(DisasContext *ctx) \
d9bce9d9
JM
1591{ \
1592 gen_##name(ctx, 0, 1); \
1593} \
e8eaa2c0
BS
1594 \
1595static void glue(gen_, name##2)(DisasContext *ctx) \
d9bce9d9
JM
1596{ \
1597 gen_##name(ctx, 1, 0); \
1598} \
e8eaa2c0
BS
1599 \
1600static void glue(gen_, name##3)(DisasContext *ctx) \
d9bce9d9
JM
1601{ \
1602 gen_##name(ctx, 1, 1); \
1603}
51789c41 1604
636aa200
BS
1605static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1606 uint32_t sh)
51789c41 1607{
d03ef511
AJ
1608 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1609 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1610 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1611 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1612 } else {
a7812ae4 1613 TCGv t0 = tcg_temp_new();
54843a58 1614 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
d03ef511 1615 if (likely(mb == 0 && me == 63)) {
54843a58 1616 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
d03ef511
AJ
1617 } else {
1618 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
51789c41 1619 }
d03ef511 1620 tcg_temp_free(t0);
51789c41 1621 }
51789c41 1622 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1623 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
51789c41 1624}
d9bce9d9 1625/* rldicl - rldicl. */
636aa200 1626static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1627{
51789c41 1628 uint32_t sh, mb;
d9bce9d9 1629
9d53c753
JM
1630 sh = SH(ctx->opcode) | (shn << 5);
1631 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1632 gen_rldinm(ctx, mb, 63, sh);
d9bce9d9 1633}
51789c41 1634GEN_PPC64_R4(rldicl, 0x1E, 0x00);
d9bce9d9 1635/* rldicr - rldicr. */
636aa200 1636static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
d9bce9d9 1637{
51789c41 1638 uint32_t sh, me;
d9bce9d9 1639
9d53c753
JM
1640 sh = SH(ctx->opcode) | (shn << 5);
1641 me = MB(ctx->opcode) | (men << 5);
51789c41 1642 gen_rldinm(ctx, 0, me, sh);
d9bce9d9 1643}
51789c41 1644GEN_PPC64_R4(rldicr, 0x1E, 0x02);
d9bce9d9 1645/* rldic - rldic. */
636aa200 1646static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1647{
51789c41 1648 uint32_t sh, mb;
d9bce9d9 1649
9d53c753
JM
1650 sh = SH(ctx->opcode) | (shn << 5);
1651 mb = MB(ctx->opcode) | (mbn << 5);
51789c41
JM
1652 gen_rldinm(ctx, mb, 63 - sh, sh);
1653}
1654GEN_PPC64_R4(rldic, 0x1E, 0x04);
1655
636aa200 1656static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
51789c41 1657{
54843a58 1658 TCGv t0;
d03ef511
AJ
1659
1660 mb = MB(ctx->opcode);
1661 me = ME(ctx->opcode);
a7812ae4 1662 t0 = tcg_temp_new();
d03ef511 1663 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
54843a58 1664 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
51789c41 1665 if (unlikely(mb != 0 || me != 63)) {
54843a58
AJ
1666 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1667 } else {
1668 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1669 }
1670 tcg_temp_free(t0);
51789c41 1671 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1672 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1673}
51789c41 1674
d9bce9d9 1675/* rldcl - rldcl. */
636aa200 1676static inline void gen_rldcl(DisasContext *ctx, int mbn)
d9bce9d9 1677{
51789c41 1678 uint32_t mb;
d9bce9d9 1679
9d53c753 1680 mb = MB(ctx->opcode) | (mbn << 5);
51789c41 1681 gen_rldnm(ctx, mb, 63);
d9bce9d9 1682}
36081602 1683GEN_PPC64_R2(rldcl, 0x1E, 0x08);
d9bce9d9 1684/* rldcr - rldcr. */
636aa200 1685static inline void gen_rldcr(DisasContext *ctx, int men)
d9bce9d9 1686{
51789c41 1687 uint32_t me;
d9bce9d9 1688
9d53c753 1689 me = MB(ctx->opcode) | (men << 5);
51789c41 1690 gen_rldnm(ctx, 0, me);
d9bce9d9 1691}
36081602 1692GEN_PPC64_R2(rldcr, 0x1E, 0x09);
d9bce9d9 1693/* rldimi - rldimi. */
636aa200 1694static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
d9bce9d9 1695{
271a916e 1696 uint32_t sh, mb, me;
d9bce9d9 1697
9d53c753
JM
1698 sh = SH(ctx->opcode) | (shn << 5);
1699 mb = MB(ctx->opcode) | (mbn << 5);
271a916e 1700 me = 63 - sh;
d03ef511
AJ
1701 if (unlikely(sh == 0 && mb == 0)) {
1702 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1703 } else {
1704 TCGv t0, t1;
1705 target_ulong mask;
1706
a7812ae4 1707 t0 = tcg_temp_new();
54843a58 1708 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
a7812ae4 1709 t1 = tcg_temp_new();
d03ef511
AJ
1710 mask = MASK(mb, me);
1711 tcg_gen_andi_tl(t0, t0, mask);
1712 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1713 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1714 tcg_temp_free(t0);
1715 tcg_temp_free(t1);
51789c41 1716 }
51789c41 1717 if (unlikely(Rc(ctx->opcode) != 0))
d03ef511 1718 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
d9bce9d9 1719}
36081602 1720GEN_PPC64_R4(rldimi, 0x1E, 0x06);
d9bce9d9
JM
1721#endif
1722
79aceca5 1723/*** Integer shift ***/
99e300ef 1724
54623277 1725/* slw & slw. */
99e300ef 1726static void gen_slw(DisasContext *ctx)
26d67362 1727{
7fd6bf7d 1728 TCGv t0, t1;
26d67362 1729
7fd6bf7d
AJ
1730 t0 = tcg_temp_new();
1731 /* AND rS with a mask that is 0 when rB >= 0x20 */
1732#if defined(TARGET_PPC64)
1733 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1734 tcg_gen_sari_tl(t0, t0, 0x3f);
1735#else
1736 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1737 tcg_gen_sari_tl(t0, t0, 0x1f);
1738#endif
1739 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1740 t1 = tcg_temp_new();
1741 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1742 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1743 tcg_temp_free(t1);
fea0c503 1744 tcg_temp_free(t0);
7fd6bf7d 1745 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
26d67362
AJ
1746 if (unlikely(Rc(ctx->opcode) != 0))
1747 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1748}
99e300ef 1749
54623277 1750/* sraw & sraw. */
99e300ef 1751static void gen_sraw(DisasContext *ctx)
26d67362 1752{
d15f74fb 1753 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1754 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1755 if (unlikely(Rc(ctx->opcode) != 0))
1756 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1757}
99e300ef 1758
54623277 1759/* srawi & srawi. */
99e300ef 1760static void gen_srawi(DisasContext *ctx)
79aceca5 1761{
26d67362 1762 int sh = SH(ctx->opcode);
ba4af3e4
RH
1763 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1764 TCGv src = cpu_gpr[rS(ctx->opcode)];
1765 if (sh == 0) {
1766 tcg_gen_mov_tl(dst, src);
da91a00f 1767 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1768 } else {
ba4af3e4
RH
1769 TCGv t0;
1770 tcg_gen_ext32s_tl(dst, src);
1771 tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1);
1772 t0 = tcg_temp_new();
1773 tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1);
1774 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1775 tcg_temp_free(t0);
1776 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1777 tcg_gen_sari_tl(dst, dst, sh);
1778 }
1779 if (unlikely(Rc(ctx->opcode) != 0)) {
1780 gen_set_Rc0(ctx, dst);
d9bce9d9 1781 }
79aceca5 1782}
99e300ef 1783
54623277 1784/* srw & srw. */
99e300ef 1785static void gen_srw(DisasContext *ctx)
26d67362 1786{
fea0c503 1787 TCGv t0, t1;
d9bce9d9 1788
7fd6bf7d
AJ
1789 t0 = tcg_temp_new();
1790 /* AND rS with a mask that is 0 when rB >= 0x20 */
1791#if defined(TARGET_PPC64)
1792 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1793 tcg_gen_sari_tl(t0, t0, 0x3f);
1794#else
1795 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1796 tcg_gen_sari_tl(t0, t0, 0x1f);
1797#endif
1798 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1799 tcg_gen_ext32u_tl(t0, t0);
a7812ae4 1800 t1 = tcg_temp_new();
7fd6bf7d
AJ
1801 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1802 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
fea0c503 1803 tcg_temp_free(t1);
fea0c503 1804 tcg_temp_free(t0);
26d67362
AJ
1805 if (unlikely(Rc(ctx->opcode) != 0))
1806 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1807}
54623277 1808
d9bce9d9
JM
1809#if defined(TARGET_PPC64)
1810/* sld & sld. */
99e300ef 1811static void gen_sld(DisasContext *ctx)
26d67362 1812{
7fd6bf7d 1813 TCGv t0, t1;
26d67362 1814
7fd6bf7d
AJ
1815 t0 = tcg_temp_new();
1816 /* AND rS with a mask that is 0 when rB >= 0x40 */
1817 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1818 tcg_gen_sari_tl(t0, t0, 0x3f);
1819 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1820 t1 = tcg_temp_new();
1821 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1822 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1823 tcg_temp_free(t1);
fea0c503 1824 tcg_temp_free(t0);
26d67362
AJ
1825 if (unlikely(Rc(ctx->opcode) != 0))
1826 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1827}
99e300ef 1828
54623277 1829/* srad & srad. */
99e300ef 1830static void gen_srad(DisasContext *ctx)
26d67362 1831{
d15f74fb 1832 gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env,
a7812ae4 1833 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
26d67362
AJ
1834 if (unlikely(Rc(ctx->opcode) != 0))
1835 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1836}
d9bce9d9 1837/* sradi & sradi. */
636aa200 1838static inline void gen_sradi(DisasContext *ctx, int n)
d9bce9d9 1839{
26d67362 1840 int sh = SH(ctx->opcode) + (n << 5);
ba4af3e4
RH
1841 TCGv dst = cpu_gpr[rA(ctx->opcode)];
1842 TCGv src = cpu_gpr[rS(ctx->opcode)];
1843 if (sh == 0) {
1844 tcg_gen_mov_tl(dst, src);
da91a00f 1845 tcg_gen_movi_tl(cpu_ca, 0);
26d67362 1846 } else {
ba4af3e4
RH
1847 TCGv t0;
1848 tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1);
1849 t0 = tcg_temp_new();
1850 tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1);
1851 tcg_gen_and_tl(cpu_ca, cpu_ca, t0);
1852 tcg_temp_free(t0);
1853 tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0);
1854 tcg_gen_sari_tl(dst, src, sh);
1855 }
1856 if (unlikely(Rc(ctx->opcode) != 0)) {
1857 gen_set_Rc0(ctx, dst);
d9bce9d9 1858 }
d9bce9d9 1859}
e8eaa2c0
BS
1860
1861static void gen_sradi0(DisasContext *ctx)
d9bce9d9
JM
1862{
1863 gen_sradi(ctx, 0);
1864}
e8eaa2c0
BS
1865
1866static void gen_sradi1(DisasContext *ctx)
d9bce9d9
JM
1867{
1868 gen_sradi(ctx, 1);
1869}
99e300ef 1870
54623277 1871/* srd & srd. */
99e300ef 1872static void gen_srd(DisasContext *ctx)
26d67362 1873{
7fd6bf7d 1874 TCGv t0, t1;
26d67362 1875
7fd6bf7d
AJ
1876 t0 = tcg_temp_new();
1877 /* AND rS with a mask that is 0 when rB >= 0x40 */
1878 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1879 tcg_gen_sari_tl(t0, t0, 0x3f);
1880 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1881 t1 = tcg_temp_new();
1882 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1883 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1884 tcg_temp_free(t1);
fea0c503 1885 tcg_temp_free(t0);
26d67362
AJ
1886 if (unlikely(Rc(ctx->opcode) != 0))
1887 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1888}
d9bce9d9 1889#endif
79aceca5
FB
1890
1891/*** Floating-Point arithmetic ***/
7c58044c 1892#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
99e300ef 1893static void gen_f##name(DisasContext *ctx) \
9a64fbe4 1894{ \
76a66253 1895 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 1896 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
1897 return; \
1898 } \
eb44b959
AJ
1899 /* NIP cannot be restored if the memory exception comes from an helper */ \
1900 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 1901 gen_reset_fpstatus(); \
8e703949
BS
1902 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1903 cpu_fpr[rA(ctx->opcode)], \
af12906f 1904 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 1905 if (isfloat) { \
8e703949
BS
1906 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1907 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 1908 } \
af12906f
AJ
1909 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
1910 Rc(ctx->opcode) != 0); \
9a64fbe4
FB
1911}
1912
7c58044c
JM
1913#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1914_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1915_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
9a64fbe4 1916
7c58044c 1917#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 1918static void gen_f##name(DisasContext *ctx) \
9a64fbe4 1919{ \
76a66253 1920 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 1921 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
1922 return; \
1923 } \
eb44b959
AJ
1924 /* NIP cannot be restored if the memory exception comes from an helper */ \
1925 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 1926 gen_reset_fpstatus(); \
8e703949
BS
1927 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1928 cpu_fpr[rA(ctx->opcode)], \
af12906f 1929 cpu_fpr[rB(ctx->opcode)]); \
4ecc3190 1930 if (isfloat) { \
8e703949
BS
1931 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1932 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 1933 } \
af12906f
AJ
1934 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1935 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 1936}
7c58044c
JM
1937#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
1938_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1939_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 1940
7c58044c 1941#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
99e300ef 1942static void gen_f##name(DisasContext *ctx) \
9a64fbe4 1943{ \
76a66253 1944 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 1945 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
1946 return; \
1947 } \
eb44b959
AJ
1948 /* NIP cannot be restored if the memory exception comes from an helper */ \
1949 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 1950 gen_reset_fpstatus(); \
8e703949
BS
1951 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1952 cpu_fpr[rA(ctx->opcode)], \
1953 cpu_fpr[rC(ctx->opcode)]); \
4ecc3190 1954 if (isfloat) { \
8e703949
BS
1955 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1956 cpu_fpr[rD(ctx->opcode)]); \
4ecc3190 1957 } \
af12906f
AJ
1958 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1959 set_fprf, Rc(ctx->opcode) != 0); \
9a64fbe4 1960}
7c58044c
JM
1961#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
1962_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1963_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
9a64fbe4 1964
7c58044c 1965#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
99e300ef 1966static void gen_f##name(DisasContext *ctx) \
9a64fbe4 1967{ \
76a66253 1968 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 1969 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
1970 return; \
1971 } \
eb44b959
AJ
1972 /* NIP cannot be restored if the memory exception comes from an helper */ \
1973 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 1974 gen_reset_fpstatus(); \
8e703949
BS
1975 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1976 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
1977 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1978 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
1979}
1980
7c58044c 1981#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
99e300ef 1982static void gen_f##name(DisasContext *ctx) \
9a64fbe4 1983{ \
76a66253 1984 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 1985 gen_exception(ctx, POWERPC_EXCP_FPU); \
3cc62370
FB
1986 return; \
1987 } \
eb44b959
AJ
1988 /* NIP cannot be restored if the memory exception comes from an helper */ \
1989 gen_update_nip(ctx, ctx->nip - 4); \
7c58044c 1990 gen_reset_fpstatus(); \
8e703949
BS
1991 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1992 cpu_fpr[rB(ctx->opcode)]); \
af12906f
AJ
1993 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1994 set_fprf, Rc(ctx->opcode) != 0); \
79aceca5
FB
1995}
1996
9a64fbe4 1997/* fadd - fadds */
7c58044c 1998GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 1999/* fdiv - fdivs */
7c58044c 2000GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
4ecc3190 2001/* fmul - fmuls */
7c58044c 2002GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
79aceca5 2003
d7e4b87e 2004/* fre */
7c58044c 2005GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
d7e4b87e 2006
a750fc0b 2007/* fres */
7c58044c 2008GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
79aceca5 2009
a750fc0b 2010/* frsqrte */
7c58044c
JM
2011GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2012
2013/* frsqrtes */
99e300ef 2014static void gen_frsqrtes(DisasContext *ctx)
7c58044c 2015{
af12906f 2016 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2017 gen_exception(ctx, POWERPC_EXCP_FPU);
af12906f
AJ
2018 return;
2019 }
eb44b959
AJ
2020 /* NIP cannot be restored if the memory exception comes from an helper */
2021 gen_update_nip(ctx, ctx->nip - 4);
af12906f 2022 gen_reset_fpstatus();
8e703949
BS
2023 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env,
2024 cpu_fpr[rB(ctx->opcode)]);
2025 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2026 cpu_fpr[rD(ctx->opcode)]);
af12906f 2027 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
7c58044c 2028}
79aceca5 2029
a750fc0b 2030/* fsel */
7c58044c 2031_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
4ecc3190 2032/* fsub - fsubs */
7c58044c 2033GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
79aceca5 2034/* Optional: */
99e300ef 2035
54623277 2036/* fsqrt */
99e300ef 2037static void gen_fsqrt(DisasContext *ctx)
c7d344af 2038{
76a66253 2039 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2040 gen_exception(ctx, POWERPC_EXCP_FPU);
c7d344af
FB
2041 return;
2042 }
eb44b959
AJ
2043 /* NIP cannot be restored if the memory exception comes from an helper */
2044 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2045 gen_reset_fpstatus();
8e703949
BS
2046 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2047 cpu_fpr[rB(ctx->opcode)]);
af12906f 2048 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
c7d344af 2049}
79aceca5 2050
99e300ef 2051static void gen_fsqrts(DisasContext *ctx)
79aceca5 2052{
76a66253 2053 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2054 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2055 return;
2056 }
eb44b959
AJ
2057 /* NIP cannot be restored if the memory exception comes from an helper */
2058 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2059 gen_reset_fpstatus();
8e703949
BS
2060 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env,
2061 cpu_fpr[rB(ctx->opcode)]);
2062 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env,
2063 cpu_fpr[rD(ctx->opcode)]);
af12906f 2064 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
79aceca5
FB
2065}
2066
2067/*** Floating-Point multiply-and-add ***/
4ecc3190 2068/* fmadd - fmadds */
7c58044c 2069GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
4ecc3190 2070/* fmsub - fmsubs */
7c58044c 2071GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
4ecc3190 2072/* fnmadd - fnmadds */
7c58044c 2073GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
4ecc3190 2074/* fnmsub - fnmsubs */
7c58044c 2075GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
79aceca5
FB
2076
2077/*** Floating-Point round & convert ***/
2078/* fctiw */
7c58044c 2079GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
79aceca5 2080/* fctiwz */
7c58044c 2081GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
79aceca5 2082/* frsp */
7c58044c 2083GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
426613db
JM
2084#if defined(TARGET_PPC64)
2085/* fcfid */
7c58044c 2086GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
426613db 2087/* fctid */
7c58044c 2088GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
426613db 2089/* fctidz */
7c58044c 2090GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
426613db 2091#endif
79aceca5 2092
d7e4b87e 2093/* frin */
7c58044c 2094GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
d7e4b87e 2095/* friz */
7c58044c 2096GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
d7e4b87e 2097/* frip */
7c58044c 2098GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
d7e4b87e 2099/* frim */
7c58044c 2100GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
d7e4b87e 2101
79aceca5 2102/*** Floating-Point compare ***/
99e300ef 2103
54623277 2104/* fcmpo */
99e300ef 2105static void gen_fcmpo(DisasContext *ctx)
79aceca5 2106{
330c483b 2107 TCGv_i32 crf;
76a66253 2108 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2109 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
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);
7c58044c 2114 gen_reset_fpstatus();
9a819377 2115 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2116 gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)],
2117 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2118 tcg_temp_free_i32(crf);
8e703949 2119 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2120}
2121
2122/* fcmpu */
99e300ef 2123static void gen_fcmpu(DisasContext *ctx)
79aceca5 2124{
330c483b 2125 TCGv_i32 crf;
76a66253 2126 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2127 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2128 return;
2129 }
eb44b959
AJ
2130 /* NIP cannot be restored if the memory exception comes from an helper */
2131 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2132 gen_reset_fpstatus();
9a819377 2133 crf = tcg_const_i32(crfD(ctx->opcode));
8e703949
BS
2134 gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)],
2135 cpu_fpr[rB(ctx->opcode)], crf);
330c483b 2136 tcg_temp_free_i32(crf);
8e703949 2137 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2138}
2139
9a64fbe4
FB
2140/*** Floating-point move ***/
2141/* fabs */
7c58044c
JM
2142/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2143GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT);
9a64fbe4
FB
2144
2145/* fmr - fmr. */
7c58044c 2146/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
99e300ef 2147static void gen_fmr(DisasContext *ctx)
9a64fbe4 2148{
76a66253 2149 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2150 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2151 return;
2152 }
af12906f
AJ
2153 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2154 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
9a64fbe4
FB
2155}
2156
2157/* fnabs */
7c58044c
JM
2158/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2159GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT);
9a64fbe4 2160/* fneg */
7c58044c
JM
2161/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2162GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT);
9a64fbe4 2163
79aceca5 2164/*** Floating-Point status & ctrl register ***/
99e300ef 2165
54623277 2166/* mcrfs */
99e300ef 2167static void gen_mcrfs(DisasContext *ctx)
79aceca5 2168{
30304420 2169 TCGv tmp = tcg_temp_new();
7c58044c
JM
2170 int bfa;
2171
76a66253 2172 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2173 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2174 return;
2175 }
7c58044c 2176 bfa = 4 * (7 - crfS(ctx->opcode));
30304420
DG
2177 tcg_gen_shri_tl(tmp, cpu_fpscr, bfa);
2178 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp);
2179 tcg_temp_free(tmp);
e1571908 2180 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
30304420 2181 tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
79aceca5
FB
2182}
2183
2184/* mffs */
99e300ef 2185static void gen_mffs(DisasContext *ctx)
79aceca5 2186{
76a66253 2187 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2188 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2189 return;
2190 }
7c58044c 2191 gen_reset_fpstatus();
30304420 2192 tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
af12906f 2193 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
79aceca5
FB
2194}
2195
2196/* mtfsb0 */
99e300ef 2197static void gen_mtfsb0(DisasContext *ctx)
79aceca5 2198{
fb0eaffc 2199 uint8_t crb;
3b46e624 2200
76a66253 2201 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2202 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2203 return;
2204 }
6e35d524 2205 crb = 31 - crbD(ctx->opcode);
7c58044c 2206 gen_reset_fpstatus();
6e35d524 2207 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
eb44b959
AJ
2208 TCGv_i32 t0;
2209 /* NIP cannot be restored if the memory exception comes from an helper */
2210 gen_update_nip(ctx, ctx->nip - 4);
2211 t0 = tcg_const_i32(crb);
8e703949 2212 gen_helper_fpscr_clrbit(cpu_env, t0);
6e35d524
AJ
2213 tcg_temp_free_i32(t0);
2214 }
7c58044c 2215 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2216 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2217 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c 2218 }
79aceca5
FB
2219}
2220
2221/* mtfsb1 */
99e300ef 2222static void gen_mtfsb1(DisasContext *ctx)
79aceca5 2223{
fb0eaffc 2224 uint8_t crb;
3b46e624 2225
76a66253 2226 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2227 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2228 return;
2229 }
6e35d524 2230 crb = 31 - crbD(ctx->opcode);
7c58044c
JM
2231 gen_reset_fpstatus();
2232 /* XXX: we pretend we can only do IEEE floating-point computations */
af12906f 2233 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
eb44b959
AJ
2234 TCGv_i32 t0;
2235 /* NIP cannot be restored if the memory exception comes from an helper */
2236 gen_update_nip(ctx, ctx->nip - 4);
2237 t0 = tcg_const_i32(crb);
8e703949 2238 gen_helper_fpscr_setbit(cpu_env, t0);
0f2f39c2 2239 tcg_temp_free_i32(t0);
af12906f 2240 }
7c58044c 2241 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2242 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2243 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2244 }
2245 /* We can raise a differed exception */
8e703949 2246 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2247}
2248
2249/* mtfsf */
99e300ef 2250static void gen_mtfsf(DisasContext *ctx)
79aceca5 2251{
0f2f39c2 2252 TCGv_i32 t0;
4911012d 2253 int L = ctx->opcode & 0x02000000;
af12906f 2254
76a66253 2255 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2256 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2257 return;
2258 }
eb44b959
AJ
2259 /* NIP cannot be restored if the memory exception comes from an helper */
2260 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2261 gen_reset_fpstatus();
4911012d
BS
2262 if (L)
2263 t0 = tcg_const_i32(0xff);
2264 else
2265 t0 = tcg_const_i32(FM(ctx->opcode));
8e703949 2266 gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0);
0f2f39c2 2267 tcg_temp_free_i32(t0);
7c58044c 2268 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2269 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2270 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2271 }
2272 /* We can raise a differed exception */
8e703949 2273 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2274}
2275
2276/* mtfsfi */
99e300ef 2277static void gen_mtfsfi(DisasContext *ctx)
79aceca5 2278{
7c58044c 2279 int bf, sh;
0f2f39c2
AJ
2280 TCGv_i64 t0;
2281 TCGv_i32 t1;
7c58044c 2282
76a66253 2283 if (unlikely(!ctx->fpu_enabled)) {
e06fcd75 2284 gen_exception(ctx, POWERPC_EXCP_FPU);
3cc62370
FB
2285 return;
2286 }
7c58044c
JM
2287 bf = crbD(ctx->opcode) >> 2;
2288 sh = 7 - bf;
eb44b959
AJ
2289 /* NIP cannot be restored if the memory exception comes from an helper */
2290 gen_update_nip(ctx, ctx->nip - 4);
7c58044c 2291 gen_reset_fpstatus();
0f2f39c2 2292 t0 = tcg_const_i64(FPIMM(ctx->opcode) << (4 * sh));
af12906f 2293 t1 = tcg_const_i32(1 << sh);
8e703949 2294 gen_helper_store_fpscr(cpu_env, t0, t1);
0f2f39c2
AJ
2295 tcg_temp_free_i64(t0);
2296 tcg_temp_free_i32(t1);
7c58044c 2297 if (unlikely(Rc(ctx->opcode) != 0)) {
30304420
DG
2298 tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr);
2299 tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX);
7c58044c
JM
2300 }
2301 /* We can raise a differed exception */
8e703949 2302 gen_helper_float_check_status(cpu_env);
79aceca5
FB
2303}
2304
76a66253
JM
2305/*** Addressing modes ***/
2306/* Register indirect with immediate index : EA = (rA|0) + SIMM */
636aa200
BS
2307static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2308 target_long maskl)
76a66253
JM
2309{
2310 target_long simm = SIMM(ctx->opcode);
2311
be147d08 2312 simm &= ~maskl;
76db3ba4
AJ
2313 if (rA(ctx->opcode) == 0) {
2314#if defined(TARGET_PPC64)
2315 if (!ctx->sf_mode) {
2316 tcg_gen_movi_tl(EA, (uint32_t)simm);
2317 } else
2318#endif
e2be8d8d 2319 tcg_gen_movi_tl(EA, simm);
76db3ba4 2320 } else if (likely(simm != 0)) {
e2be8d8d 2321 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
76db3ba4
AJ
2322#if defined(TARGET_PPC64)
2323 if (!ctx->sf_mode) {
2324 tcg_gen_ext32u_tl(EA, EA);
2325 }
2326#endif
2327 } else {
2328#if defined(TARGET_PPC64)
2329 if (!ctx->sf_mode) {
2330 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2331 } else
2332#endif
e2be8d8d 2333 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
76db3ba4 2334 }
76a66253
JM
2335}
2336
636aa200 2337static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
76a66253 2338{
76db3ba4
AJ
2339 if (rA(ctx->opcode) == 0) {
2340#if defined(TARGET_PPC64)
2341 if (!ctx->sf_mode) {
2342 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2343 } else
2344#endif
e2be8d8d 2345 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
76db3ba4 2346 } else {
e2be8d8d 2347 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76db3ba4
AJ
2348#if defined(TARGET_PPC64)
2349 if (!ctx->sf_mode) {
2350 tcg_gen_ext32u_tl(EA, EA);
2351 }
2352#endif
2353 }
76a66253
JM
2354}
2355
636aa200 2356static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
76a66253 2357{
76db3ba4 2358 if (rA(ctx->opcode) == 0) {
e2be8d8d 2359 tcg_gen_movi_tl(EA, 0);
76db3ba4
AJ
2360 } else {
2361#if defined(TARGET_PPC64)
2362 if (!ctx->sf_mode) {
2363 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2364 } else
2365#endif
2366 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2367 }
2368}
2369
636aa200
BS
2370static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2371 target_long val)
76db3ba4
AJ
2372{
2373 tcg_gen_addi_tl(ret, arg1, val);
2374#if defined(TARGET_PPC64)
2375 if (!ctx->sf_mode) {
2376 tcg_gen_ext32u_tl(ret, ret);
2377 }
2378#endif
76a66253
JM
2379}
2380
636aa200 2381static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
cf360a32
AJ
2382{
2383 int l1 = gen_new_label();
2384 TCGv t0 = tcg_temp_new();
2385 TCGv_i32 t1, t2;
2386 /* NIP cannot be restored if the memory exception comes from an helper */
2387 gen_update_nip(ctx, ctx->nip - 4);
2388 tcg_gen_andi_tl(t0, EA, mask);
2389 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2390 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2391 t2 = tcg_const_i32(0);
e5f17ac6 2392 gen_helper_raise_exception_err(cpu_env, t1, t2);
cf360a32
AJ
2393 tcg_temp_free_i32(t1);
2394 tcg_temp_free_i32(t2);
2395 gen_set_label(l1);
2396 tcg_temp_free(t0);
2397}
2398
7863667f 2399/*** Integer load ***/
636aa200 2400static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2401{
2402 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2403}
2404
636aa200 2405static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2406{
2407 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2408}
2409
636aa200 2410static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
76db3ba4
AJ
2411{
2412 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2413 if (unlikely(ctx->le_mode)) {
fa3966a3 2414 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2415 }
b61f2753
AJ
2416}
2417
636aa200 2418static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2419{
76db3ba4 2420 if (unlikely(ctx->le_mode)) {
76db3ba4 2421 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
fa3966a3 2422 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2423 tcg_gen_ext16s_tl(arg1, arg1);
76db3ba4
AJ
2424 } else {
2425 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2426 }
b61f2753
AJ
2427}
2428
636aa200 2429static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2430{
76db3ba4
AJ
2431 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2432 if (unlikely(ctx->le_mode)) {
fa3966a3 2433 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2434 }
b61f2753
AJ
2435}
2436
76db3ba4 2437#if defined(TARGET_PPC64)
636aa200 2438static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2439{
a457e7ee 2440 if (unlikely(ctx->le_mode)) {
76db3ba4 2441 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
fa3966a3
AJ
2442 tcg_gen_bswap32_tl(arg1, arg1);
2443 tcg_gen_ext32s_tl(arg1, arg1);
b61f2753 2444 } else
76db3ba4 2445 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
b61f2753 2446}
76db3ba4 2447#endif
b61f2753 2448
636aa200 2449static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2450{
76db3ba4
AJ
2451 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2452 if (unlikely(ctx->le_mode)) {
66896cb8 2453 tcg_gen_bswap64_i64(arg1, arg1);
76db3ba4 2454 }
b61f2753
AJ
2455}
2456
636aa200 2457static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2458{
76db3ba4 2459 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2460}
2461
636aa200 2462static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2463{
76db3ba4 2464 if (unlikely(ctx->le_mode)) {
76db3ba4
AJ
2465 TCGv t0 = tcg_temp_new();
2466 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2467 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2468 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2469 tcg_temp_free(t0);
76db3ba4
AJ
2470 } else {
2471 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2472 }
b61f2753
AJ
2473}
2474
636aa200 2475static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2476{
76db3ba4 2477 if (unlikely(ctx->le_mode)) {
fa3966a3
AJ
2478 TCGv t0 = tcg_temp_new();
2479 tcg_gen_ext32u_tl(t0, arg1);
2480 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2481 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2482 tcg_temp_free(t0);
76db3ba4
AJ
2483 } else {
2484 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2485 }
b61f2753
AJ
2486}
2487
636aa200 2488static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
b61f2753 2489{
76db3ba4 2490 if (unlikely(ctx->le_mode)) {
a7812ae4 2491 TCGv_i64 t0 = tcg_temp_new_i64();
66896cb8 2492 tcg_gen_bswap64_i64(t0, arg1);
76db3ba4 2493 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
a7812ae4 2494 tcg_temp_free_i64(t0);
b61f2753 2495 } else
76db3ba4 2496 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
b61f2753
AJ
2497}
2498
0c8aacd4 2499#define GEN_LD(name, ldop, opc, type) \
99e300ef 2500static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2501{ \
76db3ba4
AJ
2502 TCGv EA; \
2503 gen_set_access_type(ctx, ACCESS_INT); \
2504 EA = tcg_temp_new(); \
2505 gen_addr_imm_index(ctx, EA, 0); \
2506 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2507 tcg_temp_free(EA); \
79aceca5
FB
2508}
2509
0c8aacd4 2510#define GEN_LDU(name, ldop, opc, type) \
99e300ef 2511static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 2512{ \
b61f2753 2513 TCGv EA; \
76a66253
JM
2514 if (unlikely(rA(ctx->opcode) == 0 || \
2515 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2516 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2517 return; \
9a64fbe4 2518 } \
76db3ba4 2519 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2520 EA = tcg_temp_new(); \
9d53c753 2521 if (type == PPC_64B) \
76db3ba4 2522 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2523 else \
76db3ba4
AJ
2524 gen_addr_imm_index(ctx, EA, 0); \
2525 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2526 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2527 tcg_temp_free(EA); \
79aceca5
FB
2528}
2529
0c8aacd4 2530#define GEN_LDUX(name, ldop, opc2, opc3, type) \
99e300ef 2531static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2532{ \
b61f2753 2533 TCGv EA; \
76a66253
JM
2534 if (unlikely(rA(ctx->opcode) == 0 || \
2535 rA(ctx->opcode) == rD(ctx->opcode))) { \
e06fcd75 2536 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2537 return; \
9a64fbe4 2538 } \
76db3ba4 2539 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2540 EA = tcg_temp_new(); \
76db3ba4
AJ
2541 gen_addr_reg_index(ctx, EA); \
2542 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753
AJ
2543 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2544 tcg_temp_free(EA); \
79aceca5
FB
2545}
2546
cd6e9320 2547#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
99e300ef 2548static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2549{ \
76db3ba4
AJ
2550 TCGv EA; \
2551 gen_set_access_type(ctx, ACCESS_INT); \
2552 EA = tcg_temp_new(); \
2553 gen_addr_reg_index(ctx, EA); \
2554 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
b61f2753 2555 tcg_temp_free(EA); \
79aceca5 2556}
cd6e9320
TH
2557#define GEN_LDX(name, ldop, opc2, opc3, type) \
2558 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
79aceca5 2559
0c8aacd4
AJ
2560#define GEN_LDS(name, ldop, op, type) \
2561GEN_LD(name, ldop, op | 0x20, type); \
2562GEN_LDU(name, ldop, op | 0x21, type); \
2563GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2564GEN_LDX(name, ldop, 0x17, op | 0x00, type)
79aceca5
FB
2565
2566/* lbz lbzu lbzux lbzx */
0c8aacd4 2567GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
79aceca5 2568/* lha lhau lhaux lhax */
0c8aacd4 2569GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
79aceca5 2570/* lhz lhzu lhzux lhzx */
0c8aacd4 2571GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
79aceca5 2572/* lwz lwzu lwzux lwzx */
0c8aacd4 2573GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
d9bce9d9 2574#if defined(TARGET_PPC64)
d9bce9d9 2575/* lwaux */
0c8aacd4 2576GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
d9bce9d9 2577/* lwax */
0c8aacd4 2578GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
d9bce9d9 2579/* ldux */
0c8aacd4 2580GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
d9bce9d9 2581/* ldx */
0c8aacd4 2582GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
99e300ef
BS
2583
2584static void gen_ld(DisasContext *ctx)
d9bce9d9 2585{
b61f2753 2586 TCGv EA;
d9bce9d9
JM
2587 if (Rc(ctx->opcode)) {
2588 if (unlikely(rA(ctx->opcode) == 0 ||
2589 rA(ctx->opcode) == rD(ctx->opcode))) {
e06fcd75 2590 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2591 return;
2592 }
2593 }
76db3ba4 2594 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2595 EA = tcg_temp_new();
76db3ba4 2596 gen_addr_imm_index(ctx, EA, 0x03);
d9bce9d9
JM
2597 if (ctx->opcode & 0x02) {
2598 /* lwa (lwau is undefined) */
76db3ba4 2599 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9
JM
2600 } else {
2601 /* ld - ldu */
76db3ba4 2602 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
d9bce9d9 2603 }
d9bce9d9 2604 if (Rc(ctx->opcode))
b61f2753
AJ
2605 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2606 tcg_temp_free(EA);
d9bce9d9 2607}
99e300ef 2608
54623277 2609/* lq */
99e300ef 2610static void gen_lq(DisasContext *ctx)
be147d08
JM
2611{
2612#if defined(CONFIG_USER_ONLY)
e06fcd75 2613 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2614#else
2615 int ra, rd;
b61f2753 2616 TCGv EA;
be147d08
JM
2617
2618 /* Restore CPU state */
76db3ba4 2619 if (unlikely(ctx->mem_idx == 0)) {
e06fcd75 2620 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2621 return;
2622 }
2623 ra = rA(ctx->opcode);
2624 rd = rD(ctx->opcode);
2625 if (unlikely((rd & 1) || rd == ra)) {
e06fcd75 2626 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2627 return;
2628 }
76db3ba4 2629 if (unlikely(ctx->le_mode)) {
be147d08 2630 /* Little-endian mode is not handled */
e06fcd75 2631 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
be147d08
JM
2632 return;
2633 }
76db3ba4 2634 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2635 EA = tcg_temp_new();
76db3ba4
AJ
2636 gen_addr_imm_index(ctx, EA, 0x0F);
2637 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2638 gen_addr_add(ctx, EA, EA, 8);
2639 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
b61f2753 2640 tcg_temp_free(EA);
be147d08
JM
2641#endif
2642}
d9bce9d9 2643#endif
79aceca5
FB
2644
2645/*** Integer store ***/
0c8aacd4 2646#define GEN_ST(name, stop, opc, type) \
99e300ef 2647static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 2648{ \
76db3ba4
AJ
2649 TCGv EA; \
2650 gen_set_access_type(ctx, ACCESS_INT); \
2651 EA = tcg_temp_new(); \
2652 gen_addr_imm_index(ctx, EA, 0); \
2653 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2654 tcg_temp_free(EA); \
79aceca5
FB
2655}
2656
0c8aacd4 2657#define GEN_STU(name, stop, opc, type) \
99e300ef 2658static void glue(gen_, stop##u)(DisasContext *ctx) \
79aceca5 2659{ \
b61f2753 2660 TCGv EA; \
76a66253 2661 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2662 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2663 return; \
9a64fbe4 2664 } \
76db3ba4 2665 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2666 EA = tcg_temp_new(); \
9d53c753 2667 if (type == PPC_64B) \
76db3ba4 2668 gen_addr_imm_index(ctx, EA, 0x03); \
9d53c753 2669 else \
76db3ba4
AJ
2670 gen_addr_imm_index(ctx, EA, 0); \
2671 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2672 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2673 tcg_temp_free(EA); \
79aceca5
FB
2674}
2675
0c8aacd4 2676#define GEN_STUX(name, stop, opc2, opc3, type) \
99e300ef 2677static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 2678{ \
b61f2753 2679 TCGv EA; \
76a66253 2680 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 2681 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 2682 return; \
9a64fbe4 2683 } \
76db3ba4 2684 gen_set_access_type(ctx, ACCESS_INT); \
0c8aacd4 2685 EA = tcg_temp_new(); \
76db3ba4
AJ
2686 gen_addr_reg_index(ctx, EA); \
2687 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753
AJ
2688 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2689 tcg_temp_free(EA); \
79aceca5
FB
2690}
2691
cd6e9320
TH
2692#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2693static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 2694{ \
76db3ba4
AJ
2695 TCGv EA; \
2696 gen_set_access_type(ctx, ACCESS_INT); \
2697 EA = tcg_temp_new(); \
2698 gen_addr_reg_index(ctx, EA); \
2699 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
b61f2753 2700 tcg_temp_free(EA); \
79aceca5 2701}
cd6e9320
TH
2702#define GEN_STX(name, stop, opc2, opc3, type) \
2703 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
79aceca5 2704
0c8aacd4
AJ
2705#define GEN_STS(name, stop, op, type) \
2706GEN_ST(name, stop, op | 0x20, type); \
2707GEN_STU(name, stop, op | 0x21, type); \
2708GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2709GEN_STX(name, stop, 0x17, op | 0x00, type)
79aceca5
FB
2710
2711/* stb stbu stbux stbx */
0c8aacd4 2712GEN_STS(stb, st8, 0x06, PPC_INTEGER);
79aceca5 2713/* sth sthu sthux sthx */
0c8aacd4 2714GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
79aceca5 2715/* stw stwu stwux stwx */
0c8aacd4 2716GEN_STS(stw, st32, 0x04, PPC_INTEGER);
d9bce9d9 2717#if defined(TARGET_PPC64)
0c8aacd4
AJ
2718GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2719GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
99e300ef
BS
2720
2721static void gen_std(DisasContext *ctx)
d9bce9d9 2722{
be147d08 2723 int rs;
b61f2753 2724 TCGv EA;
be147d08
JM
2725
2726 rs = rS(ctx->opcode);
2727 if ((ctx->opcode & 0x3) == 0x2) {
2728#if defined(CONFIG_USER_ONLY)
e06fcd75 2729 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2730#else
2731 /* stq */
76db3ba4 2732 if (unlikely(ctx->mem_idx == 0)) {
e06fcd75 2733 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
2734 return;
2735 }
2736 if (unlikely(rs & 1)) {
e06fcd75 2737 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
d9bce9d9
JM
2738 return;
2739 }
76db3ba4 2740 if (unlikely(ctx->le_mode)) {
be147d08 2741 /* Little-endian mode is not handled */
e06fcd75 2742 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
be147d08
JM
2743 return;
2744 }
76db3ba4 2745 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2746 EA = tcg_temp_new();
76db3ba4
AJ
2747 gen_addr_imm_index(ctx, EA, 0x03);
2748 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
2749 gen_addr_add(ctx, EA, EA, 8);
2750 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
b61f2753 2751 tcg_temp_free(EA);
be147d08
JM
2752#endif
2753 } else {
2754 /* std / stdu */
2755 if (Rc(ctx->opcode)) {
2756 if (unlikely(rA(ctx->opcode) == 0)) {
e06fcd75 2757 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
be147d08
JM
2758 return;
2759 }
2760 }
76db3ba4 2761 gen_set_access_type(ctx, ACCESS_INT);
a7812ae4 2762 EA = tcg_temp_new();
76db3ba4
AJ
2763 gen_addr_imm_index(ctx, EA, 0x03);
2764 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
be147d08 2765 if (Rc(ctx->opcode))
b61f2753
AJ
2766 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2767 tcg_temp_free(EA);
d9bce9d9 2768 }
d9bce9d9
JM
2769}
2770#endif
79aceca5
FB
2771/*** Integer load and store with byte reverse ***/
2772/* lhbrx */
86178a57 2773static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2774{
76db3ba4
AJ
2775 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2776 if (likely(!ctx->le_mode)) {
fa3966a3 2777 tcg_gen_bswap16_tl(arg1, arg1);
76db3ba4 2778 }
b61f2753 2779}
0c8aacd4 2780GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
b61f2753 2781
79aceca5 2782/* lwbrx */
86178a57 2783static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2784{
76db3ba4
AJ
2785 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2786 if (likely(!ctx->le_mode)) {
fa3966a3 2787 tcg_gen_bswap32_tl(arg1, arg1);
76db3ba4 2788 }
b61f2753 2789}
0c8aacd4 2790GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
b61f2753 2791
cd6e9320
TH
2792#if defined(TARGET_PPC64)
2793/* ldbrx */
2794static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
2795{
2796 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2797 if (likely(!ctx->le_mode)) {
2798 tcg_gen_bswap64_tl(arg1, arg1);
2799 }
2800}
2801GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX);
2802#endif /* TARGET_PPC64 */
2803
79aceca5 2804/* sthbrx */
86178a57 2805static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2806{
76db3ba4 2807 if (likely(!ctx->le_mode)) {
76db3ba4
AJ
2808 TCGv t0 = tcg_temp_new();
2809 tcg_gen_ext16u_tl(t0, arg1);
fa3966a3 2810 tcg_gen_bswap16_tl(t0, t0);
76db3ba4
AJ
2811 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2812 tcg_temp_free(t0);
76db3ba4
AJ
2813 } else {
2814 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2815 }
b61f2753 2816}
0c8aacd4 2817GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
b61f2753 2818
79aceca5 2819/* stwbrx */
86178a57 2820static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
b61f2753 2821{
76db3ba4 2822 if (likely(!ctx->le_mode)) {
fa3966a3
AJ
2823 TCGv t0 = tcg_temp_new();
2824 tcg_gen_ext32u_tl(t0, arg1);
2825 tcg_gen_bswap32_tl(t0, t0);
76db3ba4
AJ
2826 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2827 tcg_temp_free(t0);
76db3ba4
AJ
2828 } else {
2829 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2830 }
b61f2753 2831}
0c8aacd4 2832GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
79aceca5 2833
cd6e9320
TH
2834#if defined(TARGET_PPC64)
2835/* stdbrx */
2836static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2)
2837{
2838 if (likely(!ctx->le_mode)) {
2839 TCGv t0 = tcg_temp_new();
2840 tcg_gen_bswap64_tl(t0, arg1);
2841 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
2842 tcg_temp_free(t0);
2843 } else {
2844 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
2845 }
2846}
2847GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX);
2848#endif /* TARGET_PPC64 */
2849
79aceca5 2850/*** Integer load and store multiple ***/
99e300ef 2851
54623277 2852/* lmw */
99e300ef 2853static void gen_lmw(DisasContext *ctx)
79aceca5 2854{
76db3ba4
AJ
2855 TCGv t0;
2856 TCGv_i32 t1;
2857 gen_set_access_type(ctx, ACCESS_INT);
76a66253 2858 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 2859 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
2860 t0 = tcg_temp_new();
2861 t1 = tcg_const_i32(rD(ctx->opcode));
2862 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 2863 gen_helper_lmw(cpu_env, t0, t1);
ff4a62cd
AJ
2864 tcg_temp_free(t0);
2865 tcg_temp_free_i32(t1);
79aceca5
FB
2866}
2867
2868/* stmw */
99e300ef 2869static void gen_stmw(DisasContext *ctx)
79aceca5 2870{
76db3ba4
AJ
2871 TCGv t0;
2872 TCGv_i32 t1;
2873 gen_set_access_type(ctx, ACCESS_INT);
76a66253 2874 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 2875 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
2876 t0 = tcg_temp_new();
2877 t1 = tcg_const_i32(rS(ctx->opcode));
2878 gen_addr_imm_index(ctx, t0, 0);
2f5a189c 2879 gen_helper_stmw(cpu_env, t0, t1);
ff4a62cd
AJ
2880 tcg_temp_free(t0);
2881 tcg_temp_free_i32(t1);
79aceca5
FB
2882}
2883
2884/*** Integer load and store strings ***/
54623277 2885
79aceca5 2886/* lswi */
3fc6c082 2887/* PowerPC32 specification says we must generate an exception if
9a64fbe4
FB
2888 * rA is in the range of registers to be loaded.
2889 * In an other hand, IBM says this is valid, but rA won't be loaded.
2890 * For now, I'll follow the spec...
2891 */
99e300ef 2892static void gen_lswi(DisasContext *ctx)
79aceca5 2893{
dfbc799d
AJ
2894 TCGv t0;
2895 TCGv_i32 t1, t2;
79aceca5
FB
2896 int nb = NB(ctx->opcode);
2897 int start = rD(ctx->opcode);
9a64fbe4 2898 int ra = rA(ctx->opcode);
79aceca5
FB
2899 int nr;
2900
2901 if (nb == 0)
2902 nb = 32;
2903 nr = nb / 4;
76a66253
JM
2904 if (unlikely(((start + nr) > 32 &&
2905 start <= ra && (start + nr - 32) > ra) ||
2906 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
e06fcd75 2907 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
9fddaa0c 2908 return;
297d8e62 2909 }
76db3ba4 2910 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 2911 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 2912 gen_update_nip(ctx, ctx->nip - 4);
dfbc799d 2913 t0 = tcg_temp_new();
76db3ba4 2914 gen_addr_register(ctx, t0);
dfbc799d
AJ
2915 t1 = tcg_const_i32(nb);
2916 t2 = tcg_const_i32(start);
2f5a189c 2917 gen_helper_lsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
2918 tcg_temp_free(t0);
2919 tcg_temp_free_i32(t1);
2920 tcg_temp_free_i32(t2);
79aceca5
FB
2921}
2922
2923/* lswx */
99e300ef 2924static void gen_lswx(DisasContext *ctx)
79aceca5 2925{
76db3ba4
AJ
2926 TCGv t0;
2927 TCGv_i32 t1, t2, t3;
2928 gen_set_access_type(ctx, ACCESS_INT);
76a66253 2929 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 2930 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
2931 t0 = tcg_temp_new();
2932 gen_addr_reg_index(ctx, t0);
2933 t1 = tcg_const_i32(rD(ctx->opcode));
2934 t2 = tcg_const_i32(rA(ctx->opcode));
2935 t3 = tcg_const_i32(rB(ctx->opcode));
2f5a189c 2936 gen_helper_lswx(cpu_env, t0, t1, t2, t3);
dfbc799d
AJ
2937 tcg_temp_free(t0);
2938 tcg_temp_free_i32(t1);
2939 tcg_temp_free_i32(t2);
2940 tcg_temp_free_i32(t3);
79aceca5
FB
2941}
2942
2943/* stswi */
99e300ef 2944static void gen_stswi(DisasContext *ctx)
79aceca5 2945{
76db3ba4
AJ
2946 TCGv t0;
2947 TCGv_i32 t1, t2;
4b3686fa 2948 int nb = NB(ctx->opcode);
76db3ba4 2949 gen_set_access_type(ctx, ACCESS_INT);
76a66253 2950 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 2951 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
2952 t0 = tcg_temp_new();
2953 gen_addr_register(ctx, t0);
4b3686fa
FB
2954 if (nb == 0)
2955 nb = 32;
dfbc799d 2956 t1 = tcg_const_i32(nb);
76db3ba4 2957 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 2958 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
2959 tcg_temp_free(t0);
2960 tcg_temp_free_i32(t1);
2961 tcg_temp_free_i32(t2);
79aceca5
FB
2962}
2963
2964/* stswx */
99e300ef 2965static void gen_stswx(DisasContext *ctx)
79aceca5 2966{
76db3ba4
AJ
2967 TCGv t0;
2968 TCGv_i32 t1, t2;
2969 gen_set_access_type(ctx, ACCESS_INT);
8dd4983c 2970 /* NIP cannot be restored if the memory exception comes from an helper */
5fafdf24 2971 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
2972 t0 = tcg_temp_new();
2973 gen_addr_reg_index(ctx, t0);
2974 t1 = tcg_temp_new_i32();
dfbc799d
AJ
2975 tcg_gen_trunc_tl_i32(t1, cpu_xer);
2976 tcg_gen_andi_i32(t1, t1, 0x7F);
76db3ba4 2977 t2 = tcg_const_i32(rS(ctx->opcode));
2f5a189c 2978 gen_helper_stsw(cpu_env, t0, t1, t2);
dfbc799d
AJ
2979 tcg_temp_free(t0);
2980 tcg_temp_free_i32(t1);
2981 tcg_temp_free_i32(t2);
79aceca5
FB
2982}
2983
2984/*** Memory synchronisation ***/
2985/* eieio */
99e300ef 2986static void gen_eieio(DisasContext *ctx)
79aceca5 2987{
79aceca5
FB
2988}
2989
2990/* isync */
99e300ef 2991static void gen_isync(DisasContext *ctx)
79aceca5 2992{
e06fcd75 2993 gen_stop_exception(ctx);
79aceca5
FB
2994}
2995
111bfab3 2996/* lwarx */
99e300ef 2997static void gen_lwarx(DisasContext *ctx)
79aceca5 2998{
76db3ba4 2999 TCGv t0;
18b21a2f 3000 TCGv gpr = cpu_gpr[rD(ctx->opcode)];
76db3ba4
AJ
3001 gen_set_access_type(ctx, ACCESS_RES);
3002 t0 = tcg_temp_local_new();
3003 gen_addr_reg_index(ctx, t0);
cf360a32 3004 gen_check_align(ctx, t0, 0x03);
18b21a2f 3005 gen_qemu_ld32u(ctx, gpr, t0);
cf360a32 3006 tcg_gen_mov_tl(cpu_reserve, t0);
1328c2bf 3007 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val));
cf360a32 3008 tcg_temp_free(t0);
79aceca5
FB
3009}
3010
4425265b
NF
3011#if defined(CONFIG_USER_ONLY)
3012static void gen_conditional_store (DisasContext *ctx, TCGv EA,
3013 int reg, int size)
3014{
3015 TCGv t0 = tcg_temp_new();
3016 uint32_t save_exception = ctx->exception;
3017
1328c2bf 3018 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea));
4425265b 3019 tcg_gen_movi_tl(t0, (size << 5) | reg);
1328c2bf 3020 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info));
4425265b
NF
3021 tcg_temp_free(t0);
3022 gen_update_nip(ctx, ctx->nip-4);
3023 ctx->exception = POWERPC_EXCP_BRANCH;
3024 gen_exception(ctx, POWERPC_EXCP_STCX);
3025 ctx->exception = save_exception;
3026}
3027#endif
3028
79aceca5 3029/* stwcx. */
e8eaa2c0 3030static void gen_stwcx_(DisasContext *ctx)
79aceca5 3031{
76db3ba4
AJ
3032 TCGv t0;
3033 gen_set_access_type(ctx, ACCESS_RES);
3034 t0 = tcg_temp_local_new();
3035 gen_addr_reg_index(ctx, t0);
cf360a32 3036 gen_check_align(ctx, t0, 0x03);
4425265b
NF
3037#if defined(CONFIG_USER_ONLY)
3038 gen_conditional_store(ctx, t0, rS(ctx->opcode), 4);
3039#else
3040 {
3041 int l1;
3042
da91a00f 3043 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
4425265b
NF
3044 l1 = gen_new_label();
3045 tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3046 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3047 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3048 gen_set_label(l1);
3049 tcg_gen_movi_tl(cpu_reserve, -1);
3050 }
3051#endif
cf360a32 3052 tcg_temp_free(t0);
79aceca5
FB
3053}
3054
426613db 3055#if defined(TARGET_PPC64)
426613db 3056/* ldarx */
99e300ef 3057static void gen_ldarx(DisasContext *ctx)
426613db 3058{
76db3ba4 3059 TCGv t0;
18b21a2f 3060 TCGv gpr = cpu_gpr[rD(ctx->opcode)];
76db3ba4
AJ
3061 gen_set_access_type(ctx, ACCESS_RES);
3062 t0 = tcg_temp_local_new();
3063 gen_addr_reg_index(ctx, t0);
cf360a32 3064 gen_check_align(ctx, t0, 0x07);
18b21a2f 3065 gen_qemu_ld64(ctx, gpr, t0);
cf360a32 3066 tcg_gen_mov_tl(cpu_reserve, t0);
1328c2bf 3067 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val));
cf360a32 3068 tcg_temp_free(t0);
426613db
JM
3069}
3070
3071/* stdcx. */
e8eaa2c0 3072static void gen_stdcx_(DisasContext *ctx)
426613db 3073{
76db3ba4
AJ
3074 TCGv t0;
3075 gen_set_access_type(ctx, ACCESS_RES);
3076 t0 = tcg_temp_local_new();
3077 gen_addr_reg_index(ctx, t0);
cf360a32 3078 gen_check_align(ctx, t0, 0x07);
4425265b
NF
3079#if defined(CONFIG_USER_ONLY)
3080 gen_conditional_store(ctx, t0, rS(ctx->opcode), 8);
3081#else
3082 {
3083 int l1;
da91a00f 3084 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
4425265b
NF
3085 l1 = gen_new_label();
3086 tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3087 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3088 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3089 gen_set_label(l1);
3090 tcg_gen_movi_tl(cpu_reserve, -1);
3091 }
3092#endif
cf360a32 3093 tcg_temp_free(t0);
426613db
JM
3094}
3095#endif /* defined(TARGET_PPC64) */
3096
79aceca5 3097/* sync */
99e300ef 3098static void gen_sync(DisasContext *ctx)
79aceca5 3099{
79aceca5
FB
3100}
3101
0db1b20e 3102/* wait */
99e300ef 3103static void gen_wait(DisasContext *ctx)
0db1b20e 3104{
931ff272 3105 TCGv_i32 t0 = tcg_temp_new_i32();
1328c2bf 3106 tcg_gen_st_i32(t0, cpu_env, offsetof(CPUPPCState, halted));
931ff272 3107 tcg_temp_free_i32(t0);
0db1b20e 3108 /* Stop translation, as the CPU is supposed to sleep from now */
e06fcd75 3109 gen_exception_err(ctx, EXCP_HLT, 1);
0db1b20e
JM
3110}
3111
79aceca5 3112/*** Floating-point load ***/
a0d7d5a7 3113#define GEN_LDF(name, ldop, opc, type) \
99e300ef 3114static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3115{ \
a0d7d5a7 3116 TCGv EA; \
76a66253 3117 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3118 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3119 return; \
3120 } \
76db3ba4 3121 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3122 EA = tcg_temp_new(); \
76db3ba4
AJ
3123 gen_addr_imm_index(ctx, EA, 0); \
3124 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3125 tcg_temp_free(EA); \
79aceca5
FB
3126}
3127
a0d7d5a7 3128#define GEN_LDUF(name, ldop, opc, type) \
99e300ef 3129static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3130{ \
a0d7d5a7 3131 TCGv EA; \
76a66253 3132 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3133 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3134 return; \
3135 } \
76a66253 3136 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3137 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3138 return; \
9a64fbe4 3139 } \
76db3ba4 3140 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3141 EA = tcg_temp_new(); \
76db3ba4
AJ
3142 gen_addr_imm_index(ctx, EA, 0); \
3143 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3144 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3145 tcg_temp_free(EA); \
79aceca5
FB
3146}
3147
a0d7d5a7 3148#define GEN_LDUXF(name, ldop, opc, type) \
99e300ef 3149static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3150{ \
a0d7d5a7 3151 TCGv EA; \
76a66253 3152 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3153 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3154 return; \
3155 } \
76a66253 3156 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3157 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3158 return; \
9a64fbe4 3159 } \
76db3ba4 3160 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3161 EA = tcg_temp_new(); \
76db3ba4
AJ
3162 gen_addr_reg_index(ctx, EA); \
3163 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7
AJ
3164 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3165 tcg_temp_free(EA); \
79aceca5
FB
3166}
3167
a0d7d5a7 3168#define GEN_LDXF(name, ldop, opc2, opc3, type) \
99e300ef 3169static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3170{ \
a0d7d5a7 3171 TCGv EA; \
76a66253 3172 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3173 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3174 return; \
3175 } \
76db3ba4 3176 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3177 EA = tcg_temp_new(); \
76db3ba4
AJ
3178 gen_addr_reg_index(ctx, EA); \
3179 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
a0d7d5a7 3180 tcg_temp_free(EA); \
79aceca5
FB
3181}
3182
a0d7d5a7
AJ
3183#define GEN_LDFS(name, ldop, op, type) \
3184GEN_LDF(name, ldop, op | 0x20, type); \
3185GEN_LDUF(name, ldop, op | 0x21, type); \
3186GEN_LDUXF(name, ldop, op | 0x01, type); \
3187GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3188
636aa200 3189static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3190{
3191 TCGv t0 = tcg_temp_new();
3192 TCGv_i32 t1 = tcg_temp_new_i32();
76db3ba4 3193 gen_qemu_ld32u(ctx, t0, arg2);
a0d7d5a7
AJ
3194 tcg_gen_trunc_tl_i32(t1, t0);
3195 tcg_temp_free(t0);
8e703949 3196 gen_helper_float32_to_float64(arg1, cpu_env, t1);
a0d7d5a7
AJ
3197 tcg_temp_free_i32(t1);
3198}
79aceca5 3199
a0d7d5a7
AJ
3200 /* lfd lfdu lfdux lfdx */
3201GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3202 /* lfs lfsu lfsux lfsx */
3203GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
79aceca5
FB
3204
3205/*** Floating-point store ***/
a0d7d5a7 3206#define GEN_STF(name, stop, opc, type) \
99e300ef 3207static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3208{ \
a0d7d5a7 3209 TCGv EA; \
76a66253 3210 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3211 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3212 return; \
3213 } \
76db3ba4 3214 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3215 EA = tcg_temp_new(); \
76db3ba4
AJ
3216 gen_addr_imm_index(ctx, EA, 0); \
3217 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3218 tcg_temp_free(EA); \
79aceca5
FB
3219}
3220
a0d7d5a7 3221#define GEN_STUF(name, stop, opc, type) \
99e300ef 3222static void glue(gen_, name##u)(DisasContext *ctx) \
79aceca5 3223{ \
a0d7d5a7 3224 TCGv EA; \
76a66253 3225 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3226 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3227 return; \
3228 } \
76a66253 3229 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3230 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3231 return; \
9a64fbe4 3232 } \
76db3ba4 3233 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3234 EA = tcg_temp_new(); \
76db3ba4
AJ
3235 gen_addr_imm_index(ctx, EA, 0); \
3236 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3237 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3238 tcg_temp_free(EA); \
79aceca5
FB
3239}
3240
a0d7d5a7 3241#define GEN_STUXF(name, stop, opc, type) \
99e300ef 3242static void glue(gen_, name##ux)(DisasContext *ctx) \
79aceca5 3243{ \
a0d7d5a7 3244 TCGv EA; \
76a66253 3245 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3246 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3247 return; \
3248 } \
76a66253 3249 if (unlikely(rA(ctx->opcode) == 0)) { \
e06fcd75 3250 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
9fddaa0c 3251 return; \
9a64fbe4 3252 } \
76db3ba4 3253 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3254 EA = tcg_temp_new(); \
76db3ba4
AJ
3255 gen_addr_reg_index(ctx, EA); \
3256 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7
AJ
3257 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3258 tcg_temp_free(EA); \
79aceca5
FB
3259}
3260
a0d7d5a7 3261#define GEN_STXF(name, stop, opc2, opc3, type) \
99e300ef 3262static void glue(gen_, name##x)(DisasContext *ctx) \
79aceca5 3263{ \
a0d7d5a7 3264 TCGv EA; \
76a66253 3265 if (unlikely(!ctx->fpu_enabled)) { \
e06fcd75 3266 gen_exception(ctx, POWERPC_EXCP_FPU); \
4ecc3190
FB
3267 return; \
3268 } \
76db3ba4 3269 gen_set_access_type(ctx, ACCESS_FLOAT); \
a0d7d5a7 3270 EA = tcg_temp_new(); \
76db3ba4
AJ
3271 gen_addr_reg_index(ctx, EA); \
3272 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
a0d7d5a7 3273 tcg_temp_free(EA); \
79aceca5
FB
3274}
3275
a0d7d5a7
AJ
3276#define GEN_STFS(name, stop, op, type) \
3277GEN_STF(name, stop, op | 0x20, type); \
3278GEN_STUF(name, stop, op | 0x21, type); \
3279GEN_STUXF(name, stop, op | 0x01, type); \
3280GEN_STXF(name, stop, 0x17, op | 0x00, type)
3281
636aa200 3282static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3283{
3284 TCGv_i32 t0 = tcg_temp_new_i32();
3285 TCGv t1 = tcg_temp_new();
8e703949 3286 gen_helper_float64_to_float32(t0, cpu_env, arg1);
a0d7d5a7
AJ
3287 tcg_gen_extu_i32_tl(t1, t0);
3288 tcg_temp_free_i32(t0);
76db3ba4 3289 gen_qemu_st32(ctx, t1, arg2);
a0d7d5a7
AJ
3290 tcg_temp_free(t1);
3291}
79aceca5
FB
3292
3293/* stfd stfdu stfdux stfdx */
a0d7d5a7 3294GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
79aceca5 3295/* stfs stfsu stfsux stfsx */
a0d7d5a7 3296GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
79aceca5
FB
3297
3298/* Optional: */
636aa200 3299static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
a0d7d5a7
AJ
3300{
3301 TCGv t0 = tcg_temp_new();
3302 tcg_gen_trunc_i64_tl(t0, arg1),
76db3ba4 3303 gen_qemu_st32(ctx, t0, arg2);
a0d7d5a7
AJ
3304 tcg_temp_free(t0);
3305}
79aceca5 3306/* stfiwx */
a0d7d5a7 3307GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
79aceca5 3308
697ab892
DG
3309static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip)
3310{
3311#if defined(TARGET_PPC64)
3312 if (ctx->has_cfar)
3313 tcg_gen_movi_tl(cpu_cfar, nip);
3314#endif
3315}
3316
79aceca5 3317/*** Branch ***/
636aa200 3318static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
c1942362
FB
3319{
3320 TranslationBlock *tb;
3321 tb = ctx->tb;
a2ffb812
AJ
3322#if defined(TARGET_PPC64)
3323 if (!ctx->sf_mode)
3324 dest = (uint32_t) dest;
3325#endif
57fec1fe 3326 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
8cbcb4fa 3327 likely(!ctx->singlestep_enabled)) {
57fec1fe 3328 tcg_gen_goto_tb(n);
a2ffb812 3329 tcg_gen_movi_tl(cpu_nip, dest & ~3);
4b4a72e5 3330 tcg_gen_exit_tb((tcg_target_long)tb + n);
c1942362 3331 } else {
a2ffb812 3332 tcg_gen_movi_tl(cpu_nip, dest & ~3);
8cbcb4fa
AJ
3333 if (unlikely(ctx->singlestep_enabled)) {
3334 if ((ctx->singlestep_enabled &
bdc4e053 3335 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
f0cc4aa8
JG
3336 (ctx->exception == POWERPC_EXCP_BRANCH ||
3337 ctx->exception == POWERPC_EXCP_TRACE)) {
8cbcb4fa
AJ
3338 target_ulong tmp = ctx->nip;
3339 ctx->nip = dest;
e06fcd75 3340 gen_exception(ctx, POWERPC_EXCP_TRACE);
8cbcb4fa
AJ
3341 ctx->nip = tmp;
3342 }
3343 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
e06fcd75 3344 gen_debug_exception(ctx);
8cbcb4fa
AJ
3345 }
3346 }
57fec1fe 3347 tcg_gen_exit_tb(0);
c1942362 3348 }
c53be334
FB
3349}
3350
636aa200 3351static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
e1833e1f
JM
3352{
3353#if defined(TARGET_PPC64)
a2ffb812
AJ
3354 if (ctx->sf_mode == 0)
3355 tcg_gen_movi_tl(cpu_lr, (uint32_t)nip);
e1833e1f
JM
3356 else
3357#endif
a2ffb812 3358 tcg_gen_movi_tl(cpu_lr, nip);
e1833e1f
JM
3359}
3360
79aceca5 3361/* b ba bl bla */
99e300ef 3362static void gen_b(DisasContext *ctx)
79aceca5 3363{
76a66253 3364 target_ulong li, target;
38a64f9d 3365
8cbcb4fa 3366 ctx->exception = POWERPC_EXCP_BRANCH;
38a64f9d 3367 /* sign extend LI */
76a66253 3368#if defined(TARGET_PPC64)
d9bce9d9
JM
3369 if (ctx->sf_mode)
3370 li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
3371 else
76a66253 3372#endif
d9bce9d9 3373 li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
76a66253 3374 if (likely(AA(ctx->opcode) == 0))
046d6672 3375 target = ctx->nip + li - 4;
79aceca5 3376 else
9a64fbe4 3377 target = li;
e1833e1f
JM
3378 if (LK(ctx->opcode))
3379 gen_setlr(ctx, ctx->nip);
697ab892 3380 gen_update_cfar(ctx, ctx->nip);
c1942362 3381 gen_goto_tb(ctx, 0, target);
79aceca5
FB
3382}
3383
e98a6e40
FB
3384#define BCOND_IM 0
3385#define BCOND_LR 1
3386#define BCOND_CTR 2
3387
636aa200 3388static inline void gen_bcond(DisasContext *ctx, int type)
d9bce9d9 3389{
d9bce9d9 3390 uint32_t bo = BO(ctx->opcode);
05f92404 3391 int l1;
a2ffb812 3392 TCGv target;
e98a6e40 3393
8cbcb4fa 3394 ctx->exception = POWERPC_EXCP_BRANCH;
a2ffb812 3395 if (type == BCOND_LR || type == BCOND_CTR) {
a7812ae4 3396 target = tcg_temp_local_new();
a2ffb812
AJ
3397 if (type == BCOND_CTR)
3398 tcg_gen_mov_tl(target, cpu_ctr);
3399 else
3400 tcg_gen_mov_tl(target, cpu_lr);
d2e9fd8f 3401 } else {
3402 TCGV_UNUSED(target);
e98a6e40 3403 }
e1833e1f
JM
3404 if (LK(ctx->opcode))
3405 gen_setlr(ctx, ctx->nip);
a2ffb812
AJ
3406 l1 = gen_new_label();
3407 if ((bo & 0x4) == 0) {
3408 /* Decrement and test CTR */
a7812ae4 3409 TCGv temp = tcg_temp_new();
a2ffb812 3410 if (unlikely(type == BCOND_CTR)) {
e06fcd75 3411 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
a2ffb812
AJ
3412 return;
3413 }
3414 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
d9bce9d9 3415#if defined(TARGET_PPC64)
a2ffb812
AJ
3416 if (!ctx->sf_mode)
3417 tcg_gen_ext32u_tl(temp, cpu_ctr);
3418 else
d9bce9d9 3419#endif
a2ffb812
AJ
3420 tcg_gen_mov_tl(temp, cpu_ctr);
3421 if (bo & 0x2) {
3422 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3423 } else {
3424 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
e98a6e40 3425 }
a7812ae4 3426 tcg_temp_free(temp);
a2ffb812
AJ
3427 }
3428 if ((bo & 0x10) == 0) {
3429 /* Test CR */
3430 uint32_t bi = BI(ctx->opcode);
3431 uint32_t mask = 1 << (3 - (bi & 0x03));
a7812ae4 3432 TCGv_i32 temp = tcg_temp_new_i32();
a2ffb812 3433
d9bce9d9 3434 if (bo & 0x8) {
a2ffb812
AJ
3435 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3436 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
d9bce9d9 3437 } else {
a2ffb812
AJ
3438 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3439 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
d9bce9d9 3440 }
a7812ae4 3441 tcg_temp_free_i32(temp);
d9bce9d9 3442 }
697ab892 3443 gen_update_cfar(ctx, ctx->nip);
e98a6e40 3444 if (type == BCOND_IM) {
a2ffb812
AJ
3445 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3446 if (likely(AA(ctx->opcode) == 0)) {
3447 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3448 } else {
3449 gen_goto_tb(ctx, 0, li);
3450 }
c53be334 3451 gen_set_label(l1);
c1942362 3452 gen_goto_tb(ctx, 1, ctx->nip);
e98a6e40 3453 } else {
d9bce9d9 3454#if defined(TARGET_PPC64)
a2ffb812
AJ
3455 if (!(ctx->sf_mode))
3456 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3457 else
3458#endif
3459 tcg_gen_andi_tl(cpu_nip, target, ~3);
3460 tcg_gen_exit_tb(0);
3461 gen_set_label(l1);
3462#if defined(TARGET_PPC64)
3463 if (!(ctx->sf_mode))
3464 tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip);
d9bce9d9
JM
3465 else
3466#endif
a2ffb812 3467 tcg_gen_movi_tl(cpu_nip, ctx->nip);
57fec1fe 3468 tcg_gen_exit_tb(0);
08e46e54 3469 }
e98a6e40
FB
3470}
3471
99e300ef 3472static void gen_bc(DisasContext *ctx)
3b46e624 3473{
e98a6e40
FB
3474 gen_bcond(ctx, BCOND_IM);
3475}
3476
99e300ef 3477static void gen_bcctr(DisasContext *ctx)
3b46e624 3478{
e98a6e40
FB
3479 gen_bcond(ctx, BCOND_CTR);
3480}
3481
99e300ef 3482static void gen_bclr(DisasContext *ctx)
3b46e624 3483{
e98a6e40
FB
3484 gen_bcond(ctx, BCOND_LR);
3485}
79aceca5
FB
3486
3487/*** Condition register logical ***/
e1571908 3488#define GEN_CRLOGIC(name, tcg_op, opc) \
99e300ef 3489static void glue(gen_, name)(DisasContext *ctx) \
79aceca5 3490{ \
fc0d441e
JM
3491 uint8_t bitmask; \
3492 int sh; \
a7812ae4 3493 TCGv_i32 t0, t1; \
fc0d441e 3494 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
a7812ae4 3495 t0 = tcg_temp_new_i32(); \
fc0d441e 3496 if (sh > 0) \
fea0c503 3497 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
fc0d441e 3498 else if (sh < 0) \
fea0c503 3499 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
e1571908 3500 else \
fea0c503 3501 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
a7812ae4 3502 t1 = tcg_temp_new_i32(); \
fc0d441e
JM
3503 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3504 if (sh > 0) \
fea0c503 3505 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
fc0d441e 3506 else if (sh < 0) \
fea0c503 3507 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
e1571908 3508 else \
fea0c503
AJ
3509 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3510 tcg_op(t0, t0, t1); \
fc0d441e 3511 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
fea0c503
AJ
3512 tcg_gen_andi_i32(t0, t0, bitmask); \
3513 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3514 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
a7812ae4
PB
3515 tcg_temp_free_i32(t0); \
3516 tcg_temp_free_i32(t1); \
79aceca5
FB
3517}
3518
3519/* crand */
e1571908 3520GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
79aceca5 3521/* crandc */
e1571908 3522GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
79aceca5 3523/* creqv */
e1571908 3524GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
79aceca5 3525/* crnand */
e1571908 3526GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
79aceca5 3527/* crnor */
e1571908 3528GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
79aceca5 3529/* cror */
e1571908 3530GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
79aceca5 3531/* crorc */
e1571908 3532GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
79aceca5 3533/* crxor */
e1571908 3534GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
99e300ef 3535
54623277 3536/* mcrf */
99e300ef 3537static void gen_mcrf(DisasContext *ctx)
79aceca5 3538{
47e4661c 3539 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
79aceca5
FB
3540}
3541
3542/*** System linkage ***/
99e300ef 3543
54623277 3544/* rfi (mem_idx only) */
99e300ef 3545static void gen_rfi(DisasContext *ctx)
79aceca5 3546{
9a64fbe4 3547#if defined(CONFIG_USER_ONLY)
e06fcd75 3548 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4
FB
3549#else
3550 /* Restore CPU state */
76db3ba4 3551 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3552 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 3553 return;
9a64fbe4 3554 }
697ab892 3555 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 3556 gen_helper_rfi(cpu_env);
e06fcd75 3557 gen_sync_exception(ctx);
9a64fbe4 3558#endif
79aceca5
FB
3559}
3560
426613db 3561#if defined(TARGET_PPC64)
99e300ef 3562static void gen_rfid(DisasContext *ctx)
426613db
JM
3563{
3564#if defined(CONFIG_USER_ONLY)
e06fcd75 3565 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
3566#else
3567 /* Restore CPU state */
76db3ba4 3568 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3569 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
3570 return;
3571 }
697ab892 3572 gen_update_cfar(ctx, ctx->nip);
e5f17ac6 3573 gen_helper_rfid(cpu_env);
e06fcd75 3574 gen_sync_exception(ctx);
426613db
JM
3575#endif
3576}
426613db 3577
99e300ef 3578static void gen_hrfid(DisasContext *ctx)
be147d08
JM
3579{
3580#if defined(CONFIG_USER_ONLY)
e06fcd75 3581 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3582#else
3583 /* Restore CPU state */
76db3ba4 3584 if (unlikely(ctx->mem_idx <= 1)) {
e06fcd75 3585 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
be147d08
JM
3586 return;
3587 }
e5f17ac6 3588 gen_helper_hrfid(cpu_env);
e06fcd75 3589 gen_sync_exception(ctx);
be147d08
JM
3590#endif
3591}
3592#endif
3593
79aceca5 3594/* sc */
417bf010
JM
3595#if defined(CONFIG_USER_ONLY)
3596#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3597#else
3598#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3599#endif
99e300ef 3600static void gen_sc(DisasContext *ctx)
79aceca5 3601{
e1833e1f
JM
3602 uint32_t lev;
3603
3604 lev = (ctx->opcode >> 5) & 0x7F;
e06fcd75 3605 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
79aceca5
FB
3606}
3607
3608/*** Trap ***/
99e300ef 3609
54623277 3610/* tw */
99e300ef 3611static void gen_tw(DisasContext *ctx)
79aceca5 3612{
cab3bee2 3613 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3614 /* Update the nip since this might generate a trap exception */
3615 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
3616 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
3617 t0);
cab3bee2 3618 tcg_temp_free_i32(t0);
79aceca5
FB
3619}
3620
3621/* twi */
99e300ef 3622static void gen_twi(DisasContext *ctx)
79aceca5 3623{
cab3bee2
AJ
3624 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3625 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3626 /* Update the nip since this might generate a trap exception */
3627 gen_update_nip(ctx, ctx->nip);
e5f17ac6 3628 gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
3629 tcg_temp_free(t0);
3630 tcg_temp_free_i32(t1);
79aceca5
FB
3631}
3632
d9bce9d9
JM
3633#if defined(TARGET_PPC64)
3634/* td */
99e300ef 3635static void gen_td(DisasContext *ctx)
d9bce9d9 3636{
cab3bee2 3637 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3638 /* Update the nip since this might generate a trap exception */
3639 gen_update_nip(ctx, ctx->nip);
e5f17ac6
BS
3640 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
3641 t0);
cab3bee2 3642 tcg_temp_free_i32(t0);
d9bce9d9
JM
3643}
3644
3645/* tdi */
99e300ef 3646static void gen_tdi(DisasContext *ctx)
d9bce9d9 3647{
cab3bee2
AJ
3648 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3649 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
db9a231d
AJ
3650 /* Update the nip since this might generate a trap exception */
3651 gen_update_nip(ctx, ctx->nip);
e5f17ac6 3652 gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1);
cab3bee2
AJ
3653 tcg_temp_free(t0);
3654 tcg_temp_free_i32(t1);
d9bce9d9
JM
3655}
3656#endif
3657
79aceca5 3658/*** Processor control ***/
99e300ef 3659
da91a00f
RH
3660static void gen_read_xer(TCGv dst)
3661{
3662 TCGv t0 = tcg_temp_new();
3663 TCGv t1 = tcg_temp_new();
3664 TCGv t2 = tcg_temp_new();
3665 tcg_gen_mov_tl(dst, cpu_xer);
3666 tcg_gen_shli_tl(t0, cpu_so, XER_SO);
3667 tcg_gen_shli_tl(t1, cpu_ov, XER_OV);
3668 tcg_gen_shli_tl(t2, cpu_ca, XER_CA);
3669 tcg_gen_or_tl(t0, t0, t1);
3670 tcg_gen_or_tl(dst, dst, t2);
3671 tcg_gen_or_tl(dst, dst, t0);
3672 tcg_temp_free(t0);
3673 tcg_temp_free(t1);
3674 tcg_temp_free(t2);
3675}
3676
3677static void gen_write_xer(TCGv src)
3678{
3679 tcg_gen_andi_tl(cpu_xer, src,
3680 ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA)));
3681 tcg_gen_shri_tl(cpu_so, src, XER_SO);
3682 tcg_gen_shri_tl(cpu_ov, src, XER_OV);
3683 tcg_gen_shri_tl(cpu_ca, src, XER_CA);
3684 tcg_gen_andi_tl(cpu_so, cpu_so, 1);
3685 tcg_gen_andi_tl(cpu_ov, cpu_ov, 1);
3686 tcg_gen_andi_tl(cpu_ca, cpu_ca, 1);
3687}
3688
54623277 3689/* mcrxr */
99e300ef 3690static void gen_mcrxr(DisasContext *ctx)
79aceca5 3691{
da91a00f
RH
3692 TCGv_i32 t0 = tcg_temp_new_i32();
3693 TCGv_i32 t1 = tcg_temp_new_i32();
3694 TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)];
3695
3696 tcg_gen_trunc_tl_i32(t0, cpu_so);
3697 tcg_gen_trunc_tl_i32(t1, cpu_ov);
3698 tcg_gen_trunc_tl_i32(dst, cpu_ca);
3699 tcg_gen_shri_i32(t0, t0, 2);
3700 tcg_gen_shri_i32(t1, t1, 1);
3701 tcg_gen_or_i32(dst, dst, t0);
3702 tcg_gen_or_i32(dst, dst, t1);
3703 tcg_temp_free_i32(t0);
3704 tcg_temp_free_i32(t1);
3705
3706 tcg_gen_movi_tl(cpu_so, 0);
3707 tcg_gen_movi_tl(cpu_ov, 0);
3708 tcg_gen_movi_tl(cpu_ca, 0);
79aceca5
FB
3709}
3710
0cfe11ea 3711/* mfcr mfocrf */
99e300ef 3712static void gen_mfcr(DisasContext *ctx)
79aceca5 3713{
76a66253 3714 uint32_t crm, crn;
3b46e624 3715
76a66253
JM
3716 if (likely(ctx->opcode & 0x00100000)) {
3717 crm = CRM(ctx->opcode);
8dd640e4 3718 if (likely(crm && ((crm & (crm - 1)) == 0))) {
0cfe11ea 3719 crn = ctz32 (crm);
e1571908 3720 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
0497d2f4
AJ
3721 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
3722 cpu_gpr[rD(ctx->opcode)], crn * 4);
76a66253 3723 }
d9bce9d9 3724 } else {
651721b2
AJ
3725 TCGv_i32 t0 = tcg_temp_new_i32();
3726 tcg_gen_mov_i32(t0, cpu_crf[0]);
3727 tcg_gen_shli_i32(t0, t0, 4);
3728 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
3729 tcg_gen_shli_i32(t0, t0, 4);
3730 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
3731 tcg_gen_shli_i32(t0, t0, 4);
3732 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
3733 tcg_gen_shli_i32(t0, t0, 4);
3734 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
3735 tcg_gen_shli_i32(t0, t0, 4);
3736 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
3737 tcg_gen_shli_i32(t0, t0, 4);
3738 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
3739 tcg_gen_shli_i32(t0, t0, 4);
3740 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
3741 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
3742 tcg_temp_free_i32(t0);
d9bce9d9 3743 }
79aceca5
FB
3744}
3745
3746/* mfmsr */
99e300ef 3747static void gen_mfmsr(DisasContext *ctx)
79aceca5 3748{
9a64fbe4 3749#if defined(CONFIG_USER_ONLY)
e06fcd75 3750 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 3751#else
76db3ba4 3752 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3753 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 3754 return;
9a64fbe4 3755 }
6527f6ea 3756 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
9a64fbe4 3757#endif
79aceca5
FB
3758}
3759
7b13448f 3760static void spr_noaccess(void *opaque, int gprn, int sprn)
3fc6c082 3761{
7b13448f 3762#if 0
3fc6c082
FB
3763 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3764 printf("ERROR: try to access SPR %d !\n", sprn);
7b13448f 3765#endif
3fc6c082
FB
3766}
3767#define SPR_NOACCESS (&spr_noaccess)
3fc6c082 3768
79aceca5 3769/* mfspr */
636aa200 3770static inline void gen_op_mfspr(DisasContext *ctx)
79aceca5 3771{
45d827d2 3772 void (*read_cb)(void *opaque, int gprn, int sprn);
79aceca5
FB
3773 uint32_t sprn = SPR(ctx->opcode);
3774
3fc6c082 3775#if !defined(CONFIG_USER_ONLY)
76db3ba4 3776 if (ctx->mem_idx == 2)
be147d08 3777 read_cb = ctx->spr_cb[sprn].hea_read;
76db3ba4 3778 else if (ctx->mem_idx)
3fc6c082
FB
3779 read_cb = ctx->spr_cb[sprn].oea_read;
3780 else
9a64fbe4 3781#endif
3fc6c082 3782 read_cb = ctx->spr_cb[sprn].uea_read;
76a66253
JM
3783 if (likely(read_cb != NULL)) {
3784 if (likely(read_cb != SPR_NOACCESS)) {
45d827d2 3785 (*read_cb)(ctx, rD(ctx->opcode), sprn);
3fc6c082
FB
3786 } else {
3787 /* Privilege exception */
9fceefa7
JM
3788 /* This is a hack to avoid warnings when running Linux:
3789 * this OS breaks the PowerPC virtualisation model,
3790 * allowing userland application to read the PVR
3791 */
3792 if (sprn != SPR_PVR) {
93fcfe39 3793 qemu_log("Trying to read privileged spr %d %03x at "
90e189ec
BS
3794 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3795 printf("Trying to read privileged spr %d %03x at "
3796 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
f24e5695 3797 }
e06fcd75 3798 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
79aceca5 3799 }
3fc6c082
FB
3800 } else {
3801 /* Not defined */
93fcfe39 3802 qemu_log("Trying to read invalid spr %d %03x at "
90e189ec
BS
3803 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3804 printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx "\n",
077fc206 3805 sprn, sprn, ctx->nip);
e06fcd75 3806 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 3807 }
79aceca5
FB
3808}
3809
99e300ef 3810static void gen_mfspr(DisasContext *ctx)
79aceca5 3811{
3fc6c082 3812 gen_op_mfspr(ctx);
76a66253 3813}
3fc6c082
FB
3814
3815/* mftb */
99e300ef 3816static void gen_mftb(DisasContext *ctx)
3fc6c082
FB
3817{
3818 gen_op_mfspr(ctx);
79aceca5
FB
3819}
3820
0cfe11ea 3821/* mtcrf mtocrf*/
99e300ef 3822static void gen_mtcrf(DisasContext *ctx)
79aceca5 3823{
76a66253 3824 uint32_t crm, crn;
3b46e624 3825
76a66253 3826 crm = CRM(ctx->opcode);
8dd640e4 3827 if (likely((ctx->opcode & 0x00100000))) {
3828 if (crm && ((crm & (crm - 1)) == 0)) {
3829 TCGv_i32 temp = tcg_temp_new_i32();
0cfe11ea 3830 crn = ctz32 (crm);
8dd640e4 3831 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
0cfe11ea
AJ
3832 tcg_gen_shri_i32(temp, temp, crn * 4);
3833 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
8dd640e4 3834 tcg_temp_free_i32(temp);
3835 }
76a66253 3836 } else {
651721b2
AJ
3837 TCGv_i32 temp = tcg_temp_new_i32();
3838 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
3839 for (crn = 0 ; crn < 8 ; crn++) {
3840 if (crm & (1 << crn)) {
3841 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
3842 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
3843 }
3844 }
a7812ae4 3845 tcg_temp_free_i32(temp);
76a66253 3846 }
79aceca5
FB
3847}
3848
3849/* mtmsr */
426613db 3850#if defined(TARGET_PPC64)
99e300ef 3851static void gen_mtmsrd(DisasContext *ctx)
426613db
JM
3852{
3853#if defined(CONFIG_USER_ONLY)
e06fcd75 3854 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db 3855#else
76db3ba4 3856 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3857 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
426613db
JM
3858 return;
3859 }
be147d08
JM
3860 if (ctx->opcode & 0x00010000) {
3861 /* Special form that does not need any synchronisation */
6527f6ea
AJ
3862 TCGv t0 = tcg_temp_new();
3863 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
3864 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
3865 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
3866 tcg_temp_free(t0);
be147d08 3867 } else {
056b05f8
JM
3868 /* XXX: we need to update nip before the store
3869 * if we enter power saving mode, we will exit the loop
3870 * directly from ppc_store_msr
3871 */
be147d08 3872 gen_update_nip(ctx, ctx->nip);
e5f17ac6 3873 gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
be147d08
JM
3874 /* Must stop the translation as machine state (may have) changed */
3875 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 3876 gen_stop_exception(ctx);
be147d08 3877 }
426613db
JM
3878#endif
3879}
3880#endif
3881
99e300ef 3882static void gen_mtmsr(DisasContext *ctx)
79aceca5 3883{
9a64fbe4 3884#if defined(CONFIG_USER_ONLY)
e06fcd75 3885 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 3886#else
76db3ba4 3887 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3888 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 3889 return;
9a64fbe4 3890 }
be147d08
JM
3891 if (ctx->opcode & 0x00010000) {
3892 /* Special form that does not need any synchronisation */
6527f6ea
AJ
3893 TCGv t0 = tcg_temp_new();
3894 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
3895 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
3896 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
3897 tcg_temp_free(t0);
be147d08 3898 } else {
8018dc63
AG
3899 TCGv msr = tcg_temp_new();
3900
056b05f8
JM
3901 /* XXX: we need to update nip before the store
3902 * if we enter power saving mode, we will exit the loop
3903 * directly from ppc_store_msr
3904 */
be147d08 3905 gen_update_nip(ctx, ctx->nip);
d9bce9d9 3906#if defined(TARGET_PPC64)
8018dc63
AG
3907 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
3908#else
3909 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
d9bce9d9 3910#endif
e5f17ac6 3911 gen_helper_store_msr(cpu_env, msr);
be147d08 3912 /* Must stop the translation as machine state (may have) changed */
6527f6ea 3913 /* Note that mtmsr is not always defined as context-synchronizing */
e06fcd75 3914 gen_stop_exception(ctx);
be147d08 3915 }
9a64fbe4 3916#endif
79aceca5
FB
3917}
3918
3919/* mtspr */
99e300ef 3920static void gen_mtspr(DisasContext *ctx)
79aceca5 3921{
45d827d2 3922 void (*write_cb)(void *opaque, int sprn, int gprn);
79aceca5
FB
3923 uint32_t sprn = SPR(ctx->opcode);
3924
3fc6c082 3925#if !defined(CONFIG_USER_ONLY)
76db3ba4 3926 if (ctx->mem_idx == 2)
be147d08 3927 write_cb = ctx->spr_cb[sprn].hea_write;
76db3ba4 3928 else if (ctx->mem_idx)
3fc6c082
FB
3929 write_cb = ctx->spr_cb[sprn].oea_write;
3930 else
9a64fbe4 3931#endif
3fc6c082 3932 write_cb = ctx->spr_cb[sprn].uea_write;
76a66253
JM
3933 if (likely(write_cb != NULL)) {
3934 if (likely(write_cb != SPR_NOACCESS)) {
45d827d2 3935 (*write_cb)(ctx, sprn, rS(ctx->opcode));
3fc6c082
FB
3936 } else {
3937 /* Privilege exception */
93fcfe39 3938 qemu_log("Trying to write privileged spr %d %03x at "
90e189ec
BS
3939 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3940 printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx
3941 "\n", sprn, sprn, ctx->nip);
e06fcd75 3942 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 3943 }
3fc6c082
FB
3944 } else {
3945 /* Not defined */
93fcfe39 3946 qemu_log("Trying to write invalid spr %d %03x at "
90e189ec
BS
3947 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3948 printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx "\n",
077fc206 3949 sprn, sprn, ctx->nip);
e06fcd75 3950 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
79aceca5 3951 }
79aceca5
FB
3952}
3953
3954/*** Cache management ***/
99e300ef 3955
54623277 3956/* dcbf */
99e300ef 3957static void gen_dcbf(DisasContext *ctx)
79aceca5 3958{
dac454af 3959 /* XXX: specification says this is treated as a load by the MMU */
76db3ba4
AJ
3960 TCGv t0;
3961 gen_set_access_type(ctx, ACCESS_CACHE);
3962 t0 = tcg_temp_new();
3963 gen_addr_reg_index(ctx, t0);
3964 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 3965 tcg_temp_free(t0);
79aceca5
FB
3966}
3967
3968/* dcbi (Supervisor only) */
99e300ef 3969static void gen_dcbi(DisasContext *ctx)
79aceca5 3970{
a541f297 3971#if defined(CONFIG_USER_ONLY)
e06fcd75 3972 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a541f297 3973#else
b61f2753 3974 TCGv EA, val;
76db3ba4 3975 if (unlikely(!ctx->mem_idx)) {
e06fcd75 3976 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 3977 return;
9a64fbe4 3978 }
a7812ae4 3979 EA = tcg_temp_new();
76db3ba4
AJ
3980 gen_set_access_type(ctx, ACCESS_CACHE);
3981 gen_addr_reg_index(ctx, EA);
a7812ae4 3982 val = tcg_temp_new();
76a66253 3983 /* XXX: specification says this should be treated as a store by the MMU */
76db3ba4
AJ
3984 gen_qemu_ld8u(ctx, val, EA);
3985 gen_qemu_st8(ctx, val, EA);
b61f2753
AJ
3986 tcg_temp_free(val);
3987 tcg_temp_free(EA);
a541f297 3988#endif
79aceca5
FB
3989}
3990
3991/* dcdst */
99e300ef 3992static void gen_dcbst(DisasContext *ctx)
79aceca5 3993{
76a66253 3994 /* XXX: specification say this is treated as a load by the MMU */
76db3ba4
AJ
3995 TCGv t0;
3996 gen_set_access_type(ctx, ACCESS_CACHE);
3997 t0 = tcg_temp_new();
3998 gen_addr_reg_index(ctx, t0);
3999 gen_qemu_ld8u(ctx, t0, t0);
fea0c503 4000 tcg_temp_free(t0);
79aceca5
FB
4001}
4002
4003/* dcbt */
99e300ef 4004static void gen_dcbt(DisasContext *ctx)
79aceca5 4005{
0db1b20e 4006 /* interpreted as no-op */
76a66253
JM
4007 /* XXX: specification say this is treated as a load by the MMU
4008 * but does not generate any exception
4009 */
79aceca5
FB
4010}
4011
4012/* dcbtst */
99e300ef 4013static void gen_dcbtst(DisasContext *ctx)
79aceca5 4014{
0db1b20e 4015 /* interpreted as no-op */
76a66253
JM
4016 /* XXX: specification say this is treated as a load by the MMU
4017 * but does not generate any exception
4018 */
79aceca5
FB
4019}
4020
4021/* dcbz */
99e300ef 4022static void gen_dcbz(DisasContext *ctx)
79aceca5 4023{
8e33944f
AG
4024 TCGv tcgv_addr;
4025 TCGv_i32 tcgv_is_dcbzl;
4026 int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0;
d63001d1 4027
76db3ba4 4028 gen_set_access_type(ctx, ACCESS_CACHE);
799a8c8d
AJ
4029 /* NIP cannot be restored if the memory exception comes from an helper */
4030 gen_update_nip(ctx, ctx->nip - 4);
8e33944f
AG
4031 tcgv_addr = tcg_temp_new();
4032 tcgv_is_dcbzl = tcg_const_i32(is_dcbzl);
4033
4034 gen_addr_reg_index(ctx, tcgv_addr);
4035 gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl);
4036
4037 tcg_temp_free(tcgv_addr);
4038 tcg_temp_free_i32(tcgv_is_dcbzl);
79aceca5
FB
4039}
4040
ae1c1a3d 4041/* dst / dstt */
99e300ef 4042static void gen_dst(DisasContext *ctx)
ae1c1a3d
AJ
4043{
4044 if (rA(ctx->opcode) == 0) {
4045 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4046 } else {
4047 /* interpreted as no-op */
4048 }
4049}
4050
4051/* dstst /dststt */
99e300ef 4052static void gen_dstst(DisasContext *ctx)
ae1c1a3d
AJ
4053{
4054 if (rA(ctx->opcode) == 0) {
4055 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4056 } else {
4057 /* interpreted as no-op */
4058 }
4059
4060}
4061
4062/* dss / dssall */
99e300ef 4063static void gen_dss(DisasContext *ctx)
ae1c1a3d
AJ
4064{
4065 /* interpreted as no-op */
4066}
4067
79aceca5 4068/* icbi */
99e300ef 4069static void gen_icbi(DisasContext *ctx)
79aceca5 4070{
76db3ba4
AJ
4071 TCGv t0;
4072 gen_set_access_type(ctx, ACCESS_CACHE);
30032c94
JM
4073 /* NIP cannot be restored if the memory exception comes from an helper */
4074 gen_update_nip(ctx, ctx->nip - 4);
76db3ba4
AJ
4075 t0 = tcg_temp_new();
4076 gen_addr_reg_index(ctx, t0);
2f5a189c 4077 gen_helper_icbi(cpu_env, t0);
37d269df 4078 tcg_temp_free(t0);
79aceca5
FB
4079}
4080
4081/* Optional: */
4082/* dcba */
99e300ef 4083static void gen_dcba(DisasContext *ctx)
79aceca5 4084{
0db1b20e
JM
4085 /* interpreted as no-op */
4086 /* XXX: specification say this is treated as a store by the MMU
4087 * but does not generate any exception
4088 */
79aceca5
FB
4089}
4090
4091/*** Segment register manipulation ***/
4092/* Supervisor only: */
99e300ef 4093
54623277 4094/* mfsr */
99e300ef 4095static void gen_mfsr(DisasContext *ctx)
79aceca5 4096{
9a64fbe4 4097#if defined(CONFIG_USER_ONLY)
e06fcd75 4098 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4099#else
74d37793 4100 TCGv t0;
76db3ba4 4101 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4102 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4103 return;
9a64fbe4 4104 }
74d37793 4105 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4106 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4107 tcg_temp_free(t0);
9a64fbe4 4108#endif
79aceca5
FB
4109}
4110
4111/* mfsrin */
99e300ef 4112static void gen_mfsrin(DisasContext *ctx)
79aceca5 4113{
9a64fbe4 4114#if defined(CONFIG_USER_ONLY)
e06fcd75 4115 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4116#else
74d37793 4117 TCGv t0;
76db3ba4 4118 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4119 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4120 return;
9a64fbe4 4121 }
74d37793
AJ
4122 t0 = tcg_temp_new();
4123 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4124 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4125 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4126 tcg_temp_free(t0);
9a64fbe4 4127#endif
79aceca5
FB
4128}
4129
4130/* mtsr */
99e300ef 4131static void gen_mtsr(DisasContext *ctx)
79aceca5 4132{
9a64fbe4 4133#if defined(CONFIG_USER_ONLY)
e06fcd75 4134 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4135#else
74d37793 4136 TCGv t0;
76db3ba4 4137 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4138 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4139 return;
9a64fbe4 4140 }
74d37793 4141 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4142 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4143 tcg_temp_free(t0);
9a64fbe4 4144#endif
79aceca5
FB
4145}
4146
4147/* mtsrin */
99e300ef 4148static void gen_mtsrin(DisasContext *ctx)
79aceca5 4149{
9a64fbe4 4150#if defined(CONFIG_USER_ONLY)
e06fcd75 4151 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9a64fbe4 4152#else
74d37793 4153 TCGv t0;
76db3ba4 4154 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4155 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
9fddaa0c 4156 return;
9a64fbe4 4157 }
74d37793
AJ
4158 t0 = tcg_temp_new();
4159 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4160 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4161 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]);
74d37793 4162 tcg_temp_free(t0);
9a64fbe4 4163#endif
79aceca5
FB
4164}
4165
12de9a39
JM
4166#if defined(TARGET_PPC64)
4167/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
e8eaa2c0 4168
54623277 4169/* mfsr */
e8eaa2c0 4170static void gen_mfsr_64b(DisasContext *ctx)
12de9a39
JM
4171{
4172#if defined(CONFIG_USER_ONLY)
e06fcd75 4173 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4174#else
74d37793 4175 TCGv t0;
76db3ba4 4176 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4177 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4178 return;
4179 }
74d37793 4180 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4181 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4182 tcg_temp_free(t0);
12de9a39
JM
4183#endif
4184}
4185
4186/* mfsrin */
e8eaa2c0 4187static void gen_mfsrin_64b(DisasContext *ctx)
12de9a39
JM
4188{
4189#if defined(CONFIG_USER_ONLY)
e06fcd75 4190 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4191#else
74d37793 4192 TCGv t0;
76db3ba4 4193 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4194 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4195 return;
4196 }
74d37793
AJ
4197 t0 = tcg_temp_new();
4198 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4199 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4200 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793 4201 tcg_temp_free(t0);
12de9a39
JM
4202#endif
4203}
4204
4205/* mtsr */
e8eaa2c0 4206static void gen_mtsr_64b(DisasContext *ctx)
12de9a39
JM
4207{
4208#if defined(CONFIG_USER_ONLY)
e06fcd75 4209 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4210#else
74d37793 4211 TCGv t0;
76db3ba4 4212 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4213 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4214 return;
4215 }
74d37793 4216 t0 = tcg_const_tl(SR(ctx->opcode));
c6c7cf05 4217 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4218 tcg_temp_free(t0);
12de9a39
JM
4219#endif
4220}
4221
4222/* mtsrin */
e8eaa2c0 4223static void gen_mtsrin_64b(DisasContext *ctx)
12de9a39
JM
4224{
4225#if defined(CONFIG_USER_ONLY)
e06fcd75 4226 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39 4227#else
74d37793 4228 TCGv t0;
76db3ba4 4229 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4230 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
12de9a39
JM
4231 return;
4232 }
74d37793
AJ
4233 t0 = tcg_temp_new();
4234 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4235 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 4236 gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]);
74d37793 4237 tcg_temp_free(t0);
12de9a39
JM
4238#endif
4239}
f6b868fc
BS
4240
4241/* slbmte */
e8eaa2c0 4242static void gen_slbmte(DisasContext *ctx)
f6b868fc
BS
4243{
4244#if defined(CONFIG_USER_ONLY)
4245 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4246#else
4247 if (unlikely(!ctx->mem_idx)) {
4248 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4249 return;
4250 }
c6c7cf05
BS
4251 gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)],
4252 cpu_gpr[rS(ctx->opcode)]);
f6b868fc
BS
4253#endif
4254}
4255
efdef95f
DG
4256static void gen_slbmfee(DisasContext *ctx)
4257{
4258#if defined(CONFIG_USER_ONLY)
4259 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4260#else
4261 if (unlikely(!ctx->mem_idx)) {
4262 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4263 return;
4264 }
c6c7cf05 4265 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4266 cpu_gpr[rB(ctx->opcode)]);
4267#endif
4268}
4269
4270static void gen_slbmfev(DisasContext *ctx)
4271{
4272#if defined(CONFIG_USER_ONLY)
4273 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4274#else
4275 if (unlikely(!ctx->mem_idx)) {
4276 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4277 return;
4278 }
c6c7cf05 4279 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env,
efdef95f
DG
4280 cpu_gpr[rB(ctx->opcode)]);
4281#endif
4282}
12de9a39
JM
4283#endif /* defined(TARGET_PPC64) */
4284
79aceca5 4285/*** Lookaside buffer management ***/
76db3ba4 4286/* Optional & mem_idx only: */
99e300ef 4287
54623277 4288/* tlbia */
99e300ef 4289static void gen_tlbia(DisasContext *ctx)
79aceca5 4290{
9a64fbe4 4291#if defined(CONFIG_USER_ONLY)
e06fcd75 4292 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4293#else
76db3ba4 4294 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4295 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4296 return;
9a64fbe4 4297 }
c6c7cf05 4298 gen_helper_tlbia(cpu_env);
9a64fbe4 4299#endif
79aceca5
FB
4300}
4301
bf14b1ce 4302/* tlbiel */
99e300ef 4303static void gen_tlbiel(DisasContext *ctx)
bf14b1ce
BS
4304{
4305#if defined(CONFIG_USER_ONLY)
4306 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4307#else
4308 if (unlikely(!ctx->mem_idx)) {
4309 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4310 return;
4311 }
c6c7cf05 4312 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
bf14b1ce
BS
4313#endif
4314}
4315
79aceca5 4316/* tlbie */
99e300ef 4317static void gen_tlbie(DisasContext *ctx)
79aceca5 4318{
9a64fbe4 4319#if defined(CONFIG_USER_ONLY)
e06fcd75 4320 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4321#else
76db3ba4 4322 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4323 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4324 return;
9a64fbe4 4325 }
d9bce9d9 4326#if defined(TARGET_PPC64)
74d37793
AJ
4327 if (!ctx->sf_mode) {
4328 TCGv t0 = tcg_temp_new();
4329 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 4330 gen_helper_tlbie(cpu_env, t0);
74d37793
AJ
4331 tcg_temp_free(t0);
4332 } else
d9bce9d9 4333#endif
c6c7cf05 4334 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9a64fbe4 4335#endif
79aceca5
FB
4336}
4337
4338/* tlbsync */
99e300ef 4339static void gen_tlbsync(DisasContext *ctx)
79aceca5 4340{
9a64fbe4 4341#if defined(CONFIG_USER_ONLY)
e06fcd75 4342 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9a64fbe4 4343#else
76db3ba4 4344 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4345 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
9fddaa0c 4346 return;
9a64fbe4
FB
4347 }
4348 /* This has no effect: it should ensure that all previous
4349 * tlbie have completed
4350 */
e06fcd75 4351 gen_stop_exception(ctx);
9a64fbe4 4352#endif
79aceca5
FB
4353}
4354
426613db
JM
4355#if defined(TARGET_PPC64)
4356/* slbia */
99e300ef 4357static void gen_slbia(DisasContext *ctx)
426613db
JM
4358{
4359#if defined(CONFIG_USER_ONLY)
e06fcd75 4360 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4361#else
76db3ba4 4362 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4363 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4364 return;
4365 }
c6c7cf05 4366 gen_helper_slbia(cpu_env);
426613db
JM
4367#endif
4368}
4369
4370/* slbie */
99e300ef 4371static void gen_slbie(DisasContext *ctx)
426613db
JM
4372{
4373#if defined(CONFIG_USER_ONLY)
e06fcd75 4374 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db 4375#else
76db3ba4 4376 if (unlikely(!ctx->mem_idx)) {
e06fcd75 4377 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
426613db
JM
4378 return;
4379 }
c6c7cf05 4380 gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
426613db
JM
4381#endif
4382}
4383#endif
4384
79aceca5
FB
4385/*** External control ***/
4386/* Optional: */
99e300ef 4387
54623277 4388/* eciwx */
99e300ef 4389static void gen_eciwx(DisasContext *ctx)
79aceca5 4390{
76db3ba4 4391 TCGv t0;
fa407c03 4392 /* Should check EAR[E] ! */
76db3ba4
AJ
4393 gen_set_access_type(ctx, ACCESS_EXT);
4394 t0 = tcg_temp_new();
4395 gen_addr_reg_index(ctx, t0);
fa407c03 4396 gen_check_align(ctx, t0, 0x03);
76db3ba4 4397 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4398 tcg_temp_free(t0);
76a66253
JM
4399}
4400
4401/* ecowx */
99e300ef 4402static void gen_ecowx(DisasContext *ctx)
76a66253 4403{
76db3ba4 4404 TCGv t0;
fa407c03 4405 /* Should check EAR[E] ! */
76db3ba4
AJ
4406 gen_set_access_type(ctx, ACCESS_EXT);
4407 t0 = tcg_temp_new();
4408 gen_addr_reg_index(ctx, t0);
fa407c03 4409 gen_check_align(ctx, t0, 0x03);
76db3ba4 4410 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
fa407c03 4411 tcg_temp_free(t0);
76a66253
JM
4412}
4413
4414/* PowerPC 601 specific instructions */
99e300ef 4415
54623277 4416/* abs - abs. */
99e300ef 4417static void gen_abs(DisasContext *ctx)
76a66253 4418{
22e0e173
AJ
4419 int l1 = gen_new_label();
4420 int l2 = gen_new_label();
4421 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4422 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4423 tcg_gen_br(l2);
4424 gen_set_label(l1);
4425 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4426 gen_set_label(l2);
76a66253 4427 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4428 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4429}
4430
4431/* abso - abso. */
99e300ef 4432static void gen_abso(DisasContext *ctx)
76a66253 4433{
22e0e173
AJ
4434 int l1 = gen_new_label();
4435 int l2 = gen_new_label();
4436 int l3 = gen_new_label();
4437 /* Start with XER OV disabled, the most likely case */
da91a00f 4438 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4439 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4440 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
da91a00f
RH
4441 tcg_gen_movi_tl(cpu_ov, 1);
4442 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4443 tcg_gen_br(l2);
4444 gen_set_label(l1);
4445 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4446 tcg_gen_br(l3);
4447 gen_set_label(l2);
4448 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4449 gen_set_label(l3);
76a66253 4450 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4451 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4452}
4453
4454/* clcs */
99e300ef 4455static void gen_clcs(DisasContext *ctx)
76a66253 4456{
22e0e173 4457 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
d523dd00 4458 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 4459 tcg_temp_free_i32(t0);
c7697e1f 4460 /* Rc=1 sets CR0 to an undefined state */
76a66253
JM
4461}
4462
4463/* div - div. */
99e300ef 4464static void gen_div(DisasContext *ctx)
76a66253 4465{
d15f74fb
BS
4466 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4467 cpu_gpr[rB(ctx->opcode)]);
76a66253 4468 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4469 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4470}
4471
4472/* divo - divo. */
99e300ef 4473static void gen_divo(DisasContext *ctx)
76a66253 4474{
d15f74fb
BS
4475 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4476 cpu_gpr[rB(ctx->opcode)]);
76a66253 4477 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4478 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4479}
4480
4481/* divs - divs. */
99e300ef 4482static void gen_divs(DisasContext *ctx)
76a66253 4483{
d15f74fb
BS
4484 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)],
4485 cpu_gpr[rB(ctx->opcode)]);
76a66253 4486 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4487 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4488}
4489
4490/* divso - divso. */
99e300ef 4491static void gen_divso(DisasContext *ctx)
76a66253 4492{
d15f74fb
BS
4493 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env,
4494 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
76a66253 4495 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4496 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4497}
4498
4499/* doz - doz. */
99e300ef 4500static void gen_doz(DisasContext *ctx)
76a66253 4501{
22e0e173
AJ
4502 int l1 = gen_new_label();
4503 int l2 = gen_new_label();
4504 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4505 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4506 tcg_gen_br(l2);
4507 gen_set_label(l1);
4508 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4509 gen_set_label(l2);
76a66253 4510 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4511 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4512}
4513
4514/* dozo - dozo. */
99e300ef 4515static void gen_dozo(DisasContext *ctx)
76a66253 4516{
22e0e173
AJ
4517 int l1 = gen_new_label();
4518 int l2 = gen_new_label();
4519 TCGv t0 = tcg_temp_new();
4520 TCGv t1 = tcg_temp_new();
4521 TCGv t2 = tcg_temp_new();
4522 /* Start with XER OV disabled, the most likely case */
da91a00f 4523 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4524 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4525 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4526 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4527 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4528 tcg_gen_andc_tl(t1, t1, t2);
4529 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4530 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
da91a00f
RH
4531 tcg_gen_movi_tl(cpu_ov, 1);
4532 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4533 tcg_gen_br(l2);
4534 gen_set_label(l1);
4535 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4536 gen_set_label(l2);
4537 tcg_temp_free(t0);
4538 tcg_temp_free(t1);
4539 tcg_temp_free(t2);
76a66253 4540 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4541 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4542}
4543
4544/* dozi */
99e300ef 4545static void gen_dozi(DisasContext *ctx)
76a66253 4546{
22e0e173
AJ
4547 target_long simm = SIMM(ctx->opcode);
4548 int l1 = gen_new_label();
4549 int l2 = gen_new_label();
4550 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
4551 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
4552 tcg_gen_br(l2);
4553 gen_set_label(l1);
4554 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4555 gen_set_label(l2);
4556 if (unlikely(Rc(ctx->opcode) != 0))
4557 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4558}
4559
76a66253 4560/* lscbx - lscbx. */
99e300ef 4561static void gen_lscbx(DisasContext *ctx)
76a66253 4562{
bdb4b689
AJ
4563 TCGv t0 = tcg_temp_new();
4564 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
4565 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
4566 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
76a66253 4567
76db3ba4 4568 gen_addr_reg_index(ctx, t0);
76a66253 4569 /* NIP cannot be restored if the memory exception comes from an helper */
d9bce9d9 4570 gen_update_nip(ctx, ctx->nip - 4);
2f5a189c 4571 gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3);
bdb4b689
AJ
4572 tcg_temp_free_i32(t1);
4573 tcg_temp_free_i32(t2);
4574 tcg_temp_free_i32(t3);
3d7b417e 4575 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
bdb4b689 4576 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
76a66253 4577 if (unlikely(Rc(ctx->opcode) != 0))
bdb4b689
AJ
4578 gen_set_Rc0(ctx, t0);
4579 tcg_temp_free(t0);
76a66253
JM
4580}
4581
4582/* maskg - maskg. */
99e300ef 4583static void gen_maskg(DisasContext *ctx)
76a66253 4584{
22e0e173
AJ
4585 int l1 = gen_new_label();
4586 TCGv t0 = tcg_temp_new();
4587 TCGv t1 = tcg_temp_new();
4588 TCGv t2 = tcg_temp_new();
4589 TCGv t3 = tcg_temp_new();
4590 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
4591 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4592 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
4593 tcg_gen_addi_tl(t2, t0, 1);
4594 tcg_gen_shr_tl(t2, t3, t2);
4595 tcg_gen_shr_tl(t3, t3, t1);
4596 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
4597 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
4598 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4599 gen_set_label(l1);
4600 tcg_temp_free(t0);
4601 tcg_temp_free(t1);
4602 tcg_temp_free(t2);
4603 tcg_temp_free(t3);
76a66253 4604 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4605 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4606}
4607
4608/* maskir - maskir. */
99e300ef 4609static void gen_maskir(DisasContext *ctx)
76a66253 4610{
22e0e173
AJ
4611 TCGv t0 = tcg_temp_new();
4612 TCGv t1 = tcg_temp_new();
4613 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4614 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4615 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4616 tcg_temp_free(t0);
4617 tcg_temp_free(t1);
76a66253 4618 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4619 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4620}
4621
4622/* mul - mul. */
99e300ef 4623static void gen_mul(DisasContext *ctx)
76a66253 4624{
22e0e173
AJ
4625 TCGv_i64 t0 = tcg_temp_new_i64();
4626 TCGv_i64 t1 = tcg_temp_new_i64();
4627 TCGv t2 = tcg_temp_new();
4628 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4629 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4630 tcg_gen_mul_i64(t0, t0, t1);
4631 tcg_gen_trunc_i64_tl(t2, t0);
4632 gen_store_spr(SPR_MQ, t2);
4633 tcg_gen_shri_i64(t1, t0, 32);
4634 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4635 tcg_temp_free_i64(t0);
4636 tcg_temp_free_i64(t1);
4637 tcg_temp_free(t2);
76a66253 4638 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4639 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4640}
4641
4642/* mulo - mulo. */
99e300ef 4643static void gen_mulo(DisasContext *ctx)
76a66253 4644{
22e0e173
AJ
4645 int l1 = gen_new_label();
4646 TCGv_i64 t0 = tcg_temp_new_i64();
4647 TCGv_i64 t1 = tcg_temp_new_i64();
4648 TCGv t2 = tcg_temp_new();
4649 /* Start with XER OV disabled, the most likely case */
da91a00f 4650 tcg_gen_movi_tl(cpu_ov, 0);
22e0e173
AJ
4651 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4652 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4653 tcg_gen_mul_i64(t0, t0, t1);
4654 tcg_gen_trunc_i64_tl(t2, t0);
4655 gen_store_spr(SPR_MQ, t2);
4656 tcg_gen_shri_i64(t1, t0, 32);
4657 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4658 tcg_gen_ext32s_i64(t1, t0);
4659 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
da91a00f
RH
4660 tcg_gen_movi_tl(cpu_ov, 1);
4661 tcg_gen_movi_tl(cpu_so, 1);
22e0e173
AJ
4662 gen_set_label(l1);
4663 tcg_temp_free_i64(t0);
4664 tcg_temp_free_i64(t1);
4665 tcg_temp_free(t2);
76a66253 4666 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4667 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4668}
4669
4670/* nabs - nabs. */
99e300ef 4671static void gen_nabs(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_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4676 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4677 tcg_gen_br(l2);
4678 gen_set_label(l1);
4679 tcg_gen_neg_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/* nabso - nabso. */
99e300ef 4686static void gen_nabso(DisasContext *ctx)
76a66253 4687{
22e0e173
AJ
4688 int l1 = gen_new_label();
4689 int l2 = gen_new_label();
4690 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4691 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4692 tcg_gen_br(l2);
4693 gen_set_label(l1);
4694 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4695 gen_set_label(l2);
4696 /* nabs never overflows */
da91a00f 4697 tcg_gen_movi_tl(cpu_ov, 0);
76a66253 4698 if (unlikely(Rc(ctx->opcode) != 0))
22e0e173 4699 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
76a66253
JM
4700}
4701
4702/* rlmi - rlmi. */
99e300ef 4703static void gen_rlmi(DisasContext *ctx)
76a66253 4704{
7487953d
AJ
4705 uint32_t mb = MB(ctx->opcode);
4706 uint32_t me = ME(ctx->opcode);
4707 TCGv t0 = tcg_temp_new();
4708 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4709 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4710 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
4711 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
4712 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
4713 tcg_temp_free(t0);
76a66253 4714 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4715 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4716}
4717
4718/* rrib - rrib. */
99e300ef 4719static void gen_rrib(DisasContext *ctx)
76a66253 4720{
7487953d
AJ
4721 TCGv t0 = tcg_temp_new();
4722 TCGv t1 = tcg_temp_new();
4723 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4724 tcg_gen_movi_tl(t1, 0x80000000);
4725 tcg_gen_shr_tl(t1, t1, t0);
4726 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4727 tcg_gen_and_tl(t0, t0, t1);
4728 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
4729 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4730 tcg_temp_free(t0);
4731 tcg_temp_free(t1);
76a66253 4732 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4733 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4734}
4735
4736/* sle - sle. */
99e300ef 4737static void gen_sle(DisasContext *ctx)
76a66253 4738{
7487953d
AJ
4739 TCGv t0 = tcg_temp_new();
4740 TCGv t1 = tcg_temp_new();
4741 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4742 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4743 tcg_gen_subfi_tl(t1, 32, t1);
4744 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4745 tcg_gen_or_tl(t1, t0, t1);
4746 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4747 gen_store_spr(SPR_MQ, t1);
4748 tcg_temp_free(t0);
4749 tcg_temp_free(t1);
76a66253 4750 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4751 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4752}
4753
4754/* sleq - sleq. */
99e300ef 4755static void gen_sleq(DisasContext *ctx)
76a66253 4756{
7487953d
AJ
4757 TCGv t0 = tcg_temp_new();
4758 TCGv t1 = tcg_temp_new();
4759 TCGv t2 = tcg_temp_new();
4760 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4761 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
4762 tcg_gen_shl_tl(t2, t2, t0);
4763 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4764 gen_load_spr(t1, SPR_MQ);
4765 gen_store_spr(SPR_MQ, t0);
4766 tcg_gen_and_tl(t0, t0, t2);
4767 tcg_gen_andc_tl(t1, t1, t2);
4768 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4769 tcg_temp_free(t0);
4770 tcg_temp_free(t1);
4771 tcg_temp_free(t2);
76a66253 4772 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4773 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4774}
4775
4776/* sliq - sliq. */
99e300ef 4777static void gen_sliq(DisasContext *ctx)
76a66253 4778{
7487953d
AJ
4779 int sh = SH(ctx->opcode);
4780 TCGv t0 = tcg_temp_new();
4781 TCGv t1 = tcg_temp_new();
4782 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4783 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4784 tcg_gen_or_tl(t1, t0, t1);
4785 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4786 gen_store_spr(SPR_MQ, t1);
4787 tcg_temp_free(t0);
4788 tcg_temp_free(t1);
76a66253 4789 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4790 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4791}
4792
4793/* slliq - slliq. */
99e300ef 4794static void gen_slliq(DisasContext *ctx)
76a66253 4795{
7487953d
AJ
4796 int sh = SH(ctx->opcode);
4797 TCGv t0 = tcg_temp_new();
4798 TCGv t1 = tcg_temp_new();
4799 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4800 gen_load_spr(t1, SPR_MQ);
4801 gen_store_spr(SPR_MQ, t0);
4802 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
4803 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
4804 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4805 tcg_temp_free(t0);
4806 tcg_temp_free(t1);
76a66253 4807 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4808 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4809}
4810
4811/* sllq - sllq. */
99e300ef 4812static void gen_sllq(DisasContext *ctx)
76a66253 4813{
7487953d
AJ
4814 int l1 = gen_new_label();
4815 int l2 = gen_new_label();
4816 TCGv t0 = tcg_temp_local_new();
4817 TCGv t1 = tcg_temp_local_new();
4818 TCGv t2 = tcg_temp_local_new();
4819 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
4820 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
4821 tcg_gen_shl_tl(t1, t1, t2);
4822 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
4823 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
4824 gen_load_spr(t0, SPR_MQ);
4825 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4826 tcg_gen_br(l2);
4827 gen_set_label(l1);
4828 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
4829 gen_load_spr(t2, SPR_MQ);
4830 tcg_gen_andc_tl(t1, t2, t1);
4831 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4832 gen_set_label(l2);
4833 tcg_temp_free(t0);
4834 tcg_temp_free(t1);
4835 tcg_temp_free(t2);
76a66253 4836 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4837 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4838}
4839
4840/* slq - slq. */
99e300ef 4841static void gen_slq(DisasContext *ctx)
76a66253 4842{
7487953d
AJ
4843 int l1 = gen_new_label();
4844 TCGv t0 = tcg_temp_new();
4845 TCGv t1 = tcg_temp_new();
4846 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4847 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4848 tcg_gen_subfi_tl(t1, 32, t1);
4849 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4850 tcg_gen_or_tl(t1, t0, t1);
4851 gen_store_spr(SPR_MQ, t1);
4852 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
4853 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4854 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
4855 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
4856 gen_set_label(l1);
4857 tcg_temp_free(t0);
4858 tcg_temp_free(t1);
76a66253 4859 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4860 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4861}
4862
d9bce9d9 4863/* sraiq - sraiq. */
99e300ef 4864static void gen_sraiq(DisasContext *ctx)
76a66253 4865{
7487953d
AJ
4866 int sh = SH(ctx->opcode);
4867 int l1 = gen_new_label();
4868 TCGv t0 = tcg_temp_new();
4869 TCGv t1 = tcg_temp_new();
4870 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4871 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4872 tcg_gen_or_tl(t0, t0, t1);
4873 gen_store_spr(SPR_MQ, t0);
da91a00f 4874 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
4875 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
4876 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
da91a00f 4877 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
4878 gen_set_label(l1);
4879 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
4880 tcg_temp_free(t0);
4881 tcg_temp_free(t1);
76a66253 4882 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4883 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4884}
4885
4886/* sraq - sraq. */
99e300ef 4887static void gen_sraq(DisasContext *ctx)
76a66253 4888{
7487953d
AJ
4889 int l1 = gen_new_label();
4890 int l2 = gen_new_label();
4891 TCGv t0 = tcg_temp_new();
4892 TCGv t1 = tcg_temp_local_new();
4893 TCGv t2 = tcg_temp_local_new();
4894 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
4895 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
4896 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
4897 tcg_gen_subfi_tl(t2, 32, t2);
4898 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
4899 tcg_gen_or_tl(t0, t0, t2);
4900 gen_store_spr(SPR_MQ, t0);
4901 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
4902 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
4903 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
4904 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
4905 gen_set_label(l1);
4906 tcg_temp_free(t0);
4907 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
da91a00f 4908 tcg_gen_movi_tl(cpu_ca, 0);
7487953d
AJ
4909 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
4910 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
da91a00f 4911 tcg_gen_movi_tl(cpu_ca, 1);
7487953d
AJ
4912 gen_set_label(l2);
4913 tcg_temp_free(t1);
4914 tcg_temp_free(t2);
76a66253 4915 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4916 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4917}
4918
4919/* sre - sre. */
99e300ef 4920static void gen_sre(DisasContext *ctx)
76a66253 4921{
7487953d
AJ
4922 TCGv t0 = tcg_temp_new();
4923 TCGv t1 = tcg_temp_new();
4924 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4925 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4926 tcg_gen_subfi_tl(t1, 32, t1);
4927 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4928 tcg_gen_or_tl(t1, t0, t1);
4929 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4930 gen_store_spr(SPR_MQ, t1);
4931 tcg_temp_free(t0);
4932 tcg_temp_free(t1);
76a66253 4933 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4934 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4935}
4936
4937/* srea - srea. */
99e300ef 4938static void gen_srea(DisasContext *ctx)
76a66253 4939{
7487953d
AJ
4940 TCGv t0 = tcg_temp_new();
4941 TCGv t1 = tcg_temp_new();
4942 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4943 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4944 gen_store_spr(SPR_MQ, t0);
4945 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
4946 tcg_temp_free(t0);
4947 tcg_temp_free(t1);
76a66253 4948 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4949 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4950}
4951
4952/* sreq */
99e300ef 4953static void gen_sreq(DisasContext *ctx)
76a66253 4954{
7487953d
AJ
4955 TCGv t0 = tcg_temp_new();
4956 TCGv t1 = tcg_temp_new();
4957 TCGv t2 = tcg_temp_new();
4958 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4959 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
4960 tcg_gen_shr_tl(t1, t1, t0);
4961 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4962 gen_load_spr(t2, SPR_MQ);
4963 gen_store_spr(SPR_MQ, t0);
4964 tcg_gen_and_tl(t0, t0, t1);
4965 tcg_gen_andc_tl(t2, t2, t1);
4966 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
4967 tcg_temp_free(t0);
4968 tcg_temp_free(t1);
4969 tcg_temp_free(t2);
76a66253 4970 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4971 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4972}
4973
4974/* sriq */
99e300ef 4975static void gen_sriq(DisasContext *ctx)
76a66253 4976{
7487953d
AJ
4977 int sh = SH(ctx->opcode);
4978 TCGv t0 = tcg_temp_new();
4979 TCGv t1 = tcg_temp_new();
4980 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4981 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4982 tcg_gen_or_tl(t1, t0, t1);
4983 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4984 gen_store_spr(SPR_MQ, t1);
4985 tcg_temp_free(t0);
4986 tcg_temp_free(t1);
76a66253 4987 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 4988 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
4989}
4990
4991/* srliq */
99e300ef 4992static void gen_srliq(DisasContext *ctx)
76a66253 4993{
7487953d
AJ
4994 int sh = SH(ctx->opcode);
4995 TCGv t0 = tcg_temp_new();
4996 TCGv t1 = tcg_temp_new();
4997 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4998 gen_load_spr(t1, SPR_MQ);
4999 gen_store_spr(SPR_MQ, t0);
5000 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
5001 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
5002 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5003 tcg_temp_free(t0);
5004 tcg_temp_free(t1);
76a66253 5005 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5006 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5007}
5008
5009/* srlq */
99e300ef 5010static void gen_srlq(DisasContext *ctx)
76a66253 5011{
7487953d
AJ
5012 int l1 = gen_new_label();
5013 int l2 = gen_new_label();
5014 TCGv t0 = tcg_temp_local_new();
5015 TCGv t1 = tcg_temp_local_new();
5016 TCGv t2 = tcg_temp_local_new();
5017 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
5018 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5019 tcg_gen_shr_tl(t2, t1, t2);
5020 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5021 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5022 gen_load_spr(t0, SPR_MQ);
5023 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5024 tcg_gen_br(l2);
5025 gen_set_label(l1);
5026 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5027 tcg_gen_and_tl(t0, t0, t2);
5028 gen_load_spr(t1, SPR_MQ);
5029 tcg_gen_andc_tl(t1, t1, t2);
5030 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5031 gen_set_label(l2);
5032 tcg_temp_free(t0);
5033 tcg_temp_free(t1);
5034 tcg_temp_free(t2);
76a66253 5035 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5036 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5037}
5038
5039/* srq */
99e300ef 5040static void gen_srq(DisasContext *ctx)
76a66253 5041{
7487953d
AJ
5042 int l1 = gen_new_label();
5043 TCGv t0 = tcg_temp_new();
5044 TCGv t1 = tcg_temp_new();
5045 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5046 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5047 tcg_gen_subfi_tl(t1, 32, t1);
5048 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5049 tcg_gen_or_tl(t1, t0, t1);
5050 gen_store_spr(SPR_MQ, t1);
5051 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5052 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5053 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5054 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5055 gen_set_label(l1);
5056 tcg_temp_free(t0);
5057 tcg_temp_free(t1);
76a66253 5058 if (unlikely(Rc(ctx->opcode) != 0))
7487953d 5059 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5060}
5061
5062/* PowerPC 602 specific instructions */
99e300ef 5063
54623277 5064/* dsa */
99e300ef 5065static void gen_dsa(DisasContext *ctx)
76a66253
JM
5066{
5067 /* XXX: TODO */
e06fcd75 5068 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5069}
5070
5071/* esa */
99e300ef 5072static void gen_esa(DisasContext *ctx)
76a66253
JM
5073{
5074 /* XXX: TODO */
e06fcd75 5075 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5076}
5077
5078/* mfrom */
99e300ef 5079static void gen_mfrom(DisasContext *ctx)
76a66253
JM
5080{
5081#if defined(CONFIG_USER_ONLY)
e06fcd75 5082 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5083#else
76db3ba4 5084 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5085 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5086 return;
5087 }
cf02a65c 5088 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5089#endif
5090}
5091
5092/* 602 - 603 - G2 TLB management */
e8eaa2c0 5093
54623277 5094/* tlbld */
e8eaa2c0 5095static void gen_tlbld_6xx(DisasContext *ctx)
76a66253
JM
5096{
5097#if defined(CONFIG_USER_ONLY)
e06fcd75 5098 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5099#else
76db3ba4 5100 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5101 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5102 return;
5103 }
c6c7cf05 5104 gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5105#endif
5106}
5107
5108/* tlbli */
e8eaa2c0 5109static void gen_tlbli_6xx(DisasContext *ctx)
76a66253
JM
5110{
5111#if defined(CONFIG_USER_ONLY)
e06fcd75 5112 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5113#else
76db3ba4 5114 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5115 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5116 return;
5117 }
c6c7cf05 5118 gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
76a66253
JM
5119#endif
5120}
5121
7dbe11ac 5122/* 74xx TLB management */
e8eaa2c0 5123
54623277 5124/* tlbld */
e8eaa2c0 5125static void gen_tlbld_74xx(DisasContext *ctx)
7dbe11ac
JM
5126{
5127#if defined(CONFIG_USER_ONLY)
e06fcd75 5128 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5129#else
76db3ba4 5130 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5131 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5132 return;
5133 }
c6c7cf05 5134 gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5135#endif
5136}
5137
5138/* tlbli */
e8eaa2c0 5139static void gen_tlbli_74xx(DisasContext *ctx)
7dbe11ac
JM
5140{
5141#if defined(CONFIG_USER_ONLY)
e06fcd75 5142 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac 5143#else
76db3ba4 5144 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5145 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
7dbe11ac
JM
5146 return;
5147 }
c6c7cf05 5148 gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]);
7dbe11ac
JM
5149#endif
5150}
5151
76a66253 5152/* POWER instructions not in PowerPC 601 */
99e300ef 5153
54623277 5154/* clf */
99e300ef 5155static void gen_clf(DisasContext *ctx)
76a66253
JM
5156{
5157 /* Cache line flush: implemented as no-op */
5158}
5159
5160/* cli */
99e300ef 5161static void gen_cli(DisasContext *ctx)
76a66253 5162{
7f75ffd3 5163 /* Cache line invalidate: privileged and treated as no-op */
76a66253 5164#if defined(CONFIG_USER_ONLY)
e06fcd75 5165 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5166#else
76db3ba4 5167 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5168 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5169 return;
5170 }
5171#endif
5172}
5173
5174/* dclst */
99e300ef 5175static void gen_dclst(DisasContext *ctx)
76a66253
JM
5176{
5177 /* Data cache line store: treated as no-op */
5178}
5179
99e300ef 5180static void gen_mfsri(DisasContext *ctx)
76a66253
JM
5181{
5182#if defined(CONFIG_USER_ONLY)
e06fcd75 5183 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5184#else
74d37793
AJ
5185 int ra = rA(ctx->opcode);
5186 int rd = rD(ctx->opcode);
5187 TCGv t0;
76db3ba4 5188 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5189 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5190 return;
5191 }
74d37793 5192 t0 = tcg_temp_new();
76db3ba4 5193 gen_addr_reg_index(ctx, t0);
74d37793
AJ
5194 tcg_gen_shri_tl(t0, t0, 28);
5195 tcg_gen_andi_tl(t0, t0, 0xF);
c6c7cf05 5196 gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0);
74d37793 5197 tcg_temp_free(t0);
76a66253 5198 if (ra != 0 && ra != rd)
74d37793 5199 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
76a66253
JM
5200#endif
5201}
5202
99e300ef 5203static void gen_rac(DisasContext *ctx)
76a66253
JM
5204{
5205#if defined(CONFIG_USER_ONLY)
e06fcd75 5206 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5207#else
22e0e173 5208 TCGv t0;
76db3ba4 5209 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5210 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5211 return;
5212 }
22e0e173 5213 t0 = tcg_temp_new();
76db3ba4 5214 gen_addr_reg_index(ctx, t0);
c6c7cf05 5215 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
22e0e173 5216 tcg_temp_free(t0);
76a66253
JM
5217#endif
5218}
5219
99e300ef 5220static void gen_rfsvc(DisasContext *ctx)
76a66253
JM
5221{
5222#if defined(CONFIG_USER_ONLY)
e06fcd75 5223 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5224#else
76db3ba4 5225 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5226 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5227 return;
5228 }
e5f17ac6 5229 gen_helper_rfsvc(cpu_env);
e06fcd75 5230 gen_sync_exception(ctx);
76a66253
JM
5231#endif
5232}
5233
5234/* svc is not implemented for now */
5235
5236/* POWER2 specific instructions */
5237/* Quad manipulation (load/store two floats at a time) */
76a66253
JM
5238
5239/* lfq */
99e300ef 5240static void gen_lfq(DisasContext *ctx)
76a66253 5241{
01a4afeb 5242 int rd = rD(ctx->opcode);
76db3ba4
AJ
5243 TCGv t0;
5244 gen_set_access_type(ctx, ACCESS_FLOAT);
5245 t0 = tcg_temp_new();
5246 gen_addr_imm_index(ctx, t0, 0);
5247 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5248 gen_addr_add(ctx, t0, t0, 8);
5249 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5250 tcg_temp_free(t0);
76a66253
JM
5251}
5252
5253/* lfqu */
99e300ef 5254static void gen_lfqu(DisasContext *ctx)
76a66253
JM
5255{
5256 int ra = rA(ctx->opcode);
01a4afeb 5257 int rd = rD(ctx->opcode);
76db3ba4
AJ
5258 TCGv t0, t1;
5259 gen_set_access_type(ctx, ACCESS_FLOAT);
5260 t0 = tcg_temp_new();
5261 t1 = tcg_temp_new();
5262 gen_addr_imm_index(ctx, t0, 0);
5263 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5264 gen_addr_add(ctx, t1, t0, 8);
5265 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
76a66253 5266 if (ra != 0)
01a4afeb
AJ
5267 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5268 tcg_temp_free(t0);
5269 tcg_temp_free(t1);
76a66253
JM
5270}
5271
5272/* lfqux */
99e300ef 5273static void gen_lfqux(DisasContext *ctx)
76a66253
JM
5274{
5275 int ra = rA(ctx->opcode);
01a4afeb 5276 int rd = rD(ctx->opcode);
76db3ba4
AJ
5277 gen_set_access_type(ctx, ACCESS_FLOAT);
5278 TCGv t0, t1;
5279 t0 = tcg_temp_new();
5280 gen_addr_reg_index(ctx, t0);
5281 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5282 t1 = tcg_temp_new();
5283 gen_addr_add(ctx, t1, t0, 8);
5284 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5285 tcg_temp_free(t1);
76a66253 5286 if (ra != 0)
01a4afeb
AJ
5287 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5288 tcg_temp_free(t0);
76a66253
JM
5289}
5290
5291/* lfqx */
99e300ef 5292static void gen_lfqx(DisasContext *ctx)
76a66253 5293{
01a4afeb 5294 int rd = rD(ctx->opcode);
76db3ba4
AJ
5295 TCGv t0;
5296 gen_set_access_type(ctx, ACCESS_FLOAT);
5297 t0 = tcg_temp_new();
5298 gen_addr_reg_index(ctx, t0);
5299 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5300 gen_addr_add(ctx, t0, t0, 8);
5301 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5302 tcg_temp_free(t0);
76a66253
JM
5303}
5304
5305/* stfq */
99e300ef 5306static void gen_stfq(DisasContext *ctx)
76a66253 5307{
01a4afeb 5308 int rd = rD(ctx->opcode);
76db3ba4
AJ
5309 TCGv t0;
5310 gen_set_access_type(ctx, ACCESS_FLOAT);
5311 t0 = tcg_temp_new();
5312 gen_addr_imm_index(ctx, t0, 0);
5313 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5314 gen_addr_add(ctx, t0, t0, 8);
5315 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5316 tcg_temp_free(t0);
76a66253
JM
5317}
5318
5319/* stfqu */
99e300ef 5320static void gen_stfqu(DisasContext *ctx)
76a66253
JM
5321{
5322 int ra = rA(ctx->opcode);
01a4afeb 5323 int rd = rD(ctx->opcode);
76db3ba4
AJ
5324 TCGv t0, t1;
5325 gen_set_access_type(ctx, ACCESS_FLOAT);
5326 t0 = tcg_temp_new();
5327 gen_addr_imm_index(ctx, t0, 0);
5328 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5329 t1 = tcg_temp_new();
5330 gen_addr_add(ctx, t1, t0, 8);
5331 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5332 tcg_temp_free(t1);
76a66253 5333 if (ra != 0)
01a4afeb
AJ
5334 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5335 tcg_temp_free(t0);
76a66253
JM
5336}
5337
5338/* stfqux */
99e300ef 5339static void gen_stfqux(DisasContext *ctx)
76a66253
JM
5340{
5341 int ra = rA(ctx->opcode);
01a4afeb 5342 int rd = rD(ctx->opcode);
76db3ba4
AJ
5343 TCGv t0, t1;
5344 gen_set_access_type(ctx, ACCESS_FLOAT);
5345 t0 = tcg_temp_new();
5346 gen_addr_reg_index(ctx, t0);
5347 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5348 t1 = tcg_temp_new();
5349 gen_addr_add(ctx, t1, t0, 8);
5350 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5351 tcg_temp_free(t1);
76a66253 5352 if (ra != 0)
01a4afeb
AJ
5353 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5354 tcg_temp_free(t0);
76a66253
JM
5355}
5356
5357/* stfqx */
99e300ef 5358static void gen_stfqx(DisasContext *ctx)
76a66253 5359{
01a4afeb 5360 int rd = rD(ctx->opcode);
76db3ba4
AJ
5361 TCGv t0;
5362 gen_set_access_type(ctx, ACCESS_FLOAT);
5363 t0 = tcg_temp_new();
5364 gen_addr_reg_index(ctx, t0);
5365 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5366 gen_addr_add(ctx, t0, t0, 8);
5367 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
01a4afeb 5368 tcg_temp_free(t0);
76a66253
JM
5369}
5370
5371/* BookE specific instructions */
99e300ef 5372
54623277 5373/* XXX: not implemented on 440 ? */
99e300ef 5374static void gen_mfapidi(DisasContext *ctx)
76a66253
JM
5375{
5376 /* XXX: TODO */
e06fcd75 5377 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253
JM
5378}
5379
2662a059 5380/* XXX: not implemented on 440 ? */
99e300ef 5381static void gen_tlbiva(DisasContext *ctx)
76a66253
JM
5382{
5383#if defined(CONFIG_USER_ONLY)
e06fcd75 5384 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5385#else
74d37793 5386 TCGv t0;
76db3ba4 5387 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5388 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5389 return;
5390 }
ec72e276 5391 t0 = tcg_temp_new();
76db3ba4 5392 gen_addr_reg_index(ctx, t0);
c6c7cf05 5393 gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]);
74d37793 5394 tcg_temp_free(t0);
76a66253
JM
5395#endif
5396}
5397
5398/* All 405 MAC instructions are translated here */
636aa200
BS
5399static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5400 int ra, int rb, int rt, int Rc)
76a66253 5401{
182608d4
AJ
5402 TCGv t0, t1;
5403
a7812ae4
PB
5404 t0 = tcg_temp_local_new();
5405 t1 = tcg_temp_local_new();
182608d4 5406
76a66253
JM
5407 switch (opc3 & 0x0D) {
5408 case 0x05:
5409 /* macchw - macchw. - macchwo - macchwo. */
5410 /* macchws - macchws. - macchwso - macchwso. */
5411 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5412 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5413 /* mulchw - mulchw. */
182608d4
AJ
5414 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5415 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5416 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5417 break;
5418 case 0x04:
5419 /* macchwu - macchwu. - macchwuo - macchwuo. */
5420 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5421 /* mulchwu - mulchwu. */
182608d4
AJ
5422 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5423 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5424 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5425 break;
5426 case 0x01:
5427 /* machhw - machhw. - machhwo - machhwo. */
5428 /* machhws - machhws. - machhwso - machhwso. */
5429 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5430 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5431 /* mulhhw - mulhhw. */
182608d4
AJ
5432 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5433 tcg_gen_ext16s_tl(t0, t0);
5434 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5435 tcg_gen_ext16s_tl(t1, t1);
76a66253
JM
5436 break;
5437 case 0x00:
5438 /* machhwu - machhwu. - machhwuo - machhwuo. */
5439 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5440 /* mulhhwu - mulhhwu. */
182608d4
AJ
5441 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5442 tcg_gen_ext16u_tl(t0, t0);
5443 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5444 tcg_gen_ext16u_tl(t1, t1);
76a66253
JM
5445 break;
5446 case 0x0D:
5447 /* maclhw - maclhw. - maclhwo - maclhwo. */
5448 /* maclhws - maclhws. - maclhwso - maclhwso. */
5449 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5450 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5451 /* mullhw - mullhw. */
182608d4
AJ
5452 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5453 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
76a66253
JM
5454 break;
5455 case 0x0C:
5456 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5457 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5458 /* mullhwu - mullhwu. */
182608d4
AJ
5459 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5460 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
76a66253
JM
5461 break;
5462 }
76a66253 5463 if (opc2 & 0x04) {
182608d4
AJ
5464 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5465 tcg_gen_mul_tl(t1, t0, t1);
5466 if (opc2 & 0x02) {
5467 /* nmultiply-and-accumulate (0x0E) */
5468 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5469 } else {
5470 /* multiply-and-accumulate (0x0C) */
5471 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5472 }
5473
5474 if (opc3 & 0x12) {
5475 /* Check overflow and/or saturate */
5476 int l1 = gen_new_label();
5477
5478 if (opc3 & 0x10) {
5479 /* Start with XER OV disabled, the most likely case */
da91a00f 5480 tcg_gen_movi_tl(cpu_ov, 0);
182608d4
AJ
5481 }
5482 if (opc3 & 0x01) {
5483 /* Signed */
5484 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5485 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5486 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5487 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
bdc4e053 5488 if (opc3 & 0x02) {
182608d4
AJ
5489 /* Saturate */
5490 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5491 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5492 }
5493 } else {
5494 /* Unsigned */
5495 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
bdc4e053 5496 if (opc3 & 0x02) {
182608d4
AJ
5497 /* Saturate */
5498 tcg_gen_movi_tl(t0, UINT32_MAX);
5499 }
5500 }
5501 if (opc3 & 0x10) {
5502 /* Check overflow */
da91a00f
RH
5503 tcg_gen_movi_tl(cpu_ov, 1);
5504 tcg_gen_movi_tl(cpu_so, 1);
182608d4
AJ
5505 }
5506 gen_set_label(l1);
5507 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5508 }
5509 } else {
5510 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
76a66253 5511 }
182608d4
AJ
5512 tcg_temp_free(t0);
5513 tcg_temp_free(t1);
76a66253
JM
5514 if (unlikely(Rc) != 0) {
5515 /* Update Rc0 */
182608d4 5516 gen_set_Rc0(ctx, cpu_gpr[rt]);
76a66253
JM
5517 }
5518}
5519
a750fc0b 5520#define GEN_MAC_HANDLER(name, opc2, opc3) \
99e300ef 5521static void glue(gen_, name)(DisasContext *ctx) \
76a66253
JM
5522{ \
5523 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5524 rD(ctx->opcode), Rc(ctx->opcode)); \
5525}
5526
5527/* macchw - macchw. */
a750fc0b 5528GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
76a66253 5529/* macchwo - macchwo. */
a750fc0b 5530GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
76a66253 5531/* macchws - macchws. */
a750fc0b 5532GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
76a66253 5533/* macchwso - macchwso. */
a750fc0b 5534GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
76a66253 5535/* macchwsu - macchwsu. */
a750fc0b 5536GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
76a66253 5537/* macchwsuo - macchwsuo. */
a750fc0b 5538GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
76a66253 5539/* macchwu - macchwu. */
a750fc0b 5540GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
76a66253 5541/* macchwuo - macchwuo. */
a750fc0b 5542GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
76a66253 5543/* machhw - machhw. */
a750fc0b 5544GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
76a66253 5545/* machhwo - machhwo. */
a750fc0b 5546GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
76a66253 5547/* machhws - machhws. */
a750fc0b 5548GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
76a66253 5549/* machhwso - machhwso. */
a750fc0b 5550GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
76a66253 5551/* machhwsu - machhwsu. */
a750fc0b 5552GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
76a66253 5553/* machhwsuo - machhwsuo. */
a750fc0b 5554GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
76a66253 5555/* machhwu - machhwu. */
a750fc0b 5556GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
76a66253 5557/* machhwuo - machhwuo. */
a750fc0b 5558GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
76a66253 5559/* maclhw - maclhw. */
a750fc0b 5560GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
76a66253 5561/* maclhwo - maclhwo. */
a750fc0b 5562GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
76a66253 5563/* maclhws - maclhws. */
a750fc0b 5564GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
76a66253 5565/* maclhwso - maclhwso. */
a750fc0b 5566GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
76a66253 5567/* maclhwu - maclhwu. */
a750fc0b 5568GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
76a66253 5569/* maclhwuo - maclhwuo. */
a750fc0b 5570GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
76a66253 5571/* maclhwsu - maclhwsu. */
a750fc0b 5572GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
76a66253 5573/* maclhwsuo - maclhwsuo. */
a750fc0b 5574GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
76a66253 5575/* nmacchw - nmacchw. */
a750fc0b 5576GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
76a66253 5577/* nmacchwo - nmacchwo. */
a750fc0b 5578GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
76a66253 5579/* nmacchws - nmacchws. */
a750fc0b 5580GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
76a66253 5581/* nmacchwso - nmacchwso. */
a750fc0b 5582GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
76a66253 5583/* nmachhw - nmachhw. */
a750fc0b 5584GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
76a66253 5585/* nmachhwo - nmachhwo. */
a750fc0b 5586GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
76a66253 5587/* nmachhws - nmachhws. */
a750fc0b 5588GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
76a66253 5589/* nmachhwso - nmachhwso. */
a750fc0b 5590GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
76a66253 5591/* nmaclhw - nmaclhw. */
a750fc0b 5592GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
76a66253 5593/* nmaclhwo - nmaclhwo. */
a750fc0b 5594GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
76a66253 5595/* nmaclhws - nmaclhws. */
a750fc0b 5596GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
76a66253 5597/* nmaclhwso - nmaclhwso. */
a750fc0b 5598GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
76a66253
JM
5599
5600/* mulchw - mulchw. */
a750fc0b 5601GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
76a66253 5602/* mulchwu - mulchwu. */
a750fc0b 5603GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
76a66253 5604/* mulhhw - mulhhw. */
a750fc0b 5605GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
76a66253 5606/* mulhhwu - mulhhwu. */
a750fc0b 5607GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
76a66253 5608/* mullhw - mullhw. */
a750fc0b 5609GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
76a66253 5610/* mullhwu - mullhwu. */
a750fc0b 5611GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
76a66253
JM
5612
5613/* mfdcr */
99e300ef 5614static void gen_mfdcr(DisasContext *ctx)
76a66253
JM
5615{
5616#if defined(CONFIG_USER_ONLY)
e06fcd75 5617 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 5618#else
06dca6a7 5619 TCGv dcrn;
76db3ba4 5620 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5621 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
5622 return;
5623 }
06dca6a7
AJ
5624 /* NIP cannot be restored if the memory exception comes from an helper */
5625 gen_update_nip(ctx, ctx->nip - 4);
5626 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 5627 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn);
06dca6a7 5628 tcg_temp_free(dcrn);
76a66253
JM
5629#endif
5630}
5631
5632/* mtdcr */
99e300ef 5633static void gen_mtdcr(DisasContext *ctx)
76a66253
JM
5634{
5635#if defined(CONFIG_USER_ONLY)
e06fcd75 5636 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253 5637#else
06dca6a7 5638 TCGv dcrn;
76db3ba4 5639 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5640 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
76a66253
JM
5641 return;
5642 }
06dca6a7
AJ
5643 /* NIP cannot be restored if the memory exception comes from an helper */
5644 gen_update_nip(ctx, ctx->nip - 4);
5645 dcrn = tcg_const_tl(SPR(ctx->opcode));
d0f1562d 5646 gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]);
06dca6a7 5647 tcg_temp_free(dcrn);
a42bd6cc
JM
5648#endif
5649}
5650
5651/* mfdcrx */
2662a059 5652/* XXX: not implemented on 440 ? */
99e300ef 5653static void gen_mfdcrx(DisasContext *ctx)
a42bd6cc
JM
5654{
5655#if defined(CONFIG_USER_ONLY)
e06fcd75 5656 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 5657#else
76db3ba4 5658 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5659 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
5660 return;
5661 }
06dca6a7
AJ
5662 /* NIP cannot be restored if the memory exception comes from an helper */
5663 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
5664 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
5665 cpu_gpr[rA(ctx->opcode)]);
a750fc0b 5666 /* Note: Rc update flag set leads to undefined state of Rc0 */
a42bd6cc
JM
5667#endif
5668}
5669
5670/* mtdcrx */
2662a059 5671/* XXX: not implemented on 440 ? */
99e300ef 5672static void gen_mtdcrx(DisasContext *ctx)
a42bd6cc
JM
5673{
5674#if defined(CONFIG_USER_ONLY)
e06fcd75 5675 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc 5676#else
76db3ba4 5677 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5678 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
a42bd6cc
JM
5679 return;
5680 }
06dca6a7
AJ
5681 /* NIP cannot be restored if the memory exception comes from an helper */
5682 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
5683 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
5684 cpu_gpr[rS(ctx->opcode)]);
a750fc0b 5685 /* Note: Rc update flag set leads to undefined state of Rc0 */
76a66253
JM
5686#endif
5687}
5688
a750fc0b 5689/* mfdcrux (PPC 460) : user-mode access to DCR */
99e300ef 5690static void gen_mfdcrux(DisasContext *ctx)
a750fc0b 5691{
06dca6a7
AJ
5692 /* NIP cannot be restored if the memory exception comes from an helper */
5693 gen_update_nip(ctx, ctx->nip - 4);
d0f1562d
BS
5694 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env,
5695 cpu_gpr[rA(ctx->opcode)]);
a750fc0b
JM
5696 /* Note: Rc update flag set leads to undefined state of Rc0 */
5697}
5698
5699/* mtdcrux (PPC 460) : user-mode access to DCR */
99e300ef 5700static void gen_mtdcrux(DisasContext *ctx)
a750fc0b 5701{
06dca6a7
AJ
5702 /* NIP cannot be restored if the memory exception comes from an helper */
5703 gen_update_nip(ctx, ctx->nip - 4);
975e5463 5704 gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)],
d0f1562d 5705 cpu_gpr[rS(ctx->opcode)]);
a750fc0b
JM
5706 /* Note: Rc update flag set leads to undefined state of Rc0 */
5707}
5708
76a66253 5709/* dccci */
99e300ef 5710static void gen_dccci(DisasContext *ctx)
76a66253
JM
5711{
5712#if defined(CONFIG_USER_ONLY)
e06fcd75 5713 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5714#else
76db3ba4 5715 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5716 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5717 return;
5718 }
5719 /* interpreted as no-op */
5720#endif
5721}
5722
5723/* dcread */
99e300ef 5724static void gen_dcread(DisasContext *ctx)
76a66253
JM
5725{
5726#if defined(CONFIG_USER_ONLY)
e06fcd75 5727 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5728#else
b61f2753 5729 TCGv EA, val;
76db3ba4 5730 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5731 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5732 return;
5733 }
76db3ba4 5734 gen_set_access_type(ctx, ACCESS_CACHE);
a7812ae4 5735 EA = tcg_temp_new();
76db3ba4 5736 gen_addr_reg_index(ctx, EA);
a7812ae4 5737 val = tcg_temp_new();
76db3ba4 5738 gen_qemu_ld32u(ctx, val, EA);
b61f2753
AJ
5739 tcg_temp_free(val);
5740 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5741 tcg_temp_free(EA);
76a66253
JM
5742#endif
5743}
5744
5745/* icbt */
e8eaa2c0 5746static void gen_icbt_40x(DisasContext *ctx)
76a66253
JM
5747{
5748 /* interpreted as no-op */
5749 /* XXX: specification say this is treated as a load by the MMU
5750 * but does not generate any exception
5751 */
5752}
5753
5754/* iccci */
99e300ef 5755static void gen_iccci(DisasContext *ctx)
76a66253
JM
5756{
5757#if defined(CONFIG_USER_ONLY)
e06fcd75 5758 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5759#else
76db3ba4 5760 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5761 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5762 return;
5763 }
5764 /* interpreted as no-op */
5765#endif
5766}
5767
5768/* icread */
99e300ef 5769static void gen_icread(DisasContext *ctx)
76a66253
JM
5770{
5771#if defined(CONFIG_USER_ONLY)
e06fcd75 5772 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5773#else
76db3ba4 5774 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5775 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5776 return;
5777 }
5778 /* interpreted as no-op */
5779#endif
5780}
5781
76db3ba4 5782/* rfci (mem_idx only) */
e8eaa2c0 5783static void gen_rfci_40x(DisasContext *ctx)
a42bd6cc
JM
5784{
5785#if defined(CONFIG_USER_ONLY)
e06fcd75 5786 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 5787#else
76db3ba4 5788 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5789 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
5790 return;
5791 }
5792 /* Restore CPU state */
e5f17ac6 5793 gen_helper_40x_rfci(cpu_env);
e06fcd75 5794 gen_sync_exception(ctx);
a42bd6cc
JM
5795#endif
5796}
5797
99e300ef 5798static void gen_rfci(DisasContext *ctx)
a42bd6cc
JM
5799{
5800#if defined(CONFIG_USER_ONLY)
e06fcd75 5801 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 5802#else
76db3ba4 5803 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5804 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
5805 return;
5806 }
5807 /* Restore CPU state */
e5f17ac6 5808 gen_helper_rfci(cpu_env);
e06fcd75 5809 gen_sync_exception(ctx);
a42bd6cc
JM
5810#endif
5811}
5812
5813/* BookE specific */
99e300ef 5814
54623277 5815/* XXX: not implemented on 440 ? */
99e300ef 5816static void gen_rfdi(DisasContext *ctx)
76a66253
JM
5817{
5818#if defined(CONFIG_USER_ONLY)
e06fcd75 5819 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5820#else
76db3ba4 5821 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5822 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5823 return;
5824 }
5825 /* Restore CPU state */
e5f17ac6 5826 gen_helper_rfdi(cpu_env);
e06fcd75 5827 gen_sync_exception(ctx);
76a66253
JM
5828#endif
5829}
5830
2662a059 5831/* XXX: not implemented on 440 ? */
99e300ef 5832static void gen_rfmci(DisasContext *ctx)
a42bd6cc
JM
5833{
5834#if defined(CONFIG_USER_ONLY)
e06fcd75 5835 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc 5836#else
76db3ba4 5837 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5838 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
a42bd6cc
JM
5839 return;
5840 }
5841 /* Restore CPU state */
e5f17ac6 5842 gen_helper_rfmci(cpu_env);
e06fcd75 5843 gen_sync_exception(ctx);
a42bd6cc
JM
5844#endif
5845}
5eb7995e 5846
d9bce9d9 5847/* TLB management - PowerPC 405 implementation */
e8eaa2c0 5848
54623277 5849/* tlbre */
e8eaa2c0 5850static void gen_tlbre_40x(DisasContext *ctx)
76a66253
JM
5851{
5852#if defined(CONFIG_USER_ONLY)
e06fcd75 5853 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5854#else
76db3ba4 5855 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5856 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5857 return;
5858 }
5859 switch (rB(ctx->opcode)) {
5860 case 0:
c6c7cf05
BS
5861 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env,
5862 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5863 break;
5864 case 1:
c6c7cf05
BS
5865 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env,
5866 cpu_gpr[rA(ctx->opcode)]);
76a66253
JM
5867 break;
5868 default:
e06fcd75 5869 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 5870 break;
9a64fbe4 5871 }
76a66253
JM
5872#endif
5873}
5874
d9bce9d9 5875/* tlbsx - tlbsx. */
e8eaa2c0 5876static void gen_tlbsx_40x(DisasContext *ctx)
76a66253
JM
5877{
5878#if defined(CONFIG_USER_ONLY)
e06fcd75 5879 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5880#else
74d37793 5881 TCGv t0;
76db3ba4 5882 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5883 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5884 return;
5885 }
74d37793 5886 t0 = tcg_temp_new();
76db3ba4 5887 gen_addr_reg_index(ctx, t0);
c6c7cf05 5888 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
5889 tcg_temp_free(t0);
5890 if (Rc(ctx->opcode)) {
5891 int l1 = gen_new_label();
da91a00f 5892 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
5893 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
5894 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
5895 gen_set_label(l1);
5896 }
76a66253 5897#endif
79aceca5
FB
5898}
5899
76a66253 5900/* tlbwe */
e8eaa2c0 5901static void gen_tlbwe_40x(DisasContext *ctx)
79aceca5 5902{
76a66253 5903#if defined(CONFIG_USER_ONLY)
e06fcd75 5904 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 5905#else
76db3ba4 5906 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5907 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
5908 return;
5909 }
5910 switch (rB(ctx->opcode)) {
5911 case 0:
c6c7cf05
BS
5912 gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)],
5913 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
5914 break;
5915 case 1:
c6c7cf05
BS
5916 gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)],
5917 cpu_gpr[rS(ctx->opcode)]);
76a66253
JM
5918 break;
5919 default:
e06fcd75 5920 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
76a66253 5921 break;
9a64fbe4 5922 }
76a66253
JM
5923#endif
5924}
5925
a4bb6c3e 5926/* TLB management - PowerPC 440 implementation */
e8eaa2c0 5927
54623277 5928/* tlbre */
e8eaa2c0 5929static void gen_tlbre_440(DisasContext *ctx)
5eb7995e
JM
5930{
5931#if defined(CONFIG_USER_ONLY)
e06fcd75 5932 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 5933#else
76db3ba4 5934 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5935 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
5936 return;
5937 }
5938 switch (rB(ctx->opcode)) {
5939 case 0:
5eb7995e 5940 case 1:
5eb7995e 5941 case 2:
74d37793
AJ
5942 {
5943 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
5944 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env,
5945 t0, cpu_gpr[rA(ctx->opcode)]);
74d37793
AJ
5946 tcg_temp_free_i32(t0);
5947 }
5eb7995e
JM
5948 break;
5949 default:
e06fcd75 5950 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
5951 break;
5952 }
5953#endif
5954}
5955
5956/* tlbsx - tlbsx. */
e8eaa2c0 5957static void gen_tlbsx_440(DisasContext *ctx)
5eb7995e
JM
5958{
5959#if defined(CONFIG_USER_ONLY)
e06fcd75 5960 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 5961#else
74d37793 5962 TCGv t0;
76db3ba4 5963 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5964 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
5965 return;
5966 }
74d37793 5967 t0 = tcg_temp_new();
76db3ba4 5968 gen_addr_reg_index(ctx, t0);
c6c7cf05 5969 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0);
74d37793
AJ
5970 tcg_temp_free(t0);
5971 if (Rc(ctx->opcode)) {
5972 int l1 = gen_new_label();
da91a00f 5973 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so);
74d37793
AJ
5974 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
5975 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
5976 gen_set_label(l1);
5977 }
5eb7995e
JM
5978#endif
5979}
5980
5981/* tlbwe */
e8eaa2c0 5982static void gen_tlbwe_440(DisasContext *ctx)
5eb7995e
JM
5983{
5984#if defined(CONFIG_USER_ONLY)
e06fcd75 5985 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e 5986#else
76db3ba4 5987 if (unlikely(!ctx->mem_idx)) {
e06fcd75 5988 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5eb7995e
JM
5989 return;
5990 }
5991 switch (rB(ctx->opcode)) {
5992 case 0:
5eb7995e 5993 case 1:
5eb7995e 5994 case 2:
74d37793
AJ
5995 {
5996 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
c6c7cf05
BS
5997 gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)],
5998 cpu_gpr[rS(ctx->opcode)]);
74d37793
AJ
5999 tcg_temp_free_i32(t0);
6000 }
5eb7995e
JM
6001 break;
6002 default:
e06fcd75 6003 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5eb7995e
JM
6004 break;
6005 }
6006#endif
6007}
6008
01662f3e
AG
6009/* TLB management - PowerPC BookE 2.06 implementation */
6010
6011/* tlbre */
6012static void gen_tlbre_booke206(DisasContext *ctx)
6013{
6014#if defined(CONFIG_USER_ONLY)
6015 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6016#else
6017 if (unlikely(!ctx->mem_idx)) {
6018 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6019 return;
6020 }
6021
c6c7cf05 6022 gen_helper_booke206_tlbre(cpu_env);
01662f3e
AG
6023#endif
6024}
6025
6026/* tlbsx - tlbsx. */
6027static void gen_tlbsx_booke206(DisasContext *ctx)
6028{
6029#if defined(CONFIG_USER_ONLY)
6030 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6031#else
6032 TCGv t0;
6033 if (unlikely(!ctx->mem_idx)) {
6034 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6035 return;
6036 }
6037
6038 if (rA(ctx->opcode)) {
6039 t0 = tcg_temp_new();
6040 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6041 } else {
6042 t0 = tcg_const_tl(0);
6043 }
6044
6045 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
c6c7cf05 6046 gen_helper_booke206_tlbsx(cpu_env, t0);
01662f3e
AG
6047#endif
6048}
6049
6050/* tlbwe */
6051static void gen_tlbwe_booke206(DisasContext *ctx)
6052{
6053#if defined(CONFIG_USER_ONLY)
6054 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6055#else
6056 if (unlikely(!ctx->mem_idx)) {
6057 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6058 return;
6059 }
3f162d11 6060 gen_update_nip(ctx, ctx->nip - 4);
c6c7cf05 6061 gen_helper_booke206_tlbwe(cpu_env);
01662f3e
AG
6062#endif
6063}
6064
6065static void gen_tlbivax_booke206(DisasContext *ctx)
6066{
6067#if defined(CONFIG_USER_ONLY)
6068 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6069#else
6070 TCGv t0;
6071 if (unlikely(!ctx->mem_idx)) {
6072 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6073 return;
6074 }
6075
6076 t0 = tcg_temp_new();
6077 gen_addr_reg_index(ctx, t0);
6078
c6c7cf05 6079 gen_helper_booke206_tlbivax(cpu_env, t0);
01662f3e
AG
6080#endif
6081}
6082
6d3db821
AG
6083static void gen_tlbilx_booke206(DisasContext *ctx)
6084{
6085#if defined(CONFIG_USER_ONLY)
6086 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6087#else
6088 TCGv t0;
6089 if (unlikely(!ctx->mem_idx)) {
6090 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6091 return;
6092 }
6093
6094 t0 = tcg_temp_new();
6095 gen_addr_reg_index(ctx, t0);
6096
6097 switch((ctx->opcode >> 21) & 0x3) {
6098 case 0:
c6c7cf05 6099 gen_helper_booke206_tlbilx0(cpu_env, t0);
6d3db821
AG
6100 break;
6101 case 1:
c6c7cf05 6102 gen_helper_booke206_tlbilx1(cpu_env, t0);
6d3db821
AG
6103 break;
6104 case 3:
c6c7cf05 6105 gen_helper_booke206_tlbilx3(cpu_env, t0);
6d3db821
AG
6106 break;
6107 default:
6108 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6109 break;
6110 }
6111
6112 tcg_temp_free(t0);
6113#endif
6114}
6115
01662f3e 6116
76a66253 6117/* wrtee */
99e300ef 6118static void gen_wrtee(DisasContext *ctx)
76a66253
JM
6119{
6120#if defined(CONFIG_USER_ONLY)
e06fcd75 6121 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6122#else
6527f6ea 6123 TCGv t0;
76db3ba4 6124 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6125 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6126 return;
6127 }
6527f6ea
AJ
6128 t0 = tcg_temp_new();
6129 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6130 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6131 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6132 tcg_temp_free(t0);
dee96f6c
JM
6133 /* Stop translation to have a chance to raise an exception
6134 * if we just set msr_ee to 1
6135 */
e06fcd75 6136 gen_stop_exception(ctx);
76a66253
JM
6137#endif
6138}
6139
6140/* wrteei */
99e300ef 6141static void gen_wrteei(DisasContext *ctx)
76a66253
JM
6142{
6143#if defined(CONFIG_USER_ONLY)
e06fcd75 6144 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253 6145#else
76db3ba4 6146 if (unlikely(!ctx->mem_idx)) {
e06fcd75 6147 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
76a66253
JM
6148 return;
6149 }
fbe73008 6150 if (ctx->opcode & 0x00008000) {
6527f6ea
AJ
6151 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6152 /* Stop translation to have a chance to raise an exception */
e06fcd75 6153 gen_stop_exception(ctx);
6527f6ea 6154 } else {
1b6e5f99 6155 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6527f6ea 6156 }
76a66253
JM
6157#endif
6158}
6159
08e46e54 6160/* PowerPC 440 specific instructions */
99e300ef 6161
54623277 6162/* dlmzb */
99e300ef 6163static void gen_dlmzb(DisasContext *ctx)
76a66253 6164{
ef0d51af 6165 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
d15f74fb
BS
6166 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env,
6167 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
ef0d51af 6168 tcg_temp_free_i32(t0);
76a66253
JM
6169}
6170
6171/* mbar replaces eieio on 440 */
99e300ef 6172static void gen_mbar(DisasContext *ctx)
76a66253
JM
6173{
6174 /* interpreted as no-op */
6175}
6176
6177/* msync replaces sync on 440 */
dcb2b9e1 6178static void gen_msync_4xx(DisasContext *ctx)
76a66253
JM
6179{
6180 /* interpreted as no-op */
6181}
6182
6183/* icbt */
e8eaa2c0 6184static void gen_icbt_440(DisasContext *ctx)
76a66253
JM
6185{
6186 /* interpreted as no-op */
6187 /* XXX: specification say this is treated as a load by the MMU
6188 * but does not generate any exception
6189 */
79aceca5
FB
6190}
6191
9e0b5cb1
AG
6192/* Embedded.Processor Control */
6193
6194static void gen_msgclr(DisasContext *ctx)
6195{
6196#if defined(CONFIG_USER_ONLY)
6197 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6198#else
6199 if (unlikely(ctx->mem_idx == 0)) {
6200 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6201 return;
6202 }
6203
e5f17ac6 6204 gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]);
9e0b5cb1
AG
6205#endif
6206}
6207
d5d11a39
AG
6208static void gen_msgsnd(DisasContext *ctx)
6209{
6210#if defined(CONFIG_USER_ONLY)
6211 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6212#else
6213 if (unlikely(ctx->mem_idx == 0)) {
6214 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6215 return;
6216 }
6217
6218 gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]);
6219#endif
6220}
6221
a9d9eb8f
JM
6222/*** Altivec vector extension ***/
6223/* Altivec registers moves */
a9d9eb8f 6224
636aa200 6225static inline TCGv_ptr gen_avr_ptr(int reg)
564e571a 6226{
e4704b3b 6227 TCGv_ptr r = tcg_temp_new_ptr();
564e571a
AJ
6228 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6229 return r;
6230}
6231
a9d9eb8f 6232#define GEN_VR_LDX(name, opc2, opc3) \
99e300ef 6233static void glue(gen_, name)(DisasContext *ctx) \
a9d9eb8f 6234{ \
fe1e5c53 6235 TCGv EA; \
a9d9eb8f 6236 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6237 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6238 return; \
6239 } \
76db3ba4 6240 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6241 EA = tcg_temp_new(); \
76db3ba4 6242 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6243 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6244 if (ctx->le_mode) { \
6245 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6246 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6247 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6248 } else { \
76db3ba4 6249 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6250 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6251 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6252 } \
6253 tcg_temp_free(EA); \
a9d9eb8f
JM
6254}
6255
6256#define GEN_VR_STX(name, opc2, opc3) \
99e300ef 6257static void gen_st##name(DisasContext *ctx) \
a9d9eb8f 6258{ \
fe1e5c53 6259 TCGv EA; \
a9d9eb8f 6260 if (unlikely(!ctx->altivec_enabled)) { \
e06fcd75 6261 gen_exception(ctx, POWERPC_EXCP_VPU); \
a9d9eb8f
JM
6262 return; \
6263 } \
76db3ba4 6264 gen_set_access_type(ctx, ACCESS_INT); \
fe1e5c53 6265 EA = tcg_temp_new(); \
76db3ba4 6266 gen_addr_reg_index(ctx, EA); \
fe1e5c53 6267 tcg_gen_andi_tl(EA, EA, ~0xf); \
76db3ba4
AJ
6268 if (ctx->le_mode) { \
6269 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53 6270 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6271 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6272 } else { \
76db3ba4 6273 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
fe1e5c53 6274 tcg_gen_addi_tl(EA, EA, 8); \
76db3ba4 6275 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
fe1e5c53
AJ
6276 } \
6277 tcg_temp_free(EA); \
a9d9eb8f
JM
6278}
6279
cbfb6ae9 6280#define GEN_VR_LVE(name, opc2, opc3) \
99e300ef 6281static void gen_lve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6282 { \
6283 TCGv EA; \
6284 TCGv_ptr rs; \
6285 if (unlikely(!ctx->altivec_enabled)) { \
6286 gen_exception(ctx, POWERPC_EXCP_VPU); \
6287 return; \
6288 } \
6289 gen_set_access_type(ctx, ACCESS_INT); \
6290 EA = tcg_temp_new(); \
6291 gen_addr_reg_index(ctx, EA); \
6292 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6293 gen_helper_lve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6294 tcg_temp_free(EA); \
6295 tcg_temp_free_ptr(rs); \
6296 }
6297
6298#define GEN_VR_STVE(name, opc2, opc3) \
99e300ef 6299static void gen_stve##name(DisasContext *ctx) \
cbfb6ae9
AJ
6300 { \
6301 TCGv EA; \
6302 TCGv_ptr rs; \
6303 if (unlikely(!ctx->altivec_enabled)) { \
6304 gen_exception(ctx, POWERPC_EXCP_VPU); \
6305 return; \
6306 } \
6307 gen_set_access_type(ctx, ACCESS_INT); \
6308 EA = tcg_temp_new(); \
6309 gen_addr_reg_index(ctx, EA); \
6310 rs = gen_avr_ptr(rS(ctx->opcode)); \
2f5a189c 6311 gen_helper_stve##name(cpu_env, rs, EA); \
cbfb6ae9
AJ
6312 tcg_temp_free(EA); \
6313 tcg_temp_free_ptr(rs); \
6314 }
6315
fe1e5c53 6316GEN_VR_LDX(lvx, 0x07, 0x03);
a9d9eb8f 6317/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
fe1e5c53 6318GEN_VR_LDX(lvxl, 0x07, 0x0B);
a9d9eb8f 6319
cbfb6ae9
AJ
6320GEN_VR_LVE(bx, 0x07, 0x00);
6321GEN_VR_LVE(hx, 0x07, 0x01);
6322GEN_VR_LVE(wx, 0x07, 0x02);
6323
fe1e5c53 6324GEN_VR_STX(svx, 0x07, 0x07);
a9d9eb8f 6325/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
fe1e5c53 6326GEN_VR_STX(svxl, 0x07, 0x0F);
a9d9eb8f 6327
cbfb6ae9
AJ
6328GEN_VR_STVE(bx, 0x07, 0x04);
6329GEN_VR_STVE(hx, 0x07, 0x05);
6330GEN_VR_STVE(wx, 0x07, 0x06);
6331
99e300ef 6332static void gen_lvsl(DisasContext *ctx)
bf8d8ded
AJ
6333{
6334 TCGv_ptr rd;
6335 TCGv EA;
6336 if (unlikely(!ctx->altivec_enabled)) {
6337 gen_exception(ctx, POWERPC_EXCP_VPU);
6338 return;
6339 }
6340 EA = tcg_temp_new();
6341 gen_addr_reg_index(ctx, EA);
6342 rd = gen_avr_ptr(rD(ctx->opcode));
6343 gen_helper_lvsl(rd, EA);
6344 tcg_temp_free(EA);
6345 tcg_temp_free_ptr(rd);
6346}
6347
99e300ef 6348static void gen_lvsr(DisasContext *ctx)
bf8d8ded
AJ
6349{
6350 TCGv_ptr rd;
6351 TCGv EA;
6352 if (unlikely(!ctx->altivec_enabled)) {
6353 gen_exception(ctx, POWERPC_EXCP_VPU);
6354 return;
6355 }
6356 EA = tcg_temp_new();
6357 gen_addr_reg_index(ctx, EA);
6358 rd = gen_avr_ptr(rD(ctx->opcode));
6359 gen_helper_lvsr(rd, EA);
6360 tcg_temp_free(EA);
6361 tcg_temp_free_ptr(rd);
6362}
6363
99e300ef 6364static void gen_mfvscr(DisasContext *ctx)
785f451b
AJ
6365{
6366 TCGv_i32 t;
6367 if (unlikely(!ctx->altivec_enabled)) {
6368 gen_exception(ctx, POWERPC_EXCP_VPU);
6369 return;
6370 }
6371 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6372 t = tcg_temp_new_i32();
1328c2bf 6373 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr));
785f451b 6374 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
fce5ecb7 6375 tcg_temp_free_i32(t);
785f451b
AJ
6376}
6377
99e300ef 6378static void gen_mtvscr(DisasContext *ctx)
785f451b 6379{
6e87b7c7 6380 TCGv_ptr p;
785f451b
AJ
6381 if (unlikely(!ctx->altivec_enabled)) {
6382 gen_exception(ctx, POWERPC_EXCP_VPU);
6383 return;
6384 }
6e87b7c7 6385 p = gen_avr_ptr(rD(ctx->opcode));
d15f74fb 6386 gen_helper_mtvscr(cpu_env, p);
6e87b7c7 6387 tcg_temp_free_ptr(p);
785f451b
AJ
6388}
6389
7a9b96cf
AJ
6390/* Logical operations */
6391#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
99e300ef 6392static void glue(gen_, name)(DisasContext *ctx) \
7a9b96cf
AJ
6393{ \
6394 if (unlikely(!ctx->altivec_enabled)) { \
6395 gen_exception(ctx, POWERPC_EXCP_VPU); \
6396 return; \
6397 } \
6398 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6399 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6400}
6401
6402GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6403GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6404GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6405GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6406GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6407
8e27dd6f 6408#define GEN_VXFORM(name, opc2, opc3) \
99e300ef 6409static void glue(gen_, name)(DisasContext *ctx) \
8e27dd6f
AJ
6410{ \
6411 TCGv_ptr ra, rb, rd; \
6412 if (unlikely(!ctx->altivec_enabled)) { \
6413 gen_exception(ctx, POWERPC_EXCP_VPU); \
6414 return; \
6415 } \
6416 ra = gen_avr_ptr(rA(ctx->opcode)); \
6417 rb = gen_avr_ptr(rB(ctx->opcode)); \
6418 rd = gen_avr_ptr(rD(ctx->opcode)); \
6419 gen_helper_##name (rd, ra, rb); \
6420 tcg_temp_free_ptr(ra); \
6421 tcg_temp_free_ptr(rb); \
6422 tcg_temp_free_ptr(rd); \
6423}
6424
d15f74fb
BS
6425#define GEN_VXFORM_ENV(name, opc2, opc3) \
6426static void glue(gen_, name)(DisasContext *ctx) \
6427{ \
6428 TCGv_ptr ra, rb, rd; \
6429 if (unlikely(!ctx->altivec_enabled)) { \
6430 gen_exception(ctx, POWERPC_EXCP_VPU); \
6431 return; \
6432 } \
6433 ra = gen_avr_ptr(rA(ctx->opcode)); \
6434 rb = gen_avr_ptr(rB(ctx->opcode)); \
6435 rd = gen_avr_ptr(rD(ctx->opcode)); \
54cddd21 6436 gen_helper_##name(cpu_env, rd, ra, rb); \
d15f74fb
BS
6437 tcg_temp_free_ptr(ra); \
6438 tcg_temp_free_ptr(rb); \
6439 tcg_temp_free_ptr(rd); \
6440}
6441
7872c51c
AJ
6442GEN_VXFORM(vaddubm, 0, 0);
6443GEN_VXFORM(vadduhm, 0, 1);
6444GEN_VXFORM(vadduwm, 0, 2);
6445GEN_VXFORM(vsububm, 0, 16);
6446GEN_VXFORM(vsubuhm, 0, 17);
6447GEN_VXFORM(vsubuwm, 0, 18);
e4039339
AJ
6448GEN_VXFORM(vmaxub, 1, 0);
6449GEN_VXFORM(vmaxuh, 1, 1);
6450GEN_VXFORM(vmaxuw, 1, 2);
6451GEN_VXFORM(vmaxsb, 1, 4);
6452GEN_VXFORM(vmaxsh, 1, 5);
6453GEN_VXFORM(vmaxsw, 1, 6);
6454GEN_VXFORM(vminub, 1, 8);
6455GEN_VXFORM(vminuh, 1, 9);
6456GEN_VXFORM(vminuw, 1, 10);
6457GEN_VXFORM(vminsb, 1, 12);
6458GEN_VXFORM(vminsh, 1, 13);
6459GEN_VXFORM(vminsw, 1, 14);
fab3cbe9
AJ
6460GEN_VXFORM(vavgub, 1, 16);
6461GEN_VXFORM(vavguh, 1, 17);
6462GEN_VXFORM(vavguw, 1, 18);
6463GEN_VXFORM(vavgsb, 1, 20);
6464GEN_VXFORM(vavgsh, 1, 21);
6465GEN_VXFORM(vavgsw, 1, 22);
3b430048
AJ
6466GEN_VXFORM(vmrghb, 6, 0);
6467GEN_VXFORM(vmrghh, 6, 1);
6468GEN_VXFORM(vmrghw, 6, 2);
6469GEN_VXFORM(vmrglb, 6, 4);
6470GEN_VXFORM(vmrglh, 6, 5);
6471GEN_VXFORM(vmrglw, 6, 6);
2c277908
AJ
6472GEN_VXFORM(vmuloub, 4, 0);
6473GEN_VXFORM(vmulouh, 4, 1);
6474GEN_VXFORM(vmulosb, 4, 4);
6475GEN_VXFORM(vmulosh, 4, 5);
6476GEN_VXFORM(vmuleub, 4, 8);
6477GEN_VXFORM(vmuleuh, 4, 9);
6478GEN_VXFORM(vmulesb, 4, 12);
6479GEN_VXFORM(vmulesh, 4, 13);
d79f0809
AJ
6480GEN_VXFORM(vslb, 2, 4);
6481GEN_VXFORM(vslh, 2, 5);
6482GEN_VXFORM(vslw, 2, 6);
07ef34c3
AJ
6483GEN_VXFORM(vsrb, 2, 8);
6484GEN_VXFORM(vsrh, 2, 9);
6485GEN_VXFORM(vsrw, 2, 10);
6486GEN_VXFORM(vsrab, 2, 12);
6487GEN_VXFORM(vsrah, 2, 13);
6488GEN_VXFORM(vsraw, 2, 14);
7b239bec
AJ
6489GEN_VXFORM(vslo, 6, 16);
6490GEN_VXFORM(vsro, 6, 17);
e343da72
AJ
6491GEN_VXFORM(vaddcuw, 0, 6);
6492GEN_VXFORM(vsubcuw, 0, 22);
d15f74fb
BS
6493GEN_VXFORM_ENV(vaddubs, 0, 8);
6494GEN_VXFORM_ENV(vadduhs, 0, 9);
6495GEN_VXFORM_ENV(vadduws, 0, 10);
6496GEN_VXFORM_ENV(vaddsbs, 0, 12);
6497GEN_VXFORM_ENV(vaddshs, 0, 13);
6498GEN_VXFORM_ENV(vaddsws, 0, 14);
6499GEN_VXFORM_ENV(vsububs, 0, 24);
6500GEN_VXFORM_ENV(vsubuhs, 0, 25);
6501GEN_VXFORM_ENV(vsubuws, 0, 26);
6502GEN_VXFORM_ENV(vsubsbs, 0, 28);
6503GEN_VXFORM_ENV(vsubshs, 0, 29);
6504GEN_VXFORM_ENV(vsubsws, 0, 30);
5e1d0985
AJ
6505GEN_VXFORM(vrlb, 2, 0);
6506GEN_VXFORM(vrlh, 2, 1);
6507GEN_VXFORM(vrlw, 2, 2);
d9430add
AJ
6508GEN_VXFORM(vsl, 2, 7);
6509GEN_VXFORM(vsr, 2, 11);
d15f74fb
BS
6510GEN_VXFORM_ENV(vpkuhum, 7, 0);
6511GEN_VXFORM_ENV(vpkuwum, 7, 1);
6512GEN_VXFORM_ENV(vpkuhus, 7, 2);
6513GEN_VXFORM_ENV(vpkuwus, 7, 3);
6514GEN_VXFORM_ENV(vpkshus, 7, 4);
6515GEN_VXFORM_ENV(vpkswus, 7, 5);
6516GEN_VXFORM_ENV(vpkshss, 7, 6);
6517GEN_VXFORM_ENV(vpkswss, 7, 7);
1dd9ffb9 6518GEN_VXFORM(vpkpx, 7, 12);
d15f74fb
BS
6519GEN_VXFORM_ENV(vsum4ubs, 4, 24);
6520GEN_VXFORM_ENV(vsum4sbs, 4, 28);
6521GEN_VXFORM_ENV(vsum4shs, 4, 25);
6522GEN_VXFORM_ENV(vsum2sws, 4, 26);
6523GEN_VXFORM_ENV(vsumsws, 4, 30);
6524GEN_VXFORM_ENV(vaddfp, 5, 0);
6525GEN_VXFORM_ENV(vsubfp, 5, 1);
6526GEN_VXFORM_ENV(vmaxfp, 5, 16);
6527GEN_VXFORM_ENV(vminfp, 5, 17);
fab3cbe9 6528
0cbcd906 6529#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
e8eaa2c0 6530static void glue(gen_, name)(DisasContext *ctx) \
0cbcd906
AJ
6531 { \
6532 TCGv_ptr ra, rb, rd; \
6533 if (unlikely(!ctx->altivec_enabled)) { \
6534 gen_exception(ctx, POWERPC_EXCP_VPU); \
6535 return; \
6536 } \
6537 ra = gen_avr_ptr(rA(ctx->opcode)); \
6538 rb = gen_avr_ptr(rB(ctx->opcode)); \
6539 rd = gen_avr_ptr(rD(ctx->opcode)); \
d15f74fb 6540 gen_helper_##opname(cpu_env, rd, ra, rb); \
0cbcd906
AJ
6541 tcg_temp_free_ptr(ra); \
6542 tcg_temp_free_ptr(rb); \
6543 tcg_temp_free_ptr(rd); \
6544 }
6545
6546#define GEN_VXRFORM(name, opc2, opc3) \
6547 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6548 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6549
1add6e23
AJ
6550GEN_VXRFORM(vcmpequb, 3, 0)
6551GEN_VXRFORM(vcmpequh, 3, 1)
6552GEN_VXRFORM(vcmpequw, 3, 2)
6553GEN_VXRFORM(vcmpgtsb, 3, 12)
6554GEN_VXRFORM(vcmpgtsh, 3, 13)
6555GEN_VXRFORM(vcmpgtsw, 3, 14)
6556GEN_VXRFORM(vcmpgtub, 3, 8)
6557GEN_VXRFORM(vcmpgtuh, 3, 9)
6558GEN_VXRFORM(vcmpgtuw, 3, 10)
819ca121
AJ
6559GEN_VXRFORM(vcmpeqfp, 3, 3)
6560GEN_VXRFORM(vcmpgefp, 3, 7)
6561GEN_VXRFORM(vcmpgtfp, 3, 11)
6562GEN_VXRFORM(vcmpbfp, 3, 15)
1add6e23 6563
c026766b 6564#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 6565static void glue(gen_, name)(DisasContext *ctx) \
c026766b
AJ
6566 { \
6567 TCGv_ptr rd; \
6568 TCGv_i32 simm; \
6569 if (unlikely(!ctx->altivec_enabled)) { \
6570 gen_exception(ctx, POWERPC_EXCP_VPU); \
6571 return; \
6572 } \
6573 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6574 rd = gen_avr_ptr(rD(ctx->opcode)); \
6575 gen_helper_##name (rd, simm); \
6576 tcg_temp_free_i32(simm); \
6577 tcg_temp_free_ptr(rd); \
6578 }
6579
6580GEN_VXFORM_SIMM(vspltisb, 6, 12);
6581GEN_VXFORM_SIMM(vspltish, 6, 13);
6582GEN_VXFORM_SIMM(vspltisw, 6, 14);
6583
de5f2484 6584#define GEN_VXFORM_NOA(name, opc2, opc3) \
99e300ef 6585static void glue(gen_, name)(DisasContext *ctx) \
de5f2484
AJ
6586 { \
6587 TCGv_ptr rb, rd; \
6588 if (unlikely(!ctx->altivec_enabled)) { \
6589 gen_exception(ctx, POWERPC_EXCP_VPU); \
6590 return; \
6591 } \
6592 rb = gen_avr_ptr(rB(ctx->opcode)); \
6593 rd = gen_avr_ptr(rD(ctx->opcode)); \
6594 gen_helper_##name (rd, rb); \
6595 tcg_temp_free_ptr(rb); \
6596 tcg_temp_free_ptr(rd); \
6597 }
6598
d15f74fb
BS
6599#define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6600static void glue(gen_, name)(DisasContext *ctx) \
6601 { \
6602 TCGv_ptr rb, rd; \
6603 \
6604 if (unlikely(!ctx->altivec_enabled)) { \
6605 gen_exception(ctx, POWERPC_EXCP_VPU); \
6606 return; \
6607 } \
6608 rb = gen_avr_ptr(rB(ctx->opcode)); \
6609 rd = gen_avr_ptr(rD(ctx->opcode)); \
6610 gen_helper_##name(cpu_env, rd, rb); \
6611 tcg_temp_free_ptr(rb); \
6612 tcg_temp_free_ptr(rd); \
6613 }
6614
6cf1c6e5
AJ
6615GEN_VXFORM_NOA(vupkhsb, 7, 8);
6616GEN_VXFORM_NOA(vupkhsh, 7, 9);
6617GEN_VXFORM_NOA(vupklsb, 7, 10);
6618GEN_VXFORM_NOA(vupklsh, 7, 11);
79f85c3a
AJ
6619GEN_VXFORM_NOA(vupkhpx, 7, 13);
6620GEN_VXFORM_NOA(vupklpx, 7, 15);
d15f74fb
BS
6621GEN_VXFORM_NOA_ENV(vrefp, 5, 4);
6622GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5);
6623GEN_VXFORM_NOA_ENV(vexptefp, 5, 6);
6624GEN_VXFORM_NOA_ENV(vlogefp, 5, 7);
6625GEN_VXFORM_NOA_ENV(vrfim, 5, 8);
6626GEN_VXFORM_NOA_ENV(vrfin, 5, 9);
6627GEN_VXFORM_NOA_ENV(vrfip, 5, 10);
6628GEN_VXFORM_NOA_ENV(vrfiz, 5, 11);
79f85c3a 6629
21d21583 6630#define GEN_VXFORM_SIMM(name, opc2, opc3) \
99e300ef 6631static void glue(gen_, name)(DisasContext *ctx) \
21d21583
AJ
6632 { \
6633 TCGv_ptr rd; \
6634 TCGv_i32 simm; \
6635 if (unlikely(!ctx->altivec_enabled)) { \
6636 gen_exception(ctx, POWERPC_EXCP_VPU); \
6637 return; \
6638 } \
6639 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6640 rd = gen_avr_ptr(rD(ctx->opcode)); \
6641 gen_helper_##name (rd, simm); \
6642 tcg_temp_free_i32(simm); \
6643 tcg_temp_free_ptr(rd); \
6644 }
6645
27a4edb3 6646#define GEN_VXFORM_UIMM(name, opc2, opc3) \
99e300ef 6647static void glue(gen_, name)(DisasContext *ctx) \
27a4edb3
AJ
6648 { \
6649 TCGv_ptr rb, rd; \
6650 TCGv_i32 uimm; \
6651 if (unlikely(!ctx->altivec_enabled)) { \
6652 gen_exception(ctx, POWERPC_EXCP_VPU); \
6653 return; \
6654 } \
6655 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6656 rb = gen_avr_ptr(rB(ctx->opcode)); \
6657 rd = gen_avr_ptr(rD(ctx->opcode)); \
6658 gen_helper_##name (rd, rb, uimm); \
6659 tcg_temp_free_i32(uimm); \
6660 tcg_temp_free_ptr(rb); \
6661 tcg_temp_free_ptr(rd); \
6662 }
6663
d15f74fb
BS
6664#define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6665static void glue(gen_, name)(DisasContext *ctx) \
6666 { \
6667 TCGv_ptr rb, rd; \
6668 TCGv_i32 uimm; \
6669 \
6670 if (unlikely(!ctx->altivec_enabled)) { \
6671 gen_exception(ctx, POWERPC_EXCP_VPU); \
6672 return; \
6673 } \
6674 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6675 rb = gen_avr_ptr(rB(ctx->opcode)); \
6676 rd = gen_avr_ptr(rD(ctx->opcode)); \
6677 gen_helper_##name(cpu_env, rd, rb, uimm); \
6678 tcg_temp_free_i32(uimm); \
6679 tcg_temp_free_ptr(rb); \
6680 tcg_temp_free_ptr(rd); \
6681 }
6682
e4e6bee7
AJ
6683GEN_VXFORM_UIMM(vspltb, 6, 8);
6684GEN_VXFORM_UIMM(vsplth, 6, 9);
6685GEN_VXFORM_UIMM(vspltw, 6, 10);
d15f74fb
BS
6686GEN_VXFORM_UIMM_ENV(vcfux, 5, 12);
6687GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13);
6688GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14);
6689GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15);
e4e6bee7 6690
99e300ef 6691static void gen_vsldoi(DisasContext *ctx)
cd633b10
AJ
6692{
6693 TCGv_ptr ra, rb, rd;
fce5ecb7 6694 TCGv_i32 sh;
cd633b10
AJ
6695 if (unlikely(!ctx->altivec_enabled)) {
6696 gen_exception(ctx, POWERPC_EXCP_VPU);
6697 return;
6698 }
6699 ra = gen_avr_ptr(rA(ctx->opcode));
6700 rb = gen_avr_ptr(rB(ctx->opcode));
6701 rd = gen_avr_ptr(rD(ctx->opcode));
6702 sh = tcg_const_i32(VSH(ctx->opcode));
6703 gen_helper_vsldoi (rd, ra, rb, sh);
6704 tcg_temp_free_ptr(ra);
6705 tcg_temp_free_ptr(rb);
6706 tcg_temp_free_ptr(rd);
fce5ecb7 6707 tcg_temp_free_i32(sh);
cd633b10
AJ
6708}
6709
707cec33 6710#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
d15f74fb 6711static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
707cec33
AJ
6712 { \
6713 TCGv_ptr ra, rb, rc, rd; \
6714 if (unlikely(!ctx->altivec_enabled)) { \
6715 gen_exception(ctx, POWERPC_EXCP_VPU); \
6716 return; \
6717 } \
6718 ra = gen_avr_ptr(rA(ctx->opcode)); \
6719 rb = gen_avr_ptr(rB(ctx->opcode)); \
6720 rc = gen_avr_ptr(rC(ctx->opcode)); \
6721 rd = gen_avr_ptr(rD(ctx->opcode)); \
6722 if (Rc(ctx->opcode)) { \
d15f74fb 6723 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
707cec33 6724 } else { \
d15f74fb 6725 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
707cec33
AJ
6726 } \
6727 tcg_temp_free_ptr(ra); \
6728 tcg_temp_free_ptr(rb); \
6729 tcg_temp_free_ptr(rc); \
6730 tcg_temp_free_ptr(rd); \
6731 }
6732
b161ae27
AJ
6733GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
6734
99e300ef 6735static void gen_vmladduhm(DisasContext *ctx)
bcd2ee23
AJ
6736{
6737 TCGv_ptr ra, rb, rc, rd;
6738 if (unlikely(!ctx->altivec_enabled)) {
6739 gen_exception(ctx, POWERPC_EXCP_VPU);
6740 return;
6741 }
6742 ra = gen_avr_ptr(rA(ctx->opcode));
6743 rb = gen_avr_ptr(rB(ctx->opcode));
6744 rc = gen_avr_ptr(rC(ctx->opcode));
6745 rd = gen_avr_ptr(rD(ctx->opcode));
6746 gen_helper_vmladduhm(rd, ra, rb, rc);
6747 tcg_temp_free_ptr(ra);
6748 tcg_temp_free_ptr(rb);
6749 tcg_temp_free_ptr(rc);
6750 tcg_temp_free_ptr(rd);
6751}
6752
b04ae981 6753GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
4d9903b6 6754GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
eae07261 6755GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
d1258698 6756GEN_VAFORM_PAIRED(vsel, vperm, 21)
35cf7c7e 6757GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
b04ae981 6758
0487d6a8 6759/*** SPE extension ***/
0487d6a8 6760/* Register moves */
3cd7d1dd 6761
a0e13900
FC
6762
6763static inline void gen_evmra(DisasContext *ctx)
6764{
6765
6766 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 6767 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
6768 return;
6769 }
6770
6771#if defined(TARGET_PPC64)
6772 /* rD := rA */
6773 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6774
6775 /* spe_acc := rA */
6776 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
6777 cpu_env,
1328c2bf 6778 offsetof(CPUPPCState, spe_acc));
a0e13900
FC
6779#else
6780 TCGv_i64 tmp = tcg_temp_new_i64();
6781
6782 /* tmp := rA_lo + rA_hi << 32 */
6783 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6784
6785 /* spe_acc := tmp */
1328c2bf 6786 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
6787 tcg_temp_free_i64(tmp);
6788
6789 /* rD := rA */
6790 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6791 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6792#endif
6793}
6794
636aa200
BS
6795static inline void gen_load_gpr64(TCGv_i64 t, int reg)
6796{
f78fb44e
AJ
6797#if defined(TARGET_PPC64)
6798 tcg_gen_mov_i64(t, cpu_gpr[reg]);
6799#else
36aa55dc 6800 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
3cd7d1dd 6801#endif
f78fb44e 6802}
3cd7d1dd 6803
636aa200
BS
6804static inline void gen_store_gpr64(int reg, TCGv_i64 t)
6805{
f78fb44e
AJ
6806#if defined(TARGET_PPC64)
6807 tcg_gen_mov_i64(cpu_gpr[reg], t);
6808#else
a7812ae4 6809 TCGv_i64 tmp = tcg_temp_new_i64();
f78fb44e 6810 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
f78fb44e
AJ
6811 tcg_gen_shri_i64(tmp, t, 32);
6812 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
a7812ae4 6813 tcg_temp_free_i64(tmp);
3cd7d1dd 6814#endif
f78fb44e 6815}
3cd7d1dd 6816
70560da7 6817#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
99e300ef 6818static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
0487d6a8
JM
6819{ \
6820 if (Rc(ctx->opcode)) \
6821 gen_##name1(ctx); \
6822 else \
6823 gen_##name0(ctx); \
6824}
6825
6826/* Handler for undefined SPE opcodes */
636aa200 6827static inline void gen_speundef(DisasContext *ctx)
0487d6a8 6828{
e06fcd75 6829 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
0487d6a8
JM
6830}
6831
57951c27
AJ
6832/* SPE logic */
6833#if defined(TARGET_PPC64)
6834#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 6835static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
6836{ \
6837 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 6838 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
6839 return; \
6840 } \
57951c27
AJ
6841 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6842 cpu_gpr[rB(ctx->opcode)]); \
6843}
6844#else
6845#define GEN_SPEOP_LOGIC2(name, tcg_op) \
636aa200 6846static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
6847{ \
6848 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 6849 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
6850 return; \
6851 } \
6852 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6853 cpu_gpr[rB(ctx->opcode)]); \
6854 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6855 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 6856}
57951c27
AJ
6857#endif
6858
6859GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
6860GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
6861GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
6862GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
6863GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
6864GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
6865GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
6866GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
0487d6a8 6867
57951c27
AJ
6868/* SPE logic immediate */
6869#if defined(TARGET_PPC64)
6870#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 6871static inline void gen_##name(DisasContext *ctx) \
3d3a6a0a
AJ
6872{ \
6873 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 6874 gen_exception(ctx, POWERPC_EXCP_SPEU); \
3d3a6a0a
AJ
6875 return; \
6876 } \
a7812ae4
PB
6877 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6878 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6879 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
6880 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6881 tcg_opi(t0, t0, rB(ctx->opcode)); \
6882 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6883 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 6884 tcg_temp_free_i64(t2); \
57951c27
AJ
6885 tcg_opi(t1, t1, rB(ctx->opcode)); \
6886 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
6887 tcg_temp_free_i32(t0); \
6888 tcg_temp_free_i32(t1); \
3d3a6a0a 6889}
57951c27
AJ
6890#else
6891#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
636aa200 6892static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
6893{ \
6894 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 6895 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
6896 return; \
6897 } \
57951c27
AJ
6898 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6899 rB(ctx->opcode)); \
6900 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6901 rB(ctx->opcode)); \
0487d6a8 6902}
57951c27
AJ
6903#endif
6904GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
6905GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
6906GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
6907GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
0487d6a8 6908
57951c27
AJ
6909/* SPE arithmetic */
6910#if defined(TARGET_PPC64)
6911#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 6912static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
6913{ \
6914 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 6915 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
6916 return; \
6917 } \
a7812ae4
PB
6918 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6919 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6920 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
6921 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6922 tcg_op(t0, t0); \
6923 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6924 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 6925 tcg_temp_free_i64(t2); \
57951c27
AJ
6926 tcg_op(t1, t1); \
6927 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
6928 tcg_temp_free_i32(t0); \
6929 tcg_temp_free_i32(t1); \
0487d6a8 6930}
57951c27 6931#else
a7812ae4 6932#define GEN_SPEOP_ARITH1(name, tcg_op) \
636aa200 6933static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
6934{ \
6935 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 6936 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
6937 return; \
6938 } \
6939 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6940 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6941}
6942#endif
0487d6a8 6943
636aa200 6944static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
57951c27
AJ
6945{
6946 int l1 = gen_new_label();
6947 int l2 = gen_new_label();
0487d6a8 6948
57951c27
AJ
6949 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
6950 tcg_gen_neg_i32(ret, arg1);
6951 tcg_gen_br(l2);
6952 gen_set_label(l1);
a7812ae4 6953 tcg_gen_mov_i32(ret, arg1);
57951c27
AJ
6954 gen_set_label(l2);
6955}
6956GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
6957GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
6958GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
6959GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
636aa200 6960static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
0487d6a8 6961{
57951c27
AJ
6962 tcg_gen_addi_i32(ret, arg1, 0x8000);
6963 tcg_gen_ext16u_i32(ret, ret);
6964}
6965GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
a7812ae4
PB
6966GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
6967GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
0487d6a8 6968
57951c27
AJ
6969#if defined(TARGET_PPC64)
6970#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 6971static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
6972{ \
6973 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 6974 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
6975 return; \
6976 } \
a7812ae4
PB
6977 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6978 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6979 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
501e23c4 6980 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
57951c27
AJ
6981 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6982 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6983 tcg_op(t0, t0, t2); \
6984 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6985 tcg_gen_trunc_i64_i32(t1, t3); \
6986 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6987 tcg_gen_trunc_i64_i32(t2, t3); \
a7812ae4 6988 tcg_temp_free_i64(t3); \
57951c27 6989 tcg_op(t1, t1, t2); \
a7812ae4 6990 tcg_temp_free_i32(t2); \
57951c27 6991 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
6992 tcg_temp_free_i32(t0); \
6993 tcg_temp_free_i32(t1); \
0487d6a8 6994}
57951c27
AJ
6995#else
6996#define GEN_SPEOP_ARITH2(name, tcg_op) \
636aa200 6997static inline void gen_##name(DisasContext *ctx) \
0487d6a8
JM
6998{ \
6999 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7000 gen_exception(ctx, POWERPC_EXCP_SPEU); \
0487d6a8
JM
7001 return; \
7002 } \
57951c27
AJ
7003 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7004 cpu_gpr[rB(ctx->opcode)]); \
7005 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7006 cpu_gprh[rB(ctx->opcode)]); \
0487d6a8 7007}
57951c27 7008#endif
0487d6a8 7009
636aa200 7010static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 7011{
a7812ae4 7012 TCGv_i32 t0;
57951c27 7013 int l1, l2;
0487d6a8 7014
57951c27
AJ
7015 l1 = gen_new_label();
7016 l2 = gen_new_label();
a7812ae4 7017 t0 = tcg_temp_local_new_i32();
57951c27
AJ
7018 /* No error here: 6 bits are used */
7019 tcg_gen_andi_i32(t0, arg2, 0x3F);
7020 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7021 tcg_gen_shr_i32(ret, arg1, t0);
7022 tcg_gen_br(l2);
7023 gen_set_label(l1);
7024 tcg_gen_movi_i32(ret, 0);
0aef4261 7025 gen_set_label(l2);
a7812ae4 7026 tcg_temp_free_i32(t0);
57951c27
AJ
7027}
7028GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
636aa200 7029static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 7030{
a7812ae4 7031 TCGv_i32 t0;
57951c27
AJ
7032 int l1, l2;
7033
7034 l1 = gen_new_label();
7035 l2 = gen_new_label();
a7812ae4 7036 t0 = tcg_temp_local_new_i32();
57951c27
AJ
7037 /* No error here: 6 bits are used */
7038 tcg_gen_andi_i32(t0, arg2, 0x3F);
7039 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7040 tcg_gen_sar_i32(ret, arg1, t0);
7041 tcg_gen_br(l2);
7042 gen_set_label(l1);
7043 tcg_gen_movi_i32(ret, 0);
0aef4261 7044 gen_set_label(l2);
a7812ae4 7045 tcg_temp_free_i32(t0);
57951c27
AJ
7046}
7047GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
636aa200 7048static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 7049{
a7812ae4 7050 TCGv_i32 t0;
57951c27
AJ
7051 int l1, l2;
7052
7053 l1 = gen_new_label();
7054 l2 = gen_new_label();
a7812ae4 7055 t0 = tcg_temp_local_new_i32();
57951c27
AJ
7056 /* No error here: 6 bits are used */
7057 tcg_gen_andi_i32(t0, arg2, 0x3F);
7058 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
7059 tcg_gen_shl_i32(ret, arg1, t0);
7060 tcg_gen_br(l2);
7061 gen_set_label(l1);
7062 tcg_gen_movi_i32(ret, 0);
e29ef9fa 7063 gen_set_label(l2);
a7812ae4 7064 tcg_temp_free_i32(t0);
57951c27
AJ
7065}
7066GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
636aa200 7067static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
57951c27 7068{
a7812ae4 7069 TCGv_i32 t0 = tcg_temp_new_i32();
57951c27
AJ
7070 tcg_gen_andi_i32(t0, arg2, 0x1F);
7071 tcg_gen_rotl_i32(ret, arg1, t0);
a7812ae4 7072 tcg_temp_free_i32(t0);
57951c27
AJ
7073}
7074GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
636aa200 7075static inline void gen_evmergehi(DisasContext *ctx)
57951c27
AJ
7076{
7077 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7078 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
7079 return;
7080 }
7081#if defined(TARGET_PPC64)
a7812ae4
PB
7082 TCGv t0 = tcg_temp_new();
7083 TCGv t1 = tcg_temp_new();
57951c27
AJ
7084 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
7085 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
7086 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7087 tcg_temp_free(t0);
7088 tcg_temp_free(t1);
7089#else
7090 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7091 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7092#endif
7093}
7094GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
636aa200 7095static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
0487d6a8 7096{
57951c27
AJ
7097 tcg_gen_sub_i32(ret, arg2, arg1);
7098}
7099GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
0487d6a8 7100
57951c27
AJ
7101/* SPE arithmetic immediate */
7102#if defined(TARGET_PPC64)
7103#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 7104static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7105{ \
7106 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7107 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7108 return; \
7109 } \
a7812ae4
PB
7110 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7111 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7112 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
7113 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7114 tcg_op(t0, t0, rA(ctx->opcode)); \
7115 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7116 tcg_gen_trunc_i64_i32(t1, t2); \
e06fcd75 7117 tcg_temp_free_i64(t2); \
57951c27
AJ
7118 tcg_op(t1, t1, rA(ctx->opcode)); \
7119 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
a7812ae4
PB
7120 tcg_temp_free_i32(t0); \
7121 tcg_temp_free_i32(t1); \
57951c27
AJ
7122}
7123#else
7124#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
636aa200 7125static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7126{ \
7127 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7128 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7129 return; \
7130 } \
7131 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7132 rA(ctx->opcode)); \
7133 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7134 rA(ctx->opcode)); \
7135}
7136#endif
7137GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
7138GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
7139
7140/* SPE comparison */
7141#if defined(TARGET_PPC64)
7142#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 7143static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7144{ \
7145 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7146 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7147 return; \
7148 } \
7149 int l1 = gen_new_label(); \
7150 int l2 = gen_new_label(); \
7151 int l3 = gen_new_label(); \
7152 int l4 = gen_new_label(); \
a7812ae4
PB
7153 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7154 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7155 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
57951c27
AJ
7156 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7157 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7158 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
a7812ae4 7159 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
57951c27
AJ
7160 tcg_gen_br(l2); \
7161 gen_set_label(l1); \
7162 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7163 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7164 gen_set_label(l2); \
7165 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7166 tcg_gen_trunc_i64_i32(t0, t2); \
7167 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7168 tcg_gen_trunc_i64_i32(t1, t2); \
a7812ae4 7169 tcg_temp_free_i64(t2); \
57951c27
AJ
7170 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7171 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7172 ~(CRF_CH | CRF_CH_AND_CL)); \
7173 tcg_gen_br(l4); \
7174 gen_set_label(l3); \
7175 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7176 CRF_CH | CRF_CH_OR_CL); \
7177 gen_set_label(l4); \
a7812ae4
PB
7178 tcg_temp_free_i32(t0); \
7179 tcg_temp_free_i32(t1); \
57951c27
AJ
7180}
7181#else
7182#define GEN_SPEOP_COMP(name, tcg_cond) \
636aa200 7183static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
7184{ \
7185 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7186 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
7187 return; \
7188 } \
7189 int l1 = gen_new_label(); \
7190 int l2 = gen_new_label(); \
7191 int l3 = gen_new_label(); \
7192 int l4 = gen_new_label(); \
7193 \
7194 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7195 cpu_gpr[rB(ctx->opcode)], l1); \
7196 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7197 tcg_gen_br(l2); \
7198 gen_set_label(l1); \
7199 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7200 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7201 gen_set_label(l2); \
7202 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7203 cpu_gprh[rB(ctx->opcode)], l3); \
7204 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7205 ~(CRF_CH | CRF_CH_AND_CL)); \
7206 tcg_gen_br(l4); \
7207 gen_set_label(l3); \
7208 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7209 CRF_CH | CRF_CH_OR_CL); \
7210 gen_set_label(l4); \
7211}
7212#endif
7213GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
7214GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
7215GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
7216GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
7217GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
7218
7219/* SPE misc */
636aa200 7220static inline void gen_brinc(DisasContext *ctx)
57951c27
AJ
7221{
7222 /* Note: brinc is usable even if SPE is disabled */
a7812ae4
PB
7223 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
7224 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
0487d6a8 7225}
636aa200 7226static inline void gen_evmergelo(DisasContext *ctx)
57951c27
AJ
7227{
7228 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7229 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
7230 return;
7231 }
7232#if defined(TARGET_PPC64)
a7812ae4
PB
7233 TCGv t0 = tcg_temp_new();
7234 TCGv t1 = tcg_temp_new();
17d9b3af 7235 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
7236 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
7237 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7238 tcg_temp_free(t0);
7239 tcg_temp_free(t1);
7240#else
57951c27 7241 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
33890b3e 7242 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
7243#endif
7244}
636aa200 7245static inline void gen_evmergehilo(DisasContext *ctx)
57951c27
AJ
7246{
7247 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7248 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
7249 return;
7250 }
7251#if defined(TARGET_PPC64)
a7812ae4
PB
7252 TCGv t0 = tcg_temp_new();
7253 TCGv t1 = tcg_temp_new();
17d9b3af 7254 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
7255 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
7256 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7257 tcg_temp_free(t0);
7258 tcg_temp_free(t1);
7259#else
7260 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7261 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7262#endif
7263}
636aa200 7264static inline void gen_evmergelohi(DisasContext *ctx)
57951c27
AJ
7265{
7266 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7267 gen_exception(ctx, POWERPC_EXCP_SPEU);
57951c27
AJ
7268 return;
7269 }
7270#if defined(TARGET_PPC64)
a7812ae4
PB
7271 TCGv t0 = tcg_temp_new();
7272 TCGv t1 = tcg_temp_new();
57951c27
AJ
7273 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
7274 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
7275 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7276 tcg_temp_free(t0);
7277 tcg_temp_free(t1);
7278#else
33890b3e
NF
7279 if (rD(ctx->opcode) == rA(ctx->opcode)) {
7280 TCGv_i32 tmp = tcg_temp_new_i32();
7281 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
7282 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7283 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
7284 tcg_temp_free_i32(tmp);
7285 } else {
7286 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7287 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7288 }
57951c27
AJ
7289#endif
7290}
636aa200 7291static inline void gen_evsplati(DisasContext *ctx)
57951c27 7292{
ae01847f 7293 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
0487d6a8 7294
57951c27 7295#if defined(TARGET_PPC64)
38d14952 7296 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
7297#else
7298 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
7299 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
7300#endif
7301}
636aa200 7302static inline void gen_evsplatfi(DisasContext *ctx)
0487d6a8 7303{
ae01847f 7304 uint64_t imm = rA(ctx->opcode) << 27;
0487d6a8 7305
57951c27 7306#if defined(TARGET_PPC64)
38d14952 7307 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
57951c27
AJ
7308#else
7309 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
7310 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
7311#endif
0487d6a8
JM
7312}
7313
636aa200 7314static inline void gen_evsel(DisasContext *ctx)
57951c27
AJ
7315{
7316 int l1 = gen_new_label();
7317 int l2 = gen_new_label();
7318 int l3 = gen_new_label();
7319 int l4 = gen_new_label();
a7812ae4 7320 TCGv_i32 t0 = tcg_temp_local_new_i32();
57951c27 7321#if defined(TARGET_PPC64)
a7812ae4
PB
7322 TCGv t1 = tcg_temp_local_new();
7323 TCGv t2 = tcg_temp_local_new();
57951c27
AJ
7324#endif
7325 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
7326 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
7327#if defined(TARGET_PPC64)
7328 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
7329#else
7330 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7331#endif
7332 tcg_gen_br(l2);
7333 gen_set_label(l1);
7334#if defined(TARGET_PPC64)
7335 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
7336#else
7337 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7338#endif
7339 gen_set_label(l2);
7340 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
7341 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
7342#if defined(TARGET_PPC64)
17d9b3af 7343 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
57951c27
AJ
7344#else
7345 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7346#endif
7347 tcg_gen_br(l4);
7348 gen_set_label(l3);
7349#if defined(TARGET_PPC64)
17d9b3af 7350 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
57951c27
AJ
7351#else
7352 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7353#endif
7354 gen_set_label(l4);
a7812ae4 7355 tcg_temp_free_i32(t0);
57951c27
AJ
7356#if defined(TARGET_PPC64)
7357 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
7358 tcg_temp_free(t1);
7359 tcg_temp_free(t2);
7360#endif
7361}
e8eaa2c0
BS
7362
7363static void gen_evsel0(DisasContext *ctx)
57951c27
AJ
7364{
7365 gen_evsel(ctx);
7366}
e8eaa2c0
BS
7367
7368static void gen_evsel1(DisasContext *ctx)
57951c27
AJ
7369{
7370 gen_evsel(ctx);
7371}
e8eaa2c0
BS
7372
7373static void gen_evsel2(DisasContext *ctx)
57951c27
AJ
7374{
7375 gen_evsel(ctx);
7376}
e8eaa2c0
BS
7377
7378static void gen_evsel3(DisasContext *ctx)
57951c27
AJ
7379{
7380 gen_evsel(ctx);
7381}
0487d6a8 7382
a0e13900
FC
7383/* Multiply */
7384
7385static inline void gen_evmwumi(DisasContext *ctx)
7386{
7387 TCGv_i64 t0, t1;
7388
7389 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7390 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
7391 return;
7392 }
7393
7394 t0 = tcg_temp_new_i64();
7395 t1 = tcg_temp_new_i64();
7396
7397 /* t0 := rA; t1 := rB */
7398#if defined(TARGET_PPC64)
7399 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
7400 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
7401#else
7402 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
7403 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
7404#endif
7405
7406 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
7407
7408 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
7409
7410 tcg_temp_free_i64(t0);
7411 tcg_temp_free_i64(t1);
7412}
7413
7414static inline void gen_evmwumia(DisasContext *ctx)
7415{
7416 TCGv_i64 tmp;
7417
7418 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7419 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
7420 return;
7421 }
7422
7423 gen_evmwumi(ctx); /* rD := rA * rB */
7424
7425 tmp = tcg_temp_new_i64();
7426
7427 /* acc := rD */
7428 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 7429 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7430 tcg_temp_free_i64(tmp);
7431}
7432
7433static inline void gen_evmwumiaa(DisasContext *ctx)
7434{
7435 TCGv_i64 acc;
7436 TCGv_i64 tmp;
7437
7438 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7439 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
7440 return;
7441 }
7442
7443 gen_evmwumi(ctx); /* rD := rA * rB */
7444
7445 acc = tcg_temp_new_i64();
7446 tmp = tcg_temp_new_i64();
7447
7448 /* tmp := rD */
7449 gen_load_gpr64(tmp, rD(ctx->opcode));
7450
7451 /* Load acc */
1328c2bf 7452 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7453
7454 /* acc := tmp + acc */
7455 tcg_gen_add_i64(acc, acc, tmp);
7456
7457 /* Store acc */
1328c2bf 7458 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7459
7460 /* rD := acc */
7461 gen_store_gpr64(rD(ctx->opcode), acc);
7462
7463 tcg_temp_free_i64(acc);
7464 tcg_temp_free_i64(tmp);
7465}
7466
7467static inline void gen_evmwsmi(DisasContext *ctx)
7468{
7469 TCGv_i64 t0, t1;
7470
7471 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 7472 gen_exception(ctx, POWERPC_EXCP_SPEU);
a0e13900
FC
7473 return;
7474 }
7475
7476 t0 = tcg_temp_new_i64();
7477 t1 = tcg_temp_new_i64();
7478
7479 /* t0 := rA; t1 := rB */
7480#if defined(TARGET_PPC64)
7481 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
7482 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
7483#else
7484 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
7485 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
7486#endif
7487
7488 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
7489
7490 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
7491
7492 tcg_temp_free_i64(t0);
7493 tcg_temp_free_i64(t1);
7494}
7495
7496static inline void gen_evmwsmia(DisasContext *ctx)
7497{
7498 TCGv_i64 tmp;
7499
7500 gen_evmwsmi(ctx); /* rD := rA * rB */
7501
7502 tmp = tcg_temp_new_i64();
7503
7504 /* acc := rD */
7505 gen_load_gpr64(tmp, rD(ctx->opcode));
1328c2bf 7506 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7507
7508 tcg_temp_free_i64(tmp);
7509}
7510
7511static inline void gen_evmwsmiaa(DisasContext *ctx)
7512{
7513 TCGv_i64 acc = tcg_temp_new_i64();
7514 TCGv_i64 tmp = tcg_temp_new_i64();
7515
7516 gen_evmwsmi(ctx); /* rD := rA * rB */
7517
7518 acc = tcg_temp_new_i64();
7519 tmp = tcg_temp_new_i64();
7520
7521 /* tmp := rD */
7522 gen_load_gpr64(tmp, rD(ctx->opcode));
7523
7524 /* Load acc */
1328c2bf 7525 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7526
7527 /* acc := tmp + acc */
7528 tcg_gen_add_i64(acc, acc, tmp);
7529
7530 /* Store acc */
1328c2bf 7531 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc));
a0e13900
FC
7532
7533 /* rD := acc */
7534 gen_store_gpr64(rD(ctx->opcode), acc);
7535
7536 tcg_temp_free_i64(acc);
7537 tcg_temp_free_i64(tmp);
7538}
7539
70560da7
FC
7540GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7541GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
7542GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7543GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
7544GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
7545GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
7546GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); ////
7547GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); //
7548GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE);
7549GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
7550GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7551GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7552GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7553GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
7554GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE);
7555GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE);
7556GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); ////
7557GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7558GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7559GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE);
7560GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); ////
7561GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE);
7562GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); //
7563GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE);
7564GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7565GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); ////
7566GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
7567GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); ////
7568GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); ////
0487d6a8 7569
6a6ae23f 7570/* SPE load and stores */
636aa200 7571static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
6a6ae23f
AJ
7572{
7573 target_ulong uimm = rB(ctx->opcode);
7574
76db3ba4 7575 if (rA(ctx->opcode) == 0) {
6a6ae23f 7576 tcg_gen_movi_tl(EA, uimm << sh);
76db3ba4 7577 } else {
6a6ae23f 7578 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
76db3ba4
AJ
7579#if defined(TARGET_PPC64)
7580 if (!ctx->sf_mode) {
7581 tcg_gen_ext32u_tl(EA, EA);
7582 }
7583#endif
7584 }
0487d6a8 7585}
6a6ae23f 7586
636aa200 7587static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7588{
7589#if defined(TARGET_PPC64)
76db3ba4 7590 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
7591#else
7592 TCGv_i64 t0 = tcg_temp_new_i64();
76db3ba4 7593 gen_qemu_ld64(ctx, t0, addr);
6a6ae23f
AJ
7594 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
7595 tcg_gen_shri_i64(t0, t0, 32);
7596 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
7597 tcg_temp_free_i64(t0);
7598#endif
0487d6a8 7599}
6a6ae23f 7600
636aa200 7601static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
6a6ae23f 7602{
0487d6a8 7603#if defined(TARGET_PPC64)
6a6ae23f 7604 TCGv t0 = tcg_temp_new();
76db3ba4 7605 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f 7606 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
76db3ba4
AJ
7607 gen_addr_add(ctx, addr, addr, 4);
7608 gen_qemu_ld32u(ctx, t0, addr);
6a6ae23f
AJ
7609 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7610 tcg_temp_free(t0);
7611#else
76db3ba4
AJ
7612 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7613 gen_addr_add(ctx, addr, addr, 4);
7614 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f 7615#endif
0487d6a8 7616}
6a6ae23f 7617
636aa200 7618static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7619{
7620 TCGv t0 = tcg_temp_new();
7621#if defined(TARGET_PPC64)
76db3ba4 7622 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 7623 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
7624 gen_addr_add(ctx, addr, addr, 2);
7625 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7626 tcg_gen_shli_tl(t0, t0, 32);
7627 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
7628 gen_addr_add(ctx, addr, addr, 2);
7629 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7630 tcg_gen_shli_tl(t0, t0, 16);
7631 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
7632 gen_addr_add(ctx, addr, addr, 2);
7633 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 7634 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 7635#else
76db3ba4 7636 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 7637 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
7638 gen_addr_add(ctx, addr, addr, 2);
7639 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 7640 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
7641 gen_addr_add(ctx, addr, addr, 2);
7642 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 7643 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
7644 gen_addr_add(ctx, addr, addr, 2);
7645 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 7646 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
0487d6a8 7647#endif
6a6ae23f 7648 tcg_temp_free(t0);
0487d6a8
JM
7649}
7650
636aa200 7651static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7652{
7653 TCGv t0 = tcg_temp_new();
76db3ba4 7654 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7655#if defined(TARGET_PPC64)
7656 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7657 tcg_gen_shli_tl(t0, t0, 16);
7658 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7659#else
7660 tcg_gen_shli_tl(t0, t0, 16);
7661 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7662 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7663#endif
7664 tcg_temp_free(t0);
0487d6a8
JM
7665}
7666
636aa200 7667static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7668{
7669 TCGv t0 = tcg_temp_new();
76db3ba4 7670 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7671#if defined(TARGET_PPC64)
7672 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7673 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7674#else
7675 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7676 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7677#endif
7678 tcg_temp_free(t0);
0487d6a8
JM
7679}
7680
636aa200 7681static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7682{
7683 TCGv t0 = tcg_temp_new();
76db3ba4 7684 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
7685#if defined(TARGET_PPC64)
7686 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7687 tcg_gen_ext32u_tl(t0, t0);
7688 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7689#else
7690 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7691 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7692#endif
7693 tcg_temp_free(t0);
7694}
7695
636aa200 7696static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7697{
7698 TCGv t0 = tcg_temp_new();
7699#if defined(TARGET_PPC64)
76db3ba4 7700 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 7701 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
76db3ba4
AJ
7702 gen_addr_add(ctx, addr, addr, 2);
7703 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7704 tcg_gen_shli_tl(t0, t0, 16);
7705 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7706#else
76db3ba4 7707 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f 7708 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
76db3ba4
AJ
7709 gen_addr_add(ctx, addr, addr, 2);
7710 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7711 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
7712#endif
7713 tcg_temp_free(t0);
7714}
7715
636aa200 7716static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7717{
7718#if defined(TARGET_PPC64)
7719 TCGv t0 = tcg_temp_new();
76db3ba4
AJ
7720 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7721 gen_addr_add(ctx, addr, addr, 2);
7722 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7723 tcg_gen_shli_tl(t0, t0, 32);
7724 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7725 tcg_temp_free(t0);
7726#else
76db3ba4
AJ
7727 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7728 gen_addr_add(ctx, addr, addr, 2);
7729 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
7730#endif
7731}
7732
636aa200 7733static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7734{
7735#if defined(TARGET_PPC64)
7736 TCGv t0 = tcg_temp_new();
76db3ba4 7737 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f 7738 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
7739 gen_addr_add(ctx, addr, addr, 2);
7740 gen_qemu_ld16s(ctx, t0, addr);
6a6ae23f
AJ
7741 tcg_gen_shli_tl(t0, t0, 32);
7742 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7743 tcg_temp_free(t0);
7744#else
76db3ba4
AJ
7745 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7746 gen_addr_add(ctx, addr, addr, 2);
7747 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
6a6ae23f
AJ
7748#endif
7749}
7750
636aa200 7751static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7752{
7753 TCGv t0 = tcg_temp_new();
76db3ba4 7754 gen_qemu_ld32u(ctx, t0, addr);
0487d6a8 7755#if defined(TARGET_PPC64)
6a6ae23f
AJ
7756 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7757 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7758#else
7759 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7760 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7761#endif
7762 tcg_temp_free(t0);
7763}
7764
636aa200 7765static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7766{
7767 TCGv t0 = tcg_temp_new();
7768#if defined(TARGET_PPC64)
76db3ba4 7769 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7770 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7771 tcg_gen_shli_tl(t0, t0, 32);
7772 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
76db3ba4
AJ
7773 gen_addr_add(ctx, addr, addr, 2);
7774 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7775 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7776 tcg_gen_shli_tl(t0, t0, 16);
7777 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7778#else
76db3ba4 7779 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7780 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7781 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
76db3ba4
AJ
7782 gen_addr_add(ctx, addr, addr, 2);
7783 gen_qemu_ld16u(ctx, t0, addr);
6a6ae23f
AJ
7784 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
7785 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
0487d6a8 7786#endif
6a6ae23f
AJ
7787 tcg_temp_free(t0);
7788}
7789
636aa200 7790static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7791{
7792#if defined(TARGET_PPC64)
76db3ba4 7793 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
0487d6a8 7794#else
6a6ae23f
AJ
7795 TCGv_i64 t0 = tcg_temp_new_i64();
7796 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
76db3ba4 7797 gen_qemu_st64(ctx, t0, addr);
6a6ae23f
AJ
7798 tcg_temp_free_i64(t0);
7799#endif
7800}
7801
636aa200 7802static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
6a6ae23f 7803{
0487d6a8 7804#if defined(TARGET_PPC64)
6a6ae23f
AJ
7805 TCGv t0 = tcg_temp_new();
7806 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 7807 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
7808 tcg_temp_free(t0);
7809#else
76db3ba4 7810 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 7811#endif
76db3ba4
AJ
7812 gen_addr_add(ctx, addr, addr, 4);
7813 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
7814}
7815
636aa200 7816static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7817{
7818 TCGv t0 = tcg_temp_new();
7819#if defined(TARGET_PPC64)
7820 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
7821#else
7822 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
7823#endif
76db3ba4
AJ
7824 gen_qemu_st16(ctx, t0, addr);
7825 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f
AJ
7826#if defined(TARGET_PPC64)
7827 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 7828 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 7829#else
76db3ba4 7830 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 7831#endif
76db3ba4 7832 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 7833 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 7834 gen_qemu_st16(ctx, t0, addr);
6a6ae23f 7835 tcg_temp_free(t0);
76db3ba4
AJ
7836 gen_addr_add(ctx, addr, addr, 2);
7837 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
7838}
7839
636aa200 7840static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7841{
7842 TCGv t0 = tcg_temp_new();
7843#if defined(TARGET_PPC64)
7844 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
7845#else
7846 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
7847#endif
76db3ba4
AJ
7848 gen_qemu_st16(ctx, t0, addr);
7849 gen_addr_add(ctx, addr, addr, 2);
6a6ae23f 7850 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
76db3ba4 7851 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
7852 tcg_temp_free(t0);
7853}
7854
636aa200 7855static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7856{
7857#if defined(TARGET_PPC64)
7858 TCGv t0 = tcg_temp_new();
7859 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 7860 gen_qemu_st16(ctx, t0, addr);
6a6ae23f
AJ
7861 tcg_temp_free(t0);
7862#else
76db3ba4 7863 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f 7864#endif
76db3ba4
AJ
7865 gen_addr_add(ctx, addr, addr, 2);
7866 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
7867}
7868
636aa200 7869static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
6a6ae23f
AJ
7870{
7871#if defined(TARGET_PPC64)
7872 TCGv t0 = tcg_temp_new();
7873 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
76db3ba4 7874 gen_qemu_st32(ctx, t0, addr);
6a6ae23f
AJ
7875 tcg_temp_free(t0);
7876#else
76db3ba4 7877 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
6a6ae23f
AJ
7878#endif
7879}
7880
636aa200 7881static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
6a6ae23f 7882{
76db3ba4 7883 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
6a6ae23f
AJ
7884}
7885
7886#define GEN_SPEOP_LDST(name, opc2, sh) \
99e300ef 7887static void glue(gen_, name)(DisasContext *ctx) \
6a6ae23f
AJ
7888{ \
7889 TCGv t0; \
7890 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 7891 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6a6ae23f
AJ
7892 return; \
7893 } \
76db3ba4 7894 gen_set_access_type(ctx, ACCESS_INT); \
6a6ae23f
AJ
7895 t0 = tcg_temp_new(); \
7896 if (Rc(ctx->opcode)) { \
76db3ba4 7897 gen_addr_spe_imm_index(ctx, t0, sh); \
6a6ae23f 7898 } else { \
76db3ba4 7899 gen_addr_reg_index(ctx, t0); \
6a6ae23f
AJ
7900 } \
7901 gen_op_##name(ctx, t0); \
7902 tcg_temp_free(t0); \
7903}
7904
7905GEN_SPEOP_LDST(evldd, 0x00, 3);
7906GEN_SPEOP_LDST(evldw, 0x01, 3);
7907GEN_SPEOP_LDST(evldh, 0x02, 3);
7908GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
7909GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
7910GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
7911GEN_SPEOP_LDST(evlwhe, 0x08, 2);
7912GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
7913GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
7914GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
7915GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
7916
7917GEN_SPEOP_LDST(evstdd, 0x10, 3);
7918GEN_SPEOP_LDST(evstdw, 0x11, 3);
7919GEN_SPEOP_LDST(evstdh, 0x12, 3);
7920GEN_SPEOP_LDST(evstwhe, 0x18, 2);
7921GEN_SPEOP_LDST(evstwho, 0x1A, 2);
7922GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
7923GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
0487d6a8
JM
7924
7925/* Multiply and add - TODO */
7926#if 0
70560da7
FC
7927GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);//
7928GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7929GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE);
7930GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7931GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE);
7932GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7933GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7934GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7935GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE);
7936GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7937GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE);
7938GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7939
7940GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7941GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
7942GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE);
7943GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7944GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7945GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7946GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7947GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE);
7948GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE);
7949GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7950GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7951GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7952
7953GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
7954GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
7955GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
7956GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE);
7957GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE);
7958
7959GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE);
7960GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7961GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE);
7962GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7963GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE);
7964GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7965GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE);
7966GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7967GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE);
7968GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7969GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE);
7970GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7971
7972GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE);
7973GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE);
7974GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7975GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7976
7977GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE);
7978GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7979GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE);
7980GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7981GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE);
7982GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7983GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE);
7984GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7985GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE);
7986GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7987GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE);
7988GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7989
7990GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE);
7991GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE);
7992GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
7993GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE);
7994GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE);
0487d6a8
JM
7995#endif
7996
7997/*** SPE floating-point extension ***/
1c97856d
AJ
7998#if defined(TARGET_PPC64)
7999#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 8000static inline void gen_##name(DisasContext *ctx) \
0487d6a8 8001{ \
1c97856d
AJ
8002 TCGv_i32 t0; \
8003 TCGv t1; \
8004 t0 = tcg_temp_new_i32(); \
8005 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 8006 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
8007 t1 = tcg_temp_new(); \
8008 tcg_gen_extu_i32_tl(t1, t0); \
8009 tcg_temp_free_i32(t0); \
8010 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8011 0xFFFFFFFF00000000ULL); \
8012 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8013 tcg_temp_free(t1); \
0487d6a8 8014}
1c97856d 8015#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 8016static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8017{ \
8018 TCGv_i32 t0; \
8019 TCGv t1; \
8020 t0 = tcg_temp_new_i32(); \
8e703949 8021 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
8022 t1 = tcg_temp_new(); \
8023 tcg_gen_extu_i32_tl(t1, t0); \
8024 tcg_temp_free_i32(t0); \
8025 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8026 0xFFFFFFFF00000000ULL); \
8027 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8028 tcg_temp_free(t1); \
8029}
8030#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 8031static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8032{ \
8033 TCGv_i32 t0 = tcg_temp_new_i32(); \
8034 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8e703949 8035 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
8036 tcg_temp_free_i32(t0); \
8037}
8038#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 8039static inline void gen_##name(DisasContext *ctx) \
1c97856d 8040{ \
8e703949
BS
8041 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8042 cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
8043}
8044#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 8045static inline void gen_##name(DisasContext *ctx) \
57951c27 8046{ \
1c97856d
AJ
8047 TCGv_i32 t0, t1; \
8048 TCGv_i64 t2; \
57951c27 8049 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8050 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8051 return; \
8052 } \
1c97856d
AJ
8053 t0 = tcg_temp_new_i32(); \
8054 t1 = tcg_temp_new_i32(); \
8055 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8056 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 8057 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
8058 tcg_temp_free_i32(t1); \
8059 t2 = tcg_temp_new(); \
8060 tcg_gen_extu_i32_tl(t2, t0); \
8061 tcg_temp_free_i32(t0); \
8062 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8063 0xFFFFFFFF00000000ULL); \
8064 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8065 tcg_temp_free(t2); \
57951c27 8066}
1c97856d 8067#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 8068static inline void gen_##name(DisasContext *ctx) \
57951c27
AJ
8069{ \
8070 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8071 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8072 return; \
8073 } \
8e703949
BS
8074 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8075 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
57951c27 8076}
1c97856d 8077#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 8078static inline void gen_##name(DisasContext *ctx) \
57951c27 8079{ \
1c97856d 8080 TCGv_i32 t0, t1; \
57951c27 8081 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8082 gen_exception(ctx, POWERPC_EXCP_SPEU); \
57951c27
AJ
8083 return; \
8084 } \
1c97856d
AJ
8085 t0 = tcg_temp_new_i32(); \
8086 t1 = tcg_temp_new_i32(); \
8087 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8088 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8e703949 8089 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
8090 tcg_temp_free_i32(t0); \
8091 tcg_temp_free_i32(t1); \
8092}
8093#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 8094static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8095{ \
8096 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8097 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
8098 return; \
8099 } \
8e703949 8100 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
8101 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8102}
8103#else
8104#define GEN_SPEFPUOP_CONV_32_32(name) \
636aa200 8105static inline void gen_##name(DisasContext *ctx) \
1c97856d 8106{ \
8e703949
BS
8107 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8108 cpu_gpr[rB(ctx->opcode)]); \
57951c27 8109}
1c97856d 8110#define GEN_SPEFPUOP_CONV_32_64(name) \
636aa200 8111static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8112{ \
8113 TCGv_i64 t0 = tcg_temp_new_i64(); \
8114 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 8115 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
1c97856d
AJ
8116 tcg_temp_free_i64(t0); \
8117}
8118#define GEN_SPEFPUOP_CONV_64_32(name) \
636aa200 8119static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8120{ \
8121 TCGv_i64 t0 = tcg_temp_new_i64(); \
8e703949 8122 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
1c97856d
AJ
8123 gen_store_gpr64(rD(ctx->opcode), t0); \
8124 tcg_temp_free_i64(t0); \
8125}
8126#define GEN_SPEFPUOP_CONV_64_64(name) \
636aa200 8127static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8128{ \
8129 TCGv_i64 t0 = tcg_temp_new_i64(); \
8130 gen_load_gpr64(t0, rB(ctx->opcode)); \
8e703949 8131 gen_helper_##name(t0, cpu_env, t0); \
1c97856d
AJ
8132 gen_store_gpr64(rD(ctx->opcode), t0); \
8133 tcg_temp_free_i64(t0); \
8134}
8135#define GEN_SPEFPUOP_ARITH2_32_32(name) \
636aa200 8136static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8137{ \
8138 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8139 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
8140 return; \
8141 } \
8e703949 8142 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1c97856d
AJ
8143 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8144}
8145#define GEN_SPEFPUOP_ARITH2_64_64(name) \
636aa200 8146static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8147{ \
8148 TCGv_i64 t0, t1; \
8149 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8150 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
8151 return; \
8152 } \
8153 t0 = tcg_temp_new_i64(); \
8154 t1 = tcg_temp_new_i64(); \
8155 gen_load_gpr64(t0, rA(ctx->opcode)); \
8156 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 8157 gen_helper_##name(t0, cpu_env, t0, t1); \
1c97856d
AJ
8158 gen_store_gpr64(rD(ctx->opcode), t0); \
8159 tcg_temp_free_i64(t0); \
8160 tcg_temp_free_i64(t1); \
8161}
8162#define GEN_SPEFPUOP_COMP_32(name) \
636aa200 8163static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8164{ \
8165 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8166 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
8167 return; \
8168 } \
8e703949 8169 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
1c97856d
AJ
8170 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8171}
8172#define GEN_SPEFPUOP_COMP_64(name) \
636aa200 8173static inline void gen_##name(DisasContext *ctx) \
1c97856d
AJ
8174{ \
8175 TCGv_i64 t0, t1; \
8176 if (unlikely(!ctx->spe_enabled)) { \
27a69bb0 8177 gen_exception(ctx, POWERPC_EXCP_SPEU); \
1c97856d
AJ
8178 return; \
8179 } \
8180 t0 = tcg_temp_new_i64(); \
8181 t1 = tcg_temp_new_i64(); \
8182 gen_load_gpr64(t0, rA(ctx->opcode)); \
8183 gen_load_gpr64(t1, rB(ctx->opcode)); \
8e703949 8184 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
1c97856d
AJ
8185 tcg_temp_free_i64(t0); \
8186 tcg_temp_free_i64(t1); \
8187}
8188#endif
57951c27 8189
0487d6a8
JM
8190/* Single precision floating-point vectors operations */
8191/* Arithmetic */
1c97856d
AJ
8192GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
8193GEN_SPEFPUOP_ARITH2_64_64(evfssub);
8194GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
8195GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
636aa200 8196static inline void gen_evfsabs(DisasContext *ctx)
1c97856d
AJ
8197{
8198 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8199 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8200 return;
8201 }
8202#if defined(TARGET_PPC64)
6d5c34fa 8203 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
1c97856d 8204#else
6d5c34fa
MP
8205 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
8206 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
8207#endif
8208}
636aa200 8209static inline void gen_evfsnabs(DisasContext *ctx)
1c97856d
AJ
8210{
8211 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8212 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8213 return;
8214 }
8215#if defined(TARGET_PPC64)
6d5c34fa 8216 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 8217#else
6d5c34fa
MP
8218 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8219 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
8220#endif
8221}
636aa200 8222static inline void gen_evfsneg(DisasContext *ctx)
1c97856d
AJ
8223{
8224 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8225 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8226 return;
8227 }
8228#if defined(TARGET_PPC64)
6d5c34fa 8229 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
1c97856d 8230#else
6d5c34fa
MP
8231 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8232 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
8233#endif
8234}
8235
0487d6a8 8236/* Conversion */
1c97856d
AJ
8237GEN_SPEFPUOP_CONV_64_64(evfscfui);
8238GEN_SPEFPUOP_CONV_64_64(evfscfsi);
8239GEN_SPEFPUOP_CONV_64_64(evfscfuf);
8240GEN_SPEFPUOP_CONV_64_64(evfscfsf);
8241GEN_SPEFPUOP_CONV_64_64(evfsctui);
8242GEN_SPEFPUOP_CONV_64_64(evfsctsi);
8243GEN_SPEFPUOP_CONV_64_64(evfsctuf);
8244GEN_SPEFPUOP_CONV_64_64(evfsctsf);
8245GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
8246GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
8247
0487d6a8 8248/* Comparison */
1c97856d
AJ
8249GEN_SPEFPUOP_COMP_64(evfscmpgt);
8250GEN_SPEFPUOP_COMP_64(evfscmplt);
8251GEN_SPEFPUOP_COMP_64(evfscmpeq);
8252GEN_SPEFPUOP_COMP_64(evfststgt);
8253GEN_SPEFPUOP_COMP_64(evfststlt);
8254GEN_SPEFPUOP_COMP_64(evfststeq);
0487d6a8
JM
8255
8256/* Opcodes definitions */
70560da7
FC
8257GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
8258GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
8259GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8260GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
8261GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
8262GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8263GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8264GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8265GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8266GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8267GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8268GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8269GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
8270GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
8271
8272/* Single precision floating-point operations */
8273/* Arithmetic */
1c97856d
AJ
8274GEN_SPEFPUOP_ARITH2_32_32(efsadd);
8275GEN_SPEFPUOP_ARITH2_32_32(efssub);
8276GEN_SPEFPUOP_ARITH2_32_32(efsmul);
8277GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
636aa200 8278static inline void gen_efsabs(DisasContext *ctx)
1c97856d
AJ
8279{
8280 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8281 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8282 return;
8283 }
6d5c34fa 8284 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
1c97856d 8285}
636aa200 8286static inline void gen_efsnabs(DisasContext *ctx)
1c97856d
AJ
8287{
8288 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8289 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8290 return;
8291 }
6d5c34fa 8292 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d 8293}
636aa200 8294static inline void gen_efsneg(DisasContext *ctx)
1c97856d
AJ
8295{
8296 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8297 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8298 return;
8299 }
6d5c34fa 8300 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
8301}
8302
0487d6a8 8303/* Conversion */
1c97856d
AJ
8304GEN_SPEFPUOP_CONV_32_32(efscfui);
8305GEN_SPEFPUOP_CONV_32_32(efscfsi);
8306GEN_SPEFPUOP_CONV_32_32(efscfuf);
8307GEN_SPEFPUOP_CONV_32_32(efscfsf);
8308GEN_SPEFPUOP_CONV_32_32(efsctui);
8309GEN_SPEFPUOP_CONV_32_32(efsctsi);
8310GEN_SPEFPUOP_CONV_32_32(efsctuf);
8311GEN_SPEFPUOP_CONV_32_32(efsctsf);
8312GEN_SPEFPUOP_CONV_32_32(efsctuiz);
8313GEN_SPEFPUOP_CONV_32_32(efsctsiz);
8314GEN_SPEFPUOP_CONV_32_64(efscfd);
8315
0487d6a8 8316/* Comparison */
1c97856d
AJ
8317GEN_SPEFPUOP_COMP_32(efscmpgt);
8318GEN_SPEFPUOP_COMP_32(efscmplt);
8319GEN_SPEFPUOP_COMP_32(efscmpeq);
8320GEN_SPEFPUOP_COMP_32(efststgt);
8321GEN_SPEFPUOP_COMP_32(efststlt);
8322GEN_SPEFPUOP_COMP_32(efststeq);
0487d6a8
JM
8323
8324/* Opcodes definitions */
70560da7
FC
8325GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
8326GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); //
8327GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8328GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); //
8329GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
8330GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); //
8331GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8332GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8333GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8334GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); //
8335GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8336GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
8337GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); //
8338GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); //
0487d6a8
JM
8339
8340/* Double precision floating-point operations */
8341/* Arithmetic */
1c97856d
AJ
8342GEN_SPEFPUOP_ARITH2_64_64(efdadd);
8343GEN_SPEFPUOP_ARITH2_64_64(efdsub);
8344GEN_SPEFPUOP_ARITH2_64_64(efdmul);
8345GEN_SPEFPUOP_ARITH2_64_64(efddiv);
636aa200 8346static inline void gen_efdabs(DisasContext *ctx)
1c97856d
AJ
8347{
8348 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8349 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8350 return;
8351 }
8352#if defined(TARGET_PPC64)
6d5c34fa 8353 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
1c97856d 8354#else
6d5c34fa
MP
8355 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8356 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
1c97856d
AJ
8357#endif
8358}
636aa200 8359static inline void gen_efdnabs(DisasContext *ctx)
1c97856d
AJ
8360{
8361 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8362 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8363 return;
8364 }
8365#if defined(TARGET_PPC64)
6d5c34fa 8366 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 8367#else
6d5c34fa
MP
8368 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8369 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
8370#endif
8371}
636aa200 8372static inline void gen_efdneg(DisasContext *ctx)
1c97856d
AJ
8373{
8374 if (unlikely(!ctx->spe_enabled)) {
27a69bb0 8375 gen_exception(ctx, POWERPC_EXCP_SPEU);
1c97856d
AJ
8376 return;
8377 }
8378#if defined(TARGET_PPC64)
6d5c34fa 8379 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
1c97856d 8380#else
6d5c34fa
MP
8381 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8382 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
1c97856d
AJ
8383#endif
8384}
8385
0487d6a8 8386/* Conversion */
1c97856d
AJ
8387GEN_SPEFPUOP_CONV_64_32(efdcfui);
8388GEN_SPEFPUOP_CONV_64_32(efdcfsi);
8389GEN_SPEFPUOP_CONV_64_32(efdcfuf);
8390GEN_SPEFPUOP_CONV_64_32(efdcfsf);
8391GEN_SPEFPUOP_CONV_32_64(efdctui);
8392GEN_SPEFPUOP_CONV_32_64(efdctsi);
8393GEN_SPEFPUOP_CONV_32_64(efdctuf);
8394GEN_SPEFPUOP_CONV_32_64(efdctsf);
8395GEN_SPEFPUOP_CONV_32_64(efdctuiz);
8396GEN_SPEFPUOP_CONV_32_64(efdctsiz);
8397GEN_SPEFPUOP_CONV_64_32(efdcfs);
8398GEN_SPEFPUOP_CONV_64_64(efdcfuid);
8399GEN_SPEFPUOP_CONV_64_64(efdcfsid);
8400GEN_SPEFPUOP_CONV_64_64(efdctuidz);
8401GEN_SPEFPUOP_CONV_64_64(efdctsidz);
0487d6a8 8402
0487d6a8 8403/* Comparison */
1c97856d
AJ
8404GEN_SPEFPUOP_COMP_64(efdcmpgt);
8405GEN_SPEFPUOP_COMP_64(efdcmplt);
8406GEN_SPEFPUOP_COMP_64(efdcmpeq);
8407GEN_SPEFPUOP_COMP_64(efdtstgt);
8408GEN_SPEFPUOP_COMP_64(efdtstlt);
8409GEN_SPEFPUOP_COMP_64(efdtsteq);
0487d6a8
JM
8410
8411/* Opcodes definitions */
70560da7
FC
8412GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
8413GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8414GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); //
8415GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
8416GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); //
8417GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8418GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
8419GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); //
8420GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8421GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8422GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8423GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); //
8424GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
8425GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
8426GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); //
8427GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); //
0487d6a8 8428
c227f099 8429static opcode_t opcodes[] = {
5c55ff99
BS
8430GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
8431GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
8432GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
8433GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
8434GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
8435GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
8436GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8437GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8438GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8439GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8440GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
8441GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
8442GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
8443GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
8444GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8445#if defined(TARGET_PPC64)
8446GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
8447#endif
8448GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
8449GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
8450GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8451GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8452GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8453GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
8454GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
8455GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
8456GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8457GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8458GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8459GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8460GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
eaabeef2 8461GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
5c55ff99 8462#if defined(TARGET_PPC64)
eaabeef2 8463GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
5c55ff99
BS
8464GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
8465#endif
8466GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8467GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8468GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8469GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
8470GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
8471GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
8472GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
8473#if defined(TARGET_PPC64)
8474GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
8475GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
8476GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
8477GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
8478GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
8479#endif
8480GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
8481GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
8482GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
8483GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
8484GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
8485GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
8486GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
8487GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
8488GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
8489GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
8490GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT),
8491GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT),
8492#if defined(TARGET_PPC64)
8493GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
8494GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
8495GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
8496#endif
8497GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8498GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8499GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
8500GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
8501GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
8502GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
8503GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
8504GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
f844c817 8505GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
5c55ff99
BS
8506GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
8507#if defined(TARGET_PPC64)
f844c817 8508GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
5c55ff99
BS
8509GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
8510#endif
8511GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
8512GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
8513GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8514GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8515GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
8516GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
8517GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
8518GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
8519#if defined(TARGET_PPC64)
8520GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
8521GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
8522#endif
8523GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
8524GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
8525GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8526#if defined(TARGET_PPC64)
8527GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
8528GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
8529#endif
8530GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
8531GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
8532GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
8533GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
8534GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
8535GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
8536#if defined(TARGET_PPC64)
8537GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
8538#endif
8539GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
8540GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
8541GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
8542GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
8543GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
8544GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE),
8545GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE),
8e33944f 8546GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ),
5c55ff99
BS
8547GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
8548GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
8549GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
8550GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
8551GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
8552GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
8553GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
8554GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
8555GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
8556#if defined(TARGET_PPC64)
8557GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
8558GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8559 PPC_SEGMENT_64B),
8560GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
8561GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8562 PPC_SEGMENT_64B),
efdef95f
DG
8563GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
8564GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
8565GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
5c55ff99
BS
8566#endif
8567GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
8568GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
8569GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
8570GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
8571#if defined(TARGET_PPC64)
8572GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
8573GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
8574#endif
8575GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
8576GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
8577GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
8578GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
8579GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
8580GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
8581GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
8582GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
8583GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
8584GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
8585GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
8586GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
8587GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
8588GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
8589GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
8590GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
8591GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
8592GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
8593GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
8594GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
8595GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
8596GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
8597GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
8598GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
8599GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
8600GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
8601GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
8602GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
8603GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
8604GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
8605GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
8606GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
8607GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
8608GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
8609GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
8610GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
8611GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
8612GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
8613GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
8614GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
8615GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
8616GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
8617GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
8618GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
8619GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
8620GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
8621GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
8622GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
8623GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
8624GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8625GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8626GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
8627GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
8628GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8629GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8630GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
8631GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
8632GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
8633GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
8634GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
8635GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
8636GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
8637GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
8638GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
8639GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
8640GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
8641GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
8642GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
8643GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
8644GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
8645GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
01662f3e 8646GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
8647GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
8648GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
8649GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
8650GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
8651GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
8652GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
8653GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
8654GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
01662f3e
AG
8655GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8656 PPC_NONE, PPC2_BOOKE206),
8657GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8658 PPC_NONE, PPC2_BOOKE206),
8659GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8660 PPC_NONE, PPC2_BOOKE206),
8661GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8662 PPC_NONE, PPC2_BOOKE206),
6d3db821
AG
8663GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8664 PPC_NONE, PPC2_BOOKE206),
d5d11a39
AG
8665GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8666 PPC_NONE, PPC2_PRCNTL),
9e0b5cb1
AG
8667GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8668 PPC_NONE, PPC2_PRCNTL),
5c55ff99 8669GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
fbe73008 8670GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
5c55ff99 8671GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
01662f3e
AG
8672GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
8673 PPC_BOOKE, PPC2_BOOKE206),
dcb2b9e1 8674GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
01662f3e
AG
8675GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8676 PPC_BOOKE, PPC2_BOOKE206),
5c55ff99
BS
8677GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
8678GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
8679GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
8680GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
8681GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC),
8682GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
8683GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
8684GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
8685GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
8686GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
8687
8688#undef GEN_INT_ARITH_ADD
8689#undef GEN_INT_ARITH_ADD_CONST
8690#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8691GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8692#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8693 add_ca, compute_ca, compute_ov) \
8694GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8695GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
8696GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
8697GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
8698GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
8699GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
8700GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
8701GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
8702GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
8703GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
8704GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
8705
8706#undef GEN_INT_ARITH_DIVW
8707#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8708GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8709GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
8710GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
8711GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
8712GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
8713
8714#if defined(TARGET_PPC64)
8715#undef GEN_INT_ARITH_DIVD
8716#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8717GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8718GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
8719GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
8720GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
8721GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
8722
8723#undef GEN_INT_ARITH_MUL_HELPER
8724#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8725GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8726GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
8727GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
8728GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
8729#endif
8730
8731#undef GEN_INT_ARITH_SUBF
8732#undef GEN_INT_ARITH_SUBF_CONST
8733#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8734GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8735#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8736 add_ca, compute_ca, compute_ov) \
8737GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8738GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
8739GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
8740GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
8741GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
8742GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
8743GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
8744GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
8745GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
8746GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
8747GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
8748
8749#undef GEN_LOGICAL1
8750#undef GEN_LOGICAL2
8751#define GEN_LOGICAL2(name, tcg_op, opc, type) \
8752GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8753#define GEN_LOGICAL1(name, tcg_op, opc, type) \
8754GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8755GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
8756GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
8757GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
8758GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
8759GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
8760GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
8761GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
8762GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
8763#if defined(TARGET_PPC64)
8764GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
8765#endif
8766
8767#if defined(TARGET_PPC64)
8768#undef GEN_PPC64_R2
8769#undef GEN_PPC64_R4
8770#define GEN_PPC64_R2(name, opc1, opc2) \
8771GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8772GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8773 PPC_64B)
8774#define GEN_PPC64_R4(name, opc1, opc2) \
8775GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8776GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8777 PPC_64B), \
8778GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8779 PPC_64B), \
8780GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8781 PPC_64B)
8782GEN_PPC64_R4(rldicl, 0x1E, 0x00),
8783GEN_PPC64_R4(rldicr, 0x1E, 0x02),
8784GEN_PPC64_R4(rldic, 0x1E, 0x04),
8785GEN_PPC64_R2(rldcl, 0x1E, 0x08),
8786GEN_PPC64_R2(rldcr, 0x1E, 0x09),
8787GEN_PPC64_R4(rldimi, 0x1E, 0x06),
8788#endif
8789
8790#undef _GEN_FLOAT_ACB
8791#undef GEN_FLOAT_ACB
8792#undef _GEN_FLOAT_AB
8793#undef GEN_FLOAT_AB
8794#undef _GEN_FLOAT_AC
8795#undef GEN_FLOAT_AC
8796#undef GEN_FLOAT_B
8797#undef GEN_FLOAT_BS
8798#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
8799GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
8800#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
8801_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
8802_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
8803#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8804GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8805#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
8806_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8807_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8808#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8809GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8810#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
8811_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8812_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8813#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
8814GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
8815#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
8816GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
8817
8818GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
8819GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
8820GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
8821GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
8822GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
8823GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
8824_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
8825GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
8826GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
8827GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
8828GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
8829GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
8830GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
8831GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
8832GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
8833#if defined(TARGET_PPC64)
8834GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
8835GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
8836GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
8837#endif
8838GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
8839GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
8840GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
8841GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
8842GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT),
8843GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT),
8844GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT),
8845
8846#undef GEN_LD
8847#undef GEN_LDU
8848#undef GEN_LDUX
cd6e9320 8849#undef GEN_LDX_E
5c55ff99
BS
8850#undef GEN_LDS
8851#define GEN_LD(name, ldop, opc, type) \
8852GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8853#define GEN_LDU(name, ldop, opc, type) \
8854GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8855#define GEN_LDUX(name, ldop, opc2, opc3, type) \
8856GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
8857#define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
8858GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
8859#define GEN_LDS(name, ldop, op, type) \
8860GEN_LD(name, ldop, op | 0x20, type) \
8861GEN_LDU(name, ldop, op | 0x21, type) \
8862GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
8863GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8864
8865GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
8866GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
8867GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
8868GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
8869#if defined(TARGET_PPC64)
8870GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
8871GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
8872GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
8873GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
cd6e9320 8874GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
8875#endif
8876GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
8877GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
8878
8879#undef GEN_ST
8880#undef GEN_STU
8881#undef GEN_STUX
cd6e9320 8882#undef GEN_STX_E
5c55ff99
BS
8883#undef GEN_STS
8884#define GEN_ST(name, stop, opc, type) \
8885GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8886#define GEN_STU(name, stop, opc, type) \
8887GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8888#define GEN_STUX(name, stop, opc2, opc3, type) \
8889GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
cd6e9320
TH
8890#define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
8891GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
5c55ff99
BS
8892#define GEN_STS(name, stop, op, type) \
8893GEN_ST(name, stop, op | 0x20, type) \
8894GEN_STU(name, stop, op | 0x21, type) \
8895GEN_STUX(name, stop, 0x17, op | 0x01, type) \
8896GEN_STX(name, stop, 0x17, op | 0x00, type)
8897
8898GEN_STS(stb, st8, 0x06, PPC_INTEGER)
8899GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
8900GEN_STS(stw, st32, 0x04, PPC_INTEGER)
8901#if defined(TARGET_PPC64)
8902GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
8903GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
cd6e9320 8904GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX)
5c55ff99
BS
8905#endif
8906GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
8907GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
8908
8909#undef GEN_LDF
8910#undef GEN_LDUF
8911#undef GEN_LDUXF
8912#undef GEN_LDXF
8913#undef GEN_LDFS
8914#define GEN_LDF(name, ldop, opc, type) \
8915GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8916#define GEN_LDUF(name, ldop, opc, type) \
8917GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8918#define GEN_LDUXF(name, ldop, opc, type) \
8919GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8920#define GEN_LDXF(name, ldop, opc2, opc3, type) \
8921GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8922#define GEN_LDFS(name, ldop, op, type) \
8923GEN_LDF(name, ldop, op | 0x20, type) \
8924GEN_LDUF(name, ldop, op | 0x21, type) \
8925GEN_LDUXF(name, ldop, op | 0x01, type) \
8926GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
8927
8928GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
8929GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
8930
8931#undef GEN_STF
8932#undef GEN_STUF
8933#undef GEN_STUXF
8934#undef GEN_STXF
8935#undef GEN_STFS
8936#define GEN_STF(name, stop, opc, type) \
8937GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8938#define GEN_STUF(name, stop, opc, type) \
8939GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8940#define GEN_STUXF(name, stop, opc, type) \
8941GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8942#define GEN_STXF(name, stop, opc2, opc3, type) \
8943GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8944#define GEN_STFS(name, stop, op, type) \
8945GEN_STF(name, stop, op | 0x20, type) \
8946GEN_STUF(name, stop, op | 0x21, type) \
8947GEN_STUXF(name, stop, op | 0x01, type) \
8948GEN_STXF(name, stop, 0x17, op | 0x00, type)
8949
8950GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
8951GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
8952GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
8953
8954#undef GEN_CRLOGIC
8955#define GEN_CRLOGIC(name, tcg_op, opc) \
8956GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
8957GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
8958GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
8959GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
8960GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
8961GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
8962GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
8963GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
8964GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
8965
8966#undef GEN_MAC_HANDLER
8967#define GEN_MAC_HANDLER(name, opc2, opc3) \
8968GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
8969GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
8970GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
8971GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
8972GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
8973GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
8974GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
8975GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
8976GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
8977GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
8978GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
8979GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
8980GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
8981GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
8982GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
8983GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
8984GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
8985GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
8986GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
8987GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
8988GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
8989GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
8990GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
8991GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
8992GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
8993GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
8994GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
8995GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
8996GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
8997GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
8998GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
8999GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
9000GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
9001GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
9002GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
9003GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
9004GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
9005GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
9006GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
9007GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
9008GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
9009GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
9010GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
9011
9012#undef GEN_VR_LDX
9013#undef GEN_VR_STX
9014#undef GEN_VR_LVE
9015#undef GEN_VR_STVE
9016#define GEN_VR_LDX(name, opc2, opc3) \
9017GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9018#define GEN_VR_STX(name, opc2, opc3) \
9019GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9020#define GEN_VR_LVE(name, opc2, opc3) \
9021 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9022#define GEN_VR_STVE(name, opc2, opc3) \
9023 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9024GEN_VR_LDX(lvx, 0x07, 0x03),
9025GEN_VR_LDX(lvxl, 0x07, 0x0B),
9026GEN_VR_LVE(bx, 0x07, 0x00),
9027GEN_VR_LVE(hx, 0x07, 0x01),
9028GEN_VR_LVE(wx, 0x07, 0x02),
9029GEN_VR_STX(svx, 0x07, 0x07),
9030GEN_VR_STX(svxl, 0x07, 0x0F),
9031GEN_VR_STVE(bx, 0x07, 0x04),
9032GEN_VR_STVE(hx, 0x07, 0x05),
9033GEN_VR_STVE(wx, 0x07, 0x06),
9034
9035#undef GEN_VX_LOGICAL
9036#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9037GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9038GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
9039GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
9040GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
9041GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
9042GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
9043
9044#undef GEN_VXFORM
9045#define GEN_VXFORM(name, opc2, opc3) \
9046GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9047GEN_VXFORM(vaddubm, 0, 0),
9048GEN_VXFORM(vadduhm, 0, 1),
9049GEN_VXFORM(vadduwm, 0, 2),
9050GEN_VXFORM(vsububm, 0, 16),
9051GEN_VXFORM(vsubuhm, 0, 17),
9052GEN_VXFORM(vsubuwm, 0, 18),
9053GEN_VXFORM(vmaxub, 1, 0),
9054GEN_VXFORM(vmaxuh, 1, 1),
9055GEN_VXFORM(vmaxuw, 1, 2),
9056GEN_VXFORM(vmaxsb, 1, 4),
9057GEN_VXFORM(vmaxsh, 1, 5),
9058GEN_VXFORM(vmaxsw, 1, 6),
9059GEN_VXFORM(vminub, 1, 8),
9060GEN_VXFORM(vminuh, 1, 9),
9061GEN_VXFORM(vminuw, 1, 10),
9062GEN_VXFORM(vminsb, 1, 12),
9063GEN_VXFORM(vminsh, 1, 13),
9064GEN_VXFORM(vminsw, 1, 14),
9065GEN_VXFORM(vavgub, 1, 16),
9066GEN_VXFORM(vavguh, 1, 17),
9067GEN_VXFORM(vavguw, 1, 18),
9068GEN_VXFORM(vavgsb, 1, 20),
9069GEN_VXFORM(vavgsh, 1, 21),
9070GEN_VXFORM(vavgsw, 1, 22),
9071GEN_VXFORM(vmrghb, 6, 0),
9072GEN_VXFORM(vmrghh, 6, 1),
9073GEN_VXFORM(vmrghw, 6, 2),
9074GEN_VXFORM(vmrglb, 6, 4),
9075GEN_VXFORM(vmrglh, 6, 5),
9076GEN_VXFORM(vmrglw, 6, 6),
9077GEN_VXFORM(vmuloub, 4, 0),
9078GEN_VXFORM(vmulouh, 4, 1),
9079GEN_VXFORM(vmulosb, 4, 4),
9080GEN_VXFORM(vmulosh, 4, 5),
9081GEN_VXFORM(vmuleub, 4, 8),
9082GEN_VXFORM(vmuleuh, 4, 9),
9083GEN_VXFORM(vmulesb, 4, 12),
9084GEN_VXFORM(vmulesh, 4, 13),
9085GEN_VXFORM(vslb, 2, 4),
9086GEN_VXFORM(vslh, 2, 5),
9087GEN_VXFORM(vslw, 2, 6),
9088GEN_VXFORM(vsrb, 2, 8),
9089GEN_VXFORM(vsrh, 2, 9),
9090GEN_VXFORM(vsrw, 2, 10),
9091GEN_VXFORM(vsrab, 2, 12),
9092GEN_VXFORM(vsrah, 2, 13),
9093GEN_VXFORM(vsraw, 2, 14),
9094GEN_VXFORM(vslo, 6, 16),
9095GEN_VXFORM(vsro, 6, 17),
9096GEN_VXFORM(vaddcuw, 0, 6),
9097GEN_VXFORM(vsubcuw, 0, 22),
9098GEN_VXFORM(vaddubs, 0, 8),
9099GEN_VXFORM(vadduhs, 0, 9),
9100GEN_VXFORM(vadduws, 0, 10),
9101GEN_VXFORM(vaddsbs, 0, 12),
9102GEN_VXFORM(vaddshs, 0, 13),
9103GEN_VXFORM(vaddsws, 0, 14),
9104GEN_VXFORM(vsububs, 0, 24),
9105GEN_VXFORM(vsubuhs, 0, 25),
9106GEN_VXFORM(vsubuws, 0, 26),
9107GEN_VXFORM(vsubsbs, 0, 28),
9108GEN_VXFORM(vsubshs, 0, 29),
9109GEN_VXFORM(vsubsws, 0, 30),
9110GEN_VXFORM(vrlb, 2, 0),
9111GEN_VXFORM(vrlh, 2, 1),
9112GEN_VXFORM(vrlw, 2, 2),
9113GEN_VXFORM(vsl, 2, 7),
9114GEN_VXFORM(vsr, 2, 11),
9115GEN_VXFORM(vpkuhum, 7, 0),
9116GEN_VXFORM(vpkuwum, 7, 1),
9117GEN_VXFORM(vpkuhus, 7, 2),
9118GEN_VXFORM(vpkuwus, 7, 3),
9119GEN_VXFORM(vpkshus, 7, 4),
9120GEN_VXFORM(vpkswus, 7, 5),
9121GEN_VXFORM(vpkshss, 7, 6),
9122GEN_VXFORM(vpkswss, 7, 7),
9123GEN_VXFORM(vpkpx, 7, 12),
9124GEN_VXFORM(vsum4ubs, 4, 24),
9125GEN_VXFORM(vsum4sbs, 4, 28),
9126GEN_VXFORM(vsum4shs, 4, 25),
9127GEN_VXFORM(vsum2sws, 4, 26),
9128GEN_VXFORM(vsumsws, 4, 30),
9129GEN_VXFORM(vaddfp, 5, 0),
9130GEN_VXFORM(vsubfp, 5, 1),
9131GEN_VXFORM(vmaxfp, 5, 16),
9132GEN_VXFORM(vminfp, 5, 17),
9133
9134#undef GEN_VXRFORM1
9135#undef GEN_VXRFORM
9136#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
9137 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
9138#define GEN_VXRFORM(name, opc2, opc3) \
9139 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
9140 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
9141GEN_VXRFORM(vcmpequb, 3, 0)
9142GEN_VXRFORM(vcmpequh, 3, 1)
9143GEN_VXRFORM(vcmpequw, 3, 2)
9144GEN_VXRFORM(vcmpgtsb, 3, 12)
9145GEN_VXRFORM(vcmpgtsh, 3, 13)
9146GEN_VXRFORM(vcmpgtsw, 3, 14)
9147GEN_VXRFORM(vcmpgtub, 3, 8)
9148GEN_VXRFORM(vcmpgtuh, 3, 9)
9149GEN_VXRFORM(vcmpgtuw, 3, 10)
9150GEN_VXRFORM(vcmpeqfp, 3, 3)
9151GEN_VXRFORM(vcmpgefp, 3, 7)
9152GEN_VXRFORM(vcmpgtfp, 3, 11)
9153GEN_VXRFORM(vcmpbfp, 3, 15)
9154
9155#undef GEN_VXFORM_SIMM
9156#define GEN_VXFORM_SIMM(name, opc2, opc3) \
9157 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9158GEN_VXFORM_SIMM(vspltisb, 6, 12),
9159GEN_VXFORM_SIMM(vspltish, 6, 13),
9160GEN_VXFORM_SIMM(vspltisw, 6, 14),
9161
9162#undef GEN_VXFORM_NOA
9163#define GEN_VXFORM_NOA(name, opc2, opc3) \
9164 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9165GEN_VXFORM_NOA(vupkhsb, 7, 8),
9166GEN_VXFORM_NOA(vupkhsh, 7, 9),
9167GEN_VXFORM_NOA(vupklsb, 7, 10),
9168GEN_VXFORM_NOA(vupklsh, 7, 11),
9169GEN_VXFORM_NOA(vupkhpx, 7, 13),
9170GEN_VXFORM_NOA(vupklpx, 7, 15),
9171GEN_VXFORM_NOA(vrefp, 5, 4),
9172GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
0bffbc6c 9173GEN_VXFORM_NOA(vexptefp, 5, 6),
5c55ff99
BS
9174GEN_VXFORM_NOA(vlogefp, 5, 7),
9175GEN_VXFORM_NOA(vrfim, 5, 8),
9176GEN_VXFORM_NOA(vrfin, 5, 9),
9177GEN_VXFORM_NOA(vrfip, 5, 10),
9178GEN_VXFORM_NOA(vrfiz, 5, 11),
9179
9180#undef GEN_VXFORM_UIMM
9181#define GEN_VXFORM_UIMM(name, opc2, opc3) \
9182 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9183GEN_VXFORM_UIMM(vspltb, 6, 8),
9184GEN_VXFORM_UIMM(vsplth, 6, 9),
9185GEN_VXFORM_UIMM(vspltw, 6, 10),
9186GEN_VXFORM_UIMM(vcfux, 5, 12),
9187GEN_VXFORM_UIMM(vcfsx, 5, 13),
9188GEN_VXFORM_UIMM(vctuxs, 5, 14),
9189GEN_VXFORM_UIMM(vctsxs, 5, 15),
9190
9191#undef GEN_VAFORM_PAIRED
9192#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9193 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9194GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
9195GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
9196GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
9197GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
9198GEN_VAFORM_PAIRED(vsel, vperm, 21),
9199GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
9200
9201#undef GEN_SPE
70560da7
FC
9202#define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
9203 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
9204GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9205GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9206GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9207GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9208GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
9209GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
9210GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE),
9211GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE),
9212GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE),
9213GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
9214GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9215GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9216GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9217GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
9218GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE),
9219GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE),
9220GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE),
9221GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9222GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9223GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9224GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9225GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE),
9226GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
9227GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE),
9228GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9229GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE),
9230GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE),
9231GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE),
9232GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE),
9233
9234GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
9235GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
9236GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
9237GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
9238GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
9239GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9240GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9241GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9242GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9243GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9244GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9245GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9246GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
9247GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9248
9249GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
9250GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE),
9251GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE),
9252GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE),
9253GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
9254GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE),
9255GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9256GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9257GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9258GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE),
9259GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9260GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9261GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE),
9262GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE),
9263
9264GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
9265GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9266GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE),
9267GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE),
9268GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE),
9269GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9270GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
9271GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE),
9272GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9273GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9274GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9275GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE),
9276GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
9277GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
9278GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE),
9279GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE),
5c55ff99
BS
9280
9281#undef GEN_SPEOP_LDST
9282#define GEN_SPEOP_LDST(name, opc2, sh) \
9283GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9284GEN_SPEOP_LDST(evldd, 0x00, 3),
9285GEN_SPEOP_LDST(evldw, 0x01, 3),
9286GEN_SPEOP_LDST(evldh, 0x02, 3),
9287GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
9288GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
9289GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
9290GEN_SPEOP_LDST(evlwhe, 0x08, 2),
9291GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
9292GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
9293GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
9294GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
9295
9296GEN_SPEOP_LDST(evstdd, 0x10, 3),
9297GEN_SPEOP_LDST(evstdw, 0x11, 3),
9298GEN_SPEOP_LDST(evstdh, 0x12, 3),
9299GEN_SPEOP_LDST(evstwhe, 0x18, 2),
9300GEN_SPEOP_LDST(evstwho, 0x1A, 2),
9301GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
9302GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
9303};
9304
0411a972 9305#include "helper_regs.h"
a1389542 9306#include "translate_init.c"
79aceca5 9307
9a64fbe4 9308/*****************************************************************************/
3fc6c082 9309/* Misc PowerPC helpers */
1328c2bf 9310void cpu_dump_state (CPUPPCState *env, FILE *f, fprintf_function cpu_fprintf,
36081602 9311 int flags)
79aceca5 9312{
3fc6c082
FB
9313#define RGPL 4
9314#define RFPL 4
3fc6c082 9315
79aceca5
FB
9316 int i;
9317
29979a8d
AG
9318 cpu_synchronize_state(env);
9319
90e189ec 9320 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
9a78eead 9321 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
da91a00f 9322 env->nip, env->lr, env->ctr, cpu_read_xer(env));
90e189ec
BS
9323 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
9324 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
9325 env->hflags, env->mmu_idx);
d9bce9d9 9326#if !defined(NO_TIMER_DUMP)
9a78eead 9327 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
76a66253 9328#if !defined(CONFIG_USER_ONLY)
9a78eead 9329 " DECR %08" PRIu32
76a66253
JM
9330#endif
9331 "\n",
077fc206 9332 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
76a66253
JM
9333#if !defined(CONFIG_USER_ONLY)
9334 , cpu_ppc_load_decr(env)
9335#endif
9336 );
077fc206 9337#endif
76a66253 9338 for (i = 0; i < 32; i++) {
3fc6c082
FB
9339 if ((i & (RGPL - 1)) == 0)
9340 cpu_fprintf(f, "GPR%02d", i);
b11ebf64 9341 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
3fc6c082 9342 if ((i & (RGPL - 1)) == (RGPL - 1))
7fe48483 9343 cpu_fprintf(f, "\n");
76a66253 9344 }
3fc6c082 9345 cpu_fprintf(f, "CR ");
76a66253 9346 for (i = 0; i < 8; i++)
7fe48483
FB
9347 cpu_fprintf(f, "%01x", env->crf[i]);
9348 cpu_fprintf(f, " [");
76a66253
JM
9349 for (i = 0; i < 8; i++) {
9350 char a = '-';
9351 if (env->crf[i] & 0x08)
9352 a = 'L';
9353 else if (env->crf[i] & 0x04)
9354 a = 'G';
9355 else if (env->crf[i] & 0x02)
9356 a = 'E';
7fe48483 9357 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
76a66253 9358 }
90e189ec
BS
9359 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
9360 env->reserve_addr);
3fc6c082
FB
9361 for (i = 0; i < 32; i++) {
9362 if ((i & (RFPL - 1)) == 0)
9363 cpu_fprintf(f, "FPR%02d", i);
26a76461 9364 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
3fc6c082 9365 if ((i & (RFPL - 1)) == (RFPL - 1))
7fe48483 9366 cpu_fprintf(f, "\n");
79aceca5 9367 }
30304420 9368 cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr);
f2e63a42 9369#if !defined(CONFIG_USER_ONLY)
90dc8812
SW
9370 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
9371 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
9372 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
9373 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
9374
9375 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
9376 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
9377 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
9378 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
9379
9380 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
9381 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
9382 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
9383 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
9384
9385 if (env->excp_model == POWERPC_EXCP_BOOKE) {
9386 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
9387 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
9388 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
9389 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
9390
9391 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
9392 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
9393 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
9394 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
9395
9396 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
9397 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
9398 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
9399 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
9400
9401 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
9402 " EPR " TARGET_FMT_lx "\n",
9403 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
9404 env->spr[SPR_BOOKE_EPR]);
9405
9406 /* FSL-specific */
9407 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
9408 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
9409 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
9410 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
9411
9412 /*
9413 * IVORs are left out as they are large and do not change often --
9414 * they can be read with "p $ivor0", "p $ivor1", etc.
9415 */
9416 }
9417
697ab892
DG
9418#if defined(TARGET_PPC64)
9419 if (env->flags & POWERPC_FLAG_CFAR) {
9420 cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar);
9421 }
9422#endif
9423
90dc8812
SW
9424 switch (env->mmu_model) {
9425 case POWERPC_MMU_32B:
9426 case POWERPC_MMU_601:
9427 case POWERPC_MMU_SOFT_6xx:
9428 case POWERPC_MMU_SOFT_74xx:
9429#if defined(TARGET_PPC64)
9430 case POWERPC_MMU_620:
9431 case POWERPC_MMU_64B:
9432#endif
9433 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx "\n", env->spr[SPR_SDR1]);
9434 break;
01662f3e 9435 case POWERPC_MMU_BOOKE206:
90dc8812
SW
9436 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
9437 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
9438 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
9439 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
9440
9441 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
9442 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
9443 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
9444 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
9445
9446 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
9447 " TLB1CFG " TARGET_FMT_lx "\n",
9448 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
9449 env->spr[SPR_BOOKE_TLB1CFG]);
9450 break;
9451 default:
9452 break;
9453 }
f2e63a42 9454#endif
79aceca5 9455
3fc6c082
FB
9456#undef RGPL
9457#undef RFPL
79aceca5
FB
9458}
9459
1328c2bf 9460void cpu_dump_statistics (CPUPPCState *env, FILE*f, fprintf_function cpu_fprintf,
76a66253
JM
9461 int flags)
9462{
9463#if defined(DO_PPC_STATISTICS)
c227f099 9464 opc_handler_t **t1, **t2, **t3, *handler;
76a66253
JM
9465 int op1, op2, op3;
9466
9467 t1 = env->opcodes;
9468 for (op1 = 0; op1 < 64; op1++) {
9469 handler = t1[op1];
9470 if (is_indirect_opcode(handler)) {
9471 t2 = ind_table(handler);
9472 for (op2 = 0; op2 < 32; op2++) {
9473 handler = t2[op2];
9474 if (is_indirect_opcode(handler)) {
9475 t3 = ind_table(handler);
9476 for (op3 = 0; op3 < 32; op3++) {
9477 handler = t3[op3];
9478 if (handler->count == 0)
9479 continue;
9480 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
0bfcd599 9481 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
9482 op1, op2, op3, op1, (op3 << 5) | op2,
9483 handler->oname,
9484 handler->count, handler->count);
9485 }
9486 } else {
9487 if (handler->count == 0)
9488 continue;
9489 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
0bfcd599 9490 "%016" PRIx64 " %" PRId64 "\n",
76a66253
JM
9491 op1, op2, op1, op2, handler->oname,
9492 handler->count, handler->count);
9493 }
9494 }
9495 } else {
9496 if (handler->count == 0)
9497 continue;
0bfcd599
BS
9498 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
9499 " %" PRId64 "\n",
76a66253
JM
9500 op1, op1, handler->oname,
9501 handler->count, handler->count);
9502 }
9503 }
9504#endif
9505}
9506
9a64fbe4 9507/*****************************************************************************/
1328c2bf 9508static inline void gen_intermediate_code_internal(CPUPPCState *env,
636aa200
BS
9509 TranslationBlock *tb,
9510 int search_pc)
79aceca5 9511{
9fddaa0c 9512 DisasContext ctx, *ctxp = &ctx;
c227f099 9513 opc_handler_t **table, *handler;
0fa85d43 9514 target_ulong pc_start;
79aceca5 9515 uint16_t *gen_opc_end;
a1d1bb31 9516 CPUBreakpoint *bp;
79aceca5 9517 int j, lj = -1;
2e70f6ef
PB
9518 int num_insns;
9519 int max_insns;
79aceca5
FB
9520
9521 pc_start = tb->pc;
92414b31 9522 gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
046d6672 9523 ctx.nip = pc_start;
79aceca5 9524 ctx.tb = tb;
e1833e1f 9525 ctx.exception = POWERPC_EXCP_NONE;
3fc6c082 9526 ctx.spr_cb = env->spr_cb;
76db3ba4
AJ
9527 ctx.mem_idx = env->mmu_idx;
9528 ctx.access_type = -1;
9529 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
d9bce9d9 9530#if defined(TARGET_PPC64)
e42a61f1 9531 ctx.sf_mode = msr_is_64bit(env, env->msr);
697ab892 9532 ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR);
9a64fbe4 9533#endif
3cc62370 9534 ctx.fpu_enabled = msr_fp;
a9d9eb8f 9535 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
d26bfc9a
JM
9536 ctx.spe_enabled = msr_spe;
9537 else
9538 ctx.spe_enabled = 0;
a9d9eb8f
JM
9539 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
9540 ctx.altivec_enabled = msr_vr;
9541 else
9542 ctx.altivec_enabled = 0;
d26bfc9a 9543 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
8cbcb4fa 9544 ctx.singlestep_enabled = CPU_SINGLE_STEP;
d26bfc9a 9545 else
8cbcb4fa 9546 ctx.singlestep_enabled = 0;
d26bfc9a 9547 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
8cbcb4fa
AJ
9548 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
9549 if (unlikely(env->singlestep_enabled))
9550 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
3fc6c082 9551#if defined (DO_SINGLE_STEP) && 0
9a64fbe4
FB
9552 /* Single step trace mode */
9553 msr_se = 1;
9554#endif
2e70f6ef
PB
9555 num_insns = 0;
9556 max_insns = tb->cflags & CF_COUNT_MASK;
9557 if (max_insns == 0)
9558 max_insns = CF_COUNT_MASK;
9559
806f352d 9560 gen_tb_start();
9a64fbe4 9561 /* Set env in case of segfault during code fetch */
efd7f486
EV
9562 while (ctx.exception == POWERPC_EXCP_NONE
9563 && tcg_ctx.gen_opc_ptr < gen_opc_end) {
72cf2d4f
BS
9564 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
9565 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
a1d1bb31 9566 if (bp->pc == ctx.nip) {
e06fcd75 9567 gen_debug_exception(ctxp);
ea4e754f
FB
9568 break;
9569 }
9570 }
9571 }
76a66253 9572 if (unlikely(search_pc)) {
92414b31 9573 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
79aceca5
FB
9574 if (lj < j) {
9575 lj++;
9576 while (lj < j)
ab1103de 9577 tcg_ctx.gen_opc_instr_start[lj++] = 0;
79aceca5 9578 }
25983cad 9579 tcg_ctx.gen_opc_pc[lj] = ctx.nip;
ab1103de 9580 tcg_ctx.gen_opc_instr_start[lj] = 1;
c9c99c22 9581 tcg_ctx.gen_opc_icount[lj] = num_insns;
79aceca5 9582 }
d12d51d5 9583 LOG_DISAS("----------------\n");
90e189ec 9584 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
d12d51d5 9585 ctx.nip, ctx.mem_idx, (int)msr_ir);
2e70f6ef
PB
9586 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
9587 gen_io_start();
76db3ba4 9588 if (unlikely(ctx.le_mode)) {
2f5a189c 9589 ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip));
056401ea 9590 } else {
2f5a189c 9591 ctx.opcode = cpu_ldl_code(env, ctx.nip);
111bfab3 9592 }
d12d51d5 9593 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9a64fbe4 9594 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
476b6d16 9595 opc3(ctx.opcode), ctx.le_mode ? "little" : "big");
fdefe51c 9596 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
731c54f8 9597 tcg_gen_debug_insn_start(ctx.nip);
fdefe51c 9598 }
046d6672 9599 ctx.nip += 4;
3fc6c082 9600 table = env->opcodes;
2e70f6ef 9601 num_insns++;
79aceca5
FB
9602 handler = table[opc1(ctx.opcode)];
9603 if (is_indirect_opcode(handler)) {
9604 table = ind_table(handler);
9605 handler = table[opc2(ctx.opcode)];
9606 if (is_indirect_opcode(handler)) {
9607 table = ind_table(handler);
9608 handler = table[opc3(ctx.opcode)];
9609 }
9610 }
9611 /* Is opcode *REALLY* valid ? */
76a66253 9612 if (unlikely(handler->handler == &gen_invalid)) {
93fcfe39
AL
9613 if (qemu_log_enabled()) {
9614 qemu_log("invalid/unsupported opcode: "
90e189ec
BS
9615 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
9616 opc1(ctx.opcode), opc2(ctx.opcode),
9617 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
4b3686fa 9618 }
76a66253 9619 } else {
70560da7
FC
9620 uint32_t inval;
9621
9622 if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) {
9623 inval = handler->inval2;
9624 } else {
9625 inval = handler->inval1;
9626 }
9627
9628 if (unlikely((ctx.opcode & inval) != 0)) {
93fcfe39
AL
9629 if (qemu_log_enabled()) {
9630 qemu_log("invalid bits: %08x for opcode: "
90e189ec 9631 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
70560da7 9632 ctx.opcode & inval, opc1(ctx.opcode),
90e189ec
BS
9633 opc2(ctx.opcode), opc3(ctx.opcode),
9634 ctx.opcode, ctx.nip - 4);
76a66253 9635 }
e06fcd75 9636 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
4b3686fa 9637 break;
79aceca5 9638 }
79aceca5 9639 }
4b3686fa 9640 (*(handler->handler))(&ctx);
76a66253
JM
9641#if defined(DO_PPC_STATISTICS)
9642 handler->count++;
9643#endif
9a64fbe4 9644 /* Check trace mode exceptions */
8cbcb4fa
AJ
9645 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
9646 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
9647 ctx.exception != POWERPC_SYSCALL &&
9648 ctx.exception != POWERPC_EXCP_TRAP &&
9649 ctx.exception != POWERPC_EXCP_BRANCH)) {
e06fcd75 9650 gen_exception(ctxp, POWERPC_EXCP_TRACE);
d26bfc9a 9651 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
2e70f6ef 9652 (env->singlestep_enabled) ||
1b530a6d 9653 singlestep ||
2e70f6ef 9654 num_insns >= max_insns)) {
d26bfc9a
JM
9655 /* if we reach a page boundary or are single stepping, stop
9656 * generation
9657 */
8dd4983c 9658 break;
76a66253 9659 }
3fc6c082 9660 }
2e70f6ef
PB
9661 if (tb->cflags & CF_LAST_IO)
9662 gen_io_end();
e1833e1f 9663 if (ctx.exception == POWERPC_EXCP_NONE) {
c1942362 9664 gen_goto_tb(&ctx, 0, ctx.nip);
e1833e1f 9665 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
8cbcb4fa 9666 if (unlikely(env->singlestep_enabled)) {
e06fcd75 9667 gen_debug_exception(ctxp);
8cbcb4fa 9668 }
76a66253 9669 /* Generate the return instruction */
57fec1fe 9670 tcg_gen_exit_tb(0);
9a64fbe4 9671 }
806f352d 9672 gen_tb_end(tb, num_insns);
efd7f486 9673 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
76a66253 9674 if (unlikely(search_pc)) {
92414b31 9675 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
9a64fbe4
FB
9676 lj++;
9677 while (lj <= j)
ab1103de 9678 tcg_ctx.gen_opc_instr_start[lj++] = 0;
9a64fbe4 9679 } else {
046d6672 9680 tb->size = ctx.nip - pc_start;
2e70f6ef 9681 tb->icount = num_insns;
9a64fbe4 9682 }
d9bce9d9 9683#if defined(DEBUG_DISAS)
8fec2b8c 9684 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
76a66253 9685 int flags;
237c0af0 9686 flags = env->bfd_mach;
76db3ba4 9687 flags |= ctx.le_mode << 16;
93fcfe39 9688 qemu_log("IN: %s\n", lookup_symbol(pc_start));
f4359b9f 9689 log_target_disas(env, pc_start, ctx.nip - pc_start, flags);
93fcfe39 9690 qemu_log("\n");
9fddaa0c 9691 }
79aceca5 9692#endif
79aceca5
FB
9693}
9694
1328c2bf 9695void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 9696{
2cfc5f17 9697 gen_intermediate_code_internal(env, tb, 0);
79aceca5
FB
9698}
9699
1328c2bf 9700void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)
79aceca5 9701{
2cfc5f17 9702 gen_intermediate_code_internal(env, tb, 1);
79aceca5 9703}
d2856f1a 9704
1328c2bf 9705void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos)
d2856f1a 9706{
25983cad 9707 env->nip = tcg_ctx.gen_opc_pc[pc_pos];
d2856f1a 9708}