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