2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "qemu-common.h"
33 #define CPU_SINGLE_STEP 0x1
34 #define CPU_BRANCH_STEP 0x2
35 #define GDBSTUB_SINGLE_STEP 0x4
37 /* Include definitions for instructions classes and implementations flags */
38 //#define DO_SINGLE_STEP
39 //#define PPC_DEBUG_DISAS
40 //#define DO_PPC_STATISTICS
41 //#define OPTIMIZE_FPRF_UPDATE
43 /*****************************************************************************/
44 /* Code translation helpers */
46 /* global register indexes */
48 static char cpu_reg_names[10*3 + 22*4 /* GPR */
49 #if !defined(TARGET_PPC64)
50 + 10*4 + 22*5 /* SPE GPRh */
52 + 10*4 + 22*5 /* FPR */
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
55 static TCGv cpu_gpr[32];
56 #if !defined(TARGET_PPC64)
57 static TCGv cpu_gprh[32];
59 static TCGv cpu_fpr[32];
60 static TCGv cpu_avrh[32], cpu_avrl[32];
61 static TCGv cpu_crf[8];
66 static TCGv cpu_fpscr;
68 /* dyngen register indexes */
70 #if defined(TARGET_PPC64)
73 static TCGv cpu_T64[3];
75 static TCGv cpu_FT[3];
76 static TCGv cpu_AVRh[3], cpu_AVRl[3];
78 #include "gen-icount.h"
80 void ppc_translate_init(void)
84 static int done_init = 0;
89 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
90 #if TARGET_LONG_BITS > HOST_LONG_BITS
91 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
92 TCG_AREG0, offsetof(CPUState, t0), "T0");
93 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
94 TCG_AREG0, offsetof(CPUState, t1), "T1");
95 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
96 TCG_AREG0, offsetof(CPUState, t2), "T2");
98 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
99 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
100 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
102 #if !defined(TARGET_PPC64)
103 cpu_T64[0] = tcg_global_mem_new(TCG_TYPE_I64,
104 TCG_AREG0, offsetof(CPUState, t0_64),
106 cpu_T64[1] = tcg_global_mem_new(TCG_TYPE_I64,
107 TCG_AREG0, offsetof(CPUState, t1_64),
109 cpu_T64[2] = tcg_global_mem_new(TCG_TYPE_I64,
110 TCG_AREG0, offsetof(CPUState, t2_64),
114 cpu_FT[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
115 offsetof(CPUState, ft0), "FT0");
116 cpu_FT[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
117 offsetof(CPUState, ft1), "FT1");
118 cpu_FT[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
119 offsetof(CPUState, ft2), "FT2");
121 cpu_AVRh[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
122 offsetof(CPUState, avr0.u64[0]), "AVR0H");
123 cpu_AVRl[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
124 offsetof(CPUState, avr0.u64[1]), "AVR0L");
125 cpu_AVRh[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
126 offsetof(CPUState, avr1.u64[0]), "AVR1H");
127 cpu_AVRl[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
128 offsetof(CPUState, avr1.u64[1]), "AVR1L");
129 cpu_AVRh[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
130 offsetof(CPUState, avr2.u64[0]), "AVR2H");
131 cpu_AVRl[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
132 offsetof(CPUState, avr2.u64[1]), "AVR2L");
136 for (i = 0; i < 8; i++) {
137 sprintf(p, "crf%d", i);
138 cpu_crf[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
139 offsetof(CPUState, crf[i]), p);
143 for (i = 0; i < 32; i++) {
144 sprintf(p, "r%d", i);
145 cpu_gpr[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
146 offsetof(CPUState, gpr[i]), p);
147 p += (i < 10) ? 3 : 4;
148 #if !defined(TARGET_PPC64)
149 sprintf(p, "r%dH", i);
150 cpu_gprh[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
151 offsetof(CPUState, gprh[i]), p);
152 p += (i < 10) ? 4 : 5;
155 sprintf(p, "fp%d", i);
156 cpu_fpr[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
157 offsetof(CPUState, fpr[i]), p);
158 p += (i < 10) ? 4 : 5;
160 sprintf(p, "avr%dH", i);
161 cpu_avrh[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
162 offsetof(CPUState, avr[i].u64[0]), p);
163 p += (i < 10) ? 6 : 7;
165 sprintf(p, "avr%dL", i);
166 cpu_avrl[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
167 offsetof(CPUState, avr[i].u64[1]), p);
168 p += (i < 10) ? 6 : 7;
171 cpu_nip = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
172 offsetof(CPUState, nip), "nip");
174 cpu_ctr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
175 offsetof(CPUState, ctr), "ctr");
177 cpu_lr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
178 offsetof(CPUState, lr), "lr");
180 cpu_xer = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
181 offsetof(CPUState, xer), "xer");
183 cpu_fpscr = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
184 offsetof(CPUState, fpscr), "fpscr");
186 /* register helpers */
188 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
194 #if defined(OPTIMIZE_FPRF_UPDATE)
195 static uint16_t *gen_fprf_buf[OPC_BUF_SIZE];
196 static uint16_t **gen_fprf_ptr;
199 /* internal defines */
200 typedef struct DisasContext {
201 struct TranslationBlock *tb;
205 /* Routine used to access memory */
207 /* Translation flags */
208 #if !defined(CONFIG_USER_ONLY)
211 #if defined(TARGET_PPC64)
217 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
218 int singlestep_enabled;
219 int dcache_line_size;
222 struct opc_handler_t {
225 /* instruction type */
228 void (*handler)(DisasContext *ctx);
229 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
232 #if defined(DO_PPC_STATISTICS)
237 static always_inline void gen_reset_fpstatus (void)
239 #ifdef CONFIG_SOFTFLOAT
240 gen_op_reset_fpstatus();
244 static always_inline void gen_compute_fprf (int set_fprf, int set_rc)
247 /* This case might be optimized later */
248 #if defined(OPTIMIZE_FPRF_UPDATE)
249 *gen_fprf_ptr++ = gen_opc_ptr;
251 gen_op_compute_fprf(1);
252 if (unlikely(set_rc))
253 tcg_gen_andi_i32(cpu_crf[1], cpu_T[0], 0xf);
254 gen_op_float_check_status();
255 } else if (unlikely(set_rc)) {
256 /* We always need to compute fpcc */
257 gen_op_compute_fprf(0);
258 tcg_gen_andi_i32(cpu_crf[1], cpu_T[0], 0xf);
260 gen_op_float_check_status();
264 static always_inline void gen_optimize_fprf (void)
266 #if defined(OPTIMIZE_FPRF_UPDATE)
269 for (ptr = gen_fprf_buf; ptr != (gen_fprf_ptr - 1); ptr++)
270 *ptr = INDEX_op_nop1;
271 gen_fprf_ptr = gen_fprf_buf;
275 static always_inline void gen_update_nip (DisasContext *ctx, target_ulong nip)
277 #if defined(TARGET_PPC64)
279 tcg_gen_movi_tl(cpu_nip, nip);
282 tcg_gen_movi_tl(cpu_nip, (uint32_t)nip);
285 #define GEN_EXCP(ctx, excp, error) \
287 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
288 gen_update_nip(ctx, (ctx)->nip); \
290 gen_op_raise_exception_err((excp), (error)); \
291 ctx->exception = (excp); \
294 #define GEN_EXCP_INVAL(ctx) \
295 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
296 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
298 #define GEN_EXCP_PRIVOPC(ctx) \
299 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
300 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
302 #define GEN_EXCP_PRIVREG(ctx) \
303 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
304 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
306 #define GEN_EXCP_NO_FP(ctx) \
307 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
309 #define GEN_EXCP_NO_AP(ctx) \
310 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
312 #define GEN_EXCP_NO_VR(ctx) \
313 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
315 /* Stop translation */
316 static always_inline void GEN_STOP (DisasContext *ctx)
318 gen_update_nip(ctx, ctx->nip);
319 ctx->exception = POWERPC_EXCP_STOP;
322 /* No need to update nip here, as execution flow will change */
323 static always_inline void GEN_SYNC (DisasContext *ctx)
325 ctx->exception = POWERPC_EXCP_SYNC;
328 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
329 static void gen_##name (DisasContext *ctx); \
330 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
331 static void gen_##name (DisasContext *ctx)
333 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
334 static void gen_##name (DisasContext *ctx); \
335 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
336 static void gen_##name (DisasContext *ctx)
338 typedef struct opcode_t {
339 unsigned char opc1, opc2, opc3;
340 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
341 unsigned char pad[5];
343 unsigned char pad[1];
345 opc_handler_t handler;
349 /*****************************************************************************/
350 /*** Instruction decoding ***/
351 #define EXTRACT_HELPER(name, shift, nb) \
352 static always_inline uint32_t name (uint32_t opcode) \
354 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
357 #define EXTRACT_SHELPER(name, shift, nb) \
358 static always_inline int32_t name (uint32_t opcode) \
360 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
364 EXTRACT_HELPER(opc1, 26, 6);
366 EXTRACT_HELPER(opc2, 1, 5);
368 EXTRACT_HELPER(opc3, 6, 5);
369 /* Update Cr0 flags */
370 EXTRACT_HELPER(Rc, 0, 1);
372 EXTRACT_HELPER(rD, 21, 5);
374 EXTRACT_HELPER(rS, 21, 5);
376 EXTRACT_HELPER(rA, 16, 5);
378 EXTRACT_HELPER(rB, 11, 5);
380 EXTRACT_HELPER(rC, 6, 5);
382 EXTRACT_HELPER(crfD, 23, 3);
383 EXTRACT_HELPER(crfS, 18, 3);
384 EXTRACT_HELPER(crbD, 21, 5);
385 EXTRACT_HELPER(crbA, 16, 5);
386 EXTRACT_HELPER(crbB, 11, 5);
388 EXTRACT_HELPER(_SPR, 11, 10);
389 static always_inline uint32_t SPR (uint32_t opcode)
391 uint32_t sprn = _SPR(opcode);
393 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
395 /*** Get constants ***/
396 EXTRACT_HELPER(IMM, 12, 8);
397 /* 16 bits signed immediate value */
398 EXTRACT_SHELPER(SIMM, 0, 16);
399 /* 16 bits unsigned immediate value */
400 EXTRACT_HELPER(UIMM, 0, 16);
402 EXTRACT_HELPER(NB, 11, 5);
404 EXTRACT_HELPER(SH, 11, 5);
406 EXTRACT_HELPER(MB, 6, 5);
408 EXTRACT_HELPER(ME, 1, 5);
410 EXTRACT_HELPER(TO, 21, 5);
412 EXTRACT_HELPER(CRM, 12, 8);
413 EXTRACT_HELPER(FM, 17, 8);
414 EXTRACT_HELPER(SR, 16, 4);
415 EXTRACT_HELPER(FPIMM, 12, 4);
417 /*** Jump target decoding ***/
419 EXTRACT_SHELPER(d, 0, 16);
420 /* Immediate address */
421 static always_inline target_ulong LI (uint32_t opcode)
423 return (opcode >> 0) & 0x03FFFFFC;
426 static always_inline uint32_t BD (uint32_t opcode)
428 return (opcode >> 0) & 0xFFFC;
431 EXTRACT_HELPER(BO, 21, 5);
432 EXTRACT_HELPER(BI, 16, 5);
433 /* Absolute/relative address */
434 EXTRACT_HELPER(AA, 1, 1);
436 EXTRACT_HELPER(LK, 0, 1);
438 /* Create a mask between <start> and <end> bits */
439 static always_inline target_ulong MASK (uint32_t start, uint32_t end)
443 #if defined(TARGET_PPC64)
444 if (likely(start == 0)) {
445 ret = UINT64_MAX << (63 - end);
446 } else if (likely(end == 63)) {
447 ret = UINT64_MAX >> start;
450 if (likely(start == 0)) {
451 ret = UINT32_MAX << (31 - end);
452 } else if (likely(end == 31)) {
453 ret = UINT32_MAX >> start;
457 ret = (((target_ulong)(-1ULL)) >> (start)) ^
458 (((target_ulong)(-1ULL) >> (end)) >> 1);
459 if (unlikely(start > end))
466 /*****************************************************************************/
467 /* PowerPC Instructions types definitions */
469 PPC_NONE = 0x0000000000000000ULL,
470 /* PowerPC base instructions set */
471 PPC_INSNS_BASE = 0x0000000000000001ULL,
472 /* integer operations instructions */
473 #define PPC_INTEGER PPC_INSNS_BASE
474 /* flow control instructions */
475 #define PPC_FLOW PPC_INSNS_BASE
476 /* virtual memory instructions */
477 #define PPC_MEM PPC_INSNS_BASE
478 /* ld/st with reservation instructions */
479 #define PPC_RES PPC_INSNS_BASE
480 /* spr/msr access instructions */
481 #define PPC_MISC PPC_INSNS_BASE
482 /* Deprecated instruction sets */
483 /* Original POWER instruction set */
484 PPC_POWER = 0x0000000000000002ULL,
485 /* POWER2 instruction set extension */
486 PPC_POWER2 = 0x0000000000000004ULL,
487 /* Power RTC support */
488 PPC_POWER_RTC = 0x0000000000000008ULL,
489 /* Power-to-PowerPC bridge (601) */
490 PPC_POWER_BR = 0x0000000000000010ULL,
491 /* 64 bits PowerPC instruction set */
492 PPC_64B = 0x0000000000000020ULL,
493 /* New 64 bits extensions (PowerPC 2.0x) */
494 PPC_64BX = 0x0000000000000040ULL,
495 /* 64 bits hypervisor extensions */
496 PPC_64H = 0x0000000000000080ULL,
497 /* New wait instruction (PowerPC 2.0x) */
498 PPC_WAIT = 0x0000000000000100ULL,
499 /* Time base mftb instruction */
500 PPC_MFTB = 0x0000000000000200ULL,
502 /* Fixed-point unit extensions */
503 /* PowerPC 602 specific */
504 PPC_602_SPEC = 0x0000000000000400ULL,
505 /* isel instruction */
506 PPC_ISEL = 0x0000000000000800ULL,
507 /* popcntb instruction */
508 PPC_POPCNTB = 0x0000000000001000ULL,
509 /* string load / store */
510 PPC_STRING = 0x0000000000002000ULL,
512 /* Floating-point unit extensions */
513 /* Optional floating point instructions */
514 PPC_FLOAT = 0x0000000000010000ULL,
515 /* New floating-point extensions (PowerPC 2.0x) */
516 PPC_FLOAT_EXT = 0x0000000000020000ULL,
517 PPC_FLOAT_FSQRT = 0x0000000000040000ULL,
518 PPC_FLOAT_FRES = 0x0000000000080000ULL,
519 PPC_FLOAT_FRSQRTE = 0x0000000000100000ULL,
520 PPC_FLOAT_FRSQRTES = 0x0000000000200000ULL,
521 PPC_FLOAT_FSEL = 0x0000000000400000ULL,
522 PPC_FLOAT_STFIWX = 0x0000000000800000ULL,
524 /* Vector/SIMD extensions */
525 /* Altivec support */
526 PPC_ALTIVEC = 0x0000000001000000ULL,
527 /* PowerPC 2.03 SPE extension */
528 PPC_SPE = 0x0000000002000000ULL,
529 /* PowerPC 2.03 SPE floating-point extension */
530 PPC_SPEFPU = 0x0000000004000000ULL,
532 /* Optional memory control instructions */
533 PPC_MEM_TLBIA = 0x0000000010000000ULL,
534 PPC_MEM_TLBIE = 0x0000000020000000ULL,
535 PPC_MEM_TLBSYNC = 0x0000000040000000ULL,
536 /* sync instruction */
537 PPC_MEM_SYNC = 0x0000000080000000ULL,
538 /* eieio instruction */
539 PPC_MEM_EIEIO = 0x0000000100000000ULL,
541 /* Cache control instructions */
542 PPC_CACHE = 0x0000000200000000ULL,
543 /* icbi instruction */
544 PPC_CACHE_ICBI = 0x0000000400000000ULL,
545 /* dcbz instruction with fixed cache line size */
546 PPC_CACHE_DCBZ = 0x0000000800000000ULL,
547 /* dcbz instruction with tunable cache line size */
548 PPC_CACHE_DCBZT = 0x0000001000000000ULL,
549 /* dcba instruction */
550 PPC_CACHE_DCBA = 0x0000002000000000ULL,
551 /* Freescale cache locking instructions */
552 PPC_CACHE_LOCK = 0x0000004000000000ULL,
554 /* MMU related extensions */
555 /* external control instructions */
556 PPC_EXTERN = 0x0000010000000000ULL,
557 /* segment register access instructions */
558 PPC_SEGMENT = 0x0000020000000000ULL,
559 /* PowerPC 6xx TLB management instructions */
560 PPC_6xx_TLB = 0x0000040000000000ULL,
561 /* PowerPC 74xx TLB management instructions */
562 PPC_74xx_TLB = 0x0000080000000000ULL,
563 /* PowerPC 40x TLB management instructions */
564 PPC_40x_TLB = 0x0000100000000000ULL,
565 /* segment register access instructions for PowerPC 64 "bridge" */
566 PPC_SEGMENT_64B = 0x0000200000000000ULL,
568 PPC_SLBI = 0x0000400000000000ULL,
570 /* Embedded PowerPC dedicated instructions */
571 PPC_WRTEE = 0x0001000000000000ULL,
572 /* PowerPC 40x exception model */
573 PPC_40x_EXCP = 0x0002000000000000ULL,
574 /* PowerPC 405 Mac instructions */
575 PPC_405_MAC = 0x0004000000000000ULL,
576 /* PowerPC 440 specific instructions */
577 PPC_440_SPEC = 0x0008000000000000ULL,
578 /* BookE (embedded) PowerPC specification */
579 PPC_BOOKE = 0x0010000000000000ULL,
580 /* mfapidi instruction */
581 PPC_MFAPIDI = 0x0020000000000000ULL,
582 /* tlbiva instruction */
583 PPC_TLBIVA = 0x0040000000000000ULL,
584 /* tlbivax instruction */
585 PPC_TLBIVAX = 0x0080000000000000ULL,
586 /* PowerPC 4xx dedicated instructions */
587 PPC_4xx_COMMON = 0x0100000000000000ULL,
588 /* PowerPC 40x ibct instructions */
589 PPC_40x_ICBT = 0x0200000000000000ULL,
590 /* rfmci is not implemented in all BookE PowerPC */
591 PPC_RFMCI = 0x0400000000000000ULL,
592 /* rfdi instruction */
593 PPC_RFDI = 0x0800000000000000ULL,
595 PPC_DCR = 0x1000000000000000ULL,
596 /* DCR extended accesse */
597 PPC_DCRX = 0x2000000000000000ULL,
598 /* user-mode DCR access, implemented in PowerPC 460 */
599 PPC_DCRUX = 0x4000000000000000ULL,
602 /*****************************************************************************/
603 /* PowerPC instructions table */
604 #if HOST_LONG_BITS == 64
609 #if defined(__APPLE__)
610 #define OPCODES_SECTION \
611 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
613 #define OPCODES_SECTION \
614 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
617 #if defined(DO_PPC_STATISTICS)
618 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
619 OPCODES_SECTION opcode_t opc_##name = { \
627 .handler = &gen_##name, \
628 .oname = stringify(name), \
630 .oname = stringify(name), \
632 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
633 OPCODES_SECTION opcode_t opc_##name = { \
641 .handler = &gen_##name, \
647 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
648 OPCODES_SECTION opcode_t opc_##name = { \
656 .handler = &gen_##name, \
658 .oname = stringify(name), \
660 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
661 OPCODES_SECTION opcode_t opc_##name = { \
669 .handler = &gen_##name, \
675 #define GEN_OPCODE_MARK(name) \
676 OPCODES_SECTION opcode_t opc_##name = { \
682 .inval = 0x00000000, \
686 .oname = stringify(name), \
689 /* Start opcode list */
690 GEN_OPCODE_MARK(start);
692 /* Invalid instruction */
693 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE)
698 static opc_handler_t invalid_handler = {
701 .handler = gen_invalid,
704 /*** Integer comparison ***/
706 static always_inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
710 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_xer);
711 tcg_gen_shri_i32(cpu_crf[crf], cpu_crf[crf], XER_SO);
712 tcg_gen_andi_i32(cpu_crf[crf], cpu_crf[crf], 1);
714 l1 = gen_new_label();
715 l2 = gen_new_label();
716 l3 = gen_new_label();
718 tcg_gen_brcond_tl(TCG_COND_LT, arg0, arg1, l1);
719 tcg_gen_brcond_tl(TCG_COND_GT, arg0, arg1, l2);
721 tcg_gen_brcond_tl(TCG_COND_LTU, arg0, arg1, l1);
722 tcg_gen_brcond_tl(TCG_COND_GTU, arg0, arg1, l2);
724 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_EQ);
727 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_LT);
730 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_GT);
734 static always_inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
736 TCGv t0 = tcg_const_local_tl(arg1);
737 gen_op_cmp(arg0, t0, s, crf);
741 #if defined(TARGET_PPC64)
742 static always_inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
745 t0 = tcg_temp_local_new(TCG_TYPE_TL);
746 t1 = tcg_temp_local_new(TCG_TYPE_TL);
748 tcg_gen_ext32s_tl(t0, arg0);
749 tcg_gen_ext32s_tl(t1, arg1);
751 tcg_gen_ext32u_tl(t0, arg0);
752 tcg_gen_ext32u_tl(t1, arg1);
754 gen_op_cmp(t0, t1, s, crf);
759 static always_inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
761 TCGv t0 = tcg_const_local_tl(arg1);
762 gen_op_cmp32(arg0, t0, s, crf);
767 static always_inline void gen_set_Rc0 (DisasContext *ctx, TCGv reg)
769 #if defined(TARGET_PPC64)
771 gen_op_cmpi32(reg, 0, 1, 0);
774 gen_op_cmpi(reg, 0, 1, 0);
778 GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER)
780 #if defined(TARGET_PPC64)
781 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
782 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
783 1, crfD(ctx->opcode));
786 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
787 1, crfD(ctx->opcode));
791 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
793 #if defined(TARGET_PPC64)
794 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
795 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
796 1, crfD(ctx->opcode));
799 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
800 1, crfD(ctx->opcode));
804 GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER)
806 #if defined(TARGET_PPC64)
807 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
808 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
809 0, crfD(ctx->opcode));
812 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
813 0, crfD(ctx->opcode));
817 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
819 #if defined(TARGET_PPC64)
820 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
821 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
822 0, crfD(ctx->opcode));
825 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
826 0, crfD(ctx->opcode));
829 /* isel (PowerPC 2.03 specification) */
830 GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL)
833 uint32_t bi = rC(ctx->opcode);
837 l1 = gen_new_label();
838 l2 = gen_new_label();
840 mask = 1 << (3 - (bi & 0x03));
841 t0 = tcg_temp_new(TCG_TYPE_I32);
842 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
843 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
844 if (rA(ctx->opcode) == 0)
845 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
847 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
850 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
854 /*** Integer arithmetic ***/
856 static always_inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, TCGv arg1, TCGv arg2, int sub)
861 l1 = gen_new_label();
862 /* Start with XER OV disabled, the most likely case */
863 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
864 t0 = tcg_temp_local_new(TCG_TYPE_TL);
865 tcg_gen_xor_tl(t0, arg0, arg1);
866 #if defined(TARGET_PPC64)
868 tcg_gen_ext32s_tl(t0, t0);
871 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
873 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
874 tcg_gen_xor_tl(t0, arg1, arg2);
875 #if defined(TARGET_PPC64)
877 tcg_gen_ext32s_tl(t0, t0);
880 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
882 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
883 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
888 static always_inline void gen_op_arith_compute_ca(DisasContext *ctx, TCGv arg1, TCGv arg2, int sub)
890 int l1 = gen_new_label();
892 #if defined(TARGET_PPC64)
893 if (!(ctx->sf_mode)) {
895 t0 = tcg_temp_new(TCG_TYPE_TL);
896 t1 = tcg_temp_new(TCG_TYPE_TL);
898 tcg_gen_ext32u_tl(t0, arg1);
899 tcg_gen_ext32u_tl(t1, arg2);
901 tcg_gen_brcond_tl(TCG_COND_GTU, t0, t1, l1);
903 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
908 tcg_gen_brcond_tl(TCG_COND_GTU, arg1, arg2, l1);
910 tcg_gen_brcond_tl(TCG_COND_GEU, arg1, arg2, l1);
912 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
916 /* Common add function */
917 static always_inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
918 int add_ca, int compute_ca, int compute_ov)
922 if ((!compute_ca && !compute_ov) ||
923 (GET_TCGV(ret) != GET_TCGV(arg1) && GET_TCGV(ret) != GET_TCGV(arg2))) {
926 t0 = tcg_temp_local_new(TCG_TYPE_TL);
930 t1 = tcg_temp_local_new(TCG_TYPE_TL);
931 tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
932 tcg_gen_shri_tl(t1, t1, XER_CA);
935 if (compute_ca && compute_ov) {
936 /* Start with XER CA and OV disabled, the most likely case */
937 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
938 } else if (compute_ca) {
939 /* Start with XER CA disabled, the most likely case */
940 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
941 } else if (compute_ov) {
942 /* Start with XER OV disabled, the most likely case */
943 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
946 tcg_gen_add_tl(t0, arg1, arg2);
949 gen_op_arith_compute_ca(ctx, t0, arg1, 0);
952 tcg_gen_add_tl(t0, t0, t1);
953 gen_op_arith_compute_ca(ctx, t0, t1, 0);
957 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
960 if (unlikely(Rc(ctx->opcode) != 0))
961 gen_set_Rc0(ctx, t0);
963 if (GET_TCGV(t0) != GET_TCGV(ret)) {
964 tcg_gen_mov_tl(ret, t0);
968 /* Add functions with two operands */
969 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
970 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER) \
972 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
973 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
974 add_ca, compute_ca, compute_ov); \
976 /* Add functions with one operand and one immediate */
977 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
978 add_ca, compute_ca, compute_ov) \
979 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER) \
981 TCGv t0 = tcg_const_local_tl(const_val); \
982 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
983 cpu_gpr[rA(ctx->opcode)], t0, \
984 add_ca, compute_ca, compute_ov); \
988 /* add add. addo addo. */
989 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
990 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
991 /* addc addc. addco addco. */
992 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
993 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
994 /* adde adde. addeo addeo. */
995 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
996 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
997 /* addme addme. addmeo addmeo. */
998 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
999 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
1000 /* addze addze. addzeo addzeo.*/
1001 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
1002 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
1004 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1006 target_long simm = SIMM(ctx->opcode);
1008 if (rA(ctx->opcode) == 0) {
1010 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
1012 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm);
1016 static always_inline void gen_op_addic (DisasContext *ctx, TCGv ret, TCGv arg1,
1019 target_long simm = SIMM(ctx->opcode);
1021 /* Start with XER CA and OV disabled, the most likely case */
1022 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1024 if (likely(simm != 0)) {
1025 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1026 tcg_gen_addi_tl(t0, arg1, simm);
1027 gen_op_arith_compute_ca(ctx, t0, arg1, 0);
1028 tcg_gen_mov_tl(ret, t0);
1031 tcg_gen_mov_tl(ret, arg1);
1034 gen_set_Rc0(ctx, ret);
1037 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1039 gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
1041 GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1043 gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
1046 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1048 target_long simm = SIMM(ctx->opcode);
1050 if (rA(ctx->opcode) == 0) {
1052 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
1054 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm << 16);
1058 static always_inline void gen_op_arith_divw (DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1059 int sign, int compute_ov)
1064 #if defined(TARGET_PPC64)
1065 t0 = tcg_temp_local_new(TCG_TYPE_I32);
1067 t2 = tcg_temp_local_new(TCG_TYPE_I32);
1068 tcg_gen_trunc_i64_i32(t1, arg1);
1069 tcg_gen_trunc_i64_i32(t2, arg2);
1075 l1 = gen_new_label();
1076 l2 = gen_new_label();
1077 tcg_gen_brcondi_i32(TCG_COND_EQ, t2, 0, l1);
1079 l3 = gen_new_label();
1080 tcg_gen_brcondi_i32(TCG_COND_NE, t2, -1, l3);
1081 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, INT32_MIN, l1);
1085 tcg_gen_div_i32(t0, t1, t2);
1087 tcg_gen_divu_i32(t0, t1, t2);
1090 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1095 tcg_gen_sari_i32(t0, t1, 31);
1097 tcg_gen_movi_i32(t0, 0);
1100 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1103 #if defined(TARGET_PPC64)
1104 tcg_gen_extu_i32_i64(ret, t0);
1107 if (unlikely(Rc(ctx->opcode) != 0))
1108 gen_set_Rc0(ctx, ret);
1111 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1112 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) \
1114 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1115 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1116 sign, compute_ov); \
1118 /* divwu divwu. divwuo divwuo. */
1119 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
1120 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
1121 /* divw divw. divwo divwo. */
1122 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1123 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
1124 #if defined(TARGET_PPC64)
1125 static always_inline void gen_op_divd (DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1126 int sign, int compute_ov)
1130 l1 = gen_new_label();
1131 l2 = gen_new_label();
1133 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1135 l3 = gen_new_label();
1136 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1137 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1141 tcg_gen_div_i64(ret, arg1, arg2);
1143 tcg_gen_divu_i64(ret, arg1, arg2);
1146 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1151 tcg_gen_sari_i64(ret, arg1, 63);
1153 tcg_gen_movi_i64(ret, 0);
1156 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1159 if (unlikely(Rc(ctx->opcode) != 0))
1160 gen_set_Rc0(ctx, ret);
1162 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1163 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1165 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1166 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1167 sign, compute_ov); \
1169 /* divwu divwu. divwuo divwuo. */
1170 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1171 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1172 /* divw divw. divwo divwo. */
1173 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1174 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1178 GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER)
1182 t0 = tcg_temp_new(TCG_TYPE_I64);
1183 t1 = tcg_temp_new(TCG_TYPE_I64);
1184 #if defined(TARGET_PPC64)
1185 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1186 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1187 tcg_gen_mul_i64(t0, t0, t1);
1188 tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1190 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1191 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1192 tcg_gen_mul_i64(t0, t0, t1);
1193 tcg_gen_shri_i64(t0, t0, 32);
1194 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1198 if (unlikely(Rc(ctx->opcode) != 0))
1199 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1201 /* mulhwu mulhwu. */
1202 GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER)
1206 t0 = tcg_temp_new(TCG_TYPE_I64);
1207 t1 = tcg_temp_new(TCG_TYPE_I64);
1208 #if defined(TARGET_PPC64)
1209 tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1210 tcg_gen_ext32u_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1211 tcg_gen_mul_i64(t0, t0, t1);
1212 tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1214 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1215 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1216 tcg_gen_mul_i64(t0, t0, t1);
1217 tcg_gen_shri_i64(t0, t0, 32);
1218 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1222 if (unlikely(Rc(ctx->opcode) != 0))
1223 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1226 GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER)
1228 #if defined(TARGET_PPC64)
1230 t0 = tcg_temp_new(TCG_TYPE_TL);
1231 t1 = tcg_temp_new(TCG_TYPE_TL);
1232 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1233 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1234 tcg_gen_mul_tl(t0, t0, t1);
1236 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], t0);
1239 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1240 cpu_gpr[rB(ctx->opcode)]);
1242 if (unlikely(Rc(ctx->opcode) != 0))
1243 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1245 /* mullwo mullwo. */
1246 GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER)
1251 t0 = tcg_temp_local_new(TCG_TYPE_I64);
1252 t1 = tcg_temp_local_new(TCG_TYPE_I64);
1253 l1 = gen_new_label();
1254 /* Start with XER OV disabled, the most likely case */
1255 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1256 #if defined(TARGET_PPC64)
1257 tcg_gen_ext32s_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1258 tcg_gen_ext32s_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1260 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1261 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1263 tcg_gen_mul_i64(t0, t0, t1);
1264 #if defined(TARGET_PPC64)
1265 tcg_gen_ext32s_i64(cpu_gpr[rD(ctx->opcode)], t0);
1266 tcg_gen_brcond_i64(TCG_COND_EQ, t0, cpu_gpr[rD(ctx->opcode)], l1);
1268 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1269 tcg_gen_ext32s_i64(t1, t0);
1270 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
1272 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1274 if (unlikely(Rc(ctx->opcode) != 0))
1275 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1278 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1280 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1283 #if defined(TARGET_PPC64)
1284 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1285 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1287 tcg_gen_helper_1_2(helper_##name, cpu_gpr[rD(ctx->opcode)], \
1288 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1289 if (unlikely(Rc(ctx->opcode) != 0)) \
1290 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1293 GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00);
1294 /* mulhdu mulhdu. */
1295 GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02);
1297 GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B)
1299 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1300 cpu_gpr[rB(ctx->opcode)]);
1301 if (unlikely(Rc(ctx->opcode) != 0))
1302 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1304 /* mulldo mulldo. */
1305 GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17);
1308 /* neg neg. nego nego. */
1309 static always_inline void gen_op_neg (DisasContext *ctx, TCGv ret, TCGv arg1, int ov_check)
1313 l1 = gen_new_label();
1314 l2 = gen_new_label();
1315 #if defined(TARGET_PPC64)
1317 tcg_gen_brcondi_tl(TCG_COND_EQ, arg1, INT64_MIN, l1);
1319 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1320 tcg_gen_ext32s_tl(t0, arg1);
1321 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT32_MIN, l1);
1324 tcg_gen_brcondi_tl(TCG_COND_EQ, arg1, INT32_MIN, l1);
1326 tcg_gen_neg_tl(ret, arg1);
1328 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1332 tcg_gen_mov_tl(ret, arg1);
1334 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1337 if (unlikely(Rc(ctx->opcode) != 0))
1338 gen_set_Rc0(ctx, ret);
1340 GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER)
1342 gen_op_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
1344 GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER)
1346 gen_op_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
1349 /* Common subf function */
1350 static always_inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1351 int add_ca, int compute_ca, int compute_ov)
1355 if ((!compute_ca && !compute_ov) ||
1356 (GET_TCGV(ret) != GET_TCGV(arg1) && GET_TCGV(ret) != GET_TCGV(arg2))) {
1359 t0 = tcg_temp_local_new(TCG_TYPE_TL);
1363 t1 = tcg_temp_local_new(TCG_TYPE_TL);
1364 tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
1365 tcg_gen_shri_tl(t1, t1, XER_CA);
1368 if (compute_ca && compute_ov) {
1369 /* Start with XER CA and OV disabled, the most likely case */
1370 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
1371 } else if (compute_ca) {
1372 /* Start with XER CA disabled, the most likely case */
1373 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1374 } else if (compute_ov) {
1375 /* Start with XER OV disabled, the most likely case */
1376 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1380 tcg_gen_not_tl(t0, arg1);
1381 tcg_gen_add_tl(t0, t0, arg2);
1382 gen_op_arith_compute_ca(ctx, t0, arg2, 0);
1383 tcg_gen_add_tl(t0, t0, t1);
1384 gen_op_arith_compute_ca(ctx, t0, t1, 0);
1387 tcg_gen_sub_tl(t0, arg2, arg1);
1389 gen_op_arith_compute_ca(ctx, t0, arg2, 1);
1393 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1396 if (unlikely(Rc(ctx->opcode) != 0))
1397 gen_set_Rc0(ctx, t0);
1399 if (GET_TCGV(t0) != GET_TCGV(ret)) {
1400 tcg_gen_mov_tl(ret, t0);
1404 /* Sub functions with Two operands functions */
1405 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1406 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER) \
1408 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1409 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1410 add_ca, compute_ca, compute_ov); \
1412 /* Sub functions with one operand and one immediate */
1413 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1414 add_ca, compute_ca, compute_ov) \
1415 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER) \
1417 TCGv t0 = tcg_const_local_tl(const_val); \
1418 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1419 cpu_gpr[rA(ctx->opcode)], t0, \
1420 add_ca, compute_ca, compute_ov); \
1421 tcg_temp_free(t0); \
1423 /* subf subf. subfo subfo. */
1424 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1425 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1426 /* subfc subfc. subfco subfco. */
1427 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1428 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1429 /* subfe subfe. subfeo subfo. */
1430 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1431 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1432 /* subfme subfme. subfmeo subfmeo. */
1433 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1434 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1435 /* subfze subfze. subfzeo subfzeo.*/
1436 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1437 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
1439 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1441 /* Start with XER CA and OV disabled, the most likely case */
1442 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1443 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1444 TCGv t1 = tcg_const_local_tl(SIMM(ctx->opcode));
1445 tcg_gen_sub_tl(t0, t1, cpu_gpr[rA(ctx->opcode)]);
1446 gen_op_arith_compute_ca(ctx, t0, t1, 1);
1448 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
1452 /*** Integer logical ***/
1453 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1454 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) \
1456 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1457 cpu_gpr[rB(ctx->opcode)]); \
1458 if (unlikely(Rc(ctx->opcode) != 0)) \
1459 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1462 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1463 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1465 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1466 if (unlikely(Rc(ctx->opcode) != 0)) \
1467 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1471 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
1473 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
1475 GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1477 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1478 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1481 GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1483 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1484 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1487 GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER)
1489 tcg_gen_helper_1_1(helper_cntlzw, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1490 if (unlikely(Rc(ctx->opcode) != 0))
1491 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1494 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
1495 /* extsb & extsb. */
1496 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
1497 /* extsh & extsh. */
1498 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
1500 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
1502 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
1504 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
1508 rs = rS(ctx->opcode);
1509 ra = rA(ctx->opcode);
1510 rb = rB(ctx->opcode);
1511 /* Optimisation for mr. ri case */
1512 if (rs != ra || rs != rb) {
1514 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1516 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
1517 if (unlikely(Rc(ctx->opcode) != 0))
1518 gen_set_Rc0(ctx, cpu_gpr[ra]);
1519 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1520 gen_set_Rc0(ctx, cpu_gpr[rs]);
1521 #if defined(TARGET_PPC64)
1527 /* Set process priority to low */
1531 /* Set process priority to medium-low */
1535 /* Set process priority to normal */
1538 #if !defined(CONFIG_USER_ONLY)
1540 if (ctx->supervisor > 0) {
1541 /* Set process priority to very low */
1546 if (ctx->supervisor > 0) {
1547 /* Set process priority to medium-hight */
1552 if (ctx->supervisor > 0) {
1553 /* Set process priority to high */
1558 if (ctx->supervisor > 1) {
1559 /* Set process priority to very high */
1569 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1570 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, spr[SPR_PPR]));
1571 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1572 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
1573 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, spr[SPR_PPR]));
1580 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
1582 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER)
1584 /* Optimisation for "set to zero" case */
1585 if (rS(ctx->opcode) != rB(ctx->opcode))
1586 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1588 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1589 if (unlikely(Rc(ctx->opcode) != 0))
1590 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1593 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1595 target_ulong uimm = UIMM(ctx->opcode);
1597 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1599 /* XXX: should handle special NOPs for POWER series */
1602 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1605 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1607 target_ulong uimm = UIMM(ctx->opcode);
1609 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1613 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1616 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1618 target_ulong uimm = UIMM(ctx->opcode);
1620 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1624 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1627 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1629 target_ulong uimm = UIMM(ctx->opcode);
1631 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1635 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1637 /* popcntb : PowerPC 2.03 specification */
1638 GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB)
1640 #if defined(TARGET_PPC64)
1642 tcg_gen_helper_1_1(helper_popcntb_64, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1645 tcg_gen_helper_1_1(helper_popcntb, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1648 #if defined(TARGET_PPC64)
1649 /* extsw & extsw. */
1650 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
1652 GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B)
1654 tcg_gen_helper_1_1(helper_cntlzd, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1655 if (unlikely(Rc(ctx->opcode) != 0))
1656 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1660 /*** Integer rotate ***/
1661 /* rlwimi & rlwimi. */
1662 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1664 uint32_t mb, me, sh;
1666 mb = MB(ctx->opcode);
1667 me = ME(ctx->opcode);
1668 sh = SH(ctx->opcode);
1669 if (likely(sh == 0 && mb == 0 && me == 31)) {
1670 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1675 t0 = tcg_temp_new(TCG_TYPE_TL);
1676 t1 = tcg_temp_new(TCG_TYPE_TL);
1677 if (likely(sh == 0)) {
1678 tcg_gen_mov_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1680 tcg_gen_ext32u_tl(t1, cpu_gpr[rS(ctx->opcode)]);
1681 tcg_gen_shli_tl(t0, t1, sh);
1682 tcg_gen_shri_tl(t1, t1, 32 - sh);
1683 tcg_gen_or_tl(t0, t0, t1);
1685 #if defined(TARGET_PPC64)
1689 mask = MASK(mb, me);
1690 tcg_gen_andi_tl(t0, t0, mask);
1691 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1692 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1696 if (unlikely(Rc(ctx->opcode) != 0))
1697 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1699 /* rlwinm & rlwinm. */
1700 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1702 uint32_t mb, me, sh;
1704 sh = SH(ctx->opcode);
1705 mb = MB(ctx->opcode);
1706 me = ME(ctx->opcode);
1708 if (likely(mb == 0 && me == (31 - sh))) {
1709 if (likely(sh == 0)) {
1710 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1712 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1713 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1714 tcg_gen_shli_tl(t0, t0, sh);
1715 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1718 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
1719 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1720 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1721 tcg_gen_shri_tl(t0, t0, mb);
1722 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1725 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1726 if (likely(sh != 0)) {
1727 TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
1728 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1729 tcg_gen_shli_tl(t1, t0, sh);
1730 tcg_gen_shri_tl(t0, t0, 32 - sh);
1731 tcg_gen_or_tl(t0, t0, t1);
1734 tcg_gen_mov_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1736 #if defined(TARGET_PPC64)
1740 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1743 if (unlikely(Rc(ctx->opcode) != 0))
1744 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1746 /* rlwnm & rlwnm. */
1747 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1750 TCGv t0, t1, t2, t3;
1752 mb = MB(ctx->opcode);
1753 me = ME(ctx->opcode);
1754 t0 = tcg_temp_new(TCG_TYPE_TL);
1755 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
1756 t1 = tcg_temp_new(TCG_TYPE_TL);
1757 tcg_gen_ext32u_tl(t1, cpu_gpr[rS(ctx->opcode)]);
1758 t2 = tcg_temp_new(TCG_TYPE_TL);
1759 tcg_gen_shl_tl(t2, t1, t0);
1760 t3 = tcg_const_tl(32);
1761 tcg_gen_sub_tl(t0, t3, t0);
1763 tcg_gen_shr_tl(t1, t1, t0);
1765 tcg_gen_or_tl(t2, t2, t1);
1767 if (unlikely(mb != 0 || me != 31)) {
1768 #if defined(TARGET_PPC64)
1772 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t2, MASK(mb, me));
1774 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t2);
1777 if (unlikely(Rc(ctx->opcode) != 0))
1778 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1781 #if defined(TARGET_PPC64)
1782 #define GEN_PPC64_R2(name, opc1, opc2) \
1783 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1785 gen_##name(ctx, 0); \
1787 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1790 gen_##name(ctx, 1); \
1792 #define GEN_PPC64_R4(name, opc1, opc2) \
1793 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1795 gen_##name(ctx, 0, 0); \
1797 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1800 gen_##name(ctx, 0, 1); \
1802 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1805 gen_##name(ctx, 1, 0); \
1807 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1810 gen_##name(ctx, 1, 1); \
1813 static always_inline void gen_rldinm (DisasContext *ctx, uint32_t mb,
1814 uint32_t me, uint32_t sh)
1816 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1817 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1818 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1819 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1821 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1822 if (likely(sh != 0)) {
1823 TCGv t1 = tcg_temp_new(TCG_TYPE_TL);
1824 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1825 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 64 - sh);
1826 tcg_gen_or_tl(t0, t0, t1);
1829 tcg_gen_mov_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1831 if (likely(mb == 0 && me == 63)) {
1832 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1834 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1838 if (unlikely(Rc(ctx->opcode) != 0))
1839 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1841 /* rldicl - rldicl. */
1842 static always_inline void gen_rldicl (DisasContext *ctx, int mbn, int shn)
1846 sh = SH(ctx->opcode) | (shn << 5);
1847 mb = MB(ctx->opcode) | (mbn << 5);
1848 gen_rldinm(ctx, mb, 63, sh);
1850 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1851 /* rldicr - rldicr. */
1852 static always_inline void gen_rldicr (DisasContext *ctx, int men, int shn)
1856 sh = SH(ctx->opcode) | (shn << 5);
1857 me = MB(ctx->opcode) | (men << 5);
1858 gen_rldinm(ctx, 0, me, sh);
1860 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1861 /* rldic - rldic. */
1862 static always_inline void gen_rldic (DisasContext *ctx, int mbn, int shn)
1866 sh = SH(ctx->opcode) | (shn << 5);
1867 mb = MB(ctx->opcode) | (mbn << 5);
1868 gen_rldinm(ctx, mb, 63 - sh, sh);
1870 GEN_PPC64_R4(rldic, 0x1E, 0x04);
1872 static always_inline void gen_rldnm (DisasContext *ctx, uint32_t mb,
1877 mb = MB(ctx->opcode);
1878 me = ME(ctx->opcode);
1879 t0 = tcg_temp_new(TCG_TYPE_TL);
1880 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1881 t1 = tcg_temp_new(TCG_TYPE_TL);
1882 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t0);
1883 t2 = tcg_const_tl(32);
1884 tcg_gen_sub_tl(t0, t2, t0);
1886 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1887 tcg_gen_or_tl(t1, t1, t0);
1889 if (unlikely(mb != 0 || me != 63)) {
1890 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t1, MASK(mb, me));
1892 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
1894 if (unlikely(Rc(ctx->opcode) != 0))
1895 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1898 /* rldcl - rldcl. */
1899 static always_inline void gen_rldcl (DisasContext *ctx, int mbn)
1903 mb = MB(ctx->opcode) | (mbn << 5);
1904 gen_rldnm(ctx, mb, 63);
1906 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1907 /* rldcr - rldcr. */
1908 static always_inline void gen_rldcr (DisasContext *ctx, int men)
1912 me = MB(ctx->opcode) | (men << 5);
1913 gen_rldnm(ctx, 0, me);
1915 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1916 /* rldimi - rldimi. */
1917 static always_inline void gen_rldimi (DisasContext *ctx, int mbn, int shn)
1919 uint32_t sh, mb, me;
1921 sh = SH(ctx->opcode) | (shn << 5);
1922 mb = MB(ctx->opcode) | (mbn << 5);
1924 if (unlikely(sh == 0 && mb == 0)) {
1925 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1930 t0 = tcg_temp_new(TCG_TYPE_TL);
1931 t1 = tcg_temp_new(TCG_TYPE_TL);
1932 if (likely(sh == 0)) {
1933 tcg_gen_mov_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1935 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1936 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 64 - sh);
1937 tcg_gen_or_tl(t0, t0, t1);
1939 mask = MASK(mb, me);
1940 tcg_gen_andi_tl(t0, t0, mask);
1941 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1942 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1946 if (unlikely(Rc(ctx->opcode) != 0))
1947 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1949 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1952 /*** Integer shift ***/
1954 GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER)
1958 l1 = gen_new_label();
1959 l2 = gen_new_label();
1961 t0 = tcg_temp_local_new(TCG_TYPE_TL);
1962 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1963 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x20, l1);
1964 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1967 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
1968 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
1971 if (unlikely(Rc(ctx->opcode) != 0))
1972 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1975 GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER)
1977 tcg_gen_helper_1_2(helper_sraw, cpu_gpr[rA(ctx->opcode)],
1978 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1979 if (unlikely(Rc(ctx->opcode) != 0))
1980 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1982 /* srawi & srawi. */
1983 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
1985 int sh = SH(ctx->opcode);
1989 l1 = gen_new_label();
1990 l2 = gen_new_label();
1991 t0 = tcg_temp_local_new(TCG_TYPE_TL);
1992 tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1993 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
1994 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
1995 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1996 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
1999 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2001 tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
2002 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], t0, sh);
2005 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
2006 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2008 if (unlikely(Rc(ctx->opcode) != 0))
2009 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2012 GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER)
2016 l1 = gen_new_label();
2017 l2 = gen_new_label();
2019 t0 = tcg_temp_local_new(TCG_TYPE_TL);
2020 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
2021 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x20, l1);
2022 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2025 t1 = tcg_temp_new(TCG_TYPE_TL);
2026 tcg_gen_ext32u_tl(t1, cpu_gpr[rS(ctx->opcode)]);
2027 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t1, t0);
2031 if (unlikely(Rc(ctx->opcode) != 0))
2032 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2034 #if defined(TARGET_PPC64)
2036 GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B)
2040 l1 = gen_new_label();
2041 l2 = gen_new_label();
2043 t0 = tcg_temp_local_new(TCG_TYPE_TL);
2044 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x7f);
2045 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x40, l1);
2046 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2049 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
2052 if (unlikely(Rc(ctx->opcode) != 0))
2053 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2056 GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B)
2058 tcg_gen_helper_1_2(helper_srad, cpu_gpr[rA(ctx->opcode)],
2059 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2060 if (unlikely(Rc(ctx->opcode) != 0))
2061 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2063 /* sradi & sradi. */
2064 static always_inline void gen_sradi (DisasContext *ctx, int n)
2066 int sh = SH(ctx->opcode) + (n << 5);
2070 l1 = gen_new_label();
2071 l2 = gen_new_label();
2072 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
2073 t0 = tcg_temp_new(TCG_TYPE_TL);
2074 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
2075 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2076 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
2079 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2081 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
2083 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
2084 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2086 if (unlikely(Rc(ctx->opcode) != 0))
2087 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2089 GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
2093 GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
2098 GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B)
2102 l1 = gen_new_label();
2103 l2 = gen_new_label();
2105 t0 = tcg_temp_local_new(TCG_TYPE_TL);
2106 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x7f);
2107 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x40, l1);
2108 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2111 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
2114 if (unlikely(Rc(ctx->opcode) != 0))
2115 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2119 /*** Floating-Point arithmetic ***/
2120 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2121 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
2123 if (unlikely(!ctx->fpu_enabled)) { \
2124 GEN_EXCP_NO_FP(ctx); \
2127 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2128 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2129 tcg_gen_mov_i64(cpu_FT[2], cpu_fpr[rB(ctx->opcode)]); \
2130 gen_reset_fpstatus(); \
2135 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2136 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2139 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2140 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2141 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2143 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2144 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2146 if (unlikely(!ctx->fpu_enabled)) { \
2147 GEN_EXCP_NO_FP(ctx); \
2150 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2151 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]); \
2152 gen_reset_fpstatus(); \
2157 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2158 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2160 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2161 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2162 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2164 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2165 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2167 if (unlikely(!ctx->fpu_enabled)) { \
2168 GEN_EXCP_NO_FP(ctx); \
2171 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2172 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2173 gen_reset_fpstatus(); \
2178 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2179 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2181 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2182 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2183 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2185 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2186 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
2188 if (unlikely(!ctx->fpu_enabled)) { \
2189 GEN_EXCP_NO_FP(ctx); \
2192 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2193 gen_reset_fpstatus(); \
2195 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2196 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2199 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2200 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
2202 if (unlikely(!ctx->fpu_enabled)) { \
2203 GEN_EXCP_NO_FP(ctx); \
2206 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2207 gen_reset_fpstatus(); \
2209 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2210 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2214 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
2216 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
2218 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
2221 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
2224 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
2227 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2230 static always_inline void gen_op_frsqrtes (void)
2235 GEN_FLOAT_BS(rsqrtes, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES);
2238 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
2240 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
2243 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
2245 if (unlikely(!ctx->fpu_enabled)) {
2246 GEN_EXCP_NO_FP(ctx);
2249 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2250 gen_reset_fpstatus();
2252 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2253 gen_compute_fprf(1, Rc(ctx->opcode) != 0);
2256 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
2258 if (unlikely(!ctx->fpu_enabled)) {
2259 GEN_EXCP_NO_FP(ctx);
2262 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2263 gen_reset_fpstatus();
2266 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2267 gen_compute_fprf(1, Rc(ctx->opcode) != 0);
2270 /*** Floating-Point multiply-and-add ***/
2271 /* fmadd - fmadds */
2272 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
2273 /* fmsub - fmsubs */
2274 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
2275 /* fnmadd - fnmadds */
2276 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
2277 /* fnmsub - fnmsubs */
2278 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
2280 /*** Floating-Point round & convert ***/
2282 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
2284 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
2286 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
2287 #if defined(TARGET_PPC64)
2289 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
2291 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
2293 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
2297 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
2299 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
2301 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
2303 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
2305 /*** Floating-Point compare ***/
2307 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
2309 if (unlikely(!ctx->fpu_enabled)) {
2310 GEN_EXCP_NO_FP(ctx);
2313 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]);
2314 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]);
2315 gen_reset_fpstatus();
2316 tcg_gen_helper_1_0(helper_fcmpo, cpu_crf[crfD(ctx->opcode)]);
2317 gen_op_float_check_status();
2321 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
2323 if (unlikely(!ctx->fpu_enabled)) {
2324 GEN_EXCP_NO_FP(ctx);
2327 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]);
2328 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]);
2329 gen_reset_fpstatus();
2330 tcg_gen_helper_1_0(helper_fcmpu, cpu_crf[crfD(ctx->opcode)]);
2331 gen_op_float_check_status();
2334 /*** Floating-point move ***/
2336 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2337 GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT);
2340 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2341 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
2343 if (unlikely(!ctx->fpu_enabled)) {
2344 GEN_EXCP_NO_FP(ctx);
2347 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2348 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2349 gen_compute_fprf(0, Rc(ctx->opcode) != 0);
2353 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2354 GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT);
2356 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2357 GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT);
2359 /*** Floating-Point status & ctrl register ***/
2361 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
2365 if (unlikely(!ctx->fpu_enabled)) {
2366 GEN_EXCP_NO_FP(ctx);
2369 gen_optimize_fprf();
2370 bfa = 4 * (7 - crfS(ctx->opcode));
2371 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_fpscr, bfa);
2372 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
2373 gen_op_fpscr_resetbit(~(0xF << bfa));
2377 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
2379 if (unlikely(!ctx->fpu_enabled)) {
2380 GEN_EXCP_NO_FP(ctx);
2383 gen_optimize_fprf();
2384 gen_reset_fpstatus();
2385 gen_op_load_fpscr_FT0();
2386 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2387 gen_compute_fprf(0, Rc(ctx->opcode) != 0);
2391 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
2395 if (unlikely(!ctx->fpu_enabled)) {
2396 GEN_EXCP_NO_FP(ctx);
2399 crb = 32 - (crbD(ctx->opcode) >> 2);
2400 gen_optimize_fprf();
2401 gen_reset_fpstatus();
2402 if (likely(crb != 30 && crb != 29))
2403 gen_op_fpscr_resetbit(~(1 << crb));
2404 if (unlikely(Rc(ctx->opcode) != 0)) {
2405 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2410 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
2414 if (unlikely(!ctx->fpu_enabled)) {
2415 GEN_EXCP_NO_FP(ctx);
2418 crb = 32 - (crbD(ctx->opcode) >> 2);
2419 gen_optimize_fprf();
2420 gen_reset_fpstatus();
2421 /* XXX: we pretend we can only do IEEE floating-point computations */
2422 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI))
2423 gen_op_fpscr_setbit(crb);
2424 if (unlikely(Rc(ctx->opcode) != 0)) {
2425 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2427 /* We can raise a differed exception */
2428 gen_op_float_check_status();
2432 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
2434 if (unlikely(!ctx->fpu_enabled)) {
2435 GEN_EXCP_NO_FP(ctx);
2438 gen_optimize_fprf();
2439 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2440 gen_reset_fpstatus();
2441 gen_op_store_fpscr(FM(ctx->opcode));
2442 if (unlikely(Rc(ctx->opcode) != 0)) {
2443 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2445 /* We can raise a differed exception */
2446 gen_op_float_check_status();
2450 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
2454 if (unlikely(!ctx->fpu_enabled)) {
2455 GEN_EXCP_NO_FP(ctx);
2458 bf = crbD(ctx->opcode) >> 2;
2460 gen_optimize_fprf();
2461 tcg_gen_movi_i64(cpu_FT[0], FPIMM(ctx->opcode) << (4 * sh));
2462 gen_reset_fpstatus();
2463 gen_op_store_fpscr(1 << sh);
2464 if (unlikely(Rc(ctx->opcode) != 0)) {
2465 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2467 /* We can raise a differed exception */
2468 gen_op_float_check_status();
2471 /*** Addressing modes ***/
2472 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2473 static always_inline void gen_addr_imm_index (TCGv EA,
2477 target_long simm = SIMM(ctx->opcode);
2480 if (rA(ctx->opcode) == 0)
2481 tcg_gen_movi_tl(EA, simm);
2482 else if (likely(simm != 0))
2483 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2485 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2488 static always_inline void gen_addr_reg_index (TCGv EA,
2491 if (rA(ctx->opcode) == 0)
2492 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2494 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2497 static always_inline void gen_addr_register (TCGv EA,
2500 if (rA(ctx->opcode) == 0)
2501 tcg_gen_movi_tl(EA, 0);
2503 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2506 #if defined(TARGET_PPC64)
2507 #define _GEN_MEM_FUNCS(name, mode) \
2508 &gen_op_##name##_##mode, \
2509 &gen_op_##name##_le_##mode, \
2510 &gen_op_##name##_64_##mode, \
2511 &gen_op_##name##_le_64_##mode
2513 #define _GEN_MEM_FUNCS(name, mode) \
2514 &gen_op_##name##_##mode, \
2515 &gen_op_##name##_le_##mode
2517 #if defined(CONFIG_USER_ONLY)
2518 #if defined(TARGET_PPC64)
2519 #define NB_MEM_FUNCS 4
2521 #define NB_MEM_FUNCS 2
2523 #define GEN_MEM_FUNCS(name) \
2524 _GEN_MEM_FUNCS(name, raw)
2526 #if defined(TARGET_PPC64)
2527 #define NB_MEM_FUNCS 12
2529 #define NB_MEM_FUNCS 6
2531 #define GEN_MEM_FUNCS(name) \
2532 _GEN_MEM_FUNCS(name, user), \
2533 _GEN_MEM_FUNCS(name, kernel), \
2534 _GEN_MEM_FUNCS(name, hypv)
2537 /*** Integer load ***/
2538 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2539 #define OP_LD_TABLE(width) \
2540 static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2541 GEN_MEM_FUNCS(l##width), \
2543 #define OP_ST_TABLE(width) \
2544 static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2545 GEN_MEM_FUNCS(st##width), \
2549 #if defined(TARGET_PPC64)
2550 #define GEN_QEMU_LD_PPC64(width) \
2551 static always_inline void gen_qemu_ld##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2553 if (likely(flags & 2)) \
2554 tcg_gen_qemu_ld##width(t0, t1, flags >> 2); \
2556 TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2557 tcg_gen_ext32u_tl(addr, t1); \
2558 tcg_gen_qemu_ld##width(t0, addr, flags >> 2); \
2559 tcg_temp_free(addr); \
2562 GEN_QEMU_LD_PPC64(8u)
2563 GEN_QEMU_LD_PPC64(8s)
2564 GEN_QEMU_LD_PPC64(16u)
2565 GEN_QEMU_LD_PPC64(16s)
2566 GEN_QEMU_LD_PPC64(32u)
2567 GEN_QEMU_LD_PPC64(32s)
2568 GEN_QEMU_LD_PPC64(64)
2570 #define GEN_QEMU_ST_PPC64(width) \
2571 static always_inline void gen_qemu_st##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2573 if (likely(flags & 2)) \
2574 tcg_gen_qemu_st##width(t0, t1, flags >> 2); \
2576 TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2577 tcg_gen_ext32u_tl(addr, t1); \
2578 tcg_gen_qemu_st##width(t0, addr, flags >> 2); \
2579 tcg_temp_free(addr); \
2582 GEN_QEMU_ST_PPC64(8)
2583 GEN_QEMU_ST_PPC64(16)
2584 GEN_QEMU_ST_PPC64(32)
2585 GEN_QEMU_ST_PPC64(64)
2587 static always_inline void gen_qemu_ld8u(TCGv arg0, TCGv arg1, int flags)
2589 gen_qemu_ld8u_ppc64(arg0, arg1, flags);
2592 static always_inline void gen_qemu_ld8s(TCGv arg0, TCGv arg1, int flags)
2594 gen_qemu_ld8s_ppc64(arg0, arg1, flags);
2597 static always_inline void gen_qemu_ld16u(TCGv arg0, TCGv arg1, int flags)
2599 if (unlikely(flags & 1)) {
2601 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2602 t0 = tcg_temp_new(TCG_TYPE_I32);
2603 tcg_gen_trunc_tl_i32(t0, arg0);
2604 tcg_gen_bswap16_i32(t0, t0);
2605 tcg_gen_extu_i32_tl(arg0, t0);
2608 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2611 static always_inline void gen_qemu_ld16s(TCGv arg0, TCGv arg1, int flags)
2613 if (unlikely(flags & 1)) {
2615 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2616 t0 = tcg_temp_new(TCG_TYPE_I32);
2617 tcg_gen_trunc_tl_i32(t0, arg0);
2618 tcg_gen_bswap16_i32(t0, t0);
2619 tcg_gen_extu_i32_tl(arg0, t0);
2620 tcg_gen_ext16s_tl(arg0, arg0);
2623 gen_qemu_ld16s_ppc64(arg0, arg1, flags);
2626 static always_inline void gen_qemu_ld32u(TCGv arg0, TCGv arg1, int flags)
2628 if (unlikely(flags & 1)) {
2630 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2631 t0 = tcg_temp_new(TCG_TYPE_I32);
2632 tcg_gen_trunc_tl_i32(t0, arg0);
2633 tcg_gen_bswap_i32(t0, t0);
2634 tcg_gen_extu_i32_tl(arg0, t0);
2637 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2640 static always_inline void gen_qemu_ld32s(TCGv arg0, TCGv arg1, int flags)
2642 if (unlikely(flags & 1)) {
2644 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2645 t0 = tcg_temp_new(TCG_TYPE_I32);
2646 tcg_gen_trunc_tl_i32(t0, arg0);
2647 tcg_gen_bswap_i32(t0, t0);
2648 tcg_gen_ext_i32_tl(arg0, t0);
2651 gen_qemu_ld32s_ppc64(arg0, arg1, flags);
2654 static always_inline void gen_qemu_ld64(TCGv arg0, TCGv arg1, int flags)
2656 gen_qemu_ld64_ppc64(arg0, arg1, flags);
2657 if (unlikely(flags & 1))
2658 tcg_gen_bswap_i64(arg0, arg0);
2661 static always_inline void gen_qemu_st8(TCGv arg0, TCGv arg1, int flags)
2663 gen_qemu_st8_ppc64(arg0, arg1, flags);
2666 static always_inline void gen_qemu_st16(TCGv arg0, TCGv arg1, int flags)
2668 if (unlikely(flags & 1)) {
2670 t0 = tcg_temp_new(TCG_TYPE_I32);
2671 tcg_gen_trunc_tl_i32(t0, arg0);
2672 tcg_gen_ext16u_i32(t0, t0);
2673 tcg_gen_bswap16_i32(t0, t0);
2674 t1 = tcg_temp_new(TCG_TYPE_I64);
2675 tcg_gen_extu_i32_tl(t1, t0);
2677 gen_qemu_st16_ppc64(t1, arg1, flags);
2680 gen_qemu_st16_ppc64(arg0, arg1, flags);
2683 static always_inline void gen_qemu_st32(TCGv arg0, TCGv arg1, int flags)
2685 if (unlikely(flags & 1)) {
2687 t0 = tcg_temp_new(TCG_TYPE_I32);
2688 tcg_gen_trunc_tl_i32(t0, arg0);
2689 tcg_gen_bswap_i32(t0, t0);
2690 t1 = tcg_temp_new(TCG_TYPE_I64);
2691 tcg_gen_extu_i32_tl(t1, t0);
2693 gen_qemu_st32_ppc64(t1, arg1, flags);
2696 gen_qemu_st32_ppc64(arg0, arg1, flags);
2699 static always_inline void gen_qemu_st64(TCGv arg0, TCGv arg1, int flags)
2701 if (unlikely(flags & 1)) {
2702 TCGv t0 = tcg_temp_new(TCG_TYPE_I64);
2703 tcg_gen_bswap_i64(t0, arg0);
2704 gen_qemu_st64_ppc64(t0, arg1, flags);
2707 gen_qemu_st64_ppc64(arg0, arg1, flags);
2711 #else /* defined(TARGET_PPC64) */
2712 #define GEN_QEMU_LD_PPC32(width) \
2713 static always_inline void gen_qemu_ld##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2715 tcg_gen_qemu_ld##width(arg0, arg1, flags >> 1); \
2717 GEN_QEMU_LD_PPC32(8u)
2718 GEN_QEMU_LD_PPC32(8s)
2719 GEN_QEMU_LD_PPC32(16u)
2720 GEN_QEMU_LD_PPC32(16s)
2721 GEN_QEMU_LD_PPC32(32u)
2722 GEN_QEMU_LD_PPC32(32s)
2723 GEN_QEMU_LD_PPC32(64)
2725 #define GEN_QEMU_ST_PPC32(width) \
2726 static always_inline void gen_qemu_st##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2728 tcg_gen_qemu_st##width(arg0, arg1, flags >> 1); \
2730 GEN_QEMU_ST_PPC32(8)
2731 GEN_QEMU_ST_PPC32(16)
2732 GEN_QEMU_ST_PPC32(32)
2733 GEN_QEMU_ST_PPC32(64)
2735 static always_inline void gen_qemu_ld8u(TCGv arg0, TCGv arg1, int flags)
2737 gen_qemu_ld8u_ppc32(arg0, arg1, flags >> 1);
2740 static always_inline void gen_qemu_ld8s(TCGv arg0, TCGv arg1, int flags)
2742 gen_qemu_ld8s_ppc32(arg0, arg1, flags >> 1);
2745 static always_inline void gen_qemu_ld16u(TCGv arg0, TCGv arg1, int flags)
2747 gen_qemu_ld16u_ppc32(arg0, arg1, flags >> 1);
2748 if (unlikely(flags & 1))
2749 tcg_gen_bswap16_i32(arg0, arg0);
2752 static always_inline void gen_qemu_ld16s(TCGv arg0, TCGv arg1, int flags)
2754 if (unlikely(flags & 1)) {
2755 gen_qemu_ld16u_ppc32(arg0, arg1, flags);
2756 tcg_gen_bswap16_i32(arg0, arg0);
2757 tcg_gen_ext16s_i32(arg0, arg0);
2759 gen_qemu_ld16s_ppc32(arg0, arg1, flags);
2762 static always_inline void gen_qemu_ld32u(TCGv arg0, TCGv arg1, int flags)
2764 gen_qemu_ld32u_ppc32(arg0, arg1, flags);
2765 if (unlikely(flags & 1))
2766 tcg_gen_bswap_i32(arg0, arg0);
2769 static always_inline void gen_qemu_ld64(TCGv arg0, TCGv arg1, int flags)
2771 gen_qemu_ld64_ppc32(arg0, arg1, flags);
2772 if (unlikely(flags & 1))
2773 tcg_gen_bswap_i64(arg0, arg0);
2776 static always_inline void gen_qemu_st8(TCGv arg0, TCGv arg1, int flags)
2778 gen_qemu_st8_ppc32(arg0, arg1, flags >> 1);
2781 static always_inline void gen_qemu_st16(TCGv arg0, TCGv arg1, int flags)
2783 if (unlikely(flags & 1)) {
2784 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2785 tcg_gen_ext16u_i32(temp, arg0);
2786 tcg_gen_bswap16_i32(temp, temp);
2787 gen_qemu_st16_ppc32(temp, arg1, flags >> 1);
2788 tcg_temp_free(temp);
2790 gen_qemu_st16_ppc32(arg0, arg1, flags >> 1);
2793 static always_inline void gen_qemu_st32(TCGv arg0, TCGv arg1, int flags)
2795 if (unlikely(flags & 1)) {
2796 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2797 tcg_gen_bswap_i32(temp, arg0);
2798 gen_qemu_st32_ppc32(temp, arg1, flags >> 1);
2799 tcg_temp_free(temp);
2801 gen_qemu_st32_ppc32(arg0, arg1, flags >> 1);
2804 static always_inline void gen_qemu_st64(TCGv arg0, TCGv arg1, int flags)
2806 if (unlikely(flags & 1)) {
2807 TCGv temp = tcg_temp_new(TCG_TYPE_I64);
2808 tcg_gen_bswap_i64(temp, arg0);
2809 gen_qemu_st64_ppc32(temp, arg1, flags >> 1);
2810 tcg_temp_free(temp);
2812 gen_qemu_st64_ppc32(arg0, arg1, flags >> 1);
2817 #define GEN_LD(width, opc, type) \
2818 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2820 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2821 gen_addr_imm_index(EA, ctx, 0); \
2822 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2823 tcg_temp_free(EA); \
2826 #define GEN_LDU(width, opc, type) \
2827 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2830 if (unlikely(rA(ctx->opcode) == 0 || \
2831 rA(ctx->opcode) == rD(ctx->opcode))) { \
2832 GEN_EXCP_INVAL(ctx); \
2835 EA = tcg_temp_new(TCG_TYPE_TL); \
2836 if (type == PPC_64B) \
2837 gen_addr_imm_index(EA, ctx, 0x03); \
2839 gen_addr_imm_index(EA, ctx, 0); \
2840 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2841 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2842 tcg_temp_free(EA); \
2845 #define GEN_LDUX(width, opc2, opc3, type) \
2846 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2849 if (unlikely(rA(ctx->opcode) == 0 || \
2850 rA(ctx->opcode) == rD(ctx->opcode))) { \
2851 GEN_EXCP_INVAL(ctx); \
2854 EA = tcg_temp_new(TCG_TYPE_TL); \
2855 gen_addr_reg_index(EA, ctx); \
2856 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2857 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2858 tcg_temp_free(EA); \
2861 #define GEN_LDX(width, opc2, opc3, type) \
2862 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2864 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2865 gen_addr_reg_index(EA, ctx); \
2866 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2867 tcg_temp_free(EA); \
2870 #define GEN_LDS(width, op, type) \
2871 GEN_LD(width, op | 0x20, type); \
2872 GEN_LDU(width, op | 0x21, type); \
2873 GEN_LDUX(width, 0x17, op | 0x01, type); \
2874 GEN_LDX(width, 0x17, op | 0x00, type)
2876 /* lbz lbzu lbzux lbzx */
2877 GEN_LDS(8u, 0x02, PPC_INTEGER);
2878 /* lha lhau lhaux lhax */
2879 GEN_LDS(16s, 0x0A, PPC_INTEGER);
2880 /* lhz lhzu lhzux lhzx */
2881 GEN_LDS(16u, 0x08, PPC_INTEGER);
2882 /* lwz lwzu lwzux lwzx */
2883 GEN_LDS(32u, 0x00, PPC_INTEGER);
2884 #if defined(TARGET_PPC64)
2886 GEN_LDUX(32s, 0x15, 0x0B, PPC_64B);
2888 GEN_LDX(32s, 0x15, 0x0A, PPC_64B);
2890 GEN_LDUX(64, 0x15, 0x01, PPC_64B);
2892 GEN_LDX(64, 0x15, 0x00, PPC_64B);
2893 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
2896 if (Rc(ctx->opcode)) {
2897 if (unlikely(rA(ctx->opcode) == 0 ||
2898 rA(ctx->opcode) == rD(ctx->opcode))) {
2899 GEN_EXCP_INVAL(ctx);
2903 EA = tcg_temp_new(TCG_TYPE_TL);
2904 gen_addr_imm_index(EA, ctx, 0x03);
2905 if (ctx->opcode & 0x02) {
2906 /* lwa (lwau is undefined) */
2907 gen_qemu_ld32s(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx);
2910 gen_qemu_ld64(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx);
2912 if (Rc(ctx->opcode))
2913 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2917 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX)
2919 #if defined(CONFIG_USER_ONLY)
2920 GEN_EXCP_PRIVOPC(ctx);
2925 /* Restore CPU state */
2926 if (unlikely(ctx->supervisor == 0)) {
2927 GEN_EXCP_PRIVOPC(ctx);
2930 ra = rA(ctx->opcode);
2931 rd = rD(ctx->opcode);
2932 if (unlikely((rd & 1) || rd == ra)) {
2933 GEN_EXCP_INVAL(ctx);
2936 if (unlikely(ctx->mem_idx & 1)) {
2937 /* Little-endian mode is not handled */
2938 GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2941 EA = tcg_temp_new(TCG_TYPE_TL);
2942 gen_addr_imm_index(EA, ctx, 0x0F);
2943 gen_qemu_ld64(cpu_gpr[rd], EA, ctx->mem_idx);
2944 tcg_gen_addi_tl(EA, EA, 8);
2945 gen_qemu_ld64(cpu_gpr[rd+1], EA, ctx->mem_idx);
2951 /*** Integer store ***/
2952 #define GEN_ST(width, opc, type) \
2953 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2955 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2956 gen_addr_imm_index(EA, ctx, 0); \
2957 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2958 tcg_temp_free(EA); \
2961 #define GEN_STU(width, opc, type) \
2962 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2965 if (unlikely(rA(ctx->opcode) == 0)) { \
2966 GEN_EXCP_INVAL(ctx); \
2969 EA = tcg_temp_new(TCG_TYPE_TL); \
2970 if (type == PPC_64B) \
2971 gen_addr_imm_index(EA, ctx, 0x03); \
2973 gen_addr_imm_index(EA, ctx, 0); \
2974 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2975 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2976 tcg_temp_free(EA); \
2979 #define GEN_STUX(width, opc2, opc3, type) \
2980 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2983 if (unlikely(rA(ctx->opcode) == 0)) { \
2984 GEN_EXCP_INVAL(ctx); \
2987 EA = tcg_temp_new(TCG_TYPE_TL); \
2988 gen_addr_reg_index(EA, ctx); \
2989 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2990 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2991 tcg_temp_free(EA); \
2994 #define GEN_STX(width, opc2, opc3, type) \
2995 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2997 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2998 gen_addr_reg_index(EA, ctx); \
2999 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
3000 tcg_temp_free(EA); \
3003 #define GEN_STS(width, op, type) \
3004 GEN_ST(width, op | 0x20, type); \
3005 GEN_STU(width, op | 0x21, type); \
3006 GEN_STUX(width, 0x17, op | 0x01, type); \
3007 GEN_STX(width, 0x17, op | 0x00, type)
3009 /* stb stbu stbux stbx */
3010 GEN_STS(8, 0x06, PPC_INTEGER);
3011 /* sth sthu sthux sthx */
3012 GEN_STS(16, 0x0C, PPC_INTEGER);
3013 /* stw stwu stwux stwx */
3014 GEN_STS(32, 0x04, PPC_INTEGER);
3015 #if defined(TARGET_PPC64)
3016 GEN_STUX(64, 0x15, 0x05, PPC_64B);
3017 GEN_STX(64, 0x15, 0x04, PPC_64B);
3018 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B)
3023 rs = rS(ctx->opcode);
3024 if ((ctx->opcode & 0x3) == 0x2) {
3025 #if defined(CONFIG_USER_ONLY)
3026 GEN_EXCP_PRIVOPC(ctx);
3029 if (unlikely(ctx->supervisor == 0)) {
3030 GEN_EXCP_PRIVOPC(ctx);
3033 if (unlikely(rs & 1)) {
3034 GEN_EXCP_INVAL(ctx);
3037 if (unlikely(ctx->mem_idx & 1)) {
3038 /* Little-endian mode is not handled */
3039 GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
3042 EA = tcg_temp_new(TCG_TYPE_TL);
3043 gen_addr_imm_index(EA, ctx, 0x03);
3044 gen_qemu_st64(cpu_gpr[rs], EA, ctx->mem_idx);
3045 tcg_gen_addi_tl(EA, EA, 8);
3046 gen_qemu_st64(cpu_gpr[rs+1], EA, ctx->mem_idx);
3051 if (Rc(ctx->opcode)) {
3052 if (unlikely(rA(ctx->opcode) == 0)) {
3053 GEN_EXCP_INVAL(ctx);
3057 EA = tcg_temp_new(TCG_TYPE_TL);
3058 gen_addr_imm_index(EA, ctx, 0x03);
3059 gen_qemu_st64(cpu_gpr[rs], EA, ctx->mem_idx);
3060 if (Rc(ctx->opcode))
3061 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3066 /*** Integer load and store with byte reverse ***/
3068 void always_inline gen_qemu_ld16ur(TCGv t0, TCGv t1, int flags)
3070 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3071 gen_qemu_ld16u(temp, t1, flags);
3072 tcg_gen_bswap16_i32(temp, temp);
3073 tcg_gen_extu_i32_tl(t0, temp);
3074 tcg_temp_free(temp);
3076 GEN_LDX(16ur, 0x16, 0x18, PPC_INTEGER);
3079 void always_inline gen_qemu_ld32ur(TCGv t0, TCGv t1, int flags)
3081 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3082 gen_qemu_ld32u(temp, t1, flags);
3083 tcg_gen_bswap_i32(temp, temp);
3084 tcg_gen_extu_i32_tl(t0, temp);
3085 tcg_temp_free(temp);
3087 GEN_LDX(32ur, 0x16, 0x10, PPC_INTEGER);
3090 void always_inline gen_qemu_st16r(TCGv t0, TCGv t1, int flags)
3092 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3093 tcg_gen_trunc_tl_i32(temp, t0);
3094 tcg_gen_ext16u_i32(temp, temp);
3095 tcg_gen_bswap16_i32(temp, temp);
3096 gen_qemu_st16(temp, t1, flags);
3097 tcg_temp_free(temp);
3099 GEN_STX(16r, 0x16, 0x1C, PPC_INTEGER);
3102 void always_inline gen_qemu_st32r(TCGv t0, TCGv t1, int flags)
3104 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3105 tcg_gen_trunc_tl_i32(temp, t0);
3106 tcg_gen_bswap_i32(temp, temp);
3107 gen_qemu_st32(temp, t1, flags);
3108 tcg_temp_free(temp);
3110 GEN_STX(32r, 0x16, 0x14, PPC_INTEGER);
3112 /*** Integer load and store multiple ***/
3113 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
3114 static GenOpFunc1 *gen_op_lmw[NB_MEM_FUNCS] = {
3117 static GenOpFunc1 *gen_op_stmw[NB_MEM_FUNCS] = {
3118 GEN_MEM_FUNCS(stmw),
3122 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
3124 /* NIP cannot be restored if the memory exception comes from an helper */
3125 gen_update_nip(ctx, ctx->nip - 4);
3126 gen_addr_imm_index(cpu_T[0], ctx, 0);
3127 op_ldstm(lmw, rD(ctx->opcode));
3131 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
3133 /* NIP cannot be restored if the memory exception comes from an helper */
3134 gen_update_nip(ctx, ctx->nip - 4);
3135 gen_addr_imm_index(cpu_T[0], ctx, 0);
3136 op_ldstm(stmw, rS(ctx->opcode));
3139 /*** Integer load and store strings ***/
3140 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
3141 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
3142 /* string load & stores are by definition endian-safe */
3143 #define gen_op_lswi_le_raw gen_op_lswi_raw
3144 #define gen_op_lswi_le_user gen_op_lswi_user
3145 #define gen_op_lswi_le_kernel gen_op_lswi_kernel
3146 #define gen_op_lswi_le_hypv gen_op_lswi_hypv
3147 #define gen_op_lswi_le_64_raw gen_op_lswi_raw
3148 #define gen_op_lswi_le_64_user gen_op_lswi_user
3149 #define gen_op_lswi_le_64_kernel gen_op_lswi_kernel
3150 #define gen_op_lswi_le_64_hypv gen_op_lswi_hypv
3151 static GenOpFunc1 *gen_op_lswi[NB_MEM_FUNCS] = {
3152 GEN_MEM_FUNCS(lswi),
3154 #define gen_op_lswx_le_raw gen_op_lswx_raw
3155 #define gen_op_lswx_le_user gen_op_lswx_user
3156 #define gen_op_lswx_le_kernel gen_op_lswx_kernel
3157 #define gen_op_lswx_le_hypv gen_op_lswx_hypv
3158 #define gen_op_lswx_le_64_raw gen_op_lswx_raw
3159 #define gen_op_lswx_le_64_user gen_op_lswx_user
3160 #define gen_op_lswx_le_64_kernel gen_op_lswx_kernel
3161 #define gen_op_lswx_le_64_hypv gen_op_lswx_hypv
3162 static GenOpFunc3 *gen_op_lswx[NB_MEM_FUNCS] = {
3163 GEN_MEM_FUNCS(lswx),
3165 #define gen_op_stsw_le_raw gen_op_stsw_raw
3166 #define gen_op_stsw_le_user gen_op_stsw_user
3167 #define gen_op_stsw_le_kernel gen_op_stsw_kernel
3168 #define gen_op_stsw_le_hypv gen_op_stsw_hypv
3169 #define gen_op_stsw_le_64_raw gen_op_stsw_raw
3170 #define gen_op_stsw_le_64_user gen_op_stsw_user
3171 #define gen_op_stsw_le_64_kernel gen_op_stsw_kernel
3172 #define gen_op_stsw_le_64_hypv gen_op_stsw_hypv
3173 static GenOpFunc1 *gen_op_stsw[NB_MEM_FUNCS] = {
3174 GEN_MEM_FUNCS(stsw),
3178 /* PowerPC32 specification says we must generate an exception if
3179 * rA is in the range of registers to be loaded.
3180 * In an other hand, IBM says this is valid, but rA won't be loaded.
3181 * For now, I'll follow the spec...
3183 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING)
3185 int nb = NB(ctx->opcode);
3186 int start = rD(ctx->opcode);
3187 int ra = rA(ctx->opcode);
3193 if (unlikely(((start + nr) > 32 &&
3194 start <= ra && (start + nr - 32) > ra) ||
3195 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
3196 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3197 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX);
3200 /* NIP cannot be restored if the memory exception comes from an helper */
3201 gen_update_nip(ctx, ctx->nip - 4);
3202 gen_addr_register(cpu_T[0], ctx);
3203 tcg_gen_movi_tl(cpu_T[1], nb);
3204 op_ldsts(lswi, start);
3208 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING)
3210 int ra = rA(ctx->opcode);
3211 int rb = rB(ctx->opcode);
3213 /* NIP cannot be restored if the memory exception comes from an helper */
3214 gen_update_nip(ctx, ctx->nip - 4);
3215 gen_addr_reg_index(cpu_T[0], ctx);
3219 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
3220 op_ldstsx(lswx, rD(ctx->opcode), ra, rb);
3224 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING)
3226 int nb = NB(ctx->opcode);
3228 /* NIP cannot be restored if the memory exception comes from an helper */
3229 gen_update_nip(ctx, ctx->nip - 4);
3230 gen_addr_register(cpu_T[0], ctx);
3233 tcg_gen_movi_tl(cpu_T[1], nb);
3234 op_ldsts(stsw, rS(ctx->opcode));
3238 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING)
3240 /* NIP cannot be restored if the memory exception comes from an helper */
3241 gen_update_nip(ctx, ctx->nip - 4);
3242 gen_addr_reg_index(cpu_T[0], ctx);
3243 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
3244 op_ldsts(stsw, rS(ctx->opcode));
3247 /*** Memory synchronisation ***/
3249 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO)
3254 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM)
3259 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
3260 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
3261 static GenOpFunc *gen_op_lwarx[NB_MEM_FUNCS] = {
3262 GEN_MEM_FUNCS(lwarx),
3264 static GenOpFunc *gen_op_stwcx[NB_MEM_FUNCS] = {
3265 GEN_MEM_FUNCS(stwcx),
3269 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES)
3271 /* NIP cannot be restored if the memory exception comes from an helper */
3272 gen_update_nip(ctx, ctx->nip - 4);
3273 gen_addr_reg_index(cpu_T[0], ctx);
3275 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]);
3279 GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES)
3281 /* NIP cannot be restored if the memory exception comes from an helper */
3282 gen_update_nip(ctx, ctx->nip - 4);
3283 gen_addr_reg_index(cpu_T[0], ctx);
3284 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
3288 #if defined(TARGET_PPC64)
3289 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
3290 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
3291 static GenOpFunc *gen_op_ldarx[NB_MEM_FUNCS] = {
3292 GEN_MEM_FUNCS(ldarx),
3294 static GenOpFunc *gen_op_stdcx[NB_MEM_FUNCS] = {
3295 GEN_MEM_FUNCS(stdcx),
3299 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B)
3301 /* NIP cannot be restored if the memory exception comes from an helper */
3302 gen_update_nip(ctx, ctx->nip - 4);
3303 gen_addr_reg_index(cpu_T[0], ctx);
3305 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]);
3309 GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B)
3311 /* NIP cannot be restored if the memory exception comes from an helper */
3312 gen_update_nip(ctx, ctx->nip - 4);
3313 gen_addr_reg_index(cpu_T[0], ctx);
3314 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
3317 #endif /* defined(TARGET_PPC64) */
3320 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC)
3325 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT)
3327 /* Stop translation, as the CPU is supposed to sleep from now */
3329 GEN_EXCP(ctx, EXCP_HLT, 1);
3332 /*** Floating-point load ***/
3333 #define GEN_LDF(width, opc, type) \
3334 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3336 if (unlikely(!ctx->fpu_enabled)) { \
3337 GEN_EXCP_NO_FP(ctx); \
3340 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3341 op_ldst(l##width); \
3342 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3345 #define GEN_LDUF(width, opc, type) \
3346 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3348 if (unlikely(!ctx->fpu_enabled)) { \
3349 GEN_EXCP_NO_FP(ctx); \
3352 if (unlikely(rA(ctx->opcode) == 0)) { \
3353 GEN_EXCP_INVAL(ctx); \
3356 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3357 op_ldst(l##width); \
3358 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3359 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3362 #define GEN_LDUXF(width, opc, type) \
3363 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3365 if (unlikely(!ctx->fpu_enabled)) { \
3366 GEN_EXCP_NO_FP(ctx); \
3369 if (unlikely(rA(ctx->opcode) == 0)) { \
3370 GEN_EXCP_INVAL(ctx); \
3373 gen_addr_reg_index(cpu_T[0], ctx); \
3374 op_ldst(l##width); \
3375 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3376 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3379 #define GEN_LDXF(width, opc2, opc3, type) \
3380 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3382 if (unlikely(!ctx->fpu_enabled)) { \
3383 GEN_EXCP_NO_FP(ctx); \
3386 gen_addr_reg_index(cpu_T[0], ctx); \
3387 op_ldst(l##width); \
3388 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3391 #define GEN_LDFS(width, op, type) \
3392 OP_LD_TABLE(width); \
3393 GEN_LDF(width, op | 0x20, type); \
3394 GEN_LDUF(width, op | 0x21, type); \
3395 GEN_LDUXF(width, op | 0x01, type); \
3396 GEN_LDXF(width, 0x17, op | 0x00, type)
3398 /* lfd lfdu lfdux lfdx */
3399 GEN_LDFS(fd, 0x12, PPC_FLOAT);
3400 /* lfs lfsu lfsux lfsx */
3401 GEN_LDFS(fs, 0x10, PPC_FLOAT);
3403 /*** Floating-point store ***/
3404 #define GEN_STF(width, opc, type) \
3405 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3407 if (unlikely(!ctx->fpu_enabled)) { \
3408 GEN_EXCP_NO_FP(ctx); \
3411 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3412 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3413 op_ldst(st##width); \
3416 #define GEN_STUF(width, opc, type) \
3417 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3419 if (unlikely(!ctx->fpu_enabled)) { \
3420 GEN_EXCP_NO_FP(ctx); \
3423 if (unlikely(rA(ctx->opcode) == 0)) { \
3424 GEN_EXCP_INVAL(ctx); \
3427 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3428 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3429 op_ldst(st##width); \
3430 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3433 #define GEN_STUXF(width, opc, type) \
3434 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3436 if (unlikely(!ctx->fpu_enabled)) { \
3437 GEN_EXCP_NO_FP(ctx); \
3440 if (unlikely(rA(ctx->opcode) == 0)) { \
3441 GEN_EXCP_INVAL(ctx); \
3444 gen_addr_reg_index(cpu_T[0], ctx); \
3445 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3446 op_ldst(st##width); \
3447 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3450 #define GEN_STXF(width, opc2, opc3, type) \
3451 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3453 if (unlikely(!ctx->fpu_enabled)) { \
3454 GEN_EXCP_NO_FP(ctx); \
3457 gen_addr_reg_index(cpu_T[0], ctx); \
3458 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3459 op_ldst(st##width); \
3462 #define GEN_STFS(width, op, type) \
3463 OP_ST_TABLE(width); \
3464 GEN_STF(width, op | 0x20, type); \
3465 GEN_STUF(width, op | 0x21, type); \
3466 GEN_STUXF(width, op | 0x01, type); \
3467 GEN_STXF(width, 0x17, op | 0x00, type)
3469 /* stfd stfdu stfdux stfdx */
3470 GEN_STFS(fd, 0x16, PPC_FLOAT);
3471 /* stfs stfsu stfsux stfsx */
3472 GEN_STFS(fs, 0x14, PPC_FLOAT);
3477 GEN_STXF(fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
3480 static always_inline void gen_goto_tb (DisasContext *ctx, int n,
3483 TranslationBlock *tb;
3485 #if defined(TARGET_PPC64)
3487 dest = (uint32_t) dest;
3489 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
3490 likely(!ctx->singlestep_enabled)) {
3492 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3493 tcg_gen_exit_tb((long)tb + n);
3495 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3496 if (unlikely(ctx->singlestep_enabled)) {
3497 if ((ctx->singlestep_enabled &
3498 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
3499 ctx->exception == POWERPC_EXCP_BRANCH) {
3500 target_ulong tmp = ctx->nip;
3502 GEN_EXCP(ctx, POWERPC_EXCP_TRACE, 0);
3505 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
3506 gen_update_nip(ctx, dest);
3514 static always_inline void gen_setlr (DisasContext *ctx, target_ulong nip)
3516 #if defined(TARGET_PPC64)
3517 if (ctx->sf_mode == 0)
3518 tcg_gen_movi_tl(cpu_lr, (uint32_t)nip);
3521 tcg_gen_movi_tl(cpu_lr, nip);
3525 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3527 target_ulong li, target;
3529 ctx->exception = POWERPC_EXCP_BRANCH;
3530 /* sign extend LI */
3531 #if defined(TARGET_PPC64)
3533 li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
3536 li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
3537 if (likely(AA(ctx->opcode) == 0))
3538 target = ctx->nip + li - 4;
3541 if (LK(ctx->opcode))
3542 gen_setlr(ctx, ctx->nip);
3543 gen_goto_tb(ctx, 0, target);
3550 static always_inline void gen_bcond (DisasContext *ctx, int type)
3552 uint32_t bo = BO(ctx->opcode);
3553 int l1 = gen_new_label();
3556 ctx->exception = POWERPC_EXCP_BRANCH;
3557 if (type == BCOND_LR || type == BCOND_CTR) {
3558 target = tcg_temp_local_new(TCG_TYPE_TL);
3559 if (type == BCOND_CTR)
3560 tcg_gen_mov_tl(target, cpu_ctr);
3562 tcg_gen_mov_tl(target, cpu_lr);
3564 if (LK(ctx->opcode))
3565 gen_setlr(ctx, ctx->nip);
3566 l1 = gen_new_label();
3567 if ((bo & 0x4) == 0) {
3568 /* Decrement and test CTR */
3569 TCGv temp = tcg_temp_new(TCG_TYPE_TL);
3570 if (unlikely(type == BCOND_CTR)) {
3571 GEN_EXCP_INVAL(ctx);
3574 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3575 #if defined(TARGET_PPC64)
3577 tcg_gen_ext32u_tl(temp, cpu_ctr);
3580 tcg_gen_mov_tl(temp, cpu_ctr);
3582 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3584 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3587 if ((bo & 0x10) == 0) {
3589 uint32_t bi = BI(ctx->opcode);
3590 uint32_t mask = 1 << (3 - (bi & 0x03));
3591 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3594 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3595 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3597 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3598 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
3601 if (type == BCOND_IM) {
3603 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3604 if (likely(AA(ctx->opcode) == 0)) {
3605 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3607 gen_goto_tb(ctx, 0, li);
3610 gen_goto_tb(ctx, 1, ctx->nip);
3612 #if defined(TARGET_PPC64)
3613 if (!(ctx->sf_mode))
3614 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3617 tcg_gen_andi_tl(cpu_nip, target, ~3);
3620 #if defined(TARGET_PPC64)
3621 if (!(ctx->sf_mode))
3622 tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip);
3625 tcg_gen_movi_tl(cpu_nip, ctx->nip);
3630 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3632 gen_bcond(ctx, BCOND_IM);
3635 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
3637 gen_bcond(ctx, BCOND_CTR);
3640 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
3642 gen_bcond(ctx, BCOND_LR);
3645 /*** Condition register logical ***/
3646 #define GEN_CRLOGIC(name, tcg_op, opc) \
3647 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3652 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3653 t0 = tcg_temp_new(TCG_TYPE_I32); \
3655 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3657 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3659 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3660 t1 = tcg_temp_new(TCG_TYPE_I32); \
3661 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3663 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3665 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3667 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3668 tcg_op(t0, t0, t1); \
3669 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3670 tcg_gen_andi_i32(t0, t0, bitmask); \
3671 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3672 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3673 tcg_temp_free(t0); \
3674 tcg_temp_free(t1); \
3678 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
3680 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
3682 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
3684 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
3686 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
3688 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
3690 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
3692 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
3694 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
3696 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
3699 /*** System linkage ***/
3700 /* rfi (supervisor only) */
3701 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
3703 #if defined(CONFIG_USER_ONLY)
3704 GEN_EXCP_PRIVOPC(ctx);
3706 /* Restore CPU state */
3707 if (unlikely(!ctx->supervisor)) {
3708 GEN_EXCP_PRIVOPC(ctx);
3716 #if defined(TARGET_PPC64)
3717 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B)
3719 #if defined(CONFIG_USER_ONLY)
3720 GEN_EXCP_PRIVOPC(ctx);
3722 /* Restore CPU state */
3723 if (unlikely(!ctx->supervisor)) {
3724 GEN_EXCP_PRIVOPC(ctx);
3732 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H)
3734 #if defined(CONFIG_USER_ONLY)
3735 GEN_EXCP_PRIVOPC(ctx);
3737 /* Restore CPU state */
3738 if (unlikely(ctx->supervisor <= 1)) {
3739 GEN_EXCP_PRIVOPC(ctx);
3749 #if defined(CONFIG_USER_ONLY)
3750 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3752 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3754 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW)
3758 lev = (ctx->opcode >> 5) & 0x7F;
3759 GEN_EXCP(ctx, POWERPC_SYSCALL, lev);
3764 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
3766 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3767 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3768 /* Update the nip since this might generate a trap exception */
3769 gen_update_nip(ctx, ctx->nip);
3770 gen_op_tw(TO(ctx->opcode));
3774 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3776 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3777 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
3778 /* Update the nip since this might generate a trap exception */
3779 gen_update_nip(ctx, ctx->nip);
3780 gen_op_tw(TO(ctx->opcode));
3783 #if defined(TARGET_PPC64)
3785 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B)
3787 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3788 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3789 /* Update the nip since this might generate a trap exception */
3790 gen_update_nip(ctx, ctx->nip);
3791 gen_op_td(TO(ctx->opcode));
3795 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B)
3797 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3798 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
3799 /* Update the nip since this might generate a trap exception */
3800 gen_update_nip(ctx, ctx->nip);
3801 gen_op_td(TO(ctx->opcode));
3805 /*** Processor control ***/
3807 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
3809 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer);
3810 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA);
3811 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA));
3815 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
3819 if (likely(ctx->opcode & 0x00100000)) {
3820 crm = CRM(ctx->opcode);
3821 if (likely((crm ^ (crm - 1)) == 0)) {
3823 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
3826 tcg_gen_helper_1_0(helper_load_cr, cpu_gpr[rD(ctx->opcode)]);
3831 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
3833 #if defined(CONFIG_USER_ONLY)
3834 GEN_EXCP_PRIVREG(ctx);
3836 if (unlikely(!ctx->supervisor)) {
3837 GEN_EXCP_PRIVREG(ctx);
3841 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3846 #define SPR_NOACCESS ((void *)(-1UL))
3848 static void spr_noaccess (void *opaque, int sprn)
3850 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3851 printf("ERROR: try to access SPR %d !\n", sprn);
3853 #define SPR_NOACCESS (&spr_noaccess)
3857 static always_inline void gen_op_mfspr (DisasContext *ctx)
3859 void (*read_cb)(void *opaque, int sprn);
3860 uint32_t sprn = SPR(ctx->opcode);
3862 #if !defined(CONFIG_USER_ONLY)
3863 if (ctx->supervisor == 2)
3864 read_cb = ctx->spr_cb[sprn].hea_read;
3865 else if (ctx->supervisor)
3866 read_cb = ctx->spr_cb[sprn].oea_read;
3869 read_cb = ctx->spr_cb[sprn].uea_read;
3870 if (likely(read_cb != NULL)) {
3871 if (likely(read_cb != SPR_NOACCESS)) {
3872 (*read_cb)(ctx, sprn);
3873 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3875 /* Privilege exception */
3876 /* This is a hack to avoid warnings when running Linux:
3877 * this OS breaks the PowerPC virtualisation model,
3878 * allowing userland application to read the PVR
3880 if (sprn != SPR_PVR) {
3881 if (loglevel != 0) {
3882 fprintf(logfile, "Trying to read privileged spr %d %03x at "
3883 ADDRX "\n", sprn, sprn, ctx->nip);
3885 printf("Trying to read privileged spr %d %03x at " ADDRX "\n",
3886 sprn, sprn, ctx->nip);
3888 GEN_EXCP_PRIVREG(ctx);
3892 if (loglevel != 0) {
3893 fprintf(logfile, "Trying to read invalid spr %d %03x at "
3894 ADDRX "\n", sprn, sprn, ctx->nip);
3896 printf("Trying to read invalid spr %d %03x at " ADDRX "\n",
3897 sprn, sprn, ctx->nip);
3898 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3899 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3903 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC)
3909 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB)
3915 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC)
3919 crm = CRM(ctx->opcode);
3920 if (likely((ctx->opcode & 0x00100000) || (crm ^ (crm - 1)) == 0)) {
3922 tcg_gen_shri_i32(cpu_crf[7 - crn], cpu_gpr[rS(ctx->opcode)], crn * 4);
3923 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
3925 TCGv t0 = tcg_const_tl(crm);
3926 tcg_gen_helper_0_2(helper_store_cr, cpu_gpr[rS(ctx->opcode)], t0);
3932 #if defined(TARGET_PPC64)
3933 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B)
3935 #if defined(CONFIG_USER_ONLY)
3936 GEN_EXCP_PRIVREG(ctx);
3938 if (unlikely(!ctx->supervisor)) {
3939 GEN_EXCP_PRIVREG(ctx);
3942 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3943 if (ctx->opcode & 0x00010000) {
3944 /* Special form that does not need any synchronisation */
3945 gen_op_update_riee();
3947 /* XXX: we need to update nip before the store
3948 * if we enter power saving mode, we will exit the loop
3949 * directly from ppc_store_msr
3951 gen_update_nip(ctx, ctx->nip);
3953 /* Must stop the translation as machine state (may have) changed */
3954 /* Note that mtmsr is not always defined as context-synchronizing */
3955 ctx->exception = POWERPC_EXCP_STOP;
3961 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
3963 #if defined(CONFIG_USER_ONLY)
3964 GEN_EXCP_PRIVREG(ctx);
3966 if (unlikely(!ctx->supervisor)) {
3967 GEN_EXCP_PRIVREG(ctx);
3970 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3971 if (ctx->opcode & 0x00010000) {
3972 /* Special form that does not need any synchronisation */
3973 gen_op_update_riee();
3975 /* XXX: we need to update nip before the store
3976 * if we enter power saving mode, we will exit the loop
3977 * directly from ppc_store_msr
3979 gen_update_nip(ctx, ctx->nip);
3980 #if defined(TARGET_PPC64)
3982 gen_op_store_msr_32();
3986 /* Must stop the translation as machine state (may have) changed */
3987 /* Note that mtmsrd is not always defined as context-synchronizing */
3988 ctx->exception = POWERPC_EXCP_STOP;
3994 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
3996 void (*write_cb)(void *opaque, int sprn);
3997 uint32_t sprn = SPR(ctx->opcode);
3999 #if !defined(CONFIG_USER_ONLY)
4000 if (ctx->supervisor == 2)
4001 write_cb = ctx->spr_cb[sprn].hea_write;
4002 else if (ctx->supervisor)
4003 write_cb = ctx->spr_cb[sprn].oea_write;
4006 write_cb = ctx->spr_cb[sprn].uea_write;
4007 if (likely(write_cb != NULL)) {
4008 if (likely(write_cb != SPR_NOACCESS)) {
4009 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4010 (*write_cb)(ctx, sprn);
4012 /* Privilege exception */
4013 if (loglevel != 0) {
4014 fprintf(logfile, "Trying to write privileged spr %d %03x at "
4015 ADDRX "\n", sprn, sprn, ctx->nip);
4017 printf("Trying to write privileged spr %d %03x at " ADDRX "\n",
4018 sprn, sprn, ctx->nip);
4019 GEN_EXCP_PRIVREG(ctx);
4023 if (loglevel != 0) {
4024 fprintf(logfile, "Trying to write invalid spr %d %03x at "
4025 ADDRX "\n", sprn, sprn, ctx->nip);
4027 printf("Trying to write invalid spr %d %03x at " ADDRX "\n",
4028 sprn, sprn, ctx->nip);
4029 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
4030 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
4034 /*** Cache management ***/
4036 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE)
4038 /* XXX: specification says this is treated as a load by the MMU */
4039 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
4040 gen_addr_reg_index(t0, ctx);
4041 gen_qemu_ld8u(t0, t0, ctx->mem_idx);
4045 /* dcbi (Supervisor only) */
4046 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
4048 #if defined(CONFIG_USER_ONLY)
4049 GEN_EXCP_PRIVOPC(ctx);
4052 if (unlikely(!ctx->supervisor)) {
4053 GEN_EXCP_PRIVOPC(ctx);
4056 EA = tcg_temp_new(TCG_TYPE_TL);
4057 gen_addr_reg_index(EA, ctx);
4058 val = tcg_temp_new(TCG_TYPE_TL);
4059 /* XXX: specification says this should be treated as a store by the MMU */
4060 gen_qemu_ld8u(val, EA, ctx->mem_idx);
4061 gen_qemu_st8(val, EA, ctx->mem_idx);
4068 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE)
4070 /* XXX: specification say this is treated as a load by the MMU */
4071 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
4072 gen_addr_reg_index(t0, ctx);
4073 gen_qemu_ld8u(t0, t0, ctx->mem_idx);
4078 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE)
4080 /* interpreted as no-op */
4081 /* XXX: specification say this is treated as a load by the MMU
4082 * but does not generate any exception
4087 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE)
4089 /* interpreted as no-op */
4090 /* XXX: specification say this is treated as a load by the MMU
4091 * but does not generate any exception
4096 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
4097 static GenOpFunc *gen_op_dcbz[4][NB_MEM_FUNCS] = {
4098 /* 32 bytes cache line size */
4100 #define gen_op_dcbz_l32_le_raw gen_op_dcbz_l32_raw
4101 #define gen_op_dcbz_l32_le_user gen_op_dcbz_l32_user
4102 #define gen_op_dcbz_l32_le_kernel gen_op_dcbz_l32_kernel
4103 #define gen_op_dcbz_l32_le_hypv gen_op_dcbz_l32_hypv
4104 #define gen_op_dcbz_l32_le_64_raw gen_op_dcbz_l32_64_raw
4105 #define gen_op_dcbz_l32_le_64_user gen_op_dcbz_l32_64_user
4106 #define gen_op_dcbz_l32_le_64_kernel gen_op_dcbz_l32_64_kernel
4107 #define gen_op_dcbz_l32_le_64_hypv gen_op_dcbz_l32_64_hypv
4108 GEN_MEM_FUNCS(dcbz_l32),
4110 /* 64 bytes cache line size */
4112 #define gen_op_dcbz_l64_le_raw gen_op_dcbz_l64_raw
4113 #define gen_op_dcbz_l64_le_user gen_op_dcbz_l64_user
4114 #define gen_op_dcbz_l64_le_kernel gen_op_dcbz_l64_kernel
4115 #define gen_op_dcbz_l64_le_hypv gen_op_dcbz_l64_hypv
4116 #define gen_op_dcbz_l64_le_64_raw gen_op_dcbz_l64_64_raw
4117 #define gen_op_dcbz_l64_le_64_user gen_op_dcbz_l64_64_user
4118 #define gen_op_dcbz_l64_le_64_kernel gen_op_dcbz_l64_64_kernel
4119 #define gen_op_dcbz_l64_le_64_hypv gen_op_dcbz_l64_64_hypv
4120 GEN_MEM_FUNCS(dcbz_l64),
4122 /* 128 bytes cache line size */
4124 #define gen_op_dcbz_l128_le_raw gen_op_dcbz_l128_raw
4125 #define gen_op_dcbz_l128_le_user gen_op_dcbz_l128_user
4126 #define gen_op_dcbz_l128_le_kernel gen_op_dcbz_l128_kernel
4127 #define gen_op_dcbz_l128_le_hypv gen_op_dcbz_l128_hypv
4128 #define gen_op_dcbz_l128_le_64_raw gen_op_dcbz_l128_64_raw
4129 #define gen_op_dcbz_l128_le_64_user gen_op_dcbz_l128_64_user
4130 #define gen_op_dcbz_l128_le_64_kernel gen_op_dcbz_l128_64_kernel
4131 #define gen_op_dcbz_l128_le_64_hypv gen_op_dcbz_l128_64_hypv
4132 GEN_MEM_FUNCS(dcbz_l128),
4134 /* tunable cache line size */
4136 #define gen_op_dcbz_le_raw gen_op_dcbz_raw
4137 #define gen_op_dcbz_le_user gen_op_dcbz_user
4138 #define gen_op_dcbz_le_kernel gen_op_dcbz_kernel
4139 #define gen_op_dcbz_le_hypv gen_op_dcbz_hypv
4140 #define gen_op_dcbz_le_64_raw gen_op_dcbz_64_raw
4141 #define gen_op_dcbz_le_64_user gen_op_dcbz_64_user
4142 #define gen_op_dcbz_le_64_kernel gen_op_dcbz_64_kernel
4143 #define gen_op_dcbz_le_64_hypv gen_op_dcbz_64_hypv
4144 GEN_MEM_FUNCS(dcbz),
4148 static always_inline void handler_dcbz (DisasContext *ctx,
4149 int dcache_line_size)
4153 switch (dcache_line_size) {
4170 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ)
4172 gen_addr_reg_index(cpu_T[0], ctx);
4173 handler_dcbz(ctx, ctx->dcache_line_size);
4174 gen_op_check_reservation();
4177 GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT)
4179 gen_addr_reg_index(cpu_T[0], ctx);
4180 if (ctx->opcode & 0x00200000)
4181 handler_dcbz(ctx, ctx->dcache_line_size);
4183 handler_dcbz(ctx, -1);
4184 gen_op_check_reservation();
4188 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
4189 #define gen_op_icbi_le_raw gen_op_icbi_raw
4190 #define gen_op_icbi_le_user gen_op_icbi_user
4191 #define gen_op_icbi_le_kernel gen_op_icbi_kernel
4192 #define gen_op_icbi_le_hypv gen_op_icbi_hypv
4193 #define gen_op_icbi_le_64_raw gen_op_icbi_64_raw
4194 #define gen_op_icbi_le_64_user gen_op_icbi_64_user
4195 #define gen_op_icbi_le_64_kernel gen_op_icbi_64_kernel
4196 #define gen_op_icbi_le_64_hypv gen_op_icbi_64_hypv
4197 static GenOpFunc *gen_op_icbi[NB_MEM_FUNCS] = {
4198 GEN_MEM_FUNCS(icbi),
4201 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI)
4203 /* NIP cannot be restored if the memory exception comes from an helper */
4204 gen_update_nip(ctx, ctx->nip - 4);
4205 gen_addr_reg_index(cpu_T[0], ctx);
4211 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA)
4213 /* interpreted as no-op */
4214 /* XXX: specification say this is treated as a store by the MMU
4215 * but does not generate any exception
4219 /*** Segment register manipulation ***/
4220 /* Supervisor only: */
4222 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
4224 #if defined(CONFIG_USER_ONLY)
4225 GEN_EXCP_PRIVREG(ctx);
4227 if (unlikely(!ctx->supervisor)) {
4228 GEN_EXCP_PRIVREG(ctx);
4231 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4233 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4238 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
4240 #if defined(CONFIG_USER_ONLY)
4241 GEN_EXCP_PRIVREG(ctx);
4243 if (unlikely(!ctx->supervisor)) {
4244 GEN_EXCP_PRIVREG(ctx);
4247 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4250 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4255 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
4257 #if defined(CONFIG_USER_ONLY)
4258 GEN_EXCP_PRIVREG(ctx);
4260 if (unlikely(!ctx->supervisor)) {
4261 GEN_EXCP_PRIVREG(ctx);
4264 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4265 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4271 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
4273 #if defined(CONFIG_USER_ONLY)
4274 GEN_EXCP_PRIVREG(ctx);
4276 if (unlikely(!ctx->supervisor)) {
4277 GEN_EXCP_PRIVREG(ctx);
4280 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4281 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4287 #if defined(TARGET_PPC64)
4288 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4290 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B)
4292 #if defined(CONFIG_USER_ONLY)
4293 GEN_EXCP_PRIVREG(ctx);
4295 if (unlikely(!ctx->supervisor)) {
4296 GEN_EXCP_PRIVREG(ctx);
4299 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4301 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4306 GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4309 #if defined(CONFIG_USER_ONLY)
4310 GEN_EXCP_PRIVREG(ctx);
4312 if (unlikely(!ctx->supervisor)) {
4313 GEN_EXCP_PRIVREG(ctx);
4316 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4319 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4324 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B)
4326 #if defined(CONFIG_USER_ONLY)
4327 GEN_EXCP_PRIVREG(ctx);
4329 if (unlikely(!ctx->supervisor)) {
4330 GEN_EXCP_PRIVREG(ctx);
4333 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4334 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4340 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4343 #if defined(CONFIG_USER_ONLY)
4344 GEN_EXCP_PRIVREG(ctx);
4346 if (unlikely(!ctx->supervisor)) {
4347 GEN_EXCP_PRIVREG(ctx);
4350 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4351 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4356 #endif /* defined(TARGET_PPC64) */
4358 /*** Lookaside buffer management ***/
4359 /* Optional & supervisor only: */
4361 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
4363 #if defined(CONFIG_USER_ONLY)
4364 GEN_EXCP_PRIVOPC(ctx);
4366 if (unlikely(!ctx->supervisor)) {
4367 GEN_EXCP_PRIVOPC(ctx);
4375 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
4377 #if defined(CONFIG_USER_ONLY)
4378 GEN_EXCP_PRIVOPC(ctx);
4380 if (unlikely(!ctx->supervisor)) {
4381 GEN_EXCP_PRIVOPC(ctx);
4384 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4385 #if defined(TARGET_PPC64)
4395 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
4397 #if defined(CONFIG_USER_ONLY)
4398 GEN_EXCP_PRIVOPC(ctx);
4400 if (unlikely(!ctx->supervisor)) {
4401 GEN_EXCP_PRIVOPC(ctx);
4404 /* This has no effect: it should ensure that all previous
4405 * tlbie have completed
4411 #if defined(TARGET_PPC64)
4413 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI)
4415 #if defined(CONFIG_USER_ONLY)
4416 GEN_EXCP_PRIVOPC(ctx);
4418 if (unlikely(!ctx->supervisor)) {
4419 GEN_EXCP_PRIVOPC(ctx);
4427 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI)
4429 #if defined(CONFIG_USER_ONLY)
4430 GEN_EXCP_PRIVOPC(ctx);
4432 if (unlikely(!ctx->supervisor)) {
4433 GEN_EXCP_PRIVOPC(ctx);
4436 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4442 /*** External control ***/
4444 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
4445 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
4446 static GenOpFunc *gen_op_eciwx[NB_MEM_FUNCS] = {
4447 GEN_MEM_FUNCS(eciwx),
4449 static GenOpFunc *gen_op_ecowx[NB_MEM_FUNCS] = {
4450 GEN_MEM_FUNCS(ecowx),
4454 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
4456 /* Should check EAR[E] & alignment ! */
4457 gen_addr_reg_index(cpu_T[0], ctx);
4459 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4463 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN)
4465 /* Should check EAR[E] & alignment ! */
4466 gen_addr_reg_index(cpu_T[0], ctx);
4467 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
4471 /* PowerPC 601 specific instructions */
4473 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR)
4475 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4477 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4478 if (unlikely(Rc(ctx->opcode) != 0))
4479 gen_set_Rc0(ctx, cpu_T[0]);
4483 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR)
4485 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4486 gen_op_POWER_abso();
4487 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4488 if (unlikely(Rc(ctx->opcode) != 0))
4489 gen_set_Rc0(ctx, cpu_T[0]);
4493 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR)
4495 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4496 gen_op_POWER_clcs();
4497 /* Rc=1 sets CR0 to an undefined state */
4498 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4502 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR)
4504 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4505 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4507 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4508 if (unlikely(Rc(ctx->opcode) != 0))
4509 gen_set_Rc0(ctx, cpu_T[0]);
4513 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR)
4515 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4516 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4517 gen_op_POWER_divo();
4518 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4519 if (unlikely(Rc(ctx->opcode) != 0))
4520 gen_set_Rc0(ctx, cpu_T[0]);
4524 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR)
4526 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4527 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4528 gen_op_POWER_divs();
4529 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4530 if (unlikely(Rc(ctx->opcode) != 0))
4531 gen_set_Rc0(ctx, cpu_T[0]);
4534 /* divso - divso. */
4535 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR)
4537 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4538 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4539 gen_op_POWER_divso();
4540 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4541 if (unlikely(Rc(ctx->opcode) != 0))
4542 gen_set_Rc0(ctx, cpu_T[0]);
4546 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR)
4548 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4549 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4551 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4552 if (unlikely(Rc(ctx->opcode) != 0))
4553 gen_set_Rc0(ctx, cpu_T[0]);
4557 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR)
4559 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4560 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4561 gen_op_POWER_dozo();
4562 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4563 if (unlikely(Rc(ctx->opcode) != 0))
4564 gen_set_Rc0(ctx, cpu_T[0]);
4568 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4570 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4571 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
4573 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4576 /* As lscbx load from memory byte after byte, it's always endian safe.
4577 * Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
4579 #define op_POWER_lscbx(start, ra, rb) \
4580 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
4581 #define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
4582 #define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
4583 #define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
4584 #define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
4585 #define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
4586 #define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
4587 #define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
4588 #define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
4589 #define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
4590 #define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
4591 #define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
4592 #define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
4593 static GenOpFunc3 *gen_op_POWER_lscbx[NB_MEM_FUNCS] = {
4594 GEN_MEM_FUNCS(POWER_lscbx),
4597 /* lscbx - lscbx. */
4598 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
4600 int ra = rA(ctx->opcode);
4601 int rb = rB(ctx->opcode);
4603 gen_addr_reg_index(cpu_T[0], ctx);
4607 /* NIP cannot be restored if the memory exception comes from an helper */
4608 gen_update_nip(ctx, ctx->nip - 4);
4609 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
4610 tcg_gen_shri_tl(cpu_T[2], cpu_xer, XER_CMP);
4611 tcg_gen_andi_tl(cpu_T[2], cpu_T[2], 0xFF);
4612 op_POWER_lscbx(rD(ctx->opcode), ra, rb);
4613 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
4614 tcg_gen_or_tl(cpu_xer, cpu_xer, cpu_T[0]);
4615 if (unlikely(Rc(ctx->opcode) != 0))
4616 gen_set_Rc0(ctx, cpu_T[0]);
4619 /* maskg - maskg. */
4620 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR)
4622 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4623 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4624 gen_op_POWER_maskg();
4625 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4626 if (unlikely(Rc(ctx->opcode) != 0))
4627 gen_set_Rc0(ctx, cpu_T[0]);
4630 /* maskir - maskir. */
4631 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR)
4633 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4634 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
4635 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4636 gen_op_POWER_maskir();
4637 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4638 if (unlikely(Rc(ctx->opcode) != 0))
4639 gen_set_Rc0(ctx, cpu_T[0]);
4643 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR)
4645 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4646 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4648 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4649 if (unlikely(Rc(ctx->opcode) != 0))
4650 gen_set_Rc0(ctx, cpu_T[0]);
4654 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR)
4656 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4657 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4658 gen_op_POWER_mulo();
4659 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4660 if (unlikely(Rc(ctx->opcode) != 0))
4661 gen_set_Rc0(ctx, cpu_T[0]);
4665 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR)
4667 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4668 gen_op_POWER_nabs();
4669 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4670 if (unlikely(Rc(ctx->opcode) != 0))
4671 gen_set_Rc0(ctx, cpu_T[0]);
4674 /* nabso - nabso. */
4675 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR)
4677 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4678 gen_op_POWER_nabso();
4679 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4680 if (unlikely(Rc(ctx->opcode) != 0))
4681 gen_set_Rc0(ctx, cpu_T[0]);
4685 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4689 mb = MB(ctx->opcode);
4690 me = ME(ctx->opcode);
4691 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4692 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4693 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4694 gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me));
4695 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4696 if (unlikely(Rc(ctx->opcode) != 0))
4697 gen_set_Rc0(ctx, cpu_T[0]);
4701 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR)
4703 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4704 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4705 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4706 gen_op_POWER_rrib();
4707 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4708 if (unlikely(Rc(ctx->opcode) != 0))
4709 gen_set_Rc0(ctx, cpu_T[0]);
4713 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR)
4715 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4716 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4718 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4719 if (unlikely(Rc(ctx->opcode) != 0))
4720 gen_set_Rc0(ctx, cpu_T[0]);
4724 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR)
4726 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4727 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4728 gen_op_POWER_sleq();
4729 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4730 if (unlikely(Rc(ctx->opcode) != 0))
4731 gen_set_Rc0(ctx, cpu_T[0]);
4735 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR)
4737 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4738 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4740 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4741 if (unlikely(Rc(ctx->opcode) != 0))
4742 gen_set_Rc0(ctx, cpu_T[0]);
4745 /* slliq - slliq. */
4746 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR)
4748 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4749 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4750 gen_op_POWER_sleq();
4751 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4752 if (unlikely(Rc(ctx->opcode) != 0))
4753 gen_set_Rc0(ctx, cpu_T[0]);
4757 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR)
4759 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4760 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4761 gen_op_POWER_sllq();
4762 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4763 if (unlikely(Rc(ctx->opcode) != 0))
4764 gen_set_Rc0(ctx, cpu_T[0]);
4768 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
4770 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4771 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4773 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4774 if (unlikely(Rc(ctx->opcode) != 0))
4775 gen_set_Rc0(ctx, cpu_T[0]);
4778 /* sraiq - sraiq. */
4779 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
4781 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4782 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4783 gen_op_POWER_sraq();
4784 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4785 if (unlikely(Rc(ctx->opcode) != 0))
4786 gen_set_Rc0(ctx, cpu_T[0]);
4790 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR)
4792 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4793 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4794 gen_op_POWER_sraq();
4795 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4796 if (unlikely(Rc(ctx->opcode) != 0))
4797 gen_set_Rc0(ctx, cpu_T[0]);
4801 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR)
4803 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4804 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4806 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4807 if (unlikely(Rc(ctx->opcode) != 0))
4808 gen_set_Rc0(ctx, cpu_T[0]);
4812 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR)
4814 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4815 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4816 gen_op_POWER_srea();
4817 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4818 if (unlikely(Rc(ctx->opcode) != 0))
4819 gen_set_Rc0(ctx, cpu_T[0]);
4823 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR)
4825 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4826 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4827 gen_op_POWER_sreq();
4828 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4829 if (unlikely(Rc(ctx->opcode) != 0))
4830 gen_set_Rc0(ctx, cpu_T[0]);
4834 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR)
4836 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4837 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4839 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4840 if (unlikely(Rc(ctx->opcode) != 0))
4841 gen_set_Rc0(ctx, cpu_T[0]);
4845 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR)
4847 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4848 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4849 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4850 gen_op_POWER_srlq();
4851 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4852 if (unlikely(Rc(ctx->opcode) != 0))
4853 gen_set_Rc0(ctx, cpu_T[0]);
4857 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR)
4859 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4860 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4861 gen_op_POWER_srlq();
4862 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4863 if (unlikely(Rc(ctx->opcode) != 0))
4864 gen_set_Rc0(ctx, cpu_T[0]);
4868 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
4870 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4871 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4873 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4874 if (unlikely(Rc(ctx->opcode) != 0))
4875 gen_set_Rc0(ctx, cpu_T[0]);
4878 /* PowerPC 602 specific instructions */
4880 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC)
4883 GEN_EXCP_INVAL(ctx);
4887 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC)
4890 GEN_EXCP_INVAL(ctx);
4894 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
4896 #if defined(CONFIG_USER_ONLY)
4897 GEN_EXCP_PRIVOPC(ctx);
4899 if (unlikely(!ctx->supervisor)) {
4900 GEN_EXCP_PRIVOPC(ctx);
4903 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4905 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4909 /* 602 - 603 - G2 TLB management */
4911 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
4913 #if defined(CONFIG_USER_ONLY)
4914 GEN_EXCP_PRIVOPC(ctx);
4916 if (unlikely(!ctx->supervisor)) {
4917 GEN_EXCP_PRIVOPC(ctx);
4920 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4926 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
4928 #if defined(CONFIG_USER_ONLY)
4929 GEN_EXCP_PRIVOPC(ctx);
4931 if (unlikely(!ctx->supervisor)) {
4932 GEN_EXCP_PRIVOPC(ctx);
4935 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4940 /* 74xx TLB management */
4942 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB)
4944 #if defined(CONFIG_USER_ONLY)
4945 GEN_EXCP_PRIVOPC(ctx);
4947 if (unlikely(!ctx->supervisor)) {
4948 GEN_EXCP_PRIVOPC(ctx);
4951 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4952 gen_op_74xx_tlbld();
4957 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB)
4959 #if defined(CONFIG_USER_ONLY)
4960 GEN_EXCP_PRIVOPC(ctx);
4962 if (unlikely(!ctx->supervisor)) {
4963 GEN_EXCP_PRIVOPC(ctx);
4966 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4967 gen_op_74xx_tlbli();
4971 /* POWER instructions not in PowerPC 601 */
4973 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER)
4975 /* Cache line flush: implemented as no-op */
4979 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER)
4981 /* Cache line invalidate: privileged and treated as no-op */
4982 #if defined(CONFIG_USER_ONLY)
4983 GEN_EXCP_PRIVOPC(ctx);
4985 if (unlikely(!ctx->supervisor)) {
4986 GEN_EXCP_PRIVOPC(ctx);
4993 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER)
4995 /* Data cache line store: treated as no-op */
4998 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
5000 #if defined(CONFIG_USER_ONLY)
5001 GEN_EXCP_PRIVOPC(ctx);
5003 if (unlikely(!ctx->supervisor)) {
5004 GEN_EXCP_PRIVOPC(ctx);
5007 int ra = rA(ctx->opcode);
5008 int rd = rD(ctx->opcode);
5010 gen_addr_reg_index(cpu_T[0], ctx);
5011 gen_op_POWER_mfsri();
5012 tcg_gen_mov_tl(cpu_gpr[rd], cpu_T[0]);
5013 if (ra != 0 && ra != rd)
5014 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[1]);
5018 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
5020 #if defined(CONFIG_USER_ONLY)
5021 GEN_EXCP_PRIVOPC(ctx);
5023 if (unlikely(!ctx->supervisor)) {
5024 GEN_EXCP_PRIVOPC(ctx);
5027 gen_addr_reg_index(cpu_T[0], ctx);
5029 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5033 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER)
5035 #if defined(CONFIG_USER_ONLY)
5036 GEN_EXCP_PRIVOPC(ctx);
5038 if (unlikely(!ctx->supervisor)) {
5039 GEN_EXCP_PRIVOPC(ctx);
5042 gen_op_POWER_rfsvc();
5047 /* svc is not implemented for now */
5049 /* POWER2 specific instructions */
5050 /* Quad manipulation (load/store two floats at a time) */
5051 /* Original POWER2 is 32 bits only, define 64 bits ops as 32 bits ones */
5052 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
5053 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
5054 #define gen_op_POWER2_lfq_64_raw gen_op_POWER2_lfq_raw
5055 #define gen_op_POWER2_lfq_64_user gen_op_POWER2_lfq_user
5056 #define gen_op_POWER2_lfq_64_kernel gen_op_POWER2_lfq_kernel
5057 #define gen_op_POWER2_lfq_64_hypv gen_op_POWER2_lfq_hypv
5058 #define gen_op_POWER2_lfq_le_64_raw gen_op_POWER2_lfq_le_raw
5059 #define gen_op_POWER2_lfq_le_64_user gen_op_POWER2_lfq_le_user
5060 #define gen_op_POWER2_lfq_le_64_kernel gen_op_POWER2_lfq_le_kernel
5061 #define gen_op_POWER2_lfq_le_64_hypv gen_op_POWER2_lfq_le_hypv
5062 #define gen_op_POWER2_stfq_64_raw gen_op_POWER2_stfq_raw
5063 #define gen_op_POWER2_stfq_64_user gen_op_POWER2_stfq_user
5064 #define gen_op_POWER2_stfq_64_kernel gen_op_POWER2_stfq_kernel
5065 #define gen_op_POWER2_stfq_64_hypv gen_op_POWER2_stfq_hypv
5066 #define gen_op_POWER2_stfq_le_64_raw gen_op_POWER2_stfq_le_raw
5067 #define gen_op_POWER2_stfq_le_64_user gen_op_POWER2_stfq_le_user
5068 #define gen_op_POWER2_stfq_le_64_kernel gen_op_POWER2_stfq_le_kernel
5069 #define gen_op_POWER2_stfq_le_64_hypv gen_op_POWER2_stfq_le_hypv
5070 static GenOpFunc *gen_op_POWER2_lfq[NB_MEM_FUNCS] = {
5071 GEN_MEM_FUNCS(POWER2_lfq),
5073 static GenOpFunc *gen_op_POWER2_stfq[NB_MEM_FUNCS] = {
5074 GEN_MEM_FUNCS(POWER2_stfq),
5078 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5080 /* NIP cannot be restored if the memory exception comes from an helper */
5081 gen_update_nip(ctx, ctx->nip - 4);
5082 gen_addr_imm_index(cpu_T[0], ctx, 0);
5084 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5085 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5089 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5091 int ra = rA(ctx->opcode);
5093 /* NIP cannot be restored if the memory exception comes from an helper */
5094 gen_update_nip(ctx, ctx->nip - 4);
5095 gen_addr_imm_index(cpu_T[0], ctx, 0);
5097 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5098 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5100 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5104 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
5106 int ra = rA(ctx->opcode);
5108 /* NIP cannot be restored if the memory exception comes from an helper */
5109 gen_update_nip(ctx, ctx->nip - 4);
5110 gen_addr_reg_index(cpu_T[0], ctx);
5112 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5113 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5115 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5119 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
5121 /* NIP cannot be restored if the memory exception comes from an helper */
5122 gen_update_nip(ctx, ctx->nip - 4);
5123 gen_addr_reg_index(cpu_T[0], ctx);
5125 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5126 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5130 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5132 /* NIP cannot be restored if the memory exception comes from an helper */
5133 gen_update_nip(ctx, ctx->nip - 4);
5134 gen_addr_imm_index(cpu_T[0], ctx, 0);
5135 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5136 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5141 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5143 int ra = rA(ctx->opcode);
5145 /* NIP cannot be restored if the memory exception comes from an helper */
5146 gen_update_nip(ctx, ctx->nip - 4);
5147 gen_addr_imm_index(cpu_T[0], ctx, 0);
5148 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5149 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5152 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5156 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
5158 int ra = rA(ctx->opcode);
5160 /* NIP cannot be restored if the memory exception comes from an helper */
5161 gen_update_nip(ctx, ctx->nip - 4);
5162 gen_addr_reg_index(cpu_T[0], ctx);
5163 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5164 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5167 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5171 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
5173 /* NIP cannot be restored if the memory exception comes from an helper */
5174 gen_update_nip(ctx, ctx->nip - 4);
5175 gen_addr_reg_index(cpu_T[0], ctx);
5176 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5177 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5181 /* BookE specific instructions */
5182 /* XXX: not implemented on 440 ? */
5183 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI)
5186 GEN_EXCP_INVAL(ctx);
5189 /* XXX: not implemented on 440 ? */
5190 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA)
5192 #if defined(CONFIG_USER_ONLY)
5193 GEN_EXCP_PRIVOPC(ctx);
5195 if (unlikely(!ctx->supervisor)) {
5196 GEN_EXCP_PRIVOPC(ctx);
5199 gen_addr_reg_index(cpu_T[0], ctx);
5200 /* Use the same micro-ops as for tlbie */
5201 #if defined(TARGET_PPC64)
5210 /* All 405 MAC instructions are translated here */
5211 static always_inline void gen_405_mulladd_insn (DisasContext *ctx,
5213 int ra, int rb, int rt, int Rc)
5217 t0 = tcg_temp_local_new(TCG_TYPE_TL);
5218 t1 = tcg_temp_local_new(TCG_TYPE_TL);
5220 switch (opc3 & 0x0D) {
5222 /* macchw - macchw. - macchwo - macchwo. */
5223 /* macchws - macchws. - macchwso - macchwso. */
5224 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5225 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5226 /* mulchw - mulchw. */
5227 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5228 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5229 tcg_gen_ext16s_tl(t1, t1);
5232 /* macchwu - macchwu. - macchwuo - macchwuo. */
5233 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5234 /* mulchwu - mulchwu. */
5235 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5236 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5237 tcg_gen_ext16u_tl(t1, t1);
5240 /* machhw - machhw. - machhwo - machhwo. */
5241 /* machhws - machhws. - machhwso - machhwso. */
5242 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5243 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5244 /* mulhhw - mulhhw. */
5245 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5246 tcg_gen_ext16s_tl(t0, t0);
5247 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5248 tcg_gen_ext16s_tl(t1, t1);
5251 /* machhwu - machhwu. - machhwuo - machhwuo. */
5252 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5253 /* mulhhwu - mulhhwu. */
5254 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5255 tcg_gen_ext16u_tl(t0, t0);
5256 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5257 tcg_gen_ext16u_tl(t1, t1);
5260 /* maclhw - maclhw. - maclhwo - maclhwo. */
5261 /* maclhws - maclhws. - maclhwso - maclhwso. */
5262 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5263 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5264 /* mullhw - mullhw. */
5265 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5266 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
5269 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5270 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5271 /* mullhwu - mullhwu. */
5272 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5273 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
5277 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5278 tcg_gen_mul_tl(t1, t0, t1);
5280 /* nmultiply-and-accumulate (0x0E) */
5281 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5283 /* multiply-and-accumulate (0x0C) */
5284 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5288 /* Check overflow and/or saturate */
5289 int l1 = gen_new_label();
5292 /* Start with XER OV disabled, the most likely case */
5293 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
5297 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5298 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5299 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5300 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
5303 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5304 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5308 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
5311 tcg_gen_movi_tl(t0, UINT32_MAX);
5315 /* Check overflow */
5316 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
5319 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5322 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
5326 if (unlikely(Rc) != 0) {
5328 gen_set_Rc0(ctx, cpu_gpr[rt]);
5332 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5333 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5335 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5336 rD(ctx->opcode), Rc(ctx->opcode)); \
5339 /* macchw - macchw. */
5340 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
5341 /* macchwo - macchwo. */
5342 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
5343 /* macchws - macchws. */
5344 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
5345 /* macchwso - macchwso. */
5346 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
5347 /* macchwsu - macchwsu. */
5348 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
5349 /* macchwsuo - macchwsuo. */
5350 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
5351 /* macchwu - macchwu. */
5352 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
5353 /* macchwuo - macchwuo. */
5354 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
5355 /* machhw - machhw. */
5356 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
5357 /* machhwo - machhwo. */
5358 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
5359 /* machhws - machhws. */
5360 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
5361 /* machhwso - machhwso. */
5362 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
5363 /* machhwsu - machhwsu. */
5364 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
5365 /* machhwsuo - machhwsuo. */
5366 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
5367 /* machhwu - machhwu. */
5368 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
5369 /* machhwuo - machhwuo. */
5370 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
5371 /* maclhw - maclhw. */
5372 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
5373 /* maclhwo - maclhwo. */
5374 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
5375 /* maclhws - maclhws. */
5376 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
5377 /* maclhwso - maclhwso. */
5378 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
5379 /* maclhwu - maclhwu. */
5380 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
5381 /* maclhwuo - maclhwuo. */
5382 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
5383 /* maclhwsu - maclhwsu. */
5384 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
5385 /* maclhwsuo - maclhwsuo. */
5386 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
5387 /* nmacchw - nmacchw. */
5388 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
5389 /* nmacchwo - nmacchwo. */
5390 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
5391 /* nmacchws - nmacchws. */
5392 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
5393 /* nmacchwso - nmacchwso. */
5394 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
5395 /* nmachhw - nmachhw. */
5396 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
5397 /* nmachhwo - nmachhwo. */
5398 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
5399 /* nmachhws - nmachhws. */
5400 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
5401 /* nmachhwso - nmachhwso. */
5402 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
5403 /* nmaclhw - nmaclhw. */
5404 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
5405 /* nmaclhwo - nmaclhwo. */
5406 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
5407 /* nmaclhws - nmaclhws. */
5408 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
5409 /* nmaclhwso - nmaclhwso. */
5410 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
5412 /* mulchw - mulchw. */
5413 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
5414 /* mulchwu - mulchwu. */
5415 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
5416 /* mulhhw - mulhhw. */
5417 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
5418 /* mulhhwu - mulhhwu. */
5419 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
5420 /* mullhw - mullhw. */
5421 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
5422 /* mullhwu - mullhwu. */
5423 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
5426 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR)
5428 #if defined(CONFIG_USER_ONLY)
5429 GEN_EXCP_PRIVREG(ctx);
5431 uint32_t dcrn = SPR(ctx->opcode);
5433 if (unlikely(!ctx->supervisor)) {
5434 GEN_EXCP_PRIVREG(ctx);
5437 tcg_gen_movi_tl(cpu_T[0], dcrn);
5439 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5444 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR)
5446 #if defined(CONFIG_USER_ONLY)
5447 GEN_EXCP_PRIVREG(ctx);
5449 uint32_t dcrn = SPR(ctx->opcode);
5451 if (unlikely(!ctx->supervisor)) {
5452 GEN_EXCP_PRIVREG(ctx);
5455 tcg_gen_movi_tl(cpu_T[0], dcrn);
5456 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5462 /* XXX: not implemented on 440 ? */
5463 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX)
5465 #if defined(CONFIG_USER_ONLY)
5466 GEN_EXCP_PRIVREG(ctx);
5468 if (unlikely(!ctx->supervisor)) {
5469 GEN_EXCP_PRIVREG(ctx);
5472 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5474 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5475 /* Note: Rc update flag set leads to undefined state of Rc0 */
5480 /* XXX: not implemented on 440 ? */
5481 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX)
5483 #if defined(CONFIG_USER_ONLY)
5484 GEN_EXCP_PRIVREG(ctx);
5486 if (unlikely(!ctx->supervisor)) {
5487 GEN_EXCP_PRIVREG(ctx);
5490 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5491 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5493 /* Note: Rc update flag set leads to undefined state of Rc0 */
5497 /* mfdcrux (PPC 460) : user-mode access to DCR */
5498 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX)
5500 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5502 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5503 /* Note: Rc update flag set leads to undefined state of Rc0 */
5506 /* mtdcrux (PPC 460) : user-mode access to DCR */
5507 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX)
5509 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5510 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5512 /* Note: Rc update flag set leads to undefined state of Rc0 */
5516 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
5518 #if defined(CONFIG_USER_ONLY)
5519 GEN_EXCP_PRIVOPC(ctx);
5521 if (unlikely(!ctx->supervisor)) {
5522 GEN_EXCP_PRIVOPC(ctx);
5525 /* interpreted as no-op */
5530 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON)
5532 #if defined(CONFIG_USER_ONLY)
5533 GEN_EXCP_PRIVOPC(ctx);
5536 if (unlikely(!ctx->supervisor)) {
5537 GEN_EXCP_PRIVOPC(ctx);
5540 EA = tcg_temp_new(TCG_TYPE_TL);
5541 gen_addr_reg_index(EA, ctx);
5542 val = tcg_temp_new(TCG_TYPE_TL);
5543 gen_qemu_ld32u(val, EA, ctx->mem_idx);
5545 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5551 GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT)
5553 /* interpreted as no-op */
5554 /* XXX: specification say this is treated as a load by the MMU
5555 * but does not generate any exception
5560 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
5562 #if defined(CONFIG_USER_ONLY)
5563 GEN_EXCP_PRIVOPC(ctx);
5565 if (unlikely(!ctx->supervisor)) {
5566 GEN_EXCP_PRIVOPC(ctx);
5569 /* interpreted as no-op */
5574 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
5576 #if defined(CONFIG_USER_ONLY)
5577 GEN_EXCP_PRIVOPC(ctx);
5579 if (unlikely(!ctx->supervisor)) {
5580 GEN_EXCP_PRIVOPC(ctx);
5583 /* interpreted as no-op */
5587 /* rfci (supervisor only) */
5588 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP)
5590 #if defined(CONFIG_USER_ONLY)
5591 GEN_EXCP_PRIVOPC(ctx);
5593 if (unlikely(!ctx->supervisor)) {
5594 GEN_EXCP_PRIVOPC(ctx);
5597 /* Restore CPU state */
5603 GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE)
5605 #if defined(CONFIG_USER_ONLY)
5606 GEN_EXCP_PRIVOPC(ctx);
5608 if (unlikely(!ctx->supervisor)) {
5609 GEN_EXCP_PRIVOPC(ctx);
5612 /* Restore CPU state */
5618 /* BookE specific */
5619 /* XXX: not implemented on 440 ? */
5620 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI)
5622 #if defined(CONFIG_USER_ONLY)
5623 GEN_EXCP_PRIVOPC(ctx);
5625 if (unlikely(!ctx->supervisor)) {
5626 GEN_EXCP_PRIVOPC(ctx);
5629 /* Restore CPU state */
5635 /* XXX: not implemented on 440 ? */
5636 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI)
5638 #if defined(CONFIG_USER_ONLY)
5639 GEN_EXCP_PRIVOPC(ctx);
5641 if (unlikely(!ctx->supervisor)) {
5642 GEN_EXCP_PRIVOPC(ctx);
5645 /* Restore CPU state */
5651 /* TLB management - PowerPC 405 implementation */
5653 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
5655 #if defined(CONFIG_USER_ONLY)
5656 GEN_EXCP_PRIVOPC(ctx);
5658 if (unlikely(!ctx->supervisor)) {
5659 GEN_EXCP_PRIVOPC(ctx);
5662 switch (rB(ctx->opcode)) {
5664 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5665 gen_op_4xx_tlbre_hi();
5666 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5669 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5670 gen_op_4xx_tlbre_lo();
5671 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5674 GEN_EXCP_INVAL(ctx);
5680 /* tlbsx - tlbsx. */
5681 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB)
5683 #if defined(CONFIG_USER_ONLY)
5684 GEN_EXCP_PRIVOPC(ctx);
5686 if (unlikely(!ctx->supervisor)) {
5687 GEN_EXCP_PRIVOPC(ctx);
5690 gen_addr_reg_index(cpu_T[0], ctx);
5692 if (Rc(ctx->opcode))
5693 gen_op_4xx_tlbsx_check();
5694 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5699 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
5701 #if defined(CONFIG_USER_ONLY)
5702 GEN_EXCP_PRIVOPC(ctx);
5704 if (unlikely(!ctx->supervisor)) {
5705 GEN_EXCP_PRIVOPC(ctx);
5708 switch (rB(ctx->opcode)) {
5710 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5711 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5712 gen_op_4xx_tlbwe_hi();
5715 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5716 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5717 gen_op_4xx_tlbwe_lo();
5720 GEN_EXCP_INVAL(ctx);
5726 /* TLB management - PowerPC 440 implementation */
5728 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
5730 #if defined(CONFIG_USER_ONLY)
5731 GEN_EXCP_PRIVOPC(ctx);
5733 if (unlikely(!ctx->supervisor)) {
5734 GEN_EXCP_PRIVOPC(ctx);
5737 switch (rB(ctx->opcode)) {
5741 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5742 gen_op_440_tlbre(rB(ctx->opcode));
5743 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5746 GEN_EXCP_INVAL(ctx);
5752 /* tlbsx - tlbsx. */
5753 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE)
5755 #if defined(CONFIG_USER_ONLY)
5756 GEN_EXCP_PRIVOPC(ctx);
5758 if (unlikely(!ctx->supervisor)) {
5759 GEN_EXCP_PRIVOPC(ctx);
5762 gen_addr_reg_index(cpu_T[0], ctx);
5764 if (Rc(ctx->opcode))
5765 gen_op_4xx_tlbsx_check();
5766 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5771 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
5773 #if defined(CONFIG_USER_ONLY)
5774 GEN_EXCP_PRIVOPC(ctx);
5776 if (unlikely(!ctx->supervisor)) {
5777 GEN_EXCP_PRIVOPC(ctx);
5780 switch (rB(ctx->opcode)) {
5784 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5785 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5786 gen_op_440_tlbwe(rB(ctx->opcode));
5789 GEN_EXCP_INVAL(ctx);
5796 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE)
5798 #if defined(CONFIG_USER_ONLY)
5799 GEN_EXCP_PRIVOPC(ctx);
5801 if (unlikely(!ctx->supervisor)) {
5802 GEN_EXCP_PRIVOPC(ctx);
5805 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rD(ctx->opcode)]);
5807 /* Stop translation to have a chance to raise an exception
5808 * if we just set msr_ee to 1
5815 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE)
5817 #if defined(CONFIG_USER_ONLY)
5818 GEN_EXCP_PRIVOPC(ctx);
5820 if (unlikely(!ctx->supervisor)) {
5821 GEN_EXCP_PRIVOPC(ctx);
5824 tcg_gen_movi_tl(cpu_T[0], ctx->opcode & 0x00010000);
5826 /* Stop translation to have a chance to raise an exception
5827 * if we just set msr_ee to 1
5833 /* PowerPC 440 specific instructions */
5835 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC)
5837 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
5838 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
5840 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
5841 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
5842 tcg_gen_or_tl(cpu_xer, cpu_xer, cpu_T[0]);
5843 if (Rc(ctx->opcode)) {
5844 gen_op_440_dlmzb_update_Rc();
5845 tcg_gen_andi_i32(cpu_crf[0], cpu_T[0], 0xf);
5849 /* mbar replaces eieio on 440 */
5850 GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE)
5852 /* interpreted as no-op */
5855 /* msync replaces sync on 440 */
5856 GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE)
5858 /* interpreted as no-op */
5862 GEN_HANDLER2(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE)
5864 /* interpreted as no-op */
5865 /* XXX: specification say this is treated as a load by the MMU
5866 * but does not generate any exception
5870 /*** Altivec vector extension ***/
5871 /* Altivec registers moves */
5873 static always_inline void gen_load_avr(int t, int reg) {
5874 tcg_gen_mov_i64(cpu_AVRh[t], cpu_avrh[reg]);
5875 tcg_gen_mov_i64(cpu_AVRl[t], cpu_avrl[reg]);
5878 static always_inline void gen_store_avr(int reg, int t) {
5879 tcg_gen_mov_i64(cpu_avrh[reg], cpu_AVRh[t]);
5880 tcg_gen_mov_i64(cpu_avrl[reg], cpu_AVRl[t]);
5883 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5884 #define OP_VR_LD_TABLE(name) \
5885 static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5886 GEN_MEM_FUNCS(vr_l##name), \
5888 #define OP_VR_ST_TABLE(name) \
5889 static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5890 GEN_MEM_FUNCS(vr_st##name), \
5893 #define GEN_VR_LDX(name, opc2, opc3) \
5894 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5896 if (unlikely(!ctx->altivec_enabled)) { \
5897 GEN_EXCP_NO_VR(ctx); \
5900 gen_addr_reg_index(cpu_T[0], ctx); \
5901 op_vr_ldst(vr_l##name); \
5902 gen_store_avr(rD(ctx->opcode), 0); \
5905 #define GEN_VR_STX(name, opc2, opc3) \
5906 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5908 if (unlikely(!ctx->altivec_enabled)) { \
5909 GEN_EXCP_NO_VR(ctx); \
5912 gen_addr_reg_index(cpu_T[0], ctx); \
5913 gen_load_avr(0, rS(ctx->opcode)); \
5914 op_vr_ldst(vr_st##name); \
5918 GEN_VR_LDX(vx, 0x07, 0x03);
5919 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5920 #define gen_op_vr_lvxl gen_op_vr_lvx
5921 GEN_VR_LDX(vxl, 0x07, 0x0B);
5924 GEN_VR_STX(vx, 0x07, 0x07);
5925 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5926 #define gen_op_vr_stvxl gen_op_vr_stvx
5927 GEN_VR_STX(vxl, 0x07, 0x0F);
5929 /*** SPE extension ***/
5930 /* Register moves */
5932 static always_inline void gen_load_gpr64(TCGv t, int reg) {
5933 #if defined(TARGET_PPC64)
5934 tcg_gen_mov_i64(t, cpu_gpr[reg]);
5936 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
5940 static always_inline void gen_store_gpr64(int reg, TCGv t) {
5941 #if defined(TARGET_PPC64)
5942 tcg_gen_mov_i64(cpu_gpr[reg], t);
5944 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
5945 TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
5946 tcg_gen_shri_i64(tmp, t, 32);
5947 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
5952 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5953 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5955 if (Rc(ctx->opcode)) \
5961 /* Handler for undefined SPE opcodes */
5962 static always_inline void gen_speundef (DisasContext *ctx)
5964 GEN_EXCP_INVAL(ctx);
5967 /* SPE load and stores */
5968 static always_inline void gen_addr_spe_imm_index (TCGv EA, DisasContext *ctx, int sh)
5970 target_long simm = rB(ctx->opcode);
5972 if (rA(ctx->opcode) == 0)
5973 tcg_gen_movi_tl(EA, simm << sh);
5974 else if (likely(simm != 0))
5975 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm << sh);
5977 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
5980 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5981 #define OP_SPE_LD_TABLE(name) \
5982 static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5983 GEN_MEM_FUNCS(spe_l##name), \
5985 #define OP_SPE_ST_TABLE(name) \
5986 static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5987 GEN_MEM_FUNCS(spe_st##name), \
5990 #define GEN_SPE_LD(name, sh) \
5991 static always_inline void gen_evl##name (DisasContext *ctx) \
5993 if (unlikely(!ctx->spe_enabled)) { \
5994 GEN_EXCP_NO_AP(ctx); \
5997 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
5998 op_spe_ldst(spe_l##name); \
5999 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
6002 #define GEN_SPE_LDX(name) \
6003 static always_inline void gen_evl##name##x (DisasContext *ctx) \
6005 if (unlikely(!ctx->spe_enabled)) { \
6006 GEN_EXCP_NO_AP(ctx); \
6009 gen_addr_reg_index(cpu_T[0], ctx); \
6010 op_spe_ldst(spe_l##name); \
6011 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
6014 #define GEN_SPEOP_LD(name, sh) \
6015 OP_SPE_LD_TABLE(name); \
6016 GEN_SPE_LD(name, sh); \
6019 #define GEN_SPE_ST(name, sh) \
6020 static always_inline void gen_evst##name (DisasContext *ctx) \
6022 if (unlikely(!ctx->spe_enabled)) { \
6023 GEN_EXCP_NO_AP(ctx); \
6026 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
6027 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
6028 op_spe_ldst(spe_st##name); \
6031 #define GEN_SPE_STX(name) \
6032 static always_inline void gen_evst##name##x (DisasContext *ctx) \
6034 if (unlikely(!ctx->spe_enabled)) { \
6035 GEN_EXCP_NO_AP(ctx); \
6038 gen_addr_reg_index(cpu_T[0], ctx); \
6039 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
6040 op_spe_ldst(spe_st##name); \
6043 #define GEN_SPEOP_ST(name, sh) \
6044 OP_SPE_ST_TABLE(name); \
6045 GEN_SPE_ST(name, sh); \
6048 #define GEN_SPEOP_LDST(name, sh) \
6049 GEN_SPEOP_LD(name, sh); \
6050 GEN_SPEOP_ST(name, sh)
6052 /* SPE arithmetic and logic */
6053 #define GEN_SPEOP_ARITH2(name) \
6054 static always_inline void gen_##name (DisasContext *ctx) \
6056 if (unlikely(!ctx->spe_enabled)) { \
6057 GEN_EXCP_NO_AP(ctx); \
6060 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6061 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
6063 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6066 #define GEN_SPEOP_TCG_ARITH2(name, tcg_op) \
6067 static always_inline void gen_##name (DisasContext *ctx) \
6069 if (unlikely(!ctx->spe_enabled)) { \
6070 GEN_EXCP_NO_AP(ctx); \
6073 TCGv t0 = tcg_temp_new(TCG_TYPE_I64); \
6074 TCGv t1 = tcg_temp_new(TCG_TYPE_I64); \
6075 gen_load_gpr64(t0, rA(ctx->opcode)); \
6076 gen_load_gpr64(t1, rB(ctx->opcode)); \
6077 tcg_op(t0, t0, t1); \
6078 gen_store_gpr64(rD(ctx->opcode), t0); \
6079 tcg_temp_free(t0); \
6080 tcg_temp_free(t1); \
6083 #define GEN_SPEOP_ARITH1(name) \
6084 static always_inline void gen_##name (DisasContext *ctx) \
6086 if (unlikely(!ctx->spe_enabled)) { \
6087 GEN_EXCP_NO_AP(ctx); \
6090 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6092 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6095 #define GEN_SPEOP_COMP(name) \
6096 static always_inline void gen_##name (DisasContext *ctx) \
6098 if (unlikely(!ctx->spe_enabled)) { \
6099 GEN_EXCP_NO_AP(ctx); \
6102 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6103 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
6105 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf); \
6109 GEN_SPEOP_TCG_ARITH2(evand, tcg_gen_and_i64);
6110 GEN_SPEOP_TCG_ARITH2(evandc, tcg_gen_andc_i64);
6111 GEN_SPEOP_TCG_ARITH2(evxor, tcg_gen_xor_i64);
6112 GEN_SPEOP_TCG_ARITH2(evor, tcg_gen_or_i64);
6113 GEN_SPEOP_TCG_ARITH2(evnor, tcg_gen_nor_i64);
6114 GEN_SPEOP_TCG_ARITH2(eveqv, tcg_gen_eqv_i64);
6115 GEN_SPEOP_TCG_ARITH2(evorc, tcg_gen_orc_i64);
6116 GEN_SPEOP_TCG_ARITH2(evnand, tcg_gen_nand_i64);
6117 GEN_SPEOP_ARITH2(evsrwu);
6118 GEN_SPEOP_ARITH2(evsrws);
6119 GEN_SPEOP_ARITH2(evslw);
6120 GEN_SPEOP_ARITH2(evrlw);
6121 GEN_SPEOP_ARITH2(evmergehi);
6122 GEN_SPEOP_ARITH2(evmergelo);
6123 GEN_SPEOP_ARITH2(evmergehilo);
6124 GEN_SPEOP_ARITH2(evmergelohi);
6127 GEN_SPEOP_ARITH2(evaddw);
6128 GEN_SPEOP_ARITH2(evsubfw);
6129 GEN_SPEOP_ARITH1(evabs);
6130 GEN_SPEOP_ARITH1(evneg);
6131 GEN_SPEOP_ARITH1(evextsb);
6132 GEN_SPEOP_ARITH1(evextsh);
6133 GEN_SPEOP_ARITH1(evrndw);
6134 GEN_SPEOP_ARITH1(evcntlzw);
6135 GEN_SPEOP_ARITH1(evcntlsw);
6136 static always_inline void gen_brinc (DisasContext *ctx)
6138 /* Note: brinc is usable even if SPE is disabled */
6139 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
6140 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
6142 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
6145 #define GEN_SPEOP_ARITH_IMM2(name) \
6146 static always_inline void gen_##name##i (DisasContext *ctx) \
6148 if (unlikely(!ctx->spe_enabled)) { \
6149 GEN_EXCP_NO_AP(ctx); \
6152 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
6153 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
6155 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6158 #define GEN_SPEOP_LOGIC_IMM2(name) \
6159 static always_inline void gen_##name##i (DisasContext *ctx) \
6161 if (unlikely(!ctx->spe_enabled)) { \
6162 GEN_EXCP_NO_AP(ctx); \
6165 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6166 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
6168 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6171 GEN_SPEOP_ARITH_IMM2(evaddw);
6172 #define gen_evaddiw gen_evaddwi
6173 GEN_SPEOP_ARITH_IMM2(evsubfw);
6174 #define gen_evsubifw gen_evsubfwi
6175 GEN_SPEOP_LOGIC_IMM2(evslw);
6176 GEN_SPEOP_LOGIC_IMM2(evsrwu);
6177 #define gen_evsrwis gen_evsrwsi
6178 GEN_SPEOP_LOGIC_IMM2(evsrws);
6179 #define gen_evsrwiu gen_evsrwui
6180 GEN_SPEOP_LOGIC_IMM2(evrlw);
6182 static always_inline void gen_evsplati (DisasContext *ctx)
6184 int32_t imm = (int32_t)(rA(ctx->opcode) << 27) >> 27;
6186 gen_op_splatwi_T0_64(imm);
6187 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6190 static always_inline void gen_evsplatfi (DisasContext *ctx)
6192 uint32_t imm = rA(ctx->opcode) << 27;
6194 gen_op_splatwi_T0_64(imm);
6195 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6199 GEN_SPEOP_COMP(evcmpgtu);
6200 GEN_SPEOP_COMP(evcmpgts);
6201 GEN_SPEOP_COMP(evcmpltu);
6202 GEN_SPEOP_COMP(evcmplts);
6203 GEN_SPEOP_COMP(evcmpeq);
6205 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); ////
6206 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE);
6207 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE); ////
6208 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE);
6209 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE); ////
6210 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE); ////
6211 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE); ////
6212 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE); //
6213 GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE); ////
6214 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE); ////
6215 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE); ////
6216 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE); ////
6217 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE); ////
6218 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE); ////
6219 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE); ////
6220 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE);
6221 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE); ////
6222 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE);
6223 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE); //
6224 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE);
6225 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE); ////
6226 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE); ////
6227 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE); ////
6228 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE); ////
6229 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE); ////
6231 static always_inline void gen_evsel (DisasContext *ctx)
6233 if (unlikely(!ctx->spe_enabled)) {
6234 GEN_EXCP_NO_AP(ctx);
6237 tcg_gen_mov_i32(cpu_T[0], cpu_crf[ctx->opcode & 0x7]);
6238 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode));
6239 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode));
6241 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6244 GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE)
6248 GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE)
6252 GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE)
6256 GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE)
6261 /* Load and stores */
6262 GEN_SPEOP_LDST(dd, 3);
6263 GEN_SPEOP_LDST(dw, 3);
6264 GEN_SPEOP_LDST(dh, 3);
6265 GEN_SPEOP_LDST(whe, 2);
6266 GEN_SPEOP_LD(whou, 2);
6267 GEN_SPEOP_LD(whos, 2);
6268 GEN_SPEOP_ST(who, 2);
6270 #define _GEN_OP_SPE_STWWE(suffix) \
6271 static always_inline void gen_op_spe_stwwe_##suffix (void) \
6273 gen_op_srli32_T1_64(); \
6274 gen_op_spe_stwwo_##suffix(); \
6276 #define _GEN_OP_SPE_STWWE_LE(suffix) \
6277 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
6279 gen_op_srli32_T1_64(); \
6280 gen_op_spe_stwwo_le_##suffix(); \
6282 #if defined(TARGET_PPC64)
6283 #define GEN_OP_SPE_STWWE(suffix) \
6284 _GEN_OP_SPE_STWWE(suffix); \
6285 _GEN_OP_SPE_STWWE_LE(suffix); \
6286 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
6288 gen_op_srli32_T1_64(); \
6289 gen_op_spe_stwwo_64_##suffix(); \
6291 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
6293 gen_op_srli32_T1_64(); \
6294 gen_op_spe_stwwo_le_64_##suffix(); \
6297 #define GEN_OP_SPE_STWWE(suffix) \
6298 _GEN_OP_SPE_STWWE(suffix); \
6299 _GEN_OP_SPE_STWWE_LE(suffix)
6301 #if defined(CONFIG_USER_ONLY)
6302 GEN_OP_SPE_STWWE(raw);
6303 #else /* defined(CONFIG_USER_ONLY) */
6304 GEN_OP_SPE_STWWE(user);
6305 GEN_OP_SPE_STWWE(kernel);
6306 GEN_OP_SPE_STWWE(hypv);
6307 #endif /* defined(CONFIG_USER_ONLY) */
6308 GEN_SPEOP_ST(wwe, 2);
6309 GEN_SPEOP_ST(wwo, 2);
6311 #define GEN_SPE_LDSPLAT(name, op, suffix) \
6312 static always_inline void gen_op_spe_l##name##_##suffix (void) \
6314 gen_op_##op##_##suffix(); \
6315 gen_op_splatw_T1_64(); \
6318 #define GEN_OP_SPE_LHE(suffix) \
6319 static always_inline void gen_op_spe_lhe_##suffix (void) \
6321 gen_op_spe_lh_##suffix(); \
6322 gen_op_sli16_T1_64(); \
6325 #define GEN_OP_SPE_LHX(suffix) \
6326 static always_inline void gen_op_spe_lhx_##suffix (void) \
6328 gen_op_spe_lh_##suffix(); \
6329 gen_op_extsh_T1_64(); \
6332 #if defined(CONFIG_USER_ONLY)
6333 GEN_OP_SPE_LHE(raw);
6334 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, raw);
6335 GEN_OP_SPE_LHE(le_raw);
6336 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_raw);
6337 GEN_SPE_LDSPLAT(hhousplat, spe_lh, raw);
6338 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_raw);
6339 GEN_OP_SPE_LHX(raw);
6340 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, raw);
6341 GEN_OP_SPE_LHX(le_raw);
6342 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_raw);
6343 #if defined(TARGET_PPC64)
6344 GEN_OP_SPE_LHE(64_raw);
6345 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_raw);
6346 GEN_OP_SPE_LHE(le_64_raw);
6347 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_raw);
6348 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_raw);
6349 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_raw);
6350 GEN_OP_SPE_LHX(64_raw);
6351 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_raw);
6352 GEN_OP_SPE_LHX(le_64_raw);
6353 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_raw);
6356 GEN_OP_SPE_LHE(user);
6357 GEN_OP_SPE_LHE(kernel);
6358 GEN_OP_SPE_LHE(hypv);
6359 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, user);
6360 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel);
6361 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, hypv);
6362 GEN_OP_SPE_LHE(le_user);
6363 GEN_OP_SPE_LHE(le_kernel);
6364 GEN_OP_SPE_LHE(le_hypv);
6365 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_user);
6366 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel);
6367 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_hypv);
6368 GEN_SPE_LDSPLAT(hhousplat, spe_lh, user);
6369 GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel);
6370 GEN_SPE_LDSPLAT(hhousplat, spe_lh, hypv);
6371 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_user);
6372 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel);
6373 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_hypv);
6374 GEN_OP_SPE_LHX(user);
6375 GEN_OP_SPE_LHX(kernel);
6376 GEN_OP_SPE_LHX(hypv);
6377 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, user);
6378 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel);
6379 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, hypv);
6380 GEN_OP_SPE_LHX(le_user);
6381 GEN_OP_SPE_LHX(le_kernel);
6382 GEN_OP_SPE_LHX(le_hypv);
6383 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_user);
6384 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel);
6385 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_hypv);
6386 #if defined(TARGET_PPC64)
6387 GEN_OP_SPE_LHE(64_user);
6388 GEN_OP_SPE_LHE(64_kernel);
6389 GEN_OP_SPE_LHE(64_hypv);
6390 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_user);
6391 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
6392 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_hypv);
6393 GEN_OP_SPE_LHE(le_64_user);
6394 GEN_OP_SPE_LHE(le_64_kernel);
6395 GEN_OP_SPE_LHE(le_64_hypv);
6396 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_user);
6397 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel);
6398 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_hypv);
6399 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_user);
6400 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
6401 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_hypv);
6402 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_user);
6403 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel);
6404 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_hypv);
6405 GEN_OP_SPE_LHX(64_user);
6406 GEN_OP_SPE_LHX(64_kernel);
6407 GEN_OP_SPE_LHX(64_hypv);
6408 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_user);
6409 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
6410 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_hypv);
6411 GEN_OP_SPE_LHX(le_64_user);
6412 GEN_OP_SPE_LHX(le_64_kernel);
6413 GEN_OP_SPE_LHX(le_64_hypv);
6414 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_user);
6415 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel);
6416 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_hypv);
6419 GEN_SPEOP_LD(hhesplat, 1);
6420 GEN_SPEOP_LD(hhousplat, 1);
6421 GEN_SPEOP_LD(hhossplat, 1);
6422 GEN_SPEOP_LD(wwsplat, 2);
6423 GEN_SPEOP_LD(whsplat, 2);
6425 GEN_SPE(evlddx, evldd, 0x00, 0x0C, 0x00000000, PPC_SPE); //
6426 GEN_SPE(evldwx, evldw, 0x01, 0x0C, 0x00000000, PPC_SPE); //
6427 GEN_SPE(evldhx, evldh, 0x02, 0x0C, 0x00000000, PPC_SPE); //
6428 GEN_SPE(evlhhesplatx, evlhhesplat, 0x04, 0x0C, 0x00000000, PPC_SPE); //
6429 GEN_SPE(evlhhousplatx, evlhhousplat, 0x06, 0x0C, 0x00000000, PPC_SPE); //
6430 GEN_SPE(evlhhossplatx, evlhhossplat, 0x07, 0x0C, 0x00000000, PPC_SPE); //
6431 GEN_SPE(evlwhex, evlwhe, 0x08, 0x0C, 0x00000000, PPC_SPE); //
6432 GEN_SPE(evlwhoux, evlwhou, 0x0A, 0x0C, 0x00000000, PPC_SPE); //
6433 GEN_SPE(evlwhosx, evlwhos, 0x0B, 0x0C, 0x00000000, PPC_SPE); //
6434 GEN_SPE(evlwwsplatx, evlwwsplat, 0x0C, 0x0C, 0x00000000, PPC_SPE); //
6435 GEN_SPE(evlwhsplatx, evlwhsplat, 0x0E, 0x0C, 0x00000000, PPC_SPE); //
6436 GEN_SPE(evstddx, evstdd, 0x10, 0x0C, 0x00000000, PPC_SPE); //
6437 GEN_SPE(evstdwx, evstdw, 0x11, 0x0C, 0x00000000, PPC_SPE); //
6438 GEN_SPE(evstdhx, evstdh, 0x12, 0x0C, 0x00000000, PPC_SPE); //
6439 GEN_SPE(evstwhex, evstwhe, 0x18, 0x0C, 0x00000000, PPC_SPE); //
6440 GEN_SPE(evstwhox, evstwho, 0x1A, 0x0C, 0x00000000, PPC_SPE); //
6441 GEN_SPE(evstwwex, evstwwe, 0x1C, 0x0C, 0x00000000, PPC_SPE); //
6442 GEN_SPE(evstwwox, evstwwo, 0x1E, 0x0C, 0x00000000, PPC_SPE); //
6444 /* Multiply and add - TODO */
6446 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0x00000000, PPC_SPE);
6447 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0x00000000, PPC_SPE);
6448 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, PPC_SPE);
6449 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0x00000000, PPC_SPE);
6450 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, PPC_SPE);
6451 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0x00000000, PPC_SPE);
6452 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0x00000000, PPC_SPE);
6453 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0x00000000, PPC_SPE);
6454 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, PPC_SPE);
6455 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0x00000000, PPC_SPE);
6456 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, PPC_SPE);
6457 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0x00000000, PPC_SPE);
6459 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0x00000000, PPC_SPE);
6460 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, PPC_SPE);
6461 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, PPC_SPE);
6462 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0x00000000, PPC_SPE);
6463 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0x00000000, PPC_SPE);
6464 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE);
6465 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0x00000000, PPC_SPE);
6466 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0x00000000, PPC_SPE);
6467 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, PPC_SPE);
6468 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, PPC_SPE);
6469 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0x00000000, PPC_SPE);
6470 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0x00000000, PPC_SPE);
6471 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE);
6472 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0x00000000, PPC_SPE);
6474 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, PPC_SPE);
6475 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, PPC_SPE);
6476 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, PPC_SPE);
6477 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, PPC_SPE);
6478 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, PPC_SPE);
6479 GEN_SPE(evmra, speundef, 0x07, 0x13, 0x0000F800, PPC_SPE);
6481 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, PPC_SPE);
6482 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0x00000000, PPC_SPE);
6483 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, PPC_SPE);
6484 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0x00000000, PPC_SPE);
6485 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, PPC_SPE);
6486 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0x00000000, PPC_SPE);
6487 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, PPC_SPE);
6488 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0x00000000, PPC_SPE);
6489 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, PPC_SPE);
6490 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0x00000000, PPC_SPE);
6491 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, PPC_SPE);
6492 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0x00000000, PPC_SPE);
6494 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, PPC_SPE);
6495 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, PPC_SPE);
6496 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0x00000000, PPC_SPE);
6497 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE);
6498 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0x00000000, PPC_SPE);
6500 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, PPC_SPE);
6501 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0x00000000, PPC_SPE);
6502 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, PPC_SPE);
6503 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0x00000000, PPC_SPE);
6504 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, PPC_SPE);
6505 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0x00000000, PPC_SPE);
6506 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, PPC_SPE);
6507 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0x00000000, PPC_SPE);
6508 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, PPC_SPE);
6509 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0x00000000, PPC_SPE);
6510 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, PPC_SPE);
6511 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0x00000000, PPC_SPE);
6513 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, PPC_SPE);
6514 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, PPC_SPE);
6515 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0x00000000, PPC_SPE);
6516 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, PPC_SPE);
6517 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0x00000000, PPC_SPE);
6520 /*** SPE floating-point extension ***/
6521 #define GEN_SPEFPUOP_CONV(name) \
6522 static always_inline void gen_##name (DisasContext *ctx) \
6524 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
6526 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6529 /* Single precision floating-point vectors operations */
6531 GEN_SPEOP_ARITH2(evfsadd);
6532 GEN_SPEOP_ARITH2(evfssub);
6533 GEN_SPEOP_ARITH2(evfsmul);
6534 GEN_SPEOP_ARITH2(evfsdiv);
6535 GEN_SPEOP_ARITH1(evfsabs);
6536 GEN_SPEOP_ARITH1(evfsnabs);
6537 GEN_SPEOP_ARITH1(evfsneg);
6539 GEN_SPEFPUOP_CONV(evfscfui);
6540 GEN_SPEFPUOP_CONV(evfscfsi);
6541 GEN_SPEFPUOP_CONV(evfscfuf);
6542 GEN_SPEFPUOP_CONV(evfscfsf);
6543 GEN_SPEFPUOP_CONV(evfsctui);
6544 GEN_SPEFPUOP_CONV(evfsctsi);
6545 GEN_SPEFPUOP_CONV(evfsctuf);
6546 GEN_SPEFPUOP_CONV(evfsctsf);
6547 GEN_SPEFPUOP_CONV(evfsctuiz);
6548 GEN_SPEFPUOP_CONV(evfsctsiz);
6550 GEN_SPEOP_COMP(evfscmpgt);
6551 GEN_SPEOP_COMP(evfscmplt);
6552 GEN_SPEOP_COMP(evfscmpeq);
6553 GEN_SPEOP_COMP(evfststgt);
6554 GEN_SPEOP_COMP(evfststlt);
6555 GEN_SPEOP_COMP(evfststeq);
6557 /* Opcodes definitions */
6558 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); //
6559 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU); //
6560 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU); //
6561 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPEFPU); //
6562 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPEFPU); //
6563 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPEFPU); //
6564 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPEFPU); //
6565 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPEFPU); //
6566 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU); //
6567 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU); //
6568 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU); //
6569 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU); //
6570 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU); //
6571 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU); //
6573 /* Single precision floating-point operations */
6575 GEN_SPEOP_ARITH2(efsadd);
6576 GEN_SPEOP_ARITH2(efssub);
6577 GEN_SPEOP_ARITH2(efsmul);
6578 GEN_SPEOP_ARITH2(efsdiv);
6579 GEN_SPEOP_ARITH1(efsabs);
6580 GEN_SPEOP_ARITH1(efsnabs);
6581 GEN_SPEOP_ARITH1(efsneg);
6583 GEN_SPEFPUOP_CONV(efscfui);
6584 GEN_SPEFPUOP_CONV(efscfsi);
6585 GEN_SPEFPUOP_CONV(efscfuf);
6586 GEN_SPEFPUOP_CONV(efscfsf);
6587 GEN_SPEFPUOP_CONV(efsctui);
6588 GEN_SPEFPUOP_CONV(efsctsi);
6589 GEN_SPEFPUOP_CONV(efsctuf);
6590 GEN_SPEFPUOP_CONV(efsctsf);
6591 GEN_SPEFPUOP_CONV(efsctuiz);
6592 GEN_SPEFPUOP_CONV(efsctsiz);
6593 GEN_SPEFPUOP_CONV(efscfd);
6595 GEN_SPEOP_COMP(efscmpgt);
6596 GEN_SPEOP_COMP(efscmplt);
6597 GEN_SPEOP_COMP(efscmpeq);
6598 GEN_SPEOP_COMP(efststgt);
6599 GEN_SPEOP_COMP(efststlt);
6600 GEN_SPEOP_COMP(efststeq);
6602 /* Opcodes definitions */
6603 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, PPC_SPEFPU); //
6604 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU); //
6605 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU); //
6606 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPEFPU); //
6607 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPEFPU); //
6608 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPEFPU); //
6609 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPEFPU); //
6610 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPEFPU); //
6611 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU); //
6612 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU); //
6613 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU); //
6614 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU); //
6615 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU); //
6616 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU); //
6618 /* Double precision floating-point operations */
6620 GEN_SPEOP_ARITH2(efdadd);
6621 GEN_SPEOP_ARITH2(efdsub);
6622 GEN_SPEOP_ARITH2(efdmul);
6623 GEN_SPEOP_ARITH2(efddiv);
6624 GEN_SPEOP_ARITH1(efdabs);
6625 GEN_SPEOP_ARITH1(efdnabs);
6626 GEN_SPEOP_ARITH1(efdneg);
6629 GEN_SPEFPUOP_CONV(efdcfui);
6630 GEN_SPEFPUOP_CONV(efdcfsi);
6631 GEN_SPEFPUOP_CONV(efdcfuf);
6632 GEN_SPEFPUOP_CONV(efdcfsf);
6633 GEN_SPEFPUOP_CONV(efdctui);
6634 GEN_SPEFPUOP_CONV(efdctsi);
6635 GEN_SPEFPUOP_CONV(efdctuf);
6636 GEN_SPEFPUOP_CONV(efdctsf);
6637 GEN_SPEFPUOP_CONV(efdctuiz);
6638 GEN_SPEFPUOP_CONV(efdctsiz);
6639 GEN_SPEFPUOP_CONV(efdcfs);
6640 GEN_SPEFPUOP_CONV(efdcfuid);
6641 GEN_SPEFPUOP_CONV(efdcfsid);
6642 GEN_SPEFPUOP_CONV(efdctuidz);
6643 GEN_SPEFPUOP_CONV(efdctsidz);
6645 GEN_SPEOP_COMP(efdcmpgt);
6646 GEN_SPEOP_COMP(efdcmplt);
6647 GEN_SPEOP_COMP(efdcmpeq);
6648 GEN_SPEOP_COMP(efdtstgt);
6649 GEN_SPEOP_COMP(efdtstlt);
6650 GEN_SPEOP_COMP(efdtsteq);
6652 /* Opcodes definitions */
6653 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPEFPU); //
6654 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPEFPU); //
6655 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU); //
6656 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU); //
6657 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPEFPU); //
6658 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPEFPU); //
6659 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPEFPU); //
6660 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPEFPU); //
6661 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPEFPU); //
6662 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPEFPU); //
6663 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU); //
6664 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU); //
6665 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU); //
6666 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU); //
6667 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU); //
6668 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU); //
6670 /* End opcode list */
6671 GEN_OPCODE_MARK(end);
6673 #include "translate_init.c"
6674 #include "helper_regs.h"
6676 /*****************************************************************************/
6677 /* Misc PowerPC helpers */
6678 void cpu_dump_state (CPUState *env, FILE *f,
6679 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6687 cpu_fprintf(f, "NIP " ADDRX " LR " ADDRX " CTR " ADDRX " XER %08x\n",
6688 env->nip, env->lr, env->ctr, env->xer);
6689 cpu_fprintf(f, "MSR " ADDRX " HID0 " ADDRX " HF " ADDRX " idx %d\n",
6690 env->msr, env->spr[SPR_HID0], env->hflags, env->mmu_idx);
6691 #if !defined(NO_TIMER_DUMP)
6692 cpu_fprintf(f, "TB %08x %08x "
6693 #if !defined(CONFIG_USER_ONLY)
6697 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
6698 #if !defined(CONFIG_USER_ONLY)
6699 , cpu_ppc_load_decr(env)
6703 for (i = 0; i < 32; i++) {
6704 if ((i & (RGPL - 1)) == 0)
6705 cpu_fprintf(f, "GPR%02d", i);
6706 cpu_fprintf(f, " " REGX, ppc_dump_gpr(env, i));
6707 if ((i & (RGPL - 1)) == (RGPL - 1))
6708 cpu_fprintf(f, "\n");
6710 cpu_fprintf(f, "CR ");
6711 for (i = 0; i < 8; i++)
6712 cpu_fprintf(f, "%01x", env->crf[i]);
6713 cpu_fprintf(f, " [");
6714 for (i = 0; i < 8; i++) {
6716 if (env->crf[i] & 0x08)
6718 else if (env->crf[i] & 0x04)
6720 else if (env->crf[i] & 0x02)
6722 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
6724 cpu_fprintf(f, " ] RES " ADDRX "\n", env->reserve);
6725 for (i = 0; i < 32; i++) {
6726 if ((i & (RFPL - 1)) == 0)
6727 cpu_fprintf(f, "FPR%02d", i);
6728 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
6729 if ((i & (RFPL - 1)) == (RFPL - 1))
6730 cpu_fprintf(f, "\n");
6732 #if !defined(CONFIG_USER_ONLY)
6733 cpu_fprintf(f, "SRR0 " ADDRX " SRR1 " ADDRX " SDR1 " ADDRX "\n",
6734 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
6741 void cpu_dump_statistics (CPUState *env, FILE*f,
6742 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6745 #if defined(DO_PPC_STATISTICS)
6746 opc_handler_t **t1, **t2, **t3, *handler;
6750 for (op1 = 0; op1 < 64; op1++) {
6752 if (is_indirect_opcode(handler)) {
6753 t2 = ind_table(handler);
6754 for (op2 = 0; op2 < 32; op2++) {
6756 if (is_indirect_opcode(handler)) {
6757 t3 = ind_table(handler);
6758 for (op3 = 0; op3 < 32; op3++) {
6760 if (handler->count == 0)
6762 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
6764 op1, op2, op3, op1, (op3 << 5) | op2,
6766 handler->count, handler->count);
6769 if (handler->count == 0)
6771 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
6773 op1, op2, op1, op2, handler->oname,
6774 handler->count, handler->count);
6778 if (handler->count == 0)
6780 cpu_fprintf(f, "%02x (%02x ) %16s: %016llx %lld\n",
6781 op1, op1, handler->oname,
6782 handler->count, handler->count);
6788 /*****************************************************************************/
6789 static always_inline void gen_intermediate_code_internal (CPUState *env,
6790 TranslationBlock *tb,
6793 DisasContext ctx, *ctxp = &ctx;
6794 opc_handler_t **table, *handler;
6795 target_ulong pc_start;
6796 uint16_t *gen_opc_end;
6797 int supervisor, little_endian;
6803 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
6804 #if defined(OPTIMIZE_FPRF_UPDATE)
6805 gen_fprf_ptr = gen_fprf_buf;
6809 ctx.exception = POWERPC_EXCP_NONE;
6810 ctx.spr_cb = env->spr_cb;
6811 supervisor = env->mmu_idx;
6812 #if !defined(CONFIG_USER_ONLY)
6813 ctx.supervisor = supervisor;
6815 little_endian = env->hflags & (1 << MSR_LE) ? 1 : 0;
6816 #if defined(TARGET_PPC64)
6817 ctx.sf_mode = msr_sf;
6818 ctx.mem_idx = (supervisor << 2) | (msr_sf << 1) | little_endian;
6820 ctx.mem_idx = (supervisor << 1) | little_endian;
6822 ctx.dcache_line_size = env->dcache_line_size;
6823 ctx.fpu_enabled = msr_fp;
6824 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
6825 ctx.spe_enabled = msr_spe;
6827 ctx.spe_enabled = 0;
6828 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
6829 ctx.altivec_enabled = msr_vr;
6831 ctx.altivec_enabled = 0;
6832 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
6833 ctx.singlestep_enabled = CPU_SINGLE_STEP;
6835 ctx.singlestep_enabled = 0;
6836 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
6837 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
6838 if (unlikely(env->singlestep_enabled))
6839 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
6840 #if defined (DO_SINGLE_STEP) && 0
6841 /* Single step trace mode */
6845 max_insns = tb->cflags & CF_COUNT_MASK;
6847 max_insns = CF_COUNT_MASK;
6850 /* Set env in case of segfault during code fetch */
6851 while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
6852 if (unlikely(env->nb_breakpoints > 0)) {
6853 for (j = 0; j < env->nb_breakpoints; j++) {
6854 if (env->breakpoints[j] == ctx.nip) {
6855 gen_update_nip(&ctx, ctx.nip);
6861 if (unlikely(search_pc)) {
6862 j = gen_opc_ptr - gen_opc_buf;
6866 gen_opc_instr_start[lj++] = 0;
6867 gen_opc_pc[lj] = ctx.nip;
6868 gen_opc_instr_start[lj] = 1;
6869 gen_opc_icount[lj] = num_insns;
6872 #if defined PPC_DEBUG_DISAS
6873 if (loglevel & CPU_LOG_TB_IN_ASM) {
6874 fprintf(logfile, "----------------\n");
6875 fprintf(logfile, "nip=" ADDRX " super=%d ir=%d\n",
6876 ctx.nip, supervisor, (int)msr_ir);
6879 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
6881 if (unlikely(little_endian)) {
6882 ctx.opcode = bswap32(ldl_code(ctx.nip));
6884 ctx.opcode = ldl_code(ctx.nip);
6886 #if defined PPC_DEBUG_DISAS
6887 if (loglevel & CPU_LOG_TB_IN_ASM) {
6888 fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6889 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
6890 opc3(ctx.opcode), little_endian ? "little" : "big");
6894 table = env->opcodes;
6896 handler = table[opc1(ctx.opcode)];
6897 if (is_indirect_opcode(handler)) {
6898 table = ind_table(handler);
6899 handler = table[opc2(ctx.opcode)];
6900 if (is_indirect_opcode(handler)) {
6901 table = ind_table(handler);
6902 handler = table[opc3(ctx.opcode)];
6905 /* Is opcode *REALLY* valid ? */
6906 if (unlikely(handler->handler == &gen_invalid)) {
6907 if (loglevel != 0) {
6908 fprintf(logfile, "invalid/unsupported opcode: "
6909 "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
6910 opc1(ctx.opcode), opc2(ctx.opcode),
6911 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
6913 printf("invalid/unsupported opcode: "
6914 "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
6915 opc1(ctx.opcode), opc2(ctx.opcode),
6916 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
6919 if (unlikely((ctx.opcode & handler->inval) != 0)) {
6920 if (loglevel != 0) {
6921 fprintf(logfile, "invalid bits: %08x for opcode: "
6922 "%02x - %02x - %02x (%08x) " ADDRX "\n",
6923 ctx.opcode & handler->inval, opc1(ctx.opcode),
6924 opc2(ctx.opcode), opc3(ctx.opcode),
6925 ctx.opcode, ctx.nip - 4);
6927 printf("invalid bits: %08x for opcode: "
6928 "%02x - %02x - %02x (%08x) " ADDRX "\n",
6929 ctx.opcode & handler->inval, opc1(ctx.opcode),
6930 opc2(ctx.opcode), opc3(ctx.opcode),
6931 ctx.opcode, ctx.nip - 4);
6933 GEN_EXCP_INVAL(ctxp);
6937 (*(handler->handler))(&ctx);
6938 #if defined(DO_PPC_STATISTICS)
6941 /* Check trace mode exceptions */
6942 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
6943 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
6944 ctx.exception != POWERPC_SYSCALL &&
6945 ctx.exception != POWERPC_EXCP_TRAP &&
6946 ctx.exception != POWERPC_EXCP_BRANCH)) {
6947 GEN_EXCP(ctxp, POWERPC_EXCP_TRACE, 0);
6948 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
6949 (env->singlestep_enabled) ||
6950 num_insns >= max_insns)) {
6951 /* if we reach a page boundary or are single stepping, stop
6956 #if defined (DO_SINGLE_STEP)
6960 if (tb->cflags & CF_LAST_IO)
6962 if (ctx.exception == POWERPC_EXCP_NONE) {
6963 gen_goto_tb(&ctx, 0, ctx.nip);
6964 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
6965 if (unlikely(env->singlestep_enabled)) {
6966 gen_update_nip(&ctx, ctx.nip);
6969 /* Generate the return instruction */
6972 gen_icount_end(tb, num_insns);
6973 *gen_opc_ptr = INDEX_op_end;
6974 if (unlikely(search_pc)) {
6975 j = gen_opc_ptr - gen_opc_buf;
6978 gen_opc_instr_start[lj++] = 0;
6980 tb->size = ctx.nip - pc_start;
6981 tb->icount = num_insns;
6983 #if defined(DEBUG_DISAS)
6984 if (loglevel & CPU_LOG_TB_CPU) {
6985 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
6986 cpu_dump_state(env, logfile, fprintf, 0);
6988 if (loglevel & CPU_LOG_TB_IN_ASM) {
6990 flags = env->bfd_mach;
6991 flags |= little_endian << 16;
6992 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
6993 target_disas(logfile, pc_start, ctx.nip - pc_start, flags);
6994 fprintf(logfile, "\n");
6999 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
7001 gen_intermediate_code_internal(env, tb, 0);
7004 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
7006 gen_intermediate_code_internal(env, tb, 1);
7009 void gen_pc_load(CPUState *env, TranslationBlock *tb,
7010 unsigned long searched_pc, int pc_pos, void *puc)
7013 /* for PPC, we need to look at the micro operation to get the
7015 env->nip = gen_opc_pc[pc_pos];
7016 c = gen_opc_buf[pc_pos];
7018 #if defined(CONFIG_USER_ONLY)
7020 case INDEX_op_ ## op ## _raw
7023 case INDEX_op_ ## op ## _user:\
7024 case INDEX_op_ ## op ## _kernel:\
7025 case INDEX_op_ ## op ## _hypv
7032 type = ACCESS_FLOAT;
7048 env->access_type = type;