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