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 temp = tcg_temp_new(TCG_TYPE_I32);
842 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
843 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 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 temp = tcg_temp_local_new(TCG_TYPE_TL);
1962 tcg_gen_andi_tl(temp, cpu_gpr[rB(ctx->opcode)], 0x20);
1963 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
1964 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1967 tcg_gen_andi_tl(temp, cpu_gpr[rB(ctx->opcode)], 0x3f);
1968 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], temp);
1969 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
1971 tcg_temp_free(temp);
1972 if (unlikely(Rc(ctx->opcode) != 0))
1973 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1976 GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER)
1978 tcg_gen_helper_1_2(helper_sraw, cpu_gpr[rA(ctx->opcode)],
1979 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1980 if (unlikely(Rc(ctx->opcode) != 0))
1981 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1983 /* srawi & srawi. */
1984 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
1986 int sh = SH(ctx->opcode);
1990 l1 = gen_new_label();
1991 l2 = gen_new_label();
1992 temp = tcg_temp_local_new(TCG_TYPE_TL);
1993 tcg_gen_ext32s_tl(temp, cpu_gpr[rS(ctx->opcode)]);
1994 tcg_gen_brcondi_tl(TCG_COND_GE, temp, 0, l1);
1995 tcg_gen_andi_tl(temp, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
1996 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
1997 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
2000 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2002 tcg_gen_ext32s_tl(temp, cpu_gpr[rS(ctx->opcode)]);
2003 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], temp, sh);
2004 tcg_temp_free(temp);
2006 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
2007 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2009 if (unlikely(Rc(ctx->opcode) != 0))
2010 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2013 GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER)
2017 l1 = gen_new_label();
2018 l2 = gen_new_label();
2020 temp = tcg_temp_local_new(TCG_TYPE_TL);
2021 tcg_gen_andi_tl(temp, cpu_gpr[rB(ctx->opcode)], 0x20);
2022 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
2023 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2026 tcg_gen_andi_tl(temp, cpu_gpr[rB(ctx->opcode)], 0x3f);
2027 temp2 = tcg_temp_new(TCG_TYPE_TL);
2028 tcg_gen_ext32u_tl(temp2, cpu_gpr[rS(ctx->opcode)]);
2029 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], temp2, temp);
2030 tcg_temp_free(temp2);
2032 tcg_temp_free(temp);
2033 if (unlikely(Rc(ctx->opcode) != 0))
2034 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2036 #if defined(TARGET_PPC64)
2038 GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B)
2042 l1 = gen_new_label();
2043 l2 = gen_new_label();
2045 temp = tcg_temp_local_new(TCG_TYPE_TL);
2046 tcg_gen_andi_tl(temp, cpu_gpr[rB(ctx->opcode)], 0x40);
2047 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
2048 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2051 tcg_gen_andi_tl(temp, cpu_gpr[rB(ctx->opcode)], 0x7f);
2052 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], temp);
2054 tcg_temp_free(temp);
2055 if (unlikely(Rc(ctx->opcode) != 0))
2056 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2059 GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B)
2061 tcg_gen_helper_1_2(helper_srad, cpu_gpr[rA(ctx->opcode)],
2062 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2063 if (unlikely(Rc(ctx->opcode) != 0))
2064 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2066 /* sradi & sradi. */
2067 static always_inline void gen_sradi (DisasContext *ctx, int n)
2069 int sh = SH(ctx->opcode) + (n << 5);
2073 l1 = gen_new_label();
2074 l2 = gen_new_label();
2075 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
2076 temp = tcg_temp_new(TCG_TYPE_TL);
2077 tcg_gen_andi_tl(temp, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
2078 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
2079 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
2082 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2084 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
2086 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
2087 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2089 if (unlikely(Rc(ctx->opcode) != 0))
2090 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2092 GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
2096 GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
2101 GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B)
2105 l1 = gen_new_label();
2106 l2 = gen_new_label();
2108 temp = tcg_temp_local_new(TCG_TYPE_TL);
2109 tcg_gen_andi_tl(temp, cpu_gpr[rB(ctx->opcode)], 0x40);
2110 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
2111 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2114 tcg_gen_andi_tl(temp, cpu_gpr[rB(ctx->opcode)], 0x7f);
2115 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], temp);
2117 tcg_temp_free(temp);
2118 if (unlikely(Rc(ctx->opcode) != 0))
2119 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2123 /*** Floating-Point arithmetic ***/
2124 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2125 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
2127 if (unlikely(!ctx->fpu_enabled)) { \
2128 GEN_EXCP_NO_FP(ctx); \
2131 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2132 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2133 tcg_gen_mov_i64(cpu_FT[2], cpu_fpr[rB(ctx->opcode)]); \
2134 gen_reset_fpstatus(); \
2139 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2140 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2143 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2144 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2145 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2147 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2148 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2150 if (unlikely(!ctx->fpu_enabled)) { \
2151 GEN_EXCP_NO_FP(ctx); \
2154 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2155 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]); \
2156 gen_reset_fpstatus(); \
2161 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2162 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2164 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2165 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2166 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2168 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2169 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2171 if (unlikely(!ctx->fpu_enabled)) { \
2172 GEN_EXCP_NO_FP(ctx); \
2175 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2176 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2177 gen_reset_fpstatus(); \
2182 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2183 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2185 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2186 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2187 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2189 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2190 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
2192 if (unlikely(!ctx->fpu_enabled)) { \
2193 GEN_EXCP_NO_FP(ctx); \
2196 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2197 gen_reset_fpstatus(); \
2199 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2200 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2203 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2204 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
2206 if (unlikely(!ctx->fpu_enabled)) { \
2207 GEN_EXCP_NO_FP(ctx); \
2210 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2211 gen_reset_fpstatus(); \
2213 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2214 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2218 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
2220 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
2222 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
2225 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
2228 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
2231 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2234 static always_inline void gen_op_frsqrtes (void)
2239 GEN_FLOAT_BS(rsqrtes, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES);
2242 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
2244 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
2247 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
2249 if (unlikely(!ctx->fpu_enabled)) {
2250 GEN_EXCP_NO_FP(ctx);
2253 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2254 gen_reset_fpstatus();
2256 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2257 gen_compute_fprf(1, Rc(ctx->opcode) != 0);
2260 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
2262 if (unlikely(!ctx->fpu_enabled)) {
2263 GEN_EXCP_NO_FP(ctx);
2266 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2267 gen_reset_fpstatus();
2270 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2271 gen_compute_fprf(1, Rc(ctx->opcode) != 0);
2274 /*** Floating-Point multiply-and-add ***/
2275 /* fmadd - fmadds */
2276 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
2277 /* fmsub - fmsubs */
2278 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
2279 /* fnmadd - fnmadds */
2280 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
2281 /* fnmsub - fnmsubs */
2282 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
2284 /*** Floating-Point round & convert ***/
2286 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
2288 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
2290 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
2291 #if defined(TARGET_PPC64)
2293 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
2295 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
2297 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
2301 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
2303 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
2305 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
2307 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
2309 /*** Floating-Point compare ***/
2311 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
2313 if (unlikely(!ctx->fpu_enabled)) {
2314 GEN_EXCP_NO_FP(ctx);
2317 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]);
2318 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]);
2319 gen_reset_fpstatus();
2320 tcg_gen_helper_1_0(helper_fcmpo, cpu_crf[crfD(ctx->opcode)]);
2321 gen_op_float_check_status();
2325 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
2327 if (unlikely(!ctx->fpu_enabled)) {
2328 GEN_EXCP_NO_FP(ctx);
2331 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]);
2332 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]);
2333 gen_reset_fpstatus();
2334 tcg_gen_helper_1_0(helper_fcmpu, cpu_crf[crfD(ctx->opcode)]);
2335 gen_op_float_check_status();
2338 /*** Floating-point move ***/
2340 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2341 GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT);
2344 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2345 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
2347 if (unlikely(!ctx->fpu_enabled)) {
2348 GEN_EXCP_NO_FP(ctx);
2351 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2352 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2353 gen_compute_fprf(0, Rc(ctx->opcode) != 0);
2357 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2358 GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT);
2360 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2361 GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT);
2363 /*** Floating-Point status & ctrl register ***/
2365 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
2369 if (unlikely(!ctx->fpu_enabled)) {
2370 GEN_EXCP_NO_FP(ctx);
2373 gen_optimize_fprf();
2374 bfa = 4 * (7 - crfS(ctx->opcode));
2375 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_fpscr, bfa);
2376 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
2377 gen_op_fpscr_resetbit(~(0xF << bfa));
2381 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
2383 if (unlikely(!ctx->fpu_enabled)) {
2384 GEN_EXCP_NO_FP(ctx);
2387 gen_optimize_fprf();
2388 gen_reset_fpstatus();
2389 gen_op_load_fpscr_FT0();
2390 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2391 gen_compute_fprf(0, Rc(ctx->opcode) != 0);
2395 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
2399 if (unlikely(!ctx->fpu_enabled)) {
2400 GEN_EXCP_NO_FP(ctx);
2403 crb = 32 - (crbD(ctx->opcode) >> 2);
2404 gen_optimize_fprf();
2405 gen_reset_fpstatus();
2406 if (likely(crb != 30 && crb != 29))
2407 gen_op_fpscr_resetbit(~(1 << crb));
2408 if (unlikely(Rc(ctx->opcode) != 0)) {
2409 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2414 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
2418 if (unlikely(!ctx->fpu_enabled)) {
2419 GEN_EXCP_NO_FP(ctx);
2422 crb = 32 - (crbD(ctx->opcode) >> 2);
2423 gen_optimize_fprf();
2424 gen_reset_fpstatus();
2425 /* XXX: we pretend we can only do IEEE floating-point computations */
2426 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI))
2427 gen_op_fpscr_setbit(crb);
2428 if (unlikely(Rc(ctx->opcode) != 0)) {
2429 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2431 /* We can raise a differed exception */
2432 gen_op_float_check_status();
2436 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
2438 if (unlikely(!ctx->fpu_enabled)) {
2439 GEN_EXCP_NO_FP(ctx);
2442 gen_optimize_fprf();
2443 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2444 gen_reset_fpstatus();
2445 gen_op_store_fpscr(FM(ctx->opcode));
2446 if (unlikely(Rc(ctx->opcode) != 0)) {
2447 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2449 /* We can raise a differed exception */
2450 gen_op_float_check_status();
2454 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
2458 if (unlikely(!ctx->fpu_enabled)) {
2459 GEN_EXCP_NO_FP(ctx);
2462 bf = crbD(ctx->opcode) >> 2;
2464 gen_optimize_fprf();
2465 tcg_gen_movi_i64(cpu_FT[0], FPIMM(ctx->opcode) << (4 * sh));
2466 gen_reset_fpstatus();
2467 gen_op_store_fpscr(1 << sh);
2468 if (unlikely(Rc(ctx->opcode) != 0)) {
2469 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2471 /* We can raise a differed exception */
2472 gen_op_float_check_status();
2475 /*** Addressing modes ***/
2476 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2477 static always_inline void gen_addr_imm_index (TCGv EA,
2481 target_long simm = SIMM(ctx->opcode);
2484 if (rA(ctx->opcode) == 0)
2485 tcg_gen_movi_tl(EA, simm);
2486 else if (likely(simm != 0))
2487 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2489 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2492 static always_inline void gen_addr_reg_index (TCGv EA,
2495 if (rA(ctx->opcode) == 0)
2496 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2498 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2501 static always_inline void gen_addr_register (TCGv EA,
2504 if (rA(ctx->opcode) == 0)
2505 tcg_gen_movi_tl(EA, 0);
2507 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2510 #if defined(TARGET_PPC64)
2511 #define _GEN_MEM_FUNCS(name, mode) \
2512 &gen_op_##name##_##mode, \
2513 &gen_op_##name##_le_##mode, \
2514 &gen_op_##name##_64_##mode, \
2515 &gen_op_##name##_le_64_##mode
2517 #define _GEN_MEM_FUNCS(name, mode) \
2518 &gen_op_##name##_##mode, \
2519 &gen_op_##name##_le_##mode
2521 #if defined(CONFIG_USER_ONLY)
2522 #if defined(TARGET_PPC64)
2523 #define NB_MEM_FUNCS 4
2525 #define NB_MEM_FUNCS 2
2527 #define GEN_MEM_FUNCS(name) \
2528 _GEN_MEM_FUNCS(name, raw)
2530 #if defined(TARGET_PPC64)
2531 #define NB_MEM_FUNCS 12
2533 #define NB_MEM_FUNCS 6
2535 #define GEN_MEM_FUNCS(name) \
2536 _GEN_MEM_FUNCS(name, user), \
2537 _GEN_MEM_FUNCS(name, kernel), \
2538 _GEN_MEM_FUNCS(name, hypv)
2541 /*** Integer load ***/
2542 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2543 #define OP_LD_TABLE(width) \
2544 static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2545 GEN_MEM_FUNCS(l##width), \
2547 #define OP_ST_TABLE(width) \
2548 static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2549 GEN_MEM_FUNCS(st##width), \
2553 #if defined(TARGET_PPC64)
2554 #define GEN_QEMU_LD_PPC64(width) \
2555 static always_inline void gen_qemu_ld##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2557 if (likely(flags & 2)) \
2558 tcg_gen_qemu_ld##width(t0, t1, flags >> 2); \
2560 TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2561 tcg_gen_ext32u_tl(addr, t1); \
2562 tcg_gen_qemu_ld##width(t0, addr, flags >> 2); \
2563 tcg_temp_free(addr); \
2566 GEN_QEMU_LD_PPC64(8u)
2567 GEN_QEMU_LD_PPC64(8s)
2568 GEN_QEMU_LD_PPC64(16u)
2569 GEN_QEMU_LD_PPC64(16s)
2570 GEN_QEMU_LD_PPC64(32u)
2571 GEN_QEMU_LD_PPC64(32s)
2572 GEN_QEMU_LD_PPC64(64)
2574 #define GEN_QEMU_ST_PPC64(width) \
2575 static always_inline void gen_qemu_st##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2577 if (likely(flags & 2)) \
2578 tcg_gen_qemu_st##width(t0, t1, flags >> 2); \
2580 TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2581 tcg_gen_ext32u_tl(addr, t1); \
2582 tcg_gen_qemu_st##width(t0, addr, flags >> 2); \
2583 tcg_temp_free(addr); \
2586 GEN_QEMU_ST_PPC64(8)
2587 GEN_QEMU_ST_PPC64(16)
2588 GEN_QEMU_ST_PPC64(32)
2589 GEN_QEMU_ST_PPC64(64)
2591 static always_inline void gen_qemu_ld8u(TCGv arg0, TCGv arg1, int flags)
2593 gen_qemu_ld8u_ppc64(arg0, arg1, flags);
2596 static always_inline void gen_qemu_ld8s(TCGv arg0, TCGv arg1, int flags)
2598 gen_qemu_ld8s_ppc64(arg0, arg1, flags);
2601 static always_inline void gen_qemu_ld16u(TCGv arg0, TCGv arg1, int flags)
2603 if (unlikely(flags & 1)) {
2605 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2606 t0 = tcg_temp_new(TCG_TYPE_I32);
2607 tcg_gen_trunc_tl_i32(t0, arg0);
2608 tcg_gen_bswap16_i32(t0, t0);
2609 tcg_gen_extu_i32_tl(arg0, t0);
2612 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2615 static always_inline void gen_qemu_ld16s(TCGv arg0, TCGv arg1, int flags)
2617 if (unlikely(flags & 1)) {
2619 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2620 t0 = tcg_temp_new(TCG_TYPE_I32);
2621 tcg_gen_trunc_tl_i32(t0, arg0);
2622 tcg_gen_bswap16_i32(t0, t0);
2623 tcg_gen_extu_i32_tl(arg0, t0);
2624 tcg_gen_ext16s_tl(arg0, arg0);
2627 gen_qemu_ld16s_ppc64(arg0, arg1, flags);
2630 static always_inline void gen_qemu_ld32u(TCGv arg0, TCGv arg1, int flags)
2632 if (unlikely(flags & 1)) {
2634 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2635 t0 = tcg_temp_new(TCG_TYPE_I32);
2636 tcg_gen_trunc_tl_i32(t0, arg0);
2637 tcg_gen_bswap_i32(t0, t0);
2638 tcg_gen_extu_i32_tl(arg0, t0);
2641 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2644 static always_inline void gen_qemu_ld32s(TCGv arg0, TCGv arg1, int flags)
2646 if (unlikely(flags & 1)) {
2648 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2649 t0 = tcg_temp_new(TCG_TYPE_I32);
2650 tcg_gen_trunc_tl_i32(t0, arg0);
2651 tcg_gen_bswap_i32(t0, t0);
2652 tcg_gen_ext_i32_tl(arg0, t0);
2655 gen_qemu_ld32s_ppc64(arg0, arg1, flags);
2658 static always_inline void gen_qemu_ld64(TCGv arg0, TCGv arg1, int flags)
2660 gen_qemu_ld64_ppc64(arg0, arg1, flags);
2661 if (unlikely(flags & 1))
2662 tcg_gen_bswap_i64(arg0, arg0);
2665 static always_inline void gen_qemu_st8(TCGv arg0, TCGv arg1, int flags)
2667 gen_qemu_st8_ppc64(arg0, arg1, flags);
2670 static always_inline void gen_qemu_st16(TCGv arg0, TCGv arg1, int flags)
2672 if (unlikely(flags & 1)) {
2674 t0 = tcg_temp_new(TCG_TYPE_I32);
2675 tcg_gen_trunc_tl_i32(t0, arg0);
2676 tcg_gen_ext16u_i32(t0, t0);
2677 tcg_gen_bswap16_i32(t0, t0);
2678 t1 = tcg_temp_new(TCG_TYPE_I64);
2679 tcg_gen_extu_i32_tl(t1, t0);
2681 gen_qemu_st16_ppc64(t1, arg1, flags);
2684 gen_qemu_st16_ppc64(arg0, arg1, flags);
2687 static always_inline void gen_qemu_st32(TCGv arg0, TCGv arg1, int flags)
2689 if (unlikely(flags & 1)) {
2691 t0 = tcg_temp_new(TCG_TYPE_I32);
2692 tcg_gen_trunc_tl_i32(t0, arg0);
2693 tcg_gen_bswap_i32(t0, t0);
2694 t1 = tcg_temp_new(TCG_TYPE_I64);
2695 tcg_gen_extu_i32_tl(t1, t0);
2697 gen_qemu_st32_ppc64(t1, arg1, flags);
2700 gen_qemu_st32_ppc64(arg0, arg1, flags);
2703 static always_inline void gen_qemu_st64(TCGv arg0, TCGv arg1, int flags)
2705 if (unlikely(flags & 1)) {
2706 TCGv t0 = tcg_temp_new(TCG_TYPE_I64);
2707 tcg_gen_bswap_i64(t0, arg0);
2708 gen_qemu_st64_ppc64(t0, arg1, flags);
2711 gen_qemu_st64_ppc64(arg0, arg1, flags);
2715 #else /* defined(TARGET_PPC64) */
2716 #define GEN_QEMU_LD_PPC32(width) \
2717 static always_inline void gen_qemu_ld##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2719 tcg_gen_qemu_ld##width(arg0, arg1, flags >> 1); \
2721 GEN_QEMU_LD_PPC32(8u)
2722 GEN_QEMU_LD_PPC32(8s)
2723 GEN_QEMU_LD_PPC32(16u)
2724 GEN_QEMU_LD_PPC32(16s)
2725 GEN_QEMU_LD_PPC32(32u)
2726 GEN_QEMU_LD_PPC32(32s)
2727 GEN_QEMU_LD_PPC32(64)
2729 #define GEN_QEMU_ST_PPC32(width) \
2730 static always_inline void gen_qemu_st##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2732 tcg_gen_qemu_st##width(arg0, arg1, flags >> 1); \
2734 GEN_QEMU_ST_PPC32(8)
2735 GEN_QEMU_ST_PPC32(16)
2736 GEN_QEMU_ST_PPC32(32)
2737 GEN_QEMU_ST_PPC32(64)
2739 static always_inline void gen_qemu_ld8u(TCGv arg0, TCGv arg1, int flags)
2741 gen_qemu_ld8u_ppc32(arg0, arg1, flags >> 1);
2744 static always_inline void gen_qemu_ld8s(TCGv arg0, TCGv arg1, int flags)
2746 gen_qemu_ld8s_ppc32(arg0, arg1, flags >> 1);
2749 static always_inline void gen_qemu_ld16u(TCGv arg0, TCGv arg1, int flags)
2751 gen_qemu_ld16u_ppc32(arg0, arg1, flags >> 1);
2752 if (unlikely(flags & 1))
2753 tcg_gen_bswap16_i32(arg0, arg0);
2756 static always_inline void gen_qemu_ld16s(TCGv arg0, TCGv arg1, int flags)
2758 if (unlikely(flags & 1)) {
2759 gen_qemu_ld16u_ppc32(arg0, arg1, flags);
2760 tcg_gen_bswap16_i32(arg0, arg0);
2761 tcg_gen_ext16s_i32(arg0, arg0);
2763 gen_qemu_ld16s_ppc32(arg0, arg1, flags);
2766 static always_inline void gen_qemu_ld32u(TCGv arg0, TCGv arg1, int flags)
2768 gen_qemu_ld32u_ppc32(arg0, arg1, flags);
2769 if (unlikely(flags & 1))
2770 tcg_gen_bswap_i32(arg0, arg0);
2773 static always_inline void gen_qemu_ld64(TCGv arg0, TCGv arg1, int flags)
2775 gen_qemu_ld64_ppc32(arg0, arg1, flags);
2776 if (unlikely(flags & 1))
2777 tcg_gen_bswap_i64(arg0, arg0);
2780 static always_inline void gen_qemu_st8(TCGv arg0, TCGv arg1, int flags)
2782 gen_qemu_st8_ppc32(arg0, arg1, flags >> 1);
2785 static always_inline void gen_qemu_st16(TCGv arg0, TCGv arg1, int flags)
2787 if (unlikely(flags & 1)) {
2788 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2789 tcg_gen_ext16u_i32(temp, arg0);
2790 tcg_gen_bswap16_i32(temp, temp);
2791 gen_qemu_st16_ppc32(temp, arg1, flags >> 1);
2792 tcg_temp_free(temp);
2794 gen_qemu_st16_ppc32(arg0, arg1, flags >> 1);
2797 static always_inline void gen_qemu_st32(TCGv arg0, TCGv arg1, int flags)
2799 if (unlikely(flags & 1)) {
2800 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2801 tcg_gen_bswap_i32(temp, arg0);
2802 gen_qemu_st32_ppc32(temp, arg1, flags >> 1);
2803 tcg_temp_free(temp);
2805 gen_qemu_st32_ppc32(arg0, arg1, flags >> 1);
2808 static always_inline void gen_qemu_st64(TCGv arg0, TCGv arg1, int flags)
2810 if (unlikely(flags & 1)) {
2811 TCGv temp = tcg_temp_new(TCG_TYPE_I64);
2812 tcg_gen_bswap_i64(temp, arg0);
2813 gen_qemu_st64_ppc32(temp, arg1, flags >> 1);
2814 tcg_temp_free(temp);
2816 gen_qemu_st64_ppc32(arg0, arg1, flags >> 1);
2821 #define GEN_LD(width, opc, type) \
2822 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2824 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2825 gen_addr_imm_index(EA, ctx, 0); \
2826 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2827 tcg_temp_free(EA); \
2830 #define GEN_LDU(width, opc, type) \
2831 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2834 if (unlikely(rA(ctx->opcode) == 0 || \
2835 rA(ctx->opcode) == rD(ctx->opcode))) { \
2836 GEN_EXCP_INVAL(ctx); \
2839 EA = tcg_temp_new(TCG_TYPE_TL); \
2840 if (type == PPC_64B) \
2841 gen_addr_imm_index(EA, ctx, 0x03); \
2843 gen_addr_imm_index(EA, ctx, 0); \
2844 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2845 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2846 tcg_temp_free(EA); \
2849 #define GEN_LDUX(width, opc2, opc3, type) \
2850 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2853 if (unlikely(rA(ctx->opcode) == 0 || \
2854 rA(ctx->opcode) == rD(ctx->opcode))) { \
2855 GEN_EXCP_INVAL(ctx); \
2858 EA = tcg_temp_new(TCG_TYPE_TL); \
2859 gen_addr_reg_index(EA, ctx); \
2860 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2861 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2862 tcg_temp_free(EA); \
2865 #define GEN_LDX(width, opc2, opc3, type) \
2866 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2868 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2869 gen_addr_reg_index(EA, ctx); \
2870 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2871 tcg_temp_free(EA); \
2874 #define GEN_LDS(width, op, type) \
2875 GEN_LD(width, op | 0x20, type); \
2876 GEN_LDU(width, op | 0x21, type); \
2877 GEN_LDUX(width, 0x17, op | 0x01, type); \
2878 GEN_LDX(width, 0x17, op | 0x00, type)
2880 /* lbz lbzu lbzux lbzx */
2881 GEN_LDS(8u, 0x02, PPC_INTEGER);
2882 /* lha lhau lhaux lhax */
2883 GEN_LDS(16s, 0x0A, PPC_INTEGER);
2884 /* lhz lhzu lhzux lhzx */
2885 GEN_LDS(16u, 0x08, PPC_INTEGER);
2886 /* lwz lwzu lwzux lwzx */
2887 GEN_LDS(32u, 0x00, PPC_INTEGER);
2888 #if defined(TARGET_PPC64)
2890 GEN_LDUX(32s, 0x15, 0x0B, PPC_64B);
2892 GEN_LDX(32s, 0x15, 0x0A, PPC_64B);
2894 GEN_LDUX(64, 0x15, 0x01, PPC_64B);
2896 GEN_LDX(64, 0x15, 0x00, PPC_64B);
2897 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
2900 if (Rc(ctx->opcode)) {
2901 if (unlikely(rA(ctx->opcode) == 0 ||
2902 rA(ctx->opcode) == rD(ctx->opcode))) {
2903 GEN_EXCP_INVAL(ctx);
2907 EA = tcg_temp_new(TCG_TYPE_TL);
2908 gen_addr_imm_index(EA, ctx, 0x03);
2909 if (ctx->opcode & 0x02) {
2910 /* lwa (lwau is undefined) */
2911 gen_qemu_ld32s(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx);
2914 gen_qemu_ld64(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx);
2916 if (Rc(ctx->opcode))
2917 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2921 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX)
2923 #if defined(CONFIG_USER_ONLY)
2924 GEN_EXCP_PRIVOPC(ctx);
2929 /* Restore CPU state */
2930 if (unlikely(ctx->supervisor == 0)) {
2931 GEN_EXCP_PRIVOPC(ctx);
2934 ra = rA(ctx->opcode);
2935 rd = rD(ctx->opcode);
2936 if (unlikely((rd & 1) || rd == ra)) {
2937 GEN_EXCP_INVAL(ctx);
2940 if (unlikely(ctx->mem_idx & 1)) {
2941 /* Little-endian mode is not handled */
2942 GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2945 EA = tcg_temp_new(TCG_TYPE_TL);
2946 gen_addr_imm_index(EA, ctx, 0x0F);
2947 gen_qemu_ld64(cpu_gpr[rd], EA, ctx->mem_idx);
2948 tcg_gen_addi_tl(EA, EA, 8);
2949 gen_qemu_ld64(cpu_gpr[rd+1], EA, ctx->mem_idx);
2955 /*** Integer store ***/
2956 #define GEN_ST(width, opc, type) \
2957 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2959 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2960 gen_addr_imm_index(EA, ctx, 0); \
2961 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2962 tcg_temp_free(EA); \
2965 #define GEN_STU(width, opc, type) \
2966 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2969 if (unlikely(rA(ctx->opcode) == 0)) { \
2970 GEN_EXCP_INVAL(ctx); \
2973 EA = tcg_temp_new(TCG_TYPE_TL); \
2974 if (type == PPC_64B) \
2975 gen_addr_imm_index(EA, ctx, 0x03); \
2977 gen_addr_imm_index(EA, ctx, 0); \
2978 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2979 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2980 tcg_temp_free(EA); \
2983 #define GEN_STUX(width, opc2, opc3, type) \
2984 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2987 if (unlikely(rA(ctx->opcode) == 0)) { \
2988 GEN_EXCP_INVAL(ctx); \
2991 EA = tcg_temp_new(TCG_TYPE_TL); \
2992 gen_addr_reg_index(EA, ctx); \
2993 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2994 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2995 tcg_temp_free(EA); \
2998 #define GEN_STX(width, opc2, opc3, type) \
2999 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3001 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
3002 gen_addr_reg_index(EA, ctx); \
3003 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
3004 tcg_temp_free(EA); \
3007 #define GEN_STS(width, op, type) \
3008 GEN_ST(width, op | 0x20, type); \
3009 GEN_STU(width, op | 0x21, type); \
3010 GEN_STUX(width, 0x17, op | 0x01, type); \
3011 GEN_STX(width, 0x17, op | 0x00, type)
3013 /* stb stbu stbux stbx */
3014 GEN_STS(8, 0x06, PPC_INTEGER);
3015 /* sth sthu sthux sthx */
3016 GEN_STS(16, 0x0C, PPC_INTEGER);
3017 /* stw stwu stwux stwx */
3018 GEN_STS(32, 0x04, PPC_INTEGER);
3019 #if defined(TARGET_PPC64)
3020 GEN_STUX(64, 0x15, 0x05, PPC_64B);
3021 GEN_STX(64, 0x15, 0x04, PPC_64B);
3022 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B)
3027 rs = rS(ctx->opcode);
3028 if ((ctx->opcode & 0x3) == 0x2) {
3029 #if defined(CONFIG_USER_ONLY)
3030 GEN_EXCP_PRIVOPC(ctx);
3033 if (unlikely(ctx->supervisor == 0)) {
3034 GEN_EXCP_PRIVOPC(ctx);
3037 if (unlikely(rs & 1)) {
3038 GEN_EXCP_INVAL(ctx);
3041 if (unlikely(ctx->mem_idx & 1)) {
3042 /* Little-endian mode is not handled */
3043 GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
3046 EA = tcg_temp_new(TCG_TYPE_TL);
3047 gen_addr_imm_index(EA, ctx, 0x03);
3048 gen_qemu_st64(cpu_gpr[rs], EA, ctx->mem_idx);
3049 tcg_gen_addi_tl(EA, EA, 8);
3050 gen_qemu_st64(cpu_gpr[rs+1], EA, ctx->mem_idx);
3055 if (Rc(ctx->opcode)) {
3056 if (unlikely(rA(ctx->opcode) == 0)) {
3057 GEN_EXCP_INVAL(ctx);
3061 EA = tcg_temp_new(TCG_TYPE_TL);
3062 gen_addr_imm_index(EA, ctx, 0x03);
3063 gen_qemu_st64(cpu_gpr[rs], EA, ctx->mem_idx);
3064 if (Rc(ctx->opcode))
3065 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3070 /*** Integer load and store with byte reverse ***/
3072 void always_inline gen_qemu_ld16ur(TCGv t0, TCGv t1, int flags)
3074 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3075 gen_qemu_ld16u(temp, t1, flags);
3076 tcg_gen_bswap16_i32(temp, temp);
3077 tcg_gen_extu_i32_tl(t0, temp);
3078 tcg_temp_free(temp);
3080 GEN_LDX(16ur, 0x16, 0x18, PPC_INTEGER);
3083 void always_inline gen_qemu_ld32ur(TCGv t0, TCGv t1, int flags)
3085 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3086 gen_qemu_ld32u(temp, t1, flags);
3087 tcg_gen_bswap_i32(temp, temp);
3088 tcg_gen_extu_i32_tl(t0, temp);
3089 tcg_temp_free(temp);
3091 GEN_LDX(32ur, 0x16, 0x10, PPC_INTEGER);
3094 void always_inline gen_qemu_st16r(TCGv t0, TCGv t1, int flags)
3096 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3097 tcg_gen_trunc_tl_i32(temp, t0);
3098 tcg_gen_ext16u_i32(temp, temp);
3099 tcg_gen_bswap16_i32(temp, temp);
3100 gen_qemu_st16(temp, t1, flags);
3101 tcg_temp_free(temp);
3103 GEN_STX(16r, 0x16, 0x1C, PPC_INTEGER);
3106 void always_inline gen_qemu_st32r(TCGv t0, TCGv t1, int flags)
3108 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3109 tcg_gen_trunc_tl_i32(temp, t0);
3110 tcg_gen_bswap_i32(temp, temp);
3111 gen_qemu_st32(temp, t1, flags);
3112 tcg_temp_free(temp);
3114 GEN_STX(32r, 0x16, 0x14, PPC_INTEGER);
3116 /*** Integer load and store multiple ***/
3117 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
3118 static GenOpFunc1 *gen_op_lmw[NB_MEM_FUNCS] = {
3121 static GenOpFunc1 *gen_op_stmw[NB_MEM_FUNCS] = {
3122 GEN_MEM_FUNCS(stmw),
3126 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
3128 /* NIP cannot be restored if the memory exception comes from an helper */
3129 gen_update_nip(ctx, ctx->nip - 4);
3130 gen_addr_imm_index(cpu_T[0], ctx, 0);
3131 op_ldstm(lmw, rD(ctx->opcode));
3135 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
3137 /* NIP cannot be restored if the memory exception comes from an helper */
3138 gen_update_nip(ctx, ctx->nip - 4);
3139 gen_addr_imm_index(cpu_T[0], ctx, 0);
3140 op_ldstm(stmw, rS(ctx->opcode));
3143 /*** Integer load and store strings ***/
3144 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
3145 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
3146 /* string load & stores are by definition endian-safe */
3147 #define gen_op_lswi_le_raw gen_op_lswi_raw
3148 #define gen_op_lswi_le_user gen_op_lswi_user
3149 #define gen_op_lswi_le_kernel gen_op_lswi_kernel
3150 #define gen_op_lswi_le_hypv gen_op_lswi_hypv
3151 #define gen_op_lswi_le_64_raw gen_op_lswi_raw
3152 #define gen_op_lswi_le_64_user gen_op_lswi_user
3153 #define gen_op_lswi_le_64_kernel gen_op_lswi_kernel
3154 #define gen_op_lswi_le_64_hypv gen_op_lswi_hypv
3155 static GenOpFunc1 *gen_op_lswi[NB_MEM_FUNCS] = {
3156 GEN_MEM_FUNCS(lswi),
3158 #define gen_op_lswx_le_raw gen_op_lswx_raw
3159 #define gen_op_lswx_le_user gen_op_lswx_user
3160 #define gen_op_lswx_le_kernel gen_op_lswx_kernel
3161 #define gen_op_lswx_le_hypv gen_op_lswx_hypv
3162 #define gen_op_lswx_le_64_raw gen_op_lswx_raw
3163 #define gen_op_lswx_le_64_user gen_op_lswx_user
3164 #define gen_op_lswx_le_64_kernel gen_op_lswx_kernel
3165 #define gen_op_lswx_le_64_hypv gen_op_lswx_hypv
3166 static GenOpFunc3 *gen_op_lswx[NB_MEM_FUNCS] = {
3167 GEN_MEM_FUNCS(lswx),
3169 #define gen_op_stsw_le_raw gen_op_stsw_raw
3170 #define gen_op_stsw_le_user gen_op_stsw_user
3171 #define gen_op_stsw_le_kernel gen_op_stsw_kernel
3172 #define gen_op_stsw_le_hypv gen_op_stsw_hypv
3173 #define gen_op_stsw_le_64_raw gen_op_stsw_raw
3174 #define gen_op_stsw_le_64_user gen_op_stsw_user
3175 #define gen_op_stsw_le_64_kernel gen_op_stsw_kernel
3176 #define gen_op_stsw_le_64_hypv gen_op_stsw_hypv
3177 static GenOpFunc1 *gen_op_stsw[NB_MEM_FUNCS] = {
3178 GEN_MEM_FUNCS(stsw),
3182 /* PowerPC32 specification says we must generate an exception if
3183 * rA is in the range of registers to be loaded.
3184 * In an other hand, IBM says this is valid, but rA won't be loaded.
3185 * For now, I'll follow the spec...
3187 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING)
3189 int nb = NB(ctx->opcode);
3190 int start = rD(ctx->opcode);
3191 int ra = rA(ctx->opcode);
3197 if (unlikely(((start + nr) > 32 &&
3198 start <= ra && (start + nr - 32) > ra) ||
3199 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
3200 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3201 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX);
3204 /* NIP cannot be restored if the memory exception comes from an helper */
3205 gen_update_nip(ctx, ctx->nip - 4);
3206 gen_addr_register(cpu_T[0], ctx);
3207 tcg_gen_movi_tl(cpu_T[1], nb);
3208 op_ldsts(lswi, start);
3212 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING)
3214 int ra = rA(ctx->opcode);
3215 int rb = rB(ctx->opcode);
3217 /* NIP cannot be restored if the memory exception comes from an helper */
3218 gen_update_nip(ctx, ctx->nip - 4);
3219 gen_addr_reg_index(cpu_T[0], ctx);
3223 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
3224 op_ldstsx(lswx, rD(ctx->opcode), ra, rb);
3228 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING)
3230 int nb = NB(ctx->opcode);
3232 /* NIP cannot be restored if the memory exception comes from an helper */
3233 gen_update_nip(ctx, ctx->nip - 4);
3234 gen_addr_register(cpu_T[0], ctx);
3237 tcg_gen_movi_tl(cpu_T[1], nb);
3238 op_ldsts(stsw, rS(ctx->opcode));
3242 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING)
3244 /* NIP cannot be restored if the memory exception comes from an helper */
3245 gen_update_nip(ctx, ctx->nip - 4);
3246 gen_addr_reg_index(cpu_T[0], ctx);
3247 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
3248 op_ldsts(stsw, rS(ctx->opcode));
3251 /*** Memory synchronisation ***/
3253 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO)
3258 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM)
3263 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
3264 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
3265 static GenOpFunc *gen_op_lwarx[NB_MEM_FUNCS] = {
3266 GEN_MEM_FUNCS(lwarx),
3268 static GenOpFunc *gen_op_stwcx[NB_MEM_FUNCS] = {
3269 GEN_MEM_FUNCS(stwcx),
3273 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES)
3275 /* NIP cannot be restored if the memory exception comes from an helper */
3276 gen_update_nip(ctx, ctx->nip - 4);
3277 gen_addr_reg_index(cpu_T[0], ctx);
3279 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]);
3283 GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES)
3285 /* NIP cannot be restored if the memory exception comes from an helper */
3286 gen_update_nip(ctx, ctx->nip - 4);
3287 gen_addr_reg_index(cpu_T[0], ctx);
3288 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
3292 #if defined(TARGET_PPC64)
3293 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
3294 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
3295 static GenOpFunc *gen_op_ldarx[NB_MEM_FUNCS] = {
3296 GEN_MEM_FUNCS(ldarx),
3298 static GenOpFunc *gen_op_stdcx[NB_MEM_FUNCS] = {
3299 GEN_MEM_FUNCS(stdcx),
3303 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B)
3305 /* NIP cannot be restored if the memory exception comes from an helper */
3306 gen_update_nip(ctx, ctx->nip - 4);
3307 gen_addr_reg_index(cpu_T[0], ctx);
3309 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]);
3313 GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B)
3315 /* NIP cannot be restored if the memory exception comes from an helper */
3316 gen_update_nip(ctx, ctx->nip - 4);
3317 gen_addr_reg_index(cpu_T[0], ctx);
3318 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
3321 #endif /* defined(TARGET_PPC64) */
3324 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC)
3329 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT)
3331 /* Stop translation, as the CPU is supposed to sleep from now */
3333 GEN_EXCP(ctx, EXCP_HLT, 1);
3336 /*** Floating-point load ***/
3337 #define GEN_LDF(width, opc, type) \
3338 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3340 if (unlikely(!ctx->fpu_enabled)) { \
3341 GEN_EXCP_NO_FP(ctx); \
3344 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3345 op_ldst(l##width); \
3346 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3349 #define GEN_LDUF(width, opc, type) \
3350 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3352 if (unlikely(!ctx->fpu_enabled)) { \
3353 GEN_EXCP_NO_FP(ctx); \
3356 if (unlikely(rA(ctx->opcode) == 0)) { \
3357 GEN_EXCP_INVAL(ctx); \
3360 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3361 op_ldst(l##width); \
3362 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3363 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3366 #define GEN_LDUXF(width, opc, type) \
3367 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3369 if (unlikely(!ctx->fpu_enabled)) { \
3370 GEN_EXCP_NO_FP(ctx); \
3373 if (unlikely(rA(ctx->opcode) == 0)) { \
3374 GEN_EXCP_INVAL(ctx); \
3377 gen_addr_reg_index(cpu_T[0], ctx); \
3378 op_ldst(l##width); \
3379 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3380 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3383 #define GEN_LDXF(width, opc2, opc3, type) \
3384 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3386 if (unlikely(!ctx->fpu_enabled)) { \
3387 GEN_EXCP_NO_FP(ctx); \
3390 gen_addr_reg_index(cpu_T[0], ctx); \
3391 op_ldst(l##width); \
3392 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3395 #define GEN_LDFS(width, op, type) \
3396 OP_LD_TABLE(width); \
3397 GEN_LDF(width, op | 0x20, type); \
3398 GEN_LDUF(width, op | 0x21, type); \
3399 GEN_LDUXF(width, op | 0x01, type); \
3400 GEN_LDXF(width, 0x17, op | 0x00, type)
3402 /* lfd lfdu lfdux lfdx */
3403 GEN_LDFS(fd, 0x12, PPC_FLOAT);
3404 /* lfs lfsu lfsux lfsx */
3405 GEN_LDFS(fs, 0x10, PPC_FLOAT);
3407 /*** Floating-point store ***/
3408 #define GEN_STF(width, opc, type) \
3409 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3411 if (unlikely(!ctx->fpu_enabled)) { \
3412 GEN_EXCP_NO_FP(ctx); \
3415 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3416 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3417 op_ldst(st##width); \
3420 #define GEN_STUF(width, opc, type) \
3421 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3423 if (unlikely(!ctx->fpu_enabled)) { \
3424 GEN_EXCP_NO_FP(ctx); \
3427 if (unlikely(rA(ctx->opcode) == 0)) { \
3428 GEN_EXCP_INVAL(ctx); \
3431 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3432 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3433 op_ldst(st##width); \
3434 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3437 #define GEN_STUXF(width, opc, type) \
3438 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3440 if (unlikely(!ctx->fpu_enabled)) { \
3441 GEN_EXCP_NO_FP(ctx); \
3444 if (unlikely(rA(ctx->opcode) == 0)) { \
3445 GEN_EXCP_INVAL(ctx); \
3448 gen_addr_reg_index(cpu_T[0], ctx); \
3449 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3450 op_ldst(st##width); \
3451 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3454 #define GEN_STXF(width, opc2, opc3, type) \
3455 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3457 if (unlikely(!ctx->fpu_enabled)) { \
3458 GEN_EXCP_NO_FP(ctx); \
3461 gen_addr_reg_index(cpu_T[0], ctx); \
3462 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3463 op_ldst(st##width); \
3466 #define GEN_STFS(width, op, type) \
3467 OP_ST_TABLE(width); \
3468 GEN_STF(width, op | 0x20, type); \
3469 GEN_STUF(width, op | 0x21, type); \
3470 GEN_STUXF(width, op | 0x01, type); \
3471 GEN_STXF(width, 0x17, op | 0x00, type)
3473 /* stfd stfdu stfdux stfdx */
3474 GEN_STFS(fd, 0x16, PPC_FLOAT);
3475 /* stfs stfsu stfsux stfsx */
3476 GEN_STFS(fs, 0x14, PPC_FLOAT);
3481 GEN_STXF(fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
3484 static always_inline void gen_goto_tb (DisasContext *ctx, int n,
3487 TranslationBlock *tb;
3489 #if defined(TARGET_PPC64)
3491 dest = (uint32_t) dest;
3493 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
3494 likely(!ctx->singlestep_enabled)) {
3496 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3497 tcg_gen_exit_tb((long)tb + n);
3499 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3500 if (unlikely(ctx->singlestep_enabled)) {
3501 if ((ctx->singlestep_enabled &
3502 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
3503 ctx->exception == POWERPC_EXCP_BRANCH) {
3504 target_ulong tmp = ctx->nip;
3506 GEN_EXCP(ctx, POWERPC_EXCP_TRACE, 0);
3509 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
3510 gen_update_nip(ctx, dest);
3518 static always_inline void gen_setlr (DisasContext *ctx, target_ulong nip)
3520 #if defined(TARGET_PPC64)
3521 if (ctx->sf_mode == 0)
3522 tcg_gen_movi_tl(cpu_lr, (uint32_t)nip);
3525 tcg_gen_movi_tl(cpu_lr, nip);
3529 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3531 target_ulong li, target;
3533 ctx->exception = POWERPC_EXCP_BRANCH;
3534 /* sign extend LI */
3535 #if defined(TARGET_PPC64)
3537 li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
3540 li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
3541 if (likely(AA(ctx->opcode) == 0))
3542 target = ctx->nip + li - 4;
3545 if (LK(ctx->opcode))
3546 gen_setlr(ctx, ctx->nip);
3547 gen_goto_tb(ctx, 0, target);
3554 static always_inline void gen_bcond (DisasContext *ctx, int type)
3556 uint32_t bo = BO(ctx->opcode);
3557 int l1 = gen_new_label();
3560 ctx->exception = POWERPC_EXCP_BRANCH;
3561 if (type == BCOND_LR || type == BCOND_CTR) {
3562 target = tcg_temp_local_new(TCG_TYPE_TL);
3563 if (type == BCOND_CTR)
3564 tcg_gen_mov_tl(target, cpu_ctr);
3566 tcg_gen_mov_tl(target, cpu_lr);
3568 if (LK(ctx->opcode))
3569 gen_setlr(ctx, ctx->nip);
3570 l1 = gen_new_label();
3571 if ((bo & 0x4) == 0) {
3572 /* Decrement and test CTR */
3573 TCGv temp = tcg_temp_new(TCG_TYPE_TL);
3574 if (unlikely(type == BCOND_CTR)) {
3575 GEN_EXCP_INVAL(ctx);
3578 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3579 #if defined(TARGET_PPC64)
3581 tcg_gen_ext32u_tl(temp, cpu_ctr);
3584 tcg_gen_mov_tl(temp, cpu_ctr);
3586 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3588 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3591 if ((bo & 0x10) == 0) {
3593 uint32_t bi = BI(ctx->opcode);
3594 uint32_t mask = 1 << (3 - (bi & 0x03));
3595 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3598 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3599 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3601 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3602 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
3605 if (type == BCOND_IM) {
3607 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3608 if (likely(AA(ctx->opcode) == 0)) {
3609 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3611 gen_goto_tb(ctx, 0, li);
3614 gen_goto_tb(ctx, 1, ctx->nip);
3616 #if defined(TARGET_PPC64)
3617 if (!(ctx->sf_mode))
3618 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3621 tcg_gen_andi_tl(cpu_nip, target, ~3);
3624 #if defined(TARGET_PPC64)
3625 if (!(ctx->sf_mode))
3626 tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip);
3629 tcg_gen_movi_tl(cpu_nip, ctx->nip);
3634 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3636 gen_bcond(ctx, BCOND_IM);
3639 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
3641 gen_bcond(ctx, BCOND_CTR);
3644 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
3646 gen_bcond(ctx, BCOND_LR);
3649 /*** Condition register logical ***/
3650 #define GEN_CRLOGIC(name, tcg_op, opc) \
3651 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3655 TCGv temp1, temp2; \
3656 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3657 temp1 = tcg_temp_new(TCG_TYPE_I32); \
3659 tcg_gen_shri_i32(temp1, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3661 tcg_gen_shli_i32(temp1, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3663 tcg_gen_mov_i32(temp1, cpu_crf[crbA(ctx->opcode) >> 2]); \
3664 temp2 = tcg_temp_new(TCG_TYPE_I32); \
3665 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3667 tcg_gen_shri_i32(temp2, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3669 tcg_gen_shli_i32(temp2, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3671 tcg_gen_mov_i32(temp2, cpu_crf[crbB(ctx->opcode) >> 2]); \
3672 tcg_op(temp1, temp1, temp2); \
3673 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3674 tcg_gen_andi_i32(temp1, temp1, bitmask); \
3675 tcg_gen_andi_i32(temp2, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3676 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], temp1, temp2); \
3677 tcg_temp_free(temp1); \
3678 tcg_temp_free(temp2); \
3682 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
3684 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
3686 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
3688 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
3690 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
3692 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
3694 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
3696 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
3698 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
3700 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
3703 /*** System linkage ***/
3704 /* rfi (supervisor only) */
3705 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
3707 #if defined(CONFIG_USER_ONLY)
3708 GEN_EXCP_PRIVOPC(ctx);
3710 /* Restore CPU state */
3711 if (unlikely(!ctx->supervisor)) {
3712 GEN_EXCP_PRIVOPC(ctx);
3720 #if defined(TARGET_PPC64)
3721 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B)
3723 #if defined(CONFIG_USER_ONLY)
3724 GEN_EXCP_PRIVOPC(ctx);
3726 /* Restore CPU state */
3727 if (unlikely(!ctx->supervisor)) {
3728 GEN_EXCP_PRIVOPC(ctx);
3736 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H)
3738 #if defined(CONFIG_USER_ONLY)
3739 GEN_EXCP_PRIVOPC(ctx);
3741 /* Restore CPU state */
3742 if (unlikely(ctx->supervisor <= 1)) {
3743 GEN_EXCP_PRIVOPC(ctx);
3753 #if defined(CONFIG_USER_ONLY)
3754 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3756 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3758 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW)
3762 lev = (ctx->opcode >> 5) & 0x7F;
3763 GEN_EXCP(ctx, POWERPC_SYSCALL, lev);
3768 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
3770 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3771 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3772 /* Update the nip since this might generate a trap exception */
3773 gen_update_nip(ctx, ctx->nip);
3774 gen_op_tw(TO(ctx->opcode));
3778 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3780 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3781 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
3782 /* Update the nip since this might generate a trap exception */
3783 gen_update_nip(ctx, ctx->nip);
3784 gen_op_tw(TO(ctx->opcode));
3787 #if defined(TARGET_PPC64)
3789 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B)
3791 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3792 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3793 /* Update the nip since this might generate a trap exception */
3794 gen_update_nip(ctx, ctx->nip);
3795 gen_op_td(TO(ctx->opcode));
3799 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B)
3801 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3802 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
3803 /* Update the nip since this might generate a trap exception */
3804 gen_update_nip(ctx, ctx->nip);
3805 gen_op_td(TO(ctx->opcode));
3809 /*** Processor control ***/
3811 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
3813 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer);
3814 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA);
3815 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA));
3819 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
3823 if (likely(ctx->opcode & 0x00100000)) {
3824 crm = CRM(ctx->opcode);
3825 if (likely((crm ^ (crm - 1)) == 0)) {
3827 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
3830 tcg_gen_helper_1_0(helper_load_cr, cpu_gpr[rD(ctx->opcode)]);
3835 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
3837 #if defined(CONFIG_USER_ONLY)
3838 GEN_EXCP_PRIVREG(ctx);
3840 if (unlikely(!ctx->supervisor)) {
3841 GEN_EXCP_PRIVREG(ctx);
3845 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3850 #define SPR_NOACCESS ((void *)(-1UL))
3852 static void spr_noaccess (void *opaque, int sprn)
3854 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3855 printf("ERROR: try to access SPR %d !\n", sprn);
3857 #define SPR_NOACCESS (&spr_noaccess)
3861 static always_inline void gen_op_mfspr (DisasContext *ctx)
3863 void (*read_cb)(void *opaque, int sprn);
3864 uint32_t sprn = SPR(ctx->opcode);
3866 #if !defined(CONFIG_USER_ONLY)
3867 if (ctx->supervisor == 2)
3868 read_cb = ctx->spr_cb[sprn].hea_read;
3869 else if (ctx->supervisor)
3870 read_cb = ctx->spr_cb[sprn].oea_read;
3873 read_cb = ctx->spr_cb[sprn].uea_read;
3874 if (likely(read_cb != NULL)) {
3875 if (likely(read_cb != SPR_NOACCESS)) {
3876 (*read_cb)(ctx, sprn);
3877 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3879 /* Privilege exception */
3880 /* This is a hack to avoid warnings when running Linux:
3881 * this OS breaks the PowerPC virtualisation model,
3882 * allowing userland application to read the PVR
3884 if (sprn != SPR_PVR) {
3885 if (loglevel != 0) {
3886 fprintf(logfile, "Trying to read privileged spr %d %03x at "
3887 ADDRX "\n", sprn, sprn, ctx->nip);
3889 printf("Trying to read privileged spr %d %03x at " ADDRX "\n",
3890 sprn, sprn, ctx->nip);
3892 GEN_EXCP_PRIVREG(ctx);
3896 if (loglevel != 0) {
3897 fprintf(logfile, "Trying to read invalid spr %d %03x at "
3898 ADDRX "\n", sprn, sprn, ctx->nip);
3900 printf("Trying to read invalid spr %d %03x at " ADDRX "\n",
3901 sprn, sprn, ctx->nip);
3902 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3903 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3907 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC)
3913 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB)
3919 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC)
3923 crm = CRM(ctx->opcode);
3924 if (likely((ctx->opcode & 0x00100000) || (crm ^ (crm - 1)) == 0)) {
3926 tcg_gen_shri_i32(cpu_crf[7 - crn], cpu_gpr[rS(ctx->opcode)], crn * 4);
3927 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
3929 TCGv temp = tcg_const_tl(crm);
3930 tcg_gen_helper_0_2(helper_store_cr, cpu_gpr[rS(ctx->opcode)], temp);
3931 tcg_temp_free(temp);
3936 #if defined(TARGET_PPC64)
3937 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B)
3939 #if defined(CONFIG_USER_ONLY)
3940 GEN_EXCP_PRIVREG(ctx);
3942 if (unlikely(!ctx->supervisor)) {
3943 GEN_EXCP_PRIVREG(ctx);
3946 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3947 if (ctx->opcode & 0x00010000) {
3948 /* Special form that does not need any synchronisation */
3949 gen_op_update_riee();
3951 /* XXX: we need to update nip before the store
3952 * if we enter power saving mode, we will exit the loop
3953 * directly from ppc_store_msr
3955 gen_update_nip(ctx, ctx->nip);
3957 /* Must stop the translation as machine state (may have) changed */
3958 /* Note that mtmsr is not always defined as context-synchronizing */
3959 ctx->exception = POWERPC_EXCP_STOP;
3965 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
3967 #if defined(CONFIG_USER_ONLY)
3968 GEN_EXCP_PRIVREG(ctx);
3970 if (unlikely(!ctx->supervisor)) {
3971 GEN_EXCP_PRIVREG(ctx);
3974 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3975 if (ctx->opcode & 0x00010000) {
3976 /* Special form that does not need any synchronisation */
3977 gen_op_update_riee();
3979 /* XXX: we need to update nip before the store
3980 * if we enter power saving mode, we will exit the loop
3981 * directly from ppc_store_msr
3983 gen_update_nip(ctx, ctx->nip);
3984 #if defined(TARGET_PPC64)
3986 gen_op_store_msr_32();
3990 /* Must stop the translation as machine state (may have) changed */
3991 /* Note that mtmsrd is not always defined as context-synchronizing */
3992 ctx->exception = POWERPC_EXCP_STOP;
3998 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
4000 void (*write_cb)(void *opaque, int sprn);
4001 uint32_t sprn = SPR(ctx->opcode);
4003 #if !defined(CONFIG_USER_ONLY)
4004 if (ctx->supervisor == 2)
4005 write_cb = ctx->spr_cb[sprn].hea_write;
4006 else if (ctx->supervisor)
4007 write_cb = ctx->spr_cb[sprn].oea_write;
4010 write_cb = ctx->spr_cb[sprn].uea_write;
4011 if (likely(write_cb != NULL)) {
4012 if (likely(write_cb != SPR_NOACCESS)) {
4013 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4014 (*write_cb)(ctx, sprn);
4016 /* Privilege exception */
4017 if (loglevel != 0) {
4018 fprintf(logfile, "Trying to write privileged spr %d %03x at "
4019 ADDRX "\n", sprn, sprn, ctx->nip);
4021 printf("Trying to write privileged spr %d %03x at " ADDRX "\n",
4022 sprn, sprn, ctx->nip);
4023 GEN_EXCP_PRIVREG(ctx);
4027 if (loglevel != 0) {
4028 fprintf(logfile, "Trying to write invalid spr %d %03x at "
4029 ADDRX "\n", sprn, sprn, ctx->nip);
4031 printf("Trying to write invalid spr %d %03x at " ADDRX "\n",
4032 sprn, sprn, ctx->nip);
4033 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
4034 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
4038 /*** Cache management ***/
4040 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE)
4042 /* XXX: specification says this is treated as a load by the MMU */
4043 TCGv temp = tcg_temp_new(TCG_TYPE_TL);
4044 gen_addr_reg_index(temp, ctx);
4045 gen_qemu_ld8u(temp, temp, ctx->mem_idx);
4046 tcg_temp_free(temp);
4049 /* dcbi (Supervisor only) */
4050 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
4052 #if defined(CONFIG_USER_ONLY)
4053 GEN_EXCP_PRIVOPC(ctx);
4056 if (unlikely(!ctx->supervisor)) {
4057 GEN_EXCP_PRIVOPC(ctx);
4060 EA = tcg_temp_new(TCG_TYPE_TL);
4061 gen_addr_reg_index(EA, ctx);
4062 val = tcg_temp_new(TCG_TYPE_TL);
4063 /* XXX: specification says this should be treated as a store by the MMU */
4064 gen_qemu_ld8u(val, EA, ctx->mem_idx);
4065 gen_qemu_st8(val, EA, ctx->mem_idx);
4072 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE)
4074 /* XXX: specification say this is treated as a load by the MMU */
4075 TCGv temp = tcg_temp_new(TCG_TYPE_TL);
4076 gen_addr_reg_index(temp, ctx);
4077 gen_qemu_ld8u(temp, temp, ctx->mem_idx);
4078 tcg_temp_free(temp);
4082 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE)
4084 /* interpreted as no-op */
4085 /* XXX: specification say this is treated as a load by the MMU
4086 * but does not generate any exception
4091 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE)
4093 /* interpreted as no-op */
4094 /* XXX: specification say this is treated as a load by the MMU
4095 * but does not generate any exception
4100 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
4101 static GenOpFunc *gen_op_dcbz[4][NB_MEM_FUNCS] = {
4102 /* 32 bytes cache line size */
4104 #define gen_op_dcbz_l32_le_raw gen_op_dcbz_l32_raw
4105 #define gen_op_dcbz_l32_le_user gen_op_dcbz_l32_user
4106 #define gen_op_dcbz_l32_le_kernel gen_op_dcbz_l32_kernel
4107 #define gen_op_dcbz_l32_le_hypv gen_op_dcbz_l32_hypv
4108 #define gen_op_dcbz_l32_le_64_raw gen_op_dcbz_l32_64_raw
4109 #define gen_op_dcbz_l32_le_64_user gen_op_dcbz_l32_64_user
4110 #define gen_op_dcbz_l32_le_64_kernel gen_op_dcbz_l32_64_kernel
4111 #define gen_op_dcbz_l32_le_64_hypv gen_op_dcbz_l32_64_hypv
4112 GEN_MEM_FUNCS(dcbz_l32),
4114 /* 64 bytes cache line size */
4116 #define gen_op_dcbz_l64_le_raw gen_op_dcbz_l64_raw
4117 #define gen_op_dcbz_l64_le_user gen_op_dcbz_l64_user
4118 #define gen_op_dcbz_l64_le_kernel gen_op_dcbz_l64_kernel
4119 #define gen_op_dcbz_l64_le_hypv gen_op_dcbz_l64_hypv
4120 #define gen_op_dcbz_l64_le_64_raw gen_op_dcbz_l64_64_raw
4121 #define gen_op_dcbz_l64_le_64_user gen_op_dcbz_l64_64_user
4122 #define gen_op_dcbz_l64_le_64_kernel gen_op_dcbz_l64_64_kernel
4123 #define gen_op_dcbz_l64_le_64_hypv gen_op_dcbz_l64_64_hypv
4124 GEN_MEM_FUNCS(dcbz_l64),
4126 /* 128 bytes cache line size */
4128 #define gen_op_dcbz_l128_le_raw gen_op_dcbz_l128_raw
4129 #define gen_op_dcbz_l128_le_user gen_op_dcbz_l128_user
4130 #define gen_op_dcbz_l128_le_kernel gen_op_dcbz_l128_kernel
4131 #define gen_op_dcbz_l128_le_hypv gen_op_dcbz_l128_hypv
4132 #define gen_op_dcbz_l128_le_64_raw gen_op_dcbz_l128_64_raw
4133 #define gen_op_dcbz_l128_le_64_user gen_op_dcbz_l128_64_user
4134 #define gen_op_dcbz_l128_le_64_kernel gen_op_dcbz_l128_64_kernel
4135 #define gen_op_dcbz_l128_le_64_hypv gen_op_dcbz_l128_64_hypv
4136 GEN_MEM_FUNCS(dcbz_l128),
4138 /* tunable cache line size */
4140 #define gen_op_dcbz_le_raw gen_op_dcbz_raw
4141 #define gen_op_dcbz_le_user gen_op_dcbz_user
4142 #define gen_op_dcbz_le_kernel gen_op_dcbz_kernel
4143 #define gen_op_dcbz_le_hypv gen_op_dcbz_hypv
4144 #define gen_op_dcbz_le_64_raw gen_op_dcbz_64_raw
4145 #define gen_op_dcbz_le_64_user gen_op_dcbz_64_user
4146 #define gen_op_dcbz_le_64_kernel gen_op_dcbz_64_kernel
4147 #define gen_op_dcbz_le_64_hypv gen_op_dcbz_64_hypv
4148 GEN_MEM_FUNCS(dcbz),
4152 static always_inline void handler_dcbz (DisasContext *ctx,
4153 int dcache_line_size)
4157 switch (dcache_line_size) {
4174 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ)
4176 gen_addr_reg_index(cpu_T[0], ctx);
4177 handler_dcbz(ctx, ctx->dcache_line_size);
4178 gen_op_check_reservation();
4181 GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT)
4183 gen_addr_reg_index(cpu_T[0], ctx);
4184 if (ctx->opcode & 0x00200000)
4185 handler_dcbz(ctx, ctx->dcache_line_size);
4187 handler_dcbz(ctx, -1);
4188 gen_op_check_reservation();
4192 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
4193 #define gen_op_icbi_le_raw gen_op_icbi_raw
4194 #define gen_op_icbi_le_user gen_op_icbi_user
4195 #define gen_op_icbi_le_kernel gen_op_icbi_kernel
4196 #define gen_op_icbi_le_hypv gen_op_icbi_hypv
4197 #define gen_op_icbi_le_64_raw gen_op_icbi_64_raw
4198 #define gen_op_icbi_le_64_user gen_op_icbi_64_user
4199 #define gen_op_icbi_le_64_kernel gen_op_icbi_64_kernel
4200 #define gen_op_icbi_le_64_hypv gen_op_icbi_64_hypv
4201 static GenOpFunc *gen_op_icbi[NB_MEM_FUNCS] = {
4202 GEN_MEM_FUNCS(icbi),
4205 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI)
4207 /* NIP cannot be restored if the memory exception comes from an helper */
4208 gen_update_nip(ctx, ctx->nip - 4);
4209 gen_addr_reg_index(cpu_T[0], ctx);
4215 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA)
4217 /* interpreted as no-op */
4218 /* XXX: specification say this is treated as a store by the MMU
4219 * but does not generate any exception
4223 /*** Segment register manipulation ***/
4224 /* Supervisor only: */
4226 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
4228 #if defined(CONFIG_USER_ONLY)
4229 GEN_EXCP_PRIVREG(ctx);
4231 if (unlikely(!ctx->supervisor)) {
4232 GEN_EXCP_PRIVREG(ctx);
4235 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4237 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4242 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
4244 #if defined(CONFIG_USER_ONLY)
4245 GEN_EXCP_PRIVREG(ctx);
4247 if (unlikely(!ctx->supervisor)) {
4248 GEN_EXCP_PRIVREG(ctx);
4251 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4254 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4259 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
4261 #if defined(CONFIG_USER_ONLY)
4262 GEN_EXCP_PRIVREG(ctx);
4264 if (unlikely(!ctx->supervisor)) {
4265 GEN_EXCP_PRIVREG(ctx);
4268 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4269 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4275 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
4277 #if defined(CONFIG_USER_ONLY)
4278 GEN_EXCP_PRIVREG(ctx);
4280 if (unlikely(!ctx->supervisor)) {
4281 GEN_EXCP_PRIVREG(ctx);
4284 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4285 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4291 #if defined(TARGET_PPC64)
4292 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4294 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B)
4296 #if defined(CONFIG_USER_ONLY)
4297 GEN_EXCP_PRIVREG(ctx);
4299 if (unlikely(!ctx->supervisor)) {
4300 GEN_EXCP_PRIVREG(ctx);
4303 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4305 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4310 GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4313 #if defined(CONFIG_USER_ONLY)
4314 GEN_EXCP_PRIVREG(ctx);
4316 if (unlikely(!ctx->supervisor)) {
4317 GEN_EXCP_PRIVREG(ctx);
4320 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4323 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4328 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B)
4330 #if defined(CONFIG_USER_ONLY)
4331 GEN_EXCP_PRIVREG(ctx);
4333 if (unlikely(!ctx->supervisor)) {
4334 GEN_EXCP_PRIVREG(ctx);
4337 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4338 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4344 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4347 #if defined(CONFIG_USER_ONLY)
4348 GEN_EXCP_PRIVREG(ctx);
4350 if (unlikely(!ctx->supervisor)) {
4351 GEN_EXCP_PRIVREG(ctx);
4354 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4355 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4360 #endif /* defined(TARGET_PPC64) */
4362 /*** Lookaside buffer management ***/
4363 /* Optional & supervisor only: */
4365 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
4367 #if defined(CONFIG_USER_ONLY)
4368 GEN_EXCP_PRIVOPC(ctx);
4370 if (unlikely(!ctx->supervisor)) {
4371 GEN_EXCP_PRIVOPC(ctx);
4379 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
4381 #if defined(CONFIG_USER_ONLY)
4382 GEN_EXCP_PRIVOPC(ctx);
4384 if (unlikely(!ctx->supervisor)) {
4385 GEN_EXCP_PRIVOPC(ctx);
4388 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4389 #if defined(TARGET_PPC64)
4399 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
4401 #if defined(CONFIG_USER_ONLY)
4402 GEN_EXCP_PRIVOPC(ctx);
4404 if (unlikely(!ctx->supervisor)) {
4405 GEN_EXCP_PRIVOPC(ctx);
4408 /* This has no effect: it should ensure that all previous
4409 * tlbie have completed
4415 #if defined(TARGET_PPC64)
4417 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI)
4419 #if defined(CONFIG_USER_ONLY)
4420 GEN_EXCP_PRIVOPC(ctx);
4422 if (unlikely(!ctx->supervisor)) {
4423 GEN_EXCP_PRIVOPC(ctx);
4431 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI)
4433 #if defined(CONFIG_USER_ONLY)
4434 GEN_EXCP_PRIVOPC(ctx);
4436 if (unlikely(!ctx->supervisor)) {
4437 GEN_EXCP_PRIVOPC(ctx);
4440 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4446 /*** External control ***/
4448 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
4449 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
4450 static GenOpFunc *gen_op_eciwx[NB_MEM_FUNCS] = {
4451 GEN_MEM_FUNCS(eciwx),
4453 static GenOpFunc *gen_op_ecowx[NB_MEM_FUNCS] = {
4454 GEN_MEM_FUNCS(ecowx),
4458 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
4460 /* Should check EAR[E] & alignment ! */
4461 gen_addr_reg_index(cpu_T[0], ctx);
4463 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4467 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN)
4469 /* Should check EAR[E] & alignment ! */
4470 gen_addr_reg_index(cpu_T[0], ctx);
4471 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
4475 /* PowerPC 601 specific instructions */
4477 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR)
4479 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4481 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4482 if (unlikely(Rc(ctx->opcode) != 0))
4483 gen_set_Rc0(ctx, cpu_T[0]);
4487 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR)
4489 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4490 gen_op_POWER_abso();
4491 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4492 if (unlikely(Rc(ctx->opcode) != 0))
4493 gen_set_Rc0(ctx, cpu_T[0]);
4497 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR)
4499 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4500 gen_op_POWER_clcs();
4501 /* Rc=1 sets CR0 to an undefined state */
4502 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4506 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR)
4508 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4509 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4511 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4512 if (unlikely(Rc(ctx->opcode) != 0))
4513 gen_set_Rc0(ctx, cpu_T[0]);
4517 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR)
4519 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4520 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4521 gen_op_POWER_divo();
4522 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4523 if (unlikely(Rc(ctx->opcode) != 0))
4524 gen_set_Rc0(ctx, cpu_T[0]);
4528 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR)
4530 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4531 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4532 gen_op_POWER_divs();
4533 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4534 if (unlikely(Rc(ctx->opcode) != 0))
4535 gen_set_Rc0(ctx, cpu_T[0]);
4538 /* divso - divso. */
4539 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR)
4541 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4542 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4543 gen_op_POWER_divso();
4544 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4545 if (unlikely(Rc(ctx->opcode) != 0))
4546 gen_set_Rc0(ctx, cpu_T[0]);
4550 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR)
4552 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4553 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4555 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4556 if (unlikely(Rc(ctx->opcode) != 0))
4557 gen_set_Rc0(ctx, cpu_T[0]);
4561 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR)
4563 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4564 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4565 gen_op_POWER_dozo();
4566 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4567 if (unlikely(Rc(ctx->opcode) != 0))
4568 gen_set_Rc0(ctx, cpu_T[0]);
4572 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4574 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4575 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
4577 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4580 /* As lscbx load from memory byte after byte, it's always endian safe.
4581 * Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
4583 #define op_POWER_lscbx(start, ra, rb) \
4584 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
4585 #define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
4586 #define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
4587 #define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
4588 #define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
4589 #define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
4590 #define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
4591 #define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
4592 #define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
4593 #define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
4594 #define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
4595 #define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
4596 #define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
4597 static GenOpFunc3 *gen_op_POWER_lscbx[NB_MEM_FUNCS] = {
4598 GEN_MEM_FUNCS(POWER_lscbx),
4601 /* lscbx - lscbx. */
4602 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
4604 int ra = rA(ctx->opcode);
4605 int rb = rB(ctx->opcode);
4607 gen_addr_reg_index(cpu_T[0], ctx);
4611 /* NIP cannot be restored if the memory exception comes from an helper */
4612 gen_update_nip(ctx, ctx->nip - 4);
4613 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
4614 tcg_gen_shri_tl(cpu_T[2], cpu_xer, XER_CMP);
4615 tcg_gen_andi_tl(cpu_T[2], cpu_T[2], 0xFF);
4616 op_POWER_lscbx(rD(ctx->opcode), ra, rb);
4617 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
4618 tcg_gen_or_tl(cpu_xer, cpu_xer, cpu_T[0]);
4619 if (unlikely(Rc(ctx->opcode) != 0))
4620 gen_set_Rc0(ctx, cpu_T[0]);
4623 /* maskg - maskg. */
4624 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR)
4626 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4627 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4628 gen_op_POWER_maskg();
4629 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4630 if (unlikely(Rc(ctx->opcode) != 0))
4631 gen_set_Rc0(ctx, cpu_T[0]);
4634 /* maskir - maskir. */
4635 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR)
4637 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4638 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
4639 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4640 gen_op_POWER_maskir();
4641 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4642 if (unlikely(Rc(ctx->opcode) != 0))
4643 gen_set_Rc0(ctx, cpu_T[0]);
4647 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR)
4649 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4650 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4652 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4653 if (unlikely(Rc(ctx->opcode) != 0))
4654 gen_set_Rc0(ctx, cpu_T[0]);
4658 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR)
4660 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4661 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4662 gen_op_POWER_mulo();
4663 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4664 if (unlikely(Rc(ctx->opcode) != 0))
4665 gen_set_Rc0(ctx, cpu_T[0]);
4669 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR)
4671 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4672 gen_op_POWER_nabs();
4673 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4674 if (unlikely(Rc(ctx->opcode) != 0))
4675 gen_set_Rc0(ctx, cpu_T[0]);
4678 /* nabso - nabso. */
4679 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR)
4681 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4682 gen_op_POWER_nabso();
4683 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4684 if (unlikely(Rc(ctx->opcode) != 0))
4685 gen_set_Rc0(ctx, cpu_T[0]);
4689 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4693 mb = MB(ctx->opcode);
4694 me = ME(ctx->opcode);
4695 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4696 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4697 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4698 gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me));
4699 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4700 if (unlikely(Rc(ctx->opcode) != 0))
4701 gen_set_Rc0(ctx, cpu_T[0]);
4705 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR)
4707 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4708 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4709 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4710 gen_op_POWER_rrib();
4711 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4712 if (unlikely(Rc(ctx->opcode) != 0))
4713 gen_set_Rc0(ctx, cpu_T[0]);
4717 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR)
4719 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4720 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4722 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4723 if (unlikely(Rc(ctx->opcode) != 0))
4724 gen_set_Rc0(ctx, cpu_T[0]);
4728 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR)
4730 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4731 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4732 gen_op_POWER_sleq();
4733 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4734 if (unlikely(Rc(ctx->opcode) != 0))
4735 gen_set_Rc0(ctx, cpu_T[0]);
4739 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR)
4741 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4742 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4744 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4745 if (unlikely(Rc(ctx->opcode) != 0))
4746 gen_set_Rc0(ctx, cpu_T[0]);
4749 /* slliq - slliq. */
4750 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR)
4752 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4753 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4754 gen_op_POWER_sleq();
4755 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4756 if (unlikely(Rc(ctx->opcode) != 0))
4757 gen_set_Rc0(ctx, cpu_T[0]);
4761 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR)
4763 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4764 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4765 gen_op_POWER_sllq();
4766 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4767 if (unlikely(Rc(ctx->opcode) != 0))
4768 gen_set_Rc0(ctx, cpu_T[0]);
4772 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
4774 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4775 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4777 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4778 if (unlikely(Rc(ctx->opcode) != 0))
4779 gen_set_Rc0(ctx, cpu_T[0]);
4782 /* sraiq - sraiq. */
4783 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
4785 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4786 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4787 gen_op_POWER_sraq();
4788 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4789 if (unlikely(Rc(ctx->opcode) != 0))
4790 gen_set_Rc0(ctx, cpu_T[0]);
4794 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR)
4796 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4797 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4798 gen_op_POWER_sraq();
4799 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4800 if (unlikely(Rc(ctx->opcode) != 0))
4801 gen_set_Rc0(ctx, cpu_T[0]);
4805 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR)
4807 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4808 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4810 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4811 if (unlikely(Rc(ctx->opcode) != 0))
4812 gen_set_Rc0(ctx, cpu_T[0]);
4816 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR)
4818 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4819 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4820 gen_op_POWER_srea();
4821 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4822 if (unlikely(Rc(ctx->opcode) != 0))
4823 gen_set_Rc0(ctx, cpu_T[0]);
4827 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR)
4829 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4830 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4831 gen_op_POWER_sreq();
4832 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4833 if (unlikely(Rc(ctx->opcode) != 0))
4834 gen_set_Rc0(ctx, cpu_T[0]);
4838 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR)
4840 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4841 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4843 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4844 if (unlikely(Rc(ctx->opcode) != 0))
4845 gen_set_Rc0(ctx, cpu_T[0]);
4849 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR)
4851 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4852 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4853 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4854 gen_op_POWER_srlq();
4855 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4856 if (unlikely(Rc(ctx->opcode) != 0))
4857 gen_set_Rc0(ctx, cpu_T[0]);
4861 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR)
4863 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4864 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4865 gen_op_POWER_srlq();
4866 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4867 if (unlikely(Rc(ctx->opcode) != 0))
4868 gen_set_Rc0(ctx, cpu_T[0]);
4872 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
4874 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4875 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4877 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4878 if (unlikely(Rc(ctx->opcode) != 0))
4879 gen_set_Rc0(ctx, cpu_T[0]);
4882 /* PowerPC 602 specific instructions */
4884 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC)
4887 GEN_EXCP_INVAL(ctx);
4891 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC)
4894 GEN_EXCP_INVAL(ctx);
4898 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
4900 #if defined(CONFIG_USER_ONLY)
4901 GEN_EXCP_PRIVOPC(ctx);
4903 if (unlikely(!ctx->supervisor)) {
4904 GEN_EXCP_PRIVOPC(ctx);
4907 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4909 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4913 /* 602 - 603 - G2 TLB management */
4915 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
4917 #if defined(CONFIG_USER_ONLY)
4918 GEN_EXCP_PRIVOPC(ctx);
4920 if (unlikely(!ctx->supervisor)) {
4921 GEN_EXCP_PRIVOPC(ctx);
4924 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4930 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
4932 #if defined(CONFIG_USER_ONLY)
4933 GEN_EXCP_PRIVOPC(ctx);
4935 if (unlikely(!ctx->supervisor)) {
4936 GEN_EXCP_PRIVOPC(ctx);
4939 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4944 /* 74xx TLB management */
4946 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB)
4948 #if defined(CONFIG_USER_ONLY)
4949 GEN_EXCP_PRIVOPC(ctx);
4951 if (unlikely(!ctx->supervisor)) {
4952 GEN_EXCP_PRIVOPC(ctx);
4955 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4956 gen_op_74xx_tlbld();
4961 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB)
4963 #if defined(CONFIG_USER_ONLY)
4964 GEN_EXCP_PRIVOPC(ctx);
4966 if (unlikely(!ctx->supervisor)) {
4967 GEN_EXCP_PRIVOPC(ctx);
4970 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4971 gen_op_74xx_tlbli();
4975 /* POWER instructions not in PowerPC 601 */
4977 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER)
4979 /* Cache line flush: implemented as no-op */
4983 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER)
4985 /* Cache line invalidate: privileged and treated as no-op */
4986 #if defined(CONFIG_USER_ONLY)
4987 GEN_EXCP_PRIVOPC(ctx);
4989 if (unlikely(!ctx->supervisor)) {
4990 GEN_EXCP_PRIVOPC(ctx);
4997 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER)
4999 /* Data cache line store: treated as no-op */
5002 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
5004 #if defined(CONFIG_USER_ONLY)
5005 GEN_EXCP_PRIVOPC(ctx);
5007 if (unlikely(!ctx->supervisor)) {
5008 GEN_EXCP_PRIVOPC(ctx);
5011 int ra = rA(ctx->opcode);
5012 int rd = rD(ctx->opcode);
5014 gen_addr_reg_index(cpu_T[0], ctx);
5015 gen_op_POWER_mfsri();
5016 tcg_gen_mov_tl(cpu_gpr[rd], cpu_T[0]);
5017 if (ra != 0 && ra != rd)
5018 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[1]);
5022 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
5024 #if defined(CONFIG_USER_ONLY)
5025 GEN_EXCP_PRIVOPC(ctx);
5027 if (unlikely(!ctx->supervisor)) {
5028 GEN_EXCP_PRIVOPC(ctx);
5031 gen_addr_reg_index(cpu_T[0], ctx);
5033 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5037 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER)
5039 #if defined(CONFIG_USER_ONLY)
5040 GEN_EXCP_PRIVOPC(ctx);
5042 if (unlikely(!ctx->supervisor)) {
5043 GEN_EXCP_PRIVOPC(ctx);
5046 gen_op_POWER_rfsvc();
5051 /* svc is not implemented for now */
5053 /* POWER2 specific instructions */
5054 /* Quad manipulation (load/store two floats at a time) */
5055 /* Original POWER2 is 32 bits only, define 64 bits ops as 32 bits ones */
5056 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
5057 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
5058 #define gen_op_POWER2_lfq_64_raw gen_op_POWER2_lfq_raw
5059 #define gen_op_POWER2_lfq_64_user gen_op_POWER2_lfq_user
5060 #define gen_op_POWER2_lfq_64_kernel gen_op_POWER2_lfq_kernel
5061 #define gen_op_POWER2_lfq_64_hypv gen_op_POWER2_lfq_hypv
5062 #define gen_op_POWER2_lfq_le_64_raw gen_op_POWER2_lfq_le_raw
5063 #define gen_op_POWER2_lfq_le_64_user gen_op_POWER2_lfq_le_user
5064 #define gen_op_POWER2_lfq_le_64_kernel gen_op_POWER2_lfq_le_kernel
5065 #define gen_op_POWER2_lfq_le_64_hypv gen_op_POWER2_lfq_le_hypv
5066 #define gen_op_POWER2_stfq_64_raw gen_op_POWER2_stfq_raw
5067 #define gen_op_POWER2_stfq_64_user gen_op_POWER2_stfq_user
5068 #define gen_op_POWER2_stfq_64_kernel gen_op_POWER2_stfq_kernel
5069 #define gen_op_POWER2_stfq_64_hypv gen_op_POWER2_stfq_hypv
5070 #define gen_op_POWER2_stfq_le_64_raw gen_op_POWER2_stfq_le_raw
5071 #define gen_op_POWER2_stfq_le_64_user gen_op_POWER2_stfq_le_user
5072 #define gen_op_POWER2_stfq_le_64_kernel gen_op_POWER2_stfq_le_kernel
5073 #define gen_op_POWER2_stfq_le_64_hypv gen_op_POWER2_stfq_le_hypv
5074 static GenOpFunc *gen_op_POWER2_lfq[NB_MEM_FUNCS] = {
5075 GEN_MEM_FUNCS(POWER2_lfq),
5077 static GenOpFunc *gen_op_POWER2_stfq[NB_MEM_FUNCS] = {
5078 GEN_MEM_FUNCS(POWER2_stfq),
5082 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5084 /* NIP cannot be restored if the memory exception comes from an helper */
5085 gen_update_nip(ctx, ctx->nip - 4);
5086 gen_addr_imm_index(cpu_T[0], ctx, 0);
5088 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5089 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5093 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5095 int ra = rA(ctx->opcode);
5097 /* NIP cannot be restored if the memory exception comes from an helper */
5098 gen_update_nip(ctx, ctx->nip - 4);
5099 gen_addr_imm_index(cpu_T[0], ctx, 0);
5101 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5102 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5104 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5108 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
5110 int ra = rA(ctx->opcode);
5112 /* NIP cannot be restored if the memory exception comes from an helper */
5113 gen_update_nip(ctx, ctx->nip - 4);
5114 gen_addr_reg_index(cpu_T[0], ctx);
5116 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5117 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5119 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5123 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
5125 /* NIP cannot be restored if the memory exception comes from an helper */
5126 gen_update_nip(ctx, ctx->nip - 4);
5127 gen_addr_reg_index(cpu_T[0], ctx);
5129 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5130 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5134 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5136 /* NIP cannot be restored if the memory exception comes from an helper */
5137 gen_update_nip(ctx, ctx->nip - 4);
5138 gen_addr_imm_index(cpu_T[0], ctx, 0);
5139 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5140 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5145 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5147 int ra = rA(ctx->opcode);
5149 /* NIP cannot be restored if the memory exception comes from an helper */
5150 gen_update_nip(ctx, ctx->nip - 4);
5151 gen_addr_imm_index(cpu_T[0], ctx, 0);
5152 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5153 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5156 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5160 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
5162 int ra = rA(ctx->opcode);
5164 /* NIP cannot be restored if the memory exception comes from an helper */
5165 gen_update_nip(ctx, ctx->nip - 4);
5166 gen_addr_reg_index(cpu_T[0], ctx);
5167 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5168 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5171 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5175 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
5177 /* NIP cannot be restored if the memory exception comes from an helper */
5178 gen_update_nip(ctx, ctx->nip - 4);
5179 gen_addr_reg_index(cpu_T[0], ctx);
5180 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5181 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5185 /* BookE specific instructions */
5186 /* XXX: not implemented on 440 ? */
5187 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI)
5190 GEN_EXCP_INVAL(ctx);
5193 /* XXX: not implemented on 440 ? */
5194 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA)
5196 #if defined(CONFIG_USER_ONLY)
5197 GEN_EXCP_PRIVOPC(ctx);
5199 if (unlikely(!ctx->supervisor)) {
5200 GEN_EXCP_PRIVOPC(ctx);
5203 gen_addr_reg_index(cpu_T[0], ctx);
5204 /* Use the same micro-ops as for tlbie */
5205 #if defined(TARGET_PPC64)
5214 /* All 405 MAC instructions are translated here */
5215 static always_inline void gen_405_mulladd_insn (DisasContext *ctx,
5217 int ra, int rb, int rt, int Rc)
5221 t0 = tcg_temp_local_new(TCG_TYPE_TL);
5222 t1 = tcg_temp_local_new(TCG_TYPE_TL);
5224 switch (opc3 & 0x0D) {
5226 /* macchw - macchw. - macchwo - macchwo. */
5227 /* macchws - macchws. - macchwso - macchwso. */
5228 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5229 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5230 /* mulchw - mulchw. */
5231 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5232 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5233 tcg_gen_ext16s_tl(t1, t1);
5236 /* macchwu - macchwu. - macchwuo - macchwuo. */
5237 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5238 /* mulchwu - mulchwu. */
5239 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5240 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5241 tcg_gen_ext16u_tl(t1, t1);
5244 /* machhw - machhw. - machhwo - machhwo. */
5245 /* machhws - machhws. - machhwso - machhwso. */
5246 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5247 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5248 /* mulhhw - mulhhw. */
5249 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5250 tcg_gen_ext16s_tl(t0, t0);
5251 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5252 tcg_gen_ext16s_tl(t1, t1);
5255 /* machhwu - machhwu. - machhwuo - machhwuo. */
5256 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5257 /* mulhhwu - mulhhwu. */
5258 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5259 tcg_gen_ext16u_tl(t0, t0);
5260 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5261 tcg_gen_ext16u_tl(t1, t1);
5264 /* maclhw - maclhw. - maclhwo - maclhwo. */
5265 /* maclhws - maclhws. - maclhwso - maclhwso. */
5266 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5267 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5268 /* mullhw - mullhw. */
5269 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5270 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
5273 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5274 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5275 /* mullhwu - mullhwu. */
5276 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5277 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
5281 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5282 tcg_gen_mul_tl(t1, t0, t1);
5284 /* nmultiply-and-accumulate (0x0E) */
5285 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5287 /* multiply-and-accumulate (0x0C) */
5288 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5292 /* Check overflow and/or saturate */
5293 int l1 = gen_new_label();
5296 /* Start with XER OV disabled, the most likely case */
5297 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
5301 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5302 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5303 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5304 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
5307 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5308 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5312 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
5315 tcg_gen_movi_tl(t0, UINT32_MAX);
5319 /* Check overflow */
5320 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
5323 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5326 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
5330 if (unlikely(Rc) != 0) {
5332 gen_set_Rc0(ctx, cpu_gpr[rt]);
5336 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5337 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5339 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5340 rD(ctx->opcode), Rc(ctx->opcode)); \
5343 /* macchw - macchw. */
5344 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
5345 /* macchwo - macchwo. */
5346 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
5347 /* macchws - macchws. */
5348 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
5349 /* macchwso - macchwso. */
5350 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
5351 /* macchwsu - macchwsu. */
5352 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
5353 /* macchwsuo - macchwsuo. */
5354 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
5355 /* macchwu - macchwu. */
5356 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
5357 /* macchwuo - macchwuo. */
5358 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
5359 /* machhw - machhw. */
5360 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
5361 /* machhwo - machhwo. */
5362 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
5363 /* machhws - machhws. */
5364 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
5365 /* machhwso - machhwso. */
5366 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
5367 /* machhwsu - machhwsu. */
5368 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
5369 /* machhwsuo - machhwsuo. */
5370 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
5371 /* machhwu - machhwu. */
5372 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
5373 /* machhwuo - machhwuo. */
5374 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
5375 /* maclhw - maclhw. */
5376 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
5377 /* maclhwo - maclhwo. */
5378 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
5379 /* maclhws - maclhws. */
5380 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
5381 /* maclhwso - maclhwso. */
5382 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
5383 /* maclhwu - maclhwu. */
5384 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
5385 /* maclhwuo - maclhwuo. */
5386 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
5387 /* maclhwsu - maclhwsu. */
5388 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
5389 /* maclhwsuo - maclhwsuo. */
5390 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
5391 /* nmacchw - nmacchw. */
5392 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
5393 /* nmacchwo - nmacchwo. */
5394 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
5395 /* nmacchws - nmacchws. */
5396 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
5397 /* nmacchwso - nmacchwso. */
5398 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
5399 /* nmachhw - nmachhw. */
5400 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
5401 /* nmachhwo - nmachhwo. */
5402 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
5403 /* nmachhws - nmachhws. */
5404 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
5405 /* nmachhwso - nmachhwso. */
5406 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
5407 /* nmaclhw - nmaclhw. */
5408 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
5409 /* nmaclhwo - nmaclhwo. */
5410 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
5411 /* nmaclhws - nmaclhws. */
5412 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
5413 /* nmaclhwso - nmaclhwso. */
5414 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
5416 /* mulchw - mulchw. */
5417 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
5418 /* mulchwu - mulchwu. */
5419 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
5420 /* mulhhw - mulhhw. */
5421 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
5422 /* mulhhwu - mulhhwu. */
5423 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
5424 /* mullhw - mullhw. */
5425 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
5426 /* mullhwu - mullhwu. */
5427 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
5430 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR)
5432 #if defined(CONFIG_USER_ONLY)
5433 GEN_EXCP_PRIVREG(ctx);
5435 uint32_t dcrn = SPR(ctx->opcode);
5437 if (unlikely(!ctx->supervisor)) {
5438 GEN_EXCP_PRIVREG(ctx);
5441 tcg_gen_movi_tl(cpu_T[0], dcrn);
5443 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5448 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR)
5450 #if defined(CONFIG_USER_ONLY)
5451 GEN_EXCP_PRIVREG(ctx);
5453 uint32_t dcrn = SPR(ctx->opcode);
5455 if (unlikely(!ctx->supervisor)) {
5456 GEN_EXCP_PRIVREG(ctx);
5459 tcg_gen_movi_tl(cpu_T[0], dcrn);
5460 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5466 /* XXX: not implemented on 440 ? */
5467 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX)
5469 #if defined(CONFIG_USER_ONLY)
5470 GEN_EXCP_PRIVREG(ctx);
5472 if (unlikely(!ctx->supervisor)) {
5473 GEN_EXCP_PRIVREG(ctx);
5476 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5478 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5479 /* Note: Rc update flag set leads to undefined state of Rc0 */
5484 /* XXX: not implemented on 440 ? */
5485 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX)
5487 #if defined(CONFIG_USER_ONLY)
5488 GEN_EXCP_PRIVREG(ctx);
5490 if (unlikely(!ctx->supervisor)) {
5491 GEN_EXCP_PRIVREG(ctx);
5494 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5495 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5497 /* Note: Rc update flag set leads to undefined state of Rc0 */
5501 /* mfdcrux (PPC 460) : user-mode access to DCR */
5502 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX)
5504 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5506 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5507 /* Note: Rc update flag set leads to undefined state of Rc0 */
5510 /* mtdcrux (PPC 460) : user-mode access to DCR */
5511 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX)
5513 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5514 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5516 /* Note: Rc update flag set leads to undefined state of Rc0 */
5520 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
5522 #if defined(CONFIG_USER_ONLY)
5523 GEN_EXCP_PRIVOPC(ctx);
5525 if (unlikely(!ctx->supervisor)) {
5526 GEN_EXCP_PRIVOPC(ctx);
5529 /* interpreted as no-op */
5534 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON)
5536 #if defined(CONFIG_USER_ONLY)
5537 GEN_EXCP_PRIVOPC(ctx);
5540 if (unlikely(!ctx->supervisor)) {
5541 GEN_EXCP_PRIVOPC(ctx);
5544 EA = tcg_temp_new(TCG_TYPE_TL);
5545 gen_addr_reg_index(EA, ctx);
5546 val = tcg_temp_new(TCG_TYPE_TL);
5547 gen_qemu_ld32u(val, EA, ctx->mem_idx);
5549 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5555 GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT)
5557 /* interpreted as no-op */
5558 /* XXX: specification say this is treated as a load by the MMU
5559 * but does not generate any exception
5564 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
5566 #if defined(CONFIG_USER_ONLY)
5567 GEN_EXCP_PRIVOPC(ctx);
5569 if (unlikely(!ctx->supervisor)) {
5570 GEN_EXCP_PRIVOPC(ctx);
5573 /* interpreted as no-op */
5578 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
5580 #if defined(CONFIG_USER_ONLY)
5581 GEN_EXCP_PRIVOPC(ctx);
5583 if (unlikely(!ctx->supervisor)) {
5584 GEN_EXCP_PRIVOPC(ctx);
5587 /* interpreted as no-op */
5591 /* rfci (supervisor only) */
5592 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP)
5594 #if defined(CONFIG_USER_ONLY)
5595 GEN_EXCP_PRIVOPC(ctx);
5597 if (unlikely(!ctx->supervisor)) {
5598 GEN_EXCP_PRIVOPC(ctx);
5601 /* Restore CPU state */
5607 GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE)
5609 #if defined(CONFIG_USER_ONLY)
5610 GEN_EXCP_PRIVOPC(ctx);
5612 if (unlikely(!ctx->supervisor)) {
5613 GEN_EXCP_PRIVOPC(ctx);
5616 /* Restore CPU state */
5622 /* BookE specific */
5623 /* XXX: not implemented on 440 ? */
5624 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI)
5626 #if defined(CONFIG_USER_ONLY)
5627 GEN_EXCP_PRIVOPC(ctx);
5629 if (unlikely(!ctx->supervisor)) {
5630 GEN_EXCP_PRIVOPC(ctx);
5633 /* Restore CPU state */
5639 /* XXX: not implemented on 440 ? */
5640 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI)
5642 #if defined(CONFIG_USER_ONLY)
5643 GEN_EXCP_PRIVOPC(ctx);
5645 if (unlikely(!ctx->supervisor)) {
5646 GEN_EXCP_PRIVOPC(ctx);
5649 /* Restore CPU state */
5655 /* TLB management - PowerPC 405 implementation */
5657 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
5659 #if defined(CONFIG_USER_ONLY)
5660 GEN_EXCP_PRIVOPC(ctx);
5662 if (unlikely(!ctx->supervisor)) {
5663 GEN_EXCP_PRIVOPC(ctx);
5666 switch (rB(ctx->opcode)) {
5668 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5669 gen_op_4xx_tlbre_hi();
5670 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5673 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5674 gen_op_4xx_tlbre_lo();
5675 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5678 GEN_EXCP_INVAL(ctx);
5684 /* tlbsx - tlbsx. */
5685 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB)
5687 #if defined(CONFIG_USER_ONLY)
5688 GEN_EXCP_PRIVOPC(ctx);
5690 if (unlikely(!ctx->supervisor)) {
5691 GEN_EXCP_PRIVOPC(ctx);
5694 gen_addr_reg_index(cpu_T[0], ctx);
5696 if (Rc(ctx->opcode))
5697 gen_op_4xx_tlbsx_check();
5698 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5703 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
5705 #if defined(CONFIG_USER_ONLY)
5706 GEN_EXCP_PRIVOPC(ctx);
5708 if (unlikely(!ctx->supervisor)) {
5709 GEN_EXCP_PRIVOPC(ctx);
5712 switch (rB(ctx->opcode)) {
5714 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5715 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5716 gen_op_4xx_tlbwe_hi();
5719 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5720 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5721 gen_op_4xx_tlbwe_lo();
5724 GEN_EXCP_INVAL(ctx);
5730 /* TLB management - PowerPC 440 implementation */
5732 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
5734 #if defined(CONFIG_USER_ONLY)
5735 GEN_EXCP_PRIVOPC(ctx);
5737 if (unlikely(!ctx->supervisor)) {
5738 GEN_EXCP_PRIVOPC(ctx);
5741 switch (rB(ctx->opcode)) {
5745 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5746 gen_op_440_tlbre(rB(ctx->opcode));
5747 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5750 GEN_EXCP_INVAL(ctx);
5756 /* tlbsx - tlbsx. */
5757 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE)
5759 #if defined(CONFIG_USER_ONLY)
5760 GEN_EXCP_PRIVOPC(ctx);
5762 if (unlikely(!ctx->supervisor)) {
5763 GEN_EXCP_PRIVOPC(ctx);
5766 gen_addr_reg_index(cpu_T[0], ctx);
5768 if (Rc(ctx->opcode))
5769 gen_op_4xx_tlbsx_check();
5770 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5775 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
5777 #if defined(CONFIG_USER_ONLY)
5778 GEN_EXCP_PRIVOPC(ctx);
5780 if (unlikely(!ctx->supervisor)) {
5781 GEN_EXCP_PRIVOPC(ctx);
5784 switch (rB(ctx->opcode)) {
5788 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5789 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5790 gen_op_440_tlbwe(rB(ctx->opcode));
5793 GEN_EXCP_INVAL(ctx);
5800 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE)
5802 #if defined(CONFIG_USER_ONLY)
5803 GEN_EXCP_PRIVOPC(ctx);
5805 if (unlikely(!ctx->supervisor)) {
5806 GEN_EXCP_PRIVOPC(ctx);
5809 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rD(ctx->opcode)]);
5811 /* Stop translation to have a chance to raise an exception
5812 * if we just set msr_ee to 1
5819 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE)
5821 #if defined(CONFIG_USER_ONLY)
5822 GEN_EXCP_PRIVOPC(ctx);
5824 if (unlikely(!ctx->supervisor)) {
5825 GEN_EXCP_PRIVOPC(ctx);
5828 tcg_gen_movi_tl(cpu_T[0], ctx->opcode & 0x00010000);
5830 /* Stop translation to have a chance to raise an exception
5831 * if we just set msr_ee to 1
5837 /* PowerPC 440 specific instructions */
5839 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC)
5841 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
5842 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
5844 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
5845 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
5846 tcg_gen_or_tl(cpu_xer, cpu_xer, cpu_T[0]);
5847 if (Rc(ctx->opcode)) {
5848 gen_op_440_dlmzb_update_Rc();
5849 tcg_gen_andi_i32(cpu_crf[0], cpu_T[0], 0xf);
5853 /* mbar replaces eieio on 440 */
5854 GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE)
5856 /* interpreted as no-op */
5859 /* msync replaces sync on 440 */
5860 GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE)
5862 /* interpreted as no-op */
5866 GEN_HANDLER2(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE)
5868 /* interpreted as no-op */
5869 /* XXX: specification say this is treated as a load by the MMU
5870 * but does not generate any exception
5874 /*** Altivec vector extension ***/
5875 /* Altivec registers moves */
5877 static always_inline void gen_load_avr(int t, int reg) {
5878 tcg_gen_mov_i64(cpu_AVRh[t], cpu_avrh[reg]);
5879 tcg_gen_mov_i64(cpu_AVRl[t], cpu_avrl[reg]);
5882 static always_inline void gen_store_avr(int reg, int t) {
5883 tcg_gen_mov_i64(cpu_avrh[reg], cpu_AVRh[t]);
5884 tcg_gen_mov_i64(cpu_avrl[reg], cpu_AVRl[t]);
5887 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5888 #define OP_VR_LD_TABLE(name) \
5889 static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5890 GEN_MEM_FUNCS(vr_l##name), \
5892 #define OP_VR_ST_TABLE(name) \
5893 static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5894 GEN_MEM_FUNCS(vr_st##name), \
5897 #define GEN_VR_LDX(name, opc2, opc3) \
5898 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5900 if (unlikely(!ctx->altivec_enabled)) { \
5901 GEN_EXCP_NO_VR(ctx); \
5904 gen_addr_reg_index(cpu_T[0], ctx); \
5905 op_vr_ldst(vr_l##name); \
5906 gen_store_avr(rD(ctx->opcode), 0); \
5909 #define GEN_VR_STX(name, opc2, opc3) \
5910 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5912 if (unlikely(!ctx->altivec_enabled)) { \
5913 GEN_EXCP_NO_VR(ctx); \
5916 gen_addr_reg_index(cpu_T[0], ctx); \
5917 gen_load_avr(0, rS(ctx->opcode)); \
5918 op_vr_ldst(vr_st##name); \
5922 GEN_VR_LDX(vx, 0x07, 0x03);
5923 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5924 #define gen_op_vr_lvxl gen_op_vr_lvx
5925 GEN_VR_LDX(vxl, 0x07, 0x0B);
5928 GEN_VR_STX(vx, 0x07, 0x07);
5929 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5930 #define gen_op_vr_stvxl gen_op_vr_stvx
5931 GEN_VR_STX(vxl, 0x07, 0x0F);
5933 /*** SPE extension ***/
5934 /* Register moves */
5936 static always_inline void gen_load_gpr64(TCGv t, int reg) {
5937 #if defined(TARGET_PPC64)
5938 tcg_gen_mov_i64(t, cpu_gpr[reg]);
5940 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
5944 static always_inline void gen_store_gpr64(int reg, TCGv t) {
5945 #if defined(TARGET_PPC64)
5946 tcg_gen_mov_i64(cpu_gpr[reg], t);
5948 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
5949 TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
5950 tcg_gen_shri_i64(tmp, t, 32);
5951 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
5956 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5957 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5959 if (Rc(ctx->opcode)) \
5965 /* Handler for undefined SPE opcodes */
5966 static always_inline void gen_speundef (DisasContext *ctx)
5968 GEN_EXCP_INVAL(ctx);
5971 /* SPE load and stores */
5972 static always_inline void gen_addr_spe_imm_index (TCGv EA, DisasContext *ctx, int sh)
5974 target_long simm = rB(ctx->opcode);
5976 if (rA(ctx->opcode) == 0)
5977 tcg_gen_movi_tl(EA, simm << sh);
5978 else if (likely(simm != 0))
5979 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm << sh);
5981 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
5984 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5985 #define OP_SPE_LD_TABLE(name) \
5986 static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5987 GEN_MEM_FUNCS(spe_l##name), \
5989 #define OP_SPE_ST_TABLE(name) \
5990 static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5991 GEN_MEM_FUNCS(spe_st##name), \
5994 #define GEN_SPE_LD(name, sh) \
5995 static always_inline void gen_evl##name (DisasContext *ctx) \
5997 if (unlikely(!ctx->spe_enabled)) { \
5998 GEN_EXCP_NO_AP(ctx); \
6001 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
6002 op_spe_ldst(spe_l##name); \
6003 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
6006 #define GEN_SPE_LDX(name) \
6007 static always_inline void gen_evl##name##x (DisasContext *ctx) \
6009 if (unlikely(!ctx->spe_enabled)) { \
6010 GEN_EXCP_NO_AP(ctx); \
6013 gen_addr_reg_index(cpu_T[0], ctx); \
6014 op_spe_ldst(spe_l##name); \
6015 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
6018 #define GEN_SPEOP_LD(name, sh) \
6019 OP_SPE_LD_TABLE(name); \
6020 GEN_SPE_LD(name, sh); \
6023 #define GEN_SPE_ST(name, sh) \
6024 static always_inline void gen_evst##name (DisasContext *ctx) \
6026 if (unlikely(!ctx->spe_enabled)) { \
6027 GEN_EXCP_NO_AP(ctx); \
6030 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
6031 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
6032 op_spe_ldst(spe_st##name); \
6035 #define GEN_SPE_STX(name) \
6036 static always_inline void gen_evst##name##x (DisasContext *ctx) \
6038 if (unlikely(!ctx->spe_enabled)) { \
6039 GEN_EXCP_NO_AP(ctx); \
6042 gen_addr_reg_index(cpu_T[0], ctx); \
6043 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
6044 op_spe_ldst(spe_st##name); \
6047 #define GEN_SPEOP_ST(name, sh) \
6048 OP_SPE_ST_TABLE(name); \
6049 GEN_SPE_ST(name, sh); \
6052 #define GEN_SPEOP_LDST(name, sh) \
6053 GEN_SPEOP_LD(name, sh); \
6054 GEN_SPEOP_ST(name, sh)
6056 /* SPE arithmetic and logic */
6057 #define GEN_SPEOP_ARITH2(name) \
6058 static always_inline void gen_##name (DisasContext *ctx) \
6060 if (unlikely(!ctx->spe_enabled)) { \
6061 GEN_EXCP_NO_AP(ctx); \
6064 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6065 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
6067 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6070 #define GEN_SPEOP_TCG_ARITH2(name, tcg_op) \
6071 static always_inline void gen_##name (DisasContext *ctx) \
6073 if (unlikely(!ctx->spe_enabled)) { \
6074 GEN_EXCP_NO_AP(ctx); \
6077 TCGv t0 = tcg_temp_new(TCG_TYPE_I64); \
6078 TCGv t1 = tcg_temp_new(TCG_TYPE_I64); \
6079 gen_load_gpr64(t0, rA(ctx->opcode)); \
6080 gen_load_gpr64(t1, rB(ctx->opcode)); \
6081 tcg_op(t0, t0, t1); \
6082 gen_store_gpr64(rD(ctx->opcode), t0); \
6083 tcg_temp_free(t0); \
6084 tcg_temp_free(t1); \
6087 #define GEN_SPEOP_ARITH1(name) \
6088 static always_inline void gen_##name (DisasContext *ctx) \
6090 if (unlikely(!ctx->spe_enabled)) { \
6091 GEN_EXCP_NO_AP(ctx); \
6094 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6096 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6099 #define GEN_SPEOP_COMP(name) \
6100 static always_inline void gen_##name (DisasContext *ctx) \
6102 if (unlikely(!ctx->spe_enabled)) { \
6103 GEN_EXCP_NO_AP(ctx); \
6106 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6107 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
6109 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf); \
6113 GEN_SPEOP_TCG_ARITH2(evand, tcg_gen_and_i64);
6114 GEN_SPEOP_TCG_ARITH2(evandc, tcg_gen_andc_i64);
6115 GEN_SPEOP_TCG_ARITH2(evxor, tcg_gen_xor_i64);
6116 GEN_SPEOP_TCG_ARITH2(evor, tcg_gen_or_i64);
6117 GEN_SPEOP_TCG_ARITH2(evnor, tcg_gen_nor_i64);
6118 GEN_SPEOP_TCG_ARITH2(eveqv, tcg_gen_eqv_i64);
6119 GEN_SPEOP_TCG_ARITH2(evorc, tcg_gen_orc_i64);
6120 GEN_SPEOP_TCG_ARITH2(evnand, tcg_gen_nand_i64);
6121 GEN_SPEOP_ARITH2(evsrwu);
6122 GEN_SPEOP_ARITH2(evsrws);
6123 GEN_SPEOP_ARITH2(evslw);
6124 GEN_SPEOP_ARITH2(evrlw);
6125 GEN_SPEOP_ARITH2(evmergehi);
6126 GEN_SPEOP_ARITH2(evmergelo);
6127 GEN_SPEOP_ARITH2(evmergehilo);
6128 GEN_SPEOP_ARITH2(evmergelohi);
6131 GEN_SPEOP_ARITH2(evaddw);
6132 GEN_SPEOP_ARITH2(evsubfw);
6133 GEN_SPEOP_ARITH1(evabs);
6134 GEN_SPEOP_ARITH1(evneg);
6135 GEN_SPEOP_ARITH1(evextsb);
6136 GEN_SPEOP_ARITH1(evextsh);
6137 GEN_SPEOP_ARITH1(evrndw);
6138 GEN_SPEOP_ARITH1(evcntlzw);
6139 GEN_SPEOP_ARITH1(evcntlsw);
6140 static always_inline void gen_brinc (DisasContext *ctx)
6142 /* Note: brinc is usable even if SPE is disabled */
6143 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
6144 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
6146 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
6149 #define GEN_SPEOP_ARITH_IMM2(name) \
6150 static always_inline void gen_##name##i (DisasContext *ctx) \
6152 if (unlikely(!ctx->spe_enabled)) { \
6153 GEN_EXCP_NO_AP(ctx); \
6156 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
6157 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
6159 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6162 #define GEN_SPEOP_LOGIC_IMM2(name) \
6163 static always_inline void gen_##name##i (DisasContext *ctx) \
6165 if (unlikely(!ctx->spe_enabled)) { \
6166 GEN_EXCP_NO_AP(ctx); \
6169 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6170 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
6172 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6175 GEN_SPEOP_ARITH_IMM2(evaddw);
6176 #define gen_evaddiw gen_evaddwi
6177 GEN_SPEOP_ARITH_IMM2(evsubfw);
6178 #define gen_evsubifw gen_evsubfwi
6179 GEN_SPEOP_LOGIC_IMM2(evslw);
6180 GEN_SPEOP_LOGIC_IMM2(evsrwu);
6181 #define gen_evsrwis gen_evsrwsi
6182 GEN_SPEOP_LOGIC_IMM2(evsrws);
6183 #define gen_evsrwiu gen_evsrwui
6184 GEN_SPEOP_LOGIC_IMM2(evrlw);
6186 static always_inline void gen_evsplati (DisasContext *ctx)
6188 int32_t imm = (int32_t)(rA(ctx->opcode) << 27) >> 27;
6190 gen_op_splatwi_T0_64(imm);
6191 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6194 static always_inline void gen_evsplatfi (DisasContext *ctx)
6196 uint32_t imm = rA(ctx->opcode) << 27;
6198 gen_op_splatwi_T0_64(imm);
6199 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6203 GEN_SPEOP_COMP(evcmpgtu);
6204 GEN_SPEOP_COMP(evcmpgts);
6205 GEN_SPEOP_COMP(evcmpltu);
6206 GEN_SPEOP_COMP(evcmplts);
6207 GEN_SPEOP_COMP(evcmpeq);
6209 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); ////
6210 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE);
6211 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE); ////
6212 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE);
6213 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE); ////
6214 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE); ////
6215 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE); ////
6216 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE); //
6217 GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE); ////
6218 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE); ////
6219 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE); ////
6220 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE); ////
6221 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE); ////
6222 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE); ////
6223 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE); ////
6224 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE);
6225 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE); ////
6226 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE);
6227 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE); //
6228 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE);
6229 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE); ////
6230 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE); ////
6231 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE); ////
6232 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE); ////
6233 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE); ////
6235 static always_inline void gen_evsel (DisasContext *ctx)
6237 if (unlikely(!ctx->spe_enabled)) {
6238 GEN_EXCP_NO_AP(ctx);
6241 tcg_gen_mov_i32(cpu_T[0], cpu_crf[ctx->opcode & 0x7]);
6242 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode));
6243 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode));
6245 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6248 GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE)
6252 GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE)
6256 GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE)
6260 GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE)
6265 /* Load and stores */
6266 GEN_SPEOP_LDST(dd, 3);
6267 GEN_SPEOP_LDST(dw, 3);
6268 GEN_SPEOP_LDST(dh, 3);
6269 GEN_SPEOP_LDST(whe, 2);
6270 GEN_SPEOP_LD(whou, 2);
6271 GEN_SPEOP_LD(whos, 2);
6272 GEN_SPEOP_ST(who, 2);
6274 #define _GEN_OP_SPE_STWWE(suffix) \
6275 static always_inline void gen_op_spe_stwwe_##suffix (void) \
6277 gen_op_srli32_T1_64(); \
6278 gen_op_spe_stwwo_##suffix(); \
6280 #define _GEN_OP_SPE_STWWE_LE(suffix) \
6281 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
6283 gen_op_srli32_T1_64(); \
6284 gen_op_spe_stwwo_le_##suffix(); \
6286 #if defined(TARGET_PPC64)
6287 #define GEN_OP_SPE_STWWE(suffix) \
6288 _GEN_OP_SPE_STWWE(suffix); \
6289 _GEN_OP_SPE_STWWE_LE(suffix); \
6290 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
6292 gen_op_srli32_T1_64(); \
6293 gen_op_spe_stwwo_64_##suffix(); \
6295 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
6297 gen_op_srli32_T1_64(); \
6298 gen_op_spe_stwwo_le_64_##suffix(); \
6301 #define GEN_OP_SPE_STWWE(suffix) \
6302 _GEN_OP_SPE_STWWE(suffix); \
6303 _GEN_OP_SPE_STWWE_LE(suffix)
6305 #if defined(CONFIG_USER_ONLY)
6306 GEN_OP_SPE_STWWE(raw);
6307 #else /* defined(CONFIG_USER_ONLY) */
6308 GEN_OP_SPE_STWWE(user);
6309 GEN_OP_SPE_STWWE(kernel);
6310 GEN_OP_SPE_STWWE(hypv);
6311 #endif /* defined(CONFIG_USER_ONLY) */
6312 GEN_SPEOP_ST(wwe, 2);
6313 GEN_SPEOP_ST(wwo, 2);
6315 #define GEN_SPE_LDSPLAT(name, op, suffix) \
6316 static always_inline void gen_op_spe_l##name##_##suffix (void) \
6318 gen_op_##op##_##suffix(); \
6319 gen_op_splatw_T1_64(); \
6322 #define GEN_OP_SPE_LHE(suffix) \
6323 static always_inline void gen_op_spe_lhe_##suffix (void) \
6325 gen_op_spe_lh_##suffix(); \
6326 gen_op_sli16_T1_64(); \
6329 #define GEN_OP_SPE_LHX(suffix) \
6330 static always_inline void gen_op_spe_lhx_##suffix (void) \
6332 gen_op_spe_lh_##suffix(); \
6333 gen_op_extsh_T1_64(); \
6336 #if defined(CONFIG_USER_ONLY)
6337 GEN_OP_SPE_LHE(raw);
6338 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, raw);
6339 GEN_OP_SPE_LHE(le_raw);
6340 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_raw);
6341 GEN_SPE_LDSPLAT(hhousplat, spe_lh, raw);
6342 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_raw);
6343 GEN_OP_SPE_LHX(raw);
6344 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, raw);
6345 GEN_OP_SPE_LHX(le_raw);
6346 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_raw);
6347 #if defined(TARGET_PPC64)
6348 GEN_OP_SPE_LHE(64_raw);
6349 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_raw);
6350 GEN_OP_SPE_LHE(le_64_raw);
6351 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_raw);
6352 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_raw);
6353 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_raw);
6354 GEN_OP_SPE_LHX(64_raw);
6355 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_raw);
6356 GEN_OP_SPE_LHX(le_64_raw);
6357 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_raw);
6360 GEN_OP_SPE_LHE(user);
6361 GEN_OP_SPE_LHE(kernel);
6362 GEN_OP_SPE_LHE(hypv);
6363 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, user);
6364 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel);
6365 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, hypv);
6366 GEN_OP_SPE_LHE(le_user);
6367 GEN_OP_SPE_LHE(le_kernel);
6368 GEN_OP_SPE_LHE(le_hypv);
6369 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_user);
6370 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel);
6371 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_hypv);
6372 GEN_SPE_LDSPLAT(hhousplat, spe_lh, user);
6373 GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel);
6374 GEN_SPE_LDSPLAT(hhousplat, spe_lh, hypv);
6375 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_user);
6376 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel);
6377 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_hypv);
6378 GEN_OP_SPE_LHX(user);
6379 GEN_OP_SPE_LHX(kernel);
6380 GEN_OP_SPE_LHX(hypv);
6381 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, user);
6382 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel);
6383 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, hypv);
6384 GEN_OP_SPE_LHX(le_user);
6385 GEN_OP_SPE_LHX(le_kernel);
6386 GEN_OP_SPE_LHX(le_hypv);
6387 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_user);
6388 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel);
6389 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_hypv);
6390 #if defined(TARGET_PPC64)
6391 GEN_OP_SPE_LHE(64_user);
6392 GEN_OP_SPE_LHE(64_kernel);
6393 GEN_OP_SPE_LHE(64_hypv);
6394 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_user);
6395 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
6396 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_hypv);
6397 GEN_OP_SPE_LHE(le_64_user);
6398 GEN_OP_SPE_LHE(le_64_kernel);
6399 GEN_OP_SPE_LHE(le_64_hypv);
6400 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_user);
6401 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel);
6402 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_hypv);
6403 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_user);
6404 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
6405 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_hypv);
6406 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_user);
6407 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel);
6408 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_hypv);
6409 GEN_OP_SPE_LHX(64_user);
6410 GEN_OP_SPE_LHX(64_kernel);
6411 GEN_OP_SPE_LHX(64_hypv);
6412 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_user);
6413 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
6414 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_hypv);
6415 GEN_OP_SPE_LHX(le_64_user);
6416 GEN_OP_SPE_LHX(le_64_kernel);
6417 GEN_OP_SPE_LHX(le_64_hypv);
6418 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_user);
6419 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel);
6420 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_hypv);
6423 GEN_SPEOP_LD(hhesplat, 1);
6424 GEN_SPEOP_LD(hhousplat, 1);
6425 GEN_SPEOP_LD(hhossplat, 1);
6426 GEN_SPEOP_LD(wwsplat, 2);
6427 GEN_SPEOP_LD(whsplat, 2);
6429 GEN_SPE(evlddx, evldd, 0x00, 0x0C, 0x00000000, PPC_SPE); //
6430 GEN_SPE(evldwx, evldw, 0x01, 0x0C, 0x00000000, PPC_SPE); //
6431 GEN_SPE(evldhx, evldh, 0x02, 0x0C, 0x00000000, PPC_SPE); //
6432 GEN_SPE(evlhhesplatx, evlhhesplat, 0x04, 0x0C, 0x00000000, PPC_SPE); //
6433 GEN_SPE(evlhhousplatx, evlhhousplat, 0x06, 0x0C, 0x00000000, PPC_SPE); //
6434 GEN_SPE(evlhhossplatx, evlhhossplat, 0x07, 0x0C, 0x00000000, PPC_SPE); //
6435 GEN_SPE(evlwhex, evlwhe, 0x08, 0x0C, 0x00000000, PPC_SPE); //
6436 GEN_SPE(evlwhoux, evlwhou, 0x0A, 0x0C, 0x00000000, PPC_SPE); //
6437 GEN_SPE(evlwhosx, evlwhos, 0x0B, 0x0C, 0x00000000, PPC_SPE); //
6438 GEN_SPE(evlwwsplatx, evlwwsplat, 0x0C, 0x0C, 0x00000000, PPC_SPE); //
6439 GEN_SPE(evlwhsplatx, evlwhsplat, 0x0E, 0x0C, 0x00000000, PPC_SPE); //
6440 GEN_SPE(evstddx, evstdd, 0x10, 0x0C, 0x00000000, PPC_SPE); //
6441 GEN_SPE(evstdwx, evstdw, 0x11, 0x0C, 0x00000000, PPC_SPE); //
6442 GEN_SPE(evstdhx, evstdh, 0x12, 0x0C, 0x00000000, PPC_SPE); //
6443 GEN_SPE(evstwhex, evstwhe, 0x18, 0x0C, 0x00000000, PPC_SPE); //
6444 GEN_SPE(evstwhox, evstwho, 0x1A, 0x0C, 0x00000000, PPC_SPE); //
6445 GEN_SPE(evstwwex, evstwwe, 0x1C, 0x0C, 0x00000000, PPC_SPE); //
6446 GEN_SPE(evstwwox, evstwwo, 0x1E, 0x0C, 0x00000000, PPC_SPE); //
6448 /* Multiply and add - TODO */
6450 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0x00000000, PPC_SPE);
6451 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0x00000000, PPC_SPE);
6452 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, PPC_SPE);
6453 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0x00000000, PPC_SPE);
6454 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, PPC_SPE);
6455 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0x00000000, PPC_SPE);
6456 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0x00000000, PPC_SPE);
6457 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0x00000000, PPC_SPE);
6458 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, PPC_SPE);
6459 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0x00000000, PPC_SPE);
6460 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, PPC_SPE);
6461 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0x00000000, PPC_SPE);
6463 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0x00000000, PPC_SPE);
6464 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, PPC_SPE);
6465 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, PPC_SPE);
6466 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0x00000000, PPC_SPE);
6467 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0x00000000, PPC_SPE);
6468 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE);
6469 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0x00000000, PPC_SPE);
6470 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0x00000000, PPC_SPE);
6471 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, PPC_SPE);
6472 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, PPC_SPE);
6473 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0x00000000, PPC_SPE);
6474 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0x00000000, PPC_SPE);
6475 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE);
6476 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0x00000000, PPC_SPE);
6478 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, PPC_SPE);
6479 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, PPC_SPE);
6480 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, PPC_SPE);
6481 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, PPC_SPE);
6482 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, PPC_SPE);
6483 GEN_SPE(evmra, speundef, 0x07, 0x13, 0x0000F800, PPC_SPE);
6485 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, PPC_SPE);
6486 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0x00000000, PPC_SPE);
6487 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, PPC_SPE);
6488 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0x00000000, PPC_SPE);
6489 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, PPC_SPE);
6490 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0x00000000, PPC_SPE);
6491 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, PPC_SPE);
6492 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0x00000000, PPC_SPE);
6493 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, PPC_SPE);
6494 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0x00000000, PPC_SPE);
6495 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, PPC_SPE);
6496 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0x00000000, PPC_SPE);
6498 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, PPC_SPE);
6499 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, PPC_SPE);
6500 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0x00000000, PPC_SPE);
6501 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE);
6502 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0x00000000, PPC_SPE);
6504 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, PPC_SPE);
6505 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0x00000000, PPC_SPE);
6506 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, PPC_SPE);
6507 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0x00000000, PPC_SPE);
6508 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, PPC_SPE);
6509 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0x00000000, PPC_SPE);
6510 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, PPC_SPE);
6511 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0x00000000, PPC_SPE);
6512 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, PPC_SPE);
6513 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0x00000000, PPC_SPE);
6514 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, PPC_SPE);
6515 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0x00000000, PPC_SPE);
6517 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, PPC_SPE);
6518 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, PPC_SPE);
6519 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0x00000000, PPC_SPE);
6520 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, PPC_SPE);
6521 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0x00000000, PPC_SPE);
6524 /*** SPE floating-point extension ***/
6525 #define GEN_SPEFPUOP_CONV(name) \
6526 static always_inline void gen_##name (DisasContext *ctx) \
6528 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
6530 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6533 /* Single precision floating-point vectors operations */
6535 GEN_SPEOP_ARITH2(evfsadd);
6536 GEN_SPEOP_ARITH2(evfssub);
6537 GEN_SPEOP_ARITH2(evfsmul);
6538 GEN_SPEOP_ARITH2(evfsdiv);
6539 GEN_SPEOP_ARITH1(evfsabs);
6540 GEN_SPEOP_ARITH1(evfsnabs);
6541 GEN_SPEOP_ARITH1(evfsneg);
6543 GEN_SPEFPUOP_CONV(evfscfui);
6544 GEN_SPEFPUOP_CONV(evfscfsi);
6545 GEN_SPEFPUOP_CONV(evfscfuf);
6546 GEN_SPEFPUOP_CONV(evfscfsf);
6547 GEN_SPEFPUOP_CONV(evfsctui);
6548 GEN_SPEFPUOP_CONV(evfsctsi);
6549 GEN_SPEFPUOP_CONV(evfsctuf);
6550 GEN_SPEFPUOP_CONV(evfsctsf);
6551 GEN_SPEFPUOP_CONV(evfsctuiz);
6552 GEN_SPEFPUOP_CONV(evfsctsiz);
6554 GEN_SPEOP_COMP(evfscmpgt);
6555 GEN_SPEOP_COMP(evfscmplt);
6556 GEN_SPEOP_COMP(evfscmpeq);
6557 GEN_SPEOP_COMP(evfststgt);
6558 GEN_SPEOP_COMP(evfststlt);
6559 GEN_SPEOP_COMP(evfststeq);
6561 /* Opcodes definitions */
6562 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); //
6563 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU); //
6564 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU); //
6565 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPEFPU); //
6566 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPEFPU); //
6567 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPEFPU); //
6568 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPEFPU); //
6569 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPEFPU); //
6570 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU); //
6571 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU); //
6572 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU); //
6573 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU); //
6574 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU); //
6575 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU); //
6577 /* Single precision floating-point operations */
6579 GEN_SPEOP_ARITH2(efsadd);
6580 GEN_SPEOP_ARITH2(efssub);
6581 GEN_SPEOP_ARITH2(efsmul);
6582 GEN_SPEOP_ARITH2(efsdiv);
6583 GEN_SPEOP_ARITH1(efsabs);
6584 GEN_SPEOP_ARITH1(efsnabs);
6585 GEN_SPEOP_ARITH1(efsneg);
6587 GEN_SPEFPUOP_CONV(efscfui);
6588 GEN_SPEFPUOP_CONV(efscfsi);
6589 GEN_SPEFPUOP_CONV(efscfuf);
6590 GEN_SPEFPUOP_CONV(efscfsf);
6591 GEN_SPEFPUOP_CONV(efsctui);
6592 GEN_SPEFPUOP_CONV(efsctsi);
6593 GEN_SPEFPUOP_CONV(efsctuf);
6594 GEN_SPEFPUOP_CONV(efsctsf);
6595 GEN_SPEFPUOP_CONV(efsctuiz);
6596 GEN_SPEFPUOP_CONV(efsctsiz);
6597 GEN_SPEFPUOP_CONV(efscfd);
6599 GEN_SPEOP_COMP(efscmpgt);
6600 GEN_SPEOP_COMP(efscmplt);
6601 GEN_SPEOP_COMP(efscmpeq);
6602 GEN_SPEOP_COMP(efststgt);
6603 GEN_SPEOP_COMP(efststlt);
6604 GEN_SPEOP_COMP(efststeq);
6606 /* Opcodes definitions */
6607 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, PPC_SPEFPU); //
6608 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU); //
6609 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU); //
6610 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPEFPU); //
6611 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPEFPU); //
6612 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPEFPU); //
6613 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPEFPU); //
6614 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPEFPU); //
6615 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU); //
6616 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU); //
6617 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU); //
6618 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU); //
6619 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU); //
6620 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU); //
6622 /* Double precision floating-point operations */
6624 GEN_SPEOP_ARITH2(efdadd);
6625 GEN_SPEOP_ARITH2(efdsub);
6626 GEN_SPEOP_ARITH2(efdmul);
6627 GEN_SPEOP_ARITH2(efddiv);
6628 GEN_SPEOP_ARITH1(efdabs);
6629 GEN_SPEOP_ARITH1(efdnabs);
6630 GEN_SPEOP_ARITH1(efdneg);
6633 GEN_SPEFPUOP_CONV(efdcfui);
6634 GEN_SPEFPUOP_CONV(efdcfsi);
6635 GEN_SPEFPUOP_CONV(efdcfuf);
6636 GEN_SPEFPUOP_CONV(efdcfsf);
6637 GEN_SPEFPUOP_CONV(efdctui);
6638 GEN_SPEFPUOP_CONV(efdctsi);
6639 GEN_SPEFPUOP_CONV(efdctuf);
6640 GEN_SPEFPUOP_CONV(efdctsf);
6641 GEN_SPEFPUOP_CONV(efdctuiz);
6642 GEN_SPEFPUOP_CONV(efdctsiz);
6643 GEN_SPEFPUOP_CONV(efdcfs);
6644 GEN_SPEFPUOP_CONV(efdcfuid);
6645 GEN_SPEFPUOP_CONV(efdcfsid);
6646 GEN_SPEFPUOP_CONV(efdctuidz);
6647 GEN_SPEFPUOP_CONV(efdctsidz);
6649 GEN_SPEOP_COMP(efdcmpgt);
6650 GEN_SPEOP_COMP(efdcmplt);
6651 GEN_SPEOP_COMP(efdcmpeq);
6652 GEN_SPEOP_COMP(efdtstgt);
6653 GEN_SPEOP_COMP(efdtstlt);
6654 GEN_SPEOP_COMP(efdtsteq);
6656 /* Opcodes definitions */
6657 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPEFPU); //
6658 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPEFPU); //
6659 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU); //
6660 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU); //
6661 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPEFPU); //
6662 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPEFPU); //
6663 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPEFPU); //
6664 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPEFPU); //
6665 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPEFPU); //
6666 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPEFPU); //
6667 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU); //
6668 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU); //
6669 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU); //
6670 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU); //
6671 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU); //
6672 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU); //
6674 /* End opcode list */
6675 GEN_OPCODE_MARK(end);
6677 #include "translate_init.c"
6678 #include "helper_regs.h"
6680 /*****************************************************************************/
6681 /* Misc PowerPC helpers */
6682 void cpu_dump_state (CPUState *env, FILE *f,
6683 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6691 cpu_fprintf(f, "NIP " ADDRX " LR " ADDRX " CTR " ADDRX " XER %08x\n",
6692 env->nip, env->lr, env->ctr, env->xer);
6693 cpu_fprintf(f, "MSR " ADDRX " HID0 " ADDRX " HF " ADDRX " idx %d\n",
6694 env->msr, env->spr[SPR_HID0], env->hflags, env->mmu_idx);
6695 #if !defined(NO_TIMER_DUMP)
6696 cpu_fprintf(f, "TB %08x %08x "
6697 #if !defined(CONFIG_USER_ONLY)
6701 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
6702 #if !defined(CONFIG_USER_ONLY)
6703 , cpu_ppc_load_decr(env)
6707 for (i = 0; i < 32; i++) {
6708 if ((i & (RGPL - 1)) == 0)
6709 cpu_fprintf(f, "GPR%02d", i);
6710 cpu_fprintf(f, " " REGX, ppc_dump_gpr(env, i));
6711 if ((i & (RGPL - 1)) == (RGPL - 1))
6712 cpu_fprintf(f, "\n");
6714 cpu_fprintf(f, "CR ");
6715 for (i = 0; i < 8; i++)
6716 cpu_fprintf(f, "%01x", env->crf[i]);
6717 cpu_fprintf(f, " [");
6718 for (i = 0; i < 8; i++) {
6720 if (env->crf[i] & 0x08)
6722 else if (env->crf[i] & 0x04)
6724 else if (env->crf[i] & 0x02)
6726 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
6728 cpu_fprintf(f, " ] RES " ADDRX "\n", env->reserve);
6729 for (i = 0; i < 32; i++) {
6730 if ((i & (RFPL - 1)) == 0)
6731 cpu_fprintf(f, "FPR%02d", i);
6732 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
6733 if ((i & (RFPL - 1)) == (RFPL - 1))
6734 cpu_fprintf(f, "\n");
6736 #if !defined(CONFIG_USER_ONLY)
6737 cpu_fprintf(f, "SRR0 " ADDRX " SRR1 " ADDRX " SDR1 " ADDRX "\n",
6738 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
6745 void cpu_dump_statistics (CPUState *env, FILE*f,
6746 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6749 #if defined(DO_PPC_STATISTICS)
6750 opc_handler_t **t1, **t2, **t3, *handler;
6754 for (op1 = 0; op1 < 64; op1++) {
6756 if (is_indirect_opcode(handler)) {
6757 t2 = ind_table(handler);
6758 for (op2 = 0; op2 < 32; op2++) {
6760 if (is_indirect_opcode(handler)) {
6761 t3 = ind_table(handler);
6762 for (op3 = 0; op3 < 32; op3++) {
6764 if (handler->count == 0)
6766 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
6768 op1, op2, op3, op1, (op3 << 5) | op2,
6770 handler->count, handler->count);
6773 if (handler->count == 0)
6775 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
6777 op1, op2, op1, op2, handler->oname,
6778 handler->count, handler->count);
6782 if (handler->count == 0)
6784 cpu_fprintf(f, "%02x (%02x ) %16s: %016llx %lld\n",
6785 op1, op1, handler->oname,
6786 handler->count, handler->count);
6792 /*****************************************************************************/
6793 static always_inline void gen_intermediate_code_internal (CPUState *env,
6794 TranslationBlock *tb,
6797 DisasContext ctx, *ctxp = &ctx;
6798 opc_handler_t **table, *handler;
6799 target_ulong pc_start;
6800 uint16_t *gen_opc_end;
6801 int supervisor, little_endian;
6807 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
6808 #if defined(OPTIMIZE_FPRF_UPDATE)
6809 gen_fprf_ptr = gen_fprf_buf;
6813 ctx.exception = POWERPC_EXCP_NONE;
6814 ctx.spr_cb = env->spr_cb;
6815 supervisor = env->mmu_idx;
6816 #if !defined(CONFIG_USER_ONLY)
6817 ctx.supervisor = supervisor;
6819 little_endian = env->hflags & (1 << MSR_LE) ? 1 : 0;
6820 #if defined(TARGET_PPC64)
6821 ctx.sf_mode = msr_sf;
6822 ctx.mem_idx = (supervisor << 2) | (msr_sf << 1) | little_endian;
6824 ctx.mem_idx = (supervisor << 1) | little_endian;
6826 ctx.dcache_line_size = env->dcache_line_size;
6827 ctx.fpu_enabled = msr_fp;
6828 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
6829 ctx.spe_enabled = msr_spe;
6831 ctx.spe_enabled = 0;
6832 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
6833 ctx.altivec_enabled = msr_vr;
6835 ctx.altivec_enabled = 0;
6836 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
6837 ctx.singlestep_enabled = CPU_SINGLE_STEP;
6839 ctx.singlestep_enabled = 0;
6840 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
6841 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
6842 if (unlikely(env->singlestep_enabled))
6843 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
6844 #if defined (DO_SINGLE_STEP) && 0
6845 /* Single step trace mode */
6849 max_insns = tb->cflags & CF_COUNT_MASK;
6851 max_insns = CF_COUNT_MASK;
6854 /* Set env in case of segfault during code fetch */
6855 while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
6856 if (unlikely(env->nb_breakpoints > 0)) {
6857 for (j = 0; j < env->nb_breakpoints; j++) {
6858 if (env->breakpoints[j] == ctx.nip) {
6859 gen_update_nip(&ctx, ctx.nip);
6865 if (unlikely(search_pc)) {
6866 j = gen_opc_ptr - gen_opc_buf;
6870 gen_opc_instr_start[lj++] = 0;
6871 gen_opc_pc[lj] = ctx.nip;
6872 gen_opc_instr_start[lj] = 1;
6873 gen_opc_icount[lj] = num_insns;
6876 #if defined PPC_DEBUG_DISAS
6877 if (loglevel & CPU_LOG_TB_IN_ASM) {
6878 fprintf(logfile, "----------------\n");
6879 fprintf(logfile, "nip=" ADDRX " super=%d ir=%d\n",
6880 ctx.nip, supervisor, (int)msr_ir);
6883 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
6885 if (unlikely(little_endian)) {
6886 ctx.opcode = bswap32(ldl_code(ctx.nip));
6888 ctx.opcode = ldl_code(ctx.nip);
6890 #if defined PPC_DEBUG_DISAS
6891 if (loglevel & CPU_LOG_TB_IN_ASM) {
6892 fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6893 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
6894 opc3(ctx.opcode), little_endian ? "little" : "big");
6898 table = env->opcodes;
6900 handler = table[opc1(ctx.opcode)];
6901 if (is_indirect_opcode(handler)) {
6902 table = ind_table(handler);
6903 handler = table[opc2(ctx.opcode)];
6904 if (is_indirect_opcode(handler)) {
6905 table = ind_table(handler);
6906 handler = table[opc3(ctx.opcode)];
6909 /* Is opcode *REALLY* valid ? */
6910 if (unlikely(handler->handler == &gen_invalid)) {
6911 if (loglevel != 0) {
6912 fprintf(logfile, "invalid/unsupported opcode: "
6913 "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
6914 opc1(ctx.opcode), opc2(ctx.opcode),
6915 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
6917 printf("invalid/unsupported opcode: "
6918 "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
6919 opc1(ctx.opcode), opc2(ctx.opcode),
6920 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
6923 if (unlikely((ctx.opcode & handler->inval) != 0)) {
6924 if (loglevel != 0) {
6925 fprintf(logfile, "invalid bits: %08x for opcode: "
6926 "%02x - %02x - %02x (%08x) " ADDRX "\n",
6927 ctx.opcode & handler->inval, opc1(ctx.opcode),
6928 opc2(ctx.opcode), opc3(ctx.opcode),
6929 ctx.opcode, ctx.nip - 4);
6931 printf("invalid bits: %08x for opcode: "
6932 "%02x - %02x - %02x (%08x) " ADDRX "\n",
6933 ctx.opcode & handler->inval, opc1(ctx.opcode),
6934 opc2(ctx.opcode), opc3(ctx.opcode),
6935 ctx.opcode, ctx.nip - 4);
6937 GEN_EXCP_INVAL(ctxp);
6941 (*(handler->handler))(&ctx);
6942 #if defined(DO_PPC_STATISTICS)
6945 /* Check trace mode exceptions */
6946 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
6947 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
6948 ctx.exception != POWERPC_SYSCALL &&
6949 ctx.exception != POWERPC_EXCP_TRAP &&
6950 ctx.exception != POWERPC_EXCP_BRANCH)) {
6951 GEN_EXCP(ctxp, POWERPC_EXCP_TRACE, 0);
6952 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
6953 (env->singlestep_enabled) ||
6954 num_insns >= max_insns)) {
6955 /* if we reach a page boundary or are single stepping, stop
6960 #if defined (DO_SINGLE_STEP)
6964 if (tb->cflags & CF_LAST_IO)
6966 if (ctx.exception == POWERPC_EXCP_NONE) {
6967 gen_goto_tb(&ctx, 0, ctx.nip);
6968 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
6969 if (unlikely(env->singlestep_enabled)) {
6970 gen_update_nip(&ctx, ctx.nip);
6973 /* Generate the return instruction */
6976 gen_icount_end(tb, num_insns);
6977 *gen_opc_ptr = INDEX_op_end;
6978 if (unlikely(search_pc)) {
6979 j = gen_opc_ptr - gen_opc_buf;
6982 gen_opc_instr_start[lj++] = 0;
6984 tb->size = ctx.nip - pc_start;
6985 tb->icount = num_insns;
6987 #if defined(DEBUG_DISAS)
6988 if (loglevel & CPU_LOG_TB_CPU) {
6989 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
6990 cpu_dump_state(env, logfile, fprintf, 0);
6992 if (loglevel & CPU_LOG_TB_IN_ASM) {
6994 flags = env->bfd_mach;
6995 flags |= little_endian << 16;
6996 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
6997 target_disas(logfile, pc_start, ctx.nip - pc_start, flags);
6998 fprintf(logfile, "\n");
7003 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
7005 gen_intermediate_code_internal(env, tb, 0);
7008 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
7010 gen_intermediate_code_internal(env, tb, 1);
7013 void gen_pc_load(CPUState *env, TranslationBlock *tb,
7014 unsigned long searched_pc, int pc_pos, void *puc)
7017 /* for PPC, we need to look at the micro operation to get the
7019 env->nip = gen_opc_pc[pc_pos];
7020 c = gen_opc_buf[pc_pos];
7022 #if defined(CONFIG_USER_ONLY)
7024 case INDEX_op_ ## op ## _raw
7027 case INDEX_op_ ## op ## _user:\
7028 case INDEX_op_ ## op ## _kernel:\
7029 case INDEX_op_ ## op ## _hypv
7036 type = ACCESS_FLOAT;
7052 env->access_type = type;