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